UNPKG

flexbiz-server

Version:

Flexible Server

12 lines (11 loc) 5.29 kB
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$$){const $query$$=$kbm_query_req$$.query;if(!$query$$.den_ngay)return $callback$$("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().then(function($kbm$$){$report$$=$kbm$$;async.map($report$$,function($r$$,$c1$$){setImmediate(()=>{$r$$.cach_tinh=="1"||$r$$.ngoai_bang===!0?$c1$$(null,$r$$):$r$$.cach_tinh=="2"?async.parallel({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$$);$r$$.phan_loai=="1"?($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"));$r$$.so_dn<0&&$r$$.khong_am&&($r$$.so_dn=0);$r$$.so_dn_nt<0&&$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$$);$r$$.phan_loai=="1"?($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"));$r$$.so_ck<0&&$r$$.khong_am&&($r$$.so_ck=0);$r$$.so_ck_nt<0&&$r$$.khong_am&&($r$$.so_ck_nt=0);$callback$$(null,$r$$)})}},function($error$$){if($error$$)return $c1$$($error$$);$c1$$(null,$r$$)}):$r$$.cach_tinh=="3"?async.parallel({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");$r$$.so_dn<0&&$r$$.khong_am&&($r$$.so_dn=0);$r$$.so_dn_nt<0&&$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");$r$$.so_ck<0&&$r$$.khong_am&&($r$$.so_ck=0);$r$$.so_ck_nt<0&&$r$$.khong_am&&($r$$.so_ck_nt=0);$callback$$(null, $r$$)})}},function($error$$){if($error$$)return $c1$$($error$$);$c1$$(null,$r$$)}):async.parallel({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");$r$$.so_dn<0&&$r$$.khong_am&&($r$$.so_dn=0);$r$$.so_dn_nt<0&&$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");$r$$.so_ck<0&&$r$$.khong_am&&($r$$.so_ck=0);$r$$.so_ck_nt<0&&$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$$(null,$rs$$)})})}).catch($error$$=>{$callback$$($error$$)})})};