flexbiz-server 12.0.16 → 12.0.17

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.16",
5
+ "version": "12.0.17",
6
6
  "author": {
7
7
  "name": "Van Truong Pham",
8
8
  "email": "invncur@gmail.com"
@@ -196,26 +196,27 @@ $user$jscomp$0$$.current_id_app);const $checkVoucherNumber$$=$callback$$=>{under
196
196
  $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();
197
197
  $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+
198
198
  " \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,
199
- $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})})},
200
- ($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$$,
201
- $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",
202
- $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&&
203
- $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$$=
204
- 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",
205
- 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$$,
206
- $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$$=
207
- 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$$,
208
- $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&&
209
- 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$$);
210
- $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$$)});
211
- 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$$);
212
- 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||
213
- {}).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=
214
- $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$$=>
215
- {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,
216
- $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,
217
- $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$$+=
218
- $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$$)}}
199
+ $user$jscomp$0$$.email,$ctrl$$.module,"add",function($error$$,$hr$$,$c_app$$){setImmediate(()=>{if($error$$||!$hr$$)return $callback$$($error$$);$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$jscomp$37_v$$,$_obj$$){if($error$jscomp$37_v$$)return $callback$$($error$jscomp$37_v$$);for(let $f$$ of Object.keys($schema_paths$$))$error$jscomp$37_v$$=$_obj$$.get?$_obj$$.get($f$$):$_obj$$[$f$$],
200
+ $obj$jscomp$0$$.set($f$$,$error$jscomp$37_v$$);$callback$$(null,$obj$jscomp$0$$)},{data:$data$$}):$callback$$(null,$obj$jscomp$0$$)})})},{data:$obj$jscomp$0$$,notNeedRight:$ctrl$$.options.notNeedRight})})},($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()},
201
+ {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$$,$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$$=
202
+ $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$$.id_app,
203
+ $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&&$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$$)},
204
+ 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,
205
+ "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$$,
206
+ $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$$=>{if($e$jscomp$0$$)return $callback$$($e$jscomp$0$$);setImmediate(()=>{$obj$jscomp$0$$.user_created=$user$jscomp$0$$.email;$obj$jscomp$0$$.user_updated=$user$jscomp$0$$.email;validate($obj$jscomp$0$$,async $error$$=>
207
+ {setImmediate(async()=>{if($error$$){let $msgError$$=$error$$;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{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$jscomp$0$$._id=$_id$$;await $model$$.deleteOne({_id:$_id$$})}$callback$$()}})})})})},
208
+ 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$$,$obj$jscomp$0$$,$e$$=>{$e$$&&($msgError$$=$msgError$$+"\n"+$e$$);$callback$$({error:$msgError$$,code:ERR_ALREADY_EXIST_CODE})});
209
+ 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&&Object.keys($model$$.schema.paths[$model_path$$].schema.paths).filter($path$$=>"line"!==$path$$&&
210
+ "_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$$);$obj$jscomp$0$$.save(function($error$jscomp$0$$,$obj_created$$){setImmediate(()=>{if($error$jscomp$0$$){let $msgErrors$$=
211
+ [];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$$)});else $callback$$($msgErrors$$)}else postData($obj_created$$,$ctrl$$,function($msgErrors$$){setImmediate(()=>{if($msgErrors$$)if($model$$.deleteOne({_id:$obj_created$$._id.toString()},
212
+ $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$$);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(),
213
+ 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||{}).access_token}),$ctrl$$.cacheData($obj_created$$),$req$$&&!1!==($req$$.query||{}).return_data)$ctrl$$.onView($user$jscomp$0$$,[$obj_created$$],
214
+ $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=$ctrl$$.collection_name;$obj$$.exfields&&$obj$$.exfields.__files__&&($obj$$.exfields.__files__.forEach($_file$$=>
215
+ {$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$$=>{console.error($e$$)})}),delete $obj$$.exfields.__supports__);if($ctrl$$.created)$ctrl$$.created($user$jscomp$0$$,
216
+ $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,$rs$$)});else if($req$$&&$req$$.uploadFile){let $html$$="<html><title>OK</title><body>"+JSON.stringify($rs$$)+
217
+ "</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,$error$jscomp$46_html$$)):$callback$$(null,$obj$$)});else if($req$$&&$req$$.uploadFile){let $html$$="<html><title>OK</title><body>"+
218
+ 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$$+=$user$jscomp$0$$.current_id_app),delete global.cacheDatas[$e$jscomp$145_name_cached$$],$callback$jscomp$1$$(null,$rs$$))})}catch($e$$){console.error($e$$),
219
+ $callback$jscomp$1$$($e$$)}}
219
220
  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&&
220
221
  ("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$$)})};
221
222
  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$$]=
@@ -223,35 +224,35 @@ controller.prototype.quickCreate=function(){let $model$$=this.model,$name$$=this
223
224
  {};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$$&&
224
225
  "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$$)})},
225
226
  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$$)})};
226
- 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()||
227
- {}).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$$)&&
228
- ($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$$);
229
- 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,
230
- $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,
231
- "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||
227
+ 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()||
228
+ {}).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$$)&&
229
+ ($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$$);
230
+ 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,
231
+ $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,
232
+ "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||
232
233
  $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$$};
233
234
  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$$,
234
- $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",
235
- $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?
236
- $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$$]=
237
- $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",
238
- $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$$);
239
- 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$$=>
240
- 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$$)})},
241
- $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$$,
242
- $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);delete $data$jscomp$1$$.__v;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(()=>
243
- {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$$];
244
- 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$$&&0<=fields_sync_master_detail.indexOf($path$$)).forEach($path$$=>{$obj$$[$path$$]&&$obj$$[$model_path$$].filter($detail$$=>!$detail$$[$path$$]).forEach($detail$$=>
245
- {$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$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{delete $obj$$.__v,$obj_created$$=await $obj$$.save()}catch($e$$){$error$jscomp$0$$=
246
- $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$$,
247
- 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$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$$||
248
- !$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$$,
249
- $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$$,
250
- [$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(),
251
- "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$$=>
252
- {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$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?
253
- $ctrl$$.dynamicUpdated($user$jscomp$0$$,$obj$jscomp$0$$,function($error$$){if($error$$)return $callback$$($error$$);$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),
254
- delete global.cacheDatas[$e$jscomp$164_name_cached$$],$callback$jscomp$1$$(null,$rs$$))})}catch($e$$){console.error($e$$),$callback$jscomp$1$$($e$$)}};
235
+ $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$0$$,$callback$jscomp$0$$)=>{(async($obj$$,$callback$$)=>{try{(await permission.getFieldNotRight($obj$$.id_app,$user$jscomp$0$$.email,$ctrl$$.name)).forEach($f$$=>{delete $data$jscomp$0$$[$f$$]})}catch($e$$){console.error("Error get field not right",
236
+ $e$$)}setImmediate(function(){$ctrl$$.updating?$ctrl$$.updating($user$jscomp$0$$,$data$jscomp$0$$,$obj$$,function($error$jscomp$0$$,$_data$jscomp$0$$,$_obj$$){setImmediate(()=>{if($error$jscomp$0$$)return $callback$$($error$jscomp$0$$);if($ctrl$$.dynamicUpdating)$ctrl$$.dynamicUpdating($user$jscomp$0$$,$_data$jscomp$0$$,$_obj$$,function($error$$,$_data$$){if($error$$)return $callback$$($error$$);for(let $f$$ in $_data$$)underscore.has($schema_paths$$,$f$$)&&($data$jscomp$0$$[$f$$]=$_data$$[$f$$]);
237
+ $callback$$(null,$obj$$)});else{for(let $f$$ in $_data$jscomp$0$$)underscore.has($schema_paths$$,$f$$)&&($data$jscomp$0$$[$f$$]=$_data$jscomp$0$$[$f$$]);$callback$$(null,$obj$$)}})}):$ctrl$$.dynamicUpdating?$ctrl$$.dynamicUpdating($req$$.user,$data$jscomp$0$$,$obj$$,function($error$$,$_data$$){if($error$$)return $callback$$($error$$);for(let $f$$ in $_data$$)underscore.has($schema_paths$$,$f$$)&&($data$jscomp$0$$[$f$$]=$_data$$[$f$$]);$callback$$(null,$obj$$)}):$callback$$(null,$obj$$)})})($obj$jscomp$0$$,
238
+ $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$$]=$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()?
239
+ $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$$],$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$$||
240
+ $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$$);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||
241
+ $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$$=>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$$,
242
+ $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$$)})},$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$$);
243
+ 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=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);delete $data$jscomp$0$$.__v;
244
+ 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(()=>{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,
245
+ $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$$=>{$model$$.schema.paths[$model_path$$].schema&&$model$$.schema.paths[$model_path$$].schema.paths&&Object.keys($model$$.schema.paths[$model_path$$].schema.paths).filter($path$$=>
246
+ "line"!==$path$$&&"_id"!==$path$$&&"__v"!==$path$$&&0<=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$$,$obj$$);$ctrl$$.emit("saving",$obj$$);let $obj_created$$,$error$jscomp$0$$;$data$jscomp$0$$.$condition&&($$condition_k$$=$data$jscomp$0$$.$condition,$$condition_k$$._id=
247
+ $obj$$._id,await $model$$.findOne($$condition_k$$)||($error$jscomp$0$$=ERR_CAN_NOT_UPDATE),delete $data$jscomp$0$$.$condition);if(!$error$jscomp$0$$)try{delete $obj$$.__v,$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);0==$msgErrors$$.length&&($msgErrors$$=$error$jscomp$0$$.message);$msgErrors$$||($msgErrors$$=JSON.stringify($error$jscomp$0$$));
248
+ 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,id_func:$ctrl$$.name,action:"UPDATE",data:{oldData:$current_obj$$,newData:$data$jscomp$0$$,id:$obj$$._id.toString()}},
249
+ $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...");$model$$.findById($current_obj$$._id,($e$jscomp$0$$,$_d$$)=>{if(!$_d$$)return console.error("Don't find voucher",
250
+ $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(()=>{$ctrl$$.emit("saved",$obj_created$$);$ctrl$$.emit("updated",$obj_created$$);$obj_created$$=$obj_created$$.toObject();
251
+ 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$$);$callback$$(null,$viewValue$$[0])})},{req:$req$$});else $callback$$(null,{_id:$obj_created$$._id})})})})},
252
+ 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$$)=>{!$rs$$||$rs$$.user_approved||$rs$$.user_denied||($rs$$.user_approved=$req$$.user.email,$rs$$.user_approved_name=
253
+ $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?$ctrl$$.updated($user$jscomp$0$$,$obj$jscomp$0$$,function($error$jscomp$0$$,$obj$$){if($error$jscomp$0$$)return console.error("error when saved",
254
+ $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$$);$callback$$(null,$obj$jscomp$0$$)}):$callback$$(null,$obj$jscomp$0$$)})}],($e$jscomp$164_name_cached$$,$rs$$)=>{$e$jscomp$164_name_cached$$?
255
+ (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$$),$callback$jscomp$1$$($e$$)}};
255
256
  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||
256
257
  $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$$)})};
