flexbiz-server
Version:
Flexible Server
6 lines (5 loc) • 2.28 kB
JavaScript
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$$){let $condition$$=$req$$.query;if(!$condition$$.nam)return $callback$$("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.parallel({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$$=$columns$$.map($c$$=>$c$$.value_field);$report$$.groupBy($condition$$.groupby,
$fields$$,($e$$,$rs$$)=>{$callback$$(null,{rows:$rs$$,columns:$columns$$})})}else{$report$$=_.sortBy($report$$,$ct$$=>$ct$$.sysorder+"-"+$ct$$.year+"-"+$ct$$.thang);const $total$$={bold:!0,sysorder:5,group_name:"T\u1ed5ng c\u1ed9ng",nam:0,thang:0};$columns$$.forEach($c$$=>{$total$$[$c$$.value_field]=$report$$.csum($c$$.value_field)});$report$$.push($total$$);$callback$$(null,{rows:$report$$,columns:$columns$$})}})}).catch($e$$=>{$callback$$($e$$)})},{cache:!1})};