flexbiz-server
Version:
Flexible Server
13 lines (12 loc) • 5.44 kB
JavaScript
'use strict';const dmyt=global.getModel("dmyt"),gt_thcppstk=global.getModel("gt_thcppstk"),gt_ctgt=global.getModel("gt_ctgt"),gt_sltk=global.getModel("gt_sltk"),async=require("async"),underscore=require("underscore"),utils=require("../libs/utils");
module.exports=function($condition$$,$fn$$){if(!($condition$$&&$condition$$.thang&&$condition$$.nam&&$condition$$.id_app))return $fn$$("L\u1ed7i: T\u00ednh n\u0103ng n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: thang,nam,id_app,ma_yt");(new Promise(($resole$$,$reject$$)=>{setImmediate(()=>{let $cond$$={id_app:$condition$$.id_app,nam:$condition$$.nam,thang:$condition$$.thang};$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$$,$ctgt$$)=>{if($e$$)return $reject$$($e$$);$resole$$($ctgt$$)})})})).then($ctgt$$=>new Promise(($resolve$$,$reject$$)=>{setImmediate(()=>{var $dsyt_datinh_query_yt$$=underscore.pluck($ctgt$$,"ma_yt");$dsyt_datinh_query_yt$$={id_app:$condition$$.id_app,status:!0,pt_phan_bo:"2",th_sp:!1,ma_yt:{$nin:$dsyt_datinh_query_yt$$},yt_tinh_hs_pb:{$in:$dsyt_datinh_query_yt$$}};$condition$$.ma_bp&&($dsyt_datinh_query_yt$$.ma_bp=
{$in:[$condition$$.ma_bp.toUpperCase(),null,void 0]});dmyt.find($dsyt_datinh_query_yt$$).lean().exec(($e$$,$yts$$)=>{if($e$$)return $reject$$($e$$);$resolve$$({yts:$yts$$,ctgt_tinhheso:$ctgt$$})})})})).then($data$$=>new Promise(($resolve$$,$reject$$)=>{setImmediate(()=>{var $cond$jscomp$1_yts$$=underscore.pluck($data$$.yts,"ma_yt");$cond$jscomp$1_yts$$={id_app:$condition$$.id_app,nam:$condition$$.nam,thang:$condition$$.thang,ma_yt:{$in:$cond$jscomp$1_yts$$}};$condition$$.ma_bp&&($cond$jscomp$1_yts$$.ma_bp=
$condition$$.ma_bp.toUpperCase());$condition$$.id_lenhsx&&mongoose.Types.ObjectId.isValid($condition$$.id_lenhsx)&&($cond$jscomp$1_yts$$.id_lenhsx=$condition$$.id_lenhsx);gt_thcppstk.find($cond$jscomp$1_yts$$).lean().exec(($e$jscomp$0$$,$cppstk$$)=>{if($e$jscomp$0$$)return $reject$$($e$jscomp$0$$);$cppstk$$.groupBy(["ma_bp","ma_yt","id_lenhsx"],["dd_dk","dd_dk_nt","ps_tk","ps_tk_nt"],($e$$,$rs$$)=>{if($e$$)return $reject$$($e$$);$rs$$.forEach($p$$=>{$p$$.ma_bp=$p$$.ma_bp||"";$p$$.ma_yt=$p$$.ma_yt||
"";$p$$.id_lenhsx=$p$$.id_lenhsx||""});$data$$.cppstk=$rs$$;$resolve$$($data$$)})})})})).then($data$$=>new Promise(($resolve$$,$reject$$)=>{setImmediate(()=>{let $cond$$={id_app:$condition$$.id_app,nam:$condition$$.nam,thang:$condition$$.thang};$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_sltk.find($cond$$).lean().exec(($e$$,$sltk$$)=>{if($e$$)return $reject$$($e$$);
$sltk$$.forEach($p$$=>{$p$$.ma_bp=$p$$.ma_bp||"";$p$$.id_lenhsx=$p$$.id_lenhsx||""});$data$$.sltk=$sltk$$;$resolve$$($data$$)})})})).then($data$$=>{async.map($data$$.yts,($yt$$,$callback$$)=>{setImmediate(()=>{var $cppstk$$=underscore.filter($data$$.ctgt_tinhheso,$c$$=>$c$$.ma_yt==$yt$$.yt_tinh_hs_pb);let $t_gt$$=$cppstk$$.csum("t_gt"),$gts$$=[];$cppstk$$.forEach($yths$$=>{let $gt$$={ma_sp:$yths$$.ma_sp,ma_bp:$yths$$.ma_bp||"",id_lenhsx:$yths$$.id_lenhsx||"",ma_yt:$yt$$.ma_yt,id_app:$yths$$.id_app,
nam:$yths$$.nam,thang:$yths$$.thang};$gt$$.he_so=0!==$t_gt$$?$yths$$.t_gt/$t_gt$$:0;$gt$$.yt_trung_gian=$yt$$.yt_trung_gian;$gt$$.cong_tru=$yt$$.cong_tru;$gts$$.push($gt$$)});$cppstk$$=underscore.filter($data$$.cppstk,$c$$=>$c$$.ma_yt==$yt$$.ma_yt);$gts$$.crossJoin($cppstk$$,{ma_bp:"ma_bp",id_lenhsx:"id_lenhsx"},$rs$$=>{$callback$$(null,$rs$$)})})},($e$jscomp$0$$,$rs$jscomp$0$$)=>{if($e$jscomp$0$$)return $fn$$($e$jscomp$0$$);setImmediate(()=>{let $data_pstk$$=[];$rs$jscomp$0$$.forEach($r$$=>{$r$$.forEach($_r$$=>
{$data_pstk$$.push($_r$$)})});$data_pstk$$.crossJoin($data$$.sltk,{ma_sp:"ma_sp",ma_bp:"ma_bp",id_lenhsx:"id_lenhsx"},$data_pstk$$=>{for(let $s$$ of $data_pstk$$)delete $s$$._id,$s$$.co_do_dang||($s$$.ty_le_ht_dk=0,$s$$.ty_le_ht_ck=0),$s$$.he_so||($s$$.he_so=0),$s$$.sl_dd_dk||($s$$.sl_dd_dk=0),$s$$.sl_nk_tk||($s$$.sl_nk_tk=0),$s$$.sl_sx_tk||($s$$.sl_sx_tk=0),$s$$.sl_dd_ck||($s$$.sl_dd_ck=0),$s$$.ty_le_ht_ck||($s$$.ty_le_ht_ck=0),$s$$.ty_le_ht_dk||($s$$.ty_le_ht_dk=0),$s$$.dd_dk||($s$$.dd_dk=0),$s$$.dd_dk_nt||
($s$$.dd_dk_nt=0),$s$$.ps_tk||($s$$.ps_tk=0),$s$$.ps_tk_nt||($s$$.ps_tk_nt=0),$s$$.dd_dk=utils.round($s$$.he_so*$s$$.dd_dk,5),$s$$.dd_dk_nt=utils.round($s$$.he_so*$s$$.dd_dk_nt,5),$s$$.ps_tk=utils.round($s$$.he_so*$s$$.ps_tk,5),$s$$.ps_tk_nt=utils.round($s$$.he_so*$s$$.ps_tk_nt,5),$s$$.sl_dd_dk_qd=utils.round($s$$.sl_dd_dk*$s$$.ty_le_ht_dk/100,5),$s$$.sl_dd_ck_qd=utils.round($s$$.sl_dd_ck*$s$$.ty_le_ht_ck/100,5),$s$$.sl_sx_tk=$s$$.sl_dd_ck+$s$$.sl_nk_tk-$s$$.sl_dd_dk,$s$$.sl_sp_ht_qd=$s$$.sl_dd_ck_qd+
$s$$.sl_nk_tk,$s$$.t_cp_sx=$s$$.dd_dk+$s$$.ps_tk,$s$$.t_cp_sx_nt=$s$$.dd_dk_nt+$s$$.ps_tk_nt,$s$$.gt=utils.round(0===$s$$.sl_nk_tk?0:$s$$.t_cp_sx/$s$$.sl_sp_ht_qd,5),$s$$.gt_nt=utils.round(0===$s$$.sl_nk_tk?0:$s$$.t_cp_sx_nt/$s$$.sl_sp_ht_qd,5),$s$$.t_gt=utils.round($s$$.gt*$s$$.sl_nk_tk,5),$s$$.t_gt_nt=utils.round($s$$.gt_nt*$s$$.sl_nk_tk,5),$s$$.dd_ck=utils.round($s$$.t_cp_sx-$s$$.t_gt,5),$s$$.dd_ck_nt=utils.round($s$$.t_cp_sx_nt-$s$$.t_gt_nt,5);gt_ctgt.create($data_pstk$$,($e$$,$rs$$)=>{$e$$&&
console.log($e$$);$fn$$($e$$,$rs$$)})})})})}).catch($e$$=>{$fn$$($e$$)})};