UNPKG

kpiplus

Version:

KPI+

1 lines 1.57 kB
var Customer=require("../../models/customer"),contract=require("../../models/contract"),purchase_contract=require("../../models/purchase_contract"),sale_contract=require("../../models/sale_contract"),shipbook=require("../../models/shipbook"),dmphi=require("../../models/dmphi"),dmdt=require("../../models/dmdt"),dmnv=require("../../models/dmnv"),group=require("../../models/group"),arrayFuncs=require("../../libs/array-funcs"),underscore=require("underscore"),async=require("async"),controller=require("../../controllers/controllerRPT"),stp=require("stp-utils"),moment=require("moment");module.exports=function(e){new controller(e,"dutoanthuchitheodt",function(e,r){if(!e.query.tu_ngay||!e.query.den_ngay)return r("Báo cáo này yêu cầu tham số tu_ngay, den_ngay");var t=e.query.id_app,a={};a.id_app=t,a.ngay_ct={$gte:e.query.tu_ngay,$lte:e.query.den_ngay},e.query.ma_dt&&(a.ma_dt=e.query.ma_dt),e.query.ma_kh&&(a.ma_kh=e.query.ma_kh),purchase_contract.find(a).lean().exec((e,a)=>{if(e)return r(e);async.parallel({sale:e=>{a.joinModel2(t,sale_contract,{where:{ma_dt:"ma_dt"},fields:{dot_thanh_toan_sale:"dot_thanh_toan",ma_kh_sale:"ma_kh",ty_gia_sale:"ty_gia",ma_nt_sale:"ma_nt"}},r=>{e()})},dt:e=>{a.joinModel2(t,dmdt,{where:{ma_dt:"ma_dt"},fields:["ten_dt"]},r=>{e()})},shipbook:e=>{a.joinModel2(t,shipbook,{where:{ma_dt:"ma_dt"},fields:["ngay_tau_di","ngay_tau_den"]},r=>{e()})}},(e,n)=>{if(e)return r(e);a.joinModel2(t,Customer,[{where:{ma_kh_sale:"ma_kh"},fields:{ten_kh_sale:"ten_kh"}},{where:{ma_kh:"ma_kh"},fields:{ten_kh:"ten_kh"}}],e=>{r(null,a)})})})})};