flexbiz-server 12.0.8 → 12.0.9

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.0.8",
5
+ "version": "12.0.9",
6
6
  "author": {
7
7
  "name": "Van Truong Pham",
8
8
  "email": "invncur@gmail.com"
@@ -34,12 +34,12 @@ $e$$,$approveData_condition$$),!1}});$approveDatas$$.filter($a$$=>$a$$.approve_u
34
34
  $ds_nguoi_duyet$$.map($nguoi_duyet$$=>({email:$nguoi_duyet$$,name:$nguoi_duyet$$}));$user_approves$$.joinModel2($obj$$.id_app,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)})}})});$next$$(null,$obj$$)}async sendEmailNotification($user$$,$obj$$,$title$$,$callback$jscomp$0$$,$voucher_options$$){$voucher_options$$||
35
35
  ($voucher_options$$=(await OptionsModel.findOne({id_app:$obj$$.id_app,id_func:this.name},{option:1}).lean()||{}).option);$voucher_options$$&&$voucher_options$$.send_notification_to_users?async.map($voucher_options$$.send_notification_to_users,($u$$,$callback$$)=>{setImmediate(()=>{global.createNotification($obj$$.user_updated,$u$$.email,$title$$,$title$$,($e$$,$rs$$)=>{$callback$$($e$$,$rs$$)},$obj$$,!0,$user$$.c_token,!0)})},$e$$=>{$callback$jscomp$0$$($e$$)}):$callback$jscomp$0$$()}async import($user$$,
36
36
  $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();$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});
37
- await $data$$.filter($r$$=>$r$$.ma_dvcs).asyncJoinModel2($id_app$$,global.getModel("dvcs"),{where:{ma_dvcs:"_id"},fields:"ten_dvcs"});async.map($data$$,function($row$$,$callback$$){const $row_keys$$=Object.keys($row$$);$row_keys$$.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("[")||
38
- 0==$data_value$$.indexOf("{")))try{$row$$[$key$$]=JSON.parse($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;$id_app$$!=$row$$.id_app&&delete $row$$._id;delete $row$$.id_app;if($replace$$&&$ctrl$$.unique&&0<$ctrl$$.unique.length){let $query$$={};0!=$ctrl$$.require_id_app&&($query$$.id_app=$id_app$$);$ctrl$$.options.unique_imp&&$row$$[$ctrl$$.options.unique_imp]?$query$$[$ctrl$$.options.unique_imp]=
39
- $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$$,$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();
40
- $ctrl$$.unique.forEach(function($k$$){$row$$[$k$$]=$rs$$[$k$$]});update($user$$,$ctrl$$,$rs$$._id,$row$$,function($e$$){console.log("updated object...");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$$){console.log("created new object...");if($e$$){let $_e$$=$e$$;underscore.isArray($_e$$)||($_e$$=[$e$$]);$rows_error$$.push({row:$row$$,
41
- error:$_e$$})}$callback$$()},$row$$._id,$options$$.req)})})}else create($user$$,$ctrl$$,$row$$,function($e$$){console.log("created new object...");setImmediate(()=>{if($e$$){let $_e$$=$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,
42
- rows_error:[]}):$callback$jscomp$0$$(null,{rows_imported:$data$$.length-$rows_error$$.length,rows_error:$rows_error$$})})})}}controller.prototype.__proto__=EventEmitter.prototype;
37
+ await $data$$.filter($r$$=>$r$$.ma_dvcs).asyncJoinModel2($id_app$$,global.getModel("dvcs"),{where:{ma_dvcs:"_id"},fields:"ten_dvcs"});async.map($data$$,function($row$$,$callback$$){const $row_keys$$=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$$=
38
+ $data_value$$.trim(),0==$data_value$$.indexOf("[")||0==$data_value$$.indexOf("{")))try{$row$$[$key$$]=JSON.parse($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;$id_app$$!=$row$$.id_app&&delete $row$$._id;delete $row$$.id_app;if($replace$$&&$ctrl$$.unique&&0<$ctrl$$.unique.length){let $query$$={};0!=$ctrl$$.require_id_app&&($query$$.id_app=$id_app$$);$ctrl$$.options.unique_imp&&
39
+ $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$$,$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$$=
40
+ $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$$){console.log("updated object...");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$$){console.log("created new object...");if($e$$){let $_e$$=
41
+ $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$$){console.log("created new object...");setImmediate(()=>{if($e$$){let $_e$$=$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$$);
42
+ 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;
43
43
  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();
44
44
  $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!==
45
45
  $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});counter.getNextSequence($id_app$$,$ma_ct$$,$qct$$?$qct$$._id.toString():$field$$,function($error$$,$rs$jscomp$0$$){if($error$$)console.error("auto create code for",$ma_ct$$,$field$$,$error$$),$callback$$($error$$);else{if($qct$$){let $tien_to$$=$qct$$.tien_to||
@@ -189,30 +189,32 @@ async function createIdRef($model$$,$data$$){$model$$=Object.values($model$$.sch
189
189
  mongoose.models[$modelRef_modelRefName$$.toLowerCase()])?($localField_obj$$=await $modelRef_modelRefName$$.findOne({id_app:$data$$.id_app,[$foreignField$$]:$data$$[$localField_obj$$]}).lean(),$data$$[$namePath$$]=$localField_obj$$?$localField_obj$$._id.toString():null):$data$$[$namePath$$]=null:$data$$[$namePath$$]=null;$resove$$($path$$)})})))}catch($e2$$){return console.error("error create ref data",$e2$$),null}}
190
190
  async function create($user$jscomp$0$$,$ctrl$$,$data$$,$callback$jscomp$1$$,$id_be_supply_by_user$$,$req$$){try{const $model$$=$ctrl$$.model,$voucher_options$$=(await OptionsModel.findOne({id_app:$user$jscomp$0$$.current_id_app,id_func:$ctrl$$.name}).lean()||{}).option,$schema_paths$$=$model$$.schema.paths;let $v_data$$;try{$v_data$$=await asyncBodyToJson($data$$,$ctrl$$,$user$jscomp$0$$.current_id_app,$voucher_options$$)}catch($e$$){return $callback$jscomp$1$$($e$$.message||$e$$.error||$e$$)}underscore.has($schema_paths$$,
191
191
  "ma_ct")&&$ctrl$$.options.isVoucher&&($v_data$$.ma_ct=$ctrl$$.name.toUpperCase());if($ctrl$$.options.requireRecaptchaToken){if(!$v_data$$["g-recaptcha-response"])return $callback$jscomp$1$$("Ch\u1ee9c n\u0103ng n\u00e0y y\u00eau c\u1ea7u g-recaptcha-response");try{await permission.verifyReCaptcha($v_data$$["g-recaptcha-response"])}catch($e$$){return $callback$jscomp$1$$($e$$.message||$e$$.error||$e$$)}}if(0>global.configs.admins.indexOf($user$jscomp$0$$.email)){let $requireOtp$$=$ctrl$$.options.requireOtp;
192
- $requireOtp$$&&_.isFunction($requireOtp$$)&&($requireOtp$$=$requireOtp$$($v_data$$,{action:"create",user:$user$jscomp$0$$}));if($requireOtp$$)try{await permission.verifyOTP($user$jscomp$0$$.email,$v_data$$["otp-id"],$v_data$$["otp-code"])}catch($e$$){return $callback$jscomp$1$$({error:$e$$.message||$e$$.error||$e$$,code:ERR_VERIFY_OTP})}}const $obj$jscomp$0$$=new $model$$;underscore.has($schema_paths$$,"exfields")&&($obj$jscomp$0$$.exfields=$v_data$$.exfields||{});for(let $f$$ in $v_data$$)underscore.has($schema_paths$$,
193
- $f$$)&&($obj$jscomp$0$$.set($f$$,$v_data$$[$f$$]),"exfields"!==$f$$||$obj$jscomp$0$$.exfields||($obj$jscomp$0$$.exfields={}));!0===underscore.has($schema_paths$$,"id_app")&&($obj$jscomp$0$$.id_app=$user$jscomp$0$$.current_id_app);const $checkVoucherNumber$$=$callback$$=>{underscore.has($model$$.schema.paths,"ngay_ct")&&$obj$jscomp$0$$.ngay_ct?OptionsModel.findOne({id_app:$obj$jscomp$0$$.id_app,id_func:$ctrl$$.name},{option:1}).lean().exec(($e$jscomp$1$$,$rs$jscomp$0$$)=>{setImmediate(()=>{if($rs$jscomp$0$$&&
194
- $rs$jscomp$0$$.option&&$rs$jscomp$0$$.option.check_so_ct&&"0"!==$rs$jscomp$0$$.option.check_so_ct){let $query_check$$={id_app:$obj$jscomp$0$$.id_app,so_ct:$obj$jscomp$0$$.so_ct},$tu_ngay$$,$den_ngay$$;switch($rs$jscomp$0$$.option.check_so_ct){case "1":$tu_ngay$$=moment($obj$jscomp$0$$.ngay_ct).startOf("day").toDate();$den_ngay$$=moment($obj$jscomp$0$$.ngay_ct).endOf("day").toDate();$query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$den_ngay$$};break;case "2":$tu_ngay$$=moment($obj$jscomp$0$$.ngay_ct).startOf("month").toDate();
195
- $den_ngay$$=moment($obj$jscomp$0$$.ngay_ct).endOf("month").toDate();$query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$den_ngay$$};break;case "3":$tu_ngay$$=moment($obj$jscomp$0$$.ngay_ct).startOf("quarter").toDate();$den_ngay$$=moment($obj$jscomp$0$$.ngay_ct).endOf("quarter").toDate();$query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$den_ngay$$};break;case "8":$tu_ngay$$=moment($obj$jscomp$0$$.ngay_ct).startOf("year").toDate(),$den_ngay$$=moment($obj$jscomp$0$$.ngay_ct).endOf("year").toDate(),$query_check$$.ngay_ct=
196
- {$gte:$tu_ngay$$,$lte:$den_ngay$$}}$model$$.findOne($query_check$$,{so_ct:1}).lean().exec(($e$jscomp$0$$,$rs$$)=>{setImmediate(()=>{if($rs$$){let $msgError$$="S\u1ed1 ch\u1ee9ng t\u1eeb "+$obj$jscomp$0$$.so_ct+" \u0111\u00e3 t\u1ed3n t\u1ea1i. H\u00e3y ch\u1ecdn m\u1ed9t s\u1ed1 ch\u1ee9ng t\u1eeb kh\u00e1c";if($ctrl$$.options.onErrorCreating)$ctrl$$.options.onErrorCreating($user$jscomp$0$$,$obj$jscomp$0$$,$e$$=>{$e$$&&($msgError$$=$msgError$$+"\n"+$e$$);$callback$$($msgError$$)});else $callback$$($msgError$$)}else $callback$$()})})}else $callback$$()})}):
197
- $callback$$()};let $File$$=global.getModel("file"),$Support$$=global.getModel("support");async.waterfall([function($callback$$){setImmediate(function(){permission.hasRight($obj$jscomp$0$$.id_app,$user$jscomp$0$$.email,$ctrl$$.module,"add",function($error$jscomp$0$$,$hr$$,$c_app$$){setImmediate(()=>{if($error$jscomp$0$$||!$hr$$)return $callback$$($error$jscomp$0$$);$ctrl$$.checkData($c_app$$,$obj$jscomp$0$$,$e$$=>{if($e$$)return $callback$$($e$$);$ctrl$$.creating?$ctrl$$.creating($user$jscomp$0$$,
198
- $obj$jscomp$0$$,function($error$$){if($error$$)return $callback$$($error$$);$callback$$()},{data:$data$$}):$callback$$()})})},{data:$obj$jscomp$0$$,notNeedRight:$ctrl$$.options.notNeedRight})})},$callback$$=>{setImmediate(()=>{var $condition_qct$jscomp$1_ma_ct$$=$ctrl$$.name;$condition_qct$jscomp$1_ma_ct$$={status:!0,id_app:$obj$jscomp$0$$.id_app,$and:[{$or:[{ma_ct:"#",ma_ct_khac:{$regex:$condition_qct$jscomp$1_ma_ct$$,$options:"i"}},{cac_ma_ct:$condition_qct$jscomp$1_ma_ct$$.toLowerCase()},{ma_ct:$condition_qct$jscomp$1_ma_ct$$.toUpperCase()}]}]};
199
- let $_options_qct$$;$_options_qct$$=$obj$jscomp$0$$.toObject?$obj$jscomp$0$$.toObject():{...$obj$jscomp$0$$};let $keys_options$$=Object.keys($_options_qct$$);dmqct.find($condition_qct$jscomp$1_ma_ct$$).lean().exec(($e$jscomp$0$$,$rs$jscomp$0$$)=>{setImmediate(()=>{let $qcts$$=($rs$jscomp$0$$||[]).filter($qct$$=>"so_ct"!==$qct$$.field&&!$obj$jscomp$0$$[$qct$$.field]&&underscore.has($model$$.schema.paths,$qct$$.field));$qcts$$=$qcts$$.filter($qct$$=>{if($qct$$.dieu_kien&&0<$keys_options$$.length)try{let $str_func$$=
200
- $qct$$.dieu_kien;0!==$str_func$$.indexOf("return ")&&($str_func$$=`return ${$str_func$$}`);return 0<$str_func$$.indexOf("async ")?!1:evalute($str_func$$,{...$_options_qct$$,master:{...$_options_qct$$},moment,numeral})}catch($e$$){return console.error("Error find quyen chung tu",$e$$.message,$qct$$.dieu_kien),!1}else return!0});async.map($qcts$$,($qct$$,$cb$$)=>{setImmediate(()=>{let $field$$=$qct$$.field,$_options$$={...$_options_qct$$};$_options$$.id_qct=$qct$$._id.toString();getNextSequence($obj$jscomp$0$$.id_app,
201
- $ctrl$$.name,$field$$,function($e$$,$rs$$){if($e$$)return $cb$$();$obj$jscomp$0$$[$field$$]=$rs$$[$field$$];$cb$$()},$_options$$)})},()=>{setImmediate(()=>{$callback$$()})})})})})},$callback$jscomp$0$$=>{setImmediate(function(){if(!0===underscore.has($model$$.schema.paths,"so_ct"))if($obj$jscomp$0$$.so_ct&&$obj$jscomp$0$$.so_ct.toUpperCase()!==$ctrl$$.name.toUpperCase())$checkVoucherNumber$$($error$$=>{$callback$jscomp$0$$($error$$)});else{let $count$$=0;async.whilst(function($cb$$){$cb$$(null,10>
202
- $count$$)},function($callback$$){getNextSequence($obj$jscomp$0$$.id_app,$ctrl$$.name,"so_ct",function($e$$,$rs$$){setImmediate(()=>{if($e$$)return $callback$$($e$$);$obj$jscomp$0$$.so_ct=$rs$$.so_ct;$checkVoucherNumber$$($error$$=>{$error$$?9<=$count$$?$callback$$($error$$):($count$$++,$callback$$()):($count$$=99999,$callback$$())})})},$obj$jscomp$0$$)},function($err$$){$callback$jscomp$0$$($err$$)})}else $callback$jscomp$0$$()})},function($callback$$){setImmediate(async()=>{if(underscore.has($model$$.schema.paths,
203
- "ma_dvcs")&&"dvcs"!==$ctrl$$.name)if($obj$jscomp$0$$.ma_dvcs)if(global.mongoose.Types.ObjectId.isValid($obj$jscomp$0$$.ma_dvcs)){let $_id_dvcs$$=global.mongoose.Types.ObjectId($obj$jscomp$0$$.ma_dvcs);await dvcs.findOne({_id:$_id_dvcs$$})?$callback$$():dvcs.create({_id:$_id_dvcs$$,ma_dvcs:"IMPORTED",ten_dvcs:"Imported"},$e$$=>{setImmediate(()=>{$e$$&&console.error("Can't import dvcs",$e$$);$callback$$()})})}else $callback$$();else dvcs.findOne({id_app:$obj$jscomp$0$$.id_app,status:!0}).lean().exec(function($e$$,
204
- $rs$$){setImmediate(()=>{$rs$$&&($obj$jscomp$0$$.ma_dvcs=$rs$$._id.toString());$callback$$()})});else $callback$$()})},$callback$$=>{$ctrl$$.validating||($ctrl$$.validating=($user$$,$obj$$,$next$$)=>{$next$$(null,$obj$$)});$ctrl$$.validating($user$jscomp$0$$,$obj$jscomp$0$$,($e$jscomp$0$$,$obj$$)=>{if($e$jscomp$0$$)return $callback$$($e$jscomp$0$$);setImmediate(()=>{$obj$$.user_created=$user$jscomp$0$$.email;$obj$$.user_updated=$user$jscomp$0$$.email;validate($obj$$,async $error$$=>{setImmediate(async()=>
205
- {if($error$$){let $msgError$$=$error$$;if($ctrl$$.options.onErrorCreating)$ctrl$$.options.onErrorCreating($user$jscomp$0$$,$obj$$,$e$$=>{$e$$&&($msgError$$=$msgError$$+"\n"+$e$$);$callback$$($msgError$$)});else $callback$$($msgError$$)}else{if($id_be_supply_by_user$$&&global.mongoose.Types.ObjectId.isValid($id_be_supply_by_user$$)){let $_id$$=global.mongoose.Types.ObjectId($id_be_supply_by_user$$);$obj$$._id=$_id$$;await $model$$.deleteOne({_id:$_id$$})}$callback$$()}})})})})},function($callback$$){setImmediate(function(){isExists($model$$,
206
- $ctrl$$.unique,$obj$jscomp$0$$,$ctrl$$.replaceIfExists,async($error$jscomp$1$$,$kq$$)=>{setImmediate(async()=>{if($error$jscomp$1$$||$kq$$){let $msgError$$=$error$jscomp$1$$||ERR_ALREADY_EXIST;console.error($msgError$$,$obj$jscomp$0$$);if($ctrl$$.options.onErrorCreating)$ctrl$$.options.onErrorCreating($user$jscomp$0$$,$obj$jscomp$0$$,$e$$=>{$e$$&&($msgError$$=$msgError$$+"\n"+$e$$);$callback$$({error:$msgError$$,code:ERR_ALREADY_EXIST_CODE})});else $callback$$({error:$msgError$$,code:ERR_ALREADY_EXIST_CODE})}else{for(let $k$$ in $ctrl$$.keyValues)$obj$jscomp$0$$[$k$$]=
207
- $ctrl$$.keyValues[$k$$];Object.keys($model$$.schema.paths).filter($model_path$$=>$obj$jscomp$0$$[$model_path$$]&&underscore.isArray($obj$jscomp$0$$[$model_path$$])).forEach($model_path$$=>{$model$$.schema.paths[$model_path$$].schema&&$model$$.schema.paths[$model_path$$].schema.paths&&Object.keys($model$$.schema.paths[$model_path$$].schema.paths).filter($path$$=>"line"!==$path$$&&"_id"!==$path$$&&"__v"!==$path$$&&0<=fields_sync_master_detail.indexOf($path$$)).forEach($path$$=>{$obj$jscomp$0$$[$path$$]&&
208
- $obj$jscomp$0$$[$model_path$$].filter($detail$$=>!$detail$$[$path$$]).forEach($detail$$=>{$detail$$[$path$$]=$obj$jscomp$0$$[$path$$]})})});await createIdRef($model$$,$obj$jscomp$0$$);$ctrl$$.saving&&await $ctrl$$.saving($user$jscomp$0$$,$obj$jscomp$0$$);$ctrl$$.emit("saving",$obj$jscomp$0$$);$obj$jscomp$0$$.save(function($error$jscomp$0$$,$obj_created$$){setImmediate(()=>{if($error$jscomp$0$$){let $msgErrors$$=[];for(let $k$$ in $error$jscomp$0$$.errors)$msgErrors$$.push($error$jscomp$0$$.errors[$k$$].message);
209
- 0==$msgErrors$$.length&&($msgErrors$$=$error$jscomp$0$$.message);$msgErrors$$||($msgErrors$$=JSON.stringify($error$jscomp$0$$));if($ctrl$$.options.onErrorCreating)$ctrl$$.options.onErrorCreating($user$jscomp$0$$,$obj$jscomp$0$$,$e$$=>{$e$$&&console.error($e$$);$callback$$($msgErrors$$)});else $callback$$($msgErrors$$)}else postData($obj_created$$,$ctrl$$,function($msgErrors$$){setImmediate(()=>{if($msgErrors$$)if($model$$.deleteOne({_id:$obj_created$$._id.toString()},$err$$=>{$err$$&&console.error("Error remove obj when has error post data:",
210
- $err$$,{_id:$obj_created$$._id.toString()})}),$ctrl$$.options.onErrorCreating)$ctrl$$.options.onErrorCreating($user$jscomp$0$$,$obj$jscomp$0$$,$e$$=>{$e$$&&($msgErrors$$=$msgErrors$$+"\n"+$e$$);$callback$$($msgErrors$$)});else $callback$$($msgErrors$$);else if($req$$&&$req$$.header&&setImmediate(()=>{log.create({id_app:$user$jscomp$0$$.current_id_app,id_func:$ctrl$$.name,action:"ADD",data:{id:$obj$jscomp$0$$._id.toString(),data:$obj$jscomp$0$$}},$user$jscomp$0$$.email,$req$$.header("user-agent"),
211
- $req$$)}),$ctrl$$.emit("saved",$obj_created$$),$ctrl$$.emit("created",$obj_created$$),$obj_created$$=$obj_created$$.toObject(),runWebhooks($ctrl$$,$obj_created$$,"ADD",$voucher_options$$),$req$$&&pushNotification($ctrl$$,$obj_created$$,"new",null,null,{exclude_token:($req$$.query||{}).access_token}),$ctrl$$.cacheData($obj_created$$),$req$$&&!1!==($req$$.query||{}).return_data)$ctrl$$.onView($user$jscomp$0$$,[$obj_created$$],$error$$=>{setImmediate(()=>{if($error$$)return $callback$$($error$$);$callback$$(null,
212
- $obj_created$$)})},{req:$req$$});else $callback$$(null,{_id:$obj_created$$._id.toString()})})})})})}})})})},function($obj$$,$callback$$){$ctrl$$.requestApprove($user$jscomp$0$$.current_app_info,$user$jscomp$0$$,$obj$$,$callback$$,$voucher_options$$)},function($obj$$,$callback$$){setImmediate(function(){$obj$$.collection_name=$ctrl$$.collection_name;$obj$$.exfields&&$obj$$.exfields.__files__&&($obj$$.exfields.__files__.forEach($_file$$=>{$File$$.findOneAndUpdate({_id:$_file$$._id},{id_link:$obj$$._id.toString(),
213
- collection_link:$ctrl$$.collection_name}).lean().exec($e$$=>{$e$$&&console.error($e$$)})}),delete $obj$$.exfields.__files__);$obj$$.exfields&&$obj$$.exfields.__supports__&&($obj$$.exfields.__supports__.forEach($_file$$=>{$Support$$.findOneAndUpdate({_id:$_file$$._id},{id_link:$obj$$._id.toString(),collection_link:$ctrl$$.collection_name}).lean().exec($e$$=>{console.error($e$$)})}),delete $obj$$.exfields.__supports__);if($ctrl$$.created)$ctrl$$.created($user$jscomp$0$$,$obj$$,function($error$$,$rs$$){setImmediate(()=>
214
- {if($error$$)return $callback$$($error$$);if($req$$&&$req$$.uploadFile){let $html$$="<html><title>OK</title><body>"+JSON.stringify($rs$$)+"</body></html>";$callback$$(null,$html$$)}else $callback$$(null,$rs$$)})});else if($req$$&&$req$$.uploadFile){let $html$$="<html><title>OK</title><body>"+JSON.stringify($obj$$)+"</body></html>";$callback$$(null,$html$$)}else $callback$$(null,$obj$$)})}],($e$jscomp$143_name_cached$$,$rs$$)=>{$e$jscomp$143_name_cached$$?(console.error($e$jscomp$143_name_cached$$),
215
- $callback$jscomp$1$$($e$jscomp$143_name_cached$$)):($e$jscomp$143_name_cached$$=$model$$.collection.name,$user$jscomp$0$$.current_id_app&&($e$jscomp$143_name_cached$$+=$user$jscomp$0$$.current_id_app),delete global.cacheDatas[$e$jscomp$143_name_cached$$],$callback$jscomp$1$$(null,$rs$$))})}catch($e$$){console.error($e$$),$callback$jscomp$1$$($e$$)}}
192
+ $requireOtp$$&&_.isFunction($requireOtp$$)&&($requireOtp$$=$requireOtp$$($v_data$$,{action:"create",user:$user$jscomp$0$$}));if($requireOtp$$)try{await permission.verifyOTP($user$jscomp$0$$.email,$v_data$$["otp-id"],$v_data$$["otp-code"])}catch($e$$){return $callback$jscomp$1$$({error:$e$$.message||$e$$.error||$e$$,code:ERR_VERIFY_OTP})}}if($ctrl$$.dynamicCreating)try{$v_data$$=await new Promise(($resolve$$,$reject$$)=>{try{$ctrl$$.dynamicCreating($user$jscomp$0$$,$v_data$$,function($error$$,$v_data$$){if($error$$)return $reject$$($error$$);
193
+ $resolve$$($v_data$$)})}catch($e$$){return $reject$$($e$$)}})}catch($e$$){return $callback$jscomp$1$$($e$$.message||$e$$.error||$e$$)}const $obj$jscomp$0$$=new $model$$;underscore.has($schema_paths$$,"exfields")&&($obj$jscomp$0$$.exfields=$v_data$$.exfields||{});for(let $f$$ in $v_data$$)underscore.has($schema_paths$$,$f$$)&&($obj$jscomp$0$$.set($f$$,$v_data$$[$f$$]),"exfields"!==$f$$||$obj$jscomp$0$$.exfields||($obj$jscomp$0$$.exfields={}));!0===underscore.has($schema_paths$$,"id_app")&&($obj$jscomp$0$$.id_app=
194
+ $user$jscomp$0$$.current_id_app);const $checkVoucherNumber$$=$callback$$=>{underscore.has($model$$.schema.paths,"ngay_ct")&&$obj$jscomp$0$$.ngay_ct?OptionsModel.findOne({id_app:$obj$jscomp$0$$.id_app,id_func:$ctrl$$.name},{option:1}).lean().exec(($e$jscomp$1$$,$rs$jscomp$0$$)=>{setImmediate(()=>{if($rs$jscomp$0$$&&$rs$jscomp$0$$.option&&$rs$jscomp$0$$.option.check_so_ct&&"0"!==$rs$jscomp$0$$.option.check_so_ct){let $query_check$$={id_app:$obj$jscomp$0$$.id_app,so_ct:$obj$jscomp$0$$.so_ct},$tu_ngay$$,
195
+ $den_ngay$$;switch($rs$jscomp$0$$.option.check_so_ct){case "1":$tu_ngay$$=moment($obj$jscomp$0$$.ngay_ct).startOf("day").toDate();$den_ngay$$=moment($obj$jscomp$0$$.ngay_ct).endOf("day").toDate();$query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$den_ngay$$};break;case "2":$tu_ngay$$=moment($obj$jscomp$0$$.ngay_ct).startOf("month").toDate();$den_ngay$$=moment($obj$jscomp$0$$.ngay_ct).endOf("month").toDate();$query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$den_ngay$$};break;case "3":$tu_ngay$$=moment($obj$jscomp$0$$.ngay_ct).startOf("quarter").toDate();
196
+ $den_ngay$$=moment($obj$jscomp$0$$.ngay_ct).endOf("quarter").toDate();$query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$den_ngay$$};break;case "8":$tu_ngay$$=moment($obj$jscomp$0$$.ngay_ct).startOf("year").toDate(),$den_ngay$$=moment($obj$jscomp$0$$.ngay_ct).endOf("year").toDate(),$query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$den_ngay$$}}$model$$.findOne($query_check$$,{so_ct:1}).lean().exec(($e$jscomp$0$$,$rs$$)=>{setImmediate(()=>{if($rs$$){let $msgError$$="S\u1ed1 ch\u1ee9ng t\u1eeb "+$obj$jscomp$0$$.so_ct+
197
+ " \u0111\u00e3 t\u1ed3n t\u1ea1i. H\u00e3y ch\u1ecdn m\u1ed9t s\u1ed1 ch\u1ee9ng t\u1eeb kh\u00e1c";if($ctrl$$.options.onErrorCreating)$ctrl$$.options.onErrorCreating($user$jscomp$0$$,$obj$jscomp$0$$,$e$$=>{$e$$&&($msgError$$=$msgError$$+"\n"+$e$$);$callback$$($msgError$$)});else $callback$$($msgError$$)}else $callback$$()})})}else $callback$$()})}):$callback$$()};let $File$$=global.getModel("file"),$Support$$=global.getModel("support");async.waterfall([function($callback$$){setImmediate(function(){permission.hasRight($obj$jscomp$0$$.id_app,
198
+ $user$jscomp$0$$.email,$ctrl$$.module,"add",function($error$jscomp$0$$,$hr$$,$c_app$$){setImmediate(()=>{if($error$jscomp$0$$||!$hr$$)return $callback$$($error$jscomp$0$$);$ctrl$$.checkData($c_app$$,$obj$jscomp$0$$,$e$$=>{if($e$$)return $callback$$($e$$);$ctrl$$.creating?$ctrl$$.creating($user$jscomp$0$$,$obj$jscomp$0$$,function($error$$,$obj$$){if($error$$)return $callback$$($error$$);$callback$$(null,$obj$$)},{data:$data$$}):$callback$$(null,$obj$jscomp$0$$)})})},{data:$obj$jscomp$0$$,notNeedRight:$ctrl$$.options.notNeedRight})})},
199
+ ($obj$$,$callback$$)=>{setImmediate(()=>{var $condition_qct$jscomp$1_ma_ct$$=$ctrl$$.name;$condition_qct$jscomp$1_ma_ct$$={status:!0,id_app:$obj$$.id_app,$and:[{$or:[{ma_ct:"#",ma_ct_khac:{$regex:$condition_qct$jscomp$1_ma_ct$$,$options:"i"}},{cac_ma_ct:$condition_qct$jscomp$1_ma_ct$$.toLowerCase()},{ma_ct:$condition_qct$jscomp$1_ma_ct$$.toUpperCase()}]}]};let $_options_qct$$;$_options_qct$$=$obj$$.toObject?$obj$$.toObject():{...$obj$$};let $keys_options$$=Object.keys($_options_qct$$);dmqct.find($condition_qct$jscomp$1_ma_ct$$).lean().exec(($e$jscomp$0$$,
200
+ $rs$jscomp$0$$)=>{setImmediate(()=>{let $qcts$$=($rs$jscomp$0$$||[]).filter($qct$$=>"so_ct"!==$qct$$.field&&!$obj$$[$qct$$.field]&&underscore.has($model$$.schema.paths,$qct$$.field));$qcts$$=$qcts$$.filter($qct$$=>{if($qct$$.dieu_kien&&0<$keys_options$$.length)try{let $str_func$$=$qct$$.dieu_kien;0!==$str_func$$.indexOf("return ")&&($str_func$$=`return ${$str_func$$}`);return 0<$str_func$$.indexOf("async ")?!1:evalute($str_func$$,{...$_options_qct$$,master:{...$_options_qct$$},moment,numeral})}catch($e$$){return console.error("Error find quyen chung tu",
201
+ $e$$.message,$qct$$.dieu_kien),!1}else return!0});async.map($qcts$$,($qct$$,$cb$$)=>{setImmediate(()=>{let $field$$=$qct$$.field,$_options$$={...$_options_qct$$};$_options$$.id_qct=$qct$$._id.toString();getNextSequence($obj$$.id_app,$ctrl$$.name,$field$$,function($e$$,$rs$$){if($e$$)return $cb$$();$obj$$[$field$$]=$rs$$[$field$$];$cb$$()},$_options$$)})},()=>{setImmediate(()=>{$callback$$()})})})})})},$callback$jscomp$0$$=>{setImmediate(function(){if(!0===underscore.has($model$$.schema.paths,"so_ct"))if($obj$jscomp$0$$.so_ct&&
202
+ $obj$jscomp$0$$.so_ct.toUpperCase()!==$ctrl$$.name.toUpperCase())$checkVoucherNumber$$($error$$=>{$callback$jscomp$0$$($error$$)});else{let $count$$=0;async.whilst(function($cb$$){$cb$$(null,10>$count$$)},function($callback$$){getNextSequence($obj$jscomp$0$$.id_app,$ctrl$$.name,"so_ct",function($e$$,$rs$$){setImmediate(()=>{if($e$$)return $callback$$($e$$);$obj$jscomp$0$$.so_ct=$rs$$.so_ct;$checkVoucherNumber$$($error$$=>{$error$$?9<=$count$$?$callback$$($error$$):($count$$++,$callback$$()):($count$$=
203
+ 99999,$callback$$())})})},$obj$jscomp$0$$)},function($err$$){$callback$jscomp$0$$($err$$)})}else $callback$jscomp$0$$()})},function($callback$$){setImmediate(async()=>{if(underscore.has($model$$.schema.paths,"ma_dvcs")&&"dvcs"!==$ctrl$$.name)if($obj$jscomp$0$$.ma_dvcs)if(global.mongoose.Types.ObjectId.isValid($obj$jscomp$0$$.ma_dvcs)){let $_id_dvcs$$=global.mongoose.Types.ObjectId($obj$jscomp$0$$.ma_dvcs);await dvcs.findOne({_id:$_id_dvcs$$})?$callback$$():dvcs.create({_id:$_id_dvcs$$,ma_dvcs:"IMPORTED",
204
+ ten_dvcs:"Imported"},$e$$=>{setImmediate(()=>{$e$$&&console.error("Can't import dvcs",$e$$);$callback$$()})})}else $callback$$();else dvcs.findOne({id_app:$obj$jscomp$0$$.id_app,status:!0}).lean().exec(function($e$$,$rs$$){setImmediate(()=>{$rs$$&&($obj$jscomp$0$$.ma_dvcs=$rs$$._id.toString());$callback$$()})});else $callback$$()})},$callback$$=>{$ctrl$$.validating||($ctrl$$.validating=($user$$,$obj$$,$next$$)=>{$next$$(null,$obj$$)});$ctrl$$.validating($user$jscomp$0$$,$obj$jscomp$0$$,($e$jscomp$0$$,
205
+ $obj$$)=>{if($e$jscomp$0$$)return $callback$$($e$jscomp$0$$);setImmediate(()=>{$obj$$.user_created=$user$jscomp$0$$.email;$obj$$.user_updated=$user$jscomp$0$$.email;validate($obj$$,async $error$$=>{setImmediate(async()=>{if($error$$){let $msgError$$=$error$$;if($ctrl$$.options.onErrorCreating)$ctrl$$.options.onErrorCreating($user$jscomp$0$$,$obj$$,$e$$=>{$e$$&&($msgError$$=$msgError$$+"\n"+$e$$);$callback$$($msgError$$)});else $callback$$($msgError$$)}else{if($id_be_supply_by_user$$&&global.mongoose.Types.ObjectId.isValid($id_be_supply_by_user$$)){let $_id$$=
206
+ global.mongoose.Types.ObjectId($id_be_supply_by_user$$);$obj$$._id=$_id$$;await $model$$.deleteOne({_id:$_id$$})}$callback$$()}})})})})},function($callback$$){setImmediate(function(){isExists($model$$,$ctrl$$.unique,$obj$jscomp$0$$,$ctrl$$.replaceIfExists,async($error$jscomp$1$$,$kq$$)=>{setImmediate(async()=>{if($error$jscomp$1$$||$kq$$){let $msgError$$=$error$jscomp$1$$||ERR_ALREADY_EXIST;console.error($msgError$$,$obj$jscomp$0$$);if($ctrl$$.options.onErrorCreating)$ctrl$$.options.onErrorCreating($user$jscomp$0$$,
207
+ $obj$jscomp$0$$,$e$$=>{$e$$&&($msgError$$=$msgError$$+"\n"+$e$$);$callback$$({error:$msgError$$,code:ERR_ALREADY_EXIST_CODE})});else $callback$$({error:$msgError$$,code:ERR_ALREADY_EXIST_CODE})}else{for(let $k$$ in $ctrl$$.keyValues)$obj$jscomp$0$$[$k$$]=$ctrl$$.keyValues[$k$$];Object.keys($model$$.schema.paths).filter($model_path$$=>$obj$jscomp$0$$[$model_path$$]&&underscore.isArray($obj$jscomp$0$$[$model_path$$])).forEach($model_path$$=>{$model$$.schema.paths[$model_path$$].schema&&$model$$.schema.paths[$model_path$$].schema.paths&&
208
+ Object.keys($model$$.schema.paths[$model_path$$].schema.paths).filter($path$$=>"line"!==$path$$&&"_id"!==$path$$&&"__v"!==$path$$&&0<=fields_sync_master_detail.indexOf($path$$)).forEach($path$$=>{$obj$jscomp$0$$[$path$$]&&$obj$jscomp$0$$[$model_path$$].filter($detail$$=>!$detail$$[$path$$]).forEach($detail$$=>{$detail$$[$path$$]=$obj$jscomp$0$$[$path$$]})})});await createIdRef($model$$,$obj$jscomp$0$$);$ctrl$$.saving&&await $ctrl$$.saving($user$jscomp$0$$,$obj$jscomp$0$$);$ctrl$$.emit("saving",$obj$jscomp$0$$);
209
+ $obj$jscomp$0$$.save(function($error$jscomp$0$$,$obj_created$$){setImmediate(()=>{if($error$jscomp$0$$){let $msgErrors$$=[];for(let $k$$ in $error$jscomp$0$$.errors)$msgErrors$$.push($error$jscomp$0$$.errors[$k$$].message);0==$msgErrors$$.length&&($msgErrors$$=$error$jscomp$0$$.message);$msgErrors$$||($msgErrors$$=JSON.stringify($error$jscomp$0$$));if($ctrl$$.options.onErrorCreating)$ctrl$$.options.onErrorCreating($user$jscomp$0$$,$obj$jscomp$0$$,$e$$=>{$e$$&&console.error($e$$);$callback$$($msgErrors$$)});
210
+ else $callback$$($msgErrors$$)}else postData($obj_created$$,$ctrl$$,function($msgErrors$$){setImmediate(()=>{if($msgErrors$$)if($model$$.deleteOne({_id:$obj_created$$._id.toString()},$err$$=>{$err$$&&console.error("Error remove obj when has error post data:",$err$$,{_id:$obj_created$$._id.toString()})}),$ctrl$$.options.onErrorCreating)$ctrl$$.options.onErrorCreating($user$jscomp$0$$,$obj$jscomp$0$$,$e$$=>{$e$$&&($msgErrors$$=$msgErrors$$+"\n"+$e$$);$callback$$($msgErrors$$)});else $callback$$($msgErrors$$);
211
+ else if($req$$&&$req$$.header&&setImmediate(()=>{log.create({id_app:$user$jscomp$0$$.current_id_app,id_func:$ctrl$$.name,action:"ADD",data:{id:$obj$jscomp$0$$._id.toString(),data:$obj$jscomp$0$$}},$user$jscomp$0$$.email,$req$$.header("user-agent"),$req$$)}),$ctrl$$.emit("saved",$obj_created$$),$ctrl$$.emit("created",$obj_created$$),$obj_created$$=$obj_created$$.toObject(),runWebhooks($ctrl$$,$obj_created$$,"ADD",$voucher_options$$),$req$$&&pushNotification($ctrl$$,$obj_created$$,"new",null,null,{exclude_token:($req$$.query||
212
+ {}).access_token}),$ctrl$$.cacheData($obj_created$$),$req$$&&!1!==($req$$.query||{}).return_data)$ctrl$$.onView($user$jscomp$0$$,[$obj_created$$],$error$$=>{setImmediate(()=>{if($error$$)return $callback$$($error$$);$callback$$(null,$obj_created$$)})},{req:$req$$});else $callback$$(null,{_id:$obj_created$$._id.toString()})})})})})}})})})},function($obj$$,$callback$$){$ctrl$$.requestApprove($user$jscomp$0$$.current_app_info,$user$jscomp$0$$,$obj$$,$callback$$,$voucher_options$$)},function($obj$$,$callback$$){setImmediate(function(){$obj$$.collection_name=
213
+ $ctrl$$.collection_name;$obj$$.exfields&&$obj$$.exfields.__files__&&($obj$$.exfields.__files__.forEach($_file$$=>{$File$$.findOneAndUpdate({_id:$_file$$._id},{id_link:$obj$$._id.toString(),collection_link:$ctrl$$.collection_name}).lean().exec($e$$=>{$e$$&&console.error($e$$)})}),delete $obj$$.exfields.__files__);$obj$$.exfields&&$obj$$.exfields.__supports__&&($obj$$.exfields.__supports__.forEach($_file$$=>{$Support$$.findOneAndUpdate({_id:$_file$$._id},{id_link:$obj$$._id.toString(),collection_link:$ctrl$$.collection_name}).lean().exec($e$$=>
214
+ {console.error($e$$)})}),delete $obj$$.exfields.__supports__);if($ctrl$$.created)$ctrl$$.created($user$jscomp$0$$,$obj$$,function($error$jscomp$0$$,$rs$$){setImmediate(()=>{if($error$jscomp$0$$)return $callback$$($error$jscomp$0$$);if($ctrl$$.dynamicCreated)$ctrl$$.dynamicCreated($user$jscomp$0$$,$rs$$,function($error$$){if($error$$)return $callback$$($error$$);$req$$&&$req$$.uploadFile?($error$$="<html><title>OK</title><body>"+JSON.stringify($rs$$)+"</body></html>",$callback$$(null,$error$$)):$callback$$(null,
215
+ $rs$$)});else if($req$$&&$req$$.uploadFile){let $html$$="<html><title>OK</title><body>"+JSON.stringify($rs$$)+"</body></html>";$callback$$(null,$html$$)}else $callback$$(null,$rs$$)})});else if($ctrl$$.dynamicCreated)$ctrl$$.dynamicCreated($user$jscomp$0$$,$obj$$,function($error$jscomp$46_html$$){if($error$jscomp$46_html$$)return $callback$$($error$jscomp$46_html$$);$req$$&&$req$$.uploadFile?($error$jscomp$46_html$$="<html><title>OK</title><body>"+JSON.stringify($obj$$)+"</body></html>",$callback$$(null,
216
+ $error$jscomp$46_html$$)):$callback$$(null,$obj$$)});else if($req$$&&$req$$.uploadFile){let $html$$="<html><title>OK</title><body>"+JSON.stringify($obj$$)+"</body></html>";$callback$$(null,$html$$)}else $callback$$(null,$obj$$)})}],($e$jscomp$145_name_cached$$,$rs$$)=>{$e$jscomp$145_name_cached$$?(console.error($e$jscomp$145_name_cached$$),$callback$jscomp$1$$($e$jscomp$145_name_cached$$)):($e$jscomp$145_name_cached$$=$model$$.collection.name,$user$jscomp$0$$.current_id_app&&($e$jscomp$145_name_cached$$+=
217
+ $user$jscomp$0$$.current_id_app),delete global.cacheDatas[$e$jscomp$145_name_cached$$],$callback$jscomp$1$$(null,$rs$$))})}catch($e$$){console.error($e$$),$callback$jscomp$1$$($e$$)}}
216
218
  controller.prototype.create=function(){let $name$$=this.name,$ctrl$$=this;this.router.route(this.route_name).post(function($req$$,$res$$){let $session$$=$req$$.session;if(!0===$session$$["creating_"+$name$$])return $res$$.status(400).send({error:"\u0110ang x\u1eed l\u00fd d\u1eef li\u1ec7u"});$session$$["creating_"+$name$$]=!0;let $body$$=$req$$.body;if(!$body$$)return $res$$.status(411).send({error:"Kh\u00f4ng c\u00f3 n\u1ed9i dung c\u1ea7n l\u01b0u"});$req$$.files&&0<underscore.keys($req$$.files).length&&
217
219
  ("JSON"!=$body$$.return&&($req$$.uploadFile=!0),underscore.extend($body$$,$req$$.files));create($req$$.user,$ctrl$$,$body$$,($e$$,$rs$$)=>{setImmediate(()=>{$session$$["creating_"+$name$$]=!1;if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});!1===$req$$.query.return_data?$res$$.send({_id:$rs$$._id.toString()}):$res$$.send($rs$$)})},null,$req$$)})};
