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.
Files changed (108) hide show
  1. package/package.json +1 -1
  2. package/server/auths/local.js +27 -26
  3. package/server/controllers/controller.js +56 -55
  4. package/server/controllers/controllerRPT.js +18 -17
  5. package/server/libs/cdpstk.js +1 -1
  6. package/server/libs/databanle.js +13 -13
  7. package/server/libs/getGiaban.js +23 -22
  8. package/server/libs/post-book.js +9 -8
  9. package/server/libs/post-socai.js +9 -9
  10. package/server/libs/prototypes.js +4 -4
  11. package/server/libs/tinhGtPhanboSltp.js +5 -5
  12. package/server/libs/tinhGtPhanboYtcp.js +2 -2
  13. package/server/libs/tinhGtThcppstk.js +1 -1
  14. package/server/libs/tinhGtTrucTiep.js +8 -7
  15. package/server/libs/tinhgiatb.js +4 -4
  16. package/server/libs/tinhgiatb1vt.js +3 -3
  17. package/server/libs/tinhhoahong.js +32 -0
  18. package/server/libs/utils.js +4 -3
  19. package/server/models/app.js +9 -8
  20. package/server/models/approve.js +4 -4
  21. package/server/models/customer.js +8 -8
  22. package/server/models/dh2.js +10 -9
  23. package/server/models/dmgiaban.js +6 -6
  24. package/server/models/dmhoahonghd.js +6 -5
  25. package/server/models/fbconversation.js +9 -0
  26. package/server/models/fbmessage.js +2 -0
  27. package/server/models/fbpage.js +2 -0
  28. package/server/models/group.js +4 -2
  29. package/server/models/hd2.js +8 -8
  30. package/server/models/hd3.js +9 -9
  31. package/server/models/hd7.js +1 -1
  32. package/server/models/notification.js +3 -2
  33. package/server/models/participant.js +5 -5
  34. package/server/models/pbl.js +4 -4
  35. package/server/models/reportinfo.js +2 -2
  36. package/server/models/rptform.js +3 -2
  37. package/server/models/schedule.js +1 -1
  38. package/server/models/so1.js +7 -6
  39. package/server/models/socai.js +4 -4
  40. package/server/models/tdttco.js +8 -4
  41. package/server/models/tdttno.js +8 -4
  42. package/server/models/tokens.js +2 -2
  43. package/server/models/usergroup.js +5 -4
  44. package/server/models/vatra.js +2 -2
  45. package/server/models/vatvao.js +4 -4
  46. package/server/modules/lists/ls-assinvestment.js +1 -1
  47. package/server/modules/lists/ls-customer.js +13 -14
  48. package/server/modules/lists/ls-dmvt.js +48 -39
  49. package/server/modules/lists/ls-fbconversation.js +3 -0
  50. package/server/modules/lists/ls-fbmessage.js +3 -0
  51. package/server/modules/lists/ls-fbpage.js +10 -0
  52. package/server/modules/lists/ls-introducecode.js +1 -1
  53. package/server/modules/lists/ls-news.js +1 -1
  54. package/server/modules/lists/ls-opportunity.js +3 -3
  55. package/server/modules/lists/ls-session.js +1 -1
  56. package/server/modules/public/callin.js +6 -6
  57. package/server/modules/reports/rp-cdpstk.js +3 -3
  58. package/server/modules/reports/rp-chitiettaisan.js +9 -8
  59. package/server/modules/reports/rp-ckvt.js +9 -7
  60. package/server/modules/reports/rp-ctbanle.js +13 -12
  61. package/server/modules/reports/rp-databanle.js +8 -4
  62. package/server/modules/reports/rp-dtbanletheoct.js +16 -9
  63. package/server/modules/reports/rp-dtbanletheokh.js +12 -6
  64. package/server/modules/reports/rp-dtbanletheokho.js +14 -9
  65. package/server/modules/reports/rp-dtbanletheonam.js +15 -9
  66. package/server/modules/reports/rp-dtbanletheongay.js +13 -8
  67. package/server/modules/reports/rp-dtbanletheonv.js +15 -9
  68. package/server/modules/reports/rp-dtbanletheoquy.js +15 -9
  69. package/server/modules/reports/rp-dtbanletheothang.js +15 -9
  70. package/server/modules/reports/rp-getinvoice2pay.js +4 -6
  71. package/server/modules/reports/rp-getinvoice2receive.js +4 -6
  72. package/server/modules/reports/rp-hoahong.js +9 -0
  73. package/server/modules/reports/rp-kqhdkd.js +5 -4
  74. package/server/modules/reports/rp-ptcttct.js +7 -6
  75. package/server/modules/reports/rp-pttct.js +8 -8
  76. package/server/modules/reports/rp-pttctkho.js +3 -2
  77. package/server/modules/reports/rp-pttctkho2.js +3 -3
  78. package/server/modules/reports/rp-thnxt.js +8 -8
  79. package/server/modules/reports/rp-thnxt_sl.js +6 -6
  80. package/server/modules/reports/rp-thnxttt.js +6 -6
  81. package/server/modules/reports/rp-tmbctc.js +16 -16
  82. package/server/modules/systems/sys-app.js +25 -24
  83. package/server/modules/systems/sys-notification.js +2 -2
  84. package/server/modules/systems/sys-schedule.js +1 -1
  85. package/server/modules/systems/sys-user.js +8 -8
  86. package/server/modules/vouchers/vo-bc1.js +9 -8
  87. package/server/modules/vouchers/vo-bg2.js +9 -9
  88. package/server/modules/vouchers/vo-bn1.js +5 -4
  89. package/server/modules/vouchers/vo-dh2.js +15 -38
  90. package/server/modules/vouchers/vo-dnm.js +11 -12
  91. package/server/modules/vouchers/vo-hd2.js +63 -83
  92. package/server/modules/vouchers/vo-hd3.js +28 -22
  93. package/server/modules/vouchers/vo-hd7.js +37 -36
  94. package/server/modules/vouchers/vo-pbl.js +49 -49
  95. package/server/modules/vouchers/vo-pc1.js +9 -8
  96. package/server/modules/vouchers/vo-pn1.js +24 -22
  97. package/server/modules/vouchers/vo-pn5.js +1 -1
  98. package/server/modules/vouchers/vo-pn9.js +23 -23
  99. package/server/modules/vouchers/vo-pnc.js +8 -8
  100. package/server/modules/vouchers/vo-pnh.js +5 -5
  101. package/server/modules/vouchers/vo-pt1.js +17 -16
  102. package/server/modules/vouchers/vo-pxc.js +16 -16
  103. package/server/modules/vouchers/vo-pxh.js +12 -10
  104. package/server/modules/vouchers/vo-so1.js +94 -119
  105. package/server/modules/vouchers/vo-so4.js +1 -1
  106. package/server/modules/vouchers/vo-so5.js +2 -2
  107. package/server/workers/restoreApp.js +21 -12
  108. package/server/workers/runScript.js +3 -3
@@ -1,62 +1,37 @@
1
1
  'use strict';const PostBook=require("../../libs/post-book"),options=global.getModel("options"),PostSocai=require("../../libs/post-socai"),User=global.getModel("user"),Sokho=global.getModel("sokho"),Socaitmp=global.getModel("socai"),transaction=global.getModel("transaction"),Evoucher=global.getModel("evoucher"),dvcs=global.getModel("dvcs"),dmvt=global.getModel("dmvt"),dmtt=global.getModel("dmtt"),dmcpmh=global.getModel("dmcpmh"),dmkho=global.getModel("dmkho"),customer=global.getModel("customer"),dmdt=
