flexbiz-server
Version:
Flexible Server
7 lines (6 loc) • 2.71 kB
JavaScript
'use strict';const sokho=global.getModel("sokho"),dmvt=global.getModel("dmvt"),dmkho=global.getModel("dmkho"),dmbp=global.getModel("dmbp"),controller=require("../../controllers/controllerRPT"),async=require("async"),moment=require("moment");
module.exports=function($router$$){new controller($router$$,"gt_cpnvltt",function($query_req$$,$callback$jscomp$0$$){$query_req$$=$query_req$$.query;let $id_app$$=$query_req$$.id_app,$condition$$={id_app:$id_app$$,nxt:2};$condition$$.ngay_ct={$gte:$query_req$$.tu_ngay,$lte:$query_req$$.den_ngay};$query_req$$.id_ct&&($condition$$.id_ct=$query_req$$.id_ct);$query_req$$.ma_vt&&($condition$$.ma_vt=$query_req$$.ma_vt);$condition$$.ma_sp=$query_req$$.ma_sp?$query_req$$.ma_sp:{$nin:[null,""]};$query_req$$.ma_ct&&
($condition$$.ma_ct=$query_req$$.ma_ct.toUpperCase());$query_req$$.ma_kho&&($condition$$.ma_kho=$query_req$$.ma_kho);$query_req$$.ma_kh&&($condition$$.ma_kh=$query_req$$.ma_kh);$query_req$$.ma_nv&&($condition$$.ma_nv=$query_req$$.ma_nv);$query_req$$.tk_vt&&($condition$$.tk_vt={$regex:"^"+$query_req$$.tk_vt,$options:"i"});$query_req$$.tk_gv&&($condition$$.tk_gv={$regex:"^"+$query_req$$.tk_gv,$options:"i"});$query_req$$.tk_dt&&($condition$$.tk_dt={$regex:"^"+$query_req$$.tk_dt,$options:"i"});sokho.find($condition$$).sort({ngay_ct:1,
so_ct:1}).lean().exec(async($error$$,$report$$)=>{if($error$$)return $callback$jscomp$0$$($error$$);$report$$.forEach($r$$=>{$r$$.sysorder=5;$r$$.bold=!1});$error$$=await $report$$.asyncGroupBy("id_ct so_ct ngay_ct ma_kho ma_bp ma_sp ma_tt1_sp".split(" "),["sl_xuat","sl_xuat_qd","tien_xuat","sl_sp"]);$error$$.forEach($r$$=>{$r$$.sysorder=1;$r$$.bold=!0;$r$$.ma_vt=$r$$.ma_sp;$r$$.ma_tt1=$r$$.ma_tt1_sp;$r$$.sl_xuat_qd=$r$$.sl_sp});$report$$=$report$$.concat($error$$);async.series({vt:$callback$$=>{$report$$.filter($r$$=>
$r$$.ma_vt).joinModel2($id_app$$,dmvt,[{where:"ma_vt",fields:["ten_vt","ma_dvt"]}],function(){$callback$$()})},kho:$callback$$=>{$report$$.filter($r$$=>$r$$.ma_kho).joinModel2($id_app$$,dmkho,[{where:"ma_kho",fields:"ten_kho"}],function(){$callback$$()})},bp:$callback$$=>{$report$$.filter($r$$=>$r$$.ma_bp).joinModel2($id_app$$,dmbp,[{where:"ma_bp",fields:"ten_bp"}],function(){$callback$$()})}},()=>{$report$$=$report$$.sort(($a$$,$b$$)=>{let $a_ngay_ct$$=moment($a$$.ngay_ct).format("YYYY-MM-DD"),$b_ngay_ct$$=
moment($b$$.ngay_ct).format("YYYY-MM-DD");return $a_ngay_ct$$<$b_ngay_ct$$?-1:$a_ngay_ct$$>$b_ngay_ct$$?1:$a$$.id_ct<$b$$.id_ct?-1:$a$$.id_ct>$b$$.id_ct?1:$a$$.ma_sp<$b$$.ma_sp?-1:$a$$.ma_sp>$b$$.ma_sp?1:$a$$.ma_tt1_sp<$b$$.ma_tt1_sp?-1:$a$$.ma_tt1_sp>$b$$.ma_tt1_sp?1:$a$$.sysorder<$b$$.sysorder?-1:$a$$.sysorder>$b$$.sysorder?1:0});$callback$jscomp$0$$(null,$report$$)})})})};