flexbiz-server
Version:
Flexible Server
8 lines (7 loc) • 3.19 kB
JavaScript
'use strict';const vatvao=global.getModel("vatvao"),vatra=global.getModel("vatra"),kbmtkgtgt=global.getModel("kbmTkgtgt"),{calcGrid}=require("../../libs/utils"),async=require("async"),controller=require("../../controllers/controllerRPT"),moment=require("moment");
module.exports=function($router$$){new controller($router$$,"tkgtgt",function($kbm_query_req$$,$callback$jscomp$0$$){const $query$$=$kbm_query_req$$.query;if(!$query$$.tu_thang||!$query$$.den_thang||!$query$$.nam)return $callback$jscomp$0$$("B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: tu_thang, den_thang, nam");$query$$.ma_dvcs||($query$$.ma_dvcs="");const $tu_ngay$$=moment(new Date($query$$.nam,Number($query$$.tu_thang)-1,1)).startOf("date").toDate(),$den_ngay$$=moment(new Date($query$$.nam,
Number($query$$.den_thang),0)).endOf("date").toDate();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,""]};kbmtkgtgt.find($kbm_query_req$$).lean().exec(function($error$jscomp$2$$,$kbm$$){if($error$jscomp$2$$)return $callback$jscomp$0$$($error$jscomp$2$$);$report$$=$kbm$$;async.mapSeries($report$$,function($r$$,$callback$$){if("1"==$r$$.cach_tinh||"4"==$r$$.phan_loai)$callback$$(null,$r$$);else{const $condition$$=
{ngay_ct:{$gte:$tu_ngay$$,$lte:$den_ngay$$},ma_dvcs:{$regex:"^"+$query$$.ma_dvcs,$options:"i"},id_app:$query$$.id_app};$r$$.ma_thue&&0<$r$$.ma_thue.length&&(1!=$r$$.ma_thue.length||""!==$r$$.ma_thue[0])&&($condition$$.ma_thue={$in:$r$$.ma_thue});"vatvao"==$r$$.bang_du_lieu.toLowerCase()?($r$$.ma_tc&&0<$r$$.ma_tc.length&&(1!=$r$$.ma_tc.length||""!==$r$$.ma_tc[0])&&($condition$$.ma_tc={$in:$r$$.ma_tc}),$r$$.tk&&0<$r$$.tk.length&&($condition$$.tk_thue_no={$regex:"^"+$r$$.tk,$options:"i"}),vatvao.find($condition$$,
{t_tien:1,t_thue:1},function($error$$,$rs$$){if($error$$)return $callback$$($error$$);$r$$.t_thue="1"==$r$$.phan_loai||"2"==$r$$.phan_loai?$rs$$.csum("t_thue"):0;$r$$.t_tien="1"==$r$$.phan_loai||"3"==$r$$.phan_loai?$rs$$.csum("t_tien"):0;$callback$$(null,$r$$)})):($r$$.tk&&0<$r$$.tk.length&&($condition$$.tk_thue_co={$regex:"^"+$r$$.tk,$options:"i"}),vatra.find($condition$$,{t_tien:1,t_thue:1},function($error$$,$rs$$){if($error$$)return $callback$$($error$$);$r$$.t_thue="1"==$r$$.phan_loai||"2"==$r$$.phan_loai?
$rs$$.csum("t_thue"):0;$r$$.t_tien="1"==$r$$.phan_loai||"3"==$r$$.phan_loai?$rs$$.csum("t_tien"):0;$callback$$(null,$r$$)}))}},function($error$jscomp$0$$){if($error$jscomp$0$$)return $callback$jscomp$0$$($error$jscomp$0$$);calcGrid($report$$,{t_tien:function($error$$,$rlq$$){"3"==$rlq$$.phan_loai||"1"==$rlq$$.phan_loai?"1"==$rlq$$.kieu_gia_tri&&0>$rlq$$.t_tien?$rlq$$.t_tien=0:"2"==$rlq$$.kieu_gia_tri&&0<$rlq$$.t_tien?$rlq$$.t_tien=0:"3"==$rlq$$.kieu_gia_tri&&($rlq$$.t_tien=Math.abs($rlq$$.t_tien)):
$rlq$$.t_tien=0},t_thue:function($error$$,$rlq$$){"2"==$rlq$$.phan_loai||"1"==$rlq$$.phan_loai?"1"==$rlq$$.kieu_gia_tri&&0>$rlq$$.t_thue?$rlq$$.t_thue=0:"2"==$rlq$$.kieu_gia_tri&&0<$rlq$$.t_thue?$rlq$$.t_thue=0:"3"==$rlq$$.kieu_gia_tri&&($rlq$$.t_thue=Math.abs($rlq$$.t_thue)):$rlq$$.t_thue=0}},function($rs$$){$callback$jscomp$0$$(null,$rs$$)})})})})};