UNPKG

flexbiz-server

Version:

Flexible Server

8 lines (7 loc) 2.91 kB
'use strict';const async=require("async"),_=require("lodash"),controller=require("../../controllers/controllerRPT"),kpistatus=require("../../libs/kpistatus"),dmkho=global.getModel("dmkho"),dmnv=global.getModel("dmnv"),dmbp=global.getModel("dmbp"),dmdt=global.getModel("dmdt"),dmphi=global.getModel("dmphi"); module.exports=function($router$$){new controller($router$$,"sosanhkhvatt2",async function($req$$,$callback$jscomp$0$$){let $condition$$=$req$$.query;if(!$condition$$.nam)return $callback$jscomp$0$$("B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1 nam");$condition$$.ct_theo||($condition$$.ct_theo="thang");kpistatus($condition$$).then($rs$$=>{let $report$$=$rs$$.rows,$columns$$=$rs$$.columns;async.series({kho:$callback$$=>{$report$$.filter($d$$=>$d$$.ma_kho).joinModel2($condition$$.id_app, dmkho,{where:"ma_kho",fields:{ten_kho:"ten_kho"}},()=>{$callback$$()})},nv:$callback$$=>{$report$$.filter($d$$=>$d$$.ma_nv).joinModel2($condition$$.id_app,dmnv,{where:"ma_nv",fields:{ten_nv:"ten_nv"}},()=>{$callback$$()})},ma_bp:$callback$$=>{$report$$.filter($d$$=>$d$$.ma_bp).joinModel2($condition$$.id_app,dmbp,{where:"ma_bp",fields:{ten_bp:"ten_bp"}},()=>{$callback$$()})},ma_dt:$callback$$=>{$report$$.filter($d$$=>$d$$.ma_dt).joinModel2($condition$$.id_app,dmdt,{where:"ma_dt",fields:{ten_dt:"ten_dt"}}, ()=>{$callback$$()})},ma_phi:$callback$$=>{$report$$.filter($d$$=>$d$$.ma_phi).joinModel2($condition$$.id_app,dmphi,{where:"ma_phi",fields:{ten_phi:"ten_phi"}},()=>{$callback$$()})},group:function($callback$$){$report$$.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){let $fields$$="chi_tieu ps ps_nt cl tien_hoa_hong t_tien_hoa_hong".split(" ");$columns$$.forEach($hh$$=> {$fields$$.push(`ps_tinh_hoa_hong_${$hh$$._id.toString()}`);$fields$$.push(`hoa_hong_${$hh$$._id.toString()}`)});$report$$.groupBy($condition$$.groupby,$fields$$,($e$$,$rs$$)=>{$callback$jscomp$0$$(null,$rs$$)})}else{let $t_ps$$=$report$$.csum("ps"),$t_chi_tieu$$=$report$$.csum("chi_tieu");const $total$$={bold:!0,sysorder:5,group_name:"T\u1ed5ng c\u1ed9ng",chi_tieu:$t_chi_tieu$$,ps:$t_ps$$,ps_nt:$report$$.csum("ps_nt"),cl:$report$$.csum("cl"),nam:0,thang:0,ty_le_ht:$t_chi_tieu$$?Math.roundBy($t_ps$$/ $t_chi_tieu$$*100,2):0,t_tien_hoa_hong:$report$$.csum("t_tien_hoa_hong")};$columns$$.forEach($hh$$=>{$total$$[`ps_tinh_hoa_hong_${$hh$$._id.toString()}`]=$report$$.csum(`ps_tinh_hoa_hong_${$hh$$._id.toString()}`);$total$$[`hoa_hong_${$hh$$._id.toString()}`]=$report$$.csum(`hoa_hong_${$hh$$._id.toString()}`)});$report$$.push($total$$);$report$$=_.sortBy($report$$,$ct$$=>$ct$$.sysorder+"-"+$ct$$.year+"-"+$ct$$.thang);$callback$jscomp$0$$(null,{rows:$report$$,columns:$columns$$})}})}).catch($e$$=>{$callback$jscomp$0$$($e$$)})}, {cache:!1})};