257
258
  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(()=>
@@ -22,9 +22,9 @@ Math.round($total_count$$/$limit$$);$page_total$$*$limit$$<$total_count$$&&($pag
22
22
  $events$jscomp$1_rs$$.page=$page$$;$events$jscomp$1_rs$$.txs.forEach($r$$=>{$r$$.timestamp=new Date($r$$.timestamp)});$events$jscomp$1_rs$$.txs=$events$jscomp$1_rs$$.txs.sort(($a$$,$b$$)=>$b$$.timestamp.getTime()-$a$$.timestamp.getTime());return $events$jscomp$1_rs$$},bcQuery=async $urlQuery$$=>{if(!$urlQuery$$)throw{message:"Muste declare url"};let $url$$=`${configs.BLOCKCHAIN_URL}/${$urlQuery$$}`;console.log("bcquery",$url$$);return new Promise(($resolve$$,$reject$$)=>{axios.get($url$$).then($rs$$=>
23
23
  {$resolve$$($rs$$.data)}).catch($e$$=>{$e$$.response?($e$$.response.data.url=$url$$,$reject$$({message:$e$$.response.data,url:$url$$})):$reject$$($e$$)})})},tdQuery=async $urlQuery$$=>{if(!$urlQuery$$)throw{message:"Muste declare url"};let $url$$=`${configs.BLOCKCHAIN_RPC}/${$urlQuery$$}`;return new Promise(($resolve$$,$reject$$)=>{axios.get($url$$).then($rs$$=>{$resolve$$($rs$$.data)}).catch($e$$=>{$e$$.response?($e$$.response.data.url=$url$$,$reject$$({message:$e$$.response.data,url:$url$$})):(console.error("error call",
24
24
  $url$$),$reject$$($e$$))})})},ping=async $from_address$$=>{console.log("ping from ",$from_address$$,"...");let $key$$=await model.findOne({address:$from_address$$});$key$$&&createTx($key$$.id_app,null,{values:{creator:$from_address$$,data:0},typeUrl:"/pvtruong.flexzen.flexzen.MsgPing",from_address:$from_address$$,username:$key$$.username}).then(async $rs$$=>{console.log("Pingged",$rs$$.code)})},processEventTx=async $data$$=>{try{let $senders$$=[],$receivers$$=[],$owners$$=[];for(let $key$$ in $data$$.result.events)$data$$.result.events[$key$$].forEach(async $action$$=>
25
- {0<$key$$.indexOf(".owner")?$owners$$.push($action$$):0<$key$$.indexOf(".sender")?$senders$$.push($action$$):(0<$key$$.indexOf(".receiver")||0<$key$$.indexOf(".recipient"))&&$receivers$$.push($action$$)});(new Set($senders$$)).forEach(async $sender$$=>{let $u$$=await getKeyByAddress($sender$$);$u$$&&User.emitEvent($u$$.user_created,"blockchain.wallet.changed",{sender:$sender$$,data:$data$$})});(new Set($receivers$$)).forEach(async $receiver$$=>{let $u$$=await getKeyByAddress($receiver$$);$u$$&&User.emitEvent($u$$.user_created,
26
- "blockchain.wallet.changed",{receiver:$receiver$$,data:$data$$})});(new Set($owners$$)).filter($o$$=>!$senders$$.find($s$$=>$s$$==$o$$)).filter($o$$=>!$receivers$$.find($s$$=>$s$$==$o$$)).forEach(async $owner$$=>{let $u$$=await getKeyByAddress($owner$$);$u$$&&User.emitEvent($u$$.user_created,"blockchain.wallet.changed",{receiver:$owner$$,sender:$owner$$,data:$data$$})})}catch($e$$){console.log("error emit events",$e$$.message)}};let notificationPool={};
27
- const processEventAt=async $events$$=>{let $receivers$$=[];for(let $key$$ in $events$$)$events$$[$key$$].forEach(async $action$$=>{(0<=$key$$.indexOf(".receiver")||0<=$key$$.indexOf(".recipient")||0<=$key$$.indexOf(".sender")||0<=$key$$.indexOf(".creator")||0<=$key$$.indexOf(".owner")||0<=$key$$.indexOf(".buyer")||0<=$key$$.indexOf(".seller"))&&$receivers$$.push($action$$)});(new Set($receivers$$)).forEach(async $receiver$$=>{let $u$$=await getKeyByAddress($receiver$$);$u$$&&$events$$["at.action"].forEach(($action$jscomp$2_id_invest_token$$,
25
+ {0<$key$$.indexOf(".owner")?$owners$$.push($action$$):0<$key$$.indexOf(".sender")?$senders$$.push($action$$):(0<$key$$.indexOf(".receiver")||0<$key$$.indexOf(".recipient"))&&$receivers$$.push($action$$)});[...(new Set($senders$$))].forEach(async $sender$$=>{let $u$$=await getKeyByAddress($sender$$);$u$$&&User.emitEvent($u$$.user_created,"blockchain.wallet.changed",{sender:$sender$$,data:$data$$})});[...(new Set($receivers$$))].forEach(async $receiver$$=>{let $u$$=await getKeyByAddress($receiver$$);
26
+ $u$$&&User.emitEvent($u$$.user_created,"blockchain.wallet.changed",{receiver:$receiver$$,data:$data$$})});[...(new Set($owners$$))].filter($o$$=>!$senders$$.find($s$$=>$s$$==$o$$)).filter($o$$=>!$receivers$$.find($s$$=>$s$$==$o$$)).forEach(async $owner$$=>{let $u$$=await getKeyByAddress($owner$$);$u$$&&User.emitEvent($u$$.user_created,"blockchain.wallet.changed",{receiver:$owner$$,sender:$owner$$,data:$data$$})})}catch($e$$){console.error("error emit events",$e$$.message)}};let notificationPool={};
27
+ const processEventAt=async $events$$=>{let $receivers$$=[];for(let $key$$ in $events$$)$events$$[$key$$].forEach(async $action$$=>{(0<=$key$$.indexOf(".receiver")||0<=$key$$.indexOf(".recipient")||0<=$key$$.indexOf(".sender")||0<=$key$$.indexOf(".creator")||0<=$key$$.indexOf(".owner")||0<=$key$$.indexOf(".buyer")||0<=$key$$.indexOf(".seller"))&&$receivers$$.push($action$$)});[...(new Set($receivers$$))].forEach(async $receiver$$=>{let $u$$=await getKeyByAddress($receiver$$);$u$$&&$events$$["at.action"].forEach(($action$jscomp$2_id_invest_token$$,
28
28
  $id$jscomp$2_index$jscomp$17_token$$)=>{let $creator$$=$events$$["at.creator"]&&$events$$["at.creator"].length>$id$jscomp$2_index$jscomp$17_token$$?$events$$["at.creator"][$id$jscomp$2_index$jscomp$17_token$$]:"",$owner$$=$events$$["at.owner"]&&$events$$["at.owner"].length>$id$jscomp$2_index$jscomp$17_token$$?$events$$["at.owner"][$id$jscomp$2_index$jscomp$17_token$$]:"",$memo$$=$events$$["at.memo"]&&$events$$["at.memo"].length>$id$jscomp$2_index$jscomp$17_token$$?$events$$["at.memo"][$id$jscomp$2_index$jscomp$17_token$$]:
29
29
  "",$timestamp$$=$events$$["at.timestamp"]&&$events$$["at.timestamp"].length>$id$jscomp$2_index$jscomp$17_token$$?$events$$["at.timestamp"][$id$jscomp$2_index$jscomp$17_token$$]:"";$timestamp$$=Number($timestamp$$||0)+$id$jscomp$2_index$jscomp$17_token$$;switch($action$jscomp$2_id_invest_token$$){case "withdraw":$id$jscomp$2_index$jscomp$17_token$$=$events$$["at.idWithdraw"]&&$events$$["at.idWithdraw"].length>$id$jscomp$2_index$jscomp$17_token$$?$events$$["at.idWithdraw"][$id$jscomp$2_index$jscomp$17_token$$]:
30
30
  "";var $ky_tra_lai_noti$$={title:"X\u1eed l\u00fd r\u00fat v\u1ed1n",receiver:$receiver$$,body:$memo$$||`Y\u00eau c\u1ea7u r\u00fat v\u1ed1n s\u1ed1 ${$id$jscomp$2_index$jscomp$17_token$$} \u0111\u00e3 \u0111\u01b0\u1ee3c x\u1eed l\u00fd xong`,data:{key:"withdraw:"+$id$jscomp$2_index$jscomp$17_token$$+$timestamp$$,id_withdraw:$events$$["at.idWithdraw"]}};break;case "buy":$receiver$$===$creator$$&&($ky_tra_lai_noti$$={title:"Mua th\u00e0nh c\u00f4ng",receiver:$receiver$$,body:$memo$$||`B\u1ea1n \u0111\u00e3 mua th\u00e0nh c\u00f4ng ${$events$$["at.amount"][$id$jscomp$2_index$jscomp$17_token$$]} ${$events$$["at.token"][$id$jscomp$2_index$jscomp$17_token$$]}`,
@@ -1,4 +1,4 @@
1
- 'use strict';const async=require("async"),underscore=require("underscore"),valid=function($obj$$,$next$$,$id_app$$){setImmediate(()=>{$id_app$$||($id_app$$=$obj$$.id_app);$obj$$.schema.validate?async.map(underscore.keys($obj$$.schema.validate),function($key$$,$callback$$){var $validField$$=$obj$$.schema.validate[$key$$],$value$$=$obj$$[$key$$];if(!$value$$)return $callback$$();var $msg$$=$validField$$[1];(0,$validField$$[0])($id_app$$,$value$$,function($valid$$){return!1===$valid$$?($msg$$=$msg$$.replace("{PATH}",
2
- $key$$),$msg$$=$msg$$.replace("{VALUE}",$value$$),$callback$$($msg$$)):$callback$$()})},function($error$$){if($error$$)return $next$$($error$$);$next$$()}):$next$$()})};
1
+ 'use strict';const async=require("async"),underscore=require("underscore"),valid=function($obj$$,$next$$,$id_app$$){setImmediate(()=>{$id_app$$||($id_app$$=$obj$$.id_app);$obj$$.schema&&$obj$$.schema.validate?async.map(underscore.keys($obj$$.schema.validate),function($key$$,$callback$$){var $validField$$=$obj$$.schema.validate[$key$$],$value$$=$obj$$[$key$$];if(!$value$$)return $callback$$();var $msg$$=$validField$$[1];(0,$validField$$[0])($id_app$$,$value$$,function($valid$$){return!1===$valid$$?
2
+ ($msg$$=$msg$$.replace("{PATH}",$key$$),$msg$$=$msg$$.replace("{VALUE}",$value$$),$callback$$($msg$$)):$callback$$()})},function($error$$){if($error$$)return $next$$($error$$);$next$$()}):$next$$()})};
3
3
  module.exports=function($obj$$,$next$$){const $id_app$$=$obj$$.id_app;valid($obj$$,function($error$jscomp$0$$){if($error$jscomp$0$$)return $next$$($error$jscomp$0$$);setImmediate(()=>{const $valid_path$$=[],$_push_valid_path$$=function($o$$){$valid_path$$.push($o$$)};for(let $key$$ in $obj$$.schema.paths){var $obj_d_path$$=$obj$$.schema.paths[$key$$];$obj_d_path$$.schema&&$obj_d_path$$.schema.validate&&($obj_d_path$$=$obj$$.get($key$$),underscore.isArray($obj_d_path$$)?$obj_d_path$$.forEach($_push_valid_path$$):
4
4
  $valid_path$$.push($obj_d_path$$))}0<$valid_path$$.length?async.each($valid_path$$,function($p$$,$callback$$){valid($p$$,function($error$$){if($error$$)return $callback$$($error$$);$callback$$()},$id_app$$)},function($error$$){if($error$$)return $next$$($error$$);$next$$()}):$next$$()})})};
@@ -1,5 +1,5 @@
1
1
  'use strict';const notificationSchema=new Schema({key:String,email_sender:{type:String,required:!0},email_receiver:{type:String,required:!0},email_owner:{type:String,required:!0},title:{type:String,required:!0},content:{type:String},exfields:Schema.Types.Mixed,read:{type:Boolean,default:!1},status:{type:Boolean,default:!1},date_created:{type:Date,default:Date.now},date_updated:{type:Date,default:Date.now},user_created:{type:String,default:""},user_updated:{type:String,default:""}});notificationSchema.index({email_owner:1});
2
- notificationSchema.index({email_receiver:1});notificationSchema.index({email_sender:1});notificationSchema.index({email_receiver:1,email_owner:1,read:-1});notificationSchema.index({date_created:-1});notificationSchema.index({title:"text",content:"text"});notificationSchema.index({key:1},{unique:!0});notificationSchema.index({title:1});notificationSchema.index({content:1});notificationSchema.index({status:1});notificationSchema.index({user_created:1,visible_to:1,visible_to_users:1});
3
- const Notification=mongoose.models.notification||mongoose.model("notification",notificationSchema);
2
+ notificationSchema.index({email_receiver:1});notificationSchema.index({email_sender:1});notificationSchema.index({"exfields.id_app":1});notificationSchema.index({email_receiver:1,email_owner:1,read:-1});notificationSchema.index({date_created:-1});notificationSchema.index({title:"text",content:"text"});notificationSchema.index({key:1},{unique:!0});notificationSchema.index({title:1});notificationSchema.index({content:1});notificationSchema.index({status:1});
3
+ notificationSchema.index({user_created:1,visible_to:1,visible_to_users:1});const Notification=mongoose.models.notification||mongoose.model("notification",notificationSchema);
4
4
  Notification.createNotification=function($email_sender$$,$email_receiver$$,$title$$,$content$$,$fn$$,$exfields$$,$emitEvent$$,$c_token$$,$send_email$$){const $notifi_re$$=new Notification;$notifi_re$$.email_owner=$email_receiver$$;$notifi_re$$.email_sender=$email_sender$$;$notifi_re$$.email_receiver=$email_receiver$$;$notifi_re$$.title=$title$$;$notifi_re$$.content=$content$$;$notifi_re$$.exfields=$exfields$$;$notifi_re$$.key=($exfields$$||{}).key||`${$notifi_re$$.email_receiver}-${(new Date).getTime()}`;
5
5
  $notifi_re$$.user_created=$email_sender$$;$notifi_re$$.user_updated=$email_sender$$;$notifi_re$$.save(function($err$$,$m$$){$err$$?(console.error($err$$),$fn$$&&$fn$$($err$$)):(global.alertNotification($email_receiver$$),global.sendNotification($email_receiver$$,$m$$._id,$m$$.toObject(),!1!==$emitEvent$$),$fn$$&&$fn$$(null,$notifi_re$$,$notifi_re$$))})};module.exports=Notification;
@@ -3,17 +3,22 @@ module.exports=function($contr_router$$){$contr_router$$=new controller($contr_r
3
3
  $next$$)=>{await $items$$.asyncJoinModel2($user$$.current_id_app,assproduct,{where:{id_product:"id"},fields:["ten_san_pham","hinh_anh","logo","ma_loai",{product_token:"token"},"gia_tri_hien_tai","sl_nhan_vien","nganh_nghe"]});async.map($items$$.filter($item$$=>$item$$.id||0===$item$$.id),async $item$$=>{try{var $frm_ivs$$=await bcQuery("period/"+$item$$.id);$item$$.co_phan=Number($frm_ivs$$.Period.coPhan);$item$$.tong_so_token=Number($frm_ivs$$.Period.tongSoToken);$item$$.da_dau_tu=Number($frm_ivs$$.Period.daDauTu);
4
4
  $item$$.hoat_dong=$frm_ivs$$.Period.hoatDong;$item$$.denom=$frm_ivs$$.Period.denom;$item$$.ky_tinh_lai=Number($frm_ivs$$.Period.kyTinhLai);$item$$.ngay_phat_hanh=new Date(1E3*Number($frm_ivs$$.Period.ngayPhatHanh));model.updateMany({_id:$item$$._id},$item$$).then($rs$$=>{console.log("update period",$rs$$)})}catch($e$$){console.error("view assperiod",$e$$),$e$$.message&&"3"==$e$$.message.code&&(model.deleteOne({_id:$item$$._id}).then(()=>{console.log("deleted period",$item$$)}),$item$$.not_found=!0)}$item$$.goi_dau_tu&&
5
5
  $item$$.frm_step_code&&($frm_ivs$$=await global.getModel("financialroadmap").findOne({id_app:$item$$.id_app,code:$item$$.id_product.toString()}).lean())&&($item$$.frm_step=($frm_ivs$$.steps||[]).find($s$$=>$s$$.code===$item$$.frm_step_code),$item$$.frm_step&&$item$$.frm_step.sl_slot&&($item$$.frm_step.sl_cp_slot=$item$$.frm_step.dillution/100*$item$$.frm_step.total_share/$item$$.frm_step.sl_slot))},async()=>{$items$$=$items$$.filter($i$$=>!$i$$.not_found);$items$$.joinModel2(null,Trangthai,[{where:$a$$=>
6
- ({ma_trang_thai:$a$$.trang_thai,ma_ct:"ASSPERIOD"}),fields:["ten_trang_thai","color"]}],function(){$next$$(null,$items$$)})})},onCreating:async($user$$,$obj$$,$next$$)=>{if("9"===$obj$$.trang_thai)return $next$$(null,$obj$$);var $data_from_address$$=$obj$$.creator;$data_from_address$$={values:{creator:$obj$$.creator,idProduct:Number($obj$$.id_product),laiSuatCamKet:Number($obj$$.lai_suat_cam_ket),laiSuatTruocHan:Number($obj$$.lai_suat_truoc_han),kyHan:Number($obj$$.ky_han),choPhepRutVon:$obj$$.cho_phep_rut_von,
6
+ ({ma_trang_thai:$a$$.trang_thai,ma_ct:"ASSPERIOD"}),fields:["ten_trang_thai","color"]}],function(){$next$$(null,$items$$)})})},onCreating:async($user$$,$obj$$,$next$$)=>{if("9"===$obj$$.trang_thai)return $next$$(null,$obj$$);if($obj$$.goi_dau_tu&&$obj$$.frm_step_code){$data_frm$$=await global.getModel("financialroadmap").findOne({id_app:$user$$.current_id_app,code:$obj$$.id_product.toString()}).lean();if(!$data_frm$$)return $next$$("L\u1ed9 tr\u00ecnh t\u00e0i ch\u00ednh cho g\u00f3i \u0111\u1ea7u t\u01b0 n\u00e0y kh\u00f4ng t\u1ed3n t\u1ea1i");
7
+ $data_frm$$=($data_frm$$.steps||[]).find($s$$=>$s$$.code===$obj$$.frm_step_code);if(!$data_frm$$)return $next$$("G\u00f3i \u0111\u1ea7u t\u01b0 n\u00e0y kh\u00f4ng t\u1ed3n t\u1ea1i trong l\u1ed9 tr\u00ecnh t\u00e0i ch\u00ednh");if("5"==$data_frm$$.trang_thai)return $next$$("G\u00f3i \u0111\u1ea7u t\u01b0 n\u00e0y \u0111\u00e3 ho\u00e0n th\u00e0nh k\u00eau g\u1ecdi v\u1ed1n");if("4"!=$data_frm$$.trang_thai)return $next$$("G\u00f3i \u0111\u1ea7u t\u01b0 n\u00e0y ch\u01b0a c\u00f3 hi\u1ec7u l\u1ef1c");
8
+ if($obj$$.tong_so_token!=$data_frm$$.sl_slot)return $next$$("S\u1ed1 l\u01b0\u1ee3ng token ph\u1ea3i b\u1eb1ng v\u1edbi s\u1ed1 l\u01b0\u1ee3ng c\u1ee7a g\u00f3i \u0111\u1ea7u t\u01b0(step) trong l\u1ed9 tr\u00ecnh t\u00e0i ch\u00ednh")}var $data_frm$$=$obj$$.creator;$data_frm$$={values:{creator:$obj$$.creator,idProduct:Number($obj$$.id_product),laiSuatCamKet:Number($obj$$.lai_suat_cam_ket),laiSuatTruocHan:Number($obj$$.lai_suat_truoc_han),kyHan:Number($obj$$.ky_han),choPhepRutVon:$obj$$.cho_phep_rut_von,
7
9
  choPhepChuyenNhuong:$obj$$.cho_phep_chuyen_nhuong,hoatDong:$obj$$.hoat_dong,gia:Number($obj$$.gia),denom:$obj$$.denom,tgXuLyRutVon:$obj$$.tg_xu_ly_rut_von||0,tongSoToken:Number($obj$$.tong_so_token||0),kyTinhLai:Number($obj$$.ky_tinh_lai||0),loiNhuanDuocChia:Number($obj$$.loi_nhuan_duoc_chia||0),ngayChiaLoiNhuan:$obj$$.ngay_chia_loi_nhuan?(new Date($obj$$.ngay_chia_loi_nhuan)).getTime()/1E3:0,goiDauTu:$obj$$.goi_dau_tu||!1,laiSuatTangThemSoHuuToken:Number($obj$$.lai_suat_tang_them_so_huu_token||0),
8
- tokenSoHuu:$obj$$.token_so_huu||"",soLuongSoHuu:Number($obj$$.so_luong_so_huu||0),soNgayDauTuToiThieu:Number($obj$$.so_ngay_dau_tu_toi_thieu||0),truLaiDaTra:$obj$$.tru_lai_da_tra||!1,laiSuatThoiGianConLai:Number($obj$$.lai_suat_thoi_gian_con_lai||0)},typeUrl:"/pvtruong.flexzen.flexzen.MsgCreatePeriod",from_address:$data_from_address$$};createTx($user$$.current_id_app,$user$$.token,$data_from_address$$).then(async $rs$$=>{if($rs$$.code){if(5===$rs$$.code)return $next$$("B\u1ea1n kh\u00f4ng \u0111\u1ee7 ti\u1ec1n \u0111\u1ec3 th\u1ef1c hi\u1ec7n giao d\u1ecbch n\u00e0y");
10
+ tokenSoHuu:$obj$$.token_so_huu||"",soLuongSoHuu:Number($obj$$.so_luong_so_huu||0),soNgayDauTuToiThieu:Number($obj$$.so_ngay_dau_tu_toi_thieu||0),truLaiDaTra:$obj$$.tru_lai_da_tra||!1,laiSuatThoiGianConLai:Number($obj$$.lai_suat_thoi_gian_con_lai||0)},typeUrl:"/pvtruong.flexzen.flexzen.MsgCreatePeriod",from_address:$data_frm$$};createTx($user$$.current_id_app,$user$$.token,$data_frm$$).then(async $rs$$=>{if($rs$$.code){if(5===$rs$$.code)return $next$$("B\u1ea1n kh\u00f4ng \u0111\u1ee7 ti\u1ec1n \u0111\u1ec3 th\u1ef1c hi\u1ec7n giao d\u1ecbch n\u00e0y");
9
11
  console.error($rs$$);return $next$$($rs$$.rawLog||$rs$$)}try{let $tx$$=await getTxStatus($rs$$.transactionHash),$id$$=((((($tx$$.logs.find($l$$=>$l$$.events)||{}).events||[]).find($e$$=>"message"===$e$$.type)||{}).attributes||[]).find($a$$=>"id"===$a$$.key)||{}).value;void 0!==$id$$?($obj$$.id=$id$$,$next$$(null,$obj$$)):(console.error($tx$$),$next$$("Kh\u00f4ng th\u1ec3 t\u1ea1o k\u1ef3 h\u1ea1n cho s\u1ea3n ph\u1ea9m n\u00e0y"))}catch($e$$){console.error($e$$),$next$$($e$$.message||$e$$.error||
10
- $e$$)}}).catch($e$$=>{console.error($e$$);$next$$($e$$.message||$e$$.error||$e$$)})}});$contr_router$$.deleting=function($user$$,$obj$$,$fn$$){if(!isSupperAdmin($user$$.email.toLowerCase()))return $fn$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n x\u00f3a");$fn$$(null,$obj$$)};$contr_router$$.updating=function($user$$,$data$$,$obj$$,$fn$$){if($user$$.email!==$obj$$.user_created)return $fn$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n c\u1eadp nh\u1eadt");if($data$$.creator&&$data$$.creator!==$obj$$.creator)return $fn$$("Kh\u00f4ng \u0111\u01b0\u1ee3c ph\u00e9p s\u1eeda \u0111\u1ecba ch\u1ec9 v\u00ed ng\u01b0\u1eddi t\u1ea1o");
12
+ $e$$)}}).catch($e$$=>{console.error($e$$);$next$$($e$$.message||$e$$.error||$e$$)})}});$contr_router$$.deleting=function($user$$,$obj$$,$fn$$){if(!isSupperAdmin($user$$.email.toLowerCase()))return $fn$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n x\u00f3a");$fn$$(null,$obj$$)};$contr_router$$.updating=async function($user$$,$data$$,$obj$$,$fn$$){if($user$$.email!==$obj$$.user_created)return $fn$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n c\u1eadp nh\u1eadt");if($data$$.creator&&$data$$.creator!==$obj$$.creator)return $fn$$("Kh\u00f4ng \u0111\u01b0\u1ee3c ph\u00e9p s\u1eeda \u0111\u1ecba ch\u1ec9 v\u00ed ng\u01b0\u1eddi t\u1ea1o");
11
13
  if("9"==$data$$.trang_thai&&"9"!=$obj$$.trang_thai)return $fn$$("Kh\u00f4ng th\u1ec3 chuy\u1ec3n v\u1ec1 tr\u1ea1ng th\u00e1i ch\u01b0a \u0111\u01b0\u1ee3c ph\u00e1t h\u00e0nh t\u1eeb tr\u1ea1ng th\u00e1i \u0111\u00e3 \u0111\u01b0\u1ee3c ph\u00e1t h\u00e0nh");if("9"==$data$$.trang_thai)return $fn$$(null,$data$$,$obj$$);$data$$.ngay_chia_loi_nhuan=$data$$.ngay_chia_loi_nhuan||$obj$$.ngay_chia_loi_nhuan;void 0==$data$$.lai_suat_tang_them_so_huu_token&&($data$$.lai_suat_tang_them_so_huu_token=$obj$$.lai_suat_tang_them_so_huu_token);
12
- void 0==$data$$.token_so_huu&&($data$$.token_so_huu=$obj$$.token_so_huu);void 0==$data$$.so_luong_so_huu&&($data$$.so_luong_so_huu=$obj$$.so_luong_so_huu);void 0==$data$$.tru_lai_da_tra&&($data$$.tru_lai_da_tra=$obj$$.tru_lai_da_tra);void 0==$data$$.laiSuatThoiGianConLai&&($data$$.laiSuatThoiGianConLai=$obj$$.laiSuatThoiGianConLai);let $from_address$$=$obj$$.creator,$typeUrl$$,$values$$;"9"===$obj$$.trang_thai?($typeUrl$$="/pvtruong.flexzen.flexzen.MsgCreatePeriod",$values$$={creator:$obj$$.creator,
13
- idProduct:Number($data$$.id_product||$obj$$.id_product),laiSuatCamKet:$data$$.lai_suat_cam_ket||$obj$$.lai_suat_cam_ket,laiSuatTruocHan:$data$$.lai_suat_truoc_han||$obj$$.lai_suat_truoc_han,kyHan:$data$$.ky_han||$obj$$.ky_han,choPhepRutVon:void 0!=$data$$.cho_phep_rut_von?$data$$.cho_phep_rut_von:$obj$$.cho_phep_rut_von,choPhepChuyenNhuong:void 0!=$data$$.cho_phep_chuyen_nhuong?$data$$.cho_phep_chuyen_nhuong:$obj$$.cho_phep_chuyen_nhuong,hoatDong:void 0!=$data$$.hoat_dong?$data$$.hoat_dong:$obj$$.hoat_dong,
14
- gia:Number($data$$.gia||$obj$$.gia),denom:$data$$.denom||$obj$$.denom,tgXuLyRutVon:(void 0!=$data$$.tg_xu_ly_rut_von?$data$$.tg_xu_ly_rut_von:$obj$$.tg_xu_ly_rut_von)||0,tongSoToken:(void 0!=$data$$.tong_so_token?$data$$.tong_so_token:$obj$$.tong_so_token)||0,kyTinhLai:Number(void 0==$data$$.ky_tinh_lai?$obj$$.ky_tinh_lai:$data$$.ky_tinh_lai),loiNhuanDuocChia:Number(void 0==$data$$.loi_nhuan_duoc_chia?$obj$$.loi_nhuan_duoc_chia:$data$$.loi_nhuan_duoc_chia),ngayChiaLoiNhuan:$data$$.ngay_chia_loi_nhuan?
15
- (new Date($data$$.ngay_chia_loi_nhuan)).getTime()/1E3:0,laiSuatTangThemSoHuuToken:Number($data$$.lai_suat_tang_them_so_huu_token||0),tokenSoHuu:$data$$.token_so_huu||"",soLuongSoHuu:Number($data$$.so_luong_so_huu||0),soNgayDauTuToiThieu:Number($data$$.so_ngay_dau_tu_toi_thieu||0),truLaiDaTra:$data$$.tru_lai_da_tra||!1,laiSuatThoiGianConLai:Number($data$$.lai_suat_thoi_gian_con_lai||0)}):("5"==$data$$.trang_thai&&($data$$.hoat_dong=!1),$typeUrl$$="/pvtruong.flexzen.flexzen.MsgUpdatePeriod",$values$$=
16
- {creator:$obj$$.creator,id:Number($obj$$.id),idProduct:Number($data$$.id_product||$obj$$.id_product),laiSuatCamKet:$data$$.lai_suat_cam_ket||$obj$$.lai_suat_cam_ket,laiSuatTruocHan:$data$$.lai_suat_truoc_han||$obj$$.lai_suat_truoc_han,kyHan:$data$$.ky_han||$obj$$.ky_han,choPhepRutVon:void 0!=$data$$.cho_phep_rut_von?$data$$.cho_phep_rut_von:$obj$$.cho_phep_rut_von,choPhepChuyenNhuong:void 0!=$data$$.cho_phep_chuyen_nhuong?$data$$.cho_phep_chuyen_nhuong:$obj$$.cho_phep_chuyen_nhuong,hoatDong:void 0!=
17
- $data$$.hoat_dong?$data$$.hoat_dong:$obj$$.hoat_dong,tgXuLyRutVon:(void 0!=$data$$.tg_xu_ly_rut_von?$data$$.tg_xu_ly_rut_von:$obj$$.tg_xu_ly_rut_von)||0,tongSoToken:(void 0!=$data$$.tong_so_token?$data$$.tong_so_token:$obj$$.tong_so_token)||0,loiNhuanDuocChia:Number(void 0==$data$$.loi_nhuan_duoc_chia?$obj$$.loi_nhuan_duoc_chia:$data$$.loi_nhuan_duoc_chia),ngayChiaLoiNhuan:$data$$.ngay_chia_loi_nhuan?(new Date($data$$.ngay_chia_loi_nhuan)).getTime()/1E3:0,laiSuatTangThemSoHuuToken:Number($data$$.lai_suat_tang_them_so_huu_token||
18
- 0),tokenSoHuu:$data$$.token_so_huu||"",soLuongSoHuu:Number($data$$.so_luong_so_huu||0),soNgayDauTuToiThieu:Number($data$$.so_ngay_dau_tu_toi_thieu||0),truLaiDaTra:$data$$.tru_lai_da_tra||!1,laiSuatThoiGianConLai:Number($data$$.lai_suat_thoi_gian_con_lai||0)});createTx($user$$.current_id_app,$user$$.token,{values:$values$$,typeUrl:$typeUrl$$,from_address:$from_address$$}).then(async $rs$$=>{if($rs$$.code){if(5===$rs$$.code)return $fn$$("B\u1ea1n kh\u00f4ng \u0111\u1ee7 ti\u1ec1n \u0111\u1ec3 th\u1ef1c hi\u1ec7n giao d\u1ecbch n\u00e0y");
19
- console.error($rs$$);return $fn$$($rs$$.rawLog||$rs$$)}$fn$$(null,$data$$,$obj$$)}).catch($e$$=>{console.error($e$$);$fn$$($e$$.message||$e$$.error||$e$$)})};$contr_router$$.route()};
14
+ void 0==$data$$.token_so_huu&&($data$$.token_so_huu=$obj$$.token_so_huu);void 0==$data$$.so_luong_so_huu&&($data$$.so_luong_so_huu=$obj$$.so_luong_so_huu);void 0==$data$$.tru_lai_da_tra&&($data$$.tru_lai_da_tra=$obj$$.tru_lai_da_tra);void 0==$data$$.laiSuatThoiGianConLai&&($data$$.laiSuatThoiGianConLai=$obj$$.laiSuatThoiGianConLai);void 0==$data$$.goi_dau_tu&&($data$$.goi_dau_tu=$obj$$.goi_dau_tu);void 0==$data$$.frm_step_code&&($data$$.frm_step_code=$obj$$.frm_step_code);void 0==$data$$.tong_so_token&&
15
+ ($data$$.tong_so_token=$obj$$.tong_so_token);void 0==$data$$.id_product&&($data$$.id_product=$obj$$.id_product);if($data$$.goi_dau_tu&&$data$$.frm_step_code){$frm$jscomp$2_frm_step$jscomp$1_from_address$$=await global.getModel("financialroadmap").findOne({id_app:$user$$.current_id_app,code:$data$$.id_product.toString()}).lean();if(!$frm$jscomp$2_frm_step$jscomp$1_from_address$$)return $fn$$("L\u1ed9 tr\u00ecnh t\u00e0i ch\u00ednh cho g\u00f3i \u0111\u1ea7u t\u01b0 n\u00e0y kh\u00f4ng t\u1ed3n t\u1ea1i");
16
+ $frm$jscomp$2_frm_step$jscomp$1_from_address$$=($frm$jscomp$2_frm_step$jscomp$1_from_address$$.steps||[]).find($s$$=>$s$$.code===$data$$.frm_step_code);if(!$frm$jscomp$2_frm_step$jscomp$1_from_address$$)return $fn$$("G\u00f3i \u0111\u1ea7u t\u01b0 n\u00e0y kh\u00f4ng t\u1ed3n t\u1ea1i trong l\u1ed9 tr\u00ecnh t\u00e0i ch\u00ednh");if("5"==$frm$jscomp$2_frm_step$jscomp$1_from_address$$.trang_thai)return $fn$$("G\u00f3i \u0111\u1ea7u t\u01b0 n\u00e0y \u0111\u00e3 ho\u00e0n th\u00e0nh k\u00eau g\u1ecdi v\u1ed1n");
17
+ if("4"!=$frm$jscomp$2_frm_step$jscomp$1_from_address$$.trang_thai)return $fn$$("G\u00f3i \u0111\u1ea7u t\u01b0 n\u00e0y ch\u01b0a c\u00f3 hi\u1ec7u l\u1ef1c");if($data$$.tong_so_token!=$frm$jscomp$2_frm_step$jscomp$1_from_address$$.sl_slot)return $fn$$("S\u1ed1 l\u01b0\u1ee3ng token ph\u1ea3i b\u1eb1ng v\u1edbi s\u1ed1 l\u01b0\u1ee3ng c\u1ee7a g\u00f3i \u0111\u1ea7u t\u01b0 (step) trong l\u1ed9 tr\u00ecnh t\u00e0i ch\u00ednh")}var $frm$jscomp$2_frm_step$jscomp$1_from_address$$=$obj$$.creator;let $typeUrl$$,
18
+ $values$$;"9"===$obj$$.trang_thai?($typeUrl$$="/pvtruong.flexzen.flexzen.MsgCreatePeriod",$values$$={creator:$obj$$.creator,idProduct:Number($data$$.id_product||$obj$$.id_product),laiSuatCamKet:$data$$.lai_suat_cam_ket||$obj$$.lai_suat_cam_ket,laiSuatTruocHan:$data$$.lai_suat_truoc_han||$obj$$.lai_suat_truoc_han,kyHan:$data$$.ky_han||$obj$$.ky_han,choPhepRutVon:void 0!=$data$$.cho_phep_rut_von?$data$$.cho_phep_rut_von:$obj$$.cho_phep_rut_von,choPhepChuyenNhuong:void 0!=$data$$.cho_phep_chuyen_nhuong?
19
+ $data$$.cho_phep_chuyen_nhuong:$obj$$.cho_phep_chuyen_nhuong,hoatDong:void 0!=$data$$.hoat_dong?$data$$.hoat_dong:$obj$$.hoat_dong,gia:Number($data$$.gia||$obj$$.gia),denom:$data$$.denom||$obj$$.denom,tgXuLyRutVon:(void 0!=$data$$.tg_xu_ly_rut_von?$data$$.tg_xu_ly_rut_von:$obj$$.tg_xu_ly_rut_von)||0,tongSoToken:(void 0!=$data$$.tong_so_token?$data$$.tong_so_token:$obj$$.tong_so_token)||0,kyTinhLai:Number(void 0==$data$$.ky_tinh_lai?$obj$$.ky_tinh_lai:$data$$.ky_tinh_lai),loiNhuanDuocChia:Number(void 0==
20
+ $data$$.loi_nhuan_duoc_chia?$obj$$.loi_nhuan_duoc_chia:$data$$.loi_nhuan_duoc_chia),ngayChiaLoiNhuan:$data$$.ngay_chia_loi_nhuan?(new Date($data$$.ngay_chia_loi_nhuan)).getTime()/1E3:0,laiSuatTangThemSoHuuToken:Number($data$$.lai_suat_tang_them_so_huu_token||0),tokenSoHuu:$data$$.token_so_huu||"",soLuongSoHuu:Number($data$$.so_luong_so_huu||0),soNgayDauTuToiThieu:Number($data$$.so_ngay_dau_tu_toi_thieu||0),truLaiDaTra:$data$$.tru_lai_da_tra||!1,laiSuatThoiGianConLai:Number($data$$.lai_suat_thoi_gian_con_lai||
21
+ 0)}):("5"==$data$$.trang_thai&&($data$$.hoat_dong=!1),$typeUrl$$="/pvtruong.flexzen.flexzen.MsgUpdatePeriod",$values$$={creator:$obj$$.creator,id:Number($obj$$.id),idProduct:Number($data$$.id_product||$obj$$.id_product),laiSuatCamKet:$data$$.lai_suat_cam_ket||$obj$$.lai_suat_cam_ket,laiSuatTruocHan:$data$$.lai_suat_truoc_han||$obj$$.lai_suat_truoc_han,kyHan:$data$$.ky_han||$obj$$.ky_han,choPhepRutVon:void 0!=$data$$.cho_phep_rut_von?$data$$.cho_phep_rut_von:$obj$$.cho_phep_rut_von,choPhepChuyenNhuong:void 0!=
22
+ $data$$.cho_phep_chuyen_nhuong?$data$$.cho_phep_chuyen_nhuong:$obj$$.cho_phep_chuyen_nhuong,hoatDong:void 0!=$data$$.hoat_dong?$data$$.hoat_dong:$obj$$.hoat_dong,tgXuLyRutVon:(void 0!=$data$$.tg_xu_ly_rut_von?$data$$.tg_xu_ly_rut_von:$obj$$.tg_xu_ly_rut_von)||0,tongSoToken:(void 0!=$data$$.tong_so_token?$data$$.tong_so_token:$obj$$.tong_so_token)||0,loiNhuanDuocChia:Number(void 0==$data$$.loi_nhuan_duoc_chia?$obj$$.loi_nhuan_duoc_chia:$data$$.loi_nhuan_duoc_chia),ngayChiaLoiNhuan:$data$$.ngay_chia_loi_nhuan?
23
+ (new Date($data$$.ngay_chia_loi_nhuan)).getTime()/1E3:0,laiSuatTangThemSoHuuToken:Number($data$$.lai_suat_tang_them_so_huu_token||0),tokenSoHuu:$data$$.token_so_huu||"",soLuongSoHuu:Number($data$$.so_luong_so_huu||0),soNgayDauTuToiThieu:Number($data$$.so_ngay_dau_tu_toi_thieu||0),truLaiDaTra:$data$$.tru_lai_da_tra||!1,laiSuatThoiGianConLai:Number($data$$.lai_suat_thoi_gian_con_lai||0)});createTx($user$$.current_id_app,$user$$.token,{values:$values$$,typeUrl:$typeUrl$$,from_address:$frm$jscomp$2_frm_step$jscomp$1_from_address$$}).then(async $rs$$=>
24
+ {if($rs$$.code){if(5===$rs$$.code)return $fn$$("B\u1ea1n kh\u00f4ng \u0111\u1ee7 ti\u1ec1n \u0111\u1ec3 th\u1ef1c hi\u1ec7n giao d\u1ecbch n\u00e0y");console.error($rs$$);return $fn$$($rs$$.rawLog||$rs$$)}$fn$$(null,$data$$,$obj$$)}).catch($e$$=>{console.error($e$$);$fn$$($e$$.message||$e$$.error||$e$$)})};$contr_router$$.route()};
@@ -1,4 +1,3 @@
1
1
  'use strict';const model=global.getModel("financialroadmap"),controller=require("../../controllers/controller");
