PayrollComputation.cs 92 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688
  1. using Google.Protobuf.WellKnownTypes;
  2. using NPOI.HPSF;
  3. using NPOI.OpenXmlFormats.Dml.Diagram;
  4. using NPOI.OpenXmlFormats.Spreadsheet;
  5. using NPOI.SS.Formula.Functions;
  6. using NPOI.Util;
  7. using OASystem.API.OAMethodLib.QiYeWeChatAPI;
  8. using OASystem.Domain;
  9. using OASystem.Domain.Entities.PersonnelModule;
  10. using OASystem.Domain.ViewModels.PersonnelModule;
  11. using OASystem.Domain.ViewModels.QiYeWeChat;
  12. using OASystem.Infrastructure.Repositories.Groups;
  13. using System;
  14. using System.Collections.Generic;
  15. using System.Diagnostics.Eventing.Reader;
  16. using System.Drawing;
  17. using System.Linq.Expressions;
  18. using TencentCloud.Ocr.V20181119.Models;
  19. namespace OASystem.API.OAMethodLib
  20. {
  21. /// <summary>
  22. /// 工资计算
  23. /// </summary>
  24. public static class PayrollComputation
  25. {
  26. private static Result _result = new Result();
  27. private static readonly IQiYeWeChatApiService _qiYeWeChatApiService = AutofacIocManager.Instance.GetService<IQiYeWeChatApiService>();
  28. private static readonly UsersRepository _usersRep = AutofacIocManager.Instance.GetService<UsersRepository>();
  29. private static readonly IMapper _mapper = AutofacIocManager.Instance.GetService<IMapper>();
  30. private static readonly decimal _chengDuMinimumWage = 2100.00M * 0.80M; //员工在病假医疗期限内的病假工资按照成都市最低工资标准的 80%发放
  31. /// <summary>
  32. /// 计算工资
  33. /// </summary>
  34. /// <param name="pm_WageSheetDattaSources"></param>
  35. /// <param name="userNames"></param>
  36. /// <param name="thisYearMonth"></param>
  37. /// <param name="startDt"></param>
  38. /// <param name="endDt"></param>
  39. /// <returns></returns>
  40. public static async Task<Result> SalaryCalculatorAsync(
  41. List<Pm_WageSheet> pm_WageSheetDattaSources, List<UserNameView> userNames, int userId, string thisYearMonth, DateTime startDt, DateTime endDt)
  42. {
  43. if (pm_WageSheetDattaSources.Count <= 0)
  44. {
  45. _result.Msg = "计算工资传入数据为空!";
  46. return _result;
  47. }
  48. if (userNames.Count <= 0)
  49. {
  50. var nameData = await _usersRep.GetUserNameList(1);
  51. userNames = nameData.Data;
  52. }
  53. //计算时间段内工作日
  54. int work_days = await GetWorkDays(thisYearMonth);
  55. if (work_days <=0)
  56. {
  57. _result.Msg = thisYearMonth+" 工作日未设置,请前往《工作日管理页面》设置!";
  58. return _result;
  59. }
  60. UserIdListView userIdListView = await _qiYeWeChatApiService.GetUserIdListAsync();
  61. if (userIdListView.errcode != 0)
  62. {
  63. _result.Msg = "【企业微信】【打卡】【获取员工ID】【Msg】" + userIdListView.errmsg;
  64. return _result;
  65. }
  66. List<string> qyWhchatIdList = new List<string>();
  67. qyWhchatIdList = userIdListView.dept_user.Select(it => it.userid).ToList();
  68. CheckInDayDataView checkInDayDataView = await _qiYeWeChatApiService.GetCheckInDayDataAsync(qyWhchatIdList, startDt, endDt);
  69. if (checkInDayDataView.errcode != 0)
  70. {
  71. _result.Msg = "【企业微信】【打卡】【获取时间段内所有日打卡】【Msg】" + checkInDayDataView.errmsg;
  72. return _result;
  73. }
  74. //获取所有打卡记录 外出
  75. CheckInDataView checkInDataView = new CheckInDataView();
  76. checkInDataView = await _qiYeWeChatApiService.GetCheckinDataAsync(qyWhchatIdList, 3,startDt, endDt);
  77. if (checkInDataView.errcode != 0)
  78. {
  79. _result.Msg = "【企业微信】【打卡】【获取时间段内所有日打卡记录】【Msg】" + checkInDataView.errmsg;
  80. return _result;
  81. }
  82. //查询工作日
  83. List<Sys_Calendar> sys_Calendars = new List<Sys_Calendar>();
  84. string sys_sql = string.Format("Select * From Sys_Calendar Where Isdel = 0 And Dt between '{0}' And '{1}'",
  85. startDt.ToString("yyyy-MM-dd"), endDt.ToString("yyyy-MM-dd"));
  86. sys_Calendars = await _usersRep._sqlSugar.SqlQueryable<Sys_Calendar>(sys_sql).ToListAsync();
  87. //筛选出工作日日报
  88. List<Root> workday_userRoots = checkInDayDataView.datas.Where(it => it.base_info.day_type == 0 && it.base_info.record_type == 1).ToList();
  89. //工作日日报
  90. workday_userRoots = workday_userRoots.OrderBy(it => it.base_info.date).ToList();
  91. //获取 请假类型 Sp_Detail.template_id
  92. string leave_template_id = "C4NzTJCh1onCUK915rRkvy7Fh5Vqz4YbiEV9jrBY1";
  93. List<VacationLeaveTypeView> vacationLeaveTypes = await GetVacationLeaveTypes(leave_template_id);
  94. if (vacationLeaveTypes.Count <= 0)
  95. {
  96. _result.Msg = "【企业微信】【审批】【获取审批类型】【Msg】" + startDt + " - " + endDt + "请假 类型数据 获取失败!";
  97. return _result;
  98. }
  99. try
  100. {
  101. foreach (var pm_wsInfo in pm_WageSheetDattaSources)
  102. {
  103. string itemName = userNames.Where(it => it.Id == pm_wsInfo.UserId).FirstOrDefault().CnName;
  104. //补贴 金额
  105. decimal meal_subsidy = 0.00M; // 午餐(午餐10元/天) 补贴 * 计算方式:单日上午请假时长(小时)大于或者等于三小时 没有餐补
  106. //事假 病假 总金额
  107. decimal personalLeaveTotal = 0.00M, // 事假 日薪 *计算方式:日平均工资 = 月工资/当月应出勤天数。
  108. sickLeaveTotal = 0.00M; // 病假 日薪 *计算方式:日平均工资 = 成都市最低工资标准的80%/当月应出勤天数。 短期病假=当月15天内
  109. //扣款金额
  110. decimal beLate_deduction = 0.00M, // 迟到 扣款金额 *计算方式:
  111. // 一个自然月内,不足 10 分钟的迟到/早退,不超过 2 次的部分,不做处罚;3 次及以上,按50元 / 次处罚;
  112. // 超过 10 分钟(含 10 分钟),不足 60 分钟的迟到/早退,按 50 元/次处罚;
  113. // 超过 60 分钟(含 60 分钟),不足 3 小时的迟到/早退,且无请假者,按旷工半日处理;超过3 小时的迟到 / 早退,且无请假者,按旷工一日处理。
  114. early_deduction = 0.00M, // 早退 扣款金额
  115. absenteeism_deduction = 0.00M, // 旷工 扣款金额 *计算方式:旷工扣发当日工资
  116. unprinted_deduction = 0.00M, // 未打卡 扣款金额 *计算方式:
  117. // 试用期员工每月有 2 次 补卡机会,超过 2 次不足 5 次的部分,按 10 元 / 次处罚,5 次及以上的漏卡,按 50 元 / 次处罚;
  118. // 正式员工每月 3 次以内的补卡,按 10 元 / 次处罚,3 次及以上的漏卡,按 50 元 / 次处罚。
  119. sickLeave_deduction = 0.00M, // 病假
  120. other_deduction = 0.00M; // 其他 扣款金额
  121. decimal meal_deduction = 0.00M; // 餐补 扣款金额
  122. decimal reissuecard_deduction = 0.00M; // 补卡 扣款金额
  123. #region 计算日工资 正常日薪 事假日薪 病假日薪
  124. //月 - 应发工资
  125. decimal amountPayable = pm_wsInfo.Basic + pm_wsInfo.Floats + pm_wsInfo.PostAllowance + pm_wsInfo.InformationSecurityFee +
  126. pm_wsInfo.OtherSubsidies + pm_wsInfo.OtherHandle;
  127. // 日薪 = *计算方式:日平均工资 = 月工资/当月应出勤天数。
  128. decimal dailyWage = amountPayable / work_days;
  129. // 病假日薪 *计算方式:日平均工资 = 成都市最低工资标准的80%/当月应出勤天数。 短期病假=当月15天内
  130. decimal sickLeave_dailywage = _chengDuMinimumWage / work_days;
  131. //病假 一天扣款
  132. sickLeave_deduction = dailyWage - sickLeave_dailywage;
  133. List<Ex_Items> ex_Items = new List<Ex_Items>();//假勤 And 打卡备注集合
  134. Ex_Items ex_Items_dk = new Ex_Items() { Type = "打卡" }; //打卡
  135. Ex_Items ex_Items_jq = new Ex_Items() { Type = "假勤" }; //假勤
  136. Ex_Items ex_Items_cc = new Ex_Items() { Type = "出差" }; //出差
  137. #endregion
  138. List<Root> userRoots = new List<Root>();
  139. if (itemName == "蔡雯")
  140. {
  141. userRoots = workday_userRoots.Where(it => it.base_info.name == "蔡蔡" || it.base_info.name == "蔡雯").ToList(); //工作日日报 1-固定上下班;
  142. }
  143. else
  144. {
  145. userRoots = workday_userRoots.Where(it => it.base_info.name == itemName).ToList(); //工作日日报 1-固定上下班;
  146. }
  147. //userRoots = userRoots.Distinct().ToList();
  148. userRoots = userRoots.OrderBy(it => it.base_info.date).ToList();
  149. int dk_work_days = userRoots.Count; //应出勤天数
  150. if (dk_work_days > work_days)
  151. {
  152. dk_work_days = work_days;
  153. }
  154. meal_subsidy = dk_work_days * 10; //应发放餐补
  155. if (!itemName.Equals("张海麟"))
  156. {
  157. if (userRoots.Count <= 0)
  158. {
  159. _result.Msg = "【企业微信】【打卡】【获取打卡数据】【Msg】" + startDt + " - " + endDt + "打卡日数据 获取失败!";
  160. continue;
  161. }
  162. string acctid = userRoots[0].base_info.acctid;
  163. List<Ex_Item> ex_reissuecard_Items = new List<Ex_Item>(); //打卡类型 数据
  164. List<Sp_items> acc_sp_items = new List<Sp_items>(); //审批数据
  165. int user_probationary_bk_num = 0;
  166. decimal user_probationary_bk_decimal = pm_wsInfo.Floats; //绩效工资为0 则为试用员工
  167. //处理外出打卡记录
  168. List<CheckInDataInfo> checkInData1 = new List<CheckInDataInfo>();
  169. checkInData1 = checkInDataView.checkindata;
  170. List<CheckInDataInfo> checkInDatas = new List<CheckInDataInfo>();
  171. checkInDatas = checkInData1.Where(it => it.userid == acctid).ToList();
  172. //找出外出的打卡记录
  173. List<CheckInDataInfo> checkInData2 = new List<CheckInDataInfo>();
  174. checkInData2 = checkInDatas.Where(it => it.exception_type.Equals("未打卡")).ToList();
  175. #region 迟到 早退 旷工
  176. int user_cd_zt_num = 0; //早退/迟到 次数 10分钟内 2次以内不记处罚 三次及以上50一次
  177. foreach (var root in userRoots)
  178. {
  179. List<Holiday_infos> holiday_Infos = root.holiday_infos; //当天假勤信息
  180. List<Exception_infos> exception_infos = root.exception_infos; //当天校准状态信息
  181. List<Sp_items> sp_Items = root.sp_items;//当天假勤统计信息
  182. if (sp_Items.Count > 0)
  183. {
  184. sp_Items = sp_Items.Where(it => it.count > 0).ToList();
  185. acc_sp_items.AddRange(sp_Items);
  186. }
  187. foreach (var exception_info in exception_infos)
  188. {
  189. decimal timelength = ConvertToDecimal((Convert.ToDecimal(exception_info.duration) / 3600.00M) * 60.00M); //时长 分钟
  190. if (timelength == 9) timelength = 7.50M;
  191. int exception = exception_info.exception; //异常类型
  192. decimal day_miner_unit = dailyWage / 15; //以0.5小时为单位
  193. //1:一个自然月内,不足 10 分钟的迟到/早退,不超过 2 次的部分,不做处罚;3 次及以上,按50 元 / 次处罚;
  194. //2:超过 10 分钟(含 10 分钟),不足 60 分钟的迟到 / 早退,按 50 元 / 次处罚;
  195. //3:超过 60 分钟(含 60 分钟),不足 3 小时的迟到 / 早退,且无请假者,按旷工半日处理;超过 3 小时的迟到 / 早退,且无请假者,按旷工一日处理。
  196. long date = root.base_info.date; //当日工作日期
  197. long earliest_time = root.summary_info.earliest_time; //最早打卡时间
  198. long lastest_time = root.summary_info.lastest_time; //最晚打卡时间
  199. long this_date = date + earliest_time;
  200. DateTime thisDt = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)).AddTicks(this_date * 10000000);
  201. string thisDtStr = thisDt.ToString("yyyy-MM-dd");
  202. Ex_Item beLate_belate_ex = new Ex_Item()
  203. {
  204. SubTypeId = 4,
  205. SubType = "旷工",
  206. Duration = timelength,
  207. StartTimeDt = Convert.ToDateTime(root.base_info.dateDt.ToString("yyyy-MM-dd HH:mm:ss")),
  208. Unit = "分钟",
  209. };
  210. decimal day_deduction = 0.00M;
  211. //1 - 迟到;2 - 早退;3 - 缺卡;4 - 旷工;5 - 地点异常;6 - 设备异常
  212. if (exception == 1) //迟到
  213. {
  214. if (timelength < 10)
  215. {
  216. user_cd_zt_num++;
  217. beLate_belate_ex.SubTypeId = 1;
  218. beLate_belate_ex.SubType = "迟到";
  219. string thisStartDt = (TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)).AddTicks((date + earliest_time) * 10000000))
  220. .ToString("yyyy-MM-dd HH:mm:ss");
  221. beLate_belate_ex.StartTimeDt = Convert.ToDateTime(thisStartDt);
  222. if (user_cd_zt_num >= 3)
  223. {
  224. day_deduction = 50.00M;
  225. }
  226. else
  227. {
  228. day_deduction = 0.00M;
  229. }
  230. beLate_deduction += day_deduction; //迟到扣款 总额
  231. }
  232. else if (timelength >= 10 && timelength <= 60)
  233. {
  234. string thisStartDt = (TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1))
  235. .AddTicks((date + earliest_time) * 10000000))
  236. .ToString("yyyy-MM-dd HH:mm:ss");
  237. beLate_belate_ex.StartTimeDt = Convert.ToDateTime(thisStartDt);
  238. day_deduction = 50.00M;
  239. beLate_deduction += day_deduction; //迟到扣款 总额
  240. beLate_belate_ex.SubTypeId = 1;
  241. beLate_belate_ex.SubType = "迟到";
  242. }
  243. else if (timelength > 60 && timelength <= 180)
  244. {
  245. day_deduction = ConvertToDecimal(day_miner_unit * 6); //3小时
  246. meal_deduction += 10.00M; //餐补扣款
  247. absenteeism_deduction += day_deduction; //矿工半日
  248. beLate_belate_ex.Reason = thisDtStr + " 上午(09:00)缺卡/未打卡视为上午旷工(3小时)";
  249. }
  250. else
  251. {
  252. day_deduction = ConvertToDecimal(dailyWage);
  253. absenteeism_deduction += day_deduction; //矿工一日
  254. meal_deduction += 10.00M;
  255. beLate_belate_ex.Reason = thisDtStr + " 上午(09:00)-下午(18:00) 缺卡/未打视为旷工一天(7.5小时)";
  256. }
  257. beLate_belate_ex.Deduction = day_deduction;
  258. ex_reissuecard_Items.Add(beLate_belate_ex);
  259. }
  260. else if (exception == 2) //早退
  261. {
  262. if (timelength < 10)
  263. {
  264. user_cd_zt_num++;
  265. beLate_belate_ex.SubTypeId = 2;
  266. beLate_belate_ex.SubType = "早退";
  267. string thisEndDt = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1))
  268. .AddTicks((date + lastest_time) * 10000000)
  269. .ToString("yyyy-MM-dd HH:mm:ss");
  270. beLate_belate_ex.StartTimeDt = Convert.ToDateTime(thisEndDt);
  271. if (user_cd_zt_num >= 3)
  272. {
  273. day_deduction = 50.00M;
  274. }
  275. else
  276. {
  277. day_deduction = 0.00M;
  278. }
  279. early_deduction += day_deduction; //早退扣款 总计
  280. }
  281. else if (timelength >= 10 && timelength <= 60)
  282. {
  283. day_deduction = 50.00M;
  284. early_deduction += day_deduction; //早退扣款 总计
  285. beLate_belate_ex.SubTypeId = 2;
  286. beLate_belate_ex.SubType = "早退";
  287. string thisEndDt = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1))
  288. .AddTicks((date + lastest_time) * 10000000)
  289. .ToString("yyyy-MM-dd HH:mm:ss");
  290. beLate_belate_ex.StartTimeDt = Convert.ToDateTime(thisEndDt);
  291. }
  292. else if (timelength > 60 && timelength <= 180)
  293. {
  294. day_deduction = ConvertToDecimal(day_miner_unit * 6); //3小时
  295. meal_deduction += 10.00M;
  296. absenteeism_deduction += day_deduction; //矿工半日
  297. }
  298. else
  299. {
  300. day_deduction = ConvertToDecimal(dailyWage);
  301. meal_deduction += 10.00M;
  302. absenteeism_deduction += day_deduction; //矿工一日
  303. }
  304. beLate_belate_ex.Deduction = day_deduction;
  305. ex_reissuecard_Items.Add(beLate_belate_ex);
  306. }
  307. else if (exception == 3) //缺卡
  308. {
  309. if (root.exception_infos.Count == 2)
  310. {
  311. if (ex_reissuecard_Items.Where(it => it.StartTimeDt.ToString("yyyy-MM-dd").Equals(thisDtStr)).Count() > 0)
  312. {
  313. if (earliest_time == lastest_time)
  314. {
  315. DateTime thisDt1 = Convert.ToDateTime(thisDtStr + " 12:00");
  316. if (thisDt >= thisDt1) //旷工 下午
  317. {
  318. day_deduction = ConvertToDecimal(day_miner_unit * 9); //4.5小时
  319. meal_deduction += 10.00M;
  320. beLate_belate_ex.Duration = 270;
  321. absenteeism_deduction += day_deduction; //矿工半日
  322. beLate_belate_ex.Reason = thisDtStr + " 下午(18:00)缺卡/未打卡视为下午旷工(4.5小时)";
  323. beLate_belate_ex.Deduction = day_deduction;
  324. ex_reissuecard_Items.Add(beLate_belate_ex);
  325. }
  326. else if (thisDt <= thisDt1) //旷工 上午
  327. {
  328. day_deduction = ConvertToDecimal(day_miner_unit * 6); //3小时
  329. meal_deduction += 10.00M;
  330. absenteeism_deduction += day_deduction; //矿工半日
  331. beLate_belate_ex.Duration = 180;
  332. beLate_belate_ex.Reason = thisDtStr + " 上午(09:00)缺卡/未打卡视为上午旷工(3小时)";
  333. beLate_belate_ex.Deduction = day_deduction;
  334. ex_reissuecard_Items.Add(beLate_belate_ex);
  335. }
  336. else //矿工一日
  337. {
  338. day_deduction = ConvertToDecimal(dailyWage);
  339. meal_deduction += 10.00M;
  340. absenteeism_deduction += day_deduction;
  341. beLate_belate_ex.Reason = thisDtStr + " 上午(09:00)-下午(18:00) 缺卡/未打视为旷工一天(7.5小时)";
  342. beLate_belate_ex.Deduction = day_deduction;
  343. ex_reissuecard_Items.Add(beLate_belate_ex);
  344. }
  345. }
  346. }
  347. else
  348. {
  349. day_deduction = dailyWage;
  350. meal_deduction += 10.00M;
  351. absenteeism_deduction += day_deduction;
  352. beLate_belate_ex.Reason = "上午-下午 缺卡/未打卡为旷工 一天";
  353. beLate_belate_ex.Deduction = day_deduction;
  354. ex_reissuecard_Items.Add(beLate_belate_ex);
  355. }
  356. }
  357. else if (root.exception_infos.Count == 1)
  358. {
  359. if (earliest_time == lastest_time)
  360. {
  361. DateTime thisDt1 = Convert.ToDateTime(thisDtStr + " 12:00");
  362. if (thisDt <= thisDt1) //旷工 下午
  363. {
  364. day_deduction = ConvertToDecimal(day_miner_unit * 9); //4.5小时
  365. meal_deduction += 10.00M;
  366. beLate_belate_ex.Duration = 270;
  367. absenteeism_deduction += day_deduction; //矿工半日
  368. beLate_belate_ex.Reason = thisDtStr + " 下午(18:00)缺卡/未打卡视为下午旷工(4.5小时)";
  369. beLate_belate_ex.Deduction = day_deduction;
  370. ex_reissuecard_Items.Add(beLate_belate_ex);
  371. }
  372. else if (thisDt >= thisDt1) //旷工 上午
  373. {
  374. day_deduction = ConvertToDecimal(day_miner_unit * 6); //3小时
  375. meal_deduction += 10.00M;
  376. absenteeism_deduction += day_deduction; //矿工半日
  377. beLate_belate_ex.Duration = 180;
  378. beLate_belate_ex.Reason = thisDtStr + " 上午(09:00)缺卡/未打卡视为上午旷工(3小时)";
  379. beLate_belate_ex.Deduction = day_deduction;
  380. ex_reissuecard_Items.Add(beLate_belate_ex);
  381. }
  382. else //矿工一日
  383. {
  384. day_deduction = ConvertToDecimal(dailyWage);
  385. meal_deduction += 10.00M;
  386. absenteeism_deduction += day_deduction;
  387. beLate_belate_ex.Reason = thisDtStr + " 上午(09:00)-下午(18:00) 缺卡/未打视为旷工一天(7.5小时)";
  388. beLate_belate_ex.Deduction = day_deduction;
  389. ex_reissuecard_Items.Add(beLate_belate_ex);
  390. }
  391. }
  392. }
  393. }
  394. else if (exception == 4) //旷工
  395. {
  396. if (timelength > 60 && timelength <= 180)
  397. {
  398. day_deduction = ConvertToDecimal(day_miner_unit * 6); //3小时
  399. beLate_belate_ex.Reason = thisDtStr + " 缺卡/未打视为旷工上午(3小时)";
  400. meal_deduction += 10.00M;
  401. absenteeism_deduction += day_deduction; //矿工半日
  402. }
  403. else
  404. {
  405. day_deduction = ConvertToDecimal(dailyWage);
  406. beLate_belate_ex.Reason = thisDtStr + " 上午(09:00)-下午(18:00) 缺卡/未打视为旷工一天(7.5小时)";
  407. meal_deduction += 10.00M;
  408. absenteeism_deduction += day_deduction; //矿工一日
  409. }
  410. beLate_belate_ex.Deduction = day_deduction;
  411. ex_reissuecard_Items.Add(beLate_belate_ex);
  412. }
  413. }
  414. }
  415. #endregion
  416. #region 假勤/补卡次数 审批
  417. int leaveNum = 0; //请假次数
  418. int reissuecardNum = 0; //补卡次数
  419. int evectionNum = 0; //出差次数
  420. //类型:1 - 请假;2 - 补卡;3 - 出差;4 - 外出;100 - 外勤
  421. leaveNum = acc_sp_items.Where(it => it.type == 1).ToList().Count();
  422. reissuecardNum = acc_sp_items.Where(it => it.type == 2).ToList().Count();
  423. List<Sp_items> acc_sp_items_evection = new List<Sp_items>();
  424. acc_sp_items_evection = acc_sp_items.Where(it => it.type == 3).ToList();
  425. evectionNum = acc_sp_items_evection.Count();
  426. //请假审批
  427. if (leaveNum > 0)
  428. {
  429. List<Sp_Detail> sp_leave_details = new List<Sp_Detail>();
  430. sp_leave_details = await _qiYeWeChatApiService.GetApprovalDetailsAsync(startDt, endDt, acctid, 2, 1); //时间段内所有 已同意的 请假 审批数据
  431. if (sp_leave_details.Count <= 0)
  432. {
  433. _result.Msg += startDt + " - " + endDt + " " + itemName + " 请假 审批数据获取未获取到!\r\n";
  434. //continue;
  435. }
  436. List<Ex_Item> ex_ItemInfos = new List<Ex_Item>();
  437. List<LeaveDetails> leaveDetails = new List<LeaveDetails>();
  438. foreach (Sp_Detail sp_item in sp_leave_details)
  439. {
  440. Apply_data? apply_data = sp_item.apply_data;
  441. if (apply_data != null)
  442. {
  443. List<ContentsItem> contents = apply_data.contents;
  444. ContentsItem content_Vacation = contents.Where(it => it.control == "Vacation").FirstOrDefault(); //请假类型
  445. ContentsItem content_Textarea = contents.Where(it => it.control == "Textarea").FirstOrDefault(); //多行文本
  446. if (content_Vacation != null)
  447. {
  448. Vacation vacation = content_Vacation.value.vacation;
  449. Attendance attendance = vacation.attendance; //假勤组件
  450. Selector selector = vacation.selector; //请假类型
  451. List<OptionsItem> optionsItems = selector.options; //key 请假类型 id
  452. List<TitleItem> value = optionsItems[0].value; // value 文本描述值
  453. int leaveType = int.Parse(optionsItems[0].key); //key 请假子类型 id
  454. Date_range date_Range = attendance.date_range;
  455. //筛选 不在工作日内的假勤申请
  456. if (startDt >= date_Range.new_begin_dt || Convert.ToDateTime( date_Range.new_end_dt.ToString("yyyy-MM-dd")) > endDt)
  457. {
  458. continue;
  459. }
  460. string leave_starttime = date_Range.new_begin_dt.ToString("HH:mm");
  461. string leave_endtime = date_Range.new_end_dt.ToString("HH:mm");
  462. string typeName = string.Empty;
  463. string unit = string.Empty;
  464. int leaveTypeId = leaveType;
  465. var leaveTypeData = vacationLeaveTypes.Where(it => it.id == leaveTypeId).FirstOrDefault();
  466. if (leaveTypeData != null) { typeName = leaveTypeData.name; }
  467. string startTime = string.Empty;
  468. string endTime = string.Empty;
  469. string startTime1 = string.Empty;
  470. string endTime1 = string.Empty;
  471. Slice_info slice_info = new Slice_info();
  472. //2事假;3病假;
  473. if (leaveTypeId == 2 || leaveTypeId ==3)
  474. {
  475. slice_info = vacation.attendance.slice_info;
  476. }
  477. DateTime date_Range_new_begin_dt = date_Range.new_begin_dt;
  478. DateTime date_Range_new_end_dt = date_Range.new_end_dt;
  479. //计算请假类型扣款金额
  480. decimal new_duration = 0.00M;
  481. if (date_Range.type == "halfday")
  482. {
  483. new_duration = Convert.ToDecimal(date_Range.new_duration) / 86400.00M;
  484. unit = "天";
  485. startTime = date_Range_new_begin_dt.ToString("yyyy-MM-dd") + " 09:00";
  486. endTime = date_Range_new_end_dt.ToString("yyyy-MM-dd") + " 18:00";
  487. if (new_duration >= 0.50M)
  488. {
  489. if (slice_info != null)
  490. {
  491. if (slice_info.day_items.Count > 1)
  492. {
  493. date_Range_new_begin_dt = slice_info.day_items[0].daytimeDt;
  494. date_Range_new_end_dt = slice_info.day_items[slice_info.day_items.Count - 1].daytimeDt;
  495. decimal startTime11 = slice_info.day_items[0].duration;
  496. decimal startTime11_11 = startTime11 / 3600.00M;
  497. decimal endTime11 = slice_info.day_items[slice_info.day_items.Count - 1].duration;
  498. decimal endTime11_11 = endTime11 / 3600.00M;
  499. if (startTime11_11 == 3.00M )
  500. {
  501. startTime1 = "09:00";
  502. }else if (startTime11_11 == 4.50M)
  503. {
  504. startTime1 = "12:00";
  505. }
  506. else if (startTime11_11 == 7.50M)
  507. {
  508. startTime1 = "09:00";
  509. }
  510. if (endTime11_11 == 3.00M)
  511. {
  512. endTime1 = "12:00";
  513. }
  514. else if (endTime11_11 == 4.50M)
  515. {
  516. endTime1 = "18:00";
  517. }
  518. else if (endTime11_11 == 7.50M)
  519. {
  520. endTime1 = "18:00";
  521. }
  522. }
  523. else
  524. {
  525. decimal qjLongTime = slice_info.duration / 3600.00M;
  526. if (qjLongTime == 4.50M)
  527. {
  528. startTime1 = "12:00";
  529. endTime1 = "18:00:00";
  530. }
  531. else if (qjLongTime == 3.00M)
  532. {
  533. startTime1 = "09:00";
  534. endTime1 = "12:00:00";
  535. }
  536. }
  537. }
  538. }
  539. else
  540. {
  541. startTime1 = date_Range_new_begin_dt.ToString("HH:mm:ss");
  542. endTime1 = date_Range_new_end_dt.ToString("HH:mm:ss");
  543. }
  544. }
  545. else if (date_Range.type == "hour")
  546. {
  547. new_duration = Convert.ToDecimal(date_Range.new_duration) / 3600.00M;
  548. unit = "小时";
  549. startTime = date_Range_new_begin_dt.ToString("yyyy-MM-dd HH:mm:ss");
  550. endTime = date_Range_new_end_dt.ToString("yyyy-MM-dd HH:mm:ss");
  551. startTime1 = date_Range_new_begin_dt.ToString("HH:mm:ss");
  552. endTime1 = date_Range_new_end_dt.ToString("HH:mm:ss");
  553. }
  554. LeaveDetails leaveDetails1 = new LeaveDetails()
  555. {
  556. TypeId = leaveType,
  557. TypeName = typeName,
  558. StartDt = Convert.ToDateTime(date_Range_new_begin_dt.ToString("yyyy-MM-dd") + " " + startTime1),
  559. EndDt = Convert.ToDateTime(date_Range_new_end_dt.ToString("yyyy-MM-dd") + " " + endTime1),
  560. DtType = date_Range.type,
  561. Unit = unit,
  562. New_Duration = new_duration,
  563. SliceInfo = slice_info
  564. };
  565. leaveDetails.Add(leaveDetails1);
  566. }
  567. }
  568. }
  569. #region 年假测试数据
  570. //leaveDetails.Add(new LeaveDetails() {
  571. // TypeId = 1,
  572. // TypeName = "年假",
  573. // StartDt = Convert.ToDateTime("2023-11-21 09:00:00"),
  574. // EndDt = Convert.ToDateTime("2023-11-21 12:00:00"),
  575. // DtType = "halfday",
  576. // Unit = "天",
  577. // New_Duration = 0.50M
  578. //});
  579. //leaveDetails.Add(new LeaveDetails()
  580. //{
  581. // TypeId = 1,
  582. // TypeName = "年假",
  583. // StartDt = Convert.ToDateTime("2023-11-21 12:00:00"),
  584. // EndDt = Convert.ToDateTime("2023-11-23 18:00:00"),
  585. // DtType = "halfday",
  586. // Unit = "天",
  587. // New_Duration = 2.50M
  588. //});
  589. #endregion
  590. if (leaveDetails.Count > 0)
  591. {
  592. leaveDetails = leaveDetails.OrderBy(it => it.StartDt).OrderBy(it => it.EndDt).ToList();
  593. foreach (LeaveDetails leave_item in leaveDetails)
  594. {
  595. decimal leave_meals = 0.00M;
  596. decimal thisTypeDeduction = 0.00M;//当前类型扣款
  597. int leaveType = leave_item.TypeId;
  598. decimal new_duration = leave_item.New_Duration;
  599. //计算餐补 假勤类型扣款
  600. CalculateTypeFee(leaveDetails,leaveType, leave_item.DtType, leave_item.StartDt, leave_item.EndDt, amountPayable, work_days,
  601. new_duration,out leave_meals, out thisTypeDeduction);
  602. if (leave_meals != 0)
  603. {
  604. leave_item.IsDeduction = true;
  605. }
  606. #region 累计类型扣款
  607. //1年假;2事假;3病假;4调休假;5婚假;6产假;7陪产假;8其他;9丧假
  608. if (leaveType == 2) //事假
  609. {
  610. personalLeaveTotal += thisTypeDeduction;
  611. }
  612. else if (leaveType == 3) //病假
  613. {
  614. sickLeaveTotal += thisTypeDeduction;
  615. }
  616. #endregion
  617. meal_deduction += leave_meals;
  618. Ex_Item ex_Item = new Ex_Item()
  619. {
  620. SubTypeId = leaveType,
  621. SubType = leave_item.TypeName,
  622. StartTimeDt = leave_item.StartDt,
  623. EndTimeDt = leave_item.EndDt,
  624. Duration = new_duration,
  625. Unit = leave_item.Unit,
  626. Deduction = thisTypeDeduction,
  627. //Reason = apply_data.reason,
  628. Apply_time_dt = leave_item.ApplyDt,
  629. //Approval_name = sp_item.approval_name,
  630. };
  631. ex_ItemInfos.Add(ex_Item);
  632. }
  633. }
  634. if (ex_ItemInfos.Count > 0)
  635. {
  636. ex_Items_jq.Ex_ItemInfo = ex_ItemInfos.OrderBy(it => it.StartTimeDt).ThenBy(it => it.Apply_time_dt).ToList();
  637. ex_Items.Add(ex_Items_jq);
  638. }
  639. }
  640. //打卡补卡
  641. //补卡:员工发现自己漏打卡时,需及时提起补卡申请,并说明情况。
  642. //试用期员工每月有 2 次补卡机会,超过 2 次不足 5 次的部分,按 10 元/次处罚,5 次及以上的漏卡,按 50 元/次处罚;
  643. //正式员工每月 3 次以内的补卡,按 10 元/次处罚,3 次及以上的漏卡,按 50 元/次处罚。
  644. if (reissuecardNum > 0)
  645. {
  646. List<Sp_Detail> sp_buka_details = new List<Sp_Detail>();
  647. sp_buka_details = await _qiYeWeChatApiService.GetApprovalDetailsAsync(startDt, endDt, acctid, 2, 2); //时间段内所有 已同意的 请假 审批数据
  648. int bukaNum = 1;
  649. foreach (var item in sp_buka_details)
  650. {
  651. Apply_data? apply_data = item.apply_data;
  652. if (apply_data != null)
  653. {
  654. List<ContentsItem> contents = apply_data.contents;
  655. ContentsItem content_Vacation = contents.Where(it => it.control == "PunchCorrection").FirstOrDefault(); //请假类型
  656. ContentsItem content_Textarea = contents.Where(it => it.control == "Textarea").FirstOrDefault(); //多行文本
  657. if (content_Vacation != null)
  658. {
  659. var punch_correction = content_Vacation.value.punch_correction;
  660. DateTime bukaDt = punch_correction.time_dt;
  661. DateTime bukaDtJudge = Convert.ToDateTime(bukaDt.ToString("yyyy-MM-dd"));
  662. //筛选 不在工作日内的假勤申请
  663. if (startDt > bukaDtJudge || bukaDtJudge > endDt)
  664. {
  665. continue;
  666. }
  667. decimal bukaPrice = 0.00M;
  668. if (user_probationary_bk_decimal == 0) //计算试用员工补卡次数
  669. {
  670. if (bukaNum <= 2) bukaPrice = 0.00M;
  671. else if (bukaNum <= 4 && bukaNum > 2) bukaPrice = 10.00M;
  672. else bukaPrice = 50.00M;
  673. }
  674. else //计算正式员工补卡次数
  675. {
  676. if (bukaNum <= 2) bukaPrice = 10.00M;
  677. else bukaPrice = 50.00M;
  678. }
  679. var app_data = item.apply_data;
  680. var punch_correction1 = app_data.contents[0].value.punch_correction; //未打卡时间
  681. var punch_correction2 = app_data.contents[1].value;
  682. Ex_Item ex_reissueCard = new Ex_Item()
  683. {
  684. SubTypeId = 7,
  685. SubType = "打卡补卡",
  686. StartTimeDt = Convert.ToDateTime(punch_correction1.time_dt.ToString("yyyy-MM-dd HH:mm:ss")), //未打卡时间
  687. Deduction = bukaPrice,
  688. Reason = punch_correction2.text,
  689. Unit = string.Empty
  690. };
  691. unprinted_deduction += bukaPrice;
  692. ex_reissuecard_Items.Add(ex_reissueCard);
  693. bukaNum++;
  694. }
  695. }
  696. }
  697. //外出审批 已通过的数据 且 外出未打卡
  698. List<Sp_Detail> sp_goout_details = new List<Sp_Detail>();
  699. sp_goout_details = await _qiYeWeChatApiService.GetApprovalDetailsAsync(startDt, endDt, acctid, 2, 4); //时间段内所有 已同意的 外出 审批数据
  700. if (sp_goout_details.Count > 0)
  701. {
  702. //找出外出的具体日期
  703. List<string> goOutDts = new List<string>();
  704. foreach (var goOutItem in sp_goout_details)
  705. {
  706. Apply_data? apply_data = goOutItem.apply_data;
  707. if (apply_data != null)
  708. {
  709. List<ContentsItem> contents = apply_data.contents;
  710. ContentsItem content_Vacation = contents.Where(it => it.control == "Attendance").FirstOrDefault(); //请假类型
  711. ContentsItem content_Textarea = contents.Where(it => it.control == "Textarea").FirstOrDefault(); //多行文本
  712. if (content_Vacation != null)
  713. {
  714. var attendance = content_Vacation.value.attendance;
  715. DateTime goOutDt = attendance.date_range.new_begin_dt;
  716. DateTime goOutDtJudge = Convert.ToDateTime(goOutDt.ToString("yyyy-MM-dd"));
  717. //筛选 不在工作日内的假勤申请
  718. if (startDt >= goOutDtJudge || goOutDtJudge > endDt)
  719. {
  720. continue;
  721. }
  722. goOutDts.Add(goOutDt.ToString("yyyy-MM-dd"));
  723. }
  724. }
  725. }
  726. //处理日期范围内的数据
  727. List<CheckInDataInfo> filtratePrefix_checkInData = new List<CheckInDataInfo>();
  728. if (goOutDts.Count > 0)
  729. {
  730. foreach (var goOutDtItem in goOutDts)
  731. {
  732. List<CheckInDataInfo> filtrate_checkInData = new List<CheckInDataInfo>();
  733. filtrate_checkInData = checkInData2.Where(it => it.checkin_time_dt.ToString("yyyy-MM-dd").Equals(goOutDtItem)).ToList();
  734. if (filtrate_checkInData.Count > 0)
  735. {
  736. filtratePrefix_checkInData.AddRange(filtrate_checkInData);
  737. }
  738. }
  739. }
  740. //打卡记录里抓取的未打卡数据
  741. foreach (var item in filtratePrefix_checkInData)
  742. {
  743. decimal bukaPrice = 0.00M;
  744. if (user_probationary_bk_decimal == 0) //计算试用员工补卡次数
  745. {
  746. if (bukaNum <= 2) bukaPrice = 0.00M;
  747. else if (bukaNum <= 4 && bukaNum > 2) bukaPrice = 10.00M;
  748. else bukaPrice = 50.00M;
  749. }
  750. else //计算正式员工补卡次数
  751. {
  752. if (bukaNum <= 2) bukaPrice = 10.00M;
  753. else bukaPrice = 50.00M;
  754. }
  755. Ex_Item ex_reissueCard = new Ex_Item()
  756. {
  757. SubTypeId = 7,
  758. SubType = "打卡补卡",
  759. StartTimeDt = Convert.ToDateTime(item.checkin_time_dt.ToString("yyyy-MM-dd HH:mm:ss")), //未打卡时间
  760. Deduction = bukaPrice,
  761. Reason = "[打卡记录]抓取到的未打卡数据!",
  762. Unit = string.Empty
  763. };
  764. unprinted_deduction += bukaPrice;
  765. ex_reissuecard_Items.Add(ex_reissueCard);
  766. bukaNum++;
  767. }
  768. }
  769. }
  770. if (ex_reissuecard_Items.Count > 0)
  771. {
  772. ex_Items_dk.Ex_ItemInfo = ex_reissuecard_Items;
  773. ex_Items_dk.Ex_ItemInfo = ex_reissuecard_Items.OrderBy(it => it.SubTypeId).ThenBy(it => it.StartTimeDt).ToList();
  774. ex_Items.Add(ex_Items_dk);
  775. }
  776. //出差申请
  777. if (evectionNum > 0)
  778. {
  779. List<Sp_Detail> sp_leave_details = new List<Sp_Detail>();
  780. sp_leave_details = await _qiYeWeChatApiService.GetApprovalDetailsAsync(startDt, endDt, acctid, 2, 3); //时间段内所有 已同意的 出差 审批数据
  781. if (sp_leave_details.Count <= 0)
  782. {
  783. _result.Msg += startDt + " - " + endDt + " " + itemName + " 请假 审批数据获取未获取到!\r\n";
  784. //continue;
  785. }
  786. List<Ex_Item> cc_ex_ItemInfos = new List<Ex_Item>();
  787. foreach (Sp_Detail sp_item in sp_leave_details)
  788. {
  789. Apply_data? apply_data = sp_item.apply_data;
  790. if (apply_data != null)
  791. {
  792. List<ContentsItem> contents = apply_data.contents;
  793. ContentsItem content_Vacation = contents.Where(it => it.control == "Attendance").FirstOrDefault(); //出差类型
  794. ContentsItem content_Textarea = contents.Where(it => it.control == "Textarea").FirstOrDefault(); //多行文本
  795. if (content_Vacation != null)
  796. {
  797. //Vacation vacation = content_Vacation.value.vacation;
  798. Attendance attendance = content_Vacation.value.attendance; //假勤组件
  799. //Selector selector = vacation.selector; //请假类型
  800. //List<OptionsItem> optionsItems = selector.options; //key 请假类型 id
  801. //List<TitleItem> value = optionsItems[0].value; // value 文本描述值
  802. int leaveType = int.Parse("3"); //key 请假子类型 id
  803. Date_range date_Range = attendance.date_range;
  804. //筛选 不在工作日内的假勤申请
  805. if (startDt >= date_Range.new_begin_dt || Convert.ToDateTime(date_Range.new_end_dt.ToString("yyyy-MM-dd")) > endDt)
  806. {
  807. continue;
  808. }
  809. string leave_starttime = date_Range.new_begin_dt.ToString("HH:mm");
  810. string leave_endtime = date_Range.new_end_dt.ToString("HH:mm");
  811. string typeName = string.Empty;
  812. string unit = string.Empty;
  813. int leaveTypeId = leaveType;
  814. typeName = "出差";
  815. string startTime = string.Empty;
  816. string endTime = string.Empty;
  817. string startTime1 = string.Empty;
  818. string endTime1 = string.Empty;
  819. //计算请假类型扣款金额
  820. decimal new_duration = 0.00M;
  821. if (date_Range.type == "halfday")
  822. {
  823. new_duration = Convert.ToDecimal(date_Range.new_duration) / 86400.00M;
  824. unit = "天";
  825. startTime = date_Range.new_begin_dt.ToString("yyyy-MM-dd") + " 09:00";
  826. endTime = date_Range.new_begin_dt.ToString("yyyy-MM-dd") + " 18:00";
  827. startTime1 = "09:00:00";
  828. endTime1 = "18:00:00";
  829. }
  830. else if (date_Range.type == "hour")
  831. {
  832. new_duration = Convert.ToDecimal(date_Range.new_duration) / 3600.00M;
  833. unit = "小时";
  834. startTime = date_Range.new_begin_dt.ToString("yyyy-MM-dd HH:mm:ss");
  835. endTime = date_Range.new_end_dt.ToString("yyyy-MM-dd HH:mm:ss");
  836. startTime1 = date_Range.new_begin_dt.ToString("HH:mm:ss");
  837. endTime1 = date_Range.new_end_dt.ToString("HH:mm:ss");
  838. }
  839. //出差扣款
  840. decimal cckk = 0.00M;
  841. int days = (int)(Convert.ToDateTime(date_Range.new_end_dt.ToString("yyyy-MM-dd")) -
  842. Convert.ToDateTime(date_Range.new_begin_dt.ToString("yyyy-MM-dd"))).TotalDays + 1;
  843. for (int i = 0; i < days; i++)
  844. {
  845. DateTime thisDt = date_Range.new_begin_dt.AddDays(i);
  846. //处理开始时间 是否在当天工作时间内
  847. if (i == 0) //开始时间
  848. {
  849. string ccStartTime = thisDt.ToString("HH:mm:ss");
  850. if (!IsWorkTime(ccStartTime))
  851. {
  852. continue;
  853. }
  854. }
  855. //处理结束时间 是否在当天工作时间内
  856. if (i == days - 1)
  857. {
  858. string ccStartTime = date_Range.new_end_dt.ToString("HH:mm:ss");
  859. if (!IsWorkTime(ccStartTime))
  860. {
  861. continue;
  862. }
  863. }
  864. Sys_Calendar sys_Calendar = new Sys_Calendar();
  865. sys_Calendar = sys_Calendars.Where(it => it.Dt == thisDt.ToString("yyyy-MM-dd")).FirstOrDefault();
  866. if (sys_Calendar != null) {
  867. if (sys_Calendar.IsWorkDay)
  868. {
  869. cckk += 10.00M;
  870. }
  871. }
  872. }
  873. meal_deduction += cckk;
  874. Ex_Item ex_Item = new Ex_Item()
  875. {
  876. SubTypeId = leaveType,
  877. SubType = typeName,
  878. StartTimeDt = Convert.ToDateTime(date_Range.new_begin_dt.ToString("yyyy-MM-dd") + " " + startTime1),
  879. EndTimeDt = Convert.ToDateTime(date_Range.new_end_dt.ToString("yyyy-MM-dd") + " " + endTime1),
  880. Duration = new_duration,
  881. Unit = unit,
  882. Deduction = 0.00M,
  883. //Reason = apply_data.reason,
  884. Apply_time_dt = Convert.ToDateTime(sp_item.apply_time_dt.ToString("yyyy-MM-dd HH:mm:ss"))
  885. //Approval_name = sp_item.approval_name,
  886. };
  887. cc_ex_ItemInfos.Add(ex_Item);
  888. }
  889. }
  890. }
  891. if (cc_ex_ItemInfos.Count > 0)
  892. {
  893. //ex_Items_cc.Ex_ItemInfo = cc_ex_ItemInfos.OrderBy(it => it.StartTimeDt).ThenBy(it => it.Apply_time_dt).ToList();
  894. //ex_Items.Add(ex_Items_cc);
  895. List<Ex_Item> ex_jq_Items = new List<Ex_Item>();
  896. ex_jq_Items = (List<Ex_Item>)ex_Items_jq.Ex_ItemInfo;
  897. ex_jq_Items.AddRange(cc_ex_ItemInfos);
  898. ex_Items.Remove(ex_Items_jq);
  899. ex_Items.Add(
  900. new Ex_Items()
  901. {
  902. Type = "假勤",
  903. Ex_ItemInfo = ex_jq_Items.OrderBy(it => it.StartTimeDt).ThenBy(it => it.Apply_time_dt).ToList()
  904. }
  905. );
  906. }
  907. }
  908. #endregion
  909. }
  910. else
  911. {
  912. meal_subsidy = work_days * 10.00M;
  913. }
  914. #region 应发合计 实发合计 扣款合计(假勤扣款,其他扣款,社保扣款,公积金代扣,个税扣款)
  915. decimal mealTotal = meal_subsidy - meal_deduction; //餐补
  916. decimal salaryTotal = 0.00M;
  917. if (dk_work_days >= work_days)
  918. {
  919. dk_work_days = work_days;
  920. salaryTotal = amountPayable + mealTotal; //应发合计
  921. }
  922. else
  923. {
  924. if (itemName.Equals("张海麟"))
  925. {
  926. salaryTotal = amountPayable + mealTotal; //应发合计
  927. }
  928. else
  929. {
  930. salaryTotal = (dk_work_days * dailyWage) + mealTotal; //应发合计
  931. }
  932. }
  933. //扣款合计 不含个税
  934. decimal eductionTotal = sickLeaveTotal + personalLeaveTotal + beLate_deduction + early_deduction + absenteeism_deduction + unprinted_deduction + other_deduction +
  935. pm_wsInfo.WithholdingInsurance + pm_wsInfo.ReservedFunds + pm_wsInfo.OtherDeductions;
  936. decimal actualReleaseTotal = salaryTotal - eductionTotal; //实发合计 * 不含个税
  937. #endregion
  938. #region 处理当月工资数据
  939. pm_wsInfo.YearMonth = thisYearMonth;
  940. pm_wsInfo.StartDate = startDt.ToString("yyyy-MM-dd");
  941. pm_wsInfo.EndDate = endDt.ToString("yyyy-MM-dd");
  942. pm_wsInfo.WorkDays = work_days; //当月应出勤天数
  943. pm_wsInfo.RegularDays = dk_work_days; //当月正常出勤天数
  944. pm_wsInfo.SickLeave = sickLeaveTotal; //病假
  945. pm_wsInfo.SomethingFalse = personalLeaveTotal; //事假
  946. pm_wsInfo.LateTo = beLate_deduction; //迟到
  947. pm_wsInfo.LeaveEarly = early_deduction; //早退
  948. pm_wsInfo.Absenteeism = absenteeism_deduction; //旷工
  949. pm_wsInfo.NotPunch = unprinted_deduction; //未打卡
  950. pm_wsInfo.OtherDeductions = other_deduction; //其他
  951. pm_wsInfo.Ex_ItemsRemark = JsonConvert.SerializeObject(ex_Items); //
  952. pm_wsInfo.Mealsupplement = mealTotal; //餐补
  953. pm_wsInfo.Should = ConvertToDecimal( salaryTotal); //应发合计
  954. pm_wsInfo.TotalDeductions = ConvertToDecimal(eductionTotal); //扣款合计
  955. pm_wsInfo.TotalRealHair = ConvertToDecimal(actualReleaseTotal - pm_wsInfo.WithholdingTax); //实发合计
  956. pm_wsInfo.AfterTax = ConvertToDecimal(actualReleaseTotal - pm_wsInfo.WithholdingTax); //税后工资
  957. pm_wsInfo.LastUpdateUserId = userId;
  958. pm_wsInfo.LastUpdateDt = DateTime.Now;
  959. pm_wsInfo.CreateUserId = userId;
  960. pm_wsInfo.CreateTime = DateTime.Now;
  961. pm_wsInfo.DeleteUserId = null;
  962. pm_wsInfo.DeleteTime = null;
  963. #endregion
  964. }
  965. }
  966. catch (Exception ex)
  967. {
  968. _result.Msg = ex.Message;
  969. return _result;
  970. }
  971. _result.Code = 0;
  972. _result.Data = pm_WageSheetDattaSources;
  973. return _result;
  974. }
  975. /// <summary>
  976. /// 是否在工作时间内
  977. /// </summary>
  978. /// <param name="timeStr"></param>
  979. /// <returns></returns>
  980. public static bool IsWorkTime(string timeStr)
  981. {
  982. string thisDayWorkStartTime = "09:00:00";
  983. string thisDayWorkEndTime = "18:00:00";
  984. TimeSpan dspWorkingDayAM = DateTime.Parse(thisDayWorkStartTime).TimeOfDay;
  985. TimeSpan dspWorkingDayPM = DateTime.Parse(thisDayWorkEndTime).TimeOfDay;
  986. DateTime dt = Convert.ToDateTime(timeStr);
  987. TimeSpan dspNow = dt.TimeOfDay;
  988. if (dspNow >= dspWorkingDayAM && dspNow <= dspWorkingDayPM)
  989. {
  990. return true;
  991. }
  992. return false;
  993. }
  994. /// <summary>
  995. /// decimal 保留两位小数 不四舍五入
  996. /// </summary>
  997. /// <param name="number"></param>
  998. /// <returns></returns>
  999. public static decimal ConvertToDecimal(decimal myDecimal)
  1000. {
  1001. var subDecimal = Math.Floor(myDecimal * 100) / 100;//保留两位小数,直接截取
  1002. return subDecimal;
  1003. }
  1004. /// <summary>
  1005. /// decimal 保留两位小数 不四舍五入
  1006. /// </summary>
  1007. /// <param name="number"></param>
  1008. /// <returns></returns>
  1009. public static decimal ConvertToDecimal1(this decimal myDecimal)
  1010. {
  1011. var subDecimal = Math.Floor(myDecimal * 100) / 100;//保留两位小数,直接截取
  1012. return subDecimal;
  1013. }
  1014. /// <summary>
  1015. /// 列表的成员移动到列表的前面
  1016. /// </summary>
  1017. /// <typeparam name="T"></typeparam>
  1018. /// <param name="list"></param>
  1019. /// <param name="index"></param>
  1020. public static void MoveItemAtIndexToFront<T>(this List<T> list, int index)
  1021. {
  1022. T item = list[index];
  1023. list.RemoveAt(index);
  1024. list.Insert(0, item);
  1025. }
  1026. /// <summary>
  1027. /// 获取请假类型
  1028. /// </summary>
  1029. /// <param name="template_id"></param>
  1030. /// <returns></returns>
  1031. public static async Task<List<VacationLeaveTypeView>> GetVacationLeaveTypes(string template_id)
  1032. {
  1033. List<VacationLeaveTypeView> vacationLeaveTypes = new List<VacationLeaveTypeView>();
  1034. TemplateDetailView templateDetailView = new TemplateDetailView();
  1035. templateDetailView = await _qiYeWeChatApiService.GetTemplateDetailAsync(template_id);
  1036. if (templateDetailView.errcode != 0)
  1037. {
  1038. Serilog.Log.Error("【企业微信】【审批】【获取假勤类型的审批】【Msg】"+ templateDetailView.errmsg);
  1039. return vacationLeaveTypes;
  1040. }
  1041. List<VacationItemInfo> VacationItemInfos = templateDetailView.vacation_list.item;
  1042. foreach (var item in VacationItemInfos)
  1043. {
  1044. ValueItem valueInfo = item.name.Where(it => it.lang == "zh_CN").FirstOrDefault();
  1045. if (valueInfo != null)
  1046. {
  1047. vacationLeaveTypes.Add(
  1048. new VacationLeaveTypeView()
  1049. {
  1050. id = item.id,
  1051. name = valueInfo.text
  1052. });
  1053. }
  1054. }
  1055. return vacationLeaveTypes;
  1056. }
  1057. /// <summary>
  1058. /// 计算类型费用
  1059. /// </summary>
  1060. /// <param name="leaveType">
  1061. /// 1年假;2事假;3病假;4调休假;5婚假;6产假;7陪产假;8其他;9丧假
  1062. /// </param>
  1063. /// <param name="date_Range_type">
  1064. /// halfday 全天
  1065. /// hour 小时
  1066. /// </param>
  1067. /// <param name="startTime"></param>
  1068. /// <param name="endTime"></param>
  1069. /// <param name="duration"></param>
  1070. /// <param name="mealDeduction"></param>
  1071. /// <param name="typeDeduction"></param>
  1072. public static void CalculateTypeFee(List<LeaveDetails> leaveDetails,int leaveType, string date_Range_type, DateTime startTime, DateTime endTime,
  1073. decimal amountPayable,int work_days, decimal duration, out decimal mealDeduction, out decimal typeDeduction)
  1074. {
  1075. typeDeduction = 0;
  1076. mealDeduction = 0;
  1077. string am_starttime = "08:59";
  1078. string am_endtime = "13:01";
  1079. decimal personalkLeave_dailywage_day = amountPayable / work_days; //日薪 = 事假日薪 *计算方式:日平均工资 = 当月应发工资 /当月应出勤天数。
  1080. //半小时单位
  1081. decimal halfHour = 7.50M / 0.50M;
  1082. switch (leaveType)
  1083. {
  1084. case 1: //年假
  1085. if (date_Range_type == "halfday")
  1086. {
  1087. if (duration >= 0.5M && duration <= 1M) //一天
  1088. {
  1089. var njItem = leaveDetails.Where(it => it.StartDt.ToString("yyyy-MM-dd") == startTime.ToString("yyyy-MM-dd") &&
  1090. it.EndDt.ToString("yyyy-MM-dd") == endTime.ToString("yyyy-MM-dd")).ToList();
  1091. if (njItem.Count > 1)
  1092. {
  1093. if (njItem[0].StartDt == startTime)
  1094. {
  1095. mealDeduction = 10; //餐补扣款
  1096. }
  1097. }
  1098. else
  1099. {
  1100. mealDeduction = 10; //餐补扣款
  1101. }
  1102. }
  1103. else // 多天
  1104. {
  1105. var njManyDaysItem = leaveDetails.Where(it => it.StartDt.ToString("yyyy-MM-dd") == startTime.ToString("yyyy-MM-dd")).ToList();
  1106. if (njManyDaysItem.Count > 1)
  1107. {
  1108. var njManyDaysItem1 = njManyDaysItem.Where(it => it.StartDt != startTime).ToList();
  1109. if (njManyDaysItem1.Count > 0)
  1110. {
  1111. if (njManyDaysItem1[0].Unit.Equals("天"))
  1112. {
  1113. mealDeduction = 10 * Math.Floor(duration);
  1114. }
  1115. else if (njManyDaysItem1[0].Unit.Equals("小时") && njManyDaysItem1[0].New_Duration >= 3)
  1116. {
  1117. mealDeduction = 10 * Math.Floor(duration);
  1118. }
  1119. else
  1120. {
  1121. mealDeduction = 10 * Math.Ceiling(duration);
  1122. }
  1123. }
  1124. }
  1125. else
  1126. {
  1127. mealDeduction = 10 * Math.Ceiling(duration);
  1128. }
  1129. }
  1130. }
  1131. break;
  1132. case 2: //2事假
  1133. // 事假日薪 *计算方式:日平均工资 = 当月应发工资 /当月应出勤天数。
  1134. decimal personalkLeave_dailywage_halfhour = personalkLeave_dailywage_day / 7.50M; //事假单位 0.5小时
  1135. if (date_Range_type == "halfday")
  1136. {
  1137. mealDeduction = 10.00M * Math.Ceiling(duration); //餐补扣款
  1138. if (duration % 1 == 0) //整天
  1139. {
  1140. typeDeduction = ConvertToDecimal(personalkLeave_dailywage_day * duration);
  1141. }
  1142. else //多含 半天 另外处理
  1143. {
  1144. decimal sj_wholeDay = Math.Floor(duration); //整天
  1145. decimal sj_halfDay = duration % 1; //半天
  1146. if (sj_halfDay > 0)
  1147. {
  1148. LeaveDetails sjDetails = leaveDetails.Where(it => it.StartDt == startTime && it.EndDt == endTime).FirstOrDefault();
  1149. decimal sjPrice = 0.00M;
  1150. if (sjDetails != null)
  1151. {
  1152. Slice_info sj_slice_Info = sjDetails.SliceInfo;
  1153. decimal sjLongTime = (sj_slice_Info.duration / 3600.00M);
  1154. typeDeduction = (personalkLeave_dailywage_day / 7.50M) * sjLongTime;
  1155. }
  1156. }
  1157. else
  1158. {
  1159. typeDeduction = personalkLeave_dailywage_day* sj_wholeDay;
  1160. }
  1161. typeDeduction = ConvertToDecimal(typeDeduction);
  1162. }
  1163. }
  1164. else if (date_Range_type == "hour")
  1165. {
  1166. decimal leave_halfHour = Convert.ToDecimal(duration) / Convert.ToDecimal(0.5);
  1167. typeDeduction = ConvertToDecimal(personalkLeave_dailywage_halfhour * leave_halfHour);
  1168. //duration = 11M;
  1169. if (duration >= 3 && duration < 7.5M) //单天请假三小时
  1170. {
  1171. mealDeduction = 10; //餐补扣款
  1172. }
  1173. else if (duration >= 7.5M) //多天计算
  1174. {
  1175. decimal leave_halfHour1 = Convert.ToDecimal(duration) / Convert.ToDecimal(0.5);
  1176. decimal leaveDays = duration / 7.5M;
  1177. if (leaveDays % 1 == 0)
  1178. {
  1179. typeDeduction = ConvertToDecimal(personalkLeave_dailywage_day * leaveDays);
  1180. mealDeduction = 10 * leaveDays; //餐补扣款
  1181. }
  1182. else
  1183. {
  1184. typeDeduction = personalkLeave_dailywage_day * Convert.ToInt32(leaveDays);
  1185. decimal sy_shijiaunit = leave_halfHour1 - Convert.ToDecimal (15.00M * Convert.ToInt32(leaveDays));
  1186. if (sy_shijiaunit > 0)
  1187. {
  1188. typeDeduction += ConvertToDecimal(personalkLeave_dailywage_halfhour * sy_shijiaunit);
  1189. }
  1190. mealDeduction = 10 * Convert.ToInt32(leaveDays);
  1191. //得到最后一天的请假时间 是否有餐补
  1192. int lastHours = (Convert.ToDateTime(endTime) - Convert.ToDateTime("09:00")).Hours;
  1193. if (lastHours >= 3)
  1194. {
  1195. mealDeduction += 10; //餐补扣款
  1196. }
  1197. }
  1198. }
  1199. }
  1200. break;
  1201. case 3: //3病假
  1202. // 病假日薪 *计算方式:日平均工资 = 成都市最低工资标准的80% /当月应出勤天数。 短期病假=当月15天内
  1203. decimal chengDuMinimumWage_Day = _chengDuMinimumWage / work_days;
  1204. decimal chengDuMinimumWage_halrHour = chengDuMinimumWage_Day / 7.50M;
  1205. decimal sickLeave_dailywage_halfhour_deduction1 = (personalkLeave_dailywage_day / 7.50M) - chengDuMinimumWage_halrHour; //病假单位 0.5小时 扣款金额
  1206. if (date_Range_type == "halfday")
  1207. {
  1208. mealDeduction = 10.00M * Math.Ceiling(duration); //餐补扣款
  1209. decimal pl_dailywage_day = personalkLeave_dailywage_day - chengDuMinimumWage_Day;
  1210. if (duration % 1 == 0) //整天
  1211. {
  1212. typeDeduction = ConvertToDecimal(pl_dailywage_day * duration);
  1213. }
  1214. else //多含 半天 另外处理
  1215. {
  1216. decimal bj_wholeDay = Math.Floor(duration); //整天
  1217. decimal bj_halfDay = duration % 1; //半天
  1218. decimal bj_wholeDayWage = pl_dailywage_day * bj_wholeDay;
  1219. decimal bj_halfDayWage = 0.00M;
  1220. if (bj_halfDay > 0)
  1221. {
  1222. LeaveDetails bjDetails = leaveDetails.Where(it => it.StartDt == startTime && it.EndDt == endTime).FirstOrDefault();
  1223. decimal bjPrice = 0.00M;
  1224. if (bjDetails != null)
  1225. {
  1226. Slice_info bj_slice_Info = bjDetails.SliceInfo;
  1227. decimal bjLongTime = bj_slice_Info.duration / 3600.00M;
  1228. if (bjLongTime == 3.00M)
  1229. {
  1230. bj_halfDayWage = (pl_dailywage_day / 7.50M) * 3.00M;
  1231. }
  1232. else if (bjLongTime == 4.50M)
  1233. {
  1234. bj_halfDayWage = (pl_dailywage_day / 7.50M) * 4.50M;
  1235. }
  1236. }
  1237. }
  1238. typeDeduction = ConvertToDecimal(bj_wholeDayWage + bj_halfDayWage);
  1239. }
  1240. }
  1241. else if (date_Range_type == "hour")
  1242. {
  1243. decimal sickLeave_halfHour = duration / 0.5M;
  1244. typeDeduction = ConvertToDecimal(sickLeave_dailywage_halfhour_deduction1 * sickLeave_halfHour);
  1245. if (duration >= 3 && duration < 7.5M) //单天请假三小时 && 请假时间在上午 则没有餐补
  1246. {
  1247. mealDeduction = 10; //餐补扣款
  1248. }
  1249. else if (duration >= 7.5M) //多天计算
  1250. {
  1251. decimal sickLeave_halfHour1 = duration / 0.5M;
  1252. decimal leaveDays = Convert.ToDecimal(duration / 7.5M);
  1253. typeDeduction = ConvertToDecimal(sickLeave_dailywage_halfhour_deduction1 * sickLeave_halfHour1);
  1254. if (leaveDays % 1 == 0)
  1255. {
  1256. mealDeduction = 10 * leaveDays; //餐补扣款
  1257. }
  1258. else
  1259. {
  1260. mealDeduction = 10 * Convert.ToInt32(leaveDays);
  1261. typeDeduction = ConvertToDecimal(sickLeave_dailywage_halfhour_deduction1 * Convert.ToInt32(leaveDays));
  1262. decimal sy_bingjiaunit = sickLeave_halfHour1 - Convert.ToDecimal(15.00M * Convert.ToInt32(leaveDays));
  1263. if (sy_bingjiaunit > 0)
  1264. {
  1265. typeDeduction += ConvertToDecimal(sickLeave_dailywage_halfhour_deduction1 * sy_bingjiaunit);
  1266. }
  1267. //得到最后一天的请假时间 是否有餐补
  1268. int lastHours = (Convert.ToDateTime(endTime) - Convert.ToDateTime("09:00")).Hours;
  1269. if (lastHours >= 3)
  1270. {
  1271. mealDeduction += 10; //餐补扣款
  1272. }
  1273. }
  1274. }
  1275. }
  1276. break;
  1277. case 4: //4调休假
  1278. CalculateTypeFeeSub(leaveDetails,date_Range_type, startTime, endTime, duration, out mealDeduction);
  1279. break;
  1280. case 5: //5婚假
  1281. CalculateTypeFeeSub(leaveDetails,date_Range_type, startTime, endTime, duration, out mealDeduction);
  1282. break;
  1283. case 6: //6产假
  1284. CalculateTypeFeeSub(leaveDetails,date_Range_type, startTime, endTime, duration, out mealDeduction);
  1285. break;
  1286. case 7: //7陪产假
  1287. CalculateTypeFeeSub(leaveDetails,date_Range_type, startTime, endTime, duration, out mealDeduction);
  1288. break;
  1289. case 8: //8其他
  1290. CalculateTypeFeeSub(leaveDetails,date_Range_type, startTime, endTime, duration, out mealDeduction);
  1291. break;
  1292. case 9: //9丧假
  1293. CalculateTypeFeeSub(leaveDetails,date_Range_type, startTime, endTime, duration, out mealDeduction);
  1294. break;
  1295. }
  1296. }
  1297. /// <summary>
  1298. /// 计算类型费用
  1299. /// </summary>
  1300. /// <param name="date_Range_type">
  1301. /// halfday 全天
  1302. /// hour 小时
  1303. /// </param>
  1304. /// <param name="startTime"></param>
  1305. /// <param name="endTime"></param>
  1306. /// <param name="duration"></param>
  1307. /// <param name="mealDeduction"></param>
  1308. public static void CalculateTypeFeeSub(List<LeaveDetails> leaveDetails,string date_Range_type, DateTime startTime1, DateTime endTime1,
  1309. decimal duration, out decimal mealDeduction)
  1310. {
  1311. mealDeduction = 0;
  1312. string am_starttime = "09:00";
  1313. string am_endtime = "11:59";
  1314. string startTime = startTime1.ToString("HH:mm:ss");
  1315. string endTime = endTime1.ToString("HH:mm:ss");
  1316. if (date_Range_type == "halfday")
  1317. {
  1318. mealDeduction = 10; //餐补扣款
  1319. }
  1320. else if (date_Range_type == "hour")
  1321. {
  1322. List<LeaveDetails> leaveDetails1 = new List<LeaveDetails>();
  1323. leaveDetails1 = leaveDetails.Where(it => it.StartDt.ToString("yyyy-MM-dd").Equals(startTime1.ToString("yyyy-MM-dd")))
  1324. .OrderBy(it => it.StartDt).ToList();
  1325. if (leaveDetails1.Count > 1)
  1326. {
  1327. decimal timelenTatoal = leaveDetails1.Sum(it => it.New_Duration);
  1328. if (timelenTatoal >= 3.00M)
  1329. {
  1330. if (leaveDetails1[0].StartDt == startTime1)
  1331. {
  1332. mealDeduction = 10; //餐补扣款
  1333. }
  1334. }
  1335. }
  1336. else
  1337. {
  1338. if (duration >= 3 && duration < 7) //单天请假三小时 && 请假时间在上午 则没有餐补
  1339. {
  1340. mealDeduction = 10; //餐补扣款
  1341. }
  1342. else if (duration >= 7 && duration <= 7.50M)
  1343. {
  1344. mealDeduction = 10; //餐补扣款
  1345. }
  1346. else if (duration >= 7.50M) //多天计算
  1347. {
  1348. decimal leaveDays = Convert.ToDecimal(duration / 7.50M);
  1349. if (leaveDays % 1 == 0)
  1350. {
  1351. mealDeduction = 10 * leaveDays; //餐补扣款
  1352. }
  1353. else
  1354. {
  1355. mealDeduction = 10 * Convert.ToInt32(leaveDays);
  1356. //得到最后一天的请假时间 是否有餐补
  1357. int lastHours = (Convert.ToDateTime(endTime) - Convert.ToDateTime("09:00")).Hours;
  1358. if (lastHours >= 3)
  1359. {
  1360. mealDeduction += 10; //餐补扣款
  1361. ////处理结束时间
  1362. //if (endTime.CompareTo(am_starttime) > 0 && endTime.CompareTo(am_endtime) < 0)
  1363. //{
  1364. // mealDeduction += 10; //餐补扣款
  1365. //}
  1366. }
  1367. }
  1368. }
  1369. }
  1370. }
  1371. }
  1372. /// <summary>
  1373. /// 获取打卡补卡类型
  1374. /// </summary>
  1375. /// <param name="template_id"></param>
  1376. /// <returns></returns>
  1377. public static async Task<List<VacationLeaveTypeView>> GetVacationReissueCardTypes(string template_id)
  1378. {
  1379. List<VacationLeaveTypeView> vacationLeaveTypes = new List<VacationLeaveTypeView>();
  1380. TemplateDetailView templateDetailView = new TemplateDetailView();
  1381. templateDetailView = await _qiYeWeChatApiService.GetTemplateDetailAsync(template_id);
  1382. if (templateDetailView.errcode != 0)
  1383. {
  1384. return vacationLeaveTypes;
  1385. }
  1386. List<VacationItemInfo> VacationItemInfos = templateDetailView.vacation_list.item;
  1387. foreach (var item in VacationItemInfos)
  1388. {
  1389. ValueItem valueInfo = item.name.Where(it => it.lang == "zh_CN").FirstOrDefault();
  1390. if (valueInfo != null)
  1391. {
  1392. vacationLeaveTypes.Add(
  1393. new VacationLeaveTypeView()
  1394. {
  1395. id = item.id,
  1396. name = valueInfo.text
  1397. });
  1398. }
  1399. }
  1400. return vacationLeaveTypes;
  1401. }
  1402. /// <summary>
  1403. /// 打卡数据
  1404. /// 假勤数据 统计
  1405. /// </summary>
  1406. /// <param name="datas">数据源</param>
  1407. /// <param name="type">
  1408. /// 1-请假;2-补卡;3-出差;4-外出;100-外勤;
  1409. /// </param>
  1410. /// <param name="subTypeName">
  1411. /// 年假 事假 病假 调休假 婚嫁 产假 陪产假 丧假 补卡次数 出差 外出数 外勤 其他
  1412. /// </param>
  1413. /// <returns></returns>
  1414. private static int Fallibilitydispose(List<Sp_Item> datas, int type, string? subTypeName)
  1415. {
  1416. int num = 0;
  1417. Sp_Item _Info = datas.Where(it => it.type == type && it.name == subTypeName).FirstOrDefault();
  1418. if (_Info != null) { num = _Info.count; }
  1419. return num;
  1420. }
  1421. /// <summary>
  1422. /// 打卡数据
  1423. /// 异常数据 统计
  1424. /// </summary>
  1425. /// <returns></returns>
  1426. private static int ExceptionStatistics(List<Exception_Info> datas, int type)
  1427. {
  1428. int num = 0;
  1429. Exception_Info _Info = datas.Where(it => it.exception == type).FirstOrDefault();
  1430. if (_Info != null) { num = _Info.count; }
  1431. return num;
  1432. }
  1433. /// <summary>
  1434. /// 获取时间段内除周末 节假日外的 工作日
  1435. /// </summary>
  1436. /// <param name="startDt"></param>
  1437. /// <param name="endDt"></param>
  1438. /// <returns></returns>
  1439. public static async Task<int> GetWorkDays(string yearMonth)
  1440. {
  1441. int workdays = 0;
  1442. string sql = string.Format(@"Select * From Pm_WageIssueWorkingDay
  1443. Where Isdel = 0 And YearMonth = '{0}' ", yearMonth);
  1444. var data = await _usersRep._sqlSugar.SqlQueryable<WageYearMonthView>(sql).FirstAsync();
  1445. if (data != null)
  1446. {
  1447. workdays = data.Workdays;
  1448. }
  1449. return workdays;
  1450. }
  1451. }
  1452. }