218
220
  controller.prototype.quickCreate=function(){let $model$$=this.model,$name$$=this.name,$ctrl$$=this,$createFromTemplate$$=async($req$$,$res$$,$body$jscomp$4_query$$)=>{let $session$$=$req$$.session;if(!0===$session$$["creating_"+$name$$])return $res$$.status(400).send({error:"\u0110ang x\u1eed l\u00fd d\u1eef li\u1ec7u"});$session$$["creating_"+$name$$]=!0;if(!$body$jscomp$4_query$$){$body$jscomp$4_query$$=$req$$.params.template_code;if(!$body$jscomp$4_query$$)return $session$$["creating_"+$name$$]=
@@ -220,41 +222,43 @@ controller.prototype.quickCreate=function(){let $model$$=this.model,$name$$=this
220
222
  {};delete $body$jscomp$4_query$$.so_ct;delete $body$jscomp$4_query$$.ngay_ct;delete $body$jscomp$4_query$$.user_created;delete $body$jscomp$4_query$$.date_created;delete $body$jscomp$4_query$$.user_updated;delete $body$jscomp$4_query$$.date_updated;delete $body$jscomp$4_query$$._id;delete $body$jscomp$4_query$$.pkey;delete $body$jscomp$4_query$$.__v;let $_data$$=$req$$.query;$req$$.body&&($_data$$=Object.assign($_data$$,$req$$.body));for(let $key$$ in $_data$$)$_data$$[$key$$]&&"access_token"!==$key$$&&
221
223
  "token"!==$key$$&&"_id"!==$key$$&&(underscore.has($model$$.schema.paths,$key$$)&&($body$jscomp$4_query$$[$key$$]=$_data$$[$key$$]),$body$jscomp$4_query$$.details&&$body$jscomp$4_query$$.details.forEach($d$$=>{$d$$[$key$$]=$_data$$[$key$$]}));create($req$$.user,$ctrl$$,$body$jscomp$4_query$$,($e$$,$rs$$)=>{setImmediate(()=>{$session$$["creating_"+$name$$]=!1;if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});$res$$.send($rs$$)})},
222
224
  null,$req$$)};this.router.route(`${this.route_name}/quickcreate/:template_code`).get(function($req$$,$res$$){$createFromTemplate$$($req$$,$res$$)});this.router.route(`${this.route_name}/quickcreate/:template_code`).post(function($req$$,$res$$){$createFromTemplate$$($req$$,$res$$)})};