2
- module.exports=function($router$$){(new controller($router$$,model,"financialroadmap",{unique:["code"],onCreating:($user$$,$obj$$,$next$$)=>{if(($obj$$.steps||[]).find($s$$=>{$s$$.sl_cp_slot=0;if(!$s$$.sl_slot)return!1;let $sl_cp_slot$$=$s$$.dillution/100*$s$$.total_share/$s$$.sl_slot;if(1>$sl_cp_slot$$||0<$sl_cp_slot$$-Math.floor($sl_cp_slot$$))return!0;$s$$.sl_cp_slot=$sl_cp_slot$$;return!1}))return $next$$("S\u1ed1 l\u01b0\u1ee3ng c\u1ed5 ph\u1ea7n m\u1ed7i slot ph\u1ea3i l\u00e0 s\u1ed1 nguy\u00ean d\u01b0\u01a1ng");$next$$(null,
3
- $obj$$)},onUpdating:($user$$,$data$$,$obj$$,$next$$)=>{$data$$.steps=$data$$.steps||$obj$$.steps;if(($data$$.steps||[]).find($s$$=>{$s$$.sl_cp_slot=0;if(!$s$$.sl_slot)return!1;let $sl_cp_slot$$=$s$$.dillution/100*$s$$.total_share/$s$$.sl_slot;if(1>$sl_cp_slot$$||0<$sl_cp_slot$$-Math.floor($sl_cp_slot$$))return!0;$s$$.sl_cp_slot=$sl_cp_slot$$;return!1}))return $next$$("S\u1ed1 l\u01b0\u1ee3ng c\u1ed5 ph\u1ea7n m\u1ed7i slot ph\u1ea3i l\u00e0 s\u1ed1 nguy\u00ean d\u01b0\u01a1ng");$next$$(null,$data$$,
4
- $obj$$)}})).route()};
2
+ module.exports=function($router$$){(new controller($router$$,model,"financialroadmap",{unique:["code"],onCreating:($user$$,$obj$$,$next$$)=>{if(($obj$$.steps||[]).find($s$$=>{$s$$.sl_cp_slot=0;if(!$s$$.sl_slot)return!1;let $sl_cp_slot$$=Math.floor($s$$.dillution/100*$s$$.total_share/$s$$.sl_slot);if(1>$sl_cp_slot$$)return!0;$s$$.sl_cp_slot=$sl_cp_slot$$;return!1}))return $next$$("S\u1ed1 l\u01b0\u1ee3ng c\u1ed5 ph\u1ea7n m\u1ed7i slot ph\u1ea3i l\u1edbn h\u01a1n kh\u00f4ng");$next$$(null,$obj$$)},
3
+ onUpdating:($user$$,$data$$,$obj$$,$next$$)=>{$data$$.steps=$data$$.steps||$obj$$.steps;if(($data$$.steps||[]).find($s$$=>{$s$$.sl_cp_slot=0;if(!$s$$.sl_slot)return!1;let $sl_cp_slot$$=Math.floor($s$$.dillution/100*$s$$.total_share/$s$$.sl_slot);if(1>$sl_cp_slot$$)return!0;$s$$.sl_cp_slot=$sl_cp_slot$$;return!1}))return $next$$("S\u1ed1 l\u01b0\u1ee3ng c\u1ed5 ph\u1ea7n m\u1ed7i slot ph\u1ea3i l\u1edbn h\u01a1n kh\u00f4ng");$next$$(null,$data$$,$obj$$)}})).route()};
@@ -2,23 +2,24 @@
2
2
  model=global.getModel("pt1"),pn6=global.getModel("pn6"),controller=require("../../controllers/controller"),trangthai=global.getModel("trangthai"),async=require("async"),ma_ct="BC1",{round}=require("../../libs/utils"),blockchainconnect=require("../../libs/blockchainconnect"),valid_detail=function($user$$,$obj$$,$fn$$){setImmediate(()=>{for(var $i_i$$=0;$i_i$$<$obj$$.details.length;$i_i$$++){var $detail_tdttno$$=$obj$$.details[$i_i$$];$detail_tdttno$$.line=$i_i$$;"VND"==$obj$$.ma_nt&&($detail_tdttno$$.tien=
3
3
  Math.round($detail_tdttno$$.tien_nt,0))}if($obj$$.tdttnos)for($i_i$$=0;$i_i$$<$obj$$.tdttnos.length;$i_i$$++)$detail_tdttno$$=$obj$$.tdttnos[$i_i$$],$detail_tdttno$$.line=$i_i$$,"VND"===$obj$$.ma_nt&&($detail_tdttno$$.tien=$detail_tdttno$$.tien_nt),$detail_tdttno$$.thanh_toan_qd=round($detail_tdttno$$.tien/$detail_tdttno$$.ty_gia_hd,2);$fn$$(null,$obj$$)})};
