flexbiz-server 12.5.45 → 12.5.46

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.
Files changed (50) hide show
  1. package/package.json +1 -1
  2. package/server/app.js +1 -1
  3. package/server/cluster.js +1 -1
  4. package/server/controllers/controllerRPT.js +2 -2
  5. package/server/controllers/controllerUtils.js +1 -1
  6. package/server/controllers/createHandler.js +11 -11
  7. package/server/controllers/importFromExcelHandler.js +2 -2
  8. package/server/controllers/importFromGsHandler.js +4 -4
  9. package/server/controllers/importFromJsonHandler.js +3 -3
  10. package/server/controllers/importHandler.js +13 -12
  11. package/server/controllers/updateHandler.js +38 -37
  12. package/server/libs/cdpskh.js +7 -7
  13. package/server/libs/ckcn.js +5 -5
  14. package/server/libs/dkcn.js +6 -6
  15. package/server/libs/kpistatus.js +31 -27
  16. package/server/libs/queryBuilding.js +10 -9
  17. package/server/libs/sessionContext.js +2 -2
  18. package/server/libs/tinhGt.js +8 -6
  19. package/server/libs/tinhGtCapnhatPNK.js +5 -5
  20. package/server/libs/tinhGtPhanboHeSo.js +9 -9
  21. package/server/libs/tinhGtPhanboYtcp.js +10 -10
  22. package/server/libs/tinhGtSltk.js +8 -8
  23. package/server/libs/tinhGtThcppstk.js +8 -8
  24. package/server/libs/tinhGtTrucTiep.js +6 -5
  25. package/server/libs/tinhGtXoa.js +1 -1
  26. package/server/libs/tinhgiatb.js +30 -38
  27. package/server/libs/tinhgiatb_old.js +39 -0
  28. package/server/libs/vsocai.js +3 -4
  29. package/server/models/chitietluongds.js +13 -0
  30. package/server/models/log.js +3 -3
  31. package/server/models/socai.js +10 -9
  32. package/server/modules/lists/ls-bds_dmnhbds.js +6 -5
  33. package/server/modules/lists/ls-chitietluongds.js +4 -0
  34. package/server/modules/lists/ls-dmbp.js +2 -2
  35. package/server/modules/lists/ls-dmdt.js +2 -2
  36. package/server/modules/lists/ls-dmnckkm.js +1 -1
  37. package/server/modules/lists/ls-dmnkh.js +5 -5
  38. package/server/modules/lists/ls-dmntt.js +3 -3
  39. package/server/modules/lists/ls-dmnvt.js +3 -3
  40. package/server/modules/lists/ls-dmphi.js +5 -4
  41. package/server/modules/lists/ls-ecomcategories.js +5 -5
  42. package/server/modules/lists/ls-ecomcategories_cty.js +5 -5
  43. package/server/modules/lists/ls-group.js +5 -5
  44. package/server/modules/lists/ls-usergroup.js +5 -5
  45. package/server/modules/reports/calc-tinhgiatb.js +6 -5
  46. package/server/modules/reports/calc-tinhgiathanh.js +6 -5
  47. package/server/modules/reports/calc-tinhluong.js +29 -29
  48. package/server/modules/reports/rp-sosanhkhvatt2.js +3 -3
  49. package/server/modules/systems/sys-app.js +11 -10
  50. package/server/workers/restoreApp.js +1 -1
