UNPKG

flexbiz-server

Version:

Flexible Server

6 lines (5 loc) 1.78 kB
const sokho=global.getModel("sokho"),dmvt=global.getModel("dmvt"),underscore=require("underscore"),controller=require("../../controllers/controllerRPT"); module.exports=function($router$$){new controller($router$$,"tonghoptralaihang",function($query_req$$,$callback$$){const $condition$$=$query_req$$.query;if(!$condition$$.tu_ngay||!$condition$$.den_ngay)return $callback$$("B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1:tu_ngay,den_ngay");$query_req$$={id_app:$condition$$.id_app,ma_ct:{$in:["PN5"]}};$query_req$$.ngay_ct={$gte:$condition$$.tu_ngay,$lte:$condition$$.den_ngay};$condition$$.ma_dvcs&&($query_req$$.ma_dvcs={$regex:$condition$$.ma_dvcs, $options:"i"});$condition$$.ma_vt&&($query_req$$.ma_vt={$regex:$condition$$.ma_vt,$options:"i"});$condition$$.ma_kho&&($query_req$$.ma_kho={$regex:$condition$$.ma_kho,$options:"i"});sokho.find($query_req$$).lean().exec(function($error$$,$rs$$){if($error$$)return Logger.info($error$$),$callback$$($error$$);$rs$$.groupBy("ma_vt",[{name:"sl_xuat",value:"sl_xuat"},{name:"tien_hang",value:"tien_hang"},{name:"tien_ck",value:"tien_ck"},{name:"tien_xuat",value:"tien_xuat"}],function($error$$,$rs$$){if($error$$)return Logger.info($error$$), $callback$$($error$$);const $report$$=underscore.sortBy($rs$$,function($r$$){return $r$$.ma_vt});let $i$$=1;$report$$.forEach(function($r$$){$r$$.stt=$i$$;$r$$.bold=!1;$i$$++});$report$$.joinModel($condition$$.id_app,dmvt,[{akey:"ma_vt",bkey:"ma_vt",fields:[{name:"ten_vt",value:"ten_vt"},{name:"ma_dvt",value:"ma_dvt"}]}],function(){$report$$.push({ten_vt:"T\u1ed5ng c\u1ed9ng",sl_xuat:$report$$.csum("sl_xuat"),tien_hang:$report$$.csum("tien_hang"),tien_ck:$report$$.csum("tien_ck"),tien_xuat:$report$$.csum("tien_xuat"), bold:!0});$callback$$(null,$report$$)})})})})};