flexbiz-server 12.5.40 → 12.5.41
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/libs/post-socai.js +8 -8
- package/server/libs/prototypes.js +3 -3
- package/server/modules/reports/rp-backup.js +4 -0
- package/server/modules/reports/rp-kcsns.js +1 -1
- package/server/modules/systems/sys-app.js +10 -11
- package/server/modules/vouchers/vo-hd2.js +89 -86
- package/server/workers/backupApp.js +8 -8
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
const SocaiModel=global.getModel("socai"),dmtk=global.getModel("account"),async=require("async"),cktk=require("./cktk"),ckcn=require("./ckcn"),moment=require("moment"),numeral=require("numeral"),asyncCkcn=async
|
|
2
|
-
$ps_no_tien_tien$$,$ps_co$$,$du_ck_ma_nv$$)=>{var $acc_hm_query_query_hm_chung$$=await dmtk.findOne({id_app:$hmcnct_id_app$$,tk:$tk$$,loai_tk:1}).lean();if(!$acc_hm_query_query_hm_chung$$)throw"Kh\u00f4ng t\u1ed3n t\u1ea1i t\u00e0i kho\u1ea3n "+$tk$$;if($acc_hm_query_query_hm_chung$$.tk_cn){$acc_hm_query_query_hm_chung$$={id_app:$hmcnct_id_app$$,tk:$tk$$,ma_kh:$ma_kh$$,status:!0};$du_ck_ma_nv$$&&($acc_hm_query_query_hm_chung$$.ma_nv=$du_ck_ma_nv$$);
|
|
3
|
-
[{$or:[{hieu_luc_tu:null},{hieu_luc_tu:{$lte:moment($ngay_ct$$).endOf("date").toDate()}}]},{$or:[{hieu_luc_den:null},{hieu_luc_den:{$gte:moment($ngay_ct$$).startOf("date").toDate()}}]}];$acc_hm_query_query_hm_chung$$=await global.getModel("hmcn").findOne($acc_hm_query_query_hm_chung$$).lean();$acc_hm_query_query_hm_chung$$||($acc_hm_query_query_hm_chung$$={id_app:$hmcnct_id_app$$,tk:$tk$$,status:!0,ma_kh:{$in:[null,""]}}
|
|
4
|
-
await global.getModel("hmcn").findOne($acc_hm_query_query_hm_chung$$).lean());if($acc_hm_query_query_hm_chung$$){$du_ck_ma_nv$$=await asyncCkcn({id_app:$hmcnct_id_app$$,tk:$tk$$,ma_kh:$ma_kh$$,ma_nv:$du_ck_ma_nv$$,bu_tru:!0,ngay:moment($obj$$.ngay_ct).endOf("date").toDate()});if($acc_hm_query_query_hm_chung$$.loai=="2"){$du_ck_ma_nv$$=0-$du_ck_ma_nv
|
|
5
|
-
|
|
6
|
-
$
|
|
7
|
-
$acc_hm_query_query_hm_chung$$.hm)throw`Kh\u00e1ch h\u00e0ng n\u00e0y \u0111\u00e3 v\u01b0\u1ee3t h\u1ea1n m\u1ee9c c\u00f4ng n\u1ee3 ${numeral($acc_hm_query_query_hm_chung$$.hm).format()} VND, c\u00f4ng n\u1ee3 hi\u1ec7n t\u1ea1i ${numeral($du_ck_ma_nv$$).format()} VND, ph\u00e1t sinh ${$ps_no_tien_tien$$<0?"-":""} ${numeral(Math.abs($ps_no_tien_tien$$)).format()} VND`;}$hmcnct_id_app$$=await global.getModel("hmcnct").findOne({id_app:$hmcnct_id_app$$,
|
|
8
|
-
|
|
1
|
+
const SocaiModel=global.getModel("socai"),dmtk=global.getModel("account"),async=require("async"),cktk=require("./cktk"),ckcn=require("./ckcn"),moment=require("moment"),numeral=require("numeral"),asyncCkcn=async($condition$$,$options$$={model:"socai"})=>new Promise(($resolve$$,$reject$$)=>{ckcn($condition$$,($du_e$$,$rs$$)=>{if($du_e$$)return $reject$$($du_e$$);$du_e$$=$rs$$.map($r$$=>$r$$.du_no00-$r$$.du_co00).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$resolve$$($du_e$$)},$options$$)}),asyncCheckHMCN=async($hmcnct_id_app$$,
|
|
2
|
+
$obj$$,$tk$$,$ma_kh$$,$ps_no_tien_tien$$,$ps_co$$,$du_ck_ma_nv$$)=>{let $ex_id_ct$$=$obj$$?._id?.toString();var $acc_hm_query_query_hm_chung$$=await dmtk.findOne({id_app:$hmcnct_id_app$$,tk:$tk$$,loai_tk:1}).lean();if(!$acc_hm_query_query_hm_chung$$)throw"Kh\u00f4ng t\u1ed3n t\u1ea1i t\u00e0i kho\u1ea3n "+$tk$$;if($acc_hm_query_query_hm_chung$$.tk_cn){$acc_hm_query_query_hm_chung$$={id_app:$hmcnct_id_app$$,tk:$tk$$,ma_kh:$ma_kh$$,status:!0};$du_ck_ma_nv$$&&($acc_hm_query_query_hm_chung$$.ma_nv=$du_ck_ma_nv$$);
|
|
3
|
+
let $ngay_ct$$=new Date($obj$$.ngay_ct);$acc_hm_query_query_hm_chung$$.$and=[{$or:[{hieu_luc_tu:null},{hieu_luc_tu:{$lte:moment($ngay_ct$$).endOf("date").toDate()}}]},{$or:[{hieu_luc_den:null},{hieu_luc_den:{$gte:moment($ngay_ct$$).startOf("date").toDate()}}]}];$acc_hm_query_query_hm_chung$$=await global.getModel("hmcn").findOne($acc_hm_query_query_hm_chung$$).lean();$acc_hm_query_query_hm_chung$$||($acc_hm_query_query_hm_chung$$={id_app:$hmcnct_id_app$$,tk:$tk$$,status:!0,ma_kh:{$in:[null,""]}},
|
|
4
|
+
$du_ck_ma_nv$$&&($acc_hm_query_query_hm_chung$$.ma_nv=$du_ck_ma_nv$$),$acc_hm_query_query_hm_chung$$=await global.getModel("hmcn").findOne($acc_hm_query_query_hm_chung$$).lean());if($acc_hm_query_query_hm_chung$$){$du_ck_ma_nv$$=await asyncCkcn({id_app:$hmcnct_id_app$$,ex_id_ct:$ex_id_ct$$,tk:$tk$$,ma_kh:$ma_kh$$,ma_nv:$du_ck_ma_nv$$,bu_tru:!0,ngay:moment($obj$$.ngay_ct).endOf("date").toDate()},{id_ct:$obj$$._id?.toString()});if($acc_hm_query_query_hm_chung$$.loai=="2"){$du_ck_ma_nv$$=0-$du_ck_ma_nv$$;
|
|
5
|
+
$ps_no_tien_tien$$=$ps_co$$-$ps_no_tien_tien$$;if($ps_no_tien_tien$$<0)return;if($acc_hm_query_query_hm_chung$$.hm==0){if($du_ck_ma_nv$$>$acc_hm_query_query_hm_chung$$.hm)throw`Nh\u00e0 cung c\u1ea5p n\u00e0y ch\u1ec9 \u0111\u01b0\u1ee3c n\u1ee3 \u1edf \u0111\u01a1n \u0111\u1ea7u ti\u00ean. C\u00f4ng n\u1ee3 hi\u1ec7n t\u1ea1i ${numeral($du_ck_ma_nv$$).format()} VND, ph\u00e1t sinh ${$ps_no_tien_tien$$<0?"-":""} ${numeral(Math.abs($ps_no_tien_tien$$)).format()} VND`;}else if($du_ck_ma_nv$$+$ps_no_tien_tien$$>
|
|
6
|
+
$acc_hm_query_query_hm_chung$$.hm)throw`Nh\u00e0 cung c\u1ea5p n\u00e0y \u0111\u00e3 v\u01b0\u1ee3t h\u1ea1n m\u1ee9c c\u00f4ng n\u1ee3 ${numeral($acc_hm_query_query_hm_chung$$.hm).format()} VND, c\u00f4ng n\u1ee3 hi\u1ec7n t\u1ea1i ${numeral($du_ck_ma_nv$$).format()} VND, ph\u00e1t sinh ${$ps_no_tien_tien$$<0?"-":""} ${numeral(Math.abs($ps_no_tien_tien$$)).format()} VND`;}else{$ps_no_tien_tien$$-=$ps_co$$;if($ps_no_tien_tien$$<0)return;if($acc_hm_query_query_hm_chung$$.hm==0){if($du_ck_ma_nv$$>$acc_hm_query_query_hm_chung$$.hm)throw`Kh\u00e1ch h\u00e0ng n\u00e0y ch\u1ec9 \u0111\u01b0\u1ee3c n\u1ee3 \u1edf \u0111\u01a1n \u0111\u1ea7u ti\u00ean. C\u00f4ng n\u1ee3 hi\u1ec7n t\u1ea1i ${numeral($du_ck_ma_nv$$).format()} VND, ph\u00e1t sinh ${$ps_no_tien_tien$$<
|
|
7
|
+
0?"-":""} ${numeral(Math.abs($ps_no_tien_tien$$)).format()} VND`;}else if($du_ck_ma_nv$$+$ps_no_tien_tien$$>$acc_hm_query_query_hm_chung$$.hm)throw`Kh\u00e1ch h\u00e0ng n\u00e0y \u0111\u00e3 v\u01b0\u1ee3t h\u1ea1n m\u1ee9c c\u00f4ng n\u1ee3 ${numeral($acc_hm_query_query_hm_chung$$.hm).format()} VND, c\u00f4ng n\u1ee3 hi\u1ec7n t\u1ea1i ${numeral($du_ck_ma_nv$$).format()} VND, ph\u00e1t sinh ${$ps_no_tien_tien$$<0?"-":""} ${numeral(Math.abs($ps_no_tien_tien$$)).format()} VND`;}$hmcnct_id_app$$=await global.getModel("hmcnct").findOne({id_app:$hmcnct_id_app$$,
|
|
8
|
+
tk:$tk$$,ma_kh:$ma_kh$$,id_ct:$obj$$._id.toString()}).lean();$hmcnct_id_app$$||($hmcnct_id_app$$={...$acc_hm_query_query_hm_chung$$},$hmcnct_id_app$$.id_ct=$obj$$._id.toString(),delete $hmcnct_id_app$$._id,await global.getModel("hmcnct").create($hmcnct_id_app$$))}}},checkAcc=function($id_app$$,$data$$,$tk$$,$ma_kh$$,$callback$$){dmtk.findOne({id_app:$id_app$$,tk:$tk$$,loai_tk:1}).lean().then(async $acc$$=>{if(!$acc$$)return $callback$$(`T\u00e0i kho\u1ea3n ${$tk$$} kh\u00f4ng t\u1ed3n t\u1ea1i ho\u1eb7c kh\u00f4ng ph\u1ea3i l\u00e0 t\u00e0i kho\u1ea3n chi ti\u1ebft.`);
|
|
9
9
|
if($acc$$.tk_cn&&!$ma_kh$$)return $callback$$(`T\u00e0i kho\u1ea3n ${$tk$$} y\u00eau c\u1ea7u nh\u1eadp kh\u00e1ch h\u00e0ng`);if($acc$$.tk_cp_yn&&!$data$$.ma_phi)return $callback$$(`T\u00e0i kho\u1ea3n ${$tk$$} y\u00eau c\u1ea7u nh\u1eadp doanh thu/chi ph\u00ed`);if($acc$$.tk_kho_yn&&!$data$$.ma_kho)return $callback$$(`T\u00e0i kho\u1ea3n ${$tk$$} y\u00eau c\u1ea7u nh\u1eadp kho/c\u1eeda h\u00e0ng`);if($acc$$.tk_bp_yn&&!$data$$.ma_bp)return $callback$$(`T\u00e0i kho\u1ea3n ${$tk$$} y\u00eau c\u1ea7u nh\u1eadp b\u1ed9 ph\u1eadn`);
|
|
10
10
|
if($acc$$.tk_dt_yn&&!$data$$.ma_dt)return $callback$$(`T\u00e0i kho\u1ea3n ${$tk$$} y\u00eau c\u1ea7u nh\u1eadp v\u1ee5 vi\u1ec7c, d\u1ef1 \u00e1n`);if($acc$$.tk_hd_yn&&!$data$$.ma_hd)return $callback$$(`T\u00e0i kho\u1ea3n ${$tk$$} y\u00eau c\u1ea7u nh\u1eadp h\u1ee3p \u0111\u1ed3ng`);if($acc$$.tk_nv_yn&&!$data$$.ma_nv)return $callback$$(`T\u00e0i kho\u1ea3n ${$tk$$} y\u00eau c\u1ea7u nh\u1eadp nh\u00e2n vi\u00ean`);if($acc$$.tk_td1_yn&&!$data$$.ma_td1)return $callback$$(`T\u00e0i kho\u1ea3n ${$tk$$} y\u00eau c\u1ea7u nh\u1eadp ma_td1`);
|
|
11
11
|
if($acc$$.tk_td2_yn&&!$data$$.ma_td2)return $callback$$(`T\u00e0i kho\u1ea3n ${$tk$$} y\u00eau c\u1ea7u nh\u1eadp ma_td2`);if($acc$$.tk_td3_yn&&!$data$$.ma_td3)return $callback$$(`T\u00e0i kho\u1ea3n ${$tk$$} y\u00eau c\u1ea7u nh\u1eadp ma_td3`);$callback$$(null,$acc$$)}).catch($e$$=>{$callback$$($e$$)})},checkData=function($id_app$$,$ngay_ct$$,$_data$$,$callback$$){async.parallel({tk_no:$callback$$=>{checkAcc($id_app$$,$_data$$,$_data$$.tk_no,$_data$$.ma_kh_no,($e$$,$acc$$)=>{if($e$$)return $callback$$($e$$);
|
|
@@ -2,9 +2,9 @@ const _=require("underscore"),async=require("async"),{round}=require("./utils"),
|
|
|
2
2
|
Date.prototype.nextDay=function($days_of_week_distances$$){if(!$days_of_week_distances$$||$days_of_week_distances$$.length===0)return null;let $d$$=new Date(this.getTime());$days_of_week_distances$$=$days_of_week_distances$$.map($day_of_week_distance$$=>{($day_of_week_distance$$=($day_of_week_distance$$+7-$d$$.getDay())%7)||($day_of_week_distance$$=7);return $day_of_week_distance$$}).sort(($a$$,$b$$)=>$a$$-$b$$);return $days_of_week_distances$$.length>0?($d$$.setDate($d$$.getDate()+$days_of_week_distances$$[0]),
|
|
3
3
|
$d$$):null};Array.prototype.csum=function($field$$,$condition$$,$exclude$$){return _.reduce(this,function($sum$$,$row_v$$){if(!_.isMatch($row_v$$,$condition$$)||$exclude$$&&_.isMatch($row_v$$,$exclude$$))return $sum$$;$row_v$$=Number($row_v$$[$field$$]||0)||0;isNaN($row_v$$)&&($row_v$$=0);return $sum$$+$row_v$$},0)};
|
|
4
4
|
Array.prototype.cmax=function($field$$,$condition$$){return _.reduce(this,function($max$$,$row$$){let $v$$=$row$$[$field$$];return $condition$$&&!_.isMatch($row$$,$condition$$)||lodash.isUndefined($v$$)?$max$$:$max$$?lodash.isNumber($v$$)?$max$$>$v$$?$max$$:$v$$:lodash.isString($v$$)?$v$$.localeCompare($max$$)==1?$v$$:$max$$:$v$$:$v$$},null)};Array.prototype.reg=function(){if(this.length==0)return"";let $tk$$;this.forEach(function($t$$){$t$$!==""&&($tk$$=$tk$$?$tk$$+"|^"+$t$$:"^"+$t$$)});return $tk$$};
|
|
5
|
-
Array.prototype.groupBy=function($fieldkey$$,$fieldsums$$,$fn$$,$options$$){const $self$$=this;setImmediate(()=>{const $groups$$=_.groupBy($self
|
|
6
|
-
$key$$||="ZZZ"}else $key$$=$item$$[$fieldkey$$],lodash.isDate($key$$)&&($key$$=moment($key$$).format("YYYY-MM-DD")),$key$$===!1&&($key$$="false"),$key$$||$key$$==0||($key$$="__");return $key$$});async.map(_.keys($groups$$),function($key$$,$callback$$){setImmediate(()=>{let $value$$=$groups$$[$key$$],$r$$={};if(lodash.isArray($fieldkey$$)&&$value$$.length>0)for(let $k$$ of $fieldkey$$)$r$$[$k$$]=$value$$[0][$k$$],$r$$[$k$$]||$r$$[$k$$]==0||$r$$[$k$$]==0||($r$$[$k$$]="");else $r$$[$fieldkey$$]
|
|
7
|
-
$fieldsums$$.forEach(function($f$$){lodash.isObject($f$$)?$r$$[$f$$.name]=$value$$.map($v$$=>$v$$[$f$$.value]||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0):$r$$[$f$$]=$value$$.map($v$$=>$v$$[$f$$]||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0)});$options$$&&$options$$.fieldmaxs&&$options$$.fieldmaxs.forEach(function($f$$){lodash.isObject($f$$)?$r$$[$f$$.name]=$value$$.cmax($f$$.value):$r$$[$f$$]=$value$$.cmax($f$$)});$callback$$(null,$r$$)})},function($error$$,$result$$){if($error$$)return $fn$$($error$$);$fn$$(null,
|
|
5
|
+
Array.prototype.groupBy=function($fieldkey$$,$fieldsums$$,$fn$$,$options$$){const $self$$=this;setImmediate(()=>{const $groups$$=_.groupBy($self$$.filter($i$$=>$i$$),function($item$$){let $key$$="";if(lodash.isArray($fieldkey$$)){for(let $k$$ of $fieldkey$$){let $_key$$=$item$$[$k$$];lodash.isDate($_key$$)&&($_key$$=moment($_key$$).format("YYYY-MM-DD"));$_key$$===!1&&($_key$$="false");$_key$$||$_key$$==0||($_key$$="");$key$$=$key$$||$key$$==0?$key$$+"_"+$_key$$.toString():$_key$$}lodash.isString($key$$)&&
|
|
6
|
+
($key$$=$key$$.trim());$key$$||="ZZZ"}else $key$$=$item$$[$fieldkey$$],lodash.isDate($key$$)&&($key$$=moment($key$$).format("YYYY-MM-DD")),$key$$===!1&&($key$$="false"),$key$$||$key$$==0||($key$$="__");return $key$$});async.map(_.keys($groups$$),function($key$$,$callback$$){setImmediate(()=>{let $value$$=$groups$$[$key$$],$r$$={};if(lodash.isArray($fieldkey$$)&&$value$$.length>0)for(let $k$$ of $fieldkey$$)$r$$[$k$$]=$value$$[0][$k$$],$r$$[$k$$]||$r$$[$k$$]==0||$r$$[$k$$]==0||($r$$[$k$$]="");else $r$$[$fieldkey$$]=
|
|
7
|
+
$key$$;$fieldsums$$.forEach(function($f$$){lodash.isObject($f$$)?$r$$[$f$$.name]=$value$$.map($v$$=>$v$$[$f$$.value]||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0):$r$$[$f$$]=$value$$.map($v$$=>$v$$[$f$$]||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0)});$options$$&&$options$$.fieldmaxs&&$options$$.fieldmaxs.forEach(function($f$$){lodash.isObject($f$$)?$r$$[$f$$.name]=$value$$.cmax($f$$.value):$r$$[$f$$]=$value$$.cmax($f$$)});$callback$$(null,$r$$)})},function($error$$,$result$$){if($error$$)return $fn$$($error$$);$fn$$(null,
|
|
8
8
|
$result$$)})})};Array.prototype.asyncGroupBy=function($fieldkey$$,$fieldsums$$,$options$$){let $_this$$=this;return new Promise(($resolve$$,$reject$$)=>{$_this$$.groupBy($fieldkey$$,$fieldsums$$,($error$$,$rs$$)=>{if($error$$)return $reject$$($error$$);$resolve$$($rs$$)},$options$$)})};
|
|
9
9
|
Array.prototype.joinModel=function($id_app$$,$model$$,$joinFields$$,$fn$$){lodash.isArray($joinFields$$)&&$joinFields$$.forEach($join$$=>{if($join$$.where){let $_where$$={};for(let $key$$ in $join$$.where)$_where$$[$join$$.where[$key$$]]=$key$$;$join$$.where=$_where$$}});lodash.isArray($id_app$$)&&lodash.isArray($model$$)&&$model$$.forEach($join$$=>{if($join$$.where){let $_where$$={};for(let $key$$ in $join$$.where)$_where$$[$join$$.where[$key$$]]=$key$$;$join$$.where=$_where$$}});this.joinModel2($id_app$$,
|
|
10
10
|
$model$$,$joinFields$$,$fn$$)};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
const path=require("path"),permission=require("../../libs/permission"),controller=require("../../controllers/controllerRPT"),StaticPool=require("../../libs/WorkerStaticPool");
|
|
2
|
+
module.exports=function($router$$){new controller($router$$,"backup",async function($req$$,$callback$$){let $email$$=$req$$.user.email,$id_app$$=$req$$.user.current_id_app;permission.isAdmin($id_app$$,$email$$,function($backupWorkerFile_e$$,$admin$$){if(!$admin$$)return $callback$$({error:"Ch\u1ec9 admin m\u1edbi c\u00f3 quy\u1ec1n backup d\u1eef li\u1ec7u c\u1ee7a c\u00f4ng ty"});global.backupPool||($backupWorkerFile_e$$=path.dirname(path.dirname(__dirname))+"/workers/backupApp.js",global.backupPool=
|
|
3
|
+
new StaticPool($backupWorkerFile_e$$,0,1));global.getModel("log").create({id_app:$id_app$$,id_func:"app",action:"BACKUP",data:{dateFrom:$req$$.query.dateFrom||$req$$.query.tu_ngay,dateTo:$req$$.query.dateTo||$req$$.query.den_ngay,backup_app_info:$req$$.user.current_app_info}},$req$$.user.email,$req$$.user_agent,$req$$);global.backupPool.exec({id:$id_app$$,user:$email$$,dateFrom:$req$$.query.dateFrom,dateTo:$req$$.query.dateTo,backup_app_info:$req$$.user.current_app_info,dirPath:$req$$.query.dir,configs:{database:global.configs.database}},
|
|
4
|
+
$response$$=>{if($response$$.error)return $callback$$($response$$.error);$callback$$(null,[{backup_file:$response$$.file}])})})},{stream:!1})};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const cktt=require("../../libs/cktt"),ckcn=require("../../libs/ckcn"),ckdt=require("../../libs/ckdt"),cknphep=require("../../libs/cknphep"),ckvt=require("../../libs/ckvt"),ckvtnpp=require("../../libs/ckvtnpp"),ckdiem=require("../../libs/ckdiem"),cdtk=global.getModel("cdtk"),cdkh=global.getModel("cdkh"),cddt=global.getModel("cddt"),cdnphep=global.getModel("cdnphep"),cdvt=global.getModel("cdvt"),cdvtnpp=global.getModel("cdvtnpp"),cddiem=global.getModel("cddiem"),dvcs=global.getModel("dvcs"),dmkho=global.getModel("dmkho"),
|
|
2
2
|
underscore=require("underscore"),controller=require("../../controllers/controllerRPT"),async=require("async"),moment=require("moment"),utils=require("../../libs/utils");
|
|
3
3
|
module.exports=function($router$$){new controller($router$$,"kcsns",async($req$$,$callback$$)=>{if(!$req$$.user.appAdmin)return $callback$$({error:"Ch\u1ec9 ng\u01b0\u1eddi qu\u1ea3n tr\u1ecb m\u1edbi c\u00f3 quy\u1ec1n th\u1ef1c hi\u1ec7n t\u00e1c v\u1ee5 n\u00e0y"});if(!$req$$.query.nam)return $callback$$("Ch\u1ee9c n\u0103ng n\u00e0y y\u00eau c\u1ea7u tham s\u1ed1 N\u0103m(nam)");var $nam_ngay_ks$$=Number($req$$.query.nam);const $sang_nam$$=$nam_ngay_ks$$+1,$den_ngay$$=moment([$nam_ngay_ks$$,11,
|
|
4
|
-
31]).endOf("year").toDate();let $_app$$=await global.getModel("app").findOne({_id:$req$$.user.current_id_app});if(!$_app$$)return $callback$$("C\u00f4ng ty n\u00e0y kh\u00f4ng t\u1ed3n t\u1ea1i");if($nam_ngay_ks$$=await utils.isBookLocked({id_app:$req$$.user.current_id_app,ngay_ct
|
|
4
|
+
31]).endOf("year").toDate();let $_app$$=await global.getModel("app").findOne({_id:$req$$.user.current_id_app});if(!$_app$$)return $callback$$("C\u00f4ng ty n\u00e0y kh\u00f4ng t\u1ed3n t\u1ea1i");if($nam_ngay_ks$$=await utils.isBookLocked({id_app:$req$$.user.current_id_app,ngay_ct:moment(`${$sang_nam$$}-01-01`).startOf("year").toDate(),ngay_ks:$_app$$.ngay_ks}))return $callback$$(`\u0110\u00e3 kh\u00f3a s\u1ed5 \u0111\u1ebfn ng\u00e0y ${moment($nam_ngay_ks$$).format("DD/MM/YYYY")}`);dvcs.find({id_app:$req$$.query.id_app}).lean().then(function($ds_dvcs$$){async.mapSeries($ds_dvcs$$,
|
|
5
5
|
function($dv$$,$callback$$){const $ma_dvcs$$=$dv$$._id.toString(),$condition$$={id_app:$req$$.query.id_app,ngay:$den_ngay$$,ma_dvcs:$ma_dvcs$$};async.series({ck_tt:function($callback$$){setImmediate(()=>{cdtk.deleteMany({nam:$sang_nam$$,id_app:$req$$.query.id_app,kc_yn:!0,ma_dvcs:$ma_dvcs$$},function($condition_tktt_e$$){if($condition_tktt_e$$)return $callback$$($condition_tktt_e$$);$condition_tktt_e$$={...$condition$$,groupBy:["tk"]};($_app$$.options||{}).kc_theo_kho&&$condition_tktt_e$$.groupBy.push("ma_kho");
|
|
6
6
|
cktt($condition_tktt_e$$,function($e$$,$rs$$){if($e$$)return $callback$$($e$$);$rs$$.forEach(function($r$$){delete $r$$._id;delete $r$$.date_created;delete $r$$.date_updated;$r$$.user_created=$req$$.user.email;$r$$.user_updated=$req$$.user.email;$r$$.nam=$sang_nam$$;$r$$.id_app=$req$$.query.id_app;$r$$.kc_yn=!0;$r$$.ma_dvcs=$ma_dvcs$$});async.mapSeries($rs$$,function($r$$,$callback$$){(new cdtk($r$$)).save(function($e$$,$rs_s$$){if($e$$)return $e$$.data=$r$$,$callback$$($e$$);$callback$$(null,$rs_s$$)})},
|
|
7
7
|
function($e$$,$rs$$){if($e$$)return $callback$$($e$$);$callback$$(null,$rs$$)})})})})},ck_cn:function($callback$$){setImmediate(()=>{cdkh.deleteMany({nam:$sang_nam$$,id_app:$req$$.query.id_app,kc_yn:!0,ma_dvcs:$ma_dvcs$$},function($e$$){if($e$$)return $callback$$($e$$);$e$$=["tk","ma_kh"];$req$$.query.cn_theo_dt&&$e$$.push("ma_dt");$req$$.query.cn_theo_kho&&$e$$.push("ma_kho");$req$$.query.cn_theo_bp&&$e$$.push("ma_bp");$req$$.query.cn_theo_nv&&$e$$.push("ma_nv");$req$$.query.cn_theo_hd&&$e$$.push("ma_hd");
|
|
@@ -18,14 +18,13 @@ delete $data$$.ngay_ks;underscore.contains($usersAdmin$$,$user$$.email)||isSuppe
|
|
|
18
18
|
$obj$$.user_created&&!underscore.contains($usersAdmin$$,$user$$.email)&&!isSupperAdmin($user$$.email.toLowerCase()))return $next$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n x\u00f3a c\u00f4ng ty n\u00e0y");$next$$(null,$obj$$)};$contr_router$$.deleted=function($user$$,$obj$$,$next$$){async.mapLimit(fs.readdirSync(path.dirname(path.dirname(__dirname))+"/models").filter($f$$=>$f$$.indexOf(".js")>0),20,($file$$,$callback$$)=>{try{let $_model$$=global.getModel(""+$file$$);underscore.has($_model$$.schema.paths,
|
|
19
19
|
"id_app")?$_model$$.deleteMany({id_app:$obj$$._id},()=>{console.log("Deleted ",$file$$,"id_app",$obj$$._id);$callback$$()}):$callback$$()}catch($e$$){console.error("Can't delete mode",$file$$,"error:",$e$$.message),$callback$$()}},()=>{$next$$(null,$obj$$)})};$contr_router$$.router.route($contr_router$$.route_name+"/backup/:id").get(function($req$$,$res$$){let $email$$=$req$$.user.email,$id_app$$=$req$$.params.id;permission.isAdmin($id_app$$,$email$$,function($backupWorkerFile_e$$,$admin$$){if(!$admin$$)return $res$$.status(400).send({error:"Ch\u1ec9 admin m\u1edbi c\u00f3 quy\u1ec1n backup d\u1eef li\u1ec7u c\u1ee7a c\u00f4ng ty"});
|
|
20
20
|
global.backupPool||($backupWorkerFile_e$$=path.dirname(path.dirname(__dirname))+"/workers/backupApp.js",global.backupPool=new StaticPool($backupWorkerFile_e$$,0,1));global.getModel("log").create({id_app:$id_app$$,id_func:"app",action:"BACKUP",data:{dateFrom:$req$$.query.dateFrom,dateTo:$req$$.query.dateTo,backup_app_info:$req$$.query.backup_app_info}},$req$$.user.email,$req$$.user_agent,$req$$);global.backupPool.exec({id:$id_app$$,user:$email$$,dateFrom:$req$$.query.dateFrom,dateTo:$req$$.query.dateTo,
|
|
21
|
-
backup_app_info:$req$$.query.backup_app_info,configs:{database:global.configs.database}},$response$$=>{if($response$$.error)return $res$$.status(400).send($response$$.error);$res$$.sendFile(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
$
|
|
27
|
-
$
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
email:$user$$.email,id_app:$id_app$$,user_created:$user$$.email,user_updated:$user$$.email,kh_yn:!0,of_user:$user$$.email};isMobilePhone($user$$.email,["vi-VN"])&&($cust_e$$.dien_thoai=$user$$.email);try{Customer.asyncCreateCustomer($cust_e$$)}catch($e$$){console.log("Auto create new customer with error:",$e$$.message)}$res$$.send("ok")})}catch($e$$){$res$$.status(400).send($e$$.message)}$res$$.send("ok")})};
|
|
21
|
+
backup_app_info:$req$$.query.backup_app_info,configs:{database:global.configs.database}},$response$$=>{if($response$$.error)return $res$$.status(400).send($response$$.error);$res$$.sendFile($response$$.file)})})});$contr_router$$.router.route($contr_router$$.route_name+"/restore/:id").post(async function($req$$,$res$$){let $fileZip$$;$req$$.files&&$req$$.files.backup&&$req$$.files.backup.path?$fileZip$$=$req$$.files.backup.path:$req$$.body&&$req$$.body.file_from_server&&fs.existsSync($req$$.body.file_from_server)&&
|
|
22
|
+
($fileZip$$=$req$$.body.file_from_server);if(!$fileZip$$)return $res$$.status(400).send("Kh\u00f4ng t\u00ecm th\u1ea5y file backup");let $email$$=$req$$.user.email,$id_app$$=$req$$.params.id;permission.isAdmin($id_app$$,$email$$,function($backupWorkerFile$jscomp$1_e$$,$admin$$){if(!$admin$$)return $res$$.status(400).send({error:"Ch\u1ec9 admin m\u1edbi c\u00f3 quy\u1ec1n restore d\u1eef li\u1ec7u c\u1ee7a c\u00f4ng ty"});global.backupPool||($backupWorkerFile$jscomp$1_e$$=path.dirname(path.dirname(__dirname))+
|
|
23
|
+
"/workers/backupApp.js",global.backupPool=new StaticPool($backupWorkerFile$jscomp$1_e$$,0,1));global.backupPool.exec({id:$id_app$$,user:$email$$,configs:{database:global.configs.database}},$response$$=>{if($response$$.error)return $res$$.status(400).send($response$$.error);global.getModel("log").create({id_app:$id_app$$,id_func:"app",action:"RESTORE",data:{backup_file:path.dirname(path.dirname(__dirname))+"/backup/"+$response$$.file,restore_file:$fileZip$$}},$req$$.user.email,$req$$.user_agent,$req$$);
|
|
24
|
+
global.restorePool||($response$$=path.dirname(path.dirname(__dirname))+"/workers/restoreApp.js",global.restorePool=new StaticPool($response$$));global.restorePool.exec({id:$id_app$$,user:$email$$,file:$fileZip$$,configs:{database:global.configs.database}},$response$$=>{$response$$.error?(console.error("[restore data] l\u1ed7i khi restore data",$response$$.error),_Notification.createNotification($email$$,$email$$,$response$$.error,$response$$.error,null,null,!0,$req$$.access_token,!0)):(console.log("[restore data] \u0111\u00e3 ho\u00e0n th\u00e0nh restore d\u1eef li\u1ec7u. \u0110ang g\u1eedi email th\u00f4ng b\u00e1o k\u1ebft qu\u1ea3"),
|
|
25
|
+
_Notification.createNotification($email$$,$email$$,$response$$.result,$response$$.result,null,null,!0,$req$$.access_token,!0))});$res$$.send("Ch\u01b0\u01a1ng tr\u00ecnh \u0111ang th\u1ef1c hi\u1ec7n. Xin ch\u1edd trong gi\u00e2y l\u00e1t")})})});$contr_router$$.router.route($contr_router$$.route_name+"/apps/:email_owner").get(async function($query_req$$,$res$$){var $_appsOfUser$jscomp$1_email$$=$query_req$$.params.email_owner;if(!underscore.contains(configs.admins,$query_req$$.user.email)&&!isSupperAdmin($query_req$$.user.email.toLowerCase()))return $res$$.status(403).send("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n truy c\u1eadp t\u00ednh n\u0103ng n\u00e0y");
|
|
26
|
+
$query_req$$={};$_appsOfUser$jscomp$1_email$$.toLowerCase()!="all"&&($_appsOfUser$jscomp$1_email$$=await Participant.appsOfUser($_appsOfUser$jscomp$1_email$$),$_appsOfUser$jscomp$1_email$$=$_appsOfUser$jscomp$1_email$$.map($p$$=>$p$$.id_app),$query_req$$._id={$in:$_appsOfUser$jscomp$1_email$$});model.find($query_req$$).lean().exec(function($error$$,$apps$$){if($error$$)return $res$$.status(400).send($error$$);$apps$$.forEach(function($item$$){calcTimeExpired($item$$)});$res$$.send($apps$$)})});$contr_router$$.router.route($contr_router$$.route_name+
|
|
27
|
+
"/remove/:id").get(async($app_req$$,$res$$)=>{var $id_app$jscomp$2_p$$=$app_req$$.params.id;let $email$$=$app_req$$.user.email;$app_req$$=await model.findById($id_app$jscomp$2_p$$);if(!$app_req$$)return $res$$.status(400).send("C\u00f4ng ty n\u00e0y kh\u00f4ng t\u1ed3n t\u1ea1i");$app_req$$.participants&&($app_req$$.participants=$app_req$$.participants.filter($p$$=>$p$$.email!==$email$$),$app_req$$.save(()=>{}));if($id_app$jscomp$2_p$$=await Participant.findOne({id_app:$id_app$jscomp$2_p$$,email:$email$$}))await Participant.deleteOne({_id:$id_app$jscomp$2_p$$._id}),
|
|
28
|
+
$id_app$jscomp$2_p$$=`${$id_app$jscomp$2_p$$.name} (${$email$$}) \u0111\u00e3 r\u1eddi kh\u1ecfi c\u00f4ng ty ${$app_req$$.name}`,_Notification.createNotification($email$$,$app_req$$.user_created,$id_app$jscomp$2_p$$,$id_app$jscomp$2_p$$);$res$$.send("ok")});$contr_router$$.router.route($contr_router$$.route_name+"/join/:id/:group").get(async($req$$,$res$$)=>{let $id_app$$=$req$$.params.id,$group_id$$=$req$$.params.group,$email$$=$req$$.user.email,$user$$=$req$$.user,$app$$=await model.findById($id_app$$);
|
|
29
|
+
if(!$app$$)return $res$$.status(400).send("C\u00f4ng ty n\u00e0y kh\u00f4ng t\u1ed3n t\u1ea1i");if(!await Participant.findOne({id_app:$id_app$$,email:$email$$})&&$group_id$$&&global.mongoose.Types.ObjectId.isValid($group_id$$))try{if(!await UserGroup.findOne({_id:$group_id$$,is_customer_group:!0}))return $res$$.status(400).send("Nh\u00f3m kh\u00e1ch h\u00e0ng kh\u00f4ng t\u1ed3n t\u1ea1i");Participant.createParticipant({id_app:$id_app$$,email:$email$$,name:$user$$.name,group_id:$group_id$$,active:!0},
|
|
30
|
+
$cust_e$$=>{if($cust_e$$)return $res$$.status(400).send("can't add user",$user$$.email,"to company",$app$$.name);$cust_e$$={ten_kh:$user$$.name,email:$user$$.email,id_app:$id_app$$,user_created:$user$$.email,user_updated:$user$$.email,kh_yn:!0,of_user:$user$$.email};isMobilePhone($user$$.email,["vi-VN"])&&($cust_e$$.dien_thoai=$user$$.email);try{Customer.asyncCreateCustomer($cust_e$$)}catch($e$$){console.log("Auto create new customer with error:",$e$$.message)}$res$$.send("ok")})}catch($e$$){$res$$.status(400).send($e$$.message)}$res$$.send("ok")})};
|
|
@@ -26,89 +26,92 @@ $d$$.sl_pk_nhap).concat(($obj$$.details||[]).filter($d$$=>$d$$.ma_pk_nhap&&$d$$.
|
|
|
26
26
|
$d$jscomp$9_pk$$.gia_von_nt=$d$jscomp$12_pk$$.gia_von_pk_nhap_nt||0,$d$jscomp$9_pk$$.gia_von=$d$jscomp$9_pk$$.gia_von_nt*($obj$$.ty_gia||1),$d$jscomp$9_pk$$.tien_xuat_nt=$d$jscomp$12_pk$$.tien_nhap_pk_nt||0,$d$jscomp$9_pk$$.tien_xuat=$d$jscomp$9_pk$$.tien_xuat_nt*($obj$$.ty_gia||1),$d$jscomp$9_pk$$.sl_nhap=0,$d$jscomp$9_pk$$.tien_nhap_nt=$d$jscomp$9_pk$$.tien_nhap=0,$d$jscomp$9_pk$$.tien_hang_nt=$d$jscomp$9_pk$$.tien_hang=0,$d$jscomp$9_pk$$.tien_ck=$d$jscomp$9_pk$$.tien_ck_nt=$d$jscomp$9_pk$$.ty_le_ck=
|
|
27
27
|
0,$d$jscomp$9_pk$$.tien_phi=$d$jscomp$9_pk$$.tien_phi_nt=0,$product_details_npp$$.push($d$jscomp$9_pk$$);$d$jscomp$12_pk$$=($obj$$.ds_pk_xuat||[]).filter($d$$=>$d$$.ma_pk_xuat&&$d$$.sl_pk_xuat).concat(($obj$$.details||[]).filter($d$$=>$d$$.ma_pk_xuat&&$d$$.sl_pk_xuat));for(let $d$$ of $d$jscomp$12_pk$$)$d$jscomp$12_pk$$={...$d$$},$d$jscomp$12_pk$$.ma_vt=$d$$.ma_pk_xuat,$d$jscomp$12_pk$$.ma_dvt=$d$$.ma_dvt_pk_xuat,$d$jscomp$12_pk$$.ma_kho=$obj$$.ma_kho_npp||$customer$$.ma_kho_npp,$d$jscomp$12_pk$$.ma_kh=
|
|
28
28
|
$obj$$.ma_kh,$d$jscomp$12_pk$$.nxt=1,$d$jscomp$12_pk$$.tk_co=$obj$$.tk_co,$d$jscomp$12_pk$$.sl_nhap=$d$$.sl_pk_xuat,$d$jscomp$12_pk$$.gia_von_nt=$d$$.gia_von_pk_xuat_nt||0,$d$jscomp$12_pk$$.gia_von=$d$jscomp$12_pk$$.gia_von_nt*($obj$$.ty_gia||1),$d$jscomp$12_pk$$.tien_nhap_nt=$d$$.tien_xuat_pk_nt||0,$d$jscomp$12_pk$$.tien_nhap=$d$jscomp$12_pk$$.tien_nhap_nt*($obj$$.ty_gia||1),$d$jscomp$12_pk$$.sl_xuat=0,$d$jscomp$12_pk$$.tien_xuat_nt=$d$jscomp$12_pk$$.tien_xuat=0,$d$jscomp$12_pk$$.tien_hang_nt=$d$jscomp$12_pk$$.tien_hang=
|
|
29
|
-
0,$d$jscomp$12_pk$$.tien_ck=$d$jscomp$12_pk$$.tien_ck_nt=$d$jscomp$12_pk$$.ty_le_ck=0,$d$jscomp$12_pk$$.tien_phi=$d$jscomp$12_pk$$.tien_phi_nt=0,$product_details_npp$$.push($d$jscomp$12_pk$$);await $product_details$$.filter($d$$=>!$d$$.ma_dvt).asyncJoinModel2($obj$$.id_app,"dmvt",{where:"ma_vt",fields:["ma_dvt","tk_vt","
|
|
30
|
-
|
|
31
|
-
$obj$$.ma_nv_giao_hang||$cust$jscomp$1_d$jscomp$
|
|
32
|
-
if($obj$$.ma_kh&&($cust$jscomp$1_d$jscomp$
|
|
33
|
-
"Ph\u1ee5 c\u1ea5p theo kh\u00e1ch h\u00e0ng",tien:$t_phu_cap_t_sl_xuat$$*($obj$$.phu_xe?.5:1)};$details_phu_cap$$.push($phu_cap_cust$$);$obj$$.phu_xe&&($cust$jscomp$1_d$jscomp$
|
|
34
|
-
$details_phu_cap$$,global.getModel("phucap"),async($detail$$,$callback$$)=>{$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})})},post_tdttno:function($callback$$){account.findOne({tk:$obj$$.tk_no,id_app:$obj$$.id_app},{tk_cn:1},async function($d_chinh_error$$,$tk$$){if($d_chinh_error$$)return $callback$$($d_chinh_error$$);
|
|
35
|
-
($d$$.ma_kh_no||$d$$.ma_kh)!=$ma_kh_no$$);$kh_bo_xung$$.forEach($d$$=>{$d$$.tien_nt=($d$$.tien_ct_nt||0)-($d$$.tien_ck_nt||0)-($d$$.gt_vt_du||0)+($d$$.tien_thue_nt||0);$d$$.tien=$d$$.tien_nt*$obj$$.ty_gia;$d$$.ma_kh=$d$$.ma_kh_no||$d$$.ma_kh});$kh_bo_xung$$=await $kh_bo_xung$$.asyncGroupBy(["ma_kh"],["tien_nt","tien"]);const $bao_hiem$$=[];$obj$$.tien_bh_chi
|
|
36
|
-
$d_chinh_error$$.tien_bh_chi*($obj$$.ty_gia||1),$bao_hiem$$.push($d_chinh_error$$));$d_chinh_error$$=[{...$obj$$}];$d_chinh_error$$.forEach($detail$$=>{$detail$$.ma_kh=$ma_kh_no$$;$detail$$.tien_nt=Math.max(0,$obj$$.details.csum("tien_ct_nt")-$obj$$.details.csum("tien_ck_nt")-$obj$$.details.csum("gt_vt_du")-($obj$$.tien_ck_hd||0)+$obj$$.details.csum("tien_thue_nt")+
|
|
37
|
-
(new PostBook($obj$$,[...$kh_bo_xung$$,...$bao_hiem$$,...$d_chinh_error$$].filter($d$$=>$d$$.tien_nt),Tdttno,function($detail$$,$callback$$){try{$detail$$.so_hd||($detail$$.so_hd=$obj$$.so_ct),$detail$$.ngay_hd||($detail$$.ngay_hd=$obj$$.ngay_ct)}catch($e$$){console.error($e$$,$obj$$)}$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})}else Tdttno.deleteMany({id_ct:$obj$$._id},
|
|
38
|
-
{$options$$.not_post_sokho?$callback$$():(new PostSokho($obj$$,[...$product_details$$],async($detail$$,$callback$$)=>{$detail$$.nxt=$detail$$.nxt||2;$detail$$.tk_no=$obj$$.tk_no;$detail$$.ma_kho=$detail$$.ma_kho||$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){if($e$$)return $callback$$($e$$);$ket_qua_post_sokho$$=$rs$$.rs_sokho;$callback$$(null,$rs$$)})},npp:$callback$$=>{$options$$.not_post_sokho
|
|
39
|
-
async($detail$$,$callback$$)=>{$detail$$.tk_no=$obj$$.tk_no;$detail$$.ma_kho=$detail$$.ma_kho||$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})},tt:$callback$$=>{$options$$.post_sokhott?(new PostBook($obj$$,$product_details$$,Sokhott,async($detail$$,$callback$$)=>{$detail$$.nxt=$detail$$.nxt||2;$detail$$.tk_no=$obj$$.tk_no;$detail$$.ma_kho=$detail$$.ma_kho||$obj$$.ma_kho
|
|
40
|
-
($e$$,$rs$$)=>{$callback$$($e$$,$rs$$)})},post_vatra:function($callback$$){(async()=>{if($obj$$.ngay_hd||$obj$$.vatras&&$obj$$.vatras.length>0){let $details_vatra$$=$obj$$.vatras||[];if($obj$$.ngay_hd){var $d$$=$obj$$.details.map($detail$$=>({...$detail$$,thue_suat:($detail$$.ma_thue?$detail$$.thue_suat:$obj$$.thue_suat)||0,ma_thue:$detail$$.ma_thue||$obj$$.ma_thue,tien_thue_nt:$detail$$.tien_thue_nt||0,tien_thue:$detail$$.tien_thue||
|
|
41
|
-
$r$$.ma_thue).asyncJoinModel2($obj$$.id_app,"vat",{where:"ma_thue",fields:["tk_thue_co"]});$d$$=await $d$$.asyncGroupBy(["ma_thue","thue_suat","ten_vt_vat","tk_thue_co"],"tien_ct_nt tien_ct tien_nt tien tien_ck tien_ck_nt tien_thue tien_thue_nt".split(" "));if($d$$.length==1){let $tien_thue_nt$$=$d$$.map($d$$=>$d$$.tien_thue_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0),$tien_thue$$=$d$$.map($d$$=>$d$$.tien_thue).reduce(($a$$,$b$$)
|
|
42
|
-
{try{$detail$$.tk_du_thue=$obj$$.tk_no,$detail$$.t_tien_nt=($detail$$.tien_ct_nt||0)-($detail$$.tien_ck_nt||0),$detail$$.t_tien=($detail$$.tien_ct||0)-($detail$$.tien_ck||0),$detail$$.t_thue_nt=$detail$$.tien_thue_nt,$detail$$.t_thue=$detail$$.tien_thue,$detail$$.ten_vt=$detail$$.ten_vt_vat||$obj$$.ten_vt||$obj$$.dien_giai}catch($e$$){console.error($e$$,$obj$$)}});$details_vatra$$=[...$details_vatra
|
|
43
|
-
$detail$$.ten_vt=$detail$$.ten_vt||$obj$$.dien_giai;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})}else $callback$$()})()},post_socai:function($callback$$){setImmediate(async()=>{let $details$$=[];$options$$.hoach_toan_ck_vt?($obj$$.details.forEach(function($d$jscomp$
|
|
44
|
-
utils.round($d$jscomp$
|
|
45
|
-
$obj$$.tk_ck||$kho$$.tk_ck||$options$$.tk_ck;$d$jscomp$
|
|
46
|
-
$obj$$.details.forEach(function($d$jscomp$
|
|
47
|
-
($obj$$.details||[]).filter($d$$=>$d$$.gt_vt_du).forEach(function($d$$){const $detail$$={...$d$$};$detail$$.tien_nt=$detail$$.gt_vt_du;$detail$$.tien=utils.round($detail$$.gt_vt_du*$obj$$.ty_gia,0);$detail$$.tk_co=$d$$.
|
|
48
|
-
$d$$.gt_vt_du).forEach(function($d$$){const $detail$$={...$d$$};$detail$$.tien_nt=$detail$$.gt_vt_du;$detail$$.tien=utils.round($detail$$.gt_vt_du*$obj$$.ty_gia,0);$detail$$.tk_co=$obj$$.tk_no;$detail$$.ma_kh_no=$detail$$.ma_kh||$obj$$.ma_kh;$detail$$.ma_kh_co=$obj$$.ma_kh_no||$detail$$.ma_kh||$obj$$.ma_kh;$detail$$.dien_giai=$d$$.dien_giai_vt_du;$detail$$.tk_no=$d$$.tk_tl_vt_du
|
|
49
|
-
$kho$$.tk_ck||$options$$.tk_ck;$o_tt$jscomp$1_tt$$.tk_co=$obj$$.tk_no;$o_tt$jscomp$1_tt$$.tien_nt=$obj$$.tien_ck_hd;$o_tt$jscomp$1_tt$$.tien=$o_tt$jscomp$1_tt$$.tien_nt*($obj$$.ty_gia||1);$o_tt$jscomp$1_tt$$.ma_kh_no=$obj$$.ma_kh;$o_tt$jscomp$1_tt$$.ma_kh_co=$obj$$.ma_kh_no||$obj$$.ma_kh;$o_tt$jscomp$1_tt$$.check_balance=!1;$details$$.push($o_tt$jscomp$1_tt$$)}$obj$$.tien_bh_chi
|
|
50
|
-
$obj$$.tk_no,$o_tt$jscomp$1_tt$$.tien_nt=$obj$$.tien_bh_chi,$o_tt$jscomp$1_tt$$.tien=$o_tt$jscomp$1_tt$$.tien_bh_chi*($obj$$.ty_gia||1),$o_tt$jscomp$1_tt$$.ma_kh_no=$obj$$.ma_kh_bh,$o_tt$jscomp$1_tt$$.ma_kh_co=$obj$$.ma_kh,$o_tt$jscomp$1_tt$$.check_balance=!1,$details$$.push($o_tt$jscomp$1_tt$$));$obj$$.thu_nhap_ctv&&$obj$$.ma_ctv&&(($obj$$.details||[]).filter($r
|
|
51
|
-
$kho$$.tk_no_hoa_hong||$options$$.tk_no_hoa_hong;$r$$.tk_cn_ctv=$r$$.tk_cn_ctv||$obj$$.tk_cn_ctv||$kho$$.tk_cn_ctv||$options$$.tk_cn_ctv||$obj$$.tk_co_hoa_hong||$kho$$.tk_co_hoa_hong||$options$$.tk_co_hoa_hong}),(await ($obj$$.details||[]).filter($r$$=>$r$$.tien_hoa_hong_ctv).asyncGroupBy(["tk_cp_ctv","tk_cn_ctv"],["tien_hoa_hong_ctv"])).forEach($r$$=>
|
|
52
|
-
$tt$$.ma_nt="VND";$tt$$.ty_gia=1;$tt$$.dien_giai="Hoa h\u1ed3ng b\u00e1n h\u00e0ng c\u1ed9ng t\u00e1c vi\u00ean c\u1ea5p 1";$tt$$.tk_no&&$tt$$.tk_co&&$details$$.push($tt$$)}));$obj$$.thu_nhap_ctv2&&$obj$$.ma_ctv2&&(($obj$$.details||[]).filter($r$$=>$r$$.tien_hoa_hong_ctv2).forEach($r$$=>{$r$$.tk_cp_ctv=$r$$.tk_cp_ctv||$obj$$.tk_cp_ctv||$kho$$.tk_cp_ctv
|
|
53
|
-
$options$$.tk_cn_ctv||$obj$$.tk_co_hoa_hong||$kho$$.tk_co_hoa_hong||$options$$.tk_co_hoa_hong}),(await ($obj$$.details||[]).filter($r$$=>$r$$.tien_hoa_hong_ctv2).asyncGroupBy(["tk_cp_ctv","tk_cn_ctv"],["tien_hoa_hong_ctv2"])).forEach($r$$=>{let $tt$$={};$tt$$.tk_no=$r$$.tk_cp_ctv;$tt$$.tk_co=$r$$.tk_cn_ctv;$tt$$.tien=$tt$$.tien_nt=$r$$.tien_hoa_hong_ctv2
|
|
54
|
-
$tt$$.tk_no&&$tt$$.tk_co&&$details$$.push($tt$$)}));$obj$$.tien_hoa_hong&&$obj$$.ma_kh_hoa_hong&&(($obj$$.details||[]).filter($r$$=>$r$$.tien_hoa_hong).forEach($r$$=>{$r$$.tk_no_hoa_hong=$r$$.tk_no_hoa_hong||$obj$$.tk_no_hoa_hong||$kho$$.tk_no_hoa_hong||$options$$.tk_no_hoa_hong;$r$$.tk_co_hoa_hong=$r$$.tk_co_hoa_hong||$obj$$.tk_co_hoa_hong
|
|
55
|
-
["tien_hoa_hong"])).forEach($r$$=>{let $tt$$={};$tt$$.tk_no=$r$$.tk_no_hoa_hong;$tt$$.tk_co=$r$$.tk_co_hoa_hong;$tt$$.tien=$tt$$.tien_nt=$r$$.tien_hoa_hong;$tt$$.tien=$tt$$.tien_nt*($obj$$.ty_gia||1);$tt$$.ma_kh_no=$tt$$.ma_kh_co=$obj$$.ma_kh_hoa_hong;$tt$$.ma_nv=$obj$$.ma_nv;$tt$$.check_balance=!1;$tt$$.ma_nt="VND";$tt$$.ty_gia=1;$tt$$.dien_giai=
|
|
56
|
-
[]).filter($r$$=>$r$$.tien_hoa_hong_gt).forEach($r$$=>{$r$$.tk_no_hoa_hong_gt=$r$$.tk_no_hoa_hong_gt||$obj$$.tk_no_hoa_hong_gt||$kho$$.tk_no_hoa_hong_gt||$options$$.tk_no_hoa_hong_gt||$obj$$.tk_no_hoa_hong||$kho$$.tk_no_hoa_hong||$options$$.tk_no_hoa_hong;$r$$.tk_co_hoa_hong_gt=$r$$.tk_co_hoa_hong_gt||$obj$$.tk_co_hoa_hong_gt||$kho$$.tk_co_hoa_hong_gt
|
|
57
|
-
"tk_co_hoa_hong_gt"],["tien_hoa_hong_gt"])).forEach($r$$=>{let $tt$$={};$tt$$.tk_no=$r$$.tk_no_hoa_hong_gt;$tt$$.tk_co=$r$$.tk_co_hoa_hong_gt;$tt$$.tien_nt=$r$$.tien_hoa_hong_gt;$tt$$.tien=$tt$$.tien_nt*($obj$$.ty_gia||1);$tt$$.ma_kh_no=$tt$$.ma_kh_co=$obj$$.ma_kh_hoa_hong_gt;$tt$$.ma_nv=$obj$$.ma_nv
|
|
58
|
-
(($obj$$.details||[]).filter($r$$=>$r$$.tien_hoa_hong_kho).forEach($r$$=>{$r$$.tk_no_hoa_hong_kho=$r$$.tk_no_hoa_hong_kho||$obj$$.tk_no_hoa_hong_kho||$kho$$.tk_no_hoa_hong_kho||$options$$.tk_no_hoa_hong_kho||$obj$$.tk_no_hoa_hong||$kho$$.tk_no_hoa_hong||$options$$.tk_no_hoa_hong;$r$$.tk_co_hoa_hong_kho
|
|
59
|
-
[]).filter($r$$=>$r$$.tien_hoa_hong_kho).asyncGroupBy(["tk_no_hoa_hong_kho","tk_co_hoa_hong_kho"],["tien_hoa_hong_kho"])).forEach($r$$=>{let $tt$$={};$tt$$.tk_no=$r$$.tk_no_hoa_hong_kho;$tt$$.tk_co=$r$$.tk_co_hoa_hong_kho;$tt$$.tien_nt=$r$$.tien_hoa_hong_kho;$tt$$.tien=$tt$$.tien_nt*($obj$$.ty_gia||
|
|
60
|
-
|
|
61
|
-
$kho$$.tk_co_hoa_hong||$options$$.tk_co_hoa_hong}),(await $obj$$.details.filter($r$$=>$r$$.tien_hoa_hong_ql).asyncGroupBy(["tk_no_hoa_hong_ql","tk_co_hoa_hong_ql"],["tien_hoa_hong_ql"])).forEach($r$$=>{let $tt$$={};$tt$$.tk_no=$r$$.tk_no_hoa_hong_ql;$tt$$.tk_co=$r$$.tk_co_hoa_hong_ql;$tt$$.tien_nt=$r$$.tien_hoa_hong_ql
|
|
62
|
-
$tt$$.ma_nt="VND";$tt$$.ty_gia=1;$tt$$.tk_no&&$tt$$.tk_co&&$details$$.push($tt$$)}));$o_tt$jscomp$1_tt$$={...$obj$$};$o_tt$jscomp$1_tt$$.tk_no=$obj$$.tk_no;$o_tt$jscomp$1_tt$$.tk_co=$obj$$.tk_thue_co;$o_tt$jscomp$1_tt$$.tien_nt=$obj$$.details.csum("tien_thue_nt");$o_tt$jscomp$1_tt$$.tien
|
|
63
|
-
$obj$$.vatras.length>0)for(var $o$jscomp$1_o$$ of $obj$$.vatras)$o$jscomp$1_o$$.tk_no=$obj$$.tk_no,$o$jscomp$1_o$$.tk_co=$o$jscomp$1_o$$.tk_thue_co,$o$jscomp$1_o$$.tien_nt=$o$jscomp$1_o$$.t_thue_nt,$o$jscomp$1_o$$.tien=$o$jscomp$1_o$$.t_thue,$o$jscomp$1_o$$.dien_giai_thue&&($o$jscomp$1_o$$.dien_giai
|
|
64
|
-
$o$jscomp$1_o$$.tk_co=$obj$$.tk_phi_vc,$o$jscomp$1_o$$.tien_nt=$obj$$.tien_phi_vc_nt,$o$jscomp$1_o$$.tien=$o$jscomp$1_o$$.tien_nt*$o$jscomp$1_o$$.ty_gia,$o$jscomp$1_o$$.dien_giai="Ph\u00ed giao h\u00e0ng",$details$$.push($o$jscomp$1_o$$));const $details_giavon$$=[];($ket_qua_post_sokho$$||[]).filter($r
|
|
65
|
-
$detail$$.tk_co=$detail$$.tk_vt;$detail$$.tien_nt=$detail$$.tien_xuat_nt;$detail$$.tien=$detail$$.tien_xuat;$details_giavon$$.push($detail$$)});async.series({xdtk:$callback$$=>{$details_giavon$$.joinModel2($obj$$.id_app,dmvt,{where:"ma_vt",fields:["tk_vt","gia_mua","tk_gv"]},()=>{$details_giavon$$.forEach($s$$=>
|
|
66
|
-
{$d$$.ma_kh_no=$d$$.ma_kh||$obj$$.ma_kh;$d$$.ma_kh_co=$d$$.ma_kh||$obj$$.ma_kh});$details$$=$details$$.concat($details_giavon$$);(new PostSocai($obj$$,$details$$,void 0,void 0,$_options$$)).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})})})},thanhtoanhoahongnv:$callback$$=>{if($obj$$.da_chuyen_hoa_hong
|
|
67
|
-
await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),username:$obj$$.user_nv,wallet_type:8});$wallet_nhan_vien$$||=await global.getModel("asskey").createWallet($appInfo$$._id.toString(),$obj$$.user_nv,"T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng",8);let $amount
|
|
68
|
-
$obj$$.be_introduced,$wallet_nhan_vien$$.address,$amount$$,$denom$$,$memo$$,"","2");$obj$$.da_chuyen_hoa_hong=!0;await model.updateOne({_id:$obj$$._id},{da_chuyen_hoa_hong:!0})}}catch($e$$){console.error("Kh\u00f4ng th\u1ec3 thanh to\u00e1n ti\u1ec1n hoa h\u1ed3ng",$e$$)}$callback$$()})},
|
|
69
|
-
$appInfo$$.tang_gioi_thieu_denom){let $wallet_gt$$=await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),username:$obj$$.user_gt,wallet_type:8});$wallet_gt$$||=await global.getModel("asskey").createWallet($appInfo$$._id.toString(),$obj$$.user_gt,
|
|
70
|
-
await spend($appInfo$$,$obj$$.be_introduced,$wallet_gt$$.address,$amount$$,$denom$$,$memo$$,$obj$$.introduce_code,"2");$obj$$.da_chuyen_hoa_hong_gt=!0;await model.updateOne({_id:$obj$$._id},{da_chuyen_hoa_hong_gt:!0})}}catch($e$$){console.error("Kh\u00f4ng th\u1ec3 thanh to\u00e1n ti\u1ec1n hoa h\u1ed3ng"
|
|
71
|
-
{try{if($appInfo$$.wallet_address&&$appInfo$$.wallet_token&&$appInfo$$.tang_gioi_thieu_denom){if($obj$$.user_ctv&&$obj$$.thu_nhap_ctv){let $wallet_ctv$$=await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),username:$obj$$.user_ctv,wallet_type:8});$wallet_ctv$$||=await global.getModel("asskey").createWallet($appInfo$$._id.toString()
|
|
72
|
-
|
|
73
|
-
$obj$$.user_ctv2,"T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng",8);let $amount$$=$obj$$.thu_nhap_ctv2,$denom$$=$appInfo$$.tang_gioi_thieu_denom,$memo$$=`Hoa h\u1ed3ng cho \u0111\u01a1n h\u00e0ng s\u1ed1 ${$obj$$.so_ct}: ${numeral($amount$$).format()} ${$denom$$.toUpperCase()}`;await spend($appInfo$$,$obj$$.be_introduced,$wallet_ctv2$$.address,$amount$$,$denom$$,$memo
|
|
74
|
-
$e$$)}$callback$$()})},thanhtoanhoahongql:$callback$$=>{if($obj$$.da_chuyen_hoa_hong_ql||!$obj$$.tien_hoa_hong_ql||!$obj$$.user_ql||!$obj$$.chuyen_ngay_ql)return $callback$$();setImmediate(async()=>{try{if($appInfo$$.wallet_address&&$appInfo$$.wallet_token&&$appInfo$$.tang_gioi_thieu_denom){let $wallet_ql$$=
|
|
75
|
-
$obj$$.user_ql,"T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng",8);let $amount$$=$obj$$.tien_hoa_hong_ql,$denom$$=$appInfo$$.tang_gioi_thieu_denom,$memo$$=`Hoa h\u1ed3ng cho \u0111\u01a1n h\u00e0ng s\u1ed1 ${$obj$$.so_ct}: ${numeral($amount$$).format()} ${$denom$$.toUpperCase()}`;await spend($appInfo
|
|
76
|
-
$e$$)}$callback$$()})},thanhtoanhoahongchukho:$callback$$=>{if($obj$$.da_chuyen_hoa_hong_kho||!$obj$$.tien_hoa_hong_kho||!$obj$$.user_kho||!$obj$$.chuyen_ngay_kho)return $callback$$();setImmediate(async()=>{try{if($appInfo$$.wallet_address
|
|
77
|
-
$obj$$.user_kho,"T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng",8);let $amount$$=$obj$$.tien_hoa_hong_kho,$denom$$=$appInfo$$.tang_gioi_thieu_denom,$memo$$=`Hoa h\u1ed3ng cho \u0111\u01a1n h\u00e0ng s\u1ed1 ${$obj$$.so_ct}: ${numeral($amount$$).format()} ${$denom$$.toUpperCase()}`;
|
|
78
|
-
$e$$)}$callback$$()})}},function($e$$,$rs$$){$fn$$($e$$,$rs$$)})};const $valid$$=function($i_user$$,$obj$$,$next$$){$obj$$.thue_suat=$obj$$.thue_suat||0;$obj$$.tien_phi_vc_nt=$obj$$.tien_phi_vc_nt||
|
|
79
|
-
0;$
|
|
80
|
-
$obj$$.ty_gia,0);$detail$$.tien_xuat=$detail$$.tien_xuat_nt}$obj$$.id_contract?salecontract.findOne({_id:$obj$$.id_contract,id_app:$obj$$.id_app}).lean().then($c$$=>{$c$$&&($obj$$.ma_hd
|
|
81
|
-
dmvt,{where:"ma_vt",setFields:($item$$,$ref$$)=>{$item$$.combo=$ref$$.combo||[];$item$$.ma_thue||($item$$.ma_thue=$ref$$.ma_thue);$item$$.ten_vt=$ref$$.ten_vt;$item$$.status_vt
|
|
82
|
-
let $ngay_nay_thang_truoc$$=moment($obj$$.ngay_ct).subtract(1,"months").toDate(),$details$$=[];$obj$$.details.forEach($d$$=>{$d$$.combo&&$d$$.combo.length>0?$details$$=
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
$b$$,0)});$obj$$.result_export_einvoice=null;$next$$(null,$obj$$)})};$contr$$.updating=async function($user$$,$data$$,$obj$$,$next$$){$data$$.details||($data$$.details
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
{$detail$$.combo=$detail$$.combo.map($item$$=>{$item$$.sl_xuat_1_combo==void 0&&($item$$.sl_xuat_1_combo=$item$$.sl_xuat||0);$item$$.sl_xuat=$item$$.sl_xuat_1_combo
|
|
89
|
-
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)});Tdttno_tt.findOne({id_hd:$obj$$._id},
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
""
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
$
|
|
97
|
-
$
|
|
98
|
-
|
|
99
|
-
$
|
|
100
|
-
$
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
$
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
[{where:{id_cs_ck:"_id"},
|
|
107
|
-
$
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if(!$
|
|
111
|
-
($
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
($
|
|
29
|
+
0,$d$jscomp$12_pk$$.tien_ck=$d$jscomp$12_pk$$.tien_ck_nt=$d$jscomp$12_pk$$.ty_le_ck=0,$d$jscomp$12_pk$$.tien_phi=$d$jscomp$12_pk$$.tien_phi_nt=0,$product_details_npp$$.push($d$jscomp$12_pk$$);await $product_details$$.filter($d$$=>!$d$$.ma_dvt).asyncJoinModel2($obj$$.id_app,"dmvt",{where:"ma_vt",fields:["ma_dvt","tk_vt","tk_tl"]});await $product_details$$.filter($d$$=>!$d$$.tk_vt).asyncJoinModel2($obj$$.id_app,"dmvt",{where:"ma_vt",fields:["tk_vt","tk_tl"]});await ($obj$$.details||[]).filter($d$$=>
|
|
30
|
+
!$d$$.tk_gv).asyncJoinModel2($obj$$.id_app,"dmvt",{where:"ma_vt",fields:["tk_gv"]});await ($obj$$.details||[]).filter($d$$=>$d$$.ma_vt_du).asyncJoinModel2($obj$$.id_app,"dmvt",{where:{ma_vt_du:"ma_vt"},fields:[{tk_gv_vt_du:"tk_gv"}]});let $ket_qua_post_sokho$$;async.series({phu_cap:$callback$$=>{setImmediate(async()=>{let $details_phu_cap$$=_.cloneDeep(($obj$$.details||[]).filter($d$$=>$d$$.luong_tho&&$d$$.tg_tk));$details_phu_cap$$.length==0&&($details_phu_cap$$=_.cloneDeep(($obj$$.details||[]).filter($d$$=>
|
|
31
|
+
$d$$.luong_tho)));for(var $cust$jscomp$1_d$jscomp$22_phu_cap_cust$$ of $details_phu_cap$$)$cust$jscomp$1_d$jscomp$22_phu_cap_cust$$.ma_nv=$obj$$.ma_nv_giao_hang||$cust$jscomp$1_d$jscomp$22_phu_cap_cust$$.ma_nv,$cust$jscomp$1_d$jscomp$22_phu_cap_cust$$.thang=(new Date($obj$$.ngay_ct)).getMonth()+1,$cust$jscomp$1_d$jscomp$22_phu_cap_cust$$.nam=(new Date($obj$$.ngay_ct)).getFullYear(),$cust$jscomp$1_d$jscomp$22_phu_cap_cust$$.ten_phu_cap=$cust$jscomp$1_d$jscomp$22_phu_cap_cust$$.ten_phu_cap||$cust$jscomp$1_d$jscomp$22_phu_cap_cust$$.ten_vt,
|
|
32
|
+
$cust$jscomp$1_d$jscomp$22_phu_cap_cust$$.tien=$cust$jscomp$1_d$jscomp$22_phu_cap_cust$$.luong_tho;if($obj$$.ma_kh&&($cust$jscomp$1_d$jscomp$22_phu_cap_cust$$=await global.getModel("customer").findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh,phu_cap:{$gte:0}}).lean())){var $t_phu_cap_t_sl_xuat$$=($obj$$.details||[]).map($r$$=>$r$$.sl_xuat||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$t_phu_cap_t_sl_xuat$$*=$cust$jscomp$1_d$jscomp$22_phu_cap_cust$$.phu_cap;const $phu_cap_cust$$={ma_nv:$obj$$.ma_nv_giao_hang,
|
|
33
|
+
thang:(new Date($obj$$.ngay_ct)).getMonth()+1,nam:(new Date($obj$$.ngay_ct)).getFullYear(),ten_phu_cap:$cust$jscomp$1_d$jscomp$22_phu_cap_cust$$.ten_phu_cap||"Ph\u1ee5 c\u1ea5p theo kh\u00e1ch h\u00e0ng",tien:$t_phu_cap_t_sl_xuat$$*($obj$$.phu_xe?.5:1)};$details_phu_cap$$.push($phu_cap_cust$$);$obj$$.phu_xe&&($cust$jscomp$1_d$jscomp$22_phu_cap_cust$$={ma_nv:$obj$$.phu_xe,thang:(new Date($obj$$.ngay_ct)).getMonth()+1,nam:(new Date($obj$$.ngay_ct)).getFullYear(),ten_phu_cap:$cust$jscomp$1_d$jscomp$22_phu_cap_cust$$.ten_phu_cap||
|
|
34
|
+
"Ph\u1ee5 c\u1ea5p theo kh\u00e1ch h\u00e0ng",tien:$t_phu_cap_t_sl_xuat$$/2},$details_phu_cap$$.push($cust$jscomp$1_d$jscomp$22_phu_cap_cust$$))}(new PostBook($obj$$,$details_phu_cap$$,global.getModel("phucap"),async($detail$$,$callback$$)=>{$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})})},post_tdttno:function($callback$$){account.findOne({tk:$obj$$.tk_no,id_app:$obj$$.id_app},{tk_cn:1},async function($d_chinh_error$$,$tk$$){if($d_chinh_error$$)return $callback$$($d_chinh_error$$);
|
|
35
|
+
if($tk$$&&$tk$$.tk_cn===!0){const $ma_kh_no$$=$obj$$.ma_kh_no||$obj$$.ma_kh;let $kh_bo_xung$$=($obj$$.details||[]).filter($d$$=>($d$$.ma_kh_no||$d$$.ma_kh)&&($d$$.ma_kh_no||$d$$.ma_kh)!=$ma_kh_no$$);$kh_bo_xung$$.forEach($d$$=>{$d$$.tien_nt=($d$$.tien_ct_nt||0)-($d$$.tien_ck_nt||0)-($d$$.gt_vt_du||0)+($d$$.tien_thue_nt||0);$d$$.tien=$d$$.tien_nt*$obj$$.ty_gia;$d$$.ma_kh=$d$$.ma_kh_no||$d$$.ma_kh});$kh_bo_xung$$=await $kh_bo_xung$$.asyncGroupBy(["ma_kh"],["tien_nt","tien"]);const $bao_hiem$$=[];$obj$$.tien_bh_chi&&
|
|
36
|
+
$obj$$.ma_kh_bh&&($d_chinh_error$$={...$obj$$},$d_chinh_error$$.ma_kh=$obj$$.ma_kh_bh,$d_chinh_error$$.tien_nt=$obj$$.tien_bh_chi,$d_chinh_error$$.tien=$d_chinh_error$$.tien_bh_chi*($obj$$.ty_gia||1),$bao_hiem$$.push($d_chinh_error$$));$d_chinh_error$$=[{...$obj$$}];$d_chinh_error$$.forEach($detail$$=>{$detail$$.ma_kh=$ma_kh_no$$;$detail$$.tien_nt=Math.max(0,$obj$$.details.csum("tien_ct_nt")-$obj$$.details.csum("tien_ck_nt")-$obj$$.details.csum("gt_vt_du")-($obj$$.tien_ck_hd||0)+$obj$$.details.csum("tien_thue_nt")+
|
|
37
|
+
($obj$$.tien_phi_vc_nt||0)-$kh_bo_xung$$.csum("tien_nt")-$bao_hiem$$.csum("tien_nt"));$detail$$.tien=$detail$$.tien_nt*$obj$$.ty_gia});(new PostBook($obj$$,[...$kh_bo_xung$$,...$bao_hiem$$,...$d_chinh_error$$].filter($d$$=>$d$$.tien_nt),Tdttno,function($detail$$,$callback$$){try{$detail$$.so_hd||($detail$$.so_hd=$obj$$.so_ct),$detail$$.ngay_hd||($detail$$.ngay_hd=$obj$$.ngay_ct)}catch($e$$){console.error($e$$,$obj$$)}$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})}else Tdttno.deleteMany({id_ct:$obj$$._id},
|
|
38
|
+
function($error$$){$callback$$($error$$)})})},post_sokho:$callback$$=>{async.series({kt:$callback$$=>{$options$$.not_post_sokho?$callback$$():(new PostSokho($obj$$,[...$product_details$$],async($detail$$,$callback$$)=>{$detail$$.nxt=$detail$$.nxt||2;$detail$$.tk_no=$obj$$.tk_no;$detail$$.ma_kho=$detail$$.ma_kho||$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){if($e$$)return $callback$$($e$$);$ket_qua_post_sokho$$=$rs$$.rs_sokho;$callback$$(null,$rs$$)})},npp:$callback$$=>{$options$$.not_post_sokho?
|
|
39
|
+
$callback$$():(new PostBook($obj$$,$product_details_npp$$,global.getModel("sokhonpp"),async($detail$$,$callback$$)=>{$detail$$.tk_no=$obj$$.tk_no;$detail$$.ma_kho=$detail$$.ma_kho||$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})},tt:$callback$$=>{$options$$.post_sokhott?(new PostBook($obj$$,$product_details$$,Sokhott,async($detail$$,$callback$$)=>{$detail$$.nxt=$detail$$.nxt||2;$detail$$.tk_no=$obj$$.tk_no;$detail$$.ma_kho=$detail$$.ma_kho||$obj$$.ma_kho;
|
|
40
|
+
$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)}):$callback$$()}},($e$$,$rs$$)=>{$callback$$($e$$,$rs$$)})},post_vatra:function($callback$$){(async()=>{if($obj$$.ngay_hd||$obj$$.vatras&&$obj$$.vatras.length>0){let $details_vatra$$=$obj$$.vatras||[];if($obj$$.ngay_hd){var $d$$=$obj$$.details.map($detail$$=>({...$detail$$,thue_suat:($detail$$.ma_thue?$detail$$.thue_suat:$obj$$.thue_suat)||0,ma_thue:$detail$$.ma_thue||$obj$$.ma_thue,tien_thue_nt:$detail$$.tien_thue_nt||0,tien_thue:$detail$$.tien_thue||
|
|
41
|
+
0})).filter($d$$=>$d$$.ma_thue);await $d$$.filter($r$$=>!$r$$.tk_thue_co&&$r$$.ma_thue).asyncJoinModel2($obj$$.id_app,"vat",{where:"ma_thue",fields:["tk_thue_co"]});$d$$=await $d$$.asyncGroupBy(["ma_thue","thue_suat","ten_vt_vat","tk_thue_co"],"tien_ct_nt tien_ct tien_nt tien tien_ck tien_ck_nt tien_thue tien_thue_nt".split(" "));if($d$$.length==1){let $tien_thue_nt$$=$d$$.map($d$$=>$d$$.tien_thue_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0),$tien_thue$$=$d$$.map($d$$=>$d$$.tien_thue).reduce(($a$$,$b$$)=>
|
|
42
|
+
$a$$+$b$$,0);$d$$[0].tien_thue_nt=$tien_thue_nt$$;$d$$[0].tien_thue=$tien_thue$$}$d$$.forEach($detail$$=>{try{$detail$$.tk_du_thue=$obj$$.tk_no,$detail$$.t_tien_nt=($detail$$.tien_ct_nt||0)-($detail$$.tien_ck_nt||0),$detail$$.t_tien=($detail$$.tien_ct||0)-($detail$$.tien_ck||0),$detail$$.t_thue_nt=$detail$$.tien_thue_nt,$detail$$.t_thue=$detail$$.tien_thue,$detail$$.ten_vt=$detail$$.ten_vt_vat||$obj$$.ten_vt||$obj$$.dien_giai}catch($e$$){console.error($e$$,$obj$$)}});$details_vatra$$=[...$details_vatra$$,
|
|
43
|
+
$d$$]}(new PostBook($obj$$,$details_vatra$$,Vatra,($detail$$,$callback$$)=>{$detail$$={...$detail$$};$detail$$.ten_vt=$detail$$.ten_vt||$obj$$.dien_giai;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})}else $callback$$()})()},post_socai:function($callback$$){setImmediate(async()=>{let $details$$=[];$options$$.hoach_toan_ck_vt?($obj$$.details.forEach(function($d$jscomp$31_detail$$){$d$jscomp$31_detail$$={...$d$jscomp$31_detail$$};$d$jscomp$31_detail$$.tien_nt=$d$jscomp$31_detail$$.tien_ct_nt;
|
|
44
|
+
$d$jscomp$31_detail$$.tien=$d$jscomp$31_detail$$.tien_ct?$d$jscomp$31_detail$$.tien_ct:utils.round($d$jscomp$31_detail$$.tien_ct_nt*$obj$$.ty_gia,0);$d$jscomp$31_detail$$.tk_co=$d$jscomp$31_detail$$.tk_dt||$kho$$.tk_dt||$options$$.tk_dt;$d$jscomp$31_detail$$.ma_kh||($d$jscomp$31_detail$$.ma_kh=$obj$$.ma_kh);$d$jscomp$31_detail$$.tk_no=$obj$$.tk_no;$details$$.push($d$jscomp$31_detail$$)}),($obj$$.details||[]).filter($d$$=>$d$$.tien_ck_nt).forEach(function($d$jscomp$33_detail$$){$d$jscomp$33_detail$$=
|
|
45
|
+
{...$d$jscomp$33_detail$$};$d$jscomp$33_detail$$.tk_no=$d$jscomp$33_detail$$.tk_ck||$obj$$.tk_ck||$kho$$.tk_ck||$options$$.tk_ck;$d$jscomp$33_detail$$.ma_kh||($d$jscomp$33_detail$$.ma_kh=$obj$$.ma_kh);$d$jscomp$33_detail$$.tk_co=$obj$$.tk_no;$d$jscomp$33_detail$$.tien_nt=$d$jscomp$33_detail$$.tien_ck_nt;$d$jscomp$33_detail$$.tien=$d$jscomp$33_detail$$.tien_ck;$d$jscomp$33_detail$$.ma_kh_no=$d$jscomp$33_detail$$.ma_kh||$obj$$.ma_kh;$d$jscomp$33_detail$$.ma_kh_co=$obj$$.ma_kh_no||$d$jscomp$33_detail$$.ma_kh||
|
|
46
|
+
$obj$$.ma_kh;$d$jscomp$33_detail$$.check_balance=!1;$details$$.push($d$jscomp$33_detail$$)})):$obj$$.details.forEach(function($d$jscomp$34_detail$$){$d$jscomp$34_detail$$={...$d$jscomp$34_detail$$};$d$jscomp$34_detail$$.tien_nt=$d$jscomp$34_detail$$.tien_ct_nt-($d$jscomp$34_detail$$.tien_ck_nt||0);$d$jscomp$34_detail$$.tien=utils.round($d$jscomp$34_detail$$.tien_nt*$obj$$.ty_gia,0);$d$jscomp$34_detail$$.tk_co=$d$jscomp$34_detail$$.tk_dt||$kho$$.tk_dt||$options$$.tk_dt;$d$jscomp$34_detail$$.ma_kh||
|
|
47
|
+
($d$jscomp$34_detail$$.ma_kh=$obj$$.ma_kh);$d$jscomp$34_detail$$.tk_no=$obj$$.tk_no;$details$$.push($d$jscomp$34_detail$$)});($obj$$.details||[]).filter($d$$=>$d$$.gt_vt_du).forEach(function($d$$){const $detail$$={...$d$$};$detail$$.tien_nt=$detail$$.gt_vt_du;$detail$$.tien=utils.round($detail$$.gt_vt_du*$obj$$.ty_gia,0);$detail$$.tk_co=$d$$.tk_gv_vt_du||$kho$$.tk_gv||$options$$.tk_gv;$detail$$.ma_kh||($detail$$.ma_kh=$obj$$.ma_kh);$detail$$.dien_giai=$d$$.dien_giai_vt_du;$detail$$.tk_no=$d$$.tk_vt||
|
|
48
|
+
$options$$.tk_vt;$detail$$.ma_kh_no=$detail$$.ma_kh||$obj$$.ma_kh;$details$$.push($detail$$)});($obj$$.details||[]).filter($d$$=>$d$$.gt_vt_du).forEach(function($d$$){const $detail$$={...$d$$};$detail$$.tien_nt=$detail$$.gt_vt_du;$detail$$.tien=utils.round($detail$$.gt_vt_du*$obj$$.ty_gia,0);$detail$$.tk_co=$obj$$.tk_no;$detail$$.ma_kh_no=$detail$$.ma_kh||$obj$$.ma_kh;$detail$$.ma_kh_co=$obj$$.ma_kh_no||$detail$$.ma_kh||$obj$$.ma_kh;$detail$$.dien_giai=$d$$.dien_giai_vt_du;$detail$$.tk_no=$d$$.tk_tl_vt_du||
|
|
49
|
+
$d$$.tk_tl;$details$$.push($detail$$)});if($obj$$.tien_ck_hd){var $o_tt$jscomp$1_tt$$={};$o_tt$jscomp$1_tt$$.tk_no=$obj$$.tk_ck||$kho$$.tk_ck||$options$$.tk_ck;$o_tt$jscomp$1_tt$$.tk_co=$obj$$.tk_no;$o_tt$jscomp$1_tt$$.tien_nt=$obj$$.tien_ck_hd;$o_tt$jscomp$1_tt$$.tien=$o_tt$jscomp$1_tt$$.tien_nt*($obj$$.ty_gia||1);$o_tt$jscomp$1_tt$$.ma_kh_no=$obj$$.ma_kh;$o_tt$jscomp$1_tt$$.ma_kh_co=$obj$$.ma_kh_no||$obj$$.ma_kh;$o_tt$jscomp$1_tt$$.check_balance=!1;$details$$.push($o_tt$jscomp$1_tt$$)}$obj$$.tien_bh_chi&&
|
|
50
|
+
$obj$$.ma_kh_bh&&$obj$$.ma_kh!=$obj$$.ma_kh_bh&&($o_tt$jscomp$1_tt$$={},$o_tt$jscomp$1_tt$$.tk_no=$obj$$.tk_no,$o_tt$jscomp$1_tt$$.tk_co=$obj$$.tk_no,$o_tt$jscomp$1_tt$$.tien_nt=$obj$$.tien_bh_chi,$o_tt$jscomp$1_tt$$.tien=$o_tt$jscomp$1_tt$$.tien_bh_chi*($obj$$.ty_gia||1),$o_tt$jscomp$1_tt$$.ma_kh_no=$obj$$.ma_kh_bh,$o_tt$jscomp$1_tt$$.ma_kh_co=$obj$$.ma_kh,$o_tt$jscomp$1_tt$$.check_balance=!1,$details$$.push($o_tt$jscomp$1_tt$$));$obj$$.thu_nhap_ctv&&$obj$$.ma_ctv&&(($obj$$.details||[]).filter($r$$=>
|
|
51
|
+
$r$$.tien_hoa_hong_ctv).forEach($r$$=>{$r$$.tk_cp_ctv=$r$$.tk_cp_ctv||$obj$$.tk_cp_ctv||$kho$$.tk_cp_ctv||$options$$.tk_cp_ctv||$obj$$.tk_no_hoa_hong||$kho$$.tk_no_hoa_hong||$options$$.tk_no_hoa_hong;$r$$.tk_cn_ctv=$r$$.tk_cn_ctv||$obj$$.tk_cn_ctv||$kho$$.tk_cn_ctv||$options$$.tk_cn_ctv||$obj$$.tk_co_hoa_hong||$kho$$.tk_co_hoa_hong||$options$$.tk_co_hoa_hong}),(await ($obj$$.details||[]).filter($r$$=>$r$$.tien_hoa_hong_ctv).asyncGroupBy(["tk_cp_ctv","tk_cn_ctv"],["tien_hoa_hong_ctv"])).forEach($r$$=>
|
|
52
|
+
{let $tt$$={};$tt$$.tk_no=$r$$.tk_cp_ctv;$tt$$.tk_co=$r$$.tk_cn_ctv;$tt$$.tien=$tt$$.tien_nt=$r$$.tien_hoa_hong_ctv;$tt$$.ma_kh_no=$tt$$.ma_kh_co=$obj$$.ma_ctv;$tt$$.ma_nt="VND";$tt$$.ty_gia=1;$tt$$.dien_giai="Hoa h\u1ed3ng b\u00e1n h\u00e0ng c\u1ed9ng t\u00e1c vi\u00ean c\u1ea5p 1";$tt$$.tk_no&&$tt$$.tk_co&&$details$$.push($tt$$)}));$obj$$.thu_nhap_ctv2&&$obj$$.ma_ctv2&&(($obj$$.details||[]).filter($r$$=>$r$$.tien_hoa_hong_ctv2).forEach($r$$=>{$r$$.tk_cp_ctv=$r$$.tk_cp_ctv||$obj$$.tk_cp_ctv||$kho$$.tk_cp_ctv||
|
|
53
|
+
$options$$.tk_cp_ctv||$obj$$.tk_no_hoa_hong||$kho$$.tk_no_hoa_hong||$options$$.tk_no_hoa_hong;$r$$.tk_cn_ctv=$r$$.tk_cn_ctv||$obj$$.tk_cn_ctv||$kho$$.tk_cn_ctv||$options$$.tk_cn_ctv||$obj$$.tk_co_hoa_hong||$kho$$.tk_co_hoa_hong||$options$$.tk_co_hoa_hong}),(await ($obj$$.details||[]).filter($r$$=>$r$$.tien_hoa_hong_ctv2).asyncGroupBy(["tk_cp_ctv","tk_cn_ctv"],["tien_hoa_hong_ctv2"])).forEach($r$$=>{let $tt$$={};$tt$$.tk_no=$r$$.tk_cp_ctv;$tt$$.tk_co=$r$$.tk_cn_ctv;$tt$$.tien=$tt$$.tien_nt=$r$$.tien_hoa_hong_ctv2;
|
|
54
|
+
$tt$$.ma_kh_no=$tt$$.ma_kh_co=$obj$$.ma_ctv2;$tt$$.ma_nt="VND";$tt$$.ty_gia=1;$tt$$.dien_giai="Hoa h\u1ed3ng b\u00e1n h\u00e0ng c\u00f4ng t\u00e1c vi\u00ean c\u1ea5p 2";$tt$$.tk_no&&$tt$$.tk_co&&$details$$.push($tt$$)}));$obj$$.tien_hoa_hong&&$obj$$.ma_kh_hoa_hong&&(($obj$$.details||[]).filter($r$$=>$r$$.tien_hoa_hong).forEach($r$$=>{$r$$.tk_no_hoa_hong=$r$$.tk_no_hoa_hong||$obj$$.tk_no_hoa_hong||$kho$$.tk_no_hoa_hong||$options$$.tk_no_hoa_hong;$r$$.tk_co_hoa_hong=$r$$.tk_co_hoa_hong||$obj$$.tk_co_hoa_hong||
|
|
55
|
+
$kho$$.tk_co_hoa_hong||$options$$.tk_co_hoa_hong}),(await ($obj$$.details||[]).filter($r$$=>$r$$.tien_hoa_hong).asyncGroupBy(["tk_no_hoa_hong","tk_co_hoa_hong"],["tien_hoa_hong"])).forEach($r$$=>{let $tt$$={};$tt$$.tk_no=$r$$.tk_no_hoa_hong;$tt$$.tk_co=$r$$.tk_co_hoa_hong;$tt$$.tien=$tt$$.tien_nt=$r$$.tien_hoa_hong;$tt$$.tien=$tt$$.tien_nt*($obj$$.ty_gia||1);$tt$$.ma_kh_no=$tt$$.ma_kh_co=$obj$$.ma_kh_hoa_hong;$tt$$.ma_nv=$obj$$.ma_nv;$tt$$.check_balance=!1;$tt$$.ma_nt="VND";$tt$$.ty_gia=1;$tt$$.dien_giai=
|
|
56
|
+
"Hoa h\u1ed3ng b\u00e1n h\u00e0ng";$tt$$.tk_no&&$tt$$.tk_co&&$details$$.push($tt$$)}));$obj$$.tien_hoa_hong_gt&&$obj$$.ma_kh_hoa_hong_gt&&(($obj$$.details||[]).filter($r$$=>$r$$.tien_hoa_hong_gt).forEach($r$$=>{$r$$.tk_no_hoa_hong_gt=$r$$.tk_no_hoa_hong_gt||$obj$$.tk_no_hoa_hong_gt||$kho$$.tk_no_hoa_hong_gt||$options$$.tk_no_hoa_hong_gt||$obj$$.tk_no_hoa_hong||$kho$$.tk_no_hoa_hong||$options$$.tk_no_hoa_hong;$r$$.tk_co_hoa_hong_gt=$r$$.tk_co_hoa_hong_gt||$obj$$.tk_co_hoa_hong_gt||$kho$$.tk_co_hoa_hong_gt||
|
|
57
|
+
$options$$.tk_co_hoa_hong_gt||$obj$$.tk_co_hoa_hong||$kho$$.tk_co_hoa_hong||$options$$.tk_co_hoa_hong}),(await ($obj$$.details||[]).filter($r$$=>$r$$.tien_hoa_hong_gt).asyncGroupBy(["tk_no_hoa_hong_gt","tk_co_hoa_hong_gt"],["tien_hoa_hong_gt"])).forEach($r$$=>{let $tt$$={};$tt$$.tk_no=$r$$.tk_no_hoa_hong_gt;$tt$$.tk_co=$r$$.tk_co_hoa_hong_gt;$tt$$.tien_nt=$r$$.tien_hoa_hong_gt;$tt$$.tien=$tt$$.tien_nt*($obj$$.ty_gia||1);$tt$$.ma_kh_no=$tt$$.ma_kh_co=$obj$$.ma_kh_hoa_hong_gt;$tt$$.ma_nv=$obj$$.ma_nv;
|
|
58
|
+
$tt$$.check_balance=!1;$tt$$.dien_giai="Hoa h\u1ed3ng gi\u1edbi thi\u1ec7u";$tt$$.ma_nt="VND";$tt$$.ty_gia=1;$tt$$.tk_no&&$tt$$.tk_co&&$details$$.push($tt$$)}));$obj$$.tien_hoa_hong_kho&&$obj$$.ma_kh_hoa_hong_kho&&(($obj$$.details||[]).filter($r$$=>$r$$.tien_hoa_hong_kho).forEach($r$$=>{$r$$.tk_no_hoa_hong_kho=$r$$.tk_no_hoa_hong_kho||$obj$$.tk_no_hoa_hong_kho||$kho$$.tk_no_hoa_hong_kho||$options$$.tk_no_hoa_hong_kho||$obj$$.tk_no_hoa_hong||$kho$$.tk_no_hoa_hong||$options$$.tk_no_hoa_hong;$r$$.tk_co_hoa_hong_kho=
|
|
59
|
+
$r$$.tk_co_hoa_hong_kho||$obj$$.tk_co_hoa_hong_kho||$kho$$.tk_co_hoa_hong_kho||$options$$.tk_co_hoa_hong_kho||$obj$$.tk_co_hoa_hong||$kho$$.tk_co_hoa_hong||$options$$.tk_co_hoa_hong}),(await ($obj$$.details||[]).filter($r$$=>$r$$.tien_hoa_hong_kho).asyncGroupBy(["tk_no_hoa_hong_kho","tk_co_hoa_hong_kho"],["tien_hoa_hong_kho"])).forEach($r$$=>{let $tt$$={};$tt$$.tk_no=$r$$.tk_no_hoa_hong_kho;$tt$$.tk_co=$r$$.tk_co_hoa_hong_kho;$tt$$.tien_nt=$r$$.tien_hoa_hong_kho;$tt$$.tien=$tt$$.tien_nt*($obj$$.ty_gia||
|
|
60
|
+
1);$tt$$.ma_kh_no=$tt$$.ma_kh_co=$obj$$.ma_kh_hoa_hong_kho;$tt$$.ma_nv=$obj$$.ma_nv;$tt$$.check_balance=!1;$tt$$.dien_giai="Hoa h\u1ed3ng cho ch\u1ee7 kho";$tt$$.ma_nt="VND";$tt$$.ty_gia=1;$tt$$.tk_no&&$tt$$.tk_co&&$details$$.push($tt$$)}));$obj$$.tien_hoa_hong_ql&&$obj$$.ma_kh_hoa_hong_ql&&($obj$$.details.filter($r$$=>$r$$.tien_hoa_hong_ql).forEach($r$$=>{$r$$.tk_no_hoa_hong_ql=$r$$.tk_no_hoa_hong_ql||$obj$$.tk_no_hoa_hong_ql||$kho$$.tk_no_hoa_hong_ql||$options$$.tk_no_hoa_hong_ql||$obj$$.tk_no_hoa_hong||
|
|
61
|
+
$kho$$.tk_no_hoa_hong||$options$$.tk_no_hoa_hong;$r$$.tk_co_hoa_hong_ql=$r$$.tk_co_hoa_hong_ql||$obj$$.tk_co_hoa_hong_ql||$kho$$.tk_co_hoa_hong_ql||$options$$.tk_co_hoa_hong_ql||$obj$$.tk_co_hoa_hong||$kho$$.tk_co_hoa_hong||$options$$.tk_co_hoa_hong}),(await $obj$$.details.filter($r$$=>$r$$.tien_hoa_hong_ql).asyncGroupBy(["tk_no_hoa_hong_ql","tk_co_hoa_hong_ql"],["tien_hoa_hong_ql"])).forEach($r$$=>{let $tt$$={};$tt$$.tk_no=$r$$.tk_no_hoa_hong_ql;$tt$$.tk_co=$r$$.tk_co_hoa_hong_ql;$tt$$.tien_nt=$r$$.tien_hoa_hong_ql;
|
|
62
|
+
$tt$$.tien=$tt$$.tien_nt*($obj$$.ty_gia||1);$tt$$.ma_kh_no=$tt$$.ma_kh_co=$obj$$.ma_kh_hoa_hong_ql;$tt$$.ma_nv=$obj$$.ma_nv;$tt$$.check_balance=!1;$tt$$.dien_giai="Hoa h\u1ed3ng cho \u0111i\u1ec1u h\u00e0nh kinh doanh";$tt$$.ma_nt="VND";$tt$$.ty_gia=1;$tt$$.tk_no&&$tt$$.tk_co&&$details$$.push($tt$$)}));$o_tt$jscomp$1_tt$$={...$obj$$};$o_tt$jscomp$1_tt$$.tk_no=$obj$$.tk_no;$o_tt$jscomp$1_tt$$.tk_co=$obj$$.tk_thue_co;$o_tt$jscomp$1_tt$$.tien_nt=$obj$$.details.csum("tien_thue_nt");$o_tt$jscomp$1_tt$$.tien=
|
|
63
|
+
$o_tt$jscomp$1_tt$$.tien_nt*$o_tt$jscomp$1_tt$$.ty_gia;$o_tt$jscomp$1_tt$$.dien_giai_thue&&($o_tt$jscomp$1_tt$$.dien_giai=$o_tt$jscomp$1_tt$$.dien_giai_thue);$details$$.push($o_tt$jscomp$1_tt$$);if($obj$$.vatras&&$obj$$.vatras.length>0)for(var $o$jscomp$1_o$$ of $obj$$.vatras)$o$jscomp$1_o$$.tk_no=$obj$$.tk_no,$o$jscomp$1_o$$.tk_co=$o$jscomp$1_o$$.tk_thue_co,$o$jscomp$1_o$$.tien_nt=$o$jscomp$1_o$$.t_thue_nt,$o$jscomp$1_o$$.tien=$o$jscomp$1_o$$.t_thue,$o$jscomp$1_o$$.dien_giai_thue&&($o$jscomp$1_o$$.dien_giai=
|
|
64
|
+
$o$jscomp$1_o$$.dien_giai_thue),$details$$.push($o$jscomp$1_o$$);$obj$$.tk_phi_vc=$obj$$.tk_phi_vc||$options$$.tk_phi_vc;$obj$$.tk_phi_vc&&($o$jscomp$1_o$$={...$obj$$},$o$jscomp$1_o$$.tk_no=$obj$$.tk_no,$o$jscomp$1_o$$.tk_co=$obj$$.tk_phi_vc,$o$jscomp$1_o$$.tien_nt=$obj$$.tien_phi_vc_nt,$o$jscomp$1_o$$.tien=$o$jscomp$1_o$$.tien_nt*$o$jscomp$1_o$$.ty_gia,$o$jscomp$1_o$$.dien_giai="Ph\u00ed giao h\u00e0ng",$details$$.push($o$jscomp$1_o$$));const $details_giavon$$=[];($ket_qua_post_sokho$$||[]).filter($r$$=>
|
|
65
|
+
$r$$.nxt!=1).forEach(function($detail$$){$detail$$.toObject&&($detail$$=$detail$$.toObject());$detail$$={...$detail$$};$detail$$.tk_no=$detail$$.tk_gv;$detail$$.ma_kh||($detail$$.ma_kh=$obj$$.ma_kh);$detail$$.tk_co=$detail$$.tk_vt;$detail$$.tien_nt=$detail$$.tien_xuat_nt;$detail$$.tien=$detail$$.tien_xuat;$details_giavon$$.push($detail$$)});async.series({xdtk:$callback$$=>{$details_giavon$$.joinModel2($obj$$.id_app,dmvt,{where:"ma_vt",fields:["tk_vt","gia_mua","tk_gv"]},()=>{$details_giavon$$.forEach($s$$=>
|
|
66
|
+
{$s$$.tk_co||($s$$.tk_co=$s$$.tk_vt||$options$$.tk_vt);$s$$.tk_no||($s$$.tk_no=$s$$.tk_gv||$options$$.tk_gv);$s$$.ma_nt="VND";$s$$.ty_gia=1});$callback$$()})}},()=>{$details_giavon$$.forEach($d$$=>{$d$$.ma_kh_no=$d$$.ma_kh||$obj$$.ma_kh;$d$$.ma_kh_co=$d$$.ma_kh||$obj$$.ma_kh});$details$$=$details$$.concat($details_giavon$$);(new PostSocai($obj$$,$details$$,void 0,void 0,$_options$$)).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})})})},thanhtoanhoahongnv:$callback$$=>{if($obj$$.da_chuyen_hoa_hong||
|
|
67
|
+
!$obj$$.tien_hoa_hong||!$obj$$.user_nv||!$obj$$.chuyen_ngay)return $callback$$();setImmediate(async()=>{try{if($appInfo$$.wallet_address&&$appInfo$$.wallet_token&&$appInfo$$.tang_gioi_thieu_denom){let $wallet_nhan_vien$$=await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),username:$obj$$.user_nv,wallet_type:8});$wallet_nhan_vien$$||=await global.getModel("asskey").createWallet($appInfo$$._id.toString(),$obj$$.user_nv,"T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng",8);let $amount$$=
|
|
68
|
+
$obj$$.tien_hoa_hong,$denom$$=$appInfo$$.tang_gioi_thieu_denom,$memo$$=`Hoa h\u1ed3ng cho \u0111\u01a1n h\u00e0ng s\u1ed1 ${$obj$$.so_ct}: ${numeral($amount$$).format()} ${$denom$$.toUpperCase()}`;await spend($appInfo$$,$obj$$.be_introduced,$wallet_nhan_vien$$.address,$amount$$,$denom$$,$memo$$,"","2");$obj$$.da_chuyen_hoa_hong=!0;await model.updateOne({_id:$obj$$._id},{da_chuyen_hoa_hong:!0})}}catch($e$$){console.error("Kh\u00f4ng th\u1ec3 thanh to\u00e1n ti\u1ec1n hoa h\u1ed3ng",$e$$)}$callback$$()})},
|
|
69
|
+
thanhtoanhoahonggt:$callback$$=>{if($obj$$.da_chuyen_hoa_hong_gt||!$obj$$.tien_hoa_hong_gt||!$obj$$.user_gt||!$obj$$.chuyen_ngay_gt)return $callback$$();setImmediate(async()=>{try{if($appInfo$$.wallet_address&&$appInfo$$.wallet_token&&$appInfo$$.tang_gioi_thieu_denom){let $wallet_gt$$=await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),username:$obj$$.user_gt,wallet_type:8});$wallet_gt$$||=await global.getModel("asskey").createWallet($appInfo$$._id.toString(),$obj$$.user_gt,
|
|
70
|
+
"T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng",8);let $amount$$=$obj$$.tien_hoa_hong_gt,$denom$$=$appInfo$$.tang_gioi_thieu_denom,$memo$$=`Hoa h\u1ed3ng cho \u0111\u01a1n h\u00e0ng s\u1ed1 ${$obj$$.so_ct}: ${numeral($amount$$).format()} ${$denom$$.toUpperCase()}`;await spend($appInfo$$,$obj$$.be_introduced,$wallet_gt$$.address,$amount$$,$denom$$,$memo$$,$obj$$.introduce_code,"2");$obj$$.da_chuyen_hoa_hong_gt=!0;await model.updateOne({_id:$obj$$._id},{da_chuyen_hoa_hong_gt:!0})}}catch($e$$){console.error("Kh\u00f4ng th\u1ec3 thanh to\u00e1n ti\u1ec1n hoa h\u1ed3ng",
|
|
71
|
+
$e$$)}$callback$$()})},thanhtoanhoahongctv:$callback$$=>{if($obj$$.da_chuyen_hoa_hong_ctv||!$obj$$.thu_nhap_ctv||!$obj$$.user_ctv||!$obj$$.chuyen_ngay_ctv)return $callback$$();setImmediate(async()=>{try{if($appInfo$$.wallet_address&&$appInfo$$.wallet_token&&$appInfo$$.tang_gioi_thieu_denom){if($obj$$.user_ctv&&$obj$$.thu_nhap_ctv){let $wallet_ctv$$=await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),username:$obj$$.user_ctv,wallet_type:8});$wallet_ctv$$||=await global.getModel("asskey").createWallet($appInfo$$._id.toString(),
|
|
72
|
+
$obj$$.user_ctv,"T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng",8);let $amount$$=$obj$$.thu_nhap_ctv,$denom$$=$appInfo$$.tang_gioi_thieu_denom,$memo$$=`Hoa h\u1ed3ng cho \u0111\u01a1n h\u00e0ng s\u1ed1 ${$obj$$.so_ct}: ${numeral($amount$$).format()} ${$denom$$.toUpperCase()}`;await spend($appInfo$$,$obj$$.be_introduced,$wallet_ctv$$.address,$amount$$,$denom$$,$memo$$,$obj$$.introduce_code,"2")}if($obj$$.user_ctv2&&$obj$$.thu_nhap_ctv2){let $wallet_ctv2$$=await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),
|
|
73
|
+
username:$obj$$.user_ctv2,wallet_type:8});$wallet_ctv2$$||=await global.getModel("asskey").createWallet($appInfo$$._id.toString(),$obj$$.user_ctv2,"T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng",8);let $amount$$=$obj$$.thu_nhap_ctv2,$denom$$=$appInfo$$.tang_gioi_thieu_denom,$memo$$=`Hoa h\u1ed3ng cho \u0111\u01a1n h\u00e0ng s\u1ed1 ${$obj$$.so_ct}: ${numeral($amount$$).format()} ${$denom$$.toUpperCase()}`;await spend($appInfo$$,$obj$$.be_introduced,$wallet_ctv2$$.address,$amount$$,$denom$$,$memo$$,
|
|
74
|
+
$obj$$.introduce_code,"2")}$obj$$.da_chuyen_hoa_hong_ctv=!0;await model.updateOne({_id:$obj$$._id},{da_chuyen_hoa_hong_ctv:!0})}}catch($e$$){console.error("Kh\u00f4ng th\u1ec3 thanh to\u00e1n ti\u1ec1n hoa h\u1ed3ng",$e$$)}$callback$$()})},thanhtoanhoahongql:$callback$$=>{if($obj$$.da_chuyen_hoa_hong_ql||!$obj$$.tien_hoa_hong_ql||!$obj$$.user_ql||!$obj$$.chuyen_ngay_ql)return $callback$$();setImmediate(async()=>{try{if($appInfo$$.wallet_address&&$appInfo$$.wallet_token&&$appInfo$$.tang_gioi_thieu_denom){let $wallet_ql$$=
|
|
75
|
+
await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),username:$obj$$.user_ql,wallet_type:8});$wallet_ql$$||=await global.getModel("asskey").createWallet($appInfo$$._id.toString(),$obj$$.user_ql,"T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng",8);let $amount$$=$obj$$.tien_hoa_hong_ql,$denom$$=$appInfo$$.tang_gioi_thieu_denom,$memo$$=`Hoa h\u1ed3ng cho \u0111\u01a1n h\u00e0ng s\u1ed1 ${$obj$$.so_ct}: ${numeral($amount$$).format()} ${$denom$$.toUpperCase()}`;await spend($appInfo$$,
|
|
76
|
+
$obj$$.be_introduced,$wallet_ql$$.address,$amount$$,$denom$$,$memo$$,$obj$$.introduce_code,"2");$obj$$.da_chuyen_hoa_hong_ql=!0;await model.updateOne({_id:$obj$$._id},{da_chuyen_hoa_hong_ql:!0})}}catch($e$$){console.error("Kh\u00f4ng th\u1ec3 thanh to\u00e1n ti\u1ec1n hoa h\u1ed3ng",$e$$)}$callback$$()})},thanhtoanhoahongchukho:$callback$$=>{if($obj$$.da_chuyen_hoa_hong_kho||!$obj$$.tien_hoa_hong_kho||!$obj$$.user_kho||!$obj$$.chuyen_ngay_kho)return $callback$$();setImmediate(async()=>{try{if($appInfo$$.wallet_address&&
|
|
77
|
+
$appInfo$$.wallet_token&&$appInfo$$.tang_gioi_thieu_denom){let $wallet_kho$$=await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),username:$obj$$.user_kho,wallet_type:8});$wallet_kho$$||=await global.getModel("asskey").createWallet($appInfo$$._id.toString(),$obj$$.user_kho,"T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng",8);let $amount$$=$obj$$.tien_hoa_hong_kho,$denom$$=$appInfo$$.tang_gioi_thieu_denom,$memo$$=`Hoa h\u1ed3ng cho \u0111\u01a1n h\u00e0ng s\u1ed1 ${$obj$$.so_ct}: ${numeral($amount$$).format()} ${$denom$$.toUpperCase()}`;
|
|
78
|
+
await spend($appInfo$$,$obj$$.be_introduced,$wallet_kho$$.address,$amount$$,$denom$$,$memo$$,$obj$$.introduce_code,"2");$obj$$.da_chuyen_hoa_hong_kho=!0;await model.updateOne({_id:$obj$$._id},{da_chuyen_hoa_hong_kho:!0})}}catch($e$$){console.error("Kh\u00f4ng th\u1ec3 thanh to\u00e1n ti\u1ec1n hoa h\u1ed3ng",$e$$)}$callback$$()})}},function($e$$,$rs$$){$fn$$($e$$,$rs$$)})};const $valid$$=function($i_user$$,$obj$$,$next$$){$obj$$.thue_suat=$obj$$.thue_suat||0;$obj$$.tien_phi_vc_nt=$obj$$.tien_phi_vc_nt||
|
|
79
|
+
0;$obj$$.tien_phi_vc=utils.round($obj$$.tien_phi_vc_nt*$obj$$.ty_gia,0);$obj$$.details.forEach($detail$$=>{tinhGiaChuaThue($obj$$,$detail$$)});($obj$$.vatras||[]).forEach($d$$=>{$d$$.t_tien=utils.round($d$$.t_tien_nt*($obj$$.ty_gia||1),0);$d$$.t_thue=utils.round($d$$.t_thue_nt*($obj$$.ty_gia||1),0)});for($i_user$$=0;$i_user$$<$obj$$.details.length;$i_user$$++){const $detail$$=$obj$$.details[$i_user$$];$detail$$.line=$i_user$$;$detail$$.tien_ck_nt=$detail$$.tien_ck_nt||0;$detail$$.tien_thue_nt=$detail$$.tien_thue_nt||
|
|
80
|
+
0;$detail$$.tien=utils.round($detail$$.tien_nt*$obj$$.ty_gia,0);$detail$$.tien_ct=utils.round($detail$$.tien_ct_nt*$obj$$.ty_gia,0);$detail$$.gia_ban=utils.round($detail$$.gia_ban_nt*$obj$$.ty_gia,0);$detail$$.tien_ck=utils.round($detail$$.tien_ck_nt*$obj$$.ty_gia,0);$detail$$.tien_thue=utils.round($detail$$.tien_thue_nt*$obj$$.ty_gia,0);$detail$$.tien_xuat=$detail$$.tien_xuat_nt}$obj$$.id_contract?salecontract.findOne({_id:$obj$$.id_contract,id_app:$obj$$.id_app}).lean().then($c$$=>{$c$$&&($obj$$.ma_hd=
|
|
81
|
+
$c$$.ma_hd);$next$$(null,$obj$$)}).catch($e$$=>{$next$$($e$$)}):$next$$(null,$obj$$)};$contr$$.creating=async function($user$$,$obj$$,$next$$){$obj$$.details||($obj$$.details=[]);$valid$$($user$$,$obj$$,async function($error$$){if($error$$)return $next$$($error$$);await $obj$$.details.asyncJoinModel2($user$$.current_id_app,dmvt,{where:"ma_vt",setFields:($item$$,$ref$$)=>{$item$$.combo=$ref$$.combo||[];$item$$.ma_thue||($item$$.ma_thue=$ref$$.ma_thue);$item$$.ten_vt=$ref$$.ten_vt;$item$$.status_vt=
|
|
82
|
+
$ref$$.status;$item$$.gia_mua=$ref$$.gia_mua_tmp}});$error$$=($obj$$.details||[]).filter($d$$=>!$d$$.status_vt);if($error$$.length>0)return $next$$(`C\u00e1c m\u1eb7t h\u00e0ng sau \u0111\u00e3 ng\u1eebng kinh doanh ho\u1eb7c kh\u00f4ng t\u1ed3n t\u1ea1i trong h\u1ec7 th\u1ed1ng : ${$error$$.map($d$$=>$d$$.ten_vt||$d$$.ma_vt).join(",")}`);let $ngay_nay_thang_truoc$$=moment($obj$$.ngay_ct).subtract(1,"months").toDate(),$details$$=[];$obj$$.details.forEach($d$$=>{$d$$.combo&&$d$$.combo.length>0?$details$$=
|
|
83
|
+
[...$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,gia:{$gt:0},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,"months").toDate();await $details$$.filter($r$$=>!$r$$.gia_mua).asyncJoinModel2($obj$$.id_app,"giatb",{where:$item$$=>
|
|
84
|
+
({ma_vt:$item$$.ma_vt,id_app:$obj$$.id_app,gia:{$gt:0},nam:$ngay_nay_thang_truoc$$.getFullYear(),thang:$ngay_nay_thang_truoc$$.getMonth()+1}),fields:[{gia_mua:"gia"}]});$obj$$.details.filter($d$$=>$d$$.combo&&$d$$.combo.length>0).forEach($detail$$=>{$detail$$.combo=$detail$$.combo.map($item$$=>{$item$$.sl_xuat_1_combo=$item$$.sl_xuat;$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=
|
|
85
|
+
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)});$obj$$.result_export_einvoice=null;$next$$(null,$obj$$)})};$contr$$.updating=async function($user$$,$data$$,$obj$$,$next$$){$data$$.details||($data$$.details=
|
|
86
|
+
$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$$)=>{let $old_combo$$=($item$$.combo||[]).map($i$$=>({ma_vt:$i$$.ma_vt,sl_xuat:$i$$.sl_xuat})),$new_combo$$=($ref$$.combo||[]).map($i$$=>({ma_vt:$i$$.ma_vt,sl_xuat:$i$$.sl_xuat}));_.isEqual($old_combo$$,$new_combo$$)||($item$$.combo=$ref$$.combo||[]);$item$$.gia_mua=$ref$$.gia_mua_tmp}});let $ngay_nay_thang_truoc$$=moment($data$$.ngay_ct).subtract(1,
|
|
87
|
+
"months").toDate(),$details$$=[];$data$$.details.forEach($d$$=>{$d$$.combo&&$d$$.combo.length>0?$details$$=$details$$.concat($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,gia:{$gt:0},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,"months").toDate();
|
|
88
|
+
await $details$$.filter($r$$=>!$r$$.gia_mua).asyncJoinModel2($obj$$.id_app,"giatb",{where:$item$$=>({ma_vt:$item$$.ma_vt,id_app:$obj$$.id_app,gia:{$gt:0},nam:$ngay_nay_thang_truoc$$.getFullYear(),thang:$ngay_nay_thang_truoc$$.getMonth()+1}),fields:[{gia_mua:"gia"}]});$data$$.details.filter($d$$=>$d$$.combo&&$d$$.combo.length>0).forEach($detail$$=>{$detail$$.combo=$detail$$.combo.map($item$$=>{$item$$.sl_xuat_1_combo==void 0&&($item$$.sl_xuat_1_combo=$item$$.sl_xuat||0);$item$$.sl_xuat=$item$$.sl_xuat_1_combo*
|
|
89
|
+
$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)});Tdttno_tt.findOne({id_hd:$obj$$._id},
|
|
90
|
+
function($error$$,$ct_tt$$){if($error$$)return $next$$($error$$);$ct_tt$$?$next$$(`Kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt phi\u1ebfu n\u00e0y do \u0111\u00e3 \u0111\u01b0\u1ee3c thanh to\u00e1n b\u1edfi ${$ct_tt$$.ma_ct||"ch\u1ee9ng t\u1eeb"}: ${$ct_tt$$.so_ct}, ng\u00e0y ${moment($ct_tt$$.ngay_ct).format("DD/MM/YYYY")}`):$valid$$($user$$,$data$$,function($error$$){if($error$$)return $next$$($error$$);$next$$(null,$data$$,$obj$$)})})};$contr$$.deleting=function($user$$,$obj$$,$next$$){Tdttno_tt.findOne({id_hd:$obj$$._id,
|
|
91
|
+
id_app:$obj$$.id_app},function($error$$,$ct_tt$$){if($error$$)return $next$$($error$$);$ct_tt$$?$next$$(`Kh\u00f4ng th\u1ec3 xo\u00e1 phi\u1ebfu n\u00e0y do \u0111\u00e3 \u0111\u01b0\u1ee3c thanh to\u00e1n b\u1edfi ${$ct_tt$$.ma_ct||"ch\u1ee9ng t\u1eeb"}: ${$ct_tt$$.so_ct}, ng\u00e0y ${moment($ct_tt$$.ngay_ct).format("DD/MM/YYYY")}`):$next$$(null,$obj$$)})};$contr$$.on("saved",function($obj$$){$obj$$.id_dh2&&global.getModel("dh2").updateMany({_id:$obj$$.id_dh2,id_app:$obj$$.id_app},{id_hd2:$obj$$._id.toString(),
|
|
92
|
+
trang_thai:"7"},()=>{global.getModel("dh2").findOne({_id:$obj$$.id_dh2},($e$$,$_obj$$)=>{$_obj$$&&controller.postData($_obj$$,global.controllers.DH2,$e$$=>{$e$$&&console.error($e$$)})})})});$contr$$.on("deleted",function($obj$$){$obj$$.id_dh2&&global.getModel("dh2").updateMany({_id:$obj$$.id_dh2,id_app:$obj$$.id_app,id_pxh:{$in:[null,"",void 0]}},{id_hd2:"",trang_thai:"3"},()=>{global.getModel("dh2").updateMany({_id:$obj$$.id_dh2,id_app:$obj$$.id_app,id_pxh:{$nin:[null,"",void 0]}},{id_hd2:"",trang_thai:"6"},
|
|
93
|
+
()=>{global.getModel("dh2").findOne({_id:$obj$$.id_dh2,id_app:$obj$$.id_app},($e$$,$_obj$$)=>{$_obj$$&&controller.postData($_obj$$,global.controllers.DH2,$e$$=>{$e$$&&console.error($e$$)})})})})});$contr$$.view=function($user$$,$items$$,$fn$$){const $id_app$$=$user$$.current_id_app;async.parallel({dt:function($callback$$){$items$$.filter($item$$=>$item$$.ma_dt).joinModel2($id_app$$,dmdt,[{where:"ma_dt",fields:[{name:"ten_dt",value:"ten_dt"}]}],function(){$callback$$()})},kh:function($callback$$){$items$$.filter($item$$=>
|
|
94
|
+
$item$$.ma_kh).joinModel2($id_app$$,customer,[{where:"ma_kh",fields:["ten_kh","email","nh_kh"]}],function(){$callback$$()})},ghn:function($callback$$){$items$$.filter($item$$=>$item$$.tinh_thanh&&$item$$.quan_huyen&&$item$$.xa_phuong).joinModel2(null,"xaphuong",[{where:{tinh_thanh:"ten_tinh_thanh",quan_huyen:"ten_quan_huyen",xa_phuong:"ten_xa_phuong"},fields:["provinceid_ghn","districtid_ghn","wardcode_ghn"]}],function(){$callback$$()})},nv:function($callback$$){$items$$.filter($item$$=>$item$$.ma_nv).joinModel($id_app$$,
|
|
95
|
+
dmnv,[{akey:"ma_nv",bkey:"ma_nv",setFields:($item$$,$ref$$)=>{$item$$.ma_bp||($item$$.ma_bp=$ref$$.ma_bp);$item$$.ten_nv=$ref$$.ten_nv}}],function(){$callback$$()})},trangthai:function($callback$$){$items$$.filter($item$$=>$item$$.trang_thai).joinModel2(null,trangthai,[{where:{trang_thai:"ma_trang_thai",ma_ct:"ma_ct"},fields:["ten_trang_thai","color"]}],function(){$callback$$()})},contract:function($callback$$){$items$$.filter($item$$=>$item$$.ma_hd).joinModel2($id_app$$,contract,[{where:{ma_hd:"so_hd"},
|
|
96
|
+
fields:["ten_hd","ten_hd"]}],function(){$callback$$()})},cong_no:function($callback$$){setImmediate(async()=>{try{const $id_hds$$=$items$$.map($i$$=>$i$$._id.toString()),$congnos$$=await global.getModel("tdttno").getBalance({id_app:$id_app$$,id_hd:{$in:$id_hds$$}});for(let $item$$ of $items$$){let $invoice$$=$congnos$$.find($c$$=>$c$$.id_ct.toString()==$item$$._id.toString());if($invoice$$&&($item$$.da_thanh_toan_nt=$invoice$$.da_thanh_toan_nt,$item$$.da_thanh_toan=$invoice$$.da_thanh_toan,$item$$.con_lai_nt=
|
|
97
|
+
$invoice$$.con_lai_nt,$item$$.con_lai=$invoice$$.con_lai,$item$$.con_lai_nt)){let $t_invoice$$={sel:!1,id_tdtt:$invoice$$._id,line:$invoice$$.line,id_hd:$invoice$$.id_ct,so_hd:$invoice$$.so_hd||$invoice$$.so_ct,ngay_hd:$invoice$$.ngay_hd||$invoice$$.ngay_ct,tien_hd_nt:$invoice$$.tien_nt};$t_invoice$$.ma_nt_hd=$invoice$$.ma_nt;$t_invoice$$.ty_gia_hd=$invoice$$.ty_gia;$t_invoice$$.ma_kh=$invoice$$.ma_kh;$t_invoice$$.ma_kho=$invoice$$.ma_kho;$t_invoice$$.dien_giai=$invoice$$.dien_giai;$t_invoice$$.tien_nt=
|
|
98
|
+
0;$t_invoice$$.tien=0;$t_invoice$$.thanh_toan_qd=0;$t_invoice$$.tk_co=$invoice$$.tk_no;$t_invoice$$.da_thanh_toan_nt=$invoice$$.da_thanh_toan_nt;$t_invoice$$.da_thanh_toan=$invoice$$.da_thanh_toan;$t_invoice$$.con_lai_nt=$invoice$$.con_lai_nt;$t_invoice$$.con_lai=$invoice$$.con_lai;$item$$.theo_doi_thanh_toan=$t_invoice$$}}$callback$$()}catch($e$$){$callback$$($e$$)}})},t_tien:function($callback$$){for(let $r$$ of $items$$)$r$$.details&&($r$$.details.forEach($d$$=>{$d$$.tien_tinh_thue_nt=$d$$.tien_ct_nt-
|
|
99
|
+
$d$$.tien_ck_nt;$d$$.tien_nt=$d$$.tien_ct_nt-$d$$.tien_ck_nt+$d$$.tien_thue_nt;$d$$.tien=Math.round($d$$.tien_nt*$r$$.ty_gia)}),$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"),$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"),
|
|
100
|
+
$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_sl_vt_du=$r$$.details.csum("sl_vt_du"),$r$$.t_gt_vt_du=$r$$.details.csum("gt_vt_du"),$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_gt_vt_du,$r$$.t_tt=Math.round($r$$.t_tt_nt*$r$$.ty_gia||1,0),$r$$.t_tien_xuat=$r$$.details.csum("tien_xuat"),$r$$.t_tien_xuat_nt=$r$$.details.csum("tien_xuat_nt"),$r$$.tien_hoa_hong=$r$$.details.csum("tien_hoa_hong"),
|
|
101
|
+
$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_kho:function($callback$$){async.map($items$$,function($r$$,$callback$$){($r$$.details||[]).filter($item$$=>$item$$.ma_kho).joinModel2($id_app$$,dmkho,[{where:"ma_kho",fields:["ten_kho"]}],
|
|
102
|
+
function(){$callback$$()})},function(){$callback$$()})},details_vt:function($callback$$){async.map($items$$,function($voucher$$,$callback1$$){(async()=>{const $details$$=$voucher$$.details||[];await $details$$.asyncJoinModel2($id_app$$,dmvt,[{where:"ma_vt",setFields:($item$$,$ref$$)=>{$item$$.ten_vt=$ref$$.ten_vt;$item$$.tk_tl=$ref$$.tk_tl;$item$$.trong_luong=$item$$.trong_luong||$ref$$.trong_luong;$item$$.chieu_sau=$item$$.chieu_sau||$ref$$.chieu_sau;$item$$.chieu_rong=$item$$.chieu_rong||$ref$$.chieu_rong;
|
|
103
|
+
$item$$.chieu_cao=$item$$.chieu_cao||$ref$$.chieu_cao;$item$$.ma_tt1_yn=$ref$$.ma_tt1_yn;$item$$.ma_tt2_yn=$ref$$.ma_tt2_yn;$item$$.ma_tt3_yn=$ref$$.ma_tt3_yn;$item$$.ma_lo_yn=$ref$$.ma_lo_yn;$item$$.ma_nvt||($item$$.ma_nvt=$ref$$.ma_nvt);$item$$.ma_nvt2||($item$$.ma_nvt2=$ref$$.ma_nvt2);$item$$.ma_nvt3||($item$$.ma_nvt3=$ref$$.ma_nvt3)}}]);await $details$$.filter($d$$=>$d$$.ma_nvt).asyncJoinModel2($id_app$$,"dmnvt",[{where:{ma_nvt:"_id"},setFields:($item$$,$nh_vt_ref$$)=>{$item$$.ten_nvt=$nh_vt_ref$$.ten_nvt;
|
|
104
|
+
$item$$.ten_nvt&&($nh_vt_ref$$=`nh_vt_${$item$$.ten_nvt}`,$voucher$$[$nh_vt_ref$$]=($voucher$$[$nh_vt_ref$$]||0)+$item$$.sl_xuat)}}]);$callback1$$()})()},function(){$callback$$()})},details_vt_du:function($callback$$){async.map($items$$,function($r$$,$callback1$$){($r$$.details||[]).filter($d$$=>$d$$.ma_vt_du).joinModel2($id_app$$,dmvt,[{where:{ma_vt_du:"ma_vt"},fields:{ten_vt_du:"ten_vt"}}],function(){$callback1$$()})},function(){$callback$$()})},details_pk_nhap:function($callback$$){async.map($items$$,
|
|
105
|
+
function($r$$,$callback1$$){($r$$.ds_pk_nhap||[]).filter($d$$=>$d$$.ma_pk_nhap).joinModel2($id_app$$,dmvt,[{where:{ma_pk_nhap:"ma_vt"},fields:{ten_pk_nhap:"ten_vt"}}],function(){$callback1$$()})},function(){$callback$$()})},details_pk_xuat:function($callback$$){async.map($items$$,function($r$$,$callback1$$){($r$$.ds_pk_xuat||[]).filter($d$$=>$d$$.ma_pk_xuat).joinModel2($id_app$$,dmvt,[{where:{ma_pk_xuat:"ma_vt"},fields:{ten_pk_xuat:"ten_vt"}}],function(){$callback1$$()})},function(){$callback$$()})},
|
|
106
|
+
details_csck:function($callback$$){async.map($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=$ref$$.ten_chietkhau}}],function(){$callback1$$()})},function(){$callback$$()})},details_tt1:function($callback$$){async.map($items$$,function($r$$,$callback1$$){($r$$.details||[]).filter($d$$=>$d$$.ma_tt1).joinModel2($id_app$$,"dmtt",[{where:{ma_vt:"ma_vt",ma_tt1:"ma_tt"},
|
|
107
|
+
setFields:($item$$,$ref$$)=>{$item$$.thuoc_tinh=$ref$$;$item$$.nh_tt||($item$$.nh_tt=$ref$$.nh_tt)}}],function(){$callback1$$()})},function(){$callback$$()})},details_dt:function($callback$$){async.map($items$$,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_dt).joinModel2($id_app$$,dmdt,[{where:"ma_dt",fields:["ten_dt"]}],function(){$callback1$$()})},function(){$callback$$()})},details_contract:function($callback$$){async.map($items$$,function($r$$,$callback1$$){($r$$.details||
|
|
108
|
+
[]).filter($item$$=>$item$$.ma_hd).joinModel2($id_app$$,contract,[{where:{ma_hd:"so_hd"},fields:[{name:"ten_hd",value:"ten_hd"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_phi:function($callback$$){async.map($items$$,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_phi).joinModel2($id_app$$,dmphi,[{where:"ma_phi",fields:["ten_phi"]}],function(){$callback1$$()})},function(){$callback$$()})},details_chietkhau:function($callback$$){async.map($items$$,
|
|
109
|
+
function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.id_cs_ck).joinModel2($id_app$$,"dmchietkhau",[{where:{id_cs_ck:"_id"},fields:["ma_chietkhau","ten_chietkhau"]}],function(){$callback1$$()})},function(){$callback$$()})}},async function(){$fn$$(null,$items$$)})};$contr$$.createRoute("export2viettel/:id_ct",async($req$$,$next$$)=>{var $ct_id_app$$=$req$$.user.current_id_app;const $app$$=await App.findOne({_id:$ct_id_app$$});if(!$app$$)return $next$$("Kh\u00f4ng t\u00ecm th\u1ea5y c\u00f4ng ty n\u00e0y");
|
|
110
|
+
if(!$app$$.ma_so_thue)return $next$$("B\u1ea1n ch\u01b0a nh\u1eadp m\u00e3 s\u1ed1 thu\u1ebf c\u1ee7a c\u00f4ng ty");$ct_id_app$$=await model.findOne({id_app:$ct_id_app$$,_id:$req$$.params.id_ct}).lean();if(!$ct_id_app$$)return $next$$("Ch\u1ee9ng t\u1eeb kh\u00f4ng h\u1ee3p l\u1ec7");try{let $rs$$=await utils.exportInvoice($app$$,$ct_id_app$$,$req$$.query.check_data);$next$$(null,$rs$$)}catch($e$$){$next$$({error:$e$$.message||$e$$.error||$e$$})}},{method:"GET"});$contr$$.createRoute("import/invoice",
|
|
111
|
+
async($req$$,$next$$)=>{var $invoices_tu_ngay$$=$req$$.query.tu_ngay;let $den_ngay$$=$req$$.query.den_ngay;if(!$invoices_tu_ngay$$||!$den_ngay$$)return $next$$("C\u1ea7n cung c\u1ea5p \u0111i\u1ec1u ki\u1ec7n tu_ngay,den_ngay");const $id_app$$=$req$$.user.current_id_app,$app$$=await App.findOne({_id:$id_app$$});if(!$app$$)return $next$$("Kh\u00f4ng t\u00ecm th\u1ea5y c\u00f4ng ty n\u00e0y");const $voucher_options$$=(await global.getModel("options").findOne({id_app:$id_app$$,id_func:$contr$$.name},
|
|
112
|
+
{option:1}).lean()||{}).option||{};if(!$voucher_options$$.ma_kho)return $next$$("B\u1ea1n c\u1ea7n c\u1eadp nh\u1eadt tu\u1ef3 ch\u1ecdn m\u00e3 kho m\u1eb7c \u0111\u1ecbnh trong tu\u1ef3 ch\u1ecdn c\u1ee7a ch\u1ee9ng t\u1eeb");if(!$voucher_options$$.tk_no)return $next$$("B\u1ea1n c\u1ea7n c\u1eadp nh\u1eadt tu\u1ef3 ch\u1ecdn t\u00e0i kho\u1ea3n n\u1ee3 m\u1eb7c \u0111\u1ecbnh trong tu\u1ef3 ch\u1ecdn c\u1ee7a ch\u1ee9ng t\u1eeb");if(!$voucher_options$$.tk_vt)return $next$$("B\u1ea1n c\u1ea7n c\u1eadp nh\u1eadt tu\u1ef3 ch\u1ecdn t\u00e0i v\u1eadt t\u01b0 m\u1eb7c \u0111\u1ecbnh trong tu\u1ef3 ch\u1ecdn c\u1ee7a ch\u1ee9ng t\u1eeb");
|
|
113
|
+
if(!$voucher_options$$.tk_gv)return $next$$("B\u1ea1n c\u1ea7n c\u1eadp nh\u1eadt tu\u1ef3 ch\u1ecdn t\u00e0i kho\u1ea3n gi\u00e1 v\u1ed1n m\u1eb7c \u0111\u1ecbnh trong tu\u1ef3 ch\u1ecdn c\u1ee7a ch\u1ee9ng t\u1eeb");if(!$voucher_options$$.tk_dt)return $next$$("B\u1ea1n c\u1ea7n c\u1eadp nh\u1eadt tu\u1ef3 ch\u1ecdn t\u00e0i kho\u1ea3n doanh thu m\u1eb7c \u0111\u1ecbnh trong tu\u1ef3 ch\u1ecdn c\u1ee7a ch\u1ee9ng t\u1eeb");try{$invoices_tu_ngay$$=new Date($invoices_tu_ngay$$);$den_ngay$$=new Date($den_ngay$$);
|
|
114
|
+
let $invoices_vnpt$$=await utils.getInvoices($app$$,{tu_ngay:$invoices_tu_ngay$$,den_ngay:$den_ngay$$});$invoices_tu_ngay$$=[];for(let $ivn$$ of $invoices_vnpt$$)await model.findOne({id_app:$id_app$$,id_invoice:$ivn$$.id_invoice}).lean()||($ivn$$.ma_kh=$ivn$$.ma_kh||$ivn$$.ten_kh.replace(/[^\w\s]/gi,"").split(" ").join("").toUpperCase().substring(0,32),$ivn$$.trang_thai="5",$invoices_tu_ngay$$.push($ivn$$));let $khs$$=await $invoices_tu_ngay$$.asyncGroupBy(["ma_kh","ten_kh","dia_chi","ma_so_thue",
|
|
115
|
+
"dien_thoai"],[]);for(let $kh$$ of $khs$$)$kh$$.id_app=$id_app$$,$kh$$.ma_kh||($kh$$.ma_kh=$kh$$.ten_kh.replace(/[^\w\s]/gi,"").split(" ").join("").toUpperCase()),await global.getModel("customer").asyncCreateCustomer($kh$$);let $vts$$=await $invoices_tu_ngay$$.map($i$$=>$i$$.details||[]).reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]).asyncGroupBy(["ma_vt","ten_vt","ma_dvt"],[]),$dvts$$=await $vts$$.asyncGroupBy(["ma_dvt"],[]);for(let $dvt$$ of $dvts$$)$dvt$$.id_app=$id_app$$,$dvt$$.ten_dvt=$dvt$$.ma_dvt,
|
|
116
|
+
$dvt$$.status=!0,$dvt$$.user_created=$req$$.user.email,await global.getModel("dmdvt").findOne({ma_dvt:$dvt$$.ma_dvt,id_app:$dvt$$.id_app}).lean()||(console.log("create dvt",$dvt$$),await global.getModel("dmdvt").create($dvt$$));for(let $vt$$ of $vts$$)$vt$$.id_app=$id_app$$,$vt$$.status=!0,$vt$$.user_created=$req$$.user.email,$vt$$.tk_vt=$voucher_options$$.tk_vt,$vt$$.tk_dt=$voucher_options$$.tk_dt,$vt$$.tk_gv=$voucher_options$$.tk_gv,await global.getModel("dmvt").findOne({ma_vt:$vt$$.ma_vt,id_app:$vt$$.id_app}).lean()||
|
|
117
|
+
(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,tu:1,ma:1}));$contr$$.import($req$$.user,$id_app$$,$invoices_tu_ngay$$,($e$$,$rs$$)=>$next$$($e$$,$rs$$))}catch($e$$){return $next$$($e$$.error||$e$$.messate||$e$$)}},{method:"GET"})};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
const _global=require("../global"),async=require("async"),model=global.getModel("app"),fs=require("fs"),path=require("path"),moment=require("moment"),zip=(new require("node-zip"))();require("../libs/prototypes.js");const Participant=global.getModel("participant"),{parentPort,workerData}=require("worker_threads");let connect2Db=!1;
|
|
2
|
-
const _=require("lodash"),backup=$msg$$=>{if($msg$$.configs&&_.isString($msg$$.configs))try{$msg$$.configs=JSON.parse($msg$$.configs)}catch($e$$){delete $msg$$.configs,console.info($e$$)}
|
|
3
|
-
($dateFrom$$=moment(),$dateFrom$$.year(1900));$dateTo$$?$dateTo$$=moment(new Date($dateTo$$)).endOf("date"):($dateTo$$=moment(),$dateTo$$.year(2999));
|
|
4
|
-
id_task:$msg$$.id_task});let $data$$={};$back_app_info$$&&($data$$["app.js"]=$app$$);async.parallel({data:$callback$$=>{mongoose.connection.db.listCollections().toArray(($err$$,$collections$$)=>{if($err$$)return $callback$$($err$$);
|
|
5
|
-
($collection$$,$callback$$)=>{setImmediate(()=>{let $query$$={id_app:$id_app$$};$query$$.$or=[{ngay_ct:null},{ngay_ct:{$gte:$dateFrom$$.toDate(),$lte:$dateTo$$.toDate()}}];console.log("backupping..."
|
|
6
|
-
$
|
|
7
|
-
$e$$),parentPort.postMessage({error:$e$$,id_task:$msg$$.id_task})
|
|
8
|
-
"binary");console.log("backuped to file ",$fileZip$$);parentPort.postMessage({file:$
|
|
9
|
-
workerData&&(()=>{let $msg$$=workerData;if(_.isString($msg$$))try{$msg$$=JSON.parse($msg$$)}catch($e$$){console.error($e$$);parentPort.postMessage({error:"msg is not valid"});return}$msg$$.id&&backup($msg$$)})();setInterval(()=>{parentPort.postMessage("pong")},5E3);
|
|
2
|
+
const _=require("lodash"),backup=$msg$$=>{let $dir$$=$msg$$.dirPath;if($dir$$&&!fs.existsSync($dir$$))parentPort.postMessage({error:"Th\u01b0 m\u1ee5c l\u01b0u tr\u1eef kh\u00f4ng t\u1ed3n t\u1ea1i",id_task:$msg$$.id_task});else{$dir$$=$dir$$||path.dirname(__dirname)+"/backup/";if($msg$$.configs&&_.isString($msg$$.configs))try{$msg$$.configs=JSON.parse($msg$$.configs)}catch($e$$){delete $msg$$.configs,console.info($e$$)}var $configs$$=$msg$$.configs||require("../configs");connect2Db||(mongoose.connect($configs$$.database.url,
|
|
3
|
+
{useNewUrlParser:!0}),connect2Db=!0);var $id_app$$=$msg$$.id,$dateFrom$$=$msg$$.dateFrom,$dateTo$$=$msg$$.dateTo,$back_app_info$$=$msg$$.back_app_info;$dateFrom$$?$dateFrom$$=moment(new Date($dateFrom$$)).startOf("date"):($dateFrom$$=moment(),$dateFrom$$.year(1900));$dateTo$$?$dateTo$$=moment(new Date($dateTo$$)).endOf("date"):($dateTo$$=moment(),$dateTo$$.year(2999));var $user$$=$msg$$.user;model.findOne({_id:$id_app$$}).lean().then(async $app$$=>{if(!$app$$)return parentPort.postMessage({error:"C\u00f4ng ty n\u00e0y kh\u00f4ng t\u1ed3n t\u1ea1i",
|
|
4
|
+
id_task:$msg$$.id_task});const $par$$=await Participant.findOne({email:$user$$,id_app:$id_app$$,admin:!0});if($app$$.user_created!==$user$$&&!$par$$)return parentPort.postMessage({error:"B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n th\u1ef1c hi\u1ec7n t\u00e1c v\u1ee5 n\u00e0y",id_task:$msg$$.id_task});let $data$$={};$back_app_info$$&&($data$$["app.js"]=$app$$);async.parallel({data:$callback$$=>{mongoose.connection.db.listCollections().toArray(($err$$,$collections$$)=>{if($err$$)return $callback$$($err$$);
|
|
5
|
+
const $collection_need_backup$$=$collections$$.filter($c$$=>$c$$.name!=="users"&&$c$$.name!=="apps"&&$c$$.name!=="logs"&&$c$$.name!=="rights"&&$c$$.name!=="participants");console.info("Prepare backup",$collection_need_backup$$.length,"collections");const $backed$$=[];async.map($collection_need_backup$$,($collection$$,$callback$$)=>{setImmediate(()=>{let $query$$={id_app:$id_app$$};$query$$.$or=[{ngay_ct:null},{ngay_ct:{$gte:$dateFrom$$.toDate(),$lte:$dateTo$$.toDate()}}];console.log("backupping...",
|
|
6
|
+
$collection$$.name,$query$$);mongoose.connection.db.collection($collection$$.name,($err$$,$coll$$)=>{if($err$$)return $callback$$($err$$);$coll$$.find({...$query$$}).toArray(($e$$,$rs$$)=>{if($e$$)return $callback$$($e$$);console.info("Preparing data",$collection$$.name,$rs$$.length,"row(s)");$rs$$.forEach(($r$$,$index$$)=>{$r$$.id_backup=$r$$._id.toString();$collection$$.name.includes("sokho")&&($r$$.line=$index$$);$collection$$.name.includes("socai")&&($r$$.nh_dk=$index$$)});console.info("Backup success",
|
|
7
|
+
$collection$$.name,$rs$$.length,"row(s)");$backed$$.push($collection$$.name);console.info("Backed",$backed$$.length,"/",$collection_need_backup$$.length,"collection(s)");$data$$[$collection$$.name]=$rs$$;return $callback$$()})})})},$e$$=>{$e$$&&console.error($e$$);$callback$$($e$$)})})}},$e$$=>{if($e$$)return console.error("Error backup database",$e$$),parentPort.postMessage({error:$e$$,id_task:$msg$$.id_task});fs.existsSync($dir$$)||fs.mkdirSync($dir$$);console.log("zip data...");try{zip.file("backup.json",
|
|
8
|
+
JSON.stringify($data$$));const $dataZipped$$=zip.generate({base64:!1,compression:"DEFLATE"});let $fileZip$$=$app$$._id+"-"+moment().format("YYYY-MM-DD-HH:mm:ss")+".zip";console.log("write datazipped to file ",$fileZip$$);$e$$=$dir$$+$fileZip$$;fs.writeFileSync($e$$,$dataZipped$$,"binary");console.log("backuped to file ",$fileZip$$);parentPort.postMessage({file:$e$$,id_task:$msg$$.id_task})}catch($e$$){parentPort.postMessage({error:$e$$,id_task:$msg$$.id_task})}})}).catch($e$$=>{parentPort.postMessage({error:$e$$.message,
|
|
9
|
+
id_task:$msg$$.id_task})})}};parentPort.on("message",$msg$$=>{if($msg$$&&_.isString($msg$$))try{$msg$$=JSON.parse($msg$$)}catch($e$$){console.error($e$$);parentPort.postMessage({error:"msg is not valid"});return}backup($msg$$)});workerData&&(()=>{let $msg$$=workerData;if(_.isString($msg$$))try{$msg$$=JSON.parse($msg$$)}catch($e$$){console.error($e$$);parentPort.postMessage({error:"msg is not valid"});return}$msg$$.id&&backup($msg$$)})();setInterval(()=>{parentPort.postMessage("pong")},5E3);
|