flexbiz-server
Version:
Flexible Server
7 lines (6 loc) • 2.68 kB
JavaScript
'use strict';const tinhgiatb=require("../../libs/tinhgiatb"),controller=require("../../controllers/controllerRPT"),_Notification=global.getModel("notification"),async=require("async"),utils=require("../../libs/utils");
module.exports=function($router$$){new controller($router$$,"tinhgiatb",async function($req$$,$callback$jscomp$0$$){const $query$$=$req$$.query;if(!$query$$.nam||!$query$$.tu_thang||!$query$$.den_thang)return $callback$jscomp$0$$("Ch\u1ee9c n\u0103ng n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: nam,tu_thang,den_thang");var $ds_kho_moment_query_kho$$=require("moment"),$ngay_ks_tu_ngay$$=$ds_kho_moment_query_kho$$([Number($query$$.nam),Number($query$$.tu_thang)-1,1]).startOf("month").toDate();
if($ngay_ks_tu_ngay$$=await utils.isBookLocked({id_app:$req$$.user.current_id_app,ngay_ct:$ngay_ks_tu_ngay$$}))return $callback$jscomp$0$$(`\u0110\u00e3 kh\u00f3a s\u1ed5 \u0111\u1ebfn ng\u00e0y ${$ds_kho_moment_query_kho$$($ngay_ks_tu_ngay$$).format("DD/MM/YYYY")}`);const $id_app$$=$query$$.id_app;$ds_kho_moment_query_kho$$=[];$query$$.tinh_theo_kho&&!$query$$.ma_kho?($ds_kho_moment_query_kho$$={id_app:$id_app$$,status:!0},$ds_kho_moment_query_kho$$=(await global.getModel("dmkho").find($ds_kho_moment_query_kho$$,
{ma_kho:1}).sort({stt:1}).lean()).map($r$$=>$r$$.ma_kho)):$ds_kho_moment_query_kho$$=[$query$$.ma_kho];async.mapSeries($ds_kho_moment_query_kho$$,($ma_kho$$,$callback$$)=>{const $zquery$$=Object.assign({},$query$$);$zquery$$.ma_kho=$ma_kho$$;tinhgiatb($zquery$$,function($error$$){$error$$&&console.error("l\u1ed7i t\u00ednh gia trung b\u00ecnh:",$error$$,$zquery$$);$callback$$($error$$)})},$error$$=>{const $email$$=$req$$.user.email;$error$$?(console.error("L\u1ed7i khi t\u00ednh gi\u00e1 trung b\u00ecnh",
$error$$),_Notification.createNotification($email$$,$email$$,$error$$.message||$error$$,$error$$.message||$error$$,null,{id_app:$id_app$$},!0,$req$$.access_token,!0),$callback$jscomp$0$$($error$$)):(console.info("\u0110\u00e3 t\u00ednh xong gi\u00e1 trung b\u00ecnh. Th\u00f4ng b\u00e1o t\u1edbi",$email$$),_Notification.createNotification($email$$,$email$$,"Ch\u01b0\u01a1ng tr\u00ecnh \u0111\u00e3 t\u00ednh gi\u00e1 trung b\u00ecnh xong","Ch\u01b0\u01a1ng tr\u00ecnh \u0111\u00e3 t\u00ednh gi\u00e1 trung b\u00ecnh 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."})};