flexbiz-server 12.2.3 → 12.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/package.json +1 -1
  2. package/server/auths/local.js +27 -26
  3. package/server/controllers/controller.js +56 -55
  4. package/server/controllers/controllerRPT.js +18 -17
  5. package/server/libs/cdpstk.js +1 -1
  6. package/server/libs/databanle.js +13 -13
  7. package/server/libs/getGiaban.js +23 -22
  8. package/server/libs/post-book.js +9 -8
  9. package/server/libs/post-socai.js +9 -9
  10. package/server/libs/prototypes.js +4 -4
  11. package/server/libs/tinhGtPhanboSltp.js +5 -5
  12. package/server/libs/tinhGtPhanboYtcp.js +2 -2
  13. package/server/libs/tinhGtThcppstk.js +1 -1
  14. package/server/libs/tinhGtTrucTiep.js +8 -7
  15. package/server/libs/tinhgiatb.js +4 -4
  16. package/server/libs/tinhgiatb1vt.js +3 -3
  17. package/server/libs/tinhhoahong.js +32 -0
  18. package/server/libs/utils.js +4 -3
  19. package/server/models/app.js +9 -8
  20. package/server/models/approve.js +4 -4
  21. package/server/models/customer.js +8 -8
  22. package/server/models/dh2.js +10 -9
  23. package/server/models/dmgiaban.js +6 -6
  24. package/server/models/dmhoahonghd.js +6 -5
  25. package/server/models/fbconversation.js +9 -0
  26. package/server/models/fbmessage.js +2 -0
  27. package/server/models/fbpage.js +2 -0
  28. package/server/models/group.js +4 -2
  29. package/server/models/hd2.js +8 -8
  30. package/server/models/hd3.js +9 -9
  31. package/server/models/hd7.js +1 -1
  32. package/server/models/notification.js +3 -2
  33. package/server/models/participant.js +5 -5
  34. package/server/models/pbl.js +4 -4
  35. package/server/models/reportinfo.js +2 -2
  36. package/server/models/rptform.js +3 -2
  37. package/server/models/schedule.js +1 -1
  38. package/server/models/so1.js +7 -6
  39. package/server/models/socai.js +4 -4
  40. package/server/models/tdttco.js +8 -4
  41. package/server/models/tdttno.js +8 -4
  42. package/server/models/tokens.js +2 -2
  43. package/server/models/usergroup.js +5 -4
  44. package/server/models/vatra.js +2 -2
  45. package/server/models/vatvao.js +4 -4
  46. package/server/modules/lists/ls-assinvestment.js +1 -1
  47. package/server/modules/lists/ls-customer.js +13 -14
  48. package/server/modules/lists/ls-dmvt.js +48 -39
  49. package/server/modules/lists/ls-fbconversation.js +3 -0
  50. package/server/modules/lists/ls-fbmessage.js +3 -0
  51. package/server/modules/lists/ls-fbpage.js +10 -0
  52. package/server/modules/lists/ls-introducecode.js +1 -1
  53. package/server/modules/lists/ls-news.js +1 -1
  54. package/server/modules/lists/ls-opportunity.js +3 -3
  55. package/server/modules/lists/ls-session.js +1 -1
  56. package/server/modules/public/callin.js +6 -6
  57. package/server/modules/reports/rp-cdpstk.js +3 -3
  58. package/server/modules/reports/rp-chitiettaisan.js +9 -8
  59. package/server/modules/reports/rp-ckvt.js +9 -7
  60. package/server/modules/reports/rp-ctbanle.js +13 -12
  61. package/server/modules/reports/rp-databanle.js +8 -4
  62. package/server/modules/reports/rp-dtbanletheoct.js +16 -9
  63. package/server/modules/reports/rp-dtbanletheokh.js +12 -6
  64. package/server/modules/reports/rp-dtbanletheokho.js +14 -9
  65. package/server/modules/reports/rp-dtbanletheonam.js +15 -9
  66. package/server/modules/reports/rp-dtbanletheongay.js +13 -8
  67. package/server/modules/reports/rp-dtbanletheonv.js +15 -9
  68. package/server/modules/reports/rp-dtbanletheoquy.js +15 -9
  69. package/server/modules/reports/rp-dtbanletheothang.js +15 -9
  70. package/server/modules/reports/rp-getinvoice2pay.js +4 -6
  71. package/server/modules/reports/rp-getinvoice2receive.js +4 -6
  72. package/server/modules/reports/rp-hoahong.js +9 -0
  73. package/server/modules/reports/rp-kqhdkd.js +5 -4
  74. package/server/modules/reports/rp-ptcttct.js +7 -6
  75. package/server/modules/reports/rp-pttct.js +8 -8
  76. package/server/modules/reports/rp-pttctkho.js +3 -2
  77. package/server/modules/reports/rp-pttctkho2.js +3 -3
  78. package/server/modules/reports/rp-thnxt.js +8 -8
  79. package/server/modules/reports/rp-thnxt_sl.js +6 -6
  80. package/server/modules/reports/rp-thnxttt.js +6 -6
  81. package/server/modules/reports/rp-tmbctc.js +16 -16
  82. package/server/modules/systems/sys-app.js +25 -24
  83. package/server/modules/systems/sys-notification.js +2 -2
  84. package/server/modules/systems/sys-schedule.js +1 -1
  85. package/server/modules/systems/sys-user.js +8 -8
  86. package/server/modules/vouchers/vo-bc1.js +9 -8
  87. package/server/modules/vouchers/vo-bg2.js +9 -9
  88. package/server/modules/vouchers/vo-bn1.js +5 -4
  89. package/server/modules/vouchers/vo-dh2.js +15 -38
  90. package/server/modules/vouchers/vo-dnm.js +11 -12
  91. package/server/modules/vouchers/vo-hd2.js +63 -83
  92. package/server/modules/vouchers/vo-hd3.js +28 -22
  93. package/server/modules/vouchers/vo-hd7.js +37 -36
  94. package/server/modules/vouchers/vo-pbl.js +49 -49
  95. package/server/modules/vouchers/vo-pc1.js +9 -8
  96. package/server/modules/vouchers/vo-pn1.js +24 -22
  97. package/server/modules/vouchers/vo-pn5.js +1 -1
  98. package/server/modules/vouchers/vo-pn9.js +23 -23
  99. package/server/modules/vouchers/vo-pnc.js +8 -8
  100. package/server/modules/vouchers/vo-pnh.js +5 -5
  101. package/server/modules/vouchers/vo-pt1.js +17 -16
  102. package/server/modules/vouchers/vo-pxc.js +16 -16
  103. package/server/modules/vouchers/vo-pxh.js +12 -10
  104. package/server/modules/vouchers/vo-so1.js +94 -119
  105. package/server/modules/vouchers/vo-so4.js +1 -1
  106. package/server/modules/vouchers/vo-so5.js +2 -2
  107. package/server/workers/restoreApp.js +21 -12
  108. package/server/workers/runScript.js +3 -3
@@ -1,8 +1,10 @@
1
1
  'use strict';const ckvt=require("../../libs/ckvt"),getGiaBan=require("../../libs/getGiaban"),Dmvt=global.getModel("dmvt"),Dmkho=global.getModel("dmkho"),async=require("async"),controller=require("../../controllers/controllerRPT"),moment=require("moment");
2
- module.exports=function($router$$){new controller($router$$,"ckvt",function($req$$,$callback$jscomp$1$$){const $condition$$=$req$$.query;ckvt($condition$$,function($error$jscomp$0$$,$report$$){if($error$jscomp$0$$)return $callback$jscomp$1$$($error$jscomp$0$$);$report$$=$report$$.filter($r$$=>$r$$.ton00||$r$$.du00);const $id_app$$=$condition$$.id_app;async.series({vt:$callback$$=>{$report$$.filter($r$$=>$r$$.ma_vt).joinModel2($id_app$$,Dmvt,{where:"ma_vt",fields:"ten_vt tg_tk tk_vt ma_ncc ma_dvt ma_nvt ma_vt2".split(" "),
3
- setFields:($a$$,$b$$)=>{if($b$$.picture){let $p$$=$b$$.picture.split(".");$a$$.picture_thumb=$b$$.picture+".thumb."+$p$$[$p$$.length-1]}else $a$$.picture="/getfile/others/noimage.png",$a$$.picture_thumb="/getfile/others/noimage.png"}},()=>{$callback$$()})},kho:$callback$$=>{$report$$.filter($r$$=>$r$$.ma_kho).joinModel2($id_app$$,Dmkho,{where:"ma_kho",fields:["ten_kho","la_kho_online"]},()=>{$callback$$()})},tt1:$callback$$=>{$report$$.filter($r$$=>$r$$.ma_vt&&$r$$.ma_tt1).joinModel2($id_app$$,global.getModel("dmtt"),
4
- {where:$item$$=>({ma_vt:$item$$.ma_vt,ma_tt:$item$$.ma_tt1,loai_tt:"1"}),fields:{barcode1:"ma_tt2"}},()=>{$callback$$()})},tt2:$callback$$=>{$report$$.filter($r$$=>$r$$.ma_vt&&$r$$.ma_tt2).joinModel2($id_app$$,global.getModel("dmtt"),{where:$item$$=>({ma_vt:$item$$.ma_vt,ma_tt:$item$$.ma_tt2,loai_tt:"2"}),fields:{barcode2:"ma_tt2"}},()=>{$callback$$()})},tt3:$callback$$=>{$report$$.filter($r$$=>$r$$.ma_vt&&$r$$.ma_tt3).joinModel2($id_app$$,global.getModel("dmtt"),{where:$item$$=>({ma_vt:$item$$.ma_vt,
5
- ma_tt:$item$$.ma_tt3,loai_tt:"3"}),fields:{barcode3:"ma_tt2"}},()=>{$callback$$()})},gb:function($callback$jscomp$0$$){async.mapSeries($report$$,($item$$,$callback$$)=>{const $condition_giaban$$={ma_vt:$item$$.ma_vt,id_app:$condition$$.id_app};$item$$.ma_kho&&($condition_giaban$$.ma_kho=$item$$.ma_kho);$item$$.ma_tt1&&($condition_giaban$$.ma_tt1=$item$$.ma_tt1);$item$$.ma_tt2&&($condition_giaban$$.ma_tt2=$item$$.ma_tt2);$item$$.ma_tt3&&($condition_giaban$$.ma_tt3=$item$$.ma_tt3);getGiaBan($condition_giaban$$,
6
- ($e$$,$gia$$)=>{if($e$$)return console.error("error when get gia_ban on dmvt",$e$$,$condition_giaban$$),$callback$$();$gia$$?($item$$.gia_ban_le=$gia$$.gia_ban_le||0,$item$$.doanh_thu_du_tinh=($item$$.gia_ban_le||0)*($item$$.ton00||0)):($item$$.gia_ban_le=0,$item$$.doanh_thu_du_tinh=0);$callback$$(null)})},()=>{$callback$jscomp$0$$()})}},async function($error$$){if($error$$)return $callback$jscomp$1$$($error$$);$error$$=$condition$$.ngay;!$error$$&&$condition$$.den_ngay&&($error$$=$condition$$.den_ngay);
7
- $error$$=moment($error$$).endOf("date").toDate();!($error$$.getTime()>=moment().endOf("date").toDate())||$condition$$.ma_kho||$condition$$.ma_lo||$condition$$.han_sd||$condition$$.ma_tt1||$condition$$.ma_tt2||$condition$$.ma_tt3||$condition$$.id_ct||$condition$$.ma_dvcs||(await $report$$.filter($r$$=>$r$$.ma_vt&&$r$$.la_kho_online).asyncGroupBy(["ma_vt"],["ton00"])).forEach(async $sk$$=>{let $vt$$=await global.getModel("dmvt").findOne({id_app:$condition$$.id_app,ma_vt:$sk$$.ma_vt});$vt$$&&($vt$$.ton_kho_online_hien_tai=
8
- $sk$$.ton00,$vt$$.save($e$$=>{$e$$&&console.error($e$$)}))});$report$$.forEach($r$$=>{$r$$.barcode=$r$$.barcode1||$r$$.barcode2||$r$$.barcode3||$r$$.ma_vt2});$callback$jscomp$1$$(null,$report$$)})})})};
2
+ module.exports=function($router$$){new controller($router$$,"ckvt",async function($_queryvt_req_vts$$,$callback$jscomp$1$$){const $condition$$=$_queryvt_req_vts$$.query;if(!$condition$$.ma_vt&&($condition$$.ma_kh||$condition$$.ma_ncc||$condition$$.ma_nvt||$condition$$.ma_nvt2||$condition$$.ma_nvt3||$condition$$.ma_nvt4)){$_queryvt_req_vts$$={id_app:$condition$$.id_app};if($condition$$.ma_ncc||$condition$$.ma_kh)$_queryvt_req_vts$$.ma_ncc=$condition$$.ma_ncc||$condition$$.ma_kh;$condition$$.ma_nvt&&
3
+ 0<$condition$$.ma_nvt.length&&($_queryvt_req_vts$$.ma_nvt=$condition$$.ma_nvt);$condition$$.ma_nvt2&&0<$condition$$.ma_nvt2.length&&($_queryvt_req_vts$$.ma_nvt2=$condition$$.ma_nvt2);$condition$$.ma_nvt3&&0<$condition$$.ma_nvt3.length&&($_queryvt_req_vts$$.ma_nvt3=$condition$$.ma_nvt3);$condition$$.ma_nvt4&&0<$condition$$.ma_nvt4.length&&($_queryvt_req_vts$$.ma_nvt4=$condition$$.ma_nvt4);$_queryvt_req_vts$$=await Dmvt.find($_queryvt_req_vts$$,{ma_vt:1}).lean();$condition$$.ma_vt=$_queryvt_req_vts$$.map($v$$=>
4
+ $v$$.ma_vt)}ckvt($condition$$,function($error$jscomp$0$$,$report$$){if($error$jscomp$0$$)return $callback$jscomp$1$$($error$jscomp$0$$);$report$$=$report$$.filter($r$$=>$r$$.ton00||$r$$.du00);const $id_app$$=$condition$$.id_app;async.series({vt:$callback$$=>{$report$$.filter($r$$=>$r$$.ma_vt).joinModel2($id_app$$,Dmvt,{where:"ma_vt",fields:"ten_vt tg_tk tk_vt ma_ncc ma_dvt ma_nvt ma_vt2 ma_vt3 ma_vt4".split(" "),setFields:($a$$,$b$$)=>{if($b$$.picture){let $p$$=$b$$.picture.split(".");$a$$.picture_thumb=
5
+ $b$$.picture+".thumb."+$p$$[$p$$.length-1]}else $a$$.picture="/getfile/others/noimage.png",$a$$.picture_thumb="/getfile/others/noimage.png"}},()=>{$callback$$()})},kho:$callback$$=>{$report$$.filter($r$$=>$r$$.ma_kho).joinModel2($id_app$$,Dmkho,{where:"ma_kho",fields:["ten_kho","la_kho_online"]},()=>{$callback$$()})},tt1:$callback$$=>{$report$$.filter($r$$=>$r$$.ma_vt&&$r$$.ma_tt1).joinModel2($id_app$$,global.getModel("dmtt"),{where:$item$$=>({ma_vt:$item$$.ma_vt,ma_tt:$item$$.ma_tt1,loai_tt:"1"}),
6
+ fields:{barcode1:"ma_tt2"}},()=>{$callback$$()})},tt2:$callback$$=>{$report$$.filter($r$$=>$r$$.ma_vt&&$r$$.ma_tt2).joinModel2($id_app$$,global.getModel("dmtt"),{where:$item$$=>({ma_vt:$item$$.ma_vt,ma_tt:$item$$.ma_tt2,loai_tt:"2"}),fields:{barcode2:"ma_tt2"}},()=>{$callback$$()})},tt3:$callback$$=>{$report$$.filter($r$$=>$r$$.ma_vt&&$r$$.ma_tt3).joinModel2($id_app$$,global.getModel("dmtt"),{where:$item$$=>({ma_vt:$item$$.ma_vt,ma_tt:$item$$.ma_tt3,loai_tt:"3"}),fields:{barcode3:"ma_tt2"}},()=>{$callback$$()})},
7
+ gb:function($callback$jscomp$0$$){async.mapSeries($report$$,($item$$,$callback$$)=>{const $condition_giaban$$={ma_vt:$item$$.ma_vt,id_app:$condition$$.id_app};$item$$.ma_kho&&($condition_giaban$$.ma_kho=$item$$.ma_kho);$item$$.ma_tt1&&($condition_giaban$$.ma_tt1=$item$$.ma_tt1);$item$$.ma_tt2&&($condition_giaban$$.ma_tt2=$item$$.ma_tt2);$item$$.ma_tt3&&($condition_giaban$$.ma_tt3=$item$$.ma_tt3);getGiaBan($condition_giaban$$,($e$$,$gia$$)=>{if($e$$)return console.error("error when get gia_ban on dmvt",
8
+ $e$$,$condition_giaban$$),$callback$$();$gia$$?($item$$.gia_ban_le=$gia$$.gia_ban_le||0,$item$$.doanh_thu_du_tinh=($item$$.gia_ban_le||0)*($item$$.ton00||0)):($item$$.gia_ban_le=0,$item$$.doanh_thu_du_tinh=0);$callback$$(null)})},()=>{$callback$jscomp$0$$()})}},async function($error$$){if($error$$)return $callback$jscomp$1$$($error$$);$error$$=$condition$$.ngay;!$error$$&&$condition$$.den_ngay&&($error$$=$condition$$.den_ngay);$error$$=moment($error$$).endOf("date").toDate();!($error$$.getTime()>=
9
+ moment().endOf("date").toDate())||$condition$$.ma_kho||$condition$$.ma_lo||$condition$$.han_sd||$condition$$.ma_tt1||$condition$$.ma_tt2||$condition$$.ma_tt3||$condition$$.id_ct||$condition$$.ma_dvcs||(await $report$$.filter($r$$=>$r$$.ma_vt&&$r$$.la_kho_online).asyncGroupBy(["ma_vt"],["ton00"])).forEach(async $sk$$=>{let $vt$$=await global.getModel("dmvt").findOne({id_app:$condition$$.id_app,ma_vt:$sk$$.ma_vt});$vt$$&&($vt$$.ton_kho_online_hien_tai=$sk$$.ton00,$vt$$.save($e$$=>{$e$$&&console.error($e$$)}))});
10
+ $report$$.forEach($r$$=>{$r$$.barcode=$r$$.barcode1||$r$$.barcode2||$r$$.barcode3||$r$$.ma_vt2});$callback$jscomp$1$$(null,$report$$)})})})};
@@ -1,15 +1,16 @@
1
1
  'use strict';const sokho=global.getModel("sokho"),sokhokhongton=global.getModel("sokhokhongton"),ptthanhtoan=global.getModel("ptthanhtoan"),pbl=global.getModel("pbl"),so1=global.getModel("so1"),hd2=global.getModel("hd2"),dmvt=global.getModel("dmvt"),dmtt=global.getModel("dmtt"),customer=global.getModel("customer"),group=global.getModel("group"),dmkho=global.getModel("dmkho"),dmnvt=global.getModel("dmnvt"),dmdt=global.getModel("dmdt"),dmphi=global.getModel("dmphi"),dmbp=global.getModel("dmbp"),dmban=