223
- const update=async function($user$jscomp$0$$,$ctrl$$,$id$$,$data$jscomp$0$$,$callback$jscomp$1$$,$action$jscomp$0$$,$req$$){delete $data$jscomp$0$$.__v;try{const $model$$=$ctrl$$.model,$unique$$=$ctrl$$.unique,$module$$=$ctrl$$.module,$schema_paths$$=$model$$.schema.paths;underscore.has($schema_paths$$,"ma_ct")&&$ctrl$$.options.isVoucher&&($data$jscomp$0$$.ma_ct=$ctrl$$.name.toUpperCase());const $voucher_options$$=(await OptionsModel.findOne({id_app:$user$jscomp$0$$.current_id_app,id_func:$ctrl$$.name}).lean()||
224
- {}).option;let $current_obj$$;if($ctrl$$.options.requireRecaptchaToken){if(!$data$jscomp$0$$["g-recaptcha-response"])return $callback$jscomp$1$$("Ch\u1ee9c n\u0103ng n\u00e0y y\u00eau c\u1ea7u g-recaptcha-response");try{await permission.verifyReCaptcha($data$jscomp$0$$["g-recaptcha-response"])}catch($e$$){return $callback$jscomp$1$$($e$$.message||$e$$.error||$e$$)}}if(0>global.configs.admins.indexOf($user$jscomp$0$$.email)){let $requireOtp$$=$ctrl$$.options.requireOtp;$requireOtp$$&&_.isFunction($requireOtp$$)&&
225
- ($requireOtp$$=$requireOtp$$($data$jscomp$0$$,{action:"update",_id:$id$$,user:$user$jscomp$0$$}));if($requireOtp$$)try{await permission.verifyOTP($user$jscomp$0$$.email,$data$jscomp$0$$["otp-id"],$data$jscomp$0$$["otp-code"])}catch($e$$){return $callback$jscomp$1$$({error:$e$$.message||$e$$.error||$e$$,code:ERR_VERIFY_OTP})}}async.waterfall([function($callback$$){setImmediate(function(){$model$$.findOne({_id:$id$$}).exec(function($error$$,$obj$$){setImmediate(()=>{if($error$$)return $callback$$($error$$);
226
- if(!$obj$$)return $callback$$("Kh\u00f4ng th\u1ec3 t\u00ecm th\u1ea5y \u0111\u1ed1i t\u01b0\u1ee3ng n\u00e0y");underscore.has($schema_paths$$,"exfields")&&($obj$$.exfields=$obj$$.exfields||{});const $old_obj$$=$obj$$.toObject();$current_obj$$=_.cloneDeep($old_obj$$);const $data_keys$$=Object.keys($data$jscomp$0$$);for(let $key$$ in $old_obj$$)0>$data_keys$$.indexOf($key$$)&&($data$jscomp$0$$[$key$$]=$old_obj$$[$key$$]);$callback$$(null,$obj$$)})})})},function($obj$$,$callback$$){setImmediate(function(){permission.hasRight($user$jscomp$0$$.current_id_app,
227
- $user$jscomp$0$$.email,$module$$,"update",function($error$$,$hr$$,$c_app$$){setImmediate(()=>{if($hr$$)$ctrl$$.checkData($c_app$$,{...$data$jscomp$0$$,_id:$obj$$._id.toString()},$e$$=>{if($e$$)return $callback$$($e$$);$callback$$(null,$obj$$)});else return $callback$$({error:$error$$||ERR_NOT_PERMIT,code:ERR_NOT_PERMIT_CODE})})},{data:$data$jscomp$0$$,obj:$obj$$,notNeedRight:$ctrl$$.options.notNeedRight})})},function($obj$$,$callback$$){underscore.has($model$$.schema.paths,"ngay_ct")&&underscore.has($model$$.schema.paths,
228
- "so_ct")&&$obj$$.ngay_ct&&$data$jscomp$0$$.so_ct&&$obj$$.so_ct!==$data$jscomp$0$$.so_ct?OptionsModel.findOne({id_app:$obj$$.id_app,id_func:$ctrl$$.name},{option:1}).lean().exec(($e$jscomp$0$$,$rs$jscomp$0$$)=>{setImmediate(()=>{if($rs$jscomp$0$$&&$rs$jscomp$0$$.option&&$rs$jscomp$0$$.option.check_so_ct&&"0"!==$rs$jscomp$0$$.option.check_so_ct){let $query_check$$={id_app:$obj$$.id_app,so_ct:$data$jscomp$0$$.so_ct,_id:{$ne:$obj$$._id.toString()}},$tu_ngay$$;var $date_check_den_ngay$$=$data$jscomp$0$$.ngay_ct||
225
+ const update=async function($user$jscomp$0$$,$ctrl$$,$id$$,$data$jscomp$1$$,$callback$jscomp$1$$,$action$jscomp$0$$,$req$$){delete $data$jscomp$1$$.__v;try{const $model$$=$ctrl$$.model,$unique$$=$ctrl$$.unique,$module$$=$ctrl$$.module,$schema_paths$$=$model$$.schema.paths;underscore.has($schema_paths$$,"ma_ct")&&$ctrl$$.options.isVoucher&&($data$jscomp$1$$.ma_ct=$ctrl$$.name.toUpperCase());const $voucher_options$$=(await OptionsModel.findOne({id_app:$user$jscomp$0$$.current_id_app,id_func:$ctrl$$.name}).lean()||
226
+ {}).option;let $current_obj$$;if($ctrl$$.options.requireRecaptchaToken){if(!$data$jscomp$1$$["g-recaptcha-response"])return $callback$jscomp$1$$("Ch\u1ee9c n\u0103ng n\u00e0y y\u00eau c\u1ea7u g-recaptcha-response");try{await permission.verifyReCaptcha($data$jscomp$1$$["g-recaptcha-response"])}catch($e$$){return $callback$jscomp$1$$($e$$.message||$e$$.error||$e$$)}}if(0>global.configs.admins.indexOf($user$jscomp$0$$.email)){let $requireOtp$$=$ctrl$$.options.requireOtp;$requireOtp$$&&_.isFunction($requireOtp$$)&&
227
+ ($requireOtp$$=$requireOtp$$($data$jscomp$1$$,{action:"update",_id:$id$$,user:$user$jscomp$0$$}));if($requireOtp$$)try{await permission.verifyOTP($user$jscomp$0$$.email,$data$jscomp$1$$["otp-id"],$data$jscomp$1$$["otp-code"])}catch($e$$){return $callback$jscomp$1$$({error:$e$$.message||$e$$.error||$e$$,code:ERR_VERIFY_OTP})}}async.waterfall([function($callback$$){setImmediate(function(){$model$$.findOne({_id:$id$$}).exec(function($error$$,$obj$$){setImmediate(()=>{if($error$$)return $callback$$($error$$);
228
+ if(!$obj$$)return $callback$$("Kh\u00f4ng th\u1ec3 t\u00ecm th\u1ea5y \u0111\u1ed1i t\u01b0\u1ee3ng n\u00e0y");underscore.has($schema_paths$$,"exfields")&&($obj$$.exfields=$obj$$.exfields||{});const $old_obj$$=$obj$$.toObject();$current_obj$$=_.cloneDeep($old_obj$$);const $data_keys$$=Object.keys($data$jscomp$1$$);for(let $key$$ in $old_obj$$)0>$data_keys$$.indexOf($key$$)&&($data$jscomp$1$$[$key$$]=$old_obj$$[$key$$]);$callback$$(null,$obj$$)})})})},function($obj$$,$callback$$){setImmediate(function(){permission.hasRight($user$jscomp$0$$.current_id_app,
229
+ $user$jscomp$0$$.email,$module$$,"update",function($error$$,$hr$$,$c_app$$){setImmediate(()=>{if($hr$$)$ctrl$$.checkData($c_app$$,{...$data$jscomp$1$$,_id:$obj$$._id.toString()},$e$$=>{if($e$$)return $callback$$($e$$);$callback$$(null,$obj$$)});else return $callback$$({error:$error$$||ERR_NOT_PERMIT,code:ERR_NOT_PERMIT_CODE})})},{data:$data$jscomp$1$$,obj:$obj$$,notNeedRight:$ctrl$$.options.notNeedRight})})},function($obj$$,$callback$$){underscore.has($model$$.schema.paths,"ngay_ct")&&underscore.has($model$$.schema.paths,
230
+ "so_ct")&&$obj$$.ngay_ct&&$data$jscomp$1$$.so_ct&&$obj$$.so_ct!==$data$jscomp$1$$.so_ct?OptionsModel.findOne({id_app:$obj$$.id_app,id_func:$ctrl$$.name},{option:1}).lean().exec(($e$jscomp$0$$,$rs$jscomp$0$$)=>{setImmediate(()=>{if($rs$jscomp$0$$&&$rs$jscomp$0$$.option&&$rs$jscomp$0$$.option.check_so_ct&&"0"!==$rs$jscomp$0$$.option.check_so_ct){let $query_check$$={id_app:$obj$$.id_app,so_ct:$data$jscomp$1$$.so_ct,_id:{$ne:$obj$$._id.toString()}},$tu_ngay$$;var $date_check_den_ngay$$=$data$jscomp$1$$.ngay_ct||
229
231
  $obj$$.ngay_ct;switch($rs$jscomp$0$$.option.check_so_ct){case "1":$tu_ngay$$=moment($date_check_den_ngay$$).startOf("date").toDate();$date_check_den_ngay$$=moment($date_check_den_ngay$$).endOf("date").toDate();$query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$date_check_den_ngay$$};break;case "2":$tu_ngay$$=moment($date_check_den_ngay$$).startOf("month").toDate();$date_check_den_ngay$$=moment($date_check_den_ngay$$).endOf("month").toDate();$query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$date_check_den_ngay$$};
230
232
  break;case "3":$tu_ngay$$=moment($date_check_den_ngay$$).startOf("quarter").toDate();$date_check_den_ngay$$=moment($date_check_den_ngay$$).endOf("quarter").toDate();$query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$date_check_den_ngay$$};break;case "8":$tu_ngay$$=moment($date_check_den_ngay$$).startOf("year").toDate(),$date_check_den_ngay$$=moment($date_check_den_ngay$$).startOf("year").toDate(),$query_check$$.ngay_ct={$gte:$tu_ngay$$,$lte:$date_check_den_ngay$$}}$model$$.findOne($query_check$$,{so_ct:1}).lean().exec(($e$$,
231
- $rs$$)=>{setImmediate(()=>{if($rs$$)return $callback$$("S\u1ed1 ch\u1ee9ng t\u1eeb "+$data$jscomp$0$$.so_ct+" \u0111\u00e3 t\u1ed3n t\u1ea1i. H\u00e3y ch\u1ecdn m\u1ed9t s\u1ed1 ch\u1ee9ng t\u1eeb kh\u00e1c");$callback$$(null,$obj$$)})})}else $callback$$(null,$obj$$)})}):$callback$$(null,$obj$$)},($obj$jscomp$1$$,$callback$jscomp$0$$)=>{(async($obj$jscomp$0$$,$callback$$)=>{try{(await permission.getFieldNotRight($obj$jscomp$0$$.id_app,$user$jscomp$0$$.email,$ctrl$$.name)).forEach($f$$=>{delete $data$jscomp$0$$[$f$$]})}catch($e$$){console.error("Error get field not right",
232
- $e$$)}setImmediate(function(){$ctrl$$.updating?$ctrl$$.updating($user$jscomp$0$$,$data$jscomp$0$$,$obj$jscomp$0$$,function($error$$,$data$$,$obj$$){setImmediate(()=>{if($error$$)return $callback$$($error$$);$callback$$(null,$obj$$)})}):$callback$$(null,$obj$jscomp$0$$)})})($obj$jscomp$1$$,$callback$jscomp$0$$)},function($obj$$,$callback$$){setImmediate(function(){if(!$unique$$||0===$unique$$.length)return $callback$$(null,$obj$$);let $c1$$={},$c2$$={};$obj$$.id_app&&($c1$$.id_app=$obj$$.id_app,$c2$$.id_app||
233
- ($c2$$.id_app=$obj$$.id_app));$unique$$.forEach(function($key$$){$c1$$[$key$$]=$obj$$[$key$$];$ctrl$$.model.schema.paths[$key$$]?("number"==$ctrl$$.model.schema.paths[$key$$].instance.toLowerCase()?$c2$$[$key$$]=Number($data$jscomp$0$$[$key$$]):"date"==$ctrl$$.model.schema.paths[$key$$].instance.toLowerCase()?$c2$$[$key$$]=new Date($data$jscomp$0$$[$key$$]):"string"==$ctrl$$.model.schema.paths[$key$$].instance.toLowerCase()?$c2$$[$key$$]=($data$jscomp$0$$[$key$$]||"").toString():$c2$$[$key$$]=$data$jscomp$0$$[$key$$],
234
- $c2$$[$key$$]||($c2$$[$key$$]=$c1$$[$key$$])):console.error("field",$key$$," is not exist. please check unique of controller")});!0!==underscore.isEqual($c1$$,$c2$$)?isExists($model$$,$unique$$,$c2$$,$ctrl$$.replaceIfExists,function($error$jscomp$0$$,$kq$$){setImmediate(()=>{if($error$jscomp$0$$||$kq$$){let $msgError$$=$error$jscomp$0$$||ERR_ALREADY_EXIST;console.error($msgError$$,$c2$$);if($ctrl$$.options.onErrorUpdating)$ctrl$$.options.onErrorUpdating($user$jscomp$0$$,$obj$$,$e$$=>{$e$$&&($msgError$$=
235
- $msgError$$+"\n"+$e$$);$callback$$($msgError$$)},$current_obj$$);else $callback$$($msgError$$)}else checkReference($model$$,$obj$$,function($error$$){setImmediate(()=>{if($error$$)return console.error("Keys arise data",$c1$$,$c2$$,$error$$),$callback$$({error:ERR_KEY_ARISE+($error$$.error||$error$$.message||$error$$),code:ERR_KEY_ARISE_CODE});$callback$$(null,$obj$$)})},$unique$$)})}):$callback$$(null,$obj$$)})},function($obj$$,$callback$$){let $keys$$=underscore.keys($model$$.referenceKeys).filter($key$$=>
236
- "_id"!==$key$$);$unique$$&&($keys$$=$keys$$.filter($key$$=>0>$unique$$.indexOf($key$$).length));if(0===$keys$$.length)return $callback$$(null,$obj$$);checkReference($model$$,$obj$$,function($msgError$$){setImmediate(()=>{if($msgError$$)if($ctrl$$.options.onErrorUpdating)$ctrl$$.options.onErrorUpdating($user$jscomp$0$$,$obj$$,$e$$=>{$e$$&&($msgError$$=$msgError$$+"\n"+$e$$);$callback$$($msgError$$)},$current_obj$$);else $callback$$({error:ERR_ARISE+($msgError$$.error||$msgError$$.message||$msgError$$),
237
- code:ERR_ARISE_CODE});else $callback$$(null,$obj$$)})},$keys$$)},function($obj$jscomp$1$$,$callback$$){$ctrl$$.validating||($ctrl$$.validating=($user$$,$obj$$,$next$$)=>{$next$$(null,$obj$$)});$ctrl$$.validating($user$jscomp$0$$,$obj$jscomp$1$$,($error$$,$obj$jscomp$0$$)=>{if($error$$)return $callback$$($error$$);setImmediate(function(){$data$jscomp$0$$.date_updated=new Date;$data$jscomp$0$$.user_updated=$user$jscomp$0$$.email;delete $data$jscomp$0$$.__v;$ctrl$$.options.onUpdateExtending||($ctrl$$.options.onUpdateExtending=
238
- function($obj$$,$data$$,$action$$,$fn$$){$fn$$()});$ctrl$$.options.onUpdateExtending($obj$jscomp$0$$,$data$jscomp$0$$,$action$jscomp$0$$,function(){underscore.has($schema_paths$$,"exfields")&&$data$jscomp$0$$.exfields&&($obj$jscomp$0$$.exfields=$data$jscomp$0$$.exfields);for(let $f$$ in $data$jscomp$0$$)underscore.has($schema_paths$$,$f$$)&&($obj$jscomp$0$$.set($f$$,$data$jscomp$0$$[$f$$]),"exfields"!==$f$$||$obj$jscomp$0$$.exfields||($obj$jscomp$0$$.exfields={}));validate($obj$jscomp$0$$,function($msgError$$){setImmediate(()=>
239
- {if($msgError$$)if($ctrl$$.options.onErrorUpdating)$ctrl$$.options.onErrorUpdating($user$jscomp$0$$,$obj$jscomp$0$$,$e$$=>{$e$$&&($msgError$$=$msgError$$+"\n"+$e$$);$callback$$($msgError$$)},$current_obj$$);else $callback$$($msgError$$);else $callback$$(null,$obj$jscomp$0$$)})})})})})},function($obj$$,$callback$$){setImmediate(async()=>{$obj$$.ngay_ct&&($obj$$.ngay_ct=moment($obj$$.ngay_ct).toDate());for(var $$condition_k$$ in $ctrl$$.keyValues)$obj$$[$$condition_k$$]=$ctrl$$.keyValues[$$condition_k$$];
240
- Object.keys($model$$.schema.paths).filter($model_path$$=>$obj$$[$model_path$$]&&underscore.isArray($obj$$[$model_path$$])).forEach($model_path$$=>{$model$$.schema.paths[$model_path$$].schema&&$model$$.schema.paths[$model_path$$].schema.paths&&Object.keys($model$$.schema.paths[$model_path$$].schema.paths).filter($path$$=>"line"!==$path$$&&"_id"!==$path$$&&"__v"!==$path$$&&fields_sync_master_detail.indexOf($path$$)).forEach($path$$=>{$obj$$[$path$$]&&$obj$$[$model_path$$].filter($detail$$=>!$detail$$[$path$$]).forEach($detail$$=>
241
- {$detail$$[$path$$]=$obj$$[$path$$]})})});await createIdRef($model$$,$obj$$);$ctrl$$.saving&&await $ctrl$$.saving($user$jscomp$0$$,$obj$$);$ctrl$$.emit("saving",$obj$$);let $obj_created$$,$error$jscomp$0$$;$data$jscomp$0$$.$condition&&($$condition_k$$=$data$jscomp$0$$.$condition,$$condition_k$$._id=$obj$$._id,await $model$$.findOne($$condition_k$$)||($error$jscomp$0$$=ERR_CAN_NOT_UPDATE),delete $data$jscomp$0$$.$condition);if(!$error$jscomp$0$$)try{$obj_created$$=await $obj$$.save()}catch($e$$){$error$jscomp$0$$=
242
- $e$$}if($error$jscomp$0$$){let $msgErrors$$=[];for(let $k$$ in $error$jscomp$0$$.errors)$msgErrors$$.push($error$jscomp$0$$.errors[$k$$].message);0==$msgErrors$$.length&&($msgErrors$$=$error$jscomp$0$$.message);$msgErrors$$||($msgErrors$$=JSON.stringify($error$jscomp$0$$));if($ctrl$$.options.onErrorUpdating)$ctrl$$.options.onErrorUpdating($user$jscomp$0$$,$obj$$,$e$$=>{$e$$&&console.error("onErrorUpdating",$e$$);$callback$$({error:$msgErrors$$,code:ERR_CAN_NOT_UPDATE_CODE})},$current_obj$$);else $callback$$({error:$msgErrors$$,
243
- code:ERR_CAN_NOT_UPDATE_CODE})}else $req$$&&$req$$.header&&setImmediate(()=>{log.create({id_app:$user$jscomp$0$$.current_id_app,id_func:$ctrl$$.name,action:"UPDATE",data:{oldData:$current_obj$$,newData:$data$jscomp$0$$,id:$obj$$._id.toString()}},$user$jscomp$0$$.email,$req$$.header("user-agent"),$req$$)}),postData($obj_created$$,$ctrl$$,function($msgError$$){$msgError$$?setImmediate(()=>{$current_obj$$&&$model$$.findByIdAndUpdate($current_obj$$._id,{$set:$current_obj$$},function($err$$,$restore_data$$){if($err$$||
244
- !$restore_data$$)return console.error("can't restore voucher",$err$$||": don't find voucher");console.log("restored data of voucher. posting...");$model$$.findById($current_obj$$._id,($e$jscomp$0$$,$_d$$)=>{if(!$_d$$)return console.error("Don't find voucher",$current_obj$$._id);postData($_d$$,$ctrl$$,function($e$$){if($e$$)return console.error("can't repost voucher",$e$$);console.log("reposted voucher",$_d$$._id)})})});if($ctrl$$.options.onErrorUpdating)$ctrl$$.options.onErrorUpdating($user$jscomp$0$$,
245
- $obj$$,$e$$=>{$e$$&&($msgError$$=$msgError$$+"\n"+$e$$);$callback$$($msgError$$)},$current_obj$$);else $callback$$($msgError$$)}):setImmediate(()=>{$ctrl$$.emit("saved",$obj_created$$);$ctrl$$.emit("updated",$obj_created$$);$obj_created$$=$obj_created$$.toObject();runWebhooks($ctrl$$,$obj_created$$,"UPDATE",$voucher_options$$);$req$$&&pushNotification($ctrl$$,$obj_created$$,"update",$current_obj$$,null,{exclude_token:$req$$.query.access_token});$ctrl$$.cacheData($obj_created$$);if($req$$&&!1!==$req$$.query.return_data)$ctrl$$.onView($user$jscomp$0$$,
246
- [$obj_created$$],function($error$$,$viewValue$$){setImmediate(()=>{if($error$$)return $callback$$($error$$);$callback$$(null,$viewValue$$[0])})},{req:$req$$});else $callback$$(null,{_id:$obj_created$$._id})})})})},function($obj$$,$callback$$){$ctrl$$.requestApprove($user$jscomp$0$$.current_app_info,$user$jscomp$0$$,$obj$$,$callback$$,$voucher_options$$)},function($obj$jscomp$0$$,$callback$$){void 0!=$obj$jscomp$0$$.trang_thai&&setImmediate(async()=>{Approve.findOne({id_ct:$obj$jscomp$0$$._id.toString(),
247
- "update_after_approve.data.trang_thai":$obj$jscomp$0$$.trang_thai.toString()}).lean().exec(($e$$,$rs$$)=>{!$rs$$||$rs$$.user_approved||$rs$$.user_denied||($rs$$.user_approved=$req$$.user.email,$rs$$.user_approved_name=$req$$.user.name,$rs$$.date_approved=new Date,Approve.updateOne({_id:$rs$$._id},$rs$$).then(()=>{Approve.sendNotifyApproved($rs$$,$req$$.query.access_token)}))})});setImmediate(async()=>{(await permission.getFieldNotRight($obj$jscomp$0$$.id_app,$user$jscomp$0$$.email,$ctrl$$.name)).forEach($f$$=>
248
- {delete $obj$jscomp$0$$[$f$$]});$obj$jscomp$0$$.collection_name=$ctrl$$.collection_name;$ctrl$$.updated?$ctrl$$.updated($user$jscomp$0$$,$obj$jscomp$0$$,function($error$$,$obj$$){if($error$$)return console.error("error when saved",$error$$),$callback$$($error$$);$callback$$(null,$obj$$)},$current_obj$$):$callback$$(null,$obj$jscomp$0$$)})}],($e$jscomp$162_name_cached$$,$rs$$)=>{$e$jscomp$162_name_cached$$?(console.error($e$jscomp$162_name_cached$$),$callback$jscomp$1$$($e$jscomp$162_name_cached$$)):
249
- ($e$jscomp$162_name_cached$$=$model$$.collection.name,$user$jscomp$0$$.current_id_app&&($e$jscomp$162_name_cached$$+=$user$jscomp$0$$.current_id_app),delete global.cacheDatas[$e$jscomp$162_name_cached$$],$callback$jscomp$1$$(null,$rs$$))})}catch($e$$){console.error($e$$),$callback$jscomp$1$$($e$$)}};
250
- controller.prototype.update=function(){let $ctrl$$=this,$name$$=this.name;this.router.route(this.route_name+"/:id").put(function($req$$,$res$$){let $session$$=$req$$.session;if(!0===$session$$["updating_"+$name$$])return $res$$.status(400).send({error:"\u0110ang x\u1eed l\u00fd d\u1eef li\u1ec7u"});$session$$["updating_"+$name$$]=!0;let $body$$=$req$$.body;$req$$.files&&underscore.extend($body$$,$req$$.files);let $data$$;try{$data$$=bodyToJson($body$$)}catch($e$$){return $res$$.status(400).send({error:$e$$.message||
251
- $e$$.error||$e$$})}update($req$$.user,$ctrl$$,$req$$.params.id,$data$$,($e$$,$rs$$)=>{setImmediate(()=>{$session$$["updating_"+$name$$]=!1;if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});!1===$req$$.query.return_data?$res$$.send({_id:$rs$$._id.toString()}):$res$$.send($rs$$)})},null,$req$$)})};
233
+ $rs$$)=>{setImmediate(()=>{if($rs$$)return $callback$$("S\u1ed1 ch\u1ee9ng t\u1eeb "+$data$jscomp$1$$.so_ct+" \u0111\u00e3 t\u1ed3n t\u1ea1i. H\u00e3y ch\u1ecdn m\u1ed9t s\u1ed1 ch\u1ee9ng t\u1eeb kh\u00e1c");$callback$$(null,$obj$$)})})}else $callback$$(null,$obj$$)})}):$callback$$(null,$obj$$)},($obj$jscomp$2$$,$callback$jscomp$0$$)=>{(async($obj$jscomp$1$$,$callback$$)=>{try{(await permission.getFieldNotRight($obj$jscomp$1$$.id_app,$user$jscomp$0$$.email,$ctrl$$.name)).forEach($f$$=>{delete $data$jscomp$1$$[$f$$]})}catch($e$$){console.error("Error get field not right",
234
+ $e$$)}setImmediate(function(){$ctrl$$.updating?$ctrl$$.updating($user$jscomp$0$$,$data$jscomp$1$$,$obj$jscomp$1$$,function($error$jscomp$0$$,$data$jscomp$0$$,$obj$jscomp$0$$){setImmediate(()=>{if($error$jscomp$0$$)return $callback$$($error$jscomp$0$$);$ctrl$$.dynamicUpdating?$ctrl$$.dynamicUpdating($user$jscomp$0$$,$data$jscomp$0$$,$obj$jscomp$0$$,function($error$$,$data$$,$obj$$){if($error$$)return $callback$$($error$$);$callback$$(null,$obj$$)}):$callback$$(null,$obj$jscomp$0$$)})}):$ctrl$$.dynamicUpdating?
235
+ $ctrl$$.dynamicUpdating($req$$.user,$data$jscomp$1$$,$obj$jscomp$1$$,function($error$$,$data$$,$obj$$){if($error$$)return $callback$$($error$$);$callback$$(null,$obj$$)}):$callback$$(null,$obj$jscomp$1$$)})})($obj$jscomp$2$$,$callback$jscomp$0$$)},function($obj$$,$callback$$){setImmediate(function(){if(!$unique$$||0===$unique$$.length)return $callback$$(null,$obj$$);let $c1$$={},$c2$$={};$obj$$.id_app&&($c1$$.id_app=$obj$$.id_app,$c2$$.id_app||($c2$$.id_app=$obj$$.id_app));$unique$$.forEach(function($key$$){$c1$$[$key$$]=
236
+ $obj$$[$key$$];$ctrl$$.model.schema.paths[$key$$]?("number"==$ctrl$$.model.schema.paths[$key$$].instance.toLowerCase()?$c2$$[$key$$]=Number($data$jscomp$1$$[$key$$]):"date"==$ctrl$$.model.schema.paths[$key$$].instance.toLowerCase()?$c2$$[$key$$]=new Date($data$jscomp$1$$[$key$$]):"string"==$ctrl$$.model.schema.paths[$key$$].instance.toLowerCase()?$c2$$[$key$$]=($data$jscomp$1$$[$key$$]||"").toString():$c2$$[$key$$]=$data$jscomp$1$$[$key$$],$c2$$[$key$$]||($c2$$[$key$$]=$c1$$[$key$$])):console.error("field",
237
+ $key$$," is not exist. please check unique of controller")});!0!==underscore.isEqual($c1$$,$c2$$)?isExists($model$$,$unique$$,$c2$$,$ctrl$$.replaceIfExists,function($error$jscomp$0$$,$kq$$){setImmediate(()=>{if($error$jscomp$0$$||$kq$$){let $msgError$$=$error$jscomp$0$$||ERR_ALREADY_EXIST;console.error($msgError$$,$c2$$);if($ctrl$$.options.onErrorUpdating)$ctrl$$.options.onErrorUpdating($user$jscomp$0$$,$obj$$,$e$$=>{$e$$&&($msgError$$=$msgError$$+"\n"+$e$$);$callback$$($msgError$$)},$current_obj$$);
238
+ else $callback$$($msgError$$)}else checkReference($model$$,$obj$$,function($error$$){setImmediate(()=>{if($error$$)return console.error("Keys arise data",$c1$$,$c2$$,$error$$),$callback$$({error:ERR_KEY_ARISE+($error$$.error||$error$$.message||$error$$),code:ERR_KEY_ARISE_CODE});$callback$$(null,$obj$$)})},$unique$$)})}):$callback$$(null,$obj$$)})},function($obj$$,$callback$$){let $keys$$=underscore.keys($model$$.referenceKeys).filter($key$$=>"_id"!==$key$$);$unique$$&&($keys$$=$keys$$.filter($key$$=>
239
+ 0>$unique$$.indexOf($key$$).length));if(0===$keys$$.length)return $callback$$(null,$obj$$);checkReference($model$$,$obj$$,function($msgError$$){setImmediate(()=>{if($msgError$$)if($ctrl$$.options.onErrorUpdating)$ctrl$$.options.onErrorUpdating($user$jscomp$0$$,$obj$$,$e$$=>{$e$$&&($msgError$$=$msgError$$+"\n"+$e$$);$callback$$($msgError$$)},$current_obj$$);else $callback$$({error:ERR_ARISE+($msgError$$.error||$msgError$$.message||$msgError$$),code:ERR_ARISE_CODE});else $callback$$(null,$obj$$)})},
240
+ $keys$$)},function($obj$jscomp$1$$,$callback$$){$ctrl$$.validating||($ctrl$$.validating=($user$$,$obj$$,$next$$)=>{$next$$(null,$obj$$)});$ctrl$$.validating($user$jscomp$0$$,$obj$jscomp$1$$,($error$$,$obj$jscomp$0$$)=>{if($error$$)return $callback$$($error$$);setImmediate(function(){$data$jscomp$1$$.date_updated=new Date;$data$jscomp$1$$.user_updated=$user$jscomp$0$$.email;delete $data$jscomp$1$$.__v;$ctrl$$.options.onUpdateExtending||($ctrl$$.options.onUpdateExtending=function($obj$$,$data$$,$action$$,
241
+ $fn$$){$fn$$()});$ctrl$$.options.onUpdateExtending($obj$jscomp$0$$,$data$jscomp$1$$,$action$jscomp$0$$,function(){underscore.has($schema_paths$$,"exfields")&&$data$jscomp$1$$.exfields&&($obj$jscomp$0$$.exfields=$data$jscomp$1$$.exfields);for(let $f$$ in $data$jscomp$1$$)underscore.has($schema_paths$$,$f$$)&&($obj$jscomp$0$$.set($f$$,$data$jscomp$1$$[$f$$]),"exfields"!==$f$$||$obj$jscomp$0$$.exfields||($obj$jscomp$0$$.exfields={}));validate($obj$jscomp$0$$,function($msgError$$){setImmediate(()=>{if($msgError$$)if($ctrl$$.options.onErrorUpdating)$ctrl$$.options.onErrorUpdating($user$jscomp$0$$,
242
+ $obj$jscomp$0$$,$e$$=>{$e$$&&($msgError$$=$msgError$$+"\n"+$e$$);$callback$$($msgError$$)},$current_obj$$);else $callback$$($msgError$$);else $callback$$(null,$obj$jscomp$0$$)})})})})})},function($obj$$,$callback$$){setImmediate(async()=>{$obj$$.ngay_ct&&($obj$$.ngay_ct=moment($obj$$.ngay_ct).toDate());for(var $$condition_k$$ in $ctrl$$.keyValues)$obj$$[$$condition_k$$]=$ctrl$$.keyValues[$$condition_k$$];Object.keys($model$$.schema.paths).filter($model_path$$=>$obj$$[$model_path$$]&&underscore.isArray($obj$$[$model_path$$])).forEach($model_path$$=>
243
+ {$model$$.schema.paths[$model_path$$].schema&&$model$$.schema.paths[$model_path$$].schema.paths&&Object.keys($model$$.schema.paths[$model_path$$].schema.paths).filter($path$$=>"line"!==$path$$&&"_id"!==$path$$&&"__v"!==$path$$&&fields_sync_master_detail.indexOf($path$$)).forEach($path$$=>{$obj$$[$path$$]&&$obj$$[$model_path$$].filter($detail$$=>!$detail$$[$path$$]).forEach($detail$$=>{$detail$$[$path$$]=$obj$$[$path$$]})})});await createIdRef($model$$,$obj$$);$ctrl$$.saving&&await $ctrl$$.saving($user$jscomp$0$$,
244
+ $obj$$);$ctrl$$.emit("saving",$obj$$);let $obj_created$$,$error$jscomp$0$$;$data$jscomp$1$$.$condition&&($$condition_k$$=$data$jscomp$1$$.$condition,$$condition_k$$._id=$obj$$._id,await $model$$.findOne($$condition_k$$)||($error$jscomp$0$$=ERR_CAN_NOT_UPDATE),delete $data$jscomp$1$$.$condition);if(!$error$jscomp$0$$)try{$obj_created$$=await $obj$$.save()}catch($e$$){$error$jscomp$0$$=$e$$}if($error$jscomp$0$$){let $msgErrors$$=[];for(let $k$$ in $error$jscomp$0$$.errors)$msgErrors$$.push($error$jscomp$0$$.errors[$k$$].message);
245
+ 0==$msgErrors$$.length&&($msgErrors$$=$error$jscomp$0$$.message);$msgErrors$$||($msgErrors$$=JSON.stringify($error$jscomp$0$$));if($ctrl$$.options.onErrorUpdating)$ctrl$$.options.onErrorUpdating($user$jscomp$0$$,$obj$$,$e$$=>{$e$$&&console.error("onErrorUpdating",$e$$);$callback$$({error:$msgErrors$$,code:ERR_CAN_NOT_UPDATE_CODE})},$current_obj$$);else $callback$$({error:$msgErrors$$,code:ERR_CAN_NOT_UPDATE_CODE})}else $req$$&&$req$$.header&&setImmediate(()=>{log.create({id_app:$user$jscomp$0$$.current_id_app,
246
+ id_func:$ctrl$$.name,action:"UPDATE",data:{oldData:$current_obj$$,newData:$data$jscomp$1$$,id:$obj$$._id.toString()}},$user$jscomp$0$$.email,$req$$.header("user-agent"),$req$$)}),postData($obj_created$$,$ctrl$$,function($msgError$$){$msgError$$?setImmediate(()=>{$current_obj$$&&$model$$.findByIdAndUpdate($current_obj$$._id,{$set:$current_obj$$},function($err$$,$restore_data$$){if($err$$||!$restore_data$$)return console.error("can't restore voucher",$err$$||": don't find voucher");console.log("restored data of voucher. posting...");
247
+ $model$$.findById($current_obj$$._id,($e$jscomp$0$$,$_d$$)=>{if(!$_d$$)return console.error("Don't find voucher",$current_obj$$._id);postData($_d$$,$ctrl$$,function($e$$){if($e$$)return console.error("can't repost voucher",$e$$);console.log("reposted voucher",$_d$$._id)})})});if($ctrl$$.options.onErrorUpdating)$ctrl$$.options.onErrorUpdating($user$jscomp$0$$,$obj$$,$e$$=>{$e$$&&($msgError$$=$msgError$$+"\n"+$e$$);$callback$$($msgError$$)},$current_obj$$);else $callback$$($msgError$$)}):setImmediate(()=>
248
+ {$ctrl$$.emit("saved",$obj_created$$);$ctrl$$.emit("updated",$obj_created$$);$obj_created$$=$obj_created$$.toObject();runWebhooks($ctrl$$,$obj_created$$,"UPDATE",$voucher_options$$);$req$$&&pushNotification($ctrl$$,$obj_created$$,"update",$current_obj$$,null,{exclude_token:$req$$.query.access_token});$ctrl$$.cacheData($obj_created$$);if($req$$&&!1!==$req$$.query.return_data)$ctrl$$.onView($user$jscomp$0$$,[$obj_created$$],function($error$$,$viewValue$$){setImmediate(()=>{if($error$$)return $callback$$($error$$);
249
+ $callback$$(null,$viewValue$$[0])})},{req:$req$$});else $callback$$(null,{_id:$obj_created$$._id})})})})},function($obj$$,$callback$$){$ctrl$$.requestApprove($user$jscomp$0$$.current_app_info,$user$jscomp$0$$,$obj$$,$callback$$,$voucher_options$$)},function($obj$jscomp$0$$,$callback$$){void 0!=$obj$jscomp$0$$.trang_thai&&setImmediate(async()=>{Approve.findOne({id_ct:$obj$jscomp$0$$._id.toString(),"update_after_approve.data.trang_thai":$obj$jscomp$0$$.trang_thai.toString()}).lean().exec(($e$$,$rs$$)=>
250
+ {!$rs$$||$rs$$.user_approved||$rs$$.user_denied||($rs$$.user_approved=$req$$.user.email,$rs$$.user_approved_name=$req$$.user.name,$rs$$.date_approved=new Date,Approve.updateOne({_id:$rs$$._id},$rs$$).then(()=>{Approve.sendNotifyApproved($rs$$,$req$$.query.access_token)}))})});setImmediate(async()=>{(await permission.getFieldNotRight($obj$jscomp$0$$.id_app,$user$jscomp$0$$.email,$ctrl$$.name)).forEach($f$$=>{delete $obj$jscomp$0$$[$f$$]});$obj$jscomp$0$$.collection_name=$ctrl$$.collection_name;$ctrl$$.updated?
251
+ $ctrl$$.updated($user$jscomp$0$$,$obj$jscomp$0$$,function($error$jscomp$0$$,$obj$$){if($error$jscomp$0$$)return console.error("error when saved",$error$jscomp$0$$),$callback$$($error$jscomp$0$$);$ctrl$$.dynamicUpdated?$ctrl$$.dynamicUpdated($user$jscomp$0$$,$obj$$,function($error$$){if($error$$)return $callback$$($error$$);$callback$$(null,$obj$$)}):$callback$$(null,$obj$$)},$current_obj$$):$ctrl$$.dynamicUpdated?$ctrl$$.dynamicUpdated($user$jscomp$0$$,$obj$jscomp$0$$,function($error$$){if($error$$)return $callback$$($error$$);
252
+ $callback$$(null,$obj$jscomp$0$$)}):$callback$$(null,$obj$jscomp$0$$)})}],($e$jscomp$164_name_cached$$,$rs$$)=>{$e$jscomp$164_name_cached$$?(console.error($e$jscomp$164_name_cached$$),$callback$jscomp$1$$($e$jscomp$164_name_cached$$)):($e$jscomp$164_name_cached$$=$model$$.collection.name,$user$jscomp$0$$.current_id_app&&($e$jscomp$164_name_cached$$+=$user$jscomp$0$$.current_id_app),delete global.cacheDatas[$e$jscomp$164_name_cached$$],$callback$jscomp$1$$(null,$rs$$))})}catch($e$$){console.error($e$$),
253
+ $callback$jscomp$1$$($e$$)}};
254
+ controller.prototype.update=function(){let $ctrl$$=this,$name$$=this.name;this.router.route(this.route_name+"/:id").put(function($req$$,$res$$){let $session$$=$req$$.session;if(!0===$session$$["updating_"+$name$$])return $res$$.status(400).send({error:"\u0110ang x\u1eed l\u00fd d\u1eef li\u1ec7u"});$session$$["updating_"+$name$$]=!0;let $body$$=$req$$.body;$req$$.files&&underscore.extend($body$$,$req$$.files);let $data$$;try{$data$$=bodyToJson($body$$)}catch($e$$){return $res$$.status(400).send({error:$e$$.message||$e$$.error||
255
+ $e$$})}update($req$$.user,$ctrl$$,$req$$.params.id,$data$$,($e$$,$rs$$)=>{setImmediate(()=>{$session$$["updating_"+$name$$]=!1;if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});!1===$req$$.query.return_data?$res$$.send({_id:$rs$$._id.toString()}):$res$$.send($rs$$)})},null,$req$$)})};
252
256
  function checkReference($model$jscomp$0$$,$obj$$,$fn$$,$keys$$){$model$jscomp$0$$.referenceKeys?($keys$$||($keys$$=underscore.keys($model$jscomp$0$$.referenceKeys)),async.map($keys$$,function($key$$,$callback$$){setImmediate(()=>{let $ref$$=$model$jscomp$0$$.referenceKeys[$key$$];if(!$ref$$)return $callback$$();let $value$$=$obj$$[$key$$];"_id"===$key$$&&($value$$=$value$$.toString());if(void 0==$value$$||null==$value$$||""==$value$$)return $callback$$();async.map($ref$$,function($r$$,$cb$$){setImmediate(()=>
253
257
  {let $model$$=mongoose.models[$r$$.model];if($model$$){let $query$$={id_app:$obj$$.id_app};var $_w_k$$=$r$$.key;$_w_k$$&&($query$$[$_w_k$$]=$value$$);$r$$.where&&(underscore.isObject($r$$.where)&&($query$$=Object.assign($query$$,$r$$.where)),underscore.isFunction($r$$.where)&&($_w_k$$=$r$$.where($obj$$),$query$$=Object.assign($query$$,$_w_k$$)));$model$$.find($query$$).limit(1).lean().exec(function($error$$,$o$$){setImmediate(()=>{if($error$$)return $cb$$($error$$);if($o$$&&0<$o$$.length){let $msgError$$;
254
258
  $msgError$$=$r$$.error?(new Function("obj","return `"+$r$$.error.replace("{{VALUE}}",$value$$)+"`"))($obj$$):ERR_DATA_GENERATED;return $cb$$({error:$msgError$$,code:ERR_DATA_GENERATED_CODE})}$cb$$()})})}else $cb$$()})},function($e$$){if($e$$)return $callback$$($e$$);$callback$$()})})},$error$$=>{$fn$$($error$$)})):$fn$$()}
