flexbiz-server 12.5.35 → 12.5.36

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.
@@ -1,45 +1,46 @@
1
- const async=require("async"),_=require("lodash"),moment=require("moment"),numeral=require("numeral"),PostSokho=require("../../libs/post-sokho"),PostBook=require("../../libs/post-book"),Options=global.getModel("options"),PostSocai=require("../../libs/post-socai"),Sokhott=global.getModel("sokhott"),App=global.getModel("app"),dmkho=global.getModel("dmkho"),dmvt=global.getModel("dmvt"),customer=global.getModel("customer"),dmdt=global.getModel("dmdt"),dmtt=global.getModel("dmtt"),Dmban=global.getModel("dmban"),
2
- dmphi=global.getModel("dmphi"),contract=global.getModel("contract"),trangthai=global.getModel("trangthai"),model=global.getModel("pbl"),hd7=global.getModel("hd7"),ptthanhtoan=global.getModel("ptthanhtoan"),controller=require("../../controllers/controller"),ma_ct="PBL",transaction=global.getModel("transaction"),Evoucher=global.getModel("evoucher"),ckdiem=require("../../libs/ckdiem"),dmdiemthuong=global.getModel("dmdiemthuong"),currency=global.getModel("currency"),vat=global.getModel("vat"),Wallet=
3
- global.getModel("wallet"),dmchietkhauhd=global.getModel("dmchietkhauhd"),dmkhuyenmaihd=global.getModel("dmkhuyenmaihd"),{QRPay}=require("vietnam-qr-pay"),khuyenmaihd=async $obj$$=>{if($obj$$.details){var $ckhds_query_t_tien_hang_ct_nt$$=$obj$$.details.csum("tien_hang_ct_nt")+$obj$$.details.csum("tien_hang_options_ct");if($ckhds_query_t_tien_hang_ct_nt$$!==0){var $hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$=$obj$$.details.csum("tien_ck_nt");$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$=$ckhds_query_t_tien_hang_ct_nt$$-
4
- $hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$;$obj$$.details=$obj$$.details.filter($d$$=>$d$$.km_yn_for!="khuyenmaihd");$ckhds_query_t_tien_hang_ct_nt$$={id_app:$obj$$.id_app,gt_tu:{$lte:$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$},ma_kho:{$in:[void 0,null,"",$obj$$.ma_kho]}};$ckhds_query_t_tien_hang_ct_nt$$.$and=[{$or:[{gt_den:{$in:[0,void 0,null]}},{gt_den:{$gte:$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$}}]}];var $hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$=moment($obj$$.ngay_ct).startOf("date").toDate();
5
- $hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$={$lte:moment($obj$$.ngay_ct).endOf("date").toDate()};$hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$={$gte:$hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$};$ckhds_query_t_tien_hang_ct_nt$$.hieu_luc_tu=$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$;$ckhds_query_t_tien_hang_ct_nt$$.hieu_luc_den=$hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$;$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$={$in:[void 0,null,"",$obj$$.ma_kh]};$hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$={$in:[void 0,
6
- null,""]};if($obj$$.ma_kh){var $kh_lan_mua_thu$$=await customer.findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh},{nh_kh:1});$kh_lan_mua_thu$$&&$kh_lan_mua_thu$$.nh_kh&&($hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$={$in:[void 0,null,"",$kh_lan_mua_thu$$.nh_kh]});($kh_lan_mua_thu$$=await model.countDocuments({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh,trang_thai:{$in:["5","6"]}}))||($kh_lan_mua_thu$$=0);$kh_lan_mua_thu$$+=1}$ckhds_query_t_tien_hang_ct_nt$$.$or=[{$and:[{ma_kh:$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$},
1
+ const async=require("async"),_=require("lodash"),moment=require("moment"),numeral=require("numeral"),PostSokho=require("flexbiz-server/server/libs/post-sokho"),PostBook=require("flexbiz-server/server/libs/post-book"),Options=global.getModel("options"),PostSocai=require("flexbiz-server/server/libs/post-socai"),Sokhott=global.getModel("sokhott"),App=global.getModel("app"),dmkho=global.getModel("dmkho"),dmvt=global.getModel("dmvt"),customer=global.getModel("customer"),dmdt=global.getModel("dmdt"),dmtt=
2
+ global.getModel("dmtt"),Dmban=global.getModel("dmban"),dmphi=global.getModel("dmphi"),contract=global.getModel("contract"),trangthai=global.getModel("trangthai"),model=global.getModel("pbl"),hd7=global.getModel("hd7"),ptthanhtoan=global.getModel("ptthanhtoan"),controller=require("flexbiz-server/server/controllers/controller"),ma_ct="PBL",transaction=global.getModel("transaction"),Evoucher=global.getModel("evoucher"),ckdiem=require("flexbiz-server/server/libs/ckdiem"),dmdiemthuong=global.getModel("dmdiemthuong"),
3
+ currency=global.getModel("currency"),vat=global.getModel("vat"),Wallet=global.getModel("wallet"),dmchietkhauhd=global.getModel("dmchietkhauhd"),dmkhuyenmaihd=global.getModel("dmkhuyenmaihd"),{QRPay}=require("vietnam-qr-pay"),khuyenmaihd=async $obj$$=>{if($obj$$.details){var $ckhds_query_t_tien_hang_ct_nt$$=$obj$$.details.csum("tien_hang_ct_nt")+$obj$$.details.csum("tien_hang_options_ct");if($ckhds_query_t_tien_hang_ct_nt$$!==0){var $hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$=$obj$$.details.csum("tien_ck_nt");
4
+ $hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$=$ckhds_query_t_tien_hang_ct_nt$$-$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$;$obj$$.details=$obj$$.details.filter($d$$=>$d$$.km_yn_for!="khuyenmaihd");$ckhds_query_t_tien_hang_ct_nt$$={id_app:$obj$$.id_app,gt_tu:{$lte:$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$},ma_kho:{$in:[void 0,null,"",$obj$$.ma_kho]}};$ckhds_query_t_tien_hang_ct_nt$$.$and=[{$or:[{gt_den:{$in:[0,void 0,null]}},{gt_den:{$gte:$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$}}]}];var $hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$=
5
+ moment($obj$$.ngay_ct).startOf("date").toDate();$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$={$lte:moment($obj$$.ngay_ct).endOf("date").toDate()};$hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$={$gte:$hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$};$ckhds_query_t_tien_hang_ct_nt$$.hieu_luc_tu=$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$;$ckhds_query_t_tien_hang_ct_nt$$.hieu_luc_den=$hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$;$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$={$in:[void 0,null,"",$obj$$.ma_kh]};$hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$=
6
+ {$in:[void 0,null,""]};if($obj$$.ma_kh){var $kh_lan_mua_thu$$=await customer.findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh},{nh_kh:1});$kh_lan_mua_thu$$&&$kh_lan_mua_thu$$.nh_kh&&($hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$={$in:[void 0,null,"",$kh_lan_mua_thu$$.nh_kh]});($kh_lan_mua_thu$$=await model.countDocuments({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh,trang_thai:{$in:["5","6"]}}))||($kh_lan_mua_thu$$=0);$kh_lan_mua_thu$$+=1}$ckhds_query_t_tien_hang_ct_nt$$.$or=[{$and:[{ma_kh:$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$},
7
7
  {nh_kh:{$in:["",null,void 0]}}]},{$and:[{nh_kh:$hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$},{ma_kh:{$in:["",null,void 0]}}]}];$ckhds_query_t_tien_hang_ct_nt$$.ap_dung_lan_mua_thu={$in:[null,void 0,0,void 0]};$ckhds_query_t_tien_hang_ct_nt$$=await dmkhuyenmaihd.find($ckhds_query_t_tien_hang_ct_nt$$).sort({stt_uu_tien:1,gt_tu:-1,ma_kh:-1,nh_kh:-1,hieu_luc_tu:-1}).lean();for($hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$=0;$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$<$ckhds_query_t_tien_hang_ct_nt$$.length;$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$++){let $ckhd$$=
8
8
  $ckhds_query_t_tien_hang_ct_nt$$[$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$];if($ckhd$$&&$ckhd$$.details_km&&$ckhd$$.details_km.length>0){$hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$=$ckhd$$.sl_toi_thieu||0;let $sl_dap_ung$$=0;$hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$&&$ckhd$$.vts&&$ckhd$$.vts.length>0&&$ckhd$$.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||
9
9
  $vt$$.ma_tt3===$d$$.ma_tt3));if($ds_tien$$.length!=0){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_ct_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($hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$<=$sl_dap_ung$$){$ckhd$$.details_km.forEach($d$$=>
10
10
  {$d$$={...$d$$,km_yn_for:"khuyenmaihd"};$d$$.id_cs=$ckhd$$._id.toString();$d$$.sl_xuat=$d$$.sl_km;$d$$.tien_hang_ct_nt=$d$$.tien_hang_ct=$d$$.tien_hang_nt=$d$$.tien_hang=0;$d$$.tien_ck_nt=$d$$.tien_ck=0;$d$$.ty_le_ck=0;$d$$.tien_nt=$d$$.tien=0;$obj$$.details.push($d$$)});break}}}}}},chietkhauhd=async($user$$,$obj$$)=>{if(!$obj$$.signature){$obj$$.details=$obj$$.details||[];var $t_ck_nt$$=$obj$$.details.csum("tien_ck_nt"),$t_tien_hang_ct_nt$$=$obj$$.details.csum("tien_hang_ct_nt")+$obj$$.details.csum("tien_hang_options_ct");
11
- $user$$.current_app_info&&($user$$.current_app_info.options||{}).tinh_lai_chiet_khau_pbl!=0&&dmchietkhauhd.tinhChietKhau($user$$,$obj$$.id_app,$obj$$,$t_tien_hang_ct_nt$$-$t_ck_nt$$)}},tinhtienthue=$detail$$=>{$detail$$.thue_suat=$detail$$.thue_suat||0;$detail$$.gia_ban_ct_nt=$detail$$.gia_ban_ct=Math.roundBy($detail$$.gia_ban_nt/(1+$detail$$.thue_suat/100));$detail$$.tien_hang_ct=$detail$$.tien_hang_ct_nt=Math.roundBy($detail$$.sl_xuat*$detail$$.gia_ban_ct_nt);$detail$$.ty_le_ck&&($detail$$.tien_ck_nt=
12
- Math.roundBy($detail$$.tien_hang_ct_nt*$detail$$.ty_le_ck/100));$detail$$.tien_thue=$detail$$.tien_thue_nt=Math.roundBy(($detail$$.tien_hang_ct_nt-$detail$$.tien_ck_nt)*$detail$$.thue_suat/100)},tinhtongtien=$r$$=>{$r$$.details&&($r$$.details.forEach($d$$=>{$d$$.sl_order=$d$$.sl_order||$d$$.sl_xuat}),$r$$.t_sl_order=$r$$.details.csum("sl_order"),$r$$.t_sl=$r$$.details.csum("sl_xuat"),$r$$.t_tien_hang_ct=$r$$.details.csum("tien_hang_ct")+$r$$.details.csum("tien_hang_options_ct"),$r$$.t_tien_hang_ct_nt=
13
- $r$$.details.csum("tien_hang_ct_nt")+$r$$.details.csum("tien_hang_options_ct"),$r$$.t_thue_nt=$r$$.details.csum("tien_thue_nt")+$r$$.details.csum("tien_thue_options"),$r$$.t_thue=$r$$.details.csum("tien_thue")+$r$$.details.csum("tien_thue_options"),$r$$.t_tien_hang=$r$$.t_tien_hang_ct+$r$$.t_thue,$r$$.t_tien_hang_nt=$r$$.t_tien_hang_ct_nt+$r$$.t_thue_nt,$r$$.t_ck=$r$$.details.csum("tien_ck")+$r$$.tien_ck_hd+($r$$.tien_evoucher||0),$r$$.t_ck_nt=$r$$.details.csum("tien_ck_nt")+$r$$.tien_ck_hd+($r$$.tien_evoucher||
14
- 0),$r$$.t_tien_nt=$r$$.details.csum("tien_nt"),$r$$.t_tien=$r$$.details.csum("tien"),$r$$.t_tt=$r$$.t_tt_nt=$r$$.t_tien_hang_ct_nt+$r$$.t_thue_nt-$r$$.t_ck_nt,$r$$.con_no=$r$$.t_tt-($r$$.tien_thu||0)-($r$$.tien_thu2||0)-($r$$.tien_paymentByPoints||0),$r$$.con_no<0&&($r$$.con_no=0),$r$$.t_tien_xuat=$r$$.details.csum("tien_xuat"),$r$$.t_tien_xuat_nt=$r$$.details.csum("tien_xuat_nt"))},taothongtinchuyenkhoan=async($bank_bin$jscomp$1_user$$,$r$$)=>{if($r$$.trang_thai!="6"&&$r$$.trang_thai!="9"){var $amount_bank_name_bank_name$$=
15
- $r$$.t_tt-($r$$.tien_paymentByPoints||0);if($amount_bank_name_bank_name$$>0&&$r$$.pt_thanh_toan){var $amount$jscomp$2_bank_bin_pttt_pttt$$=await ptthanhtoan.findOne({id_app:$r$$.id_app,_id:$r$$.pt_thanh_toan,payment_service:"bank"}).lean();if($amount$jscomp$2_bank_bin_pttt_pttt$$&&$amount$jscomp$2_bank_bin_pttt_pttt$$.payment_service=="bank"&&$bank_bin$jscomp$1_user$$.current_app_info){$amount_bank_name_bank_name$$=($amount$jscomp$2_bank_bin_pttt_pttt$$.bank_configs||{}).bank_name||$bank_bin$jscomp$1_user$$.current_app_info.ten_ngan_hang;
16
- var $bank_account_number_bank_account_number$$=($amount$jscomp$2_bank_bin_pttt_pttt$$.bank_configs||{}).bank_account_number||$bank_bin$jscomp$1_user$$.current_app_info.tai_khoan_ngan_hang,$bank_account_name_bank_account_name$$=($amount$jscomp$2_bank_bin_pttt_pttt$$.bank_configs||{}).bank_account_name||$bank_bin$jscomp$1_user$$.current_app_info.ten_chu_tai_khoan;$amount$jscomp$2_bank_bin_pttt_pttt$$=($amount$jscomp$2_bank_bin_pttt_pttt$$.bank_configs||{}).so_bin||$bank_bin$jscomp$1_user$$.current_app_info.so_bin;
17
- var $amount$jscomp$1_purpose$$=$r$$.t_tt,$purpose_qrcode$$=`TTDH ${$r$$.so_ct} ${$r$$._id.toString()}`;const $qrcode$$=QRPay.initVietQR({bankBin:$amount$jscomp$2_bank_bin_pttt_pttt$$,bankNumber:$bank_account_number_bank_account_number$$,amount:$amount$jscomp$1_purpose$$.toString(),purpose:$purpose_qrcode$$}).build();$r$$.bank_payment_info={bank_name:$amount_bank_name_bank_name$$,bank_bin:$amount$jscomp$2_bank_bin_pttt_pttt$$,bank_account_number:$bank_account_number_bank_account_number$$,bank_account_name:$bank_account_name_bank_account_name$$,
18
- amount:$amount$jscomp$1_purpose$$,purpose:$purpose_qrcode$$,qrcode:$qrcode$$}}else $r$$.bank_payment_info=void 0}else $r$$.bank_payment_info=void 0;$amount_bank_name_bank_name$$=$r$$.t_tt-($r$$.tien_thu||0)-($r$$.tien_paymentByPoints||0);$amount_bank_name_bank_name$$>0&&$r$$.pt_thanh_toan2?($amount$jscomp$2_bank_bin_pttt_pttt$$=await ptthanhtoan.findOne({id_app:$r$$.id_app,_id:$r$$.pt_thanh_toan2,payment_service:"bank"}).lean())&&$amount$jscomp$2_bank_bin_pttt_pttt$$.payment_service=="bank"&&$bank_bin$jscomp$1_user$$.current_app_info?
19
- ($amount_bank_name_bank_name$$=($amount$jscomp$2_bank_bin_pttt_pttt$$.bank_configs||{}).bank_name||$bank_bin$jscomp$1_user$$.current_app_info.ten_ngan_hang,$bank_account_number_bank_account_number$$=($amount$jscomp$2_bank_bin_pttt_pttt$$.bank_configs||{}).bank_account_number||$bank_bin$jscomp$1_user$$.current_app_info.tai_khoan_ngan_hang,$bank_account_name_bank_account_name$$=($amount$jscomp$2_bank_bin_pttt_pttt$$.bank_configs||{}).bank_account_name||$bank_bin$jscomp$1_user$$.current_app_info.ten_chu_tai_khoan,
20
- $bank_bin$jscomp$1_user$$=($amount$jscomp$2_bank_bin_pttt_pttt$$.bank_configs||{}).so_bin||$bank_bin$jscomp$1_user$$.current_app_info.so_bin,$amount$jscomp$2_bank_bin_pttt_pttt$$=$r$$.t_tt,$amount$jscomp$1_purpose$$=`TTDH ${$r$$.so_ct} ${$r$$._id.toString()}`,$purpose_qrcode$$=QRPay.initVietQR({bankBin:$bank_bin$jscomp$1_user$$,bankNumber:$bank_account_number_bank_account_number$$,amount:$amount$jscomp$2_bank_bin_pttt_pttt$$.toString(),purpose:$amount$jscomp$1_purpose$$}).build(),$r$$.bank_payment_info2=
21
- {bank_name:$amount_bank_name_bank_name$$,bank_bin:$bank_bin$jscomp$1_user$$,bank_account_number:$bank_account_number_bank_account_number$$,bank_account_name:$bank_account_name_bank_account_name$$,amount:$amount$jscomp$2_bank_bin_pttt_pttt$$,purpose:$amount$jscomp$1_purpose$$,qrcode:$purpose_qrcode$$}):$r$$.bank_payment_info2=void 0:$r$$.bank_payment_info2=void 0}},getPointBalance=async($id_app$$,$user$$)=>new Promise(($resolve$$,$reject$$)=>{ckdiem({id_app:$id_app$$,email:$user$$},($e$$,$rs$$)=>{if($e$$)return $reject$$(Error($e$$));
22
- $resolve$$($rs$$.length===0?0:$rs$$[0].ton00)})}),createTransactionBonus=async function($obj$$){if($obj$$.trang_thai!=="5")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"),null;let $kh$$=await customer.findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh});if(!$kh$$)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"),
23
- null;const $receiver$$=$kh$$.of_user||$kh$$.ma_kh;let $lan_mua$$=(await model.find({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh,ngay_ct:{$lte:$obj$$.ngay_ct}})).length+1;let $now$$=moment(new Date).startOf("date").toDate();var $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}).lean(),$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,
24
- "",$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:[null,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).lean();return $ckdiemthuong_ty_le_diem_thuong$$.length>0?($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)&&
25
- ($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($amount$$=(await Promise.all($amount$$)).reduce(($a$$,$b$$)=>$a$$+$b$$,0)){var $old_trans$$=await transaction.findOne({id_ct:$obj$$._id.toString()+":bonus"});if(!$old_trans$$||$old_trans$$.amount!==$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"),
26
- await transaction.createTrans({id_app:$obj$$.id_app,sender_email:$obj$$.id_app,receiver_email:$receiver$$,amount:$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=async function($obj$$,
27
- $user_payment$$){await transaction.deleteTrans({id_ct:$obj$$._id.toString()});let $amount$$=$obj$$.paymentByPoints;$amount$$&&($user_payment$$=$user_payment$$||$obj$$.user_created,await transaction.createTrans({id_app:$obj$$.id_app,sender_email:$user_payment$$,receiver_email:$obj$$.id_app,amount:$amount$$,description:"Thanh to\u00e1n cho bill "+$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$$=
28
- $obj$$.details.map($d$$=>($d$$.tien_hang_ct_nt||0)-($d$$.tien_ck_nt||0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0);return($obj$$.evouchers||[]).map($ev$$=>new Promise(($resolve$$,$reject$$)=>{(async()=>{var $cust_date_created_id_ct_so_tien_giam$$=($obj$$._id||"").toString();const $_e$$=await Evoucher.findOne({ma:$ev$$.ma,id_app:$user$$.current_id_app});if(!$_e$$)return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} kh\u00f4ng t\u1ed3n t\u1ea1i`));if($_e$$.id_ct_used&&$_e$$.id_ct_used!==$cust_date_created_id_ct_so_tien_giam$$)return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} \u0111\u00e3 \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng`));
29
- if($_e$$.so_lan_sd>=1&&$_e$$.id_ct_useds&&$_e$$.id_ct_useds.length>0&&($_e$$.id_ct_useds=[...(new Set([...$_e$$.id_ct_useds]))],$_e$$.id_ct_useds.length>=$_e$$.so_lan_sd&&(!$obj$$._id||$_e$$.id_ct_useds.indexOf($obj$$._id)<0)))return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} \u0111\u00e3 \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng h\u1ebft`));if($_e$$.user){if(!$obj$$.ma_kh)return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} n\u00e0y ch\u1ec9 s\u1eed d\u1ee5ng cho m\u1ed9t kh\u00e1ch h\u00e0ng c\u1ee5 th\u1ec3`));
30
- $cust_date_created_id_ct_so_tien_giam$$=await global.getModel("customer").findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh},{of_user:1});if(!$cust_date_created_id_ct_so_tien_giam$$||$cust_date_created_id_ct_so_tien_giam$$.of_user!==$_e$$.user)return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} kh\u00f4ng th\u1ec3 \u00e1p d\u1ee5ng cho kh\u00e1ch h\u00e0ng n\u00e0y`))}$cust_date_created_id_ct_so_tien_giam$$=new Date($obj$$.date_created);if(moment($_e$$.hieu_luc_den).endOf("date").toDate().getTime()<
31
- $cust_date_created_id_ct_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()}`));if($_e$$.vts&&$_e$$.vts.length>
32
- 0&&$_e$$.sl_toi_thieu){let $sl_dap_ung$$=0;$_e$$.vts.forEach($vt$$=>{var $ds$jscomp$1_tien$$=$obj$$.details.filter($d$$=>$d$$.ma_vt===$vt$$.ma_vt&&(!$vt$$.ma_tt1||$vt$$.ma_tt1===$d$$.ma_tt1)&&(!$vt$$.ma_tt2||$vt$$.ma_tt2===$d$$.ma_tt2)&&(!$vt$$.ma_tt3||$vt$$.ma_tt3===$d$$.ma_tt3));if($ds$jscomp$1_tien$$.length!=0){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_ct_nt||0)-($d$$.tien_ck_nt||
33
- 0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$vt$$.sl_tu&&$so_luong$$<$vt$$.sl_tu||$vt$$.sl_den&&$so_luong$$>$vt$$.sl_den||$vt$$.gt_tu&&$ds$jscomp$1_tien$$<$vt$$.gt_tu||$vt$$.gt_den&&$ds$jscomp$1_tien$$>$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`))}$cust_date_created_id_ct_so_tien_giam$$=$_e$$.so_tien;
34
- $_e$$.ty_le&&($cust_date_created_id_ct_so_tien_giam$$=Math.roundBy($gt_don_hang$$*$_e$$.ty_le/100));$_e$$.so_tien_max&&$cust_date_created_id_ct_so_tien_giam$$>$_e$$.so_tien_max&&($cust_date_created_id_ct_so_tien_giam$$=$_e$$.so_tien_max);if($ev$$.so_tien_giam!==$cust_date_created_id_ct_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=$cust_date_created_id_ct_so_tien_giam$$;$resolve$$(!0)})()}))},updateEvoucher=
35
- async($id_app$jscomp$1_rs$$,$evoucher_code$$,$id_ct$$)=>{$id_ct$$=$id_ct$$.toString();var $e$$=await Evoucher.findOne({ma:$evoucher_code$$,id_app:$id_app$jscomp$1_rs$$});$e$$?($e$$=$e$$.id_ct_useds||[],$e$$.push($id_ct$$),$e$$=[...(new Set($e$$))],$id_app$jscomp$1_rs$$=await Evoucher.findOneAndUpdate({ma:$evoucher_code$$,id_app:$id_app$jscomp$1_rs$$},{id_ct_useds:$e$$}),console.log("update id_ct_useds",$evoucher_code$$,$e$$,$id_app$jscomp$1_rs$$)):console.error("can't find evoucher",$evoucher_code$$)},
36
- deleteEvoucher=async($id_app$jscomp$2_id_ct_useds$$,$evoucher_code$$,$id_ct$$)=>{if($evoucher_code$$){$id_ct$$=$id_ct$$.toString();var $e$jscomp$2_rs$$=await Evoucher.findOne({id_app:$id_app$jscomp$2_id_ct_useds$$,ma:$evoucher_code$$});$e$jscomp$2_rs$$&&($id_app$jscomp$2_id_ct_useds$$=($e$jscomp$2_rs$$.id_ct_useds||[]).filter($ct$$=>$ct$$!==$id_ct$$),$e$jscomp$2_rs$$=await Evoucher.findOneAndUpdate({_id:$e$jscomp$2_rs$$._id},{id_ct_useds:$id_app$jscomp$2_id_ct_useds$$}),console.log("update id_ct_useds",
37
- $evoucher_code$$,$id_app$jscomp$2_id_ct_useds$$,$e$jscomp$2_rs$$))}},valid=async function($_opt_t_tien_evoucher_user$$,$obj$$,$next$$,$pre_obj_tien_con_lai$$){$pre_obj_tien_con_lai$$&&($obj$$._id=$pre_obj_tien_con_lai$$._id,$obj$$.details=$obj$$.details||$pre_obj_tien_con_lai$$.details||[],$obj$$.evouchers=$obj$$.evouchers||$pre_obj_tien_con_lai$$.evouchers||[]);$obj$$.details=$obj$$.details||[];if($obj$$.signature&&!await Wallet.verifySignature($obj$$.id_app,$obj$$.sign_user,$obj$$.sign_data,$obj$$.signature))return $next$$("Signature is not valid");
38
- try{await Promise.all(($obj$$.details||[]).map($detail$$=>(async()=>{if($detail$$.signature&&!await Wallet.verifySignature($obj$$.id_app,$detail$$.sign_user,$detail$$.sign_data,$detail$$.signature))throw"Signature is not valid";})()))}catch($e$$){return $next$$($e$$||$e$$.message)}await $obj$$.details.asyncJoinModel2($obj$$.id_app,vat,{where:"ma_thue",fields:["thue_suat","tk_thue_co","tk_thue_co_treo"]});for(let $i$$=0;$i$$<$obj$$.details.length;$i$$++){const $detail$$=$obj$$.details[$i$$];if($detail$$.line==
39
- null||$detail$$.line==void 0)$detail$$.line=(new Date).getTime();$detail$$.tien_hang=$detail$$.tien_hang_nt=Math.roundBy($detail$$.tien_hang_nt);$detail$$.tien_ck=$detail$$.tien_ck_nt=Math.roundBy($detail$$.tien_ck_nt||0);$detail$$.gia_ban=$detail$$.gia_ban_nt;$detail$$.ma_kho=$obj$$.ma_kho;$detail$$.tien_xuat=$detail$$.tien_xuat_nt=Math.roundBy($detail$$.tien_xuat_nt||0);tinhtienthue($detail$$);$detail$$.options=$detail$$.options||[];for(let $i_o$$=0;$i_o$$<$detail$$.options.length;$i_o$$++){let $o$$=
40
- $detail$$.options[0];$o$$.details=$o$$.details||[];await $o$$.details.asyncJoinModel2($obj$$.id_app,vat,{where:"ma_thue",fields:["thue_suat","tk_thue_co","tk_thue_co_treo"]});$o$$.details.filter($d$$=>$d$$.sl_xuat).forEach($d$$=>{$d$$.tien_hang=$d$$.tien_hang_nt=$d$$.sl_xuat*($d$$.gia_ban_nt||0);tinhtienthue($d$$)});$o$$.tien_hang_nt=$o$$.details.map($d$$=>$d$$.tien_hang_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$o$$.tien_hang_ct_nt=$o$$.details.map($d$$=>$d$$.tien_hang_ct_nt).reduce(($a$$,$b$$)=>$a$$+
41
- $b$$,0);$o$$.tien_thue_nt=$o$$.details.map($d$$=>$d$$.tien_thue_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0)}$detail$$.tien_hang_options=$detail$$.options.map($o$$=>$o$$.tien_hang_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$detail$$.tien_hang_options_ct=$detail$$.options.map($o$$=>$o$$.tien_hang_ct_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$detail$$.tien_thue_options=$detail$$.options.map($o$$=>$o$$.tien_thue_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$detail$$.tien=$detail$$.tien_nt=$detail$$.tien_hang_ct_nt-$detail$$.tien_ck_nt+
42
- $detail$$.tien_thue_nt+$detail$$.tien_hang_options_ct+$detail$$.tien_thue_options}await $obj$$.details.filter($d$$=>!$d$$.ma_dvt&&$d$$.ma_tt1).asyncJoinModel2($_opt_t_tien_evoucher_user$$.current_id_app,dmtt,{where:{ma_vt:"ma_vt",ma_tt1:"ma_tt"},fields:"ma_dvt"});await $obj$$.details.filter($d$$=>!$d$$.ma_dvt&&$d$$.ma_tt2).asyncJoinModel2($_opt_t_tien_evoucher_user$$.current_id_app,dmtt,{where:{ma_vt:"ma_vt",ma_tt2:"ma_tt"},fields:"ma_dvt"});await $obj$$.details.filter($d$$=>!$d$$.ma_dvt&&$d$$.ma_tt3).asyncJoinModel2($_opt_t_tien_evoucher_user$$.current_id_app,
11
+ $user$$.current_app_info&&($user$$.current_app_info.options||{}).tinh_lai_chiet_khau_pbl!=0&&dmchietkhauhd.tinhChietKhau($user$$,$obj$$.id_app,$obj$$,$t_tien_hang_ct_nt$$-$t_ck_nt$$)}},tinhtienthue=$detail$$=>{$detail$$.tien_thue_nt?$detail$$.tien_thue=$detail$$.tien_thue_nt:($detail$$.thue_suat=$detail$$.thue_suat||0,$detail$$.gia_ban_ct_nt=$detail$$.gia_ban_ct=Math.roundBy($detail$$.gia_ban_nt/(1+$detail$$.thue_suat/100)),$detail$$.tien_hang_ct=$detail$$.tien_hang_ct_nt=Math.roundBy($detail$$.sl_xuat*
12
+ $detail$$.gia_ban_ct_nt),$detail$$.ty_le_ck&&($detail$$.tien_ck_nt=Math.roundBy($detail$$.tien_hang_ct_nt*$detail$$.ty_le_ck/100)),$detail$$.tien_thue=$detail$$.tien_thue_nt=Math.roundBy(($detail$$.tien_hang_ct_nt-$detail$$.tien_ck_nt)*$detail$$.thue_suat/100))},tinhtongtien=$r$$=>{$r$$.details&&($r$$.details.forEach($d$$=>{$d$$.sl_order=$d$$.sl_order||$d$$.sl_xuat}),$r$$.t_sl_order=$r$$.details.csum("sl_order"),$r$$.t_sl=$r$$.details.csum("sl_xuat"),$r$$.t_tien_hang_ct=$r$$.details.csum("tien_hang_ct")+
13
+ $r$$.details.csum("tien_hang_options_ct"),$r$$.t_tien_hang_ct_nt=$r$$.details.csum("tien_hang_ct_nt")+$r$$.details.csum("tien_hang_options_ct"),$r$$.t_thue_nt=$r$$.details.csum("tien_thue_nt")+$r$$.details.csum("tien_thue_options"),$r$$.t_thue=$r$$.details.csum("tien_thue")+$r$$.details.csum("tien_thue_options"),$r$$.t_tien_hang=$r$$.t_tien_hang_ct+$r$$.t_thue,$r$$.t_tien_hang_nt=$r$$.t_tien_hang_ct_nt+$r$$.t_thue_nt,$r$$.t_ck=$r$$.details.csum("tien_ck")+$r$$.tien_ck_hd+($r$$.tien_evoucher||0),$r$$.t_ck_nt=
14
+ $r$$.details.csum("tien_ck_nt")+$r$$.tien_ck_hd+($r$$.tien_evoucher||0),$r$$.t_tien_nt=$r$$.details.csum("tien_nt"),$r$$.t_tien=$r$$.details.csum("tien"),$r$$.t_tt=$r$$.t_tt_nt=$r$$.t_tien_hang_ct_nt+$r$$.t_thue_nt-$r$$.t_ck_nt,$r$$.con_no=$r$$.t_tt-($r$$.tien_thu||0)-($r$$.tien_thu2||0)-($r$$.tien_paymentByPoints||0),$r$$.con_no<0&&($r$$.con_no=0),$r$$.t_tien_xuat=$r$$.details.csum("tien_xuat"),$r$$.t_tien_xuat_nt=$r$$.details.csum("tien_xuat_nt"))},taothongtinchuyenkhoan=async($bank_bin$jscomp$1_user$$,
15
+ $r$$)=>{if($r$$.trang_thai!="6"&&$r$$.trang_thai!="9"){var $amount_bank_name_bank_name$$=$r$$.t_tt-($r$$.tien_paymentByPoints||0);if($amount_bank_name_bank_name$$>0&&$r$$.pt_thanh_toan){var $amount$jscomp$2_bank_bin_pttt_pttt$$=await ptthanhtoan.findOne({id_app:$r$$.id_app,_id:$r$$.pt_thanh_toan,payment_service:"bank"}).lean();if($amount$jscomp$2_bank_bin_pttt_pttt$$&&$amount$jscomp$2_bank_bin_pttt_pttt$$.payment_service=="bank"&&$bank_bin$jscomp$1_user$$.current_app_info){$amount_bank_name_bank_name$$=
16
+ ($amount$jscomp$2_bank_bin_pttt_pttt$$.bank_configs||{}).bank_name||$bank_bin$jscomp$1_user$$.current_app_info.ten_ngan_hang;var $bank_account_number_bank_account_number$$=($amount$jscomp$2_bank_bin_pttt_pttt$$.bank_configs||{}).bank_account_number||$bank_bin$jscomp$1_user$$.current_app_info.tai_khoan_ngan_hang,$bank_account_name_bank_account_name$$=($amount$jscomp$2_bank_bin_pttt_pttt$$.bank_configs||{}).bank_account_name||$bank_bin$jscomp$1_user$$.current_app_info.ten_chu_tai_khoan;$amount$jscomp$2_bank_bin_pttt_pttt$$=
17
+ ($amount$jscomp$2_bank_bin_pttt_pttt$$.bank_configs||{}).so_bin||$bank_bin$jscomp$1_user$$.current_app_info.so_bin;var $amount$jscomp$1_purpose$$=$r$$.t_tt,$purpose_qrcode$$=`TTDH ${$r$$.so_ct} ${$r$$._id.toString()}`;const $qrcode$$=QRPay.initVietQR({bankBin:$amount$jscomp$2_bank_bin_pttt_pttt$$,bankNumber:$bank_account_number_bank_account_number$$,amount:$amount$jscomp$1_purpose$$.toString(),purpose:$purpose_qrcode$$}).build();$r$$.bank_payment_info={bank_name:$amount_bank_name_bank_name$$,bank_bin:$amount$jscomp$2_bank_bin_pttt_pttt$$,
18
+ bank_account_number:$bank_account_number_bank_account_number$$,bank_account_name:$bank_account_name_bank_account_name$$,amount:$amount$jscomp$1_purpose$$,purpose:$purpose_qrcode$$,qrcode:$qrcode$$}}else $r$$.bank_payment_info=void 0}else $r$$.bank_payment_info=void 0;$amount_bank_name_bank_name$$=$r$$.t_tt-($r$$.tien_thu||0)-($r$$.tien_paymentByPoints||0);$amount_bank_name_bank_name$$>0&&$r$$.pt_thanh_toan2?($amount$jscomp$2_bank_bin_pttt_pttt$$=await ptthanhtoan.findOne({id_app:$r$$.id_app,_id:$r$$.pt_thanh_toan2,
19
+ payment_service:"bank"}).lean())&&$amount$jscomp$2_bank_bin_pttt_pttt$$.payment_service=="bank"&&$bank_bin$jscomp$1_user$$.current_app_info?($amount_bank_name_bank_name$$=($amount$jscomp$2_bank_bin_pttt_pttt$$.bank_configs||{}).bank_name||$bank_bin$jscomp$1_user$$.current_app_info.ten_ngan_hang,$bank_account_number_bank_account_number$$=($amount$jscomp$2_bank_bin_pttt_pttt$$.bank_configs||{}).bank_account_number||$bank_bin$jscomp$1_user$$.current_app_info.tai_khoan_ngan_hang,$bank_account_name_bank_account_name$$=
20
+ ($amount$jscomp$2_bank_bin_pttt_pttt$$.bank_configs||{}).bank_account_name||$bank_bin$jscomp$1_user$$.current_app_info.ten_chu_tai_khoan,$bank_bin$jscomp$1_user$$=($amount$jscomp$2_bank_bin_pttt_pttt$$.bank_configs||{}).so_bin||$bank_bin$jscomp$1_user$$.current_app_info.so_bin,$amount$jscomp$2_bank_bin_pttt_pttt$$=$r$$.t_tt,$amount$jscomp$1_purpose$$=`TTDH ${$r$$.so_ct} ${$r$$._id.toString()}`,$purpose_qrcode$$=QRPay.initVietQR({bankBin:$bank_bin$jscomp$1_user$$,bankNumber:$bank_account_number_bank_account_number$$,
21
+ amount:$amount$jscomp$2_bank_bin_pttt_pttt$$.toString(),purpose:$amount$jscomp$1_purpose$$}).build(),$r$$.bank_payment_info2={bank_name:$amount_bank_name_bank_name$$,bank_bin:$bank_bin$jscomp$1_user$$,bank_account_number:$bank_account_number_bank_account_number$$,bank_account_name:$bank_account_name_bank_account_name$$,amount:$amount$jscomp$2_bank_bin_pttt_pttt$$,purpose:$amount$jscomp$1_purpose$$,qrcode:$purpose_qrcode$$}):$r$$.bank_payment_info2=void 0:$r$$.bank_payment_info2=void 0}},getPointBalance=
22
+ async($id_app$$,$user$$)=>new Promise(($resolve$$,$reject$$)=>{ckdiem({id_app:$id_app$$,email:$user$$},($e$$,$rs$$)=>{if($e$$)return $reject$$(Error($e$$));$resolve$$($rs$$.length===0?0:$rs$$[0].ton00)})}),createTransactionBonus=async function($obj$$){if($obj$$.trang_thai!=="5")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"),null;let $kh$$=await customer.findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh});
23
+ if(!$kh$$)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"),null;const $receiver$$=$kh$$.of_user||$kh$$.ma_kh;let $lan_mua$$=(await model.find({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh,ngay_ct:{$lte:$obj$$.ngay_ct}})).length+1;let $now$$=moment(new Date).startOf("date").toDate();var $amount$$=$obj$$.details.filter($d$$=>$d$$.tien_hang).map(async $d$$=>{var $amount$$=await dmvt.findOne({ma_vt:$d$$.ma_vt,
24
+ id_app:$obj$$.id_app}).lean(),$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:[null,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).lean();return $ckdiemthuong_ty_le_diem_thuong$$.length>
25
+ 0?($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($amount$$=(await Promise.all($amount$$)).reduce(($a$$,$b$$)=>$a$$+$b$$,0)){var $old_trans$$=await transaction.findOne({id_ct:$obj$$._id.toString()+
26
+ ":bonus"});if(!$old_trans$$||$old_trans$$.amount!==$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:$receiver$$,amount:$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()+
27
+ ":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$$,$user_payment$$){await transaction.deleteTrans({id_ct:$obj$$._id.toString()});let $amount$$=$obj$$.paymentByPoints;$amount$$&&($user_payment$$=$user_payment$$||$obj$$.user_created,await transaction.createTrans({id_app:$obj$$.id_app,sender_email:$user_payment$$,receiver_email:$obj$$.id_app,
28
+ amount:$amount$$,description:"Thanh to\u00e1n cho bill "+$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_ct_nt||0)-($d$$.tien_ck_nt||0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0);return($obj$$.evouchers||[]).map($ev$$=>new Promise(($resolve$$,$reject$$)=>{(async()=>{var $cust_date_created_id_ct_so_tien_giam$$=($obj$$._id||"").toString();const $_e$$=
29
+ await Evoucher.findOne({ma:$ev$$.ma,id_app:$user$$.current_id_app});if(!$_e$$)return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} kh\u00f4ng t\u1ed3n t\u1ea1i`));if($_e$$.id_ct_used&&$_e$$.id_ct_used!==$cust_date_created_id_ct_so_tien_giam$$)return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} \u0111\u00e3 \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng`));if($_e$$.so_lan_sd>=1&&$_e$$.id_ct_useds&&$_e$$.id_ct_useds.length>0&&($_e$$.id_ct_useds=[...(new Set([...$_e$$.id_ct_useds]))],$_e$$.id_ct_useds.length>=
30
+ $_e$$.so_lan_sd&&(!$obj$$._id||$_e$$.id_ct_useds.indexOf($obj$$._id)<0)))return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} \u0111\u00e3 \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng h\u1ebft`));if($_e$$.user){if(!$obj$$.ma_kh)return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} n\u00e0y ch\u1ec9 s\u1eed d\u1ee5ng cho m\u1ed9t kh\u00e1ch h\u00e0ng c\u1ee5 th\u1ec3`));$cust_date_created_id_ct_so_tien_giam$$=await global.getModel("customer").findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh},{of_user:1});
31
+ if(!$cust_date_created_id_ct_so_tien_giam$$||$cust_date_created_id_ct_so_tien_giam$$.of_user!==$_e$$.user)return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} kh\u00f4ng th\u1ec3 \u00e1p d\u1ee5ng cho kh\u00e1ch h\u00e0ng n\u00e0y`))}$cust_date_created_id_ct_so_tien_giam$$=new Date($obj$$.date_created);if(moment($_e$$.hieu_luc_den).endOf("date").toDate().getTime()<$cust_date_created_id_ct_so_tien_giam$$.getTime())return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} \u0111\u00e3 h\u1ebft h\u1ea1n s\u1eed d\u1ee5ng`));
32
+ 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()}`));if($_e$$.vts&&$_e$$.vts.length>0&&$_e$$.sl_toi_thieu){let $sl_dap_ung$$=0;$_e$$.vts.forEach($vt$$=>{var $ds$jscomp$1_tien$$=$obj$$.details.filter($d$$=>$d$$.ma_vt===$vt$$.ma_vt&&(!$vt$$.ma_tt1||
33
+ $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($ds$jscomp$1_tien$$.length!=0){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_ct_nt||0)-($d$$.tien_ck_nt||0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$vt$$.sl_tu&&$so_luong$$<$vt$$.sl_tu||$vt$$.sl_den&&$so_luong$$>$vt$$.sl_den||$vt$$.gt_tu&&$ds$jscomp$1_tien$$<$vt$$.gt_tu||
34
+ $vt$$.gt_den&&$ds$jscomp$1_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`))}$cust_date_created_id_ct_so_tien_giam$$=$_e$$.so_tien;$_e$$.ty_le&&($cust_date_created_id_ct_so_tien_giam$$=Math.roundBy($gt_don_hang$$*$_e$$.ty_le/100));$_e$$.so_tien_max&&$cust_date_created_id_ct_so_tien_giam$$>
35
+ $_e$$.so_tien_max&&($cust_date_created_id_ct_so_tien_giam$$=$_e$$.so_tien_max);if($ev$$.so_tien_giam!==$cust_date_created_id_ct_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=$cust_date_created_id_ct_so_tien_giam$$;$resolve$$(!0)})()}))},updateEvoucher=async($id_app$jscomp$1_rs$$,$evoucher_code$$,$id_ct$$)=>{$id_ct$$=$id_ct$$.toString();var $e$$=await Evoucher.findOne({ma:$evoucher_code$$,id_app:$id_app$jscomp$1_rs$$});
36
+ $e$$?($e$$=$e$$.id_ct_useds||[],$e$$.push($id_ct$$),$e$$=[...(new Set($e$$))],$id_app$jscomp$1_rs$$=await Evoucher.updateOne({ma:$evoucher_code$$,id_app:$id_app$jscomp$1_rs$$},{id_ct_useds:$e$$}),console.log("update id_ct_useds",$evoucher_code$$,$e$$,$id_app$jscomp$1_rs$$)):console.error("can't find evoucher",$evoucher_code$$)},deleteEvoucher=async($id_app$jscomp$2_id_ct_useds$$,$evoucher_code$$,$id_ct$$)=>{if($evoucher_code$$){$id_ct$$=$id_ct$$.toString();var $e$jscomp$2_rs$$=await Evoucher.findOne({id_app:$id_app$jscomp$2_id_ct_useds$$,
37
+ ma:$evoucher_code$$});$e$jscomp$2_rs$$&&($id_app$jscomp$2_id_ct_useds$$=($e$jscomp$2_rs$$.id_ct_useds||[]).filter($ct$$=>$ct$$!==$id_ct$$),$e$jscomp$2_rs$$=await Evoucher.updateOne({_id:$e$jscomp$2_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$2_rs$$))}},valid=async function($_opt_t_tien_evoucher_user$$,$obj$$,$next$$,$pre_obj_tien_con_lai$$){$pre_obj_tien_con_lai$$&&($obj$$._id=$pre_obj_tien_con_lai$$._id,
38
+ $obj$$.details=$obj$$.details||$pre_obj_tien_con_lai$$.details||[],$obj$$.evouchers=$obj$$.evouchers||$pre_obj_tien_con_lai$$.evouchers||[]);$obj$$.details=$obj$$.details||[];if($obj$$.signature&&!await Wallet.verifySignature($obj$$.id_app,$obj$$.sign_user,$obj$$.sign_data,$obj$$.signature))return $next$$("Signature is not valid");try{await Promise.all(($obj$$.details||[]).map($detail$$=>(async()=>{if($detail$$.signature&&!await Wallet.verifySignature($obj$$.id_app,$detail$$.sign_user,$detail$$.sign_data,
39
+ $detail$$.signature))throw"Signature is not valid";})()))}catch($e$$){return $next$$($e$$||$e$$.message)}await $obj$$.details.asyncJoinModel2($obj$$.id_app,vat,{where:"ma_thue",fields:["thue_suat","tk_thue_co","tk_thue_co_treo"]});for(let $i$$=0;$i$$<$obj$$.details.length;$i$$++){const $detail$$=$obj$$.details[$i$$];if($detail$$.line==null||$detail$$.line==void 0)$detail$$.line=(new Date).getTime();$detail$$.tien_hang=$detail$$.tien_hang_nt=Math.roundBy($detail$$.tien_hang_nt);$detail$$.tien_ck=$detail$$.tien_ck_nt=
40
+ Math.roundBy($detail$$.tien_ck_nt||0);$detail$$.gia_ban=$detail$$.gia_ban_nt;$detail$$.ma_kho=$obj$$.ma_kho;$detail$$.tien_xuat=$detail$$.tien_xuat_nt=Math.roundBy($detail$$.tien_xuat_nt||0);tinhtienthue($detail$$);$detail$$.options=$detail$$.options||[];for(let $i_o$$=0;$i_o$$<$detail$$.options.length;$i_o$$++){let $o$$=$detail$$.options[0];$o$$.details=$o$$.details||[];await $o$$.details.filter($d$$=>!$d$$.ma_thue).asyncJoinModel2($_opt_t_tien_evoucher_user$$.current_id_app,dmvt,{where:"ma_vt",
41
+ fields:["ma_thue"]});await $o$$.details.asyncJoinModel2($obj$$.id_app,vat,{where:"ma_thue",fields:["thue_suat","tk_thue_co","tk_thue_co_treo"]});$o$$.details.filter($d$$=>$d$$.sl_xuat).forEach($d$$=>{$d$$.tien_hang=$d$$.tien_hang_nt=$d$$.sl_xuat*($d$$.gia_ban_nt||0);tinhtienthue($d$$)});$o$$.tien_hang_nt=$o$$.details.map($d$$=>$d$$.tien_hang_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$o$$.tien_hang_ct_nt=$o$$.details.map($d$$=>$d$$.tien_hang_ct_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$o$$.tien_thue_nt=$o$$.details.map($d$$=>
42
+ $d$$.tien_thue_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0)}$detail$$.tien_hang_options=$detail$$.options.map($o$$=>$o$$.tien_hang_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$detail$$.tien_hang_options_ct=$detail$$.options.map($o$$=>$o$$.tien_hang_ct_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$detail$$.tien_thue_options=$detail$$.options.map($o$$=>$o$$.tien_thue_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$detail$$.tien=$detail$$.tien_nt=$detail$$.tien_hang_ct_nt-$detail$$.tien_ck_nt+$detail$$.tien_thue_nt+$detail$$.tien_hang_options_ct+
43
+ $detail$$.tien_thue_options}await $obj$$.details.filter($d$$=>!$d$$.ma_dvt&&$d$$.ma_tt1).asyncJoinModel2($_opt_t_tien_evoucher_user$$.current_id_app,dmtt,{where:{ma_vt:"ma_vt",ma_tt1:"ma_tt"},fields:"ma_dvt"});await $obj$$.details.filter($d$$=>!$d$$.ma_dvt&&$d$$.ma_tt2).asyncJoinModel2($_opt_t_tien_evoucher_user$$.current_id_app,dmtt,{where:{ma_vt:"ma_vt",ma_tt2:"ma_tt"},fields:"ma_dvt"});await $obj$$.details.filter($d$$=>!$d$$.ma_dvt&&$d$$.ma_tt3).asyncJoinModel2($_opt_t_tien_evoucher_user$$.current_id_app,
43
44
  dmtt,{where:{ma_vt:"ma_vt",ma_tt3:"ma_tt"},fields:"ma_dvt"});try{const $_checkEvoucher$$=checkEvoucher($_opt_t_tien_evoucher_user$$,$obj$$,$pre_obj_tien_con_lai$$);await Promise.all($_checkEvoucher$$)}catch($e$$){return $next$$($e$$.message)}$_opt_t_tien_evoucher_user$$=$obj$$.evouchers.map($e$$=>$e$$.so_tien_giam||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$pre_obj_tien_con_lai$$=$obj$$.details.map($a$$=>($a$$.tien_hang_ct_nt||0)-($a$$.tien_ck_nt||0)+($a$$.tien_thue_nt||0)+$a$$.tien_hang_options_ct+$a$$.tien_thue_options).reduce(($a$$,
44
45
  $b$$)=>$a$$+$b$$,0)-(($obj$$.tt_tien_thuong||0)+($obj$$.tien_ck_hd||0));$_opt_t_tien_evoucher_user$$>$pre_obj_tien_con_lai$$&&($_opt_t_tien_evoucher_user$$=$pre_obj_tien_con_lai$$);$obj$$.tien_evoucher=$_opt_t_tien_evoucher_user$$;$_opt_t_tien_evoucher_user$$=await Options.findOne({id_app:$obj$$.id_app,id_func:$obj$$.ma_ct.toLowerCase()}).lean();$_opt_t_tien_evoucher_user$$=($_opt_t_tien_evoucher_user$$||{}).option||{};if($obj$$.tien_evoucher&&$_opt_t_tien_evoucher_user$$.option.phan_bo_evoucher){let $tien_evoucher_da_phan_bo$$=
45
46
  0,$tien_evoucher$$=$obj$$.tien_evoucher,$tien_evoucher_con_lai$$=$tien_evoucher$$-$tien_evoucher_da_phan_bo$$;$obj$$.details.forEach($detail$$=>{if($tien_evoucher_con_lai$$>0){var $tien_evoucher_duoc_pb_tien_hang_con_lai$$=$detail$$.tien_hang_ct_nt-($detail$$.tien_ck_nt||0)+($detail$$.tien_thue_nt||0)+$detail$$.tien_hang_options_ct+$detail$$.tien_thue_options;$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$$:
@@ -49,37 +50,36 @@ module.exports=function($router$$){const $contr$$=new controller($router$$,model
49
50
  $obj$$.t_thue_nt=$obj$$.details.csum("tien_thue_nt")+$obj$$.details.csum("tien_thue_options");$obj$$.t_tt=$obj$$.t_tien_hang_ct+$obj$$.t_thue-$obj$$.t_ck;$obj$$.t_tt_nt=$obj$$.t_tien_hang_ct_nt+$obj$$.t_thue_nt-$obj$$.t_ck_nt;$obj$$.con_no=$obj$$.t_tt_nt-($obj$$.tien_paymentByPoints||0)-($obj$$.tien_thu||0)-($obj$$.tien_thu2||0);$obj$$.con_no<0&&($obj$$.con_no=0);let $product_details$$=[...$obj$$.details.map($d$$=>({...$d$$}))];$product_details$$.forEach($d$$=>{$d$$={...$d$$};$d$$.promotion&&$d$$.promotion.details_km&&
50
51
  $d$$.promotion.details_km.forEach($p$$=>{if($p$$.ma_vt&&$p$$.sl_km){let $_p$$={};_.extend($_p$$,$p$$,{sl_xuat:$p$$.sl_km});$product_details$$.push($_p$$)}});$d$$.combo&&$d$$.combo.length>0&&($d$$.combo.forEach($item$$=>{delete $item$$.px_gia_dd;$item$$.ma_kho=$d$$.ma_kho}),$product_details$$=[...$product_details$$,...$d$$.combo]);$d$$.options&&$d$$.options.length>0&&$d$$.options.forEach($ds$jscomp$2_o$$=>{$ds$jscomp$2_o$$=$ds$jscomp$2_o$$.details.filter($d$$=>$d$$.sl_xuat);$ds$jscomp$2_o$$.forEach($item$$=>
51
52
  {delete $item$$.px_gia_dd;$item$$.ma_kho=$d$$.ma_kho});$product_details$$=[...$product_details$$,...$ds$jscomp$2_o$$]})});$obj$$.promotion&&$obj$$.promotion.forEach($p$$=>{$p$$={...$p$$};if($p$$.ma_vt&&$p$$.sl_km){let $_p$$={};_.extend($_p$$,$p$$,{sl_xuat:$p$$.sl_km});$product_details$$.push($_p$$)}});$product_details$$=$product_details$$.filter($d$$=>!$d$$.combo||$d$$.combo.length===0);let $du_lieu_kho_kt$$;async.series({post_sokho:function($callback$$){async.series({kho:$callback$$=>{(new PostSokho($obj$$,
52
- $product_details$$,async function($detail$$,$callback$$){$detail$$.nxt=2;$detail$$.ma_kho=$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){$du_lieu_kho_kt$$=$rs$$;$callback$$($e$$,$rs$$)})},khott:$callback$$=>{(new PostBook($obj$$,$product_details$$,Sokhott,async function($detail$$,$callback$$){$detail$$.nxt=2;$detail$$.ma_kho=$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})}},($e$$,$rs$$)=>{$callback$$($e$$,$rs$$)})},post_socai:function($callback$$){Options.findOne({id_app:$obj$$.id_app,
53
- id_func:ma_ct.toLowerCase()}).lean().exec(async($details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$,$_opt$jscomp$1_tt_tt$jscomp$1_tt$$)=>{let $option$$;$option$$=$_opt$jscomp$1_tt_tt$jscomp$1_tt$$?$_opt$jscomp$1_tt_tt$jscomp$1_tt$$.option||{}:{};$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$=await dmkho.findOne({id_app:$obj$$.id_app,ma_kho:$obj$$.ma_kho}).lean()||{};let $pt$$;$obj$$.pt_thanh_toan&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan)&&
54
- ($pt$$=await ptthanhtoan.findOne({id_app:$obj$$.id_app,_id:$obj$$.pt_thanh_toan}).lean());$pt$$=$pt$$||{};$pt$$.tk_tien=$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.tk_tien||$pt$$.tk_tien;$pt$$.tk_cn=$pt$$.tk_cn||$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.tk_cn;$pt$$.tk_dt=$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.tk_dt||$pt$$.tk_dt;$pt$$.tk_gv=$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.tk_gv||
55
- $pt$$.tk_gv;$pt$$.tk_ck=$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.tk_ck||$pt$$.tk_ck;$pt$$.ma_kh||($pt$$.ma_kh=$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.ma_kh);$pt$$.ma_kh&&($pt$$.tk_tien=$pt$$.tk_cn);$option$$.tk_tien=$pt$$.tk_tien||$option$$.tk_tien||"1111";$option$$.tk_cn=$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.tk_cn||$option$$.tk_cn||"131111";$option$$.tk_dt=
56
- $pt$$.tk_dt||$option$$.tk_dt||"51111";$option$$.tk_ck=$pt$$.tk_ck||$option$$.tk_ck||"52111";$option$$.tk_gv=$pt$$.tk_gv||$option$$.tk_gv||"6321";$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$=[...$obj$$.details.map($d$$=>({...$d$$}))];let $details_ht$$=[];$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.forEach($detail$$=>{$detail$$={...$detail$$};let $tien$$=$detail$$.tien_hang_ct+$detail$$.tien_hang_options_ct,
57
- $tien_nt$$=$detail$$.tien_hang_ct_nt+$detail$$.tien_hang_options_ct;$detail$$.tk_no=$option$$.tk_tien;$detail$$.tk_co=$option$$.tk_dt;$detail$$.ma_kh||($detail$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh);$detail$$.tien_nt=$tien_nt$$;$detail$$.tien=$tien$$;$detail$$.flag="DT_"+($detail$$.ma_vt||"");$details_ht$$.push($detail$$)});$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.filter($d$$=>$d$$.tien_thue+$d$$.tien_thue_options&&($d$$.tk_thue_co_treo||$d$$.tk_thue_co)).forEach($detail$$=>
58
- {$detail$$={...$detail$$};$detail$$.tk_no=$option$$.tk_tien;$detail$$.tk_co=$detail$$.tk_thue_co_treo||$detail$$.tk_thue_co;$detail$$.ma_kh||($detail$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh);$detail$$.tien_nt=$detail$$.tien_thue_nt+$detail$$.tien_thue_options;$detail$$.tien=$detail$$.tien_thue+$detail$$.tien_thue_options;$detail$$.flag="THUE_"+($detail$$.ma_vt||"");$details_ht$$.push($detail$$)});if($details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$=$obj$$.tien_evoucher||
59
- 0)$_opt$jscomp$1_tt_tt$jscomp$1_tt$$={},$_opt$jscomp$1_tt_tt$jscomp$1_tt$$.tk_no=$obj$$.tk_no_evoucher||$option$$.tk_no_evoucher||$option$$.tk_ck,$_opt$jscomp$1_tt_tt$jscomp$1_tt$$.tk_co=$obj$$.tk_co_evoucher||$option$$.tk_co_evoucher||$option$$.tk_tien,$_opt$jscomp$1_tt_tt$jscomp$1_tt$$.tien_nt=$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$,$_opt$jscomp$1_tt_tt$jscomp$1_tt$$.tien=$_opt$jscomp$1_tt_tt$jscomp$1_tt$$.tien_nt,$_opt$jscomp$1_tt_tt$jscomp$1_tt$$.ma_kh=
60
- $pt$$.ma_kh||$obj$$.ma_kh,$_opt$jscomp$1_tt_tt$jscomp$1_tt$$.check_balance=!1,$details_ht$$.push($_opt$jscomp$1_tt_tt$jscomp$1_tt$$);if($details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$=($obj$$.tien_ck_hd||0)+$obj$$.details.map($d$$=>$d$$.tien_ck||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0))$_opt$jscomp$1_tt_tt$jscomp$1_tt$$={},$_opt$jscomp$1_tt_tt$jscomp$1_tt$$.tk_no=$option$$.tk_ck,$_opt$jscomp$1_tt_tt$jscomp$1_tt$$.tk_co=$option$$.tk_tien,$_opt$jscomp$1_tt_tt$jscomp$1_tt$$.tien=
61
- $_opt$jscomp$1_tt_tt$jscomp$1_tt$$.tien_nt=$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$,$_opt$jscomp$1_tt_tt$jscomp$1_tt$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh,$_opt$jscomp$1_tt_tt$jscomp$1_tt$$.check_balance=!1,$details_ht$$.push($_opt$jscomp$1_tt_tt$jscomp$1_tt$$);$obj$$.con_no&&($details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$={},$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.tk_no=
62
- $option$$.tk_cn,$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.tk_co=$option$$.tk_tien,$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.tien_nt=$obj$$.con_no,$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.tien=$obj$$.con_no,$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.ma_kh=$obj$$.ma_kh,$details_ht$$.push($details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$));
63
- $obj$$.tien_thu&&$pt$$.tk_cn&&$pt$$.tk_cn!==$option$$.tk_tien&&($details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$={},$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.tk_no=$pt$$.tk_cn,$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.tk_co=$option$$.tk_tien,$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.tien_nt=$obj$$.tien_thu,$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.tien=
64
- $obj$$.tien_thu,$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh,$details_ht$$.push($details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$));$obj$$.tien_thu2&&($details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$=($obj$$.pt_thanh_toan2&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan2)?await ptthanhtoan.findOne({_id:$obj$$.pt_thanh_toan2}).lean():
65
- null)||$pt$$,$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.tk_cn&&$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.ma_kh!==$pt$$.ma_kh&&($_opt$jscomp$1_tt_tt$jscomp$1_tt$$={},$_opt$jscomp$1_tt_tt$jscomp$1_tt$$.tk_no=$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.tk_cn,$_opt$jscomp$1_tt_tt$jscomp$1_tt$$.tk_co=$option$$.tk_tien,$_opt$jscomp$1_tt_tt$jscomp$1_tt$$.tien_nt=
66
- $obj$$.tien_thu2,$_opt$jscomp$1_tt_tt$jscomp$1_tt$$.tien=$obj$$.tien_thu2,$_opt$jscomp$1_tt_tt$jscomp$1_tt$$.ma_kh_no=$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.ma_kh,$_opt$jscomp$1_tt_tt$jscomp$1_tt$$.ma_kh_co=$pt$$.ma_kh,$details_ht$$.push($_opt$jscomp$1_tt_tt$jscomp$1_tt$$)));let $details_tienvon$$=[];($du_lieu_kho_kt$$||[]).forEach(function($detail$$){$detail$$.toObject&&($detail$$=$detail$$.toObject());$detail$$={...$detail$$};$detail$$.tk_no=$option$$.tk_gv||
67
- $detail$$.tk_gv;$detail$$.ma_kh||($detail$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh);$detail$$.tk_co=$detail$$.tk_vt;$detail$$.tien_nt=$detail$$.tien_xuat_nt;$detail$$.tien=$detail$$.tien_xuat;$detail$$.ma_nt="VND";$detail$$.ty_gia=1;$details_tienvon$$.push($detail$$)});$details_ht$$=$details_ht$$.concat($details_tienvon$$);$details_ht$$.forEach($d$$=>{$d$$.ma_kho=$obj$$.ma_kho});(new PostSocai($obj$$,$details_ht$$,void 0,void 0,$_options$$)).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})})}},async function($e$$,
68
- $rs$$){$rs$$&&($obj$$.details.filter($d$$=>!$d$$.px_gia_dd).forEach($detail$$=>{let $sokhos$$=($du_lieu_kho_kt$$||[]).filter($d$$=>$d$$.ma_vt==$detail$$.ma_vt&&$d$$.ma_tt1==$detail$$.ma_tt1||$d$$.ma_sp==$detail$$.ma_vt&&$d$$.ma_tt1_sp==$detail$$.ma_tt1);$detail$$.tien_xuat_nt=$detail$$.tien_xuat=$sokhos$$.map($s$$=>$s$$.tien_xuat_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$detail$$.sl_xuat&&($detail$$.gia_von_nt=$detail$$.gia_von=Math.round($detail$$.tien_xuat_nt/$detail$$.sl_xuat))}),await model.updateOne({_id:$obj$$._id},
69
- {details:$obj$$.details}));$fn$$($e$$,$rs$$)})};$contr$$.saving=async($user$$,$obj$$)=>{$obj$$.details=$obj$$.details||[];await chietkhauhd($user$$.email,$obj$$);await khuyenmaihd($obj$$);tinhtongtien($obj$$);await taothongtinchuyenkhoan($user$$,$obj$$)};$contr$$.creating=async function($user$$,$obj$$,$next$$){$obj$$.details||($obj$$.details=[]);await $obj$$.details.asyncJoinModel2($user$$.current_id_app,dmvt,{where:"ma_vt",setFields:($item$$,$ref$$)=>{$item$$.combo=$ref$$.combo||[];$item$$.ma_thue=
70
- $ref$$.ma_thue}});$obj$$.details.forEach($detail$$=>{$detail$$.combo&&$detail$$.combo.length>0&&($detail$$.combo=$detail$$.combo.map($item$$=>{$item$$=$item$$.toObject?$item$$.toObject():{...$item$$};$item$$.sl_xuat_1_combo=$item$$.sl_xuat||0;$item$$.sl_xuat=($item$$.sl_xuat_1_combo||0)*($detail$$.sl_xuat||0);$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=
71
- $item$$.sl_xuat*($item$$.tien_ck_nt||0);$item$$.tien=$item$$.tien_nt=$item$$.tien_hang_nt-($item$$.tien_ck_nt||0);return $item$$}))});$obj$$.tien_thu=Math.roundBy($obj$$.tien_thu||0);$obj$$.tien_thu2=Math.roundBy($obj$$.tien_thu2||0);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,$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.");
72
- $next$$(null,$obj$$)}catch($e$$){$next$$($e$$.message)}})};$contr$$.created=async function($user$$,$obj$$,$next$$){await createTransactionPayment($obj$$);await createTransactionBonus($obj$$);$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>updateEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$obj$$.trang_thai=="5"&&($obj$$.trang_thai="6",await model.updateOne({_id:$obj$$._id},{trang_thai:"6"}));$next$$(null,$obj$$)};$contr$$.updating=async function($user$$,$data$$,$obj$$,$next$$){$data$$.details||
73
- ($data$$.details=$obj$$.details||[]);$data$$.evouchers||($data$$.evouchers=$obj$$.evouchers||[]);await $data$$.details.asyncJoinModel2($user$$.current_id_app,dmvt,{where:"ma_vt",setFields:($item$$,$ref$$)=>{let $old_combo$$=($item$$.combo||[]).map($i$$=>({ma_vt:$i$$.ma_vt,sl_xuat:$i$$.sl_xuat})),$new_combo$$=($ref$$.combo||[]).map($i$$=>({ma_vt:$i$$.ma_vt,sl_xuat:$i$$.sl_xuat}));_.isEqual($old_combo$$,$new_combo$$)||($item$$.combo=$ref$$.combo||[]);$obj$$.details.find($d$$=>$d$$.ma_vt===$item$$.ma_vt)?
74
- $item$$.ma_thue||($item$$.ma_thue=$ref$$.ma_thue):$item$$.ma_thue=$ref$$.ma_thue}});$data$$.details.forEach($detail$$=>{$detail$$.combo&&$detail$$.combo.length>0&&($detail$$.combo=$detail$$.combo.map($item$$=>{$item$$=$item$$.toObject?$item$$.toObject():{...$item$$};$item$$.sl_xuat_1_combo==void 0&&($item$$.sl_xuat_1_combo=$item$$.sl_xuat||0);$item$$.sl_xuat=($item$$.sl_xuat_1_combo||0)*($detail$$.sl_xuat||0);$item$$.tien_xuat=$item$$.tien_xuat_nt=$item$$.sl_xuat*($item$$.gia_von_nt||0);$item$$.tien_hang=
75
- $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$$.tien_thu=$data$$.tien_thu==void 0?$obj$$.tien_thu:$data$$.tien_thu;$data$$.tien_thu2=$data$$.tien_thu2==void 0?$obj$$.tien_thu2:$data$$.tien_thu2;$data$$.tien_thu=Math.roundBy($data$$.tien_thu||0);$data$$.tien_thu2=Math.roundBy($data$$.tien_thu2||0);$data$$.ma_ban&&
76
- $obj$$.ma_ban!==$data$$.ma_ban&&($data$$.ma_ban0=$obj$$.ma_ban);$data$$.details.forEach(function($d$$){$obj$$.details.forEach(function($_d$$){if($_d$$.ma_vt===$d$$.ma_vt&&$_d$$.line===$d$$.line){if($d$$.sl_order==void 0||$d$$.sl_order==null)$d$$.sl_order=$_d$$.sl_order;if($d$$.sl_xuat==void 0||$d$$.sl_xuat==null)$d$$.sl_xuat=$_d$$.sl_xuat;$d$$.order_time=$d$$.order_time||$_d$$.order_time||new Date;$d$$.sl_order<=$d$$.sl_xuat?$d$$.finish_time&&$d$$.sl_xuat===$_d$$.sl_xuat||($d$$.finish_time=new Date):
77
- $d$$.finish_time=null;let $trang_thai$$=$data$$.trang_thai||$obj$$.trang_thai;$d$$.finish_time||$trang_thai$$!=="5"&&$trang_thai$$!=="6"&&$trang_thai$$!=="9"||($d$$.finish_time=new Date);$_d$$.het_hang&&($d$$.het_hang=!0)}})});valid($user$$,$data$$,function($error$$){if($error$$)return $next$$($error$$);if($obj$$.paymentByPoints&&$obj$$.paymentByPoints!==($data$$.paymentByPoints||0))return $next$$("B\u1ea1n kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt s\u1ed1 \u0111i\u1ec3m thanh to\u00e1n.");$data$$.ma_ban&&
78
- $obj$$.ma_ban&&$data$$.ma_ban!==$obj$$.ma_ban&&App.emitEvent($obj$$.id_app,"pbl:delete",{_id:$obj$$._id,ma_ban:$obj$$.ma_ban,action:"DELETE",trang_thai:-1});$next$$(null,$data$$,$obj$$)},$obj$$)};$contr$$.updated=async function($evouchers_user$$,$obj$$,$next$$){await Evoucher.updateMany({id_ct_used:$obj$$._id.toString()},{id_ct_used:null});$evouchers_user$$=await Evoucher.find({id_ct_useds:$obj$$._id.toString()});await Promise.all($evouchers_user$$.map($e$$=>deleteEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));
79
- $obj$$.trang_thai==="9"?(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")):(createTransactionBonus($obj$$),$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>updateEvoucher($e$$.id_app,$e$$.ma,$obj$$._id))));$obj$$.trang_thai=="5"&&($obj$$.trang_thai="6",await model.findOneAndUpdate({_id:$obj$$._id},{trang_thai:"6"}));$next$$(null,$obj$$)};$contr$$.deleting=
80
- function($user$$,$obj$$,$next$$){$next$$(null,$obj$$)};$contr$$.deleted=async function($user$$,$obj$$,$callback$$){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");$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>deleteEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$callback$$(null,$obj$$)};$contr$$.view=function($user$$,$items$$,$fn$$){let $id_app$$=$user$$.current_id_app;
81
- $items$$.forEach($item$$=>{$item$$.trang_thai=$item$$.trang_thai.toString();$item$$.evouchers&&($item$$.evouchers_string=$item$$.evouchers.map($e$$=>$e$$.ma).join(","))});async.parallel({cashier:function($callback$$){$items$$.filter($item$$=>$item$$.cashier).joinModel2(null,"user",[{where:{cashier:"email"},fields:[{cashier_name:"name"}]}],function(){$callback$$()})},kh:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kh).joinModel2($id_app$$,customer,[{where:{ma_kh:"ma_kh"},fields:[{ten_kh:"ten_kh"},
82
- {nh_kh:"nh_kh"},{dia_chi_kh:"dia_chi"},{dien_thoai_kh:"dien_thoai"}]}],function(){$callback$$()})},ban:function($callback$$){$items$$.filter($item$$=>$item$$.ma_ban).joinModel2($id_app$$,Dmban,[{where:{ma_ban:"ma_ban"},fields:[{ten_ban:"ten_ban"}]}],function(){$callback$$()})},ban0:function($callback$$){$items$$.filter($item$$=>$item$$.ma_ban0).joinModel2($id_app$$,Dmban,[{where:{ma_ban0:"ma_ban"},fields:[{ten_ban0:"ten_ban"}]}],function(){$callback$$()})},kho:function($callback$$){$items$$.filter($item$$=>
53
+ $product_details$$,async function($detail$$,$callback$$){$detail$$={...$detail$$,nxt:2};$detail$$.ma_kho=$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){if($e$$)return $callback$$($e$$);$du_lieu_kho_kt$$=$rs$$?.rs_sokho;$callback$$(null,$rs$$)})},khott:$callback$$=>{(new PostBook($obj$$,$product_details$$,Sokhott,async function($detail$$,$callback$$){$detail$$={...$detail$$,nxt:2};$detail$$.ma_kho=$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})}},
54
+ ($e$$,$rs$$)=>{$callback$$($e$$,$rs$$)})},post_vatra:function($callback$$){$obj$$.ngay_hd&&$obj$$.so_hd?setImmediate(async()=>{let $details_vatra$$=[];var $d$jscomp$27_ds$$=$product_details$$.map($detail$$=>({...$detail$$,thue_suat:($detail$$.ma_thue?$detail$$.thue_suat:$obj$$.thue_suat)||0,ma_thue:$detail$$.ma_thue||$obj$$.ma_thue,tien_thue_nt:$detail$$.tien_thue_nt||0,tien_thue:$detail$$.tien_thue||0})).filter($d$$=>$d$$.ma_thue);await $d$jscomp$27_ds$$.filter($r$$=>!$r$$.tk_thue_co&&$r$$.ma_thue).asyncJoinModel2($obj$$.id_app,
55
+ "vat",{where:"ma_thue",fields:["tk_thue_co"]});$d$jscomp$27_ds$$=await $d$jscomp$27_ds$$.asyncGroupBy(["ma_thue","thue_suat","ten_vt_vat","tk_thue_co"],"tien_hang_ct_nt tien_hang_ct tien_ck_nt tien_ck tien_thue tien_thue_nt tien_hang_options_ct tien_thue_options".split(" "));$d$jscomp$27_ds$$.forEach($detail$$=>{try{$detail$$.tk_du_thue=$obj$$.tk_no,$detail$$.t_tien_nt=($detail$$.tien_hang_ct_nt||0)+($detail$$.tien_hang_options_ct||0)-($detail$$.tien_ck_nt||0),$detail$$.t_tien=($detail$$.tien_hang_ct||
56
+ 0)+($detail$$.tien_hang_options_ct||0)-($detail$$.tien_ck||0),$detail$$.t_thue_nt=$detail$$.tien_thue_nt+($detail$$.tien_thue_options||0),$detail$$.t_thue=$detail$$.tien_thue+($detail$$.tien_thue_options||0),$detail$$.ten_vt=$detail$$.ten_vt_vat||$obj$$.ten_vt||$obj$$.dien_giai}catch($e$$){console.error($e$$,$obj$$)}});$details_vatra$$=[...$details_vatra$$,...$d$jscomp$27_ds$$];(new PostBook($obj$$,$details_vatra$$,global.getModel("vatra"),($detail$$,$callback$$)=>{$detail$$={...$detail$$};$detail$$.ten_vt=
57
+ $detail$$.ten_vt||$obj$$.dien_giai;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})}):$callback$$()},post_socai:function($callback$$){setImmediate(async()=>{try{var $_opt$$=await Options.findOne({id_app:$obj$$.id_app,id_func:ma_ct.toLowerCase()}).lean();let $option$$;$option$$=$_opt$$?$_opt$$.option||{}:{};let $kho$$=await dmkho.findOne({id_app:$obj$$.id_app,ma_kho:$obj$$.ma_kho}).lean()||{},$pt$$;$obj$$.pt_thanh_toan&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan)&&
58
+ ($pt$$=await ptthanhtoan.findOne({id_app:$obj$$.id_app,_id:$obj$$.pt_thanh_toan}).lean());$pt$$=$pt$$||{};$pt$$.tk_tien=$kho$$.tk_tien||$pt$$.tk_tien;$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$$.ma_kh||($pt$$.ma_kh=$kho$$.ma_kh);$pt$$.ma_kh&&($pt$$.tk_tien=$pt$$.tk_cn);$option$$.tk_tien=$pt$$.tk_tien||$option$$.tk_tien||"1111";$option$$.tk_cn=$kho$$.tk_cn||$option$$.tk_cn||"131111";$option$$.tk_dt=
59
+ $pt$$.tk_dt||$option$$.tk_dt||"51111";$option$$.tk_ck=$pt$$.tk_ck||$option$$.tk_ck||"52111";$option$$.tk_gv=$pt$$.tk_gv||$option$$.tk_gv||"6321";let $details$$=[...$obj$$.details.map($d$$=>({...$d$$}))],$details_ht$$=[];$details$$.forEach($detail$$=>{$detail$$={...$detail$$};let $tien$$=$detail$$.tien_hang_ct+$detail$$.tien_hang_options_ct,$tien_nt$$=$detail$$.tien_hang_ct_nt+$detail$$.tien_hang_options_ct;$detail$$.tk_no=$option$$.tk_tien;$detail$$.tk_co=$option$$.tk_dt;$detail$$.ma_kh||($detail$$.ma_kh=
60
+ $pt$$.ma_kh||$obj$$.ma_kh);$detail$$.tien_nt=$tien_nt$$;$detail$$.tien=$tien$$;$detail$$.flag="DT_"+($detail$$.ma_vt||"");$details_ht$$.push($detail$$)});$details$$.filter($d$$=>$d$$.tien_thue_nt+$d$$.tien_thue_options&&($d$$.tk_thue_co_treo||$d$$.tk_thue_co)).forEach($detail$$=>{$detail$$={...$detail$$};$detail$$.tk_no=$option$$.tk_tien;$detail$$.tk_co=$obj$$.ngay_hd&&$obj$$.so_hd?$detail$$.tk_thue_co:$detail$$.tk_thue_co_treo||$detail$$.tk_thue_co;$detail$$.ma_kh||($detail$$.ma_kh=$pt$$.ma_kh||
61
+ $obj$$.ma_kh);$detail$$.tien=$detail$$.tien_nt=$detail$$.tien_thue_nt+$detail$$.tien_thue_options;$detail$$.flag="THUE_"+($detail$$.ma_vt||"");$details_ht$$.push($detail$$)});var $tien_evoucher_con_lai$jscomp$1_tt$$=$obj$$.tien_evoucher||0;$tien_evoucher_con_lai$jscomp$1_tt$$&&($_opt$$={},$_opt$$.tk_no=$obj$$.tk_no_evoucher||$option$$.tk_no_evoucher||$option$$.tk_ck,$_opt$$.tk_co=$obj$$.tk_co_evoucher||$option$$.tk_co_evoucher||$option$$.tk_tien,$_opt$$.tien_nt=$tien_evoucher_con_lai$jscomp$1_tt$$,
62
+ $_opt$$.tien=$_opt$$.tien_nt,$_opt$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh,$_opt$$.check_balance=!1,$details_ht$$.push($_opt$$));var $tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$=($obj$$.tien_ck_hd||0)+$obj$$.details.map($d$$=>$d$$.tien_ck||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$&&($tien_evoucher_con_lai$jscomp$1_tt$$={},$tien_evoucher_con_lai$jscomp$1_tt$$.tk_no=$option$$.tk_ck,$tien_evoucher_con_lai$jscomp$1_tt$$.tk_co=$option$$.tk_tien,$tien_evoucher_con_lai$jscomp$1_tt$$.tien=
63
+ $tien_evoucher_con_lai$jscomp$1_tt$$.tien_nt=$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$,$tien_evoucher_con_lai$jscomp$1_tt$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh,$tien_evoucher_con_lai$jscomp$1_tt$$.check_balance=!1,$details_ht$$.push($tien_evoucher_con_lai$jscomp$1_tt$$));$obj$$.con_no&&$obj$$.ma_kh&&($tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$={},$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.tk_no=$option$$.tk_cn,$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.tk_co=$option$$.tk_tien,$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt=
64
+ $obj$$.con_no,$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.tien=$obj$$.con_no,$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh=$obj$$.ma_kh,$details_ht$$.push($tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$));$obj$$.tien_thu&&$pt$$.tk_cn&&$pt$$.tk_cn!==$option$$.tk_tien&&($tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$={},$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.tk_no=$pt$$.tk_cn,$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.tk_co=$option$$.tk_tien,$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt=$obj$$.tien_thu,$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.tien=
65
+ $obj$$.tien_thu,$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh,$details_ht$$.push($tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$));if($obj$$.tien_thu2){let $pt2$$=($obj$$.pt_thanh_toan2&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan2)?await ptthanhtoan.findOne({_id:$obj$$.pt_thanh_toan2}).lean():null)||$pt$$;$pt2$$.tk_cn&&$pt2$$.ma_kh!==$pt$$.ma_kh&&($tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$={},$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.tk_no=$pt2$$.tk_cn,$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.tk_co=
66
+ $option$$.tk_tien,$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt=$obj$$.tien_thu2,$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.tien=$obj$$.tien_thu2,$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_no=$pt2$$.ma_kh,$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_co=$pt$$.ma_kh,$details_ht$$.push($tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$))}let $details_tienvon$$=[];($du_lieu_kho_kt$$||[]).forEach(function($detail$$){$detail$$.toObject&&($detail$$=$detail$$.toObject());$detail$$={...$detail$$};$detail$$.tk_no=
67
+ $option$$.tk_gv||$detail$$.tk_gv;$detail$$.ma_kh||($detail$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh);$detail$$.tk_co=$detail$$.tk_vt;$detail$$.tien_nt=$detail$$.tien_xuat_nt;$detail$$.tien=$detail$$.tien_xuat;$detail$$.ma_nt="VND";$detail$$.ty_gia=1;$details_tienvon$$.push($detail$$)});$details_ht$$=$details_ht$$.concat($details_tienvon$$);$details_ht$$.forEach($d$$=>{$d$$.ma_kho=$obj$$.ma_kho});(new PostSocai($obj$$,$details_ht$$,void 0,void 0,$_options$$)).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})}catch($e$$){$callback$$($e$$)}})}},
68
+ async function($e$$,$rs$$){if($rs$$)try{$obj$$.details.filter($d$$=>!$d$$.px_gia_dd).forEach($detail$$=>{let $sokhos$$=($du_lieu_kho_kt$$||[]).filter($d$$=>$d$$.ma_vt==$detail$$.ma_vt&&$d$$.ma_tt1==$detail$$.ma_tt1||$d$$.ma_sp==$detail$$.ma_vt&&$d$$.ma_tt1_sp==$detail$$.ma_tt1);$detail$$.tien_xuat_nt=$detail$$.tien_xuat=$sokhos$$.map($s$$=>$s$$.tien_xuat_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$detail$$.sl_xuat&&($detail$$.gia_von_nt=$detail$$.gia_von=Math.round($detail$$.tien_xuat_nt/$detail$$.sl_xuat))}),
69
+ await model.updateOne({_id:$obj$$._id},{details:$obj$$.details})}catch($e$$){return $fn$$($e$$)}$fn$$($e$$,$rs$$)})};$contr$$.saving=async($user$$,$obj$$)=>{$obj$$.details=$obj$$.details||[];await chietkhauhd($user$$.email,$obj$$);await khuyenmaihd($obj$$);tinhtongtien($obj$$);await taothongtinchuyenkhoan($user$$,$obj$$)};$contr$$.creating=async function($user$$,$obj$$,$next$$){$obj$$.details||($obj$$.details=[]);await $obj$$.details.asyncJoinModel2($user$$.current_id_app,dmvt,{where:"ma_vt",setFields:($item$$,
70
+ $ref$$)=>{$item$$.combo=$ref$$.combo||[];$item$$.ma_thue||($item$$.ma_thue=$ref$$.ma_thue)}});$obj$$.details.forEach($detail$$=>{$detail$$.combo&&$detail$$.combo.length>0&&($detail$$.combo=$detail$$.combo.map($item$$=>{$item$$=$item$$.toObject?$item$$.toObject():{...$item$$};$item$$.sl_xuat_1_combo=$item$$.sl_xuat||0;$item$$.sl_xuat=($item$$.sl_xuat_1_combo||0)*($detail$$.sl_xuat||0);$item$$.tien_xuat=$item$$.tien_xuat_nt=$item$$.sl_xuat*($item$$.gia_von_nt||0);$item$$.tien_hang=$item$$.tien_hang_nt=
71
+ $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$$}))});$obj$$.tien_thu=Math.roundBy($obj$$.tien_thu||0);$obj$$.tien_thu2=Math.roundBy($obj$$.tien_thu2||0);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,$user$$.email)<
72
+ $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$$.created=async function($user$$,$obj$$,$next$$){await createTransactionPayment($obj$$);await createTransactionBonus($obj$$);$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>updateEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$obj$$.trang_thai=="5"&&($obj$$.trang_thai=
73
+ "6",await model.updateOne({_id:$obj$$._id},{trang_thai:"6"}));$next$$(null,$obj$$)};$contr$$.updating=async function($user$$,$data$$,$obj$$,$next$$){$data$$.details||($data$$.details=$obj$$.details||[]);$data$$.evouchers||($data$$.evouchers=$obj$$.evouchers||[]);await $data$$.details.asyncJoinModel2($user$$.current_id_app,dmvt,{where:"ma_vt",setFields:($item$$,$ref$$)=>{let $old_combo$$=($item$$.combo||[]).map($i$$=>({ma_vt:$i$$.ma_vt,sl_xuat:$i$$.sl_xuat})),$new_combo$$=($ref$$.combo||[]).map($i$$=>
74
+ ({ma_vt:$i$$.ma_vt,sl_xuat:$i$$.sl_xuat}));_.isEqual($old_combo$$,$new_combo$$)||($item$$.combo=$ref$$.combo||[]);$item$$.ma_thue||($obj$$.details.find($d$$=>$d$$.ma_vt===$item$$.ma_vt),$item$$.ma_thue=$ref$$.ma_thue)}});$data$$.details.forEach($detail$$=>{$detail$$.combo&&$detail$$.combo.length>0&&($detail$$.combo=$detail$$.combo.map($item$$=>{$item$$=$item$$.toObject?$item$$.toObject():{...$item$$};$item$$.sl_xuat_1_combo==void 0&&($item$$.sl_xuat_1_combo=$item$$.sl_xuat||0);$item$$.sl_xuat=($item$$.sl_xuat_1_combo||
75
+ 0)*($detail$$.sl_xuat||0);$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-($item$$.tien_ck_nt||0);return $item$$}))});$data$$.tien_thu=$data$$.tien_thu==void 0?$obj$$.tien_thu:$data$$.tien_thu;$data$$.tien_thu2=$data$$.tien_thu2==void 0?$obj$$.tien_thu2:$data$$.tien_thu2;
76
+ $data$$.tien_thu=Math.roundBy($data$$.tien_thu||0);$data$$.tien_thu2=Math.roundBy($data$$.tien_thu2||0);$data$$.ma_ban&&$obj$$.ma_ban!==$data$$.ma_ban&&($data$$.ma_ban0=$obj$$.ma_ban);$data$$.details.forEach(function($d$$){$obj$$.details.forEach(function($_d$$){if($_d$$.ma_vt===$d$$.ma_vt&&$_d$$.line===$d$$.line){if($d$$.sl_order==void 0||$d$$.sl_order==null)$d$$.sl_order=$_d$$.sl_order;if($d$$.sl_xuat==void 0||$d$$.sl_xuat==null)$d$$.sl_xuat=$_d$$.sl_xuat;$d$$.order_time=$d$$.order_time||$_d$$.order_time||
77
+ new Date;$d$$.sl_order<=$d$$.sl_xuat?$d$$.finish_time&&$d$$.sl_xuat===$_d$$.sl_xuat||($d$$.finish_time=new Date):$d$$.finish_time=null;let $trang_thai$$=$data$$.trang_thai||$obj$$.trang_thai;$d$$.finish_time||$trang_thai$$!=="5"&&$trang_thai$$!=="6"&&$trang_thai$$!=="9"||($d$$.finish_time=new Date);$_d$$.het_hang&&($d$$.het_hang=!0)}})});valid($user$$,$data$$,function($error$$){if($error$$)return $next$$($error$$);if($obj$$.paymentByPoints&&$obj$$.paymentByPoints!==($data$$.paymentByPoints||0))return $next$$("B\u1ea1n kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt s\u1ed1 \u0111i\u1ec3m thanh to\u00e1n.");
78
+ $data$$.ma_ban&&$obj$$.ma_ban&&$data$$.ma_ban!==$obj$$.ma_ban&&App.emitEvent($obj$$.id_app,"pbl:delete",{_id:$obj$$._id,ma_ban:$obj$$.ma_ban,action:"DELETE",trang_thai:-1});$next$$(null,$data$$,$obj$$)},$obj$$)};$contr$$.updated=async function($evouchers_user$$,$obj$$,$next$$){await Evoucher.updateMany({id_ct_used:$obj$$._id.toString()},{id_ct_used:null});$evouchers_user$$=await Evoucher.find({id_ct_useds:$obj$$._id.toString()});await Promise.all($evouchers_user$$.map($e$$=>deleteEvoucher($e$$.id_app,
79
+ $e$$.ma,$obj$$._id)));$obj$$.trang_thai==="9"?(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 createTransactionBonus($obj$$),$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>updateEvoucher($e$$.id_app,$e$$.ma,$obj$$._id))));$obj$$.trang_thai=="5"&&($obj$$.trang_thai="6",await model.updateOne({_id:$obj$$._id},{trang_thai:"6"}));$next$$(null,$obj$$)};
80
+ $contr$$.deleting=function($user$$,$obj$$,$next$$){$next$$(null,$obj$$)};$contr$$.deleted=async function($user$$,$obj$$,$callback$$){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");$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>deleteEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$callback$$(null,$obj$$)};$contr$$.view=function($user$$,$items$$,$fn$$){let $id_app$$=
81
+ $user$$.current_id_app;$items$$.forEach($item$$=>{$item$$.trang_thai=$item$$.trang_thai.toString();$item$$.evouchers&&($item$$.evouchers_string=$item$$.evouchers.map($e$$=>$e$$.ma).join(","))});async.parallel({cashier:function($callback$$){$items$$.filter($item$$=>$item$$.cashier).joinModel2(null,"user",[{where:{cashier:"email"},fields:[{cashier_name:"name"}]}],function(){$callback$$()})},kh:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kh).joinModel2($id_app$$,customer,[{where:{ma_kh:"ma_kh"},
82
+ fields:[{ten_kh:"ten_kh"},{nh_kh:"nh_kh"},{dia_chi_kh:"dia_chi"},{dien_thoai_kh:"dien_thoai"}]}],function(){$callback$$()})},ban:function($callback$$){$items$$.filter($item$$=>$item$$.ma_ban).joinModel2($id_app$$,Dmban,[{where:{ma_ban:"ma_ban"},fields:[{ten_ban:"ten_ban"}]}],function(){$callback$$()})},ban0:function($callback$$){$items$$.filter($item$$=>$item$$.ma_ban0).joinModel2($id_app$$,Dmban,[{where:{ma_ban0:"ma_ban"},fields:[{ten_ban0:"ten_ban"}]}],function(){$callback$$()})},kho:function($callback$$){$items$$.filter($item$$=>
83
83
  $item$$.ma_kho).joinModel2($id_app$$,dmkho,[{where:{ma_kho:"ma_kho"},fields:["ten_kho","wifi","wifi_pass"],setFields:($a$$,$b$$)=>{$b$$&&$b$$.exfields&&($a$$.dia_chi_kho=$b$$.exfields.dia_chi,$a$$.dien_thoai_kho=$b$$.exfields.dien_thoai)}}],function(){$callback$$()})},hd7:function($callback$$){$items$$.joinModel2($id_app$$,hd7,[{where:{_id:"id_pbl"},fields:[{id_hd7:"_id"},{so_ct_hd7:"so_ct"},{ngay_ct_hd7:"ngay_ct"}]}],function(){$callback$$()})},trangthai:function($callback$$){$items$$.filter($item$$=>
84
84
  $item$$.trang_thai).joinModel2(null,trangthai,[{where:{trang_thai:"ma_trang_thai",ma_ct:"ma_ct"},fields:["ten_trang_thai","color"]}],function(){$callback$$()})},ptthanhtoan:function($callback$$){$items$$.filter($item$$=>$item$$.pt_thanh_toan).joinModel2($id_app$$,ptthanhtoan,[{where:{pt_thanh_toan:"_id"},fields:{ten_pt_thanh_toan:"ten"}}],function(){$callback$$()})},ptthanhtoan2:function($callback$$){$items$$.filter($item$$=>$item$$.pt_thanh_toan2).joinModel2($id_app$$,ptthanhtoan,[{where:{pt_thanh_toan2:"_id"},
85
85
  fields:{ten_pt_thanh_toan2:"ten"}}],function(){$callback$$()})},t_tien:function($callback$$){$items$$.forEach(function($r$$){$r$$.details&&($r$$.details.forEach($d$$=>{$d$$.sl_order=$d$$.sl_order||$d$$.sl_xuat;$d$$.sl_order<=$d$$.sl_xuat?$d$$.finish_time||($d$$.finish_time=new Date):$d$$.finish_time=null}),$r$$.t_tien_hang_ct==void 0&&tinhtongtien($r$$))});$callback$$()},details_vt:function($callback$$){async.mapLimit($items$$,20,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_vt).joinModel2($id_app$$,
@@ -1,6 +1,6 @@
1
- const moment=require("moment"),numeral=require("numeral"),_=require("lodash"),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"),
2
- customer=global.getModel("customer"),dmdt=global.getModel("dmdt"),dmphi=global.getModel("dmphi"),contract=global.getModel("contract"),trangthai=global.getModel("trangthai"),currency=global.getModel("currency"),ptthanhtoan=global.getModel("ptthanhtoan"),dmdiemthuong=global.getModel("dmdiemthuong"),model=global.getModel("so1"),pt1=global.getModel("pt1"),controller=require("../../controllers/controller"),async=require("async"),ma_ct="SO1",ckdiem=require("../../libs/ckdiem"),tinhhoahong=require("../../libs/tinhhoahong"),
3
- blockchainconnect=require("../../libs/blockchainconnect"),App=global.getModel("app"),Introducer=global.getModel("introducer"),getGiaBan=require("../../libs/getGiabanAsync"),dmchietkhauhd=global.getModel("dmchietkhauhd"),dmkhuyenmaihd=global.getModel("dmkhuyenmaihd"),utils=require("../../libs/utils"),spend=async($appInfo$$,$receiver_user$$,$receiver_address$$,$amount$$,$denom$$,$memo$$,$introduce_code$$,$sub_action$$="")=>{try{await blockchainconnect.spend($appInfo$$._id,$appInfo$$.wallet_token,$appInfo$$.wallet_address,
1
+ const moment=require("moment"),numeral=require("numeral"),_=require("lodash"),PostSokho=require("../../libs/post-sokho"),options=global.getModel("options"),PostSocai=require("../../libs/post-socai"),User=global.getModel("user"),Socai=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"),
2
+ dmdt=global.getModel("dmdt"),dmphi=global.getModel("dmphi"),contract=global.getModel("contract"),trangthai=global.getModel("trangthai"),currency=global.getModel("currency"),ptthanhtoan=global.getModel("ptthanhtoan"),dmdiemthuong=global.getModel("dmdiemthuong"),model=global.getModel("so1"),pt1=global.getModel("pt1"),controller=require("../../controllers/controller"),async=require("async"),ma_ct="SO1",ckdiem=require("../../libs/ckdiem"),tinhhoahong=require("../../libs/tinhhoahong"),blockchainconnect=
3
+ require("../../libs/blockchainconnect"),App=global.getModel("app"),Introducer=global.getModel("introducer"),getGiaBan=require("../../libs/getGiabanAsync"),dmchietkhauhd=global.getModel("dmchietkhauhd"),dmkhuyenmaihd=global.getModel("dmkhuyenmaihd"),utils=require("../../libs/utils"),spend=async($appInfo$$,$receiver_user$$,$receiver_address$$,$amount$$,$denom$$,$memo$$,$introduce_code$$,$sub_action$$="")=>{try{await blockchainconnect.spend($appInfo$$._id,$appInfo$$.wallet_token,$appInfo$$.wallet_address,
4
4
  $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$$)}},validOffline=$detail$$=>{$detail$$.ma_thue?($detail$$.gia_ban_ct_nt=$detail$$.gia_ban_ct=Math.roundBy($detail$$.gia_ban_nt/(1+$detail$$.thue_suat/100),5),$detail$$.tien_hang_ct=$detail$$.tien_hang_ct_nt=Math.roundBy($detail$$.sl_xuat*$detail$$.gia_ban_ct_nt,
5
5
  0),$detail$$.ty_le_ck&&($detail$$.tien_ck=$detail$$.tien_ck_nt=utils.round($detail$$.tien_hang_ct*$detail$$.ty_le_ck/100)),$detail$$.tien_thue=$detail$$.tien_thue_nt=Math.roundBy(($detail$$.tien_hang_ct_nt-$detail$$.tien_ck_nt)*$detail$$.thue_suat/100)):($detail$$.gia_ban_ct=$detail$$.gia_ban,$detail$$.gia_ban_ct_nt=$detail$$.gia_ban_nt,$detail$$.tien_hang_ct=$detail$$.tien_hang_ct_nt=$detail$$.tien_hang_nt,$detail$$.ty_le_ck&&($detail$$.tien_ck=$detail$$.tien_ck_nt=utils.round($detail$$.tien_hang_ct*
6
6
  $detail$$.ty_le_ck/100)),$detail$$.tien_thue=0,$detail$$.tien_thue_nt=0)},khuyenmaihd=async $obj$$=>{if($obj$$.details&&$obj$$.online){var $ckhds_query_t_tien_hang_ct_nt$$=$obj$$.details.filter($d$$=>!$d$$.km_yn_for).csum("tien_hang_ct_nt");if($ckhds_query_t_tien_hang_ct_nt$$!==0){var $hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$=$obj$$.details.filter($d$$=>!$d$$.km_yn_for).csum("tien_ck_nt");$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$=$ckhds_query_t_tien_hang_ct_nt$$-$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$;
@@ -56,20 +56,20 @@ module.exports=function($contr_router$$){$contr_router$$=new controller($contr_r
56
56
  $user$$.email);$obj$$.details.forEach($d$$=>{$d$$.tien_xuat_tmp=$d$$.sl_xuat*($d$$.gia_mua||0)});await chietkhauhd($obj$$);await khuyenmaihd($obj$$);$obj$$.details.forEach($d$$=>{$d$$.sl_xuat=utils.round($d$$.sl_xuat,4);$d$$.tt_nt=($d$$.tien_han_ct_nt||0)-($d$$.tien_ck_nt||0);$d$$.tt=($d$$.tien_hang_ct||0)-($d$$.tien_ck||0)});await tinhhoahong($obj$$,$user$$)};$contr_router$$.handleAfterPayment=async $obj$$=>{$obj$$.trang_thai_tt="5";$obj$$.trang_thai="1";await model.updateOne({_id:$obj$$._id},{details:$obj$$.details,
57
57
  trang_thai_tt:"5",trang_thai:"1"});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$$,$_options$$={}){$fn$$||=function(){};let $he_so_qd$$=await currency.getRate($obj$$.id_app,$obj$$.ma_nt)||1;const $appInfo$$=await global.getModel("app").findOne({_id:$obj$$.id_app}).lean();await $obj$$.details.filter($d$$=>!$d$$.ma_thue).asyncJoinModel2($obj$$.id_app,
58
58
  dmvt,{where:"ma_vt",fields:["ma_thue","gia_mua"]});await $obj$$.details.filter($d$$=>$d$$.ma_thue).asyncJoinModel2($obj$$.id_app,global.getModel("vat"),{where:"ma_thue",fields:["thue_suat","tk_thue_co","tk_thue_co_treo"]});let $product_details$$=$obj$$.details.map($detail$$=>$detail$$.combo&&$detail$$.combo.length>0?$detail$$.combo.map($item$$=>{$item$$=$item$$.toObject?$item$$.toObject():{...$item$$};delete $item$$.px_gia_dd;$item$$.ma_kho=$detail$$.ma_kho;return $item$$}):[$detail$$]).reduce(($a$$,
59
- $b$$)=>$a$$.concat($b$$),[]);async.series({post_sokho:function($callback$$){const $details$$=[];$obj$$.details.forEach($d$$=>{$details$$.push({...$d$$})});(new PostBook($obj$$,$product_details$$,Sokho,async function($detail$$,$callback$$){$detail$$.nxt=2;$detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;$detail$$.ma_kho=$detail$$.ma_kho||$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})},post_socai:function($callback$$){options.findOne({id_app:$obj$$.id_app,
60
- id_func:ma_ct.toLowerCase()}).lean().exec(async($error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$,$rs$jscomp$3_tien_paymentByPoints_tt$$)=>{let $option$$;$option$$=$rs$jscomp$3_tien_paymentByPoints_tt$$?$rs$jscomp$3_tien_paymentByPoints_tt$$.option||{}:{};let $kho$$=await dmkho.findOne({id_app:$obj$$.id_app,ma_kho:$obj$$.ma_kho}).lean();$kho$$||={};let $pt$$;$obj$$.pt_thanh_toan&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan)&&($pt$$=await ptthanhtoan.findOne({id_app:$obj$$.id_app,
61
- _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||$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=
62
- $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||$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;
63
- $pt$$.ten&&$pt$$.ten.indexOf("COD")>=0?$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;const $details$$=[];$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_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$3_tien_paymentByPoints_tt$$=$obj$$.tien_paymentByPoints||
64
- 0;const $hoachtoandtvathue$$=($tk_tien$$,$ty_le$$)=>{$obj$$.details.forEach(function($d$jscomp$26_detail$$){$d$jscomp$26_detail$$={...$d$jscomp$26_detail$$};let $tien_nt$$;$tien_nt$$=$d$jscomp$26_detail$$.tien_hang_ct_nt;$d$jscomp$26_detail$$.tk_co=$option$$.tk_dt;$d$jscomp$26_detail$$.tk_no=$tk_tien$$;$d$jscomp$26_detail$$.ma_kh_co=$obj$$.ma_kh;$d$jscomp$26_detail$$.ma_kh_no=$option$$.ma_kh;$d$jscomp$26_detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;$d$jscomp$26_detail$$.tien=$d$jscomp$26_detail$$.tien_nt=
65
- Math.roundBy($tien_nt$$*$ty_le$$);$d$jscomp$26_detail$$.flag="DT_"+($d$jscomp$26_detail$$.ma_vt||"");$details$$.push($d$jscomp$26_detail$$)});$obj$$.details.filter($d$$=>$d$$.tien_thue).forEach($detail$$=>{$detail$$={...$detail$$};$detail$$.tk_no=$tk_tien$$;$detail$$.tk_co=$detail$$.tk_thue_co_treo||$detail$$.tk_thue_co;$detail$$.ma_kh||($detail$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh);$detail$$.tien=$detail$$.tien_nt=Math.roundBy($detail$$.tien_thue_nt*$ty_le$$);$detail$$.flag="THUE_"+($detail$$.ma_vt||
66
- "");$details$$.push($detail$$)})};$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$&&($hoachtoandtvathue$$($option$$.tk_cn,$rs$jscomp$3_tien_paymentByPoints_tt$$/$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$),$hoachtoandtvathue$$($option$$.tk_tien,($error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$-$rs$jscomp$3_tien_paymentByPoints_tt$$)/$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$));$obj$$.details.filter($d$$=>$d$$.diem_thuong&&$d$$.tk_km_no&&
67
- $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$30_detail$$){$d$jscomp$30_detail$$={...$d$jscomp$30_detail$$};$d$jscomp$30_detail$$.tk_co=$option$$.tk_dt;$d$jscomp$30_detail$$.tk_no=$option$$.tk_cn;$d$jscomp$30_detail$$.ma_kh_co=
68
- $obj$$.ma_kh;$d$jscomp$30_detail$$.ma_kh_no=$option$$.ma_kh;$d$jscomp$30_detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;$d$jscomp$30_detail$$.tien_nt=$d$jscomp$30_detail$$.tien_cp_nt;$d$jscomp$30_detail$$.tien=$d$jscomp$30_detail$$.tien_cp;$details$$.push($d$jscomp$30_detail$$)});$obj$$.tien_phi_vc&&$option$$.tk_phi_vc&&($error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$={},$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_co=$option$$.tk_phi_vc,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_no=
69
- $option$$.tk_cn,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien_nt=$obj$$.tien_phi_vc||0,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien=$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien_nt,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.ma_kh_co=$obj$$.ma_kh,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.ma_kh_no=$obj$$.nhan_vien_giao_hang||$obj$$.don_vi_vc,$details$$.push($error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$));
70
- $obj$$.tien_freeship&&($error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$={},$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_no=$option$$.tk_cp_gh,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_co=$option$$.tk_cn,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien_nt=$obj$$.tien_freeship||0,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien=$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien_nt,
71
- $error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.ma_kh_no=$obj$$.ma_kh,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.ma_kh_co=$option$$.ma_kh,$details$$.push($error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$));$obj$$.tt_tien_thuong&&($error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$={},$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_no=$option$$.tk_cp_bh,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_co=
72
- $option$$.tk_cn,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien_nt=$obj$$.tt_tien_thuong||0,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien=$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien_nt,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.ma_kh_no=$obj$$.ma_kh,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.ma_kh_co=$option$$.ma_kh,$details$$.push($error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$));
59
+ $b$$)=>$a$$.concat($b$$),[]),$ket_qua_post_sokho$$;async.series({post_sokho:function($callback$$){const $details$$=[];$obj$$.details.forEach($d$$=>{$details$$.push({...$d$$})});(new PostSokho($obj$$,$product_details$$,async function($detail$$,$callback$$){$detail$$.nxt=2;$detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;$detail$$.ma_kho=$detail$$.ma_kho||$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){if($e$$)return $callback$$($e$$);$ket_qua_post_sokho$$=$rs$$.rs_sokho;$callback$$(null,
60
+ $rs$$)})},post_socai:function($callback$$){options.findOne({id_app:$obj$$.id_app,id_func:ma_ct.toLowerCase()}).lean().exec(async($error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$,$rs$jscomp$3_tien_paymentByPoints_tt$$)=>{let $option$$;$option$$=$rs$jscomp$3_tien_paymentByPoints_tt$$?$rs$jscomp$3_tien_paymentByPoints_tt$$.option||{}:{};let $kho$$=await dmkho.findOne({id_app:$obj$$.id_app,ma_kho:$obj$$.ma_kho}).lean();$kho$$||={};let $pt$$;$obj$$.pt_thanh_toan&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan)&&
61
+ ($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||$pt$$.tk_cp_ctv;$pt$$.tk_cn_ctv=$kho$$.tk_cn_ctv||$pt$$.tk_cn_ctv;$option$$.tk_tien=$pt$$.tk_tien||
62
+ $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||$option$$.tk_cp_bh||$option$$.tk_ck;$option$$.tk_cp_ctv=$pt$$.tk_cp_ctv||$option$$.tk_cp_ctv;
63
+ $option$$.tk_cn_ctv=$pt$$.tk_cn_ctv||$option$$.tk_cn_ctv;$pt$$.ten&&$pt$$.ten.indexOf("COD")>=0?$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;const $details$$=[];$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_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$3_tien_paymentByPoints_tt$$=
64
+ $obj$$.tien_paymentByPoints||0;const $hoachtoandtvathue$$=($tk_tien$$,$ty_le$$)=>{$obj$$.details.forEach(function($d$jscomp$26_detail$$){$d$jscomp$26_detail$$={...$d$jscomp$26_detail$$};let $tien_nt$$;$tien_nt$$=$d$jscomp$26_detail$$.tien_hang_ct_nt;$d$jscomp$26_detail$$.tk_co=$option$$.tk_dt;$d$jscomp$26_detail$$.tk_no=$tk_tien$$;$d$jscomp$26_detail$$.ma_kh_co=$obj$$.ma_kh;$d$jscomp$26_detail$$.ma_kh_no=$option$$.ma_kh;$d$jscomp$26_detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;$d$jscomp$26_detail$$.tien=
65
+ $d$jscomp$26_detail$$.tien_nt=Math.roundBy($tien_nt$$*$ty_le$$);$d$jscomp$26_detail$$.flag="DT_"+($d$jscomp$26_detail$$.ma_vt||"");$details$$.push($d$jscomp$26_detail$$)});$obj$$.details.filter($d$$=>$d$$.tien_thue).forEach($detail$$=>{$detail$$={...$detail$$};$detail$$.tk_no=$tk_tien$$;$detail$$.tk_co=$detail$$.tk_thue_co_treo||$detail$$.tk_thue_co;$detail$$.ma_kh||($detail$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh);$detail$$.tien=$detail$$.tien_nt=Math.roundBy($detail$$.tien_thue_nt*$ty_le$$);$detail$$.flag=
66
+ "THUE_"+($detail$$.ma_vt||"");$details$$.push($detail$$)})};$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$&&($hoachtoandtvathue$$($option$$.tk_cn,$rs$jscomp$3_tien_paymentByPoints_tt$$/$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$),$hoachtoandtvathue$$($option$$.tk_tien,($error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$-$rs$jscomp$3_tien_paymentByPoints_tt$$)/$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$));$obj$$.details.filter($d$$=>
67
+ $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$30_detail$$){$d$jscomp$30_detail$$={...$d$jscomp$30_detail$$};$d$jscomp$30_detail$$.tk_co=$option$$.tk_dt;$d$jscomp$30_detail$$.tk_no=
68
+ $option$$.tk_cn;$d$jscomp$30_detail$$.ma_kh_co=$obj$$.ma_kh;$d$jscomp$30_detail$$.ma_kh_no=$option$$.ma_kh;$d$jscomp$30_detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;$d$jscomp$30_detail$$.tien_nt=$d$jscomp$30_detail$$.tien_cp_nt;$d$jscomp$30_detail$$.tien=$d$jscomp$30_detail$$.tien_cp;$details$$.push($d$jscomp$30_detail$$)});$obj$$.tien_phi_vc&&$option$$.tk_phi_vc&&($error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$={},$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_co=
69
+ $option$$.tk_phi_vc,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_no=$option$$.tk_cn,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien_nt=$obj$$.tien_phi_vc||0,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien=$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien_nt,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.ma_kh_co=$obj$$.ma_kh,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.ma_kh_no=$obj$$.nhan_vien_giao_hang||
70
+ $obj$$.don_vi_vc,$details$$.push($error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$));$obj$$.tien_freeship&&($error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$={},$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_no=$option$$.tk_cp_gh,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_co=$option$$.tk_cn,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien_nt=$obj$$.tien_freeship||0,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien=
71
+ $error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien_nt,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.ma_kh_no=$obj$$.ma_kh,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.ma_kh_co=$option$$.ma_kh,$details$$.push($error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$));$obj$$.tt_tien_thuong&&($error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$={},$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_no=$option$$.tk_cp_bh,
72
+ $error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_co=$option$$.tk_cn,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien_nt=$obj$$.tt_tien_thuong||0,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien=$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien_nt,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.ma_kh_no=$obj$$.ma_kh,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.ma_kh_co=$option$$.ma_kh,$details$$.push($error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$));
73
73
  $obj$$.tien_evoucher&&($error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$={},$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_no=$obj$$.tk_no_evoucher||$option$$.tk_no_evoucher||$option$$.tk_ck,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_co=$obj$$.tk_co_evoucher||$option$$.tk_co_evoucher||$option$$.tk_cn,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien_nt=$obj$$.tien_evoucher||0,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien=
74
74
  $error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien_nt,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.ma_kh_no=$obj$$.ma_kh,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.ma_kh_co=$option$$.ma_kh,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.check_balance=!1,$details$$.push($error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$));if($error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$=($obj$$.tien_ck_hd||0)+$obj$$.details.map($d$$=>
75
75
  $d$$.tien_ck||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0))$rs$jscomp$3_tien_paymentByPoints_tt$$={},$rs$jscomp$3_tien_paymentByPoints_tt$$.tk_no=$option$$.tk_ck,$rs$jscomp$3_tien_paymentByPoints_tt$$.tk_co=$option$$.tk_cn,$rs$jscomp$3_tien_paymentByPoints_tt$$.tien_nt=$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$,$rs$jscomp$3_tien_paymentByPoints_tt$$.tien=$rs$jscomp$3_tien_paymentByPoints_tt$$.tien_nt,$rs$jscomp$3_tien_paymentByPoints_tt$$.ma_kh_no=$obj$$.ma_kh,$rs$jscomp$3_tien_paymentByPoints_tt$$.ma_kh_co=
@@ -78,9 +78,9 @@ options.tk_co_hoa_hong}),(await $obj$$.details.filter($r$$=>$r$$.tien_hoa_hong_c
78
78
  $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*($obj$$.ty_gia||
79
79
  1);$tt$$.ma_kh=$obj$$.ma_kh_hoa_hong;$tt$$.ma_nv=$obj$$.ma_nv;$tt$$.check_balance=!1;$tt$$.ma_nt="VND";$tt$$.ty_gia=1;$tt$$.tk_no&&$tt$$.tk_co&&$details$$.push($tt$$)}));$obj$$.tien_hoa_hong_gt&&$obj$$.ma_kh_hoa_hong_gt&&($obj$$.details.filter($r$$=>$r$$.tien_hoa_hong_gt).forEach($r$$=>{$r$$.tk_no_hoa_hong_gt=$r$$.tk_no_hoa_hong_gt||$obj$$.tk_no_hoa_hong_gt||$kho$$.tk_no_hoa_hong_gt||options.tk_no_hoa_hong_gt||$obj$$.tk_no_hoa_hong||$kho$$.tk_no_hoa_hong||options.tk_no_hoa_hong;$r$$.tk_co_hoa_hong_gt=
80
80
  $r$$.tk_co_hoa_hong_gt||$obj$$.tk_co_hoa_hong_gt||$kho$$.tk_co_hoa_hong_gt||options.tk_co_hoa_hong_gt||$obj$$.tk_co_hoa_hong||$kho$$.tk_co_hoa_hong||options.tk_co_hoa_hong}),(await $obj$$.details.filter($r$$=>$r$$.tien_hoa_hong_gt).asyncGroupBy(["tk_no_hoa_hong_gt","tk_co_hoa_hong_gt"],["tien_hoa_hong_gt"])).forEach($r$$=>{let $tt$$={};$tt$$.tk_no=$r$$.tk_no_hoa_hong_gt;$tt$$.tk_co=$r$$.tk_co_hoa_hong_gt;$tt$$.tien_nt=$r$$.tien_hoa_hong_gt;$tt$$.tien=$tt$$.tien_nt*($obj$$.ty_gia||1);$tt$$.ma_kh=$obj$$.ma_kh_hoa_hong_gt;
81
- $tt$$.ma_nv=$obj$$.ma_nv;$tt$$.check_balance=!1;$tt$$.ma_nt="VND";$tt$$.ty_gia=1;$tt$$.tk_no&&$tt$$.tk_co&&$details$$.push($tt$$)}));let $details_tienvon$$=[...$product_details$$];$product_details$$.joinModel2($obj$$.id_app,dmvt,{where:"ma_vt",fields:["tk_vt","gia_mua","tk_gv","tg_tk"]},()=>{$details_tienvon$$.forEach(function($d$jscomp$32_detail$$){$d$jscomp$32_detail$$={...$d$jscomp$32_detail$$};$d$jscomp$32_detail$$.tk_no=$option$$.tk_gv;$d$jscomp$32_detail$$.ma_kh=$obj$$.ma_kh;$d$jscomp$32_detail$$.ngay_ct=
82
- $obj$$.ngay_giao_hang||$obj$$.ngay_ct;$d$jscomp$32_detail$$.tk_co=$d$jscomp$32_detail$$.tk_vt||"1561";$d$jscomp$32_detail$$.tien_nt=$d$jscomp$32_detail$$.tien_xuat_nt;$d$jscomp$32_detail$$.tien=$d$jscomp$32_detail$$.tien_xuat;$d$jscomp$32_detail$$.tg_tk||($d$jscomp$32_detail$$.tien=$d$jscomp$32_detail$$.tien_nt=0);$d$jscomp$32_detail$$.ma_nt="VND";$d$jscomp$32_detail$$.ty_gia=1;$details$$.push($d$jscomp$32_detail$$)});(new PostSocai($obj$$,$details$$,null,Socaitmp,$_options$$)).run(function($e$$,
83
- $rs$$){$callback$$($e$$,$rs$$)})})})},thanhtoanhoahongnv:$callback$$=>{if($obj$$.da_chuyen_hoa_hong||!$obj$$.tien_hoa_hong||!$obj$$.user_nv||!$obj$$.chuyen_ngay)return $callback$$();setImmediate(async()=>{try{if($appInfo$$.wallet_address&&$appInfo$$.wallet_token&&$appInfo$$.tang_gioi_thieu_denom){let $wallet_nhan_vien$$=await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),username:$obj$$.user_nv,wallet_type:8});$wallet_nhan_vien$$||=await global.getModel("asskey").createWallet($appInfo$$._id.toString(),
81
+ $tt$$.ma_nv=$obj$$.ma_nv;$tt$$.check_balance=!1;$tt$$.ma_nt="VND";$tt$$.ty_gia=1;$tt$$.tk_no&&$tt$$.tk_co&&$details$$.push($tt$$)}));let $details_tienvon$$=[...($ket_qua_post_sokho$$||[])];$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$32_detail$$){$d$jscomp$32_detail$$={...$d$jscomp$32_detail$$};$d$jscomp$32_detail$$.tk_no=$option$$.tk_gv;$d$jscomp$32_detail$$.ma_kh=$obj$$.ma_kh;$d$jscomp$32_detail$$.ngay_ct=
82
+ $obj$$.ngay_giao_hang||$obj$$.ngay_ct;$d$jscomp$32_detail$$.tk_co=$d$jscomp$32_detail$$.tk_vt||"1561";$d$jscomp$32_detail$$.tien_nt=$d$jscomp$32_detail$$.tien_xuat_nt;$d$jscomp$32_detail$$.tien=$d$jscomp$32_detail$$.tien_xuat;$d$jscomp$32_detail$$.tg_tk||($d$jscomp$32_detail$$.tien=$d$jscomp$32_detail$$.tien_nt=0);$d$jscomp$32_detail$$.ma_nt="VND";$d$jscomp$32_detail$$.ty_gia=1;$details$$.push($d$jscomp$32_detail$$)});(new PostSocai($obj$$,$details$$,null,Socai,$_options$$)).run(function($e$$,$rs$$){$callback$$($e$$,
83
+ $rs$$)})})})},thanhtoanhoahongnv:$callback$$=>{if($obj$$.da_chuyen_hoa_hong||!$obj$$.tien_hoa_hong||!$obj$$.user_nv||!$obj$$.chuyen_ngay)return $callback$$();setImmediate(async()=>{try{if($appInfo$$.wallet_address&&$appInfo$$.wallet_token&&$appInfo$$.tang_gioi_thieu_denom){let $wallet_nhan_vien$$=await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),username:$obj$$.user_nv,wallet_type:8});$wallet_nhan_vien$$||=await global.getModel("asskey").createWallet($appInfo$$._id.toString(),
84
84
  $obj$$.user_nv,"T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng",8);let $amount$$=$obj$$.tien_hoa_hong,$denom$$=$appInfo$$.tang_gioi_thieu_denom,$memo$$=`Hoa h\u1ed3ng cho \u0111\u01a1n h\u00e0ng s\u1ed1 ${$obj$$.so_ct}: ${numeral($amount$$).format()} ${$denom$$.toUpperCase()}`;await spend($appInfo$$,$obj$$.be_introduced,$wallet_nhan_vien$$.address,$amount$$,$denom$$,$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",
85
85
  $e$$)}$callback$$()})},thanhtoanhoahonggt:$callback$$=>{if($obj$$.da_chuyen_hoa_hong_gt||!$obj$$.tien_hoa_hong_gt||!$obj$$.user_gt||!$obj$$.chuyen_ngay_gt)return $callback$$();setImmediate(async()=>{try{if($appInfo$$.wallet_address&&$appInfo$$.wallet_token&&$appInfo$$.tang_gioi_thieu_denom){let $wallet_gt$$=await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),username:$obj$$.user_gt,wallet_type:8});$wallet_gt$$||=await global.getModel("asskey").createWallet($appInfo$$._id.toString(),
86
86
  $obj$$.user_gt,"T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng",8);let $amount$$=$obj$$.tien_hoa_hong_gt,$denom$$=$appInfo$$.tang_gioi_thieu_denom,$memo$$=`Hoa h\u1ed3ng cho \u0111\u01a1n h\u00e0ng s\u1ed1 ${$obj$$.so_ct}: ${numeral($amount$$).format()} ${$denom$$.toUpperCase()}`;await spend($appInfo$$,$obj$$.be_introduced,$wallet_gt$$.address,$amount$$,$denom$$,$memo$$,$obj$$.introduce_code,"2");$obj$$.da_chuyen_hoa_hong_gt=!0;await model.updateOne({_id:$obj$$._id},{da_chuyen_hoa_hong_gt:!0})}}catch($e$$){console.error("Kh\u00f4ng th\u1ec3 thanh to\u00e1n ti\u1ec1n hoa h\u1ed3ng",