2
2
  global.getModel("dmban"),dmhd=global.getModel("contract"),dmnv=global.getModel("dmnv"),User=global.getModel("user"),async=require("async"),underscore=require("underscore"),controller=require("../../controllers/controllerRPT"),moment=require("moment");
3
3
  module.exports=function($router$$){new controller($router$$,"ctbanle",async function($ma_ct_query_req$$,$callback$jscomp$0$$){const $condition$$=$ma_ct_query_req$$.query;if(!$condition$$.tu_ngay||!$condition$$.den_ngay)return $callback$jscomp$0$$("B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1:tu_ngay,den_ngay");($ma_ct_query_req$$=$condition$$.ma_ct)?($ma_ct_query_req$$=$ma_ct_query_req$$.split(","),$ma_ct_query_req$$.push("HD7")):$ma_ct_query_req$$="HD2 HD9 PBL SO1 HD3 HD7".split(" ");
4
- $ma_ct_query_req$$={id_app:$condition$$.id_app,ma_ct:{$in:$ma_ct_query_req$$}};$ma_ct_query_req$$.ngay_ct={$gte:$condition$$.tu_ngay,$lte:$condition$$.den_ngay};$condition$$.ma_dvcs&&($ma_ct_query_req$$.ma_dvcs=$condition$$.ma_dvcs);$condition$$.ma_vt?$ma_ct_query_req$$.ma_vt=$condition$$.ma_vt:$condition$$.ma_ncc&&($data_khongton_vts$$=(await dmvt.find({id_app:$condition$$.id_app,ma_ncc:$condition$$.ma_ncc},{ma_vt:1}).lean()).map($v$$=>$v$$.ma_vt),$ma_ct_query_req$$.ma_vt={$in:$data_khongton_vts$$});
5
- $condition$$.ma_kho&&($ma_ct_query_req$$.ma_kho=$condition$$.ma_kho);$condition$$.ma_kh&&($ma_ct_query_req$$.ma_kh=$condition$$.ma_kh);$condition$$.user_created&&($ma_ct_query_req$$.user_created=$condition$$.user_created);$condition$$.cashier&&($ma_ct_query_req$$.cashier=$condition$$.cashier);$condition$$.pt_thanh_toan&&($ma_ct_query_req$$.$or=[{pt_thanh_toan:$condition$$.pt_thanh_toan},{pt_thanh_toan2:$condition$$.pt_thanh_toan}]);var $data_khongton_vts$$=await sokhokhongton.find($ma_ct_query_req$$).lean();
6
- let $rs$$=await sokho.find($ma_ct_query_req$$).lean();$rs$$=$rs$$.concat($data_khongton_vts$$);$rs$$.forEach($r$$=>{$r$$.tien_hang=$r$$.tien_hang||$r$$.tien;1==$r$$.nxt?($r$$.tien_tl=$r$$.tien,$r$$.tien_ck_tl=$r$$.tien_ck,$r$$.tien_hang=0,$r$$.tien_hang_nt=0,$r$$.tien_ck=0,$r$$.tien_ck_nt=0,$r$$.tien=0,$r$$.tien_nt=0):($r$$.tien_tl=0,$r$$.tien_ck_tl=0);$r$$.tien=$r$$.tien_hang-($r$$.tien_ck||0);$r$$.tien_tl_net=$r$$.tien_tl-$r$$.tien_ck_tl});(new Promise(($resolve$$,$reject$$)=>{async.series({ten_vt:$callback$$=>
7
- {$rs$$.joinModel2($condition$$.id_app,dmvt,{where:"ma_vt",fields:["ten_vt","ma_nvt","ma_lvt","ma_ncc","ma_vt2"]},()=>{$callback$$()})},tt1:$callback$$=>{$rs$$.filter($r$$=>$r$$.ma_tt1).joinModel2($condition$$.id_app,dmtt,{where:$item$$=>({ma_vt:$item$$.ma_vt,ma_tt:$item$$.ma_tt1,loai_tt:"1"}),fields:{barcode:"ma_tt2"}},()=>{$callback$$()})},tt2:$callback$$=>{$rs$$.filter($r$$=>$r$$.ma_tt2).joinModel2($condition$$.id_app,dmtt,{where:$item$$=>({ma_vt:$item$$.ma_vt,ma_tt:$item$$.ma_tt2,loai_tt:"2"}),
8
- fields:{barcode:"ma_tt2"}},()=>{$callback$$()})},tt3:$callback$$=>{$rs$$.filter($r$$=>$r$$.ma_tt3).joinModel2($condition$$.id_app,dmtt,{where:$item$$=>({ma_vt:$item$$.ma_vt,ma_tt:$item$$.ma_tt3,loai_tt:"3"}),fields:{barcode:"ma_tt2"}},()=>{$callback$$()})},ban:$callback$$=>{$rs$$.filter($r$$=>$r$$.ma_ban).joinModel2($condition$$.id_app,dmban,{where:"ma_ban",fields:["ten_ban","kenh_ban_hang","nh_ban","loai_ban"]},()=>{$callback$$()})},pbl:$callback$$=>{$rs$$.filter($r$$=>"PBL"===$r$$.ma_ct).joinModel2($condition$$.id_app,
9
- pbl,{where:{id_ct:"_id"},fields:["pt_thanh_toan","pt_thanh_toan2"]},()=>{$callback$$()})},so1:$callback$$=>{$rs$$.filter($r$$=>"SO1"===$r$$.ma_ct).joinModel2($condition$$.id_app,so1,{where:{id_ct:"_id"},fields:["pt_thanh_toan","pt_thanh_toan2"]},()=>{$callback$$()})},hd2:$callback$$=>{$rs$$.filter($r$$=>"HD2"===$r$$.ma_ct).joinModel2($condition$$.id_app,hd2,{where:{id_ct:"_id"},fields:["pt_thanh_toan"]},()=>{$callback$$()})},ten_kho:$callback$$=>{$rs$$.joinModel2($condition$$.id_app,dmkho,{where:"ma_kho",
10
- fields:"ten_kho"},()=>{$callback$$()})},ten_kh:$callback$$=>{$rs$$.filter($r$$=>$r$$.ma_kh).joinModel2($condition$$.id_app,customer,{where:"ma_kh",fields:["ten_kh","nh_kh"]},()=>{$callback$$()})},dmdt:$callback$$=>{$rs$$.filter($r$$=>$r$$.ma_dt).joinModel2($condition$$.id_app,dmdt,{where:"ma_dt",fields:"ten_dt"},()=>{$callback$$()})},dmhd:$callback$$=>{$rs$$.filter($r$$=>$r$$.ma_hd).joinModel2($condition$$.id_app,dmhd,{where:{ma_hd:"so_hd"},fields:"ten_hd"},()=>{$callback$$()})},dmbp:$callback$$=>
11
- {$rs$$.filter($r$$=>$r$$.ma_bp).joinModel2($condition$$.id_app,dmbp,{where:"ma_bp",fields:"ten_bp"},()=>{$callback$$()})},dmphi:$callback$$=>{$rs$$.filter($r$$=>$r$$.ma_phi).joinModel2($condition$$.id_app,dmphi,{where:"ma_phi",fields:"ten_phi"},()=>{$callback$$()})},dmnv:$callback$$=>{$rs$$.filter($r$$=>$r$$.ma_nv).joinModel2($condition$$.id_app,dmnv,{where:"ma_nv",fields:"ten_nv"},()=>{$callback$$()})},user:$callback$$=>{$rs$$.joinModel2(null,User,{where:{user_created:"email"},fields:[{user_name:"name"}]},
12
- ()=>{$callback$$()})},cashier:$callback$$=>{$rs$$.filter($r$$=>$r$$.cashier).joinModel2(null,User,{where:{cashier:"email"},fields:[{cashier_name:"name"}]},()=>{$callback$$()})}},($e$$,$rs$$)=>{if($e$$)return $reject$$($e$$);$resolve$$($rs$$)})})).then(()=>new Promise(($resolve$$,$reject$$)=>{async.series({pt_thanh_toan:$callback$$=>{$rs$$.filter($r$$=>$r$$.pt_thanh_toan).joinModel2($condition$$.id_app,ptthanhtoan,{where:{pt_thanh_toan:"_id"},fields:{ten_pt_thanh_toan:"ten"}},()=>{$callback$$()})},
13
- pt_thanh_toan2:$callback$$=>{$rs$$.filter($r$$=>$r$$.pt_thanh_toan2).joinModel2($condition$$.id_app,ptthanhtoan,{where:{pt_thanh_toan2:"_id"},fields:{ten_pt_thanh_toan2:"ten"}},()=>{$callback$$()})},nh_vt:$callback$$=>{$rs$$.joinModel2($condition$$.id_app,dmnvt,{where:{ma_nvt:"_id"},fields:"ten_nvt"},()=>{$callback$$()})},nh_kh:$callback$$=>{$rs$$.filter($r$$=>$r$$.nh_kh).joinModel2($condition$$.id_app,group,{where:{nh_kh:"_id"},fields:[{ten_nh_kh:"group_name"}]},()=>{$callback$$()})},nha_cc:$callback$$=>
14
- {$rs$$.filter($r$$=>$r$$.ma_ncc).joinModel2($condition$$.id_app,customer,{where:{ma_ncc:"ma_kh"},fields:[{ten_ncc:"ten_kh"}]},()=>{$callback$$()})}},($e$$,$rs$$)=>{if($e$$)return $reject$$($e$$);$resolve$$($rs$$)})})).then(()=>{$rs$$.forEach(function($r$$){$r$$.barcode=$r$$.barcode||$r$$.ma_vt2;$r$$.lai=$r$$.tien-$r$$.tien_xuat-($r$$.tien_tl-$r$$.tien_nhap);$r$$.bold=!1});const $report$$=underscore.sortBy($rs$$,function($r$$){return moment($r$$.ngay_ct).format("YYYY-MM-DD")+$r$$.so_ct+$r$$.ma_vt});
15
- $report$$.push({ten_vt:"T\u1ed5ng c\u1ed9ng",sl_xuat:$report$$.csum("sl_xuat"),tien_xuat:$report$$.csum("tien_xuat"),tien_hang:$report$$.csum("tien_hang"),tien_ck:$report$$.csum("tien_ck"),tien:$report$$.csum("tien"),sl_nhap:$report$$.csum("sl_nhap"),tien_nhap:$report$$.csum("tien_nhap"),tien_tl:$report$$.csum("tien_tl"),tien_ck_tl:$report$$.csum("tien_ck_tl"),tien_tl_net:$report$$.csum("tien_tl_net"),lai:$report$$.csum("lai"),bold:!0});$callback$jscomp$0$$(null,$report$$)}).catch($e$$=>{$callback$jscomp$0$$($e$$)})})};
4
+ $ma_ct_query_req$$={id_app:$condition$$.id_app,ma_ct:{$in:$ma_ct_query_req$$}};$ma_ct_query_req$$.ngay_ct={$gte:$condition$$.tu_ngay,$lte:$condition$$.den_ngay};$condition$$.ma_dvcs&&($ma_ct_query_req$$.ma_dvcs=$condition$$.ma_dvcs);if($condition$$.ma_vt)$ma_ct_query_req$$.ma_vt=$condition$$.ma_vt;else if($condition$$.ma_ncc||$condition$$.ma_nvt||$condition$$.ma_danh_muc_cty||$condition$$.ma_danh_muc)$data_khongton_q_vts$$={id_app:$condition$$.id_app},$condition$$.ma_ncc&&($data_khongton_q_vts$$.ma_ncc=
5
+ $condition$$.ma_ncc),$condition$$.ma_nvt&&($data_khongton_q_vts$$.ma_nvt=$condition$$.ma_nvt),$condition$$.ma_danh_muc_cty&&($data_khongton_q_vts$$.ma_danh_muc_cty=$condition$$.ma_danh_muc_cty),$condition$$.ma_danh_muc&&($data_khongton_q_vts$$.ma_danh_muc=$condition$$.ma_danh_muc),$data_khongton_q_vts$$=(await dmvt.find($data_khongton_q_vts$$,{ma_vt:1}).lean()).map($v$$=>$v$$.ma_vt),$ma_ct_query_req$$.ma_vt={$in:$data_khongton_q_vts$$};$condition$$.ma_kho&&($ma_ct_query_req$$.ma_kho=$condition$$.ma_kho);
6
+ $condition$$.ma_kh&&($ma_ct_query_req$$.ma_kh=$condition$$.ma_kh);$condition$$.user_created&&($ma_ct_query_req$$.user_created=$condition$$.user_created);$condition$$.cashier&&($ma_ct_query_req$$.cashier=$condition$$.cashier);$condition$$.pt_thanh_toan&&($ma_ct_query_req$$.$or=[{pt_thanh_toan:$condition$$.pt_thanh_toan},{pt_thanh_toan2:$condition$$.pt_thanh_toan}]);var $data_khongton_q_vts$$=await sokhokhongton.find($ma_ct_query_req$$).lean();let $rs$$=await sokho.find($ma_ct_query_req$$).lean();$rs$$=
7
+ $rs$$.concat($data_khongton_q_vts$$);$rs$$.forEach($r$$=>{$r$$.tien_hang=$r$$.tien_hang||$r$$.tien;1==$r$$.nxt?($r$$.tien_tl=$r$$.tien,$r$$.tien_ck_tl=$r$$.tien_ck,$r$$.tien_hang=0,$r$$.tien_hang_nt=0,$r$$.tien_ck=0,$r$$.tien_ck_nt=0,$r$$.tien=0,$r$$.tien_nt=0):($r$$.tien_tl=0,$r$$.tien_ck_tl=0);$r$$.tien=$r$$.tien_hang-($r$$.tien_ck||0);$r$$.tien_tl_net=$r$$.tien_tl-$r$$.tien_ck_tl});(new Promise(($resolve$$,$reject$$)=>{async.series({ten_vt:$callback$$=>{$rs$$.joinModel2($condition$$.id_app,dmvt,
8
+ {where:"ma_vt",fields:["ten_vt","ma_nvt","ma_lvt","ma_ncc","ma_vt2"]},()=>{$callback$$()})},tt1:$callback$$=>{$rs$$.filter($r$$=>$r$$.ma_tt1).joinModel2($condition$$.id_app,dmtt,{where:$item$$=>({ma_vt:$item$$.ma_vt,ma_tt:$item$$.ma_tt1,loai_tt:"1"}),fields:{barcode:"ma_tt2"}},()=>{$callback$$()})},tt2:$callback$$=>{$rs$$.filter($r$$=>$r$$.ma_tt2).joinModel2($condition$$.id_app,dmtt,{where:$item$$=>({ma_vt:$item$$.ma_vt,ma_tt:$item$$.ma_tt2,loai_tt:"2"}),fields:{barcode:"ma_tt2"}},()=>{$callback$$()})},
9
+ tt3:$callback$$=>{$rs$$.filter($r$$=>$r$$.ma_tt3).joinModel2($condition$$.id_app,dmtt,{where:$item$$=>({ma_vt:$item$$.ma_vt,ma_tt:$item$$.ma_tt3,loai_tt:"3"}),fields:{barcode:"ma_tt2"}},()=>{$callback$$()})},ban:$callback$$=>{$rs$$.filter($r$$=>$r$$.ma_ban).joinModel2($condition$$.id_app,dmban,{where:"ma_ban",fields:["ten_ban","kenh_ban_hang","nh_ban","loai_ban"]},()=>{$callback$$()})},pbl:$callback$$=>{$rs$$.filter($r$$=>"PBL"===$r$$.ma_ct).joinModel2($condition$$.id_app,pbl,{where:{id_ct:"_id"},
10
+ fields:["pt_thanh_toan","pt_thanh_toan2"]},()=>{$callback$$()})},so1:$callback$$=>{$rs$$.filter($r$$=>"SO1"===$r$$.ma_ct).joinModel2($condition$$.id_app,so1,{where:{id_ct:"_id"},fields:["pt_thanh_toan","pt_thanh_toan2"]},()=>{$callback$$()})},hd2:$callback$$=>{$rs$$.filter($r$$=>"HD2"===$r$$.ma_ct).joinModel2($condition$$.id_app,hd2,{where:{id_ct:"_id"},fields:["pt_thanh_toan"]},()=>{$callback$$()})},ten_kho:$callback$$=>{$rs$$.joinModel2($condition$$.id_app,dmkho,{where:"ma_kho",fields:"ten_kho"},
11
+ ()=>{$callback$$()})},ten_kh:$callback$$=>{$rs$$.filter($r$$=>$r$$.ma_kh).joinModel2($condition$$.id_app,customer,{where:"ma_kh",fields:["ten_kh","nh_kh"]},()=>{$callback$$()})},dmdt:$callback$$=>{$rs$$.filter($r$$=>$r$$.ma_dt).joinModel2($condition$$.id_app,dmdt,{where:"ma_dt",fields:"ten_dt"},()=>{$callback$$()})},dmhd:$callback$$=>{$rs$$.filter($r$$=>$r$$.ma_hd).joinModel2($condition$$.id_app,dmhd,{where:{ma_hd:"so_hd"},fields:"ten_hd"},()=>{$callback$$()})},dmbp:$callback$$=>{$rs$$.filter($r$$=>
12
+ $r$$.ma_bp).joinModel2($condition$$.id_app,dmbp,{where:"ma_bp",fields:"ten_bp"},()=>{$callback$$()})},dmphi:$callback$$=>{$rs$$.filter($r$$=>$r$$.ma_phi).joinModel2($condition$$.id_app,dmphi,{where:"ma_phi",fields:"ten_phi"},()=>{$callback$$()})},dmnv:$callback$$=>{$rs$$.filter($r$$=>$r$$.ma_nv).joinModel2($condition$$.id_app,dmnv,{where:"ma_nv",fields:"ten_nv"},()=>{$callback$$()})},user:$callback$$=>{$rs$$.joinModel2(null,User,{where:{user_created:"email"},fields:[{user_name:"name"}]},()=>{$callback$$()})},
13
+ cashier:$callback$$=>{$rs$$.filter($r$$=>$r$$.cashier).joinModel2(null,User,{where:{cashier:"email"},fields:[{cashier_name:"name"}]},()=>{$callback$$()})}},($e$$,$rs$$)=>{if($e$$)return $reject$$($e$$);$resolve$$($rs$$)})})).then(()=>new Promise(($resolve$$,$reject$$)=>{async.series({pt_thanh_toan:$callback$$=>{$rs$$.filter($r$$=>$r$$.pt_thanh_toan).joinModel2($condition$$.id_app,ptthanhtoan,{where:{pt_thanh_toan:"_id"},fields:{ten_pt_thanh_toan:"ten"}},()=>{$callback$$()})},pt_thanh_toan2:$callback$$=>
14
+ {$rs$$.filter($r$$=>$r$$.pt_thanh_toan2).joinModel2($condition$$.id_app,ptthanhtoan,{where:{pt_thanh_toan2:"_id"},fields:{ten_pt_thanh_toan2:"ten"}},()=>{$callback$$()})},nh_vt:$callback$$=>{$rs$$.joinModel2($condition$$.id_app,dmnvt,{where:{ma_nvt:"_id"},fields:"ten_nvt"},()=>{$callback$$()})},nh_kh:$callback$$=>{$rs$$.filter($r$$=>$r$$.nh_kh).joinModel2($condition$$.id_app,group,{where:{nh_kh:"_id"},fields:[{ten_nh_kh:"group_name"}]},()=>{$callback$$()})},nha_cc:$callback$$=>{$rs$$.filter($r$$=>
15
+ $r$$.ma_ncc).joinModel2($condition$$.id_app,customer,{where:{ma_ncc:"ma_kh"},fields:[{ten_ncc:"ten_kh"}]},()=>{$callback$$()})}},($e$$,$rs$$)=>{if($e$$)return $reject$$($e$$);$resolve$$($rs$$)})})).then(()=>{$rs$$.forEach(function($r$$){$r$$.barcode=$r$$.barcode||$r$$.ma_vt2;$r$$.lai=$r$$.tien-$r$$.tien_xuat-($r$$.tien_tl-$r$$.tien_nhap);$r$$.bold=!1});const $report$$=underscore.sortBy($rs$$,function($r$$){return moment($r$$.ngay_ct).format("YYYY-MM-DD")+$r$$.so_ct+$r$$.ma_vt});$report$$.push({ten_vt:"T\u1ed5ng c\u1ed9ng",
16
+ sl_xuat:$report$$.csum("sl_xuat"),tien_xuat:$report$$.csum("tien_xuat"),tien_hang:$report$$.csum("tien_hang"),tien_ck:$report$$.csum("tien_ck"),tien:$report$$.csum("tien"),sl_nhap:$report$$.csum("sl_nhap"),tien_nhap:$report$$.csum("tien_nhap"),tien_tl:$report$$.csum("tien_tl"),tien_ck_tl:$report$$.csum("tien_ck_tl"),tien_tl_net:$report$$.csum("tien_tl_net"),lai:$report$$.csum("lai"),bold:!0});$callback$jscomp$0$$(null,$report$$)}).catch($e$$=>{$callback$jscomp$0$$($e$$)})})};
@@ -1,5 +1,9 @@
1
1
  'use strict';const databanle=require("../../libs/databanle"),async=require("async"),controller=require("../../controllers/controllerRPT"),underscore=require("underscore");