255
- controller.prototype.delete=function(){let $model$$=this.model,$ctrl$$=this,$module$$=this.module,$codeSync$$=this.codeSync,$keySync$$=this.keySync;this.router.route(this.route_name+"/:id").delete(function($req$$,$res$$,$next$$){if(!global.mongoose.Types.ObjectId.isValid($req$$.params.id))return $res$$.status(400).send({error:ERR_NOT_FOUND,code:ERR_NOT_FOUND_CODE});$model$$.findOne({_id:$req$$.params.id}).lean().exec(async function($e$jscomp$167_user$$,$obj$$){if($e$jscomp$167_user$$)return console.error($e$jscomp$167_user$$),
256
- $e$jscomp$167_user$$.error?$res$$.status(400).send($e$jscomp$167_user$$):$res$$.status(400).send({error:$e$jscomp$167_user$$.message||$e$jscomp$167_user$$.error||$e$jscomp$167_user$$});if(!$obj$$)return $res$$.status(404).send({error:ERR_NOT_FOUND,code:ERR_NOT_FOUND_CODE});$e$jscomp$167_user$$=$req$$.user;if(0>global.configs.admins.indexOf($e$jscomp$167_user$$.email)){let $requireOtp$$=$ctrl$$.options.requireOtp;$requireOtp$$&&_.isFunction($requireOtp$$)&&($requireOtp$$=$requireOtp$$($obj$$,{action:"delete",
257
- _id:$req$$.params.id,user:$e$jscomp$167_user$$}));if($requireOtp$$)try{await permission.verifyOTP($e$jscomp$167_user$$.email,$req$$.query["otp-id"],$req$$.query["otp-code"])}catch($e$$){return $res$$.status(400).send({error:$e$$.message||$e$$.error||$e$$,code:ERR_VERIFY_OTP})}}setImmediate(()=>{permission.hasRight($obj$$.id_app,$req$$.user.email,$module$$,"delete",function($error$jscomp$0$$,$hr$$){if($hr$$)checkReference($model$$,$obj$$,function($error$$){if($error$$)return $res$$.status(400).send({error:ERR_ARISE+
259
+ controller.prototype.delete=function(){let $model$$=this.model,$ctrl$$=this,$module$$=this.module,$codeSync$$=this.codeSync,$keySync$$=this.keySync;this.router.route(this.route_name+"/:id").delete(function($req$$,$res$$,$next$$){if(!global.mongoose.Types.ObjectId.isValid($req$$.params.id))return $res$$.status(400).send({error:ERR_NOT_FOUND,code:ERR_NOT_FOUND_CODE});$model$$.findOne({_id:$req$$.params.id}).lean().exec(async function($e$jscomp$169_user$$,$obj$$){if($e$jscomp$169_user$$)return console.error($e$jscomp$169_user$$),
260
+ $e$jscomp$169_user$$.error?$res$$.status(400).send($e$jscomp$169_user$$):$res$$.status(400).send({error:$e$jscomp$169_user$$.message||$e$jscomp$169_user$$.error||$e$jscomp$169_user$$});if(!$obj$$)return $res$$.status(404).send({error:ERR_NOT_FOUND,code:ERR_NOT_FOUND_CODE});$e$jscomp$169_user$$=$req$$.user;if(0>global.configs.admins.indexOf($e$jscomp$169_user$$.email)){let $requireOtp$$=$ctrl$$.options.requireOtp;$requireOtp$$&&_.isFunction($requireOtp$$)&&($requireOtp$$=$requireOtp$$($obj$$,{action:"delete",
261
+ _id:$req$$.params.id,user:$e$jscomp$169_user$$}));if($requireOtp$$)try{await permission.verifyOTP($e$jscomp$169_user$$.email,$req$$.query["otp-id"],$req$$.query["otp-code"])}catch($e$$){return $res$$.status(400).send({error:$e$$.message||$e$$.error||$e$$,code:ERR_VERIFY_OTP})}}setImmediate(()=>{permission.hasRight($obj$$.id_app,$req$$.user.email,$module$$,"delete",function($error$jscomp$0$$,$hr$$){if($hr$$)checkReference($model$$,$obj$$,function($error$$){if($error$$)return $res$$.status(400).send({error:ERR_ARISE+
258
262
  ($error$$.error||$error$$.message||$error$$),code:ERR_ARISE_CODE});$req$$.obj=$obj$$;$next$$()});else return $res$$.status(403).send({error:$error$jscomp$0$$||ERR_NOT_PERMIT,code:ERR_NOT_PERMIT_CODE})},{obj:$obj$$,notNeedRight:$ctrl$$.options.notNeedRight})})})},function($req$$,$res$$,$next$$){setImmediate(()=>{let $obj$jscomp$0$$=$req$$.obj;$ctrl$$.deleting?$ctrl$$.deleting($req$$.user,$obj$jscomp$0$$,function($e$$,$obj$$){if($e$$)return console.error($e$$),$e$$.error?$res$$.status(400).send($e$$):
259
263
  $res$$.status(400).send({error:$e$$.message||$e$$});$req$$.obj=$obj$$;$next$$()},{req:$req$$}):($req$$.obj=$obj$jscomp$0$$,$next$$())})},function($req$$,$res$$){setImmediate(()=>{let $obj$jscomp$0$$=$req$$.obj;$ctrl$$.emit("deleting",{...$obj$jscomp$0$$});$model$$.deleteOne({_id:$obj$jscomp$0$$._id},function($e$jscomp$1$$){if($e$jscomp$1$$)return console.error($e$jscomp$1$$),$e$jscomp$1$$.error?$res$$.status(400).send($e$jscomp$1$$):$res$$.status(400).send({error:$e$jscomp$1$$.message||$e$jscomp$1$$});
260
264
  setImmediate(()=>{$ctrl$$.deleteData({...$obj$jscomp$0$$});log.create({id_app:$req$$.user.current_id_app,id_func:$ctrl$$.name,action:"DELETE",data:{id:$obj$jscomp$0$$._id,data:$obj$jscomp$0$$}},$req$$.user.email,$req$$.header("user-agent"),$req$$);link.deleteMany({$or:[{id_a:$obj$jscomp$0$$._id},{id_b:$obj$jscomp$0$$._id}]},function($e$$){$e$$&&console.error("Can't delete links\n"+$e$$)})});setImmediate(()=>{$ctrl$$.emit("deleted",$obj$jscomp$0$$);runWebhooks($ctrl$$,$obj$jscomp$0$$,"DELETE")});pushNotification($ctrl$$,
@@ -29,15 +29,15 @@ $rptConfig$$.handle_data_expression.indexOf("async "))return $res$$.status(400).
29
29
  })`;try{($func_string$jscomp$3_rptInfo$jscomp$2_rs$$=await evalute($func_string$jscomp$2_key$$,{data:$app$$,moment,user:$req$jscomp$0$$.user,utils,numeral,getData:getParameterData})())&&($app$$=$func_string$jscomp$3_rptInfo$jscomp$2_rs$$)}catch($e$$){return console.error($e$$,$func_string$jscomp$2_key$$),$e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$})}}var $func_string$jscomp$3_rptInfo$jscomp$2_rs$$=await reportinfo.findOne({code:($req$jscomp$0$$.query.report_info_code||
30
30
  $rptId$$).toLowerCase()}).lean();if($func_string$jscomp$3_rptInfo$jscomp$2_rs$$&&$func_string$jscomp$3_rptInfo$jscomp$2_rs$$.handle_data_expression){if(0<=$func_string$jscomp$3_rptInfo$jscomp$2_rs$$.handle_data_expression.indexOf("async "))return $res$$.status(400).send({error:"async function is not allow"});$func_string$jscomp$3_rptInfo$jscomp$2_rs$$=`return (async ()=>{
31
31
  ${$func_string$jscomp$3_rptInfo$jscomp$2_rs$$.handle_data_expression}
32
- })`;try{const $rs$$=await evalute($func_string$jscomp$3_rptInfo$jscomp$2_rs$$,{data:$data$jscomp$3_e$$,moment,user:$req$jscomp$0$$.user,utils,numeral,getData:getParameterData})();$rs$$&&($app$$.detail=$app$$.details=$rs$$)}catch($e$$){return console.error($e$$,$func_string$jscomp$3_rptInfo$jscomp$2_rs$$),$res$$.status(400).send({error:$e$$.message||$e$$})}}$rptConfig$$&&$rptConfig$$.parameters&&await prepareParameters($rptConfig$$.parameters,$app$$,$app$$);if($req$jscomp$0$$.query.json)$res$$.json($app$$);
33
- else $options$$.onExport($app$$,function(){setImmediate(()=>{if($req$jscomp$0$$.query.print)htmlReport($html_template$$,$app$$).then($rs$$=>$res$$.send($rs$$),$error$$=>{$res$$.status(400).send({error:$error$$.message||$error$$.error||$error$$})});else{let $ext$$=$templatePath$$.split(".").pop();"xlsx"===$ext$$?excelReport($templatePath$$,$app$$,function($error$$,$result$$){if($error$$)return console.error("Error export to excel",$error$$),$res$$.status(400).send({error:$error$$.message||$error$$.error||
34
- $error$$});$res$$.setHeader("Content-Type","application/vnd.openxmlformats");$res$$.setHeader("Content-Disposition","attachment; filename="+$rptId$$+".xlsx");$res$$.end($result$$,"binary")}):textReport($templatePath$$,$app$$,function($error$$,$result$$){if($error$$)return console.error("Error export to text",$error$$),$res$$.status(400).send({error:$error$$.message||$error$$.error||$error$$});"docx"===$ext$$?($res$$.setHeader("Content-Type","application/vnd.openxmlformats-officedocument.wordprocessingml.document"),
35
- $res$$.setHeader("Content-Disposition","attachment; filename="+$rptId$$+".docx"),$res$$.write($result$$,"binary"),$res$$.end(null,"binary")):$res$$.send($result$$)})}})})})},$id_rpt$$=$req$jscomp$0$$.query.id_rpt,$dir_root_templates$$=configs.paths.templates||__dirname,$templatePath$$,$rptConfig$$,$html_template$$;(new Promise(($resolve$$,$reject$$)=>{$rptConfig$$=$templatePath$$=void 0;if($id_rpt$$&&global.mongoose.Types.ObjectId.isValid($id_rpt$$))rpt.findOne({_id:$id_rpt$$}).lean().exec(async function($error$$,
36
- $r$$){if($error$$||!$r$$)return console.error("Not found excel template",$id_rpt$$,$error$$),$reject$$($error$$||"Kh\u00f4ng t\u00ecm th\u1ea5y m\u1eabu");if($req$jscomp$0$$.query.print)$html_template$$=$r$$.html_template;else{if(0<$r$$.file_mau_in.indexOf("/file/download")){$error$$=$r$$.file_mau_in.split("/").pop();const $file$$=global.getModel("file");try{const $_fileMauIn$$=await $file$$.findOne({_id:$error$$}).lean();if(!$_fileMauIn$$)return $reject$$("Kh\u00f4ng t\u00ecm th\u1ea5y m\u1eabu");
37
- let $file_name$$=$_fileMauIn$$.file.name,$root$$=configs.paths.uploads;$root$$||($root$$=__dirname,$root$$=path.dirname($root$$),$root$$=path.join($root$$,"uploads"));$templatePath$$=path.join($root$$,$file_name$$)}catch($e$$){return $reject$$($e$$.message||"Kh\u00f4ng t\u00ecm th\u1ea5y m\u1eabu")}}else $templatePath$$=path.dirname($dir_root_templates$$)+$r$$.file_mau_in;fs.existsSync($templatePath$$)||(console.log("file template not found",$templatePath$$),$templatePath$$=`${path.dirname($dir_root_templates$$)}/templates/excels/reports/${$module$$}.xlsx`);
38
- fs.existsSync($templatePath$$)||($templatePath$$=`${path.dirname(__dirname)}/templates/excels/reports/${$module$$}.xlsx`);if(!fs.existsSync($templatePath$$))return $reject$$("M\u1eabu kh\u00f4ng t\u1ed3n t\u1ea1i")}$rptConfig$$=$r$$;return $resolve$$($templatePath$$,$html_template$$)});else if($templatePath$$=`${path.dirname($dir_root_templates$$)}/templates/excels/reports/${$module$$}.xlsx`,fs.existsSync($templatePath$$)||($templatePath$$=`${path.dirname(__dirname)}/templates/excels/reports/${$module$$}.xlsx`),
39
- !fs.existsSync($templatePath$$))return $reject$$("M\u1eabu excel kh\u00f4ng t\u1ed3n t\u1ea1i")})).then(()=>{!1===$options$$.require_id_app?$streamData$$({}):permission.hasRight($req$jscomp$0$$.params.id_app,$req$jscomp$0$$.user.email,$module$$,"view",function($error$$,$hr$$,$app$$){$hr$$?$streamData$$({...$app$$}):$res$$.status(403).send({error:"B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n xu\u1ea5t excel b\u00e1o c\u00e1o n\u00e0y"})},{notNeedRight:$options$$.notNeedRight})}).catch($e$$=>{console.error($e$$);
40
- return $e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$})})}catch($e$$){return $e$$.error?$res$$.status(500).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$})}})}getData($req$$,$callback$$){setImmediate(()=>{try{this.fecthDataFunc($req$$,$callback$$)}catch($e$$){console.error($e$$),$callback$$($e$$.message)}})}createRoute($routeName$$,$callback$$,$_options$$={method:"GET"}){$_options$$.method=$_options$$.method?$_options$$.method.toUpperCase():
41
- "GET";const $self$$=this;let $r$$=function($req$$,$res$$){setImmediate(()=>{!1===$self$$.options.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,"view",function($error$$,$hr$$){$hr$$?$callback$$($req$$,function($e$$,$rs$$){if($e$$)return console.error($e$$),$e$$.error?
42
- $res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$});$res$$.send($rs$$)},$res$$):$res$$.status(403).send({error:"B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n xem b\u00e1o c\u00e1o n\u00e0y"})},{notNeedRight:$self$$.options.notNeedRight||$_options$$.notNeedRight})})};"DELETE"==$_options$$.method?this.router.route(`${this.base_path+this.module}/${$routeName$$}`).delete($r$$):"POST"==$_options$$.method?this.router.route(`${this.base_path+this.module}/${$routeName$$}`).post($r$$):
43
- "PUT"==$_options$$.method?this.router.route(`${this.base_path+this.module}/${$routeName$$}`).put($r$$):this.router.route(`${this.base_path+this.module}/${$routeName$$}`).get($r$$)}}module.exports=controllerRPT;
32
+ })`;try{const $rs$$=await evalute($func_string$jscomp$3_rptInfo$jscomp$2_rs$$,{data:$data$jscomp$3_e$$,moment,user:$req$jscomp$0$$.user,utils,numeral,getData:getParameterData})();$rs$$&&($app$$.detail=$app$$.details=$rs$$)}catch($e$$){return console.error($e$$,$func_string$jscomp$3_rptInfo$jscomp$2_rs$$),$res$$.status(400).send({error:$e$$.message||$e$$})}}else $app$$.detail.forEach($r$$=>{for(let $_key$$ in $r$$){let $_v$$=$r$$[$_key$$];if($_v$$&&0<=$_key$$.indexOf("ngay")||0<=$_key$$.indexOf("date"))try{let $d$$=
33
+ moment($_v$$,"YYYY-MM-DD");$d$$.isValid()&&($r$$[`${$_key$$}`]=$d$$.toDate(),$r$$[`${$_key$$}_string`]=$d$$.format("DD/MM/YYYY"))}catch($e$$){console.error("Error convert to date",$_v$$,$e$$)}}});$rptConfig$$&&$rptConfig$$.parameters&&await prepareParameters($rptConfig$$.parameters,$app$$,$app$$);if($req$jscomp$0$$.query.json)$res$$.json($app$$);else $options$$.onExport($app$$,function(){setImmediate(()=>{if($req$jscomp$0$$.query.print)htmlReport($html_template$$,$app$$).then($rs$$=>$res$$.send($rs$$),
34
+ $error$$=>{$res$$.status(400).send({error:$error$$.message||$error$$.error||$error$$})});else{let $ext$$=$templatePath$$.split(".").pop();"xlsx"===$ext$$?excelReport($templatePath$$,$app$$,function($error$$,$result$$){if($error$$)return console.error("Error export to excel",$error$$),$res$$.status(400).send({error:$error$$.message||$error$$.error||$error$$});$res$$.setHeader("Content-Type","application/vnd.openxmlformats");$res$$.setHeader("Content-Disposition","attachment; filename="+$rptId$$+".xlsx");
35
+ $res$$.end($result$$,"binary")}):textReport($templatePath$$,$app$$,function($error$$,$result$$){if($error$$)return console.error("Error export to text",$error$$),$res$$.status(400).send({error:$error$$.message||$error$$.error||$error$$});"docx"===$ext$$?($res$$.setHeader("Content-Type","application/vnd.openxmlformats-officedocument.wordprocessingml.document"),$res$$.setHeader("Content-Disposition","attachment; filename="+$rptId$$+".docx"),$res$$.write($result$$,"binary"),$res$$.end(null,"binary")):
36
+ $res$$.send($result$$)})}})})})},$id_rpt$$=$req$jscomp$0$$.query.id_rpt,$dir_root_templates$$=configs.paths.templates||__dirname,$templatePath$$,$rptConfig$$,$html_template$$;(new Promise(($resolve$$,$reject$$)=>{$rptConfig$$=$templatePath$$=void 0;if($id_rpt$$&&global.mongoose.Types.ObjectId.isValid($id_rpt$$))rpt.findOne({_id:$id_rpt$$}).lean().exec(async function($error$$,$r$$){if($error$$||!$r$$)return console.error("Not found excel template",$id_rpt$$,$error$$),$reject$$($error$$||"Kh\u00f4ng t\u00ecm th\u1ea5y m\u1eabu");
37
+ if($req$jscomp$0$$.query.print)$html_template$$=$r$$.html_template;else{if(0<$r$$.file_mau_in.indexOf("/file/download")){$error$$=$r$$.file_mau_in.split("/").pop();const $file$$=global.getModel("file");try{const $_fileMauIn$$=await $file$$.findOne({_id:$error$$}).lean();if(!$_fileMauIn$$)return $reject$$("Kh\u00f4ng t\u00ecm th\u1ea5y m\u1eabu");let $file_name$$=$_fileMauIn$$.file.name,$root$$=configs.paths.uploads;$root$$||($root$$=__dirname,$root$$=path.dirname($root$$),$root$$=path.join($root$$,
38
+ "uploads"));$templatePath$$=path.join($root$$,$file_name$$)}catch($e$$){return $reject$$($e$$.message||"Kh\u00f4ng t\u00ecm th\u1ea5y m\u1eabu")}}else $templatePath$$=path.dirname($dir_root_templates$$)+$r$$.file_mau_in;fs.existsSync($templatePath$$)||(console.log("file template not found",$templatePath$$),$templatePath$$=`${path.dirname($dir_root_templates$$)}/templates/excels/reports/${$module$$}.xlsx`);fs.existsSync($templatePath$$)||($templatePath$$=`${path.dirname(__dirname)}/templates/excels/reports/${$module$$}.xlsx`);
39
+ if(!fs.existsSync($templatePath$$))return $reject$$("M\u1eabu kh\u00f4ng t\u1ed3n t\u1ea1i")}$rptConfig$$=$r$$;return $resolve$$($templatePath$$,$html_template$$)});else if($templatePath$$=`${path.dirname($dir_root_templates$$)}/templates/excels/reports/${$module$$}.xlsx`,fs.existsSync($templatePath$$)||($templatePath$$=`${path.dirname(__dirname)}/templates/excels/reports/${$module$$}.xlsx`),!fs.existsSync($templatePath$$))return $reject$$("M\u1eabu excel kh\u00f4ng t\u1ed3n t\u1ea1i")})).then(()=>
40
+ {!1===$options$$.require_id_app?$streamData$$({}):permission.hasRight($req$jscomp$0$$.params.id_app,$req$jscomp$0$$.user.email,$module$$,"view",function($error$$,$hr$$,$app$$){$hr$$?$streamData$$({...$app$$}):$res$$.status(403).send({error:"B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n xu\u1ea5t excel b\u00e1o c\u00e1o n\u00e0y"})},{notNeedRight:$options$$.notNeedRight})}).catch($e$$=>{console.error($e$$);return $e$$.error?$res$$.status(400).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$})})}catch($e$$){return $e$$.error?
41
+ $res$$.status(500).send($e$$):$res$$.status(400).send({error:$e$$.message||$e$$})}})}getData($req$$,$callback$$){setImmediate(()=>{try{this.fecthDataFunc($req$$,$callback$$)}catch($e$$){console.error($e$$),$callback$$($e$$.message)}})}createRoute($routeName$$,$callback$$,$_options$$={method:"GET"}){$_options$$.method=$_options$$.method?$_options$$.method.toUpperCase():"GET";const $self$$=this;let $r$$=function($req$$,$res$$){setImmediate(()=>{!1===$self$$.options.require_id_app?$callback$$($req$$,
42
+ 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,"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:"B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n xem b\u00e1o c\u00e1o n\u00e0y"})},
43
+ {notNeedRight:$self$$.options.notNeedRight||$_options$$.notNeedRight})})};"DELETE"==$_options$$.method?this.router.route(`${this.base_path+this.module}/${$routeName$$}`).delete($r$$):"POST"==$_options$$.method?this.router.route(`${this.base_path+this.module}/${$routeName$$}`).post($r$$):"PUT"==$_options$$.method?this.router.route(`${this.base_path+this.module}/${$routeName$$}`).put($r$$):this.router.route(`${this.base_path+this.module}/${$routeName$$}`).get($r$$)}}module.exports=controllerRPT;
@@ -15,11 +15,10 @@ $_right__right_trang_thai$$&&!$_right__right_trang_thai$$.viewOfOther&&$options$
15
15
  ma_trang_thai:$options$$.obj.trang_thai},function($e$$,$trang_thai$$){if($e$$)return $callback$$($e$$);if($trang_thai$$){if("update"===$action$$){if(0==$trang_thai$$.allow_update)return $callback$$("Tr\u1ea1ng th\u00e1i ch\u1ee9ng t\u1eeb n\u00e0y kh\u00f4ng cho ph\u00e9p s\u1eeda");if(1==$trang_thai$$.lock_data)return $callback$$("Tr\u1ea1ng th\u00e1i ch\u1ee9ng t\u1eeb n\u00e0y \u0111\u00e3 \u0111\u01b0\u1ee3c kho\u00e1")}if("delete"===$action$$&&($trang_thai$$.lock_data||0==$trang_thai$$.allow_delete))return $callback$$("Tr\u1ea1ng th\u00e1i ch\u1ee9ng t\u1eeb n\u00e0y kh\u00f4ng cho ph\u00e9p xo\u00e1")}return $callback$$()}):
16
16
  $callback$$()}},$e$$=>{$e$$?$callback$jscomp$0$$($e$$,!1):$callback$jscomp$0$$(null,!0,$app$$)}):$callback$jscomp$0$$(null,!0,$app$$)})})};
