UNPKG

flexbiz-server

Version:

Flexible Server

10 lines (9 loc) 4.04 kB
'use strict';const task=global.getModel("task"),dmbp=global.getModel("dmbp"),async=require("async"),underscore=require("underscore"),dmloaitask=global.getModel("dmloaitask"),controller=require("../../controllers/controllerRPT"),moment=require("moment"); module.exports=function($router$$){new controller($router$$,"congviectheobp",async($req$$,$callback$jscomp$0$$)=>{const $condition$$=$req$$.query;if(!$condition$$.tu_ngay||!$condition$$.den_ngay)return $callback$jscomp$0$$("B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1:tu_ngay,den_ngay");const $query$$={id_app:$condition$$.id_app};$condition$$.tu_ngay=moment(new Date($condition$$.tu_ngay)).startOf("date").toDate();$condition$$.den_ngay=moment(new Date($condition$$.den_ngay)).endOf("date").toDate(); $query$$.start_date={$gte:$condition$$.tu_ngay,$lte:$condition$$.den_ngay};if($condition$$.id_bp)try{let $_ch$$=await dmbp.getChilren($condition$$.id_app,$condition$$.id_bp);$_ch$$.push($condition$$.id_bp);$query$$.id_bp={$in:$_ch$$}}catch($e$$){console.log($e$$)}else $query$$.id_bp={$ne:""};$condition$$.phu_trach&&($query$$.phu_trach=$condition$$.phu_trach);$condition$$.id_dt&&($query$$.id_dt=$condition$$.id_dt);$condition$$.id_kh&&($query$$.id_kh=$condition$$.id_kh);$condition$$.nh_cv&&($query$$.nh_cv= $condition$$.nh_cv);const $now$$=new Date;task.find($query$$).lean().exec(async function($error$jscomp$2$$,$rs$$){if($error$jscomp$2$$)return console.log($error$jscomp$2$$,$query$$),$callback$jscomp$0$$($error$jscomp$2$$);await $rs$$.filter($item$$=>$item$$.ma_loai_cv).asyncJoinModel2($req$$.user.current_id_app,dmloaitask,{where:"ma_loai_cv",fields:["ten_loai_cv","he_so"]});async.mapSeries($rs$$,function($r$$,$callback$$){$r$$.t_so_luong=1;$r$$.chua_thuc_hien=0===$r$$.progress?1:0;$r$$.dang_thuc_hien= 1===$r$$.progress?1:0;$r$$.kiem_tra=2===$r$$.progress?1:0;$r$$.hoan_thanh=3===$r$$.progress?1:0;$r$$.tam_dung=4===$r$$.progress?1:0;$r$$.cho=5===$r$$.progress?1:0;$r$$.cham_tien_do=0;$r$$.diem=0;$r$$.complete_hour=task.calcCompleteHours($r$$);$r$$.he_so=void 0===$r$$.he_so?1:$r$$.he_so;$r$$.ngay=moment($r$$.start_date).date();$r$$.thang=(new Date($r$$.start_date)).getMonth()+1;$r$$.quy=moment($r$$.start_date).quarter();$r$$.nam=(new Date($r$$.start_date)).getFullYear();$r$$.due_date&&($r$$.finished_date? $r$$.finished_date.getTime()>$r$$.due_date.getTime()&&($r$$.cham_tien_do=1):$now$$.getTime()>$r$$.due_date.getTime()&&($r$$.cham_tien_do=1));$r$$.diem=($r$$.diem_du_tinh||0)*$r$$.he_so*($r$$.percent||0)/100;$callback$$(null,$r$$)},function($error$jscomp$0$$,$rs$jscomp$0$$){if($error$jscomp$0$$)return $callback$jscomp$0$$($error$jscomp$0$$);$error$jscomp$0$$=["id_bp"];$condition$$.groupby&&($error$jscomp$0$$=[...(new Set([...$error$jscomp$0$$,...$condition$$.groupby.split(",")]))]);$rs$jscomp$0$$.groupBy($error$jscomp$0$$, [{name:"t_so_luong",value:"t_so_luong"},{name:"chua_thuc_hien",value:"chua_thuc_hien"},{name:"dang_thuc_hien",value:"dang_thuc_hien"},{name:"kiem_tra",value:"kiem_tra"},{name:"hoan_thanh",value:"hoan_thanh"},{name:"tam_dung",value:"tam_dung"},{name:"cho",value:"cho"},{name:"cham_tien_do",value:"cham_tien_do"},{name:"diem",value:"diem"},{name:"complete_hour",value:"complete_hour"}],function($error$$,$rs$$){if($error$$)return $callback$jscomp$0$$($error$$);const $report$$=underscore.sortBy($rs$$,function($r$$){return $r$$.id_bp}); $report$$.forEach(function($r$$,$i$$){$r$$.stt=$i$$+1;$r$$.bold=!1});$report$$.joinModel2($condition$$.id_app,dmbp,{where:{id_bp:"_id"},fields:["ma_bp","ten_bp"]},function(){$report$$.push({ten_bp:"T\u1ed5ng c\u1ed9ng",t_so_luong:$report$$.csum("t_so_luong"),chua_thuc_hien:$report$$.csum("chua_thuc_hien"),dang_thuc_hien:$report$$.csum("dang_thuc_hien"),kiem_tra:$report$$.csum("kiem_tra"),hoan_thanh:$report$$.csum("hoan_thanh"),tam_dung:$report$$.csum("tam_dung"),cho:$report$$.csum("cho"),cham_tien_do:$report$$.csum("cham_tien_do"), diem:$report$$.csum("diem"),complete_hour:$report$$.csum("complete_hour"),bold:!0});$callback$jscomp$0$$(null,$report$$)})})})})})};