2
- module.exports=function($router$$){new controller($router$$,"databanle",function($condition_req$$,$callback$jscomp$0$$){$condition_req$$=$condition_req$$.query;if(!$condition_req$$.tu_ngay||!$condition_req$$.den_ngay)return $callback$jscomp$0$$("B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1:tu_ngay,den_ngay");const $query$$={id_app:$condition_req$$.id_app};$query$$.ngay_ct={$gte:$condition_req$$.tu_ngay,$lte:$condition_req$$.den_ngay};$condition_req$$.ma_dvcs&&($query$$.ma_dvcs=
3
- $condition_req$$.ma_dvcs);$condition_req$$.ma_kho&&($query$$.ma_kho=$condition_req$$.ma_kho);$condition_req$$.ma_kh&&($query$$.ma_kh=$condition_req$$.ma_kh);$condition_req$$.ma_ct&&($query$$.ma_ct=$condition_req$$.ma_ct);databanle($query$$,function($error$jscomp$0$$,$rs$$){if($error$jscomp$0$$)return $callback$jscomp$0$$($error$jscomp$0$$);async.mapSeries($rs$$,function($r$$,$callback$$){$r$$.t_sl_xuat=$r$$.details.csum("sl_xuat");$r$$.t_tien_hang=$r$$.details.csum("tien_hang");$r$$.t_tien_ck=$r$$.details.csum("tien_ck");
4
- $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$$.details_tl?($r$$.t_tien_tl=$r$$.details_tl.csum("tien"),$r$$.t_tien_nhap=$r$$.details_tl.csum("tien_nhap"),$r$$.t_sl_nhap=$r$$.details_tl.csum("sl_nhap")):($r$$.t_tien_tl=0,$r$$.t_sl_nhap=0,$r$$.t_tien_nhap=0);$callback$$(null,$r$$)},function($error$$,$rs$$){if($error$$)return $callback$jscomp$0$$($error$$);$error$$=underscore.sortBy($rs$$,
5
- function($r$$){return $r$$.ngay_ct});$error$$.forEach(function($r$$){$r$$.t_doanh_thu=$r$$.t_tien-($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_doanh_thu_thuan=$r$$.t_doanh_thu-$r$$.t_tien_tl;$r$$.t_tien_thu=($r$$.tien_thu||0)+($r$$.tien_thu2||0)});$callback$jscomp$0$$(null,$error$$)})})})};
2
+ module.exports=function($router$$){new controller($router$$,"databanle",async function($condition_req$$,$callback$jscomp$0$$){$condition_req$$=$condition_req$$.query;if(!$condition_req$$.tu_ngay||!$condition_req$$.den_ngay)return $callback$jscomp$0$$("B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1:tu_ngay,den_ngay");const $query$$={id_app:$condition_req$$.id_app};$query$$.ngay_ct={$gte:$condition_req$$.tu_ngay,$lte:$condition_req$$.den_ngay};$condition_req$$.ma_dvcs&&($query$$.ma_dvcs=
3
+ $condition_req$$.ma_dvcs);$condition_req$$.ma_kho&&($query$$.ma_kho=$condition_req$$.ma_kho);if($condition_req$$.ma_kh)$query$$.ma_kh=$condition_req$$.ma_kh;else{var $condition_kh_custs$$={};if($condition_req$$.nh_kh){var $nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$=await global.getModel("group").getAllChildrenGroup($condition_req$$.id_app,$condition_req$$.nh_kh,{status:!0});$condition_kh_custs$$.nh_kh={$in:$nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$}}$condition_req$$.nh_kh2&&($nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$=
4
+ await global.getModel("group").getAllChildrenGroup($condition_req$$.id_app,$condition_req$$.nh_kh2,{status:!0}),$condition_kh_custs$$.nh_kh2={$in:$nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$});$condition_req$$.nh_kh3&&($nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$=await global.getModel("group").getAllChildrenGroup($condition_req$$.id_app,$condition_req$$.nh_kh3,{status:!0}),$condition_kh_custs$$.nh_kh3={$in:$nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$});$condition_req$$.nh_kh4&&($nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$=
5
+ await global.getModel("group").getAllChildrenGroup($condition_req$$.id_app,$condition_req$$.nh_kh4,{status:!0}),$condition_kh_custs$$.nh_kh4={$in:$nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$});$condition_req$$.nh_kh5&&($nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$=await global.getModel("group").getAllChildrenGroup($condition_req$$.id_app,$condition_req$$.nh_kh5,{status:!0}),$condition_kh_custs$$.nh_kh5={$in:$nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$});0<Object.keys($condition_kh_custs$$).length&&($condition_kh_custs$$.id_app=
6
+ $condition_req$$.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_req$$.ma_ct&&($query$$.ma_ct=$condition_req$$.ma_ct);databanle($query$$,function($error$jscomp$0$$,$rs$$){if($error$jscomp$0$$)return $callback$jscomp$0$$($error$jscomp$0$$);async.mapSeries($rs$$,function($r$$,$callback$$){$r$$.t_sl_xuat=$r$$.details.csum("sl_xuat");$r$$.t_tien_hang=$r$$.details.csum("tien_hang");
7
+ $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");$r$$.t_tien_hoa_hong_ql=$r$$.details.csum("tien_hoa_hong_ql");$r$$.details_tl?($r$$.t_tien_tl=$r$$.details_tl.csum("tien"),
8
+ $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=0,$r$$.t_sl_nhap=0,$r$$.t_tien_nhap=0);$callback$$(null,$r$$)},function($error$$,$rs$$){if($error$$)return $callback$jscomp$0$$($error$$);
9
+ $error$$=underscore.sortBy($rs$$,function($r$$){return $r$$.ngay_ct});$error$$.forEach(function($r$$){$r$$.t_doanh_thu=$r$$.t_tien-($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_doanh_thu_thuan=$r$$.t_doanh_thu-$r$$.t_tien_tl;$r$$.t_tien_thu=($r$$.tien_thu||0)+($r$$.tien_thu2||0)});$callback$jscomp$0$$(null,$error$$)})})})};
@@ -1,11 +1,18 @@
1
1
  'use strict';const databanle=require("../../libs/databanle"),async=require("async"),underscore=require("underscore"),controller=require("../../controllers/controllerRPT");
2
2
  module.exports=function($router$$){new controller($router$$,"dtbanletheoct",async function($req$$,$callback$jscomp$0$$){const $condition$$=$req$$.query;if(!$condition$$.tu_ngay||!$condition$$.den_ngay)return $callback$jscomp$0$$("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};$query$$.ngay_ct={$gte:$condition$$.tu_ngay,$lte:$condition$$.den_ngay};$condition$$.ma_dvcs&&($query$$.ma_dvcs=$condition$$.ma_dvcs);$condition$$.ma_kho&&
3
- ($query$$.ma_kho=$condition$$.ma_kho);$condition$$.ma_kh&&($query$$.ma_kh=$condition$$.ma_kh);$condition$$.ma_ct&&($query$$.ma_ct=$condition$$.ma_ct);databanle($query$$,function($error$jscomp$2$$,$rs$$,$ptthanhtoans$$){if($error$jscomp$2$$)return $callback$jscomp$0$$($error$jscomp$2$$);const $thanh_toan$$=$ptthanhtoans$$.map($pt$$=>({name:$pt$$.ma,value:$pt$$.ma,ma:$pt$$.ma,ten:$pt$$.ten}));async.mapSeries($rs$$,function($r$$,$callback$$){$r$$.t_sl_xuat=$r$$.details.csum("sl_xuat");$r$$.t_tien_hang=
4
- $r$$.details.csum("tien_hang");$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$$.details_tl?($r$$.t_tien_tl=$r$$.details_tl.csum("tien"),$r$$.t_tien_nhap=$r$$.details_tl.csum("tien_nhap"),$r$$.t_sl_nhap=$r$$.details_tl.csum("sl_nhap")):($r$$.t_tien_tl=0,$r$$.t_sl_nhap=0,$r$$.t_tien_nhap=0);$r$$.tien_freeship=$r$$.tien_freeship||0;$r$$.tien_phi_vc=
5
- $r$$.tien_phi_vc||0;global.getModel("sokho").find({id_ct:$r$$._id}).lean().then($rs$$=>{$r$$.t_sl_xuat_kho=$rs$$.map($r$$=>$r$$.sl_xuat).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$callback$$(null,$r$$)})},function($error$jscomp$0$$,$rs$$){if($error$jscomp$0$$)return $callback$jscomp$0$$($error$jscomp$0$$);$condition$$.chi_hien_chua_post_sokho&&($rs$$=$rs$$.filter($r$$=>!$r$$.t_sl_xuat_kho));let $field_group_by$$=$req$$.query.group_by||["_id","so_ct","ngay_ct","ma_ct"];underscore.isString($field_group_by$$)&&
6
- ($field_group_by$$=[$field_group_by$$]);$error$jscomp$0$$=[{name:"t_sl_xuat",value:"t_sl_xuat"},{name:"t_sl_xuat_kho",value:"t_sl_xuat_kho"},{name:"t_sl_nhap",value:"t_sl_nhap"},{name:"t_tien_hang",value:"t_tien_hang"},{name:"t_tien_cp",value:"t_tien_cp"},{name:"tien_freeship",value:"tien_freeship"},{name:"tien_phi_vc",value:"tien_phi_vc"},{name:"t_tien_ck",value:"t_tien_ck"},{name:"t_tien",value:"t_tien"},{name:"tien_ck_hd",value:"tien_ck_hd"},{name:"tien_evoucher",value:"tien_evoucher"},{name:"tien_thu",
7
- 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_nhap",value:"t_tien_nhap"},{name:"phai_tra",value:"phai_tra"},...$thanh_toan$$];$rs$$.groupBy($field_group_by$$,$error$jscomp$0$$,function($error$$,$report$$){if($error$$)return $callback$jscomp$0$$($error$$);$report$$=$report$$.sort(($a$$,$b$$)=>{for(let $i$$=0;$i$$<$field_group_by$$.length;$i$$++){let $field$$=
8
- $field_group_by$$[$i$$];if($a$$[$field$$]<$b$$[$field$$])return-1;if($a$$[$field$$]>$b$$[$field$$])return 1}return 0});$report$$.forEach(function($r$$,$i$$){$r$$.stt=$i$$+1;$r$$.bold=!1;$r$$.t_tien_paymentByPoints=$r$$.tien_paymentByPoints||0;$r$$.t_doanh_thu=$r$$.t_tien+$r$$.tien_phi_vc-$r$$.tien_freeship-($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_doanh_thu_thuan=$r$$.t_doanh_thu-$r$$.t_tien_tl;$r$$.t_tien_thu=
9
- $thanh_toan$$.map($pt$$=>$r$$[$pt$$.name]||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0)});const $tong_cong$$={[$field_group_by$$[0]]:"T\u1ed5ng c\u1ed9ng",t_sl_xuat:$report$$.csum("t_sl_xuat"),t_sl_xuat_kho:$report$$.csum("t_sl_xuat_kho"),t_sl_nhap:$report$$.csum("t_sl_nhap"),t_tien_hang:$report$$.csum("t_tien_hang"),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"),
10
- t_tien_tl:$report$$.csum("t_tien_tl"),t_tien_xuat:$report$$.csum("t_tien_xuat"),t_tien_nhap:$report$$.csum("t_tien_nhap"),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"),
11
- bold:!0};$thanh_toan$$.forEach($pt$$=>{$pt$$.tong_cong=$tong_cong$$[$pt$$.name]=$report$$.csum($pt$$.name)});$report$$.push($tong_cong$$);$callback$jscomp$0$$(null,{data:$report$$,thanh_toan:$thanh_toan$$.filter($t$$=>$t$$.tong_cong)})})})})})};
3
+ ($query$$.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});$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,
4
+ $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={$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,
5
+ {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$$});0<Object.keys($condition_kh_custs$$).length&&($condition_kh_custs$$.id_app=$condition$$.id_app,$condition_kh_custs$$=await global.getModel("customer").find($condition_kh_custs$$,
6
+ {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=[{user_nv:$condition$$.user_hoa_hong},{user_ctv:$condition$$.user_hoa_hong},{user_gt:$condition$$.user_hoa_hong},{user_ql:$condition$$.user_hoa_hong}]);databanle($query$$,function($error$jscomp$2$$,$rs$$,$ptthanhtoans$$){if($error$jscomp$2$$)return $callback$jscomp$0$$($error$jscomp$2$$);const $thanh_toan$$=$ptthanhtoans$$.map($pt$$=>
7
+ ({name:$pt$$.ma,value:$pt$$.ma,ma:$pt$$.ma,ten:$pt$$.ten}));async.mapSeries($rs$$,function($r$$,$callback$$){$r$$.t_sl_xuat=$r$$.details.csum("sl_xuat");$r$$.t_tien_hang=$r$$.details.csum("tien_hang");$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=$condition$$.user_hoa_hong&&$r$$.user_nv!==$condition$$.user_hoa_hong?
8
+ 0:$r$$.details.csum("tien_hoa_hong");$r$$.t_tien_hoa_hong_gt=$condition$$.user_hoa_hong&&$r$$.user_gt!==$condition$$.user_hoa_hong?0:$r$$.details.csum("tien_hoa_hong_gt");$r$$.t_tien_hoa_hong_ctv=$condition$$.user_hoa_hong&&$r$$.user_ctv!==$condition$$.user_hoa_hong?0:$r$$.details.csum("tien_hoa_hong_ctv");$r$$.t_tien_hoa_hong_ql=$condition$$.user_hoa_hong&&$r$$.user_ql!==$condition$$.user_hoa_hong?0:$r$$.details.csum("tien_hoa_hong_ql");$r$$.details_tl?($r$$.t_tien_tl=$r$$.details_tl.csum("tien"),
9
+ $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.map($d$$=>$condition$$.user_hoa_hong&&$d$$.user_nv!==$condition$$.user_hoa_hong?0:$d$$.tien_hoa_hong).reduce(($a$$,$b$$)=>($a$$||0)+($b$$||0),0),$r$$.t_tien_hoa_hong_gt-=$r$$.details_tl.map($d$$=>$condition$$.user_hoa_hong&&$d$$.user_gt!==$condition$$.user_hoa_hong?0:$d$$.tien_hoa_hong_gt).reduce(($a$$,$b$$)=>($a$$||0)+($b$$||0),0),$r$$.t_tien_hoa_hong_ctv-=$r$$.details_tl.map($d$$=>
10
+ $condition$$.user_hoa_hong&&$d$$.user_ctv!==$condition$$.user_hoa_hong?0:$d$$.tien_hoa_hong_ctv).reduce(($a$$,$b$$)=>($a$$||0)+($b$$||0),0),$r$$.t_tien_hoa_hong_ql-=$r$$.details_tl.map($d$$=>$condition$$.user_hoa_hong&&$d$$.user_ql!==$condition$$.user_hoa_hong?0:$d$$.tien_hoa_hong_ql).reduce(($a$$,$b$$)=>($a$$||0)+($b$$||0),0)):($r$$.t_tien_tl=0,$r$$.t_sl_nhap=0,$r$$.t_tien_nhap=0);$r$$.tien_freeship=$r$$.tien_freeship||0;$r$$.tien_phi_vc=$r$$.tien_phi_vc||0;global.getModel("sokho").find({id_ct:$r$$._id}).lean().then($rs$$=>
11
+ {$r$$.t_sl_xuat_kho=$rs$$.map($r$$=>$r$$.sl_xuat).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$callback$$(null,$r$$)})},function($error$jscomp$0$$,$rs$$){if($error$jscomp$0$$)return $callback$jscomp$0$$($error$jscomp$0$$);$condition$$.chi_hien_chua_post_sokho&&($rs$$=$rs$$.filter($r$$=>!$r$$.t_sl_xuat_kho));let $field_group_by$$=$req$$.query.group_by||["_id","so_ct","ngay_ct","ma_ct"];underscore.isString($field_group_by$$)&&($field_group_by$$=[$field_group_by$$]);$error$jscomp$0$$=[{name:"t_sl_xuat",value:"t_sl_xuat"},
12
+ {name:"t_sl_xuat_kho",value:"t_sl_xuat_kho"},{name:"t_sl_nhap",value:"t_sl_nhap"},{name:"t_tien_hang",value:"t_tien_hang"},{name:"t_tien_cp",value:"t_tien_cp"},{name:"tien_freeship",value:"tien_freeship"},{name:"tien_phi_vc",value:"tien_phi_vc"},{name:"t_tien_ck",value:"t_tien_ck"},{name:"t_tien",value:"t_tien"},{name:"tien_ck_hd",value:"tien_ck_hd"},{name:"tien_evoucher",value:"tien_evoucher"},{name:"tien_thu",value:"tien_thu"},{name:"tien_thu2",value:"tien_thu2"},{name:"tien_paymentByPoints",value:"tien_paymentByPoints"},
13
+ {name:"t_tien_xuat",value:"t_tien_xuat"},{name:"t_tien_tl",value:"t_tien_tl"},{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"},...$thanh_toan$$];$rs$$.groupBy($field_group_by$$,$error$jscomp$0$$,function($error$$,$report$$){if($error$$)return $callback$jscomp$0$$($error$$);
14
+ $report$$=$report$$.sort(($a$$,$b$$)=>{for(let $i$$=0;$i$$<$field_group_by$$.length;$i$$++){let $field$$=$field_group_by$$[$i$$];if($a$$[$field$$]<$b$$[$field$$])return-1;if($a$$[$field$$]>$b$$[$field$$])return 1}return 0});$report$$.forEach(function($r$$,$i$$){$r$$.stt=$i$$+1;$r$$.bold=!1;$r$$.t_tien_paymentByPoints=$r$$.tien_paymentByPoints||0;$r$$.t_doanh_thu=$r$$.t_tien+$r$$.tien_phi_vc-$r$$.tien_freeship-($r$$.tien_ck_hd||0)-($r$$.tien_evoucher||0);$r$$.t_lai=$r$$.t_doanh_thu-$r$$.t_tien_xuat-
15
+ ($r$$.t_tien_tl-$r$$.t_tien_nhap);$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$$,0);$r$$.t_hoa_hong=$r$$.t_tien_hoa_hong+$r$$.t_tien_hoa_hong_gt+$r$$.t_tien_hoa_hong_ctv+$r$$.t_tien_hoa_hong_ql});const $tong_cong$$={[$field_group_by$$[0]]:"T\u1ed5ng c\u1ed9ng",t_sl_xuat:$report$$.csum("t_sl_xuat"),t_sl_xuat_kho:$report$$.csum("t_sl_xuat_kho"),t_sl_nhap:$report$$.csum("t_sl_nhap"),t_tien_hang:$report$$.csum("t_tien_hang"),
16
+ 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_xuat:$report$$.csum("t_tien_xuat"),t_tien_nhap:$report$$.csum("t_tien_nhap"),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"),
17
+ 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"),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_hoa_hong:$report$$.csum("t_hoa_hong"),bold:!0};$thanh_toan$$.forEach($pt$$=>
18
+ {$pt$$.tong_cong=$tong_cong$$[$pt$$.name]=$report$$.csum($pt$$.name)});$report$$.push($tong_cong$$);$callback$jscomp$0$$(null,{data:$report$$,thanh_toan:$thanh_toan$$.filter($t$$=>$t$$.tong_cong)})})})})})};
@@ -1,10 +1,16 @@
1
1
  'use strict';const databanle=require("../../libs/databanle"),dmkh=global.getModel("customer"),introducer=global.getModel("introducer"),async=require("async"),controller=require("../../controllers/controllerRPT");
