flexbiz-server
Version:
Flexible Server
10 lines (9 loc) • 3.98 kB
JavaScript
'use strict';const dkcn=require("./dkcn"),ckcn=require("./ckcn"),vsocai=require("./vsocai"),Customer=global.getModel("customer"),async=require("async"),underscore=require("underscore");
module.exports=async($query$$,$fn$$)=>new Promise(($resolve$$,$reject$$)=>{setImmediate(async()=>{if(!($query$$.tk&&$query$$.tu_ngay&&$query$$.den_ngay&&$query$$.id_app))return $fn$$?($fn$$(Error("tk,tu_ngay, den_ngay and id_app parameter required")),$resolve$$({error:"tk,tu_ngay, den_ngay and id_app parameter required"})):$reject$$("tk,tu_ngay, den_ngay and id_app parameter required");if(!$query$$.ma_kh&&($query$$.nh_kh||$query$$.phu_trach)){let $_q$$={};$query$$.nh_kh&&($_q$$.nh_kh=$query$$.nh_kh);
$query$$.phu_trach&&($_q$$.phu_trach=$query$$.phu_trach);$query$$.ma_kh=await Customer.getList($query$$.id_app,$_q$$,"ma_kh")}async.series({dk:function($callback$$){setImmediate(()=>{let $condition$$={...$query$$};$condition$$.ngay=$query$$.tu_ngay;dkcn($condition$$,function($error$$,$result$$){if($error$$)return $callback$$($error$$);$callback$$(null,$result$$)})})},ps:function($callback$$){setImmediate(()=>{let $condition$$={id_app:$query$$.id_app};$condition$$.tk={$regex:"^"+$query$$.tk,$options:"i"};
$condition$$.ngay_ct={$gte:$query$$.tu_ngay,$lte:$query$$.den_ngay};$query$$.ma_dvcs&&($condition$$.ma_dvcs=$query$$.ma_dvcs);$query$$.ma_kh&&(underscore.isArray($query$$.ma_kh)?$condition$$.ma_kh={$in:$query$$.ma_kh}:$condition$$.ma_kh=$query$$.ma_kh);$query$$.ma_kho&&($condition$$.ma_kho=$query$$.ma_kho);$query$$.ma_bp&&($condition$$.ma_bp=$query$$.ma_bp);$query$$.ma_phi&&($condition$$.ma_phi=$query$$.ma_phi);$query$$.ma_nv&&($condition$$.ma_nv=$query$$.ma_nv);$query$$.ma_hd&&($condition$$.ma_hd=
$query$$.ma_hd);$query$$.ma_dt&&($condition$$.ma_dt=$query$$.ma_dt);vsocai.find($condition$$,function($error$$,$result$$){$callback$$($error$$,$result$$)})})},ck:function($callback$$){setImmediate(()=>{let $condition$$={...$query$$};$condition$$.ngay=$query$$.den_ngay;ckcn($condition$$,function($error$$,$result$$){if($error$$)return $callback$$($error$$);$callback$$(null,$result$$)})})}},function($error$jscomp$0$$,$results$$){if($error$jscomp$0$$)return $fn$$?($fn$$(Error($error$jscomp$0$$)),$resolve$$({error:$error$jscomp$0$$})):
$reject$$($error$jscomp$0$$);setImmediate(()=>{let $data$$=$results$$.ps;$results$$.dk.forEach(function($r$$){$r$$.dk_no=$r$$.du_no00;$r$$.dk_co=$r$$.du_co00;$r$$.dk_no_nt=$r$$.du_no_nt00;$r$$.dk_co_nt=$r$$.du_co_nt00;$data$$.push($r$$)});$results$$.ck.forEach(function($r$$){$r$$.ck_no=$r$$.du_no00;$r$$.ck_co=$r$$.du_co00;$r$$.ck_no_nt=$r$$.du_no_nt00;$r$$.ck_co_nt=$r$$.du_co_nt00;$data$$.push($r$$)});$query$$.groupBy&&0!=$query$$.groupBy.length||($query$$.groupBy=["ma_kh"]);$data$$.groupBy($query$$.groupBy,
[{name:"dk_no",value:"dk_no"},{name:"dk_co",value:"dk_co"},{name:"dk_no_nt",value:"dk_no_nt"},{name:"dk_co_nt",value:"dk_co_nt"},{name:"ps_no",value:"ps_no"},{name:"ps_co",value:"ps_co"},{name:"ps_no_nt",value:"ps_no_nt"},{name:"ps_co_nt",value:"ps_co_nt"},{name:"ck_no",value:"ck_no"},{name:"ck_co",value:"ck_co"},{name:"ck_no_nt",value:"ck_no_nt"},{name:"ck_co_nt",value:"ck_co_nt"}],function($error$$,$data$$){$data$$.forEach($d$$=>{$d$$.dk_no-=$d$$.dk_co;0<$d$$.dk_no?$d$$.dk_co=0:($d$$.dk_co=-$d$$.dk_no,
$d$$.dk_no=0);$d$$.dk_no_nt-=$d$$.dk_co_nt;0<$d$$.dk_no_nt?$d$$.dk_co_nt=0:($d$$.dk_co_nt=-$d$$.dk_no_nt,$d$$.dk_no_nt=0);$d$$.ck_no-=$d$$.ck_co;0<$d$$.ck_no?$d$$.ck_co=0:($d$$.ck_co=-$d$$.ck_no,$d$$.ck_no=0);$d$$.ck_no_nt-=$d$$.ck_co_nt;0<$d$$.ck_no_nt?$d$$.ck_co_nt=0:($d$$.ck_co_nt=-$d$$.ck_no_nt,$d$$.ck_no_nt=0)});$data$$=$data$$.filter($row$$=>0!==Math.abs($row$$.dk_no)+Math.abs($row$$.dk_co)+Math.abs($row$$.ps_no)+Math.abs($row$$.ps_co)+Math.abs($row$$.ck_no)+Math.abs($row$$.ck_co)+(Math.abs($row$$.dk_no_nt)+
Math.abs($row$$.dk_co_nt)+Math.abs($row$$.ps_no_nt)+Math.abs($row$$.ps_co_nt)+Math.abs($row$$.ck_no_nt)+Math.abs($row$$.ck_co_nt)));$fn$$&&$fn$$(null,$data$$);$resolve$$($data$$)})})})})});