UNPKG

flexbiz-server

Version:

Flexible Server

7 lines (6 loc) 2.48 kB
const cddt=global.getModel("cddt"),Vsocai=require("./vsocai"),async=require("async"),underscore=require("underscore"),moment=require("moment"); module.exports=function($condition$$,$fn$$){if($condition$$&&$condition$$.ngay&&$condition$$.id_app&&$condition$$.tk){var $ma_dvcs$$=$condition$$.ma_dvcs;$ma_dvcs$$||="";$ma_dvcs$$={$regex:$ma_dvcs$$,$options:"i"};var $tk$$=$condition$$.tk;if(underscore.isArray($tk$$)){let $tks$$;$tk$$.forEach(function($t$$){$tks$$=$tks$$?$tks$$+"|^"+$t$$:"^"+$t$$});$tks$$||="^";$tk$$={$regex:$tks$$,$options:"i"}}else $tk$$={$regex:"^"+$tk$$,$options:"i"};var $ma_dt$$=$condition$$.ma_dt;$ma_dt$$||={$ne:""};var $ngay$$= moment(new Date($condition$$.ngay)).startOf("date").toDate(),$nam$$=$ngay$$.getFullYear(),$ngay_dn$$=moment($ngay$$).startOf("year").toDate(),$id_app$$=$condition$$.id_app;async.series({dn:function($callback$$){setImmediate(()=>{cddt.find({id_app:$id_app$$,nam:$nam$$,tk:$tk$$,ma_dt:$ma_dt$$,ma_dvcs:$ma_dvcs$$}).lean().then(function($results$$){$callback$$(null,$results$$)}).catch($error$$=>{$callback$$({message:$error$$.message})})})},ps:function($callback$$){setImmediate(()=>{Vsocai.find({id_app:$id_app$$, ngay_ct:{$gte:$ngay_dn$$,$lt:$ngay$$},ma_dt:$ma_dt$$,tk:$tk$$,ma_dvcs:$ma_dvcs$$},function($error$$,$pss$$){$error$$?$callback$$($error$$):$callback$$(null,$pss$$)})})}},function($error$$,$results$$){if($error$$)return $fn$$($error$$);const $data$$=$results$$.dn;$results$$.ps.forEach(function($r$$){$data$$.push($r$$)});$error$$=$condition$$.groupBy||["tk","ma_dt"];if(!underscore.isArray($error$$))if($error$$.indexOf("[")>=0)try{$error$$=JSON.parse($error$$)}catch($e$$){Logger.error("err parse json groupby", $error$$),$error$$=[$error$$]}else $error$$=$error$$.indexOf(",")>=0?$error$$.split(","):[$error$$];$data$$.groupBy($error$$,"du_no00 du_co00 du_no_nt00 du_co_nt00 ps_no ps_co ps_no_nt ps_co_nt".split(" "),($error$$,$rs$$)=>{if($error$$)return $fn$$($error$$);$rs$$.forEach($r$$=>{$r$$.du_no00=$r$$.du_no00+$r$$.ps_no-$r$$.du_co00-$r$$.ps_co;$r$$.du_no_nt00=$r$$.du_no_nt00+$r$$.ps_no_nt-$r$$.du_co_nt00-$r$$.ps_co_nt;$r$$.du_co00=0-$r$$.du_no00;$r$$.du_co_nt00=0-$r$$.du_no_nt00;$r$$.du_no00<0&&($r$$.du_no00= 0);$r$$.du_no_nt00<0&&($r$$.du_no_nt00=0);$r$$.du_co00<0&&($r$$.du_co00=0);$r$$.du_co_nt00<0&&($r$$.du_co_nt00=0);$r$$.ps_no_nt=0;$r$$.ps_co_nt=0;$r$$.ps_no=0;$r$$.ps_co=0});$fn$$(null,$rs$$)})})}else $fn$$(Error("H\u00e0m n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1 ngay,id_app,tk"))};