flexbiz-server 12.6.11 → 12.6.13
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 +11 -3
- package/server/app.js +11 -10
- package/server/auths/local.js +6 -6
- package/server/cluster.js +11 -12
- package/server/controllers/controller.js +14 -3
- package/server/controllers/controllerRPT.js +4 -4
- package/server/controllers/controllerUtils.js +12 -12
- package/server/controllers/createHandler.js +20 -21
- package/server/controllers/deleteHandler.js +3 -3
- package/server/controllers/findHandler.js +49 -48
- package/server/controllers/updateHandler.js +25 -26
- package/server/controllers/viewHandler.js +14 -14
- package/server/flow/handlers.js +2 -2
- package/server/flow/nodes/aiAnalysis.js +7 -7
- package/server/flow/nodes/checkAction.js +7 -0
- package/server/flow/nodes/email.js +7 -8
- package/server/flow/utils.js +58 -1
- package/server/global.js +1 -1
- package/server/libs/WorkerStaticPool.js +19 -18
- package/server/libs/cdpskh.js +3 -2
- package/server/libs/cdpstk.js +11 -11
- package/server/libs/cktk.js +3 -3
- package/server/libs/ckvt.js +10 -10
- package/server/libs/ckvtnpp.js +6 -5
- package/server/libs/ckvttt.js +5 -5
- package/server/libs/ctvt.js +6 -6
- package/server/libs/dkcn.js +1 -1
- package/server/libs/dktk.js +4 -3
- package/server/libs/docs.js +31 -25
- package/server/libs/dtbanletheosp.js +4 -1
- package/server/libs/email.js +2 -2
- package/server/libs/executiveDashboard.js +8 -0
- package/server/libs/getGiaban.js +2 -2
- package/server/libs/kpistatus.js +38 -36
- package/server/libs/kqchamcong.js +12 -0
- package/server/libs/kqhdkd.js +8 -0
- package/server/libs/post-book.js +4 -3
- package/server/libs/post-socai.js +2 -2
- package/server/libs/post-sokho.js +5 -5
- package/server/libs/redis-cache.js +0 -0
- package/server/libs/sctcnkh.js +18 -0
- package/server/libs/sessionContext.js +6 -11
- package/server/libs/socaitk.js +9 -0
- package/server/libs/thnxt.js +2 -1
- package/server/libs/tinhgiatb.js +4 -4
- package/server/libs/tuoinophaithu.js +11 -10
- package/server/libs/tuoinophaitra.js +12 -10
- package/server/libs/utils.js +8 -4
- package/server/libs/vectorService.js +12 -8
- package/server/models/actionLog.js +2 -0
- package/server/models/aimemory.js +1 -0
- package/server/models/app.js +3 -2
- package/server/models/approve.js +4 -4
- package/server/models/chat_message.js +2 -0
- package/server/models/chat_session.js +2 -0
- package/server/models/checkin.js +2 -2
- package/server/models/chitietluongds.js +4 -3
- package/server/models/customer.js +8 -9
- package/server/models/data_list_config.js +2 -2
- package/server/models/dmchietkhau.js +3 -4
- package/server/models/dmchietkhauhd.js +3 -4
- package/server/models/dmdiemthuong.js +2 -4
- package/server/models/dmhoahonghd.js +2 -3
- package/server/models/dmhoahongnpp.js +2 -3
- package/server/models/dmletet.js +2 -2
- package/server/models/dmphatdichvu.js +1 -2
- package/server/models/filechunk.js +2 -2
- package/server/models/hd2.js +9 -11
- package/server/models/hd3.js +10 -11
- package/server/models/listinfo.js +3 -1
- package/server/models/pc0.js +4 -4
- package/server/models/pn1.js +9 -11
- package/server/models/pn2.js +3 -3
- package/server/models/pnc.js +9 -10
- package/server/models/pnh.js +5 -6
- package/server/models/pnk.js +7 -7
- package/server/models/pxc.js +9 -10
- package/server/models/pxh.js +6 -7
- package/server/models/pxk.js +7 -8
- package/server/models/schedule.js +17 -16
- package/server/models/sokho.js +10 -11
- package/server/models/step.js +1 -1
- package/server/modules/lists/bg-cdvt.js +1 -1
- package/server/modules/lists/bg-cdvtnpp.js +1 -1
- package/server/modules/lists/ls-chat_session.js +5 -0
- package/server/modules/lists/ls-checkin.js +11 -12
- package/server/modules/lists/ls-chitietluongds.js +2 -2
- package/server/modules/lists/ls-customer.js +20 -20
- package/server/modules/lists/ls-dmnv.js +12 -11
- package/server/modules/lists/ls-file.js +5 -5
- package/server/modules/lists/ls-mailsent.js +3 -3
- package/server/modules/lists/ls-warranty.js +3 -4
- package/server/modules/reports/calc-tinhluong.js +42 -40
- package/server/modules/reports/rp-dtbanlekempk.js +1 -1
- package/server/modules/reports/rp-dtbanletheoctkempk.js +13 -13
- package/server/modules/reports/rp-kgchamcong.js +1 -12
- package/server/modules/reports/rp-kqhdkd.js +1 -7
- package/server/modules/reports/rp-phanbochitienchohoadon.js +1 -1
- package/server/modules/reports/rp-ptcttct.js +2 -2
- package/server/modules/reports/rp-sctcnkh.js +4 -19
- package/server/modules/reports/rp-socaitk.js +1 -8
- package/server/modules/systems/sys-app.js +20 -19
- package/server/modules/vouchers/vo-hd2.js +71 -85
- package/server/modules/vouchers/vo-hd3.js +15 -21
- package/server/modules/vouchers/vo-pbl.js +48 -48
- package/server/modules/vouchers/vo-pc1.js +11 -11
- package/server/modules/vouchers/vo-pc2.js +13 -12
- package/server/modules/vouchers/vo-pgh.js +12 -15
- package/server/modules/vouchers/vo-pn1.js +27 -33
- package/server/modules/vouchers/vo-pnc.js +14 -15
- package/server/modules/vouchers/vo-pnh.js +12 -15
- package/server/modules/vouchers/vo-pnk.js +11 -15
- package/server/modules/vouchers/vo-po1.js +0 -0
- package/server/modules/vouchers/vo-pxc.js +24 -22
- package/server/modules/vouchers/vo-pxh.js +13 -22
- package/server/modules/vouchers/vo-pxk.js +11 -16
- package/server/route.js +32 -32
- package/server/workers/inputWorker.js +8 -8
- package/server/workers/reportWorker.js +3 -4
- package/server/workers/sendEmail.js +11 -11
- package/server/workers/worker-utils.js +3 -1
- package/server/actions/mailtemplate.js +0 -142
- package/server/actions/schedule.js +0 -23
- package/server/libs/schedule.js +0 -18
- package/server/models/bds_area.js +0 -4
- package/server/models/bds_block.js +0 -3
- package/server/models/bds_building.js +0 -4
- package/server/models/bds_floor.js +0 -3
- package/server/models/bds_floordetail.js +0 -9
- package/server/models/bds_nhadat.js +0 -13
- package/server/models/bds_nhadat_moigioi_ban.js +0 -3
- package/server/models/bds_nhomnhadat.js +0 -4
- package/server/models/bds_phanloainhadat.js +0 -3
- package/server/models/campaign.js +0 -6
- package/server/models/form.js +0 -3
- package/server/models/formvalue.js +0 -3
- package/server/models/hlink.js +0 -2
- package/server/models/hlinkvalue.js +0 -2
- package/server/models/kbm_bcdkt.js +0 -4
- package/server/models/kbm_kqhdkd.js +0 -3
- package/server/models/kbm_lcttgt.js +0 -5
- package/server/models/kbm_lctttt.js +0 -4
- package/server/models/kbm_pttct.js +0 -4
- package/server/models/kbm_tkgtgt.js +0 -5
- package/server/models/mailschedule.js +0 -2
- package/server/models/waitevent.js +0 -2
- package/server/modules/lists/ls-bds_area.js +0 -3
- package/server/modules/lists/ls-bds_block.js +0 -1
- package/server/modules/lists/ls-bds_building.js +0 -3
- package/server/modules/lists/ls-bds_dmnhbds.js +0 -6
- package/server/modules/lists/ls-bds_floor.js +0 -2
- package/server/modules/lists/ls-bds_floordetail.js +0 -19
- package/server/modules/lists/ls-bds_nhadat.js +0 -19
- package/server/modules/lists/ls-bds_nhadat_moigioi_ban.js +0 -9
- package/server/modules/lists/ls-bds_nhomnhadat.js +0 -1
- package/server/modules/lists/ls-bds_phanloainhadat.js +0 -1
- package/server/modules/lists/ls-campaign.js +0 -1
- package/server/modules/lists/ls-dmnhnd.js +0 -1
- package/server/modules/lists/ls-formvalue.js +0 -1
- package/server/modules/lists/ls-hlink.js +0 -1
- package/server/modules/lists/ls-hlinkvalue.js +0 -1
- package/server/modules/lists/ls-mailschedule.js +0 -7
- package/server/modules/lists/ls-waitevent.js +0 -1
- package/server/modules/public/form.js +0 -7
- package/server/modules/public/hlink.js +0 -3
|
@@ -13,66 +13,54 @@ dmvt,{where:"ma_vt",setFields:($item$$,$ref$$)=>{$item$$.combo=$ref$$.combo||[]}
|
|
|
13
13
|
""&&delete $obj$$.warranty_policy_id;$obj$$.ma_kho_npp="";$obj$$.of_user="";var $cust_kho_npp$$=$obj$$.ma_kh?await customer.findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh}).lean():void 0;$cust_kho_npp$$&&$cust_kho_npp$$.of_user&&($cust_kho_npp$$=await global.getModel("dmkho").findOne({id_app:$obj$$.id_app,user_npp:$cust_kho_npp$$.of_user,la_kho_npp:!0}).lean())&&($obj$$.ma_kho_npp=$cust_kho_npp$$.ma_kho,$obj$$.of_user=$cust_kho_npp$$.user_npp);$obj$$.user_created||($obj$$.user_created=$user$$.email);
|
|
14
14
|
$obj$$.details.forEach($d$$=>{$d$$.sl_xuat=utils.round($d$$.sl_xuat,4);$d$$.tt_nt=$d$$.tien_ct_nt-$d$$.tien_ck_nt;$d$$.tt=$d$$.tien_ct-$d$$.tien_ck;$d$$.tien_xuat_tmp=$d$$.sl_xuat*($d$$.gia_mua||0)});$obj$$.ma_nv_giao_hang&&!$obj$$.user_nv_giao_hang&&($obj$$.user_nv_giao_hang=(await global.getModel("dmnv").findOne({id_app:$obj$$.id_app,ma_nv:$obj$$.ma_nv_giao_hang}).lean())?.user);!$obj$$.ma_nv_giao_hang&&$obj$$.user_nv_giao_hang&&($obj$$.ma_nv_giao_hang=(await global.getModel("dmnv").findOne({id_app:$obj$$.id_app,
|
|
15
15
|
user:$obj$$.user_nv_giao_hang}).lean())?.ma_nv);await tinhhoahong($obj$$,$user$$);await taothongtinchuyenkhoan($user$$,$obj$$)};$contr$$.post=async($obj$$,$fn$$,$_options$$={})=>{$fn$$||=function(){};const $appInfo$$=await global.getModel("app").findOne({_id:$obj$$.id_app}).lean();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,{id_func:($obj$$.listinfo_code||$obj$$.ma_ct).toLowerCase()},"option")}catch($e$$){Logger.info($e$$.message,
|
|
16
|
-
{id_func:$obj$$.ma_ct})}$options$$||={};await $obj$$.details.asyncJoinModel2($obj$$.id_app,dmvt,{where:"ma_vt",fields:["gia_mua,tk_tl"]});
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
$
|
|
20
|
-
$
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
$
|
|
24
|
-
$detail$
|
|
25
|
-
$d$$.
|
|
26
|
-
$
|
|
27
|
-
|
|
28
|
-
$
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
$d$$.
|
|
32
|
-
$
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
$
|
|
39
|
-
$
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
$
|
|
44
|
-
$
|
|
45
|
-
$
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
($obj$$.details
|
|
49
|
-
{};$
|
|
50
|
-
$obj$$.tk_no
|
|
51
|
-
$
|
|
52
|
-
$
|
|
53
|
-
$
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
$obj$$.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
$
|
|
60
|
-
|
|
61
|
-
$obj$$.
|
|
62
|
-
|
|
63
|
-
$
|
|
64
|
-
$obj$$.tk_phi_vc&&($o$jscomp$1_o$$={...$obj$$},$o$jscomp$1_o$$.tk_no=$obj$$.tk_no,$o$jscomp$1_o$$.tk_co=$obj$$.tk_phi_vc,$o$jscomp$1_o$$.tien_nt=$obj$$.tien_phi_vc_nt,$o$jscomp$1_o$$.tien=$o$jscomp$1_o$$.tien_nt*$o$jscomp$1_o$$.ty_gia,$o$jscomp$1_o$$.dien_giai="Ph\u00ed giao h\u00e0ng",$details$$.push($o$jscomp$1_o$$));const $details_giavon$$=[];($ket_qua_post_sokho$$||[]).filter($r$$=>$r$$.nxt!=1).forEach(function($detail$$){$detail$$.toObject&&($detail$$=$detail$$.toObject());$detail$$={...$detail$$};
|
|
65
|
-
$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;$detail$$.tien=$detail$$.tien_xuat;$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);
|
|
66
|
-
$s$$.ma_nt="VND";$s$$.ty_gia=1});$callback$$()})}},async()=>{$details_giavon$$.forEach($d$$=>{$d$$.ma_kh_no=$d$$.ma_kh||$obj$$.ma_kh;$d$$.ma_kh_co=$d$$.ma_kh||$obj$$.ma_kh});$details$$=$details$$.concat($details_giavon$$);(new PostSocai($obj$$,$details$$,void 0,void 0,$_options$$)).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})})})},thanhtoanhoahongnv:$callback$$=>{if($obj$$.da_chuyen_hoa_hong||!$obj$$.tien_hoa_hong||!$obj$$.user_nv||!$obj$$.chuyen_ngay)return $callback$$();setImmediate(async()=>
|
|
67
|
-
{try{if($appInfo$$.wallet_address&&$appInfo$$.wallet_token&&$appInfo$$.tang_gioi_thieu_denom){let $wallet_nhan_vien$$=await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),username:$obj$$.user_nv,wallet_type:8});$wallet_nhan_vien$$||=await global.getModel("asskey").createWallet($appInfo$$._id.toString(),$obj$$.user_nv,"T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng",8);let $amount$$=$obj$$.tien_hoa_hong,$denom$$=$appInfo$$.tang_gioi_thieu_denom,$memo$$=`Hoa h\u1ed3ng cho \u0111\u01a1n h\u00e0ng s\u1ed1 ${$obj$$.so_ct}: ${numeral($amount$$).format()} ${$denom$$.toUpperCase()}`;
|
|
68
|
-
await spend($appInfo$$,$obj$$.be_introduced,$wallet_nhan_vien$$.address,$amount$$,$denom$$,$memo$$,"","2");$obj$$.da_chuyen_hoa_hong=!0;await model.updateOne({_id:$obj$$._id},{da_chuyen_hoa_hong:!0})}}catch($e$$){Logger.error("Kh\u00f4ng th\u1ec3 thanh to\u00e1n ti\u1ec1n hoa h\u1ed3ng",$e$$)}$callback$$()})},thanhtoanhoahonggt:$callback$$=>{if($obj$$.da_chuyen_hoa_hong_gt||!$obj$$.tien_hoa_hong_gt||!$obj$$.user_gt||!$obj$$.chuyen_ngay_gt)return $callback$$();setImmediate(async()=>{try{if($appInfo$$.wallet_address&&
|
|
69
|
-
$appInfo$$.wallet_token&&$appInfo$$.tang_gioi_thieu_denom){let $wallet_gt$$=await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),username:$obj$$.user_gt,wallet_type:8});$wallet_gt$$||=await global.getModel("asskey").createWallet($appInfo$$._id.toString(),$obj$$.user_gt,"T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng",8);let $amount$$=$obj$$.tien_hoa_hong_gt,$denom$$=$appInfo$$.tang_gioi_thieu_denom,$memo$$=`Hoa h\u1ed3ng cho \u0111\u01a1n h\u00e0ng s\u1ed1 ${$obj$$.so_ct}: ${numeral($amount$$).format()} ${$denom$$.toUpperCase()}`;
|
|
70
|
-
await spend($appInfo$$,$obj$$.be_introduced,$wallet_gt$$.address,$amount$$,$denom$$,$memo$$,$obj$$.introduce_code,"2");$obj$$.da_chuyen_hoa_hong_gt=!0;await model.updateOne({_id:$obj$$._id},{da_chuyen_hoa_hong_gt:!0})}}catch($e$$){Logger.error("Kh\u00f4ng th\u1ec3 thanh to\u00e1n ti\u1ec1n hoa h\u1ed3ng",$e$$)}$callback$$()})},thanhtoanhoahongctv:$callback$$=>{if($obj$$.da_chuyen_hoa_hong_ctv||!$obj$$.thu_nhap_ctv||!$obj$$.user_ctv||!$obj$$.chuyen_ngay_ctv)return $callback$$();setImmediate(async()=>
|
|
71
|
-
{try{if($appInfo$$.wallet_address&&$appInfo$$.wallet_token&&$appInfo$$.tang_gioi_thieu_denom){if($obj$$.user_ctv&&$obj$$.thu_nhap_ctv){let $wallet_ctv$$=await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),username:$obj$$.user_ctv,wallet_type:8});$wallet_ctv$$||=await global.getModel("asskey").createWallet($appInfo$$._id.toString(),$obj$$.user_ctv,"T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng",8);let $amount$$=$obj$$.thu_nhap_ctv,$denom$$=$appInfo$$.tang_gioi_thieu_denom,$memo$$=
|
|
72
|
-
`Hoa h\u1ed3ng cho \u0111\u01a1n h\u00e0ng s\u1ed1 ${$obj$$.so_ct}: ${numeral($amount$$).format()} ${$denom$$.toUpperCase()}`;await spend($appInfo$$,$obj$$.be_introduced,$wallet_ctv$$.address,$amount$$,$denom$$,$memo$$,$obj$$.introduce_code,"2")}if($obj$$.user_ctv2&&$obj$$.thu_nhap_ctv2){let $wallet_ctv2$$=await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),username:$obj$$.user_ctv2,wallet_type:8});$wallet_ctv2$$||=await global.getModel("asskey").createWallet($appInfo$$._id.toString(),
|
|
73
|
-
$obj$$.user_ctv2,"T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng",8);let $amount$$=$obj$$.thu_nhap_ctv2,$denom$$=$appInfo$$.tang_gioi_thieu_denom,$memo$$=`Hoa h\u1ed3ng cho \u0111\u01a1n h\u00e0ng s\u1ed1 ${$obj$$.so_ct}: ${numeral($amount$$).format()} ${$denom$$.toUpperCase()}`;await spend($appInfo$$,$obj$$.be_introduced,$wallet_ctv2$$.address,$amount$$,$denom$$,$memo$$,$obj$$.introduce_code,"2")}$obj$$.da_chuyen_hoa_hong_ctv=!0;await model.updateOne({_id:$obj$$._id},{da_chuyen_hoa_hong_ctv:!0})}}catch($e$$){Logger.error("Kh\u00f4ng th\u1ec3 thanh to\u00e1n ti\u1ec1n hoa h\u1ed3ng",
|
|
74
|
-
$e$$)}$callback$$()})},thanhtoanhoahongql:$callback$$=>{if($obj$$.da_chuyen_hoa_hong_ql||!$obj$$.tien_hoa_hong_ql||!$obj$$.user_ql||!$obj$$.chuyen_ngay_ql)return $callback$$();setImmediate(async()=>{try{if($appInfo$$.wallet_address&&$appInfo$$.wallet_token&&$appInfo$$.tang_gioi_thieu_denom){let $wallet_ql$$=await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),username:$obj$$.user_ql,wallet_type:8});$wallet_ql$$||=await global.getModel("asskey").createWallet($appInfo$$._id.toString(),
|
|
75
|
-
$obj$$.user_ql,"T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng",8);let $amount$$=$obj$$.tien_hoa_hong_ql,$denom$$=$appInfo$$.tang_gioi_thieu_denom,$memo$$=`Hoa h\u1ed3ng cho \u0111\u01a1n h\u00e0ng s\u1ed1 ${$obj$$.so_ct}: ${numeral($amount$$).format()} ${$denom$$.toUpperCase()}`;await spend($appInfo$$,$obj$$.be_introduced,$wallet_ql$$.address,$amount$$,$denom$$,$memo$$,$obj$$.introduce_code,"2");$obj$$.da_chuyen_hoa_hong_ql=!0;await model.updateOne({_id:$obj$$._id},{da_chuyen_hoa_hong_ql:!0})}}catch($e$$){Logger.error("Kh\u00f4ng th\u1ec3 thanh to\u00e1n ti\u1ec1n hoa h\u1ed3ng",
|
|
16
|
+
{id_func:$obj$$.ma_ct})}$options$$||={};await $obj$$.details.asyncJoinModel2($obj$$.id_app,dmvt,{where:"ma_vt",fields:["gia_mua,tk_tl"]});let $product_details$$=$obj$$.details.map($detail$$=>{$detail$$.tien_nt=$detail$$.tien_nt||0;$detail$$.tien=$detail$$.tien||0;$detail$$.nxt=2;return $detail$$.combo&&$detail$$.combo.length>0?$detail$$.combo.map($item$$=>{$item$$=$item$$.toObject?$item$$.toObject():{...$item$$};$detail$$.gia_ban_nt||($item$$.gia_ban_nt=0,$item$$.gia_nt=0,$item$$.tien_nt=0,$item$$.tien=
|
|
17
|
+
0,$item$$.tien_ck_nt=0,$item$$.tien_ck=0);$item$$.ma_kho=$item$$.ma_kho||$detail$$.ma_kho;$item$$.nxt=2;delete $item$$.px_gia_dd;return $item$$}):[$detail$$]}).reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]);$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$$={};_.extend($_p$$,$p$$,{sl_xuat:$p$$.sl_km});$product_details$$.push($_p$$)}})});$obj$$.promotion&&$obj$$.promotion.forEach($p$$=>{if($p$$.ma_vt&&$p$$.sl_km){let $_p$$=
|
|
18
|
+
{};_.extend($_p$$,$p$$,{sl_xuat:$p$$.sl_km});$product_details$$.push($_p$$)}});let $product_details_npp$$=$obj$$.ma_kho_npp?_.cloneDeep($product_details$$):[];$product_details_npp$$.forEach($detail$$=>{$detail$$.nxt=1;$detail$$.sl_nhap=$detail$$.sl_xuat;$detail$$.gia_von_nt=$detail$$.gia_ban_nt;$detail$$.gia_von=$detail$$.gia_ban;$detail$$.tien_nhap_nt=$detail$$.tien_nt-($detail$$.tien_ck_nt||0);$detail$$.tien_nhap=$detail$$.tien-($detail$$.tien_ck||0);$detail$$.tk_co=$obj$$.tk_co;$detail$$.ma_kho=
|
|
19
|
+
$obj$$.ma_kho_npp;$detail$$.sl_xuat=0;$detail$$.sl_xuat_qd=0;$detail$$.tien_xuat=$detail$$.tien_xuat_nt=0});await $product_details$$.filter($d$$=>!$d$$.ma_dvt).asyncJoinModel2($obj$$.id_app,"dmvt",{where:"ma_vt",fields:["ma_dvt","tk_vt","tk_tl"]});await $product_details$$.filter($d$$=>!$d$$.tk_vt).asyncJoinModel2($obj$$.id_app,"dmvt",{where:"ma_vt",fields:["tk_vt","tk_tl"]});await ($obj$$.details||[]).filter($d$$=>!$d$$.tk_gv).asyncJoinModel2($obj$$.id_app,"dmvt",{where:"ma_vt",fields:["tk_gv"]});
|
|
20
|
+
let $ket_qua_post_sokho$$;async.series({phu_cap:$callback$$=>{setImmediate(async()=>{let $details_phu_cap$$=_.cloneDeep(($obj$$.details||[]).filter($d$$=>$d$$.luong_tho&&$d$$.tg_tk));$details_phu_cap$$.length==0&&($details_phu_cap$$=_.cloneDeep(($obj$$.details||[]).filter($d$$=>$d$$.luong_tho)));for(var $cust$jscomp$1_d$jscomp$9_phu_cap_cust$$ of $details_phu_cap$$)$cust$jscomp$1_d$jscomp$9_phu_cap_cust$$.ma_nv=$obj$$.ma_nv_giao_hang||$cust$jscomp$1_d$jscomp$9_phu_cap_cust$$.ma_nv,$cust$jscomp$1_d$jscomp$9_phu_cap_cust$$.thang=
|
|
21
|
+
(new Date($obj$$.ngay_ct)).getMonth()+1,$cust$jscomp$1_d$jscomp$9_phu_cap_cust$$.nam=(new Date($obj$$.ngay_ct)).getFullYear(),$cust$jscomp$1_d$jscomp$9_phu_cap_cust$$.ten_phu_cap=$cust$jscomp$1_d$jscomp$9_phu_cap_cust$$.ten_phu_cap||$cust$jscomp$1_d$jscomp$9_phu_cap_cust$$.ten_vt,$cust$jscomp$1_d$jscomp$9_phu_cap_cust$$.tien=$cust$jscomp$1_d$jscomp$9_phu_cap_cust$$.luong_tho;if($obj$$.ma_kh&&($cust$jscomp$1_d$jscomp$9_phu_cap_cust$$=await global.getModel("customer").findOne({id_app:$obj$$.id_app,
|
|
22
|
+
ma_kh:$obj$$.ma_kh,phu_cap:{$gte:0}}).lean())){var $t_phu_cap_t_sl_xuat$$=($obj$$.details||[]).map($r$$=>$r$$.sl_xuat||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$t_phu_cap_t_sl_xuat$$*=$cust$jscomp$1_d$jscomp$9_phu_cap_cust$$.phu_cap;const $phu_cap_cust$$={ma_nv:$obj$$.ma_nv_giao_hang,thang:(new Date($obj$$.ngay_ct)).getMonth()+1,nam:(new Date($obj$$.ngay_ct)).getFullYear(),ten_phu_cap:$cust$jscomp$1_d$jscomp$9_phu_cap_cust$$.ten_phu_cap||"Ph\u1ee5 c\u1ea5p theo kh\u00e1ch h\u00e0ng",tien:$t_phu_cap_t_sl_xuat$$*
|
|
23
|
+
($obj$$.phu_xe?.5:1)};$details_phu_cap$$.push($phu_cap_cust$$);$obj$$.phu_xe&&($cust$jscomp$1_d$jscomp$9_phu_cap_cust$$={ma_nv:$obj$$.phu_xe,thang:(new Date($obj$$.ngay_ct)).getMonth()+1,nam:(new Date($obj$$.ngay_ct)).getFullYear(),ten_phu_cap:$cust$jscomp$1_d$jscomp$9_phu_cap_cust$$.ten_phu_cap||"Ph\u1ee5 c\u1ea5p theo kh\u00e1ch h\u00e0ng",tien:$t_phu_cap_t_sl_xuat$$/2},$details_phu_cap$$.push($cust$jscomp$1_d$jscomp$9_phu_cap_cust$$))}(new PostBook($obj$$,$details_phu_cap$$,global.getModel("phucap"),
|
|
24
|
+
async($detail$$,$callback$$)=>{$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})})},post_tdttno:function($callback$$){account.findOne({tk:$obj$$.tk_no,id_app:$obj$$.id_app},{tk_cn:1},async function($d_chinh_error$$,$tk$$){if($d_chinh_error$$)return $callback$$($d_chinh_error$$);if($tk$$?.tk_cn===!0||$options$$.post_tdtt_tm){const $ma_kh_no$$=$obj$$.ma_kh_no||$obj$$.ma_kh;let $kh_bo_xung$$=($obj$$.details||[]).filter($d$$=>($d$$.ma_kh_no||$d$$.ma_kh)&&($d$$.ma_kh_no||$d$$.ma_kh)!=
|
|
25
|
+
$ma_kh_no$$);$kh_bo_xung$$.forEach($d$$=>{$d$$.tien_nt=($d$$.tien_ct_nt||0)-($d$$.tien_ck_nt||0)+($d$$.tien_thue_nt||0);$d$$.tien=$d$$.tien_nt*$obj$$.ty_gia;$d$$.ma_kh=$d$$.ma_kh_no||$d$$.ma_kh});$kh_bo_xung$$=await $kh_bo_xung$$.asyncGroupBy(["ma_kh"],["tien_nt","tien"]);const $bao_hiem$$=[];$obj$$.tien_bh_chi&&$obj$$.ma_kh_bh&&($d_chinh_error$$={...$obj$$},$d_chinh_error$$.ma_kh=$obj$$.ma_kh_bh,$d_chinh_error$$.tien_nt=$obj$$.tien_bh_chi,$d_chinh_error$$.tien=$d_chinh_error$$.tien_bh_chi*($obj$$.ty_gia||
|
|
26
|
+
1),$bao_hiem$$.push($d_chinh_error$$));$d_chinh_error$$=[{...$obj$$}];$d_chinh_error$$.forEach($detail$$=>{$detail$$.ma_kh=$ma_kh_no$$;$detail$$.tien_nt=Math.max(0,$obj$$.details.csum("tien_ct_nt")-$obj$$.details.csum("tien_ck_nt")-($obj$$.tien_ck_hd||0)+$obj$$.details.csum("tien_thue_nt")+($obj$$.tien_phi_vc_nt||0)-$kh_bo_xung$$.csum("tien_nt")-$bao_hiem$$.csum("tien_nt"));$detail$$.tien=$detail$$.tien_nt*$obj$$.ty_gia});(new PostBook($obj$$,[...$kh_bo_xung$$,...$bao_hiem$$,...$d_chinh_error$$].filter($d$$=>
|
|
27
|
+
$d$$.tien_nt),Tdttno,function($detail$$,$callback$$){try{$detail$$.so_hd||($detail$$.so_hd=$obj$$.so_ct),$detail$$.ngay_hd||($detail$$.ngay_hd=$obj$$.ngay_ct)}catch($e$$){Logger.error($e$$,$obj$$)}$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})}else Tdttno.deleteMany({id_ct:$obj$$._id},function($error$$){$callback$$($error$$)})})},post_sokho:$callback$$=>{async.series({kt:$callback$$=>{$options$$.not_post_sokho?$callback$$():(new PostSokho($obj$$,[...$product_details$$],
|
|
28
|
+
async($detail$$,$callback$$)=>{$detail$$.nxt=$detail$$.nxt||2;$detail$$.tk_no=$obj$$.tk_no;$detail$$.ma_kho=$detail$$.ma_kho||$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){if($e$$)return $callback$$($e$$);$ket_qua_post_sokho$$=$rs$$.rs_sokho;$callback$$(null,$rs$$)})},npp:$callback$$=>{$options$$.not_post_sokho?$callback$$():(new PostBook($obj$$,$product_details_npp$$,global.getModel("sokhonpp"),async($detail$$,$callback$$)=>{$detail$$.tk_no=$obj$$.tk_no;$detail$$.ma_kho=$detail$$.ma_kho||
|
|
29
|
+
$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})},tt:$callback$$=>{$options$$.post_sokhott?(new PostBook($obj$$,$product_details$$,Sokhott,async($detail$$,$callback$$)=>{$detail$$.nxt=$detail$$.nxt||2;$detail$$.tk_no=$obj$$.tk_no;$detail$$.ma_kho=$detail$$.ma_kho||$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)}):$callback$$()}},($e$$,$rs$$)=>{$callback$$($e$$,$rs$$)})},post_vatra:function($callback$$){(async()=>{if($obj$$.ngay_hd||
|
|
30
|
+
$obj$$.vatras&&$obj$$.vatras.length>0){let $details_vatra$$=($obj$$.vatras||[]).filter($v$$=>$v$$.ma_thue);if($obj$$.ngay_hd){var $d$$=$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||0,tien_thue:$detail$$.tien_thue||0})).filter($d$$=>$d$$.ma_thue);await $d$$.filter($r$$=>!$r$$.tk_thue_co&&$r$$.ma_thue).asyncJoinModel2($obj$$.id_app,"vat",{where:"ma_thue",
|
|
31
|
+
fields:["tk_thue_co"]});$d$$=await $d$$.asyncGroupBy(["ma_thue","thue_suat","ten_vt_vat","tk_thue_co"],"tien_ct_nt tien_ct tien_nt tien tien_ck tien_ck_nt tien_thue tien_thue_nt".split(" "));$d$$.forEach($detail$$=>{try{$detail$$.tk_du_thue=$obj$$.tk_no,$detail$$.t_tien_nt=($detail$$.tien_ct_nt||0)-($detail$$.tien_ck_nt||0),$detail$$.t_tien=($detail$$.tien_ct||0)-($detail$$.tien_ck||0),$detail$$.t_thue_nt=$detail$$.tien_thue_nt,$detail$$.t_thue=$detail$$.tien_thue,$detail$$.ten_vt=$detail$$.ten_vt_vat||
|
|
32
|
+
$obj$$.ten_vt||$obj$$.dien_giai}catch($e$$){Logger.error($e$$,$obj$$)}});$details_vatra$$=[...$details_vatra$$,...$d$$]}(new PostBook($obj$$,$details_vatra$$,Vatra,($detail$$,$callback$$)=>{$detail$$={...$detail$$};$detail$$.ten_vt=$detail$$.ten_vt||$obj$$.dien_giai;$callback$$($detail$$)})).run(function($e$$,$rs$$){$e$$&&Logger.error("[hd2][post vatra]",$e$$,JSON.stringify($details_vatra$$,null,2));$callback$$($e$$,$rs$$)})}else $callback$$()})()},post_socai:function($callback$$){setImmediate(async()=>
|
|
33
|
+
{let $details$$=[];$options$$.hoach_toan_ck_vt?($obj$$.details.forEach(function($d$jscomp$16_detail$$){$d$jscomp$16_detail$$={...$d$jscomp$16_detail$$};$d$jscomp$16_detail$$.tien_nt=$d$jscomp$16_detail$$.tien_ct_nt;$d$jscomp$16_detail$$.tien=$d$jscomp$16_detail$$.tien_ct?$d$jscomp$16_detail$$.tien_ct:utils.round($d$jscomp$16_detail$$.tien_ct_nt*$obj$$.ty_gia,0);$d$jscomp$16_detail$$.tk_co=$d$jscomp$16_detail$$.tk_dt||$kho$$.tk_dt||$options$$.tk_dt;$d$jscomp$16_detail$$.ma_kh||($d$jscomp$16_detail$$.ma_kh=
|
|
34
|
+
$obj$$.ma_kh);$d$jscomp$16_detail$$.tk_no=$obj$$.tk_no;$details$$.push($d$jscomp$16_detail$$)}),($obj$$.details||[]).filter($d$$=>$d$$.tien_ck_nt).forEach(function($d$jscomp$18_detail$$){$d$jscomp$18_detail$$={...$d$jscomp$18_detail$$};$d$jscomp$18_detail$$.tk_no=$d$jscomp$18_detail$$.tk_ck||$obj$$.tk_ck||$kho$$.tk_ck||$options$$.tk_ck;$d$jscomp$18_detail$$.ma_kh||($d$jscomp$18_detail$$.ma_kh=$obj$$.ma_kh);$d$jscomp$18_detail$$.tk_co=$obj$$.tk_no;$d$jscomp$18_detail$$.tien_nt=$d$jscomp$18_detail$$.tien_ck_nt;
|
|
35
|
+
$d$jscomp$18_detail$$.tien=$d$jscomp$18_detail$$.tien_ck;$d$jscomp$18_detail$$.ma_kh_no=$d$jscomp$18_detail$$.ma_kh||$obj$$.ma_kh;$d$jscomp$18_detail$$.ma_kh_co=$obj$$.ma_kh_no||$d$jscomp$18_detail$$.ma_kh||$obj$$.ma_kh;$d$jscomp$18_detail$$.check_balance=!1;$details$$.push($d$jscomp$18_detail$$)})):$obj$$.details.forEach(function($d$jscomp$19_detail$$){$d$jscomp$19_detail$$={...$d$jscomp$19_detail$$};$d$jscomp$19_detail$$.tien_nt=$d$jscomp$19_detail$$.tien_ct_nt-($d$jscomp$19_detail$$.tien_ck_nt||
|
|
36
|
+
0);$d$jscomp$19_detail$$.tien=utils.round($d$jscomp$19_detail$$.tien_nt*$obj$$.ty_gia,0);$d$jscomp$19_detail$$.tk_co=$d$jscomp$19_detail$$.tk_dt||$kho$$.tk_dt||$options$$.tk_dt;$d$jscomp$19_detail$$.ma_kh||($d$jscomp$19_detail$$.ma_kh=$obj$$.ma_kh);$d$jscomp$19_detail$$.tk_no=$obj$$.tk_no;$details$$.push($d$jscomp$19_detail$$)});if($obj$$.tien_ck_hd){var $o_tt$jscomp$1_tt$$={};$o_tt$jscomp$1_tt$$.tk_no=$obj$$.tk_ck||$kho$$.tk_ck||$options$$.tk_ck;$o_tt$jscomp$1_tt$$.tk_co=$obj$$.tk_no;$o_tt$jscomp$1_tt$$.tien_nt=
|
|
37
|
+
$obj$$.tien_ck_hd;$o_tt$jscomp$1_tt$$.tien=$o_tt$jscomp$1_tt$$.tien_nt*($obj$$.ty_gia||1);$o_tt$jscomp$1_tt$$.ma_kh_no=$obj$$.ma_kh;$o_tt$jscomp$1_tt$$.ma_kh_co=$obj$$.ma_kh_no||$obj$$.ma_kh;$o_tt$jscomp$1_tt$$.check_balance=!1;$details$$.push($o_tt$jscomp$1_tt$$)}$obj$$.tien_bh_chi&&$obj$$.ma_kh_bh&&$obj$$.ma_kh!=$obj$$.ma_kh_bh&&($o_tt$jscomp$1_tt$$={},$o_tt$jscomp$1_tt$$.tk_no=$obj$$.tk_no,$o_tt$jscomp$1_tt$$.tk_co=$obj$$.tk_no,$o_tt$jscomp$1_tt$$.tien_nt=$obj$$.tien_bh_chi,$o_tt$jscomp$1_tt$$.tien=
|
|
38
|
+
$o_tt$jscomp$1_tt$$.tien_bh_chi*($obj$$.ty_gia||1),$o_tt$jscomp$1_tt$$.ma_kh_no=$obj$$.ma_kh_bh,$o_tt$jscomp$1_tt$$.ma_kh_co=$obj$$.ma_kh,$o_tt$jscomp$1_tt$$.check_balance=!1,$details$$.push($o_tt$jscomp$1_tt$$));$obj$$.thu_nhap_ctv&&$obj$$.ma_ctv&&(($obj$$.details||[]).filter($r$$=>$r$$.tien_hoa_hong_ctv).forEach($r$$=>{$r$$.tk_cp_ctv=$r$$.tk_cp_ctv||$obj$$.tk_cp_ctv||$kho$$.tk_cp_ctv||$options$$.tk_cp_ctv||$obj$$.tk_no_hoa_hong||$kho$$.tk_no_hoa_hong||$options$$.tk_no_hoa_hong;$r$$.tk_cn_ctv=$r$$.tk_cn_ctv||
|
|
39
|
+
$obj$$.tk_cn_ctv||$kho$$.tk_cn_ctv||$options$$.tk_cn_ctv||$obj$$.tk_co_hoa_hong||$kho$$.tk_co_hoa_hong||$options$$.tk_co_hoa_hong}),(await ($obj$$.details||[]).filter($r$$=>$r$$.tien_hoa_hong_ctv).asyncGroupBy(["tk_cp_ctv","tk_cn_ctv"],["tien_hoa_hong_ctv"])).forEach($r$$=>{let $tt$$={};$tt$$.tk_no=$r$$.tk_cp_ctv;$tt$$.tk_co=$r$$.tk_cn_ctv;$tt$$.tien=$tt$$.tien_nt=$r$$.tien_hoa_hong_ctv;$tt$$.ma_kh_no=$tt$$.ma_kh_co=$obj$$.ma_ctv;$tt$$.ma_nt="VND";$tt$$.ty_gia=1;$tt$$.dien_giai="Hoa h\u1ed3ng b\u00e1n h\u00e0ng c\u1ed9ng t\u00e1c vi\u00ean c\u1ea5p 1";
|
|
40
|
+
$tt$$.tk_no&&$tt$$.tk_co&&$details$$.push($tt$$)}));$obj$$.thu_nhap_ctv2&&$obj$$.ma_ctv2&&(($obj$$.details||[]).filter($r$$=>$r$$.tien_hoa_hong_ctv2).forEach($r$$=>{$r$$.tk_cp_ctv=$r$$.tk_cp_ctv||$obj$$.tk_cp_ctv||$kho$$.tk_cp_ctv||$options$$.tk_cp_ctv||$obj$$.tk_no_hoa_hong||$kho$$.tk_no_hoa_hong||$options$$.tk_no_hoa_hong;$r$$.tk_cn_ctv=$r$$.tk_cn_ctv||$obj$$.tk_cn_ctv||$kho$$.tk_cn_ctv||$options$$.tk_cn_ctv||$obj$$.tk_co_hoa_hong||$kho$$.tk_co_hoa_hong||$options$$.tk_co_hoa_hong}),(await ($obj$$.details||
|
|
41
|
+
[]).filter($r$$=>$r$$.tien_hoa_hong_ctv2).asyncGroupBy(["tk_cp_ctv","tk_cn_ctv"],["tien_hoa_hong_ctv2"])).forEach($r$$=>{let $tt$$={};$tt$$.tk_no=$r$$.tk_cp_ctv;$tt$$.tk_co=$r$$.tk_cn_ctv;$tt$$.tien=$tt$$.tien_nt=$r$$.tien_hoa_hong_ctv2;$tt$$.ma_kh_no=$tt$$.ma_kh_co=$obj$$.ma_ctv2;$tt$$.ma_nt="VND";$tt$$.ty_gia=1;$tt$$.dien_giai="Hoa h\u1ed3ng b\u00e1n h\u00e0ng c\u00f4ng t\u00e1c vi\u00ean c\u1ea5p 2";$tt$$.tk_no&&$tt$$.tk_co&&$details$$.push($tt$$)}));$obj$$.tien_hoa_hong&&$obj$$.ma_kh_hoa_hong&&
|
|
42
|
+
(($obj$$.details||[]).filter($r$$=>$r$$.tien_hoa_hong).forEach($r$$=>{$r$$.tk_no_hoa_hong=$r$$.tk_no_hoa_hong||$obj$$.tk_no_hoa_hong||$kho$$.tk_no_hoa_hong||$options$$.tk_no_hoa_hong;$r$$.tk_co_hoa_hong=$r$$.tk_co_hoa_hong||$obj$$.tk_co_hoa_hong||$kho$$.tk_co_hoa_hong||$options$$.tk_co_hoa_hong}),(await ($obj$$.details||[]).filter($r$$=>$r$$.tien_hoa_hong).asyncGroupBy(["tk_no_hoa_hong","tk_co_hoa_hong"],["tien_hoa_hong"])).forEach($r$$=>{let $tt$$={};$tt$$.tk_no=$r$$.tk_no_hoa_hong;$tt$$.tk_co=$r$$.tk_co_hoa_hong;
|
|
43
|
+
$tt$$.tien=$tt$$.tien_nt=$r$$.tien_hoa_hong;$tt$$.tien=$tt$$.tien_nt*($obj$$.ty_gia||1);$tt$$.ma_kh_no=$tt$$.ma_kh_co=$obj$$.ma_kh_hoa_hong;$tt$$.ma_nv=$obj$$.ma_nv;$tt$$.check_balance=!1;$tt$$.ma_nt="VND";$tt$$.ty_gia=1;$tt$$.dien_giai="Hoa h\u1ed3ng b\u00e1n h\u00e0ng";$tt$$.tk_no&&$tt$$.tk_co&&$details$$.push($tt$$)}));$obj$$.tien_hoa_hong_gt&&$obj$$.ma_kh_hoa_hong_gt&&(($obj$$.details||[]).filter($r$$=>$r$$.tien_hoa_hong_gt).forEach($r$$=>{$r$$.tk_no_hoa_hong_gt=$r$$.tk_no_hoa_hong_gt||$obj$$.tk_no_hoa_hong_gt||
|
|
44
|
+
$kho$$.tk_no_hoa_hong_gt||$options$$.tk_no_hoa_hong_gt||$obj$$.tk_no_hoa_hong||$kho$$.tk_no_hoa_hong||$options$$.tk_no_hoa_hong;$r$$.tk_co_hoa_hong_gt=$r$$.tk_co_hoa_hong_gt||$obj$$.tk_co_hoa_hong_gt||$kho$$.tk_co_hoa_hong_gt||$options$$.tk_co_hoa_hong_gt||$obj$$.tk_co_hoa_hong||$kho$$.tk_co_hoa_hong||$options$$.tk_co_hoa_hong}),(await ($obj$$.details||[]).filter($r$$=>$r$$.tien_hoa_hong_gt).asyncGroupBy(["tk_no_hoa_hong_gt","tk_co_hoa_hong_gt"],["tien_hoa_hong_gt"])).forEach($r$$=>{let $tt$$={};
|
|
45
|
+
$tt$$.tk_no=$r$$.tk_no_hoa_hong_gt;$tt$$.tk_co=$r$$.tk_co_hoa_hong_gt;$tt$$.tien_nt=$r$$.tien_hoa_hong_gt;$tt$$.tien=$tt$$.tien_nt*($obj$$.ty_gia||1);$tt$$.ma_kh_no=$tt$$.ma_kh_co=$obj$$.ma_kh_hoa_hong_gt;$tt$$.ma_nv=$obj$$.ma_nv;$tt$$.check_balance=!1;$tt$$.dien_giai="Hoa h\u1ed3ng gi\u1edbi thi\u1ec7u";$tt$$.ma_nt="VND";$tt$$.ty_gia=1;$tt$$.tk_no&&$tt$$.tk_co&&$details$$.push($tt$$)}));$obj$$.tien_hoa_hong_kho&&$obj$$.ma_kh_hoa_hong_kho&&(($obj$$.details||[]).filter($r$$=>$r$$.tien_hoa_hong_kho).forEach($r$$=>
|
|
46
|
+
{$r$$.tk_no_hoa_hong_kho=$r$$.tk_no_hoa_hong_kho||$obj$$.tk_no_hoa_hong_kho||$kho$$.tk_no_hoa_hong_kho||$options$$.tk_no_hoa_hong_kho||$obj$$.tk_no_hoa_hong||$kho$$.tk_no_hoa_hong||$options$$.tk_no_hoa_hong;$r$$.tk_co_hoa_hong_kho=$r$$.tk_co_hoa_hong_kho||$obj$$.tk_co_hoa_hong_kho||$kho$$.tk_co_hoa_hong_kho||$options$$.tk_co_hoa_hong_kho||$obj$$.tk_co_hoa_hong||$kho$$.tk_co_hoa_hong||$options$$.tk_co_hoa_hong}),(await ($obj$$.details||[]).filter($r$$=>$r$$.tien_hoa_hong_kho).asyncGroupBy(["tk_no_hoa_hong_kho",
|
|
47
|
+
"tk_co_hoa_hong_kho"],["tien_hoa_hong_kho"])).forEach($r$$=>{let $tt$$={};$tt$$.tk_no=$r$$.tk_no_hoa_hong_kho;$tt$$.tk_co=$r$$.tk_co_hoa_hong_kho;$tt$$.tien_nt=$r$$.tien_hoa_hong_kho;$tt$$.tien=$tt$$.tien_nt*($obj$$.ty_gia||1);$tt$$.ma_kh_no=$tt$$.ma_kh_co=$obj$$.ma_kh_hoa_hong_kho;$tt$$.ma_nv=$obj$$.ma_nv;$tt$$.check_balance=!1;$tt$$.dien_giai="Hoa h\u1ed3ng cho ch\u1ee7 kho";$tt$$.ma_nt="VND";$tt$$.ty_gia=1;$tt$$.tk_no&&$tt$$.tk_co&&$details$$.push($tt$$)}));$obj$$.tien_hoa_hong_ql&&$obj$$.ma_kh_hoa_hong_ql&&
|
|
48
|
+
($obj$$.details.filter($r$$=>$r$$.tien_hoa_hong_ql).forEach($r$$=>{$r$$.tk_no_hoa_hong_ql=$r$$.tk_no_hoa_hong_ql||$obj$$.tk_no_hoa_hong_ql||$kho$$.tk_no_hoa_hong_ql||$options$$.tk_no_hoa_hong_ql||$obj$$.tk_no_hoa_hong||$kho$$.tk_no_hoa_hong||$options$$.tk_no_hoa_hong;$r$$.tk_co_hoa_hong_ql=$r$$.tk_co_hoa_hong_ql||$obj$$.tk_co_hoa_hong_ql||$kho$$.tk_co_hoa_hong_ql||$options$$.tk_co_hoa_hong_ql||$obj$$.tk_co_hoa_hong||$kho$$.tk_co_hoa_hong||$options$$.tk_co_hoa_hong}),(await $obj$$.details.filter($r$$=>
|
|
49
|
+
$r$$.tien_hoa_hong_ql).asyncGroupBy(["tk_no_hoa_hong_ql","tk_co_hoa_hong_ql"],["tien_hoa_hong_ql"])).forEach($r$$=>{let $tt$$={};$tt$$.tk_no=$r$$.tk_no_hoa_hong_ql;$tt$$.tk_co=$r$$.tk_co_hoa_hong_ql;$tt$$.tien_nt=$r$$.tien_hoa_hong_ql;$tt$$.tien=$tt$$.tien_nt*($obj$$.ty_gia||1);$tt$$.ma_kh_no=$tt$$.ma_kh_co=$obj$$.ma_kh_hoa_hong_ql;$tt$$.ma_nv=$obj$$.ma_nv;$tt$$.check_balance=!1;$tt$$.dien_giai="Hoa h\u1ed3ng cho \u0111i\u1ec1u h\u00e0nh kinh doanh";$tt$$.ma_nt="VND";$tt$$.ty_gia=1;$tt$$.tk_no&&$tt$$.tk_co&&
|
|
50
|
+
$details$$.push($tt$$)}));$o_tt$jscomp$1_tt$$={...$obj$$};$o_tt$jscomp$1_tt$$.tk_no=$obj$$.tk_no;$o_tt$jscomp$1_tt$$.tk_co=$obj$$.tk_thue_co;$o_tt$jscomp$1_tt$$.tien_nt=$obj$$.details.csum("tien_thue_nt");$o_tt$jscomp$1_tt$$.tien=$o_tt$jscomp$1_tt$$.tien_nt*$o_tt$jscomp$1_tt$$.ty_gia;$o_tt$jscomp$1_tt$$.dien_giai_thue&&($o_tt$jscomp$1_tt$$.dien_giai=$o_tt$jscomp$1_tt$$.dien_giai_thue);$details$$.push($o_tt$jscomp$1_tt$$);if($obj$$.vatras&&$obj$$.vatras.length>0)for(var $o$jscomp$1_o$$ of $obj$$.vatras)$o$jscomp$1_o$$.tk_no=
|
|
51
|
+
$obj$$.tk_no,$o$jscomp$1_o$$.tk_co=$o$jscomp$1_o$$.tk_thue_co,$o$jscomp$1_o$$.tien_nt=$o$jscomp$1_o$$.t_thue_nt,$o$jscomp$1_o$$.tien=$o$jscomp$1_o$$.t_thue,$o$jscomp$1_o$$.dien_giai_thue&&($o$jscomp$1_o$$.dien_giai=$o$jscomp$1_o$$.dien_giai_thue),$details$$.push($o$jscomp$1_o$$);$obj$$.tk_phi_vc=$obj$$.tk_phi_vc||$options$$.tk_phi_vc;$obj$$.tk_phi_vc&&($o$jscomp$1_o$$={...$obj$$},$o$jscomp$1_o$$.tk_no=$obj$$.tk_no,$o$jscomp$1_o$$.tk_co=$obj$$.tk_phi_vc,$o$jscomp$1_o$$.tien_nt=$obj$$.tien_phi_vc_nt,
|
|
52
|
+
$o$jscomp$1_o$$.tien=$o$jscomp$1_o$$.tien_nt*$o$jscomp$1_o$$.ty_gia,$o$jscomp$1_o$$.dien_giai="Ph\u00ed giao h\u00e0ng",$details$$.push($o$jscomp$1_o$$));const $details_giavon$$=[];($ket_qua_post_sokho$$||[]).filter($r$$=>$r$$.nxt!=1).forEach(function($detail$$){$detail$$.toObject&&($detail$$=$detail$$.toObject());$detail$$={...$detail$$};$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;$detail$$.tien=
|
|
53
|
+
$detail$$.tien_xuat;$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);$s$$.ma_nt="VND";$s$$.ty_gia=1});$callback$$()})}},async()=>{$details_giavon$$.forEach($d$$=>{$d$$.ma_kh_no=$d$$.ma_kh||$obj$$.ma_kh;$d$$.ma_kh_co=$d$$.ma_kh||$obj$$.ma_kh});
|
|
54
|
+
$details$$=$details$$.concat($details_giavon$$);(new PostSocai($obj$$,$details$$,void 0,void 0,$_options$$)).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})})})},thanhtoanhoahongnv:$callback$$=>{if($obj$$.da_chuyen_hoa_hong||!$obj$$.tien_hoa_hong||!$obj$$.user_nv||!$obj$$.chuyen_ngay)return $callback$$();setImmediate(async()=>{try{if($appInfo$$.wallet_address&&$appInfo$$.wallet_token&&$appInfo$$.tang_gioi_thieu_denom){let $wallet_nhan_vien$$=await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),
|
|
55
|
+
username:$obj$$.user_nv,wallet_type:8});$wallet_nhan_vien$$||=await global.getModel("asskey").createWallet($appInfo$$._id.toString(),$obj$$.user_nv,"T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng",8);let $amount$$=$obj$$.tien_hoa_hong,$denom$$=$appInfo$$.tang_gioi_thieu_denom,$memo$$=`Hoa h\u1ed3ng cho \u0111\u01a1n h\u00e0ng s\u1ed1 ${$obj$$.so_ct}: ${numeral($amount$$).format()} ${$denom$$.toUpperCase()}`;await spend($appInfo$$,$obj$$.be_introduced,$wallet_nhan_vien$$.address,$amount$$,$denom$$,
|
|
56
|
+
$memo$$,"","2");$obj$$.da_chuyen_hoa_hong=!0;await model.updateOne({_id:$obj$$._id},{da_chuyen_hoa_hong:!0})}}catch($e$$){Logger.error("Kh\u00f4ng th\u1ec3 thanh to\u00e1n ti\u1ec1n hoa h\u1ed3ng",$e$$)}$callback$$()})},thanhtoanhoahonggt:$callback$$=>{if($obj$$.da_chuyen_hoa_hong_gt||!$obj$$.tien_hoa_hong_gt||!$obj$$.user_gt||!$obj$$.chuyen_ngay_gt)return $callback$$();setImmediate(async()=>{try{if($appInfo$$.wallet_address&&$appInfo$$.wallet_token&&$appInfo$$.tang_gioi_thieu_denom){let $wallet_gt$$=
|
|
57
|
+
await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),username:$obj$$.user_gt,wallet_type:8});$wallet_gt$$||=await global.getModel("asskey").createWallet($appInfo$$._id.toString(),$obj$$.user_gt,"T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng",8);let $amount$$=$obj$$.tien_hoa_hong_gt,$denom$$=$appInfo$$.tang_gioi_thieu_denom,$memo$$=`Hoa h\u1ed3ng cho \u0111\u01a1n h\u00e0ng s\u1ed1 ${$obj$$.so_ct}: ${numeral($amount$$).format()} ${$denom$$.toUpperCase()}`;await spend($appInfo$$,
|
|
58
|
+
$obj$$.be_introduced,$wallet_gt$$.address,$amount$$,$denom$$,$memo$$,$obj$$.introduce_code,"2");$obj$$.da_chuyen_hoa_hong_gt=!0;await model.updateOne({_id:$obj$$._id},{da_chuyen_hoa_hong_gt:!0})}}catch($e$$){Logger.error("Kh\u00f4ng th\u1ec3 thanh to\u00e1n ti\u1ec1n hoa h\u1ed3ng",$e$$)}$callback$$()})},thanhtoanhoahongctv:$callback$$=>{if($obj$$.da_chuyen_hoa_hong_ctv||!$obj$$.thu_nhap_ctv||!$obj$$.user_ctv||!$obj$$.chuyen_ngay_ctv)return $callback$$();setImmediate(async()=>{try{if($appInfo$$.wallet_address&&
|
|
59
|
+
$appInfo$$.wallet_token&&$appInfo$$.tang_gioi_thieu_denom){if($obj$$.user_ctv&&$obj$$.thu_nhap_ctv){let $wallet_ctv$$=await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),username:$obj$$.user_ctv,wallet_type:8});$wallet_ctv$$||=await global.getModel("asskey").createWallet($appInfo$$._id.toString(),$obj$$.user_ctv,"T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng",8);let $amount$$=$obj$$.thu_nhap_ctv,$denom$$=$appInfo$$.tang_gioi_thieu_denom,$memo$$=`Hoa h\u1ed3ng cho \u0111\u01a1n h\u00e0ng s\u1ed1 ${$obj$$.so_ct}: ${numeral($amount$$).format()} ${$denom$$.toUpperCase()}`;
|
|
60
|
+
await spend($appInfo$$,$obj$$.be_introduced,$wallet_ctv$$.address,$amount$$,$denom$$,$memo$$,$obj$$.introduce_code,"2")}if($obj$$.user_ctv2&&$obj$$.thu_nhap_ctv2){let $wallet_ctv2$$=await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),username:$obj$$.user_ctv2,wallet_type:8});$wallet_ctv2$$||=await global.getModel("asskey").createWallet($appInfo$$._id.toString(),$obj$$.user_ctv2,"T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng",8);let $amount$$=$obj$$.thu_nhap_ctv2,$denom$$=$appInfo$$.tang_gioi_thieu_denom,
|
|
61
|
+
$memo$$=`Hoa h\u1ed3ng cho \u0111\u01a1n h\u00e0ng s\u1ed1 ${$obj$$.so_ct}: ${numeral($amount$$).format()} ${$denom$$.toUpperCase()}`;await spend($appInfo$$,$obj$$.be_introduced,$wallet_ctv2$$.address,$amount$$,$denom$$,$memo$$,$obj$$.introduce_code,"2")}$obj$$.da_chuyen_hoa_hong_ctv=!0;await model.updateOne({_id:$obj$$._id},{da_chuyen_hoa_hong_ctv:!0})}}catch($e$$){Logger.error("Kh\u00f4ng th\u1ec3 thanh to\u00e1n ti\u1ec1n hoa h\u1ed3ng",$e$$)}$callback$$()})},thanhtoanhoahongql:$callback$$=>{if($obj$$.da_chuyen_hoa_hong_ql||
|
|
62
|
+
!$obj$$.tien_hoa_hong_ql||!$obj$$.user_ql||!$obj$$.chuyen_ngay_ql)return $callback$$();setImmediate(async()=>{try{if($appInfo$$.wallet_address&&$appInfo$$.wallet_token&&$appInfo$$.tang_gioi_thieu_denom){let $wallet_ql$$=await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),username:$obj$$.user_ql,wallet_type:8});$wallet_ql$$||=await global.getModel("asskey").createWallet($appInfo$$._id.toString(),$obj$$.user_ql,"T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng",8);let $amount$$=
|
|
63
|
+
$obj$$.tien_hoa_hong_ql,$denom$$=$appInfo$$.tang_gioi_thieu_denom,$memo$$=`Hoa h\u1ed3ng cho \u0111\u01a1n h\u00e0ng s\u1ed1 ${$obj$$.so_ct}: ${numeral($amount$$).format()} ${$denom$$.toUpperCase()}`;await spend($appInfo$$,$obj$$.be_introduced,$wallet_ql$$.address,$amount$$,$denom$$,$memo$$,$obj$$.introduce_code,"2");$obj$$.da_chuyen_hoa_hong_ql=!0;await model.updateOne({_id:$obj$$._id},{da_chuyen_hoa_hong_ql:!0})}}catch($e$$){Logger.error("Kh\u00f4ng th\u1ec3 thanh to\u00e1n ti\u1ec1n hoa h\u1ed3ng",
|
|
76
64
|
$e$$)}$callback$$()})},thanhtoanhoahongchukho:$callback$$=>{if($obj$$.da_chuyen_hoa_hong_kho||!$obj$$.tien_hoa_hong_kho||!$obj$$.user_kho||!$obj$$.chuyen_ngay_kho)return $callback$$();setImmediate(async()=>{try{if($appInfo$$.wallet_address&&$appInfo$$.wallet_token&&$appInfo$$.tang_gioi_thieu_denom){let $wallet_kho$$=await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),username:$obj$$.user_kho,wallet_type:8});$wallet_kho$$||=await global.getModel("asskey").createWallet($appInfo$$._id.toString(),
|
|
77
65
|
$obj$$.user_kho,"T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng",8);let $amount$$=$obj$$.tien_hoa_hong_kho,$denom$$=$appInfo$$.tang_gioi_thieu_denom,$memo$$=`Hoa h\u1ed3ng cho \u0111\u01a1n h\u00e0ng s\u1ed1 ${$obj$$.so_ct}: ${numeral($amount$$).format()} ${$denom$$.toUpperCase()}`;await spend($appInfo$$,$obj$$.be_introduced,$wallet_kho$$.address,$amount$$,$denom$$,$memo$$,$obj$$.introduce_code,"2");$obj$$.da_chuyen_hoa_hong_kho=!0;await model.updateOne({_id:$obj$$._id},{da_chuyen_hoa_hong_kho:!0})}}catch($e$$){Logger.error("Kh\u00f4ng th\u1ec3 thanh to\u00e1n ti\u1ec1n hoa h\u1ed3ng",
|
|
78
66
|
$e$$)}$callback$$()})}},function($e$$,$rs$$){$fn$$($e$$,$rs$$)})};const $valid$$=function($i_user$$,$obj$$,$next$$){$obj$$.thue_suat=$obj$$.thue_suat||0;$obj$$.tien_phi_vc_nt=$obj$$.tien_phi_vc_nt||0;$obj$$.tien_phi_vc=utils.round($obj$$.tien_phi_vc_nt*$obj$$.ty_gia,0);$obj$$.details.forEach($detail$$=>{tinhGiaChuaThue($obj$$,$detail$$)});$obj$$.vatras=($obj$$.vatras||[]).filter($d$$=>$d$$);$obj$$.vatras.forEach($d$$=>{$d$$.t_tien=utils.round($d$$.t_tien_nt*($obj$$.ty_gia||1),0);$d$$.t_thue=utils.round($d$$.t_thue_nt*
|
|
@@ -88,31 +76,29 @@ id_app:$obj$$.id_app,gia:{$gt:0},nam:$ngay_nay_thang_truoc$$.getFullYear(),thang
|
|
|
88
76
|
$data$$.details.filter($d$$=>$d$$.combo&&$d$$.combo.length>0).forEach($detail$$=>{$detail$$.combo=$detail$$.combo.map($item$$=>{$item$$.sl_xuat_1_combo==void 0&&($item$$.sl_xuat_1_combo=$item$$.sl_xuat||0);$item$$.sl_xuat=$item$$.sl_xuat_1_combo*$detail$$.sl_xuat;$item$$.tien_xuat=$item$$.tien_xuat_nt=$item$$.sl_xuat*($item$$.gia_von_nt||0);$item$$.tien_hang=$item$$.tien_hang_nt=0;$item$$.tien=$item$$.tien_nt=$item$$.sl_xuat*($item$$.gia_ban_nt||0);$item$$.tien_ck=$item$$.tien_ck_nt=$item$$.sl_xuat*
|
|
89
77
|
($item$$.tien_ck_nt||0);$item$$.tt=$item$$.tt_nt=$item$$.tien_nt-($item$$.tien_ck_nt||0);return{...$item$$}});$detail$$.gia_mua=$detail$$.combo.map($c$$=>($c$$.gia_mua||0)*$c$$.sl_xuat_1_combo).reduce(($a$$,$b$$)=>$a$$+$b$$,0)});const $ct_tt$$=await Tdttno_tt.findOne({id_hd:$obj$$._id,id_app:$obj$$.id_app}).lean();if($ct_tt$$)return $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")}`);
|
|
90
78
|
$valid$$($user$$,$data$$,function($error$$){if($error$$)return $next$$($error$$);$next$$(null,$data$$,$obj$$)})};$contr$$.deleting=async function($ct_tt$jscomp$1_user$$,$obj$$,$next$$){($ct_tt$jscomp$1_user$$=await Tdttno_tt.findOne({id_hd:$obj$$._id,id_app:$obj$$.id_app}).lean())?$next$$(`Kh\u00f4ng th\u1ec3 xo\u00e1 phi\u1ebfu n\u00e0y do \u0111\u00e3 \u0111\u01b0\u1ee3c thanh to\u00e1n b\u1edfi ${$ct_tt$jscomp$1_user$$.ma_ct||"ch\u1ee9ng t\u1eeb"}: ${$ct_tt$jscomp$1_user$$.so_ct}, ng\u00e0y ${moment($ct_tt$jscomp$1_user$$.ngay_ct).format("DD/MM/YYYY")}`):
|
|
91
|
-
$next$$(null,$obj$$)};$contr$$.on("saved",function($
|
|
92
|
-
"",void 0]}},{id_hd2:"",trang_thai:"3"},
|
|
93
|
-
$item$$.ma_dt).joinModel2($id_app$$,dmdt,[{where:"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$$()})},ghn:function($callback$$){$items$$.filter($item$$=>$item$$.tinh_thanh
|
|
94
|
-
xa_phuong:"ten_xa_phuong"},fields:["provinceid_ghn","districtid_ghn","wardcode_ghn"]}],function(){$callback$$()})},nv:function($callback$$){$items$$.filter($item$$=>$item$$.ma_nv).joinModel($id_app$$,dmnv,[{akey:"ma_nv",bkey:"ma_nv",setFields:($item$$,$ref$$)=>{$item$$.ma_bp||($item$$.ma_bp=$ref$$.ma_bp);$item$$.ten_nv=$ref$$.ten_nv}}],function(){$callback$$()})},trangthai:function($callback$$){$items$$.filter($item
|
|
95
|
-
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$$()})},cong_no:function($callback$$){setImmediate(async()=>{try{const $id_hds$$=$items$$.map($i$$=>$i$$._id.toString()),$congnos$$=await global.getModel("tdttno").getBalance({id_app:$id_app$$,
|
|
96
|
-
$congnos$$.find($c$$=>$c$$.id_ct.toString()==$item$$._id.toString());if($invoice$$&&($item$$.da_thanh_toan_nt=$invoice$$.da_thanh_toan_nt,$item$$.da_thanh_toan=$invoice$$.da_thanh_toan,$item$$.con_lai_nt=$invoice$$.con_lai_nt,$item$$.con_lai=$invoice$$.con_lai,$item$$.con_lai_nt)){let $t_invoice$$={sel:!1,id_tdtt:$invoice$$._id,line:$invoice$$.line,id_hd:$invoice$$.id_ct,so_hd:$invoice$$.so_hd||$invoice$$.so_ct,ngay_hd:$invoice$$.ngay_hd
|
|
97
|
-
$invoice$$.ma_nt;$t_invoice$$.ty_gia_hd=$invoice$$.ty_gia;$t_invoice$$.ma_kh=$invoice$$.ma_kh;$t_invoice$$.ma_kho=$invoice$$.ma_kho;$t_invoice$$.dien_giai=$invoice$$.dien_giai;$t_invoice$$.tien_nt=0;$t_invoice$$.tien=0;$t_invoice$$.thanh_toan_qd=0;$t_invoice$$.tk_co=$invoice$$.tk_no;$t_invoice$$.da_thanh_toan_nt=$invoice$$.da_thanh_toan_nt;$t_invoice$$.da_thanh_toan=$invoice$$.da_thanh_toan;$t_invoice$$.con_lai_nt=$invoice$$.con_lai_nt
|
|
98
|
-
$t_invoice$$}}$callback$$()}catch($e$$){$callback$$($e$$)}})},t_tien:function($callback$$){for(let $r$$ of $items$$)$r$$.details&&($r$$.details.forEach($d$$=>{$d$$.tien_tinh_thue_nt=$d$$.tien_ct_nt-$d$$.tien_ck_nt;$d$$.tien_nt=$d$$.tien_ct_nt-$d$$.tien_ck_nt+$d$$.tien_thue_nt;$d$$.tien=Math.round($d$$.tien_nt*$r$$.ty_gia)}),$r$$.t_sl=$r$$.details.csum("sl_xuat"),$r$$.t_thue=$r$$.details.csum("tien_thue"),$r$$.t_thue_nt=$r$$.details.csum("tien_thue_nt")
|
|
99
|
-
$r$$.details.csum("tien_nt"),$r$$.t_tien_ct=$r$$.details.csum("tien_ct"),$r$$.t_tien_ct_nt=$r$$.details.csum("tien_ct_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$$.
|
|
100
|
-
$r$$.
|
|
101
|
-
|
|
102
|
-
$
|
|
103
|
-
$ref$$.
|
|
104
|
-
|
|
105
|
-
function($r$$,$callback1$$){($r$$.
|
|
106
|
-
function(){$callback$$()})},
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
$
|
|
111
|
-
$ct$jscomp$
|
|
112
|
-
$
|
|
113
|
-
|
|
114
|
-
const $app$$=await App.findOne({_id:$ct$jscomp$3_id_app$$});if(!$app$$)return $next$$("Kh\u00f4ng t\u00ecm th\u1ea5y c\u00f4ng ty n\u00e0y");if(!$app$$.ma_so_thue)return $next$$("B\u1ea1n ch\u01b0a nh\u1eadp m\u00e3 s\u1ed1 thu\u1ebf c\u1ee7a c\u00f4ng ty");$ct$jscomp$3_id_app$$=await model.findOne({id_app:$ct$jscomp$3_id_app$$,_id:$req$$.params.id_ct}).lean();if(!$ct$jscomp$3_id_app$$)return $next$$("Ch\u1ee9ng t\u1eeb kh\u00f4ng h\u1ee3p l\u1ec7");try{let $body$$=$req$$.body||{};$body$$.vatras&&
|
|
115
|
-
($ct$jscomp$3_id_app$$.vatras=$body$$.vatras);$body$$.export_yn!=void 0&&($ct$jscomp$3_id_app$$.export_yn=$body$$.export_yn);let $rs$$=await utils.exportInvoice($app$$,$ct$jscomp$3_id_app$$,$req$$.query.check_data);$next$$(null,$rs$$)}catch($e$$){$next$$({error:$e$$.message||$e$$.error||$e$$})}},{method:"POST",action_code:"add"});$contr$$.createRoute("import/invoice",async($req$$,$next$$)=>{var $invoices_tu_ngay$$=$req$$.query.tu_ngay;let $den_ngay$$=$req$$.query.den_ngay;if(!$invoices_tu_ngay$$||
|
|
79
|
+
$next$$(null,$obj$$)};$contr$$.on("saved",async function($_obj_obj$$){$_obj_obj$$.id_dh2&&(await global.getModel("dh2").updateMany({_id:$_obj_obj$$.id_dh2,id_app:$_obj_obj$$.id_app},{id_hd2:$_obj_obj$$._id.toString(),trang_thai:"7"}),($_obj_obj$$=await global.getModel("dh2").findOne({_id:$_obj_obj$$.id_dh2}))&&controller.postData($_obj_obj$$,global.controllers.DH2,$e$$=>{$e$$&&Logger.error($e$$)}))});$contr$$.on("deleted",async function($_obj$jscomp$1_obj$$){$_obj$jscomp$1_obj$$.id_dh2&&(await global.getModel("dh2").updateMany({_id:$_obj$jscomp$1_obj$$.id_dh2,
|
|
80
|
+
id_app:$_obj$jscomp$1_obj$$.id_app,id_pxh:{$in:[null,"",void 0]}},{id_hd2:"",trang_thai:"3"}),await global.getModel("dh2").updateMany({_id:$_obj$jscomp$1_obj$$.id_dh2,id_app:$_obj$jscomp$1_obj$$.id_app,id_pxh:{$nin:[null,"",void 0]}},{id_hd2:"",trang_thai:"6"}),($_obj$jscomp$1_obj$$=await global.getModel("dh2").findOne({_id:$_obj$jscomp$1_obj$$.id_dh2,id_app:$_obj$jscomp$1_obj$$.id_app}))&&controller.postData($_obj$jscomp$1_obj$$,global.controllers.DH2,$e$$=>{$e$$&&Logger.error($e$$)}))});$contr$$.view=
|
|
81
|
+
function($user$$,$items$$,$fn$$){const $id_app$$=$user$$.current_id_app;async.parallel({dt:function($callback$$){$items$$.filter($item$$=>$item$$.ma_dt).joinModel2($id_app$$,dmdt,[{where:"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$$()})},ghn:function($callback$$){$items$$.filter($item$$=>$item$$.tinh_thanh&&
|
|
82
|
+
$item$$.quan_huyen&&$item$$.xa_phuong).joinModel2(null,"xaphuong",[{where:{tinh_thanh:"ten_tinh_thanh",quan_huyen:"ten_quan_huyen",xa_phuong:"ten_xa_phuong"},fields:["provinceid_ghn","districtid_ghn","wardcode_ghn"]}],function(){$callback$$()})},nv:function($callback$$){$items$$.filter($item$$=>$item$$.ma_nv).joinModel($id_app$$,dmnv,[{akey:"ma_nv",bkey:"ma_nv",setFields:($item$$,$ref$$)=>{$item$$.ma_bp||($item$$.ma_bp=$ref$$.ma_bp);$item$$.ten_nv=$ref$$.ten_nv}}],function(){$callback$$()})},trangthai:function($callback$$){$items$$.filter($item$$=>
|
|
83
|
+
$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$$()})},cong_no:function($callback$$){setImmediate(async()=>{try{const $id_hds$$=$items$$.map($i$$=>$i$$._id.toString()),$congnos$$=await global.getModel("tdttno").getBalance({id_app:$id_app$$,
|
|
84
|
+
id_hd:{$in:$id_hds$$}});for(let $item$$ of $items$$){let $invoice$$=$congnos$$.find($c$$=>$c$$.id_ct.toString()==$item$$._id.toString());if($invoice$$&&($item$$.da_thanh_toan_nt=$invoice$$.da_thanh_toan_nt,$item$$.da_thanh_toan=$invoice$$.da_thanh_toan,$item$$.con_lai_nt=$invoice$$.con_lai_nt,$item$$.con_lai=$invoice$$.con_lai,$item$$.con_lai_nt)){let $t_invoice$$={sel:!1,id_tdtt:$invoice$$._id,line:$invoice$$.line,id_hd:$invoice$$.id_ct,so_hd:$invoice$$.so_hd||$invoice$$.so_ct,ngay_hd:$invoice$$.ngay_hd||
|
|
85
|
+
$invoice$$.ngay_ct,tien_hd_nt:$invoice$$.tien_nt};$t_invoice$$.ma_nt_hd=$invoice$$.ma_nt;$t_invoice$$.ty_gia_hd=$invoice$$.ty_gia;$t_invoice$$.ma_kh=$invoice$$.ma_kh;$t_invoice$$.ma_kho=$invoice$$.ma_kho;$t_invoice$$.dien_giai=$invoice$$.dien_giai;$t_invoice$$.tien_nt=0;$t_invoice$$.tien=0;$t_invoice$$.thanh_toan_qd=0;$t_invoice$$.tk_co=$invoice$$.tk_no;$t_invoice$$.da_thanh_toan_nt=$invoice$$.da_thanh_toan_nt;$t_invoice$$.da_thanh_toan=$invoice$$.da_thanh_toan;$t_invoice$$.con_lai_nt=$invoice$$.con_lai_nt;
|
|
86
|
+
$t_invoice$$.con_lai=$invoice$$.con_lai;$item$$.theo_doi_thanh_toan=$t_invoice$$}}$callback$$()}catch($e$$){$callback$$($e$$)}})},t_tien:function($callback$$){for(let $r$$ of $items$$)$r$$.details&&($r$$.details.forEach($d$$=>{$d$$.tien_tinh_thue_nt=$d$$.tien_ct_nt-$d$$.tien_ck_nt;$d$$.tien_nt=$d$$.tien_ct_nt-$d$$.tien_ck_nt+$d$$.tien_thue_nt;$d$$.tien=Math.round($d$$.tien_nt*$r$$.ty_gia)}),$r$$.t_sl=$r$$.details.csum("sl_xuat"),$r$$.t_thue=$r$$.details.csum("tien_thue"),$r$$.t_thue_nt=$r$$.details.csum("tien_thue_nt"),
|
|
87
|
+
$r$$.t_tien=$r$$.details.csum("tien"),$r$$.t_tien_nt=$r$$.details.csum("tien_nt"),$r$$.t_tien_ct=$r$$.details.csum("tien_ct"),$r$$.t_tien_ct_nt=$r$$.details.csum("tien_ct_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_tt_nt=$r$$.t_tien_ct_nt-$r$$.tc_ck_nt+$r$$.t_thue_nt+($r$$.tien_phi_vc_nt||0),$r$$.t_tt=Math.round($r$$.t_tt_nt*$r$$.ty_gia||1,0),$r$$.t_tien_xuat=
|
|
88
|
+
$r$$.details.csum("tien_xuat"),$r$$.t_tien_xuat_nt=$r$$.details.csum("tien_xuat_nt"),$r$$.tien_hoa_hong=$r$$.details.csum("tien_hoa_hong"),$r$$.tien_hoa_hong_gt=$r$$.details.csum("tien_hoa_hong_gt"),$r$$.tien_hoa_hong_ql=$r$$.details.csum("tien_hoa_hong_ql"),$r$$.tien_hoa_hong_kho=$r$$.details.csum("tien_hoa_hong_kho"),$r$$.thu_nhap_ctv=$r$$.details.csum("tien_hoa_hong_ctv"),$r$$.thu_nhap_ctv2=$r$$.details.csum("tien_hoa_hong_ctv2"));$callback$$()},details_kho:function($callback$$){async.map($items$$,
|
|
89
|
+
function($r$$,$callback$$){($r$$.details||[]).filter($item$$=>$item$$.ma_kho).joinModel2($id_app$$,dmkho,[{where:"ma_kho",fields:["ten_kho"]}],function(){$callback$$()})},function(){$callback$$()})},details_vt:function($callback$$){async.map($items$$,function($voucher$$,$callback1$$){(async()=>{const $details$$=$voucher$$.details||[];await $details$$.asyncJoinModel2($id_app$$,dmvt,[{where:"ma_vt",setFields:($item$$,$ref$$)=>{$item$$.ten_vt=$ref$$.ten_vt;$item$$.tk_tl=$ref$$.tk_tl;$item$$.trong_luong=
|
|
90
|
+
$item$$.trong_luong||$ref$$.trong_luong;$item$$.chieu_sau=$item$$.chieu_sau||$ref$$.chieu_sau;$item$$.chieu_rong=$item$$.chieu_rong||$ref$$.chieu_rong;$item$$.chieu_cao=$item$$.chieu_cao||$ref$$.chieu_cao;$item$$.ma_tt1_yn=$ref$$.ma_tt1_yn;$item$$.ma_tt2_yn=$ref$$.ma_tt2_yn;$item$$.ma_tt3_yn=$ref$$.ma_tt3_yn;$item$$.ma_lo_yn=$ref$$.ma_lo_yn;$item$$.kl_nl=$ref$$.kl_nl;$item$$.ma_nvt||($item$$.ma_nvt=$ref$$.ma_nvt);$item$$.ma_nvt2||($item$$.ma_nvt2=$ref$$.ma_nvt2);$item$$.ma_nvt3||($item$$.ma_nvt3=
|
|
91
|
+
$ref$$.ma_nvt3)}}]);await $details$$.filter($d$$=>$d$$.ma_nvt).asyncJoinModel2($id_app$$,"dmnvt",[{where:{ma_nvt:"_id"},setFields:($item$$,$nh_vt_ref$$)=>{$item$$.ten_nvt=$nh_vt_ref$$.ten_nvt;$item$$.ten_nvt&&($nh_vt_ref$$=`nh_vt_${$item$$.ten_nvt}`,$voucher$$[$nh_vt_ref$$]=($voucher$$[$nh_vt_ref$$]||0)+$item$$.sl_xuat)}}]);$callback1$$()})()},function(){$callback$$()})},details_csck:function($callback$$){async.map($items$$,function($r$$,$callback1$$){($r$$.details||[]).filter($d$$=>$d$$.id_cs_ck).joinModel2($id_app$$,
|
|
92
|
+
"dmchietkhau",[{where:{id_cs_ck:"_id"},setFields:($item$$,$ref$$)=>{$item$$.ten_chietkhau=$ref$$.ten_chietkhau}}],function(){$callback1$$()})},function(){$callback$$()})},details_tt1:function($callback$$){async.map($items$$,function($r$$,$callback1$$){($r$$.details||[]).filter($d$$=>$d$$.ma_tt1).joinModel2($id_app$$,"dmtt",[{where:{ma_vt:"ma_vt",ma_tt1:"ma_tt"},setFields:($item$$,$ref$$)=>{$item$$.thuoc_tinh=$ref$$;$item$$.nh_tt||($item$$.nh_tt=$ref$$.nh_tt)}}],function(){$callback1$$()})},function(){$callback$$()})},
|
|
93
|
+
details_dt:function($callback$$){async.map($items$$,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_dt).joinModel2($id_app$$,dmdt,[{where:"ma_dt",fields:["ten_dt"]}],function(){$callback1$$()})},function(){$callback$$()})},details_contract:function($callback$$){async.map($items$$,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_hd).joinModel2($id_app$$,contract,[{where:{ma_hd:"so_hd"},fields:[{name:"ten_hd",value:"ten_hd"}]}],function(){$callback1$$()})},
|
|
94
|
+
function(){$callback$$()})},details_phi:function($callback$$){async.map($items$$,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_phi).joinModel2($id_app$$,dmphi,[{where:"ma_phi",fields:["ten_phi"]}],function(){$callback1$$()})},function(){$callback$$()})},details_chietkhau:function($callback$$){async.map($items$$,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.id_cs_ck).joinModel2($id_app$$,"dmchietkhau",[{where:{id_cs_ck:"_id"},fields:["ma_chietkhau",
|
|
95
|
+
"ten_chietkhau"]}],function(){$callback1$$()})},function(){$callback$$()})}},async function(){$fn$$(null,$items$$)})};$contr$$.createRoute("export2viettel/:id_ct",async($req$$,$next$$)=>{var $ct_id_app$$=$req$$.user.current_id_app;const $app$$=await App.findOne({_id:$ct_id_app$$});if(!$app$$)return $next$$("Kh\u00f4ng t\u00ecm th\u1ea5y c\u00f4ng ty n\u00e0y");if(!$app$$.ma_so_thue)return $next$$("B\u1ea1n ch\u01b0a nh\u1eadp m\u00e3 s\u1ed1 thu\u1ebf c\u1ee7a c\u00f4ng ty");$ct_id_app$$=await model.findOne({id_app:$ct_id_app$$,
|
|
96
|
+
_id:$req$$.params.id_ct}).lean();if(!$ct_id_app$$)return $next$$("Ch\u1ee9ng t\u1eeb kh\u00f4ng h\u1ee3p l\u1ec7");try{let $rs$$=await utils.exportInvoice($app$$,$ct_id_app$$,$req$$.query.check_data);$next$$(null,$rs$$)}catch($e$$){$next$$({error:$e$$.message||$e$$.error||$e$$})}},{method:"GET"});$contr$$.createRoute("export2viettel/:id_ct",async($req$$,$next$$)=>{var $ct$jscomp$1_id_app$$=$req$$.user.current_id_app;const $app$$=await App.findOne({_id:$ct$jscomp$1_id_app$$});if(!$app$$)return $next$$("Kh\u00f4ng t\u00ecm th\u1ea5y c\u00f4ng ty n\u00e0y");
|
|
97
|
+
if(!$app$$.ma_so_thue)return $next$$("B\u1ea1n ch\u01b0a nh\u1eadp m\u00e3 s\u1ed1 thu\u1ebf c\u1ee7a c\u00f4ng ty");$ct$jscomp$1_id_app$$=await model.findOne({id_app:$ct$jscomp$1_id_app$$,_id:$req$$.params.id_ct}).lean();if(!$ct$jscomp$1_id_app$$)return $next$$("Ch\u1ee9ng t\u1eeb kh\u00f4ng h\u1ee3p l\u1ec7");try{let $body$$=$req$$.body||{};Logger.info("[vo-hd2] export2viettel",$body$$);$body$$.vatras&&($ct$jscomp$1_id_app$$.vatras=$body$$.vatras);$body$$.export_yn!=void 0&&($ct$jscomp$1_id_app$$.export_yn=
|
|
98
|
+
$body$$.export_yn);let $rs$$=await utils.exportInvoice($app$$,$ct$jscomp$1_id_app$$,$req$$.query.check_data);$next$$(null,$rs$$)}catch($e$$){$next$$({error:$e$$.message||$e$$.error||$e$$})}},{method:"POST"});$contr$$.createRoute("export/invoice/:id_ct",async($req$$,$next$$)=>{var $ct$jscomp$2_id_app$$=$req$$.user.current_id_app;const $app$$=await App.findOne({_id:$ct$jscomp$2_id_app$$});if(!$app$$)return $next$$("Kh\u00f4ng t\u00ecm th\u1ea5y c\u00f4ng ty n\u00e0y");if(!$app$$.ma_so_thue)return $next$$("B\u1ea1n ch\u01b0a nh\u1eadp m\u00e3 s\u1ed1 thu\u1ebf c\u1ee7a c\u00f4ng ty");
|
|
99
|
+
$ct$jscomp$2_id_app$$=await model.findOne({id_app:$ct$jscomp$2_id_app$$,_id:$req$$.params.id_ct}).lean();if(!$ct$jscomp$2_id_app$$)return $next$$("Ch\u1ee9ng t\u1eeb kh\u00f4ng h\u1ee3p l\u1ec7");try{let $rs$$=await utils.exportInvoice($app$$,$ct$jscomp$2_id_app$$,$req$$.query.check_data);$next$$(null,$rs$$)}catch($e$$){$next$$({error:$e$$.message||$e$$.error||$e$$})}},{method:"GET",action_code:"add"});$contr$$.createRoute("export/invoice/:id_ct",async($req$$,$next$$)=>{var $ct$jscomp$3_id_app$$=
|
|
100
|
+
$req$$.user.current_id_app;const $app$$=await App.findOne({_id:$ct$jscomp$3_id_app$$});if(!$app$$)return $next$$("Kh\u00f4ng t\u00ecm th\u1ea5y c\u00f4ng ty n\u00e0y");if(!$app$$.ma_so_thue)return $next$$("B\u1ea1n ch\u01b0a nh\u1eadp m\u00e3 s\u1ed1 thu\u1ebf c\u1ee7a c\u00f4ng ty");$ct$jscomp$3_id_app$$=await model.findOne({id_app:$ct$jscomp$3_id_app$$,_id:$req$$.params.id_ct}).lean();if(!$ct$jscomp$3_id_app$$)return $next$$("Ch\u1ee9ng t\u1eeb kh\u00f4ng h\u1ee3p l\u1ec7");try{let $body$$=$req$$.body||
|
|
101
|
+
{};$body$$.vatras&&($ct$jscomp$3_id_app$$.vatras=$body$$.vatras);$body$$.export_yn!=void 0&&($ct$jscomp$3_id_app$$.export_yn=$body$$.export_yn);let $rs$$=await utils.exportInvoice($app$$,$ct$jscomp$3_id_app$$,$req$$.query.check_data);$next$$(null,$rs$$)}catch($e$$){$next$$({error:$e$$.message||$e$$.error||$e$$})}},{method:"POST",action_code:"add"});$contr$$.createRoute("import/invoice",async($req$$,$next$$)=>{var $invoices_tu_ngay$$=$req$$.query.tu_ngay;let $den_ngay$$=$req$$.query.den_ngay;if(!$invoices_tu_ngay$$||
|
|
116
102
|
!$den_ngay$$)return $next$$("C\u1ea7n cung c\u1ea5p \u0111i\u1ec1u ki\u1ec7n tu_ngay,den_ngay");const $id_app$$=$req$$.user.current_id_app,$app$$=await App.findOne({_id:$id_app$$});if(!$app$$)return $next$$("Kh\u00f4ng t\u00ecm th\u1ea5y c\u00f4ng ty n\u00e0y");const $voucher_options$$=(await global.getModel("options").findOne({id_app:$id_app$$,id_func:$contr$$.name},{option:1}).lean()||{}).option||{};if(!$voucher_options$$.ma_kho)return $next$$("B\u1ea1n c\u1ea7n c\u1eadp nh\u1eadt tu\u1ef3 ch\u1ecdn m\u00e3 kho m\u1eb7c \u0111\u1ecbnh trong tu\u1ef3 ch\u1ecdn c\u1ee7a ch\u1ee9ng t\u1eeb");
|
|
117
103
|
if(!$voucher_options$$.tk_no)return $next$$("B\u1ea1n c\u1ea7n c\u1eadp nh\u1eadt tu\u1ef3 ch\u1ecdn t\u00e0i kho\u1ea3n n\u1ee3 m\u1eb7c \u0111\u1ecbnh trong tu\u1ef3 ch\u1ecdn c\u1ee7a ch\u1ee9ng t\u1eeb");if(!$voucher_options$$.tk_vt)return $next$$("B\u1ea1n c\u1ea7n c\u1eadp nh\u1eadt tu\u1ef3 ch\u1ecdn t\u00e0i v\u1eadt t\u01b0 m\u1eb7c \u0111\u1ecbnh trong tu\u1ef3 ch\u1ecdn c\u1ee7a ch\u1ee9ng t\u1eeb");if(!$voucher_options$$.tk_gv)return $next$$("B\u1ea1n c\u1ea7n c\u1eadp nh\u1eadt tu\u1ef3 ch\u1ecdn t\u00e0i kho\u1ea3n gi\u00e1 v\u1ed1n m\u1eb7c \u0111\u1ecbnh trong tu\u1ef3 ch\u1ecdn c\u1ee7a ch\u1ee9ng t\u1eeb");
|
|
118
104
|
if(!$voucher_options$$.tk_dt)return $next$$("B\u1ea1n c\u1ea7n c\u1eadp nh\u1eadt tu\u1ef3 ch\u1ecdn t\u00e0i kho\u1ea3n doanh thu m\u1eb7c \u0111\u1ecbnh trong tu\u1ef3 ch\u1ecdn c\u1ee7a ch\u1ee9ng t\u1eeb");try{$invoices_tu_ngay$$=new Date($invoices_tu_ngay$$);$den_ngay$$=new Date($den_ngay$$);let $invoices_vnpt$$=await utils.getInvoices($app$$,{tu_ngay:$invoices_tu_ngay$$,den_ngay:$den_ngay$$});$invoices_tu_ngay$$=[];for(let $ivn$$ of $invoices_vnpt$$)await model.findOne({id_app:$id_app$$,id_invoice:$ivn$$.id_invoice}).lean()||
|
|
@@ -1,26 +1,20 @@
|
|
|
1
1
|
const PostBook=require("../../libs/post-book"),PostSocai=require("../../libs/post-socai"),PostSokho=require("../../libs/post-sokho"),utils=require("../../libs/utils"),Sokhott=global.getModel("sokhott"),Vatra=global.getModel("vatra"),dmvt=global.getModel("dmvt"),dmkho=global.getModel("dmkho"),customer=global.getModel("customer"),dmdt=global.getModel("dmdt"),dmphi=global.getModel("dmphi"),contract=global.getModel("contract"),model=global.getModel("hd3"),controller=require("../../controllers/controller"),
|
|
2
2
|
async=require("async"),ma_ct="HD3";
|
|
3
|
-
module.exports=function($contr_router$$){$contr_router$$=new controller($contr_router$$,model,ma_ct.toLowerCase(),{isVoucher:!0,check_stock:!1,sort:{ngay_ct:-1,so_ct:-1}});$contr_router$$.route();$contr_router$$.post=async function($obj$$,$fn$$){$fn$$||=function(){}
|
|
4
|
-
$detail$$.
|
|
5
|
-
$
|
|
6
|
-
|
|
7
|
-
$
|
|
8
|
-
$
|
|
9
|
-
|
|
10
|
-
($
|
|
11
|
-
$
|
|
12
|
-
0)
|
|
13
|
-
$
|
|
14
|
-
|
|
15
|
-
$
|
|
16
|
-
$
|
|
17
|
-
$
|
|
18
|
-
{if($ds$$.length==1){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);$tien_thue_nt$$==0&&$tien_thue$$==0&&($tien_thue_nt$$=$obj$$.t_thue_nt||0,$tien_thue$$=$obj$$.t_thue||0);$ds$$[0].tien_thue_nt=$tien_thue_nt$$;$ds$$[0].tien_thue=$tien_thue$$}(new PostBook($obj$$,$ds$$,Vatra,function($detail$$,$callback$$){try{$detail$$.tk_du_thue=$obj$$.tk_co,$detail$$.t_tien_nt=-($detail$$.tien_ct_nt-
|
|
19
|
-
$detail$$.tien_ck_nt),$detail$$.t_tien=-($detail$$.tien_ct-$detail$$.tien_ck),$detail$$.t_thue_nt=0-$detail$$.tien_thue_nt,$detail$$.t_thue=0-$detail$$.tien_thue,$detail$$.ten_vt=$detail$$.ten_vt_vat||$obj$$.ten_vt||$obj$$.dien_giai}catch($e$$){Logger.error($e$$,$obj$$)}$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})}):$callback$$()})()},post_socai:function($callback$$){(async()=>{const $details_sc$$=[];if($details_thue$$.length===0&&$obj$$.t_thue_nt&&$obj$$.tk_thue_co){const $o$$=
|
|
20
|
-
{...$obj$$};$o$$.tk_co=$obj$$.tk_co;$o$$.tk_no=$obj$$.tk_thue_co;$o$$.tien_nt=Math.abs($obj$$.t_thue_nt);$o$$.tien=Math.abs($obj$$.t_thue);$o$$.dien_giai_thue&&($o$$.dien_giai=$o$$.dien_giai_thue);$details_sc$$.push($o$$)}else $details_thue$$.forEach($v_vatra$$=>{$v_vatra$$={...$v_vatra$$};$v_vatra$$.tk_co=$obj$$.tk_co;$v_vatra$$.tk_no=$v_vatra$$.tk_thue_co;$v_vatra$$.tien_nt=$v_vatra$$.tien_thue_nt;$v_vatra$$.tien=$v_vatra$$.tien_thue;$details_sc$$.push($v_vatra$$)});$obj$$.details.forEach(function($d$jscomp$18_detail$$){$d$jscomp$18_detail$$=
|
|
21
|
-
{...$d$jscomp$18_detail$$};$d$jscomp$18_detail$$.tien_ct_nt||($d$jscomp$18_detail$$.tien_ct_nt=$d$jscomp$18_detail$$.tien_nt,$d$jscomp$18_detail$$.tien_ct=$d$jscomp$18_detail$$.tien);$d$jscomp$18_detail$$.tk_no=$d$jscomp$18_detail$$.tk_tl||"52131";$d$jscomp$18_detail$$.ma_kh||($d$jscomp$18_detail$$.ma_kh=$obj$$.ma_kh);$d$jscomp$18_detail$$.tk_co=$obj$$.tk_co||"1111";$d$jscomp$18_detail$$.tien_nt=$d$jscomp$18_detail$$.tien_ct_nt-($d$jscomp$18_detail$$.tien_ck_nt||0);$d$jscomp$18_detail$$.tien=$d$jscomp$18_detail$$.tien_ct-
|
|
22
|
-
($d$jscomp$18_detail$$.tien_ck||0);$details_sc$$.push($d$jscomp$18_detail$$)});[...$product_details$$].forEach(function($d$jscomp$19_detail$$){$d$jscomp$19_detail$$={...$d$jscomp$19_detail$$};$d$jscomp$19_detail$$.tk_no=$d$jscomp$19_detail$$.tk_vt||"1561";$d$jscomp$19_detail$$.ma_kh||($d$jscomp$19_detail$$.ma_kh=$obj$$.ma_kh);$d$jscomp$19_detail$$.tk_co=$d$jscomp$19_detail$$.tk_gv||"6321";$d$jscomp$19_detail$$.tien_nt=$d$jscomp$19_detail$$.tien_nhap_nt;$d$jscomp$19_detail$$.tien=$d$jscomp$19_detail$$.tien_nhap;
|
|
23
|
-
$details_sc$$.push($d$jscomp$19_detail$$)});(await $obj$$.details.filter($r$$=>$r$$.tien_hoa_hong_ctv&&$r$$.ma_ctv).asyncGroupBy(["ma_ctv","tk_cp_ctv","tk_cn_ctv"],["tien_hoa_hong_ctv"])).forEach($r$$=>{let $tt$$={};$tt$$.tk_co=$r$$.tk_cp_ctv;$tt$$.tk_no=$r$$.tk_cn_ctv;$tt$$.ma_kh=$r$$.ma_ctv;$tt$$.tien=$tt$$.tien_nt=$r$$.tien_hoa_hong_ctv;$tt$$.tk_no&&$tt$$.tk_co&&$tt$$.tien&&$details_sc$$.push($tt$$)});(await $obj$$.details.filter($r$$=>$r$$.tien_hoa_hong_ctv2&&$r$$.ma_ctv2).asyncGroupBy(["ma_ctv2",
|
|
3
|
+
module.exports=function($contr_router$$){$contr_router$$=new controller($contr_router$$,model,ma_ct.toLowerCase(),{isVoucher:!0,check_stock:!1,sort:{ngay_ct:-1,so_ct:-1}});$contr_router$$.route();$contr_router$$.post=async function($obj$$,$fn$$){$fn$$||=function(){};$obj$$.details.forEach($detail$$=>{$detail$$.tien_ct_nt||($detail$$.gia_ban_ct_nt=$detail$$.gia_ban_nt,$detail$$.tien_ct_nt=$detail$$.tien_nt,$detail$$.tien_ct=$detail$$.tien,$detail$$.tien_ck_nt=0,$detail$$.tien_ck=0,$detail$$.thue_suat=
|
|
4
|
+
$detail$$.thue_suat||0,$detail$$.tien_thue_nt=$detail$$.tien_thue_nt||0,$detail$$.gia_ban_nt=$detail$$.gia_ban_ct_nt*(1+$detail$$.thue_suat/100))});let $product_details$$=[...$obj$$.details].map($detail$$=>$detail$$.combo&&$detail$$.combo.length>0?$detail$$.combo.map($item_combo$$=>{$item_combo$$=$item_combo$$.toObject?$item_combo$$.toObject():{...$item_combo$$};$item_combo$$.ma_kho=$detail$$.ma_kho;$item_combo$$.pn_gia_tb=$detail$$.pn_gia_tb;return $item_combo$$}):[$detail$$]).reduce(($a$$,$b$$)=>
|
|
5
|
+
$a$$.concat($b$$),[]);await $product_details$$.filter($d$$=>!$d$$.ma_dvt).asyncJoinModel2($obj$$.id_app,"dmvt",{where:"ma_vt",fields:"ma_dvt"});let $details_thue$$=$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||0,tien_thue:$detail$$.tien_thue||0})).filter($d$$=>$d$$.ma_thue);await $details_thue$$.filter($r$$=>!$r$$.tk_thue_co&&$r$$.ma_thue).asyncJoinModel2($obj$$.id_app,
|
|
6
|
+
"vat",{where:"ma_thue",fields:["tk_thue_co"]});async.series({post_tdttno:$callback$$=>{setImmediate(async()=>{var $hds_tdttno_tt$$=[...(new Set(($obj$$.details||[]).filter($d$$=>$d$$.id_hd).map($d$$=>$d$$.id_hd)))];if($hds_tdttno_tt$$.length==0)return $callback$$();$hds_tdttno_tt$$=(await global.getModel("tdttno").getBalance({id_app:$obj$$.id_app,id_hd:{$in:$hds_tdttno_tt$$}})).map($invoice$$=>{let $t_invoice$$={sel:!1,id_tdtt:$invoice$$._id,line:$invoice$$.line,id_hd:$invoice$$.id_ct,so_hd:$invoice$$.so_hd||
|
|
7
|
+
$invoice$$.so_ct,ngay_hd:$invoice$$.ngay_hd||$invoice$$.ngay_ct,tien_hd_nt:$invoice$$.tien_nt};$t_invoice$$.ma_nt_hd=$invoice$$.ma_nt;$t_invoice$$.ty_gia_hd=$invoice$$.ty_gia;$t_invoice$$.ma_kh=$invoice$$.ma_kh;$t_invoice$$.dien_giai=$invoice$$.dien_giai;$t_invoice$$.tk_co=$invoice$$.tk_no;$t_invoice$$.da_thanh_toan_nt=$invoice$$.da_thanh_toan_nt;$t_invoice$$.da_thanh_toan=$invoice$$.da_thanh_toan;$t_invoice$$.con_lai_nt=$invoice$$.con_lai_nt;$t_invoice$$.con_lai=$invoice$$.con_lai;$t_invoice$$.tien_nt=
|
|
8
|
+
$obj$$.details.filter($d$$=>$d$$.id_hd===$t_invoice$$.id_hd).map($d$$=>$d$$.tien_nt||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$t_invoice$$.tien=$t_invoice$$.tien_nt*$obj$$.ty_gia;$t_invoice$$.thanh_toan_qd=$t_invoice$$.tien/$t_invoice$$.ty_gia_hd;return $t_invoice$$});(new PostBook($obj$$,$hds_tdttno_tt$$,global.getModel("tdttno_tt"),function($tdttno$$,$callback$$){$callback$$($tdttno$$)})).run(function($e$$,$details$$){if($e$$)return $callback$$($e$$);async.map($details$$,($detail$$,$callback$$)=>{$detail$$.con_lai_nt<=
|
|
9
|
+
$detail$$.thanh_toan_qd?global.getModel("tdttno").updateOne({_id:$detail$$.id_tdtt.toString()},{tat_toan:!0},($error$$,$result$$)=>{$callback$$($error$$,$result$$)}):$callback$$(null,$detail$$)},($e$$,$rs$$)=>{$callback$$($e$$,$rs$$)})})})},post_sokho:function($callback$$){(new PostSokho($obj$$,$product_details$$,async function($detail$$,$callback$$){$detail$$.nxt=1;$detail$$.tk_co=$obj$$.tk_co;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})},post_sokhott:function($callback$$){(new PostBook($obj$$,
|
|
10
|
+
$product_details$$,Sokhott,async function($detail$$,$callback$$){$detail$$.nxt=1;$detail$$.tk_co=$obj$$.tk_co;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})},post_vatra:function($callback$$){(async()=>{$obj$$.ngay_hd?$details_thue$$.length==0&&$obj$$.so_hd&&$obj$$.ngay_hd&&$obj$$.ma_thue&&$obj$$.t_thue_nt?(new PostBook($obj$$,[{...$obj$$}],Vatra,function($obj$$,$callback$$){$obj$$.tk_du_thue=$obj$$.tk_co;$obj$$.t_tien_nt=-($obj$$.details.csum("tien_ct_nt")-$obj$$.details.csum("tien_ck_nt"));
|
|
11
|
+
$obj$$.t_tien=-($obj$$.details.csum("tien_ct")-$obj$$.details.csum("tien_ck"));$obj$$.t_thue_nt=0-$obj$$.t_thue_nt;$obj$$.t_thue=0-$obj$$.t_thue;$obj$$.ten_vt||($obj$$.ten_vt=$obj$$.dien_giai);$callback$$($obj$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)}):$details_thue$$.asyncGroupBy(["ma_thue","thue_suat","ten_vt_vat","tk_thue_co"],"tien_ct_nt tien_ct tien_ck_nt tien_ck tien_thue tien_thue_nt tien_nt tien".split(" ")).then($ds$$=>{if($ds$$.length==1){let $tien_thue_nt$$=$ds$$.map($d$$=>
|
|
12
|
+
$d$$.tien_thue_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0),$tien_thue$$=$ds$$.map($d$$=>$d$$.tien_thue).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$tien_thue_nt$$==0&&$tien_thue$$==0&&($tien_thue_nt$$=$obj$$.t_thue_nt||0,$tien_thue$$=$obj$$.t_thue||0);$ds$$[0].tien_thue_nt=$tien_thue_nt$$;$ds$$[0].tien_thue=$tien_thue$$}(new PostBook($obj$$,$ds$$,Vatra,function($detail$$,$callback$$){try{$detail$$.tk_du_thue=$obj$$.tk_co,$detail$$.t_tien_nt=-($detail$$.tien_ct_nt-$detail$$.tien_ck_nt),$detail$$.t_tien=-($detail$$.tien_ct-
|
|
13
|
+
$detail$$.tien_ck),$detail$$.t_thue_nt=0-$detail$$.tien_thue_nt,$detail$$.t_thue=0-$detail$$.tien_thue,$detail$$.ten_vt=$detail$$.ten_vt_vat||$obj$$.ten_vt||$obj$$.dien_giai}catch($e$$){Logger.error($e$$,$obj$$)}$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})}):$callback$$()})()},post_socai:function($callback$$){(async()=>{const $details_sc$$=[];if($details_thue$$.length===0&&$obj$$.t_thue_nt&&$obj$$.tk_thue_co){const $o$$={...$obj$$};$o$$.tk_co=$obj$$.tk_co;$o$$.tk_no=
|
|
14
|
+
$obj$$.tk_thue_co;$o$$.tien_nt=Math.abs($obj$$.t_thue_nt);$o$$.tien=Math.abs($obj$$.t_thue);$o$$.dien_giai_thue&&($o$$.dien_giai=$o$$.dien_giai_thue);$details_sc$$.push($o$$)}else $details_thue$$.forEach($v_vatra$$=>{$v_vatra$$={...$v_vatra$$};$v_vatra$$.tk_co=$obj$$.tk_co;$v_vatra$$.tk_no=$v_vatra$$.tk_thue_co;$v_vatra$$.tien_nt=$v_vatra$$.tien_thue_nt;$v_vatra$$.tien=$v_vatra$$.tien_thue;$details_sc$$.push($v_vatra$$)});$obj$$.details.forEach(function($d$jscomp$10_detail$$){$d$jscomp$10_detail$$=
|
|
15
|
+
{...$d$jscomp$10_detail$$};$d$jscomp$10_detail$$.tien_ct_nt||($d$jscomp$10_detail$$.tien_ct_nt=$d$jscomp$10_detail$$.tien_nt,$d$jscomp$10_detail$$.tien_ct=$d$jscomp$10_detail$$.tien);$d$jscomp$10_detail$$.tk_no=$d$jscomp$10_detail$$.tk_tl||"52131";$d$jscomp$10_detail$$.ma_kh||($d$jscomp$10_detail$$.ma_kh=$obj$$.ma_kh);$d$jscomp$10_detail$$.tk_co=$obj$$.tk_co||"1111";$d$jscomp$10_detail$$.tien_nt=$d$jscomp$10_detail$$.tien_ct_nt-($d$jscomp$10_detail$$.tien_ck_nt||0);$d$jscomp$10_detail$$.tien=$d$jscomp$10_detail$$.tien_ct-
|
|
16
|
+
($d$jscomp$10_detail$$.tien_ck||0);$details_sc$$.push($d$jscomp$10_detail$$)});[...$product_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_vt||"1561";$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_gv||"6321";$d$jscomp$11_detail$$.tien_nt=$d$jscomp$11_detail$$.tien_nhap_nt;$d$jscomp$11_detail$$.tien=$d$jscomp$11_detail$$.tien_nhap;
|
|
17
|
+
$details_sc$$.push($d$jscomp$11_detail$$)});(await $obj$$.details.filter($r$$=>$r$$.tien_hoa_hong_ctv&&$r$$.ma_ctv).asyncGroupBy(["ma_ctv","tk_cp_ctv","tk_cn_ctv"],["tien_hoa_hong_ctv"])).forEach($r$$=>{let $tt$$={};$tt$$.tk_co=$r$$.tk_cp_ctv;$tt$$.tk_no=$r$$.tk_cn_ctv;$tt$$.ma_kh=$r$$.ma_ctv;$tt$$.tien=$tt$$.tien_nt=$r$$.tien_hoa_hong_ctv;$tt$$.tk_no&&$tt$$.tk_co&&$tt$$.tien&&$details_sc$$.push($tt$$)});(await $obj$$.details.filter($r$$=>$r$$.tien_hoa_hong_ctv2&&$r$$.ma_ctv2).asyncGroupBy(["ma_ctv2",
|
|
24
18
|
"tk_cp_ctv","tk_cn_ctv"],["tien_hoa_hong_ctv2"])).forEach($r$$=>{let $tt$$={};$tt$$.tk_co=$r$$.tk_cp_ctv;$tt$$.tk_no=$r$$.tk_cn_ctv;$tt$$.ma_kh=$r$$.ma_ctv2;$tt$$.tien=$tt$$.tien_nt=$r$$.tien_hoa_hong_ctv2;$tt$$.tk_no&&$tt$$.tk_co&&$tt$$.tien&&$details_sc$$.push($tt$$)});(await $obj$$.details.filter($r$$=>$r$$.tien_hoa_hong&&$r$$.ma_kh_hoa_hong).asyncGroupBy(["ma_kh_hoa_hong","tk_no_hoa_hong","tk_co_hoa_hong"],["tien_hoa_hong"])).forEach($r$$=>{let $tt$$={};$tt$$.tk_co=$r$$.tk_no_hoa_hong;$tt$$.tk_no=
|
|
25
19
|
$r$$.tk_co_hoa_hong;$tt$$.ma_kh=$r$$.ma_kh_hoa_hong;$tt$$.tien=$tt$$.tien_nt=$r$$.tien_hoa_hong;$tt$$.tien=$tt$$.tien_nt*($obj$$.ty_gia||1);$tt$$.check_balance=!1;$tt$$.tk_no&&$tt$$.tk_co&&$tt$$.tien&&$details_sc$$.push($tt$$)});(await $obj$$.details.filter($r$$=>$r$$.tien_hoa_hong_gt&&$r$$.ma_kh_hoa_hong_gt).asyncGroupBy(["ma_kh_hoa_hong_gt","tk_no_hoa_hong_gt","tk_co_hoa_hong_gt"],["tien_hoa_hong_gt"])).forEach($r$$=>{let $tt$$={};$tt$$.tk_co=$r$$.tk_no_hoa_hong_gt;$tt$$.tk_no=$r$$.tk_co_hoa_hong_gt;
|
|
26
20
|
$tt$$.ma_kh=$r$$.ma_kh_hoa_hong_gt;$tt$$.tien_nt=$r$$.tien_hoa_hong_gt;$tt$$.tien=$tt$$.tien_nt*($obj$$.ty_gia||1);$tt$$.check_balance=!1;$tt$$.tk_no&&$tt$$.tk_co&&$tt$$.tien&&$details_sc$$.push($tt$$)});(await $obj$$.details.filter($r$$=>$r$$.tien_hoa_hong_ql&&$r$$.ma_kh_hoa_hong_ql).asyncGroupBy(["ma_kh_hoa_hong_ql","tk_no_hoa_hong_ql","tk_co_hoa_hong_ql"],["tien_hoa_hong_ql"])).forEach($r$$=>{let $tt$$={};$tt$$.tk_co=$r$$.tk_no_hoa_hong_ql;$tt$$.tk_no=$r$$.tk_co_hoa_hong_ql;$tt$$.ma_kh=$r$$.ma_kh_hoa_hong_ql;
|