flexbiz-server 12.2.2 → 12.2.3

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 (57) hide show
  1. package/package.json +2 -2
  2. package/server/app.js +14 -14
  3. package/server/auths/local.js +3 -3
  4. package/server/cluster.js +12 -11
  5. package/server/controllers/controller.js +37 -34
  6. package/server/data/sys/listinfo.js +80395 -78085
  7. package/server/data/sys/reportinfo.js +8826 -8826
  8. package/server/data/sys/trangthai.js +10348 -10229
  9. package/server/libs/getGiaban.js +21 -21
  10. package/server/libs/permission.js +12 -12
  11. package/server/libs/prototypes.js +3 -3
  12. package/server/libs/tinhgiatb.js +16 -19
  13. package/server/models/customer.js +9 -5
  14. package/server/models/dh2.js +9 -7
  15. package/server/models/dmbp.js +7 -4
  16. package/server/models/dmgiaban.js +6 -6
  17. package/server/models/dmhoahonghd.js +5 -5
  18. package/server/models/dmnvt.js +3 -3
  19. package/server/models/dmvt.js +9 -9
  20. package/server/models/ecomcategories.js +2 -2
  21. package/server/models/ecomcategories_cty.js +3 -0
  22. package/server/models/group.js +4 -4
  23. package/server/models/hd2.js +9 -6
  24. package/server/models/listinfo.js +15 -8
  25. package/server/models/originimportid.js +1 -0
  26. package/server/models/so1.js +15 -13
  27. package/server/models/socai.js +3 -1
  28. package/server/models/task.js +4 -4
  29. package/server/models/tontucthoi.js +2 -2
  30. package/server/models/usergroup.js +4 -4
  31. package/server/modules/lists/ls-asskey.js +34 -34
  32. package/server/modules/lists/ls-customer.js +14 -7
  33. package/server/modules/lists/ls-dmbp.js +7 -3
  34. package/server/modules/lists/ls-dmnkh.js +5 -1
  35. package/server/modules/lists/ls-dmnvt.js +5 -5
  36. package/server/modules/lists/ls-dmvt.js +15 -11
  37. package/server/modules/lists/ls-ecomcategories.js +5 -0
  38. package/server/modules/lists/ls-ecomcategories_cty.js +5 -0
  39. package/server/modules/lists/ls-file.js +21 -25
  40. package/server/modules/lists/ls-group.js +5 -1
  41. package/server/modules/lists/ls-introducecode.js +8 -7
  42. package/server/modules/lists/ls-introducer.js +16 -17
  43. package/server/modules/lists/ls-message2.js +8 -7
  44. package/server/modules/lists/ls-message2setting.js +4 -4
  45. package/server/modules/lists/ls-session.js +1 -1
  46. package/server/modules/lists/ls-task.js +18 -18
  47. package/server/modules/lists/ls-usergroup.js +6 -2
  48. package/server/modules/reports/calc-tinhgiatb.js +2 -2
  49. package/server/modules/reports/rp-congviectheonv.js +5 -5
  50. package/server/modules/reports/rp-thnxt.js +4 -3
  51. package/server/modules/reports/rp-thnxt_sl.js +3 -3
  52. package/server/modules/reports/rp-thnxttt.js +3 -3
  53. package/server/modules/vouchers/vo-dh2.js +38 -20
  54. package/server/modules/vouchers/vo-hd2.js +82 -50
  55. package/server/modules/vouchers/vo-so1.js +119 -120
  56. package/server/templates/reset mat khau.html +1 -1
  57. package/server/templates/reset mat khau.pug +1 -3
