flexbiz-server
Version:
Flexible Server
10 lines (9 loc) • 4.2 kB
JavaScript
const task=global.getModel("task"),Participant=global.getModel("participant"),dmloaitask=global.getModel("dmloaitask"),async=require("async"),underscore=require("underscore"),controller=require("../../controllers/controllerRPT"),moment=require("moment");
module.exports=function($router$$){new controller($router$$,"congviectheonv",function($req$$,$callback$$){const $condition$$=$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");$condition$$.tu_ngay=moment(new Date($condition$$.tu_ngay)).startOf("date").toDate();$condition$$.den_ngay=moment(new Date($condition$$.den_ngay)).endOf("date").toDate();const $query$$={id_app:$condition$$.id_app};
$query$$.start_date={$gte:$condition$$.tu_ngay,$lte:$condition$$.den_ngay};$condition$$.id_bp&&($query$$.id_bp=$condition$$.id_bp);$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$$,$rs$$){if($error$$)return $callback$$($error$$);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.mapLimit($rs$$,20,function($r$$,$callback$$){$r$$.t_so_luong=1;$r$$.chua_thuc_hien=$r$$.progress===0?1:0;$r$$.dang_thuc_hien=$r$$.progress===1?1:0;$r$$.kiem_tra=$r$$.progress===2?1:0;$r$$.hoan_thanh=$r$$.progress===3?1:0;$r$$.tam_dung=$r$$.progress===4?1:0;$r$$.cho=$r$$.progress===5?1:0;$r$$.cham_tien_do=0;$r$$.diem=0;$r$$.complete_hour=task.calcCompleteHours($r$$);$r$$.he_so=$r$$.he_so===void 0?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$$,$_rs$$){if($error$$)return $callback$$($error$$);$_rs$$.filter($r$$=>$r$$.attends&&
$r$$.attends.length>0&&$r$$.chia_diem&&$r$$.he_so_chia_diem.length>0).forEach($r$$=>{const $tong_diem$$=$r$$.diem,$tong_he_so$$=$r$$.he_so_chia_diem.map($u$$=>$u$$.he_so).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$tong_he_so$$&&($r$$.diem=0,$r$$.he_so_chia_diem.forEach($u$$=>{const $diem$$=$u$$.he_so/$tong_he_so$$*$tong_diem$$;$u$$.user===$r$$.phu_trach?$r$$.diem=$diem$$:$rs$$.push({...$r$$,phu_trach:$u$$.user,diem:$diem$$})}))});$condition$$.phu_trach&&($rs$$=$rs$$.filter($r$$=>$r$$.phu_trach===$condition$$.phu_trach));
$error$$=["phu_trach"];$condition$$.groupby&&($error$$=[...(new Set([...$error$$,...$condition$$.groupby.split(",")]))]);$rs$$.groupBy($error$$,[{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$$($error$$);const $report$$=underscore.sortBy($rs$$,function($r$$){return $r$$.phu_trach});let $i$$=1;$report$$.forEach(function($r$$){$r$$.stt=$i$$;$r$$.bold=!1;$i$$++});$report$$.joinModel2($condition$$.id_app,Participant,{where:{phu_trach:"email"},fields:[{name:"name",value:"name"}]},function(){$report$$.push({name:"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$$(null,$report$$)})})})})})};