17
17
  exports.getRightByItem=function($id_app$$,$model$$,$email$$,$next$$,$module$$){exports.isAdmin($id_app$$,$email$$,async function($e$jscomp$3_key_right$$,$admin$$,$app$$,$participant$$){if($e$jscomp$3_key_right$$)return $next$$($e$jscomp$3_key_right$$);let $condition$$={};$module$$||($module$$=$model$$&&$model$$.collection&&$model$$.collection.name&&1<$model$$.collection.name.length?$model$$.collection.name.substr(0,$model$$.collection.name.length-1).toLowerCase():"");if($admin$$)$next$$(null,$condition$$,
18
- $admin$$);else{const $ds_dang_phu_trach$$=await exports.dsDangPhuTrach($id_app$$,$email$$);$ds_dang_phu_trach$$.push($email$$);$ds_dang_phu_trach$$.push(null);$ds_dang_phu_trach$$.push(void 0);$ds_dang_phu_trach$$.push("");let $allUsers$$,$onlyCreated$$;$app$$={visible_to:null};let $visible$$=[];underscore.has($model$$.schema.paths,"visible_to")&&($condition$$.$and||($condition$$.$and=[]),$allUsers$$={visible_to:0},$e$jscomp$3_key_right$$={visible_to:2,visible_to_users:$email$$},$admin$$={visible_to:5,
19
- visible_to_users:($participant$$||{}).group_id},$onlyCreated$$={user_created:{$in:$ds_dang_phu_trach$$}},$visible$$.push($allUsers$$),$visible$$.push($onlyCreated$$),$visible$$.push($e$jscomp$3_key_right$$),$visible$$.push($admin$$),$visible$$.push($app$$),underscore.has($model$$.schema.paths,"of_user")&&$visible$$.push({of_user:$email$$}),underscore.has($model$$.schema.paths,"phu_trach")&&$visible$$.push({phu_trach:{$in:$ds_dang_phu_trach$$}}),underscore.has($model$$.schema.paths,"attends")&&$visible$$.push({attends:{$in:$ds_dang_phu_trach$$}}));
20
- $e$jscomp$3_key_right$$=$email$$;$participant$$&&$participant$$.group_id&&($e$jscomp$3_key_right$$=$participant$$.group_id.toLowerCase());right.findOne({id_app:$id_app$$,email:$e$jscomp$3_key_right$$,module:$module$$},function($_right_trang_thai$jscomp$1_error$$,$allow_trang_thai_result$$){if($allow_trang_thai_result$$&&(!1===$allow_trang_thai_result$$.viewOfOther&&(underscore.has($model$$.schema.paths,"of_user")&&$visible$$.push({of_user:$email$$}),underscore.has($model$$.schema.paths,"phu_trach")&&
21
- $visible$$.push({phu_trach:{$in:$ds_dang_phu_trach$$}}),underscore.has($model$$.schema.paths,"attends")&&$visible$$.push({attends:{$in:$ds_dang_phu_trach$$}}),$allUsers$$?$allUsers$$.user_created={$in:$ds_dang_phu_trach$$}:$onlyCreated$$||$visible$$.push({user_created:{$in:$ds_dang_phu_trach$$}})),!0===underscore.has($model$$.schema.paths,"trang_thai")&&($_right_trang_thai$jscomp$1_error$$=$allow_trang_thai_result$$.view_trang_thai))){$allow_trang_thai_result$$=[void 0,null,""];for(let $t$$ in $_right_trang_thai$jscomp$1_error$$)$_right_trang_thai$jscomp$1_error$$[$t$$]&&
22
- $allow_trang_thai_result$$.push($t$$);$allUsers$$?$allUsers$$.trang_thai={$in:$allow_trang_thai_result$$}:$condition$$.trang_thai={$in:$allow_trang_thai_result$$}}0<$visible$$.length&&($condition$$.$and||($condition$$.$and=[]),$condition$$.$and.push({$or:$visible$$}));console.log("permission condition of module",$module$$,JSON.stringify($condition$$));$next$$(null,$condition$$,!1)})}})};
18
+ $admin$$);else{const $ds_dang_phu_trach$$=await exports.dsDangPhuTrach($id_app$$,$email$$);$ds_dang_phu_trach$$.push($email$$);let $allUsers$$;$app$$={visible_to:null};let $visible$$=[];underscore.has($model$$.schema.paths,"visible_to")&&($condition$$.$and||($condition$$.$and=[]),$allUsers$$={visible_to:0},$e$jscomp$3_key_right$$={visible_to:2,visible_to_users:$email$$},$admin$$={visible_to:5,visible_to_users:($participant$$||{}).group_id},$visible$$.push($allUsers$$),$visible$$.push($e$jscomp$3_key_right$$),
19
+ $visible$$.push($admin$$),$visible$$.push($app$$));$e$jscomp$3_key_right$$=$email$$;$participant$$&&$participant$$.group_id&&($e$jscomp$3_key_right$$=$participant$$.group_id.toLowerCase());right.findOne({id_app:$id_app$$,email:$e$jscomp$3_key_right$$,module:$module$$},function($_right_trang_thai$jscomp$1_error$$,$allow_trang_thai_result$$){if($allow_trang_thai_result$$&&(!1===$allow_trang_thai_result$$.viewOfOther?($visible$$.push({user_created:{$in:$ds_dang_phu_trach$$}}),$allUsers$$&&($allUsers$$.user_created=
20
+ {$in:$ds_dang_phu_trach$$})):($ds_dang_phu_trach$$.push(null),$ds_dang_phu_trach$$.push(void 0),$ds_dang_phu_trach$$.push("")),!0===underscore.has($model$$.schema.paths,"trang_thai")&&($_right_trang_thai$jscomp$1_error$$=$allow_trang_thai_result$$.view_trang_thai))){$allow_trang_thai_result$$=[void 0,null,""];for(let $t$$ in $_right_trang_thai$jscomp$1_error$$)$_right_trang_thai$jscomp$1_error$$[$t$$]&&$allow_trang_thai_result$$.push($t$$);$allUsers$$?$allUsers$$.trang_thai={$in:$allow_trang_thai_result$$}:
21
+ $condition$$.trang_thai={$in:$allow_trang_thai_result$$}}underscore.has($model$$.schema.paths,"of_user")&&$visible$$.push({of_user:$email$$});underscore.has($model$$.schema.paths,"phu_trach")&&$visible$$.push({phu_trach:{$in:$ds_dang_phu_trach$$}});underscore.has($model$$.schema.paths,"attends")&&$visible$$.push({attends:{$in:$ds_dang_phu_trach$$}});0<$visible$$.length&&($condition$$.$and||($condition$$.$and=[]),$condition$$.$and.push({$or:$visible$$}));$next$$(null,$condition$$,!1)})}})};
23
22
  exports.getRightDataView=function($id_app$$,$model$$,$email$$,$next$$){exports.isAdmin($id_app$$,$email$$,function($condition$jscomp$1_e$$,$admin$$){if($condition$jscomp$1_e$$)return $next$$($condition$jscomp$1_e$$);$condition$jscomp$1_e$$={};if(!$admin$$&&!0===underscore.has($model$$.schema.paths,"dataview_to_users")){$condition$jscomp$1_e$$.$and||($condition$jscomp$1_e$$.$and=[]);let $dataview$$=[{dataview_to:null}];$dataview$$.push({dataview_to:0});$dataview$$.push({dataview_to:1,user_created:$email$$});
24
23
  $dataview$$.push({dataview_to:2,dataview_to_users:$email$$});$condition$jscomp$1_e$$.$and.push({$or:$dataview$$})}$next$$(null,$condition$jscomp$1_e$$,$admin$$)})};
25
24
  exports.getFieldNotRight=async($_fields_id_app$$,$_p_email$$,$ma_ct$$)=>{if(!$_fields_id_app$$)return[];$_p_email$$=await Participant.ofApp($_fields_id_app$$,$_p_email$$);if(0<$_p_email$$.length){$_p_email$$=$_p_email$$[0].group_id;let $field_not_right$$;try{$field_not_right$$=await right.getInfo($_fields_id_app$$,{email:$_p_email$$,module:$ma_ct$$.toLowerCase()},"field_not_right")}catch($e$$){return[]}$_fields_id_app$$=[];for(let $_key$$ in $field_not_right$$)$field_not_right$$[$_key$$]&&$_fields_id_app$$.push($_key$$);
@@ -11,12 +11,12 @@ $joinFields$$,$fn$$)};const getFields=$fields$$=>{_.isArray($fields$$)||($fields
11
11
  Array.prototype.joinModel2=function($id_app$$,$model$jscomp$0$$,$joinFields$$,$fn$$,$options$$={cache:!0}){let $self$$=this;setImmediate(()=>{if(_.isArray($id_app$$)){let $model_1$$=$id_app$$,$joinFields_1$$=$model$jscomp$0$$,$fn_1$$=$joinFields$$;$id_app$$=void 0;$model$jscomp$0$$=$model_1$$;$joinFields$$=$joinFields_1$$;$fn$$=$fn_1$$}let $model_origin$$;_.isArray($model$jscomp$0$$)||($model_origin$$=$model$jscomp$0$$);(new Promise($resolve$$=>{setImmediate(()=>{_.isArray($joinFields$$)||($joinFields$$=
12
12
  [$joinFields$$]);$joinFields$$.forEach($join$$=>{$join$$.fields_need_get_data||_.isArray($model$jscomp$0$$)||$join$$.setFields||$join$$.asyncSetFields||!$join$$.fields||_.isFunction($join$$.fields)||($join$$.fields_need_get_data=getFields($join$$.fields))});_.isArray($model$jscomp$0$$)?$resolve$$($model$jscomp$0$$):$resolve$$([])})})).then($model$$=>{async.map($self$$,function($item$$,$callback$jscomp$0$$){setImmediate(()=>{async.map($joinFields$$,function($join$$,$callback$$){setImmediate(()=>{let $query$$=
13
13
  {};if($join$$.where)if(_.isFunction($join$$.where))$query$$=$join$$.where($item$$)||{};else{if(_.isString($join$$.where)){var $bkey_k$$=$join$$.where;$join$$.where={};$join$$.where[$bkey_k$$]=$bkey_k$$}for(let $akey$$ in $join$$.where)if($bkey_k$$=$join$$.where[$akey$$],_.isObject($bkey_k$$)?$query$$[$akey$$]=$bkey_k$$:$query$$[$bkey_k$$]=$item$$[$akey$$],"_id"==$bkey_k$$&&!$item$$[$akey$$])return console.log("can't join with this condition",$join$$.where),$callback$$(null)}if($join$$.akey&&$join$$.bkey){if("_id"==
14
- $join$$.bkey&&!$item$$[$join$$.akey])return console.log("can't join with this condition",$join$$.akey,$join$$.bkey),$callback$$(null);$query$$[$join$$.bkey]=$item$$[$join$$.akey]}let $b$$=_.findWhere($model$$,$query$$),$d_session$$="";if($query$$._id)$d_session$$="stp:"+$query$$._id;else{for(let $key$$ in $query$$)"id_app"!==$key$$&&$query$$[$key$$]&&($d_session$$=$d_session$$?$d_session$$+":"+$key$$+":"+$query$$[$key$$]:$key$$+":"+$query$$[$key$$]);$d_session$$=$query$$.id_app?"id_app:"+$query$$.id_app+
15
- ":"+$d_session$$:($id_app$$||"")+":"+$d_session$$}(new Promise(($resolve$jscomp$0$$,$reject$$)=>{let $_model$$;($_model$$="function"!==typeof $model_origin$$||$model_origin$$.findOne?$model_origin$$:$model_origin$$($item$$))&&!$b$$?(new Promise($resolve$$=>{setImmediate(()=>{$options$$.cache&&$d_session$$&&$_model$$.collection&&$_model$$.collection.name&&cachedKeys[$_model$$.collection.name.substring(0,$_model$$.collection.name.length-1)]?global.clientRedis.get($d_session$$,function($err$$,$reply$$){$resolve$$($reply$$)}):
16
- $resolve$$()})})).then($rep$$=>{setImmediate(async()=>{if($rep$$)$b$$=JSON.parse($rep$$),$resolve$jscomp$0$$($b$$);else{let $q$$={};for($fields$jscomp$1_key$$ in $query$$)void 0!==$query$$[$fields$jscomp$1_key$$]&&($q$$[$fields$jscomp$1_key$$]=$query$$[$fields$jscomp$1_key$$]);if(0===Object.keys($q$$).length)return $resolve$jscomp$0$$(null);$id_app$$&&($q$$.id_app=$id_app$$);if(""==$q$$._id||$q$$._id&&!global.mongoose.Types.ObjectId.isValid($q$$._id))return $resolve$jscomp$0$$(null);var $fields$jscomp$1_key$$=
17
- $join$$.fields_need_get_data;if(_.isString($_model$$)){if(!mongoose.models[$_model$$])return $reject$$("Collection is not exists");$_model$$=mongoose.models[$_model$$]}try{const $rs$$=await $_model$$.findOne($q$$,$fields$jscomp$1_key$$).lean().exec();$rs$$&&($rs$$._id=$rs$$._id.toString(),$b$$=$rs$$);$resolve$jscomp$0$$($b$$)}catch($e$$){console.error($e$$),$resolve$jscomp$0$$($b$$)}}})}):$resolve$jscomp$0$$($b$$)})).then(()=>{setImmediate(()=>{$b$$&&($join$$.fields||$join$$.setFields||$join$$.asyncSetFields)?
18
- ($join$$.fields&&(_.isFunction($join$$.fields)?$join$$.fields($item$$,$b$$):(_.isArray($join$$.fields)||($join$$.fields=[$join$$.fields]),$join$$.fields.forEach(function($map$$){if(_.isObject($map$$)){let $name$$=$map$$.name,$value$$=$map$$.value;if($name$$&&$value$$)$item$$[$name$$]=$b$$[$value$$];else for(let $key$$ in $map$$)$item$$[$key$$]=$b$$[$map$$[$key$$]]}else $item$$[$map$$]=$b$$[$map$$]}))),$join$$.setFields&&$join$$.setFields($item$$,$b$$),$join$$.asyncSetFields?setImmediate(()=>{$join$$.asyncSetFields($item$$,
19
- $b$$,()=>{$callback$$(null)})}):$callback$$(null)):$callback$$(null)})})})},function($error$$){setImmediate(()=>{if($error$$)return $callback$jscomp$0$$($error$$);$callback$jscomp$0$$()})})})},function($error$$){setImmediate(()=>{$error$$&&console.error($error$$);$fn$$($self$$)})})}).catch($error$$=>{console.error($error$$);$fn$$($self$$)})})};
14
+ $join$$.bkey&&!$item$$[$join$$.akey])return console.log("can't join with this condition",$join$$.akey,$join$$.bkey),$callback$$(null);$query$$[$join$$.bkey]=$item$$[$join$$.akey]}let $_model$$;($_model$$="function"!==typeof $model_origin$$||$model_origin$$.findOne?$model_origin$$:$model_origin$$($item$$))&&$_model$$.schema&&($_model$$.schema.paths.id_app?$query$$.id_app=$item$$.id_app||$query$$.id_app:delete $query$$.id_app);let $b$$=_.findWhere($model$$,$query$$),$d_session$$="";if($query$$._id)$d_session$$=
15
+ "stp:"+$query$$._id;else{for(let $key$$ in $query$$)"id_app"!==$key$$&&$query$$[$key$$]&&($d_session$$=$d_session$$?$d_session$$+":"+$key$$+":"+$query$$[$key$$]:$key$$+":"+$query$$[$key$$]);$d_session$$=$query$$.id_app?"id_app:"+$query$$.id_app+":"+$d_session$$:($id_app$$||"")+":"+$d_session$$}(new Promise(($resolve$jscomp$0$$,$reject$$)=>{$_model$$&&!$b$$?(new Promise($resolve$$=>{setImmediate(()=>{$options$$.cache&&$d_session$$&&$_model$$.collection&&$_model$$.collection.name&&cachedKeys[$_model$$.collection.name.substring(0,
16
+ $_model$$.collection.name.length-1)]?global.clientRedis.get($d_session$$,function($err$$,$reply$$){$resolve$$($reply$$)}):$resolve$$()})})).then($rep$$=>{setImmediate(async()=>{if($rep$$)$b$$=JSON.parse($rep$$),$resolve$jscomp$0$$($b$$);else{let $q$$={};for($fields$jscomp$1_key$$ in $query$$)void 0!==$query$$[$fields$jscomp$1_key$$]&&($q$$[$fields$jscomp$1_key$$]=$query$$[$fields$jscomp$1_key$$]);if(0===Object.keys($q$$).length)return $resolve$jscomp$0$$(null);$id_app$$&&($q$$.id_app=$id_app$$);if(""==
17
+ $q$$._id||$q$$._id&&!global.mongoose.Types.ObjectId.isValid($q$$._id))return $resolve$jscomp$0$$(null);var $fields$jscomp$1_key$$=$join$$.fields_need_get_data;if(_.isString($_model$$)){if(!mongoose.models[$_model$$])return $reject$$("Collection is not exists");$_model$$=mongoose.models[$_model$$]}try{const $rs$$=await $_model$$.findOne($q$$,$fields$jscomp$1_key$$).lean().exec();$rs$$&&($rs$$._id=$rs$$._id.toString(),$b$$=$rs$$);$resolve$jscomp$0$$($b$$)}catch($e$$){console.error($e$$),$resolve$jscomp$0$$($b$$)}}})}):
18
+ $resolve$jscomp$0$$($b$$)})).then(()=>{setImmediate(()=>{$b$$&&($join$$.fields||$join$$.setFields||$join$$.asyncSetFields)?($join$$.fields&&(_.isFunction($join$$.fields)?$join$$.fields($item$$,$b$$):(_.isArray($join$$.fields)||($join$$.fields=[$join$$.fields]),$join$$.fields.forEach(function($map$$){if(_.isObject($map$$)){let $name$$=$map$$.name,$value$$=$map$$.value;if($name$$&&$value$$)$item$$[$name$$]=$b$$[$value$$];else for(let $key$$ in $map$$)$item$$[$key$$]=$b$$[$map$$[$key$$]]}else $item$$[$map$$]=
19
+ $b$$[$map$$]}))),$join$$.setFields&&$join$$.setFields($item$$,$b$$),$join$$.asyncSetFields?setImmediate(()=>{$join$$.asyncSetFields($item$$,$b$$,()=>{$callback$$(null)})}):$callback$$(null)):$callback$$(null)})})})},function($error$$){setImmediate(()=>{if($error$$)return $callback$jscomp$0$$($error$$);$callback$jscomp$0$$()})})})},function($error$$){setImmediate(()=>{$error$$&&console.error($error$$);$fn$$($self$$)})})}).catch($error$$=>{console.error($error$$);$fn$$($self$$)})})};
20
20
  Array.prototype.asyncJoinModel2=function($id_app$$,$model$$,$joinFields$$,$options$$={cache:!0}){let $_this$$=this;return new Promise($resolve$$=>{$_this$$.joinModel2($id_app$$,$model$$,$joinFields$$,$rs$$=>{$resolve$$($rs$$)},$options$$)})};
21
21
  Array.prototype.crossJoin=function($otherArray$$,$where$$,$fn$$){setImmediate(()=>{let $newArray$$=[];for(let $e1$$ of this){var $_otherArray__where$$={};if($where$$)for(let $key$$ in $where$$)$_otherArray__where$$[$where$$[$key$$]]=$e1$$[$key$$];$_otherArray__where$$=_.where($otherArray$$,$_otherArray__where$$);if(0===$_otherArray__where$$.length)$newArray$$.push($e1$$);else for(let $item$$ of $_otherArray__where$$)$_otherArray__where$$={},_.extend($_otherArray__where$$,$e1$$),_.extend($_otherArray__where$$,
22
22
  $item$$),$newArray$$.push($_otherArray__where$$)}$fn$$($newArray$$)})};Array.prototype.asyncCrossJoin=function($otherArray$$,$where$$){let $_this$$=this;return new Promise($resolve$$=>{$_this$$.crossJoin($otherArray$$,$where$$,$rs$$=>{$resolve$$($rs$$)})})};
@@ -1,11 +1,12 @@
1
1
  'use strict';const validAccount=require("../libs/validator-account"),validator=require("../libs/validator"),unidecode=require("unidecode"),dmvtSchema=new Schema({id_app:{type:String,required:!0,maxlength:1024},ma_vt:{type:String,required:"M\u00e3 v\u1eadt t\u01b0 kh\u00f4ng \u0111\u01b0\u1ee3c tr\u1ed1ng",uppercase:!0,trim:!0,maxlength:1024},ma_vt2:{type:String,maxlength:1024,uppercase:!0,trim:!0},ma_can:{type:String,maxlength:1024,uppercase:!0,trim:!0},ten_vt:{type:String,required:"T\u00ean v\u1eadt t\u01b0 kh\u00f4ng \u0111\u01b0\u1ee3c tr\u1ed1ng",
2
2
  maxlength:1024},ten_vt_kd:String,ma_dvt:{type:String,required:"M\u00e3 \u0111\u01a1n v\u1ecb t\u00ednh kh\u00f4ng \u0111\u01b0\u1ee3c tr\u1ed1ng",maxlength:32},ma_lvt:{type:String,required:!1,maxlength:32},ma_nvt:{type:String,required:!1,maxlength:1024},ten_nvt:String,ma_nvt2:{type:String,required:!1,maxlength:1024},ma_nvt3:{type:String,required:!1,maxlength:1024},ma_nvt4:{type:String,required:!1,maxlength:1024},ma_ncc:{type:String,required:!1,maxlength:32},ten_ncc:String,tg_tk:{type:Boolean,default:!0},
3
3
  kg_kiem_tra_ton_kho:{type:Boolean,default:!1},kg_kiem_tra_ton_kho_tt:{type:Boolean,default:!1},gia_xuat:{type:String,default:"1",maxlength:32},tk_vt:{type:String,default:"1561",maxlength:32},tk_dt:{type:String,maxlength:32},tk_gv:{type:String,maxlength:32},tk_dl:{type:String,maxlength:32},tk_tl:{type:String,maxlength:32},gia_ban_le0:{type:Number,default:0},gia_ban_buon0:{type:Number,default:0},gia_ban_le:{type:Number,default:0},gia_ban_buon:{type:Number,default:0},ban_theo_tg:{type:Boolean,default:!1},
4
- sp_yeu_cau_che_bien:{type:Boolean,default:!1},sp_yeu_cau_pha_che:{type:Boolean,default:!1},gia_mua:{type:Number,default:0},ty_le_ck0:{type:Number,default:0},tien_ck0:{type:Number,default:0},thue_suat_nk0:{type:Number,default:0},ton_kho_mac_dinh:{type:Number,default:0},thue_suat_nk:{type:Number,default:0},ma_thue:{type:String,maxlength:32},picture_slide:{type:String,maxlength:1024},picture:{type:String,maxlength:1024},picture2:{type:String,maxlength:1024},picture3:{type:String,maxlength:1024},picture4:{type:String,
5
- maxlength:1024},picture5:{type:String,maxlength:1024},picture6:{type:String,maxlength:1024},mieu_ta:{type:String},mieu_ta_chi_tiet:{type:String},khuyen_mai:{type:String},bao_hang:{type:String},xuat_xu:{type:String},nhan_hieu:{type:String},hot:{type:Boolean},bestseller:{type:Boolean},banner_large:{type:Boolean},banner_small:{type:Boolean},tinh_trang:{type:String,maxlength:1024},exfields:Schema.Types.Mixed,labels:[String],ma_lo_yn:Boolean,ma_tt1_yn:Boolean,ma_tt2_yn:Boolean,ma_tt3_yn:Boolean,thuoc_tinh:Schema.Types.Mixed,
6
- cong_doan_sx:[Schema.Types.Mixed],is_service:{type:Boolean,default:!1},is_digital:{type:Boolean,default:!1},is_coin:Boolean,is_point:Boolean,file_digital:String,combo:[],shared:{type:Boolean,default:!0},status:{type:Boolean,default:!0},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:0},visible_to_users:[String]},{toJSON:{virtuals:!0}});
4
+ sp_yeu_cau_che_bien:{type:Boolean,default:!1},sp_yeu_cau_pha_che:{type:Boolean,default:!1},gia_mua:{type:Number,default:0},ty_le_ck0:{type:Number,default:0},tien_ck0:{type:Number,default:0},thue_suat_nk0:{type:Number,default:0},ton_kho_mac_dinh:{type:Number,default:0},ton_kho_hien_tai:{type:Number,default:0},thue_suat_nk:{type:Number,default:0},ma_thue:{type:String,maxlength:32},picture_slide:{type:String,maxlength:1024},picture:{type:String,maxlength:1024},picture2:{type:String,maxlength:1024},picture3:{type:String,
5
+ maxlength:1024},picture4:{type:String,maxlength:1024},picture5:{type:String,maxlength:1024},picture6:{type:String,maxlength:1024},mieu_ta:{type:String},mieu_ta_chi_tiet:{type:String},khuyen_mai:{type:String},bao_hang:{type:String},xuat_xu:{type:String},nhan_hieu:{type:String},hot:{type:Boolean},bestseller:{type:Boolean},banner_large:{type:Boolean},banner_small:{type:Boolean},tinh_trang:{type:String,maxlength:1024},exfields:Schema.Types.Mixed,labels:[String],ma_lo_yn:Boolean,ma_tt1_yn:Boolean,ma_tt2_yn:Boolean,
6
+ ma_tt3_yn:Boolean,thuoc_tinh:Schema.Types.Mixed,cong_doan_sx:[Schema.Types.Mixed],is_service:{type:Boolean,default:!1},is_digital:{type:Boolean,default:!1},is_coin:Boolean,is_point:Boolean,file_digital:String,combo:[],shared:{type:Boolean,default:!0},status:{type:Boolean,default:!0},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:0},visible_to_users:[String]},
7
+ {toJSON:{virtuals:!0}});
7
8
  dmvtSchema.validate={tk_vt:validAccount.existsTk,ma_dvt:validator.existsDvt,ma_thue:validator.existsVat,gia_xuat:[function($id_app$$,$gx$$,$callback$$){"1"!=$gx$$&&"2"!=$gx$$&&"3"!=$gx$$?$callback$$(!1):$callback$$(!0)},"Ph\u01b0\u01a1ng ph\u00e1p t\u00ednh gi\u00e1 xu\u1ea5t: 1- Trung b\u00ecnh th\u00e1ng, 2- Nh\u1eadp tr\u01b0\u1edbc xu\u1ea5t tr\u01b0\u1edbc, 3- \u0110\u00edch danh"],tinh_trang:[function($id_app$$,$gx$$,$callback$$){"1"!=$gx$$&&"2"!=$gx$$&&"3"!=$gx$$?$callback$$(!1):$callback$$(!0)},
8
- "T\u00ecnh tr\u1ea1ng: 1- \u0110ang c\u00f3 h\u00e0ng, 2- S\u1eafp c\u00f3 h\u00e0ng, 3- H\u1ebft h\u00e0ng"]};dmvtSchema.index({id_app:1});dmvtSchema.index({ma_nvt:1});dmvtSchema.index({is_service:1});dmvtSchema.index({is_digital:1});dmvtSchema.index({date_updated:-1});dmvtSchema.index({date_created:-1});dmvtSchema.index({user_created:1});dmvtSchema.index({ten_vt_kd:1});
9
+ "T\u00ecnh tr\u1ea1ng: 1- \u0110ang c\u00f3 h\u00e0ng, 2- S\u1eafp c\u00f3 h\u00e0ng, 3- H\u1ebft h\u00e0ng"]};dmvtSchema.index({id_app:1});dmvtSchema.index({ma_nvt:1});dmvtSchema.index({is_service:1});dmvtSchema.index({is_digital:1});dmvtSchema.index({date_updated:-1});dmvtSchema.index({date_created:-1});dmvtSchema.index({user_created:1});dmvtSchema.index({ton_kho_hien_tai:1});dmvtSchema.index({ten_vt_kd:1});
9
10
  dmvtSchema.index({ten_vt:"text",mieu_ta:"text",ma_vt:"text",ma_vt2:"text",ma_can:"text",nhan_hieu:"text",xuat_xu:"text",ma_nvt:"text",ten_nvt:"text",ma_ncc:"text",ten_ncc:"text",labels:"text"},{name:"product_index"});dmvtSchema.index({id_app:1,ma_vt:1},{unique:!0});dmvtSchema.index({ma_vt2:1});dmvtSchema.index({ma_can:1});dmvtSchema.index({ten_vt:1});dmvtSchema.index({ma_dvt:1});dmvtSchema.index({ma_lvt:1});dmvtSchema.index({ma_nvt:1});dmvtSchema.index({ten_nvt:1});dmvtSchema.index({ma_ncc:1});dmvtSchema.index({ten_ncc:1});
