flexbiz-server
Version:
Flexible Server
7 lines (6 loc) • 2.57 kB
JavaScript
'use strict';const gt_ctgt=global.getModel("gt_ctgt"),dmvt=global.getModel("dmvt"),controller=require("../../controllers/controllerRPT"),async=require("async"),underscore=require("underscore");
module.exports=function($router$$){new controller($router$$,"thgt",function($req$$,$callback$jscomp$0$$){const $condition$$=$req$$.query;if(!$condition$$.nam||!$condition$$.thang)return $callback$jscomp$0$$("Ch\u1ee9c n\u0103ng n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: nam,thang");$condition$$.nam=Number($condition$$.nam);$condition$$.thang=Number($condition$$.thang);(new Promise(($resolve$$,$reject$$)=>{let $cond$$={id_app:$condition$$.id_app,nam:$condition$$.nam,thang:$condition$$.thang,
yt_trung_gian:{$ne:!0}};$condition$$.ma_bp&&($cond$$.ma_bp=$condition$$.ma_bp.toUpperCase());$condition$$.id_lenhsx&&mongoose.Types.ObjectId.isValid($condition$$.id_lenhsx)&&($cond$$.id_lenhsx=$condition$$.id_lenhsx);gt_ctgt.find($cond$$).lean().exec(($e$$,$rs$$)=>{if($e$$)return $reject$$($e$$);$rs$$.forEach($r$$=>{"2"==$r$$.cong_tru&&($r$$.gt=-$r$$.gt,$r$$.gt_nt=-$r$$.gt_nt,$r$$.t_gt=-$r$$.t_gt,$r$$.t_gt_nt=-$r$$.t_gt_nt)});$resolve$$($rs$$)})})).then($ctgt$$=>new Promise(($resolve$$,$reject$$)=>
{async.series({dsyt:$callback$$=>{$ctgt$$.groupBy(["ma_yt"],["gt"],($e$$,$yts$$)=>{$callback$$(null,$yts$$)})},thgt:$callback$$=>{$ctgt$$.groupBy(["ma_sp","ma_bp","id_lenhsx"],["gt","gt_nt","t_gt","t_gt_nt"],($e$$,$rs$$)=>{$callback$$(null,$rs$$)},{fieldmaxs:["sl_dd_dk","sl_nk_tk","sl_sx_tk","sl_dd_ck"]})}},($e$$,$rs$$)=>{if($e$$)return $reject$$($e$$);const $report$$=$rs$$.thgt;$ctgt$$.forEach($ytgt$$=>{const $r$$=underscore.find($report$$,$re$$=>$re$$.ma_sp==$ytgt$$.ma_sp&&$re$$.ma_bp==$ytgt$$.ma_bp&&
$re$$.id_lenhsx==$ytgt$$.id_lenhsx);$r$$&&($r$$[$ytgt$$.ma_yt]=$ytgt$$.t_gt,$r$$[$ytgt$$.ma_yt+"_nt"]=$ytgt$$.t_gt_nt)});$resolve$$({report:$report$$,dsyt:$rs$$.dsyt})})})).then(async $rs$$=>{await $rs$$.report.filter($r$$=>$r$$.id_lenhsx).asyncJoinModel2($condition$$.id_app,"lenhsx",[{where:{id_lenhsx:"_id"},fields:[{name:"so_lenhsx",value:"so_ct"}]}]);$rs$$.report.joinModel2($condition$$.id_app,dmvt,[{where:{ma_sp:"ma_vt"},fields:[{name:"ten_sp",value:"ten_vt"}]}],()=>{const $sum$$="sl_dd_dk sl_sx_tk sl_nk_tk sl_dd_ck t_gt t_gt_nt".split(" ");
$rs$$.dsyt.forEach($yt$$=>{$sum$$.push($yt$$.ma_yt)});$rs$$.report.groupBy([],$sum$$,($e$$,$tc$$)=>{$tc$$.forEach($r$$=>{$r$$.bold=!0;$r$$.ten_sp="T\u1ed5ng c\u1ed9ng";$rs$$.report.push($r$$)})});$callback$jscomp$0$$(null,$rs$$)})}).catch($e$$=>{console.log("error",$e$$);$callback$jscomp$0$$($e$$)})})};