flexbiz-server 12.2.3 → 12.2.4
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 +27 -26
- package/server/controllers/controller.js +56 -55
- package/server/controllers/controllerRPT.js +18 -17
- package/server/libs/cdpstk.js +1 -1
- package/server/libs/databanle.js +13 -13
- package/server/libs/getGiaban.js +23 -22
- package/server/libs/post-book.js +9 -8
- package/server/libs/post-socai.js +9 -9
- package/server/libs/prototypes.js +4 -4
- package/server/libs/tinhGtPhanboSltp.js +5 -5
- package/server/libs/tinhGtPhanboYtcp.js +2 -2
- package/server/libs/tinhGtThcppstk.js +1 -1
- package/server/libs/tinhGtTrucTiep.js +8 -7
- package/server/libs/tinhgiatb.js +4 -4
- package/server/libs/tinhgiatb1vt.js +3 -3
- package/server/libs/tinhhoahong.js +32 -0
- package/server/libs/utils.js +4 -3
- package/server/models/app.js +9 -8
- package/server/models/approve.js +4 -4
- package/server/models/customer.js +8 -8
- package/server/models/dh2.js +10 -9
- package/server/models/dmgiaban.js +6 -6
- package/server/models/dmhoahonghd.js +6 -5
- package/server/models/fbconversation.js +9 -0
- package/server/models/fbmessage.js +2 -0
- package/server/models/fbpage.js +2 -0
- package/server/models/group.js +4 -2
- package/server/models/hd2.js +8 -8
- package/server/models/hd3.js +9 -9
- package/server/models/hd7.js +1 -1
- package/server/models/notification.js +3 -2
- package/server/models/participant.js +5 -5
- package/server/models/pbl.js +4 -4
- package/server/models/reportinfo.js +2 -2
- package/server/models/rptform.js +3 -2
- package/server/models/schedule.js +1 -1
- package/server/models/so1.js +7 -6
- package/server/models/socai.js +4 -4
- package/server/models/tdttco.js +8 -4
- package/server/models/tdttno.js +8 -4
- package/server/models/tokens.js +2 -2
- package/server/models/usergroup.js +5 -4
- package/server/models/vatra.js +2 -2
- package/server/models/vatvao.js +4 -4
- package/server/modules/lists/ls-assinvestment.js +1 -1
- package/server/modules/lists/ls-customer.js +13 -14
- package/server/modules/lists/ls-dmvt.js +48 -39
- package/server/modules/lists/ls-fbconversation.js +3 -0
- package/server/modules/lists/ls-fbmessage.js +3 -0
- package/server/modules/lists/ls-fbpage.js +10 -0
- package/server/modules/lists/ls-introducecode.js +1 -1
- package/server/modules/lists/ls-news.js +1 -1
- package/server/modules/lists/ls-opportunity.js +3 -3
- package/server/modules/lists/ls-session.js +1 -1
- package/server/modules/public/callin.js +6 -6
- package/server/modules/reports/rp-cdpstk.js +3 -3
- package/server/modules/reports/rp-chitiettaisan.js +9 -8
- package/server/modules/reports/rp-ckvt.js +9 -7
- package/server/modules/reports/rp-ctbanle.js +13 -12
- package/server/modules/reports/rp-databanle.js +8 -4
- package/server/modules/reports/rp-dtbanletheoct.js +16 -9
- package/server/modules/reports/rp-dtbanletheokh.js +12 -6
- package/server/modules/reports/rp-dtbanletheokho.js +14 -9
- package/server/modules/reports/rp-dtbanletheonam.js +15 -9
- package/server/modules/reports/rp-dtbanletheongay.js +13 -8
- package/server/modules/reports/rp-dtbanletheonv.js +15 -9
- package/server/modules/reports/rp-dtbanletheoquy.js +15 -9
- package/server/modules/reports/rp-dtbanletheothang.js +15 -9
- package/server/modules/reports/rp-getinvoice2pay.js +4 -6
- package/server/modules/reports/rp-getinvoice2receive.js +4 -6
- package/server/modules/reports/rp-hoahong.js +9 -0
- package/server/modules/reports/rp-kqhdkd.js +5 -4
- package/server/modules/reports/rp-ptcttct.js +7 -6
- package/server/modules/reports/rp-pttct.js +8 -8
- package/server/modules/reports/rp-pttctkho.js +3 -2
- package/server/modules/reports/rp-pttctkho2.js +3 -3
- package/server/modules/reports/rp-thnxt.js +8 -8
- package/server/modules/reports/rp-thnxt_sl.js +6 -6
- package/server/modules/reports/rp-thnxttt.js +6 -6
- package/server/modules/reports/rp-tmbctc.js +16 -16
- package/server/modules/systems/sys-app.js +25 -24
- package/server/modules/systems/sys-notification.js +2 -2
- package/server/modules/systems/sys-schedule.js +1 -1
- package/server/modules/systems/sys-user.js +8 -8
- package/server/modules/vouchers/vo-bc1.js +9 -8
- package/server/modules/vouchers/vo-bg2.js +9 -9
- package/server/modules/vouchers/vo-bn1.js +5 -4
- package/server/modules/vouchers/vo-dh2.js +15 -38
- package/server/modules/vouchers/vo-dnm.js +11 -12
- package/server/modules/vouchers/vo-hd2.js +63 -83
- package/server/modules/vouchers/vo-hd3.js +28 -22
- package/server/modules/vouchers/vo-hd7.js +37 -36
- package/server/modules/vouchers/vo-pbl.js +49 -49
- package/server/modules/vouchers/vo-pc1.js +9 -8
- package/server/modules/vouchers/vo-pn1.js +24 -22
- package/server/modules/vouchers/vo-pn5.js +1 -1
- package/server/modules/vouchers/vo-pn9.js +23 -23
- package/server/modules/vouchers/vo-pnc.js +8 -8
- package/server/modules/vouchers/vo-pnh.js +5 -5
- package/server/modules/vouchers/vo-pt1.js +17 -16
- package/server/modules/vouchers/vo-pxc.js +16 -16
- package/server/modules/vouchers/vo-pxh.js +12 -10
- package/server/modules/vouchers/vo-so1.js +94 -119
- package/server/modules/vouchers/vo-so4.js +1 -1
- package/server/modules/vouchers/vo-so5.js +2 -2
- package/server/workers/restoreApp.js +21 -12
- package/server/workers/runScript.js +3 -3
|
@@ -1,87 +1,67 @@
|
|
|
1
1
|
'use strict';const PostBook=require("../../libs/post-book"),PostSocai=require("../../libs/post-socai"),Sokho=global.getModel("sokho"),Sokhott=global.getModel("sokhott"),Tdttno=global.getModel("tdttno"),Tdttno_tt=global.getModel("tdttno_tt"),Vatra=global.getModel("vatra"),Options=global.getModel("options"),dvcs=global.getModel("dvcs"),dmvt=global.getModel("dmvt"),account=global.getModel("account"),dmkho=global.getModel("dmkho"),customer=global.getModel("customer"),dmnv=global.getModel("dmnv"),dmdt=
|
|
2
|
-
global.getModel("dmdt"),dmphi=global.getModel("dmphi"),contract=global.getModel("contract"),salecontract=global.getModel("sale_contract"),model=global.getModel("hd2"),controller=require("../../controllers/controller"),utils=require("../../libs/utils"),trangthai=global.getModel("trangthai"),async=require("async"),ma_ct="HD2",underscore=require("underscore"),App=global.getModel("app"),axios=require("axios"),moment=require("moment"),numeral=require("numeral"),
|
|
3
|
-
{DirectSecp256k1HdWallet}=require("@cosmjs/proto-signing"),spend=async($appInfo$$,$receiver_user$$,$receiver_address$$,$amount$$,$denom$$,$memo$$,$introduce_code$$,$sub_action$$="")=>{try{await blockchainconnect.spend($appInfo$$._id,$appInfo$$.wallet_token,$appInfo$$.wallet_address,$receiver_address$$,{amount:$amount$$,denom:$denom$$,memo:$memo$$,action:"bonus",introduce_code:$introduce_code$$,sub_action:$sub_action$$})}catch($e$$){console.error("Error send coin"
|
|
4
|
-
$amount$$,$denom$$,$memo$$)}}
|
|
5
|
-
|
|
6
|
-
$
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
{$
|
|
11
|
-
$
|
|
12
|
-
$detail$$.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
$
|
|
18
|
-
$
|
|
19
|
-
$
|
|
20
|
-
$
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
($
|
|
24
|
-
{
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
$
|
|
28
|
-
($
|
|
29
|
-
$
|
|
30
|
-
|
|
31
|
-
await
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
$
|
|
36
|
-
|
|
37
|
-
$
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
$
|
|
41
|
-
$
|
|
42
|
-
$
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
$
|
|
46
|
-
($
|
|
47
|
-
$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,$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,
|
|
48
|
-
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$$,$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$$,
|
|
49
|
-
$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")-$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$$,
|
|
50
|
-
$obj$$)}$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$jscomp$0$$($e$$,$rs$$)}):Tdttno.deleteMany({id_ct:$obj$$._id},function($error$$){$callback$jscomp$0$$($error$$)})})},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(),
|
|
51
|
-
username:$obj$$.user_nv,wallet_type:1});if(!$wallet_nhan_vien$$){$wallet_nhan_vien$$=(new global.getModel("asskey"))({user_created:$obj$$.user_nv,username:$obj$$.user_nv,id_app:$obj$$.id_app,wallet_type:1});const $wallet$$=await DirectSecp256k1HdWallet.generate(24,{prefix:configs.ADDRESS_PREFIX});let $accounts$$=await $wallet$$.getAccounts();$wallet_nhan_vien$$.address=$accounts$$[0].address;$wallet_nhan_vien$$.mnemonic=$wallet$$.mnemonic;$wallet_nhan_vien$$.name="T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng";
|
|
52
|
-
await $wallet_nhan_vien$$.save()}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$$,$memo$$,"","2");$obj$$.da_chuyen_hoa_hong=!0;await model.updateOne({_id:$obj$$._id},{da_chuyen_hoa_hong:!0})}}catch($e$$){console.error("Kh\u00f4ng th\u1ec3 thanh to\u00e1n ti\u1ec1n hoa h\u1ed3ng",
|
|
53
|
-
$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$$=await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),username:$obj$$.user_gt,wallet_type:1});if(!$wallet_gt$$){$wallet_gt$$=(new global.getModel("asskey"))({user_created:$obj$$.user_gt,
|
|
54
|
-
username:$obj$$.user_gt,id_app:$obj$$.id_app,wallet_type:1});const $wallet$$=await DirectSecp256k1HdWallet.generate(24,{prefix:configs.ADDRESS_PREFIX});let $accounts$$=await $wallet$$.getAccounts();$wallet_gt$$.address=$accounts$$[0].address;$wallet_gt$$.mnemonic=$wallet$$.mnemonic;$wallet_gt$$.name="T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng";await $wallet_gt$$.save()}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()}`;
|
|
55
|
-
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$$){console.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()=>
|
|
56
|
-
{try{if($appInfo$$.wallet_address&&$appInfo$$.wallet_token&&$appInfo$$.tang_gioi_thieu_denom){let $wallet_gt$$=await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),username:$obj$$.user_ctv,wallet_type:1});if(!$wallet_gt$$){$wallet_gt$$=(new global.getModel("asskey"))({user_created:$obj$$.user_ctv,username:$obj$$.user_ctv,id_app:$obj$$.id_app,wallet_type:1});const $wallet$$=await DirectSecp256k1HdWallet.generate(24,{prefix:configs.ADDRESS_PREFIX});let $accounts$$=await $wallet$$.getAccounts();
|
|
57
|
-
$wallet_gt$$.address=$accounts$$[0].address;$wallet_gt$$.mnemonic=$wallet$$.mnemonic;$wallet_gt$$.name="T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng";await $wallet_gt$$.save()}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()}`;await spend($appInfo$$,$obj$$.be_introduced,$wallet_gt$$.address,$amount$$,$denom$$,$memo$$,$obj$$.introduce_code,
|
|
58
|
-
"2");$obj$$.da_chuyen_hoa_hong_ctv=!0;await model.updateOne({_id:$obj$$._id},{da_chuyen_hoa_hong_ctv:!0})}}catch($e$$){console.error("Kh\u00f4ng th\u1ec3 thanh to\u00e1n ti\u1ec1n hoa h\u1ed3ng",$e$$)}$callback$$()})}},function($e$$,$rs$$){$fn$$($e$$,$rs$$)})};const $valid$$=function($i_t_thue_nt_user$$,$obj$$,$next$$){for($i_t_thue_nt_user$$=0;$i_t_thue_nt_user$$<$obj$$.details.length;$i_t_thue_nt_user$$++){var $detail$jscomp$0$$=$obj$$.details[$i_t_thue_nt_user$$];$obj$$.ma_kho&&($detail$jscomp$0$$.ma_kho=
|
|
59
|
-
$obj$$.ma_kho);$detail$jscomp$0$$.line=$i_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;$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?
|
|
60
|
-
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$$)});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"))*
|
|
61
|
-
$obj$$.thue_suat/100,$f_tien_nt$$),$obj$$.t_thue=utils.round($obj$$.t_thue_nt*($obj$$.ty_gia||1),0),$i_t_thue_nt_user$$=$obj$$.details.csum("tien_thue_nt"),$detail$jscomp$0$$=$obj$$.details.csum("tien_thue"),($i_t_thue_nt_user$$!==$obj$$.t_thue_nt||$detail$jscomp$0$$!==$obj$$.t_thue)&&0<$obj$$.details.length)){let $row_dieu_chinh$$=$obj$$.details[$obj$$.details.length-1];$row_dieu_chinh$$.tien_thue_nt+=$obj$$.t_thue_nt-$i_t_thue_nt_user$$;$row_dieu_chinh$$.tien_thue+=$obj$$.t_thue-$detail$jscomp$0$$}$obj$$.id_contract?
|
|
62
|
-
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$$);$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$$);
|
|
63
|
-
$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")}`):$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$$);
|
|
64
|
-
$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")}`):$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",
|
|
65
|
-
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$$()})},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$$,
|
|
66
|
-
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",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$$=>
|
|
2
|
+
global.getModel("dmdt"),dmphi=global.getModel("dmphi"),contract=global.getModel("contract"),salecontract=global.getModel("sale_contract"),model=global.getModel("hd2"),controller=require("../../controllers/controller"),utils=require("../../libs/utils"),tinhhoahong=require("../../libs/tinhhoahong"),trangthai=global.getModel("trangthai"),async=require("async"),ma_ct="HD2",underscore=require("underscore"),App=global.getModel("app"),axios=require("axios"),moment=require("moment"),numeral=require("numeral"),
|
|
3
|
+
blockchainconnect=require("../../libs/blockchainconnect"),{DirectSecp256k1HdWallet}=require("@cosmjs/proto-signing"),spend=async($appInfo$$,$receiver_user$$,$receiver_address$$,$amount$$,$denom$$,$memo$$,$introduce_code$$,$sub_action$$="")=>{try{await blockchainconnect.spend($appInfo$$._id,$appInfo$$.wallet_token,$appInfo$$.wallet_address,$receiver_address$$,{amount:$amount$$,denom:$denom$$,memo:$memo$$,action:"bonus",introduce_code:$introduce_code$$,sub_action:$sub_action$$})}catch($e$$){console.error("Error send coin",
|
|
4
|
+
$e$$,$receiver_user$$,$receiver_address$$,$amount$$,$denom$$,$memo$$)}};
|
|
5
|
+
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$$)=>{$obj$$.user_created||($obj$$.user_created=$user$$.email);$obj$$.details.forEach($d$$=>{$d$$.tt_nt=$d$$.tien_nt-$d$$.tien_ck_nt;$d$$.tt=$d$$.tien-$d$$.tien_ck;$d$$.tien_xuat_tmp=$d$$.sl_xuat*($d$$.gia_mua||0)});$obj$$.id_dh2||await tinhhoahong($obj$$)};
|
|
6
|
+
$contr$$.post=async($obj$$,$fn$$)=>{$fn$$||($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$$.ma_ct.toLowerCase()},"option")}catch($e$$){console.log($e$$.message,{id_func:$obj$$.ma_ct})}$options$$||($options$$={});await $obj$$.details.asyncJoinModel2($obj$$.id_app,dmvt,{where:"ma_vt",
|
|
7
|
+
fields:["gia_mua"]});let $product_details$$=$obj$$.details.map($detail$$=>$detail$$.combo&&0<$detail$$.combo.length?$detail$$.combo.map($item$$=>$item$$=$item$$.toObject?$item$$.toObject():{...$item$$}):[$detail$$]).reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]);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$$={};
|
|
8
|
+
underscore.extend($_p$$,$p$$,{sl_xuat:$p$$.sl_km});$details$$.push($_p$$)}})});$obj$$.promotion&&$obj$$.promotion.forEach($p$$=>{if($p$$.ma_vt&&$p$$.sl_km){let $_p$$={};underscore.extend($_p$$,$p$$,{sl_xuat:$p$$.sl_km});$details$$.push($_p$$)}});async.series({kt:$callback$jscomp$0$$=>{$options$$.not_post_sokho?$callback$jscomp$0$$():(new PostBook($obj$$,$product_details$$,Sokho,async($detail$$,$callback$$)=>{$detail$$.nxt=2;$detail$$.tk_no=$obj$$.tk_no;$detail$$.ma_kho=$detail$$.ma_kho||$obj$$.ma_kho;
|
|
9
|
+
$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$jscomp$0$$($e$$,$rs$$)})},tt:$callback$jscomp$0$$=>{$options$$.post_sokhott?(new PostBook($obj$$,$product_details$$,Sokhott,async($detail$$,$callback$$)=>{$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$jscomp$0$$($e$$,$rs$$)}):$callback$jscomp$0$$()}},($e$$,$rs$$)=>{$callback$jscomp$1$$($e$$,$rs$$)})},post_vatra:function($callback$jscomp$0$$){(async()=>
|
|
10
|
+
{if($obj$$.ngay_hd){let $d$jscomp$0$$=$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$jscomp$0$$.filter($r$$=>!$r$$.tk_thue_co&&$r$$.ma_thue).asyncJoinModel2($obj$$.id_app,"vat",{where:"ma_thue",fields:["tk_thue_co"]});$d$jscomp$0$$.asyncGroupBy(["ma_thue","thue_suat","ten_vt_vat",
|
|
11
|
+
"tk_thue_co"],"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=$tien_thue_nt$$;$ds$$[0].tien_thue=$tien_thue$$}(new PostBook($obj$$,$ds$$,Vatra,function($detail$$,
|
|
12
|
+
$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$$,$rs$$)})})}else $callback$jscomp$0$$()})()},post_socai:function($callback$jscomp$0$$){setImmediate(async()=>
|
|
13
|
+
{let $details$$=[];$obj$$.details.forEach(function($d$jscomp$7_detail$$){$d$jscomp$7_detail$$={...$d$jscomp$7_detail$$};$d$jscomp$7_detail$$.tk_co=$d$jscomp$7_detail$$.tk_dt||$kho$$.tk_dt||$options$$.tk_dt;$d$jscomp$7_detail$$.ma_kh||($d$jscomp$7_detail$$.ma_kh=$obj$$.ma_kh);$d$jscomp$7_detail$$.tk_no=$obj$$.tk_no;$details$$.push($d$jscomp$7_detail$$)});$obj$$.details.forEach(function($d$jscomp$8_detail$$){$d$jscomp$8_detail$$={...$d$jscomp$8_detail$$};$d$jscomp$8_detail$$.tk_no=$d$jscomp$8_detail$$.tk_ck||
|
|
14
|
+
$obj$$.tk_ck||$kho$$.tk_ck||$options$$.tk_ck;$d$jscomp$8_detail$$.ma_kh||($d$jscomp$8_detail$$.ma_kh=$obj$$.ma_kh);$d$jscomp$8_detail$$.tk_co=$obj$$.tk_no;$d$jscomp$8_detail$$.tien_nt=$d$jscomp$8_detail$$.tien_ck_nt;$d$jscomp$8_detail$$.tien=$d$jscomp$8_detail$$.tien_ck;$d$jscomp$8_detail$$.check_balance=!1;$details$$.push($d$jscomp$8_detail$$)});if($obj$$.tien_ck_hd){var $o_tt$$={};$o_tt$$.tk_no=$obj$$.tk_ck||$kho$$.tk_ck||$options$$.tk_ck;$o_tt$$.tk_co=$obj$$.tk_no;$o_tt$$.tien_nt=$obj$$.tien_ck_hd;
|
|
15
|
+
$o_tt$$.tien=$o_tt$$.tien_nt*($obj$$.ty_gia||1);$o_tt$$.ma_kh=$obj$$.ma_kh;$o_tt$$.check_balance=!1;$details$$.push($o_tt$$)}$obj$$.thu_nhap_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||$obj$$.tk_cn_ctv||$kho$$.tk_cn_ctv||$options$$.tk_cn_ctv||$obj$$.tk_co_hoa_hong||$kho$$.tk_co_hoa_hong||
|
|
16
|
+
$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=$obj$$.ma_ctv;$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&&$obj$$.ma_kh_hoa_hong&&($obj$$.details.filter($r$$=>
|
|
17
|
+
$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;$tt$$.tien=$tt$$.tien_nt=
|
|
18
|
+
$r$$.tien_hoa_hong;$tt$$.tien=$tt$$.tien_nt*($obj$$.ty_gia||1);$tt$$.ma_kh=$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||$kho$$.tk_no_hoa_hong_gt||$options$$.tk_no_hoa_hong_gt||
|
|
19
|
+
$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$$={};$tt$$.tk_no=$r$$.tk_no_hoa_hong_gt;$tt$$.tk_co=$r$$.tk_co_hoa_hong_gt;
|
|
20
|
+
$tt$$.tien_nt=$r$$.tien_hoa_hong_gt;$tt$$.tien=$tt$$.tien_nt*($obj$$.ty_gia||1);$tt$$.ma_kh=$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$$)}));$o_tt$$={...$obj$$};$o_tt$$.tk_no=$obj$$.tk_no;$o_tt$$.tk_co=$obj$$.tk_thue_co;$o_tt$$.tien_nt=$obj$$.tien_thue_dc_nt||$obj$$.details.csum("tien_thue_nt");$o_tt$$.tien=$o_tt$$.tien_nt*$o_tt$$.ty_gia;
|
|
21
|
+
$o_tt$$.dien_giai_thue&&($o_tt$$.dien_giai=$o_tt$$.dien_giai_thue);$details$$.push($o_tt$$);const $details_giavon$$=[];[...$product_details$$].forEach(function($d$jscomp$9_detail$$){$d$jscomp$9_detail$$={...$d$jscomp$9_detail$$};$d$jscomp$9_detail$$.tk_no=$d$jscomp$9_detail$$.tk_gv;$d$jscomp$9_detail$$.ma_kh||($d$jscomp$9_detail$$.ma_kh=$obj$$.ma_kh);$d$jscomp$9_detail$$.tk_co=$d$jscomp$9_detail$$.tk_vt;$d$jscomp$9_detail$$.tien_nt=$d$jscomp$9_detail$$.tien_xuat_nt;$d$jscomp$9_detail$$.tien=$d$jscomp$9_detail$$.tien_xuat;
|
|
22
|
+
$details_giavon$$.push($d$jscomp$9_detail$$);$d$jscomp$9_detail$$.promotion&&$d$jscomp$9_detail$$.promotion.details_km&&$d$jscomp$9_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&&
|
|
23
|
+
($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$$))});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)});
|
|
24
|
+
$callback$$()})}},()=>{$details$$=$details$$.concat($details_giavon$$);(new PostSocai($obj$$,$details$$)).run(function($e$$,$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=
|
|
25
|
+
$obj$$.so_ct),$detail$$.ngay_hd||($detail$$.ngay_hd=$obj$$.ngay_ct),$detail$$.tien_nt=$obj$$.details.csum("tien_nt")-$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$$)})})},thanhtoanhoahongnv:$callback$$=>
|
|
26
|
+
{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(),username:$obj$$.user_nv,wallet_type:1});if(!$wallet_nhan_vien$$){$wallet_nhan_vien$$=(new global.getModel("asskey"))({user_created:$obj$$.user_nv,username:$obj$$.user_nv,id_app:$obj$$.id_app,
|
|
27
|
+
wallet_type:1});const $wallet$$=await DirectSecp256k1HdWallet.generate(24,{prefix:configs.ADDRESS_PREFIX});let $accounts$$=await $wallet$$.getAccounts();$wallet_nhan_vien$$.address=$accounts$$[0].address;$wallet_nhan_vien$$.mnemonic=$wallet$$.mnemonic;$wallet_nhan_vien$$.name="T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng";await $wallet_nhan_vien$$.save()}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()}`;
|
|
28
|
+
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$$){console.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&&
|
|
29
|
+
$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:1});if(!$wallet_gt$$){$wallet_gt$$=(new global.getModel("asskey"))({user_created:$obj$$.user_gt,username:$obj$$.user_gt,id_app:$obj$$.id_app,wallet_type:1});const $wallet$$=await DirectSecp256k1HdWallet.generate(24,{prefix:configs.ADDRESS_PREFIX});let $accounts$$=await $wallet$$.getAccounts();$wallet_gt$$.address=
|
|
30
|
+
$accounts$$[0].address;$wallet_gt$$.mnemonic=$wallet$$.mnemonic;$wallet_gt$$.name="T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng";await $wallet_gt$$.save()}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$$,$obj$$.be_introduced,$wallet_gt$$.address,$amount$$,$denom$$,$memo$$,$obj$$.introduce_code,"2");$obj$$.da_chuyen_hoa_hong_gt=
|
|
31
|
+
!0;await model.updateOne({_id:$obj$$._id},{da_chuyen_hoa_hong_gt:!0})}}catch($e$$){console.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&&$appInfo$$.wallet_token&&$appInfo$$.tang_gioi_thieu_denom){let $wallet_gt$$=await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),
|
|
32
|
+
username:$obj$$.user_ctv,wallet_type:1});if(!$wallet_gt$$){$wallet_gt$$=(new global.getModel("asskey"))({user_created:$obj$$.user_ctv,username:$obj$$.user_ctv,id_app:$obj$$.id_app,wallet_type:1});const $wallet$$=await DirectSecp256k1HdWallet.generate(24,{prefix:configs.ADDRESS_PREFIX});let $accounts$$=await $wallet$$.getAccounts();$wallet_gt$$.address=$accounts$$[0].address;$wallet_gt$$.mnemonic=$wallet$$.mnemonic;$wallet_gt$$.name="T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng";await $wallet_gt$$.save()}let $amount$$=
|
|
33
|
+
$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()}`;await spend($appInfo$$,$obj$$.be_introduced,$wallet_gt$$.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$$){console.error("Kh\u00f4ng th\u1ec3 thanh to\u00e1n ti\u1ec1n hoa h\u1ed3ng",
|
|
34
|
+
$e$$)}$callback$$()})}},function($e$$,$rs$$){$fn$$($e$$,$rs$$)})};const $valid$$=function($i_t_thue_nt_user$$,$obj$$,$next$$){$obj$$.thue_suat=$obj$$.thue_suat||0;let $f_tien_nt$$="VND"==$obj$$.ma_nt?0:2;$obj$$.details.forEach($detail$$=>{$detail$$.tien_thue_nt=utils.round(($detail$$.tien_nt-$detail$$.tien_ck_nt)*(($detail$$.ma_thue?$detail$$.thue_suat:$obj$$.thue_suat)||0)/100,$f_tien_nt$$)});for($i_t_thue_nt_user$$=0;$i_t_thue_nt_user$$<$obj$$.details.length;$i_t_thue_nt_user$$++){var $detail$jscomp$0$$=
|
|
35
|
+
$obj$$.details[$i_t_thue_nt_user$$];$detail$jscomp$0$$.line=$i_t_thue_nt_user$$;$detail$jscomp$0$$.tien_ck_nt=$detail$jscomp$0$$.tien_ck_nt||0;$detail$jscomp$0$$.tien_thue_nt=$detail$jscomp$0$$.tien_thue_nt||0;$detail$jscomp$0$$.tien=utils.round($detail$jscomp$0$$.tien_nt*$obj$$.ty_gia,0);$detail$jscomp$0$$.gia_ban=utils.round($detail$jscomp$0$$.gia_ban_nt*$obj$$.ty_gia,0);$detail$jscomp$0$$.tien_ck=utils.round($detail$jscomp$0$$.tien_ck_nt*$obj$$.ty_gia,0);$detail$jscomp$0$$.tien_thue=utils.round($detail$jscomp$0$$.tien_thue_nt*
|
|
36
|
+
$obj$$.ty_gia,0);$detail$jscomp$0$$.tien_xuat=$detail$jscomp$0$$.tien_xuat_nt}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_t_thue_nt_user$$=$obj$$.details.csum("tien_thue_nt"),$detail$jscomp$0$$=$obj$$.details.csum("tien_thue"),($i_t_thue_nt_user$$!==
|
|
37
|
+
$obj$$.t_thue_nt||$detail$jscomp$0$$!==$obj$$.t_thue)&&0<$obj$$.details.length)){let $row_dieu_chinh$$=$obj$$.details[$obj$$.details.length-1];$row_dieu_chinh$$.tien_thue_nt+=$obj$$.t_thue_nt-$i_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||
|
|
38
|
+
($obj$$.details=[]);$valid$$($user$$,$obj$$,async function($error$$){if($error$$)return $next$$($error$$);await $obj$$.details.asyncJoinModel2($obj$$.id_app,dmvt,{where:"ma_vt",fields:["gia_mua","combo"]});$obj$$.details.filter($d$$=>$d$$.combo).forEach($detail$$=>{$detail$$.combo=$detail$$.combo.map($item$$=>{$item$$.sl_xuat*=$detail$$.sl_xuat;$item$$.tien_xuat=$item$$.tien_xuat_nt=$item$$.sl_xuat*($item$$.gia_von_nt||0);$item$$.tien=$item$$.tien_nt=$item$$.sl_xuat*($item$$.gia_ban_nt||0);$item$$.tien_ck=
|
|
39
|
+
$item$$.tien_ck_nt=$item$$.sl_xuat*($item$$.tien_ck_nt||0);$item$$.tt=$item$$.tt_nt=$item$$.tien_nt-($item$$.tien_ck_nt||0);return $item$$})});$obj$$.result_export_einvoice=null;$next$$(null,$obj$$)})};$contr$$.updating=async function($user$$,$data$$,$obj$$,$next$$){$data$$.details||($data$$.details=$obj$$.details);await $data$$.details.asyncJoinModel2($user$$.current_id_app,dmvt,{where:"ma_vt",setFields:($item$$,$ref$$)=>{$item$$.combo=$ref$$.combo;$obj$$.details.find($d$$=>$d$$.ma_vt===$item$$.ma_vt)?
|
|
40
|
+
$item$$.gia_mua||($item$$.gia_mua=$ref$$.gia_mua):$item$$.gia_mua=$ref$$.gia_mua}});$data$$.details.filter($d$$=>$d$$.combo).forEach($detail$$=>{$detail$$.combo=$detail$$.combo.map($item$$=>{$item$$.sl_xuat*=$detail$$.sl_xuat;$item$$.tien_xuat=$item$$.tien_xuat_nt=$item$$.sl_xuat*($item$$.gia_von_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*($item$$.tien_ck_nt||0);$item$$.tt=$item$$.tt_nt=$item$$.tien_nt-($item$$.tien_ck_nt||
|
|
41
|
+
0);return $item$$})});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")}`):$valid$$($user$$,$data$$,function($error$$){if($error$$)return $next$$($error$$);$next$$(null,
|
|
42
|
+
$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")}`):$next$$(null,$obj$$)})};$contr$$.on("saved",function($obj$$){$obj$$.id_dh2&&global.getModel("dh2").updateMany({_id:$obj$$.id_dh2},
|
|
43
|
+
{id_hd2:$obj$$._id.toString(),trang_thai:"7"},()=>{global.getModel("dh2").findOne({_id:$obj$$.id_dh2},($e$jscomp$0$$,$_obj$$)=>{$_obj$$&&controller.postData($_obj$$,global.controllers.DH2,$e$$=>{$e$$&&console.error($e$$)})})})});$contr$$.on("deleted",function($obj$$){$obj$$.id_dh2&&global.getModel("dh2").updateMany({_id:$obj$$.id_dh2,id_pxh:{$in:[null,"",void 0]}},{id_hd2:"",trang_thai:"3"},()=>{global.getModel("dh2").updateMany({_id:$obj$$.id_dh2,id_pxh:{$nin:[null,"",void 0]}},{id_hd2:"",trang_thai:"6"},
|
|
44
|
+
()=>{global.getModel("dh2").findOne({_id:$obj$$.id_dh2},($e$jscomp$0$$,$_obj$$)=>{$_obj$$&&controller.postData($_obj$$,global.controllers.DH2,$e$$=>{$e$$&&console.error($e$$)})})})})});$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$$=>
|
|
45
|
+
$item$$.tk_no).joinModel($id_app$$,account,[{akey:"tk_no",bkey:"tk",fields:[{name:"ten_tk_no",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$$()})},kh:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kh).joinModel2($id_app$$,customer,[{where:"ma_kh",fields:["ten_kh","email","nh_kh"]}],function(){$callback$$()})},
|
|
46
|
+
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$$=>$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$$=>
|
|
67
47
|
$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&&($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,
|
|
68
48
|
$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,$r$$.t_tien_xuat=$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_ctv=$r$$.details.csum("tien_hoa_hong_ctv"),$r$$.tien_hoa_hong_ql=$r$$.details.csum("tien_hoa_hong_ql"))});
|
|
69
49
|
$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",value:"ten_tk"}]},{akey:"tk_gv",bkey:"tk",fields:[{name:"ten_tk_gv",value:"ten_tk"}]}],function(){$callback$$()})},
|
|
70
|
-
kho:function($callback$$){$details$$.filter($item$$=>$item$$.ma_kho).
|
|
71
|
-
|
|
72
|
-
function(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
$
|
|
77
|
-
$
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
$
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
$
|
|
50
|
+
kho:function($callback$$){$details$$.filter($item$$=>$item$$.ma_kho).joinModel2($id_app$$,dmkho,[{where:"ma_kho",fields:["ten_kho"]}],function(){$callback$$()})}},function(){$callback1$$()})},function(){$callback$jscomp$0$$()})},details_vt:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){$r$$.details.joinModel2($id_app$$,dmvt,[{where:"ma_vt",fields:["ten_vt","tk_tl"]}],function(){$callback1$$()})},function(){$callback$$()})},details_dt:function($callback$$){async.mapSeries($items$$,
|
|
51
|
+
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.mapSeries($items$$,function($r$$,$callback1$$){$r$$.details.filter($item$$=>$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$$,
|
|
52
|
+
function($r$$,$callback1$$){$r$$.details.filter($item$$=>$item$$.ma_phi).joinModel2($id_app$$,dmphi,[{where:"ma_phi",fields:["ten_phi"]}],function(){$callback1$$()})},function(){$callback$$()})}},function(){$fn$$(null,$items$$)})};$contr$$.createRoute("export2viettel/:id_ct",async($data$jscomp$0$$,$next$$)=>{var $id_app$$=$data$jscomp$0$$.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||
|
|
53
|
+
!$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");const $ct$$=await model.findOne({id_app:$id_app$$,_id:$data$jscomp$0$$.params.id_ct}).lean();if(!$ct$$)return $next$$("Ch\u1ee9ng t\u1eeb kh\u00f4ng h\u1ee3p l\u1ec7");if($ct$$.result_export_einvoice&&
|
|
54
|
+
$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$0$$=await customer.findOne({id_app:$id_app$$,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$$=
|
|
55
|
+
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$$,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===
|
|
56
|
+
$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),taxAmount:Math.abs($detail$$.tien_thue_nt)}));$taxBreakdowns$$=await $taxBreakdowns$$.asyncGroupBy("taxPercentage",["taxableAmount","taxAmount"]);$data$jscomp$0$$={generalInvoiceInfo:{invoiceType:$ct$$.ma_hoa_don||
|
|
57
|
+
$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||$data$jscomp$0$$.ten_kh||"",buyerTaxCode:$ct$$.ma_so_thue||$data$jscomp$0$$.ma_so_thue||"",buyerAddressLine:$ct$$.dia_chi||$data$jscomp$0$$.dia_chi||"",buyerPostalCode:"",buyerDistrictName:"",buyerCityName:"",
|
|
58
|
+
buyerCountryCode:"",buyerPhoneNumber:$ct$$.dien_thoai||$data$jscomp$0$$.dien_thoai||"",buyerFaxNumber:"",buyerEmail:$data$jscomp$0$$.email||"",buyerBankName:"",buyerBankAccount:"",buyerIdType:"",buyerIdNo:"",buyerCode:"",buyerBirthDay:""},sellerInfo:{sellerLegalName:$app_msg_e$$.name,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||
|
|
59
|
+
""},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,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,
|
|
60
|
+
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),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$$,
|
|
61
|
+
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||($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$0$$.generalInvoiceInfo.invoiceIssuedDate=(new Date($ct$$.ngay_hd)).getTime();
|
|
62
|
+
$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()}`;var $headers_url_token$$=`${$app_msg_e$$.viettel_url_service.trim()}/auth/login`;try{$viettel_token$$=(await axios({method:"post",url:$headers_url_token$$,
|
|
63
|
+
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$$}`,"Content-Type":"application/json"};$auth_t_ck$$=
|
|
64
|
+
void 0}else $data$jscomp$0$$.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?JSON.stringify($data$jscomp$0$$):
|
|
65
|
+
$data$jscomp$0$$,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});await Tdttno_tt.updateMany({id_hd:$ct$$._id.toString()},
|
|
66
|
+
{so_hd:$ct$$.so_hd});await Vatra.updateMany({id_ct:$ct$$._id.toString()},{so_hd:$ct$$.so_hd});controller.postData($ct$$,$contr$$,$e$$=>{if($e$$)return console.error($e$$);controller.pushNotification($contr$$,$ct$$)});$next$$(null,$data$$)}).catch($e$$=>{console.error("error invocie viettel",$e$$.response);let $msg_e$$=$e$$.response?$e$$.response.data:$e$$.message;$msg_e$$.data&&($msg_e$$.message=$msg_e$$.data);$msg_e$$.detail&&($msg_e$$.message=$msg_e$$.detail);$next$$($msg_e$$||$e$$.message||$e$$.error||
|
|
67
|
+
$e$$)})},{method:"GET"})};
|
|
@@ -1,24 +1,30 @@
|
|
|
1
1
|
'use strict';const PostBook=require("../../libs/post-book"),PostSocai=require("../../libs/post-socai"),utils=require("../../libs/utils"),Sokho=global.getModel("sokho"),Sokhott=global.getModel("sokhott"),Vatra=global.getModel("vatra"),dmvt=global.getModel("dmvt"),dmkho=global.getModel("dmkho"),account=global.getModel("account"),customer=global.getModel("customer"),dmdt=global.getModel("dmdt"),dmphi=global.getModel("dmphi"),contract=global.getModel("contract"),model=global.getModel("hd3"),controller=
|
|
2
2
|
require("../../controllers/controller"),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$jscomp$0$$,$fn$$){$fn$$||($fn$$=function(){});let $
|
|
4
|
-
$detail$$.
|
|
5
|
-
|
|
6
|
-
$
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
$
|
|
10
|
-
$
|
|
11
|
-
$d$jscomp$
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
$
|
|
16
|
-
0);$
|
|
17
|
-
$
|
|
18
|
-
$
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
$
|
|
23
|
-
|
|
24
|
-
function(){$
|
|
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$jscomp$0$$,$fn$$){$fn$$||($fn$$=function(){});let $product_details$$=[...$obj$jscomp$0$$.details].map($detail$$=>$detail$$.combo&&0<$detail$$.combo.length?$detail$$.combo.map($item_combo$$=>$item_combo$$=$item_combo$$.toObject?$item_combo$$.toObject():{...$item_combo$$}):
|
|
4
|
+
[$detail$$]).reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]),$details_thue$$=$obj$jscomp$0$$.details.map($detail$$=>({...$detail$$,thue_suat:($detail$$.ma_thue?$detail$$.thue_suat:$obj$jscomp$0$$.thue_suat)||0,ma_thue:$detail$$.ma_thue||$obj$jscomp$0$$.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$jscomp$0$$.id_app,"vat",{where:"ma_thue",fields:["tk_thue_co"]});
|
|
5
|
+
async.series({post_sokho:function($callback$jscomp$0$$){(new PostBook($obj$jscomp$0$$,$product_details$$,Sokho,async function($detail$$,$callback$$){$detail$$.nxt=1;$detail$$.tk_co=$obj$jscomp$0$$.tk_co;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$jscomp$0$$($e$$,$rs$$)})},post_sokhott:function($callback$jscomp$0$$){(new PostBook($obj$jscomp$0$$,$product_details$$,Sokhott,async function($detail$$,$callback$$){$detail$$.nxt=1;$detail$$.tk_co=$obj$jscomp$0$$.tk_co;$callback$$($detail$$)})).run(function($e$$,
|
|
6
|
+
$rs$$){$callback$jscomp$0$$($e$$,$rs$$)})},post_vatra:function($callback$jscomp$0$$){(async()=>{$obj$jscomp$0$$.ngay_hd?0==$details_thue$$.length&&$obj$jscomp$0$$.so_hd&&$obj$jscomp$0$$.ngay_hd&&$obj$jscomp$0$$.ma_thue&&$obj$jscomp$0$$.t_thue_nt?(new PostBook($obj$jscomp$0$$,[{...$obj$jscomp$0$$}],Vatra,function($obj$$,$callback$$){$obj$$.tk_du_thue=$obj$$.tk_co;$obj$$.t_tien_nt=-($obj$$.details.csum("tien_nt")-$obj$$.details.csum("tien_ck_nt"));$obj$$.t_tien=-($obj$$.details.csum("tien")-$obj$$.details.csum("tien_ck"));
|
|
7
|
+
$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$jscomp$0$$($e$$,$rs$$)}):$details_thue$$.asyncGroupBy(["ma_thue","thue_suat","ten_vt_vat","tk_thue_co"],"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$$,
|
|
8
|
+
$b$$)=>$a$$+$b$$,0);0==$tien_thue_nt$$&&0==$tien_thue$$&&($tien_thue_nt$$=$obj$jscomp$0$$.t_thue_nt||0,$tien_thue$$=$obj$jscomp$0$$.t_thue||0);$ds$$[0].tien_thue_nt=$tien_thue_nt$$;$ds$$[0].tien_thue=$tien_thue$$}(new PostBook($obj$jscomp$0$$,$ds$$,Vatra,function($detail$$,$callback$$){try{$detail$$.tk_du_thue=$obj$jscomp$0$$.tk_co,$detail$$.t_tien_nt=-($detail$$.tien_nt-$detail$$.tien_ck_nt),$detail$$.t_tien=-($detail$$.tien-$detail$$.tien_ck),$detail$$.t_thue_nt=0-$detail$$.tien_thue_nt,$detail$$.t_thue=
|
|
9
|
+
0-$detail$$.tien_thue,$detail$$.ten_vt=$detail$$.ten_vt_vat||$obj$jscomp$0$$.ten_vt||$obj$jscomp$0$$.dien_giai}catch($e$$){console.error($e$$,$obj$jscomp$0$$)}$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$jscomp$0$$($e$$,$rs$$)})}):$callback$jscomp$0$$()})()},post_socai:function($callback$$){(async()=>{const $details_sc$$=[];if(0===$details_thue$$.length&&$obj$jscomp$0$$.t_thue_nt&&$obj$jscomp$0$$.tk_thue_co){const $o$$={...$obj$jscomp$0$$};$o$$.tk_co=$obj$jscomp$0$$.tk_co;$o$$.tk_no=
|
|
10
|
+
$obj$jscomp$0$$.tk_thue_co;$o$$.tien_nt=Math.abs($obj$jscomp$0$$.t_thue_nt);$o$$.tien=Math.abs($obj$jscomp$0$$.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$jscomp$0$$.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$$);console.log($v_vatra$$)});$obj$jscomp$0$$.details.forEach(function($d$jscomp$5_detail$$){$d$jscomp$5_detail$$=
|
|
11
|
+
{...$d$jscomp$5_detail$$};$d$jscomp$5_detail$$.tk_no=$d$jscomp$5_detail$$.tk_tl||"52131";$d$jscomp$5_detail$$.ma_kh||($d$jscomp$5_detail$$.ma_kh=$obj$jscomp$0$$.ma_kh);$d$jscomp$5_detail$$.tk_co=$obj$jscomp$0$$.tk_co||"1111";$d$jscomp$5_detail$$.tien_nt-=$d$jscomp$5_detail$$.tien_ck_nt;$d$jscomp$5_detail$$.tien-=$d$jscomp$5_detail$$.tien_ck;$details_sc$$.push($d$jscomp$5_detail$$)});[...$product_details$$].forEach(function($d$jscomp$6_detail$$){$d$jscomp$6_detail$$={...$d$jscomp$6_detail$$};$d$jscomp$6_detail$$.tk_no=
|
|
12
|
+
$d$jscomp$6_detail$$.tk_vt||"1561";$d$jscomp$6_detail$$.ma_kh||($d$jscomp$6_detail$$.ma_kh=$obj$jscomp$0$$.ma_kh);$d$jscomp$6_detail$$.tk_co=$d$jscomp$6_detail$$.tk_gv||"6321";$d$jscomp$6_detail$$.tien_nt=$d$jscomp$6_detail$$.tien_nhap_nt;$d$jscomp$6_detail$$.tien=$d$jscomp$6_detail$$.tien_nhap;$details_sc$$.push($d$jscomp$6_detail$$)});(await $obj$jscomp$0$$.details.filter($r$$=>$r$$.tien_hoa_hong_ctv).asyncGroupBy(["ma_ctv","tk_cp_ctv","tk_cn_ctv"],["tien_hoa_hong_ctv"])).forEach($r$$=>{let $tt$$=
|
|
13
|
+
{};$tt$$.tk_co=$r$$.tk_cp_ctv;$tt$$.tk_no=$r$$.tk_cn_ctv;$tt$$.tien=$tt$$.tien_nt=$r$$.tien_hoa_hong_ctv;$tt$$.ma_kh=$tt$$.ma_ctv;$tt$$.tk_no&&$tt$$.tk_co&&$tt$$.tien&&$details_sc$$.push($tt$$)});(await $obj$jscomp$0$$.details.filter($r$$=>$r$$.tien_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=$r$$.tk_co_hoa_hong;$tt$$.tien=$tt$$.tien_nt=$r$$.tien_hoa_hong;$tt$$.tien=$tt$$.tien_nt*
|
|
14
|
+
($obj$jscomp$0$$.ty_gia||1);$tt$$.ma_kh=$tt$$.ma_kh_hoa_hong;$tt$$.check_balance=!1;$tt$$.tk_no&&$tt$$.tk_co&&$tt$$.tien&&$details_sc$$.push($tt$$)});(await $obj$jscomp$0$$.details.filter($r$$=>$r$$.tien_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;$tt$$.tien_nt=$r$$.tien_hoa_hong_gt;$tt$$.tien=$tt$$.tien_nt*($obj$jscomp$0$$.ty_gia||1);
|
|
15
|
+
$tt$$.ma_kh=$tt$$.ma_kh_hoa_hong_gt;$tt$$.check_balance=!1;$tt$$.tk_no&&$tt$$.tk_co&&$tt$$.tien&&$details_sc$$.push($tt$$)});(new PostSocai($obj$jscomp$0$$,$details_sc$$)).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})})()}},function($e$$,$rs$$){$fn$$($e$$,$rs$$)})};const $valid$$=function($f_tien_nt_i_user$$,$obj$$,$next$$){for($f_tien_nt_i_user$$=0;$f_tien_nt_i_user$$<$obj$$.details.length;$f_tien_nt_i_user$$++){const $detail$$=$obj$$.details[$f_tien_nt_i_user$$];$detail$$.line=$f_tien_nt_i_user$$;
|
|
16
|
+
$detail$$.tien=utils.round($detail$$.tien_nt*$obj$$.ty_gia,0);$detail$$.tien_ck=utils.round($detail$$.tien_ck_nt*$obj$$.ty_gia,0);$detail$$.tien_thue=utils.round($detail$$.tien_thue_nt*$obj$$.ty_gia,0);$detail$$.tien_nhap=$detail$$.tien_nhap_nt}$obj$$.details.find($d$$=>$d$$.tien_thue_nt)?($obj$$.t_thue_nt=$obj$$.details.csum("tien_thue_nt"),$obj$$.t_thue=utils.round($obj$$.t_thue_nt*($obj$$.ty_gia||1),0)):$obj$$.thue_suat&&!$obj$$.t_thue_nt&&($f_tien_nt_i_user$$="VND"===$obj$$.ma_nt?0:2,$obj$$.t_thue_nt=
|
|
17
|
+
utils.round(($obj$$.details.csum("tien_nt")-$obj$$.details.csum("tien_ck_nt"))*$obj$$.thue_suat/100,$f_tien_nt_i_user$$),$obj$$.t_thue=utils.round($obj$$.t_thue_nt*($obj$$.ty_gia||1),0));$next$$(null,$obj$$)};$contr_router$$.creating=function($user$$,$obj$$,$next$$){$obj$$.details||($obj$$.details=[]);$valid$$($user$$,$obj$$,async function($error$$){if($error$$)return $next$$($error$$);await $obj$$.details.asyncJoinModel2($obj$$.id_app,dmvt,{where:"ma_vt",fields:["combo"]});$obj$$.details.filter($d$$=>
|
|
18
|
+
$d$$.combo).forEach($detail$$=>{$detail$$.combo=$detail$$.combo.map($item_combo$$=>{$item_combo$$=$item_combo$$.toObject?$item_combo$$.toObject():{...$item_combo$$};$item_combo$$.sl_nhap=$item_combo$$.sl_xuat;delete $item_combo$$.sl_xuat;delete $item_combo$$.tien_xuat;delete $item_combo$$.tien_xuat_nt;delete $item_combo$$.px_gia_dd;$item_combo$$.sl_nhap*=$detail$$.sl_nhap;$item_combo$$.tien_nhap=$item_combo$$.tien_nhap_nt=$item_combo$$.sl_nhap*($item_combo$$.gia_von_nt||0);$item_combo$$.tien=$item_combo$$.tien_nt=
|
|
19
|
+
$item_combo$$.sl_nhap*($item_combo$$.gia_ban_nt||0);$item_combo$$.tien_ck=$item_combo$$.tien_ck_nt=$item_combo$$.sl_nhap*($item_combo$$.tien_ck_nt||0);return $item_combo$$})});$next$$(null,$obj$$)})};$contr_router$$.updating=function($user$$,$data$$,$obj$$,$next$$){$data$$.details=$data$$.details||$obj$$.details;$valid$$($user$$,$data$$,async function($error$$){if($error$$)return $next$$($error$$);await $data$$.details.asyncJoinModel2($obj$$.id_app,dmvt,{where:"ma_vt",fields:["combo"]});$data$$.details.filter($d$$=>
|
|
20
|
+
$d$$.combo).forEach($detail$$=>{$detail$$.combo=$detail$$.combo.map($item_combo$$=>{$item_combo$$=$item_combo$$.toObject?$item_combo$$.toObject():{...$item_combo$$};$item_combo$$.sl_nhap=$item_combo$$.sl_xuat;delete $item_combo$$.sl_xuat;delete $item_combo$$.tien_xuat;delete $item_combo$$.tien_xuat_nt;delete $item_combo$$.px_gia_dd;$item_combo$$.sl_nhap*=$detail$$.sl_nhap;$item_combo$$.tien_nhap=$item_combo$$.tien_nhap_nt=$item_combo$$.sl_nhap*($item_combo$$.gia_von_nt||0);$item_combo$$.tien=$item_combo$$.tien_nt=
|
|
21
|
+
$item_combo$$.sl_nhap*($item_combo$$.gia_ban_nt||0);$item_combo$$.tien_ck=$item_combo$$.tien_ck_nt=$item_combo$$.sl_nhap*($item_combo$$.tien_ck_nt||0);return $item_combo$$})});$next$$(null,$data$$,$obj$$)})};$contr_router$$.view=function($user$$,$items$$,$fn$$){const $id_app$$=$user$$.current_id_app;async.series({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$$()})},
|
|
22
|
+
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$$()})},t_tien:function($callback$$){$items$$.forEach(function($r$$){$r$$.details_doi?($r$$.t_sl_doi=$r$$.details_doi.csum("sl_xuat"),$r$$.t_tien_doi=$r$$.details.csum("tien"),$r$$.t_tien_doi_nt=$r$$.details.csum("tien_nt"),$r$$.t_tien_nhap_doi=$r$$.details.csum("tien_nhap"),$r$$.t_tien_nhap_doi_nt=$r$$.details.csum("tien_nhap_nt")):
|
|
23
|
+
($r$$.t_tien_doi=0,$r$$.t_tien_doi_nt=0);$r$$.vatvaos?($r$$.t_thue_vao=$r$$.vatvaos.csum("t_thue"),$r$$.t_thue_vao_nt=$r$$.vatvaos.csum("t_thue_nt")):($r$$.t_thue_vao=0,$r$$.t_thue_vao_nt=0);$r$$.t_thue_ra=Math.abs($r$$.t_thue_nt||0);$r$$.t_thue_ra_nt=Math.abs($r$$.t_thue||0);$r$$.details||($r$$.details=[]);$r$$.t_sl=$r$$.details.csum("sl_nhap");$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");
|
|
24
|
+
$r$$.t_tt=$r$$.t_tien+($r$$.t_thue_ra||0)-$r$$.t_ck;$r$$.t_tt_nt=$r$$.t_tien_nt+($r$$.t_thue_ra_nt||0)-$r$$.t_ck_nt;$r$$.t_tien_nhap=$r$$.details.csum("tien_nhap");$r$$.t_tien_nhap_nt=$r$$.details.csum("tien_nhap_nt");$r$$.t_chenh_lech_nt=$r$$.t_tt_nt+$r$$.t_thue_vao_nt-$r$$.t_tien_doi_nt-$r$$.t_thue_ra_nt});$callback$$()},details_hd2:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){$r$$.details.filter($d$$=>$d$$.id_hd&&!$d$$.so_ct_hd).joinModel2($id_app$$,"hd2",[{where:{id_hd:"_id"},
|
|
25
|
+
fields:[{name:"so_ct_hd",value:"so_ct"},{name:"ngay_ct_hd",value:"ngay_ct"},{name:"ma_ct_hd",value:"ma_ct"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_pbl:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){$r$$.details.filter($d$$=>$d$$.id_hd&&!$d$$.so_ct_hd).joinModel2($id_app$$,"pbl",[{where:{id_hd:"_id"},fields:[{name:"so_ct_hd",value:"so_ct"},{name:"ngay_ct_hd",value:"ngay_ct"},{name:"ma_ct_hd",value:"ma_ct"}]}],function(){$callback1$$()})},function(){$callback$$()})},
|
|
26
|
+
details_so1:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){$r$$.details.filter($d$$=>$d$$.id_hd&&!$d$$.so_ct_hd).joinModel2($id_app$$,"so1",[{where:{id_hd:"_id"},fields:[{name:"so_ct_hd",value:"so_ct"},{name:"ngay_ct_hd",value:"ngay_ct"},{name:"ma_ct_hd",value:"ma_ct"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_tk:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){$r$$.details.joinModel($id_app$$,account,[{akey:"tk_vt",bkey:"tk",
|
|
27
|
+
fields:[{name:"ten_tk_vt",value:"ten_tk"}]},{akey:"tk_gv",bkey:"tk",fields:[{name:"ten_tk_gv",value:"ten_tk"}]},{akey:"tk_tl",bkey:"tk",fields:[{name:"ten_tk_tl",value:"ten_tk"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_vt:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){$r$$.details.joinModel($id_app$$,dmvt,[{akey:"ma_vt",bkey:"ma_vt",fields:[{name:"ten_vt",value:"ten_vt"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_doi_vt:function($callback$$){async.mapSeries($items$$,
|
|
28
|
+
function($details$jscomp$6_r$$,$callback1$$){($details$jscomp$6_r$$=$details$jscomp$6_r$$.details_doi)?$details$jscomp$6_r$$.joinModel($id_app$$,dmvt,[{akey:"ma_vt",bkey:"ma_vt",fields:[{name:"ten_vt",value:"ten_vt"}]}],function(){$callback1$$()}):$callback1$$()},function(){$callback$$()})},details_kho:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){$r$$.details.filter($item$$=>$item$$.ma_kho).joinModel($id_app$$,dmkho,[{akey:"ma_kho",bkey:"ma_kho",fields:[{name:"ten_kho",
|
|
29
|
+
value:"ten_kho"}]}],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$$=>$item$$.ma_hd).joinModel($id_app$$,
|
|
30
|
+
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$$)})}};
|