flexbiz-server
Version:
Flexible Server
8 lines (7 loc) • 3.19 kB
JavaScript
'use strict';const dmtk=global.getModel("account"),dmbp=global.getModel("dmbp"),qts=global.getModel("qts"),sotinhkh=global.getModel("sotinhkh"),phanbokh=require("../../libs/phanbokh"),async=require("async"),controller=require("../../controllers/controllerRPT");
module.exports=function($router$$){new controller($router$$,"getkhauhao",function($req$$,$callback$jscomp$0$$){const $condition$$=$req$$.query;if(!$condition$$.nam||!$condition$$.id_app)return $callback$jscomp$0$$("Ch\u1ee9c n\u0103ng n\u00e0y y\u00eau c\u1ea7u tham s\u1ed1: nam,id_app");$condition$$.thang||($condition$$.thang=0);if(11<$condition$$.thang)return $callback$jscomp$0$$("Tham s\u1ed1 th\u00e1ng kh\u00f4ng h\u1ee3p l\u1ec7");sotinhkh.find({id_app:$condition$$.id_app,thang:Number($condition$$.thang)+
1,nam:$condition$$.nam}).lean().exec(async function($error$jscomp$0$$,$khauhaos$$){if($error$jscomp$0$$)return $callback$jscomp$0$$($error$jscomp$0$$);await $khauhaos$$.filter($r$$=>$r$$.ma_tang_giam_ts).asyncJoinModel2($condition$$.id_app,"dmtanggiamts",{where:"ma_tang_giam_ts",fields:{kieu_dc:"kieu"}});$khauhaos$$.forEach($r$$=>{"2"==$r$$.kieu_dc&&($r$$.nguyen_gia=0-$r$$.nguyen_gia,$r$$.gia_tri_da_kh=0-$r$$.gia_tri_da_kh,$r$$.gia_tri_con_lai=0-$r$$.gia_tri_con_lai,$r$$.gia_tri_kh_ky=0-$r$$.gia_tri_kh_ky)});
$khauhaos$$=await $khauhaos$$.asyncGroupBy("id_app nam thang ngay_dau_thang ngay_cuoi_thang so_ngay_kh sua_kh id_ts tk_cp tk_kh ma_kho ma_bp ma_phi ma_dt".split(" "),["gia_tri_kh_ky"]);$khauhaos$$.joinModel2($condition$$.id_app,qts,[{where:{id_ts:"_id"},fields:[{tk_kh_goc:"tk_kh"},{tk_cp_goc:"tk_cp"},{ma_bp_goc:"ma_bp"},{ma_kho_goc:"ma_kho"},{ma_phi_goc:"ma_phi"},{ma_dt_goc:"ma_dt"},"ten_ts","so_the_ts"]}],function(){async.mapSeries($khauhaos$$,function($khauhao$$,$callback$$){phanbokh($khauhao$$,
function($error$$,$kqpb$$){if($error$$)return console.log($error$$),$callback$$($error$$);$callback$$(null,$kqpb$$)})},function($error$$,$kqpbs$$){$kqpbs$$=$kqpbs$$.reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]);if($error$$)return $callback$jscomp$0$$($error$$);let $report$$=$kqpbs$$.filter($r$$=>!!$r$$).map(($r$$,$i$$)=>{$r$$.line=$i$$;$r$$.tk_no=$r$$.tk_cp||$r$$.tk_cp_goc;$r$$.tk_co=$r$$.tk_kh||$r$$.tk_kh_goc;$r$$.ma_kho=$r$$.ma_kho||$r$$.ma_kho_goc;$r$$.ma_bp=$r$$.ma_bp||$r$$.ma_bp_goc;$r$$.ma_phi=
$r$$.ma_phi||$r$$.ma_phi_goc;$r$$.ma_dt=$r$$.ma_dt||$r$$.ma_dt_goc;$r$$.tien_nt=$r$$.gia_tri_kh_ky;$r$$.tien=$r$$.tien_nt;return $r$$});async.series({tk:function($callback$$){$report$$.joinModel2($condition$$.id_app,dmtk,[{where:{tk_no:"tk"},fields:[{name:"ten_tk_no",value:"ten_tk"}]},{akey:"tk_co",bkey:"tk",fields:[{name:"ten_tk_co",value:"ten_tk"}]}],function($r$$){$callback$$(null,$r$$)})},bp:function($callback$$){$report$$.joinModel2($condition$$.id_app,dmbp,[{where:"ma_bp",fields:[{name:"ten_bp",
value:"ten_bp"}]}],function($r$$){$callback$$(null,$r$$)})},ts:function($callback$$){$report$$.joinModel2($condition$$.id_app,qts,[{where:{id_ts:"_id"},fields:[{name:"ten_ts",value:"ten_ts"},{name:"so_the_ts",value:"so_the_ts"}]}],function($r$$){$callback$$(null,$r$$)})}},function(){$report$$.forEach($r$$=>{delete $r$$._id});$callback$jscomp$0$$(null,$report$$)})})})})},{cache:!1})};