flexbiz-server
Version:
Flexible Server
9 lines (8 loc) • 3.73 kB
JavaScript
'use strict';const Customer=global.getModel("customer"),contract=global.getModel("contract"),dmphi=global.getModel("dmphi"),dmdt=global.getModel("dmdt"),dmnv=global.getModel("dmnv"),dmvt=global.getModel("dmvt"),Shipbook=global.getModel("shipbook"),underscore=require("underscore"),async=require("async"),controller=require("../../controllers/controllerRPT"),moment=require("moment");
module.exports=function($router$$){new controller($router$$,"bkshipbook",function($req$$,$callback$jscomp$0$$){const $query$$={};$query$$.id_app=$req$$.query.id_app;if($req$$.query.q){const $q$$=JSON.parse($req$$.query.q);underscore.extend($query$$,$q$$)}else $query$$.$and=[],$req$$.query.tu_ngay&&$query$$.$and.push({ngay_ct:{$gte:$req$$.query.tu_ngay}}),$req$$.query.den_ngay&&$query$$.$and.push({ngay_ct:{$lte:$req$$.query.den_ngay}}),$req$$.query.dien_giai&&($query$$.dien_giai={$regex:$req$$.query.dien_giai,
$options:"i"}),$req$$.query.so_ct&&($query$$.so_ct={$regex:$req$$.query.so_ct,$options:"i"}),$req$$.query.ma_phi&&($query$$.ma_phi=$req$$.query.ma_phi),$req$$.query.ma_kh&&($query$$.ma_kh=$req$$.query.ma_kh),$req$$.query.ma_hd&&($query$$.ma_hd=$req$$.query.ma_hd),$req$$.query.ma_dt&&($query$$.ma_dt=$req$$.query.ma_dt),$req$$.query.ma_nv&&($query$$.ma_nv=$req$$.query.ma_nv),$req$$.query.ma_dvcs&&($query$$.ma_dvcs=$req$$.query.ma_dvcs);Shipbook.find($query$$).lean().exec(function($error$jscomp$0$$,
$rp$$){if($error$jscomp$0$$)return $callback$jscomp$0$$($error$jscomp$0$$);async.series([function($callback$$){$rp$$.joinModel($req$$.query.id_app,Customer,[{akey:"ma_kh",bkey:"ma_kh",fields:[{name:"ten_kh",value:"ten_kh"},{name:"nh_kh",value:"nh_kh"}]}],function(){$callback$$()})},function($callback$$){$rp$$.joinModel($req$$.query.id_app,contract,[{akey:"ma_hd",bkey:"so_hd",fields:[{name:"ten_hd",value:"ten_hd"}]}],function(){$callback$$()})},function($callback$$){$rp$$.joinModel($req$$.query.id_app,
dmdt,[{akey:"ma_dt",bkey:"ma_dt",fields:[{name:"ten_dt",value:"ten_dt"}]}],function(){$callback$$()})},function($callback$$){$rp$$.joinModel($req$$.query.id_app,dmphi,[{akey:"ma_phi",bkey:"ma_phi",fields:[{name:"ten_phi",value:"ten_phi"}]}],function(){$callback$$()})},function($callback$$){$rp$$.joinModel($req$$.query.id_app,dmnv,[{akey:"ma_nv",bkey:"ma_nv",fields:[{name:"ten_nv",value:"ten_nv"}]}],function(){$callback$$()})}],function($error$$){let $report$$=[];$rp$$.forEach($r$$=>{let $m$$=JSON.parse(JSON.stringify($r$$));
$r$$.details.forEach($d$$=>{$d$$.master=$m$$;$d$$.exfields_detail||($d$$.exfields_detail={});$d$$.tien_phi_nt=$d$$.exfields_detail.tien_phi_nt||0;$d$$.tien_phi=$d$$.exfields_detail.tien_phi||0;$d$$.tien_phi_khac_nt=$d$$.exfields_detail.tien_phi_khac_nt||0;$d$$.tien_phi_khac=$d$$.exfields_detail.tien_phi_khac||0;$d$$.tong_cong_nt=($d$$.tien_nt||0)+$d$$.tien_phi_nt+$d$$.tien_phi_khac_nt;$d$$.tong_cong=($d$$.tien||0)+$d$$.tien_phi+$d$$.tien_phi_khac;$d$$.bold=!1;$d$$.systotal=0;$report$$.push($d$$)})});
$report$$.joinModel($req$$.query.id_app,dmvt,[{akey:"ma_vt",bkey:"ma_vt",fields:[{name:"ten_vt",value:"ten_vt"}]}],function(){$report$$=underscore.sortBy($report$$,function($r$$){return($r$$.master.ngay_ct?moment($r$$.master.ngay_ct).format("YYYYMMDD"):"0")+$r$$.master.ma_ct+$r$$.master.so_ct});var $rt$$={ten_vt:"T\u1ed5ng c\u1ed9ng",so_luong:$report$$.csum("so_luong"),tien_nt:$report$$.csum("tien_nt"),tien:$report$$.csum("tien"),tien_phi_nt:$report$$.csum("tien_phi_nt"),tien_phi:$report$$.csum("tien_phi"),
tien_phi_khac_nt:$report$$.csum("tien_phi_khac_nt"),tien_phi_khac:$report$$.csum("tien_phi_khac"),tong_cong_nt:$report$$.csum("tong_cong_nt"),tong_cong:$report$$.csum("tong_cong"),systotal:1,bold:!0};$report$$.push($rt$$);$callback$jscomp$0$$($error$$,$report$$)})})})})};