UNPKG

flexbiz-server

Version:

Flexible Server

97 lines 61.8 kB
'use strict';const async=require("async"),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("sokhonpp"),Socai=global.getModel("socainpp"),transaction=global.getModel("transaction"),Evoucher=global.getModel("evoucher"),dvcs=global.getModel("dvcs"),dmvt=global.getModel("dmvt"),dmtt=global.getModel("dmtt"),dmcpmh= global.getModel("dmcpmh"),dmkho=global.getModel("dmkho"),customer=global.getModel("customer"),dmdt=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("so9"),pt1=global.getModel("pt1"),controller=require("../../controllers/controller"),ma_ct="SO9",ckdiem=require("../../libs/ckdiem"), tinhhoahong=require("../../libs/tinhhoahongnpp"),blockchainconnect=require("../../libs/blockchainconnect"),App=global.getModel("app"),Introducer=global.getModel("introducer"),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,$receiver_address$$,{amount:$amount$$,denom:$denom$$,memo:$memo$$,action:"bonus",introduce_code:$introduce_code$$,sub_action:$sub_action$$})}catch($e$$){console.error("Error send coin",$e$$,$receiver_user$$,$receiver_address$$,$amount$$,$denom$$,$memo$$)}},tinhtienthue=$detail$$=>{$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),$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* $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_nt$$=$obj$$.details.filter($d$$=>!$d$$.km_yn_for).csum("tien_hang_nt");if(0!==$ckhds_query_t_tien_nt$$){var $hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$=$obj$$.details.filter($d$$=>!$d$$.km_yn_for).csum("tien_ck_nt");$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$=$ckhds_query_t_tien_nt$$-$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$;$obj$$.details=$obj$$.details.filter($d$$=> "khuyenmaihd"!=$d$$.km_yn_for);$ckhds_query_t_tien_nt$$={id_app:$obj$$.id_app,gt_tu:{$lte:$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$},ma_kho:{$in:[void 0,null,"",$obj$$.ma_kho]}};$ckhds_query_t_tien_nt$$.$and=[{$or:[{gt_den:{$in:[0,void 0,null]}},{gt_den:{$gte:$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$}}]}];var $ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$=moment($obj$$.ngay_ct).startOf("date").toDate();$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$={$lte:moment($obj$$.ngay_ct).endOf("date").toDate()};$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$= {$gte:$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$};$ckhds_query_t_tien_nt$$.hieu_luc_tu=$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$;$ckhds_query_t_tien_nt$$.hieu_luc_den=$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$;$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$={$in:[void 0,null,"",$obj$$.ma_kh]};$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$={$in:[void 0,null,""]};if($obj$$.ma_kh){var $kh_lan_mua_thu$$=await customer.findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh},{nh_kh:1});$kh_lan_mua_thu$$&&$kh_lan_mua_thu$$.nh_kh&&($ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$= {$in:[void 0,null,"",$kh_lan_mua_thu$$.nh_kh]});($kh_lan_mua_thu$$=await model.countDocuments({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh,trang_thai:{$in:["5","6"]}}))||($kh_lan_mua_thu$$=0);$kh_lan_mua_thu$$+=1}$ckhds_query_t_tien_nt$$.$or=[{$and:[{ma_kh:$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$},{nh_kh:{$in:["",null,void 0]}}]},{$and:[{nh_kh:$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$},{ma_kh:{$in:["",null,void 0]}}]}];$ckhds_query_t_tien_nt$$.ap_dung_lan_mua_thu={$in:[null,void 0,0,void 0]};$ckhds_query_t_tien_nt$$.online= !0;$ckhds_query_t_tien_nt$$=await dmkhuyenmaihd.find($ckhds_query_t_tien_nt$$).sort({stt_uu_tien:1,gt_tu:-1,ma_kh:-1,nh_kh:-1,hieu_luc_tu:-1}).lean();for($hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$=0;$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$<$ckhds_query_t_tien_nt$$.length;$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$++)if(($ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$=$ckhds_query_t_tien_nt$$[$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$])&&$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.details_km&&0<$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.details_km.length){$kh_lan_mua_thu$$= $ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.sl_toi_thieu||0;let $sl_dap_ung$$=0;$kh_lan_mua_thu$$&&$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.vts&&0<$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.vts.length&&$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.vts.forEach($vt$$=>{var $ds_tien$$=$obj$$.details.filter($d$$=>$d$$.ma_vt===$vt$$.ma_vt&&(!$vt$$.ma_tt1||$vt$$.ma_tt1===$d$$.ma_tt1)&&(!$vt$$.ma_tt2||$vt$$.ma_tt2===$d$$.ma_tt2)&&(!$vt$$.ma_tt3||$vt$$.ma_tt3===$d$$.ma_tt3));if(0!=$ds_tien$$.length){var $so_luong$$=$ds_tien$$.map($d$$=> $d$$.sl_xuat).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$ds_tien$$=$ds_tien$$.map($d$$=>($d$$.tien_hang_nt||0)-($d$$.tien_ck_nt||0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$vt$$.sl_tu&&$so_luong$$<$vt$$.sl_tu||$vt$$.sl_den&&$so_luong$$>$vt$$.sl_den||$vt$$.gt_tu&&$ds_tien$$<$vt$$.gt_tu||$vt$$.gt_den&&$ds_tien$$>$vt$$.gt_den||($sl_dap_ung$$+=1)}});if($kh_lan_mua_thu$$<=$sl_dap_ung$$){$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.details_km.forEach($d$jscomp$6_detail$$=>{$d$jscomp$6_detail$$={...$d$jscomp$6_detail$$,km_yn_for:"khuyenmaihd"}; $d$jscomp$6_detail$$.sl_xuat=$d$jscomp$6_detail$$.sl_km;$d$jscomp$6_detail$$.tien_hang_nt=$d$jscomp$6_detail$$.tien_hang=0;$d$jscomp$6_detail$$.tien_ck_nt=$d$jscomp$6_detail$$.tien_ck=0;$d$jscomp$6_detail$$.ty_le_ck=0;$d$jscomp$6_detail$$.tien_nt=$d$jscomp$6_detail$$.tien=0;$obj$$.details.push($d$jscomp$6_detail$$)});break}}}}},chietkhauhd=async $obj$$=>{if(!$obj$$.signature&&$obj$$.online){$obj$$.tien_ck_hd=0;$obj$$.ty_le_ck_hd=0;var $t_tien_nt$jscomp$1_t_tt_nt$$=$obj$$.details.filter($d$$=>!$d$$.km_yn_for).csum("tien_hang_nt"), $ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$=$obj$$.details.filter($d$$=>!$d$$.km_yn_for).csum("tien_ck_nt");$t_tien_nt$jscomp$1_t_tt_nt$$-=$ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$;$ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$={id_app:$obj$$.id_app,gt_tu:{$lte:$t_tien_nt$jscomp$1_t_tt_nt$$},ma_kho:{$in:[void 0,null,"",$obj$$.ma_kho]}};$ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$.$and=[{$or:[{gt_den:{$in:[0,void 0,null]}},{gt_den:{$gte:$t_tien_nt$jscomp$1_t_tt_nt$$}}]}];var $ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$= moment($obj$$.ngay_ct).startOf("date").toDate();var $hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_kh$$={$lte:moment($obj$$.ngay_ct).endOf("date").toDate()};$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$={$gte:$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$};$ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$.hieu_luc_tu=$hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_kh$$;$ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$.hieu_luc_den=$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$;$hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_kh$$= {$in:[void 0,null,"",$obj$$.ma_kh]};$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$={$in:[void 0,null,""]};if($obj$$.ma_kh){var $kh$jscomp$1_lan_mua_thu$jscomp$3_sl_toi_thieu$$=await customer.findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh},{nh_kh:1});$kh$jscomp$1_lan_mua_thu$jscomp$3_sl_toi_thieu$$&&$kh$jscomp$1_lan_mua_thu$jscomp$3_sl_toi_thieu$$.nh_kh&&($ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$={$in:[void 0,null,"",$kh$jscomp$1_lan_mua_thu$jscomp$3_sl_toi_thieu$$.nh_kh]}); ($kh$jscomp$1_lan_mua_thu$jscomp$3_sl_toi_thieu$$=await model.countDocuments({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh,trang_thai:{$in:["5","6"]}}))||($kh$jscomp$1_lan_mua_thu$jscomp$3_sl_toi_thieu$$=0);$kh$jscomp$1_lan_mua_thu$jscomp$3_sl_toi_thieu$$+=1}$ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$.$or=[{$and:[{ma_kh:$hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_kh$$},{nh_kh:{$in:["",null,void 0]}}]},{$and:[{nh_kh:$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$},{ma_kh:{$in:["",null,void 0]}}]}]; $ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$.ap_dung_lan_mua_thu={$in:[null,void 0,0,void 0]};$ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$.online=!0;$ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$=await dmchietkhauhd.find($ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$).sort({gt_tu:-1,tien_ck:-1,ty_le_ck:-1,ma_kh:-1,nh_kh:-1,hieu_luc_tu:-1}).lean();if(0<$ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$.length)for($hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_kh$$=0;$hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_kh$$<$ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$.length;$hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_kh$$++){$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$= $ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$[$hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_kh$$];$kh$jscomp$1_lan_mua_thu$jscomp$3_sl_toi_thieu$$=$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.sl_toi_thieu||0;let $sl_dap_ung$$=0;$kh$jscomp$1_lan_mua_thu$jscomp$3_sl_toi_thieu$$&&$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.vts&&0<$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.vts.length&&$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.vts.forEach($vt$$=> {var $ds$jscomp$1_tien$$=$obj$$.details.filter($d$$=>$d$$.ma_vt===$vt$$.ma_vt&&(!$vt$$.ma_tt1||$vt$$.ma_tt1===$d$$.ma_tt1)&&(!$vt$$.ma_tt2||$vt$$.ma_tt2===$d$$.ma_tt2)&&(!$vt$$.ma_tt3||$vt$$.ma_tt3===$d$$.ma_tt3));if(0!=$ds$jscomp$1_tien$$.length){var $so_luong$$=$ds$jscomp$1_tien$$.map($d$$=>$d$$.sl_xuat).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$ds$jscomp$1_tien$$=$ds$jscomp$1_tien$$.map($d$$=>($d$$.tien_hang_nt||0)-($d$$.tien_ck_nt||0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$vt$$.sl_tu&&$so_luong$$<$vt$$.sl_tu|| $vt$$.sl_den&&$so_luong$$>$vt$$.sl_den||$vt$$.gt_tu&&$ds$jscomp$1_tien$$<$vt$$.gt_tu||$vt$$.gt_den&&$ds$jscomp$1_tien$$>$vt$$.gt_den||($sl_dap_ung$$+=1)}});if($kh$jscomp$1_lan_mua_thu$jscomp$3_sl_toi_thieu$$<=$sl_dap_ung$$){$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.tien_ck?($obj$$.tien_ck_hd=$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.tien_ck,$obj$$.ty_le_ck_hd=0):($obj$$.ty_le_ck_hd=$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.ty_le_ck, $obj$$.tien_ck_hd=Math.roundBy($t_tien_nt$jscomp$1_t_tt_nt$$*$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.ty_le_ck/100,0));$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.so_tien_max&&($obj$$.tien_ck_hd=Math.min($ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.so_tien_max,$obj$$.tien_ck_hd));break}}}},getPointBalance=async($id_app$$,$sender_email$$)=>new Promise(($resolve$$,$reject$$)=>{ckdiem({id_app:$id_app$$,email:$sender_email$$},($e$$,$rs$$)=> {if($e$$)return $reject$$(Error($e$$));$resolve$$(0===$rs$$.length?0:$rs$$[0].ton00)})}),createTransactionBonus=async function($obj$$){if("5"!=$obj$$.trang_thai&&"6"!=$obj$$.trang_thai)return await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng \u0111\u1ec3 t\u00ednh l\u1ea1i"),await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":introduce"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng gi\u1edbi thi\u1ec7u th\u00e0nh vi\u00ean m\u1edbi \u0111\u1ec3 t\u00ednh l\u1ea1i"), null;let $kh$$=await customer.findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh})||{},$lan_mua$$=(await model.find({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh,ngay_ct:{$lte:$obj$$.ngay_ct}})).length+1;var $_app_diem_thuong_gioi_thieu_old_trans$$=await App.findOne({_id:$obj$$.id_app}),$_intro_amount$$=await Introducer.findOne({id_app:$obj$$.id_app,be_introduced:$obj$$.of_user||$obj$$.user_created});$_app_diem_thuong_gioi_thieu_old_trans$$=$_app_diem_thuong_gioi_thieu_old_trans$$.exfields.diem_thuong_gioi_thieu; 1===$lan_mua$$&&$_app_diem_thuong_gioi_thieu_old_trans$$&&$_intro_amount$$&&await transaction.createTrans({id_app:$obj$$.id_app,sender_email:$obj$$.id_app,receiver_email:$_intro_amount$$.be_introduced_by,amount:$_app_diem_thuong_gioi_thieu_old_trans$$,description:"\u0110i\u1ec3m th\u01b0\u1edfng gi\u1edbi thi\u1ec7u kh\u00e1ch h\u00e0ng",otherData:{ma_ct:$obj$$.ma_ct,so_ct:$obj$$.so_ct,ngay_ct:$obj$$.ngay_ct,id_ct:$obj$$._id.toString()+":introduce"}});if(!$obj$$.exfields.survey)return null;let $now$$= moment(new Date).startOf("date").toDate();$_intro_amount$$=$obj$$.details.filter($d$$=>$d$$.tien_hang).map(async $d$$=>{var $amount$$=await dmvt.findOne({ma_vt:$d$$.ma_vt,id_app:$obj$$.id_app}),$ckdiemthuong_ty_le_diem_thuong$$=await dmdiemthuong.find({id_app:$obj$$.id_app,status:!0,ma_kh:{$in:[null,"",$kh$$.ma_kh]},ma_kho:{$in:[null,"",$obj$$.ma_kho]},nh_kh:{$in:[null,"",$kh$$.nh_kh]},hieu_luc_tu:{$lte:$now$$},hieu_luc_den:{$gte:$now$$},ap_dung_lan_mua_thu:{$in:[0,$lan_mua$$]},ma_vt:{$in:[null,"", void 0,$d$$.ma_vt]},ma_nvt:{$in:[null,"",void 0,$amount$$?$amount$$.ma_nvt:""]}}).sort({ma_vt:-1,ma_nvt:-1,hieu_luc_tu:-1}).limit(1);return 0<$ckdiemthuong_ty_le_diem_thuong$$.length?($amount$$=0,$ckdiemthuong_ty_le_diem_thuong$$[0].tien?($ckdiemthuong_ty_le_diem_thuong$$=$ckdiemthuong_ty_le_diem_thuong$$[0].diem/$ckdiemthuong_ty_le_diem_thuong$$[0].tien)||($amount$$=Math.roundBy(($d$$.tien_hang-($d$$.tien_ck||0))*$ckdiemthuong_ty_le_diem_thuong$$,0)):$amount$$=$ckdiemthuong_ty_le_diem_thuong$$[0].diem* ($d$$.sl_xuat||1),$amount$$):0});if($_intro_amount$$=(await Promise.all($_intro_amount$$)).reduce(($a$$,$b$$)=>$a$$+$b$$,0)){if($_app_diem_thuong_gioi_thieu_old_trans$$=await transaction.findOne({id_ct:$obj$$._id.toString()+":bonus"}),!$_app_diem_thuong_gioi_thieu_old_trans$$||$_app_diem_thuong_gioi_thieu_old_trans$$.amount!==$_intro_amount$$)return await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng \u0111\u1ec3 t\u00ednh l\u1ea1i"), await transaction.createTrans({id_app:$obj$$.id_app,sender_email:$obj$$.id_app,receiver_email:$obj$$.of_user||$obj$$.user_created,amount:$_intro_amount$$,description:"\u0110i\u1ec3m th\u01b0\u1edfng mua h\u00e0ng",otherData:{ma_ct:$obj$$.ma_ct,so_ct:$obj$$.so_ct,ngay_ct:$obj$$.ngay_ct,id_ct:$obj$$._id.toString()+":bonus"}})}else await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng \u0111\u1ec3 t\u00ednh l\u1ea1i")},createTransactionPayment= async function($obj$$){await transaction.deleteTrans({id_ct:$obj$$._id.toString()});$obj$$.paymentByPoints&&await transaction.createTrans({id_app:$obj$$.id_app,sender_email:$obj$$.of_user||$obj$$.user_created,receiver_email:$obj$$.id_app,amount:$obj$$.paymentByPoints,description:"Thanh to\u00e1n cho \u0111\u01a1n h\u00e0ng s\u1ed1 "+$obj$$.so_ct,otherData:{ma_ct:$obj$$.ma_ct,so_ct:$obj$$.so_ct,ngay_ct:$obj$$.ngay_ct,id_ct:$obj$$._id.toString()}})},updateEvoucher=async($id_app$$,$evoucher_code$$,$id_ct_rs$$)=> {if($evoucher_code$$){$id_ct_rs$$=$id_ct_rs$$.toString();var $e$$=await Evoucher.findOne({ma:$evoucher_code$$,id_app:$id_app$$});$e$$?($id_app$$=$e$$.id_ct_useds||[],$id_app$$.push($id_ct_rs$$),$id_app$$=[...(new Set($id_app$$))],$id_ct_rs$$=await Evoucher.findOneAndUpdate({_id:$e$$._id},{id_ct_useds:$id_app$$}),console.log("update id_ct_useds",$evoucher_code$$,$id_app$$,$id_ct_rs$$)):console.error("can't find evoucher",$evoucher_code$$)}},deleteEvoucher=async($id_app$jscomp$2_id_ct_useds$$,$evoucher_code$$, $id_ct$$)=>{if($evoucher_code$$){$id_ct$$=$id_ct$$.toString();var $e$jscomp$3_rs$$=await Evoucher.findOne({id_app:$id_app$jscomp$2_id_ct_useds$$,ma:$evoucher_code$$});$e$jscomp$3_rs$$&&($id_app$jscomp$2_id_ct_useds$$=($e$jscomp$3_rs$$.id_ct_useds||[]).filter($ct$$=>$ct$$!==$id_ct$$),$e$jscomp$3_rs$$=await Evoucher.findOneAndUpdate({_id:$e$jscomp$3_rs$$._id},{id_ct_useds:$id_app$jscomp$2_id_ct_useds$$}),console.log("update id_ct_useds",$evoucher_code$$,$id_app$jscomp$2_id_ct_useds$$,$e$jscomp$3_rs$$))}}, valid=async function($user$$,$obj$$,$next$$,$i$$){$i$$&&($obj$$.online=$i$$.online,$obj$$._id=$i$$._id,$obj$$.details=$obj$$.details||$i$$.details||[],$obj$$.evouchers=$obj$$.evouchers||$i$$.evouchers);if($obj$$.paymentByPoints)try{var $detail$$=await currency.getRate($obj$$.id_app,$obj$$.ma_nt);$detail$$=$detail$$||1;$obj$$.tien_paymentByPoints=$obj$$.paymentByPoints*$detail$$}catch($e$$){return $next$$($e$$.message)}await $obj$$.details.asyncJoinModel2($obj$$.id_app,"vat",{where:"ma_thue",fields:["thue_suat", "tk_thue_co","tk_thue_co_treo"]});for($i$$=0;$i$$<($obj$$.details||[]).length;$i$$++)$detail$$=($obj$$.details||[])[$i$$],$detail$$.line=$i$$,"VND"===$obj$$.ma_nt&&($detail$$.tien_hang=$detail$$.tien_hang_nt,$detail$$.tien_ck=$detail$$.tien_ck_nt||0,$detail$$.gia_ban=$detail$$.gia_ban_nt),$detail$$.tien_nt=Math.max(0,$detail$$.tien_hang_ct_nt-$detail$$.tien_ck_nt+$detail$$.tien_thue_nt),$detail$$.tien=Math.max(0,$detail$$.tien_hang_ct-$detail$$.tien_ck+$detail$$.tien_thue),$detail$$.tien_xuat=$detail$$.tien_xuat_nt, tinhtienthue($detail$$);$obj$$.ma_dvcs?$next$$(null,$obj$$):dvcs.findOne({id_app:$user$$.current_id_app},{_id:1},function($error$$,$dv$$){return $error$$?$next$$($error$$):$dv$$?($obj$$.ma_dvcs=$dv$$._id.toString(),$next$$(null,$obj$$)):$next$$("C\u00f4ng ty/c\u1eeda h\u00e0ng n\u00e0y ch\u01b0a c\u00f3 m\u1ed9t \u0111\u01a1n v\u1ecb c\u01a1 s\u1edf n\u00e0o")})}; module.exports=function($contr_router$$){$contr_router$$=new controller($contr_router$$,model,ma_ct.toLowerCase(),{isVoucher:!0,requireRecaptchaToken:!1,unique:["so_ct"],sort:{ngay_ct:-1,so_ct:-1},onEmitEvent:async($obj$$,$users_will_receive$$,$next$$)=>{$obj$$.user_nv_giao_hang&&$users_will_receive$$.push($obj$$.user_nv_giao_hang);$next$$(null,$users_will_receive$$)}});$contr_router$$.route();$contr_router$$.validating=async($user$$,$obj$$,$next$$)=>{$obj$$.sdt_nguoi_nhan&&($obj$$.sdt_nguoi_nhan= $obj$$.sdt_nguoi_nhan.split(" ").join(""));if($obj$$.sdt_nguoi_nhan&&!utils.isMobilePhone($obj$$.sdt_nguoi_nhan,"vi-VN"))return $next$$(`S\u1ed1 \u0111i\u1ec7n tho\u1ea1i ng\u01b0\u1eddi nh\u1eadn ${$obj$$.sdt_nguoi_nhan} l\u00e0 kh\u00f4ng h\u1ee3p l\u1ec7`);$next$$(null,$obj$$)};$contr_router$$.saving=async($user$$,$obj$$)=>{$obj$$.user_created||($obj$$.user_created=$user$$.email);$obj$$.of_user="";if(!$obj$$.ma_kho){var $kho_npp_kho_npp$$=await global.getModel("dmkho").findOne({id_app:$obj$$.id_app, user_npp:$user$$.email,la_kho_npp:!0}).lean();!$kho_npp_kho_npp$$&&($kho_npp_kho_npp$$=await global.getModel("dmkho").findOne({id_app:$obj$$.id_app,ds_ctv_npp:$user$$.email,la_kho_npp:!0}).lean())&&($obj$$.user_ctv=$user$$.email);$kho_npp_kho_npp$$&&($obj$$.ma_kho=$kho_npp_kho_npp$$.ma_kho,$obj$$.of_user=$kho_npp_kho_npp$$.user_npp)}!$obj$$.of_user&&$obj$$.ma_kho&&($kho_npp_kho_npp$$=await global.getModel("dmkho").findOne({id_app:$obj$$.id_app,ma_kho:$obj$$.ma_kho,la_kho_npp:!0}).lean())&&($obj$$.of_user= $kho_npp_kho_npp$$.user_npp);$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_hang_ct_nt-$d$$.tien_ck_nt;$d$$.tt=$d$$.tien_hang_ct-$d$$.tien_ck});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, 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$$){$fn$$||($fn$$=function(){});$obj$$.ma_kh&&(await global.getModel("customer").updateOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh,ma_kho_npp:{$exists:!1}},{ma_kho_npp:$obj$$.ma_kho}),await global.getModel("cache").deleteMany({id_app:$obj$$.id_app, key:"customer"}));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();let $kho_npp$$=await global.getModel("dmkho").findOne({id_app:$obj$$.id_app,ma_kho:$obj$$.ma_kho,la_kho_npp:1},{user_npp:1}).lean();const $cust_npp$$=$kho_npp$$&&$kho_npp$$.user_npp?await customer.findOne({id_app:$obj$$.id_app,of_user:$kho_npp$$.user_npp},{ma_kh:1}).lean():void 0;await $obj$$.details.filter($d$$=>!$d$$.ma_thue).asyncJoinModel2($obj$$.id_app, dmvt,{where:"ma_vt",fields:["ma_thue","gia_mua"]});await $obj$$.details.filter($d$$=>$d$$.ma_thue).asyncJoinModel2($obj$$.id_app,global.getModel("vat"),{where:"ma_thue",fields:["thue_suat","tk_thue_co","tk_thue_co_treo"]});let $product_details$$=$obj$$.details.map($detail$$=>$detail$$.combo&&0<$detail$$.combo.length?$detail$$.combo.map($item$$=>{$item$$=$item$$.toObject?$item$$.toObject():{...$item$$};$item$$.ma_kho=$detail$$.ma_kho;delete $item$$.px_gia_dd;return $item$$}):[$detail$$]).reduce(($a$$, $b$$)=>$a$$.concat($b$$),[]);async.series({post_sokho:function($callback$jscomp$0$$){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$jscomp$0$$($e$$,$rs$$)})},post_socainpp:function($callback$$){options.findOne({id_app:$obj$$.id_app, id_func:ma_ct.toLowerCase()}).lean().exec(async($error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$,$rs$jscomp$4_tien_paymentByPoints_tt$$)=>{let $option$$;$option$$=$rs$jscomp$4_tien_paymentByPoints_tt$$?$rs$jscomp$4_tien_paymentByPoints_tt$$.option||{}:{};($error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$=await dmkho.findOne({id_app:$obj$$.id_app,ma_kho:$obj$$.ma_kho}).lean())||($error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$={});let $pt$$;$obj$$.pt_thanh_toan&& global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan)&&($pt$$=await ptthanhtoan.findOne({id_app:$obj$$.id_app,_id:$obj$$.pt_thanh_toan}).lean());$pt$$=$pt$$||{};$pt$$.tk_tien=$pt$$.tk_cn;$pt$$.tk_cn=$pt$$.tk_cn||$error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_cn;$pt$$.tk_dt=$error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_dt||$pt$$.tk_dt;$pt$$.tk_gv=$error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_gv||$pt$$.tk_gv;$pt$$.tk_ck= $error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_ck||$pt$$.tk_ck;$pt$$.tk_cp_gh=$error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_cp_gh||$pt$$.tk_cp_gh;$pt$$.tk_cp_bh=$error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_cp_bh||$pt$$.tk_cp_bh;$pt$$.tk_cp_ctv=$error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_cp_ctv||$pt$$.tk_cp_ctv;$pt$$.tk_cn_ctv=$error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_cn_ctv|| $pt$$.tk_cn_ctv;$option$$.tk_tien=$pt$$.tk_tien||$error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.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;$option$$.tk_cn_ctv=$pt$$.tk_cn_ctv||$option$$.tk_cn_ctv;$pt$$.ten&&0<=$pt$$.ten.indexOf("COD")?$option$$.ma_kh=$obj$$.nhan_vien_giao_hang||$obj$$.don_vi_vc||$pt$$.ma_kh||$obj$$.ma_kh:$option$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh;const $details$$=[];$error$jscomp$2_kho_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$4_tien_paymentByPoints_tt$$=$obj$$.tien_paymentByPoints||0;const $hoachtoandtvathue$$=($tk_tien$$,$ty_le$$)=>{$obj$$.details.forEach(function($d$jscomp$19_detail$$){$d$jscomp$19_detail$$={...$d$jscomp$19_detail$$};let $tien_nt$$=$d$jscomp$19_detail$$.tien_hang_ct_nt;$d$jscomp$19_detail$$.tk_co=$option$$.tk_dt;$d$jscomp$19_detail$$.tk_no=$tk_tien$$;$d$jscomp$19_detail$$.ma_kh_co=$obj$$.ma_kh; $d$jscomp$19_detail$$.ma_kh_no=$option$$.ma_kh;$d$jscomp$19_detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;$d$jscomp$19_detail$$.tien=$d$jscomp$19_detail$$.tien_nt=Math.roundBy($tien_nt$$*$ty_le$$);$d$jscomp$19_detail$$.flag="DT_"+($d$jscomp$19_detail$$.ma_vt||"");$details$$.push($d$jscomp$19_detail$$)});$obj$$.details.filter($d$$=>$d$$.tien_thue).forEach($detail$$=>{$detail$$={...$detail$$};$detail$$.tk_no=$tk_tien$$;$detail$$.tk_co=$detail$$.tk_thue_co_treo||$detail$$.tk_thue_co;$detail$$.ma_kh|| ($detail$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh);$detail$$.tien=$detail$$.tien_nt=Math.roundBy($detail$$.tien_thue_nt*$ty_le$$);$detail$$.flag="THUE_"+($detail$$.ma_vt||"");$details$$.push($detail$$)})};$error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$&&($hoachtoandtvathue$$($option$$.tk_cn,$rs$jscomp$4_tien_paymentByPoints_tt$$/$error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$),$hoachtoandtvathue$$($option$$.tk_tien,($error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$- $rs$jscomp$4_tien_paymentByPoints_tt$$)/$error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$));$obj$$.details.filter($d$$=>$d$$.diem_thuong&&$d$$.tk_km_no&&$d$$.tk_km_co).forEach(function($d$$){let $detail$$={...$d$$};$detail$$.tk_co=$option$$.tk_km_co||$d$$.tk_km_co;$detail$$.tk_no=$option$$.tk_km_no||$d$$.tk_km_no;$detail$$.ma_kh=$obj$$.ma_kh;$detail$$.tien=$detail$$.tien_nt=$detail$$.diem_thuong*$he_so_qd$$;$details$$.push($detail$$)});$obj$$.ctcpbhs&&$obj$$.ctcpbhs.forEach(function($d$jscomp$23_detail$$){$d$jscomp$23_detail$$= {...$d$jscomp$23_detail$$};$d$jscomp$23_detail$$.tk_co=$option$$.tk_dt;$d$jscomp$23_detail$$.tk_no=$option$$.tk_cn;$d$jscomp$23_detail$$.ma_kh_co=$obj$$.ma_kh;$d$jscomp$23_detail$$.ma_kh_no=$option$$.ma_kh;$d$jscomp$23_detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;$d$jscomp$23_detail$$.tien_nt=$d$jscomp$23_detail$$.tien_cp_nt;$d$jscomp$23_detail$$.tien=$d$jscomp$23_detail$$.tien_cp;$details$$.push($d$jscomp$23_detail$$)});$obj$$.tien_phi_vc&&($error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$= {},$error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_co=$option$$.tk_dt,$error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_no=$option$$.tk_cn,$error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien_nt=$obj$$.tien_phi_vc||0,$error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien=$error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien_nt,$error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.ma_kh_co= $obj$$.ma_kh,$error$jscomp$2_kho_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$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$));$obj$$.tien_freeship&&($error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$={},$error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_no=$option$$.tk_cp_gh,$error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_co=$option$$.tk_cn,$error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien_nt= $obj$$.tien_freeship||0,$error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien=$error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien_nt,$error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.ma_kh_no=$obj$$.ma_kh,$error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.ma_kh_co=$option$$.ma_kh,$details$$.push($error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$));$obj$$.tt_tien_thuong&&($error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$= {},$error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_no=$option$$.tk_cp_bh,$error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_co=$option$$.tk_cn,$error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien_nt=$obj$$.tt_tien_thuong||0,$error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien=$error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien_nt,$error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.ma_kh_no= $obj$$.ma_kh,$error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.ma_kh_co=$option$$.ma_kh,$details$$.push($error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$));$obj$$.tien_evoucher&&($error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$={},$error$jscomp$2_kho_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$2_kho_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$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien_nt=$obj$$.tien_evoucher||0,$error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien=$error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien_nt,$error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.ma_kh_no=$obj$$.ma_kh,$error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.ma_kh_co=$option$$.ma_kh,$error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.check_balance= !1,$details$$.push($error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$));if($error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$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))$rs$jscomp$4_tien_paymentByPoints_tt$$={},$rs$jscomp$4_tien_paymentByPoints_tt$$.tk_no=$option$$.tk_ck,$rs$jscomp$4_tien_paymentByPoints_tt$$.tk_co=$option$$.tk_cn,$rs$jscomp$4_tien_paymentByPoints_tt$$.tien_nt=$error$jscomp$2_kho_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$, $rs$jscomp$4_tien_paymentByPoints_tt$$.tien=$rs$jscomp$4_tien_paymentByPoints_tt$$.tien_nt,$rs$jscomp$4_tien_paymentByPoints_tt$$.ma_kh_no=$obj$$.ma_kh,$rs$jscomp$4_tien_paymentByPoints_tt$$.ma_kh_co=$option$$.ma_kh,$rs$jscomp$4_tien_paymentByPoints_tt$$.check_balance=!1,$details$$.push($rs$jscomp$4_tien_paymentByPoints_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$25_detail$$){$d$jscomp$25_detail$$= {...$d$jscomp$25_detail$$};$d$jscomp$25_detail$$.tk_no=$option$$.tk_gv;$d$jscomp$25_detail$$.ma_kh=$obj$$.ma_kh;$d$jscomp$25_detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;$d$jscomp$25_detail$$.tk_co=$d$jscomp$25_detail$$.tk_vt||"1561";$d$jscomp$25_detail$$.tien_nt=$d$jscomp$25_detail$$.tien_xuat_nt;$d$jscomp$25_detail$$.tien=$d$jscomp$25_detail$$.tien_xuat;$d$jscomp$25_detail$$.tg_tk||($d$jscomp$25_detail$$.tien=$d$jscomp$25_detail$$.tien_nt=0);$d$jscomp$25_detail$$.ma_nt="VND";$d$jscomp$25_detail$$.ty_gia= 1;$details$$.push($d$jscomp$25_detail$$)});(new PostSocai($obj$$,$details$$,null,Socai)).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})})})},post_socai:function($callback$$){options.findOne({id_app:$obj$$.id_app,id_func:ma_ct.toLowerCase()}).lean().exec(async($error$jscomp$3_option$$,$rs$jscomp$6_tt$$)=>{$error$jscomp$3_option$$=$rs$jscomp$6_tt$$?$rs$jscomp$6_tt$$.option||{}:{};let $kho$$=await dmkho.findOne({id_app:$obj$$.id_app,ma_kho:$obj$$.ma_kho}).lean();$kho$$||($kho$$={});var $pt$jscomp$1_tien_ck_hd$$; $obj$$.pt_thanh_toan&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan)&&($pt$jscomp$1_tien_ck_hd$$=await ptthanhtoan.findOne({id_app:$obj$$.id_app,_id:$obj$$.pt_thanh_toan}).lean());$pt$jscomp$1_tien_ck_hd$$=$pt$jscomp$1_tien_ck_hd$$||{};$pt$jscomp$1_tien_ck_hd$$.tk_tien=$pt$jscomp$1_tien_ck_hd$$.tk_cn;$pt$jscomp$1_tien_ck_hd$$.tk_cn=$pt$jscomp$1_tien_ck_hd$$.tk_cn||$kho$$.tk_cn;$pt$jscomp$1_tien_ck_hd$$.tk_dt=$kho$$.tk_dt||$pt$jscomp$1_tien_ck_hd$$.tk_dt;$pt$jscomp$1_tien_ck_hd$$.tk_gv= $kho$$.tk_gv||$pt$jscomp$1_tien_ck_hd$$.tk_gv;$pt$jscomp$1_tien_ck_hd$$.tk_ck=$kho$$.tk_ck||$pt$jscomp$1_tien_ck_hd$$.tk_ck;$pt$jscomp$1_tien_ck_hd$$.tk_cp_gh=$kho$$.tk_cp_gh||$pt$jscomp$1_tien_ck_hd$$.tk_cp_gh;$pt$jscomp$1_tien_ck_hd$$.tk_cp_bh=$kho$$.tk_cp_bh||$pt$jscomp$1_tien_ck_hd$$.tk_cp_bh;$pt$jscomp$1_tien_ck_hd$$.tk_cp_ctv=$kho$$.tk_cp_ctv||$pt$jscomp$1_tien_ck_hd$$.tk_cp_ctv;$pt$jscomp$1_tien_ck_hd$$.tk_cn_ctv=$kho$$.tk_cn_ctv||$pt$jscomp$1_tien_ck_hd$$.tk_cn_ctv;$error$jscomp$3_option$$.tk_tien= $pt$jscomp$1_tien_ck_hd$$.tk_tien||$kho$$.tk_tien||$error$jscomp$3_option$$.tk_tien||"1111";$error$jscomp$3_option$$.tk_cn=$pt$jscomp$1_tien_ck_hd$$.tk_cn||$error$jscomp$3_option$$.tk_cn||"131111";$error$jscomp$3_option$$.tk_dt=$pt$jscomp$1_tien_ck_hd$$.tk_dt||$error$jscomp$3_option$$.tk_dt||"51111";$error$jscomp$3_option$$.tk_tl=$pt$jscomp$1_tien_ck_hd$$.tk_tl||$error$jscomp$3_option$$.tk_tl||"52131";$error$jscomp$3_option$$.tk_ck=$pt$jscomp$1_tien_ck_hd$$.tk_ck||$error$jscomp$3_option$$.tk_ck|| "52111";$error$jscomp$3_option$$.tk_gv=$pt$jscomp$1_tien_ck_hd$$.tk_gv||$error$jscomp$3_option$$.tk_gv||"6321";$error$jscomp$3_option$$.tk_cp_gh=$pt$jscomp$1_tien_ck_hd$$.tk_cp_gh||$error$jscomp$3_option$$.tk_cp_gh||"6418";$error$jscomp$3_option$$.tk_cp_bh=$pt$jscomp$1_tien_ck_hd$$.tk_cp_bh||$error$jscomp$3_option$$.tk_cp_bh||$error$jscomp$3_option$$.tk_ck;$error$jscomp$3_option$$.tk_cp_ctv=$pt$jscomp$1_tien_ck_hd$$.tk_cp_ctv||$error$jscomp$3_option$$.tk_cp_ctv;$error$jscomp$3_option$$.tk_cn_ctv= $pt$jscomp$1_tien_ck_hd$$.tk_cn_ctv||$error$jscomp$3_option$$.tk_cn_ctv;$pt$jscomp$1_tien_ck_hd$$.ten&&0<=$pt$jscomp$1_tien_ck_hd$$.ten.indexOf("COD")?$error$jscomp$3_option$$.ma_kh=$obj$$.nhan_vien_giao_hang||$obj$$.don_vi_vc||$pt$jscomp$1_tien_ck_hd$$.ma_kh||$obj$$.ma_kh:$error$jscomp$3_option$$.ma_kh=$pt$jscomp$1_tien_ck_hd$$.ma_kh||$obj$$.ma_kh;const $details$$=[];$cust_npp$$&&($pt$jscomp$1_tien_ck_hd$$=($obj$$.tien_ck_hd||0)+$obj$$.details.map($d$$=>$d$$.tien_ck_nt||0).reduce(($a$$,$b$$)=>$a$$+ $b$$,0))&&($rs$jscomp$6_tt$$={},$rs$jscomp$6_tt$$.tk_no=$error$jscomp$3_option$$.tk_ck_npp||$error$jscomp$3_option$$.tk_ck,$rs$jscomp$6_tt$$.tk_co=$error$jscomp$3_option$$.tk_cn_npp||$error$jscomp$3_option$$.tk_cn,$rs$jscomp$6_tt$$.tien_nt=$pt$jscomp$1_tien_ck_hd$$,$rs$jscomp$6_tt$$.tien=$rs$jscomp$6_tt$$.tien_nt*($obj$$.ty_gia||1),$rs$jscomp$6_tt$$.ma_kh=$cust_npp$$.ma_kh,$rs$jscomp$6_tt$$.check_balance=!1,$details$$.push($rs$jscomp$6_tt$$));$obj$$.thu_nhap_ctv&&$obj$$.ma_ctv&&($obj$$.details.filter($r$$=> $r$$.tien_hoa_hong_ctv).forEach($r$$=>{$r$$.tk_cp_ctv=$r$$.tk_cp_ctv||$obj$$.tk_cp_ctv||$kho$$.tk_cp_ctv||options.tk_cp_ctv||$obj$$.tk_no_hoa_hong||$kho$$.tk_no_hoa_hong||options.tk_no_hoa_hong;$r$$.tk_cn_ctv=$r$$.tk_cn_ctv||$obj$$.tk_cn_ctv||$kho$$.tk_cn_ctv||options.tk_cn_ctv||$obj$$.tk_co_hoa_hong||$kho$$.tk_co_hoa_hong||options.tk_co_hoa_hong}),(await $obj$$.details.filter($r$$=>$r$$.tien_hoa_hong_ctv).asyncGroupBy(["tk_cp_ctv","tk_cn_ctv"],["tien_hoa_hong_ctv"])).forEach($r$$=>{let $tt$$={}; $tt$$.tk_no=$r$$.tk_cp_ctv;$tt$$.tk_co=$r$$.tk_cn_ctv;$tt$$.tien=$tt$$.tien_nt=$r$$.tien_hoa_hong_ctv;$tt$$.ma_kh=$obj$$.ma_ctv;$tt$$.ma_nt="VND";$tt$$.ty_gia=1;$tt$$.tk_no&&$tt$$.tk_co&&$details$$.push($tt$$)}));$obj$$.tien_hoa_hong&&$obj$$.ma_kh_hoa_hong&&($obj$$.details.filter($r$$=>$r$$.tien_hoa_hong).forEach($r$$=>{$r$$.tk_no_hoa_hong=$r$$.tk_no_hoa_hong||$obj$$.tk_no_hoa_hong||$kho$$.tk_no_hoa_hong||options.tk_no_hoa_hong;$r$$.tk_co_hoa_hong=$r$$.tk_co_hoa_hong||$obj$$.tk_co_hoa_hong||$kho$$.tk_co_hoa_hong|| options.tk_co_hoa_hong}),(await $obj$$.details.filter($r$$=>$r$$.tien_hoa_hong).asyncGroupBy(["tk_no_hoa_hong","tk_co_hoa_hong"],["tien_hoa_hong"])).forEach($r$$=>{let $tt$$={};$tt$$.tk_no=$r$$.tk_no_hoa_hong;$tt$$.tk_co=$r$$.tk_co_hoa_hong;$tt$$.tien=$tt$$.tien_nt=$r$$.tien_hoa_hong;$tt$$.tien=$tt$$.tien_nt*($obj$$.ty_gia||1);$tt$$.ma_kh=$obj$$.ma_kh_hoa_hong;$tt$$.ma_nv=$obj$$.ma_nv;$tt$$.check_balance=!1;$tt$$.ma_nt="VND";$tt$$.ty_gia=1;$tt$$.tk_no&&$tt$$.tk_co&&$details$$.push($tt$$)}));$obj$$.tien_hoa_hong_gt&& $obj$$.ma_kh_hoa_hong_gt&&($obj$$.details.filter($r$$=>$r$$.tien_hoa_hong_gt).forEach($r$$=>{$r$$.tk_no_hoa_hong_gt=$r$$.tk_no_hoa_hong_gt||$obj$$.tk_no_hoa_hong_gt||$kho$$.tk_no_hoa_hong_gt||options.tk_no_hoa_hong_gt||$obj$$.tk_no_hoa_hong||$kho$$.tk_no_hoa_hong||options.tk_no_hoa_hong;$r$$.tk_co_hoa_hong_gt=$r$$.tk_co_hoa_hong_gt||$obj$$.tk_co_hoa_hong_gt||$kho$$.tk_co_hoa_hong_gt||options.tk_co_hoa_hong_gt||$obj$$.tk_co_hoa_hong||$kho$$.tk_co_hoa_hong||options.tk_co_hoa_hong}),(await $obj$$.details.filter($r$$=> $r$$.tien_hoa_hong_gt).asyncGroupBy(["tk_no_hoa_hong_gt","tk_co_hoa_hong_gt"],["tien_hoa_hong_gt"])).forEach($r$$=>{let $tt$$={};$tt$$.tk_no=$r$$.tk_no_hoa_hong_gt;$tt$$.tk_co=$r$$.tk_co_hoa_hong_gt;$tt$$.tien_nt=$r$$.tien_hoa_hong_gt;$tt$$.tien=$tt$$.tien_nt*($obj$$.ty_gia||1);$tt$$.ma_kh=$obj$$.ma_kh_hoa_hong_gt;$tt$$.ma_nv=$obj$$.ma_nv;$tt$$.check_balance=!1;$tt$$.ma_nt="VND";$tt$$.ty_gia=1;$tt$$.tk_no&&$tt$$.tk_co&&$details$$.push($tt$$)}));(new PostSocai($obj$$,$details$$,null,global.getModel("socai"))).run(function($e$$, $rs$$){console.log("post result",$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$$||($wallet_nhan_vien$$= await global.getModel("asskey").createWallet($appInfo$$._id.toString(),$obj$$.user_nv,"T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng",8));let $amount$$=$obj$$.tien_hoa_hong,$denom$$=$appInfo$$.tang_gioi_thieu_denom,$memo$$=`Hoa h\u1ed3ng cho \u0111\u01a1n h\u00e0ng s\u1ed1 ${$obj$$.so_ct}: ${numeral($amount$$).format()} ${$denom$$.toUpperCase()}`;await spend($appInfo$$,$obj$$.be_introduced,$wallet_nhan_vien$$.address,$amount$$,$denom$$,$memo$$,"","2");$obj$$.da_chuyen_hoa_hong=!0;await model.updateOne({_id:$obj$$._id}, {da_chuyen_hoa_hong:!0})}}catch($e$$){console.error("Kh\u00f4ng th\u1ec3 thanh to\u00e1n ti\u1ec1n hoa h\u1ed3ng",$e$$)}$callback$$()})},thanhtoanhoahonggt:$callback$$=>{if($obj$$.da_chuyen_hoa_hong_gt||!$obj$$.tien_hoa_hong_gt||!$obj$$.user_gt||!$obj$$.chuyen_ngay_gt)return $callback$$();setImmediate(async()=>{try{if($appInfo$$.wallet_address&&$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$$||($wallet_gt$$=await global.getModel("asskey").createWallet($appInfo$$._id.toString(),$obj$$.user_gt,"T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng",8));let $amount$$=$obj$$.tien_hoa_hong_gt,$denom$$=$appInfo$$.tang_gioi_thieu_denom,$memo$$=`Hoa h\u1ed3ng cho \u0111\u01a1n h\u00e0ng s\u1ed1 ${$obj$$.so_ct}: ${numeral($amount$$).format()} ${$denom$$.toUpperCase()}`;await spend($appInfo$$,$obj$$.be_introduced,$wallet_gt$$.address,$amount$$,$denom$$,$memo$$,$obj$$.introduce_code, "2");$obj$$.da_chuyen_hoa_hong_gt=!0;await model.updateOne({_id:$obj$$._id},{da_chuyen_hoa_hong_gt:!0})}}catch($e$$){console.error("Kh\u00f4ng th\u1ec3 thanh to\u00e1n ti\u1ec1n hoa h\u1ed3ng",$e$$)}$callback$$()})},thanhtoanhoahongctv:$callback$$=>{if($obj$$.da_chuyen_hoa_hong_ctv||!$obj$$.thu_nhap_ctv||!$obj$$.user_ctv||!$obj$$.chuyen_ngay_ctv)return $callback$$();setImmediate(async()=>{try{if($appInfo$$.wallet_address&&$appInfo$$.wallet_token&&$appInfo$$.tang_gioi_thieu_denom){let $wallet_gt$$= await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),username:$obj$$.user_ctv,wallet_type:8});$wallet_gt$$||($wallet_gt$$=await global.getModel("asskey").createWallet($appInfo$$._id.toString(),$obj$$.user_ctv,"T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng",8));let $amount$$=$obj$$.thu_nhap_ctv,$denom$$=$appInfo$$.tang_gioi_thieu_denom,$memo$$=`Hoa h\u1ed3ng cho \u0111\u01a1n h\u00e0ng s\u1ed1 ${$obj$$.so_ct}: ${numeral($amount$$).format()} ${$denom$$.toUpperCase()}`;await spend($appInfo$$, $obj$$.be_introduced,$wallet_gt$$.address,$amount$$,$denom$$,$memo$$,$obj$$.introduce_code,"2");$obj$$.da_chuyen_hoa_hong_ctv=!0;await model.updateOne({_id:$obj$$._id},{da_chuyen_hoa_hong_ctv:!0})}}catch($e$$){console.error("Kh\u00f4ng th\u1ec3 thanh to\u00e1n ti\u1ec1n hoa h\u1ed3ng",$e$$)}$callback$$()})}},function($e$$,$rs$$){$fn$$($e$$,$rs$$)})};$contr_router$$.creating=async function($user$$,$obj$$,$next$$){$obj$$.details||($obj$$.details=[]);if(!$obj$$.ma_kh){var $kh$$=await customer.findOne({id_app:$obj$$.id_app|| $user$$.current_id_app,of_user:$user$$.email},{ma_kh:-1});$kh$$&&($obj$$.ma_kh=$kh$$.ma_kh)}delete $obj$$.virtual_payment_client_url;$obj$$.da_chuyen_hoa_hong=!1;$obj$$.da_chuyen_hoa_hong_gt=!1;await $obj$$.details.asyncJoinModel2($user$$.current_id_app,dmvt,{where:"ma_vt",setFields:($item$$,$ref$$)=>{$item$$.ten_vt=$ref$$.ten_vt;$item$$.combo=$ref$$.combo||[];$item$$.ma_thue=$ref$$.ma_thue;$item$$.status_vt=$ref$$.status;$item$$.gia_mua=$ref$$.gia_mua_tmp}});$kh$$=$obj$$.details.filter($d$$=>!$d$$.status_vt); if(0<$kh$$.length)return $next$$(`C\u00e1c m\u1eb7t h\u00e0ng sau \u0111\u00e3 ng\u1eebng kinh doanh : ${$kh$$.map($d$$=>$d$$.ten_vt).join(",")}`);let $ngay_nay_thang_truoc$$=moment($obj$$.ngay_ct).subtract(1,"months").toDate(),$details$$=[];$obj$$.details.forEach($d$$=>{$d$$.combo&&0<$d$$.combo.length?$details$$=[...$details$$,...$d$$.combo]:$details$$.push($d$$)});await $details$$.filter($r$$=>!$r$$.gia_mua).asyncJoinModel2($obj$$.id_app,"giatb",{where:$item$$=>({ma_vt:$item$$.ma_vt,id_app:$obj$$.id_app, nam:$ngay_nay_thang_truoc$$.getFullYear(),thang:$ngay_nay_thang_truoc$$.getMonth()+1}),fields:[{gia_mua:"gia"}]});$ngay_nay_thang_truoc$$=moment($ngay_nay_thang_truoc$$).subtract(1,"months").toDate();await $details$$.filter($r$$=>!$r$$.gia_mua).asyncJoinModel2($obj$$.id_app,"giatb",{where:$item$$=>({ma_vt:$item$$.ma_vt,id_app:$obj$$.id_app,nam:$ngay_nay_thang_truoc$$.getFullYear(),thang:$ngay_nay_thang_truoc$$.getMonth()+1}),fields:[{gia_mua:"gia"}]});$obj$$.details.forEach($detail$$=>{$detail$$.combo&& 0<$detail$$.combo.length&&($detail$$.combo=$detail$$.combo.map($item$$=>{$item$$=$item$$.toObject?$item$$.toObject():{...$item$$};$item$$.sl_xuat_1_combo=$item$$.sl_xuat;$item$$.sl_xuat=$item$$.sl_xuat_1_combo*$detail$$.sl_xuat;$item$$.tien_xuat=$item$$.tien_xuat_nt=$item$$.sl_xuat*($item$$.gia_von_nt||0);$item$$.tien_hang=$item$$.tien_hang_nt=$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$$}),$detail$$.gia_mua=$detail$$.combo.map($c$$=>($c$$.gia_mua||0)*$c$$.sl_xuat_1_combo).reduce(($a$$,$b$$)=>$a$$+$b$$,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,$obj$$.of_user||$user$$.email)<$obj$$.paymentByPoints)return $next$$("B\u1ea1n kh\u00f4ng c\u00f3 \u0111\u1ee7 \u0111i\u1ec3m \u0111\u1ec3 th\u1ef1c hi\u1ec7n giao d\u1ecbch n\u00e0y."); $next$$(null,$obj$$)}catch($e$$){$next$$($e$$.message)}})};$contr_router$$.created=async function($user$$,$obj$$,$next$$){if($obj$$.pt_thanh_toan&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan))try{const $pt_thanh_toan$$=await global.getModel("ptthanhtoan").findOne({_id:$obj$$.pt_thanh_toan});if($pt_thanh_toan$$.payment_service){let $paymentServiceModel$$=global.getModel($pt_thanh_toan$$.payment_service);$obj$$.amount=$obj$$.t_tt_nt-($obj$$.tien_paymentByPoints||0);if($obj$$.amount&& $paymentServiceModel$$.createVirtualPaymentClientURL){let $virtual_payment_client_url$$=await $paymentServiceModel$$.createVirtualPaymentClientURL($obj$$,$user$$.clientIp,$pt_thanh_toan$$);$obj$$.virtual_payment_client_url=$virtual_payment_client_url$$;$obj$$.payment_service=$pt_thanh_toan$$.payment_service;$obj$$.payment_id=((await $paymentServiceModel$$.findOne({$or:[{id_ct:$obj$$._id.toString()},{request_id:$obj$$._id.toString()},{order_id:$obj$$._id.toString()}]})||{})._id||"").toString()}else $obj$$.virtual_payment_client_url= "",$obj$$.payment_service="",$obj$$.payment_id=""}else $obj$$.virtual_payment_client_url=""}catch($e$$){return console.error($e$$),$next$$("Kh\u00f4ng tao li\u00ean k\u1ebft thanh to\u00e1n:"+($e$$.message||$e$$.error||$e$$))}else console.log("Chua nhap phuong thuc thanh toan"),$obj$$.virtual_payment_client_url="";model.findOneAndUpdate({_id:$obj$$._id},{virtual_payment_client_url:$obj$$.virtual_payment_client_url,payment_id:$obj$$.payment_id,payment_service:$obj$$.payment_service},$e$$=>{$e$$&&(console.error($e$$), console.log("error create Virtual Payment ClientURL",$e$$.message))});await createTransactionPayment($obj$$);await createTransactionBonus($obj$$);$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>updateEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$next$$(null,$obj$$)};$contr_router$$.updating=async($user$$,$data$$,$obj$$,$next$$)=>{$data$$.details||($data$$.details=$obj$$.details);$data$$.ngay_ct=$data$$.ngay_ct||$obj$$.ngay_ct;if("10"==$data$$.trang_thai&&0>["LCT","0","1"].indexOf($obj$$.trang_thai)&& $user$$.email===$obj$$.user_created)return $next$$("Kh\u00f4ng th\u1ec3 hu\u1ef7 \u0111\u01a1n h\u00e0ng n\u00e0y");$data$$.da_chuyen_hoa_hong=$obj$$.da_chuyen_hoa_hong;$data$$.da_chuyen_hoa_hong_gt=$obj$$.da_chuyen_hoa_hong_gt;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||[]);$item$$.gia_mua=$ref$$.gia_mua_tmp;$obj$$.details.find($d$$=>$d$$.ma_vt===$item$$.ma_vt)?$item$$.ma_thue||($item$$.ma_thue=$ref$$.ma_thue):$item$$.ma_thue=$ref$$.ma_thue}});let $ngay_nay_thang_truoc$$=moment($data$$.ngay_ct).subtract(1,"months").toDate(),$details$$=[];$data$$.details.forEach($d$$=>{$d$$.combo&&0<$d$$.combo.length?$details$$=[...$details$$,...$d$$.combo]:$details$$.push($d$$)});await $details$$.filter($r$$=>!$r$$.gia_mua).asyncJoinModel2($obj$$.id_app, "giatb",{where:$item$$=>({ma_vt:$item$$.ma_vt,id_app:$obj$$.id_app,nam:$ngay_nay_thang_truoc$$.getFullYear(),thang:$ngay_nay_thang_truoc$$.getMonth()+1}),fields:[{gia_mua:"gia"}]});$ngay_nay_thang_truoc$$=moment($ngay_nay_thang_truoc$$).subtract(1,"months").toDate();await $details$$.filter($r$$=>!$r$$.gia_mua).asyncJoinModel2($obj$$.id_app,"giatb",{where:$item$$=>({ma_vt:$item$$.ma_vt,id_app:$obj$$.id_app,nam:$ngay_nay_thang_truoc$$.getFullYear(),thang:$ngay_nay_thang_truoc$$.getMonth()+1}),fields:[{gia_mua:"gia"}]}); await $data$$.details.asyncJoinModel2($obj$$.id_app,"vat",{where:"ma_thue",fields:["thue_suat","tk_thue_co","tk_thue_co_treo"]});$data$$.details.forEach($detail$$=>{$detail$$.combo&&0<$detail$$.combo.length&&($detail$$.combo=$detail$$.combo.map($item$$=>{$item$$=$item$$.toObject?$item$$.toObject():{...$item$$};void 0==$item$$.sl_xuat_1_combo&&($item$$.sl_xuat_1_combo=$item$$.sl_xuat||0);$item$$.sl_xuat=$item$$.sl_xuat_1_combo*$detail$$.sl_xuat;$item$$.tien_xuat=$item$$.tien_xuat_nt=$item$$.sl_xuat* ($item$$.gia_von_nt||0);$item$$.tien_hang=$item$$.tien_hang_nt=$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$$}),$detail$$.gia_mua=$detail$$.combo.map($c$$=>($c$$.gia_mua||0)*$c$$.sl_xuat_1_combo).reduce(($a$$,$b$$)=>$a$$+$b$$,0))});$data$$.pt_thanh_toan&&$data$$.pt_thanh_toan!=$obj$$.pt_thanh_toan&&($data$$.virtual_payment_client_url="",$data$$.payment_service= "",$data$$.payment_id="");$data$$.evouchers=$data$$.evouchers||$obj$$.evouchers||[];valid($user$$,$data$$,async $error$$=>{if($error$$)return $next$$($error$$);if(($obj$$.paymentByPoints||0)!==($data$$.paymentByPoints||0))return $next$$("B\u1ea1n kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt s\u1ed1 \u0111i\u1ec3m thanh to\u00e1n.");await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":buy"});$next$$(null,$data$$,$obj$$)},$obj$$)};$contr_router$$.updated=async function($amount$jscomp$6_evouchers_user$$, $obj$$,$next$$){if(!$obj$$.virtual_payment_client_url&&("1"===$obj$$.trang_thai||"0"===$obj$$.trang_thai||"LCT"===$obj$$.trang_thai)){if($obj$$.pt_thanh_toan&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan))tr