flexbiz-server 12.5.34 → 12.5.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "flexbiz-server",
3
3
  "main": "./server/app.js",
4
4
  "description": "Flexible Server",
5
- "version": "12.5.34",
5
+ "version": "12.5.36",
6
6
  "author": {
7
7
  "name": "Van Truong Pham",
8
8
  "email": "invncur@gmail.com"
@@ -6,7 +6,7 @@ new Date($condition$$.tu_ngay)<$ngay$$?moment($condition$$.tu_ngay).endOf("date"
6
6
  $condition$$.ma_tt2&&($c_dk$$.ma_tt2=$condition$$.ma_tt2);$condition$$.ma_tt3&&($c_dk$$.ma_tt3=$condition$$.ma_tt3);$cdvt$$.find($c_dk$$).lean().then($results$$=>{$callback$$(null,$results$$)}).catch($error$$=>{$callback$$($error$$)})})},hanmucton:$callback$$=>{setImmediate(()=>{const $c_dk$$={id_app:$id_app$$};$ma_kho$$&&($c_dk$$.ma_kho=$ma_kho$$);$ma_dvcs$$&&($c_dk$$.ma_dvcs=$ma_dvcs$$);$ma_vt$$&&($c_dk$$.ma_vt=$ma_vt$$);$condition$$.ma_lo&&($c_dk$$.ma_lo=$condition$$.ma_lo);$condition$$.han_sd&&
7
7
  ($c_dk$$.han_sd=$condition$$.han_sd);$condition$$.ma_tt1&&($c_dk$$.ma_tt1=$condition$$.ma_tt1);$condition$$.ma_tt2&&($c_dk$$.ma_tt2=$condition$$.ma_tt2);$condition$$.ma_tt3&&($c_dk$$.ma_tt3=$condition$$.ma_tt3);hanmucton.find($c_dk$$).lean().then($results$$=>{$callback$$(null,$results$$)}).catch($error$$=>{$callback$$($error$$)})})},ps:$callback$$=>{setImmediate(()=>{const $query$$={id_app:$id_app$$,ngay_ct:{$gte:$ngay_dn$$,$lte:$ngay$$}};$ma_kho$$&&($query$$.ma_kho=$ma_kho$$);$ma_dvcs$$&&($query$$.ma_dvcs=
8
8
  $ma_dvcs$$);$ma_vt$$&&($query$$.ma_vt=$ma_vt$$);$condition$$.ma_lo&&($query$$.ma_lo=$condition$$.ma_lo);$condition$$.han_sd&&($query$$.han_sd=$condition$$.han_sd);$condition$$.ma_tt1&&($query$$.ma_tt1=$condition$$.ma_tt1);$condition$$.ma_tt2&&($query$$.ma_tt2=$condition$$.ma_tt2);$condition$$.ma_tt3&&($query$$.ma_tt3=$condition$$.ma_tt3);$condition$$.id_ct&&($query$$.id_ct={$ne:$condition$$.id_ct});sokho.find($query$$,{ma_vt:1,ma_kho:1,ma_tt1:1,ma_tt2:1,ma_tt3:1,sl_nhap:1,sl_xuat:1,sl_nhap_qd:1,sl_xuat_qd:1,
9
- tien_nhap:1,tien_xuat:1}).lean().then($pss$$=>{$pss$$=$pss$$.map($ps$$=>{$ps$$.sl_nhap=utils.round($ps$$.sl_nhap_qd,4);$ps$$.sl_xuat=utils.round($ps$$.sl_xuat_qd,4);return $ps$$});$callback$$(null,$pss$$)}).catch($error$$=>{$callback$$($error$$)})})},ton_kho_mac_dinh:$callback$$=>{setImmediate(()=>{let $query$$={id_app:$id_app$$,ton_kho_mac_dinh:{$nin:[null,void 0,0]}};$ma_vt$$&&($query$$.ma_vt=$ma_vt$$);dmvt.find($query$$,{ma_vt:1,ton_kho_mac_dinh:1}).lean().then($rs$$=>{$callback$$(null,$rs$$)}).catch($error$$=>
10
- {console.error($error$$)})})}},($ckcapphat_error$$,$data_results$$)=>{if($ckcapphat_error$$)return $fn$$($ckcapphat_error$$),$reject$$(Error($ckcapphat_error$$));$ckcapphat_error$$=$data_results$$.ckcapphat.map($c$$=>{$c$$.ton00_capphat=$c$$.ton00;$c$$.du00_capphat=$c$$.du00;$c$$.ton00=0;$c$$.du00=0;return $c$$});$data_results$$=$data_results$$.dn.concat($data_results$$.ps).concat($ckcapphat_error$$).concat($data_results$$.ton_kho_mac_dinh).concat($data_results$$.hanmucton);($ckcapphat_error$$=$condition$$.groupBy||
11
- $condition$$.groupby)||($ckcapphat_error$$=["ma_vt"]);if(_.isString($ckcapphat_error$$))if($ckcapphat_error$$.indexOf("[")>=0)try{$ckcapphat_error$$=JSON.parse($ckcapphat_error$$)}catch($e$$){console.error($e$$)}else $ckcapphat_error$$=$ckcapphat_error$$.split(",");$data_results$$.groupBy($ckcapphat_error$$,"sl_nhap sl_xuat ton00 du00 ton00_capphat du00_capphat tien_nhap tien_xuat ton_kho_mac_dinh ton_toi_thieu ton_toi_da".split(" "),($e$$,$groups$$)=>{if($e$$)return $fn$$($e$$),$reject$$(Error($e$$));
12
- setImmediate(()=>{for(let $r$$ of $groups$$)$r$$.ton00=utils.round($r$$.ton00+$r$$.sl_nhap-$r$$.sl_xuat,4),$r$$.du00=Math.roundBy($r$$.du00,0)+Math.roundBy($r$$.tien_nhap,0)-Math.roundBy($r$$.tien_xuat,0),$r$$.sl_nhap=0,$r$$.sl_xuat=0,$r$$.tien_nhap=0,$r$$.tien_xuat=0,$r$$.ton=$r$$.ton00-($r$$.ton00_capphat>0?$r$$.ton00_capphat:0),$r$$.du=$r$$.du00-($r$$.du00_capphat>0?$r$$.du00_capphat:0);$fn$$(null,$groups$$);$resolve$$($groups$$)})})})})};
9
+ tien_nhap:1,tien_xuat:1}).inTxn().lean().then($pss$$=>{$pss$$=$pss$$.map($ps$$=>{$ps$$.sl_nhap=utils.round($ps$$.sl_nhap_qd,4);$ps$$.sl_xuat=utils.round($ps$$.sl_xuat_qd,4);return $ps$$});$callback$$(null,$pss$$)}).catch($error$$=>{$callback$$($error$$)})})},ton_kho_mac_dinh:$callback$$=>{setImmediate(()=>{let $query$$={id_app:$id_app$$,ton_kho_mac_dinh:{$nin:[null,void 0,0]}};$ma_vt$$&&($query$$.ma_vt=$ma_vt$$);dmvt.find($query$$,{ma_vt:1,ton_kho_mac_dinh:1}).lean().then($rs$$=>{$callback$$(null,
10
+ $rs$$)}).catch($error$$=>{console.error($error$$)})})}},($ckcapphat_error$$,$data_results$$)=>{if($ckcapphat_error$$)return $fn$$($ckcapphat_error$$),$reject$$(Error($ckcapphat_error$$));$ckcapphat_error$$=$data_results$$.ckcapphat.map($c$$=>{$c$$.ton00_capphat=$c$$.ton00;$c$$.du00_capphat=$c$$.du00;$c$$.ton00=0;$c$$.du00=0;return $c$$});$data_results$$=$data_results$$.dn.concat($data_results$$.ps).concat($ckcapphat_error$$).concat($data_results$$.ton_kho_mac_dinh).concat($data_results$$.hanmucton);
11
+ ($ckcapphat_error$$=$condition$$.groupBy||$condition$$.groupby)||($ckcapphat_error$$=["ma_vt"]);if(_.isString($ckcapphat_error$$))if($ckcapphat_error$$.indexOf("[")>=0)try{$ckcapphat_error$$=JSON.parse($ckcapphat_error$$)}catch($e$$){console.error($e$$)}else $ckcapphat_error$$=$ckcapphat_error$$.split(",");$data_results$$.groupBy($ckcapphat_error$$,"sl_nhap sl_xuat ton00 du00 ton00_capphat du00_capphat tien_nhap tien_xuat ton_kho_mac_dinh ton_toi_thieu ton_toi_da".split(" "),($e$$,$groups$$)=>{if($e$$)return $fn$$($e$$),
12
+ $reject$$(Error($e$$));setImmediate(()=>{for(let $r$$ of $groups$$)$r$$.ton00=utils.round($r$$.ton00+$r$$.sl_nhap-$r$$.sl_xuat,4),$r$$.du00=Math.roundBy($r$$.du00,0)+Math.roundBy($r$$.tien_nhap,0)-Math.roundBy($r$$.tien_xuat,0),$r$$.sl_nhap=0,$r$$.sl_xuat=0,$r$$.tien_nhap=0,$r$$.tien_xuat=0,$r$$.ton=$r$$.ton00-($r$$.ton00_capphat>0?$r$$.ton00_capphat:0),$r$$.du=$r$$.du00-($r$$.du00_capphat>0?$r$$.du00_capphat:0);$fn$$(null,$groups$$);$resolve$$($groups$$)})})})})};
@@ -1,6 +1,6 @@
1
1
  const sokhocapphat=global.getModel("sokhocapphat"),utils=require("./utils"),async=require("async"),underscore=require("underscore"),moment=require("moment");
2
2
  module.exports=function($condition$$,$fn$$){!$condition$$.ngay&&$condition$$.den_ngay&&($condition$$.ngay=$condition$$.den_ngay);let $ma_dvcs$$=$condition$$.ma_dvcs,$ma_kho$$=$condition$$.ma_kho,$ma_vt$$=$condition$$.ma_vt;$ma_vt$$&&underscore.isArray($ma_vt$$)&&($ma_vt$$={$in:Object.assign($ma_vt$$)});let $ngay$$=moment($condition$$.ngay).endOf("date").toDate(),$id_app$$=$condition$$.id_app;async.series({dn:$callback$$=>{$callback$$(null,[])},ps:$callback$$=>{const $query$$={id_app:$id_app$$,ngay_ct:{$lte:$ngay$$}};
3
- $ma_kho$$&&($query$$.ma_kho=$ma_kho$$);$ma_dvcs$$&&($query$$.ma_dvcs=$ma_dvcs$$);$ma_vt$$&&($query$$.ma_vt=$ma_vt$$);$condition$$.ma_lo&&($query$$.ma_lo=$condition$$.ma_lo);$condition$$.han_sd&&($query$$.han_sd=$condition$$.han_sd);$condition$$.ma_tt1&&($query$$.ma_tt1=$condition$$.ma_tt1);$condition$$.ma_tt2&&($query$$.ma_tt2=$condition$$.ma_tt2);$condition$$.ma_tt3&&($query$$.ma_tt3=$condition$$.ma_tt3);$condition$$.id_ct&&($query$$.id_ct={$ne:$condition$$.id_ct});sokhocapphat.find($query$$).lean().then(function($pss$$){$pss$$=
3
+ $ma_kho$$&&($query$$.ma_kho=$ma_kho$$);$ma_dvcs$$&&($query$$.ma_dvcs=$ma_dvcs$$);$ma_vt$$&&($query$$.ma_vt=$ma_vt$$);$condition$$.ma_lo&&($query$$.ma_lo=$condition$$.ma_lo);$condition$$.han_sd&&($query$$.han_sd=$condition$$.han_sd);$condition$$.ma_tt1&&($query$$.ma_tt1=$condition$$.ma_tt1);$condition$$.ma_tt2&&($query$$.ma_tt2=$condition$$.ma_tt2);$condition$$.ma_tt3&&($query$$.ma_tt3=$condition$$.ma_tt3);$condition$$.id_ct&&($query$$.id_ct={$ne:$condition$$.id_ct});sokhocapphat.find($query$$).inTxn().lean().then(function($pss$$){$pss$$=
4
4
  $pss$$.map($ps$$=>{$ps$$.sl_nhap=utils.round($ps$$.sl_nhap_qd,4);$ps$$.sl_xuat=utils.round($ps$$.sl_xuat_qd,4);return $ps$$});$callback$$(null,$pss$$)}).catch($error$$=>{$callback$$($error$$)})}},($data_error$$,$groupBy_results$$)=>{if($data_error$$)$fn$$($data_error$$);else{$data_error$$=$groupBy_results$$.dn.concat($groupBy_results$$.ps);($groupBy_results$$=$condition$$.groupBy)||($groupBy_results$$=["ma_vt"]);if(underscore.isString($groupBy_results$$))if($groupBy_results$$.indexOf("[")>=0)try{$groupBy_results$$=
5
5
  JSON.parse($groupBy_results$$)}catch($e$$){console.error($e$$)}else $groupBy_results$$=$groupBy_results$$.split(",");$data_error$$.groupBy($groupBy_results$$,"sl_nhap sl_xuat ton00 du00 tien_nhap tien_xuat".split(" "),($e$$,$groups$$)=>{if($e$$)return $fn$$($e$$);for(let $r$$ of $groups$$)$r$$.ton00=utils.round($r$$.ton00+$r$$.sl_nhap-$r$$.sl_xuat,4),$r$$.du00=Math.roundBy($r$$.du00,0)+Math.roundBy($r$$.tien_nhap,0)-Math.roundBy($r$$.tien_xuat,0),$r$$.sl_nhap=0,$r$$.sl_xuat=0,$r$$.tien_nhap=0,$r$$.tien_xuat=
6
6
  0;$fn$$(null,$groups$$)})}})};
@@ -8,16 +8,16 @@ $resolve$$($details$$)})};
8
8
  post.prototype.remove=function($callback$$=()=>{}){let $master$$=this.master;$master$$&&$master$$.toObject&&($master$$=$master$$.toObject());if(!$master$$._id)return $callback$$();let $query_delete$$={id_ct:$master$$._id.toString(),id_app:$master$$.id_app};this.options.queryDelete&&($query_delete$$={...$query_delete$$,...this.options.queryDelete,id_app:$master$$.id_app});async.series({sks:$callback$$=>{setImmediate(()=>{global.getModel("sokho").find({id_ct:$master$$._id.toString()}).lean().then(function($sks$$){$callback$$(null,$sks$$)}).catch($e$$=>
9
9
  {$callback$$($e$$)})})}},async($e$$,$rs$$)=>{if($e$$)return $callback$$($e$$);await global.getModel("sokho").deleteMany($query_delete$$);await global.getModel("sokhonpp").deleteMany($query_delete$$);await global.getModel("sokhokhongton").deleteMany($query_delete$$);$rs$$.sks.length>0&&tontucthoi.tinhTonTucThoi($rs$$.sks,$e$$=>{$e$$&&console.error("[post-sokho] T\u00ednh t\u1ed3n t\u1ee9c th\u1eddi sau khi xo\u00e1 sokho c\u1ee7a v\u1eadt t\u01b0",$e$$)});$callback$$()})};
