kpiplus
Version:
KPI+
1 lines • 1.08 kB
JavaScript
var Vsocai=require("../models/vsocai"),socai=require("../models/socai"),async=require("async"),underscore=require("underscore");exports.find=function(n,o){async.parallel({ps_no:function(o){let _={};underscore.extend(_,n),_.tk&&(_.tk_no=_.tk,delete _.tk),_.ma_kh&&(_.ma_kh_no=_.ma_kh,delete _.ma_kh),socai.find(_).lean().exec(function(n,_){if(n)return o(n);_.forEach(function(n){n.tk=n.tk_no,n.tk_du=n.tk_co,n.ma_kh=n.ma_kh_no,!n.ma_kh&&n.ma_kh_co&&(n.ma_kh=n.ma_kh_co),n.ps_no_nt=n.tien_nt,n.ps_no=Math.round(n.tien,0),n.ps_co_nt=0,n.ps_co=0}),o(null,_)})},ps_co:function(o){let _={};underscore.extend(_,n),_.tk&&(_.tk_co=_.tk,delete _.tk),_.ma_kh&&(_.ma_kh_co=_.ma_kh,delete _.ma_kh),socai.find(_).lean().exec(function(n,_){if(n)return o(n);_.forEach(function(n){n.tk=n.tk_co,n.tk_du=n.tk_no,n.ma_kh=n.ma_kh_co,!n.ma_kh&&n.ma_kh_no&&(n.ma_kh=n.ma_kh_no),n.ps_co_nt=n.tien_nt,n.ps_co=Math.round(n.tien,0),n.ps_no_nt=0,n.ps_no=0}),o(null,_)})}},function(n,_){if(n)return o(n);var e=[];_.ps_no.forEach(function(n){e.push(n)}),_.ps_co.forEach(function(n){e.push(n)}),o(null,e)})};