UNPKG

flexbiz-server

Version:

Flexible Server

14 lines (13 loc) 6.34 kB
'use strict';const socai=global.getModel("socai"),ctds=global.getModel("ctds"),dmkho=global.getModel("dmkho"),dmnv=global.getModel("dmnv"),dmbp=global.getModel("dmbp"),dmdt=global.getModel("dmdt"),dmphi=global.getModel("dmphi"),async=require("async"),underscore=require("underscore"),controller=require("../../controllers/controllerRPT"),moment=require("moment"),{getCodeChildren}=require("../../libs/utils"); module.exports=function($router$$){new controller($router$$,"sosanhkhvatt",async function($query_req$$,$callback$jscomp$1$$){let $condition$$=$query_req$$.query;if(!$condition$$.nam||!$condition$$.tu_thang||!$condition$$.den_thang)return $callback$jscomp$1$$("B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1 nam,tu_thang,den_thang");$query_req$$={id_app:$condition$$.id_app,tu_nam_thang:{$gte:12*Number($condition$$.nam)+Number($condition$$.tu_thang)},den_nam_thang:{$lte:12*Number($condition$$.nam)+ Number($condition$$.den_thang)}};$condition$$.ma_dvcs&&($query_req$$.ma_dvcs=$condition$$.ma_dvcs);$condition$$.ma_kho&&($query_req$$.ma_kho=$condition$$.ma_kho);$condition$$.ma_nv&&($query_req$$.ma_nv=$condition$$.ma_nv);if($condition$$.ma_bp){var $bps_dts_phis$$=await getCodeChildren(dmbp,$condition$$.id_app,$condition$$.ma_bp,"ma_bp","ma_bp_me");$query_req$$.ma_bp={$in:$bps_dts_phis$$}}$condition$$.ma_phi&&($bps_dts_phis$$=await getCodeChildren(dmphi,$condition$$.id_app,$condition$$.ma_phi,"ma_phi", "ma_phi_me"),$query_req$$.ma_phi={$in:$bps_dts_phis$$});$condition$$.ma_dt&&($bps_dts_phis$$=await getCodeChildren(dmdt,$condition$$.id_app,$condition$$.ma_dt,"ma_dt","ma_dt_me"),$query_req$$.ma_dt={$in:$bps_dts_phis$$});$condition$$.group_id&&($query_req$$.group_id=$condition$$.group_id);ctds.find($query_req$$).lean().exec(($e$$,$cts$$)=>{if($e$$)return $callback$jscomp$1$$($e$$);async.mapSeries($cts$$,($ct$$,$callback$jscomp$0$$)=>{setImmediate(async()=>{let $query$$={id_app:$ct$$.id_app,ma_dvcs:$ct$$.ma_dvcs}; $ct$$.ma_kho&&($query$$.ma_kho=$ct$$.ma_kho);$ct$$.ma_nv&&($query$$.ma_nv=$ct$$.ma_nv);if($ct$$.ma_bp){var $bps$jscomp$1_dts$jscomp$1_phis$$=await getCodeChildren(dmbp,$condition$$.id_app,$ct$$.ma_bp,"ma_bp","ma_bp_me");$query$$.ma_bp={$in:$bps$jscomp$1_dts$jscomp$1_phis$$}}$ct$$.ma_dt&&($bps$jscomp$1_dts$jscomp$1_phis$$=await getCodeChildren(dmdt,$condition$$.id_app,$ct$$.ma_dt,"ma_dt","ma_dt_me"),$query$$.ma_dt={$in:$bps$jscomp$1_dts$jscomp$1_phis$$});$ct$$.ma_phi&&($bps$jscomp$1_dts$jscomp$1_phis$$= await getCodeChildren(dmphi,$condition$$.id_app,$ct$$.ma_phi,"ma_phi","ma_phi_me"),$query$$.ma_phi={$in:$bps$jscomp$1_dts$jscomp$1_phis$$});$bps$jscomp$1_dts$jscomp$1_phis$$=moment().year($ct$$.nam).month($ct$$.tu_thang-1);let $den_ngay$$=moment().year($ct$$.nam).month($ct$$.den_thang-1);$query$$.ngay_ct={$gte:$bps$jscomp$1_dts$jscomp$1_phis$$.startOf("month").toDate(),$lte:$den_ngay$$.endOf("month").toDate()};async.series({dt:$callback$$=>{let $_query$$=Object.assign({},$query$$);var $tks_co_tks_no$$= $ct$$.tk_no;$tks_co_tks_no$$&&!$ct$$.tk_no_gt&&(underscore.isArray($tks_co_tks_no$$)||($tks_co_tks_no$$=[$tks_co_tks_no$$]),0<$tks_co_tks_no$$.length&&($_query$$.tk_no={$regex:$tks_co_tks_no$$.reg(),$options:"i"}));($tks_co_tks_no$$=$ct$$.tk_co)&&!$ct$$.tk_co_gt&&(underscore.isArray($tks_co_tks_no$$)||($tks_co_tks_no$$=[$tks_co_tks_no$$]),0<$tks_co_tks_no$$.length&&($_query$$.tk_co={$regex:$tks_co_tks_no$$.reg(),$options:"i"}));socai.find($_query$$).lean().exec(($e$$,$rs$$)=>{if($e$$)return console.log("error get data phat sinh", $e$$),$callback$$($e$$);$callback$$(null,$rs$$)})},gt:$callback$$=>{if($ct$$.tk_no&&0<$ct$$.tk_no.length&&$ct$$.tk_no_gt||$ct$$.tk_co&&0<$ct$$.tk_co.length&&$ct$$.tk_co_gt){let $_query$$=Object.assign({},$query$$);var $tks_co$jscomp$1_tks_no$$=$ct$$.tk_no;$tks_co$jscomp$1_tks_no$$&&$ct$$.tk_no_gt&&(underscore.isArray($tks_co$jscomp$1_tks_no$$)||($tks_co$jscomp$1_tks_no$$=[$tks_co$jscomp$1_tks_no$$]),0<$tks_co$jscomp$1_tks_no$$.length&&($_query$$.tk_no={$regex:$tks_co$jscomp$1_tks_no$$.reg(),$options:"i"})); ($tks_co$jscomp$1_tks_no$$=$ct$$.tk_co)&&$ct$$.tk_co_gt&&(underscore.isArray($tks_co$jscomp$1_tks_no$$)||($tks_co$jscomp$1_tks_no$$=[$tks_co$jscomp$1_tks_no$$]),0<$tks_co$jscomp$1_tks_no$$.length&&($_query$$.tk_co={$regex:$tks_co$jscomp$1_tks_no$$.reg(),$options:"i"}));socai.find($_query$$).lean().exec(($e$$,$rs$$)=>{if($e$$)return $callback$$($e$$);$callback$$(null,$rs$$)})}else $callback$$(null,[])}},($e$$,$rs$$)=>{if($e$$)return console.log("error get data giam tru",$e$$),$callback$jscomp$0$$($e$$); $ct$$.ps=$rs$$.dt.csum("tien")-$rs$$.gt.csum("tien");$ct$$.ps_nt=$rs$$.dt.csum("tien_nt")-$rs$$.gt.csum("tien_nt");$ct$$.cl=$ct$$.chi_tieu-$ct$$.ps;$ct$$.bold=!1;$ct$$.sysorder=0;$callback$jscomp$0$$(null,$ct$$)})})},$e$jscomp$0$$=>{if($e$jscomp$0$$)return console.log("error get data",$e$jscomp$0$$),$callback$jscomp$1$$($e$jscomp$0$$);async.series({kho:$callback$$=>{$cts$$.filter($d$$=>$d$$.ma_kho).joinModel2($condition$$.id_app,dmkho,{where:"ma_kho",fields:{ten_kho:"ten_kho"}},()=>{$callback$$()})}, nv:$callback$$=>{$cts$$.filter($d$$=>$d$$.ma_nv).joinModel2($condition$$.id_app,dmnv,{where:"ma_nv",fields:{ten_nv:"ten_nv"}},()=>{$callback$$()})},ma_bp:$callback$$=>{$cts$$.filter($d$$=>$d$$.ma_bp).joinModel2($condition$$.id_app,dmbp,{where:"ma_bp",fields:{ten_bp:"ten_bp"}},()=>{$callback$$()})},ma_dt:$callback$$=>{$cts$$.filter($d$$=>$d$$.ma_dt).joinModel2($condition$$.id_app,dmdt,{where:"ma_dt",fields:{ten_dt:"ten_dt"}},()=>{$callback$$()})},ma_phi:$callback$$=>{$cts$$.filter($d$$=>$d$$.ma_phi).joinModel2($condition$$.id_app, dmphi,{where:"ma_phi",fields:{ten_phi:"ten_phi"}},()=>{$callback$$()})},group:function($callback$$){$cts$$.filter($r$$=>$r$$.group_id).joinModel2($condition$$.id_app,global.getModel("group"),{where:{group_id:"_id"},fields:{group_name:"group_name"}},function(){$callback$$()})}},()=>{if($condition$$.groupby)$cts$$.groupBy($condition$$.groupby,["chi_tieu","ps","ps_nt","cl"],($e$$,$rs$$)=>{$callback$jscomp$1$$(null,$rs$$)});else{const $total$$={bold:!0,sysorder:5,group_name:"T\u1ed5ng c\u1ed9ng",chi_tieu:$cts$$.csum("chi_tieu"), ps:$cts$$.csum("ps"),ps_nt:$cts$$.csum("ps_nt"),cl:$cts$$.csum("cl"),nam:0,thang:0};$cts$$.push($total$$);$cts$$=underscore.sortBy($cts$$,$ct$$=>$ct$$.sysorder+"-"+$ct$$.year+"-"+$ct$$.thang);$callback$jscomp$1$$(null,$cts$$)}})})})})};