10
10
  post.prototype.run=async function($callback$$=()=>{}){if(!this.details)return console.error("details not exists"),$callback$$(null);if(!this.master||!this.master._id)return console.error("masters not exists",this.master),$callback$$(null);let $master$$=this.master;$master$$.toObject&&($master$$=$master$$.toObject());let $details$$=await this.runPrepare(this.prepare,this.details);await $details$$.asyncJoinModel2($master$$.id_app,Dmvt,{where:"ma_vt",setFields:($item$$,$ref$$)=>{$item$$.tk_vt||($item$$.tk_vt=
11
- $ref$$.tk_vt);$item$$.tk_gv||($item$$.tk_gv=$ref$$.tk_gv);$item$$.tg_tk=$ref$$.tg_tk;$item$$.xk_nvl=$ref$$.xk_nvl}});if(($master$$.ma_ct||"").toUpperCase()!=="PKK"){var $ds_kho_kho_locked_ps_kg_dm_sp_co_dm_sp_xk_nvl$$=[...(new Set($details$$.map($d$$=>$d$$.ma_kho||$master$$.ma_kho)))];if($ds_kho_kho_locked_ps_kg_dm_sp_co_dm_sp_xk_nvl$$=await global.getModel("dmkho").findOne({id_app:$master$$.id_app,lock:!0,ma_kho:{$in:$ds_kho_kho_locked_ps_kg_dm_sp_co_dm_sp_xk_nvl$$}}).lean())return $callback$$(`Kho ${$ds_kho_kho_locked_ps_kg_dm_sp_co_dm_sp_xk_nvl$$.ten_kho} \u0111\u00e3 b\u1ecb kho\u00e1`)}$ds_kho_kho_locked_ps_kg_dm_sp_co_dm_sp_xk_nvl$$=
12
- $details$$.filter($p$$=>$p$$.xk_nvl&&$p$$.nxt==2);for(var $i$jscomp$1_i$$=0;$i$jscomp$1_i$$<$ds_kho_kho_locked_ps_kg_dm_sp_co_dm_sp_xk_nvl$$.length;$i$jscomp$1_i$$++)$ds_kho_kho_locked_ps_kg_dm_sp_co_dm_sp_xk_nvl$$[$i$jscomp$1_i$$].dinh_muc_nvl=await dinhmucsx($master$$.id_app,$ds_kho_kho_locked_ps_kg_dm_sp_co_dm_sp_xk_nvl$$[$i$jscomp$1_i$$].ma_vt,$ds_kho_kho_locked_ps_kg_dm_sp_co_dm_sp_xk_nvl$$[$i$jscomp$1_i$$].ma_tt1,$ds_kho_kho_locked_ps_kg_dm_sp_co_dm_sp_xk_nvl$$[$i$jscomp$1_i$$].sl_xuat,$ds_kho_kho_locked_ps_kg_dm_sp_co_dm_sp_xk_nvl$$[$i$jscomp$1_i$$].ma_dvt);
13
- $details$$=$details$$.filter($d$$=>$d$$.tg_tk||$d$$.dinh_muc_nvl&&$d$$.dinh_muc_nvl.length>0);$ds_kho_kho_locked_ps_kg_dm_sp_co_dm_sp_xk_nvl$$=$details$$.filter($p$$=>$p$$.xk_nvl&&$p$$.dinh_muc_nvl&&$p$$.dinh_muc_nvl.length>0);for($i$jscomp$1_i$$=0;$i$jscomp$1_i$$<$ds_kho_kho_locked_ps_kg_dm_sp_co_dm_sp_xk_nvl$$.length;$i$jscomp$1_i$$++){const $p$$=$ds_kho_kho_locked_ps_kg_dm_sp_co_dm_sp_xk_nvl$$[$i$jscomp$1_i$$];let $he_so_qd$$=1,$qd$$=await global.getModel("dmqddvt").findOne({id_app:$master$$.id_app,
14
- ma_vt:$p$$.ma_vt,ma_dvt:$p$$.ma_dvt}).lean();$qd$$&&($he_so_qd$$=$qd$$.mau?$qd$$.tu/$qd$$.mau:$qd$$.ty_le_qd);let $sl_sp$$=$p$$.sl_xuat*$he_so_qd$$;$p$$.dinh_muc_nvl=$p$$.dinh_muc_nvl.map($d$$=>{$d$$.nxt=$p$$.nxt;$d$$.ma_sp=$p$$.ma_vt;$d$$.sl_sp=$sl_sp$$;$d$$.ma_tt1_sp=$p$$.ma_tt1;$d$$.ma_tt2_sp=$p$$.ma_tt2;$d$$.ma_tt3_sp=$p$$.ma_tt3;$d$$.ma_kho=$p$$.ma_kho;return $d$$});$p$$.dinh_muc_nvl=$p$$.dinh_muc_nvl.filter($p$$=>$p$$.tg_tk)}$ds_kho_kho_locked_ps_kg_dm_sp_co_dm_sp_xk_nvl$$=$details$$.filter($p$$=>
15
- !$p$$.xk_nvl||!$p$$.dinh_muc_nvl||$p$$.dinh_muc_nvl.length===0);$i$jscomp$1_i$$=$details$$.filter($p$$=>$p$$.xk_nvl&&$p$$.dinh_muc_nvl&&$p$$.dinh_muc_nvl.length>0).map($p$$=>$p$$.dinh_muc_nvl).reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]);$details$$=[...$ds_kho_kho_locked_ps_kg_dm_sp_co_dm_sp_xk_nvl$$,...$i$jscomp$1_i$$];await $details$$.asyncJoinModel2($master$$.id_app,global.getModel("dmqddvt"),{where:{ma_vt:"ma_vt",ma_dvt:"ma_dvt"},fields:["tu","mau",{he_so_qd:"ty_le_qd"}]});$details$$.forEach($detail$$=>
16
- {$detail$$.ma_kho=$detail$$.ma_kho||$master$$.ma_kho;$detail$$.he_so_qd=$detail$$.he_so_qd||1;$detail$$.mau&&$detail$$.tu?($detail$$.he_so_qd=$detail$$.tu/$detail$$.mau,$detail$$.sl_xuat_qd=utils.round(($detail$$.sl_xuat||0)*$detail$$.tu/$detail$$.mau,round),$detail$$.sl_nhap_qd=utils.round(($detail$$.sl_nhap||0)*$detail$$.tu/$detail$$.mau,round)):($detail$$.sl_xuat_qd=utils.round(($detail$$.sl_xuat||0)*$detail$$.he_so_qd,round),$detail$$.sl_nhap_qd=utils.round(($detail$$.sl_nhap||0)*$detail$$.he_so_qd,
17
- round))});let $nam$$=(new Date($master$$.ngay_ct)).getFullYear(),$thang$$=(new Date($master$$.ngay_ct)).getMonth()+1;await new Promise($rs$$=>{async.map($details$$.filter($p$$=>$p$$.tg_tk&&($p$$.sl_xuat&&!$p$$.px_gia_dd||$p$$.sl_nhap&&$p$$.pn_gia_tb)&&$p$$.sl_xuat),($p$$,$callback$$)=>{setImmediate(async()=>{let $he_so_qd$$=1;var $giatb_qd$$=await global.getModel("dmqddvt").findOne({id_app:$master$$.id_app,ma_vt:$p$$.ma_vt,ma_dvt:$p$$.ma_dvt}).lean();$giatb_qd$$&&($he_so_qd$$=$giatb_qd$$.mau?$giatb_qd$$.tu/
18
- $giatb_qd$$.mau:$giatb_qd$$.ty_le_qd);$giatb_qd$$={ma_vt:$p$$.ma_vt,nam:$nam$$,thang:$thang$$,ma_kho:{$in:[$p$$.ma_kho,"",null]}};if($giatb_qd$$=await global.getModel("giatb").findOne($giatb_qd$$).sort({ma_kho:-1}).lean())$p$$.gia_von_nt=$p$$.gia_von=($giatb_qd$$.gia||0)*$he_so_qd$$,$p$$.tien_xuat_nt=$p$$.tien_xuat=($p$$.sl_xuat||0)*$p$$.gia_von_nt,$p$$.tien_nhap_nt=$p$$.tien_nhap=($p$$.sl_nhap||0)*$p$$.gia_von_nt,$callback$$();else{let $condition$$={id_app:$master$$.id_app,ma_vt:$p$$.ma_vt,ma_kho:$p$$.ma_kho};
19
- $condition$$.tu_ngay=moment($master$$.ngay_ct).startOf("month").toDate();$condition$$.den_ngay=moment($master$$.ngay_ct).endOf("month").toDate();tinhgiatb($condition$$,($e$$,$giatb$$)=>{$e$$&&console.error("[postSokho] Kh\u00f4ng th\u1ec3 t\u00ednh gi\u00e1 trung b\u00ecnh",$e$$.message||$e$$.error||$e$$,$condition$$);$p$$.gia_von_nt=$rs$$?$p$$.gia_von=($giatb$$.gia||0)*$he_so_qd$$:$p$$.gia_von=0;$p$$.tien_xuat_nt=$p$$.tien_xuat=($p$$.sl_xuat||0)*$p$$.gia_von_nt;$p$$.tien_nhap_nt=$p$$.tien_nhap=($p$$.sl_nhap||
20
- 0)*$p$$.gia_von_nt;$callback$$()})}})},()=>{$rs$$()})});$details$$=$details$$.map(($detail$$,$line$$)=>{$detail$$.id_ct=$master$$._id.toString();$detail$$.ma_ct=$master$$.ma_ct;$detail$$.so_ct=$master$$.so_ct;$detail$$.ngay_ct=$master$$.ngay_ct;for(let $attr$$ in global.getModel("sokho").schema.paths)if($attr$$!="id_ct"&&$attr$$!="_id"&&$attr$$!="__v"&&$attr$$!="date_updated"&&$attr$$!="date_created"){let $v$$=$detail$$[$attr$$];$v$$!==void 0&&$v$$!==null&&$v$$!==""||$v$$===0||$master$$[$attr$$]===
21
- void 0||($detail$$[$attr$$]=$master$$[$attr$$])}$detail$$.line=$line$$;delete $detail$$.toObject;delete $detail$$._id;delete $detail$$.__v;return $detail$$});await $details$$.asyncJoinModel2($master$$.id_app,"dmkho",{where:"ma_kho",fields:"la_kho_npp"});this.remove(async $error$$=>{if($error$$)return console.error("[postSokho] error delete data post",$error$$.message||$error$$.error||$error$$,$master$$.so_ct,$master$$.ma_ct),$callback$$($error$$);if($details$$.length==0)return $callback$$(null,[]);
22
- try{let $data_sokho$$=$details$$.filter($d$$=>$d$$.tg_tk&&!$d$$.la_kho_npp),$rs_sokho$$=await global.getModel("sokho").create($data_sokho$$),$data_sokhonpp$$=$details$$.filter($d$$=>$d$$.tg_tk&&$d$$.la_kho_npp),$rs_sokhnpp$$=await global.getModel("sokhonpp").create($data_sokhonpp$$),$data_sokhokhongton$$=$details$$.filter($d$$=>$d$$.tg_tk==0),$rs_sokhokhongton$$=await global.getModel("sokhokhongton").create($data_sokhokhongton$$);$callback$$(null,{rs_sokho:$rs_sokho$$,rs_sokhnpp:$rs_sokhnpp$$,rs_sokhokhongton:$rs_sokhokhongton$$});
23
- $rs_sokho$$&&setImmediate(()=>{tontucthoi.tinhTonTucThoi($rs_sokho$$,$e$$=>{$e$$&&console.error("L\u1ed7i t\u00ednh t\u1ed3n t\u1ee9c th\u1eddi v\u1eadt t\u01b0",$rs_sokho$$,$e$$.message||$e$$.error||$e$$,$master$$.so_ct,$master$$.ma_ct)})})}catch($e$$){console.error("[postSokho] \u0110\u00e3 c\u00f3 l\u1ed7i khi post sokho",$e$$),$callback$$($e$$)}})};module.exports=post;
11
+ $ref$$.tk_vt);$item$$.tk_gv||($item$$.tk_gv=$ref$$.tk_gv);$item$$.tg_tk=$ref$$.tg_tk;$item$$.xk_nvl=$ref$$.xk_nvl}});if(($master$$.ma_ct||"").toUpperCase()!=="PKK"){var $ds_kho_kho_locked_ps_kg_dm_sp_co_dm_sp_xk_nvl$$=[...(new Set($details$$.map($d$$=>$d$$.ma_kho||$master$$.ma_kho)))];if($ds_kho_kho_locked_ps_kg_dm_sp_co_dm_sp_xk_nvl$$=await global.getModel("dmkho").findOne({id_app:$master$$.id_app,lock:!0,ma_kho:{$in:$ds_kho_kho_locked_ps_kg_dm_sp_co_dm_sp_xk_nvl$$}}).lean())return $callback$$(`Kho ${$ds_kho_kho_locked_ps_kg_dm_sp_co_dm_sp_xk_nvl$$.ten_kho} \u0111\u00e3 b\u1ecb kho\u00e1`)}if(["HD2",
12
+ "SO1","PBL"].indexOf($master$$.ma_ct)>=0){$ds_kho_kho_locked_ps_kg_dm_sp_co_dm_sp_xk_nvl$$=$details$$.filter($p$$=>$p$$.xk_nvl&&$p$$.nxt==2);for(var $i$jscomp$1_i$$=0;$i$jscomp$1_i$$<$ds_kho_kho_locked_ps_kg_dm_sp_co_dm_sp_xk_nvl$$.length;$i$jscomp$1_i$$++)$ds_kho_kho_locked_ps_kg_dm_sp_co_dm_sp_xk_nvl$$[$i$jscomp$1_i$$].dinh_muc_nvl=await dinhmucsx($master$$.id_app,$ds_kho_kho_locked_ps_kg_dm_sp_co_dm_sp_xk_nvl$$[$i$jscomp$1_i$$].ma_vt,$ds_kho_kho_locked_ps_kg_dm_sp_co_dm_sp_xk_nvl$$[$i$jscomp$1_i$$].ma_tt1,
13
+ $ds_kho_kho_locked_ps_kg_dm_sp_co_dm_sp_xk_nvl$$[$i$jscomp$1_i$$].sl_xuat,$ds_kho_kho_locked_ps_kg_dm_sp_co_dm_sp_xk_nvl$$[$i$jscomp$1_i$$].ma_dvt)}$details$$=$details$$.filter($d$$=>$d$$.tg_tk||$d$$.dinh_muc_nvl&&$d$$.dinh_muc_nvl.length>0);$ds_kho_kho_locked_ps_kg_dm_sp_co_dm_sp_xk_nvl$$=$details$$.filter($p$$=>$p$$.xk_nvl&&$p$$.dinh_muc_nvl&&$p$$.dinh_muc_nvl.length>0);for($i$jscomp$1_i$$=0;$i$jscomp$1_i$$<$ds_kho_kho_locked_ps_kg_dm_sp_co_dm_sp_xk_nvl$$.length;$i$jscomp$1_i$$++){const $p$$=$ds_kho_kho_locked_ps_kg_dm_sp_co_dm_sp_xk_nvl$$[$i$jscomp$1_i$$];
14
+ let $he_so_qd$$=1,$qd$$=await global.getModel("dmqddvt").findOne({id_app:$master$$.id_app,ma_vt:$p$$.ma_vt,ma_dvt:$p$$.ma_dvt}).lean();$qd$$&&($he_so_qd$$=$qd$$.mau?$qd$$.tu/$qd$$.mau:$qd$$.ty_le_qd);let $sl_sp$$=$p$$.sl_xuat*$he_so_qd$$;$p$$.dinh_muc_nvl=$p$$.dinh_muc_nvl.map($d$$=>{$d$$.nxt=$p$$.nxt;$d$$.ma_sp=$p$$.ma_vt;$d$$.sl_sp=$sl_sp$$;$d$$.ma_tt1_sp=$p$$.ma_tt1;$d$$.ma_tt2_sp=$p$$.ma_tt2;$d$$.ma_tt3_sp=$p$$.ma_tt3;$d$$.ma_kho=$p$$.ma_kho;return $d$$});$p$$.dinh_muc_nvl=$p$$.dinh_muc_nvl.filter($p$$=>
15
+ $p$$.tg_tk)}$ds_kho_kho_locked_ps_kg_dm_sp_co_dm_sp_xk_nvl$$=$details$$.filter($p$$=>!$p$$.xk_nvl||!$p$$.dinh_muc_nvl||$p$$.dinh_muc_nvl.length===0);$i$jscomp$1_i$$=$details$$.filter($p$$=>$p$$.xk_nvl&&$p$$.dinh_muc_nvl&&$p$$.dinh_muc_nvl.length>0).map($p$$=>$p$$.dinh_muc_nvl).reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]);$details$$=[...$ds_kho_kho_locked_ps_kg_dm_sp_co_dm_sp_xk_nvl$$,...$i$jscomp$1_i$$];await $details$$.asyncJoinModel2($master$$.id_app,global.getModel("dmqddvt"),{where:{ma_vt:"ma_vt",
16
+ ma_dvt:"ma_dvt"},fields:["tu","mau",{he_so_qd:"ty_le_qd"}]});$details$$.forEach($detail$$=>{$detail$$.ma_kho=$detail$$.ma_kho||$master$$.ma_kho;$detail$$.he_so_qd=$detail$$.he_so_qd||1;$detail$$.mau&&$detail$$.tu?($detail$$.he_so_qd=$detail$$.tu/$detail$$.mau,$detail$$.sl_xuat_qd=utils.round(($detail$$.sl_xuat||0)*$detail$$.tu/$detail$$.mau,round),$detail$$.sl_nhap_qd=utils.round(($detail$$.sl_nhap||0)*$detail$$.tu/$detail$$.mau,round)):($detail$$.sl_xuat_qd=utils.round(($detail$$.sl_xuat||0)*$detail$$.he_so_qd,
17
+ round),$detail$$.sl_nhap_qd=utils.round(($detail$$.sl_nhap||0)*$detail$$.he_so_qd,round))});let $nam$$=(new Date($master$$.ngay_ct)).getFullYear(),$thang$$=(new Date($master$$.ngay_ct)).getMonth()+1;await new Promise($rs$$=>{async.map($details$$.filter($p$$=>$p$$.tg_tk&&($p$$.sl_xuat&&!$p$$.px_gia_dd||$p$$.sl_nhap&&$p$$.pn_gia_tb)&&$p$$.sl_xuat),($p$$,$callback$$)=>{setImmediate(async()=>{let $he_so_qd$$=1;var $giatb_qd$$=await global.getModel("dmqddvt").findOne({id_app:$master$$.id_app,ma_vt:$p$$.ma_vt,
18
+ ma_dvt:$p$$.ma_dvt}).lean();$giatb_qd$$&&($he_so_qd$$=$giatb_qd$$.mau?$giatb_qd$$.tu/$giatb_qd$$.mau:$giatb_qd$$.ty_le_qd);$giatb_qd$$={ma_vt:$p$$.ma_vt,nam:$nam$$,thang:$thang$$,ma_kho:{$in:[$p$$.ma_kho,"",null]}};if($giatb_qd$$=await global.getModel("giatb").findOne($giatb_qd$$).sort({ma_kho:-1}).lean())$p$$.gia_von_nt=$p$$.gia_von=($giatb_qd$$.gia||0)*$he_so_qd$$,$p$$.tien_xuat_nt=$p$$.tien_xuat=($p$$.sl_xuat||0)*$p$$.gia_von_nt,$p$$.tien_nhap_nt=$p$$.tien_nhap=($p$$.sl_nhap||0)*$p$$.gia_von_nt,
19
+ $callback$$();else{let $condition$$={id_app:$master$$.id_app,ma_vt:$p$$.ma_vt,ma_kho:$p$$.ma_kho};$condition$$.tu_ngay=moment($master$$.ngay_ct).startOf("month").toDate();$condition$$.den_ngay=moment($master$$.ngay_ct).endOf("month").toDate();tinhgiatb($condition$$,($e$$,$giatb$$)=>{$e$$&&console.error("[postSokho] Kh\u00f4ng th\u1ec3 t\u00ednh gi\u00e1 trung b\u00ecnh",$e$$.message||$e$$.error||$e$$,$condition$$);$p$$.gia_von_nt=$rs$$?$p$$.gia_von=($giatb$$.gia||0)*$he_so_qd$$:$p$$.gia_von=0;$p$$.tien_xuat_nt=
20
+ $p$$.tien_xuat=($p$$.sl_xuat||0)*$p$$.gia_von_nt;$p$$.tien_nhap_nt=$p$$.tien_nhap=($p$$.sl_nhap||0)*$p$$.gia_von_nt;$callback$$()})}})},()=>{$rs$$()})});$details$$=$details$$.map(($detail$$,$line$$)=>{$detail$$.id_ct=$master$$._id.toString();$detail$$.ma_ct=$master$$.ma_ct;$detail$$.so_ct=$master$$.so_ct;$detail$$.ngay_ct=$master$$.ngay_ct;for(let $attr$$ in global.getModel("sokho").schema.paths)if($attr$$!="id_ct"&&$attr$$!="_id"&&$attr$$!="__v"&&$attr$$!="date_updated"&&$attr$$!="date_created"){let $v$$=
21
+ $detail$$[$attr$$];$v$$!==void 0&&$v$$!==null&&$v$$!==""||$v$$===0||$master$$[$attr$$]===void 0||($detail$$[$attr$$]=$master$$[$attr$$])}$detail$$.line=$line$$;delete $detail$$.toObject;delete $detail$$._id;delete $detail$$.__v;return $detail$$});await $details$$.asyncJoinModel2($master$$.id_app,"dmkho",{where:"ma_kho",fields:"la_kho_npp"});this.remove(async $error$$=>{if($error$$)return console.error("[postSokho] error delete data post",$error$$.message||$error$$.error||$error$$,$master$$.so_ct,
22
+ $master$$.ma_ct),$callback$$($error$$);if($details$$.length==0)return $callback$$(null,[]);try{let $data_sokho$$=$details$$.filter($d$$=>$d$$.tg_tk&&!$d$$.la_kho_npp),$rs_sokho$$=await global.getModel("sokho").create($data_sokho$$),$data_sokhonpp$$=$details$$.filter($d$$=>$d$$.tg_tk&&$d$$.la_kho_npp),$rs_sokhnpp$$=await global.getModel("sokhonpp").create($data_sokhonpp$$),$data_sokhokhongton$$=$details$$.filter($d$$=>$d$$.tg_tk==0),$rs_sokhokhongton$$=await global.getModel("sokhokhongton").create($data_sokhokhongton$$);
23
+ $callback$$(null,{rs_sokho:$rs_sokho$$,rs_sokhnpp:$rs_sokhnpp$$,rs_sokhokhongton:$rs_sokhokhongton$$});$rs_sokho$$&&setImmediate(()=>{tontucthoi.tinhTonTucThoi($rs_sokho$$,$e$$=>{$e$$&&console.error("L\u1ed7i t\u00ednh t\u1ed3n t\u1ee9c th\u1eddi v\u1eadt t\u01b0",$rs_sokho$$,$e$$.message||$e$$.error||$e$$,$master$$.so_ct,$master$$.ma_ct)})})}catch($e$$){console.error("[postSokho] \u0110\u00e3 c\u00f3 l\u1ed7i khi post sokho",$e$$),$callback$$($e$$)}})};module.exports=post;
@@ -30,9 +30,9 @@ $d$$.gia_von,$f_tien$$),$d$$.tien_nhap=$d$$.tien_nhap_nt)})()));$voucher_n$$.ma_
30
30
  $detail$$.gia_von_nt=Math.roundBy($detail$$.sl_nhap?$detail$$.tien_nhap_nt/$detail$$.sl_nhap:0,$f_tien$$))})()));if($voucher_n$$.details_doi){const $details_doi$$=$voucher_n$$.details_doi.filter($d$$=>(!$condition$$.ma_vt||$condition$$.ma_vt===$d$$.ma_vt)&&$d$$.pn_gia_tb&&(!$ma_kho$$||$ma_kho$$===$d$$.ma_kho));await Promise.all($details_doi$$.map($d$$=>(async()=>{var $gia$jscomp$9_gia_chuan$$=_.find($bang_gia$$,$vt$$=>$d$$.ma_vt===$vt$$.ma_vt);$gia$jscomp$9_gia_chuan$$=$gia$jscomp$9_gia_chuan$$?$gia$jscomp$9_gia_chuan$$.gia:
31
31
  0;let $he_so_qd$$=1,$qd$$=await dmqddvt.findOne({id_app:$vouchers_n$$.id_app,ma_vt:$d$$.ma_vt,ma_dvt:$d$$.ma_dvt}).lean();$qd$$&&($he_so_qd$$=$qd$$.mau?$qd$$.tu/$qd$$.mau:$qd$$.ty_le_qd);$d$$.gia_von_nt=$gia$jscomp$9_gia_chuan$$*$he_so_qd$$;$d$$.gia_von=$d$$.gia_von_nt;$d$$.tien_xuat_nt=Math.roundBy($d$$.sl_xuat*$d$$.gia_von,$f_tien$$);$d$$.tien_xuat=$d$$.tien_xuat_nt})()))}let $voucher_n_data$$=$voucher_n$$.toObject();const $ctrl$$=global.controllers[$voucher_n_data$$.ma_ct.toUpperCase()];await ($ctrl$$?
32
32
  $ctrl$$.getProperty("model"):mongoose.models[$voucher_n_data$$.ma_ct.toLowerCase()]).updateOne({_id:$voucher_n_data$$._id},$voucher_n_data$$);$ctrl$$&&$ctrl$$.post&&await new Promise(($resolve$$,$reject$$)=>{Controller.postData($voucher_n_data$$,$ctrl$$,function($e$$,$rs$$){if($e$$)return console.error("\u274c [tinhgiatb][postData] l\u1ed7i:",$e$$.message,$voucher_n_data$$.so_ct,$voucher_n_data$$.ma_ct),$reject$$($e$$);$resolve$$($rs$$)},{kiem_tra_han_muc_cong_no:!1})});$callback$$(null,$voucher_n$$)}catch($e$$){console.error("\u274c [tinhgiatb] L\u1ed7i c\u1eadp nh\u1ea5t phi\u1ebfu nh\u1eadp",
33
- $voucher_n$$.ma_ct,$voucher_n$$.so_ct,$e$$.error||$e$$.message||$e$$),$callback$$($e$$)}})},function($error$$){$callback$$($error$$)})}],function($e$$){if($e$$)return $fn$$($e$$);console.log("[tinhgiatb] \u0110\u00e1nh gi\u00e1 ch\u00eanh l\u1ec7ch...");$e$$={id_app:$condition$$.id_app,ngay:$den_ngay$$,chenh_lech:1};$condition$$.ma_vt&&($e$$.ma_vt=$condition$$.ma_vt);$condition$$.ma_kho&&($e$$.ma_kho=$condition$$.ma_kho);ckvt($e$$,($e$$,$rs$$)=>{if($e$$)return $fn$$($e$$);$rs$$=_.filter($rs$$,$r$$=>
34
- $r$$.du00!==0&&($r$$.ton00==0||Math.abs($r$$.ton00)<.001));$vouchers_x$$=_.sortBy(_.values($vouchers_x$$),$v$$=>-(new Date($v$$.ngay_ct)).getTime());$vouchers_n$$=_.sortBy(_.values($vouchers_n$$),$v$$=>-(new Date($v$$.ngay_ct)).getTime());let $chung_tu_cap_nhat_chenh_lech$$={};async.map($rs$$,($vt$$,$callback$$)=>{setImmediate(()=>{let $d_voucher$$=null;($d_voucher$$=_.find($vouchers_x$$,$x$$=>_.find($x$$.details,$vc$$=>{if($vc$$.ma_vt!=$vt$$.ma_vt||$vc$$.px_gia_dd||$ma_kho$$&&$ma_kho$$!==$vc$$.ma_kho&&
35
- $ma_kho$$!==$x$$.ma_kho)return!1;$vc$$.tien_xuat_nt+=$vt$$.du00;$vc$$.tien_xuat=Math.roundBy($vc$$.tien_xuat_nt,$f_tien$$);$vc$$.sl_xuat&&($vc$$.gia_von_nt=$vc$$.gia_von=Math.roundBy($vc$$.tien_xuat_nt/$vc$$.sl_xuat,0));return!0})))||($d_voucher$$=_.find($vouchers_n$$,$n$$=>_.find($n$$.details,$vc$$=>{if($vc$$.ma_vt!=$vt$$.ma_vt||$vc$$.pn_gia_tb||$ma_kho$$&&$ma_kho$$!==$vc$$.ma_kho&&$ma_kho$$!==$n$$.ma_kho)return!1;$vc$$.tien_nhap_nt-=$vt$$.du00;$vc$$.tien_nhap=Math.roundBy($vc$$.tien_nhap_nt,$f_tien$$);
36
- $vc$$.sl_nhap&&($vc$$.gia_von_nt=$vc$$.gia_von=Math.roundBy($vc$$.tien_nhap_nt/$vc$$.sl_nhap,0));return!0})));$d_voucher$$&&($chung_tu_cap_nhat_chenh_lech$$[$d_voucher$$._id.toString()]=$d_voucher$$);$callback$$(null,$d_voucher$$)})},$_vouchers_chenh_lech_e$$=>{if($_vouchers_chenh_lech_e$$)return $fn$$($_vouchers_chenh_lech_e$$);$_vouchers_chenh_lech_e$$=_.values($chung_tu_cap_nhat_chenh_lech$$);console.log("[tinhgiatb] C\u1eadp nh\u1eadt phi\u1ebfu ch\u00eanh l\u1ec7ch...");async.map($_vouchers_chenh_lech_e$$,
37
- ($voucher$$,$callback$$)=>{setImmediate(async()=>{try{let $voucher_data$$=$voucher$$.toObject();const $ctrl$$=global.controllers[$voucher_data$$.ma_ct.toUpperCase()];await ($ctrl$$?$ctrl$$.getProperty("model"):mongoose.models[$voucher_data$$.ma_ct.toLowerCase()]).updateOne({_id:$voucher_data$$._id},$voucher_data$$);$ctrl$$&&$ctrl$$.post?Controller.postData($voucher_data$$,$ctrl$$,($e$$,$rs$$)=>{$e$$&&console.error("\u274c [tinhgiatb] [postData] L\u1ed7i:",$e$$.message,$voucher_data$$.so_ct,$voucher_data$$.ma_ct);
38
- $callback$$($e$$,$rs$$)},{kiem_tra_han_muc_cong_no:!1}):$callback$$(null)}catch($error$$){return $callback$$($error$$)}})},async $e$$=>{if($e$$)return $fn$$($e$$);$bang_gia$$.joinModel2($id_app$$,dmvt,[{where:"ma_vt",fields:"ten_vt"}],()=>{$fn$$(null,$bang_gia$$)})})})})})})})})}).catch($e$$=>{$fn$$($e$$)})}else $fn$$("L\u1ed7i: T\u00ednh n\u0103ng n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: tu_thang,den_thang,nam,id_app")};
33
+ $voucher_n$$.ma_ct,$voucher_n$$.so_ct,$e$$.error||$e$$.message||$e$$),$callback$$($e$$)}})},function($error$$){$callback$$($error$$)})}],function($e$$){if($e$$)return $fn$$($e$$);console.log("[tinhgiatb] \u0110\u00e1nh gi\u00e1 ch\u00eanh l\u1ec7ch...");$e$$={id_app:$condition$$.id_app,ngay:$den_ngay$$,chenh_lech:1};$condition$$.ma_vt&&($e$$.ma_vt=$condition$$.ma_vt);$condition$$.ma_kho&&($e$$.ma_kho=$condition$$.ma_kho);ckvt($e$$,($e$$,$du_cuoi_ky$$)=>{if($e$$)return $fn$$($e$$);$du_cuoi_ky$$=_.filter($du_cuoi_ky$$,
34
+ $r$$=>$r$$.du00!==0&&($r$$.ton00==0||Math.abs($r$$.ton00)<.001));$vouchers_x$$=_.sortBy(_.values($vouchers_x$$),$v$$=>-(new Date($v$$.ngay_ct)).getTime());$vouchers_n$$=_.sortBy(_.values($vouchers_n$$),$v$$=>-(new Date($v$$.ngay_ct)).getTime());let $chung_tu_cap_nhat_chenh_lech$$={};async.map($du_cuoi_ky$$,($vt$$,$callback$$)=>{setImmediate(()=>{let $d_voucher$$=null;($d_voucher$$=_.find($vouchers_x$$,$x$$=>_.find($x$$.details,$vc$$=>{if($vc$$.ma_vt!=$vt$$.ma_vt||$vc$$.px_gia_dd||$ma_kho$$&&$ma_kho$$!==
35
+ $vc$$.ma_kho&&$ma_kho$$!==$x$$.ma_kho)return!1;$vc$$.tien_xuat_nt+=$vt$$.du00;$vc$$.tien_xuat=Math.roundBy($vc$$.tien_xuat_nt,$f_tien$$);$vc$$.sl_xuat&&($vc$$.gia_von_nt=$vc$$.gia_von=Math.roundBy($vc$$.tien_xuat_nt/$vc$$.sl_xuat,0));return!0})))||($d_voucher$$=_.find($vouchers_n$$,$n$$=>_.find($n$$.details,$vc$$=>{if($vc$$.ma_vt!=$vt$$.ma_vt||$vc$$.pn_gia_tb||$ma_kho$$&&$ma_kho$$!==$vc$$.ma_kho&&$ma_kho$$!==$n$$.ma_kho)return!1;$vc$$.tien_nhap_nt-=$vt$$.du00;$vc$$.tien_nhap=Math.roundBy($vc$$.tien_nhap_nt,
36
+ $f_tien$$);$vc$$.sl_nhap&&($vc$$.gia_von_nt=$vc$$.gia_von=Math.roundBy($vc$$.tien_nhap_nt/$vc$$.sl_nhap,0));return!0})));$d_voucher$$&&($chung_tu_cap_nhat_chenh_lech$$[$d_voucher$$._id.toString()]=$d_voucher$$);$callback$$(null,$d_voucher$$)})},$_vouchers_chenh_lech_e$$=>{if($_vouchers_chenh_lech_e$$)return $fn$$($_vouchers_chenh_lech_e$$);$_vouchers_chenh_lech_e$$=_.values($chung_tu_cap_nhat_chenh_lech$$);console.log("\u26a0\ufe0f [tinhgiatb] C\u1eadp nh\u1eadt phi\u1ebfu ch\u00eanh l\u1ec7ch...",
37
+ $_vouchers_chenh_lech_e$$.length);async.map($_vouchers_chenh_lech_e$$,($voucher$$,$callback$$)=>{setImmediate(async()=>{try{let $voucher_data$$=$voucher$$.toObject();const $ctrl$$=global.controllers[$voucher_data$$.ma_ct.toUpperCase()];await ($ctrl$$?$ctrl$$.getProperty("model"):mongoose.models[$voucher_data$$.ma_ct.toLowerCase()]).updateOne({_id:$voucher_data$$._id},$voucher_data$$);$ctrl$$&&$ctrl$$.post?Controller.postData($voucher_data$$,$ctrl$$,($e$$,$rs$$)=>{$e$$&&console.error("\u274c [tinhgiatb] [postData] L\u1ed7i:",
38
+ $e$$.message,$voucher_data$$.so_ct,$voucher_data$$.ma_ct);$callback$$($e$$,$rs$$)},{kiem_tra_han_muc_cong_no:!1}):$callback$$(null)}catch($error$$){return $callback$$($error$$)}})},async $e$$=>{if($e$$)return $fn$$($e$$);$bang_gia$$.joinModel2($id_app$$,dmvt,[{where:"ma_vt",fields:"ten_vt"}],()=>{$fn$$(null,$bang_gia$$)})})})})})})})})}).catch($e$$=>{$fn$$($e$$)})}else $fn$$("L\u1ed7i: T\u00ednh n\u0103ng n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: tu_thang,den_thang,nam,id_app")};
@@ -64,20 +64,21 @@ $emails$$=[$rq$$.user_request],$rqs$$=$requests$$.map($a$$=>$a$$.user_request),$
64
64
  await File.find({id_link:$rq$$.data._id}).lean():void 0},null,$emails$$,!0,!0)}catch($e$$){console.error("Error send email",$e$$.message)}}).catch($e$$=>{console.error($e$$)}):console.log("don't find email template or report template to send notify email to request user")}).catch($e$$=>{console.error($e$$)})}};
