flexbiz-server
Version:
Flexible Server
5 lines (4 loc) • 1.64 kB
JavaScript
var Customer=global.getModel("customer"),purchase_contract=global.getModel("purchase_contract"),sale_contract=global.getModel("sale_contract"),shipbook=global.getModel("shipbook"),dmdt=global.getModel("dmdt");const async=require("async"),controller=require("../../controllers/controllerRPT");
module.exports=function($router$$){new controller($router$$,"dutoanthuchitheodt",function($req$$,$callback$$){if(!$req$$.query.tu_ngay||!$req$$.query.den_ngay)return $callback$$("B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u tham s\u1ed1 tu_ngay, den_ngay");var $id_app$$=$req$$.query.id_app,$query$$={};$query$$.id_app=$id_app$$;$query$$.ngay_ct={$gte:$req$$.query.tu_ngay,$lte:$req$$.query.den_ngay};$req$$.query.ma_dt&&($query$$.ma_dt=$req$$.query.ma_dt);$req$$.query.ma_kh&&($query$$.ma_kh=$req$$.query.ma_kh);
purchase_contract.find($query$$).lean().exec(($e$$,$purchase$$)=>{if($e$$)return $callback$$($e$$);async.series({sale:$callback$$=>{$purchase$$.joinModel2($id_app$$,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"}},()=>{$callback$$()})},dt:$callback$$=>{$purchase$$.joinModel2($id_app$$,dmdt,{where:{ma_dt:"ma_dt"},fields:["ten_dt"]},()=>{$callback$$()})},shipbook:$callback$$=>{$purchase$$.joinModel2($id_app$$,
shipbook,{where:{ma_dt:"ma_dt"},fields:["ngay_tau_di","ngay_tau_den"]},()=>{$callback$$()})}},$e$$=>{if($e$$)return $callback$$($e$$);$purchase$$.joinModel2($id_app$$,Customer,[{where:{ma_kh_sale:"ma_kh"},fields:{ten_kh_sale:"ten_kh"}},{where:{ma_kh:"ma_kh"},fields:{ten_kh:"ten_kh"}}],()=>{$callback$$(null,$purchase$$)})})})})};