flexbiz-server
Version:
Flexible Server
12 lines (11 loc) • 5.37 kB
JavaScript
'use strict';const dktk=require("../../libs/dktk"),cktk=require("../../libs/cktk"),{calcGrid}=require("../../libs/utils"),kbmbcdkt=global.getModel("kbmbcdkt"),async=require("async"),controller=require("../../controllers/controllerRPT"),moment=require("moment");
module.exports=function($router$$){new controller($router$$,"bcdkt",function($kbm_query_req$$,$callback$jscomp$0$$){const $query$$=$kbm_query_req$$.query;if(!$query$$.den_ngay)return $callback$jscomp$0$$("B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u tham s\u1ed1 den_ngay");$query$$.tu_ngay||($query$$.tu_ngay=moment($query$$.den_ngay).startOf("year").toDate());$query$$.ma_dvcs||($query$$.ma_dvcs="");let $report$$;$kbm_query_req$$={id_app:$query$$.id_app};$kbm_query_req$$.id_rptform=$query$$.id_rptform?
$query$$.id_rptform:{$in:[void 0,null,""]};kbmbcdkt.find($kbm_query_req$$).sort({stt:1}).lean().exec(function($error$jscomp$0$$,$kbm$$){if($error$jscomp$0$$)return $callback$jscomp$0$$($error$jscomp$0$$);$report$$=$kbm$$;async.mapSeries($report$$,function($r$$,$c1$$){setImmediate(()=>{"1"==$r$$.cach_tinh||!0===$r$$.ngoai_bang?$c1$$(null,$r$$):"2"==$r$$.cach_tinh?async.series({dn:function($callback$$){if(!$r$$.tk)return $r$$.so_dn=0,$r$$.so_dn_nt=0,$callback$$(null,$r$$);let $condition$$={...$query$$};
$condition$$.ngay=$query$$.tu_ngay;delete $condition$$.tu_ngay;delete $condition$$.den_ngay;$condition$$.bu_tru=!1;$condition$$.tk=$r$$.tk;dktk($condition$$,function($error$$,$result$$){if($error$$)return $callback$$($error$$);"1"==$r$$.phan_loai?($r$$.so_dn=$result$$.csum("du_no00")-$result$$.csum("du_co00"),$r$$.so_dn_nt=$result$$.csum("du_no_nt00")-$result$$.csum("du_co_nt00")):($r$$.so_dn=$result$$.csum("du_co00")-$result$$.csum("du_no00"),$r$$.so_dn_nt=$result$$.csum("du_co_nt00")-$result$$.csum("du_no_nt00"));
0>$r$$.so_dn&&$r$$.khong_am&&($r$$.so_dn=0);0>$r$$.so_dn_nt&&$r$$.khong_am&&($r$$.so_dn_nt=0);$callback$$(null,$r$$)})},ck:function($callback$$){if(!$r$$.tk)return $r$$.so_ck=0,$r$$.so_ck_nt=0,$callback$$(null,$r$$);let $condition$$={...$query$$};$condition$$.ngay=$query$$.den_ngay;delete $condition$$.tu_ngay;delete $condition$$.den_ngay;$condition$$.bu_tru=!1;$condition$$.tk=$r$$.tk;cktk($condition$$,function($error$$,$result$$){if($error$$)return $callback$$($error$$);"1"==$r$$.phan_loai?($r$$.so_ck=
$result$$.csum("du_no00")-$result$$.csum("du_co00"),$r$$.so_ck_nt=$result$$.csum("du_no_nt00")-$result$$.csum("du_co_nt00")):($r$$.so_ck=$result$$.csum("du_co00")-$result$$.csum("du_no00"),$r$$.so_ck_nt=$result$$.csum("du_co_nt00")-$result$$.csum("du_no_nt00"));0>$r$$.so_ck&&$r$$.khong_am&&($r$$.so_ck=0);0>$r$$.so_ck_nt&&$r$$.khong_am&&($r$$.so_ck_nt=0);$callback$$(null,$r$$)})}},function($error$$){if($error$$)return $c1$$($error$$);$c1$$(null,$r$$)}):"3"==$r$$.cach_tinh?async.series({dn:function($callback$$){if(!$r$$.tk)return $r$$.so_dn=
0,$r$$.so_dn_nt=0,$callback$$(null,$r$$);let $condition$$={...$query$$};$condition$$.ngay=$query$$.tu_ngay;delete $condition$$.tu_ngay;delete $condition$$.den_ngay;$condition$$.bu_tru=$r$$.bu_tru_cong_no;$condition$$.tk=$r$$.tk;dktk($condition$$,function($error$$,$result$$){if($error$$)return $callback$$($error$$);$r$$.so_dn=$result$$.csum("du_no00");$r$$.so_dn_nt=$result$$.csum("du_no_nt00");0>$r$$.so_dn&&$r$$.khong_am&&($r$$.so_dn=0);0>$r$$.so_dn_nt&&$r$$.khong_am&&($r$$.so_dn_nt=0);$callback$$(null,
$r$$)})},ck:function($callback$$){if(!$r$$.tk)return $r$$.so_ck=0,$r$$.so_ck_nt=0,$callback$$(null,$r$$);let $condition$$={...$query$$};$condition$$.ngay=$query$$.den_ngay;delete $condition$$.tu_ngay;delete $condition$$.den_ngay;$condition$$.bu_tru=$r$$.bu_tru_cong_no;$condition$$.tk=$r$$.tk;cktk($condition$$,function($error$$,$result$$){if($error$$)return $callback$$($error$$);$r$$.so_ck=$result$$.csum("du_no00");$r$$.so_ck_nt=$result$$.csum("du_no_nt00");0>$r$$.so_ck&&$r$$.khong_am&&($r$$.so_ck=
0);0>$r$$.so_ck_nt&&$r$$.khong_am&&($r$$.so_ck_nt=0);$callback$$(null,$r$$)})}},function($error$$){if($error$$)return $c1$$($error$$);$c1$$(null,$r$$)}):async.series({dn:function($callback$$){if(!$r$$.tk)return $r$$.so_dn=0,$r$$.so_dn_nt=0,$callback$$(null,$r$$);let $condition$$={...$query$$};$condition$$.ngay=$query$$.tu_ngay;delete $condition$$.tu_ngay;delete $condition$$.den_ngay;$condition$$.bu_tru=$r$$.bu_tru_cong_no;$condition$$.tk=$r$$.tk;dktk($condition$$,function($error$$,$result$$){if($error$$)return $callback$$($error$$);
$r$$.so_dn=$result$$.csum("du_co00");$r$$.so_dn_nt=$result$$.csum("du_co_nt00");0>$r$$.so_dn&&$r$$.khong_am&&($r$$.so_dn=0);0>$r$$.so_dn_nt&&$r$$.khong_am&&($r$$.so_dn_nt=0);$callback$$(null,$r$$)})},ck:function($callback$$){if(!$r$$.tk)return $r$$.so_ck=0,$r$$.so_ck_nt=0,$callback$$(null,$r$$);let $condition$$={...$query$$};$condition$$.ngay=$query$$.den_ngay;delete $condition$$.tu_ngay;delete $condition$$.den_ngay;$condition$$.bu_tru=$r$$.bu_tru_cong_no;$condition$$.tk=$r$$.tk;cktk($condition$$,
function($error$$,$result$$){if($error$$)return $callback$$($error$$);$r$$.so_ck=$result$$.csum("du_co00");$r$$.so_ck_nt=$result$$.csum("du_co_nt00");0>$r$$.so_ck&&$r$$.khong_am&&($r$$.so_ck=0);0>$r$$.so_ck_nt&&$r$$.khong_am&&($r$$.so_ck_nt=0);$callback$$(null,$r$$)})}},function($error$$){if($error$$)return $c1$$($error$$);$c1$$(null,$r$$)})})},function(){calcGrid($report$$,"so_dn,so_dn_nt,so_ck,so_ck_nt",function($rs$$){$callback$jscomp$0$$(null,$rs$$)})})})})};