2
2
  module.exports=function($router$$){new controller($router$$,"dtbanletheokh",async($query_req$$,$callback$jscomp$0$$)=>{const $condition$$=$query_req$$.query;if(!$condition$$.tu_ngay||!$condition$$.den_ngay)return $callback$jscomp$0$$("B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1:tu_ngay,den_ngay");$query_req$$={id_app:$condition$$.id_app};$query_req$$.ngay_ct={$gte:$condition$$.tu_ngay,$lte:$condition$$.den_ngay};$condition$$.ma_dvcs&&($query_req$$.ma_dvcs=$condition$$.ma_dvcs);
3
- $condition$$.ma_kh&&($query_req$$.ma_kh=$condition$$.ma_kh);$condition$$.ma_kho&&($query_req$$.ma_kho=$condition$$.ma_kho);$condition$$.ma_ct&&($query_req$$.ma_ct=$condition$$.ma_ct);if($condition$$.be_introduced_by){let $users$$=(await introducer.find({id_app:$condition$$.id_app,be_introduced_by:$condition$$.be_introduced_by},{be_introduced:1})).map($u$$=>$u$$.be_introduced);$query_req$$.user_created={$in:$users$$}}$condition$$.ma_ct&&($query_req$$.ma_ct=$condition$$.ma_ct);databanle($query_req$$,
4
- function($error$jscomp$2$$,$rs$$,$ptthanhtoans$$){if($error$jscomp$2$$)return $callback$jscomp$0$$($error$jscomp$2$$);const $thanh_toan$$=$ptthanhtoans$$.map($pt$$=>({name:$pt$$.ma,value:$pt$$.ma,ma:$pt$$.ma,ten:$pt$$.ten}));async.mapSeries($rs$$,function($r$$,$callback$$){$r$$.t_sl_xuat=$r$$.details.csum("sl_xuat");$r$$.t_tien_hang=$r$$.details.csum("tien_hang");$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=
5
- $r$$.tien_ck_hd?$r$$.tien_ck_hd:0;$r$$.t_tien_xuat=$r$$.details.csum("tien_xuat");$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"),$r$$.t_tien_nhap=$r$$.details_tl.csum("tien_nhap"),$r$$.t_sl_nhap=$r$$.details_tl.csum("sl_nhap")):($r$$.t_tien_tl=0,$r$$.t_sl_nhap=0,$r$$.t_tien_nhap=0);$r$$.t_so_bill="HD7"!==$r$$.so_ct?1:0;$callback$$(null,$r$$)},function($error$jscomp$0$$,$rs$$){if($error$jscomp$0$$)return $callback$jscomp$0$$($error$jscomp$0$$);
6
- $rs$$.groupBy("ma_kh",[{name:"t_so_bill",value:"t_so_bill"},{name:"t_sl_xuat",value:"t_sl_xuat"},{name:"t_tien_hang",value:"t_tien_hang"},{name:"t_tien_cp",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",
7
- value:"tien_paymentByPoints"},{name:"t_tien_xuat",value:"t_tien_xuat"},{name:"t_sl_nhap",value:"t_sl_nhap"},{name:"t_tien_tl",value:"t_tien_tl"},{name:"t_tien_nhap",value:"t_tien_nhap"},{name:"phai_tra",value:"phai_tra"},...$thanh_toan$$],async($error$$,$report$$)=>{if($error$$)return $callback$jscomp$0$$($error$$);$report$$.forEach(($r$$,$i$$)=>{$r$$.stt=$i$$+1;$r$$.bold=!1;$r$$.t_doanh_thu=$r$$.t_tien+$r$$.tien_phi_vc-$r$$.tien_freeship-($r$$.tien_ck_hd||0)-($r$$.tien_evoucher||0);$r$$.t_doanh_thu_thuan=
3
+ if($condition$$.ma_kh)$query_req$$.ma_kh=$condition$$.ma_kh;else{var $condition_kh_custs_users$$={};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});$condition_kh_custs_users$$.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,
4
+ {status:!0}),$condition_kh_custs_users$$.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_users$$.nh_kh3={$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,
5
+ {status:!0}),$condition_kh_custs_users$$.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_users$$.nh_kh5={$in:$nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$});0<Object.keys($condition_kh_custs_users$$).length&&($condition_kh_custs_users$$.id_app=$condition$$.id_app,$condition_kh_custs_users$$=await global.getModel("customer").find($condition_kh_custs_users$$,
6
+ {ma_kh:1}).lean(),$query_req$$.ma_kh={$in:$condition_kh_custs_users$$.map($c$$=>$c$$.ma_kh)})}$condition$$.ma_kho&&($query_req$$.ma_kho=$condition$$.ma_kho);$condition$$.ma_ct&&($query_req$$.ma_ct=$condition$$.ma_ct);$condition$$.be_introduced_by&&($condition_kh_custs_users$$=(await introducer.find({id_app:$condition$$.id_app,be_introduced_by:$condition$$.be_introduced_by},{be_introduced:1})).map($u$$=>$u$$.be_introduced),$query_req$$.user_created={$in:$condition_kh_custs_users$$});$condition$$.ma_ct&&
7
+ ($query_req$$.ma_ct=$condition$$.ma_ct);$condition$$.user_hoa_hong&&($query_req$$.$or=[{user_nv:$condition$$.user_hoa_hong},{user_ctv:$condition$$.user_hoa_hong},{user_gt:$condition$$.user_hoa_hong},{user_ql:$condition$$.user_hoa_hong}]);databanle($query_req$$,function($error$jscomp$2$$,$rs$$,$ptthanhtoans$$){if($error$jscomp$2$$)return $callback$jscomp$0$$($error$jscomp$2$$);const $thanh_toan$$=$ptthanhtoans$$.map($pt$$=>({name:$pt$$.ma,value:$pt$$.ma,ma:$pt$$.ma,ten:$pt$$.ten}));async.mapSeries($rs$$,
8
+ function($r$$,$callback$$){$r$$.t_sl_xuat=$r$$.details.csum("sl_xuat");$r$$.t_tien_hang=$r$$.details.csum("tien_hang");$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?$r$$.tien_ck_hd:0;$r$$.t_tien_xuat=$r$$.details.csum("tien_xuat");$r$$.tien_freeship=$r$$.tien_freeship||0;$r$$.tien_phi_vc=$r$$.tien_phi_vc||0;$r$$.t_tien_hoa_hong=$r$$.details.csum("tien_hoa_hong");$r$$.t_tien_hoa_hong_gt=
9
+ $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$$.details_tl?($r$$.t_tien_tl=$r$$.details_tl.csum("tien"),$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"),
10
+ $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$$.t_so_bill="HD7"!==$r$$.so_ct?1:0;$callback$$(null,$r$$)},function($error$jscomp$0$$,$rs$$){if($error$jscomp$0$$)return $callback$jscomp$0$$($error$jscomp$0$$);$rs$$.groupBy("ma_kh",[{name:"t_so_bill",value:"t_so_bill"},{name:"t_sl_xuat",value:"t_sl_xuat"},{name:"t_tien_hang",value:"t_tien_hang"},{name:"t_tien_cp",value:"t_tien_cp"},{name:"t_tien_ck",value:"t_tien_ck"},{name:"t_tien",
11
+ 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_sl_nhap",value:"t_sl_nhap"},{name:"t_tien_tl",value:"t_tien_tl"},{name:"t_tien_nhap",value:"t_tien_nhap"},{name:"phai_tra",value:"phai_tra"},
12
+ {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"},...$thanh_toan$$],async($error$$,$report$$)=>{if($error$$)return $callback$jscomp$0$$($error$$);$report$$.forEach(($r$$,$i$$)=>{$r$$.stt=$i$$+1;$r$$.bold=!1;$r$$.t_doanh_thu=$r$$.t_tien+$r$$.tien_phi_vc-$r$$.tien_freeship-($r$$.tien_ck_hd||0)-($r$$.tien_evoucher||0);$r$$.t_doanh_thu_thuan=
8
13
  $r$$.t_doanh_thu-$r$$.t_tien_tl;$r$$.t_lai=$r$$.t_doanh_thu-$r$$.t_tien_xuat-($r$$.t_tien_tl-$r$$.t_tien_nhap);$r$$.t_tien_thu=$thanh_toan$$.map($pt$$=>$r$$[$pt$$.ma]||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$r$$.t_tien_paymentByPoints=$r$$.tien_paymentByPoints||0});await $report$$.asyncJoinModel2($condition$$.id_app,dmkh,[{where:"ma_kh",fields:["ten_kh","dia_chi"]}]);const $tong_cong$$={ten_kh:"T\u1ed5ng c\u1ed9ng",t_so_bill:$report$$.csum("t_so_bill"),t_sl_xuat:$report$$.csum("t_sl_xuat"),t_tien_hang:$report$$.csum("t_tien_hang"),
9
14
  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_xuat:$report$$.csum("t_tien_xuat"),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"),
10
- phai_tra:$report$$.csum("phai_tra"),t_tien_paymentByPoints:$report$$.csum("tien_paymentByPoints"),t_sl_nhap:$report$$.csum("t_sl_nhap"),t_tien_nhap:$report$$.csum("t_tien_nhap"),t_tien_tl:$report$$.csum("t_tien_tl"),t_lai:$report$$.csum("t_lai"),bold:!0};$thanh_toan$$.forEach($pt$$=>{$pt$$.tong_cong=$tong_cong$$[$pt$$.ma]=$report$$.csum($pt$$.ma)});$report$$.push($tong_cong$$);$callback$jscomp$0$$(null,{data:$report$$,thanh_toan:$thanh_toan$$.filter($t$$=>$t$$.tong_cong)})})})})})};
15
+ phai_tra:$report$$.csum("phai_tra"),t_tien_paymentByPoints:$report$$.csum("tien_paymentByPoints"),t_sl_nhap:$report$$.csum("t_sl_nhap"),t_tien_nhap:$report$$.csum("t_tien_nhap"),t_tien_tl:$report$$.csum("t_tien_tl"),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"),bold:!0};$thanh_toan$$.forEach($pt$$=>
16
+ {$pt$$.tong_cong=$tong_cong$$[$pt$$.ma]=$report$$.csum($pt$$.ma)});$report$$.push($tong_cong$$);$callback$jscomp$0$$(null,{data:$report$$,thanh_toan:$thanh_toan$$.filter($t$$=>$t$$.tong_cong)})})})})})};
@@ -1,10 +1,15 @@
1
1
  'use strict';const databanle=require("../../libs/databanle"),dmkho=global.getModel("dmkho"),async=require("async"),controller=require("../../controllers/controllerRPT");
