flexbiz-server 12.2.2 → 12.2.4
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 +2 -2
- package/server/app.js +14 -14
- package/server/auths/local.js +27 -26
- package/server/cluster.js +12 -11
- package/server/controllers/controller.js +83 -79
- package/server/controllers/controllerRPT.js +18 -17
- package/server/data/sys/listinfo.js +80395 -78085
- package/server/data/sys/reportinfo.js +8826 -8826
- package/server/data/sys/trangthai.js +10348 -10229
- package/server/libs/cdpstk.js +1 -1
- package/server/libs/databanle.js +13 -13
- package/server/libs/getGiaban.js +17 -16
- package/server/libs/permission.js +12 -12
- package/server/libs/post-book.js +9 -8
- package/server/libs/post-socai.js +9 -9
- package/server/libs/prototypes.js +7 -7
- package/server/libs/tinhGtPhanboSltp.js +5 -5
- package/server/libs/tinhGtPhanboYtcp.js +2 -2
- package/server/libs/tinhGtThcppstk.js +1 -1
- package/server/libs/tinhGtTrucTiep.js +8 -7
- package/server/libs/tinhgiatb.js +16 -19
- package/server/libs/tinhgiatb1vt.js +3 -3
- package/server/libs/tinhhoahong.js +32 -0
- package/server/libs/utils.js +4 -3
- package/server/models/app.js +9 -8
- package/server/models/approve.js +4 -4
- package/server/models/customer.js +8 -4
- package/server/models/dh2.js +10 -7
- package/server/models/dmbp.js +7 -4
- package/server/models/dmgiaban.js +6 -6
- package/server/models/dmhoahonghd.js +6 -5
- package/server/models/dmnvt.js +3 -3
- package/server/models/dmvt.js +9 -9
- package/server/models/ecomcategories.js +2 -2
- package/server/models/ecomcategories_cty.js +3 -0
- package/server/models/fbconversation.js +9 -0
- package/server/models/fbmessage.js +2 -0
- package/server/models/fbpage.js +2 -0
- package/server/models/group.js +7 -5
- package/server/models/hd2.js +11 -8
- package/server/models/hd3.js +9 -9
- package/server/models/hd7.js +1 -1
- package/server/models/listinfo.js +15 -8
- package/server/models/notification.js +3 -2
- package/server/models/originimportid.js +1 -0
- package/server/models/participant.js +5 -5
- package/server/models/pbl.js +4 -4
- package/server/models/reportinfo.js +2 -2
- package/server/models/rptform.js +3 -2
- package/server/models/schedule.js +1 -1
- package/server/models/so1.js +17 -14
- package/server/models/socai.js +7 -5
- package/server/models/task.js +4 -4
- package/server/models/tdttco.js +8 -4
- package/server/models/tdttno.js +8 -4
- package/server/models/tokens.js +2 -2
- package/server/models/tontucthoi.js +2 -2
- package/server/models/usergroup.js +4 -3
- package/server/models/vatra.js +2 -2
- package/server/models/vatvao.js +4 -4
- package/server/modules/lists/ls-assinvestment.js +1 -1
- package/server/modules/lists/ls-asskey.js +34 -34
- package/server/modules/lists/ls-customer.js +13 -7
- package/server/modules/lists/ls-dmbp.js +7 -3
- package/server/modules/lists/ls-dmnkh.js +5 -1
- package/server/modules/lists/ls-dmnvt.js +5 -5
- package/server/modules/lists/ls-dmvt.js +48 -35
- package/server/modules/lists/ls-ecomcategories.js +5 -0
- package/server/modules/lists/ls-ecomcategories_cty.js +5 -0
- package/server/modules/lists/ls-fbconversation.js +3 -0
- package/server/modules/lists/ls-fbmessage.js +3 -0
- package/server/modules/lists/ls-fbpage.js +10 -0
- package/server/modules/lists/ls-file.js +21 -25
- package/server/modules/lists/ls-group.js +5 -1
- package/server/modules/lists/ls-introducecode.js +8 -7
- package/server/modules/lists/ls-introducer.js +16 -17
- package/server/modules/lists/ls-message2.js +8 -7
- package/server/modules/lists/ls-message2setting.js +4 -4
- package/server/modules/lists/ls-news.js +1 -1
- package/server/modules/lists/ls-opportunity.js +3 -3
- package/server/modules/lists/ls-session.js +2 -2
- package/server/modules/lists/ls-task.js +18 -18
- package/server/modules/lists/ls-usergroup.js +6 -2
- package/server/modules/public/callin.js +6 -6
- package/server/modules/reports/calc-tinhgiatb.js +2 -2
- package/server/modules/reports/rp-cdpstk.js +3 -3
- package/server/modules/reports/rp-chitiettaisan.js +9 -8
- package/server/modules/reports/rp-ckvt.js +9 -7
- package/server/modules/reports/rp-congviectheonv.js +5 -5
- package/server/modules/reports/rp-ctbanle.js +13 -12
- package/server/modules/reports/rp-databanle.js +8 -4
- package/server/modules/reports/rp-dtbanletheoct.js +16 -9
- package/server/modules/reports/rp-dtbanletheokh.js +12 -6
- package/server/modules/reports/rp-dtbanletheokho.js +14 -9
- package/server/modules/reports/rp-dtbanletheonam.js +15 -9
- package/server/modules/reports/rp-dtbanletheongay.js +13 -8
- package/server/modules/reports/rp-dtbanletheonv.js +15 -9
- package/server/modules/reports/rp-dtbanletheoquy.js +15 -9
- package/server/modules/reports/rp-dtbanletheothang.js +15 -9
- package/server/modules/reports/rp-getinvoice2pay.js +4 -6
- package/server/modules/reports/rp-getinvoice2receive.js +4 -6
- package/server/modules/reports/rp-hoahong.js +9 -0
- package/server/modules/reports/rp-kqhdkd.js +5 -4
- package/server/modules/reports/rp-ptcttct.js +7 -6
- package/server/modules/reports/rp-pttct.js +8 -8
- package/server/modules/reports/rp-pttctkho.js +3 -2
- package/server/modules/reports/rp-pttctkho2.js +3 -3
- package/server/modules/reports/rp-thnxt.js +8 -7
- package/server/modules/reports/rp-thnxt_sl.js +6 -6
- package/server/modules/reports/rp-thnxttt.js +6 -6
- package/server/modules/reports/rp-tmbctc.js +16 -16
- package/server/modules/systems/sys-app.js +25 -24
- package/server/modules/systems/sys-notification.js +2 -2
- package/server/modules/systems/sys-schedule.js +1 -1
- package/server/modules/systems/sys-user.js +8 -8
- package/server/modules/vouchers/vo-bc1.js +9 -8
- package/server/modules/vouchers/vo-bg2.js +9 -9
- package/server/modules/vouchers/vo-bn1.js +5 -4
- package/server/modules/vouchers/vo-dh2.js +14 -19
- package/server/modules/vouchers/vo-dnm.js +11 -12
- package/server/modules/vouchers/vo-hd2.js +66 -54
- package/server/modules/vouchers/vo-hd3.js +28 -22
- package/server/modules/vouchers/vo-hd7.js +37 -36
- package/server/modules/vouchers/vo-pbl.js +49 -49
- package/server/modules/vouchers/vo-pc1.js +9 -8
- package/server/modules/vouchers/vo-pn1.js +24 -22
- package/server/modules/vouchers/vo-pn5.js +1 -1
- package/server/modules/vouchers/vo-pn9.js +23 -23
- package/server/modules/vouchers/vo-pnc.js +8 -8
- package/server/modules/vouchers/vo-pnh.js +5 -5
- package/server/modules/vouchers/vo-pt1.js +17 -16
- package/server/modules/vouchers/vo-pxc.js +16 -16
- package/server/modules/vouchers/vo-pxh.js +12 -10
- package/server/modules/vouchers/vo-so1.js +90 -116
- package/server/modules/vouchers/vo-so4.js +1 -1
- package/server/modules/vouchers/vo-so5.js +2 -2
- package/server/templates/reset mat khau.html +1 -1
- package/server/templates/reset mat khau.pug +1 -3
- package/server/workers/restoreApp.js +21 -12
- package/server/workers/runScript.js +3 -3
package/server/libs/cdpstk.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';const dktk=require("./dktk"),cktk=require("./cktk"),pstk=require("./pstk"),Account=global.getModel("account"),async=require("async"),underscore=require("underscore"),setBacTKCon=($data$$,$tk_me$$,$bac_tk_me$$)=>{$data$$.filter($d$$=>$d$$.tk_me==$tk_me$$).forEach($tk$$=>{$tk$$.bac_tk=$bac_tk_me$$+1;setBacTKCon($data$$,$tk$$.tk,$tk$$.bac_tk)})};
|
|
2
2
|
module.exports=function($query$$,$fn$$){if(!$query$$.tu_ngay||!$query$$.den_ngay||!$query$$.id_app)return $fn$$(Error("H\u00e0m n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1 tu_ngay,den_ngay,id_app"));$query$$.tk||($query$$.tk="");$query$$.ma_dvcs||($query$$.ma_dvcs="");let $bac_tk$$=$query$$.bac_tk||0;delete $query$$.bac_tk;async.series({dk:function($callback$$){setImmediate(()=>{let $condition$$={};underscore.extend($condition$$,$query$$);$condition$$.ngay=$query$$.tu_ngay;dktk($condition$$,
|
|
3
|
-
function($error$$,$result$$){if($error$$)return $callback$$($error$$);$callback$$(null,$result$$)})})},ps:function($callback$$){setImmediate(()=>{let $condition$$={id_app:$query$$.id_app};$condition$$.tk={$regex:"^"+$query$$.tk,$options:"i"};$condition$$.ma_dvcs={$regex:$query$$.ma_dvcs,$options:"i"};$condition$$.ngay_ct={$gte:$query$$.tu_ngay,$lte:$query$$.den_ngay};$
|
|
3
|
+
function($error$$,$result$$){if($error$$)return $callback$$($error$$);$callback$$(null,$result$$)})})},ps:function($callback$$){setImmediate(()=>{let $condition$$={id_app:$query$$.id_app};$condition$$.tk={$regex:"^"+$query$$.tk,$options:"i"};$condition$$.ma_dvcs={$regex:$query$$.ma_dvcs,$options:"i"};$condition$$.ngay_ct={$gte:$query$$.tu_ngay,$lte:$query$$.den_ngay};$query$$.ma_kho&&($condition$$.ma_kho=$query$$.ma_kho);pstk($condition$$,function($error$$,$result$$){if($error$$)return $callback$$($error$$);
|
|
4
4
|
$callback$$(null,$result$$)})})},ck:function($callback$$){setImmediate(()=>{let $condition$$={};underscore.extend($condition$$,$query$$);$condition$$.ngay=$query$$.den_ngay;cktk($condition$$,function($error$$,$result$$){if($error$$)return $callback$$($error$$);$callback$$(null,$result$$)})})}},function($error$jscomp$1$$,$results$$){if($error$jscomp$1$$)return $fn$$($error$jscomp$1$$);let $data$jscomp$0$$=$results$$.ps;$results$$.dk.forEach(function($r$$){$r$$.dk_no=$r$$.du_no00;$r$$.dk_co=$r$$.du_co00;
|
|
5
5
|
$r$$.dk_no_nt=$r$$.du_no_nt00;$r$$.dk_co_nt=$r$$.du_co_nt00;$data$jscomp$0$$.push($r$$)});$results$$.ck.forEach(function($r$$){$r$$.ck_no=$r$$.du_no00;$r$$.ck_co=$r$$.du_co00;$r$$.ck_no_nt=$r$$.du_no_nt00;$r$$.ck_co_nt=$r$$.du_co_nt00;$data$jscomp$0$$.push($r$$)});$data$jscomp$0$$.groupBy("tk",[{name:"dk_no",value:"dk_no"},{name:"dk_co",value:"dk_co"},{name:"dk_no_nt",value:"dk_no_nt"},{name:"dk_co_nt",value:"dk_co_nt"},{name:"ps_no",value:"ps_no"},{name:"ps_co",value:"ps_co"},{name:"ps_no_nt",value:"ps_no_nt"},
|
|
6
6
|
{name:"ps_co_nt",value:"ps_co_nt"},{name:"ck_no",value:"ck_no"},{name:"ck_co",value:"ck_co"},{name:"ck_no_nt",value:"ck_no_nt"},{name:"ck_co_nt",value:"ck_co_nt"}],function($error$jscomp$0$$,$data$$){let $cdpstkme$$=[];async.mapSeries($data$$,function($acc$$,$callback$$){setImmediate(()=>{$acc$$.loai_tk=1;let $tk$$=$acc$$.tk;async.forever(function($next$$){Account.find({tk:$tk$$,id_app:$query$$.id_app},{tk_me:1},function($error1_vTK$$,$r$$){$r$$&&1==$r$$.length&&$r$$[0].tk_me?($error1_vTK$$={},underscore.extend($error1_vTK$$,
|
package/server/libs/databanle.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
'use strict';const pbl=global.getModel("pbl"),hd2=global.getModel("hd2"),hd3=global.getModel("hd3"),so1=global.getModel("so1"),hd7=global.getModel("hd7"),async=require("async"),trangthai=global.getModel("trangthai"),transaction=global.getModel("transaction");
|
|
2
2
|
module.exports=function($condition$$,$callback$jscomp$0$$){if(!$condition$$.id_app)return $callback$jscomp$0$$("H\u00e0m n\u00e0y y\u00eau c\u1ea7u tham s\u1ed1 id_app");async.series({hd2:$callback$$=>{setImmediate(()=>{!$condition$$.ma_ct||0<=$condition$$.ma_ct.indexOf("HD2")?hd2.find({...$condition$$}).lean().exec(($error$$,$rs$$)=>{if($error$$)return $callback$$($error$$);$rs$$.forEach($v$$=>{$v$$.details.forEach($r$$=>{$r$$.tien_hang_nt=$r$$.tien_nt;$r$$.tien_hang=$r$$.tien_hang_nt*($v$$.ty_gia||
|
|
3
|
-
1);!$r$$.tien_ck_nt&&$r$$.tien_ck?$r$$.tien_ck_nt=$r$$.tien_ck:$r$$.tien_ck=($r$$.tien_ck_nt||0)*($v$$.ty_gia||1);$r$$.tien_nt=$r$$.tien_hang_nt-($r$$.tien_ck_nt||0);$r$$.tien=$r$$.tien_nt*($v$$.ty_gia||1)})});$callback$$(null,$rs$$)}):$callback$$(null,[])})},hd3:$callback$$=>{setImmediate(()=>{if(!$condition$$.ma_ct||0<=$condition$$.ma_ct.indexOf("HD2")){let $_cd$$={...$condition$$}
|
|
4
|
-
$rs$$)})}else $callback$$(null,[])})},pbl:$callback$$=>{setImmediate(()=>{!$condition$$.ma_ct||0<=$condition$$.ma_ct.indexOf("PBL")?pbl.find({...$condition$$}).lean().exec(($error$$,$rs$$)=>{if($error$$)return $callback$$($error$$);$rs$$.forEach($pbl$$=>{$pbl$$.details.forEach($r$$=>{$r$$.tien_hang_nt=$r$$.tien_hang_nt||$r$$.tien_nt;$r$$.tien_hang=$r$$.tien_hang_nt*($pbl$$.ty_gia||
|
|
5
|
-
$r$$.tien_hang_nt-($r$$.tien_ck_nt||0);$r$$.tien=$r$$.tien_nt*($pbl$$.ty_gia||1)})});$callback$$(null,$rs$$)}):$callback$$(null,[])})},so:$callback$$=>{setImmediate(()=>{!$condition$$.ma_ct||0<=$condition$$.ma_ct.indexOf("SO1")?so1.find({...$condition$$}).lean().exec(($error$$,$rs$$)=>{if($error$$)return $callback$$($error$$);$rs$$.forEach($r$$=>{$r$$.ngay_ct=$r$$.ngay_giao_hang
|
|
6
|
-
($r$$.tien_ck_nt||0);$r$$.tien=$r$$.tien_hang-($r$$.tien_ck||0)});$callback$$(null,$rs$$)}):$callback$$(null,[])})},so_tl:$callback$$=>{setImmediate(()=>{if(!$condition$$.ma_ct||0<=$condition$$.ma_ct.indexOf("SO1")){let $_cd$$={...$condition$$};$_cd$$.ngay_tra_lai=$condition$$.ngay_ct;delete $_cd$$.ngay_ct;delete $_cd$$.ma_ct;so1.find($_cd$$).lean().exec(($error
|
|
7
|
-
$r$$.tien;$r$$.tien_hang_nt=$r$$.tien_hang_nt||$r$$.tien_nt;$r$$.tien=$r$$.tien_hang-($r$$.tien_ck||0);$r$$.tien_nt=$r$$.tien_hang_nt-($r$$.tien_ck_nt||0)});$callback$$(null,$rs$$)})}else $callback$$(null,[])})},tl:$callback$$=>{setImmediate(()=>{if(!$condition$$.ma_ct||0<=$condition$$.ma_ct.indexOf("PBL")){let $_cd$$={...$condition$$};delete $_cd$$.ma_ct;
|
|
8
|
-
async($error$$,$rs$$)=>{$error$$&&$callback$jscomp$0$$($error$$);async.series({pbl:$callback$$=>{setImmediate(()=>{$rs$$.pbl.forEach($m$$=>{$m$$.details.filter($d$$=>$d$$.promotion&&$d$$.promotion.details_km).map($d$$=>$d$$.promotion.details_km).reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]).forEach($d$$=>{$d$$.sl_xuat=$d$$.sl_km;$m$$.details.push($d$$)});$m$$.promotion
|
|
9
|
-
{setImmediate(()=>{$rs$$.so.forEach($r$$=>{$r$$.ctcpbhs&&$r$$.ctcpbhs.forEach($c$$=>{$c$$.tien_hang=0;$c$$.tien_hang_nt=0;$c$$.sl_xuat=0;$c$$.tien=$c$$.tien_hang+$c$$.tien_cp;$c$$.tien_nt=$c$$.tien_hang_nt+$c$$.tien_cp_nt;$r$$.details.push($c$$)});$rs$$.pbl.push($r$$)});$callback$$()})},so_tl:$callback$$=>{setImmediate(()=>{$rs$$.so_tl.forEach($r$$=>{"5"
|
|
10
|
-
$d$$.tien_xuat=0;return $d$$}),$r$$.details=[],$rs$$.pbl.push($r$$))});$callback$$()})},hd2:$callback$$=>{setImmediate(()=>{$rs$$.hd2.forEach($r$$=>{$rs$$.pbl.push($r$$)});$rs$$.hd3.forEach($r$jscomp$0$$=>{$r$jscomp$0$$.details_tl=$r$jscomp$0$$.details.
|
|
11
|
-
($r$jscomp$0$$.details_doi=[]);let $t_tien_tl$$=$r$jscomp$0$$.details.csum("tien_hang_nt")-$r$jscomp$0$$.details.csum("tien_ck_nt"),$t_tien_doi$$=$r$jscomp$0$$.details_doi.csum("tien_hang_nt")-$r$jscomp$0$$.details_doi.csum("tien_ck_nt");$r$jscomp$0$$.details_tl=$r$jscomp$0$$.details.map($r$$=>{$t_tien_doi$$&&$t_tien_doi
|
|
12
|
-
{$t_tien_doi$$&&$t_tien_doi$$<=$t_tien_tl$$&&($r$$.tien_hang=0,$r$$.tien_hang_nt=0,$r$$.tien=0,$r$$.tien_nt=0,$r$$.tien_ck=0,$r$$.tien_ck_nt=0);return $r$$});$r$jscomp$0$$.details.forEach($r$$=>{$r$$.tien_hang=$r$$.tien_hang||$r$$.tien;$r$$.tien_hang_nt=$r$$.tien_hang_nt||$r$$.tien_nt;$r$$.tien=$r$$.tien_hang-$r$$.tien_ck
|
|
13
|
-
trangthai,[{where:{trang_thai:"ma_trang_thai",ma_ct:"ma_ct"},fields:["post_sokho","post","post_socai","ten_trang_thai"]}]);$reportData$$=$reportData$$.filter($p$$=>$p$$.post);const $ptthanhtoans$$=(await global.getModel("ptthanhtoan").find({status:!0,id_app:$condition$$.id_app}).lean()).map($pt$$=>{$pt$$.ma=`pttt__${$pt$$._id}`;
|
|
14
|
-
$options:"i"}}).lean();$r$$.bonus_points=$trans$$.filter($tran$$=>$tran$$.receiver.email.toLowerCase()===$r$$.ma_kh.toLowerCase()).map($tran$$=>$tran$$.amount).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$r$$.used_points=$trans$$.filter($tran$$=>$tran$$.sender.email.toLowerCase()===$r$$.ma_kh.toLowerCase()).map($tran
|
|
15
|
-
$r$$.tien_thu||$r$$.tien_con_lai||0);$r$$.pt_thanh_toan2===$pt$$._id.toString()&&($r$$[$pt$$.ma]+=$r$$.tien_thu2||0);$pt$$.tien_thu=$r$$[$pt$$.ma]});$callback$$(null,$r$$)})},()=>{$callback$jscomp$0$$(null,$reportData$$,$ptthanhtoans$$)})})})};
|
|
3
|
+
1);!$r$$.tien_ck_nt&&$r$$.tien_ck?$r$$.tien_ck_nt=$r$$.tien_ck:$r$$.tien_ck=($r$$.tien_ck_nt||0)*($v$$.ty_gia||1);$r$$.tien_nt=$r$$.tien_hang_nt-($r$$.tien_ck_nt||0);$r$$.tien=$r$$.tien_nt*($v$$.ty_gia||1)})});$callback$$(null,$rs$$)}):$callback$$(null,[])})},hd3:$callback$$=>{setImmediate(()=>{if(!$condition$$.ma_ct||0<=$condition$$.ma_ct.indexOf("HD2")){let $_cd$$={...$condition$$};$_cd$$.$or&&$_cd$$.$or.find($o$$=>$o$$.user_nv)&&($_cd$$.details={$elemMatch:{$or:$_cd$$.$or}},delete $_cd$$.$or);
|
|
4
|
+
delete $_cd$$.ma_ct;hd3.find($_cd$$).lean().exec(($error$$,$rs$$)=>{if($error$$)return $callback$$($error$$);$callback$$(null,$rs$$)})}else $callback$$(null,[])})},pbl:$callback$$=>{setImmediate(()=>{!$condition$$.ma_ct||0<=$condition$$.ma_ct.indexOf("PBL")?pbl.find({...$condition$$}).lean().exec(($error$$,$rs$$)=>{if($error$$)return $callback$$($error$$);$rs$$.forEach($pbl$$=>{$pbl$$.details.forEach($r$$=>{$r$$.tien_hang_nt=$r$$.tien_hang_nt||$r$$.tien_nt;$r$$.tien_hang=$r$$.tien_hang_nt*($pbl$$.ty_gia||
|
|
5
|
+
1);!$r$$.tien_ck_nt&&$r$$.tien_ck?$r$$.tien_ck_nt=$r$$.tien_ck:$r$$.tien_ck=($r$$.tien_ck_nt||0)*($pbl$$.ty_gia||1);$r$$.tien_nt=$r$$.tien_hang_nt-($r$$.tien_ck_nt||0);$r$$.tien=$r$$.tien_nt*($pbl$$.ty_gia||1)})});$callback$$(null,$rs$$)}):$callback$$(null,[])})},so:$callback$$=>{setImmediate(()=>{!$condition$$.ma_ct||0<=$condition$$.ma_ct.indexOf("SO1")?so1.find({...$condition$$}).lean().exec(($error$$,$rs$$)=>{if($error$$)return $callback$$($error$$);$rs$$.forEach($r$$=>{$r$$.ngay_ct=$r$$.ngay_giao_hang||
|
|
6
|
+
$r$$.ngay_ct;$r$$.tien_hang_nt=$r$$.tien_hang_nt||$r$$.tien_nt;$r$$.tien_hang=$r$$.tien_hang||$r$$.tien;$r$$.tien_nt=$r$$.tien_hang_nt-($r$$.tien_ck_nt||0);$r$$.tien=$r$$.tien_hang-($r$$.tien_ck||0)});$callback$$(null,$rs$$)}):$callback$$(null,[])})},so_tl:$callback$$=>{setImmediate(()=>{if(!$condition$$.ma_ct||0<=$condition$$.ma_ct.indexOf("SO1")){let $_cd$$={...$condition$$};$_cd$$.ngay_tra_lai=$condition$$.ngay_ct;delete $_cd$$.ngay_ct;delete $_cd$$.ma_ct;so1.find($_cd$$).lean().exec(($error$$,
|
|
7
|
+
$rs$$)=>{if($error$$)return $callback$$($error$$);$rs$$.forEach($r$$=>{$r$$.ngay_ct=$r$$.ngay_tra_lai||$r$$.ngay_ct;$r$$.tien_hang=$r$$.tien_hang||$r$$.tien;$r$$.tien_hang_nt=$r$$.tien_hang_nt||$r$$.tien_nt;$r$$.tien=$r$$.tien_hang-($r$$.tien_ck||0);$r$$.tien_nt=$r$$.tien_hang_nt-($r$$.tien_ck_nt||0)});$callback$$(null,$rs$$)})}else $callback$$(null,[])})},tl:$callback$$=>{setImmediate(()=>{if(!$condition$$.ma_ct||0<=$condition$$.ma_ct.indexOf("PBL")){let $_cd$$={...$condition$$};delete $_cd$$.ma_ct;
|
|
8
|
+
hd7.find($_cd$$).lean().exec(($error$$,$rs$$)=>{if($error$$)return $callback$$($error$$);$callback$$(null,$rs$$)})}else $callback$$(null,[])})}},async($error$$,$rs$$)=>{$error$$&&$callback$jscomp$0$$($error$$);async.series({pbl:$callback$$=>{setImmediate(()=>{$rs$$.pbl.forEach($m$$=>{$m$$.details.filter($d$$=>$d$$.promotion&&$d$$.promotion.details_km).map($d$$=>$d$$.promotion.details_km).reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]).forEach($d$$=>{$d$$.sl_xuat=$d$$.sl_km;$m$$.details.push($d$$)});$m$$.promotion&&
|
|
9
|
+
$m$$.promotion.forEach($p$$=>{$p$$=Object.assign({},$p$$);$p$$.sl_xuat=$p$$.sl_km;$m$$.details.push($p$$)})});$callback$$()})},so:$callback$$=>{setImmediate(()=>{$rs$$.so.forEach($r$$=>{$r$$.ctcpbhs&&$r$$.ctcpbhs.forEach($c$$=>{$c$$.tien_hang=0;$c$$.tien_hang_nt=0;$c$$.sl_xuat=0;$c$$.tien=$c$$.tien_hang+$c$$.tien_cp;$c$$.tien_nt=$c$$.tien_hang_nt+$c$$.tien_cp_nt;$r$$.details.push($c$$)});$rs$$.pbl.push($r$$)});$callback$$()})},so_tl:$callback$$=>{setImmediate(()=>{$rs$$.so_tl.forEach($r$$=>{"5"===
|
|
10
|
+
$r$$.trang_thai&&($r$$.details_tl=Object.assign({},$r$$).details.map($d$$=>{$d$$.sl_nhap=$d$$.sl_xuat;$d$$.sl_xuat=0;$d$$.tien_nhap=$d$$.tien_xuat;$d$$.tien_xuat=0;return $d$$}),$r$$.details=[],$rs$$.pbl.push($r$$))});$callback$$()})},hd2:$callback$$=>{setImmediate(()=>{$rs$$.hd2.forEach($r$$=>{$rs$$.pbl.push($r$$)});$rs$$.hd3.forEach($r$jscomp$0$$=>{$r$jscomp$0$$.details_tl=$r$jscomp$0$$.details.map($r$$=>{$r$$.tien_hang=$r$$.tien;$r$$.tien_hang_nt=$r$$.tien_nt;$r$$.tien=$r$$.tien_hang-$r$$.tien_ck;
|
|
11
|
+
$r$$.tien_nt=$r$$.tien_hang_nt-$r$$.tien_ck_nt;return $r$$});$r$jscomp$0$$.details=[];$rs$$.pbl.push($r$jscomp$0$$)});$rs$$.tl.forEach($r$jscomp$0$$=>{$r$jscomp$0$$.details_doi||($r$jscomp$0$$.details_doi=[]);let $t_tien_tl$$=$r$jscomp$0$$.details.csum("tien_hang_nt")-$r$jscomp$0$$.details.csum("tien_ck_nt"),$t_tien_doi$$=$r$jscomp$0$$.details_doi.csum("tien_hang_nt")-$r$jscomp$0$$.details_doi.csum("tien_ck_nt");$r$jscomp$0$$.details_tl=$r$jscomp$0$$.details.map($r$$=>{$t_tien_doi$$&&$t_tien_doi$$<=
|
|
12
|
+
$t_tien_tl$$&&($r$$.tien_hang=0,$r$$.tien_hang_nt=0,$r$$.tien=0,$r$$.tien_nt=0,$r$$.tien_ck=0,$r$$.tien_ck_nt=0);return $r$$});$r$jscomp$0$$.details=$r$jscomp$0$$.details_doi.map($r$$=>{$t_tien_doi$$&&$t_tien_doi$$<=$t_tien_tl$$&&($r$$.tien_hang=0,$r$$.tien_hang_nt=0,$r$$.tien=0,$r$$.tien_nt=0,$r$$.tien_ck=0,$r$$.tien_ck_nt=0);return $r$$});$r$jscomp$0$$.details.forEach($r$$=>{$r$$.tien_hang=$r$$.tien_hang||$r$$.tien;$r$$.tien_hang_nt=$r$$.tien_hang_nt||$r$$.tien_nt;$r$$.tien=$r$$.tien_hang-$r$$.tien_ck;
|
|
13
|
+
$r$$.tien_nt=$r$$.tien_hang_nt-$r$$.tien_ck_nt});$rs$$.pbl.push($r$jscomp$0$$)});$callback$$()})}},async()=>{let $reportData$$=$rs$$.pbl;await $reportData$$.asyncJoinModel2(null,trangthai,[{where:{trang_thai:"ma_trang_thai",ma_ct:"ma_ct"},fields:["post_sokho","post","post_socai","ten_trang_thai"]}]);$reportData$$=$reportData$$.filter($p$$=>$p$$.post);const $ptthanhtoans$$=(await global.getModel("ptthanhtoan").find({status:!0,id_app:$condition$$.id_app}).lean()).map($pt$$=>{$pt$$.ma=`pttt__${$pt$$._id}`;
|
|
14
|
+
return $pt$$});async.mapSeries($reportData$$,($r$$,$callback$$)=>{setImmediate(async()=>{if($condition$$.show_bonus_points){let $trans$$=await transaction.find({id_ct:{$regex:$r$$._id.toString(),$options:"i"}}).lean();$r$$.bonus_points=$trans$$.filter($tran$$=>$tran$$.receiver.email.toLowerCase()===$r$$.ma_kh.toLowerCase()).map($tran$$=>$tran$$.amount).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$r$$.used_points=$trans$$.filter($tran$$=>$tran$$.sender.email.toLowerCase()===$r$$.ma_kh.toLowerCase()).map($tran$$=>
|
|
15
|
+
$tran$$.amount).reduce(($a$$,$b$$)=>$a$$+$b$$,0)}$r$$.thanh_toan=$ptthanhtoans$$;$r$$.thanh_toan.forEach($pt$$=>{$r$$[$pt$$.ma]=0;$r$$.pt_thanh_toan===$pt$$._id.toString()&&($r$$[$pt$$.ma]+=$r$$.tien_thu||$r$$.tien_con_lai||0);$r$$.pt_thanh_toan2===$pt$$._id.toString()&&($r$$[$pt$$.ma]+=$r$$.tien_thu2||0);$pt$$.tien_thu=$r$$[$pt$$.ma]});$callback$$(null,$r$$)})},()=>{$callback$jscomp$0$$(null,$reportData$$,$ptthanhtoans$$)})})})};
|
package/server/libs/getGiaban.js
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
'use strict';const dmvt=global.getModel("dmvt"),dmgiaban=global.getModel("dmgiaban"),so1=global.getModel("so1"),pbl=global.getModel("pbl"),dmchietkhau=global.getModel("dmchietkhau"),dmkhuyenmai=global.getModel("dmkhuyenmai"),customer=global.getModel("customer"),async=require("async"),underscore=require("underscore"),getSLDaBanCKs=async $items$$=>new Promise(($rs$$,$rj$$)=>{async.mapSeries($items$$,($item$$,$cb$$)=>{setImmediate(async()=>{try{const $details$$=(await so1.find({id_app:$item$$.id_app,
|
|
2
2
|
"details.id_cs":$item$$._id.toString(),trang_thai:{$nin:["9","10","LCT"]}})).map($r$$=>$r$$.details||[]).reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]).filter($a$$=>$a$$.id_cs===$item$$._id.toString());$item$$.sl_da_ban=$details$$.map($r$$=>$item$$.sl_ap_dung?Math.min($r$$.sl_xuat,$item$$.sl_ap_dung):$r$$.sl_xuat).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$item$$.sl_con_lai=Math.max(($item$$.tong_sl_ap_dung||0)-$item$$.sl_da_ban,0);$item$$.sl_ap_dung=$item$$.tong_sl_ap_dung?Math.min($item$$.sl_ap_dung,$item$$.sl_con_lai):
|
|
3
3
|
$item$$.sl_ap_dung;$cb$$(null,$item$$)}catch($e$$){$cb$$($e$$)}})},$e$$=>{if($e$$)return $rj$$($e$$);$rs$$($items$$)})});
|
|
4
|
-
module.exports=async($condition$$,$fn$$)=>{!$condition$$.ma_vt&&$condition$$.vt&&($condition$$.ma_vt=$condition$$.vt.ma_vt);!$condition$$.ma_vt&&$condition$$.vt&&$condition$$.vt._id&&($condition$$.vt=await dmvt.findOne({_id:$condition$$.vt._id},{ma_vt:1,ma_nvt:1,ma_danh_muc:1,gia_ban_le0:1,gia_ban_buon0:1,gia_ban_le:1,gia_ban_buon:1,ty_le_ck0:1,tien_ck0:1}).lean(),$condition$$.vt&&($condition$$.ma_vt=$condition$$.vt.ma_vt));if($condition
|
|
5
|
-
if(!$vt$$||void 0===$vt$$.gia_ban_le||void 0===$vt$$.gia_ban_le0||void 0===$vt$$.ty_le_ck0||void 0===$vt$$.tien_ck0)if($vt$$=await dmvt.findOne({ma_vt:$condition$$.ma_vt,id_app:$condition$$.id_app},{ma_vt:1,ma_nvt:1,ma_danh_muc:1,gia_ban_le0:1,gia_ban_buon0:1,gia_ban_le:1,gia_ban_buon:1,ty_le_ck0:1,tien_ck0:1}).lean(),!$vt$$)return $fn$$("Not found product: "+$condition$$.ma_vt);if($condition$$.ma_tt1){var $
|
|
6
|
-
|
|
7
|
-
$vt$$.gia_ban_le0||$vt$$.gia_ban_le||0,$vt$$.gia_ban_buon0=$
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
ma_kh:$condition$$.ma_kh,trang_thai:{$in:["4","5"]}});($lan_mua_thu$$+=await pbl.countDocuments({id_app:$condition$$.id_app,ma_kh:$condition$$.ma_kh,trang_thai:{$in:["5","6"]}}))||($lan_mua_thu$$=0);$lan_mua_thu$$+=1;!$_cust_den_ngay_hieu_luc_tu$$&&($_cust_den_ngay_hieu_luc_tu$$=await customer.findOne({id_app:$condition$$.id_app,ma_kh:$condition$$.ma_kh}))&&($condition$$.nh_kh=$_cust_den_ngay_hieu_luc_tu$$.nh_kh
|
|
13
|
-
|
|
14
|
-
void 0,""
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
$
|
|
18
|
-
Object.assign({},$
|
|
19
|
-
|
|
4
|
+
module.exports=async($condition$$,$fn$$)=>{!$condition$$.ma_vt&&$condition$$.vt&&($condition$$.ma_vt=$condition$$.vt.ma_vt);$condition$$.so_luong=$condition$$.so_luong||$condition$$.sl_xuat||0;!$condition$$.ma_vt&&$condition$$.vt&&$condition$$.vt._id&&($condition$$.vt=await dmvt.findOne({_id:$condition$$.vt._id},{ma_vt:1,ma_nvt:1,ma_danh_muc:1,gia_ban_le0:1,gia_ban_buon0:1,gia_ban_le:1,gia_ban_buon:1,ty_le_ck0:1,tien_ck0:1}).lean(),$condition$$.vt&&($condition$$.ma_vt=$condition$$.vt.ma_vt));if($condition$$&&
|
|
5
|
+
$condition$$.ma_vt&&$condition$$.id_app){var $vt$$=$condition$$.vt;if(!$vt$$||void 0===$vt$$.gia_ban_le||void 0===$vt$$.gia_ban_le0||void 0===$vt$$.ty_le_ck0||void 0===$vt$$.tien_ck0)if($vt$$=await dmvt.findOne({ma_vt:$condition$$.ma_vt,id_app:$condition$$.id_app},{ma_vt:1,ma_nvt:1,ma_danh_muc:1,gia_ban_le0:1,gia_ban_buon0:1,gia_ban_le:1,gia_ban_buon:1,ty_le_ck0:1,tien_ck0:1}).lean(),!$vt$$)return $fn$$("Not found product: "+$condition$$.ma_vt);if($condition$$.ma_tt1){var $hieu_luc_den_query_tt_query_tt$jscomp$1_query_tt$jscomp$2_tt_tt$jscomp$1_tt$$=
|
|
6
|
+
{id_app:$vt$$.id_app_vt||$condition$$.id_app,ma_vt:$vt$$.ma_vt,status:!0};$hieu_luc_den_query_tt_query_tt$jscomp$1_query_tt$jscomp$2_tt_tt$jscomp$1_tt$$.ma_tt=$condition$$.ma_tt1;$hieu_luc_den_query_tt_query_tt$jscomp$1_query_tt$jscomp$2_tt_tt$jscomp$1_tt$$.loai_tt="1";if($hieu_luc_den_query_tt_query_tt$jscomp$1_query_tt$jscomp$2_tt_tt$jscomp$1_tt$$=await global.getModel("dmtt").findOne($hieu_luc_den_query_tt_query_tt$jscomp$1_query_tt$jscomp$2_tt_tt$jscomp$1_tt$$).lean())$vt$$.gia_ban_le0=$hieu_luc_den_query_tt_query_tt$jscomp$1_query_tt$jscomp$2_tt_tt$jscomp$1_tt$$.gia_ban_le||
|
|
7
|
+
$vt$$.gia_ban_le0||$vt$$.gia_ban_le||0,$vt$$.gia_ban_buon0=$hieu_luc_den_query_tt_query_tt$jscomp$1_query_tt$jscomp$2_tt_tt$jscomp$1_tt$$.gia_ban_buon||$vt$$.gia_ban_buon0||$vt$$.gia_ban_buon||0}else if($condition$$.ma_tt2){if($hieu_luc_den_query_tt_query_tt$jscomp$1_query_tt$jscomp$2_tt_tt$jscomp$1_tt$$={id_app:$vt$$.id_app_vt||$condition$$.id_app,ma_vt:$vt$$.ma_vt,status:!0},$hieu_luc_den_query_tt_query_tt$jscomp$1_query_tt$jscomp$2_tt_tt$jscomp$1_tt$$.ma_tt=$condition$$.ma_tt2,$hieu_luc_den_query_tt_query_tt$jscomp$1_query_tt$jscomp$2_tt_tt$jscomp$1_tt$$.loai_tt=
|
|
8
|
+
"2",$hieu_luc_den_query_tt_query_tt$jscomp$1_query_tt$jscomp$2_tt_tt$jscomp$1_tt$$=await global.getModel("dmtt").findOne($hieu_luc_den_query_tt_query_tt$jscomp$1_query_tt$jscomp$2_tt_tt$jscomp$1_tt$$).lean())$vt$$.gia_ban_le0=$hieu_luc_den_query_tt_query_tt$jscomp$1_query_tt$jscomp$2_tt_tt$jscomp$1_tt$$.gia_ban_le||$vt$$.gia_ban_le0||$vt$$.gia_ban_le||0,$vt$$.gia_ban_buon0=$hieu_luc_den_query_tt_query_tt$jscomp$1_query_tt$jscomp$2_tt_tt$jscomp$1_tt$$.gia_ban_buon||$vt$$.gia_ban_buon0||$vt$$.gia_ban_buon||
|
|
9
|
+
0}else $condition$$.ma_tt3&&($hieu_luc_den_query_tt_query_tt$jscomp$1_query_tt$jscomp$2_tt_tt$jscomp$1_tt$$={id_app:$vt$$.id_app_vt||$condition$$.id_app,ma_vt:$vt$$.ma_vt,status:!0},$hieu_luc_den_query_tt_query_tt$jscomp$1_query_tt$jscomp$2_tt_tt$jscomp$1_tt$$.ma_tt=$condition$$.ma_tt3,$hieu_luc_den_query_tt_query_tt$jscomp$1_query_tt$jscomp$2_tt_tt$jscomp$1_tt$$.loai_tt="3",$hieu_luc_den_query_tt_query_tt$jscomp$1_query_tt$jscomp$2_tt_tt$jscomp$1_tt$$=await global.getModel("dmtt").findOne($hieu_luc_den_query_tt_query_tt$jscomp$1_query_tt$jscomp$2_tt_tt$jscomp$1_tt$$).lean())&&
|
|
10
|
+
($vt$$.gia_ban_le0=$hieu_luc_den_query_tt_query_tt$jscomp$1_query_tt$jscomp$2_tt_tt$jscomp$1_tt$$.gia_ban_le||$vt$$.gia_ban_le0||$vt$$.gia_ban_le||0,$vt$$.gia_ban_buon0=$hieu_luc_den_query_tt_query_tt$jscomp$1_query_tt$jscomp$2_tt_tt$jscomp$1_tt$$.gia_ban_buon||$vt$$.gia_ban_buon0||$vt$$.gia_ban_buon||0);var $_cust_den_ngay_hieu_luc_tu$$;if($condition$$.user&&!$condition$$.ma_kh)try{if($_cust_den_ngay_hieu_luc_tu$$=await customer.findOne({id_app:$condition$$.id_app,of_user:$condition$$.user.email},
|
|
11
|
+
{ma_kh:1,nh_kh:1,nh_kh2:1,nh_kh3:1,nh_kh4:1,nh_kh5:1}).lean())$condition$$.ma_kh=$_cust_den_ngay_hieu_luc_tu$$.ma_kh,$condition$$.nh_kh=$_cust_den_ngay_hieu_luc_tu$$.nh_kh,$condition$$.nh_kh2=$_cust_den_ngay_hieu_luc_tu$$.nh_kh2,$condition$$.nh_kh3=$_cust_den_ngay_hieu_luc_tu$$.nh_kh3,$condition$$.nh_kh4=$_cust_den_ngay_hieu_luc_tu$$.nh_kh4,$condition$$.nh_kh5=$_cust_den_ngay_hieu_luc_tu$$.nh_kh5}catch($e$$){console.log("Error find customer code of user",$e$$)}if($condition$$.ma_kh){var $lan_mua_thu$$=
|
|
12
|
+
await so1.countDocuments({id_app:$condition$$.id_app,ma_kh:$condition$$.ma_kh,trang_thai:{$in:["4","5"]}});($lan_mua_thu$$+=await pbl.countDocuments({id_app:$condition$$.id_app,ma_kh:$condition$$.ma_kh,trang_thai:{$in:["5","6"]}}))||($lan_mua_thu$$=0);$lan_mua_thu$$+=1;!$_cust_den_ngay_hieu_luc_tu$$&&($_cust_den_ngay_hieu_luc_tu$$=await customer.findOne({id_app:$condition$$.id_app,ma_kh:$condition$$.ma_kh},{nh_kh:1,nh_kh2:1,nh_kh3:1,nh_kh4:1,nh_kh5:1}).lean())&&($condition$$.nh_kh=$_cust_den_ngay_hieu_luc_tu$$.nh_kh,
|
|
13
|
+
$condition$$.nh_kh2=$_cust_den_ngay_hieu_luc_tu$$.nh_kh2,$condition$$.nh_kh3=$_cust_den_ngay_hieu_luc_tu$$.nh_kh3,$condition$$.nh_kh4=$_cust_den_ngay_hieu_luc_tu$$.nh_kh4,$condition$$.nh_kh5=$_cust_den_ngay_hieu_luc_tu$$.nh_kh5)}else $lan_mua_thu$$=0;var $query$$={ma_vt:$condition$$.ma_vt,id_app:$condition$$.id_app,status:!0,$and:[]};$query$$.ma_kh={$in:[null,void 0,"",$condition$$.ma_kh]};$query$$.nh_kh={$in:[null,void 0,"",$condition$$.nh_kh]};$query$$.nh_kh2={$in:[null,void 0,"",...($condition$$.nh_kh2||
|
|
14
|
+
[])]};$query$$.nh_kh3={$in:[null,void 0,"",...($condition$$.nh_kh3||[])]};$query$$.nh_kh4={$in:[null,void 0,"",...($condition$$.nh_kh4||[])]};$query$$.nh_kh5={$in:[null,void 0,"",...($condition$$.nh_kh5||[])]};$query$$.ma_kho={$in:[null,void 0,"",$condition$$.ma_kho]};$query$$.ma_ban={$in:[null,void 0,"",$condition$$.ma_ban]};$query$$.ma_tt1={$in:[null,void 0,"",$condition$$.ma_tt1]};$query$$.ma_tt2={$in:[null,void 0,"",$condition$$.ma_tt2]};$query$$.ma_tt3={$in:[null,void 0,"",$condition$$.ma_tt3]};
|
|
15
|
+
$condition$$.ngay_ct=$condition$$.ngay_ct?new Date($condition$$.ngay_ct):new Date;$hieu_luc_den_query_tt_query_tt$jscomp$1_query_tt$jscomp$2_tt_tt$jscomp$1_tt$$=$_cust_den_ngay_hieu_luc_tu$$=$condition$$.ngay_ct;$_cust_den_ngay_hieu_luc_tu$$={$lte:$_cust_den_ngay_hieu_luc_tu$$};$hieu_luc_den_query_tt_query_tt$jscomp$1_query_tt$jscomp$2_tt_tt$jscomp$1_tt$$={$gte:$hieu_luc_den_query_tt_query_tt$jscomp$1_query_tt$jscomp$2_tt_tt$jscomp$1_tt$$};$query$$.hieu_luc_tu=$_cust_den_ngay_hieu_luc_tu$$;$query$$.hieu_luc_den=
|
|
16
|
+
$hieu_luc_den_query_tt_query_tt$jscomp$1_query_tt$jscomp$2_tt_tt$jscomp$1_tt$$;var $sort$$={stt_uu_tien:1,sl_tu:-1,sl_den:-1,id_cs:-1,tien_ck:-1,ty_le_ck:-1,ma_kho:-1,ma_ban:-1,ma_kh:-1,nh_kh:-1,hieu_luc_tu:-1,ma_tt1:-1,ma_tt2:-1,ma_tt3:-1};async.series({giabans:$callback$$=>{setImmediate(()=>{let $_query$$=Object.assign({},$query$$);$_query$$.$and.push({$or:[{ap_dung_lan_mua_tu_thu:{$in:[0,void 0,null]}},{ap_dung_lan_mua_tu_thu:{$lte:$lan_mua_thu$$}}]});$_query$$.$and.push({$or:[{ap_dung_lan_mua_den_thu:{$in:[0,
|
|
17
|
+
void 0,null]}},{ap_dung_lan_mua_den_thu:{$gte:$lan_mua_thu$$}}]});void 0!=$condition$$.online&&($_query$$.online=$condition$$.online);void 0!=$condition$$.offline&&($_query$$.offline=$condition$$.offline);$_query$$.sl_tu={$lte:$condition$$.so_luong};$_query$$.$and.push({$or:[{sl_den:null},{sl_den:0},{sl_den:{$gte:$condition$$.so_luong}}]});dmgiaban.find($_query$$).sort($sort$$).lean().exec(($_q_e$$,$giabans$$)=>{if($_q_e$$)return $callback$$($_q_e$$);0<$giabans$$.length?$callback$$(null,$giabans$$):
|
|
18
|
+
($_q_e$$=Object.assign({},$_query$$),$_q_e$$.ma_vt={$in:["",null,void 0]},$_q_e$$.ma_nvt={$in:["",null,void 0,$vt$$.ma_nvt]},$_q_e$$.ma_danh_muc={$in:["",null,void 0,$vt$$.ma_danh_muc]},dmgiaban.find($_q_e$$).sort($sort$$).lean().exec(($e$$,$giabans$$)=>{if($e$$)return $callback$$($e$$);0===$giabans$$.length&&($giabans$$=[{gia_ban_le:$vt$$.gia_ban_le0||$vt$$.gia_ban_le||0,gia_ban_buon:$vt$$.gia_ban_buon0||$vt$$.gia_ban_buon||0}]);$callback$$(null,$giabans$$)}))})})},discount_vt:$callback$$=>{setImmediate(()=>
|
|
19
|
+
{let $query_ck$$=Object.assign({},$query$$);$query_ck$$.$and.push({$or:[{ap_dung_lan_mua_tu_thu:{$in:[0,void 0,null]}},{ap_dung_lan_mua_tu_thu:{$lte:$lan_mua_thu$$}}]});$query_ck$$.$and.push({$or:[{ap_dung_lan_mua_den_thu:{$in:[0,void 0,null]}},{ap_dung_lan_mua_den_thu:{$gte:$lan_mua_thu$$}}]});$condition$$.sl_xuat&&($query_ck$$.$and.push({$or:[{sl_tu:{$in:[0,void 0,null]}},{sl_tu:{$lte:$condition$$.sl_xuat}}]}),$query_ck$$.$and.push({$or:[{sl_den:{$in:[0,void 0,null]}},{sl_den:{$gte:$condition$$.sl_xuat}}]}));
|
|
20
|
+
$condition$$.t_gt_hd&&($query_ck$$.$and.push({$or:[{gt_hd_tu:{$in:[0,void 0,null]}},{gt_hd_tu:{$lte:$condition$$.t_gt_hd}}]}),$query_ck$$.$and.push({$or:[{gt_hd_den:{$in:[0,void 0,null]}},{gt_hd_den:{$gte:$condition$$.t_gt_hd}}]}));void 0!=$condition$$.online&&($query_ck$$.online=$condition$$.online);void 0!=$condition$$.offline&&($query_ck$$.offline=$condition$$.offline);dmchietkhau.find($query_ck$$).sort($sort$$).lean().exec(async($_q$jscomp$1_e$$,$chietkhaus$$)=>{if($_q$jscomp$1_e$$)return $callback$$($_q$jscomp$1_e$$);
|
|
20
21
|
await getSLDaBanCKs($chietkhaus$$);($chietkhaus$$=$chietkhaus$$.filter($ck$$=>!$ck$$.tong_sl_ap_dung||!$ck$$.sl_da_ban||0<$ck$$.sl_con_lai))&&0<$chietkhaus$$.length?$callback$$(null,$chietkhaus$$):($_q$jscomp$1_e$$=Object.assign({},$query_ck$$),$_q$jscomp$1_e$$.ma_vt={$in:["",null,void 0]},$_q$jscomp$1_e$$.ma_nvt={$in:["",null,void 0,$vt$$.ma_nvt]},$_q$jscomp$1_e$$.ma_danh_muc={$in:["",null,void 0,$vt$$.ma_danh_muc]},dmchietkhau.find($_q$jscomp$1_e$$).sort($sort$$).lean().exec(async($e$$,$chietkhaus$$)=>
|
|
21
22
|
{if($e$$)return $callback$$($e$$);await getSLDaBanCKs($chietkhaus$$);$chietkhaus$$=$chietkhaus$$.filter($ck$$=>!$ck$$.tong_sl_ap_dung||!$ck$$.sl_da_ban||0<$ck$$.sl_con_lai);$callback$$(null,$chietkhaus$$)}))})})},promotion_vt:$callback$$=>{setImmediate(()=>{let $query_ck$$=Object.assign({},$query$$);void 0!=$condition$$.online&&($query_ck$$.online=$condition$$.online);void 0!=$condition$$.offline&&($query_ck$$.offline=$condition$$.offline);let $sort_km$$={stt_uu_tien:1,sl_tu:-1,ma_vt:-1,ma_nvt:-1};
|
|
22
23
|
dmkhuyenmai.find($query_ck$$).sort($sort_km$$).lean().exec(($_q$jscomp$2_e$$,$khuyenmai$$)=>{if($_q$jscomp$2_e$$)return $callback$$($_q$jscomp$2_e$$);$khuyenmai$$&&0<$khuyenmai$$.length?$callback$$(null,$khuyenmai$$):($_q$jscomp$2_e$$=Object.assign({},$query_ck$$),$_q$jscomp$2_e$$.ma_vt={$in:["",null,void 0]},$_q$jscomp$2_e$$.ma_nvt={$in:["",null,void 0,$vt$$.ma_nvt]},$_q$jscomp$2_e$$.ma_danh_muc={$in:["",null,void 0,$vt$$.ma_danh_muc]},dmkhuyenmai.find($_q$jscomp$2_e$$).sort($sort_km$$).lean().exec(($e$$,
|
|
@@ -5,18 +5,18 @@ exports.isAdmin=function($current_id_app$$,$email$$,$callback$$){if(!$current_id
|
|
|
5
5
|
!1);$error$$=await Participant.findOne({id_app:$current_id_app$$,email:$email$$});if(!$error$$)return $callback$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n truy c\u1eadp c\u00f4ng ty n\u00e0y",!1);$callback$$(null,$error$$.admin,$app$$,$error$$)})};
|
|
6
6
|
exports.hasRight=async function($current_id_app$$,$email$$,$module$$,$action$$,$callback$jscomp$0$$,$options$$={}){if(!$current_id_app$$||$options$$.notNeedRight||global.controllers[$module$$]&&global.controllers[$module$$].model&&global.controllers[$module$$].model.schema&&!underscore.has(global.controllers[$module$$].model.schema.paths,"id_app"))return $callback$jscomp$0$$(null,!0);$options$$.data&&($options$$.data.trang_thai||0==$options$$.data.trang_thai)&&($options$$.data.trang_thai=$options$$.data.trang_thai.toString());
|
|
7
7
|
$options$$.obj&&($options$$.obj.trang_thai||0==$options$$.obj.trang_thai)&&($options$$.obj.trang_thai=$options$$.obj.trang_thai.toString());$action$$=$action$$.toLowerCase();var $data_trang_thai$$=$options$$.data||$options$$.obj||{};const $ma_ct$$=(($options$$.obj||{}).ma_ct||($options$$.data||{}).ma_ct||"").toString().toUpperCase();let $ma_trang_thai$$=($data_trang_thai$$.trang_thai||$data_trang_thai$$.progress||"").toString().toUpperCase();!$ma_trang_thai$$&&$options$$.obj&&($ma_trang_thai$$=($options$$.obj.trang_thai||
|
|
8
|
-
$options$$.obj.progress||"").toString().toUpperCase());if($ma_ct$$&&$ma_trang_thai$$)if($data_trang_thai$$=await trangthai.findOne({ma_trang_thai:$ma_trang_thai$$,ma_ct:$ma_ct$$}).lean()){if($data_trang_thai$$.not_need_right)return $callback$jscomp$0$$(null,!0)}else console.log("Khong tim thay trang thai cho chuc nang nay",{ma_ct:$ma_ct$$,ma_trang_thai:$ma_trang_thai$$,trang_thai:$data_trang_thai$$,action:$action$$});exports.isAdmin($current_id_app$$,$email$$,async($
|
|
9
|
-
{if($
|
|
10
|
-
$module$$+'" ch\u01b0a \u0111\u01b0\u1ee3c k\u00edch ho\u1ea1t cho c\u00f4ng ty n\u00e0y (trong module '+$
|
|
11
|
-
|
|
12
|
-
$email$$.toLowerCase())return $callback$jscomp$0$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n truy c\u1eadp \u0111\u1ed1i t\u01b0\u1ee3ng n\u00e0y",!1)}else if(1===$options$$.obj.visible_to&&$options$$.obj.of_user!==$email$$.toLowerCase()&&$options$$.obj.user_created&&$options$$.obj.user_created.toLowerCase()!==$email$$.toLowerCase()&&await exports.nguoiPhuTrach($options$$.obj.id_app
|
|
13
|
-
[]).indexOf($email$$))return $callback$jscomp$0$$("Ch\u1ec9 ng\u01b0\u1eddi t\u1ea1o, ph\u1ee5 tr\u00e1ch, h\u1ed7 tr\u1ee3 v\u00e0 admin m\u1edbi c\u00f3 quy\u1ec1n truy c\u1eadp \u0111\u1ed1i t\u01b0\u1ee3ng n\u00e0y",!1)
|
|
14
|
-
|
|
15
|
-
$_right__right_trang_thai$$&&!$_right__right_trang_thai$$.viewOfOther&&$options$$.obj.user_created.toLowerCase()!==$email$$&&(2!==$options$$.obj.visible_to||!underscore.contains($options$$.obj.visible_to_users,$email$$))&&($error$jscomp$2_user_phu_trach$$=await exports.nguoiPhuTrach($options$$.obj.id_app
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
8
|
+
$options$$.obj.progress||"").toString().toUpperCase());if($ma_ct$$&&$ma_trang_thai$$)if($data_trang_thai$$=await trangthai.findOne({ma_trang_thai:$ma_trang_thai$$,ma_ct:$ma_ct$$}).lean()){if($data_trang_thai$$.not_need_right)return $callback$jscomp$0$$(null,!0)}else console.log("Khong tim thay trang thai cho chuc nang nay",{ma_ct:$ma_ct$$,ma_trang_thai:$ma_trang_thai$$,trang_thai:$data_trang_thai$$,action:$action$$});exports.isAdmin($current_id_app$$,$email$$,async($e_key_right_ms$$,$admin$$,$app$$,
|
|
9
|
+
$participant$$)=>{if($e_key_right_ms$$)return $callback$jscomp$0$$($e_key_right_ms$$,!1);if($app$$&&$app$$.allow_modules&&0<$app$$.allow_modules.length&&($e_key_right_ms$$=await global.getModel("moduleinfo").find({"items.code":{$regex:"^"+$module$$+"$",$options:"i"},active_require:!0}),0<$e_key_right_ms$$.length&&0==$e_key_right_ms$$.filter($m$$=>0<=$app$$.allow_modules.indexOf($m$$.code)&&(!$m$$.not_for_companies||0>$m$$.not_for_companies.indexOf($app$$._id.toString()))&&(!$m$$.only_for_companies||
|
|
10
|
+
0<=$m$$.only_for_companies.indexOf($app$$._id.toString()))).length))return $callback$jscomp$0$$('API "'+$module$$+'" ch\u01b0a \u0111\u01b0\u1ee3c k\u00edch ho\u1ea1t cho c\u00f4ng ty n\u00e0y (trong module '+$e_key_right_ms$$[0].app+"/"+$e_key_right_ms$$[0].title+")",!1);if($options$$.data&&$options$$.data.id_app){if($options$$.data.id_app!=$current_id_app$$)return $callback$jscomp$0$$("B\u1ea1n kh\u00f4ng th\u1ec3 truy c\u1eadp \u0111\u1ed1i t\u01b0\u1ee3ng n\u00e0y",!1);if($options$$.obj&&$options$$.data.id_app!=
|
|
11
|
+
$options$$.obj.id_app)return $callback$jscomp$0$$("B\u1ea1n kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt \u0111\u1ed1i t\u01b0\u1ee3ng n\u00e0y",!1)}if($options$$.obj&&$options$$.obj.id_app&&$options$$.obj.id_app!=$current_id_app$$)return $callback$jscomp$0$$("B\u1ea1n kh\u00f4ng th\u1ec3 truy c\u1eadp \u0111\u1ed1i t\u01b0\u1ee3ng n\u00e0y",!1);if($options$$.notNeedRight)return $callback$jscomp$0$$(null,!0,$app$$);if($options$$.obj&&!$admin$$)if(2===$options$$.obj.visible_to){if(!underscore.contains($options$$.obj.visible_to_users,
|
|
12
|
+
$email$$)&&$options$$.obj.of_user!==$email$$.toLowerCase()&&$options$$.obj.user_created&&$options$$.obj.user_created.toLowerCase()!==$email$$.toLowerCase())return $callback$jscomp$0$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n truy c\u1eadp \u0111\u1ed1i t\u01b0\u1ee3ng n\u00e0y",!1)}else if(1===$options$$.obj.visible_to&&$options$$.obj.of_user!==$email$$.toLowerCase()&&$options$$.obj.user_created&&$options$$.obj.user_created.toLowerCase()!==$email$$.toLowerCase()&&await exports.nguoiPhuTrach($options$$.obj.id_app,
|
|
13
|
+
$options$$.obj.user_created)!=$email$$.toLowerCase()&&$options$$.obj.phu_trach!=$email$$.toLowerCase()&&0>($options$$.obj.attends||[]).indexOf($email$$))return $callback$jscomp$0$$("Ch\u1ec9 ng\u01b0\u1eddi t\u1ea1o, ph\u1ee5 tr\u00e1ch, h\u1ed7 tr\u1ee3 v\u00e0 admin m\u1edbi c\u00f3 quy\u1ec1n truy c\u1eadp \u0111\u1ed1i t\u01b0\u1ee3ng n\u00e0y",!1);$e_key_right_ms$$=$email$$;$participant$$&&$participant$$.group_id&&($e_key_right_ms$$=$participant$$.group_id.toLowerCase());right.findOne({id_app:$current_id_app$$,
|
|
14
|
+
email:$e_key_right_ms$$,module:$module$$.toLowerCase()},async function($error$jscomp$2_user_phu_trach$$,$_right__right_trang_thai$$){if($error$jscomp$2_user_phu_trach$$)return $callback$jscomp$0$$($error$jscomp$2_user_phu_trach$$,!1);if(!$admin$$){if(!$_right__right_trang_thai$$)return global.modulesInMenu[$module$$]||"view"!==$action$$&&("add"!==$action$$||"group"!==$module$$.toLowerCase())?$callback$jscomp$0$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n \u0111\u1ed1i v\u1edbi t\u00ednh n\u0103ng n\u00e0y",
|
|
15
|
+
!1):$callback$jscomp$0$$(null,!0,$app$$);if(!$_right__right_trang_thai$$[$action$$])return $callback$jscomp$0$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n \u0111\u1ed1i v\u1edbi t\u00ednh n\u0103ng n\u00e0y",!1);if($options$$.obj&&$_right__right_trang_thai$$&&!$_right__right_trang_thai$$.viewOfOther&&$options$$.obj.user_created.toLowerCase()!==$email$$&&(2!==$options$$.obj.visible_to||!underscore.contains($options$$.obj.visible_to_users,$email$$))&&($error$jscomp$2_user_phu_trach$$=await exports.nguoiPhuTrach($options$$.obj.id_app,
|
|
16
|
+
$options$$.obj.user_created),$options$$.obj.phu_trach!==$email$$&&$error$jscomp$2_user_phu_trach$$!=$email$$&&0>($options$$.obj.attends||[]).indexOf($email$$)))return $callback$jscomp$0$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n truy c\u1eadp \u0111\u1ed1i t\u01b0\u1ee3ng n\u00e0y",!1);if($ma_trang_thai$$&&($_right__right_trang_thai$$=$_right__right_trang_thai$$[`${$action$$}_trang_thai`])&&!$_right__right_trang_thai$$[$ma_trang_thai$$]&&void 0!=$_right__right_trang_thai$$[$ma_trang_thai$$])return $callback$jscomp$0$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n \u0111\u1ed1i v\u1edbi tr\u1ea1ng th\u00e1i ch\u1ee9ng t\u1eeb n\u00e0y",
|
|
17
|
+
!1)}$options$$.obj?async.series({trangthai:$callback$$=>{$options$$.obj&&("update"===$action$$||"delete"===$action$$)&&$options$$.obj.ma_ct?trangthai.findOne({ma_ct:$options$$.obj.ma_ct.toUpperCase(),ma_trang_thai:$options$$.obj.trang_thai},function($e$$,$trang_thai$$){if($e$$)return $callback$$($e$$);if($trang_thai$$){if("update"===$action$$){if(0==$trang_thai$$.allow_update)return $callback$$("Tr\u1ea1ng th\u00e1i ch\u1ee9ng t\u1eeb n\u00e0y kh\u00f4ng cho ph\u00e9p s\u1eeda");if(1==$trang_thai$$.lock_data)return $callback$$("Tr\u1ea1ng th\u00e1i ch\u1ee9ng t\u1eeb n\u00e0y \u0111\u00e3 \u0111\u01b0\u1ee3c kho\u00e1")}if("delete"===
|
|
18
|
+
$action$$&&($trang_thai$$.lock_data||0==$trang_thai$$.allow_delete))return $callback$$("Tr\u1ea1ng th\u00e1i ch\u1ee9ng t\u1eeb n\u00e0y kh\u00f4ng cho ph\u00e9p xo\u00e1")}return $callback$$()}):$callback$$()}},$action_right_e$$=>{if($action_right_e$$)$callback$jscomp$0$$($action_right_e$$,!1);else{$action_right_e$$=`${$action$$}_right`;if(!$admin$$&&$options$$.obj&&$options$$.obj[$action_right_e$$]&&0<$options$$.obj[$action_right_e$$].length&&0>$options$$.obj[$action_right_e$$].indexOf($email$$.toLowerCase()))return $callback$jscomp$0$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n \u0111\u1ed1i v\u1edbi t\u00ednh n\u0103ng n\u00e0y",
|
|
19
|
+
!1);$callback$jscomp$0$$(null,!0,$app$$)}}):$callback$jscomp$0$$(null,!0,$app$$)})},$options$$)};
|
|
20
20
|
exports.getRightByItem=function($id_app$$,$model$$,$email$$,$next$$,$module$$,$options$$={}){exports.isAdmin($id_app$$,$email$$,async function($e$jscomp$3_key_right$$,$admin$$,$app$$,$participant$$){if($e$jscomp$3_key_right$$)return $next$$($e$jscomp$3_key_right$$);let $condition$$={};$module$$||($module$$=$model$$&&$model$$.collection&&$model$$.collection.name&&1<$model$$.collection.name.length?$model$$.collection.name.substr(0,$model$$.collection.name.length-1).toLowerCase():"");if($admin$$||$options$$.notNeedRight||
|
|
21
21
|
!underscore.has($model$$.schema.paths,"id_app"))$next$$(null,$condition$$,$admin$$);else{let $allUsers$$,$selUsers$$,$selGroups$$,$visible$$=[],$allow_trang_thai$$;$e$jscomp$3_key_right$$=$email$$;$participant$$&&$participant$$.group_id&&($e$jscomp$3_key_right$$=$participant$$.group_id.toLowerCase());right.findOne({id_app:$id_app$$,email:$e$jscomp$3_key_right$$,module:$module$$},async function($ds_dang_phu_trach_error$$,$_right$jscomp$1_users$$){if($_right$jscomp$1_users$$&&$_right$jscomp$1_users$$.view){$ds_dang_phu_trach_error$$=
|
|
22
22
|
{visible_to:null};underscore.has($model$$.schema.paths,"visible_to")&&($condition$$.$and||($condition$$.$and=[]),$allUsers$$={visible_to:0},$selUsers$$={visible_to:2,visible_to_users:$email$$},$selGroups$$=underscore.has($model$$.schema.paths,"visible_to_usergroups")?{visible_to:5,visible_to_usergroups:($participant$$||{}).group_id}:{visible_to:5,visible_to_users:($participant$$||{}).group_id},$visible$$.push($allUsers$$),$visible$$.push($selUsers$$),$visible$$.push($selGroups$$),$visible$$.push($ds_dang_phu_trach_error$$));
|
package/server/libs/post-book.js
CHANGED
|
@@ -8,11 +8,12 @@ post.prototype.run=async function($callback$$=()=>{}){if(!this.details)return co
|
|
|
8
8
|
{_id:1,tat_toan:1}).lean(),0<$rs$jscomp$2_tdtts_tdtts$$.length)){if(0<$rs$jscomp$2_tdtts_tdtts$$.filter($t$$=>$t$$.tat_toan).length)return $callback$$(null);$rs$jscomp$2_tdtts_tdtts$$=$rs$jscomp$2_tdtts_tdtts$$.map($t$$=>$t$$._id.toString());if(await global.getModel("tdttno_tt").findOne({id_tdtt:{$in:$rs$jscomp$2_tdtts_tdtts$$}}))return $callback$$(null)}"tdttco_tt"===$model_book$$.modelName.toLowerCase()&&await Promise.all($details$$.filter($d$$=>$d$$.id_hd&&$d$$.id_tdtt).map($detail$$=>(async()=>
|
|
9
9
|
{let $tdtt$$=await global.getModel("tdttco").findOne({_id:$detail$$.id_tdtt},{_id:1}).lean();!$tdtt$$&&($tdtt$$=await global.getModel("tdttco").findOne({id_ct:$detail$$.id_hd},{_id:1}).lean())&&($detail$$.id_tdtt=$tdtt$$._id.toString())})()));"tdttno_tt"===$model_book$$.modelName.toLowerCase()&&await Promise.all($details$$.filter($d$$=>$d$$.id_hd&&$d$$.id_tdtt).map($detail$$=>(async()=>{let $tdtt$$=await global.getModel("tdttno").findOne({_id:$detail$$.id_tdtt},{_id:1}).lean();!$tdtt$$&&($tdtt$$=
|
|
10
10
|
await global.getModel("tdttno").findOne({id_ct:$detail$$.id_hd},{_id:1}).lean())&&($detail$$.id_tdtt=$tdtt$$._id.toString())})()));if("sokho"===$model_book$$.modelName.toLowerCase()||"sokhott"===$model_book$$.modelName.toLowerCase())await $details$$.asyncJoinModel2($master$$.id_app,Dmvt,{where:"ma_vt",fields:"tg_tk"}),$details$$=$details$$.filter($d$$=>$d$$.tg_tk),await $details$$.asyncJoinModel2($master$$.id_app,global.getModel("dmqddvt"),{where:{ma_vt:"ma_vt",ma_dvt:"ma_dvt"},fields:["tu","mau",
|
|
11
|
-
{he_so_qd:"ty_le_qd"}]}),$details$$.forEach($detail$$=>{$detail$$.he_so_qd=$detail$$.he_so_qd||1;$detail$$.mau&&$detail$$.tu?($detail$$.he_so_qd=$detail$$.tu/$detail$$.mau,$detail$$.sl_xuat_qd=utils.round(($detail$$.sl_xuat||0)*$detail$$.tu/$detail$$.mau,round),$detail$$.sl_nhap_qd=utils.round(($detail$$.sl_nhap||0)*$detail$$.tu/$detail$$.mau,round)):($detail$$.sl_xuat_qd=($detail$$.sl_xuat||0)*$detail$$.he_so_qd,$detail$$.sl_nhap_qd=($detail$$.sl_nhap||
|
|
12
|
-
|
|
13
|
-
utils.round(($detail$$.sl_xuat||0)*$detail$$.tu/$detail$$.mau,round),$detail$$.sl_nhap_qd=utils.round(($detail$$.sl_nhap||0)*$detail$$.tu/$detail$$.mau,round)):($detail$$.sl_xuat_qd=utils.round(($detail$$.sl_xuat||0)*$detail$$.he_so_qd,round),$detail$$.sl_nhap_qd=utils.round(($detail$$.sl_nhap||0)*$detail$$.he_so_qd,round))}));if("vatra"===$model_book$$.modelName.toLowerCase()||"vatvao"===$model_book$$.modelName.toLowerCase())if($rs$jscomp$2_tdtts_tdtts$$=
|
|
14
|
-
$r$$.so_hd&&$r$$.so_hd.toUpperCase()!==($master$$.ma_ct||"").toUpperCase()).map($detail$$=>(async()=>{let $v$$=await $model_book$$.findOne({id_app:$master$$.id_app,so_hd:$detail$$.so_hd,ma_kh:$detail$$.ma_kh||$master$$.ma_kh,so_seri:$detail$$.so_seri,ky_hieu_hoa_don:$detail$$.ky_hieu_hoa_don,id_ct:{$ne:$master$$._id.toString()}});return $v$$?$v$$.so_hd:""})())),$rs$jscomp$2_tdtts_tdtts$$=$rs$jscomp$2_tdtts_tdtts$$.filter($r$$=>$r$$),0<$rs$jscomp$2_tdtts_tdtts$$.length)return $callback$$(`S\u1ed1 ho\u00e1 \u0111\u01a1n ${$rs$jscomp$2_tdtts_tdtts$$.join(",")} \u0111\u00e3 t\u1ed3n t\u1ea1i`);
|
|
15
|
-
$details$$=$details$$.map(($detail$$,$line$$)=>{$detail$$.id_ct=$master$$._id.toString();for(let $attr$$ in $model_book$$.schema.paths)if("id_ct"!=$attr$$&&"_id"!=$attr$$&&"__v"!=$attr$$){let $v$$=$detail$$[$attr$$];void 0!==$v$$&&null!==$v$$&&""!==$v$$||0===$v$$||void 0===$master$$[$attr$$]||($detail$$[$attr$$]=$master$$[$attr$$])}$detail$$.line=$line$$;delete $detail$$.toObject;delete $detail$$._id;
|
|
16
|
-
$error$$),$callback$$($error$$);if(0==$details$$.length)return $callback$$(null,[]);$model_book$$.create($details$$,async($e$jscomp$0$$,$rs$$)=>{if($e$jscomp$0$$){var $contr_msg_error$$=$e$jscomp$0$$.message||$e$jscomp$0$$.error||$e$jscomp$0$$.toString();0<=$contr_msg_error$$.indexOf("E11000 duplicate")&&
|
|
17
|
-
$details$$),$self$$.remove(()=>{$callback$$($e$jscomp$0$$)}))):(console.error("error save data post",$e$jscomp$0$$,$details$$),$self$$.remove(()=>{$callback$$($e$jscomp$0$$)}))}else
|
|
18
|
-
|
|
11
|
+
{he_so_qd:"ty_le_qd"}]}),$details$$.forEach($detail$$=>{$detail$$.ma_kho=$detail$$.ma_kho||$master$$.ma_kho;$detail$$.he_so_qd=$detail$$.he_so_qd||1;$detail$$.mau&&$detail$$.tu?($detail$$.he_so_qd=$detail$$.tu/$detail$$.mau,$detail$$.sl_xuat_qd=utils.round(($detail$$.sl_xuat||0)*$detail$$.tu/$detail$$.mau,round),$detail$$.sl_nhap_qd=utils.round(($detail$$.sl_nhap||0)*$detail$$.tu/$detail$$.mau,round)):($detail$$.sl_xuat_qd=($detail$$.sl_xuat||0)*$detail$$.he_so_qd,$detail$$.sl_nhap_qd=($detail$$.sl_nhap||
|
|
12
|
+
0)*$detail$$.he_so_qd)});"sokhokhongton"===$model_book$$.modelName.toLowerCase()&&(await $details$$.asyncJoinModel2($master$$.id_app,Dmvt,{where:"ma_vt",fields:"tg_tk"}),$details$$=$details$$.filter($d$$=>0==$d$$.tg_tk),await $details$$.asyncJoinModel2($master$$.id_app,global.getModel("dmqddvt"),{where:{ma_vt:"ma_vt",ma_dvt:"ma_dvt"},fields:["tu","mau",{he_so_qd:"ty_le_qd"}]}),$details$$.forEach($detail$$=>{$detail$$.ma_kho=$detail$$.ma_kho||$master$$.ma_kho;$detail$$.he_so_qd=$detail$$.he_so_qd||
|
|
13
|
+
1;$detail$$.mau&&$detail$$.tu?($detail$$.he_so_qd=$detail$$.tu/$detail$$.mau,$detail$$.sl_xuat_qd=utils.round(($detail$$.sl_xuat||0)*$detail$$.tu/$detail$$.mau,round),$detail$$.sl_nhap_qd=utils.round(($detail$$.sl_nhap||0)*$detail$$.tu/$detail$$.mau,round)):($detail$$.sl_xuat_qd=utils.round(($detail$$.sl_xuat||0)*$detail$$.he_so_qd,round),$detail$$.sl_nhap_qd=utils.round(($detail$$.sl_nhap||0)*$detail$$.he_so_qd,round))}));if("vatra"===$model_book$$.modelName.toLowerCase()||"vatvao"===$model_book$$.modelName.toLowerCase())if($rs$jscomp$2_tdtts_tdtts$$=
|
|
14
|
+
await Promise.all($details$$.filter($r$$=>$r$$.so_hd&&$r$$.so_hd.toUpperCase()!==($master$$.ma_ct||"").toUpperCase()).map($detail$$=>(async()=>{let $v$$=await $model_book$$.findOne({id_app:$master$$.id_app,so_hd:$detail$$.so_hd,ma_kh:$detail$$.ma_kh||$master$$.ma_kh,so_seri:$detail$$.so_seri,ky_hieu_hoa_don:$detail$$.ky_hieu_hoa_don,id_ct:{$ne:$master$$._id.toString()}});return $v$$?$v$$.so_hd:""})())),$rs$jscomp$2_tdtts_tdtts$$=$rs$jscomp$2_tdtts_tdtts$$.filter($r$$=>$r$$),0<$rs$jscomp$2_tdtts_tdtts$$.length)return $callback$$(`S\u1ed1 ho\u00e1 \u0111\u01a1n ${$rs$jscomp$2_tdtts_tdtts$$.join(",")} \u0111\u00e3 t\u1ed3n t\u1ea1i`);
|
|
15
|
+
$details$$=$details$$.map(($detail$$,$line$$)=>{$detail$$.id_ct=$master$$._id.toString();$detail$$.ma_ct=$master$$.ma_ct;$detail$$.so_ct=$master$$.so_ct;$detail$$.ngay_ct=$master$$.ngay_ct;for(let $attr$$ in $model_book$$.schema.paths)if("id_ct"!=$attr$$&&"_id"!=$attr$$&&"__v"!=$attr$$){let $v$$=$detail$$[$attr$$];void 0!==$v$$&&null!==$v$$&&""!==$v$$||0===$v$$||void 0===$master$$[$attr$$]||($detail$$[$attr$$]=$master$$[$attr$$])}$detail$$.line=$line$$;delete $detail$$.toObject;delete $detail$$._id;
|
|
16
|
+
delete $detail$$.__v;return $detail$$});const $self$$=this;$self$$.remove($error$$=>{if($error$$)return console.error("error delete data post",$error$$),$callback$$($error$$);if(0==$details$$.length)return $callback$$(null,[]);$model_book$$.create($details$$,async($e$jscomp$0$$,$rs$$)=>{if($e$jscomp$0$$){console.error("\u0110\u00e3 c\u00f3 l\u1ed7i khi postdata",$e$jscomp$0$$);var $contr_msg_error$$=$e$jscomp$0$$.message||$e$jscomp$0$$.error||$e$jscomp$0$$.toString();0<=$contr_msg_error$$.indexOf("E11000 duplicate")&&
|
|
17
|
+
0<=$contr_msg_error$$.indexOf("id_ct_1_line_1")?($rs$$=await $model_book$$.find({id_ct:$master$$._id.toString()}),0<$rs$$.length?$callback$$(null,$rs$$):(console.error("error save data post",$e$jscomp$0$$,$details$$),$self$$.remove(()=>{$callback$$($e$jscomp$0$$)}))):(console.error("error save data post",$e$jscomp$0$$,$details$$),$self$$.remove(()=>{$callback$$($e$jscomp$0$$)}))}else $master$$.ma_ct?($contr_msg_error$$=global.controllers[$master$$.ma_ct.toUpperCase()])?await $contr_msg_error$$.model.findById($master$$._id)?
|
|
18
|
+
$callback$$(null,$rs$$):(console.error("Ch\u1ee9ng t\u1eeb kh\u00f4ng t\u1ed3n t\u1ea1i. X\u00f3a s\u1ed5 s\u00e1ch",$master$$._id),$self$$.remove(()=>{$callback$$("Ch\u1ee9ng t\u1eeb kh\u00f4ng t\u1ed3n t\u1ea1i")})):(console.log("not found controller",$master$$.ma_ct.toUpperCase()),$callback$$(null,$rs$$)):$callback$$(null,$rs$$),$rs$$&&"sokho"===$model_book$$.modelName.toLowerCase()&&setImmediate(()=>{tontucthoi.tinhTonTucThoi($rs$$,$e$$=>{$e$$&&console.error("L\u1ed7i t\u00ednh t\u1ed3n t\u1ee9c th\u1eddi v\u1eadt t\u01b0",
|
|
19
|
+
$rs$$,$e$$)})})})})};module.exports=post;
|
|
@@ -10,12 +10,12 @@ $callback$$()}):$callback$$()})},tk_co:$callback$$=>{checkAcc($id_app$$,$_data$$
|
|
|
10
10
|
0<$du_co$jscomp$1_e$$?$callback$$(`T\u00e0i kho\u1ea3n ${$_data$$.tk_co} kh\u00f4ng \u0111\u01b0\u1ee3c ph\u00e9p c\u00f3 s\u1ed1 d\u01b0 b\u00ean c\u00f3: ${$du_co$jscomp$1_e$$}`):$callback$$()}):$callback$$()})}},$e$$=>{$callback$jscomp$0$$($e$$,$_data$$)})},post=function($master$$,$details$$,$prepare$$,$model$$=SocaiModel){$details$$&&(this.master={...$master$$},this.details=$details$$.map($detail$$=>({...$detail$$})),this.model=$model$$,this.prepare=$prepare$$)};
|
|
11
11
|
post.prototype.runPrepare=async($prepare$$,$details$jscomp$0$$)=>{$details$jscomp$0$$=$details$jscomp$0$$.map($d$$=>{$d$$.toObject&&($d$$=$d$$.toObject());return{...$d$$}});return new Promise($resolve$$=>{$prepare$$?async.mapSeries($details$jscomp$0$$,($detail$jscomp$0$$,$callback$$)=>{setImmediate(()=>{$detail$jscomp$0$$.toObject=function(){return Object.assign({},$detail$jscomp$0$$)};$prepare$$($detail$jscomp$0$$,$detail$$=>{$detail$$.toObject=function(){return Object.assign({},$detail$$)};$callback$$(null,
|
|
12
12
|
$detail$$)})})},($e$$,$details$$)=>{$resolve$$($details$$)}):$resolve$$($details$jscomp$0$$)})};
|
|
13
|
-
post.prototype.run=async function($callback$jscomp$0$$=()=>{}){if(!this.details)return $callback$jscomp$0$$(null,null);const $Socai$$=this.model||SocaiModel;let $master$$=this.master,$details$jscomp$0$$=await this.runPrepare(this.prepare,this.details);$details$jscomp$0$$.forEach($d$$=>{$d$$.tk_no=$d$$.tk_no||$master$$.tk_no;$d$$.tk_co=$d$$.tk_co||$master$$.tk_co});$details$jscomp$0$$=$details$jscomp$0$$.filter($d
|
|
14
|
-
let $check_hmcn$$=$details$jscomp$0$$.map($d$$=>[{tk:$d$$.tk_no,tien:$d$$.tien,ma_kh:$d$$.ma_kh_no||$d$$.ma_kh||$master$$.ma_kh},{tk:$d$$.tk_co,tien:0-$d$$.tien,ma_kh:$d$$.ma_kh_co||$d$$.ma_kh||$master$$.ma_kh}]).reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]).filter($a$$=>$a$$.ma_kh&&$a$$.tien);$check_hmcn$$=await $check_hmcn$$.asyncGroupBy(["tk","ma_kh"],["tien"]);if(0<$check_hmcn$$.length)try{await Promise.all($check_hmcn$$.map($d$$=>
|
|
15
|
-
$e$$.error||$e$$)}async.mapSeries($details$jscomp$0$$,($detail$jscomp$0$$,$callback$$)=>{setImmediate(()=>{$detail$jscomp$0$$.ma_kh_no||($detail$jscomp$0$$.ma_kh_no=$detail$jscomp$0$$.ma_kh||$master$$.ma_kh);$detail$jscomp$0$$.ma_kh_co||($detail$jscomp$0$$.ma_kh_co=$detail$jscomp$0$$.ma_kh||$master$$.ma_kh);checkData($master$$.id_app,$master$$.ngay_ct,$detail$jscomp$0$$,
|
|
16
|
-
$but_toan_loi_e$$=$details$$.filter($detail$$=>isNaN($detail$$.tien_nt)||isNaN($detail$$.tien));0<$but_toan_loi_e$$.length&&console.error("Cac but toan khong hop ly",$but_toan_loi_e$$,"cua chung tu",$master$$._id);let $dks$$=$details$$.filter($detail$$=>!(0===$detail$$.tien_nt&&0===$detail$$.tien)&&!isNaN($detail$$.tien_nt)&&!isNaN($detail$$.tien)).map(($detail
|
|
17
|
-
$detail$$[$attr$$]&&""!==$detail$$[$attr$$]||0===$detail$$[$attr$$]||void 0===$master$$[$attr$$]||($detail$$[$attr$$]=$master$$[$attr$$]));$detail$$.nh_dk=$nh_dk$$;$detail$$.id_ct=$master$$._id.toString();delete $detail$$.toObject;delete $detail$$._id;delete $detail$$.__v;return $detail$$});$Socai$$.deleteMany({id_ct:$master$$._id.toString()},$error$$=>{if($error$$)return $callback$jscomp$0$$("Don't remove socai \n"
|
|
18
|
-
async($e$$,$msg_error_rs$$)=>{if($e$$)if($msg_error_rs$$=$e$$.message||$e$$.error||$e$$.toString(),0<=$msg_error_rs$$.indexOf("E11000 duplicate")&&0<=$msg_error_rs$$.indexOf("id_ct_1_nh_dk_1"))if($msg_error_rs$$=await $Socai$$.find({id_ct:$master$$._id.toString()}),0<$msg_error_rs$$.length)$callback$jscomp$0$$(null,$msg_error_rs$$);else{console.error("Error save socai",$e$$,$master$$);let $q_remove$$={id_app:$master$$.id_app,
|
|
19
|
-
{console.error("delete socai because error when posting",$master$$._id.toString(),JSON.stringify($rs$$),$q_remove$$);$callback$jscomp$0$$($e$$)})}else{console.error("Error save socai",$e$$,$master$$);let $q_remove$$={id_app:$master$$.id_app,id_ct:$master$$._id.toString()};$Socai$$.deleteMany($q_remove$$,($_e$$,$rs$$)=>{console.error("delete socai because error when posting",$master$$._id.toString(),JSON.stringify($rs$$)
|
|
20
|
-
global.controllers[$master$$.ma_ct.toUpperCase()];$contr$$?await $contr$$.model.findById($master$$._id)?$callback$jscomp$0$$(null,$msg_error_rs$$):$Socai$$.deleteMany({id_ct:$master$$._id.toString()},($_e$$,$rs$$)=>{console.error("Ch\u1ee9ng t\u1eeb kh\u00f4ng t\u1ed3n t\u1ea1i. X\u00f3a socai",$master$$._id,$rs$$);$callback$jscomp$0$$($e$$)}):(console.log("not found controller",$master$$.ma_ct.toUpperCase()),$callback$jscomp$0$$(null
|
|
21
|
-
module.exports=post;
|
|
13
|
+
post.prototype.run=async function($callback$jscomp$0$$=()=>{}){if(!this.details)return $callback$jscomp$0$$(null,null);const $Socai$$=this.model||SocaiModel;let $master$$=this.master,$details$jscomp$0$$=await this.runPrepare(this.prepare,this.details);$details$jscomp$0$$.forEach($d$$=>{$d$$.tk_no=$d$$.tk_no||$master$$.tk_no;$d$$.tk_co=$d$$.tk_co||$master$$.tk_co;$d$$.ma_ct=$master$$.ma_ct;$d$$.so_ct=$master$$.so_ct;$d$$.ngay_ct=$master$$.ngay_ct});$details$jscomp$0$$=$details$jscomp$0$$.filter($d$$=>
|
|
14
|
+
$d$$.tk_no&&$d$$.tk_co);if(!$master$$.ngay_ct)return $callback$jscomp$0$$("ngay_ct is not null");let $check_hmcn$$=$details$jscomp$0$$.map($d$$=>[{tk:$d$$.tk_no,tien:$d$$.tien,ma_kh:$d$$.ma_kh_no||$d$$.ma_kh||$master$$.ma_kh},{tk:$d$$.tk_co,tien:0-$d$$.tien,ma_kh:$d$$.ma_kh_co||$d$$.ma_kh||$master$$.ma_kh}]).reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]).filter($a$$=>$a$$.ma_kh&&$a$$.tien);$check_hmcn$$=await $check_hmcn$$.asyncGroupBy(["tk","ma_kh"],["tien"]);if(0<$check_hmcn$$.length)try{await Promise.all($check_hmcn$$.map($d$$=>
|
|
15
|
+
asyncCheckHMCN($master$$.id_app,$master$$,$d$$.tk,$d$$.ma_kh,$d$$.tien)))}catch($e$$){return $callback$jscomp$0$$($e$$.message||$e$$.error||$e$$)}async.mapSeries($details$jscomp$0$$,($detail$jscomp$0$$,$callback$$)=>{setImmediate(()=>{$detail$jscomp$0$$.ma_kh_no||($detail$jscomp$0$$.ma_kh_no=$detail$jscomp$0$$.ma_kh||$master$$.ma_kh);$detail$jscomp$0$$.ma_kh_co||($detail$jscomp$0$$.ma_kh_co=$detail$jscomp$0$$.ma_kh||$master$$.ma_kh);checkData($master$$.id_app,$master$$.ngay_ct,$detail$jscomp$0$$,
|
|
16
|
+
($e$$,$detail$$)=>{$callback$$($e$$,$detail$$)})})},($but_toan_loi_e$$,$details$$)=>{if($but_toan_loi_e$$)return $callback$jscomp$0$$($but_toan_loi_e$$);$but_toan_loi_e$$=$details$$.filter($detail$$=>isNaN($detail$$.tien_nt)||isNaN($detail$$.tien));0<$but_toan_loi_e$$.length&&console.error("Cac but toan khong hop ly",$but_toan_loi_e$$,"cua chung tu",$master$$._id);let $dks$$=$details$$.filter($detail$$=>!(0===$detail$$.tien_nt&&0===$detail$$.tien)&&!isNaN($detail$$.tien_nt)&&!isNaN($detail$$.tien)).map(($detail$$,
|
|
17
|
+
$nh_dk$$)=>{for(let $attr$$ in $Socai$$.schema.paths)"id_ct"!=$attr$$&&"_id"!=$attr$$&&"__v"!=$attr$$&&(void 0!==$detail$$[$attr$$]&&null!==$detail$$[$attr$$]&&""!==$detail$$[$attr$$]||0===$detail$$[$attr$$]||void 0===$master$$[$attr$$]||($detail$$[$attr$$]=$master$$[$attr$$]));$detail$$.nh_dk=$nh_dk$$;$detail$$.id_ct=$master$$._id.toString();delete $detail$$.toObject;delete $detail$$._id;delete $detail$$.__v;return $detail$$});$Socai$$.deleteMany({id_ct:$master$$._id.toString()},$error$$=>{if($error$$)return $callback$jscomp$0$$("Don't remove socai \n"+
|
|
18
|
+
$error$$);if(0==$dks$$.length)return $callback$jscomp$0$$(null,[]);$Socai$$.create($dks$$,async($e$$,$msg_error_rs$$)=>{if($e$$)if($msg_error_rs$$=$e$$.message||$e$$.error||$e$$.toString(),0<=$msg_error_rs$$.indexOf("E11000 duplicate")&&0<=$msg_error_rs$$.indexOf("id_ct_1_nh_dk_1"))if($msg_error_rs$$=await $Socai$$.find({id_ct:$master$$._id.toString()}),0<$msg_error_rs$$.length)$callback$jscomp$0$$(null,$msg_error_rs$$);else{console.error("Error save socai",$e$$,$master$$);let $q_remove$$={id_app:$master$$.id_app,
|
|
19
|
+
id_ct:$master$$._id.toString()};$Socai$$.deleteMany($q_remove$$,($_e$$,$rs$$)=>{console.error("delete socai because error when posting",$master$$._id.toString(),JSON.stringify($rs$$),$q_remove$$);$callback$jscomp$0$$($e$$)})}else{console.error("Error save socai",$e$$,$master$$);let $q_remove$$={id_app:$master$$.id_app,id_ct:$master$$._id.toString()};$Socai$$.deleteMany($q_remove$$,($_e$$,$rs$$)=>{console.error("delete socai because error when posting",$master$$._id.toString(),JSON.stringify($rs$$),
|
|
20
|
+
$q_remove$$);$callback$jscomp$0$$($e$$)})}else if($master$$.ma_ct){let $contr$$=global.controllers[$master$$.ma_ct.toUpperCase()];$contr$$?await $contr$$.model.findById($master$$._id)?$callback$jscomp$0$$(null,$msg_error_rs$$):$Socai$$.deleteMany({id_ct:$master$$._id.toString()},($_e$$,$rs$$)=>{console.error("Ch\u1ee9ng t\u1eeb kh\u00f4ng t\u1ed3n t\u1ea1i. X\u00f3a socai",$master$$._id,$rs$$);$callback$jscomp$0$$($e$$)}):(console.log("not found controller",$master$$.ma_ct.toUpperCase()),$callback$jscomp$0$$(null,
|
|
21
|
+
$msg_error_rs$$))}else $callback$jscomp$0$$(null,$msg_error_rs$$)})})})};module.exports=post;
|
|
@@ -8,16 +8,16 @@ $r$$[$f$$.name]=$value$$.map($v$$=>$v$$[$f$$.value]||0).reduce(($a$$,$b$$)=>$a$$
|
|
|
8
8
|
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$$){_.isArray($joinFields$$)&&$joinFields$$.forEach($join$$=>{if($join$$.where){let $_where$$={};for(let $key$$ in $join$$.where)$_where$$[$join$$.where[$key$$]]=$key$$;$join$$.where=$_where$$}});_.isArray($id_app$$)&&_.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$$,$model$$,
|
|
10
10
|
$joinFields$$,$fn$$)};const getFields=$fields$$=>{_.isArray($fields$$)||($fields$$=[$fields$$]);return $fields$$=$fields$$.map(function($map$$){if(_.isObject($map$$)){var $rs$jscomp$1_value$$=$map$$.value;if($map$$.name&&$rs$jscomp$1_value$$)return{[$rs$jscomp$1_value$$]:1};$rs$jscomp$1_value$$={};for(let $key$$ in $map$$)$rs$jscomp$1_value$$[$map$$[$key$$]]=1;return $rs$jscomp$1_value$$}return{[$map$$]:1}}).reduce(($a$$,$b$$)=>({...$a$$,...$b$$}),{})};
|
|
11
|
-
Array.prototype.joinModel2=function($id_app$$,$model$jscomp$0$$,$joinFields$$,$fn$$,$options$$={cache:!0}){let $self$$=this;setImmediate(()=>{if(_.isArray($id_app$$)){let $model_1$$=$id_app$$,$joinFields_1$$=$model$jscomp$0$$,$fn_1$$=$joinFields$$;$id_app$$=void 0;$model$jscomp$0$$=$model_1$$;$joinFields$$=$joinFields_1$$;$fn$$=$fn_1$$}let $model_origin$$;_.isArray($model$jscomp$0$$)||($model_origin$$=$model$jscomp$0$$);(new Promise($resolve$$=>{setImmediate(()=>{_.isArray($joinFields$$)||
|
|
12
|
-
[$joinFields$$]);$joinFields$$.forEach($join$$=>{$join$$.fields_need_get_data||_.isArray($model$jscomp$0$$)||$join$$.setFields||$join$$.asyncSetFields||!$join$$.fields||_.isFunction($join$$.fields)||($join$$.fields_need_get_data=getFields($join$$.fields))});_.isArray($model$jscomp$0$$)?$resolve$$($model$jscomp$0$$):$resolve$$([])})})).then($model$$=>{async.mapSeries($self$$,function($item$$,$callback$jscomp$0$$){setImmediate(()=>{async.mapSeries($joinFields$$,function($join$$,$callback$$){setImmediate(()=>
|
|
13
|
-
{let $query$$={};if($join$$.where)if(_.isFunction($join$$.where))$query$$=$join$$.where($item$$)||{};else{if(_.isString($join$$.where)){var $bkey_k$$=$join$$.where;$join$$.where={};$join$$.where[$bkey_k$$]=$bkey_k$$}for(let $akey$$ in $join$$.where)if($bkey_k$$=$join$$.where[$akey$$],_.isObject($bkey_k$$)?$query$$[$akey$$]=$bkey_k$$:$query$$[$bkey_k$$]=$item$$[$akey$$]
|
|
14
|
-
$join$$.bkey){if("_id"
|
|
15
|
-
|
|
11
|
+
Array.prototype.joinModel2=function($id_app$$,$model$jscomp$0$$,$joinFields$$,$fn$$,$options$$={cache:!0}){let $self$$=this;setImmediate(()=>{if(_.isArray($id_app$$)){let $model_1$$=$id_app$$,$joinFields_1$$=$model$jscomp$0$$,$fn_1$$=$joinFields$$;$id_app$$=void 0;$model$jscomp$0$$=$model_1$$;$joinFields$$=$joinFields_1$$;$fn$$=$fn_1$$}$fn$$||($fn$$=()=>{});let $model_origin$$;_.isArray($model$jscomp$0$$)||($model_origin$$=$model$jscomp$0$$);(new Promise($resolve$$=>{setImmediate(()=>{_.isArray($joinFields$$)||
|
|
12
|
+
($joinFields$$=[$joinFields$$]);$joinFields$$.forEach($join$$=>{$join$$.fields_need_get_data||_.isArray($model$jscomp$0$$)||$join$$.setFields||$join$$.asyncSetFields||!$join$$.fields||_.isFunction($join$$.fields)||($join$$.fields_need_get_data=getFields($join$$.fields))});_.isArray($model$jscomp$0$$)?$resolve$$($model$jscomp$0$$):$resolve$$([])})})).then($model$$=>{async.mapSeries($self$$,function($item$$,$callback$jscomp$0$$){setImmediate(()=>{async.mapSeries($joinFields$$,function($join$$,$callback$$){setImmediate(()=>
|
|
13
|
+
{let $query$$={};if($join$$.where)if(_.isFunction($join$$.where))$query$$=$join$$.where($item$$)||{};else{if(_.isString($join$$.where)){var $bkey_k$$=$join$$.where;$join$$.where={};$join$$.where[$bkey_k$$]=$bkey_k$$}for(let $akey$$ in $join$$.where)if($bkey_k$$=$join$$.where[$akey$$],_.isObject($bkey_k$$)?$query$$[$akey$$]=$bkey_k$$:$query$$[$bkey_k$$]=$item$$[$akey$$],!("_id"!=$bkey_k$$||$item$$[$akey$$]&&global.mongoose.Types.ObjectId.isValid($item$$[$akey$$])))return $callback$$(null)}if($join$$.akey&&
|
|
14
|
+
$join$$.bkey){if(!("_id"!=$join$$.bkey||$item$$[$join$$.akey]&&global.mongoose.Types.ObjectId.isValid($item$$[$join$$.akey])))return $callback$$(null);$query$$[$join$$.bkey]=$item$$[$join$$.akey]}let $_model$$;($_model$$="function"!==typeof $model_origin$$||$model_origin$$.findOne?$model_origin$$:$model_origin$$($item$$))&&$_model$$.schema&&($_model$$.schema.paths.id_app?$query$$.id_app=$item$$.id_app||$query$$.id_app:delete $query$$.id_app);let $b$$=_.findWhere($model$$,$query$$),$d_session$$="";
|
|
15
|
+
if($query$$._id)$d_session$$="stp:"+$query$$._id;else{for(let $key$$ in $query$$)"id_app"!==$key$$&&$query$$[$key$$]&&($d_session$$=$d_session$$?$d_session$$+":"+$key$$+":"+$query$$[$key$$]:$key$$+":"+$query$$[$key$$]);$d_session$$=$query$$.id_app?"id_app:"+$query$$.id_app+":"+$d_session$$:($id_app$$||"")+":"+$d_session$$}(new Promise(($resolve$jscomp$0$$,$reject$$)=>{$_model$$&&!$b$$?(new Promise($resolve$$=>{setImmediate(()=>{$options$$.cache&&$d_session$$&&$_model$$.collection&&$_model$$.collection.name&&
|
|
16
16
|
cachedKeys[$_model$$.collection.name.substring(0,$_model$$.collection.name.length-1)]?global.clientRedis.get($d_session$$,function($err$$,$reply$$){$resolve$$($reply$$)}):$resolve$$()})})).then($rep$$=>{setImmediate(async()=>{if($rep$$)$b$$=JSON.parse($rep$$),$resolve$jscomp$0$$($b$$);else{let $q$$={};for($fields$jscomp$1_key$$ in $query$$)void 0!==$query$$[$fields$jscomp$1_key$$]&&($q$$[$fields$jscomp$1_key$$]=$query$$[$fields$jscomp$1_key$$]);if(0===Object.keys($q$$).length)return $resolve$jscomp$0$$(null);
|
|
17
17
|
$id_app$$&&($q$$.id_app=$id_app$$);if(""==$q$$._id||$q$$._id&&!global.mongoose.Types.ObjectId.isValid($q$$._id))return $resolve$jscomp$0$$(null);var $fields$jscomp$1_key$$=$join$$.fields_need_get_data;if(_.isString($_model$$)){if(!mongoose.models[$_model$$])return $reject$$("Collection "+$_model$$+" is not exists");$_model$$=mongoose.models[$_model$$]}try{const $rs$$=await $_model$$.findOne($q$$,$fields$jscomp$1_key$$).lean().exec();$rs$$&&($rs$$._id=$rs$$._id.toString(),$b$$=$rs$$);$resolve$jscomp$0$$($b$$)}catch($e$$){console.error($e$$),
|
|
18
18
|
$resolve$jscomp$0$$($b$$)}}})}):$resolve$jscomp$0$$($b$$)})).then(()=>{setImmediate(()=>{$b$$&&($join$$.fields||$join$$.setFields||$join$$.asyncSetFields)?($join$$.fields&&(_.isFunction($join$$.fields)?$join$$.fields($item$$,$b$$):(_.isArray($join$$.fields)||($join$$.fields=[$join$$.fields]),$join$$.fields.forEach(function($map$$){if(_.isObject($map$$)){let $name$$=$map$$.name,$value$$=$map$$.value;if($name$$&&$value$$)$item$$[$name$$]=$b$$[$value$$];else for(let $key$$ in $map$$)$item$$[$key$$]=
|
|
19
|
-
$b$$[$map$$[$key$$]]}else $item$$[$map$$]=$b$$[$map$$]}))),$join$$.setFields&&$join$$.setFields($item$$,$b$$),$join$$.asyncSetFields?setImmediate(()=>{$join$$.asyncSetFields($item$$,$b$$,()=>{$callback$$(null)})}):$callback$$(null)):$callback$$(null)})})})},function($error$$){setImmediate(()=>{if($error$$)return $callback$jscomp$0$$($error$$);$callback$jscomp$0$$()})})})},function($error$$){setImmediate(()=>{$error$$&&console.error($error$$)
|
|
20
|
-
$fn$$($self$$)})})};Array.prototype.asyncJoinModel2=function($id_app$$,$model$$,$joinFields$$,$options$$={cache:!0}){let $_this$$=this;return new Promise($resolve$$=>{$_this$$.joinModel2($id_app$$,$model$$,$joinFields$$,$rs$$=>{$resolve$$($rs$$)},$options$$)})};
|
|
19
|
+
$b$$[$map$$[$key$$]]}else $item$$[$map$$]=$b$$[$map$$]}))),$join$$.setFields&&$join$$.setFields($item$$,$b$$),$join$$.asyncSetFields?setImmediate(()=>{$join$$.asyncSetFields($item$$,$b$$,()=>{$callback$$(null)})}):$callback$$(null)):$callback$$(null)})})})},function($error$$){setImmediate(()=>{if($error$$)return $callback$jscomp$0$$($error$$);$callback$jscomp$0$$()})})})},function($error$$){setImmediate(()=>{$error$$&&console.error($error$$);try{$fn$$($self$$)}catch($e$$){console.error($e$$,$fn$$)}})})}).catch($error$$=>
|
|
20
|
+
{console.error($error$$);try{$fn$$($self$$)}catch($e$$){console.error($e$$,$fn$$)}})})};Array.prototype.asyncJoinModel2=function($id_app$$,$model$$,$joinFields$$,$options$$={cache:!0}){let $_this$$=this;return new Promise($resolve$$=>{$_this$$.joinModel2($id_app$$,$model$$,$joinFields$$,$rs$$=>{$resolve$$($rs$$)},$options$$)})};
|
|
21
21
|
Array.prototype.crossJoin=function($otherArray$$,$where$$,$fn$$){setImmediate(()=>{let $newArray$$=[];for(let $e1$$ of this){var $_otherArray__where$$={};if($where$$)for(let $key$$ in $where$$)$_otherArray__where$$[$where$$[$key$$]]=$e1$$[$key$$];$_otherArray__where$$=_.where($otherArray$$,$_otherArray__where$$);if(0===$_otherArray__where$$.length)$newArray$$.push($e1$$);else for(let $item$$ of $_otherArray__where$$)$_otherArray__where$$={},_.extend($_otherArray__where$$,$e1$$),_.extend($_otherArray__where$$,
|
|
22
22
|
$item$$),$newArray$$.push($_otherArray__where$$)}$fn$$($newArray$$)})};Array.prototype.asyncCrossJoin=function($otherArray$$,$where$$){let $_this$$=this;return new Promise($resolve$$=>{$_this$$.crossJoin($otherArray$$,$where$$,$rs$$=>{$resolve$$($rs$$)})})};
|
|
23
23
|
Array.prototype.pivot=function($rowFields$$,$colPivot$$,$colSum$$,$fn$$,$options$$={},$log$$=()=>{}){setImmediate(()=>{$log$$("pivot:start");this.groupBy($colPivot$$,[],($e$jscomp$0$$,$colFields$$)=>{$log$$("pivot:group by col");$colFields$$=_.pluck($colFields$$,$colPivot$$);this.groupBy($rowFields$$,[],($e$$,$report$$)=>{setImmediate(()=>{$log$$("pivot:group by row");for(let $r$$ of $report$$)for(let $c$$ of $colFields$$){let $w$$={};$w$$[$colPivot$$]=$c$$;$rowFields$$.forEach(function($rf$$){$w$$[$rf$$]=
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
module.exports=function($condition$$,$fn$$){if(!($condition$$&&$condition$$.thang&&$condition$$.nam&&$condition$$.id_app))return $fn$$("T\u00ednh n\u0103ng n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: thang,nam,id_app");let $thang$$=Number($condition$$.thang),$nam$$=Number($condition$$.nam);dmyt.find({id_app:$condition$$.id_app,pt_phan_bo:"1",th_sp:!1}).lean().exec(($e$$,$yts$$)=>{if($e$$)return $fn$$($e$$);async.mapSeries($yts$$,($yt$$,$callback$jscomp$0$$)=>{async.series({gt:$callback$$=>
|
|
3
|
-
{let $cond$$={id_app:$condition$$.id_app,ma_yt:$yt$$.ma_yt,nam:$condition$$.nam,thang:$condition$$.thang};$condition$$.ma_bp&&($cond$$.ma_bp=$condition$$.ma_bp.toUpperCase());$condition$$.id_lenhsx&&mongoose.Types.ObjectId.isValid($condition$$.id_lenhsx)&&($cond$$.id_lenhsx=$condition$$.id_lenhsx);gt_thcppstk.find($cond$$).lean().exec(($e$jscomp$0$$,$pstk$$)=>{if($e$jscomp$0$$)return $callback$$($e$jscomp$0$$);$pstk$$.groupBy(["ma_bp","ma_yt","id_lenhsx"],["dd_dk","dd_dk_nt","ps_tk",
|
|
4
|
-
$rs$$)=>{if($e$$)return $callback$$($e$$);$rs$$.forEach($p$$=>{$p$$.co_do_dang=$yt$$.co_do_dang;$p$$.nam=$nam$$;$p$$.thang=$thang$$;$p$$.id_app=$condition$$.id_app;$p$$.yt_trung_gian=$yt$$.yt_trung_gian;$p$$.cong_tru=$yt$$.cong_tru});$callback$$(null,$rs$$)})})})}},function($e$$,$rs$$){if($e$$)return $callback$jscomp$0$$($e$$);$callback$jscomp$0$$(null,$rs$$.gt)})},($cond$jscomp$1_e$$,$cppstk$$)=>{if($cond$jscomp$1_e$$)return $fn$$($cond$jscomp$1_e$$);let $data_pstk$$=$cppstk$$.reduce(($a
|
|
5
|
-
$a$$.concat($b$$),[]);$cond$jscomp$1_e$$={id_app:$condition$$.id_app,nam:$condition$$.nam,thang:$condition$$.thang};$condition$$.ma_bp&&($cond$jscomp$1_e$$.ma_bp=$condition$$.ma_bp.toUpperCase());$condition$$.id_lenhsx&&mongoose.Types.ObjectId.isValid($condition$$.id_lenhsx)&&($cond$jscomp$1_e$$.id_lenhsx=$condition$$.id_lenhsx);gt_sltk.find($cond$jscomp$1_e$$).lean().exec(($e$jscomp$0$$,$sltk$$)=>{if($e$jscomp$0$$)return $fn$$($e$jscomp$0$$);$e$jscomp$0$$=$sltk$$.csum("sl_nk_tk")+$sltk$$.csum("sl_dd_ck");
|
|
1
|
+
'use strict';const dmyt=global.getModel("dmyt"),gt_thcppstk=global.getModel("gt_thcppstk"),gt_ctgt=global.getModel("gt_ctgt"),gt_sltk=global.getModel("gt_sltk"),async=require("async");
|
|
2
|
+
module.exports=function($condition$$,$fn$$){if(!($condition$$&&$condition$$.thang&&$condition$$.nam&&$condition$$.id_app))return $fn$$("T\u00ednh n\u0103ng n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: thang,nam,id_app");let $thang$$=Number($condition$$.thang),$nam$$=Number($condition$$.nam);dmyt.find({id_app:$condition$$.id_app,pt_phan_bo:"1",th_sp:!1,status:!0}).lean().exec(($e$$,$yts$$)=>{if($e$$)return $fn$$($e$$);async.mapSeries($yts$$,($yt$$,$callback$jscomp$0$$)=>{async.series({gt:$callback$$=>
|
|
3
|
+
{setImmediate(()=>{let $cond$$={id_app:$condition$$.id_app,ma_yt:$yt$$.ma_yt,nam:$condition$$.nam,thang:$condition$$.thang};$condition$$.ma_bp&&($cond$$.ma_bp=$condition$$.ma_bp.toUpperCase());$condition$$.id_lenhsx&&mongoose.Types.ObjectId.isValid($condition$$.id_lenhsx)&&($cond$$.id_lenhsx=$condition$$.id_lenhsx);gt_thcppstk.find($cond$$).lean().exec(($e$jscomp$0$$,$pstk$$)=>{if($e$jscomp$0$$)return $callback$$($e$jscomp$0$$);$pstk$$.groupBy(["ma_bp","ma_yt","id_lenhsx"],["dd_dk","dd_dk_nt","ps_tk",
|
|
4
|
+
"ps_tk_nt"],($e$$,$rs$$)=>{if($e$$)return $callback$$($e$$);$rs$$.forEach($p$$=>{$p$$.co_do_dang=$yt$$.co_do_dang;$p$$.nam=$nam$$;$p$$.thang=$thang$$;$p$$.id_app=$condition$$.id_app;$p$$.yt_trung_gian=$yt$$.yt_trung_gian;$p$$.cong_tru=$yt$$.cong_tru});$callback$$(null,$rs$$)})})})}},function($e$$,$rs$$){if($e$$)return $callback$jscomp$0$$($e$$);$callback$jscomp$0$$(null,$rs$$.gt)})},($cond$jscomp$1_e$$,$cppstk$$)=>{if($cond$jscomp$1_e$$)return $fn$$($cond$jscomp$1_e$$);let $data_pstk$$=$cppstk$$.reduce(($a$$,
|
|
5
|
+
$b$$)=>$a$$.concat($b$$),[]);$cond$jscomp$1_e$$={id_app:$condition$$.id_app,nam:$condition$$.nam,thang:$condition$$.thang};$condition$$.ma_bp&&($cond$jscomp$1_e$$.ma_bp=$condition$$.ma_bp.toUpperCase());$condition$$.id_lenhsx&&mongoose.Types.ObjectId.isValid($condition$$.id_lenhsx)&&($cond$jscomp$1_e$$.id_lenhsx=$condition$$.id_lenhsx);gt_sltk.find($cond$jscomp$1_e$$).lean().exec(($e$jscomp$0$$,$sltk$$)=>{if($e$jscomp$0$$)return $fn$$($e$jscomp$0$$);$e$jscomp$0$$=$sltk$$.csum("sl_nk_tk")+$sltk$$.csum("sl_dd_ck");
|
|
6
6
|
for(let $sp$$ of $sltk$$)$sp$$.he_so=0!==$e$jscomp$0$$?($sp$$.sl_nk_tk+$sp$$.sl_dd_ck)/$e$jscomp$0$$:0;$data_pstk$$.crossJoin($sltk$$,{ma_bp:"ma_bp"},$data_pstk$$=>{for(let $s$$ of $data_pstk$$){delete $s$$._id;$s$$.co_do_dang||($s$$.ty_le_ht_dk=0,$s$$.ty_le_ht_ck=0);$s$$.he_so||($s$$.he_so=0);$s$$.sl_dd_dk||($s$$.sl_dd_dk=0);$s$$.sl_nk_tk||($s$$.sl_nk_tk=0);$s$$.sl_sx_tk||($s$$.sl_sx_tk=0);$s$$.sl_dd_ck||($s$$.sl_dd_ck=0);$s$$.ty_le_ht_ck||($s$$.ty_le_ht_ck=0);$s$$.ty_le_ht_dk||($s$$.ty_le_ht_dk=
|
|
7
7
|
0);if(!$s$$.dd_dk||isNaN($s$$.dd_dk))$s$$.dd_dk=0;if(!$s$$.dd_dk_nt||isNaN($s$$.dd_dk_nt))$s$$.dd_dk_nt=0;if(!$s$$.ps_tk||isNaN($s$$.ps_tk))$s$$.ps_tk=0;if(!$s$$.ps_tk_nt||isNaN($s$$.ps_tk_nt))$s$$.ps_tk_nt=0;$s$$.dd_dk*=$s$$.he_so;$s$$.dd_dk_nt*=$s$$.he_so;$s$$.ps_tk*=$s$$.he_so;$s$$.ps_tk_nt*=$s$$.he_so;$s$$.sl_dd_dk_qd=$s$$.sl_dd_dk*$s$$.ty_le_ht_dk/100;$s$$.sl_dd_ck_qd=$s$$.sl_dd_ck*$s$$.ty_le_ht_ck/100;$s$$.sl_sx_tk=$s$$.sl_dd_ck+$s$$.sl_nk_tk-$s$$.sl_dd_dk;$s$$.sl_sp_ht_qd=$s$$.sl_dd_ck_qd+
|
|
8
8
|
$s$$.sl_nk_tk;$s$$.t_cp_sx=$s$$.dd_dk+$s$$.ps_tk;$s$$.t_cp_sx_nt=$s$$.dd_dk_nt+$s$$.ps_tk_nt;$s$$.gt=0===$s$$.sl_nk_tk?0:$s$$.t_cp_sx/$s$$.sl_sp_ht_qd;$s$$.gt_nt=0===$s$$.sl_nk_tk?0:$s$$.t_cp_sx_nt/$s$$.sl_sp_ht_qd;$s$$.t_gt=$s$$.gt*$s$$.sl_nk_tk;$s$$.t_gt_nt=$s$$.gt_nt*$s$$.sl_nk_tk;$s$$.dd_ck=$s$$.t_cp_sx-$s$$.t_gt;$s$$.dd_ck_nt=$s$$.t_cp_sx_nt-$s$$.t_gt_nt}gt_ctgt.create($data_pstk$$.filter($d$$=>$d$$.ma_sp),($e$$,$rs$$)=>{$e$$&&console.error($e$$.message);$fn$$($e$$,$rs$$)})})})})})};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
'use strict';
|
|
1
|
+
'use strict';const dmyt=global.getModel("dmyt"),gt_thcppstk=global.getModel("gt_thcppstk"),gt_ctgt=global.getModel("gt_ctgt"),gt_sltk=global.getModel("gt_sltk"),async=require("async"),underscore=require("underscore");
|
|
2
2
|
module.exports=function($condition$$,$fn$$){if(!($condition$$&&$condition$$.thang&&$condition$$.nam&&$condition$$.id_app))return $fn$$("L\u1ed7i: T\u00ednh n\u0103ng n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: thang,nam,id_app,ma_yt");(new Promise(($resole$$,$reject$$)=>{setImmediate(()=>{let $cond$$={id_app:$condition$$.id_app,nam:$condition$$.nam,thang:$condition$$.thang};$condition$$.ma_bp&&($cond$$.ma_bp=$condition$$.ma_bp.toUpperCase());$condition$$.id_lenhsx&&mongoose.Types.ObjectId.isValid($condition$$.id_lenhsx)&&
|
|
3
|
-
($cond$$.id_lenhsx=$condition$$.id_lenhsx);gt_ctgt.find($cond$$).lean().exec(($e$$,$ctgt$$)=>{if($e$$)return $reject$$($e$$);$resole$$($ctgt$$)})})})).then($ctgt$$=>new Promise(($resolve$$,$reject$$)=>{setImmediate(()=>{let $dsyt_datinh$$=underscore.pluck($ctgt$$,"ma_yt");dmyt.find({id_app:$condition$$.id_app,pt_phan_bo:"2",th_sp:!1,ma_yt:{$nin:$dsyt_datinh$$},yt_tinh_hs_pb:{$in:$dsyt_datinh$$}}).lean().exec(($e$$,$yts$$)=>{if($e$$)return $reject$$($e$$);$resolve$$({yts:$yts$$,ctgt_tinhheso:$ctgt$$})})})})).then($data$$=>
|
|
3
|
+
($cond$$.id_lenhsx=$condition$$.id_lenhsx);gt_ctgt.find($cond$$).lean().exec(($e$$,$ctgt$$)=>{if($e$$)return $reject$$($e$$);$resole$$($ctgt$$)})})})).then($ctgt$$=>new Promise(($resolve$$,$reject$$)=>{setImmediate(()=>{let $dsyt_datinh$$=underscore.pluck($ctgt$$,"ma_yt");dmyt.find({id_app:$condition$$.id_app,status:!0,pt_phan_bo:"2",th_sp:!1,ma_yt:{$nin:$dsyt_datinh$$},yt_tinh_hs_pb:{$in:$dsyt_datinh$$}}).lean().exec(($e$$,$yts$$)=>{if($e$$)return $reject$$($e$$);$resolve$$({yts:$yts$$,ctgt_tinhheso:$ctgt$$})})})})).then($data$$=>
|
|
4
4
|
new Promise(($resolve$$,$reject$$)=>{setImmediate(()=>{var $cond$jscomp$1_yts$$=underscore.pluck($data$$.yts,"ma_yt");$cond$jscomp$1_yts$$={id_app:$condition$$.id_app,nam:$condition$$.nam,thang:$condition$$.thang,ma_yt:{$in:$cond$jscomp$1_yts$$}};$condition$$.ma_bp&&($cond$jscomp$1_yts$$.ma_bp=$condition$$.ma_bp.toUpperCase());$condition$$.id_lenhsx&&mongoose.Types.ObjectId.isValid($condition$$.id_lenhsx)&&($cond$jscomp$1_yts$$.id_lenhsx=$condition$$.id_lenhsx);gt_thcppstk.find($cond$jscomp$1_yts$$).lean().exec(($e$jscomp$0$$,
|
|
5
5
|
$cppstk$$)=>{if($e$jscomp$0$$)return $reject$$($e$jscomp$0$$);$cppstk$$.groupBy(["ma_bp","ma_yt","id_lenhsx"],["dd_dk","dd_dk_nt","ps_tk","ps_tk_nt"],($e$$,$rs$$)=>{if($e$$)return $reject$$($e$$);$data$$.cppstk=$rs$$;$resolve$$($data$$)})})})})).then($data$$=>new Promise(($resolve$$,$reject$$)=>{setImmediate(()=>{let $cond$$={id_app:$condition$$.id_app,nam:$condition$$.nam,thang:$condition$$.thang};$condition$$.ma_bp&&($cond$$.ma_bp=$condition$$.ma_bp.toUpperCase());$condition$$.id_lenhsx&&mongoose.Types.ObjectId.isValid($condition$$.id_lenhsx)&&
|
|
6
6
|
($cond$$.id_lenhsx=$condition$$.id_lenhsx);gt_sltk.find($cond$$).lean().exec(($e$$,$sltk$$)=>{if($e$$)return $reject$$($e$$);$data$$.sltk=$sltk$$;$resolve$$($data$$)})})})).then($data$$=>{async.mapSeries($data$$.yts,($yt$$,$callback$$)=>{setImmediate(()=>{var $cppstk$$=underscore.filter($data$$.ctgt_tinhheso,$c$$=>$c$$.ma_yt==$yt$$.yt_tinh_hs_pb);let $t_gt$$=$cppstk$$.csum("t_gt"),$gts$$=[];$cppstk$$.forEach($yths$$=>{let $gt$$={ma_sp:$yths$$.ma_sp,ma_bp:$yths$$.ma_bp,id_lenhsx:$yths$$.id_lenhsx,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';const sokho=global.getModel("sokho"),socai=global.getModel("socai"),dmyt=global.getModel("dmyt"),gt_thcppstk=global.getModel("gt_thcppstk"),ytdd_dk=global.getModel("ytdd_dk"),ytdd_ck=global.getModel("ytdd_ck"),async=require("async"),underscore=require("underscore"),moment=require("moment");
|
|
2
|
-
module.exports=function($condition$$,$fn$$){if(!($condition$$&&$condition$$.thang&&$condition$$.nam&&$condition$$.id_app))return $fn$$("L\u1ed7i: T\u00ednh n\u0103ng n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: thang,nam,id_app");let $thang$$=Number($condition$$.thang),$nam$$=Number($condition$$.nam),$tu_ngay$$=moment(new Date($nam$$,$thang$$-1,1)).startOf("date").toDate(),$den_ngay$$=moment(new Date($nam$$,$thang$$,0)).endOf("date").toDate();dmyt.find({id_app:$condition$$.id_app}).lean().exec(($e$$,
|
|
2
|
+
module.exports=function($condition$$,$fn$$){if(!($condition$$&&$condition$$.thang&&$condition$$.nam&&$condition$$.id_app))return $fn$$("L\u1ed7i: T\u00ednh n\u0103ng n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: thang,nam,id_app");let $thang$$=Number($condition$$.thang),$nam$$=Number($condition$$.nam),$tu_ngay$$=moment(new Date($nam$$,$thang$$-1,1)).startOf("date").toDate(),$den_ngay$$=moment(new Date($nam$$,$thang$$,0)).endOf("date").toDate();dmyt.find({id_app:$condition$$.id_app,status:!0}).lean().exec(($e$$,
|
|
3
3
|
$yts$$)=>{if($e$$)return $fn$$($e$$);let $data$$=[];async.mapSeries($yts$$,($yt$$,$callback$jscomp$0$$)=>{async.series({dk:$callback$$=>{(new Promise(($resolve$$,$reject$$)=>{setImmediate(()=>{let $cond$$={id_app:$condition$$.id_app,nam:$condition$$.nam,thang:$condition$$.thang,ma_yt:$yt$$.ma_yt};$condition$$.ma_bp&&($cond$$.ma_bp=$condition$$.ma_bp.toUpperCase());$condition$$.id_lenhsx&&mongoose.Types.ObjectId.isValid($condition$$.id_lenhsx)&&($cond$$.id_lenhsx=$condition$$.id_lenhsx);ytdd_dk.find($cond$$).lean().exec(($e$$,
|
|
4
4
|
$rs$$)=>{if($e$$)return $reject$$($e$$);for(let $dd$$ of $rs$$)$dd$$.dd_dk_nt=$dd$$.tien_nt,$dd$$.dd_dk=$dd$$.tien,$data$$.push($dd$$);$resolve$$($rs$$)})})})).then($dddk$$=>{setImmediate(()=>{let $cond$$={id_app:$condition$$.id_app,nam:$condition$$.nam,thang:$condition$$.thang-1,ma_yt:$yt$$.ma_yt};$condition$$.ma_bp&&($cond$$.ma_bp=$condition$$.ma_bp.toUpperCase());$condition$$.id_lenhsx&&mongoose.Types.ObjectId.isValid($condition$$.id_lenhsx)&&($cond$$.id_lenhsx=$condition$$.id_lenhsx);0===$cond$$.thang&&
|
|
5
5
|
($cond$$.thang=12,--$cond$$.nam);ytdd_ck.find($cond$$).lean().exec(($e$$,$rs$$)=>{if($e$$)return $callback$$($e$$);for(let $ck$$ of $rs$$)underscore.find($dddk$$,$d$$=>$d$$.ma_yt==$ck$$.ma_yt&&$d$$.ma_sp==$ck$$.ma_sp&&$d$$.ma_bp==$ck$$.ma_bp&&$d$$.id_lenhsx==$ck$$.id_lenhsx)||($ck$$.dd_dk_nt=$ck$$.tien_nt,$ck$$.dd_dk=$ck$$.tien,$data$$.push($ck$$));$callback$$(null)})})}).catch($e$$=>{$callback$$($e$$)})},ps:$callback$$=>{setImmediate(()=>{let $cond$$={id_app:$condition$$.id_app,ngay_ct:{$gte:$tu_ngay$$,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
module.exports=function($condition$$,$fn$$){if(!($condition$$&&$condition$$.thang&&$condition$$.nam&&$condition$$.id_app))return $fn$$("L\u1ed7i: T\u00ednh n\u0103ng n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: thang,nam,id_app");let $thang$$=Number($condition$$.thang),$nam$$=Number($condition$$.nam);dmyt.find({id_app:$condition$$.id_app,th_sp:!0}).lean().exec(($e$$,$yts$$)=>{if($e$$)return $fn$$($e$$);async.mapSeries($yts$$,($yt$$,$callback$jscomp$0$$)=>{async.series({gt:$callback$$=>
|
|
3
|
-
{let $cond$$={id_app:$condition$$.id_app,ma_yt:$yt$$.ma_yt,nam:$condition$$.nam,thang:$condition$$.thang};$condition$$.ma_bp&&($cond$$.ma_bp=$condition$$.ma_bp.toUpperCase());$condition$$.id_lenhsx&&mongoose.Types.ObjectId.isValid($condition$$.id_lenhsx)&&($cond$$.id_lenhsx=$condition$$.id_lenhsx);gt_thcppstk.find($cond$$).lean().exec(($e$jscomp$0$$,$pstk$$)=>{if($e$jscomp$0$$)return $callback$$($e$jscomp$0$$);$pstk$$=$pstk$$.filter($p$$=>$p$$.ma_sp);$pstk$$.groupBy(["ma_sp","ma_bp",
|
|
4
|
-
["dd_dk","dd_dk_nt","ps_tk","ps_tk_nt"],($e$$,$rs$$)=>{if($e$$)return $callback$$($e$$);$rs$$.forEach($p$$=>{$p$$.co_do_dang=$yt$$.co_do_dang;$p$$.nam=$nam$$;$p$$.thang=$thang$$;$p$$.id_app=$condition$$.id_app;$p$$.yt_trung_gian=$yt$$.yt_trung_gian;$p$$.cong_tru=$yt$$.cong_tru});$callback$$(null,$rs$$)})})})}},function($e$$,$rs$$){$callback$jscomp$0$$($e$$,$rs$$.gt)})},($e$jscomp$1$$,$ps$$)=>{if($e$jscomp$1$$)return $fn$$($e$jscomp$1$$);setImmediate(()=>{let $data_pstk$$=$ps$$.reduce(($a
|
|
5
|
-
$a$$.concat($b$$),[]),$cond$$={id_app:$condition$$.id_app,nam:$condition$$.nam,thang:$condition$$.thang};$condition$$.ma_bp&&($cond$$.ma_bp=$condition$$.ma_bp.toUpperCase());$condition$$.id_lenhsx&&mongoose.Types.ObjectId.isValid($condition$$.id_lenhsx)&&($cond$$.id_lenhsx=$condition$$.id_lenhsx);gt_sltk.find($cond$$).lean().exec(($e$jscomp$0$$,$sltk$$)=>{if($e$jscomp$0$$)return $fn$$($e$jscomp$0$$);$data_pstk$$.joinModel2($sltk$$,[{where:{ma_sp:"ma_sp",ma_bp:"ma_bp",id_lenhsx:"id_lenhsx"},
|
|
6
|
-
()=>{for(let $s$$ of $data_pstk$$)$s$$.co_do_dang||($s$$.sl_dd_ck=0,$s$$.sl_dd_dk=0,$s$$.ty_le_ht_dk=0,$s$$.ty_le_ht_ck=0),$s$$.sl_dd_dk||($s$$.sl_dd_dk=0),$s$$.sl_nk_tk||($s$$.sl_nk_tk=0),$s$$.sl_sx_tk||($s$$.sl_sx_tk=0),$s$$.sl_dd_ck||($s$$.sl_dd_ck=0),$s$$.ty_le_ht_ck||($s$$.ty_le_ht_ck=0),$s$$.ty_le_ht_dk||($s$$.ty_le_ht_dk=0),$s$$.sl_dd_dk_qd=$s$$.sl_dd_dk*$s$$.ty_le_ht_dk/100,$s$$.sl_dd_ck_qd=$s$$.sl_dd_ck*$s$$.ty_le_ht_ck/
|
|
7
|
-
|
|
1
|
+
'use strict';const dmyt=global.getModel("dmyt"),gt_thcppstk=global.getModel("gt_thcppstk"),gt_ctgt=global.getModel("gt_ctgt"),gt_sltk=global.getModel("gt_sltk"),async=require("async");
|
|
2
|
+
module.exports=function($condition$$,$fn$$){if(!($condition$$&&$condition$$.thang&&$condition$$.nam&&$condition$$.id_app))return $fn$$("L\u1ed7i: T\u00ednh n\u0103ng n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: thang,nam,id_app");let $thang$$=Number($condition$$.thang),$nam$$=Number($condition$$.nam);dmyt.find({id_app:$condition$$.id_app,th_sp:!0,status:!0}).lean().exec(($e$$,$yts$$)=>{if($e$$)return $fn$$($e$$);async.mapSeries($yts$$,($yt$$,$callback$jscomp$0$$)=>{async.series({gt:$callback$$=>
|
|
3
|
+
{setImmediate(()=>{let $cond$$={id_app:$condition$$.id_app,ma_yt:$yt$$.ma_yt,nam:$condition$$.nam,thang:$condition$$.thang};$condition$$.ma_bp&&($cond$$.ma_bp=$condition$$.ma_bp.toUpperCase());$condition$$.id_lenhsx&&mongoose.Types.ObjectId.isValid($condition$$.id_lenhsx)&&($cond$$.id_lenhsx=$condition$$.id_lenhsx);gt_thcppstk.find($cond$$).lean().exec(($e$jscomp$0$$,$pstk$$)=>{if($e$jscomp$0$$)return $callback$$($e$jscomp$0$$);$pstk$$=$pstk$$.filter($p$$=>$p$$.ma_sp);$pstk$$.groupBy(["ma_sp","ma_bp",
|
|
4
|
+
"ma_yt","id_lenhsx"],["dd_dk","dd_dk_nt","ps_tk","ps_tk_nt"],($e$$,$rs$$)=>{if($e$$)return $callback$$($e$$);$rs$$.forEach($p$$=>{$p$$.co_do_dang=$yt$$.co_do_dang;$p$$.nam=$nam$$;$p$$.thang=$thang$$;$p$$.id_app=$condition$$.id_app;$p$$.yt_trung_gian=$yt$$.yt_trung_gian;$p$$.cong_tru=$yt$$.cong_tru});$callback$$(null,$rs$$)})})})}},function($e$$,$rs$$){$callback$jscomp$0$$($e$$,$rs$$.gt)})},($e$jscomp$1$$,$ps$$)=>{if($e$jscomp$1$$)return $fn$$($e$jscomp$1$$);setImmediate(()=>{let $data_pstk$$=$ps$$.reduce(($a$$,
|
|
5
|
+
$b$$)=>$a$$.concat($b$$),[]),$cond$$={id_app:$condition$$.id_app,nam:$condition$$.nam,thang:$condition$$.thang};$condition$$.ma_bp&&($cond$$.ma_bp=$condition$$.ma_bp.toUpperCase());$condition$$.id_lenhsx&&mongoose.Types.ObjectId.isValid($condition$$.id_lenhsx)&&($cond$$.id_lenhsx=$condition$$.id_lenhsx);gt_sltk.find($cond$$).lean().exec(($e$jscomp$0$$,$sltk$$)=>{if($e$jscomp$0$$)return $fn$$($e$jscomp$0$$);$data_pstk$$.joinModel2($sltk$$,[{where:{ma_sp:"ma_sp",ma_bp:"ma_bp",id_lenhsx:"id_lenhsx"},
|
|
6
|
+
fields:"sl_dd_dk sl_nk_tk sl_sx_tk sl_dd_ck ty_le_ht_dk ty_le_ht_ck".split(" ")}],()=>{for(let $s$$ of $data_pstk$$)$s$$.co_do_dang||($s$$.sl_dd_ck=0,$s$$.sl_dd_dk=0,$s$$.ty_le_ht_dk=0,$s$$.ty_le_ht_ck=0),$s$$.sl_dd_dk||($s$$.sl_dd_dk=0),$s$$.sl_nk_tk||($s$$.sl_nk_tk=0),$s$$.sl_sx_tk||($s$$.sl_sx_tk=0),$s$$.sl_dd_ck||($s$$.sl_dd_ck=0),$s$$.ty_le_ht_ck||($s$$.ty_le_ht_ck=0),$s$$.ty_le_ht_dk||($s$$.ty_le_ht_dk=0),$s$$.sl_dd_dk_qd=$s$$.sl_dd_dk*$s$$.ty_le_ht_dk/100,$s$$.sl_dd_ck_qd=$s$$.sl_dd_ck*$s$$.ty_le_ht_ck/
|
|
7
|
+
100,$s$$.sl_sx_tk=$s$$.sl_dd_ck+$s$$.sl_nk_tk-$s$$.sl_dd_dk,$s$$.sl_sp_ht_qd=$s$$.sl_dd_ck_qd+$s$$.sl_nk_tk,$s$$.t_cp_sx=$s$$.dd_dk+$s$$.ps_tk,$s$$.t_cp_sx_nt=$s$$.dd_dk_nt+$s$$.ps_tk_nt,$s$$.gt=0===$s$$.sl_nk_tk?0:$s$$.t_cp_sx/$s$$.sl_sp_ht_qd,$s$$.gt_nt=0===$s$$.sl_nk_tk?0:$s$$.t_cp_sx_nt/$s$$.sl_sp_ht_qd,$s$$.t_gt=$s$$.gt*$s$$.sl_nk_tk,$s$$.t_gt_nt=$s$$.gt_nt*$s$$.sl_nk_tk,$s$$.dd_ck=$s$$.t_cp_sx-$s$$.t_gt,$s$$.dd_ck_nt=$s$$.t_cp_sx_nt-$s$$.t_gt_nt;gt_ctgt.create($data_pstk$$,($e$$,$rs$$)=>{$e$$&&
|
|
8
|
+
(console.error($e$$),console.error($data_pstk$$));$fn$$($e$$,$rs$$)})})})})})})};
|
package/server/libs/tinhgiatb.js
CHANGED
|
@@ -6,7 +6,7 @@ $bang_gia$$=underscore.filter($bang_gia$$,function($r$$){return 0!==$r$$.gia||0!
|
|
|
6
6
|
{id_app:$id_app$$,ma_vt:$gia$$.ma_vt};$ma_kho$$&&($query_delete$$.ma_kho=$ma_kho$$);giatb.deleteMany($query_delete$$,function($error$jscomp$0$$){if($error$jscomp$0$$)return $callback$$($error$jscomp$0$$);giatb.create($gia$$,function($error$$,$result$$){if($error$$)return console.log("Loi khi luu vao bang gia trung binh thang vat tu "+$gia$$.ma_vt,$error$$),$callback$$($error$$);$callback$$(null,$result$$)})})}},function($error$$){if($error$$)return $callback$jscomp$0$$($error$$);$callback$jscomp$0$$(null)})})},
|
|
7
7
|
function($error$$){if($error$$)return $callback$jscomp$1$$($error$$);$callback$jscomp$1$$(null)})},function($error$jscomp$1$$){if($error$jscomp$1$$)return $fn$$($error$jscomp$1$$);let $vouchers_x$$={},$vouchers_n$$={},$ma_vts$$=underscore.pluck($bang_gia$$,"ma_vt");async.series({xuat:function($callback$jscomp$0$$){setImmediate(()=>{let $query_sokho_x$$={id_app:$id_app$$,ngay_ct:{$gte:$tu_ngay$$,$lte:$den_ngay$$},nxt:2,ma_vt:{$in:$ma_vts$$},px_gia_dd:!1};$ma_kho$$&&($query_sokho_x$$.ma_kho=$ma_kho$$);
|
|
8
8
|
sokho.find($query_sokho_x$$).lean().exec(function($error$jscomp$0$$,$sks$$){if($error$jscomp$0$$)return $callback$jscomp$0$$($error$jscomp$0$$);if(!$sks$$||0===$sks$$.length)return $callback$jscomp$0$$(null,$vouchers_x$$);async.mapSeries($sks$$,function($sk$$,$callback$$){let $voucher$$=$vouchers_x$$[$sk$$.id_ct],$ct$$=mongoose.models[$sk$$.ma_ct.toLowerCase()];!$voucher$$&&$ct$$?$ct$$.findById($sk$$.id_ct,function($error$$,$v$$){if($error$$)return $callback$$($error$$);$v$$?($voucher$$=$v$$,$vouchers_x$$[$sk$$.id_ct]=
|
|
9
|
-
$voucher$$):(sokho.deleteMany({id_ct:$sk$$.id_ct.toString()},($e$$,$rs$$)=>{console.log("Khong tim thay phieu xuat. chuong trinh da xoa phieu nay khoi sokho",$sk$$.id_ct,"ma_ct",$sk$$.ma_ct,$sk$$.so_ct,$sk$$.ngay_ct,$rs$$)}),socai.deleteMany({id_ct:$sk$$.id_ct.toString()},($e$$,$rs$$)=>{console.log("Khong tim thay phieu xuat. chuong trinh da xoa phieu nay khoi socai",$sk$$.id_ct,"ma_ct",$sk$$.ma_ct,$sk$$.so_ct,$sk$$.ngay_ct,$rs$$)}));$callback$$()}):$callback$$()},function($error$$){if($error$$)return console.
|
|
9
|
+
$voucher$$):(sokho.deleteMany({id_ct:$sk$$.id_ct.toString()},($e$$,$rs$$)=>{console.log("Khong tim thay phieu xuat. chuong trinh da xoa phieu nay khoi sokho",$sk$$.id_ct,"ma_ct",$sk$$.ma_ct,$sk$$.so_ct,$sk$$.ngay_ct,$rs$$)}),socai.deleteMany({id_ct:$sk$$.id_ct.toString()},($e$$,$rs$$)=>{console.log("Khong tim thay phieu xuat. chuong trinh da xoa phieu nay khoi socai",$sk$$.id_ct,"ma_ct",$sk$$.ma_ct,$sk$$.so_ct,$sk$$.ngay_ct,$rs$$)}));$callback$$()}):$callback$$()},function($error$$){if($error$$)return console.error("co loi lay phieu xuat",
|
|
10
10
|
$error$$),$callback$jscomp$0$$($error$$);$callback$jscomp$0$$(null,$vouchers_x$$)})})})},nhap:function($callback$jscomp$0$$){setImmediate(()=>{let $query_sokho_n$$={id_app:$id_app$$,ngay_ct:{$gte:$tu_ngay$$,$lte:$den_ngay$$},nxt:1,ma_vt:{$in:$ma_vts$$},pn_gia_tb:!0,ma_ct:{$ne:"PXC"}};$ma_kho$$&&($query_sokho_n$$.ma_kho=$ma_kho$$);sokho.find($query_sokho_n$$,function($error$jscomp$0$$,$sks$$){if($error$jscomp$0$$)return $callback$jscomp$0$$($error$jscomp$0$$);if(!$sks$$||0===$sks$$.length)return $callback$jscomp$0$$(null,
|
|
11
11
|
$vouchers_n$$);async.mapSeries($sks$$,function($sk$$,$callback$$){let $voucher$$=$vouchers_n$$[$sk$$.id_ct],$ct$$=mongoose.models[$sk$$.ma_ct.toLowerCase()];!$voucher$$&&$ct$$?$ct$$.findById($sk$$.id_ct,function($error$$,$v$$){if($error$$)return $callback$$($error$$);$v$$?($voucher$$=$v$$,$vouchers_n$$[$sk$$.id_ct]=$voucher$$):(sokho.deleteMany({id_ct:$sk$$.id_ct.toString()},($e$$,$rs$$)=>{console.log("Khong tim thay phieu nhap. chuong trinh da xoa phieu nay khoi sokho",$sk$$.id_ct,"ma_ct",$sk$$.ma_ct,
|
|
12
12
|
$sk$$.so_ct,$sk$$.ngay_ct,$rs$$)}),socai.deleteMany({id_ct:$sk$$.id_ct.toString()},($e$$,$rs$$)=>{console.log("Khong tim thay phieu nhap. chuong trinh da xoa phieu nay khoi socai",$sk$$.id_ct,"ma_ct",$sk$$.ma_ct,$sk$$.so_ct,$sk$$.ngay_ct,$rs$$)}));$callback$$()}):$callback$$()},function($error$$){if($error$$)return console.log("co loi lay phieu nhap",$error$$),$callback$jscomp$0$$($error$$);$callback$jscomp$0$$(null,$vouchers_n$$)})})})}},function($error$jscomp$0$$){if($error$jscomp$0$$)return $fn$$($error$jscomp$0$$);
|
|
@@ -15,21 +15,18 @@ $d$$.ma_vt===$vt$$.ma_vt);$gia$$=$gia$$?$gia$$.gia:0;let $he_so_qd$$=1,$qd$$=awa
|
|
|
15
15
|
$d$$.ma_vt)&&!$d$$.px_gia_dd&&(!$ma_kho$$||$ma_kho$$===($d$$.ma_kho||$voucher_x$$.ma_kho||$voucher_x$$.ma_kho_x))),await Promise.all($details_details_doi_details_kmc$$.map($d$$=>(async()=>{var $gia$jscomp$3_gia_chuan$$=underscore.find($bang_gia$$,$vt$$=>$d$$.ma_vt===$vt$$.ma_vt);$gia$jscomp$3_gia_chuan$$=$gia$jscomp$3_gia_chuan$$?$gia$jscomp$3_gia_chuan$$.gia:0;let $he_so_qd$$=1,$qd$$=await dmqddvt.findOne({id_app:$voucher_x$$.id_app,ma_vt:$d$$.ma_vt,ma_dvt:$d$$.ma_dvt}).lean();$qd$$&&($he_so_qd$$=
|
|
16
16
|
$qd$$.mau?$qd$$.tu/$qd$$.mau:$qd$$.ty_le_qd);$d$$.gia_von=$d$$.gia_von_nt=$gia$jscomp$3_gia_chuan$$*$he_so_qd$$;$d$$.tien_xuat=$d$$.tien_xuat_nt=Math.roundBy($d$$.sl_xuat*$d$$.gia_von,$f_tien$$)})())));await $voucher_x$$.details.filter($d$$=>$d$$.promotion&&$d$$.promotion.details_km).map($d$jscomp$0$$=>(async()=>{const $details_km$$=$d$jscomp$0$$.promotion.details_km.filter($d$$=>(!$condition$$.ma_vt||$condition$$.ma_vt===$d$$.ma_vt)&&!$d$$.px_gia_dd&&(!$ma_kho$$||$ma_kho$$===($d$$.ma_kho||$voucher_x$$.ma_kho||
|
|
17
17
|
$voucher_x$$.ma_kho_x)));await Promise.all($details_km$$.map($d$$=>(async()=>{var $gia$jscomp$4_gia_chuan$$=underscore.find($bang_gia$$,$vt$$=>$d$$.ma_vt===$vt$$.ma_vt);$gia$jscomp$4_gia_chuan$$=$gia$jscomp$4_gia_chuan$$?$gia$jscomp$4_gia_chuan$$.gia:0;let $he_so_qd$$=1,$qd$$=await dmqddvt.findOne({id_app:$voucher_x$$.id_app,ma_vt:$d$$.ma_vt,ma_dvt:$d$$.ma_dvt}).lean();$qd$$&&($he_so_qd$$=$qd$$.mau?$qd$$.tu/$qd$$.mau:$qd$$.ty_le_qd);$d$$.gia_von=$d$$.gia_von_nt=$gia$jscomp$4_gia_chuan$$*$he_so_qd$$;
|
|
18
|
-
$d$$.tien_xuat=$d$$.tien_xuat_nt=Math.roundBy(($d$$.sl_xuat||$d$$.sl_km||0)*$d$$.gia_von,$f_tien$$)
|
|
19
|
-
|
|
20
|
-
$
|
|
21
|
-
|
|
22
|
-
$
|
|
23
|
-
$
|
|
24
|
-
$
|
|
25
|
-
$voucher_n$$.
|
|
26
|
-
$d$$.
|
|
27
|
-
($
|
|
28
|
-
|
|
29
|
-
$
|
|
30
|
-
$
|
|
31
|
-
$
|
|
32
|
-
$
|
|
33
|
-
$d_voucher$$&&($chung_tu_cap_nhat_chenh_lech$$[$d_voucher$$._id.toString()]=$d_voucher$$);$callback$$(null,$d_voucher$$)})},$_vouchers_chenh_lech_e$$=>{if($_vouchers_chenh_lech_e$$)return $fn$$($_vouchers_chenh_lech_e$$);$_vouchers_chenh_lech_e$$=underscore.values($chung_tu_cap_nhat_chenh_lech$$);async.mapSeries($_vouchers_chenh_lech_e$$,($voucher$$,$callback$$)=>{setImmediate(()=>{$voucher$$.save($ctrl$jscomp$2_error$$=>{if($ctrl$jscomp$2_error$$)return $callback$$($ctrl$jscomp$2_error$$);let $voucher_data$$=
|
|
34
|
-
$voucher$$.toObject();($ctrl$jscomp$2_error$$=global.controllers[$voucher_data$$.ma_ct.toUpperCase()])&&$ctrl$jscomp$2_error$$.post?(console.log("repost voucher",$voucher_data$$.ma_ct,$voucher_data$$.so_ct,$voucher_data$$._id,"..."),Controller.postData($voucher_data$$,$ctrl$jscomp$2_error$$,($e$$,$rs$$)=>{$e$$&&console.error("error repost khi tinh gia trung binh",$e$$,$voucher_data$$);$callback$$($e$$,$rs$$)})):$callback$$(null)})})},$e$$=>{if($e$$)return $fn$$($e$$);$bang_gia$$.joinModel2($id_app$$,
|
|
35
|
-
dmvt,[{where:"ma_vt",fields:"ten_vt"}],()=>{$fn$$(null,$bang_gia$$)})})})})})})})})})}else $fn$$("L\u1ed7i: T\u00ednh n\u0103ng n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: tu_thang,den_thang,nam,id_app")};
|
|
18
|
+
$d$$.tien_xuat=$d$$.tien_xuat_nt=Math.roundBy(($d$$.sl_xuat||$d$$.sl_km||0)*$d$$.gia_von,$f_tien$$)})()))})());await $voucher_x$$.details.filter($d$$=>$d$$.combo&&0<$d$$.combo.length).map($d$jscomp$0$$=>(async()=>{const $combo$$=$d$jscomp$0$$.combo.filter($d$$=>(!$condition$$.ma_vt||$condition$$.ma_vt===$d$$.ma_vt)&&!$d$$.px_gia_dd&&(!$ma_kho$$||$ma_kho$$===($d$$.ma_kho||$voucher_x$$.ma_kho||$voucher_x$$.ma_kho_x)));await Promise.all($combo$$.map($d$$=>(async()=>{var $gia$jscomp$5_gia_chuan$$=underscore.find($bang_gia$$,
|
|
19
|
+
$vt$$=>$d$$.ma_vt===$vt$$.ma_vt);$gia$jscomp$5_gia_chuan$$=$gia$jscomp$5_gia_chuan$$?$gia$jscomp$5_gia_chuan$$.gia:0;let $he_so_qd$$=1,$qd$$=await dmqddvt.findOne({id_app:$voucher_x$$.id_app,ma_vt:$d$$.ma_vt,ma_dvt:$d$$.ma_dvt}).lean();$qd$$&&($he_so_qd$$=$qd$$.mau?$qd$$.tu/$qd$$.mau:$qd$$.ty_le_qd);$d$$.gia_von=$d$$.gia_von_nt=$gia$jscomp$5_gia_chuan$$*$he_so_qd$$;$d$$.tien_xuat=$d$$.tien_xuat_nt=Math.roundBy(($d$$.sl_xuat||0)*$d$$.gia_von,$f_tien$$)})()))})());$voucher_x$$.promotion&&($details_details_doi_details_kmc$$=
|
|
20
|
+
$voucher_x$$.promotion.filter($d$$=>(!$condition$$.ma_vt||$condition$$.ma_vt===$d$$.ma_vt)&&!$d$$.px_gia_dd&&(!$ma_kho$$||$ma_kho$$===($d$$.ma_kho||$voucher_x$$.ma_kho||$voucher_x$$.ma_kho_x))),await Promise.all($details_details_doi_details_kmc$$.map($d$$=>(async()=>{var $gia$jscomp$6_gia_chuan$$=underscore.find($bang_gia$$,$vt$$=>$d$$.ma_vt===$vt$$.ma_vt);$gia$jscomp$6_gia_chuan$$=$gia$jscomp$6_gia_chuan$$?$gia$jscomp$6_gia_chuan$$.gia:0;let $he_so_qd$$=1,$qd$$=await dmqddvt.findOne({id_app:$voucher_x$$.id_app,
|
|
21
|
+
ma_vt:$d$$.ma_vt,ma_dvt:$d$$.ma_dvt}).lean();$qd$$&&($he_so_qd$$=$qd$$.mau?$qd$$.tu/$qd$$.mau:$qd$$.ty_le_qd);$d$$.gia_von_nt=$gia$jscomp$6_gia_chuan$$*$he_so_qd$$;$d$$.gia_von=$d$$.gia_von_nt;$d$$.tien_xuat_nt=Math.roundBy(($d$$.sl_xuat||$d$$.sl_km||0)*$d$$.gia_von,$f_tien$$);$d$$.tien_xuat=$d$$.tien_xuat_nt})())));await $voucher_x$$.save();let $voucher_x_data$$=$voucher_x$$.toObject(),$ctrl$$=global.controllers[$voucher_x_data$$.ma_ct.toUpperCase()];$ctrl$$&&$ctrl$$.post&&await (async()=>new Promise(($resolve$$,
|
|
22
|
+
$reject$$)=>{Controller.postData($voucher_x_data$$,$ctrl$$,($e$$,$rs$$)=>{if($e$$)return console.error("error repost khi tinh gia trung binh",$e$$,$voucher_x_data$$),$reject$$($e$$);$resolve$$($rs$$)})}))()})().then($rs$$=>{$callback$$(null,$rs$$)}).catch($e$$=>{$callback$$($e$$)})})},$error$$=>{$callback$jscomp$0$$($error$$,$vouchers_x$$)})},function($_vouchers_x$$,$callback$jscomp$0$$){async.mapSeries(underscore.values($vouchers_n$$),($voucher_n$$,$callback$$)=>{setImmediate(()=>{(async()=>{var $details_doi$$=
|
|
23
|
+
$voucher_n$$.details.filter($d$$=>(!$condition$$.ma_vt||$condition$$.ma_vt===$d$$.ma_vt)&&($d$$.pn_gia_tb||"PNC"===$voucher_n$$.ma_ct&&!$d$$.px_gia_dd||"PKK"===$voucher_n$$.ma_ct&&!$d$$.px_gia_dd)&&(!$ma_kho$$||$ma_kho$$===$d$$.ma_kho||$ma_kho$$===$voucher_n$$.ma_kho||$ma_kho$$===$voucher_n$$.ma_kho_n));await Promise.all($details_doi$$.map($d$$=>(async()=>{var $gia$jscomp$7_gia_chuan$$=underscore.find($bang_gia$$,$vt$$=>$d$$.ma_vt===$vt$$.ma_vt);$gia$jscomp$7_gia_chuan$$=$gia$jscomp$7_gia_chuan$$?
|
|
24
|
+
$gia$jscomp$7_gia_chuan$$.gia:0;let $he_so_qd$$=1,$qd$$=await dmqddvt.findOne({id_app:$vouchers_n$$.id_app,ma_vt:$d$$.ma_vt,ma_dvt:$d$$.ma_dvt}).lean();$qd$$&&($he_so_qd$$=$qd$$.mau?$qd$$.tu/$qd$$.mau:$qd$$.ty_le_qd);$d$$.gia_von_nt=$gia$jscomp$7_gia_chuan$$*$he_so_qd$$;$d$$.gia_von=$d$$.gia_von_nt;"PNC"===$voucher_n$$.ma_ct||"PKK"===$voucher_n$$.ma_ct?($d$$.tien_xuat_nt=Math.roundBy($d$$.sl_xuat*$d$$.gia_von,$f_tien$$),$d$$.tien_xuat=$d$$.tien_xuat_nt):($d$$.tien_nhap_nt=Math.roundBy($d$$.sl_nhap*
|
|
25
|
+
$d$$.gia_von,$f_tien$$),$d$$.tien_nhap=$d$$.tien_nhap_nt)})()));$voucher_n$$.details_doi&&($details_doi$$=$voucher_n$$.details_doi.filter($d$$=>(!$condition$$.ma_vt||$condition$$.ma_vt===$d$$.ma_vt)&&$d$$.pn_gia_tb&&(!$ma_kho$$||$ma_kho$$===$d$$.ma_kho)),await Promise.all($details_doi$$.map($d$$=>(async()=>{var $gia$jscomp$8_gia_chuan$$=underscore.find($bang_gia$$,$vt$$=>$d$$.ma_vt===$vt$$.ma_vt);$gia$jscomp$8_gia_chuan$$=$gia$jscomp$8_gia_chuan$$?$gia$jscomp$8_gia_chuan$$.gia:0;let $he_so_qd$$=1,
|
|
26
|
+
$qd$$=await dmqddvt.findOne({id_app:$vouchers_n$$.id_app,ma_vt:$d$$.ma_vt,ma_dvt:$d$$.ma_dvt}).lean();$qd$$&&($he_so_qd$$=$qd$$.mau?$qd$$.tu/$qd$$.mau:$qd$$.ty_le_qd);$d$$.gia_von_nt=$gia$jscomp$8_gia_chuan$$*$he_so_qd$$;$d$$.gia_von=$d$$.gia_von_nt;$d$$.tien_xuat_nt=Math.roundBy($d$$.sl_xuat*$d$$.gia_von,$f_tien$$);$d$$.tien_xuat=$d$$.tien_xuat_nt})())));await $voucher_n$$.save();let $voucher_n_data$$=$voucher_n$$.toObject(),$ctrl$$=global.controllers[$voucher_n_data$$.ma_ct.toUpperCase()];$ctrl$$&&
|
|
27
|
+
$ctrl$$.post&&await (async()=>new Promise(($resolve$$,$reject$$)=>{Controller.postData($voucher_n_data$$,$ctrl$$,function($e$$,$rs$$){if($e$$)return console.error("error repost khi tinh gia trung binh",$e$$,$voucher_n_data$$),$reject$$($e$$);$resolve$$($rs$$)})}))()})().then($rs$$=>{$callback$$(null,$rs$$)}).catch($e$$=>{$callback$$($e$$)})})},function($error$$){$callback$jscomp$0$$($error$$)})}],function($e$jscomp$1$$){if($e$jscomp$1$$)return $fn$$($e$jscomp$1$$);$e$jscomp$1$$={id_app:$condition$$.id_app,
|
|
28
|
+
ngay:$den_ngay$$,chenh_lech:1};$condition$$.ma_vt&&($e$jscomp$1$$.ma_vt=$condition$$.ma_vt);$condition$$.ma_kho&&($e$jscomp$1$$.ma_kho=$condition$$.ma_kho);ckvt($e$jscomp$1$$,($e$jscomp$0$$,$rs$jscomp$0$$)=>{if($e$jscomp$0$$)return $fn$$($e$jscomp$0$$);$rs$jscomp$0$$=underscore.filter($rs$jscomp$0$$,$r$$=>0!==$r$$.du00&&(0==$r$$.ton00||.001>Math.abs($r$$.ton00)));$vouchers_x$$=underscore.sortBy(underscore.values($vouchers_x$$),$v$$=>-(new Date($v$$.ngay_ct)).getTime());$vouchers_n$$=underscore.sortBy(underscore.values($vouchers_n$$),
|
|
29
|
+
$v$$=>-(new Date($v$$.ngay_ct)).getTime());let $chung_tu_cap_nhat_chenh_lech$$={};async.mapSeries($rs$jscomp$0$$,($vt$$,$callback$$)=>{setImmediate(()=>{let $d_voucher$$=null;($d_voucher$$=underscore.find($vouchers_x$$,$x$$=>underscore.find($x$$.details,$vc$$=>{if($vc$$.ma_vt!=$vt$$.ma_vt||$vc$$.px_gia_dd||$ma_kho$$&&$ma_kho$$!==$vc$$.ma_kho&&$ma_kho$$!==$x$$.ma_kho)return!1;$vc$$.tien_xuat_nt+=$vt$$.du00;$vc$$.tien_xuat=Math.roundBy($vc$$.tien_xuat_nt,$f_tien$$);$vc$$.sl_xuat&&($vc$$.gia_von_nt=
|
|
30
|
+
$vc$$.gia_von=Math.roundBy($vc$$.tien_xuat_nt/$vc$$.sl_xuat,0));return!0})))||($d_voucher$$=underscore.find($vouchers_n$$,$n$$=>underscore.find($n$$.details,$vc$$=>{if($vc$$.ma_vt!=$vt$$.ma_vt||$vc$$.pn_gia_tb||$ma_kho$$&&$ma_kho$$!==$vc$$.ma_kho&&$ma_kho$$!==$n$$.ma_kho)return!1;$vc$$.tien_nhap_nt-=$vt$$.du00;$vc$$.tien_nhap=Math.roundBy($vc$$.tien_nhap_nt,$f_tien$$);$vc$$.sl_nhap&&($vc$$.gia_von_nt=$vc$$.gia_von=Math.roundBy($vc$$.tien_nhap_nt/$vc$$.sl_nhap,0));return!0})));$d_voucher$$&&($chung_tu_cap_nhat_chenh_lech$$[$d_voucher$$._id.toString()]=
|
|
31
|
+
$d_voucher$$);$callback$$(null,$d_voucher$$)})},$_vouchers_chenh_lech_e$$=>{if($_vouchers_chenh_lech_e$$)return $fn$$($_vouchers_chenh_lech_e$$);$_vouchers_chenh_lech_e$$=underscore.values($chung_tu_cap_nhat_chenh_lech$$);async.mapSeries($_vouchers_chenh_lech_e$$,($voucher$$,$callback$$)=>{setImmediate(()=>{$voucher$$.save($ctrl$jscomp$2_error$$=>{if($ctrl$jscomp$2_error$$)return $callback$$($ctrl$jscomp$2_error$$);let $voucher_data$$=$voucher$$.toObject();($ctrl$jscomp$2_error$$=global.controllers[$voucher_data$$.ma_ct.toUpperCase()])&&
|
|
32
|
+
$ctrl$jscomp$2_error$$.post?Controller.postData($voucher_data$$,$ctrl$jscomp$2_error$$,($e$$,$rs$$)=>{$e$$&&console.error("error repost khi tinh gia trung binh",$e$$,$voucher_data$$);$callback$$($e$$,$rs$$)}):$callback$$(null)})})},$e$$=>{if($e$$)return $fn$$($e$$);$bang_gia$$.joinModel2($id_app$$,dmvt,[{where:"ma_vt",fields:"ten_vt"}],()=>{$fn$$(null,$bang_gia$$)})})})})})})})})})}else $fn$$("L\u1ed7i: T\u00ednh n\u0103ng n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: tu_thang,den_thang,nam,id_app")};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';const dkvt=require("./dkvt"),sokho=global.getModel("sokho"),async=require("async");
|
|
2
2
|
module.exports=function($condition$$,$fn$$){if($condition$$&&$condition$$.ma_vt&&$condition$$.tu_ngay&&$condition$$.den_ngay&&$condition$$.id_app){var $ma_vt$$=$condition$$.ma_vt,$tu_ngay$$=$condition$$.tu_ngay,$den_ngay$$=$condition$$.den_ngay,$id_app$$=$condition$$.id_app;async.series({dn:function($callback$$){let $query$$={ngay:$tu_ngay$$,id_app:$id_app$$};$condition$$.ma_kho&&($query$$.ma_kho=$condition$$.ma_kho);$query$$.ma_vt=$condition$$.ma_vt;dkvt($query$$,function($error$$,$du_dau_result$$){if($error$$)return $callback$$($error$$);
|
|
3
|
-
$error$$=$du_dau_result$$.csum("ton00");$du_dau_result$$=$du_dau_result$$.csum("du00");$callback$$(null,{ton_dau:$error$$,du_dau:$du_dau_result$$})})},ps:function($callback$$){let $query$$={id_app:$id_app$$,pn_gia_tb:!1,ngay_ct:{$gte:$tu_ngay$$,$lt:$den_ngay$$},ma_vt:$ma_vt
|
|
4
|
-
$ps$$.
|
|
5
|
-
du_dau:$results$$.dn.du_dau,sl_nhap:$results$$.ps.sl_nhap,tien_nhap:$results$$.ps.tien_nhap,tong_sl:$error$$,tong_tien:$tong_tien$$,gia:$gia$$})}})}else $fn$$("L\u1ed7i: B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: tu_ngay,den_ngay,id_app,ma_vt")};
|
|
3
|
+
$error$$=$du_dau_result$$.csum("ton00");$du_dau_result$$=$du_dau_result$$.csum("du00");$callback$$(null,{ton_dau:$error$$,du_dau:$du_dau_result$$})})},ps:function($callback$$){let $query$$={id_app:$id_app$$,pn_gia_tb:!1,ngay_ct:{$gte:$tu_ngay$$,$lt:$den_ngay$$},ma_vt:$ma_vt$$,$or:[{nxt:1},{nxt:2,px_gia_dd:!0}]};$condition$$.ma_kho&&($query$$.ma_kho=$condition$$.ma_kho);sokho.find($query$$).lean().exec(function($error$$,$pss_tien_nhap$$){$error$$?$callback$$($error$$):($pss_tien_nhap$$=$pss_tien_nhap$$.map($ps$$=>
|
|
4
|
+
{$ps$$.sl_nhap=($ps$$.sl_nhap_qd||0)-($ps$$.sl_xuat_qd||0);return $ps$$}),$error$$=$pss_tien_nhap$$.csum("sl_nhap"),$pss_tien_nhap$$=$pss_tien_nhap$$.csum("tien_nhap")-$pss_tien_nhap$$.csum("tien_xuat"),$callback$$(null,{sl_nhap:$error$$,tien_nhap:$pss_tien_nhap$$}))})}},function($error$$,$results$$){if($error$$)$fn$$($error$$);else{$error$$=$results$$.ps.sl_nhap+$results$$.dn.ton_dau;var $tong_tien$$=$results$$.ps.tien_nhap+$results$$.dn.du_dau,$gia$$=$error$$?Math.roundBy($tong_tien$$/$error$$,
|
|
5
|
+
0):0;return $fn$$(null,{ma_vt:$ma_vt$$,ton_dau:$results$$.dn.ton_dau,du_dau:$results$$.dn.du_dau,sl_nhap:$results$$.ps.sl_nhap,tien_nhap:$results$$.ps.tien_nhap,tong_sl:$error$$,tong_tien:$tong_tien$$,gia:$gia$$})}})}else $fn$$("L\u1ed7i: B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: tu_ngay,den_ngay,id_app,ma_vt")};
|