flexbiz-server
Version:
Flexible Server
53 lines (50 loc) • 21.6 kB
JavaScript
const cktk=require("../../libs/cktk"),dktk=require("../../libs/dktk"),rptform=global.getModel("rptform"),async=require("async"),_=require("lodash"),utils=require("../../libs/utils"),controller=require("../../controllers/controllerRPT"),moment=require("moment"),numeral=require("numeral"),getRegString=function($arrayTk$$){if($arrayTk$$)return $arrayTk$$.reg()},{getCodeChildren,sumByCondition}=require("../../libs/utils");
module.exports=function($router$$){new controller($router$$,"pttct",async function($req$$,$callback$$){let $query$$=$req$$.query;if(!$query$$.den_ngay||!$query$$.tu_ngay||!$query$$.id_rptform&&!$query$$.form_code)return $callback$$("B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u tham s\u1ed1 t\u1eeb ng\u00e0y(tu_ngay), \u0111\u1ebfn ng\u00e0y(den_ngay), id m\u1eabu b\u00e1o c\u00e1o");if($query$$.id_rptform&&!global.mongoose.Types.ObjectId.isValid($query$$.id_rptform))return $callback$$("M\u1eabu b\u00e1o c\u00e1o n\u00e0y kh\u00f4ng c\u00f3 gi\u00e1 tr\u1ecb");
if($query$$.ma_bp){var $bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$=await getCodeChildren(global.getModel("dmbp"),$query$$.id_app,$query$$.ma_bp,"ma_bp","ma_bp_me");$query$$.ma_bp={$in:$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$}}$query$$.ma_phi&&($bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$=await getCodeChildren(global.getModel("dmphi"),$query$$.id_app,
$query$$.ma_phi,"ma_phi","ma_phi_me"),$query$$.ma_phi={$in:$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$});$query$$.ma_dt&&($bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$=await getCodeChildren(global.getModel("dmdt"),$query$$.id_app,$query$$.ma_dt,"ma_dt","ma_dt_me"),$query$$.ma_dt={$in:$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$});$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$=
{id_app:$query$$.id_app};$query$$.id_rptform?$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$._id=$query$$.id_rptform:$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$.form_code=$query$$.form_code;const $_rptform$$=await rptform.findOne($bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$).lean();if(!$_rptform$$)return $callback$$("M\u1eabu b\u00e1o c\u00e1o kh\u00f4ng t\u1ed3n t\u1ea1i");
$query$$.tu_ngay=moment(new Date($query$$.tu_ngay)).startOf("date").toDate();$query$$.den_ngay=moment(new Date($query$$.den_ngay)).endOf("date").toDate();let $report$$=$_rptform$$.report;$report$$&&$_rptform$$.report.length!==0||($report$$=await global.getModel("kbmPttct").find({id_rptform:$_rptform$$._id.toString(),id_app:$query$$.id_app}).sort({stt:1}).lean());let $kys$$=[];switch($query$$.loai_ky){case "ngay":for($bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$=
moment($query$$.tu_ngay).startOf("date").toDate();$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$.getTime()<$query$$.den_ngay.getTime();){var $den_ngay_den_ngay$jscomp$1_den_ngay$jscomp$2_den_ngay$jscomp$3_den_ngay$$=moment($bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$).endOf("date").toDate();$den_ngay_den_ngay$jscomp$1_den_ngay$jscomp$2_den_ngay$jscomp$3_den_ngay$$.getTime()>$query$$.den_ngay.getTime()&&
($den_ngay_den_ngay$jscomp$1_den_ngay$jscomp$2_den_ngay$jscomp$3_den_ngay$$=$query$$.den_ngay);$kys$$.push({field:`so_${$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$.getDate()}-${$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$.getMonth()+1}-${$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$.getFullYear()}`,header:`${$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$.getDate()}/${$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$.getMonth()+
1}/${$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$.getFullYear()}`,datatype:"Number",ma_ky:`${$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$.getDate()}-${$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$.getMonth()+1}-${$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$.getFullYear()}`,ten_ky:`${$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$.getDate()}/${$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$.getMonth()+
1}/${$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$.getFullYear()}`,tu_ngay:$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$,den_ngay:$den_ngay_den_ngay$jscomp$1_den_ngay$jscomp$2_den_ngay$jscomp$3_den_ngay$$});$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$=moment($den_ngay_den_ngay$jscomp$1_den_ngay$jscomp$2_den_ngay$jscomp$3_den_ngay$$).add(1,"days").startOf("date").toDate()}$kys$$.push({ma_ky:"tong_cong",
ten_ky:"T\u1ed5ng c\u1ed9ng",datatype:"Number",tu_ngay:moment($query$$.tu_ngay).startOf("date").toDate(),den_ngay:moment($query$$.den_ngay).endOf("date").toDate()});break;case "tuan":for($bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$=moment($query$$.tu_ngay).startOf("date").toDate();$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$.getTime()<$query$$.den_ngay.getTime();)$den_ngay_den_ngay$jscomp$1_den_ngay$jscomp$2_den_ngay$jscomp$3_den_ngay$$=
moment($bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$).endOf("week").toDate(),$den_ngay_den_ngay$jscomp$1_den_ngay$jscomp$2_den_ngay$jscomp$3_den_ngay$$.getTime()>$query$$.den_ngay.getTime()&&($den_ngay_den_ngay$jscomp$1_den_ngay$jscomp$2_den_ngay$jscomp$3_den_ngay$$=$query$$.den_ngay),$kys$$.push({field:`so_${moment($bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$).get("weeks")}-${$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$.getFullYear()}`,
header:`Tu\u1ea7n ${moment($bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$).get("weeks")}/${$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$.getFullYear()}`,ma_ky:`${moment($bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$).get("weeks")}-${$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$.getFullYear()}`,ten_ky:`Tu\u1ea7n ${moment($bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$).get("weeks")}/${$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$.getFullYear()}`,
tu_ngay:$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$,den_ngay:$den_ngay_den_ngay$jscomp$1_den_ngay$jscomp$2_den_ngay$jscomp$3_den_ngay$$}),$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$=moment($den_ngay_den_ngay$jscomp$1_den_ngay$jscomp$2_den_ngay$jscomp$3_den_ngay$$).add(1,"days").startOf("date").toDate();$kys$$.push({ma_ky:"tong_cong",ten_ky:"T\u1ed5ng c\u1ed9ng",datatype:"Number",tu_ngay:moment($query$$.tu_ngay).startOf("date").toDate(),
den_ngay:moment($query$$.den_ngay).endOf("date").toDate()});break;case "thang":for($bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$=moment($query$$.tu_ngay).startOf("date").toDate();$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$.getTime()<$query$$.den_ngay.getTime();)$den_ngay_den_ngay$jscomp$1_den_ngay$jscomp$2_den_ngay$jscomp$3_den_ngay$$=moment($bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$).endOf("month").toDate(),
$den_ngay_den_ngay$jscomp$1_den_ngay$jscomp$2_den_ngay$jscomp$3_den_ngay$$.getTime()>$query$$.den_ngay.getTime()&&($den_ngay_den_ngay$jscomp$1_den_ngay$jscomp$2_den_ngay$jscomp$3_den_ngay$$=$query$$.den_ngay),$kys$$.push({field:`so_${$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$.getMonth()+1}-${$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$.getFullYear()}`,header:`Th\u00e1ng ${$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$.getMonth()+
1}/${$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$.getFullYear()}`,datatype:"Number",ma_ky:`${$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$.getMonth()+1}-${$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$.getFullYear()}`,ten_ky:`Th\u00e1ng ${$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$.getMonth()+1}/${$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$.getFullYear()}`,
tu_ngay:$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$,den_ngay:$den_ngay_den_ngay$jscomp$1_den_ngay$jscomp$2_den_ngay$jscomp$3_den_ngay$$}),$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$=moment($den_ngay_den_ngay$jscomp$1_den_ngay$jscomp$2_den_ngay$jscomp$3_den_ngay$$).add(1,"days").startOf("date").toDate();$kys$$.push({ma_ky:"tong_cong",ten_ky:"T\u1ed5ng c\u1ed9ng",datatype:"Number",tu_ngay:moment($query$$.tu_ngay).startOf("date").toDate(),
den_ngay:moment($query$$.den_ngay).endOf("date").toDate()});break;case "quy":for($bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$=moment($query$$.tu_ngay).startOf("date").toDate();$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$.getTime()<$query$$.den_ngay.getTime();)$den_ngay_den_ngay$jscomp$1_den_ngay$jscomp$2_den_ngay$jscomp$3_den_ngay$$=moment($bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$).endOf("quarters").toDate(),
$den_ngay_den_ngay$jscomp$1_den_ngay$jscomp$2_den_ngay$jscomp$3_den_ngay$$.getTime()>$query$$.den_ngay.getTime()&&($den_ngay_den_ngay$jscomp$1_den_ngay$jscomp$2_den_ngay$jscomp$3_den_ngay$$=$query$$.den_ngay),$kys$$.push({field:`so_${moment($bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$).get("quarters")}-${$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$.getFullYear()}`,header:`${moment($bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$).get("quarters")}/${$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$.getFullYear()}`,
datatype:"Number",ma_ky:`${moment($bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$).get("quarters")}-${$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$.getFullYear()}`,ten_ky:`${moment($bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$).get("quarters")}/${$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$.getFullYear()}`,tu_ngay:$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$,
den_ngay:$den_ngay_den_ngay$jscomp$1_den_ngay$jscomp$2_den_ngay$jscomp$3_den_ngay$$}),$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$=moment($den_ngay_den_ngay$jscomp$1_den_ngay$jscomp$2_den_ngay$jscomp$3_den_ngay$$).add(1,"days").startOf("date").toDate();$kys$$.push({ma_ky:"tong_cong",ten_ky:"T\u1ed5ng c\u1ed9ng",datatype:"Number",tu_ngay:moment($query$$.tu_ngay).startOf("date").toDate(),den_ngay:moment($query$$.den_ngay).endOf("date").toDate()});break;
case "nam":for($bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$=moment($query$$.tu_ngay).startOf("date").toDate();$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$.getTime()<$query$$.den_ngay.getTime();)$den_ngay_den_ngay$jscomp$1_den_ngay$jscomp$2_den_ngay$jscomp$3_den_ngay$$=moment($bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$).endOf("year").toDate(),$den_ngay_den_ngay$jscomp$1_den_ngay$jscomp$2_den_ngay$jscomp$3_den_ngay$$.getTime()>
$query$$.den_ngay.getTime()&&($den_ngay_den_ngay$jscomp$1_den_ngay$jscomp$2_den_ngay$jscomp$3_den_ngay$$=$query$$.den_ngay),$kys$$.push({field:`so_${$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$.getFullYear()}`,header:`${$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$.getFullYear()}`,ma_ky:`${$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$.getFullYear()}`,ten_ky:`${$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$.getFullYear()}`,
tu_ngay:$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$,den_ngay:$den_ngay_den_ngay$jscomp$1_den_ngay$jscomp$2_den_ngay$jscomp$3_den_ngay$$}),$bps_dts_phis_query_form_tu_ngay_tu_ngay$jscomp$1_tu_ngay$jscomp$2_tu_ngay$jscomp$3_tu_ngay$$=moment($den_ngay_den_ngay$jscomp$1_den_ngay$jscomp$2_den_ngay$jscomp$3_den_ngay$$).add(1,"days").startOf("date").toDate();$kys$$.push({ma_ky:"tong_cong",ten_ky:"T\u1ed5ng c\u1ed9ng",datatype:"Number",tu_ngay:moment($query$$.tu_ngay).startOf("date").toDate(),
den_ngay:moment($query$$.den_ngay).endOf("date").toDate()});break;case "kn":$kys$$=[{field:"so_kn",header:"Gi\u00e1 tr\u1ecb",datatype:"Number",ma_ky:"kn",ten_ky:"Gi\u00e1 tr\u1ecb",tu_ngay:$query$$.tu_ngay,den_ngay:$query$$.den_ngay}];break;default:$query$$.tu_ngay_kt=new Date($query$$.tu_ngay),$query$$.tu_ngay_kt.setYear($query$$.tu_ngay_kt.getFullYear()-1),$query$$.den_ngay_kt=new Date($query$$.den_ngay),$query$$.den_ngay_kt.setYear($query$$.den_ngay_kt.getFullYear()-1),$kys$$=[{field:"so_kt",
header:"K\u1ef3 tr\u01b0\u1edbc",datatype:"Number",ma_ky:"kt",ten_ky:"K\u1ef3 tr\u01b0\u1edbc",tu_ngay:$query$$.tu_ngay_kt,den_ngay:$query$$.den_ngay_kt},{field:"so_kn",header:"K\u1ef3 n\u00e0y",datatype:"Number",ma_ky:"kn",ten_ky:"K\u1ef3 n\u00e0y",tu_ngay:$query$$.tu_ngay,den_ngay:$query$$.den_ngay}]}async.map($report$$,($r$$,$c1$$)=>{setImmediate(()=>{switch($r$$.cach_tinh){case "9":$r$$.cong_thuc="";utils.getInfoFromQuery($query$$,$r$$.query,($e$$,$rs$$)=>{if($e$$)return $c1$$();_.isNumber($rs$$)?
($r$$.so_kn=$rs$$,$r$$.so_kn_nt=$rs$$,$r$$.so_kt=$rs$$,$r$$.so_kt_nt=$rs$$):$r$$.value_string=$rs$$;$c1$$()});break;case "2":$r$$.cong_thuc="";async.map($kys$$,($ky$$,$callback$$)=>{setImmediate(async()=>{let $condition$$={ngay_ct:{$gte:$ky$$.tu_ngay,$lte:$ky$$.den_ngay},id_app:$query$$.id_app};$query$$.ma_dvcs&&($condition$$.ma_dvcs=$query$$.ma_dvcs);$query$$.ma_bp&&($condition$$.ma_bp=$query$$.ma_bp);$query$$.ma_hd&&($condition$$.ma_hd=$query$$.ma_hd);$query$$.ma_dt&&($condition$$.ma_dt=$query$$.ma_dt);
$query$$.ma_sp&&($condition$$.ma_sp=$query$$.ma_sp);$query$$.ma_nv&&($condition$$.ma_nv=$query$$.ma_nv);$r$$.ma_phi&&($condition$$.ma_phi={$in:await getCodeChildren(global.getModel("dmphi"),$query$$.id_app,$r$$.ma_phi,"ma_phi","ma_phi_me")});var $tk_co_tk_no$$=getRegString($r$$.tk_no);$tk_co_tk_no$$&&($condition$$.tk_no=$r$$.giam_tru_no?{$not:new RegExp($tk_co_tk_no$$)}:{$regex:$tk_co_tk_no$$,$options:"i"});if($tk_co_tk_no$$=getRegString($r$$.tk_co))$condition$$.tk_co=$r$$.giam_tru_co&&$tk_co_tk_no$$?
{$not:new RegExp($tk_co_tk_no$$)}:{$regex:$tk_co_tk_no$$,$options:"i"};if($r$$.dieu_kien_khac)try{$r$$.dieu_kien_khac.indexOf("{")<0&&($r$$.dieu_kien_khac="{"+$r$$.dieu_kien_khac+"}");var $socai_str_func$$=$r$$.dieu_kien_khac;$socai_str_func$$.indexOf("return ")<0&&($socai_str_func$$=`return ${$socai_str_func$$}`);let $dieu_kien_khac$$=utils.evalute($socai_str_func$$,{moment,condition:$condition$$,row:$r$$});$condition$$={...$condition$$,...$dieu_kien_khac$$}}catch($e$$){return $callback$$($e$$.toString())}$r$$.ma_kho?
($condition$$.ma_kho=$r$$.ma_kho,$socai_str_func$$=global.getModel("socaitc")):$socai_str_func$$=global.getModel("socaitt");sumByCondition($socai_str_func$$,["tien","tien_nt"],$condition$$).then($dt$$=>{$r$$[`so_${$ky$$.ma_ky}`]=$dt$$.tien;$r$$[`so_${$ky$$.ma_ky}_nt`]=$dt$$.tien_nt}).catch($e$$=>{$callback$$($e$$)})})},($e$$,$rs$$)=>{$c1$$($e$$,$rs$$)});break;case "5":$r$$.cong_thuc="";async.map($kys$$,($ky$$,$callback$$)=>{let $condition$$={...$query$$};$condition$$.ngay=$ky$$.tu_ngay;$condition$$.bu_tru=
$r$$.bu_tru_cong_no;$condition$$.tk=$r$$.tk;delete $condition$$.tu_ngay;delete $condition$$.den_ngay;dktk($condition$$,function($error$$,$result$$){if($error$$)return $callback$$($error$$);$r$$[`so_${$ky$$.ma_ky}`]=$result$$.csum("du_no00");$r$$[`so_${$ky$$.ma_ky}_nt`]=$result$$.csum("du_no_nt00");$r$$[`so_${$ky$$.ma_ky}`]<0&&$r$$.khong_am&&($r$$[`so_${$ky$$.ma_ky}`]=0);$r$$[`so_${$ky$$.ma_ky}_nt`]<0&&$r$$.khong_am&&($r$$[`so_${$ky$$.ma_ky}_nt`]=0);$callback$$(null,$r$$)})},($e$$,$rs$$)=>{$c1$$($e$$,
$rs$$)});break;case "6":$r$$.cong_thuc="";async.map($kys$$,($ky$$,$callback$$)=>{let $condition$$={...$query$$};$condition$$.ngay=$ky$$.tu_ngay;$condition$$.bu_tru=$r$$.bu_tru_cong_no;$condition$$.tk=$r$$.tk;delete $condition$$.tu_ngay;delete $condition$$.den_ngay;dktk($condition$$,function($error$$,$result$$){if($error$$)return $callback$$($error$$);$r$$[`so_${$ky$$.ma_ky}`]=$result$$.csum("du_co00");$r$$[`so_${$ky$$.ma_ky}_nt`]=$result$$.csum("du_co_nt00");$r$$[`so_${$ky$$.ma_ky}`]<0&&$r$$.khong_am&&
($r$$[`so_${$ky$$.ma_ky}`]=0);$r$$[`so_${$ky$$.ma_ky}_nt`]<0&&$r$$.khong_am&&($r$$[`so_${$ky$$.ma_ky}_nt`]=0);$callback$$(null,$r$$)})},($e$$,$rs$$)=>{$c1$$($e$$,$rs$$)});break;case "7":$r$$.cong_thuc="";async.map($kys$$,($ky$$,$callback$$)=>{let $condition$$={...$query$$};$condition$$.ngay=$ky$$.den_ngay;$condition$$.bu_tru=$r$$.bu_tru_cong_no;$condition$$.tk=$r$$.tk;delete $condition$$.tu_ngay;delete $condition$$.den_ngay;cktk($condition$$,function($error$$,$result$$){if($error$$)return $callback$$($error$$);
$r$$[`so_${$ky$$.ma_ky}`]=$result$$.csum("du_no00");$r$$[`so_${$ky$$.ma_ky}_nt`]=$result$$.csum("du_no_nt00");$r$$[`so_${$ky$$.ma_ky}`]<0&&$r$$.khong_am&&($r$$[`so_${$ky$$.ma_ky}`]=0);$r$$[`so_${$ky$$.ma_ky}_nt`]<0&&$r$$.khong_am&&($r$$[`so_${$ky$$.ma_ky}_nt`]=0);$callback$$(null,$r$$)})},($e$$,$rs$$)=>{$c1$$($e$$,$rs$$)});break;case "8":$r$$.cong_thuc="";async.map($kys$$,($ky$$,$callback$$)=>{let $condition$$={...$query$$};$condition$$.ngay=$ky$$.den_ngay;$condition$$.bu_tru=$r$$.bu_tru_cong_no;
$condition$$.tk=$r$$.tk;delete $condition$$.tu_ngay;delete $condition$$.den_ngay;cktk($condition$$,function($error$$,$result$$){if($error$$)return $callback$$($error$$);$r$$[`so_${$ky$$.ma_ky}`]=$result$$.csum("du_co00");$r$$[`so_${$ky$$.ma_ky}_nt`]=$result$$.csum("du_co_nt00");$r$$[`so_${$ky$$.ma_ky}`]<0&&$r$$.khong_am&&($r$$[`so_${$ky$$.ma_ky}`]=0);$r$$[`so_${$ky$$.ma_ky}_nt`]<0&&$r$$.khong_am&&($r$$[`so_${$ky$$.ma_ky}_nt`]=0);$callback$$(null,$r$$)})},($e$$,$rs$$)=>{$c1$$($e$$,$rs$$)});break;case "99":if(!$r$$.script)return $c1$$(null,
$r$$);if($r$$.script.indexOf("async ")>=0)return $c1$$("async function is not allow");let $func_string$$=`return (async ()=>{
try{
${$r$$.script}
}catch(e){
return {error:e}
}
})`;$r$$.cong_thuc="";utils.evalute($func_string$$,{row:$r$$,moment,condition:$query$$,user:$req$$.user,_,utils})().then($rs$$=>{if($rs$$&&$rs$$.error)return Logger.error($rs$$.error,$func_string$$),$c1$$($rs$$.error.message||$rs$$.error.error||$rs$$.error);$c1$$(null,$r$$)}).catch($e$$=>{Logger.error($e$$,$func_string$$);return $c1$$($e$$.message||$e$$.error||$e$$)});break;default:$c1$$(null,$r$$)}})},function($error$$){if($error$$)return $callback$$($error$$);$error$$=$kys$$.map($k$$=>`so_${$k$$.ma_ky},so_${$k$$.ma_ky}_nt`).join(",");
utils.calcGrid($report$$,$error$$,async function($data$$){if($_rptform$$.handle_data_expression_server){if($_rptform$$.handle_data_expression_server.indexOf("async ")>=0)return $callback$$("async function is not allow");let $func_string$$=`return (async ()=>{
try{
${$_rptform$$.handle_data_expression_server}
}catch(e){
return {error:e}
}
})`;try{let $rs$$=await utils.evalute($func_string$$,{data:$data$$,moment,numeral,condition:$req$$.query})();if($rs$$){if($rs$$.error)return Logger.error($rs$$.error,$func_string$$),$callback$$($rs$$.error.message||$rs$$.error);$data$$=$rs$$}}catch($e$$){return Logger.error($e$$,$func_string$$),$callback$$($e$$.message||$e$$)}}$req$$.query.loai_ky?$callback$$(null,{data:$data$$.filter($r$$=>$r$$.print),columns:$kys$$}):$callback$$(null,$data$$.filter($r$$=>$r$$.print))})})})};