2
- module.exports=function($router$$){new controller($router$$,"dtbanletheokho",function($query_req$$,$callback$jscomp$0$$){const $condition$$=$query_req$$.query;if(!$condition$$.tu_ngay||!$condition$$.den_ngay)return $callback$jscomp$0$$("B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1:tu_ngay,den_ngay");$query_req$$={id_app:$condition$$.id_app};$query_req$$.ngay_ct={$gte:$condition$$.tu_ngay,$lte:$condition$$.den_ngay};$condition$$.ma_dvcs&&($query_req$$.ma_dvcs=$condition$$.ma_dvcs);
3
- $condition$$.ma_kh&&($query_req$$.ma_kh=$condition$$.ma_kh);$condition$$.ma_kho&&($query_req$$.ma_kho=$condition$$.ma_kho);$condition$$.ma_ct&&($query_req$$.ma_ct=$condition$$.ma_ct);databanle($query_req$$,function($error$jscomp$2$$,$rs$$,$ptthanhtoans$$){if($error$jscomp$2$$)return $callback$jscomp$0$$($error$jscomp$2$$);const $thanh_toan$$=$ptthanhtoans$$.map($pt$$=>({name:$pt$$.ma,value:$pt$$.ma,ma:$pt$$.ma,ten:$pt$$.ten}));async.mapSeries($rs$$,function($r$$,$callback$$){$r$$.t_sl_xuat=$r$$.details.csum("sl_xuat");
4
- $r$$.t_tien_hang=$r$$.details.csum("tien_hang");$r$$.t_tien_ck=$r$$.details.csum("tien_ck");$r$$.t_tien_cp=$r$$.details.csum("tien_cp");$r$$.t_tien=$r$$.details.csum("tien");$r$$.tien_ck_hd=$r$$.tien_ck_hd||0;$r$$.t_tien_xuat=$r$$.details.csum("tien_xuat");$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"),$r$$.t_tien_nhap=$r$$.details_tl.csum("tien_nhap"),$r$$.t_sl_nhap=$r$$.details_tl.csum("sl_nhap")):($r$$.t_tien_tl=
5
- 0,$r$$.t_sl_nhap=0,$r$$.t_tien_nhap=0);$callback$$(null,$r$$)},function($error$jscomp$0$$,$rs$$){if($error$jscomp$0$$)return $callback$jscomp$0$$($error$jscomp$0$$);$rs$$.groupBy("ma_kho",[{name:"t_sl_xuat",value:"t_sl_xuat"},{name:"t_tien_hang",value:"t_tien_hang"},{name:"t_tien_cp",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",
6
- 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_sl_nhap",value:"t_sl_nhap"},{name:"t_tien_tl",value:"t_tien_tl"},{name:"t_tien_nhap",value:"t_tien_nhap"},{name:"phai_tra",value:"phai_tra"},...$thanh_toan$$],function($error$$,$report$$){if($error$$)return $callback$jscomp$0$$($error$$);let $i$$=1;$report$$.forEach(function($r$$){$r$$.stt=$i$$;$r$$.bold=
7
- !1;$r$$.t_doanh_thu=$r$$.t_tien+$r$$.tien_phi_vc-$r$$.tien_freeship-($r$$.tien_ck_hd||0)-($r$$.tien_evoucher||0);$r$$.t_doanh_thu_thuan=$r$$.t_doanh_thu-$r$$.t_tien_tl;$r$$.t_lai=$r$$.t_doanh_thu-$r$$.t_tien_xuat-($r$$.t_tien_tl-$r$$.t_tien_nhap);$r$$.t_tien_thu=$thanh_toan$$.map($pt$$=>$r$$[$pt$$.ma]||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$r$$.t_tien_paymentByPoints=$r$$.tien_paymentByPoints||0;$i$$++});$report$$.joinModel2($condition$$.id_app,dmkho,[{where:"ma_kho",fields:"ten_kho"}],function(){const $tong_cong$$=
8
- {ten_kho:"T\u1ed5ng c\u1ed9ng",t_sl_xuat:$report$$.csum("t_sl_xuat"),t_tien_hang:$report$$.csum("t_tien_hang"),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_xuat:$report$$.csum("t_tien_xuat"),t_doanh_thu:$report$$.csum("t_doanh_thu"),t_sl_nhap:$report$$.csum("t_sl_nhap"),t_tien_nhap:$report$$.csum("t_tien_nhap"),
9
- t_tien_tl:$report$$.csum("t_tien_tl"),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"),bold:!0};$thanh_toan$$.forEach($pt$$=>{$pt$$.tong_cong=$tong_cong$$[$pt$$.ma]=$report$$.csum($pt$$.ma)});$report$$.push($tong_cong$$);
10
- $callback$jscomp$0$$(null,{data:$report$$,thanh_toan:$thanh_toan$$.filter($t$$=>$t$$.tong_cong)})})})})})})};
2
+ module.exports=function($router$$){new controller($router$$,"dtbanletheokho",async function($query_req$$,$callback$jscomp$0$$){const $condition$$=$query_req$$.query;if(!$condition$$.tu_ngay||!$condition$$.den_ngay)return $callback$jscomp$0$$("B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1:tu_ngay,den_ngay");$query_req$$={id_app:$condition$$.id_app};$query_req$$.ngay_ct={$gte:$condition$$.tu_ngay,$lte:$condition$$.den_ngay};$condition$$.ma_dvcs&&($query_req$$.ma_dvcs=$condition$$.ma_dvcs);
3
+ if($condition$$.ma_kh)$query_req$$.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});$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}),
4
+ $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={$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=
5
+ {$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$$});0<Object.keys($condition_kh_custs$$).length&&($condition_kh_custs$$.id_app=$condition$$.id_app,$condition_kh_custs$$=await global.getModel("customer").find($condition_kh_custs$$,{ma_kh:1}).lean(),$query_req$$.ma_kh=
6
+ {$in:$condition_kh_custs$$.map($c$$=>$c$$.ma_kh)})}$condition$$.ma_kho&&($query_req$$.ma_kho=$condition$$.ma_kho);$condition$$.ma_ct&&($query_req$$.ma_ct=$condition$$.ma_ct);$condition$$.user_hoa_hong&&($query_req$$.$or=[{user_nv:$condition$$.user_hoa_hong},{user_ctv:$condition$$.user_hoa_hong},{user_gt:$condition$$.user_hoa_hong},{user_ql:$condition$$.user_hoa_hong}]);databanle($query_req$$,function($error$jscomp$2$$,$rs$$,$ptthanhtoans$$){if($error$jscomp$2$$)return $callback$jscomp$0$$($error$jscomp$2$$);
7
+ const $thanh_toan$$=$ptthanhtoans$$.map($pt$$=>({name:$pt$$.ma,value:$pt$$.ma,ma:$pt$$.ma,ten:$pt$$.ten}));async.mapSeries($rs$$,function($r$$,$callback$$){$r$$.t_sl_xuat=$r$$.details.csum("sl_xuat");$r$$.t_tien_hang=$r$$.details.csum("tien_hang");$r$$.t_tien_ck=$r$$.details.csum("tien_ck");$r$$.t_tien_cp=$r$$.details.csum("tien_cp");$r$$.t_tien=$r$$.details.csum("tien");$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");
8
+ $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?($r$$.t_tien_tl=$r$$.details_tl.csum("tien"),$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-=
9
+ $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=0,$r$$.t_sl_nhap=0,$r$$.t_tien_nhap=0);$callback$$(null,$r$$)},function($error$jscomp$0$$,$rs$$){if($error$jscomp$0$$)return $callback$jscomp$0$$($error$jscomp$0$$);$rs$$.groupBy("ma_kho",[{name:"t_sl_xuat",value:"t_sl_xuat"},{name:"t_tien_hang",value:"t_tien_hang"},{name:"t_tien_cp",value:"t_tien_cp"},{name:"t_tien_ck",
10
+ 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_sl_nhap",value:"t_sl_nhap"},{name:"t_tien_tl",value:"t_tien_tl"},{name:"t_tien_nhap",value:"t_tien_nhap"},
11
+ {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"},...$thanh_toan$$],function($error$$,$report$$){if($error$$)return $callback$jscomp$0$$($error$$);let $i$$=1;$report$$.forEach(function($r$$){$r$$.stt=$i$$;$r$$.bold=!1;$r$$.t_doanh_thu=$r$$.t_tien+$r$$.tien_phi_vc-$r$$.tien_freeship-($r$$.tien_ck_hd||
12
+ 0)-($r$$.tien_evoucher||0);$r$$.t_doanh_thu_thuan=$r$$.t_doanh_thu-$r$$.t_tien_tl;$r$$.t_lai=$r$$.t_doanh_thu-$r$$.t_tien_xuat-($r$$.t_tien_tl-$r$$.t_tien_nhap);$r$$.t_tien_thu=$thanh_toan$$.map($pt$$=>$r$$[$pt$$.ma]||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$r$$.t_tien_paymentByPoints=$r$$.tien_paymentByPoints||0;$i$$++});$report$$.joinModel2($condition$$.id_app,dmkho,[{where:"ma_kho",fields:"ten_kho"}],function(){const $tong_cong$$={ten_kho:"T\u1ed5ng c\u1ed9ng",t_sl_xuat:$report$$.csum("t_sl_xuat"),
13
+ t_tien_hang:$report$$.csum("t_tien_hang"),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_xuat:$report$$.csum("t_tien_xuat"),t_doanh_thu:$report$$.csum("t_doanh_thu"),t_sl_nhap:$report$$.csum("t_sl_nhap"),t_tien_nhap:$report$$.csum("t_tien_nhap"),t_tien_tl:$report$$.csum("t_tien_tl"),t_doanh_thu_thuan:$report$$.csum("t_doanh_thu_thuan"),
14
+ 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"),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"),
15
+ bold:!0};$thanh_toan$$.forEach($pt$$=>{$pt$$.tong_cong=$tong_cong$$[$pt$$.ma]=$report$$.csum($pt$$.ma)});$report$$.push($tong_cong$$);$callback$jscomp$0$$(null,{data:$report$$,thanh_toan:$thanh_toan$$.filter($t$$=>$t$$.tong_cong)})})})})})})};
@@ -1,10 +1,16 @@
1
1
  'use strict';const databanle=require("../../libs/databanle"),async=require("async"),underscore=require("underscore"),controller=require("../../controllers/controllerRPT"),moment=require("moment");
