flexbiz-server 12.1.32 → 12.2.0

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.1.32",
5
+ "version": "12.2.0",
6
6
  "author": {
7
7
  "name": "Van Truong Pham",
8
8
  "email": "invncur@gmail.com"
@@ -14,18 +14,19 @@ class controller{constructor($router$$,$model$$,$name$$,$options$jscomp$0$$={isV
14
14
  !0===$options$jscomp$0$$.require_id_app?(this.require_id_app=!0,this.route_name=`/:id_app/${this.module}`):(this.require_id_app=!1,this.route_name=`/${this.module}`);this.collection_name=$options$jscomp$0$$.collection_name?$options$jscomp$0$$.collection_name:$name$$;this.sort=$options$jscomp$0$$.sort;this.unique=$options$jscomp$0$$.unique;this.getting=$options$jscomp$0$$.onGetting;this.finding=$options$jscomp$0$$.onFinding;this.found=$options$jscomp$0$$.onFound;this.validating=$options$jscomp$0$$.onValidating;
15
15
  this.saving=$options$jscomp$0$$.onSaving;this.creating=$options$jscomp$0$$.onCreating;this.created=$options$jscomp$0$$.onCreated;this.updating=$options$jscomp$0$$.onUpdating;this.updated=$options$jscomp$0$$.onUpdated;this.deleting=$options$jscomp$0$$.onDeleting;this.deleted=$options$jscomp$0$$.onDeleted;this.approveData=$options$jscomp$0$$.approveData;this.view=$options$jscomp$0$$.onView;this.asyncView=async($user$$,$items$$,$options$$)=>{const $self$$=this;return new Promise($resolve$$=>{$self$$.onView($user$$,
16
16
  $items$$,($error$$,$rs$$)=>{if($error$$)return console.error($error$$),$resolve$$($items$$);$resolve$$($rs$$)},$options$$)})};this.onView=($user$$,$items$$,$next$$,$options$$)=>{let $self$$=this,$fields_load$$="";$options$$&&$options$$.req&&$options$$.req.query&&$options$$.req.query.fields&&($fields_load$$=$options$$.req.query.fields);let $schema_paths$$=$model$$.schema.paths;underscore.has($schema_paths$$,"exfields")&&$items$$.forEach($item$$=>{delete $item$$.__v;$item$$.exfields||($item$$.exfields=
17
- {})});async.series({_user_created:$callback$$=>{$items$$.filter($item$$=>$item$$.user_created).joinModel2(null,User,{where:{user_created:"email"},fields:{name_user_created:"name"}},()=>{$callback$$(null)})},_user_updated:$callback$$=>{$items$$.filter($item$$=>$item$$.user_updated).joinModel2(null,User,{where:{user_updated:"email"},fields:{name_user_updated:"name"}},()=>{$callback$$(null)})},_approve:$callback$$=>{!$fields_load$$||0<=$fields_load$$.indexOf("approve_data")?async.mapSeries($items$$,
18
- ($item$$,$next$$)=>{setImmediate(()=>{Approve.find({id_ct:$item$$._id.toString()},{title:1,trang_thai:1,user_approved:1,user_approved_name:1,date_approved:1,user_denied:1,user_denied_name:1,date_denied:1}).lean().exec(async($e$$,$rs$$)=>{setImmediate(async()=>{$item$$.approve_data=$rs$$;await $item$$.approve_data.asyncJoinModel2($item$$.id_app,Participant,{where:{user_approved:"email"},fields:{user_approved_name:"name",signature_image:"signature_image"}});await $item$$.approve_data.asyncJoinModel2($item$$.id_app,
19
- Participant,{where:{user_denied:"email"},fields:{user_denied_name:"name",signature_image:"signature_image"}});$next$$(null)})})})},()=>{$callback$$(null)}):$callback$$(null)},transfer_ct:$callback$$=>{if(underscore.has($schema_paths$$,"id_ct_chuyen")&&$user$$.current_app_info&&$user$$.current_app_info.options&&$user$$.current_app_info.options.id_app_thue)async.mapSeries($items$$,($item$$,$next$$)=>{setImmediate(()=>{$model$$.findOne({id_app:$user$$.current_app_info.options.id_app_thue,id_ct_chuyen:$item$$._id.toString()},
20
- {_id:1}).lean().exec(async($e$$,$rs$$)=>{$rs$$&&($item$$.id_ct_nhan=$rs$$._id);$next$$(null)})})},()=>{$callback$$(null)});else return $callback$$()},posted:$callback$$=>{$options$$&&$options$$.req&&($options$$.req.query.show_posted_book||$options$$.req.query.show_not_post_book)?async.mapSeries($items$$,($item$$,$next$$)=>{setImmediate(async()=>{let $book$$=$options$$.req.query.show_posted_book||$options$$.req.query.show_not_post_book,$exists$$=await global.getModel($book$$).findOne({id_ct:$item$$._id.toString()},
21
- {_id:1});$item$$[`${$book$$}_posted`]=!!$exists$$;$next$$()})},()=>{$callback$$(null)}):$callback$$()}},$e$jscomp$0$$=>{if($e$jscomp$0$$)return $next$$($e$jscomp$0$$);if($options$$&&$options$$.req&&($options$$.req.query.show_posted_book||$options$$.req.query.show_not_post_book)){let $book$$=$options$$.req.query.show_posted_book||$options$$.req.query.show_not_post_book;$items$$=$items$$.filter($r$$=>$options$$.req.query.show_posted_book?$r$$[`${$book$$}_posted`]:!$r$$[`${$book$$}_posted`])}setImmediate(()=>
22
- {if($self$$.view)try{$self$$.view($user$$,$items$$,function($error$jscomp$0$$,$rs$jscomp$0$$){setImmediate(()=>{if($error$jscomp$0$$)return $next$$($error$jscomp$0$$);$self$$.dynamicView?$self$$.dynamicView($user$$,$rs$jscomp$0$$||$items$$,function($error$$,$rs$$){if($error$$)return $next$$($error$$);$next$$(null,$rs$$||$items$$)}):$next$$(null,$rs$jscomp$0$$||$items$$)})},$options$$)}catch($e$$){console.error("Error on view of",$name$$,$e$$),$next$$(null,$items$$)}else $self$$.dynamicView?$self$$.dynamicView($user$$,
23
- $items$$,function($error$$,$rs$$){if($error$$)return $next$$($error$$);$next$$(null,$rs$$||$items$$)}):$next$$(null,$items$$)})})};this.excelParse=$options$jscomp$0$$.onExcelParse;this.options=$options$jscomp$0$$;this.replaceIfExists=$options$jscomp$0$$.replaceIfExists;this.notNeedRight=$options$jscomp$0$$.notNeedRight}getProperty($name$$){return this[$name$$]}getNextId(){let $ma_ct$$=this.name;this.router.route(`${this.route_name}/next/:field`).get(($field$$,$res$$)=>{let $id_app$$=$field$$.user.current_id_app;
24
- $field$$=$field$$.params.field;"so_ct"===$field$$?$res$$.send({[$field$$]:$ma_ct$$}):getNextSequence($id_app$$,$ma_ct$$,$field$$,($e$$,$rs$$)=>{if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});$res$$.send($rs$$)})})}async checkData($appInfo$$,$data$$,$fn$$){const $options$$=this.options;if($data$$.trang_thai&&$data$$.ma_ct){let $tt$$=await trangthai.findOne({ma_ct:$data$$.ma_ct,ma_trang_thai:$data$$.trang_thai},{check_data:1}).lean();
25
- if($tt$$&&0==$tt$$.check_data)return $fn$$()}async.series({checkTonKho:$callback$jscomp$0$$=>{$data$$.details&&$appInfo$$&&$appInfo$$.options&&$appInfo$$.options.khong_xuat_kho_am&&0!=$options$$.check_stock?(async()=>{let $details$$=$data$$.details.filter($d$$=>$d$$.ma_vt&&$d$$.sl_xuat);await $details$$.asyncJoinModel2($appInfo$$._id,dmvt,{where:{ma_vt:"ma_vt"},fields:["tg_tk","kg_kiem_tra_ton_kho","kg_kiem_tra_ton_kho_tt","combo","ten_vt"]});$details$$=$details$$.filter($d$$=>$d$$.tg_tk&&!$d$$.kg_kiem_tra_ton_kho||
26
- 0<($d$$.combo||[]).length);$details$$=$details$$.map($detail$$=>$detail$$.combo&&0<$detail$$.combo.length?$detail$$.combo.map($c$$=>{$c$$=$c$$.toObject?$c$$.toObject():{...$c$$};$c$$.sl_xuat*=$detail$$.sl_xuat;$c$$.ma_kho=$detail$$.ma_kho;return $c$$}):[$detail$$]).reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]);await $details$$.asyncJoinModel2($appInfo$$._id,dmqddvt,{where:{ma_vt:"ma_vt",ma_dvt:"ma_dvt"},fields:"ty_le_qd"});let $data_sokho$$=[];$data$$._id&&($data_sokho$$=await Sokho.find({id_ct:$data$$._id.toString()}).lean());
27
- $details$$.forEach($d$$=>{$d$$.he_so_qd=$d$$.ty_le_qd||1;$d$$.sl_xuat_qd=$d$$.he_so_qd*$d$$.sl_xuat});$details$$=await $details$$.asyncGroupBy(["ma_vt","ma_kho","ten_vt"],["sl_xuat_qd"]);async.mapSeries($details$$,($d$$,$callback$$)=>{let $ma_kho$$=$d$$.ma_kho||$data$$.ma_kho||$data$$.ma_kho_x,$query$$={ma_vt:$d$$.ma_vt,ma_kho:$ma_kho$$,ngay:new Date,id_app:$appInfo$$._id};$d$$.kg_kiem_tra_ton_kho_tt||($d$$.ma_lo&&($query$$.ma_lo=$d$$.ma_lo),$d$$.han_sd&&($query$$.han_sd=$d$$.han_sd),$d$$.ma_tt1&&
28
- ($query$$.ma_tt1=$d$$.ma_tt1),$d$$.ma_tt2&&($query$$.ma_tt2=$d$$.ma_tt2),$d$$.ma_tt3&&($query$$.ma_tt3=$d$$.ma_tt3));ckvt($query$$,function($e$$,$rs$$){if($e$$)return $callback$$($e$$);$rs$$?($e$$=$rs$$.csum("ton"),$rs$$=$data_sokho$$.filter($s$$=>$s$$.ma_vt===$d$$.ma_vt&&$s$$.ma_kho===$ma_kho$$).reduce(($a$$,$b$$)=>($a$$.sl_xuat_qd||0)+($b$$.sl_xuat_qd||0),0),$d$$.sl_xuat_qd>utils.round($e$$+$rs$$,2)?$callback$$(`S\u1ea3n ph\u1ea9m ${$d$$.ma_vt} - ${$d$$.ten_vt} c\u00f3 s\u1ed1 l\u01b0\u1ee3ng xu\u1ea5t quy \u0111\u1ed5i (${$d$$.sl_xuat_qd}) l\u1edbn h\u01a1n s\u1ed1 l\u01b0\u1ee3ng t\u1ed3n quy \u0111\u1ed5i (${$e$$+
17
+ {})});async.series({_Participant_created:$callback$$=>{underscore.has($schema_paths$$,"id_app")?$items$$.filter($item$$=>$item$$.user_created).joinModel2($user$$.current_id_app,Participant,{where:{user_created:"email"},fields:{name_user_created:"name"}},()=>{$callback$$(null)}):$items$$.filter($item$$=>$item$$.user_created).joinModel2(null,User,{where:{user_created:"email"},fields:{name_user_created:"name"}},()=>{$callback$$(null)})},_Participant_updated:$callback$$=>{underscore.has($schema_paths$$,
18
+ "id_app")?$items$$.filter($item$$=>$item$$.user_updated).joinModel2($user$$.current_id_app,Participant,{where:{user_updated:"email"},fields:{name_user_updated:"name"}},()=>{$callback$$(null)}):$items$$.filter($item$$=>$item$$.user_updated).joinModel2(null,User,{where:{user_updated:"email"},fields:{name_user_updated:"name"}},()=>{$callback$$(null)})},_approve:$callback$$=>{!$fields_load$$||0<=$fields_load$$.indexOf("approve_data")?async.mapSeries($items$$,($item$$,$next$$)=>{setImmediate(()=>{Approve.find({id_ct:$item$$._id.toString()},
19
+ {title:1,trang_thai:1,user_approved:1,user_approved_name:1,date_approved:1,user_denied:1,user_denied_name:1,date_denied:1}).lean().exec(async($e$$,$rs$$)=>{setImmediate(async()=>{$item$$.approve_data=$rs$$;await $item$$.approve_data.asyncJoinModel2($item$$.id_app,Participant,{where:{user_approved:"email"},fields:{user_approved_name:"name",signature_image:"signature_image"}});await $item$$.approve_data.asyncJoinModel2($item$$.id_app,Participant,{where:{user_denied:"email"},fields:{user_denied_name:"name",
20
+ signature_image:"signature_image"}});$next$$(null)})})})},()=>{$callback$$(null)}):$callback$$(null)},transfer_ct:$callback$$=>{if(underscore.has($schema_paths$$,"id_ct_chuyen")&&$user$$.current_app_info&&$user$$.current_app_info.options&&$user$$.current_app_info.options.id_app_thue)async.mapSeries($items$$,($item$$,$next$$)=>{setImmediate(()=>{$model$$.findOne({id_app:$user$$.current_app_info.options.id_app_thue,id_ct_chuyen:$item$$._id.toString()},{_id:1}).lean().exec(async($e$$,$rs$$)=>{$rs$$&&
21
+ ($item$$.id_ct_nhan=$rs$$._id);$next$$(null)})})},()=>{$callback$$(null)});else return $callback$$()},posted:$callback$$=>{$options$$&&$options$$.req&&($options$$.req.query.show_posted_book||$options$$.req.query.show_not_post_book)?async.mapSeries($items$$,($item$$,$next$$)=>{setImmediate(async()=>{let $book$$=$options$$.req.query.show_posted_book||$options$$.req.query.show_not_post_book,$exists$$=await global.getModel($book$$).findOne({id_ct:$item$$._id.toString()},{_id:1});$item$$[`${$book$$}_posted`]=
22
+ !!$exists$$;$next$$()})},()=>{$callback$$(null)}):$callback$$()}},$e$jscomp$0$$=>{if($e$jscomp$0$$)return $next$$($e$jscomp$0$$);if($options$$&&$options$$.req&&($options$$.req.query.show_posted_book||$options$$.req.query.show_not_post_book)){let $book$$=$options$$.req.query.show_posted_book||$options$$.req.query.show_not_post_book;$items$$=$items$$.filter($r$$=>$options$$.req.query.show_posted_book?$r$$[`${$book$$}_posted`]:!$r$$[`${$book$$}_posted`])}setImmediate(()=>{if($self$$.view)try{$self$$.view($user$$,
23
+ $items$$,function($error$jscomp$0$$,$rs$jscomp$0$$){setImmediate(()=>{if($error$jscomp$0$$)return $next$$($error$jscomp$0$$);$self$$.dynamicView?$self$$.dynamicView($user$$,$rs$jscomp$0$$||$items$$,function($error$$,$rs$$){if($error$$)return $next$$($error$$);$next$$(null,$rs$$||$items$$)}):$next$$(null,$rs$jscomp$0$$||$items$$)})},$options$$)}catch($e$$){console.error("Error on view of",$name$$,$e$$),$next$$(null,$items$$)}else $self$$.dynamicView?$self$$.dynamicView($user$$,$items$$,function($error$$,
24
+ $rs$$){if($error$$)return $next$$($error$$);$next$$(null,$rs$$||$items$$)}):$next$$(null,$items$$)})})};this.excelParse=$options$jscomp$0$$.onExcelParse;this.options=$options$jscomp$0$$;this.replaceIfExists=$options$jscomp$0$$.replaceIfExists;this.notNeedRight=$options$jscomp$0$$.notNeedRight}getProperty($name$$){return this[$name$$]}getNextId(){let $ma_ct$$=this.name;this.router.route(`${this.route_name}/next/:field`).get(($field$$,$res$$)=>{let $id_app$$=$field$$.user.current_id_app;$field$$=$field$$.params.field;
25
+ "so_ct"===$field$$?$res$$.send({[$field$$]:$ma_ct$$}):getNextSequence($id_app$$,$ma_ct$$,$field$$,($e$$,$rs$$)=>{if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});$res$$.send($rs$$)})})}async checkData($appInfo$$,$data$$,$fn$$){const $options$$=this.options;if($data$$.trang_thai&&$data$$.ma_ct){let $tt$$=await trangthai.findOne({ma_ct:$data$$.ma_ct,ma_trang_thai:$data$$.trang_thai},{check_data:1}).lean();if($tt$$&&0==$tt$$.check_data)return $fn$$()}async.series({checkTonKho:$callback$jscomp$0$$=>
26
+ {$data$$.details&&$appInfo$$&&$appInfo$$.options&&$appInfo$$.options.khong_xuat_kho_am&&0!=$options$$.check_stock?(async()=>{let $details$$=$data$$.details.filter($d$$=>$d$$.ma_vt&&$d$$.sl_xuat);await $details$$.asyncJoinModel2($appInfo$$._id,dmvt,{where:{ma_vt:"ma_vt"},fields:["tg_tk","kg_kiem_tra_ton_kho","kg_kiem_tra_ton_kho_tt","combo","ten_vt"]});$details$$=$details$$.filter($d$$=>$d$$.tg_tk&&!$d$$.kg_kiem_tra_ton_kho||0<($d$$.combo||[]).length);$details$$=$details$$.map($detail$$=>$detail$$.combo&&
27
+ 0<$detail$$.combo.length?$detail$$.combo.map($c$$=>{$c$$=$c$$.toObject?$c$$.toObject():{...$c$$};$c$$.sl_xuat*=$detail$$.sl_xuat;$c$$.ma_kho=$detail$$.ma_kho;return $c$$}):[$detail$$]).reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]);await $details$$.asyncJoinModel2($appInfo$$._id,dmqddvt,{where:{ma_vt:"ma_vt",ma_dvt:"ma_dvt"},fields:"ty_le_qd"});let $data_sokho$$=[];$data$$._id&&($data_sokho$$=await Sokho.find({id_ct:$data$$._id.toString()}).lean());$details$$.forEach($d$$=>{$d$$.he_so_qd=$d$$.ty_le_qd||
28
+ 1;$d$$.sl_xuat_qd=$d$$.he_so_qd*$d$$.sl_xuat});$details$$=await $details$$.asyncGroupBy(["ma_vt","ma_kho","ten_vt"],["sl_xuat_qd"]);async.mapSeries($details$$,($d$$,$callback$$)=>{let $ma_kho$$=$d$$.ma_kho||$data$$.ma_kho||$data$$.ma_kho_x,$query$$={ma_vt:$d$$.ma_vt,ma_kho:$ma_kho$$,ngay:new Date,id_app:$appInfo$$._id};$d$$.kg_kiem_tra_ton_kho_tt||($d$$.ma_lo&&($query$$.ma_lo=$d$$.ma_lo),$d$$.han_sd&&($query$$.han_sd=$d$$.han_sd),$d$$.ma_tt1&&($query$$.ma_tt1=$d$$.ma_tt1),$d$$.ma_tt2&&($query$$.ma_tt2=
29
+ $d$$.ma_tt2),$d$$.ma_tt3&&($query$$.ma_tt3=$d$$.ma_tt3));ckvt($query$$,function($e$$,$rs$$){if($e$$)return $callback$$($e$$);$rs$$?($e$$=$rs$$.csum("ton"),$rs$$=$data_sokho$$.filter($s$$=>$s$$.ma_vt===$d$$.ma_vt&&$s$$.ma_kho===$ma_kho$$).reduce(($a$$,$b$$)=>($a$$.sl_xuat_qd||0)+($b$$.sl_xuat_qd||0),0),$d$$.sl_xuat_qd>utils.round($e$$+$rs$$,2)?$callback$$(`S\u1ea3n ph\u1ea9m ${$d$$.ma_vt} - ${$d$$.ten_vt} c\u00f3 s\u1ed1 l\u01b0\u1ee3ng xu\u1ea5t quy \u0111\u1ed5i (${$d$$.sl_xuat_qd}) l\u1edbn h\u01a1n s\u1ed1 l\u01b0\u1ee3ng t\u1ed3n quy \u0111\u1ed5i (${$e$$+
29
30
  $rs$$})`):$callback$$()):$callback$$()})},$e$$=>{$callback$jscomp$0$$($e$$)})})():$callback$jscomp$0$$()}},$e$$=>{$fn$$($e$$)})}cacheData($obj$$,$callback$$){$obj$$&&$obj$$.toObject&&($obj$$=$obj$$.toObject());redisCache.set(this.model.collection.name.substring(0,this.model.collection.name.length-1),$obj$$,$callback$$)}deleteData($obj$$,$callback$$){$obj$$&&$obj$$.toObject&&($obj$$=$obj$$.toObject());redisCache.remove(this.model.collection.name.substring(0,this.model.collection.name.length-1),$obj$$,
30
31
  $callback$$)}createRoute($routeName_url$$,$callback$$,$_options$$={method:"GET"}){let $self$$=this;$_options$$.method=$_options$$.method?$_options$$.method.toUpperCase():"GET";let $r$$=function($req$$,$res$$){!1===$self$$.require_id_app?$callback$$($req$$,function($e$$,$rs$$){if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});$res$$.send($rs$$)},$res$$):permission.hasRight($req$$.params.id_app,$req$$.user.email,$self$$.module,
31
32
  "view",function($error$$,$hr$$){$hr$$?$callback$$($req$$,function($e$$,$rs$$){if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});$res$$.send($rs$$)},$res$$):$res$$.status(403).send({error:$error$$||ERR_NOT_PERMIT,code:ERR_NOT_PERMIT_CODE})},{notNeedRight:$self$$.notNeedRight||$_options$$.notNeedRight})};$routeName_url$$=`${this.route_name}/${$routeName_url$$}`;let $router$$=this.router;"DELETE"==$_options$$.method?$router$$.route($routeName_url$$).delete($r$$):
@@ -36,14 +37,14 @@ $trang_thai_approve$$.trang_thai3)$trang_thai_approve$$.update_after_deny={modul
36
37
  try{return evalute($approveData_condition$$,{master:$obj$$,data:$obj$$})}catch($e$$){return console.error("check condition approve",$e$$,$approveData_condition$$),!1}});$approveDatas$$.filter($a$$=>$a$$.approve_users).forEach($approveData$$=>{setImmediate(()=>{let $title$$=$approveData$$.title||"Y\u00eau c\u1ea7u duy\u1ec7t";if(0<=$title$$.indexOf("return ")){var $ds_nguoi_duyet_str_func$$=$title$$;try{$title$$=evalute($ds_nguoi_duyet_str_func$$,{master:$obj$$,data:$obj$$})}catch($e$$){console.error($e$$,
37
38
  $ds_nguoi_duyet_str_func$$)}}$ds_nguoi_duyet_str_func$$=$approveData$$.approve_users;let $update_after_approve$$=$approveData$$.update_after_approve,$update_after_deny$$=$approveData$$.update_after_deny;if(_.isString($ds_nguoi_duyet_str_func$$))try{let $str_func$$=$ds_nguoi_duyet_str_func$$;0>$str_func$$.indexOf("return ")&&($str_func$$=`return ${$str_func$$}`);$ds_nguoi_duyet_str_func$$=evalute($str_func$$,{master:$obj$$,data:$obj$$});if(!_.isArray($ds_nguoi_duyet_str_func$$)){console.error("danh s\u00e1ch ng\u01b0\u1eddi duy\u1ec7t ph\u1ea3i l\u00e0 m\u1ed9t m\u1ea3ng, hi\u1ec7n t\u1ea1i \u0111ang l\u00e0",
38
39
  $ds_nguoi_duyet_str_func$$);return}}catch($e$$){console.error($e$$,$ds_nguoi_duyet_str_func$$);return}if($approveData$$.approve_users_custom)try{let $str_func$$=$approveData$$.approve_users_custom;0>$str_func$$.indexOf("return ")&&($str_func$$=`return ${$str_func$$}`);let $ds_nguoi_duyet_custom$$=evalute($str_func$$,{master:$obj$$,data:$obj$$});$ds_nguoi_duyet_custom$$&&(_.isArray($ds_nguoi_duyet_custom$$)?$ds_nguoi_duyet_str_func$$=[...$ds_nguoi_duyet_str_func$$,...$ds_nguoi_duyet_custom$$]:console.error("danh s\u00e1ch ng\u01b0\u1eddi duy\u1ec7t ph\u1ea3i l\u00e0 m\u1ed9t m\u1ea3ng, hi\u1ec7n t\u1ea1i \u0111ang l\u00e0",
39
- $ds_nguoi_duyet_custom$$))}catch($e$$){console.error($e$$,$approveData$$.approve_users_custom)}if($ds_nguoi_duyet_str_func$$&&0!==$ds_nguoi_duyet_str_func$$.length&&($ds_nguoi_duyet_str_func$$=[...(new Set($ds_nguoi_duyet_str_func$$))],$obj$$.trang_thai==$approveData$$.trang_thai)){let $user_approves$$=$ds_nguoi_duyet_str_func$$.map($nguoi_duyet$$=>({email:$nguoi_duyet$$,name:$nguoi_duyet$$}));$user_approves$$.joinModel2($obj$$.id_app,Participant,{where:"email",fields:"name"},()=>{Approve.request($user_request$$,
40
- $user_approves$$,$title$$,$obj$$,$e$$=>{$e$$&&console.error("error create request approve",$e$$.message)},$update_after_approve$$,$approveData$$.template_content,$update_after_deny$$)})}})});$next$$(null,$obj$$)}async import($user$$,$id_app$$,$data$$,$callback$jscomp$0$$,$options$$={replace:!0,req:null}){const $ctrl$$=this;let $replace$$=$options$$.replace,$rows_error$$=[];const $listInfo$$=global.getModel("listinfo");let $info$$=await $listInfo$$.findOne({code:$ctrl$$.name.toLowerCase()}).lean();
41
- $info$$&&await $listInfo$$.updateModel($info$$,$ctrl$$.model);$data$$=$data$$.filter($row$$=>{let $has_data$$=!1;for(let $key$$ in $row$$)if($row$$[$key$$]){$has_data$$=!0;break}return $has_data$$});$data$$.forEach($r$$=>{delete $r$$.ten_dvcs});await $data$$.filter($r$$=>$r$$.ma_dvcs).asyncJoinModel2($id_app$$,global.getModel("dvcs"),{where:{ma_dvcs:"_id"},fields:"ten_dvcs"});async.mapSeries($data$$,function($row$$,$callback$$){const $row_keys$$=Object.keys($row$$);$row_keys$$.filter($key$$=>$ctrl$$.model.schema.paths[$key$$]).forEach($key$$=>
42
- {let $data_type$$=$ctrl$$.model.schema.paths[$key$$].instance.toLowerCase(),$data_value$$=$row$$[$key$$];if($data_value$$&&_.isString($data_value$$)&&("mixed"==$data_type$$||"array"==$data_type$$)&&($data_value$$=$data_value$$.trim(),0==$data_value$$.indexOf("[")||0==$data_value$$.indexOf("{")))try{$row$$[$key$$]=JSONParser($data_value$$)}catch($e$$){delete $row$$[$key$$],console.error("Error parse data",$e$$)}});setImmediate(()=>{delete $row$$.__v;$row$$.ma_dvcs&&!$row$$.ten_dvcs&&delete $row$$.ma_dvcs;
43
- $row$$.id_app&&$id_app$$!=$row$$.id_app&&delete $row$$._id;delete $row$$.id_app;if($replace$$&&($ctrl$$.unique&&0<$ctrl$$.unique.length||$row$$._id)){let $query$$={};$row$$._id?$query$$._id=$row$$._id:(0!=$ctrl$$.require_id_app&&($query$$.id_app=$id_app$$),$ctrl$$.options.unique_imp&&$row$$[$ctrl$$.options.unique_imp]?$query$$[$ctrl$$.options.unique_imp]=$row$$[$ctrl$$.options.unique_imp]:$ctrl$$.unique.forEach(function($k$$){0<=$row_keys$$.indexOf($k$$)&&($query$$[$k$$]=$row$$[$k$$])}));$ctrl$$.model.find($query$$).lean().exec(function($error$$,
44
- $rss$$){if(1<$rss$$.length)return $callback$$("Kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt \u0111\u1ed1i t\u01b0\u1ee3ng:"+Object.values($query$$).join("-"));setImmediate(()=>{if($error$$)return $callback$$($error$$);if(1===$rss$$.length){let $rs$$=$rss$$[0];$row$$.id_app=$rs$$.id_app;$row$$._id=$rs$$._id.toString();$ctrl$$.unique.forEach(function($k$$){$row$$[$k$$]=$rs$$[$k$$]});update($user$$,$ctrl$$,$rs$$._id,$row$$,function($e$$){if($e$$){let $_e$$=$e$$;underscore.isArray($_e$$)||($_e$$=[$e$$]);$rows_error$$.push({row:$row$$,
45
- error:"Error update data:"+$_e$$})}$callback$$()},"import",$options$$.req)}else create($user$$,$ctrl$$,$row$$,function($e$$){if($e$$){let $_e$$=$e$$;underscore.isArray($_e$$)||($_e$$=[$e$$]);$rows_error$$.push({row:$row$$,error:$_e$$})}$callback$$()},$row$$._id,$options$$.req)})})}else create($user$$,$ctrl$$,$row$$,function($e$$){setImmediate(()=>{if($e$$){let $_e$$=$e$$;underscore.isArray($_e$$)||($_e$$=[$e$$]);$rows_error$$.push({row:$row$$,error:$_e$$})}$callback$$()})},$row$$._id,$options$$.req)})},
46
- function($error$$){setImmediate(()=>{console.log("finish import...");if($error$$)return $callback$jscomp$0$$($error$$);0===$rows_error$$.length?$callback$jscomp$0$$(null,{rows_imported:$data$$.length,rows_error:[]}):$callback$jscomp$0$$(null,{rows_imported:$data$$.length-$rows_error$$.length,rows_error:$rows_error$$})})})}}controller.prototype.__proto__=EventEmitter.prototype;
40
+ $ds_nguoi_duyet_custom$$))}catch($e$$){console.error($e$$,$approveData$$.approve_users_custom)}if($ds_nguoi_duyet_str_func$$&&0!==$ds_nguoi_duyet_str_func$$.length&&($ds_nguoi_duyet_str_func$$=[...(new Set($ds_nguoi_duyet_str_func$$))],$obj$$.trang_thai==$approveData$$.trang_thai)){let $user_approves$$=$ds_nguoi_duyet_str_func$$.map($nguoi_duyet$$=>({email:$nguoi_duyet$$,name:$nguoi_duyet$$}));$user_approves$$.joinModel2($obj$$.id_app,Participant,{where:"email",fields:"name"},()=>{[$user_request$$].joinModel2($obj$$.id_app,
41
+ Participant,{where:"email",fields:"name"},()=>{Approve.request($user_request$$,$user_approves$$,$title$$,$obj$$,$e$$=>{$e$$&&console.error("error create request approve",$e$$.message)},$update_after_approve$$,$approveData$$.template_content,$update_after_deny$$)})})}})});$next$$(null,$obj$$)}async import($user$$,$id_app$$,$data$$,$callback$jscomp$0$$,$options$$={replace:!0,req:null}){const $ctrl$$=this;let $replace$$=$options$$.replace,$rows_error$$=[];const $listInfo$$=global.getModel("listinfo");
42
+ let $info$$=await $listInfo$$.findOne({code:$ctrl$$.name.toLowerCase()}).lean();$info$$&&await $listInfo$$.updateModel($info$$,$ctrl$$.model);$data$$=$data$$.filter($row$$=>{let $has_data$$=!1;for(let $key$$ in $row$$)if($row$$[$key$$]){$has_data$$=!0;break}return $has_data$$});$data$$.forEach($r$$=>{delete $r$$.ten_dvcs});await $data$$.filter($r$$=>$r$$.ma_dvcs).asyncJoinModel2($id_app$$,global.getModel("dvcs"),{where:{ma_dvcs:"_id"},fields:"ten_dvcs"});async.mapSeries($data$$,function($row$$,$callback$$){const $row_keys$$=
43
+ Object.keys($row$$);$row_keys$$.filter($key$$=>$ctrl$$.model.schema.paths[$key$$]).forEach($key$$=>{let $data_type$$=$ctrl$$.model.schema.paths[$key$$].instance.toLowerCase(),$data_value$$=$row$$[$key$$];if($data_value$$&&_.isString($data_value$$)&&("mixed"==$data_type$$||"array"==$data_type$$)&&($data_value$$=$data_value$$.trim(),0==$data_value$$.indexOf("[")||0==$data_value$$.indexOf("{")))try{$row$$[$key$$]=JSONParser($data_value$$)}catch($e$$){delete $row$$[$key$$],console.error("Error parse data",
44
+ $e$$)}});setImmediate(()=>{delete $row$$.__v;$row$$.ma_dvcs&&!$row$$.ten_dvcs&&delete $row$$.ma_dvcs;$row$$.id_app&&$id_app$$!=$row$$.id_app&&delete $row$$._id;delete $row$$.id_app;if($replace$$&&($ctrl$$.unique&&0<$ctrl$$.unique.length||$row$$._id)){let $query$$={};$row$$._id?$query$$._id=$row$$._id:(0!=$ctrl$$.require_id_app&&($query$$.id_app=$id_app$$),$ctrl$$.options.unique_imp&&$row$$[$ctrl$$.options.unique_imp]?$query$$[$ctrl$$.options.unique_imp]=$row$$[$ctrl$$.options.unique_imp]:$ctrl$$.unique.forEach(function($k$$){0<=
45
+ $row_keys$$.indexOf($k$$)&&($query$$[$k$$]=$row$$[$k$$])}));$ctrl$$.model.find($query$$).lean().exec(function($error$$,$rss$$){if(1<$rss$$.length)return $callback$$("Kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt \u0111\u1ed1i t\u01b0\u1ee3ng:"+Object.values($query$$).join("-"));setImmediate(()=>{if($error$$)return $callback$$($error$$);if(1===$rss$$.length){let $rs$$=$rss$$[0];$row$$.id_app=$rs$$.id_app;$row$$._id=$rs$$._id.toString();$ctrl$$.unique.forEach(function($k$$){$row$$[$k$$]=$rs$$[$k$$]});update($user$$,
46
+ $ctrl$$,$rs$$._id,$row$$,function($e$$){if($e$$){let $_e$$=$e$$;underscore.isArray($_e$$)||($_e$$=[$e$$]);$rows_error$$.push({row:$row$$,error:"Error update data:"+$_e$$})}$callback$$()},"import",$options$$.req)}else create($user$$,$ctrl$$,$row$$,function($e$$){if($e$$){let $_e$$=$e$$;underscore.isArray($_e$$)||($_e$$=[$e$$]);$rows_error$$.push({row:$row$$,error:$_e$$})}$callback$$()},$row$$._id,$options$$.req)})})}else create($user$$,$ctrl$$,$row$$,function($e$$){setImmediate(()=>{if($e$$){let $_e$$=
47
+ $e$$;underscore.isArray($_e$$)||($_e$$=[$e$$]);$rows_error$$.push({row:$row$$,error:$_e$$})}$callback$$()})},$row$$._id,$options$$.req)})},function($error$$){setImmediate(()=>{console.log("finish import...");if($error$$)return $callback$jscomp$0$$($error$$);0===$rows_error$$.length?$callback$jscomp$0$$(null,{rows_imported:$data$$.length,rows_error:[]}):$callback$jscomp$0$$(null,{rows_imported:$data$$.length-$rows_error$$.length,rows_error:$rows_error$$})})})}}controller.prototype.__proto__=EventEmitter.prototype;
47
48
  const getNextSequence=async function($id_app$$,$ma_ct$$,$field$$,$callback$$,$options$$={}){var $condition_qct_qcts$$={status:!0,field:$field$$,id_app:$id_app$$,$and:[{$or:[{ma_ct:"#",ma_ct_khac:{$regex:$ma_ct$$,$options:"i"}},{cac_ma_ct:$ma_ct$$.toLowerCase()},{ma_ct:$ma_ct$$.toUpperCase()}]}]};$options$$.id_qct&&($condition_qct_qcts$$._id=$options$$.id_qct);if($options$$.ngay_ct){let $start_date$$=moment($options$$.ngay_ct).startOf("date").toDate(),$end_date$$=moment($options$$.ngay_ct).endOf("date").toDate();
48
49
  $condition_qct_qcts$$.$and.push({$or:[{tu_ngay:null},{tu_ngay:{$lte:$end_date$$}}]});$condition_qct_qcts$$.$and.push({$or:[{den_ngay:null},{den_ngay:{$gte:$start_date$$}}]})}$options$$.toObject&&($options$$=$options$$.toObject());$condition_qct_qcts$$=await dmqct.find($condition_qct_qcts$$).lean();const $keys$$=Object.keys($options$$),$qct$$=$condition_qct_qcts$$.find($qct$$=>{if($qct$$.dieu_kien&&0<$keys$$.length)try{let $str_func$$=$qct$$.dieu_kien;if(0<=$str_func$$.indexOf("async "))return!1;0!==
49
50
  $str_func$$.indexOf("return ")&&($str_func$$=`return ${$str_func$$}`);return evalute($str_func$$,{...$options$$,master:{...$options$$},moment,numeral})}catch($e$$){return console.error("Error find quyen chung tu",$e$$,$qct$$.dieu_kien),!1}else return!0});let $code$$=$qct$$?$qct$$._id.toString():$field$$;counter.getNextSequence($id_app$$,$ma_ct$$,$code$$,async function($error$$,$rs$$){if($error$$)console.error("auto create code for",$ma_ct$$,$code$$,$error$$),$callback$$($error$$);else{if($qct$$){let $tien_to$$=
@@ -55,41 +56,43 @@ controller.prototype.getFieldNoRight=function(){let $ctrl$$=this;this.router.rou
55
56
  controller.prototype.getSocai=function(){this.router.route(`${this.route_name}/socai/:id_ct`).get(function($req$$,$res$$){Socai.find({id_ct:$req$$.params.id_ct}).lean().exec(($e$$,$rs$$)=>{setImmediate(()=>{if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});$res$$.send($rs$$)})})})};
56
57
  controller.prototype.getVsocai=function(){this.router.route("/:id_app/vsocai/:id_ct").get(function($req$$,$res$$){Socai.find({id_ct:$req$$.params.id_ct}).lean().exec(($e$$,$rs$$)=>{setImmediate(()=>{if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$.error||$e$$});let $dks$$=[];$rs$$.forEach($r$$=>{$dks$$.push({no_co:"N",tk:$r$$.tk_no,tien:$r$$.tien,tien_nt:$r$$.tien_nt})});$rs$$.forEach($r$$=>{$dks$$.push({no_co:"C",tk:$r$$.tk_co,
57
58
  tien:$r$$.tien,tien_nt:$r$$.tien_nt})});$res$$.send($dks$$)})})})};controller.prototype.getSokho=function(){this.router.route(`${this.route_name}/sokho/:id_ct`).get(function($req$$,$res$$){Sokho.find({id_ct:$req$$.params.id_ct}).lean().exec(($e$$,$rs$$)=>{setImmediate(()=>{if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$.error||$e$$});$rs$$.joinModel2($req$$.user.current_id_app,dmvt,{where:"ma_vt",fields:"ten_vt"},function(){$res$$.send($rs$$)})})})})};
58
- controller.prototype.find=function($_route_name_route_name$$,$shareRoute$$=!1,$method$$="GET"){let $sort$$,$model$$=this.model,$ctrl$$=this;const $findRoute$$=[function($req$$,$res$$,$next$$){setImmediate(()=>{var $body$jscomp$2_query$$={};underscore.isObject($req$$.body)&&($body$jscomp$2_query$$=$req$$.body);$body$jscomp$2_query$$={...$req$$.query,...$body$jscomp$2_query$$};var $condition$jscomp$1$$={...$body$jscomp$2_query$$};delete $condition$jscomp$1$$.access_token;$req$$.user&&!$body$jscomp$2_query$$.count&&
59
- "log"!==$ctrl$$.name&&"labelinfo"!==$ctrl$$.name&&"listinfo"!==$ctrl$$.name&&"reportinfo"!==$ctrl$$.name&&"moduleinfo"!==$ctrl$$.name&&"options"!==$ctrl$$.name&&log.create({id_app:$req$$.user.current_id_app,id_func:$ctrl$$.name,action:"QUERY",data:{condition:JSON.stringify($condition$jscomp$1$$)}},$req$$.user.email,$req$$.header("user-agent"),$req$$);$req$$.query=$body$jscomp$2_query$$;if($body$jscomp$2_query$$.sort)if(underscore.isObject($body$jscomp$2_query$$.sort))$sort$$=$body$jscomp$2_query$$.sort;
60
- else try{$sort$$=JSONParser($body$jscomp$2_query$$.sort)}catch($e$$){console.error("error parse json",$e$$,$body$jscomp$2_query$$.sort)}!$sort$$&&$ctrl$$.sort&&($sort$$=Object.assign({},$ctrl$$.sort));$condition$jscomp$1$$={};let $or$$=[];for(let $k$$ in $body$jscomp$2_query$$)if("id_app"!==$k$$&&"access_token"!==$k$$)if("_id"===$k$$&&global.mongoose.Types.ObjectId.isValid($body$jscomp$2_query$$._id))try{let $id$$=global.mongoose.Types.ObjectId($body$jscomp$2_query$$._id);$or$$.push({_id:$id$$})}catch($error$$){console.error($error$$)}else{if("q"===
61
- $k$$&&$body$jscomp$2_query$$[$k$$])try{let $q$$=underscore.isObject($body$jscomp$2_query$$[$k$$])?$body$jscomp$2_query$$[$k$$]:JSONParser($body$jscomp$2_query$$[$k$$]);if(Object.keys($q$$).includes("_id"))if(!$q$$._id)delete $q$$._id;else if("object"!==typeof $q$$._id&&!global.mongoose.Types.ObjectId.isValid($q$$._id))return console.error("Condition is not valid",$q$$),$res$$.status(400).send({error:"Condition is not valid"});($condition$jscomp$1$$=$q$$)||($condition$jscomp$1$$={});if($condition$jscomp$1$$.sync_from_date){let $sync_date$$=
62
- moment(new Date($condition$jscomp$1$$.sync_from_date)).startOf("date").toDate();$condition$jscomp$1$$.date_updated={$gte:$sync_date$$};delete $condition$jscomp$1$$.sync_from_date}continue}catch($e$$){return console.error($e$$,$body$jscomp$2_query$$[$k$$]),$res$$.status(400).send({error:"Condition is not valid"})}if("fields"!==$k$$&&underscore.has($model$$.schema.paths,$k$$))if($ctrl$$.options.findExact[$k$$])$condition$jscomp$1$$[$k$$]=$body$jscomp$2_query$$[$k$$];else{let $item$$={};"number"==$ctrl$$.model.schema.paths[$k$$].instance.toLowerCase()?
63
- $item$$[$k$$]=Number($body$jscomp$2_query$$[$k$$]):"date"==$ctrl$$.model.schema.paths[$k$$].instance.toLowerCase()?$item$$[$k$$]=new Date($body$jscomp$2_query$$[$k$$]):"string"==$ctrl$$.model.schema.paths[$k$$].instance.toLowerCase()?$item$$[$k$$]={$regex:$body$jscomp$2_query$$[$k$$],$options:"i"}:$item$$[$k$$]=$body$jscomp$2_query$$[$k$$];$or$$.push($item$$)}else"$text"===$k$$&&$or$$.push({$text:{$search:$body$jscomp$2_query$$[$k$$]}})}0!==$or$$.length&&("$and"===$body$jscomp$2_query$$.cType?$condition$jscomp$1$$.$and=
64
- $or$$:$condition$jscomp$1$$.$or=$or$$);$shareRoute$$||0==$ctrl$$.require_id_app||($condition$jscomp$1$$.id_app=$req$$.user.current_id_app);$ctrl$$.finding?$ctrl$$.finding($req$$.user,$condition$jscomp$1$$,function($error$$,$condition$jscomp$0$$){setImmediate(()=>{if($error$$)return $res$$.status(400).send({error:$error$$.message||$error$$.error||$error$$});$ctrl$$.dynamicFinding?$ctrl$$.dynamicFinding($req$$.user,$condition$jscomp$0$$,function($e$$,$condition$$){if($e$$)return console.error($e$$),
65
- $e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});$req$$.condition=$condition$$;$next$$()}):($req$$.condition=$condition$jscomp$0$$,$next$$())})},{req:$req$$}):$ctrl$$.dynamicFinding?$ctrl$$.dynamicFinding($req$$.user,$condition$jscomp$1$$,function($e$$,$condition$$){if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});$req$$.condition=$condition$$;$next$$()}):($req$$.condition=$condition$jscomp$1$$,
66
- $next$$())})},function($req$$,$res$$,$next$$){if($shareRoute$$)return $next$$();permission.getRightByItem($req$$.user.current_id_app,$model$$,$req$$.user.email,function($e$jscomp$0$$,$_condition$$,$admin$$){setImmediate(()=>{if($e$jscomp$0$$)return $res$$.status(403).send({error:$e$jscomp$0$$.error||$e$jscomp$0$$.message||$e$jscomp$0$$});if($admin$$)return $next$$();$req$$.admin=$admin$$;let $condition$$=$req$$.condition;$condition$$||($condition$$={});$condition$$.$and||($condition$$.$and=[]);if($ctrl$$.options.onRightByItem)$ctrl$$.options.onRightByItem($req$$.user,
67
- $_condition$$,($e$$,$_condition$$)=>{setImmediate(()=>{if($e$$)return $res$$.status(403).send({error:$e$$.error||$e$$.message||$e$$});_.isObject($_condition$$)&&0<Object.keys($_condition$$).length&&$condition$$.$and.push($_condition$$);$req$$.condition=$condition$$;$next$$()})});else _.isObject($_condition$$)&&0<Object.keys($_condition$$).length&&$condition$$.$and.push($_condition$$),$req$$.condition=$condition$$,$next$$()})},$ctrl$$.name,{notNeedRight:$ctrl$$.options.notNeedRight})},function($req$$,
68
- $res$$,$next$$){if($shareRoute$$)return $next$$();setImmediate(()=>{$ctrl$$.options.assignWiths?async.mapSeries($ctrl$$.options.assignWiths,($col$$,$callback$$)=>{setImmediate(()=>{let $m$$=global.getModel($col$$.ref_collection);permission.getRightByItem($req$$.user.current_id_app,$m$$,$req$$.user.email,function($e$jscomp$0$$,$_condition$$,$admin$$){setImmediate(()=>{if($e$jscomp$0$$)return $callback$$($e$jscomp$0$$);if($admin$$)return $callback$$();$_condition$$.id_app=$req$$.user.current_id_app;
69
- $m$$.find($_condition$$).lean().exec(($e$$,$rs$$)=>{setImmediate(()=>{if($e$$)return $callback$$($e$$);let $dsdt$$=underscore.pluck($rs$$,$col$$.ref_field);$dsdt$$.push("");$dsdt$$.push(null);$req$$.condition[$col$$.ref_field]={$in:$dsdt$$};$callback$$()})})})},$ctrl$$.name,{notNeedRight:$ctrl$$.options.notNeedRight})})},$e$$=>{setImmediate(()=>{if($e$$)return $res$$.status(400).send({error:$e$$.error||$e$$.message||$e$$});$next$$()})}):$next$$()})},function($req$$,$res$$,$next$$){if($shareRoute$$)return $next$$();
70
- setImmediate(()=>{if($req$$.admin||"dmdt"===$ctrl$$.name)return $next$$();if(underscore.has($model$$.schema.paths,"ma_dt")||underscore.has($model$$.schema.paths,"id_dt")){let $dmdt$$=mongoose.models.dmdt;permission.getRightDataView($req$$.user.current_id_app,$dmdt$$,$req$$.user.email,function($e$jscomp$0$$,$_condition$$,$admin$$){setImmediate(()=>{if($e$jscomp$0$$)return $res$$.status(400).send({error:$e$jscomp$0$$.error||$e$jscomp$0$$.message||$e$jscomp$0$$});if($admin$$)return $next$$();$_condition$$.id_app=
71
- $req$$.user.current_id_app;$req$$.condition.ma_dt&&($_condition$$.ma_dt=$req$$.condition.ma_dt);$dmdt$$.find($_condition$$,{ma_dt:1,_id:1}).lean().exec(($e$$,$rs$$)=>{setImmediate(()=>{if($e$$)return $res$$.status(400).send({error:$e$$.error||$e$$.message||$e$$});if(underscore.has($model$$.schema.paths,"ma_dt")){var $dsdt$jscomp$1_dsdt$$=underscore.pluck($rs$$,"ma_dt");$dsdt$jscomp$1_dsdt$$.push("");$dsdt$jscomp$1_dsdt$$.push(null);$dsdt$jscomp$1_dsdt$$.push(void 0);$req$$.condition.ma_dt={$in:$dsdt$jscomp$1_dsdt$$}}else $dsdt$jscomp$1_dsdt$$=
72
- underscore.pluck($rs$$,"_id"),$dsdt$jscomp$1_dsdt$$.push(""),$dsdt$jscomp$1_dsdt$$.push(null),$dsdt$jscomp$1_dsdt$$.push(void 0),$req$$.condition.id_dt={$in:$dsdt$jscomp$1_dsdt$$};$next$$()})})})})}else $next$$()})},function($req$$,$res$$,$next$$){setImmediate(()=>{if($shareRoute$$||$req$$.admin||"dmkho"===$ctrl$$.name)return $next$$();if(underscore.has($model$$.schema.paths,"ma_kho")||underscore.has($model$$.schema.paths,"ma_kho_x")||underscore.has($model$$.schema.paths,"ma_kho_n")){let $dmkho$$=
73
- mongoose.models.dmkho;permission.getRightDataView($req$$.user.current_id_app,$dmkho$$,$req$$.user.email,function($e$jscomp$0$$,$_condition$$,$admin$$){setImmediate(()=>{if($e$jscomp$0$$)return $res$$.status(403).send({error:$e$jscomp$0$$.error||$e$jscomp$0$$.message||$e$jscomp$0$$});if($admin$$)return $next$$();$_condition$$.id_app=$req$$.user.current_id_app;$req$$.condition.ma_kho&&($_condition$$.ma_kho=$req$$.condition.ma_kho);$dmkho$$.find($_condition$$,{ma_kho:1}).lean().exec(($e$$,$rs$$)=>{setImmediate(()=>
74
- {if($e$$)return $res$$.status(400).send({error:$e$$.error||$e$$.message||$e$$});let $dskho$$=underscore.pluck($rs$$,"ma_kho");$req$$.condition.ma_kho||($dskho$$.push(""),$dskho$$.push(null),$dskho$$.push(void 0));if(underscore.has($model$$.schema.paths,"ma_kho"))return $req$$.condition.ma_kho={$in:$dskho$$},$next$$();if("pxc"===$ctrl$$.name&&underscore.has($model$$.schema.paths,"ma_kho_x"))return $req$$.condition.ma_kho_x={$in:$dskho$$},$next$$();if("pnc"===$ctrl$$.name&&underscore.has($model$$.schema.paths,
75
- "ma_kho_n"))return $req$$.condition.ma_kho_n={$in:$dskho$$},$next$$();$next$$()})})})})}else $next$$()})},function($req$$,$res$$,$next$$){setImmediate(()=>{if($shareRoute$$)return $next$$();permission.hasRight($req$$.user.current_id_app,$req$$.user.email,$ctrl$$.module,"view",function($error$$,$permission$$){setImmediate(()=>{if($ctrl$$.options.onQuery)$req$$.permission=$permission$$,$ctrl$$.options.onQuery($req$$,$e$$=>{if($e$$)return $res$$.status(400).send({error:$e$$.error||$e$$.message||$e$$});
76
- if(!$req$$.permission)return $res$$.send([]);$next$$()});else{if(!$permission$$)return $res$$.send([]);$next$$()}})},{notNeedRight:$ctrl$$.options.notNeedRight})})},async function($req$$,$res$$){setImmediate(async()=>{let $condition$$=$req$$.condition;$condition$$||($condition$$={});if($shareRoute$$){$condition$$.shared=!0;var $id_sellers_query$$=(await app.find({sale_online:!0},{_id:1}).lean()).map($a$$=>$a$$._id);$condition$$.$and||($condition$$.$and=[]);$condition$$.$and.push({id_app:{$in:$id_sellers_query$$}});
77
- $condition$$.id_app&&$condition$$.$and.push({id_app:$condition$$.id_app})}else underscore.has($model$$.schema.paths,"id_app")&&!1!==$ctrl$$.require_id_app&&($condition$$.id_app=$req$$.user.current_id_app);"public"===$req$$.user.email&&underscore.has($model$$.schema.paths,"session_created")&&($condition$$.session_created=($req$$.cookies||{}).uid);underscore.extend($condition$$,$ctrl$$.keyValues);$condition$$.$and&&0===$condition$$.$and.length&&delete $condition$$.$and;$condition$$.$or&&0===$condition$$.$or.length&&
78
- delete $condition$$.$or;$condition$$.$nor&&0===$condition$$.$nor.length&&delete $condition$$.$nor;$id_sellers_query$$=null;if($req$$.query.count)$condition$$.$where?(console.log("phai loai bo $where trong condition"),$id_sellers_query$$=$model$$.count($condition$$,function($e$$,$data$$){if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});$res$$.send({rows_number:$data$$})})):$id_sellers_query$$=$model$$.countDocuments($condition$$,
79
- function($e$$,$data$$){if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});$res$$.send({rows_number:$data$$})});else{let $field_not_right$$;try{$field_not_right$$=await permission.getFieldNotRight($req$$.user.current_id_app,$req$$.user.email,$ctrl$$.name)}catch($e$$){$field_not_right$$=[]}var $fields$$=$req$$.query.fields;let $gfields$$={};$fields$$&&(underscore.isArray($fields$$)?$fields$$.forEach($f$$=>{"_id"!==$f$$&&($gfields$$[$f$$]=
80
- 1)}):underscore.isObject($fields$$)?$gfields$$={...$gfields$$,...$fields$$}:$fields$$.split(",").filter($f$$=>$f$$&&0>$field_not_right$$.indexOf($f$$)).forEach($f$$=>{"_id"!==$f$$&&($gfields$$[$f$$]=1)}));$field_not_right$$.forEach($f$$=>{Object.keys($gfields$$).find($k$$=>1==$gfields$$[$k$$])?delete $gfields$$[$f$$]:$gfields$$[$f$$]=0});!$fields$$&&(($fields$$=$req$$.query.notfields)&&(underscore.isArray($fields$$)?$fields$$.forEach($f$$=>{$f$$&&"_id"!==$f$$&&(Object.keys($gfields$$).find($k$$=>
81
- 1==$gfields$$[$k$$])?delete $gfields$$[$f$$]:$gfields$$[$f$$]=0)}):underscore.isObject($fields$$)?$gfields$$={...$gfields$$,...$fields$$}:$fields$$.split(",").forEach($f$$=>{$f$$&&"_id"!==$f$$&&(Object.keys($gfields$$).find($k$$=>1==$gfields$$[$k$$])?delete $gfields$$[$f$$]:$gfields$$[$f$$]=0)})),$shareRoute$$||"public"===$req$$.user.email)&&(Object.keys($gfields$$).find($k$$=>1==$gfields$$[$k$$])?(delete $gfields$$.dataview_to,delete $gfields$$.dataview_to_users):($gfields$$.dataview_to=0,$gfields$$.dataview_to_users=
82
- 0));$condition$$.$text&&($gfields$$||($gfields$$={}),$gfields$$.textScore={$meta:"textScore"});if($req$$.query.group||$req$$.query.project||$req$$.query.match||$req$$.query.aggregate)try{$id_sellers_query$$=$model$$.aggregate([{$match:$condition$$}]);if($req$$.query.group){var $group_page$$=JSONParser($req$$.query.group);$id_sellers_query$$.group($group_page$$)}if($req$$.query.match){let $match$$=JSONParser($req$$.query.match);$id_sellers_query$$.match($match$$)}if($req$$.query.project){var $limit_project$$=
83
- JSONParser($req$$.query.project);$id_sellers_query$$.project($limit_project$$)}else if($gfields$$&&0<Object.keys($gfields$$).length)$limit_project$$=$gfields$$;else if($limit_project$$={_id:1},$group_page$$)for(let $key$$ in $group_page$$)$limit_project$$[$key$$]=1;$id_sellers_query$$.project($limit_project$$);if($req$$.query.aggregate){let $aggregate$$=JSONParser($req$$.query.aggregate);$id_sellers_query$$.append($aggregate$$)}}catch($e$$){return $res$$.status(400).send({error:$e$$.message||$e$$.error||
84
- $e$$})}else underscore.has($model$$.schema.paths,"id_app")&&0<Object.keys($gfields$$).length&&Object.keys($gfields$$).find($k$$=>1==$gfields$$[$k$$])&&($gfields$$.id_app=1),$id_sellers_query$$=$model$$.find($condition$$,$gfields$$);!$sort$$&&$gfields$$.textScore?$sort$$={textScore:{$meta:"textScore"}}:$sort$$&&($sort$$._id=1);$sort$$&&$id_sellers_query$$.sort($sort$$);"xlsx"!==$req$$.query.type_data&&"1"!=$req$$.query.rpt&&($group_page$$=$req$$.query.page,($limit_project$$=$req$$.query.limit)&&($limit_project$$=
85
- Number($limit_project$$)),$limit_project$$||($limit_project$$=!1!==$ctrl$$.require_id_app&&"right"!==$ctrl$$.name?20:1E5),$limit_project$$&&500<$limit_project$$&&!$req$$.query.print&&!1!==$ctrl$$.require_id_app&&"right"!==$ctrl$$.name&&($limit_project$$=500),$group_page$$?$id_sellers_query$$.skip((Number($group_page$$)-1)*$limit_project$$).limit($limit_project$$):$id_sellers_query$$.limit($limit_project$$));$id_sellers_query$$.lean&&($id_sellers_query$$=$id_sellers_query$$.lean());$id_sellers_query$$.exec(function($e$jscomp$0$$,
86
- $obj4view$$){if($e$jscomp$0$$)return console.error($e$jscomp$0$$,$condition$$,$gfields$$),$res$$.status(400).send({error:$e$jscomp$0$$.error||$e$jscomp$0$$.message||$e$jscomp$0$$});$obj4view$$||($obj4view$$=[]);async.series({found:function($callback$$){$ctrl$$.found?$ctrl$$.found($req$$.user,$condition$$,$obj4view$$,function($error$$,$items$$){setImmediate(()=>{$callback$$($error$$,$items$$)})}):$callback$$(null,$obj4view$$)},set_collection_name:function($callback$$){$obj4view$$.forEach($obj$$=>{$obj$$.collection_name||
87
- ($obj$$.collection_name=$ctrl$$.collection_name)});$callback$$(null)}},function($error$jscomp$0$$,$rs$jscomp$0$$){setImmediate(()=>{if($error$jscomp$0$$)return $res$$.status(400).send({error:$error$jscomp$0$$.error||$error$jscomp$0$$.message||$error$jscomp$0$$});$obj4view$$=$rs$jscomp$0$$.found;async.series({e_view:function($callback$$){$ctrl$$.onView($req$$.user,$obj4view$$,($error$$,$viewValue$$)=>{setImmediate(()=>{if($error$$)return console.error("Erron on view:",$error$$),$callback$$($error$$);
88
- $callback$$(null,$viewValue$$)})},{req:$req$$,shareRoute:$shareRoute$$})}},async function($app$jscomp$1_dir_root_template_e$$,$_groupBy_func_string_rs$$){if($error$jscomp$0$$)return $res$$.status(400).send({error:$error$jscomp$0$$.error||$error$jscomp$0$$.message||$error$jscomp$0$$});if($req$$.query.type_data&&"xlsx"==$req$$.query.type_data){$app$jscomp$1_dir_root_template_e$$=(configs.paths||{}).templates;let $template_id$$,$excelTemplate$$;if($template_id$$=$req$$.query.id_template){if(!global.mongoose.Types.ObjectId.isValid($template_id$$))return $res$$.status(400).send({error:"M\u1eabu excel kh\u00f4ng t\u1ed3n t\u1ea1i"});
89
- $excelTemplate$$=await global.getModel("exportexceltemplate").findById($template_id$$);if(!$excelTemplate$$||!$excelTemplate$$.file)return $res$$.status(400).send({error:"M\u1eabu excel kh\u00f4ng t\u1ed3n t\u1ea1i"});var $_rs_msg_templatePath$$=$app$jscomp$1_dir_root_template_e$$?`${path.dirname($app$jscomp$1_dir_root_template_e$$)}${$excelTemplate$$.file}`:`${path.dirname(__dirname)}${$excelTemplate$$.file}`}else $app$jscomp$1_dir_root_template_e$$&&($_rs_msg_templatePath$$=`${$app$jscomp$1_dir_root_template_e$$}/excels/lists/${$ctrl$$.name}.xlsx`),
90
- $_rs_msg_templatePath$$&&fs.existsSync($_rs_msg_templatePath$$)||($_rs_msg_templatePath$$=`${path.dirname(__dirname)}/templates/excels/lists/${$ctrl$$.name}.xlsx`);if(!fs.existsSync($_rs_msg_templatePath$$))return $_rs_msg_templatePath$$="File m\u1eabu excel ch\u01b0a \u0111\u01b0\u1ee3c khai b\u00e1o t\u1ea1i '"+$_rs_msg_templatePath$$+"'",$res$$.status(400).send({error:$_rs_msg_templatePath$$});$app$jscomp$1_dir_root_template_e$$={};$_groupBy_func_string_rs$$.e_view.forEach($item$$=>{for(let $_key$$ in $item$$){let $_v$$=
91
- $item$$[$_key$$];if(underscore.isObject($_v$$))for(let $__key$$ in $_v$$){let $__v$$=$_v$$[$__key$$];if(!underscore.isFunction($__v$$))if(0<=$__key$$.indexOf("ngay")||0<=$__key$$.indexOf("date"))try{$item$$[`${$_key$$}_${$__key$$}`]=new Date($__v$$)}catch($e$$){$item$$[`${$_key$$}_${$__key$$}`]=$__v$$}else $item$$[`${$_key$$}_${$__key$$}`]=$__v$$}else if($_v$$&&0<=$_key$$.indexOf("ngay")||0<=$_key$$.indexOf("date"))try{let $d$$=moment($_v$$,"YYYY-MM-DD");$d$$.isValid()&&($item$$[`${$_key$$}`]=$d$$.toDate(),
92
- $item$$[`${$_key$$}_string`]=$d$$.format("DD/MM/YYYY"))}catch($e$$){console.error("Error convert to date",$_v$$,$e$$)}}});$app$jscomp$1_dir_root_template_e$$.detail=$_groupBy_func_string_rs$$.e_view;if($excelTemplate$$&&$excelTemplate$$.handle_data){$_groupBy_func_string_rs$$=`return (async ()=>{
59
+ controller.prototype.find=function($_route_name_route_name$$,$shareRoute$$=!1,$method$$="GET"){let $model$$=this.model,$ctrl$$=this;const $findRoute$$=[function($req$$,$res$$,$next$$){setImmediate(()=>{var $body$jscomp$2_query$$={};underscore.isObject($req$$.body)&&($body$jscomp$2_query$$=$req$$.body);$body$jscomp$2_query$$={...$req$$.query,...$body$jscomp$2_query$$};var $data_log_or$$={...$body$jscomp$2_query$$};delete $data_log_or$$.access_token;$req$$.user&&!$body$jscomp$2_query$$.count&&"log"!==
60
+ $ctrl$$.name&&"labelinfo"!==$ctrl$$.name&&"listinfo"!==$ctrl$$.name&&"reportinfo"!==$ctrl$$.name&&"moduleinfo"!==$ctrl$$.name&&"options"!==$ctrl$$.name&&log.create({id_app:$req$$.user.current_id_app,id_func:$ctrl$$.name,action:"QUERY",data:{condition:JSON.stringify($data_log_or$$)}},$req$$.user.email,$req$$.header("user-agent"),$req$$);$req$$.query=$body$jscomp$2_query$$;if($body$jscomp$2_query$$.sort)if(underscore.isObject($body$jscomp$2_query$$.sort))var $condition$jscomp$1$$=$body$jscomp$2_query$$.sort;
61
+ else try{$condition$jscomp$1$$=JSONParser($body$jscomp$2_query$$.sort)}catch($e$$){return console.error("error parse json",$e$$,$body$jscomp$2_query$$.sort),$res$$.status(400).send({error:"sort is not valid."})}!$condition$jscomp$1$$&&$ctrl$$.sort&&($condition$jscomp$1$$=Object.assign({},$ctrl$$.sort));$req$$.sort=$condition$jscomp$1$$;$condition$jscomp$1$$={};$data_log_or$$=[];for(let $k$$ in $body$jscomp$2_query$$)if("id_app"!==$k$$&&"access_token"!==$k$$)if("_id"===$k$$&&global.mongoose.Types.ObjectId.isValid($body$jscomp$2_query$$._id))try{let $id$$=
62
+ global.mongoose.Types.ObjectId($body$jscomp$2_query$$._id);$data_log_or$$.push({_id:$id$$})}catch($error$$){console.error($error$$)}else{if("q"===$k$$&&$body$jscomp$2_query$$[$k$$])try{let $q$$=underscore.isObject($body$jscomp$2_query$$[$k$$])?$body$jscomp$2_query$$[$k$$]:JSONParser($body$jscomp$2_query$$[$k$$]);if(Object.keys($q$$).includes("_id"))if(!$q$$._id)delete $q$$._id;else if("object"!==typeof $q$$._id&&!global.mongoose.Types.ObjectId.isValid($q$$._id))return console.error("Condition is not valid",
63
+ $q$$),$res$$.status(400).send({error:"Condition is not valid"});($condition$jscomp$1$$=$q$$)||($condition$jscomp$1$$={});if($condition$jscomp$1$$.sync_from_date){let $sync_date$$=moment(new Date($condition$jscomp$1$$.sync_from_date)).startOf("date").toDate();$condition$jscomp$1$$.date_updated={$gte:$sync_date$$};delete $condition$jscomp$1$$.sync_from_date}continue}catch($e$$){return console.error($e$$,$body$jscomp$2_query$$[$k$$]),$res$$.status(400).send({error:"Condition is not valid"})}if("fields"!==
64
+ $k$$&&underscore.has($model$$.schema.paths,$k$$))if($ctrl$$.options.findExact[$k$$])$condition$jscomp$1$$[$k$$]=$body$jscomp$2_query$$[$k$$];else{let $item$$={};"number"==$ctrl$$.model.schema.paths[$k$$].instance.toLowerCase()?$item$$[$k$$]=Number($body$jscomp$2_query$$[$k$$]):"date"==$ctrl$$.model.schema.paths[$k$$].instance.toLowerCase()?$item$$[$k$$]=new Date($body$jscomp$2_query$$[$k$$]):"string"==$ctrl$$.model.schema.paths[$k$$].instance.toLowerCase()?$item$$[$k$$]={$regex:$body$jscomp$2_query$$[$k$$],
65
+ $options:"i"}:$item$$[$k$$]=$body$jscomp$2_query$$[$k$$];$data_log_or$$.push($item$$)}else"$text"===$k$$&&$data_log_or$$.push({$text:{$search:$body$jscomp$2_query$$[$k$$]}})}0!==$data_log_or$$.length&&("$and"===$body$jscomp$2_query$$.cType?$condition$jscomp$1$$.$and=$data_log_or$$:$condition$jscomp$1$$.$or=$data_log_or$$);$shareRoute$$||0==$ctrl$$.require_id_app||($condition$jscomp$1$$.id_app=$req$$.user.current_id_app);$ctrl$$.finding?$ctrl$$.finding($req$$.user,$condition$jscomp$1$$,function($error$$,
66
+ $condition$jscomp$0$$){setImmediate(()=>{if($error$$)return $res$$.status(400).send({error:$error$$.message||$error$$.error||$error$$});$ctrl$$.dynamicFinding?$ctrl$$.dynamicFinding($req$$.user,$condition$jscomp$0$$,function($e$$,$condition$$){if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});$req$$.condition=$condition$$;$next$$()}):($req$$.condition=$condition$jscomp$0$$,$next$$())})},{req:$req$$}):$ctrl$$.dynamicFinding?
67
+ $ctrl$$.dynamicFinding($req$$.user,$condition$jscomp$1$$,function($e$$,$condition$$){if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});$req$$.condition=$condition$$;$next$$()}):($req$$.condition=$condition$jscomp$1$$,$next$$())})},function($req$$,$res$$,$next$$){if($shareRoute$$)return $next$$();permission.getRightByItem($req$$.user.current_id_app,$model$$,$req$$.user.email,function($e$jscomp$0$$,$_condition$$,$admin$$){setImmediate(()=>
68
+ {if($e$jscomp$0$$)return $res$$.status(403).send({error:$e$jscomp$0$$.error||$e$jscomp$0$$.message||$e$jscomp$0$$});if($admin$$)return $next$$();$req$$.admin=$admin$$;let $condition$$=$req$$.condition;$condition$$||($condition$$={});$condition$$.$and||($condition$$.$and=[]);if($ctrl$$.options.onRightByItem)$ctrl$$.options.onRightByItem($req$$.user,$_condition$$,($e$$,$_condition$$)=>{setImmediate(()=>{if($e$$)return $res$$.status(403).send({error:$e$$.error||$e$$.message||$e$$});_.isObject($_condition$$)&&
69
+ 0<Object.keys($_condition$$).length&&$condition$$.$and.push($_condition$$);$req$$.condition=$condition$$;$next$$()})});else _.isObject($_condition$$)&&0<Object.keys($_condition$$).length&&$condition$$.$and.push($_condition$$),$req$$.condition=$condition$$,$next$$()})},$ctrl$$.name,{notNeedRight:$ctrl$$.options.notNeedRight})},function($req$$,$res$$,$next$$){if($shareRoute$$)return $next$$();setImmediate(()=>{$ctrl$$.options.assignWiths?async.mapSeries($ctrl$$.options.assignWiths,($col$$,$callback$$)=>
70
+ {setImmediate(()=>{let $m$$=global.getModel($col$$.ref_collection);permission.getRightByItem($req$$.user.current_id_app,$m$$,$req$$.user.email,function($e$jscomp$0$$,$_condition$$,$admin$$){setImmediate(()=>{if($e$jscomp$0$$)return $callback$$($e$jscomp$0$$);if($admin$$)return $callback$$();$_condition$$.id_app=$req$$.user.current_id_app;$m$$.find($_condition$$).lean().exec(($e$$,$rs$$)=>{setImmediate(()=>{if($e$$)return $callback$$($e$$);let $dsdt$$=underscore.pluck($rs$$,$col$$.ref_field);$dsdt$$.push("");
71
+ $dsdt$$.push(null);$req$$.condition[$col$$.ref_field]={$in:$dsdt$$};$callback$$()})})})},$ctrl$$.name,{notNeedRight:$ctrl$$.options.notNeedRight})})},$e$$=>{setImmediate(()=>{if($e$$)return $res$$.status(400).send({error:$e$$.error||$e$$.message||$e$$});$next$$()})}):$next$$()})},function($req$$,$res$$,$next$$){if($shareRoute$$)return $next$$();setImmediate(()=>{if($req$$.admin||"dmdt"===$ctrl$$.name)return $next$$();if(underscore.has($model$$.schema.paths,"ma_dt")||underscore.has($model$$.schema.paths,
72
+ "id_dt")){let $dmdt$$=mongoose.models.dmdt;permission.getRightDataView($req$$.user.current_id_app,$dmdt$$,$req$$.user.email,function($e$jscomp$0$$,$_condition$$,$admin$$){setImmediate(()=>{if($e$jscomp$0$$)return $res$$.status(400).send({error:$e$jscomp$0$$.error||$e$jscomp$0$$.message||$e$jscomp$0$$});if($admin$$)return $next$$();$_condition$$.id_app=$req$$.user.current_id_app;$req$$.condition.ma_dt&&($_condition$$.ma_dt=$req$$.condition.ma_dt);$dmdt$$.find($_condition$$,{ma_dt:1,_id:1}).lean().exec(($e$$,
73
+ $rs$$)=>{setImmediate(()=>{if($e$$)return $res$$.status(400).send({error:$e$$.error||$e$$.message||$e$$});if(underscore.has($model$$.schema.paths,"ma_dt")){var $dsdt$jscomp$1_dsdt$$=underscore.pluck($rs$$,"ma_dt");$dsdt$jscomp$1_dsdt$$.push("");$dsdt$jscomp$1_dsdt$$.push(null);$dsdt$jscomp$1_dsdt$$.push(void 0);$req$$.condition.ma_dt={$in:$dsdt$jscomp$1_dsdt$$}}else $dsdt$jscomp$1_dsdt$$=underscore.pluck($rs$$,"_id"),$dsdt$jscomp$1_dsdt$$.push(""),$dsdt$jscomp$1_dsdt$$.push(null),$dsdt$jscomp$1_dsdt$$.push(void 0),
74
+ $req$$.condition.id_dt={$in:$dsdt$jscomp$1_dsdt$$};$next$$()})})})})}else $next$$()})},function($req$$,$res$$,$next$$){setImmediate(()=>{if($shareRoute$$||$req$$.admin||"dmkho"===$ctrl$$.name)return $next$$();if(underscore.has($model$$.schema.paths,"ma_kho")||underscore.has($model$$.schema.paths,"ma_kho_x")||underscore.has($model$$.schema.paths,"ma_kho_n")){let $dmkho$$=mongoose.models.dmkho;permission.getRightDataView($req$$.user.current_id_app,$dmkho$$,$req$$.user.email,function($e$jscomp$0$$,$_condition$$,
75
+ $admin$$){setImmediate(()=>{if($e$jscomp$0$$)return $res$$.status(403).send({error:$e$jscomp$0$$.error||$e$jscomp$0$$.message||$e$jscomp$0$$});if($admin$$)return $next$$();$_condition$$.id_app=$req$$.user.current_id_app;$req$$.condition.ma_kho&&($_condition$$.ma_kho=$req$$.condition.ma_kho);$dmkho$$.find($_condition$$,{ma_kho:1}).lean().exec(($e$$,$rs$$)=>{setImmediate(()=>{if($e$$)return $res$$.status(400).send({error:$e$$.error||$e$$.message||$e$$});let $dskho$$=underscore.pluck($rs$$,"ma_kho");
76
+ $req$$.condition.ma_kho||($dskho$$.push(""),$dskho$$.push(null),$dskho$$.push(void 0));if(underscore.has($model$$.schema.paths,"ma_kho"))return $req$$.condition.ma_kho={$in:$dskho$$},$next$$();if("pxc"===$ctrl$$.name&&underscore.has($model$$.schema.paths,"ma_kho_x"))return $req$$.condition.ma_kho_x={$in:$dskho$$},$next$$();if("pnc"===$ctrl$$.name&&underscore.has($model$$.schema.paths,"ma_kho_n"))return $req$$.condition.ma_kho_n={$in:$dskho$$},$next$$();$next$$()})})})})}else $next$$()})},function($req$$,
77
+ $res$$,$next$$){setImmediate(()=>{if($shareRoute$$)return $next$$();permission.hasRight($req$$.user.current_id_app,$req$$.user.email,$ctrl$$.module,"view",function($error$$,$permission$$){setImmediate(()=>{if($ctrl$$.options.onQuery)$req$$.permission=$permission$$,$ctrl$$.options.onQuery($req$$,$e$$=>{if($e$$)return $res$$.status(400).send({error:$e$$.error||$e$$.message||$e$$});if(!$req$$.permission)return $res$$.send([]);$next$$()});else{if(!$permission$$)return $res$$.send([]);$next$$()}})},{notNeedRight:$ctrl$$.options.notNeedRight})})},
78
+ async function($req$$,$res$$){setImmediate(async()=>{let $condition$$=$req$$.condition;$condition$$||($condition$$={});if($shareRoute$$){$condition$$.shared=!0;var $id_sellers_query$$=(await app.find({sale_online:!0},{_id:1}).lean()).map($a$$=>$a$$._id);$condition$$.$and||($condition$$.$and=[]);$condition$$.$and.push({id_app:{$in:$id_sellers_query$$}});$condition$$.id_app&&$condition$$.$and.push({id_app:$condition$$.id_app})}else underscore.has($model$$.schema.paths,"id_app")&&!1!==$ctrl$$.require_id_app&&
79
+ ($condition$$.id_app=$req$$.user.current_id_app);"public"===$req$$.user.email&&underscore.has($model$$.schema.paths,"session_created")&&($condition$$.session_created=($req$$.cookies||{}).uid);underscore.extend($condition$$,$ctrl$$.keyValues);$condition$$.$and&&0===$condition$$.$and.length&&delete $condition$$.$and;$condition$$.$or&&0===$condition$$.$or.length&&delete $condition$$.$or;$condition$$.$nor&&0===$condition$$.$nor.length&&delete $condition$$.$nor;$id_sellers_query$$=null;if($req$$.query.count)$condition$$.$where?
80
+ (console.log("phai loai bo $where trong condition"),$id_sellers_query$$=$model$$.count($condition$$,function($e$$,$data$$){if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});$res$$.send({rows_number:$data$$})})):$id_sellers_query$$=$model$$.countDocuments($condition$$,function($e$$,$data$$){if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});$res$$.send({rows_number:$data$$})});
81
+ else{let $field_not_right$$;try{$field_not_right$$=await permission.getFieldNotRight($req$$.user.current_id_app,$req$$.user.email,$ctrl$$.name)}catch($e$$){$field_not_right$$=[]}var $fields$$=$req$$.query.fields;let $gfields$$={};$fields$$&&(underscore.isArray($fields$$)?$fields$$.forEach($f$$=>{"_id"!==$f$$&&($gfields$$[$f$$]=1)}):underscore.isObject($fields$$)?$gfields$$={...$gfields$$,...$fields$$}:$fields$$.split(",").filter($f$$=>$f$$&&0>$field_not_right$$.indexOf($f$$)).forEach($f$$=>{"_id"!==
82
+ $f$$&&($gfields$$[$f$$]=1)}));$field_not_right$$.forEach($f$$=>{Object.keys($gfields$$).find($k$$=>1==$gfields$$[$k$$])?delete $gfields$$[$f$$]:$gfields$$[$f$$]=0});!$fields$$&&(($fields$$=$req$$.query.notfields)&&(underscore.isArray($fields$$)?$fields$$.forEach($f$$=>{$f$$&&"_id"!==$f$$&&(Object.keys($gfields$$).find($k$$=>1==$gfields$$[$k$$])?delete $gfields$$[$f$$]:$gfields$$[$f$$]=0)}):underscore.isObject($fields$$)?$gfields$$={...$gfields$$,...$fields$$}:$fields$$.split(",").forEach($f$$=>{$f$$&&
83
+ "_id"!==$f$$&&(Object.keys($gfields$$).find($k$$=>1==$gfields$$[$k$$])?delete $gfields$$[$f$$]:$gfields$$[$f$$]=0)})),$shareRoute$$||"public"===$req$$.user.email)&&(Object.keys($gfields$$).find($k$$=>1==$gfields$$[$k$$])?(delete $gfields$$.dataview_to,delete $gfields$$.dataview_to_users):($gfields$$.dataview_to=0,$gfields$$.dataview_to_users=0));$condition$$.$text&&($gfields$$||($gfields$$={}),$gfields$$.textScore={$meta:"textScore"});if($req$$.query.group||$req$$.query.project||$req$$.query.match||
84
+ $req$$.query.aggregate)try{$id_sellers_query$$=$model$$.aggregate([{$match:$condition$$}]);$req$$.query.group&&($group_limit_sort$$=JSONParser($req$$.query.group),$id_sellers_query$$.group($group_limit_sort$$));if($req$$.query.match){let $match$$=JSONParser($req$$.query.match);$id_sellers_query$$.match($match$$)}let $project$$;if($req$$.query.project)$project$$=JSONParser($req$$.query.project),$id_sellers_query$$.project($project$$);else if($gfields$$&&0<Object.keys($gfields$$).length)$project$$=
85
+ $gfields$$;else if($project$$={_id:1},$group_limit_sort$$)for(let $key$$ in $group_limit_sort$$)$project$$[$key$$]=1;$id_sellers_query$$.project($project$$);if($req$$.query.aggregate){let $aggregate$$=JSONParser($req$$.query.aggregate);$id_sellers_query$$.append($aggregate$$)}}catch($e$$){return $res$$.status(400).send({error:$e$$.message||$e$$.error||$e$$})}else underscore.has($model$$.schema.paths,"id_app")&&0<Object.keys($gfields$$).length&&Object.keys($gfields$$).find($k$$=>1==$gfields$$[$k$$])&&
86
+ ($gfields$$.id_app=1),$id_sellers_query$$=$model$$.find($condition$$,$gfields$$);var $group_limit_sort$$=$req$$.sort;!$group_limit_sort$$&&$gfields$$.textScore?$group_limit_sort$$={textScore:{$meta:"textScore"}}:$group_limit_sort$$&&($group_limit_sort$$._id=1);if($group_limit_sort$$){for(var $key$jscomp$0$$ in $group_limit_sort$$)if(1!=$group_limit_sort$$[$key$jscomp$0$$]&&-1!=$group_limit_sort$$[$key$jscomp$0$$])return $res$$.status(400).send({error:"sort is not valid"});$id_sellers_query$$.sort($group_limit_sort$$)}"xlsx"!==
87
+ $req$$.query.type_data&&"1"!=$req$$.query.rpt&&($key$jscomp$0$$=$req$$.query.page,($group_limit_sort$$=$req$$.query.limit)&&($group_limit_sort$$=Number($group_limit_sort$$)),$group_limit_sort$$||($group_limit_sort$$=!1!==$ctrl$$.require_id_app&&"right"!==$ctrl$$.name?20:1E5),$group_limit_sort$$&&500<$group_limit_sort$$&&!$req$$.query.print&&!1!==$ctrl$$.require_id_app&&"right"!==$ctrl$$.name&&($group_limit_sort$$=500),$key$jscomp$0$$?$id_sellers_query$$.skip((Number($key$jscomp$0$$)-1)*$group_limit_sort$$).limit($group_limit_sort$$):
88
+ $id_sellers_query$$.limit($group_limit_sort$$));$id_sellers_query$$.lean&&($id_sellers_query$$=$id_sellers_query$$.lean());$id_sellers_query$$.exec(function($e$jscomp$0$$,$obj4view$$){if($e$jscomp$0$$)return console.error($e$jscomp$0$$,$condition$$,$gfields$$),$res$$.status(400).send({error:$e$jscomp$0$$.error||$e$jscomp$0$$.message||$e$jscomp$0$$});$obj4view$$||($obj4view$$=[]);async.series({found:function($callback$$){$ctrl$$.found?$ctrl$$.found($req$$.user,$condition$$,$obj4view$$,function($error$$,
89
+ $items$$){setImmediate(()=>{$callback$$($error$$,$items$$)})}):$callback$$(null,$obj4view$$)},set_collection_name:function($callback$$){$obj4view$$.forEach($obj$$=>{$obj$$.collection_name||($obj$$.collection_name=$ctrl$$.collection_name)});$callback$$(null)}},function($error$jscomp$0$$,$rs$jscomp$0$$){setImmediate(()=>{if($error$jscomp$0$$)return $res$$.status(400).send({error:$error$jscomp$0$$.error||$error$jscomp$0$$.message||$error$jscomp$0$$});$obj4view$$=$rs$jscomp$0$$.found;async.series({e_view:function($callback$$){$ctrl$$.onView($req$$.user,
90
+ $obj4view$$,($error$$,$viewValue$$)=>{setImmediate(()=>{if($error$$)return console.error("Erron on view:",$error$$),$callback$$($error$$);$callback$$(null,$viewValue$$)})},{req:$req$$,shareRoute:$shareRoute$$})}},async function($app$jscomp$1_dir_root_template_e$$,$_groupBy_func_string_rs$$){if($error$jscomp$0$$)return $res$$.status(400).send({error:$error$jscomp$0$$.error||$error$jscomp$0$$.message||$error$jscomp$0$$});if($req$$.query.type_data&&"xlsx"==$req$$.query.type_data){$app$jscomp$1_dir_root_template_e$$=
91
+ (configs.paths||{}).templates;let $template_id$$,$excelTemplate$$;if($template_id$$=$req$$.query.id_template){if(!global.mongoose.Types.ObjectId.isValid($template_id$$))return $res$$.status(400).send({error:"M\u1eabu excel kh\u00f4ng t\u1ed3n t\u1ea1i"});$excelTemplate$$=await global.getModel("exportexceltemplate").findById($template_id$$);if(!$excelTemplate$$||!$excelTemplate$$.file)return $res$$.status(400).send({error:"M\u1eabu excel kh\u00f4ng t\u1ed3n t\u1ea1i"});var $_rs_msg_templatePath$$=
92
+ $app$jscomp$1_dir_root_template_e$$?`${path.dirname($app$jscomp$1_dir_root_template_e$$)}${$excelTemplate$$.file}`:`${path.dirname(__dirname)}${$excelTemplate$$.file}`}else $app$jscomp$1_dir_root_template_e$$&&($_rs_msg_templatePath$$=`${$app$jscomp$1_dir_root_template_e$$}/excels/lists/${$ctrl$$.name}.xlsx`),$_rs_msg_templatePath$$&&fs.existsSync($_rs_msg_templatePath$$)||($_rs_msg_templatePath$$=`${path.dirname(__dirname)}/templates/excels/lists/${$ctrl$$.name}.xlsx`);if(!fs.existsSync($_rs_msg_templatePath$$))return $_rs_msg_templatePath$$=
93
+ "File m\u1eabu excel ch\u01b0a \u0111\u01b0\u1ee3c khai b\u00e1o t\u1ea1i '"+$_rs_msg_templatePath$$+"'",$res$$.status(400).send({error:$_rs_msg_templatePath$$});$app$jscomp$1_dir_root_template_e$$={};$_groupBy_func_string_rs$$.e_view.forEach($item$$=>{for(let $_key$$ in $item$$){let $_v$$=$item$$[$_key$$];if(underscore.isObject($_v$$))for(let $__key$$ in $_v$$){let $__v$$=$_v$$[$__key$$];if(!underscore.isFunction($__v$$))if(0<=$__key$$.indexOf("ngay")||0<=$__key$$.indexOf("date"))try{$item$$[`${$_key$$}_${$__key$$}`]=
94
+ new Date($__v$$)}catch($e$$){$item$$[`${$_key$$}_${$__key$$}`]=$__v$$}else $item$$[`${$_key$$}_${$__key$$}`]=$__v$$}else if($_v$$&&0<=$_key$$.indexOf("ngay")||0<=$_key$$.indexOf("date"))try{let $d$$=moment($_v$$,"YYYY-MM-DD");$d$$.isValid()&&($item$$[`${$_key$$}`]=$d$$.toDate(),$item$$[`${$_key$$}_string`]=$d$$.format("DD/MM/YYYY"))}catch($e$$){console.error("Error convert to date",$_v$$,$e$$)}}});$app$jscomp$1_dir_root_template_e$$.detail=$_groupBy_func_string_rs$$.e_view;if($excelTemplate$$&&$excelTemplate$$.handle_data){$_groupBy_func_string_rs$$=
95
+ `return (async ()=>{
93
96
  try{
94
97
  ${$excelTemplate$$.handle_data}
95
98
  }catch(e){
@@ -1,7 +1,7 @@
1
- 'use strict';const App=require("./app"),Options=require("./options"),ngcompile=require("ng-node-compile"),utils=require("../libs/utils"),File=require("./file"),underscore=require("underscore"),crypto=require("crypto"),User=require("./user"),moment=require("moment"),participant=require("./participant"),_=require("lodash"),approveSchema=new Schema({id_app:{type:String,required:!0,maxlength:1024},id_ct:{type:String,required:!0,maxlength:1024},ma_ct:{type:String,required:!0,maxlength:32,trim:!0},trang_thai:{type:String},
2
- user_request:{type:String,required:!0,maxlength:128,trim:!0},user_request_name:{type:String,required:!0,maxlength:1024},template_content:String,request_content:String,user_approves:[{email:{type:String,maxlength:128,trim:!0},name:{type:String,maxlength:1024}}],user_approved:{type:String,maxlength:128,trim:!0},user_approved_name:{type:String,maxlength:1024},date_approved:Date,approved_reason:String,user_denied:{type:String,maxlength:128,trim:!0},user_denied_name:{type:String,maxlength:1024},date_denied:Date,
3
- denied_reason:{type:String,maxlength:4E3},update_after_approve:Schema.Types.Mixed,update_after_deny:Schema.Types.Mixed,title:{type:String,maxlength:1024},data:Schema.Types.Mixed,status:{type:Boolean,default:!1},date_created:{type:Date,default:Date.now},date_updated:{type:Date,default:Date.now},user_created:{type:String,default:""},user_updated:{type:String,default:""},visible_to:{type:Number,default:2},visible_to_users:[String]});approveSchema.index({id_ct:1,id_app:1});approveSchema.index({trang_thai:1});
4
- approveSchema.index({user_approved:1});approveSchema.index({user_denied:1});approveSchema.index({status:1});approveSchema.index({user_request:"text",user_request_name:"text"},{name:"approve_index"});const model=mongoose.models.approve||mongoose.model("approve",approveSchema);let renderRequests=$requests$$=>$requests$$&&0!==$requests$$.length?`
1
+ 'use strict';const App=require("./app"),Options=require("./options"),ngcompile=require("ng-node-compile"),utils=require("../libs/utils"),File=require("./file"),underscore=require("underscore"),crypto=require("crypto"),moment=require("moment"),participant=require("./participant"),_=require("lodash"),approveSchema=new Schema({id_app:{type:String,required:!0,maxlength:1024},id_ct:{type:String,required:!0,maxlength:1024},ma_ct:{type:String,required:!0,maxlength:32,trim:!0},trang_thai:{type:String},user_request:{type:String,
2
+ required:!0,maxlength:128,trim:!0},user_request_name:{type:String,required:!0,maxlength:1024},template_content:String,request_content:String,user_approves:[{email:{type:String,maxlength:128,trim:!0},name:{type:String,maxlength:1024}}],user_approved:{type:String,maxlength:128,trim:!0},user_approved_name:{type:String,maxlength:1024},date_approved:Date,approved_reason:String,user_denied:{type:String,maxlength:128,trim:!0},user_denied_name:{type:String,maxlength:1024},date_denied:Date,denied_reason:{type:String,
3
+ maxlength:4E3},update_after_approve:Schema.Types.Mixed,update_after_deny:Schema.Types.Mixed,title:{type:String,maxlength:1024},data:Schema.Types.Mixed,status:{type:Boolean,default:!1},date_created:{type:Date,default:Date.now},date_updated:{type:Date,default:Date.now},user_created:{type:String,default:""},user_updated:{type:String,default:""},visible_to:{type:Number,default:2},visible_to_users:[String]});approveSchema.index({id_ct:1,id_app:1});approveSchema.index({trang_thai:1});approveSchema.index({user_approved:1});
4
+ approveSchema.index({user_denied:1});approveSchema.index({status:1});approveSchema.index({user_request:"text",user_request_name:"text"},{name:"approve_index"});const model=mongoose.models.approve||mongoose.model("approve",approveSchema);let renderRequests=$requests$$=>$requests$$&&0!==$requests$$.length?`
5
5
  <p style='margin-top:50px'>
6
6
  <hr/>
7
7
  <h5>Danh s\u00e1ch \u0111\u00e3 duy\u1ec7t ho\u1eb7c t\u1eeb ch\u1ed1i</h5>
@@ -67,8 +67,8 @@ $_id$$=$key_data$$.id_request;$user_approved$$=$key_data$$.email;$user_approved_
67
67
  ($_c$$.trang_thai=$trang_thai$$);model.findOne($_c$$,($e$jscomp$3$$,$rq$$)=>{if($e$jscomp$3$$||!$rq$$)return $callback$$($e$jscomp$3$$||"Y\u00eau c\u1ea7u n\u00e0y kh\u00f4ng t\u1ed3n t\u1ea1i");if($rq$$.date_approved)return $callback$$("Y\u00eau c\u1ea7u n\u00e0y \u0111\u00e3 \u0111\u01b0\u1ee3c duy\u1ec7t b\u1edfi "+$rq$$.user_approved_name);if($rq$$.date_denied)return $callback$$("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=
68
68
  new Date;$rq$$.user_approved=$user_approved$$;$rq$$.user_approved_name=$user_approved_name$$;$rq$$.approved_reason=$options$$.reason||"";if(!$rq$$.user_approves||!$rq$$.user_approves.find($u$$=>0<=$u$$.email.indexOf($user_approved$$)))return $callback$$("User n\u00e0y kh\u00f4ng c\u00f3 quy\u1ec1n duy\u1ec7t y\u00eau c\u1ea7u n\u00e0y");$rq$$.save(($e$jscomp$2$$,$approve$$)=>{if($e$jscomp$2$$)return $callback$$($e$jscomp$2$$);model.sendNotifyApproved($rq$$,$token$$);if($rq$$.update_after_approve&&
69
69
  $rq$$.update_after_approve.data)try{let $module_name$$=$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$$)return;$_m$$.updateOne({_id:$rq$$.id_ct},$rq$$.update_after_approve.data,async $e$jscomp$1$$=>{if($e$jscomp$1$$)return console.error("Can't update data after approved, error:",
70
- $e$jscomp$1$$);if($ctrl$$)try{const $obj$$=await $_m$$.findOne({_id:$rq$$.id_ct});if($obj$$){const $u$$=await User.findOne({email:$user_approved$$});$u$$.current_id_app=$obj$$.id_app;const $app_info$$=await App.findOne({_id:$obj$$.id_app});$ctrl$$.postData($obj$$,$e$$=>{$e$$&&console.error($e$$)});$ctrl$$.handleAfterAproved&&await $ctrl$$.handleAfterAproved($obj$$);console.log("request to approve next step");$ctrl$$.onView($u$$,[$obj$$.toObject()],($e$jscomp$0$$,$rs$$)=>{$ctrl$$.requestApprove($app_info$$,
71
- $u$$,$rs$$[0],$e$$=>{$e$$&&console.error($e$$)})})}}catch($e$$){console.error($e$$)}})}catch($e$$){console.error("Can't update data after approved, error:",$e$$.message)}$callback$$(null,$approve$$)})})};
70
+ $e$jscomp$1$$);if($ctrl$$)try{const $obj$$=await $_m$$.findOne({_id:$rq$$.id_ct});if($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});$ctrl$$.postData($obj$$,$e$$=>{$e$$&&console.error($e$$)});$ctrl$$.handleAfterAproved&&await $ctrl$$.handleAfterAproved($obj$$);$ctrl$$.onView($u$$,[$obj$$.toObject()],($e$jscomp$0$$,$rs$$)=>{$ctrl$$.requestApprove($app_info$$,$u$$,$rs$$[0],$e$$=>
71
+ {$e$$&&console.error($e$$)})})}}catch($e$$){console.error($e$$)}})}catch($e$$){console.error("Can't update data after approved, error:",$e$$.message)}$callback$$(null,$approve$$)})})};
72
72
  model.deny=function($_c$jscomp$2_encrypted$$,$callback$$,$token$$,$options$$={reason:""}){let $key_data$$,$_id$$,$user_denied$$,$user_denied_name$$,$trang_thai$$;if(underscore.isObject($_c$jscomp$2_encrypted$$))$_id$$=$_c$jscomp$2_encrypted$$.id_request,$user_denied$$=$_c$jscomp$2_encrypted$$.email,$user_denied_name$$=$_c$jscomp$2_encrypted$$.name,$trang_thai$$=$_c$jscomp$2_encrypted$$.trang_thai;else try{const $decipher$$=crypto.createDecipher("aes192",configs.cryptoPassword||"PVT@1");let $decrypted$$=
73
73
  $decipher$$.update($_c$jscomp$2_encrypted$$,"hex","utf8");$decrypted$$+=$decipher$$.final("utf8");$key_data$$=JSON.parse($decrypted$$);$_id$$=$key_data$$.id_request;$user_denied$$=$key_data$$.email;$user_denied_name$$=$key_data$$.name;$trang_thai$$=$key_data$$.trang_thai}catch($e$$){return $callback$$("Y\u00eau c\u1ea7u n\u00e0y kh\u00f4ng c\u00f3 gi\u00e1 tr\u1ecb")}if(!$_id$$||!$user_denied$$)return $callback$$("request id and deny user are required");if(!global.mongoose.Types.ObjectId.isValid($_id$$))return $callback$$("request id '"+
74
74
  $_id$$+"' is not valid");$_c$jscomp$2_encrypted$$={_id:$_id$$};void 0!==$trang_thai$$&&null!==$trang_thai$$&&($_c$jscomp$2_encrypted$$.trang_thai=$trang_thai$$);model.findOne($_c$jscomp$2_encrypted$$,($e$jscomp$2$$,$rq$$)=>{if($e$jscomp$2$$||!$rq$$||!$rq$$.ma_ct)return $callback$$($e$jscomp$2$$||"Y\u00eau c\u1ea7u n\u00e0y kh\u00f4ng t\u1ed3n t\u1ea1i");if($rq$$.date_approved)return $callback$$("Y\u00eau c\u1ea7u n\u00e0y \u0111\u00e3 \u0111\u01b0\u1ee3c duy\u1ec7t b\u1edfi "+$rq$$.user_approved_name);
@@ -6,6 +6,6 @@ model.createVirtualPaymentClientURL=async($order$$,$_app_client_ip$$,$_paymentVi
6
6
  "",amount:$order$$.amount,denom:$_paymentViaWallet_item$$.wallet_configs.denom,order_id:$order$$.so_ct||$order$$._id.toString(),order_info:$order$$.dien_giai||"Thanh to\u00e1n th\u00f4ng qua v\u00ed \u0111i\u1ec7n t\u1eed"});$_paymentViaWallet_item$$.return_url=`${configs.domain?`https://${configs.domain}`:configs.api_url}/public/${$order$$.id_app}/assrequest/${$_paymentViaWallet_item$$._id.toString()}/callback`;await $_paymentViaWallet_item$$.save();return($_app_client_ip$$.domain||"")+"/#/payment/"+
7
7
  $_paymentViaWallet_item$$._id.toString()};
8
8
  model.verifyReturnUrl=async($again_link_id_app$$,$id_transaction_request$$,$query_results$$)=>{$again_link_id_app$$=`${configs.domain?`https://${configs.domain}`:configs.api_url}/public/payment/again`;$id_transaction_request$$=await model.findOne({_id:$id_transaction_request$$}).lean();if(!$id_transaction_request$$)throw"Y\u00eau c\u1ea7u thanh to\u00e1n kh\u00f4ng t\u1ed3n t\u1ea1i";$query_results$$={...$query_results$$};$query_results$$.isSuccess="1"==$id_transaction_request$$.trang_thai;if($query_results$$.isSuccess&&
9
- $id_transaction_request$$.ma_ct){let $_v$$=global.getModel(`${$id_transaction_request$$.ma_ct.toLowerCase()}`);const $obj_updated$$=await $_v$$.findOne({_id:$id_transaction_request$$.request_id});try{let $ctrl$$=global.controllers[$id_transaction_request$$.ma_ct.toUpperCase()];if($ctrl$$&&$obj_updated$$){if($ctrl$$.handleAfterPayment)try{await $ctrl$$.handleAfterPayment($obj_updated$$),controller.pushNotification($ctrl$$,$obj_updated$$,"payment",null,!1,{title:`Bill ${$obj_updated$$.so_ct} \u0111\u00e3 \u0111\u01b0\u1ee3c thanh to\u00e1n`})}catch($e$$){console.error("error handle after payment",
10
- $e$$)}else await $_v$$.findOneAndUpdate({_id:$id_transaction_request$$.request_id},{trang_thai:"5"}),$ctrl$$.post?controller.postData($obj_updated$$,$ctrl$$,async()=>{controller.pushNotification($ctrl$$,$obj_updated$$,"update")}):controller.pushNotification($ctrl$$,$obj_updated$$,"update");$query_results$$.result_url=$obj_updated$$.again_link||$again_link_id_app$$}}catch($e$$){console.error("error update status for voucher",$id_transaction_request$$.ma_ct,$e$$),$query_results$$.result_url=$obj_updated$$.again_link||
9
+ $id_transaction_request$$.ma_ct){let $_v$$=global.getModel(`${$id_transaction_request$$.ma_ct.toLowerCase()}`);const $obj_updated$$=await $_v$$.findOne({_id:$id_transaction_request$$.request_id});try{let $ctrl$$=global.controllers[$id_transaction_request$$.ma_ct.toUpperCase()];if($ctrl$$&&$obj_updated$$){if($ctrl$$.handleAfterPayment){console.log("handle after payment");try{await $ctrl$$.handleAfterPayment($obj_updated$$),controller.pushNotification($ctrl$$,$obj_updated$$,"payment",null,!1,{title:`Bill ${$obj_updated$$.so_ct} \u0111\u00e3 \u0111\u01b0\u1ee3c thanh to\u00e1n`})}catch($e$$){console.error("error handle after payment",
10
+ $e$$)}}else await $_v$$.findOneAndUpdate({_id:$id_transaction_request$$.request_id},{trang_thai:"5"}),$ctrl$$.post?controller.postData($obj_updated$$,$ctrl$$,async()=>{controller.pushNotification($ctrl$$,$obj_updated$$,"update")}):controller.pushNotification($ctrl$$,$obj_updated$$,"update");$query_results$$.result_url=$obj_updated$$.again_link||$again_link_id_app$$}}catch($e$$){console.error("error update status for voucher",$id_transaction_request$$.ma_ct,$e$$),$query_results$$.result_url=$obj_updated$$.again_link||
11
11
  $again_link_id_app$$}}else $query_results$$.result_url=$again_link_id_app$$;return $query_results$$};module.exports=model;
@@ -7,6 +7,7 @@ const {isSupperAdmin} = require("../libs/utils");
7
7
  const PostBook = require('../libs/post-book');
8
8
  const PostSocai = require('../libs/post-socai');
9
9
  const moment = require("moment");
10
+ const numeral = require("numeral");
10
11
  const fs = require("fs");
11
12
  const joinModel2 = (arr,id_app, model, joinFields, fn,options={cache:true})=>{
12
13
  return [...arr].joinModel2(id_app, model, joinFields, fn,options);
@@ -152,8 +153,6 @@ const requireFields= model.requireFields ={
152
153
  user_updated: {type: String, default: ''},
153
154
  visible_to: {type: Number, default: 0},
154
155
  visible_to_users: [String],
155
- update_right: [String],
156
- delete_right: [String],
157
156
  }
158
157
  model.createSchema = (info)=>{
159
158
  if(!info.create_model) return null;
@@ -219,7 +218,7 @@ model.createSchema = (info)=>{
219
218
  }
220
219
  mySchema.add(fields);
221
220
  //create index for all fields
222
- info.fields.filter(f=>!f.unique && require_paths.indexOf(f.name)<0).forEach(field=>{
221
+ info.fields.filter(f=>!f.unique && f.type!="Array" && f.type!="Mixed" && require_paths.indexOf(f.name)<0).forEach(field=>{
223
222
  mySchema.index({[field.name]:1});
224
223
  })
225
224
  //create unique index
@@ -335,7 +334,7 @@ model.updateModel = (info,_newModel)=>{
335
334
  delete _field.maxlength
336
335
  }
337
336
  _newModel.schema.add({[field.name]:_field});
338
- if(!field.unique) _newModel.schema.index({[field.name]:1});
337
+ if(!field.unique && field.type!="Array" && field.type!="Mixed") _newModel.schema.index({[field.name]:1});
339
338
  })
340
339
  //create unique index
341
340
  if(_newList && _newList.is_dynamic_list){
@@ -411,7 +410,7 @@ const post = (_listInfo,obj)=>{
411
410
  return {error:e}
412
411
  }
413
412
  })()`
414
- let data = await evalute(script,{master:{...obj},data:{...obj},moment});
413
+ let data = await evalute(script,{master:{...obj},data:{...obj},moment,numeral});
415
414
  if(data && data.error){
416
415
  throw data.error
417
416
  }
@@ -452,11 +451,13 @@ const dynamicFinding = (_listInfo,user,condition,next)=>{
452
451
  try{
453
452
  let script = _listInfo.require_condition;
454
453
  if(script.indexOf("return ")<0) script = `return ${script}`;
455
- const require_condition = evalute(script);
456
- //console.log(require_condition)
457
- for(let key in require_condition){
458
- condition[key] = require_condition[key];
454
+ const require_condition = evalute(script,{user,condition,moment,numeral});
455
+ if(require_condition && Object.keys(require_condition).length>0){
456
+ for(let key in require_condition){
457
+ condition[key] = require_condition[key];
458
+ }
459
459
  }
460
+
460
461
  }catch(e){
461
462
  console.error(e);
462
463
  return next(`Error on require condition: ${e.message}`);
@@ -495,7 +496,7 @@ const dynamicCreating = async (listInfo,user,obj,next)=>{
495
496
  })();`
496
497
  setImmediate(async ()=>{
497
498
  try{
498
- await evalute(func_body,{obj,user,getLib:global.getLib,getModel:global.getModel,utils,query:utils.query,async,controller,controllers:global.controllers,joinModel2,next})
499
+ await evalute(func_body,{obj,user,getLib:global.getLib,getModel:global.getModel,utils,query:utils.query,async,controller,controllers:global.controllers,joinModel2,next,moment,numeral})
499
500
  }catch(e){
500
501
  console.error("error dynamic create",_listInfo.handle_oncreating_server,e)
501
502
  next(e);
@@ -535,7 +536,7 @@ const dynamicCreated = async (_listInfo,user,obj,next)=>{
535
536
  })();`
536
537
  setImmediate(async ()=>{
537
538
  try{
538
- await evalute(func_body,{obj,user,getLib:global.getLib,getModel:global.getModel,controller,controllers:global.controllers,utils,query:utils.query,async,joinModel2,next})
539
+ await evalute(func_body,{obj,user,getLib:global.getLib,getModel:global.getModel,controller,controllers:global.controllers,utils,query:utils.query,async,joinModel2,next,moment,numeral})
539
540
  }catch(e){
540
541
  console.error("error dynamic created",_listInfo.handle_oncreated_server,e)
541
542
  next(e)
@@ -589,7 +590,7 @@ const dynamicUpdating = async (listInfo,user,data,obj,next)=>{
589
590
  })();`
590
591
  setImmediate(async ()=>{
591
592
  try{
592
- await evalute(func_body,{data,obj,user,getLib:global.getLib,getModel:global.getModel,controller,controllers:global.controllers,utils,query:utils.query,async,joinModel2,next})
593
+ await evalute(func_body,{data,obj,user,getLib:global.getLib,getModel:global.getModel,controller,controllers:global.controllers,utils,query:utils.query,async,joinModel2,next,moment,numeral})
593
594
  }catch(e){
594
595
  console.error("error dynamic update",_listInfo.handle_onupdating_server,e)
595
596
  next(e)
@@ -631,7 +632,7 @@ const dynamicUpdated = async (_listInfo,user,obj,next)=>{
631
632
  })();`
632
633
  setImmediate(async ()=>{
633
634
  try{
634
- await evalute(func_body,{obj,user,getLib:global.getLib,getModel:global.getModel,controller,controllers:global.controllers,utils,query:utils.query,async,joinModel2,next})
635
+ await evalute(func_body,{obj,user,getLib:global.getLib,getModel:global.getModel,controller,controllers:global.controllers,utils,query:utils.query,async,joinModel2,next,moment,numeral})
635
636
  }catch(e){
636
637
  console.error("error dynamic updated",_listInfo.handle_onupdated_server,e)
637
638
  next(e)
@@ -683,7 +684,7 @@ const dynamicDeleting = async (listInfo,user,obj,next)=>{
683
684
  })();`
684
685
  setImmediate(async ()=>{
685
686
  try{
686
- await evalute(func_body,{obj,user,getLib:global.getLib,getModel:global.getModel,controller,controllers:global.controllers,utils,query:utils.query,async,joinModel2,next})
687
+ await evalute(func_body,{obj,user,getLib:global.getLib,getModel:global.getModel,controller,controllers:global.controllers,utils,query:utils.query,async,joinModel2,next,moment,numeral})
687
688
  }catch(e){
688
689
  console.error("error dynamic delete",_listInfo.handle_ondeleting_server,e)
689
690
  next(e)
@@ -728,7 +729,7 @@ const onView = async (obj,user,items,next)=>{
728
729
 
729
730
  })();`
730
731
  try{
731
- evalute(func_body,{items,user,getLib:global.getLib,utils,next,async,joinModel2})
732
+ evalute(func_body,{items,user,getLib:global.getLib,utils,next,async,joinModel2,moment,numeral})
732
733
  }catch(e){
733
734
  console.error("error dynamic view",obj.handle_view_serve,e)
734
735
  }
@@ -2,7 +2,7 @@
2
2
  default:0},gia_ban_nt:{type:Number,default:0},tien_hang:{type:Number,default:0},tien_hang_nt:{type:Number,default:0},ty_le_ck:{type:Number,default:0},tien_ck:{type:Number,default:0},tien_ck_nt:{type:Number,default:0},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},tien:{type:Number,default:0},tien_nt:{type:Number,default:0},gia_ban_thuc:{type:Number,default:0},ma_bp:{type:String,
3
3
  uppercase:!0,default:"",maxlength:32},ma_phi:{type:String,uppercase:!0,default:"",maxlength:32},ma_hd:{type:String,uppercase:!0,default:"",maxlength:32},ma_dt:{type:String,uppercase:!0,default:"",maxlength:32},ma_nv:{type:String,uppercase:!0,default:"",maxlength:32},tk_vt:{type:String,uppercase:!0,maxlength:32},tk_dt:{type:String,uppercase:!0,maxlength:32},tk_gv:{type:String,uppercase:!0,maxlength:32},tk_ck:{type:String,uppercase:!0,maxlength:32},ma_lo:{type:String,default:"",uppercase:!0,maxlength:32},
4
4
  han_sd:{type:Date},ma_vt2:{type:String,default:"",uppercase:!0,maxlength:32},ma_tt1:{type:String,default:"",uppercase:!0,maxlength:32},ma_tt2:{type:String,default:"",uppercase:!0,maxlength:32},ma_tt3:{type:String,default:"",uppercase:!0,maxlength:32},thuoc_tinh:Schema.Types.Mixed,tien_evoucher_duoc_pb:{type:Number,default:0},exfields_detail:global.Schema.Types.Mixed,tasks:[Schema.Types.Mixed],days_of_week:[{index:Number,name:String,sel:Boolean,ghi_chu:String}],ngay_bat_dau:{type:Date},ngay_ket_thuc:{type:Date},
5
- tu_gio:{type:Date},den_gio:{type:Date},so_lan:Number,diem_thuong:{type:Number,default:0},tk_km_no:{type:String},tk_km_co:{type:String},km_yn_for:String,id_cs:String,collection_cs:String,is_coin:Boolean,transferred:Boolean,wallet_receiver:String,freeship:Schema.Types.Mixed,combo:Schema.Types.Mixed,line:{type:Number,default:0}});detailSchema.validate={ma_vt:validVt.existsVt,ma_dvt:validator.existsDvt};
5
+ tu_gio:{type:Date},den_gio:{type:Date},so_lan:Number,diem_thuong:{type:Number,default:0},tk_km_no:{type:String},tk_km_co:{type:String},km_yn_for:String,id_cs:String,collection_cs:String,freeship:Schema.Types.Mixed,combo:Schema.Types.Mixed,line:{type:Number,default:0}});detailSchema.validate={ma_vt:validVt.existsVt,ma_dvt:validator.existsDvt};
6
6
  const ctcpbhSchema=new global.Schema({ma_cp:{type:String,uppercase:!0,required:!0},dien_giai:{type:String,maxlength:1024},tien_cp_nt:{type:Number,default:0},tien_cp:{type:Number,default:0},line:{type:Number,default:0}}),so1Schema=new global.Schema({id_app:{type:String,required:!0,maxlength:1024},ma_dvcs:{type:String,maxlength:1024},ma_ct:{type:String,default:"SO1",required:!0,uppercase:!0,maxlength:32},ma_gd:{type:String,default:"0",maxlength:32},so_ct:{type:String,uppercase:!0,trim:!0,maxlength:32},
7
7
  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},trang_thai:{type:String,default:"1",maxlength:32},ma_kh:{type:String,uppercase:!0,maxlength:32},ten_kh:String,of_user:{type:String,maxlength:128},ma_kho:{type:String,uppercase:!0,maxlength:32},ten_kho:String,ten_nguoi_nhan:{type:String,maxlength:1024},dien_thoai:{type:String,maxlength:1024},email:{type:String,
8
8
  maxlength:1024},dia_chi:{type:String,maxlength:1024},xa_phuong:{type:String,maxlength:1024},quan_huyen:{type:String,maxlength:1024},tinh_thanh:{type:String,maxlength:1024},quoc_gia:{type:String,default:"VN",maxlength:2},post_code:{type:String,maxlength:1024},location:global.Schema.Types.Mixed,note_ship:{type:String,maxlength:1024},pt_giao_hang:{type:String,default:"1",maxlength:1024},dich_vu_giao_hang:{type:String,maxlength:1024},trang_thai_giao_hang:{type:String,maxlength:1024},ma_kiem_soat:{type:String,
@@ -72,19 +72,19 @@ $contr$$.created=async function($user$$,$obj$$,$next$$){await createTransactionP
72
72
  $item$$.sl_xuat*($item$$.gia_ban_nt||0);$item$$.tien_ck=$item$$.tien_ck_nt=$item$$.sl_xuat*($item$$.tien_ck_nt||0);$item$$.tien=$item$$.tien_nt=$item$$.tien_hang_nt-($item$$.tien_ck_nt||0);return $item$$}))});$data$$.tien_thu=void 0==$data$$.tien_thu?$obj$$.tien_thu:$data$$.tien_thu;$data$$.tien_thu2=void 0==$data$$.tien_thu2?$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&&$obj$$.ma_ban!==$data$$.ma_ban&&
73
73
  ($data$$.ma_ban0=$obj$$.ma_ban);$data$$.details.forEach(function($d$$){$obj$$.details.forEach(function($_d$$){if($_d$$.ma_vt===$d$$.ma_vt&&$_d$$.line===$d$$.line){if(void 0==$d$$.sl_order||null==$d$$.sl_order)$d$$.sl_order=$_d$$.sl_order;if(void 0==$d$$.sl_xuat||null==$d$$.sl_xuat)$d$$.sl_xuat=$_d$$.sl_xuat;$d$$.order_time=$d$$.order_time||$_d$$.order_time||new Date;$d$$.sl_order<=$d$$.sl_xuat?$d$$.finish_time&&$d$$.sl_xuat===$_d$$.sl_xuat||($d$$.finish_time=new Date):$d$$.finish_time=null;let $trang_thai$$=
74
74
  $data$$.trang_thai||$obj$$.trang_thai;$d$$.finish_time||"5"!==$trang_thai$$&&"6"!==$trang_thai$$&&"9"!==$trang_thai$$||($d$$.finish_time=new Date);$_d$$.het_hang&&($d$$.het_hang=!0)}})});valid($user$$,$data$$,function($error$$){if($error$$)return $next$$($error$$);if($obj$$.paymentByPoints&&$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&&$obj$$.ma_ban&&$data$$.ma_ban!==$obj$$.ma_ban&&
75
- App.emitEvent($obj$$.id_app,"pbl:delete",{_id:$obj$$._id,ma_ban:$obj$$.ma_ban,action:"DELETE",trang_thai:-1});$next$$(null,$data$$,$obj$$)},$obj$$)};$contr$$.updated=async function($evouchers_user$$,$obj$$,$next$$){"9"===$obj$$.trang_thai?(await transaction.deleteTrans({id_ct:$obj$$._id.toString()}),await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng")):createTransactionBonus($obj$$);await Evoucher.updateMany({id_ct_used:$obj$$._id.toString()},
76
- {id_ct_used:null});$evouchers_user$$=await Evoucher.find({id_ct_useds:$obj$$._id.toString()});await Promise.all($evouchers_user$$.map($e$$=>deleteEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>updateEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));"5"==$obj$$.trang_thai&&($obj$$.trang_thai="6",await model.findOneAndUpdate({_id:$obj$$._id},{trang_thai:"6"}));$next$$(null,$obj$$)};$contr$$.deleting=function($user$$,$obj$$,$next$$){$next$$(null,$obj$$)};
77
- $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$$.find=function($user$$,$condition$$,$next$$){$next$$(null,$condition$$)};$contr$$.view=function($user$$,$items$$,
78
- $fn$$){let $id_app$$=$user$$.current_id_app;$items$$.forEach($item$$=>{$item$$.trang_thai=$item$$.trang_thai.toString();$item$$.evouchers&&($item$$.evouchers_string=$item$$.evouchers.map($e$$=>$e$$.ma).join(","))});async.series({dv:function($callback$$){$items$$.filter($item$$=>$item$$.ma_dvcs).joinModel2($id_app$$,dvcs,[{where:{ma_dvcs:"_id"},fields:[{ten_dvcs:"ten_dvcs"}]}],function(){$callback$$()})},kh:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kh).joinModel2($id_app$$,customer,
79
- [{where:{ma_kh:"ma_kh"},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$$()})},
80
- kho:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kho).joinModel2($id_app$$,dmkho,[{where:{ma_kho:"ma_kho"},fields:[{ten_kho:"ten_kho"}],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$$=>
81
- $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"},
82
- 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_sl_order=$r$$.details.csum("sl_order"),$r$$.t_sl=$r$$.details.csum("sl_xuat"),$r$$.t_tien=$r$$.details.csum("tien_hang"),$r$$.t_tien_nt=$r$$.details.csum("tien_hang_nt"),$r$$.t_ck=$r$$.details.csum("tien_ck")+
83
- $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||0),$r$$.t_tt=$r$$.t_tien-$r$$.t_ck,$r$$.t_tt_nt=$r$$.t_tien_nt-$r$$.t_ck_nt,$r$$.con_no=$r$$.t_tt-($r$$.tien_thu||0)-($r$$.tien_thu2||0)-($r$$.tien_paymentByPoints||0),0>$r$$.con_no&&($r$$.con_no=0),$r$$.t_tien_xuat=$r$$.details.csum("tien_xuat"),$r$$.t_tien_xuat_nt=$r$$.details.csum("tien_xuat_nt"))});$callback$$()},details_vt:function($callback$$){async.mapSeries($items$$,function($r$$,
84
- $callback1$$){$r$$.details.filter($item$$=>$item$$.ma_vt).joinModel2($id_app$$,dmvt,[{where:{ma_vt:"ma_vt"},fields:[{ten_vt:"ten_vt"},{picture:"picture"},{sp_yeu_cau_che_bien:"sp_yeu_cau_che_bien",sp_yeu_cau_pha_che:"sp_yeu_cau_pha_che"},{gia_ban_le_goc:"gia_ban_le"},{barcode:"ma_vt2",ma_can:"ma_can"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_dt:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){$r$$.details.filter($item$$=>$item$$.ma_dt).joinModel2($id_app$$,
85
- dmdt,[{where:{ma_dt:"ma_dt"},fields:[{name:"ten_dt",value:"ten_dt"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_contract:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){$r$$.details.filter($item$$=>$item$$.ma_hd).joinModel2($id_app$$,contract,[{where:{ma_hd:"so_hd"},fields:[{ten_hd:"ten_hd"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_phi:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){$r$$.details.filter($item$$=>
86
- $item$$.ma_phi).joinModel2($id_app$$,dmphi,[{where:{ma_phi:"ma_phi"},fields:[{name:"ten_phi",value:"ten_phi"}]}],function(){$callback1$$()})},function(){$callback$$()})}},function(){async.mapSeries($items$$,function($r$$,$callback1$$){$r$$.details.filter($item$$=>$item$$.ma_tt1).joinModel2($id_app$$,dmtt,[{where:{ma_vt:"ma_vt",ma_tt1:"ma_tt"},setFields:($item$$,$ref$$)=>{$item$$.ten_vt=$item$$.ten_vt+" - "+$ref$$.ten_tt;$item$$.barcode=$ref$$.ma_tt2||$item$$.barcode;$item$$.ma_can=$ref$$.ma_can||
87
- $item$$.ma_can}}],function(){$callback1$$()})},function(){$fn$$(null,$items$$)})})};$contr$$.createRoute("payment/:id",async($req$$,$next$$)=>{var $id_obj$$=$req$$.params.id;if(!global.mongoose.Types.ObjectId.isValid($id_obj$$))return $next$$("Bill kh\u00f4ng t\u1ed3n t\u1ea1i");$id_obj$$=await model.findOne({_id:$id_obj$$});if(!$id_obj$$)return $next$$("Bill kh\u00f4ng t\u1ed3n t\u1ea1i");var $t_tien$$=$id_obj$$.details.map($r$$=>$r$$.tien_hang||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);let $t_ck$$=$id_obj$$.details.map($r$$=>
88
- $r$$.tien_ck||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0)+($id_obj$$.tien_ck_hd||0)+($id_obj$$.tien_evoucher||0);$t_tien$$=$t_tien$$-$t_ck$$-($id_obj$$.tien_paymentByPoints||0)-($id_obj$$.tien_thu||0)-($id_obj$$.tien_thu2||0);if("5"===$id_obj$$.trang_thai||"6"===$id_obj$$.trang_thai||!$t_tien$$)return $next$$("Bill n\u00e0y \u0111\u00e3 \u0111\u01b0\u1ee3c thanh to\u00e1n");try{var $he_so_qd$$=await currency.getRate($id_obj$$.id_app,$id_obj$$.ma_nt);if(!$he_so_qd$$)return $next$$("Ch\u01b0a khai bao h\u1ec7 s\u1ed1 quy \u0111\u1ed5i v\u1edbi lo\u1ea1i ti\u1ec1n "+
75
+ 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)));"9"===$obj$$.trang_thai?(await transaction.deleteTrans({id_ct:$obj$$._id.toString()}),
76
+ 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))));"5"==$obj$$.trang_thai&&($obj$$.trang_thai="6",await model.findOneAndUpdate({_id:$obj$$._id},{trang_thai:"6"}));$next$$(null,$obj$$)};$contr$$.deleting=function($user$$,$obj$$,$next$$){$next$$(null,$obj$$)};$contr$$.deleted=async function($user$$,
77
+ $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$$.find=function($user$$,$condition$$,$next$$){$next$$(null,$condition$$)};$contr$$.view=function($user$$,$items$$,$fn$$){let $id_app$$=$user$$.current_id_app;
78
+ $items$$.forEach($item$$=>{$item$$.trang_thai=$item$$.trang_thai.toString();$item$$.evouchers&&($item$$.evouchers_string=$item$$.evouchers.map($e$$=>$e$$.ma).join(","))});async.series({dv:function($callback$$){$items$$.filter($item$$=>$item$$.ma_dvcs).joinModel2($id_app$$,dvcs,[{where:{ma_dvcs:"_id"},fields:[{ten_dvcs:"ten_dvcs"}]}],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"},
79
+ {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$$=>
80
+ $item$$.ma_kho).joinModel2($id_app$$,dmkho,[{where:{ma_kho:"ma_kho"},fields:[{ten_kho:"ten_kho"}],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$$=>$item$$.trang_thai).joinModel2(null,
81
+ 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"},fields:{ten_pt_thanh_toan2:"ten"}}],
82
+ 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_sl_order=$r$$.details.csum("sl_order"),$r$$.t_sl=$r$$.details.csum("sl_xuat"),$r$$.t_tien=$r$$.details.csum("tien_hang"),$r$$.t_tien_nt=$r$$.details.csum("tien_hang_nt"),$r$$.t_ck=$r$$.details.csum("tien_ck")+$r$$.tien_ck_hd+
83
+ ($r$$.tien_evoucher||0),$r$$.t_ck_nt=$r$$.details.csum("tien_ck_nt")+$r$$.tien_ck_hd+($r$$.tien_evoucher||0),$r$$.t_tt=$r$$.t_tien-$r$$.t_ck,$r$$.t_tt_nt=$r$$.t_tien_nt-$r$$.t_ck_nt,$r$$.con_no=$r$$.t_tt-($r$$.tien_thu||0)-($r$$.tien_thu2||0)-($r$$.tien_paymentByPoints||0),0>$r$$.con_no&&($r$$.con_no=0),$r$$.t_tien_xuat=$r$$.details.csum("tien_xuat"),$r$$.t_tien_xuat_nt=$r$$.details.csum("tien_xuat_nt"))});$callback$$()},details_vt:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){$r$$.details.filter($item$$=>
84
+ $item$$.ma_vt).joinModel2($id_app$$,dmvt,[{where:{ma_vt:"ma_vt"},fields:[{ten_vt:"ten_vt"},{picture:"picture"},{sp_yeu_cau_che_bien:"sp_yeu_cau_che_bien",sp_yeu_cau_pha_che:"sp_yeu_cau_pha_che"},{gia_ban_le_goc:"gia_ban_le"},{barcode:"ma_vt2",ma_can:"ma_can"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_dt:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){$r$$.details.filter($item$$=>$item$$.ma_dt).joinModel2($id_app$$,dmdt,[{where:{ma_dt:"ma_dt"},fields:[{name:"ten_dt",
85
+ value:"ten_dt"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_contract:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){$r$$.details.filter($item$$=>$item$$.ma_hd).joinModel2($id_app$$,contract,[{where:{ma_hd:"so_hd"},fields:[{ten_hd:"ten_hd"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_phi:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){$r$$.details.filter($item$$=>$item$$.ma_phi).joinModel2($id_app$$,
86
+ dmphi,[{where:{ma_phi:"ma_phi"},fields:[{name:"ten_phi",value:"ten_phi"}]}],function(){$callback1$$()})},function(){$callback$$()})}},function(){async.mapSeries($items$$,function($r$$,$callback1$$){$r$$.details.filter($item$$=>$item$$.ma_tt1).joinModel2($id_app$$,dmtt,[{where:{ma_vt:"ma_vt",ma_tt1:"ma_tt"},setFields:($item$$,$ref$$)=>{$item$$.ten_vt=$item$$.ten_vt+" - "+$ref$$.ten_tt;$item$$.barcode=$ref$$.ma_tt2||$item$$.barcode;$item$$.ma_can=$ref$$.ma_can||$item$$.ma_can}}],function(){$callback1$$()})},
87
+ function(){$fn$$(null,$items$$)})})};$contr$$.createRoute("payment/:id",async($req$$,$next$$)=>{var $id_obj$$=$req$$.params.id;if(!global.mongoose.Types.ObjectId.isValid($id_obj$$))return $next$$("Bill kh\u00f4ng t\u1ed3n t\u1ea1i");$id_obj$$=await model.findOne({_id:$id_obj$$});if(!$id_obj$$)return $next$$("Bill kh\u00f4ng t\u1ed3n t\u1ea1i");var $t_tien$$=$id_obj$$.details.map($r$$=>$r$$.tien_hang||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);let $t_ck$$=$id_obj$$.details.map($r$$=>$r$$.tien_ck||0).reduce(($a$$,
88
+ $b$$)=>$a$$+$b$$,0)+($id_obj$$.tien_ck_hd||0)+($id_obj$$.tien_evoucher||0);$t_tien$$=$t_tien$$-$t_ck$$-($id_obj$$.tien_paymentByPoints||0)-($id_obj$$.tien_thu||0)-($id_obj$$.tien_thu2||0);if("5"===$id_obj$$.trang_thai||"6"===$id_obj$$.trang_thai||!$t_tien$$)return $next$$("Bill n\u00e0y \u0111\u00e3 \u0111\u01b0\u1ee3c thanh to\u00e1n");try{var $he_so_qd$$=await currency.getRate($id_obj$$.id_app,$id_obj$$.ma_nt);if(!$he_so_qd$$)return $next$$("Ch\u01b0a khai bao h\u1ec7 s\u1ed1 quy \u0111\u1ed5i v\u1edbi lo\u1ea1i ti\u1ec1n "+
89
89
  $id_obj$$.ma_nt);$he_so_qd$$=$t_tien$$/$he_so_qd$$;if(await getPointBalance($req$$.user.current_id_app,$req$$.user.email)<$he_so_qd$$)return $next$$("B\u1ea1n kh\u00f4ng c\u00f3 \u0111\u1ee7 \u0111i\u1ec3m \u0111\u1ec3 th\u1ef1c hi\u1ec7n giao d\u1ecbch n\u00e0y.");$id_obj$$.paymentByPoints=$he_so_qd$$;$id_obj$$.tien_paymentByPoints=$t_tien$$;await createTransactionPayment($id_obj$$,$req$$.user.email);$id_obj$$.con_no=0;$id_obj$$.trang_thai="6";await $id_obj$$.save();const $obj_updated$$=await model.findOne({_id:$id_obj$$._id}).lean();
90
90
  controller.postData($id_obj$$,$contr$$,async function($e$$){if($e$$)return $next$$($e$$);$e$$=await $contr$$.asyncView($req$$.user,[$obj_updated$$],{req:$req$$});controller.pushNotification($contr$$,$e$$[0],"update");controller.pushNotification($contr$$,$e$$[0],"payment",null,!1,{title:`Bill ${$obj_updated$$.so_ct} \u0111\u00e3 \u0111\u01b0\u1ee3c thanh to\u00e1n`});$next$$(null,{rs:"B\u1ea1n \u0111\u00e3 thanh to\u00e1n th\u00e0nh c\u00f4ng"})})}catch($e$$){$next$$($e$$.message)}},{method:"GET"})};
@@ -77,45 +77,43 @@ if($freeship_i$$.gia_tri_dh&&$freeship_i$$.gia_tri_dh>$details_dvgh_t_tien_nt$$)
77
77
  $obj$$,$_opt_pre_obj_t_tien_evoucher$$),await Promise.all($_checkEvoucher_tien_con_lai$$)}catch($e$$){throw console.error($e$$),Error($e$$.message||$e$$);}$obj$$.evouchers=$obj$$.evouchers||($_opt_pre_obj_t_tien_evoucher$$||{}).evouchers||[];$_opt_pre_obj_t_tien_evoucher$$=$obj$$.evouchers.map($e$$=>$e$$.so_tien_giam||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);var $_checkEvoucher_tien_con_lai$$=$details_dvgh_t_tien_nt$$-($obj$$.tt_tien_thuong||0);$_opt_pre_obj_t_tien_evoucher$$>$_checkEvoucher_tien_con_lai$$&&
78
78
  ($_opt_pre_obj_t_tien_evoucher$$=$_checkEvoucher_tien_con_lai$$);$obj$$.tien_evoucher=$_opt_pre_obj_t_tien_evoucher$$;if($obj$$.tien_evoucher&&($_opt_pre_obj_t_tien_evoucher$$=await options.findOne({id_app:$obj$$.id_app,id_func:$obj$$.ma_ct.toLowerCase()}).lean())&&$_opt_pre_obj_t_tien_evoucher$$.option&&$_opt_pre_obj_t_tien_evoucher$$.option.phan_bo_evoucher){let $tien_evoucher_da_phan_bo$$=0,$tien_evoucher$$=$obj$$.tien_evoucher,$tien_evoucher_con_lai$$=$tien_evoucher$$-$tien_evoucher_da_phan_bo$$;
79
79
  ($obj$$.details||[]).forEach($detail$$=>{if(0<$tien_evoucher_con_lai$$){var $tien_evoucher_duoc_pb_tien_hang_con_lai$$=$detail$$.tien_hang_nt-($detail$$.tien_ck_nt||0);$tien_evoucher_duoc_pb_tien_hang_con_lai$$=$tien_evoucher_con_lai$$>$tien_evoucher_duoc_pb_tien_hang_con_lai$$?$tien_evoucher_duoc_pb_tien_hang_con_lai$$:$tien_evoucher_con_lai$$;$detail$$.tien_evoucher_duoc_pb=$tien_evoucher_duoc_pb_tien_hang_con_lai$$;$tien_evoucher_da_phan_bo$$+=$tien_evoucher_duoc_pb_tien_hang_con_lai$$;$tien_evoucher_con_lai$$=
80
- $tien_evoucher$$-$tien_evoucher_da_phan_bo$$}else $tien_evoucher_con_lai$$=0})}},valid=async function($user$$,$obj$$,$next$$,$i$jscomp$6_pre_obj$$){$i$jscomp$6_pre_obj$$&&($obj$$.online=$i$jscomp$6_pre_obj$$.online,$obj$$._id=$i$jscomp$6_pre_obj$$._id,$obj$$.details=$obj$$.details||$i$jscomp$6_pre_obj$$.details||[],$obj$$.evouchers=$obj$$.evouchers||$i$jscomp$6_pre_obj$$.evouchers);if($obj$$.online)try{await validOnline($user$$,$obj$$,$i$jscomp$6_pre_obj$$)}catch($e$$){return $next$$($e$$.message)}await ($obj$$.details||
81
- []).asyncJoinModel2($user$$.current_id_app,dmvt,{where:"ma_vt",fields:"is_coin"});if($obj$$.paymentByPoints)try{var $detail$$=await currency.getRate($obj$$.id_app,$obj$$.ma_nt);$detail$$=$detail$$||1;$obj$$.tien_paymentByPoints=$obj$$.paymentByPoints*$detail$$}catch($e$$){return $next$$($e$$.message)}for($i$jscomp$6_pre_obj$$=0;$i$jscomp$6_pre_obj$$<($obj$$.details||[]).length;$i$jscomp$6_pre_obj$$++)$detail$$=($obj$$.details||[])[$i$jscomp$6_pre_obj$$],$detail$$.line=$i$jscomp$6_pre_obj$$,"VND"===
82
- $obj$$.ma_nt&&($detail$$.tien_hang=$detail$$.tien_hang_nt,$detail$$.tien_ck=$detail$$.tien_ck_nt||0,$detail$$.gia_ban=$detail$$.gia_ban_nt),$detail$$.tien_nt=Math.max(0,$detail$$.tien_hang_nt-$detail$$.tien_ck_nt),$detail$$.tien=Math.max(0,$detail$$.tien_hang-$detail$$.tien_ck),$detail$$.tien_xuat=$detail$$.tien_xuat_nt;$obj$$.ma_dvcs?$next$$(null,$obj$$):dvcs.findOne({id_app:$user$$.current_id_app},{_id:1},function($error$$,$dv$$){return $error$$?$next$$($error$$):$dv$$?($obj$$.ma_dvcs=$dv$$._id.toString(),
83
- $next$$(null,$obj$$)):$next$$("C\u00f4ng ty/c\u1eeda h\u00e0ng n\u00e0y ch\u01b0a c\u00f3 m\u1ed9t \u0111\u01a1n v\u1ecb c\u01a1 s\u1edf n\u00e0o")})};
80
+ $tien_evoucher$$-$tien_evoucher_da_phan_bo$$}else $tien_evoucher_con_lai$$=0})}},valid=async function($user$$,$obj$$,$next$$,$i$jscomp$6_pre_obj$$){$i$jscomp$6_pre_obj$$&&($obj$$.online=$i$jscomp$6_pre_obj$$.online,$obj$$._id=$i$jscomp$6_pre_obj$$._id,$obj$$.details=$obj$$.details||$i$jscomp$6_pre_obj$$.details||[],$obj$$.evouchers=$obj$$.evouchers||$i$jscomp$6_pre_obj$$.evouchers);if($obj$$.online)try{await validOnline($user$$,$obj$$,$i$jscomp$6_pre_obj$$)}catch($e$$){return $next$$($e$$.message)}if($obj$$.paymentByPoints)try{var $detail$$=
81
+ await currency.getRate($obj$$.id_app,$obj$$.ma_nt);$detail$$=$detail$$||1;$obj$$.tien_paymentByPoints=$obj$$.paymentByPoints*$detail$$}catch($e$$){return $next$$($e$$.message)}for($i$jscomp$6_pre_obj$$=0;$i$jscomp$6_pre_obj$$<($obj$$.details||[]).length;$i$jscomp$6_pre_obj$$++)$detail$$=($obj$$.details||[])[$i$jscomp$6_pre_obj$$],$detail$$.line=$i$jscomp$6_pre_obj$$,"VND"===$obj$$.ma_nt&&($detail$$.tien_hang=$detail$$.tien_hang_nt,$detail$$.tien_ck=$detail$$.tien_ck_nt||0,$detail$$.gia_ban=$detail$$.gia_ban_nt),
82
+ $detail$$.tien_nt=Math.max(0,$detail$$.tien_hang_nt-$detail$$.tien_ck_nt),$detail$$.tien=Math.max(0,$detail$$.tien_hang-$detail$$.tien_ck),$detail$$.tien_xuat=$detail$$.tien_xuat_nt;$obj$$.ma_dvcs?$next$$(null,$obj$$):dvcs.findOne({id_app:$user$$.current_id_app},{_id:1},function($error$$,$dv$$){return $error$$?$next$$($error$$):$dv$$?($obj$$.ma_dvcs=$dv$$._id.toString(),$next$$(null,$obj$$)):$next$$("C\u00f4ng ty/c\u1eeda h\u00e0ng n\u00e0y ch\u01b0a c\u00f3 m\u1ed9t \u0111\u01a1n v\u1ecb c\u01a1 s\u1edf n\u00e0o")})};
84
83
  module.exports=function($contr_router$$){$contr_router$$=new controller($contr_router$$,model,ma_ct.toLowerCase(),{isVoucher:!0,requireRecaptchaToken:!1,unique:["so_ct"],sort:{ngay_ct:-1,so_ct:-1},onEmitEvent:async($obj$$,$users_will_receive$$,$next$$)=>{$obj$$.user_nv_giao_hang&&$users_will_receive$$.push($obj$$.user_nv_giao_hang);$next$$(null,$users_will_receive$$)}});$contr_router$$.route();$contr_router$$.saving=async($user$$,$obj$$)=>{await chietkhauhd($obj$$);await khuyenmaihd($obj$$);await hoahonghdnv($obj$$);
85
- await hoahonghdgt($obj$$)};$contr_router$$.handleAfterPayment=async $obj$$=>{let $app$$=await App.findOne({_id:$obj$$.id_app});$app$$.wallet_address&&$app$$.wallet_token&&$obj$$.details&&await Promise.all($obj$$.details.filter($d$$=>$d$$.is_coin&&!$d$$.transferred&&$d$$.wallet_receiver).map($detail$$=>(async()=>{let $memo$$=$obj$$.dien_giai||"",$amount$$=$detail$$.sl_xuat,$denom$$=$detail$$.ma_vt.toLowerCase(),$rs$$=await blockchainconnect.spend($obj$$.id_app,$app$$.wallet_token,$app$$.wallet_address,
86
- $detail$$.wallet_receiver,{amount:$amount$$,denom:$denom$$,memo:$memo$$});console.log("buy point result",$rs$$,$amount$$,$denom$$,$memo$$);$detail$$.transferred=!0})()));$obj$$.trang_thai_tt="5";await model.updateOne({_id:$obj$$._id},{details:$obj$$.details,trang_thai_tt:"5"});let $ctrlSO1$$=global.controllers.SO1;$ctrlSO1$$&&controller.postData($obj$$,$ctrlSO1$$,$e$$=>{if($e$$)return console.error($e$$);controller.pushNotification($ctrlSO1$$,$obj$$)});return null};$contr_router$$.post=async function($obj$$,
87
- $fn$$){$fn$$||($fn$$=function(){});let $he_so_qd$$=await currency.getRate($obj$$.id_app,$obj$$.ma_nt)||1;const $appInfo$$=await global.getModel("app").findOne({_id:$obj$$.id_app}).lean();await $obj$$.details.asyncJoinModel2($obj$$.id_app,dmvt,{where:"ma_vt",fields:["ma_thue","gia_mua"]});await $obj$$.details.filter($d$$=>$d$$.ma_thue).asyncJoinModel2($obj$$.id_app,global.getModel("vat"),{where:"ma_thue",fields:["thue_suat","tk_thue_co","tk_thue_co_treo"]});async.series({post_sokho:function($callback$jscomp$0$$){const $details$$=
88
- [];$obj$$.details.forEach($d$$=>{$details$$.push({...$d$$})});let $data_post$$=$details$$.map($detail$$=>$detail$$.combo&&0<$detail$$.combo.length?$detail$$.combo.map($item$$=>{$item$$=$item$$.toObject?$item$$.toObject():{...$item$$};$item$$.sl_xuat*=$detail$$.sl_xuat;$item$$.tien_xuat=$item$$.tien_xuat_nt=$item$$.sl_xuat*$item$$.gia_von_nt;$item$$.tien_hang=$item$$.tien_hang_nt=$item$$.sl_xuat*$item$$.gia_ban_nt;$item$$.tien_ck=$item$$.tien_ck_nt*=$item$$.sl_xuat;$item$$.tien=$item$$.tien_nt=$item$$.tien_hang_nt-
89
- $item$$.tien_ck_nt;return $item$$}):[$detail$$]).reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]);(new PostBook($obj$$,$data_post$$,Sokho,async function($detail$$,$callback$$){$detail$$.nxt=2;$detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;$detail$$.ma_kho=$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$jscomp$0$$($e$$,$rs$$)})},post_socai:function($callback$$){options.findOne({id_app:$obj$$.id_app,id_func:ma_ct.toLowerCase()}).lean().exec(async($error$$,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$)=>
90
- {let $option$$;$option$$=$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$?$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.option||{}:{};($error$$=await dmkho.findOne({id_app:$obj$$.id_app,ma_kho:$obj$$.ma_kho}).lean())||($error$$={});let $pt$$;$obj$$.pt_thanh_toan&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan)&&($pt$$=await ptthanhtoan.findOne({id_app:$obj$$.id_app,_id:$obj$$.pt_thanh_toan}).lean());
84
+ await hoahonghdgt($obj$$)};$contr_router$$.handleAfterPayment=async $obj$$=>{$obj$$.trang_thai_tt="5";$obj$$.trang_thai="1";await model.updateOne({_id:$obj$$._id},{details:$obj$$.details,trang_thai_tt:"5",trang_thai:"1"});let $ctrlSO1$$=global.controllers.SO1;$ctrlSO1$$&&controller.postData($obj$$,$ctrlSO1$$,$e$$=>{if($e$$)return console.error($e$$);controller.pushNotification($ctrlSO1$$,$obj$$)});return null};$contr_router$$.post=async function($obj$$,$fn$$){$fn$$||($fn$$=function(){});let $he_so_qd$$=
85
+ await currency.getRate($obj$$.id_app,$obj$$.ma_nt)||1;const $appInfo$$=await global.getModel("app").findOne({_id:$obj$$.id_app}).lean();await $obj$$.details.asyncJoinModel2($obj$$.id_app,dmvt,{where:"ma_vt",fields:["ma_thue","gia_mua"]});await $obj$$.details.filter($d$$=>$d$$.ma_thue).asyncJoinModel2($obj$$.id_app,global.getModel("vat"),{where:"ma_thue",fields:["thue_suat","tk_thue_co","tk_thue_co_treo"]});async.series({post_sokho:function($callback$jscomp$0$$){const $details$$=[];$obj$$.details.forEach($d$$=>
86
+ {$details$$.push({...$d$$})});let $data_post$$=$details$$.map($detail$$=>$detail$$.combo&&0<$detail$$.combo.length?$detail$$.combo.map($item$$=>{$item$$=$item$$.toObject?$item$$.toObject():{...$item$$};$item$$.sl_xuat*=$detail$$.sl_xuat;$item$$.tien_xuat=$item$$.tien_xuat_nt=$item$$.sl_xuat*$item$$.gia_von_nt;$item$$.tien_hang=$item$$.tien_hang_nt=$item$$.sl_xuat*$item$$.gia_ban_nt;$item$$.tien_ck=$item$$.tien_ck_nt*=$item$$.sl_xuat;$item$$.tien=$item$$.tien_nt=$item$$.tien_hang_nt-$item$$.tien_ck_nt;
87
+ return $item$$}):[$detail$$]).reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]);(new PostBook($obj$$,$data_post$$,Sokho,async function($detail$$,$callback$$){$detail$$.nxt=2;$detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;$detail$$.ma_kho=$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$jscomp$0$$($e$$,$rs$$)})},post_socai:function($callback$$){options.findOne({id_app:$obj$$.id_app,id_func:ma_ct.toLowerCase()}).lean().exec(async($error$$,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$)=>
88
+ {let $option$$;$option$$=$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$?$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.option||{}:{};($error$$=await dmkho.findOne({id_app:$obj$$.id_app,ma_kho:$obj$$.ma_kho}).lean())||($error$$={});let $pt$$;$obj$$.pt_thanh_toan&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan)&&($pt$$=await ptthanhtoan.findOne({id_app:$obj$$.id_app,_id:$obj$$.pt_thanh_toan}).lean());
91
89
  $pt$$=$pt$$||{};$pt$$.tk_tien=$pt$$.tk_cn;$pt$$.tk_cn=$pt$$.tk_cn||$error$$.tk_cn;$pt$$.tk_dt=$error$$.tk_dt||$pt$$.tk_dt;$pt$$.tk_gv=$error$$.tk_gv||$pt$$.tk_gv;$pt$$.tk_ck=$error$$.tk_ck||$pt$$.tk_ck;$pt$$.tk_cp_gh=$error$$.tk_cp_gh||$pt$$.tk_cp_gh;$pt$$.tk_cp_bh=$error$$.tk_cp_bh||$pt$$.tk_cp_bh;$pt$$.tk_cp_ctv=$error$$.tk_cp_ctv||$pt$$.tk_cp_ctv;$pt$$.tk_cn_ctv=$error$$.tk_cn_ctv||$pt$$.tk_cn_ctv;$option$$.tk_tien=$pt$$.tk_tien||$error$$.tk_tien||$option$$.tk_tien||"1111";$option$$.tk_cn=$pt$$.tk_cn||
92
90
  $option$$.tk_cn||"131111";$option$$.tk_dt=$pt$$.tk_dt||$option$$.tk_dt||"51111";$option$$.tk_tl=$pt$$.tk_tl||$option$$.tk_tl||"52131";$option$$.tk_ck=$pt$$.tk_ck||$option$$.tk_ck||"52111";$option$$.tk_gv=$pt$$.tk_gv||$option$$.tk_gv||"6321";$option$$.tk_cp_gh=$pt$$.tk_cp_gh||$option$$.tk_cp_gh||"6418";$option$$.tk_cp_bh=$pt$$.tk_cp_bh||$option$$.tk_cp_bh||$option$$.tk_ck;$option$$.tk_cp_ctv=$pt$$.tk_cp_ctv||$option$$.tk_cp_ctv;$option$$.tk_cn_ctv=$pt$$.tk_cn_ctv||$option$$.tk_cn_ctv;$pt$$.ten&&0<=
93
91
  $pt$$.ten.indexOf("COD")?$option$$.ma_kh=$obj$$.nhan_vien_giao_hang||$obj$$.don_vi_vc||$pt$$.ma_kh||$obj$$.ma_kh:$option$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh;$obj$$.details.forEach($detail$$=>{$detail$$.ma_thue&&$detail$$.tk_thue_co_treo?($detail$$.tien_ct=($detail$$.tien_hang-($detail$$.tien_ck||0))/(1+$detail$$.thue_suat/100),$detail$$.tien_ct_nt=($detail$$.tien_hang_nt-($detail$$.tien_ck_nt||0))/(1+$detail$$.thue_suat/100),$detail$$.gia_ban_ct=Math.roundBy($detail$$.tien_ct/($detail$$.sl_xuat||1)),
94
92
  $detail$$.gia_ban_ct_nt=Math.roundBy($detail$$.tien_ct_nt/($detail$$.sl_xuat||1)),$detail$$.tien_ct=$detail$$.sl_xuat*$detail$$.gia_ban_ct,$detail$$.tien_ct_nt=$detail$$.sl_xuat*$detail$$.gia_ban_ct_nt,$detail$$.tien_thue=Math.roundBy($detail$$.tien_ct*$detail$$.thue_suat/100),$detail$$.tien_thue_nt=Math.roundBy($detail$$.tien_ct_nt*$detail$$.thue_suat/100)):($detail$$.tien_ck_ct_nt=$detail$$.tien_ck_nt,$detail$$.tien_ck_ct=$detail$$.tien_ck,$detail$$.tien_thue=0,$detail$$.tien_thue_nt=0,$detail$$.tien_ct=
95
- $detail$$.tien,$detail$$.tien_ct_nt=$detail$$.tien_nt)});const $details$$=[];$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$=$obj$$.details.map($a$$=>($a$$.tien_hang_nt||0)-($a$$.tien_ck_nt||0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0)-(($obj$$.tt_tien_thuong||0)+($obj$$.tien_ck_hd||0)+($obj$$.tien_evoucher||0));let $tien_paymentByPoints$$=$obj$$.tien_paymentByPoints||0;const $hoachtoandtvathue$$=($tk_tien$$,$ty_le$$)=>{$obj$$.details.forEach(function($d$jscomp$35_detail$$){$d$jscomp$35_detail$$=
96
- {...$d$jscomp$35_detail$$};$d$jscomp$35_detail$$.tk_co=$option$$.tk_dt;$d$jscomp$35_detail$$.tk_no=$tk_tien$$;$d$jscomp$35_detail$$.ma_kh_co=$obj$$.ma_kh;$d$jscomp$35_detail$$.ma_kh_no=$option$$.ma_kh;$d$jscomp$35_detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;$d$jscomp$35_detail$$.tien=$d$jscomp$35_detail$$.tien_nt=Math.roundBy($d$jscomp$35_detail$$.tien_ct_nt*$ty_le$$);$d$jscomp$35_detail$$.flag="DT_"+($d$jscomp$35_detail$$.ma_vt||"");$details$$.push($d$jscomp$35_detail$$)});$obj$$.details.filter($d$$=>
97
- $d$$.tien_thue).forEach($detail$$=>{$detail$$={...$detail$$};$detail$$.tk_no=$tk_tien$$;$detail$$.tk_co=$detail$$.tk_thue_co_treo;$detail$$.ma_kh||($detail$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh);$detail$$.tien=$detail$$.tien_nt=Math.roundBy($detail$$.tien_thue_nt*$ty_le$$);$detail$$.flag="THUE_"+($detail$$.ma_vt||"");$details$$.push($detail$$)});console.log("post socai",$tk_tien$$,$ty_le$$)};$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$&&($hoachtoandtvathue$$($option$$.tk_cn,
98
- $tien_paymentByPoints$$/$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$),$hoachtoandtvathue$$($option$$.tk_tien,($rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$-$tien_paymentByPoints$$)/$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$));$obj$$.details.filter($d$$=>$d$$.diem_thuong&&$d$$.tk_km_no&&$d$$.tk_km_co).forEach(function($d$$){let $detail$$={...$d$$};
99
- $detail$$.tk_co=$option$$.tk_km_co||$d$$.tk_km_co;$detail$$.tk_no=$option$$.tk_km_no||$d$$.tk_km_no;$detail$$.ma_kh=$obj$$.ma_kh;$detail$$.tien=$detail$$.tien_nt=$detail$$.diem_thuong*$he_so_qd$$;$details$$.push($detail$$)});$obj$$.ctcpbhs&&$obj$$.ctcpbhs.forEach(function($d$jscomp$39_detail$$){$d$jscomp$39_detail$$={...$d$jscomp$39_detail$$};$d$jscomp$39_detail$$.tk_co=$option$$.tk_dt;$d$jscomp$39_detail$$.tk_no=$option$$.tk_cn;$d$jscomp$39_detail$$.ma_kh_co=$obj$$.ma_kh;$d$jscomp$39_detail$$.ma_kh_no=
100
- $option$$.ma_kh;$d$jscomp$39_detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;$d$jscomp$39_detail$$.tien_nt=$d$jscomp$39_detail$$.tien_cp_nt;$d$jscomp$39_detail$$.tien=$d$jscomp$39_detail$$.tien_cp;$details$$.push($d$jscomp$39_detail$$)});$obj$$.tien_phi_vc&&($rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$={},$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_co=$option$$.tk_dt,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_no=
101
- $option$$.tk_cn,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt=$obj$$.tien_phi_vc||0,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien=$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh_co=$obj$$.ma_kh,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh_no=
102
- $obj$$.nhan_vien_giao_hang||$obj$$.don_vi_vc,$details$$.push($rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$));$obj$$.tien_freeship&&($rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$={},$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_no=$option$$.tk_cp_gh,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_co=
103
- $option$$.tk_cn,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt=$obj$$.tien_freeship||0,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien=$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh_no=$obj$$.ma_kh,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh_co=
104
- $option$$.ma_kh,$details$$.push($rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$));$obj$$.tt_tien_thuong&&($rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$={},$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_no=$option$$.tk_cp_bh,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_co=$option$$.tk_cn,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt=
105
- $obj$$.tt_tien_thuong||0,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien=$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh_no=$obj$$.ma_kh,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh_co=$option$$.ma_kh,$details$$.push($rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$));
106
- $obj$$.thu_nhap_ctv&&$option$$.tk_cp_ctv&&$option$$.tk_cn_ctv&&($rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$={},$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_no=$option$$.tk_cp_ctv,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_co=$option$$.tk_cn_ctv,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt=
107
- $obj$$.thu_nhap_ctv||0,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien=$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh=$obj$$.ma_ctv,$details$$.push($rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$));$obj$$.tien_evoucher&&($rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$=
108
- {},$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_no=$obj$$.tk_no_evoucher||$option$$.tk_no_evoucher||$option$$.tk_ck,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_co=$obj$$.tk_co_evoucher||$option$$.tk_co_evoucher||$option$$.tk_cn,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt=$obj$$.tien_evoucher||0,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien=
109
- $rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh_no=$obj$$.ma_kh,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh_co=$option$$.ma_kh,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.check_balance=!1,$details$$.push($rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$));
110
- $obj$$.tien_ck_hd&&($rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$={},$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_no=$option$$.tk_ck,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_co=$option$$.tk_cn,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt=$obj$$.tien_ck_hd||0,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien=
111
- $rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh_no=$obj$$.ma_kh,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh_co=$option$$.ma_kh,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.check_balance=!1,$details$$.push($rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$));
112
- $obj$$.tien_hoa_hong&&$obj$$.ma_kh_hoa_hong&&($rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$={},$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_no=$obj$$.tk_no_hoa_hong||$error$$.tk_no_hoa_hong||options.tk_no_hoa_hong,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_co=$obj$$.tk_co_hoa_hong||$error$$.tk_co_hoa_hong||options.tk_co_hoa_hong,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt=
113
- $obj$$.tien_hoa_hong,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien=$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt*($obj$$.ty_gia||1),$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh=$obj$$.ma_kh_hoa_hong,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_nv=$obj$$.ma_nv,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.check_balance=
114
- !1,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_no&&$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_co&&$details$$.push($rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$));$obj$$.tien_hoa_hong_gt&&$obj$$.ma_kh_hoa_hong_gt&&($rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$={},$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_no=
115
- $obj$$.tk_no_hoa_hong_gt||$error$$.tk_no_hoa_hong_gt||options.tk_no_hoa_hong_gt,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_co=$obj$$.tk_co_hoa_hong_gt||$error$$.tk_co_hoa_hong_gt||options.tk_co_hoa_hong_gt,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt=$obj$$.tien_hoa_hong_gt,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien=$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt*
116
- ($obj$$.ty_gia||1),$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh=$obj$$.ma_kh_hoa_hong_gt,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_nv=$obj$$.ma_nv,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.check_balance=!1,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_no&&$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_co&&
117
- $details$$.push($rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$));let $details_tienvon$$=[...$obj$$.details];$details_tienvon$$.joinModel2($obj$$.id_app,dmvt,{where:"ma_vt",fields:["tk_vt","gia_mua","tk_gv","tg_tk"]},()=>{$details_tienvon$$.forEach(function($d$jscomp$40_detail$$){$d$jscomp$40_detail$$={...$d$jscomp$40_detail$$};$d$jscomp$40_detail$$.tk_no=$option$$.tk_gv;$d$jscomp$40_detail$$.ma_kh=$obj$$.ma_kh;$d$jscomp$40_detail$$.ngay_ct=$obj$$.ngay_giao_hang||
118
- $obj$$.ngay_ct;$d$jscomp$40_detail$$.tk_co=$d$jscomp$40_detail$$.tk_vt||"1561";$d$jscomp$40_detail$$.tien_nt=$d$jscomp$40_detail$$.tien_xuat_nt;$d$jscomp$40_detail$$.tien=$d$jscomp$40_detail$$.tien_xuat;$d$jscomp$40_detail$$.tg_tk||($d$jscomp$40_detail$$.tien=$d$jscomp$40_detail$$.tien_nt=0);$details$$.push($d$jscomp$40_detail$$)});(new PostSocai($obj$$,$details$$,null,Socaitmp)).run(function($e$$,$rs$$){console.log("post result",$rs$$);$callback$$($e$$,$rs$$)})})})},thanhtoanhoahongnv:$callback$$=>
93
+ $detail$$.tien,$detail$$.tien_ct_nt=$detail$$.tien_nt)});const $details$$=[];$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$=$obj$$.details.map($a$$=>($a$$.tien_hang_nt||0)-($a$$.tien_ck_nt||0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0)-(($obj$$.tt_tien_thuong||0)+($obj$$.tien_ck_hd||0)+($obj$$.tien_evoucher||0));let $tien_paymentByPoints$$=$obj$$.tien_paymentByPoints||0;const $hoachtoandtvathue$$=($tk_tien$$,$ty_le$$)=>{$obj$$.details.forEach(function($d$jscomp$34_detail$$){$d$jscomp$34_detail$$=
94
+ {...$d$jscomp$34_detail$$};$d$jscomp$34_detail$$.tk_co=$option$$.tk_dt;$d$jscomp$34_detail$$.tk_no=$tk_tien$$;$d$jscomp$34_detail$$.ma_kh_co=$obj$$.ma_kh;$d$jscomp$34_detail$$.ma_kh_no=$option$$.ma_kh;$d$jscomp$34_detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;$d$jscomp$34_detail$$.tien=$d$jscomp$34_detail$$.tien_nt=Math.roundBy($d$jscomp$34_detail$$.tien_ct_nt*$ty_le$$);$d$jscomp$34_detail$$.flag="DT_"+($d$jscomp$34_detail$$.ma_vt||"");$details$$.push($d$jscomp$34_detail$$)});$obj$$.details.filter($d$$=>
95
+ $d$$.tien_thue).forEach($detail$$=>{$detail$$={...$detail$$};$detail$$.tk_no=$tk_tien$$;$detail$$.tk_co=$detail$$.tk_thue_co_treo;$detail$$.ma_kh||($detail$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh);$detail$$.tien=$detail$$.tien_nt=Math.roundBy($detail$$.tien_thue_nt*$ty_le$$);$detail$$.flag="THUE_"+($detail$$.ma_vt||"");$details$$.push($detail$$)});console.log("post socai",$tk_tien$$,$ty_le$$)};$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$&&($hoachtoandtvathue$$($option$$.tk_cn,
96
+ $tien_paymentByPoints$$/$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$),$hoachtoandtvathue$$($option$$.tk_tien,($rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$-$tien_paymentByPoints$$)/$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$));$obj$$.details.filter($d$$=>$d$$.diem_thuong&&$d$$.tk_km_no&&$d$$.tk_km_co).forEach(function($d$$){let $detail$$={...$d$$};
97
+ $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$38_detail$$){$d$jscomp$38_detail$$={...$d$jscomp$38_detail$$};$d$jscomp$38_detail$$.tk_co=$option$$.tk_dt;$d$jscomp$38_detail$$.tk_no=$option$$.tk_cn;$d$jscomp$38_detail$$.ma_kh_co=$obj$$.ma_kh;$d$jscomp$38_detail$$.ma_kh_no=
98
+ $option$$.ma_kh;$d$jscomp$38_detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;$d$jscomp$38_detail$$.tien_nt=$d$jscomp$38_detail$$.tien_cp_nt;$d$jscomp$38_detail$$.tien=$d$jscomp$38_detail$$.tien_cp;$details$$.push($d$jscomp$38_detail$$)});$obj$$.tien_phi_vc&&($rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$={},$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_co=$option$$.tk_dt,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_no=
99
+ $option$$.tk_cn,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt=$obj$$.tien_phi_vc||0,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien=$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh_co=$obj$$.ma_kh,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh_no=
100
+ $obj$$.nhan_vien_giao_hang||$obj$$.don_vi_vc,$details$$.push($rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$));$obj$$.tien_freeship&&($rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$={},$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_no=$option$$.tk_cp_gh,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_co=
101
+ $option$$.tk_cn,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt=$obj$$.tien_freeship||0,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien=$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh_no=$obj$$.ma_kh,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh_co=
102
+ $option$$.ma_kh,$details$$.push($rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$));$obj$$.tt_tien_thuong&&($rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$={},$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_no=$option$$.tk_cp_bh,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_co=$option$$.tk_cn,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt=
103
+ $obj$$.tt_tien_thuong||0,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien=$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh_no=$obj$$.ma_kh,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh_co=$option$$.ma_kh,$details$$.push($rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$));
104
+ $obj$$.thu_nhap_ctv&&$option$$.tk_cp_ctv&&$option$$.tk_cn_ctv&&($rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$={},$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_no=$option$$.tk_cp_ctv,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_co=$option$$.tk_cn_ctv,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt=
105
+ $obj$$.thu_nhap_ctv||0,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien=$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh=$obj$$.ma_ctv,$details$$.push($rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$));$obj$$.tien_evoucher&&($rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$=
106
+ {},$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_no=$obj$$.tk_no_evoucher||$option$$.tk_no_evoucher||$option$$.tk_ck,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_co=$obj$$.tk_co_evoucher||$option$$.tk_co_evoucher||$option$$.tk_cn,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt=$obj$$.tien_evoucher||0,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien=
107
+ $rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh_no=$obj$$.ma_kh,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh_co=$option$$.ma_kh,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.check_balance=!1,$details$$.push($rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$));
108
+ $obj$$.tien_ck_hd&&($rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$={},$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_no=$option$$.tk_ck,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_co=$option$$.tk_cn,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt=$obj$$.tien_ck_hd||0,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien=
109
+ $rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh_no=$obj$$.ma_kh,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh_co=$option$$.ma_kh,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.check_balance=!1,$details$$.push($rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$));
110
+ $obj$$.tien_hoa_hong&&$obj$$.ma_kh_hoa_hong&&($rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$={},$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_no=$obj$$.tk_no_hoa_hong||$error$$.tk_no_hoa_hong||options.tk_no_hoa_hong,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_co=$obj$$.tk_co_hoa_hong||$error$$.tk_co_hoa_hong||options.tk_co_hoa_hong,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt=
111
+ $obj$$.tien_hoa_hong,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien=$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt*($obj$$.ty_gia||1),$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh=$obj$$.ma_kh_hoa_hong,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_nv=$obj$$.ma_nv,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.check_balance=
112
+ !1,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_no&&$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_co&&$details$$.push($rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$));$obj$$.tien_hoa_hong_gt&&$obj$$.ma_kh_hoa_hong_gt&&($rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$={},$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_no=
113
+ $obj$$.tk_no_hoa_hong_gt||$error$$.tk_no_hoa_hong_gt||options.tk_no_hoa_hong_gt,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_co=$obj$$.tk_co_hoa_hong_gt||$error$$.tk_co_hoa_hong_gt||options.tk_co_hoa_hong_gt,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt=$obj$$.tien_hoa_hong_gt,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien=$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt*
114
+ ($obj$$.ty_gia||1),$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh=$obj$$.ma_kh_hoa_hong_gt,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_nv=$obj$$.ma_nv,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.check_balance=!1,$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_no&&$rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_co&&
115
+ $details$$.push($rs$jscomp$4_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$));let $details_tienvon$$=[...$obj$$.details];$details_tienvon$$.joinModel2($obj$$.id_app,dmvt,{where:"ma_vt",fields:["tk_vt","gia_mua","tk_gv","tg_tk"]},()=>{$details_tienvon$$.forEach(function($d$jscomp$39_detail$$){$d$jscomp$39_detail$$={...$d$jscomp$39_detail$$};$d$jscomp$39_detail$$.tk_no=$option$$.tk_gv;$d$jscomp$39_detail$$.ma_kh=$obj$$.ma_kh;$d$jscomp$39_detail$$.ngay_ct=$obj$$.ngay_giao_hang||
116
+ $obj$$.ngay_ct;$d$jscomp$39_detail$$.tk_co=$d$jscomp$39_detail$$.tk_vt||"1561";$d$jscomp$39_detail$$.tien_nt=$d$jscomp$39_detail$$.tien_xuat_nt;$d$jscomp$39_detail$$.tien=$d$jscomp$39_detail$$.tien_xuat;$d$jscomp$39_detail$$.tg_tk||($d$jscomp$39_detail$$.tien=$d$jscomp$39_detail$$.tien_nt=0);$details$$.push($d$jscomp$39_detail$$)});(new PostSocai($obj$$,$details$$,null,Socaitmp)).run(function($e$$,$rs$$){console.log("post result",$rs$$);$callback$$($e$$,$rs$$)})})})},thanhtoanhoahongnv:$callback$$=>
119
117
  {if($obj$$.da_chuyen_hoa_hong||!$obj$$.tien_hoa_hong||!$obj$$.user_nv||!$obj$$.chuyen_ngay)return $callback$$();setImmediate(async()=>{try{if($appInfo$$.wallet_address&&$appInfo$$.wallet_token&&$appInfo$$.tang_gioi_thieu_denom){let $wallet_nhan_vien$$=await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),username:$obj$$.user_nv,wallet_type:1});if(!$wallet_nhan_vien$$){$wallet_nhan_vien$$=(new global.getModel("asskey"))({user_created:$obj$$.user_nv,username:$obj$$.user_nv,id_app:$obj$$.id_app,
120
118
  wallet_type:1});const $wallet$$=await DirectSecp256k1HdWallet.generate(24,{prefix:configs.ADDRESS_PREFIX});let $accounts$$=await $wallet$$.getAccounts();$wallet_nhan_vien$$.address=$accounts$$[0].address;$wallet_nhan_vien$$.mnemonic=$wallet$$.mnemonic;$wallet_nhan_vien$$.name="T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng";await $wallet_nhan_vien$$.save()}let $amount$$=$obj$$.tien_hoa_hong,$denom$$=$appInfo$$.tang_gioi_thieu_denom,$memo$$=`Hoa h\u1ed3ng cho \u0111\u01a1n h\u00e0ng s\u1ed1 ${$obj$$.so_ct}: ${numeral($amount$$).format()} ${$denom$$.toUpperCase()}`;
121
119
  await spend($appInfo$$,$obj$$.be_introduced,$wallet_nhan_vien$$.address,$amount$$,$denom$$,$memo$$,"","2");$obj$$.da_chuyen_hoa_hong=!0;await model.updateOne({_id:$obj$$._id},{da_chuyen_hoa_hong:!0})}}catch($e$$){console.error("Kh\u00f4ng th\u1ec3 thanh to\u00e1n ti\u1ec1n hoa h\u1ed3ng",$e$$)}$callback$$()})},thanhtoanhoahonggt:$callback$$=>{if($obj$$.da_chuyen_hoa_hong_gt||!$obj$$.tien_hoa_hong_gt||!$obj$$.user_gt||!$obj$$.chuyen_ngay_gt)return $callback$$();setImmediate(async()=>{try{if($appInfo$$.wallet_address&&
@@ -125,24 +123,28 @@ $accounts$$[0].address;$wallet_gt$$.mnemonic=$wallet$$.mnemonic;$wallet_gt$$.nam
125
123
  $obj$$.da_chuyen_hoa_hong=!1;$obj$$.da_chuyen_hoa_hong_gt=!1;await $obj$$.details.asyncJoinModel2($user$$.current_id_app,dmvt,{where:"ma_vt",fields:["combo"]});$obj$$.details.forEach($detail$$=>{$detail$$.combo&&0<$detail$$.combo.length&&($detail$$.combo=$detail$$.combo.map($item$$=>{$item$$=$item$$.toObject?$item$$.toObject():{...$item$$};$item$$.sl_xuat*=$detail$$.sl_xuat;$item$$.tien_xuat=$item$$.tien_xuat_nt=$item$$.sl_xuat*($item$$.gia_von_nt||0);$item$$.tien_hang=$item$$.tien_hang_nt=$item$$.sl_xuat*
126
124
  ($item$$.gia_ban_nt||0);$item$$.tien_ck=$item$$.tien_ck_nt=$item$$.sl_xuat*($item$$.tien_ck_nt||0);$item$$.tien=$item$$.tien_nt=$item$$.tien_hang_nt-($item$$.tien_ck_nt||0);return $item$$}))});valid($user$$,$obj$$,async $error$$=>{if($error$$)return $next$$($error$$);if(!$obj$$.paymentByPoints)return $next$$(null,$obj$$);try{if(await getPointBalance($user$$.current_id_app,$obj$$.of_user||$user$$.email)<$obj$$.paymentByPoints)return $next$$("B\u1ea1n kh\u00f4ng c\u00f3 \u0111\u1ee7 \u0111i\u1ec3m \u0111\u1ec3 th\u1ef1c hi\u1ec7n giao d\u1ecbch n\u00e0y.");
127
125
  $next$$(null,$obj$$)}catch($e$$){$next$$($e$$.message)}})};$contr_router$$.created=async function($user$$,$obj$$,$next$$){if($obj$$.pt_thanh_toan&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan))try{const $pt_thanh_toan$$=await global.getModel("ptthanhtoan").findOne({_id:$obj$$.pt_thanh_toan});if($pt_thanh_toan$$.payment_service){let $paymentServiceModel$$=global.getModel($pt_thanh_toan$$.payment_service);$obj$$.amount=$obj$$.t_tt_nt-($obj$$.tien_paymentByPoints||0);if($obj$$.amount&&
128
- $paymentServiceModel$$.createVirtualPaymentClientURL){let $virtual_payment_client_url$$=await $paymentServiceModel$$.createVirtualPaymentClientURL($obj$$,$user$$.clientIp,$pt_thanh_toan$$);$obj$$.virtual_payment_client_url=$virtual_payment_client_url$$;$obj$$.payment_service=$pt_thanh_toan$$.payment_service;$obj$$.payment_id=((await $paymentServiceModel$$.findOne({$or:[{id_ct:$obj$$._id.toString(),order_id:$obj$$._id.toString()}]})||{})._id||"").toString()}else $obj$$.virtual_payment_client_url="",
129
- $obj$$.payment_service="",$obj$$.payment_id=""}else $obj$$.virtual_payment_client_url=""}catch($e$$){return console.error($e$$),$next$$("Kh\u00f4ng tao li\u00ean k\u1ebft thanh to\u00e1n:"+($e$$.message||$e$$.error||$e$$))}else console.log("Chua nhap phuong thuc thanh toan"),$obj$$.virtual_payment_client_url="";model.findOneAndUpdate({_id:$obj$$._id},{virtual_payment_client_url:$obj$$.virtual_payment_client_url},$e$$=>{$e$$&&(console.error($e$$),console.log("error create Virtual Payment ClientURL",
130
- $e$$.message))});await createTransactionPayment($obj$$);await createTransactionBonus($obj$$);$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>updateEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$next$$(null,$obj$$)};$contr_router$$.updating=async($user$$,$data$$,$obj$$,$next$$)=>{$data$$.details||($data$$.details=$obj$$.details);$data$$.da_chuyen_hoa_hong=$obj$$.da_chuyen_hoa_hong;$data$$.da_chuyen_hoa_hong_gt=$obj$$.da_chuyen_hoa_hong_gt;await $data$$.details.asyncJoinModel2($user$$.current_id_app,
131
- dmvt,{where:"ma_vt",fields:["combo"]});$obj$$.details.forEach($detail$$=>{$detail$$.combo&&0<$detail$$.combo.length&&($detail$$.combo=$detail$$.combo.map($item$$=>{$item$$=$item$$.toObject?$item$$.toObject():{...$item$$};$item$$.sl_xuat*=$detail$$.sl_xuat;$item$$.tien_xuat=$item$$.tien_xuat_nt=$item$$.sl_xuat*($item$$.gia_von_nt||0);$item$$.tien_hang=$item$$.tien_hang_nt=$item$$.sl_xuat*($item$$.gia_ban_nt||0);$item$$.tien_ck=$item$$.tien_ck_nt=$item$$.sl_xuat*($item$$.tien_ck_nt||0);$item$$.tien=
132
- $item$$.tien_nt=$item$$.tien_hang_nt-($item$$.tien_ck_nt||0);return $item$$}))});$data$$.pt_thanh_toan&&$data$$.pt_thanh_toan!=$obj$$.pt_thanh_toan&&($data$$.virtual_payment_client_url="",$data$$.payment_service="",$data$$.payment_id="");$data$$.evouchers=$data$$.evouchers||$obj$$.evouchers||[];valid($user$$,$data$$,async $error$$=>{if($error$$)return $next$$($error$$);if(($obj$$.paymentByPoints||0)!==($data$$.paymentByPoints||0))return $next$$("B\u1ea1n kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt s\u1ed1 \u0111i\u1ec3m thanh to\u00e1n.");
133
- await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":buy"});$next$$(null,$data$$,$obj$$)},$obj$$)};$contr_router$$.updated=async function($evouchers_user$$,$obj$$,$next$$){if(!$obj$$.virtual_payment_client_url&&("1"===$obj$$.trang_thai||"0"===$obj$$.trang_thai)){if($obj$$.pt_thanh_toan&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan))try{const $pt_thanh_toan$$=await global.getModel("ptthanhtoan").findOne({_id:$obj$$.pt_thanh_toan});if($pt_thanh_toan$$.payment_service){let $paymentServiceModel$$=
134
- global.getModel($pt_thanh_toan$$.payment_service);$obj$$.amount=$obj$$.t_tt_nt-($obj$$.tien_paymentByPoints||0);if($obj$$.amount&&$paymentServiceModel$$.createVirtualPaymentClientURL){let $virtual_payment_client_url$$=await $paymentServiceModel$$.createVirtualPaymentClientURL($obj$$,$evouchers_user$$.clientIp,$pt_thanh_toan$$);$obj$$.virtual_payment_client_url=$virtual_payment_client_url$$;$obj$$.payment_service=$pt_thanh_toan$$.payment_service;$obj$$.payment_id=((await $paymentServiceModel$$.findOne({$or:[{id_ct:$obj$$._id.toString()},
135
- {order_id:$obj$$._id.toString()}]})||{})._id||"").toString()}else $obj$$.virtual_payment_client_url="",$obj$$.payment_service="",$obj$$.payment_id=""}else $obj$$.virtual_payment_client_url=""}catch($e$$){return console.error($e$$),$next$$("Error create Virtual Payment ClientURL:"+($e$$.message||$e$$.error||$e$$))}else $obj$$.virtual_payment_client_url="";model.findOneAndUpdate({_id:$obj$$._id},{virtual_payment_client_url:$obj$$.virtual_payment_client_url},$e$$=>{$e$$&&console.log("error create Virtual Payment ClientURL",
136
- $e$$.message)})}"9"===$obj$$.trang_thai?(await transaction.deleteTrans({id_ct:$obj$$._id.toString()}),await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng"),await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":buy"})):(await createTransactionPayment($obj$$),createTransactionBonus($obj$$));await Evoucher.updateMany({id_ct_used:$obj$$._id.toString()},{id_ct_used:null});$evouchers_user$$=await Evoucher.find({id_ct_useds:$obj$$._id.toString()});
137
- await Promise.all($evouchers_user$$.map($e$$=>deleteEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>updateEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$next$$(null,$obj$$)};$contr_router$$.deleting=function($user$$,$obj$$,$next$$){$next$$(null,$obj$$)};$contr_router$$.deleted=async function($user$$,$obj$$,$next$$){await transaction.deleteTrans({id_ct:$obj$$._id.toString()});await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},
138
- "Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng");await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":buy"});$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>deleteEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$next$$(null,$obj$$)};$contr_router$$.view=function($user$$,$items$$,$fn$$){async.series({app:function($callback$$){$items$$.filter($item$$=>$item$$.id_app).joinModel2(null,App,[{where:{id_app:"_id"},fields:{name_app:"name"}}],function(){$callback$$()})},kh:function($callback$$){$items$$.filter($item$$=>
139
- $item$$.ma_kh).joinModel2(null,customer,[{where:$item$$=>({id_app:$item$$.id_app,ma_kh:$item$$.ma_kh}),fields:"ten_kh"}],function(){$callback$$()})},nhan_vien_giao_hang:function($callback$$){$items$$.filter($item$$=>$item$$.nhan_vien_giao_hang).joinModel2(null,customer,[{where:{nhan_vien_giao_hang:"ma_kh"},fields:[{ten_nhan_vien_giao_hang:"ten_kh"}]}],function(){$callback$$()})},nv_giao_hang:function($callback$$){$items$$.filter($item$$=>$item$$.user_nv_giao_hang).joinModel2(null,User,{where:{user_nv_giao_hang:"email"},
140
- fields:{ten_nv_giao_hang:"name"}},function(){$callback$$()})},kho:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kho).joinModel2(null,dmkho,[{where:$item$$=>({id_app:$item$$.id_app,ma_kho:$item$$.ma_kho}),fields:["ten_kho",{tk_cn_kho:"tk_cn"}]}],function(){$callback$$()})},trangthai:function($callback$$){$items$$.filter($item$$=>$item$$.trang_thai).joinModel2(null,trangthai,[{where:{trang_thai:"ma_trang_thai",ma_ct:"ma_ct"},fields:["ten_trang_thai","color"]}],function(){$callback$$()})},
141
- ptthanhtoan:function($callback$$){$items$$.filter($item$$=>$item$$.pt_thanh_toan).joinModel2(null,ptthanhtoan,[{where:$item$$=>({_id:$item$$.pt_thanh_toan,id_app:$item$$.id_app}),fields:[{ten_pt_thanh_toan:"ten"},{tk_cn_thanhtoan:"tk_cn"}]}],function(){$callback$$()})},pt1:function($callback$$){$items$$.joinModel2(null,pt1,[{where:$item$$=>({id_app:$item$$.id_app,id_so1:"_id"}),fields:[{id_pt1:"_id"},{so_ct_pt1:"so_ct"},{ma_ct_pt1:"ma_ct"},{ngay_ct_pt1:"ngay_ct"}]}],function(){$callback$$()})},t_tien:function($callback$$){$items$$.filter($item$$=>
142
- $item$$.details).forEach(function($r$$){$r$$.tien_phi_vc=$r$$.tien_phi_vc||0;$r$$.tien_freeship=$r$$.tien_freeship||0;$r$$.details?($r$$.t_sl=$r$$.details.csum("sl_xuat"),$r$$.t_tien_hang=$r$$.details.csum("tien_hang"),$r$$.t_tien_hang_nt=$r$$.details.csum("tien_hang_nt"),$r$$.t_tien=$r$$.t_tien_hang-$r$$.details.csum("tien_ck"),$r$$.t_tien_nt=$r$$.t_tien_hang_nt-$r$$.details.csum("tien_ck_nt"),$r$$.t_ck_nt=$r$$.t_ck=$r$$.tien_ck_hd+($r$$.tien_evoucher||0)):($r$$.t_sl=0,$r$$.t_tien_hang=0,$r$$.t_tien_hang_nt=
143
- 0,$r$$.t_ck=0,$r$$.t_ck_nt=0,$r$$.t_tien=$r$$.t_tien_hang,$r$$.t_tien_nt=$r$$.t_tien_hang_nt);$r$$.ctcpbhs?($r$$.t_cp_cpb_nt=$r$$.ctcpbhs.csum("tien_cp_nt"),$r$$.t_cp_cpb=$r$$.ctcpbhs.csum("tien_cp")):($r$$.t_cp_cpb_nt=0,$r$$.t_cp_cpb=0);$r$$.t_tt=$r$$.t_tt_nt=Math.max(0,$r$$.t_tien_nt+$r$$.t_cp_cpb_nt-$r$$.t_ck_nt-($r$$.tt_tien_thuong||0)+($r$$.tien_phi_vc||0)-($r$$.tien_freeship||0))});$callback$$()},details_vt:function($callback$$){async.each($items$$,function($r$$,$callback1$$){const $details$$=
144
- $r$$.details;if(!$details$$)return $callback1$$();$details$$.joinModel2(null,dmvt,[{where:$item$$=>({id_app:$r$$.id_app,ma_vt:$item$$.ma_vt}),fields:"ten_vt ten_vt_eng picture chieu_cao chieu_rong chieu_sau trong_luong".split(" ")}],function(){$callback1$$()})},function(){$callback$$()})},details_tt1:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){$r$$.details.filter($item$$=>$item$$.ma_tt1).joinModel2(null,dmtt,[{where:$item$$=>({id_app:$r$$.id_app,ma_vt:$item$$.ma_vt,
145
- ma_tt1:$item$$.ma_tt1}),setFields:($item$$,$ref$$)=>{$item$$.ten_vt=$item$$.ten_vt+" - "+$ref$$.ten_tt}}],function(){$callback1$$()})},function(){$callback$$()})},details_dt:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){const $details$$=$r$$.details;if(!$details$$)return $callback1$$();$details$$.filter($item$$=>$item$$.ma_dt).joinModel2(null,dmdt,[{where:$item$$=>({id_app:$r$$.id_app,ma_dt:$item$$.ma_dt}),fields:["ten_dt"]}],function(){$callback1$$()})},function(){$callback$$()})},
146
- details_contract:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){const $details$$=$r$$.details;if(!$details$$)return $callback1$$();$details$$.filter($item$$=>$item$$.ma_hd).joinModel2(null,contract,[{where:$item$$=>({id_app:$r$$.id_app,so_hd:$item$$.ma_hd}),fields:["ten_hd"]}],function(){$callback1$$()})},function(){$callback$$()})},details_phi:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){const $details$$=$r$$.details;if(!$details$$)return $callback1$$();
147
- $details$$.filter($item$$=>$item$$.ma_phi).joinModel2(null,dmphi,[{where:$item$$=>({id_app:$r$$.id_app,ma_phi:$item$$.ma_phi}),fields:["ten_phi"]}],function(){$callback1$$()})},function(){$callback$$()})},details_cpbh:function($callback$$){async.each($items$$,function($r$$,$callback1$$){let $ctcpbhs$$=$r$$.ctcpbhs;if(!$ctcpbhs$$)return $callback1$$();$ctcpbhs$$?$ctcpbhs$$.filter($item$$=>$item$$.ma_cp).joinModel2(null,dmcpmh,[{where:$item$$=>({id_app:$r$$.id_app,ma_cp:$item$$.ma_cp}),fields:["ten_cp"]}],
148
- function(){$callback1$$()}):$callback1$$()},function(){$callback$$()})}},function(){$fn$$(null,$items$$)})}};
126
+ $paymentServiceModel$$.createVirtualPaymentClientURL){let $virtual_payment_client_url$$=await $paymentServiceModel$$.createVirtualPaymentClientURL($obj$$,$user$$.clientIp,$pt_thanh_toan$$);$obj$$.virtual_payment_client_url=$virtual_payment_client_url$$;$obj$$.payment_service=$pt_thanh_toan$$.payment_service;$obj$$.payment_id=((await $paymentServiceModel$$.findOne({$or:[{id_ct:$obj$$._id.toString()},{request_id:$obj$$._id.toString()},{order_id:$obj$$._id.toString()}]})||{})._id||"").toString()}else $obj$$.virtual_payment_client_url=
127
+ "",$obj$$.payment_service="",$obj$$.payment_id=""}else $obj$$.virtual_payment_client_url=""}catch($e$$){return console.error($e$$),$next$$("Kh\u00f4ng tao li\u00ean k\u1ebft thanh to\u00e1n:"+($e$$.message||$e$$.error||$e$$))}else console.log("Chua nhap phuong thuc thanh toan"),$obj$$.virtual_payment_client_url="";model.findOneAndUpdate({_id:$obj$$._id},{virtual_payment_client_url:$obj$$.virtual_payment_client_url,payment_id:$obj$$.payment_id,payment_service:$obj$$.payment_service},$e$$=>{$e$$&&(console.error($e$$),
128
+ console.log("error create Virtual Payment ClientURL",$e$$.message))});await createTransactionPayment($obj$$);await createTransactionBonus($obj$$);$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>updateEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$next$$(null,$obj$$)};$contr_router$$.updating=async($user$$,$data$$,$obj$$,$next$$)=>{$data$$.details||($data$$.details=$obj$$.details);if("10"==$data$$.trang_thai&&0>["LCT","0","1"].indexOf($obj$$.trang_thai))return $next$$("Kh\u00f4ng th\u1ec3 hu\u1ef7 \u0111\u01a1n h\u00e0ng n\u00e0y");
129
+ $data$$.da_chuyen_hoa_hong=$obj$$.da_chuyen_hoa_hong;$data$$.da_chuyen_hoa_hong_gt=$obj$$.da_chuyen_hoa_hong_gt;await $data$$.details.asyncJoinModel2($user$$.current_id_app,dmvt,{where:"ma_vt",fields:["combo"]});$obj$$.details.forEach($detail$$=>{$detail$$.combo&&0<$detail$$.combo.length&&($detail$$.combo=$detail$$.combo.map($item$$=>{$item$$=$item$$.toObject?$item$$.toObject():{...$item$$};$item$$.sl_xuat*=$detail$$.sl_xuat;$item$$.tien_xuat=$item$$.tien_xuat_nt=$item$$.sl_xuat*($item$$.gia_von_nt||
130
+ 0);$item$$.tien_hang=$item$$.tien_hang_nt=$item$$.sl_xuat*($item$$.gia_ban_nt||0);$item$$.tien_ck=$item$$.tien_ck_nt=$item$$.sl_xuat*($item$$.tien_ck_nt||0);$item$$.tien=$item$$.tien_nt=$item$$.tien_hang_nt-($item$$.tien_ck_nt||0);return $item$$}))});$data$$.pt_thanh_toan&&$data$$.pt_thanh_toan!=$obj$$.pt_thanh_toan&&($data$$.virtual_payment_client_url="",$data$$.payment_service="",$data$$.payment_id="");$data$$.evouchers=$data$$.evouchers||$obj$$.evouchers||[];valid($user$$,$data$$,async $error$$=>
131
+ {if($error$$)return $next$$($error$$);if(($obj$$.paymentByPoints||0)!==($data$$.paymentByPoints||0))return $next$$("B\u1ea1n kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt s\u1ed1 \u0111i\u1ec3m thanh to\u00e1n.");await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":buy"});$next$$(null,$data$$,$obj$$)},$obj$$)};$contr_router$$.updated=async function($amount$jscomp$5_evouchers_user$$,$obj$$,$next$$){if(!$obj$$.virtual_payment_client_url&&("1"===$obj$$.trang_thai||"0"===$obj$$.trang_thai||"LCT"===$obj$$.trang_thai)){if($obj$$.pt_thanh_toan&&
132
+ global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan))try{var $pt_thanh_toan$jscomp$1_pt_thanh_toan$$=await global.getModel("ptthanhtoan").findOne({_id:$obj$$.pt_thanh_toan});if($pt_thanh_toan$jscomp$1_pt_thanh_toan$$.payment_service){var $app_paymentServiceModel$$=global.getModel($pt_thanh_toan$jscomp$1_pt_thanh_toan$$.payment_service);$obj$$.amount=$obj$$.t_tt_nt-($obj$$.tien_paymentByPoints||0);if($obj$$.amount&&$app_paymentServiceModel$$.createVirtualPaymentClientURL){var $memo$jscomp$3_virtual_payment_client_url$$=
133
+ await $app_paymentServiceModel$$.createVirtualPaymentClientURL($obj$$,$amount$jscomp$5_evouchers_user$$.clientIp,$pt_thanh_toan$jscomp$1_pt_thanh_toan$$);$obj$$.virtual_payment_client_url=$memo$jscomp$3_virtual_payment_client_url$$;$obj$$.payment_service=$pt_thanh_toan$jscomp$1_pt_thanh_toan$$.payment_service;$obj$$.payment_id=((await $app_paymentServiceModel$$.findOne({$or:[{id_ct:$obj$$._id.toString()},{request_id:$obj$$._id.toString()},{order_id:$obj$$._id.toString()}]})||{})._id||"").toString()}else $obj$$.virtual_payment_client_url=
134
+ "",$obj$$.payment_service="",$obj$$.payment_id=""}else $obj$$.virtual_payment_client_url=""}catch($e$$){return console.error($e$$),$next$$("Error create Virtual Payment ClientURL:"+($e$$.message||$e$$.error||$e$$))}else $obj$$.virtual_payment_client_url="";model.findOneAndUpdate({_id:$obj$$._id},{virtual_payment_client_url:$obj$$.virtual_payment_client_url,payment_id:$obj$$.payment_id,payment_service:$obj$$.payment_service},$e$$=>{$e$$&&console.log("error create Virtual Payment ClientURL",$e$$.message)})}await Evoucher.updateMany({id_ct_used:$obj$$._id.toString()},
135
+ {id_ct_used:null});$amount$jscomp$5_evouchers_user$$=await Evoucher.find({id_ct_useds:$obj$$._id.toString()});await Promise.all($amount$jscomp$5_evouchers_user$$.map($e$$=>deleteEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));if("9"===$obj$$.trang_thai||"10"===$obj$$.trang_thai){if(await transaction.deleteTrans({id_ct:$obj$$._id.toString()}),await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng"),await transaction.deleteTrans({id_ct:$obj$$._id.toString()+
136
+ ":buy"}),"10"===$obj$$.trang_thai&&$obj$$.payment_id&&global.mongoose.Types.ObjectId.isValid($obj$$.payment_id)&&"5"===$obj$$.trang_thai_tt&&$obj$$.virtual_payment_client_url&&$obj$$.pt_thanh_toan&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan)&&($pt_thanh_toan$jscomp$1_pt_thanh_toan$$=await global.getModel("ptthanhtoan").findOne({_id:$obj$$.pt_thanh_toan}),"assrequest"==$pt_thanh_toan$jscomp$1_pt_thanh_toan$$.payment_service&&($amount$jscomp$5_evouchers_user$$=$obj$$.t_tt_nt-($obj$$.tien_paymentByPoints||
137
+ 0))))if($pt_thanh_toan$jscomp$1_pt_thanh_toan$$=await global.getModel($pt_thanh_toan$jscomp$1_pt_thanh_toan$$.payment_service).findOne({_id:$obj$$.payment_id}),$app_paymentServiceModel$$=await App.findOne({_id:$obj$$.id_app}),$app_paymentServiceModel$$.wallet_address&&$app_paymentServiceModel$$.wallet_token&&$pt_thanh_toan$jscomp$1_pt_thanh_toan$$&&"1"==$pt_thanh_toan$jscomp$1_pt_thanh_toan$$.trang_thai){$memo$jscomp$3_virtual_payment_client_url$$="Tr\u1ea3 l\u1ea1i ti\u1ec1n cho \u0111\u01a1n h\u00e0ng "+
138
+ $pt_thanh_toan$jscomp$1_pt_thanh_toan$$.order_id;let $denom$$=$pt_thanh_toan$jscomp$1_pt_thanh_toan$$.denom;try{await blockchainconnect.spend($obj$$.id_app,$app_paymentServiceModel$$.wallet_token,$app_paymentServiceModel$$.wallet_address,$pt_thanh_toan$jscomp$1_pt_thanh_toan$$.sender_address,{amount:$amount$jscomp$5_evouchers_user$$,denom:$denom$$,memo:$memo$jscomp$3_virtual_payment_client_url$$}),await model.updateOne({_id:$obj$$._id},{trang_thai_tt:9})}catch($e$$){console.error("Kh\u00f4ng th\u1ec3 tr\u1ea3 ti\u1ec1n cho \u0111\u01a1n h\u00e0ng",
139
+ $e$$)}}}else await createTransactionPayment($obj$$),createTransactionBonus($obj$$),$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>updateEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$next$$(null,$obj$$)};$contr_router$$.deleting=function($user$$,$obj$$,$next$$){$next$$(null,$obj$$)};$contr_router$$.deleted=async function($user$$,$obj$$,$next$$){await transaction.deleteTrans({id_ct:$obj$$._id.toString()});await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng");
140
+ await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":buy"});$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>deleteEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$next$$(null,$obj$$)};$contr_router$$.view=function($user$$,$items$$,$fn$$){async.series({app:function($callback$$){$items$$.filter($item$$=>$item$$.id_app).joinModel2(null,App,[{where:{id_app:"_id"},fields:{name_app:"name"}}],function(){$callback$$()})},kh:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kh).joinModel2(null,
141
+ customer,[{where:$item$$=>({id_app:$item$$.id_app,ma_kh:$item$$.ma_kh}),fields:"ten_kh"}],function(){$callback$$()})},nhan_vien_giao_hang:function($callback$$){$items$$.filter($item$$=>$item$$.nhan_vien_giao_hang).joinModel2(null,customer,[{where:{nhan_vien_giao_hang:"ma_kh"},fields:[{ten_nhan_vien_giao_hang:"ten_kh"}]}],function(){$callback$$()})},nv_giao_hang:function($callback$$){$items$$.filter($item$$=>$item$$.user_nv_giao_hang).joinModel2(null,User,{where:{user_nv_giao_hang:"email"},fields:{ten_nv_giao_hang:"name"}},
142
+ function(){$callback$$()})},kho:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kho).joinModel2(null,dmkho,[{where:$item$$=>({id_app:$item$$.id_app,ma_kho:$item$$.ma_kho}),fields:["ten_kho",{tk_cn_kho:"tk_cn"}]}],function(){$callback$$()})},trangthai:function($callback$$){$items$$.filter($item$$=>$item$$.trang_thai).joinModel2(null,trangthai,[{where:{trang_thai:"ma_trang_thai",ma_ct:"ma_ct"},fields:["ten_trang_thai","color"]}],function(){$callback$$()})},ptthanhtoan:function($callback$$){$items$$.filter($item$$=>
143
+ $item$$.pt_thanh_toan).joinModel2(null,ptthanhtoan,[{where:$item$$=>({_id:$item$$.pt_thanh_toan,id_app:$item$$.id_app}),fields:[{ten_pt_thanh_toan:"ten"},{tk_cn_thanhtoan:"tk_cn"}]}],function(){$callback$$()})},pt1:function($callback$$){$items$$.joinModel2(null,pt1,[{where:$item$$=>({id_app:$item$$.id_app,id_so1:"_id"}),fields:[{id_pt1:"_id"},{so_ct_pt1:"so_ct"},{ma_ct_pt1:"ma_ct"},{ngay_ct_pt1:"ngay_ct"}]}],function(){$callback$$()})},t_tien:function($callback$$){$items$$.filter($item$$=>$item$$.details).forEach(function($r$$){$r$$.tien_phi_vc=
144
+ $r$$.tien_phi_vc||0;$r$$.tien_freeship=$r$$.tien_freeship||0;$r$$.details?($r$$.t_sl=$r$$.details.csum("sl_xuat"),$r$$.t_tien_hang=$r$$.details.csum("tien_hang"),$r$$.t_tien_hang_nt=$r$$.details.csum("tien_hang_nt"),$r$$.t_tien=$r$$.t_tien_hang-$r$$.details.csum("tien_ck"),$r$$.t_tien_nt=$r$$.t_tien_hang_nt-$r$$.details.csum("tien_ck_nt"),$r$$.t_ck_nt=$r$$.t_ck=$r$$.tien_ck_hd+($r$$.tien_evoucher||0)):($r$$.t_sl=0,$r$$.t_tien_hang=0,$r$$.t_tien_hang_nt=0,$r$$.t_ck=0,$r$$.t_ck_nt=0,$r$$.t_tien=$r$$.t_tien_hang,
145
+ $r$$.t_tien_nt=$r$$.t_tien_hang_nt);$r$$.ctcpbhs?($r$$.t_cp_cpb_nt=$r$$.ctcpbhs.csum("tien_cp_nt"),$r$$.t_cp_cpb=$r$$.ctcpbhs.csum("tien_cp")):($r$$.t_cp_cpb_nt=0,$r$$.t_cp_cpb=0);$r$$.t_tt=$r$$.t_tt_nt=Math.max(0,$r$$.t_tien_nt+$r$$.t_cp_cpb_nt-$r$$.t_ck_nt-($r$$.tt_tien_thuong||0)+($r$$.tien_phi_vc||0)-($r$$.tien_freeship||0))});$callback$$()},details_vt:function($callback$$){async.each($items$$,function($r$$,$callback1$$){const $details$$=$r$$.details;if(!$details$$)return $callback1$$();$details$$.joinModel2(null,
146
+ dmvt,[{where:$item$$=>({id_app:$r$$.id_app,ma_vt:$item$$.ma_vt}),fields:"ten_vt ten_vt_eng picture chieu_cao chieu_rong chieu_sau trong_luong".split(" ")}],function(){$callback1$$()})},function(){$callback$$()})},details_tt1:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_tt1).joinModel2(null,dmtt,[{where:$item$$=>({id_app:$r$$.id_app,ma_vt:$item$$.ma_vt,ma_tt1:$item$$.ma_tt1}),setFields:($item$$,$ref$$)=>{$item$$.ten_vt=$item$$.ten_vt+
147
+ " - "+$ref$$.ten_tt}}],function(){$callback1$$()})},function(){$callback$$()})},details_dt:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){const $details$$=$r$$.details;if(!$details$$)return $callback1$$();$details$$.filter($item$$=>$item$$.ma_dt).joinModel2(null,dmdt,[{where:$item$$=>({id_app:$r$$.id_app,ma_dt:$item$$.ma_dt}),fields:["ten_dt"]}],function(){$callback1$$()})},function(){$callback$$()})},details_contract:function($callback$$){async.mapSeries($items$$,function($r$$,
148
+ $callback1$$){const $details$$=$r$$.details;if(!$details$$)return $callback1$$();$details$$.filter($item$$=>$item$$.ma_hd).joinModel2(null,contract,[{where:$item$$=>({id_app:$r$$.id_app,so_hd:$item$$.ma_hd}),fields:["ten_hd"]}],function(){$callback1$$()})},function(){$callback$$()})},details_phi:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){const $details$$=$r$$.details;if(!$details$$)return $callback1$$();$details$$.filter($item$$=>$item$$.ma_phi).joinModel2(null,dmphi,
149
+ [{where:$item$$=>({id_app:$r$$.id_app,ma_phi:$item$$.ma_phi}),fields:["ten_phi"]}],function(){$callback1$$()})},function(){$callback$$()})},details_cpbh:function($callback$$){async.each($items$$,function($r$$,$callback1$$){let $ctcpbhs$$=$r$$.ctcpbhs;if(!$ctcpbhs$$)return $callback1$$();$ctcpbhs$$?$ctcpbhs$$.filter($item$$=>$item$$.ma_cp).joinModel2(null,dmcpmh,[{where:$item$$=>({id_app:$r$$.id_app,ma_cp:$item$$.ma_cp}),fields:["ten_cp"]}],function(){$callback1$$()}):$callback1$$()},function(){$callback$$()})}},
150
+ function(){$fn$$(null,$items$$)})}};
@@ -35,23 +35,24 @@ $option$$.tk_tien,$error$jscomp$2_tt_tt$$.tien_nt=$obj$$.tt_tien_thuong||0,$erro
35
35
  if(!$obj$$.ma_kh){let $cust$$=await global.getModel("customer").findOne({id_app:$user$$.current_id_app,of_user:$user$$.email},{ma_kh:1,ten_kh:1}).lean();$cust$$&&($obj$$.ma_kh=$cust$$.ma_kh)}valid($user$$,$obj$$,async $error$$=>{if($error$$)return $next$$($error$$);if(!$obj$$.paymentByPoints)return $next$$(null,$obj$$);try{let $detail_buy_coins$$=$obj$$.details.filter($d$$=>$d$$.is_coin&&!$d$$.transferred&&$d$$.wallet_receiver).asyncGroupBy(["ma_vt"],["sl_xuat"]);if(1==$detail_buy_coins$$.length&&
36
36
  await getWalletBalanceOfApp($user$$.current_id_app,$detail_buy_coins$$[0].ma_vt.toLowerCase())<$detail_buy_coins$$[0].sl_xuat)return $next$$("B\u1ea1n kh\u00f4ng th\u1ec3 n\u1ea1p ti\u1ec1n th\u1eddi gian n\u00e0y. Hay th\u1eed l\u1ea1i sau");if(1<$detail_buy_coins$$.length)return $next$$("M\u1ed7i l\u1ea7n ch\u1ec9 \u0111\u01b0\u1ee3c mua m\u1ed9t lo\u1ea1i coin");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.");
37
37
  $next$$(null,$obj$$)}catch($e$$){$next$$($e$$.message)}})};$contr_router$$.created=async function($user$$,$obj$$,$next$$){if($obj$$.pt_thanh_toan&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan))try{const $pt_thanh_toan$$=await global.getModel("ptthanhtoan").findOne({_id:$obj$$.pt_thanh_toan});if($pt_thanh_toan$$.payment_service){let $paymentServiceModel$$=global.getModel($pt_thanh_toan$$.payment_service);$obj$$.amount=$obj$$.t_tt_nt-($obj$$.tien_paymentByPoints||0);if($obj$$.amount&&
38
- $paymentServiceModel$$.createVirtualPaymentClientURL){let $virtual_payment_client_url$$=await $paymentServiceModel$$.createVirtualPaymentClientURL($obj$$,$user$$.clientIp,$pt_thanh_toan$$);$obj$$.virtual_payment_client_url=$virtual_payment_client_url$$;$obj$$.payment_service=$pt_thanh_toan$$.payment_service;$obj$$.payment_id=((await $paymentServiceModel$$.findOne({id_ct:$obj$$._id.toString()})||{})._id||"").toString()}else $obj$$.virtual_payment_client_url="",$obj$$.payment_service="",$obj$$.payment_id=
39
- ""}else $obj$$.virtual_payment_client_url=""}catch($e$$){return console.error($e$$),$next$$("Kh\u00f4ng tao li\u00ean k\u1ebft thanh to\u00e1n:"+($e$$.message||$e$$.error||$e$$))}else console.log("Chua nhap phuong thuc thanh toan"),$obj$$.virtual_payment_client_url="";model.findOneAndUpdate({_id:$obj$$._id},{virtual_payment_client_url:$obj$$.virtual_payment_client_url},$e$$=>{$e$$&&(console.error($e$$),console.log("error create Virtual Payment ClientURL",$e$$.message))});await createTransactionPayment($obj$$);
40
- await createTransactionBonus($obj$$);$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>updateEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$next$$(null,$obj$$)};$contr_router$$.updating=async($user$$,$data$$,$obj$$,$next$$)=>{$data$$.pt_thanh_toan&&$data$$.pt_thanh_toan!=$obj$$.pt_thanh_toan&&($data$$.virtual_payment_client_url="",$data$$.payment_service="",$data$$.payment_id="");valid($user$$,$data$$,async $detail_buy_coins$jscomp$1_error$$=>{if($detail_buy_coins$jscomp$1_error$$)return $next$$($detail_buy_coins$jscomp$1_error$$);
41
- if(($obj$$.paymentByPoints||0)!==($data$$.paymentByPoints||0))return $next$$("B\u1ea1n kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt s\u1ed1 \u0111i\u1ec3m thanh to\u00e1n.");$detail_buy_coins$jscomp$1_error$$=$data$$.details.filter($d$$=>$d$$.is_coin&&!$d$$.transferred&&$d$$.wallet_receiver).asyncGroupBy(["ma_vt"],["sl_xuat"]);if(1==$detail_buy_coins$jscomp$1_error$$.length&&await getWalletBalanceOfApp($user$$.current_id_app,$detail_buy_coins$jscomp$1_error$$[0].ma_vt.toLowerCase())<$detail_buy_coins$jscomp$1_error$$[0].sl_xuat)return $next$$("B\u1ea1n kh\u00f4ng th\u1ec3 n\u1ea1p ti\u1ec1n th\u1eddi gian n\u00e0y. Hay th\u1eed l\u1ea1i sau");
42
- if(1<$detail_buy_coins$jscomp$1_error$$.length)return $next$$("M\u1ed7i l\u1ea7n ch\u1ec9 \u0111\u01b0\u1ee3c mua m\u1ed9t lo\u1ea1i coin");await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":buy"});$next$$(null,$data$$,$obj$$)},$obj$$)};$contr_router$$.updated=async function($evouchers_user$$,$obj$$,$next$$){if(!$obj$$.virtual_payment_client_url&&("1"===$obj$$.trang_thai||"0"===$obj$$.trang_thai)){if($obj$$.pt_thanh_toan&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan))try{const $pt_thanh_toan$$=
43
- await global.getModel("ptthanhtoan").findOne({_id:$obj$$.pt_thanh_toan});if($pt_thanh_toan$$.payment_service){let $paymentServiceModel$$=global.getModel($pt_thanh_toan$$.payment_service);$obj$$.amount=$obj$$.t_tt_nt-($obj$$.tien_paymentByPoints||0);if($obj$$.amount&&$paymentServiceModel$$.createVirtualPaymentClientURL){let $virtual_payment_client_url$$=await $paymentServiceModel$$.createVirtualPaymentClientURL($obj$$,$evouchers_user$$.clientIp,$pt_thanh_toan$$);$obj$$.virtual_payment_client_url=$virtual_payment_client_url$$;
44
- $obj$$.payment_service=$pt_thanh_toan$$.payment_service;$obj$$.payment_id=((await $paymentServiceModel$$.findOne({id_ct:$obj$$._id.toString()})||{})._id||"").toString()}else $obj$$.virtual_payment_client_url="",$obj$$.payment_service="",$obj$$.payment_id=""}else $obj$$.virtual_payment_client_url=""}catch($e$$){return console.error($e$$),$next$$("Error create Virtual Payment ClientURL:"+($e$$.message||$e$$.error||$e$$))}else $obj$$.virtual_payment_client_url="";model.findOneAndUpdate({_id:$obj$$._id},
45
- {virtual_payment_client_url:$obj$$.virtual_payment_client_url},$e$$=>{$e$$&&console.log("error create Virtual Payment ClientURL",$e$$.message)})}"9"===$obj$$.trang_thai?(await transaction.deleteTrans({id_ct:$obj$$._id.toString()}),await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng"),await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":buy"})):(await createTransactionPayment($obj$$),createTransactionBonus($obj$$));await Evoucher.updateMany({id_ct_used:$obj$$._id.toString()},
46
- {id_ct_used:null});$evouchers_user$$=await Evoucher.find({id_ct_useds:$obj$$._id.toString()});await Promise.all($evouchers_user$$.map($e$$=>deleteEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>updateEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$next$$(null,$obj$$)};$contr_router$$.deleting=function($user$$,$obj$$,$next$$){$next$$(null,$obj$$)};$contr_router$$.deleted=async function($user$$,$obj$$,$next$$){await transaction.deleteTrans({id_ct:$obj$$._id.toString()});
47
- await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng");await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":buy"});$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>deleteEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$next$$(null,$obj$$)};$contr_router$$.view=async function($user$$,$items$$,$fn$$){let $id_app$$=$user$$.current_id_app;await Promise.all($items$$.filter($item$$=>"0"==$item$$.trang_thai||"2"==$item$$.trang_thai||
48
- "7"==$item$$.trang_thai).map($inv$$=>(async()=>{let $tg_hien_tai$$=(new Date).getTime(),$tg_tao$$=(new Date($inv$$.date_created)).getTime();1<($tg_hien_tai$$-$tg_tao$$)/864E5&&($inv$$.trang_thai="9",await model.findOneAndUpdate({_id:$inv$$._id},{trang_thai:9}))})()));async.series({kh:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kh).joinModel2($id_app$$,customer,[{where:"ma_kh",fields:"ten_kh"}],function(){$callback$$()})},nhan_vien_giao_hang:function($callback$$){$items$$.filter($item$$=>
49
- $item$$.nhan_vien_giao_hang).joinModel2($id_app$$,customer,[{where:{nhan_vien_giao_hang:"ma_kh"},fields:[{ten_nhan_vien_giao_hang:"ten_kh"}]}],function(){$callback$$()})},nv_giao_hang:function($callback$$){$items$$.filter($item$$=>$item$$.user_nv_giao_hang).joinModel2(null,User,{where:{user_nv_giao_hang:"email"},fields:{ten_nv_giao_hang:"name"}},function(){$callback$$()})},trangthai:function($callback$$){$items$$.filter($item$$=>$item$$.trang_thai).joinModel2(null,trangthai,[{where:{trang_thai:"ma_trang_thai",
50
- 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"},{tk_cn_thanhtoan:"tk_cn"}]}],function(){$callback$$()})},pt1:function($callback$$){$items$$.joinModel2($id_app$$,pt1,[{where:{_id:"id_so5"},fields:[{id_pt1:"_id"},{so_ct_pt1:"so_ct"},{ma_ct_pt1:"ma_ct"},{ngay_ct_pt1:"ngay_ct"}]}],function(){$callback$$()})},
51
- t_tien:function($callback$$){$items$$.forEach(function($r$$){$r$$.details?($r$$.t_sl=$r$$.details.csum("sl_xuat"),$r$$.t_tien_hang=$r$$.details.csum("tien_hang"),$r$$.t_tien_hang_nt=$r$$.details.csum("tien_hang_nt"),$r$$.t_tien=$r$$.t_tien_hang-$r$$.details.csum("tien_ck_nt"),$r$$.t_tien_nt=$r$$.t_tien_hang_nt-$r$$.details.csum("tien_ck"),$r$$.t_ck_nt=$r$$.t_ck=$r$$.tien_ck_hd+($r$$.tien_evoucher||0)):($r$$.t_sl=0,$r$$.t_tien_hang=0,$r$$.t_tien_hang_nt=0,$r$$.t_ck=0,$r$$.t_ck_nt=0,$r$$.t_tien=$r$$.t_tien_hang,
52
- $r$$.t_tien_nt=$r$$.t_tien_hang_nt);$r$$.ctcpbhs?($r$$.t_cp_cpb_nt=$r$$.ctcpbhs.csum("tien_cp_nt"),$r$$.t_cp_cpb=$r$$.ctcpbhs.csum("tien_cp")):($r$$.t_cp_cpb_nt=0,$r$$.t_cp_cpb=0);$r$$.t_tt_nt=$r$$.t_tien_nt+$r$$.t_cp_cpb_nt-$r$$.t_ck_nt-($r$$.tt_tien_thuong||0)+($r$$.tien_phi_vc||0)-($r$$.tien_freeship||0);$r$$.t_tt=$r$$.t_tien+$r$$.t_cp_cpb-$r$$.t_ck-($r$$.tt_tien_thuong||0)+($r$$.tien_phi_vc||0)-($r$$.tien_freeship||0)});$callback$$()},details_vt:function($callback$$){async.each($items$$,function($details$jscomp$2_r$$,
53
- $callback1$$){$details$jscomp$2_r$$=$details$jscomp$2_r$$.details;if(!$details$jscomp$2_r$$)return $callback1$$();$details$jscomp$2_r$$.joinModel2($id_app$$,dmvt,[{where:"ma_vt",fields:["ten_vt"]}],function(){$callback1$$()})},function(){$callback$$()})},details_tt1:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){$r$$.details.filter($item$$=>$item$$.ma_tt1).joinModel2($id_app$$,dmtt,[{where:{ma_vt:"ma_vt",ma_tt1:"ma_tt"},setFields:($item$$,$ref$$)=>{$item$$.ten_vt=$item$$.ten_vt+
54
- " - "+$ref$$.ten_tt}}],function(){$callback1$$()})},function(){$callback$$()})},details_dt:function($callback$$){async.mapSeries($items$$,function($details$jscomp$4_r$$,$callback1$$){$details$jscomp$4_r$$=$details$jscomp$4_r$$.details;if(!$details$jscomp$4_r$$)return $callback1$$();$details$jscomp$4_r$$.filter($item$$=>$item$$.ma_dt).joinModel2($id_app$$,dmdt,[{where:"ma_dt",fields:["ten_dt"]}],function(){$callback1$$()})},function(){$callback$$()})},details_contract:function($callback$$){async.mapSeries($items$$,
55
- function($details$jscomp$5_r$$,$callback1$$){$details$jscomp$5_r$$=$details$jscomp$5_r$$.details;if(!$details$jscomp$5_r$$)return $callback1$$();$details$jscomp$5_r$$.filter($item$$=>$item$$.ma_hd).joinModel2($id_app$$,contract,[{where:{ma_hd:"so_hd"},fields:["ten_hd"]}],function(){$callback1$$()})},function(){$callback$$()})},details_phi:function($callback$$){async.mapSeries($items$$,function($details$jscomp$6_r$$,$callback1$$){$details$jscomp$6_r$$=$details$jscomp$6_r$$.details;if(!$details$jscomp$6_r$$)return $callback1$$();
56
- $details$jscomp$6_r$$.filter($item$$=>$item$$.ma_phi).joinModel2($id_app$$,dmphi,[{where:"ma_phi",fields:["ten_phi"]}],function(){$callback1$$()})},function(){$callback$$()})},details_cpbh:function($callback$$){async.each($items$$,function($ctcpbhs_r$$,$callback1$$){$ctcpbhs_r$$=$ctcpbhs_r$$.ctcpbhs;if(!$ctcpbhs_r$$)return $callback1$$();$ctcpbhs_r$$?$ctcpbhs_r$$.filter($item$$=>$item$$.ma_cp).joinModel2($id_app$$,dmcpmh,[{where:"ma_cp",fields:["ten_cp"]}],function(){$callback1$$()}):$callback1$$()},
57
- function(){$callback$$()})}},function(){$fn$$(null,$items$$)})}};
38
+ $paymentServiceModel$$.createVirtualPaymentClientURL){let $virtual_payment_client_url$$=await $paymentServiceModel$$.createVirtualPaymentClientURL($obj$$,$user$$.clientIp,$pt_thanh_toan$$);$obj$$.virtual_payment_client_url=$virtual_payment_client_url$$;$obj$$.payment_service=$pt_thanh_toan$$.payment_service;$obj$$.payment_id=((await $paymentServiceModel$$.findOne({$or:[{id_ct:$obj$$._id.toString()},{request_id:$obj$$._id.toString()},{order_id:$obj$$._id.toString()}]})||{})._id||"").toString()}else $obj$$.virtual_payment_client_url=
39
+ "",$obj$$.payment_service="",$obj$$.payment_id=""}else $obj$$.virtual_payment_client_url=""}catch($e$$){return console.error($e$$),$next$$("Kh\u00f4ng tao li\u00ean k\u1ebft thanh to\u00e1n:"+($e$$.message||$e$$.error||$e$$))}else console.log("Chua nhap phuong thuc thanh toan"),$obj$$.virtual_payment_client_url="";model.findOneAndUpdate({_id:$obj$$._id},{virtual_payment_client_url:$obj$$.virtual_payment_client_url,payment_id:$obj$$.payment_id,payment_service:$obj$$.payment_service},$e$$=>{$e$$&&(console.error($e$$),
40
+ console.log("error create Virtual Payment ClientURL",$e$$.message))});await createTransactionPayment($obj$$);await createTransactionBonus($obj$$);$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>updateEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$next$$(null,$obj$$)};$contr_router$$.updating=async($user$$,$data$$,$obj$$,$next$$)=>{$data$$.pt_thanh_toan&&$data$$.pt_thanh_toan!=$obj$$.pt_thanh_toan&&($data$$.virtual_payment_client_url="",$data$$.payment_service="",$data$$.payment_id="");
41
+ valid($user$$,$data$$,async $detail_buy_coins$jscomp$1_error$$=>{if($detail_buy_coins$jscomp$1_error$$)return $next$$($detail_buy_coins$jscomp$1_error$$);if(($obj$$.paymentByPoints||0)!==($data$$.paymentByPoints||0))return $next$$("B\u1ea1n kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt s\u1ed1 \u0111i\u1ec3m thanh to\u00e1n.");$detail_buy_coins$jscomp$1_error$$=$data$$.details.filter($d$$=>$d$$.is_coin&&!$d$$.transferred&&$d$$.wallet_receiver).asyncGroupBy(["ma_vt"],["sl_xuat"]);if(1==$detail_buy_coins$jscomp$1_error$$.length&&
42
+ await getWalletBalanceOfApp($user$$.current_id_app,$detail_buy_coins$jscomp$1_error$$[0].ma_vt.toLowerCase())<$detail_buy_coins$jscomp$1_error$$[0].sl_xuat)return $next$$("B\u1ea1n kh\u00f4ng th\u1ec3 n\u1ea1p ti\u1ec1n th\u1eddi gian n\u00e0y. Hay th\u1eed l\u1ea1i sau");if(1<$detail_buy_coins$jscomp$1_error$$.length)return $next$$("M\u1ed7i l\u1ea7n ch\u1ec9 \u0111\u01b0\u1ee3c mua m\u1ed9t lo\u1ea1i coin");await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":buy"});$next$$(null,$data$$,
43
+ $obj$$)},$obj$$)};$contr_router$$.updated=async function($evouchers_user$$,$obj$$,$next$$){if(!$obj$$.virtual_payment_client_url&&("1"===$obj$$.trang_thai||"0"===$obj$$.trang_thai)){if($obj$$.pt_thanh_toan&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan))try{const $pt_thanh_toan$$=await global.getModel("ptthanhtoan").findOne({_id:$obj$$.pt_thanh_toan});if($pt_thanh_toan$$.payment_service){let $paymentServiceModel$$=global.getModel($pt_thanh_toan$$.payment_service);$obj$$.amount=$obj$$.t_tt_nt-
44
+ ($obj$$.tien_paymentByPoints||0);if($obj$$.amount&&$paymentServiceModel$$.createVirtualPaymentClientURL){let $virtual_payment_client_url$$=await $paymentServiceModel$$.createVirtualPaymentClientURL($obj$$,$evouchers_user$$.clientIp,$pt_thanh_toan$$);$obj$$.virtual_payment_client_url=$virtual_payment_client_url$$;$obj$$.payment_service=$pt_thanh_toan$$.payment_service;$obj$$.payment_id=((await $paymentServiceModel$$.findOne({$or:[{id_ct:$obj$$._id.toString()},{request_id:$obj$$._id.toString()},{order_id:$obj$$._id.toString()}]})||
45
+ {})._id||"").toString()}else $obj$$.virtual_payment_client_url="",$obj$$.payment_service="",$obj$$.payment_id=""}else $obj$$.virtual_payment_client_url=""}catch($e$$){return console.error($e$$),$next$$("Error create Virtual Payment ClientURL:"+($e$$.message||$e$$.error||$e$$))}else $obj$$.virtual_payment_client_url="";model.findOneAndUpdate({_id:$obj$$._id},{virtual_payment_client_url:$obj$$.virtual_payment_client_url,payment_id:$obj$$.payment_id,payment_service:$obj$$.payment_service},$e$$=>{$e$$&&
46
+ console.log("error create Virtual Payment ClientURL",$e$$.message)})}"9"===$obj$$.trang_thai?(await transaction.deleteTrans({id_ct:$obj$$._id.toString()}),await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng"),await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":buy"})):(await createTransactionPayment($obj$$),createTransactionBonus($obj$$));await Evoucher.updateMany({id_ct_used:$obj$$._id.toString()},{id_ct_used:null});$evouchers_user$$=
47
+ await Evoucher.find({id_ct_useds:$obj$$._id.toString()});await Promise.all($evouchers_user$$.map($e$$=>deleteEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>updateEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$next$$(null,$obj$$)};$contr_router$$.deleting=function($user$$,$obj$$,$next$$){$next$$(null,$obj$$)};$contr_router$$.deleted=async function($user$$,$obj$$,$next$$){await transaction.deleteTrans({id_ct:$obj$$._id.toString()});await transaction.deleteTrans({id_ct:$obj$$._id.toString()+
48
+ ":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng");await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":buy"});$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>deleteEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$next$$(null,$obj$$)};$contr_router$$.view=async function($user$$,$items$$,$fn$$){let $id_app$$=$user$$.current_id_app;await Promise.all($items$$.filter($item$$=>"0"==$item$$.trang_thai||"2"==$item$$.trang_thai||"7"==$item$$.trang_thai).map($inv$$=>(async()=>
49
+ {let $tg_hien_tai$$=(new Date).getTime(),$tg_tao$$=(new Date($inv$$.date_created)).getTime();1<($tg_hien_tai$$-$tg_tao$$)/864E5&&($inv$$.trang_thai="9",await model.findOneAndUpdate({_id:$inv$$._id},{trang_thai:9}))})()));async.series({kh:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kh).joinModel2($id_app$$,customer,[{where:"ma_kh",fields:"ten_kh"}],function(){$callback$$()})},nhan_vien_giao_hang:function($callback$$){$items$$.filter($item$$=>$item$$.nhan_vien_giao_hang).joinModel2($id_app$$,
50
+ customer,[{where:{nhan_vien_giao_hang:"ma_kh"},fields:[{ten_nhan_vien_giao_hang:"ten_kh"}]}],function(){$callback$$()})},nv_giao_hang:function($callback$$){$items$$.filter($item$$=>$item$$.user_nv_giao_hang).joinModel2(null,User,{where:{user_nv_giao_hang:"email"},fields:{ten_nv_giao_hang:"name"}},function(){$callback$$()})},trangthai:function($callback$$){$items$$.filter($item$$=>$item$$.trang_thai).joinModel2(null,trangthai,[{where:{trang_thai:"ma_trang_thai",ma_ct:"ma_ct"},fields:["ten_trang_thai",
51
+ "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"},{tk_cn_thanhtoan:"tk_cn"}]}],function(){$callback$$()})},pt1:function($callback$$){$items$$.joinModel2($id_app$$,pt1,[{where:{_id:"id_so5"},fields:[{id_pt1:"_id"},{so_ct_pt1:"so_ct"},{ma_ct_pt1:"ma_ct"},{ngay_ct_pt1:"ngay_ct"}]}],function(){$callback$$()})},t_tien:function($callback$$){$items$$.forEach(function($r$$){$r$$.details?
52
+ ($r$$.t_sl=$r$$.details.csum("sl_xuat"),$r$$.t_tien_hang=$r$$.details.csum("tien_hang"),$r$$.t_tien_hang_nt=$r$$.details.csum("tien_hang_nt"),$r$$.t_tien=$r$$.t_tien_hang-$r$$.details.csum("tien_ck_nt"),$r$$.t_tien_nt=$r$$.t_tien_hang_nt-$r$$.details.csum("tien_ck"),$r$$.t_ck_nt=$r$$.t_ck=$r$$.tien_ck_hd+($r$$.tien_evoucher||0)):($r$$.t_sl=0,$r$$.t_tien_hang=0,$r$$.t_tien_hang_nt=0,$r$$.t_ck=0,$r$$.t_ck_nt=0,$r$$.t_tien=$r$$.t_tien_hang,$r$$.t_tien_nt=$r$$.t_tien_hang_nt);$r$$.ctcpbhs?($r$$.t_cp_cpb_nt=
53
+ $r$$.ctcpbhs.csum("tien_cp_nt"),$r$$.t_cp_cpb=$r$$.ctcpbhs.csum("tien_cp")):($r$$.t_cp_cpb_nt=0,$r$$.t_cp_cpb=0);$r$$.t_tt_nt=$r$$.t_tien_nt+$r$$.t_cp_cpb_nt-$r$$.t_ck_nt-($r$$.tt_tien_thuong||0)+($r$$.tien_phi_vc||0)-($r$$.tien_freeship||0);$r$$.t_tt=$r$$.t_tien+$r$$.t_cp_cpb-$r$$.t_ck-($r$$.tt_tien_thuong||0)+($r$$.tien_phi_vc||0)-($r$$.tien_freeship||0)});$callback$$()},details_vt:function($callback$$){async.each($items$$,function($details$jscomp$2_r$$,$callback1$$){$details$jscomp$2_r$$=$details$jscomp$2_r$$.details;
54
+ if(!$details$jscomp$2_r$$)return $callback1$$();$details$jscomp$2_r$$.joinModel2($id_app$$,dmvt,[{where:"ma_vt",fields:["ten_vt"]}],function(){$callback1$$()})},function(){$callback$$()})},details_tt1:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_tt1).joinModel2($id_app$$,dmtt,[{where:{ma_vt:"ma_vt",ma_tt1:"ma_tt"},setFields:($item$$,$ref$$)=>{$item$$.ten_vt=$item$$.ten_vt+" - "+$ref$$.ten_tt}}],function(){$callback1$$()})},
55
+ function(){$callback$$()})},details_dt:function($callback$$){async.mapSeries($items$$,function($details$jscomp$4_r$$,$callback1$$){$details$jscomp$4_r$$=$details$jscomp$4_r$$.details;if(!$details$jscomp$4_r$$)return $callback1$$();$details$jscomp$4_r$$.filter($item$$=>$item$$.ma_dt).joinModel2($id_app$$,dmdt,[{where:"ma_dt",fields:["ten_dt"]}],function(){$callback1$$()})},function(){$callback$$()})},details_contract:function($callback$$){async.mapSeries($items$$,function($details$jscomp$5_r$$,$callback1$$){$details$jscomp$5_r$$=
56
+ $details$jscomp$5_r$$.details;if(!$details$jscomp$5_r$$)return $callback1$$();$details$jscomp$5_r$$.filter($item$$=>$item$$.ma_hd).joinModel2($id_app$$,contract,[{where:{ma_hd:"so_hd"},fields:["ten_hd"]}],function(){$callback1$$()})},function(){$callback$$()})},details_phi:function($callback$$){async.mapSeries($items$$,function($details$jscomp$6_r$$,$callback1$$){$details$jscomp$6_r$$=$details$jscomp$6_r$$.details;if(!$details$jscomp$6_r$$)return $callback1$$();$details$jscomp$6_r$$.filter($item$$=>
57
+ $item$$.ma_phi).joinModel2($id_app$$,dmphi,[{where:"ma_phi",fields:["ten_phi"]}],function(){$callback1$$()})},function(){$callback$$()})},details_cpbh:function($callback$$){async.each($items$$,function($ctcpbhs_r$$,$callback1$$){$ctcpbhs_r$$=$ctcpbhs_r$$.ctcpbhs;if(!$ctcpbhs_r$$)return $callback1$$();$ctcpbhs_r$$?$ctcpbhs_r$$.filter($item$$=>$item$$.ma_cp).joinModel2($id_app$$,dmcpmh,[{where:"ma_cp",fields:["ten_cp"]}],function(){$callback1$$()}):$callback1$$()},function(){$callback$$()})}},function(){$fn$$(null,
58
+ $items$$)})}};