@@ -1,63 +1,64 @@
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
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"),{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="";if($obj$$.introduce_code){$obj$$.user_gt="";var $intro_intro$jscomp$1_intro$$=
5
- await global.getModel("introducer").findOne({id_app:$obj$$.id_app,introduce_code:$obj$$.introduce_code});$intro_intro$jscomp$1_intro$$&&($obj$$.user_gt=$intro_intro$jscomp$1_intro$$.be_introduced_by)}$obj$$.user_gt&&!$obj$$.introduce_code&&($intro_intro$jscomp$1_intro$$=await global.getModel("introducer").findOne({id_app:$obj$$.id_app,be_introduced_by:$obj$$.user_gt}))&&($obj$$.introduce_code=$intro_intro$jscomp$1_intro$$.introduce_code);!$obj$$.user_gt&&($obj$$.introduce_code="",$intro_intro$jscomp$1_intro$$=
6
- await global.getModel("introducer").findOne({id_app:$obj$$.id_app,be_introduced:$obj$$.user_created}))&&($obj$$.user_gt=$intro_intro$jscomp$1_intro$$.be_introduced_by,$obj$$.introduce_code=$intro_intro$jscomp$1_intro$$.introduce_code);if($obj$$.user_gt&&$obj$$.introduce_code){if($intro_intro$jscomp$1_intro$$=await global.getModel("customer").findOne({id_app:$obj$$.id_app,of_user:$obj$$.user_gt}))$obj$$.ma_kh_hoa_hong_gt=$intro_intro$jscomp$1_intro$$.ma_kh;$intro_intro$jscomp$1_intro$$=$obj$$.details.csum("tien_hang_nt");
7
- var $loi_nhuan_t_ck_nt_t_gv_nt$$=$obj$$.details.csum("tien_ck_nt");$intro_intro$jscomp$1_intro$$=$intro_intro$jscomp$1_intro$$-$loi_nhuan_t_ck_nt_t_gv_nt$$-($obj$$.tien_ck_hd||0);$loi_nhuan_t_ck_nt_t_gv_nt$$=$obj$$.details.csum("tien_xuat_tmp");$loi_nhuan_t_ck_nt_t_gv_nt$$=$intro_intro$jscomp$1_intro$$-$loi_nhuan_t_ck_nt_t_gv_nt$$;var $ckhds_query$$={id_app:$obj$$.id_app,gt_tu:{$lte:$intro_intro$jscomp$1_intro$$},ma_kho:{$in:[void 0,null,"",$obj$$.ma_kho]},doi_tuong:"1",ma_nv:{$in:[void 0,null,"",
8
- $obj$$.ma_nv]}};$ckhds_query$$.$and=[{$or:[{gt_den:{$in:[0,void 0,null]}},{gt_den:{$gte:$intro_intro$jscomp$1_intro$$}}]}];var $ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$=moment($obj$$.ngay_ct).startOf("date").toDate();var $hieu_luc_tu_i_q_ma_kh$$={$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$$.hieu_luc_tu=$hieu_luc_tu_i_q_ma_kh$$;$ckhds_query$$.hieu_luc_den=$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$;$hieu_luc_tu_i_q_ma_kh$$=
9
- {$in:[void 0,null,"",$obj$$.ma_kh]};$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$={$in:[void 0,null,""]};if($obj$$.ma_kh){var $g_kh$jscomp$1_lan_mua_thu$$=await customer.findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh},{nh_kh:1});$g_kh$jscomp$1_lan_mua_thu$$&&$g_kh$jscomp$1_lan_mua_thu$$.nh_kh&&($ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$={$in:[void 0,null,"",$g_kh$jscomp$1_lan_mua_thu$$.nh_kh]});($g_kh$jscomp$1_lan_mua_thu$$=await model.countDocuments({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh,trang_thai:{$in:["5",
10
- "6"]}}))||($g_kh$jscomp$1_lan_mua_thu$$=0);$g_kh$jscomp$1_lan_mua_thu$$+=1}if($obj$$.user_gt){if($g_kh$jscomp$1_lan_mua_thu$$=await global.getModel("participant").findOne({id_app:$obj$$.id_app,email:$obj$$.user_gt}).lean())$ckhds_query$$.user_group={$in:[($g_kh$jscomp$1_lan_mua_thu$$.group_id||"").toString(),null,void 0,""]}}else $ckhds_query$$.user_group={$in:[null,void 0,""]};$ckhds_query$$.$or=[{$and:[{ma_kh:$hieu_luc_tu_i_q_ma_kh$$},{nh_kh:{$in:["",null,void 0]}}]},{$and:[{nh_kh:$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$},
11
- {ma_kh:{$in:["",null,void 0]}}]}];$ckhds_query$$.ap_dung_lan_mua_thu={$in:[null,void 0,0,void 0]};$ckhds_query$$=await global.getModel("dmhoahonghd").find($ckhds_query$$).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}).limit(1).lean();$ckhds_query$$=$ckhds_query$$.filter($cs$$=>$cs$$.chi_su_dung_cho_ct?0<=$cs$$.chi_su_dung_cho_ct.indexOf($obj$$.ma_ct):$cs$$.khong_su_dung_cho_ct?0>$cs$$.khong_su_dung_cho_ct.indexOf($obj$$.ma_ct):!0);if(0<$ckhds_query$$.length)for($hieu_luc_tu_i_q_ma_kh$$=
12
- 0;$hieu_luc_tu_i_q_ma_kh$$<$ckhds_query$$.length;$hieu_luc_tu_i_q_ma_kh$$++){$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$=$ckhds_query$$[$hieu_luc_tu_i_q_ma_kh$$];$g_kh$jscomp$1_lan_mua_thu$$=$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.sl_toi_thieu||0;let $sl_dap_ung$$=0;$g_kh$jscomp$1_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&&
13
- (!$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||
14
- ($sl_dap_ung$$+=1)}});if($g_kh$jscomp$1_lan_mua_thu$$<=$sl_dap_ung$$){$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.tien_hh?($obj$$.tien_hoa_hong_gt=$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.tien_hh,$obj$$.ty_le_hoa_hong_gt=0):($obj$$.ty_le_hoa_hong_gt=$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.ty_le_hh||0,$obj$$.tien_hoa_hong_gt="9"==$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.kieu?Math.roundBy($loi_nhuan_t_ck_nt_t_gv_nt$$*$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.ty_le_hh/100,0):Math.roundBy($intro_intro$jscomp$1_intro$$*$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.ty_le_hh/
15
- 100,0));$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.so_tien_max&&($obj$$.tien_hoa_hong_gt=Math.min($ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.so_tien_max,$obj$$.tien_hoa_hong_gt));$obj$$.chuyen_ngay_gt="1"==$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.hinh_thuc_tt;break}}}}},hoahonghdnv=async $obj$$=>{if($obj$$.tu_tinh_hoa_hong&&!$obj$$.da_chuyen_hoa_hong){$obj$$.tien_hoa_hong=0;$obj$$.ty_le_hoa_hong=0;$obj$$.ma_kh_hoa_hong="";if(!$obj$$.user_nv&&$obj$$.ma_nv){var $kh$jscomp$2_nv_t_tien_nt$jscomp$1_t_tt_nt$$=await global.getModel("dmnv").findOne({id_app:$obj$$.id_app,
16
- ma_nv:$obj$$.ma_nv}).lean();$kh$jscomp$2_nv_t_tien_nt$jscomp$1_t_tt_nt$$&&($obj$$.ma_kh_hoa_hong=$kh$jscomp$2_nv_t_tien_nt$jscomp$1_t_tt_nt$$.ma_kh,$obj$$.user_nv=$kh$jscomp$2_nv_t_tien_nt$jscomp$1_t_tt_nt$$.user)}$obj$$.user_nv&&!$obj$$.ma_kh_hoa_hong&&($kh$jscomp$2_nv_t_tien_nt$jscomp$1_t_tt_nt$$=await global.getModel("customer").findOne({id_app:$obj$$.id_app,of_user:$obj$$.user_nv}))&&($obj$$.ma_kh_hoa_hong=$kh$jscomp$2_nv_t_tien_nt$jscomp$1_t_tt_nt$$.ma_kh);$kh$jscomp$2_nv_t_tien_nt$jscomp$1_t_tt_nt$$=
17
- $obj$$.details.csum("tien_hang_nt");var $loi_nhuan$jscomp$1_t_ck_nt$jscomp$1_t_gv_nt$$=$obj$$.details.csum("tien_ck_nt");$kh$jscomp$2_nv_t_tien_nt$jscomp$1_t_tt_nt$$=$kh$jscomp$2_nv_t_tien_nt$jscomp$1_t_tt_nt$$-$loi_nhuan$jscomp$1_t_ck_nt$jscomp$1_t_gv_nt$$-($obj$$.tien_ck_hd||0);$loi_nhuan$jscomp$1_t_ck_nt$jscomp$1_t_gv_nt$$=$obj$$.details.csum("tien_xuat_tmp");$loi_nhuan$jscomp$1_t_ck_nt$jscomp$1_t_gv_nt$$=$kh$jscomp$2_nv_t_tien_nt$jscomp$1_t_tt_nt$$-$loi_nhuan$jscomp$1_t_ck_nt$jscomp$1_t_gv_nt$$;
18
- var $ckhds$jscomp$1_query$$={id_app:$obj$$.id_app,gt_tu:{$lte:$kh$jscomp$2_nv_t_tien_nt$jscomp$1_t_tt_nt$$},ma_kho:{$in:[void 0,null,"",$obj$$.ma_kho]},doi_tuong:"0",ma_nv:{$in:[void 0,null,"",$obj$$.ma_nv]}};$ckhds$jscomp$1_query$$.$and=[{$or:[{gt_den:{$in:[0,void 0,null]}},{gt_den:{$gte:$kh$jscomp$2_nv_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 $g$jscomp$1_hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_kh$$=
19
- {$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$$};$ckhds$jscomp$1_query$$.hieu_luc_tu=$g$jscomp$1_hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_kh$$;$ckhds$jscomp$1_query$$.hieu_luc_den=$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$;if($obj$$.user_nv){if($g$jscomp$1_hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_kh$$=await global.getModel("participant").findOne({id_app:$obj$$.id_app,
20
- email:$obj$$.user_nv}).lean())$ckhds$jscomp$1_query$$.user_group={$in:[($g$jscomp$1_hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_kh$$.group_id||"").toString(),null,void 0,""]}}else $ckhds$jscomp$1_query$$.user_group={$in:[null,void 0,""]};$g$jscomp$1_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$3_lan_mua_thu$jscomp$3_sl_toi_thieu$$=await customer.findOne({id_app:$obj$$.id_app,
21
- ma_kh:$obj$$.ma_kh},{nh_kh:1});$kh$jscomp$3_lan_mua_thu$jscomp$3_sl_toi_thieu$$&&$kh$jscomp$3_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$3_lan_mua_thu$jscomp$3_sl_toi_thieu$$.nh_kh]});($kh$jscomp$3_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$3_lan_mua_thu$jscomp$3_sl_toi_thieu$$=0);$kh$jscomp$3_lan_mua_thu$jscomp$3_sl_toi_thieu$$+=
22
- 1}$ckhds$jscomp$1_query$$.$or=[{$and:[{ma_kh:$g$jscomp$1_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$$.ap_dung_lan_mua_thu={$in:[null,void 0,0,void 0]};$ckhds$jscomp$1_query$$=await global.getModel("dmhoahonghd").find($ckhds$jscomp$1_query$$).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,
23
- kieu:1}).limit(1).lean();$ckhds$jscomp$1_query$$=$ckhds$jscomp$1_query$$.filter($cs$$=>$cs$$.chi_su_dung_cho_ct?0<=$cs$$.chi_su_dung_cho_ct.indexOf($obj$$.ma_ct):$cs$$.khong_su_dung_cho_ct?0>$cs$$.khong_su_dung_cho_ct.indexOf($obj$$.ma_ct):!0);if(0<$ckhds$jscomp$1_query$$.length)for($g$jscomp$1_hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_kh$$=0;$g$jscomp$1_hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_kh$$<$ckhds$jscomp$1_query$$.length;$g$jscomp$1_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$$=
24
- $ckhds$jscomp$1_query$$[$g$jscomp$1_hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_kh$$];$kh$jscomp$3_lan_mua_thu$jscomp$3_sl_toi_thieu$$=$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$3_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$$=>
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$$=>
25
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||
26
- $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$3_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_hh?($obj$$.tien_hoa_hong=$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.tien_hh,$obj$$.ty_le_hoa_hong=0):($obj$$.ty_le_hoa_hong=$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.ty_le_hh||
27
- 0,$obj$$.tien_hoa_hong="9"==$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.kieu?Math.roundBy($loi_nhuan$jscomp$1_t_ck_nt$jscomp$1_t_gv_nt$$*$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.ty_le_hh/100,0):Math.roundBy($kh$jscomp$2_nv_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_hh/100,0));$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.so_tien_max&&($obj$$.tien_hoa_hong=Math.min($ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.so_tien_max,
28
- $obj$$.tien_hoa_hong));$obj$$.chuyen_ngay="1"==$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.hinh_thuc_tt;break}}}},khuyenmaihd=async $obj$$=>{if($obj$$.details&&$obj$$.online){var $ckhds$jscomp$2_query$jscomp$2_t_tien_nt$$=$obj$$.details.filter($d$$=>!$d$$.km_yn_for).csum("tien_hang_nt");if(0!==$ckhds$jscomp$2_query$jscomp$2_t_tien_nt$$){var $hieu_luc_tu$jscomp$2_i$jscomp$2_q_ma_kh$jscomp$2_t_ck_nt$jscomp$2_t_tt_nt$$=$obj$$.details.filter($d$$=>!$d$$.km_yn_for).csum("tien_ck_nt");
29
- $hieu_luc_tu$jscomp$2_i$jscomp$2_q_ma_kh$jscomp$2_t_ck_nt$jscomp$2_t_tt_nt$$=$ckhds$jscomp$2_query$jscomp$2_t_tien_nt$$-$hieu_luc_tu$jscomp$2_i$jscomp$2_q_ma_kh$jscomp$2_t_ck_nt$jscomp$2_t_tt_nt$$;$obj$$.details=$obj$$.details.filter($d$$=>"khuyenmaihd"!=$d$$.km_yn_for);$ckhds$jscomp$2_query$jscomp$2_t_tien_nt$$={id_app:$obj$$.id_app,gt_tu:{$lte:$hieu_luc_tu$jscomp$2_i$jscomp$2_q_ma_kh$jscomp$2_t_ck_nt$jscomp$2_t_tt_nt$$},ma_kho:{$in:[void 0,null,"",$obj$$.ma_kho]}};$ckhds$jscomp$2_query$jscomp$2_t_tien_nt$$.$and=
30
- [{$or:[{gt_den:{$in:[0,void 0,null]}},{gt_den:{$gte:$hieu_luc_tu$jscomp$2_i$jscomp$2_q_ma_kh$jscomp$2_t_ck_nt$jscomp$2_t_tt_nt$$}}]}];var $ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$=moment($obj$$.ngay_ct).startOf("date").toDate();$hieu_luc_tu$jscomp$2_i$jscomp$2_q_ma_kh$jscomp$2_t_ck_nt$jscomp$2_t_tt_nt$$={$lte:moment($obj$$.ngay_ct).endOf("date").toDate()};$ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$={$gte:$ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$};
31
- $ckhds$jscomp$2_query$jscomp$2_t_tien_nt$$.hieu_luc_tu=$hieu_luc_tu$jscomp$2_i$jscomp$2_q_ma_kh$jscomp$2_t_ck_nt$jscomp$2_t_tt_nt$$;$ckhds$jscomp$2_query$jscomp$2_t_tien_nt$$.hieu_luc_den=$ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$;$hieu_luc_tu$jscomp$2_i$jscomp$2_q_ma_kh$jscomp$2_t_ck_nt$jscomp$2_t_tt_nt$$={$in:[void 0,null,"",$obj$$.ma_kh]};$ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$={$in:[void 0,null,""]};if($obj$$.ma_kh){var $kh$jscomp$4_lan_mua_thu$jscomp$5_sl_toi_thieu$$=
32
- await customer.findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh},{nh_kh:1});$kh$jscomp$4_lan_mua_thu$jscomp$5_sl_toi_thieu$$&&$kh$jscomp$4_lan_mua_thu$jscomp$5_sl_toi_thieu$$.nh_kh&&($ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$={$in:[void 0,null,"",$kh$jscomp$4_lan_mua_thu$jscomp$5_sl_toi_thieu$$.nh_kh]});($kh$jscomp$4_lan_mua_thu$jscomp$5_sl_toi_thieu$$=await model.countDocuments({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh,trang_thai:{$in:["5","6"]}}))||($kh$jscomp$4_lan_mua_thu$jscomp$5_sl_toi_thieu$$=
33
- 0);$kh$jscomp$4_lan_mua_thu$jscomp$5_sl_toi_thieu$$+=1}$ckhds$jscomp$2_query$jscomp$2_t_tien_nt$$.$or=[{$and:[{ma_kh:$hieu_luc_tu$jscomp$2_i$jscomp$2_q_ma_kh$jscomp$2_t_ck_nt$jscomp$2_t_tt_nt$$},{nh_kh:{$in:["",null,void 0]}}]},{$and:[{nh_kh:$ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$},{ma_kh:{$in:["",null,void 0]}}]}];$ckhds$jscomp$2_query$jscomp$2_t_tien_nt$$.ap_dung_lan_mua_thu={$in:[null,void 0,0,void 0]};$ckhds$jscomp$2_query$jscomp$2_t_tien_nt$$.online=!0;$ckhds$jscomp$2_query$jscomp$2_t_tien_nt$$=
34
- await dmkhuyenmaihd.find($ckhds$jscomp$2_query$jscomp$2_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$2_i$jscomp$2_q_ma_kh$jscomp$2_t_ck_nt$jscomp$2_t_tt_nt$$=0;$hieu_luc_tu$jscomp$2_i$jscomp$2_q_ma_kh$jscomp$2_t_ck_nt$jscomp$2_t_tt_nt$$<$ckhds$jscomp$2_query$jscomp$2_t_tien_nt$$.length;$hieu_luc_tu$jscomp$2_i$jscomp$2_q_ma_kh$jscomp$2_t_ck_nt$jscomp$2_t_tt_nt$$++)if(($ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$=$ckhds$jscomp$2_query$jscomp$2_t_tien_nt$$[$hieu_luc_tu$jscomp$2_i$jscomp$2_q_ma_kh$jscomp$2_t_ck_nt$jscomp$2_t_tt_nt$$])&&
35
- $ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$.details_km&&0<$ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$.details_km.length){$kh$jscomp$4_lan_mua_thu$jscomp$5_sl_toi_thieu$$=$ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$.sl_toi_thieu||0;let $sl_dap_ung$$=0;$kh$jscomp$4_lan_mua_thu$jscomp$5_sl_toi_thieu$$&&$ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$.vts&&0<$ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$.vts.length&&
36
- $ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$.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||0)-($d$$.tien_ck_nt||
37
- 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($kh$jscomp$4_lan_mua_thu$jscomp$5_sl_toi_thieu$$<=$sl_dap_ung$$){$ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$.details_km.forEach($d$$=>{$d$$={...$d$$,km_yn_for:"khuyenmaihd"};$d$$.sl_xuat=$d$$.sl_km;$d$$.tien_hang_nt=$d$$.tien_hang=0;$d$$.tien_ck_nt=
38
- $d$$.tien_ck=0;$d$$.ty_le_ck=0;$d$$.tien_nt=$d$$.tien=0;$obj$$.details.push($d$$)});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$3_t_tt_nt$$=$obj$$.details.filter($d$$=>!$d$$.km_yn_for).csum("tien_hang_nt"),$ckhds$jscomp$3_query$jscomp$3_t_ck_nt$$=$obj$$.details.filter($d$$=>!$d$$.km_yn_for).csum("tien_ck_nt");$t_tien_nt$jscomp$3_t_tt_nt$$-=$ckhds$jscomp$3_query$jscomp$3_t_ck_nt$$;$ckhds$jscomp$3_query$jscomp$3_t_ck_nt$$=
39
- {id_app:$obj$$.id_app,gt_tu:{$lte:$t_tien_nt$jscomp$3_t_tt_nt$$},ma_kho:{$in:[void 0,null,"",$obj$$.ma_kho]}};$ckhds$jscomp$3_query$jscomp$3_t_ck_nt$$.$and=[{$or:[{gt_den:{$in:[0,void 0,null]}},{gt_den:{$gte:$t_tien_nt$jscomp$3_t_tt_nt$$}}]}];var $ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$=moment($obj$$.ngay_ct).startOf("date").toDate();var $hieu_luc_tu$jscomp$3_i$jscomp$3_q_ma_kh$$={$lte:moment($obj$$.ngay_ct).endOf("date").toDate()};$ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$=
40
- {$gte:$ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$};$ckhds$jscomp$3_query$jscomp$3_t_ck_nt$$.hieu_luc_tu=$hieu_luc_tu$jscomp$3_i$jscomp$3_q_ma_kh$$;$ckhds$jscomp$3_query$jscomp$3_t_ck_nt$$.hieu_luc_den=$ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$;$hieu_luc_tu$jscomp$3_i$jscomp$3_q_ma_kh$$={$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$5_lan_mua_thu$jscomp$7_sl_toi_thieu$$=
41
- await customer.findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh},{nh_kh:1});$kh$jscomp$5_lan_mua_thu$jscomp$7_sl_toi_thieu$$&&$kh$jscomp$5_lan_mua_thu$jscomp$7_sl_toi_thieu$$.nh_kh&&($ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$={$in:[void 0,null,"",$kh$jscomp$5_lan_mua_thu$jscomp$7_sl_toi_thieu$$.nh_kh]});($kh$jscomp$5_lan_mua_thu$jscomp$7_sl_toi_thieu$$=await model.countDocuments({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh,trang_thai:{$in:["5","6"]}}))||($kh$jscomp$5_lan_mua_thu$jscomp$7_sl_toi_thieu$$=
42
- 0);$kh$jscomp$5_lan_mua_thu$jscomp$7_sl_toi_thieu$$+=1}$ckhds$jscomp$3_query$jscomp$3_t_ck_nt$$.$or=[{$and:[{ma_kh:$hieu_luc_tu$jscomp$3_i$jscomp$3_q_ma_kh$$},{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_ck_nt$$.ap_dung_lan_mua_thu={$in:[null,void 0,0,void 0]};$ckhds$jscomp$3_query$jscomp$3_t_ck_nt$$.online=!0;$ckhds$jscomp$3_query$jscomp$3_t_ck_nt$$=await dmchietkhauhd.find($ckhds$jscomp$3_query$jscomp$3_t_ck_nt$$).sort({gt_tu:-1,
43
- tien_ck:-1,ty_le_ck:-1,ma_kh:-1,nh_kh:-1,hieu_luc_tu:-1}).lean();if(0<$ckhds$jscomp$3_query$jscomp$3_t_ck_nt$$.length)for($hieu_luc_tu$jscomp$3_i$jscomp$3_q_ma_kh$$=0;$hieu_luc_tu$jscomp$3_i$jscomp$3_q_ma_kh$$<$ckhds$jscomp$3_query$jscomp$3_t_ck_nt$$.length;$hieu_luc_tu$jscomp$3_i$jscomp$3_q_ma_kh$$++){$ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$=$ckhds$jscomp$3_query$jscomp$3_t_ck_nt$$[$hieu_luc_tu$jscomp$3_i$jscomp$3_q_ma_kh$$];$kh$jscomp$5_lan_mua_thu$jscomp$7_sl_toi_thieu$$=
44
- $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$5_lan_mua_thu$jscomp$7_sl_toi_thieu$$&&$ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$.vts&&0<$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$jscomp$3_tien$$=$obj$$.details.filter($d$$=>$d$$.ma_vt===$vt$$.ma_vt&&(!$vt$$.ma_tt1||$vt$$.ma_tt1===$d$$.ma_tt1)&&
45
- (!$vt$$.ma_tt2||$vt$$.ma_tt2===$d$$.ma_tt2)&&(!$vt$$.ma_tt3||$vt$$.ma_tt3===$d$$.ma_tt3));if(0!=$ds$jscomp$3_tien$$.length){var $so_luong$$=$ds$jscomp$3_tien$$.map($d$$=>$d$$.sl_xuat).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$ds$jscomp$3_tien$$=$ds$jscomp$3_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$3_tien$$<$vt$$.gt_tu||$vt$$.gt_den&&$ds$jscomp$3_tien$$>
46
- $vt$$.gt_den||($sl_dap_ung$$+=1)}});if($kh$jscomp$5_lan_mua_thu$jscomp$7_sl_toi_thieu$$<=$sl_dap_ung$$){$ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$.tien_ck?($obj$$.tien_ck_hd=$ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$.tien_ck,$obj$$.ty_le_ck_hd=0):($obj$$.ty_le_ck_hd=$ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$.ty_le_ck,$obj$$.tien_ck_hd=Math.roundBy($t_tien_nt$jscomp$3_t_tt_nt$$*$ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$.ty_le_ck/
47
- 100,0));$ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$.so_tien_max&&($obj$$.tien_ck_hd=Math.min($ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_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"!=
48
- $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$$=
49
- (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,
50
- 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$$=
51
- 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);
52
- 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$$=
53
- 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",
54
- 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,
55
- 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,
56
- 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`));
57
- 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`));
58
- 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()}`));
59
- if($_e$$.vts&&0<$_e$$.vts.length&&$_e$$.sl_toi_thieu){let $sl_dap_ung$$=0;$_e$$.vts.forEach($vt$$=>{var $ds$jscomp$4_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$4_tien$$.length){var $so_luong$$=$ds$jscomp$4_tien$$.map($d$$=>$d$$.sl_xuat).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$ds$jscomp$4_tien$$=$ds$jscomp$4_tien$$.map($d$$=>($d$$.tien_hang_nt||
60
- 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$4_tien$$<$vt$$.gt_tu||$vt$$.gt_den&&$ds$jscomp$4_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$$=
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()}`));
60
+ 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
+ 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$$=
61
62
  $_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$$)=>
62
63
  {if($evoucher_code$$){$id_ct_rs$$=$id_ct_rs$$.toString();var $e$$=await Evoucher.findOne({ma:$evoucher_code$$,id_app:$id_app$$});$e$$?($id_app$$=$e$$.id_ct_useds||[],$id_app$$.push($id_ct_rs$$),$id_app$$=[...(new Set($id_app$$))],$id_ct_rs$$=await Evoucher.findOneAndUpdate({_id:$e$$._id},{id_ct_useds:$id_app$$}),console.log("update id_ct_useds",$evoucher_code$$,$id_app$$,$id_ct_rs$$)):console.error("can't find evoucher",$evoucher_code$$)}},deleteEvoucher=async($id_app$jscomp$2_id_ct_useds$$,$evoucher_code$$,
63
64
  $id_ct$$)=>{if($evoucher_code$$){$id_ct$$=$id_ct$$.toString();var $e$jscomp$3_rs$$=await Evoucher.findOne({id_app:$id_app$jscomp$2_id_ct_useds$$,ma:$evoucher_code$$});$e$jscomp$3_rs$$&&($id_app$jscomp$2_id_ct_useds$$=($e$jscomp$3_rs$$.id_ct_useds||[]).filter($ct$$=>$ct$$!==$id_ct$$),$e$jscomp$3_rs$$=await Evoucher.findOneAndUpdate({_id:$e$jscomp$3_rs$$._id},{id_ct_useds:$id_app$jscomp$2_id_ct_useds$$}),console.log("update id_ct_useds",$evoucher_code$$,$id_app$jscomp$2_id_ct_useds$$,$e$jscomp$3_rs$$))}},
@@ -78,75 +79,73 @@ if($freeship_i$$.gia_tri_dh&&$freeship_i$$.gia_tri_dh>$details_dvgh_t_tien_nt$$)
78
79
  $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$$&&
79
80
  ($_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$$;
80
81
  ($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$$=
81
- $tien_evoucher$$-$tien_evoucher_da_phan_bo$$}else $tien_evoucher_con_lai$$=0})}},valid=async function($user$$,$obj$$,$next$$,$i$jscomp$6_pre_obj$$){$i$jscomp$6_pre_obj$$&&($obj$$.online=$i$jscomp$6_pre_obj$$.online,$obj$$._id=$i$jscomp$6_pre_obj$$._id,$obj$$.details=$obj$$.details||$i$jscomp$6_pre_obj$$.details||[],$obj$$.evouchers=$obj$$.evouchers||$i$jscomp$6_pre_obj$$.evouchers);if($obj$$.online)try{await validOnline($user$$,$obj$$,$i$jscomp$6_pre_obj$$)}catch($e$$){return $next$$($e$$.message)}if($obj$$.paymentByPoints)try{var $detail$$=
82
- 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$6_pre_obj$$=0;$i$jscomp$6_pre_obj$$<($obj$$.details||[]).length;$i$jscomp$6_pre_obj$$++)$detail$$=($obj$$.details||[])[$i$jscomp$6_pre_obj$$],$detail$$.line=$i$jscomp$6_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),
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),
83
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")})};
84
- 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$$)=>{await $obj$$.details.asyncJoinModel2($obj$$.id_app,dmvt,{where:"ma_vt",
85
- 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$$)};$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;$ctrlSO1$$&&controller.postData($obj$$,$ctrlSO1$$,
86
- $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","gia_mua"]});await $obj$$.details.filter($d$$=>$d$$.ma_thue).asyncJoinModel2($obj$$.id_app,
87
- 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*=$detail$$.sl_xuat;$item$$.tien_xuat=$item$$.tien_xuat_nt=$item$$.sl_xuat*$item$$.gia_von_nt;
88
- $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;$detail$$.ma_kho=$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$jscomp$0$$($e$$,
89
- $rs$$)})},post_socai:function($callback$$){options.findOne({id_app:$obj$$.id_app,id_func:ma_ct.toLowerCase()}).lean().exec(async($error$$,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$)=>{let $option$$;$option$$=$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$?$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.option||{}:{};($error$$=await dmkho.findOne({id_app:$obj$$.id_app,
90
- ma_kho:$obj$$.ma_kho}).lean())||($error$$={});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||$error$$.tk_cn;$pt$$.tk_dt=$error$$.tk_dt||$pt$$.tk_dt;$pt$$.tk_gv=$error$$.tk_gv||$pt$$.tk_gv;$pt$$.tk_ck=$error$$.tk_ck||$pt$$.tk_ck;$pt$$.tk_cp_gh=$error$$.tk_cp_gh||$pt$$.tk_cp_gh;$pt$$.tk_cp_bh=$error$$.tk_cp_bh||
91
- $pt$$.tk_cp_bh;$pt$$.tk_cp_ctv=$error$$.tk_cp_ctv||$pt$$.tk_cp_ctv;$pt$$.tk_cn_ctv=$error$$.tk_cn_ctv||$pt$$.tk_cn_ctv;$option$$.tk_tien=$pt$$.tk_tien||$error$$.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||
92
- $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;$obj$$.details.forEach($detail$$=>{$detail$$.ma_thue&&$detail$$.tk_thue_co_treo?($detail$$.tien_ct=($detail$$.tien_hang-
93
- ($detail$$.tien_ck||0))/(1+$detail$$.thue_suat/100),$detail$$.tien_ct_nt=($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/
94
- 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)});const $details$$=[];$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$=$obj$$.details.map($a$$=>($a$$.tien_hang_nt||0)-($a$$.tien_ck_nt||0)).reduce(($a$$,$b$$)=>
95
- $a$$+$b$$,0)-(($obj$$.tt_tien_thuong||0)+($obj$$.tien_ck_hd||0)+($obj$$.tien_evoucher||0));let $tien_paymentByPoints$$=$obj$$.tien_paymentByPoints||0;const $hoachtoandtvathue$$=($tk_tien$$,$ty_le$$)=>{$obj$$.details.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=$tk_tien$$;$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=
96
- $obj$$.ngay_giao_hang||$obj$$.ngay_ct;$d$jscomp$35_detail$$.tien=$d$jscomp$35_detail$$.tien_nt=Math.roundBy($d$jscomp$35_detail$$.tien_ct_nt*$ty_le$$);$d$jscomp$35_detail$$.flag="DT_"+($d$jscomp$35_detail$$.ma_vt||"");$details$$.push($d$jscomp$35_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=
97
- 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$$)};$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$&&($hoachtoandtvathue$$($option$$.tk_cn,$tien_paymentByPoints$$/$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$),$hoachtoandtvathue$$($option$$.tk_tien,($rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$-
98
- $tien_paymentByPoints$$)/$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_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||$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$39_detail$$){$d$jscomp$39_detail$$=
99
- {...$d$jscomp$39_detail$$};$d$jscomp$39_detail$$.tk_co=$option$$.tk_dt;$d$jscomp$39_detail$$.tk_no=$option$$.tk_cn;$d$jscomp$39_detail$$.ma_kh_co=$obj$$.ma_kh;$d$jscomp$39_detail$$.ma_kh_no=$option$$.ma_kh;$d$jscomp$39_detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;$d$jscomp$39_detail$$.tien_nt=$d$jscomp$39_detail$$.tien_cp_nt;$d$jscomp$39_detail$$.tien=$d$jscomp$39_detail$$.tien_cp;$details$$.push($d$jscomp$39_detail$$)});$obj$$.tien_phi_vc&&($rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$=
100
- {},$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_co=$option$$.tk_dt,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_no=$option$$.tk_cn,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt=$obj$$.tien_phi_vc||0,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien=$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt,
101
- $rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh_co=$obj$$.ma_kh,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh_no=$obj$$.nhan_vien_giao_hang||$obj$$.don_vi_vc,$details$$.push($rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$));$obj$$.tien_freeship&&($rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$=
102
- {},$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_no=$option$$.tk_cp_gh,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_co=$option$$.tk_cn,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt=$obj$$.tien_freeship||0,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien=$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt,
103
- $rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh_no=$obj$$.ma_kh,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh_co=$option$$.ma_kh,$details$$.push($rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$));$obj$$.tt_tien_thuong&&($rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$={},$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_no=
104
- $option$$.tk_cp_bh,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_co=$option$$.tk_cn,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt=$obj$$.tt_tien_thuong||0,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien=$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh_no=
105
- $obj$$.ma_kh,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh_co=$option$$.ma_kh,$details$$.push($rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$));$obj$$.thu_nhap_ctv&&$option$$.tk_cp_ctv&&$option$$.tk_cn_ctv&&($rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$={},$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_no=
106
- $option$$.tk_cp_ctv,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_co=$option$$.tk_cn_ctv,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt=$obj$$.thu_nhap_ctv||0,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien=$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh=
107
- $obj$$.ma_ctv,$details$$.push($rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$));$obj$$.tien_evoucher&&($rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$={},$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_no=$obj$$.tk_no_evoucher||$option$$.tk_no_evoucher||$option$$.tk_ck,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_co=
108
- $obj$$.tk_co_evoucher||$option$$.tk_co_evoucher||$option$$.tk_cn,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt=$obj$$.tien_evoucher||0,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien=$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh_no=
109
- $obj$$.ma_kh,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh_co=$option$$.ma_kh,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.check_balance=!1,$details$$.push($rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$));$obj$$.tien_ck_hd&&($rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$={},$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_no=
110
- $option$$.tk_ck,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_co=$option$$.tk_cn,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt=$obj$$.tien_ck_hd||0,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien=$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh_no=
111
- $obj$$.ma_kh,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh_co=$option$$.ma_kh,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.check_balance=!1,$details$$.push($rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$));$obj$$.tien_hoa_hong&&$obj$$.ma_kh_hoa_hong&&($rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$=
112
- {},$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_no=$obj$$.tk_no_hoa_hong||$error$$.tk_no_hoa_hong||options.tk_no_hoa_hong,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_co=$obj$$.tk_co_hoa_hong||$error$$.tk_co_hoa_hong||options.tk_co_hoa_hong,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt=$obj$$.tien_hoa_hong,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien=
113
- $rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt*($obj$$.ty_gia||1),$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh=$obj$$.ma_kh_hoa_hong,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_nv=$obj$$.ma_nv,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.check_balance=!1,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_no&&
114
- $rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_co&&$details$$.push($rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$));$obj$$.tien_hoa_hong_gt&&$obj$$.ma_kh_hoa_hong_gt&&($rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$={},$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_no=$obj$$.tk_no_hoa_hong_gt||
115
- $error$$.tk_no_hoa_hong_gt||options.tk_no_hoa_hong_gt,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_co=$obj$$.tk_co_hoa_hong_gt||$error$$.tk_co_hoa_hong_gt||options.tk_co_hoa_hong_gt,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt=$obj$$.tien_hoa_hong_gt,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien=$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt*
116
- ($obj$$.ty_gia||1),$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh=$obj$$.ma_kh_hoa_hong_gt,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_nv=$obj$$.ma_nv,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.check_balance=!1,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_no&&$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_co&&
117
- $details$$.push($rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_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$40_detail$$){$d$jscomp$40_detail$$={...$d$jscomp$40_detail$$};$d$jscomp$40_detail$$.tk_no=$option$$.tk_gv;$d$jscomp$40_detail$$.ma_kh=$obj$$.ma_kh;$d$jscomp$40_detail$$.ngay_ct=$obj$$.ngay_giao_hang||
118
- $obj$$.ngay_ct;$d$jscomp$40_detail$$.tk_co=$d$jscomp$40_detail$$.tk_vt||"1561";$d$jscomp$40_detail$$.tien_nt=$d$jscomp$40_detail$$.tien_xuat_nt;$d$jscomp$40_detail$$.tien=$d$jscomp$40_detail$$.tien_xuat;$d$jscomp$40_detail$$.tg_tk||($d$jscomp$40_detail$$.tien=$d$jscomp$40_detail$$.tien_nt=0);$details$$.push($d$jscomp$40_detail$$)});(new PostSocai($obj$$,$details$$,null,Socaitmp)).run(function($e$$,$rs$$){console.log("post result",$rs$$);$callback$$($e$$,$rs$$)})})})},thanhtoanhoahongnv:$callback$$=>
119
- {if($obj$$.da_chuyen_hoa_hong||!$obj$$.tien_hoa_hong||!$obj$$.user_nv||!$obj$$.chuyen_ngay)return $callback$$();setImmediate(async()=>{try{if($appInfo$$.wallet_address&&$appInfo$$.wallet_token&&$appInfo$$.tang_gioi_thieu_denom){let $wallet_nhan_vien$$=await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),username:$obj$$.user_nv,wallet_type:1});if(!$wallet_nhan_vien$$){$wallet_nhan_vien$$=(new global.getModel("asskey"))({user_created:$obj$$.user_nv,username:$obj$$.user_nv,id_app:$obj$$.id_app,
120
- 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()}`;
85
+ 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=
108
+ $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()}`;
121
117
  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&&
122
118
  $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=
123
119
  $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=
124
- !0;await model.updateOne({_id:$obj$$._id},{da_chuyen_hoa_hong_gt:!0})}}catch($e$$){console.error("Kh\u00f4ng th\u1ec3 thanh to\u00e1n ti\u1ec1n hoa h\u1ed3ng",$e$$)}$callback$$()})}},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;
125
- $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",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*
126
- ($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-($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.");
127
- $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&&
128
- $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=
129
- "",$obj$$.payment_service="",$obj$$.payment_id=""}else $obj$$.virtual_payment_client_url=""}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$$),
130
- console.log("error create Virtual Payment ClientURL",$e$$.message))});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");
131
- $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",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||
132
- 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-($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$$=>
133
- {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.");await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":buy"});$next$$(null,$data$$,$obj$$)},$obj$$)};$contr_router$$.updated=async function($amount$jscomp$5_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&&
134
- 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});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$3_virtual_payment_client_url$$=
135
- await $app_paymentServiceModel$$.createVirtualPaymentClientURL($obj$$,$amount$jscomp$5_evouchers_user$$.clientIp,$pt_thanh_toan$jscomp$1_pt_thanh_toan$$);$obj$$.virtual_payment_client_url=$memo$jscomp$3_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=
136
- "",$obj$$.payment_service="",$obj$$.payment_id=""}else $obj$$.virtual_payment_client_url=""}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()},
137
- {id_ct_used:null});$amount$jscomp$5_evouchers_user$$=await Evoucher.find({id_ct_useds:$obj$$._id.toString()});await Promise.all($amount$jscomp$5_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()+
138
- ":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$5_evouchers_user$$=$obj$$.t_tt_nt-($obj$$.tien_paymentByPoints||
139
- 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$3_virtual_payment_client_url$$="Tr\u1ea3 l\u1ea1i ti\u1ec1n cho \u0111\u01a1n h\u00e0ng "+
140
- $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$5_evouchers_user$$,denom:$denom$$,memo:$memo$jscomp$3_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",
120
+ !0;await model.updateOne({_id:$obj$$._id},{da_chuyen_hoa_hong_gt:!0})}}catch($e$$){console.error("Kh\u00f4ng th\u1ec3 thanh to\u00e1n ti\u1ec1n hoa h\u1ed3ng",$e$$)}$callback$$()})},thanhtoanhoahongctv:$callback$$=>{if($obj$$.da_chuyen_hoa_hong_ctv||!$obj$$.thu_nhap_ctv||!$obj$$.user_ctv||!$obj$$.chuyen_ngay_ctv)return $callback$$();setImmediate(async()=>{try{if($appInfo$$.wallet_address&&$appInfo$$.wallet_token&&$appInfo$$.tang_gioi_thieu_denom){let $wallet_gt$$=await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),
121
+ 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
+ $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
+ $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",
141
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");
142
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,
143
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"}},
144
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$$=>
145
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=
146
- $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$$.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,
147
- $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||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,
148
- 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$$,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+
149
- " - "+$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$$=>$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$$,
150
- $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$$()})},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,
151
- [{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$$();$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$$()})}},
152
- function(){$fn$$(null,$items$$)})}};
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$$)})}};