flexbiz-server
Version:
Flexible Server
7 lines (6 loc) • 2.41 kB
JavaScript
const pbl=global.getModel("pbl"),so1=global.getModel("so1"),dmvt=global.getModel("dmvt"),async=require("async"),controller=require("../../controllers/controllerRPT");
module.exports=function($router$$){new controller($router$$,"getinvoice2return_bl",function($req$$,$callback$$){const $condition$$=$req$$.query;if(!$condition$$.id_app||!$condition$$.tu_ngay||!$condition$$.den_ngay)return $callback$$("B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1:id_app,ma_kh,tu_ngay,den_ngay");async.parallel({pbl:$callback$$=>{let $query$$={};$condition$$.ma_kh&&($query$$.ma_kh=$condition$$.ma_kh);$query$$.id_app=$condition$$.id_app;$query$$.ngay_ct={$gte:$condition$$.tu_ngay,
$lte:$condition$$.den_ngay};$condition$$.ma_dvcs&&($query$$.ma_dvcs=$condition$$.ma_dvcs);$condition$$.so_ct&&($query$$.so_ct=$condition$$.so_ct);pbl.find($query$$).lean().exec(function($error$$,$results$$){if($error$$)return $callback$$($error$$);$callback$$(null,$results$$)})},so1:$callback$$=>{let $query$$={};$condition$$.ma_kh&&($query$$.ma_kh=$condition$$.ma_kh);$query$$.id_app=$condition$$.id_app;$query$$.ngay_ct={$gte:$condition$$.tu_ngay,$lte:$condition$$.den_ngay};$condition$$.ma_dvcs&&($query$$.ma_dvcs=
$condition$$.ma_dvcs);$condition$$.so_ct&&($query$$.so_ct=$condition$$.so_ct);so1.find($query$$).lean().exec(function($error$$,$results$$){if($error$$)return $callback$$($error$$);$callback$$(null,$results$$)})}},function($error$$,$results$$){if($error$$)return $callback$$($error$$);var $invoices$$=$results$$.pbl.concat($results$$.so1);async.mapLimit($invoices$$,20,function($invoice$$,$callback$$){var $ds$$=[];for(let $i$$=0;$i$$<$invoice$$.details.length;$i$$++){var $detail$$=$invoice$$.details[$i$$];
$detail$$.sl_nhap=$detail$$.sl_xuat;$detail$$.tien_nhap_nt=$detail$$.tien_xuat_nt;$detail$$.tien_nhap=$detail$$.tien_xuat;$detail$$.id_hd=$invoice$$._id.toString();$detail$$.so_ct=$invoice$$.so_ct;$detail$$.ngay_ct=$invoice$$.ngay_ct;$detail$$.so_hd=$invoice$$.so_hd;$detail$$.ngay_hd=$invoice$$.ngay_hd;$detail$$.ma_ct=$invoice$$.ma_ct;$detail$$.sel=!1;$ds$$.push($detail$$)}$invoice$$.details=$ds$$;$invoice$$.sel=!1;$ds$$.joinModel2($condition$$.id_app,dmvt,{where:"ma_vt",fields:[{name:"ten_vt",value:"ten_vt"},
{name:"tk_tl",value:"tk_tl"}]},function(){$callback$$(null,$invoice$$)})},function($error$$){if($error$$)return $callback$$($error$$);$callback$$(null,$invoices$$)})})},{cache:!1})};