flexbiz-server 12.6.13 → 12.6.16

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 (129) hide show
  1. package/README.md +439 -4
  2. package/package.json +4 -3
  3. package/server/agents/agents.js +1 -0
  4. package/server/agents/ai_memory_manager.js +6 -0
  5. package/server/agents/ceoAgent.js +43 -0
  6. package/server/agents/chatController.js +6 -0
  7. package/server/agents/cskhAgent.js +43 -0
  8. package/server/agents/flowAgent.js +43 -0
  9. package/server/agents/prompts/ceo.js +2 -0
  10. package/server/agents/prompts/flow.js +2 -0
  11. package/server/agents/staffAgent.js +44 -0
  12. package/server/agents/tools/financeTools.js +57 -0
  13. package/server/agents/tools/flowTools.js +36 -0
  14. package/server/agents/tools/kpiTools.js +104 -0
  15. package/server/agents/tools/masterDataTools.js +74 -0
  16. package/server/agents/tools/okrTools.js +21 -0
  17. package/server/agents/tools/ragTools.js +21 -0
  18. package/server/agents/tools/reportTools.js +43 -0
  19. package/server/agents/tools/staffTools.js +13 -0
  20. package/server/agents/tools/stockTools.js +41 -0
  21. package/server/agents/tools/systemTools.js +52 -0
  22. package/server/agents/tools/taskTools.js +23 -0
  23. package/server/agents/tools/utils.js +57 -0
  24. package/server/app.js +7 -7
  25. package/server/controllers/controller.js +31 -29
  26. package/server/controllers/controllerRPT.js +31 -29
  27. package/server/controllers/findHandler.js +22 -21
  28. package/server/controllers/importFromExcelHandler.js +17 -14
  29. package/server/controllers/importHandler.js +26 -41
  30. package/server/controllers/importHandler_old.js +41 -0
  31. package/server/controllers/rptHandler.js +14 -11
  32. package/server/controllers/viewHandler.js +7 -7
  33. package/server/flow/FlowEngine.js +49 -45
  34. package/server/flow/WebhookManager.js +1 -1
  35. package/server/flow/handlers.js +2 -2
  36. package/server/flow/nodes/userform.js +28 -0
  37. package/server/flow/utils.js +12 -4
  38. package/server/global.js +4 -3
  39. package/server/libs/cdpstk.js +1 -1
  40. package/server/libs/ckvt.js +12 -11
  41. package/server/libs/ckvtcapphat.js +5 -5
  42. package/server/libs/ckvtnpp.js +8 -8
  43. package/server/libs/ckvttt.js +6 -5
  44. package/server/libs/ctvt.js +7 -6
  45. package/server/libs/ctvtnpp.js +7 -6
  46. package/server/libs/ctvttt.js +6 -6
  47. package/server/libs/databanle.js +17 -18
  48. package/server/libs/databanle_old.js +18 -0
  49. package/server/libs/databanletheongay.js +25 -29
  50. package/server/libs/dktk.js +3 -3
  51. package/server/libs/dkvt.js +11 -11
  52. package/server/libs/dkvtnpp.js +7 -6
  53. package/server/libs/dkvttt.js +7 -6
  54. package/server/libs/docs.js +72 -36
  55. package/server/libs/dtbanletheosp.js +16 -19
  56. package/server/libs/fifo_dk.js +8 -0
  57. package/server/libs/fifo_group.js +4 -0
  58. package/server/libs/fifo_trace_query.js +12 -0
  59. package/server/libs/getGiaban.js +59 -70
  60. package/server/libs/getGiaban_old.js +70 -0
  61. package/server/libs/joinData.js +3 -3
  62. package/server/libs/joinData_bk.js +44 -0
  63. package/server/libs/kpistatus.js +24 -17
  64. package/server/libs/permission.js +54 -56
  65. package/server/libs/permission_old.js +58 -0
  66. package/server/libs/post-book.js +1 -1
  67. package/server/libs/post-socai.js +2 -1
  68. package/server/libs/post-sokho.js +11 -11
  69. package/server/libs/prototypes.js +13 -12
  70. package/server/libs/queryBuilding.js +11 -10
  71. package/server/libs/redis-cache.js +22 -10
  72. package/server/libs/sctcnkh.js +19 -17
  73. package/server/libs/socaitk.js +1 -1
  74. package/server/libs/thnxt.js +17 -14
  75. package/server/libs/thnxtnpp.js +8 -8
  76. package/server/libs/thnxttt.js +8 -7
  77. package/server/libs/tinhgia1vt_fifo.js +22 -0
  78. package/server/libs/tinhgiafifo.js +28 -0
  79. package/server/libs/utils.js +37 -19
  80. package/server/models/app.js +1 -1
  81. package/server/models/approve.js +8 -8
  82. package/server/models/cacheDataReport.js +2 -2
  83. package/server/models/cacheSessionReport.js +5 -1
  84. package/server/models/cdvt.js +2 -2
  85. package/server/models/checkin.js +2 -2
  86. package/server/models/chitietluongds.js +1 -1
  87. package/server/models/contract.js +1 -1
  88. package/server/models/csluongtheods.js +2 -2
  89. package/server/models/ctds2.js +7 -6
  90. package/server/models/custom_report.js +1 -0
  91. package/server/models/dmdt.js +2 -2
  92. package/server/models/dmkho.js +5 -4
  93. package/server/models/dmnvt.js +5 -4
  94. package/server/models/fifo_dk.js +2 -0
  95. package/server/models/fifo_lot.js +3 -0
  96. package/server/models/fifo_trace.js +4 -0
  97. package/server/models/flowpending.js +2 -0
  98. package/server/models/group.js +3 -5
  99. package/server/models/listinfo.js +61 -33
  100. package/server/models/schedule.js +4 -3
  101. package/server/models/task.js +1 -1
  102. package/server/models/trangthai.js +2 -2
  103. package/server/modules/lists/bg-fifo_dk.js +8 -0
  104. package/server/modules/lists/ls-checkin.js +1 -1
  105. package/server/modules/lists/ls-customer.js +23 -26
  106. package/server/modules/lists/ls-dmbp.js +5 -5
  107. package/server/modules/lists/ls-dmkho.js +7 -1
  108. package/server/modules/lists/ls-dmnhtask.js +1 -1
  109. package/server/modules/lists/ls-dmvt.js +52 -70
  110. package/server/modules/lists/ls-flowpending.js +3 -0
  111. package/server/modules/lists/ls-participant.js +6 -4
  112. package/server/modules/lists/ls-task.js +6 -6
  113. package/server/modules/reports/calc-tinhgiafifo.js +8 -0
  114. package/server/modules/reports/calc-tinhluong.js +17 -16
  115. package/server/modules/reports/rp-baoCaoFifoKy.js +1 -0
  116. package/server/modules/reports/rp-congviectheobp.js +4 -4
  117. package/server/modules/reports/rp-congviectheodt.js +1 -1
  118. package/server/modules/reports/rp-congviectheokh.js +1 -1
  119. package/server/modules/reports/rp-congviectheonv.js +1 -1
  120. package/server/modules/reports/rp-dtbanletheoct.js +22 -23
  121. package/server/modules/reports/rp-dtbanletheokh.js +17 -20
  122. package/server/modules/reports/rp-dtbanletheokho.js +15 -18
  123. package/server/modules/reports/rp-hoahong.js +1 -1
  124. package/server/modules/reports/rp-sctvt.js +1 -1
  125. package/server/modules/reports/rp-sosanhkhvatt2.js +1 -1
  126. package/server/modules/reports/rp-thnxt.js +8 -8
  127. package/server/modules/reports/rp-tongquannvbh.js +1 -1
  128. package/server/modules/systems/sys-app.js +5 -5
  129. package/server/modules/vouchers/vo-so1.js +14 -14
@@ -1,9 +1,10 @@
1
1
  const cdvt=global.getModel("cdvt"),dmvt=global.getModel("dmvt"),sokho=global.getModel("sokhott"),ckvtcapphat=require("./ckvtcapphat"),hanmucton=global.getModel("hanmucton"),utils=require("./utils"),async=require("async"),underscore=require("underscore"),moment=require("moment");