@@ -2,9 +2,9 @@ const Vsocai=require("./vsocai"),dstkcn=require("./dstkcn"),async=require("async
2
2
  module.exports=async function($condition$$,$fn$$,$options$$={model:"socaitc"}){if($condition$$&&$condition$$.ngay&&$condition$$.id_app){if(!$condition$$.ma_kh&&($condition$$.nh_kh||$condition$$.phu_trach)){let $_q$$={};$condition$$.nh_kh&&($_q$$.nh_kh=$condition$$.nh_kh);$condition$$.phu_trach&&($_q$$.phu_trach=$condition$$.phu_trach);$condition$$.ma_kh=await global.getModel("customer").getList($condition$$.id_app,$_q$$,"ma_kh")}var $tk$$=$condition$$.tk;$tk$$||="";if(underscore.isArray($tk$$)){let $tks$$;
3
3
  $tk$$.forEach(function($t$$){$tks$$=$tks$$?$tks$$+"|^"+$t$$:"^"+$t$$});$tks$$||="^";$tk$$={$regex:$tks$$,$options:"i"}}else $tk$$={$regex:"^"+$tk$$,$options:"i"};var $id_app$$=$condition$$.id_app,$ngay$$=new Date($condition$$.ngay);$ngay$$=moment($ngay$$).startOf("date").toDate();if(!await global.getModel("app").findOne({_id:$id_app$$},{ngay_ks:1}).lean())return $fn$$("C\u00f4ng ty kh\u00f4ng t\u1ed3n t\u1ea1i");var $ngay_ks$$=(await global.getModel("cdkhtheongay").findOne({id_app:$id_app$$,den_ngay:{$lte:moment($ngay$$).startOf("date").toDate()}},
4
4
  {den_ngay:1}).sort({den_ngay:-1}).lean()||{}).den_ngay;$ngay_ks$$&&=moment($ngay_ks$$).endOf("date").toDate();var $ngay_dn$$=moment($ngay$$).startOf("year").toDate();if(!$ngay_ks$$||$ngay_ks$$<$ngay_dn$$){var $Cdkh$$=global.getModel("cdkh");var $nam$$=$ngay$$.getFullYear()}else $Cdkh$$=global.getModel("cdkhtheongay"),$ngay_dn$$=moment($ngay_ks$$).startOf("date").add(1,"days").toDate();async.parallel({dn:function($callback$$){let $c_dk$$={id_app:$id_app$$,tk:$tk$$};$nam$$?$c_dk$$.nam=$nam$$:(console.log("lay cdcn theo ngay khoa so",
5
- $ngay_ks$$),$c_dk$$.den_ngay=$ngay_ks$$);$condition$$.ma_kh&&(underscore.isArray($condition$$.ma_kh)?$c_dk$$.ma_kh={$in:$condition$$.ma_kh}:$c_dk$$.ma_kh=$condition$$.ma_kh);$condition$$.ma_dvcs&&($c_dk$$.ma_dvcs=$condition$$.ma_dvcs);$condition$$.ma_kho&&($c_dk$$.ma_kho=$condition$$.ma_kho);$condition$$.ma_bp&&($c_dk$$.ma_bp=$condition$$.ma_bp);$condition$$.ma_phi&&($c_dk$$.ma_phi=$condition$$.ma_phi);$condition$$.ma_nv&&($c_dk$$.ma_nv=$condition$$.ma_nv);$condition$$.ma_hd&&($c_dk$$.ma_hd=$condition$$.ma_hd);
6
- $condition$$.ma_dt&&($c_dk$$.ma_dt=$condition$$.ma_dt);$Cdkh$$.find($c_dk$$).lean().then(function($results$$){$callback$$(null,$results$$)}).catch($error$$=>{$callback$$({message:$error$$.message})})},ps:function($callback$$){async.waterfall([function($callback1$$){dstkcn($id_app$$,$tk$$,function($error$$,$accs$$){$error$$?$callback1$$($error$$):$callback1$$(null,$accs$$)})},function($accs$$,$callback1$$){$accs$$={id_app:$id_app$$,ngay_ct:{$gte:$ngay_dn$$,$lt:$ngay$$},tk:{$in:$accs$$}};$condition$$.ma_kh&&
7
- (underscore.isArray($condition$$.ma_kh)?$accs$$.ma_kh={$in:$condition$$.ma_kh}:$accs$$.ma_kh=$condition$$.ma_kh);$condition$$.ma_dvcs&&($accs$$.ma_dvcs=$condition$$.ma_dvcs);$condition$$.ma_kho&&($accs$$.ma_kho=$condition$$.ma_kho);$condition$$.ma_bp&&($accs$$.ma_bp=$condition$$.ma_bp);$condition$$.ma_phi&&($accs$$.ma_phi=$condition$$.ma_phi);$condition$$.ma_nv&&($accs$$.ma_nv=$condition$$.ma_nv);$condition$$.ma_hd&&($accs$$.ma_hd=$condition$$.ma_hd);$condition$$.ma_dt&&($accs$$.ma_dt=$condition$$.ma_dt);
8
- $condition$$.ex_id_ct&&($accs$$.id_ct={$ne:$condition$$.ex_id_ct});Vsocai.find($accs$$,function($error$$,$pss$$){$error$$?$callback1$$($error$$):$callback1$$(null,$pss$$)},$options$$)}],function($error$$,$result$$){$error$$?$callback$$($error$$):$callback$$(null,$result$$)})}},function($data_error$$,$groupBy_results$$){if($data_error$$)return $fn$$($data_error$$);$data_error$$=$groupBy_results$$.dn.concat($groupBy_results$$.ps);$groupBy_results$$=$condition$$.groupBy||"tk ma_kh ma_kho ma_bp ma_phi ma_dt ma_hd ma_nv".split(" ");
9
- if(!underscore.isArray($groupBy_results$$))if($groupBy_results$$.indexOf("[")>=0)try{$groupBy_results$$=JSON.parse($groupBy_results$$)}catch($e$$){console.error("err parse json groupby",$groupBy_results$$),$groupBy_results$$=[$groupBy_results$$]}else $groupBy_results$$=$groupBy_results$$.indexOf(",")>=0?$groupBy_results$$.split(","):[$groupBy_results$$];$data_error$$.groupBy($groupBy_results$$,"du_no00 du_co00 du_no_nt00 du_co_nt00 ps_no ps_co ps_no_nt ps_co_nt".split(" "),($error$$,$rs$$)=>{$error$$?
10
- $fn$$($error$$):($rs$$.forEach($r$$=>{$r$$.du_no00=$r$$.du_no00+$r$$.ps_no-$r$$.du_co00-$r$$.ps_co;$r$$.du_no_nt00=$r$$.du_no_nt00+$r$$.ps_no_nt-$r$$.du_co_nt00-$r$$.ps_co_nt;$r$$.du_co00=0-$r$$.du_no00;$r$$.du_co_nt00=0-$r$$.du_no_nt00;$r$$.du_no00<0&&($r$$.du_no00=0);$r$$.du_no_nt00<0&&($r$$.du_no_nt00=0);$r$$.du_co00<0&&($r$$.du_co00=0);$r$$.du_co_nt00<0&&($r$$.du_co_nt00=0);$r$$.ps_no_nt=0;$r$$.ps_co_nt=0;$r$$.ps_no=0;$r$$.ps_co=0}),$fn$$(null,$rs$$))})})}else $fn$$("Ch\u1ee9c n\u0103ng n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: ngay")};
5
+ $ngay_ks$$),$c_dk$$.den_ngay=$ngay_ks$$);$condition$$.ma_kh&&(underscore.isArray($condition$$.ma_kh)&&$condition$$.ma_kh.length>0?$c_dk$$.ma_kh={$in:$condition$$.ma_kh}:$c_dk$$.ma_kh=$condition$$.ma_kh);$condition$$.ma_dvcs&&($c_dk$$.ma_dvcs=$condition$$.ma_dvcs);$condition$$.ma_kho&&($c_dk$$.ma_kho=$condition$$.ma_kho);$condition$$.ma_bp&&($c_dk$$.ma_bp=$condition$$.ma_bp);$condition$$.ma_phi&&($c_dk$$.ma_phi=$condition$$.ma_phi);$condition$$.ma_nv&&($c_dk$$.ma_nv=$condition$$.ma_nv);$condition$$.ma_hd&&
6
+ ($c_dk$$.ma_hd=$condition$$.ma_hd);$condition$$.ma_dt&&($c_dk$$.ma_dt=$condition$$.ma_dt);$Cdkh$$.find($c_dk$$).lean().then(function($results$$){$callback$$(null,$results$$)}).catch($error$$=>{$callback$$({message:$error$$.message})})},ps:function($callback$$){async.waterfall([function($callback1$$){dstkcn($id_app$$,$tk$$,function($error$$,$accs$$){$error$$?$callback1$$($error$$):$callback1$$(null,$accs$$)})},function($accs$$,$callback1$$){$accs$$={id_app:$id_app$$,ngay_ct:{$gte:$ngay_dn$$,$lt:$ngay$$},
7
+ tk:{$in:$accs$$}};$condition$$.ma_kh&&(underscore.isArray($condition$$.ma_kh)&&$condition$$.ma_kh.length>0?$accs$$.ma_kh={$in:$condition$$.ma_kh}:$accs$$.ma_kh=$condition$$.ma_kh);$condition$$.ma_dvcs&&($accs$$.ma_dvcs=$condition$$.ma_dvcs);$condition$$.ma_kho&&($accs$$.ma_kho=$condition$$.ma_kho);$condition$$.ma_bp&&($accs$$.ma_bp=$condition$$.ma_bp);$condition$$.ma_phi&&($accs$$.ma_phi=$condition$$.ma_phi);$condition$$.ma_nv&&($accs$$.ma_nv=$condition$$.ma_nv);$condition$$.ma_hd&&($accs$$.ma_hd=
8
+ $condition$$.ma_hd);$condition$$.ma_dt&&($accs$$.ma_dt=$condition$$.ma_dt);$condition$$.ex_id_ct&&($accs$$.id_ct={$ne:$condition$$.ex_id_ct});Vsocai.find($accs$$,function($error$$,$pss$$){$error$$?$callback1$$($error$$):$callback1$$(null,$pss$$)},$options$$)}],function($error$$,$result$$){$error$$?$callback$$($error$$):$callback$$(null,$result$$)})}},function($data_error$$,$groupBy_results$$){if($data_error$$)return $fn$$($data_error$$);$data_error$$=$groupBy_results$$.dn.concat($groupBy_results$$.ps);
9
+ $groupBy_results$$=$condition$$.groupBy||"tk ma_kh ma_kho ma_bp ma_phi ma_dt ma_hd ma_nv".split(" ");if(!underscore.isArray($groupBy_results$$))if($groupBy_results$$.indexOf("[")>=0)try{$groupBy_results$$=JSON.parse($groupBy_results$$)}catch($e$$){console.error("err parse json groupby",$groupBy_results$$),$groupBy_results$$=[$groupBy_results$$]}else $groupBy_results$$=$groupBy_results$$.indexOf(",")>=0?$groupBy_results$$.split(","):[$groupBy_results$$];$data_error$$.groupBy($groupBy_results$$,"du_no00 du_co00 du_no_nt00 du_co_nt00 ps_no ps_co ps_no_nt ps_co_nt".split(" "),
10
+ ($error$$,$rs$$)=>{$error$$?$fn$$($error$$):($rs$$.forEach($r$$=>{$r$$.du_no00=$r$$.du_no00+$r$$.ps_no-$r$$.du_co00-$r$$.ps_co;$r$$.du_no_nt00=$r$$.du_no_nt00+$r$$.ps_no_nt-$r$$.du_co_nt00-$r$$.ps_co_nt;$r$$.du_co00=0-$r$$.du_no00;$r$$.du_co_nt00=0-$r$$.du_no_nt00;$r$$.du_no00<0&&($r$$.du_no00=0);$r$$.du_no_nt00<0&&($r$$.du_no_nt00=0);$r$$.du_co00<0&&($r$$.du_co00=0);$r$$.du_co_nt00<0&&($r$$.du_co_nt00=0);$r$$.ps_no_nt=0;$r$$.ps_co_nt=0;$r$$.ps_no=0;$r$$.ps_co=0}),$fn$$(null,$rs$$))})})}else $fn$$("Ch\u1ee9c n\u0103ng n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: ngay")};
@@ -1,32 +1,36 @@
1
1
  const socai=global.getModel("socai"),ctds=global.getModel("ctds2"),dmbp=global.getModel("dmbp"),dmdt=global.getModel("dmdt"),dmphi=global.getModel("dmphi"),async=require("async"),_=require("lodash"),moment=require("moment"),{getCodeChildren}=require("./utils"),databanle=require("./databanle"),tinhHoaHong=async($ct$$,$query$$,$callback$$)=>{if(!$ct$$.chinh_sach_hoa_hong||$ct$$.chinh_sach_hoa_hong.length==0)return $callback$$();$ct$$.chinh_sach_hoa_hong=$ct$$.chinh_sach_hoa_hong.filter($cs$$=>$cs$$.ty_le_ht_tu<=
2
2
  $ct$$.ty_le_ht&&(!$cs$$.ty_le_ht_den||$cs$$.ty_le_ht_den>$ct$$.ty_le_ht));async.mapLimit($ct$$.chinh_sach_hoa_hong,20,($cs$$,$callback$$)=>{$ct$$.ma_kho&&!$cs$$.ma_kho&&($cs$$.ma_kho=$ct$$.ma_kho);$ct$$.ma_nv&&!$cs$$.ma_nv&&($cs$$.ma_nv=$ct$$.ma_nv);$cs$$.quan_ly=$ct$$.quan_ly;$ct$$.__in_ma_bp__&&!$cs$$.ma_bp&&($cs$$.__in_ma_bp__=$ct$$.__in_ma_bp__);$ct$$.__in_ma_dt__&&!$cs$$.ma_dt&&($cs$$.__in_ma_dt__=$ct$$.__in_ma_dt__);$ct$$.__in_ma_phi__&&!$cs$$.ma_phi&&($cs$$.__in_ma_phi__=$ct$$.__in_ma_phi__);
3
3
  setImmediate(async()=>{switch($cs$$.cach_tinh){case "0":$cs$$.ps_tinh_hoa_hong=$ct$$.ps;$cs$$.tien_hoa_hong=Math.roundBy($cs$$.ps_tinh_hoa_hong*$cs$$.ty_le_hoa_hong/100,0);$callback$$();break;case "1":await calcSoCai($cs$$,_.cloneDeep($query$$),($e$$,$ps_tinh_hoa_hong$$)=>{if($e$$)return $callback$$($e$$);$cs$$.ps_tinh_hoa_hong=$ps_tinh_hoa_hong$$;$cs$$.tien_hoa_hong=Math.roundBy($cs$$.ps_tinh_hoa_hong*$cs$$.ty_le_hoa_hong/100,0);$callback$$()});break;case "2":await calcDoanhThu($cs$$,_.cloneDeep($query$$),
4
- ($e$$,$ps_tinh_hoa_hong$$)=>{if($e$$)return $callback$$($e$$);$cs$$.ps_tinh_hoa_hong=$ps_tinh_hoa_hong$$;$cs$$.tien_hoa_hong=Math.roundBy($cs$$.ps_tinh_hoa_hong*$cs$$.ty_le_hoa_hong/100,0);$callback$$()},{doanh_thu_tinh_hoa_hong:!0});break;default:$callback$$()}})},$e$$=>{if($e$$)return $callback$$($e$$);$callback$$()})},calcSoCai=async($ct$$,$query$$,$callback$$)=>{$ct$$.ma_kho&&($query$$.ma_kho=$ct$$.ma_kho);$ct$$.ma_nv&&($query$$.ma_nv=$ct$$.ma_nv);if($ct$$.__in_ma_bp__)$query$$.ma_bp=$ct$$.__in_ma_bp__;
5
- else if($ct$$.ma_bp){var $bps_custs_dts_nh_khs_nh_vts_phis_vts$$=await getCodeChildren(dmbp,$query$$.id_app,$ct$$.ma_bp,"ma_bp","ma_bp_me");$query$$.ma_bp={$in:$bps_custs_dts_nh_khs_nh_vts_phis_vts$$};$ct$$.__in_ma_bp__={$in:$bps_custs_dts_nh_khs_nh_vts_phis_vts$$}}$ct$$.quan_ly&&$query$$.ma_nv&&($query$$.ma_nv={$ne:$query$$.ma_nv});$ct$$.__in_ma_dt__?$query$$.ma_dt=$ct$$.__in_ma_dt__:$ct$$.ma_dt&&($bps_custs_dts_nh_khs_nh_vts_phis_vts$$=await getCodeChildren(dmdt,$query$$.id_app,$ct$$.ma_dt,"ma_dt",
6
- "ma_dt_me"),$query$$.ma_dt={$in:$bps_custs_dts_nh_khs_nh_vts_phis_vts$$},$ct$$.__in_ma_dt__={$in:$bps_custs_dts_nh_khs_nh_vts_phis_vts$$});$ct$$.__in_ma_phi__?$query$$.ma_phi=$ct$$.__in_ma_phi__:$ct$$.ma_phi&&($bps_custs_dts_nh_khs_nh_vts_phis_vts$$=await getCodeChildren(dmphi,$query$$.id_app,$ct$$.ma_phi,"ma_phi","ma_phi_me"),$query$$.ma_phi={$in:$bps_custs_dts_nh_khs_nh_vts_phis_vts$$},$ct$$.__in_ma_phi__={$in:$bps_custs_dts_nh_khs_nh_vts_phis_vts$$});!$ct$$.ma_kh&&$ct$$.nh_kh&&$ct$$.nh_kh.length>
7
- 0&&($bps_custs_dts_nh_khs_nh_vts_phis_vts$$=await global.getModel("group").getAllChildrenGroup($query$$.id_app,$ct$$.nh_kh,{group_kind:1}),$bps_custs_dts_nh_khs_nh_vts_phis_vts$$=await global.getModel("customer").find({id_app:$query$$.id_app,nh_kh:{$in:$bps_custs_dts_nh_khs_nh_vts_phis_vts$$}},{ma_kh:1}),$query$$.ma_kh=$ct$$.nh_kh_lt?{$nin:$bps_custs_dts_nh_khs_nh_vts_phis_vts$$.map($r$$=>$r$$.ma_kh)}:{$in:$bps_custs_dts_nh_khs_nh_vts_phis_vts$$.map($r$$=>$r$$.ma_kh)});$ct$$.ma_nvt&&$ct$$.ma_nvt.length>
8
- 0&&($bps_custs_dts_nh_khs_nh_vts_phis_vts$$=await global.getModel("dmnvt").getAllChildrenGroup($query$$.id_app,$query$$.ma_nvt),$bps_custs_dts_nh_khs_nh_vts_phis_vts$$=await global.getModel("dmvt").find({id_app:$query$$.id_app,ma_nvt:{$in:$bps_custs_dts_nh_khs_nh_vts_phis_vts$$}},{ma_vt:1}),console.log("vts",$bps_custs_dts_nh_khs_nh_vts_phis_vts$$),$query$$.ma_vt=$ct$$.ma_nvt_lt?{$nin:$bps_custs_dts_nh_khs_nh_vts_phis_vts$$.map($r$$=>$r$$.ma_vt)}:{$in:$bps_custs_dts_nh_khs_nh_vts_phis_vts$$.map($r$$=>
9
- $r$$.ma_vt)});async.parallel({dt:$callback$$=>{let $_query$$=Object.assign({},$query$$);var $tks_co_tks_no$$=$ct$$.tk_no;$tks_co_tks_no$$&&!$ct$$.tk_no_gt&&(_.isArray($tks_co_tks_no$$)||($tks_co_tks_no$$=[$tks_co_tks_no$$]),$tks_co_tks_no$$.length>0&&($_query$$.tk_no={$regex:$tks_co_tks_no$$.reg(),$options:"i"}));($tks_co_tks_no$$=$ct$$.tk_co)&&!$ct$$.tk_co_gt&&(_.isArray($tks_co_tks_no$$)||($tks_co_tks_no$$=[$tks_co_tks_no$$]),$tks_co_tks_no$$.length>0&&($_query$$.tk_co={$regex:$tks_co_tks_no$$.reg(),
10
- $options:"i"}));socai.find($_query$$).lean().then($rs$$=>{$callback$$(null,$rs$$)}).catch($e$$=>{$callback$$($e$$)})},gt:$callback$$=>{if($ct$$.tk_no&&$ct$$.tk_no.length>0&&$ct$$.tk_no_gt||$ct$$.tk_co&&$ct$$.tk_co.length>0&&$ct$$.tk_co_gt){let $_query$$=Object.assign({},$query$$);var $tks_co$jscomp$1_tks_no$$=$ct$$.tk_no;$tks_co$jscomp$1_tks_no$$&&$ct$$.tk_no_gt&&(_.isArray($tks_co$jscomp$1_tks_no$$)||($tks_co$jscomp$1_tks_no$$=[$tks_co$jscomp$1_tks_no$$]),$tks_co$jscomp$1_tks_no$$.length>0&&($_query$$.tk_no=
11
- {$regex:$tks_co$jscomp$1_tks_no$$.reg(),$options:"i"}));($tks_co$jscomp$1_tks_no$$=$ct$$.tk_co)&&$ct$$.tk_co_gt&&(_.isArray($tks_co$jscomp$1_tks_no$$)||($tks_co$jscomp$1_tks_no$$=[$tks_co$jscomp$1_tks_no$$]),$tks_co$jscomp$1_tks_no$$.length>0&&($_query$$.tk_co={$regex:$tks_co$jscomp$1_tks_no$$.reg(),$options:"i"}));socai.find($_query$$).lean().then($rs$$=>{$callback$$(null,$rs$$)}).catch($error$$=>{$callback$$({message:$error$$.message})})}else $callback$$(null,[])}},($e$$,$rs$$)=>{if($e$$)return console.log("error get data giam tru",
12
- $e$$),$callback$$($e$$);$e$$=$rs$$.dt.csum("tien")-$rs$$.gt.csum("tien");$callback$$(null,$e$$)})},calcDoanhThu=async($_query$jscomp$2_ct$$,$query$$,$callback$$,$options$$={})=>{$_query$jscomp$2_ct$$.ma_kho&&($query$$.ma_kho=$_query$jscomp$2_ct$$.ma_kho);$_query$jscomp$2_ct$$.ma_nv&&($query$$.ma_nv=$_query$jscomp$2_ct$$.ma_nv);if($_query$jscomp$2_ct$$.__in_ma_bp__)$query$$.ma_bp=$_query$jscomp$2_ct$$.__in_ma_bp__;else if($_query$jscomp$2_ct$$.ma_bp){var $bps$jscomp$1_custs$jscomp$1_dts$jscomp$1_nh_khs$jscomp$1_nh_vts$jscomp$1_phis$jscomp$1_vts$$=
13
- await getCodeChildren(dmbp,$query$$.id_app,$_query$jscomp$2_ct$$.ma_bp,"ma_bp","ma_bp_me");$query$$.ma_bp={$in:$bps$jscomp$1_custs$jscomp$1_dts$jscomp$1_nh_khs$jscomp$1_nh_vts$jscomp$1_phis$jscomp$1_vts$$};$_query$jscomp$2_ct$$.__in_ma_bp__={$in:$bps$jscomp$1_custs$jscomp$1_dts$jscomp$1_nh_khs$jscomp$1_nh_vts$jscomp$1_phis$jscomp$1_vts$$}}$_query$jscomp$2_ct$$.quan_ly&&$query$$.ma_nv&&($query$$.ma_nv={$ne:$query$$.ma_nv});$_query$jscomp$2_ct$$.__in_ma_dt__?$query$$.ma_dt=$_query$jscomp$2_ct$$.__in_ma_dt__:
14
- $_query$jscomp$2_ct$$.ma_dt&&($bps$jscomp$1_custs$jscomp$1_dts$jscomp$1_nh_khs$jscomp$1_nh_vts$jscomp$1_phis$jscomp$1_vts$$=await getCodeChildren(dmdt,$query$$.id_app,$_query$jscomp$2_ct$$.ma_dt,"ma_dt","ma_dt_me"),$query$$.ma_dt={$in:$bps$jscomp$1_custs$jscomp$1_dts$jscomp$1_nh_khs$jscomp$1_nh_vts$jscomp$1_phis$jscomp$1_vts$$},$_query$jscomp$2_ct$$.__in_ma_dt__={$in:$bps$jscomp$1_custs$jscomp$1_dts$jscomp$1_nh_khs$jscomp$1_nh_vts$jscomp$1_phis$jscomp$1_vts$$});$_query$jscomp$2_ct$$.__in_ma_phi__?
15
- $query$$.ma_phi=$_query$jscomp$2_ct$$.__in_ma_phi__:$_query$jscomp$2_ct$$.ma_phi&&($bps$jscomp$1_custs$jscomp$1_dts$jscomp$1_nh_khs$jscomp$1_nh_vts$jscomp$1_phis$jscomp$1_vts$$=await getCodeChildren(dmphi,$query$$.id_app,$_query$jscomp$2_ct$$.ma_phi,"ma_phi","ma_phi_me"),$query$$.ma_phi={$in:$bps$jscomp$1_custs$jscomp$1_dts$jscomp$1_nh_khs$jscomp$1_nh_vts$jscomp$1_phis$jscomp$1_vts$$},$_query$jscomp$2_ct$$.__in_ma_phi__={$in:$bps$jscomp$1_custs$jscomp$1_dts$jscomp$1_nh_khs$jscomp$1_nh_vts$jscomp$1_phis$jscomp$1_vts$$});
16
- !$_query$jscomp$2_ct$$.ma_kh&&$_query$jscomp$2_ct$$.nh_kh&&$_query$jscomp$2_ct$$.nh_kh.length>0&&($bps$jscomp$1_custs$jscomp$1_dts$jscomp$1_nh_khs$jscomp$1_nh_vts$jscomp$1_phis$jscomp$1_vts$$=await global.getModel("group").getAllChildrenGroup($query$$.id_app,$_query$jscomp$2_ct$$.nh_kh,{group_kind:1}),$bps$jscomp$1_custs$jscomp$1_dts$jscomp$1_nh_khs$jscomp$1_nh_vts$jscomp$1_phis$jscomp$1_vts$$=await global.getModel("customer").find({id_app:$query$$.id_app,nh_kh:{$in:$bps$jscomp$1_custs$jscomp$1_dts$jscomp$1_nh_khs$jscomp$1_nh_vts$jscomp$1_phis$jscomp$1_vts$$},
17
- ngay_mua_dau_tien:{$exists:!0}},{ma_kh:1}),$query$$.ma_kh=$_query$jscomp$2_ct$$.nh_kh_lt?{$nin:$bps$jscomp$1_custs$jscomp$1_dts$jscomp$1_nh_khs$jscomp$1_nh_vts$jscomp$1_phis$jscomp$1_vts$$.map($r$$=>$r$$.ma_kh)}:{$in:$bps$jscomp$1_custs$jscomp$1_dts$jscomp$1_nh_khs$jscomp$1_nh_vts$jscomp$1_phis$jscomp$1_vts$$.map($r$$=>$r$$.ma_kh)});$_query$jscomp$2_ct$$.ma_nvt&&$_query$jscomp$2_ct$$.ma_nvt.length>0&&($bps$jscomp$1_custs$jscomp$1_dts$jscomp$1_nh_khs$jscomp$1_nh_vts$jscomp$1_phis$jscomp$1_vts$$=await global.getModel("dmnvt").getAllChildrenGroup($query$$.id_app,
18
- $_query$jscomp$2_ct$$.ma_nvt),$bps$jscomp$1_custs$jscomp$1_dts$jscomp$1_nh_khs$jscomp$1_nh_vts$jscomp$1_phis$jscomp$1_vts$$=await global.getModel("dmvt").find({id_app:$query$$.id_app,ma_nvt:{$in:$bps$jscomp$1_custs$jscomp$1_dts$jscomp$1_nh_khs$jscomp$1_nh_vts$jscomp$1_phis$jscomp$1_vts$$}},{ma_vt:1}),$query$$["details.ma_vt"]=$_query$jscomp$2_ct$$.ma_nvt_lt?{$nin:$bps$jscomp$1_custs$jscomp$1_dts$jscomp$1_nh_khs$jscomp$1_nh_vts$jscomp$1_phis$jscomp$1_vts$$.map($r$$=>$r$$.ma_vt)}:{$in:$bps$jscomp$1_custs$jscomp$1_dts$jscomp$1_nh_khs$jscomp$1_nh_vts$jscomp$1_phis$jscomp$1_vts$$.map($r$$=>
19
- $r$$.ma_vt)});$_query$jscomp$2_ct$$=Object.assign({},$query$$);databanle($_query$jscomp$2_ct$$,function($error$$,$rs$$){if($error$$)return $callback$$($error$$);async.mapLimit($rs$$,20,function($r$$,$callback$$){$options$$.doanh_thu_tinh_hoa_hong&&($r$$.details=$r$$.details.filter($d$$=>!$d$$.tien_hoa_hong));$r$$.details=$r$$.details.filter($d$$=>$query$$["details.ma_vt"]&&$query$$["details.ma_vt"].$in?$query$$["details.ma_vt"].$in.indexOf($d$$.ma_vt)>=0:!0);$r$$.t_sl_xuat=$r$$.details.csum("sl_xuat");
20
- $r$$.t_tien_hang=$r$$.details.csum("tien_hang");$r$$.t_tien_hang_ct=$r$$.details.csum("tien_hang_ct");$r$$.t_thue=$r$$.details.csum("tien_thue");$r$$.t_tien_ck=$r$$.details.csum("tien_ck");$r$$.t_tien=$r$$.details.csum("tien");$r$$.t_tien_cp=$r$$.details.csum("tien_cp");$r$$.tien_freeship=$r$$.tien_freeship||0;$r$$.tien_phi_vc=$r$$.tien_phi_vc||0;$r$$.tien_ck_hd=$r$$.tien_ck_hd?$r$$.tien_ck_hd:0;$r$$.t_tien_xuat=$r$$.details.csum("tien_xuat");$r$$.details_tl?($r$$.t_tien_tl=$r$$.details_tl.csum("tien_hang_ct")-
21
- $r$$.details_tl.csum("tien_ck"),$r$$.t_tien_thue_tl=$r$$.details_tl.csum("tien_thue"),$r$$.t_tien_nhap=$r$$.details_tl.csum("tien_nhap"),$r$$.t_sl_nhap=$r$$.details_tl.csum("sl_nhap")):($r$$.t_tien_tl=0,$r$$.t_tien_thue_tl=0,$r$$.t_sl_nhap=0,$r$$.t_tien_nhap=0);$callback$$(null,$r$$)},function($error$$,$dt$$){if($error$$)return $callback$$($error$$);$error$$=$dt$$.map($r$$=>$r$$.t_tien_hang_ct-$r$$.t_tien_ck-$r$$.tien_ck_hd-$r$$.t_tien_tl-$r$$.t_tien_thue_tl).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$callback$$(null,
22
- $error$$)})})},kpistatus=async function($condition$$,$callback$$){$condition$$.nam=$condition$$.nam?Number($condition$$.nam):(new Date).getFullYear();$condition$$.tu_thang=$condition$$.tu_thang?Number($condition$$.tu_thang):moment().month()-1;$condition$$.den_thang=$condition$$.den_thang?Number($condition$$.den_thang):moment().month()-1;$condition$$.tu_quy=$condition$$.tu_quy?Number($condition$$.tu_quy):moment().quarter();$condition$$.den_quy=$condition$$.den_quy?Number($condition$$.den_quy):moment().quarter();
23
- let $query$$={id_app:$condition$$.id_app,status:!0};$condition$$.ma_dvcs&&($query$$.ma_dvcs=$condition$$.ma_dvcs);$condition$$.ma_kho&&($query$$.ma_kho=$condition$$.ma_kho);$condition$$.ma_nv&&($query$$.ma_nv=$condition$$.ma_nv);if($condition$$.ma_bp){var $bps$jscomp$2_dts$jscomp$2_khoang_ts_phis$$=await getCodeChildren(dmbp,$condition$$.id_app,$condition$$.ma_bp,"ma_bp","ma_bp_me");$query$$.ma_bp={$in:$bps$jscomp$2_dts$jscomp$2_khoang_ts_phis$$}}$condition$$.ma_phi&&($bps$jscomp$2_dts$jscomp$2_khoang_ts_phis$$=
24
- await getCodeChildren(dmphi,$condition$$.id_app,$condition$$.ma_phi,"ma_phi","ma_phi_me"),$query$$.ma_phi={$in:$bps$jscomp$2_dts$jscomp$2_khoang_ts_phis$$});$condition$$.ma_dt&&($bps$jscomp$2_dts$jscomp$2_khoang_ts_phis$$=await getCodeChildren(dmdt,$condition$$.id_app,$condition$$.ma_dt,"ma_dt","ma_dt_me"),$query$$.ma_dt={$in:$bps$jscomp$2_dts$jscomp$2_khoang_ts_phis$$});$condition$$.group_id&&($query$$.group_id=$condition$$.group_id);$bps$jscomp$2_dts$jscomp$2_khoang_ts_phis$$=[];switch($condition$$.ct_theo){case "thang":for(var $quy_thang$$=
25
- $condition$$.tu_thang;$quy_thang$$<=$condition$$.den_thang;$quy_thang$$++)$bps$jscomp$2_dts$jscomp$2_khoang_ts_phis$$.push({thang:$quy_thang$$,nam:$condition$$.nam});break;case "quy":for($quy_thang$$=$condition$$.tu_quy;$quy_thang$$<=$condition$$.den_quy;$quy_thang$$++)$bps$jscomp$2_dts$jscomp$2_khoang_ts_phis$$.push({quy:$quy_thang$$,nam:$condition$$.nam});break;case "nam":$bps$jscomp$2_dts$jscomp$2_khoang_ts_phis$$.push({nam:$condition$$.nam});break;default:$bps$jscomp$2_dts$jscomp$2_khoang_ts_phis$$.push({tu_ngay:$condition$$.tu_ngay,
26
- den_ngay:$condition$$.den_ngay})}async.map($bps$jscomp$2_dts$jscomp$2_khoang_ts_phis$$,($ts$$,$callback$$)=>{let $_query$$=_.cloneDeep($query$$),$tu_ngay$$=$ts$$.tu_ngay||moment().year($ts$$.nam);$ts$$.thang&&$tu_ngay$$.month($ts$$.thang-1).startOf("month");$ts$$.quy&&$tu_ngay$$.quarter($ts$$.quy).starOf("quarter");$tu_ngay$$=$tu_ngay$$.endOf("date").toDate();$_query$$.hl_tu_ngay={$lte:$tu_ngay$$};let $den_ngay$$=$ts$$.den_ngay||moment().year($ts$$.nam);$ts$$.thang&&$den_ngay$$.month($ts$$.thang-
27
- 1).endOf("month");$ts$$.quy&&$den_ngay$$.quarter($ts$$.quy).endOf("quarter");$den_ngay$$=$den_ngay$$.startOf("date").toDate();$_query$$.hl_den_ngay={$gte:$den_ngay$$};ctds.find($_query$$).lean().then($cts$$=>{async.mapLimit($cts$$,20,($ct$$,$callback$$)=>{setImmediate(async()=>{$ct$$.thang=$ts$$.thang;$ct$$.quy=$ts$$.quy;$ct$$.nam=$ts$$.nam;$ct$$.ky=$ct$$.thang||$ct$$.quy;$ct$$.ky=$ct$$.ky?`${$ct$$.ky}/${$ct$$.nam}`:`${$ct$$.nam}`;$ct$$.chi_tieu=$ct$$.quy?Math.round($ct$$.chi_tieu_thang*3):$ct$$.thang?
28
- Math.round($ct$$.chi_tieu_thang):Math.round($ct$$.chi_tieu_thang*12);let $query$$={id_app:$ct$$.id_app,ma_dvcs:$ct$$.ma_dvcs};$query$$.ngay_ct={$gte:moment($tu_ngay$$).startOf("date").toDate(),$lte:moment($den_ngay$$).endOf("date").toDate()};switch($ct$$.cach_tinh){case "1":console.log("tinh kpi theo socai",$ct$$.ma_nv);await calcSoCai($ct$$,_.cloneDeep($query$$),($e$$,$ps$$)=>{if($e$$)return $callback$$($e$$);$ct$$.ps_nt=$ct$$.ps=$ps$$;$ct$$.cl=$ct$$.chi_tieu-$ct$$.ps;$ct$$.bold=!1;$ct$$.sysorder=
29
- 0;$ct$$.ty_le_ht=$ct$$.chi_tieu?Math.roundBy($ct$$.ps/$ct$$.chi_tieu*100,2):0;tinhHoaHong($ct$$,_.cloneDeep($query$$),$callback$$)});break;case "2":await calcDoanhThu($ct$$,_.cloneDeep($query$$),($e$$,$ps$$)=>{if($e$$)return $callback$$($e$$);$ct$$.ps_nt=$ct$$.ps=$ps$$;$ct$$.cl=$ct$$.chi_tieu-$ct$$.ps;$ct$$.bold=!1;$ct$$.sysorder=0;$ct$$.ty_le_ht=$ct$$.chi_tieu?Math.roundBy($ct$$.ps/$ct$$.chi_tieu*100,2):0;tinhHoaHong($ct$$,_.cloneDeep($query$$),$callback$$)});break;default:$callback$$()}})},$e$$=>
30
- {if($e$$)return console.error("error get data",$e$$),$callback$$($e$$);$callback$$(null,$cts$$)})}).catch($error$$=>{$callback$$({message:$error$$.message})})},async($e$$,$rs$$)=>{if($e$$)return $callback$$($e$$);$e$$=$rs$$.reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]);const $loai_hoa_hong$$=await global.getModel("group").find({id_app:$condition$$.id_app,group_type:"HOAHONG",status:!0}).lean();$e$$.forEach($row$$=>{$row$$.t_tien_hoa_hong=0;$loai_hoa_hong$$.forEach($hh$$=>{$row$$[`ps_tinh_hoa_hong_${$hh$$._id.toString()}`]=
4
+ ($e$$,$doanh_thu$$)=>{if($e$$)return $callback$$($e$$);$cs$$.ps_tinh_hoa_hong=$doanh_thu$$;$cs$$.tien_hoa_hong=Math.roundBy($cs$$.ps_tinh_hoa_hong*$cs$$.ty_le_hoa_hong/100,0);$callback$$()},{doanh_thu_tinh_hoa_hong:!0});break;case "3":await calcDoanhThu($cs$$,_.cloneDeep($query$$),($e$$,$doanh_thu$$,$doanh_so$$)=>{if($e$$)return $callback$$($e$$);$cs$$.ps_tinh_hoa_hong=$doanh_so$$;$cs$$.tien_hoa_hong=Math.roundBy($cs$$.ps_tinh_hoa_hong*$cs$$.ty_le_hoa_hong/100,0);$callback$$()},{doanh_thu_tinh_hoa_hong:!0});
5
+ break;default:$callback$$()}})},$e$$=>{if($e$$)return $callback$$($e$$);$callback$$()})},calcSoCai=async($ct$$,$query$$,$callback$$)=>{$ct$$.ma_kho&&($query$$.ma_kho=$ct$$.ma_kho);$ct$$.ma_nv&&($query$$.ma_nv=$ct$$.ma_nv);$ct$$.ma_nv_giao_hang&&($query$$.ma_nv_giao_hang=$ct$$.ma_nv_giao_hang);$ct$$.phu_xe&&($query$$.phu_xe=$ct$$.phu_xe);if($ct$$.__in_ma_bp__)$query$$.ma_bp=$ct$$.__in_ma_bp__;else if($ct$$.ma_bp){var $bps_custs_dts_nh_khs_nh_vts_phis_vts$$=await getCodeChildren(dmbp,$query$$.id_app,
6
+ $ct$$.ma_bp,"ma_bp","ma_bp_me");$query$$.ma_bp={$in:$bps_custs_dts_nh_khs_nh_vts_phis_vts$$};$ct$$.__in_ma_bp__={$in:$bps_custs_dts_nh_khs_nh_vts_phis_vts$$}}$ct$$.quan_ly&&$query$$.ma_nv&&($query$$.ma_nv={$ne:$query$$.ma_nv});$ct$$.__in_ma_dt__?$query$$.ma_dt=$ct$$.__in_ma_dt__:$ct$$.ma_dt&&($bps_custs_dts_nh_khs_nh_vts_phis_vts$$=await getCodeChildren(dmdt,$query$$.id_app,$ct$$.ma_dt,"ma_dt","ma_dt_me"),$query$$.ma_dt={$in:$bps_custs_dts_nh_khs_nh_vts_phis_vts$$},$ct$$.__in_ma_dt__={$in:$bps_custs_dts_nh_khs_nh_vts_phis_vts$$});
7
+ $ct$$.__in_ma_phi__?$query$$.ma_phi=$ct$$.__in_ma_phi__:$ct$$.ma_phi&&($bps_custs_dts_nh_khs_nh_vts_phis_vts$$=await getCodeChildren(dmphi,$query$$.id_app,$ct$$.ma_phi,"ma_phi","ma_phi_me"),$query$$.ma_phi={$in:$bps_custs_dts_nh_khs_nh_vts_phis_vts$$},$ct$$.__in_ma_phi__={$in:$bps_custs_dts_nh_khs_nh_vts_phis_vts$$});!$ct$$.ma_kh&&$ct$$.nh_kh&&$ct$$.nh_kh.length>0&&($bps_custs_dts_nh_khs_nh_vts_phis_vts$$=await global.getModel("group").getAllChildrenGroup($query$$.id_app,$ct$$.nh_kh,{group_kind:1}),
8
+ $bps_custs_dts_nh_khs_nh_vts_phis_vts$$=await global.getModel("customer").find({id_app:$query$$.id_app,nh_kh:{$in:$bps_custs_dts_nh_khs_nh_vts_phis_vts$$}},{ma_kh:1}),$query$$.ma_kh=$ct$$.nh_kh_lt?{$nin:$bps_custs_dts_nh_khs_nh_vts_phis_vts$$.map($r$$=>$r$$.ma_kh)}:{$in:$bps_custs_dts_nh_khs_nh_vts_phis_vts$$.map($r$$=>$r$$.ma_kh)});$ct$$.ma_nvt&&$ct$$.ma_nvt.length>0&&($bps_custs_dts_nh_khs_nh_vts_phis_vts$$=await global.getModel("dmnvt").getAllChildrenGroup($query$$.id_app,$query$$.ma_nvt),$bps_custs_dts_nh_khs_nh_vts_phis_vts$$=
9
+ await global.getModel("dmvt").find({id_app:$query$$.id_app,ma_nvt:{$in:$bps_custs_dts_nh_khs_nh_vts_phis_vts$$}},{ma_vt:1}),console.log("vts",$bps_custs_dts_nh_khs_nh_vts_phis_vts$$),$query$$.ma_vt=$ct$$.ma_nvt_lt?{$nin:$bps_custs_dts_nh_khs_nh_vts_phis_vts$$.map($r$$=>$r$$.ma_vt)}:{$in:$bps_custs_dts_nh_khs_nh_vts_phis_vts$$.map($r$$=>$r$$.ma_vt)});async.parallel({dt:$callback$$=>{let $_query$$=Object.assign({},$query$$);var $tks_co_tks_no$$=$ct$$.tk_no;$tks_co_tks_no$$&&!$ct$$.tk_no_gt&&(_.isArray($tks_co_tks_no$$)||
10
+ ($tks_co_tks_no$$=[$tks_co_tks_no$$]),$tks_co_tks_no$$.length>0&&($_query$$.tk_no={$regex:$tks_co_tks_no$$.reg(),$options:"i"}));($tks_co_tks_no$$=$ct$$.tk_co)&&!$ct$$.tk_co_gt&&(_.isArray($tks_co_tks_no$$)||($tks_co_tks_no$$=[$tks_co_tks_no$$]),$tks_co_tks_no$$.length>0&&($_query$$.tk_co={$regex:$tks_co_tks_no$$.reg(),$options:"i"}));socai.find($_query$$).lean().then($rs$$=>{$callback$$(null,$rs$$)}).catch($e$$=>{$callback$$($e$$)})},gt:$callback$$=>{if($ct$$.tk_no&&$ct$$.tk_no.length>0&&$ct$$.tk_no_gt||
11
+ $ct$$.tk_co&&$ct$$.tk_co.length>0&&$ct$$.tk_co_gt){let $_query$$=Object.assign({},$query$$);var $tks_co$jscomp$1_tks_no$$=$ct$$.tk_no;$tks_co$jscomp$1_tks_no$$&&$ct$$.tk_no_gt&&(_.isArray($tks_co$jscomp$1_tks_no$$)||($tks_co$jscomp$1_tks_no$$=[$tks_co$jscomp$1_tks_no$$]),$tks_co$jscomp$1_tks_no$$.length>0&&($_query$$.tk_no={$regex:$tks_co$jscomp$1_tks_no$$.reg(),$options:"i"}));($tks_co$jscomp$1_tks_no$$=$ct$$.tk_co)&&$ct$$.tk_co_gt&&(_.isArray($tks_co$jscomp$1_tks_no$$)||($tks_co$jscomp$1_tks_no$$=
12
+ [$tks_co$jscomp$1_tks_no$$]),$tks_co$jscomp$1_tks_no$$.length>0&&($_query$$.tk_co={$regex:$tks_co$jscomp$1_tks_no$$.reg(),$options:"i"}));socai.find($_query$$).lean().then($rs$$=>{$callback$$(null,$rs$$)}).catch($error$$=>{$callback$$({message:$error$$.message})})}else $callback$$(null,[])}},($e$$,$rs$$)=>{if($e$$)return console.log("error get data giam tru",$e$$),$callback$$($e$$);$e$$=$rs$$.dt.csum("tien")-$rs$$.gt.csum("tien");$callback$$(null,$e$$)})},calcDoanhThu=async($ct$$,$query$$,$callback$$,
13
+ $options$$={})=>{$ct$$.ma_kho&&($query$$.ma_kho=$ct$$.ma_kho);$ct$$.ma_nv&&($query$$.ma_nv=$ct$$.ma_nv);$ct$$.ma_nv_giao_hang&&($query$$.ma_nv_giao_hang=$ct$$.ma_nv_giao_hang);$ct$$.phu_xe&&($query$$.phu_xe=$ct$$.phu_xe);if($ct$$.__in_ma_bp__)$query$$.ma_bp=$ct$$.__in_ma_bp__;else if($ct$$.ma_bp){var $bps$jscomp$1_custs$jscomp$1_dts$jscomp$1_nh_khs$jscomp$1_nh_vts$jscomp$1_phis$jscomp$1_vts$$=await getCodeChildren(dmbp,$query$$.id_app,$ct$$.ma_bp,"ma_bp","ma_bp_me");$query$$.ma_bp={$in:$bps$jscomp$1_custs$jscomp$1_dts$jscomp$1_nh_khs$jscomp$1_nh_vts$jscomp$1_phis$jscomp$1_vts$$};
14
+ $ct$$.__in_ma_bp__={$in:$bps$jscomp$1_custs$jscomp$1_dts$jscomp$1_nh_khs$jscomp$1_nh_vts$jscomp$1_phis$jscomp$1_vts$$}}$ct$$.quan_ly&&$query$$.ma_nv&&($query$$.ma_nv={$ne:$query$$.ma_nv});$ct$$.__in_ma_dt__?$query$$.ma_dt=$ct$$.__in_ma_dt__:$ct$$.ma_dt&&($bps$jscomp$1_custs$jscomp$1_dts$jscomp$1_nh_khs$jscomp$1_nh_vts$jscomp$1_phis$jscomp$1_vts$$=await getCodeChildren(dmdt,$query$$.id_app,$ct$$.ma_dt,"ma_dt","ma_dt_me"),$query$$.ma_dt={$in:$bps$jscomp$1_custs$jscomp$1_dts$jscomp$1_nh_khs$jscomp$1_nh_vts$jscomp$1_phis$jscomp$1_vts$$},
15
+ $ct$$.__in_ma_dt__={$in:$bps$jscomp$1_custs$jscomp$1_dts$jscomp$1_nh_khs$jscomp$1_nh_vts$jscomp$1_phis$jscomp$1_vts$$});$ct$$.__in_ma_phi__?$query$$.ma_phi=$ct$$.__in_ma_phi__:$ct$$.ma_phi&&($bps$jscomp$1_custs$jscomp$1_dts$jscomp$1_nh_khs$jscomp$1_nh_vts$jscomp$1_phis$jscomp$1_vts$$=await getCodeChildren(dmphi,$query$$.id_app,$ct$$.ma_phi,"ma_phi","ma_phi_me"),$query$$.ma_phi={$in:$bps$jscomp$1_custs$jscomp$1_dts$jscomp$1_nh_khs$jscomp$1_nh_vts$jscomp$1_phis$jscomp$1_vts$$},$ct$$.__in_ma_phi__={$in:$bps$jscomp$1_custs$jscomp$1_dts$jscomp$1_nh_khs$jscomp$1_nh_vts$jscomp$1_phis$jscomp$1_vts$$});
16
+ !$ct$$.ma_kh&&$ct$$.nh_kh&&$ct$$.nh_kh.length>0&&($bps$jscomp$1_custs$jscomp$1_dts$jscomp$1_nh_khs$jscomp$1_nh_vts$jscomp$1_phis$jscomp$1_vts$$=await global.getModel("group").getAllChildrenGroup($query$$.id_app,$ct$$.nh_kh,{group_kind:1}),$bps$jscomp$1_custs$jscomp$1_dts$jscomp$1_nh_khs$jscomp$1_nh_vts$jscomp$1_phis$jscomp$1_vts$$=await global.getModel("customer").find({id_app:$query$$.id_app,nh_kh:{$in:$bps$jscomp$1_custs$jscomp$1_dts$jscomp$1_nh_khs$jscomp$1_nh_vts$jscomp$1_phis$jscomp$1_vts$$},
17
+ ngay_mua_dau_tien:{$exists:!0}},{ma_kh:1}),$query$$.ma_kh=$ct$$.nh_kh_lt?{$nin:$bps$jscomp$1_custs$jscomp$1_dts$jscomp$1_nh_khs$jscomp$1_nh_vts$jscomp$1_phis$jscomp$1_vts$$.map($r$$=>$r$$.ma_kh)}:{$in:$bps$jscomp$1_custs$jscomp$1_dts$jscomp$1_nh_khs$jscomp$1_nh_vts$jscomp$1_phis$jscomp$1_vts$$.map($r$$=>$r$$.ma_kh)});$ct$$.ma_nvt&&$ct$$.ma_nvt.length>0&&($bps$jscomp$1_custs$jscomp$1_dts$jscomp$1_nh_khs$jscomp$1_nh_vts$jscomp$1_phis$jscomp$1_vts$$=await global.getModel("dmnvt").getAllChildrenGroup($query$$.id_app,
18
+ $ct$$.ma_nvt),$bps$jscomp$1_custs$jscomp$1_dts$jscomp$1_nh_khs$jscomp$1_nh_vts$jscomp$1_phis$jscomp$1_vts$$=await global.getModel("dmvt").find({id_app:$query$$.id_app,ma_nvt:{$in:$bps$jscomp$1_custs$jscomp$1_dts$jscomp$1_nh_khs$jscomp$1_nh_vts$jscomp$1_phis$jscomp$1_vts$$}},{ma_vt:1}),$query$$["details.ma_vt"]=$ct$$.ma_nvt_lt?{$nin:$bps$jscomp$1_custs$jscomp$1_dts$jscomp$1_nh_khs$jscomp$1_nh_vts$jscomp$1_phis$jscomp$1_vts$$.map($r$$=>$r$$.ma_vt)}:{$in:$bps$jscomp$1_custs$jscomp$1_dts$jscomp$1_nh_khs$jscomp$1_nh_vts$jscomp$1_phis$jscomp$1_vts$$.map($r$$=>
19
+ $r$$.ma_vt)});let $_query$$=Object.assign({},$query$$);databanle($_query$$,async function($error$$,$rs$$){if($error$$)return $callback$$($error$$);await $rs$$.asyncJoinModel2($_query$$.id_app,"dmqddvt",{where:{ma_dvt:"ma_dvt",ma_vt:"ma_vt"},fields:["tu","mau","ma_dvt_goc"]});$rs$$.forEach(function($r$$,$he_so_qd_i$$){$r$$.stt=$he_so_qd_i$$+1;$r$$.id_ct=$r$$._id.toString();$r$$.bold=!1;$r$$.sysorder=5;$r$$.tt=$r$$.tien=($r$$.tien_hang_ct||0)-($r$$.tien_ck||0)+($r$$.tien_thue||0);$r$$.loi_nhuan_tmp=
20
+ $r$$.tien_xuat_tmp?$r$$.tt-$r$$.tien_xuat_tmp-($r$$.tien_thue||0)-($r$$.tien_cp||0):0;$r$$.loi_nhuan=$r$$.tt-($r$$.tien_xuat||0)-($r$$.tien_thue||0)-($r$$.tien_cp||0);$r$$.t_hoa_hong=$r$$.tien_hoa_hong+$r$$.tien_hoa_hong_gt+$r$$.tien_hoa_hong_ctv+$r$$.tien_hoa_hong_ql;$r$$.mau?($he_so_qd_i$$=$r$$.tu/$r$$.mau,$r$$.sl_xuat_qd=$he_so_qd_i$$*($r$$.sl_xuat||0),$r$$.sl_nhap_qd=$he_so_qd_i$$*($r$$.sl_nhap||0)):($r$$.sl_xuat_qd=$r$$.sl_xuat||0,$r$$.sl_nhap_qd=$r$$.sl_nhap||0);$r$$.sl_xuat_qd_bc=$r$$.sl_xuat_qd;
21
+ $r$$.sl_nhap_qd_bc=$r$$.sl_nhap_qd;$r$$.ma_dvt_bc=$r$$.ma_dvt_goc||$r$$.ma_dvt});$ct$$.ma_dvt&&await $rs$$.asyncJoinModel2($_query$$.id_app,"dmqddvt",{where:$item$$=>({ma_vt:$item$$.ma_vt,ma_dvt:$ct$$.ma_dvt}),setFields:($item$$,$he_so_qd$$)=>{$he_so_qd$$&&$he_so_qd$$.tu?($item$$.ma_dvt_bc=$ct$$.ma_dvt,$he_so_qd$$=$he_so_qd$$.mau/$he_so_qd$$.tu,$item$$.sl_xuat_qd_bc=$he_so_qd$$*($item$$.sl_xuat_qd||0),$item$$.sl_nhap_qd_bc=$he_so_qd$$*($item$$.sl_nhap_qd||0)):($item$$.sl_xuat_qd_bc=$item$$.sl_xuat_qd,
22
+ $item$$.sl_nhap_qd_bc=$item$$.sl_nhap_qd)}});async.mapLimit($rs$$,20,function($r$$,$callback$$){$options$$.doanh_thu_tinh_hoa_hong&&($r$$.details=$r$$.details.filter($d$$=>!$d$$.tien_hoa_hong));$r$$.details=$r$$.details.filter($d$$=>$query$$["details.ma_vt"]&&$query$$["details.ma_vt"].$in?$query$$["details.ma_vt"].$in.indexOf($d$$.ma_vt)>=0:!0);$r$$.t_sl_xuat=$r$$.details.csum("sl_xuat_qd_bc");$r$$.t_tien_hang=$r$$.details.csum("tien_hang");$r$$.t_tien_hang_ct=$r$$.details.csum("tien_hang_ct");$r$$.t_thue=
23
+ $r$$.details.csum("tien_thue");$r$$.t_tien_ck=$r$$.details.csum("tien_ck");$r$$.t_tien=$r$$.details.csum("tien");$r$$.t_tien_cp=$r$$.details.csum("tien_cp");$r$$.tien_freeship=$r$$.tien_freeship||0;$r$$.tien_phi_vc=$r$$.tien_phi_vc||0;$r$$.tien_ck_hd=$r$$.tien_ck_hd?$r$$.tien_ck_hd:0;$r$$.t_tien_xuat=$r$$.details.csum("tien_xuat");$r$$.details_tl?($r$$.t_tien_tl=$r$$.details_tl.csum("tien_hang_ct")-$r$$.details_tl.csum("tien_ck"),$r$$.t_tien_thue_tl=$r$$.details_tl.csum("tien_thue"),$r$$.t_tien_nhap=
24
+ $r$$.details_tl.csum("tien_nhap"),$r$$.t_sl_nhap=$r$$.details_tl.csum("sl_nhap")):($r$$.t_tien_tl=0,$r$$.t_tien_thue_tl=0,$r$$.t_sl_nhap=0,$r$$.t_tien_nhap=0);$callback$$(null,$r$$)},function($error$$,$dt_t_ds$$){if($error$$)return $callback$$($error$$);$error$$=$dt_t_ds$$.map($r$$=>$r$$.t_tien_hang_ct-$r$$.t_tien_ck-$r$$.tien_ck_hd-$r$$.t_tien_tl-$r$$.t_tien_thue_tl).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$dt_t_ds$$=$dt_t_ds$$.map($r$$=>$r$$.t_sl_xuat||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$callback$$(null,
25
+ $error$$,$dt_t_ds$$)})})},kpistatus=async function($condition$$,$callback$$){$condition$$.nam=$condition$$.nam?Number($condition$$.nam):(new Date).getFullYear();$condition$$.tu_thang=$condition$$.tu_thang?Number($condition$$.tu_thang):moment().month()-1;$condition$$.den_thang=$condition$$.den_thang?Number($condition$$.den_thang):moment().month()-1;$condition$$.tu_quy=$condition$$.tu_quy?Number($condition$$.tu_quy):moment().quarter();$condition$$.den_quy=$condition$$.den_quy?Number($condition$$.den_quy):
26
+ moment().quarter();let $query$$={id_app:$condition$$.id_app,status:!0};$condition$$.ma_dvcs&&($query$$.ma_dvcs=$condition$$.ma_dvcs);$condition$$.ma_kho&&($query$$.ma_kho=$condition$$.ma_kho);$condition$$.ma_nv&&($query$$.ma_nv=$condition$$.ma_nv);$condition$$.ma_nv_giao_hang&&($query$$.ma_nv_giao_hang=$condition$$.ma_nv_giao_hang);$condition$$.phu_xe&&($query$$.phu_xe=$condition$$.phu_xe);if($condition$$.ma_bp){var $bps$jscomp$2_dts$jscomp$2_khoang_ts_phis$$=await getCodeChildren(dmbp,$condition$$.id_app,
27
+ $condition$$.ma_bp,"ma_bp","ma_bp_me");$query$$.ma_bp={$in:$bps$jscomp$2_dts$jscomp$2_khoang_ts_phis$$}}$condition$$.ma_phi&&($bps$jscomp$2_dts$jscomp$2_khoang_ts_phis$$=await getCodeChildren(dmphi,$condition$$.id_app,$condition$$.ma_phi,"ma_phi","ma_phi_me"),$query$$.ma_phi={$in:$bps$jscomp$2_dts$jscomp$2_khoang_ts_phis$$});$condition$$.ma_dt&&($bps$jscomp$2_dts$jscomp$2_khoang_ts_phis$$=await getCodeChildren(dmdt,$condition$$.id_app,$condition$$.ma_dt,"ma_dt","ma_dt_me"),$query$$.ma_dt={$in:$bps$jscomp$2_dts$jscomp$2_khoang_ts_phis$$});
28
+ $condition$$.group_id&&($query$$.group_id=$condition$$.group_id);$bps$jscomp$2_dts$jscomp$2_khoang_ts_phis$$=[];switch($condition$$.ct_theo){case "thang":for(var $quy_thang$$=$condition$$.tu_thang;$quy_thang$$<=$condition$$.den_thang;$quy_thang$$++)$bps$jscomp$2_dts$jscomp$2_khoang_ts_phis$$.push({thang:$quy_thang$$,nam:$condition$$.nam});break;case "quy":for($quy_thang$$=$condition$$.tu_quy;$quy_thang$$<=$condition$$.den_quy;$quy_thang$$++)$bps$jscomp$2_dts$jscomp$2_khoang_ts_phis$$.push({quy:$quy_thang$$,
29
+ nam:$condition$$.nam});break;case "nam":$bps$jscomp$2_dts$jscomp$2_khoang_ts_phis$$.push({nam:$condition$$.nam});break;default:$bps$jscomp$2_dts$jscomp$2_khoang_ts_phis$$.push({tu_ngay:$condition$$.tu_ngay,den_ngay:$condition$$.den_ngay})}async.map($bps$jscomp$2_dts$jscomp$2_khoang_ts_phis$$,($ts$$,$callback$$)=>{let $_query$$=_.cloneDeep($query$$),$tu_ngay$$=$ts$$.tu_ngay||moment().year($ts$$.nam);$ts$$.thang&&$tu_ngay$$.month($ts$$.thang-1).startOf("month");$ts$$.quy&&$tu_ngay$$.quarter($ts$$.quy).starOf("quarter");
30
+ $tu_ngay$$=$tu_ngay$$.endOf("date").toDate();$_query$$.hl_tu_ngay={$lte:$tu_ngay$$};let $den_ngay$$=$ts$$.den_ngay||moment().year($ts$$.nam);$ts$$.thang&&$den_ngay$$.month($ts$$.thang-1).endOf("month");$ts$$.quy&&$den_ngay$$.quarter($ts$$.quy).endOf("quarter");$den_ngay$$=$den_ngay$$.startOf("date").toDate();$_query$$.hl_den_ngay={$gte:$den_ngay$$};ctds.find($_query$$).lean().then($cts$$=>{async.mapLimit($cts$$,20,($ct$$,$callback$$)=>{setImmediate(async()=>{$ct$$.thang=$ts$$.thang;$ct$$.quy=$ts$$.quy;
31
+ $ct$$.nam=$ts$$.nam;$ct$$.ky=$ct$$.thang||$ct$$.quy;$ct$$.ky=$ct$$.ky?`${$ct$$.ky}/${$ct$$.nam}`:`${$ct$$.nam}`;$ct$$.chi_tieu=$ct$$.quy?Math.round($ct$$.chi_tieu_thang*3):$ct$$.thang?Math.round($ct$$.chi_tieu_thang):Math.round($ct$$.chi_tieu_thang*12);let $query$$={id_app:$ct$$.id_app,ma_dvcs:$ct$$.ma_dvcs};$query$$.ngay_ct={$gte:moment($tu_ngay$$).startOf("date").toDate(),$lte:moment($den_ngay$$).endOf("date").toDate()};switch($ct$$.cach_tinh){case "1":console.log("tinh kpi theo socai",$ct$$.ma_nv);
32
+ await calcSoCai($ct$$,_.cloneDeep($query$$),($e$$,$ps$$)=>{if($e$$)return $callback$$($e$$);$ct$$.ps_nt=$ct$$.ps=$ps$$;$ct$$.cl=$ct$$.chi_tieu-$ct$$.ps;$ct$$.bold=!1;$ct$$.sysorder=0;$ct$$.ty_le_ht=$ct$$.chi_tieu?Math.roundBy($ct$$.ps/$ct$$.chi_tieu*100,2):0;tinhHoaHong($ct$$,_.cloneDeep($query$$),$callback$$)});break;case "2":await calcDoanhThu($ct$$,_.cloneDeep($query$$),($e$$,$dt$$)=>{if($e$$)return $callback$$($e$$);$ct$$.ps_nt=$ct$$.ps=$dt$$;$ct$$.cl=$ct$$.chi_tieu-$ct$$.ps;$ct$$.bold=!1;$ct$$.sysorder=
33
+ 0;$ct$$.ty_le_ht=$ct$$.chi_tieu?Math.roundBy($ct$$.ps/$ct$$.chi_tieu*100,2):0;tinhHoaHong($ct$$,_.cloneDeep($query$$),$callback$$)});break;case "3":await calcDoanhThu($ct$$,_.cloneDeep($query$$),($e$$,$dt$$,$ds$$)=>{if($e$$)return $callback$$($e$$);$ct$$.ps_nt=$ct$$.ps=$ds$$;$ct$$.cl=$ct$$.chi_tieu-$ct$$.ps;$ct$$.bold=!1;$ct$$.sysorder=0;$ct$$.ty_le_ht=$ct$$.chi_tieu?Math.roundBy($ct$$.ps/$ct$$.chi_tieu*100,2):0;tinhHoaHong($ct$$,_.cloneDeep($query$$),$callback$$)});break;default:$callback$$()}})},
34
+ $e$$=>{if($e$$)return console.error("error get data",$e$$),$callback$$($e$$);$callback$$(null,$cts$$)})}).catch($error$$=>{$callback$$({message:$error$$.message})})},async($e$$,$rs$$)=>{if($e$$)return $callback$$($e$$);$e$$=$rs$$.reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]);const $loai_hoa_hong$$=await global.getModel("group").find({id_app:$condition$$.id_app,group_type:"HOAHONG",status:!0}).lean();$e$$.forEach($row$$=>{$row$$.t_tien_hoa_hong=0;$loai_hoa_hong$$.forEach($hh$$=>{$row$$[`ps_tinh_hoa_hong_${$hh$$._id.toString()}`]=
31
35
  ($row$$.chinh_sach_hoa_hong||[]).filter($c$$=>$c$$.phan_loai==$hh$$._id.toString()).map($c$$=>$c$$.ps_tinh_hoa_hong||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$row$$[`hoa_hong_${$hh$$._id.toString()}`]=($row$$.chinh_sach_hoa_hong||[]).filter($c$$=>$c$$.phan_loai==$hh$$._id.toString()).map($c$$=>$c$$.tien_hoa_hong||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$row$$.t_tien_hoa_hong+=$row$$[`hoa_hong_${$hh$$._id.toString()}`]})});$callback$$(null,{rows:$e$$,columns:$loai_hoa_hong$$})})};
32
36
  module.exports=$condition$$=>new Promise(($resolve$$,$reject$$)=>{kpistatus($condition$$,($e$$,$rs$$)=>{if($e$$)return $reject$$($e$$);$resolve$$($rs$$)})});
@@ -1,12 +1,13 @@
1
- const ALLOWED_FIELDS={},BLOCKED_FIELDS="password secret_key token __v hash salt".split(" "),OPERATOR_MAP={eq:"$eq",ne:"$ne",gt:"$gt",gte:"$gte",lt:"$lt",lte:"$lte","in":"$in",contains:"$regex"},escapeRegex=$text$$=>typeof $text$$!=="string"?$text$$:$text$$.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),castValue=($value$$,$type$$)=>$type$$?$type$$==="number"?Number($value$$):$type$$==="date"?new Date($value$$):$type$$==="boolean"?$value$$==="true"||$value$$===!0:$value$$:$value$$,tryMergeValues=($existingVal$$,
2
- $newVal$$)=>{if(typeof $existingVal$$==="object"&&$existingVal$$!==null&&!Array.isArray($existingVal$$)&&typeof $newVal$$==="object"&&$newVal$$!==null&&!Array.isArray($newVal$$)){const $existingKeys$$=Object.keys($existingVal$$);if(!Object.keys($newVal$$).some($k$$=>$existingKeys$$.includes($k$$)))return{...$existingVal$$,...$newVal$$}}return null},buildSearchQuery=$dbField_queryNode$$=>{if($dbField_queryNode$$.field){const {field:$field$$,operator:$operator$$,value:$value$$}=$dbField_queryNode$$;
3
- $dbField_queryNode$$=$field$$;let $type$$=null;var $childConditions_config_isStrict_mongoOp$$=ALLOWED_FIELDS&&Object.keys(ALLOWED_FIELDS).length>0;if($field$$==="_id"||$field$$==="id")$dbField_queryNode$$="_id",$type$$="objectId";else if($childConditions_config_isStrict_mongoOp$$){$childConditions_config_isStrict_mongoOp$$=ALLOWED_FIELDS[$field$$];if(!$childConditions_config_isStrict_mongoOp$$)return null;$dbField_queryNode$$=$childConditions_config_isStrict_mongoOp$$.dbField;$type$$=$childConditions_config_isStrict_mongoOp$$.type}else if(BLOCKED_FIELDS.includes($field$$))return null;
4
- $childConditions_config_isStrict_mongoOp$$=OPERATOR_MAP[$operator$$];if(!$childConditions_config_isStrict_mongoOp$$)return null;let $finalVal$$=$value$$;if($operator$$==="contains")return{[$dbField_queryNode$$]:{[$childConditions_config_isStrict_mongoOp$$]:new RegExp(escapeRegex(String($value$$)),"i")}};if($operator$$==="in"){const $arr$$=Array.isArray($value$$)?$value$$:[$value$$];$finalVal$$=$arr$$.map($v$$=>castValue($v$$,$type$$)).filter(($v$$,$i$$)=>$v$$!==null||$arr$$[$i$$]===null);return{[$dbField_queryNode$$]:{[$childConditions_config_isStrict_mongoOp$$]:$finalVal$$}}}$finalVal$$=
5
- castValue($value$$,$type$$);return $finalVal$$===null&&$type$$==="number"?null:$childConditions_config_isStrict_mongoOp$$==="$eq"?{[$dbField_queryNode$$]:$finalVal$$}:{[$dbField_queryNode$$]:{[$childConditions_config_isStrict_mongoOp$$]:$finalVal$$}}}if($dbField_queryNode$$.logic&&Array.isArray($dbField_queryNode$$.filters)){$childConditions_config_isStrict_mongoOp$$=$dbField_queryNode$$.filters.map($childNode$$=>buildSearchQuery($childNode$$)).filter($cond$$=>$cond$$!==null&&Object.keys($cond$$).length>
6
- 0);if($childConditions_config_isStrict_mongoOp$$.length===0)return{};if($dbField_queryNode$$.logic==="OR")return{$or:$childConditions_config_isStrict_mongoOp$$};const $finalQuery$$={},$conflictConditions$$=[];$childConditions_config_isStrict_mongoOp$$.forEach($cond$$=>{const $key$$=Object.keys($cond$$)[0],$val$$=$cond$$[$key$$];$key$$.startsWith("$")?$conflictConditions$$.push($cond$$):$finalQuery$$[$key$$]===void 0?$finalQuery$$[$key$$]=$val$$:($cond$$=tryMergeValues($finalQuery$$[$key$$],$val$$))?
7
- $finalQuery$$[$key$$]=$cond$$:($conflictConditions$$.push({[$key$$]:$finalQuery$$[$key$$]}),$conflictConditions$$.push({[$key$$]:$val$$}),delete $finalQuery$$[$key$$])});if($conflictConditions$$.length>0){if(Object.keys($finalQuery$$).length===0)return{$and:$conflictConditions$$};$finalQuery$$.$and=$conflictConditions$$}return $finalQuery$$}return{}};exports.buildSearchQuery=buildSearchQuery;const MONGO_TO_OP_MAP={};Object.entries(OPERATOR_MAP).forEach(([$k$$,$v$$])=>MONGO_TO_OP_MAP[$v$$]=$k$$);
8
- const MAX_DEPTH=5,IS_STRICT_MODE=ALLOWED_FIELDS&&Object.keys(ALLOWED_FIELDS).length>0;let GLOBAL_ALIAS_MAP=null;IS_STRICT_MODE&&(GLOBAL_ALIAS_MAP={},Object.entries(ALLOWED_FIELDS).forEach(([$alias$$,$config$$])=>{GLOBAL_ALIAS_MAP[$config$$.dbField]=$alias$$}));
1
+ const ALLOWED_FIELDS={},BLOCKED_FIELDS="password secret_key token __v hash salt".split(" "),OPERATOR_MAP={eq:"$eq",ne:"$ne",gt:"$gt",gte:"$gte",lt:"$lt",lte:"$lte","in":"$in",contains:"$regex",regex:"$regex"},escapeRegex=$hasStartAnchor_text$$=>{if(typeof $hasStartAnchor_text$$!=="string")return $hasStartAnchor_text$$;var $escapedBody_pattern$$=$hasStartAnchor_text$$;let $hasEndAnchor$$=$hasStartAnchor_text$$=!1;$escapedBody_pattern$$.startsWith("^")&&($hasStartAnchor_text$$=!0,$escapedBody_pattern$$=
2
+ $escapedBody_pattern$$.substring(1));$escapedBody_pattern$$.endsWith("$")&&$escapedBody_pattern$$.length>0&&($hasEndAnchor$$=!0,$escapedBody_pattern$$=$escapedBody_pattern$$.substring(0,$escapedBody_pattern$$.length-1));$escapedBody_pattern$$=$escapedBody_pattern$$.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return($hasStartAnchor_text$$?"^":"")+$escapedBody_pattern$$+($hasEndAnchor$$?"$":"")},castValue=($value$$,$type$$)=>$type$$?$type$$==="number"?Number($value$$):$type$$==="date"?new Date($value$$):
3
+ $type$$==="boolean"?$value$$==="true"||$value$$===!0:$value$$:$value$$,tryMergeValues=($existingVal$$,$newVal$$)=>{if(typeof $existingVal$$==="object"&&$existingVal$$!==null&&!Array.isArray($existingVal$$)&&typeof $newVal$$==="object"&&$newVal$$!==null&&!Array.isArray($newVal$$)){const $existingKeys$$=Object.keys($existingVal$$);if(!Object.keys($newVal$$).some($k$$=>$existingKeys$$.includes($k$$)))return{...$existingVal$$,...$newVal$$}}return null},buildSearchQuery=$dbField_queryNode$$=>{if($dbField_queryNode$$.field){const {field:$field$$,
4
+ operator:$operator$$,value:$value$$}=$dbField_queryNode$$;$dbField_queryNode$$=$field$$;let $type$$=null;var $childConditions_config_isStrict_mongoOp$$=ALLOWED_FIELDS&&Object.keys(ALLOWED_FIELDS).length>0;if($field$$==="_id"||$field$$==="id")$dbField_queryNode$$="_id",$type$$="objectId";else if($childConditions_config_isStrict_mongoOp$$){$childConditions_config_isStrict_mongoOp$$=ALLOWED_FIELDS[$field$$];if(!$childConditions_config_isStrict_mongoOp$$)return null;$dbField_queryNode$$=$childConditions_config_isStrict_mongoOp$$.dbField;
5
+ $type$$=$childConditions_config_isStrict_mongoOp$$.type}else if(BLOCKED_FIELDS.includes($field$$))return null;$childConditions_config_isStrict_mongoOp$$=OPERATOR_MAP[$operator$$];if(!$childConditions_config_isStrict_mongoOp$$)return null;let $finalVal$$=$value$$;if($operator$$==="contains")return{[$dbField_queryNode$$]:{[$childConditions_config_isStrict_mongoOp$$]:new RegExp(escapeRegex(String($value$$)),"i")}};if($operator$$==="regex")return{[$dbField_queryNode$$]:{[$childConditions_config_isStrict_mongoOp$$]:new RegExp(String($value$$),
6
+ "i")}};if($operator$$==="in"){const $arr$$=Array.isArray($value$$)?$value$$:[$value$$];$finalVal$$=$arr$$.map($v$$=>castValue($v$$,$type$$)).filter(($v$$,$i$$)=>$v$$!==null||$arr$$[$i$$]===null);return{[$dbField_queryNode$$]:{[$childConditions_config_isStrict_mongoOp$$]:$finalVal$$}}}$finalVal$$=castValue($value$$,$type$$);return $finalVal$$===null&&$type$$==="number"?null:$childConditions_config_isStrict_mongoOp$$==="$eq"?{[$dbField_queryNode$$]:$finalVal$$}:{[$dbField_queryNode$$]:{[$childConditions_config_isStrict_mongoOp$$]:$finalVal$$}}}if($dbField_queryNode$$.logic&&
7
+ Array.isArray($dbField_queryNode$$.filters)){$childConditions_config_isStrict_mongoOp$$=$dbField_queryNode$$.filters.map($childNode$$=>buildSearchQuery($childNode$$)).filter($cond$$=>$cond$$!==null&&Object.keys($cond$$).length>0);if($childConditions_config_isStrict_mongoOp$$.length===0)return{};if($dbField_queryNode$$.logic==="OR")return{$or:$childConditions_config_isStrict_mongoOp$$};const $finalQuery$$={},$conflictConditions$$=[];$childConditions_config_isStrict_mongoOp$$.forEach($cond$$=>{const $key$$=
8
+ Object.keys($cond$$)[0],$val$$=$cond$$[$key$$];$key$$.startsWith("$")?$conflictConditions$$.push($cond$$):$finalQuery$$[$key$$]===void 0?$finalQuery$$[$key$$]=$val$$:($cond$$=tryMergeValues($finalQuery$$[$key$$],$val$$))?$finalQuery$$[$key$$]=$cond$$:($conflictConditions$$.push({[$key$$]:$finalQuery$$[$key$$]}),$conflictConditions$$.push({[$key$$]:$val$$}),delete $finalQuery$$[$key$$])});if($conflictConditions$$.length>0){if(Object.keys($finalQuery$$).length===0)return{$and:$conflictConditions$$};
9
+ $finalQuery$$.$and=$conflictConditions$$}return $finalQuery$$}return{}};exports.buildSearchQuery=buildSearchQuery;const MONGO_TO_OP_MAP={};Object.entries(OPERATOR_MAP).forEach(([$k$$,$v$$])=>MONGO_TO_OP_MAP[$v$$]=$k$$);const MAX_DEPTH=5,IS_STRICT_MODE=ALLOWED_FIELDS&&Object.keys(ALLOWED_FIELDS).length>0;let GLOBAL_ALIAS_MAP=null;IS_STRICT_MODE&&(GLOBAL_ALIAS_MAP={},Object.entries(ALLOWED_FIELDS).forEach(([$alias$$,$config$$])=>{GLOBAL_ALIAS_MAP[$config$$.dbField]=$alias$$}));
9
10
  const isOperatorObject=$val$$=>!$val$$||typeof $val$$!=="object"||$val$$ instanceof Date||Array.isArray($val$$)||$val$$._bsontype==="ObjectID"||$val$$.toString&&$val$$.toString().match(/^[0-9a-fA-F]{24}$/)?!1:Object.keys($val$$).some($k$$=>$k$$.startsWith("$")),convertLegacyQuery=($mongoQuery$$,$currentDepth$$=0)=>{if($currentDepth$$>MAX_DEPTH)return console.warn("[Convert] \u26a0\ufe0f Max depth exceeded"),null;const $group$$={logic:"AND",filters:[]};if(!$mongoQuery$$||typeof $mongoQuery$$!=="object")return $group$$;
10
11
  Object.keys($mongoQuery$$).forEach($key$$=>{if(!["__proto__","constructor","prototype"].includes($key$$)){var $value$$=$mongoQuery$$[$key$$];if($key$$==="$or"||$key$$==="$and"){if(Array.isArray($value$$)){var $subGroup$$={logic:$key$$==="$or"?"OR":"AND",filters:[]};$value$$.forEach($convertedChild_subQuery$$=>{($convertedChild_subQuery$$=convertLegacyQuery($convertedChild_subQuery$$,$currentDepth$$+1))&&$convertedChild_subQuery$$.filters.length>0&&$subGroup$$.filters.push($convertedChild_subQuery$$)});
11
12
  $subGroup$$.filters.length>0&&$group$$.filters.push($subGroup$$)}}else if(!$key$$.startsWith("$")){var $aliasField$$=$key$$,$isAllowed$$=!1;$key$$==="_id"||$key$$==="id"?($aliasField$$="_id",$isAllowed$$=!0):IS_STRICT_MODE?GLOBAL_ALIAS_MAP[$key$$]&&($aliasField$$=GLOBAL_ALIAS_MAP[$key$$],$isAllowed$$=!0):BLOCKED_FIELDS.includes($key$$)||($isAllowed$$=!0);$isAllowed$$&&(isOperatorObject($value$$)?Object.keys($value$$).forEach($mongoOp$$=>{if(!["__proto__","constructor"].includes($mongoOp$$)){var $newOp$$=
12
- MONGO_TO_OP_MAP[$mongoOp$$],$val$$=$value$$[$mongoOp$$];$mongoOp$$==="$regex"&&($newOp$$="contains",$val$$ instanceof RegExp&&($val$$=$val$$.source));$mongoOp$$!=="$options"&&$newOp$$&&$group$$.filters.push({field:$aliasField$$,operator:$newOp$$,value:$val$$})}}):$group$$.filters.push({field:$aliasField$$,operator:"eq",value:$value$$}))}}});return $group$$};exports.convertLegacyQuery=convertLegacyQuery;
13
+ MONGO_TO_OP_MAP[$mongoOp$$],$val$$=$value$$[$mongoOp$$];$mongoOp$$==="$regex"&&($val$$ instanceof RegExp&&($val$$=$val$$.source),$newOp$$="contains");$mongoOp$$!=="$options"&&$newOp$$&&$group$$.filters.push({field:$aliasField$$,operator:$newOp$$,value:$val$$})}}):$group$$.filters.push({field:$aliasField$$,operator:"eq",value:$value$$}))}}});return $group$$};exports.convertLegacyQuery=convertLegacyQuery;
@@ -12,6 +12,6 @@ await new Promise($res$$=>setTimeout($res$$,$delay$$))}else{console.error(`\u274
12
12
  exports.executeInTransaction=async function($fn$$){const $session$$=await mongoose.startSession(),$outerSessionId$$=`txn-auto-${++globalSessionCounter}`;$session$$._debugId=$outerSessionId$$;let $result$$=null,$committedCallbacks$$=[];try{await $session$$.withTransaction(async $sessionInTxn$$=>{$sessionInTxn$$.afterCommit=[];const $context$$={session:$sessionInTxn$$,storeId:++globalStoreCounter,sessionId:$sessionInTxn$$._debugId||$outerSessionId$$};await storage.run($context$$,async()=>{console.log(`\ud83d\udd04 [executeInTransaction] Start/Retry txnId=${$context$$.sessionId} storeId=${$context$$.storeId}`);
13
13
  $result$$=await $fn$$($sessionInTxn$$)});$sessionInTxn$$.afterCommit&&$sessionInTxn$$.afterCommit.length>0&&($committedCallbacks$$=[...$sessionInTxn$$.afterCommit])},{readPreference:"primary",readConcern:{level:"local"},writeConcern:{w:"majority"},maxCommitTimeMS:5E3})}catch($error$$){throw console.error(`\u274c [executeInTransaction] Failed permanently: ${$error$$.message}`),$error$$;}finally{await $session$$.endSession()}$committedCallbacks$$.length>0&&(console.log(`\ud83d\udd25 [executeInTransaction] Running ${$committedCallbacks$$.length} afterCommit callbacks`),
14
14
  exports.runWithoutSession(async()=>{for(const $cb$$ of $committedCallbacks$$)try{await $cb$$()}catch($err$$){console.error("\u274c [executeInTransaction] afterCommit error",$err$$)}}));return $result$$};
15
- exports.onAfterCommit=function($cb$$,$description$$="",$session$$=null,$store$$=null){$store$$=$store$$||storage.getStore();$session$$=$session$$||$store$$?.session;$store$$&&$session$$&&exports.isSessionActive($session$$)?($session$$.afterCommit=$session$$.afterCommit||[],$session$$.afterCommit.push($cb$$),console.log(`[onAfterCommit] added callback, storeId=${$store$$.storeId}, count=${$session$$.afterCommit.length},des=${$description$$}`)):Promise.resolve().then($cb$$).catch($err$$=>console.error("[onAfterCommit immediate error]",
16
- $err$$,$description$$,", storeId=",$store$$?.storeId))};exports.getAfterCommitList=function(){return exports.getCurrentSession()?.afterCommit||[]};exports.runWithoutSession=async function($fn$$){return storage.run({session:void 0},$fn$$)};exports.getCurrentSession=function(){return storage.getStore()?.session};exports.isModelExcludedFromSession=function($model_name$$){$model_name$$=typeof $model_name$$==="string"?$model_name$$:$model_name$$?.modelName;return!(!$model_name$$||!SESSION_EXCLUDE_MODELS.includes($model_name$$))};
15
+ exports.onAfterCommit=function($cb$$,$description$$="",$session$$=null,$store$$=null){$store$$=$store$$||storage.getStore();$session$$=$session$$||$store$$?.session;$store$$&&$session$$&&exports.isSessionActive($session$$)?($session$$.afterCommit=$session$$.afterCommit||[],$session$$.afterCommit.push($cb$$)):Promise.resolve().then($cb$$).catch($err$$=>console.error("[onAfterCommit immediate error]",$err$$,$description$$,", storeId=",$store$$?.storeId))};
16
+ exports.getAfterCommitList=function(){return exports.getCurrentSession()?.afterCommit||[]};exports.runWithoutSession=async function($fn$$){return storage.run({session:void 0},$fn$$)};exports.getCurrentSession=function(){return storage.getStore()?.session};exports.isModelExcludedFromSession=function($model_name$$){$model_name$$=typeof $model_name$$==="string"?$model_name$$:$model_name$$?.modelName;return!(!$model_name$$||!SESSION_EXCLUDE_MODELS.includes($model_name$$))};
17
17
  exports.isSessionActive=function($session$$){if(!$session$$)return!1;try{return $session$$.inTransaction()&&!$session$$.hasEnded}catch{return!1}};console.log("[sessionContext] \u2705 Loaded");
@@ -1,7 +1,9 @@
1
1
  const gt_ctgt=global.getModel("gt_ctgt"),xoadulieucu=require("./tinhGtXoa"),tinhgiathanhtt=require("./tinhGtTrucTiep"),tinhsoluong=require("./tinhGtSltk"),taphopcppstk=require("./tinhGtThcppstk"),phanbotheosl=require("./tinhGtPhanboSltp"),phanbotheohs=require("./tinhGtPhanboHeSo"),phanbotheoyt=require("./tinhGtPhanboYtcp"),capnhatpnk=require("./tinhGtCapnhatPNK"),tinhgiatb=require("./tinhgiatb");
2
- module.exports=function($condition$$,$callback$$){if(!($condition$$&&$condition$$.thang&&$condition$$.nam&&$condition$$.id_app))return $callback$$("T\u00ednh n\u0103ng n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: thang,nam,id_app");$condition$$.nam=Number($condition$$.nam);$condition$$.thang=Number($condition$$.thang);(new Promise(($resolve$$,$reject$$)=>{xoadulieucu($condition$$,($e$$,$rs$$)=>{if($e$$)return $reject$$($e$$);$resolve$$($rs$$)})})).then(()=>new Promise(($resole$$,$reject$$)=>
3
- {tinhsoluong($condition$$,($e$$,$rs$$)=>{if($e$$)return $reject$$($e$$);$resole$$($rs$$)})})).then(()=>new Promise(($resole$$,$reject$$)=>{taphopcppstk($condition$$,($e$$,$rs$$)=>{if($e$$)return $reject$$($e$$);$resole$$($rs$$)})})).then(()=>new Promise(($resole$$,$reject$$)=>{tinhgiathanhtt($condition$$,($e$$,$rs$$)=>{if($e$$)return $reject$$($e$$);$resole$$($rs$$)})})).then(()=>new Promise(($resole$$,$reject$$)=>{phanbotheosl($condition$$,($e$$,$rs$$)=>{if($e$$)return $reject$$($e$$);$resole$$($rs$$)})})).then(()=>
4
- new Promise(($resole$$,$reject$$)=>{phanbotheohs($condition$$,($e$$,$rs$$)=>{if($e$$)return $reject$$($e$$);$resole$$($rs$$)})})).then(()=>new Promise(($resole$$,$reject$$)=>{phanbotheoyt($condition$$,($e$$,$rs$$)=>{if($e$$)return $reject$$($e$$);$resole$$($rs$$)})})).then(()=>new Promise(($resole$$,$reject$$)=>{phanbotheoyt($condition$$,($e$$,$rs$$)=>{if($e$$)return $reject$$($e$$);$resole$$($rs$$)})})).then(()=>new Promise(($resole$$,$reject$$)=>{capnhatpnk($condition$$,($e$$,$rs$$)=>{if($e$$)return $reject$$($e$$);
5
- $resole$$($rs$$)})})).then(()=>new Promise(($resole$$,$reject$$)=>{setImmediate(async()=>{var $cond_ds_ma_vt_query_dmvt$$={id_app:$condition$$.id_app,nam:$condition$$.nam,thang:$condition$$.thang};$condition$$.ma_bp&&($cond_ds_ma_vt_query_dmvt$$.ma_bp=$condition$$.ma_bp.toUpperCase());$condition$$.id_lenhsx&&global.mongoose.Types.ObjectId.isValid($condition$$.id_lenhsx)&&($cond_ds_ma_vt_query_dmvt$$.id_lenhsx=$condition$$.id_lenhsx);const $ctgt$$=await gt_ctgt.find($cond_ds_ma_vt_query_dmvt$$).lean();
6
- $cond_ds_ma_vt_query_dmvt$$=[...(new Set($ctgt$$.filter($r$$=>$r$$.ma_sp).map($r$$=>$r$$.ma_sp)))];$cond_ds_ma_vt_query_dmvt$$={id_app:$condition$$.id_app,nam:$condition$$.nam,tu_thang:$condition$$.thang,den_thang:$condition$$.thang,ma_vt:{$in:$cond_ds_ma_vt_query_dmvt$$}};console.log("tinh gia trung binh",$cond_ds_ma_vt_query_dmvt$$);tinhgiatb($cond_ds_ma_vt_query_dmvt$$,function($e$$){console.log("ket thuc tinh gia trung binh",$e$$);if($e$$)return $reject$$($e$$);$resole$$($ctgt$$)})})})).then($ctgt$$=>
7
- {$callback$$(null,$ctgt$$)}).catch($e$$=>{console.log("error",$e$$);$callback$$($e$$)})};
2
+ module.exports=async function($condition$$,$callback$$){console.log("\ud83d\udd25 [tinhgiathanh] b\u1eaft \u0111\u1ea7u t\u00ednh gi\u00e1 th\u00e0nh v\u1edbi \u0111i\u1ec1u ki\u1ec7n",JSON.stringify($condition$$,null,2));if(!($condition$$&&$condition$$.thang&&$condition$$.nam&&$condition$$.id_app))return $callback$$("T\u00ednh n\u0103ng n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: thang,nam,id_app");$condition$$.nam=Number($condition$$.nam);$condition$$.thang=Number($condition$$.thang);(new Promise(($resolve$$,
3
+ $reject$$)=>{console.log("[tinhgiathanh] xo\u00e1 d\u1eef li\u1ec7u c\u0169...");xoadulieucu($condition$$,($e$$,$rs$$)=>{if($e$$)return $reject$$($e$$);$resolve$$($rs$$)})})).then(()=>{console.log("[tinhgiathanh] T\u00ednh s\u1ed1 l\u01b0\u1ee3ng s\u1ea3n xu\u1ea5t...");return new Promise(($resole$$,$reject$$)=>{tinhsoluong($condition$$,($e$$,$rs$$)=>{if($e$$)return $reject$$($e$$);$resole$$($rs$$)})})}).then(()=>{console.log("[tinhgiathanh] T\u1eadp h\u1ee3p chi ph\u00ed ph\u00e1t sinh trong k\u1ef3...");
4
+ return new Promise(($resole$$,$reject$$)=>{taphopcppstk($condition$$,($e$$,$rs$$)=>{if($e$$)return $reject$$($e$$);$resole$$($rs$$)})})}).then(()=>{console.log("[tinhgiathanh] Chi ph\u00ed t\u1eadp h\u1ee3p tr\u1ef1c ti\u1ebfp theo s\u1ea3n ph\u1ea9m...");return new Promise(($resole$$,$reject$$)=>{tinhgiathanhtt($condition$$,($e$$,$rs$$)=>{if($e$$)return $reject$$($e$$);$resole$$($rs$$)})})}).then(()=>{console.log("[tinhgiathanh] Ph\u00e2n b\u1ed5 chi ph\u00ed theo s\u1ed1 l\u01b0\u1ee3ng th\u00e0nh ph\u1ea9m...");
5
+ return new Promise(($resole$$,$reject$$)=>{phanbotheosl($condition$$,($e$$,$rs$$)=>{if($e$$)return $reject$$($e$$);$resole$$($rs$$)})})}).then(()=>{console.log("[tinhgiathanh] Ph\u00e2n b\u1ed5 chi ph\u00ed theo h\u1ec7 s\u1ed1...");return new Promise(($resole$$,$reject$$)=>{phanbotheohs($condition$$,($e$$,$rs$$)=>{if($e$$)return $reject$$($e$$);$resole$$($rs$$)})})}).then(()=>{console.log("[tinhgiathanh] Ph\u00e2n b\u1ed5 chi ph\u00ed theo y\u00eau t\u1ed1 l\u1ea7n 1...");return new Promise(($resole$$,
6
+ $reject$$)=>{phanbotheoyt($condition$$,($e$$,$rs$$)=>{if($e$$)return $reject$$($e$$);$resole$$($rs$$)})})}).then(()=>{console.log("[tinhgiathanh] Ph\u00e2n b\u1ed5 chi ph\u00ed theo y\u00eau t\u1ed1 l\u1ea7n 2...");return new Promise(($resole$$,$reject$$)=>{phanbotheoyt($condition$$,($e$$,$rs$$)=>{if($e$$)return $reject$$($e$$);$resole$$($rs$$)})})}).then(()=>{console.log("[tinhgiathanh] C\u1eadp nh\u1eadt phi\u1ebfu nh\u1eadp kho th\u00e0nh ph\u1ea9m...");return new Promise(($resole$$,$reject$$)=>
7
+ {capnhatpnk($condition$$,($e$$,$rs$$)=>{if($e$$)return $reject$$($e$$);$resole$$($rs$$)})})}).then(()=>{console.log("[tinhgiathanh] T\u00ednh gi\u00e1 trung b\u00ecnh cho s\u1ea3n ph\u1ea9m s\u1ea3n xu\u1ea5t \u0111\u1ec3 \u0111\u01b0a v\u00e0o phi\u1ebfu b\u00e1n h\u00e0ng...");return new Promise(($resole$$,$reject$$)=>{setImmediate(async()=>{var $cond_ds_ma_vt$$={id_app:$condition$$.id_app,nam:$condition$$.nam,thang:$condition$$.thang};$condition$$.ma_bp&&($cond_ds_ma_vt$$.ma_bp=$condition$$.ma_bp.toUpperCase());
8
+ $condition$$.id_lenhsx&&global.mongoose.Types.ObjectId.isValid($condition$$.id_lenhsx)&&($cond_ds_ma_vt$$.id_lenhsx=$condition$$.id_lenhsx);const $ctgt$$=await gt_ctgt.find($cond_ds_ma_vt$$).lean();$cond_ds_ma_vt$$=[...(new Set($ctgt$$.filter($r$$=>$r$$.ma_sp).map($r$$=>$r$$.ma_sp)))];tinhgiatb({id_app:$condition$$.id_app,nam:$condition$$.nam,tu_thang:$condition$$.thang,den_thang:$condition$$.thang,ma_vt:{$in:$cond_ds_ma_vt$$}},function($e$$){if($e$$)return $reject$$($e$$);$resole$$($ctgt$$)})})})}).then($ctgt$$=>
9
+ {console.log("\u2705[tinhgiathanh] \u0110\u00e3 ho\u00e0n th\u00e0nh");$callback$$(null,$ctgt$$)}).catch($e$$=>{console.error("\u274c [tinhgiathanh] \u0110\u00e3 c\u00f3 l\u1ed7i x\u1ea3y ra:",$e$$);$callback$$($e$$)})};
@@ -1,7 +1,7 @@
1
1
  const pnk=global.getModel("pnk"),sokho=global.getModel("sokho"),gt_ctgt=global.getModel("gt_ctgt"),async=require("async"),underscore=require("underscore"),moment=require("moment"),controller=require("../controllers/controller");
2
2
  module.exports=async 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");let $thang$$=Number($condition$$.thang),$nam$$=Number($condition$$.nam);const $app$$=await global.getModel("app").findOne({_id:$condition$$.id_app},{options:1}).lean();if(!$app$$)return $fn$$("C\u00f4ng ty n\u00e0y kh\u00f4ng t\u1ed3n t\u1ea1i");const $f_tien$$=
3
- ($app$$.options||{}).f_tien||0;(new Promise(($resole$$,$reject$$)=>{setImmediate(()=>{let $cond$$={id_app:$condition$$.id_app,nam:$nam$$,thang:$thang$$,yt_trung_gian:!1};$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_ctgt.find($cond$$).inTxn().lean().then($ctgt$$=>{$ctgt$$.forEach($c$$=>{$c$$.cong_tru=="2"&&($c$$.gt=-$c$$.gt,$c$$.gt_nt=-$c$$.gt_nt,$c$$.t_gt=
4
- -$c$$.t_gt,$c$$.t_gt_nt=-$c$$.t_gt_nt)});$resole$$($ctgt$$)}).catch($e$$=>{$reject$$($e$$)})})})).then($ctgt$$=>new Promise(($resolve$$,$reject$$)=>{$ctgt$$.groupBy(["ma_sp","ma_bp","id_lenhsx"],["gt","gt_nt","t_gt","t_gt_nt"],($e$$,$rs$$)=>{if($e$$)return $reject$$($e$$);$resolve$$($rs$$)})})).then($gts$$=>{let $ctrl$$=global.controllers.PNK;var $cond$$=underscore.pluck($gts$$,"ma_sp");$cond$$={id_app:$condition$$.id_app,ma_gd:"1",ma_ct:"PNK",ma_vt:{$in:$cond$$}};$condition$$.ma_bp&&($cond$$.ma_bp=
5
- $condition$$.ma_bp.toUpperCase());$condition$$.id_lenhsx&&mongoose.Types.ObjectId.isValid($condition$$.id_lenhsx)&&($cond$$.id_lenhsx=$condition$$.id_lenhsx);let $tu_ngay$$=moment(new Date($nam$$,$thang$$-1,1)).startOf("date").toDate(),$den_ngay$$=moment(new Date($nam$$,$thang$$,0)).endOf("date").toDate();$cond$$.ngay_ct={$gte:$tu_ngay$$,$lte:$den_ngay$$};sokho.find($cond$$).lean().then($rs$$=>{$rs$$.groupBy(["id_ct"],["sl_nhap"],($e$$,$vs$$)=>{if($e$$)return $fn$$($e$$);async.map($vs$$,($v$$,$callback$$)=>
6
- {pnk.findOne({_id:$v$$.id_ct},($e$$,$p$$)=>{if($e$$)return $callback$$($e$$);if(!$p$$)return $callback$$();setImmediate(()=>{$p$$.details.forEach($detail$$=>{$detail$$.ma_bp||($detail$$.ma_bp="");$detail$$.id_lenhsx||($detail$$.id_lenhsx="");let $gt$$=underscore.find($gts$$,$gt$$=>$gt$$.ma_sp==$detail$$.ma_vt&&$gt$$.ma_bp==$detail$$.ma_bp&&$gt$$.id_lenhsx==$detail$$.id_lenhsx);$gt$$&&($detail$$.gia_von=$gt$$.gt,$detail$$.gia_von_nt=$detail$$.gia_von,$detail$$.tien_nhap=Math.roundBy($detail$$.gia_von*
7
- $detail$$.sl_nhap,$f_tien$$),$detail$$.tien_nhap_nt=$detail$$.tien_nhap)});$p$$.save(($e$$,$n_p$$)=>{if($e$$)return $callback$$($e$$);controller.postData($n_p$$.toObject(),$ctrl$$,function($e$$){$callback$$($e$$)})})})})},($e$$,$rs$$)=>{$fn$$($e$$,$rs$$)})})}).catch($e$$=>{$fn$$($e$$)})}).catch($e$$=>{$fn$$($e$$)})};
3
+ ($app$$.options||{}).f_tien||0;(new Promise(($resole$$,$reject$$)=>{let $cond$$={id_app:$condition$$.id_app,nam:$nam$$,thang:$thang$$,yt_trung_gian:!1};$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_ctgt.find($cond$$).inTxn().lean().then($ctgt$$=>{$ctgt$$.forEach($c$$=>{$c$$.cong_tru=="2"&&($c$$.gt=-$c$$.gt,$c$$.gt_nt=-$c$$.gt_nt,$c$$.t_gt=-$c$$.t_gt,
4
+ $c$$.t_gt_nt=-$c$$.t_gt_nt)});$resole$$($ctgt$$)}).catch($e$$=>{$reject$$($e$$)})})).then($ctgt$$=>new Promise(($resolve$$,$reject$$)=>{$ctgt$$.groupBy(["ma_sp","ma_bp","id_lenhsx"],["gt","gt_nt","t_gt","t_gt_nt"],($e$$,$rs$$)=>{if($e$$)return $reject$$($e$$);$resolve$$($rs$$)})})).then($gts$$=>{let $ctrl$$=global.controllers.PNK;var $cond$$=underscore.pluck($gts$$,"ma_sp");$cond$$={id_app:$condition$$.id_app,ma_gd:"1",ma_ct:"PNK",ma_vt:{$in:$cond$$}};$condition$$.ma_bp&&($cond$$.ma_bp=$condition$$.ma_bp.toUpperCase());
5
+ $condition$$.id_lenhsx&&mongoose.Types.ObjectId.isValid($condition$$.id_lenhsx)&&($cond$$.id_lenhsx=$condition$$.id_lenhsx);let $tu_ngay$$=moment(new Date($nam$$,$thang$$-1,1)).startOf("date").toDate(),$den_ngay$$=moment(new Date($nam$$,$thang$$,0)).endOf("date").toDate();$cond$$.ngay_ct={$gte:$tu_ngay$$,$lte:$den_ngay$$};sokho.find($cond$$).lean().then($rs$$=>{$rs$$.groupBy(["id_ct"],["sl_nhap"],($e$$,$vs$$)=>{if($e$$)return $fn$$($e$$);async.mapSeries($vs$$,($v$$,$callback$$)=>{pnk.findOne({_id:$v$$.id_ct},
6
+ ($e$$,$p$$)=>{if($e$$)return $callback$$($e$$);if(!$p$$)return $callback$$();$p$$.details.forEach($detail$$=>{$detail$$.ma_bp||($detail$$.ma_bp="");$detail$$.id_lenhsx||($detail$$.id_lenhsx="");let $gt$$=underscore.find($gts$$,$gt$$=>$gt$$.ma_sp==$detail$$.ma_vt&&$gt$$.ma_bp==$detail$$.ma_bp&&$gt$$.id_lenhsx==$detail$$.id_lenhsx);$gt$$&&($detail$$.gia_von=$gt$$.gt,$detail$$.gia_von_nt=$detail$$.gia_von,$detail$$.tien_nhap=Math.roundBy($detail$$.gia_von*$detail$$.sl_nhap,$f_tien$$),$detail$$.tien_nhap_nt=
7
+ $detail$$.tien_nhap)});$p$$.save(($e$$,$n_p$$)=>{if($e$$)return $callback$$($e$$);controller.postData($n_p$$.toObject(),$ctrl$$,function($e$$){$callback$$($e$$)})})})},($e$$,$rs$$)=>{$fn$$($e$$,$rs$$)})})}).catch($e$$=>{$fn$$($e$$)})}).catch($e$$=>{$fn$$($e$$)})};
@@ -1,12 +1,12 @@
1
1
  const dmyt=global.getModel("dmyt"),gt_thcppstk=global.getModel("gt_thcppstk"),gt_ctgt=global.getModel("gt_ctgt"),gt_sltk=global.getModel("gt_sltk"),gt_hspb=global.getModel("gt_hspb"),async=require("async"),utils=require("../libs/utils"),_=require("lodash");
2
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),$query_yt$$={id_app:$condition$$.id_app,pt_phan_bo:"5",th_sp:!1,status:!0};$condition$$.ma_bp&&($query_yt$$.ma_bp={$in:[$condition$$.ma_bp.toUpperCase(),null,void 0]});let $sltk$$=[];dmyt.find($query_yt$$).lean().then(async $yts$$=>
3
- {if($yts$$.length>0){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)&&($cond$$.id_lenhsx=$condition$$.id_lenhsx);$sltk$$=await gt_sltk.find($cond$$).inTxn().lean();$sltk$$.forEach($p$$=>{$p$$.ma_bp=$p$$.ma_bp||"";$p$$.id_lenhsx=$p$$.id_lenhsx||""})}async.map($yts$$,($yt$$,$callback$$)=>{async.series({gt:$callback$$=>
4
- {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$$).inTxn().lean().then($pstk$$=>{$pstk$$.groupBy(["ma_bp","ma_yt","id_lenhsx"],["dd_dk","dd_dk_nt","ps_tk","ps_tk_nt"],($_sltk_e$$,$rs$$)=>{if($_sltk_e$$)return $callback$$($_sltk_e$$);
3
+ {if($yts$$.length>0){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)&&($cond$$.id_lenhsx=$condition$$.id_lenhsx);$sltk$$=await gt_sltk.find($cond$$).inTxn().lean();$sltk$$.forEach($p$$=>{$p$$.ma_bp=$p$$.ma_bp||"";$p$$.id_lenhsx=$p$$.id_lenhsx||""})}async.mapSeries($yts$$,($yt$$,$callback$$)=>{async.series({gt:$callback$$=>
4
+ {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$$).inTxn().lean().then($pstk$$=>{$pstk$$.groupBy(["ma_bp","ma_yt","id_lenhsx"],["dd_dk","dd_dk_nt","ps_tk","ps_tk_nt"],($_sltk_e$$,$rs$$)=>{if($_sltk_e$$)return $callback$$($_sltk_e$$);
5
5
  $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;$p$$.ma_bp=$p$$.ma_bp||"";$p$$.ma_yt=$p$$.ma_yt||"";$p$$.id_lenhsx=$p$$.id_lenhsx||"";$p$$.th_bp=$yt$$.th_bp;$p$$.th_lsx=$yt$$.th_lsx});$_sltk_e$$=_.cloneDeep($sltk$$);let $fiels_join$$={};$yt$$.th_bp&&($fiels_join$$.ma_bp="ma_bp");$yt$$.th_lsx&&($fiels_join$$.id_lenhsx="id_lenhsx");$rs$$.crossJoin($_sltk_e$$,
6
- $fiels_join$$,async $dt$$=>{$callback$$(null,$dt$$)})})}).catch($e$$=>{$callback$$($e$$)})})}},function($e$$,$rs$$){if($e$$)return $callback$$($e$$);$callback$$(null,$rs$$.gt)})},async($data_pstk_e$$,$condition_s_cppstk_t_sl_tinh_he_so$$)=>{if($data_pstk_e$$)return $fn$$($data_pstk_e$$);$data_pstk_e$$=$condition_s_cppstk_t_sl_tinh_he_so$$.reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]);await $data_pstk_e$$.asyncJoinModel2($condition$$.id_app,gt_hspb,{where:$item$$=>({nam:$item$$.nam,thang:$item$$.thang,
7
- ma_sp:$item$$.ma_sp,ma_yt:{$in:[void 0,null,"",$item$$.ma_yt]},ma_bp:{$in:[void 0,null,"",$item$$.ma_bp]},id_lenhsx:{$in:[void 0,null,"",$item$$.id_lenhsx]}}),fields:{he_so_dc:"he_so",dieu_chinh_slsx:"dieu_chinh_slsx"}});await $data_pstk_e$$.filter($r$$=>$r$$.he_so_dc==void 0).asyncJoinModel2($condition$$.id_app,gt_hspb,{where:$item$$=>({nam:$item$$.nam,thang:0,ma_sp:$item$$.ma_sp,ma_yt:{$in:[void 0,null,"",$item$$.ma_yt]},ma_bp:{$in:[void 0,null,"",$item$$.ma_bp]},id_lenhsx:{$in:[void 0,null,"",
8
- $item$$.id_lenhsx]}}),fields:{he_so_dc:"he_so",dieu_chinh_slsx:"dieu_chinh_slsx"}});$data_pstk_e$$.forEach($r$$=>{$r$$.he_so_dc=$r$$.he_so_dc||0;$r$$.sl_tinh_he_so=$r$$.dieu_chinh_slsx?($r$$.sl_nk_tk||0)*$r$$.he_so_dc+($r$$.sl_dd_ck||0)*$r$$.he_so_dc:$r$$.he_so_dc});for(let $s$$ of $data_pstk_e$$){$condition_s_cppstk_t_sl_tinh_he_so$$={ma_yt:$s$$.ma_yt};$s$$.th_bp&&($condition_s_cppstk_t_sl_tinh_he_so$$.ma_bp=$s$$.ma_bp);$s$$.th_lsx&&($condition_s_cppstk_t_sl_tinh_he_so$$.id_lenhsx=$s$$.id_lenhsx);
9
- $condition_s_cppstk_t_sl_tinh_he_so$$=$data_pstk_e$$.csum("sl_tinh_he_so",$condition_s_cppstk_t_sl_tinh_he_so$$);$s$$.he_so=$condition_s_cppstk_t_sl_tinh_he_so$$!==0?$s$$.sl_tinh_he_so/$condition_s_cppstk_t_sl_tinh_he_so$$:0;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||
10
- ($s$$.ty_le_ht_dk=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=utils.round($s$$.he_so*$s$$.dd_dk,5);$s$$.dd_dk_nt=utils.round($s$$.he_so*$s$$.dd_dk_nt,5);$s$$.ps_tk=utils.round($s$$.he_so*$s$$.ps_tk,5);$s$$.ps_tk_nt=utils.round($s$$.he_so*$s$$.ps_tk_nt,5);$s$$.sl_dd_dk_qd=utils.round($s$$.sl_dd_dk*$s$$.ty_le_ht_dk/100,5);$s$$.sl_dd_ck_qd=
11
- utils.round($s$$.sl_dd_ck*$s$$.ty_le_ht_ck/100,5);$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=utils.round($s$$.sl_nk_tk===0?0:$s$$.t_cp_sx/$s$$.sl_sp_ht_qd,5);$s$$.gt_nt=utils.round($s$$.sl_nk_tk===0?0:$s$$.t_cp_sx_nt/$s$$.sl_sp_ht_qd,5);$s$$.t_gt=utils.round($s$$.gt*$s$$.sl_nk_tk,5);$s$$.t_gt_nt=utils.round($s$$.gt_nt*$s$$.sl_nk_tk,5);$s$$.dd_ck=utils.round($s$$.t_cp_sx-
12
- $s$$.t_gt,5);$s$$.dd_ck_nt=utils.round($s$$.t_cp_sx_nt-$s$$.t_gt_nt,5)}gt_ctgt.create($data_pstk_e$$.filter($d$$=>$d$$.ma_sp),($e$$,$rs$$)=>{$e$$&&console.error($e$$.message);$fn$$($e$$,$rs$$)})})}).catch($e$$=>{$fn$$($e$$)})};
6
+ $fiels_join$$,async $dt$$=>{$callback$$(null,$dt$$)})})}).catch($e$$=>{$callback$$($e$$)})}},function($e$$,$rs$$){if($e$$)return $callback$$($e$$);$callback$$(null,$rs$$.gt)})},async($data_pstk_e$$,$condition_s_cppstk_t_sl_tinh_he_so$$)=>{if($data_pstk_e$$)return $fn$$($data_pstk_e$$);$data_pstk_e$$=$condition_s_cppstk_t_sl_tinh_he_so$$.reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]);await $data_pstk_e$$.asyncJoinModel2($condition$$.id_app,gt_hspb,{where:$item$$=>({nam:$item$$.nam,thang:$item$$.thang,ma_sp:$item$$.ma_sp,
7
+ ma_yt:{$in:[void 0,null,"",$item$$.ma_yt]},ma_bp:{$in:[void 0,null,"",$item$$.ma_bp]},id_lenhsx:{$in:[void 0,null,"",$item$$.id_lenhsx]}}),fields:{he_so_dc:"he_so",dieu_chinh_slsx:"dieu_chinh_slsx"}});await $data_pstk_e$$.filter($r$$=>$r$$.he_so_dc==void 0).asyncJoinModel2($condition$$.id_app,gt_hspb,{where:$item$$=>({nam:$item$$.nam,thang:0,ma_sp:$item$$.ma_sp,ma_yt:{$in:[void 0,null,"",$item$$.ma_yt]},ma_bp:{$in:[void 0,null,"",$item$$.ma_bp]},id_lenhsx:{$in:[void 0,null,"",$item$$.id_lenhsx]}}),
8
+ fields:{he_so_dc:"he_so",dieu_chinh_slsx:"dieu_chinh_slsx"}});$data_pstk_e$$.forEach($r$$=>{$r$$.he_so_dc=$r$$.he_so_dc||0;$r$$.sl_tinh_he_so=$r$$.dieu_chinh_slsx?($r$$.sl_nk_tk||0)*$r$$.he_so_dc+($r$$.sl_dd_ck||0)*$r$$.he_so_dc:$r$$.he_so_dc});for(let $s$$ of $data_pstk_e$$){$condition_s_cppstk_t_sl_tinh_he_so$$={ma_yt:$s$$.ma_yt};$s$$.th_bp&&($condition_s_cppstk_t_sl_tinh_he_so$$.ma_bp=$s$$.ma_bp);$s$$.th_lsx&&($condition_s_cppstk_t_sl_tinh_he_so$$.id_lenhsx=$s$$.id_lenhsx);$condition_s_cppstk_t_sl_tinh_he_so$$=
9
+ $data_pstk_e$$.csum("sl_tinh_he_so",$condition_s_cppstk_t_sl_tinh_he_so$$);$s$$.he_so=$condition_s_cppstk_t_sl_tinh_he_so$$!==0?$s$$.sl_tinh_he_so/$condition_s_cppstk_t_sl_tinh_he_so$$:0;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=0);if(!$s$$.dd_dk||
10
+ 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=utils.round($s$$.he_so*$s$$.dd_dk,5);$s$$.dd_dk_nt=utils.round($s$$.he_so*$s$$.dd_dk_nt,5);$s$$.ps_tk=utils.round($s$$.he_so*$s$$.ps_tk,5);$s$$.ps_tk_nt=utils.round($s$$.he_so*$s$$.ps_tk_nt,5);$s$$.sl_dd_dk_qd=utils.round($s$$.sl_dd_dk*$s$$.ty_le_ht_dk/100,5);$s$$.sl_dd_ck_qd=utils.round($s$$.sl_dd_ck*
11
+ $s$$.ty_le_ht_ck/100,5);$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=utils.round($s$$.sl_nk_tk===0?0:$s$$.t_cp_sx/$s$$.sl_sp_ht_qd,5);$s$$.gt_nt=utils.round($s$$.sl_nk_tk===0?0:$s$$.t_cp_sx_nt/$s$$.sl_sp_ht_qd,5);$s$$.t_gt=utils.round($s$$.gt*$s$$.sl_nk_tk,5);$s$$.t_gt_nt=utils.round($s$$.gt_nt*$s$$.sl_nk_tk,5);$s$$.dd_ck=utils.round($s$$.t_cp_sx-$s$$.t_gt,
12
+ 5);$s$$.dd_ck_nt=utils.round($s$$.t_cp_sx_nt-$s$$.t_gt_nt,5)}gt_ctgt.create($data_pstk_e$$.filter($d$$=>$d$$.ma_sp),($e$$,$rs$$)=>{$e$$&&console.error($e$$.message);$fn$$($e$$,$rs$$)})})}).catch($e$$=>{$fn$$($e$$)})};
@@ -1,11 +1,11 @@
1
1
  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"),utils=require("../libs/utils");
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$$).inTxn().lean().then($ctgt$$=>{$resole$$($ctgt$$)}).catch($e$$=>{$reject$$($e$$)})})})).then($ctgt$$=>new Promise(($resolve$$,$reject$$)=>{setImmediate(()=>{var $dsyt_datinh_query_yt$$=underscore.pluck($ctgt$$,"ma_yt");$dsyt_datinh_query_yt$$={id_app:$condition$$.id_app,status:!0,pt_phan_bo:"2",th_sp:!1,ma_yt:{$nin:$dsyt_datinh_query_yt$$},yt_tinh_hs_pb:{$in:$dsyt_datinh_query_yt$$}};$condition$$.ma_bp&&($dsyt_datinh_query_yt$$.ma_bp=
4
- {$in:[$condition$$.ma_bp.toUpperCase(),null,void 0]});dmyt.find($dsyt_datinh_query_yt$$).lean().then($yts$$=>{$resolve$$({yts:$yts$$,ctgt_tinhheso:$ctgt$$})}).catch($e$$=>{$reject$$($e$$)})})})).then($data$$=>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=
5
- $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$$).inTxn().lean().then($cppstk$$=>{$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$$);$rs$$.forEach($p$$=>{$p$$.ma_bp=$p$$.ma_bp||"";$p$$.ma_yt=$p$$.ma_yt||"";$p$$.id_lenhsx=$p$$.id_lenhsx||""});$data$$.cppstk=$rs$$;
6
- $resolve$$($data$$)})}).catch($e$$=>{$reject$$($e$$)})})})).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)&&($cond$$.id_lenhsx=$condition$$.id_lenhsx);gt_sltk.find($cond$$).inTxn().lean().then($sltk$$=>{$sltk$$.forEach($p$$=>{$p$$.ma_bp=$p$$.ma_bp||
7
- "";$p$$.id_lenhsx=$p$$.id_lenhsx||""});$data$$.sltk=$sltk$$;$resolve$$($data$$)}).catch($e$$=>{$reject$$($e$$)})})})).then($data$$=>{async.map($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||"",ma_yt:$yt$$.ma_yt,id_app:$yths$$.id_app,nam:$yths$$.nam,
8
- thang:$yths$$.thang};$gt$$.he_so=$t_gt$$!==0?$yths$$.t_gt/$t_gt$$:0;$gt$$.yt_trung_gian=$yt$$.yt_trung_gian;$gt$$.cong_tru=$yt$$.cong_tru;$gts$$.push($gt$$)});$cppstk$$=underscore.filter($data$$.cppstk,$c$$=>$c$$.ma_yt==$yt$$.ma_yt);$gts$$.crossJoin($cppstk$$,{ma_bp:"ma_bp",id_lenhsx:"id_lenhsx"},$rs$$=>{$callback$$(null,$rs$$)})})},($e$$,$rs$$)=>{if($e$$)return $fn$$($e$$);setImmediate(()=>{let $data_pstk$$=[];$rs$$.forEach($r$$=>{$r$$.forEach($_r$$=>{$data_pstk$$.push($_r$$)})});$data_pstk$$.crossJoin($data$$.sltk,
9
- {ma_sp:"ma_sp",ma_bp:"ma_bp",id_lenhsx:"id_lenhsx"},$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=0),$s$$.dd_dk||($s$$.dd_dk=0),$s$$.dd_dk_nt||($s$$.dd_dk_nt=0),$s$$.ps_tk||($s$$.ps_tk=0),$s$$.ps_tk_nt||
10
- ($s$$.ps_tk_nt=0),$s$$.dd_dk=utils.round($s$$.he_so*$s$$.dd_dk,5),$s$$.dd_dk_nt=utils.round($s$$.he_so*$s$$.dd_dk_nt,5),$s$$.ps_tk=utils.round($s$$.he_so*$s$$.ps_tk,5),$s$$.ps_tk_nt=utils.round($s$$.he_so*$s$$.ps_tk_nt,5),$s$$.sl_dd_dk_qd=utils.round($s$$.sl_dd_dk*$s$$.ty_le_ht_dk/100,5),$s$$.sl_dd_ck_qd=utils.round($s$$.sl_dd_ck*$s$$.ty_le_ht_ck/100,5),$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=
11
- $s$$.dd_dk_nt+$s$$.ps_tk_nt,$s$$.gt=utils.round($s$$.sl_nk_tk===0?0:$s$$.t_cp_sx/$s$$.sl_sp_ht_qd,5),$s$$.gt_nt=utils.round($s$$.sl_nk_tk===0?0:$s$$.t_cp_sx_nt/$s$$.sl_sp_ht_qd,5),$s$$.t_gt=utils.round($s$$.gt*$s$$.sl_nk_tk,5),$s$$.t_gt_nt=utils.round($s$$.gt_nt*$s$$.sl_nk_tk,5),$s$$.dd_ck=utils.round($s$$.t_cp_sx-$s$$.t_gt,5),$s$$.dd_ck_nt=utils.round($s$$.t_cp_sx_nt-$s$$.t_gt_nt,5);gt_ctgt.create($data_pstk$$,($e$$,$rs$$)=>{$e$$&&console.log($e$$);$fn$$($e$$,$rs$$)})})})})}).catch($e$$=>{$fn$$($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,ma_yt");(new Promise(($resole$$,$reject$$)=>{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$$).inTxn().lean().then($ctgt$$=>{$resole$$($ctgt$$)}).catch($e$$=>{$reject$$($e$$)})})).then($ctgt$$=>new Promise(($resolve$$,$reject$$)=>{var $dsyt_datinh_query_yt$$=underscore.pluck($ctgt$$,"ma_yt");$dsyt_datinh_query_yt$$={id_app:$condition$$.id_app,status:!0,pt_phan_bo:"2",th_sp:!1,ma_yt:{$nin:$dsyt_datinh_query_yt$$},yt_tinh_hs_pb:{$in:$dsyt_datinh_query_yt$$}};$condition$$.ma_bp&&($dsyt_datinh_query_yt$$.ma_bp={$in:[$condition$$.ma_bp.toUpperCase(),
4
+ null,void 0]});dmyt.find($dsyt_datinh_query_yt$$).lean().then($yts$$=>{$resolve$$({yts:$yts$$,ctgt_tinhheso:$ctgt$$})}).catch($e$$=>{$reject$$($e$$)})})).then($data$$=>new Promise(($resolve$$,$reject$$)=>{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&&
5
+ mongoose.Types.ObjectId.isValid($condition$$.id_lenhsx)&&($cond$jscomp$1_yts$$.id_lenhsx=$condition$$.id_lenhsx);gt_thcppstk.find($cond$jscomp$1_yts$$).inTxn().lean().then($cppstk$$=>{$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$$);$rs$$.forEach($p$$=>{$p$$.ma_bp=$p$$.ma_bp||"";$p$$.ma_yt=$p$$.ma_yt||"";$p$$.id_lenhsx=$p$$.id_lenhsx||""});$data$$.cppstk=$rs$$;$resolve$$($data$$)})}).catch($e$$=>{$reject$$($e$$)})})).then($data$$=>
6
+ new Promise(($resolve$$,$reject$$)=>{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)&&($cond$$.id_lenhsx=$condition$$.id_lenhsx);gt_sltk.find($cond$$).inTxn().lean().then($sltk$$=>{$sltk$$.forEach($p$$=>{$p$$.ma_bp=$p$$.ma_bp||"";$p$$.id_lenhsx=$p$$.id_lenhsx||""});$data$$.sltk=$sltk$$;$resolve$$($data$$)}).catch($e$$=>
7
+ {$reject$$($e$$)})})).then($data$$=>{async.mapSeries($data$$.yts,($yt$$,$callback$$)=>{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||"",ma_yt:$yt$$.ma_yt,id_app:$yths$$.id_app,nam:$yths$$.nam,thang:$yths$$.thang};$gt$$.he_so=$t_gt$$!==0?$yths$$.t_gt/$t_gt$$:0;$gt$$.yt_trung_gian=$yt$$.yt_trung_gian;
8
+ $gt$$.cong_tru=$yt$$.cong_tru;$gts$$.push($gt$$)});$cppstk$$=underscore.filter($data$$.cppstk,$c$$=>$c$$.ma_yt==$yt$$.ma_yt);$gts$$.crossJoin($cppstk$$,{ma_bp:"ma_bp",id_lenhsx:"id_lenhsx"},$rs$$=>{$callback$$(null,$rs$$)})},($e$$,$rs$$)=>{if($e$$)return $fn$$($e$$);let $data_pstk$$=[];$rs$$.forEach($r$$=>{$r$$.forEach($_r$$=>{$data_pstk$$.push($_r$$)})});$data_pstk$$.crossJoin($data$$.sltk,{ma_sp:"ma_sp",ma_bp:"ma_bp",id_lenhsx:"id_lenhsx"},$data_pstk$$=>{for(let $s$$ of $data_pstk$$)delete $s$$._id,
9
+ $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=0),$s$$.dd_dk||($s$$.dd_dk=0),$s$$.dd_dk_nt||($s$$.dd_dk_nt=0),$s$$.ps_tk||($s$$.ps_tk=0),$s$$.ps_tk_nt||($s$$.ps_tk_nt=0),$s$$.dd_dk=utils.round($s$$.he_so*$s$$.dd_dk,5),$s$$.dd_dk_nt=utils.round($s$$.he_so*$s$$.dd_dk_nt,
10
+ 5),$s$$.ps_tk=utils.round($s$$.he_so*$s$$.ps_tk,5),$s$$.ps_tk_nt=utils.round($s$$.he_so*$s$$.ps_tk_nt,5),$s$$.sl_dd_dk_qd=utils.round($s$$.sl_dd_dk*$s$$.ty_le_ht_dk/100,5),$s$$.sl_dd_ck_qd=utils.round($s$$.sl_dd_ck*$s$$.ty_le_ht_ck/100,5),$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=utils.round($s$$.sl_nk_tk===0?0:$s$$.t_cp_sx/$s$$.sl_sp_ht_qd,5),$s$$.gt_nt=
11
+ utils.round($s$$.sl_nk_tk===0?0:$s$$.t_cp_sx_nt/$s$$.sl_sp_ht_qd,5),$s$$.t_gt=utils.round($s$$.gt*$s$$.sl_nk_tk,5),$s$$.t_gt_nt=utils.round($s$$.gt_nt*$s$$.sl_nk_tk,5),$s$$.dd_ck=utils.round($s$$.t_cp_sx-$s$$.t_gt,5),$s$$.dd_ck_nt=utils.round($s$$.t_cp_sx_nt-$s$$.t_gt_nt,5);gt_ctgt.create($data_pstk$$,($e$$,$rs$$)=>{$e$$&&console.log($e$$);$fn$$($e$$,$rs$$)})})})}).catch($e$$=>{$fn$$($e$$)})};
@@ -1,9 +1,9 @@
1
1
  var sokho=global.getModel("sokho"),gt_sltk=global.getModel("gt_sltk"),spdd_dk=global.getModel("spdd_dk"),spdd_ck=global.getModel("spdd_ck");const 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(),$data$$=[];async.parallel({nhapkhotp:$callback$$=>
3
- {setImmediate(()=>{let $condition_nhapkho$$={id_app:$condition$$.id_app,ngay_ct:{$gte:$tu_ngay$$,$lte:$den_ngay$$},ma_gd:"1",ma_ct:"PNK"};$condition$$.ma_bp&&($condition_nhapkho$$.ma_bp=$condition$$.ma_bp.toUpperCase());$condition$$.id_lenhsx&&!mongoose.Types.ObjectId.isValid($condition$$.id_lenhsx)&&delete $condition$$.id_lenhsx;$condition$$.ma_sp&&($condition_nhapkho$$.ma_sp=$condition$$.ma_sp.toUpperCase());sokho.find($condition_nhapkho$$).lean().then($sk$$=>{for(let $s$$ of $sk$$)$data$$.push({ma_sp:$s$$.ma_vt,
4
- ma_bp:$s$$.ma_bp,id_lenhsx:$s$$.id_lenhsx,sl_nk_tk:$s$$.sl_nhap_qd,ty_le_ht_dk:0,ty_le_ht_ck:0});$callback$$(null)}).catch($e$$=>{$callback$$($e$$)})})},ddck:$callback$$=>{setImmediate(()=>{let $condition_ck$$={id_app:$condition$$.id_app,nam:$nam$$,thang:$thang$$};$condition$$.ma_sp&&($condition_ck$$.ma_sp=$condition$$.ma_sp.toUpperCase());$condition$$.ma_bp&&($condition_ck$$.ma_bp=$condition$$.ma_bp.toUpperCase());$condition$$.id_lenhsx&&mongoose.Types.ObjectId.isValid($condition$$.id_lenhsx)&&($condition_ck$$.id_lenhsx=
5
- $condition$$.id_lenhsx);spdd_ck.find($condition_ck$$).lean().then($ck$$=>{for(let $s$$ of $ck$$)$s$$.sl_dd_ck=$s$$.sl_dd,$s$$.ty_le_ht_ck=$s$$.ty_le_ht,$s$$.ty_le_ht_dk=0,$data$$.push($s$$);$callback$$(null)}).catch($e$$=>{$callback$$($e$$)})})},dddk:$callback$$=>{async.parallel({dauky:$callback$$=>{setImmediate(()=>{let $condition_dk$$={id_app:$condition$$.id_app,nam:$nam$$,thang:$thang$$};$condition$$.ma_sp&&($condition_dk$$.ma_sp=$condition$$.ma_sp.toUpperCase());$condition$$.ma_bp&&($condition_dk$$.ma_bp=
6
- $condition$$.ma_bp.toUpperCase());$condition$$.id_lenhsx&&mongoose.Types.ObjectId.isValid($condition$$.id_lenhsx)&&($condition_dk$$.id_lenhsx=$condition$$.id_lenhsx);spdd_dk.find($condition_dk$$).lean().then($dk$$=>{$callback$$(null,$dk$$)}).catch($e$$=>{$callback$$($e$$)})})},cuoikytruoc:$callback$$=>{setImmediate(()=>{let $condition_ck$$={id_app:$condition$$.id_app,nam:$nam$$,thang:$thang$$-1};$condition_ck$$.thang===0&&($condition_ck$$.thang=12,--$condition_ck$$.nam);$condition$$.ma_sp&&($condition_ck$$.ma_sp=
7
- $condition$$.ma_sp.toUpperCase());$condition$$.ma_bp&&($condition_ck$$.ma_bp=$condition$$.ma_bp.toUpperCase());$condition$$.id_lenhsx&&mongoose.Types.ObjectId.isValid($condition$$.id_lenhsx)&&($condition_ck$$.id_lenhsx=$condition$$.id_lenhsx);spdd_ck.find($condition_ck$$).lean().then($ck$$=>{$callback$$(null,$ck$$)}).catch($e$$=>{$callback$$($e$$)})})}},function($dauky_e$$,$rs$$){if($dauky_e$$)return $callback$$($dauky_e$$);$dauky_e$$=$rs$$.dauky;for(let $dk$$ of $dauky_e$$)$dk$$.sl_dd_dk=$dk$$.sl_dd,
8
- $dk$$.ty_le_ht_dk=$dk$$.ty_le_ht,$dk$$.ty_le_ht_ck=0,$data$$.push($dk$$);for(let $ckt$$ of $rs$$.cuoikytruoc)$ckt$$.sl_dd_dk=$ckt$$.sl_dd,$ckt$$.ty_le_ht_dk=$ckt$$.ty_le_ht,$ckt$$.ty_le_ht_ck=0,underscore.find($dauky_e$$,$d$$=>$d$$.ma_sp==$ckt$$.ma_sp&&$d$$.ma_bp==$ckt$$.ma_bp&&$d$$.id_lenhsx==$ckt$$.id_lenhsx)||$data$$.push($ckt$$);$callback$$(null)})}},function($e$$){if($e$$)return $fn$$($e$$);$data$$.groupBy(["ma_sp","ma_bp","id_lenhsx"],["sl_dd_dk","sl_nk_tk","sl_dd_ck"],function($e$$,$rs$$){if($e$$)return $fn$$($e$$);
9
- for(let $r$$ of $rs$$)$r$$.id_app=$condition$$.id_app,$r$$.nam=$condition$$.nam,$r$$.thang=$condition$$.thang,$r$$.ty_le_ht_dk||($r$$.ty_le_ht_dk=0),$r$$.ty_le_ht_ck||($r$$.ty_le_ht_ck=0),$r$$.sl_nk_tk||($r$$.sl_nk_tk=0),$r$$.sl_dd_ck||($r$$.sl_dd_ck=0),$r$$.sl_dd_dk||($r$$.sl_dd_dk=0),$r$$.sl_sx_tk=$r$$.sl_nk_tk+$r$$.sl_dd_ck-$r$$.sl_dd_dk;gt_sltk.create($rs$$,($e$$,$dt$$)=>{$fn$$($e$$,$dt$$)})},{fieldmaxs:["ty_le_ht_dk","ty_le_ht_ck"]})})};
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(),$data$$=[];async.series({nhapkhotp:$callback$$=>{let $condition_nhapkho$$=
3
+ {id_app:$condition$$.id_app,ngay_ct:{$gte:$tu_ngay$$,$lte:$den_ngay$$},ma_gd:"1",ma_ct:"PNK"};$condition$$.ma_bp&&($condition_nhapkho$$.ma_bp=$condition$$.ma_bp.toUpperCase());$condition$$.id_lenhsx&&!mongoose.Types.ObjectId.isValid($condition$$.id_lenhsx)&&delete $condition$$.id_lenhsx;$condition$$.ma_sp&&($condition_nhapkho$$.ma_sp=$condition$$.ma_sp.toUpperCase());sokho.find($condition_nhapkho$$).lean().then($sk$$=>{for(let $s$$ of $sk$$)$data$$.push({ma_sp:$s$$.ma_vt,ma_bp:$s$$.ma_bp,id_lenhsx:$s$$.id_lenhsx,
4
+ sl_nk_tk:$s$$.sl_nhap_qd,ty_le_ht_dk:0,ty_le_ht_ck:0});$callback$$(null)}).catch($e$$=>{$callback$$($e$$)})},ddck:$callback$$=>{let $condition_ck$$={id_app:$condition$$.id_app,nam:$nam$$,thang:$thang$$};$condition$$.ma_sp&&($condition_ck$$.ma_sp=$condition$$.ma_sp.toUpperCase());$condition$$.ma_bp&&($condition_ck$$.ma_bp=$condition$$.ma_bp.toUpperCase());$condition$$.id_lenhsx&&mongoose.Types.ObjectId.isValid($condition$$.id_lenhsx)&&($condition_ck$$.id_lenhsx=$condition$$.id_lenhsx);spdd_ck.find($condition_ck$$).lean().then($ck$$=>
5
+ {for(let $s$$ of $ck$$)$s$$.sl_dd_ck=$s$$.sl_dd,$s$$.ty_le_ht_ck=$s$$.ty_le_ht,$s$$.ty_le_ht_dk=0,$data$$.push($s$$);$callback$$(null)}).catch($e$$=>{$callback$$($e$$)})},dddk:$callback$$=>{async.parallel({dauky:$callback$$=>{let $condition_dk$$={id_app:$condition$$.id_app,nam:$nam$$,thang:$thang$$};$condition$$.ma_sp&&($condition_dk$$.ma_sp=$condition$$.ma_sp.toUpperCase());$condition$$.ma_bp&&($condition_dk$$.ma_bp=$condition$$.ma_bp.toUpperCase());$condition$$.id_lenhsx&&mongoose.Types.ObjectId.isValid($condition$$.id_lenhsx)&&
6
+ ($condition_dk$$.id_lenhsx=$condition$$.id_lenhsx);spdd_dk.find($condition_dk$$).lean().then($dk$$=>{$callback$$(null,$dk$$)}).catch($e$$=>{$callback$$($e$$)})},cuoikytruoc:$callback$$=>{let $condition_ck$$={id_app:$condition$$.id_app,nam:$nam$$,thang:$thang$$-1};$condition_ck$$.thang===0&&($condition_ck$$.thang=12,--$condition_ck$$.nam);$condition$$.ma_sp&&($condition_ck$$.ma_sp=$condition$$.ma_sp.toUpperCase());$condition$$.ma_bp&&($condition_ck$$.ma_bp=$condition$$.ma_bp.toUpperCase());$condition$$.id_lenhsx&&
7
+ mongoose.Types.ObjectId.isValid($condition$$.id_lenhsx)&&($condition_ck$$.id_lenhsx=$condition$$.id_lenhsx);spdd_ck.find($condition_ck$$).lean().then($ck$$=>{$callback$$(null,$ck$$)}).catch($e$$=>{$callback$$($e$$)})}},function($dauky_e$$,$rs$$){if($dauky_e$$)return $callback$$($dauky_e$$);$dauky_e$$=$rs$$.dauky;for(let $dk$$ of $dauky_e$$)$dk$$.sl_dd_dk=$dk$$.sl_dd,$dk$$.ty_le_ht_dk=$dk$$.ty_le_ht,$dk$$.ty_le_ht_ck=0,$data$$.push($dk$$);for(let $ckt$$ of $rs$$.cuoikytruoc)$ckt$$.sl_dd_dk=$ckt$$.sl_dd,
8
+ $ckt$$.ty_le_ht_dk=$ckt$$.ty_le_ht,$ckt$$.ty_le_ht_ck=0,underscore.find($dauky_e$$,$d$$=>$d$$.ma_sp==$ckt$$.ma_sp&&$d$$.ma_bp==$ckt$$.ma_bp&&$d$$.id_lenhsx==$ckt$$.id_lenhsx)||$data$$.push($ckt$$);$callback$$(null)})}},function($e$$){if($e$$)return $fn$$($e$$);$data$$.groupBy(["ma_sp","ma_bp","id_lenhsx"],["sl_dd_dk","sl_nk_tk","sl_dd_ck"],function($e$$,$rs$$){if($e$$)return $fn$$($e$$);for(let $r$$ of $rs$$)$r$$.id_app=$condition$$.id_app,$r$$.nam=$condition$$.nam,$r$$.thang=$condition$$.thang,$r$$.ty_le_ht_dk||
9
+ ($r$$.ty_le_ht_dk=0),$r$$.ty_le_ht_ck||($r$$.ty_le_ht_ck=0),$r$$.sl_nk_tk||($r$$.sl_nk_tk=0),$r$$.sl_dd_ck||($r$$.sl_dd_ck=0),$r$$.sl_dd_dk||($r$$.sl_dd_dk=0),$r$$.sl_sx_tk=$r$$.sl_nk_tk+$r$$.sl_dd_ck-$r$$.sl_dd_dk;gt_sltk.create($rs$$,($e$$,$dt$$)=>{$fn$$($e$$,$dt$$)})},{fieldmaxs:["ty_le_ht_dk","ty_le_ht_ck"]})})};
@@ -1,10 +1,10 @@
1
1
  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"),_=require("lodash"),moment=require("moment");
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");var $query_yt_thang$$=Number($condition$$.thang);let $nam$$=Number($condition$$.nam),$tu_ngay$$=moment(new Date($nam$$,$query_yt_thang$$-1,1)).startOf("date").toDate(),$den_ngay$$=moment(new Date($nam$$,$query_yt_thang$$,0)).endOf("date").toDate();$query_yt_thang$$=
3
- {id_app:$condition$$.id_app,status:!0};$condition$$.ma_bp&&($query_yt_thang$$.ma_bp={$in:[$condition$$.ma_bp.toUpperCase(),null,void 0]});dmyt.find($query_yt_thang$$).lean().then($yts$$=>{let $data$$=[];async.map($yts$$,($yt$$,$callback$$)=>{async.parallel({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());
4
- $condition$$.id_lenhsx&&mongoose.Types.ObjectId.isValid($condition$$.id_lenhsx)&&($cond$$.id_lenhsx=$condition$$.id_lenhsx);ytdd_dk.find($cond$$).lean().then($rs$$=>{for(let $dd$$ of $rs$$)$dd$$.dd_dk_nt=$dd$$.tien_nt,$dd$$.dd_dk=$dd$$.tien,$data$$.push($dd$$);$resolve$$($rs$$)}).catch($e$$=>{$reject$$($e$$)})})})).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());
5
- $condition$$.id_lenhsx&&mongoose.Types.ObjectId.isValid($condition$$.id_lenhsx)&&($cond$$.id_lenhsx=$condition$$.id_lenhsx);$cond$$.thang===0&&($cond$$.thang=12,--$cond$$.nam);ytdd_ck.find($cond$$).lean().then($rs$$=>{for(let $ck$$ of $rs$$)_.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$$)})})}).catch($e$$=>
6
- {$callback$$($e$$)})},ps:$callback$$=>{setImmediate(()=>{let $cond$$={id_app:$condition$$.id_app,ngay_ct:{$gte:$tu_ngay$$,$lte:$den_ngay$$}};$condition$$.id_lenhsx&&mongoose.Types.ObjectId.isValid($condition$$.id_lenhsx)&&($cond$$.id_lenhsx=$condition$$.id_lenhsx);let $md$$;$yt$$.ma_bp_cp&&($cond$$.ma_bp=$yt$$.ma_bp_cp);$yt$$.ma_dt_cp&&($cond$$.ma_dt=$yt$$.ma_dt_cp);$yt$$.ma_phi_cp&&($cond$$.ma_phi=$yt$$.ma_phi_cp);$yt$$.ma_kho_cp&&($cond$$.ma_kho=$yt$$.ma_kho_cp);$yt$$.ma_vt_cp&&($cond$$.ma_vt=$yt$$.ma_vt_cp);
7
- $yt$$.th_nvl?($md$$=sokho,_.isArray($yt$$.tk_no)&&$yt$$.tk_no.length>0&&($cond$$.tk_du={$regex:$yt$$.tk_no.reg(),$options:"i"}),_.isArray($yt$$.tk_co)&&$yt$$.tk_co.length>0&&($cond$$.tk_vt={$regex:$yt$$.tk_co.reg(),$options:"i"})):($md$$=socai,_.isArray($yt$$.tk_no)&&$yt$$.tk_no.length>0&&($cond$$.tk_no={$regex:$yt$$.tk_no.reg(),$options:"i"}),_.isArray($yt$$.tk_co)&&$yt$$.tk_co.length>0&&($cond$$.tk_co={$regex:$yt$$.tk_co.reg(),$options:"i"}));$md$$.find($cond$$).lean().then($rows$$=>{let $keys$$=
8
- [],$sumfields$$;$yt$$.ma_bp&&$rows$$.forEach($r$$=>{$r$$.ma_bp=$yt$$.ma_bp});$yt$$.th_bp&&($rows$$=$rows$$.filter($r$$=>$r$$.ma_bp),$condition$$.ma_bp&&($rows$$=$rows$$.filter($r$$=>$r$$.ma_bp==$condition$$.ma_bp.toUpperCase())),$keys$$.push("ma_bp"));$yt$$.th_lsx&&($rows$$=$rows$$.filter($r$$=>$r$$.id_lenhsx),$keys$$.push("id_lenhsx"));$yt$$.th_sp&&($rows$$=$rows$$.filter($r$$=>$r$$.ma_sp),$keys$$.push("ma_sp"));$yt$$.th_nvl?($keys$$.push("ma_vt"),$sumfields$$=[{name:"ps_tk_nt",value:"tien_xuat_nt"},
9
- {name:"ps_tk",value:"tien_xuat"}]):$sumfields$$=[{name:"ps_tk_nt",value:"tien_nt"},{name:"ps_tk",value:"tien"}];$rows$$.groupBy($keys$$,$sumfields$$,($e$$,$rs$$)=>{if($e$$)return $callback$$($e$$);$rs$$.forEach($r$$=>{$r$$.ma_yt=$yt$$.ma_yt});$data$$=$data$$.concat($rs$$);$callback$$(null,$rs$$)})}).catch($e$$=>{$callback$$($e$$)})})}},function($e$$,$rs$$){$callback$$($e$$,$rs$$)})},$e$$=>{if($e$$)return $fn$$($e$$);$data$$.groupBy(["ma_yt","ma_sp","ma_bp","id_lenhsx","ma_nvl"],["dd_dk_nt","dd_dk",
10
- "ps_tk_nt","ps_tk"],($e$$,$rs$$)=>{if($e$$)return $fn$$($e$$);for(let $r$$ of $rs$$)$r$$.nam=$condition$$.nam,$r$$.thang=$condition$$.thang,$r$$.id_app=$condition$$.id_app;gt_thcppstk.create($rs$$,$e$$=>{$fn$$($e$$,$rs$$)})})})}).catch($e$$=>{$fn$$($e$$)})};
3
+ {id_app:$condition$$.id_app,status:!0};$condition$$.ma_bp&&($query_yt_thang$$.ma_bp={$in:[$condition$$.ma_bp.toUpperCase(),null,void 0]});dmyt.find($query_yt_thang$$).lean().then($yts$$=>{let $data$$=[];async.mapSeries($yts$$,($yt$$,$callback$$)=>{async.series({dk:$callback$$=>{(new Promise(($resolve$$,$reject$$)=>{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&&
4
+ mongoose.Types.ObjectId.isValid($condition$$.id_lenhsx)&&($cond$$.id_lenhsx=$condition$$.id_lenhsx);ytdd_dk.find($cond$$).lean().then($rs$$=>{for(let $dd$$ of $rs$$)$dd$$.dd_dk_nt=$dd$$.tien_nt,$dd$$.dd_dk=$dd$$.tien,$data$$.push($dd$$);$resolve$$($rs$$)}).catch($e$$=>{$reject$$($e$$)})})).then($dddk$$=>{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&&
5
+ mongoose.Types.ObjectId.isValid($condition$$.id_lenhsx)&&($cond$$.id_lenhsx=$condition$$.id_lenhsx);$cond$$.thang===0&&($cond$$.thang=12,--$cond$$.nam);ytdd_ck.find($cond$$).lean().then($rs$$=>{for(let $ck$$ of $rs$$)_.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$$)})}).catch($e$$=>{$callback$$($e$$)})},
6
+ ps:$callback$$=>{let $cond$$={id_app:$condition$$.id_app,ngay_ct:{$gte:$tu_ngay$$,$lte:$den_ngay$$}};$condition$$.id_lenhsx&&mongoose.Types.ObjectId.isValid($condition$$.id_lenhsx)&&($cond$$.id_lenhsx=$condition$$.id_lenhsx);let $md$$;$yt$$.ma_bp_cp&&($cond$$.ma_bp=$yt$$.ma_bp_cp);$yt$$.ma_dt_cp&&($cond$$.ma_dt=$yt$$.ma_dt_cp);$yt$$.ma_phi_cp&&($cond$$.ma_phi=$yt$$.ma_phi_cp);$yt$$.ma_kho_cp&&($cond$$.ma_kho=$yt$$.ma_kho_cp);$yt$$.ma_vt_cp&&($cond$$.ma_vt=$yt$$.ma_vt_cp);$yt$$.th_nvl?($md$$=sokho,
7
+ _.isArray($yt$$.tk_no)&&$yt$$.tk_no.length>0&&($cond$$.tk_du={$regex:$yt$$.tk_no.reg(),$options:"i"}),_.isArray($yt$$.tk_co)&&$yt$$.tk_co.length>0&&($cond$$.tk_vt={$regex:$yt$$.tk_co.reg(),$options:"i"})):($md$$=socai,_.isArray($yt$$.tk_no)&&$yt$$.tk_no.length>0&&($cond$$.tk_no={$regex:$yt$$.tk_no.reg(),$options:"i"}),_.isArray($yt$$.tk_co)&&$yt$$.tk_co.length>0&&($cond$$.tk_co={$regex:$yt$$.tk_co.reg(),$options:"i"}));$md$$.find($cond$$).lean().then($rows$$=>{let $keys$$=[],$sumfields$$;$yt$$.ma_bp&&
8
+ $rows$$.forEach($r$$=>{$r$$.ma_bp=$yt$$.ma_bp});$yt$$.th_bp&&($rows$$=$rows$$.filter($r$$=>$r$$.ma_bp),$condition$$.ma_bp&&($rows$$=$rows$$.filter($r$$=>$r$$.ma_bp==$condition$$.ma_bp.toUpperCase())),$keys$$.push("ma_bp"));$yt$$.th_lsx&&($rows$$=$rows$$.filter($r$$=>$r$$.id_lenhsx),$keys$$.push("id_lenhsx"));$yt$$.th_sp&&($rows$$=$rows$$.filter($r$$=>$r$$.ma_sp),$keys$$.push("ma_sp"));$yt$$.th_nvl?($keys$$.push("ma_vt"),$sumfields$$=[{name:"ps_tk_nt",value:"tien_xuat_nt"},{name:"ps_tk",value:"tien_xuat"}]):
9
+ $sumfields$$=[{name:"ps_tk_nt",value:"tien_nt"},{name:"ps_tk",value:"tien"}];$rows$$.groupBy($keys$$,$sumfields$$,($e$$,$rs$$)=>{if($e$$)return $callback$$($e$$);$rs$$.forEach($r$$=>{$r$$.ma_yt=$yt$$.ma_yt});$data$$=$data$$.concat($rs$$);$callback$$(null,$rs$$)})}).catch($e$$=>{$callback$$($e$$)})}},function($e$$,$rs$$){$callback$$($e$$,$rs$$)})},$e$$=>{if($e$$)return $fn$$($e$$);$data$$.groupBy(["ma_yt","ma_sp","ma_bp","id_lenhsx","ma_nvl"],["dd_dk_nt","dd_dk","ps_tk_nt","ps_tk"],($e$$,$rs$$)=>{if($e$$)return $fn$$($e$$);
10
+ for(let $r$$ of $rs$$)$r$$.nam=$condition$$.nam,$r$$.thang=$condition$$.thang,$r$$.id_app=$condition$$.id_app;gt_thcppstk.create($rs$$,$e$$=>{$fn$$($e$$,$rs$$)})})})}).catch($e$$=>{$fn$$($e$$)})};
@@ -1,7 +1,8 @@
1
1
  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().then($yts$$=>{async.map($yts$$,($yt$$,$callback$$)=>{async.parallel({gt:$callback$$=>{setImmediate(()=>{let $cond$$={id_app:$condition$$.id_app,
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().then($yts$$=>{async.mapSeries($yts$$,($yt$$,$callback$$)=>{async.series({gt:$callback$$=>{let $cond$$={id_app:$condition$$.id_app,
3
3
  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$$).inTxn().lean().then($pstk$$=>{$pstk$$=$pstk$$.filter($p$$=>$p$$.ma_sp);$pstk$$.groupBy(["ma_sp","ma_bp","ma_yt","id_lenhsx"],["dd_dk","dd_dk_nt","ps_tk","ps_tk_nt"],($e$$,$rs$$)=>{if($e$$)return $callback$$($e$$);$rs$$.forEach($p$$=>
4
- {$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$$)})}).catch($e$$=>{$callback$$($e$$)})})}},function($e$$,$rs$$){$callback$$($e$$,$rs$$.gt)})},($e$$,$ps$$)=>{if($e$$)return $fn$$($e$$);setImmediate(()=>{let $data_pstk$$=$ps$$.reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]),$cond$$={id_app:$condition$$.id_app,nam:$condition$$.nam,thang:$condition$$.thang};$condition$$.ma_bp&&
5
- ($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$$).inTxn().lean().then($sltk$$=>{$data_pstk$$.joinModel2($sltk$$,{where:{ma_sp:"ma_sp",ma_bp:"ma_bp",id_lenhsx:"id_lenhsx"},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=
6
- 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/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=
7
- $s$$.sl_nk_tk===0?0:$s$$.t_cp_sx/$s$$.sl_sp_ht_qd,$s$$.gt_nt=$s$$.sl_nk_tk===0?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$$&&(console.error($e$$),console.error($data_pstk$$));$fn$$($e$$,$rs$$)})})}).catch($e$$=>{$fn$$($e$$)})})})}).catch($e$$=>{$fn$$($e$$)})};
4
+ {$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$$)})}).catch($e$$=>{$callback$$($e$$)})}},function($e$$,$rs$$){$callback$$($e$$,$rs$$.gt)})},($cond$jscomp$1_e$$,$ps$$)=>{if($cond$jscomp$1_e$$)return $fn$$($cond$jscomp$1_e$$);let $data_pstk$$=$ps$$.reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]);$cond$jscomp$1_e$$={id_app:$condition$$.id_app,nam:$condition$$.nam,
5
+ 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$$).inTxn().lean().then($sltk$$=>{$data_pstk$$.joinModel2($sltk$$,{where:{ma_sp:"ma_sp",ma_bp:"ma_bp",id_lenhsx:"id_lenhsx"},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||
6
+ ($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/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=
7
+ $s$$.dd_dk+$s$$.ps_tk,$s$$.t_cp_sx_nt=$s$$.dd_dk_nt+$s$$.ps_tk_nt,$s$$.gt=$s$$.sl_nk_tk===0?0:$s$$.t_cp_sx/$s$$.sl_sp_ht_qd,$s$$.gt_nt=$s$$.sl_nk_tk===0?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$$&&(console.error($e$$),console.error($data_pstk$$));$fn$$($e$$,$rs$$)})})}).catch($e$$=>{$fn$$($e$$)})})}).catch($e$$=>
8
+ {$fn$$($e$$)})};
@@ -1,3 +1,3 @@
1
1
  var gt_thcppstk=global.getModel("gt_thcppstk"),gt_ctgt=global.getModel("gt_ctgt"),gt_sltk=global.getModel("gt_sltk");const async=require("async");
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");let $cond$$={id_app:$condition$$.id_app,nam:Number($condition$$.nam),thang:Number($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=
3
- $condition$$.id_lenhsx);async.parallel({sl:$callback$$=>{gt_sltk.deleteMany($cond$$,$e$$=>{$callback$$($e$$)})},cp:$callback$$=>{gt_thcppstk.deleteMany($cond$$,$e$$=>{$callback$$($e$$)})},gt:$callback$$=>{gt_ctgt.deleteMany($cond$$,$e$$=>{$callback$$($e$$)})}},($e$$,$rs$$)=>{$fn$$($e$$,$rs$$)})};
3
+ $condition$$.id_lenhsx);async.series({sl:$callback$$=>{gt_sltk.deleteMany($cond$$,$e$$=>{$callback$$($e$$)})},cp:$callback$$=>{gt_thcppstk.deleteMany($cond$$,$e$$=>{$callback$$($e$$)})},gt:$callback$$=>{gt_ctgt.deleteMany($cond$$,$e$$=>{$callback$$($e$$)})}},($e$$,$rs$$)=>{$fn$$($e$$,$rs$$)})};