10
11
  dmvtSchema.index({nhan_hieu:1});dmvtSchema.index({xuat_xu:1});dmvtSchema.index({labels:1});dmvtSchema.index({mieu_ta:1});dmvtSchema.index({status:1});dmvtSchema.index({user_created:1,visible_to:1,visible_to_users:1});dmvtSchema.pre("save",function($next$$){const $self$$=this;$self$$.ten_vt?setImmediate(()=>{const $ten_vt_kd$$=unidecode($self$$.ten_vt);$self$$.ten_vt_kd=`${$ten_vt_kd$$}`;$next$$()}):$next$$()});const model=mongoose.models.dmvt||mongoose.model("dmvt",dmvtSchema);
11
12
  model.on("index",async function($err$$){$err$$?(console.error("Product index error",$err$$),(await model.aggregate([{$group:{_id:{id_app:"$id_app",ma_vt:"$ma_vt"},count:{$sum:1},ids:{$push:"$_id"}}},{$match:{count:{$gt:1}}}])).forEach($d$$=>{console.info("product duplication",$d$$._id,$d$$.ids);$d$$.ids.forEach(($id$$,$index$$)=>{0<$index$$&&console.info("you should delete product",$id$$)})})):console.info("Product indexing complete")});
@@ -3,9 +3,9 @@ new global.Schema({stt:{type:Number,default:0},name:{type:String,required:"Y\u00
3
3
  index:{type:Boolean,default:!1},is_tmp:{type:Boolean,default:!1},is_title:{type:Boolean,default:!1},on_view:{type:Boolean,default:!0},maxlength:Number,min:global.Schema.Types.Mixed,max:global.Schema.Types.Mixed,ref_model:{type:String},ref_field:{type:String},ref_label:{type:String},ref_label_as:{type:String},ref_search_fields:{type:String},ref_condition:{type:String},multiple:Boolean,not_display:global.Schema.Types.Mixed,not_input:global.Schema.Types.Mixed,min_width_display:{type:Number,default:80},
4
4
  format:{type:String},align:{type:String},color:{type:String},bold:Boolean,html_variant_display:{type:String},html_component_display:{type:String},html_component_input:{type:String},grid_configs:String,handle_value_changed:{type:String},handle_search_condition:String,tab:{type:String},group:{type:String},help_text:{type:String},line:{type:Number,default:0}}),listinfoSchema=new global.Schema({menu_position:String,code:{type:String,required:!0,index:!0,lowercase:!0,trim:!0},title:{type:String,required:!0},
5
5
  title2:{type:String},mother_code:{type:String,lowercase:!0},api_code:{type:String,lowercase:!0},model_code:{type:String,lowercase:!0},fields:[fieldScheme],postinfos:[global.Schema.Types.Mixed],exfields:global.Schema.Types.Mixed,create_model:{type:Boolean,default:!1},breadcrumbs:{type:String},not_add:Boolean,not_edit:Boolean,not_delete:Boolean,handle_cell_clicked:{type:String},expression_check_save:String,on_saved:String,on_deleting:String,on_deleted:String,on_init:String,on_init_update:String,handle_view_server:String,
6
- search_required:Boolean,search_form:String,default_condition:String,require_condition:String,export_yn:Boolean,sort_by:String,not_need_right:{type:Boolean,default:!1},require_id_app:{type:Boolean,default:!0},private_data:Boolean,view_tabs:[],allow_users:{type:String},create_menu:Boolean,show_view_tabs_on_grid:Boolean,form_size:{type:String,default:"md"},is_dashboard_item:{type:Boolean,default:!1},dashboard_default:{type:Boolean,default:!0},dashboard_ids:{type:String},dashboard_stt:{type:Number},get_other_fields:String,
7
- status:{type:Boolean,default:!0},date_created:{type:Date,default:Date.now},date_updated:{type:Date,default:Date.now},user_created:{type:String,default:""},user_updated:{type:String,default:""}});listinfoSchema.index({code:1});listinfoSchema.index({title:1});listinfoSchema.index({title2:1});listinfoSchema.index({mother_code:1});listinfoSchema.index({api_code:1});listinfoSchema.index({model_code:1});listinfoSchema.index({mother_code:1});listinfoSchema.index({is_dashboard_item:1});listinfoSchema.index({dashboard_ids:1});
8
- listinfoSchema.index({mother_code:"text",code:"text",title:"text"},{name:"listinfo_index2_text"});listinfoSchema.index({status:1});listinfoSchema.index({user_created:1,visible_to:1,visible_to_users:1});
6
+ handle_oncreating_server:String,handle_oncreated_server:String,handle_onupdating_server:String,handle_onupdated_server:String,search_required:Boolean,search_form:String,default_condition:String,require_condition:String,export_yn:Boolean,sort_by:String,not_need_right:{type:Boolean,default:!1},require_id_app:{type:Boolean,default:!0},private_data:Boolean,view_tabs:[],allow_users:{type:String},create_menu:Boolean,show_view_tabs_on_grid:Boolean,form_size:{type:String,default:"md"},is_dashboard_item:{type:Boolean,
7
+ default:!1},dashboard_default:{type:Boolean,default:!0},dashboard_ids:{type:String},dashboard_stt:{type:Number},get_other_fields:String,status:{type:Boolean,default:!0},date_created:{type:Date,default:Date.now},date_updated:{type:Date,default:Date.now},user_created:{type:String,default:""},user_updated:{type:String,default:""}});listinfoSchema.index({code:1});listinfoSchema.index({title:1});listinfoSchema.index({title2:1});listinfoSchema.index({mother_code:1});listinfoSchema.index({api_code:1});listinfoSchema.index({model_code:1});
8
+ listinfoSchema.index({mother_code:1});listinfoSchema.index({is_dashboard_item:1});listinfoSchema.index({dashboard_ids:1});listinfoSchema.index({mother_code:"text",code:"text",title:"text"},{name:"listinfo_index2_text"});listinfoSchema.index({status:1});listinfoSchema.index({user_created:1,visible_to:1,visible_to_users:1});
9
9
  const model=global.mongoose.models.listinfo||global.mongoose.model("listinfo",listinfoSchema),requireFields={id_app:{type:String,required:!0},exfields:global.Schema.Types.Mixed,status:{type:Boolean,default:!0},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:0},visible_to_users:[String]};
