flexbiz-server
Version:
Flexible Server
7 lines (6 loc) • 2.82 kB
JavaScript
'use strict';const _Notification=global.getModel("notification"),controller=require("../../controllers/controllerRPT"),tinhGt=require("../../libs/tinhGt"),async=require("async"),utils=require("../../libs/utils");
module.exports=function($router$$){new controller($router$$,"tinhgiathanh",async function($req$$,$callback$jscomp$0$$){const $condition$$=$req$$.query;if(!$condition$$.nam||!$condition$$.thang)return $callback$jscomp$0$$("Ch\u1ee9c n\u0103ng n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: nam,thang");$condition$$.nam=Number($condition$$.nam);$condition$$.thang=Number($condition$$.thang);var $dsbp_moment_q$$=require("moment"),$bpcon_ngay_ks_tu_ngay$$=$dsbp_moment_q$$([Number($condition$$.nam),Number($condition$$.thang)-
1,1]).startOf("month").toDate();if($bpcon_ngay_ks_tu_ngay$$=await utils.isBookLocked({id_app:$req$$.user.current_id_app,ngay_ct:$bpcon_ngay_ks_tu_ngay$$}))return $callback$jscomp$0$$(`\u0110\u00e3 kh\u00f3a s\u1ed5 \u0111\u1ebfn ng\u00e0y ${$dsbp_moment_q$$($bpcon_ngay_ks_tu_ngay$$).format("DD/MM/YYYY")}`);$dsbp_moment_q$$=[];$condition$$.tinh_theo_cong_doan?($dsbp_moment_q$$={id_app:$condition$$.id_app,la_cong_doan_sx:!0,status:!0},$condition$$.ma_bp&&($bpcon_ngay_ks_tu_ngay$$=await global.getModel("dmbp").getChilrenByMaBP($condition$$.id_app,
$condition$$.ma_bp),$bpcon_ngay_ks_tu_ngay$$.push($condition$$.ma_bp),$dsbp_moment_q$$.ma_bp={$in:$bpcon_ngay_ks_tu_ngay$$}),$dsbp_moment_q$$=(await global.getModel("dmbp").find($dsbp_moment_q$$).sort({stt:1}).lean()).map($r$$=>$r$$.ma_bp)):$dsbp_moment_q$$=[$condition$$.ma_bp];async.mapSeries($dsbp_moment_q$$,($bp$$,$callback$$)=>{setImmediate(()=>{tinhGt({...$condition$$,ma_bp:$bp$$},($e$$,$ctgt$$)=>{if($e$$)return $callback$$($e$$);$callback$$(null,$ctgt$$)})})},async $e$$=>{const $email$$=$req$$.user.email,
$id_app$$=$condition$$.id_app;$e$$?(console.error("L\u1ed7i t\u00ednh gi\u00e1 th\u00e0nh:",$e$$),_Notification.createNotification($email$$,$email$$,$e$$.message||$e$$.error||$e$$,$e$$.message||$e$$.error||$e$$,null,{id_app:$id_app$$},!0,$req$$.access_token,!0),$callback$jscomp$0$$($e$$)):(console.log("\u0110\u00e3 t\u00ednh xong gi\u00e1 gi\u00e1 th\u00e0nh, th\u00f4ng b\u00e1o t\u1edbi",$email$$),_Notification.createNotification($email$$,$email$$,"Ch\u01b0\u01a1ng tr\u00ecnh \u0111\u00e3 t\u00ednh gi\u00e1 th\u00e0nh xong",
"Ch\u01b0\u01a1ng tr\u00ecnh \u0111\u00e3 t\u00ednh gi\u00e1 th\u00e0nh xong",null,{id_app:$id_app$$},!0,$req$$.access_token,!0),$callback$jscomp$0$$(null))})},{stream:!1,cache:!1,queue:!0,timeout:18E6,waiting_message:"Ch\u01b0\u01a1ng tr\u00ecnh \u0111ang th\u1ef1c hi\u1ec7n. B\u1ea1n c\u00f3 th\u1ec3 chuy\u1ec3n sang trang kh\u00e1c \u0111\u1ec3 l\u00e0m vi\u1ec7c. Khi ch\u01b0\u01a1ng tr\u00ecnh th\u1ef1c hi\u1ec7n xong s\u1ebd g\u1eedi th\u00f4ng b\u00e1o cho b\u1ea1n."})};