UNPKG

flexbiz-server

Version:

Flexible Server

8 lines (7 loc) 3.2 kB
const kbmkqhdkd=global.getModel("kbmkqhdkd"),{calcGrid,sumByCondition}=require("../../libs/utils"),async=require("async"),controller=require("../../controllers/controllerRPT"),getRegString=function($arrayTk$$){return $arrayTk$$.reg()}; module.exports=function($router$$){new controller($router$$,"kqhdkd",function($kbm_query_req$$,$callback$$){const $query$$=$kbm_query_req$$.query;if(!$query$$.den_ngay||!$query$$.tu_ngay)return $callback$$("B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u tham s\u1ed1: t\u1eeb ng\u00e0y(tu_ngay), \u0111\u1ebfn ng\u00e0y(den_ngay)");$query$$.tu_ngay=new Date($query$$.tu_ngay);$query$$.den_ngay=new Date($query$$.den_ngay);$query$$.tu_ngay_kt&&$query$$.den_ngay_kt||($query$$.tu_ngay_kt=new Date($query$$.tu_ngay), $query$$.tu_ngay_kt.setYear($query$$.tu_ngay_kt.getFullYear()-1),$query$$.den_ngay_kt=new Date($query$$.den_ngay),$query$$.den_ngay_kt.setYear($query$$.den_ngay_kt.getFullYear()-1));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,""]};let $socai$$;$socai$$=$query$$.ma_kho?global.getModel("socaitc"):global.getModel("socaitt");kbmkqhdkd.find($kbm_query_req$$).sort({stt:1}).lean().then(function($kbm$$){$report$$= $kbm$$;async.map($report$$,function($r$$,$c1$$){setImmediate(()=>{$r$$.cach_tinh=="1"?$c1$$(null,$r$$):async.parallel({ky_truoc:function($callback$$){const $condition$$={ngay_ct:{$gte:$query$$.tu_ngay_kt,$lte:$query$$.den_ngay_kt},id_app:$query$$.id_app};$query$$.ma_dvcs&&($condition$$.ma_dvcs=$query$$.ma_dvcs);$query$$.ma_kho&&($condition$$.ma_kho=$query$$.ma_kho);var $tk_co_tk_no$$=getRegString($r$$.tk_no);$tk_co_tk_no$$&&($condition$$.tk_no=$r$$.giam_tru_no?{$not:new RegExp($tk_co_tk_no$$)}:{$regex:$tk_co_tk_no$$, $options:"i"});if($tk_co_tk_no$$=getRegString($r$$.tk_co))$condition$$.tk_co=$r$$.giam_tru_co?{$not:new RegExp($tk_co_tk_no$$)}:{$regex:$tk_co_tk_no$$,$options:"i"};sumByCondition($socai$$,["tien","tien_nt"],$condition$$).then($rs$$=>{$r$$.ky_truoc=$rs$$.tien;$r$$.ky_truoc_nt=$rs$$.tien_nt;$callback$$(null,$r$$)}).catch($e$$=>{$callback$$($e$$)})},ky_nay:function($callback$$){const $condition$$={ngay_ct:{$gte:$query$$.tu_ngay,$lte:$query$$.den_ngay},id_app:$query$$.id_app};$query$$.ma_dvcs&&($condition$$.ma_dvcs= $query$$.ma_dvcs);$query$$.ma_kho&&($condition$$.ma_kho=$query$$.ma_kho);var $tk_co$jscomp$1_tk_no$$=getRegString($r$$.tk_no);$tk_co$jscomp$1_tk_no$$&&($condition$$.tk_no=$r$$.giam_tru_no?{$not:new RegExp($tk_co$jscomp$1_tk_no$$)}:{$regex:$tk_co$jscomp$1_tk_no$$,$options:"i"});if($tk_co$jscomp$1_tk_no$$=getRegString($r$$.tk_co))$condition$$.tk_co=$r$$.giam_tru_co?{$not:new RegExp($tk_co$jscomp$1_tk_no$$)}:{$regex:$tk_co$jscomp$1_tk_no$$,$options:"i"};sumByCondition($socai$$,["tien","tien_nt"],$condition$$).then($rs$$=> {$r$$.ky_nay=$rs$$.tien;$r$$.ky_nay_nt=$rs$$.tien_nt;$callback$$(null,$r$$)}).catch($e$$=>{$callback$$($e$$)})}},function($error$$,$results$$){$c1$$($error$$,$results$$)})})},function($error$$){if($error$$)return $callback$$($error$$);calcGrid($report$$,"ky_nay,ky_nay_nt,ky_truoc,ky_truoc_nt",function($rs$$){$callback$$(null,$rs$$)})})}).catch($e$$=>{$callback$$($e$$)})})};