flexbiz-server
Version:
Flexible Server
66 lines (65 loc) • 33.1 kB
JavaScript
const chamcong=global.getModel("chamcong"),dmnv=global.getModel("dmnv"),dmbp=global.getModel("dmbp"),phucap=global.getModel("phucap"),dmloaicong=global.getModel("dmloaicong"),ckgtluong=global.getModel("ckgtluong"),bangtinhluong=global.getModel("bangtinhluong"),dmletet=global.getModel("dmletet"),App=global.getModel("app"),controller=require("../../controllers/controllerRPT"),moment=require("moment"),async=require("async"),_=require("lodash"),utils=require("../../libs/utils"),generateVirtualTimekeepingForVIP=
($nv$$,$condition$$)=>({ma_nv:$nv$$.ma_nv,ma_bp:$nv$$.ma_bp,loai_don_gia_ngay_cong:"luong_ngay_cong",ngay_cong:$condition$$.so_ngay_lam_mot_thang,sl_cong:1,ngay_phep:0,ngay_khong_phep:0,ngay_khong_luong:0,ngay_tang_ca:0,so_ngay_tinh_phu_cap:0,so_luong_ngay_tang_ca_mien_thue:0,is_virtual_vip:!0}),bac_tinh_thue=[{thu_nhap_chiu_thue_toi_da:5E6,thue_suat:5},{thu_nhap_chiu_thue_toi_da:1E7,thue_suat:10},{thu_nhap_chiu_thue_toi_da:18E6,thue_suat:15},{thu_nhap_chiu_thue_toi_da:32E6,thue_suat:20},{thu_nhap_chiu_thue_toi_da:52E6,
thue_suat:25},{thu_nhap_chiu_thue_toi_da:8E7,thue_suat:30},{thue_suat:35}],tinhThueTNCV=$tong_thu_nhap_chiu_thue$$=>{let $i$$=0;const $thue_tncn$$=_.cloneDeep(bac_tinh_thue);let $thu_nha_da_chiu_thue$$=0;for(var $thu_nhap_chiu_thue_thu_nhap_con_lai$$=$tong_thu_nhap_chiu_thue$$;$i$$<$thue_tncn$$.length;){let $bac$$=$thue_tncn$$[$i$$];$thu_nhap_chiu_thue_thu_nhap_con_lai$$=$bac$$.thu_nhap_chiu_thue_toi_da?Math.min($bac$$.thu_nhap_chiu_thue_toi_da-$thu_nha_da_chiu_thue$$,$thu_nhap_chiu_thue_thu_nhap_con_lai$$):
$thu_nhap_chiu_thue_thu_nhap_con_lai$$;if($thu_nhap_chiu_thue_thu_nhap_con_lai$$<=0)break;$bac$$.thu_nhap_chiu_thue=$thu_nhap_chiu_thue_thu_nhap_con_lai$$;$bac$$.tien_thue=Math.roundBy($thu_nhap_chiu_thue_thu_nhap_con_lai$$*$bac$$.thue_suat/100);$thu_nha_da_chiu_thue$$+=$thu_nhap_chiu_thue_thu_nhap_con_lai$$;$thu_nhap_chiu_thue_thu_nhap_con_lai$$=$tong_thu_nhap_chiu_thue$$-$thu_nha_da_chiu_thue$$;$i$$+=1}return $thue_tncn$$},mergeTimekeepingFragments=($fragments$$,$condition$$)=>{const {loai_luong:$loai_luong$$,
so_ngay_lam_mot_thang:$so_ngay_lam_mot_thang$$}=$condition$$;let $nvs_merged_map$$={};$fragments$$.forEach($frag$$=>{$frag$$.ngay_bat_dau_lam&&($frag$$.ngay_bat_dau_lam=moment($frag$$.ngay_bat_dau_lam).startOf("date").toDate());$frag$$.ngay_nghi_viec&&($frag$$.ngay_nghi_viec=moment($frag$$.ngay_nghi_viec).endOf("date").toDate());if($frag$$.tinh_luong&&(!$frag$$.ngay_bat_dau_lam||$frag$$.ngay_bat_dau_lam.getTime()<=$condition$$.den_ngay.getTime())&&(!$frag$$.ngay_nghi_viec||$frag$$.ngay_nghi_viec.getTime()>
$condition$$.tu_ngay.getTime())){var $luong_co_ban_target$$=$frag$$.luong_co_ban||0;if($frag$$.is_virtual_holiday){var $don_gia_ngay$$=$frag$$[$frag$$.loai_don_gia_ngay_cong]||Math.roundBy($luong_co_ban_target$$/$so_ngay_lam_mot_thang$$);var $ten_don_gia$$=`Ngh\u1ec9 L\u1ec5/T\u1ebft: ${$frag$$.ten_le||"C\u00f3 h\u01b0\u1edfng l\u01b0\u01a1ng"}`}else $loai_luong$$==1?($luong_co_ban_target$$=$frag$$.luong_thu_viec||0,$don_gia_ngay$$=$frag$$[$frag$$.loai_don_gia_ngay_cong]||Math.roundBy($luong_co_ban_target$$/
$so_ngay_lam_mot_thang$$),$ten_don_gia$$=`L\u01b0\u01a1ng th\u1eed vi\u1ec7c (${$frag$$.loai_don_gia_ngay_cong})`):($don_gia_ngay$$=$frag$$[$frag$$.loai_don_gia_ngay_cong]||Math.roundBy($luong_co_ban_target$$/$so_ngay_lam_mot_thang$$),$ten_don_gia$$=`L\u01b0\u01a1ng ch\u00ednh th\u1ee9c (${$frag$$.loai_don_gia_ngay_cong})`);var $tien_cong$$=Math.roundBy($don_gia_ngay$$*$frag$$.ngay_cong),$tien_phep$$=Math.roundBy($don_gia_ngay$$*$frag$$.ngay_phep),$tien_tang_ca$$=Math.roundBy($don_gia_ngay$$*$frag$$.ngay_tang_ca);
$nvs_merged_map$$[$frag$$.ma_nv]||($nvs_merged_map$$[$frag$$.ma_nv]=_.cloneDeep($frag$$),Object.assign($nvs_merged_map$$[$frag$$.ma_nv],{ngay_phep:0,ngay_khong_phep:0,ngay_tang_ca:0,tong_ngay_khong_luong:0,tong_ngay_cong_tinh_luong:0,so_ngay_tinh_phu_cap:0,so_luong_ngay_tang_ca_mien_thue:0,ct_luong_tg:[],luong_theo_ngay_cong:0,tong_tien_luong_tg:0,tru_luong:0,luong_phep:0,luong_tang_ca:0,don_gia_binh_quan_chuan:Math.roundBy($luong_co_ban_target$$/$so_ngay_lam_mot_thang$$)}));$luong_co_ban_target$$=
$nvs_merged_map$$[$frag$$.ma_nv];$luong_co_ban_target$$.ngay_phep+=$frag$$.ngay_phep;$luong_co_ban_target$$.ngay_khong_phep+=$frag$$.ngay_khong_phep||0;$luong_co_ban_target$$.ngay_tang_ca+=$frag$$.ngay_tang_ca;$luong_co_ban_target$$.tong_ngay_cong_tinh_luong+=$frag$$.ngay_cong+$frag$$.ngay_phep;$luong_co_ban_target$$.so_luong_ngay_tang_ca_mien_thue+=$frag$$.so_luong_ngay_tang_ca_mien_thue;$luong_co_ban_target$$.so_ngay_tinh_phu_cap+=$frag$$.so_ngay_tinh_phu_cap;$frag$$.ngay_cong>0&&$luong_co_ban_target$$.ct_luong_tg.push({loai:"NC",
dien_giai:`${$ten_don_gia$$}`,so_luong:$frag$$.ngay_cong,don_gia:$don_gia_ngay$$,thanh_tien:$tien_cong$$});$frag$$.ngay_phep>0&&$luong_co_ban_target$$.ct_luong_tg.push({loai:"NP",dien_giai:`L\u01b0\u01a1ng ngh\u1ec9 ph\u00e9p theo m\u1ee9c ${$ten_don_gia$$}`,so_luong:$frag$$.ngay_phep,don_gia:$don_gia_ngay$$,thanh_tien:$tien_phep$$});$frag$$.ngay_tang_ca>0&&$luong_co_ban_target$$.ct_luong_tg.push({loai:"TC",dien_giai:`L\u01b0\u01a1ng t\u0103ng ca (quy \u0111\u1ed5i) theo m\u1ee9c ${$ten_don_gia$$}`,
so_luong:$frag$$.ngay_tang_ca,don_gia:$don_gia_ngay$$,thanh_tien:$tien_tang_ca$$});$luong_co_ban_target$$[`${$frag$$.loai_don_gia_ngay_cong}`]=$tien_cong$$+$tien_tang_ca$$+$tien_phep$$;$luong_co_ban_target$$.luong_theo_ngay_cong+=$tien_cong$$;$luong_co_ban_target$$.luong_tang_ca+=$tien_tang_ca$$;$luong_co_ban_target$$.luong_phep+=$tien_phep$$;$luong_co_ban_target$$.tong_ngay_khong_luong=$so_ngay_lam_mot_thang$$-$luong_co_ban_target$$.tong_ngay_cong_tinh_luong;$luong_co_ban_target$$.tong_tien_luong_tg+=
$luong_co_ban_target$$[`${$frag$$.loai_don_gia_ngay_cong}`]}});return Object.values($nvs_merged_map$$)},calculateTimeBasedSalary=async($nv$$,$condition$$)=>{let {tu_ngay:$tu_ngay$$,den_ngay:$den_ngay$$,loai_luong:$loai_luong$$,so_ngay_lam_mot_thang:$so_ngay_lam_mot_thang$$}=$condition$$;$nv$$.tinh_luong_theo_ngay||($nv$$.tinh_luong_theo_ngay=moment($tu_ngay$$).startOf("month").toDate().getTime()<moment($tu_ngay$$).startOf("date").toDate().getTime()||$nv$$.ngay_bat_dau_lam&&$nv$$.ngay_bat_dau_lam.getTime()>
$tu_ngay$$.getTime()||$nv$$.ngay_nghi_viec&&$nv$$.ngay_nghi_viec.getTime()<$den_ngay$$.getTime());$nv$$.so_ngay_lam_mot_thang=$so_ngay_lam_mot_thang$$;$condition$$=$nv$$.luong_bhxh;$loai_luong$$==1?($nv$$.thu_viec=!0,$nv$$.luong_co_ban=$nv$$.luong_thu_viec,$condition$$=0):($nv$$.thu_viec=!1,$nv$$.thu_viec_den_ngay&&(new Date($nv$$.thu_viec_den_ngay)).getTime()>=moment($den_ngay$$).startOf("month").toDate().getTime()&&($condition$$=0));if($nv$$.cham_cong)if($nv$$.tinh_luong_theo_ngay)$nv$$.tru_luong=
0,$nv$$.luong_binh_quan_ngay=$nv$$.tong_ngay_cong_tinh_luong?Math.roundBy($nv$$.luong_theo_ngay_cong/$nv$$.tong_ngay_cong_tinh_luong):0,$nv$$.luong_thang=$nv$$.tong_tien_luong_tg;else{$nv$$.ct_luong_tg=$nv$$.ct_luong_tg.filter($c$$=>$c$$.loai!="TC");$nv$$.ct_luong_tg.push({loai:"LCB",dien_giai:"L\u01b0\u01a1ng c\u01a1 b\u1ea3n th\u00e1ng",so_luong:1,don_gia:$nv$$.luong_co_ban,thanh_tien:$nv$$.luong_co_ban});let $tien_tang_ca$$=$nv$$.luong_tang_ca,$tien_tru$$=Math.roundBy($nv$$.don_gia_binh_quan_chuan*
$nv$$.tong_ngay_khong_luong);$tien_tru$$>0&&$nv$$.ct_luong_tg.push({loai:"TRU",dien_giai:"Tr\u1eeb l\u01b0\u01a1ng ngh\u1ec9",so_luong:$nv$$.tong_ngay_khong_luong,don_gia:-$nv$$.don_gia_binh_quan_chuan,thanh_tien:-$tien_tru$$});$nv$$.luong_binh_quan_ngay=$nv$$.don_gia_binh_quan_chuan;$nv$$.tru_luong=$tien_tru$$;$nv$$.luong_thang=$nv$$.luong_co_ban+$tien_tang_ca$$-$tien_tru$$}else $nv$$.luong_thang=$nv$$.luong_co_ban,$nv$$.ct_luong_tg=[{loai:"LCB",dien_giai:"L\u01b0\u01a1ng c\u1ee9ng (kh\u00f4ng ch\u1ea5m c\u00f4ng)",
so_luong:1,don_gia:$nv$$.luong_co_ban,thanh_tien:$nv$$.luong_co_ban}];$nv$$.luong_bhxh_calculator=$condition$$;return $nv$$},calculateSalesBasedSalary=async($nv$$,$condition$$,$data_tinh_luong_ds_storage$$)=>{let {id_app:$id_app$$,tu_ngay:$tu_ngay$$,den_ngay:$den_ngay$$}=$condition$$,$id_used$$=[];var $csluongtheods_query_luong_sl$$={id_app:$id_app$$,status:!0,$or:[{ds_nv:$nv$$.ma_nv},{ds_bp:$nv$$.ma_bp}]};$csluongtheods_query_luong_sl$$=await global.getModel("csluongtheods").find($csluongtheods_query_luong_sl$$).lean();
$csluongtheods_query_luong_sl$$.sort(($a$$,$b$$)=>{$a$$=Array.isArray($a$$.ds_ma_kh)&&$a$$.ds_ma_kh.length>0;$b$$=Array.isArray($b$$.ds_ma_kh)&&$b$$.ds_ma_kh.length>0;return Number($b$$)-Number($a$$)});for(let $csluong$$ of $csluongtheods_query_luong_sl$$){var $data_sokho_ds_ct_query_san_luong$$=$csluong$$.ds_ma_ct.filter($c$$=>$c$$).map($c$$=>$c$$.toUpperCase());$data_sokho_ds_ct_query_san_luong$$={id_app:$id_app$$,ngay_ct:{$gte:$tu_ngay$$,$lte:$den_ngay$$},$or:[{[$csluong$$.doi_tuong_nhan_vien]:$nv$$.ma_nv},
{phu_xe:$nv$$.ma_nv}],ma_ct:{$in:$data_sokho_ds_ct_query_san_luong$$},_id:{$nin:$id_used$$}};if($csluong$$.ds_ma_vt?.length>0)$data_sokho_ds_ct_query_san_luong$$.ma_vt={$in:$csluong$$.ds_ma_vt};else if($csluong$$.ma_nvt||$csluong$$.ma_nvt2||$csluong$$.ma_nvt3){var $ds_ma_kh_ds_ma_vt_luong_theo_ds_q_q$$={id_app:$id_app$$};$csluong$$.ma_nvt&&($ds_ma_kh_ds_ma_vt_luong_theo_ds_q_q$$.ma_nvt=$csluong$$.ma_nvt);$csluong$$.ma_nvt2&&($ds_ma_kh_ds_ma_vt_luong_theo_ds_q_q$$.ma_nvt2=$csluong$$.ma_nvt2);$csluong$$.ma_nvt3&&
($ds_ma_kh_ds_ma_vt_luong_theo_ds_q_q$$.ma_nvt3=$csluong$$.ma_nvt3);$ds_ma_kh_ds_ma_vt_luong_theo_ds_q_q$$=(await global.getModel("dmvt").find($ds_ma_kh_ds_ma_vt_luong_theo_ds_q_q$$,{ma_vt:1}).lean()).map($v$$=>$v$$.ma_vt);$data_sokho_ds_ct_query_san_luong$$.ma_vt={$in:$ds_ma_kh_ds_ma_vt_luong_theo_ds_q_q$$}}$csluong$$.ds_ma_kh?.length>0?$data_sokho_ds_ct_query_san_luong$$.ma_kh=$csluong$$.loai_tru_kh?{$nin:$csluong$$.ds_ma_kh}:{$in:$csluong$$.ds_ma_kh}:$csluong$$.nh_kh&&($ds_ma_kh_ds_ma_vt_luong_theo_ds_q_q$$=
{id_app:$id_app$$},$csluong$$.nh_kh&&($ds_ma_kh_ds_ma_vt_luong_theo_ds_q_q$$.nh_kh=$csluong$$.nh_kh),$csluong$$.nh_kh2&&($ds_ma_kh_ds_ma_vt_luong_theo_ds_q_q$$.nh_kh2=$csluong$$.nh_kh2),$csluong$$.nh_kh3&&($ds_ma_kh_ds_ma_vt_luong_theo_ds_q_q$$.nh_kh3=$csluong$$.nh_kh3),$ds_ma_kh_ds_ma_vt_luong_theo_ds_q_q$$=(await global.getModel("customer").find($ds_ma_kh_ds_ma_vt_luong_theo_ds_q_q$$,{ma_kh:1}).lean()).map($v$$=>$v$$.ma_kh),$data_sokho_ds_ct_query_san_luong$$.ma_kh={$in:$ds_ma_kh_ds_ma_vt_luong_theo_ds_q_q$$});
$csluong$$.ds_loai_phuong_tien?.length>0&&($data_sokho_ds_ct_query_san_luong$$.loai_phuong_tien={$in:$csluong$$.ds_loai_phuong_tien});$data_sokho_ds_ct_query_san_luong$$=await global.getModel("sokho").find($data_sokho_ds_ct_query_san_luong$$).lean();$id_used$$=[...$id_used$$,...$data_sokho_ds_ct_query_san_luong$$.map($d$$=>$d$$._id.toString())];$ds_ma_kh_ds_ma_vt_luong_theo_ds_q_q$$=0;if($csluong$$.tinh_theo_tong_ds){let $tong_doanh_so_quydoi$$=$data_sokho_ds_ct_query_san_luong$$.map($s$$=>{var $cong_thuc_sl_goc$$=
$s$$[$csluong$$.field_sl]||0;let $ty_le_phu$$=$csluong$$.ty_le_nv_phu_giup||0;let $dien_giai$$;if($s$$.phu_xe&&$s$$.phu_xe.trim()!==""&&$s$$.phu_xe!==$s$$[$csluong$$.doi_tuong_nhan_vien]){var $ds_thuc_phan_phu_xe$$=Math.round($cong_thuc_sl_goc$$*$ty_le_phu$$/100);$s$$.phu_xe==$nv$$.ma_nv?($dien_giai$$="Ph\u1ee5 xe",$cong_thuc_sl_goc$$=`${$cong_thuc_sl_goc$$} * ${$ty_le_phu$$}%`):($ds_thuc_phan_phu_xe$$=$cong_thuc_sl_goc$$-$ds_thuc_phan_phu_xe$$,$dien_giai$$="L\u00e1i ch\u00ednh",$cong_thuc_sl_goc$$=
`${$cong_thuc_sl_goc$$} - (${$cong_thuc_sl_goc$$} * ${$ty_le_phu$$}%)`)}else $ds_thuc_phan_phu_xe$$=$cong_thuc_sl_goc$$,$dien_giai$$="L\u00e1i ch\u00ednh (h\u01b0\u1edfng 100%)",$cong_thuc_sl_goc$$=`${$cong_thuc_sl_goc$$}`;$s$$.ma_nv=$nv$$.ma_nv;$s$$.dien_giai_luong=$dien_giai$$;$s$$.cong_thuc_doanh_so=$cong_thuc_sl_goc$$;return $s$$.doanh_so_quydoi=$ds_thuc_phan_phu_xe$$}).reduce(($a$$,$b$$)=>$a$$+$b$$,0),$dinh_muc$$=$csluong$$.ds_yeu_cau||1,$don_gia$$=$csluong$$.don_gia_luong||0;$ds_ma_kh_ds_ma_vt_luong_theo_ds_q_q$$=
Math.trunc($tong_doanh_so_quydoi$$/$dinh_muc$$)*$don_gia$$;$data_tinh_luong_ds_storage$$&&($data_tinh_luong_ds_storage$$.push({id_app:$condition$$.id_app,thang:$condition$$.thang,nam:$condition$$.nam,ma_nv:$nv$$.ma_nv,ngay_ct:$condition$$.den_ngay,so_ct:"TONG_HOP",dien_giai_luong:`T\u1ed5ng h\u1ee3p l\u01b0\u01a1ng theo DS (Ch\u00ednh s\u00e1ch: ${$csluong$$.ten_cs||"..."})`,cong_thuc:`(${$tong_doanh_so_quydoi$$} / ${$dinh_muc$$}) * ${$don_gia$$}`,doanh_so:$tong_doanh_so_quydoi$$,luong_theo_ds:$ds_ma_kh_ds_ma_vt_luong_theo_ds_q_q$$}),
$data_tinh_luong_ds_storage$$.push(...$data_sokho_ds_ct_query_san_luong$$.map($s$$=>({...$s$$,id_app:$condition$$.id_app,thang:$condition$$.thang,nam:$condition$$.nam,luong_theo_ds:0,ghi_chu:"Chi ti\u1ebft th\u00e0nh ph\u1ea7n c\u1ee7a l\u01b0\u01a1ng t\u1ed5ng h\u1ee3p"}))))}else $ds_ma_kh_ds_ma_vt_luong_theo_ds_q_q$$=$data_sokho_ds_ct_query_san_luong$$.map($s$$=>{let $sl_goc$$=$s$$[$csluong$$.field_sl]||0,$ty_le_phu$$=$s$$.phu_xe?$csluong$$.ty_le_nv_phu_giup||0:0,$dinh_muc$$=$csluong$$.ds_yeu_cau||
1,$don_gia$$=$csluong$$.don_gia_luong||0,$luong_goc$$=Math.trunc($sl_goc$$/$dinh_muc$$)*$don_gia$$;let $dien_giai$$,$cong_thuc$$;if($s$$.phu_xe&&$s$$.phu_xe.trim()!==""&&$s$$.phu_xe!==$s$$[$csluong$$.doi_tuong_nhan_vien]){var $luong_thuc_nhan_tien_phu_xe$$=Math.round($luong_goc$$*$ty_le_phu$$/100);$s$$.phu_xe==$nv$$.ma_nv?($dien_giai$$=`Ph\u1ee5 xe (${$ty_le_phu$$}%)`,$cong_thuc$$=`(${$sl_goc$$}/${$dinh_muc$$}*${$don_gia$$}) * ${$ty_le_phu$$}%`):($luong_thuc_nhan_tien_phu_xe$$=$luong_goc$$-$luong_thuc_nhan_tien_phu_xe$$,
$dien_giai$$=`L\u00e1i ch\u00ednh (tr\u1eeb ${$ty_le_phu$$}%)`,$cong_thuc$$=`(${$sl_goc$$}/${$dinh_muc$$}*${$don_gia$$}) - Ph\u1ee5 xe`)}else $luong_thuc_nhan_tien_phu_xe$$=$luong_goc$$,$dien_giai$$="L\u00e1i ch\u00ednh (100%)",$cong_thuc$$=`${$sl_goc$$}/${$dinh_muc$$} * ${$don_gia$$}`;$s$$.ma_nv=$nv$$.ma_nv;$s$$.id_app=$condition$$.id_app;$s$$.thang=$condition$$.thang;$s$$.nam=$condition$$.nam;$s$$.luong_theo_ds=$luong_thuc_nhan_tien_phu_xe$$;$s$$.luong_goc=$luong_goc$$;$s$$.dien_giai_luong=$dien_giai$$;
$s$$.cong_thuc=$cong_thuc$$;$s$$.doanh_so=$sl_goc$$;$s$$.ds_yeu_cau=$dinh_muc$$;$s$$.don_gia_luong=$don_gia$$;$s$$.ty_le_nv_phu_giup=$ty_le_phu$$;delete $s$$._id;delete $s$$.__v;$data_tinh_luong_ds_storage$$&&$data_tinh_luong_ds_storage$$.push($s$$);return $luong_thuc_nhan_tien_phu_xe$$}).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$csluong$$.luong=$ds_ma_kh_ds_ma_vt_luong_theo_ds_q_q$$}$nv$$.ct_luong_theo_ds=$csluongtheods_query_luong_sl$$.filter($c$$=>$c$$.luong);$nv$$.luong_theo_ds=$nv$$.ct_luong_theo_ds.map($d$$=>
$d$$.luong).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$nv$$.luong_thang=Number($nv$$.luong_thang||0)+Number($nv$$.luong_theo_ds)},calculateInsurance=($nv$$,$condition$jscomp$4_tu_ngay$$,$cac_khoan_giam_tru$$)=>{if($nv$$.thu_viec||$nv$$.luong_ctv)$nv$$.gt_bhxh=0,$nv$$.cty_bhxh=0,$nv$$.gt_bhyt=0,$nv$$.cty_bhyt=0,$nv$$.gt_bhtn=0,$nv$$.cty_bhtn=0,$nv$$.gt_kpcd=0,$nv$$.cty_kpcd=0,$nv$$.giam_tru=[],$nv$$.tong_bao_hiem_nv=0,$nv$$.tong_bao_hiem_cty=0;else{({tu_ngay:$condition$jscomp$4_tu_ngay$$}=$condition$jscomp$4_tu_ngay$$);
var $luong_bhxh$$=$nv$$.luong_bhxh_calculator;$nv$$.gt_bhxh=0;$nv$$.cty_bhxh=0;$nv$$.gt_bhyt=0;$nv$$.cty_bhyt=0;$nv$$.gt_bhtn=0;$nv$$.cty_bhtn=0;$nv$$.gt_kpcd=0;$nv$$.cty_kpcd=0;var $giam_tru$$=[];if(!$nv$$.ngay_tinh_bhxh||moment($nv$$.ngay_tinh_bhxh).startOf("date").toDate().getTime()<=$condition$jscomp$4_tu_ngay$$.getTime())$giam_tru$$=_.cloneDeep($cac_khoan_giam_tru$$).filter($gt$$=>(!$gt$$.ma_nv||$gt$$.ma_nv==0||$gt$$.ma_nv.indexOf($nv$$.ma_nv)>=0)&&(!$gt$$.ma_bp||$gt$$.ma_bp.length==0||$gt$$.ma_bp.indexOf($nv$$.ma_bp)>=
0)),$giam_tru$$.forEach($gt$$=>{let $userVal$$=0,$companyVal$$=0;const $calc$$=$typeInfo$$=>{$typeInfo$$&&($userVal$$=Math.roundBy($gt$$.ty_le_nv*$luong_bhxh$$/100),$companyVal$$=Math.roundBy($gt$$.ty_le_cty*$luong_bhxh$$/100))};$gt$$.kieu_trich=="BHXH"?($calc$$($nv$$.bhxh),$nv$$.gt_bhxh+=$userVal$$,$nv$$.cty_bhxh+=$companyVal$$):$gt$$.kieu_trich=="BHYT"?($calc$$($nv$$.bhyt),$nv$$.gt_bhyt+=$userVal$$,$nv$$.cty_bhyt+=$companyVal$$):$gt$$.kieu_trich=="BHTN"?($calc$$($nv$$.bhtn),$nv$$.gt_bhtn+=$userVal$$,
$nv$$.cty_bhtn+=$companyVal$$):$gt$$.kieu_trich=="KPCD"?($userVal$$=Math.roundBy($gt$$.ty_le_nv*$luong_bhxh$$/100),$companyVal$$=Math.roundBy($gt$$.ty_le_cty*$luong_bhxh$$/100),$nv$$.gt_kpcd+=$userVal$$,$nv$$.cty_kpcd+=$companyVal$$):($gt$$.nv=$gt$$.ty_le_nv?Math.roundBy($gt$$.ty_le_nv*$luong_bhxh$$/100):$gt$$.nv||0,$gt$$.cty=$gt$$.ty_le_cty?Math.roundBy($gt$$.ty_le_cty*$luong_bhxh$$/100):$gt$$.cty||0);["BHXH","BHYT","BHTN","KPCD"].includes($gt$$.kieu_trich)&&($gt$$.nv=$userVal$$,$gt$$.cty=$companyVal$$)});
$nv$$.giam_tru=$giam_tru$$;$nv$$.tong_bao_hiem_nv=$giam_tru$$.map($g$$=>$g$$.nv).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$nv$$.tong_bao_hiem_cty=$giam_tru$$.map($g$$=>$g$$.cty).reduce(($a$$,$b$$)=>$a$$+$b$$,0)}},calculateAllowances=async($nv$$,$condition$$,$csphucap_processed_phu_cap$$)=>{let {id_app:$id_app$$,thang:$thang$$,nam:$nam$$,tu_ngay:$tu_ngay$$,den_ngay:$den_ngay$$,tyGiaMap:$tyGiaMap$$,so_ngay_lam_mot_thang:$so_ngay_lam_mot_thang$$}=$condition$$;const $getTyGia$$=$ma_ma_nt$$=>{if(!$ma_ma_nt$$)return 1;
$ma_ma_nt$$=$ma_ma_nt$$.toUpperCase();return $tyGiaMap$$[$ma_ma_nt$$]||1};let $phu_cap_mot_lan$$=[];if(!$condition$$.cac_khoan_phu_cap?.length){$phu_cap_mot_lan$$=await phucap.find({id_app:$id_app$$,thang:$thang$$,nam:$nam$$,ma_nv:{$in:["",null,void 0,$nv$$.ma_nv]},ma_bp:{$in:["",null,void 0,$nv$$.ma_bp]}}).lean();$phu_cap_mot_lan$$.forEach($p$$=>{$p$$.dvt="month";let $ty_gia$$=$getTyGia$$($p$$.ma_nt);$p$$.tien_pc=Math.roundBy(($p$$.tien||0)*$ty_gia$$);$p$$.max_mien_thue&&($p$$.max_mien_thue=Math.roundBy($p$$.max_mien_thue*
$ty_gia$$))});var $phu_cap_mot_lan_them_query_san_luong$$={id_app:$id_app$$,ma_nv:$nv$$.ma_nv,nxt:2,ma_ct:{$in:["HD2","PBL","SO1"]},ngay_ct:{$gte:$tu_ngay$$,$lte:$den_ngay$$}};$phu_cap_mot_lan_them_query_san_luong$$=await global.getModel("sokho").find($phu_cap_mot_lan_them_query_san_luong$$).lean();$phu_cap_mot_lan_them_query_san_luong$$=await $phu_cap_mot_lan_them_query_san_luong$$.asyncGroupBy(["ma_vt"],["sl_xuat"]);await $phu_cap_mot_lan_them_query_san_luong$$.asyncJoinModel2($id_app$$,"dmvt",
{where:"ma_vt",fields:["ten_phu_cap_them","ten_vt","luong_tho_theo_ds","ds_yeu_cau"]});$phu_cap_mot_lan_them_query_san_luong$$=$phu_cap_mot_lan_them_query_san_luong$$.filter($d$$=>$d$$.luong_tho_theo_ds&&$d$$.ds_yeu_cau&&$d$$.sl_xuat>=$d$$.ds_yeu_cau);$phu_cap_mot_lan_them_query_san_luong$$=$phu_cap_mot_lan_them_query_san_luong$$.map($sl$$=>{let $pc$$={kieu:"2",id_app:$id_app$$,thang:$thang$$,nam:$nam$$,ma_nv:$nv$$.ma_nv,ten_phu_cap:$sl$$.ten_phu_cap_them||$sl$$.ten_vt,dvt:"month"};$pc$$.sl_xuat=
$sl$$.sl_xuat;$pc$$.ds_yeu_cau=$sl$$.ds_yeu_cau;$pc$$.tien_pc=$pc$$.tien=Math.trunc($sl$$.sl_xuat/$sl$$.ds_yeu_cau)*$sl$$.luong_tho_theo_ds;return $pc$$});$phu_cap_mot_lan$$=[...$phu_cap_mot_lan$$,...$phu_cap_mot_lan_them_query_san_luong$$]}$nv$$.cac_khoan_phat=$phu_cap_mot_lan$$.filter($r$$=>$r$$.tien<0);$nv$$.tien_phat=$nv$$.cac_khoan_phat.map($r$$=>$r$$.tien_pc).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$csphucap_processed_phu_cap$$=[...($nv$$.phu_cap||[]),...($nv$$.phu_cap_theo_bp||[]),...($csphucap_processed_phu_cap$$?.phu_cap||
[])].filter($p$$=>$p$$.tu_ngay&&(new Date($p$$.tu_ngay)).getTime()>$den_ngay$$.getTime()||$p$$.den_ngay&&(new Date($p$$.den_ngay)).getTime()<$tu_ngay$$.getTime()?!1:!0).map($r$$=>{var $max_mien_thue_vnd_ty_gia$$=$getTyGia$$($r$$.ma_nt);let $tien_pc$$=Math.roundBy(($r$$.tien||0)*$max_mien_thue_vnd_ty_gia$$),$max_phu_cap_vnd$$=$r$$.max_phu_cap?Math.roundBy($r$$.max_phu_cap*$max_mien_thue_vnd_ty_gia$$):0;$max_mien_thue_vnd_ty_gia$$=$r$$.max_mien_thue?Math.roundBy($r$$.max_mien_thue*$max_mien_thue_vnd_ty_gia$$):
0;if($r$$.dvt=="date")$tien_pc$$=Math.roundBy($tien_pc$$*$nv$$.so_ngay_tinh_phu_cap);else if($r$$.dvt=="year"){$tien_pc$$=Math.roundBy($tien_pc$$/12);var $da_phu_cap_so_ngay_tru_so_ngay_tru$jscomp$1_tien_tru_pc_tien_tru_pc$$=$nv$$.tong_ngay_khong_luong;$da_phu_cap_so_ngay_tru_so_ngay_tru$jscomp$1_tien_tru_pc_tien_tru_pc$$>0&&($da_phu_cap_so_ngay_tru_so_ngay_tru$jscomp$1_tien_tru_pc_tien_tru_pc$$=Math.roundBy($tien_pc$$/($so_ngay_lam_mot_thang$$||26)*$da_phu_cap_so_ngay_tru_so_ngay_tru$jscomp$1_tien_tru_pc_tien_tru_pc$$),
$tien_pc$$=Math.max(0,$tien_pc$$-$da_phu_cap_so_ngay_tru_so_ngay_tru$jscomp$1_tien_tru_pc_tien_tru_pc$$))}else $r$$.dvt!="month"&&$r$$.dvt||($da_phu_cap_so_ngay_tru_so_ngay_tru$jscomp$1_tien_tru_pc_tien_tru_pc$$=$nv$$.tong_ngay_khong_luong,$da_phu_cap_so_ngay_tru_so_ngay_tru$jscomp$1_tien_tru_pc_tien_tru_pc$$>0&&($da_phu_cap_so_ngay_tru_so_ngay_tru$jscomp$1_tien_tru_pc_tien_tru_pc$$=Math.roundBy($tien_pc$$/($so_ngay_lam_mot_thang$$||26)*$da_phu_cap_so_ngay_tru_so_ngay_tru$jscomp$1_tien_tru_pc_tien_tru_pc$$),
$tien_pc$$=Math.max(0,$tien_pc$$-$da_phu_cap_so_ngay_tru_so_ngay_tru$jscomp$1_tien_tru_pc_tien_tru_pc$$)));$max_phu_cap_vnd$$>0&&($da_phu_cap_so_ngay_tru_so_ngay_tru$jscomp$1_tien_tru_pc_tien_tru_pc$$=($condition$$.cac_khoan_phu_cap||[]).filter($p$$=>$p$$.line==$r$$.line).map($r$$=>$r$$.tien_pc||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0),$tien_pc$$=Math.min($tien_pc$$,$max_phu_cap_vnd$$-$da_phu_cap_so_ngay_tru_so_ngay_tru$jscomp$1_tien_tru_pc_tien_tru_pc$$));$r$$.tien_pc=$tien_pc$$;$r$$.max_mien_thue&&($r$$.max_mien_thue=
$max_mien_thue_vnd_ty_gia$$);return $r$$});$nv$$.cac_khoan_phu_cap=[...$csphucap_processed_phu_cap$$,...$phu_cap_mot_lan$$.filter($r$$=>$r$$.tien>0)];$nv$$.tien_phu_cap=$nv$$.cac_khoan_phu_cap.map($r$$=>$r$$.tien_pc).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$nv$$.tong_phu_cap=$nv$$.tien_phu_cap+$nv$$.tien_phat},calculateTax=($nv$$,$condition$$)=>{var $phu_cap_mien_thue_tien_thue$$=$nv$$.cac_khoan_phu_cap.filter($p$$=>!$p$$.khong_mien_thue&&$p$$.tien_pc>0).map($r$$=>{let $tien_pc$$=$r$$.tien_pc;if($r$$.max_mien_thue>
0){let $da_phu_cap$$=($condition$$.cac_khoan_phu_cap_mien_thue||[]).filter($p$$=>$p$$.line==$r$$.line).map($r$$=>$r$$.tien_pc||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$tien_pc$$=Math.min($tien_pc$$,$r$$.max_mien_thue-$da_phu_cap$$)}$r$$.tien_pc=$tien_pc$$;return $r$$});$nv$$.thu_viec||$nv$$.luong_ctv?($phu_cap_mien_thue_tien_thue$$=[],$nv$$.ttncn_gt_phu_thuoc=0,$nv$$.ttncn_gt_tu_thien=0,$nv$$.ttncn_gt_ban_than=0):($nv$$.ttncn_gt_phu_thuoc=Math.roundBy(($nv$$.ttncn_so_nguoi_phu_thuoc||0)*($nv$$.ttncn_muc_gt_phu_thuoc||
0)),$nv$$.ttncn_gt_tu_thien=0,$nv$$.ttncn_gt_ban_than=Math.roundBy(($nv$$.ttncn_so_thang_gt_ban_than||1)*($nv$$.ttncn_muc_gt_ban_than||0)));$nv$$.cac_khoan_phu_cap_mien_thue=$phu_cap_mien_thue_tien_thue$$;$nv$$.tong_phu_cap_mien_thue=$phu_cap_mien_thue_tien_thue$$.map($r$$=>$r$$.tien_pc).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$nv$$.tong_thu_nhap=$nv$$.luong_thang+$nv$$.tong_phu_cap;$nv$$.luong_tang_ca_mien_thue=Math.roundBy($nv$$.don_gia_binh_quan_chuan*$nv$$.so_luong_ngay_tang_ca_mien_thue);$nv$$.ttncn_tong_thu_nhap_mien_thue=
$nv$$.luong_tang_ca_mien_thue+$nv$$.tong_phu_cap_mien_thue;$nv$$.ttncn_tong_giam_tru=$nv$$.ttncn_gt_phu_thuoc+$nv$$.ttncn_gt_tu_thien+$nv$$.tong_bao_hiem_nv+$nv$$.ttncn_gt_ban_than;$nv$$.ttncn_thu_nhap_chiu_thue=Math.max($nv$$.tong_thu_nhap-$nv$$.ttncn_tong_thu_nhap_mien_thue-$nv$$.ttncn_tong_giam_tru,0);$nv$$.thu_viec||$nv$$.luong_ctv?$nv$$.ttncn_thu_nhap_chiu_thue>=2E6?($phu_cap_mien_thue_tien_thue$$=Math.roundBy($nv$$.ttncn_thu_nhap_chiu_thue*10/100),$nv$$.ttncn_thue_theo_bac=[{thue_suat:10,tien_thue:$phu_cap_mien_thue_tien_thue$$}]):
$nv$$.ttncn_thue_theo_bac=[{thue_suat:0,tien_thue:0}]:$nv$$.ttncn_thue_theo_bac=tinhThueTNCV($nv$$.ttncn_thu_nhap_chiu_thue);$nv$$.ttncn_tong_thue=$nv$$.ttncn_thue_theo_bac.map($b$$=>$b$$.tien_thue||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$nv$$.tong_luong=$nv$$.tong_thu_nhap-$nv$$.tong_bao_hiem_nv-$nv$$.ttncn_tong_thue;$nv$$.id_app=$condition$$.id_app;$nv$$.thang=$condition$$.thang;$nv$$.nam=$condition$$.nam;$nv$$.loai_luong=$condition$$.loai_luong},tinhluong=async($condition$$,$callback$$)=>{let {tu_ngay:$tu_ngay$$,
den_ngay:$den_ngay$$,id_app:$id_app$$,ma_nv:$ma_nv$$,nv:$nv$$}=$condition$$;const $data_tinh_luong_ds$$=[];var $congs_nv_congs_nvs_fragments_virtual_frag$$=await chamcong.find({ma_nv:$ma_nv$$,id_app:$id_app$$,ngay:{$gte:$tu_ngay$$,$lte:$den_ngay$$}}).lean();if($nv$$.cham_cong){var $danh_sach_le_tet_nvs_ready_to_calc$$=await dmletet.find({id_app:$id_app$$}).lean();if($danh_sach_le_tet_nvs_ready_to_calc$$.length>0){let $date$$=new Date($tu_ngay$$),$endDate$$=new Date($den_ngay$$),$startWorkTs$$=$nv$$.ngay_bat_dau_lam?
moment($nv$$.ngay_bat_dau_lam).startOf("day").toDate().getTime():0,$endWorkTs$$=$nv$$.ngay_nghi_viec?moment($nv$$.ngay_nghi_viec).endOf("day").toDate().getTime():Infinity;for(;$date$$.getTime()<=$endDate$$.getTime();){let $currentDay$$=$date$$.getDate(),$currentMonth$$=$date$$.getMonth()+1,$isHoliday$$=$danh_sach_le_tet_nvs_ready_to_calc$$.find($le$$=>$le$$.ngay==$currentDay$$&&$le$$.thang==$currentMonth$$);if($isHoliday$$&&$isHoliday$$.ma_loai_cong){let $checkTs$$=moment($date$$).startOf("day").toDate().getTime();
$checkTs$$>=$startWorkTs$$&&$checkTs$$<=$endWorkTs$$&&($congs_nv_congs_nvs_fragments_virtual_frag$$.find($c$$=>moment($c$$.ngay).format("YYYY-MM-DD")===moment($date$$).format("YYYY-MM-DD"))||$congs_nv_congs_nvs_fragments_virtual_frag$$.push({id_app:$id_app$$,ma_nv:$ma_nv$$,ma_bp:$nv$$.ma_bp,ngay:new Date($date$$),ma_loai_cong:$isHoliday$$.ma_loai_cong,loai_don_gia_ngay_cong:"luong_ngay_cong",sl_cong:1,is_virtual_holiday:!0,ten_le:$isHoliday$$.ten_le}))}$date$$.setDate($date$$.getDate()+1)}}}await $congs_nv_congs_nvs_fragments_virtual_frag$$.filter($c$$=>
!$c$$.ma_bp).asyncJoinModel2($id_app$$,dmnv,[{where:{ma_nv:"ma_nv"},fields:["ma_bp"]}]);await $congs_nv_congs_nvs_fragments_virtual_frag$$.asyncJoinModel2($id_app$$,dmloaicong,[{where:{ma_loai_cong:"ma_loai_cong"},fields:"ngay_cong ngay_phep ngay_khong_phep ngay_khong_luong la_cong_lam_them tinh_phu_cap loai_don_gia_ngay_cong".split(" ")}]);$congs_nv_congs_nvs_fragments_virtual_frag$$.forEach($c$$=>{$c$$.loai_don_gia_ngay_cong&&$c$$.loai_don_gia_ngay_cong!="default"||($c$$.loai_don_gia_ngay_cong=
"luong_ngay_cong");$c$$.so_ngay_tinh_phu_cap=$c$$.tinh_phu_cap?Math.min($c$$.ngay_cong||0,1):0;$c$$.la_cong_lam_them&&($c$$.ngay_tang_ca=$c$$.ngay_cong,$c$$.ngay_cong=0,$c$$.so_luong_ngay_tang_ca_mien_thue=Math.max($c$$.ngay_tang_ca-1,0));$c$$.sl_cong=$c$$.sl_cong||1;"ngay_cong ngay_phep ngay_khong_phep ngay_khong_luong ngay_tang_ca so_ngay_tinh_phu_cap so_luong_ngay_tang_ca_mien_thue".split(" ").forEach($k$$=>$c$$[$k$$]*=$c$$.sl_cong)});$danh_sach_le_tet_nvs_ready_to_calc$$=[];$nv$$.cham_cong?($congs_nv_congs_nvs_fragments_virtual_frag$$=
$congs_nv_congs_nvs_fragments_virtual_frag$$.filter($c$$=>$c$$.ma_nv===$ma_nv$$),$danh_sach_le_tet_nvs_ready_to_calc$$=[...$danh_sach_le_tet_nvs_ready_to_calc$$,...$congs_nv_congs_nvs_fragments_virtual_frag$$]):($congs_nv_congs_nvs_fragments_virtual_frag$$=generateVirtualTimekeepingForVIP($nv$$,$condition$$),Object.assign($congs_nv_congs_nvs_fragments_virtual_frag$$,$nv$$),$danh_sach_le_tet_nvs_ready_to_calc$$.push($congs_nv_congs_nvs_fragments_virtual_frag$$));$congs_nv_congs_nvs_fragments_virtual_frag$$=
await $danh_sach_le_tet_nvs_ready_to_calc$$.asyncGroupBy(["ma_nv","ma_bp","loai_don_gia_ngay_cong"],"ngay_cong ngay_phep ngay_khong_phep ngay_khong_luong ngay_tang_ca so_ngay_tinh_phu_cap so_luong_ngay_tang_ca_mien_thue".split(" "));await $congs_nv_congs_nvs_fragments_virtual_frag$$.asyncJoinModel2($id_app$$,dmnv,[{where:{ma_nv:"ma_nv"},fields:"ten_nv ma_kho luong_ngay_cong luong_ngay_cong2 luong_ngay_cong3 luong_co_ban luong_thu_viec thu_viec_den_ngay ngay_bat_dau_lam ngay_nghi_viec luong_bhxh phu_cap cham_cong tinh_luong bhxh bhyt bhtn ttncn_so_nguoi_phu_thuoc ttncn_muc_gt_phu_thuoc ttncn_so_thang_gt_ban_than ttncn_muc_gt_ban_than luong_ctv".split(" ")}]);
let $nvs$$=mergeTimekeepingFragments($congs_nv_congs_nvs_fragments_virtual_frag$$,$condition$$);await $nvs$$.asyncJoinModel2($id_app$$,dmbp,[{where:{ma_bp:"ma_bp"},fields:["ten_bp","tinh_luong_theo_ngay",{phu_cap_theo_bp:"phu_cap"}]}]);let $cac_khoan_giam_tru$$=await ckgtluong.find({id_app:$id_app$$,status:!0}).lean(),$tyGiaMap$$={VND:1};(await global.getModel("currency").find({id_app:$id_app$$}).lean()).forEach($c$$=>{$c$$.ma_nt&&$c$$.ty_gia&&($tyGiaMap$$[$c$$.ma_nt.toUpperCase()]=Number($c$$.ty_gia))});
$condition$$.tyGiaMap=$tyGiaMap$$;async.mapLimit($nvs$$,20,async $nv$$=>{try{await calculateTimeBasedSalary($nv$$,$condition$$);await calculateSalesBasedSalary($nv$$,$condition$$,$data_tinh_luong_ds$$);calculateInsurance($nv$$,$condition$$,$cac_khoan_giam_tru$$);const $csphucap$$=await global.getModel("csphucap").findOne({id_app:$id_app$$,status:!0,$or:[{ds_nv:$nv$$.ma_nv},{ds_bp:$nv$$.ma_bp}]}).lean();await calculateAllowances($nv$$,$condition$$,$csphucap$$);calculateTax($nv$$,$condition$$);return null}catch($err$$){return $err$$}},
async $e$$=>{if($e$$)return $callback$$($e$$);try{await bangtinhluong.create($nvs$$),$data_tinh_luong_ds$$.length>0&&await global.getModel("chitietluongds").create($data_tinh_luong_ds$$),$callback$$(null,$nvs$$)}catch($e$$){$callback$$($e$$.message)}})};
module.exports=function($router$$){new controller($router$$,"tinhluong",async($nhanvien_req$$,$callback$$)=>{let $thang$$=Number($nhanvien_req$$.query.thang),$nam$$=Number($nhanvien_req$$.query.nam),$id_app$$=$nhanvien_req$$.query.id_app;if(!$thang$$||!$nam$$)return $callback$$("T\u00ednh n\u0103ng n\u00e0y y\u00eau c\u1ea7u hai tham s\u1ed1 thang v\u00e0 nam");if($thang$$<1||$thang$$>12||$nam$$<1E3||$nam$$>3E3)return $callback$$("Tham s\u1ed1 thang ho\u1eb7c nam kh\u00f4ng ph\u00f9 h\u1ee3p");const $tu_ngay$$=
moment(new Date($nam$$,$thang$$-1,1)).startOf("month").toDate(),$den_ngay$$=moment($tu_ngay$$).endOf("month").toDate();var $appInfo_query$$=await App.findOne({_id:$id_app$$});if(!$appInfo_query$$)return $callback$$("C\u00f4ng ty n\u00e0y kh\u00f4ng t\u1ed3n t\u1ea1i");let $ngay_ks$$=await utils.isBookLocked({id_app:$id_app$$,ngay_ct:$tu_ngay$$});if($ngay_ks$$)return $callback$$(`\u0110\u00e3 kh\u00f3a s\u1ed5 \u0111\u1ebfn ng\u00e0y ${moment($ngay_ks$$).format("DD/MM/YYYY")}`);const $main_condition$$=
{tu_ngay:$tu_ngay$$,den_ngay:$den_ngay$$,id_app:$id_app$$,thang:$thang$$,nam:$nam$$,so_ngay_lam_mot_thang:$nhanvien_req$$.query.so_ngay_lam_mot_thang||$appInfo_query$$.so_ngay_lam_mot_thang||24,ma_bp:$nhanvien_req$$.query.ma_bp};$appInfo_query$$={id_app:$nhanvien_req$$.query.id_app,tinh_luong:!0,$or:[{ngay_nghi_viec:{$exists:!1}},{ngay_nghi_viec:null},{ngay_nghi_viec:{$gt:$tu_ngay$$}}]};$nhanvien_req$$.query.ma_nv&&($appInfo_query$$.ma_nv=$nhanvien_req$$.query.ma_nv);$main_condition$$.ma_bp&&($appInfo_query$$.ma_bp=
$main_condition$$.ma_bp);$nhanvien_req$$=await dmnv.find($appInfo_query$$).lean();$appInfo_query$$={};$appInfo_query$$.id_app=$id_app$$;$appInfo_query$$.thang=$thang$$;$appInfo_query$$.nam=$nam$$;$appInfo_query$$.ma_nv={$in:$nhanvien_req$$.map($n$$=>$n$$.ma_nv)};$main_condition$$.ma_bp&&($appInfo_query$$.ma_bp=$main_condition$$.ma_bp);Logger.debug("[tinhluong] xo\u00e1 d\u1eef li\u1ec7u c\u0169",$appInfo_query$$);await bangtinhluong.deleteMany($appInfo_query$$);await global.getModel("chitietluongds").deleteMany($appInfo_query$$);
async.mapLimit($nhanvien_req$$,20,($nv$$,$callback$$)=>{let $cac_khoan_phu_cap$$=[],$cac_khoan_phu_cap_mien_thue$$=[];async.series({tv:$callback$$=>{if(!$nv$$.thu_viec_den_ngay)return $callback$$(null,[]);var $condition$$=moment($nv$$.thu_viec_den_ngay).endOf("date").toDate();if($condition$$.getTime()<$tu_ngay$$.getTime())return $callback$$(null,[]);$condition$$.getTime()>$den_ngay$$.getTime()&&($condition$$=$den_ngay$$);$condition$$={...$main_condition$$,ma_nv:$nv$$.ma_nv,ma_bp:$main_condition$$.ma_bp,
loai_luong:1,nam:$nam$$,thang:$thang$$,tu_ngay:$tu_ngay$$,den_ngay:$condition$$,nv:$nv$$};Logger.info("[tinhluong] t\u00ednh l\u01b0\u01a1ng th\u1eed vi\u1ec7c nh\u00e2n vi\u00ean",$nv$$.ten_nv);tinhluong($condition$$,($error$$,$rs$$)=>{$rs$$&&($cac_khoan_phu_cap$$=$rs$$.map($r$$=>$r$$.cac_khoan_phu_cap||[]).reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]),$cac_khoan_phu_cap_mien_thue$$=$rs$$.map($r$$=>$r$$.cac_khoan_phu_cap_mien_thue||[]).reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]));$callback$$($error$$,
$rs$$)})},ct:$callback$$=>{let $tinh_luong_tu_ngay$$;$nv$$.thu_viec_den_ngay?($tinh_luong_tu_ngay$$=moment($nv$$.thu_viec_den_ngay).startOf("date").toDate(),$tinh_luong_tu_ngay$$.setDate($tinh_luong_tu_ngay$$.getDate()+1),$tinh_luong_tu_ngay$$.getTime()<$tu_ngay$$.getTime()&&($tinh_luong_tu_ngay$$=$tu_ngay$$)):$tinh_luong_tu_ngay$$=$tu_ngay$$;if($tinh_luong_tu_ngay$$.getTime()>$den_ngay$$.getTime())return $callback$$(null,[]);Logger.info("[tinhluong] t\u00ednh l\u01b0\u01a1ng ch\u00ednh th\u1ee9c nh\u00e2n vi\u00ean",
$nv$$.ten_nv);tinhluong({...$main_condition$$,ma_nv:$nv$$.ma_nv,ma_bp:$main_condition$$.ma_bp,loai_luong:2,tu_ngay:$tinh_luong_tu_ngay$$,den_ngay:$den_ngay$$,cac_khoan_phu_cap:$cac_khoan_phu_cap$$,cac_khoan_phu_cap_mien_thue:$cac_khoan_phu_cap_mien_thue$$,nv:$nv$$},$callback$$)}},($e$$,$rs$$)=>{if($e$$)return $callback$$($e$$);$rs$$=$rs$$.tv.concat($rs$$.ct);$callback$$(null,$rs$$)})},($e$$,$rs$$)=>{if($e$$)return $callback$$($e$$);$callback$$(null,$rs$$.reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]))})},
{stream:!1,useSession:!0,cache:!1,queue:!0,timeout:18E6})};