65
65
  model.approve=async function($encrypted$$,$callback$$,$token$$,$options$$={reason:""}){try{const $result_approve$$=await executeInTransaction(async()=>{console.log("[approve] \u0111ang duy\u1ec7t y\u00eau c\u1ea7u....");let $user_approved$$;if(underscore.isObject($encrypted$$)){var $_c$$=$encrypted$$.id_request;$user_approved$$=$encrypted$$.email;var $approve_user_approved_name$$=$encrypted$$.name;var $key_data_trang_thai$$=$encrypted$$.trang_thai}else $key_data_trang_thai$$=utils.decrypt($encrypted$$),
66
66
  $_c$$=$key_data_trang_thai$$.id_request,$user_approved$$=$key_data_trang_thai$$.email,$approve_user_approved_name$$=$key_data_trang_thai$$.name,$key_data_trang_thai$$=$key_data_trang_thai$$.trang_thai;if(!$_c$$||!$user_approved$$)throw"request id and approve user are required";if(!global.mongoose.Types.ObjectId.isValid($_c$$))throw"request id '"+$_c$$+"' is not valid";$_c$$={_id:$_c$$};$key_data_trang_thai$$!==void 0&&$key_data_trang_thai$$!==null&&($_c$$.trang_thai=$key_data_trang_thai$$);const $rq$$=
67
- await model.findOne($_c$$);if($rq$$.date_approved)throw"Y\u00eau c\u1ea7u n\u00e0y \u0111\u00e3 \u0111\u01b0\u1ee3c duy\u1ec7t b\u1edfi "+$rq$$.user_approved_name;if($rq$$.date_denied)throw"Y\u00eau c\u1ea7u n\u00e0y \u0111\u00e3 b\u1ecb t\u1eeb ch\u1ed1i duy\u1ec7t b\u1edfi "+$rq$$.user_denied_name;$rq$$.date_approved=new Date;$rq$$.user_approved=$user_approved$$;$rq$$.user_approved_name=$approve_user_approved_name$$;$rq$$.approved_reason=$options$$.reason||"";if(!$rq$$.user_approves||!$rq$$.user_approves.find($u$$=>
68
- $u$$.email.indexOf($user_approved$$)>=0))throw"User n\u00e0y kh\u00f4ng c\u00f3 quy\u1ec1n duy\u1ec7t y\u00eau c\u1ea7u n\u00e0y";$approve_user_approved_name$$=await $rq$$.save();if($rq$$.update_after_approve&&$rq$$.update_after_approve.data){console.log("[approve] t\u00ecm controller c\u1ee7a ch\u1ee9ng t\u1eeb \u0111\u00e3 duy\u1ec7t",$rq$$.update_after_approve.module||$rq$$.update_after_approve.model);let $module_name$$=$rq$$.update_after_approve.module||$rq$$.update_after_approve.model,$ctrl$$;
69
- $module_name$$&&($ctrl$$=global.controllers[$module_name$$.toUpperCase()]);let $_m$$;$rq$$.update_after_approve.model?$_m$$=global.getModel($rq$$.update_after_approve.model):$ctrl$$&&($_m$$=$ctrl$$.getProperty("model"));if(!$_m$$){console.error("[approve] kh\u00f4ng t\u00ecm th\u1ea5y model c\u1ee7a ch\u1ee9ng t\u1eeb",$rq$$.update_after_approve.model||$module_name$$.toUpperCase());return}console.log("[approve] c\u1eadp nh\u1eadt data cho ch\u1ee9ng t\u1eeb sau khi duy\u1ec7t...",$module_name$$);
70
- await $_m$$.updateOne({_id:$rq$$.id_ct},$rq$$.update_after_approve.data);if($ctrl$$){const $obj$$=await $_m$$.findOne({_id:$rq$$.id_ct});if($obj$$){onAfterCommit(()=>{$ctrl$$.emit("saved",$obj$$);$ctrl$$.emit("updated",$obj$$)});const $u$$=await global.getModel("user").findOne({email:$user_approved$$});$u$$.current_id_app=$obj$$.id_app;const $app_info$$=await App.findOne({_id:$obj$$.id_app});console.log("[approve] post s\u1ed5 s\u00e1ch sau khi duy\u1ec7t ch\u1ee9ng t\u1eeb...",$ctrl$$.name,$module_name$$,
71
- $obj$$.so_ct,$obj$$.trang_thai);await new Promise(($resolve$$,$reject$$)=>{$ctrl$$.postData($obj$$,$e$$=>{if($e$$)return console.error("[approve] [postData]",$e$$,$module_name$$,$obj$$.so_ct,$obj$$.trang_thai),$reject$$($e$$);$resolve$$()},{kiem_tra_han_muc_cong_no:!1})});$ctrl$$.handleAfterAproved&&await $ctrl$$.handleAfterAproved($obj$$,$rq$$);await new Promise(($resolve$$,$reject$$)=>{$ctrl$$.onView($u$$,[$obj$$.toObject()],async($channel_e$$,$rs$$)=>{$channel_e$$&&console.error("[approve][approved][onView]",
67
+ await model.findOne($_c$$);if(!$rq$$)throw"Y\u00eau c\u1ea7u kh\u00f4ng t\u1ed3n t\u1ea1i";if($rq$$.date_approved)throw"Y\u00eau c\u1ea7u n\u00e0y \u0111\u00e3 \u0111\u01b0\u1ee3c duy\u1ec7t b\u1edfi "+$rq$$.user_approved_name;if($rq$$.date_denied)throw"Y\u00eau c\u1ea7u n\u00e0y \u0111\u00e3 b\u1ecb t\u1eeb ch\u1ed1i duy\u1ec7t b\u1edfi "+$rq$$.user_denied_name;$rq$$.date_approved=new Date;$rq$$.user_approved=$user_approved$$;$rq$$.user_approved_name=$approve_user_approved_name$$;$rq$$.approved_reason=
68
+ $options$$.reason||"";if(!$rq$$.user_approves||!$rq$$.user_approves.find($u$$=>$u$$.email.indexOf($user_approved$$)>=0))throw"User n\u00e0y kh\u00f4ng c\u00f3 quy\u1ec1n duy\u1ec7t y\u00eau c\u1ea7u n\u00e0y";$approve_user_approved_name$$=await $rq$$.save();if($rq$$.update_after_approve&&$rq$$.update_after_approve.data){console.log("[approve] t\u00ecm controller c\u1ee7a ch\u1ee9ng t\u1eeb \u0111\u00e3 duy\u1ec7t",$rq$$.update_after_approve.module||$rq$$.update_after_approve.model);let $module_name$$=
69
+ $rq$$.update_after_approve.module||$rq$$.update_after_approve.model,$ctrl$$;$module_name$$&&($ctrl$$=global.controllers[$module_name$$.toUpperCase()]);let $_m$$;$rq$$.update_after_approve.model?$_m$$=global.getModel($rq$$.update_after_approve.model):$ctrl$$&&($_m$$=$ctrl$$.getProperty("model"));if(!$_m$$){console.error("[approve] kh\u00f4ng t\u00ecm th\u1ea5y model c\u1ee7a ch\u1ee9ng t\u1eeb",$rq$$.update_after_approve.model||$module_name$$.toUpperCase());return}console.log("[approve] c\u1eadp nh\u1eadt data cho ch\u1ee9ng t\u1eeb sau khi duy\u1ec7t...",
70
+ $module_name$$);await $_m$$.updateOne({_id:$rq$$.id_ct},$rq$$.update_after_approve.data);if($ctrl$$){const $obj$$=await $_m$$.findOne({_id:$rq$$.id_ct});if($obj$$){onAfterCommit(()=>{$ctrl$$.emit("saved",$obj$$);$ctrl$$.emit("updated",$obj$$)});const $u$$=await global.getModel("user").findOne({email:$user_approved$$});$u$$.current_id_app=$obj$$.id_app;const $app_info$$=await App.findOne({_id:$obj$$.id_app});console.log("[approve] post s\u1ed5 s\u00e1ch sau khi duy\u1ec7t ch\u1ee9ng t\u1eeb...",$ctrl$$.name,
71
+ $module_name$$,$obj$$.so_ct,$obj$$.trang_thai);await new Promise(($resolve$$,$reject$$)=>{$ctrl$$.postData($obj$$,$e$$=>{if($e$$)return console.error("[approve] [postData]",$e$$,$module_name$$,$obj$$.so_ct,$obj$$.trang_thai),$reject$$($e$$);$resolve$$()},{kiem_tra_han_muc_cong_no:!1})});$ctrl$$.handleAfterAproved&&await $ctrl$$.handleAfterAproved($obj$$,$rq$$);await new Promise(($resolve$$,$reject$$)=>{$ctrl$$.onView($u$$,[$obj$$.toObject()],async($channel_e$$,$rs$$)=>{$channel_e$$&&console.error("[approve][approved][onView]",
72
72
  $channel_e$$);$channel_e$$=`${$module_name$$.toLowerCase()}-${"request_approved"}`;$obj$$.id_app&&($channel_e$$=`${$channel_e$$}-${$obj$$.id_app}`);let $message$$=JSON.stringify($rs$$[0]);try{await global.clientRedis.publish($channel_e$$,$message$$)}catch($e$$){console.error("[approve] [sendNotifyApproved] fire event","request_approved",$e$$)}console.log("[approve][approved][requestApprove] t\u1ea1o y\u00eau c\u1ea7u duy\u1ec7t ti\u1ebfp theo...");$ctrl$$.requestApprove($app_info$$,$u$$,$rs$$[0],
73
73
  $e$$=>{if($e$$)return $reject$$($e$$);$resolve$$()},null,$rq$$)})})}else console.error("[approve] kh\u00f4ng tim th\u1ea5y l\u1ed7i data \u0111\u00e3 duy\u1ec7t theo id_ct",$rq$$.id_ct)}else console.error("[approve] kh\u00f4ng t\u00ecm th\u1ea5y controller c\u1ee7a ch\u1ee9ng t\u1eeb",$module_name$$)}else console.log("[approve] kh\u00f4ng c\u00f3 d\u1eef li\u1ec7u c\u1ea7n c\u1eadp nh\u1eadt sau khi \u0111\u00e3 duy\u1ec7t");onAfterCommit(()=>{model.sendNotifyApproved($rq$$,$token$$)});return $approve_user_approved_name$$});
74
74
  $callback$$(null,$result_approve$$)}catch($e$$){console.error("[approve][approved]",$e$$),$callback$$($e$$)}};
75
75
  model.deny=async function($encrypted$$,$callback$$,$token$$,$options$$={reason:""}){try{const $result_reject$$=await executeInTransaction(async()=>{let $user_denied$$;if(underscore.isObject($encrypted$$)){var $_c$jscomp$2__id$$=$encrypted$$.id_request;$user_denied$$=$encrypted$$.email;var $approve$$=$encrypted$$.name;var $key_data$jscomp$1_trang_thai$$=$encrypted$$.trang_thai}else $key_data$jscomp$1_trang_thai$$=utils.decrypt($encrypted$$),$_c$jscomp$2__id$$=$key_data$jscomp$1_trang_thai$$.id_request,
76
76
  $user_denied$$=$key_data$jscomp$1_trang_thai$$.email,$approve$$=$key_data$jscomp$1_trang_thai$$.name,$key_data$jscomp$1_trang_thai$$=$key_data$jscomp$1_trang_thai$$.trang_thai;if(!$_c$jscomp$2__id$$||!$user_denied$$)throw"request id and deny user are required";if(!global.mongoose.Types.ObjectId.isValid($_c$jscomp$2__id$$))throw"request id '"+$_c$jscomp$2__id$$+"' is not valid";$_c$jscomp$2__id$$={_id:$_c$jscomp$2__id$$};$key_data$jscomp$1_trang_thai$$!==void 0&&$key_data$jscomp$1_trang_thai$$!==null&&
77
- ($_c$jscomp$2__id$$.trang_thai=$key_data$jscomp$1_trang_thai$$);const $rq$$=await model.findOne($_c$jscomp$2__id$$);if($rq$$.date_approved)throw"Y\u00eau c\u1ea7u n\u00e0y \u0111\u00e3 \u0111\u01b0\u1ee3c duy\u1ec7t b\u1edfi "+$rq$$.user_approved_name;if($rq$$.date_denied)throw"Y\u00eau c\u1ea7u n\u00e0y \u0111\u00e3 b\u1ecb t\u1eeb ch\u1ed1i duy\u1ec7t b\u1edfi "+$rq$$.user_denied_name;$rq$$.date_denied=new Date;$rq$$.user_denied=$user_denied$$;$rq$$.user_denied_name=$approve$$;$rq$$.denied_reason=
78
- $options$$.reason||"";if(!$rq$$.user_approves||!$rq$$.user_approves.find($u$$=>$u$$.email.indexOf($user_denied$$)>=0))throw"User n\u00e0y kh\u00f4ng c\u00f3 quy\u1ec1n duy\u1ec7t y\u00eau c\u1ea7u n\u00e0y";$approve$$=await $rq$$.save();onAfterCommit(async()=>{let $title$$=`[B\u1ecb t\u1eeb ch\u1ed1i] ${$rq$$.title}`;var $option$jscomp$2_template$$=await Options.findOne({id_app:$rq$$.id_app,id_func:{$regex:"^"+$rq$$.ma_ct+"$",$options:"i"}}).lean();if($rq$$.template_content||$option$jscomp$2_template$$&&
79
- $option$jscomp$2_template$$.option&&$option$jscomp$2_template$$.option.system&&($option$jscomp$2_template$$.option.system.templateEmail||$option$jscomp$2_template$$.option.system.templateRpt)){var $_data$jscomp$3_app_info$$=await App.findOne({_id:$rq$$.id_app}).lean();if(!$_data$jscomp$3_app_info$$)return console.log("khong the tim thay thong tin cong ty nay");let $requests$$=await model.find({id_ct:$rq$$.data._id}).sort({trang_thai:-1}).lean();await $requests$$.asyncJoinModel2($rq$$.id_app,participant,
80
- {where:{user_approved:"email"},fields:{user_approved_name:"name"}});await $requests$$.asyncJoinModel2($rq$$.id_app,participant,{where:{user_denied:"email"},fields:{user_denied_name:"name"}});$option$jscomp$2_template$$=($rq$$.template_content||(($option$jscomp$2_template$$.option||{}).system||{}).templateEmail||(($option$jscomp$2_template$$.option||{}).system||{}).templateRpt).split("<em>").join("").split("</em>").join("");$option$jscomp$2_template$$=`
77
+ ($_c$jscomp$2__id$$.trang_thai=$key_data$jscomp$1_trang_thai$$);const $rq$$=await model.findOne($_c$jscomp$2__id$$);if(!$rq$$)throw"Y\u00eau c\u1ea7u kh\u00f4ng t\u1ed3n t\u1ea1i";if($rq$$.date_approved)throw"Y\u00eau c\u1ea7u n\u00e0y \u0111\u00e3 \u0111\u01b0\u1ee3c duy\u1ec7t b\u1edfi "+$rq$$.user_approved_name;if($rq$$.date_denied)throw"Y\u00eau c\u1ea7u n\u00e0y \u0111\u00e3 b\u1ecb t\u1eeb ch\u1ed1i duy\u1ec7t b\u1edfi "+$rq$$.user_denied_name;$rq$$.date_denied=new Date;$rq$$.user_denied=$user_denied$$;
78
+ $rq$$.user_denied_name=$approve$$;$rq$$.denied_reason=$options$$.reason||"";if(!$rq$$.user_approves||!$rq$$.user_approves.find($u$$=>$u$$.email.indexOf($user_denied$$)>=0))throw"User n\u00e0y kh\u00f4ng c\u00f3 quy\u1ec1n duy\u1ec7t y\u00eau c\u1ea7u n\u00e0y";$approve$$=await $rq$$.save();onAfterCommit(async()=>{let $title$$=`[B\u1ecb t\u1eeb ch\u1ed1i] ${$rq$$.title}`;var $option$jscomp$2_template$$=await Options.findOne({id_app:$rq$$.id_app,id_func:{$regex:"^"+$rq$$.ma_ct+"$",$options:"i"}}).lean();
79
+ if($rq$$.template_content||$option$jscomp$2_template$$&&$option$jscomp$2_template$$.option&&$option$jscomp$2_template$$.option.system&&($option$jscomp$2_template$$.option.system.templateEmail||$option$jscomp$2_template$$.option.system.templateRpt)){var $_data$jscomp$3_app_info$$=await App.findOne({_id:$rq$$.id_app}).lean();if(!$_data$jscomp$3_app_info$$)return console.log("khong the tim thay thong tin cong ty nay");let $requests$$=await model.find({id_ct:$rq$$.data._id}).sort({trang_thai:-1}).lean();
80
+ await $requests$$.asyncJoinModel2($rq$$.id_app,participant,{where:{user_approved:"email"},fields:{user_approved_name:"name"}});await $requests$$.asyncJoinModel2($rq$$.id_app,participant,{where:{user_denied:"email"},fields:{user_denied_name:"name"}});$option$jscomp$2_template$$=($rq$$.template_content||(($option$jscomp$2_template$$.option||{}).system||{}).templateEmail||(($option$jscomp$2_template$$.option||{}).system||{}).templateRpt).split("<em>").join("").split("</em>").join("");$option$jscomp$2_template$$=
81
+ `
81
82
  <div>
82
83
  <h3>Y\u00eau c\u1ea7u d\u01b0\u1edbi \u0111\u00e2y \u0111\u00e3 b\u1ecb t\u1eeb ch\u1ed1i duy\u1ec7t b\u1edfi ${$rq$$.user_denied_name} </h3>
83
84
  <div style='color:red'>L\u00fd do t\u1eeb ch\u1ed1i: ${$rq$$.denied_reason} </div>
@@ -1,9 +1,9 @@
1
1
  const moment=require("moment"),validVt=require("../libs/validator-vt"),validator=require("../libs/validator"),detailSchema=new Schema({ma_vt:{type:String,required:!0,uppercase:!0,maxlength:1024,trim:!0},ma_dvt:{type:String,required:!0,maxlength:32,trim:!0},px_gia_dd:{type:Boolean,default:!1},ton_kho:{type:Number,default:0},sl_order:{type:Number,default:0},sl_xuat:{type:Number,default:0},sl_gui_bep:{type:Number,default:0},sl_gui_bartender:{type:Number,default:0},sl_ht:{type:Number,default:0},gia_von:{type:Number,
2
2
  default:0},gia_von_nt:{type:Number,default:0},tien_xuat:{type:Number,default:0},tien_xuat_nt:{type:Number,default:0},gia_ban:{type:Number,default:0},gia_ban_nt:{type:Number,default:0},tien_hang:{type:Number,default:0},tien_hang_nt:{type:Number,default:0},gia_ban_chua_thue:Boolean,id_cs_ck:String,ty_le_ck:{type:Number,default:0},tien_ck:{type:Number,default:0},tien_ck_nt:{type:Number,default:0},tien:{type:Number,default:0},tien_nt:{type:Number,default:0},gia_ban_ct_nt:{type:Number},gia_ban_ct:{type:Number},
3
3
  tien_hang_ct:{type:Number,default:0},tien_hang_ct_nt:{type:Number,default:0},tien_thue_nt:{type:Number},tien_thue:{type:Number},thue_suat:{type:Number},tk_thue_co:String,tk_thue_co_treo:String,cs_discount:Schema.Types.Mixed,cs_tien_ck:{type:Number,default:0},cs_ty_le_ck:{type:Number,default:0},cs_sl_ap_dung:{type:Number,default:0},cs_gt_hd_tu:{type:Number,default:0},cs_gt_hd_den:{type:Number,default:0},ck_sl_tu2:[],tien_evoucher_duoc_pb:{type:Number,default:0},promotion:Schema.Types.Mixed,combo:Schema.Types.Mixed,
4
- sl_ap_dung_km:{type:Number,default:0},km_yn_for:String,id_cs:String,ma_thue:String,ma_hoa_don:{type:String,uppercase:!0,trim:!0,maxlength:32},ky_hieu_hoa_don:{type:String,uppercase:!0,trim:!0,maxlength:32},ma_tc:{type:String,uppercase:!0,trim:!0,maxlength:32},so_hd:{type:String,uppercase:!0,trim:!0,maxlength:32},so_seri:{type:String,uppercase:!0,trim:!0,maxlength:32},ngay_hd:{type:Date},ma_bp:{type:String,uppercase:!0,default:"",maxlength:32,trim:!0},ma_phi:{type:String,uppercase:!0,default:"",maxlength:32,
5
- trim:!0},ma_hd:{type:String,uppercase:!0,default:"",maxlength:32,trim:!0},ma_dt:{type:String,uppercase:!0,default:"",maxlength:32,trim:!0},ma_nv:{type:String,uppercase:!0,default:"",maxlength:32,trim:!0},ma_lo:{type:String,default:"",uppercase:!0,maxlength:32,trim:!0},han_sd:{type:Date},ma_tt1:{type:String,default:"",uppercase:!0,maxlength:32,trim:!0},ma_tt2:{type:String,default:"",uppercase:!0,maxlength:32,trim:!0},ma_tt3:{type:String,default:"",uppercase:!0,maxlength:32,trim:!0},options:[],tien_hang_options:Number,
6
- tien_hang_options_ct:Number,tien_thue_options:Number,sign_user:String,sign_data:Schema.Types.Mixed,signature:String,order_time:{type:Date,default:Date.now},finish_time:{type:Date},ghi_chu:{type:String},exfields_detail:Schema.Types.Mixed,line:{type:Number,default:0},het_hang:{type:Boolean,default:!1}});detailSchema.validate={ma_vt:validVt.existsVt,ma_kho:validVt.existsKho,ma_dvt:validator.existsDvt};
4
+ sl_ap_dung_km:{type:Number,default:0},km_yn_for:String,id_cs:String,ma_thue:String,ma_hoa_don:{type:String,uppercase:!0,trim:!0,maxlength:32},ky_hieu_hoa_don:{type:String,uppercase:!0,trim:!0,maxlength:32},ma_tc:{type:String,uppercase:!0,trim:!0,maxlength:32},so_hd:{type:String,uppercase:!0,trim:!0,maxlength:32},so_seri:{type:String,uppercase:!0,trim:!0,maxlength:32},ngay_hd:{type:Date},ong_ba:String,ma_so_thue:String,ma_bp:{type:String,uppercase:!0,default:"",maxlength:32,trim:!0},ma_phi:{type:String,
5
+ uppercase:!0,default:"",maxlength:32,trim:!0},ma_hd:{type:String,uppercase:!0,default:"",maxlength:32,trim:!0},ma_dt:{type:String,uppercase:!0,default:"",maxlength:32,trim:!0},ma_nv:{type:String,uppercase:!0,default:"",maxlength:32,trim:!0},ma_lo:{type:String,default:"",uppercase:!0,maxlength:32,trim:!0},han_sd:{type:Date},ma_tt1:{type:String,default:"",uppercase:!0,maxlength:32,trim:!0},ma_tt2:{type:String,default:"",uppercase:!0,maxlength:32,trim:!0},ma_tt3:{type:String,default:"",uppercase:!0,
6
+ maxlength:32,trim:!0},options:[],tien_hang_options:Number,tien_hang_options_ct:Number,tien_thue_options:Number,sign_user:String,sign_data:Schema.Types.Mixed,signature:String,order_time:{type:Date,default:Date.now},finish_time:{type:Date},ghi_chu:{type:String},exfields_detail:Schema.Types.Mixed,line:{type:Number,default:0},het_hang:{type:Boolean,default:!1}});detailSchema.validate={ma_vt:validVt.existsVt,ma_kho:validVt.existsKho,ma_dvt:validator.existsDvt};
7
7
  const pblSchema=new Schema({id_app:{type:String,required:!0,maxlength:1024},ma_dvcs:{type:String,required:!0,maxlength:1024},ma_ct:{type:String,default:"PBL",required:!0,uppercase:!0,maxlength:32,trim:!0},ma_gd:{type:String,default:"0",maxlength:32,trim:!0},so_ct:{type:String,uppercase:!0,trim:!0,maxlength:32},ngay_ct:{type:Date,default:Date.now,required:!0},ma_nt:{type:String,required:"ma_nt is required",default:"VND",trim:!0,uppercase:!0,maxlength:32},ty_gia:{type:Number,required:!0,min:0,default:1},
8
8
  ma_kh:{type:String,uppercase:!0,default:"",maxlength:32,trim:!0},ten_kh:String,ma_kho:{type:String,uppercase:!0,default:"",maxlength:32,trim:!0},ten_kho:String,ma_bp:{type:String,uppercase:!0,maxlength:32,trim:!0},ten_bp:String,ma_ban:{type:String,uppercase:!0,maxlength:32,trim:!0},ma_ban0:{type:String,uppercase:!0,maxlength:32,trim:!0},ma_ca:{type:String,uppercase:!0,maxlength:32,trim:!0},ty_le_ck_hd:{type:Number,default:0},tien_ck_hd:{type:Number,default:0},ong_ba:{type:String,maxlength:1024},sender_email:{type:String,
9
9
  maxlength:128},id_trans:{type:String,maxlength:1024},paymentByPoints:{type:Number,default:0},exchangeRate:Number,tien_paymentByPoints:{type:Number,default:0},evouchers:[global.Schema.Types.Mixed],tien_evoucher:Number,tk_no_evoucher:String,tk_co_evoucher:String,pt_thanh_toan:{type:String},tien_thu:{type:Number,default:0},bank_payment_info:{},pt_thanh_toan2:{type:String},tien_thu2:{type:Number,default:0},bank_payment_info2:{},ghi_chu_tt:String,con_no:{type:Number,default:0},phai_tra:{type:Number,default:0},
@@ -10,7 +10,7 @@ $reject$$)=>{$trans$$.save(async($e_master_users_will_receive$$,$rs$$)=>{if($e_m
10
10
  $ma_dvcs$$=await global.getModel("dvcs").findOne({id_app:$rs$$.id_app}).lean();$e_master_users_will_receive$$=$rs$$.toObject();$e_master_users_will_receive$$.dien_giai=$e_master_users_will_receive$$.description;$e_master_users_will_receive$$.ma_dvcs=(($ma_dvcs$$||{})._id||"").toString();$details_sc_kh_no_notificationData_title$$=[{tk_no:$rs$$.tk_no,tk_co:$rs$$.tk_co,tien_nt:$rs$$.amount,tien:$rs$$.amount,ma_nt:$rs$$.denom.toUpperCase(),ty_gia:1,ma_kh_no:($details_sc_kh_no_notificationData_title$$||
11
11
  {}).ma_kh,ma_kh_co:($kh_co$$||{}).ma_kh}];(new PostSocai($e_master_users_will_receive$$,$details_sc_kh_no_notificationData_title$$)).run($e$$=>{$e$$&&console.error($e$$)})}$e_master_users_will_receive$$=[$rs$$.sender.email,$rs$$.receiver.email];$details_sc_kh_no_notificationData_title$$=`${$data$$.sender_email} \u0111\u00e3 chuy\u1ec3n cho ${$data$$.receiver_email} ${$rs$$.amount} ${$rs$$.denom} v\u1edbi n\u1ed9i dung: ${$data$$.description}`;if($data$$.sender_email===$data$$.id_app||$data$$.receiver_email===
12
12
  $data$$.id_app)$details_sc_kh_no_notificationData_title$$=`${$data$$.description}`;$details_sc_kh_no_notificationData_title$$={_id:$rs$$._id,id_app:$data$$.id_app,title:$details_sc_kh_no_notificationData_title$$,body:$details_sc_kh_no_notificationData_title$$,code:"transaction",event:"new",action:"NEW"};global.getModel("app").emitEvent($data$$.id_app,`${$details_sc_kh_no_notificationData_title$$.code}:${$details_sc_kh_no_notificationData_title$$.event}`,$details_sc_kh_no_notificationData_title$$,
13
- null,$e_master_users_will_receive$$,!0);$resolve$$($rs$$.toObject())})})};model.getTrans=async $id_trans$$=>new Promise($resolve$$=>{model.findOne({id_trans:$id_trans$$},($e$$,$rs$$)=>{$resolve$$($rs$$)})});model.deleteTrans=async $id_trans$$=>{$id_trans$$=typeof $id_trans$$==="string"?{id_trans:$id_trans$$}:{...$id_trans$$};console.log("delete transaction",$id_trans$$);await model.deleteMany($id_trans$$)};
14
- model.balance=async($email$$,$date_to$$)=>{$date_to$$||=new Date;$date_to$$=moment($date_to$$).endOf("date").toDate();return(await model.find({date_created:{$lte:$date_to$$},$or:[{"sender.email":$email$$},{"receiver.email":$email$$}]})).map($tran$$=>$tran$$.sender.email===$email$$?0-$tran$$.amount:$tran$$.amount).reduce(($a$$,$b$$)=>$a$$+$b$$,0)};
15
- model.in=async($email$$,$date_to$$)=>{$date_to$$||=new Date;$date_to$$=moment($date_to$$).endOf("date").toDate();return(await model.find({date_created:{$lte:$date_to$$},$or:[{"receiver.email":$email$$}]})).map($tran$$=>$tran$$.amount).reduce(($a$$,$b$$)=>$a$$+$b$$,0)};
16
- model.out=async($email$$,$date_to$$)=>{$date_to$$||=new Date;$date_to$$=moment($date_to$$).endOf("date").toDate();return(await model.find({date_created:{$lte:$date_to$$},$or:[{"sender.email":$email$$}]})).map($tran$$=>$tran$$.amount).reduce(($a$$,$b$$)=>$a$$+$b$$,0)};module.exports=model;
13
+ null,$e_master_users_will_receive$$,!0);$resolve$$($rs$$.toObject())})})};model.getTrans=async $id_trans$$=>model.findOne({id_trans:$id_trans$$});model.deleteTrans=async $id_trans$$=>{$id_trans$$=typeof $id_trans$$==="string"?{id_trans:$id_trans$$}:{...$id_trans$$};console.log("delete transaction",$id_trans$$);await model.deleteMany($id_trans$$)};
14
+ model.balance=async($email$$,$date_to$$)=>{$date_to$$||=new Date;$date_to$$=moment($date_to$$).endOf("date").toDate();return(await model.find({date_created:{$lte:$date_to$$},$or:[{"sender.email":$email$$},{"receiver.email":$email$$}]}).inTxn()).map($tran$$=>$tran$$.sender.email===$email$$?0-$tran$$.amount:$tran$$.amount).reduce(($a$$,$b$$)=>$a$$+$b$$,0)};
15
+ model.in=async($email$$,$date_to$$)=>{$date_to$$||=new Date;$date_to$$=moment($date_to$$).endOf("date").toDate();return(await model.find({date_created:{$lte:$date_to$$},$or:[{"receiver.email":$email$$}]}).inTxn()).map($tran$$=>$tran$$.amount).reduce(($a$$,$b$$)=>$a$$+$b$$,0)};
16
+ model.out=async($email$$,$date_to$$)=>{$date_to$$||=new Date;$date_to$$=moment($date_to$$).endOf("date").toDate();return(await model.find({date_created:{$lte:$date_to$$},$or:[{"sender.email":$email$$}]}).inTxn()).map($tran$$=>$tran$$.amount).reduce(($a$$,$b$$)=>$a$$+$b$$,0)};module.exports=model;
@@ -7,11 +7,7 @@ dmdoi,[{where:{ma_bp:"ma_bp",ma_doi:"ma_doi"},fields:"ten_doi"}],function(){$cal
7
7
  function(){$callback$$(null,$items$$)})},$callback$$=>{$items$$.filter($item$$=>$item$$.chuc_vu).joinModel2($user$$.current_id_app,group,[{where:{chuc_vu:"_id"},fields:[{ten_chuc_vu:"group_name"},{color:"color"},{muc_tieu_bieu:"muc_tieu_bieu"}]}],function(){$callback$$(null,$items$$)})},$callback$$=>{async.mapLimit($items$$,20,($item$$,$callback$$)=>{($item$$.bo_phan||[]).filter($item$$=>$item$$.chuc_vu).joinModel2($user$$.current_id_app,group,[{where:{chuc_vu:"_id"},fields:[{ten_chuc_vu:"group_name"},
8
8
  {color:"color"},{muc_tieu_bieu:"muc_tieu_bieu"}]}],function(){$callback$$(null,$items$$)})},()=>{$callback$$(null,$items$$)})},$callback$$=>{async.mapLimit($items$$,20,($item$$,$callback$$)=>{($item$$.bo_phan||[]).filter($item$$=>$item$$.ma_bp).joinModel2($user$$.current_id_app,dmbp,[{where:{ma_bp:"ma_bp"},fields:[{ten_bp:"ten_bp"}]}],function(){$callback$$(null,$items$$)})},()=>{$callback$$(null,$items$$)})}],()=>{$items$$.filter($item$$=>$item$$.bo_phan).forEach($item$$=>{$item$$.bo_phan.forEach($bp$$=>
9
9
  {$bp$$.active=!$bp$$.den_ngay||$bp$$.den_ngay>=new Date;$bp$$.active&&($item$$.ma_bp=$item$$.map_bp||$bp$$.ma_bp,$item$$.ten_bp=$item$$.ten_bp||$bp$$.ten_bp,$item$$.phu_trach=$item$$.phu_trach||$bp$$.phu_trach,$item$$.chuc_vu=$item$$.chuc_vu||$bp$$.chuc_vu)})});$next$$(null,$items$$)})},onImport:($user$$,$data$$,$columns$$,$next$$)=>{async.mapLimit($data$$,20,function($r$$,$callback$$){async.series({nhom:function($callback$$){$r$$.group_name&&!$r$$.nh_kh?group.findOneAndUpdate({id_app:$user$$.current_id_app,
10
- group_type:"DMNV",group_name:{$regex:$r$$.group_name,$options:"i"}},{group_name:$r$$.group_name,group_type:"DMNV",status:!0},{new:!0,upsert:!0},function($e$$,$n$$){if($e$$)return $callback$$($e$$);$r$$.nh_nv=$n$$._id.toString();$callback$$(null)}):$callback$$()}},function(){$callback$$()})},function(){$next$$()})},onRightByItem:($user$$,$condition$$,$next$$)=>{async.parallel({phu_trach_bp:$callback$$=>{dmbp.find({id_app:$user$$.current_id_app,phu_trach:$user$$.email}).lean().then($bps$$=>{$callback$$(null,
11
- $bps$$)}).catch($e$$=>{$callback$$($e$$)})},phu_trach_doi:$callback$$=>{dmdoi.find({id_app:$user$$.current_id_app,phu_trach:$user$$.email}).lean().then($bps$$=>{$callback$$(null,$bps$$)}).catch($e$$=>{$callback$$($e$$)})},phu_trach_to:$callback$$=>{dmto.find({id_app:$user$$.current_id_app,phu_trach:$user$$.email}).lean().then($bps$$=>{$callback$$(null,$bps$$)}).catch($e$$=>{$callback$$($e$$)})},phu_trach_nhom:$callback$$=>{dmnhnv.find({id_app:$user$$.current_id_app,phu_trach:$user$$.email}).lean().then($bps$$=>
12
- {$callback$$(null,$bps$$)}).catch($e$$=>{$callback$$($e$$)})}},($_condition_bps$jscomp$4_e$$,$$or_nhs_rs$$)=>{if($_condition_bps$jscomp$4_e$$)return $next$$($_condition_bps$jscomp$4_e$$);$_condition_bps$jscomp$4_e$$=$$or_nhs_rs$$.phu_trach_bp.map($b$$=>$b$$.ma_bp);var $_c_dois$$=$$or_nhs_rs$$.phu_trach_doi.map($d$$=>$d$$.ma_doi);let $tos$$=$$or_nhs_rs$$.phu_trach_to.map($t$$=>$t$$.ma_to);$$or_nhs_rs$$=$$or_nhs_rs$$.phu_trach_nhom.map($n$$=>$n$$.ma_nh_nv);$$or_nhs_rs$$=[{user:$user$$.email},{ma_bp:{$in:$_condition_bps$jscomp$4_e$$}},
13
- {ma_doi:{$in:$_c_dois$$}},{ma_to:{$in:$tos$$}},{ma_nh_nv:{$in:$$or_nhs_rs$$}}];$_condition_bps$jscomp$4_e$$=[];for(let $k$$ in $condition$$)$_c_dois$$={},$_c_dois$$[$k$$]=$condition$$[$k$$],$_condition_bps$jscomp$4_e$$.push($_c_dois$$);$_condition_bps$jscomp$4_e$$.length>0&&$$or_nhs_rs$$.push({$and:$_condition_bps$jscomp$4_e$$});$next$$(null,{$or:$$or_nhs_rs$$})})},onQuery:($req$$,$next$$)=>{if($req$$.obj&&$req$$.obj.user===$req$$.user.email)return $req$$.permission=!0,$next$$();$req$$.permission||
14
- ($req$$.condition={user:$req$$.user.email});$req$$.permission=!0;$next$$()}});$contr_router$$.validating=async($id_app_user$$,$obj$$,$next$$,$options$$={})=>{if($options$$.action=="add"&&!$obj$$.ma_nv&&$obj$$.ten_nv){$id_app_user$$=$id_app_user$$.current_id_app;try{let $ma_nv$$=await model.asyncCreateEmployeeCode($id_app_user$$,$obj$$.ten_nv);$obj$$.ma_nv=$ma_nv$$;$next$$(null,$obj$$)}catch($e$$){console.error($e$$),$next$$($e$$)}}else $next$$(null,$obj$$)};$contr_router$$.route();$contr_router$$.on("saved",
15
- async $data$$=>{let $_usergroup$$;try{$_usergroup$$=await Usergroup.getInfo($data$$.id_app,{is_employee_group:!0})}catch($e$$){return}$data$$.user&&$_usergroup$$&&User.findOne({email:$data$$.user},($e$$,$rs$$)=>{if($rs$$)Participant.createParticipant({id_app:$data$$.id_app,email:$data$$.user,group_id:$_usergroup$$._id,active:!0},$e$$=>{if($e$$)return console.log("can't add user",$data$$.user,"to company")});else{var $result$$=new User;$result$$.email=$data$$.user;$result$$.name=$data$$.ten_nv;$result$$.email2=
16
- $data$$.email;$result$$.local={};$result$$.local.email=$result$$.email;$result$$.local.name=$result$$.name;$result$$.local.picture="/images/avatar.jpg";$result$$.local.password=$result$$.generateHash($result$$.email+($data$$.default_password||$result$$.email+"@123456"));$result$$.save($e$$=>{if($e$$)return console.log($e$$.message);Participant.createParticipant({id_app:$data$$.id_app,email:$result$$.email,group_id:$_usergroup$$._id,active:!0},$e$$=>{if($e$$)return console.log("can't add user",$result$$.email,
17
- "to company")})})}})})};module.exports=dmnv;
10
+ group_type:"DMNV",group_name:{$regex:$r$$.group_name,$options:"i"}},{group_name:$r$$.group_name,group_type:"DMNV",status:!0},{new:!0,upsert:!0},function($e$$,$n$$){if($e$$)return $callback$$($e$$);$r$$.nh_nv=$n$$._id.toString();$callback$$(null)}):$callback$$()}},function(){$callback$$()})},function(){$next$$()})},onQuery:($req$$,$next$$)=>{if($req$$.obj&&$req$$.obj.user===$req$$.user.email)return $req$$.permission=!0,$next$$();$req$$.permission||($req$$.condition={user:$req$$.user.email});$req$$.permission=
11
+ !0;$next$$()}});$contr_router$$.validating=async($id_app_user$$,$obj$$,$next$$,$options$$={})=>{if($options$$.action=="add"&&!$obj$$.ma_nv&&$obj$$.ten_nv){$id_app_user$$=$id_app_user$$.current_id_app;try{let $ma_nv$$=await model.asyncCreateEmployeeCode($id_app_user$$,$obj$$.ten_nv);$obj$$.ma_nv=$ma_nv$$;$next$$(null,$obj$$)}catch($e$$){console.error($e$$),$next$$($e$$)}}else $next$$(null,$obj$$)};$contr_router$$.route();$contr_router$$.on("saved",async $data$$=>{let $_usergroup$$;try{$_usergroup$$=
12
+ await Usergroup.getInfo($data$$.id_app,{is_employee_group:!0})}catch($e$$){return}$data$$.user&&$_usergroup$$&&User.findOne({email:$data$$.user},($e$$,$rs$$)=>{if($rs$$)Participant.createParticipant({id_app:$data$$.id_app,email:$data$$.user,group_id:$_usergroup$$._id,active:!0},$e$$=>{if($e$$)return console.log("can't add user",$data$$.user,"to company")});else{var $result$$=new User;$result$$.email=$data$$.user;$result$$.name=$data$$.ten_nv;$result$$.email2=$data$$.email;$result$$.local={};$result$$.local.email=
13
+ $result$$.email;$result$$.local.name=$result$$.name;$result$$.local.picture="/images/avatar.jpg";$result$$.local.password=$result$$.generateHash($result$$.email+($data$$.default_password||$result$$.email+"@123456"));$result$$.save($e$$=>{if($e$$)return console.log($e$$.message);Participant.createParticipant({id_app:$data$$.id_app,email:$result$$.email,group_id:$_usergroup$$._id,active:!0},$e$$=>{if($e$$)return console.log("can't add user",$result$$.email,"to company")})})}})})};module.exports=dmnv;
@@ -0,0 +1,4 @@
1
+ const chamcong=global.getModel("chamcong"),controller=require("../../controllers/controllerRPT"),async=require("async"),permission=require("../../libs/permission");
2
+ module.exports=function($router$$){new controller($router$$,"bkchamcong",function($req$$,$callback$$){async.map($req$$.query.id_apps||[$req$$.query.id_app],($id_app$$,$callback$$)=>{permission.hasRight($id_app$$,$req$$.user.email,"chamcong","view",async function($error$$,$permission$$){if(!$permission$$)return $callback$$(`B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n v\u1edbi c\u00f4ng ty c\u00f3 id '${$id_app$$}'`);$error$$={};$error$$.id_app=$id_app$$;$error$$.ngay={$gte:$req$$.query.tu_ngay,$lte:$req$$.query.den_ngay};
3
+ $req$$.query.ma_nv&&($error$$.ma_nv=$req$$.query.ma_nv);$req$$.query.ma_bp&&($error$$.ma_bp=$req$$.query.ma_bp);chamcong.find($error$$).lean().then(async $congs$$=>{await $congs$$.asyncJoinModel2($id_app$$,"dmloaicong",[{where:{ma_loai_cong:"ma_loai_cong"},fields:["ten_loai_cong","color"]}]);await $congs$$.asyncJoinModel2($id_app$$,global.getModel("dmnv"),[{where:{ma_nv:"ma_nv"},fields:["ten_nv"]}]);await $congs$$.asyncJoinModel2($id_app$$,global.getModel("dmbp"),[{where:{ma_bp:"ma_bp"},fields:["ten_bp"]}]);
4
+ $callback$$(null,$congs$$)}).catch($e$$=>{$callback$$($e$$)})})},($e$$,$rs$$)=>{if($e$$)return $callback$$($e$$);$callback$$(null,$rs$$.reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]))})})};
@@ -25,18 +25,18 @@ $detail$jscomp$4_pk$$.ma_kho=$d$jscomp$6_pk$$.ma_kho_pk_xuat,$detail$jscomp$4_pk
25
25
  $d$jscomp$8_pk$$.tien_nhap_pk_nt||0,$d$jscomp$6_pk$$.tien_xuat=$d$jscomp$6_pk$$.tien_xuat_nt*($obj$$.ty_gia||1),$d$jscomp$6_pk$$.sl_nhap=0,$d$jscomp$6_pk$$.tien_nhap_nt=$d$jscomp$6_pk$$.tien_nhap=0,$d$jscomp$6_pk$$.tien_hang_nt=$d$jscomp$6_pk$$.tien_hang=0,$d$jscomp$6_pk$$.tien_ck=$d$jscomp$6_pk$$.tien_ck_nt=$d$jscomp$6_pk$$.ty_le_ck=0,$d$jscomp$6_pk$$.tien_phi=$d$jscomp$6_pk$$.tien_phi_nt=0,$product_details_npp$$.push($d$jscomp$6_pk$$);for(let $d$$ of($obj$$.ds_pk_xuat||[]).filter($d$$=>$d$$.ma_pk_xuat&&
26
26
  $d$$.sl_pk_xuat))$d$jscomp$8_pk$$={...$d$$},$d$jscomp$8_pk$$.ma_vt=$d$$.ma_pk_xuat,$d$jscomp$8_pk$$.ma_dvt=$d$$.ma_dvt_pk_xuat,$d$jscomp$8_pk$$.ma_kho=$obj$$.ma_kho_npp||$customer$$.ma_kho_npp,$d$jscomp$8_pk$$.ma_kh=$obj$$.ma_kh,$d$jscomp$8_pk$$.nxt=1,$d$jscomp$8_pk$$.tk_co=$obj$$.tk_co,$d$jscomp$8_pk$$.sl_nhap=$d$$.sl_pk_xuat,$d$jscomp$8_pk$$.gia_von_nt=$d$$.gia_von_pk_xuat_nt||0,$d$jscomp$8_pk$$.gia_von=$d$jscomp$8_pk$$.gia_von_nt*($obj$$.ty_gia||1),$d$jscomp$8_pk$$.tien_nhap_nt=$d$$.tien_xuat_pk_nt||
