flexbiz-server
Version:
Flexible Server
11 lines (10 loc) • 4.89 kB
JavaScript
'use strict';const Vsocai=require("./vsocai"),dstkcn=require("./dstkcn"),async=require("async"),underscore=require("underscore"),moment=require("moment");
module.exports=async function($condition$$,$fn$$){if($condition$$&&$condition$$.ngay&&$condition$$.id_app){if(!$condition$$.ma_kh&&($condition$$.nh_kh||$condition$$.phu_trach)){var $_q_app_ngay_chua_ks$$={};$condition$$.nh_kh&&($_q_app_ngay_chua_ks$$.nh_kh=$condition$$.nh_kh);$condition$$.phu_trach&&($_q_app_ngay_chua_ks$$.phu_trach=$condition$$.phu_trach);$condition$$.ma_kh=await global.getModel("customer").getList($condition$$.id_app,$_q_app_ngay_chua_ks$$,"ma_kh")}var $tk$$=$condition$$.tk;$tk$$||
($tk$$="");if(underscore.isArray($tk$$)){let $tks$$;$tk$$.forEach(function($t$$){$tks$$=$tks$$?$tks$$+"|^"+$t$$:"^"+$t$$});$tks$$||($tks$$="^");$tk$$={$regex:$tks$$,$options:"i"}}else $tk$$={$regex:"^"+$tk$$,$options:"i"};var $id_app$$=$condition$$.id_app,$ngay$$=new Date($condition$$.ngay);$ngay$$=moment($ngay$$).startOf("date").toDate();$_q_app_ngay_chua_ks$$=await global.getModel("app").findOne({_id:$id_app$$},{ngay_ks:1}).lean();if(!$_q_app_ngay_chua_ks$$)return $fn$$("C\u00f4ng ty kh\u00f4ng t\u1ed3n t\u1ea1i");
var $ngay_ks$$=moment($_q_app_ngay_chua_ks$$.ngay_ks).endOf("date").toDate();$_q_app_ngay_chua_ks$$=moment($_q_app_ngay_chua_ks$$.ngay_ks).startOf("date").add(1,"days").toDate();var $ngay_dn$$=moment($ngay$$).startOf("year").toDate();if($ngay$$<$_q_app_ngay_chua_ks$$||$ngay_dn$$>=$_q_app_ngay_chua_ks$$){var $Cdkh$$=global.getModel("cdkh");var $nam$$=$ngay$$.getFullYear()}else $Cdkh$$=global.getModel("cdkhtheongay"),$ngay_dn$$=$_q_app_ngay_chua_ks$$;async.parallel({dn:function($callback$$){let $c_dk$$=
{id_app:$id_app$$,tk:$tk$$};$nam$$?$c_dk$$.nam=$nam$$:(console.log("lay cdcn theo ngay khoa so",$ngay_ks$$),$c_dk$$.den_ngay=$ngay_ks$$);$condition$$.ma_kh&&(underscore.isArray($condition$$.ma_kh)?$c_dk$$.ma_kh={$in:$condition$$.ma_kh}:$c_dk$$.ma_kh=$condition$$.ma_kh);$condition$$.ma_dvcs&&($c_dk$$.ma_dvcs=$condition$$.ma_dvcs);$condition$$.ma_kho&&($c_dk$$.ma_kho=$condition$$.ma_kho);$condition$$.ma_bp&&($c_dk$$.ma_bp=$condition$$.ma_bp);$condition$$.ma_phi&&($c_dk$$.ma_phi=$condition$$.ma_phi);
$condition$$.ma_nv&&($c_dk$$.ma_nv=$condition$$.ma_nv);$condition$$.ma_hd&&($c_dk$$.ma_hd=$condition$$.ma_hd);$condition$$.ma_dt&&($c_dk$$.ma_dt=$condition$$.ma_dt);$Cdkh$$.find($c_dk$$).lean().exec(function($error$$,$results$$){$error$$?$callback$$($error$$):$callback$$(null,$results$$)})},ps:function($callback$$){async.waterfall([function($callback1$$){dstkcn($id_app$$,$tk$$,function($error$$,$accs$$){$error$$?$callback1$$($error$$):$callback1$$(null,$accs$$)})},function($accs$$,$callback1$$){$accs$$=
{id_app:$id_app$$,ngay_ct:{$gte:$ngay_dn$$,$lt:$ngay$$},tk:{$in:$accs$$}};$condition$$.ma_kh&&(underscore.isArray($condition$$.ma_kh)?$accs$$.ma_kh={$in:$condition$$.ma_kh}:$accs$$.ma_kh=$condition$$.ma_kh);$condition$$.ma_dvcs&&($accs$$.ma_dvcs=$condition$$.ma_dvcs);$condition$$.ma_kho&&($accs$$.ma_kho=$condition$$.ma_kho);$condition$$.ma_bp&&($accs$$.ma_bp=$condition$$.ma_bp);$condition$$.ma_phi&&($accs$$.ma_phi=$condition$$.ma_phi);$condition$$.ma_nv&&($accs$$.ma_nv=$condition$$.ma_nv);$condition$$.ma_hd&&
($accs$$.ma_hd=$condition$$.ma_hd);$condition$$.ma_dt&&($accs$$.ma_dt=$condition$$.ma_dt);$condition$$.ex_id_ct&&($accs$$.id_ct={$ne:$condition$$.ex_id_ct});Vsocai.find($accs$$,function($error$$,$pss$$){$error$$?$callback1$$($error$$):$callback1$$(null,$pss$$)})}],function($error$$,$result$$){$error$$?$callback$$($error$$):$callback$$(null,$result$$)})}},function($data_error$$,$groupBy_results$$){if($data_error$$)return $fn$$($data_error$$);$data_error$$=$groupBy_results$$.dn.concat($groupBy_results$$.ps);
$groupBy_results$$=$condition$$.groupBy||"tk ma_kh ma_kho ma_bp ma_phi ma_dt ma_hd ma_nv".split(" ");if(!underscore.isArray($groupBy_results$$))if(0<=$groupBy_results$$.indexOf("["))try{$groupBy_results$$=JSON.parse($groupBy_results$$)}catch($e$$){console.error("err parse json groupby",$groupBy_results$$),$groupBy_results$$=[$groupBy_results$$]}else $groupBy_results$$=0<=$groupBy_results$$.indexOf(",")?$groupBy_results$$.split(","):[$groupBy_results$$];$data_error$$.groupBy($groupBy_results$$,"du_no00 du_co00 du_no_nt00 du_co_nt00 ps_no ps_co ps_no_nt ps_co_nt".split(" "),
($error$$,$rs$$)=>{$error$$?$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;0>$r$$.du_no00&&($r$$.du_no00=0);0>$r$$.du_no_nt00&&($r$$.du_no_nt00=0);0>$r$$.du_co00&&($r$$.du_co00=0);0>$r$$.du_co_nt00&&($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$$("Ch\u1ee9c n\u0103ng n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: ngay")};