10
10
  model.createSchema=$info_textFields$$=>{if(!$info_textFields$$.create_model)return null;var $api_code_index_name$$=$info_textFields$$.api_code||$info_textFields$$.code,$_requireFields_fields$$={...requireFields};0!=$info_textFields$$.require_id_app&&"false"!=$info_textFields$$.require_id_app||delete $_requireFields_fields$$.id_app;let $mySchema$$=new global.Schema($_requireFields_fields$$,{strict:!1}),$require_paths$$=Object.keys($mySchema$$.paths);$_requireFields_fields$$={};for($f_uq$$ of $info_textFields$$.fields.filter($f$$=>
11
11
  "Link"!==$f$$.type&&"Files"!==$f$$.type&&"Action"!==$f$$.type&&"Group"!==$f$$.type&&0>$require_paths$$.indexOf($f$$.name))){$f_uq$$.unique&&($f_uq$$.index=!0);let $_field$$=Object.assign({},$f_uq$$);if("DateTime"==$_field$$.type||"Time"==$_field$$.type)$_field$$.type="Date";if("File"==$_field$$.type||"OtherFile"==$_field$$.type)$_field$$.type="Mixed";"Array"==$_field$$.type&&($_field$$.type="Mixed");"Pdf"==$_field$$.type&&($_field$$.type="String");"Image"==$_field$$.type&&($_field$$.type="String");
@@ -26,20 +26,34 @@ evalute($condition_postInfo_scriptCondition$$,{master:$obj$$,data:$obj$$,moment}
26
26
  ${$postInfo$$.script}
27
27
  })()`,{master:{...$obj$$},data:{...$obj$$},moment});return new Promise(($resolve$$,$reject$$)=>{if("socai"===$postInfo$$.model)(new PostSocai($obj$$,$data$$)).run(($e$$,$rs$$)=>{if($e$$)return $reject$$($e$$);$resolve$$($rs$$)});else{let $m$$=global.getModel($postInfo$$.model);(new PostBook($obj$$,$data$$,$m$$,function($detail$$,$callback$$){$callback$$($detail$$)})).run(function($e$$,$rs$$){if($e$$)return $reject$$($e$$);$resolve$$($rs$$)})}})})()))},dynamicFinding=($_listInfo$$,$user$$,$condition$$,
28
28
  $next$$)=>{if($_listInfo$$.api_code&&$_listInfo$$.api_code!=$_listInfo$$.code)return $next$$(null,$condition$$);$_listInfo$$.private_data&&($condition$$.user_created=$user$$.email);if($_listInfo$$.require_condition)try{let $script$$=$_listInfo$$.require_condition;0>$script$$.indexOf("return ")&&($script$$=`return ${$script$$}`);const $require_condition$$=evalute($script$$);for(let $key$$ in $require_condition$$)$condition$$[$key$$]=$require_condition$$[$key$$]}catch($e$$){return console.error($e$$),
29
- $next$$(`Error on require condition: ${$e$$.message}`)}$next$$(null,$condition$$)},onView=async($obj$$,$user$$,$items$$,$next$jscomp$0$$)=>{$obj$$.private_data&&($items$$=$items$$.filter($item$$=>$item$$.user_created===$user$$.email));$obj$$.handle_view_server&&await new Promise($resolve$$=>{async.parallel([$next$$=>{evalute(`(async ()=>{
29
+ $next$$(`Error on require condition: ${$e$$.message}`)}$next$$(null,$condition$$)},dynamicCreating=async($_listInfo$$,$user$$,$obj$$,$next$jscomp$0$$)=>{if($_listInfo$$.handle_oncreating_server&&""!==$_listInfo$$.handle_oncreating_server.trim()){if(0>$_listInfo$$.handle_oncreating_server.indexOf("next"))return $next$jscomp$0$$("Script x\u1eed l\u00fd d\u1eef li\u1ec7u tr\u01b0\u1edbc khi t\u1ea1o y\u00eau c\u1ea7u g\u1ecdi function next");try{await new Promise(($resolve$$,$reject$$)=>{async.parallel([$next$$=>
30
+ {const $func_body$$=`(async ()=>{
31
+ ${$_listInfo$$.handle_oncreating_server}
32
+ })();`;try{evalute($func_body$$,{obj:$obj$$,user:$user$$,getLib:global.getLib,getModel:global.getModel,utils,async,controller,controllers:global.controllers,joinModel2,next:$next$$})}catch($e$$){$next$$($e$$)}}],($e$$,$rs$$)=>{if($e$$)return console.error($e$$),$reject$$($e$$);$resolve$$($rs$$)})})}catch($e$$){return console.error($e$$),$next$jscomp$0$$($e$$)}}$next$jscomp$0$$(null,$obj$$)},dynamicCreated=async($_listInfo$$,$user$$,$obj$$,$next$jscomp$0$$)=>{if($_listInfo$$.handle_oncreated_server&&
33
+ ""!==$_listInfo$$.handle_oncreated_server.trim()){if(0>$_listInfo$$.handle_oncreated_server.indexOf("next"))return $next$jscomp$0$$("Script x\u1eed l\u00fd d\u1eef li\u1ec7u sau khi t\u1ea1o y\u00eau c\u1ea7u g\u1ecdi function next");try{await new Promise(($resolve$$,$reject$$)=>{async.parallel([$next$$=>{const $func_body$$=`(async ()=>{
34
+ ${$_listInfo$$.handle_oncreated_server}
35
+ })();`;try{evalute($func_body$$,{obj:$obj$$,user:$user$$,getLib:global.getLib,getModel:global.getModel,controller,controllers:global.controllers,utils,async,joinModel2,next:$next$$})}catch($e$$){$next$$($e$$)}}],($e$$,$rs$$)=>{if($e$$)return console.error($e$$),$reject$$($e$$);$resolve$$($rs$$)})})}catch($e$$){return console.error($e$$),$next$jscomp$0$$($e$$)}}$next$jscomp$0$$(null,$obj$$)},dynamicUpdating=async($_listInfo$$,$user$$,$data$$,$obj$$,$next$jscomp$0$$)=>{if($_listInfo$$.handle_onupdating_server&&
36
+ ""!==$_listInfo$$.handle_onupdating_server.trim()){if(0>$_listInfo$$.handle_onupdating_server.indexOf("next"))return $next$jscomp$0$$("Script x\u1eed l\u00fd d\u1eef li\u1ec7u tr\u01b0\u1edbc khi update y\u00eau c\u1ea7u g\u1ecdi function next");try{await new Promise(($resolve$$,$reject$$)=>{async.parallel([$next$$=>{const $func_body$$=`(async ()=>{
37
+ ${$_listInfo$$.handle_onupdating_server}
38
+ })();`;try{evalute($func_body$$,{data:$data$$,obj:$obj$$,user:$user$$,getLib:global.getLib,getModel:global.getModel,controller,controllers:global.controllers,utils,async,joinModel2,next:$next$$})}catch($e$$){$next$$($e$$)}}],($e$$,$rs$$)=>{if($e$$)return console.error($e$$),$reject$$($e$$);$resolve$$($rs$$)})})}catch($e$$){return console.error($e$$),$next$jscomp$0$$($e$$)}}$next$jscomp$0$$(null,$data$$,$obj$$)},dynamicUpdated=async($_listInfo$$,$user$$,$obj$$,$next$jscomp$0$$)=>{if($_listInfo$$.handle_onupdated_server&&
39
+ ""!==$_listInfo$$.handle_onupdated_server.trim()){if(0>$_listInfo$$.handle_onupdated_server.indexOf("next"))return $next$jscomp$0$$("Script x\u1eed l\u00fd d\u1eef li\u1ec7u sau khi update y\u00eau c\u1ea7u g\u1ecdi function next");try{await new Promise(($resolve$$,$reject$$)=>{async.parallel([$next$$=>{const $func_body$$=`(async ()=>{
40
+ ${$_listInfo$$.handle_onupdated_server}
41
+ })();`;try{evalute($func_body$$,{obj:$obj$$,user:$user$$,getLib:global.getLib,getModel:global.getModel,controller,controllers:global.controllers,utils,async,joinModel2,next:$next$$})}catch($e$$){$next$$($e$$)}}],($e$$,$rs$$)=>{if($e$$)return console.error($e$$),$reject$$($e$$);$resolve$$($rs$$)})})}catch($e$$){return console.error($e$$),$next$jscomp$0$$($e$$)}}$next$jscomp$0$$(null,$obj$$)},onView=async($obj$$,$user$$,$items$$,$next$jscomp$0$$)=>{$obj$$.private_data&&($items$$=$items$$.filter($item$$=>
42
+ $item$$.user_created===$user$$.email));if($obj$$.handle_view_server&&""!==$obj$$.handle_view_server.trim()){if(0>$obj$$.handle_view_server.indexOf("next"))return $next$jscomp$0$$("Script x\u1eed l\u00fd view y\u00eau c\u1ea7u g\u1ecdi function next");await new Promise($resolve$$=>{async.parallel([$next$$=>{evalute(`(async ()=>{
30
43
  ${$obj$$.handle_view_server}
31
- })();`,{items:$items$$,user:$user$$,getLib:global.getLib,utils,next:$next$$,async,joinModel2})}],($e$$,$rs$$)=>{$e$$&&console.error($e$$);$resolve$$($rs$$)})});let $ref_model$$,$where$$,$fields$$,$ref_name_model$$,$fields_have_ref$$=$obj$$.fields.filter($f$$=>$f$$.ref_model&&0>$f$$.ref_model.indexOf("[")&&$f$$.ref_field&&$f$$.ref_label);if(0===$fields_have_ref$$.length)return $next$jscomp$0$$(null,$items$$);async.map($fields_have_ref$$,async $f$$=>{try{$ref_name_model$$=$f$$.ref_model;"dmkh"===
44
+ })();`,{items:$items$$,user:$user$$,getLib:global.getLib,utils,next:$next$$,async,joinModel2})}],($e$$,$rs$$)=>{$e$$&&console.error($e$$);$resolve$$($rs$$)})})}let $ref_model$$,$where$$,$fields$$,$ref_name_model$$,$fields_have_ref$$=$obj$$.fields.filter($f$$=>$f$$.ref_model&&0>$f$$.ref_model.indexOf("[")&&$f$$.ref_field&&$f$$.ref_label);if(0===$fields_have_ref$$.length)return $next$jscomp$0$$(null,$items$$);async.map($fields_have_ref$$,async $f$$=>{try{$ref_name_model$$=$f$$.ref_model;"dmkh"===
32
45
  $ref_name_model$$&&($ref_name_model$$="customer");"dmtk"===$ref_name_model$$&&($ref_name_model$$="account");"dmnt"===$ref_name_model$$&&($ref_name_model$$="currency");$ref_model$$=global.mongoose.models[$ref_name_model$$];if(!$ref_model$$){var $_listInofOfRef_items_will_join$$=await model.findOne({code:$ref_name_model$$});$_listInofOfRef_items_will_join$$&&($_listInofOfRef_items_will_join$$.api_code||$_listInofOfRef_items_will_join$$.model_code)&&($ref_model$$=global.mongoose.models[$_listInofOfRef_items_will_join$$.api_code||
33
46
  $_listInofOfRef_items_will_join$$.model_code])}if(!$ref_model$$)return`Model ${$ref_name_model$$},${$f$$.name} is not exists`}catch($e$$){return $e$$.message}$f$$.ref_label?($fields$$={[$f$$.ref_label_as||$f$$.ref_label]:$f$$.ref_label},$_listInofOfRef_items_will_join$$=$items$$.filter($i$$=>!$i$$[$f$$.ref_label_as||$f$$.ref_label])):($fields$$={},$_listInofOfRef_items_will_join$$=$items$$);"trangthai"===$f$$.ref_model&&($fields$$.color="color");$where$$=$item$$=>{let $w$$={[$f$$.ref_field]:$item$$[$f$$.name]},
34
47
  $condition$$;if($f$$.ref_condition&&0>$f$$.ref_condition.indexOf("API")){let $func_string$$=$f$$.ref_condition;0>$func_string$$.indexOf("return ")&&($func_string$$=`return ${$func_string$$}`);let $userInfo$$={...$user$$};try{$condition$$=evalute($func_string$$,{master:$item$$,data:$item$$,detail:$item$$,userInfo:$userInfo$$})}catch($e$$){console.error($e$$,$func_string$$)}}$condition$$&&($w$$={...$w$$,...$condition$$});"participant"===$f$$.ref_model&&delete $w$$.groups;return $w$$};let $id_app$$;
35
48
  underscore.has($ref_model$$.schema.paths,"id_app")&&($id_app$$=$user$$.current_id_app);await $_listInofOfRef_items_will_join$$.filter($item$$=>$item$$[$f$$.name]).asyncJoinModel2($id_app$$,$ref_model$$,{where:$where$$,fields:$fields$$});return null},$e$$=>{if($e$$)return $next$jscomp$0$$($e$$);$next$jscomp$0$$(null,$items$$)})};
36
49
  model.createController=($router$$,$_listInfo$$)=>{let $api_code$$=$_listInfo$$.api_code||$_listInfo$$.code;if(!$_listInfo$$.create_model)return null;let $sort$$={},$unique$$=[];let $_newList$$;$_listInfo$$.fields.filter($f$$=>$f$$.sort).forEach($f$$=>{$sort$$[$f$$.name]=$f$$.sort});if($_listInfo$$.sort_by)if(0<=$_listInfo$$.sort_by.indexOf("return ")||0===$_listInfo$$.sort_by.indexOf("{"))try{var $_newModel$jscomp$1_func_string$$=$_listInfo$$.sort_by;0>$_newModel$jscomp$1_func_string$$.indexOf("return ")&&
37
50
  ($_newModel$jscomp$1_func_string$$="return "+$_newModel$jscomp$1_func_string$$);$sort$$=evalute($_newModel$jscomp$1_func_string$$)}catch($e$$){console.error($e$$)}else $sort$$=$_listInfo$$.sort_by.split(",").reduce(($sort$$,$b$$)=>$sort$$[$b$$]=1,{});$_listInfo$$.fields.filter($f$$=>$f$$.unique).forEach($f$$=>{$unique$$.push($f$$.name)});if($_newList$$=global.controllers[$api_code$$.toUpperCase()])0<Object.keys($sort$$).length&&($_newList$$.sort=$_newList$$.options.sort=$sort$$),$_newModel$jscomp$1_func_string$$=
38
- $_newList$$.model,model.updateModel($_listInfo$$,$_newModel$jscomp$1_func_string$$),$_newList$$.is_dynamic_list&&($_newList$$.unique=$_newList$$.options.unique=$unique$$),$_newList$$.dynamicView=($user$$,$items$$,$next$$)=>{onView($_listInfo$$,$user$$,$items$$,$next$$)},$_newList$$.dynamicFinding=($user$$,$condition$$,$next$$)=>{dynamicFinding($_listInfo$$,$user$$,$condition$$,$next$$)},$_listInfo$$.fields.find($f$$=>"ma_ct"===$f$$.name)&&$_listInfo$$.postinfos&&0<$_listInfo$$.postinfos.length?($_newList$$.dynamicDeletePost=
39
- async $obj$$=>deletePost($_listInfo$$,$obj$$),$_newList$$.dynamicPost=async($obj$$,$fn$$)=>{if($_newList$$.post)$_newList$$.post($obj$$,async function($e$jscomp$0$$){if($e$jscomp$0$$)return $fn$$($e$jscomp$0$$);try{let $rs$$=await post($_listInfo$$,$obj$$);$fn$$(null,$rs$$)}catch($e$$){$fn$$($e$$.message||$e$$.error||$e$$)}});else try{let $rs$$=await post($_listInfo$$,$obj$$);$fn$$(null,$rs$$)}catch($e$$){$fn$$($e$$.message||$e$$.error||$e$$)}}):($_newList$$.dynamicPost=void 0,$_newList$$.dynamicDeletePost=
40
- void 0);else{0===Object.keys($sort$$).length&&($sort$$.date_created=-1);const $require_id_app$$=0!=$_listInfo$$.require_id_app&&"false"!=$_listInfo$$.require_id_app;$_newModel$jscomp$1_func_string$$=model.createModel($_listInfo$$);$_newList$$=new controller($router$$,$_newModel$jscomp$1_func_string$$,$api_code$$.toLowerCase(),{sort:$sort$$,unique:$unique$$,notNeedRight:$_listInfo$$.not_need_right,require_id_app:$require_id_app$$,onView:($user$$,$items$$,$next$$)=>{onView($_listInfo$$,$user$$,$items$$,
41
- $next$$)},onCreating:async($user$$,$data$$,$next$$)=>{const $supportUsers$$=configs.supportUsers||[];if(!$require_id_app$$&&0>($_listInfo$$.allow_users||"").toLowerCase().indexOf($user$$.email.toLowerCase())&&!$supportUsers$$.includes($user$$.email.toLowerCase())&&!isSupperAdmin($user$$.email.toLowerCase()))return $next$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n th\u1ef1c hi\u1ec7n thao t\u00e1c n\u00e0y");$next$$(null,$data$$)},onUpdating:async($user$$,$data$$,$obj$$,$next$$)=>{const $supportUsers$$=
42
- configs.supportUsers||[];if(!$require_id_app$$&&0>($_listInfo$$.allow_users||"").toLowerCase().indexOf($user$$.email.toLowerCase())&&!$supportUsers$$.includes($user$$.email.toLowerCase())&&!isSupperAdmin($user$$.email.toLowerCase()))return $next$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n th\u1ef1c hi\u1ec7n thao t\u00e1c n\u00e0y");$next$$(null,$data$$,$obj$$)},onDeleting:async($user$$,$obj$$,$next$$)=>{const $supportUsers$$=configs.supportUsers||[];if(!$require_id_app$$&&0>($_listInfo$$.allow_users||
43
- "").toLowerCase().indexOf($user$$.email.toLowerCase())&&!$supportUsers$$.includes($user$$.email)&&!isSupperAdmin($user$$.email.toLowerCase()))return $next$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n th\u1ef1c hi\u1ec7n thao t\u00e1c n\u00e0y");$next$$(null,$obj$$)}});$_newList$$.is_dynamic_list=!0;$_newList$$.dynamicFinding=($user$$,$condition$$,$next$$)=>{dynamicFinding($_listInfo$$,$user$$,$condition$$,$next$$)};$_listInfo$$.fields.find($f$$=>"ma_ct"===$f$$.name)&&$_listInfo$$.postinfos&&0<$_listInfo$$.postinfos.length&&
44
- ($_newList$$.dynamicDeletePost=async $obj$$=>deletePost($_listInfo$$,$obj$$),$_newList$$.dynamicPost=async($obj$$,$fn$$)=>{if($_newList$$.post)$_newList$$.post($obj$$,async function($e$jscomp$0$$){if($e$jscomp$0$$)return $fn$$($e$jscomp$0$$);try{let $rs$$=await post($_listInfo$$,$obj$$);$fn$$(null,$rs$$)}catch($e$$){$fn$$($e$$.message||$e$$.error||$e$$)}});else try{let $rs$$=await post($_listInfo$$,$obj$$);$fn$$(null,$rs$$)}catch($e$$){$fn$$($e$$.message||$e$$.error||$e$$)}});$_newList$$.route()}return $_newList$$};
45
- module.exports=model;
51
+ $_newList$$.model,model.updateModel($_listInfo$$,$_newModel$jscomp$1_func_string$$),$_newList$$.is_dynamic_list&&($_newList$$.unique=$_newList$$.options.unique=$unique$$),$_newList$$.dynamicView=($user$$,$items$$,$next$$)=>{onView($_listInfo$$,$user$$,$items$$,$next$$)},$_newList$$.dynamicFinding=($user$$,$condition$$,$next$$)=>{dynamicFinding($_listInfo$$,$user$$,$condition$$,$next$$)},$_newList$$.dynamicCreating=($user$$,$obj$$,$next$$)=>{dynamicCreating($_listInfo$$,$user$$,$obj$$,$next$$)},$_newList$$.dynamicCreated=
52
+ ($user$$,$obj$$,$next$$)=>{dynamicCreated($_listInfo$$,$user$$,$obj$$,$next$$)},$_newList$$.dynamicUpdating=($user$$,$data$$,$obj$$,$next$$)=>{dynamicUpdating($_listInfo$$,$user$$,$data$$,$obj$$,$next$$)},$_newList$$.dynamicUpdated=($user$$,$obj$$,$next$$)=>{dynamicUpdated($_listInfo$$,$user$$,$obj$$,$next$$)},$_listInfo$$.fields.find($f$$=>"ma_ct"===$f$$.name)&&$_listInfo$$.postinfos&&0<$_listInfo$$.postinfos.length?($_newList$$.dynamicDeletePost=async $obj$$=>deletePost($_listInfo$$,$obj$$),$_newList$$.dynamicPost=
53
+ async($obj$$,$fn$$)=>{if($_newList$$.post)$_newList$$.post($obj$$,async function($e$jscomp$0$$){if($e$jscomp$0$$)return $fn$$($e$jscomp$0$$);try{let $rs$$=await post($_listInfo$$,$obj$$);$fn$$(null,$rs$$)}catch($e$$){$fn$$($e$$.message||$e$$.error||$e$$)}});else try{let $rs$$=await post($_listInfo$$,$obj$$);$fn$$(null,$rs$$)}catch($e$$){$fn$$($e$$.message||$e$$.error||$e$$)}}):($_newList$$.dynamicPost=void 0,$_newList$$.dynamicDeletePost=void 0);else{0===Object.keys($sort$$).length&&($sort$$.date_created=
54
+ -1);const $require_id_app$$=0!=$_listInfo$$.require_id_app&&"false"!=$_listInfo$$.require_id_app;$_newModel$jscomp$1_func_string$$=model.createModel($_listInfo$$);$_newList$$=new controller($router$$,$_newModel$jscomp$1_func_string$$,$api_code$$.toLowerCase(),{sort:$sort$$,unique:$unique$$,notNeedRight:$_listInfo$$.not_need_right,require_id_app:$require_id_app$$,onView:($user$$,$items$$,$next$$)=>{onView($_listInfo$$,$user$$,$items$$,$next$$)},onCreating:async($user$$,$data$$,$next$$)=>{const $supportUsers$$=
55
+ configs.supportUsers||[];if(!$require_id_app$$&&0>($_listInfo$$.allow_users||"").toLowerCase().indexOf($user$$.email.toLowerCase())&&!$supportUsers$$.includes($user$$.email.toLowerCase())&&!isSupperAdmin($user$$.email.toLowerCase()))return $next$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n th\u1ef1c hi\u1ec7n thao t\u00e1c n\u00e0y");$next$$(null,$data$$)},onUpdating:async($user$$,$data$$,$obj$$,$next$$)=>{const $supportUsers$$=configs.supportUsers||[];if(!$require_id_app$$&&0>($_listInfo$$.allow_users||
56
+ "").toLowerCase().indexOf($user$$.email.toLowerCase())&&!$supportUsers$$.includes($user$$.email.toLowerCase())&&!isSupperAdmin($user$$.email.toLowerCase()))return $next$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n th\u1ef1c hi\u1ec7n thao t\u00e1c n\u00e0y");$next$$(null,$data$$,$obj$$)},onDeleting:async($user$$,$obj$$,$next$$)=>{const $supportUsers$$=configs.supportUsers||[];if(!$require_id_app$$&&0>($_listInfo$$.allow_users||"").toLowerCase().indexOf($user$$.email.toLowerCase())&&!$supportUsers$$.includes($user$$.email)&&
57
+ !isSupperAdmin($user$$.email.toLowerCase()))return $next$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n th\u1ef1c hi\u1ec7n thao t\u00e1c n\u00e0y");$next$$(null,$obj$$)}});$_newList$$.is_dynamic_list=!0;$_newList$$.dynamicFinding=($user$$,$condition$$,$next$$)=>{dynamicFinding($_listInfo$$,$user$$,$condition$$,$next$$)};$_newList$$.dynamicCreating=($user$$,$obj$$,$next$$)=>{dynamicCreating($_listInfo$$,$user$$,$obj$$,$next$$)};$_newList$$.dynamicCreated=($user$$,$obj$$,$next$$)=>{dynamicCreated($_listInfo$$,
58
+ $user$$,$obj$$,$next$$)};$_newList$$.dynamicUpdating=($user$$,$data$$,$obj$$,$next$$)=>{dynamicUpdating($_listInfo$$,$user$$,$data$$,$obj$$,$next$$)};$_newList$$.dynamicUpdated=($user$$,$obj$$,$next$$)=>{dynamicUpdated($_listInfo$$,$user$$,$obj$$,$next$$)};$_listInfo$$.fields.find($f$$=>"ma_ct"===$f$$.name)&&$_listInfo$$.postinfos&&0<$_listInfo$$.postinfos.length&&($_newList$$.dynamicDeletePost=async $obj$$=>deletePost($_listInfo$$,$obj$$),$_newList$$.dynamicPost=async($obj$$,$fn$$)=>{if($_newList$$.post)$_newList$$.post($obj$$,
59
+ async function($e$jscomp$0$$){if($e$jscomp$0$$)return $fn$$($e$jscomp$0$$);try{let $rs$$=await post($_listInfo$$,$obj$$);$fn$$(null,$rs$$)}catch($e$$){$fn$$($e$$.message||$e$$.error||$e$$)}});else try{let $rs$$=await post($_listInfo$$,$obj$$);$fn$$(null,$rs$$)}catch($e$$){$fn$$($e$$.message||$e$$.error||$e$$)}});$_newList$$.route()}return $_newList$$};module.exports=model;
@@ -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},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},tu_gio:{type:Date},
5
- 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,line:{type:Number,default:0}});detailSchema.validate={ma_vt:validVt.existsVt,ma_dvt:validator.existsDvt};
5
+ 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,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,
@@ -2,5 +2,5 @@
2
2
  default:0},du_nt00:{type:Number,default:0},kc_yn:{type:Boolean,default:!1},status:{type:Boolean,default:!0},date_created:{type:Date,default:Date.now},date_updated:{type:Date,default:Date.now},user_created:{type:String,default:""},user_updated:{type:String,default:""}});tontucthoiScheam.index({id_app:1,nam:1,ma_dvcs:1,ma_vt:1,ma_kho:1,ma_lo:1,ma_tt1:1,ma_tt2:1,ma_tt3:1},{name:"tontucthoi_index_1"});tontucthoiScheam.index({status:1});tontucthoiScheam.index({user_created:1,visible_to:1,visible_to_users:1});
3
3
  const tontucthoi=mongoose.models.tontucthoi||mongoose.model("tontucthoi",tontucthoiScheam),ckvt=require("../libs/ckvt"),underscore=require("underscore"),async=require("async");
4
4
  tontucthoi.tinhTonTucThoi=function($sks$$,$cb$$){$cb$$||($cb$$=function($e$$){$e$$&&console.log("error when calc tontucthoi",$e$$)});underscore.isArray($sks$$)||($sks$$=[$sks$$]);async.map($sks$$,function($sk$$,$cb$$){if(!$sk$$)return $cb$$();let $query$$={id_app:$sk$$.id_app,ma_vt:$sk$$.ma_vt};$sk$$.ma_kho&&($query$$.ma_kho=$sk$$.ma_kho);$sk$$.ma_dvcs&&($query$$.ma_dvcs=$sk$$.ma_dvcs);$sk$$.ma_lo&&($query$$.ma_lo=$sk$$.ma_lo);$sk$$.han_sd&&($query$$.han_sd=$sk$$.han_sd);$sk$$.ma_tt1&&($query$$.ma_tt1=
5
- $sk$$.ma_tt1);$sk$$.ma_tt2&&($query$$.ma_tt2=$sk$$.ma_tt2);$sk$$.ma_tt3&&($query$$.ma_tt3=$sk$$.ma_tt3);tontucthoi.deleteMany($query$$,function($e$jscomp$2$$){if($e$jscomp$2$$)return $cb$$("remove tonkhotucthoi");$query$$.groupBy="id_app ma_vt ma_kho ma_dvcs ma_lo ma_tt1 ma_tt2 ma_tt3 han_sd".split(" ");$query$$.ngay=new Date;ckvt($query$$,function($e$jscomp$0$$,$rs$$){if($e$jscomp$0$$)return $cb$$("error when calc tontucthoi\n"+$e$jscomp$0$$);($rs$$=$rs$$.filter($r$$=>$r$$.ma_vt&&$r$$.ma_kho&&$r$$.id_app))&&
6
- 0<$rs$$.length?tontucthoi.create($rs$$,function($e$$){if($e$$)return $cb$$($e$$);$cb$$(null,$rs$$)}):$cb$$()})})},function($e$$,$rs$$){$cb$$($e$$,$rs$$)})};module.exports=tontucthoi;
5
+ $sk$$.ma_tt1);$sk$$.ma_tt2&&($query$$.ma_tt2=$sk$$.ma_tt2);$sk$$.ma_tt3&&($query$$.ma_tt3=$sk$$.ma_tt3);tontucthoi.deleteMany($query$$,function($e$jscomp$2$$){if($e$jscomp$2$$)return $cb$$("remove tonkhotucthoi");$query$$.groupBy="id_app ma_vt ma_kho ma_dvcs ma_lo ma_tt1 ma_tt2 ma_tt3 han_sd".split(" ");$query$$.ngay=new Date;ckvt($query$$,function($e$jscomp$1$$,$rs$$){if($e$jscomp$1$$)return $cb$$("error when calc tontucthoi\n"+$e$jscomp$1$$);($rs$$=$rs$$.filter($r$$=>$r$$.ma_vt&&$r$$.ma_kho&&$r$$.id_app))&&
6
+ 0<$rs$$.length?tontucthoi.create($rs$$,async function($e$jscomp$0$$){if($e$jscomp$0$$)return $cb$$($e$jscomp$0$$);if($e$jscomp$0$$=await global.getModel("dmvt").findOne({id_app:$sk$$.id_app,ma_vt:$sk$$.ma_vt}))$e$jscomp$0$$.ton_kho_hien_tai=$rs$$.map($r$$=>$r$$.ton00||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0),$e$jscomp$0$$.save($e$$=>{$e$$&&console.error($e$$)});$cb$$(null,$rs$$)}):$cb$$()})})},function($e$$,$rs$$){$cb$$($e$$,$rs$$)})};module.exports=tontucthoi;
@@ -1,4 +1,4 @@
1
1
  'use strict';const introducebonus=global.getModel("introducebonus"),User=global.getModel("user"),controller=require("../../controllers/controllerRPT");
2
- module.exports=function($router$$){new controller($router$$,"bcintroducebonus",function($query_req$$,$callback$$){const $condition$$=$query_req$$.query;$query_req$$={id_app:$condition$$.id_app};$condition$$.user_received&&($query_req$$.user_received=$condition$$.user_received);$condition$$.tu_ngay&&($query_req$$.ngay_ct={$gte:$condition$$.tu_ngay});$condition$$.den_ngay&&($query_req$$.ngay_ct?$query_req$$.ngay_ct.$lte=$condition$$.den_ngay:$query_req$$.ngay_ct={$lte:$condition$$.den_ngay});$condition$$.type&&
3
- ($query_req$$.type=$condition$$.type);introducebonus.find($query_req$$).lean().exec(async($e$$,$rs$$)=>{if($e$$)return $callback$$($e$$);await $rs$$.asyncJoinModel2($condition$$.id_app,User,{where:{user_received:"email"},fields:{user_received_name:"name"}});$rs$$.forEach($r$$=>{switch($r$$.type){case "1":$r$$.type_name="Thu nh\u1eadp t\u1eeb gi\u1edbi thi\u1ec7u ng\u01b0\u1eddi s\u1eed d\u1ee5ng";break;case "2":$r$$.type_name="Thu nh\u1eadp khi s\u1eed d\u1ee5ng m\u00e3 gi\u1edbi thi\u1ec7u \u0111\u1ec3 \u0111\u0103ng k\u00fd";
2
+ module.exports=function($router$$){new controller($router$$,"bcintroducebonus",function($condition_req$$,$callback$$){$condition_req$$=$condition_req$$.query;const $query$$={id_app:$condition_req$$.id_app};$condition_req$$.user_received&&($query$$.user_received=$condition_req$$.user_received);$condition_req$$.tu_ngay&&($query$$.ngay_ct={$gte:$condition_req$$.tu_ngay});$condition_req$$.den_ngay&&($query$$.ngay_ct?$query$$.ngay_ct.$lte=$condition_req$$.den_ngay:$query$$.ngay_ct={$lte:$condition_req$$.den_ngay});
3
+ $condition_req$$.type&&($query$$.type=$condition_req$$.type);introducebonus.find($query$$).lean().exec(async($e$$,$rs$$)=>{if($e$$)return $callback$$($e$$);await $rs$$.asyncJoinModel2(null,User,{where:{user_received:"email"},fields:{user_received_name:"name"}});$rs$$.forEach($r$$=>{switch($r$$.type){case "1":$r$$.type_name="Thu nh\u1eadp t\u1eeb gi\u1edbi thi\u1ec7u ng\u01b0\u1eddi s\u1eed d\u1ee5ng";break;case "2":$r$$.type_name="Thu nh\u1eadp khi s\u1eed d\u1ee5ng m\u00e3 gi\u1edbi thi\u1ec7u \u0111\u1ec3 \u0111\u0103ng k\u00fd";
4
4
  break;case "3":$r$$.type_name="Thu nh\u1eadp t\u1eeb giao d\u1ecbch c\u1ee7a ng\u01b0\u1eddi \u0111\u01b0\u1ee3c gi\u1edbi thi\u1ec7u"}});$callback$$(null,$rs$$)})})};
@@ -1,3 +1,4 @@
1
1
  'use strict';const ckvt=require("../../libs/ckvt"),Dmvt=global.getModel("dmvt"),Dmkho=global.getModel("dmkho"),async=require("async"),controller=require("../../controllers/controllerRPT");
2
2
  module.exports=function($router$$){new controller($router$$,"ckvt",function($req$$,$callback$jscomp$0$$){const $condition$$=$req$$.query;ckvt($condition$$,function($error$jscomp$0$$,$report$$){if($error$jscomp$0$$)return $callback$jscomp$0$$($error$jscomp$0$$);$report$$=$report$$.filter($r$$=>$r$$.ton00||$r$$.du00);async.parallel([function($callback$$){$report$$.joinModel2($condition$$.id_app,Dmvt,[{where:{ma_vt:"ma_vt"},fields:["ten_vt","ma_dvt","tk_vt"]}],function($results$$){$callback$$(null,$results$$)})},
3
- function($callback$$){$report$$.joinModel2($condition$$.id_app,Dmkho,[{where:{ma_kho:"ma_kho"},fields:["ten_kho"]}],function($results$$){$callback$$(null,$results$$)})}],function($error$$){if($error$$)return $callback$jscomp$0$$($error$$);$callback$jscomp$0$$(null,$report$$)})})})};
3
+ function($callback$$){$report$$.joinModel2($condition$$.id_app,Dmkho,[{where:{ma_kho:"ma_kho"},fields:["ten_kho"]}],function($results$$){$callback$$(null,$results$$)})}],async function($error$$){if($error$$)return $callback$jscomp$0$$($error$$);(await $report$$.filter($r$$=>$r$$.ma_vt).asyncGroupBy(["ma_vt"],["ton00"])).forEach(async $sk$$=>{let $vt$$=await global.getModel("dmvt").findOne({id_app:$condition$$.id_app,ma_vt:$sk$$.ma_vt});$vt$$&&($vt$$.ton_kho_hien_tai=$sk$$.ton00,$vt$$.save($e$$=>{$e$$&&
4
+ console.error($e$$)}))});$callback$jscomp$0$$(null,$report$$)})})})};
@@ -7,4 +7,4 @@ $user$$.current_id_app;async.parallel({dv:function($callback$$){$items$$.joinMod
7
7
  function(){$callback$$()})},kho:function($callback$$){$items$$.joinModel2(null,dmkho,[{where:{ma_kho:"ma_kho"},fields:["ten_kho"]}],function(){$callback$$()})},tinhtong:function($callback$$){$items$$.forEach($item$$=>{$item$$.t_sl=($item$$.details||[]).csum("so_luong")});$callback$$()},details_vt:function($callback$$){async.each($items$$,function($r$$,$callback1$$){($r$$.details||[]).joinModel2($id_app$$,dmvt,[{where:"ma_vt",fields:["ten_vt","tk_vt"]}],function(){$callback1$$()})},function(){$callback$$()})},
8
8
  san_pham:function($callback$$){async.each($items$$,function($r$$,$callback1$$){($r$$.details||[]).joinModel2($id_app$$,dmvt,[{where:{ma_sp:"ma_vt"},fields:{ten_sp:"ten_vt"}}],function(){$callback1$$()})},function(){$callback$$()})},sale_contract:function($callback$$){$items$$.joinModel2($id_app$$,sale_contract,{where:{id_contract:"_id"},fields:{so_ct_contract:"so_ct"}},function(){$callback$$()})},lenhsx:function($callback$$){$items$$.joinModel2($id_app$$,lenhsx,{where:{id_lenhsx:"_id"},fields:{so_lenh_sx:"so_ct"}},
9
9
  function(){$callback$$()})},congdoansx:function($callback$$){async.each($items$$,function($r$$,$callback1$$){($r$$.details||[]).joinModel2($id_app$$,congdoansx,{where:{ma_cong_doan:"ma_cong_doan"},fields:{ten_cong_doan:"ten_cong_doan"}},function(){$callback1$$()})},function(){$callback$$()})}},function(){async.map($items$$,($item$$,$callback$$)=>{pxk.find({id_lenhcapphat:$item$$._id}).lean().exec(($e$$,$pxks$$)=>{if(!$item$$.details)return $callback$$();$item$$.details.forEach($d$$=>{$d$$.sl_da_xuat=
10
- $pxks$$.map($xk$$=>$xk$$.details.filter($_d$$=>$d$$.ma_vt===$_d$$.ma_vt).csum("sl_xuat")).reduce(($a$$,$b$$)=>$a$$+$b$$,0)});$item$$.t_sl_da_xuat=$item$$.details.csum("sl_da_xuat");$callback$$()})},()=>{$fn$$(null,$items$$)})})}};
10
+ $pxks$$.map($xk$$=>$xk$$.details.filter($_d$$=>$d$$.ma_vt===$_d$$.ma_vt).csum("sl_xuat")).reduce(($a$$,$b$$)=>$a$$+$b$$,0)});$item$$.t_sl_da_xuat=$pxks$$.map($xk$$=>$xk$$.details.csum("sl_xuat")).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$callback$$()})},()=>{$fn$$(null,$items$$)})})}};
@@ -66,40 +66,41 @@ $rs$jscomp$0$$)=>{let $option$$;$option$$=$rs$jscomp$0$$?$rs$jscomp$0$$.option||
66
66
  {};$pt$$.tk_tien=$pt$$.tk_cn;$pt$$.tk_cn=$pt$$.tk_cn||$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_cn;$pt$$.tk_dt=$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_dt||$pt$$.tk_dt;$pt$$.tk_gv=$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_gv||$pt$$.tk_gv;$pt$$.tk_ck=$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_ck||$pt$$.tk_ck;$pt$$.tk_cp_gh=$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_cp_gh||
67
67
  $pt$$.tk_cp_gh;$pt$$.tk_cp_bh=$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_cp_bh||$pt$$.tk_cp_bh;$pt$$.tk_cp_ctv=$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_cp_ctv||$pt$$.tk_cp_ctv;$pt$$.tk_cn_ctv=$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_cn_ctv||$pt$$.tk_cn_ctv;$option$$.tk_tien=$pt$$.tk_tien||$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_tien||$option$$.tk_tien||"1111";$option$$.tk_cn=
68
68
  $pt$$.tk_cn||$option$$.tk_cn||"131111";$option$$.tk_dt=$pt$$.tk_dt||$option$$.tk_dt||"51111";$option$$.tk_tl=$pt$$.tk_tl||$option$$.tk_tl||"52131";$option$$.tk_ck=$pt$$.tk_ck||$option$$.tk_ck||"52111";$option$$.tk_gv=$pt$$.tk_gv||$option$$.tk_gv||"6321";$option$$.tk_cp_gh=$pt$$.tk_cp_gh||$option$$.tk_cp_gh||"6418";$option$$.tk_cp_bh=$pt$$.tk_cp_bh||$option$$.tk_cp_bh||$option$$.tk_ck;$option$$.tk_cp_ctv=$pt$$.tk_cp_ctv||$option$$.tk_cp_ctv;$option$$.tk_cn_ctv=$pt$$.tk_cn_ctv||$option$$.tk_cn_ctv;
69
- $option$$.ma_kh="COD"===$pt$$.ten?$obj$$.nhan_vien_giao_hang||$obj$$.don_vi_vc||$pt$$.ma_kh||$obj$$.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.round($detail$$.tien_ct/($detail$$.sl_xuat||1)),$detail$$.gia_ban_ct_nt=
70
- Math.round($detail$$.tien_ct_nt/($detail$$.sl_xuat||1)),$detail$$.tien_ct=$detail$$.sl_xuat*$detail$$.gia_ban_ct,$detail$$.tien_ct_nt=$detail$$.sl_xuat*$detail$$.gia_ban_ct_nt,$detail$$.tien_thue=Math.round($detail$$.tien_ct*$detail$$.thue_suat/100),$detail$$.tien_thue_nt=Math.round($detail$$.tien_ct_nt*$detail$$.thue_suat/100)):($detail$$.tien_ck_ct_nt=$detail$$.tien_ck_nt,$detail$$.tien_ck_ct=$detail$$.tien_ck,$detail$$.tien_thue=0,$detail$$.tien_thue_nt=0,$detail$$.tien_ct=$detail$$.tien,$detail$$.tien_ct_nt=
71
- $detail$$.tien_nt)});const $details$$=[];$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$=$obj$$.details.map($a$$=>($a$$.tien_hang_nt||0)-($a$$.tien_ck_nt||0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0)-(($obj$$.tt_tien_thuong||0)+($obj$$.tien_ck_hd||0)+($obj$$.tien_evoucher||0));$rs$jscomp$0$$=$obj$$.tien_paymentByPoints||0;const $hoachtoandtvathue$$=($tk_tien$$,$ty_le$$)=>{$obj$$.details.forEach(function($d$jscomp$34_detail$$){$d$jscomp$34_detail$$={...$d$jscomp$34_detail$$};$d$jscomp$34_detail$$.tk_co=
72
- $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.round($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$$=>$d$$.tien_thue).forEach($detail$$=>{$detail$$=
73
- {...$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.round($detail$$.tien_thue_nt*$ty_le$$);$detail$$.flag="THUE_"+($detail$$.ma_vt||"");$details$$.push($detail$$)});console.log("post socai",$tk_tien$$,$ty_le$$)};$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$&&($hoachtoandtvathue$$($option$$.tk_cn,$rs$jscomp$0$$/$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$),
74
- $hoachtoandtvathue$$($option$$.tk_tien,($error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$-$rs$jscomp$0$$)/$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$));$obj$$.details.filter($d$$=>$d$$.diem_thuong&&$d$$.tk_km_no&&$d$$.tk_km_co).forEach(function($d$$){let $detail$$={...$d$$};$detail$$.tk_co=$option$$.tk_km_co||$d$$.tk_km_co;$detail$$.tk_no=$option$$.tk_km_no||$d$$.tk_km_no;$detail$$.ma_kh=$obj$$.ma_kh;$detail$$.tien=$detail$$.tien_nt=$detail$$.diem_thuong*
75
- $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=$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;
76
- $details$$.push($d$jscomp$38_detail$$)});$obj$$.tien_phi_vc&&($error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$={},$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_co=$option$$.tk_dt,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_no=$option$$.tk_cn,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt=$obj$$.tien_phi_vc||0,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien=$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt,
77
- $error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_co=$obj$$.ma_kh,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_no=$obj$$.nhan_vien_giao_hang||$obj$$.don_vi_vc,$details$$.push($error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$));$obj$$.tien_freeship&&($error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$={},$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_no=$option$$.tk_cp_gh,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_co=
78
- $option$$.tk_cn,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt=$obj$$.tien_freeship||0,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien=$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_no=$obj$$.ma_kh,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_co=$option$$.ma_kh,$details$$.push($error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$));
79
- $obj$$.tt_tien_thuong&&($error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$={},$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_no=$option$$.tk_cp_bh,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_co=$option$$.tk_cn,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt=$obj$$.tt_tien_thuong||0,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien=$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt,
80
- $error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_no=$obj$$.ma_kh,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_co=$option$$.ma_kh,$details$$.push($error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$));$obj$$.thu_nhap_ctv&&$option$$.tk_cp_ctv&&$option$$.tk_cn_ctv&&($error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$={},$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_no=$option$$.tk_cp_ctv,
81
- $error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_co=$option$$.tk_cn_ctv,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt=$obj$$.thu_nhap_ctv||0,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien=$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh=$obj$$.ma_ctv,$details$$.push($error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$));
82
- if($obj$$.tien_ck_hd||$obj$$.tien_evoucher)$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$={},$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_no=$option$$.tk_ck,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_co=$option$$.tk_cn,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt=($obj$$.tien_ck_hd||0)+($obj$$.tien_evoucher||0),$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien=$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt,
83
- $error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_no=$obj$$.ma_kh,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_co=$option$$.ma_kh,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.check_balance=!1,$details$$.push($error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$);let $details_tienvon$$=[...$obj$$.details];$details_tienvon$$.joinModel2($obj$$.id_app,dmvt,{where:"ma_vt",fields:["tk_vt","gia_mua","tk_gv","tg_tk"]},
84
- ()=>{$details_tienvon$$.forEach(function($d$jscomp$39_detail$$){$d$jscomp$39_detail$$={...$d$jscomp$39_detail$$};$d$jscomp$39_detail$$.tk_no=$option$$.tk_gv;$d$jscomp$39_detail$$.ma_kh=$obj$$.ma_kh;$d$jscomp$39_detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;$d$jscomp$39_detail$$.tk_co=$d$jscomp$39_detail$$.tk_vt||"1561";$d$jscomp$39_detail$$.tien_nt=$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=
85
- $d$jscomp$39_detail$$.tien_nt=0);$details$$.push($d$jscomp$39_detail$$)});(new PostSocai($obj$$,$details$$,null,Socaitmp)).run(function($e$$,$rs$$){console.log("post result",$rs$$);$callback$$($e$$,$rs$$)})})})}},function($e$$,$rs$$){$fn$$($e$$,$rs$$)})};$contr_router$$.creating=async function($user$$,$obj$$,$next$$){$obj$$.details||($obj$$.details=[]);if(!$obj$$.ma_kh){let $kh$$=await customer.findOne({id_app:$obj$$.id_app||$user$$.current_id_app,of_user:$user$$.email},{ma_kh:-1});$kh$$&&($obj$$.ma_kh=
86
- $kh$$.ma_kh)}delete $obj$$.virtual_payment_client_url;valid($user$$,$obj$$,async $error$$=>{if($error$$)return $next$$($error$$);if(!$obj$$.paymentByPoints)return $next$$(null,$obj$$);try{if(await getPointBalance($user$$.current_id_app,$obj$$.of_user||$user$$.email)<$obj$$.paymentByPoints)return $next$$("B\u1ea1n kh\u00f4ng c\u00f3 \u0111\u1ee7 \u0111i\u1ec3m \u0111\u1ec3 th\u1ef1c hi\u1ec7n giao d\u1ecbch n\u00e0y.");$next$$(null,$obj$$)}catch($e$$){$next$$($e$$.message)}})};$contr_router$$.created=
87
- async function($user$$,$obj$$,$next$$){if($obj$$.pt_thanh_toan&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan))try{const $pt_thanh_toan$$=await global.getModel("ptthanhtoan").findOne({_id:$obj$$.pt_thanh_toan});if($pt_thanh_toan$$.payment_service){let $paymentServiceModel$$=global.getModel($pt_thanh_toan$$.payment_service);$obj$$.amount=$obj$$.t_tt_nt-($obj$$.tien_paymentByPoints||0);console.log("payment by",$pt_thanh_toan$$.payment_service,$obj$$.amount);if($obj$$.amount){let $virtual_payment_client_url$$=
88
- 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=""}else $obj$$.virtual_payment_client_url=""}catch($e$$){return console.error($e$$),
89
- $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$$);await createTransactionBonus($obj$$);$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>
90
- updateEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$next$$(null,$obj$$)};$contr_router$$.updating=async($user$$,$data$$,$obj$$,$next$$)=>{$data$$.pt_thanh_toan&&$data$$.pt_thanh_toan!=$obj$$.pt_thanh_toan&&($data$$.virtual_payment_client_url="",$data$$.payment_service="",$data$$.payment_id="");$data$$.evouchers=$data$$.evouchers||$obj$$.evouchers||[];valid($user$$,$data$$,async $error$$=>{if($error$$)return $next$$($error$$);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.");
91
- 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$$=
92
- global.getModel($pt_thanh_toan$$.payment_service);$obj$$.amount=$obj$$.t_tt_nt-($obj$$.tien_paymentByPoints||0);if($obj$$.amount){let $virtual_payment_client_url$$=await $paymentServiceModel$$.createVirtualPaymentClientURL($obj$$,$evouchers_user$$.clientIp,$pt_thanh_toan$$);$obj$$.virtual_payment_client_url=$virtual_payment_client_url$$;$obj$$.payment_service=$pt_thanh_toan$$.payment_service;$obj$$.payment_id=((await $paymentServiceModel$$.findOne({id_ct:$obj$$._id.toString()})||{})._id||"").toString()}else $obj$$.virtual_payment_client_url=
93
- "",$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",$e$$.message)})}"9"===$obj$$.trang_thai?(await transaction.deleteTrans({id_ct:$obj$$._id.toString()}),
94
- await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng"),await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":buy"})):(await createTransactionPayment($obj$$),createTransactionBonus($obj$$));await Evoucher.updateMany({id_ct_used:$obj$$._id.toString()},{id_ct_used:null});$evouchers_user$$=await Evoucher.find({id_ct_useds:$obj$$._id.toString()});await Promise.all($evouchers_user$$.map($e$$=>deleteEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));
95
- $obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>updateEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$next$$(null,$obj$$)};$contr_router$$.deleting=function($user$$,$obj$$,$next$$){$next$$(null,$obj$$)};$contr_router$$.deleted=async function($user$$,$obj$$,$next$$){await transaction.deleteTrans({id_ct:$obj$$._id.toString()});await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng");await transaction.deleteTrans({id_ct:$obj$$._id.toString()+
96
- ":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$$){let $id_app$$=$user$$.current_id_app;async.parallel({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$$,
97
- 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$$()})},kho:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kho).joinModel2($id_app$$,dmkho,[{where:"ma_kho",fields:["ten_kho",{tk_cn_kho:"tk_cn"}]}],function(){$callback$$()})},
98
- trangthai:function($callback$$){$items$$.filter($item$$=>$item$$.trang_thai).joinModel2(null,trangthai,[{where:{trang_thai:"ma_trang_thai",ma_ct:"ma_ct"},fields:["ten_trang_thai","color"]}],function(){$callback$$()})},ptthanhtoan:function($callback$$){$items$$.filter($item$$=>$item$$.pt_thanh_toan).joinModel2($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$$,
99
- pt1,[{where:{_id:"id_so1"},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=$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-
100
- $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,$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-
101
- $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($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$$.joinModel2($id_app$$,dmvt,[{where:"ma_vt",fields:"ten_vt picture chieu_cao chieu_rong chieu_sau trong_luong".split(" ")}],function(){$callback1$$()})},function(){$callback$$()})},
102
- details_tt1:function($callback$$){async.map($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$$()})},function(){$callback$$()})},details_dt:function($callback$$){async.map($items$$,function($details$jscomp$6_r$$,$callback1$$){$details$jscomp$6_r$$=$details$jscomp$6_r$$.details;if(!$details$jscomp$6_r$$)return $callback1$$();
103
- $details$jscomp$6_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.map($items$$,function($details$jscomp$7_r$$,$callback1$$){$details$jscomp$7_r$$=$details$jscomp$7_r$$.details;if(!$details$jscomp$7_r$$)return $callback1$$();$details$jscomp$7_r$$.filter($item$$=>$item$$.ma_hd).joinModel2($id_app$$,contract,[{where:{ma_hd:"so_hd"},fields:["ten_hd"]}],
104
- function(){$callback1$$()})},function(){$callback$$()})},details_phi:function($callback$$){async.map($items$$,function($details$jscomp$8_r$$,$callback1$$){$details$jscomp$8_r$$=$details$jscomp$8_r$$.details;if(!$details$jscomp$8_r$$)return $callback1$$();$details$jscomp$8_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$$,
105
- $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,$items$$)})}};
69
+ $pt$$.ten&&0<=$pt$$.ten.indexOf("COD")?$option$$.ma_kh=$obj$$.nhan_vien_giao_hang||$obj$$.don_vi_vc||$pt$$.ma_kh||$obj$$.ma_kh:$option$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh;$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.round($detail$$.tien_ct/($detail$$.sl_xuat||
70
+ 1)),$detail$$.gia_ban_ct_nt=Math.round($detail$$.tien_ct_nt/($detail$$.sl_xuat||1)),$detail$$.tien_ct=$detail$$.sl_xuat*$detail$$.gia_ban_ct,$detail$$.tien_ct_nt=$detail$$.sl_xuat*$detail$$.gia_ban_ct_nt,$detail$$.tien_thue=Math.round($detail$$.tien_ct*$detail$$.thue_suat/100),$detail$$.tien_thue_nt=Math.round($detail$$.tien_ct_nt*$detail$$.thue_suat/100)):($detail$$.tien_ck_ct_nt=$detail$$.tien_ck_nt,$detail$$.tien_ck_ct=$detail$$.tien_ck,$detail$$.tien_thue=0,$detail$$.tien_thue_nt=0,$detail$$.tien_ct=
71
+ $detail$$.tien,$detail$$.tien_ct_nt=$detail$$.tien_nt)});const $details$$=[];$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$=$obj$$.details.map($a$$=>($a$$.tien_hang_nt||0)-($a$$.tien_ck_nt||0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0)-(($obj$$.tt_tien_thuong||0)+($obj$$.tien_ck_hd||0)+($obj$$.tien_evoucher||0));$rs$jscomp$0$$=$obj$$.tien_paymentByPoints||0;const $hoachtoandtvathue$$=($tk_tien$$,$ty_le$$)=>{$obj$$.details.forEach(function($d$jscomp$34_detail$$){$d$jscomp$34_detail$$=
72
+ {...$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.round($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$$=>
73
+ $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.round($detail$$.tien_thue_nt*$ty_le$$);$detail$$.flag="THUE_"+($detail$$.ma_vt||"");$details$$.push($detail$$)});console.log("post socai",$tk_tien$$,$ty_le$$)};$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$&&($hoachtoandtvathue$$($option$$.tk_cn,$rs$jscomp$0$$/
74
+ $error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$),$hoachtoandtvathue$$($option$$.tk_tien,($error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$-$rs$jscomp$0$$)/$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$));$obj$$.details.filter($d$$=>$d$$.diem_thuong&&$d$$.tk_km_no&&$d$$.tk_km_co).forEach(function($d$$){let $detail$$={...$d$$};$detail$$.tk_co=$option$$.tk_km_co||$d$$.tk_km_co;$detail$$.tk_no=$option$$.tk_km_no||$d$$.tk_km_no;$detail$$.ma_kh=
75
+ $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=$option$$.ma_kh;$d$jscomp$38_detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;$d$jscomp$38_detail$$.tien_nt=
76
+ $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&&($error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$={},$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_co=$option$$.tk_dt,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_no=$option$$.tk_cn,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt=$obj$$.tien_phi_vc||
77
+ 0,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien=$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_co=$obj$$.ma_kh,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_no=$obj$$.nhan_vien_giao_hang||$obj$$.don_vi_vc,$details$$.push($error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$));$obj$$.tien_freeship&&($error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$=
78
+ {},$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_no=$option$$.tk_cp_gh,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_co=$option$$.tk_cn,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt=$obj$$.tien_freeship||0,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien=$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_no=
79
+ $obj$$.ma_kh,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_co=$option$$.ma_kh,$details$$.push($error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$));$obj$$.tt_tien_thuong&&($error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$={},$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_no=$option$$.tk_cp_bh,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_co=$option$$.tk_cn,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt=
80
+ $obj$$.tt_tien_thuong||0,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien=$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_no=$obj$$.ma_kh,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_co=$option$$.ma_kh,$details$$.push($error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$));$obj$$.thu_nhap_ctv&&$option$$.tk_cp_ctv&&$option$$.tk_cn_ctv&&
81
+ ($error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$={},$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_no=$option$$.tk_cp_ctv,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_co=$option$$.tk_cn_ctv,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt=$obj$$.thu_nhap_ctv||0,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien=$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt,
82
+ $error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh=$obj$$.ma_ctv,$details$$.push($error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$));if($obj$$.tien_ck_hd||$obj$$.tien_evoucher)$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$={},$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_no=$option$$.tk_ck,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tk_co=$option$$.tk_cn,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt=
83
+ ($obj$$.tien_ck_hd||0)+($obj$$.tien_evoucher||0),$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien=$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_no=$obj$$.ma_kh,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_co=$option$$.ma_kh,$error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$.check_balance=!1,$details$$.push($error$jscomp$2_kho_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$$);
84
+ let $details_tienvon$$=[...$obj$$.details];$details_tienvon$$.joinModel2($obj$$.id_app,dmvt,{where:"ma_vt",fields:["tk_vt","gia_mua","tk_gv","tg_tk"]},()=>{$details_tienvon$$.forEach(function($d$jscomp$39_detail$$){$d$jscomp$39_detail$$={...$d$jscomp$39_detail$$};$d$jscomp$39_detail$$.tk_no=$option$$.tk_gv;$d$jscomp$39_detail$$.ma_kh=$obj$$.ma_kh;$d$jscomp$39_detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;$d$jscomp$39_detail$$.tk_co=$d$jscomp$39_detail$$.tk_vt||"1561";$d$jscomp$39_detail$$.tien_nt=
85
+ $d$jscomp$39_detail$$.tien_xuat_nt;$d$jscomp$39_detail$$.tien=$d$jscomp$39_detail$$.tien_xuat;$d$jscomp$39_detail$$.tg_tk||($d$jscomp$39_detail$$.tien=$d$jscomp$39_detail$$.tien_nt=0);$details$$.push($d$jscomp$39_detail$$)});(new PostSocai($obj$$,$details$$,null,Socaitmp)).run(function($e$$,$rs$$){console.log("post result",$rs$$);$callback$$($e$$,$rs$$)})})})}},function($e$$,$rs$$){$fn$$($e$$,$rs$$)})};$contr_router$$.creating=async function($user$$,$obj$$,$next$$){$obj$$.details||($obj$$.details=
86
+ []);if(!$obj$$.ma_kh){let $kh$$=await customer.findOne({id_app:$obj$$.id_app||$user$$.current_id_app,of_user:$user$$.email},{ma_kh:-1});$kh$$&&($obj$$.ma_kh=$kh$$.ma_kh)}delete $obj$$.virtual_payment_client_url;valid($user$$,$obj$$,async $error$$=>{if($error$$)return $next$$($error$$);if(!$obj$$.paymentByPoints)return $next$$(null,$obj$$);try{if(await getPointBalance($user$$.current_id_app,$obj$$.of_user||$user$$.email)<$obj$$.paymentByPoints)return $next$$("B\u1ea1n kh\u00f4ng c\u00f3 \u0111\u1ee7 \u0111i\u1ec3m \u0111\u1ec3 th\u1ef1c hi\u1ec7n giao d\u1ecbch n\u00e0y.");
87
+ $next$$(null,$obj$$)}catch($e$$){$next$$($e$$.message)}})};$contr_router$$.created=async function($user$$,$obj$$,$next$$){if($obj$$.pt_thanh_toan&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan))try{const $pt_thanh_toan$$=await global.getModel("ptthanhtoan").findOne({_id:$obj$$.pt_thanh_toan});if($pt_thanh_toan$$.payment_service){let $paymentServiceModel$$=global.getModel($pt_thanh_toan$$.payment_service);$obj$$.amount=$obj$$.t_tt_nt-($obj$$.tien_paymentByPoints||0);console.log("payment by",
88
+ $pt_thanh_toan$$.payment_service,$obj$$.amount);if($obj$$.amount){let $virtual_payment_client_url$$=await $paymentServiceModel$$.createVirtualPaymentClientURL($obj$$,$user$$.clientIp,$pt_thanh_toan$$);$obj$$.virtual_payment_client_url=$virtual_payment_client_url$$;$obj$$.payment_service=$pt_thanh_toan$$.payment_service;$obj$$.payment_id=((await $paymentServiceModel$$.findOne({id_ct:$obj$$._id.toString()})||{})._id||"").toString()}else $obj$$.virtual_payment_client_url="",$obj$$.payment_service="",
89
+ $obj$$.payment_id=""}else $obj$$.virtual_payment_client_url=""}catch($e$$){return console.error($e$$),$next$$("Kh\u00f4ng tao li\u00ean k\u1ebft thanh to\u00e1n:"+($e$$.message||$e$$.error||$e$$))}else console.log("Chua nhap phuong thuc thanh toan"),$obj$$.virtual_payment_client_url="";model.findOneAndUpdate({_id:$obj$$._id},{virtual_payment_client_url:$obj$$.virtual_payment_client_url},$e$$=>{$e$$&&(console.error($e$$),console.log("error create Virtual Payment ClientURL",$e$$.message))});await createTransactionPayment($obj$$);
90
+ await createTransactionBonus($obj$$);$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>updateEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$next$$(null,$obj$$)};$contr_router$$.updating=async($user$$,$data$$,$obj$$,$next$$)=>{$data$$.pt_thanh_toan&&$data$$.pt_thanh_toan!=$obj$$.pt_thanh_toan&&($data$$.virtual_payment_client_url="",$data$$.payment_service="",$data$$.payment_id="");$data$$.evouchers=$data$$.evouchers||$obj$$.evouchers||[];valid($user$$,$data$$,async $error$$=>{if($error$$)return $next$$($error$$);
91
+ if(($obj$$.paymentByPoints||0)!==($data$$.paymentByPoints||0))return $next$$("B\u1ea1n kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt s\u1ed1 \u0111i\u1ec3m thanh to\u00e1n.");await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":buy"});$next$$(null,$data$$,$obj$$)},$obj$$)};$contr_router$$.updated=async function($evouchers_user$$,$obj$$,$next$$){if(!$obj$$.virtual_payment_client_url&&("1"===$obj$$.trang_thai||"0"===$obj$$.trang_thai)){if($obj$$.pt_thanh_toan&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan))try{const $pt_thanh_toan$$=
92
+ await global.getModel("ptthanhtoan").findOne({_id:$obj$$.pt_thanh_toan});if($pt_thanh_toan$$.payment_service){let $paymentServiceModel$$=global.getModel($pt_thanh_toan$$.payment_service);$obj$$.amount=$obj$$.t_tt_nt-($obj$$.tien_paymentByPoints||0);if($obj$$.amount){let $virtual_payment_client_url$$=await $paymentServiceModel$$.createVirtualPaymentClientURL($obj$$,$evouchers_user$$.clientIp,$pt_thanh_toan$$);$obj$$.virtual_payment_client_url=$virtual_payment_client_url$$;$obj$$.payment_service=$pt_thanh_toan$$.payment_service;
93
+ $obj$$.payment_id=((await $paymentServiceModel$$.findOne({id_ct:$obj$$._id.toString()})||{})._id||"").toString()}else $obj$$.virtual_payment_client_url="",$obj$$.payment_service="",$obj$$.payment_id=""}else $obj$$.virtual_payment_client_url=""}catch($e$$){return console.error($e$$),$next$$("Error create Virtual Payment ClientURL:"+($e$$.message||$e$$.error||$e$$))}else $obj$$.virtual_payment_client_url="";model.findOneAndUpdate({_id:$obj$$._id},{virtual_payment_client_url:$obj$$.virtual_payment_client_url},
94
+ $e$$=>{$e$$&&console.log("error create Virtual Payment ClientURL",$e$$.message)})}"9"===$obj$$.trang_thai?(await transaction.deleteTrans({id_ct:$obj$$._id.toString()}),await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng"),await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":buy"})):(await createTransactionPayment($obj$$),createTransactionBonus($obj$$));await Evoucher.updateMany({id_ct_used:$obj$$._id.toString()},{id_ct_used:null});
95
+ $evouchers_user$$=await Evoucher.find({id_ct_useds:$obj$$._id.toString()});await Promise.all($evouchers_user$$.map($e$$=>deleteEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>updateEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$next$$(null,$obj$$)};$contr_router$$.deleting=function($user$$,$obj$$,$next$$){$next$$(null,$obj$$)};$contr_router$$.deleted=async function($user$$,$obj$$,$next$$){await transaction.deleteTrans({id_ct:$obj$$._id.toString()});
96
+ await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng");await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":buy"});$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>deleteEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$next$$(null,$obj$$)};$contr_router$$.view=function($user$$,$items$$,$fn$$){async.parallel({app:function($callback$$){$items$$.filter($item$$=>$item$$.id_app).joinModel2(null,App,[{where:{id_app:"_id"},
97
+ fields:{name_app:"name"}}],function(){$callback$$()})},kh:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kh).joinModel2(null,customer,[{where:$item$$=>({id_app:$item$$.id_app,ma_kh:$item$$.ma_kh}),fields:"ten_kh"}],function(){$callback$$()})},nhan_vien_giao_hang:function($callback$$){$items$$.filter($item$$=>$item$$.nhan_vien_giao_hang).joinModel2(null,customer,[{where:{nhan_vien_giao_hang:"ma_kh"},fields:[{ten_nhan_vien_giao_hang:"ten_kh"}]}],function(){$callback$$()})},nv_giao_hang:function($callback$$){$items$$.filter($item$$=>
98
+ $item$$.user_nv_giao_hang).joinModel2(null,User,{where:{user_nv_giao_hang:"email"},fields:{ten_nv_giao_hang:"name"}},function(){$callback$$()})},kho:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kho).joinModel2(null,dmkho,[{where:$item$$=>({id_app:$item$$.id_app,ma_kho:$item$$.ma_kho}),fields:["ten_kho",{tk_cn_kho:"tk_cn"}]}],function(){$callback$$()})},trangthai:function($callback$$){$items$$.filter($item$$=>$item$$.trang_thai).joinModel2(null,trangthai,[{where:{trang_thai:"ma_trang_thai",
99
+ ma_ct:"ma_ct"},fields:["ten_trang_thai","color"]}],function(){$callback$$()})},ptthanhtoan:function($callback$$){$items$$.filter($item$$=>$item$$.pt_thanh_toan).joinModel2(null,ptthanhtoan,[{where:$item$$=>({_id:$item$$.pt_thanh_toan,id_app:$item$$.id_app}),fields:[{ten_pt_thanh_toan:"ten"},{tk_cn_thanhtoan:"tk_cn"}]}],function(){$callback$$()})},pt1:function($callback$$){$items$$.joinModel2(null,pt1,[{where:$item$$=>({id_app:$item$$.id_app,id_so1:"_id"}),fields:[{id_pt1:"_id"},{so_ct_pt1:"so_ct"},
100
+ {ma_ct_pt1:"ma_ct"},{ngay_ct_pt1:"ngay_ct"}]}],function(){$callback$$()})},t_tien:function($callback$$){$items$$.filter($item$$=>$item$$.details).forEach(function($r$$){$r$$.tien_phi_vc=$r$$.tien_phi_vc||0;$r$$.tien_freeship=$r$$.tien_freeship||0;$r$$.details?($r$$.t_sl=$r$$.details.csum("sl_xuat"),$r$$.t_tien_hang=$r$$.details.csum("tien_hang"),$r$$.t_tien_hang_nt=$r$$.details.csum("tien_hang_nt"),$r$$.t_tien=$r$$.t_tien_hang-$r$$.details.csum("tien_ck"),$r$$.t_tien_nt=$r$$.t_tien_hang_nt-$r$$.details.csum("tien_ck_nt"),
101
+ $r$$.t_ck_nt=$r$$.t_ck=$r$$.tien_ck_hd+($r$$.tien_evoucher||0)):($r$$.t_sl=0,$r$$.t_tien_hang=0,$r$$.t_tien_hang_nt=0,$r$$.t_ck=0,$r$$.t_ck_nt=0,$r$$.t_tien=$r$$.t_tien_hang,$r$$.t_tien_nt=$r$$.t_tien_hang_nt);$r$$.ctcpbhs?($r$$.t_cp_cpb_nt=$r$$.ctcpbhs.csum("tien_cp_nt"),$r$$.t_cp_cpb=$r$$.ctcpbhs.csum("tien_cp")):($r$$.t_cp_cpb_nt=0,$r$$.t_cp_cpb=0);$r$$.t_tt=$r$$.t_tt_nt=Math.max(0,$r$$.t_tien_nt+$r$$.t_cp_cpb_nt-$r$$.t_ck_nt-($r$$.tt_tien_thuong||0)+($r$$.tien_phi_vc||0)-($r$$.tien_freeship||
102
+ 0))});$callback$$()},details_vt:function($callback$$){async.each($items$$,function($r$$,$callback1$$){const $details$$=$r$$.details;if(!$details$$)return $callback1$$();$details$$.joinModel2(null,dmvt,[{where:$item$$=>({id_app:$r$$.id_app,ma_vt:$item$$.ma_vt}),fields:"ten_vt picture chieu_cao chieu_rong chieu_sau trong_luong".split(" ")}],function(){$callback1$$()})},function(){$callback$$()})},details_tt1:function($callback$$){async.map($items$$,function($r$$,$callback1$$){$r$$.details.filter($item$$=>
103
+ $item$$.ma_tt1).joinModel2(null,dmtt,[{where:$item$$=>({id_app:$r$$.id_app,ma_vt:$item$$.ma_vt,ma_tt1:$item$$.ma_tt1}),setFields:($item$$,$ref$$)=>{$item$$.ten_vt=$item$$.ten_vt+" - "+$ref$$.ten_tt}}],function(){$callback1$$()})},function(){$callback$$()})},details_dt:function($callback$$){async.map($items$$,function($r$$,$callback1$$){const $details$$=$r$$.details;if(!$details$$)return $callback1$$();$details$$.filter($item$$=>$item$$.ma_dt).joinModel2(null,dmdt,[{where:$item$$=>({id_app:$r$$.id_app,
104
+ ma_dt:$item$$.ma_dt}),fields:["ten_dt"]}],function(){$callback1$$()})},function(){$callback$$()})},details_contract:function($callback$$){async.map($items$$,function($r$$,$callback1$$){const $details$$=$r$$.details;if(!$details$$)return $callback1$$();$details$$.filter($item$$=>$item$$.ma_hd).joinModel2(null,contract,[{where:$item$$=>({id_app:$r$$.id_app,so_hd:$item$$.ma_hd}),fields:["ten_hd"]}],function(){$callback1$$()})},function(){$callback$$()})},details_phi:function($callback$$){async.map($items$$,
105
+ function($r$$,$callback1$$){const $details$$=$r$$.details;if(!$details$$)return $callback1$$();$details$$.filter($item$$=>$item$$.ma_phi).joinModel2(null,dmphi,[{where:$item$$=>({id_app:$r$$.id_app,ma_phi:$item$$.ma_phi}),fields:["ten_phi"]}],function(){$callback1$$()})},function(){$callback$$()})},details_cpbh:function($callback$$){async.each($items$$,function($r$$,$callback1$$){let $ctcpbhs$$=$r$$.ctcpbhs;if(!$ctcpbhs$$)return $callback1$$();$ctcpbhs$$?$ctcpbhs$$.filter($item$$=>$item$$.ma_cp).joinModel2(null,
106
+ dmcpmh,[{where:$item$$=>({id_app:$r$$.id_app,ma_cp:$item$$.ma_cp}),fields:["ten_cp"]}],function(){$callback1$$()}):$callback1$$()},function(){$callback$$()})}},function(){$fn$$(null,$items$$)})}};