flexbiz-server 12.0.10 → 12.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/package.json +2 -1
  2. package/server/auths/facebook.js +10 -9
  3. package/server/auths/google.js +9 -8
  4. package/server/controllers/controller.js +79 -78
  5. package/server/global.js +2 -2
  6. package/server/libs/blockchainconnect.js +11 -10
  7. package/server/libs/ckvt.js +10 -9
  8. package/server/libs/ckvtcapphat.js +2 -2
  9. package/server/libs/ckvttt.js +5 -5
  10. package/server/libs/databanle.js +14 -14
  11. package/server/libs/dkvt.js +2 -2
  12. package/server/libs/dkvttt.js +3 -3
  13. package/server/libs/permission.js +12 -12
  14. package/server/libs/post-book.js +2 -2
  15. package/server/libs/thnxt.js +7 -7
  16. package/server/libs/thnxttt.js +7 -7
  17. package/server/libs/tinhgiatb.js +22 -19
  18. package/server/models/app.js +4 -4
  19. package/server/models/asskey.js +2 -2
  20. package/server/models/asssell.js +3 -3
  21. package/server/models/dmvt.js +5 -5
  22. package/server/models/hd2.js +5 -5
  23. package/server/models/listinfo.js +2 -2
  24. package/server/models/pbl.js +5 -5
  25. package/server/models/pn1.js +2 -2
  26. package/server/models/pn5.js +3 -3
  27. package/server/models/pn9.js +2 -2
  28. package/server/models/po1.js +1 -1
  29. package/server/models/so1.js +3 -3
  30. package/server/models/tontucthoi.js +3 -3
  31. package/server/models/transaction.js +3 -3
  32. package/server/models/user.js +7 -6
  33. package/server/modules/lists/ls-asskey.js +17 -14
  34. package/server/modules/lists/ls-asssell.js +13 -12
  35. package/server/modules/lists/ls-cart.js +12 -9
  36. package/server/modules/lists/ls-dmvt.js +32 -27
  37. package/server/modules/lists/ls-file.js +13 -13
  38. package/server/modules/lists/ls-participant.js +4 -4
  39. package/server/modules/public/file.js +10 -0
  40. package/server/modules/reports/rp-bkct.js +7 -7
  41. package/server/modules/reports/rp-ckvt.js +8 -4
  42. package/server/modules/reports/rp-dtbanletheovt.js +6 -6
  43. package/server/modules/reports/rp-thnxt.js +8 -7
  44. package/server/modules/reports/rp-tkbanhangtheogioithieu.js +6 -6
  45. package/server/modules/reports/rpt-tkdiemtichluy.js +2 -2
  46. package/server/modules/vouchers/vo-bn1.js +9 -7
  47. package/server/modules/vouchers/vo-hd2.js +7 -7
  48. package/server/modules/vouchers/vo-lenhsx.js +4 -4
  49. package/server/modules/vouchers/vo-pbl.js +26 -24
  50. package/server/modules/vouchers/vo-pc1.js +8 -6
  51. package/server/modules/vouchers/vo-so1.js +25 -22
  52. package/server/route.js +9 -9
@@ -44,30 +44,32 @@ $_opt_detail$jscomp$3_t_tien_evoucher_user$$.tien_hang-$_opt_detail$jscomp$3_t_t
44
44
  $obj$$)};