2
- module.exports=function($router$$){new controller($router$$,"dtbanletheonam",function($condition_req$$,$callback$jscomp$0$$){$condition_req$$=$condition_req$$.query;if(!$condition_req$$.tu_nam||!$condition_req$$.den_nam)return $callback$jscomp$0$$("B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1:tu_nam,den_nam");const $query$$={id_app:$condition_req$$.id_app},$tu_ngay$$=moment(new Date($condition_req$$.tu_nam,5,15)).startOf("year").toDate(),$den_ngay$$=moment(new Date($condition_req$$.den_nam,
3
- 5,15)).endOf("year").toDate();$query$$.ngay_ct={$gte:$tu_ngay$$,$lte:$den_ngay$$};$condition_req$$.ma_dvcs&&($query$$.ma_dvcs=$condition_req$$.ma_dvcs);$condition_req$$.ma_kho&&($query$$.ma_kho=$condition_req$$.ma_kho);$condition_req$$.ma_ct&&($query$$.ma_ct=$condition_req$$.ma_ct);databanle($query$$,function($error$jscomp$2$$,$rs$$,$ptthanhtoans$$){if($error$jscomp$2$$)return $callback$jscomp$0$$($error$jscomp$2$$);const $thanh_toan$$=$ptthanhtoans$$.map($pt$$=>({name:$pt$$.ma,value:$pt$$.ma,ma:$pt$$.ma,
4
- ten:$pt$$.ten}));$rs$$.forEach(function($r$$){$r$$.nam=$r$$.ngay_ct.getFullYear()});async.mapSeries($rs$$,function($r$$,$callback$$){$r$$.t_sl_xuat=$r$$.details.csum("sl_xuat");$r$$.t_tien_hang=$r$$.details.csum("tien_hang");$r$$.t_tien_cp=$r$$.details.csum("tien_cp");$r$$.t_tien_ck=$r$$.details.csum("tien_ck");$r$$.t_tien=$r$$.details.csum("tien");$r$$.tien_freeship=$r$$.tien_freeship||0;$r$$.tien_phi_vc=$r$$.tien_phi_vc||0;$r$$.tien_ck_hd=$r$$.tien_ck_hd?$r$$.tien_ck_hd:0;$r$$.t_tien_xuat=$r$$.details.csum("tien_xuat");
5
- $r$$.details_tl?($r$$.t_tien_tl=$r$$.details_tl.csum("tien"),$r$$.t_tien_nhap=$r$$.details_tl.csum("tien_nhap"),$r$$.t_sl_nhap=$r$$.details_tl.csum("sl_nhap")):($r$$.t_tien_tl=0,$r$$.t_sl_nhap=0,$r$$.t_tien_nhap=0);$callback$$(null,$r$$)},function($error$jscomp$0$$,$rs$jscomp$0$$){if($error$jscomp$0$$)return $callback$jscomp$0$$($error$jscomp$0$$);$rs$jscomp$0$$.groupBy("nam",[{name:"t_sl_xuat",value:"t_sl_xuat"},{name:"t_tien_hang",value:"t_tien_hang"},{name:"t_tien_cp",value:"t_tien_cp"},{name:"t_tien_ck",
6
- 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_sl_nhap",value:"t_sl_nhap"},{name:"t_tien_tl",value:"t_tien_tl"},{name:"t_tien_nhap",value:"t_tien_nhap"},
7
- {name:"phai_tra",value:"phai_tra"},...$thanh_toan$$],function($error$$,$rs$$){if($error$$)return $callback$jscomp$0$$($error$$);const $report$$=underscore.sortBy($rs$$,function($r$$){return Number($r$$.nam)});let $i$$=1;$report$$.forEach(function($r$$){$r$$.stt=$i$$;$r$$.bold=!1;$r$$.t_doanh_thu=$r$$.t_tien+$r$$.tien_phi_vc-$r$$.tien_freeship-($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_doanh_thu_thuan=$r$$.t_doanh_thu-
8
- $r$$.t_tien_tl;$r$$.t_tien_thu=$thanh_toan$$.map($pt$$=>$r$$[$pt$$.ma]||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$r$$.tu_ngay=moment([$r$$.nam,0,1]).startOf("year").toDate();$r$$.den_ngay=moment([$r$$.nam,0,1]).endOf("year").toDate();$r$$.t_tien_paymentByPoints=$r$$.tien_paymentByPoints||0;$i$$++});const $tong_cong$$={nam:"T\u1ed5ng c\u1ed9ng",t_sl_xuat:$report$$.csum("t_sl_xuat"),t_tien_hang:$report$$.csum("t_tien_hang"),t_tien_cp:$report$$.csum("t_tien_cp"),t_tien_ck:$report$$.csum("t_tien_ck"),t_tien:$report$$.csum("t_tien"),
9
- tien_ck_hd:$report$$.csum("tien_ck_hd"),tien_phi_vc:$report$$.csum("tien_phi_vc"),tien_freeship:$report$$.csum("tien_freeship"),t_tien_xuat:$report$$.csum("t_tien_xuat"),t_doanh_thu:$report$$.csum("t_doanh_thu"),t_sl_nhap:$report$$.csum("t_sl_nhap"),t_tien_tl:$report$$.csum("t_tien_tl"),t_tien_nhap:$report$$.csum("t_tien_nhap"),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"),
10
- 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"),bold:!0};$thanh_toan$$.forEach($pt$$=>{$pt$$.tong_cong=$tong_cong$$[$pt$$.ma]=$report$$.csum($pt$$.ma)});$report$$.push($tong_cong$$);$callback$jscomp$0$$(null,{data:$report$$,thanh_toan:$thanh_toan$$.filter($t$$=>$t$$.tong_cong)})})})})})};
2
+ module.exports=function($router$$){new controller($router$$,"dtbanletheonam",async function($condition_req$$,$callback$jscomp$0$$){$condition_req$$=$condition_req$$.query;if(!$condition_req$$.tu_nam||!$condition_req$$.den_nam)return $callback$jscomp$0$$("B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1:tu_nam,den_nam");const $query$$={id_app:$condition_req$$.id_app};var $condition_kh_custs_tu_ngay$$=moment(new Date($condition_req$$.tu_nam,5,15)).startOf("year").toDate(),$den_ngay_nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$=
3
+ moment(new Date($condition_req$$.den_nam,5,15)).endOf("year").toDate();$query$$.ngay_ct={$gte:$condition_kh_custs_tu_ngay$$,$lte:$den_ngay_nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$};$condition_req$$.ma_dvcs&&($query$$.ma_dvcs=$condition_req$$.ma_dvcs);$condition_req$$.ma_kho&&($query$$.ma_kho=$condition_req$$.ma_kho);$condition_req$$.ma_kh?$query$$.ma_kh=$condition_req$$.ma_kh:($condition_kh_custs_tu_ngay$$={},$condition_req$$.nh_kh&&($den_ngay_nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$=await global.getModel("group").getAllChildrenGroup($condition_req$$.id_app,
4
+ $condition_req$$.nh_kh,{status:!0}),$condition_kh_custs_tu_ngay$$.nh_kh={$in:$den_ngay_nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$}),$condition_req$$.nh_kh2&&($den_ngay_nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$=await global.getModel("group").getAllChildrenGroup($condition_req$$.id_app,$condition_req$$.nh_kh2,{status:!0}),$condition_kh_custs_tu_ngay$$.nh_kh2={$in:$den_ngay_nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$}),$condition_req$$.nh_kh3&&($den_ngay_nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$=await global.getModel("group").getAllChildrenGroup($condition_req$$.id_app,
5
+ $condition_req$$.nh_kh3,{status:!0}),$condition_kh_custs_tu_ngay$$.nh_kh3={$in:$den_ngay_nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$}),$condition_req$$.nh_kh4&&($den_ngay_nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$=await global.getModel("group").getAllChildrenGroup($condition_req$$.id_app,$condition_req$$.nh_kh4,{status:!0}),$condition_kh_custs_tu_ngay$$.nh_kh4={$in:$den_ngay_nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$}),$condition_req$$.nh_kh5&&($den_ngay_nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$=await global.getModel("group").getAllChildrenGroup($condition_req$$.id_app,
6
+ $condition_req$$.nh_kh5,{status:!0}),$condition_kh_custs_tu_ngay$$.nh_kh5={$in:$den_ngay_nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$}),0<Object.keys($condition_kh_custs_tu_ngay$$).length&&($condition_kh_custs_tu_ngay$$.id_app=$condition_req$$.id_app,$condition_kh_custs_tu_ngay$$=await global.getModel("customer").find($condition_kh_custs_tu_ngay$$,{ma_kh:1}).lean(),$query$$.ma_kh={$in:$condition_kh_custs_tu_ngay$$.map($c$$=>$c$$.ma_kh)}));$condition_req$$.ma_ct&&($query$$.ma_ct=$condition_req$$.ma_ct);
7
+ $condition_req$$.user_hoa_hong&&($query$$.$or=[{user_nv:$condition_req$$.user_hoa_hong},{user_ctv:$condition_req$$.user_hoa_hong},{user_gt:$condition_req$$.user_hoa_hong},{user_ql:$condition_req$$.user_hoa_hong}]);databanle($query$$,function($error$jscomp$2$$,$rs$$,$ptthanhtoans$$){if($error$jscomp$2$$)return $callback$jscomp$0$$($error$jscomp$2$$);const $thanh_toan$$=$ptthanhtoans$$.map($pt$$=>({name:$pt$$.ma,value:$pt$$.ma,ma:$pt$$.ma,ten:$pt$$.ten}));$rs$$.forEach(function($r$$){$r$$.nam=$r$$.ngay_ct.getFullYear()});
8
+ async.mapSeries($rs$$,function($r$$,$callback$$){$r$$.t_sl_xuat=$r$$.details.csum("sl_xuat");$r$$.t_tien_hang=$r$$.details.csum("tien_hang");$r$$.t_tien_cp=$r$$.details.csum("tien_cp");$r$$.t_tien_ck=$r$$.details.csum("tien_ck");$r$$.t_tien=$r$$.details.csum("tien");$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");
9
+ $r$$.tien_freeship=$r$$.tien_freeship||0;$r$$.tien_phi_vc=$r$$.tien_phi_vc||0;$r$$.tien_ck_hd=$r$$.tien_ck_hd?$r$$.tien_ck_hd:0;$r$$.t_tien_xuat=$r$$.details.csum("tien_xuat");$r$$.details_tl?($r$$.t_tien_tl=$r$$.details_tl.csum("tien"),$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"),
10
+ $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);$callback$$(null,$r$$)},function($error$jscomp$0$$,$rs$jscomp$0$$){if($error$jscomp$0$$)return $callback$jscomp$0$$($error$jscomp$0$$);$rs$jscomp$0$$.groupBy("nam",[{name:"t_sl_xuat",value:"t_sl_xuat"},{name:"t_tien_hang",value:"t_tien_hang"},{name:"t_tien_cp",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"},
11
+ {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_sl_nhap",value:"t_sl_nhap"},{name:"t_tien_tl",value:"t_tien_tl"},{name:"t_tien_nhap",value:"t_tien_nhap"},{name:"phai_tra",value:"phai_tra"},{name:"t_tien_hoa_hong",value:"t_tien_hoa_hong"},
12
+ {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"},...$thanh_toan$$],function($error$$,$rs$$){if($error$$)return $callback$jscomp$0$$($error$$);const $report$$=underscore.sortBy($rs$$,function($r$$){return Number($r$$.nam)});let $i$$=1;$report$$.forEach(function($r$$){$r$$.stt=$i$$;$r$$.bold=!1;$r$$.t_doanh_thu=$r$$.t_tien+$r$$.tien_phi_vc-$r$$.tien_freeship-($r$$.tien_ck_hd||0)-($r$$.tien_evoucher||
13
+ 0);$r$$.t_lai=$r$$.t_doanh_thu-$r$$.t_tien_xuat-($r$$.t_tien_tl-$r$$.t_tien_nhap);$r$$.t_doanh_thu_thuan=$r$$.t_doanh_thu-$r$$.t_tien_tl;$r$$.t_tien_thu=$thanh_toan$$.map($pt$$=>$r$$[$pt$$.ma]||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$r$$.tu_ngay=moment([$r$$.nam,0,1]).startOf("year").toDate();$r$$.den_ngay=moment([$r$$.nam,0,1]).endOf("year").toDate();$r$$.t_tien_paymentByPoints=$r$$.tien_paymentByPoints||0;$i$$++});const $tong_cong$$={nam:"T\u1ed5ng c\u1ed9ng",t_sl_xuat:$report$$.csum("t_sl_xuat"),
14
+ t_tien_hang:$report$$.csum("t_tien_hang"),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_xuat:$report$$.csum("t_tien_xuat"),t_doanh_thu:$report$$.csum("t_doanh_thu"),t_sl_nhap:$report$$.csum("t_sl_nhap"),t_tien_tl:$report$$.csum("t_tien_tl"),t_tien_nhap:$report$$.csum("t_tien_nhap"),t_doanh_thu_thuan:$report$$.csum("t_doanh_thu_thuan"),
15
+ 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"),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"),
16
+ bold:!0};$thanh_toan$$.forEach($pt$$=>{$pt$$.tong_cong=$tong_cong$$[$pt$$.ma]=$report$$.csum($pt$$.ma)});$report$$.push($tong_cong$$);$callback$jscomp$0$$(null,{data:$report$$,thanh_toan:$thanh_toan$$.filter($t$$=>$t$$.tong_cong)})})})})})};
@@ -1,10 +1,15 @@
1
1
  'use strict';const databanle=require("../../libs/databanle"),async=require("async"),underscore=require("underscore"),controller=require("../../controllers/controllerRPT");
2
2
  module.exports=function($router$$){new controller($router$$,"dtbanletheongay",async function($req$$,$callback$jscomp$0$$){const $condition$$=$req$$.query;if(!$condition$$.tu_ngay||!$condition$$.den_ngay)return $callback$jscomp$0$$("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};$query$$.ngay_ct={$gte:$condition$$.tu_ngay,$lte:$condition$$.den_ngay};$condition$$.ma_dvcs&&($query$$.ma_dvcs=$condition$$.ma_dvcs);$condition$$.ma_kho&&
3
- ($query$$.ma_kho=$condition$$.ma_kho);$condition$$.ma_kh&&($query$$.ma_kh=$condition$$.ma_kh);$condition$$.ma_ct&&($query$$.ma_ct=$condition$$.ma_ct);databanle($query$$,function($error$jscomp$2$$,$rs$$,$ptthanhtoans$$){if($error$jscomp$2$$)return $callback$jscomp$0$$($error$jscomp$2$$);const $thanh_toan$$=$ptthanhtoans$$.map($pt$$=>({name:$pt$$.ma,value:$pt$$.ma,ma:$pt$$.ma,ten:$pt$$.ten}));async.mapSeries($rs$$,function($r$$,$callback$$){$r$$.t_sl_xuat=$r$$.details.csum("sl_xuat");$r$$.t_tien_hang=
4
- $r$$.details.csum("tien_hang");$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$$.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"),$r$$.t_tien_nhap=$r$$.details_tl.csum("tien_nhap"),$r$$.t_sl_nhap=$r$$.details_tl.csum("sl_nhap")):($r$$.t_tien_tl=0,$r$$.t_sl_nhap=
5
- 0,$r$$.t_tien_nhap=0);$callback$$(null,$r$$)},function($error$jscomp$0$$,$rs$jscomp$0$$){if($error$jscomp$0$$)return $callback$jscomp$0$$($error$jscomp$0$$);const $field_group_by$$=$req$$.query.group_by||"ngay_ct";$error$jscomp$0$$=[{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_cp",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",
6
- 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_nhap",value:"t_tien_nhap"},{name:"phai_tra",value:"phai_tra"},...$thanh_toan$$];$rs$jscomp$0$$.groupBy($field_group_by$$,$error$jscomp$0$$,function($error$$,$rs$$){if($error$$)return $callback$jscomp$0$$($error$$);
7
- let $report$$=underscore.sortBy($rs$$,function($r$$){return $r$$[$field_group_by$$]});$report$$.forEach(function($r$$,$i$$){$r$$.stt=$i$$+1;$r$$.bold=!1;$r$$.t_doanh_thu=$r$$.t_tien+$r$$.tien_phi_vc-$r$$.tien_freeship-($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_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$$,0);$r$$.t_tien_paymentByPoints=
8
- $r$$.tien_paymentByPoints||0});const $tong_cong$$={[$field_group_by$$]:"T\u1ed5ng c\u1ed9ng",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_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_xuat:$report$$.csum("t_tien_xuat"),
9
- t_tien_nhap:$report$$.csum("t_tien_nhap"),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"),bold:!0};$thanh_toan$$.forEach($pt$$=>{$pt$$.tong_cong=$tong_cong$$[$pt$$.name]=
10
- $report$$.csum($pt$$.name)});$report$$.push($tong_cong$$);$callback$jscomp$0$$(null,{data:$report$$,thanh_toan:$thanh_toan$$.filter($t$$=>$t$$.tong_cong)})})})})})};
3
+ ($query$$.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});$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,
4
+ $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={$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,
5
+ {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$$});0<Object.keys($condition_kh_custs$$).length&&($condition_kh_custs$$.id_app=$condition$$.id_app,$condition_kh_custs$$=await global.getModel("customer").find($condition_kh_custs$$,
6
+ {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=[{user_nv:$condition$$.user_hoa_hong},{user_ctv:$condition$$.user_hoa_hong},{user_gt:$condition$$.user_hoa_hong},{user_ql:$condition$$.user_hoa_hong}]);databanle($query$$,function($error$jscomp$2$$,$rs$$,$ptthanhtoans$$){if($error$jscomp$2$$)return $callback$jscomp$0$$($error$jscomp$2$$);const $thanh_toan$$=$ptthanhtoans$$.map($pt$$=>
7
+ ({name:$pt$$.ma,value:$pt$$.ma,ma:$pt$$.ma,ten:$pt$$.ten}));async.mapSeries($rs$$,function($r$$,$callback$$){$r$$.t_sl_xuat=$r$$.details.csum("sl_xuat");$r$$.t_tien_hang=$r$$.details.csum("tien_hang");$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");
8
+ $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?($r$$.t_tien_tl=$r$$.details_tl.csum("tien"),$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-=
9
+ $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);$callback$$(null,$r$$)},function($error$jscomp$0$$,$rs$jscomp$0$$){if($error$jscomp$0$$)return $callback$jscomp$0$$($error$jscomp$0$$);const $field_group_by$$=$req$$.query.group_by||"ngay_ct";$error$jscomp$0$$=[{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_cp",
10
+ 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_nhap",value:"t_tien_nhap"},
11
+ {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"},...$thanh_toan$$];$rs$jscomp$0$$.groupBy($field_group_by$$,$error$jscomp$0$$,function($error$$,$rs$$){if($error$$)return $callback$jscomp$0$$($error$$);let $report$$=underscore.sortBy($rs$$,function($r$$){return $r$$[$field_group_by$$]});$report$$.forEach(function($r$$,
12
+ $i$$){$r$$.stt=$i$$+1;$r$$.bold=!1;$r$$.t_doanh_thu=$r$$.t_tien+$r$$.tien_phi_vc-$r$$.tien_freeship-($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_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$$,0);$r$$.t_tien_paymentByPoints=$r$$.tien_paymentByPoints||0});const $tong_cong$$={[$field_group_by$$]:"T\u1ed5ng c\u1ed9ng",t_sl_xuat:$report$$.csum("t_sl_xuat"),
13
+ t_sl_nhap:$report$$.csum("t_sl_nhap"),t_tien_hang:$report$$.csum("t_tien_hang"),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_xuat:$report$$.csum("t_tien_xuat"),t_tien_nhap:$report$$.csum("t_tien_nhap"),t_doanh_thu:$report$$.csum("t_doanh_thu"),t_doanh_thu_thuan:$report$$.csum("t_doanh_thu_thuan"),
14
+ 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"),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"),
15
+ bold:!0};$thanh_toan$$.forEach($pt$$=>{$pt$$.tong_cong=$tong_cong$$[$pt$$.name]=$report$$.csum($pt$$.name)});$report$$.push($tong_cong$$);$callback$jscomp$0$$(null,{data:$report$$,thanh_toan:$thanh_toan$$.filter($t$$=>$t$$.tong_cong)})})})})})};
@@ -1,10 +1,16 @@
1
1
  'use strict';const databanle=require("../../libs/databanle"),User=global.getModel("user"),async=require("async"),underscore=require("underscore"),controller=require("../../controllers/controllerRPT");
2
- module.exports=function($router$$){new controller($router$$,"dtbanletheonv",function($condition_req$$,$callback$jscomp$0$$){$condition_req$$=$condition_req$$.query;if(!$condition_req$$.tu_ngay||!$condition_req$$.den_ngay)return $callback$jscomp$0$$("B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1:tu_ngay,den_ngay");const $query$$={id_app:$condition_req$$.id_app};$query$$.ngay_ct={$gte:$condition_req$$.tu_ngay,$lte:$condition_req$$.den_ngay};$condition_req$$.ma_dvcs&&($query$$.ma_dvcs=
3
- $condition_req$$.ma_dvcs);$condition_req$$.user_created&&($query$$.user_created=$condition_req$$.user_created);$condition_req$$.cashier&&($query$$.cashier=$condition_req$$.cashier);$condition_req$$.ma_kho&&($query$$.ma_kho=$condition_req$$.ma_kho);$condition_req$$.ma_ct&&($query$$.ma_ct=$condition_req$$.ma_ct);databanle($query$$,function($error$jscomp$2$$,$rs$$,$ptthanhtoans$$){if($error$jscomp$2$$)return $callback$jscomp$0$$($error$jscomp$2$$);const $thanh_toan$$=$ptthanhtoans$$.map($pt$$=>({name:$pt$$.ma,
4
- value:$pt$$.ma,ma:$pt$$.ma,ten:$pt$$.ten}));async.mapSeries($rs$$,function($r$$,$callback$$){$r$$.t_sl_xuat=$r$$.details.csum("sl_xuat");$r$$.t_tien_hang=$r$$.details.csum("tien_hang");$r$$.t_tien_ck=$r$$.details.csum("tien_ck");$r$$.t_tien=$r$$.details.csum("tien");$r$$.t_tien_cp=$r$$.details.csum("tien_cp");$r$$.tien_freeship=$r$$.tien_freeship||0;$r$$.tien_phi_vc=$r$$.tien_phi_vc||0;$r$$.tien_ck_hd=$r$$.tien_ck_hd?$r$$.tien_ck_hd:0;$r$$.t_tien_xuat=$r$$.details.csum("tien_xuat");$r$$.details_tl?
5
- ($r$$.t_tien_tl=$r$$.details_tl.csum("tien"),$r$$.t_tien_nhap=$r$$.details_tl.csum("tien_nhap"),$r$$.t_sl_nhap=$r$$.details_tl.csum("sl_nhap")):($r$$.t_tien_tl=0,$r$$.t_sl_nhap=0,$r$$.t_tien_nhap=0);$callback$$(null,$r$$)},function($error$jscomp$0$$,$rs$jscomp$0$$){if($error$jscomp$0$$)return $callback$jscomp$0$$($error$jscomp$0$$);$rs$jscomp$0$$.groupBy("user_created",[{name:"t_sl_xuat",value:"t_sl_xuat"},{name:"t_tien_hang",value:"t_tien_hang"},{name:"t_tien_cp",value:"t_tien_cp"},{name:"t_tien_ck",
6
- 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_sl_nhap",value:"t_sl_nhap"},{name:"t_tien_tl",value:"t_tien_tl"},{name:"t_tien_nhap",value:"t_tien_nhap"},
7
- {name:"phai_tra",value:"phai_tra"},...$thanh_toan$$],function($error$$,$rs$$){if($error$$)return $callback$jscomp$0$$($error$$);const $report$$=underscore.sortBy($rs$$,function($r$$){return $r$$.user_created});let $i$$=1;$report$$.forEach(function($r$$){$r$$.stt=$i$$;$r$$.bold=!1;$r$$.t_doanh_thu=$r$$.t_tien+$r$$.tien_phi_vc-$r$$.tien_freeship-($r$$.tien_ck_hd||0)-($r$$.tien_evoucher||0);$r$$.t_doanh_thu_thuan=$r$$.t_doanh_thu-$r$$.t_tien_tl;$r$$.t_lai=$r$$.t_doanh_thu-$r$$.t_tien_xuat-($r$$.t_tien_tl-
8
- $r$$.t_tien_nhap);$r$$.t_tien_thu=$thanh_toan$$.map($pt$$=>$r$$[$pt$$.ma]||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$r$$.t_tien_paymentByPoints=$r$$.tien_paymentByPoints||0;$i$$++});$report$$.joinModel(null,User,[{akey:"user_created",bkey:"email",fields:[{name:"name",value:"name"}]}],function(){const $tong_cong$$={name:"T\u1ed5ng c\u1ed9ng",t_sl_xuat:$report$$.csum("t_sl_xuat"),t_tien_hang:$report$$.csum("t_tien_hang"),t_tien_cp:$report$$.csum("t_tien_cp"),t_tien_ck:$report$$.csum("t_tien_ck"),t_tien:$report$$.csum("t_tien"),
9
- tien_ck_hd:$report$$.csum("tien_ck_hd"),tien_phi_vc:$report$$.csum("tien_phi_vc"),tien_freeship:$report$$.csum("tien_freeship"),t_tien_xuat:$report$$.csum("t_tien_xuat"),t_doanh_thu:$report$$.csum("t_doanh_thu"),t_sl_nhap:$report$$.csum("t_sl_nhap"),t_tien_tl:$report$$.csum("t_tien_tl"),t_tien_nhap:$report$$.csum("t_tien_nhap"),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"),
10
- 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"),bold:!0};$thanh_toan$$.forEach($pt$$=>{$pt$$.tong_cong=$tong_cong$$[$pt$$.ma]=$report$$.csum($pt$$.ma)});$report$$.push($tong_cong$$);$callback$jscomp$0$$(null,{data:$report$$,thanh_toan:$thanh_toan$$.filter($t$$=>$t$$.tong_cong)})})})})})})};
2
+ module.exports=function($router$$){new controller($router$$,"dtbanletheonv",async function($condition_req$$,$callback$jscomp$0$$){$condition_req$$=$condition_req$$.query;if(!$condition_req$$.tu_ngay||!$condition_req$$.den_ngay)return $callback$jscomp$0$$("B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1:tu_ngay,den_ngay");const $query$$={id_app:$condition_req$$.id_app};$query$$.ngay_ct={$gte:$condition_req$$.tu_ngay,$lte:$condition_req$$.den_ngay};$condition_req$$.ma_dvcs&&($query$$.ma_dvcs=
3
+ $condition_req$$.ma_dvcs);$condition_req$$.user_created&&($query$$.user_created=$condition_req$$.user_created);$condition_req$$.user_hoa_hong&&($query$$.$or=[{user_nv:$condition_req$$.user_hoa_hong},{user_ctv:$condition_req$$.user_hoa_hong},{user_gt:$condition_req$$.user_hoa_hong},{user_ql:$condition_req$$.user_hoa_hong}]);if($condition_req$$.ma_kh)$query$$.ma_kh=$condition_req$$.ma_kh;else{var $condition_kh_custs$$={};if($condition_req$$.nh_kh){var $nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$=await global.getModel("group").getAllChildrenGroup($condition_req$$.id_app,
4
+ $condition_req$$.nh_kh,{status:!0});$condition_kh_custs$$.nh_kh={$in:$nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$}}$condition_req$$.nh_kh2&&($nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$=await global.getModel("group").getAllChildrenGroup($condition_req$$.id_app,$condition_req$$.nh_kh2,{status:!0}),$condition_kh_custs$$.nh_kh2={$in:$nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$});$condition_req$$.nh_kh3&&($nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$=await global.getModel("group").getAllChildrenGroup($condition_req$$.id_app,
5
+ $condition_req$$.nh_kh3,{status:!0}),$condition_kh_custs$$.nh_kh3={$in:$nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$});$condition_req$$.nh_kh4&&($nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$=await global.getModel("group").getAllChildrenGroup($condition_req$$.id_app,$condition_req$$.nh_kh4,{status:!0}),$condition_kh_custs$$.nh_kh4={$in:$nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$});$condition_req$$.nh_kh5&&($nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$=await global.getModel("group").getAllChildrenGroup($condition_req$$.id_app,
6
+ $condition_req$$.nh_kh5,{status:!0}),$condition_kh_custs$$.nh_kh5={$in:$nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$});0<Object.keys($condition_kh_custs$$).length&&($condition_kh_custs$$.id_app=$condition_req$$.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_req$$.cashier&&($query$$.cashier=$condition_req$$.cashier);$condition_req$$.ma_kho&&($query$$.ma_kho=$condition_req$$.ma_kho);
7
+ $condition_req$$.ma_ct&&($query$$.ma_ct=$condition_req$$.ma_ct);databanle($query$$,function($error$jscomp$2$$,$rs$$,$ptthanhtoans$$){if($error$jscomp$2$$)return $callback$jscomp$0$$($error$jscomp$2$$);const $thanh_toan$$=$ptthanhtoans$$.map($pt$$=>({name:$pt$$.ma,value:$pt$$.ma,ma:$pt$$.ma,ten:$pt$$.ten}));async.mapSeries($rs$$,function($r$$,$callback$$){$r$$.t_sl_xuat=$r$$.details.csum("sl_xuat");$r$$.t_tien_hang=$r$$.details.csum("tien_hang");$r$$.t_tien_ck=$r$$.details.csum("tien_ck");$r$$.t_tien=
8
+ $r$$.details.csum("tien");$r$$.t_tien_cp=$r$$.details.csum("tien_cp");$r$$.tien_freeship=$r$$.tien_freeship||0;$r$$.tien_phi_vc=$r$$.tien_phi_vc||0;$r$$.tien_ck_hd=$r$$.tien_ck_hd?$r$$.tien_ck_hd:0;$r$$.t_tien_xuat=$r$$.details.csum("tien_xuat");$r$$.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$$.details_tl?
9
+ ($r$$.t_tien_tl=$r$$.details_tl.csum("tien"),$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=0,$r$$.t_sl_nhap=0,$r$$.t_tien_nhap=0);$callback$$(null,$r$$)},function($error$jscomp$0$$,
10
+ $rs$jscomp$0$$){if($error$jscomp$0$$)return $callback$jscomp$0$$($error$jscomp$0$$);$rs$jscomp$0$$.groupBy("user_created",[{name:"t_sl_xuat",value:"t_sl_xuat"},{name:"t_tien_hang",value:"t_tien_hang"},{name:"t_tien_cp",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"},
11
+ {name:"tien_thu2",value:"tien_thu2"},{name:"tien_paymentByPoints",value:"tien_paymentByPoints"},{name:"t_tien_xuat",value:"t_tien_xuat"},{name:"t_sl_nhap",value:"t_sl_nhap"},{name:"t_tien_tl",value:"t_tien_tl"},{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"},
12
+ ...$thanh_toan$$],function($error$$,$rs$$){if($error$$)return $callback$jscomp$0$$($error$$);const $report$$=underscore.sortBy($rs$$,function($r$$){return $r$$.user_created});let $i$$=1;$report$$.forEach(function($r$$){$r$$.stt=$i$$;$r$$.bold=!1;$r$$.t_doanh_thu=$r$$.t_tien+$r$$.tien_phi_vc-$r$$.tien_freeship-($r$$.tien_ck_hd||0)-($r$$.tien_evoucher||0);$r$$.t_doanh_thu_thuan=$r$$.t_doanh_thu-$r$$.t_tien_tl;$r$$.t_lai=$r$$.t_doanh_thu-$r$$.t_tien_xuat-($r$$.t_tien_tl-$r$$.t_tien_nhap);$r$$.t_tien_thu=
13
+ $thanh_toan$$.map($pt$$=>$r$$[$pt$$.ma]||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$r$$.t_tien_paymentByPoints=$r$$.tien_paymentByPoints||0;$i$$++});$report$$.joinModel(null,User,[{akey:"user_created",bkey:"email",fields:[{name:"name",value:"name"}]}],function(){const $tong_cong$$={name:"T\u1ed5ng c\u1ed9ng",t_sl_xuat:$report$$.csum("t_sl_xuat"),t_tien_hang:$report$$.csum("t_tien_hang"),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"),
14
+ tien_phi_vc:$report$$.csum("tien_phi_vc"),tien_freeship:$report$$.csum("tien_freeship"),t_tien_xuat:$report$$.csum("t_tien_xuat"),t_doanh_thu:$report$$.csum("t_doanh_thu"),t_sl_nhap:$report$$.csum("t_sl_nhap"),t_tien_tl:$report$$.csum("t_tien_tl"),t_tien_nhap:$report$$.csum("t_tien_nhap"),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"),
15
+ 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"),bold:!0};$thanh_toan$$.forEach($pt$$=>{$pt$$.tong_cong=$tong_cong$$[$pt$$.ma]=$report$$.csum($pt$$.ma)});$report$$.push($tong_cong$$);$callback$jscomp$0$$(null,
16
+ {data:$report$$,thanh_toan:$thanh_toan$$.filter($t$$=>$t$$.tong_cong)})})})})})})};
@@ -1,10 +1,16 @@
1
1
  'use strict';const databanle=require("../../libs/databanle"),async=require("async"),underscore=require("underscore"),controller=require("../../controllers/controllerRPT"),moment=require("moment");
2
- module.exports=function($router$$){new controller($router$$,"dtbanletheoquy",function($condition_req$$,$callback$jscomp$0$$){$condition_req$$=$condition_req$$.query;if(!$condition_req$$.nam)return $callback$jscomp$0$$("B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1:nam");const $query$$={id_app:$condition_req$$.id_app},$tu_ngay$$=moment(new Date($condition_req$$.nam,0,1)).startOf("year").toDate(),$den_ngay$$=moment(new Date($condition_req$$.nam,11,31)).endOf("year").toDate();$query$$.ngay_ct=
3
- {$gte:$tu_ngay$$,$lte:$den_ngay$$};$condition_req$$.ma_dvcs&&($query$$.ma_dvcs=$condition_req$$.ma_dvcs);$condition_req$$.ma_kho&&($query$$.ma_kho=$condition_req$$.ma_kho);$condition_req$$.ma_ct&&($query$$.ma_ct=$condition_req$$.ma_ct);databanle($query$$,function($error$jscomp$2$$,$rs$$,$ptthanhtoans$$){if($error$jscomp$2$$)return $callback$jscomp$0$$($error$jscomp$2$$);const $thanh_toan$$=$ptthanhtoans$$.map($pt$$=>({name:$pt$$.ma,value:$pt$$.ma,ma:$pt$$.ma,ten:$pt$$.ten}));$rs$$.forEach(function($r$$){$r$$.thang=
4
- $r$$.ngay_ct.getMonth()+1;$r$$.nam=moment($r$$.ngay_ct).year();$r$$.quy=moment($r$$.ngay_ct).quarter()});async.mapSeries($rs$$,function($r$$,$callback$$){$r$$.t_sl_xuat=$r$$.details.csum("sl_xuat");$r$$.t_tien_hang=$r$$.details.csum("tien_hang");$r$$.t_tien_cp=$r$$.details.csum("tien_cp");$r$$.t_tien_ck=$r$$.details.csum("tien_ck");$r$$.t_tien=$r$$.details.csum("tien");$r$$.tien_freeship=$r$$.tien_freeship||0;$r$$.tien_phi_vc=$r$$.tien_phi_vc||0;$r$$.tien_ck_hd=$r$$.tien_ck_hd?$r$$.tien_ck_hd:0;$r$$.t_tien_xuat=
5
- $r$$.details.csum("tien_xuat");$r$$.details_tl?($r$$.t_tien_tl=$r$$.details_tl.csum("tien"),$r$$.t_tien_nhap=$r$$.details_tl.csum("tien_nhap"),$r$$.t_sl_nhap=$r$$.details_tl.csum("sl_nhap")):($r$$.t_tien_tl=0,$r$$.t_sl_nhap=0,$r$$.t_tien_nhap=0);$callback$$(null,$r$$)},function($error$jscomp$0$$,$rs$jscomp$0$$){if($error$jscomp$0$$)return $callback$jscomp$0$$($error$jscomp$0$$);$rs$jscomp$0$$.groupBy(["nam","quy"],[{name:"t_sl_xuat",value:"t_sl_xuat"},{name:"t_tien_hang",value:"t_tien_hang"},{name:"t_tien_cp",
6
- 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_sl_nhap",value:"t_sl_nhap"},{name:"t_tien_tl",value:"t_tien_tl"},
7
- {name:"t_tien_nhap",value:"t_tien_nhap"},{name:"phai_tra",value:"phai_tra"},...$thanh_toan$$],function($error$$,$rs$$){if($error$$)return $callback$jscomp$0$$($error$$);const $report$$=underscore.sortBy($rs$$,function($r$$){return Number($r$$.quy)});let $i$$=1;$report$$.forEach(function($r$$){$r$$.stt=$i$$;$r$$.bold=!1;$r$$.t_doanh_thu=$r$$.t_tien+$r$$.tien_phi_vc-$r$$.tien_freeship-($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);
8
- $r$$.t_doanh_thu_thuan=$r$$.t_doanh_thu-$r$$.t_tien_tl;$r$$.t_tien_thu=$thanh_toan$$.map($pt$$=>$r$$[$pt$$.ma]||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$r$$.tu_ngay=moment([$r$$.nam,0,1]).quarter($r$$.quy).startOf("quarter").toDate();$r$$.den_ngay=moment([$r$$.nam,0,1]).quarter($r$$.quy).endOf("quarter").toDate();$r$$.t_tien_paymentByPoints=$r$$.tien_paymentByPoints||0;$i$$++});const $tong_cong$$={quy:"T\u1ed5ng c\u1ed9ng",t_sl_xuat:$report$$.csum("t_sl_xuat"),t_tien_hang:$report$$.csum("t_tien_hang"),
9
- 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_xuat:$report$$.csum("t_tien_xuat"),t_doanh_thu:$report$$.csum("t_doanh_thu"),t_sl_nhap:$report$$.csum("t_sl_nhap"),t_tien_tl:$report$$.csum("t_tien_tl"),t_tien_nhap:$report$$.csum("t_tien_nhap"),tien_evoucher:$report$$.csum("tien_evoucher"),tien_thu:$report$$.csum("tien_thu"),
10
- tien_thu2:$report$$.csum("tien_thu2"),t_tien_evoucher:$report$$.csum("tien_evoucher"),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"),bold:!0};$thanh_toan$$.forEach($pt$$=>{$pt$$.tong_cong=$tong_cong$$[$pt$$.ma]=$report$$.csum($pt$$.ma)});$report$$.push($tong_cong$$);$callback$jscomp$0$$(null,{data:$report$$,thanh_toan:$thanh_toan$$.filter($t$$=>$t$$.tong_cong)})})})})})};
2
+ module.exports=function($router$$){new controller($router$$,"dtbanletheoquy",async function($condition_req$$,$callback$jscomp$0$$){$condition_req$$=$condition_req$$.query;if(!$condition_req$$.nam)return $callback$jscomp$0$$("B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1:nam");const $query$$={id_app:$condition_req$$.id_app};var $condition_kh_custs_tu_ngay$$=moment(new Date($condition_req$$.nam,0,1)).startOf("year").toDate(),$den_ngay_nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$=moment(new Date($condition_req$$.nam,
3
+ 11,31)).endOf("year").toDate();$query$$.ngay_ct={$gte:$condition_kh_custs_tu_ngay$$,$lte:$den_ngay_nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$};$condition_req$$.ma_dvcs&&($query$$.ma_dvcs=$condition_req$$.ma_dvcs);$condition_req$$.ma_kho&&($query$$.ma_kho=$condition_req$$.ma_kho);$condition_req$$.ma_ct&&($query$$.ma_ct=$condition_req$$.ma_ct);$condition_req$$.ma_kh?$query$$.ma_kh=$condition_req$$.ma_kh:($condition_kh_custs_tu_ngay$$={},$condition_req$$.nh_kh&&($den_ngay_nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$=
4
+ await global.getModel("group").getAllChildrenGroup($condition_req$$.id_app,$condition_req$$.nh_kh,{status:!0}),$condition_kh_custs_tu_ngay$$.nh_kh={$in:$den_ngay_nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$}),$condition_req$$.nh_kh2&&($den_ngay_nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$=await global.getModel("group").getAllChildrenGroup($condition_req$$.id_app,$condition_req$$.nh_kh2,{status:!0}),$condition_kh_custs_tu_ngay$$.nh_kh2={$in:$den_ngay_nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$}),$condition_req$$.nh_kh3&&
5
+ ($den_ngay_nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$=await global.getModel("group").getAllChildrenGroup($condition_req$$.id_app,$condition_req$$.nh_kh3,{status:!0}),$condition_kh_custs_tu_ngay$$.nh_kh3={$in:$den_ngay_nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$}),$condition_req$$.nh_kh4&&($den_ngay_nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$=await global.getModel("group").getAllChildrenGroup($condition_req$$.id_app,$condition_req$$.nh_kh4,{status:!0}),$condition_kh_custs_tu_ngay$$.nh_kh4={$in:$den_ngay_nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$}),
6
+ $condition_req$$.nh_kh5&&($den_ngay_nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$=await global.getModel("group").getAllChildrenGroup($condition_req$$.id_app,$condition_req$$.nh_kh5,{status:!0}),$condition_kh_custs_tu_ngay$$.nh_kh5={$in:$den_ngay_nh_khs_nh_khs2_nh_khs3_nh_khs4_nh_khs5$$}),0<Object.keys($condition_kh_custs_tu_ngay$$).length&&($condition_kh_custs_tu_ngay$$.id_app=$condition_req$$.id_app,$condition_kh_custs_tu_ngay$$=await global.getModel("customer").find($condition_kh_custs_tu_ngay$$,{ma_kh:1}).lean(),
7
+ $query$$.ma_kh={$in:$condition_kh_custs_tu_ngay$$.map($c$$=>$c$$.ma_kh)}));$condition_req$$.user_hoa_hong&&($query$$.$or=[{user_nv:$condition_req$$.user_hoa_hong},{user_ctv:$condition_req$$.user_hoa_hong},{user_gt:$condition_req$$.user_hoa_hong},{user_ql:$condition_req$$.user_hoa_hong}]);databanle($query$$,function($error$jscomp$2$$,$rs$$,$ptthanhtoans$$){if($error$jscomp$2$$)return $callback$jscomp$0$$($error$jscomp$2$$);const $thanh_toan$$=$ptthanhtoans$$.map($pt$$=>({name:$pt$$.ma,value:$pt$$.ma,
8
+ ma:$pt$$.ma,ten:$pt$$.ten}));$rs$$.forEach(function($r$$){$r$$.thang=$r$$.ngay_ct.getMonth()+1;$r$$.nam=moment($r$$.ngay_ct).year();$r$$.quy=moment($r$$.ngay_ct).quarter()});async.mapSeries($rs$$,function($r$$,$callback$$){$r$$.t_sl_xuat=$r$$.details.csum("sl_xuat");$r$$.t_tien_hang=$r$$.details.csum("tien_hang");$r$$.t_tien_cp=$r$$.details.csum("tien_cp");$r$$.t_tien_ck=$r$$.details.csum("tien_ck");$r$$.t_tien=$r$$.details.csum("tien");$r$$.tien_freeship=$r$$.tien_freeship||0;$r$$.tien_phi_vc=$r$$.tien_phi_vc||
9
+ 0;$r$$.tien_ck_hd=$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$$.details_tl?($r$$.t_tien_tl=$r$$.details_tl.csum("tien"),$r$$.t_tien_nhap=$r$$.details_tl.csum("tien_nhap"),$r$$.t_sl_nhap=$r$$.details_tl.csum("sl_nhap"),
10
+ $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=0,$r$$.t_sl_nhap=0,$r$$.t_tien_nhap=0);$callback$$(null,$r$$)},function($error$jscomp$0$$,$rs$jscomp$0$$){if($error$jscomp$0$$)return $callback$jscomp$0$$($error$jscomp$0$$);$rs$jscomp$0$$.groupBy(["nam","quy"],[{name:"t_sl_xuat",
11
+ value:"t_sl_xuat"},{name:"t_tien_hang",value:"t_tien_hang"},{name:"t_tien_cp",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"},
12
+ {name:"t_sl_nhap",value:"t_sl_nhap"},{name:"t_tien_tl",value:"t_tien_tl"},{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"},...$thanh_toan$$],function($error$$,$rs$$){if($error$$)return $callback$jscomp$0$$($error$$);const $report$$=underscore.sortBy($rs$$,function($r$$){return Number($r$$.quy)});
13
+ let $i$$=1;$report$$.forEach(function($r$$){$r$$.stt=$i$$;$r$$.bold=!1;$r$$.t_doanh_thu=$r$$.t_tien+$r$$.tien_phi_vc-$r$$.tien_freeship-($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_doanh_thu_thuan=$r$$.t_doanh_thu-$r$$.t_tien_tl;$r$$.t_tien_thu=$thanh_toan$$.map($pt$$=>$r$$[$pt$$.ma]||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$r$$.tu_ngay=moment([$r$$.nam,0,1]).quarter($r$$.quy).startOf("quarter").toDate();$r$$.den_ngay=
14
+ moment([$r$$.nam,0,1]).quarter($r$$.quy).endOf("quarter").toDate();$r$$.t_tien_paymentByPoints=$r$$.tien_paymentByPoints||0;$i$$++});const $tong_cong$$={quy:"T\u1ed5ng c\u1ed9ng",t_sl_xuat:$report$$.csum("t_sl_xuat"),t_tien_hang:$report$$.csum("t_tien_hang"),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_xuat:$report$$.csum("t_tien_xuat"),
15
+ t_doanh_thu:$report$$.csum("t_doanh_thu"),t_sl_nhap:$report$$.csum("t_sl_nhap"),t_tien_tl:$report$$.csum("t_tien_tl"),t_tien_nhap:$report$$.csum("t_tien_nhap"),tien_evoucher:$report$$.csum("tien_evoucher"),tien_thu:$report$$.csum("tien_thu"),tien_thu2:$report$$.csum("tien_thu2"),t_tien_evoucher:$report$$.csum("tien_evoucher"),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"),
16
+ 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"),bold:!0};$thanh_toan$$.forEach($pt$$=>{$pt$$.tong_cong=$tong_cong$$[$pt$$.ma]=$report$$.csum($pt$$.ma)});$report$$.push($tong_cong$$);$callback$jscomp$0$$(null,{data:$report$$,thanh_toan:$thanh_toan$$.filter($t$$=>$t$$.tong_cong)})})})})})};