UNPKG

flexbiz-server

Version:

Flexible Server

8 lines (7 loc) 3.08 kB
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_old",function($kbm_query_req$$,$callback$$){const $query$$=$kbm_query_req$$.query;if(!$query$$.tu_thang||!$query$$.den_thang||!$query$$.nam)return $callback$$("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$$,$kbm$$){if($error$$)return $callback$$($error$$);$report$$=$kbm$$;async.mapLimit($report$$,20,function($r$$,$callback$$){if($r$$.cach_tinh=="1"||$r$$.phan_loai=="4")$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&&$r$$.ma_thue.length>0&&($r$$.ma_thue.length!=1||$r$$.ma_thue[0]!=="")&&($condition$$.ma_thue={$in:$r$$.ma_thue});$r$$.bang_du_lieu.toLowerCase()=="vatvao"?($r$$.ma_tc&&$r$$.ma_tc.length>0&&($r$$.ma_tc.length!=1||$r$$.ma_tc[0]!=="")&&($condition$$.ma_tc={$in:$r$$.ma_tc}),$r$$.tk&&$r$$.tk.length>0&&($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=$r$$.phan_loai=="1"||$r$$.phan_loai=="2"?$rs$$.csum("t_thue"):0;$r$$.t_tien=$r$$.phan_loai=="1"||$r$$.phan_loai=="3"?$rs$$.csum("t_tien"):0;$callback$$(null,$r$$)})):($r$$.tk&&$r$$.tk.length>0&&($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=$r$$.phan_loai=="1"||$r$$.phan_loai=="2"?$rs$$.csum("t_thue"): 0;$r$$.t_tien=$r$$.phan_loai=="1"||$r$$.phan_loai=="3"?$rs$$.csum("t_tien"):0;$callback$$(null,$r$$)}))}},function($error$$){if($error$$)return $callback$$($error$$);calcGrid($report$$,{t_tien:function($error$$,$rlq$$){$rlq$$.phan_loai=="3"||$rlq$$.phan_loai=="1"?$rlq$$.kieu_gia_tri=="1"&&$rlq$$.t_tien<0?$rlq$$.t_tien=0:$rlq$$.kieu_gia_tri=="2"&&$rlq$$.t_tien>0?$rlq$$.t_tien=0:$rlq$$.kieu_gia_tri=="3"&&($rlq$$.t_tien=Math.abs($rlq$$.t_tien)):$rlq$$.t_tien=0},t_thue:function($error$$,$rlq$$){$rlq$$.phan_loai== "2"||$rlq$$.phan_loai=="1"?$rlq$$.kieu_gia_tri=="1"&&$rlq$$.t_thue<0?$rlq$$.t_thue=0:$rlq$$.kieu_gia_tri=="2"&&$rlq$$.t_thue>0?$rlq$$.t_thue=0:$rlq$$.kieu_gia_tri=="3"&&($rlq$$.t_thue=Math.abs($rlq$$.t_thue)):$rlq$$.t_thue=0}},function($rs$$){$callback$$(null,$rs$$)})})})})};