45
45
  module.exports=function($router$$){const $contr$$=new controller($router$$,model,ma_ct.toLowerCase(),{isVoucher:!0,sort:{ngay_ct:-1,so_ct:-1},users_receive_notification_default:[{send_tat_ca_nhan_vien:!0,send_admin:!0}]});$contr$$.route();$contr$$.post=async function($obj$$,$fn$$){$fn$$||($fn$$=function(){});await $obj$$.details.asyncJoinModel2($obj$$.id_app,dmvt,{where:"ma_vt",fields:["ma_thue","ten_vt","tk_vt","tg_tk"]});$obj$$.details.filter($d$$=>!$d$$.tg_tk).forEach($d$$=>{$d$$.tien_xuat=$d$$.tien_xuat_nt=
46
46
  0;$d$$.gia_von_nt=$d$$.gia_von=0});$obj$$.t_tien=$obj$$.details.csum("tien_hang");$obj$$.t_tien_nt=$obj$$.details.csum("tien_hang_nt");$obj$$.t_ck=$obj$$.details.csum("tien_ck")+$obj$$.tien_ck_hd+($obj$$.tien_evoucher||0);$obj$$.t_ck_nt=$obj$$.details.csum("tien_ck_nt")+$obj$$.tien_ck_hd+($obj$$.tien_evoucher||0);$obj$$.t_tt=$obj$$.t_tien-$obj$$.t_ck;$obj$$.t_tt_nt=$obj$$.t_tien_nt-$obj$$.t_ck_nt;$obj$$.con_no=$obj$$.t_tt_nt-($obj$$.tien_paymentByPoints||0)-($obj$$.tien_thu||0)-($obj$$.tien_thu2||
47
- 0);0>$obj$$.con_no&&($obj$$.con_no=0);async.parallel({post_sokho:function($callback$jscomp$1$$){let $details$$=[...$obj$$.details.map($d$$=>({...$d$$}))];$details$$.forEach($d$$=>{$d$$={...$d$$};$d$$.promotion&&$d$$.promotion.details_km&&$d$$.promotion.details_km.forEach($p$$=>{if($p$$.ma_vt&&$p$$.sl_km){let $_p$$={};underscore.extend($_p$$,$p$$,{sl_xuat:$p$$.sl_km});$details$$.push($_p$$)}})});$obj$$.promotion&&$obj$$.promotion.forEach($p$$=>{$p$$={...$p$$};if($p$$.ma_vt&&$p$$.sl_km){let $_p$$={};
48
- underscore.extend($_p$$,$p$$,{sl_xuat:$p$$.sl_km});$details$$.push($_p$$)}});$details$$.joinModel2($obj$$.id_app,dmvt,{where:"ma_vt",fields:["gia_mua","combo","tg_tk"]},()=>{let $data_post$$=$details$$.map($detail$$=>$detail$$.combo&&0<$detail$$.combo.length?$detail$$.combo.map($item$$=>{$item$$=$item$$.toObject?$item$$.toObject():{...$item$$};$item$$.sl_xuat*=$detail$$.sl_xuat;$item$$.tien_xuat=$item$$.tien_xuat_nt=$item$$.sl_xuat*$item$$.gia_von_nt;$item$$.tien_hang=$item$$.tien_hang_nt=$item$$.sl_xuat*
49
- $item$$.gia_ban_nt;$item$$.tien_ck=$item$$.tien_ck_nt*=$item$$.sl_xuat;$item$$.tien=$item$$.tien_nt=$item$$.tien_hang_nt-$item$$.tien_ck_nt;return $item$$}):[$detail$$]).reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]);async.parallel({tt:$callback$jscomp$0$$=>{(new PostBook($obj$$,$data_post$$,Sokho,async function($detail$$,$callback$$){$detail$$.nxt=2;$detail$$.ma_kho=$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$jscomp$0$$($e$$,$rs$$)})},kt:$callback$jscomp$0$$=>{(new PostBook($obj$$,
50
- $data_post$$,Sokhott,async function($detail$$,$callback$$){$detail$$.nxt=2;$detail$$.ma_kho=$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$jscomp$0$$($e$$,$rs$$)})},khongton:$callback$jscomp$0$$=>{(new PostBook($obj$$,$data_post$$,Sokhokhongton,async function($detail$$,$callback$$){$detail$$.nxt=2;$detail$$.ma_kho=$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$jscomp$0$$($e$$,$rs$$)})}},($e$$,$rs$$)=>{$callback$jscomp$1$$($e$$,$rs$$)})})},post_socai:function($callback$jscomp$0$$){options.findOne({id_app:$obj$$.id_app,
51
- id_func:ma_ct.toLowerCase()}).lean().exec(async($details$jscomp$1_error$$,$_opt$jscomp$1_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$)=>{let $option$$;$option$$=$_opt$jscomp$1_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$?$_opt$jscomp$1_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$.option||{}:{};$details$jscomp$1_error$$=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)&&
52
- ($pt$$=await ptthanhtoan.findOne({id_app:$obj$$.id_app,_id:$obj$$.pt_thanh_toan}).lean());$pt$$=$pt$$||{};$pt$$.tk_tien=$details$jscomp$1_error$$.tk_tien||$pt$$.tk_tien;$pt$$.tk_cn=$pt$$.tk_cn||$details$jscomp$1_error$$.tk_cn;$pt$$.tk_dt=$details$jscomp$1_error$$.tk_dt||$pt$$.tk_dt;$pt$$.tk_gv=$details$jscomp$1_error$$.tk_gv||$pt$$.tk_gv;$pt$$.tk_ck=$details$jscomp$1_error$$.tk_ck||$pt$$.tk_ck;$pt$$.ma_kh||($pt$$.ma_kh=$details$jscomp$1_error$$.ma_kh);$pt$$.ma_kh&&($pt$$.tk_tien=$pt$$.tk_cn);$option$$.tk_tien=
53
- $pt$$.tk_tien||$option$$.tk_tien||"1111";$option$$.tk_cn=$details$jscomp$1_error$$.tk_cn||$option$$.tk_cn||"131111";$option$$.tk_dt=$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$jscomp$1_error$$=[...$obj$$.details.map($d$$=>({...$d$$}))];let $details_ht$$=[];await $details$jscomp$1_error$$.asyncJoinModel2($obj$$.id_app,vat,{where:"ma_thue",fields:["thue_suat","tk_thue_co","tk_thue_co_treo"]});
54
- $details$jscomp$1_error$$.forEach($detail$$=>{$detail$$.ma_thue&&$detail$$.tk_thue_co_treo?($detail$$.tien_ct=$detail$$.tien/(1+$detail$$.thue_suat/100),$detail$$.tien_ct_nt=$detail$$.tien_nt/(1+$detail$$.thue_suat/100),$detail$$.gia_ban_ct=Math.round($detail$$.tien_ct/($detail$$.sl_xuat||1)),$detail$$.gia_ban_ct_nt=Math.round($detail$$.tien_ct_nt/($detail$$.sl_xuat||1)),$detail$$.tien_ct=$detail$$.sl_xuat*$detail$$.gia_ban_ct,$detail$$.tien_ct_nt=$detail$$.sl_xuat*$detail$$.gia_ban_ct_nt,$detail$$.tien_thue=
55
- Math.round($detail$$.tien_ct*$detail$$.thue_suat/100),$detail$$.tien_thue_nt=Math.round($detail$$.tien_ct_nt*$detail$$.thue_suat/100)):($detail$$.tien_ck_ct_nt=$detail$$.tien_ck_nt,$detail$$.tien_ck_ct=$detail$$.tien_ck,$detail$$.tien_thue=0,$detail$$.tien_thue_nt=0,$detail$$.tien_ct=$detail$$.tien,$detail$$.tien_ct_nt=$detail$$.tien_nt)});$details$jscomp$1_error$$.forEach($detail$$=>{$detail$$={...$detail$$};$detail$$.tk_no=$option$$.tk_tien;$detail$$.tk_co=$option$$.tk_dt;$detail$$.ma_kh||($detail$$.ma_kh=
56
- $pt$$.ma_kh||$obj$$.ma_kh);$detail$$.tien_nt=$detail$$.tien_ct_nt;$detail$$.tien=$detail$$.tien_ct;$detail$$.flag="DT_"+($detail$$.ma_vt||"");$details_ht$$.push($detail$$)});$details$jscomp$1_error$$.filter($d$$=>$d$$.tien_thue).forEach($detail$$=>{$detail$$={...$detail$$};$detail$$.tk_no=$option$$.tk_tien;$detail$$.tk_co=$detail$$.tk_thue_co_treo;$detail$$.ma_kh||($detail$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh);$detail$$.tien_nt=$detail$$.tien_thue_nt;$detail$$.tien=$detail$$.tien_thue;$detail$$.flag=
57
- "THUE_"+($detail$$.ma_vt||"");$details_ht$$.push($detail$$)});$_opt$jscomp$1_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$=$obj$$.tien_evoucher||0;if($obj$$.tien_ck_hd||$_opt$jscomp$1_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$){var $tt_tt$$={};$tt_tt$$.tk_no=$option$$.tk_ck;$tt_tt$$.tk_co=$option$$.tk_tien;$tt_tt$$.tien_nt=($obj$$.tien_ck_hd||0)+$_opt$jscomp$1_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$;$tt_tt$$.tien=$tt_tt$$.tien_nt;$tt_tt$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh;
58
- $tt_tt$$.check_balance=!1;$details_ht$$.push($tt_tt$$)}$obj$$.con_no&&($_opt$jscomp$1_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$={},$_opt$jscomp$1_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$.tk_no=$option$$.tk_cn,$_opt$jscomp$1_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$.tk_co=$option$$.tk_tien,$_opt$jscomp$1_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$.tien_nt=$obj$$.con_no,$_opt$jscomp$1_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$.tien=$obj$$.con_no,$_opt$jscomp$1_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$.ma_kh=
59
- $obj$$.ma_kh,$details_ht$$.push($_opt$jscomp$1_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$));$obj$$.tien_thu&&$pt$$.tk_cn&&$pt$$.tk_cn!==$option$$.tk_tien&&($_opt$jscomp$1_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$={},$_opt$jscomp$1_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$.tk_no=$pt$$.tk_cn,$_opt$jscomp$1_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$.tk_co=$option$$.tk_tien,$_opt$jscomp$1_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$.tien_nt=$obj$$.tien_thu,
60
- $_opt$jscomp$1_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$.tien=$obj$$.tien_thu,$_opt$jscomp$1_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh,$details_ht$$.push($_opt$jscomp$1_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$));$obj$$.tien_thu2&&($_opt$jscomp$1_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$=($obj$$.pt_thanh_toan2&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan2)?await ptthanhtoan.findOne({_id:$obj$$.pt_thanh_toan2}).lean():
61
- null)||$pt$$,$_opt$jscomp$1_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$.tk_cn&&$_opt$jscomp$1_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$.ma_kh!==$pt$$.ma_kh&&($tt_tt$$={},$tt_tt$$.tk_no=$_opt$jscomp$1_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$.tk_cn,$tt_tt$$.tk_co=$option$$.tk_tien,$tt_tt$$.tien_nt=$obj$$.tien_thu2,$tt_tt$$.tien=$obj$$.tien_thu2,$tt_tt$$.ma_kh_no=$_opt$jscomp$1_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$.ma_kh,$tt_tt$$.ma_kh_co=$pt$$.ma_kh,$details_ht$$.push($tt_tt$$)));
62
- let $details_tienvon$$=[];$details$jscomp$1_error$$.forEach(function($detail$jscomp$0$$){$detail$jscomp$0$$={...$detail$jscomp$0$$};$detail$jscomp$0$$.tk_no=$option$$.tk_gv;$detail$jscomp$0$$.ma_kh||($detail$jscomp$0$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh);$detail$jscomp$0$$.tk_co=$detail$jscomp$0$$.tk_vt;$detail$jscomp$0$$.tien_nt=$detail$jscomp$0$$.tien_xuat_nt;$detail$jscomp$0$$.tien=$detail$jscomp$0$$.tien_xuat;$details_tienvon$$.push($detail$jscomp$0$$);$detail$jscomp$0$$.promotion&&$detail$jscomp$0$$.promotion.details_km&&
63
- $detail$jscomp$0$$.promotion.details_km.forEach($detail$$=>{$detail$$.ma_vt&&($detail$$.tk_no=$option$$.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||0,$detail$$.tien=$detail$$.tien_xuat||0,$details_tienvon$$.push($detail$$))})});$obj$$.promotion&&$obj$$.promotion.forEach(function($detail$$){$detail$$={...$detail$$};$detail$$.ma_vt&&($detail$$.tk_no=$option$$.tk_gv,$detail$$.ma_kh||($detail$$.ma_kh=$pt$$.ma_kh||
64
- $obj$$.ma_kh),$detail$$.tk_co=$detail$$.tk_vt,$detail$$.tien_nt=$detail$$.tien_xuat_nt||0,$detail$$.tien=$detail$$.tien_xuat||0,$details_tienvon$$.push($detail$$))});async.parallel({xdtk:$callback$$=>{$details_tienvon$$.joinModel2($obj$$.id_app,dmvt,{where:"ma_vt",fields:["tk_vt","gia_mua","tk_gv","tg_tk"]},()=>{$details_tienvon$$.forEach($s$$=>{$s$$.tg_tk||($s$$.tien=$s$$.tien_nt=0);$s$$.tk_co||($s$$.tk_co=$s$$.tk_vt);$s$$.tk_no||($s$$.tk_no=$s$$.tk_gv)});$callback$$()})}},()=>{$details_ht$$=$details_ht$$.concat($details_tienvon$$);
65
- $details_ht$$.forEach($d$$=>{$d$$.ma_kho=$obj$$.ma_kho});(new PostSocai($obj$$,$details_ht$$)).run(function($e$$,$rs$$){$callback$jscomp$0$$($e$$,$rs$$)})})})}},function($e$$,$rs$$){$fn$$($e$$,$rs$$)})};$contr$$.saving=async($user$$,$obj$$)=>{await chietkhauhd($obj$$);await khuyenmaihd($obj$$)};$contr$$.creating=async function($user$$,$obj$$,$next$$){$obj$$.details||($obj$$.details=[]);$obj$$.tien_thu=Math.round($obj$$.tien_thu||0);$obj$$.tien_thu2=Math.round($obj$$.tien_thu2||0);valid($user$$,$obj$$,
66
- 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.");$next$$(null,$obj$$)}catch($e$$){$next$$($e$$.message)}})};$contr$$.created=async function($user$$,$obj$$,$next$$){await createTransactionPayment($obj$$);await createTransactionBonus($obj$$);
67
- $obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>updateEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));"5"==$obj$$.trang_thai&&($obj$$.trang_thai="6",await model.findOneAndUpdate({_id:$obj$$._id},{trang_thai:"6"}));$next$$(null,$obj$$)};$contr$$.updating=function($user$$,$data$$,$obj$$,$next$$){$data$$.details||($data$$.details=$obj$$.details||[]);$data$$.evouchers||($data$$.evouchers=$obj$$.evouchers||[]);$data$$.tien_thu=void 0==$data$$.tien_thu?$obj$$.tien_thu:$data$$.tien_thu;$data$$.tien_thu2=
68
- void 0==$data$$.tien_thu2?$obj$$.tien_thu2:$data$$.tien_thu2;$data$$.tien_thu=Math.round($data$$.tien_thu||0);$data$$.tien_thu2=Math.round($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(void 0==$d$$.sl_order||null==$d$$.sl_order)$d$$.sl_order=$_d$$.sl_order;if(void 0==$d$$.sl_xuat||null==$d$$.sl_xuat)$d$$.sl_xuat=
69
- $_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):$d$$.finish_time=null;let $trang_thai$$=$data$$.trang_thai||$obj$$.trang_thai;$d$$.finish_time||"5"!==$trang_thai$$&&"6"!==$trang_thai$$&&"9"!==$trang_thai$$||($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||
70
- 0)!==($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&&$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$$){"9"===$obj$$.trang_thai?(await transaction.deleteTrans({id_ct:$obj$$._id.toString()}),
47
+ 0);0>$obj$$.con_no&&($obj$$.con_no=0);let $product_details$$=[...$obj$$.details.map($d$$=>({...$d$$}))];$product_details$$.forEach($d$$=>{$d$$={...$d$$};$d$$.promotion&&$d$$.promotion.details_km&&$d$$.promotion.details_km.forEach($p$$=>{if($p$$.ma_vt&&$p$$.sl_km){let $_p$$={};underscore.extend($_p$$,$p$$,{sl_xuat:$p$$.sl_km});$product_details$$.push($_p$$)}});$d$$.combo&&0<$d$$.combo.length&&($product_details$$=[...$product_details$$,...$d$$.combo])});$obj$$.promotion&&$obj$$.promotion.forEach($p$$=>
48
+ {$p$$={...$p$$};if($p$$.ma_vt&&$p$$.sl_km){let $_p$$={};underscore.extend($_p$$,$p$$,{sl_xuat:$p$$.sl_km});$product_details$$.push($_p$$)}});$product_details$$=$product_details$$.filter($d$$=>!$d$$.combo||0===$d$$.combo.length);async.parallel({post_sokho:function($callback$jscomp$1$$){async.parallel({tt:$callback$jscomp$0$$=>{(new PostBook($obj$$,$product_details$$,Sokho,async function($detail$$,$callback$$){$detail$$.nxt=2;$detail$$.ma_kho=$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,
49
+ $rs$$){$callback$jscomp$0$$($e$$,$rs$$)})},kt:$callback$jscomp$0$$=>{(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$jscomp$0$$($e$$,$rs$$)})},khongton:$callback$jscomp$0$$=>{(new PostBook($obj$$,$product_details$$,Sokhokhongton,async function($detail$$,$callback$$){$detail$$.nxt=2;$detail$$.ma_kho=$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,
50
+ $rs$$){$callback$jscomp$0$$($e$$,$rs$$)})}},($e$$,$rs$$)=>{$callback$jscomp$1$$($e$$,$rs$$)})},post_socai:function($callback$jscomp$0$$){options.findOne({id_app:$obj$$.id_app,id_func:ma_ct.toLowerCase()}).lean().exec(async($details_error$jscomp$1_kho_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$,$_opt$jscomp$1_tt_tt$$)=>{let $option$$;$option$$=$_opt$jscomp$1_tt_tt$$?$_opt$jscomp$1_tt_tt$$.option||{}:{};$details_error$jscomp$1_kho_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$=await dmkho.findOne({id_app:$obj$$.id_app,
51
+ ma_kho:$obj$$.ma_kho}).lean()||{};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=$details_error$jscomp$1_kho_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$.tk_tien||$pt$$.tk_tien;$pt$$.tk_cn=$pt$$.tk_cn||$details_error$jscomp$1_kho_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$.tk_cn;$pt$$.tk_dt=$details_error$jscomp$1_kho_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$.tk_dt||
52
+ $pt$$.tk_dt;$pt$$.tk_gv=$details_error$jscomp$1_kho_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$.tk_gv||$pt$$.tk_gv;$pt$$.tk_ck=$details_error$jscomp$1_kho_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$.tk_ck||$pt$$.tk_ck;$pt$$.ma_kh||($pt$$.ma_kh=$details_error$jscomp$1_kho_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_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$1_kho_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$.tk_cn||
53
+ $option$$.tk_cn||"131111";$option$$.tk_dt=$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$1_kho_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$=[...$obj$$.details.map($d$$=>({...$d$$}))];let $details_ht$$=[];await $details_error$jscomp$1_kho_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$.asyncJoinModel2($obj$$.id_app,vat,{where:"ma_thue",fields:["thue_suat","tk_thue_co",
54
+ "tk_thue_co_treo"]});$details_error$jscomp$1_kho_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$.forEach($detail$$=>{$detail$$.ma_thue&&$detail$$.tk_thue_co_treo?($detail$$.tien_ct=$detail$$.tien/(1+$detail$$.thue_suat/100),$detail$$.tien_ct_nt=$detail$$.tien_nt/(1+$detail$$.thue_suat/100),$detail$$.gia_ban_ct=Math.round($detail$$.tien_ct/($detail$$.sl_xuat||1)),$detail$$.gia_ban_ct_nt=Math.round($detail$$.tien_ct_nt/($detail$$.sl_xuat||1)),$detail$$.tien_ct=$detail$$.sl_xuat*$detail$$.gia_ban_ct,
55
+ $detail$$.tien_ct_nt=$detail$$.sl_xuat*$detail$$.gia_ban_ct_nt,$detail$$.tien_thue=Math.round($detail$$.tien_ct*$detail$$.thue_suat/100),$detail$$.tien_thue_nt=Math.round($detail$$.tien_ct_nt*$detail$$.thue_suat/100)):($detail$$.tien_ck_ct_nt=$detail$$.tien_ck_nt,$detail$$.tien_ck_ct=$detail$$.tien_ck,$detail$$.tien_thue=0,$detail$$.tien_thue_nt=0,$detail$$.tien_ct=$detail$$.tien,$detail$$.tien_ct_nt=$detail$$.tien_nt)});$details_error$jscomp$1_kho_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$.forEach($detail$$=>
56
+ {$detail$$={...$detail$$};$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=$detail$$.tien_ct_nt;$detail$$.tien=$detail$$.tien_ct;$detail$$.flag="DT_"+($detail$$.ma_vt||"");$details_ht$$.push($detail$$)});$details_error$jscomp$1_kho_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$.filter($d$$=>$d$$.tien_thue).forEach($detail$$=>{$detail$$={...$detail$$};$detail$$.tk_no=$option$$.tk_tien;$detail$$.tk_co=
57
+ $detail$$.tk_thue_co_treo;$detail$$.ma_kh||($detail$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh);$detail$$.tien_nt=$detail$$.tien_thue_nt;$detail$$.tien=$detail$$.tien_thue;$detail$$.flag="THUE_"+($detail$$.ma_vt||"");$details_ht$$.push($detail$$)});$details_error$jscomp$1_kho_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$=$obj$$.tien_evoucher||0;if($obj$$.tien_ck_hd||$details_error$jscomp$1_kho_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$)$_opt$jscomp$1_tt_tt$$={},$_opt$jscomp$1_tt_tt$$.tk_no=
58
+ $option$$.tk_ck,$_opt$jscomp$1_tt_tt$$.tk_co=$option$$.tk_tien,$_opt$jscomp$1_tt_tt$$.tien_nt=($obj$$.tien_ck_hd||0)+$details_error$jscomp$1_kho_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$,$_opt$jscomp$1_tt_tt$$.tien=$_opt$jscomp$1_tt_tt$$.tien_nt,$_opt$jscomp$1_tt_tt$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh,$_opt$jscomp$1_tt_tt$$.check_balance=!1,$details_ht$$.push($_opt$jscomp$1_tt_tt$$);$obj$$.con_no&&($details_error$jscomp$1_kho_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$={},$details_error$jscomp$1_kho_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$.tk_no=
59
+ $option$$.tk_cn,$details_error$jscomp$1_kho_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$.tk_co=$option$$.tk_tien,$details_error$jscomp$1_kho_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$.tien_nt=$obj$$.con_no,$details_error$jscomp$1_kho_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$.tien=$obj$$.con_no,$details_error$jscomp$1_kho_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$.ma_kh=$obj$$.ma_kh,$details_ht$$.push($details_error$jscomp$1_kho_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$));
60
+ $obj$$.tien_thu&&$pt$$.tk_cn&&$pt$$.tk_cn!==$option$$.tk_tien&&($details_error$jscomp$1_kho_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$={},$details_error$jscomp$1_kho_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$.tk_no=$pt$$.tk_cn,$details_error$jscomp$1_kho_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$.tk_co=$option$$.tk_tien,$details_error$jscomp$1_kho_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$.tien_nt=$obj$$.tien_thu,$details_error$jscomp$1_kho_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$.tien=
61
+ $obj$$.tien_thu,$details_error$jscomp$1_kho_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh,$details_ht$$.push($details_error$jscomp$1_kho_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$));$obj$$.tien_thu2&&($details_error$jscomp$1_kho_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$=($obj$$.pt_thanh_toan2&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan2)?await ptthanhtoan.findOne({_id:$obj$$.pt_thanh_toan2}).lean():null)||$pt$$,$details_error$jscomp$1_kho_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$.tk_cn&&
62
+ $details_error$jscomp$1_kho_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$.ma_kh!==$pt$$.ma_kh&&($_opt$jscomp$1_tt_tt$$={},$_opt$jscomp$1_tt_tt$$.tk_no=$details_error$jscomp$1_kho_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$.tk_cn,$_opt$jscomp$1_tt_tt$$.tk_co=$option$$.tk_tien,$_opt$jscomp$1_tt_tt$$.tien_nt=$obj$$.tien_thu2,$_opt$jscomp$1_tt_tt$$.tien=$obj$$.tien_thu2,$_opt$jscomp$1_tt_tt$$.ma_kh_no=$details_error$jscomp$1_kho_pt2_tien_evoucher_con_lai$jscomp$1_tt$jscomp$1_tt$$.ma_kh,
63
+ $_opt$jscomp$1_tt_tt$$.ma_kh_co=$pt$$.ma_kh,$details_ht$$.push($_opt$jscomp$1_tt_tt$$)));let $details_tienvon$$=[];$product_details$$.forEach(function($detail$$){$detail$$={...$detail$$};$detail$$.tk_no=$option$$.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;$details_tienvon$$.push($detail$$)});async.parallel({xdtk:$callback$$=>{$details_tienvon$$.joinModel2($obj$$.id_app,
64
+ dmvt,{where:"ma_vt",fields:["tk_vt","gia_mua","tk_gv","tg_tk"]},()=>{$details_tienvon$$.forEach($s$$=>{$s$$.tg_tk||($s$$.tien=$s$$.tien_nt=0);$s$$.tk_co||($s$$.tk_co=$s$$.tk_vt);$s$$.tk_no||($s$$.tk_no=$s$$.tk_gv)});$callback$$()})}},()=>{$details_ht$$=$details_ht$$.concat($details_tienvon$$);$details_ht$$.forEach($d$$=>{$d$$.ma_kho=$obj$$.ma_kho});(new PostSocai($obj$$,$details_ht$$)).run(function($e$$,$rs$$){$callback$jscomp$0$$($e$$,$rs$$)})})})}},function($e$$,$rs$$){$fn$$($e$$,$rs$$)})};$contr$$.saving=
65
+ async($user$$,$obj$$)=>{await chietkhauhd($obj$$);await khuyenmaihd($obj$$)};$contr$$.creating=async function($user$$,$obj$$,$next$$){$obj$$.details||($obj$$.details=[]);await $obj$$.details.asyncJoinModel2($user$$.current_id_app,dmvt,{where:"ma_vt",fields:["combo"]});$obj$$.details.forEach($detail$$=>{$detail$$.combo&&0<$detail$$.combo.length&&($detail$$.combo=$detail$$.combo.map($item$$=>{$item$$=$item$$.toObject?$item$$.toObject():{...$item$$};$item$$.sl_xuat*=$detail$$.sl_xuat;$item$$.tien_xuat=
66
+ $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$$}))});$obj$$.tien_thu=Math.round($obj$$.tien_thu||0);$obj$$.tien_thu2=Math.round($obj$$.tien_thu2||0);valid($user$$,$obj$$,async $error$$=>{if($error$$)return $next$$($error$$);if(!$obj$$.paymentByPoints)return $next$$(null,
67
+ $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.");$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,
68
+ $e$$.ma,$obj$$._id)));"5"==$obj$$.trang_thai&&($obj$$.trang_thai="6",await model.findOneAndUpdate({_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",fields:["combo"]});$data$$.details.forEach($detail$$=>{$detail$$.combo&&0<$detail$$.combo.length&&
69
+ ($detail$$.combo=$detail$$.combo.map($item$$=>{$item$$=$item$$.toObject?$item$$.toObject():{...$item$$};$item$$.sl_xuat*=$detail$$.sl_xuat;$item$$.tien_xuat=$item$$.tien_xuat_nt=$item$$.sl_xuat*($item$$.gia_von_nt||0);$item$$.tien_hang=$item$$.tien_hang_nt=$item$$.sl_xuat*($item$$.gia_ban_nt||0);$item$$.tien_ck=$item$$.tien_ck_nt=$item$$.sl_xuat*($item$$.tien_ck_nt||0);$item$$.tien=$item$$.tien_nt=$item$$.tien_hang_nt-($item$$.tien_ck_nt||0);return $item$$}))});$data$$.tien_thu=void 0==$data$$.tien_thu?
70
+ $obj$$.tien_thu:$data$$.tien_thu;$data$$.tien_thu2=void 0==$data$$.tien_thu2?$obj$$.tien_thu2:$data$$.tien_thu2;$data$$.tien_thu=Math.round($data$$.tien_thu||0);$data$$.tien_thu2=Math.round($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(void 0==$d$$.sl_order||null==$d$$.sl_order)$d$$.sl_order=$_d$$.sl_order;if(void 0==
71
+ $d$$.sl_xuat||null==$d$$.sl_xuat)$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):$d$$.finish_time=null;let $trang_thai$$=$data$$.trang_thai||$obj$$.trang_thai;$d$$.finish_time||"5"!==$trang_thai$$&&"6"!==$trang_thai$$&&"9"!==$trang_thai$$||($d$$.finish_time=new Date);$_d$$.het_hang&&($d$$.het_hang=!0)}})});valid($user$$,$data$$,function($error$$){if($error$$)return $next$$($error$$);
72
+ 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.");$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$$){"9"===$obj$$.trang_thai?(await transaction.deleteTrans({id_ct:$obj$$._id.toString()}),
71
73
  await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng")):createTransactionBonus($obj$$);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)));$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>updateEvoucher($e$$.id_app,$e$$.ma,
72
74
  $obj$$._id)));"5"==$obj$$.trang_thai&&($obj$$.trang_thai="6",await model.findOneAndUpdate({_id:$obj$$._id},{trang_thai:"6"}));$next$$(null,$obj$$)};$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$$=>
