PayrollComputation.cs 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114
  1. using Google.Protobuf.WellKnownTypes;
  2. using NPOI.HPSF;
  3. using NPOI.OpenXmlFormats.Spreadsheet;
  4. using NPOI.SS.Formula.Functions;
  5. using NPOI.Util;
  6. using OASystem.API.OAMethodLib.QiYeWeChatAPI;
  7. using OASystem.Domain;
  8. using OASystem.Domain.Entities.PersonnelModule;
  9. using OASystem.Domain.ViewModels.PersonnelModule;
  10. using OASystem.Domain.ViewModels.QiYeWeChat;
  11. using OASystem.Infrastructure.Repositories.Groups;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Diagnostics.Eventing.Reader;
  15. using System.Linq.Expressions;
  16. using TencentCloud.Ocr.V20181119.Models;
  17. namespace OASystem.API.OAMethodLib
  18. {
  19. /// <summary>
  20. /// 工资计算
  21. /// </summary>
  22. public static class PayrollComputation
  23. {
  24. private static Result _result = new Result();
  25. private static readonly IQiYeWeChatApiService _qiYeWeChatApiService = AutofacIocManager.Instance.GetService<IQiYeWeChatApiService>();
  26. private static readonly UsersRepository _usersRep = AutofacIocManager.Instance.GetService<UsersRepository>();
  27. private static readonly IMapper _mapper = AutofacIocManager.Instance.GetService<IMapper>();
  28. private static readonly decimal _chengDuMinimumWage = 2100.00M;
  29. /// <summary>
  30. /// 计算工资
  31. /// </summary>
  32. /// <param name="pm_WageSheetDattaSources"></param>
  33. /// <param name="userNames"></param>
  34. /// <param name="thisYearMonth"></param>
  35. /// <param name="startDt"></param>
  36. /// <param name="endDt"></param>
  37. /// <returns></returns>
  38. public static async Task<Result> SalaryCalculatorAsync(
  39. List<Pm_WageSheet> pm_WageSheetDattaSources, List<UserNameView> userNames, int userId, string thisYearMonth, DateTime startDt, DateTime endDt)
  40. {
  41. if (pm_WageSheetDattaSources.Count <= 0)
  42. {
  43. _result.Msg = "计算工资传入数据为空!";
  44. return _result;
  45. }
  46. if (userNames.Count <= 0)
  47. {
  48. var nameData = await _usersRep.GetUserNameList(1);
  49. userNames = nameData.Data;
  50. }
  51. //计算时间段内工作日
  52. int work_days = await GetWorkDays(thisYearMonth);
  53. if (work_days <=0)
  54. {
  55. _result.Msg = thisYearMonth+" 工作日未设置,请前往《工作日管理页面》设置!";
  56. return _result;
  57. }
  58. UserIdListView userIdListView = await _qiYeWeChatApiService.GetUserIdListAsync();
  59. if (userIdListView.errcode != 0)
  60. {
  61. _result.Msg = "【企业微信】【打卡】【获取员工ID】【Msg】" + userIdListView.errmsg;
  62. return _result;
  63. }
  64. List<string> qyWhchatIdList = new List<string>();
  65. qyWhchatIdList = userIdListView.dept_user.Select(it => it.userid).ToList();
  66. CheckInDayDataView checkInDayDataView = await _qiYeWeChatApiService.GetCheckInDayDataAsync(qyWhchatIdList, startDt, endDt);
  67. if (checkInDayDataView.errcode != 0)
  68. {
  69. _result.Msg = "【企业微信】【打卡】【获取时间段内所有日打卡】【Msg】" + checkInDayDataView.errmsg;
  70. return _result;
  71. }
  72. //筛选出工作日日报
  73. List<Root> workday_userRoots = checkInDayDataView.datas.Where(it => it.base_info.day_type == 0 && it.base_info.record_type == 1).ToList(); //工作日日报
  74. workday_userRoots = workday_userRoots.OrderBy(it => it.base_info.date).ToList();
  75. //获取 请假类型 Sp_Detail.template_id
  76. string leave_template_id = "C4NzTJCh1onCUK915rRkvy7Fh5Vqz4YbiEV9jrBY1";
  77. List<VacationLeaveTypeView> vacationLeaveTypes = await GetVacationLeaveTypes(leave_template_id);
  78. if (vacationLeaveTypes.Count <= 0)
  79. {
  80. _result.Msg = "【企业微信】【审批】【获取审批类型】【Msg】" + startDt + " - " + endDt + "请假 类型数据 获取失败!";
  81. return _result;
  82. }
  83. try
  84. {
  85. foreach (var pm_wsInfo in pm_WageSheetDattaSources)
  86. {
  87. string itemName = userNames.Where(it => it.Id == pm_wsInfo.UserId).FirstOrDefault().CnName;
  88. //补贴 金额
  89. decimal meal_subsidy = 0.00M; // 午餐(午餐10元/天) 补贴 * 计算方式:单日上午请假时长(小时)大于或者等于三小时 没有餐补
  90. //事假 病假 总金额
  91. decimal personalLeaveTotal = 0.00M, // 事假 日薪 *计算方式:日平均工资 = 月工资/当月应出勤天数。
  92. sickLeaveTotal = 0.00M; // 病假 日薪 *计算方式:日平均工资 = 成都市最低工资标准的80%/当月应出勤天数。 短期病假=当月15天内
  93. //扣款金额
  94. decimal beLate_deduction = 0.00M, // 迟到 扣款金额 *计算方式:
  95. // 一个自然月内,不足 10 分钟的迟到/早退,不超过 2 次的部分,不做处罚;3 次及以上,按50元 / 次处罚;
  96. // 超过 10 分钟(含 10 分钟),不足 60 分钟的迟到/早退,按 50 元/次处罚;
  97. // 超过 60 分钟(含 60 分钟),不足 3 小时的迟到/早退,且无请假者,按旷工半日处理;超过3 小时的迟到 / 早退,且无请假者,按旷工一日处理。
  98. early_deduction = 0.00M, // 早退 扣款金额
  99. absenteeism_deduction = 0.00M, // 旷工 扣款金额 *计算方式:旷工扣发当日工资
  100. unprinted_deduction = 0.00M, // 未打卡 扣款金额 *计算方式:
  101. // 试用期员工每月有 2 次 补卡机会,超过 2 次不足 5 次的部分,按 10 元 / 次处罚,5 次及以上的漏卡,按 50 元 / 次处罚;
  102. // 正式员工每月 3 次以内的补卡,按 10 元 / 次处罚,3 次及以上的漏卡,按 50 元 / 次处罚。
  103. sickLeave_deduction = 0.00M, // 病假
  104. other_deduction = 0.00M; // 其他 扣款金额
  105. decimal meal_deduction = 0.00M; // 餐补 扣款金额
  106. decimal reissuecard_deduction = 0.00M; // 补卡 扣款金额
  107. #region 计算日工资 正常日薪 事假日薪 病假日薪
  108. //月 - 应发工资
  109. decimal amountPayable = pm_wsInfo.Basic + pm_wsInfo.Floats + pm_wsInfo.PostAllowance + pm_wsInfo.InformationSecurityFee + pm_wsInfo.OtherSubsidies;
  110. // 日薪 = *计算方式:日平均工资 = 月工资/当月应出勤天数。
  111. decimal dailyWage = amountPayable / work_days;
  112. // 病假日薪 *计算方式:日平均工资 = 成都市最低工资标准的80%/当月应出勤天数。 短期病假=当月15天内
  113. decimal sickLeave_dailywage = _chengDuMinimumWage / work_days;
  114. //病假 一天扣款
  115. sickLeave_deduction = dailyWage - sickLeave_dailywage;
  116. List<Ex_Items> ex_Items = new List<Ex_Items>();//假勤 And 打卡备注集合
  117. Ex_Items ex_Items_dk = new Ex_Items() { Type = "打卡" }; //打卡
  118. Ex_Items ex_Items_jq = new Ex_Items() { Type = "假勤" }; //假勤
  119. #endregion
  120. List<Root> userRoots = new List<Root>();
  121. if (itemName == "蔡雯")
  122. {
  123. userRoots = workday_userRoots.Where(it => it.base_info.name == "蔡蔡" || it.base_info.name == "蔡雯").ToList(); //工作日日报 1-固定上下班;
  124. }
  125. else
  126. {
  127. userRoots = workday_userRoots.Where(it => it.base_info.name == itemName).ToList(); //工作日日报 1-固定上下班;
  128. }
  129. //userRoots = userRoots.Distinct().ToList();
  130. userRoots = userRoots.OrderBy(it => it.base_info.date).ToList();
  131. int dk_work_days = userRoots.Count; //应出勤天数
  132. if (dk_work_days > work_days)
  133. {
  134. dk_work_days = work_days;
  135. }
  136. meal_subsidy = dk_work_days * 10; //应发放餐补
  137. if (!itemName.Equals("张海麟"))
  138. {
  139. if (userRoots.Count <= 0)
  140. {
  141. _result.Msg = "【企业微信】【打卡】【获取打卡数据】【Msg】" + startDt + " - " + endDt + "打卡日数据 获取失败!";
  142. continue;
  143. }
  144. string acctid = userRoots[0].base_info.acctid;
  145. List<Ex_Item> ex_reissuecard_Items = new List<Ex_Item>(); //打卡类型 数据
  146. List<Sp_items> acc_sp_items = new List<Sp_items>(); //审批数据
  147. int user_probationary_bk_num = 0;
  148. decimal user_probationary_bk_decimal = pm_wsInfo.Floats; //绩效工资为0 则为试用员工
  149. #region 迟到 早退 旷工
  150. int user_cd_zt_num = 0; //早退/迟到 次数 10分钟内 2次以内不记处罚 三次及以上50一次
  151. foreach (var root in userRoots)
  152. {
  153. List<Holiday_infos> holiday_Infos = root.holiday_infos; //当天假勤信息
  154. List<Exception_infos> exception_infos = root.exception_infos; //当天校准状态信息
  155. List<Sp_items> sp_Items = root.sp_items;//当天假勤统计信息
  156. if (sp_Items.Count > 0)
  157. {
  158. sp_Items = sp_Items.Where(it => it.count > 0).ToList();
  159. acc_sp_items.AddRange(sp_Items);
  160. }
  161. foreach (var exception_info in exception_infos)
  162. {
  163. decimal timelength = ConvertToDecimal((Convert.ToDecimal(exception_info.duration) / 3600.00M) * 60.00M); //时长 分钟
  164. if (timelength == 9) timelength = 7.50M;
  165. int exception = exception_info.exception; //异常类型
  166. decimal day_miner_unit = dailyWage / 15; //以0.5小时为单位
  167. //1:一个自然月内,不足 10 分钟的迟到/早退,不超过 2 次的部分,不做处罚;3 次及以上,按50 元 / 次处罚;
  168. //2:超过 10 分钟(含 10 分钟),不足 60 分钟的迟到 / 早退,按 50 元 / 次处罚;
  169. //3:超过 60 分钟(含 60 分钟),不足 3 小时的迟到 / 早退,且无请假者,按旷工半日处理;超过 3 小时的迟到 / 早退,且无请假者,按旷工一日处理。
  170. long date = root.base_info.date; //当日工作日期
  171. long earliest_time = root.summary_info.earliest_time; //最早打卡时间
  172. long lastest_time = root.summary_info.lastest_time; //最晚打卡时间
  173. long this_date = date + earliest_time;
  174. DateTime thisDt = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)).AddTicks(this_date * 10000000);
  175. string thisDtStr = thisDt.ToString("yyyy-MM-dd");
  176. Ex_Item beLate_belate_ex = new Ex_Item()
  177. {
  178. SubTypeId = 4,
  179. SubType = "旷工",
  180. Duration = timelength,
  181. StartTimeDt = Convert.ToDateTime(root.base_info.dateDt.ToString("yyyy-MM-dd HH:mm:ss")),
  182. Unit = "分钟",
  183. };
  184. decimal day_deduction = 0.00M;
  185. //1 - 迟到;2 - 早退;3 - 缺卡;4 - 旷工;5 - 地点异常;6 - 设备异常
  186. if (exception == 1) //迟到
  187. {
  188. if (timelength < 10)
  189. {
  190. user_cd_zt_num++;
  191. beLate_belate_ex.SubTypeId = 1;
  192. beLate_belate_ex.SubType = "迟到";
  193. string thisStartDt = (TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)).AddTicks((date + earliest_time) * 10000000))
  194. .ToString("yyyy-MM-dd HH:mm:ss");
  195. beLate_belate_ex.StartTimeDt = Convert.ToDateTime(thisStartDt);
  196. if (user_cd_zt_num >= 3)
  197. {
  198. day_deduction = 50.00M;
  199. }
  200. else
  201. {
  202. day_deduction = 0.00M;
  203. }
  204. beLate_deduction += day_deduction; //迟到扣款 总额
  205. }
  206. else if (timelength >= 10 && timelength <= 60)
  207. {
  208. string thisStartDt = (TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1))
  209. .AddTicks((date + earliest_time) * 10000000))
  210. .ToString("yyyy-MM-dd HH:mm:ss");
  211. beLate_belate_ex.StartTimeDt = Convert.ToDateTime(thisStartDt);
  212. day_deduction = 50.00M;
  213. beLate_deduction += day_deduction; //迟到扣款 总额
  214. beLate_belate_ex.SubTypeId = 1;
  215. beLate_belate_ex.SubType = "迟到";
  216. }
  217. else if (timelength > 60 && timelength <= 180)
  218. {
  219. day_deduction = ConvertToDecimal(day_miner_unit * 6); //3小时
  220. meal_deduction += 10.00M; //餐补扣款
  221. absenteeism_deduction += day_deduction; //矿工半日
  222. }
  223. else
  224. {
  225. day_deduction = ConvertToDecimal(dailyWage);
  226. absenteeism_deduction += day_deduction; //矿工一日
  227. meal_deduction += 10.00M;
  228. }
  229. beLate_belate_ex.Deduction = day_deduction;
  230. ex_reissuecard_Items.Add(beLate_belate_ex);
  231. }
  232. else if (exception == 2) //早退
  233. {
  234. if (timelength < 10)
  235. {
  236. user_cd_zt_num++;
  237. beLate_belate_ex.SubTypeId = 2;
  238. beLate_belate_ex.SubType = "早退";
  239. string thisEndDt = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1))
  240. .AddTicks((date + lastest_time) * 10000000)
  241. .ToString("yyyy-MM-dd HH:mm:ss");
  242. beLate_belate_ex.StartTimeDt = Convert.ToDateTime(thisEndDt);
  243. if (user_cd_zt_num >= 3)
  244. {
  245. day_deduction = 50.00M;
  246. }
  247. else
  248. {
  249. day_deduction = 0.00M;
  250. }
  251. early_deduction += day_deduction; //早退扣款 总计
  252. }
  253. else if (timelength >= 10 && timelength <= 60)
  254. {
  255. day_deduction = 50.00M;
  256. early_deduction += day_deduction; //早退扣款 总计
  257. beLate_belate_ex.SubTypeId = 2;
  258. beLate_belate_ex.SubType = "早退";
  259. string thisEndDt = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1))
  260. .AddTicks((date + lastest_time) * 10000000)
  261. .ToString("yyyy-MM-dd HH:mm:ss");
  262. beLate_belate_ex.StartTimeDt = Convert.ToDateTime(thisEndDt);
  263. }
  264. else if (timelength > 60 && timelength <= 180)
  265. {
  266. day_deduction = ConvertToDecimal(day_miner_unit * 6); //3小时
  267. meal_deduction += 10.00M;
  268. absenteeism_deduction += day_deduction; //矿工半日
  269. }
  270. else
  271. {
  272. day_deduction = ConvertToDecimal(dailyWage);
  273. meal_deduction += 10.00M;
  274. absenteeism_deduction += day_deduction; //矿工一日
  275. }
  276. beLate_belate_ex.Deduction = day_deduction;
  277. ex_reissuecard_Items.Add(beLate_belate_ex);
  278. }
  279. else if (exception == 3) //缺卡
  280. {
  281. if (root.exception_infos.Count == 2)
  282. {
  283. day_deduction = dailyWage;
  284. meal_deduction += 10.00M;
  285. absenteeism_deduction += day_deduction;
  286. beLate_belate_ex.Reason = "上午-下午 缺卡/未打卡为旷工 一天";
  287. beLate_belate_ex.Deduction = day_deduction;
  288. ex_reissuecard_Items.Add(beLate_belate_ex);
  289. }
  290. else if (root.exception_infos.Count == 1)
  291. {
  292. if (earliest_time == lastest_time)
  293. {
  294. DateTime thisDt1 = Convert.ToDateTime(thisDtStr + " 12:00");
  295. if (thisDt <= thisDt1) //旷工 下午
  296. {
  297. day_deduction = ConvertToDecimal(day_miner_unit * 9); //4.5小时
  298. meal_deduction += 10.00M;
  299. beLate_belate_ex.Duration = 270;
  300. absenteeism_deduction += day_deduction; //矿工半日
  301. beLate_belate_ex.Reason = thisDtStr + " 下午(18:00)缺卡/未打卡视为下午旷工(4.5小时)";
  302. beLate_belate_ex.Deduction = day_deduction;
  303. ex_reissuecard_Items.Add(beLate_belate_ex);
  304. }
  305. else if (thisDt >= thisDt1) //旷工 上午
  306. {
  307. day_deduction = ConvertToDecimal(day_miner_unit * 6); //3小时
  308. meal_deduction += 10.00M;
  309. absenteeism_deduction += day_deduction; //矿工半日
  310. beLate_belate_ex.Duration = 180;
  311. beLate_belate_ex.Reason = thisDtStr + " 上午(09:00)缺卡/未打卡视为上午旷工(3小时)";
  312. beLate_belate_ex.Deduction = day_deduction;
  313. ex_reissuecard_Items.Add(beLate_belate_ex);
  314. }
  315. else //矿工一日
  316. {
  317. day_deduction = ConvertToDecimal(dailyWage);
  318. meal_deduction += 10.00M;
  319. absenteeism_deduction += day_deduction;
  320. beLate_belate_ex.Reason = thisDtStr + " 上午(09:00)-下午(18:00) 缺卡/未打视为旷工一天(7.5小时)";
  321. beLate_belate_ex.Deduction = day_deduction;
  322. ex_reissuecard_Items.Add(beLate_belate_ex);
  323. }
  324. }
  325. }
  326. }
  327. else if (exception == 4) //旷工
  328. {
  329. if (timelength > 60 && timelength <= 180)
  330. {
  331. day_deduction = ConvertToDecimal(day_miner_unit * 6); //3小时
  332. beLate_belate_ex.Reason = thisDtStr + " 缺卡/未打视为旷工上午(3小时)";
  333. meal_deduction += 10.00M;
  334. absenteeism_deduction += day_deduction; //矿工半日
  335. }
  336. else
  337. {
  338. day_deduction = ConvertToDecimal(dailyWage);
  339. beLate_belate_ex.Reason = thisDtStr + " 上午(09:00)-下午(18:00) 缺卡/未打视为旷工一天(7.5小时)";
  340. meal_deduction += 10.00M;
  341. absenteeism_deduction += day_deduction; //矿工一日
  342. }
  343. beLate_belate_ex.Deduction = day_deduction;
  344. ex_reissuecard_Items.Add(beLate_belate_ex);
  345. }
  346. }
  347. }
  348. #endregion
  349. #region 假勤/补卡次数 审批
  350. int leaveNum = 0; //请假次数
  351. int reissuecardNum = 0; //补卡次数\
  352. //类型:1 - 请假;2 - 补卡;3 - 出差;4 - 外出;100 - 外勤
  353. leaveNum = acc_sp_items.Where(it => it.type == 1).ToList().Count();
  354. reissuecardNum = acc_sp_items.Where(it => it.type == 2).ToList().Count();
  355. //请假审批
  356. if (leaveNum > 0)
  357. {
  358. List<Sp_Detail> sp_leave_details = new List<Sp_Detail>();
  359. sp_leave_details = await _qiYeWeChatApiService.GetApprovalDetailsAsync(startDt, endDt, acctid, 2, 1); //时间段内所有 已同意的 请假 审批数据
  360. if (sp_leave_details.Count <= 0)
  361. {
  362. _result.Msg += startDt + " - " + endDt + " " + itemName + " 请假 审批数据获取未获取到!\r\n";
  363. //continue;
  364. }
  365. List<Ex_Item> ex_ItemInfos = new List<Ex_Item>();
  366. List<LeaveDetails> leaveDetails = new List<LeaveDetails>();
  367. foreach (Sp_Detail sp_item in sp_leave_details)
  368. {
  369. Apply_data? apply_data = sp_item.apply_data;
  370. if (apply_data != null)
  371. {
  372. List<ContentsItem> contents = apply_data.contents;
  373. ContentsItem content_Vacation = contents.Where(it => it.control == "Vacation").FirstOrDefault(); //请假类型
  374. ContentsItem content_Textarea = contents.Where(it => it.control == "Textarea").FirstOrDefault(); //多行文本
  375. if (content_Vacation != null)
  376. {
  377. Vacation vacation = content_Vacation.value.vacation;
  378. Attendance attendance = vacation.attendance; //假勤组件
  379. Selector selector = vacation.selector; //请假类型
  380. List<OptionsItem> optionsItems = selector.options; //key 请假类型 id
  381. List<TitleItem> value = optionsItems[0].value; // value 文本描述值
  382. int leaveType = int.Parse(optionsItems[0].key); //key 请假子类型 id
  383. Date_range date_Range = attendance.date_range;
  384. //筛选 不在工作日内的假勤申请
  385. if (startDt >= date_Range.new_begin_dt || Convert.ToDateTime( date_Range.new_end_dt.ToString("yyyy-MM-dd")) > endDt)
  386. {
  387. continue;
  388. }
  389. string leave_starttime = date_Range.new_begin_dt.ToString("HH:mm");
  390. string leave_endtime = date_Range.new_end_dt.ToString("HH:mm");
  391. string typeName = string.Empty;
  392. string unit = string.Empty;
  393. int leaveTypeId = leaveType;
  394. var leaveTypeData = vacationLeaveTypes.Where(it => it.id == leaveTypeId).FirstOrDefault();
  395. if (leaveTypeData != null) { typeName = leaveTypeData.name; }
  396. string startTime = string.Empty;
  397. string endTime = string.Empty;
  398. string startTime1 = string.Empty;
  399. string endTime1 = string.Empty;
  400. //计算请假类型扣款金额
  401. decimal new_duration = 0.00M;
  402. if (date_Range.type == "halfday")
  403. {
  404. new_duration = Convert.ToDecimal(date_Range.new_duration) / 86400.00M;
  405. unit = "天";
  406. startTime = date_Range.new_begin_dt.ToString("yyyy-MM-dd") + " 09:00";
  407. endTime = date_Range.new_begin_dt.ToString("yyyy-MM-dd") + " 18:00";
  408. startTime1 = "09:00:00";
  409. endTime1 = "18:00:00";
  410. }
  411. else if (date_Range.type == "hour")
  412. {
  413. new_duration = Convert.ToDecimal(date_Range.new_duration) / 3600.00M;
  414. unit = "小时";
  415. startTime = date_Range.new_begin_dt.ToString("yyyy-MM-dd HH:mm:ss");
  416. endTime = date_Range.new_end_dt.ToString("yyyy-MM-dd HH:mm:ss");
  417. startTime1 = date_Range.new_begin_dt.ToString("HH:mm:ss");
  418. endTime1 = date_Range.new_end_dt.ToString("HH:mm:ss");
  419. }
  420. LeaveDetails leaveDetails1 = new LeaveDetails()
  421. {
  422. TypeId = leaveType,
  423. TypeName = typeName,
  424. StartDt = Convert.ToDateTime(date_Range.new_begin_dt.ToString("yyyy-MM-dd") + " " + startTime1),
  425. EndDt = Convert.ToDateTime(date_Range.new_end_dt.ToString("yyyy-MM-dd") + " " + endTime1),
  426. DtType = date_Range.type,
  427. Unit = unit,
  428. New_Duration = new_duration,
  429. ApplyDt = Convert.ToDateTime(sp_item.apply_time_dt.ToString("yyyy-MM-dd HH:mm:ss"))
  430. };
  431. leaveDetails.Add(leaveDetails1);
  432. }
  433. }
  434. }
  435. if (leaveDetails.Count > 0)
  436. {
  437. foreach (LeaveDetails leave_item in leaveDetails)
  438. {
  439. decimal leave_meals = 0.00M;
  440. decimal thisTypeDeduction = 0.00M;//当前类型扣款
  441. int leaveType = leave_item.TypeId;
  442. decimal new_duration = leave_item.New_Duration;
  443. //计算餐补 假勤类型扣款
  444. CalculateTypeFee(leaveDetails,leaveType, leave_item.DtType, leave_item.StartDt, leave_item.EndDt, amountPayable, work_days,
  445. new_duration,out leave_meals, out thisTypeDeduction);
  446. #region 累计类型扣款
  447. //1年假;2事假;3病假;4调休假;5婚假;6产假;7陪产假;8其他;9丧假
  448. if (leaveType == 2) //事假
  449. {
  450. personalLeaveTotal += thisTypeDeduction;
  451. }
  452. else if (leaveType == 3) //病假
  453. {
  454. sickLeaveTotal = thisTypeDeduction;
  455. }
  456. #endregion
  457. meal_deduction += leave_meals;
  458. Ex_Item ex_Item = new Ex_Item()
  459. {
  460. SubTypeId = leaveType,
  461. SubType = leave_item.TypeName,
  462. StartTimeDt = leave_item.StartDt,
  463. EndTimeDt = leave_item.EndDt,
  464. Duration = new_duration,
  465. Unit = leave_item.Unit,
  466. Deduction = thisTypeDeduction,
  467. //Reason = apply_data.reason,
  468. Apply_time_dt = leave_item.ApplyDt,
  469. //Approval_name = sp_item.approval_name,
  470. };
  471. ex_ItemInfos.Add(ex_Item);
  472. }
  473. }
  474. if (ex_ItemInfos.Count > 0)
  475. {
  476. ex_Items_jq.Ex_ItemInfo = ex_ItemInfos.OrderBy(it => it.StartTimeDt).ThenBy(it => it.Apply_time_dt).ToList();
  477. ex_Items.Add(ex_Items_jq);
  478. }
  479. }
  480. //打卡补卡
  481. //补卡:员工发现自己漏打卡时,需及时提起补卡申请,并说明情况。
  482. //试用期员工每月有 2 次补卡机会,超过 2 次不足 5 次的部分,按 10 元/次处罚,5 次及以上的漏卡,按 50 元/次处罚;
  483. //正式员工每月 3 次以内的补卡,按 10 元/次处罚,3 次及以上的漏卡,按 50 元/次处罚。
  484. if (reissuecardNum > 0)
  485. {
  486. List<Sp_Detail> sp_buka_details = new List<Sp_Detail>();
  487. sp_buka_details = await _qiYeWeChatApiService.GetApprovalDetailsAsync(startDt, endDt, acctid, 2, 2); //时间段内所有 已同意的 请假 审批数据
  488. int bukaNum = 1;
  489. foreach (var item in sp_buka_details)
  490. {
  491. Apply_data? apply_data = item.apply_data;
  492. if (apply_data != null)
  493. {
  494. List<ContentsItem> contents = apply_data.contents;
  495. ContentsItem content_Vacation = contents.Where(it => it.control == "PunchCorrection").FirstOrDefault(); //请假类型
  496. ContentsItem content_Textarea = contents.Where(it => it.control == "Textarea").FirstOrDefault(); //多行文本
  497. if (content_Vacation != null)
  498. {
  499. var punch_correction = content_Vacation.value.punch_correction;
  500. DateTime bukaDt = punch_correction.time_dt;
  501. DateTime bukaDtJudge = Convert.ToDateTime(bukaDt.ToString("yyyy-MM-dd"));
  502. //筛选 不在工作日内的假勤申请
  503. if (startDt >= bukaDtJudge || bukaDtJudge > endDt)
  504. {
  505. continue;
  506. }
  507. decimal bukaPrice = 0.00M;
  508. if (user_probationary_bk_decimal == 0) //计算试用员工补卡次数
  509. {
  510. if (bukaNum <= 2) bukaPrice = 0.00M;
  511. else if (bukaNum <= 4 && bukaNum > 2) bukaPrice = 10.00M;
  512. else bukaPrice = 50.00M;
  513. }
  514. else //计算正式员工补卡次数
  515. {
  516. if (bukaNum <= 2) bukaPrice = 10.00M;
  517. else bukaPrice = 50.00M;
  518. }
  519. var app_data = item.apply_data;
  520. var punch_correction1 = app_data.contents[0].value.punch_correction; //未打卡时间
  521. var punch_correction2 = app_data.contents[1].value;
  522. Ex_Item ex_reissueCard = new Ex_Item()
  523. {
  524. SubTypeId = 7,
  525. SubType = "打卡补卡",
  526. StartTimeDt = Convert.ToDateTime(punch_correction1.time_dt.ToString("yyyy-MM-dd HH:mm:ss")), //未打卡时间
  527. Deduction = bukaPrice,
  528. Reason = punch_correction2.text,
  529. Unit = string.Empty
  530. };
  531. unprinted_deduction += bukaPrice;
  532. ex_reissuecard_Items.Add(ex_reissueCard);
  533. bukaNum++;
  534. }
  535. }
  536. }
  537. }
  538. if (ex_reissuecard_Items.Count > 0)
  539. {
  540. ex_Items_dk.Ex_ItemInfo = ex_reissuecard_Items;
  541. //ex_Items_dk.Ex_ItemInfo = ex_reissuecard_Items.OrderBy(it => it.SubTypeId).ThenBy(it => it.StartTimeDt).ToList();
  542. ex_Items.Add(ex_Items_dk);
  543. }
  544. #endregion
  545. }
  546. else
  547. {
  548. meal_subsidy = work_days * 10.00M;
  549. }
  550. #region 应发合计 实发合计 扣款合计(假勤扣款,其他扣款,社保扣款,公积金代扣,个税扣款)
  551. decimal mealTotal = meal_subsidy - meal_deduction; //餐补
  552. decimal salaryTotal = 0.00M;
  553. if (dk_work_days >= work_days)
  554. {
  555. dk_work_days = work_days;
  556. salaryTotal = amountPayable + mealTotal; //应发合计
  557. }
  558. else
  559. {
  560. if (itemName.Equals("张海麟"))
  561. {
  562. salaryTotal = amountPayable + mealTotal; //应发合计
  563. }
  564. else
  565. {
  566. salaryTotal = (dk_work_days * dailyWage) + mealTotal; //应发合计
  567. }
  568. }
  569. //扣款合计 不含个税
  570. decimal eductionTotal = sickLeaveTotal + personalLeaveTotal + beLate_deduction + early_deduction + absenteeism_deduction + unprinted_deduction + other_deduction +
  571. pm_wsInfo.WithholdingInsurance + pm_wsInfo.ReservedFunds + pm_wsInfo.OtherDeductions;
  572. decimal actualReleaseTotal = salaryTotal - eductionTotal; //实发合计 * 不含个税
  573. #endregion
  574. #region 处理当月工资数据
  575. pm_wsInfo.YearMonth = thisYearMonth;
  576. pm_wsInfo.StartDate = startDt.ToString("yyyy-MM-dd");
  577. pm_wsInfo.EndDate = endDt.ToString("yyyy-MM-dd");
  578. pm_wsInfo.WorkDays = work_days; //当月应出勤天数
  579. pm_wsInfo.RegularDays = dk_work_days; //当月正常出勤天数
  580. pm_wsInfo.SickLeave = sickLeaveTotal; //病假
  581. pm_wsInfo.SomethingFalse = personalLeaveTotal; //事假
  582. pm_wsInfo.LateTo = beLate_deduction; //迟到
  583. pm_wsInfo.LeaveEarly = early_deduction; //早退
  584. pm_wsInfo.Absenteeism = absenteeism_deduction; //旷工
  585. pm_wsInfo.NotPunch = unprinted_deduction; //未打卡
  586. pm_wsInfo.OtherDeductions = other_deduction; //其他
  587. pm_wsInfo.Ex_ItemsRemark = JsonConvert.SerializeObject(ex_Items); //
  588. pm_wsInfo.Mealsupplement = mealTotal; //餐补
  589. pm_wsInfo.Should = salaryTotal; //应发合计
  590. pm_wsInfo.TotalDeductions = eductionTotal; //扣款合计
  591. pm_wsInfo.TotalRealHair = actualReleaseTotal - pm_wsInfo.WithholdingTax; //实发合计
  592. pm_wsInfo.AfterTax = actualReleaseTotal - pm_wsInfo.WithholdingTax; //税后工资
  593. pm_wsInfo.LastUpdateUserId = userId;
  594. pm_wsInfo.LastUpdateDt = DateTime.Now;
  595. pm_wsInfo.CreateUserId = userId;
  596. pm_wsInfo.CreateTime = DateTime.Now;
  597. pm_wsInfo.DeleteUserId = null;
  598. pm_wsInfo.DeleteTime = null;
  599. #endregion
  600. }
  601. }
  602. catch (Exception ex)
  603. {
  604. _result.Msg = ex.Message;
  605. return _result;
  606. }
  607. _result.Code = 0;
  608. _result.Data = pm_WageSheetDattaSources;
  609. return _result;
  610. }
  611. /// <summary>
  612. /// decimal 保留两位小数 不四舍五入
  613. /// </summary>
  614. /// <param name="number"></param>
  615. /// <returns></returns>
  616. public static decimal ConvertToDecimal(decimal myDecimal)
  617. {
  618. var subDecimal = Math.Floor(myDecimal * 100) / 100;//保留两位小数,直接截取
  619. return subDecimal;
  620. }
  621. /// <summary>
  622. /// 获取请假类型
  623. /// </summary>
  624. /// <param name="template_id"></param>
  625. /// <returns></returns>
  626. public static async Task<List<VacationLeaveTypeView>> GetVacationLeaveTypes(string template_id)
  627. {
  628. List<VacationLeaveTypeView> vacationLeaveTypes = new List<VacationLeaveTypeView>();
  629. TemplateDetailView templateDetailView = new TemplateDetailView();
  630. templateDetailView = await _qiYeWeChatApiService.GetTemplateDetailAsync(template_id);
  631. if (templateDetailView.errcode != 0)
  632. {
  633. Serilog.Log.Error("【企业微信】【审批】【获取假勤类型的审批】【Msg】"+ templateDetailView.errmsg);
  634. return vacationLeaveTypes;
  635. }
  636. List<VacationItemInfo> VacationItemInfos = templateDetailView.vacation_list.item;
  637. foreach (var item in VacationItemInfos)
  638. {
  639. ValueItem valueInfo = item.name.Where(it => it.lang == "zh_CN").FirstOrDefault();
  640. if (valueInfo != null)
  641. {
  642. vacationLeaveTypes.Add(
  643. new VacationLeaveTypeView()
  644. {
  645. id = item.id,
  646. name = valueInfo.text
  647. });
  648. }
  649. }
  650. return vacationLeaveTypes;
  651. }
  652. /// <summary>
  653. /// 计算类型费用
  654. /// </summary>
  655. /// <param name="leaveType">
  656. /// 1年假;2事假;3病假;4调休假;5婚假;6产假;7陪产假;8其他;9丧假
  657. /// </param>
  658. /// <param name="date_Range_type">
  659. /// halfday 全天
  660. /// hour 小时
  661. /// </param>
  662. /// <param name="startTime"></param>
  663. /// <param name="endTime"></param>
  664. /// <param name="duration"></param>
  665. /// <param name="mealDeduction"></param>
  666. /// <param name="typeDeduction"></param>
  667. public static void CalculateTypeFee(List<LeaveDetails> leaveDetails,int leaveType, string date_Range_type, DateTime startTime, DateTime endTime,
  668. decimal amountPayable,int work_days, decimal duration, out decimal mealDeduction, out decimal typeDeduction)
  669. {
  670. typeDeduction = 0;
  671. mealDeduction = 0;
  672. string am_starttime = "08:59";
  673. string am_endtime = "13:01";
  674. //string startTime = startTime1.ToString("HH:mm:ss");
  675. //string endTime = endTime1.ToString("HH:mm:ss");
  676. decimal personalkLeave_dailywage_day = amountPayable / work_days; //日薪 = 事假日薪 *计算方式:日平均工资 = 当月应发工资 /当月应出勤天数。
  677. //半小时单位
  678. decimal halfHour = 7.50M / 0.50M;
  679. switch (leaveType)
  680. {
  681. case 1: //年假
  682. CalculateTypeFeeSub(leaveDetails, date_Range_type, startTime, endTime, duration, out mealDeduction);
  683. break;
  684. case 2: //2事假
  685. // 事假日薪 *计算方式:日平均工资 = 当月应发工资 /当月应出勤天数。
  686. decimal personalkLeave_dailywage_halfhour = personalkLeave_dailywage_day / halfHour; //事假单位 0.5小时
  687. if (date_Range_type == "halfday")
  688. {
  689. mealDeduction = 10; //餐补扣款
  690. typeDeduction = ConvertToDecimal(personalkLeave_dailywage_day);
  691. }
  692. else if (date_Range_type == "hour")
  693. {
  694. decimal leave_halfHour = Convert.ToDecimal(duration) / Convert.ToDecimal(0.5);
  695. typeDeduction = ConvertToDecimal( personalkLeave_dailywage_halfhour * leave_halfHour);
  696. //duration = 11M;
  697. if (duration >= 3 && duration < 7.5M) //单天请假三小时
  698. {
  699. mealDeduction = 10; //餐补扣款
  700. }
  701. else if (duration >= 7.5M) //多天计算
  702. {
  703. decimal leave_halfHour1 = Convert.ToDecimal(duration) / Convert.ToDecimal(0.5);
  704. decimal leaveDays = duration / 7.5M;
  705. if (leaveDays % 1 == 0)
  706. {
  707. typeDeduction = ConvertToDecimal(personalkLeave_dailywage_day * leaveDays);
  708. mealDeduction = 10 * leaveDays; //餐补扣款
  709. }
  710. else
  711. {
  712. typeDeduction = personalkLeave_dailywage_day * Convert.ToInt32(leaveDays);
  713. decimal sy_shijiaunit = leave_halfHour1 - Convert.ToDecimal (15.00M * Convert.ToInt32(leaveDays));
  714. if (sy_shijiaunit > 0)
  715. {
  716. typeDeduction += ConvertToDecimal(personalkLeave_dailywage_halfhour * sy_shijiaunit);
  717. }
  718. mealDeduction = 10 * Convert.ToInt32(leaveDays);
  719. //得到最后一天的请假时间 是否有餐补
  720. int lastHours = (Convert.ToDateTime(endTime) - Convert.ToDateTime("09:00")).Hours;
  721. if (lastHours >= 3)
  722. {
  723. mealDeduction += 10; //餐补扣款
  724. }
  725. }
  726. }
  727. }
  728. break;
  729. case 3: //3病假
  730. // 病假日薪 *计算方式:日平均工资 = 成都市最低工资标准的80% /当月应出勤天数。 短期病假=当月15天内
  731. decimal chengDuMinimumWage_halrHour = _chengDuMinimumWage / work_days / halfHour;
  732. decimal sickLeave_dailywage_halfhour_deduction = personalkLeave_dailywage_day - chengDuMinimumWage_halrHour; //病假单位 0.5小时 扣款金额
  733. if (date_Range_type == "halfday")
  734. {
  735. mealDeduction = 10; //餐补扣款
  736. typeDeduction = ConvertToDecimal( sickLeave_dailywage_halfhour_deduction * halfHour);
  737. }
  738. else if (date_Range_type == "hour")
  739. {
  740. decimal sickLeave_halfHour = duration / 0.5M;
  741. typeDeduction = ConvertToDecimal(personalkLeave_dailywage_day); ;
  742. if (duration >= 3 && duration < 7.5M) //单天请假三小时 && 请假时间在上午 则没有餐补
  743. {
  744. mealDeduction = 10; //餐补扣款
  745. }
  746. else if (duration >= 7.5M) //多天计算
  747. {
  748. decimal sickLeave_halfHour1 = duration / 0.5M;
  749. decimal leaveDays = Convert.ToDecimal(duration / 7.5M);
  750. typeDeduction = ConvertToDecimal(sickLeave_dailywage_halfhour_deduction * sickLeave_halfHour1);
  751. if (leaveDays % 1 == 0)
  752. {
  753. mealDeduction = 10 * leaveDays; //餐补扣款
  754. }
  755. else
  756. {
  757. mealDeduction = 10 * Convert.ToInt32(leaveDays);
  758. typeDeduction = ConvertToDecimal(sickLeave_dailywage_halfhour_deduction * Convert.ToInt32(leaveDays));
  759. decimal sy_bingjiaunit = sickLeave_halfHour1 - Convert.ToDecimal(15.00M * Convert.ToInt32(leaveDays));
  760. if (sy_bingjiaunit > 0)
  761. {
  762. typeDeduction += ConvertToDecimal(sickLeave_dailywage_halfhour_deduction * sy_bingjiaunit);
  763. }
  764. //得到最后一天的请假时间 是否有餐补
  765. int lastHours = (Convert.ToDateTime(endTime) - Convert.ToDateTime("09:00")).Hours;
  766. if (lastHours >= 3)
  767. {
  768. mealDeduction += 10; //餐补扣款
  769. }
  770. }
  771. }
  772. }
  773. break;
  774. case 4: //4调休假
  775. CalculateTypeFeeSub(leaveDetails,date_Range_type, startTime, endTime, duration, out mealDeduction);
  776. break;
  777. case 5: //5婚假
  778. CalculateTypeFeeSub(leaveDetails,date_Range_type, startTime, endTime, duration, out mealDeduction);
  779. break;
  780. case 6: //6产假
  781. CalculateTypeFeeSub(leaveDetails,date_Range_type, startTime, endTime, duration, out mealDeduction);
  782. break;
  783. case 7: //7陪产假
  784. CalculateTypeFeeSub(leaveDetails,date_Range_type, startTime, endTime, duration, out mealDeduction);
  785. break;
  786. case 8: //8其他
  787. CalculateTypeFeeSub(leaveDetails,date_Range_type, startTime, endTime, duration, out mealDeduction);
  788. break;
  789. case 9: //9丧假
  790. CalculateTypeFeeSub(leaveDetails,date_Range_type, startTime, endTime, duration, out mealDeduction);
  791. break;
  792. }
  793. }
  794. /// <summary>
  795. /// 计算类型费用
  796. /// </summary>
  797. /// <param name="date_Range_type">
  798. /// halfday 全天
  799. /// hour 小时
  800. /// </param>
  801. /// <param name="startTime"></param>
  802. /// <param name="endTime"></param>
  803. /// <param name="duration"></param>
  804. /// <param name="mealDeduction"></param>
  805. public static void CalculateTypeFeeSub(List<LeaveDetails> leaveDetails,string date_Range_type, DateTime startTime1, DateTime endTime1,
  806. decimal duration, out decimal mealDeduction)
  807. {
  808. mealDeduction = 0;
  809. string am_starttime = "09:00";
  810. string am_endtime = "11:59";
  811. string startTime = startTime1.ToString("HH:mm:ss");
  812. string endTime = endTime1.ToString("HH:mm:ss");
  813. if (date_Range_type == "halfday")
  814. {
  815. mealDeduction = 10; //餐补扣款
  816. }
  817. else if (date_Range_type == "hour")
  818. {
  819. List<LeaveDetails> leaveDetails1 = new List<LeaveDetails>();
  820. leaveDetails1 = leaveDetails.Where(it => it.StartDt.ToString("yyyy-MM-dd").Equals(startTime1.ToString("yyyy-MM-dd")))
  821. .OrderBy(it => it.StartDt).ToList();
  822. if (leaveDetails1.Count > 1)
  823. {
  824. decimal timelenTatoal = leaveDetails1.Sum(it => it.New_Duration);
  825. if (timelenTatoal >= 3.00M)
  826. {
  827. if (leaveDetails1[0].StartDt == startTime1)
  828. {
  829. mealDeduction = 10; //餐补扣款
  830. }
  831. }
  832. }
  833. else
  834. {
  835. if (duration >= 3 && duration < 7) //单天请假三小时 && 请假时间在上午 则没有餐补
  836. {
  837. mealDeduction = 10; //餐补扣款
  838. }
  839. else if (duration >= 7 && duration <= 7.50M)
  840. {
  841. mealDeduction = 10; //餐补扣款
  842. }
  843. else if (duration >= 7.50M) //多天计算
  844. {
  845. decimal leaveDays = Convert.ToDecimal(duration / 7.50M);
  846. if (leaveDays % 1 == 0)
  847. {
  848. mealDeduction = 10 * leaveDays; //餐补扣款
  849. }
  850. else
  851. {
  852. mealDeduction = 10 * Convert.ToInt32(leaveDays);
  853. //得到最后一天的请假时间 是否有餐补
  854. int lastHours = (Convert.ToDateTime(endTime) - Convert.ToDateTime("09:00")).Hours;
  855. if (lastHours >= 3)
  856. {
  857. mealDeduction += 10; //餐补扣款
  858. ////处理结束时间
  859. //if (endTime.CompareTo(am_starttime) > 0 && endTime.CompareTo(am_endtime) < 0)
  860. //{
  861. // mealDeduction += 10; //餐补扣款
  862. //}
  863. }
  864. }
  865. }
  866. }
  867. }
  868. }
  869. /// <summary>
  870. /// 获取打卡补卡类型
  871. /// </summary>
  872. /// <param name="template_id"></param>
  873. /// <returns></returns>
  874. public static async Task<List<VacationLeaveTypeView>> GetVacationReissueCardTypes(string template_id)
  875. {
  876. List<VacationLeaveTypeView> vacationLeaveTypes = new List<VacationLeaveTypeView>();
  877. TemplateDetailView templateDetailView = new TemplateDetailView();
  878. templateDetailView = await _qiYeWeChatApiService.GetTemplateDetailAsync(template_id);
  879. if (templateDetailView.errcode != 0)
  880. {
  881. return vacationLeaveTypes;
  882. }
  883. List<VacationItemInfo> VacationItemInfos = templateDetailView.vacation_list.item;
  884. foreach (var item in VacationItemInfos)
  885. {
  886. ValueItem valueInfo = item.name.Where(it => it.lang == "zh_CN").FirstOrDefault();
  887. if (valueInfo != null)
  888. {
  889. vacationLeaveTypes.Add(
  890. new VacationLeaveTypeView()
  891. {
  892. id = item.id,
  893. name = valueInfo.text
  894. });
  895. }
  896. }
  897. return vacationLeaveTypes;
  898. }
  899. /// <summary>
  900. /// 打卡数据
  901. /// 假勤数据 统计
  902. /// </summary>
  903. /// <param name="datas">数据源</param>
  904. /// <param name="type">
  905. /// 1-请假;2-补卡;3-出差;4-外出;100-外勤;
  906. /// </param>
  907. /// <param name="subTypeName">
  908. /// 年假 事假 病假 调休假 婚嫁 产假 陪产假 丧假 补卡次数 出差 外出数 外勤 其他
  909. /// </param>
  910. /// <returns></returns>
  911. private static int Fallibilitydispose(List<Sp_Item> datas, int type, string? subTypeName)
  912. {
  913. int num = 0;
  914. Sp_Item _Info = datas.Where(it => it.type == type && it.name == subTypeName).FirstOrDefault();
  915. if (_Info != null) { num = _Info.count; }
  916. return num;
  917. }
  918. /// <summary>
  919. /// 打卡数据
  920. /// 异常数据 统计
  921. /// </summary>
  922. /// <returns></returns>
  923. private static int ExceptionStatistics(List<Exception_Info> datas, int type)
  924. {
  925. int num = 0;
  926. Exception_Info _Info = datas.Where(it => it.exception == type).FirstOrDefault();
  927. if (_Info != null) { num = _Info.count; }
  928. return num;
  929. }
  930. /// <summary>
  931. /// 获取时间段内除周末 节假日外的 工作日
  932. /// </summary>
  933. /// <param name="startDt"></param>
  934. /// <param name="endDt"></param>
  935. /// <returns></returns>
  936. public static async Task<int> GetWorkDays(string yearMonth)
  937. {
  938. int workdays = 0;
  939. string sql = string.Format(@"Select * From Pm_WageIssueWorkingDay
  940. Where Isdel = 0 And YearMonth = '{0}' ", yearMonth);
  941. var data = await _usersRep._sqlSugar.SqlQueryable<WageYearMonthView>(sql).FirstAsync();
  942. if (data != null)
  943. {
  944. workdays = data.Workdays;
  945. }
  946. return workdays;
  947. }
  948. }
  949. }