4
4
  module.exports=function($contr_router$$){$contr_router$$=new controller($contr_router$$,model,ma_ct.toLowerCase(),{isVoucher:!0,sort:{ngay_ct:-1,so_ct:-1},keyValues:{ma_ct},onExport:function($user$$,$obj$$,$next$$){$obj$$.tdttnos&&0<$obj$$.tdttnos.length&&($obj$$.details=$obj$$.tdttnos);$next$$()}});$contr_router$$.route();$contr_router$$.post=function($obj$$,$fn$$){$fn$$||($fn$$=function(){});async.parallel({nap_tien_vao_vi:$callback$$=>{(async()=>{if(!$obj$$.id_so5)return $callback$$();try{let $inv$$=
5
- await so5.findOne({id_app:$obj$$.id_app,_id:$obj$$.id_so5});if(!$inv$$)return $callback$$("Phi\u1ebfu n\u1ea1p ti\u1ec1n kh\u00f4ng t\u1ed3n t\u1ea1i");if(!$obj$$.da_chuyen_token){let $app$$=await App.findOne({_id:$obj$$.id_app});if(!($app$$.wallet_address&&$app$$.wallet_token&&$obj$$.details))return $callback$$("Kh\u00f4ng th\u1ec3 th\u1ef1c hi\u1ec7n l\u00fac n\u00e0y. Hay th\u1eed l\u1ea1i sau");let $details$$=$inv$$.details.filter($d$$=>$d$$.is_coin&&!$d$$.transferred&&$d$$.wallet_receiver&&$d$$.sl_xuat);
6
- await Promise.all($details$$.map($detail$$=>(async()=>{let $denom$$=$detail$$.ma_vt.toLowerCase();await blockchainconnect.spend($obj$$.id_app,$app$$.wallet_token,$app$$.wallet_address,$detail$$.wallet_receiver,{amount:$detail$$.sl_xuat,denom:$denom$$,memo:$inv$$.dien_giai||"N\u1ea1p ti\u1ec1n v\u00e0o v\u00ed"});$detail$$.transferred=!0})()));await model.findOneAndUpdate({_id:$obj$$._id},{da_chuyen_token:!0})}let $ctrlinvest$$=global.controllers.SO5;$inv$$.trang_thai="5";$inv$$.save($e$$=>{if($e$$)return $callback$$($e$$.message);
7
- controller.postData($inv$$,$ctrlinvest$$,$e$$=>{if($e$$)return $callback$$($e$$);controller.pushNotification($ctrlinvest$$,$inv$$);$callback$$()})})}catch($e$$){$callback$$($e$$.message||$e$$.error||$e$$)}})()},thanh_toan_dau_tu:$callback$$=>{(async()=>{if(!$obj$$.id_assinvestment)return $callback$$();try{let $inv$$=await assinvestment.findOne({id_app:$obj$$.id_app,_id:$obj$$.id_assinvestment});if(!$inv$$)return $callback$$("H\u1ee3p \u0111\u1ed3ng \u0111\u1ea7u t\u01b0 kh\u00f4ng t\u1ed3n t\u1ea1i");
8
- if("1"===$inv$$.trang_thai||"2"!==$inv$$.trang_thai&&"0"!==$inv$$.trang_thai)return $callback$$();console.log("Thanh toan cho khoan dau tu",$inv$$.id_period);if(!$obj$$.da_chuyen_token){let $amount$$=$inv$$.gia*$inv$$.so_luong,$denom$$=$inv$$.denom,$app$$=await App.findOne({_id:$obj$$.id_app});if($app$$.wallet_address&&$app$$.wallet_token&&$obj$$.details)try{await blockchainconnect.spend($obj$$.id_app,$app$$.wallet_token,$app$$.wallet_address,$inv$$.creator,{amount:$amount$$,denom:$denom$$,memo:"N\u1ea1p ti\u1ec1n v\u00e0o v\u00ed b\u1eb1ng chuy\u1ec3n kho\u1ea3n"}),
9
- await model.findOneAndUpdate({_id:$obj$$._id},{da_chuyen_token:!0})}catch($e$$){return $callback$$($e$$.message||$e$$.error||$e$$)}else return $callback$$("Kh\u00f4ng th\u1ec3 th\u1ef1c hi\u1ec7n l\u00fac n\u00e0y. Hay th\u1eed l\u1ea1i sau")}let $ctrlinvest$$=global.controllers.ASSINVESTMENT;$ctrlinvest$$.updating({email:$inv$$.user_created,current_id_app:$obj$$.id_app},{trang_thai:"1"},$inv$$,($e$jscomp$0$$,$data$$)=>{if($e$jscomp$0$$)return $callback$$($e$jscomp$0$$);for(let $key$$ in $data$$)$inv$$[$key$$]=
10
- $data$$[$key$$];$inv$$.trang_thai="1";$inv$$.save($e$$=>{if($e$$)return $callback$$($e$$.message);controller.pushNotification($ctrlinvest$$,$inv$$);$callback$$()})})}catch($e$$){$callback$$($e$$.message)}})()},post_tdttno:function($callback$jscomp$0$$){(new PostBook($obj$$,$obj$$.tdttnos,Tdttno_tt,function($tdttno$$,$callback$$){$tdttno$$.tk_no=$obj$$.tk_no;$callback$$($tdttno$$)})).run(function($e$jscomp$0$$,$details$$){if($e$jscomp$0$$)return $callback$jscomp$0$$($e$jscomp$0$$);async.map($details$$,
11
- ($detail$$,$callback$$)=>{setImmediate(()=>{$detail$$.con_lai_nt<=$detail$$.thanh_toan_qd?Tdttno.findOneAndUpdate({_id:$detail$$.id_tdtt.toString()},{$set:{tat_toan:!0}},($error$$,$result$$)=>{$callback$$($error$$,$result$$)}):$callback$$(null,$detail$$)})},($e$$,$rs$$)=>{$callback$jscomp$0$$($e$$,$rs$$)})})},post_socai:function($callback$$){setImmediate(()=>{const $details_sc$$=[];$obj$$.details.forEach(function($d$jscomp$1_detail$$){$d$jscomp$1_detail$$={...$d$jscomp$1_detail$$};$d$jscomp$1_detail$$.tk_no=
12
- $obj$$.tk_no;$d$jscomp$1_detail$$.ma_kh||($d$jscomp$1_detail$$.ma_kh=$obj$$.ma_kh);$details_sc$$.push($d$jscomp$1_detail$$)});$obj$$.tdttnos.forEach($t_tdttno$$=>{$t_tdttno$$={...$t_tdttno$$};$t_tdttno$$.tk_no=$obj$$.tk_no;$t_tdttno$$.ma_kh||($t_tdttno$$.ma_kh=$obj$$.ma_kh);$details_sc$$.push($t_tdttno$$)});(new PostSocai($obj$$,$details_sc$$)).run(($e$$,$rs$$)=>{$callback$$($e$$,$rs$$)})})}},($e$$,$rs$$)=>{$fn$$($e$$,$rs$$)})};$contr_router$$.creating=async function($user$$,$obj$$,$next$$){$obj$$.details||
13
- ($obj$$.details=[]);if($obj$$.tdttnos&&0<$obj$$.tdttnos.length&&(await $obj$$.tdttnos.asyncJoinModel2($user$$.current_id_app,Tdttno,{where:{id_tdtt:"_id"},fields:["tat_toan",{tien_hd_nt:"tien_nt"}]}),0<(await Promise.all($obj$$.tdttnos.map($hd$$=>(async()=>{if(!global.mongoose.Types.ObjectId.isValid($hd$$.id_tdtt))return{error:"Ho\u00e1 \u0111\u01a1n kh\u00f4ng h\u1ee3p l\u1ec7",invoice:$hd$$};let $ds_da_thanh_toan$$=await Tdttno_tt.find({id_app:$obj$$.id_app,id_tdtt:$hd$$.id_tdtt}).lean(),$da_thanh_toan$$=
14
- $ds_da_thanh_toan$$.map($t$$=>$t$$.thanh_toan_qd||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0),$con_lai$$=$hd$$.tien_hd_nt-$da_thanh_toan$$;return 0>=$con_lai$$?{error:"Ho\u00e1 \u0111\u01a1n \u0111\u00e3 \u0111\u01b0\u1ee3c thanh to\u00e1n",invoice:$hd$$,da_thanh_toan:$da_thanh_toan$$,con_lai:$con_lai$$,ds_da_thanh_toan:$ds_da_thanh_toan$$}:{invoice:$hd$$,da_thanh_toan:$da_thanh_toan$$,con_lai:$con_lai$$,ds_da_thanh_toan:$ds_da_thanh_toan$$}})()))).filter($hd$$=>$hd$$.error).length))return $next$$("Ho\u00e1 \u0111\u01a1n \u0111\u00e3 \u0111\u01b0\u1ee3c thanh to\u00e1n");
15
- valid_detail($user$$,$obj$$,function($error$$){if($error$$)return $next$$($error$$);$next$$(null,$obj$$)})};$contr_router$$.updating=function($user$$,$data$$,$obj$$,$next$$){valid_detail($user$$,$data$$,function($error$$){if($error$$)return $next$$($error$$);$next$$(null,$data$$,$obj$$)})};$contr_router$$.on("saved",function($obj$$){$obj$$.id_pn6&&pn6.updateMany({_id:$obj$$.id_pn6},{id_pt1:$obj$$._id.toString(),trang_thai:"7"},($e$jscomp$1$$,$rs$$)=>{console.log("update pn6",$obj$$.id_pn6,$rs$$);
16
- pn6.findOne({_id:$obj$$.id_pn6},($e$jscomp$0$$,$_obj$$)=>{$_obj$$&&controller.postData($_obj$$,global.controllers.PN6,$e$$=>{$e$$&&console.error($e$$)})})})});$contr_router$$.on("deleted",function($obj$$){$obj$$.id_pn6&&pn6.updateMany({_id:$obj$$.id_pn6},{id_pt1:""},()=>{pn6.updateMany({_id:$obj$$.id_pn6,trang_thai:"7"},{trang_thai:"5"},($e$jscomp$1$$,$rs$$)=>{console.log("update pn6",$obj$$.id_pn6,$rs$$);pn6.findOne({_id:$obj$$.id_pn6},($e$jscomp$0$$,$_obj$$)=>{$_obj$$&&controller.postData($_obj$$,
17
- global.controllers.PN6,$e$$=>{$e$$&&console.error($e$$)})})})})});$contr_router$$.view=function($user$$,$items$$,$fn$$){const $id_app$$=$user$$.current_id_app;async.parallel({kh:function($callback$$){setImmediate(()=>{$items$$.filter($item$$=>$item$$.ma_kh).joinModel2($id_app$$,customer,[{where:"ma_kh",fields:["ten_kh"]}],function(){$callback$$()})})},nv:function($callback$$){setImmediate(()=>{$items$$.filter($item$$=>$item$$.ma_nv).joinModel2($id_app$$,dmnv,[{where:"ma_nv",fields:["ten_nv"]}],function(){$callback$$()})})},
18
- tk:function($callback$$){setImmediate(()=>{$items$$.filter($item$$=>$item$$.tk_no).joinModel2($id_app$$,account,[{where:$item$$=>({tk:$item$$.tk_no}),fields:{ten_tk_co:"ten_tk"}}],function(){$callback$$()})})},dv:function($callback$$){setImmediate(()=>{$items$$.filter($item$$=>$item$$.ma_dvcs).joinModel2($id_app$$,dvcs,[{where:$item$$=>({_id:$item$$.ma_dvcs}),fields:["ten_dvcs"]}],function(){$callback$$()})})},trangthai:function($callback$$){setImmediate(()=>{$items$$.filter($item$$=>$item$$.trang_thai).joinModel2(null,
19
- trangthai,[{where:$item$$=>({ma_trang_thai:$item$$.trang_thai,ma_ct:$item$$.ma_ct}),fields:["ten_trang_thai","color"]}],function(){$callback$$()})})},t_tien:function($callback$$){setImmediate(()=>{$items$$.forEach(function($r$$){$r$$.t_tien=0;$r$$.t_tien_nt=0;$r$$.details&&($r$$.t_tien=$r$$.details.csum("tien"),$r$$.t_tien_nt=$r$$.details.csum("tien_nt"));$r$$.tdttnos&&($r$$.t_tien+=$r$$.tdttnos.csum("tien"),$r$$.t_tien_nt+=$r$$.tdttnos.csum("tien_nt"));$r$$.t_tt=$r$$.t_tien;$r$$.t_tt_nt=$r$$.t_tien_nt});
20
- $callback$$()})},details_tk:function($callback$$){async.map($items$$,function($r$$,$callback1$$){setImmediate(()=>{$r$$.details.filter($item$$=>$item$$.tk_co).joinModel2($id_app$$,account,[{where:$item$$=>({tk:$item$$.tk_co}),fields:[{ten_tk_co:"ten_tk"}]}],function(){$callback1$$()})})},function(){$callback$$()})},details_tk_tdttno:function($callback$$){async.map($items$$,function($r$$,$callback1$$){setImmediate(()=>{$r$$.tdttnos.filter($item$$=>$item$$.tk_co).joinModel2($id_app$$,account,[{where:$item$$=>
21
- ({tk:$item$$.tk_co}),fields:[{ten_tk_co:"ten_tk"}]}],function(){$callback1$$()})})},function(){$callback$$()})},details_contract_tdttno:function($callback$$){async.map($items$$,function($r$$,$callback1$$){setImmediate(()=>{$r$$.tdttnos.filter($item$$=>$item$$.ma_hd).joinModel2($id_app$$,contract,[{where:$item$$=>({so_hd:$item$$.ma_hd}),fields:["ten_hd"]}],function(){$callback1$$()})})},function(){$callback$$()})},details_dt_tdttno:function($callback$$){async.map($items$$,function($r$$,$callback1$$){setImmediate(()=>
22
- {$r$$.tdttnos.filter($item$$=>$item$$.ma_dt).joinModel2($id_app$$,dmdt,[{where:$item$$=>({ma_dt:$item$$.ma_dt}),fields:["ten_dt"]}],function(){$callback1$$()})})},function(){$callback$$()})},details_customer:function($callback$$){async.map($items$$,function($r$$,$callback1$$){setImmediate(()=>{$r$$.details.filter($item$$=>$item$$.ma_kh).joinModel2($id_app$$,customer,[{where:$item$$=>({ma_kh:$item$$.ma_kh}),fields:["ten_kh"]}],function(){$callback1$$()})})},function(){$callback$$()})},details_dt:function($callback$$){async.map($items$$,
23
- function($r$$,$callback1$$){setImmediate(()=>{$r$$.details.filter($item$$=>$item$$.ma_dt).joinModel2($id_app$$,dmdt,[{where:$item$$=>({ma_dt:$item$$.ma_dt}),fields:["ten_dt"]}],function(){$callback1$$()})})},function(){$callback$$()})},details_contract:function($callback$$){async.map($items$$,function($r$$,$callback1$$){setImmediate(()=>{$r$$.details.filter($item$$=>$item$$.ma_hd).joinModel2($id_app$$,contract,[{where:$item$$=>({so_hd:$item$$.ma_hd}),fields:["ten_hd"]}],function(){$callback1$$()})})},
24
- function(){$callback$$()})},details_phi:function($callback$$){async.map($items$$,function($r$$,$callback1$$){setImmediate(()=>{$r$$.details.filter($item$$=>$item$$.ma_phi).joinModel2($id_app$$,dmphi,[{where:$item$$=>({ma_phi:$item$$.ma_phi}),fields:["ten_phi"]}],function(){$callback1$$()})})},function(){$callback$$()})}},function(){$fn$$(null,$items$$)})}};
5
+ await so5.findOne({id_app:$obj$$.id_app,_id:$obj$$.id_so5});if(!$inv$$)return $callback$$("Phi\u1ebfu n\u1ea1p ti\u1ec1n kh\u00f4ng t\u1ed3n t\u1ea1i");if(!$obj$$.da_chuyen_token){let $app$$=await App.findById($obj$$.id_app);if(!($app$$.wallet_address&&$app$$.wallet_token&&$obj$$.details))return $callback$$("Kh\u00f4ng th\u1ec3 th\u1ef1c hi\u1ec7n l\u00fac n\u00e0y. Hay th\u1eed l\u1ea1i sau");let $details$$=$inv$$.details.filter($d$$=>$d$$.is_coin&&!$d$$.transferred&&$d$$.wallet_receiver&&$d$$.sl_xuat);
6
+ await Promise.all($details$$.map($detail$$=>(async()=>{var $denom_rs$$=$detail$$.ma_vt.toLowerCase();$denom_rs$$=await blockchainconnect.spend($obj$$.id_app,$app$$.wallet_token,$app$$.wallet_address,$detail$$.wallet_receiver,{amount:$detail$$.sl_xuat,denom:$denom_rs$$,memo:$inv$$.dien_giai||"N\u1ea1p ti\u1ec1n v\u00e0o v\u00ed"});if($denom_rs$$.code){if(5===$denom_rs$$.code)throw"V\u00ed h\u1ec7 th\u1ed1ng kh\u00f4ng \u0111\u1ee7 ti\u1ec1n \u0111\u1ec3 th\u1ef1c hi\u1ec7n giao d\u1ecbch n\u00e0y";
7
+ throw $denom_rs$$.rawLog;}$detail$$.transferred=!0})()));await model.findOneAndUpdate({_id:$obj$$._id},{da_chuyen_token:!0})}let $ctrlinvest$$=global.controllers.SO5;$inv$$.trang_thai="5";$inv$$.save($e$$=>{if($e$$)return $callback$$($e$$.message);controller.postData($inv$$,$ctrlinvest$$,$e$$=>{if($e$$)return $callback$$($e$$);controller.pushNotification($ctrlinvest$$,$inv$$);$callback$$()})})}catch($e$$){$callback$$($e$$.message||$e$$.error||$e$$)}})()},thanh_toan_dau_tu:$callback$$=>{(async()=>
8
+ {if(!$obj$$.id_assinvestment)return $callback$$();try{let $inv$$=await assinvestment.findOne({id_app:$obj$$.id_app,_id:$obj$$.id_assinvestment});if(!$inv$$)return $callback$$("H\u1ee3p \u0111\u1ed3ng \u0111\u1ea7u t\u01b0 kh\u00f4ng t\u1ed3n t\u1ea1i");if("1"===$inv$$.trang_thai||"2"!==$inv$$.trang_thai&&"0"!==$inv$$.trang_thai)return $callback$$();console.log("Thanh toan cho khoan dau tu",$inv$$.id_period);if(!$obj$$.da_chuyen_token){let $amount$$=$inv$$.gia*$inv$$.so_luong,$denom$$=$inv$$.denom,
9
+ $app$$=await App.findOne({_id:$obj$$.id_app});if($app$$.wallet_address&&$app$$.wallet_token&&$obj$$.details)try{await blockchainconnect.spend($obj$$.id_app,$app$$.wallet_token,$app$$.wallet_address,$inv$$.creator,{amount:$amount$$,denom:$denom$$,memo:"N\u1ea1p ti\u1ec1n v\u00e0o v\u00ed b\u1eb1ng chuy\u1ec3n kho\u1ea3n"}),await model.findOneAndUpdate({_id:$obj$$._id},{da_chuyen_token:!0})}catch($e$$){return $callback$$($e$$.message||$e$$.error||$e$$)}else return $callback$$("Kh\u00f4ng th\u1ec3 th\u1ef1c hi\u1ec7n l\u00fac n\u00e0y. Hay th\u1eed l\u1ea1i sau")}let $ctrlinvest$$=
10
+ global.controllers.ASSINVESTMENT;$ctrlinvest$$.updating({email:$inv$$.user_created,current_id_app:$obj$$.id_app},{trang_thai:"1"},$inv$$,($e$jscomp$0$$,$data$$)=>{if($e$jscomp$0$$)return $callback$$($e$jscomp$0$$);for(let $key$$ in $data$$)$inv$$[$key$$]=$data$$[$key$$];$inv$$.trang_thai="1";$inv$$.save($e$$=>{if($e$$)return $callback$$($e$$.message);controller.pushNotification($ctrlinvest$$,$inv$$);$callback$$()})})}catch($e$$){$callback$$($e$$.message)}})()},post_tdttno:function($callback$jscomp$0$$){(new PostBook($obj$$,
11
+ $obj$$.tdttnos,Tdttno_tt,function($tdttno$$,$callback$$){$tdttno$$.tk_no=$obj$$.tk_no;$callback$$($tdttno$$)})).run(function($e$jscomp$0$$,$details$$){if($e$jscomp$0$$)return $callback$jscomp$0$$($e$jscomp$0$$);async.map($details$$,($detail$$,$callback$$)=>{setImmediate(()=>{$detail$$.con_lai_nt<=$detail$$.thanh_toan_qd?Tdttno.findOneAndUpdate({_id:$detail$$.id_tdtt.toString()},{$set:{tat_toan:!0}},($error$$,$result$$)=>{$callback$$($error$$,$result$$)}):$callback$$(null,$detail$$)})},($e$$,$rs$$)=>
12
+ {$callback$jscomp$0$$($e$$,$rs$$)})})},post_socai:function($callback$$){setImmediate(()=>{const $details_sc$$=[];$obj$$.details.forEach(function($d$jscomp$1_detail$$){$d$jscomp$1_detail$$={...$d$jscomp$1_detail$$};$d$jscomp$1_detail$$.tk_no=$obj$$.tk_no;$d$jscomp$1_detail$$.ma_kh||($d$jscomp$1_detail$$.ma_kh=$obj$$.ma_kh);$details_sc$$.push($d$jscomp$1_detail$$)});$obj$$.tdttnos.forEach($t_tdttno$$=>{$t_tdttno$$={...$t_tdttno$$};$t_tdttno$$.tk_no=$obj$$.tk_no;$t_tdttno$$.ma_kh||($t_tdttno$$.ma_kh=
13
+ $obj$$.ma_kh);$details_sc$$.push($t_tdttno$$)});(new PostSocai($obj$$,$details_sc$$)).run(($e$$,$rs$$)=>{$callback$$($e$$,$rs$$)})})}},($e$$,$rs$$)=>{$fn$$($e$$,$rs$$)})};$contr_router$$.creating=async function($user$$,$obj$$,$next$$){$obj$$.details||($obj$$.details=[]);if($obj$$.tdttnos&&0<$obj$$.tdttnos.length&&(await $obj$$.tdttnos.asyncJoinModel2($user$$.current_id_app,Tdttno,{where:{id_tdtt:"_id"},fields:["tat_toan",{tien_hd_nt:"tien_nt"}]}),0<(await Promise.all($obj$$.tdttnos.map($hd$$=>(async()=>
14
+ {if(!global.mongoose.Types.ObjectId.isValid($hd$$.id_tdtt))return{error:"Ho\u00e1 \u0111\u01a1n kh\u00f4ng h\u1ee3p l\u1ec7",invoice:$hd$$};let $ds_da_thanh_toan$$=await Tdttno_tt.find({id_app:$obj$$.id_app,id_tdtt:$hd$$.id_tdtt}).lean(),$da_thanh_toan$$=$ds_da_thanh_toan$$.map($t$$=>$t$$.thanh_toan_qd||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0),$con_lai$$=$hd$$.tien_hd_nt-$da_thanh_toan$$;return 0>=$con_lai$$?{error:"Ho\u00e1 \u0111\u01a1n \u0111\u00e3 \u0111\u01b0\u1ee3c thanh to\u00e1n",invoice:$hd$$,
15
+ da_thanh_toan:$da_thanh_toan$$,con_lai:$con_lai$$,ds_da_thanh_toan:$ds_da_thanh_toan$$}:{invoice:$hd$$,da_thanh_toan:$da_thanh_toan$$,con_lai:$con_lai$$,ds_da_thanh_toan:$ds_da_thanh_toan$$}})()))).filter($hd$$=>$hd$$.error).length))return $next$$("Ho\u00e1 \u0111\u01a1n \u0111\u00e3 \u0111\u01b0\u1ee3c thanh to\u00e1n");valid_detail($user$$,$obj$$,function($error$$){if($error$$)return $next$$($error$$);$next$$(null,$obj$$)})};$contr_router$$.updating=function($user$$,$data$$,$obj$$,$next$$){valid_detail($user$$,
16
+ $data$$,function($error$$){if($error$$)return $next$$($error$$);$next$$(null,$data$$,$obj$$)})};$contr_router$$.on("saved",function($obj$$){$obj$$.id_pn6&&pn6.updateMany({_id:$obj$$.id_pn6},{id_pt1:$obj$$._id.toString(),trang_thai:"7"},($e$jscomp$1$$,$rs$$)=>{console.log("update pn6",$obj$$.id_pn6,$rs$$);pn6.findOne({_id:$obj$$.id_pn6},($e$jscomp$0$$,$_obj$$)=>{$_obj$$&&controller.postData($_obj$$,global.controllers.PN6,$e$$=>{$e$$&&console.error($e$$)})})})});$contr_router$$.on("deleted",function($obj$$){$obj$$.id_pn6&&
17
+ pn6.updateMany({_id:$obj$$.id_pn6},{id_pt1:""},()=>{pn6.updateMany({_id:$obj$$.id_pn6,trang_thai:"7"},{trang_thai:"5"},($e$jscomp$1$$,$rs$$)=>{console.log("update pn6",$obj$$.id_pn6,$rs$$);pn6.findOne({_id:$obj$$.id_pn6},($e$jscomp$0$$,$_obj$$)=>{$_obj$$&&controller.postData($_obj$$,global.controllers.PN6,$e$$=>{$e$$&&console.error($e$$)})})})})});$contr_router$$.view=function($user$$,$items$$,$fn$$){const $id_app$$=$user$$.current_id_app;async.parallel({kh:function($callback$$){setImmediate(()=>
18
+ {$items$$.filter($item$$=>$item$$.ma_kh).joinModel2($id_app$$,customer,[{where:"ma_kh",fields:["ten_kh"]}],function(){$callback$$()})})},nv:function($callback$$){setImmediate(()=>{$items$$.filter($item$$=>$item$$.ma_nv).joinModel2($id_app$$,dmnv,[{where:"ma_nv",fields:["ten_nv"]}],function(){$callback$$()})})},tk:function($callback$$){setImmediate(()=>{$items$$.filter($item$$=>$item$$.tk_no).joinModel2($id_app$$,account,[{where:$item$$=>({tk:$item$$.tk_no}),fields:{ten_tk_co:"ten_tk"}}],function(){$callback$$()})})},
19
+ dv:function($callback$$){setImmediate(()=>{$items$$.filter($item$$=>$item$$.ma_dvcs).joinModel2($id_app$$,dvcs,[{where:$item$$=>({_id:$item$$.ma_dvcs}),fields:["ten_dvcs"]}],function(){$callback$$()})})},trangthai:function($callback$$){setImmediate(()=>{$items$$.filter($item$$=>$item$$.trang_thai).joinModel2(null,trangthai,[{where:$item$$=>({ma_trang_thai:$item$$.trang_thai,ma_ct:$item$$.ma_ct}),fields:["ten_trang_thai","color"]}],function(){$callback$$()})})},t_tien:function($callback$$){setImmediate(()=>
20
+ {$items$$.forEach(function($r$$){$r$$.t_tien=0;$r$$.t_tien_nt=0;$r$$.details&&($r$$.t_tien=$r$$.details.csum("tien"),$r$$.t_tien_nt=$r$$.details.csum("tien_nt"));$r$$.tdttnos&&($r$$.t_tien+=$r$$.tdttnos.csum("tien"),$r$$.t_tien_nt+=$r$$.tdttnos.csum("tien_nt"));$r$$.t_tt=$r$$.t_tien;$r$$.t_tt_nt=$r$$.t_tien_nt});$callback$$()})},details_tk:function($callback$$){async.map($items$$,function($r$$,$callback1$$){setImmediate(()=>{$r$$.details.filter($item$$=>$item$$.tk_co).joinModel2($id_app$$,account,
21
+ [{where:$item$$=>({tk:$item$$.tk_co}),fields:[{ten_tk_co:"ten_tk"}]}],function(){$callback1$$()})})},function(){$callback$$()})},details_tk_tdttno:function($callback$$){async.map($items$$,function($r$$,$callback1$$){setImmediate(()=>{$r$$.tdttnos.filter($item$$=>$item$$.tk_co).joinModel2($id_app$$,account,[{where:$item$$=>({tk:$item$$.tk_co}),fields:[{ten_tk_co:"ten_tk"}]}],function(){$callback1$$()})})},function(){$callback$$()})},details_contract_tdttno:function($callback$$){async.map($items$$,
22
+ function($r$$,$callback1$$){setImmediate(()=>{$r$$.tdttnos.filter($item$$=>$item$$.ma_hd).joinModel2($id_app$$,contract,[{where:$item$$=>({so_hd:$item$$.ma_hd}),fields:["ten_hd"]}],function(){$callback1$$()})})},function(){$callback$$()})},details_dt_tdttno:function($callback$$){async.map($items$$,function($r$$,$callback1$$){setImmediate(()=>{$r$$.tdttnos.filter($item$$=>$item$$.ma_dt).joinModel2($id_app$$,dmdt,[{where:$item$$=>({ma_dt:$item$$.ma_dt}),fields:["ten_dt"]}],function(){$callback1$$()})})},
23
+ function(){$callback$$()})},details_customer:function($callback$$){async.map($items$$,function($r$$,$callback1$$){setImmediate(()=>{$r$$.details.filter($item$$=>$item$$.ma_kh).joinModel2($id_app$$,customer,[{where:$item$$=>({ma_kh:$item$$.ma_kh}),fields:["ten_kh"]}],function(){$callback1$$()})})},function(){$callback$$()})},details_dt:function($callback$$){async.map($items$$,function($r$$,$callback1$$){setImmediate(()=>{$r$$.details.filter($item$$=>$item$$.ma_dt).joinModel2($id_app$$,dmdt,[{where:$item$$=>
24
+ ({ma_dt:$item$$.ma_dt}),fields:["ten_dt"]}],function(){$callback1$$()})})},function(){$callback$$()})},details_contract:function($callback$$){async.map($items$$,function($r$$,$callback1$$){setImmediate(()=>{$r$$.details.filter($item$$=>$item$$.ma_hd).joinModel2($id_app$$,contract,[{where:$item$$=>({so_hd:$item$$.ma_hd}),fields:["ten_hd"]}],function(){$callback1$$()})})},function(){$callback$$()})},details_phi:function($callback$$){async.map($items$$,function($r$$,$callback1$$){setImmediate(()=>{$r$$.details.filter($item$$=>
25
+ $item$$.ma_phi).joinModel2($id_app$$,dmphi,[{where:$item$$=>({ma_phi:$item$$.ma_phi}),fields:["ten_phi"]}],function(){$callback1$$()})})},function(){$callback$$()})}},function(){$fn$$(null,$items$$)})}};