flexbiz-server
Version:
Flexible Server
5 lines (4 loc) • 1.55 kB
JavaScript
const kehoachmh=global.getModel("kehoachmh"),dmvt=global.getModel("dmvt"),congdoansx=global.getModel("congdoansx"),async=require("async"),controller=require("../../controllers/controllerRPT");
module.exports=function($router$$){new controller($router$$,"getkehoachmh4lenhcp",function($req$$,$callback$$){const $condition$$=$req$$.query;async.series({kehoachmh:function($callback$$){let $query$$={id_app:$condition$$.id_app,ngay_ct:{$gte:$condition$$.tu_ngay,$lte:$condition$$.den_ngay}};$condition$$.id_lenhsx&&($query$$.id_lenhsx=$condition$$.id_lenhsx);$condition$$.id_contract&&($query$$.id_contract=$condition$$.id_contract);$condition$$.so_ct&&($query$$.so_ct={$regex:$query$$.so_ct,$options:"i"});
kehoachmh.find($query$$).lean().exec(($e$$,$khmhs$$)=>{if($e$$)return $callback$$($e$$.message);$khmhs$$.forEach($khmh$$=>{$khmh$$.details.forEach($d$$=>{$d$$.so_luong=$d$$.sl_ke_hoach})});async.parallel({ten_vt_sp:$callback$$=>{async.mapLimit($khmhs$$,20,$khmh$$=>{$khmh$$.details.joinModel2($condition$$.id_app,dmvt,[{where:"ma_vt",fields:"ten_vt"},{where:{ma_sp:"ma_vt"},fields:{ten_sp:"ten_vt"}}],()=>{$callback$$()})},()=>{$callback$$()})},congdoan:$callback$$=>{async.mapLimit($khmhs$$,20,$khmh$$=>
{$khmh$$.details.joinModel2($condition$$.id_app,congdoansx,[{where:{ma_cong_doan:"ma_cong_doan"},fields:{ten_cong_doan:"ten_cong_doan"}}],()=>{$callback$$()})},()=>{$callback$$()})}},()=>{$callback$$(null,$khmhs$$)})})}},function($error$$,$results$$){if($error$$)return $callback$$($error$$);$callback$$(null,$results$$.kehoachmh)})})};