flexbiz-server 12.3.25 → 12.3.26
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 +1 -1
- package/server/controllers/controller.js +1 -1
- package/server/controllers/controllerUtils.js +3 -3
- package/server/controllers/importHandler.js +2 -2
- package/server/controllers/viewHandler.js +4 -4
- package/server/modules/vouchers/vo-bc1.js +7 -6
- package/server/modules/vouchers/vo-bn1.js +9 -9
- package/server/modules/vouchers/vo-dh2.js +16 -16
- package/server/modules/vouchers/vo-hd2.js +99 -99
- package/server/modules/vouchers/vo-pbl.js +24 -24
- package/server/modules/vouchers/vo-so1.js +36 -36
- package/server/modules/vouchers/vo-so7.js +20 -20
- package/server/modules/vouchers/vo-so9.js +38 -38
package/package.json
CHANGED
|
@@ -34,7 +34,7 @@ controller.prototype.get=function($route_name$$,$shareRoute$$=!1){const $ctrl$$=
|
|
|
34
34
|
user:$user$$,params:$params$$}=$req$$;try{handlers.findHandler($ctrl$$,{query:$query$$,body:$body$$,user:$user$$,params:$params$$,user_agent:$user_agent$$,ip:$ip$$,shareRoute:$shareRoute$$,originalUrl:$req$$.originalUrl},($e$jscomp$16_result$$,$returnvalue$$)=>{if($e$jscomp$16_result$$)return $res$$.status(400).send($e$jscomp$16_result$$);({result:$e$jscomp$16_result$$}=$returnvalue$$);if(0==$e$jscomp$16_result$$.length)return $res$$.status(404).send({error:ERRORS.ERR_NOT_FOUND,code:ERRORS.ERR_NOT_FOUND_CODE});
|
|
35
35
|
$res$$.send($e$jscomp$16_result$$[0])})}catch($e$$){console.error($e$$),$res$$.status(400).send($e$$)}})};
|
|
36
36
|
controller.prototype.postAgainHandler=function($user$$,$condition$$,$callback$jscomp$0$$,$options$$={req:null}){let $model$$=this.model,$ctrl$$=this;if(!$ctrl$$.post)return $callback$jscomp$0$$(null,{message:"Ch\u01b0\u01a1ng tr\u00ecnh \u0111ang th\u1ef1c hi\u1ec7n xong"});const $update_tk_vt$$=$condition$$.update_tk_vt;delete $condition$$.update_tk_vt;const $user_update$$={date_updated:new Date,user_updated:$user$$.email};$model$$.find($condition$$).sort({ngay_ct:1}).lean().exec(function($e$jscomp$0$$,
|
|
37
|
-
$objsrepost$$){console.log("start repost",$condition$$,$objsrepost$$.length," vouchers","by",$user$$.email);setImmediate(()=>{if($e$jscomp$0$$)return console.error("postAgain: find",$e$jscomp$0$$),$callback$jscomp$0$$({error:$e$jscomp$0$$.message||$e$jscomp$0$$.error||$e$jscomp$0$$});async.
|
|
37
|
+
$objsrepost$$){console.log("start repost",$condition$$,$objsrepost$$.length," vouchers","by",$user$$.email);setImmediate(()=>{if($e$jscomp$0$$)return console.error("postAgain: find",$e$jscomp$0$$),$callback$jscomp$0$$({error:$e$jscomp$0$$.message||$e$jscomp$0$$.error||$e$jscomp$0$$});async.map($objsrepost$$,function($obj$$,$callback$$){setImmediate(async()=>{console.log("postAgain: handle data before post",$obj$$.ma_ct,$obj$$.so_ct,$obj$$.ngay_ct,"by",$user$$.email);if($ctrl$$.reposting)try{await $ctrl$$.reposting($user$$,
|
|
38
38
|
$obj$$)}catch($e$$){return $callback$$({error:"Kh\u00f4ng th\u1ec3 x\u1eed l\u00fd \u0111\u01b0\u1ee3c d\u1eef li\u1ec7u tr\u01b0\u1edbc khi repost ch\u1ee9ng t\u1eeb:"+$obj$$.so_ct+", L\u1ed7i: "+($e$$.message||$e$$.error||"")})}$update_tk_vt$$&&$obj$$.details&&(console.log("postAgain: update tk_vt..."),await $obj$$.details.filter($d$$=>$d$$.ma_vt).asyncJoinModel2($obj$$.id_app,global.getModel("dmvt"),{where:"ma_vt",fields:"tk_vt"}),$user_update$$.details=$obj$$.details);try{console.log("postAgain: update voucher..."),
|
|
39
39
|
await $model$$.updateOne({_id:$obj$$._id},{...$user_update$$})}catch($e$$){return console.error("postAgain: error update data before repost",$e$$),$callback$$({error:"Kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt \u0111\u01b0\u1ee3c d\u1eef li\u1ec7u ch\u1ee9ng t\u1eeb "+$obj$$.so_ct+",Error:"+$e$$.message||$e$$.error||""})}console.log("postAgain: posting...");postData($obj$$,$ctrl$$,function($e$$,$rs$$){console.log("postAgain: reported",$obj$$.ma_ct,$obj$$.so_ct,$obj$$.ngay_ct,"by",$user$$.email);if($e$$)return $callback$$({error:$e$$.message||
|
|
40
40
|
$e$$.error||"Kh\u00f4ng th\u1ec3 post s\u1ed5 s\u00e1ch ch\u1ee9ng t\u1eeb:"+$obj$$.so_ct});$callback$$(null,$rs$$)},{req:$options$$.req})})},function($e$$){if($e$$)return console.error("postAgain: Error",$e$$),$callback$jscomp$0$$({error:$e$$.message||$e$$.error||$e$$});console.log("postAgain: finished",$condition$$,$objsrepost$$.length," vouchers","by",$user$$.email);$callback$jscomp$0$$(null,{message:"Ch\u01b0\u01a1ng tr\u00ecnh \u0111ang th\u1ef1c hi\u1ec7n xong"})})})})};
|
|
@@ -40,15 +40,15 @@ if(0>$str_func$$.indexOf("async ")){0>$str_func$$.indexOf("return ")&&($str_func
|
|
|
40
40
|
})`,$admins_of_user_sandbox_us$$)();_.isArray($cust_users_will_receive$$)?$users_will_receive$$=$cust_users_will_receive$$:console.error("handle user will receive notify:",$cust_users_will_receive$$,$p$jscomp$0$$.handle_receivers)}}catch($e$$){console.error("pushNotification",$e$$)}}$ctrl$$.options||($ctrl$$.options={});$ctrl$$.options.onEmitEvent||($ctrl$$.options.onEmitEvent=($obj$$,$users_will_receive$$,$next$$,$_notificationData$$)=>{$next$$(null,$users_will_receive$$,$_notificationData$$)});
|
|
41
41
|
$ctrl$$.options.onEmitEvent(Object.assign({},$obj$jscomp$0$$),$users_will_receive$$,($e$$,$_users_will_receive$$,$_notificationData$$)=>{setImmediate(()=>{if($e$$)return console.error("Error emit events",$e$$);$_users_will_receive$$=_.uniq($_users_will_receive$$);0<$_users_will_receive$$.length&&app.emitEvent($obj$jscomp$0$$.id_app,`${$ctrl$$.name.toLowerCase()}:${$eventName$$}`,$_notificationData$$||$notificationData$$,$exclude_token$$,$_users_will_receive$$,!$_justFireEvents$$)})},Object.assign({},
|
|
42
42
|
$notificationData$$),Object.assign({},$p$jscomp$0$$))})}))}})},PostBook=require("../libs/post-book"),Sokho=global.getModel("sokho"),Sokhott=global.getModel("sokhott"),Sokhokhongton=global.getModel("sokhokhongton"),Tdttno=global.getModel("tdttno"),Tdttno_tt=global.getModel("tdttno_tt"),Tdttco_tt=global.getModel("tdttco_tt"),Tdttco=global.getModel("tdttco"),Vatra=global.getModel("vatra"),Vatvao=global.getModel("vatvao"),deletePost=function($user$$,$obj$$,$callback$jscomp$1$$){$obj$$.toObject&&($obj$$=
|
|
43
|
-
$obj$$.toObject());if(!$obj$$._id)return console.error("Error when delete post: obj does not have _id",$obj$$),$callback$jscomp$1$$("Error when delete post: obj does not have _id",$obj$$);async.series({delete_model_books_registed:$callback$jscomp$0$$=>{setImmediate(()=>{if(!global.model_books)return $callback$jscomp$0$$();async.
|
|
43
|
+
$obj$$.toObject());if(!$obj$$._id)return console.error("Error when delete post: obj does not have _id",$obj$$),$callback$jscomp$1$$("Error when delete post: obj does not have _id",$obj$$);async.series({delete_model_books_registed:$callback$jscomp$0$$=>{setImmediate(()=>{if(!global.model_books)return $callback$jscomp$0$$();async.map(global.model_books.filter($d$$=>"sokho"!==$d$$&&"sokhonpp"!==$d$$&&"sokhott"!==$d$$&&"sokhokhongton"!==$d$$&&"socai"!==$d$$&&"socaitmp"!==$d$$),($bookName$$,$callback$$)=>
|
|
44
44
|
{setImmediate(()=>{let $book$$=mongoose.models[$bookName$$.toLowerCase()];$book$$?$book$$.deleteMany({id_ct:$obj$$._id.toString()},$e$$=>{$callback$$($e$$)}):$callback$$()})},$e$$=>{$callback$jscomp$0$$($e$$)})})},sk:$callback$jscomp$0$$=>{setImmediate(()=>{(new PostBook($obj$$,$obj$$.details,Sokho,function($detail$$,$callback$$){$callback$$($detail$$)})).remove(function($e$$){$callback$jscomp$0$$($e$$)})})},sktt:$callback$jscomp$0$$=>{setImmediate(()=>{(new PostBook($obj$$,$obj$$.details,Sokhott,
|
|
45
45
|
function($detail$$,$callback$$){$callback$$($detail$$)})).remove(function($e$$){$callback$jscomp$0$$($e$$)})})},skkhongton:$callback$jscomp$0$$=>{setImmediate(()=>{(new PostBook($obj$$,$obj$$.details,Sokhokhongton,function($detail$$,$callback$$){$callback$$($detail$$)})).remove(function($e$$){$callback$jscomp$0$$($e$$)})})},sknpp:$callback$jscomp$0$$=>{setImmediate(()=>{(new PostBook($obj$$,$obj$$.details,global.getModel("sokhonpp"),function($detail$$,$callback$$){$callback$$($detail$$)})).remove(function($e$$){$callback$jscomp$0$$($e$$)})})},
|
|
46
46
|
vsc:$callback$$=>{setImmediate(()=>{if(global.model_books&&0<=global.model_books.indexOf("vsocai"))return $callback$$();vsocai.deleteMany({id_ct:$obj$$._id.toString()},function($error$$){$callback$$($error$$)})})},sc:$callback$$=>{setImmediate(()=>{Socai.deleteMany({id_ct:$obj$$._id.toString()},function($error$$){$callback$$($error$$)})})},sctmp:$callback$$=>{setImmediate(()=>{global.getModel("socaitmp").deleteMany({id_ct:$obj$$._id.toString()},function($error$$){$callback$$($error$$)})})},vatra:$callback$$=>
|
|
47
47
|
{setImmediate(()=>{if(global.model_books&&0<=global.model_books.indexOf("vatra"))return $callback$$();Vatra.deleteMany({id_ct:$obj$$._id.toString()},function($error$$){$callback$$($error$$)})})},vatvao:$callback$$=>{setImmediate(()=>{if(global.model_books&&0<=global.model_books.indexOf("vatvao"))return $callback$$();Vatvao.deleteMany({id_ct:$obj$$._id.toString()},function($error$$){$callback$$($error$$)})})},tdttno:$callback$$=>{setImmediate(async()=>{let $tdtts$$=await Tdttno.find({id_ct:$obj$$._id.toString()},
|
|
48
48
|
{_id:1,tat_toan:1}).lean();if(0<$tdtts$$.length){if(0<$tdtts$$.filter($t$$=>$t$$.tat_toan).length)return $callback$$(null);$tdtts$$=$tdtts$$.map($t$$=>$t$$._id.toString());if(await Tdttno_tt.findOne({id_tdtt:{$in:$tdtts$$}}))return $callback$$()}Tdttno.deleteMany({id_ct:$obj$$._id.toString()},function($error$$){$callback$$($error$$)})})},tdttco:$callback$$=>{setImmediate(async()=>{let $tdtts$$=await Tdttco.find({id_ct:$obj$$._id.toString()},{_id:1,tat_toan:1}).lean();if(0<$tdtts$$.length){if(0<$tdtts$$.filter($t$$=>
|
|
49
|
-
$t$$.tat_toan).length)return $callback$$(null);$tdtts$$=$tdtts$$.map($t$$=>$t$$._id.toString());if(await Tdttco_tt.findOne({id_tdtt:{$in:$tdtts$$}}))return $callback$$()}Tdttco.deleteMany({id_ct:$obj$$._id.toString()},function($error$$){$callback$$($error$$)})})},tdttno_tt:$callback$jscomp$0$$=>{setImmediate(()=>{Tdttno_tt.deleteMany({id_ct:$obj$$._id.toString()},function($error$jscomp$0$$){if($error$jscomp$0$$)return $callback$jscomp$0$$($error$jscomp$0$$);$obj$$.tdttnos?async.
|
|
49
|
+
$t$$.tat_toan).length)return $callback$$(null);$tdtts$$=$tdtts$$.map($t$$=>$t$$._id.toString());if(await Tdttco_tt.findOne({id_tdtt:{$in:$tdtts$$}}))return $callback$$()}Tdttco.deleteMany({id_ct:$obj$$._id.toString()},function($error$$){$callback$$($error$$)})})},tdttno_tt:$callback$jscomp$0$$=>{setImmediate(()=>{Tdttno_tt.deleteMany({id_ct:$obj$$._id.toString()},function($error$jscomp$0$$){if($error$jscomp$0$$)return $callback$jscomp$0$$($error$jscomp$0$$);$obj$$.tdttnos?async.map($obj$$.tdttnos,
|
|
50
50
|
function($detail$$,$callback$$){setImmediate(()=>{Tdttno.findOneAndUpdate({_id:$detail$$.id_tdtt},{$set:{tat_toan:!1}},function($error$$){setImmediate(()=>{if($error$$)return $callback$$($error$$);$callback$$()})})})},function($e$$){$e$$&&console.error($e$$);$callback$jscomp$0$$()}):$callback$jscomp$0$$()})})},tdttco_tt:$callback$jscomp$0$$=>{setImmediate(()=>{Tdttco_tt.deleteMany({id_ct:$obj$$._id.toString()},function($error$jscomp$0$$){if($error$jscomp$0$$)return $callback$jscomp$0$$($error$jscomp$0$$);
|
|
51
|
-
$obj$$.tdttcos?async.
|
|
51
|
+
$obj$$.tdttcos?async.map($obj$$.tdttcos,function($detail$$,$callback$$){setImmediate(()=>{Tdttco.findOneAndUpdate({_id:$detail$$.id_tdtt},{$set:{tat_toan:!1}},function($error$$){setImmediate(()=>{if($error$$)return $callback$$($error$$);$callback$$()})})})},function($e$$){$e$$&&console.error($e$$);$callback$jscomp$0$$()}):$callback$jscomp$0$$()})})}},function($e$$){$e$$&&console.error("delete books",$e$$);$callback$jscomp$1$$($e$$,$obj$$)})},runWebhooks=async($ctrl$$,$obj$$,$action$$,$voucher_options$$)=>
|
|
52
52
|
{$voucher_options$$||($voucher_options$$=(await OptionsModel.findOne({id_app:$obj$$.id_app,id_func:$ctrl$$.name},{option:1}).lean()||{}).option);if($voucher_options$$&&$voucher_options$$.option_webhooks&&($ctrl$$=$voucher_options$$.option_webhooks.find($w$$=>$w$$.action.toUpperCase()===$action$$.toUpperCase()&&$w$$.url))){$voucher_options$$=path.dirname(__dirname)+"/workers/webhook.js";if(!fs.existsSync($voucher_options$$))return console.error("webhook process is not exitst");global.webhookPool||
|
|
53
53
|
(global.webhookPool=new StaticPool($voucher_options$$,0,1));global.webhookPool.exec({data:$obj$$,webhook_configs:$ctrl$$},$response$$=>{$response$$.error?console.error("runWebhooks",$response$$.error):console.log($response$$)})}},getNextSequence=async function($id_app$$,$ma_ct$$,$field$$,$callback$$,$options$$={}){var $condition_qct_qcts$$={status:!0,field:$field$$,id_app:$id_app$$,$and:[{$or:[{ma_ct:"#",ma_ct_khac:{$regex:$ma_ct$$,$options:"i"}},{cac_ma_ct:$ma_ct$$.toLowerCase()},{ma_ct:$ma_ct$$.toUpperCase()}]}]};
|
|
54
54
|
$options$$.id_qct&&($condition_qct_qcts$$._id=$options$$.id_qct);if($options$$.ngay_ct){let $start_date$$=moment($options$$.ngay_ct).startOf("date").toDate(),$end_date$$=moment($options$$.ngay_ct).endOf("date").toDate();$condition_qct_qcts$$.$and.push({$or:[{tu_ngay:null},{tu_ngay:{$lte:$end_date$$}}]});$condition_qct_qcts$$.$and.push({$or:[{den_ngay:null},{den_ngay:{$gte:$start_date$$}}]})}$options$$.toObject&&($options$$=$options$$.toObject());$condition_qct_qcts$$=await dmqct.find($condition_qct_qcts$$).lean();
|
|
@@ -8,8 +8,8 @@ var $dvts_kh$$=[];$model$$.schema.paths.ma_kho&&($dvts_kh$$=$data$$.filter($r$$=
|
|
|
8
8
|
[]).filter($r$$=>$r$$.ma_vt&&$r$$.ten_vt)));$kho_vts$$=$kho_vts$$.map($vt$$=>({ma_vt:$vt$$.ma_vt,ten_vt:$vt$$.ten_vt,ma_dvt:$vt$$.ma_dvt||"Kh\u00f4ng \u0111\u01a1n v\u1ecb t\u00ednh",user_created:$user$$.email}));$kho_vts$$=await $kho_vts$$.asyncGroupBy(["ma_vt","ten_vt","ma_dvt"],[]);if(0<$kho_vts$$.length){$dvts_kh$$=await $kho_vts$$.asyncGroupBy(["ma_dvt"],[]);for($dvt_tk_vt$$ of $dvts_kh$$)$dvt_tk_vt$$.id_app=$id_app$$,$dvt_tk_vt$$.ten_dvt=$dvt_tk_vt$$.ma_dvt,$dvt_tk_vt$$.status=!0,$dvt_tk_vt$$.user_created=
|
|
9
9
|
$user$$.email,await global.getModel("dmdvt").findOne({ma_dvt:$dvt_tk_vt$$.ma_dvt,id_app:$id_app$$}).lean()||(console.log("create dvt",$dvt_tk_vt$$),await global.getModel("dmdvt").create($dvt_tk_vt$$));var $dvt_tk_vt$$=(await global.getModel("account").findOne({id_app:$id_app$$,loai:1,tk:{$regex:"^156",$options:"i"}},{tk:1}).lean()||{}).tk;$dvts_kh$$=(await global.getModel("account").findOne({id_app:$id_app$$,loai:1,tk:{$regex:"^632",$options:"i"}},{tk:1}).lean()||{}).tk;$custs_listInfo_tk_dt$$=(await global.getModel("account").findOne({id_app:$id_app$$,
|
|
10
10
|
loai:1,tk:{$regex:"^511",$options:"i"}},{tk:1}).lean()||{}).tk;for(let $vt$$ of $kho_vts$$)$vt$$.id_app=$id_app$$,$vt$$.tk_vt=$dvt_tk_vt$$,$vt$$.tk_gv=$dvts_kh$$,$vt$$.tk_dt=$custs_listInfo_tk_dt$$,$vt$$.status=!0,$vt$$.user_created=$user$$.email,await global.getModel("dmvt").findOne({ma_vt:$vt$$.ma_vt,id_app:$id_app$$}).lean()||(console.log("create product",$vt$$),await global.getModel("dmvt").create($vt$$),await global.getModel("dmqddvt").create({id_app:$id_app$$,status:!0,ma_vt:$vt$$.ma_vt,ma_dvt:$vt$$.ma_dvt,
|
|
11
|
-
tu:1,ma:1}))}$data$$.forEach($r$$=>{delete $r$$.ten_dvcs;global.mongoose.Types.ObjectId.isValid($r$$._id)&&delete $r$$._id});await $data$$.filter($r$$=>$r$$.ma_dvcs).asyncJoinModel2($id_app$$,global.getModel("dvcs"),{where:{ma_dvcs:"_id"},fields:"ten_dvcs"});async.
|
|
12
|
-
$
|
|
11
|
+
tu:1,ma:1}))}$data$$.forEach($r$$=>{delete $r$$.ten_dvcs;global.mongoose.Types.ObjectId.isValid($r$$._id)&&delete $r$$._id});await $data$$.filter($r$$=>$r$$.ma_dvcs).asyncJoinModel2($id_app$$,global.getModel("dvcs"),{where:{ma_dvcs:"_id"},fields:"ten_dvcs"});async.map($data$$,function($row$$,$callback$$){const $row_keys$$=Object.keys($row$$);$row_keys$$.filter($key$$=>$ctrl$$.model.schema.paths[$key$$]).forEach($key$$=>{let $data_type$$=$ctrl$$.model.schema.paths[$key$$].instance.toLowerCase(),$data_value$$=
|
|
12
|
+
$row$$[$key$$];if($data_value$$&&_.isString($data_value$$)&&("mixed"==$data_type$$||"array"==$data_type$$)&&($data_value$$=$data_value$$.trim(),0==$data_value$$.indexOf("[")||0==$data_value$$.indexOf("{")))try{$row$$[$key$$]=JSONParser($data_value$$)}catch($e$$){delete $row$$[$key$$],console.error("Error parse data",$e$$)}});setImmediate(async()=>{for(let $i$$=0;$i$$<$modelJoins$$.length;$i$$++){let $field_ref$$=$modelJoins$$[$i$$];if($row$$[$field_ref$$.name]){let $new_data_ref$$=await global.getModel("originimportid").findOne({id_app:$id_app$$,
|
|
13
13
|
old_id:$row$$[$field_ref$$.name]}).lean();$new_data_ref$$&&($row$$[$field_ref$$.name]=$new_data_ref$$.new_id)}}delete $row$$.__v;let $old_id$$=$row$$._id;$row$$.ma_dvcs&&!$row$$.ten_dvcs&&delete $row$$.ma_dvcs;$row$$.id_app&&$id_app$$!=$row$$.id_app&&delete $row$$._id;delete $row$$.id_app;if($replace$$&&($ctrl$$.unique&&0<$ctrl$$.unique.length||$row$$._id)){let $query$$={};if($ctrl$$.unique&&0<$ctrl$$.unique.length){if($ctrl$$.options.unique_imp&&null!=$row$$[$ctrl$$.options.unique_imp]&&void 0!=
|
|
14
14
|
$row$$[$ctrl$$.options.unique_imp]&&""!=$row$$[$ctrl$$.options.unique_imp])$query$$[$ctrl$$.options.unique_imp]=$row$$[$ctrl$$.options.unique_imp];else if($ctrl$$.unique.forEach(function($k$$){0<=$row_keys$$.indexOf($k$$)&&($query$$[$k$$]=$row$$[$k$$],void 0==$query$$[$k$$]&&delete $query$$[$k$$])}),1>Object.keys($query$$).length)return $callback$$("Kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt, D\u1eef li\u1ec7u kh\u00f4ng t\u1ed3n t\u1ea1i \u0111\u1ee7 c\u00e1c gi\u00e1 tr\u1ecb:"+$ctrl$$.unique.join(","));
|
|
15
15
|
0!=$ctrl$$.require_id_app&&($query$$.id_app=$id_app$$)}else $query$$._id=$row$$._id;$ctrl$$.model.find($query$$).lean().exec(function($error$$,$rss$$){if($error$$)return $callback$$($error$$);if(1<$rss$$.length)return $callback$$("Kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt, \u0111\u1ed1i t\u01b0\u1ee3ng "+Object.values($query$$).join("-")+" \u0111\u00e3 t\u1ed3n t\u1ea1i nhi\u1ec1u h\u01a1n m\u1ed9t l\u1ea7n");setImmediate(async()=>{let $foundObject$$;1===$rss$$.length&&($foundObject$$=$rss$$[0]);$foundObject$$?
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
'use strict';const async=require("async"),_=require("lodash"),redisCache=require("../libs/redis-cache"),view=async($user$$,$self$$,$rows$$,$next$$,$options$$)=>{const $model$$=$self$$.model;let $fields_load$$="";$options$$&&$options$$.req&&$options$$.req.query&&$options$$.req.query.fields&&($fields_load$$=$options$$.req.query.fields);let $schema_paths$$=$model$$.schema.paths;for(let $index$$=0;$index$$<$rows$$.length;$index$$++){const $item$$=$rows$$[$index$$];delete $item$$.__v;$item$$.stt_sorted=
|
|
2
2
|
$index$$;delete $item$$.from_cached;_.has($schema_paths$$,"exfields")&&!$item$$.exfields&&($item$$.exfields={})}let $items$$=[];$options$$&&$options$$.req&&$options$$.req.query_cache&&!$options$$.req.query.refresh_required?await new Promise($resolve$$=>{setImmediate(async()=>{let $cacheData$$=await redisCache.getCacheReport($options$$.req.user.email,($options$$.req.user.current_id_app||"system").toString(),$self$$.name,$options$$.req.query_cache,0,$options$$.req.query.page);if($cacheData$$)for(let $index$$=
|
|
3
|
-
0;$index$$<$rows$$.length;$index$$++){const $item$$=$rows$$[$index$$];let $cacheds$$=$cacheData$$.filter($r$$=>$r$$._id===$item$$._id.toString());if(0<$cacheds$$.length)for(let $cached$$ of $cacheds$$)$cached$$.from_cached=!0,$items$$.push($cached$$);else $items$$.push($item$$)}else $items$$=$rows$$;$resolve$$()})}):$items$$=$rows$$;async.
|
|
3
|
+
0;$index$$<$rows$$.length;$index$$++){const $item$$=$rows$$[$index$$];let $cacheds$$=$cacheData$$.filter($r$$=>$r$$._id===$item$$._id.toString());if(0<$cacheds$$.length)for(let $cached$$ of $cacheds$$)$cached$$.from_cached=!0,$items$$.push($cached$$);else $items$$.push($item$$)}else $items$$=$rows$$;$resolve$$()})}):$items$$=$rows$$;async.parallel({_Participant_created:$callback$$=>{setImmediate(async()=>{_.has($schema_paths$$,"id_app")&&await $items$$.filter($item$$=>$item$$.user_created&&!$item$$.from_cached).asyncJoinModel2($user$$.current_id_app,
|
|
4
4
|
"participant",{where:{user_created:"email"},fields:{name_user_created:"name"}});await $items$$.filter($item$$=>$item$$.user_created&&!$item$$.name_user_created&&!$item$$.from_cached).asyncJoinModel2(null,"user",{where:{user_created:"email"},fields:{name_user_created:"name"}});$callback$$(null)})},_Participant_updated:$callback$$=>{setImmediate(async()=>{_.has($schema_paths$$,"id_app")&&await $items$$.filter($item$$=>$item$$.user_updated&&!$item$$.from_cached).asyncJoinModel2($user$$.current_id_app,
|
|
5
|
-
global.getModel("participant"),{where:{user_updated:"email"},fields:{name_user_updated:"name"}});await $items$$.filter($item$$=>$item$$.user_updated&&!$item$$.name_user_updated&&!$item$$.from_cached).asyncJoinModel2(null,global.getModel("user"),{where:{user_updated:"email"},fields:{name_user_updated:"name"}});$callback$$(null)})},_approve:$callback$$=>{!$fields_load$$||0<=$fields_load$$.indexOf("approve_data")?async.
|
|
5
|
+
global.getModel("participant"),{where:{user_updated:"email"},fields:{name_user_updated:"name"}});await $items$$.filter($item$$=>$item$$.user_updated&&!$item$$.name_user_updated&&!$item$$.from_cached).asyncJoinModel2(null,global.getModel("user"),{where:{user_updated:"email"},fields:{name_user_updated:"name"}});$callback$$(null)})},_approve:$callback$$=>{!$fields_load$$||0<=$fields_load$$.indexOf("approve_data")?async.map($items$$,($item$$,$next$$)=>{setImmediate(()=>{global.getModel("approve").find({id_ct:$item$$._id.toString()},
|
|
6
6
|
{title:1,trang_thai:1,user_approved:1,user_approved_name:1,date_approved:1,user_denied:1,user_denied_name:1,date_denied:1}).lean().exec(async($e$$,$rs$$)=>{setImmediate(async()=>{$item$$.approve_data=$rs$$||[];await $item$$.approve_data.filter($r$$=>$r$$.user_approved).asyncJoinModel2($item$$.id_app,global.getModel("participant"),{where:{user_approved:"email"},fields:{user_approved_name:"name",signature_image:"signature_image"}});await $item$$.approve_data.filter($r$$=>$r$$.user_denied).asyncJoinModel2($item$$.id_app,
|
|
7
|
-
global.getModel("participant"),{where:{user_denied:"email"},fields:{user_denied_name:"name",signature_image:"signature_image"}});$next$$(null)})})})},()=>{$callback$$(null)}):$callback$$(null)},transfer_ct:$callback$$=>{if(_.has($schema_paths$$,"id_ct_chuyen")&&$user$$.current_app_info&&$user$$.current_app_info.options&&$user$$.current_app_info.options.id_app_thue)async.
|
|
8
|
-
{_id:1}).lean().exec(async($e$$,$rs$$)=>{$rs$$&&($item$$.id_ct_nhan=$rs$$._id);$next$$(null)})})},()=>{$callback$$(null)});else return $callback$$()},posted:$callback$$=>{$options$$&&$options$$.req&&($options$$.req.query.show_posted_book||$options$$.req.query.show_not_post_book)?async.
|
|
7
|
+
global.getModel("participant"),{where:{user_denied:"email"},fields:{user_denied_name:"name",signature_image:"signature_image"}});$next$$(null)})})})},()=>{$callback$$(null)}):$callback$$(null)},transfer_ct:$callback$$=>{if(_.has($schema_paths$$,"id_ct_chuyen")&&$user$$.current_app_info&&$user$$.current_app_info.options&&$user$$.current_app_info.options.id_app_thue)async.map($items$$,($item$$,$next$$)=>{setImmediate(()=>{$model$$.findOne({id_app:$user$$.current_app_info.options.id_app_thue,id_ct_chuyen:$item$$._id.toString()},
|
|
8
|
+
{_id:1}).lean().exec(async($e$$,$rs$$)=>{$rs$$&&($item$$.id_ct_nhan=$rs$$._id);$next$$(null)})})},()=>{$callback$$(null)});else return $callback$$()},posted:$callback$$=>{$options$$&&$options$$.req&&($options$$.req.query.show_posted_book||$options$$.req.query.show_not_post_book)?async.map($items$$,($item$$,$next$$)=>{setImmediate(async()=>{let $book$$=$options$$.req.query.show_posted_book||$options$$.req.query.show_not_post_book,$exists$$=await global.getModel($book$$).findOne({id_ct:$item$$._id.toString()},
|
|
9
9
|
{_id:1});$item$$[`${$book$$}_posted`]=!!$exists$$;$next$$()})},()=>{$callback$$(null)}):$callback$$()}},$e$jscomp$0$$=>{if($e$jscomp$0$$)return $next$$($e$jscomp$0$$);if($options$$&&$options$$.req&&($options$$.req.query.show_posted_book||$options$$.req.query.show_not_post_book)){let $book$$=$options$$.req.query.show_posted_book||$options$$.req.query.show_not_post_book;$items$$=$items$$.filter($r$$=>$options$$.req.query.show_posted_book?$r$$[`${$book$$}_posted`]:!$r$$[`${$book$$}_posted`])}let $items_need_view$$=
|
|
10
10
|
$items$$.filter($i$$=>!$i$$.from_cached),$items_cached$$=$items$$.filter($i$$=>$i$$.from_cached);async.series({view:$callback$$=>{if($self$$.view)try{$self$$.view($user$$,$items_need_view$$,function($error$$,$rs$$){setImmediate(()=>{if($error$$)return $callback$$($error$$);$items_need_view$$=$rs$$||$items_need_view$$;$callback$$(null,$items_need_view$$)})},$options$$)}catch($e$$){console.error("Error on view of",name,$e$$),$callback$$(null,$items_need_view$$)}else $callback$$(null,$items_need_view$$)},
|
|
11
11
|
dynamicView:$callback$$=>{$self$$.dynamicView?$self$$.dynamicView($user$$,$items_need_view$$,function($error$$,$rs$$){if($error$$)return $callback$$($error$$);$items_need_view$$=$rs$$||$items_need_view$$;$callback$$(null,$items_need_view$$)}):$callback$$(null,$items_need_view$$)},viewRequired:$callback$$=>{$items$$=[...$items_cached$$,...$items_need_view$$].sort(($a$$,$b$$)=>$a$$.stt_sorted-$b$$.stt_sorted);if($self$$.viewRequired)try{$self$$.viewRequired($user$$,$items$$,function($error$$,$rs$$){if($error$$)return $callback$$($error$$);
|
|
@@ -24,9 +24,10 @@ $d$$.id_tdtt);async.mapSeries($details$jscomp$2_user$$,($detail$$,$callback$$)=>
|
|
|
24
24
|
($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$$,global.controllers.PN6,$e$$=>
|
|
25
25
|
{$e$$&&console.error($e$$)})})})})});$contr_router$$.view=function($user$$,$items$$,$fn$$){const $id_app$$=$user$$.current_id_app;async.series({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$$()})})},tk:function($callback$$){setImmediate(()=>
|
|
26
26
|
{$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,trangthai,[{where:$item$$=>
|
|
27
|
-
({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
|
|
28
|
-
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.mapSeries($items$$,function($r$$,$callback1$$){setImmediate(()=>
|
|
29
|
-
function(){$callback1$$()})})},function(){$callback$$()})},details_contract_tdttno:function($callback$$){async.mapSeries($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$$()})},
|
|
30
|
-
[]).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.mapSeries($items$$,function($r$$,$callback1$$){setImmediate(()=>{($r$$.details||[]).filter($item$$=>$item$$.ma_kh).joinModel2($id_app$$,customer,[{where:$item$$=>
|
|
31
|
-
|
|
32
|
-
function(){$callback$$()})},details_phi:function($callback$$){async.mapSeries($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$$()})}},
|
|
27
|
+
({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$$){let $f_tien_nt$$="VND"==$r$$.ma_nt?0:3;$r$$.t_tien=0;$r$$.t_tien_nt=0;$r$$.details&&($r$$.t_tien=$r$$.details.csum("tien"),$r$$.t_tien_nt=Math.roundBy($r$$.details.csum("tien_nt"),$f_tien_nt$$));$r$$.tdttnos&&($r$$.t_tien+=$r$$.tdttnos.csum("tien"),$r$$.t_tien_nt=Math.roundBy($r$$.t_tien_nt+$r$$.tdttnos.csum("tien_nt"),
|
|
28
|
+
$f_tien_nt$$));$r$$.t_tt=$r$$.t_tien;$r$$.t_tt_nt=$r$$.t_tien_nt});$callback$$()})},details_tk:function($callback$$){async.mapSeries($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.mapSeries($items$$,function($r$$,$callback1$$){setImmediate(()=>
|
|
29
|
+
{($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.mapSeries($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$$()})},
|
|
30
|
+
details_dt_tdttno:function($callback$$){async.mapSeries($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$$()})})},function(){$callback$$()})},details_customer:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){setImmediate(()=>{($r$$.details||[]).filter($item$$=>$item$$.ma_kh).joinModel2($id_app$$,customer,[{where:$item$$=>
|
|
31
|
+
({ma_kh:$item$$.ma_kh}),fields:["ten_kh"]}],function(){$callback1$$()})})},function(){$callback$$()})},details_dt:function($callback$$){async.mapSeries($items$$,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.mapSeries($items$$,function($r$$,$callback1$$){setImmediate(()=>
|
|
32
|
+
{($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.mapSeries($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$$()})}},
|
|
33
|
+
function(){$fn$$(null,$items$$)})}};
|
|
@@ -23,13 +23,13 @@ valid_detail($user$$,$data$$,function($error$$){if($error$$)return $next$$($erro
|
|
|
23
23
|
$obj$$)})};$contr_router$$.on("saved",function($obj$$){$obj$$.id_pc0&&pc0.updateMany({_id:$obj$$.id_pc0},{id_pc1:$obj$$._id.toString(),trang_thai:"6"},($e$jscomp$1$$,$rs$$)=>{console.log("update pc0",$obj$$.id_pc0,$rs$$);pc0.findOne({_id:$obj$$.id_pc0},($e$jscomp$0$$,$_obj$$)=>{$_obj$$&&controller.postData($_obj$$,global.controllers.PC0,$e$$=>{$e$$&&console.error($e$$)})})});$obj$$.id_pn6&&pn6.updateMany({_id:$obj$$.id_pn6},{id_pc1:$obj$$._id.toString(),trang_thai:"7"},($e$jscomp$1$$,$rs$$)=>{console.log("update pn6",
|
|
24
24
|
$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_pc0&&pc0.updateMany({_id:$obj$$.id_pc0},{id_pc1:""},()=>{pc0.updateMany({_id:$obj$$.id_pc0,trang_thai:"6"},{trang_thai:"4"},($e$jscomp$1$$,$rs$$)=>{console.log("update pc0",$obj$$.id_pc0,$rs$$);pc0.findOne({_id:$obj$$.id_pc0},($e$jscomp$0$$,$_obj$$)=>{$_obj$$&&controller.postData($_obj$$,
|
|
25
25
|
global.controllers.PC0,$e$$=>{$e$$&&console.error($e$$)})})})});$obj$$.id_pn6&&pn6.updateMany({_id:$obj$$.id_pn6},{id_pc1:""},()=>{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;
|
|
26
|
-
async.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
$r$$.tdttcos&&($r$$.t_tien+=$r$$.tdttcos.csum("tien"),$r$$.t_tien_nt
|
|
30
|
-
value:"ten_tk"}]}],function(){$callback1$$()})},function(){$callback$$()})})},details_tk_tdttco:function($callback$$){async.
|
|
31
|
-
$item$$.ma_dt).
|
|
32
|
-
function($r$$,$callback1$$){setImmediate(()=>{($r$$.tdttcos||[]).filter($item$$=>$item$$.ma_phi).
|
|
33
|
-
function(){$callback1$$()})})},function(){$callback$$()})},details_dt:function($callback$$){async.
|
|
34
|
-
$item$$.ma_hd).joinModel($id_app$$,contract,[{akey:"ma_hd",bkey:"so_hd",fields:[{name:"ten_hd",value:"ten_hd"}]}],function(){$callback1$$()})})},function(){$callback$$()})},details_phi:function($callback$$){async.
|
|
26
|
+
async.parallel({kh:function($callback$$){setImmediate(()=>{$items$$.filter($item$$=>$item$$.ma_kh).joinModel2($id_app$$,customer,[{where:"ma_kh",fields:[{name:"ten_kh",value:"ten_kh"}]}],function(){$callback$$()})})},nv:function($callback$$){setImmediate(()=>{$items$$.filter($item$$=>$item$$.ma_nv).joinModel2($id_app$$,dmnv,[{where:"ma_nv",fields:[{name:"ten_nv",value:"ten_nv"}]}],function(){$callback$$()})})},tk:function($callback$$){setImmediate(()=>{$items$$.filter($item$$=>$item$$.tk_co).joinModel($id_app$$,
|
|
27
|
+
account,[{akey:"tk_co",bkey:"tk",fields:[{name:"ten_tk_co",value:"ten_tk"}]}],function(){$callback$$()})})},dv:function($callback$$){setImmediate(()=>{$items$$.filter($item$$=>$item$$.ma_dvcs).joinModel($id_app$$,dvcs,[{akey:"ma_dvcs",bkey:"_id",fields:[{name:"ten_dvcs",value:"ten_dvcs"}]}],function(){$callback$$()})})},trangthai:function($callback$$){setImmediate(()=>{$items$$.filter($item$$=>$item$$.trang_thai).joinModel2(null,trangthai,[{where:{trang_thai:"ma_trang_thai",ma_ct:"ma_ct"},fields:["ten_trang_thai",
|
|
28
|
+
"color"]}],function(){$callback$$()})})},pc0:function($callback$$){setImmediate(()=>{$items$$.joinModel2($id_app$$,pc0,[{where:{id_pc0:"_id"},fields:[{so_ct_pc0:"so_ct"},{ngay_ct_pc0:"ngay_ct"}]}],function(){$callback$$()})})},t_tien:function($callback$$){setImmediate(()=>{$items$$.forEach(function($r$$){let $f_tien_nt$$="VND"==$r$$.ma_nt?0:3;$r$$.t_tien=0;$r$$.t_tien_nt=0;$r$$.t_thue_vao=0;$r$$.t_thue_vao_nt=0;$r$$.details&&($r$$.t_tien=$r$$.details.csum("tien"),$r$$.t_tien_nt=$r$$.details.csum("tien_nt"));
|
|
29
|
+
$r$$.tdttcos&&($r$$.t_tien+=$r$$.tdttcos.csum("tien"),$r$$.t_tien_nt=Math.roundBy($r$$.t_tien_nt+$r$$.tdttcos.csum("tien_nt"),$f_tien_nt$$));$r$$.vatvaos&&($r$$.t_thue_vao=$r$$.vatvaos.csum("t_thue"),$r$$.t_thue_vao_nt=$r$$.vatvaos.csum("t_thue_nt"));$r$$.t_tt=$r$$.t_tien+$r$$.t_thue_vao;$r$$.t_tt_nt=Math.roundBy($r$$.t_tien_nt+$r$$.t_thue_vao_nt,$f_tien_nt$$)});$callback$$()})},details_tk:function($callback$$){setImmediate(()=>{async.map($items$$,function($r$$,$callback1$$){($r$$.details||[]).joinModel($id_app$$,
|
|
30
|
+
account,[{akey:"tk_no",bkey:"tk",fields:[{name:"ten_tk_no",value:"ten_tk"}]}],function(){$callback1$$()})},function(){$callback$$()})})},details_tk_tdttco:function($callback$$){async.map($items$$,function($r$$,$callback1$$){setImmediate(()=>{($r$$.tdttcos||[]).joinModel($id_app$$,account,[{akey:"tk_no",bkey:"tk",fields:[{name:"ten_tk_no",value:"ten_tk"}]}],function(){$callback1$$()})})},function(){$callback$$()})},details_dt_tdttco:function($callback$$){async.map($items$$,function($r$$,$callback1$$){setImmediate(()=>
|
|
31
|
+
{($r$$.tdttcos||[]).filter($item$$=>$item$$.ma_dt).joinModel2($id_app$$,dmdt,[{where:"ma_dt",fields:[{name:"ten_dt",value:"ten_dt"}]}],function(){$callback1$$()})})},function(){$callback$$()})},details_hd_tdttco:function($callback$$){setImmediate(()=>{async.map($items$$,function($r$$,$callback1$$){($r$$.tdttcos||[]).filter($item$$=>$item$$.ma_hd).joinModel($id_app$$,contract,[{akey:"ma_hd",bkey:"so_hd",fields:[{name:"ten_hd",value:"ten_hd"}]}],function(){$callback1$$()})},function(){$callback$$()})})},
|
|
32
|
+
details_phi_tdttco:function($callback$$){async.map($items$$,function($r$$,$callback1$$){setImmediate(()=>{($r$$.tdttcos||[]).filter($item$$=>$item$$.ma_phi).joinModel2($id_app$$,dmphi,[{where:"ma_phi",fields:[{name:"ten_phi",value:"ten_phi"}]}],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:"ma_kh",
|
|
33
|
+
fields:[{name:"ten_kh",value:"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:"ma_dt",fields:[{name:"ten_dt",value:"ten_dt"}]}],function(){$callback1$$()})})},function(){$callback$$()})},details_hopdong:function($callback$$){async.map($items$$,function($r$$,$callback1$$){setImmediate(()=>{($r$$.details||
|
|
34
|
+
[]).filter($item$$=>$item$$.ma_hd).joinModel($id_app$$,contract,[{akey:"ma_hd",bkey:"so_hd",fields:[{name:"ten_hd",value:"ten_hd"}]}],function(){$callback1$$()})})},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:"ma_phi",fields:[{name:"ten_phi",value:"ten_phi"}]}],function(){$callback1$$()})})},function(){$callback$$()})}},function(){setImmediate(()=>
|
|
35
35
|
{$fn$$(null,$items$$)})})}};
|
|
@@ -10,22 +10,22 @@ $next$$){$obj$$.thue_suat=$obj$$.thue_suat||0;$f_tien_nt$jscomp$1_t_thue_nt_user
|
|
|
10
10
|
0;$detail$jscomp$0$$.tien_thue_nt=$detail$jscomp$0$$.tien_thue_nt||0;$detail$jscomp$0$$.tien=utils.round($detail$jscomp$0$$.tien_nt*$obj$$.ty_gia,0);$detail$jscomp$0$$.tien_ct=utils.round($detail$jscomp$0$$.tien_ct_nt*$obj$$.ty_gia,0);$detail$jscomp$0$$.gia_ban=utils.round($detail$jscomp$0$$.gia_ban_nt*$obj$$.ty_gia,0);$detail$jscomp$0$$.gia_ban_ct=utils.round($detail$jscomp$0$$.gia_ban_ct_nt*$obj$$.ty_gia,0);$detail$jscomp$0$$.tien_ck=utils.round($detail$jscomp$0$$.tien_ck_nt*$obj$$.ty_gia,0);$detail$jscomp$0$$.tien_thue=
|
|
11
11
|
utils.round($detail$jscomp$0$$.tien_thue_nt*$obj$$.ty_gia,0);$detail$jscomp$0$$.tien_xuat=$detail$jscomp$0$$.tien_xuat_nt}!$obj$$.details.find($r$$=>$r$$.ma_thue)&&$obj$$.thue_suat&&($obj$$.t_thue_nt=utils.round(($obj$$.details.csum("tien_ct_nt")-$obj$$.details.csum("tien_ck_nt"))*$obj$$.thue_suat/100,$f_tien_nt$jscomp$1_t_thue_nt_user$$),$obj$$.t_thue=utils.round($obj$$.t_thue_nt*($obj$$.ty_gia||1),0),$f_tien_nt$jscomp$1_t_thue_nt_user$$=$obj$$.details.csum("tien_thue_nt"),$i_t_thue$$=$obj$$.details.csum("tien_thue"),
|
|
12
12
|
($f_tien_nt$jscomp$1_t_thue_nt_user$$!==$obj$$.t_thue_nt||$i_t_thue$$!==$obj$$.t_thue)&&0<$obj$$.details.length&&($detail$jscomp$0$$=$obj$$.details[$obj$$.details.length-1],$detail$jscomp$0$$.tien_thue_nt+=$obj$$.t_thue_nt-$f_tien_nt$jscomp$1_t_thue_nt_user$$,$detail$jscomp$0$$.tien_thue+=$obj$$.t_thue-$i_t_thue$$));$obj$$.id_contract?salecontract.findOne({_id:$obj$$.id_contract}).lean().exec(($e$$,$c$$)=>{$c$$&&($obj$$.ma_hd=$c$$.ma_hd);$next$$(null,$obj$$)}):$next$$(null,$obj$$)};$contr_router$$.creating=
|
|
13
|
-
async function($user$$,$obj$$,$next$$){$obj$$.details||($obj$$.details=[]);$obj$$.id_hd2=void 0;await $obj$$.details.asyncJoinModel2($
|
|
14
|
-
moment($obj$$.ngay_ct).subtract(1,"months").toDate(),$details$$=[];$obj$$.details.forEach($d$$=>{$d$$.combo&&0<$d$$.combo.length?$details$$=[...$details$$,...$d$$.combo]:$details$$.push($d$$)});await $details$$.filter($r$$=>!$r$$.gia_mua).asyncJoinModel2($obj$$.id_app,"giatb",{where:$item$$=>({ma_vt:$item$$.ma_vt,id_app:$obj$$.id_app,nam:$ngay_nay_thang_truoc$$.getFullYear(),thang:$ngay_nay_thang_truoc$$.getMonth()+1}),fields:[{gia_mua:"gia"}]})
|
|
15
|
-
"months").toDate();await $details$$.filter($r$$=>!$r$$.gia_mua).asyncJoinModel2($obj$$.id_app,"giatb",{where:$item$$=>({ma_vt:$item$$.ma_vt,id_app:$obj$$.id_app,nam:$ngay_nay_thang_truoc$$.getFullYear(),thang:$ngay_nay_thang_truoc$$.getMonth()+1}),fields:[{gia_mua:"gia"}]});$obj$$.details.filter($d$$=>$d$$.combo&&0<$d$$.combo.length).forEach($detail$$=>{$detail$$.combo=$detail$$.combo.map($item$$=>{$item$$.sl_xuat_1_combo=$item$$.sl_xuat
|
|
16
|
-
$item$$.tien_xuat_nt=$item$$.sl_xuat*($item$$.gia_von_nt||0);$item$$.tien_hang=$item$$.tien_hang_nt=0;$item$$.tien=$item$$.tien_nt=$item$$.sl_xuat*($item$$.gia_ban_nt||0);$item$$.tien_ck=$item$$.tien_ck_nt=$item$$.sl_xuat*($item$$.tien_ck_nt||0);$item$$.tt=$item$$.tt_nt=$item$$.tien_nt-($item$$.tien_ck_nt||0);return{...$item$$}});$detail$$.gia_mua=$detail$$.combo.map($c$$=>($c$$.gia_mua||0)*$c$$.sl_xuat_1_combo).reduce(($a
|
|
17
|
-
$next$$(null,$obj$$)})};$contr_router$$.updating=async($user$$,$data$$,$obj$$,$next$$)=>{$data$$.details||($data$$.details=$obj$$.details);$data$$.ngay_ct=$data$$.ngay_ct||$obj$$.ngay_ct;await $data$$.details.asyncJoinModel2($user$$.current_id_app,dmvt,{where:"ma_vt",setFields:($item$$,$ref$$)=>{$item$$.combo
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
$
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
pxh
|
|
25
|
-
$r$$.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
13
|
+
async function($user$$,$obj$$,$next$$){$obj$$.details||($obj$$.details=[]);$obj$$.id_hd2=void 0;await $obj$$.details.asyncJoinModel2($user$$.current_id_app,dmvt,{where:"ma_vt",setFields:($item$$,$ref$$)=>{$item$$.ten_vt=$ref$$.ten_vt;$item$$.combo=$ref$$.combo||[];$item$$.ma_thue=$ref$$.ma_thue;$item$$.status_vt=$ref$$.status;$item$$.gia_mua=$ref$$.gia_mua_tmp}});let $sp_het_su_dung$$=$obj$$.details.filter($d$$=>!$d$$.status_vt);if(0<$sp_het_su_dung$$.length)return $next$$(`C\u00e1c m\u1eb7t h\u00e0ng sau \u0111\u00e3 ng\u1eebng kinh doanh : ${$sp_het_su_dung$$.map($d$$=>
|
|
14
|
+
$d$$.ten_vt).join(",")}`);let $ngay_nay_thang_truoc$$=moment($obj$$.ngay_ct).subtract(1,"months").toDate(),$details$$=[];$obj$$.details.forEach($d$$=>{$d$$.combo&&0<$d$$.combo.length?$details$$=[...$details$$,...$d$$.combo]:$details$$.push($d$$)});await $details$$.filter($r$$=>!$r$$.gia_mua).asyncJoinModel2($obj$$.id_app,"giatb",{where:$item$$=>({ma_vt:$item$$.ma_vt,id_app:$obj$$.id_app,nam:$ngay_nay_thang_truoc$$.getFullYear(),thang:$ngay_nay_thang_truoc$$.getMonth()+1}),fields:[{gia_mua:"gia"}]});
|
|
15
|
+
$ngay_nay_thang_truoc$$=moment($ngay_nay_thang_truoc$$).subtract(1,"months").toDate();await $details$$.filter($r$$=>!$r$$.gia_mua).asyncJoinModel2($obj$$.id_app,"giatb",{where:$item$$=>({ma_vt:$item$$.ma_vt,id_app:$obj$$.id_app,nam:$ngay_nay_thang_truoc$$.getFullYear(),thang:$ngay_nay_thang_truoc$$.getMonth()+1}),fields:[{gia_mua:"gia"}]});$obj$$.details.filter($d$$=>$d$$.combo&&0<$d$$.combo.length).forEach($detail$$=>{$detail$$.combo=$detail$$.combo.map($item$$=>{$item$$.sl_xuat_1_combo=$item$$.sl_xuat;
|
|
16
|
+
$item$$.sl_xuat=$item$$.sl_xuat_1_combo*$detail$$.sl_xuat;$item$$.tien_xuat=$item$$.tien_xuat_nt=$item$$.sl_xuat*($item$$.gia_von_nt||0);$item$$.tien_hang=$item$$.tien_hang_nt=0;$item$$.tien=$item$$.tien_nt=$item$$.sl_xuat*($item$$.gia_ban_nt||0);$item$$.tien_ck=$item$$.tien_ck_nt=$item$$.sl_xuat*($item$$.tien_ck_nt||0);$item$$.tt=$item$$.tt_nt=$item$$.tien_nt-($item$$.tien_ck_nt||0);return{...$item$$}});$detail$$.gia_mua=$detail$$.combo.map($c$$=>($c$$.gia_mua||0)*$c$$.sl_xuat_1_combo).reduce(($a$$,
|
|
17
|
+
$b$$)=>$a$$+$b$$,0)});$valid$$($user$$,$obj$$,async function($error$$){if($error$$)return $next$$($error$$);$next$$(null,$obj$$)})};$contr_router$$.updating=async($user$$,$data$$,$obj$$,$next$$)=>{$data$$.details||($data$$.details=$obj$$.details);$data$$.ngay_ct=$data$$.ngay_ct||$obj$$.ngay_ct;await $data$$.details.asyncJoinModel2($user$$.current_id_app,dmvt,{where:"ma_vt",setFields:($item$$,$ref$$)=>{$item$$.combo=$ref$$.combo||[];$item$$.gia_mua=$ref$$.gia_mua_tmp}});let $ngay_nay_thang_truoc$$=
|
|
18
|
+
moment($data$$.ngay_ct).subtract(1,"months").toDate(),$details$$=[];$data$$.details.forEach($d$$=>{$d$$.combo&&0<$d$$.combo.length?$details$$=[...$details$$,...$d$$.combo]:$details$$.push($d$$)});await $details$$.filter($r$$=>!$r$$.gia_mua).asyncJoinModel2($obj$$.id_app,"giatb",{where:$item$$=>({ma_vt:$item$$.ma_vt,id_app:$obj$$.id_app,nam:$ngay_nay_thang_truoc$$.getFullYear(),thang:$ngay_nay_thang_truoc$$.getMonth()+1}),fields:[{gia_mua:"gia"}]});$ngay_nay_thang_truoc$$=moment($ngay_nay_thang_truoc$$).subtract(1,
|
|
19
|
+
"months").toDate();await $details$$.filter($r$$=>!$r$$.gia_mua).asyncJoinModel2($obj$$.id_app,"giatb",{where:$item$$=>({ma_vt:$item$$.ma_vt,id_app:$obj$$.id_app,nam:$ngay_nay_thang_truoc$$.getFullYear(),thang:$ngay_nay_thang_truoc$$.getMonth()+1}),fields:[{gia_mua:"gia"}]});$data$$.details.filter($d$$=>$d$$.combo&&0<$d$$.combo.length).forEach($detail$$=>{$detail$$.combo=$detail$$.combo.map($item$$=>{void 0==$item$$.sl_xuat_1_combo&&($item$$.sl_xuat_1_combo=$item$$.sl_xuat||0);$item$$.sl_xuat=$item$$.sl_xuat_1_combo*
|
|
20
|
+
$detail$$.sl_xuat;$item$$.tien_xuat=$item$$.tien_xuat_nt=$item$$.sl_xuat*($item$$.gia_von_nt||0);$item$$.tien_hang=$item$$.tien_hang_nt=0;$item$$.tien=$item$$.tien_nt=$item$$.sl_xuat*($item$$.gia_ban_nt||0);$item$$.tien_ck=$item$$.tien_ck_nt=$item$$.sl_xuat*($item$$.tien_ck_nt||0);$item$$.tt=$item$$.tt_nt=$item$$.tien_nt-($item$$.tien_ck_nt||0);return{...$item$$}});$detail$$.gia_mua=$detail$$.combo.map($c$$=>($c$$.gia_mua||0)*$c$$.sl_xuat_1_combo).reduce(($a$$,$b$$)=>$a$$+$b$$,0)});$valid$$($user$$,
|
|
21
|
+
$data$$,async function($error$$){if($error$$)return $next$$($error$$);$next$$(null,$data$$,$obj$$)})};$contr_router$$.view=function($user$$,$items$$,$fn$$){const $id_app$$=$user$$.current_id_app;async.series({dv:function($callback$$){$items$$.filter($item$$=>$item$$.ma_dvcs).joinModel2($id_app$$,dvcs,[{where:{ma_dvcs:"_id"},fields:[{name:"ten_dvcs",value:"ten_dvcs"}]}],function(){$callback$$()})},dt:function($callback$$){$items$$.filter($item$$=>$item$$.ma_dt).joinModel2($id_app$$,dmdt,[{where:"ma_dt",
|
|
22
|
+
fields:[{name:"ten_dt",value:"ten_dt"}]}],function(){$callback$$()})},kh:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kh).joinModel2($id_app$$,customer,[{where:"ma_kh",fields:["ten_kh","dia_chi","dien_thoai","email","nh_kh"]}],function(){$callback$$()})},nv:function($callback$$){$items$$.filter($item$$=>$item$$.ma_nv).joinModel2($id_app$$,dmnv,[{where:"ma_nv",fields:[{name:"ten_nv",value:"ten_nv"}]}],function(){$callback$$()})},contract:function($callback$$){$items$$.filter($item$$=>
|
|
23
|
+
$item$$.ma_hd).joinModel2($id_app$$,contract,[{where:{ma_hd:"so_hd"},fields:["ten_hd"]}],function(){$callback$$()})},hd2:function($callback$$){$items$$.joinModel2($id_app$$,hd2,[{where:{_id:"id_dh2"},fields:[{name:"id_hd2",value:"_id"}]}],function(){$callback$$()})},lenhsx:function($callback$$){$items$$.joinModel2($id_app$$,global.getModel("lenhsx"),[{where:{_id:"id_dh2"},fields:[{name:"id_lenhsx",value:"_id"}]}],function(){$callback$$()})},pxh:function($callback$$){$items$$.joinModel2($id_app$$,
|
|
24
|
+
pxh,[{where:{_id:"id_dh2"},fields:[{name:"id_pxh",value:"_id"}]}],function(){$callback$$()})},t_tien:function($callback$$){$items$$.forEach(function($r$$){$r$$.details&&($r$$.details.forEach($d$$=>{void 0==$d$$.gia_ban_ct_nt&&$r$$.ma_nt&&$tinhGiaChuaThue$$($r$$,$d$$);$d$$.tien_nt=$d$$.tien_ct_nt-$d$$.tien_ck_nt+$d$$.tien_thue_nt}),$r$$.t_sl=$r$$.details.csum("sl_xuat"),$r$$.t_thue=$r$$.details.csum("tien_thue"),$r$$.t_thue_nt=$r$$.details.csum("tien_thue_nt"),$r$$.t_tien=$r$$.details.csum("tien"),
|
|
25
|
+
$r$$.t_tien_nt=$r$$.details.csum("tien_nt"),$r$$.t_tien_ct=$r$$.details.csum("tien_ct"),$r$$.t_tien_ct_nt=$r$$.details.csum("tien_ct_nt"),$r$$.t_ck=$r$$.details.csum("tien_ck"),$r$$.t_ck_nt=$r$$.details.csum("tien_ck_nt"),$r$$.tc_ck_nt=$r$$.t_ck_nt+($r$$.tien_ck_hd||0),$r$$.tc_ck=$r$$.t_ck+($r$$.tien_ck_hd||0)*$r$$.ty_gia,$r$$.t_tt=$r$$.t_tien_ct-$r$$.tc_ck+$r$$.t_thue+($r$$.tien_phi_vc||0),$r$$.t_tt_nt=$r$$.t_tien_ct_nt-$r$$.tc_ck_nt+$r$$.t_thue_nt+($r$$.tien_phi_vc_nt||0),$r$$.t_tien_xuat=$r$$.details.csum("tien_xuat"),
|
|
26
|
+
$r$$.t_tien_xuat_nt=$r$$.details.csum("tien_xuat_nt"),$r$$.tien_hoa_hong=$r$$.details.csum("tien_hoa_hong"),$r$$.tien_hoa_hong_gt=$r$$.details.csum("tien_hoa_hong_gt"),$r$$.tien_hoa_hong_ql=$r$$.details.csum("tien_hoa_hong_ql"),$r$$.tien_hoa_hong_kho=$r$$.details.csum("tien_hoa_hong_kho"),$r$$.thu_nhap_ctv=$r$$.details.csum("tien_hoa_hong_ctv"),$r$$.thu_nhap_ctv2=$r$$.details.csum("tien_hoa_hong_ctv2"))});$callback$$()},details_vt:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){const $details$$=
|
|
27
|
+
$r$$.details||[];setImmediate(async()=>{await $details$$.asyncJoinModel2($id_app$$,dmvt,[{where:"ma_vt",fields:"ten_vt ma_lvt tk_dt tk_gv tk_vt tk_ck".split(" "),setFields:($item$$,$ref$$)=>{$item$$.ten_vt=$ref$$.ten_vt;$item$$.tk_tl=$ref$$.tk_tl;$item$$.tk_dt=$ref$$.tk_dt;$item$$.tk_gv=$ref$$.tk_gv;$item$$.tk_vt=$ref$$.tk_vt;$item$$.tk_ck=$ref$$.tk_ck;$item$$.ma_nvt||($item$$.ma_nvt=$ref$$.ma_nvt)}}]);await $details$$.filter($d$$=>$d$$.ma_dvt&&!$d$$.he_so_qd).asyncJoinModel2($id_app$$,"dmqddvt",
|
|
28
|
+
[{where:{ma_vt:"ma_vt",ma_dvt:"ma_dvt"},setFields:($item$$,$qddct$$)=>{let $he_so_qd$$=1;$qddct$$&&($he_so_qd$$=$qddct$$.ty_le_qd||1,$qddct$$.mau&&$qddct$$.tu&&($he_so_qd$$=$qddct$$.tu/$qddct$$.mau));$item$$.he_so_qd=$he_so_qd$$}}]);$details$$.filter($i$$=>void 0!=$i$$.sl_xuat).forEach($item$$=>{$item$$.sl_xuat_qd=($item$$.sl_xuat||0)*$item$$.he_so_qd});$callback1$$()})},function(){$callback$$()})},details_tt1:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){($r$$.details||
|
|
29
29
|
[]).filter($d$$=>$d$$.ma_tt1).joinModel2($id_app$$,"dmtt",[{where:{ma_vt:"ma_vt",ma_tt1:"ma_tt"},setFields:($item$$,$ref$$)=>{$item$$.thuoc_tinh=$ref$$;$item$$.nh_tt||($item$$.nh_tt=$ref$$.nh_tt)}}],function(){$callback1$$()})},function(){$callback$$()})},details_csck:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){($r$$.details||[]).filter($d$$=>$d$$.id_cs_ck).joinModel2($id_app$$,"dmchietkhau",[{where:{id_cs_ck:"_id"},setFields:($item$$,$ref$$)=>{$item$$.ten_chietkhau=
|
|
30
30
|
$ref$$.ten_chietkhau}}],function(){$callback1$$()})},function(){$callback$$()})},details_dt:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_dt).joinModel2($id_app$$,dmdt,[{where:"ma_dt",fields:[{name:"ten_dt",value:"ten_dt"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_contract:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_hd).joinModel2($id_app$$,
|
|
31
31
|
contract,[{where:{ma_hd:"so_hd"},fields:[{name:"ten_hd",value:"ten_hd"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_phi:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_phi).joinModel2($id_app$$,dmphi,[{where:"ma_phi",fields:[{name:"ten_phi",value:"ten_phi"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_chietkhau:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){($r$$.details||
|