2
- module.exports=async($condition$$,$callback$$)=>{!$condition$$.ngay&&$condition$$.den_ngay&&($condition$$.ngay=$condition$$.den_ngay);let $ma_dvcs$$=$condition$$.ma_dvcs,$ma_kho$$=$condition$$.ma_kho,$ma_vt$$=$condition$$.ma_vt;$ma_vt$$&&underscore.isArray($ma_vt$$)&&($ma_vt$$={$in:Object.assign($ma_vt$$)});let $ngay$$,$nam$$,$ngay_dn$$;$ngay$$=moment($condition$$.ngay).endOf("date").toDate();if($condition$$.tu_ngay){let $tu_ngay$$=new Date($condition$$.tu_ngay);$nam$$=$tu_ngay$$.getFullYear();$ngay_dn$$=
3
- moment($tu_ngay$$).startOf("year").toDate()}else $nam$$=$ngay$$.getFullYear(),$ngay_dn$$=moment($ngay$$).startOf("year").toDate();let $id_app$$=$condition$$.id_app;try{let $result$$=await new Promise(($resolve$$,$reject$$)=>{async.series({ckcapphat:$callback$$=>{setImmediate(()=>{ckvtcapphat($condition$$,($e$$,$rs$$)=>{$callback$$($e$$,$rs$$)})})},dn:$callback$$=>{setImmediate(()=>{const $c_dk$$={id_app:$id_app$$,nam:$nam$$};$ma_kho$$&&($c_dk$$.ma_kho=$ma_kho$$);$ma_dvcs$$&&($c_dk$$.ma_dvcs=$ma_dvcs$$);
4
- $ma_vt$$&&($c_dk$$.ma_vt=$ma_vt$$);$condition$$.ma_lo&&($c_dk$$.ma_lo=$condition$$.ma_lo);$condition$$.han_sd&&($c_dk$$.han_sd=$condition$$.han_sd);$condition$$.ma_tt1&&($c_dk$$.ma_tt1=$condition$$.ma_tt1);$condition$$.ma_tt2&&($c_dk$$.ma_tt2=$condition$$.ma_tt2);$condition$$.ma_tt3&&($c_dk$$.ma_tt3=$condition$$.ma_tt3);cdvt.find($c_dk$$).lean().then($results$$=>{$callback$$(null,$results$$)}).catch($error$$=>{$callback$$($error$$)})})},hanmucton:$callback$$=>{setImmediate(()=>{const $c_dk$$={id_app:$id_app$$};
5
- $ma_kho$$&&($c_dk$$.ma_kho=$ma_kho$$);$ma_dvcs$$&&($c_dk$$.ma_dvcs=$ma_dvcs$$);$ma_vt$$&&($c_dk$$.ma_vt=$ma_vt$$);$condition$$.ma_lo&&($c_dk$$.ma_lo=$condition$$.ma_lo);$condition$$.han_sd&&($c_dk$$.han_sd=$condition$$.han_sd);$condition$$.ma_tt1&&($c_dk$$.ma_tt1=$condition$$.ma_tt1);$condition$$.ma_tt2&&($c_dk$$.ma_tt2=$condition$$.ma_tt2);$condition$$.ma_tt3&&($c_dk$$.ma_tt3=$condition$$.ma_tt3);hanmucton.find($c_dk$$).lean().then($results$$=>{$callback$$(null,$results$$)}).catch($error$$=>{$callback$$($error$$)})})},
6
- ps:$callback$$=>{setImmediate(()=>{const $query$$={id_app:$id_app$$,ngay_ct:{$gte:$ngay_dn$$,$lte:$ngay$$}};$ma_kho$$&&($query$$.ma_kho=$ma_kho$$);$ma_dvcs$$&&($query$$.ma_dvcs=$ma_dvcs$$);$ma_vt$$&&($query$$.ma_vt=$ma_vt$$);$condition$$.ma_lo&&($query$$.ma_lo=$condition$$.ma_lo);$condition$$.han_sd&&($query$$.han_sd=$condition$$.han_sd);$condition$$.ma_tt1&&($query$$.ma_tt1=$condition$$.ma_tt1);$condition$$.ma_tt2&&($query$$.ma_tt2=$condition$$.ma_tt2);$condition$$.ma_tt3&&($query$$.ma_tt3=$condition$$.ma_tt3);
2
+ module.exports=async($condition$$,$callback$$)=>{!$condition$$.ngay&&$condition$$.den_ngay&&($condition$$.ngay=$condition$$.den_ngay);let $ma_dvcs$$=$condition$$.ma_dvcs,$id_app$$=$condition$$.id_app;var $ma_kho_tu_ngay$$=$condition$$.ma_kho;let $ds_ma_kho$$;$ma_kho_tu_ngay$$&&(Array.isArray($ma_kho_tu_ngay$$)?$ds_ma_kho$$=[...$ma_kho_tu_ngay$$]:typeof $ma_kho_tu_ngay$$=="string"&&($ds_ma_kho$$=await global.getModel("dmkho").getAllChildrenGroup($id_app$$,$ma_kho_tu_ngay$$)));let $ma_vt$$=$condition$$.ma_vt;
3
+ $ma_vt$$&&underscore.isArray($ma_vt$$)&&($ma_vt$$={$in:Object.assign($ma_vt$$)});let $ngay$$,$nam$$,$ngay_dn$$;$ngay$$=moment($condition$$.ngay).endOf("date").toDate();$condition$$.tu_ngay?($ma_kho_tu_ngay$$=new Date($condition$$.tu_ngay),$nam$$=$ma_kho_tu_ngay$$.getFullYear(),$ngay_dn$$=moment($ma_kho_tu_ngay$$).startOf("year").toDate()):($nam$$=$ngay$$.getFullYear(),$ngay_dn$$=moment($ngay$$).startOf("year").toDate());try{let $result$$=await new Promise(($resolve$$,$reject$$)=>{async.series({ckcapphat:$callback$$=>
4
+ {setImmediate(()=>{ckvtcapphat({...$condition$$,ma_kho:$ds_ma_kho$$},($e$$,$rs$$)=>{$callback$$($e$$,$rs$$)})})},dn:$callback$$=>{setImmediate(()=>{const $c_dk$$={id_app:$id_app$$,nam:$nam$$};$ds_ma_kho$$?$c_dk$$.ma_kho={$in:$ds_ma_kho$$}:$condition$$.ma_kho&&($c_dk$$.ma_kho=$condition$$.ma_kho);$ma_dvcs$$&&($c_dk$$.ma_dvcs=$ma_dvcs$$);$ma_vt$$&&($c_dk$$.ma_vt=$ma_vt$$);$condition$$.ma_lo&&($c_dk$$.ma_lo=$condition$$.ma_lo);$condition$$.han_sd&&($c_dk$$.han_sd=$condition$$.han_sd);$condition$$.ma_tt1&&
5
+ ($c_dk$$.ma_tt1=$condition$$.ma_tt1);$condition$$.ma_tt2&&($c_dk$$.ma_tt2=$condition$$.ma_tt2);$condition$$.ma_tt3&&($c_dk$$.ma_tt3=$condition$$.ma_tt3);cdvt.find($c_dk$$).lean().then($results$$=>{$callback$$(null,$results$$)}).catch($error$$=>{$callback$$($error$$)})})},hanmucton:$callback$$=>{setImmediate(()=>{const $c_dk$$={id_app:$id_app$$};$ds_ma_kho$$?$c_dk$$.ma_kho={$in:$ds_ma_kho$$}:$condition$$.ma_kho&&($c_dk$$.ma_kho=$condition$$.ma_kho);$ma_dvcs$$&&($c_dk$$.ma_dvcs=$ma_dvcs$$);$ma_vt$$&&
6
+ ($c_dk$$.ma_vt=$ma_vt$$);$condition$$.ma_lo&&($c_dk$$.ma_lo=$condition$$.ma_lo);$condition$$.han_sd&&($c_dk$$.han_sd=$condition$$.han_sd);$condition$$.ma_tt1&&($c_dk$$.ma_tt1=$condition$$.ma_tt1);$condition$$.ma_tt2&&($c_dk$$.ma_tt2=$condition$$.ma_tt2);$condition$$.ma_tt3&&($c_dk$$.ma_tt3=$condition$$.ma_tt3);hanmucton.find($c_dk$$).lean().then($results$$=>{$callback$$(null,$results$$)}).catch($error$$=>{$callback$$($error$$)})})},ps:$callback$$=>{setImmediate(()=>{const $query$$={id_app:$id_app$$,
7
+ ngay_ct:{$gte:$ngay_dn$$,$lte:$ngay$$}};$ds_ma_kho$$?$query$$.ma_kho={$in:$ds_ma_kho$$}:$condition$$.ma_kho&&($query$$.ma_kho=$condition$$.ma_kho);$ma_dvcs$$&&($query$$.ma_dvcs=$ma_dvcs$$);$ma_vt$$&&($query$$.ma_vt=$ma_vt$$);$condition$$.ma_lo&&($query$$.ma_lo=$condition$$.ma_lo);$condition$$.han_sd&&($query$$.han_sd=$condition$$.han_sd);$condition$$.ma_tt1&&($query$$.ma_tt1=$condition$$.ma_tt1);$condition$$.ma_tt2&&($query$$.ma_tt2=$condition$$.ma_tt2);$condition$$.ma_tt3&&($query$$.ma_tt3=$condition$$.ma_tt3);
7
8
  $condition$$.id_ct&&($query$$.id_ct={$ne:$condition$$.id_ct});sokho.find($query$$).inTxn().lean().then($pss$$=>{$pss$$=$pss$$.map($ps$$=>{$ps$$.sl_nhap=utils.round($ps$$.sl_nhap_qd,4);$ps$$.sl_xuat=utils.round($ps$$.sl_xuat_qd,4);return $ps$$});$callback$$(null,$pss$$)}).catch($error$$=>{$callback$$($error$$)})})},ton_kho_mac_dinh:$callback$$=>{setImmediate(()=>{let $query$$={id_app:$id_app$$,ton_kho_mac_dinh:{$nin:[null,void 0,0]}};$ma_vt$$&&($query$$.ma_vt=$ma_vt$$);dmvt.find($query$$,{ma_vt:1,
8
9
  ton_kho_mac_dinh:1}).lean().then($rs$$=>{$callback$$(null,$rs$$)}).catch($e$$=>{Logger.error($e$$)})})}},($ckcapphat_error$$,$data_results$$)=>{if($ckcapphat_error$$)return $reject$$(Error($ckcapphat_error$$));$ckcapphat_error$$=$data_results$$.ckcapphat.map($c$$=>{$c$$.ton00_capphat=$c$$.ton00;$c$$.du00_capphat=$c$$.du00;$c$$.ton00=0;$c$$.du00=0;return $c$$});$data_results$$=$data_results$$.dn.concat($data_results$$.ps).concat($ckcapphat_error$$).concat($data_results$$.ton_kho_mac_dinh).concat($data_results$$.hanmucton);
9
10
  ($ckcapphat_error$$=$condition$$.groupBy||$condition$$.groupby)||($ckcapphat_error$$=["ma_vt"]);if(underscore.isString($ckcapphat_error$$))if($ckcapphat_error$$.indexOf("[")>=0)try{$ckcapphat_error$$=JSON.parse($ckcapphat_error$$)}catch($e$$){Logger.error($e$$)}else $ckcapphat_error$$=$ckcapphat_error$$.split(",");$data_results$$.groupBy($ckcapphat_error$$,"sl_nhap sl_xuat ton00 du00 ton00_capphat du00_capphat tien_nhap tien_xuat ton_kho_mac_dinh ton_toi_thieu ton_toi_da".split(" "),($e$$,$groups$$)=>
@@ -1,7 +1,8 @@
1
1
  const dkvt=require("./dkvt"),sokho=global.getModel("sokho"),async=require("async");
2
- module.exports=async function($condition$$,$callback$$){try{if(!($condition$$&&$condition$$.tu_ngay&&$condition$$.ma_vt&&$condition$$.den_ngay&&$condition$$.id_app))throw"L\u1ed7i: B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: tu_ngay,den_ngay,ma_vt,id_app";let $ma_dvcs$$=$condition$$.ma_dvcs,$ma_kho$$=$condition$$.ma_kho,$ma_vt$$=$condition$$.ma_vt,$tu_ngay$$=$condition$$.tu_ngay,$den_ngay$$=$condition$$.den_ngay,$id_app$$=$condition$$.id_app;const $data$$=await new Promise(($resolve$$,
3
- $reject$$)=>{async.parallel({dn:function($callback$$){dkvt($condition$$,function($error$$,$result$$){if($error$$)return $callback$$($error$$);$callback$$(null,$result$$)})},ps:function($callback$$){let $query$$={id_app:$id_app$$,ngay_ct:{$gte:$tu_ngay$$,$lte:$den_ngay$$},ma_vt:$ma_vt$$};$ma_kho$$&&($query$$.ma_kho=$ma_kho$$);$ma_dvcs$$&&($query$$.ma_dvcs=$ma_dvcs$$);$condition$$.ma_lo&&($query$$.ma_lo=$condition$$.ma_lo);$condition$$.han_sd&&($query$$.han_sd=$condition$$.han_sd);$condition$$.ma_tt1&&
4
- ($query$$.ma_tt1=$condition$$.ma_tt1);$condition$$.ma_tt2&&($query$$.ma_tt2=$condition$$.ma_tt2);$condition$$.ma_tt3&&($query$$.ma_tt3=$condition$$.ma_tt3);$condition$$.ma_kh&&($query$$.ma_kh=$condition$$.ma_kh);sokho.find($query$$).lean().then(function($pss$$){$pss$$=$pss$$.map($ps$$=>{$ps$$.sl_nhap=$ps$$.sl_nhap_qd;$ps$$.sl_xuat=$ps$$.sl_xuat_qd;return $ps$$});$callback$$(null,$pss$$)}).catch($error$$=>{$callback$$($error$$)})}},function($error$$,$results$$){if($error$$)return $reject$$($error$$);
5
- let $data$$=[];$results$$.ps.forEach(function($r$$){$r$$.sysorder=5;$r$$.bold=!1;$data$$.push($r$$)});async.parallel({ton_dau:function($callback$$){let $ton_dau$$=$results$$.dn.csum("ton00");$callback$$(null,$ton_dau$$)},du_dau:function($callback$$){let $du_dau$$=$results$$.dn.csum("du00");$callback$$(null,$du_dau$$)},sl_nhap:function($callback$$){let $sl_nhap$$=$results$$.ps.csum("sl_nhap");$callback$$(null,$sl_nhap$$)},tien_nhap:function($callback$$){let $tien_nhap$$=$results$$.ps.csum("tien_nhap");
6
- $callback$$(null,$tien_nhap$$)},sl_xuat:function($callback$$){let $sl_xuat$$=$results$$.ps.csum("sl_xuat");$callback$$(null,$sl_xuat$$)},tien_xuat:function($callback$$){let $tien_xuat$$=$results$$.ps.csum("tien_xuat");$callback$$(null,$tien_xuat$$)}},function($error$$,$results$$){$data$$.push({sysorder:1,bold:!0,dien_giai:"T\u1ed3n \u0111\u1ea7u k\u1ef3",sl_nhap:$results$$.ton_dau,tien_nhap:$results$$.du_dau,sl_xuat:0,tien_xuat:0});$data$$.push({sysorder:6,bold:!0,dien_giai:"C\u1ed9ng ph\u00e1t sinh trong k\u1ef3",
7
- sl_nhap:$results$$.sl_nhap,tien_nhap:$results$$.tien_nhap,sl_xuat:$results$$.sl_xuat,tien_xuat:$results$$.tien_xuat});$data$$.push({sysorder:9,bold:!0,dien_giai:"T\u1ed3n cu\u1ed1i k\u1ef3",sl_nhap:$results$$.ton_dau+$results$$.sl_nhap-$results$$.sl_xuat,tien_nhap:$results$$.du_dau+$results$$.tien_nhap-$results$$.tien_xuat});$resolve$$($data$$)})})});return $callback$$?$callback$$(null,$data$$):$data$$}catch($e$$){if($callback$$)return $callback$$($e$$);throw $e$$;}};
2
+ module.exports=async function($condition$$,$callback$$){try{if(!($condition$$&&$condition$$.tu_ngay&&$condition$$.ma_vt&&$condition$$.den_ngay&&$condition$$.id_app))throw"L\u1ed7i: B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: tu_ngay,den_ngay,ma_vt,id_app";let $id_app$$=$condition$$.id_app,$ma_dvcs$$=$condition$$.ma_dvcs,$ma_kho$$=$condition$$.ma_kho,$ds_ma_kho$$;$ma_kho$$&&(Array.isArray($ma_kho$$)?$ds_ma_kho$$=[...$ma_kho$$]:typeof $ma_kho$$=="string"&&($ds_ma_kho$$=await global.getModel("dmkho").getAllChildrenGroup($id_app$$,
3
+ $ma_kho$$)));let $ma_vt$$=$condition$$.ma_vt,$tu_ngay$$=$condition$$.tu_ngay,$den_ngay$$=$condition$$.den_ngay;const $data$$=await new Promise(($resolve$$,$reject$$)=>{async.parallel({dn:function($callback$$){dkvt({...$condition$$,ma_kho:$ds_ma_kho$$},function($error$$,$result$$){if($error$$)return $callback$$($error$$);$callback$$(null,$result$$)})},ps:function($callback$$){let $query$$={id_app:$id_app$$,ngay_ct:{$gte:$tu_ngay$$,$lte:$den_ngay$$},ma_vt:$ma_vt$$};$ds_ma_kho$$?$query$$.ma_kho={$in:$ds_ma_kho$$}:
4
+ $condition$$.ma_kho&&($query$$.ma_kho=$condition$$.ma_kho);$ma_dvcs$$&&($query$$.ma_dvcs=$ma_dvcs$$);$condition$$.ma_lo&&($query$$.ma_lo=$condition$$.ma_lo);$condition$$.han_sd&&($query$$.han_sd=$condition$$.han_sd);$condition$$.ma_tt1&&($query$$.ma_tt1=$condition$$.ma_tt1);$condition$$.ma_tt2&&($query$$.ma_tt2=$condition$$.ma_tt2);$condition$$.ma_tt3&&($query$$.ma_tt3=$condition$$.ma_tt3);$condition$$.ma_kh&&($query$$.ma_kh=$condition$$.ma_kh);sokho.find($query$$).sort({ngay_ct_full:1}).lean().then(function($pss$$){$pss$$=
5
+ $pss$$.map($ps$$=>{$ps$$.sl_nhap=$ps$$.sl_nhap_qd;$ps$$.sl_xuat=$ps$$.sl_xuat_qd;return $ps$$});$callback$$(null,$pss$$)}).catch($error$$=>{$callback$$($error$$)})}},function($error$$,$results$$){if($error$$)return $reject$$($error$$);let $data$$=[];$results$$.ps.forEach(function($r$$){$r$$.sysorder=5;$r$$.bold=!1;$data$$.push($r$$)});async.parallel({ton_dau:function($callback$$){let $ton_dau$$=$results$$.dn.csum("ton00");$callback$$(null,$ton_dau$$)},du_dau:function($callback$$){let $du_dau$$=$results$$.dn.csum("du00");
6
+ $callback$$(null,$du_dau$$)},sl_nhap:function($callback$$){let $sl_nhap$$=$results$$.ps.csum("sl_nhap");$callback$$(null,$sl_nhap$$)},tien_nhap:function($callback$$){let $tien_nhap$$=$results$$.ps.csum("tien_nhap");$callback$$(null,$tien_nhap$$)},sl_xuat:function($callback$$){let $sl_xuat$$=$results$$.ps.csum("sl_xuat");$callback$$(null,$sl_xuat$$)},tien_xuat:function($callback$$){let $tien_xuat$$=$results$$.ps.csum("tien_xuat");$callback$$(null,$tien_xuat$$)}},function($error$$,$results$$){$data$$.push({sysorder:1,
7
+ bold:!0,dien_giai:"T\u1ed3n \u0111\u1ea7u k\u1ef3",sl_nhap:$results$$.ton_dau,tien_nhap:$results$$.du_dau,sl_xuat:0,tien_xuat:0});$data$$.push({sysorder:6,bold:!0,dien_giai:"C\u1ed9ng ph\u00e1t sinh trong k\u1ef3",sl_nhap:$results$$.sl_nhap,tien_nhap:$results$$.tien_nhap,sl_xuat:$results$$.sl_xuat,tien_xuat:$results$$.tien_xuat});$data$$.push({sysorder:9,bold:!0,dien_giai:"T\u1ed3n cu\u1ed1i k\u1ef3",sl_nhap:$results$$.ton_dau+$results$$.sl_nhap-$results$$.sl_xuat,tien_nhap:$results$$.du_dau+$results$$.tien_nhap-
8
+ $results$$.tien_xuat});$resolve$$($data$$)})})});return $callback$$?$callback$$(null,$data$$):$data$$}catch($e$$){if($callback$$)return $callback$$($e$$);throw $e$$;}};
@@ -1,7 +1,8 @@
1
1
  const dkvt=require("./dkvtnpp"),sokho=global.getModel("sokhonpp"),async=require("async");
2
- module.exports=function($condition$$,$fn$$){if(!($condition$$&&$condition$$.tu_ngay&&$condition$$.ma_vt&&$condition$$.den_ngay&&$condition$$.id_app))return $fn$$("L\u1ed7i: B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: tu_ngay,den_ngay,ma_vt,id_app");let $ma_dvcs$$=$condition$$.ma_dvcs,$ma_kho$$=$condition$$.ma_kho,$ma_vt$$=$condition$$.ma_vt,$tu_ngay$$=$condition$$.tu_ngay,$den_ngay$$=$condition$$.den_ngay,$id_app$$=$condition$$.id_app;async.series({dn:function($callback$$){setImmediate(()=>
3
- {dkvt($condition$$,function($error$$,$result$$){if($error$$)return $callback$$($error$$);$callback$$(null,$result$$)})})},ps:function($callback$$){setImmediate(()=>{let $query$$={id_app:$id_app$$,ngay_ct:{$gte:$tu_ngay$$,$lte:$den_ngay$$},ma_vt:$ma_vt$$};$ma_kho$$&&($query$$.ma_kho=$ma_kho$$);$ma_dvcs$$&&($query$$.ma_dvcs=$ma_dvcs$$);$condition$$.ma_lo&&($query$$.ma_lo=$condition$$.ma_lo);$condition$$.han_sd&&($query$$.han_sd=$condition$$.han_sd);$condition$$.ma_tt1&&($query$$.ma_tt1=$condition$$.ma_tt1);
4
- $condition$$.ma_tt2&&($query$$.ma_tt2=$condition$$.ma_tt2);$condition$$.ma_tt3&&($query$$.ma_tt3=$condition$$.ma_tt3);$condition$$.ma_kh&&($query$$.ma_kh=$condition$$.ma_kh);sokho.find($query$$).lean().then(function($pss$$){$pss$$=$pss$$.map($ps$$=>{$ps$$.sl_nhap=$ps$$.sl_nhap_qd;$ps$$.sl_xuat=$ps$$.sl_xuat_qd;return $ps$$});$callback$$(null,$pss$$)}).catch($error$$=>{$callback$$($error$$)})})}},function($error$$,$results$$){if($error$$)return $fn$$($error$$);let $data$$=[];$results$$.ps.forEach(function($r$$){$r$$.sysorder=
5
- 5;$r$$.bold=!1;$data$$.push($r$$)});async.parallel({ton_dau:function($callback$$){var $ton_dau$$=$results$$.dn.csum("ton00");$callback$$(null,$ton_dau$$)},du_dau:function($callback$$){var $du_dau$$=$results$$.dn.csum("du00");$callback$$(null,$du_dau$$)},sl_nhap:function($callback$$){var $sl_nhap$$=$results$$.ps.csum("sl_nhap");$callback$$(null,$sl_nhap$$)},tien_nhap:function($callback$$){var $tien_nhap$$=$results$$.ps.csum("tien_nhap");$callback$$(null,$tien_nhap$$)},sl_xuat:function($callback$$){var $sl_xuat$$=
6
- $results$$.ps.csum("sl_xuat");$callback$$(null,$sl_xuat$$)},tien_xuat:function($callback$$){var $tien_xuat$$=$results$$.ps.csum("tien_xuat");$callback$$(null,$tien_xuat$$)}},function($error$$,$results$$){$data$$.push({sysorder:1,bold:!0,dien_giai:"T\u1ed3n \u0111\u1ea7u k\u1ef3",sl_nhap:$results$$.ton_dau,tien_nhap:$results$$.du_dau,sl_xuat:0,tien_xuat:0});$data$$.push({sysorder:6,bold:!0,dien_giai:"C\u1ed9ng ph\u00e1t sinh trong k\u1ef3",sl_nhap:$results$$.sl_nhap,tien_nhap:$results$$.tien_nhap,
7
- sl_xuat:$results$$.sl_xuat,tien_xuat:$results$$.tien_xuat});$data$$.push({sysorder:9,bold:!0,dien_giai:"T\u1ed3n cu\u1ed1i k\u1ef3",sl_nhap:$results$$.ton_dau+$results$$.sl_nhap-$results$$.sl_xuat,tien_nhap:$results$$.du_dau+$results$$.tien_nhap-$results$$.tien_xuat});$fn$$(null,$data$$)})})};
2
+ module.exports=async function($condition$$,$fn$$){if(!($condition$$&&$condition$$.tu_ngay&&$condition$$.ma_vt&&$condition$$.den_ngay&&$condition$$.id_app))return $fn$$("L\u1ed7i: B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: tu_ngay,den_ngay,ma_vt,id_app");let $id_app$$=$condition$$.id_app,$ma_dvcs$$=$condition$$.ma_dvcs,$ma_kho$$=$condition$$.ma_kho,$ds_ma_kho$$;$ma_kho$$&&(Array.isArray($ma_kho$$)?$ds_ma_kho$$=[...$ma_kho$$]:typeof $ma_kho$$=="string"&&($ds_ma_kho$$=await global.getModel("dmkho").getAllChildrenGroup($id_app$$,
3
+ $ma_kho$$)));let $ma_vt$$=$condition$$.ma_vt,$tu_ngay$$=$condition$$.tu_ngay,$den_ngay$$=$condition$$.den_ngay;async.series({dn:function($callback$$){setImmediate(()=>{dkvt({...$condition$$,ma_kho:$ds_ma_kho$$},function($error$$,$result$$){if($error$$)return $callback$$($error$$);$callback$$(null,$result$$)})})},ps:function($callback$$){setImmediate(()=>{let $query$$={id_app:$id_app$$,ngay_ct:{$gte:$tu_ngay$$,$lte:$den_ngay$$},ma_vt:$ma_vt$$};$ds_ma_kho$$?$query$$.ma_kho={$in:$ds_ma_kho$$}:$condition$$.ma_kho&&
4
+ ($query$$.ma_kho=$condition$$.ma_kho);$ma_dvcs$$&&($query$$.ma_dvcs=$ma_dvcs$$);$condition$$.ma_lo&&($query$$.ma_lo=$condition$$.ma_lo);$condition$$.han_sd&&($query$$.han_sd=$condition$$.han_sd);$condition$$.ma_tt1&&($query$$.ma_tt1=$condition$$.ma_tt1);$condition$$.ma_tt2&&($query$$.ma_tt2=$condition$$.ma_tt2);$condition$$.ma_tt3&&($query$$.ma_tt3=$condition$$.ma_tt3);$condition$$.ma_kh&&($query$$.ma_kh=$condition$$.ma_kh);sokho.find($query$$).lean().then(function($pss$$){$pss$$=$pss$$.map($ps$$=>
5
+ {$ps$$.sl_nhap=$ps$$.sl_nhap_qd;$ps$$.sl_xuat=$ps$$.sl_xuat_qd;return $ps$$});$callback$$(null,$pss$$)}).catch($error$$=>{$callback$$($error$$)})})}},function($error$$,$results$$){if($error$$)return $fn$$($error$$);let $data$$=[];$results$$.ps.forEach(function($r$$){$r$$.sysorder=5;$r$$.bold=!1;$data$$.push($r$$)});async.parallel({ton_dau:function($callback$$){var $ton_dau$$=$results$$.dn.csum("ton00");$callback$$(null,$ton_dau$$)},du_dau:function($callback$$){var $du_dau$$=$results$$.dn.csum("du00");
6
+ $callback$$(null,$du_dau$$)},sl_nhap:function($callback$$){var $sl_nhap$$=$results$$.ps.csum("sl_nhap");$callback$$(null,$sl_nhap$$)},tien_nhap:function($callback$$){var $tien_nhap$$=$results$$.ps.csum("tien_nhap");$callback$$(null,$tien_nhap$$)},sl_xuat:function($callback$$){var $sl_xuat$$=$results$$.ps.csum("sl_xuat");$callback$$(null,$sl_xuat$$)},tien_xuat:function($callback$$){var $tien_xuat$$=$results$$.ps.csum("tien_xuat");$callback$$(null,$tien_xuat$$)}},function($error$$,$results$$){$data$$.push({sysorder:1,
7
+ bold:!0,dien_giai:"T\u1ed3n \u0111\u1ea7u k\u1ef3",sl_nhap:$results$$.ton_dau,tien_nhap:$results$$.du_dau,sl_xuat:0,tien_xuat:0});$data$$.push({sysorder:6,bold:!0,dien_giai:"C\u1ed9ng ph\u00e1t sinh trong k\u1ef3",sl_nhap:$results$$.sl_nhap,tien_nhap:$results$$.tien_nhap,sl_xuat:$results$$.sl_xuat,tien_xuat:$results$$.tien_xuat});$data$$.push({sysorder:9,bold:!0,dien_giai:"T\u1ed3n cu\u1ed1i k\u1ef3",sl_nhap:$results$$.ton_dau+$results$$.sl_nhap-$results$$.sl_xuat,tien_nhap:$results$$.du_dau+$results$$.tien_nhap-
8
+ $results$$.tien_xuat});$fn$$(null,$data$$)})})};
@@ -1,7 +1,7 @@
1
1
  const dkvt=require("./dkvttt"),sokho=global.getModel("sokhott"),async=require("async");
2
- module.exports=function($condition$$,$fn$$){if(!($condition$$&&$condition$$.tu_ngay&&$condition$$.ma_vt&&$condition$$.den_ngay&&$condition$$.id_app))return $fn$$("L\u1ed7i: B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: tu_ngay,den_ngay,ma_vt,id_app");let $ma_dvcs$$=$condition$$.ma_dvcs,$ma_kho$$=$condition$$.ma_kho,$ma_vt$$=$condition$$.ma_vt,$tu_ngay$$=$condition$$.tu_ngay,$den_ngay$$=$condition$$.den_ngay,$id_app$$=$condition$$.id_app;async.parallel({dn:function($callback$$){setImmediate(()=>
3
- {dkvt($condition$$,function($error$$,$result$$){if($error$$)return $callback$$($error$$);$callback$$(null,$result$$)})})},ps:function($callback$$){setImmediate(()=>{let $query$$={id_app:$id_app$$,ngay_ct:{$gte:$tu_ngay$$,$lte:$den_ngay$$},ma_vt:$ma_vt$$};$ma_kho$$&&($query$$.ma_kho=$ma_kho$$);$ma_dvcs$$&&($query$$.ma_dvcs=$ma_dvcs$$);$condition$$.ma_lo&&($query$$.ma_lo=$condition$$.ma_lo);$condition$$.han_sd&&($query$$.han_sd=$condition$$.han_sd);$condition$$.ma_tt1&&($query$$.ma_tt1=$condition$$.ma_tt1);
4
- $condition$$.ma_tt2&&($query$$.ma_tt2=$condition$$.ma_tt2);$condition$$.ma_tt3&&($query$$.ma_tt3=$condition$$.ma_tt3);sokho.find($query$$).lean().then(function($pss$$){$pss$$=$pss$$.map($ps$$=>{$ps$$.sl_nhap=$ps$$.sl_nhap_qd;$ps$$.sl_xuat=$ps$$.sl_xuat_qd;return $ps$$});$callback$$(null,$pss$$)}).catch($error$$=>{$callback$$($error$$)})})}},function($error$$,$results$$){if($error$$)return $fn$$($error$$);let $data$$=[];$results$$.ps.forEach(function($r$$){$r$$.sysorder=5;$r$$.bold=!1;$data$$.push($r$$)});
5
- async.parallel({ton_dau:function($callback$$){var $ton_dau$$=$results$$.dn.csum("ton00");$callback$$(null,$ton_dau$$)},du_dau:function($callback$$){var $du_dau$$=$results$$.dn.csum("du00");$callback$$(null,$du_dau$$)},sl_nhap:function($callback$$){var $sl_nhap$$=$results$$.ps.csum("sl_nhap");$callback$$(null,$sl_nhap$$)},tien_nhap:function($callback$$){var $tien_nhap$$=$results$$.ps.csum("tien_nhap");$callback$$(null,$tien_nhap$$)},sl_xuat:function($callback$$){var $sl_xuat$$=$results$$.ps.csum("sl_xuat");
6
- $callback$$(null,$sl_xuat$$)},tien_xuat:function($callback$$){var $tien_xuat$$=$results$$.ps.csum("tien_xuat");$callback$$(null,$tien_xuat$$)}},function($error$$,$results$$){$data$$.push({sysorder:1,bold:!0,dien_giai:"T\u1ed3n \u0111\u1ea7u k\u1ef3",sl_nhap:$results$$.ton_dau,tien_nhap:$results$$.du_dau,sl_xuat:0,tien_xuat:0});$data$$.push({sysorder:6,bold:!0,dien_giai:"C\u1ed9ng ph\u00e1t sinh trong k\u1ef3",sl_nhap:$results$$.sl_nhap,tien_nhap:$results$$.tien_nhap,sl_xuat:$results$$.sl_xuat,tien_xuat:$results$$.tien_xuat});
7
- $data$$.push({sysorder:9,bold:!0,dien_giai:"T\u1ed3n cu\u1ed1i k\u1ef3",sl_nhap:$results$$.ton_dau+$results$$.sl_nhap-$results$$.sl_xuat,tien_nhap:$results$$.du_dau+$results$$.tien_nhap-$results$$.tien_xuat});$fn$$(null,$data$$)})})};
2
+ module.exports=async function($condition$$,$fn$$){if(!($condition$$&&$condition$$.tu_ngay&&$condition$$.ma_vt&&$condition$$.den_ngay&&$condition$$.id_app))return $fn$$("L\u1ed7i: B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: tu_ngay,den_ngay,ma_vt,id_app");let $id_app$$=$condition$$.id_app,$ma_dvcs$$=$condition$$.ma_dvcs,$ma_kho$$=$condition$$.ma_kho,$ds_ma_kho$$;$ma_kho$$&&(Array.isArray($ma_kho$$)?$ds_ma_kho$$=[...$ma_kho$$]:typeof $ma_kho$$=="string"&&($ds_ma_kho$$=await global.getModel("dmkho").getAllChildrenGroup($id_app$$,
3
+ $ma_kho$$)));let $ma_vt$$=$condition$$.ma_vt,$tu_ngay$$=$condition$$.tu_ngay,$den_ngay$$=$condition$$.den_ngay;async.parallel({dn:function($callback$$){setImmediate(()=>{dkvt({...$condition$$,ma_kho:$ds_ma_kho$$},function($error$$,$result$$){if($error$$)return $callback$$($error$$);$callback$$(null,$result$$)})})},ps:function($callback$$){setImmediate(()=>{let $query$$={id_app:$id_app$$,ngay_ct:{$gte:$tu_ngay$$,$lte:$den_ngay$$},ma_vt:$ma_vt$$};$ds_ma_kho$$?$query$$.ma_kho={$in:$ds_ma_kho$$}:$condition$$.ma_kho&&
4
+ ($query$$.ma_kho=$condition$$.ma_kho);$ma_dvcs$$&&($query$$.ma_dvcs=$ma_dvcs$$);$condition$$.ma_lo&&($query$$.ma_lo=$condition$$.ma_lo);$condition$$.han_sd&&($query$$.han_sd=$condition$$.han_sd);$condition$$.ma_tt1&&($query$$.ma_tt1=$condition$$.ma_tt1);$condition$$.ma_tt2&&($query$$.ma_tt2=$condition$$.ma_tt2);$condition$$.ma_tt3&&($query$$.ma_tt3=$condition$$.ma_tt3);sokho.find($query$$).lean().then(function($pss$$){$pss$$=$pss$$.map($ps$$=>{$ps$$.sl_nhap=$ps$$.sl_nhap_qd;$ps$$.sl_xuat=$ps$$.sl_xuat_qd;
5
+ return $ps$$});$callback$$(null,$pss$$)}).catch($error$$=>{$callback$$($error$$)})})}},function($error$$,$results$$){if($error$$)return $fn$$($error$$);let $data$$=[];$results$$.ps.forEach(function($r$$){$r$$.sysorder=5;$r$$.bold=!1;$data$$.push($r$$)});async.parallel({ton_dau:function($callback$$){var $ton_dau$$=$results$$.dn.csum("ton00");$callback$$(null,$ton_dau$$)},du_dau:function($callback$$){var $du_dau$$=$results$$.dn.csum("du00");$callback$$(null,$du_dau$$)},sl_nhap:function($callback$$){var $sl_nhap$$=
6
+ $results$$.ps.csum("sl_nhap");$callback$$(null,$sl_nhap$$)},tien_nhap:function($callback$$){var $tien_nhap$$=$results$$.ps.csum("tien_nhap");$callback$$(null,$tien_nhap$$)},sl_xuat:function($callback$$){var $sl_xuat$$=$results$$.ps.csum("sl_xuat");$callback$$(null,$sl_xuat$$)},tien_xuat:function($callback$$){var $tien_xuat$$=$results$$.ps.csum("tien_xuat");$callback$$(null,$tien_xuat$$)}},function($error$$,$results$$){$data$$.push({sysorder:1,bold:!0,dien_giai:"T\u1ed3n \u0111\u1ea7u k\u1ef3",sl_nhap:$results$$.ton_dau,
7
+ tien_nhap:$results$$.du_dau,sl_xuat:0,tien_xuat:0});$data$$.push({sysorder:6,bold:!0,dien_giai:"C\u1ed9ng ph\u00e1t sinh trong k\u1ef3",sl_nhap:$results$$.sl_nhap,tien_nhap:$results$$.tien_nhap,sl_xuat:$results$$.sl_xuat,tien_xuat:$results$$.tien_xuat});$data$$.push({sysorder:9,bold:!0,dien_giai:"T\u1ed3n cu\u1ed1i k\u1ef3",sl_nhap:$results$$.ton_dau+$results$$.sl_nhap-$results$$.sl_xuat,tien_nhap:$results$$.du_dau+$results$$.tien_nhap-$results$$.tien_xuat});$fn$$(null,$data$$)})})};
@@ -1,18 +1,17 @@
1
- const pbl=global.getModel("pbl"),hd2=global.getModel("hd2"),hd3=global.getModel("hd3"),so1=global.getModel("so1"),hd7=global.getModel("hd7"),async=require("async"),trangthai=global.getModel("trangthai"),transaction=global.getModel("transaction");
2
- module.exports=function($condition$$,$callback$$){if(!$condition$$.id_app)return $callback$$("H\u00e0m n\u00e0y y\u00eau c\u1ea7u tham s\u1ed1 id_app");let $data_hd2$$,$data_pbl$$,$data_so1$$;async.parallel({hd2:$callback$$=>{setImmediate(()=>{if(!$condition$$.ma_ct||$condition$$.ma_ct.indexOf("HD2")>=0||$condition$$.ma_ct.indexOf("SO7")>=0){let $_cd$$={...$condition$$};delete $_cd$$.show_payment_method;delete $_cd$$.show_bonus_points;hd2.find($_cd$$).lean().then($rs$$=>{for(let $v$$ of $rs$$)$v$$.details.forEach($r$$=>
3
- {$r$$.tien_hang_nt=$r$$.tien_nt;$r$$.tien_hang=$r$$.tien_hang_nt*($v$$.ty_gia||1);$r$$.tien_hang_ct_nt=$r$$.tien_ct_nt;$r$$.tien_hang_ct=$r$$.tien_hang_ct_nt*($v$$.ty_gia||1);$r$$.tien_hang_ct_nt||($r$$.tien_hang_ct=$r$$.tien_hang,$r$$.tien_hang_ct_nt=$r$$.tien_hang_nt);!$r$$.tien_ck_nt&&$r$$.tien_ck?$r$$.tien_ck_nt=$r$$.tien_ck:$r$$.tien_ck=($r$$.tien_ck_nt||0)*($v$$.ty_gia||1);$r$$.tien_nt=$r$$.tien_hang_ct_nt-($r$$.tien_ck_nt||0)+($r$$.tien_thue_nt||0);$r$$.tien=$r$$.tien_nt*($v$$.ty_gia||1)});
4
- $data_hd2$$=$rs$$;$callback$$(null,$rs$$)}).catch($error$$=>{$callback$$($error$$)})}else $callback$$(null,[])})},hd4:$callback$$=>{setImmediate(async()=>{if(!$condition$$.ma_ct||$condition$$.ma_ct.indexOf("HD2")>=0||$condition$$.ma_ct.indexOf("SO7")>=0){let $_cd$$;$condition$$.so_ct?$_cd$$={id_app:$condition$$.id_app,"details.id_hd":{$in:($data_hd2$$||[]).map($d$$=>$d$$._id.toString())}}:($_cd$$={...$condition$$},delete $_cd$$.show_payment_method,delete $_cd$$.show_bonus_points,delete $_cd$$.ma_ct);
5
- global.getModel("hd4").find($_cd$$).lean().then($rs$$=>{$callback$$(null,$rs$$)}).catch($error$$=>{$callback$$($error$$)})}else $callback$$(null,[])})},hd3:$callback$$=>{setImmediate(()=>{if(!$condition$$.ma_ct||$condition$$.ma_ct.indexOf("HD2")>=0||$condition$$.ma_ct.indexOf("SO7")>=0){let $_cd$$;$condition$$.so_ct?$_cd$$={id_app:$condition$$.id_app,"details.id_hd":{$in:($data_hd2$$||[]).map($d$$=>$d$$._id.toString())}}:($_cd$$={...$condition$$},delete $_cd$$.show_payment_method,delete $_cd$$.show_bonus_points,
6
- $_cd$$.$or&&$_cd$$.$or.find($o$$=>$o$$.user_nv)&&($_cd$$.details={$elemMatch:{$or:$_cd$$.$or}},delete $_cd$$.$or),delete $_cd$$.ma_ct,delete $_cd$$.so_ct);hd3.find($_cd$$).lean().then($rs$$=>{$rs$$.forEach($v$$=>{$v$$.details.forEach($r$$=>{$r$$.tien_hang=$r$$.tien;$r$$.tien_hang_nt=$r$$.tien_nt;$r$$.tien_hang_ct=$r$$.tien_ct;$r$$.tien_hang_ct_nt=$r$$.tien_ct_nt;$r$$.tien_hang_ct_nt||($r$$.tien_hang_ct=$r$$.tien_hang,$r$$.tien_hang_ct_nt=$r$$.tien_hang_nt);$r$$.tien_nt=$r$$.tien_hang_ct_nt-($r$$.tien_ck_nt||
7
- 0)+($r$$.tien_thue_nt||0);$r$$.tien=$r$$.tien_nt*($v$$.ty_gia||1)})});$callback$$(null,$rs$$)}).catch($error$$=>{$callback$$($error$$)})}else $callback$$(null,[])})},pbl:$callback$$=>{setImmediate(()=>{if(!$condition$$.ma_ct||$condition$$.ma_ct.indexOf("PBL")>=0){let $_cd$$={...$condition$$};delete $_cd$$.show_payment_method;delete $_cd$$.show_bonus_points;pbl.find($_cd$$).lean().then($rs$$=>{$rs$$.forEach($pbl$$=>{$pbl$$.details.forEach($r$$=>{$r$$.tien_hang_nt=$r$$.tien_hang_nt||0;$r$$.tien_hang=
8
- $r$$.tien_hang_nt*($pbl$$.ty_gia||1);$r$$.tien_hang_ct_nt=$r$$.tien_hang_ct_nt||0;$r$$.tien_hang_ct=$r$$.tien_hang_ct_nt*($pbl$$.ty_gia||1);$r$$.tien_hang_ct_nt||($r$$.tien_hang_ct=$r$$.tien_hang,$r$$.tien_hang_ct_nt=$r$$.tien_hang_nt);!$r$$.tien_ck_nt&&$r$$.tien_ck?$r$$.tien_ck_nt=$r$$.tien_ck:$r$$.tien_ck=($r$$.tien_ck_nt||0)*($pbl$$.ty_gia||1);$r$$.tien_nt=$r$$.tien_hang_ct_nt-($r$$.tien_ck_nt||0)+($r$$.tien_thue_nt||0);$r$$.tien=$r$$.tien_nt*($pbl$$.ty_gia||1)})});$data_pbl$$=$rs$$;$callback$$(null,
9
- $rs$$)}).catch($error$$=>{$callback$$($error$$)})}else $callback$$(null,[])})},so:$callback$$=>{setImmediate(()=>{if(!$condition$$.ma_ct||$condition$$.ma_ct.indexOf("SO1")>=0){let $_cd$$={...$condition$$};delete $_cd$$.show_payment_method;delete $_cd$$.show_bonus_points;so1.find($_cd$$).lean().then($rs$$=>{$rs$$.forEach($so1$$=>{$so1$$.ngay_ct=$so1$$.ngay_giao_hang||$so1$$.ngay_ct;$so1$$.details.forEach($r$$=>{$r$$.tien_hang_ct_nt||($r$$.tien_hang_ct=$r$$.tien_hang,$r$$.tien_hang_ct_nt=$r$$.tien_hang_nt);
10
- $r$$.tien_nt=$r$$.tien_hang_ct_nt-($r$$.tien_ck_nt||0)+($r$$.tien_thue_nt||0);$r$$.tien=$r$$.tien_hang_ct-($r$$.tien_ck||0)+($r$$.tien_thue_nt||0)})});$data_so1$$=$rs$$;$callback$$(null,$rs$$)}).catch($error$$=>{$callback$$($error$$)})}else $callback$$(null,[])})},hd7:$callback$$=>{setImmediate(()=>{if(!$condition$$.ma_ct||$condition$$.ma_ct.indexOf("PBL")>=0||$condition$$.ma_ct.indexOf("SO1")>=0){if($condition$$.so_ct){var $_cd$$=($data_pbl$$||[]).map($d$$=>$d$$._id.toString());$_cd$$=[...$_cd$$,
11
- ...($data_so1$$||[]).map($d$$=>$d$$._id.toString())];$_cd$$={id_app:$condition$$.id_app,"details.id_hd":{$in:$_cd$$}}}else $_cd$$={...$condition$$},delete $_cd$$.show_payment_method,delete $_cd$$.show_bonus_points,delete $_cd$$.ma_ct,delete $_cd$$.so_ct;hd7.find($_cd$$).lean().then($rs$$=>{$callback$$(null,$rs$$)}).catch($error$$=>{$callback$$($error$$)})}else $callback$$(null,[])})}},async($error$$,$rs$$)=>{if($error$$)return $callback$$($error$$);async.series({pbl:$callback$$=>{setImmediate(()=>
12
- {$rs$$.pbl.forEach($m$$=>{$m$$.details.filter($d$$=>$d$$.promotion&&$d$$.promotion.details_km).map($d$$=>$d$$.promotion.details_km).reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]).forEach($d$$=>{$d$$.sl_xuat=$d$$.sl_km;$m$$.details.push($d$$)});$m$$.promotion&&$m$$.promotion.forEach($p$$=>{$p$$=Object.assign({},$p$$);$p$$.sl_xuat=$p$$.sl_km;$m$$.details.push($p$$)})});$callback$$()})},so:$callback$$=>{setImmediate(()=>{($rs$$.so||[]).forEach($r$$=>{$r$$.ctcpbhs&&$r$$.ctcpbhs.forEach($c$$=>{$c$$.tien_hang=
13
- 0;$c$$.tien_hang_nt=0;$c$$.sl_xuat=0;$c$$.tien=$c$$.tien_hang+$c$$.tien_cp;$c$$.tien_nt=$c$$.tien_hang_nt+$c$$.tien_cp_nt;$r$$.details.push($c$$)});$rs$$.pbl.push($r$$)});$callback$$()})},hd2:$callback$$=>{setImmediate(()=>{let $hd4_details$$=($rs$$.hd4||[]).map($h$$=>$h$$.details||[]).reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]);$rs$$.hd2.forEach($r$$=>{($r$$.details||[]).forEach($detail$$=>{$detail$$.chi_phi_bh=$hd4_details$$.filter($h$$=>$h$$.id_hd===$r$$._id.toString()&&$h$$.ma_vt===$detail$$.ma_vt&&
14
- ($h$$.line_hd==void 0||$h$$.line_hd==$detail$$.line));$detail$$.tien_cp_nt=$detail$$.chi_phi_bh.map($d$$=>$d$$.tien_phi_nt||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$detail$$.tien_cp=$detail$$.chi_phi_bh.map($d$$=>$d$$.tien_phi||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0)});$rs$$.pbl.push($r$$)});$rs$$.hd3.forEach($r$$=>{$r$$.details_tl=$r$$.details.map($r$$=>$r$$);$r$$.details=[];$rs$$.pbl.push($r$$)});$rs$$.hd7.forEach($r$$=>{$r$$.details_tl=$r$$.details.map($r$$=>$r$$);$r$$.details=[];$rs$$.pbl.push($r$$)});
15
- $callback$$()})}},async()=>{let $reportData$$=$rs$$.pbl;await $reportData$$.asyncJoinModel2(null,trangthai,[{where:{trang_thai:"ma_trang_thai",ma_ct:"ma_ct"},fields:["post_sokho","post","post_socai","ten_trang_thai"]}]);$reportData$$=$reportData$$.filter($p$$=>$p$$.post);const $ptthanhtoans$$=$condition$$.show_payment_method!==!1?(await global.getModel("ptthanhtoan").find({status:!0,id_app:$condition$$.id_app}).lean()).map($pt$$=>{$pt$$.ma=`pttt__${$pt$$._id}`;return $pt$$}):[];if($condition$$.show_bonus_points||
16
- $ptthanhtoans$$&&$ptthanhtoans$$.length>0){const $queue$$=async.queue(async $r$$=>{if($condition$$.show_bonus_points){let $trans$$=await transaction.find({id_app:$condition$$.id_app,id_ct:{$regex:$r$$._id.toString(),$options:"i"}}).lean();$r$$.bonus_points=$trans$$.filter($tran$$=>$tran$$.receiver.email.toLowerCase()===$r$$.ma_kh.toLowerCase()).map($tran$$=>$tran$$.amount).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$r$$.used_points=$trans$$.filter($tran$$=>$tran$$.sender.email.toLowerCase()===$r$$.ma_kh.toLowerCase()).map($tran$$=>
17
- $tran$$.amount).reduce(($a$$,$b$$)=>$a$$+$b$$,0)}$ptthanhtoans$$&&$ptthanhtoans$$.length>0&&($r$$.thanh_toan=$ptthanhtoans$$,$r$$.thanh_toan.forEach($pt$$=>{$r$$[$pt$$.ma]=0;$r$$.pt_thanh_toan===$pt$$._id.toString()&&($r$$[$pt$$.ma]+=$r$$.tien_thu||$r$$.tien_con_lai||0);$r$$.pt_thanh_toan2===$pt$$._id.toString()&&($r$$[$pt$$.ma]+=$r$$.tien_thu2||0);$pt$$.tien_thu=$r$$[$pt$$.ma]}))},10);$queue$$.push($reportData$$);$queue$$.drain(()=>{$callback$$(null,$reportData$$,$ptthanhtoans$$||[])})}else $callback$$(null,
18
- $reportData$$,[])})})};
1
+ const pbl=global.getModel("pbl"),hd2=global.getModel("hd2"),hd3=global.getModel("hd3"),so1=global.getModel("so1"),hd7=global.getModel("hd7"),trangthai=global.getModel("trangthai"),transaction=global.getModel("transaction");function baseCondition($cd_condition$$){$cd_condition$$={...$cd_condition$$};delete $cd_condition$$.show_payment_method;delete $cd_condition$$.show_bonus_points;return $cd_condition$$}
2
+ function matchMaCt($condition$$,...$prefixes$$){return $condition$$.ma_ct?$prefixes$$.some($p$$=>$condition$$.ma_ct.indexOf($p$$)>=0):!0}
3
+ function normalizeHd2Detail($r$$,$ty_gia$$){$r$$.tien_hang_nt=$r$$.tien_nt;$r$$.tien_hang=$r$$.tien_hang_nt*$ty_gia$$;$r$$.tien_hang_ct_nt=$r$$.tien_ct_nt;$r$$.tien_hang_ct=$r$$.tien_hang_ct_nt*$ty_gia$$;$r$$.tien_hang_ct_nt||($r$$.tien_hang_ct=$r$$.tien_hang,$r$$.tien_hang_ct_nt=$r$$.tien_hang_nt);!$r$$.tien_ck_nt&&$r$$.tien_ck?$r$$.tien_ck_nt=$r$$.tien_ck:$r$$.tien_ck=($r$$.tien_ck_nt||0)*$ty_gia$$;$r$$.tien_nt=$r$$.tien_hang_ct_nt-($r$$.tien_ck_nt||0)+($r$$.tien_thue_nt||0);$r$$.tien=$r$$.tien_nt*
4
+ $ty_gia$$}function normalizeHd3Detail($r$$,$ty_gia$$){$r$$.tien_hang=$r$$.tien;$r$$.tien_hang_nt=$r$$.tien_nt;$r$$.tien_hang_ct=$r$$.tien_ct;$r$$.tien_hang_ct_nt=$r$$.tien_ct_nt;$r$$.tien_hang_ct_nt||($r$$.tien_hang_ct=$r$$.tien_hang,$r$$.tien_hang_ct_nt=$r$$.tien_hang_nt);$r$$.tien_nt=$r$$.tien_hang_ct_nt-($r$$.tien_ck_nt||0)+($r$$.tien_thue_nt||0);$r$$.tien=$r$$.tien_nt*$ty_gia$$}
5
+ function normalizePblDetail($r$$,$ty_gia$$){$r$$.tien_hang_nt=$r$$.tien_hang_nt||0;$r$$.tien_hang=$r$$.tien_hang_nt*$ty_gia$$;$r$$.tien_hang_ct_nt=$r$$.tien_hang_ct_nt||0;$r$$.tien_hang_ct=$r$$.tien_hang_ct_nt*$ty_gia$$;$r$$.tien_hang_ct_nt||($r$$.tien_hang_ct=$r$$.tien_hang,$r$$.tien_hang_ct_nt=$r$$.tien_hang_nt);!$r$$.tien_ck_nt&&$r$$.tien_ck?$r$$.tien_ck_nt=$r$$.tien_ck:$r$$.tien_ck=($r$$.tien_ck_nt||0)*$ty_gia$$;$r$$.tien_nt=$r$$.tien_hang_ct_nt-($r$$.tien_ck_nt||0)+($r$$.tien_thue_nt||0);$r$$.tien=
6
+ $r$$.tien_nt*$ty_gia$$}function normalizeSo1Detail($r$$){$r$$.tien_hang_ct_nt||($r$$.tien_hang_ct=$r$$.tien_hang,$r$$.tien_hang_ct_nt=$r$$.tien_hang_nt);$r$$.tien_nt=$r$$.tien_hang_ct_nt-($r$$.tien_ck_nt||0)+($r$$.tien_thue_nt||0);$r$$.tien=$r$$.tien_hang_ct-($r$$.tien_ck||0)+($r$$.tien_thue_nt||0)}
7
+ module.exports=async function($condition$$,$callback$$){if(!$condition$$.id_app)return $callback$$("H\u00e0m n\u00e0y y\u00eau c\u1ea7u tham s\u1ed1 id_app");try{var $isHD2_reportData$$=matchMaCt($condition$$,"HD2","SO7");const $isPBL$$=matchMaCt($condition$$,"PBL"),$isSO1$$=matchMaCt($condition$$,"SO1"),[$rawHd2$$,$rawPbl$$,$rawSo1$$]=await Promise.all([$isHD2_reportData$$?hd2.find(baseCondition($condition$$)).lean():Promise.resolve([]),$isPBL$$?pbl.find(baseCondition($condition$$)).lean():Promise.resolve([]),
8
+ $isSO1$$?so1.find(baseCondition($condition$$)).lean():Promise.resolve([])]);for(var $buildDependentCd_v$$ of $rawHd2$$){const $ty_gia$$=$buildDependentCd_v$$.ty_gia||1;$buildDependentCd_v$$.details.forEach($r$$=>normalizeHd2Detail($r$$,$ty_gia$$))}for(var $buildHd3Cd_v$$ of $rawPbl$$){const $ty_gia$$=$buildHd3Cd_v$$.ty_gia||1;$buildHd3Cd_v$$.details.forEach($r$$=>normalizePblDetail($r$$,$ty_gia$$))}for(const $v$$ of $rawSo1$$)$v$$.ngay_ct=$v$$.ngay_giao_hang||$v$$.ngay_ct,$v$$.details.forEach($r$$=>
9
+ normalizeSo1Detail($r$$));const $hd2Ids$$=$rawHd2$$.map($d$$=>$d$$._id.toString()),$pblSo1Ids$$=[...$rawPbl$$.map($d$$=>$d$$._id.toString()),...$rawSo1$$.map($d$$=>$d$$._id.toString())];$buildDependentCd_v$$=($cd$$,$ids$$)=>{if($condition$$.so_ct)return{id_app:$condition$$.id_app,[$cd$$]:{$in:$ids$$}};$cd$$=baseCondition($condition$$);delete $cd$$.ma_ct;delete $cd$$.so_ct;return $cd$$};$buildHd3Cd_v$$=()=>{if($condition$$.so_ct)return{id_app:$condition$$.id_app,"details.id_hd":{$in:$hd2Ids$$}};const $cd$$=
10
+ baseCondition($condition$$);delete $cd$$.ma_ct;delete $cd$$.so_ct;$cd$$.$or&&$cd$$.$or.find($o$$=>$o$$.user_nv)&&($cd$$.details={$elemMatch:{$or:$cd$$.$or}},delete $cd$$.$or);return $cd$$};const [$rawHd3$$,$rawHd4$$,$rawHd7$$]=await Promise.all([$isHD2_reportData$$?hd3.find($buildHd3Cd_v$$()).lean():Promise.resolve([]),$isHD2_reportData$$?global.getModel("hd4").find($condition$$.so_ct?{id_app:$condition$$.id_app,"details.id_hd":{$in:$hd2Ids$$}}:(()=>{const $cd$$=baseCondition($condition$$);delete $cd$$.ma_ct;
11
+ return $cd$$})()).lean():Promise.resolve([]),$isPBL$$||$isSO1$$?hd7.find($buildDependentCd_v$$("details.id_hd",$pblSo1Ids$$)).lean():Promise.resolve([])]);for(const $v$$ of $rawHd3$$){const $ty_gia$$=$v$$.ty_gia||1;$v$$.details.forEach($r$$=>normalizeHd3Detail($r$$,$ty_gia$$))}const $hd4Map$$=new Map;for(const $h$$ of $rawHd4$$)for(const $d$$ of $h$$.details||[]){const $keyBase$$=`${$d$$.id_hd}|${$d$$.ma_vt}`;$hd4Map$$.has($keyBase$$)||$hd4Map$$.set($keyBase$$,[]);$hd4Map$$.get($keyBase$$).push($d$$)}$isHD2_reportData$$=
12
+ [];for(const $m$$ of $rawPbl$$){$m$$.details.filter($d$$=>$d$$.promotion?.details_km).flatMap($d$$=>$d$$.promotion.details_km).forEach($d$$=>{$d$$.sl_xuat=$d$$.sl_km;$m$$.details.push($d$$)});if($m$$.promotion)for(const $p$$ of $m$$.promotion)$m$$.details.push({...$p$$,sl_xuat:$p$$.sl_km});$isHD2_reportData$$.push($m$$)}for(const $r$$ of $rawSo1$$){if($r$$.ctcpbhs)for(const $c$$ of $r$$.ctcpbhs)$c$$.tien_hang=0,$c$$.tien_hang_nt=0,$c$$.sl_xuat=0,$c$$.tien=$c$$.tien_hang+$c$$.tien_cp,$c$$.tien_nt=
13
+ $c$$.tien_hang_nt+$c$$.tien_cp_nt,$r$$.details.push($c$$);$isHD2_reportData$$.push($r$$)}for(const $r$$ of $rawHd2$$){const $rid$$=$r$$._id.toString();for(const $detail$$ of $r$$.details||[]){const $candidates$$=$hd4Map$$.get(`${$rid$$}|${$detail$$.ma_vt}`)||[];$detail$$.chi_phi_bh=$candidates$$.filter($h$$=>$h$$.line_hd===void 0||$h$$.line_hd===$detail$$.line);$detail$$.tien_cp_nt=$detail$$.chi_phi_bh.reduce(($s$$,$d$$)=>$s$$+($d$$.tien_phi_nt||0),0);$detail$$.tien_cp=$detail$$.chi_phi_bh.reduce(($s$$,
14
+ $d$$)=>$s$$+($d$$.tien_phi||0),0)}$isHD2_reportData$$.push($r$$)}for(const $r$$ of $rawHd3$$)$r$$.details_tl=$r$$.details,$r$$.details=[],$isHD2_reportData$$.push($r$$);for(const $r$$ of $rawHd7$$)$r$$.details_tl=$r$$.details,$r$$.details=[],$isHD2_reportData$$.push($r$$);const [,$ptthanhtoans$$]=await Promise.all([$isHD2_reportData$$.asyncJoinModel2(null,trangthai,[{where:{trang_thai:"ma_trang_thai",ma_ct:"ma_ct"},fields:["post_sokho","post","post_socai","ten_trang_thai"]}]),$condition$$.show_payment_method!==
15
+ !1?global.getModel("ptthanhtoan").find({status:!0,id_app:$condition$$.id_app}).lean():Promise.resolve([])]),$filteredData$$=$isHD2_reportData$$.filter($p$$=>$p$$.post),$mappedPt$$=$ptthanhtoans$$.map($pt$$=>({...$pt$$,ma:`pttt__${$pt$$._id}`})),$needPoints$$=$condition$$.show_bonus_points,$needPt$$=$mappedPt$$.length>0;if($needPoints$$||$needPt$$){if($needPoints$$){const $allIds$$=$filteredData$$.map($r$$=>$r$$._id.toString()),$allTrans$$=await transaction.find({id_app:$condition$$.id_app,id_ct:{$in:$allIds$$}}).lean(),
16
+ $transMap$$=new Map;for(const $tran$$ of $allTrans$$)for(const $id$$ of $allIds$$)$tran$$.id_ct?.toLowerCase().includes($id$$.toLowerCase())&&($transMap$$.has($id$$)||$transMap$$.set($id$$,[]),$transMap$$.get($id$$).push($tran$$));for(const $r$$ of $filteredData$$){const $trans$$=$transMap$$.get($r$$._id.toString())||[],$maKhLower$$=$r$$.ma_kh?.toLowerCase();$r$$.bonus_points=$trans$$.filter($t$$=>$t$$.receiver?.email?.toLowerCase()===$maKhLower$$).reduce(($s$$,$t$$)=>$s$$+$t$$.amount,0);$r$$.used_points=
17
+ $trans$$.filter($t$$=>$t$$.sender?.email?.toLowerCase()===$maKhLower$$).reduce(($s$$,$t$$)=>$s$$+$t$$.amount,0)}}if($needPt$$)for(const $r$$ of $filteredData$$){$r$$.thanh_toan=$mappedPt$$;for(const $pt$$ of $mappedPt$$)$r$$[$pt$$.ma]=0,$r$$.pt_thanh_toan===$pt$$._id.toString()&&($r$$[$pt$$.ma]+=$r$$.tien_thu||$r$$.tien_con_lai||0),$r$$.pt_thanh_toan2===$pt$$._id.toString()&&($r$$[$pt$$.ma]+=$r$$.tien_thu2||0),$pt$$.tien_thu=$r$$[$pt$$.ma]}}$callback$$(null,$filteredData$$,$mappedPt$$)}catch($error$$){$callback$$($error$$)}};
@@ -0,0 +1,18 @@
1
+ const pbl=global.getModel("pbl"),hd2=global.getModel("hd2"),hd3=global.getModel("hd3"),so1=global.getModel("so1"),hd7=global.getModel("hd7"),async=require("async"),trangthai=global.getModel("trangthai"),transaction=global.getModel("transaction");
2
+ module.exports=function($condition$$,$callback$$){if(!$condition$$.id_app)return $callback$$("H\u00e0m n\u00e0y y\u00eau c\u1ea7u tham s\u1ed1 id_app");let $data_hd2$$,$data_pbl$$,$data_so1$$;async.parallel({hd2:$callback$$=>{setImmediate(()=>{if(!$condition$$.ma_ct||$condition$$.ma_ct.indexOf("HD2")>=0||$condition$$.ma_ct.indexOf("SO7")>=0){let $_cd$$={...$condition$$};delete $_cd$$.show_payment_method;delete $_cd$$.show_bonus_points;hd2.find($_cd$$).lean().then($rs$$=>{for(let $v$$ of $rs$$)$v$$.details.forEach($r$$=>
3
+ {$r$$.tien_hang_nt=$r$$.tien_nt;$r$$.tien_hang=$r$$.tien_hang_nt*($v$$.ty_gia||1);$r$$.tien_hang_ct_nt=$r$$.tien_ct_nt;$r$$.tien_hang_ct=$r$$.tien_hang_ct_nt*($v$$.ty_gia||1);$r$$.tien_hang_ct_nt||($r$$.tien_hang_ct=$r$$.tien_hang,$r$$.tien_hang_ct_nt=$r$$.tien_hang_nt);!$r$$.tien_ck_nt&&$r$$.tien_ck?$r$$.tien_ck_nt=$r$$.tien_ck:$r$$.tien_ck=($r$$.tien_ck_nt||0)*($v$$.ty_gia||1);$r$$.tien_nt=$r$$.tien_hang_ct_nt-($r$$.tien_ck_nt||0)+($r$$.tien_thue_nt||0);$r$$.tien=$r$$.tien_nt*($v$$.ty_gia||1)});
4
+ $data_hd2$$=$rs$$;$callback$$(null,$rs$$)}).catch($error$$=>{$callback$$($error$$)})}else $callback$$(null,[])})},hd4:$callback$$=>{setImmediate(async()=>{if(!$condition$$.ma_ct||$condition$$.ma_ct.indexOf("HD2")>=0||$condition$$.ma_ct.indexOf("SO7")>=0){let $_cd$$;$condition$$.so_ct?$_cd$$={id_app:$condition$$.id_app,"details.id_hd":{$in:($data_hd2$$||[]).map($d$$=>$d$$._id.toString())}}:($_cd$$={...$condition$$},delete $_cd$$.show_payment_method,delete $_cd$$.show_bonus_points,delete $_cd$$.ma_ct);
5
+ global.getModel("hd4").find($_cd$$).lean().then($rs$$=>{$callback$$(null,$rs$$)}).catch($error$$=>{$callback$$($error$$)})}else $callback$$(null,[])})},hd3:$callback$$=>{setImmediate(()=>{if(!$condition$$.ma_ct||$condition$$.ma_ct.indexOf("HD2")>=0||$condition$$.ma_ct.indexOf("SO7")>=0){let $_cd$$;$condition$$.so_ct?$_cd$$={id_app:$condition$$.id_app,"details.id_hd":{$in:($data_hd2$$||[]).map($d$$=>$d$$._id.toString())}}:($_cd$$={...$condition$$},delete $_cd$$.show_payment_method,delete $_cd$$.show_bonus_points,
6
+ $_cd$$.$or&&$_cd$$.$or.find($o$$=>$o$$.user_nv)&&($_cd$$.details={$elemMatch:{$or:$_cd$$.$or}},delete $_cd$$.$or),delete $_cd$$.ma_ct,delete $_cd$$.so_ct);hd3.find($_cd$$).lean().then($rs$$=>{$rs$$.forEach($v$$=>{$v$$.details.forEach($r$$=>{$r$$.tien_hang=$r$$.tien;$r$$.tien_hang_nt=$r$$.tien_nt;$r$$.tien_hang_ct=$r$$.tien_ct;$r$$.tien_hang_ct_nt=$r$$.tien_ct_nt;$r$$.tien_hang_ct_nt||($r$$.tien_hang_ct=$r$$.tien_hang,$r$$.tien_hang_ct_nt=$r$$.tien_hang_nt);$r$$.tien_nt=$r$$.tien_hang_ct_nt-($r$$.tien_ck_nt||
7
+ 0)+($r$$.tien_thue_nt||0);$r$$.tien=$r$$.tien_nt*($v$$.ty_gia||1)})});$callback$$(null,$rs$$)}).catch($error$$=>{$callback$$($error$$)})}else $callback$$(null,[])})},pbl:$callback$$=>{setImmediate(()=>{if(!$condition$$.ma_ct||$condition$$.ma_ct.indexOf("PBL")>=0){let $_cd$$={...$condition$$};delete $_cd$$.show_payment_method;delete $_cd$$.show_bonus_points;pbl.find($_cd$$).lean().then($rs$$=>{$rs$$.forEach($pbl$$=>{$pbl$$.details.forEach($r$$=>{$r$$.tien_hang_nt=$r$$.tien_hang_nt||0;$r$$.tien_hang=
8
+ $r$$.tien_hang_nt*($pbl$$.ty_gia||1);$r$$.tien_hang_ct_nt=$r$$.tien_hang_ct_nt||0;$r$$.tien_hang_ct=$r$$.tien_hang_ct_nt*($pbl$$.ty_gia||1);$r$$.tien_hang_ct_nt||($r$$.tien_hang_ct=$r$$.tien_hang,$r$$.tien_hang_ct_nt=$r$$.tien_hang_nt);!$r$$.tien_ck_nt&&$r$$.tien_ck?$r$$.tien_ck_nt=$r$$.tien_ck:$r$$.tien_ck=($r$$.tien_ck_nt||0)*($pbl$$.ty_gia||1);$r$$.tien_nt=$r$$.tien_hang_ct_nt-($r$$.tien_ck_nt||0)+($r$$.tien_thue_nt||0);$r$$.tien=$r$$.tien_nt*($pbl$$.ty_gia||1)})});$data_pbl$$=$rs$$;$callback$$(null,
9
+ $rs$$)}).catch($error$$=>{$callback$$($error$$)})}else $callback$$(null,[])})},so:$callback$$=>{setImmediate(()=>{if(!$condition$$.ma_ct||$condition$$.ma_ct.indexOf("SO1")>=0){let $_cd$$={...$condition$$};delete $_cd$$.show_payment_method;delete $_cd$$.show_bonus_points;so1.find($_cd$$).lean().then($rs$$=>{$rs$$.forEach($so1$$=>{$so1$$.ngay_ct=$so1$$.ngay_giao_hang||$so1$$.ngay_ct;$so1$$.details.forEach($r$$=>{$r$$.tien_hang_ct_nt||($r$$.tien_hang_ct=$r$$.tien_hang,$r$$.tien_hang_ct_nt=$r$$.tien_hang_nt);
10
+ $r$$.tien_nt=$r$$.tien_hang_ct_nt-($r$$.tien_ck_nt||0)+($r$$.tien_thue_nt||0);$r$$.tien=$r$$.tien_hang_ct-($r$$.tien_ck||0)+($r$$.tien_thue_nt||0)})});$data_so1$$=$rs$$;$callback$$(null,$rs$$)}).catch($error$$=>{$callback$$($error$$)})}else $callback$$(null,[])})},hd7:$callback$$=>{setImmediate(()=>{if(!$condition$$.ma_ct||$condition$$.ma_ct.indexOf("PBL")>=0||$condition$$.ma_ct.indexOf("SO1")>=0){if($condition$$.so_ct){var $_cd$$=($data_pbl$$||[]).map($d$$=>$d$$._id.toString());$_cd$$=[...$_cd$$,
11
+ ...($data_so1$$||[]).map($d$$=>$d$$._id.toString())];$_cd$$={id_app:$condition$$.id_app,"details.id_hd":{$in:$_cd$$}}}else $_cd$$={...$condition$$},delete $_cd$$.show_payment_method,delete $_cd$$.show_bonus_points,delete $_cd$$.ma_ct,delete $_cd$$.so_ct;hd7.find($_cd$$).lean().then($rs$$=>{$callback$$(null,$rs$$)}).catch($error$$=>{$callback$$($error$$)})}else $callback$$(null,[])})}},async($error$$,$rs$$)=>{if($error$$)return $callback$$($error$$);async.series({pbl:$callback$$=>{setImmediate(()=>
12
+ {$rs$$.pbl.forEach($m$$=>{$m$$.details.filter($d$$=>$d$$.promotion&&$d$$.promotion.details_km).map($d$$=>$d$$.promotion.details_km).reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]).forEach($d$$=>{$d$$.sl_xuat=$d$$.sl_km;$m$$.details.push($d$$)});$m$$.promotion&&$m$$.promotion.forEach($p$$=>{$p$$=Object.assign({},$p$$);$p$$.sl_xuat=$p$$.sl_km;$m$$.details.push($p$$)})});$callback$$()})},so:$callback$$=>{setImmediate(()=>{($rs$$.so||[]).forEach($r$$=>{$r$$.ctcpbhs&&$r$$.ctcpbhs.forEach($c$$=>{$c$$.tien_hang=
13
+ 0;$c$$.tien_hang_nt=0;$c$$.sl_xuat=0;$c$$.tien=$c$$.tien_hang+$c$$.tien_cp;$c$$.tien_nt=$c$$.tien_hang_nt+$c$$.tien_cp_nt;$r$$.details.push($c$$)});$rs$$.pbl.push($r$$)});$callback$$()})},hd2:$callback$$=>{setImmediate(()=>{let $hd4_details$$=($rs$$.hd4||[]).map($h$$=>$h$$.details||[]).reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]);$rs$$.hd2.forEach($r$$=>{($r$$.details||[]).forEach($detail$$=>{$detail$$.chi_phi_bh=$hd4_details$$.filter($h$$=>$h$$.id_hd===$r$$._id.toString()&&$h$$.ma_vt===$detail$$.ma_vt&&
14
+ ($h$$.line_hd==void 0||$h$$.line_hd==$detail$$.line));$detail$$.tien_cp_nt=$detail$$.chi_phi_bh.map($d$$=>$d$$.tien_phi_nt||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$detail$$.tien_cp=$detail$$.chi_phi_bh.map($d$$=>$d$$.tien_phi||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0)});$rs$$.pbl.push($r$$)});$rs$$.hd3.forEach($r$$=>{$r$$.details_tl=$r$$.details.map($r$$=>$r$$);$r$$.details=[];$rs$$.pbl.push($r$$)});$rs$$.hd7.forEach($r$$=>{$r$$.details_tl=$r$$.details.map($r$$=>$r$$);$r$$.details=[];$rs$$.pbl.push($r$$)});
15
+ $callback$$()})}},async()=>{let $reportData$$=$rs$$.pbl;await $reportData$$.asyncJoinModel2(null,trangthai,[{where:{trang_thai:"ma_trang_thai",ma_ct:"ma_ct"},fields:["post_sokho","post","post_socai","ten_trang_thai"]}]);$reportData$$=$reportData$$.filter($p$$=>$p$$.post);const $ptthanhtoans$$=$condition$$.show_payment_method!==!1?(await global.getModel("ptthanhtoan").find({status:!0,id_app:$condition$$.id_app}).lean()).map($pt$$=>{$pt$$.ma=`pttt__${$pt$$._id}`;return $pt$$}):[];if($condition$$.show_bonus_points||
16
+ $ptthanhtoans$$&&$ptthanhtoans$$.length>0){const $queue$$=async.queue(async $r$$=>{if($condition$$.show_bonus_points){let $trans$$=await transaction.find({id_app:$condition$$.id_app,id_ct:{$regex:$r$$._id.toString(),$options:"i"}}).lean();$r$$.bonus_points=$trans$$.filter($tran$$=>$tran$$.receiver.email.toLowerCase()===$r$$.ma_kh.toLowerCase()).map($tran$$=>$tran$$.amount).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$r$$.used_points=$trans$$.filter($tran$$=>$tran$$.sender.email.toLowerCase()===$r$$.ma_kh.toLowerCase()).map($tran$$=>
17
+ $tran$$.amount).reduce(($a$$,$b$$)=>$a$$+$b$$,0)}$ptthanhtoans$$&&$ptthanhtoans$$.length>0&&($r$$.thanh_toan=$ptthanhtoans$$,$r$$.thanh_toan.forEach($pt$$=>{$r$$[$pt$$.ma]=0;$r$$.pt_thanh_toan===$pt$$._id.toString()&&($r$$[$pt$$.ma]+=$r$$.tien_thu||$r$$.tien_con_lai||0);$r$$.pt_thanh_toan2===$pt$$._id.toString()&&($r$$[$pt$$.ma]+=$r$$.tien_thu2||0);$pt$$.tien_thu=$r$$[$pt$$.ma]}))},10);$queue$$.push($reportData$$);$queue$$.drain(()=>{$callback$$(null,$reportData$$,$ptthanhtoans$$||[])})}else $callback$$(null,
18
+ $reportData$$,[])})})};
@@ -1,29 +1,25 @@
1
- const databanle=require("./databanle"),async=require("async"),moment=require("moment");
2
- module.exports=async function($condition$$,$callback$$){let $field_group_by$$=$condition$$.group_by||"ngay_ct",$group_by$$;$group_by$$=$field_group_by$$!="ngay_ct"&&$field_group_by$$!="nam"&&$field_group_by$$!="ma_kho"&&$field_group_by$$!="ma_kh"&&$field_group_by$$!="ma_nv"?["nam",$field_group_by$$]:[$field_group_by$$];if(!$condition$$.tu_ngay||!$condition$$.den_ngay)return $callback$$("B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1:tu_ngay,den_ngay");const $query$$={id_app:$condition$$.id_app};
3
- $query$$.ngay_ct={$gte:$condition$$.tu_ngay,$lte:$condition$$.den_ngay};$condition$$.ma_dvcs&&($query$$.ma_dvcs=$condition$$.ma_dvcs);$condition$$.ma_kho&&($query$$.$or=[{ma_kho:$condition$$.ma_kho},{"details.ma_kho":$condition$$.ma_kho}]);if($condition$$.ma_kh)$query$$.ma_kh=$condition$$.ma_kh;else{var $condition_kh_custs$$={};if($condition$$.nh_kh){var $nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$=await global.getModel("group").getAllChildrenGroup($condition$$.id_app,$condition$$.nh_kh,{status:!0});
4
- $condition_kh_custs$$.nh_kh={$in:$nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$}}$condition$$.nh_kh2&&($nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$=await global.getModel("group").getAllChildrenGroup($condition$$.id_app,$condition$$.nh_kh2,{status:!0}),$condition_kh_custs$$.nh_kh2={$in:$nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$});$condition$$.nh_kh3&&($nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$=await global.getModel("group").getAllChildrenGroup($condition$$.id_app,$condition$$.nh_kh3,{status:!0}),$condition_kh_custs$$.nh_kh3=
5
- {$in:$nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$});$condition$$.nh_kh4&&($nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$=await global.getModel("group").getAllChildrenGroup($condition$$.id_app,$condition$$.nh_kh4,{status:!0}),$condition_kh_custs$$.nh_kh4={$in:$nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$});$condition$$.nh_kh5&&($nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$=await global.getModel("group").getAllChildrenGroup($condition$$.id_app,$condition$$.nh_kh5,{status:!0}),$condition_kh_custs$$.nh_kh5={$in:$nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$});
6
- Object.keys($condition_kh_custs$$).length>0&&($condition_kh_custs$$.id_app=$condition$$.id_app,$condition_kh_custs$$=await global.getModel("customer").find($condition_kh_custs$$,{ma_kh:1}).lean(),$query$$.ma_kh={$in:$condition_kh_custs$$.map($c$$=>$c$$.ma_kh)})}$condition$$.ma_ct&&($query$$.ma_ct=$condition$$.ma_ct);$condition$$.user_hoa_hong&&($query$$.$or?$query$$.$and=[{$or:[{user_nv:$condition$$.user_hoa_hong},{user_ctv:$condition$$.user_hoa_hong},{user_ctv2:$condition$$.user_hoa_hong},{user_kho:$condition$$.user_hoa_hong},
7
- {user_gt:$condition$$.user_hoa_hong},{user_ql:$condition$$.user_hoa_hong},{"details.user_nv":$condition$$.user_hoa_hong},{"details.user_ctv":$condition$$.user_hoa_hong},{"details.user_ctv2":$condition$$.user_hoa_hong},{"details.user_kho":$condition$$.user_hoa_hong},{"details.user_gt":$condition$$.user_hoa_hong},{"details.user_ql":$condition$$.user_hoa_hong}]}]:$query$$.$or=[{user_nv:$condition$$.user_hoa_hong},{user_ctv:$condition$$.user_hoa_hong},{user_ctv2:$condition$$.user_hoa_hong},{user_kho:$condition$$.user_hoa_hong},
8
- {user_gt:$condition$$.user_hoa_hong},{user_ql:$condition$$.user_hoa_hong},{"details.user_nv":$condition$$.user_hoa_hong},{"details.user_ctv":$condition$$.user_hoa_hong},{"details.user_ctv2":$condition$$.user_hoa_hong},{"details.user_kho":$condition$$.user_hoa_hong},{"details.user_gt":$condition$$.user_hoa_hong},{"details.user_ql":$condition$$.user_hoa_hong}]);databanle($query$$,async function($error$$,$rs$$,$ptthanhtoans$$){if($error$$)return $callback$$($error$$);const $thanh_toan$$=($ptthanhtoans$$||
9
- []).map($pt$$=>({name:$pt$$.ma,value:$pt$$.ma,ma:$pt$$.ma,ten:$pt$$.ten}));$rs$$.forEach(function($r$$){$r$$.sl_dh=1;$r$$.thang=$r$$.ngay_ct.getMonth()+1;$r$$.nam=moment($r$$.ngay_ct).year();$r$$.quy=moment($r$$.ngay_ct).quarter()});async.mapLimit($rs$$,20,function($r$$,$callback$$){$r$$.t_sl_xuat=$r$$.details.csum("sl_xuat");$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");
10
- $r$$.t_tien=$r$$.details.csum("tien");$r$$.t_tien_cp=$r$$.details.csum("tien_cp");$r$$.tien_ck_hd=$r$$.tien_ck_hd||0;$r$$.t_tien_xuat=$r$$.details.csum("tien_xuat");$r$$.t_tien_hoa_hong=$r$$.details.csum("tien_hoa_hong");$r$$.t_tien_hoa_hong_gt=$r$$.details.csum("tien_hoa_hong_gt");$r$$.t_tien_hoa_hong_ctv=$r$$.details.csum("tien_hoa_hong_ctv");$r$$.t_tien_hoa_hong_ql=$r$$.details.csum("tien_hoa_hong_ql");$r$$.tien_freeship=$r$$.tien_freeship||0;$r$$.tien_phi_vc=$r$$.tien_phi_vc||0;$r$$.details_tl?
11
- ($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=$r$$.details_tl.csum("tien_nhap"),$r$$.t_sl_nhap=$r$$.details_tl.csum("sl_nhap"),$r$$.t_tien_hoa_hong-=$r$$.details_tl.csum("tien_hoa_hong"),$r$$.t_tien_hoa_hong_gt-=$r$$.details_tl.csum("tien_hoa_hong_gt"),$r$$.t_tien_hoa_hong_ctv-=$r$$.details_tl.csum("tien_hoa_hong_ctv"),$r$$.t_tien_hoa_hong_ql-=$r$$.details_tl.csum("tien_hoa_hong_ql")):($r$$.t_tien_tl=
12
- 0,$r$$.t_sl_nhap=0,$r$$.t_tien_nhap=0);setImmediate(async()=>{try{if($r$$._id){const $no$$=await global.getModel("tdttno").findOne({id_ct:$r$$._id,id_app:$condition$$.id_app}).lean();if($no$$){$r$$.t_tien_no_nt=$no$$.tien_nt;$r$$.t_tien_no=$no$$.tien;const $da_thus$$=await global.getModel("tdttno_tt").find({id_hd:$r$$._id,id_app:$condition$$.id_app}).lean();$r$$.t_tien_da_thu=$da_thus$$.map($d$$=>$d$$.tien).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$r$$.t_tien_da_thu_nt=$da_thus$$.map($d$$=>$d$$.tien_nt).reduce(($a$$,
13
- $b$$)=>$a$$+$b$$,0)}$r$$.t_tien_con_no=$r$$.t_tien_no-$r$$.t_tien_da_thu;$r$$.t_tien_con_no_nt=$r$$.t_tien_no_nt-$r$$.t_tien_da_thu_nt}$callback$$(null,$r$$)}catch($e$$){$callback$$($e$$)}})},async function($error$$,$rs$$){if($error$$)return $callback$$($error$$);$error$$=[{name:"sl_dh",value:"sl_dh"},{name:"t_sl_xuat",value:"t_sl_xuat"},{name:"t_sl_nhap",value:"t_sl_nhap"},{name:"t_tien_hang",value:"t_tien_hang"},{name:"t_tien_hang_ct",value:"t_tien_hang_ct"},{name:"t_thue",value:"t_thue"},{name:"t_tien_cp",
14
- value:"t_tien_cp"},{name:"t_tien_ck",value:"t_tien_ck"},{name:"t_tien",value:"t_tien"},{name:"tien_ck_hd",value:"tien_ck_hd"},{name:"tien_freeship",value:"tien_freeship"},{name:"tien_phi_vc",value:"tien_phi_vc"},{name:"tien_evoucher",value:"tien_evoucher"},{name:"tien_thu",value:"tien_thu"},{name:"tien_thu2",value:"tien_thu2"},{name:"tien_paymentByPoints",value:"tien_paymentByPoints"},{name:"t_tien_xuat",value:"t_tien_xuat"},{name:"t_tien_tl",value:"t_tien_tl"},{name:"t_tien_thue_tl",value:"t_tien_thue_tl"},
15
- {name:"t_tien_nhap",value:"t_tien_nhap"},{name:"phai_tra",value:"phai_tra"},{name:"t_tien_hoa_hong",value:"t_tien_hoa_hong"},{name:"t_tien_hoa_hong_gt",value:"t_tien_hoa_hong_gt"},{name:"t_tien_hoa_hong_ctv",value:"t_tien_hoa_hong_ctv"},{name:"t_tien_hoa_hong_ql",value:"t_tien_hoa_hong_ql"},{name:"t_tien_da_thu",value:"t_tien_da_thu"},{name:"t_tien_con_no",value:"t_tien_con_no"},...$thanh_toan$$];let $data$$=await $rs$$.asyncGroupBy([...(new Set([...$group_by$$,"ma_kh"]))],$error$$);await $data$$.filter($r$$=>
16
- $r$$.ma_kh).asyncJoinModel2($condition$$.id_app,"customer",{where:"ma_kh",fields:["ngay_mua_dau_tien",{cust_date_created:"date_created"}]});$data$$.forEach($r$$=>{$r$$.t_kh=1;if($r$$.cust_date_created){let $tu_ngay$$;switch($field_group_by$$){case "nam":var $date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$=moment(new Date(Number($r$$.nam),1,1));$tu_ngay$$=$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$.startOf("year").toDate().getTime();$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$=$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$.endOf("year").toDate().getTime();
17
- break;case "quy":$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$=moment(new Date(Number($r$$.nam),1,1));$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$=$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$.quarters(Number($r$$.quy));$tu_ngay$$=$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$.startOf("quarters").toDate().getTime();$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$=$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$.endOf("quarters").toDate().getTime();break;case "thang":$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$=
18
- moment(new Date(Number($r$$.nam),0,1));$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$=$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$.month(Number($r$$.thang)-1);$tu_ngay$$=$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$.startOf("months").toDate().getTime();$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$=$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$.endOf("months").toDate().getTime();break;case "ngay_ct":$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$=moment($r$$.ngay_ct);$tu_ngay$$=
19
- $date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$.startOf("dates").toDate().getTime();$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$=$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$.endOf("dates").toDate().getTime();break;default:$tu_ngay$$=(new Date($condition$$.tu_ngay)).getTime(),$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$=(new Date($condition$$.den_ngay)).getTime()}var $cust_created_ngay_mua_dau_tien$$=(new Date($r$$.ngay_mua_dau_tien)).getTime();$r$$.mua_lan_dau=$r$$.ngay_mua_dau_tien&&
20
- $cust_created_ngay_mua_dau_tien$$>=$tu_ngay$$&&$cust_created_ngay_mua_dau_tien$$<=$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$?1:0;$r$$.kh_cu=$r$$.ngay_mua_dau_tien&&$cust_created_ngay_mua_dau_tien$$<$tu_ngay$$?1:0;$cust_created_ngay_mua_dau_tien$$=(new Date($r$$.cust_date_created)).getTime();$r$$.kh_moi=$r$$.ngay_mua_dau_tien&&$cust_created_ngay_mua_dau_tien$$>=$tu_ngay$$&&$cust_created_ngay_mua_dau_tien$$<=$date$jscomp$1_date$jscomp$2_date$jscomp$3_date$$?1:0}else $r$$.mua_lan_dau=0,$r$$.kh_moi=
21
- 0,$r$$.kh_cu=0});switch($condition$$.loai_kh){case "MUA_LAN_DAU":$data$$=$data$$.filter($c$$=>$c$$.mua_lan_dau);$rs$$=$rs$$.filter($r$$=>$data$$.find($c$$=>$c$$.ma_kh===$r$$.ma_kh));break;case "KH_MOI":$data$$=$data$$.filter($c$$=>$c$$.kh_moi);$rs$$=$rs$$.filter($r$$=>$data$$.find($c$$=>$c$$.ma_kh===$r$$.ma_kh));break;case "KH_CU":$data$$=$data$$.filter($c$$=>$c$$.kh_cu),$rs$$=$rs$$.filter($r$$=>$data$$.find($c$$=>$c$$.ma_kh===$r$$.ma_kh))}let $report$$=await $data$$.asyncGroupBy($group_by$$,[...$error$$,
22
- "kh_moi","kh_cu","t_kh","sl_dh","mua_lan_dau"]);$report$$=$report$$.sort(($a$$,$b$$)=>{for(let $i$$=0;$i$$<$group_by$$.length;$i$$++){let $field$$=$group_by$$[$i$$],$a_v$$=$a$$[$field$$],$b_v$$=$b$$[$field$$];$field$$=="ngay_ct"&&($a_v$$=moment($a_v$$).format("YYYY-MM-DD"),$b_v$$=moment($b_v$$).format("YYYY-MM-DD"));if($a_v$$<$b_v$$)return-1;if($a_v$$>$b_v$$)return 1}return 0});$report$$.forEach(function($r$$,$i$$){$r$$.stt=$i$$+1;$r$$.bold=!1;$r$$.t_phai_thu=$r$$.t_tien_hang_ct-($r$$.t_tien_ck||
23
- 0)+($r$$.t_thue||0)+($r$$.tien_phi_vc||0)-($r$$.tien_freeship||0)-($r$$.tien_ck_hd||0)-($r$$.tien_evoucher||0);$r$$.t_doanh_thu=$r$$.t_tien_hang_ct-($r$$.t_tien_ck||0)+($r$$.tien_phi_vc||0)-($r$$.tien_freeship||0)-($r$$.tien_ck_hd||0)-($r$$.tien_evoucher||0);$r$$.t_lai=$r$$.t_doanh_thu-$r$$.t_tien_xuat-($r$$.t_tien_tl-$r$$.t_tien_nhap)-($r$$.t_tien_cp||0);$r$$.t_doanh_thu_thuan=$r$$.t_doanh_thu-$r$$.t_tien_tl;$r$$.t_tien_thu=$thanh_toan$$.map($pt$$=>$r$$[$pt$$.name]||0).reduce(($a$$,$b$$)=>$a$$+$b$$,
24
- 0);$r$$.t_tien_paymentByPoints=$r$$.tien_paymentByPoints||0;$r$$.nam?($i$$=moment(new Date($r$$.nam,0,1)),$r$$.quy?($i$$=$i$$.quarter($r$$.quy),$r$$.tu_ngay=$i$$.startOf("quarter").toDate(),$r$$.den_ngay=$i$$.endOf("quarter").toDate()):$r$$.thang?($i$$=$i$$.month($r$$.thang-1),$r$$.tu_ngay=$i$$.startOf("month").toDate(),$r$$.den_ngay=$i$$.endOf("month").toDate()):($r$$.tu_ngay=$i$$.startOf("year").toDate(),$r$$.den_ngay=$i$$.endOf("year").toDate())):($r$$.tu_ngay=$condition$$.tu_ngay,$r$$.den_ngay=
25
- $condition$$.den_ngay)});await $report$$.filter($r$$=>$r$$.ma_kh).asyncJoinModel2($condition$$.id_app,"customer",{where:"ma_kh",fields:"ten_kh"});await $report$$.filter($r$$=>$r$$.ma_kho).asyncJoinModel2($condition$$.id_app,"dmkho",{where:"ma_kho",fields:"ten_kho"});const $tong_cong$$={[$group_by$$[0]]:"T\u1ed5ng c\u1ed9ng",mua_lan_dau:$report$$.csum("mua_lan_dau"),kh_moi:$report$$.csum("kh_moi"),kh_cu:$report$$.csum("kh_cu"),t_kh:$report$$.csum("t_kh"),sl_dh:$report$$.csum("sl_dh"),t_sl_xuat:$report$$.csum("t_sl_xuat"),
26
- t_sl_nhap:$report$$.csum("t_sl_nhap"),t_tien_hang:$report$$.csum("t_tien_hang"),t_tien_hang_ct:$report$$.csum("t_tien_hang_ct"),t_thue:$report$$.csum("t_thue"),t_tien_cp:$report$$.csum("t_tien_cp"),t_tien_ck:$report$$.csum("t_tien_ck"),t_tien:$report$$.csum("t_tien"),tien_ck_hd:$report$$.csum("tien_ck_hd"),tien_phi_vc:$report$$.csum("tien_phi_vc"),tien_freeship:$report$$.csum("tien_freeship"),t_tien_tl:$report$$.csum("t_tien_tl"),t_tien_thue_tl:$report$$.csum("t_tien_thue_tl"),t_tien_xuat:$report$$.csum("t_tien_xuat"),
27
- t_tien_nhap:$report$$.csum("t_tien_nhap"),t_phai_thu:$report$$.csum("t_phai_thu"),t_doanh_thu:$report$$.csum("t_doanh_thu"),t_doanh_thu_thuan:$report$$.csum("t_doanh_thu_thuan"),tien_evoucher:$report$$.csum("tien_evoucher"),tien_thu:$report$$.csum("tien_thu"),tien_thu2:$report$$.csum("tien_thu2"),t_tien_thu:$report$$.csum("t_tien_thu"),phai_tra:$report$$.csum("phai_tra"),t_tien_paymentByPoints:$report$$.csum("tien_paymentByPoints"),t_lai:$report$$.csum("t_lai"),t_tien_hoa_hong:$report$$.csum("t_tien_hoa_hong"),
28
- t_tien_hoa_hong_gt:$report$$.csum("t_tien_hoa_hong_gt"),t_tien_hoa_hong_ctv:$report$$.csum("t_tien_hoa_hong_ctv"),t_tien_hoa_hong_ql:$report$$.csum("t_tien_hoa_hong_ql"),t_tien_da_thu:$report$$.csum("t_tien_da_thu"),t_tien_con_no:$report$$.csum("t_tien_con_no"),bold:!0};$thanh_toan$$.forEach($pt$$=>{$pt$$.tong_cong=$tong_cong$$[$pt$$.name]=$report$$.csum($pt$$.name)});$report$$.push($tong_cong$$);$report$$.forEach($r$$=>{$r$$.t_tien_phai_tl=$r$$.t_tien_tl+$r$$.t_tien_thue_tl});$callback$$(null,{data:$report$$,
29
- thanh_toan:$thanh_toan$$.filter($t$$=>$t$$.tong_cong)})})})};
1
+ const databanle=require("./databanle"),moment=require("moment");
2
+ function getDateRange($d_d$jscomp$1_d$jscomp$2_d$$,$field_group_by$$,$fallback_tu$$,$fallback_den$$){switch($field_group_by$$){case "nam":return $d_d$jscomp$1_d$jscomp$2_d$$=moment(new Date(Number($d_d$jscomp$1_d$jscomp$2_d$$.nam),0,1)),[$d_d$jscomp$1_d$jscomp$2_d$$.startOf("year").valueOf(),$d_d$jscomp$1_d$jscomp$2_d$$.endOf("year").valueOf()];case "quy":return $d_d$jscomp$1_d$jscomp$2_d$$=moment(new Date(Number($d_d$jscomp$1_d$jscomp$2_d$$.nam),0,1)).quarter(Number($d_d$jscomp$1_d$jscomp$2_d$$.quy)),
3
+ [$d_d$jscomp$1_d$jscomp$2_d$$.startOf("quarter").valueOf(),$d_d$jscomp$1_d$jscomp$2_d$$.endOf("quarter").valueOf()];case "thang":return $d_d$jscomp$1_d$jscomp$2_d$$=moment(new Date(Number($d_d$jscomp$1_d$jscomp$2_d$$.nam),0,1)).month(Number($d_d$jscomp$1_d$jscomp$2_d$$.thang)-1),[$d_d$jscomp$1_d$jscomp$2_d$$.startOf("month").valueOf(),$d_d$jscomp$1_d$jscomp$2_d$$.endOf("month").valueOf()];case "ngay_ct":return $d_d$jscomp$1_d$jscomp$2_d$$=moment($d_d$jscomp$1_d$jscomp$2_d$$.ngay_ct),[$d_d$jscomp$1_d$jscomp$2_d$$.startOf("day").valueOf(),
4
+ $d_d$jscomp$1_d$jscomp$2_d$$.endOf("day").valueOf()];default:return[(new Date($fallback_tu$$)).getTime(),(new Date($fallback_den$$)).getTime()]}}
5
+ function getReportDateRange($r$$){if(!$r$$.nam)return null;let $d$$=moment(new Date($r$$.nam,0,1));return $r$$.quy?($d$$=$d$$.quarter($r$$.quy),[$d$$.startOf("quarter").toDate(),$d$$.endOf("quarter").toDate()]):$r$$.thang?($d$$=$d$$.month($r$$.thang-1),[$d$$.startOf("month").toDate(),$d$$.endOf("month").toDate()]):[$d$$.startOf("year").toDate(),$d$$.endOf("year").toDate()]}
6
+ module.exports=async function($condition$$,$callback$$){try{const $field_group_by$$=$condition$$.group_by||"ngay_ct",$group_by$$=$field_group_by$$!=="ngay_ct"&&$field_group_by$$!=="nam"&&$field_group_by$$!=="ma_kho"&&$field_group_by$$!=="ma_kh"&&$field_group_by$$!=="ma_nv"?["nam",$field_group_by$$]:[$field_group_by$$];if(!$condition$$.id_app||!$condition$$.tu_ngay||!$condition$$.den_ngay)return $callback$$("B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: id_app, tu_ngay, den_ngay");
7
+ const $query$$={id_app:$condition$$.id_app,ngay_ct:{$gte:$condition$$.tu_ngay,$lte:$condition$$.den_ngay}};$condition$$.ma_dvcs&&($query$$.ma_dvcs=$condition$$.ma_dvcs);$condition$$.ma_kho&&($query$$.$or=[{ma_kho:$condition$$.ma_kho},{"details.ma_kho":$condition$$.ma_kho}]);$condition$$.ma_ct&&($query$$.ma_ct=$condition$$.ma_ct);if($condition$$.ma_kh)$query$$.ma_kh=$condition$$.ma_kh;else{var $activeFields_hhOr$$=["nh_kh","nh_kh2","nh_kh3","nh_kh4","nh_kh5"].filter($f$$=>$condition$$[$f$$]);if($activeFields_hhOr$$.length>
8
+ 0){const $groupModel$$=global.getModel("group"),$nhResults$$=await Promise.all($activeFields_hhOr$$.map($f$$=>$groupModel$$.getAllChildrenGroup($condition$$.id_app,$condition$$[$f$$],{status:!0}))),$condition_kh$$={id_app:$condition$$.id_app};$activeFields_hhOr$$.forEach(($f$$,$i$$)=>{$condition_kh$$[$f$$]={$in:$nhResults$$[$i$$]}});const $custs$$=await global.getModel("customer").find($condition_kh$$,{ma_kh:1}).lean();$query$$.ma_kh={$in:$custs$$.map($c$$=>$c$$.ma_kh)}}}if($condition$$.user_hoa_hong){const $uHH$$=
9
+ $condition$$.user_hoa_hong;$activeFields_hhOr$$=[{user_nv:$uHH$$},{user_ctv:$uHH$$},{user_ctv2:$uHH$$},{user_kho:$uHH$$},{user_gt:$uHH$$},{user_ql:$uHH$$},{"details.user_nv":$uHH$$},{"details.user_ctv":$uHH$$},{"details.user_ctv2":$uHH$$},{"details.user_kho":$uHH$$},{"details.user_gt":$uHH$$},{"details.user_ql":$uHH$$}];$query$$.$or?$query$$.$and=[{$or:$activeFields_hhOr$$}]:$query$$.$or=$activeFields_hhOr$$}const [$rs$$,$ptthanhtoans$$]=await new Promise(($resolve$$,$reject$$)=>{databanle($query$$,
10
+ ($err$$,$rs$$,$pt$$)=>$err$$?$reject$$($err$$):$resolve$$([$rs$$,$pt$$]))}),$thanh_toan$$=($ptthanhtoans$$||[]).map($pt$$=>({name:$pt$$.ma,value:$pt$$.ma,ma:$pt$$.ma,ten:$pt$$.ten}));for(const $r$$ of $rs$$)$r$$.sl_dh=1,$r$$.thang=$r$$.ngay_ct.getMonth()+1,$r$$.nam=moment($r$$.ngay_ct).year(),$r$$.quy=moment($r$$.ngay_ct).quarter();const $recordIds$$=$rs$$.filter($r$$=>$r$$._id).map($r$$=>$r$$._id),[$allNo$$,$allDaThu$$]=await Promise.all([global.getModel("tdttno").find({id_app:$condition$$.id_app,
11
+ id_ct:{$in:$recordIds$$}},{id_ct:1,tien_nt:1,tien:1}).lean(),global.getModel("tdttno_tt").find({id_app:$condition$$.id_app,id_hd:{$in:$recordIds$$}},{id_hd:1,tien:1,tien_nt:1}).lean()]),$noMap$$=new Map($allNo$$.map($n$$=>[$n$$.id_ct.toString(),$n$$])),$daThuMap$$=new Map;for(const $d$$ of $allDaThu$$){const $key$$=$d$$.id_hd.toString();$daThuMap$$.has($key$$)||$daThuMap$$.set($key$$,[]);$daThuMap$$.get($key$$).push($d$$)}for(const $r$$ of $rs$$)if($r$$.t_sl_xuat=$r$$.details.csum("sl_xuat"),$r$$.t_tien_hang=
12
+ $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_ck_hd=$r$$.tien_ck_hd||0,$r$$.t_tien_xuat=$r$$.details.csum("tien_xuat"),$r$$.t_tien_hoa_hong=$r$$.details.csum("tien_hoa_hong"),$r$$.t_tien_hoa_hong_gt=$r$$.details.csum("tien_hoa_hong_gt"),$r$$.t_tien_hoa_hong_ctv=$r$$.details.csum("tien_hoa_hong_ctv"),
13
+ $r$$.t_tien_hoa_hong_ql=$r$$.details.csum("tien_hoa_hong_ql"),$r$$.tien_freeship=$r$$.tien_freeship||0,$r$$.tien_phi_vc=$r$$.tien_phi_vc||0,$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=$r$$.details_tl.csum("tien_nhap"),$r$$.t_sl_nhap=$r$$.details_tl.csum("sl_nhap"),$r$$.t_tien_hoa_hong-=$r$$.details_tl.csum("tien_hoa_hong"),$r$$.t_tien_hoa_hong_gt-=$r$$.details_tl.csum("tien_hoa_hong_gt"),
14
+ $r$$.t_tien_hoa_hong_ctv-=$r$$.details_tl.csum("tien_hoa_hong_ctv"),$r$$.t_tien_hoa_hong_ql-=$r$$.details_tl.csum("tien_hoa_hong_ql")):($r$$.t_tien_tl=0,$r$$.t_sl_nhap=0,$r$$.t_tien_nhap=0),$r$$._id){const $idStr$$=$r$$._id.toString(),$no$$=$noMap$$.get($idStr$$);if($no$$){$r$$.t_tien_no_nt=$no$$.tien_nt;$r$$.t_tien_no=$no$$.tien;const $da_thus$$=$daThuMap$$.get($idStr$$)||[];$r$$.t_tien_da_thu=$da_thus$$.reduce(($s$$,$d$$)=>$s$$+$d$$.tien,0);$r$$.t_tien_da_thu_nt=$da_thus$$.reduce(($s$$,$d$$)=>$s$$+
15
+ $d$$.tien_nt,0)}$r$$.t_tien_con_no=($r$$.t_tien_no||0)-($r$$.t_tien_da_thu||0);$r$$.t_tien_con_no_nt=($r$$.t_tien_no_nt||0)-($r$$.t_tien_da_thu_nt||0)}const $total_fields$$=["sl_dh","t_sl_xuat","t_sl_nhap","t_tien_hang","t_tien_hang_ct","t_thue","t_tien_cp","t_tien_ck","t_tien","tien_ck_hd","tien_freeship","tien_phi_vc","tien_evoucher","tien_thu","tien_thu2","tien_paymentByPoints","t_tien_xuat","t_tien_tl","t_tien_thue_tl","t_tien_nhap","phai_tra","t_tien_hoa_hong","t_tien_hoa_hong_gt","t_tien_hoa_hong_ctv",
16
+ "t_tien_hoa_hong_ql","t_tien_da_thu","t_tien_con_no",...$thanh_toan$$.map($pt$$=>$pt$$.ma)].map($f$$=>typeof $f$$==="string"?{name:$f$$,value:$f$$}:$f$$);let $data$$=await $rs$$.asyncGroupBy([...(new Set([...$group_by$$,"ma_kh"]))],$total_fields$$);await $data$$.filter($r$$=>$r$$.ma_kh).asyncJoinModel2($condition$$.id_app,"customer",{where:"ma_kh",fields:["ngay_mua_dau_tien",{cust_date_created:"date_created"}]});for(const $r$$ of $data$$)if($r$$.t_kh=1,$r$$.cust_date_created){const [$tu_ngay$$,$den_ngay$$]=
17
+ getDateRange($r$$,$field_group_by$$,$condition$$.tu_ngay,$condition$$.den_ngay),$ngay_mua_ts$$=$r$$.ngay_mua_dau_tien?(new Date($r$$.ngay_mua_dau_tien)).getTime():null,$cust_created$$=(new Date($r$$.cust_date_created)).getTime();$r$$.mua_lan_dau=$ngay_mua_ts$$&&$ngay_mua_ts$$>=$tu_ngay$$&&$ngay_mua_ts$$<=$den_ngay$$?1:0;$r$$.kh_cu=$ngay_mua_ts$$&&$ngay_mua_ts$$<$tu_ngay$$?1:0;$r$$.kh_moi=$ngay_mua_ts$$&&$cust_created$$>=$tu_ngay$$&&$cust_created$$<=$den_ngay$$?1:0}else $r$$.mua_lan_dau=0,$r$$.kh_moi=
18
+ 0,$r$$.kh_cu=0;if($condition$$.loai_kh){const $fn$$={MUA_LAN_DAU:$r$$=>$r$$.mua_lan_dau,KH_MOI:$r$$=>$r$$.kh_moi,KH_CU:$r$$=>$r$$.kh_cu}[$condition$$.loai_kh];if($fn$$){$data$$=$data$$.filter($fn$$);const $validMaKh$$=new Set($data$$.map($r$$=>$r$$.ma_kh));$rs$$.splice(0,$rs$$.length,...$rs$$.filter($r$$=>$validMaKh$$.has($r$$.ma_kh)))}}const $extended_fields$$=[...$total_fields$$,...["kh_moi","kh_cu","t_kh","sl_dh","mua_lan_dau"].map($f$$=>({name:$f$$,value:$f$$}))];let $report$$=await $data$$.asyncGroupBy($group_by$$,
19
+ $extended_fields$$);$report$$=$report$$.sort(($a$$,$b$$)=>{for(const $field$$ of $group_by$$){const $av$$=$field$$==="ngay_ct"?moment($a$$[$field$$]).format("YYYY-MM-DD"):$a$$[$field$$],$bv$$=$field$$==="ngay_ct"?moment($b$$[$field$$]).format("YYYY-MM-DD"):$b$$[$field$$];if($av$$<$bv$$)return-1;if($av$$>$bv$$)return 1}return 0});await Promise.all([$report$$.filter($r$$=>$r$$.ma_kh).asyncJoinModel2($condition$$.id_app,"customer",{where:"ma_kh",fields:"ten_kh"}),$report$$.filter($r$$=>$r$$.ma_kho).asyncJoinModel2($condition$$.id_app,
20
+ "dmkho",{where:"ma_kho",fields:"ten_kho"})]);$report$$.forEach(($r$$,$dateRange_i$$)=>{$r$$.stt=$dateRange_i$$+1;$r$$.bold=!1;$r$$.t_phai_thu=$r$$.t_tien_hang_ct-($r$$.t_tien_ck||0)+($r$$.t_thue||0)+($r$$.tien_phi_vc||0)-($r$$.tien_freeship||0)-($r$$.tien_ck_hd||0)-($r$$.tien_evoucher||0);$r$$.t_doanh_thu=$r$$.t_tien_hang_ct-($r$$.t_tien_ck||0)+($r$$.tien_phi_vc||0)-($r$$.tien_freeship||0)-($r$$.tien_ck_hd||0)-($r$$.tien_evoucher||0);$r$$.t_lai=$r$$.t_doanh_thu-$r$$.t_tien_xuat-($r$$.t_tien_tl-$r$$.t_tien_nhap)-
21
+ ($r$$.t_tien_cp||0);$r$$.t_doanh_thu_thuan=$r$$.t_doanh_thu-$r$$.t_tien_tl;$r$$.t_tien_thu=$thanh_toan$$.reduce(($s$$,$pt$$)=>$s$$+($r$$[$pt$$.name]||0),0);$r$$.t_tien_paymentByPoints=$r$$.tien_paymentByPoints||0;$r$$.t_tien_phai_tl=$r$$.t_tien_tl+$r$$.t_tien_thue_tl;($dateRange_i$$=getReportDateRange($r$$))?[$r$$.tu_ngay,$r$$.den_ngay]=$dateRange_i$$:($r$$.tu_ngay=$condition$$.tu_ngay,$r$$.den_ngay=$condition$$.den_ngay)});const $tong_cong$$={[$group_by$$[0]]:"T\u1ed5ng c\u1ed9ng",bold:!0,mua_lan_dau:$report$$.csum("mua_lan_dau"),
22
+ kh_moi:$report$$.csum("kh_moi"),kh_cu:$report$$.csum("kh_cu"),t_kh:$report$$.csum("t_kh"),sl_dh:$report$$.csum("sl_dh"),t_sl_xuat:$report$$.csum("t_sl_xuat"),t_sl_nhap:$report$$.csum("t_sl_nhap"),t_tien_hang:$report$$.csum("t_tien_hang"),t_tien_hang_ct:$report$$.csum("t_tien_hang_ct"),t_thue:$report$$.csum("t_thue"),t_tien_cp:$report$$.csum("t_tien_cp"),t_tien_ck:$report$$.csum("t_tien_ck"),t_tien:$report$$.csum("t_tien"),tien_ck_hd:$report$$.csum("tien_ck_hd"),tien_phi_vc:$report$$.csum("tien_phi_vc"),
23
+ tien_freeship:$report$$.csum("tien_freeship"),t_tien_tl:$report$$.csum("t_tien_tl"),t_tien_thue_tl:$report$$.csum("t_tien_thue_tl"),t_tien_xuat:$report$$.csum("t_tien_xuat"),t_tien_nhap:$report$$.csum("t_tien_nhap"),t_phai_thu:$report$$.csum("t_phai_thu"),t_doanh_thu:$report$$.csum("t_doanh_thu"),t_doanh_thu_thuan:$report$$.csum("t_doanh_thu_thuan"),tien_evoucher:$report$$.csum("tien_evoucher"),tien_thu:$report$$.csum("tien_thu"),tien_thu2:$report$$.csum("tien_thu2"),t_tien_thu:$report$$.csum("t_tien_thu"),
24
+ phai_tra:$report$$.csum("phai_tra"),t_tien_paymentByPoints:$report$$.csum("tien_paymentByPoints"),t_lai:$report$$.csum("t_lai"),t_tien_hoa_hong:$report$$.csum("t_tien_hoa_hong"),t_tien_hoa_hong_gt:$report$$.csum("t_tien_hoa_hong_gt"),t_tien_hoa_hong_ctv:$report$$.csum("t_tien_hoa_hong_ctv"),t_tien_hoa_hong_ql:$report$$.csum("t_tien_hoa_hong_ql"),t_tien_da_thu:$report$$.csum("t_tien_da_thu"),t_tien_con_no:$report$$.csum("t_tien_con_no")};$thanh_toan$$.forEach($pt$$=>{$pt$$.tong_cong=$tong_cong$$[$pt$$.name]=
25
+ $report$$.csum($pt$$.name)});$report$$.push($tong_cong$$);$report$$.forEach($r$$=>{$r$$.t_tien_phai_tl=$r$$.t_tien_tl+$r$$.t_tien_thue_tl});$callback$$(null,{data:$report$$,thanh_toan:$thanh_toan$$.filter($t$$=>$t$$.tong_cong)})}catch($err$$){$callback$$($err$$)}};
@@ -1,5 +1,5 @@
1
1
  const bgaccs=require("./dktt"),bgcustaccs=require("./dkcn"),async=require("async");
2
- module.exports=async function($condition$$,$callback$$,$options$$={}){try{if(!$condition$$||!$condition$$.ngay||!$condition$$.id_app)throw Error("ngay and id_app required");let $bu_tru$$=$condition$$.bu_tru;$bu_tru$$||=!1;$condition$$.groupBy=$condition$$.groupBy||["tk"];const $data$$=await new Promise(($resolve$$,$reject$$)=>{async.parallel({tt:function($callback$$){bgaccs({...$condition$$},function($error$$,$report$$){$error$$?$callback$$($error$$):$callback$$(null,$report$$)},{model:"socaitt",
3
- queryByDateHour:$options$$.queryByDateHour})},cn:function($callback$$){let $_group$$=["tk","ma_kh"];$bu_tru$$===!0&&($_group$$=["tk"]);let $_condition$$=Object.assign({},$condition$$);$_condition$$.groupBy=$_group$$;bgcustaccs($_condition$$,function($error$$,$result$$){$error$$?$callback$$($error$$):($bu_tru$$&&$result$$.forEach(function($r$$){$r$$.du_no00-=$r$$.du_co00;$r$$.du_no_nt00-=$r$$.du_co_nt00;$r$$.du_no00<0?($r$$.du_co00=Math.abs($r$$.du_no00),$r$$.du_no00=0):$r$$.du_co00=0;$r$$.du_no_nt00<
4
- 0?($r$$.du_co_nt00=Math.abs($r$$.du_no_nt00),$r$$.du_no_nt00=0):$r$$.du_co_nt00=0}),$callback$$(null,$result$$))},{model:"socaitt",queryByDateHour:$options$$.queryByDateHour})}},function($error$jscomp$4_report$$,$results$$){if($error$jscomp$4_report$$)return $reject$$($error$jscomp$4_report$$);$error$jscomp$4_report$$=$results$$.tt.concat($results$$.cn);$resolve$$($error$jscomp$4_report$$)})});return $callback$$?$callback$$(null,$data$$):$data$$}catch($e$$){if($callback$$)return $callback$$($e$$);
2
+ module.exports=async function($condition$$,$callback$$,$options$$={}){try{if(!$condition$$||!$condition$$.ngay||!$condition$$.id_app)throw Error("ngay and id_app required");let $bu_tru$$=$condition$$.bu_tru;$bu_tru$$||=!1;$condition$$.groupBy=$condition$$.groupBy||$condition$$.group_by||["tk"];const $data$$=await new Promise(($resolve$$,$reject$$)=>{async.parallel({tt:function($callback$$){bgaccs({...$condition$$},function($error$$,$report$$){$error$$?$callback$$($error$$):$callback$$(null,$report$$)},
3
+ {model:"socaitt",queryByDateHour:$options$$.queryByDateHour})},cn:function($callback$$){let $_group$$=["tk","ma_kh"];$bu_tru$$===!0&&($_group$$=["tk"]);let $_condition$$=Object.assign({},$condition$$);$_condition$$.groupBy=$_group$$;bgcustaccs($_condition$$,function($error$$,$result$$){$error$$?$callback$$($error$$):($bu_tru$$&&$result$$.forEach(function($r$$){$r$$.du_no00-=$r$$.du_co00;$r$$.du_no_nt00-=$r$$.du_co_nt00;$r$$.du_no00<0?($r$$.du_co00=Math.abs($r$$.du_no00),$r$$.du_no00=0):$r$$.du_co00=
4
+ 0;$r$$.du_no_nt00<0?($r$$.du_co_nt00=Math.abs($r$$.du_no_nt00),$r$$.du_no_nt00=0):$r$$.du_co_nt00=0}),$callback$$(null,$result$$))},{model:"socaitt",queryByDateHour:$options$$.queryByDateHour})}},function($error$jscomp$4_report$$,$results$$){if($error$jscomp$4_report$$)return $reject$$($error$jscomp$4_report$$);$error$jscomp$4_report$$=$results$$.tt.concat($results$$.cn);$resolve$$($error$jscomp$4_report$$)})});return $callback$$?$callback$$(null,$data$$):$data$$}catch($e$$){if($callback$$)return $callback$$($e$$);
5
5
  throw $e$$;}};
@@ -1,12 +1,12 @@
1
1
  const sokho=global.getModel("sokho"),_=require("lodash"),utils=require("./utils"),moment=require("moment");
2
- module.exports=async function($condition$$,$fn$$){$fn$$||=()=>{};try{!$condition$$.ngay&&$condition$$.tu_ngay&&($condition$$.ngay=$condition$$.tu_ngay);if(!$condition$$||!$condition$$.ngay||!$condition$$.id_app)return $fn$$("B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: ngay, id_app");const {id_app:$id_app$$,ma_dvcs:$ma_dvcs$$,ma_kho:$ma_kho$$}=$condition$$;let $ma_vt$$=$condition$$.ma_vt;_.isArray($ma_vt$$)&&($ma_vt$$={$in:$ma_vt$$});const $ngay$$=moment($condition$$.ngay).startOf("date").toDate(),
3
- [$app$$,$lastLockData$$]=await Promise.all([global.getModel("app").findOne({_id:$id_app$$},{ngay_ks:1}).lean(),global.getModel("cdvttheongay").findOne({id_app:$id_app$$,den_ngay:{$lte:moment($ngay$$).startOf("date").toDate()}},{den_ngay:1}).sort({den_ngay:-1}).lean()]);if(!$app$$)return $fn$$("C\u00f4ng ty kh\u00f4ng t\u1ed3n t\u1ea1i");let $ngay_ks$$=$lastLockData$$?$lastLockData$$.den_ngay:null;$ngay_ks$$&&=moment($ngay_ks$$).endOf("date").toDate();var $merge_ngay_tinh_dn$$=moment($condition$$.ngay).startOf("date").toDate();
4
- let $ngay_dn$$=moment($merge_ngay_tinh_dn$$).startOf("year").toDate(),$nam$$,$CdvtModel$$;!$ngay_ks$$||$ngay_ks$$<$ngay_dn$$?($CdvtModel$$=global.getModel("cdvt"),$nam$$=$merge_ngay_tinh_dn$$.getFullYear()):($CdvtModel$$=global.getModel("cdvttheongay"),$ngay_dn$$=moment($ngay_ks$$).startOf("date").add(1,"days").toDate());const $buildFilter$$=($base$$={})=>{const $q$$={...$base$$};$ma_vt$$&&($q$$.ma_vt=$ma_vt$$);$ma_kho$$&&($q$$.ma_kho=$ma_kho$$);$ma_dvcs$$&&($q$$.ma_dvcs=$ma_dvcs$$);["ma_lo","han_sd",
5
- "ma_tt1","ma_tt2","ma_tt3"].forEach($f$$=>{$condition$$[$f$$]&&($q$$[$f$$]=$condition$$[$f$$])});return $q$$},$pDauKy$$=(async()=>{var $c_dk_results$$={id_app:$id_app$$};$nam$$?$c_dk_results$$.nam=$nam$$:$c_dk_results$$.den_ngay=$ngay_ks$$;Object.assign($c_dk_results$$,$buildFilter$$());$c_dk_results$$=await $CdvtModel$$.find($c_dk_results$$).lean();$c_dk_results$$.length>0&&await $c_dk_results$$.asyncJoinModel2($id_app$$,"dmvt",{where:"ma_vt",fields:["tk_vt","ma_nvt","ma_nvt2","ma_nvt3","ma_nvt4"]});
6
- return $c_dk_results$$})(),$pPhatSinh$$=(async()=>{const $query$$={id_app:$id_app$$,ngay_ct:{$gte:$ngay_dn$$,$lt:$ngay$$}};Object.assign($query$$,$buildFilter$$());return sokho.aggregate([{$match:$query$$},{$group:{_id:{ma_vt:"$ma_vt",ma_kho:"$ma_kho",ma_dvcs:"$ma_dvcs",ma_lo:"$ma_lo",han_sd:"$han_sd",ma_tt1:"$ma_tt1",ma_tt2:"$ma_tt2",ma_tt3:"$ma_tt3"},sl_nhap:{$sum:"$sl_nhap_qd"},sl_xuat:{$sum:"$sl_xuat_qd"},tien_nhap:{$sum:"$tien_nhap"},tien_xuat:{$sum:"$tien_xuat"}}},{$project:{_id:0,ma_vt:"$_id.ma_vt",
7
- ma_kho:"$_id.ma_kho",ma_dvcs:"$_id.ma_dvcs",ma_lo:"$_id.ma_lo",han_sd:"$_id.han_sd",ma_tt1:"$_id.ma_tt1",ma_tt2:"$_id.ma_tt2",ma_tt3:"$_id.ma_tt3",sl_nhap:1,sl_xuat:1,tien_nhap:1,tien_xuat:1}}])})(),[$dnData$$,$psData$$]=await Promise.all([$pDauKy$$,$pPhatSinh$$]);let $groupBy$$=$condition$$.groupBy||$condition$$.groupby||["ma_vt"];if(_.isString($groupBy$$))try{$groupBy$$=$groupBy$$.includes("[")?JSON.parse($groupBy$$):$groupBy$$.split(",")}catch($e$$){$groupBy$$=["ma_vt"]}if($groupBy$$.some($field$$=>
8
- ["ma_nvt","ma_nvt2","ma_nvt3","ma_nvt4"].includes($field$$))&&$psData$$.length>0){const $distinctMaVt$$=[...(new Set($psData$$.map($d$$=>$d$$.ma_vt)))],$listDmvt$$=await global.getModel("dmvt").find({id_app:$id_app$$,ma_vt:{$in:$distinctMaVt$$}},{ma_vt:1,ma_nvt:1,ma_nvt2:1,ma_nvt3:1,ma_nvt4:1}).lean(),$dmvtMap$$=new Map;$listDmvt$$.forEach($d$$=>$dmvtMap$$.set($d$$.ma_vt,$d$$));$psData$$.forEach($p$$=>{const $info$$=$dmvtMap$$.get($p$$.ma_vt);$info$$&&($p$$.ma_nvt=$info$$.ma_nvt,$p$$.ma_nvt2=$info$$.ma_nvt2,
9
- $p$$.ma_nvt3=$info$$.ma_nvt3,$p$$.ma_nvt4=$info$$.ma_nvt4)})}const $dataMap$$=new Map,$getGroupKey$$=$item$$=>$groupBy$$.map($k$$=>$item$$[$k$$]||"").join("||");$merge_ngay_tinh_dn$$=($JSCompiler_temp_const$jscomp$0$$,$type$$)=>{if($JSCompiler_temp_const$jscomp$0$$)for(const $item$$ of $JSCompiler_temp_const$jscomp$0$$){const $key$$=$getGroupKey$$($item$$);if(!$dataMap$$.has($key$$)){$JSCompiler_temp_const$jscomp$0$$=$dataMap$$;var $JSCompiler_temp_const$$=$JSCompiler_temp_const$jscomp$0$$.set;const $obj$$=
10
- _.pick($item$$,$groupBy$$);$obj$$.ton00=0;$obj$$.du00=0;$obj$$.sl_nhap=0;$obj$$.sl_xuat=0;$obj$$.tien_nhap=0;$obj$$.tien_xuat=0;$JSCompiler_temp_const$$.call($JSCompiler_temp_const$jscomp$0$$,$key$$,$obj$$)}$JSCompiler_temp_const$jscomp$0$$=$dataMap$$.get($key$$);$type$$==="dn"?($JSCompiler_temp_const$jscomp$0$$.ton00+=$item$$.ton00||0,$JSCompiler_temp_const$jscomp$0$$.du00+=$item$$.du00||0):$type$$==="ps"&&($JSCompiler_temp_const$jscomp$0$$.sl_nhap+=$item$$.sl_nhap||0,$JSCompiler_temp_const$jscomp$0$$.sl_xuat+=
11
- $item$$.sl_xuat||0,$JSCompiler_temp_const$jscomp$0$$.tien_nhap+=$item$$.tien_nhap||0,$JSCompiler_temp_const$jscomp$0$$.tien_xuat+=$item$$.tien_xuat||0)}};$merge_ngay_tinh_dn$$($dnData$$,"dn");$merge_ngay_tinh_dn$$($psData$$,"ps");const $finalResult$$=Array.from($dataMap$$.values()).map($r$$=>{$r$$.ton00=utils.round($r$$.ton00+$r$$.sl_nhap-$r$$.sl_xuat,4);$r$$.du00=utils.round($r$$.du00,0)+utils.round($r$$.tien_nhap,0)-utils.round($r$$.tien_xuat,0);$r$$.sl_nhap=0;$r$$.sl_xuat=0;$r$$.tien_nhap=0;$r$$.tien_xuat=
12
- 0;return $r$$});$fn$$(null,$finalResult$$);return $finalResult$$}catch($error$$){throw $fn$$($error$$),$error$$;}};
2
+ module.exports=async function($condition$$,$fn$$){$fn$$||=()=>{};try{!$condition$$.ngay&&$condition$$.tu_ngay&&($condition$$.ngay=$condition$$.tu_ngay);if(!$condition$$||!$condition$$.ngay||!$condition$$.id_app)return $fn$$("B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: ngay, id_app");const {id_app:$id_app$$,ma_dvcs:$ma_dvcs$$,ma_kho:$ma_kho$$,ma_kh:$ma_kh$$}=$condition$$;let $ma_vt$$=$condition$$.ma_vt;_.isArray($ma_vt$$)&&($ma_vt$$={$in:$ma_vt$$});let $ds_ma_kho$$;$ma_kho$$&&
3
+ (Array.isArray($ma_kho$$)?$ds_ma_kho$$=[...$ma_kho$$]:typeof $ma_kho$$=="string"&&($ds_ma_kho$$=await global.getModel("dmkho").getAllChildrenGroup($id_app$$,$ma_kho$$)));const $ngay$$=moment($condition$$.ngay).startOf("date").toDate(),[$app$$,$lastLockData$$]=await Promise.all([global.getModel("app").findOne({_id:$id_app$$},{ngay_ks:1}).lean(),global.getModel("cdvttheongay").findOne({id_app:$id_app$$,den_ngay:{$lte:moment($ngay$$).startOf("date").toDate()}},{den_ngay:1}).sort({den_ngay:-1}).lean()]);
4
+ if(!$app$$)return $fn$$("C\u00f4ng ty kh\u00f4ng t\u1ed3n t\u1ea1i");let $ngay_ks$$=$lastLockData$$?$lastLockData$$.den_ngay:null;$ngay_ks$$&&=moment($ngay_ks$$).endOf("date").toDate();var $merge_ngay_tinh_dn$$=moment($condition$$.ngay).startOf("date").toDate();let $ngay_dn$$=moment($merge_ngay_tinh_dn$$).startOf("year").toDate(),$nam$$,$CdvtModel$$;!$ngay_ks$$||$ngay_ks$$<$ngay_dn$$?($CdvtModel$$=global.getModel("cdvt"),$nam$$=$merge_ngay_tinh_dn$$.getFullYear()):($CdvtModel$$=global.getModel("cdvttheongay"),
5
+ $ngay_dn$$=moment($ngay_ks$$).startOf("date").add(1,"days").toDate());const $buildFilter$$=($base$$={})=>{const $q$$={...$base$$};$ma_vt$$&&($q$$.ma_vt=$ma_vt$$);$ds_ma_kho$$?$q$$.ma_kho={$in:$ds_ma_kho$$}:$condition$$.ma_kho&&($q$$.ma_kho=$condition$$.ma_kho);$ma_kh$$&&($q$$.ma_kh=$ma_kh$$);$ma_dvcs$$&&($q$$.ma_dvcs=$ma_dvcs$$);["ma_lo","han_sd","ma_tt1","ma_tt2","ma_tt3"].forEach($f$$=>{$condition$$[$f$$]&&($q$$[$f$$]=$condition$$[$f$$])});return $q$$},$pDauKy$$=(async()=>{var $c_dk_results$$={id_app:$id_app$$};
6
+ $nam$$?$c_dk_results$$.nam=$nam$$:$c_dk_results$$.den_ngay=$ngay_ks$$;Object.assign($c_dk_results$$,$buildFilter$$());$c_dk_results$$=await $CdvtModel$$.find($c_dk_results$$).lean();$c_dk_results$$.length>0&&await $c_dk_results$$.asyncJoinModel2($id_app$$,"dmvt",{where:"ma_vt",fields:["tk_vt","ma_nvt","ma_nvt2","ma_nvt3","ma_nvt4"]});return $c_dk_results$$})(),$pPhatSinh$$=(async()=>{const $query$$={id_app:$id_app$$,ngay_ct:{$gte:$ngay_dn$$,$lt:$ngay$$}};Object.assign($query$$,$buildFilter$$());return sokho.aggregate([{$match:$query$$},
7
+ {$group:{_id:{ma_vt:"$ma_vt",ma_kho:"$ma_kho",ma_dvcs:"$ma_dvcs",ma_lo:"$ma_lo",han_sd:"$han_sd",ma_tt1:"$ma_tt1",ma_tt2:"$ma_tt2",ma_tt3:"$ma_tt3"},sl_nhap:{$sum:"$sl_nhap_qd"},sl_xuat:{$sum:"$sl_xuat_qd"},tien_nhap:{$sum:"$tien_nhap"},tien_xuat:{$sum:"$tien_xuat"}}},{$project:{_id:0,ma_vt:"$_id.ma_vt",ma_kho:"$_id.ma_kho",ma_dvcs:"$_id.ma_dvcs",ma_lo:"$_id.ma_lo",han_sd:"$_id.han_sd",ma_tt1:"$_id.ma_tt1",ma_tt2:"$_id.ma_tt2",ma_tt3:"$_id.ma_tt3",sl_nhap:1,sl_xuat:1,tien_nhap:1,tien_xuat:1}}])})(),
8
+ [$dnData$$,$psData$$]=await Promise.all([$pDauKy$$,$pPhatSinh$$]);let $groupBy$$=$condition$$.groupBy||$condition$$.groupby||["ma_vt"];if(_.isString($groupBy$$))try{$groupBy$$=$groupBy$$.includes("[")?JSON.parse($groupBy$$):$groupBy$$.split(",")}catch($e$$){$groupBy$$=["ma_vt"]}if($groupBy$$.some($field$$=>["ma_nvt","ma_nvt2","ma_nvt3","ma_nvt4"].includes($field$$))&&$psData$$.length>0){const $distinctMaVt$$=[...(new Set($psData$$.map($d$$=>$d$$.ma_vt)))],$listDmvt$$=await global.getModel("dmvt").find({id_app:$id_app$$,
9
+ ma_vt:{$in:$distinctMaVt$$}},{ma_vt:1,ma_nvt:1,ma_nvt2:1,ma_nvt3:1,ma_nvt4:1}).lean(),$dmvtMap$$=new Map;$listDmvt$$.forEach($d$$=>$dmvtMap$$.set($d$$.ma_vt,$d$$));$psData$$.forEach($p$$=>{const $info$$=$dmvtMap$$.get($p$$.ma_vt);$info$$&&($p$$.ma_nvt=$info$$.ma_nvt,$p$$.ma_nvt2=$info$$.ma_nvt2,$p$$.ma_nvt3=$info$$.ma_nvt3,$p$$.ma_nvt4=$info$$.ma_nvt4)})}const $dataMap$$=new Map,$getGroupKey$$=$item$$=>$groupBy$$.map($k$$=>$item$$[$k$$]||"").join("||");$merge_ngay_tinh_dn$$=($JSCompiler_temp_const$jscomp$0$$,
10
+ $type$$)=>{if($JSCompiler_temp_const$jscomp$0$$)for(const $item$$ of $JSCompiler_temp_const$jscomp$0$$){const $key$$=$getGroupKey$$($item$$);if(!$dataMap$$.has($key$$)){$JSCompiler_temp_const$jscomp$0$$=$dataMap$$;var $JSCompiler_temp_const$$=$JSCompiler_temp_const$jscomp$0$$.set;const $obj$$=_.pick($item$$,$groupBy$$);$obj$$.ton00=0;$obj$$.du00=0;$obj$$.sl_nhap=0;$obj$$.sl_xuat=0;$obj$$.tien_nhap=0;$obj$$.tien_xuat=0;$JSCompiler_temp_const$$.call($JSCompiler_temp_const$jscomp$0$$,$key$$,$obj$$)}$JSCompiler_temp_const$jscomp$0$$=
11
+ $dataMap$$.get($key$$);$type$$==="dn"?($JSCompiler_temp_const$jscomp$0$$.ton00+=$item$$.ton00||0,$JSCompiler_temp_const$jscomp$0$$.du00+=$item$$.du00||0):$type$$==="ps"&&($JSCompiler_temp_const$jscomp$0$$.sl_nhap+=$item$$.sl_nhap||0,$JSCompiler_temp_const$jscomp$0$$.sl_xuat+=$item$$.sl_xuat||0,$JSCompiler_temp_const$jscomp$0$$.tien_nhap+=$item$$.tien_nhap||0,$JSCompiler_temp_const$jscomp$0$$.tien_xuat+=$item$$.tien_xuat||0)}};$merge_ngay_tinh_dn$$($dnData$$,"dn");$merge_ngay_tinh_dn$$($psData$$,"ps");
12
+ const $finalResult$$=Array.from($dataMap$$.values()).map($r$$=>{$r$$.ton00=utils.round($r$$.ton00+$r$$.sl_nhap-$r$$.sl_xuat,4);$r$$.du00=utils.round($r$$.du00,0)+utils.round($r$$.tien_nhap,0)-utils.round($r$$.tien_xuat,0);$r$$.sl_nhap=0;$r$$.sl_xuat=0;$r$$.tien_nhap=0;$r$$.tien_xuat=0;return $r$$});$fn$$(null,$finalResult$$);return $finalResult$$}catch($error$$){throw $fn$$($error$$),$error$$;}};
@@ -1,7 +1,8 @@
1
1
  const cdvt=global.getModel("cdvtnpp"),sokho=global.getModel("sokhonpp"),async=require("async"),underscore=require("underscore"),utils=require("./utils"),moment=require("moment");
2
- module.exports=function($condition$$,$fn$$){!$condition$$.ngay&&$condition$$.tu_ngay&&($condition$$.ngay=$condition$$.tu_ngay);if($condition$$&&$condition$$.ngay&&$condition$$.id_app){var $ma_dvcs$$=$condition$$.ma_dvcs,$ma_kho$$=$condition$$.ma_kho,$ma_vt$$=$condition$$.ma_vt;underscore.isArray($ma_vt$$)&&($ma_vt$$={$in:$ma_vt$$});var $ngay$$=moment(new Date($condition$$.ngay)).startOf("date").toDate(),$nam$$=$ngay$$.getFullYear(),$ngay_dn$$=moment($ngay$$).startOf("year").toDate(),$id_app$$=$condition$$.id_app;
3
- async.series({dn:$callback$$=>{setImmediate(()=>{const $c_dk$$={id_app:$id_app$$,nam:$nam$$};$ma_vt$$&&($c_dk$$.ma_vt=$ma_vt$$);$ma_kho$$&&($c_dk$$.ma_kho=$ma_kho$$);$ma_dvcs$$&&($c_dk$$.ma_dvcs=$ma_dvcs$$);$condition$$.ma_lo&&($c_dk$$.ma_lo=$condition$$.ma_lo);$condition$$.han_sd&&($c_dk$$.han_sd=$condition$$.han_sd);$condition$$.ma_tt1&&($c_dk$$.ma_tt1=$condition$$.ma_tt1);$condition$$.ma_tt2&&($c_dk$$.ma_tt2=$condition$$.ma_tt2);$condition$$.ma_tt3&&($c_dk$$.ma_tt3=$condition$$.ma_tt3);$condition$$.ma_kh&&
4
- ($c_dk$$.ma_kh=$condition$$.ma_kh);cdvt.find($c_dk$$).lean().then($results$$=>{$callback$$(null,$results$$)}).catch($error$$=>{$callback$$({message:$error$$.message})})})},ps:$callback$$=>{setImmediate(()=>{const $query$$={id_app:$id_app$$,ngay_ct:{$gte:$ngay_dn$$,$lt:$ngay$$}};$ma_vt$$&&($query$$.ma_vt=$ma_vt$$);$ma_kho$$&&($query$$.ma_kho=$ma_kho$$);$ma_dvcs$$&&($query$$.ma_dvcs=$ma_dvcs$$);$condition$$.ma_lo&&($query$$.ma_lo=$condition$$.ma_lo);$condition$$.han_sd&&($query$$.han_sd=$condition$$.han_sd);
5
- $condition$$.ma_tt1&&($query$$.ma_tt1=$condition$$.ma_tt1);$condition$$.ma_tt2&&($query$$.ma_tt2=$condition$$.ma_tt2);$condition$$.ma_tt3&&($query$$.ma_tt3=$condition$$.ma_tt3);$condition$$.ma_kh&&($query$$.ma_kh=$condition$$.ma_kh);sokho.find($query$$).lean().then($pss$$=>{$pss$$=$pss$$.map($ps$$=>{$ps$$.sl_nhap=utils.round($ps$$.sl_nhap_qd,4);$ps$$.sl_xuat=utils.round($ps$$.sl_xuat_qd,4);return $ps$$});$callback$$(null,$pss$$)}).catch($error$$=>{$callback$$({message:$error$$.message})})})}},($data_error$$,
6
- $groupBy_results$$)=>{if($data_error$$)return $fn$$($data_error$$);$data_error$$=$groupBy_results$$.dn.concat($groupBy_results$$.ps);($groupBy_results$$=$condition$$.groupBy||$condition$$.groupby)||($groupBy_results$$=["ma_vt"]);if(underscore.isString($groupBy_results$$))if($groupBy_results$$.indexOf("[")>=0)try{$groupBy_results$$=JSON.parse($groupBy_results$$)}catch($e$$){Logger.error($e$$)}else $groupBy_results$$=$groupBy_results$$.split(",");$data_error$$.groupBy($groupBy_results$$,"sl_nhap sl_xuat ton00 du00 tien_nhap tien_xuat".split(" "),
7
- ($e$$,$groups$$)=>{if($e$$)return $fn$$($e$$);setImmediate(()=>{for(let $r$$ of $groups$$)$r$$.ton00=utils.round($r$$.ton00+$r$$.sl_nhap-$r$$.sl_xuat,4),$r$$.du00=utils.round($r$$.du00,0)+utils.round($r$$.tien_nhap,0)-utils.round($r$$.tien_xuat,0),$r$$.sl_nhap=0,$r$$.sl_xuat=0,$r$$.tien_nhap=0,$r$$.tien_xuat=0;$fn$$(null,$groups$$)})})})}else $fn$$("B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: ngay,id_app")};
2
+ module.exports=async function($condition$$,$fn$$){!$condition$$.ngay&&$condition$$.tu_ngay&&($condition$$.ngay=$condition$$.tu_ngay);if($condition$$&&$condition$$.ngay&&$condition$$.id_app){var $id_app$$=$condition$$.id_app,$ma_dvcs$$=$condition$$.ma_dvcs,$ma_kho$$=$condition$$.ma_kho,$ds_ma_kho$$;$ma_kho$$&&(Array.isArray($ma_kho$$)?$ds_ma_kho$$=[...$ma_kho$$]:typeof $ma_kho$$=="string"&&($ds_ma_kho$$=await global.getModel("dmkho").getAllChildrenGroup($id_app$$,$ma_kho$$)));var $ma_vt$$=$condition$$.ma_vt;
3
+ underscore.isArray($ma_vt$$)&&($ma_vt$$={$in:$ma_vt$$});var $ngay$$=moment(new Date($condition$$.ngay)).startOf("date").toDate(),$nam$$=$ngay$$.getFullYear(),$ngay_dn$$=moment($ngay$$).startOf("year").toDate();async.series({dn:$callback$$=>{setImmediate(()=>{const $c_dk$$={id_app:$id_app$$,nam:$nam$$};$ma_vt$$&&($c_dk$$.ma_vt=$ma_vt$$);$ds_ma_kho$$&&($c_dk$$.ma_kho={$in:$ds_ma_kho$$});$ma_dvcs$$&&($c_dk$$.ma_dvcs=$ma_dvcs$$);$condition$$.ma_lo&&($c_dk$$.ma_lo=$condition$$.ma_lo);$condition$$.han_sd&&
4
+ ($c_dk$$.han_sd=$condition$$.han_sd);$condition$$.ma_tt1&&($c_dk$$.ma_tt1=$condition$$.ma_tt1);$condition$$.ma_tt2&&($c_dk$$.ma_tt2=$condition$$.ma_tt2);$condition$$.ma_tt3&&($c_dk$$.ma_tt3=$condition$$.ma_tt3);$condition$$.ma_kh&&($c_dk$$.ma_kh=$condition$$.ma_kh);cdvt.find($c_dk$$).lean().then($results$$=>{$callback$$(null,$results$$)}).catch($error$$=>{$callback$$({message:$error$$.message})})})},ps:$callback$$=>{setImmediate(()=>{const $query$$={id_app:$id_app$$,ngay_ct:{$gte:$ngay_dn$$,$lt:$ngay$$}};
5
+ $ma_vt$$&&($query$$.ma_vt=$ma_vt$$);$ds_ma_kho$$?$query$$.ma_kho={$in:$ds_ma_kho$$}:$condition$$.ma_kho&&($query$$.ma_kho=$condition$$.ma_kho);$ma_dvcs$$&&($query$$.ma_dvcs=$ma_dvcs$$);$condition$$.ma_lo&&($query$$.ma_lo=$condition$$.ma_lo);$condition$$.han_sd&&($query$$.han_sd=$condition$$.han_sd);$condition$$.ma_tt1&&($query$$.ma_tt1=$condition$$.ma_tt1);$condition$$.ma_tt2&&($query$$.ma_tt2=$condition$$.ma_tt2);$condition$$.ma_tt3&&($query$$.ma_tt3=$condition$$.ma_tt3);$condition$$.ma_kh&&($query$$.ma_kh=
6
+ $condition$$.ma_kh);sokho.find($query$$).lean().then($pss$$=>{$pss$$=$pss$$.map($ps$$=>{$ps$$.sl_nhap=utils.round($ps$$.sl_nhap_qd,4);$ps$$.sl_xuat=utils.round($ps$$.sl_xuat_qd,4);return $ps$$});$callback$$(null,$pss$$)}).catch($error$$=>{$callback$$({message:$error$$.message})})})}},($data_error$$,$groupBy_results$$)=>{if($data_error$$)return $fn$$($data_error$$);$data_error$$=$groupBy_results$$.dn.concat($groupBy_results$$.ps);($groupBy_results$$=$condition$$.groupBy||$condition$$.groupby)||($groupBy_results$$=
7
+ ["ma_vt"]);if(underscore.isString($groupBy_results$$))if($groupBy_results$$.indexOf("[")>=0)try{$groupBy_results$$=JSON.parse($groupBy_results$$)}catch($e$$){Logger.error($e$$)}else $groupBy_results$$=$groupBy_results$$.split(",");$data_error$$.groupBy($groupBy_results$$,"sl_nhap sl_xuat ton00 du00 tien_nhap tien_xuat".split(" "),($e$$,$groups$$)=>{if($e$$)return $fn$$($e$$);setImmediate(()=>{for(let $r$$ of $groups$$)$r$$.ton00=utils.round($r$$.ton00+$r$$.sl_nhap-$r$$.sl_xuat,4),$r$$.du00=utils.round($r$$.du00,
8
+ 0)+utils.round($r$$.tien_nhap,0)-utils.round($r$$.tien_xuat,0),$r$$.sl_nhap=0,$r$$.sl_xuat=0,$r$$.tien_nhap=0,$r$$.tien_xuat=0;$fn$$(null,$groups$$)})})})}else $fn$$("B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: ngay,id_app")};
@@ -1,7 +1,8 @@
1
1
  const cdvt=global.getModel("cdvt"),sokho=global.getModel("sokhott"),async=require("async"),underscore=require("underscore"),utils=require("./utils"),moment=require("moment");
2
- module.exports=function($condition$$,$fn$$){!$condition$$.ngay&&$condition$$.tu_ngay&&($condition$$.ngay=$condition$$.tu_ngay);if($condition$$&&$condition$$.ngay&&$condition$$.id_app){var $ma_dvcs$$=$condition$$.ma_dvcs,$ma_kho$$=$condition$$.ma_kho,$ma_vt$$=$condition$$.ma_vt;underscore.isArray($ma_vt$$)&&($ma_vt$$={$in:$ma_vt$$});var $ngay$$=moment(new Date($condition$$.ngay)).startOf("date").toDate(),$nam$$=$ngay$$.getFullYear(),$ngay_dn$$=moment($ngay$$).startOf("year").toDate(),$id_app$$=$condition$$.id_app;
3
- async.series({dn:$callback$$=>{setImmediate(()=>{const $c_dk$$={id_app:$id_app$$,nam:$nam$$};$ma_vt$$&&($c_dk$$.ma_vt=$ma_vt$$);$ma_kho$$&&($c_dk$$.ma_kho=$ma_kho$$);$ma_dvcs$$&&($c_dk$$.ma_dvcs=$ma_dvcs$$);$condition$$.ma_lo&&($c_dk$$.ma_lo=$condition$$.ma_lo);$condition$$.han_sd&&($c_dk$$.han_sd=$condition$$.han_sd);$condition$$.ma_tt1&&($c_dk$$.ma_tt1=$condition$$.ma_tt1);$condition$$.ma_tt2&&($c_dk$$.ma_tt2=$condition$$.ma_tt2);$condition$$.ma_tt3&&($c_dk$$.ma_tt3=$condition$$.ma_tt3);cdvt.find($c_dk$$).lean().then($results$$=>
4
- {$callback$$(null,$results$$)}).catch($error$$=>{$callback$$({message:$error$$.message})})})},ps:$callback$$=>{setImmediate(()=>{const $query$$={id_app:$id_app$$,ngay_ct:{$gte:$ngay_dn$$,$lt:$ngay$$}};$ma_vt$$&&($query$$.ma_vt=$ma_vt$$);$ma_kho$$&&($query$$.ma_kho=$ma_kho$$);$ma_dvcs$$&&($query$$.ma_dvcs=$ma_dvcs$$);$condition$$.ma_lo&&($query$$.ma_lo=$condition$$.ma_lo);$condition$$.han_sd&&($query$$.han_sd=$condition$$.han_sd);$condition$$.ma_tt1&&($query$$.ma_tt1=$condition$$.ma_tt1);$condition$$.ma_tt2&&
5
- ($query$$.ma_tt2=$condition$$.ma_tt2);$condition$$.ma_tt3&&($query$$.ma_tt3=$condition$$.ma_tt3);sokho.find($query$$).lean().then($pss$$=>{$pss$$=$pss$$.map($ps$$=>{$ps$$.sl_nhap=utils.round($ps$$.sl_nhap_qd,4);$ps$$.sl_xuat=utils.round($ps$$.sl_xuat_qd,4);return $ps$$});$callback$$(null,$pss$$)}).catch($error$$=>{$callback$$({message:$error$$.message})})})}},($data_error$$,$groupBy_results$$)=>{if($data_error$$)return $fn$$($data_error$$);$data_error$$=$groupBy_results$$.dn.concat($groupBy_results$$.ps);
6
- ($groupBy_results$$=$condition$$.groupBy||$condition$$.groupby)||($groupBy_results$$=["ma_vt"]);if(underscore.isString($groupBy_results$$))if($groupBy_results$$.indexOf("[")>=0)try{$groupBy_results$$=JSON.parse($groupBy_results$$)}catch($e$$){Logger.error($e$$)}else $groupBy_results$$=$groupBy_results$$.split(",");$data_error$$.groupBy($groupBy_results$$,"sl_nhap sl_xuat ton00 du00 tien_nhap tien_xuat".split(" "),($e$$,$groups$$)=>{if($e$$)return $fn$$($e$$);setImmediate(()=>{for(let $r$$ of $groups$$)$r$$.ton00=
7
- utils.round($r$$.ton00+$r$$.sl_nhap-$r$$.sl_xuat,4),$r$$.du00=utils.round($r$$.du00,0)+utils.round($r$$.tien_nhap,0)-utils.round($r$$.tien_xuat,0),$r$$.sl_nhap=0,$r$$.sl_xuat=0,$r$$.tien_nhap=0,$r$$.tien_xuat=0;$fn$$(null,$groups$$)})})})}else $fn$$("B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: ngay,id_app")};
2
+ module.exports=async function($condition$$,$fn$$){!$condition$$.ngay&&$condition$$.tu_ngay&&($condition$$.ngay=$condition$$.tu_ngay);if($condition$$&&$condition$$.ngay&&$condition$$.id_app){var $id_app$$=$condition$$.id_app,$ma_dvcs$$=$condition$$.ma_dvcs,$ma_kho$$=$condition$$.ma_kho,$ds_ma_kho$$;$ma_kho$$&&(Array.isArray($ma_kho$$)?$ds_ma_kho$$=[...$ma_kho$$]:typeof $ma_kho$$=="string"&&($ds_ma_kho$$=await global.getModel("dmkho").getAllChildrenGroup($id_app$$,$ma_kho$$)));var $ma_vt$$=$condition$$.ma_vt;
3
+ underscore.isArray($ma_vt$$)&&($ma_vt$$={$in:$ma_vt$$});var $ngay$$=moment(new Date($condition$$.ngay)).startOf("date").toDate(),$nam$$=$ngay$$.getFullYear(),$ngay_dn$$=moment($ngay$$).startOf("year").toDate();async.series({dn:$callback$$=>{setImmediate(()=>{const $c_dk$$={id_app:$id_app$$,nam:$nam$$};$ma_vt$$&&($c_dk$$.ma_vt=$ma_vt$$);$ds_ma_kho$$?$c_dk$$.ma_kho={$in:$ds_ma_kho$$}:$condition$$.ma_kho&&($c_dk$$.ma_kho=$condition$$.ma_kho);$ma_dvcs$$&&($c_dk$$.ma_dvcs=$ma_dvcs$$);$condition$$.ma_lo&&
4
+ ($c_dk$$.ma_lo=$condition$$.ma_lo);$condition$$.han_sd&&($c_dk$$.han_sd=$condition$$.han_sd);$condition$$.ma_tt1&&($c_dk$$.ma_tt1=$condition$$.ma_tt1);$condition$$.ma_tt2&&($c_dk$$.ma_tt2=$condition$$.ma_tt2);$condition$$.ma_tt3&&($c_dk$$.ma_tt3=$condition$$.ma_tt3);cdvt.find($c_dk$$).lean().then($results$$=>{$callback$$(null,$results$$)}).catch($error$$=>{$callback$$({message:$error$$.message})})})},ps:$callback$$=>{setImmediate(()=>{const $query$$={id_app:$id_app$$,ngay_ct:{$gte:$ngay_dn$$,$lt:$ngay$$}};
5
+ $ma_vt$$&&($query$$.ma_vt=$ma_vt$$);$ds_ma_kho$$?$query$$.ma_kho={$in:$ds_ma_kho$$}:$condition$$.ma_kho&&($query$$.ma_kho=$condition$$.ma_kho);$ma_dvcs$$&&($query$$.ma_dvcs=$ma_dvcs$$);$condition$$.ma_lo&&($query$$.ma_lo=$condition$$.ma_lo);$condition$$.han_sd&&($query$$.han_sd=$condition$$.han_sd);$condition$$.ma_tt1&&($query$$.ma_tt1=$condition$$.ma_tt1);$condition$$.ma_tt2&&($query$$.ma_tt2=$condition$$.ma_tt2);$condition$$.ma_tt3&&($query$$.ma_tt3=$condition$$.ma_tt3);sokho.find($query$$).lean().then($pss$$=>
6
+ {$pss$$=$pss$$.map($ps$$=>{$ps$$.sl_nhap=utils.round($ps$$.sl_nhap_qd,4);$ps$$.sl_xuat=utils.round($ps$$.sl_xuat_qd,4);return $ps$$});$callback$$(null,$pss$$)}).catch($error$$=>{$callback$$({message:$error$$.message})})})}},($data_error$$,$groupBy_results$$)=>{if($data_error$$)return $fn$$($data_error$$);$data_error$$=$groupBy_results$$.dn.concat($groupBy_results$$.ps);($groupBy_results$$=$condition$$.groupBy||$condition$$.groupby)||($groupBy_results$$=["ma_vt"]);if(underscore.isString($groupBy_results$$))if($groupBy_results$$.indexOf("[")>=
7
+ 0)try{$groupBy_results$$=JSON.parse($groupBy_results$$)}catch($e$$){Logger.error($e$$)}else $groupBy_results$$=$groupBy_results$$.split(",");$data_error$$.groupBy($groupBy_results$$,"sl_nhap sl_xuat ton00 du00 tien_nhap tien_xuat".split(" "),($e$$,$groups$$)=>{if($e$$)return $fn$$($e$$);setImmediate(()=>{for(let $r$$ of $groups$$)$r$$.ton00=utils.round($r$$.ton00+$r$$.sl_nhap-$r$$.sl_xuat,4),$r$$.du00=utils.round($r$$.du00,0)+utils.round($r$$.tien_nhap,0)-utils.round($r$$.tien_xuat,0),$r$$.sl_nhap=
8
+ 0,$r$$.sl_xuat=0,$r$$.tien_nhap=0,$r$$.tien_xuat=0;$fn$$(null,$groups$$)})})})}else $fn$$("B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: ngay,id_app")};