73
75
  deleteEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$callback$$(null,$obj$$)};$contr$$.find=function($user$$,$condition$$,$next$$){$next$$(null,$condition$$)};$contr$$.view=function($user$$,$items$$,$fn$$){let $id_app$$=$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({dv:function($callback$$){$items$$.filter($item$$=>$item$$.ma_dvcs).joinModel2($id_app$$,
@@ -6,12 +6,14 @@ module.exports=function($contr_router$$){$contr_router$$=new controller($contr_r
6
6
  $rs$$){$callback$$($e$$,$rs$$)})},post_tdttco:function($callback$jscomp$0$$){(new PostBook($obj$$,$obj$$.tdttcos,Tdttco_tt,function($tdttco$$,$callback$$){$tdttco$$.tk_co=$obj$$.tk_co;$callback$$($tdttco$$)})).run(function($e$jscomp$0$$,$details$$){if($e$jscomp$0$$)return $callback$jscomp$0$$($e$jscomp$0$$);async.map($details$$,($detail$$,$callback$$)=>{$detail$$.con_lai_nt<=$detail$$.thanh_toan_qd?Tdttco.findOneAndUpdate({_id:$detail$$.id_tdtt.toString()},{$set:{tat_toan:!0}},function($error$$,$result$$){$callback$$($error$$,
7
7
  $result$$)}):$callback$$(null,$detail$$)},function($e$$,$rs$$){$callback$jscomp$0$$($e$$,$rs$$)})})},post_socai:function($callback$$){const $details_sc$$=[];$obj$$.vatvaos.forEach(function($v_vatvao$$){$v_vatvao$$={...$v_vatvao$$};$v_vatvao$$.tk_no=$v_vatvao$$.tk_thue_no;$v_vatvao$$.tk_co=$v_vatvao$$.tk_du_thue;$v_vatvao$$.tien_nt=$v_vatvao$$.t_thue_nt;$v_vatvao$$.tien=$v_vatvao$$.t_thue;$details_sc$$.push($v_vatvao$$)});$obj$$.details.forEach(function($d_detail$$){$d_detail$$={...$d_detail$$};$d_detail$$.tk_co=
8
8
  $obj$$.tk_co;$d_detail$$.ma_kh||($d_detail$$.ma_kh=$obj$$.ma_kh);$details_sc$$.push($d_detail$$)});$obj$$.tdttcos.forEach(function($t_tdttco$$){$t_tdttco$$={...$t_tdttco$$};$t_tdttco$$.tk_co=$obj$$.tk_co;$t_tdttco$$.ma_kh||($t_tdttco$$.ma_kh=$obj$$.ma_kh);$details_sc$$.push($t_tdttco$$)});(new PostSocai($obj$$,$details_sc$$)).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})}},function($e$$,$rs$$){$fn$$($e$$,$rs$$)})};$contr_router$$.creating=async function($user$$,$obj$$,$next$$){if($user$$.current_app_info.options.phieu_chi_phai_co_phieu_de_nghi&&
9
- !$obj$$.id_pc0&&!$obj$$.id_pn6)return $next$$("Ch\u01b0a c\u00f3 phi\u1ebfu \u0111\u1ec1 ngh\u1ecb thanh to\u00e1n");$obj$$.details||($obj$$.details=[]);if($obj$$.id_pc0&&global.mongoose.Types.ObjectId.isValid($obj$$.id_pc0)){var $dntt_t_tien_dn$$=await pc0.findOne({_id:$obj$$.id_pc0,id_app:$user$$.current_id_app});if(!$dntt_t_tien_dn$$)return $next$$("\u0110\u1ec1 ngh\u1ecb thanh to\u00e1n kh\u00f4ng t\u1ed3n t\u1ea1i");$dntt_t_tien_dn$$=($dntt_t_tien_dn$$.details||[]).map($d$$=>$d$$.tien_nt||0)+
10
- ($dntt_t_tien_dn$$.tdttcos||[]).map($d$$=>$d$$.tien_nt||0)+($dntt_t_tien_dn$$.vatvaos||[]).map($d$$=>$d$$.t_thue_nt||0);let $t_tien_tt$$=($obj$$.details||[]).map($d$$=>$d$$.tien_nt||0)+($obj$$.tdttcos||[]).map($d$$=>$d$$.tien_nt||0)+($obj$$.vatvaos||[]).map($d$$=>$d$$.t_thue_nt||0);if($dntt_t_tien_dn$$!==$t_tien_tt$$)return $next$$("T\u1ed5ng s\u1ed1 ti\u1ec1n thanh to\u00e1n ph\u1ea3i b\u1eb1ng v\u1edbi s\u1ed1 ti\u1ec1n trong \u0111\u1ec1 ngh\u1ecb thanh to\u00e1n \u0111\u00e3 \u0111\u01b0\u1ee3c duy\u1ec7t")}if($obj$$.tdttcos&&
11
- 0<$obj$$.tdttcos.length&&(await $obj$$.tdttcos.asyncJoinModel2($user$$.current_id_app,Tdttco,{where:{id_tdtt:"_id"},fields:["tat_toan",{tien_hd_nt:"tien_nt"}]}),0<(await Promise.all($obj$$.tdttcos.map($hd$$=>(async()=>{if(!global.mongoose.Types.ObjectId.isValid($hd$$.id_tdtt))return{error:"Ho\u00e1 \u0111\u01a1n kh\u00f4ng h\u1ee3p l\u1ec7",invoice:$hd$$};let $ds_da_thanh_toan$$=await Tdttco_tt.find({id_app:$obj$$.id_app,id_tdtt:$hd$$.id_tdtt}).lean(),$da_thanh_toan$$=$ds_da_thanh_toan$$.map($t$$=>
12
- $t$$.thanh_toan_qd||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0),$con_lai$$=$hd$$.tien_hd_nt-$da_thanh_toan$$;return $con_lai$$<$hd$$.thanh_toan_qd?{error:"S\u1ed1 ti\u1ec1n c\u00f2n l\u1ea1i nh\u1ecf h\u01a1n s\u1ed1 ti\u1ec1n thanh to\u00e1n",invoice:$hd$$,da_thanh_toan:$da_thanh_toan$$,con_lai:$con_lai$$,ds_da_thanh_toan:$ds_da_thanh_toan$$}:{invoice:$hd$$,da_thanh_toan:$da_thanh_toan$$,con_lai:$con_lai$$,ds_da_thanh_toan:$ds_da_thanh_toan$$}})()))).filter($hd$$=>$hd$$.error).length))return $next$$("S\u1ed1 ti\u1ec1n thanh to\u00e1n kh\u00f4ng \u0111\u01b0\u1ee3c l\u1edbn h\u01a1n s\u1ed1 ti\u1ec1n c\u00f2n l\u1ea1i c\u1ee7a ho\u00e1 \u0111\u01a1n");
13
- valid_detail($user$$,$obj$$,function($error$$){if($error$$)return $next$$($error$$);$next$$(null,$obj$$)})};$contr_router$$.updating=async function($user$$,$data$$,$obj$$,$next$$){if($data$$.id_pc0||$obj$$.id_pc0){var $dntt$jscomp$1_t_tien_dn$$=await pc0.findOne({_id:$data$$.id_pc0||$obj$$.id_pc0,id_app:$user$$.current_id_app});if(!$dntt$jscomp$1_t_tien_dn$$)return $next$$("\u0110\u1ec1 ngh\u1ecb thanh to\u00e1n kh\u00f4ng t\u1ed3n t\u1ea1i");$dntt$jscomp$1_t_tien_dn$$=($dntt$jscomp$1_t_tien_dn$$.details||
14
- []).map($d$$=>$d$$.tien_nt||0)+($dntt$jscomp$1_t_tien_dn$$.tdttcos||[]).map($d$$=>$d$$.tien_nt||0)+($dntt$jscomp$1_t_tien_dn$$.vatvaos||[]).map($d$$=>$d$$.t_thue_nt||0);let $t_tien_tt$$=($data$$.details||$obj$$.details||[]).map($d$$=>$d$$.tien_nt||0)+($data$$.tdttcos||$obj$$.tdttcos||[]).map($d$$=>$d$$.tien_nt||0)+($data$$.vatvaos||$obj$$.vatvaos||[]).map($d$$=>$d$$.t_thue_nt||0);if($dntt$jscomp$1_t_tien_dn$$!==$t_tien_tt$$)return $next$$("T\u1ed5ng s\u1ed1 ti\u1ec1n thanh to\u00e1n ph\u1ea3i b\u1eb1ng v\u1edbi s\u1ed1 ti\u1ec1n trong \u0111\u1ec1 ngh\u1ecb thanh to\u00e1n \u0111\u00e3 \u0111\u01b0\u1ee3c duy\u1ec7t")}if($obj$$.tdttcos&&
9
+ !$obj$$.id_pc0&&!$obj$$.id_pn6)return $next$$("Ch\u01b0a c\u00f3 phi\u1ebfu \u0111\u1ec1 ngh\u1ecb thanh to\u00e1n");$obj$$.details||($obj$$.details=[]);if($obj$$.id_pc0&&global.mongoose.Types.ObjectId.isValid($obj$$.id_pc0)){if(await model.findOne({id_pc0:$obj$$.id_pc0}))return $next$$("\u0110\u1ec1 ngh\u1ecb thanh to\u00e1n n\u00e0y \u0111\u00e3 \u0111\u01b0\u1ee3c chi");var $dntt_t_tien_dn$$=await pc0.findOne({_id:$obj$$.id_pc0,id_app:$user$$.current_id_app});if(!$dntt_t_tien_dn$$)return $next$$("\u0110\u1ec1 ngh\u1ecb thanh to\u00e1n kh\u00f4ng t\u1ed3n t\u1ea1i");
10
+ $dntt_t_tien_dn$$=($dntt_t_tien_dn$$.details||[]).map($d$$=>$d$$.tien_nt||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0)+($dntt_t_tien_dn$$.tdttcos||[]).map($d$$=>$d$$.tien_nt||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0)+($dntt_t_tien_dn$$.vatvaos||[]).map($d$$=>$d$$.t_thue_nt||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);let $t_tien_tt$$=($obj$$.details||[]).map($d$$=>$d$$.tien_nt||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0)+($obj$$.tdttcos||[]).map($d$$=>$d$$.tien_nt||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0)+($obj$$.vatvaos||[]).map($d$$=>
11
+ $d$$.t_thue_nt||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);if($dntt_t_tien_dn$$!==$t_tien_tt$$)return $next$$("T\u1ed5ng s\u1ed1 ti\u1ec1n thanh to\u00e1n ph\u1ea3i b\u1eb1ng v\u1edbi s\u1ed1 ti\u1ec1n trong \u0111\u1ec1 ngh\u1ecb thanh to\u00e1n \u0111\u00e3 \u0111\u01b0\u1ee3c duy\u1ec7t")}if($obj$$.tdttcos&&0<$obj$$.tdttcos.length&&(await $obj$$.tdttcos.asyncJoinModel2($user$$.current_id_app,Tdttco,{where:{id_tdtt:"_id"},fields:["tat_toan",{tien_hd_nt:"tien_nt"}]}),0<(await Promise.all($obj$$.tdttcos.map($hd$$=>
12
+ (async()=>{if(!global.mongoose.Types.ObjectId.isValid($hd$$.id_tdtt))return{error:"Ho\u00e1 \u0111\u01a1n kh\u00f4ng h\u1ee3p l\u1ec7",invoice:$hd$$};let $ds_da_thanh_toan$$=await Tdttco_tt.find({id_app:$obj$$.id_app,id_tdtt:$hd$$.id_tdtt}).lean(),$da_thanh_toan$$=$ds_da_thanh_toan$$.map($t$$=>$t$$.thanh_toan_qd||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0),$con_lai$$=$hd$$.tien_hd_nt-$da_thanh_toan$$;return $con_lai$$<$hd$$.thanh_toan_qd?{error:"S\u1ed1 ti\u1ec1n c\u00f2n l\u1ea1i nh\u1ecf h\u01a1n s\u1ed1 ti\u1ec1n thanh to\u00e1n",
13
+ invoice:$hd$$,da_thanh_toan:$da_thanh_toan$$,con_lai:$con_lai$$,ds_da_thanh_toan:$ds_da_thanh_toan$$}:{invoice:$hd$$,da_thanh_toan:$da_thanh_toan$$,con_lai:$con_lai$$,ds_da_thanh_toan:$ds_da_thanh_toan$$}})()))).filter($hd$$=>$hd$$.error).length))return $next$$("S\u1ed1 ti\u1ec1n thanh to\u00e1n kh\u00f4ng \u0111\u01b0\u1ee3c l\u1edbn h\u01a1n s\u1ed1 ti\u1ec1n c\u00f2n l\u1ea1i c\u1ee7a ho\u00e1 \u0111\u01a1n");valid_detail($user$$,$obj$$,function($error$$){if($error$$)return $next$$($error$$);$next$$(null,
14
+ $obj$$)})};$contr_router$$.updating=async function($user$$,$data$$,$obj$$,$next$$){if($data$$.id_pc0||$obj$$.id_pc0){var $dntt$jscomp$1_id_pc0_t_tien_dn$$=$data$$.id_pc0||$obj$$.id_pc0,$ex$jscomp$1_t_tien_tt$$=await model.findOne({id_pc0:$dntt$jscomp$1_id_pc0_t_tien_dn$$}).lean();if($ex$jscomp$1_t_tien_tt$$&&$ex$jscomp$1_t_tien_tt$$._id.toString()!==$obj$$._id.toString())return $next$$("\u0110\u1ec1 ngh\u1ecb thanh to\u00e1n n\u00e0y \u0111\u00e3 \u0111\u01b0\u1ee3c chi");$dntt$jscomp$1_id_pc0_t_tien_dn$$=
15
+ await pc0.findOne({_id:$dntt$jscomp$1_id_pc0_t_tien_dn$$,id_app:$user$$.current_id_app});if(!$dntt$jscomp$1_id_pc0_t_tien_dn$$)return $next$$("\u0110\u1ec1 ngh\u1ecb thanh to\u00e1n kh\u00f4ng t\u1ed3n t\u1ea1i");$dntt$jscomp$1_id_pc0_t_tien_dn$$=($dntt$jscomp$1_id_pc0_t_tien_dn$$.details||[]).map($d$$=>$d$$.tien_nt||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0)+($dntt$jscomp$1_id_pc0_t_tien_dn$$.tdttcos||[]).map($d$$=>$d$$.tien_nt||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0)+($dntt$jscomp$1_id_pc0_t_tien_dn$$.vatvaos||
16
+ []).map($d$$=>$d$$.t_thue_nt||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$ex$jscomp$1_t_tien_tt$$=($data$$.details||$obj$$.details||[]).map($d$$=>$d$$.tien_nt||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0)+($data$$.tdttcos||$obj$$.tdttcos||[]).map($d$$=>$d$$.tien_nt||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0)+($data$$.vatvaos||$obj$$.vatvaos||[]).map($d$$=>$d$$.t_thue_nt||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);if($dntt$jscomp$1_id_pc0_t_tien_dn$$!==$ex$jscomp$1_t_tien_tt$$)return $next$$("T\u1ed5ng s\u1ed1 ti\u1ec1n thanh to\u00e1n ph\u1ea3i b\u1eb1ng v\u1edbi s\u1ed1 ti\u1ec1n trong \u0111\u1ec1 ngh\u1ecb thanh to\u00e1n \u0111\u00e3 \u0111\u01b0\u1ee3c duy\u1ec7t")}if($obj$$.tdttcos&&
15
17
  0<$obj$$.tdttcos.length&&(await $obj$$.tdttcos.asyncJoinModel2($user$$.current_id_app,Tdttco,{where:{id_tdtt:"_id"},fields:["tat_toan",{tien_hd_nt:"tien_nt"}]}),0<(await Promise.all($obj$$.tdttcos.map($hd$$=>(async()=>{if(!global.mongoose.Types.ObjectId.isValid($hd$$.id_tdtt))return{error:"Ho\u00e1 \u0111\u01a1n kh\u00f4ng h\u1ee3p l\u1ec7",invoice:$hd$$};let $ds_da_thanh_toan$$=await Tdttco_tt.find({id_app:$obj$$.id_app,id_tdtt:$hd$$.id_tdtt,id_ct:{$ne:$obj$$._id.toString()}}).lean(),$da_thanh_toan$$=
16
18
  $ds_da_thanh_toan$$.map($t$$=>$t$$.thanh_toan_qd||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0),$con_lai$$=$hd$$.tien_hd_nt-$da_thanh_toan$$;return $con_lai$$<$hd$$.thanh_toan_qd?{error:!0,invoice:$hd$$}:{ds_da_thanh_toan:$ds_da_thanh_toan$$,da_thanh_toan:$da_thanh_toan$$,invoice:$hd$$,con_lai:$con_lai$$}})()))).filter($hd$$=>$hd$$.error).length))return $next$$("S\u1ed1 ti\u1ec1n thanh to\u00e1n kh\u00f4ng \u0111\u01b0\u1ee3c l\u1edbn h\u01a1n s\u1ed1 ti\u1ec1n c\u00f2n l\u1ea1i c\u1ee7a ho\u00e1 \u0111\u01a1n");
17
19
  valid_detail($user$$,$data$$,function($error$$){if($error$$)return $next$$($error$$);$next$$(null,$data$$,$obj$$)})};$contr_router$$.on("saved",function($obj$$){$obj$$.id_pc0&&pc0.updateMany({_id:$obj$$.id_pc0},{id_pc1:$obj$$._id.toString(),trang_thai:"6"},($e$jscomp$1$$,$rs$$)=>{console.log("update pc0",$obj$$.id_pc0,$rs$$);pc0.findOne({_id:$obj$$.id_pc0},($e$jscomp$0$$,$_obj$$)=>{$_obj$$&&controller.postData($_obj$$,global.controllers.PC0,$e$$=>{$e$$&&console.error($e$$)})})});$obj$$.id_pn6&&pn6.updateMany({_id:$obj$$.id_pn6},
@@ -58,7 +58,7 @@ $detail$$.tien_hang_nt,$detail$$.tien_ck=$detail$$.tien_ck_nt||0,$detail$$.gia_b
58
58
  module.exports=function($contr_router$$){$contr_router$$=new controller($contr_router$$,model,ma_ct.toLowerCase(),{isVoucher:!0,requireRecaptchaToken:!1,unique:["so_ct"],sort:{ngay_ct:-1,so_ct:-1},onEmitEvent:async($obj$$,$users_will_receive$$,$next$$)=>{$obj$$.user_nv_giao_hang&&$users_will_receive$$.push($obj$$.user_nv_giao_hang);$next$$(null,$users_will_receive$$)}});$contr_router$$.route();$contr_router$$.saving=async($user$$,$obj$$)=>{await chietkhauhd($obj$$);await khuyenmaihd($obj$$)};$contr_router$$.handleAfterPayment=
59
59
  async $obj$$=>{let $app$$=await App.findOne({_id:$obj$$.id_app});$app$$.wallet_address&&$app$$.wallet_token&&$obj$$.details&&await Promise.all($obj$$.details.filter($d$$=>$d$$.is_coin&&!$d$$.transferred&&$d$$.wallet_receiver).map($detail$$=>(async()=>{let $memo$$=$obj$$.dien_giai||"",$amount$$=$detail$$.sl_xuat,$denom$$=$detail$$.ma_vt.toLowerCase(),$rs$$=await blockchainconnect.spend($obj$$.id_app,$app$$.wallet_token,$app$$.wallet_address,$detail$$.wallet_receiver,{amount:$amount$$,denom:$denom$$,
60
60
  memo:$memo$$});console.log("buy point result",$rs$$,$amount$$,$denom$$,$memo$$);$detail$$.transferred=!0})()));$obj$$.trang_thai_tt="5";await model.updateOne({_id:$obj$$._id},{details:$obj$$.details,trang_thai_tt:"5"});let $ctrlSO1$$=global.controllers.SO1;$ctrlSO1$$&&controller.postData($obj$$,$ctrlSO1$$,$e$$=>{if($e$$)return console.error($e$$);controller.pushNotification($ctrlSO1$$,$obj$$)});return null};$contr_router$$.post=async function($obj$$,$fn$$){$fn$$||($fn$$=function(){});let $he_so_qd$$=
61
- await currency.getRate($obj$$.id_app,$obj$$.ma_nt)||1;await $obj$$.details.asyncJoinModel2($obj$$.id_app,dmvt,{where:"ma_vt",fields:["ma_thue","gia_mua","combo"]});await $obj$$.details.filter($d$$=>$d$$.ma_thue).asyncJoinModel2($obj$$.id_app,global.getModel("vat"),{where:"ma_thue",fields:["thue_suat","tk_thue_co","tk_thue_co_treo"]});async.parallel({BuyPoint:$callback$$=>{BuyPoint($obj$$).then(()=>{$callback$$()}).catch($e$$=>{$callback$$($e$$)})},post_sodiemthuong:function($callback$$){const $details$$=
61
+ await currency.getRate($obj$$.id_app,$obj$$.ma_nt)||1;await $obj$$.details.asyncJoinModel2($obj$$.id_app,dmvt,{where:"ma_vt",fields:["ma_thue","gia_mua"]});await $obj$$.details.filter($d$$=>$d$$.ma_thue).asyncJoinModel2($obj$$.id_app,global.getModel("vat"),{where:"ma_thue",fields:["thue_suat","tk_thue_co","tk_thue_co_treo"]});async.parallel({BuyPoint:$callback$$=>{BuyPoint($obj$$).then(()=>{$callback$$()}).catch($e$$=>{$callback$$($e$$)})},post_sodiemthuong:function($callback$$){const $details$$=
62
62
  [];$obj$$.details.filter($d$$=>$d$$.diem_thuong).forEach($d$jscomp$32_detail$$=>{$d$jscomp$32_detail$$={...$d$jscomp$32_detail$$};$d$jscomp$32_detail$$.ngay_ct=$obj$$.ngay_ct;$d$jscomp$32_detail$$.ma_kh=$obj$$.ma_kh;$d$jscomp$32_detail$$.sl_nhan=$d$jscomp$32_detail$$.diem_thuong;$details$$.push($d$jscomp$32_detail$$)});(new PostBook($obj$$,$details$$,Sodiemthuong)).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})},post_sokho:function($callback$jscomp$0$$){const $details$$=[];$obj$$.details.forEach($d$$=>
63
63
  {$details$$.push({...$d$$})});let $data_post$$=$details$$.map($detail$$=>$detail$$.combo&&0<$detail$$.combo.length?$detail$$.combo.map($item$$=>{$item$$=$item$$.toObject?$item$$.toObject():{...$item$$};$item$$.sl_xuat*=$detail$$.sl_xuat;$item$$.tien_xuat=$item$$.tien_xuat_nt=$item$$.sl_xuat*$item$$.gia_von_nt;$item$$.tien_hang=$item$$.tien_hang_nt=$item$$.sl_xuat*$item$$.gia_ban_nt;$item$$.tien_ck=$item$$.tien_ck_nt*=$item$$.sl_xuat;$item$$.tien=$item$$.tien_nt=$item$$.tien_hang_nt-$item$$.tien_ck_nt;
64
64
  return $item$$}):[$detail$$]).reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]);(new PostBook($obj$$,$data_post$$,Sokho,async function($detail$$,$callback$$){$detail$$.nxt=2;$detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;$detail$$.ma_kho=$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$jscomp$0$$($e$$,$rs$$)})},post_socai:function($callback$$){options.findOne({id_app:$obj$$.id_app,id_func:ma_ct.toLowerCase()}).lean().exec(async($error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$,
@@ -83,24 +83,27 @@ $error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh=$obj$
83
83
  ($obj$$.tien_ck_hd||0)+($obj$$.tien_evoucher||0),$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien=$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_no=$obj$$.ma_kh,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_co=$option$$.ma_kh,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.check_balance=!1,$details$$.push($error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$);
84
84
  let $details_tienvon$$=[...$obj$$.details];$details_tienvon$$.joinModel2($obj$$.id_app,dmvt,{where:"ma_vt",fields:["tk_vt","gia_mua","tk_gv","tg_tk"]},()=>{$details_tienvon$$.forEach(function($d$jscomp$39_detail$$){$d$jscomp$39_detail$$={...$d$jscomp$39_detail$$};$d$jscomp$39_detail$$.tk_no=$option$$.tk_gv;$d$jscomp$39_detail$$.ma_kh=$obj$$.ma_kh;$d$jscomp$39_detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;$d$jscomp$39_detail$$.tk_co=$d$jscomp$39_detail$$.tk_vt||"1561";$d$jscomp$39_detail$$.tien_nt=
85
85
  $d$jscomp$39_detail$$.tien_xuat_nt;$d$jscomp$39_detail$$.tien=$d$jscomp$39_detail$$.tien_xuat;$d$jscomp$39_detail$$.tg_tk||($d$jscomp$39_detail$$.tien=$d$jscomp$39_detail$$.tien_nt=0);$details$$.push($d$jscomp$39_detail$$)});(new PostSocai($obj$$,$details$$,null,Socaitmp)).run(function($e$$,$rs$$){console.log("post result",$rs$$);$callback$$($e$$,$rs$$)})})})}},function($e$$,$rs$$){$fn$$($e$$,$rs$$)})};$contr_router$$.creating=async function($user$$,$obj$$,$next$$){$obj$$.details||($obj$$.details=
86
- []);if(!$obj$$.ma_kh){let $kh$$=await customer.findOne({id_app:$obj$$.id_app||$user$$.current_id_app,of_user:$user$$.email},{ma_kh:-1});$kh$$&&($obj$$.ma_kh=$kh$$.ma_kh)}delete $obj$$.virtual_payment_client_url;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.");
87
- $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);console.log("payment by",
88
- $pt_thanh_toan$$.payment_service,$obj$$.amount);if($obj$$.amount){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({id_ct:$obj$$._id.toString()})||{})._id||"").toString()}else $obj$$.virtual_payment_client_url="",$obj$$.payment_service="",
89
- $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},$e$$=>{$e$$&&(console.error($e$$),console.log("error create Virtual Payment ClientURL",$e$$.message))});await createTransactionPayment($obj$$);
90
- 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$$.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$$);
91
- 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($evouchers_user$$,$obj$$,$next$$){if(!$obj$$.virtual_payment_client_url&&("1"===$obj$$.trang_thai||"0"===$obj$$.trang_thai)){if($obj$$.pt_thanh_toan&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan))try{const $pt_thanh_toan$$=
92
- 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){let $virtual_payment_client_url$$=await $paymentServiceModel$$.createVirtualPaymentClientURL($obj$$,$evouchers_user$$.clientIp,$pt_thanh_toan$$);$obj$$.virtual_payment_client_url=$virtual_payment_client_url$$;$obj$$.payment_service=$pt_thanh_toan$$.payment_service;
93
- $obj$$.payment_id=((await $paymentServiceModel$$.findOne({id_ct:$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$$("Error create Virtual Payment ClientURL:"+($e$$.message||$e$$.error||$e$$))}else $obj$$.virtual_payment_client_url="";model.findOneAndUpdate({_id:$obj$$._id},{virtual_payment_client_url:$obj$$.virtual_payment_client_url},
94
- $e$$=>{$e$$&&console.log("error create Virtual Payment ClientURL",$e$$.message)})}"9"===$obj$$.trang_thai?(await transaction.deleteTrans({id_ct:$obj$$._id.toString()}),await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng"),await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":buy"})):(await createTransactionPayment($obj$$),createTransactionBonus($obj$$));await Evoucher.updateMany({id_ct_used:$obj$$._id.toString()},{id_ct_used:null});
95
- $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)));$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>updateEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$next$$(null,$obj$$)};$contr_router$$.deleting=function($user$$,$obj$$,$next$$){$next$$(null,$obj$$)};$contr_router$$.deleted=async function($user$$,$obj$$,$next$$){await transaction.deleteTrans({id_ct:$obj$$._id.toString()});
96
- await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng");await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":buy"});$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>deleteEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$next$$(null,$obj$$)};$contr_router$$.view=function($user$$,$items$$,$fn$$){async.parallel({app:function($callback$$){$items$$.filter($item$$=>$item$$.id_app).joinModel2(null,App,[{where:{id_app:"_id"},
97
- fields:{name_app:"name"}}],function(){$callback$$()})},kh:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kh).joinModel2(null,customer,[{where:$item$$=>({id_app:$item$$.id_app,ma_kh:$item$$.ma_kh}),fields:"ten_kh"}],function(){$callback$$()})},nhan_vien_giao_hang:function($callback$$){$items$$.filter($item$$=>$item$$.nhan_vien_giao_hang).joinModel2(null,customer,[{where:{nhan_vien_giao_hang:"ma_kh"},fields:[{ten_nhan_vien_giao_hang:"ten_kh"}]}],function(){$callback$$()})},nv_giao_hang:function($callback$$){$items$$.filter($item$$=>
98
- $item$$.user_nv_giao_hang).joinModel2(null,User,{where:{user_nv_giao_hang:"email"},fields:{ten_nv_giao_hang:"name"}},function(){$callback$$()})},kho:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kho).joinModel2(null,dmkho,[{where:$item$$=>({id_app:$item$$.id_app,ma_kho:$item$$.ma_kho}),fields:["ten_kho",{tk_cn_kho:"tk_cn"}]}],function(){$callback$$()})},trangthai:function($callback$$){$items$$.filter($item$$=>$item$$.trang_thai).joinModel2(null,trangthai,[{where:{trang_thai:"ma_trang_thai",
99
- ma_ct:"ma_ct"},fields:["ten_trang_thai","color"]}],function(){$callback$$()})},ptthanhtoan:function($callback$$){$items$$.filter($item$$=>$item$$.pt_thanh_toan).joinModel2(null,ptthanhtoan,[{where:$item$$=>({_id:$item$$.pt_thanh_toan,id_app:$item$$.id_app}),fields:[{ten_pt_thanh_toan:"ten"},{tk_cn_thanhtoan:"tk_cn"}]}],function(){$callback$$()})},pt1:function($callback$$){$items$$.joinModel2(null,pt1,[{where:$item$$=>({id_app:$item$$.id_app,id_so1:"_id"}),fields:[{id_pt1:"_id"},{so_ct_pt1:"so_ct"},
100
- {ma_ct_pt1:"ma_ct"},{ngay_ct_pt1:"ngay_ct"}]}],function(){$callback$$()})},t_tien:function($callback$$){$items$$.filter($item$$=>$item$$.details).forEach(function($r$$){$r$$.tien_phi_vc=$r$$.tien_phi_vc||0;$r$$.tien_freeship=$r$$.tien_freeship||0;$r$$.details?($r$$.t_sl=$r$$.details.csum("sl_xuat"),$r$$.t_tien_hang=$r$$.details.csum("tien_hang"),$r$$.t_tien_hang_nt=$r$$.details.csum("tien_hang_nt"),$r$$.t_tien=$r$$.t_tien_hang-$r$$.details.csum("tien_ck"),$r$$.t_tien_nt=$r$$.t_tien_hang_nt-$r$$.details.csum("tien_ck_nt"),
101
- $r$$.t_ck_nt=$r$$.t_ck=$r$$.tien_ck_hd+($r$$.tien_evoucher||0)):($r$$.t_sl=0,$r$$.t_tien_hang=0,$r$$.t_tien_hang_nt=0,$r$$.t_ck=0,$r$$.t_ck_nt=0,$r$$.t_tien=$r$$.t_tien_hang,$r$$.t_tien_nt=$r$$.t_tien_hang_nt);$r$$.ctcpbhs?($r$$.t_cp_cpb_nt=$r$$.ctcpbhs.csum("tien_cp_nt"),$r$$.t_cp_cpb=$r$$.ctcpbhs.csum("tien_cp")):($r$$.t_cp_cpb_nt=0,$r$$.t_cp_cpb=0);$r$$.t_tt=$r$$.t_tt_nt=Math.max(0,$r$$.t_tien_nt+$r$$.t_cp_cpb_nt-$r$$.t_ck_nt-($r$$.tt_tien_thuong||0)+($r$$.tien_phi_vc||0)-($r$$.tien_freeship||
102
- 0))});$callback$$()},details_vt:function($callback$$){async.each($items$$,function($r$$,$callback1$$){const $details$$=$r$$.details;if(!$details$$)return $callback1$$();$details$$.joinModel2(null,dmvt,[{where:$item$$=>({id_app:$r$$.id_app,ma_vt:$item$$.ma_vt}),fields:"ten_vt picture chieu_cao chieu_rong chieu_sau trong_luong".split(" ")}],function(){$callback1$$()})},function(){$callback$$()})},details_tt1:function($callback$$){async.map($items$$,function($r$$,$callback1$$){$r$$.details.filter($item$$=>
103
- $item$$.ma_tt1).joinModel2(null,dmtt,[{where:$item$$=>({id_app:$r$$.id_app,ma_vt:$item$$.ma_vt,ma_tt1:$item$$.ma_tt1}),setFields:($item$$,$ref$$)=>{$item$$.ten_vt=$item$$.ten_vt+" - "+$ref$$.ten_tt}}],function(){$callback1$$()})},function(){$callback$$()})},details_dt:function($callback$$){async.map($items$$,function($r$$,$callback1$$){const $details$$=$r$$.details;if(!$details$$)return $callback1$$();$details$$.filter($item$$=>$item$$.ma_dt).joinModel2(null,dmdt,[{where:$item$$=>({id_app:$r$$.id_app,
104
- ma_dt:$item$$.ma_dt}),fields:["ten_dt"]}],function(){$callback1$$()})},function(){$callback$$()})},details_contract:function($callback$$){async.map($items$$,function($r$$,$callback1$$){const $details$$=$r$$.details;if(!$details$$)return $callback1$$();$details$$.filter($item$$=>$item$$.ma_hd).joinModel2(null,contract,[{where:$item$$=>({id_app:$r$$.id_app,so_hd:$item$$.ma_hd}),fields:["ten_hd"]}],function(){$callback1$$()})},function(){$callback$$()})},details_phi:function($callback$$){async.map($items$$,
105
- function($r$$,$callback1$$){const $details$$=$r$$.details;if(!$details$$)return $callback1$$();$details$$.filter($item$$=>$item$$.ma_phi).joinModel2(null,dmphi,[{where:$item$$=>({id_app:$r$$.id_app,ma_phi:$item$$.ma_phi}),fields:["ten_phi"]}],function(){$callback1$$()})},function(){$callback$$()})},details_cpbh:function($callback$$){async.each($items$$,function($r$$,$callback1$$){let $ctcpbhs$$=$r$$.ctcpbhs;if(!$ctcpbhs$$)return $callback1$$();$ctcpbhs$$?$ctcpbhs$$.filter($item$$=>$item$$.ma_cp).joinModel2(null,
106
- dmcpmh,[{where:$item$$=>({id_app:$r$$.id_app,ma_cp:$item$$.ma_cp}),fields:["ten_cp"]}],function(){$callback1$$()}):$callback1$$()},function(){$callback$$()})}},function(){$fn$$(null,$items$$)})}};
86
+ []);if(!$obj$$.ma_kh){let $kh$$=await customer.findOne({id_app:$obj$$.id_app||$user$$.current_id_app,of_user:$user$$.email},{ma_kh:-1});$kh$$&&($obj$$.ma_kh=$kh$$.ma_kh)}delete $obj$$.virtual_payment_client_url;await $obj$$.details.asyncJoinModel2($user$$.current_id_app,dmvt,{where:"ma_vt",fields:["combo"]});$obj$$.details.forEach($detail$$=>{$detail$$.combo&&0<$detail$$.combo.length&&($detail$$.combo=$detail$$.combo.map($item$$=>{$item$$=$item$$.toObject?$item$$.toObject():{...$item$$};$item$$.sl_xuat*=
87
+ $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$$}))});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,
88
+ $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$$=
89
+ global.getModel($pt_thanh_toan$$.payment_service);$obj$$.amount=$obj$$.t_tt_nt-($obj$$.tien_paymentByPoints||0);console.log("payment by",$pt_thanh_toan$$.payment_service,$obj$$.amount);if($obj$$.amount){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({id_ct:$obj$$._id.toString()})||
90
+ {})._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},$e$$=>{$e$$&&(console.error($e$$),
91
+ 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);await $data$$.details.asyncJoinModel2($user$$.current_id_app,dmvt,{where:"ma_vt",fields:["combo"]});$obj$$.details.forEach($detail$$=>
92
+ {$detail$$.combo&&0<$detail$$.combo.length&&($detail$$.combo=$detail$$.combo.map($item$$=>{$item$$=$item$$.toObject?$item$$.toObject():{...$item$$};$item$$.sl_xuat*=$detail$$.sl_xuat;$item$$.tien_xuat=$item$$.tien_xuat_nt=$item$$.sl_xuat*($item$$.gia_von_nt||0);$item$$.tien_hang=$item$$.tien_hang_nt=$item$$.sl_xuat*($item$$.gia_ban_nt||0);$item$$.tien_ck=$item$$.tien_ck_nt=$item$$.sl_xuat*($item$$.tien_ck_nt||0);$item$$.tien=$item$$.tien_nt=$item$$.tien_hang_nt-($item$$.tien_ck_nt||0);return $item$$}))});
93
+ $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()+
94
+ ":buy"});$next$$(null,$data$$,$obj$$)},$obj$$)};$contr_router$$.updated=async function($evouchers_user$$,$obj$$,$next$$){if(!$obj$$.virtual_payment_client_url&&("1"===$obj$$.trang_thai||"0"===$obj$$.trang_thai)){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);
95
+ $obj$$.amount=$obj$$.t_tt_nt-($obj$$.tien_paymentByPoints||0);if($obj$$.amount){let $virtual_payment_client_url$$=await $paymentServiceModel$$.createVirtualPaymentClientURL($obj$$,$evouchers_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({id_ct:$obj$$._id.toString()})||{})._id||"").toString()}else $obj$$.virtual_payment_client_url="",$obj$$.payment_service=
96
+ "",$obj$$.payment_id=""}else $obj$$.virtual_payment_client_url=""}catch($e$$){return console.error($e$$),$next$$("Error create Virtual Payment ClientURL:"+($e$$.message||$e$$.error||$e$$))}else $obj$$.virtual_payment_client_url="";model.findOneAndUpdate({_id:$obj$$._id},{virtual_payment_client_url:$obj$$.virtual_payment_client_url},$e$$=>{$e$$&&console.log("error create Virtual Payment ClientURL",$e$$.message)})}"9"===$obj$$.trang_thai?(await transaction.deleteTrans({id_ct:$obj$$._id.toString()}),
97
+ await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng"),await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":buy"})):(await createTransactionPayment($obj$$),createTransactionBonus($obj$$));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)));
98
+ $obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>updateEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$next$$(null,$obj$$)};$contr_router$$.deleting=function($user$$,$obj$$,$next$$){$next$$(null,$obj$$)};$contr_router$$.deleted=async function($user$$,$obj$$,$next$$){await transaction.deleteTrans({id_ct:$obj$$._id.toString()});await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng");await transaction.deleteTrans({id_ct:$obj$$._id.toString()+
99
+ ":buy"});$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>deleteEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$next$$(null,$obj$$)};$contr_router$$.view=function($user$$,$items$$,$fn$$){async.parallel({app:function($callback$$){$items$$.filter($item$$=>$item$$.id_app).joinModel2(null,App,[{where:{id_app:"_id"},fields:{name_app:"name"}}],function(){$callback$$()})},kh:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kh).joinModel2(null,customer,[{where:$item$$=>({id_app:$item$$.id_app,
100
+ ma_kh:$item$$.ma_kh}),fields:"ten_kh"}],function(){$callback$$()})},nhan_vien_giao_hang:function($callback$$){$items$$.filter($item$$=>$item$$.nhan_vien_giao_hang).joinModel2(null,customer,[{where:{nhan_vien_giao_hang:"ma_kh"},fields:[{ten_nhan_vien_giao_hang:"ten_kh"}]}],function(){$callback$$()})},nv_giao_hang:function($callback$$){$items$$.filter($item$$=>$item$$.user_nv_giao_hang).joinModel2(null,User,{where:{user_nv_giao_hang:"email"},fields:{ten_nv_giao_hang:"name"}},function(){$callback$$()})},
101
+ kho:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kho).joinModel2(null,dmkho,[{where:$item$$=>({id_app:$item$$.id_app,ma_kho:$item$$.ma_kho}),fields:["ten_kho",{tk_cn_kho:"tk_cn"}]}],function(){$callback$$()})},trangthai:function($callback$$){$items$$.filter($item$$=>$item$$.trang_thai).joinModel2(null,trangthai,[{where:{trang_thai:"ma_trang_thai",ma_ct:"ma_ct"},fields:["ten_trang_thai","color"]}],function(){$callback$$()})},ptthanhtoan:function($callback$$){$items$$.filter($item$$=>$item$$.pt_thanh_toan).joinModel2(null,
102
+ ptthanhtoan,[{where:$item$$=>({_id:$item$$.pt_thanh_toan,id_app:$item$$.id_app}),fields:[{ten_pt_thanh_toan:"ten"},{tk_cn_thanhtoan:"tk_cn"}]}],function(){$callback$$()})},pt1:function($callback$$){$items$$.joinModel2(null,pt1,[{where:$item$$=>({id_app:$item$$.id_app,id_so1:"_id"}),fields:[{id_pt1:"_id"},{so_ct_pt1:"so_ct"},{ma_ct_pt1:"ma_ct"},{ngay_ct_pt1:"ngay_ct"}]}],function(){$callback$$()})},t_tien:function($callback$$){$items$$.filter($item$$=>$item$$.details).forEach(function($r$$){$r$$.tien_phi_vc=
103
+ $r$$.tien_phi_vc||0;$r$$.tien_freeship=$r$$.tien_freeship||0;$r$$.details?($r$$.t_sl=$r$$.details.csum("sl_xuat"),$r$$.t_tien_hang=$r$$.details.csum("tien_hang"),$r$$.t_tien_hang_nt=$r$$.details.csum("tien_hang_nt"),$r$$.t_tien=$r$$.t_tien_hang-$r$$.details.csum("tien_ck"),$r$$.t_tien_nt=$r$$.t_tien_hang_nt-$r$$.details.csum("tien_ck_nt"),$r$$.t_ck_nt=$r$$.t_ck=$r$$.tien_ck_hd+($r$$.tien_evoucher||0)):($r$$.t_sl=0,$r$$.t_tien_hang=0,$r$$.t_tien_hang_nt=0,$r$$.t_ck=0,$r$$.t_ck_nt=0,$r$$.t_tien=$r$$.t_tien_hang,
104
+ $r$$.t_tien_nt=$r$$.t_tien_hang_nt);$r$$.ctcpbhs?($r$$.t_cp_cpb_nt=$r$$.ctcpbhs.csum("tien_cp_nt"),$r$$.t_cp_cpb=$r$$.ctcpbhs.csum("tien_cp")):($r$$.t_cp_cpb_nt=0,$r$$.t_cp_cpb=0);$r$$.t_tt=$r$$.t_tt_nt=Math.max(0,$r$$.t_tien_nt+$r$$.t_cp_cpb_nt-$r$$.t_ck_nt-($r$$.tt_tien_thuong||0)+($r$$.tien_phi_vc||0)-($r$$.tien_freeship||0))});$callback$$()},details_vt:function($callback$$){async.each($items$$,function($r$$,$callback1$$){const $details$$=$r$$.details;if(!$details$$)return $callback1$$();$details$$.joinModel2(null,
105
+ dmvt,[{where:$item$$=>({id_app:$r$$.id_app,ma_vt:$item$$.ma_vt}),fields:"ten_vt picture chieu_cao chieu_rong chieu_sau trong_luong".split(" ")}],function(){$callback1$$()})},function(){$callback$$()})},details_tt1:function($callback$$){async.map($items$$,function($r$$,$callback1$$){$r$$.details.filter($item$$=>$item$$.ma_tt1).joinModel2(null,dmtt,[{where:$item$$=>({id_app:$r$$.id_app,ma_vt:$item$$.ma_vt,ma_tt1:$item$$.ma_tt1}),setFields:($item$$,$ref$$)=>{$item$$.ten_vt=$item$$.ten_vt+" - "+$ref$$.ten_tt}}],
106
+ function(){$callback1$$()})},function(){$callback$$()})},details_dt:function($callback$$){async.map($items$$,function($r$$,$callback1$$){const $details$$=$r$$.details;if(!$details$$)return $callback1$$();$details$$.filter($item$$=>$item$$.ma_dt).joinModel2(null,dmdt,[{where:$item$$=>({id_app:$r$$.id_app,ma_dt:$item$$.ma_dt}),fields:["ten_dt"]}],function(){$callback1$$()})},function(){$callback$$()})},details_contract:function($callback$$){async.map($items$$,function($r$$,$callback1$$){const $details$$=
107
+ $r$$.details;if(!$details$$)return $callback1$$();$details$$.filter($item$$=>$item$$.ma_hd).joinModel2(null,contract,[{where:$item$$=>({id_app:$r$$.id_app,so_hd:$item$$.ma_hd}),fields:["ten_hd"]}],function(){$callback1$$()})},function(){$callback$$()})},details_phi:function($callback$$){async.map($items$$,function($r$$,$callback1$$){const $details$$=$r$$.details;if(!$details$$)return $callback1$$();$details$$.filter($item$$=>$item$$.ma_phi).joinModel2(null,dmphi,[{where:$item$$=>({id_app:$r$$.id_app,
108
+ ma_phi:$item$$.ma_phi}),fields:["ten_phi"]}],function(){$callback1$$()})},function(){$callback$$()})},details_cpbh:function($callback$$){async.each($items$$,function($r$$,$callback1$$){let $ctcpbhs$$=$r$$.ctcpbhs;if(!$ctcpbhs$$)return $callback1$$();$ctcpbhs$$?$ctcpbhs$$.filter($item$$=>$item$$.ma_cp).joinModel2(null,dmcpmh,[{where:$item$$=>({id_app:$r$$.id_app,ma_cp:$item$$.ma_cp}),fields:["ten_cp"]}],function(){$callback1$$()}):$callback1$$()},function(){$callback$$()})}},function(){$fn$$(null,
109
+ $items$$)})}};
package/server/route.js CHANGED
@@ -14,17 +14,17 @@ $id_app$jscomp$1_next$$=$req$$.params.id_app;$modelName_user$$=$req$$.params.mod
14
14
  {},$req$$.query.fields.split(",").forEach($field$$=>{$fields$$[$field$$]=1}));try{$limit$$=Number($limit$$)}catch($e$$){return $res$$.status(400).send($e$$.message)}$limit$$||($limit$$=1E3);$model$$.find($query$$,$fields$$).limit($limit$$).lean().exec(($e$$,$rs$$)=>{if($e$$)return $res$$.status(400).send($e$$);$res$$.send($rs$$)});break;case "update":let $data$$=$req$$.query.fields;if(!$data$$)return $res$$.status(400).send("Data to update is empty");try{$data$$=JSON.parse($data$$),$model$$.updateMany($query$$,
15
15
  $data$$,($e$$,$rs$$)=>{if($e$$)return $res$$.status(400).send($e$$);$res$$.send($rs$$)})}catch($e$$){$res$$.status(400).send($e$$.message)}break;case "remove":$model$$.deleteMany($query$$,($e$$,$rs$$)=>{if($e$$)return $res$$.status(400).send($e$$);$res$$.send($rs$$)});break;default:$res$$.status(400).send(`Action ${$action$$} is not support`)}}catch($e$$){$res$$.status(400).send($e$$.message)}});const $Menu$$=require(configs.paths.menu||"./menu");$router$$.route("/modules").get(function($req$$,$res$$){$Menu$$.getMenu($menu_modules_o_rs$$=>
16
16
  {$menu_modules_o_rs$$=JSON.parse(JSON.stringify($menu_modules_o_rs$$));$menu_modules_o_rs$$=$Menu$$.getModules($menu_modules_o_rs$$);let $modules_a$$=[];for(let $key$$ in $menu_modules_o_rs$$)$modules_a$$.push($menu_modules_o_rs$$[$key$$].command);$res$$.send($modules_a$$)})});const $permission$$=require("./libs/permission");$router$$.route("/:id_app/menu").get(function($req$$,$res$$){$Menu$$.getMenu($Menu_menu$$=>{const $id_app$$=$req$$.params.id_app,$user$$=$req$$.user;appModel.findOne({_id:$id_app$$}).lean().exec(function($e$jscomp$1$$,
17
- $app$$){if($e$jscomp$1$$||!$app$$)return $res$$.status(400).send("Kh\u00f4ng th\u1ec3 l\u1ea5y th\u00f4ng tin c\u1ee7a c\u00f4ng ty n\u00e0y.\n");$permission$$.isAdmin($id_app$$,$user$$.email,function($e$jscomp$0$$,$admin$$){const $menu$$={menu:JSON.parse(JSON.stringify($Menu_menu$$))};let $_menu$$=$menu$$.menu=$menu$$.menu.filter($m$$=>!$m$$.appAllow||0===$m$$.appAllow.length||0<=$m$$.appAllow.indexOf($id_app$$));$menu$$.modules=$Menu$$.getModules($_menu$$);$admin$$?$res$$.send($menu$$):async.map(underscore.values($menu$$.modules),
18
- function($module$$,$callback$$){var $m$$=$module$$.command;$permission$$.hasRight($id_app$$,$user$$.email,$m$$.module?$m$$.module:$m$$.path,"view",function($e$$,$right$$){$m$$.visible=$right$$;$callback$$()})},function($e$$){if($e$$)return $res$$.status(400).send($e$$);$_menu$$.forEach(function($child_menu$$){$child_menu$$.visible=!1;if("1"==$child_menu$$.type)for(let $i$$ of $child_menu$$.input)if($i$$.items)for(let $_i$$ of $i$$.items){if($_i$$.visible){$i$$.visible=!0;$child_menu$$.visible=!0;
19
- break}}else if($i$$.visible){$child_menu$$.visible=!0;break}"2"==$child_menu$$.type&&$child_menu$$.input.forEach(function($module$$){$module$$.visible=!1;$module$$.items.forEach(function($item$$){$item$$.visible&&($module$$.visible=!0,$child_menu$$.visible=!0)})});"3"==$child_menu$$.type&&$child_menu$$.input.forEach(function($module$$){$module$$.visible=!1;$module$$.items.forEach(function($group$$){$group$$.visible=!1;$group$$.items.forEach(function($item$$){$item$$.visible&&($group$$.visible=!0,
20
- $module$$.visible=!0,$child_menu$$.visible=!0)})})})});$res$$.send($menu$$)})})})})});const $bot_router$$=express.Router();configs.limitRequest.bot&&($limiter$jscomp$2_limiter$$=$createRateLimiterMiddleware_limiter_others$$(configs.limitRequest.bot,"bot"),$router$$.use($limiter$jscomp$2_limiter$$));$app$$.use("/bot",$bot_router$$);fs.existsSync(__dirname+"/modules/bot")&&(console.log("init bot..."),fs.readdirSync(__dirname+"/modules/bot").forEach(function($file$$){".js"===$file$$.substr(-3)&&require("./modules/bot/"+
21
- $file$$)($bot_router$$)}));const $public_router$$=express.Router();configs.limitRequest.public&&($limiter$jscomp$2_limiter$$=$createRateLimiterMiddleware_limiter_others$$(configs.limitRequest.public,"public"),$router$$.use($limiter$jscomp$2_limiter$$));$public_router$$.use(function($req$$,$res$$,$next$$){for(let $key$$ in $req$$.query)"true"==$req$$.query[$key$$]&&($req$$.query[$key$$]=!0),"false"==$req$$.query[$key$$]&&($req$$.query[$key$$]=!1);if($req$$.query.id_app){let $id_app$$=$req$$.query.id_app;
22
- appModel.findOne({_id:$id_app$$},function($error$$,$app$$){if($error$$)return $next$$($error$$);if($app$$)$req$$.user={current_id_app:$id_app$$,email:"public"},$req$$.query.id_app=$id_app$$,$next$$();else return $res$$.status(400).send("Kh\u00f4ng t\u1ed3n t\u1ea1i c\u00f4ng ty n\u00e0y")})}else $next$$()});$app$$.use("/public",$public_router$$);const $funcs_public_inited$$={};configs.paths.modules&&fs.existsSync(configs.paths.modules+"/public")&&(console.log("init custom public..."),fs.readdirSync(configs.paths.modules+
23
- "/public").forEach(function($file$$){".js"==$file$$.substr(-3)&&(require(configs.paths.modules+"/public/"+$file$$)($public_router$$),$funcs_public_inited$$[$file$$]=$file$$)}));fs.existsSync(__dirname+"/modules/public")&&(console.log("init default public..."),fs.readdirSync(__dirname+"/modules/public").filter($file$$=>!$funcs_public_inited$$[$file$$]).forEach(function($file$$){".js"==$file$$.substr(-3)&&(require("./modules/public/"+$file$$)($public_router$$),$funcs_public_inited$$[$file$$]=$file$$)}));
24
- $createRateLimiterMiddleware_limiter_others$$=$createRateLimiterMiddleware_limiter_others$$(configs.limitRequest.other||{},"other");$app$$.get("/getfile/:folder/:filename",$createRateLimiterMiddleware_limiter_others$$,function($req$$,$res$$){let $root_dir$$=configs.paths.images||path.join(__dirname,"images"),$imgPath$$=path.join($root_dir$$,$req$$.params.folder,$req$$.params.filename);if(fs.existsSync($imgPath$$)){let $size$$,$cache$$;if($req$$.query.size||$req$$.query.resize)switch(String($req$$.query.size||
17
+ $app$$){if($e$jscomp$1$$||!$app$$)return $res$$.status(400).send("Kh\u00f4ng th\u1ec3 l\u1ea5y th\u00f4ng tin c\u1ee7a c\u00f4ng ty n\u00e0y.\n");$permission$$.isAdmin($id_app$$,$user$$.email,function($e$jscomp$0$$,$admin$$){if($e$jscomp$0$$)return $res$$.status(403).send({error:$e$jscomp$0$$});const $menu$$={menu:JSON.parse(JSON.stringify($Menu_menu$$))};let $_menu$$=$menu$$.menu=$menu$$.menu.filter($m$$=>!$m$$.appAllow||0===$m$$.appAllow.length||0<=$m$$.appAllow.indexOf($id_app$$));$menu$$.modules=
18
+ $Menu$$.getModules($_menu$$);$admin$$?$res$$.send($menu$$):async.map(underscore.values($menu$$.modules),function($module$$,$callback$$){var $m$$=$module$$.command;$permission$$.hasRight($id_app$$,$user$$.email,$m$$.module?$m$$.module:$m$$.path,"view",function($e$$,$right$$){$m$$.visible=$right$$;$callback$$()})},function($e$$){if($e$$)return $res$$.status(400).send($e$$);$_menu$$.forEach(function($child_menu$$){$child_menu$$.visible=!1;if("1"==$child_menu$$.type)for(let $i$$ of $child_menu$$.input)if($i$$.items)for(let $_i$$ of $i$$.items){if($_i$$.visible){$i$$.visible=
19
+ !0;$child_menu$$.visible=!0;break}}else if($i$$.visible){$child_menu$$.visible=!0;break}"2"==$child_menu$$.type&&$child_menu$$.input.forEach(function($module$$){$module$$.visible=!1;$module$$.items.forEach(function($item$$){$item$$.visible&&($module$$.visible=!0,$child_menu$$.visible=!0)})});"3"==$child_menu$$.type&&$child_menu$$.input.forEach(function($module$$){$module$$.visible=!1;$module$$.items.forEach(function($group$$){$group$$.visible=!1;$group$$.items.forEach(function($item$$){$item$$.visible&&
20
+ ($group$$.visible=!0,$module$$.visible=!0,$child_menu$$.visible=!0)})})})});$res$$.send($menu$$)})})})})});const $bot_router$$=express.Router();configs.limitRequest.bot&&($limiter$jscomp$2_limiter$$=$createRateLimiterMiddleware_limiter_others$$(configs.limitRequest.bot,"bot"),$router$$.use($limiter$jscomp$2_limiter$$));$app$$.use("/bot",$bot_router$$);fs.existsSync(__dirname+"/modules/bot")&&(console.log("init bot..."),fs.readdirSync(__dirname+"/modules/bot").forEach(function($file$$){".js"===$file$$.substr(-3)&&
21
+ require("./modules/bot/"+$file$$)($bot_router$$)}));const $public_router$$=express.Router();configs.limitRequest.public&&($limiter$jscomp$2_limiter$$=$createRateLimiterMiddleware_limiter_others$$(configs.limitRequest.public,"public"),$router$$.use($limiter$jscomp$2_limiter$$));$public_router$$.use(function($req$$,$res$$,$next$$){for(let $key$$ in $req$$.query)"true"==$req$$.query[$key$$]&&($req$$.query[$key$$]=!0),"false"==$req$$.query[$key$$]&&($req$$.query[$key$$]=!1);if($req$$.query.id_app){let $id_app$$=
22
+ $req$$.query.id_app;appModel.findOne({_id:$id_app$$},function($error$$,$app$$){if($error$$)return $next$$($error$$);if($app$$)$req$$.user={current_id_app:$id_app$$,email:"public"},$req$$.query.id_app=$id_app$$,$next$$();else return $res$$.status(400).send("Kh\u00f4ng t\u1ed3n t\u1ea1i c\u00f4ng ty n\u00e0y")})}else $next$$()});$app$$.use("/public",$public_router$$);const $funcs_public_inited$$={};configs.paths.modules&&fs.existsSync(configs.paths.modules+"/public")&&(console.log("init custom public..."),
23
+ fs.readdirSync(configs.paths.modules+"/public").forEach(function($file$$){".js"==$file$$.substr(-3)&&(require(configs.paths.modules+"/public/"+$file$$)($public_router$$),$funcs_public_inited$$[$file$$]=$file$$)}));fs.existsSync(__dirname+"/modules/public")&&(console.log("init default public..."),fs.readdirSync(__dirname+"/modules/public").filter($file$$=>!$funcs_public_inited$$[$file$$]).forEach(function($file$$){".js"==$file$$.substr(-3)&&(require("./modules/public/"+$file$$)($public_router$$),$funcs_public_inited$$[$file$$]=
24
+ $file$$)}));$createRateLimiterMiddleware_limiter_others$$=$createRateLimiterMiddleware_limiter_others$$(configs.limitRequest.other||{},"other");$app$$.get("/getfile/:folder/:filename",$createRateLimiterMiddleware_limiter_others$$,function($req$$,$res$$){let $root_dir$$=configs.paths.images||path.join(__dirname,"images"),$imgPath$$=path.join($root_dir$$,$req$$.params.folder,$req$$.params.filename);if(fs.existsSync($imgPath$$)){let $size$$,$cache$$;if($req$$.query.size||$req$$.query.resize)switch(String($req$$.query.size||
25
25
  $req$$.query.resize).toUpperCase()){case "64":case "X":$size$$=64;$cache$$=!0;break;case "128":$size$$=128;$cache$$=!0;break;case "320":case "S":$size$$=320;$cache$$=!0;break;case "512":case "M":$size$$=512;$cache$$=!0;break;case "1024":case "L":$size$$=1024;$cache$$=!0;break;default:try{$size$$=Number($req$$.query.size||$req$$.query.resize)}catch($e$$){console.log("size param must be X or S or M or L or a number")}}if($size$$){let $file_name_resize$$=path.join($root_dir$$,$req$$.params.folder,String($size$$)+
26
26
  "."+$req$$.params.filename);if(fs.existsSync($file_name_resize$$))return gm($file_name_resize$$).stream(function($err$$,$stdout$$){$stdout$$.pipe($res$$)});$cache$$?gm($imgPath$$).resize($size$$,null).write($file_name_resize$$,function($error$$){if($error$$)console.log("Can't resize image \n"+$error$$),$res$$.sendFile($imgPath$$);else return gm($file_name_resize$$).stream(function($err$$,$stdout$$){$stdout$$.pipe($res$$)})}):gm($imgPath$$).resize($size$$,null).stream(function($err$$,$stdout$$){$stdout$$.pipe($res$$)})}else $res$$.sendFile($imgPath$$)}else $res$$.sendFile(path.join(__dirname,
27
27
  "images","others","noimage.png"))});const $Labelinfo$$=global.getModel("labelinfo");$app$$.get("/labels/:labelid",$createRateLimiterMiddleware_limiter_others$$,function($labelid_req$$,$res$$){$labelid_req$$=$labelid_req$$.params.labelid.toUpperCase();$Labelinfo$$.find({labelid:$labelid_req$$}).lean().exec(($e$$,$labels$$)=>{if($e$$)return $res$$.status(400).send($e$$);let $_labels$$={};$labels$$.forEach($l$$=>{$_labels$$[$l$$.textid]=$l$$});$res$$.send($_labels$$)})});const $qr$$=require("qr-image");