27
27
  0,$d$jscomp$8_pk$$.tien_nhap=$d$jscomp$8_pk$$.tien_nhap_nt*($obj$$.ty_gia||1),$d$jscomp$8_pk$$.sl_xuat=0,$d$jscomp$8_pk$$.tien_xuat_nt=$d$jscomp$8_pk$$.tien_xuat=0,$d$jscomp$8_pk$$.tien_hang_nt=$d$jscomp$8_pk$$.tien_hang=0,$d$jscomp$8_pk$$.tien_ck=$d$jscomp$8_pk$$.tien_ck_nt=$d$jscomp$8_pk$$.ty_le_ck=0,$d$jscomp$8_pk$$.tien_phi=$d$jscomp$8_pk$$.tien_phi_nt=0,$product_details_npp$$.push($d$jscomp$8_pk$$);await $product_details$$.filter($d$$=>!$d$$.ma_dvt).asyncJoinModel2($obj$$.id_app,"dmvt",{where:"ma_vt",
28
- fields:["ma_dvt","tk_vt","tk_gv","tk_tl"]});await ($obj$$.details||[]).asyncJoinModel2($obj$$.id_app,"dmvt",{where:"ma_vt",fields:"ten_phu_cap ten_vt ma_dvt tk_vt tk_gv tk_tl tg_tk".split(" ")});async.series({phu_cap:$callback$$=>{setImmediate(async()=>{let $details_phu_cap$$=_.cloneDeep(($obj$$.details||[]).filter($d$$=>$d$$.luong_tho&&$d$$.tg_tk));$details_phu_cap$$.length==0&&($details_phu_cap$$=_.cloneDeep(($obj$$.details||[]).filter($d$$=>$d$$.luong_tho)));for(var $cust$jscomp$1_d$$ of $details_phu_cap$$)$cust$jscomp$1_d$$.ma_nv=
28
+ fields:["ma_dvt","tk_vt","tk_gv","tk_tl"]});await ($obj$$.details||[]).asyncJoinModel2($obj$$.id_app,"dmvt",{where:"ma_vt",fields:"ten_phu_cap ten_vt ma_dvt tk_vt tk_gv tk_tl tg_tk".split(" ")});let $ket_qua_post_sokho$$;async.series({phu_cap:$callback$$=>{setImmediate(async()=>{let $details_phu_cap$$=_.cloneDeep(($obj$$.details||[]).filter($d$$=>$d$$.luong_tho&&$d$$.tg_tk));$details_phu_cap$$.length==0&&($details_phu_cap$$=_.cloneDeep(($obj$$.details||[]).filter($d$$=>$d$$.luong_tho)));for(var $cust$jscomp$1_d$$ of $details_phu_cap$$)$cust$jscomp$1_d$$.ma_nv=
29
29
  $obj$$.ma_nv_giao_hang||$cust$jscomp$1_d$$.ma_nv,$cust$jscomp$1_d$$.thang=(new Date($obj$$.ngay_ct)).getMonth()+1,$cust$jscomp$1_d$$.nam=(new Date($obj$$.ngay_ct)).getFullYear(),$cust$jscomp$1_d$$.ten_phu_cap=$cust$jscomp$1_d$$.ten_phu_cap||$cust$jscomp$1_d$$.ten_vt,$cust$jscomp$1_d$$.tien=$cust$jscomp$1_d$$.luong_tho;$obj$$.ma_kh&&($cust$jscomp$1_d$$=await global.getModel("customer").findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh,phu_cap:{$gte:0}}).lean())&&($cust$jscomp$1_d$$={ma_nv:$obj$$.ma_nv_giao_hang,
30
30
  thang:(new Date($obj$$.ngay_ct)).getMonth()+1,nam:(new Date($obj$$.ngay_ct)).getFullYear(),ten_phu_cap:$cust$jscomp$1_d$$.ten_phu_cap||"Ph\u1ee5 c\u1ea5p theo kh\u00e1ch h\u00e0ng",tien:$cust$jscomp$1_d$$.phu_cap},$details_phu_cap$$.push($cust$jscomp$1_d$$));(new PostBook($obj$$,$details_phu_cap$$,global.getModel("phucap"),async($detail$$,$callback$$)=>{$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})})},post_tdttno:function($callback$$){account.findOne({tk:$obj$$.tk_no,
31
31
  id_app:$obj$$.id_app},{tk_cn:1},async function($d_chinh_error$$,$tk$$){if($d_chinh_error$$)return $callback$$($d_chinh_error$$);if($tk$$&&$tk$$.tk_cn===!0){const $ma_kh_no$$=$obj$$.ma_kh_no||$obj$$.ma_kh;let $kh_bo_xung$$=($obj$$.details||[]).filter($d$$=>($d$$.ma_kh_no||$d$$.ma_kh)&&($d$$.ma_kh_no||$d$$.ma_kh)!=$ma_kh_no$$);$kh_bo_xung$$.forEach($d$$=>{$d$$.tien_nt=($d$$.tien_ct_nt||0)-($d$$.tien_ck_nt||0)-($d$$.gt_vt_du||0)+($d$$.tien_thue_nt||0);$d$$.tien=$d$$.tien_nt*$obj$$.ty_gia;$d$$.ma_kh=
32
32
  $d$$.ma_kh_no||$d$$.ma_kh});$kh_bo_xung$$=await $kh_bo_xung$$.asyncGroupBy(["ma_kh"],["tien_nt","tien"]);const $bao_hiem$$=[];$obj$$.tien_bh_chi&&$obj$$.ma_kh_bh&&($d_chinh_error$$={...$obj$$},$d_chinh_error$$.ma_kh=$obj$$.ma_kh_bh,$d_chinh_error$$.tien_nt=$obj$$.tien_bh_chi,$d_chinh_error$$.tien=$d_chinh_error$$.tien_bh_chi*($obj$$.ty_gia||1),$bao_hiem$$.push($d_chinh_error$$));$d_chinh_error$$=[{...$obj$$}];$d_chinh_error$$.forEach($detail$$=>{$detail$$.ma_kh=$ma_kh_no$$;$detail$$.tien_nt=Math.max(0,
33
33
  $obj$$.details.csum("tien_ct_nt")-$obj$$.details.csum("tien_ck_nt")-$obj$$.details.csum("gt_vt_du")-($obj$$.tien_ck_hd||0)+$obj$$.details.csum("tien_thue_nt")+($obj$$.tien_phi_vc_nt||0)-$kh_bo_xung$$.csum("tien_nt")-$bao_hiem$$.csum("tien_nt"));$detail$$.tien=$detail$$.tien_nt*$obj$$.ty_gia});(new PostBook($obj$$,[...$kh_bo_xung$$,...$bao_hiem$$,...$d_chinh_error$$].filter($d$$=>$d$$.tien_nt),Tdttno,function($detail$$,$callback$$){try{$detail$$.so_hd||($detail$$.so_hd=$obj$$.so_ct),$detail$$.ngay_hd||
34
34
  ($detail$$.ngay_hd=$obj$$.ngay_ct)}catch($e$$){console.error($e$$,$obj$$)}$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})}else Tdttno.deleteMany({id_ct:$obj$$._id},function($error$$){$callback$$($error$$)})})},post_sokho:$callback$$=>{async.parallel({kt:$callback$$=>{$options$$.not_post_sokho?$callback$$():(new PostSokho($obj$$,[...$product_details$$],async($detail$$,$callback$$)=>{$detail$$.nxt=$detail$$.nxt||2;$detail$$.tk_no=$obj$$.tk_no;$detail$$.ma_kho=$detail$$.ma_kho||
35
- $obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})},npp:$callback$$=>{$options$$.not_post_sokho?$callback$$():(new PostBook($obj$$,$product_details_npp$$,global.getModel("sokhonpp"),async($detail$$,$callback$$)=>{$detail$$.tk_no=$obj$$.tk_no;$detail$$.ma_kho=$detail$$.ma_kho||$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})},tt:$callback$$=>{$options$$.post_sokhott?(new PostBook($obj$$,$product_details$$,Sokhott,async($detail$$,
36
- $callback$$)=>{$detail$$.nxt=$detail$$.nxt||2;$detail$$.tk_no=$obj$$.tk_no;$detail$$.ma_kho=$detail$$.ma_kho||$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)}):$callback$$()}},($e$$,$rs$$)=>{$callback$$($e$$,$rs$$)})},post_vatra:function($callback$$){(async()=>{if($obj$$.ngay_hd||$obj$$.vatras&&$obj$$.vatras.length>0){let $details_vatra$$=$obj$$.vatras||[];if($obj$$.ngay_hd){var $d$$=$obj$$.details.map($detail$$=>({...$detail$$,thue_suat:($detail$$.ma_thue?
37
- $detail$$.thue_suat:$obj$$.thue_suat)||0,ma_thue:$detail$$.ma_thue||$obj$$.ma_thue,tien_thue_nt:$detail$$.tien_thue_nt||0,tien_thue:$detail$$.tien_thue||0})).filter($d$$=>$d$$.ma_thue);await $d$$.filter($r$$=>!$r$$.tk_thue_co&&$r$$.ma_thue).asyncJoinModel2($obj$$.id_app,"vat",{where:"ma_thue",fields:["tk_thue_co"]});$d$$=await $d$$.asyncGroupBy(["ma_thue","thue_suat","ten_vt_vat","tk_thue_co"],"tien_ct_nt tien_ct tien_nt tien tien_ck tien_ck_nt tien_thue tien_thue_nt".split(" "));if($d$$.length==
38
- 1){let $tien_thue_nt$$=$d$$.map($d$$=>$d$$.tien_thue_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0),$tien_thue$$=$d$$.map($d$$=>$d$$.tien_thue).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$d$$[0].tien_thue_nt=$tien_thue_nt$$;$d$$[0].tien_thue=$tien_thue$$}$d$$.forEach($detail$$=>{try{$detail$$.tk_du_thue=$obj$$.tk_no,$detail$$.t_tien_nt=($detail$$.tien_ct_nt||0)-($detail$$.tien_ck_nt||0),$detail$$.t_tien=($detail$$.tien_ct||0)-($detail$$.tien_ck||0),$detail$$.t_thue_nt=$detail$$.tien_thue_nt,$detail$$.t_thue=$detail$$.tien_thue,
39
- $detail$$.ten_vt=$detail$$.ten_vt_vat||$obj$$.ten_vt||$obj$$.dien_giai}catch($e$$){console.error($e$$,$obj$$)}});$details_vatra$$=[...$details_vatra$$,$d$$]}(new PostBook($obj$$,$details_vatra$$,Vatra,($detail$$,$callback$$)=>{$detail$$={...$detail$$};$detail$$.ten_vt=$detail$$.ten_vt||$obj$$.dien_giai;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})}else $callback$$()})()},post_socai:function($callback$$){setImmediate(async()=>{let $details$$=[];$options$$.hoach_toan_ck_vt?
35
+ $obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){if($e$$)return $callback$$($e$$);$ket_qua_post_sokho$$=$rs$$.rs_sokho;$callback$$(null,$rs$$)})},npp:$callback$$=>{$options$$.not_post_sokho?$callback$$():(new PostBook($obj$$,$product_details_npp$$,global.getModel("sokhonpp"),async($detail$$,$callback$$)=>{$detail$$.tk_no=$obj$$.tk_no;$detail$$.ma_kho=$detail$$.ma_kho||$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})},tt:$callback$$=>{$options$$.post_sokhott?
36
+ (new PostBook($obj$$,$product_details$$,Sokhott,async($detail$$,$callback$$)=>{$detail$$.nxt=$detail$$.nxt||2;$detail$$.tk_no=$obj$$.tk_no;$detail$$.ma_kho=$detail$$.ma_kho||$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)}):$callback$$()}},($e$$,$rs$$)=>{$callback$$($e$$,$rs$$)})},post_vatra:function($callback$$){(async()=>{if($obj$$.ngay_hd||$obj$$.vatras&&$obj$$.vatras.length>0){let $details_vatra$$=$obj$$.vatras||[];if($obj$$.ngay_hd){var $d$$=$obj$$.details.map($detail$$=>
37
+ ({...$detail$$,thue_suat:($detail$$.ma_thue?$detail$$.thue_suat:$obj$$.thue_suat)||0,ma_thue:$detail$$.ma_thue||$obj$$.ma_thue,tien_thue_nt:$detail$$.tien_thue_nt||0,tien_thue:$detail$$.tien_thue||0})).filter($d$$=>$d$$.ma_thue);await $d$$.filter($r$$=>!$r$$.tk_thue_co&&$r$$.ma_thue).asyncJoinModel2($obj$$.id_app,"vat",{where:"ma_thue",fields:["tk_thue_co"]});$d$$=await $d$$.asyncGroupBy(["ma_thue","thue_suat","ten_vt_vat","tk_thue_co"],"tien_ct_nt tien_ct tien_nt tien tien_ck tien_ck_nt tien_thue tien_thue_nt".split(" "));
38
+ if($d$$.length==1){let $tien_thue_nt$$=$d$$.map($d$$=>$d$$.tien_thue_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0),$tien_thue$$=$d$$.map($d$$=>$d$$.tien_thue).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$d$$[0].tien_thue_nt=$tien_thue_nt$$;$d$$[0].tien_thue=$tien_thue$$}$d$$.forEach($detail$$=>{try{$detail$$.tk_du_thue=$obj$$.tk_no,$detail$$.t_tien_nt=($detail$$.tien_ct_nt||0)-($detail$$.tien_ck_nt||0),$detail$$.t_tien=($detail$$.tien_ct||0)-($detail$$.tien_ck||0),$detail$$.t_thue_nt=$detail$$.tien_thue_nt,$detail$$.t_thue=
39
+ $detail$$.tien_thue,$detail$$.ten_vt=$detail$$.ten_vt_vat||$obj$$.ten_vt||$obj$$.dien_giai}catch($e$$){console.error($e$$,$obj$$)}});$details_vatra$$=[...$details_vatra$$,$d$$]}(new PostBook($obj$$,$details_vatra$$,Vatra,($detail$$,$callback$$)=>{$detail$$={...$detail$$};$detail$$.ten_vt=$detail$$.ten_vt||$obj$$.dien_giai;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})}else $callback$$()})()},post_socai:function($callback$$){setImmediate(async()=>{let $details$$=[];$options$$.hoach_toan_ck_vt?
40
40
  ($obj$$.details.forEach(function($d$jscomp$24_detail$$){$d$jscomp$24_detail$$={...$d$jscomp$24_detail$$};$d$jscomp$24_detail$$.tien_nt=$d$jscomp$24_detail$$.tien_ct_nt;$d$jscomp$24_detail$$.tien=$d$jscomp$24_detail$$.tien_ct?$d$jscomp$24_detail$$.tien_ct:utils.round($d$jscomp$24_detail$$.tien_ct_nt*$obj$$.ty_gia,0);$d$jscomp$24_detail$$.tk_co=$d$jscomp$24_detail$$.tk_dt||$kho$$.tk_dt||$options$$.tk_dt;$d$jscomp$24_detail$$.ma_kh||($d$jscomp$24_detail$$.ma_kh=$obj$$.ma_kh);$d$jscomp$24_detail$$.tk_no=
41
41
  $obj$$.tk_no;$details$$.push($d$jscomp$24_detail$$)}),($obj$$.details||[]).filter($d$$=>$d$$.tien_ck_nt).forEach(function($d$jscomp$26_detail$$){$d$jscomp$26_detail$$={...$d$jscomp$26_detail$$};$d$jscomp$26_detail$$.tk_no=$d$jscomp$26_detail$$.tk_ck||$obj$$.tk_ck||$kho$$.tk_ck||$options$$.tk_ck;$d$jscomp$26_detail$$.ma_kh||($d$jscomp$26_detail$$.ma_kh=$obj$$.ma_kh);$d$jscomp$26_detail$$.tk_co=$obj$$.tk_no;$d$jscomp$26_detail$$.tien_nt=$d$jscomp$26_detail$$.tien_ck_nt;$d$jscomp$26_detail$$.tien=$d$jscomp$26_detail$$.tien_ck;
42
42
  $d$jscomp$26_detail$$.ma_kh_no=$d$jscomp$26_detail$$.ma_kh||$obj$$.ma_kh;$d$jscomp$26_detail$$.ma_kh_co=$obj$$.ma_kh_no||$d$jscomp$26_detail$$.ma_kh||$obj$$.ma_kh;$d$jscomp$26_detail$$.check_balance=!1;$details$$.push($d$jscomp$26_detail$$)})):$obj$$.details.forEach(function($d$jscomp$27_detail$$){$d$jscomp$27_detail$$={...$d$jscomp$27_detail$$};$d$jscomp$27_detail$$.tien_nt=$d$jscomp$27_detail$$.tien_ct_nt-($d$jscomp$27_detail$$.tien_ck_nt||0);$d$jscomp$27_detail$$.tien=utils.round($d$jscomp$27_detail$$.tien_nt*
@@ -58,10 +58,10 @@ $obj$$.tk_no_hoa_hong_ql||$kho$$.tk_no_hoa_hong_ql||$options$$.tk_no_hoa_hong_ql
58
58
  {let $tt$$={};$tt$$.tk_no=$r$$.tk_no_hoa_hong_ql;$tt$$.tk_co=$r$$.tk_co_hoa_hong_ql;$tt$$.tien_nt=$r$$.tien_hoa_hong_ql;$tt$$.tien=$tt$$.tien_nt*($obj$$.ty_gia||1);$tt$$.ma_kh_no=$tt$$.ma_kh_co=$obj$$.ma_kh_hoa_hong_ql;$tt$$.ma_nv=$obj$$.ma_nv;$tt$$.check_balance=!1;$tt$$.dien_giai="Hoa h\u1ed3ng cho \u0111i\u1ec1u h\u00e0nh kinh doanh";$tt$$.ma_nt="VND";$tt$$.ty_gia=1;$tt$$.tk_no&&$tt$$.tk_co&&$details$$.push($tt$$)}));$o_tt$jscomp$1_tt$$={...$obj$$};$o_tt$jscomp$1_tt$$.tk_no=$obj$$.tk_no;$o_tt$jscomp$1_tt$$.tk_co=
59
59
  $obj$$.tk_thue_co;$o_tt$jscomp$1_tt$$.tien_nt=$obj$$.details.csum("tien_thue_nt");$o_tt$jscomp$1_tt$$.tien=$o_tt$jscomp$1_tt$$.tien_nt*$o_tt$jscomp$1_tt$$.ty_gia;$o_tt$jscomp$1_tt$$.dien_giai_thue&&($o_tt$jscomp$1_tt$$.dien_giai=$o_tt$jscomp$1_tt$$.dien_giai_thue);$details$$.push($o_tt$jscomp$1_tt$$);if($obj$$.vatras&&$obj$$.vatras.length>0)for(var $o$jscomp$1_o$$ of $obj$$.vatras)$o$jscomp$1_o$$.tk_no=$obj$$.tk_no,$o$jscomp$1_o$$.tk_co=$o$jscomp$1_o$$.tk_thue_co,$o$jscomp$1_o$$.tien_nt=$o$jscomp$1_o$$.t_thue_nt,
60
60
  $o$jscomp$1_o$$.tien=$o$jscomp$1_o$$.t_thue,$o$jscomp$1_o$$.dien_giai_thue&&($o$jscomp$1_o$$.dien_giai=$o$jscomp$1_o$$.dien_giai_thue),$details$$.push($o$jscomp$1_o$$);$obj$$.tk_phi_vc=$obj$$.tk_phi_vc||$options$$.tk_phi_vc;$obj$$.tk_phi_vc&&($o$jscomp$1_o$$={...$obj$$},$o$jscomp$1_o$$.tk_no=$obj$$.tk_no,$o$jscomp$1_o$$.tk_co=$obj$$.tk_phi_vc,$o$jscomp$1_o$$.tien_nt=$obj$$.tien_phi_vc_nt,$o$jscomp$1_o$$.tien=$o$jscomp$1_o$$.tien_nt*$o$jscomp$1_o$$.ty_gia,$o$jscomp$1_o$$.dien_giai="Ph\u00ed giao h\u00e0ng",
61
- $details$$.push($o$jscomp$1_o$$));const $details_giavon$$=[];[...$product_details$$].forEach(function($d$$){const $detail$$={...$d$$};$d$$.nxt!=1&&($detail$$.tk_no=$detail$$.tk_gv,$detail$$.ma_kh||($detail$$.ma_kh=$obj$$.ma_kh),$detail$$.tk_co=$detail$$.tk_vt,$detail$$.tien_nt=$detail$$.tien_xuat_nt,$detail$$.tien=$detail$$.tien_xuat,$details_giavon$$.push($detail$$))});async.series({xdtk:$callback$$=>{$details_giavon$$.joinModel2($obj$$.id_app,dmvt,{where:"ma_vt",fields:["tk_vt","gia_mua","tk_gv"]},
62
- ()=>{$details_giavon$$.forEach($s$$=>{$s$$.tk_co||($s$$.tk_co=$s$$.tk_vt||$options$$.tk_vt);$s$$.tk_no||($s$$.tk_no=$s$$.tk_gv||$options$$.tk_gv);$s$$.ma_nt="VND";$s$$.ty_gia=1});$callback$$()})}},()=>{$details_giavon$$.forEach($d$$=>{$d$$.ma_kh_no=$d$$.ma_kh||$obj$$.ma_kh;$d$$.ma_kh_co=$d$$.ma_kh||$obj$$.ma_kh});$details$$=$details$$.concat($details_giavon$$);(new PostSocai($obj$$,$details$$,void 0,void 0,$_options$$)).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})})})},thanhtoanhoahongnv:$callback$$=>
63
- {if($obj$$.da_chuyen_hoa_hong||!$obj$$.tien_hoa_hong||!$obj$$.user_nv||!$obj$$.chuyen_ngay)return $callback$$();setImmediate(async()=>{try{if($appInfo$$.wallet_address&&$appInfo$$.wallet_token&&$appInfo$$.tang_gioi_thieu_denom){let $wallet_nhan_vien$$=await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),username:$obj$$.user_nv,wallet_type:8});$wallet_nhan_vien$$||=await global.getModel("asskey").createWallet($appInfo$$._id.toString(),$obj$$.user_nv,"T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng",
64
- 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",
61
+ $details$$.push($o$jscomp$1_o$$));const $details_giavon$$=[];($ket_qua_post_sokho$$||[]).filter($r$$=>$r$$.nxt!=1).forEach(function($detail$$){$detail$$.toObject&&($detail$$=$detail$$.toObject());$detail$$={...$detail$$};$detail$$.tk_no=$detail$$.tk_gv;$detail$$.ma_kh||($detail$$.ma_kh=$obj$$.ma_kh);$detail$$.tk_co=$detail$$.tk_vt;$detail$$.tien_nt=$detail$$.tien_xuat_nt;$detail$$.tien=$detail$$.tien_xuat;$details_giavon$$.push($detail$$)});async.series({xdtk:$callback$$=>{$details_giavon$$.joinModel2($obj$$.id_app,
62
+ dmvt,{where:"ma_vt",fields:["tk_vt","gia_mua","tk_gv"]},()=>{$details_giavon$$.forEach($s$$=>{$s$$.tk_co||($s$$.tk_co=$s$$.tk_vt||$options$$.tk_vt);$s$$.tk_no||($s$$.tk_no=$s$$.tk_gv||$options$$.tk_gv);$s$$.ma_nt="VND";$s$$.ty_gia=1});$callback$$()})}},()=>{$details_giavon$$.forEach($d$$=>{$d$$.ma_kh_no=$d$$.ma_kh||$obj$$.ma_kh;$d$$.ma_kh_co=$d$$.ma_kh||$obj$$.ma_kh});$details$$=$details$$.concat($details_giavon$$);(new PostSocai($obj$$,$details$$,void 0,void 0,$_options$$)).run(function($e$$,$rs$$){$callback$$($e$$,
63
+ $rs$$)})})})},thanhtoanhoahongnv:$callback$$=>{if($obj$$.da_chuyen_hoa_hong||!$obj$$.tien_hoa_hong||!$obj$$.user_nv||!$obj$$.chuyen_ngay)return $callback$$();setImmediate(async()=>{try{if($appInfo$$.wallet_address&&$appInfo$$.wallet_token&&$appInfo$$.tang_gioi_thieu_denom){let $wallet_nhan_vien$$=await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),username:$obj$$.user_nv,wallet_type:8});$wallet_nhan_vien$$||=await global.getModel("asskey").createWallet($appInfo$$._id.toString(),
64
+ $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",
65
65
  $e$$)}$callback$$()})},thanhtoanhoahonggt:$callback$$=>{if($obj$$.da_chuyen_hoa_hong_gt||!$obj$$.tien_hoa_hong_gt||!$obj$$.user_gt||!$obj$$.chuyen_ngay_gt)return $callback$$();setImmediate(async()=>{try{if($appInfo$$.wallet_address&&$appInfo$$.wallet_token&&$appInfo$$.tang_gioi_thieu_denom){let $wallet_gt$$=await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),username:$obj$$.user_gt,wallet_type:8});$wallet_gt$$||=await global.getModel("asskey").createWallet($appInfo$$._id.toString(),
66
66
  $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",
67
67
  $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){if($obj$$.user_ctv&&$obj$$.thu_nhap_ctv){let $wallet_ctv$$=await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),username:$obj$$.user_ctv,wallet_type:8});$wallet_ctv$$||=await global.getModel("asskey").createWallet($appInfo$$._id.toString(),
@@ -1,45 +1,46 @@
1
- const async=require("async"),_=require("lodash"),moment=require("moment"),numeral=require("numeral"),PostSokho=require("../../libs/post-sokho"),PostBook=require("../../libs/post-book"),Options=global.getModel("options"),PostSocai=require("../../libs/post-socai"),Sokhott=global.getModel("sokhott"),App=global.getModel("app"),dmkho=global.getModel("dmkho"),dmvt=global.getModel("dmvt"),customer=global.getModel("customer"),dmdt=global.getModel("dmdt"),dmtt=global.getModel("dmtt"),Dmban=global.getModel("dmban"),
2
- dmphi=global.getModel("dmphi"),contract=global.getModel("contract"),trangthai=global.getModel("trangthai"),model=global.getModel("pbl"),hd7=global.getModel("hd7"),ptthanhtoan=global.getModel("ptthanhtoan"),controller=require("../../controllers/controller"),ma_ct="PBL",transaction=global.getModel("transaction"),Evoucher=global.getModel("evoucher"),ckdiem=require("../../libs/ckdiem"),dmdiemthuong=global.getModel("dmdiemthuong"),currency=global.getModel("currency"),vat=global.getModel("vat"),Wallet=
3
- global.getModel("wallet"),dmchietkhauhd=global.getModel("dmchietkhauhd"),dmkhuyenmaihd=global.getModel("dmkhuyenmaihd"),{QRPay}=require("vietnam-qr-pay"),khuyenmaihd=async $obj$$=>{if($obj$$.details){var $ckhds_query_t_tien_hang_ct_nt$$=$obj$$.details.csum("tien_hang_ct_nt")+$obj$$.details.csum("tien_hang_options_ct");if($ckhds_query_t_tien_hang_ct_nt$$!==0){var $hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$=$obj$$.details.csum("tien_ck_nt");$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$=$ckhds_query_t_tien_hang_ct_nt$$-
4
- $hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$;$obj$$.details=$obj$$.details.filter($d$$=>$d$$.km_yn_for!="khuyenmaihd");$ckhds_query_t_tien_hang_ct_nt$$={id_app:$obj$$.id_app,gt_tu:{$lte:$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$},ma_kho:{$in:[void 0,null,"",$obj$$.ma_kho]}};$ckhds_query_t_tien_hang_ct_nt$$.$and=[{$or:[{gt_den:{$in:[0,void 0,null]}},{gt_den:{$gte:$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$}}]}];var $hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$=moment($obj$$.ngay_ct).startOf("date").toDate();
5
- $hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$={$lte:moment($obj$$.ngay_ct).endOf("date").toDate()};$hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$={$gte:$hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$};$ckhds_query_t_tien_hang_ct_nt$$.hieu_luc_tu=$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$;$ckhds_query_t_tien_hang_ct_nt$$.hieu_luc_den=$hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$;$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$={$in:[void 0,null,"",$obj$$.ma_kh]};$hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$={$in:[void 0,
6
- null,""]};if($obj$$.ma_kh){var $kh_lan_mua_thu$$=await customer.findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh},{nh_kh:1});$kh_lan_mua_thu$$&&$kh_lan_mua_thu$$.nh_kh&&($hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$={$in:[void 0,null,"",$kh_lan_mua_thu$$.nh_kh]});($kh_lan_mua_thu$$=await model.countDocuments({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh,trang_thai:{$in:["5","6"]}}))||($kh_lan_mua_thu$$=0);$kh_lan_mua_thu$$+=1}$ckhds_query_t_tien_hang_ct_nt$$.$or=[{$and:[{ma_kh:$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$},
1
+ const async=require("async"),_=require("lodash"),moment=require("moment"),numeral=require("numeral"),PostSokho=require("flexbiz-server/server/libs/post-sokho"),PostBook=require("flexbiz-server/server/libs/post-book"),Options=global.getModel("options"),PostSocai=require("flexbiz-server/server/libs/post-socai"),Sokhott=global.getModel("sokhott"),App=global.getModel("app"),dmkho=global.getModel("dmkho"),dmvt=global.getModel("dmvt"),customer=global.getModel("customer"),dmdt=global.getModel("dmdt"),dmtt=
2
+ global.getModel("dmtt"),Dmban=global.getModel("dmban"),dmphi=global.getModel("dmphi"),contract=global.getModel("contract"),trangthai=global.getModel("trangthai"),model=global.getModel("pbl"),hd7=global.getModel("hd7"),ptthanhtoan=global.getModel("ptthanhtoan"),controller=require("flexbiz-server/server/controllers/controller"),ma_ct="PBL",transaction=global.getModel("transaction"),Evoucher=global.getModel("evoucher"),ckdiem=require("flexbiz-server/server/libs/ckdiem"),dmdiemthuong=global.getModel("dmdiemthuong"),
3
+ currency=global.getModel("currency"),vat=global.getModel("vat"),Wallet=global.getModel("wallet"),dmchietkhauhd=global.getModel("dmchietkhauhd"),dmkhuyenmaihd=global.getModel("dmkhuyenmaihd"),{QRPay}=require("vietnam-qr-pay"),khuyenmaihd=async $obj$$=>{if($obj$$.details){var $ckhds_query_t_tien_hang_ct_nt$$=$obj$$.details.csum("tien_hang_ct_nt")+$obj$$.details.csum("tien_hang_options_ct");if($ckhds_query_t_tien_hang_ct_nt$$!==0){var $hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$=$obj$$.details.csum("tien_ck_nt");
4
+ $hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$=$ckhds_query_t_tien_hang_ct_nt$$-$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$;$obj$$.details=$obj$$.details.filter($d$$=>$d$$.km_yn_for!="khuyenmaihd");$ckhds_query_t_tien_hang_ct_nt$$={id_app:$obj$$.id_app,gt_tu:{$lte:$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$},ma_kho:{$in:[void 0,null,"",$obj$$.ma_kho]}};$ckhds_query_t_tien_hang_ct_nt$$.$and=[{$or:[{gt_den:{$in:[0,void 0,null]}},{gt_den:{$gte:$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$}}]}];var $hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$=
5
+ moment($obj$$.ngay_ct).startOf("date").toDate();$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$={$lte:moment($obj$$.ngay_ct).endOf("date").toDate()};$hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$={$gte:$hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$};$ckhds_query_t_tien_hang_ct_nt$$.hieu_luc_tu=$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$;$ckhds_query_t_tien_hang_ct_nt$$.hieu_luc_den=$hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$;$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$={$in:[void 0,null,"",$obj$$.ma_kh]};$hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$=
6
+ {$in:[void 0,null,""]};if($obj$$.ma_kh){var $kh_lan_mua_thu$$=await customer.findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh},{nh_kh:1});$kh_lan_mua_thu$$&&$kh_lan_mua_thu$$.nh_kh&&($hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$={$in:[void 0,null,"",$kh_lan_mua_thu$$.nh_kh]});($kh_lan_mua_thu$$=await model.countDocuments({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh,trang_thai:{$in:["5","6"]}}))||($kh_lan_mua_thu$$=0);$kh_lan_mua_thu$$+=1}$ckhds_query_t_tien_hang_ct_nt$$.$or=[{$and:[{ma_kh:$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$},
7
7
  {nh_kh:{$in:["",null,void 0]}}]},{$and:[{nh_kh:$hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$},{ma_kh:{$in:["",null,void 0]}}]}];$ckhds_query_t_tien_hang_ct_nt$$.ap_dung_lan_mua_thu={$in:[null,void 0,0,void 0]};$ckhds_query_t_tien_hang_ct_nt$$=await dmkhuyenmaihd.find($ckhds_query_t_tien_hang_ct_nt$$).sort({stt_uu_tien:1,gt_tu:-1,ma_kh:-1,nh_kh:-1,hieu_luc_tu:-1}).lean();for($hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$=0;$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$<$ckhds_query_t_tien_hang_ct_nt$$.length;$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$++){let $ckhd$$=
8
8
  $ckhds_query_t_tien_hang_ct_nt$$[$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$];if($ckhd$$&&$ckhd$$.details_km&&$ckhd$$.details_km.length>0){$hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$=$ckhd$$.sl_toi_thieu||0;let $sl_dap_ung$$=0;$hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$&&$ckhd$$.vts&&$ckhd$$.vts.length>0&&$ckhd$$.vts.forEach($vt$$=>{var $ds_tien$$=$obj$$.details.filter($d$$=>$d$$.ma_vt===$vt$$.ma_vt&&(!$vt$$.ma_tt1||$vt$$.ma_tt1===$d$$.ma_tt1)&&(!$vt$$.ma_tt2||$vt$$.ma_tt2===$d$$.ma_tt2)&&(!$vt$$.ma_tt3||
9
9
  $vt$$.ma_tt3===$d$$.ma_tt3));if($ds_tien$$.length!=0){var $so_luong$$=$ds_tien$$.map($d$$=>$d$$.sl_xuat).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$ds_tien$$=$ds_tien$$.map($d$$=>($d$$.tien_hang_ct_nt||0)-($d$$.tien_ck_nt||0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$vt$$.sl_tu&&$so_luong$$<$vt$$.sl_tu||$vt$$.sl_den&&$so_luong$$>$vt$$.sl_den||$vt$$.gt_tu&&$ds_tien$$<$vt$$.gt_tu||$vt$$.gt_den&&$ds_tien$$>$vt$$.gt_den||($sl_dap_ung$$+=1)}});if($hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$<=$sl_dap_ung$$){$ckhd$$.details_km.forEach($d$$=>
10
10
  {$d$$={...$d$$,km_yn_for:"khuyenmaihd"};$d$$.id_cs=$ckhd$$._id.toString();$d$$.sl_xuat=$d$$.sl_km;$d$$.tien_hang_ct_nt=$d$$.tien_hang_ct=$d$$.tien_hang_nt=$d$$.tien_hang=0;$d$$.tien_ck_nt=$d$$.tien_ck=0;$d$$.ty_le_ck=0;$d$$.tien_nt=$d$$.tien=0;$obj$$.details.push($d$$)});break}}}}}},chietkhauhd=async($user$$,$obj$$)=>{if(!$obj$$.signature){$obj$$.details=$obj$$.details||[];var $t_ck_nt$$=$obj$$.details.csum("tien_ck_nt"),$t_tien_hang_ct_nt$$=$obj$$.details.csum("tien_hang_ct_nt")+$obj$$.details.csum("tien_hang_options_ct");
11
- $user$$.current_app_info&&($user$$.current_app_info.options||{}).tinh_lai_chiet_khau_pbl!=0&&dmchietkhauhd.tinhChietKhau($user$$,$obj$$.id_app,$obj$$,$t_tien_hang_ct_nt$$-$t_ck_nt$$)}},tinhtienthue=$detail$$=>{$detail$$.thue_suat=$detail$$.thue_suat||0;$detail$$.gia_ban_ct_nt=$detail$$.gia_ban_ct=Math.roundBy($detail$$.gia_ban_nt/(1+$detail$$.thue_suat/100));$detail$$.tien_hang_ct=$detail$$.tien_hang_ct_nt=Math.roundBy($detail$$.sl_xuat*$detail$$.gia_ban_ct_nt);$detail$$.ty_le_ck&&($detail$$.tien_ck_nt=
12
- Math.roundBy($detail$$.tien_hang_ct_nt*$detail$$.ty_le_ck/100));$detail$$.tien_thue=$detail$$.tien_thue_nt=Math.roundBy(($detail$$.tien_hang_ct_nt-$detail$$.tien_ck_nt)*$detail$$.thue_suat/100)},tinhtongtien=$r$$=>{$r$$.details&&($r$$.details.forEach($d$$=>{$d$$.sl_order=$d$$.sl_order||$d$$.sl_xuat}),$r$$.t_sl_order=$r$$.details.csum("sl_order"),$r$$.t_sl=$r$$.details.csum("sl_xuat"),$r$$.t_tien_hang_ct=$r$$.details.csum("tien_hang_ct")+$r$$.details.csum("tien_hang_options_ct"),$r$$.t_tien_hang_ct_nt=
13
- $r$$.details.csum("tien_hang_ct_nt")+$r$$.details.csum("tien_hang_options_ct"),$r$$.t_thue_nt=$r$$.details.csum("tien_thue_nt")+$r$$.details.csum("tien_thue_options"),$r$$.t_thue=$r$$.details.csum("tien_thue")+$r$$.details.csum("tien_thue_options"),$r$$.t_tien_hang=$r$$.t_tien_hang_ct+$r$$.t_thue,$r$$.t_tien_hang_nt=$r$$.t_tien_hang_ct_nt+$r$$.t_thue_nt,$r$$.t_ck=$r$$.details.csum("tien_ck")+$r$$.tien_ck_hd+($r$$.tien_evoucher||0),$r$$.t_ck_nt=$r$$.details.csum("tien_ck_nt")+$r$$.tien_ck_hd+($r$$.tien_evoucher||
14
- 0),$r$$.t_tien_nt=$r$$.details.csum("tien_nt"),$r$$.t_tien=$r$$.details.csum("tien"),$r$$.t_tt=$r$$.t_tt_nt=$r$$.t_tien_hang_ct_nt+$r$$.t_thue_nt-$r$$.t_ck_nt,$r$$.con_no=$r$$.t_tt-($r$$.tien_thu||0)-($r$$.tien_thu2||0)-($r$$.tien_paymentByPoints||0),$r$$.con_no<0&&($r$$.con_no=0),$r$$.t_tien_xuat=$r$$.details.csum("tien_xuat"),$r$$.t_tien_xuat_nt=$r$$.details.csum("tien_xuat_nt"))},taothongtinchuyenkhoan=async($bank_bin$jscomp$1_user$$,$r$$)=>{if($r$$.trang_thai!="6"&&$r$$.trang_thai!="9"){var $amount_bank_name_bank_name$$=
15
- $r$$.t_tt-($r$$.tien_paymentByPoints||0);if($amount_bank_name_bank_name$$>0&&$r$$.pt_thanh_toan){var $amount$jscomp$2_bank_bin_pttt_pttt$$=await ptthanhtoan.findOne({id_app:$r$$.id_app,_id:$r$$.pt_thanh_toan,payment_service:"bank"}).lean();if($amount$jscomp$2_bank_bin_pttt_pttt$$&&$amount$jscomp$2_bank_bin_pttt_pttt$$.payment_service=="bank"&&$bank_bin$jscomp$1_user$$.current_app_info){$amount_bank_name_bank_name$$=($amount$jscomp$2_bank_bin_pttt_pttt$$.bank_configs||{}).bank_name||$bank_bin$jscomp$1_user$$.current_app_info.ten_ngan_hang;
16
- var $bank_account_number_bank_account_number$$=($amount$jscomp$2_bank_bin_pttt_pttt$$.bank_configs||{}).bank_account_number||$bank_bin$jscomp$1_user$$.current_app_info.tai_khoan_ngan_hang,$bank_account_name_bank_account_name$$=($amount$jscomp$2_bank_bin_pttt_pttt$$.bank_configs||{}).bank_account_name||$bank_bin$jscomp$1_user$$.current_app_info.ten_chu_tai_khoan;$amount$jscomp$2_bank_bin_pttt_pttt$$=($amount$jscomp$2_bank_bin_pttt_pttt$$.bank_configs||{}).so_bin||$bank_bin$jscomp$1_user$$.current_app_info.so_bin;
17
- var $amount$jscomp$1_purpose$$=$r$$.t_tt,$purpose_qrcode$$=`TTDH ${$r$$.so_ct} ${$r$$._id.toString()}`;const $qrcode$$=QRPay.initVietQR({bankBin:$amount$jscomp$2_bank_bin_pttt_pttt$$,bankNumber:$bank_account_number_bank_account_number$$,amount:$amount$jscomp$1_purpose$$.toString(),purpose:$purpose_qrcode$$}).build();$r$$.bank_payment_info={bank_name:$amount_bank_name_bank_name$$,bank_bin:$amount$jscomp$2_bank_bin_pttt_pttt$$,bank_account_number:$bank_account_number_bank_account_number$$,bank_account_name:$bank_account_name_bank_account_name$$,
18
- amount:$amount$jscomp$1_purpose$$,purpose:$purpose_qrcode$$,qrcode:$qrcode$$}}else $r$$.bank_payment_info=void 0}else $r$$.bank_payment_info=void 0;$amount_bank_name_bank_name$$=$r$$.t_tt-($r$$.tien_thu||0)-($r$$.tien_paymentByPoints||0);$amount_bank_name_bank_name$$>0&&$r$$.pt_thanh_toan2?($amount$jscomp$2_bank_bin_pttt_pttt$$=await ptthanhtoan.findOne({id_app:$r$$.id_app,_id:$r$$.pt_thanh_toan2,payment_service:"bank"}).lean())&&$amount$jscomp$2_bank_bin_pttt_pttt$$.payment_service=="bank"&&$bank_bin$jscomp$1_user$$.current_app_info?
19
- ($amount_bank_name_bank_name$$=($amount$jscomp$2_bank_bin_pttt_pttt$$.bank_configs||{}).bank_name||$bank_bin$jscomp$1_user$$.current_app_info.ten_ngan_hang,$bank_account_number_bank_account_number$$=($amount$jscomp$2_bank_bin_pttt_pttt$$.bank_configs||{}).bank_account_number||$bank_bin$jscomp$1_user$$.current_app_info.tai_khoan_ngan_hang,$bank_account_name_bank_account_name$$=($amount$jscomp$2_bank_bin_pttt_pttt$$.bank_configs||{}).bank_account_name||$bank_bin$jscomp$1_user$$.current_app_info.ten_chu_tai_khoan,
20
- $bank_bin$jscomp$1_user$$=($amount$jscomp$2_bank_bin_pttt_pttt$$.bank_configs||{}).so_bin||$bank_bin$jscomp$1_user$$.current_app_info.so_bin,$amount$jscomp$2_bank_bin_pttt_pttt$$=$r$$.t_tt,$amount$jscomp$1_purpose$$=`TTDH ${$r$$.so_ct} ${$r$$._id.toString()}`,$purpose_qrcode$$=QRPay.initVietQR({bankBin:$bank_bin$jscomp$1_user$$,bankNumber:$bank_account_number_bank_account_number$$,amount:$amount$jscomp$2_bank_bin_pttt_pttt$$.toString(),purpose:$amount$jscomp$1_purpose$$}).build(),$r$$.bank_payment_info2=
21
- {bank_name:$amount_bank_name_bank_name$$,bank_bin:$bank_bin$jscomp$1_user$$,bank_account_number:$bank_account_number_bank_account_number$$,bank_account_name:$bank_account_name_bank_account_name$$,amount:$amount$jscomp$2_bank_bin_pttt_pttt$$,purpose:$amount$jscomp$1_purpose$$,qrcode:$purpose_qrcode$$}):$r$$.bank_payment_info2=void 0:$r$$.bank_payment_info2=void 0}},getPointBalance=async($id_app$$,$user$$)=>new Promise(($resolve$$,$reject$$)=>{ckdiem({id_app:$id_app$$,email:$user$$},($e$$,$rs$$)=>{if($e$$)return $reject$$(Error($e$$));
22
- $resolve$$($rs$$.length===0?0:$rs$$[0].ton00)})}),createTransactionBonus=async function($obj$$){if($obj$$.trang_thai!=="5")return await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng \u0111\u1ec3 t\u00ednh l\u1ea1i"),null;let $kh$$=await customer.findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh});if(!$kh$$)return await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng \u0111\u1ec3 t\u00ednh l\u1ea1i"),
23
- null;const $receiver$$=$kh$$.of_user||$kh$$.ma_kh;let $lan_mua$$=(await model.find({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh,ngay_ct:{$lte:$obj$$.ngay_ct}})).length+1;let $now$$=moment(new Date).startOf("date").toDate();var $amount$$=$obj$$.details.filter($d$$=>$d$$.tien_hang).map(async $d$$=>{var $amount$$=await dmvt.findOne({ma_vt:$d$$.ma_vt,id_app:$obj$$.id_app}).lean(),$ckdiemthuong_ty_le_diem_thuong$$=await dmdiemthuong.find({id_app:$obj$$.id_app,status:!0,ma_kh:{$in:[null,"",$kh$$.ma_kh]},ma_kho:{$in:[null,
24
- "",$obj$$.ma_kho]},nh_kh:{$in:[null,"",$kh$$.nh_kh]},hieu_luc_tu:{$lte:$now$$},hieu_luc_den:{$gte:$now$$},ap_dung_lan_mua_thu:{$in:[null,0,$lan_mua$$]},ma_vt:{$in:[null,"",void 0,$d$$.ma_vt]},ma_nvt:{$in:[null,"",void 0,$amount$$?$amount$$.ma_nvt:""]}}).sort({ma_vt:-1,ma_nvt:-1,hieu_luc_tu:-1}).limit(1).lean();return $ckdiemthuong_ty_le_diem_thuong$$.length>0?($amount$$=0,$ckdiemthuong_ty_le_diem_thuong$$[0].tien?($ckdiemthuong_ty_le_diem_thuong$$=$ckdiemthuong_ty_le_diem_thuong$$[0].diem/$ckdiemthuong_ty_le_diem_thuong$$[0].tien)&&
25
- ($amount$$=Math.roundBy(($d$$.tien_hang-($d$$.tien_ck||0))*$ckdiemthuong_ty_le_diem_thuong$$,0)):$amount$$=$ckdiemthuong_ty_le_diem_thuong$$[0].diem*($d$$.sl_xuat||1),$amount$$):0});if($amount$$=(await Promise.all($amount$$)).reduce(($a$$,$b$$)=>$a$$+$b$$,0)){var $old_trans$$=await transaction.findOne({id_ct:$obj$$._id.toString()+":bonus"});if(!$old_trans$$||$old_trans$$.amount!==$amount$$)return await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng \u0111\u1ec3 t\u00ednh l\u1ea1i"),
26
- await transaction.createTrans({id_app:$obj$$.id_app,sender_email:$obj$$.id_app,receiver_email:$receiver$$,amount:$amount$$,description:"\u0110i\u1ec3m th\u01b0\u1edfng mua h\u00e0ng",otherData:{ma_ct:$obj$$.ma_ct,so_ct:$obj$$.so_ct,ngay_ct:$obj$$.ngay_ct,id_ct:$obj$$._id.toString()+":bonus"}})}else await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng \u0111\u1ec3 t\u00ednh l\u1ea1i")},createTransactionPayment=async function($obj$$,
27
- $user_payment$$){await transaction.deleteTrans({id_ct:$obj$$._id.toString()});let $amount$$=$obj$$.paymentByPoints;$amount$$&&($user_payment$$=$user_payment$$||$obj$$.user_created,await transaction.createTrans({id_app:$obj$$.id_app,sender_email:$user_payment$$,receiver_email:$obj$$.id_app,amount:$amount$$,description:"Thanh to\u00e1n cho bill "+$obj$$.so_ct,otherData:{ma_ct:$obj$$.ma_ct,so_ct:$obj$$.so_ct,ngay_ct:$obj$$.ngay_ct,id_ct:$obj$$._id.toString()}}))},checkEvoucher=($user$$,$obj$$)=>{let $gt_don_hang$$=
28
- $obj$$.details.map($d$$=>($d$$.tien_hang_ct_nt||0)-($d$$.tien_ck_nt||0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0);return($obj$$.evouchers||[]).map($ev$$=>new Promise(($resolve$$,$reject$$)=>{(async()=>{var $cust_date_created_id_ct_so_tien_giam$$=($obj$$._id||"").toString();const $_e$$=await Evoucher.findOne({ma:$ev$$.ma,id_app:$user$$.current_id_app});if(!$_e$$)return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} kh\u00f4ng t\u1ed3n t\u1ea1i`));if($_e$$.id_ct_used&&$_e$$.id_ct_used!==$cust_date_created_id_ct_so_tien_giam$$)return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} \u0111\u00e3 \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng`));
29
- if($_e$$.so_lan_sd>=1&&$_e$$.id_ct_useds&&$_e$$.id_ct_useds.length>0&&($_e$$.id_ct_useds=[...(new Set([...$_e$$.id_ct_useds]))],$_e$$.id_ct_useds.length>=$_e$$.so_lan_sd&&(!$obj$$._id||$_e$$.id_ct_useds.indexOf($obj$$._id)<0)))return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} \u0111\u00e3 \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng h\u1ebft`));if($_e$$.user){if(!$obj$$.ma_kh)return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} n\u00e0y ch\u1ec9 s\u1eed d\u1ee5ng cho m\u1ed9t kh\u00e1ch h\u00e0ng c\u1ee5 th\u1ec3`));
30
- $cust_date_created_id_ct_so_tien_giam$$=await global.getModel("customer").findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh},{of_user:1});if(!$cust_date_created_id_ct_so_tien_giam$$||$cust_date_created_id_ct_so_tien_giam$$.of_user!==$_e$$.user)return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} kh\u00f4ng th\u1ec3 \u00e1p d\u1ee5ng cho kh\u00e1ch h\u00e0ng n\u00e0y`))}$cust_date_created_id_ct_so_tien_giam$$=new Date($obj$$.date_created);if(moment($_e$$.hieu_luc_den).endOf("date").toDate().getTime()<
31
- $cust_date_created_id_ct_so_tien_giam$$.getTime())return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} \u0111\u00e3 h\u1ebft h\u1ea1n s\u1eed d\u1ee5ng`));if($_e$$.gt_don_hang_toi_thieu&&$gt_don_hang$$<$_e$$.gt_don_hang_toi_thieu)return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} ch\u1ec9 \u00e1p d\u1ee5ng cho c\u00e1c \u0111\u01a1n h\u00e0ng c\u00f3 gi\u00e1 tr\u1ecb l\u1edbn h\u01a1n ho\u1eb7c b\u1eb1ng ${numeral($_e$$.gt_don_hang_toi_thieu).format()}`));if($_e$$.vts&&$_e$$.vts.length>
32
- 0&&$_e$$.sl_toi_thieu){let $sl_dap_ung$$=0;$_e$$.vts.forEach($vt$$=>{var $ds$jscomp$1_tien$$=$obj$$.details.filter($d$$=>$d$$.ma_vt===$vt$$.ma_vt&&(!$vt$$.ma_tt1||$vt$$.ma_tt1===$d$$.ma_tt1)&&(!$vt$$.ma_tt2||$vt$$.ma_tt2===$d$$.ma_tt2)&&(!$vt$$.ma_tt3||$vt$$.ma_tt3===$d$$.ma_tt3));if($ds$jscomp$1_tien$$.length!=0){var $so_luong$$=$ds$jscomp$1_tien$$.map($d$$=>$d$$.sl_xuat).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$ds$jscomp$1_tien$$=$ds$jscomp$1_tien$$.map($d$$=>($d$$.tien_hang_ct_nt||0)-($d$$.tien_ck_nt||
33
- 0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$vt$$.sl_tu&&$so_luong$$<$vt$$.sl_tu||$vt$$.sl_den&&$so_luong$$>$vt$$.sl_den||$vt$$.gt_tu&&$ds$jscomp$1_tien$$<$vt$$.gt_tu||$vt$$.gt_den&&$ds$jscomp$1_tien$$>$vt$$.gt_den||($sl_dap_ung$$+=1)}});if($_e$$.sl_toi_thieu>$sl_dap_ung$$)return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} kh\u00f4ng h\u1ee3p l\u1ec7 do kh\u00f4ng \u0111\u00e1p \u1ee9ng \u0111\u01b0\u1ee3c y\u00eau c\u1ea7u s\u1ea3n ph\u1ea9m`))}$cust_date_created_id_ct_so_tien_giam$$=$_e$$.so_tien;
34
- $_e$$.ty_le&&($cust_date_created_id_ct_so_tien_giam$$=Math.roundBy($gt_don_hang$$*$_e$$.ty_le/100));$_e$$.so_tien_max&&$cust_date_created_id_ct_so_tien_giam$$>$_e$$.so_tien_max&&($cust_date_created_id_ct_so_tien_giam$$=$_e$$.so_tien_max);if($ev$$.so_tien_giam!==$cust_date_created_id_ct_so_tien_giam$$)return $reject$$(Error(`S\u1ed1 ti\u1ec1n gi\u1ea3m cho th\u1ebb ${$ev$$.ma} kh\u00f4ng h\u1ee3p l\u1ec7`));$ev$$.so_tien_giam=$cust_date_created_id_ct_so_tien_giam$$;$resolve$$(!0)})()}))},updateEvoucher=
35
- async($id_app$jscomp$1_rs$$,$evoucher_code$$,$id_ct$$)=>{$id_ct$$=$id_ct$$.toString();var $e$$=await Evoucher.findOne({ma:$evoucher_code$$,id_app:$id_app$jscomp$1_rs$$});$e$$?($e$$=$e$$.id_ct_useds||[],$e$$.push($id_ct$$),$e$$=[...(new Set($e$$))],$id_app$jscomp$1_rs$$=await Evoucher.findOneAndUpdate({ma:$evoucher_code$$,id_app:$id_app$jscomp$1_rs$$},{id_ct_useds:$e$$}),console.log("update id_ct_useds",$evoucher_code$$,$e$$,$id_app$jscomp$1_rs$$)):console.error("can't find evoucher",$evoucher_code$$)},
36
- deleteEvoucher=async($id_app$jscomp$2_id_ct_useds$$,$evoucher_code$$,$id_ct$$)=>{if($evoucher_code$$){$id_ct$$=$id_ct$$.toString();var $e$jscomp$2_rs$$=await Evoucher.findOne({id_app:$id_app$jscomp$2_id_ct_useds$$,ma:$evoucher_code$$});$e$jscomp$2_rs$$&&($id_app$jscomp$2_id_ct_useds$$=($e$jscomp$2_rs$$.id_ct_useds||[]).filter($ct$$=>$ct$$!==$id_ct$$),$e$jscomp$2_rs$$=await Evoucher.findOneAndUpdate({_id:$e$jscomp$2_rs$$._id},{id_ct_useds:$id_app$jscomp$2_id_ct_useds$$}),console.log("update id_ct_useds",
37
- $evoucher_code$$,$id_app$jscomp$2_id_ct_useds$$,$e$jscomp$2_rs$$))}},valid=async function($_opt_t_tien_evoucher_user$$,$obj$$,$next$$,$pre_obj_tien_con_lai$$){$pre_obj_tien_con_lai$$&&($obj$$._id=$pre_obj_tien_con_lai$$._id,$obj$$.details=$obj$$.details||$pre_obj_tien_con_lai$$.details||[],$obj$$.evouchers=$obj$$.evouchers||$pre_obj_tien_con_lai$$.evouchers||[]);$obj$$.details=$obj$$.details||[];if($obj$$.signature&&!await Wallet.verifySignature($obj$$.id_app,$obj$$.sign_user,$obj$$.sign_data,$obj$$.signature))return $next$$("Signature is not valid");
38
- try{await Promise.all(($obj$$.details||[]).map($detail$$=>(async()=>{if($detail$$.signature&&!await Wallet.verifySignature($obj$$.id_app,$detail$$.sign_user,$detail$$.sign_data,$detail$$.signature))throw"Signature is not valid";})()))}catch($e$$){return $next$$($e$$||$e$$.message)}await $obj$$.details.asyncJoinModel2($obj$$.id_app,vat,{where:"ma_thue",fields:["thue_suat","tk_thue_co","tk_thue_co_treo"]});for(let $i$$=0;$i$$<$obj$$.details.length;$i$$++){const $detail$$=$obj$$.details[$i$$];if($detail$$.line==
39
- null||$detail$$.line==void 0)$detail$$.line=(new Date).getTime();$detail$$.tien_hang=$detail$$.tien_hang_nt=Math.roundBy($detail$$.tien_hang_nt);$detail$$.tien_ck=$detail$$.tien_ck_nt=Math.roundBy($detail$$.tien_ck_nt||0);$detail$$.gia_ban=$detail$$.gia_ban_nt;$detail$$.ma_kho=$obj$$.ma_kho;$detail$$.tien_xuat=$detail$$.tien_xuat_nt=Math.roundBy($detail$$.tien_xuat_nt||0);tinhtienthue($detail$$);$detail$$.options=$detail$$.options||[];for(let $i_o$$=0;$i_o$$<$detail$$.options.length;$i_o$$++){let $o$$=
40
- $detail$$.options[0];$o$$.details=$o$$.details||[];await $o$$.details.asyncJoinModel2($obj$$.id_app,vat,{where:"ma_thue",fields:["thue_suat","tk_thue_co","tk_thue_co_treo"]});$o$$.details.filter($d$$=>$d$$.sl_xuat).forEach($d$$=>{$d$$.tien_hang=$d$$.tien_hang_nt=$d$$.sl_xuat*($d$$.gia_ban_nt||0);tinhtienthue($d$$)});$o$$.tien_hang_nt=$o$$.details.map($d$$=>$d$$.tien_hang_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$o$$.tien_hang_ct_nt=$o$$.details.map($d$$=>$d$$.tien_hang_ct_nt).reduce(($a$$,$b$$)=>$a$$+
41
- $b$$,0);$o$$.tien_thue_nt=$o$$.details.map($d$$=>$d$$.tien_thue_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0)}$detail$$.tien_hang_options=$detail$$.options.map($o$$=>$o$$.tien_hang_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$detail$$.tien_hang_options_ct=$detail$$.options.map($o$$=>$o$$.tien_hang_ct_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$detail$$.tien_thue_options=$detail$$.options.map($o$$=>$o$$.tien_thue_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$detail$$.tien=$detail$$.tien_nt=$detail$$.tien_hang_ct_nt-$detail$$.tien_ck_nt+
42
- $detail$$.tien_thue_nt+$detail$$.tien_hang_options_ct+$detail$$.tien_thue_options}await $obj$$.details.filter($d$$=>!$d$$.ma_dvt&&$d$$.ma_tt1).asyncJoinModel2($_opt_t_tien_evoucher_user$$.current_id_app,dmtt,{where:{ma_vt:"ma_vt",ma_tt1:"ma_tt"},fields:"ma_dvt"});await $obj$$.details.filter($d$$=>!$d$$.ma_dvt&&$d$$.ma_tt2).asyncJoinModel2($_opt_t_tien_evoucher_user$$.current_id_app,dmtt,{where:{ma_vt:"ma_vt",ma_tt2:"ma_tt"},fields:"ma_dvt"});await $obj$$.details.filter($d$$=>!$d$$.ma_dvt&&$d$$.ma_tt3).asyncJoinModel2($_opt_t_tien_evoucher_user$$.current_id_app,
11
+ $user$$.current_app_info&&($user$$.current_app_info.options||{}).tinh_lai_chiet_khau_pbl!=0&&dmchietkhauhd.tinhChietKhau($user$$,$obj$$.id_app,$obj$$,$t_tien_hang_ct_nt$$-$t_ck_nt$$)}},tinhtienthue=$detail$$=>{$detail$$.tien_thue_nt?$detail$$.tien_thue=$detail$$.tien_thue_nt:($detail$$.thue_suat=$detail$$.thue_suat||0,$detail$$.gia_ban_ct_nt=$detail$$.gia_ban_ct=Math.roundBy($detail$$.gia_ban_nt/(1+$detail$$.thue_suat/100)),$detail$$.tien_hang_ct=$detail$$.tien_hang_ct_nt=Math.roundBy($detail$$.sl_xuat*
12
+ $detail$$.gia_ban_ct_nt),$detail$$.ty_le_ck&&($detail$$.tien_ck_nt=Math.roundBy($detail$$.tien_hang_ct_nt*$detail$$.ty_le_ck/100)),$detail$$.tien_thue=$detail$$.tien_thue_nt=Math.roundBy(($detail$$.tien_hang_ct_nt-$detail$$.tien_ck_nt)*$detail$$.thue_suat/100))},tinhtongtien=$r$$=>{$r$$.details&&($r$$.details.forEach($d$$=>{$d$$.sl_order=$d$$.sl_order||$d$$.sl_xuat}),$r$$.t_sl_order=$r$$.details.csum("sl_order"),$r$$.t_sl=$r$$.details.csum("sl_xuat"),$r$$.t_tien_hang_ct=$r$$.details.csum("tien_hang_ct")+
13
+ $r$$.details.csum("tien_hang_options_ct"),$r$$.t_tien_hang_ct_nt=$r$$.details.csum("tien_hang_ct_nt")+$r$$.details.csum("tien_hang_options_ct"),$r$$.t_thue_nt=$r$$.details.csum("tien_thue_nt")+$r$$.details.csum("tien_thue_options"),$r$$.t_thue=$r$$.details.csum("tien_thue")+$r$$.details.csum("tien_thue_options"),$r$$.t_tien_hang=$r$$.t_tien_hang_ct+$r$$.t_thue,$r$$.t_tien_hang_nt=$r$$.t_tien_hang_ct_nt+$r$$.t_thue_nt,$r$$.t_ck=$r$$.details.csum("tien_ck")+$r$$.tien_ck_hd+($r$$.tien_evoucher||0),$r$$.t_ck_nt=
14
+ $r$$.details.csum("tien_ck_nt")+$r$$.tien_ck_hd+($r$$.tien_evoucher||0),$r$$.t_tien_nt=$r$$.details.csum("tien_nt"),$r$$.t_tien=$r$$.details.csum("tien"),$r$$.t_tt=$r$$.t_tt_nt=$r$$.t_tien_hang_ct_nt+$r$$.t_thue_nt-$r$$.t_ck_nt,$r$$.con_no=$r$$.t_tt-($r$$.tien_thu||0)-($r$$.tien_thu2||0)-($r$$.tien_paymentByPoints||0),$r$$.con_no<0&&($r$$.con_no=0),$r$$.t_tien_xuat=$r$$.details.csum("tien_xuat"),$r$$.t_tien_xuat_nt=$r$$.details.csum("tien_xuat_nt"))},taothongtinchuyenkhoan=async($bank_bin$jscomp$1_user$$,
15
+ $r$$)=>{if($r$$.trang_thai!="6"&&$r$$.trang_thai!="9"){var $amount_bank_name_bank_name$$=$r$$.t_tt-($r$$.tien_paymentByPoints||0);if($amount_bank_name_bank_name$$>0&&$r$$.pt_thanh_toan){var $amount$jscomp$2_bank_bin_pttt_pttt$$=await ptthanhtoan.findOne({id_app:$r$$.id_app,_id:$r$$.pt_thanh_toan,payment_service:"bank"}).lean();if($amount$jscomp$2_bank_bin_pttt_pttt$$&&$amount$jscomp$2_bank_bin_pttt_pttt$$.payment_service=="bank"&&$bank_bin$jscomp$1_user$$.current_app_info){$amount_bank_name_bank_name$$=
16
+ ($amount$jscomp$2_bank_bin_pttt_pttt$$.bank_configs||{}).bank_name||$bank_bin$jscomp$1_user$$.current_app_info.ten_ngan_hang;var $bank_account_number_bank_account_number$$=($amount$jscomp$2_bank_bin_pttt_pttt$$.bank_configs||{}).bank_account_number||$bank_bin$jscomp$1_user$$.current_app_info.tai_khoan_ngan_hang,$bank_account_name_bank_account_name$$=($amount$jscomp$2_bank_bin_pttt_pttt$$.bank_configs||{}).bank_account_name||$bank_bin$jscomp$1_user$$.current_app_info.ten_chu_tai_khoan;$amount$jscomp$2_bank_bin_pttt_pttt$$=
17
+ ($amount$jscomp$2_bank_bin_pttt_pttt$$.bank_configs||{}).so_bin||$bank_bin$jscomp$1_user$$.current_app_info.so_bin;var $amount$jscomp$1_purpose$$=$r$$.t_tt,$purpose_qrcode$$=`TTDH ${$r$$.so_ct} ${$r$$._id.toString()}`;const $qrcode$$=QRPay.initVietQR({bankBin:$amount$jscomp$2_bank_bin_pttt_pttt$$,bankNumber:$bank_account_number_bank_account_number$$,amount:$amount$jscomp$1_purpose$$.toString(),purpose:$purpose_qrcode$$}).build();$r$$.bank_payment_info={bank_name:$amount_bank_name_bank_name$$,bank_bin:$amount$jscomp$2_bank_bin_pttt_pttt$$,
18
+ bank_account_number:$bank_account_number_bank_account_number$$,bank_account_name:$bank_account_name_bank_account_name$$,amount:$amount$jscomp$1_purpose$$,purpose:$purpose_qrcode$$,qrcode:$qrcode$$}}else $r$$.bank_payment_info=void 0}else $r$$.bank_payment_info=void 0;$amount_bank_name_bank_name$$=$r$$.t_tt-($r$$.tien_thu||0)-($r$$.tien_paymentByPoints||0);$amount_bank_name_bank_name$$>0&&$r$$.pt_thanh_toan2?($amount$jscomp$2_bank_bin_pttt_pttt$$=await ptthanhtoan.findOne({id_app:$r$$.id_app,_id:$r$$.pt_thanh_toan2,
19
+ payment_service:"bank"}).lean())&&$amount$jscomp$2_bank_bin_pttt_pttt$$.payment_service=="bank"&&$bank_bin$jscomp$1_user$$.current_app_info?($amount_bank_name_bank_name$$=($amount$jscomp$2_bank_bin_pttt_pttt$$.bank_configs||{}).bank_name||$bank_bin$jscomp$1_user$$.current_app_info.ten_ngan_hang,$bank_account_number_bank_account_number$$=($amount$jscomp$2_bank_bin_pttt_pttt$$.bank_configs||{}).bank_account_number||$bank_bin$jscomp$1_user$$.current_app_info.tai_khoan_ngan_hang,$bank_account_name_bank_account_name$$=
20
+ ($amount$jscomp$2_bank_bin_pttt_pttt$$.bank_configs||{}).bank_account_name||$bank_bin$jscomp$1_user$$.current_app_info.ten_chu_tai_khoan,$bank_bin$jscomp$1_user$$=($amount$jscomp$2_bank_bin_pttt_pttt$$.bank_configs||{}).so_bin||$bank_bin$jscomp$1_user$$.current_app_info.so_bin,$amount$jscomp$2_bank_bin_pttt_pttt$$=$r$$.t_tt,$amount$jscomp$1_purpose$$=`TTDH ${$r$$.so_ct} ${$r$$._id.toString()}`,$purpose_qrcode$$=QRPay.initVietQR({bankBin:$bank_bin$jscomp$1_user$$,bankNumber:$bank_account_number_bank_account_number$$,
21
+ amount:$amount$jscomp$2_bank_bin_pttt_pttt$$.toString(),purpose:$amount$jscomp$1_purpose$$}).build(),$r$$.bank_payment_info2={bank_name:$amount_bank_name_bank_name$$,bank_bin:$bank_bin$jscomp$1_user$$,bank_account_number:$bank_account_number_bank_account_number$$,bank_account_name:$bank_account_name_bank_account_name$$,amount:$amount$jscomp$2_bank_bin_pttt_pttt$$,purpose:$amount$jscomp$1_purpose$$,qrcode:$purpose_qrcode$$}):$r$$.bank_payment_info2=void 0:$r$$.bank_payment_info2=void 0}},getPointBalance=
22
+ async($id_app$$,$user$$)=>new Promise(($resolve$$,$reject$$)=>{ckdiem({id_app:$id_app$$,email:$user$$},($e$$,$rs$$)=>{if($e$$)return $reject$$(Error($e$$));$resolve$$($rs$$.length===0?0:$rs$$[0].ton00)})}),createTransactionBonus=async function($obj$$){if($obj$$.trang_thai!=="5")return await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng \u0111\u1ec3 t\u00ednh l\u1ea1i"),null;let $kh$$=await customer.findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh});
23
+ if(!$kh$$)return await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng \u0111\u1ec3 t\u00ednh l\u1ea1i"),null;const $receiver$$=$kh$$.of_user||$kh$$.ma_kh;let $lan_mua$$=(await model.find({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh,ngay_ct:{$lte:$obj$$.ngay_ct}})).length+1;let $now$$=moment(new Date).startOf("date").toDate();var $amount$$=$obj$$.details.filter($d$$=>$d$$.tien_hang).map(async $d$$=>{var $amount$$=await dmvt.findOne({ma_vt:$d$$.ma_vt,
24
+ id_app:$obj$$.id_app}).lean(),$ckdiemthuong_ty_le_diem_thuong$$=await dmdiemthuong.find({id_app:$obj$$.id_app,status:!0,ma_kh:{$in:[null,"",$kh$$.ma_kh]},ma_kho:{$in:[null,"",$obj$$.ma_kho]},nh_kh:{$in:[null,"",$kh$$.nh_kh]},hieu_luc_tu:{$lte:$now$$},hieu_luc_den:{$gte:$now$$},ap_dung_lan_mua_thu:{$in:[null,0,$lan_mua$$]},ma_vt:{$in:[null,"",void 0,$d$$.ma_vt]},ma_nvt:{$in:[null,"",void 0,$amount$$?$amount$$.ma_nvt:""]}}).sort({ma_vt:-1,ma_nvt:-1,hieu_luc_tu:-1}).limit(1).lean();return $ckdiemthuong_ty_le_diem_thuong$$.length>
25
+ 0?($amount$$=0,$ckdiemthuong_ty_le_diem_thuong$$[0].tien?($ckdiemthuong_ty_le_diem_thuong$$=$ckdiemthuong_ty_le_diem_thuong$$[0].diem/$ckdiemthuong_ty_le_diem_thuong$$[0].tien)&&($amount$$=Math.roundBy(($d$$.tien_hang-($d$$.tien_ck||0))*$ckdiemthuong_ty_le_diem_thuong$$,0)):$amount$$=$ckdiemthuong_ty_le_diem_thuong$$[0].diem*($d$$.sl_xuat||1),$amount$$):0});if($amount$$=(await Promise.all($amount$$)).reduce(($a$$,$b$$)=>$a$$+$b$$,0)){var $old_trans$$=await transaction.findOne({id_ct:$obj$$._id.toString()+
26
+ ":bonus"});if(!$old_trans$$||$old_trans$$.amount!==$amount$$)return await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng \u0111\u1ec3 t\u00ednh l\u1ea1i"),await transaction.createTrans({id_app:$obj$$.id_app,sender_email:$obj$$.id_app,receiver_email:$receiver$$,amount:$amount$$,description:"\u0110i\u1ec3m th\u01b0\u1edfng mua h\u00e0ng",otherData:{ma_ct:$obj$$.ma_ct,so_ct:$obj$$.so_ct,ngay_ct:$obj$$.ngay_ct,id_ct:$obj$$._id.toString()+
27
+ ":bonus"}})}else await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng \u0111\u1ec3 t\u00ednh l\u1ea1i")},createTransactionPayment=async function($obj$$,$user_payment$$){await transaction.deleteTrans({id_ct:$obj$$._id.toString()});let $amount$$=$obj$$.paymentByPoints;$amount$$&&($user_payment$$=$user_payment$$||$obj$$.user_created,await transaction.createTrans({id_app:$obj$$.id_app,sender_email:$user_payment$$,receiver_email:$obj$$.id_app,
28
+ amount:$amount$$,description:"Thanh to\u00e1n cho bill "+$obj$$.so_ct,otherData:{ma_ct:$obj$$.ma_ct,so_ct:$obj$$.so_ct,ngay_ct:$obj$$.ngay_ct,id_ct:$obj$$._id.toString()}}))},checkEvoucher=($user$$,$obj$$)=>{let $gt_don_hang$$=$obj$$.details.map($d$$=>($d$$.tien_hang_ct_nt||0)-($d$$.tien_ck_nt||0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0);return($obj$$.evouchers||[]).map($ev$$=>new Promise(($resolve$$,$reject$$)=>{(async()=>{var $cust_date_created_id_ct_so_tien_giam$$=($obj$$._id||"").toString();const $_e$$=
29
+ await Evoucher.findOne({ma:$ev$$.ma,id_app:$user$$.current_id_app});if(!$_e$$)return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} kh\u00f4ng t\u1ed3n t\u1ea1i`));if($_e$$.id_ct_used&&$_e$$.id_ct_used!==$cust_date_created_id_ct_so_tien_giam$$)return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} \u0111\u00e3 \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng`));if($_e$$.so_lan_sd>=1&&$_e$$.id_ct_useds&&$_e$$.id_ct_useds.length>0&&($_e$$.id_ct_useds=[...(new Set([...$_e$$.id_ct_useds]))],$_e$$.id_ct_useds.length>=
30
+ $_e$$.so_lan_sd&&(!$obj$$._id||$_e$$.id_ct_useds.indexOf($obj$$._id)<0)))return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} \u0111\u00e3 \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng h\u1ebft`));if($_e$$.user){if(!$obj$$.ma_kh)return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} n\u00e0y ch\u1ec9 s\u1eed d\u1ee5ng cho m\u1ed9t kh\u00e1ch h\u00e0ng c\u1ee5 th\u1ec3`));$cust_date_created_id_ct_so_tien_giam$$=await global.getModel("customer").findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh},{of_user:1});
31
+ if(!$cust_date_created_id_ct_so_tien_giam$$||$cust_date_created_id_ct_so_tien_giam$$.of_user!==$_e$$.user)return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} kh\u00f4ng th\u1ec3 \u00e1p d\u1ee5ng cho kh\u00e1ch h\u00e0ng n\u00e0y`))}$cust_date_created_id_ct_so_tien_giam$$=new Date($obj$$.date_created);if(moment($_e$$.hieu_luc_den).endOf("date").toDate().getTime()<$cust_date_created_id_ct_so_tien_giam$$.getTime())return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} \u0111\u00e3 h\u1ebft h\u1ea1n s\u1eed d\u1ee5ng`));
32
+ if($_e$$.gt_don_hang_toi_thieu&&$gt_don_hang$$<$_e$$.gt_don_hang_toi_thieu)return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} ch\u1ec9 \u00e1p d\u1ee5ng cho c\u00e1c \u0111\u01a1n h\u00e0ng c\u00f3 gi\u00e1 tr\u1ecb l\u1edbn h\u01a1n ho\u1eb7c b\u1eb1ng ${numeral($_e$$.gt_don_hang_toi_thieu).format()}`));if($_e$$.vts&&$_e$$.vts.length>0&&$_e$$.sl_toi_thieu){let $sl_dap_ung$$=0;$_e$$.vts.forEach($vt$$=>{var $ds$jscomp$1_tien$$=$obj$$.details.filter($d$$=>$d$$.ma_vt===$vt$$.ma_vt&&(!$vt$$.ma_tt1||
33
+ $vt$$.ma_tt1===$d$$.ma_tt1)&&(!$vt$$.ma_tt2||$vt$$.ma_tt2===$d$$.ma_tt2)&&(!$vt$$.ma_tt3||$vt$$.ma_tt3===$d$$.ma_tt3));if($ds$jscomp$1_tien$$.length!=0){var $so_luong$$=$ds$jscomp$1_tien$$.map($d$$=>$d$$.sl_xuat).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$ds$jscomp$1_tien$$=$ds$jscomp$1_tien$$.map($d$$=>($d$$.tien_hang_ct_nt||0)-($d$$.tien_ck_nt||0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$vt$$.sl_tu&&$so_luong$$<$vt$$.sl_tu||$vt$$.sl_den&&$so_luong$$>$vt$$.sl_den||$vt$$.gt_tu&&$ds$jscomp$1_tien$$<$vt$$.gt_tu||
34
+ $vt$$.gt_den&&$ds$jscomp$1_tien$$>$vt$$.gt_den||($sl_dap_ung$$+=1)}});if($_e$$.sl_toi_thieu>$sl_dap_ung$$)return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} kh\u00f4ng h\u1ee3p l\u1ec7 do kh\u00f4ng \u0111\u00e1p \u1ee9ng \u0111\u01b0\u1ee3c y\u00eau c\u1ea7u s\u1ea3n ph\u1ea9m`))}$cust_date_created_id_ct_so_tien_giam$$=$_e$$.so_tien;$_e$$.ty_le&&($cust_date_created_id_ct_so_tien_giam$$=Math.roundBy($gt_don_hang$$*$_e$$.ty_le/100));$_e$$.so_tien_max&&$cust_date_created_id_ct_so_tien_giam$$>
35
+ $_e$$.so_tien_max&&($cust_date_created_id_ct_so_tien_giam$$=$_e$$.so_tien_max);if($ev$$.so_tien_giam!==$cust_date_created_id_ct_so_tien_giam$$)return $reject$$(Error(`S\u1ed1 ti\u1ec1n gi\u1ea3m cho th\u1ebb ${$ev$$.ma} kh\u00f4ng h\u1ee3p l\u1ec7`));$ev$$.so_tien_giam=$cust_date_created_id_ct_so_tien_giam$$;$resolve$$(!0)})()}))},updateEvoucher=async($id_app$jscomp$1_rs$$,$evoucher_code$$,$id_ct$$)=>{$id_ct$$=$id_ct$$.toString();var $e$$=await Evoucher.findOne({ma:$evoucher_code$$,id_app:$id_app$jscomp$1_rs$$});
36
+ $e$$?($e$$=$e$$.id_ct_useds||[],$e$$.push($id_ct$$),$e$$=[...(new Set($e$$))],$id_app$jscomp$1_rs$$=await Evoucher.updateOne({ma:$evoucher_code$$,id_app:$id_app$jscomp$1_rs$$},{id_ct_useds:$e$$}),console.log("update id_ct_useds",$evoucher_code$$,$e$$,$id_app$jscomp$1_rs$$)):console.error("can't find evoucher",$evoucher_code$$)},deleteEvoucher=async($id_app$jscomp$2_id_ct_useds$$,$evoucher_code$$,$id_ct$$)=>{if($evoucher_code$$){$id_ct$$=$id_ct$$.toString();var $e$jscomp$2_rs$$=await Evoucher.findOne({id_app:$id_app$jscomp$2_id_ct_useds$$,
37
+ ma:$evoucher_code$$});$e$jscomp$2_rs$$&&($id_app$jscomp$2_id_ct_useds$$=($e$jscomp$2_rs$$.id_ct_useds||[]).filter($ct$$=>$ct$$!==$id_ct$$),$e$jscomp$2_rs$$=await Evoucher.updateOne({_id:$e$jscomp$2_rs$$._id},{id_ct_useds:$id_app$jscomp$2_id_ct_useds$$}),console.log("update id_ct_useds",$evoucher_code$$,$id_app$jscomp$2_id_ct_useds$$,$e$jscomp$2_rs$$))}},valid=async function($_opt_t_tien_evoucher_user$$,$obj$$,$next$$,$pre_obj_tien_con_lai$$){$pre_obj_tien_con_lai$$&&($obj$$._id=$pre_obj_tien_con_lai$$._id,
38
+ $obj$$.details=$obj$$.details||$pre_obj_tien_con_lai$$.details||[],$obj$$.evouchers=$obj$$.evouchers||$pre_obj_tien_con_lai$$.evouchers||[]);$obj$$.details=$obj$$.details||[];if($obj$$.signature&&!await Wallet.verifySignature($obj$$.id_app,$obj$$.sign_user,$obj$$.sign_data,$obj$$.signature))return $next$$("Signature is not valid");try{await Promise.all(($obj$$.details||[]).map($detail$$=>(async()=>{if($detail$$.signature&&!await Wallet.verifySignature($obj$$.id_app,$detail$$.sign_user,$detail$$.sign_data,
39
+ $detail$$.signature))throw"Signature is not valid";})()))}catch($e$$){return $next$$($e$$||$e$$.message)}await $obj$$.details.asyncJoinModel2($obj$$.id_app,vat,{where:"ma_thue",fields:["thue_suat","tk_thue_co","tk_thue_co_treo"]});for(let $i$$=0;$i$$<$obj$$.details.length;$i$$++){const $detail$$=$obj$$.details[$i$$];if($detail$$.line==null||$detail$$.line==void 0)$detail$$.line=(new Date).getTime();$detail$$.tien_hang=$detail$$.tien_hang_nt=Math.roundBy($detail$$.tien_hang_nt);$detail$$.tien_ck=$detail$$.tien_ck_nt=
40
+ Math.roundBy($detail$$.tien_ck_nt||0);$detail$$.gia_ban=$detail$$.gia_ban_nt;$detail$$.ma_kho=$obj$$.ma_kho;$detail$$.tien_xuat=$detail$$.tien_xuat_nt=Math.roundBy($detail$$.tien_xuat_nt||0);tinhtienthue($detail$$);$detail$$.options=$detail$$.options||[];for(let $i_o$$=0;$i_o$$<$detail$$.options.length;$i_o$$++){let $o$$=$detail$$.options[0];$o$$.details=$o$$.details||[];await $o$$.details.filter($d$$=>!$d$$.ma_thue).asyncJoinModel2($_opt_t_tien_evoucher_user$$.current_id_app,dmvt,{where:"ma_vt",
41
+ fields:["ma_thue"]});await $o$$.details.asyncJoinModel2($obj$$.id_app,vat,{where:"ma_thue",fields:["thue_suat","tk_thue_co","tk_thue_co_treo"]});$o$$.details.filter($d$$=>$d$$.sl_xuat).forEach($d$$=>{$d$$.tien_hang=$d$$.tien_hang_nt=$d$$.sl_xuat*($d$$.gia_ban_nt||0);tinhtienthue($d$$)});$o$$.tien_hang_nt=$o$$.details.map($d$$=>$d$$.tien_hang_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$o$$.tien_hang_ct_nt=$o$$.details.map($d$$=>$d$$.tien_hang_ct_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$o$$.tien_thue_nt=$o$$.details.map($d$$=>
42
+ $d$$.tien_thue_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0)}$detail$$.tien_hang_options=$detail$$.options.map($o$$=>$o$$.tien_hang_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$detail$$.tien_hang_options_ct=$detail$$.options.map($o$$=>$o$$.tien_hang_ct_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$detail$$.tien_thue_options=$detail$$.options.map($o$$=>$o$$.tien_thue_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$detail$$.tien=$detail$$.tien_nt=$detail$$.tien_hang_ct_nt-$detail$$.tien_ck_nt+$detail$$.tien_thue_nt+$detail$$.tien_hang_options_ct+
43
+ $detail$$.tien_thue_options}await $obj$$.details.filter($d$$=>!$d$$.ma_dvt&&$d$$.ma_tt1).asyncJoinModel2($_opt_t_tien_evoucher_user$$.current_id_app,dmtt,{where:{ma_vt:"ma_vt",ma_tt1:"ma_tt"},fields:"ma_dvt"});await $obj$$.details.filter($d$$=>!$d$$.ma_dvt&&$d$$.ma_tt2).asyncJoinModel2($_opt_t_tien_evoucher_user$$.current_id_app,dmtt,{where:{ma_vt:"ma_vt",ma_tt2:"ma_tt"},fields:"ma_dvt"});await $obj$$.details.filter($d$$=>!$d$$.ma_dvt&&$d$$.ma_tt3).asyncJoinModel2($_opt_t_tien_evoucher_user$$.current_id_app,
43
44
  dmtt,{where:{ma_vt:"ma_vt",ma_tt3:"ma_tt"},fields:"ma_dvt"});try{const $_checkEvoucher$$=checkEvoucher($_opt_t_tien_evoucher_user$$,$obj$$,$pre_obj_tien_con_lai$$);await Promise.all($_checkEvoucher$$)}catch($e$$){return $next$$($e$$.message)}$_opt_t_tien_evoucher_user$$=$obj$$.evouchers.map($e$$=>$e$$.so_tien_giam||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$pre_obj_tien_con_lai$$=$obj$$.details.map($a$$=>($a$$.tien_hang_ct_nt||0)-($a$$.tien_ck_nt||0)+($a$$.tien_thue_nt||0)+$a$$.tien_hang_options_ct+$a$$.tien_thue_options).reduce(($a$$,
44
45
  $b$$)=>$a$$+$b$$,0)-(($obj$$.tt_tien_thuong||0)+($obj$$.tien_ck_hd||0));$_opt_t_tien_evoucher_user$$>$pre_obj_tien_con_lai$$&&($_opt_t_tien_evoucher_user$$=$pre_obj_tien_con_lai$$);$obj$$.tien_evoucher=$_opt_t_tien_evoucher_user$$;$_opt_t_tien_evoucher_user$$=await Options.findOne({id_app:$obj$$.id_app,id_func:$obj$$.ma_ct.toLowerCase()}).lean();$_opt_t_tien_evoucher_user$$=($_opt_t_tien_evoucher_user$$||{}).option||{};if($obj$$.tien_evoucher&&$_opt_t_tien_evoucher_user$$.option.phan_bo_evoucher){let $tien_evoucher_da_phan_bo$$=
45
46
  0,$tien_evoucher$$=$obj$$.tien_evoucher,$tien_evoucher_con_lai$$=$tien_evoucher$$-$tien_evoucher_da_phan_bo$$;$obj$$.details.forEach($detail$$=>{if($tien_evoucher_con_lai$$>0){var $tien_evoucher_duoc_pb_tien_hang_con_lai$$=$detail$$.tien_hang_ct_nt-($detail$$.tien_ck_nt||0)+($detail$$.tien_thue_nt||0)+$detail$$.tien_hang_options_ct+$detail$$.tien_thue_options;$tien_evoucher_duoc_pb_tien_hang_con_lai$$=$tien_evoucher_con_lai$$>$tien_evoucher_duoc_pb_tien_hang_con_lai$$?$tien_evoucher_duoc_pb_tien_hang_con_lai$$:
@@ -49,37 +50,36 @@ module.exports=function($router$$){const $contr$$=new controller($router$$,model
49
50
  $obj$$.t_thue_nt=$obj$$.details.csum("tien_thue_nt")+$obj$$.details.csum("tien_thue_options");$obj$$.t_tt=$obj$$.t_tien_hang_ct+$obj$$.t_thue-$obj$$.t_ck;$obj$$.t_tt_nt=$obj$$.t_tien_hang_ct_nt+$obj$$.t_thue_nt-$obj$$.t_ck_nt;$obj$$.con_no=$obj$$.t_tt_nt-($obj$$.tien_paymentByPoints||0)-($obj$$.tien_thu||0)-($obj$$.tien_thu2||0);$obj$$.con_no<0&&($obj$$.con_no=0);let $product_details$$=[...$obj$$.details.map($d$$=>({...$d$$}))];$product_details$$.forEach($d$$=>{$d$$={...$d$$};$d$$.promotion&&$d$$.promotion.details_km&&
50
51
  $d$$.promotion.details_km.forEach($p$$=>{if($p$$.ma_vt&&$p$$.sl_km){let $_p$$={};_.extend($_p$$,$p$$,{sl_xuat:$p$$.sl_km});$product_details$$.push($_p$$)}});$d$$.combo&&$d$$.combo.length>0&&($d$$.combo.forEach($item$$=>{delete $item$$.px_gia_dd;$item$$.ma_kho=$d$$.ma_kho}),$product_details$$=[...$product_details$$,...$d$$.combo]);$d$$.options&&$d$$.options.length>0&&$d$$.options.forEach($ds$jscomp$2_o$$=>{$ds$jscomp$2_o$$=$ds$jscomp$2_o$$.details.filter($d$$=>$d$$.sl_xuat);$ds$jscomp$2_o$$.forEach($item$$=>
51
52
  {delete $item$$.px_gia_dd;$item$$.ma_kho=$d$$.ma_kho});$product_details$$=[...$product_details$$,...$ds$jscomp$2_o$$]})});$obj$$.promotion&&$obj$$.promotion.forEach($p$$=>{$p$$={...$p$$};if($p$$.ma_vt&&$p$$.sl_km){let $_p$$={};_.extend($_p$$,$p$$,{sl_xuat:$p$$.sl_km});$product_details$$.push($_p$$)}});$product_details$$=$product_details$$.filter($d$$=>!$d$$.combo||$d$$.combo.length===0);let $du_lieu_kho_kt$$;async.series({post_sokho:function($callback$$){async.series({kho:$callback$$=>{(new PostSokho($obj$$,
52
- $product_details$$,async function($detail$$,$callback$$){$detail$$.nxt=2;$detail$$.ma_kho=$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){$du_lieu_kho_kt$$=$rs$$;$callback$$($e$$,$rs$$)})},khott:$callback$$=>{(new PostBook($obj$$,$product_details$$,Sokhott,async function($detail$$,$callback$$){$detail$$.nxt=2;$detail$$.ma_kho=$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})}},($e$$,$rs$$)=>{$callback$$($e$$,$rs$$)})},post_socai:function($callback$$){Options.findOne({id_app:$obj$$.id_app,
53
- id_func:ma_ct.toLowerCase()}).lean().exec(async($details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$,$_opt$jscomp$1_tt_tt$jscomp$1_tt$$)=>{let $option$$;$option$$=$_opt$jscomp$1_tt_tt$jscomp$1_tt$$?$_opt$jscomp$1_tt_tt$jscomp$1_tt$$.option||{}:{};$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$=await dmkho.findOne({id_app:$obj$$.id_app,ma_kho:$obj$$.ma_kho}).lean()||{};let $pt$$;$obj$$.pt_thanh_toan&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan)&&
54
- ($pt$$=await ptthanhtoan.findOne({id_app:$obj$$.id_app,_id:$obj$$.pt_thanh_toan}).lean());$pt$$=$pt$$||{};$pt$$.tk_tien=$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.tk_tien||$pt$$.tk_tien;$pt$$.tk_cn=$pt$$.tk_cn||$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.tk_cn;$pt$$.tk_dt=$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.tk_dt||$pt$$.tk_dt;$pt$$.tk_gv=$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.tk_gv||
55
- $pt$$.tk_gv;$pt$$.tk_ck=$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.tk_ck||$pt$$.tk_ck;$pt$$.ma_kh||($pt$$.ma_kh=$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.ma_kh);$pt$$.ma_kh&&($pt$$.tk_tien=$pt$$.tk_cn);$option$$.tk_tien=$pt$$.tk_tien||$option$$.tk_tien||"1111";$option$$.tk_cn=$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.tk_cn||$option$$.tk_cn||"131111";$option$$.tk_dt=
56
- $pt$$.tk_dt||$option$$.tk_dt||"51111";$option$$.tk_ck=$pt$$.tk_ck||$option$$.tk_ck||"52111";$option$$.tk_gv=$pt$$.tk_gv||$option$$.tk_gv||"6321";$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$=[...$obj$$.details.map($d$$=>({...$d$$}))];let $details_ht$$=[];$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.forEach($detail$$=>{$detail$$={...$detail$$};let $tien$$=$detail$$.tien_hang_ct+$detail$$.tien_hang_options_ct,
57
- $tien_nt$$=$detail$$.tien_hang_ct_nt+$detail$$.tien_hang_options_ct;$detail$$.tk_no=$option$$.tk_tien;$detail$$.tk_co=$option$$.tk_dt;$detail$$.ma_kh||($detail$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh);$detail$$.tien_nt=$tien_nt$$;$detail$$.tien=$tien$$;$detail$$.flag="DT_"+($detail$$.ma_vt||"");$details_ht$$.push($detail$$)});$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.filter($d$$=>$d$$.tien_thue+$d$$.tien_thue_options&&($d$$.tk_thue_co_treo||$d$$.tk_thue_co)).forEach($detail$$=>
58
- {$detail$$={...$detail$$};$detail$$.tk_no=$option$$.tk_tien;$detail$$.tk_co=$detail$$.tk_thue_co_treo||$detail$$.tk_thue_co;$detail$$.ma_kh||($detail$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh);$detail$$.tien_nt=$detail$$.tien_thue_nt+$detail$$.tien_thue_options;$detail$$.tien=$detail$$.tien_thue+$detail$$.tien_thue_options;$detail$$.flag="THUE_"+($detail$$.ma_vt||"");$details_ht$$.push($detail$$)});if($details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$=$obj$$.tien_evoucher||
59
- 0)$_opt$jscomp$1_tt_tt$jscomp$1_tt$$={},$_opt$jscomp$1_tt_tt$jscomp$1_tt$$.tk_no=$obj$$.tk_no_evoucher||$option$$.tk_no_evoucher||$option$$.tk_ck,$_opt$jscomp$1_tt_tt$jscomp$1_tt$$.tk_co=$obj$$.tk_co_evoucher||$option$$.tk_co_evoucher||$option$$.tk_tien,$_opt$jscomp$1_tt_tt$jscomp$1_tt$$.tien_nt=$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$,$_opt$jscomp$1_tt_tt$jscomp$1_tt$$.tien=$_opt$jscomp$1_tt_tt$jscomp$1_tt$$.tien_nt,$_opt$jscomp$1_tt_tt$jscomp$1_tt$$.ma_kh=
60
- $pt$$.ma_kh||$obj$$.ma_kh,$_opt$jscomp$1_tt_tt$jscomp$1_tt$$.check_balance=!1,$details_ht$$.push($_opt$jscomp$1_tt_tt$jscomp$1_tt$$);if($details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$=($obj$$.tien_ck_hd||0)+$obj$$.details.map($d$$=>$d$$.tien_ck||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0))$_opt$jscomp$1_tt_tt$jscomp$1_tt$$={},$_opt$jscomp$1_tt_tt$jscomp$1_tt$$.tk_no=$option$$.tk_ck,$_opt$jscomp$1_tt_tt$jscomp$1_tt$$.tk_co=$option$$.tk_tien,$_opt$jscomp$1_tt_tt$jscomp$1_tt$$.tien=
61
- $_opt$jscomp$1_tt_tt$jscomp$1_tt$$.tien_nt=$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$,$_opt$jscomp$1_tt_tt$jscomp$1_tt$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh,$_opt$jscomp$1_tt_tt$jscomp$1_tt$$.check_balance=!1,$details_ht$$.push($_opt$jscomp$1_tt_tt$jscomp$1_tt$$);$obj$$.con_no&&($details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$={},$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.tk_no=
62
- $option$$.tk_cn,$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.tk_co=$option$$.tk_tien,$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.tien_nt=$obj$$.con_no,$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.tien=$obj$$.con_no,$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.ma_kh=$obj$$.ma_kh,$details_ht$$.push($details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$));
63
- $obj$$.tien_thu&&$pt$$.tk_cn&&$pt$$.tk_cn!==$option$$.tk_tien&&($details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$={},$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.tk_no=$pt$$.tk_cn,$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.tk_co=$option$$.tk_tien,$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.tien_nt=$obj$$.tien_thu,$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.tien=
64
- $obj$$.tien_thu,$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh,$details_ht$$.push($details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$));$obj$$.tien_thu2&&($details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$=($obj$$.pt_thanh_toan2&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan2)?await ptthanhtoan.findOne({_id:$obj$$.pt_thanh_toan2}).lean():
65
- null)||$pt$$,$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.tk_cn&&$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.ma_kh!==$pt$$.ma_kh&&($_opt$jscomp$1_tt_tt$jscomp$1_tt$$={},$_opt$jscomp$1_tt_tt$jscomp$1_tt$$.tk_no=$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.tk_cn,$_opt$jscomp$1_tt_tt$jscomp$1_tt$$.tk_co=$option$$.tk_tien,$_opt$jscomp$1_tt_tt$jscomp$1_tt$$.tien_nt=
66
- $obj$$.tien_thu2,$_opt$jscomp$1_tt_tt$jscomp$1_tt$$.tien=$obj$$.tien_thu2,$_opt$jscomp$1_tt_tt$jscomp$1_tt$$.ma_kh_no=$details_error$jscomp$2_kho_pt2_tien_ck_hd_tien_evoucher_con_lai$jscomp$1_tt$jscomp$2_tt$$.ma_kh,$_opt$jscomp$1_tt_tt$jscomp$1_tt$$.ma_kh_co=$pt$$.ma_kh,$details_ht$$.push($_opt$jscomp$1_tt_tt$jscomp$1_tt$$)));let $details_tienvon$$=[];($du_lieu_kho_kt$$||[]).forEach(function($detail$$){$detail$$.toObject&&($detail$$=$detail$$.toObject());$detail$$={...$detail$$};$detail$$.tk_no=$option$$.tk_gv||
67
- $detail$$.tk_gv;$detail$$.ma_kh||($detail$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh);$detail$$.tk_co=$detail$$.tk_vt;$detail$$.tien_nt=$detail$$.tien_xuat_nt;$detail$$.tien=$detail$$.tien_xuat;$detail$$.ma_nt="VND";$detail$$.ty_gia=1;$details_tienvon$$.push($detail$$)});$details_ht$$=$details_ht$$.concat($details_tienvon$$);$details_ht$$.forEach($d$$=>{$d$$.ma_kho=$obj$$.ma_kho});(new PostSocai($obj$$,$details_ht$$,void 0,void 0,$_options$$)).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})})}},async function($e$$,
68
- $rs$$){$rs$$&&($obj$$.details.filter($d$$=>!$d$$.px_gia_dd).forEach($detail$$=>{let $sokhos$$=($du_lieu_kho_kt$$||[]).filter($d$$=>$d$$.ma_vt==$detail$$.ma_vt&&$d$$.ma_tt1==$detail$$.ma_tt1||$d$$.ma_sp==$detail$$.ma_vt&&$d$$.ma_tt1_sp==$detail$$.ma_tt1);$detail$$.tien_xuat_nt=$detail$$.tien_xuat=$sokhos$$.map($s$$=>$s$$.tien_xuat_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$detail$$.sl_xuat&&($detail$$.gia_von_nt=$detail$$.gia_von=Math.round($detail$$.tien_xuat_nt/$detail$$.sl_xuat))}),await model.updateOne({_id:$obj$$._id},
69
- {details:$obj$$.details}));$fn$$($e$$,$rs$$)})};$contr$$.saving=async($user$$,$obj$$)=>{$obj$$.details=$obj$$.details||[];await chietkhauhd($user$$.email,$obj$$);await khuyenmaihd($obj$$);tinhtongtien($obj$$);await taothongtinchuyenkhoan($user$$,$obj$$)};$contr$$.creating=async function($user$$,$obj$$,$next$$){$obj$$.details||($obj$$.details=[]);await $obj$$.details.asyncJoinModel2($user$$.current_id_app,dmvt,{where:"ma_vt",setFields:($item$$,$ref$$)=>{$item$$.combo=$ref$$.combo||[];$item$$.ma_thue=
70
- $ref$$.ma_thue}});$obj$$.details.forEach($detail$$=>{$detail$$.combo&&$detail$$.combo.length>0&&($detail$$.combo=$detail$$.combo.map($item$$=>{$item$$=$item$$.toObject?$item$$.toObject():{...$item$$};$item$$.sl_xuat_1_combo=$item$$.sl_xuat||0;$item$$.sl_xuat=($item$$.sl_xuat_1_combo||0)*($detail$$.sl_xuat||0);$item$$.tien_xuat=$item$$.tien_xuat_nt=$item$$.sl_xuat*($item$$.gia_von_nt||0);$item$$.tien_hang=$item$$.tien_hang_nt=$item$$.sl_xuat*($item$$.gia_ban_nt||0);$item$$.tien_ck=$item$$.tien_ck_nt=
71
- $item$$.sl_xuat*($item$$.tien_ck_nt||0);$item$$.tien=$item$$.tien_nt=$item$$.tien_hang_nt-($item$$.tien_ck_nt||0);return $item$$}))});$obj$$.tien_thu=Math.roundBy($obj$$.tien_thu||0);$obj$$.tien_thu2=Math.roundBy($obj$$.tien_thu2||0);valid($user$$,$obj$$,async $error$$=>{if($error$$)return $next$$($error$$);if(!$obj$$.paymentByPoints)return $next$$(null,$obj$$);try{if(await getPointBalance($user$$.current_id_app,$user$$.email)<$obj$$.paymentByPoints)return $next$$("B\u1ea1n kh\u00f4ng c\u00f3 \u0111\u1ee7 \u0111i\u1ec3m \u0111\u1ec3 th\u1ef1c hi\u1ec7n giao d\u1ecbch n\u00e0y.");
72
- $next$$(null,$obj$$)}catch($e$$){$next$$($e$$.message)}})};$contr$$.created=async function($user$$,$obj$$,$next$$){await createTransactionPayment($obj$$);await createTransactionBonus($obj$$);$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>updateEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$obj$$.trang_thai=="5"&&($obj$$.trang_thai="6",await model.updateOne({_id:$obj$$._id},{trang_thai:"6"}));$next$$(null,$obj$$)};$contr$$.updating=async function($user$$,$data$$,$obj$$,$next$$){$data$$.details||
73
- ($data$$.details=$obj$$.details||[]);$data$$.evouchers||($data$$.evouchers=$obj$$.evouchers||[]);await $data$$.details.asyncJoinModel2($user$$.current_id_app,dmvt,{where:"ma_vt",setFields:($item$$,$ref$$)=>{let $old_combo$$=($item$$.combo||[]).map($i$$=>({ma_vt:$i$$.ma_vt,sl_xuat:$i$$.sl_xuat})),$new_combo$$=($ref$$.combo||[]).map($i$$=>({ma_vt:$i$$.ma_vt,sl_xuat:$i$$.sl_xuat}));_.isEqual($old_combo$$,$new_combo$$)||($item$$.combo=$ref$$.combo||[]);$obj$$.details.find($d$$=>$d$$.ma_vt===$item$$.ma_vt)?
74
- $item$$.ma_thue||($item$$.ma_thue=$ref$$.ma_thue):$item$$.ma_thue=$ref$$.ma_thue}});$data$$.details.forEach($detail$$=>{$detail$$.combo&&$detail$$.combo.length>0&&($detail$$.combo=$detail$$.combo.map($item$$=>{$item$$=$item$$.toObject?$item$$.toObject():{...$item$$};$item$$.sl_xuat_1_combo==void 0&&($item$$.sl_xuat_1_combo=$item$$.sl_xuat||0);$item$$.sl_xuat=($item$$.sl_xuat_1_combo||0)*($detail$$.sl_xuat||0);$item$$.tien_xuat=$item$$.tien_xuat_nt=$item$$.sl_xuat*($item$$.gia_von_nt||0);$item$$.tien_hang=
75
- $item$$.tien_hang_nt=$item$$.sl_xuat*($item$$.gia_ban_nt||0);$item$$.tien_ck=$item$$.tien_ck_nt=$item$$.sl_xuat*($item$$.tien_ck_nt||0);$item$$.tien=$item$$.tien_nt=$item$$.tien_hang_nt-($item$$.tien_ck_nt||0);return $item$$}))});$data$$.tien_thu=$data$$.tien_thu==void 0?$obj$$.tien_thu:$data$$.tien_thu;$data$$.tien_thu2=$data$$.tien_thu2==void 0?$obj$$.tien_thu2:$data$$.tien_thu2;$data$$.tien_thu=Math.roundBy($data$$.tien_thu||0);$data$$.tien_thu2=Math.roundBy($data$$.tien_thu2||0);$data$$.ma_ban&&
76
- $obj$$.ma_ban!==$data$$.ma_ban&&($data$$.ma_ban0=$obj$$.ma_ban);$data$$.details.forEach(function($d$$){$obj$$.details.forEach(function($_d$$){if($_d$$.ma_vt===$d$$.ma_vt&&$_d$$.line===$d$$.line){if($d$$.sl_order==void 0||$d$$.sl_order==null)$d$$.sl_order=$_d$$.sl_order;if($d$$.sl_xuat==void 0||$d$$.sl_xuat==null)$d$$.sl_xuat=$_d$$.sl_xuat;$d$$.order_time=$d$$.order_time||$_d$$.order_time||new Date;$d$$.sl_order<=$d$$.sl_xuat?$d$$.finish_time&&$d$$.sl_xuat===$_d$$.sl_xuat||($d$$.finish_time=new Date):
77
- $d$$.finish_time=null;let $trang_thai$$=$data$$.trang_thai||$obj$$.trang_thai;$d$$.finish_time||$trang_thai$$!=="5"&&$trang_thai$$!=="6"&&$trang_thai$$!=="9"||($d$$.finish_time=new Date);$_d$$.het_hang&&($d$$.het_hang=!0)}})});valid($user$$,$data$$,function($error$$){if($error$$)return $next$$($error$$);if($obj$$.paymentByPoints&&$obj$$.paymentByPoints!==($data$$.paymentByPoints||0))return $next$$("B\u1ea1n kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt s\u1ed1 \u0111i\u1ec3m thanh to\u00e1n.");$data$$.ma_ban&&
78
- $obj$$.ma_ban&&$data$$.ma_ban!==$obj$$.ma_ban&&App.emitEvent($obj$$.id_app,"pbl:delete",{_id:$obj$$._id,ma_ban:$obj$$.ma_ban,action:"DELETE",trang_thai:-1});$next$$(null,$data$$,$obj$$)},$obj$$)};$contr$$.updated=async function($evouchers_user$$,$obj$$,$next$$){await Evoucher.updateMany({id_ct_used:$obj$$._id.toString()},{id_ct_used:null});$evouchers_user$$=await Evoucher.find({id_ct_useds:$obj$$._id.toString()});await Promise.all($evouchers_user$$.map($e$$=>deleteEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));
79
- $obj$$.trang_thai==="9"?(await transaction.deleteTrans({id_ct:$obj$$._id.toString()}),await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng")):(createTransactionBonus($obj$$),$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>updateEvoucher($e$$.id_app,$e$$.ma,$obj$$._id))));$obj$$.trang_thai=="5"&&($obj$$.trang_thai="6",await model.findOneAndUpdate({_id:$obj$$._id},{trang_thai:"6"}));$next$$(null,$obj$$)};$contr$$.deleting=
80
- function($user$$,$obj$$,$next$$){$next$$(null,$obj$$)};$contr$$.deleted=async function($user$$,$obj$$,$callback$$){await transaction.deleteTrans({id_ct:$obj$$._id.toString()});await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng");$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>deleteEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$callback$$(null,$obj$$)};$contr$$.view=function($user$$,$items$$,$fn$$){let $id_app$$=$user$$.current_id_app;
81
- $items$$.forEach($item$$=>{$item$$.trang_thai=$item$$.trang_thai.toString();$item$$.evouchers&&($item$$.evouchers_string=$item$$.evouchers.map($e$$=>$e$$.ma).join(","))});async.parallel({cashier:function($callback$$){$items$$.filter($item$$=>$item$$.cashier).joinModel2(null,"user",[{where:{cashier:"email"},fields:[{cashier_name:"name"}]}],function(){$callback$$()})},kh:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kh).joinModel2($id_app$$,customer,[{where:{ma_kh:"ma_kh"},fields:[{ten_kh:"ten_kh"},
82
- {nh_kh:"nh_kh"},{dia_chi_kh:"dia_chi"},{dien_thoai_kh:"dien_thoai"}]}],function(){$callback$$()})},ban:function($callback$$){$items$$.filter($item$$=>$item$$.ma_ban).joinModel2($id_app$$,Dmban,[{where:{ma_ban:"ma_ban"},fields:[{ten_ban:"ten_ban"}]}],function(){$callback$$()})},ban0:function($callback$$){$items$$.filter($item$$=>$item$$.ma_ban0).joinModel2($id_app$$,Dmban,[{where:{ma_ban0:"ma_ban"},fields:[{ten_ban0:"ten_ban"}]}],function(){$callback$$()})},kho:function($callback$$){$items$$.filter($item$$=>
53
+ $product_details$$,async function($detail$$,$callback$$){$detail$$={...$detail$$,nxt:2};$detail$$.ma_kho=$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){if($e$$)return $callback$$($e$$);$du_lieu_kho_kt$$=$rs$$?.rs_sokho;$callback$$(null,$rs$$)})},khott:$callback$$=>{(new PostBook($obj$$,$product_details$$,Sokhott,async function($detail$$,$callback$$){$detail$$={...$detail$$,nxt:2};$detail$$.ma_kho=$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})}},
54
+ ($e$$,$rs$$)=>{$callback$$($e$$,$rs$$)})},post_vatra:function($callback$$){$obj$$.ngay_hd&&$obj$$.so_hd?setImmediate(async()=>{let $details_vatra$$=[];var $d$jscomp$27_ds$$=$product_details$$.map($detail$$=>({...$detail$$,thue_suat:($detail$$.ma_thue?$detail$$.thue_suat:$obj$$.thue_suat)||0,ma_thue:$detail$$.ma_thue||$obj$$.ma_thue,tien_thue_nt:$detail$$.tien_thue_nt||0,tien_thue:$detail$$.tien_thue||0})).filter($d$$=>$d$$.ma_thue);await $d$jscomp$27_ds$$.filter($r$$=>!$r$$.tk_thue_co&&$r$$.ma_thue).asyncJoinModel2($obj$$.id_app,
55
+ "vat",{where:"ma_thue",fields:["tk_thue_co"]});$d$jscomp$27_ds$$=await $d$jscomp$27_ds$$.asyncGroupBy(["ma_thue","thue_suat","ten_vt_vat","tk_thue_co"],"tien_hang_ct_nt tien_hang_ct tien_ck_nt tien_ck tien_thue tien_thue_nt tien_hang_options_ct tien_thue_options".split(" "));$d$jscomp$27_ds$$.forEach($detail$$=>{try{$detail$$.tk_du_thue=$obj$$.tk_no,$detail$$.t_tien_nt=($detail$$.tien_hang_ct_nt||0)+($detail$$.tien_hang_options_ct||0)-($detail$$.tien_ck_nt||0),$detail$$.t_tien=($detail$$.tien_hang_ct||
56
+ 0)+($detail$$.tien_hang_options_ct||0)-($detail$$.tien_ck||0),$detail$$.t_thue_nt=$detail$$.tien_thue_nt+($detail$$.tien_thue_options||0),$detail$$.t_thue=$detail$$.tien_thue+($detail$$.tien_thue_options||0),$detail$$.ten_vt=$detail$$.ten_vt_vat||$obj$$.ten_vt||$obj$$.dien_giai}catch($e$$){console.error($e$$,$obj$$)}});$details_vatra$$=[...$details_vatra$$,...$d$jscomp$27_ds$$];(new PostBook($obj$$,$details_vatra$$,global.getModel("vatra"),($detail$$,$callback$$)=>{$detail$$={...$detail$$};$detail$$.ten_vt=
57
+ $detail$$.ten_vt||$obj$$.dien_giai;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})}):$callback$$()},post_socai:function($callback$$){setImmediate(async()=>{try{var $_opt$$=await Options.findOne({id_app:$obj$$.id_app,id_func:ma_ct.toLowerCase()}).lean();let $option$$;$option$$=$_opt$$?$_opt$$.option||{}:{};let $kho$$=await dmkho.findOne({id_app:$obj$$.id_app,ma_kho:$obj$$.ma_kho}).lean()||{},$pt$$;$obj$$.pt_thanh_toan&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan)&&
58
+ ($pt$$=await ptthanhtoan.findOne({id_app:$obj$$.id_app,_id:$obj$$.pt_thanh_toan}).lean());$pt$$=$pt$$||{};$pt$$.tk_tien=$kho$$.tk_tien||$pt$$.tk_tien;$pt$$.tk_cn=$pt$$.tk_cn||$kho$$.tk_cn;$pt$$.tk_dt=$kho$$.tk_dt||$pt$$.tk_dt;$pt$$.tk_gv=$kho$$.tk_gv||$pt$$.tk_gv;$pt$$.tk_ck=$kho$$.tk_ck||$pt$$.tk_ck;$pt$$.ma_kh||($pt$$.ma_kh=$kho$$.ma_kh);$pt$$.ma_kh&&($pt$$.tk_tien=$pt$$.tk_cn);$option$$.tk_tien=$pt$$.tk_tien||$option$$.tk_tien||"1111";$option$$.tk_cn=$kho$$.tk_cn||$option$$.tk_cn||"131111";$option$$.tk_dt=
59
+ $pt$$.tk_dt||$option$$.tk_dt||"51111";$option$$.tk_ck=$pt$$.tk_ck||$option$$.tk_ck||"52111";$option$$.tk_gv=$pt$$.tk_gv||$option$$.tk_gv||"6321";let $details$$=[...$obj$$.details.map($d$$=>({...$d$$}))],$details_ht$$=[];$details$$.forEach($detail$$=>{$detail$$={...$detail$$};let $tien$$=$detail$$.tien_hang_ct+$detail$$.tien_hang_options_ct,$tien_nt$$=$detail$$.tien_hang_ct_nt+$detail$$.tien_hang_options_ct;$detail$$.tk_no=$option$$.tk_tien;$detail$$.tk_co=$option$$.tk_dt;$detail$$.ma_kh||($detail$$.ma_kh=
60
+ $pt$$.ma_kh||$obj$$.ma_kh);$detail$$.tien_nt=$tien_nt$$;$detail$$.tien=$tien$$;$detail$$.flag="DT_"+($detail$$.ma_vt||"");$details_ht$$.push($detail$$)});$details$$.filter($d$$=>$d$$.tien_thue_nt+$d$$.tien_thue_options&&($d$$.tk_thue_co_treo||$d$$.tk_thue_co)).forEach($detail$$=>{$detail$$={...$detail$$};$detail$$.tk_no=$option$$.tk_tien;$detail$$.tk_co=$obj$$.ngay_hd&&$obj$$.so_hd?$detail$$.tk_thue_co:$detail$$.tk_thue_co_treo||$detail$$.tk_thue_co;$detail$$.ma_kh||($detail$$.ma_kh=$pt$$.ma_kh||
61
+ $obj$$.ma_kh);$detail$$.tien=$detail$$.tien_nt=$detail$$.tien_thue_nt+$detail$$.tien_thue_options;$detail$$.flag="THUE_"+($detail$$.ma_vt||"");$details_ht$$.push($detail$$)});var $tien_evoucher_con_lai$jscomp$1_tt$$=$obj$$.tien_evoucher||0;$tien_evoucher_con_lai$jscomp$1_tt$$&&($_opt$$={},$_opt$$.tk_no=$obj$$.tk_no_evoucher||$option$$.tk_no_evoucher||$option$$.tk_ck,$_opt$$.tk_co=$obj$$.tk_co_evoucher||$option$$.tk_co_evoucher||$option$$.tk_tien,$_opt$$.tien_nt=$tien_evoucher_con_lai$jscomp$1_tt$$,
62
+ $_opt$$.tien=$_opt$$.tien_nt,$_opt$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh,$_opt$$.check_balance=!1,$details_ht$$.push($_opt$$));var $tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$=($obj$$.tien_ck_hd||0)+$obj$$.details.map($d$$=>$d$$.tien_ck||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$&&($tien_evoucher_con_lai$jscomp$1_tt$$={},$tien_evoucher_con_lai$jscomp$1_tt$$.tk_no=$option$$.tk_ck,$tien_evoucher_con_lai$jscomp$1_tt$$.tk_co=$option$$.tk_tien,$tien_evoucher_con_lai$jscomp$1_tt$$.tien=
63
+ $tien_evoucher_con_lai$jscomp$1_tt$$.tien_nt=$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$,$tien_evoucher_con_lai$jscomp$1_tt$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh,$tien_evoucher_con_lai$jscomp$1_tt$$.check_balance=!1,$details_ht$$.push($tien_evoucher_con_lai$jscomp$1_tt$$));$obj$$.con_no&&$obj$$.ma_kh&&($tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$={},$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.tk_no=$option$$.tk_cn,$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.tk_co=$option$$.tk_tien,$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt=
64
+ $obj$$.con_no,$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.tien=$obj$$.con_no,$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh=$obj$$.ma_kh,$details_ht$$.push($tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$));$obj$$.tien_thu&&$pt$$.tk_cn&&$pt$$.tk_cn!==$option$$.tk_tien&&($tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$={},$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.tk_no=$pt$$.tk_cn,$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.tk_co=$option$$.tk_tien,$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt=$obj$$.tien_thu,$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.tien=
65
+ $obj$$.tien_thu,$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh,$details_ht$$.push($tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$));if($obj$$.tien_thu2){let $pt2$$=($obj$$.pt_thanh_toan2&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan2)?await ptthanhtoan.findOne({_id:$obj$$.pt_thanh_toan2}).lean():null)||$pt$$;$pt2$$.tk_cn&&$pt2$$.ma_kh!==$pt$$.ma_kh&&($tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$={},$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.tk_no=$pt2$$.tk_cn,$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.tk_co=
66
+ $option$$.tk_tien,$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt=$obj$$.tien_thu2,$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.tien=$obj$$.tien_thu2,$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_no=$pt2$$.ma_kh,$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_co=$pt$$.ma_kh,$details_ht$$.push($tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$))}let $details_tienvon$$=[];($du_lieu_kho_kt$$||[]).forEach(function($detail$$){$detail$$.toObject&&($detail$$=$detail$$.toObject());$detail$$={...$detail$$};$detail$$.tk_no=
67
+ $option$$.tk_gv||$detail$$.tk_gv;$detail$$.ma_kh||($detail$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh);$detail$$.tk_co=$detail$$.tk_vt;$detail$$.tien_nt=$detail$$.tien_xuat_nt;$detail$$.tien=$detail$$.tien_xuat;$detail$$.ma_nt="VND";$detail$$.ty_gia=1;$details_tienvon$$.push($detail$$)});$details_ht$$=$details_ht$$.concat($details_tienvon$$);$details_ht$$.forEach($d$$=>{$d$$.ma_kho=$obj$$.ma_kho});(new PostSocai($obj$$,$details_ht$$,void 0,void 0,$_options$$)).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})}catch($e$$){$callback$$($e$$)}})}},
68
+ async function($e$$,$rs$$){if($rs$$)try{$obj$$.details.filter($d$$=>!$d$$.px_gia_dd).forEach($detail$$=>{let $sokhos$$=($du_lieu_kho_kt$$||[]).filter($d$$=>$d$$.ma_vt==$detail$$.ma_vt&&$d$$.ma_tt1==$detail$$.ma_tt1||$d$$.ma_sp==$detail$$.ma_vt&&$d$$.ma_tt1_sp==$detail$$.ma_tt1);$detail$$.tien_xuat_nt=$detail$$.tien_xuat=$sokhos$$.map($s$$=>$s$$.tien_xuat_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$detail$$.sl_xuat&&($detail$$.gia_von_nt=$detail$$.gia_von=Math.round($detail$$.tien_xuat_nt/$detail$$.sl_xuat))}),
69
+ await model.updateOne({_id:$obj$$._id},{details:$obj$$.details})}catch($e$$){return $fn$$($e$$)}$fn$$($e$$,$rs$$)})};$contr$$.saving=async($user$$,$obj$$)=>{$obj$$.details=$obj$$.details||[];await chietkhauhd($user$$.email,$obj$$);await khuyenmaihd($obj$$);tinhtongtien($obj$$);await taothongtinchuyenkhoan($user$$,$obj$$)};$contr$$.creating=async function($user$$,$obj$$,$next$$){$obj$$.details||($obj$$.details=[]);await $obj$$.details.asyncJoinModel2($user$$.current_id_app,dmvt,{where:"ma_vt",setFields:($item$$,
70
+ $ref$$)=>{$item$$.combo=$ref$$.combo||[];$item$$.ma_thue||($item$$.ma_thue=$ref$$.ma_thue)}});$obj$$.details.forEach($detail$$=>{$detail$$.combo&&$detail$$.combo.length>0&&($detail$$.combo=$detail$$.combo.map($item$$=>{$item$$=$item$$.toObject?$item$$.toObject():{...$item$$};$item$$.sl_xuat_1_combo=$item$$.sl_xuat||0;$item$$.sl_xuat=($item$$.sl_xuat_1_combo||0)*($detail$$.sl_xuat||0);$item$$.tien_xuat=$item$$.tien_xuat_nt=$item$$.sl_xuat*($item$$.gia_von_nt||0);$item$$.tien_hang=$item$$.tien_hang_nt=
71
+ $item$$.sl_xuat*($item$$.gia_ban_nt||0);$item$$.tien_ck=$item$$.tien_ck_nt=$item$$.sl_xuat*($item$$.tien_ck_nt||0);$item$$.tien=$item$$.tien_nt=$item$$.tien_hang_nt-($item$$.tien_ck_nt||0);return $item$$}))});$obj$$.tien_thu=Math.roundBy($obj$$.tien_thu||0);$obj$$.tien_thu2=Math.roundBy($obj$$.tien_thu2||0);valid($user$$,$obj$$,async $error$$=>{if($error$$)return $next$$($error$$);if(!$obj$$.paymentByPoints)return $next$$(null,$obj$$);try{if(await getPointBalance($user$$.current_id_app,$user$$.email)<
72
+ $obj$$.paymentByPoints)return $next$$("B\u1ea1n kh\u00f4ng c\u00f3 \u0111\u1ee7 \u0111i\u1ec3m \u0111\u1ec3 th\u1ef1c hi\u1ec7n giao d\u1ecbch n\u00e0y.");$next$$(null,$obj$$)}catch($e$$){$next$$($e$$.message)}})};$contr$$.created=async function($user$$,$obj$$,$next$$){await createTransactionPayment($obj$$);await createTransactionBonus($obj$$);$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>updateEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$obj$$.trang_thai=="5"&&($obj$$.trang_thai=
73
+ "6",await model.updateOne({_id:$obj$$._id},{trang_thai:"6"}));$next$$(null,$obj$$)};$contr$$.updating=async function($user$$,$data$$,$obj$$,$next$$){$data$$.details||($data$$.details=$obj$$.details||[]);$data$$.evouchers||($data$$.evouchers=$obj$$.evouchers||[]);await $data$$.details.asyncJoinModel2($user$$.current_id_app,dmvt,{where:"ma_vt",setFields:($item$$,$ref$$)=>{let $old_combo$$=($item$$.combo||[]).map($i$$=>({ma_vt:$i$$.ma_vt,sl_xuat:$i$$.sl_xuat})),$new_combo$$=($ref$$.combo||[]).map($i$$=>
74
+ ({ma_vt:$i$$.ma_vt,sl_xuat:$i$$.sl_xuat}));_.isEqual($old_combo$$,$new_combo$$)||($item$$.combo=$ref$$.combo||[]);$item$$.ma_thue||($obj$$.details.find($d$$=>$d$$.ma_vt===$item$$.ma_vt),$item$$.ma_thue=$ref$$.ma_thue)}});$data$$.details.forEach($detail$$=>{$detail$$.combo&&$detail$$.combo.length>0&&($detail$$.combo=$detail$$.combo.map($item$$=>{$item$$=$item$$.toObject?$item$$.toObject():{...$item$$};$item$$.sl_xuat_1_combo==void 0&&($item$$.sl_xuat_1_combo=$item$$.sl_xuat||0);$item$$.sl_xuat=($item$$.sl_xuat_1_combo||
75
+ 0)*($detail$$.sl_xuat||0);$item$$.tien_xuat=$item$$.tien_xuat_nt=$item$$.sl_xuat*($item$$.gia_von_nt||0);$item$$.tien_hang=$item$$.tien_hang_nt=$item$$.sl_xuat*($item$$.gia_ban_nt||0);$item$$.tien_ck=$item$$.tien_ck_nt=$item$$.sl_xuat*($item$$.tien_ck_nt||0);$item$$.tien=$item$$.tien_nt=$item$$.tien_hang_nt-($item$$.tien_ck_nt||0);return $item$$}))});$data$$.tien_thu=$data$$.tien_thu==void 0?$obj$$.tien_thu:$data$$.tien_thu;$data$$.tien_thu2=$data$$.tien_thu2==void 0?$obj$$.tien_thu2:$data$$.tien_thu2;
76
+ $data$$.tien_thu=Math.roundBy($data$$.tien_thu||0);$data$$.tien_thu2=Math.roundBy($data$$.tien_thu2||0);$data$$.ma_ban&&$obj$$.ma_ban!==$data$$.ma_ban&&($data$$.ma_ban0=$obj$$.ma_ban);$data$$.details.forEach(function($d$$){$obj$$.details.forEach(function($_d$$){if($_d$$.ma_vt===$d$$.ma_vt&&$_d$$.line===$d$$.line){if($d$$.sl_order==void 0||$d$$.sl_order==null)$d$$.sl_order=$_d$$.sl_order;if($d$$.sl_xuat==void 0||$d$$.sl_xuat==null)$d$$.sl_xuat=$_d$$.sl_xuat;$d$$.order_time=$d$$.order_time||$_d$$.order_time||
77
+ new Date;$d$$.sl_order<=$d$$.sl_xuat?$d$$.finish_time&&$d$$.sl_xuat===$_d$$.sl_xuat||($d$$.finish_time=new Date):$d$$.finish_time=null;let $trang_thai$$=$data$$.trang_thai||$obj$$.trang_thai;$d$$.finish_time||$trang_thai$$!=="5"&&$trang_thai$$!=="6"&&$trang_thai$$!=="9"||($d$$.finish_time=new Date);$_d$$.het_hang&&($d$$.het_hang=!0)}})});valid($user$$,$data$$,function($error$$){if($error$$)return $next$$($error$$);if($obj$$.paymentByPoints&&$obj$$.paymentByPoints!==($data$$.paymentByPoints||0))return $next$$("B\u1ea1n kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt s\u1ed1 \u0111i\u1ec3m thanh to\u00e1n.");
78
+ $data$$.ma_ban&&$obj$$.ma_ban&&$data$$.ma_ban!==$obj$$.ma_ban&&App.emitEvent($obj$$.id_app,"pbl:delete",{_id:$obj$$._id,ma_ban:$obj$$.ma_ban,action:"DELETE",trang_thai:-1});$next$$(null,$data$$,$obj$$)},$obj$$)};$contr$$.updated=async function($evouchers_user$$,$obj$$,$next$$){await Evoucher.updateMany({id_ct_used:$obj$$._id.toString()},{id_ct_used:null});$evouchers_user$$=await Evoucher.find({id_ct_useds:$obj$$._id.toString()});await Promise.all($evouchers_user$$.map($e$$=>deleteEvoucher($e$$.id_app,
79
+ $e$$.ma,$obj$$._id)));$obj$$.trang_thai==="9"?(await transaction.deleteTrans({id_ct:$obj$$._id.toString()}),await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng")):(await createTransactionBonus($obj$$),$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>updateEvoucher($e$$.id_app,$e$$.ma,$obj$$._id))));$obj$$.trang_thai=="5"&&($obj$$.trang_thai="6",await model.updateOne({_id:$obj$$._id},{trang_thai:"6"}));$next$$(null,$obj$$)};
80
+ $contr$$.deleting=function($user$$,$obj$$,$next$$){$next$$(null,$obj$$)};$contr$$.deleted=async function($user$$,$obj$$,$callback$$){await transaction.deleteTrans({id_ct:$obj$$._id.toString()});await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng");$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>deleteEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$callback$$(null,$obj$$)};$contr$$.view=function($user$$,$items$$,$fn$$){let $id_app$$=
81
+ $user$$.current_id_app;$items$$.forEach($item$$=>{$item$$.trang_thai=$item$$.trang_thai.toString();$item$$.evouchers&&($item$$.evouchers_string=$item$$.evouchers.map($e$$=>$e$$.ma).join(","))});async.parallel({cashier:function($callback$$){$items$$.filter($item$$=>$item$$.cashier).joinModel2(null,"user",[{where:{cashier:"email"},fields:[{cashier_name:"name"}]}],function(){$callback$$()})},kh:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kh).joinModel2($id_app$$,customer,[{where:{ma_kh:"ma_kh"},
82
+ fields:[{ten_kh:"ten_kh"},{nh_kh:"nh_kh"},{dia_chi_kh:"dia_chi"},{dien_thoai_kh:"dien_thoai"}]}],function(){$callback$$()})},ban:function($callback$$){$items$$.filter($item$$=>$item$$.ma_ban).joinModel2($id_app$$,Dmban,[{where:{ma_ban:"ma_ban"},fields:[{ten_ban:"ten_ban"}]}],function(){$callback$$()})},ban0:function($callback$$){$items$$.filter($item$$=>$item$$.ma_ban0).joinModel2($id_app$$,Dmban,[{where:{ma_ban0:"ma_ban"},fields:[{ten_ban0:"ten_ban"}]}],function(){$callback$$()})},kho:function($callback$$){$items$$.filter($item$$=>
83
83
  $item$$.ma_kho).joinModel2($id_app$$,dmkho,[{where:{ma_kho:"ma_kho"},fields:["ten_kho","wifi","wifi_pass"],setFields:($a$$,$b$$)=>{$b$$&&$b$$.exfields&&($a$$.dia_chi_kho=$b$$.exfields.dia_chi,$a$$.dien_thoai_kho=$b$$.exfields.dien_thoai)}}],function(){$callback$$()})},hd7:function($callback$$){$items$$.joinModel2($id_app$$,hd7,[{where:{_id:"id_pbl"},fields:[{id_hd7:"_id"},{so_ct_hd7:"so_ct"},{ngay_ct_hd7:"ngay_ct"}]}],function(){$callback$$()})},trangthai:function($callback$$){$items$$.filter($item$$=>
84
84
  $item$$.trang_thai).joinModel2(null,trangthai,[{where:{trang_thai:"ma_trang_thai",ma_ct:"ma_ct"},fields:["ten_trang_thai","color"]}],function(){$callback$$()})},ptthanhtoan:function($callback$$){$items$$.filter($item$$=>$item$$.pt_thanh_toan).joinModel2($id_app$$,ptthanhtoan,[{where:{pt_thanh_toan:"_id"},fields:{ten_pt_thanh_toan:"ten"}}],function(){$callback$$()})},ptthanhtoan2:function($callback$$){$items$$.filter($item$$=>$item$$.pt_thanh_toan2).joinModel2($id_app$$,ptthanhtoan,[{where:{pt_thanh_toan2:"_id"},
85
85
  fields:{ten_pt_thanh_toan2:"ten"}}],function(){$callback$$()})},t_tien:function($callback$$){$items$$.forEach(function($r$$){$r$$.details&&($r$$.details.forEach($d$$=>{$d$$.sl_order=$d$$.sl_order||$d$$.sl_xuat;$d$$.sl_order<=$d$$.sl_xuat?$d$$.finish_time||($d$$.finish_time=new Date):$d$$.finish_time=null}),$r$$.t_tien_hang_ct==void 0&&tinhtongtien($r$$))});$callback$$()},details_vt:function($callback$$){async.mapLimit($items$$,20,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_vt).joinModel2($id_app$$,
@@ -1,6 +1,6 @@
1
- const moment=require("moment"),numeral=require("numeral"),_=require("lodash"),PostBook=require("../../libs/post-book"),options=global.getModel("options"),PostSocai=require("../../libs/post-socai"),User=global.getModel("user"),Sokho=global.getModel("sokho"),Socaitmp=global.getModel("socai"),transaction=global.getModel("transaction"),Evoucher=global.getModel("evoucher"),dvcs=global.getModel("dvcs"),dmvt=global.getModel("dmvt"),dmtt=global.getModel("dmtt"),dmcpmh=global.getModel("dmcpmh"),dmkho=global.getModel("dmkho"),
2
- customer=global.getModel("customer"),dmdt=global.getModel("dmdt"),dmphi=global.getModel("dmphi"),contract=global.getModel("contract"),trangthai=global.getModel("trangthai"),currency=global.getModel("currency"),ptthanhtoan=global.getModel("ptthanhtoan"),dmdiemthuong=global.getModel("dmdiemthuong"),model=global.getModel("so1"),pt1=global.getModel("pt1"),controller=require("../../controllers/controller"),async=require("async"),ma_ct="SO1",ckdiem=require("../../libs/ckdiem"),tinhhoahong=require("../../libs/tinhhoahong"),
3
- blockchainconnect=require("../../libs/blockchainconnect"),App=global.getModel("app"),Introducer=global.getModel("introducer"),getGiaBan=require("../../libs/getGiabanAsync"),dmchietkhauhd=global.getModel("dmchietkhauhd"),dmkhuyenmaihd=global.getModel("dmkhuyenmaihd"),utils=require("../../libs/utils"),spend=async($appInfo$$,$receiver_user$$,$receiver_address$$,$amount$$,$denom$$,$memo$$,$introduce_code$$,$sub_action$$="")=>{try{await blockchainconnect.spend($appInfo$$._id,$appInfo$$.wallet_token,$appInfo$$.wallet_address,
1
+ const moment=require("moment"),numeral=require("numeral"),_=require("lodash"),PostSokho=require("../../libs/post-sokho"),options=global.getModel("options"),PostSocai=require("../../libs/post-socai"),User=global.getModel("user"),Socai=global.getModel("socai"),transaction=global.getModel("transaction"),Evoucher=global.getModel("evoucher"),dvcs=global.getModel("dvcs"),dmvt=global.getModel("dmvt"),dmtt=global.getModel("dmtt"),dmcpmh=global.getModel("dmcpmh"),dmkho=global.getModel("dmkho"),customer=global.getModel("customer"),
2
+ dmdt=global.getModel("dmdt"),dmphi=global.getModel("dmphi"),contract=global.getModel("contract"),trangthai=global.getModel("trangthai"),currency=global.getModel("currency"),ptthanhtoan=global.getModel("ptthanhtoan"),dmdiemthuong=global.getModel("dmdiemthuong"),model=global.getModel("so1"),pt1=global.getModel("pt1"),controller=require("../../controllers/controller"),async=require("async"),ma_ct="SO1",ckdiem=require("../../libs/ckdiem"),tinhhoahong=require("../../libs/tinhhoahong"),blockchainconnect=
3
+ require("../../libs/blockchainconnect"),App=global.getModel("app"),Introducer=global.getModel("introducer"),getGiaBan=require("../../libs/getGiabanAsync"),dmchietkhauhd=global.getModel("dmchietkhauhd"),dmkhuyenmaihd=global.getModel("dmkhuyenmaihd"),utils=require("../../libs/utils"),spend=async($appInfo$$,$receiver_user$$,$receiver_address$$,$amount$$,$denom$$,$memo$$,$introduce_code$$,$sub_action$$="")=>{try{await blockchainconnect.spend($appInfo$$._id,$appInfo$$.wallet_token,$appInfo$$.wallet_address,
4
4
  $receiver_address$$,{amount:$amount$$,denom:$denom$$,memo:$memo$$,action:"bonus",introduce_code:$introduce_code$$,sub_action:$sub_action$$})}catch($e$$){console.error("Error send coin",$e$$,$receiver_user$$,$receiver_address$$,$amount$$,$denom$$,$memo$$)}},validOffline=$detail$$=>{$detail$$.ma_thue?($detail$$.gia_ban_ct_nt=$detail$$.gia_ban_ct=Math.roundBy($detail$$.gia_ban_nt/(1+$detail$$.thue_suat/100),5),$detail$$.tien_hang_ct=$detail$$.tien_hang_ct_nt=Math.roundBy($detail$$.sl_xuat*$detail$$.gia_ban_ct_nt,
5
5
  0),$detail$$.ty_le_ck&&($detail$$.tien_ck=$detail$$.tien_ck_nt=utils.round($detail$$.tien_hang_ct*$detail$$.ty_le_ck/100)),$detail$$.tien_thue=$detail$$.tien_thue_nt=Math.roundBy(($detail$$.tien_hang_ct_nt-$detail$$.tien_ck_nt)*$detail$$.thue_suat/100)):($detail$$.gia_ban_ct=$detail$$.gia_ban,$detail$$.gia_ban_ct_nt=$detail$$.gia_ban_nt,$detail$$.tien_hang_ct=$detail$$.tien_hang_ct_nt=$detail$$.tien_hang_nt,$detail$$.ty_le_ck&&($detail$$.tien_ck=$detail$$.tien_ck_nt=utils.round($detail$$.tien_hang_ct*
6
6
  $detail$$.ty_le_ck/100)),$detail$$.tien_thue=0,$detail$$.tien_thue_nt=0)},khuyenmaihd=async $obj$$=>{if($obj$$.details&&$obj$$.online){var $ckhds_query_t_tien_hang_ct_nt$$=$obj$$.details.filter($d$$=>!$d$$.km_yn_for).csum("tien_hang_ct_nt");if($ckhds_query_t_tien_hang_ct_nt$$!==0){var $hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$=$obj$$.details.filter($d$$=>!$d$$.km_yn_for).csum("tien_ck_nt");$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$=$ckhds_query_t_tien_hang_ct_nt$$-$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$;
@@ -56,20 +56,20 @@ module.exports=function($contr_router$$){$contr_router$$=new controller($contr_r
56
56
  $user$$.email);$obj$$.details.forEach($d$$=>{$d$$.tien_xuat_tmp=$d$$.sl_xuat*($d$$.gia_mua||0)});await chietkhauhd($obj$$);await khuyenmaihd($obj$$);$obj$$.details.forEach($d$$=>{$d$$.sl_xuat=utils.round($d$$.sl_xuat,4);$d$$.tt_nt=($d$$.tien_han_ct_nt||0)-($d$$.tien_ck_nt||0);$d$$.tt=($d$$.tien_hang_ct||0)-($d$$.tien_ck||0)});await tinhhoahong($obj$$,$user$$)};$contr_router$$.handleAfterPayment=async $obj$$=>{$obj$$.trang_thai_tt="5";$obj$$.trang_thai="1";await model.updateOne({_id:$obj$$._id},{details:$obj$$.details,
57
57
  trang_thai_tt:"5",trang_thai:"1"});let $ctrlSO1$$=global.controllers.SO1;$ctrlSO1$$&&controller.postData($obj$$,$ctrlSO1$$,$e$$=>{if($e$$)return console.error($e$$);controller.pushNotification($ctrlSO1$$,$obj$$)});return null};$contr_router$$.post=async function($obj$$,$fn$$,$_options$$={}){$fn$$||=function(){};let $he_so_qd$$=await currency.getRate($obj$$.id_app,$obj$$.ma_nt)||1;const $appInfo$$=await global.getModel("app").findOne({_id:$obj$$.id_app}).lean();await $obj$$.details.filter($d$$=>!$d$$.ma_thue).asyncJoinModel2($obj$$.id_app,
58
58
  dmvt,{where:"ma_vt",fields:["ma_thue","gia_mua"]});await $obj$$.details.filter($d$$=>$d$$.ma_thue).asyncJoinModel2($obj$$.id_app,global.getModel("vat"),{where:"ma_thue",fields:["thue_suat","tk_thue_co","tk_thue_co_treo"]});let $product_details$$=$obj$$.details.map($detail$$=>$detail$$.combo&&$detail$$.combo.length>0?$detail$$.combo.map($item$$=>{$item$$=$item$$.toObject?$item$$.toObject():{...$item$$};delete $item$$.px_gia_dd;$item$$.ma_kho=$detail$$.ma_kho;return $item$$}):[$detail$$]).reduce(($a$$,
59
- $b$$)=>$a$$.concat($b$$),[]);async.series({post_sokho:function($callback$$){const $details$$=[];$obj$$.details.forEach($d$$=>{$details$$.push({...$d$$})});(new PostBook($obj$$,$product_details$$,Sokho,async function($detail$$,$callback$$){$detail$$.nxt=2;$detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;$detail$$.ma_kho=$detail$$.ma_kho||$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})},post_socai:function($callback$$){options.findOne({id_app:$obj$$.id_app,
60
- id_func:ma_ct.toLowerCase()}).lean().exec(async($error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$,$rs$jscomp$3_tien_paymentByPoints_tt$$)=>{let $option$$;$option$$=$rs$jscomp$3_tien_paymentByPoints_tt$$?$rs$jscomp$3_tien_paymentByPoints_tt$$.option||{}:{};let $kho$$=await dmkho.findOne({id_app:$obj$$.id_app,ma_kho:$obj$$.ma_kho}).lean();$kho$$||={};let $pt$$;$obj$$.pt_thanh_toan&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan)&&($pt$$=await ptthanhtoan.findOne({id_app:$obj$$.id_app,
61
- _id:$obj$$.pt_thanh_toan}).lean());$pt$$=$pt$$||{};$pt$$.tk_tien=$pt$$.tk_cn;$pt$$.tk_cn=$pt$$.tk_cn||$kho$$.tk_cn;$pt$$.tk_dt=$kho$$.tk_dt||$pt$$.tk_dt;$pt$$.tk_gv=$kho$$.tk_gv||$pt$$.tk_gv;$pt$$.tk_ck=$kho$$.tk_ck||$pt$$.tk_ck;$pt$$.tk_cp_gh=$kho$$.tk_cp_gh||$pt$$.tk_cp_gh;$pt$$.tk_cp_bh=$kho$$.tk_cp_bh||$pt$$.tk_cp_bh;$pt$$.tk_cp_ctv=$kho$$.tk_cp_ctv||$pt$$.tk_cp_ctv;$pt$$.tk_cn_ctv=$kho$$.tk_cn_ctv||$pt$$.tk_cn_ctv;$option$$.tk_tien=$pt$$.tk_tien||$kho$$.tk_tien||$option$$.tk_tien||"1111";$option$$.tk_cn=
62
- $pt$$.tk_cn||$option$$.tk_cn||"131111";$option$$.tk_dt=$pt$$.tk_dt||$option$$.tk_dt||"51111";$option$$.tk_tl=$pt$$.tk_tl||$option$$.tk_tl||"52131";$option$$.tk_ck=$pt$$.tk_ck||$option$$.tk_ck||"52111";$option$$.tk_gv=$pt$$.tk_gv||$option$$.tk_gv||"6321";$option$$.tk_cp_gh=$pt$$.tk_cp_gh||$option$$.tk_cp_gh||"6418";$option$$.tk_cp_bh=$pt$$.tk_cp_bh||$option$$.tk_cp_bh||$option$$.tk_ck;$option$$.tk_cp_ctv=$pt$$.tk_cp_ctv||$option$$.tk_cp_ctv;$option$$.tk_cn_ctv=$pt$$.tk_cn_ctv||$option$$.tk_cn_ctv;
63
- $pt$$.ten&&$pt$$.ten.indexOf("COD")>=0?$option$$.ma_kh=$obj$$.nhan_vien_giao_hang||$obj$$.don_vi_vc||$pt$$.ma_kh||$obj$$.ma_kh:$option$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh;const $details$$=[];$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$=$obj$$.details.map($a$$=>($a$$.tien_hang_nt||0)-($a$$.tien_ck_nt||0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0)-(($obj$$.tt_tien_thuong||0)+($obj$$.tien_ck_hd||0)+($obj$$.tien_evoucher||0));$rs$jscomp$3_tien_paymentByPoints_tt$$=$obj$$.tien_paymentByPoints||
64
- 0;const $hoachtoandtvathue$$=($tk_tien$$,$ty_le$$)=>{$obj$$.details.forEach(function($d$jscomp$26_detail$$){$d$jscomp$26_detail$$={...$d$jscomp$26_detail$$};let $tien_nt$$;$tien_nt$$=$d$jscomp$26_detail$$.tien_hang_ct_nt;$d$jscomp$26_detail$$.tk_co=$option$$.tk_dt;$d$jscomp$26_detail$$.tk_no=$tk_tien$$;$d$jscomp$26_detail$$.ma_kh_co=$obj$$.ma_kh;$d$jscomp$26_detail$$.ma_kh_no=$option$$.ma_kh;$d$jscomp$26_detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;$d$jscomp$26_detail$$.tien=$d$jscomp$26_detail$$.tien_nt=
65
- Math.roundBy($tien_nt$$*$ty_le$$);$d$jscomp$26_detail$$.flag="DT_"+($d$jscomp$26_detail$$.ma_vt||"");$details$$.push($d$jscomp$26_detail$$)});$obj$$.details.filter($d$$=>$d$$.tien_thue).forEach($detail$$=>{$detail$$={...$detail$$};$detail$$.tk_no=$tk_tien$$;$detail$$.tk_co=$detail$$.tk_thue_co_treo||$detail$$.tk_thue_co;$detail$$.ma_kh||($detail$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh);$detail$$.tien=$detail$$.tien_nt=Math.roundBy($detail$$.tien_thue_nt*$ty_le$$);$detail$$.flag="THUE_"+($detail$$.ma_vt||
66
- "");$details$$.push($detail$$)})};$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$&&($hoachtoandtvathue$$($option$$.tk_cn,$rs$jscomp$3_tien_paymentByPoints_tt$$/$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$),$hoachtoandtvathue$$($option$$.tk_tien,($error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$-$rs$jscomp$3_tien_paymentByPoints_tt$$)/$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$));$obj$$.details.filter($d$$=>$d$$.diem_thuong&&$d$$.tk_km_no&&
67
- $d$$.tk_km_co).forEach(function($d$$){let $detail$$={...$d$$};$detail$$.tk_co=$option$$.tk_km_co||$d$$.tk_km_co;$detail$$.tk_no=$option$$.tk_km_no||$d$$.tk_km_no;$detail$$.ma_kh=$obj$$.ma_kh;$detail$$.tien=$detail$$.tien_nt=$detail$$.diem_thuong*$he_so_qd$$;$details$$.push($detail$$)});$obj$$.ctcpbhs&&$obj$$.ctcpbhs.forEach(function($d$jscomp$30_detail$$){$d$jscomp$30_detail$$={...$d$jscomp$30_detail$$};$d$jscomp$30_detail$$.tk_co=$option$$.tk_dt;$d$jscomp$30_detail$$.tk_no=$option$$.tk_cn;$d$jscomp$30_detail$$.ma_kh_co=
68
- $obj$$.ma_kh;$d$jscomp$30_detail$$.ma_kh_no=$option$$.ma_kh;$d$jscomp$30_detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;$d$jscomp$30_detail$$.tien_nt=$d$jscomp$30_detail$$.tien_cp_nt;$d$jscomp$30_detail$$.tien=$d$jscomp$30_detail$$.tien_cp;$details$$.push($d$jscomp$30_detail$$)});$obj$$.tien_phi_vc&&$option$$.tk_phi_vc&&($error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$={},$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_co=$option$$.tk_phi_vc,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_no=
69
- $option$$.tk_cn,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien_nt=$obj$$.tien_phi_vc||0,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien=$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien_nt,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.ma_kh_co=$obj$$.ma_kh,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.ma_kh_no=$obj$$.nhan_vien_giao_hang||$obj$$.don_vi_vc,$details$$.push($error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$));
70
- $obj$$.tien_freeship&&($error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$={},$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_no=$option$$.tk_cp_gh,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_co=$option$$.tk_cn,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien_nt=$obj$$.tien_freeship||0,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien=$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien_nt,
71
- $error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.ma_kh_no=$obj$$.ma_kh,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.ma_kh_co=$option$$.ma_kh,$details$$.push($error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$));$obj$$.tt_tien_thuong&&($error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$={},$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_no=$option$$.tk_cp_bh,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_co=
72
- $option$$.tk_cn,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien_nt=$obj$$.tt_tien_thuong||0,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien=$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien_nt,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.ma_kh_no=$obj$$.ma_kh,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.ma_kh_co=$option$$.ma_kh,$details$$.push($error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$));
59
+ $b$$)=>$a$$.concat($b$$),[]),$ket_qua_post_sokho$$;async.series({post_sokho:function($callback$$){const $details$$=[];$obj$$.details.forEach($d$$=>{$details$$.push({...$d$$})});(new PostSokho($obj$$,$product_details$$,async function($detail$$,$callback$$){$detail$$.nxt=2;$detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;$detail$$.ma_kho=$detail$$.ma_kho||$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){if($e$$)return $callback$$($e$$);$ket_qua_post_sokho$$=$rs$$.rs_sokho;$callback$$(null,
60
+ $rs$$)})},post_socai:function($callback$$){options.findOne({id_app:$obj$$.id_app,id_func:ma_ct.toLowerCase()}).lean().exec(async($error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$,$rs$jscomp$3_tien_paymentByPoints_tt$$)=>{let $option$$;$option$$=$rs$jscomp$3_tien_paymentByPoints_tt$$?$rs$jscomp$3_tien_paymentByPoints_tt$$.option||{}:{};let $kho$$=await dmkho.findOne({id_app:$obj$$.id_app,ma_kho:$obj$$.ma_kho}).lean();$kho$$||={};let $pt$$;$obj$$.pt_thanh_toan&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan)&&
61
+ ($pt$$=await ptthanhtoan.findOne({id_app:$obj$$.id_app,_id:$obj$$.pt_thanh_toan}).lean());$pt$$=$pt$$||{};$pt$$.tk_tien=$pt$$.tk_cn;$pt$$.tk_cn=$pt$$.tk_cn||$kho$$.tk_cn;$pt$$.tk_dt=$kho$$.tk_dt||$pt$$.tk_dt;$pt$$.tk_gv=$kho$$.tk_gv||$pt$$.tk_gv;$pt$$.tk_ck=$kho$$.tk_ck||$pt$$.tk_ck;$pt$$.tk_cp_gh=$kho$$.tk_cp_gh||$pt$$.tk_cp_gh;$pt$$.tk_cp_bh=$kho$$.tk_cp_bh||$pt$$.tk_cp_bh;$pt$$.tk_cp_ctv=$kho$$.tk_cp_ctv||$pt$$.tk_cp_ctv;$pt$$.tk_cn_ctv=$kho$$.tk_cn_ctv||$pt$$.tk_cn_ctv;$option$$.tk_tien=$pt$$.tk_tien||
62
+ $kho$$.tk_tien||$option$$.tk_tien||"1111";$option$$.tk_cn=$pt$$.tk_cn||$option$$.tk_cn||"131111";$option$$.tk_dt=$pt$$.tk_dt||$option$$.tk_dt||"51111";$option$$.tk_tl=$pt$$.tk_tl||$option$$.tk_tl||"52131";$option$$.tk_ck=$pt$$.tk_ck||$option$$.tk_ck||"52111";$option$$.tk_gv=$pt$$.tk_gv||$option$$.tk_gv||"6321";$option$$.tk_cp_gh=$pt$$.tk_cp_gh||$option$$.tk_cp_gh||"6418";$option$$.tk_cp_bh=$pt$$.tk_cp_bh||$option$$.tk_cp_bh||$option$$.tk_ck;$option$$.tk_cp_ctv=$pt$$.tk_cp_ctv||$option$$.tk_cp_ctv;
63
+ $option$$.tk_cn_ctv=$pt$$.tk_cn_ctv||$option$$.tk_cn_ctv;$pt$$.ten&&$pt$$.ten.indexOf("COD")>=0?$option$$.ma_kh=$obj$$.nhan_vien_giao_hang||$obj$$.don_vi_vc||$pt$$.ma_kh||$obj$$.ma_kh:$option$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh;const $details$$=[];$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$=$obj$$.details.map($a$$=>($a$$.tien_hang_nt||0)-($a$$.tien_ck_nt||0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0)-(($obj$$.tt_tien_thuong||0)+($obj$$.tien_ck_hd||0)+($obj$$.tien_evoucher||0));$rs$jscomp$3_tien_paymentByPoints_tt$$=
64
+ $obj$$.tien_paymentByPoints||0;const $hoachtoandtvathue$$=($tk_tien$$,$ty_le$$)=>{$obj$$.details.forEach(function($d$jscomp$26_detail$$){$d$jscomp$26_detail$$={...$d$jscomp$26_detail$$};let $tien_nt$$;$tien_nt$$=$d$jscomp$26_detail$$.tien_hang_ct_nt;$d$jscomp$26_detail$$.tk_co=$option$$.tk_dt;$d$jscomp$26_detail$$.tk_no=$tk_tien$$;$d$jscomp$26_detail$$.ma_kh_co=$obj$$.ma_kh;$d$jscomp$26_detail$$.ma_kh_no=$option$$.ma_kh;$d$jscomp$26_detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;$d$jscomp$26_detail$$.tien=
65
+ $d$jscomp$26_detail$$.tien_nt=Math.roundBy($tien_nt$$*$ty_le$$);$d$jscomp$26_detail$$.flag="DT_"+($d$jscomp$26_detail$$.ma_vt||"");$details$$.push($d$jscomp$26_detail$$)});$obj$$.details.filter($d$$=>$d$$.tien_thue).forEach($detail$$=>{$detail$$={...$detail$$};$detail$$.tk_no=$tk_tien$$;$detail$$.tk_co=$detail$$.tk_thue_co_treo||$detail$$.tk_thue_co;$detail$$.ma_kh||($detail$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh);$detail$$.tien=$detail$$.tien_nt=Math.roundBy($detail$$.tien_thue_nt*$ty_le$$);$detail$$.flag=
66
+ "THUE_"+($detail$$.ma_vt||"");$details$$.push($detail$$)})};$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$&&($hoachtoandtvathue$$($option$$.tk_cn,$rs$jscomp$3_tien_paymentByPoints_tt$$/$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$),$hoachtoandtvathue$$($option$$.tk_tien,($error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$-$rs$jscomp$3_tien_paymentByPoints_tt$$)/$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$));$obj$$.details.filter($d$$=>
67
+ $d$$.diem_thuong&&$d$$.tk_km_no&&$d$$.tk_km_co).forEach(function($d$$){let $detail$$={...$d$$};$detail$$.tk_co=$option$$.tk_km_co||$d$$.tk_km_co;$detail$$.tk_no=$option$$.tk_km_no||$d$$.tk_km_no;$detail$$.ma_kh=$obj$$.ma_kh;$detail$$.tien=$detail$$.tien_nt=$detail$$.diem_thuong*$he_so_qd$$;$details$$.push($detail$$)});$obj$$.ctcpbhs&&$obj$$.ctcpbhs.forEach(function($d$jscomp$30_detail$$){$d$jscomp$30_detail$$={...$d$jscomp$30_detail$$};$d$jscomp$30_detail$$.tk_co=$option$$.tk_dt;$d$jscomp$30_detail$$.tk_no=
68
+ $option$$.tk_cn;$d$jscomp$30_detail$$.ma_kh_co=$obj$$.ma_kh;$d$jscomp$30_detail$$.ma_kh_no=$option$$.ma_kh;$d$jscomp$30_detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;$d$jscomp$30_detail$$.tien_nt=$d$jscomp$30_detail$$.tien_cp_nt;$d$jscomp$30_detail$$.tien=$d$jscomp$30_detail$$.tien_cp;$details$$.push($d$jscomp$30_detail$$)});$obj$$.tien_phi_vc&&$option$$.tk_phi_vc&&($error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$={},$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_co=
69
+ $option$$.tk_phi_vc,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_no=$option$$.tk_cn,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien_nt=$obj$$.tien_phi_vc||0,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien=$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien_nt,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.ma_kh_co=$obj$$.ma_kh,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.ma_kh_no=$obj$$.nhan_vien_giao_hang||
70
+ $obj$$.don_vi_vc,$details$$.push($error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$));$obj$$.tien_freeship&&($error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$={},$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_no=$option$$.tk_cp_gh,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_co=$option$$.tk_cn,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien_nt=$obj$$.tien_freeship||0,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien=
71
+ $error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien_nt,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.ma_kh_no=$obj$$.ma_kh,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.ma_kh_co=$option$$.ma_kh,$details$$.push($error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$));$obj$$.tt_tien_thuong&&($error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$={},$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_no=$option$$.tk_cp_bh,
72
+ $error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_co=$option$$.tk_cn,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien_nt=$obj$$.tt_tien_thuong||0,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien=$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien_nt,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.ma_kh_no=$obj$$.ma_kh,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.ma_kh_co=$option$$.ma_kh,$details$$.push($error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$));
73
73
  $obj$$.tien_evoucher&&($error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$={},$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_no=$obj$$.tk_no_evoucher||$option$$.tk_no_evoucher||$option$$.tk_ck,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tk_co=$obj$$.tk_co_evoucher||$option$$.tk_co_evoucher||$option$$.tk_cn,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien_nt=$obj$$.tien_evoucher||0,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien=
74
74
  $error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.tien_nt,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.ma_kh_no=$obj$$.ma_kh,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.ma_kh_co=$option$$.ma_kh,$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$.check_balance=!1,$details$$.push($error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$));if($error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$=($obj$$.tien_ck_hd||0)+$obj$$.details.map($d$$=>
75
75
  $d$$.tien_ck||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0))$rs$jscomp$3_tien_paymentByPoints_tt$$={},$rs$jscomp$3_tien_paymentByPoints_tt$$.tk_no=$option$$.tk_ck,$rs$jscomp$3_tien_paymentByPoints_tt$$.tk_co=$option$$.tk_cn,$rs$jscomp$3_tien_paymentByPoints_tt$$.tien_nt=$error$jscomp$3_t_tt_tien_ck_hd_tt_tt$jscomp$1_tt$jscomp$2_tt$$,$rs$jscomp$3_tien_paymentByPoints_tt$$.tien=$rs$jscomp$3_tien_paymentByPoints_tt$$.tien_nt,$rs$jscomp$3_tien_paymentByPoints_tt$$.ma_kh_no=$obj$$.ma_kh,$rs$jscomp$3_tien_paymentByPoints_tt$$.ma_kh_co=
@@ -78,9 +78,9 @@ options.tk_co_hoa_hong}),(await $obj$$.details.filter($r$$=>$r$$.tien_hoa_hong_c
78
78
  $r$$.tk_no_hoa_hong||$obj$$.tk_no_hoa_hong||$kho$$.tk_no_hoa_hong||options.tk_no_hoa_hong;$r$$.tk_co_hoa_hong=$r$$.tk_co_hoa_hong||$obj$$.tk_co_hoa_hong||$kho$$.tk_co_hoa_hong||options.tk_co_hoa_hong}),(await $obj$$.details.filter($r$$=>$r$$.tien_hoa_hong).asyncGroupBy(["tk_no_hoa_hong","tk_co_hoa_hong"],["tien_hoa_hong"])).forEach($r$$=>{let $tt$$={};$tt$$.tk_no=$r$$.tk_no_hoa_hong;$tt$$.tk_co=$r$$.tk_co_hoa_hong;$tt$$.tien=$tt$$.tien_nt=$r$$.tien_hoa_hong;$tt$$.tien=$tt$$.tien_nt*($obj$$.ty_gia||
79
79
  1);$tt$$.ma_kh=$obj$$.ma_kh_hoa_hong;$tt$$.ma_nv=$obj$$.ma_nv;$tt$$.check_balance=!1;$tt$$.ma_nt="VND";$tt$$.ty_gia=1;$tt$$.tk_no&&$tt$$.tk_co&&$details$$.push($tt$$)}));$obj$$.tien_hoa_hong_gt&&$obj$$.ma_kh_hoa_hong_gt&&($obj$$.details.filter($r$$=>$r$$.tien_hoa_hong_gt).forEach($r$$=>{$r$$.tk_no_hoa_hong_gt=$r$$.tk_no_hoa_hong_gt||$obj$$.tk_no_hoa_hong_gt||$kho$$.tk_no_hoa_hong_gt||options.tk_no_hoa_hong_gt||$obj$$.tk_no_hoa_hong||$kho$$.tk_no_hoa_hong||options.tk_no_hoa_hong;$r$$.tk_co_hoa_hong_gt=
80
80
  $r$$.tk_co_hoa_hong_gt||$obj$$.tk_co_hoa_hong_gt||$kho$$.tk_co_hoa_hong_gt||options.tk_co_hoa_hong_gt||$obj$$.tk_co_hoa_hong||$kho$$.tk_co_hoa_hong||options.tk_co_hoa_hong}),(await $obj$$.details.filter($r$$=>$r$$.tien_hoa_hong_gt).asyncGroupBy(["tk_no_hoa_hong_gt","tk_co_hoa_hong_gt"],["tien_hoa_hong_gt"])).forEach($r$$=>{let $tt$$={};$tt$$.tk_no=$r$$.tk_no_hoa_hong_gt;$tt$$.tk_co=$r$$.tk_co_hoa_hong_gt;$tt$$.tien_nt=$r$$.tien_hoa_hong_gt;$tt$$.tien=$tt$$.tien_nt*($obj$$.ty_gia||1);$tt$$.ma_kh=$obj$$.ma_kh_hoa_hong_gt;
81
- $tt$$.ma_nv=$obj$$.ma_nv;$tt$$.check_balance=!1;$tt$$.ma_nt="VND";$tt$$.ty_gia=1;$tt$$.tk_no&&$tt$$.tk_co&&$details$$.push($tt$$)}));let $details_tienvon$$=[...$product_details$$];$product_details$$.joinModel2($obj$$.id_app,dmvt,{where:"ma_vt",fields:["tk_vt","gia_mua","tk_gv","tg_tk"]},()=>{$details_tienvon$$.forEach(function($d$jscomp$32_detail$$){$d$jscomp$32_detail$$={...$d$jscomp$32_detail$$};$d$jscomp$32_detail$$.tk_no=$option$$.tk_gv;$d$jscomp$32_detail$$.ma_kh=$obj$$.ma_kh;$d$jscomp$32_detail$$.ngay_ct=
82
- $obj$$.ngay_giao_hang||$obj$$.ngay_ct;$d$jscomp$32_detail$$.tk_co=$d$jscomp$32_detail$$.tk_vt||"1561";$d$jscomp$32_detail$$.tien_nt=$d$jscomp$32_detail$$.tien_xuat_nt;$d$jscomp$32_detail$$.tien=$d$jscomp$32_detail$$.tien_xuat;$d$jscomp$32_detail$$.tg_tk||($d$jscomp$32_detail$$.tien=$d$jscomp$32_detail$$.tien_nt=0);$d$jscomp$32_detail$$.ma_nt="VND";$d$jscomp$32_detail$$.ty_gia=1;$details$$.push($d$jscomp$32_detail$$)});(new PostSocai($obj$$,$details$$,null,Socaitmp,$_options$$)).run(function($e$$,
83
- $rs$$){$callback$$($e$$,$rs$$)})})})},thanhtoanhoahongnv:$callback$$=>{if($obj$$.da_chuyen_hoa_hong||!$obj$$.tien_hoa_hong||!$obj$$.user_nv||!$obj$$.chuyen_ngay)return $callback$$();setImmediate(async()=>{try{if($appInfo$$.wallet_address&&$appInfo$$.wallet_token&&$appInfo$$.tang_gioi_thieu_denom){let $wallet_nhan_vien$$=await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),username:$obj$$.user_nv,wallet_type:8});$wallet_nhan_vien$$||=await global.getModel("asskey").createWallet($appInfo$$._id.toString(),
81
+ $tt$$.ma_nv=$obj$$.ma_nv;$tt$$.check_balance=!1;$tt$$.ma_nt="VND";$tt$$.ty_gia=1;$tt$$.tk_no&&$tt$$.tk_co&&$details$$.push($tt$$)}));let $details_tienvon$$=[...($ket_qua_post_sokho$$||[])];$details_tienvon$$.joinModel2($obj$$.id_app,dmvt,{where:"ma_vt",fields:["tk_vt","gia_mua","tk_gv","tg_tk"]},()=>{$details_tienvon$$.forEach(function($d$jscomp$32_detail$$){$d$jscomp$32_detail$$={...$d$jscomp$32_detail$$};$d$jscomp$32_detail$$.tk_no=$option$$.tk_gv;$d$jscomp$32_detail$$.ma_kh=$obj$$.ma_kh;$d$jscomp$32_detail$$.ngay_ct=
82
+ $obj$$.ngay_giao_hang||$obj$$.ngay_ct;$d$jscomp$32_detail$$.tk_co=$d$jscomp$32_detail$$.tk_vt||"1561";$d$jscomp$32_detail$$.tien_nt=$d$jscomp$32_detail$$.tien_xuat_nt;$d$jscomp$32_detail$$.tien=$d$jscomp$32_detail$$.tien_xuat;$d$jscomp$32_detail$$.tg_tk||($d$jscomp$32_detail$$.tien=$d$jscomp$32_detail$$.tien_nt=0);$d$jscomp$32_detail$$.ma_nt="VND";$d$jscomp$32_detail$$.ty_gia=1;$details$$.push($d$jscomp$32_detail$$)});(new PostSocai($obj$$,$details$$,null,Socai,$_options$$)).run(function($e$$,$rs$$){$callback$$($e$$,
83
+ $rs$$)})})})},thanhtoanhoahongnv:$callback$$=>{if($obj$$.da_chuyen_hoa_hong||!$obj$$.tien_hoa_hong||!$obj$$.user_nv||!$obj$$.chuyen_ngay)return $callback$$();setImmediate(async()=>{try{if($appInfo$$.wallet_address&&$appInfo$$.wallet_token&&$appInfo$$.tang_gioi_thieu_denom){let $wallet_nhan_vien$$=await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),username:$obj$$.user_nv,wallet_type:8});$wallet_nhan_vien$$||=await global.getModel("asskey").createWallet($appInfo$$._id.toString(),
84
84
  $obj$$.user_nv,"T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng",8);let $amount$$=$obj$$.tien_hoa_hong,$denom$$=$appInfo$$.tang_gioi_thieu_denom,$memo$$=`Hoa h\u1ed3ng cho \u0111\u01a1n h\u00e0ng s\u1ed1 ${$obj$$.so_ct}: ${numeral($amount$$).format()} ${$denom$$.toUpperCase()}`;await spend($appInfo$$,$obj$$.be_introduced,$wallet_nhan_vien$$.address,$amount$$,$denom$$,$memo$$,"","2");$obj$$.da_chuyen_hoa_hong=!0;await model.updateOne({_id:$obj$$._id},{da_chuyen_hoa_hong:!0})}}catch($e$$){console.error("Kh\u00f4ng th\u1ec3 thanh to\u00e1n ti\u1ec1n hoa h\u1ed3ng",
85
85
  $e$$)}$callback$$()})},thanhtoanhoahonggt:$callback$$=>{if($obj$$.da_chuyen_hoa_hong_gt||!$obj$$.tien_hoa_hong_gt||!$obj$$.user_gt||!$obj$$.chuyen_ngay_gt)return $callback$$();setImmediate(async()=>{try{if($appInfo$$.wallet_address&&$appInfo$$.wallet_token&&$appInfo$$.tang_gioi_thieu_denom){let $wallet_gt$$=await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),username:$obj$$.user_gt,wallet_type:8});$wallet_gt$$||=await global.getModel("asskey").createWallet($appInfo$$._id.toString(),
86
86
  $obj$$.user_gt,"T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng",8);let $amount$$=$obj$$.tien_hoa_hong_gt,$denom$$=$appInfo$$.tang_gioi_thieu_denom,$memo$$=`Hoa h\u1ed3ng cho \u0111\u01a1n h\u00e0ng s\u1ed1 ${$obj$$.so_ct}: ${numeral($amount$$).format()} ${$denom$$.toUpperCase()}`;await spend($appInfo$$,$obj$$.be_introduced,$wallet_gt$$.address,$amount$$,$denom$$,$memo$$,$obj$$.introduce_code,"2");$obj$$.da_chuyen_hoa_hong_gt=!0;await model.updateOne({_id:$obj$$._id},{da_chuyen_hoa_hong_gt:!0})}}catch($e$$){console.error("Kh\u00f4ng th\u1ec3 thanh to\u00e1n ti\u1ec1n hoa h\u1ed3ng",