flexbiz-server
Version:
Flexible Server
8 lines (7 loc) • 3.44 kB
JavaScript
const sokho=global.getModel("sokho"),dmvt=global.getModel("dmvt"),dmkho=global.getModel("dmkho"),customer=global.getModel("customer"),dmnv=global.getModel("dmnv"),dmbp=global.getModel("dmbp"),dmphi=global.getModel("dmphi"),underscore=require("underscore"),controller=require("../../controllers/controllerRPT"),moment=require("moment"),async=require("async");
module.exports=function($router$$){new controller($router$$,"sokho",async function($condition_req$$,$callback$$){let $query$$=$condition_req$$.query,$id_app$$=$query$$.id_app;$condition_req$$={id_app:$id_app$$};$query$$.id_ct&&($condition_req$$.id_ct=$query$$.id_ct);$query$$.tu_ngay&&($condition_req$$.ngay_ct={$gte:$query$$.tu_ngay});$query$$.den_ngay&&($condition_req$$.ngay_ct?$condition_req$$.ngay_ct.$lte=$query$$.den_ngay:$condition_req$$.ngay_ct={$lte:$query$$.tu_ngay});$query$$.ma_ct&&($condition_req$$.ma_ct=
$query$$.ma_ct.toUpperCase());$query$$.ma_kho&&($condition_req$$.ma_kho=$query$$.ma_kho);$query$$.ma_kh&&($condition_req$$.ma_kh=$query$$.ma_kh);$query$$.ma_nv&&($condition_req$$.ma_nv=$query$$.ma_nv);$query$$.tk_vt&&($condition_req$$.tk_vt={$regex:"^"+$query$$.tk_vt,$options:"i"});$query$$.tk_gv&&($condition_req$$.tk_gv={$regex:"^"+$query$$.tk_gv,$options:"i"});$query$$.tk_dt&&($condition_req$$.tk_dt={$regex:"^"+$query$$.tk_dt,$options:"i"});$query$$.nxt&&($condition_req$$.nxt=Number($query$$.nxt));
let $vts$$=await new Promise(($resolve$$,$reject$$)=>{if(!$query$$.ma_vt&&($query$$.ma_ncc||$query$$.ma_kh||$query$$.ma_nvt||$query$$.ma_nvt2||$query$$.ma_nvt3||$query$$.ma_nvt4||$query$$.ma_lvt)){const $_query$$={id_app:$id_app$$,tg_tk:!0};$query$$.ma_ncc&&($_query$$.ma_ncc=$query$$.ma_ncc);$query$$.ma_nvt&&$query$$.ma_nvt.length>0&&($_query$$.ma_nvt=$query$$.ma_nvt);$query$$.ma_nvt2&&$query$$.ma_nvt2.length>0&&($_query$$.ma_nvt2=$query$$.ma_nvt2);$query$$.ma_nvt3&&$query$$.ma_nvt3.length>0&&($_query$$.ma_nvt3=
$query$$.ma_nvt3);$query$$.ma_nvt4&&$query$$.ma_nvt4.length>0&&($_query$$.ma_nvt4=$query$$.ma_nvt4);$query$$.ma_lvt&&($_query$$.ma_lvt=$query$$.ma_lvt);dmvt.find($_query$$,{ma_vt:1}).lean().exec(($err$$,$rs$$)=>{if($err$$)return $reject$$($err$$);$resolve$$($rs$$.map($r$$=>$r$$.ma_vt))})}else $resolve$$($query$$.ma_vt)});$vts$$&&(Array.isArray($vts$$)?$condition_req$$.ma_vt={$in:$vts$$}:$condition_req$$.ma_vt=$vts$$);sokho.find($condition_req$$).sort({ngay_ct:1,so_ct:1}).lean().exec(($error$$,$report$$)=>
{if($error$$)return $callback$$($error$$);async.parallel({vt:$callback$$=>{$report$$.joinModel2($id_app$$,dmvt,[{where:"ma_vt",fields:"ten_vt"}],function(){$callback$$()})},kho:$callback$$=>{$report$$.joinModel2($id_app$$,dmkho,[{where:"ma_kho",fields:"ten_kho"}],function(){$callback$$()})},kh:$callback$$=>{$report$$.filter($r$$=>$r$$.ma_kh).joinModel2($id_app$$,customer,[{where:"ma_kh",fields:"ten_kh"}],function(){$callback$$()})},nv:$callback$$=>{$report$$.filter($r$$=>$r$$.ma_nv).joinModel2($id_app$$,
dmnv,[{where:"ma_nv",fields:"ten_nv"}],function(){$callback$$()})},bp:$callback$$=>{$report$$.filter($r$$=>$r$$.ma_bp).joinModel2($id_app$$,dmbp,[{where:"ma_bp",fields:"ten_bp"}],function(){$callback$$()})},phi:$callback$$=>{$report$$.filter($r$$=>$r$$.ma_phi).joinModel2($id_app$$,dmphi,[{where:"ma_phi",fields:"ten_phi"}],function(){$callback$$()})}},()=>{$report$$=underscore.sortBy($report$$,function($r$$){return $r$$.ngay_ct?moment($r$$.ngay_ct).format("YYYYMMDD"):"0"});$callback$$(null,$report$$)})})})};