UNPKG

flexbiz-server

Version:

Flexible Server

6 lines (5 loc) 1.99 kB
const dmbp=global.getModel("dmbp"),dmnv=global.getModel("dmnv"),customer=global.getModel("customer"),bangtinhluong=global.getModel("bangtinhluong"),controller=require("../../controllers/controllerRPT"); module.exports=function($router$$){new controller($router$$,"getluongchuyen",function($req$$,$callback$$){const $condition$$=$req$$.query;if(!$condition$$.thang||!$condition$$.nam||!$condition$$.id_app)return $callback$$("Ch\u1ee9c n\u0103ng n\u00e0y y\u00eau c\u1ea7u tham s\u1ed1: thang,nam,id_app");bangtinhluong.find({id_app:$condition$$.id_app,thang:Number($condition$$.thang),nam:Number($condition$$.nam)}).lean().then(function($luongs$$){$luongs$$.joinModel2($condition$$.id_app,dmbp,[{where:{ma_bp:"ma_bp"}, fields:["tk_cp_luong","tk_pt_nv","tk_thue_tncn","ma_phi","ten_bp"]}],async function(){const $cpluong$$=$luongs$$.filter($luong$$=>$luong$$.luong_thang).map($_luong_luong$$=>{$_luong_luong$$={...$_luong_luong$$};$_luong_luong$$.tk_no=$_luong_luong$$.tk_pt_nv;$_luong_luong$$.tien_nt=$_luong_luong$$.tien=Math.roundBy($_luong_luong$$.tong_luong);return $_luong_luong$$});let $report$$=[...$cpluong$$];$report$$=await $report$$.asyncGroupBy("tk_no ma_nv ma_bp ten_bp ma_phi ma_kho dien_giai".split(" "),["tien", "tien_nt"]);await $report$$.asyncJoinModel2($condition$$.id_app,dmnv,{where:"ma_nv",fields:["ten_nv","so_tk_ngan_hang","ten_chu_tk_ngan_hang","phat_hanh_boi_ngan_hang"]});$report$$=$report$$.map(($r$$,$i$$)=>{$r$$.line=$i$$;$r$$.ma_kh=$r$$.ma_kh||$r$$.ma_nv;$condition$$.ty_le&&$condition$$.dot&&($r$$.tien_nt=$r$$.tien=Math.roundBy($r$$.tien_nt*$condition$$.ty_le/100),$r$$.dot=$condition$$.dot,$r$$.ty_le=$condition$$.ty_le);$r$$.bang_luong=$cpluong$$.filter($c$$=>$c$$.ma_nv==$r$$.ma_nv&&$c$$.ma_bp== $r$$.ma_bp);return $r$$});await $report$$.asyncJoinModel2($condition$$.id_app,customer,{where:"ma_kh",fields:["ten_kh"]});$report$$.forEach($r$$=>{$r$$.ten_kh||delete $r$$.ma_kh});$callback$$(null,$report$$)})}).catch($error$$=>{$callback$$($error$$)})})};