flexbiz-server 12.2.1 → 12.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/server/auths/local.js +2 -1
- package/server/models/assrequest.js +2 -2
- package/server/models/dmhoahonghd.js +5 -5
- package/server/models/file.js +2 -2
- package/server/models/folder.js +2 -2
- package/server/models/group.js +4 -4
- package/server/models/keyresult.js +2 -1
- package/server/models/moduleinfo.js +4 -3
- package/server/models/okr.js +1 -1
- package/server/models/so1.js +14 -14
- package/server/models/task.js +1 -1
- package/server/modules/lists/ls-customer.js +5 -4
- package/server/modules/lists/ls-dmbp.js +2 -2
- package/server/modules/lists/ls-dmdt.js +5 -5
- package/server/modules/lists/ls-dmdvt.js +1 -1
- package/server/modules/lists/ls-dmkho.js +1 -2
- package/server/modules/lists/ls-dmnhtask.js +5 -4
- package/server/modules/lists/ls-dmnv.js +14 -14
- package/server/modules/lists/ls-dvcs.js +1 -1
- package/server/modules/lists/ls-file.js +4 -4
- package/server/modules/lists/ls-task.js +4 -3
- package/server/modules/reports/rp-congviectheobp.js +4 -4
- package/server/modules/reports/rp-congviectheodt.js +5 -5
- package/server/modules/reports/rp-congviectheokh.js +5 -5
- package/server/modules/reports/rp-congviectheonv.js +3 -3
- package/server/modules/systems/sys-app.js +4 -4
- package/server/modules/vouchers/vo-hd2.js +37 -37
- package/server/modules/vouchers/vo-pnh.js +5 -4
- package/server/modules/vouchers/vo-pxh.js +4 -3
- package/server/modules/vouchers/vo-so1.js +68 -66
|
@@ -8,10 +8,10 @@ user_updated:$user$$.email,kh_yn:!0,of_user:$user$$.email};validator.isMobilePho
|
|
|
8
8
|
{$items$$.joinModel2(null,Trangthai,{where:$item$$=>({ma_ct:"APP",ma_trang_thai:$item$$.trang_thai}),fields:["ten_trang_thai","color"]},()=>{$callback$$()})},show_gia_von_va_nguoi_duyet:$callback$jscomp$0$$=>{async.mapSeries($items$$,($item$$,$callback$$)=>{$item$$.options=$item$$.options||{};$item$$.show_gia_von=!0;$callback$$()},()=>{$callback$jscomp$0$$()})},check_admin:$callback$jscomp$0$$=>{async.mapSeries($items$$,($item$$,$callback$$)=>{checkadmin($user$$,$item$$,()=>{$item$$.appAdmin||(delete $item$$.viettel_user,
|
|
9
9
|
delete $item$$.viettel_password,delete $item$$.viettel_url_service,delete $item$$.wallet_address,delete $item$$.wallet_token,delete $item$$.voiip_access_token,delete $item$$.email_host,delete $item$$.email_port,delete $item$$.email_secure,delete $item$$.email_authMethod,delete $item$$.email_user,delete $item$$.email_pass,delete $item$$.email_name);$callback$$()})},()=>{$callback$jscomp$0$$()})}},function(){$items$$.forEach(function($item$$){calcTimeExpired($item$$)});$fn$$(null,$items$$)})};$contr_router$$.getting=
|
|
10
10
|
async($user$$,$id$$,$next$$)=>{(await model.participants($id$$)).find($p$$=>$p$$.email===$user$$.email&&0==$p$$.cancel)?$next$$():$next$$("Not allowed")};$contr_router$$.finding=async($user$$,$condition$$,$next$$)=>{var $_appsOfUser_or1$$=await Participant.appsOfUser($user$$.email);$_appsOfUser_or1$$=$_appsOfUser_or1$$.map($p$$=>$p$$.id_app);let $user_created_condition$$={user_created:$user$$.email};$_appsOfUser_or1$$=[{_id:{$in:$_appsOfUser_or1$$}},$user_created_condition$$];let $or2$$=$condition$$.$or;
|
|
11
|
-
delete $condition$$.$or;$or2$$?$condition$$.$and=[{$or:$_appsOfUser_or1$$},{$or:$or2$$}]:$condition$$.$or=$_appsOfUser_or1$$;$condition$$.working||(isSupperAdmin($user$$.email.toLowerCase())?delete $user_created_condition$$.user_created:underscore.contains(configs.admins,$user$$.email)&&($user_created_condition$$.user_created={$nin:["invncur@gmail.com","admin"]}));delete $condition$$.working
|
|
12
|
-
$
|
|
13
|
-
|
|
14
|
-
$
|
|
11
|
+
delete $condition$$.$or;$or2$$?$condition$$.$and=[{$or:$_appsOfUser_or1$$},{$or:$or2$$}]:$condition$$.$or=$_appsOfUser_or1$$;$condition$$.working||(isSupperAdmin($user$$.email.toLowerCase())?delete $user_created_condition$$.user_created:underscore.contains(configs.admins,$user$$.email)&&($user_created_condition$$.user_created={$nin:["invncur@gmail.com","admin"]}));delete $condition$$.working;$next$$(null,$condition$$)};$contr_router$$.creating=async function($now_user$$,$obj$$,$next$$){if(!underscore.contains(configs.admins,
|
|
12
|
+
$now_user$$.email)&&!isSupperAdmin($now_user$$.email.toLowerCase())){if(await model.findOne({user_created:$now_user$$.email},{_id:1}))return $next$$("M\u1ed7i t\u00e0i kho\u1ea3n ch\u1ec9 \u0111\u01b0\u1ee3c ph\u00e9p t\u1ea1o m\u1ed9t c\u00f4ng ty");delete $obj$$.allow_modules;delete $obj$$.trang_thai;delete $obj$$.sale_online}if(!$obj$$.ngay_dn)return $next$$(Error("Ng\u00e0y \u0111\u1ea7u n\u0103m t\u00e0i ch\u00ednh kh\u00f4ng \u0111\u01b0\u1ee3c tr\u1ed1ng"));$obj$$.ngay_ks||($obj$$.ngay_ks=
|
|
13
|
+
new Date("2000-01-01"));$obj$$.ngay_ky1||($obj$$.ngay_ky1=new Date);$now_user$$=new Date;$now_user$$.setMonth($now_user$$.getMonth()+1);$obj$$.expire_date=new Date($now_user$$);$obj$$.nam_bd=$obj$$.ngay_ky1.getFullYear();$obj$$.options=$obj$$.options||{};$next$$(null,$obj$$)};$contr_router$$.created=function($user$$,$obj$$,$next$$){require("../../libs/initDatabase").init($obj$$._id,async $error$$=>{$error$$&&console.error("Can't init database \n"+$error$$);createUserOwner($obj$$,$e$$=>{$e$$&&console.error($e$$);
|
|
14
|
+
$next$$(null,$obj$$)})})};$contr_router$$.updating=function($user$$,$data$$,$obj$$,$next$$){const $usersAdmin$$=configs.admins;underscore.contains($usersAdmin$$,$user$$.email)||isSupperAdmin($user$$.email.toLowerCase())||(delete $data$$.allow_modules,delete $data$$.expire_date,delete $data$$.trang_thai,delete $data$$.sale_online);permission.isAdmin($obj$$._id,$user$$.email,function($e$$,$admin$$){if(!$admin$$&&!underscore.contains($usersAdmin$$,$user$$.email)&&!isSupperAdmin($user$$.email.toLowerCase()))return $next$$($user$$.email+
|
|
15
15
|
" have not permission");$data$$.ngay_ky1&&($data$$.nam_bd=(new Date($data$$.ngay_ky1)).getFullYear());$data$$.options&&0===Object.keys($data$$.options).length&&delete $data$$.options;$data$$.options=$data$$.options?{...$obj$$.options,...$data$$.options}:$obj$$.options||{};$next$$(null,$data$$,$obj$$)})};$contr_router$$.updated=function($user$$,$obj$$,$next$$){createUserOwner($obj$$,$e$$=>{$e$$&&console.error($e$$);$next$$(null,$obj$$)})};$contr_router$$.deleting=function($user$$,$obj$$,$next$$){const $usersAdmin$$=
|
|
16
16
|
configs.admins;if($user$$.email!=$obj$$.user_created&&!underscore.contains($usersAdmin$$,$user$$.email)&&!isSupperAdmin($user$$.email.toLowerCase()))return $next$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n x\u00f3a c\u00f4ng ty n\u00e0y");$next$$(null,$obj$$)};$contr_router$$.deleted=function($user$$,$obj$$,$next$$){async.mapSeries(fs.readdirSync(path.dirname(path.dirname(__dirname))+"/models").filter($f$$=>0<$f$$.indexOf(".js")),($file$$,$callback$$)=>{try{let $_model$$=global.getModel(""+$file$$);
|
|
17
17
|
underscore.has($_model$$.schema.paths,"id_app")?$_model$$.deleteMany({id_app:$obj$$._id},()=>{console.log("Deleted ",$file$$,"id_app",$obj$$._id);$callback$$()}):$callback$$()}catch($e$$){console.error("Can't delete mode",$file$$,"error:",$e$$.message),$callback$$()}},()=>{$next$$(null,$obj$$)})};$contr_router$$.router.route($contr_router$$.route_name+"/backup/:id").get(function($req$$,$res$$){let $email$$=$req$$.user.email,$id_app$$=$req$$.params.id;permission.isAdmin($id_app$$,$email$$,function($backupWorkerFile_e$$,
|
|
@@ -11,43 +11,43 @@ $ckhds_query_t_ck_nt$$=$ckhds_query_t_ck_nt$$.filter($cs$$=>$cs$$.chi_su_dung_ch
|
|
|
11
11
|
module.exports=function($router$$){const $contr$$=new controller($router$$,model,ma_ct.toLowerCase(),{isVoucher:!0,sort:{ngay_ct:-1,so_ct:-1},onFinding:($user$$,$condition$$,$next$$)=>{$next$$(null,$condition$$)}});$contr$$.route();$contr$$.saving=async($user$$,$obj$$)=>{await hoahonghd($obj$$)};$contr$$.post=async($obj$$,$fn$$)=>{$fn$$||($fn$$=function(){});let $kho$$=await dmkho.findOne({id_app:$obj$$.id_app,ma_kho:$obj$$.ma_kho}).lean()||{},$options$$;try{$options$$=await Options.getInfo($obj$$.id_app,
|
|
12
12
|
{id_func:$obj$$.ma_ct.toLowerCase()},"option")}catch($e$$){console.log($e$$.message,{id_func:$obj$$.ma_ct})}$options$$||($options$$={});async.series({post_sokho:function($callback$jscomp$1$$){let $details$$=[...$obj$$.details];$obj$$.details.forEach($d$$=>{$d$$.promotion&&$d$$.promotion.details_km&&$d$$.promotion.details_km.forEach($p$$=>{if($p$$.ma_vt&&$p$$.sl_km){let $_p$$={};underscore.extend($_p$$,$p$$,{sl_xuat:$p$$.sl_km});$details$$.push($_p$$)}})});$obj$$.promotion&&$obj$$.promotion.forEach($p$$=>
|
|
13
13
|
{if($p$$.ma_vt&&$p$$.sl_km){let $_p$$={};underscore.extend($_p$$,$p$$,{sl_xuat:$p$$.sl_km});$details$$.push($_p$$)}});$details$$.joinModel2($obj$$.id_app,dmvt,{where:"ma_vt",fields:["gia_mua","combo"]},()=>{let $data_post$$=$details$$.map($detail$$=>$detail$$.combo&&0<$detail$$.combo.length?$detail$$.combo.map($item$$=>{$item$$=$item$$.toObject?$item$$.toObject():{...$item$$};$item$$.sl_xuat*=$detail$$.sl_xuat;$item$$.tien_xuat=$item$$.tien_xuat_nt=$item$$.sl_xuat*$item$$.gia_von_nt;$item$$.tien=
|
|
14
|
-
$item$$.tien_nt=$item$$.sl_xuat*$item$$.gia_ban_nt;$item$$.tien_ck=$item$$.tien_ck_nt*=$item$$.sl_xuat;return $item$$}):[$detail$$]).reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]);async.series({kt:$callback$jscomp$0$$=>{(new PostBook($obj$$,$data_post$$,Sokho,async($detail$$,$callback$$)=>{$detail$$.nxt=2;$detail$$.tk_no=$obj$$.tk_no;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$jscomp$0$$($e$$,$rs$$)})},tt:$callback$jscomp$0$$=>{
|
|
15
|
-
$callback$$)=>{$detail$$.nxt=2;$detail$$.tk_no=$obj$$.tk_no;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$jscomp$0$$($e$$,$rs$$)})}},($e$$,$rs$$)=>{$callback$jscomp$1$$($e$$,$rs$$)})})},post_vatra:function($callback$jscomp$0$$){$obj$$.ngay_hd?$obj$$.details.map($detail$$=>({...$detail$$,thue_suat:($detail$$.ma_thue?$detail$$.thue_suat:$obj$$.thue_suat)||0,ma_thue:$detail$$.ma_thue||$obj$$.ma_thue,tien_thue_nt:$detail$$.tien_thue_nt||
|
|
16
|
-
$d$$.ma_thue).asyncGroupBy(["ma_thue","thue_suat","ten_vt_vat"],"tien_nt tien tien_ck tien_ck_nt tien_thue tien_thue_nt".split(" ")).then($ds$$=>{if(1==$ds$$.length){let $tien_thue_nt$$=$ds$$.map($d$$=>$d$$.tien_thue_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0),$tien_thue$$=$ds$$.map($d$$=>$d$$.tien_thue).reduce(($a$$,$b$$)=>$a$$+$b$$,0);0==$tien_thue_nt$$&&0==$tien_thue$$&&($tien_thue_nt$$=$obj$$.t_thue_nt||0,$tien_thue$$=$obj$$.t_thue||0);$ds$$[0].tien_thue_nt
|
|
17
|
-
$ds$$,Vatra,function($detail$$,$callback$$){try{$detail$$.tk_du_thue=$obj$$.tk_no,$detail$$.t_tien_nt=$detail$$.tien_nt-$detail$$.tien_ck_nt,$detail$$.t_tien=$detail$$.tien-$detail$$.tien_ck,$detail$$.t_thue_nt=$detail$$.tien_thue_nt,$detail$$.t_thue=$detail$$.tien_thue,$detail$$.ten_vt=$detail$$.ten_vt_vat||$obj$$.ten_vt||$obj$$.dien_giai}catch($e$$){console.error($e$$,$obj$$)}$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$jscomp$0$$($e
|
|
18
|
-
[];$obj$$.details.forEach(function($d$jscomp$9_detail$$){$d$jscomp$9_detail$$={...$d$jscomp$9_detail$$};$d$jscomp$9_detail$$.tk_co=$d$jscomp$9_detail$$.tk_dt||$kho$$.tk_dt||$options$$.tk_dt;$d$jscomp$9_detail$$.ma_kh||($d$jscomp$9_detail$$.ma_kh=$obj$$.ma_kh);$d$jscomp$9_detail$$.tk_no=$obj$$.tk_no;$details$$.push($d$jscomp$9_detail$$)});$obj$$.details.forEach(function($d$jscomp$10_detail$$){$d$jscomp$10_detail$$=
|
|
19
|
-
$obj$$.tk_ck||$kho$$.tk_ck||$options$$.tk_ck;$d$jscomp$10_detail$$.ma_kh||($d$jscomp$10_detail$$.ma_kh=$obj$$.ma_kh);$d$jscomp$10_detail$$.tk_co=$obj$$.tk_no;$d$jscomp$10_detail$$.tien_nt=$d$jscomp$10_detail$$.tien_ck_nt;$d$jscomp$10_detail$$.tien=$d$jscomp$10_detail$$.tien_ck;$d$jscomp$10_detail$$.check_balance=!1;$details$$.push($d$jscomp$10_detail$$)});if($obj$$.tien_ck_hd){var $o_tt_tt$$={};$o_tt_tt$$.tk_no=$obj$$.tk_ck
|
|
20
|
-
$obj$$.tien_ck_hd;$o_tt_tt$$.tien=$o_tt_tt$$.tien_nt*($obj$$.ty_gia||1);$o_tt_tt$$.ma_kh=$obj$$.ma_kh;$o_tt_tt$$.check_balance=!1;$details$$.push($o_tt_tt$$)}$obj$$.tien_hoa_hong&&($o_tt_tt$$={},$o_tt_tt$$.tk_no=$obj$$.tk_no_hoa_hong||$kho$$.tk_no_hoa_hong||$options$$.tk_no_hoa_hong,$o_tt_tt$$.tk_co=$obj$$.tk_co_hoa_hong||$kho$$.tk_co_hoa_hong||$options$$.tk_co_hoa_hong,$o_tt_tt$$.tien_nt=$obj$$.tien_hoa_hong,$o_tt_tt$$.tien
|
|
21
|
-
$o_tt_tt$$.ma_nv=$obj$$.ma_nv,$o_tt_tt$$.check_balance=!1,$details$$.push($o_tt_tt$$));$o_tt_tt$$={...$obj$$};$o_tt_tt$$.tk_no=$obj$$.tk_no;$o_tt_tt$$.tk_co=$obj$$.tk_thue_co;$o_tt_tt$$.tien_nt=$obj$$.tien_thue_dc_nt||$obj$$.details.csum("tien_thue_nt");$o_tt_tt$$.tien=$o_tt_tt$$.tien_nt*$o_tt_tt$$.ty_gia;$o_tt_tt$$.dien_giai_thue&&($o_tt_tt$$.dien_giai=$o_tt_tt$$.dien_giai_thue);$details$$.push($o_tt_tt$$);const $details_giavon$$=
|
|
22
|
-
{...$d$jscomp$11_detail$$};$d$jscomp$11_detail$$.tk_no=$d$jscomp$11_detail$$.tk_gv;$d$jscomp$11_detail$$.ma_kh||($d$jscomp$11_detail$$.ma_kh=$obj$$.ma_kh);$d$jscomp$11_detail$$.tk_co=$d$jscomp$11_detail$$.tk_vt;$d$jscomp$11_detail$$.tien_nt=$d$jscomp$11_detail$$.tien_xuat_nt;$d$jscomp$11_detail$$.tien=$d$jscomp$11_detail$$.tien_xuat;$details_giavon$$.push($d$jscomp$11_detail$$);$d$jscomp$11_detail$$.promotion&&$d$jscomp$11_detail$$.promotion.details_km
|
|
23
|
-
{$detail$$.ma_vt&&($detail$$.tk_no=$detail$$.tk_gv,$detail$$.ma_kh||($detail$$.ma_kh=$obj$$.ma_kh),$detail$$.tk_co=$detail$$.tk_vt,$detail$$.tien_nt=$detail$$.tien_xuat_nt||0,$detail$$.tien=$detail$$.tien_xuat||0,$details_giavon$$.push($detail$$))})});$obj$$.promotion&&$obj$$.promotion.forEach(function($detail$$){$detail$$.ma_vt&&($detail$$.tk_no=$detail$$.tk_gv,$detail$$.ma_kh||($detail$$.ma_kh=$obj$$.ma_kh),$detail$$.tk_co=$detail$$.tk_vt
|
|
24
|
-
$detail$$.tien_xuat||0,$details_giavon$$.push($detail$$))});async.series({xdtk:$callback$$=>{$details_giavon$$.joinModel2($obj$$.id_app,dmvt,{where:"ma_vt",fields:["tk_vt","gia_mua","tk_gv"]},()=>{$details_giavon$$.forEach($s$$=>{$s$$.tk_co||($s$$.tk_co=$s$$.tk_vt||$options$$.tk_vt);$s$$.tk_no||($s$$.tk_no=$s$$.tk_gv||$options$$.tk_gv)});$callback$$()})}},()=>{$details$$=$details$$.concat($details_giavon$$);(new PostSocai($obj$$,$details$$)).run(function($e
|
|
25
|
-
post_tdttno:function($callback$jscomp$0$$){account.findOne({tk:$obj$$.tk_no,id_app:$obj$$.id_app},{tk_cn:1},function($error$jscomp$0$$,$tk$$){if($error$jscomp$0$$)return $callback$jscomp$0$$($error$jscomp$0$$);$tk$$&&!0===$tk$$.tk_cn?(new PostBook($obj$$,[{...$obj$$}],Tdttno,function($detail$$,$callback$$){try{$detail$$.so_hd||($detail$$.so_hd=$obj$$.so_ct),$detail$$.ngay_hd||($detail$$.ngay_hd=$obj$$.ngay_ct),$detail$$.tien_nt=$obj$$.details.csum("tien_nt")
|
|
26
|
-
$obj$$.details.csum("tien_thue_nt")),$detail$$.tien=$detail$$.tien_nt*$obj$$.ty_gia}catch($e$$){console.error($e$$,$obj$$)}$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$jscomp$0$$($e$$,$rs$$)}):Tdttno.deleteMany({id_ct:$obj$$._id},function($error$$){$callback$jscomp$0$$($error$$)})})}},function($e$$,$rs$$){$fn$$($e$$,$rs$$)})};const $valid$$=function($i$jscomp$1_t_thue_nt_user$$,$obj$$,$next$$){for($i$jscomp$1_t_thue_nt_user$$=
|
|
27
|
-
$obj$$.details[$i$jscomp$1_t_thue_nt_user$$];$obj$$.ma_kho&&($detail$jscomp$0$$.ma_kho=$obj$$.ma_kho);$detail$jscomp$0$$.line=$i$jscomp$1_t_thue_nt_user$$;"VND"===$obj$$.ma_nt&&($detail$jscomp$0$$.tien=$detail$jscomp$0$$.tien_nt,$detail$jscomp$0$$.gia_ban=$detail$jscomp$0$$.gia_ban_nt,$detail$jscomp$0$$.tien_ck=$detail$jscomp$0$$.tien_ck_nt);$detail$jscomp$0$$.tien_xuat=$detail$jscomp$0$$.tien_xuat_nt
|
|
28
|
-
0}$obj$$.thue_suat=$obj$$.thue_suat||0;let $f_tien_nt$$="VND"==$obj$$.ma_nt?0:2;$obj$$.details.forEach($detail$$=>{let $thue_suat$$=($detail$$.ma_thue?$detail$$.thue_suat:$obj$$.thue_suat)||0;$detail$$.tien_thue=utils.round(($detail$$.tien-$detail$$.tien_ck)*$thue_suat$$/100,0);$detail$$.tien_thue_nt=utils.round(($detail$$.tien_nt-$detail$$.tien_ck_nt)*$thue_suat$$/100,$f_tien_nt$$)});
|
|
29
|
-
utils.round(($obj$$.details.csum("tien_nt")-$obj$$.details.csum("tien_ck_nt"))*$obj$$.thue_suat/100,$f_tien_nt$$),$obj$$.t_thue=utils.round($obj$$.t_thue_nt*($obj$$.ty_gia||1),0),$i$jscomp$1_t_thue_nt_user$$=$obj$$.details.csum("tien_thue_nt"),$detail$jscomp$0$$=$obj$$.details.csum("tien_thue"),($i$jscomp$1_t_thue_nt_user$$!==$obj$$.t_thue_nt||$detail$jscomp$0$$!==$obj$$.t_thue)&&0<$obj$$.details.length)){let $row_dieu_chinh
|
|
30
|
-
$obj$$.t_thue_nt-$i$jscomp$1_t_thue_nt_user$$;$row_dieu_chinh$$.tien_thue+=$obj$$.t_thue-$detail$jscomp$0$$}$obj$$.id_contract?salecontract.findOne({_id:$obj$$.id_contract}).lean().exec(($e$$,$c$$)=>{$c$$&&($obj$$.ma_hd=$c$$.ma_hd);$next$$(null,$obj$$)}):$next$$(null,$obj$$)};$contr$$.creating=function($user$$,$obj$$,$next$$){$obj$$.details||($obj$$.details=[]);$valid$$($user$$,$obj$$,function($error$$){if($error$$)return $next$$($error$$)
|
|
31
|
-
$contr$$.updating=function($user$$,$data$$,$obj$$,$next$$){Tdttno_tt.findOne({id_hd:$obj$$._id},function($error$jscomp$0$$,$ct_tt$$){if($error$jscomp$0$$)return $next$$($error$jscomp$0$$);$ct_tt$$?$next$$(`Kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt phi\u1ebfu n\u00e0y do \u0111\u00e3 \u0111\u01b0\u1ee3c thanh to\u00e1n b\u1edfi ${$ct_tt$$.ma_ct||"ch\u1ee9ng t\u1eeb"}: ${$ct_tt$$.so_ct}, ng\u00e0y ${Moment($ct_tt$$.ngay_ct).format("DD/MM/YYYY")}`)
|
|
32
|
-
$next$$(null,$data$$,$obj$$)})})};$contr$$.deleting=function($user$$,$obj$$,$next$$){Tdttno_tt.findOne({id_hd:$obj$$._id},function($error$$,$ct_tt$$){if($error$$)return $next$$($error$$);$ct_tt$$?$next$$(`Kh\u00f4ng th\u1ec3 xo\u00e1 phi\u1ebfu n\u00e0y do \u0111\u00e3 \u0111\u01b0\u1ee3c thanh to\u00e1n b\u1edfi ${$ct_tt$$.ma_ct||"ch\u1ee9ng t\u1eeb"}: ${$ct_tt$$.so_ct}, ng\u00e0y ${Moment($ct_tt$$.ngay_ct).format("DD/MM/YYYY")}`)
|
|
33
|
-
$user$$.current_id_app;async.series({dv:function($callback$$){$items$$.filter($item$$=>$item$$.ma_dvcs).joinModel($id_app$$,dvcs,[{akey:"ma_dvcs",bkey:"_id",fields:[{name:"ten_dvcs",value:"ten_dvcs"}]}],function(){$callback$$()})},tk:function($callback$$){$items$$.filter($item$$=>$item$$.tk_no).joinModel($id_app$$,account,[{akey:"tk_no",bkey:"tk",fields:[{name:"ten_tk_no",value:"ten_tk"}]}],function(){$callback$$()})},
|
|
34
|
-
dmdt,[{akey:"ma_dt",bkey:"ma_dt",fields:[{name:"ten_dt",value:"ten_dt"}]}],function(){$callback$$()})},kh:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kh).joinModel2($id_app$$,customer,[{where:"ma_kh",fields:["ten_kh","email","nh_kh"]}],function(){$callback$$()})},nv:function($callback$$){$items$$.filter($item$$=>$item$$.ma_nv).joinModel($id_app$$,dmnv,[{akey:"ma_nv",bkey:"ma_nv",fields:[{name:"ten_nv",
|
|
35
|
-
$item$$.trang_thai).joinModel2(null,trangthai,[{where:{trang_thai:"ma_trang_thai",ma_ct:"ma_ct"},fields:["ten_trang_thai","color"]}],function(){$callback$$()})},contract:function($callback$$){$items$$.filter($item$$=>$item$$.ma_hd).joinModel2($id_app$$,contract,[{where:{ma_hd:"so_hd"},fields:["ten_hd","ten_hd"]}],function(){$callback$$()})},t_tien:function($callback$$){$items$$.forEach(function($r$$){$r$$.details&&
|
|
36
|
-
$r$$.details.csum("tien_nt"),$r$$.t_ck=$r$$.details.csum("tien_ck"),$r$$.t_ck_nt=$r$$.details.csum("tien_ck_nt"),$r$$.tc_ck_nt=$r$$.t_ck_nt+($r$$.tien_ck_hd||0),$r$$.tc_ck=$r$$.t_ck+($r$$.tien_ck_hd||0)*$r$$.ty_gia,$r$$.t_thue=$r$$.details.csum("tien_thue"),$r$$.t_thue_nt=$r$$.details.csum("tien_thue_nt"),$r$$.t_tt=$r$$.t_tien+$r$$.t_thue-$r$$.tc_ck,$r$$.t_tt_nt=$r$$.t_tien_nt+$r$$.t_thue_nt-$r$$.tc_ck_nt
|
|
37
|
-
$callback$$()},details_tk:function($callback$jscomp$0$$){async.mapSeries($items$$,function($r$$,$callback1$$){const $details$$=$r$$.details;async.series({tk:function($callback$$){$details$$.joinModel($id_app$$,account,[{akey:"tk_vt",bkey:"tk",fields:[{name:"ten_tk_vt",value:"ten_tk"}]},{akey:"tk_dt",bkey:"tk",fields:[{name:"ten_tk_dt",value:"ten_tk"}]},{akey:"tk_ck",bkey:"tk",fields:[{name:"ten_tk_ck",
|
|
38
|
-
kho:function($callback$$){$details$$.filter($item$$=>$item$$.ma_kho).joinModel($id_app$$,dmkho,[{akey:"ma_kho",bkey:"ma_kho",fields:[{name:"ten_kho",value:"ten_kho"}]}],function(){$callback$$()})}},function(){$callback1$$()})},function(){$callback$jscomp$0$$()})},details_vt:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){$r$$.details.joinModel($id_app$$,dmvt,
|
|
39
|
-
details_dt:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){$r$$.details.filter($item$$=>$item$$.ma_dt).joinModel($id_app$$,dmdt,[{akey:"ma_dt",bkey:"ma_dt",fields:[{name:"ten_dt",value:"ten_dt"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_contract:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){$r$$.details.filter($item
|
|
40
|
-
function(){$callback1$$()})},function(){$callback$$()})},details_phi:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){$r$$.details.filter($item$$=>$item$$.ma_phi).joinModel($id_app$$,dmphi,[{akey:"ma_phi",bkey:"ma_phi",fields:[{name:"ten_phi",value:"ten_phi"}]}],function(){$callback1$$()})},function(){$callback$$()})}},function(){$fn$$(null,$items$$)})};$contr$$.createRoute("export2viettel/:id_ct",
|
|
41
|
-
$app_msg_e$$=await App.findOne({_id:$id_app$$});if(!$app_msg_e$$)return $next$$("Kh\u00f4ng t\u00ecm th\u1ea5y c\u00f4ng ty n\u00e0y");if(!$app_msg_e$$.viettel_url_service||!$app_msg_e$$.viettel_user||!$app_msg_e$$.viettel_password)return $next$$("Th\u00f4ng tin xu\u1ea5t ho\u00e1 \u0111\u01a1n Viettel ch\u01b0a \u0111\u01b0\u1ee3c khai b\u00e1o \u0111\u1ea7y \u0111\u1ee7");if(!$app_msg_e$$.ma_so_thue)return $next$$("B\u1ea1n ch\u01b0a nh\u1eadp m\u00e3 s\u1ed1 thu\u1ebf c\u1ee7a c\u00f4ng ty");
|
|
42
|
-
await model.findOne({id_app:$id_app$$,_id:$data$jscomp$1_kh$$.params.id_ct}).lean();if(!$ct$$)return $next$$("Ch\u1ee9ng t\u1eeb kh\u00f4ng h\u1ee3p l\u1ec7");if($ct$$.result_export_einvoice&&$ct$$.result_export_einvoice.result&&$ct$$.result_export_einvoice.result.transactionID)return $next$$("Ho\u00e1 \u0111\u01a1n n\u00e0y \u0111\u00e3 \u0111\u01b0\u1ee3c xu\u1ea5t sang ho\u00e1 \u0111\u01a1n \u0111i\u1ec7n t\u1eed Viettel");$data$jscomp$1_kh$$=await customer.findOne({id_app:$id_app$$,
|
|
43
|
-
{};await $ct$$.details.asyncJoinModel2($id_app$$,dmvt,{where:"ma_vt",fields:"ten_vt"});$id_app$$=Math.abs($ct$$.details.map($d$$=>$d$$.tien_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0));var $auth_t_ck$$=Math.abs($ct$$.details.map($d$$=>$d$$.tien_ck_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0));const $t_tien$$=Math.abs($ct$$.details.map($d$$=>$d$$.tien_nt-$d$$.tien_ck_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0)),$t_thue$$=Math.abs($ct$$.details.map($d$$=>$d$$.tien_thue_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,
|
|
44
|
-
$ct$$.details.map($detail$$=>({...$detail$$,ma_thue:$detail$$.ma_thue||$ct$$.ma_thue,thue_suat:($detail$$.ma_thue?$detail$$.thue_suat:$ct$$.thue_suat)||0})).filter($d$$=>$d$$.ma_thue);if(0===$taxBreakdowns$$.length)return $next$$("B\u1ea1n ch\u01b0a khai b\u00e1o thu\u1ebf");$taxBreakdowns$$=$taxBreakdowns$$.filter($d$$=>"KT"!==$d$$.ma_thue).map($detail$$=>({taxPercentage:"KT"===$detail$$.ma_thue?-2:$detail$$.thue_suat,taxableAmount:Math.abs($detail$$.tien_nt-$detail$$.tien_ck_nt),
|
|
45
|
-
$taxBreakdowns$$=await $taxBreakdowns$$.asyncGroupBy("taxPercentage",["taxableAmount","taxAmount"]);$data$jscomp$1_kh$$={generalInvoiceInfo:{invoiceType:$ct$$.ma_hoa_don||$app_msg_e$$.ma_hoa_don||"1",templateCode:$ct$$.ky_hieu_hoa_don||$app_msg_e$$.ky_hieu_hoa_don||"1/001",invoiceSeries:$ct$$.so_seri,currencyCode:"VND",adjustmentType:"1",paymentStatus:!0,cusGetInvoiceRight:!0,userName:$ct$$.user_created},buyerInfo:{buyerName:$ct$$.ong_ba||"",buyerLegalName:$ct$$.ten_kh
|
|
46
|
-
"",buyerTaxCode:$ct$$.ma_so_thue||$data$jscomp$1_kh$$.ma_so_thue||"",buyerAddressLine:$ct$$.dia_chi||$data$jscomp$1_kh$$.dia_chi||"",buyerPostalCode:"",buyerDistrictName:"",buyerCityName:"",buyerCountryCode:"",buyerPhoneNumber:$ct$$.dien_thoai||$data$jscomp$1_kh$$.dien_thoai||"",buyerFaxNumber:"",buyerEmail:$data$jscomp$1_kh$$.email||"",buyerBankName:"",buyerBankAccount:"",buyerIdType:"",buyerIdNo:"",buyerCode:"",buyerBirthDay:""},sellerInfo:{sellerLegalName:$app_msg_e$$.name,
|
|
47
|
-
sellerAddressLine:$app_msg_e$$.address,sellerPhoneNumber:$app_msg_e$$.phone||"",sellerEmail:$app_msg_e$$.email||"",sellerBankName:$app_msg_e$$.ten_ngan_hang||"",sellerBankAccount:$app_msg_e$$.tai_khoan_ngan_hang||""},itemInfo:$ct$$.details.map(($detail$$,$index$$)=>{let $thue_suat$$=($detail$$.ma_thue?$detail$$.thue_suat:$ct$$.thue_suat)||0;return{lineNumber:$index$$+1,selection:0>$detail$$.tien_nt?3:1,itemCode:$detail$$.ma_vt,itemName:$detail$$.ten_vt_vat||$detail$$.ten_vt,
|
|
48
|
-
"":$detail$$.ma_dvt,itemNote:"",unitPrice:0>$detail$$.tien_nt?void 0:$detail$$.gia_ban_nt,quantity:0>$detail$$.tien_nt?void 0:$detail$$.sl_xuat,itemTotalAmountWithoutTax:Math.abs($detail$$.tien_nt),discount:$detail$$.ty_le_ck,itemDiscount:Math.abs($detail$$.tien_ck_nt),itemTotalAmountAfterDiscount:Math.abs($detail$$.tien_nt-$detail$$.tien_ck_nt),taxPercentage:"KT"===($detail$$.ma_thue||$ct$$.ma_thue)?0>$detail$$.tien_nt?void 0:-2:$thue_suat$$,taxAmount:Math.abs($detail$$.tien_thue_nt),
|
|
49
|
-
$detail$$.tien_ck_nt+$detail$$.tien_thue_nt),customTaxAmount:"0",batchNo:"",expDate:""}}),summarizeInfo:{sumOfTotalLineAmountWithoutTax:$id_app$$,discountAmount:$auth_t_ck$$,settlementDiscountAmount:$auth_t_ck$$,totalAmountWithoutTax:$t_tien$$,totalTaxAmount:$t_thue$$,totalAmountWithTax:$t_tien$$+$t_thue$$},taxBreakdowns:$taxBreakdowns$$,payments:[{paymentMethodName:$ct$$.hinh_thuc_tt||"TM"}],extAttribute:[],deliveryInfo:{},metadata:[]};$ct$$.ngay_hd||
|
|
50
|
-
$auth_t_ck$$={username:$app_msg_e$$.viettel_user.trim(),password:$app_msg_e$$.viettel_password.trim()};if("1"!=$app_msg_e$$.viettel_version){$data$jscomp$1_kh$$.generalInvoiceInfo.invoiceIssuedDate=(new Date($ct$$.ngay_hd)).getTime();$id_app$$=$app_msg_e$$.viettel_direct_issue?`${$app_msg_e$$.viettel_url_service.trim()}/services/einvoiceapplication/api/InvoiceAPI/InvoiceWS/createInvoice/${$app_msg_e$$.ma_so_thue.trim()}`:`${$app_msg_e$$.viettel_url_service.trim()}/services/einvoiceapplication/api/InvoiceAPI/InvoiceWS/createOrUpdateInvoiceDraft/${$app_msg_e$$.ma_so_thue.trim()}`;
|
|
14
|
+
$item$$.tien_nt=$item$$.sl_xuat*$item$$.gia_ban_nt;$item$$.tien_ck=$item$$.tien_ck_nt*=$item$$.sl_xuat;return $item$$}):[$detail$$]).reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]);async.series({kt:$callback$jscomp$0$$=>{$options$$.not_post_sokho?$callback$jscomp$0$$():(new PostBook($obj$$,$data_post$$,Sokho,async($detail$$,$callback$$)=>{$detail$$.nxt=2;$detail$$.tk_no=$obj$$.tk_no;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$jscomp$0$$($e$$,$rs$$)})},tt:$callback$jscomp$0$$=>{$options$$.post_sokhott?
|
|
15
|
+
(new PostBook($obj$$,$data_post$$,Sokhott,async($detail$$,$callback$$)=>{$detail$$.nxt=2;$detail$$.tk_no=$obj$$.tk_no;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$jscomp$0$$($e$$,$rs$$)}):$callback$jscomp$0$$()}},($e$$,$rs$$)=>{$callback$jscomp$1$$($e$$,$rs$$)})})},post_vatra:function($callback$jscomp$0$$){$obj$$.ngay_hd?$obj$$.details.map($detail$$=>({...$detail$$,thue_suat:($detail$$.ma_thue?$detail$$.thue_suat:$obj$$.thue_suat)||0,ma_thue:$detail$$.ma_thue||$obj$$.ma_thue,tien_thue_nt:$detail$$.tien_thue_nt||
|
|
16
|
+
0,tien_thue:$detail$$.tien_thue||0})).filter($d$$=>$d$$.ma_thue).asyncGroupBy(["ma_thue","thue_suat","ten_vt_vat"],"tien_nt tien tien_ck tien_ck_nt tien_thue tien_thue_nt".split(" ")).then($ds$$=>{if(1==$ds$$.length){let $tien_thue_nt$$=$ds$$.map($d$$=>$d$$.tien_thue_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0),$tien_thue$$=$ds$$.map($d$$=>$d$$.tien_thue).reduce(($a$$,$b$$)=>$a$$+$b$$,0);0==$tien_thue_nt$$&&0==$tien_thue$$&&($tien_thue_nt$$=$obj$$.t_thue_nt||0,$tien_thue$$=$obj$$.t_thue||0);$ds$$[0].tien_thue_nt=
|
|
17
|
+
$tien_thue_nt$$;$ds$$[0].tien_thue=$tien_thue$$}(new PostBook($obj$$,$ds$$,Vatra,function($detail$$,$callback$$){try{$detail$$.tk_du_thue=$obj$$.tk_no,$detail$$.t_tien_nt=$detail$$.tien_nt-$detail$$.tien_ck_nt,$detail$$.t_tien=$detail$$.tien-$detail$$.tien_ck,$detail$$.t_thue_nt=$detail$$.tien_thue_nt,$detail$$.t_thue=$detail$$.tien_thue,$detail$$.ten_vt=$detail$$.ten_vt_vat||$obj$$.ten_vt||$obj$$.dien_giai}catch($e$$){console.error($e$$,$obj$$)}$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$jscomp$0$$($e$$,
|
|
18
|
+
$rs$$)})}):$callback$jscomp$0$$()},post_socai:function($callback$jscomp$0$$){let $details$$=[];$obj$$.details.forEach(function($d$jscomp$9_detail$$){$d$jscomp$9_detail$$={...$d$jscomp$9_detail$$};$d$jscomp$9_detail$$.tk_co=$d$jscomp$9_detail$$.tk_dt||$kho$$.tk_dt||$options$$.tk_dt;$d$jscomp$9_detail$$.ma_kh||($d$jscomp$9_detail$$.ma_kh=$obj$$.ma_kh);$d$jscomp$9_detail$$.tk_no=$obj$$.tk_no;$details$$.push($d$jscomp$9_detail$$)});$obj$$.details.forEach(function($d$jscomp$10_detail$$){$d$jscomp$10_detail$$=
|
|
19
|
+
{...$d$jscomp$10_detail$$};$d$jscomp$10_detail$$.tk_no=$d$jscomp$10_detail$$.tk_ck||$obj$$.tk_ck||$kho$$.tk_ck||$options$$.tk_ck;$d$jscomp$10_detail$$.ma_kh||($d$jscomp$10_detail$$.ma_kh=$obj$$.ma_kh);$d$jscomp$10_detail$$.tk_co=$obj$$.tk_no;$d$jscomp$10_detail$$.tien_nt=$d$jscomp$10_detail$$.tien_ck_nt;$d$jscomp$10_detail$$.tien=$d$jscomp$10_detail$$.tien_ck;$d$jscomp$10_detail$$.check_balance=!1;$details$$.push($d$jscomp$10_detail$$)});if($obj$$.tien_ck_hd){var $o_tt_tt$$={};$o_tt_tt$$.tk_no=$obj$$.tk_ck||
|
|
20
|
+
$kho$$.tk_ck||$options$$.tk_ck;$o_tt_tt$$.tk_co=$obj$$.tk_no;$o_tt_tt$$.tien_nt=$obj$$.tien_ck_hd;$o_tt_tt$$.tien=$o_tt_tt$$.tien_nt*($obj$$.ty_gia||1);$o_tt_tt$$.ma_kh=$obj$$.ma_kh;$o_tt_tt$$.check_balance=!1;$details$$.push($o_tt_tt$$)}$obj$$.tien_hoa_hong&&($o_tt_tt$$={},$o_tt_tt$$.tk_no=$obj$$.tk_no_hoa_hong||$kho$$.tk_no_hoa_hong||$options$$.tk_no_hoa_hong,$o_tt_tt$$.tk_co=$obj$$.tk_co_hoa_hong||$kho$$.tk_co_hoa_hong||$options$$.tk_co_hoa_hong,$o_tt_tt$$.tien_nt=$obj$$.tien_hoa_hong,$o_tt_tt$$.tien=
|
|
21
|
+
$o_tt_tt$$.tien_nt*($obj$$.ty_gia||1),$o_tt_tt$$.ma_kh=$obj$$.ma_kh_hoa_hong,$o_tt_tt$$.ma_nv=$obj$$.ma_nv,$o_tt_tt$$.check_balance=!1,$details$$.push($o_tt_tt$$));$o_tt_tt$$={...$obj$$};$o_tt_tt$$.tk_no=$obj$$.tk_no;$o_tt_tt$$.tk_co=$obj$$.tk_thue_co;$o_tt_tt$$.tien_nt=$obj$$.tien_thue_dc_nt||$obj$$.details.csum("tien_thue_nt");$o_tt_tt$$.tien=$o_tt_tt$$.tien_nt*$o_tt_tt$$.ty_gia;$o_tt_tt$$.dien_giai_thue&&($o_tt_tt$$.dien_giai=$o_tt_tt$$.dien_giai_thue);$details$$.push($o_tt_tt$$);const $details_giavon$$=
|
|
22
|
+
[];$obj$$.details.forEach(function($d$jscomp$11_detail$$){$d$jscomp$11_detail$$={...$d$jscomp$11_detail$$};$d$jscomp$11_detail$$.tk_no=$d$jscomp$11_detail$$.tk_gv;$d$jscomp$11_detail$$.ma_kh||($d$jscomp$11_detail$$.ma_kh=$obj$$.ma_kh);$d$jscomp$11_detail$$.tk_co=$d$jscomp$11_detail$$.tk_vt;$d$jscomp$11_detail$$.tien_nt=$d$jscomp$11_detail$$.tien_xuat_nt;$d$jscomp$11_detail$$.tien=$d$jscomp$11_detail$$.tien_xuat;$details_giavon$$.push($d$jscomp$11_detail$$);$d$jscomp$11_detail$$.promotion&&$d$jscomp$11_detail$$.promotion.details_km&&
|
|
23
|
+
$d$jscomp$11_detail$$.promotion.details_km.forEach($detail$$=>{$detail$$.ma_vt&&($detail$$.tk_no=$detail$$.tk_gv,$detail$$.ma_kh||($detail$$.ma_kh=$obj$$.ma_kh),$detail$$.tk_co=$detail$$.tk_vt,$detail$$.tien_nt=$detail$$.tien_xuat_nt||0,$detail$$.tien=$detail$$.tien_xuat||0,$details_giavon$$.push($detail$$))})});$obj$$.promotion&&$obj$$.promotion.forEach(function($detail$$){$detail$$.ma_vt&&($detail$$.tk_no=$detail$$.tk_gv,$detail$$.ma_kh||($detail$$.ma_kh=$obj$$.ma_kh),$detail$$.tk_co=$detail$$.tk_vt,
|
|
24
|
+
$detail$$.tien_nt=$detail$$.tien_xuat_nt||0,$detail$$.tien=$detail$$.tien_xuat||0,$details_giavon$$.push($detail$$))});async.series({xdtk:$callback$$=>{$details_giavon$$.joinModel2($obj$$.id_app,dmvt,{where:"ma_vt",fields:["tk_vt","gia_mua","tk_gv"]},()=>{$details_giavon$$.forEach($s$$=>{$s$$.tk_co||($s$$.tk_co=$s$$.tk_vt||$options$$.tk_vt);$s$$.tk_no||($s$$.tk_no=$s$$.tk_gv||$options$$.tk_gv)});$callback$$()})}},()=>{$details$$=$details$$.concat($details_giavon$$);(new PostSocai($obj$$,$details$$)).run(function($e$$,
|
|
25
|
+
$rs$$){$callback$jscomp$0$$($e$$,$rs$$)})})},post_tdttno:function($callback$jscomp$0$$){account.findOne({tk:$obj$$.tk_no,id_app:$obj$$.id_app},{tk_cn:1},function($error$jscomp$0$$,$tk$$){if($error$jscomp$0$$)return $callback$jscomp$0$$($error$jscomp$0$$);$tk$$&&!0===$tk$$.tk_cn?(new PostBook($obj$$,[{...$obj$$}],Tdttno,function($detail$$,$callback$$){try{$detail$$.so_hd||($detail$$.so_hd=$obj$$.so_ct),$detail$$.ngay_hd||($detail$$.ngay_hd=$obj$$.ngay_ct),$detail$$.tien_nt=$obj$$.details.csum("tien_nt")-
|
|
26
|
+
$obj$$.details.csum("tien_ck_nt")+($obj$$.tien_thue_dc_nt||$obj$$.details.csum("tien_thue_nt")),$detail$$.tien=$detail$$.tien_nt*$obj$$.ty_gia}catch($e$$){console.error($e$$,$obj$$)}$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$jscomp$0$$($e$$,$rs$$)}):Tdttno.deleteMany({id_ct:$obj$$._id},function($error$$){$callback$jscomp$0$$($error$$)})})}},function($e$$,$rs$$){$fn$$($e$$,$rs$$)})};const $valid$$=function($i$jscomp$1_t_thue_nt_user$$,$obj$$,$next$$){for($i$jscomp$1_t_thue_nt_user$$=
|
|
27
|
+
0;$i$jscomp$1_t_thue_nt_user$$<$obj$$.details.length;$i$jscomp$1_t_thue_nt_user$$++){var $detail$jscomp$0$$=$obj$$.details[$i$jscomp$1_t_thue_nt_user$$];$obj$$.ma_kho&&($detail$jscomp$0$$.ma_kho=$obj$$.ma_kho);$detail$jscomp$0$$.line=$i$jscomp$1_t_thue_nt_user$$;"VND"===$obj$$.ma_nt&&($detail$jscomp$0$$.tien=$detail$jscomp$0$$.tien_nt,$detail$jscomp$0$$.gia_ban=$detail$jscomp$0$$.gia_ban_nt,$detail$jscomp$0$$.tien_ck=$detail$jscomp$0$$.tien_ck_nt);$detail$jscomp$0$$.tien_xuat=$detail$jscomp$0$$.tien_xuat_nt;
|
|
28
|
+
$detail$jscomp$0$$.tien_ck=$detail$jscomp$0$$.tien_ck||0;$detail$jscomp$0$$.tien_ck_nt=$detail$jscomp$0$$.tien_ck_nt||0}$obj$$.thue_suat=$obj$$.thue_suat||0;let $f_tien_nt$$="VND"==$obj$$.ma_nt?0:2;$obj$$.details.forEach($detail$$=>{let $thue_suat$$=($detail$$.ma_thue?$detail$$.thue_suat:$obj$$.thue_suat)||0;$detail$$.tien_thue=utils.round(($detail$$.tien-$detail$$.tien_ck)*$thue_suat$$/100,0);$detail$$.tien_thue_nt=utils.round(($detail$$.tien_nt-$detail$$.tien_ck_nt)*$thue_suat$$/100,$f_tien_nt$$)});
|
|
29
|
+
if(!$obj$$.details.find($r$$=>$r$$.ma_thue)&&void 0!=$obj$$.thue_suat&&($obj$$.t_thue_nt=$obj$$.tien_thue_dc_nt||utils.round(($obj$$.details.csum("tien_nt")-$obj$$.details.csum("tien_ck_nt"))*$obj$$.thue_suat/100,$f_tien_nt$$),$obj$$.t_thue=utils.round($obj$$.t_thue_nt*($obj$$.ty_gia||1),0),$i$jscomp$1_t_thue_nt_user$$=$obj$$.details.csum("tien_thue_nt"),$detail$jscomp$0$$=$obj$$.details.csum("tien_thue"),($i$jscomp$1_t_thue_nt_user$$!==$obj$$.t_thue_nt||$detail$jscomp$0$$!==$obj$$.t_thue)&&0<$obj$$.details.length)){let $row_dieu_chinh$$=
|
|
30
|
+
$obj$$.details[$obj$$.details.length-1];$row_dieu_chinh$$.tien_thue_nt+=$obj$$.t_thue_nt-$i$jscomp$1_t_thue_nt_user$$;$row_dieu_chinh$$.tien_thue+=$obj$$.t_thue-$detail$jscomp$0$$}$obj$$.id_contract?salecontract.findOne({_id:$obj$$.id_contract}).lean().exec(($e$$,$c$$)=>{$c$$&&($obj$$.ma_hd=$c$$.ma_hd);$next$$(null,$obj$$)}):$next$$(null,$obj$$)};$contr$$.creating=function($user$$,$obj$$,$next$$){$obj$$.details||($obj$$.details=[]);$valid$$($user$$,$obj$$,function($error$$){if($error$$)return $next$$($error$$);
|
|
31
|
+
$obj$$.result_export_einvoice=null;$next$$(null,$obj$$)})};$contr$$.updating=function($user$$,$data$$,$obj$$,$next$$){Tdttno_tt.findOne({id_hd:$obj$$._id},function($error$jscomp$0$$,$ct_tt$$){if($error$jscomp$0$$)return $next$$($error$jscomp$0$$);$ct_tt$$?$next$$(`Kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt phi\u1ebfu n\u00e0y do \u0111\u00e3 \u0111\u01b0\u1ee3c thanh to\u00e1n b\u1edfi ${$ct_tt$$.ma_ct||"ch\u1ee9ng t\u1eeb"}: ${$ct_tt$$.so_ct}, ng\u00e0y ${Moment($ct_tt$$.ngay_ct).format("DD/MM/YYYY")}`):
|
|
32
|
+
$valid$$($user$$,$data$$,function($error$$){if($error$$)return $next$$($error$$);$next$$(null,$data$$,$obj$$)})})};$contr$$.deleting=function($user$$,$obj$$,$next$$){Tdttno_tt.findOne({id_hd:$obj$$._id},function($error$$,$ct_tt$$){if($error$$)return $next$$($error$$);$ct_tt$$?$next$$(`Kh\u00f4ng th\u1ec3 xo\u00e1 phi\u1ebfu n\u00e0y do \u0111\u00e3 \u0111\u01b0\u1ee3c thanh to\u00e1n b\u1edfi ${$ct_tt$$.ma_ct||"ch\u1ee9ng t\u1eeb"}: ${$ct_tt$$.so_ct}, ng\u00e0y ${Moment($ct_tt$$.ngay_ct).format("DD/MM/YYYY")}`):
|
|
33
|
+
$next$$(null,$obj$$)})};$contr$$.view=function($user$$,$items$$,$fn$$){const $id_app$$=$user$$.current_id_app;async.series({dv:function($callback$$){$items$$.filter($item$$=>$item$$.ma_dvcs).joinModel($id_app$$,dvcs,[{akey:"ma_dvcs",bkey:"_id",fields:[{name:"ten_dvcs",value:"ten_dvcs"}]}],function(){$callback$$()})},tk:function($callback$$){$items$$.filter($item$$=>$item$$.tk_no).joinModel($id_app$$,account,[{akey:"tk_no",bkey:"tk",fields:[{name:"ten_tk_no",value:"ten_tk"}]}],function(){$callback$$()})},
|
|
34
|
+
dt:function($callback$$){$items$$.filter($item$$=>$item$$.ma_dt).joinModel($id_app$$,dmdt,[{akey:"ma_dt",bkey:"ma_dt",fields:[{name:"ten_dt",value:"ten_dt"}]}],function(){$callback$$()})},kh:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kh).joinModel2($id_app$$,customer,[{where:"ma_kh",fields:["ten_kh","email","nh_kh"]}],function(){$callback$$()})},nv:function($callback$$){$items$$.filter($item$$=>$item$$.ma_nv).joinModel($id_app$$,dmnv,[{akey:"ma_nv",bkey:"ma_nv",fields:[{name:"ten_nv",
|
|
35
|
+
value:"ten_nv"}]}],function(){$callback$$()})},trangthai:function($callback$$){$items$$.filter($item$$=>$item$$.trang_thai).joinModel2(null,trangthai,[{where:{trang_thai:"ma_trang_thai",ma_ct:"ma_ct"},fields:["ten_trang_thai","color"]}],function(){$callback$$()})},contract:function($callback$$){$items$$.filter($item$$=>$item$$.ma_hd).joinModel2($id_app$$,contract,[{where:{ma_hd:"so_hd"},fields:["ten_hd","ten_hd"]}],function(){$callback$$()})},t_tien:function($callback$$){$items$$.forEach(function($r$$){$r$$.details&&
|
|
36
|
+
($r$$.t_sl=$r$$.details.csum("sl_xuat"),$r$$.t_tien=$r$$.details.csum("tien"),$r$$.t_tien_nt=$r$$.details.csum("tien_nt"),$r$$.t_ck=$r$$.details.csum("tien_ck"),$r$$.t_ck_nt=$r$$.details.csum("tien_ck_nt"),$r$$.tc_ck_nt=$r$$.t_ck_nt+($r$$.tien_ck_hd||0),$r$$.tc_ck=$r$$.t_ck+($r$$.tien_ck_hd||0)*$r$$.ty_gia,$r$$.t_thue=$r$$.details.csum("tien_thue"),$r$$.t_thue_nt=$r$$.details.csum("tien_thue_nt"),$r$$.t_tt=$r$$.t_tien+$r$$.t_thue-$r$$.tc_ck,$r$$.t_tt_nt=$r$$.t_tien_nt+$r$$.t_thue_nt-$r$$.tc_ck_nt,
|
|
37
|
+
$r$$.t_tien_xuat=$r$$.details.csum("tien_xuat"),$r$$.t_tien_xuat_nt=$r$$.details.csum("tien_xuat_nt"))});$callback$$()},details_tk:function($callback$jscomp$0$$){async.mapSeries($items$$,function($r$$,$callback1$$){const $details$$=$r$$.details;async.series({tk:function($callback$$){$details$$.joinModel($id_app$$,account,[{akey:"tk_vt",bkey:"tk",fields:[{name:"ten_tk_vt",value:"ten_tk"}]},{akey:"tk_dt",bkey:"tk",fields:[{name:"ten_tk_dt",value:"ten_tk"}]},{akey:"tk_ck",bkey:"tk",fields:[{name:"ten_tk_ck",
|
|
38
|
+
value:"ten_tk"}]},{akey:"tk_gv",bkey:"tk",fields:[{name:"ten_tk_gv",value:"ten_tk"}]}],function(){$callback$$()})},kho:function($callback$$){$details$$.filter($item$$=>$item$$.ma_kho).joinModel($id_app$$,dmkho,[{akey:"ma_kho",bkey:"ma_kho",fields:[{name:"ten_kho",value:"ten_kho"}]}],function(){$callback$$()})}},function(){$callback1$$()})},function(){$callback$jscomp$0$$()})},details_vt:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){$r$$.details.joinModel($id_app$$,dmvt,
|
|
39
|
+
[{akey:"ma_vt",bkey:"ma_vt",fields:[{name:"ten_vt",value:"ten_vt"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_dt:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){$r$$.details.filter($item$$=>$item$$.ma_dt).joinModel($id_app$$,dmdt,[{akey:"ma_dt",bkey:"ma_dt",fields:[{name:"ten_dt",value:"ten_dt"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_contract:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){$r$$.details.filter($item$$=>
|
|
40
|
+
$item$$.ma_hd).joinModel($id_app$$,contract,[{akey:"ma_hd",bkey:"so_hd",fields:[{name:"ten_hd",value:"ten_hd"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_phi:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){$r$$.details.filter($item$$=>$item$$.ma_phi).joinModel($id_app$$,dmphi,[{akey:"ma_phi",bkey:"ma_phi",fields:[{name:"ten_phi",value:"ten_phi"}]}],function(){$callback1$$()})},function(){$callback$$()})}},function(){$fn$$(null,$items$$)})};$contr$$.createRoute("export2viettel/:id_ct",
|
|
41
|
+
async($data$jscomp$1_kh$$,$next$$)=>{var $id_app$$=$data$jscomp$1_kh$$.user.current_id_app,$app_msg_e$$=await App.findOne({_id:$id_app$$});if(!$app_msg_e$$)return $next$$("Kh\u00f4ng t\u00ecm th\u1ea5y c\u00f4ng ty n\u00e0y");if(!$app_msg_e$$.viettel_url_service||!$app_msg_e$$.viettel_user||!$app_msg_e$$.viettel_password)return $next$$("Th\u00f4ng tin xu\u1ea5t ho\u00e1 \u0111\u01a1n Viettel ch\u01b0a \u0111\u01b0\u1ee3c khai b\u00e1o \u0111\u1ea7y \u0111\u1ee7");if(!$app_msg_e$$.ma_so_thue)return $next$$("B\u1ea1n ch\u01b0a nh\u1eadp m\u00e3 s\u1ed1 thu\u1ebf c\u1ee7a c\u00f4ng ty");
|
|
42
|
+
const $ct$$=await model.findOne({id_app:$id_app$$,_id:$data$jscomp$1_kh$$.params.id_ct}).lean();if(!$ct$$)return $next$$("Ch\u1ee9ng t\u1eeb kh\u00f4ng h\u1ee3p l\u1ec7");if($ct$$.result_export_einvoice&&$ct$$.result_export_einvoice.result&&$ct$$.result_export_einvoice.result.transactionID)return $next$$("Ho\u00e1 \u0111\u01a1n n\u00e0y \u0111\u00e3 \u0111\u01b0\u1ee3c xu\u1ea5t sang ho\u00e1 \u0111\u01a1n \u0111i\u1ec7n t\u1eed Viettel");$data$jscomp$1_kh$$=await customer.findOne({id_app:$id_app$$,
|
|
43
|
+
ma_kh:$ct$$.ma_kh})||{};await $ct$$.details.asyncJoinModel2($id_app$$,dmvt,{where:"ma_vt",fields:"ten_vt"});$id_app$$=Math.abs($ct$$.details.map($d$$=>$d$$.tien_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0));var $auth_t_ck$$=Math.abs($ct$$.details.map($d$$=>$d$$.tien_ck_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0));const $t_tien$$=Math.abs($ct$$.details.map($d$$=>$d$$.tien_nt-$d$$.tien_ck_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0)),$t_thue$$=Math.abs($ct$$.details.map($d$$=>$d$$.tien_thue_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,
|
|
44
|
+
0));let $taxBreakdowns$$=$ct$$.details.map($detail$$=>({...$detail$$,ma_thue:$detail$$.ma_thue||$ct$$.ma_thue,thue_suat:($detail$$.ma_thue?$detail$$.thue_suat:$ct$$.thue_suat)||0})).filter($d$$=>$d$$.ma_thue);if(0===$taxBreakdowns$$.length)return $next$$("B\u1ea1n ch\u01b0a khai b\u00e1o thu\u1ebf");$taxBreakdowns$$=$taxBreakdowns$$.filter($d$$=>"KT"!==$d$$.ma_thue).map($detail$$=>({taxPercentage:"KT"===$detail$$.ma_thue?-2:$detail$$.thue_suat,taxableAmount:Math.abs($detail$$.tien_nt-$detail$$.tien_ck_nt),
|
|
45
|
+
taxAmount:Math.abs($detail$$.tien_thue_nt)}));$taxBreakdowns$$=await $taxBreakdowns$$.asyncGroupBy("taxPercentage",["taxableAmount","taxAmount"]);$data$jscomp$1_kh$$={generalInvoiceInfo:{invoiceType:$ct$$.ma_hoa_don||$app_msg_e$$.ma_hoa_don||"1",templateCode:$ct$$.ky_hieu_hoa_don||$app_msg_e$$.ky_hieu_hoa_don||"1/001",invoiceSeries:$ct$$.so_seri,currencyCode:"VND",adjustmentType:"1",paymentStatus:!0,cusGetInvoiceRight:!0,userName:$ct$$.user_created},buyerInfo:{buyerName:$ct$$.ong_ba||"",buyerLegalName:$ct$$.ten_kh||
|
|
46
|
+
$data$jscomp$1_kh$$.ten_kh||"",buyerTaxCode:$ct$$.ma_so_thue||$data$jscomp$1_kh$$.ma_so_thue||"",buyerAddressLine:$ct$$.dia_chi||$data$jscomp$1_kh$$.dia_chi||"",buyerPostalCode:"",buyerDistrictName:"",buyerCityName:"",buyerCountryCode:"",buyerPhoneNumber:$ct$$.dien_thoai||$data$jscomp$1_kh$$.dien_thoai||"",buyerFaxNumber:"",buyerEmail:$data$jscomp$1_kh$$.email||"",buyerBankName:"",buyerBankAccount:"",buyerIdType:"",buyerIdNo:"",buyerCode:"",buyerBirthDay:""},sellerInfo:{sellerLegalName:$app_msg_e$$.name,
|
|
47
|
+
sellerTaxCode:$app_msg_e$$.ma_so_thue,sellerAddressLine:$app_msg_e$$.address,sellerPhoneNumber:$app_msg_e$$.phone||"",sellerEmail:$app_msg_e$$.email||"",sellerBankName:$app_msg_e$$.ten_ngan_hang||"",sellerBankAccount:$app_msg_e$$.tai_khoan_ngan_hang||""},itemInfo:$ct$$.details.map(($detail$$,$index$$)=>{let $thue_suat$$=($detail$$.ma_thue?$detail$$.thue_suat:$ct$$.thue_suat)||0;return{lineNumber:$index$$+1,selection:0>$detail$$.tien_nt?3:1,itemCode:$detail$$.ma_vt,itemName:$detail$$.ten_vt_vat||$detail$$.ten_vt,
|
|
48
|
+
unitName:0>$detail$$.tien_nt?"":$detail$$.ma_dvt,itemNote:"",unitPrice:0>$detail$$.tien_nt?void 0:$detail$$.gia_ban_nt,quantity:0>$detail$$.tien_nt?void 0:$detail$$.sl_xuat,itemTotalAmountWithoutTax:Math.abs($detail$$.tien_nt),discount:$detail$$.ty_le_ck,itemDiscount:Math.abs($detail$$.tien_ck_nt),itemTotalAmountAfterDiscount:Math.abs($detail$$.tien_nt-$detail$$.tien_ck_nt),taxPercentage:"KT"===($detail$$.ma_thue||$ct$$.ma_thue)?0>$detail$$.tien_nt?void 0:-2:$thue_suat$$,taxAmount:Math.abs($detail$$.tien_thue_nt),
|
|
49
|
+
itemTotalAmountWithTax:Math.abs($detail$$.tien_nt-$detail$$.tien_ck_nt+$detail$$.tien_thue_nt),customTaxAmount:"0",batchNo:"",expDate:""}}),summarizeInfo:{sumOfTotalLineAmountWithoutTax:$id_app$$,discountAmount:$auth_t_ck$$,settlementDiscountAmount:$auth_t_ck$$,totalAmountWithoutTax:$t_tien$$,totalTaxAmount:$t_thue$$,totalAmountWithTax:$t_tien$$+$t_thue$$},taxBreakdowns:$taxBreakdowns$$,payments:[{paymentMethodName:$ct$$.hinh_thuc_tt||"TM"}],extAttribute:[],deliveryInfo:{},metadata:[]};$ct$$.ngay_hd||
|
|
50
|
+
($ct$$.ngay_hd=new Date);let $viettel_token$$;$auth_t_ck$$={username:$app_msg_e$$.viettel_user.trim(),password:$app_msg_e$$.viettel_password.trim()};if("1"!=$app_msg_e$$.viettel_version){$data$jscomp$1_kh$$.generalInvoiceInfo.invoiceIssuedDate=(new Date($ct$$.ngay_hd)).getTime();$id_app$$=$app_msg_e$$.viettel_direct_issue?`${$app_msg_e$$.viettel_url_service.trim()}/services/einvoiceapplication/api/InvoiceAPI/InvoiceWS/createInvoice/${$app_msg_e$$.ma_so_thue.trim()}`:`${$app_msg_e$$.viettel_url_service.trim()}/services/einvoiceapplication/api/InvoiceAPI/InvoiceWS/createOrUpdateInvoiceDraft/${$app_msg_e$$.ma_so_thue.trim()}`;
|
|
51
51
|
var $headers_url_token$$=`${$app_msg_e$$.viettel_url_service.trim()}/auth/login`;try{$viettel_token$$=(await axios({method:"post",url:$headers_url_token$$,data:$auth_t_ck$$})).data.access_token}catch($e$$){return console.error("error when get token viettel",$auth_t_ck$$,$headers_url_token$$),($app_msg_e$$=$e$$.response?$e$$.response.data:$e$$.message)&&$app_msg_e$$.detail&&($app_msg_e$$.message=$app_msg_e$$.detail),$next$$($app_msg_e$$||$e$$.message||$e$$.error||$e$$)}$headers_url_token$$={Cookie:`"access_token":"${$viettel_token$$}"; access_token=${$viettel_token$$}; session_token=${$viettel_token$$}`,
|
|
52
52
|
"Content-Type":"application/json"};$auth_t_ck$$=void 0}else $data$jscomp$1_kh$$.generalInvoiceInfo.invoiceIssuedDate=Moment($ct$$.ngay_hd).format("YYYY-MM-DD"),$id_app$$=$app_msg_e$$.viettel_direct_issue?`${$app_msg_e$$.viettel_url_service.trim()}/InvoiceAPI/InvoiceWS/createInvoice/${$app_msg_e$$.ma_so_thue.trim()}`:`${$app_msg_e$$.viettel_url_service.trim()}/InvoiceAPI/InvoiceWS/createOrUpdateInvoiceDraft/${$app_msg_e$$.ma_so_thue.trim()}`;axios({method:"post",url:$id_app$$,data:"1"!=$app_msg_e$$.viettel_version?
|
|
53
53
|
JSON.stringify($data$jscomp$1_kh$$):$data$jscomp$1_kh$$,auth:$auth_t_ck$$,headers:$headers_url_token$$}).then(async $data$$=>{$data$$=$data$$.data;if(!$data$$)return $next$$("Kh\u00f4ng th\u1ec3 xu\u1ea5t ho\u00e1 \u0111\u01a1n");if($data$$.errorCode)return $next$$($data$$.description);$ct$$.result_export_einvoice=$data$$;$ct$$.so_hd=$ct$$.result_export_einvoice.result.invoiceNo;await model.findOneAndUpdate({_id:$ct$$._id},$ct$$);await Tdttno.updateMany({id_ct:$ct$$._id.toString()},{so_hd:$ct$$.so_hd});
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
'use strict';const dmkho=global.getModel("dmkho"),dvcs=global.getModel("dvcs"),dmvt=global.getModel("dmvt"),account=global.getModel("account"),customer=global.getModel("customer"),dmdt=global.getModel("dmdt"),dmphi=global.getModel("dmphi"),contract=global.getModel("contract"),purchasecontract=global.getModel("purchase_contract"),po1=global.getModel("po1"),model=global.getModel("pnh"),controller=require("../../controllers/controller"),trangthai=global.getModel("trangthai"),async=require("async"),ma_ct=
|
|
2
|
-
"PNH",Sokhott=global.getModel("sokhott"),PostBook=require("../../libs/post-book");
|
|
2
|
+
"PNH",Sokhott=global.getModel("sokhott"),Sokho=global.getModel("sokho"),Options=global.getModel("options"),PostBook=require("../../libs/post-book");
|
|
3
3
|
module.exports=function($contr_router$$){$contr_router$$=new controller($contr_router$$,model,ma_ct.toLowerCase(),{isVoucher:!0,sort:{ngay_ct:-1,so_ct:-1}});$contr_router$$.route();const $valid$$=async($_po1_i_user$$,$obj$$,$next$$)=>{for($_po1_i_user$$=0;$_po1_i_user$$<$obj$$.details.length;$_po1_i_user$$++){const $detail$$=$obj$$.details[$_po1_i_user$$];$detail$$.line=$_po1_i_user$$;$detail$$.tien_hang_nt=$detail$$.tien_hang_nt?$detail$$.tien_hang_nt:$detail$$.sl_nhap*$detail$$.gia_von_nt;$detail$$.tien_hang=
|
|
4
4
|
$detail$$.tien_hang?$detail$$.tien_hang:$detail$$.sl_nhap*$detail$$.gia_von;$detail$$.tien_nhap_nt=($detail$$.tien_hang_nt||0)+($detail$$.tien_phi_nt||0)-($detail$$.tien_ck_nt||0);$detail$$.tien_nhap=($detail$$.tien_hang||0)+($detail$$.tien_phi||0)-($detail$$.tien_ck||0);"VND"===$obj$$.ma_nt&&($detail$$.tien_hang=$detail$$.tien_hang_nt,$detail$$.tien_ck=$detail$$.tien_ck_nt,$detail$$.tien_phi=$detail$$.tien_phi_nt,$detail$$.tien_nhap=$detail$$.tien_nhap_nt);$obj$$.ma_kho&&($detail$$.ma_kho=$obj$$.ma_kho)}$obj$$.id_po1&&
|
|
5
|
-
!$obj$$.id_contract&&($_po1_i_user$$=await po1.findOne({_id:$obj$$.id_po1}))&&($obj$$.id_contract=$_po1_i_user$$.id_contract);$obj$$.id_contract?purchasecontract.findOne({_id:$obj$$.id_contract}).lean().exec(($e$$,$c$$)=>{$c$$&&($obj$$.ma_hd=$c$$.ma_hd);$next$$(null,$obj$$)}):$next$$(null,$obj$$)};$contr_router$$.post=function($obj$$,$fn$$){$fn$$||($fn$$=function(){});
|
|
6
|
-
{$detail$$={...$detail$$,nxt:1};$detail$$.tk_co=$obj$$.tk_co;$callback$$($detail$$)})).run(function(){$callback$jscomp$0$$()})}
|
|
7
|
-
$
|
|
5
|
+
!$obj$$.id_contract&&($_po1_i_user$$=await po1.findOne({_id:$obj$$.id_po1}))&&($obj$$.id_contract=$_po1_i_user$$.id_contract);$obj$$.id_contract?purchasecontract.findOne({_id:$obj$$.id_contract}).lean().exec(($e$$,$c$$)=>{$c$$&&($obj$$.ma_hd=$c$$.ma_hd);$next$$(null,$obj$$)}):$next$$(null,$obj$$)};$contr_router$$.post=async function($obj$$,$fn$$){$fn$$||($fn$$=function(){});let $options$$;try{$options$$=await Options.getInfo($obj$$.id_app,{id_func:$obj$$.ma_ct.toLowerCase()},"option")}catch($e$$){console.log($e$$.message,
|
|
6
|
+
{id_func:$obj$$.ma_ct})}$options$$||($options$$={});async.series({post_sokhott:function($callback$jscomp$0$$){$options$$.not_post_sokhott?$callback$jscomp$0$$():(new PostBook($obj$$,$obj$$.details,Sokhott,async($detail$$,$callback$$)=>{$detail$$={...$detail$$,nxt:1};$detail$$.tk_co=$obj$$.tk_co;$callback$$($detail$$)})).run(function(){$callback$jscomp$0$$()})},post_sokho:function($callback$jscomp$0$$){$options$$.post_sokho?$callback$jscomp$0$$():(new PostBook($obj$$,$obj$$.details,Sokho,async($detail$$,
|
|
7
|
+
$callback$$)=>{$detail$$={...$detail$$,nxt:1};$detail$$.tk_co=$obj$$.tk_co;$callback$$($detail$$)})).run(function(){$callback$jscomp$0$$()})}},function($e$$,$rs$$){$fn$$($e$$,$rs$$)})};$contr_router$$.creating=function($user$$,$obj$$,$next$$){$obj$$.details||($obj$$.details=[]);$valid$$($user$$,$obj$$,function($error$$){if($error$$)return $next$$($error$$);$next$$(null,$obj$$)})};$contr_router$$.updating=function($user$$,$data$$,$obj$$,$next$$){$valid$$($user$$,$data$$,function($error$$){if($error$$)return $next$$($error$$);
|
|
8
|
+
$next$$(null,$data$$,$obj$$)})};$contr_router$$.on("saved",function($obj$$){$obj$$.id_po1&&po1.updateMany({_id:$obj$$.id_po1},{id_pnh:$obj$$._id.toString()},($e$jscomp$2$$,$rs$jscomp$0$$)=>{console.log("update po1",$rs$jscomp$0$$);po1.updateMany({_id:$obj$$.id_po1,trang_thai:{$ne:"7"}},{trang_thai:"6"},($e$jscomp$1$$,$rs$$)=>{console.log("update po1",$rs$$);po1.findOne({_id:$obj$$.id_po1},($e$jscomp$0$$,$_obj$$)=>{$_obj$$&&controller.postData($_obj$$,global.controllers.PO1,$e$$=>{$e$$&&console.error($e$$)})})})})});
|
|
8
9
|
$contr_router$$.on("deleted",function($obj$$){$obj$$.id_po1&&po1.updateMany({_id:$obj$$.id_po1},{id_pnh:""},()=>{po1.updateMany({_id:$obj$$.id_po1,trang_thai:{$ne:"7"}},{trang_thai:"3"},($e$jscomp$1$$,$rs$$)=>{console.log("update po1",$rs$$);po1.findOne({_id:$obj$$.id_po1},($e$jscomp$0$$,$_obj$$)=>{$_obj$$&&controller.postData($_obj$$,global.controllers.PO1,$e$$=>{$e$$&&console.error($e$$)})})})})});$contr_router$$.view=function($user$$,$items$$,$fn$$){let $id_app$$=$user$$.current_id_app;async.series({dv:function($callback$$){$items$$.filter($item$$=>
|
|
9
10
|
$item$$.ma_dvcs).joinModel($id_app$$,dvcs,[{akey:"ma_dvcs",bkey:"_id",fields:[{name:"ten_dvcs",value:"ten_dvcs"}]}],function(){$callback$$()})},tk:function($callback$$){$items$$.filter($item$$=>$item$$.tk_co).joinModel($id_app$$,account,[{akey:"tk_co",bkey:"tk",fields:[{name:"ten_tk_co",value:"ten_tk"}]}],function(){$callback$$()})},dt:function($callback$$){$items$$.filter($item$$=>$item$$.ma_dt).joinModel($id_app$$,dmdt,[{akey:"ma_dt",bkey:"ma_dt",fields:[{name:"ten_dt",value:"ten_dt"}]}],function(){$callback$$()})},
|
|
10
11
|
kh:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kh).joinModel($id_app$$,customer,[{akey:"ma_kh",bkey:"ma_kh",fields:[{name:"ten_kh",value:"ten_kh"}]}],function(){$callback$$()})},kho:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kho).joinModel($id_app$$,dmkho,[{akey:"ma_kho",bkey:"ma_kho",fields:[{name:"ten_kho",value:"ten_kho"}]}],function(){$callback$$()})},trangthai:function($callback$$){$items$$.filter($item$$=>$item$$.trang_thai).joinModel2(null,trangthai,[{where:{trang_thai:"ma_trang_thai",
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
'use strict';const dmkho=global.getModel("dmkho"),dvcs=global.getModel("dvcs"),dmvt=global.getModel("dmvt"),customer=global.getModel("customer"),dmdt=global.getModel("dmdt"),dmphi=global.getModel("dmphi"),contract=global.getModel("contract"),salecontract=global.getModel("sale_contract"),so1=global.getModel("so1"),model=global.getModel("pxh"),controller=require("../../controllers/controller"),trangthai=global.getModel("trangthai"),async=require("async"),ma_ct="PXH",Sokhott=global.getModel("sokhott"),
|
|
2
|
-
PostBook=require("../../libs/post-book");
|
|
2
|
+
Sokho=global.getModel("sokho"),Options=global.getModel("options"),PostBook=require("../../libs/post-book");
|
|
3
3
|
module.exports=function($contr_router$$){$contr_router$$=new controller($contr_router$$,model,ma_ct.toLowerCase(),{isVoucher:!0,sort:{ngay_ct:-1,so_ct:-1}});$contr_router$$.route();const $valid$$=async($_so1_i_user$$,$obj$$,$next$$)=>{for($_so1_i_user$$=0;$_so1_i_user$$<$obj$$.details.length;$_so1_i_user$$++){const $detail$$=$obj$$.details[$_so1_i_user$$];$detail$$.line=$_so1_i_user$$;$detail$$.tien_hang_nt=$detail$$.tien_hang_nt?$detail$$.tien_hang_nt:$detail$$.sl_xuat*$detail$$.gia_von_nt;$detail$$.tien_hang=
|
|
4
4
|
$detail$$.tien_hang?$detail$$.tien_hang:$detail$$.sl_xuat*$detail$$.gia_von;$detail$$.tien_xuat_nt=($detail$$.tien_hang_nt||0)+($detail$$.tien_phi_nt||0)-($detail$$.tien_ck_nt||0);$detail$$.tien_xuat=($detail$$.tien_hang||0)+($detail$$.tien_phi||0)-($detail$$.tien_ck||0);"VND"===$obj$$.ma_nt&&($detail$$.tien_hang=$detail$$.tien_hang_nt,$detail$$.tien_ck=$detail$$.tien_ck_nt,$detail$$.tien_phi=$detail$$.tien_phi_nt,$detail$$.tien_xuat=$detail$$.tien_xuat_nt);$obj$$.ma_kho&&($detail$$.ma_kho=$obj$$.ma_kho)}$obj$$.id_so1&&
|
|
5
|
-
!$obj$$.id_contract&&($_so1_i_user$$=await so1.findOne({_id:$obj$$.id_so1}))&&($obj$$.id_contract=$_so1_i_user$$.id_contract);$obj$$.id_contract?salecontract.findOne({_id:$obj$$.id_contract}).lean().exec(($e$$,$c$$)=>{$c$$&&($obj$$.ma_hd=$c$$.ma_hd);$next$$(null,$obj$$)}):$next$$(null,$obj$$)};$contr_router$$.post=function($obj$$,$fn$$){$fn$$||($fn$$=function(){});
|
|
6
|
-
{...$detail$$,nxt:2};$detail$$.tk_no=$obj$$.tk_no;$callback$$($detail$$)})).run(function(){$callback$jscomp$0$$()})
|
|
5
|
+
!$obj$$.id_contract&&($_so1_i_user$$=await so1.findOne({_id:$obj$$.id_so1}))&&($obj$$.id_contract=$_so1_i_user$$.id_contract);$obj$$.id_contract?salecontract.findOne({_id:$obj$$.id_contract}).lean().exec(($e$$,$c$$)=>{$c$$&&($obj$$.ma_hd=$c$$.ma_hd);$next$$(null,$obj$$)}):$next$$(null,$obj$$)};$contr_router$$.post=async function($obj$$,$fn$$){$fn$$||($fn$$=function(){});let $options$$;try{$options$$=await Options.getInfo($obj$$.id_app,{id_func:$obj$$.ma_ct.toLowerCase()},"option")}catch($e$$){console.log($e$$.message,
|
|
6
|
+
{id_func:$obj$$.ma_ct})}$options$$||($options$$={});async.series({post_sokho:function($callback$jscomp$0$$){$options$$.post_sokho?(new PostBook($obj$$,$obj$$.details,Sokho,async($detail$$,$callback$$)=>{$detail$$={...$detail$$,nxt:2};$detail$$.tk_no=$obj$$.tk_no;$callback$$($detail$$)})).run(function(){$callback$jscomp$0$$()}):$callback$jscomp$0$$()},post_sokhott:function($callback$jscomp$0$$){$options$$.not_post_sokhott?$callback$jscomp$0$$():(new PostBook($obj$$,$obj$$.details,Sokhott,async($detail$$,
|
|
7
|
+
$callback$$)=>{$detail$$={...$detail$$,nxt:2};$detail$$.tk_no=$obj$$.tk_no;$callback$$($detail$$)})).run(function(){$callback$jscomp$0$$()})}},function($e$$,$rs$$){$fn$$($e$$,$rs$$)})};$contr_router$$.creating=function($user$$,$obj$$,$next$$){$obj$$.details||($obj$$.details=[]);$valid$$($user$$,$obj$$,function($error$$){if($error$$)return $next$$($error$$);$next$$(null,$obj$$)})};$contr_router$$.updating=function($user$$,$data$$,$obj$$,$next$$){$valid$$($user$$,$data$$,function($error$$){if($error$$)return $next$$($error$$);
|
|
7
8
|
$next$$(null,$data$$,$obj$$)})};$contr_router$$.view=function($user$$,$items$$,$fn$$){let $id_app$$=$user$$.current_id_app;async.series({dv:function($callback$$){$items$$.joinModel($id_app$$,dvcs,[{akey:"ma_dvcs",bkey:"_id",fields:[{name:"ten_dvcs",value:"ten_dvcs"}]}],function(){$callback$$()})},dt:function($callback$$){$items$$.filter($item$$=>$item$$.ma_dt).joinModel($id_app$$,dmdt,[{akey:"ma_dt",bkey:"ma_dt",fields:[{name:"ten_dt",value:"ten_dt"}]}],function(){$callback$$()})},kh:function($callback$$){$items$$.filter($item$$=>
|
|
8
9
|
$item$$.ma_kh).joinModel($id_app$$,customer,[{akey:"ma_kh",bkey:"ma_kh",fields:[{name:"ten_kh",value:"ten_kh"}]}],function(){$callback$$()})},kho:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kho).joinModel($id_app$$,dmkho,[{akey:"ma_kho",bkey:"ma_kho",fields:[{name:"ten_kho",value:"ten_kho"}]}],function(){$callback$$()})},trangthai:function($callback$$){$items$$.joinModel2(null,trangthai,[{where:{trang_thai:"ma_trang_thai",ma_ct:"ma_ct"},fields:["ten_trang_thai","color"]}],function(){$callback$$()})},
|
|
9
10
|
contract:function($callback$$){$items$$.filter($item$$=>$item$$.ma_hd).joinModel2($id_app$$,contract,[{where:{ma_hd:"so_hd"},fields:["ten_hd","ten_hd"]}],function(){$callback$$()})},t_tien:function($callback$$){$items$$.forEach(function($r$$){$r$$.t_thue_ra=0;$r$$.t_thue_ra_nt=0;$r$$.t_tien_xuat=0;$r$$.t_tien_xuat_nt=0;$r$$.details&&($r$$.t_sl=$r$$.details.csum("sl_xuat"),$r$$.t_tien_hang=$r$$.details.csum("tien_hang"),$r$$.t_tien_hang_nt=$r$$.details.csum("tien_hang_nt"),$r$$.t_ck=$r$$.details.csum("tien_ck"),
|