flexbiz-server
Version:
Flexible Server
9 lines (8 loc) • 3.32 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");
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");let $thang$$=Number($condition$$.thang),$nam$$=Number($condition$$.nam);dmyt.find({id_app:$condition$$.id_app,th_sp:!0,status:!0}).lean().exec(($e$$,$yts$$)=>{if($e$$)return $fn$$($e$$);async.map($yts$$,($yt$$,$callback$jscomp$0$$)=>{async.parallel({gt:$callback$$=>
{setImmediate(()=>{let $cond$$={id_app:$condition$$.id_app,ma_yt:$yt$$.ma_yt,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_thcppstk.find($cond$$).lean().exec(($e$jscomp$0$$,$pstk$$)=>{if($e$jscomp$0$$)return $callback$$($e$jscomp$0$$);$pstk$$=$pstk$$.filter($p$$=>$p$$.ma_sp);$pstk$$.groupBy(["ma_sp","ma_bp",
"ma_yt","id_lenhsx"],["dd_dk","dd_dk_nt","ps_tk","ps_tk_nt"],($e$$,$rs$$)=>{if($e$$)return $callback$$($e$$);$rs$$.forEach($p$$=>{$p$$.co_do_dang=$yt$$.co_do_dang;$p$$.nam=$nam$$;$p$$.thang=$thang$$;$p$$.id_app=$condition$$.id_app;$p$$.yt_trung_gian=$yt$$.yt_trung_gian;$p$$.cong_tru=$yt$$.cong_tru});$callback$$(null,$rs$$)})})})}},function($e$$,$rs$$){$callback$jscomp$0$$($e$$,$rs$$.gt)})},($e$jscomp$1$$,$ps$$)=>{if($e$jscomp$1$$)return $fn$$($e$jscomp$1$$);setImmediate(()=>{let $data_pstk$$=$ps$$.reduce(($a$$,
$b$$)=>$a$$.concat($b$$),[]),$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$jscomp$0$$,$sltk$$)=>{if($e$jscomp$0$$)return $fn$$($e$jscomp$0$$);$data_pstk$$.joinModel2($sltk$$,{where:{ma_sp:"ma_sp",ma_bp:"ma_bp",id_lenhsx:"id_lenhsx"},
fields:"sl_dd_dk sl_nk_tk sl_sx_tk sl_dd_ck ty_le_ht_dk ty_le_ht_ck".split(" ")},()=>{for(let $s$$ of $data_pstk$$)$s$$.co_do_dang||($s$$.sl_dd_ck=0,$s$$.sl_dd_dk=0,$s$$.ty_le_ht_dk=0,$s$$.ty_le_ht_ck=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$$.sl_dd_dk_qd=$s$$.sl_dd_dk*$s$$.ty_le_ht_dk/100,$s$$.sl_dd_ck_qd=$s$$.sl_dd_ck*$s$$.ty_le_ht_ck/
100,$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=0===$s$$.sl_nk_tk?0:$s$$.t_cp_sx/$s$$.sl_sp_ht_qd,$s$$.gt_nt=0===$s$$.sl_nk_tk?0:$s$$.t_cp_sx_nt/$s$$.sl_sp_ht_qd,$s$$.t_gt=$s$$.gt*$s$$.sl_nk_tk,$s$$.t_gt_nt=$s$$.gt_nt*$s$$.sl_nk_tk,$s$$.dd_ck=$s$$.t_cp_sx-$s$$.t_gt,$s$$.dd_ck_nt=$s$$.t_cp_sx_nt-$s$$.t_gt_nt;gt_ctgt.create($data_pstk$$,($e$$,$rs$$)=>{$e$$&&
(console.error($e$$),console.error($data_pstk$$));$fn$$($e$$,$rs$$)})})})})})})};