28
28
  $app$$.get("/qrcode",$createRateLimiterMiddleware_limiter_others$$,function($req$$,$res$$){let $report$$=$req$$.query.report;$report$$||($report$$=$req$$.query.data)&&($report$$=Buffer.from($report$$,"base64").toString("utf8"));if(!$report$$)return $res$$.status(400).send("miss parameter 'report'");setImmediate(()=>{const $code$$=$qr$$.image($report$$,{type:"svg"});$res$$.type("svg");$code$$.pipe($res$$)})});const $nodemailer$$=require("nodemailer");$app$$.post("/sendmail",function($req$$,$res$$){setImmediate(()=>
29
29
  {let $msg$$=$req$$.body;if("KHGFIUWPPC"!==$msg$$.secretKey)return $res$$.status(400).send("Not allow");if(!$msg$$.to||!$msg$$.subject||!$msg$$.message)return $res$$.status(400).send("Msg is not valid");$nodemailer$$.createTransport({host:"mail.flexbiz.app",port:25,secure:!1,auth:{user:"info",pass:""},tls:{rejectUnauthorized:!1},name:$msg$$.name}).sendMail({from:"info@flexbiz.app",to:$msg$$.to,subject:$msg$$.subject,text:$msg$$.message,html:$msg$$.message},$e$$=>{if($e$$)return $res$$.status(400).send($e$$);
30
- $res$$.send("OK")})})});$cb$$()}};
30
+ $res$$.send("OK")})})})}$cb$$()};