2
- global.getModel("dmdt"),dmphi=global.getModel("dmphi"),contract=global.getModel("contract"),trangthai=global.getModel("trangthai"),currency=global.getModel("currency"),ptthanhtoan=global.getModel("ptthanhtoan"),dmdiemthuong=global.getModel("dmdiemthuong"),model=global.getModel("so1"),pt1=global.getModel("pt1"),controller=require("../../controllers/controller"),async=require("async"),ma_ct="SO1",ckdiem=require("../../libs/ckdiem"),blockchainconnect=require("../../libs/blockchainconnect"),moment=require("moment"),
3
- numeral=require("numeral"),App=global.getModel("app"),Introducer=global.getModel("introducer"),getGiaBan=require("../../libs/getGiabanAsync"),dmchietkhauhd=global.getModel("dmchietkhauhd"),dmkhuyenmaihd=global.getModel("dmkhuyenmaihd"),underscore=require("underscore"),_=require("lodash"),{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,
4
- $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",$e$$,$receiver_user$$,$receiver_address$$,$amount$$,$denom$$,$memo$$)}},hoahonghdgt=async $obj$$=>{if(!$obj$$.da_chuyen_hoa_hong_gt&&($obj$$.tien_hoa_hong_gt=0,$obj$$.ty_le_hoa_hong_gt=0,$obj$$.ma_kh_hoa_hong_gt="",$obj$$.details.forEach($detail$$=>{$detail$$.tien_hoa_hong_gt=
5
- 0;$detail$$.ty_le_hoa_hong_gt=0}),$obj$$.introduce_code&&($obj$$.user_gt="",$hieu_luc_tu_intro_intro$jscomp$1_intro$$=await global.getModel("introducer").findOne({id_app:$obj$$.id_app,introduce_code:$obj$$.introduce_code}))&&($obj$$.user_gt=$hieu_luc_tu_intro_intro$jscomp$1_intro$$.be_introduced_by),$obj$$.user_gt&&!$obj$$.introduce_code&&($hieu_luc_tu_intro_intro$jscomp$1_intro$$=await global.getModel("introducer").findOne({id_app:$obj$$.id_app,be_introduced_by:$obj$$.user_gt}))&&($obj$$.introduce_code=
6
- $hieu_luc_tu_intro_intro$jscomp$1_intro$$.introduce_code),!$obj$$.user_gt&&($obj$$.introduce_code="",$hieu_luc_tu_intro_intro$jscomp$1_intro$$=await global.getModel("introducer").findOne({id_app:$obj$$.id_app,be_introduced:$obj$$.user_created}))&&($obj$$.user_gt=$hieu_luc_tu_intro_intro$jscomp$1_intro$$.be_introduced_by,$obj$$.introduce_code=$hieu_luc_tu_intro_intro$jscomp$1_intro$$.introduce_code),$obj$$.user_gt&&$obj$$.introduce_code)){var $hieu_luc_tu_intro_intro$jscomp$1_intro$$=await global.getModel("customer").findOne({id_app:$obj$$.id_app,
7
- of_user:$obj$$.user_gt});$hieu_luc_tu_intro_intro$jscomp$1_intro$$&&($obj$$.ma_kh_hoa_hong_gt=$hieu_luc_tu_intro_intro$jscomp$1_intro$$.ma_kh);var $query$$={id_app:$obj$$.id_app,ma_kho:{$in:[void 0,null,"",$obj$$.ma_kho]},doi_tuong:"1"};var $hieu_luc_den_q_nh_kh_tu_ngay$$=moment($obj$$.ngay_ct).startOf("date").toDate();$hieu_luc_tu_intro_intro$jscomp$1_intro$$={$lte:moment($obj$$.ngay_ct).endOf("date").toDate()};$hieu_luc_den_q_nh_kh_tu_ngay$$={$gte:$hieu_luc_den_q_nh_kh_tu_ngay$$};$query$$.hieu_luc_tu=
8
- $hieu_luc_tu_intro_intro$jscomp$1_intro$$;$query$$.hieu_luc_den=$hieu_luc_den_q_nh_kh_tu_ngay$$;var $sort$$={do_uu_tien:1,gt_tu:-1,tien_hh:-1,ty_le_hh:-1,ma_nv:-1,user_group:-1,nh_kh:-1,hieu_luc_tu:-1,kieu:1};$hieu_luc_tu_intro_intro$jscomp$1_intro$$={$in:[void 0,null,"",$obj$$.ma_kh]};$hieu_luc_den_q_nh_kh_tu_ngay$$={$in:[void 0,null,""]};if($obj$$.ma_kh){var $g_kh$$=await customer.findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh},{nh_kh:1});$g_kh$$&&$g_kh$$.nh_kh&&($hieu_luc_den_q_nh_kh_tu_ngay$$=
9
- {$in:[void 0,null,"",$g_kh$$.nh_kh]})}if($obj$$.user_gt){if($g_kh$$=await global.getModel("participant").findOne({id_app:$obj$$.id_app,email:$obj$$.user_gt}).lean())$query$$.user_group={$in:[($g_kh$$.group_id||"").toString(),null,void 0,""]}}else $query$$.user_group={$in:[null,void 0,""]};$query$$.$or=[{$and:[{ma_kh:$hieu_luc_tu_intro_intro$jscomp$1_intro$$},{nh_kh:{$in:["",null,void 0]}}]},{$and:[{nh_kh:$hieu_luc_den_q_nh_kh_tu_ngay$$},{ma_kh:{$in:["",null,void 0]}}]}];await Promise.all($obj$$.details.map($detail$$=>
10
- {let $t_tt_nt$$=$detail$$.tien_hang_nt-$detail$$.tien_ck_nt,$loi_nhuan$$=$t_tt_nt$$-$detail$$.tien_xuat_tmp;const $_query$$=_.cloneDeep($query$$);$_query$$.gt_tu={$lte:$t_tt_nt$$};$_query$$.$and=[{$or:[{gt_den:{$in:[0,void 0,null]}},{gt_den:{$gte:$t_tt_nt$$}}]},{$or:[{"vts.0":{$exists:!1}},{vts:$detail$$.ma_vt}]}];return(async()=>{var $ckhd_ckhds$$=await global.getModel("dmhoahonghd").find($_query$$).sort($sort$$).limit(1).lean();0<$ckhd_ckhds$$.length&&($ckhd_ckhds$$=$ckhd_ckhds$$[0],$detail$$.gia_ban_niem_yet_nt&&
11
- $detail$$.gia_ban_niem_yet_nt>$detail$$.gia_ban_nt?$ckhd_ckhds$$.tien_hh2?($detail$$.tien_hoa_hong_gt=$ckhd_ckhds$$.tien_hh2,$detail$$.ty_le_hoa_hong_gt=0):($detail$$.ty_le_hoa_hong_gt=$ckhd_ckhds$$.ty_le_hh2||0,$detail$$.tien_hoa_hong_gt="9"==$ckhd_ckhds$$.kieu?Math.roundBy($loi_nhuan$$*$ckhd_ckhds$$.ty_le_hh2/100,0):Math.roundBy($t_tt_nt$$*$ckhd_ckhds$$.ty_le_hh2/100,0)):$ckhd_ckhds$$.tien_hh?($detail$$.tien_hoa_hong_gt=$ckhd_ckhds$$.tien_hh,$detail$$.ty_le_hoa_hong_gt=0):($detail$$.ty_le_hoa_hong_gt=
12
- $ckhd_ckhds$$.ty_le_hh||0,$detail$$.tien_hoa_hong_gt="9"==$ckhd_ckhds$$.kieu?Math.roundBy($loi_nhuan$$*$ckhd_ckhds$$.ty_le_hh/100,0):Math.roundBy($t_tt_nt$$*$ckhd_ckhds$$.ty_le_hh/100,0)),$detail$$.chuyen_ngay_gt="1"==$ckhd_ckhds$$.hinh_thuc_tt,$detail$$.tk_no_hoa_hong_gt=$ckhd_ckhds$$.tk_no,$detail$$.tk_co_hoa_hong_gt=$ckhd_ckhds$$.tk_co)})()}));$obj$$.tien_hoa_hong_gt=$obj$$.details.csum("tien_hoa_hong_gt");$obj$$.chuyen_ngay_gt=!!$obj$$.details.find($d$$=>$d$$.chuyen_ngay_gt)}},hoahonghdctv=async $obj$$=>
13
- {if(!$obj$$.da_chuyen_hoa_hong_ctv){$obj$$.thu_nhap_ctv=0;$obj$$.ty_le_hoa_hong_ctv=0;$obj$$.details.forEach($detail$$=>{$detail$$.thu_nhap_ctv=0;$detail$$.ty_le_hoa_hong_ctv=0});$obj$$.user_ctv||$obj$$.ma_ctv||($obj$$.user_ctv=$obj$$.user_created);var $hieu_luc_tu$jscomp$1_kh$jscomp$2_q_ma_kh$$;$obj$$.user_ctv&&($hieu_luc_tu$jscomp$1_kh$jscomp$2_q_ma_kh$$=await global.getModel("customer").findOne({id_app:$obj$$.id_app,status:!0,of_user:$obj$$.user_ctv,isctv:!0}))&&($obj$$.ma_ctv=$hieu_luc_tu$jscomp$1_kh$jscomp$2_q_ma_kh$$.ma_kh);
14
- !$hieu_luc_tu$jscomp$1_kh$jscomp$2_q_ma_kh$$&&$obj$$.ma_ctv&&($hieu_luc_tu$jscomp$1_kh$jscomp$2_q_ma_kh$$=await global.getModel("customer").findOne({id_app:$obj$$.id_app,status:!0,ma_kh:$obj$$.ma_ctv,isctv:!0}));if($hieu_luc_tu$jscomp$1_kh$jscomp$2_q_ma_kh$$){var $query$$={id_app:$obj$$.id_app,ma_kho:{$in:[void 0,null,"",$obj$$.ma_kho]},doi_tuong:"2"};var $hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$=moment($obj$$.ngay_ct).startOf("date").toDate();$hieu_luc_tu$jscomp$1_kh$jscomp$2_q_ma_kh$$={$lte:moment($obj$$.ngay_ct).endOf("date").toDate()};
15
- $hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$={$gte:$hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$};$query$$.hieu_luc_tu=$hieu_luc_tu$jscomp$1_kh$jscomp$2_q_ma_kh$$;$query$$.hieu_luc_den=$hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$;var $sort$$={do_uu_tien:1,gt_tu:-1,tien_hh:-1,ty_le_hh:-1,ma_nv:-1,user_group:-1,nh_kh:-1,hieu_luc_tu:-1,kieu:1};$hieu_luc_tu$jscomp$1_kh$jscomp$2_q_ma_kh$$={$in:[void 0,null,"",$obj$$.ma_kh]};$hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$={$in:[void 0,null,
16
- ""]};if($obj$$.ma_kh){var $g$jscomp$1_kh$$=await customer.findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh},{nh_kh:1});$g$jscomp$1_kh$$&&$g$jscomp$1_kh$$.nh_kh&&($hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$={$in:[void 0,null,"",$g$jscomp$1_kh$$.nh_kh]})}if($obj$$.user_ctv){if($g$jscomp$1_kh$$=await global.getModel("participant").findOne({id_app:$obj$$.id_app,email:$obj$$.user_ctv}).lean())$query$$.user_group={$in:[($g$jscomp$1_kh$$.group_id||"").toString(),null,void 0,""]}}else $query$$.user_group=
17
- {$in:[null,void 0,""]};$query$$.$or=[{$and:[{ma_kh:$hieu_luc_tu$jscomp$1_kh$jscomp$2_q_ma_kh$$},{nh_kh:{$in:["",null,void 0]}}]},{$and:[{nh_kh:$hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$},{ma_kh:{$in:["",null,void 0]}}]}];await Promise.all($obj$$.details.map($detail$$=>{let $t_tt_nt$$=$detail$$.tien_hang_nt-$detail$$.tien_ck_nt,$loi_nhuan$$=$t_tt_nt$$-$detail$$.tien_xuat_tmp;const $_query$$=_.cloneDeep($query$$);$_query$$.gt_tu={$lte:$t_tt_nt$$};$_query$$.$and=[{$or:[{gt_den:{$in:[0,void 0,
18
- null]}},{gt_den:{$gte:$t_tt_nt$$}}]},{$or:[{"vts.0":{$exists:!1}},{vts:$detail$$.ma_vt}]}];return(async()=>{var $ckhd$jscomp$1_ckhds$$=await global.getModel("dmhoahonghd").find($_query$$).sort($sort$$).limit(1).lean();0<$ckhd$jscomp$1_ckhds$$.length&&($ckhd$jscomp$1_ckhds$$=$ckhd$jscomp$1_ckhds$$[0],$detail$$.gia_ban_niem_yet_nt&&$detail$$.gia_ban_niem_yet_nt>$detail$$.gia_ban_nt?$ckhd$jscomp$1_ckhds$$.tien_hh2?($detail$$.tien_hoa_hong_ctv=$ckhd$jscomp$1_ckhds$$.tien_hh2,$detail$$.ty_le_hoa_hong_ctv=
19
- 0):($detail$$.ty_le_hoa_hong_ctv=$ckhd$jscomp$1_ckhds$$.ty_le_hh2||0,$detail$$.tien_hoa_hong_ctv="9"==$ckhd$jscomp$1_ckhds$$.kieu?Math.roundBy($loi_nhuan$$*$ckhd$jscomp$1_ckhds$$.ty_le_hh2/100,0):Math.roundBy($t_tt_nt$$*$ckhd$jscomp$1_ckhds$$.ty_le_hh2/100,0)):$ckhd$jscomp$1_ckhds$$.tien_hh?($detail$$.tien_hoa_hong_ctv=$ckhd$jscomp$1_ckhds$$.tien_hh,$detail$$.ty_le_hoa_hong_ctv=0):($detail$$.ty_le_hoa_hong_ctv=$ckhd$jscomp$1_ckhds$$.ty_le_hh||0,$detail$$.tien_hoa_hong_ctv="9"==$ckhd$jscomp$1_ckhds$$.kieu?
20
- Math.roundBy($loi_nhuan$$*$ckhd$jscomp$1_ckhds$$.ty_le_hh/100,0):Math.roundBy($t_tt_nt$$*$ckhd$jscomp$1_ckhds$$.ty_le_hh/100,0)),$detail$$.chuyen_ngay_ctv="1"==$ckhd$jscomp$1_ckhds$$.hinh_thuc_tt,$detail$$.tk_cp_ctv=$ckhd$jscomp$1_ckhds$$.tk_no,$detail$$.tk_cn_ctv=$ckhd$jscomp$1_ckhds$$.tk_co)})()}));$obj$$.thu_nhap_ctv=$obj$$.details.csum("tien_hoa_hong_ctv");$obj$$.chuyen_ngay_ctv=!!$obj$$.details.find($d$$=>$d$$.chuyen_ngay_ctv)}}},hoahonghdnv=async $obj$$=>{if($obj$$.tu_tinh_hoa_hong&&!$obj$$.da_chuyen_hoa_hong){$obj$$.tien_hoa_hong=
21
- 0;$obj$$.ty_le_hoa_hong=0;$obj$$.ma_kh_hoa_hong="";$obj$$.details.forEach($detail$$=>{$detail$$.tien_hoa_hong=0;$detail$$.ty_le_hoa_hong=0});$obj$$.user_nv||$obj$$.ma_nv||($obj$$.user_nv=$obj$$.user_created);var $g$jscomp$2_kh$jscomp$4_kh$$;if($obj$$.ma_nv||$obj$$.user_nv){var $nv_query_nv$$={id_app:$obj$$.id_app,status:!0};$obj$$.ma_nv&&($nv_query_nv$$.ma_nv=$obj$$.ma_nv);$obj$$.user_nv&&($nv_query_nv$$.user=$obj$$.user_nv);if($nv_query_nv$$=await global.getModel("dmnv").findOne($nv_query_nv$$).lean())$obj$$.ma_kh_hoa_hong=
22
- $nv_query_nv$$.ma_kh,$obj$$.user_nv=$nv_query_nv$$.user,$obj$$.ma_nv=$nv_query_nv$$.ma_nv,$obj$$.ten_nv=$nv_query_nv$$.ten_nv,$obj$$.ma_kh_hoa_hong&&($g$jscomp$2_kh$jscomp$4_kh$$=await global.getModel("customer").findOne({id_app:$obj$$.id_app,status:!0,ma_kh:$obj$$.ma_kh_hoa_hong,isctv:{$in:[!1,null]}}))}!$g$jscomp$2_kh$jscomp$4_kh$$&&$obj$$.user_nv&&($obj$$.ma_kh_hoa_hong="",$g$jscomp$2_kh$jscomp$4_kh$$=await global.getModel("customer").findOne({id_app:$obj$$.id_app,status:!0,of_user:$obj$$.user_nv,
23
- isctv:{$in:[!1,null]}}))&&($obj$$.ma_kh_hoa_hong=$g$jscomp$2_kh$jscomp$4_kh$$.ma_kh);if($g$jscomp$2_kh$jscomp$4_kh$$){var $user_group$$;$obj$$.user_nv?($g$jscomp$2_kh$jscomp$4_kh$$=await global.getModel("participant").findOne({id_app:$obj$$.id_app,email:$obj$$.user_nv}).lean())&&($user_group$$={$in:[($g$jscomp$2_kh$jscomp$4_kh$$.group_id||"").toString(),null,void 0,""]}):$user_group$$={$in:[null,void 0,""]};var $q_ma_kh$$={$in:[void 0,null,"",$obj$$.ma_kh]},$q_nh_kh$$={$in:[void 0,null,""]};$obj$$.ma_kh&&
24
- ($g$jscomp$2_kh$jscomp$4_kh$$=await customer.findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh},{nh_kh:1}))&&$g$jscomp$2_kh$jscomp$4_kh$$.nh_kh&&($q_nh_kh$$={$in:[void 0,null,"",$g$jscomp$2_kh$jscomp$4_kh$$.nh_kh]});await Promise.all($obj$$.details.map($detail$$=>(async()=>{let $t_tt_nt$$=$detail$$.tien_hang_nt-$detail$$.tien_ck_nt,$loi_nhuan$$=$t_tt_nt$$-$detail$$.tien_xuat_tmp;var $ckhd$jscomp$2_ckhds$jscomp$2_query$$={id_app:$obj$$.id_app,gt_tu:{$lte:$t_tt_nt$$},ma_kho:{$in:[void 0,null,"",$obj$$.ma_kho]},
25
- doi_tuong:"0",ma_nv:{$in:[void 0,null,"",$obj$$.ma_nv]}};$ckhd$jscomp$2_ckhds$jscomp$2_query$$.$and=[{$or:[{gt_den:{$in:[0,void 0,null]}},{gt_den:{$gte:$t_tt_nt$$}}]},{$or:[{"vts.0":{$exists:!1}},{vts:$detail$$.ma_vt}]}];let $hieu_luc_tu$$;var $hieu_luc_den$jscomp$2_tu_ngay$$=moment($obj$$.ngay_ct).startOf("date").toDate();$hieu_luc_tu$$={$lte:moment($obj$$.ngay_ct).endOf("date").toDate()};$hieu_luc_den$jscomp$2_tu_ngay$$={$gte:$hieu_luc_den$jscomp$2_tu_ngay$$};$ckhd$jscomp$2_ckhds$jscomp$2_query$$.hieu_luc_tu=
26
- $hieu_luc_tu$$;$ckhd$jscomp$2_ckhds$jscomp$2_query$$.hieu_luc_den=$hieu_luc_den$jscomp$2_tu_ngay$$;$user_group$$&&($ckhd$jscomp$2_ckhds$jscomp$2_query$$.user_group=$user_group$$);$ckhd$jscomp$2_ckhds$jscomp$2_query$$.$or=[{$and:[{ma_kh:$q_ma_kh$$},{nh_kh:{$in:["",null,void 0]}}]},{$and:[{nh_kh:$q_nh_kh$$},{ma_kh:{$in:["",null,void 0]}}]}];$ckhd$jscomp$2_ckhds$jscomp$2_query$$=await global.getModel("dmhoahonghd").find($ckhd$jscomp$2_ckhds$jscomp$2_query$$).sort({do_uu_tien:1,gt_tu:-1,tien_hh:-1,ty_le_hh:-1,
27
- ma_nv:-1,user_group:-1,nh_kh:-1,hieu_luc_tu:-1,kieu:1}).limit(1).lean();0<$ckhd$jscomp$2_ckhds$jscomp$2_query$$.length&&($ckhd$jscomp$2_ckhds$jscomp$2_query$$=$ckhd$jscomp$2_ckhds$jscomp$2_query$$[0],$detail$$.gia_ban_niem_yet_nt&&$detail$$.gia_ban_niem_yet_nt>$detail$$.gia_ban_nt?$ckhd$jscomp$2_ckhds$jscomp$2_query$$.tien_hh2?($detail$$.tien_hoa_hong=$ckhd$jscomp$2_ckhds$jscomp$2_query$$.tien_hh2,$detail$$.ty_le_hoa_hong=0):($detail$$.ty_le_hoa_hong=$ckhd$jscomp$2_ckhds$jscomp$2_query$$.ty_le_hh2||
28
- 0,$detail$$.tien_hoa_hong="9"==$ckhd$jscomp$2_ckhds$jscomp$2_query$$.kieu?Math.roundBy($loi_nhuan$$*$ckhd$jscomp$2_ckhds$jscomp$2_query$$.ty_le_hh2/100,0):Math.roundBy($t_tt_nt$$*$ckhd$jscomp$2_ckhds$jscomp$2_query$$.ty_le_hh2/100,0)):$ckhd$jscomp$2_ckhds$jscomp$2_query$$.tien_hh?($detail$$.tien_hoa_hong=$ckhd$jscomp$2_ckhds$jscomp$2_query$$.tien_hh,$detail$$.ty_le_hoa_hong=0):($detail$$.ty_le_hoa_hong=$ckhd$jscomp$2_ckhds$jscomp$2_query$$.ty_le_hh||0,$detail$$.tien_hoa_hong="9"==$ckhd$jscomp$2_ckhds$jscomp$2_query$$.kieu?
29
- Math.roundBy($loi_nhuan$$*$ckhd$jscomp$2_ckhds$jscomp$2_query$$.ty_le_hh/100,0):Math.roundBy($t_tt_nt$$*$ckhd$jscomp$2_ckhds$jscomp$2_query$$.ty_le_hh/100,0)),$detail$$.chuyen_ngay="1"==$ckhd$jscomp$2_ckhds$jscomp$2_query$$.hinh_thuc_tt,$detail$$.tk_no_hoa_hong=$ckhd$jscomp$2_ckhds$jscomp$2_query$$.tk_no,$detail$$.tk_co_hoa_hong=$ckhd$jscomp$2_ckhds$jscomp$2_query$$.tk_co)})()));$obj$$.tien_hoa_hong=$obj$$.details.csum("tien_hoa_hong");$obj$$.chuyen_ngay=!!$obj$$.details.find($d$$=>$d$$.chuyen_ngay)}}},
30
- khuyenmaihd=async $obj$$=>{if($obj$$.details&&$obj$$.online){var $ckhds$jscomp$3_query$jscomp$3_t_tien_nt$$=$obj$$.details.filter($d$$=>!$d$$.km_yn_for).csum("tien_hang_nt");if(0!==$ckhds$jscomp$3_query$jscomp$3_t_tien_nt$$){var $hieu_luc_tu$jscomp$3_i_q_ma_kh$jscomp$3_t_ck_nt$jscomp$3_t_tt_nt$$=$obj$$.details.filter($d$$=>!$d$$.km_yn_for).csum("tien_ck_nt");$hieu_luc_tu$jscomp$3_i_q_ma_kh$jscomp$3_t_ck_nt$jscomp$3_t_tt_nt$$=$ckhds$jscomp$3_query$jscomp$3_t_tien_nt$$-$hieu_luc_tu$jscomp$3_i_q_ma_kh$jscomp$3_t_ck_nt$jscomp$3_t_tt_nt$$;
31
- $obj$$.details=$obj$$.details.filter($d$$=>"khuyenmaihd"!=$d$$.km_yn_for);$ckhds$jscomp$3_query$jscomp$3_t_tien_nt$$={id_app:$obj$$.id_app,gt_tu:{$lte:$hieu_luc_tu$jscomp$3_i_q_ma_kh$jscomp$3_t_ck_nt$jscomp$3_t_tt_nt$$},ma_kho:{$in:[void 0,null,"",$obj$$.ma_kho]}};$ckhds$jscomp$3_query$jscomp$3_t_tien_nt$$.$and=[{$or:[{gt_den:{$in:[0,void 0,null]}},{gt_den:{$gte:$hieu_luc_tu$jscomp$3_i_q_ma_kh$jscomp$3_t_ck_nt$jscomp$3_t_tt_nt$$}}]}];var $ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$=
32
- moment($obj$$.ngay_ct).startOf("date").toDate();$hieu_luc_tu$jscomp$3_i_q_ma_kh$jscomp$3_t_ck_nt$jscomp$3_t_tt_nt$$={$lte:moment($obj$$.ngay_ct).endOf("date").toDate()};$ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$={$gte:$ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$};$ckhds$jscomp$3_query$jscomp$3_t_tien_nt$$.hieu_luc_tu=$hieu_luc_tu$jscomp$3_i_q_ma_kh$jscomp$3_t_ck_nt$jscomp$3_t_tt_nt$$;$ckhds$jscomp$3_query$jscomp$3_t_tien_nt$$.hieu_luc_den=$ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$;
33
- $hieu_luc_tu$jscomp$3_i_q_ma_kh$jscomp$3_t_ck_nt$jscomp$3_t_tt_nt$$={$in:[void 0,null,"",$obj$$.ma_kh]};$ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$={$in:[void 0,null,""]};if($obj$$.ma_kh){var $kh$jscomp$6_lan_mua_thu$$=await customer.findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh},{nh_kh:1});$kh$jscomp$6_lan_mua_thu$$&&$kh$jscomp$6_lan_mua_thu$$.nh_kh&&($ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$={$in:[void 0,null,"",$kh$jscomp$6_lan_mua_thu$$.nh_kh]});($kh$jscomp$6_lan_mua_thu$$=
34
- await model.countDocuments({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh,trang_thai:{$in:["5","6"]}}))||($kh$jscomp$6_lan_mua_thu$$=0);$kh$jscomp$6_lan_mua_thu$$+=1}$ckhds$jscomp$3_query$jscomp$3_t_tien_nt$$.$or=[{$and:[{ma_kh:$hieu_luc_tu$jscomp$3_i_q_ma_kh$jscomp$3_t_ck_nt$jscomp$3_t_tt_nt$$},{nh_kh:{$in:["",null,void 0]}}]},{$and:[{nh_kh:$ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$},{ma_kh:{$in:["",null,void 0]}}]}];$ckhds$jscomp$3_query$jscomp$3_t_tien_nt$$.ap_dung_lan_mua_thu={$in:[null,
35
- void 0,0,void 0]};$ckhds$jscomp$3_query$jscomp$3_t_tien_nt$$.online=!0;$ckhds$jscomp$3_query$jscomp$3_t_tien_nt$$=await dmkhuyenmaihd.find($ckhds$jscomp$3_query$jscomp$3_t_tien_nt$$).sort({stt_uu_tien:1,gt_tu:-1,ma_kh:-1,nh_kh:-1,hieu_luc_tu:-1}).lean();for($hieu_luc_tu$jscomp$3_i_q_ma_kh$jscomp$3_t_ck_nt$jscomp$3_t_tt_nt$$=0;$hieu_luc_tu$jscomp$3_i_q_ma_kh$jscomp$3_t_ck_nt$jscomp$3_t_tt_nt$$<$ckhds$jscomp$3_query$jscomp$3_t_tien_nt$$.length;$hieu_luc_tu$jscomp$3_i_q_ma_kh$jscomp$3_t_ck_nt$jscomp$3_t_tt_nt$$++)if(($ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$=
36
- $ckhds$jscomp$3_query$jscomp$3_t_tien_nt$$[$hieu_luc_tu$jscomp$3_i_q_ma_kh$jscomp$3_t_ck_nt$jscomp$3_t_tt_nt$$])&&$ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$.details_km&&0<$ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$.details_km.length){$kh$jscomp$6_lan_mua_thu$$=$ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$.sl_toi_thieu||0;let $sl_dap_ung$$=0;$kh$jscomp$6_lan_mua_thu$$&&$ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$.vts&&0<
37
- $ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$.vts.length&&$ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$.vts.forEach($vt$$=>{var $ds_tien$$=$obj$$.details.filter($d$$=>$d$$.ma_vt===$vt$$.ma_vt&&(!$vt$$.ma_tt1||$vt$$.ma_tt1===$d$$.ma_tt1)&&(!$vt$$.ma_tt2||$vt$$.ma_tt2===$d$$.ma_tt2)&&(!$vt$$.ma_tt3||$vt$$.ma_tt3===$d$$.ma_tt3));if(0!=$ds_tien$$.length){var $so_luong$$=$ds_tien$$.map($d$$=>$d$$.sl_xuat).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$ds_tien$$=$ds_tien$$.map($d$$=>
38
- ($d$$.tien_hang_nt||0)-($d$$.tien_ck_nt||0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$vt$$.sl_tu&&$so_luong$$<$vt$$.sl_tu||$vt$$.sl_den&&$so_luong$$>$vt$$.sl_den||$vt$$.gt_tu&&$ds_tien$$<$vt$$.gt_tu||$vt$$.gt_den&&$ds_tien$$>$vt$$.gt_den||($sl_dap_ung$$+=1)}});if($kh$jscomp$6_lan_mua_thu$$<=$sl_dap_ung$$){$ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$.details_km.forEach($d$jscomp$9_detail$$=>{$d$jscomp$9_detail$$={...$d$jscomp$9_detail$$,km_yn_for:"khuyenmaihd"};$d$jscomp$9_detail$$.sl_xuat=
39
- $d$jscomp$9_detail$$.sl_km;$d$jscomp$9_detail$$.tien_hang_nt=$d$jscomp$9_detail$$.tien_hang=0;$d$jscomp$9_detail$$.tien_ck_nt=$d$jscomp$9_detail$$.tien_ck=0;$d$jscomp$9_detail$$.ty_le_ck=0;$d$jscomp$9_detail$$.tien_nt=$d$jscomp$9_detail$$.tien=0;$obj$$.details.push($d$jscomp$9_detail$$)});break}}}}},chietkhauhd=async $obj$$=>{if(!$obj$$.signature&&$obj$$.online){$obj$$.tien_ck_hd=0;$obj$$.ty_le_ck_hd=0;var $t_tien_nt$jscomp$4_t_tt_nt$$=$obj$$.details.filter($d$$=>!$d$$.km_yn_for).csum("tien_hang_nt"),
40
- $ckhds$jscomp$4_query$jscomp$4_t_ck_nt$$=$obj$$.details.filter($d$$=>!$d$$.km_yn_for).csum("tien_ck_nt");$t_tien_nt$jscomp$4_t_tt_nt$$-=$ckhds$jscomp$4_query$jscomp$4_t_ck_nt$$;$ckhds$jscomp$4_query$jscomp$4_t_ck_nt$$={id_app:$obj$$.id_app,gt_tu:{$lte:$t_tien_nt$jscomp$4_t_tt_nt$$},ma_kho:{$in:[void 0,null,"",$obj$$.ma_kho]}};$ckhds$jscomp$4_query$jscomp$4_t_ck_nt$$.$and=[{$or:[{gt_den:{$in:[0,void 0,null]}},{gt_den:{$gte:$t_tien_nt$jscomp$4_t_tt_nt$$}}]}];var $ckhd$jscomp$4_hieu_luc_den$jscomp$4_q_nh_kh$jscomp$4_tu_ngay$$=
41
- moment($obj$$.ngay_ct).startOf("date").toDate();var $hieu_luc_tu$jscomp$4_i$jscomp$1_q_ma_kh$$={$lte:moment($obj$$.ngay_ct).endOf("date").toDate()};$ckhd$jscomp$4_hieu_luc_den$jscomp$4_q_nh_kh$jscomp$4_tu_ngay$$={$gte:$ckhd$jscomp$4_hieu_luc_den$jscomp$4_q_nh_kh$jscomp$4_tu_ngay$$};$ckhds$jscomp$4_query$jscomp$4_t_ck_nt$$.hieu_luc_tu=$hieu_luc_tu$jscomp$4_i$jscomp$1_q_ma_kh$$;$ckhds$jscomp$4_query$jscomp$4_t_ck_nt$$.hieu_luc_den=$ckhd$jscomp$4_hieu_luc_den$jscomp$4_q_nh_kh$jscomp$4_tu_ngay$$;$hieu_luc_tu$jscomp$4_i$jscomp$1_q_ma_kh$$=
42
- {$in:[void 0,null,"",$obj$$.ma_kh]};$ckhd$jscomp$4_hieu_luc_den$jscomp$4_q_nh_kh$jscomp$4_tu_ngay$$={$in:[void 0,null,""]};if($obj$$.ma_kh){var $kh$jscomp$7_lan_mua_thu$jscomp$3_sl_toi_thieu$$=await customer.findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh},{nh_kh:1});$kh$jscomp$7_lan_mua_thu$jscomp$3_sl_toi_thieu$$&&$kh$jscomp$7_lan_mua_thu$jscomp$3_sl_toi_thieu$$.nh_kh&&($ckhd$jscomp$4_hieu_luc_den$jscomp$4_q_nh_kh$jscomp$4_tu_ngay$$={$in:[void 0,null,"",$kh$jscomp$7_lan_mua_thu$jscomp$3_sl_toi_thieu$$.nh_kh]});
43
- ($kh$jscomp$7_lan_mua_thu$jscomp$3_sl_toi_thieu$$=await model.countDocuments({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh,trang_thai:{$in:["5","6"]}}))||($kh$jscomp$7_lan_mua_thu$jscomp$3_sl_toi_thieu$$=0);$kh$jscomp$7_lan_mua_thu$jscomp$3_sl_toi_thieu$$+=1}$ckhds$jscomp$4_query$jscomp$4_t_ck_nt$$.$or=[{$and:[{ma_kh:$hieu_luc_tu$jscomp$4_i$jscomp$1_q_ma_kh$$},{nh_kh:{$in:["",null,void 0]}}]},{$and:[{nh_kh:$ckhd$jscomp$4_hieu_luc_den$jscomp$4_q_nh_kh$jscomp$4_tu_ngay$$},{ma_kh:{$in:["",null,void 0]}}]}];
44
- $ckhds$jscomp$4_query$jscomp$4_t_ck_nt$$.ap_dung_lan_mua_thu={$in:[null,void 0,0,void 0]};$ckhds$jscomp$4_query$jscomp$4_t_ck_nt$$.online=!0;$ckhds$jscomp$4_query$jscomp$4_t_ck_nt$$=await dmchietkhauhd.find($ckhds$jscomp$4_query$jscomp$4_t_ck_nt$$).sort({gt_tu:-1,tien_ck:-1,ty_le_ck:-1,ma_kh:-1,nh_kh:-1,hieu_luc_tu:-1}).lean();if(0<$ckhds$jscomp$4_query$jscomp$4_t_ck_nt$$.length)for($hieu_luc_tu$jscomp$4_i$jscomp$1_q_ma_kh$$=0;$hieu_luc_tu$jscomp$4_i$jscomp$1_q_ma_kh$$<$ckhds$jscomp$4_query$jscomp$4_t_ck_nt$$.length;$hieu_luc_tu$jscomp$4_i$jscomp$1_q_ma_kh$$++){$ckhd$jscomp$4_hieu_luc_den$jscomp$4_q_nh_kh$jscomp$4_tu_ngay$$=
45
- $ckhds$jscomp$4_query$jscomp$4_t_ck_nt$$[$hieu_luc_tu$jscomp$4_i$jscomp$1_q_ma_kh$$];$kh$jscomp$7_lan_mua_thu$jscomp$3_sl_toi_thieu$$=$ckhd$jscomp$4_hieu_luc_den$jscomp$4_q_nh_kh$jscomp$4_tu_ngay$$.sl_toi_thieu||0;let $sl_dap_ung$$=0;$kh$jscomp$7_lan_mua_thu$jscomp$3_sl_toi_thieu$$&&$ckhd$jscomp$4_hieu_luc_den$jscomp$4_q_nh_kh$jscomp$4_tu_ngay$$.vts&&0<$ckhd$jscomp$4_hieu_luc_den$jscomp$4_q_nh_kh$jscomp$4_tu_ngay$$.vts.length&&$ckhd$jscomp$4_hieu_luc_den$jscomp$4_q_nh_kh$jscomp$4_tu_ngay$$.vts.forEach($vt$$=>
46
- {var $ds$jscomp$1_tien$$=$obj$$.details.filter($d$$=>$d$$.ma_vt===$vt$$.ma_vt&&(!$vt$$.ma_tt1||$vt$$.ma_tt1===$d$$.ma_tt1)&&(!$vt$$.ma_tt2||$vt$$.ma_tt2===$d$$.ma_tt2)&&(!$vt$$.ma_tt3||$vt$$.ma_tt3===$d$$.ma_tt3));if(0!=$ds$jscomp$1_tien$$.length){var $so_luong$$=$ds$jscomp$1_tien$$.map($d$$=>$d$$.sl_xuat).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$ds$jscomp$1_tien$$=$ds$jscomp$1_tien$$.map($d$$=>($d$$.tien_hang_nt||0)-($d$$.tien_ck_nt||0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$vt$$.sl_tu&&$so_luong$$<$vt$$.sl_tu||
47
- $vt$$.sl_den&&$so_luong$$>$vt$$.sl_den||$vt$$.gt_tu&&$ds$jscomp$1_tien$$<$vt$$.gt_tu||$vt$$.gt_den&&$ds$jscomp$1_tien$$>$vt$$.gt_den||($sl_dap_ung$$+=1)}});if($kh$jscomp$7_lan_mua_thu$jscomp$3_sl_toi_thieu$$<=$sl_dap_ung$$){$ckhd$jscomp$4_hieu_luc_den$jscomp$4_q_nh_kh$jscomp$4_tu_ngay$$.tien_ck?($obj$$.tien_ck_hd=$ckhd$jscomp$4_hieu_luc_den$jscomp$4_q_nh_kh$jscomp$4_tu_ngay$$.tien_ck,$obj$$.ty_le_ck_hd=0):($obj$$.ty_le_ck_hd=$ckhd$jscomp$4_hieu_luc_den$jscomp$4_q_nh_kh$jscomp$4_tu_ngay$$.ty_le_ck,
48
- $obj$$.tien_ck_hd=Math.roundBy($t_tien_nt$jscomp$4_t_tt_nt$$*$ckhd$jscomp$4_hieu_luc_den$jscomp$4_q_nh_kh$jscomp$4_tu_ngay$$.ty_le_ck/100,0));$ckhd$jscomp$4_hieu_luc_den$jscomp$4_q_nh_kh$jscomp$4_tu_ngay$$.so_tien_max&&($obj$$.tien_ck_hd=Math.min($ckhd$jscomp$4_hieu_luc_den$jscomp$4_q_nh_kh$jscomp$4_tu_ngay$$.so_tien_max,$obj$$.tien_ck_hd));break}}}},getPointBalance=async($id_app$$,$sender_email$$)=>new Promise(($resolve$$,$reject$$)=>{ckdiem({id_app:$id_app$$,email:$sender_email$$},($e$$,$rs$$)=>
49
- {if($e$$)return $reject$$(Error($e$$));$resolve$$(0===$rs$$.length?0:$rs$$[0].ton00)})}),createTransactionBonus=async function($obj$$){if("5"!=$obj$$.trang_thai&&"6"!=$obj$$.trang_thai)return await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng \u0111\u1ec3 t\u00ednh l\u1ea1i"),await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":introduce"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng gi\u1edbi thi\u1ec7u th\u00e0nh vi\u00ean m\u1edbi \u0111\u1ec3 t\u00ednh l\u1ea1i"),
50
- null;let $kh$$=await customer.findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh})||{},$lan_mua$$=(await model.find({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh,ngay_ct:{$lte:$obj$$.ngay_ct}})).length+1;var $_app_diem_thuong_gioi_thieu_old_trans$$=await App.findOne({_id:$obj$$.id_app}),$_intro_amount$$=await Introducer.findOne({id_app:$obj$$.id_app,be_introduced:$obj$$.of_user||$obj$$.user_created});$_app_diem_thuong_gioi_thieu_old_trans$$=$_app_diem_thuong_gioi_thieu_old_trans$$.exfields.diem_thuong_gioi_thieu;
51
- 1===$lan_mua$$&&$_app_diem_thuong_gioi_thieu_old_trans$$&&$_intro_amount$$&&await transaction.createTrans({id_app:$obj$$.id_app,sender_email:$obj$$.id_app,receiver_email:$_intro_amount$$.be_introduced_by,amount:$_app_diem_thuong_gioi_thieu_old_trans$$,description:"\u0110i\u1ec3m th\u01b0\u1edfng gi\u1edbi thi\u1ec7u kh\u00e1ch h\u00e0ng",otherData:{ma_ct:$obj$$.ma_ct,so_ct:$obj$$.so_ct,ngay_ct:$obj$$.ngay_ct,id_ct:$obj$$._id.toString()+":introduce"}});if(!$obj$$.exfields.survey)return null;let $now$$=
52
- moment(new Date).startOf("date").toDate();$_intro_amount$$=$obj$$.details.filter($d$$=>$d$$.tien_hang).map(async $d$$=>{var $amount$$=await dmvt.findOne({ma_vt:$d$$.ma_vt,id_app:$obj$$.id_app}),$ckdiemthuong_ty_le_diem_thuong$$=await dmdiemthuong.find({id_app:$obj$$.id_app,status:!0,ma_kh:{$in:[null,"",$kh$$.ma_kh]},ma_kho:{$in:[null,"",$obj$$.ma_kho]},nh_kh:{$in:[null,"",$kh$$.nh_kh]},hieu_luc_tu:{$lte:$now$$},hieu_luc_den:{$gte:$now$$},ap_dung_lan_mua_thu:{$in:[0,$lan_mua$$]},ma_vt:{$in:[null,"",
53
- void 0,$d$$.ma_vt]},ma_nvt:{$in:[null,"",void 0,$amount$$?$amount$$.ma_nvt:""]}}).sort({ma_vt:-1,ma_nvt:-1,hieu_luc_tu:-1}).limit(1);return 0<$ckdiemthuong_ty_le_diem_thuong$$.length?($amount$$=0,$ckdiemthuong_ty_le_diem_thuong$$[0].tien?($ckdiemthuong_ty_le_diem_thuong$$=$ckdiemthuong_ty_le_diem_thuong$$[0].diem/$ckdiemthuong_ty_le_diem_thuong$$[0].tien)||($amount$$=Math.roundBy(($d$$.tien_hang-($d$$.tien_ck||0))*$ckdiemthuong_ty_le_diem_thuong$$,0)):$amount$$=$ckdiemthuong_ty_le_diem_thuong$$[0].diem*
54
- ($d$$.sl_xuat||1),$amount$$):0});if($_intro_amount$$=(await Promise.all($_intro_amount$$)).reduce(($a$$,$b$$)=>$a$$+$b$$,0)){if($_app_diem_thuong_gioi_thieu_old_trans$$=await transaction.findOne({id_ct:$obj$$._id.toString()+":bonus"}),!$_app_diem_thuong_gioi_thieu_old_trans$$||$_app_diem_thuong_gioi_thieu_old_trans$$.amount!==$_intro_amount$$)return await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng \u0111\u1ec3 t\u00ednh l\u1ea1i"),
55
- await transaction.createTrans({id_app:$obj$$.id_app,sender_email:$obj$$.id_app,receiver_email:$obj$$.of_user||$obj$$.user_created,amount:$_intro_amount$$,description:"\u0110i\u1ec3m th\u01b0\u1edfng mua h\u00e0ng",otherData:{ma_ct:$obj$$.ma_ct,so_ct:$obj$$.so_ct,ngay_ct:$obj$$.ngay_ct,id_ct:$obj$$._id.toString()+":bonus"}})}else await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng \u0111\u1ec3 t\u00ednh l\u1ea1i")},createTransactionPayment=
56
- async function($obj$$){await transaction.deleteTrans({id_ct:$obj$$._id.toString()});$obj$$.paymentByPoints&&await transaction.createTrans({id_app:$obj$$.id_app,sender_email:$obj$$.of_user||$obj$$.user_created,receiver_email:$obj$$.id_app,amount:$obj$$.paymentByPoints,description:"Thanh to\u00e1n cho \u0111\u01a1n h\u00e0ng s\u1ed1 "+$obj$$.so_ct,otherData:{ma_ct:$obj$$.ma_ct,so_ct:$obj$$.so_ct,ngay_ct:$obj$$.ngay_ct,id_ct:$obj$$._id.toString()}})},checkEvoucher=($user$$,$obj$$)=>{let $gt_don_hang$$=
57
- $obj$$.details.map($d$$=>$d$$.tien_hang_nt-($d$$.tien_ck_nt||0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0);return($obj$$.evouchers||[]).map($ev$$=>new Promise(($resolve$$,$reject$$)=>{(async()=>{const $_e$$=await Evoucher.findOne({ma:$ev$$.ma,id_app:$user$$.current_id_app});if(!$_e$$)return console.error("Th\u1ebb mua h\u00e0ng kh\u00f4ng t\u1ed3n t\u1ea1i",$ev$$),$reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} kh\u00f4ng t\u1ed3n t\u1ea1i`));if(!$_e$$.online)return $reject$$(Error(`Kh\u00f4ng th\u1ec3 s\u1eed d\u1ee5ng th\u1ebb mua h\u00e0ng ${$ev$$.ma} cho \u0111\u01a1n h\u00e0ng online`));
58
- if($_e$$.id_ct_used&&$_e$$.id_ct_used!==($obj$$._id||"").toString())return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} \u0111\u00e3 \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng`));if(1<=$_e$$.so_lan_sd&&$_e$$.id_ct_useds&&0<$_e$$.id_ct_useds.length&&($_e$$.id_ct_useds=[...(new Set([...$_e$$.id_ct_useds]))],$_e$$.id_ct_useds.length>=$_e$$.so_lan_sd&&(!$obj$$._id||0>$_e$$.id_ct_useds.indexOf($obj$$._id))))return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} \u0111\u00e3 \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng h\u1ebft`));
59
- if($_e$$.user&&$_e$$.user!==($obj$$.of_user||$obj$$.user_created||$user$$.email))return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} kh\u00f4ng h\u1ee3p l\u1ec7`));var $date_created_so_tien_giam$$=new Date($obj$$.date_created);if(moment($_e$$.hieu_luc_den).endOf("date").toDate().getTime()<$date_created_so_tien_giam$$.getTime())return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} \u0111\u00e3 h\u1ebft h\u1ea1n s\u1eed d\u1ee5ng`));if($_e$$.gt_don_hang_toi_thieu&&$gt_don_hang$$<$_e$$.gt_don_hang_toi_thieu)return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} ch\u1ec9 \u00e1p d\u1ee5ng cho c\u00e1c \u0111\u01a1n h\u00e0ng c\u00f3 gi\u00e1 tr\u1ecb l\u1edbn h\u01a1n ho\u1eb7c b\u1eb1ng ${numeral($_e$$.gt_don_hang_toi_thieu).format()}`));
2
+ global.getModel("dmdt"),dmphi=global.getModel("dmphi"),contract=global.getModel("contract"),trangthai=global.getModel("trangthai"),currency=global.getModel("currency"),ptthanhtoan=global.getModel("ptthanhtoan"),dmdiemthuong=global.getModel("dmdiemthuong"),model=global.getModel("so1"),pt1=global.getModel("pt1"),controller=require("../../controllers/controller"),async=require("async"),ma_ct="SO1",ckdiem=require("../../libs/ckdiem"),tinhhoahong=require("../../libs/tinhhoahong"),blockchainconnect=require("../../libs/blockchainconnect"),
3
+ moment=require("moment"),numeral=require("numeral"),App=global.getModel("app"),Introducer=global.getModel("introducer"),getGiaBan=require("../../libs/getGiabanAsync"),dmchietkhauhd=global.getModel("dmchietkhauhd"),dmkhuyenmaihd=global.getModel("dmkhuyenmaihd"),underscore=require("underscore"),{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,
4
+ $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",$e$$,$receiver_user$$,$receiver_address$$,$amount$$,$denom$$,$memo$$)}},tinhtienthue=($detail$$,$gia_ban_chua_thue$$)=>{$detail$$.ma_thue?($gia_ban_chua_thue$$?($detail$$.tien_ct=$detail$$.tien,$detail$$.tien_ct_nt=$detail$$.tien_nt,$detail$$.gia_ban_ct=$detail$$.gia_ban,
5
+ $detail$$.gia_ban_ct_nt=$detail$$.gia_ban_nt):($detail$$.tien_ct=$detail$$.tien/(1+$detail$$.thue_suat/100),$detail$$.tien_ct_nt=$detail$$.tien_nt/(1+$detail$$.thue_suat/100),$detail$$.gia_ban_ct=Math.roundBy($detail$$.tien_ct/($detail$$.sl_xuat||1)),$detail$$.gia_ban_ct_nt=Math.roundBy($detail$$.tien_ct_nt/($detail$$.sl_xuat||1)),$detail$$.tien_ct=$detail$$.sl_xuat*$detail$$.gia_ban_ct,$detail$$.tien_ct_nt=$detail$$.sl_xuat*$detail$$.gia_ban_ct_nt),$detail$$.tien_thue=Math.roundBy($detail$$.tien_ct*
6
+ $detail$$.thue_suat/100),$detail$$.tien_thue_nt=Math.roundBy($detail$$.tien_ct_nt*$detail$$.thue_suat/100)):($detail$$.tien_ck_ct_nt=$detail$$.tien_ck_nt,$detail$$.tien_ck_ct=$detail$$.tien_ck,$detail$$.tien_thue=0,$detail$$.tien_thue_nt=0,$detail$$.tien_ct=$detail$$.tien,$detail$$.tien_ct_nt=$detail$$.tien_nt)},khuyenmaihd=async $obj$$=>{if($obj$$.details&&$obj$$.online){var $ckhds_query_t_tien_nt$$=$obj$$.details.filter($d$$=>!$d$$.km_yn_for).csum("tien_hang_nt");if(0!==$ckhds_query_t_tien_nt$$){var $hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$=
7
+ $obj$$.details.filter($d$$=>!$d$$.km_yn_for).csum("tien_ck_nt");$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$=$ckhds_query_t_tien_nt$$-$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$;$obj$$.details=$obj$$.details.filter($d$$=>"khuyenmaihd"!=$d$$.km_yn_for);$ckhds_query_t_tien_nt$$={id_app:$obj$$.id_app,gt_tu:{$lte:$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$},ma_kho:{$in:[void 0,null,"",$obj$$.ma_kho]}};$ckhds_query_t_tien_nt$$.$and=[{$or:[{gt_den:{$in:[0,void 0,null]}},{gt_den:{$gte:$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$}}]}];
8
+ var $ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$=moment($obj$$.ngay_ct).startOf("date").toDate();$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$={$lte:moment($obj$$.ngay_ct).endOf("date").toDate()};$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$={$gte:$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$};$ckhds_query_t_tien_nt$$.hieu_luc_tu=$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$;$ckhds_query_t_tien_nt$$.hieu_luc_den=$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$;$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$={$in:[void 0,null,"",$obj$$.ma_kh]};$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$=
9
+ {$in:[void 0,null,""]};if($obj$$.ma_kh){var $kh_lan_mua_thu$$=await customer.findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh},{nh_kh:1});$kh_lan_mua_thu$$&&$kh_lan_mua_thu$$.nh_kh&&($ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$={$in:[void 0,null,"",$kh_lan_mua_thu$$.nh_kh]});($kh_lan_mua_thu$$=await model.countDocuments({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh,trang_thai:{$in:["5","6"]}}))||($kh_lan_mua_thu$$=0);$kh_lan_mua_thu$$+=1}$ckhds_query_t_tien_nt$$.$or=[{$and:[{ma_kh:$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$},
10
+ {nh_kh:{$in:["",null,void 0]}}]},{$and:[{nh_kh:$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$},{ma_kh:{$in:["",null,void 0]}}]}];$ckhds_query_t_tien_nt$$.ap_dung_lan_mua_thu={$in:[null,void 0,0,void 0]};$ckhds_query_t_tien_nt$$.online=!0;$ckhds_query_t_tien_nt$$=await dmkhuyenmaihd.find($ckhds_query_t_tien_nt$$).sort({stt_uu_tien:1,gt_tu:-1,ma_kh:-1,nh_kh:-1,hieu_luc_tu:-1}).lean();for($hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$=0;$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$<$ckhds_query_t_tien_nt$$.length;$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$++)if(($ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$=
11
+ $ckhds_query_t_tien_nt$$[$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$])&&$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.details_km&&0<$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.details_km.length){$kh_lan_mua_thu$$=$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.sl_toi_thieu||0;let $sl_dap_ung$$=0;$kh_lan_mua_thu$$&&$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.vts&&0<$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.vts.length&&$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.vts.forEach($vt$$=>{var $ds_tien$$=$obj$$.details.filter($d$$=>$d$$.ma_vt===$vt$$.ma_vt&&
12
+ (!$vt$$.ma_tt1||$vt$$.ma_tt1===$d$$.ma_tt1)&&(!$vt$$.ma_tt2||$vt$$.ma_tt2===$d$$.ma_tt2)&&(!$vt$$.ma_tt3||$vt$$.ma_tt3===$d$$.ma_tt3));if(0!=$ds_tien$$.length){var $so_luong$$=$ds_tien$$.map($d$$=>$d$$.sl_xuat).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$ds_tien$$=$ds_tien$$.map($d$$=>($d$$.tien_hang_nt||0)-($d$$.tien_ck_nt||0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$vt$$.sl_tu&&$so_luong$$<$vt$$.sl_tu||$vt$$.sl_den&&$so_luong$$>$vt$$.sl_den||$vt$$.gt_tu&&$ds_tien$$<$vt$$.gt_tu||$vt$$.gt_den&&$ds_tien$$>$vt$$.gt_den||
13
+ ($sl_dap_ung$$+=1)}});if($kh_lan_mua_thu$$<=$sl_dap_ung$$){$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.details_km.forEach($d$jscomp$6_detail$$=>{$d$jscomp$6_detail$$={...$d$jscomp$6_detail$$,km_yn_for:"khuyenmaihd"};$d$jscomp$6_detail$$.sl_xuat=$d$jscomp$6_detail$$.sl_km;$d$jscomp$6_detail$$.tien_hang_nt=$d$jscomp$6_detail$$.tien_hang=0;$d$jscomp$6_detail$$.tien_ck_nt=$d$jscomp$6_detail$$.tien_ck=0;$d$jscomp$6_detail$$.ty_le_ck=0;$d$jscomp$6_detail$$.tien_nt=$d$jscomp$6_detail$$.tien=0;$obj$$.details.push($d$jscomp$6_detail$$)});
14
+ break}}}}},chietkhauhd=async $obj$$=>{if(!$obj$$.signature&&$obj$$.online){$obj$$.tien_ck_hd=0;$obj$$.ty_le_ck_hd=0;var $t_tien_nt$jscomp$1_t_tt_nt$$=$obj$$.details.filter($d$$=>!$d$$.km_yn_for).csum("tien_hang_nt"),$ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$=$obj$$.details.filter($d$$=>!$d$$.km_yn_for).csum("tien_ck_nt");$t_tien_nt$jscomp$1_t_tt_nt$$-=$ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$;$ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$={id_app:$obj$$.id_app,gt_tu:{$lte:$t_tien_nt$jscomp$1_t_tt_nt$$},ma_kho:{$in:[void 0,
15
+ null,"",$obj$$.ma_kho]}};$ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$.$and=[{$or:[{gt_den:{$in:[0,void 0,null]}},{gt_den:{$gte:$t_tien_nt$jscomp$1_t_tt_nt$$}}]}];var $ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$=moment($obj$$.ngay_ct).startOf("date").toDate();var $hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_kh$$={$lte:moment($obj$$.ngay_ct).endOf("date").toDate()};$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$={$gte:$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$};
16
+ $ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$.hieu_luc_tu=$hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_kh$$;$ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$.hieu_luc_den=$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$;$hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_kh$$={$in:[void 0,null,"",$obj$$.ma_kh]};$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$={$in:[void 0,null,""]};if($obj$$.ma_kh){var $kh$jscomp$1_lan_mua_thu$jscomp$3_sl_toi_thieu$$=await customer.findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh},
17
+ {nh_kh:1});$kh$jscomp$1_lan_mua_thu$jscomp$3_sl_toi_thieu$$&&$kh$jscomp$1_lan_mua_thu$jscomp$3_sl_toi_thieu$$.nh_kh&&($ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$={$in:[void 0,null,"",$kh$jscomp$1_lan_mua_thu$jscomp$3_sl_toi_thieu$$.nh_kh]});($kh$jscomp$1_lan_mua_thu$jscomp$3_sl_toi_thieu$$=await model.countDocuments({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh,trang_thai:{$in:["5","6"]}}))||($kh$jscomp$1_lan_mua_thu$jscomp$3_sl_toi_thieu$$=0);$kh$jscomp$1_lan_mua_thu$jscomp$3_sl_toi_thieu$$+=
18
+ 1}$ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$.$or=[{$and:[{ma_kh:$hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_kh$$},{nh_kh:{$in:["",null,void 0]}}]},{$and:[{nh_kh:$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$},{ma_kh:{$in:["",null,void 0]}}]}];$ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$.ap_dung_lan_mua_thu={$in:[null,void 0,0,void 0]};$ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$.online=!0;$ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$=await dmchietkhauhd.find($ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$).sort({gt_tu:-1,
19
+ tien_ck:-1,ty_le_ck:-1,ma_kh:-1,nh_kh:-1,hieu_luc_tu:-1}).lean();if(0<$ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$.length)for($hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_kh$$=0;$hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_kh$$<$ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$.length;$hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_kh$$++){$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$=$ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$[$hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_kh$$];$kh$jscomp$1_lan_mua_thu$jscomp$3_sl_toi_thieu$$=
20
+ $ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.sl_toi_thieu||0;let $sl_dap_ung$$=0;$kh$jscomp$1_lan_mua_thu$jscomp$3_sl_toi_thieu$$&&$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.vts&&0<$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.vts.length&&$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.vts.forEach($vt$$=>{var $ds$jscomp$1_tien$$=$obj$$.details.filter($d$$=>$d$$.ma_vt===$vt$$.ma_vt&&(!$vt$$.ma_tt1||$vt$$.ma_tt1===$d$$.ma_tt1)&&
21
+ (!$vt$$.ma_tt2||$vt$$.ma_tt2===$d$$.ma_tt2)&&(!$vt$$.ma_tt3||$vt$$.ma_tt3===$d$$.ma_tt3));if(0!=$ds$jscomp$1_tien$$.length){var $so_luong$$=$ds$jscomp$1_tien$$.map($d$$=>$d$$.sl_xuat).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$ds$jscomp$1_tien$$=$ds$jscomp$1_tien$$.map($d$$=>($d$$.tien_hang_nt||0)-($d$$.tien_ck_nt||0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$vt$$.sl_tu&&$so_luong$$<$vt$$.sl_tu||$vt$$.sl_den&&$so_luong$$>$vt$$.sl_den||$vt$$.gt_tu&&$ds$jscomp$1_tien$$<$vt$$.gt_tu||$vt$$.gt_den&&$ds$jscomp$1_tien$$>
22
+ $vt$$.gt_den||($sl_dap_ung$$+=1)}});if($kh$jscomp$1_lan_mua_thu$jscomp$3_sl_toi_thieu$$<=$sl_dap_ung$$){$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.tien_ck?($obj$$.tien_ck_hd=$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.tien_ck,$obj$$.ty_le_ck_hd=0):($obj$$.ty_le_ck_hd=$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.ty_le_ck,$obj$$.tien_ck_hd=Math.roundBy($t_tien_nt$jscomp$1_t_tt_nt$$*$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.ty_le_ck/
23
+ 100,0));$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.so_tien_max&&($obj$$.tien_ck_hd=Math.min($ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.so_tien_max,$obj$$.tien_ck_hd));break}}}},getPointBalance=async($id_app$$,$sender_email$$)=>new Promise(($resolve$$,$reject$$)=>{ckdiem({id_app:$id_app$$,email:$sender_email$$},($e$$,$rs$$)=>{if($e$$)return $reject$$(Error($e$$));$resolve$$(0===$rs$$.length?0:$rs$$[0].ton00)})}),createTransactionBonus=async function($obj$$){if("5"!=
24
+ $obj$$.trang_thai&&"6"!=$obj$$.trang_thai)return await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng \u0111\u1ec3 t\u00ednh l\u1ea1i"),await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":introduce"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng gi\u1edbi thi\u1ec7u th\u00e0nh vi\u00ean m\u1edbi \u0111\u1ec3 t\u00ednh l\u1ea1i"),null;let $kh$$=await customer.findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh})||{},$lan_mua$$=
25
+ (await model.find({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh,ngay_ct:{$lte:$obj$$.ngay_ct}})).length+1;var $_app_diem_thuong_gioi_thieu_old_trans$$=await App.findOne({_id:$obj$$.id_app}),$_intro_amount$$=await Introducer.findOne({id_app:$obj$$.id_app,be_introduced:$obj$$.of_user||$obj$$.user_created});$_app_diem_thuong_gioi_thieu_old_trans$$=$_app_diem_thuong_gioi_thieu_old_trans$$.exfields.diem_thuong_gioi_thieu;1===$lan_mua$$&&$_app_diem_thuong_gioi_thieu_old_trans$$&&$_intro_amount$$&&await transaction.createTrans({id_app:$obj$$.id_app,
26
+ sender_email:$obj$$.id_app,receiver_email:$_intro_amount$$.be_introduced_by,amount:$_app_diem_thuong_gioi_thieu_old_trans$$,description:"\u0110i\u1ec3m th\u01b0\u1edfng gi\u1edbi thi\u1ec7u kh\u00e1ch h\u00e0ng",otherData:{ma_ct:$obj$$.ma_ct,so_ct:$obj$$.so_ct,ngay_ct:$obj$$.ngay_ct,id_ct:$obj$$._id.toString()+":introduce"}});if(!$obj$$.exfields.survey)return null;let $now$$=moment(new Date).startOf("date").toDate();$_intro_amount$$=$obj$$.details.filter($d$$=>$d$$.tien_hang).map(async $d$$=>{var $amount$$=
27
+ await dmvt.findOne({ma_vt:$d$$.ma_vt,id_app:$obj$$.id_app}),$ckdiemthuong_ty_le_diem_thuong$$=await dmdiemthuong.find({id_app:$obj$$.id_app,status:!0,ma_kh:{$in:[null,"",$kh$$.ma_kh]},ma_kho:{$in:[null,"",$obj$$.ma_kho]},nh_kh:{$in:[null,"",$kh$$.nh_kh]},hieu_luc_tu:{$lte:$now$$},hieu_luc_den:{$gte:$now$$},ap_dung_lan_mua_thu:{$in:[0,$lan_mua$$]},ma_vt:{$in:[null,"",void 0,$d$$.ma_vt]},ma_nvt:{$in:[null,"",void 0,$amount$$?$amount$$.ma_nvt:""]}}).sort({ma_vt:-1,ma_nvt:-1,hieu_luc_tu:-1}).limit(1);
28
+ return 0<$ckdiemthuong_ty_le_diem_thuong$$.length?($amount$$=0,$ckdiemthuong_ty_le_diem_thuong$$[0].tien?($ckdiemthuong_ty_le_diem_thuong$$=$ckdiemthuong_ty_le_diem_thuong$$[0].diem/$ckdiemthuong_ty_le_diem_thuong$$[0].tien)||($amount$$=Math.roundBy(($d$$.tien_hang-($d$$.tien_ck||0))*$ckdiemthuong_ty_le_diem_thuong$$,0)):$amount$$=$ckdiemthuong_ty_le_diem_thuong$$[0].diem*($d$$.sl_xuat||1),$amount$$):0});if($_intro_amount$$=(await Promise.all($_intro_amount$$)).reduce(($a$$,$b$$)=>$a$$+$b$$,0)){if($_app_diem_thuong_gioi_thieu_old_trans$$=
29
+ await transaction.findOne({id_ct:$obj$$._id.toString()+":bonus"}),!$_app_diem_thuong_gioi_thieu_old_trans$$||$_app_diem_thuong_gioi_thieu_old_trans$$.amount!==$_intro_amount$$)return await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng \u0111\u1ec3 t\u00ednh l\u1ea1i"),await transaction.createTrans({id_app:$obj$$.id_app,sender_email:$obj$$.id_app,receiver_email:$obj$$.of_user||$obj$$.user_created,amount:$_intro_amount$$,description:"\u0110i\u1ec3m th\u01b0\u1edfng mua h\u00e0ng",
30
+ otherData:{ma_ct:$obj$$.ma_ct,so_ct:$obj$$.so_ct,ngay_ct:$obj$$.ngay_ct,id_ct:$obj$$._id.toString()+":bonus"}})}else await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng \u0111\u1ec3 t\u00ednh l\u1ea1i")},createTransactionPayment=async function($obj$$){await transaction.deleteTrans({id_ct:$obj$$._id.toString()});$obj$$.paymentByPoints&&await transaction.createTrans({id_app:$obj$$.id_app,sender_email:$obj$$.of_user||$obj$$.user_created,
31
+ receiver_email:$obj$$.id_app,amount:$obj$$.paymentByPoints,description:"Thanh to\u00e1n cho \u0111\u01a1n h\u00e0ng s\u1ed1 "+$obj$$.so_ct,otherData:{ma_ct:$obj$$.ma_ct,so_ct:$obj$$.so_ct,ngay_ct:$obj$$.ngay_ct,id_ct:$obj$$._id.toString()}})},checkEvoucher=($user$$,$obj$$)=>{let $gt_don_hang$$=$obj$$.details.map($d$$=>$d$$.tien_hang_nt-($d$$.tien_ck_nt||0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0);return($obj$$.evouchers||[]).map($ev$$=>new Promise(($resolve$$,$reject$$)=>{(async()=>{const $_e$$=await Evoucher.findOne({ma:$ev$$.ma,
32
+ id_app:$user$$.current_id_app});if(!$_e$$)return console.error("Th\u1ebb mua h\u00e0ng kh\u00f4ng t\u1ed3n t\u1ea1i",$ev$$),$reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} kh\u00f4ng t\u1ed3n t\u1ea1i`));if(!$_e$$.online)return $reject$$(Error(`Kh\u00f4ng th\u1ec3 s\u1eed d\u1ee5ng th\u1ebb mua h\u00e0ng ${$ev$$.ma} cho \u0111\u01a1n h\u00e0ng online`));if($_e$$.id_ct_used&&$_e$$.id_ct_used!==($obj$$._id||"").toString())return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} \u0111\u00e3 \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng`));
33
+ if(1<=$_e$$.so_lan_sd&&$_e$$.id_ct_useds&&0<$_e$$.id_ct_useds.length&&($_e$$.id_ct_useds=[...(new Set([...$_e$$.id_ct_useds]))],$_e$$.id_ct_useds.length>=$_e$$.so_lan_sd&&(!$obj$$._id||0>$_e$$.id_ct_useds.indexOf($obj$$._id))))return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} \u0111\u00e3 \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng h\u1ebft`));if($_e$$.user&&$_e$$.user!==($obj$$.of_user||$obj$$.user_created||$user$$.email))return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} kh\u00f4ng h\u1ee3p l\u1ec7`));
34
+ var $date_created_so_tien_giam$$=new Date($obj$$.date_created);if(moment($_e$$.hieu_luc_den).endOf("date").toDate().getTime()<$date_created_so_tien_giam$$.getTime())return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} \u0111\u00e3 h\u1ebft h\u1ea1n s\u1eed d\u1ee5ng`));if($_e$$.gt_don_hang_toi_thieu&&$gt_don_hang$$<$_e$$.gt_don_hang_toi_thieu)return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} ch\u1ec9 \u00e1p d\u1ee5ng cho c\u00e1c \u0111\u01a1n h\u00e0ng c\u00f3 gi\u00e1 tr\u1ecb l\u1edbn h\u01a1n ho\u1eb7c b\u1eb1ng ${numeral($_e$$.gt_don_hang_toi_thieu).format()}`));
60
35
  if($_e$$.vts&&0<$_e$$.vts.length&&$_e$$.sl_toi_thieu){let $sl_dap_ung$$=0;$_e$$.vts.forEach($vt$$=>{var $ds$jscomp$2_tien$$=$obj$$.details.filter($d$$=>$d$$.ma_vt===$vt$$.ma_vt&&(!$vt$$.ma_tt1||$vt$$.ma_tt1===$d$$.ma_tt1)&&(!$vt$$.ma_tt2||$vt$$.ma_tt2===$d$$.ma_tt2)&&(!$vt$$.ma_tt3||$vt$$.ma_tt3===$d$$.ma_tt3));if(0!=$ds$jscomp$2_tien$$.length){var $so_luong$$=$ds$jscomp$2_tien$$.map($d$$=>$d$$.sl_xuat).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$ds$jscomp$2_tien$$=$ds$jscomp$2_tien$$.map($d$$=>($d$$.tien_hang_nt||
61
36
  0)-($d$$.tien_ck_nt||0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$vt$$.sl_tu&&$so_luong$$<$vt$$.sl_tu||$vt$$.sl_den&&$so_luong$$>$vt$$.sl_den||$vt$$.gt_tu&&$ds$jscomp$2_tien$$<$vt$$.gt_tu||$vt$$.gt_den&&$ds$jscomp$2_tien$$>$vt$$.gt_den||($sl_dap_ung$$+=1)}});if($_e$$.sl_toi_thieu>$sl_dap_ung$$)return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} kh\u00f4ng h\u1ee3p l\u1ec7 do kh\u00f4ng \u0111\u00e1p \u1ee9ng \u0111\u01b0\u1ee3c y\u00eau c\u1ea7u s\u1ea3n ph\u1ea9m`))}$date_created_so_tien_giam$$=
62
37
  $_e$$.so_tien;$_e$$.ty_le&&($date_created_so_tien_giam$$=Math.roundBy($gt_don_hang$$*$_e$$.ty_le/100));$_e$$.so_tien_max&&$date_created_so_tien_giam$$>$_e$$.so_tien_max&&($date_created_so_tien_giam$$=$_e$$.so_tien_max);if($ev$$.so_tien_giam!==$date_created_so_tien_giam$$)return $reject$$(Error(`S\u1ed1 ti\u1ec1n gi\u1ea3m cho th\u1ebb ${$ev$$.ma} kh\u00f4ng h\u1ee3p l\u1ec7`));$ev$$.so_tien_giam=$date_created_so_tien_giam$$;$resolve$$(!0)})()}))},updateEvoucher=async($id_app$$,$evoucher_code$$,$id_ct_rs$$)=>
@@ -79,41 +54,40 @@ if($freeship_i$$.gia_tri_dh&&$freeship_i$$.gia_tri_dh>$details_dvgh_t_tien_nt$$)
79
54
  $obj$$,$_opt_pre_obj_t_tien_evoucher$$),await Promise.all($_checkEvoucher_tien_con_lai$$)}catch($e$$){throw console.error($e$$),Error($e$$.message||$e$$);}$obj$$.evouchers=$obj$$.evouchers||($_opt_pre_obj_t_tien_evoucher$$||{}).evouchers||[];$_opt_pre_obj_t_tien_evoucher$$=$obj$$.evouchers.map($e$$=>$e$$.so_tien_giam||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);var $_checkEvoucher_tien_con_lai$$=$details_dvgh_t_tien_nt$$-($obj$$.tt_tien_thuong||0);$_opt_pre_obj_t_tien_evoucher$$>$_checkEvoucher_tien_con_lai$$&&
80
55
  ($_opt_pre_obj_t_tien_evoucher$$=$_checkEvoucher_tien_con_lai$$);$obj$$.tien_evoucher=$_opt_pre_obj_t_tien_evoucher$$;if($obj$$.tien_evoucher&&($_opt_pre_obj_t_tien_evoucher$$=await options.findOne({id_app:$obj$$.id_app,id_func:$obj$$.ma_ct.toLowerCase()}).lean())&&$_opt_pre_obj_t_tien_evoucher$$.option&&$_opt_pre_obj_t_tien_evoucher$$.option.phan_bo_evoucher){let $tien_evoucher_da_phan_bo$$=0,$tien_evoucher$$=$obj$$.tien_evoucher,$tien_evoucher_con_lai$$=$tien_evoucher$$-$tien_evoucher_da_phan_bo$$;
81
56
  ($obj$$.details||[]).forEach($detail$$=>{if(0<$tien_evoucher_con_lai$$){var $tien_evoucher_duoc_pb_tien_hang_con_lai$$=$detail$$.tien_hang_nt-($detail$$.tien_ck_nt||0);$tien_evoucher_duoc_pb_tien_hang_con_lai$$=$tien_evoucher_con_lai$$>$tien_evoucher_duoc_pb_tien_hang_con_lai$$?$tien_evoucher_duoc_pb_tien_hang_con_lai$$:$tien_evoucher_con_lai$$;$detail$$.tien_evoucher_duoc_pb=$tien_evoucher_duoc_pb_tien_hang_con_lai$$;$tien_evoucher_da_phan_bo$$+=$tien_evoucher_duoc_pb_tien_hang_con_lai$$;$tien_evoucher_con_lai$$=
82
- $tien_evoucher$$-$tien_evoucher_da_phan_bo$$}else $tien_evoucher_con_lai$$=0})}},valid=async function($user$$,$obj$$,$next$$,$i$jscomp$4_pre_obj$$){$i$jscomp$4_pre_obj$$&&($obj$$.online=$i$jscomp$4_pre_obj$$.online,$obj$$._id=$i$jscomp$4_pre_obj$$._id,$obj$$.details=$obj$$.details||$i$jscomp$4_pre_obj$$.details||[],$obj$$.evouchers=$obj$$.evouchers||$i$jscomp$4_pre_obj$$.evouchers);if($obj$$.online)try{await validOnline($user$$,$obj$$,$i$jscomp$4_pre_obj$$)}catch($e$$){return $next$$($e$$.message)}if($obj$$.paymentByPoints)try{var $detail$$=
83
- await currency.getRate($obj$$.id_app,$obj$$.ma_nt);$detail$$=$detail$$||1;$obj$$.tien_paymentByPoints=$obj$$.paymentByPoints*$detail$$}catch($e$$){return $next$$($e$$.message)}for($i$jscomp$4_pre_obj$$=0;$i$jscomp$4_pre_obj$$<($obj$$.details||[]).length;$i$jscomp$4_pre_obj$$++)$detail$$=($obj$$.details||[])[$i$jscomp$4_pre_obj$$],$detail$$.line=$i$jscomp$4_pre_obj$$,"VND"===$obj$$.ma_nt&&($detail$$.tien_hang=$detail$$.tien_hang_nt,$detail$$.tien_ck=$detail$$.tien_ck_nt||0,$detail$$.gia_ban=$detail$$.gia_ban_nt),
84
- $detail$$.tien_nt=Math.max(0,$detail$$.tien_hang_nt-$detail$$.tien_ck_nt),$detail$$.tien=Math.max(0,$detail$$.tien_hang-$detail$$.tien_ck),$detail$$.tien_xuat=$detail$$.tien_xuat_nt;$obj$$.ma_dvcs?$next$$(null,$obj$$):dvcs.findOne({id_app:$user$$.current_id_app},{_id:1},function($error$$,$dv$$){return $error$$?$next$$($error$$):$dv$$?($obj$$.ma_dvcs=$dv$$._id.toString(),$next$$(null,$obj$$)):$next$$("C\u00f4ng ty/c\u1eeda h\u00e0ng n\u00e0y ch\u01b0a c\u00f3 m\u1ed9t \u0111\u01a1n v\u1ecb c\u01a1 s\u1edf n\u00e0o")})};
57
+ $tien_evoucher$$-$tien_evoucher_da_phan_bo$$}else $tien_evoucher_con_lai$$=0})}},valid=async function($user$$,$obj$$,$next$$,$opts_pre_obj$$){$opts_pre_obj$$&&($obj$$.online=$opts_pre_obj$$.online,$obj$$._id=$opts_pre_obj$$._id,$obj$$.details=$obj$$.details||$opts_pre_obj$$.details||[],$obj$$.evouchers=$obj$$.evouchers||$opts_pre_obj$$.evouchers);if($obj$$.online)try{await validOnline($user$$,$obj$$,$opts_pre_obj$$)}catch($e$$){return $next$$($e$$.message)}if($obj$$.paymentByPoints)try{var $he_so_qd_i$$=
58
+ await currency.getRate($obj$$.id_app,$obj$$.ma_nt);$he_so_qd_i$$=$he_so_qd_i$$||1;$obj$$.tien_paymentByPoints=$obj$$.paymentByPoints*$he_so_qd_i$$}catch($e$$){return $next$$($e$$.message)}$opts_pre_obj$$=await options.findOne({id_app:$obj$$.id_app,id_func:ma_ct.toLowerCase()}).lean();$opts_pre_obj$$=($opts_pre_obj$$||{}).option||{};await $obj$$.details.asyncJoinModel2($obj$$.id_app,"vat",{where:"ma_thue",fields:["thue_suat","tk_thue_co","tk_thue_co_treo"]});for($he_so_qd_i$$=0;$he_so_qd_i$$<($obj$$.details||
59
+ []).length;$he_so_qd_i$$++){const $detail$$=($obj$$.details||[])[$he_so_qd_i$$];$detail$$.line=$he_so_qd_i$$;"VND"===$obj$$.ma_nt&&($detail$$.tien_hang=$detail$$.tien_hang_nt,$detail$$.tien_ck=$detail$$.tien_ck_nt||0,$detail$$.gia_ban=$detail$$.gia_ban_nt);$detail$$.tien_nt=Math.max(0,$detail$$.tien_hang_nt-$detail$$.tien_ck_nt);$detail$$.tien=Math.max(0,$detail$$.tien_hang-$detail$$.tien_ck);$detail$$.tien_xuat=$detail$$.tien_xuat_nt;tinhtienthue($detail$$,$opts_pre_obj$$.gia_ban_chua_thue)}$obj$$.ma_dvcs?
60
+ $next$$(null,$obj$$):dvcs.findOne({id_app:$user$$.current_id_app},{_id:1},function($error$$,$dv$$){return $error$$?$next$$($error$$):$dv$$?($obj$$.ma_dvcs=$dv$$._id.toString(),$next$$(null,$obj$$)):$next$$("C\u00f4ng ty/c\u1eeda h\u00e0ng n\u00e0y ch\u01b0a c\u00f3 m\u1ed9t \u0111\u01a1n v\u1ecb c\u01a1 s\u1edf n\u00e0o")})};
85
61
  module.exports=function($contr_router$$){$contr_router$$=new controller($contr_router$$,model,ma_ct.toLowerCase(),{isVoucher:!0,requireRecaptchaToken:!1,unique:["so_ct"],sort:{ngay_ct:-1,so_ct:-1},onEmitEvent:async($obj$$,$users_will_receive$$,$next$$)=>{$obj$$.user_nv_giao_hang&&$users_will_receive$$.push($obj$$.user_nv_giao_hang);$next$$(null,$users_will_receive$$)}});$contr_router$$.route();$contr_router$$.saving=async($user$$,$obj$$)=>{$obj$$.user_created||($obj$$.user_created=$user$$.email);
86
- await $obj$$.details.asyncJoinModel2($obj$$.id_app,dmvt,{where:"ma_vt",fields:["ma_thue","gia_mua"]});$obj$$.details.forEach($d$$=>{$d$$.tien_xuat_tmp=$d$$.sl_xuat*($d$$.gia_mua||0)});await chietkhauhd($obj$$);await khuyenmaihd($obj$$);await hoahonghdnv($obj$$);await hoahonghdgt($obj$$);await hoahonghdctv($obj$$)};$contr_router$$.handleAfterPayment=async $obj$$=>{$obj$$.trang_thai_tt="5";$obj$$.trang_thai="1";await model.updateOne({_id:$obj$$._id},{details:$obj$$.details,trang_thai_tt:"5",trang_thai:"1"});
87
- let $ctrlSO1$$=global.controllers.SO1;$ctrlSO1$$&&controller.postData($obj$$,$ctrlSO1$$,$e$$=>{if($e$$)return console.error($e$$);controller.pushNotification($ctrlSO1$$,$obj$$)});return null};$contr_router$$.post=async function($obj$$,$fn$$){$fn$$||($fn$$=function(){});let $he_so_qd$$=await currency.getRate($obj$$.id_app,$obj$$.ma_nt)||1;const $appInfo$$=await global.getModel("app").findOne({_id:$obj$$.id_app}).lean();await $obj$$.details.asyncJoinModel2($obj$$.id_app,dmvt,{where:"ma_vt",fields:["ma_thue",
88
- "gia_mua"]});await $obj$$.details.filter($d$$=>$d$$.ma_thue).asyncJoinModel2($obj$$.id_app,global.getModel("vat"),{where:"ma_thue",fields:["thue_suat","tk_thue_co","tk_thue_co_treo"]});async.series({post_sokho:function($callback$jscomp$0$$){const $details$$=[];$obj$$.details.forEach($d$$=>{$details$$.push({...$d$$})});let $data_post$$=$details$$.map($detail$$=>$detail$$.combo&&0<$detail$$.combo.length?$detail$$.combo.map($item$$=>{$item$$=$item$$.toObject?$item$$.toObject():{...$item$$};$item$$.sl_xuat*=
89
- $detail$$.sl_xuat;$item$$.tien_xuat=$item$$.tien_xuat_nt=$item$$.sl_xuat*$item$$.gia_von_nt;$item$$.tien_hang=$item$$.tien_hang_nt=$item$$.sl_xuat*$item$$.gia_ban_nt;$item$$.tien_ck=$item$$.tien_ck_nt*=$item$$.sl_xuat;$item$$.tien=$item$$.tien_nt=$item$$.tien_hang_nt-$item$$.tien_ck_nt;return $item$$}):[$detail$$]).reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]);(new PostBook($obj$$,$data_post$$,Sokho,async function($detail$$,$callback$$){$detail$$.nxt=2;$detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;
90
- $detail$$.ma_kho=$detail$$.ma_kho||$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$jscomp$0$$($e$$,$rs$$)})},post_socai:function($callback$$){options.findOne({id_app:$obj$$.id_app,id_func:ma_ct.toLowerCase()}).lean().exec(async($error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$,$rs$jscomp$0$$)=>{let $option$$;$option$$=$rs$jscomp$0$$?$rs$jscomp$0$$.option||{}:{};let $kho$$=await dmkho.findOne({id_app:$obj$$.id_app,ma_kho:$obj$$.ma_kho}).lean();$kho$$||($kho$$=
91
- {});let $pt$$;$obj$$.pt_thanh_toan&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan)&&($pt$$=await ptthanhtoan.findOne({id_app:$obj$$.id_app,_id:$obj$$.pt_thanh_toan}).lean());$pt$$=$pt$$||{};$pt$$.tk_tien=$pt$$.tk_cn;$pt$$.tk_cn=$pt$$.tk_cn||$kho$$.tk_cn;$pt$$.tk_dt=$kho$$.tk_dt||$pt$$.tk_dt;$pt$$.tk_gv=$kho$$.tk_gv||$pt$$.tk_gv;$pt$$.tk_ck=$kho$$.tk_ck||$pt$$.tk_ck;$pt$$.tk_cp_gh=$kho$$.tk_cp_gh||$pt$$.tk_cp_gh;$pt$$.tk_cp_bh=$kho$$.tk_cp_bh||$pt$$.tk_cp_bh;$pt$$.tk_cp_ctv=$kho$$.tk_cp_ctv||
92
- $pt$$.tk_cp_ctv;$pt$$.tk_cn_ctv=$kho$$.tk_cn_ctv||$pt$$.tk_cn_ctv;$option$$.tk_tien=$pt$$.tk_tien||$kho$$.tk_tien||$option$$.tk_tien||"1111";$option$$.tk_cn=$pt$$.tk_cn||$option$$.tk_cn||"131111";$option$$.tk_dt=$pt$$.tk_dt||$option$$.tk_dt||"51111";$option$$.tk_tl=$pt$$.tk_tl||$option$$.tk_tl||"52131";$option$$.tk_ck=$pt$$.tk_ck||$option$$.tk_ck||"52111";$option$$.tk_gv=$pt$$.tk_gv||$option$$.tk_gv||"6321";$option$$.tk_cp_gh=$pt$$.tk_cp_gh||$option$$.tk_cp_gh||"6418";$option$$.tk_cp_bh=$pt$$.tk_cp_bh||
93
- $option$$.tk_cp_bh||$option$$.tk_ck;$option$$.tk_cp_ctv=$pt$$.tk_cp_ctv||$option$$.tk_cp_ctv;$option$$.tk_cn_ctv=$pt$$.tk_cn_ctv||$option$$.tk_cn_ctv;$pt$$.ten&&0<=$pt$$.ten.indexOf("COD")?$option$$.ma_kh=$obj$$.nhan_vien_giao_hang||$obj$$.don_vi_vc||$pt$$.ma_kh||$obj$$.ma_kh:$option$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh;$obj$$.details.forEach($detail$$=>{$detail$$.ma_thue&&$detail$$.tk_thue_co_treo?($detail$$.tien_ct=($detail$$.tien_hang-($detail$$.tien_ck||0))/(1+$detail$$.thue_suat/100),$detail$$.tien_ct_nt=
94
- ($detail$$.tien_hang_nt-($detail$$.tien_ck_nt||0))/(1+$detail$$.thue_suat/100),$detail$$.gia_ban_ct=Math.roundBy($detail$$.tien_ct/($detail$$.sl_xuat||1)),$detail$$.gia_ban_ct_nt=Math.roundBy($detail$$.tien_ct_nt/($detail$$.sl_xuat||1)),$detail$$.tien_ct=$detail$$.sl_xuat*$detail$$.gia_ban_ct,$detail$$.tien_ct_nt=$detail$$.sl_xuat*$detail$$.gia_ban_ct_nt,$detail$$.tien_thue=Math.roundBy($detail$$.tien_ct*$detail$$.thue_suat/100),$detail$$.tien_thue_nt=Math.roundBy($detail$$.tien_ct_nt*$detail$$.thue_suat/
95
- 100)):($detail$$.tien_ck_ct_nt=$detail$$.tien_ck_nt,$detail$$.tien_ck_ct=$detail$$.tien_ck,$detail$$.tien_thue=0,$detail$$.tien_thue_nt=0,$detail$$.tien_ct=$detail$$.tien,$detail$$.tien_ct_nt=$detail$$.tien_nt)});const $details$$=[];$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$=$obj$$.details.map($a$$=>($a$$.tien_hang_nt||0)-($a$$.tien_ck_nt||0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0)-(($obj$$.tt_tien_thuong||0)+($obj$$.tien_ck_hd||0)+($obj$$.tien_evoucher||0));$rs$jscomp$0$$=$obj$$.tien_paymentByPoints||
96
- 0;const $hoachtoandtvathue$$=($tk_tien$$,$ty_le$$)=>{$obj$$.details.forEach(function($d$jscomp$32_detail$$){$d$jscomp$32_detail$$={...$d$jscomp$32_detail$$};$d$jscomp$32_detail$$.tk_co=$option$$.tk_dt;$d$jscomp$32_detail$$.tk_no=$tk_tien$$;$d$jscomp$32_detail$$.ma_kh_co=$obj$$.ma_kh;$d$jscomp$32_detail$$.ma_kh_no=$option$$.ma_kh;$d$jscomp$32_detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;$d$jscomp$32_detail$$.tien=$d$jscomp$32_detail$$.tien_nt=Math.roundBy($d$jscomp$32_detail$$.tien_ct_nt*
97
- $ty_le$$);$d$jscomp$32_detail$$.flag="DT_"+($d$jscomp$32_detail$$.ma_vt||"");$details$$.push($d$jscomp$32_detail$$)});$obj$$.details.filter($d$$=>$d$$.tien_thue).forEach($detail$$=>{$detail$$={...$detail$$};$detail$$.tk_no=$tk_tien$$;$detail$$.tk_co=$detail$$.tk_thue_co_treo;$detail$$.ma_kh||($detail$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh);$detail$$.tien=$detail$$.tien_nt=Math.roundBy($detail$$.tien_thue_nt*$ty_le$$);$detail$$.flag="THUE_"+($detail$$.ma_vt||"");$details$$.push($detail$$)});console.log("post socai",
98
- $tk_tien$$,$ty_le$$)};$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$&&($hoachtoandtvathue$$($option$$.tk_cn,$rs$jscomp$0$$/$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$),$hoachtoandtvathue$$($option$$.tk_tien,($error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$-$rs$jscomp$0$$)/$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$));$obj$$.details.filter($d$$=>$d$$.diem_thuong&&$d$$.tk_km_no&&$d$$.tk_km_co).forEach(function($d$$){let $detail$$=
99
- {...$d$$};$detail$$.tk_co=$option$$.tk_km_co||$d$$.tk_km_co;$detail$$.tk_no=$option$$.tk_km_no||$d$$.tk_km_no;$detail$$.ma_kh=$obj$$.ma_kh;$detail$$.tien=$detail$$.tien_nt=$detail$$.diem_thuong*$he_so_qd$$;$details$$.push($detail$$)});$obj$$.ctcpbhs&&$obj$$.ctcpbhs.forEach(function($d$jscomp$36_detail$$){$d$jscomp$36_detail$$={...$d$jscomp$36_detail$$};$d$jscomp$36_detail$$.tk_co=$option$$.tk_dt;$d$jscomp$36_detail$$.tk_no=$option$$.tk_cn;$d$jscomp$36_detail$$.ma_kh_co=$obj$$.ma_kh;$d$jscomp$36_detail$$.ma_kh_no=
100
- $option$$.ma_kh;$d$jscomp$36_detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;$d$jscomp$36_detail$$.tien_nt=$d$jscomp$36_detail$$.tien_cp_nt;$d$jscomp$36_detail$$.tien=$d$jscomp$36_detail$$.tien_cp;$details$$.push($d$jscomp$36_detail$$)});$obj$$.tien_phi_vc&&($error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$={},$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_co=$option$$.tk_dt,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_no=$option$$.tk_cn,
101
- $error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt=$obj$$.tien_phi_vc||0,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien=$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_co=$obj$$.ma_kh,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_no=$obj$$.nhan_vien_giao_hang||$obj$$.don_vi_vc,$details$$.push($error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$));
102
- $obj$$.tien_freeship&&($error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$={},$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_no=$option$$.tk_cp_gh,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_co=$option$$.tk_cn,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt=$obj$$.tien_freeship||0,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien=$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt,
103
- $error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_no=$obj$$.ma_kh,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_co=$option$$.ma_kh,$details$$.push($error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$));$obj$$.tt_tien_thuong&&($error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$={},$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_no=$option$$.tk_cp_bh,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_co=
104
- $option$$.tk_cn,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt=$obj$$.tt_tien_thuong||0,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien=$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_no=$obj$$.ma_kh,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_co=$option$$.ma_kh,$details$$.push($error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$));
105
- $obj$$.tien_evoucher&&($error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$={},$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_no=$obj$$.tk_no_evoucher||$option$$.tk_no_evoucher||$option$$.tk_ck,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_co=$obj$$.tk_co_evoucher||$option$$.tk_co_evoucher||$option$$.tk_cn,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt=$obj$$.tien_evoucher||0,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien=
106
- $error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_no=$obj$$.ma_kh,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_co=$option$$.ma_kh,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.check_balance=!1,$details$$.push($error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$));$obj$$.tien_ck_hd&&($error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$={},
107
- $error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_no=$option$$.tk_ck,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_co=$option$$.tk_cn,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt=$obj$$.tien_ck_hd||0,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien=$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_no=$obj$$.ma_kh,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_co=
62
+ $obj$$.details.forEach($d$$=>{$d$$.tien_xuat_tmp=$d$$.sl_xuat*($d$$.gia_mua||0)});await chietkhauhd($obj$$);await khuyenmaihd($obj$$);$obj$$.details.forEach($d$$=>{$d$$.tt_nt=$d$$.tien_hang_nt-$d$$.tien_ck_nt;$d$$.tt=$d$$.tien_hang-$d$$.tien_ck});await tinhhoahong($obj$$)};$contr_router$$.handleAfterPayment=async $obj$$=>{$obj$$.trang_thai_tt="5";$obj$$.trang_thai="1";await model.updateOne({_id:$obj$$._id},{details:$obj$$.details,trang_thai_tt:"5",trang_thai:"1"});let $ctrlSO1$$=global.controllers.SO1;
63
+ $ctrlSO1$$&&controller.postData($obj$$,$ctrlSO1$$,$e$$=>{if($e$$)return console.error($e$$);controller.pushNotification($ctrlSO1$$,$obj$$)});return null};$contr_router$$.post=async function($obj$$,$fn$$){$fn$$||($fn$$=function(){});let $he_so_qd$$=await currency.getRate($obj$$.id_app,$obj$$.ma_nt)||1;const $appInfo$$=await global.getModel("app").findOne({_id:$obj$$.id_app}).lean();await $obj$$.details.filter($d$$=>!$d$$.ma_thue).asyncJoinModel2($obj$$.id_app,dmvt,{where:"ma_vt",fields:["ma_thue",
64
+ "gia_mua"]});await $obj$$.details.filter($d$$=>$d$$.ma_thue).asyncJoinModel2($obj$$.id_app,global.getModel("vat"),{where:"ma_thue",fields:["thue_suat","tk_thue_co","tk_thue_co_treo"]});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$0$$){const $details$$=[];$obj$$.details.forEach($d$$=>
65
+ {$details$$.push({...$d$$})});(new PostBook($obj$$,$product_details$$,Sokho,async function($detail$$,$callback$$){$detail$$.nxt=2;$detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;$detail$$.ma_kho=$detail$$.ma_kho||$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$jscomp$0$$($e$$,$rs$$)})},post_socai:function($callback$$){options.findOne({id_app:$obj$$.id_app,id_func:ma_ct.toLowerCase()}).lean().exec(async($error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$,
66
+ $rs$jscomp$0$$)=>{let $option$$;$option$$=$rs$jscomp$0$$?$rs$jscomp$0$$.option||{}:{};let $kho$$=await dmkho.findOne({id_app:$obj$$.id_app,ma_kho:$obj$$.ma_kho}).lean();$kho$$||($kho$$={});let $pt$$;$obj$$.pt_thanh_toan&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan)&&($pt$$=await ptthanhtoan.findOne({id_app:$obj$$.id_app,_id:$obj$$.pt_thanh_toan}).lean());$pt$$=$pt$$||{};$pt$$.tk_tien=$pt$$.tk_cn;$pt$$.tk_cn=$pt$$.tk_cn||$kho$$.tk_cn;$pt$$.tk_dt=$kho$$.tk_dt||$pt$$.tk_dt;$pt$$.tk_gv=
67
+ $kho$$.tk_gv||$pt$$.tk_gv;$pt$$.tk_ck=$kho$$.tk_ck||$pt$$.tk_ck;$pt$$.tk_cp_gh=$kho$$.tk_cp_gh||$pt$$.tk_cp_gh;$pt$$.tk_cp_bh=$kho$$.tk_cp_bh||$pt$$.tk_cp_bh;$pt$$.tk_cp_ctv=$kho$$.tk_cp_ctv||$pt$$.tk_cp_ctv;$pt$$.tk_cn_ctv=$kho$$.tk_cn_ctv||$pt$$.tk_cn_ctv;$option$$.tk_tien=$pt$$.tk_tien||$kho$$.tk_tien||$option$$.tk_tien||"1111";$option$$.tk_cn=$pt$$.tk_cn||$option$$.tk_cn||"131111";$option$$.tk_dt=$pt$$.tk_dt||$option$$.tk_dt||"51111";$option$$.tk_tl=$pt$$.tk_tl||$option$$.tk_tl||"52131";$option$$.tk_ck=
68
+ $pt$$.tk_ck||$option$$.tk_ck||"52111";$option$$.tk_gv=$pt$$.tk_gv||$option$$.tk_gv||"6321";$option$$.tk_cp_gh=$pt$$.tk_cp_gh||$option$$.tk_cp_gh||"6418";$option$$.tk_cp_bh=$pt$$.tk_cp_bh||$option$$.tk_cp_bh||$option$$.tk_ck;$option$$.tk_cp_ctv=$pt$$.tk_cp_ctv||$option$$.tk_cp_ctv;$option$$.tk_cn_ctv=$pt$$.tk_cn_ctv||$option$$.tk_cn_ctv;$pt$$.ten&&0<=$pt$$.ten.indexOf("COD")?$option$$.ma_kh=$obj$$.nhan_vien_giao_hang||$obj$$.don_vi_vc||$pt$$.ma_kh||$obj$$.ma_kh:$option$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh;
69
+ const $details$$=[];$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$=$obj$$.details.map($a$$=>($a$$.tien_hang_nt||0)-($a$$.tien_ck_nt||0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0)-(($obj$$.tt_tien_thuong||0)+($obj$$.tien_ck_hd||0)+($obj$$.tien_evoucher||0));$rs$jscomp$0$$=$obj$$.tien_paymentByPoints||0;const $hoachtoandtvathue$$=($tk_tien$$,$ty_le$$)=>{$obj$$.details.forEach(function($d$jscomp$31_detail$$){$d$jscomp$31_detail$$={...$d$jscomp$31_detail$$};let $tien_nt$$=$d$jscomp$31_detail$$.tien_ct_nt+
70
+ ($d$jscomp$31_detail$$.tien_nt-($d$jscomp$31_detail$$.tien_ct_nt+$d$jscomp$31_detail$$.tien_thue_nt));$d$jscomp$31_detail$$.tk_co=$option$$.tk_dt;$d$jscomp$31_detail$$.tk_no=$tk_tien$$;$d$jscomp$31_detail$$.ma_kh_co=$obj$$.ma_kh;$d$jscomp$31_detail$$.ma_kh_no=$option$$.ma_kh;$d$jscomp$31_detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;$d$jscomp$31_detail$$.tien=$d$jscomp$31_detail$$.tien_nt=Math.roundBy($tien_nt$$*$ty_le$$);$d$jscomp$31_detail$$.flag="DT_"+($d$jscomp$31_detail$$.ma_vt||"");
71
+ $details$$.push($d$jscomp$31_detail$$)});$obj$$.details.filter($d$$=>$d$$.tien_thue).forEach($detail$$=>{$detail$$={...$detail$$};$detail$$.tk_no=$tk_tien$$;$detail$$.tk_co=$detail$$.tk_thue_co_treo||$detail$$.tk_thue_co;$detail$$.ma_kh||($detail$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh);$detail$$.tien=$detail$$.tien_nt=Math.roundBy($detail$$.tien_thue_nt*$ty_le$$);$detail$$.flag="THUE_"+($detail$$.ma_vt||"");$details$$.push($detail$$)});console.log("post socai",$tk_tien$$,$ty_le$$)};$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$&&
72
+ ($hoachtoandtvathue$$($option$$.tk_cn,$rs$jscomp$0$$/$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$),$hoachtoandtvathue$$($option$$.tk_tien,($error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$-$rs$jscomp$0$$)/$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$));$obj$$.details.filter($d$$=>$d$$.diem_thuong&&$d$$.tk_km_no&&$d$$.tk_km_co).forEach(function($d$$){let $detail$$={...$d$$};$detail$$.tk_co=$option$$.tk_km_co||$d$$.tk_km_co;$detail$$.tk_no=$option$$.tk_km_no||
73
+ $d$$.tk_km_no;$detail$$.ma_kh=$obj$$.ma_kh;$detail$$.tien=$detail$$.tien_nt=$detail$$.diem_thuong*$he_so_qd$$;$details$$.push($detail$$)});$obj$$.ctcpbhs&&$obj$$.ctcpbhs.forEach(function($d$jscomp$35_detail$$){$d$jscomp$35_detail$$={...$d$jscomp$35_detail$$};$d$jscomp$35_detail$$.tk_co=$option$$.tk_dt;$d$jscomp$35_detail$$.tk_no=$option$$.tk_cn;$d$jscomp$35_detail$$.ma_kh_co=$obj$$.ma_kh;$d$jscomp$35_detail$$.ma_kh_no=$option$$.ma_kh;$d$jscomp$35_detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;
74
+ $d$jscomp$35_detail$$.tien_nt=$d$jscomp$35_detail$$.tien_cp_nt;$d$jscomp$35_detail$$.tien=$d$jscomp$35_detail$$.tien_cp;$details$$.push($d$jscomp$35_detail$$)});$obj$$.tien_phi_vc&&($error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$={},$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_co=$option$$.tk_dt,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_no=$option$$.tk_cn,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt=$obj$$.tien_phi_vc||
75
+ 0,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien=$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_co=$obj$$.ma_kh,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_no=$obj$$.nhan_vien_giao_hang||$obj$$.don_vi_vc,$details$$.push($error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$));$obj$$.tien_freeship&&($error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$=
76
+ {},$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_no=$option$$.tk_cp_gh,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_co=$option$$.tk_cn,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt=$obj$$.tien_freeship||0,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien=$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_no=$obj$$.ma_kh,
77
+ $error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_co=$option$$.ma_kh,$details$$.push($error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$));$obj$$.tt_tien_thuong&&($error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$={},$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_no=$option$$.tk_cp_bh,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_co=$option$$.tk_cn,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt=
78
+ $obj$$.tt_tien_thuong||0,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien=$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_no=$obj$$.ma_kh,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_co=$option$$.ma_kh,$details$$.push($error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$));$obj$$.tien_evoucher&&($error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$=
79
+ {},$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_no=$obj$$.tk_no_evoucher||$option$$.tk_no_evoucher||$option$$.tk_ck,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_co=$obj$$.tk_co_evoucher||$option$$.tk_co_evoucher||$option$$.tk_cn,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt=$obj$$.tien_evoucher||0,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien=$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt,
80
+ $error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_no=$obj$$.ma_kh,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_co=$option$$.ma_kh,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.check_balance=!1,$details$$.push($error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$));$obj$$.tien_ck_hd&&($error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$={},$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_no=
81
+ $option$$.tk_ck,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_co=$option$$.tk_cn,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt=$obj$$.tien_ck_hd||0,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien=$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_no=$obj$$.ma_kh,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_co=
108
82
  $option$$.ma_kh,$error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.check_balance=!1,$details$$.push($error$jscomp$2_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_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||
109
- $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=$obj$$.ma_ctv;$tt$$.tk_no&&$tt$$.tk_co&&$details$$.push($tt$$)}));$obj$$.tien_hoa_hong&&$obj$$.ma_kh_hoa_hong&&($obj$$.details.filter($r$$=>$r$$.tien_hoa_hong).forEach($r$$=>
110
- {$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=$r$$.tien_hoa_hong;$tt$$.tien=$tt$$.tien_nt*
111
- ($obj$$.ty_gia||1);$tt$$.ma_kh=$obj$$.ma_kh_hoa_hong;$tt$$.ma_nv=$obj$$.ma_nv;$tt$$.check_balance=!1;$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||$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||
112
- $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;$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;
113
- $tt$$.ma_nv=$obj$$.ma_nv;$tt$$.check_balance=!1;$tt$$.tk_no&&$tt$$.tk_co&&$details$$.push($tt$$)}));let $details_tienvon$$=[...$obj$$.details];$details_tienvon$$.joinModel2($obj$$.id_app,dmvt,{where:"ma_vt",fields:["tk_vt","gia_mua","tk_gv","tg_tk"]},()=>{$details_tienvon$$.forEach(function($d$jscomp$37_detail$$){$d$jscomp$37_detail$$={...$d$jscomp$37_detail$$};$d$jscomp$37_detail$$.tk_no=$option$$.tk_gv;$d$jscomp$37_detail$$.ma_kh=$obj$$.ma_kh;$d$jscomp$37_detail$$.ngay_ct=$obj$$.ngay_giao_hang||
114
- $obj$$.ngay_ct;$d$jscomp$37_detail$$.tk_co=$d$jscomp$37_detail$$.tk_vt||"1561";$d$jscomp$37_detail$$.tien_nt=$d$jscomp$37_detail$$.tien_xuat_nt;$d$jscomp$37_detail$$.tien=$d$jscomp$37_detail$$.tien_xuat;$d$jscomp$37_detail$$.tg_tk||($d$jscomp$37_detail$$.tien=$d$jscomp$37_detail$$.tien_nt=0);$details$$.push($d$jscomp$37_detail$$)});(new PostSocai($obj$$,$details$$,null,Socaitmp)).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})})})},thanhtoanhoahongnv:$callback$$=>{if($obj$$.da_chuyen_hoa_hong||
115
- !$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,wallet_type:1});
116
- 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()}`;
83
+ $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=$obj$$.ma_ctv;$tt$$.ma_nt="VND";$tt$$.ty_gia=1;$tt$$.tk_no&&$tt$$.tk_co&&$details$$.push($tt$$)}));$obj$$.tien_hoa_hong&&$obj$$.ma_kh_hoa_hong&&($obj$$.details.filter($r$$=>
84
+ $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=$r$$.tien_hoa_hong;
85
+ $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$$.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||$obj$$.tk_no_hoa_hong||$kho$$.tk_no_hoa_hong||
86
+ 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;$tt$$.tien_nt=$r$$.tien_hoa_hong_gt;$tt$$.tien=
87
+ $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$$.ma_nt="VND";$tt$$.ty_gia=1;$tt$$.tk_no&&$tt$$.tk_co&&$details$$.push($tt$$)}));let $details_tienvon$$=[...$product_details$$];$product_details$$.joinModel2($obj$$.id_app,dmvt,{where:"ma_vt",fields:["tk_vt","gia_mua","tk_gv","tg_tk"]},()=>{$details_tienvon$$.forEach(function($d$jscomp$36_detail$$){$d$jscomp$36_detail$$={...$d$jscomp$36_detail$$};$d$jscomp$36_detail$$.tk_no=$option$$.tk_gv;
88
+ $d$jscomp$36_detail$$.ma_kh=$obj$$.ma_kh;$d$jscomp$36_detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;$d$jscomp$36_detail$$.tk_co=$d$jscomp$36_detail$$.tk_vt||"1561";$d$jscomp$36_detail$$.tien_nt=$d$jscomp$36_detail$$.tien_xuat_nt;$d$jscomp$36_detail$$.tien=$d$jscomp$36_detail$$.tien_xuat;$d$jscomp$36_detail$$.tg_tk||($d$jscomp$36_detail$$.tien=$d$jscomp$36_detail$$.tien_nt=0);$details$$.push($d$jscomp$36_detail$$)});(new PostSocai($obj$$,$details$$,null,Socaitmp)).run(function($e$$,$rs$$){$callback$$($e$$,
89
+ $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(),username:$obj$$.user_nv,wallet_type:1});if(!$wallet_nhan_vien$$){$wallet_nhan_vien$$=(new global.getModel("asskey"))({user_created:$obj$$.user_nv,
90
+ 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";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()}`;
117
91
  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&&
118
92
  $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=
119
93
  $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=
@@ -121,31 +95,32 @@ $accounts$$[0].address;$wallet_gt$$.mnemonic=$wallet$$.mnemonic;$wallet_gt$$.nam
121
95
  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$$=
122
96
  $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",
123
97
  $e$$)}$callback$$()})}},function($e$$,$rs$$){$fn$$($e$$,$rs$$)})};$contr_router$$.creating=async function($user$$,$obj$$,$next$$){$obj$$.details||($obj$$.details=[]);if(!$obj$$.ma_kh){let $kh$$=await customer.findOne({id_app:$obj$$.id_app||$user$$.current_id_app,of_user:$user$$.email},{ma_kh:-1});$kh$$&&($obj$$.ma_kh=$kh$$.ma_kh)}delete $obj$$.virtual_payment_client_url;$obj$$.da_chuyen_hoa_hong=!1;$obj$$.da_chuyen_hoa_hong_gt=!1;await $obj$$.details.asyncJoinModel2($user$$.current_id_app,dmvt,{where:"ma_vt",
124
- fields:["combo"]});$obj$$.details.forEach($detail$$=>{$detail$$.combo&&0<$detail$$.combo.length&&($detail$$.combo=$detail$$.combo.map($item$$=>{$item$$=$item$$.toObject?$item$$.toObject():{...$item$$};$item$$.sl_xuat*=$detail$$.sl_xuat;$item$$.tien_xuat=$item$$.tien_xuat_nt=$item$$.sl_xuat*($item$$.gia_von_nt||0);$item$$.tien_hang=$item$$.tien_hang_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$$.tien=$item$$.tien_nt=$item$$.tien_hang_nt-
125
- ($item$$.tien_ck_nt||0);return $item$$}))});valid($user$$,$obj$$,async $error$$=>{if($error$$)return $next$$($error$$);if(!$obj$$.paymentByPoints)return $next$$(null,$obj$$);try{if(await getPointBalance($user$$.current_id_app,$obj$$.of_user||$user$$.email)<$obj$$.paymentByPoints)return $next$$("B\u1ea1n kh\u00f4ng c\u00f3 \u0111\u1ee7 \u0111i\u1ec3m \u0111\u1ec3 th\u1ef1c hi\u1ec7n giao d\u1ecbch n\u00e0y.");$next$$(null,$obj$$)}catch($e$$){$next$$($e$$.message)}})};$contr_router$$.created=async function($user$$,
126
- $obj$$,$next$$){if($obj$$.pt_thanh_toan&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan))try{const $pt_thanh_toan$$=await global.getModel("ptthanhtoan").findOne({_id:$obj$$.pt_thanh_toan});if($pt_thanh_toan$$.payment_service){let $paymentServiceModel$$=global.getModel($pt_thanh_toan$$.payment_service);$obj$$.amount=$obj$$.t_tt_nt-($obj$$.tien_paymentByPoints||0);if($obj$$.amount&&$paymentServiceModel$$.createVirtualPaymentClientURL){let $virtual_payment_client_url$$=await $paymentServiceModel$$.createVirtualPaymentClientURL($obj$$,
127
- $user$$.clientIp,$pt_thanh_toan$$);$obj$$.virtual_payment_client_url=$virtual_payment_client_url$$;$obj$$.payment_service=$pt_thanh_toan$$.payment_service;$obj$$.payment_id=((await $paymentServiceModel$$.findOne({$or:[{id_ct:$obj$$._id.toString()},{request_id:$obj$$._id.toString()},{order_id:$obj$$._id.toString()}]})||{})._id||"").toString()}else $obj$$.virtual_payment_client_url="",$obj$$.payment_service="",$obj$$.payment_id=""}else $obj$$.virtual_payment_client_url=""}catch($e$$){return console.error($e$$),
128
- $next$$("Kh\u00f4ng tao li\u00ean k\u1ebft thanh to\u00e1n:"+($e$$.message||$e$$.error||$e$$))}else console.log("Chua nhap phuong thuc thanh toan"),$obj$$.virtual_payment_client_url="";model.findOneAndUpdate({_id:$obj$$._id},{virtual_payment_client_url:$obj$$.virtual_payment_client_url,payment_id:$obj$$.payment_id,payment_service:$obj$$.payment_service},$e$$=>{$e$$&&(console.error($e$$),console.log("error create Virtual Payment ClientURL",$e$$.message))});await createTransactionPayment($obj$$);await createTransactionBonus($obj$$);
129
- $obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>updateEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$next$$(null,$obj$$)};$contr_router$$.updating=async($user$$,$data$$,$obj$$,$next$$)=>{$data$$.details||($data$$.details=$obj$$.details);if("10"==$data$$.trang_thai&&0>["LCT","0","1"].indexOf($obj$$.trang_thai)&&$user$$.email===$obj$$.user_created)return $next$$("Kh\u00f4ng th\u1ec3 hu\u1ef7 \u0111\u01a1n h\u00e0ng n\u00e0y");$data$$.da_chuyen_hoa_hong=$obj$$.da_chuyen_hoa_hong;$data$$.da_chuyen_hoa_hong_gt=
130
- $obj$$.da_chuyen_hoa_hong_gt;await $data$$.details.asyncJoinModel2($user$$.current_id_app,dmvt,{where:"ma_vt",fields:["combo"]});$obj$$.details.forEach($detail$$=>{$detail$$.combo&&0<$detail$$.combo.length&&($detail$$.combo=$detail$$.combo.map($item$$=>{$item$$=$item$$.toObject?$item$$.toObject():{...$item$$};$item$$.sl_xuat*=$detail$$.sl_xuat;$item$$.tien_xuat=$item$$.tien_xuat_nt=$item$$.sl_xuat*($item$$.gia_von_nt||0);$item$$.tien_hang=$item$$.tien_hang_nt=$item$$.sl_xuat*($item$$.gia_ban_nt||
131
- 0);$item$$.tien_ck=$item$$.tien_ck_nt=$item$$.sl_xuat*($item$$.tien_ck_nt||0);$item$$.tien=$item$$.tien_nt=$item$$.tien_hang_nt-($item$$.tien_ck_nt||0);return $item$$}))});$data$$.pt_thanh_toan&&$data$$.pt_thanh_toan!=$obj$$.pt_thanh_toan&&($data$$.virtual_payment_client_url="",$data$$.payment_service="",$data$$.payment_id="");$data$$.evouchers=$data$$.evouchers||$obj$$.evouchers||[];valid($user$$,$data$$,async $error$$=>{if($error$$)return $next$$($error$$);if(($obj$$.paymentByPoints||0)!==($data$$.paymentByPoints||
132
- 0))return $next$$("B\u1ea1n kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt s\u1ed1 \u0111i\u1ec3m thanh to\u00e1n.");await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":buy"});$next$$(null,$data$$,$obj$$)},$obj$$)};$contr_router$$.updated=async function($amount$jscomp$6_evouchers_user$$,$obj$$,$next$$){if(!$obj$$.virtual_payment_client_url&&("1"===$obj$$.trang_thai||"0"===$obj$$.trang_thai||"LCT"===$obj$$.trang_thai)){if($obj$$.pt_thanh_toan&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan))try{var $pt_thanh_toan$jscomp$1_pt_thanh_toan$$=
133
- await global.getModel("ptthanhtoan").findOne({_id:$obj$$.pt_thanh_toan});if($pt_thanh_toan$jscomp$1_pt_thanh_toan$$.payment_service){var $app_paymentServiceModel$$=global.getModel($pt_thanh_toan$jscomp$1_pt_thanh_toan$$.payment_service);$obj$$.amount=$obj$$.t_tt_nt-($obj$$.tien_paymentByPoints||0);if($obj$$.amount&&$app_paymentServiceModel$$.createVirtualPaymentClientURL){var $memo$jscomp$4_virtual_payment_client_url$$=await $app_paymentServiceModel$$.createVirtualPaymentClientURL($obj$$,$amount$jscomp$6_evouchers_user$$.clientIp,
134
- $pt_thanh_toan$jscomp$1_pt_thanh_toan$$);$obj$$.virtual_payment_client_url=$memo$jscomp$4_virtual_payment_client_url$$;$obj$$.payment_service=$pt_thanh_toan$jscomp$1_pt_thanh_toan$$.payment_service;$obj$$.payment_id=((await $app_paymentServiceModel$$.findOne({$or:[{id_ct:$obj$$._id.toString()},{request_id:$obj$$._id.toString()},{order_id:$obj$$._id.toString()}]})||{})._id||"").toString()}else $obj$$.virtual_payment_client_url="",$obj$$.payment_service="",$obj$$.payment_id=""}else $obj$$.virtual_payment_client_url=
135
- ""}catch($e$$){return console.error($e$$),$next$$("Error create Virtual Payment ClientURL:"+($e$$.message||$e$$.error||$e$$))}else $obj$$.virtual_payment_client_url="";model.findOneAndUpdate({_id:$obj$$._id},{virtual_payment_client_url:$obj$$.virtual_payment_client_url,payment_id:$obj$$.payment_id,payment_service:$obj$$.payment_service},$e$$=>{$e$$&&console.log("error create Virtual Payment ClientURL",$e$$.message)})}await Evoucher.updateMany({id_ct_used:$obj$$._id.toString()},{id_ct_used:null});
136
- $amount$jscomp$6_evouchers_user$$=await Evoucher.find({id_ct_useds:$obj$$._id.toString()});await Promise.all($amount$jscomp$6_evouchers_user$$.map($e$$=>deleteEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));if("9"===$obj$$.trang_thai||"10"===$obj$$.trang_thai){if(await transaction.deleteTrans({id_ct:$obj$$._id.toString()}),await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng"),await transaction.deleteTrans({id_ct:$obj$$._id.toString()+
137
- ":buy"}),"10"===$obj$$.trang_thai&&$obj$$.payment_id&&global.mongoose.Types.ObjectId.isValid($obj$$.payment_id)&&"5"===$obj$$.trang_thai_tt&&$obj$$.virtual_payment_client_url&&$obj$$.pt_thanh_toan&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan)&&($pt_thanh_toan$jscomp$1_pt_thanh_toan$$=await global.getModel("ptthanhtoan").findOne({_id:$obj$$.pt_thanh_toan}),"assrequest"==$pt_thanh_toan$jscomp$1_pt_thanh_toan$$.payment_service&&($amount$jscomp$6_evouchers_user$$=$obj$$.t_tt_nt-($obj$$.tien_paymentByPoints||
138
- 0))))if($pt_thanh_toan$jscomp$1_pt_thanh_toan$$=await global.getModel($pt_thanh_toan$jscomp$1_pt_thanh_toan$$.payment_service).findOne({_id:$obj$$.payment_id}),$app_paymentServiceModel$$=await App.findOne({_id:$obj$$.id_app}),$app_paymentServiceModel$$.wallet_address&&$app_paymentServiceModel$$.wallet_token&&$pt_thanh_toan$jscomp$1_pt_thanh_toan$$&&"1"==$pt_thanh_toan$jscomp$1_pt_thanh_toan$$.trang_thai){$memo$jscomp$4_virtual_payment_client_url$$="Tr\u1ea3 l\u1ea1i ti\u1ec1n cho \u0111\u01a1n h\u00e0ng "+
139
- $pt_thanh_toan$jscomp$1_pt_thanh_toan$$.order_id;let $denom$$=$pt_thanh_toan$jscomp$1_pt_thanh_toan$$.denom;try{await blockchainconnect.spend($obj$$.id_app,$app_paymentServiceModel$$.wallet_token,$app_paymentServiceModel$$.wallet_address,$pt_thanh_toan$jscomp$1_pt_thanh_toan$$.sender_address,{amount:$amount$jscomp$6_evouchers_user$$,denom:$denom$$,memo:$memo$jscomp$4_virtual_payment_client_url$$}),await model.updateOne({_id:$obj$$._id},{trang_thai_tt:9})}catch($e$$){console.error("Kh\u00f4ng th\u1ec3 tr\u1ea3 ti\u1ec1n cho \u0111\u01a1n h\u00e0ng",
140
- $e$$)}}}else await createTransactionPayment($obj$$),createTransactionBonus($obj$$),$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>updateEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$next$$(null,$obj$$)};$contr_router$$.deleting=function($user$$,$obj$$,$next$$){$next$$(null,$obj$$)};$contr_router$$.deleted=async function($user$$,$obj$$,$next$$){await transaction.deleteTrans({id_ct:$obj$$._id.toString()});await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng");
141
- await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":buy"});$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>deleteEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$next$$(null,$obj$$)};$contr_router$$.view=function($user$$,$items$$,$fn$$){async.series({app:function($callback$$){$items$$.filter($item$$=>$item$$.id_app).joinModel2(null,App,[{where:{id_app:"_id"},fields:{name_app:"name"}}],function(){$callback$$()})},kh:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kh).joinModel2(null,
142
- customer,[{where:$item$$=>({id_app:$item$$.id_app,ma_kh:$item$$.ma_kh}),fields:"ten_kh"}],function(){$callback$$()})},nhan_vien_giao_hang:function($callback$$){$items$$.filter($item$$=>$item$$.nhan_vien_giao_hang).joinModel2(null,customer,[{where:{nhan_vien_giao_hang:"ma_kh"},fields:[{ten_nhan_vien_giao_hang:"ten_kh"}]}],function(){$callback$$()})},nv_giao_hang:function($callback$$){$items$$.filter($item$$=>$item$$.user_nv_giao_hang).joinModel2(null,User,{where:{user_nv_giao_hang:"email"},fields:{ten_nv_giao_hang:"name"}},
143
- function(){$callback$$()})},kho:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kho).joinModel2(null,dmkho,[{where:$item$$=>({id_app:$item$$.id_app,ma_kho:$item$$.ma_kho}),fields:["ten_kho",{tk_cn_kho:"tk_cn"}]}],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$$()})},ptthanhtoan:function($callback$$){$items$$.filter($item$$=>
144
- $item$$.pt_thanh_toan).joinModel2(null,ptthanhtoan,[{where:$item$$=>({_id:$item$$.pt_thanh_toan,id_app:$item$$.id_app}),fields:[{ten_pt_thanh_toan:"ten"},{tk_cn_thanhtoan:"tk_cn"}]}],function(){$callback$$()})},pt1:function($callback$$){$items$$.joinModel2(null,pt1,[{where:$item$$=>({id_app:$item$$.id_app,id_so1:"_id"}),fields:[{id_pt1:"_id"},{so_ct_pt1:"so_ct"},{ma_ct_pt1:"ma_ct"},{ngay_ct_pt1:"ngay_ct"}]}],function(){$callback$$()})},t_tien:function($callback$$){$items$$.filter($item$$=>$item$$.details).forEach(function($r$$){$r$$.tien_phi_vc=
145
- $r$$.tien_phi_vc||0;$r$$.tien_freeship=$r$$.tien_freeship||0;$r$$.details?($r$$.t_sl=$r$$.details.csum("sl_xuat"),$r$$.t_tien_hang=$r$$.details.csum("tien_hang"),$r$$.t_tien_hang_nt=$r$$.details.csum("tien_hang_nt"),$r$$.t_tien=$r$$.t_tien_hang-$r$$.details.csum("tien_ck"),$r$$.t_tien_nt=$r$$.t_tien_hang_nt-$r$$.details.csum("tien_ck_nt"),$r$$.t_ck_nt=$r$$.t_ck=$r$$.tien_ck_hd+($r$$.tien_evoucher||0),$r$$.tien_hoa_hong=$r$$.details.csum("tien_hoa_hong"),$r$$.tien_hoa_hong_gt=$r$$.details.csum("tien_hoa_hong_gt"),
146
- $r$$.tien_hoa_hong_ctv=$r$$.details.csum("tien_hoa_hong_ctv"),$r$$.tien_hoa_hong_ql=$r$$.details.csum("tien_hoa_hong_ql")):($r$$.t_sl=0,$r$$.t_tien_hang=0,$r$$.t_tien_hang_nt=0,$r$$.t_ck=0,$r$$.t_ck_nt=0,$r$$.t_tien=$r$$.t_tien_hang,$r$$.t_tien_nt=$r$$.t_tien_hang_nt);$r$$.ctcpbhs?($r$$.t_cp_cpb_nt=$r$$.ctcpbhs.csum("tien_cp_nt"),$r$$.t_cp_cpb=$r$$.ctcpbhs.csum("tien_cp")):($r$$.t_cp_cpb_nt=0,$r$$.t_cp_cpb=0);$r$$.t_tt=$r$$.t_tt_nt=Math.max(0,$r$$.t_tien_nt+$r$$.t_cp_cpb_nt-$r$$.t_ck_nt-($r$$.tt_tien_thuong||
147
- 0)+($r$$.tien_phi_vc||0)-($r$$.tien_freeship||0))});$callback$$()},details_vt:function($callback$$){async.each($items$$,function($r$$,$callback1$$){const $details$$=$r$$.details;if(!$details$$)return $callback1$$();$details$$.joinModel2(null,dmvt,[{where:$item$$=>({id_app:$r$$.id_app,ma_vt:$item$$.ma_vt}),fields:"ten_vt ten_vt_eng picture chieu_cao chieu_rong chieu_sau trong_luong".split(" ")}],function(){$callback1$$()})},function(){$callback$$()})},details_tt1:function($callback$$){async.mapSeries($items$$,
148
- function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_tt1).joinModel2(null,dmtt,[{where:$item$$=>({id_app:$r$$.id_app,ma_vt:$item$$.ma_vt,ma_tt1:$item$$.ma_tt1}),setFields:($item$$,$ref$$)=>{$item$$.ten_vt=$item$$.ten_vt+" - "+$ref$$.ten_tt}}],function(){$callback1$$()})},function(){$callback$$()})},details_dt:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){const $details$$=$r$$.details;if(!$details$$)return $callback1$$();$details$$.filter($item$$=>
149
- $item$$.ma_dt).joinModel2(null,dmdt,[{where:$item$$=>({id_app:$r$$.id_app,ma_dt:$item$$.ma_dt}),fields:["ten_dt"]}],function(){$callback1$$()})},function(){$callback$$()})},details_contract:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){const $details$$=$r$$.details;if(!$details$$)return $callback1$$();$details$$.filter($item$$=>$item$$.ma_hd).joinModel2(null,contract,[{where:$item$$=>({id_app:$r$$.id_app,so_hd:$item$$.ma_hd}),fields:["ten_hd"]}],function(){$callback1$$()})},
150
- function(){$callback$$()})},details_phi:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){const $details$$=$r$$.details;if(!$details$$)return $callback1$$();$details$$.filter($item$$=>$item$$.ma_phi).joinModel2(null,dmphi,[{where:$item$$=>({id_app:$r$$.id_app,ma_phi:$item$$.ma_phi}),fields:["ten_phi"]}],function(){$callback1$$()})},function(){$callback$$()})},details_cpbh:function($callback$$){async.each($items$$,function($r$$,$callback1$$){let $ctcpbhs$$=$r$$.ctcpbhs;if(!$ctcpbhs$$)return $callback1$$();
151
- $ctcpbhs$$?$ctcpbhs$$.filter($item$$=>$item$$.ma_cp).joinModel2(null,dmcpmh,[{where:$item$$=>({id_app:$r$$.id_app,ma_cp:$item$$.ma_cp}),fields:["ten_cp"]}],function(){$callback1$$()}):$callback1$$()},function(){$callback$$()})}},function(){$fn$$(null,$items$$)})}};
98
+ fields:["combo","ma_thue","gia_mua"]});$obj$$.details.forEach($detail$$=>{$detail$$.combo&&0<$detail$$.combo.length&&($detail$$.combo=$detail$$.combo.map($item$$=>{$item$$=$item$$.toObject?$item$$.toObject():{...$item$$};$item$$.sl_xuat*=$detail$$.sl_xuat;$item$$.tien_xuat=$item$$.tien_xuat_nt=$item$$.sl_xuat*($item$$.gia_von_nt||0);$item$$.tien_hang=$item$$.tien_hang_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$$.tien=
99
+ $item$$.tien_nt=$item$$.tien_hang_nt-($item$$.tien_ck_nt||0);return $item$$}))});valid($user$$,$obj$$,async $error$$=>{if($error$$)return $next$$($error$$);if(!$obj$$.paymentByPoints)return $next$$(null,$obj$$);try{if(await getPointBalance($user$$.current_id_app,$obj$$.of_user||$user$$.email)<$obj$$.paymentByPoints)return $next$$("B\u1ea1n kh\u00f4ng c\u00f3 \u0111\u1ee7 \u0111i\u1ec3m \u0111\u1ec3 th\u1ef1c hi\u1ec7n giao d\u1ecbch n\u00e0y.");$next$$(null,$obj$$)}catch($e$$){$next$$($e$$.message)}})};
100
+ $contr_router$$.created=async function($user$$,$obj$$,$next$$){if($obj$$.pt_thanh_toan&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan))try{const $pt_thanh_toan$$=await global.getModel("ptthanhtoan").findOne({_id:$obj$$.pt_thanh_toan});if($pt_thanh_toan$$.payment_service){let $paymentServiceModel$$=global.getModel($pt_thanh_toan$$.payment_service);$obj$$.amount=$obj$$.t_tt_nt-($obj$$.tien_paymentByPoints||0);if($obj$$.amount&&$paymentServiceModel$$.createVirtualPaymentClientURL){let $virtual_payment_client_url$$=
101
+ await $paymentServiceModel$$.createVirtualPaymentClientURL($obj$$,$user$$.clientIp,$pt_thanh_toan$$);$obj$$.virtual_payment_client_url=$virtual_payment_client_url$$;$obj$$.payment_service=$pt_thanh_toan$$.payment_service;$obj$$.payment_id=((await $paymentServiceModel$$.findOne({$or:[{id_ct:$obj$$._id.toString()},{request_id:$obj$$._id.toString()},{order_id:$obj$$._id.toString()}]})||{})._id||"").toString()}else $obj$$.virtual_payment_client_url="",$obj$$.payment_service="",$obj$$.payment_id=""}else $obj$$.virtual_payment_client_url=
102
+ ""}catch($e$$){return console.error($e$$),$next$$("Kh\u00f4ng tao li\u00ean k\u1ebft thanh to\u00e1n:"+($e$$.message||$e$$.error||$e$$))}else console.log("Chua nhap phuong thuc thanh toan"),$obj$$.virtual_payment_client_url="";model.findOneAndUpdate({_id:$obj$$._id},{virtual_payment_client_url:$obj$$.virtual_payment_client_url,payment_id:$obj$$.payment_id,payment_service:$obj$$.payment_service},$e$$=>{$e$$&&(console.error($e$$),console.log("error create Virtual Payment ClientURL",$e$$.message))});
103
+ await createTransactionPayment($obj$$);await createTransactionBonus($obj$$);$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>updateEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$next$$(null,$obj$$)};$contr_router$$.updating=async($user$$,$data$$,$obj$$,$next$$)=>{$data$$.details||($data$$.details=$obj$$.details);if("10"==$data$$.trang_thai&&0>["LCT","0","1"].indexOf($obj$$.trang_thai)&&$user$$.email===$obj$$.user_created)return $next$$("Kh\u00f4ng th\u1ec3 hu\u1ef7 \u0111\u01a1n h\u00e0ng n\u00e0y");
104
+ $data$$.da_chuyen_hoa_hong=$obj$$.da_chuyen_hoa_hong;$data$$.da_chuyen_hoa_hong_gt=$obj$$.da_chuyen_hoa_hong_gt;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)?($item$$.gia_mua||($item$$.gia_mua=$ref$$.gia_mua),$item$$.ma_thue||($item$$.ma_thue=$ref$$.ma_thue)):($item$$.gia_mua=$ref$$.gia_mua,$item$$.ma_thue=$ref$$.ma_thue)}});await $data$$.details.asyncJoinModel2($obj$$.id_app,
105
+ "vat",{where:"ma_thue",fields:["thue_suat","tk_thue_co","tk_thue_co_treo"]});$data$$.details.forEach($detail$$=>{$detail$$.combo&&0<$detail$$.combo.length&&($detail$$.combo=$detail$$.combo.map($item$$=>{$item$$=$item$$.toObject?$item$$.toObject():{...$item$$};$item$$.sl_xuat*=$detail$$.sl_xuat;$item$$.tien_xuat=$item$$.tien_xuat_nt=$item$$.sl_xuat*($item$$.gia_von_nt||0);$item$$.tien_hang=$item$$.tien_hang_nt=$item$$.sl_xuat*($item$$.gia_ban_nt||0);$item$$.tien_ck=$item$$.tien_ck_nt=$item$$.sl_xuat*
106
+ ($item$$.tien_ck_nt||0);$item$$.tien=$item$$.tien_nt=$item$$.tien_hang_nt-($item$$.tien_ck_nt||0);return $item$$}))});$data$$.pt_thanh_toan&&$data$$.pt_thanh_toan!=$obj$$.pt_thanh_toan&&($data$$.virtual_payment_client_url="",$data$$.payment_service="",$data$$.payment_id="");$data$$.evouchers=$data$$.evouchers||$obj$$.evouchers||[];valid($user$$,$data$$,async $error$$=>{if($error$$)return $next$$($error$$);if(($obj$$.paymentByPoints||0)!==($data$$.paymentByPoints||0))return $next$$("B\u1ea1n kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt s\u1ed1 \u0111i\u1ec3m thanh to\u00e1n.");
107
+ await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":buy"});$next$$(null,$data$$,$obj$$)},$obj$$)};$contr_router$$.updated=async function($amount$jscomp$6_evouchers_user$$,$obj$$,$next$$){if(!$obj$$.virtual_payment_client_url&&("1"===$obj$$.trang_thai||"0"===$obj$$.trang_thai||"LCT"===$obj$$.trang_thai)){if($obj$$.pt_thanh_toan&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan))try{var $pt_thanh_toan$jscomp$1_pt_thanh_toan$$=await global.getModel("ptthanhtoan").findOne({_id:$obj$$.pt_thanh_toan});
108
+ if($pt_thanh_toan$jscomp$1_pt_thanh_toan$$.payment_service){var $app_paymentServiceModel$$=global.getModel($pt_thanh_toan$jscomp$1_pt_thanh_toan$$.payment_service);$obj$$.amount=$obj$$.t_tt_nt-($obj$$.tien_paymentByPoints||0);if($obj$$.amount&&$app_paymentServiceModel$$.createVirtualPaymentClientURL){var $memo$jscomp$4_virtual_payment_client_url$$=await $app_paymentServiceModel$$.createVirtualPaymentClientURL($obj$$,$amount$jscomp$6_evouchers_user$$.clientIp,$pt_thanh_toan$jscomp$1_pt_thanh_toan$$);
109
+ $obj$$.virtual_payment_client_url=$memo$jscomp$4_virtual_payment_client_url$$;$obj$$.payment_service=$pt_thanh_toan$jscomp$1_pt_thanh_toan$$.payment_service;$obj$$.payment_id=((await $app_paymentServiceModel$$.findOne({$or:[{id_ct:$obj$$._id.toString()},{request_id:$obj$$._id.toString()},{order_id:$obj$$._id.toString()}]})||{})._id||"").toString()}else $obj$$.virtual_payment_client_url="",$obj$$.payment_service="",$obj$$.payment_id=""}else $obj$$.virtual_payment_client_url=""}catch($e$$){return console.error($e$$),
110
+ $next$$("Error create Virtual Payment ClientURL:"+($e$$.message||$e$$.error||$e$$))}else $obj$$.virtual_payment_client_url="";model.findOneAndUpdate({_id:$obj$$._id},{virtual_payment_client_url:$obj$$.virtual_payment_client_url,payment_id:$obj$$.payment_id,payment_service:$obj$$.payment_service},$e$$=>{$e$$&&console.log("error create Virtual Payment ClientURL",$e$$.message)})}await Evoucher.updateMany({id_ct_used:$obj$$._id.toString()},{id_ct_used:null});$amount$jscomp$6_evouchers_user$$=await Evoucher.find({id_ct_useds:$obj$$._id.toString()});
111
+ await Promise.all($amount$jscomp$6_evouchers_user$$.map($e$$=>deleteEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));if("9"===$obj$$.trang_thai||"10"===$obj$$.trang_thai){if(await transaction.deleteTrans({id_ct:$obj$$._id.toString()}),await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng"),await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":buy"}),"10"===$obj$$.trang_thai&&$obj$$.payment_id&&global.mongoose.Types.ObjectId.isValid($obj$$.payment_id)&&
112
+ "5"===$obj$$.trang_thai_tt&&$obj$$.virtual_payment_client_url&&$obj$$.pt_thanh_toan&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan)&&($pt_thanh_toan$jscomp$1_pt_thanh_toan$$=await global.getModel("ptthanhtoan").findOne({_id:$obj$$.pt_thanh_toan}),"assrequest"==$pt_thanh_toan$jscomp$1_pt_thanh_toan$$.payment_service&&($amount$jscomp$6_evouchers_user$$=$obj$$.t_tt_nt-($obj$$.tien_paymentByPoints||0))))if($pt_thanh_toan$jscomp$1_pt_thanh_toan$$=await global.getModel($pt_thanh_toan$jscomp$1_pt_thanh_toan$$.payment_service).findOne({_id:$obj$$.payment_id}),
113
+ $app_paymentServiceModel$$=await App.findOne({_id:$obj$$.id_app}),$app_paymentServiceModel$$.wallet_address&&$app_paymentServiceModel$$.wallet_token&&$pt_thanh_toan$jscomp$1_pt_thanh_toan$$&&"1"==$pt_thanh_toan$jscomp$1_pt_thanh_toan$$.trang_thai){$memo$jscomp$4_virtual_payment_client_url$$="Tr\u1ea3 l\u1ea1i ti\u1ec1n cho \u0111\u01a1n h\u00e0ng "+$pt_thanh_toan$jscomp$1_pt_thanh_toan$$.order_id;let $denom$$=$pt_thanh_toan$jscomp$1_pt_thanh_toan$$.denom;try{await blockchainconnect.spend($obj$$.id_app,
114
+ $app_paymentServiceModel$$.wallet_token,$app_paymentServiceModel$$.wallet_address,$pt_thanh_toan$jscomp$1_pt_thanh_toan$$.sender_address,{amount:$amount$jscomp$6_evouchers_user$$,denom:$denom$$,memo:$memo$jscomp$4_virtual_payment_client_url$$}),await model.updateOne({_id:$obj$$._id},{trang_thai_tt:9})}catch($e$$){console.error("Kh\u00f4ng th\u1ec3 tr\u1ea3 ti\u1ec1n cho \u0111\u01a1n h\u00e0ng",$e$$)}}}else await createTransactionPayment($obj$$),createTransactionBonus($obj$$),$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>
115
+ updateEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$next$$(null,$obj$$)};$contr_router$$.deleting=function($user$$,$obj$$,$next$$){$next$$(null,$obj$$)};$contr_router$$.deleted=async function($user$$,$obj$$,$next$$){await transaction.deleteTrans({id_ct:$obj$$._id.toString()});await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng");await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":buy"});$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>
116
+ deleteEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$next$$(null,$obj$$)};$contr_router$$.view=function($user$$,$items$$,$fn$$){async.series({app:function($callback$$){$items$$.filter($item$$=>$item$$.id_app).joinModel2(null,App,[{where:{id_app:"_id"},fields:{name_app:"name"}}],function(){$callback$$()})},kh:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kh).joinModel2(null,customer,[{where:$item$$=>({id_app:$item$$.id_app,ma_kh:$item$$.ma_kh}),fields:"ten_kh"}],function(){$callback$$()})},
117
+ nhan_vien_giao_hang:function($callback$$){$items$$.filter($item$$=>$item$$.nhan_vien_giao_hang).joinModel2(null,customer,[{where:{nhan_vien_giao_hang:"ma_kh"},fields:[{ten_nhan_vien_giao_hang:"ten_kh"}]}],function(){$callback$$()})},nv_giao_hang:function($callback$$){$items$$.filter($item$$=>$item$$.user_nv_giao_hang).joinModel2(null,User,{where:{user_nv_giao_hang:"email"},fields:{ten_nv_giao_hang:"name"}},function(){$callback$$()})},kho:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kho).joinModel2(null,
118
+ dmkho,[{where:$item$$=>({id_app:$item$$.id_app,ma_kho:$item$$.ma_kho}),fields:["ten_kho",{tk_cn_kho:"tk_cn"}]}],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$$()})},ptthanhtoan:function($callback$$){$items$$.filter($item$$=>$item$$.pt_thanh_toan).joinModel2(null,ptthanhtoan,[{where:$item$$=>({_id:$item$$.pt_thanh_toan,
119
+ id_app:$item$$.id_app}),fields:[{ten_pt_thanh_toan:"ten"},{tk_cn_thanhtoan:"tk_cn"}]}],function(){$callback$$()})},pt1:function($callback$$){$items$$.joinModel2(null,pt1,[{where:$item$$=>({id_app:$item$$.id_app,id_so1:"_id"}),fields:[{id_pt1:"_id"},{so_ct_pt1:"so_ct"},{ma_ct_pt1:"ma_ct"},{ngay_ct_pt1:"ngay_ct"}]}],function(){$callback$$()})},t_tien:function($callback$$){$items$$.filter($item$$=>$item$$.details).forEach(function($r$$){$r$$.tien_phi_vc=$r$$.tien_phi_vc||0;$r$$.tien_freeship=$r$$.tien_freeship||
120
+ 0;$r$$.details?($r$$.t_sl=$r$$.details.csum("sl_xuat"),$r$$.t_tien_hang=$r$$.details.csum("tien_hang"),$r$$.t_tien_hang_nt=$r$$.details.csum("tien_hang_nt"),$r$$.t_tien=$r$$.t_tien_hang-$r$$.details.csum("tien_ck"),$r$$.t_tien_nt=$r$$.t_tien_hang_nt-$r$$.details.csum("tien_ck_nt"),$r$$.t_ck_nt=$r$$.t_ck=$r$$.tien_ck_hd+($r$$.tien_evoucher||0),$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"),
121
+ $r$$.tien_hoa_hong_ql=$r$$.details.csum("tien_hoa_hong_ql")):($r$$.t_sl=0,$r$$.t_tien_hang=0,$r$$.t_tien_hang_nt=0,$r$$.t_ck=0,$r$$.t_ck_nt=0,$r$$.t_tien=$r$$.t_tien_hang,$r$$.t_tien_nt=$r$$.t_tien_hang_nt);$r$$.ctcpbhs?($r$$.t_cp_cpb_nt=$r$$.ctcpbhs.csum("tien_cp_nt"),$r$$.t_cp_cpb=$r$$.ctcpbhs.csum("tien_cp")):($r$$.t_cp_cpb_nt=0,$r$$.t_cp_cpb=0);$r$$.t_tien_ct_nt=$r$$.details.csum("tien_ct_nt");$r$$.t_tien_ct=$r$$.details.csum("tien_ct");$r$$.t_thue_nt=$r$$.details.csum("tien_thue_nt");$r$$.t_thue=
122
+ $r$$.details.csum("tien_thue");$r$$.t_tt=$r$$.t_tt_nt=Math.max(0,$r$$.t_tien_ct_nt+$r$$.t_thue_nt+$r$$.t_cp_cpb_nt-$r$$.t_ck_nt-($r$$.tt_tien_thuong||0)+($r$$.tien_phi_vc||0)-($r$$.tien_freeship||0))});$callback$$()},details_vt:function($callback$$){async.each($items$$,function($r$$,$callback1$$){const $details$$=$r$$.details;if(!$details$$)return $callback1$$();$details$$.joinModel2(null,dmvt,[{where:$item$$=>({id_app:$r$$.id_app,ma_vt:$item$$.ma_vt}),fields:"ten_vt ten_vt_eng picture chieu_cao chieu_rong chieu_sau trong_luong".split(" ")}],
123
+ function(){$callback1$$()})},function(){$callback$$()})},details_tt1:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_tt1).joinModel2(null,dmtt,[{where:$item$$=>({id_app:$r$$.id_app,ma_vt:$item$$.ma_vt,ma_tt1:$item$$.ma_tt1}),setFields:($item$$,$ref$$)=>{$item$$.ten_vt=$item$$.ten_vt+" - "+$ref$$.ten_tt}}],function(){$callback1$$()})},function(){$callback$$()})},details_dt:function($callback$$){async.mapSeries($items$$,function($r$$,
124
+ $callback1$$){const $details$$=$r$$.details;if(!$details$$)return $callback1$$();$details$$.filter($item$$=>$item$$.ma_dt).joinModel2(null,dmdt,[{where:$item$$=>({id_app:$r$$.id_app,ma_dt:$item$$.ma_dt}),fields:["ten_dt"]}],function(){$callback1$$()})},function(){$callback$$()})},details_contract:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){const $details$$=$r$$.details;if(!$details$$)return $callback1$$();$details$$.filter($item$$=>$item$$.ma_hd).joinModel2(null,contract,
125
+ [{where:$item$$=>({id_app:$r$$.id_app,so_hd:$item$$.ma_hd}),fields:["ten_hd"]}],function(){$callback1$$()})},function(){$callback$$()})},details_phi:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){const $details$$=$r$$.details;if(!$details$$)return $callback1$$();$details$$.filter($item$$=>$item$$.ma_phi).joinModel2(null,dmphi,[{where:$item$$=>({id_app:$r$$.id_app,ma_phi:$item$$.ma_phi}),fields:["ten_phi"]}],function(){$callback1$$()})},function(){$callback$$()})},details_cpbh:function($callback$$){async.each($items$$,
126
+ function($r$$,$callback1$$){let $ctcpbhs$$=$r$$.ctcpbhs;if(!$ctcpbhs$$)return $callback1$$();$ctcpbhs$$?$ctcpbhs$$.filter($item$$=>$item$$.ma_cp).joinModel2(null,dmcpmh,[{where:$item$$=>({id_app:$r$$.id_app,ma_cp:$item$$.ma_cp}),fields:["ten_cp"]}],function(){$callback1$$()}):$callback1$$()},function(){$callback$$()})}},function(){$fn$$(null,$items$$)})}};
@@ -9,7 +9,7 @@ $d$jscomp$2_detail$$.tien_nt=$d$jscomp$2_detail$$.tien_hang_nt;$d$jscomp$2_detai
9
9
  $d$jscomp$3_detail$$.tien_ck_nt;$d$jscomp$3_detail$$.tien=$d$jscomp$3_detail$$.tien_ck;$details$$.push($d$jscomp$3_detail$$)});$obj$$.tien_ck_hd&&($detail_tt$$={},$detail_tt$$.tk_no=$option$$.tk_ck,$detail_tt$$.tk_co=$obj$$.tien_thu&&$obj$$.t_tt==$obj$$.tien_thu?$option$$.tk_tien:$option$$.tk_cn,$detail_tt$$.tien_nt=$obj$$.tien_ck_hd,$detail_tt$$.tien=$detail_tt$$.tien_nt,$detail_tt$$.ma_kh=$option$$.ma_kh,$details$$.push($detail_tt$$));(new PostSocai($obj$$,$details$$)).run(function($e$$,$rs$$){$callback$$($e$$,
10
10
  $rs$$)})})})}},function($e$$,$rs$$){$fn$$($e$$,$rs$$)})};const $valid$$=async function($user$$,$obj$$,$next$$){try{if($obj$$.pt_thanh_toan&&(await ptthanhtoan.getInfo($obj$$.id_app,{_id:$obj$$.pt_thanh_toan})).thanh_toan_bang_diem){var $he_so_qd_i$$=await currency.getRate($obj$$.id_app,$obj$$.ma_nt);$he_so_qd_i$$&&($obj$$.tien_paymentByPoints=$obj$$.details.map($d$$=>($d$$.tien_hang_nt||0)-($d$$.tien_ck_nt||0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0),$obj$$.ctcpbhs&&($obj$$.tien_paymentByPoints+=$obj$$.ctcpbhs.csum("tien_cp_nt")),
11
11
  $obj$$.paymentByPoints=$obj$$.tien_paymentByPoints/$he_so_qd_i$$)}}catch($e$$){return $next$$($e$$.message)}for($he_so_qd_i$$=0;$he_so_qd_i$$<$obj$$.details.length;$he_so_qd_i$$++){const $detail$$=$obj$$.details[$he_so_qd_i$$];$detail$$.line=$he_so_qd_i$$;"VND"===$obj$$.ma_nt&&($detail$$.tien=$detail$$.tien_nt,$detail$$.tien_hang=$detail$$.tien_hang_nt,$detail$$.tien_ck=$detail$$.tien_ck_nt,$detail$$.gia_ban=$detail$$.gia_ban_nt)}$obj$$.ma_dvcs?$next$$(null,$obj$$):dvcs.findOne({id_app:$user$$.current_id_app},
12
- {_id:1},function($error$$,$dv$$){return $error$$?$next$$($error$$):$dv$$?($obj$$.ma_dvcs=$dv$$._id.toString(),$next$$(null,$obj$$)):$next$$("C\u00f4ng ty/c\u1eeda h\u00e0ng n\u00e0y ch\u01b0a c\u00f3 m\u1ed9t \u0111\u01a1n v\u1ecb c\u01a1 s\u1edf n\u00e0o")})};$contr_router$$.creating=function($user$$,$obj$$,$next$$){delete $obj$$.virtual_payment_client_url;$obj$$.details||($obj$$.details=[]);$valid$$($user$$,$obj$$,async $error$$=>{if($error$$)return $next$$($error$$);if(!$obj$$.paymentByPoints)return $next$$(null,
12
+ {_id:1},function($error$$,$dv$$){return $error$$?$next$$($error$$):$dv$$?($obj$$.ma_dvcs=$dv$$._id.toString(),$next$$(null,$obj$$)):$next$$("C\u00f4ng ty/c\u1eeda h\u00e0ng n\u00e0y ch\u01b0a c\u00f3 m\u1ed9t \u0111\u01a1n v\u1ecb c\u01a1 s\u1edf n\u00e0o")})};$contr_router$$.creating=function($user$$,$obj$$,$next$$){$obj$$.virtual_payment_client_url=void 0;$obj$$.details||($obj$$.details=[]);$valid$$($user$$,$obj$$,async $error$$=>{if($error$$)return $next$$($error$$);if(!$obj$$.paymentByPoints)return $next$$(null,
13
13
  $obj$$);if(!$obj$$.ma_kh)return $next$$("Customer is missed");try{if(!$obj$$.sender_email){let $cust$$=await customer.getInfo($obj$$.id_app,{ma_kh:$obj$$.ma_kh});$obj$$.sender_email=$cust$$.of_user}if(!$obj$$.sender_email)return $next$$("To payment by points, you must to sign this voucher");let $balance$$=await getPointBalance($user$$.current_id_app,$obj$$.sender_email);if($balance$$<$obj$$.paymentByPoints)return $next$$(`B\u1ea1n kh\u00f4ng c\u00f3 \u0111\u1ee7 Point \u0111\u1ec3 th\u1ef1c hi\u1ec7n giao d\u1ecbch n\u00e0y. S\u1ed1 d\u01b0 c\u1ee7a b\u1ea1n hi\u1ec7n t\u1ea1i l\u00e0 ${$balance$$} points. H\u00e3y n\u1ea1p th\u00eam ti\u1ec1n v\u00e0o v\u00ed c\u1ee7a b\u1ea1n ho\u1eb7c ch\u1ecdn ph\u01b0\u01a1ng th\u1ee9c thanh to\u00e1n kh\u00e1c`);
14
14
  if($obj$$.id_trans){let $trans$$=await transaction.getTrans($obj$$.id_trans);if(!$trans$$)return $next$$("Transaction is not exists. Please sign this voucher");if(!await transaction.verifyTrans({id_app:$user$$.current_id_app,sender_email:$obj$$.sender_email,receiver_email:$user$$.current_id_app,amount:$obj$$.paymentByPoints},$trans$$))return $next$$("Transaction is invalid. Please sign this voucher again")}else if($obj$$.sender_email===$user$$.email){let $trans$$=await transaction.createTrans({id_app:$obj$$.id_app,
15
15
  sender_email:$obj$$.sender_email,receiver_email:$obj$$.id_app,amount:$obj$$.paymentByPoints,description:`Thanh to\u00e1n cho kho\u00e1 h\u1ecdc ${$obj$$.dien_giai}`,otherData:{ma_ct}});$obj$$.id_trans=$trans$$.id_trans;$next$$(null,$obj$$)}else return $next$$("To payment by points, you must to sign this voucher")}catch($e$$){$next$$($e$$.message)}})};$contr_router$$.created=async function($user$$,$obj$$,$next$$){if($obj$$.id_trans){let $trans$$=await transaction.getTrans($obj$$.id_trans);$trans$$.so_ct=
@@ -31,8 +31,8 @@ $pt$$=$pt$$||{};$pt$$.ma_kh&&($pt$$.tk_tien=$pt$$.tk_cn);console.log("phuong thu
31
31
  $obj$$.ma_kh;const $details$$=[];$obj$$.details.forEach(function($d$jscomp$8_detail$$){$d$jscomp$8_detail$$={...$d$jscomp$8_detail$$};$d$jscomp$8_detail$$.tk_co=$option$$.tk_dt;$d$jscomp$8_detail$$.tk_no=$option$$.tk_tien;$d$jscomp$8_detail$$.ma_kh_co=$obj$$.ma_kh;$d$jscomp$8_detail$$.ma_kh_no=$option$$.ma_kh;$d$jscomp$8_detail$$.tien_nt=$d$jscomp$8_detail$$.tien_hang_nt-($d$jscomp$8_detail$$.tien_ck_nt||0);$d$jscomp$8_detail$$.tien=$d$jscomp$8_detail$$.tien_hang-($d$jscomp$8_detail$$.tien_ck||0);
32
32
  $details$$.push($d$jscomp$8_detail$$)});$obj$$.details.filter($d$$=>$d$$.diem_thuong&&$d$$.tk_km_no&&$d$$.tk_km_co).forEach(function($d$$){let $detail$$={...$d$$};$detail$$.tk_co=$option$$.tk_km_co||$d$$.tk_km_co;$detail$$.tk_no=$option$$.tk_km_no||$d$$.tk_km_no;$detail$$.ma_kh=$obj$$.ma_kh;$detail$$.tien=$detail$$.tien_nt=$detail$$.diem_thuong*$he_so_qd$$;$details$$.push($detail$$)});$obj$$.tt_tien_thuong&&($error$jscomp$2_tt_tt$$={},$error$jscomp$2_tt_tt$$.tk_no=$option$$.tk_cp_bh,$error$jscomp$2_tt_tt$$.tk_co=
33
33
  $option$$.tk_tien,$error$jscomp$2_tt_tt$$.tien_nt=$obj$$.tt_tien_thuong||0,$error$jscomp$2_tt_tt$$.tien=$error$jscomp$2_tt_tt$$.tien_nt,$error$jscomp$2_tt_tt$$.ma_kh_no=$obj$$.ma_kh,$error$jscomp$2_tt_tt$$.ma_kh_co=$option$$.ma_kh,$details$$.push($error$jscomp$2_tt_tt$$));if($obj$$.tien_ck_hd||$obj$$.tien_evoucher)$error$jscomp$2_tt_tt$$={},$error$jscomp$2_tt_tt$$.tk_no=$option$$.tk_ck,$error$jscomp$2_tt_tt$$.tk_co=$option$$.tk_tien,$error$jscomp$2_tt_tt$$.tien_nt=($obj$$.tien_ck_hd||0)+($obj$$.tien_evoucher||
34
- 0),$error$jscomp$2_tt_tt$$.tien=$error$jscomp$2_tt_tt$$.tien_nt,$error$jscomp$2_tt_tt$$.ma_kh_no=$obj$$.ma_kh,$error$jscomp$2_tt_tt$$.ma_kh_co=$option$$.ma_kh,$error$jscomp$2_tt_tt$$.check_balance=!1,$details$$.push($error$jscomp$2_tt_tt$$);(new PostSocai($obj$$,$details$$)).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})})}},function($e$$,$rs$$){$fn$$($e$$,$rs$$)})};$contr_router$$.creating=async function($user$$,$obj$$,$next$$){$obj$$.details||($obj$$.details=[]);delete $obj$$.virtual_payment_client_url;
35
- if(!$obj$$.ma_kh){let $cust$$=await global.getModel("customer").findOne({id_app:$user$$.current_id_app,of_user:$user$$.email},{ma_kh:1,ten_kh:1}).lean();$cust$$&&($obj$$.ma_kh=$cust$$.ma_kh)}valid($user$$,$obj$$,async $error$$=>{if($error$$)return $next$$($error$$);if(!$obj$$.paymentByPoints)return $next$$(null,$obj$$);try{let $detail_buy_coins$$=$obj$$.details.filter($d$$=>$d$$.is_coin&&!$d$$.transferred&&$d$$.wallet_receiver).asyncGroupBy(["ma_vt"],["sl_xuat"]);if(1==$detail_buy_coins$$.length&&
34
+ 0),$error$jscomp$2_tt_tt$$.tien=$error$jscomp$2_tt_tt$$.tien_nt,$error$jscomp$2_tt_tt$$.ma_kh_no=$obj$$.ma_kh,$error$jscomp$2_tt_tt$$.ma_kh_co=$option$$.ma_kh,$error$jscomp$2_tt_tt$$.check_balance=!1,$details$$.push($error$jscomp$2_tt_tt$$);(new PostSocai($obj$$,$details$$)).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})})}},function($e$$,$rs$$){$fn$$($e$$,$rs$$)})};$contr_router$$.creating=async function($user$$,$obj$$,$next$$){$obj$$.details||($obj$$.details=[]);$obj$$.virtual_payment_client_url=
35
+ void 0;if(!$obj$$.ma_kh){let $cust$$=await global.getModel("customer").findOne({id_app:$user$$.current_id_app,of_user:$user$$.email},{ma_kh:1,ten_kh:1}).lean();$cust$$&&($obj$$.ma_kh=$cust$$.ma_kh)}valid($user$$,$obj$$,async $error$$=>{if($error$$)return $next$$($error$$);if(!$obj$$.paymentByPoints)return $next$$(null,$obj$$);try{let $detail_buy_coins$$=$obj$$.details.filter($d$$=>$d$$.is_coin&&!$d$$.transferred&&$d$$.wallet_receiver).asyncGroupBy(["ma_vt"],["sl_xuat"]);if(1==$detail_buy_coins$$.length&&
36
36
  await getWalletBalanceOfApp($user$$.current_id_app,$detail_buy_coins$$[0].ma_vt.toLowerCase())<$detail_buy_coins$$[0].sl_xuat)return $next$$("B\u1ea1n kh\u00f4ng th\u1ec3 n\u1ea1p ti\u1ec1n th\u1eddi gian n\u00e0y. Hay th\u1eed l\u1ea1i sau");if(1<$detail_buy_coins$$.length)return $next$$("M\u1ed7i l\u1ea7n ch\u1ec9 \u0111\u01b0\u1ee3c mua m\u1ed9t lo\u1ea1i coin");if(await getPointBalance($user$$.current_id_app,$user$$.email)<$obj$$.paymentByPoints)return $next$$("B\u1ea1n kh\u00f4ng c\u00f3 \u0111\u1ee7 \u0111i\u1ec3m \u0111\u1ec3 th\u1ef1c hi\u1ec7n giao d\u1ecbch n\u00e0y.");
37
37
  $next$$(null,$obj$$)}catch($e$$){$next$$($e$$.message)}})};$contr_router$$.created=async function($user$$,$obj$$,$next$$){if($obj$$.pt_thanh_toan&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan))try{const $pt_thanh_toan$$=await global.getModel("ptthanhtoan").findOne({_id:$obj$$.pt_thanh_toan});if($pt_thanh_toan$$.payment_service){let $paymentServiceModel$$=global.getModel($pt_thanh_toan$$.payment_service);$obj$$.amount=$obj$$.t_tt_nt-($obj$$.tien_paymentByPoints||0);if($obj$$.amount&&
38
38
  $paymentServiceModel$$.createVirtualPaymentClientURL){let $virtual_payment_client_url$$=await $paymentServiceModel$$.createVirtualPaymentClientURL($obj$$,$user$$.clientIp,$pt_thanh_toan$$);$obj$$.virtual_payment_client_url=$virtual_payment_client_url$$;$obj$$.payment_service=$pt_thanh_toan$$.payment_service;$obj$$.payment_id=((await $paymentServiceModel$$.findOne({$or:[{id_ct:$obj$$._id.toString()},{request_id:$obj$$._id.toString()},{order_id:$obj$$._id.toString()}]})||{})._id||"").toString()}else $obj$$.virtual_payment_client_url=