UNPKG

flexbiz-server

Version:

Flexible Server

7 lines (6 loc) 2.46 kB
'use strict';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",function($query_req$$,$callback$jscomp$0$$){$query_req$$=$query_req$$.query;let $id_app$$=$query_req$$.id_app,$condition$$={id_app:$id_app$$};$query_req$$.id_ct&&($condition$$.id_ct=$query_req$$.id_ct);$query_req$$.tu_ngay&&($condition$$.ngay_ct={$gte:$query_req$$.tu_ngay});$query_req$$.den_ngay&&($condition$$.ngay_ct?$condition$$.ngay_ct.$lte=$query_req$$.den_ngay:$condition$$.ngay_ct={$lte:$query_req$$.tu_ngay});$query_req$$.ma_vt&& ($condition$$.ma_vt=$query_req$$.ma_vt);$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(($error$$,$report$$)=>{if($error$$)return $callback$jscomp$0$$($error$$);async.series({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$$.joinModel2($id_app$$,customer,[{where:"ma_kh", fields:"ten_kh"}],function(){$callback$$()})},nv:$callback$$=>{$report$$.joinModel2($id_app$$,dmnv,[{where:"ma_nv",fields:"ten_nv"}],function(){$callback$$()})},bp:$callback$$=>{$report$$.joinModel2($id_app$$,dmbp,[{where:"ma_bp",fields:"ten_bp"}],function(){$callback$$()})},phi:$callback$$=>{$report$$.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$jscomp$0$$(null,$report$$)})})})};