PayrollComputation.cs 134 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393
  1. using OASystem.API.OAMethodLib.QiYeWeChatAPI;
  2. using OASystem.Domain.Entities.PersonnelModule;
  3. using OASystem.Domain.ViewModels.PersonnelModule;
  4. using OASystem.Domain.ViewModels.QiYeWeChat;
  5. namespace OASystem.API.OAMethodLib
  6. {
  7. /// <summary>
  8. /// 工资计算
  9. /// </summary>
  10. public static class PayrollComputation
  11. {
  12. private static Result _result = new Result();
  13. private static readonly IQiYeWeChatApiService _qiYeWeChatApiService = AutofacIocManager.Instance.GetService<IQiYeWeChatApiService>();
  14. private static readonly UsersRepository _usersRep = AutofacIocManager.Instance.GetService<UsersRepository>();
  15. private static readonly IMapper _mapper = AutofacIocManager.Instance.GetService<IMapper>();
  16. private static readonly decimal _chengDuMinimumWage = 2100.00M * 0.80M; //员工在病假医疗期限内的病假工资按照成都市最低工资标准的 80%发放
  17. /// <summary>
  18. /// 计算工资
  19. /// </summary>
  20. /// <param name="pm_WageSheetDattaSources"></param>
  21. /// <param name="userNames"></param>
  22. /// <param name="userId"></param>
  23. /// <param name="thisYearMonth"></param>
  24. /// <param name="startDt"></param>
  25. /// <param name="endDt"></param>
  26. /// <returns></returns>
  27. public static async Task<Result> SalaryCalculatorAsync(
  28. List<Pm_WageSheet> pm_WageSheetDattaSources, List<UserNameView> userNames, int userId, string thisYearMonth, DateTime startDt, DateTime endDt)
  29. {
  30. if (pm_WageSheetDattaSources.Count <= 0)
  31. {
  32. _result.Msg = "计算工资传入数据为空!";
  33. return _result;
  34. }
  35. //计算时间段内工作日
  36. int work_days = await GetWorkDays(thisYearMonth);
  37. if (work_days <= 0)
  38. {
  39. _result.Msg = $"{thisYearMonth} 工作日未设置,请前往《工作日管理页面》设置!";
  40. return _result;
  41. }
  42. UserIdListView userIdListView = await _qiYeWeChatApiService.GetUserIdListAsync();
  43. if (userIdListView.errcode != 0)
  44. {
  45. _result.Msg = $"【企业微信】【打卡】【获取员工ID】【Msg】{userIdListView.errmsg}";
  46. return _result;
  47. }
  48. //Task<QYWX_UserInfosView> GetUserInfosAsync()
  49. //QYWX_UserInfosView usersView = await _qiYeWeChatApiService.GetUserInfosAsync();
  50. //if (usersView.errcode != 0)
  51. //{
  52. // _result.Msg = $"【企业微信】【打卡】【获取员工基础信息】【Msg】{userIdListView.errmsg}";
  53. // return _result;
  54. //}
  55. List<string> qyWhchatIdList = new List<string>();
  56. qyWhchatIdList = userIdListView.dept_user.Select(it => it.userid ?? "").ToList();
  57. CheckInDayDataView checkInDayDataView = await _qiYeWeChatApiService.GetCheckInDayDataAsync(qyWhchatIdList, startDt, endDt);
  58. if (checkInDayDataView.errcode != 0)
  59. {
  60. _result.Msg = $"【企业微信】【打卡】【获取时间段内所有日打卡】【Msg】{checkInDayDataView.errmsg}";
  61. return _result;
  62. }
  63. //获取所有打卡记录 外出
  64. CheckInDataView checkInDataView = new CheckInDataView();
  65. checkInDataView = await _qiYeWeChatApiService.GetCheckinDataAsync(qyWhchatIdList, 3, startDt, endDt);
  66. if (checkInDataView.errcode != 0)
  67. {
  68. _result.Msg = $"【企业微信】【打卡】【获取时间段内所有日打卡记录】【Msg】{checkInDataView.errmsg}";
  69. return _result;
  70. }
  71. //查询工作日
  72. List<Sys_Calendar> sys_Calendars = new List<Sys_Calendar>();
  73. string sys_sql = string.Format("Select * From Sys_Calendar Where Isdel = 0 And Dt between '{0}' And '{1}'",
  74. startDt.ToString("yyyy-MM-dd"), endDt.ToString("yyyy-MM-dd"));
  75. sys_Calendars = await _usersRep._sqlSugar.SqlQueryable<Sys_Calendar>(sys_sql).ToListAsync();
  76. //筛选出工作日日报
  77. List<Root> workday_userRoots = checkInDayDataView.datas.Where(it => it.base_info.day_type == 0 && it.base_info.record_type == 1).ToList();
  78. //工作日日报
  79. workday_userRoots = workday_userRoots.OrderBy(it => it.base_info.date).ToList();
  80. #region 特殊日期-不用打卡日期信息
  81. //获取企业打卡规则
  82. CorpCheckInRuleView corpCheckInRole = await _qiYeWeChatApiService.GetCheckIn_CorpCheckInOptionAsync();
  83. if (corpCheckInRole.errcode != 0)
  84. {
  85. _result.Msg = $"【企业微信】【打卡】【获取企业打卡规则】【Msg】{corpCheckInRole.errmsg}";
  86. return _result;
  87. }
  88. int spe_offdays = 0;
  89. GroupItem group = corpCheckInRole.group.Where(it => it.groupid == 4).FirstOrDefault();
  90. if (group != null)
  91. {
  92. foreach (var item in group.spe_offdays)
  93. {
  94. if (item.begtime_dt >= startDt && item.endtime_dt <= endDt)
  95. {
  96. if (item.endtime_dt > startDt)
  97. {
  98. TimeSpan ts = item.endtime_dt - item.begtime_dt;
  99. spe_offdays = (ts.Days + 1);
  100. }
  101. }
  102. }
  103. }
  104. #endregion
  105. //获取 请假类型 Sp_Detail.template_id
  106. string leave_template_id = "C4NzTJCh1onCUK915rRkvy7Fh5Vqz4YbiEV9jrBY1";
  107. List<VacationLeaveTypeView> vacationLeaveTypes = await GetVacationLeaveTypes(leave_template_id);
  108. if (vacationLeaveTypes.Count <= 0)
  109. {
  110. _result.Msg = $"【企业微信】【审批】【获取审批类型】【Msg】{startDt} - {endDt}请假 类型数据 获取失败!";
  111. return _result;
  112. }
  113. string _name = "";
  114. try
  115. {
  116. #region 手动配置企业员工userid,通过userid 去匹配打卡数据
  117. //Dictionary<string, string> wx_useridDic = new Dictionary<string, string>();
  118. //wx_useridDic.Add("张海麟", "fred.chang@pan-american-intl.com");
  119. //wx_useridDic.Add("罗诗怡", "lsyyyy");
  120. //wx_useridDic.Add("赖红燕", "LaiHongYan");
  121. //wx_useridDic.Add("刘一茹", "liuyiru");
  122. //wx_useridDic.Add("李雯琪", "LiWenQi");
  123. //wx_useridDic.Add("罗聪惠", "LuoCongHui");
  124. //wx_useridDic.Add("肖俊杰", "20230410");
  125. //wx_useridDic.Add("朱成梅", "amy.zhu@pan-american-intl.com");
  126. //wx_useridDic.Add("伏虹瑾", "FuHongJin");
  127. //wx_useridDic.Add("曾艳", "judy.zeng@pan-american-intl.com");
  128. //wx_useridDic.Add("舒庆", "cilina.shu@pan-american-intl.com");
  129. //wx_useridDic.Add("高媛媛", "GaoYuanYuan");
  130. //wx_useridDic.Add("龙畑恬", "longtiantian");
  131. //wx_useridDic.Add("叶琪琪", "YeQiQi");
  132. //wx_useridDic.Add("王鸽", "ellisa.wang@pan-american-intl.com");
  133. //wx_useridDic.Add("赵雅琪", "ZhaoYaQi");
  134. //wx_useridDic.Add("陈思帆", "ChenSiFan");
  135. //wx_useridDic.Add("廖文雅", "LiaoWenYa");
  136. //wx_useridDic.Add("李敏", "annie.li@pan-american-intl.com");
  137. //wx_useridDic.Add("李明华", "LiMingHua");
  138. //wx_useridDic.Add("李文婷", "LiWenTing");
  139. //wx_useridDic.Add("仇久龙", "rf");
  140. //wx_useridDic.Add("宋夏雨", "songxiayu");
  141. //wx_useridDic.Add("王思雨", "ysw");
  142. //wx_useridDic.Add("汪燕平", "yime");
  143. //wx_useridDic.Add("张海麟", "fred.chang@pan-american-intl.com");
  144. //wx_useridDic.Add("张海麟", "fred.chang@pan-american-intl.com");
  145. //wx_useridDic.Add("张海麟", "fred.chang@pan-american-intl.com");
  146. //wx_useridDic.Add("张海麟", "fred.chang@pan-american-intl.com");
  147. //wx_useridDic.Add("张海麟", "fred.chang@pan-american-intl.com");
  148. //wx_useridDic.Add("张海麟", "fred.chang@pan-american-intl.com");
  149. //wx_useridDic.Add("张海麟", "fred.chang@pan-american-intl.com");
  150. //wx_useridDic.Add("张海麟", "fred.chang@pan-american-intl.com");
  151. //wx_useridDic.Add("张海麟", "fred.chang@pan-american-intl.com");
  152. //wx_useridDic.Add("张海麟", "fred.chang@pan-american-intl.com");
  153. //wx_useridDic.Add("张海麟", "fred.chang@pan-american-intl.com");
  154. //wx_useridDic.Add("张海麟", "fred.chang@pan-american-intl.com");
  155. //wx_useridDic.Add("张海麟", "fred.chang@pan-american-intl.com");
  156. #endregion
  157. foreach (var pm_wsInfo in pm_WageSheetDattaSources)
  158. {
  159. _name = userNames.Find(it => it.Id == pm_wsInfo.UserId)?.CnName ?? "Unknown";
  160. //补贴 金额
  161. decimal meal_subsidy = 0.00M; // 午餐(午餐10元/天) 补贴 * 计算方式:单日上午请假时长(小时)大于或者等于三小时 没有餐补
  162. //事假 病假 总金额
  163. decimal personalLeaveTotal = 0.00M, // 事假 日薪 *计算方式:日平均工资 = 月工资/当月应出勤天数。
  164. sickLeaveTotal = 0.00M; // 病假 日薪 *计算方式:日平均工资 = 成都市最低工资标准的80%/当月应出勤天数。 短期病假=当月15天内
  165. //扣款金额
  166. decimal beLate_deduction = 0.00M, // 迟到 扣款金额 *计算方式:
  167. // 一个自然月内,不足 10 分钟的迟到/早退,不超过 2 次的部分,不做处罚;3 次及以上,按50元 / 次处罚;
  168. // 超过 10 分钟(含 10 分钟),不足 60 分钟的迟到/早退,按 50 元/次处罚;
  169. // 超过 60 分钟(含 60 分钟),不足 3 小时的迟到/早退,且无请假者,按旷工半日处理;超过3 小时的迟到 / 早退,且无请假者,按旷工一日处理。
  170. early_deduction = 0.00M, // 早退 扣款金额
  171. absenteeism_deduction = 0.00M, // 旷工 扣款金额 *计算方式:旷工扣发当日工资
  172. unprinted_deduction = 0.00M, // 未打卡 扣款金额 *计算方式:
  173. // 试用期员工每月有 2 次 补卡机会,超过 2 次不足 5 次的部分,按 10 元 / 次处罚,5 次及以上的漏卡,按 50 元 / 次处罚;
  174. // 正式员工每月 3 次以内的补卡,按 10 元 / 次处罚,3 次及以上的漏卡,按 50 元 / 次处罚。
  175. sickLeave_deduction = 0.00M, // 病假
  176. other_deduction = 0.00M; // 其他 扣款金额
  177. decimal meal_deduction = 0.00M; // 餐补 扣款金额
  178. //decimal reissuecard_deduction = 0.00M; // 补卡 扣款金额
  179. #region 计算日工资 正常日薪 事假日薪 病假日薪
  180. //月 - 应发工资
  181. decimal amountPayable = pm_wsInfo.Basic + pm_wsInfo.Floats + pm_wsInfo.PostAllowance + pm_wsInfo.InformationSecurityFee +
  182. pm_wsInfo.OtherSubsidies;
  183. // 日薪 = *计算方式:日平均工资 = 月工资/当月应出勤天数。
  184. decimal dailyWage = amountPayable / work_days;
  185. // 病假日薪 *计算方式:日平均工资 = 成都市最低工资标准的80%/当月应出勤天数。 短期病假=当月15天内
  186. decimal sickLeave_dailywage = _chengDuMinimumWage / work_days;
  187. //病假 一天扣款
  188. sickLeave_deduction = dailyWage - sickLeave_dailywage;
  189. List<Ex_Items> ex_Items = new List<Ex_Items>();//假勤 And 打卡备注集合
  190. Ex_Items ex_Items_dk = new Ex_Items() { Type = "打卡" }; //打卡
  191. Ex_Items ex_Items_jq = new Ex_Items() { Type = "假勤" }; //假勤
  192. Ex_Items ex_Items_cc = new Ex_Items() { Type = "出差" }; //出差
  193. #endregion
  194. List<Root> userRoots = new List<Root>();
  195. //string wx_userid = "";
  196. if (_name == "蔡雯")
  197. {
  198. userRoots = workday_userRoots.Where(it => it.base_info.name == "蔡蔡" || it.base_info.name == "蔡雯").ToList(); //工作日日报 1-固定上下班;
  199. }
  200. else
  201. {
  202. userRoots = workday_userRoots.Where(it => it.base_info.name == _name || it.base_info.name.Contains(_name)).ToList(); //工作日日报 1-固定上下班;
  203. }
  204. //userRoots = userRoots.Distinct().ToList();
  205. userRoots = userRoots.OrderBy(it => it.base_info.date).ToList();
  206. int dk_work_days = userRoots.Count; //应出勤天数
  207. if (dk_work_days > work_days)
  208. {
  209. dk_work_days = work_days;
  210. }
  211. meal_subsidy = dk_work_days * 10; //应发放餐补
  212. if (!_name.Equals("张海麟"))
  213. {
  214. if (userRoots.Count <= 0)
  215. {
  216. _result.Msg = $"【{_name}】【企业微信】【打卡】【获取打卡数据】【Msg】{startDt} - {endDt} 打卡日数据 获取失败!";
  217. continue;
  218. }
  219. string acctid = userRoots[0].base_info.acctid;
  220. List<Ex_Item> ex_reissuecard_Items = new List<Ex_Item>(); //打卡类型 数据
  221. List<Sp_items> acc_sp_items = new List<Sp_items>(); //审批数据
  222. //int user_probationary_bk_num = 0;
  223. decimal user_probationary_bk_decimal = pm_wsInfo.Floats; //绩效工资为0 则为试用员工
  224. //处理外出打卡记录
  225. List<CheckInDataInfo> checkInData1 = new List<CheckInDataInfo>();
  226. checkInData1 = checkInDataView.checkindata;
  227. List<CheckInDataInfo> checkInDatas = new List<CheckInDataInfo>();
  228. checkInDatas = checkInData1.Where(it => it.userid == acctid).ToList();
  229. //找出外出的打卡记录
  230. List<CheckInDataInfo> checkInData2 = new List<CheckInDataInfo>();
  231. checkInData2 = checkInDatas.Where(it => it.exception_type.Equals("未打卡")).ToList();
  232. //外出打卡
  233. List<CheckInDataInfo> checkInData_outPunch = new List<CheckInDataInfo>();
  234. checkInData_outPunch = checkInDatas.Where(it => it.checkin_type.Equals("外出打卡")).ToList();
  235. #region 迟到 早退 旷工
  236. int user_cd_zt_num = 0; //早退/迟到 次数 10分钟内 2次以内不记处罚 三次及以上50一次
  237. foreach (var root in userRoots)
  238. {
  239. List<Holiday_infos> holiday_Infos = root.holiday_infos; //当天假勤信息
  240. List<Exception_infos> exception_infos = root.exception_infos; //当天校准状态信息
  241. List<Sp_items> sp_Items = root.sp_items;//当天假勤统计信息
  242. if (sp_Items.Count > 0)
  243. {
  244. sp_Items = sp_Items.Where(it => it.count > 0).ToList();
  245. acc_sp_items.AddRange(sp_Items);
  246. }
  247. foreach (var exception_info in exception_infos)
  248. {
  249. decimal timelength = ConvertToDecimal((Convert.ToDecimal(exception_info.duration) / 3600.00M) * 60.00M); //时长 分钟
  250. if (timelength == 9) timelength = 7.50M;
  251. int exception = exception_info.exception; //异常类型
  252. decimal day_miner_unit = dailyWage / 15; //以0.5小时为单位
  253. //1:一个自然月内,不足 10 分钟的迟到/早退,不超过 2 次的部分,不做处罚;3 次及以上,按50 元 / 次处罚;
  254. //2:超过 10 分钟(含 10 分钟),不足 60 分钟的迟到 / 早退,按 50 元 / 次处罚;
  255. //3:超过 60 分钟(含 60 分钟),不足 3 小时的迟到 / 早退,且无请假者,按旷工半日处理;超过 3 小时的迟到 / 早退,且无请假者,按旷工一日处理。
  256. long date = root.base_info.date; //当日工作日期
  257. long earliest_time = root.summary_info.earliest_time; //最早打卡时间
  258. long lastest_time = root.summary_info.lastest_time; //最晚打卡时间
  259. long this_date = date + earliest_time;
  260. //DateTime thisDt = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)).AddTicks(this_date * 10000000);
  261. DateTime thisDt = DateTime.MinValue.AddTicks(this_date * 10000000);
  262. string thisDtStr = thisDt.ToString("yyyy-MM-dd");
  263. Ex_Item beLate_belate_ex = new Ex_Item()
  264. {
  265. SubTypeId = 4,
  266. SubType = "旷工",
  267. Duration = timelength,
  268. StartTimeDt = Convert.ToDateTime(root.base_info.dateDt.ToString("yyyy-MM-dd HH:mm:ss")),
  269. Unit = "分钟",
  270. };
  271. decimal day_deduction = 0.00M;
  272. //1 - 迟到;2 - 早退;3 - 缺卡;4 - 旷工;5 - 地点异常;6 - 设备异常
  273. if (exception == 1) //迟到
  274. {
  275. if (timelength < 10)
  276. {
  277. user_cd_zt_num++;
  278. beLate_belate_ex.SubTypeId = 1;
  279. beLate_belate_ex.SubType = "迟到";
  280. //string thisStartDt = (TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)).AddTicks((date + earliest_time) * 10000000)).ToString("yyyy-MM-dd HH:mm:ss");
  281. string thisStartDt = DateTime.MinValue.AddTicks((date + earliest_time) * 10000000).ToString("yyyy-MM-dd HH:mm:ss");
  282. beLate_belate_ex.StartTimeDt = Convert.ToDateTime(thisStartDt);
  283. if (user_cd_zt_num >= 3)
  284. {
  285. day_deduction = 50.00M;
  286. }
  287. else
  288. {
  289. day_deduction = 0.00M;
  290. }
  291. beLate_deduction += day_deduction; //迟到扣款 总额
  292. }
  293. else if (timelength >= 10 && timelength < 60)
  294. {
  295. //string thisStartDt = (TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)).AddTicks((date + earliest_time) * 10000000)).ToString("yyyy-MM-dd HH:mm:ss");
  296. string thisStartDt = DateTime.MinValue.AddTicks((date + earliest_time) * 10000000).ToString("yyyy-MM-dd HH:mm:ss");
  297. beLate_belate_ex.StartTimeDt = Convert.ToDateTime(thisStartDt);
  298. day_deduction = 50.00M;
  299. beLate_deduction += day_deduction; //迟到扣款 总额
  300. beLate_belate_ex.SubTypeId = 1;
  301. beLate_belate_ex.SubType = "迟到";
  302. }
  303. else if (timelength >= 60 && timelength <= 180)
  304. {
  305. day_deduction = ConvertToDecimal(dailyWage / 2); //3小时 按半天计算
  306. meal_deduction += 10.00M; //餐补扣款
  307. absenteeism_deduction += day_deduction; //矿工半日
  308. beLate_belate_ex.Reason = thisDtStr + " 上午(09:00)缺卡/未打卡视为旷工半天";
  309. }
  310. else
  311. {
  312. day_deduction = ConvertToDecimal(dailyWage);
  313. absenteeism_deduction += day_deduction; //矿工一日
  314. meal_deduction += 10.00M;
  315. beLate_belate_ex.Reason = thisDtStr + " 上午(09:00)-下午(18:00) 缺卡/未打视为旷工一天(7.5小时)";
  316. }
  317. beLate_belate_ex.Deduction = day_deduction;
  318. ex_reissuecard_Items.Add(beLate_belate_ex);
  319. }
  320. else if (exception == 2) //早退
  321. {
  322. if (timelength < 10)
  323. {
  324. user_cd_zt_num++;
  325. beLate_belate_ex.SubTypeId = 2;
  326. beLate_belate_ex.SubType = "早退";
  327. //string thisEndDt = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)).AddTicks((date + lastest_time) * 10000000).ToString("yyyy-MM-dd HH:mm:ss");
  328. string thisEndDt = DateTime.MinValue.AddTicks((date + lastest_time) * 10000000).ToString("yyyy-MM-dd HH:mm:ss");
  329. beLate_belate_ex.StartTimeDt = Convert.ToDateTime(thisEndDt);
  330. if (user_cd_zt_num >= 3)
  331. {
  332. day_deduction = 50.00M;
  333. }
  334. else
  335. {
  336. day_deduction = 0.00M;
  337. }
  338. early_deduction += day_deduction; //早退扣款 总计
  339. }
  340. else if (timelength >= 10 && timelength < 60)
  341. {
  342. day_deduction = 50.00M;
  343. early_deduction += day_deduction; //早退扣款 总计
  344. beLate_belate_ex.SubTypeId = 2;
  345. beLate_belate_ex.SubType = "早退";
  346. //string thisEndDt = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)).AddTicks((date + lastest_time) * 10000000).ToString("yyyy-MM-dd HH:mm:ss");
  347. string thisEndDt = DateTime.MinValue.AddTicks((date + lastest_time) * 10000000).ToString("yyyy-MM-dd HH:mm:ss");
  348. beLate_belate_ex.StartTimeDt = Convert.ToDateTime(thisEndDt);
  349. }
  350. else if (timelength >= 60 && timelength <= 180)
  351. {
  352. day_deduction = ConvertToDecimal(dailyWage / 2); //3小时 按半天计算
  353. meal_deduction += 10.00M;
  354. absenteeism_deduction += day_deduction; //矿工半日
  355. }
  356. else
  357. {
  358. day_deduction = ConvertToDecimal(dailyWage);
  359. meal_deduction += 10.00M;
  360. absenteeism_deduction += day_deduction; //矿工一日
  361. }
  362. beLate_belate_ex.Deduction = day_deduction;
  363. ex_reissuecard_Items.Add(beLate_belate_ex);
  364. }
  365. else if (exception == 3) //缺卡
  366. {
  367. if (root.exception_infos.Count == 2)
  368. {
  369. if (ex_reissuecard_Items.Where(it => it.StartTimeDt.ToString("yyyy-MM-dd").Equals(thisDtStr)).Count() > 0)
  370. {
  371. if (earliest_time == lastest_time)
  372. {
  373. DateTime thisDt1 = Convert.ToDateTime(thisDtStr + " 12:00");
  374. if (thisDt >= thisDt1) //旷工 下午
  375. {
  376. day_deduction = ConvertToDecimal(dailyWage / 2); //4.5小时 按半天计算
  377. meal_deduction += 10.00M;
  378. beLate_belate_ex.Duration = 270;
  379. absenteeism_deduction += day_deduction; //矿工半日
  380. beLate_belate_ex.Reason = thisDtStr + " 下午(18:00)缺卡/未打卡视为旷工半天";
  381. beLate_belate_ex.Deduction = day_deduction;
  382. ex_reissuecard_Items.Add(beLate_belate_ex);
  383. }
  384. else if (thisDt <= thisDt1) //旷工 上午
  385. {
  386. day_deduction = ConvertToDecimal(dailyWage / 2); //3小时 按半天计算
  387. meal_deduction += 10.00M;
  388. absenteeism_deduction += day_deduction; //矿工半日
  389. beLate_belate_ex.Duration = 180;
  390. beLate_belate_ex.Reason = thisDtStr + " 上午(09:00)缺卡/未打卡视为旷工半天";
  391. beLate_belate_ex.Deduction = day_deduction;
  392. ex_reissuecard_Items.Add(beLate_belate_ex);
  393. }
  394. else //矿工一日
  395. {
  396. day_deduction = ConvertToDecimal(dailyWage);
  397. meal_deduction += 10.00M;
  398. absenteeism_deduction += day_deduction;
  399. beLate_belate_ex.Reason = thisDtStr + " 上午(09:00)-下午(18:00) 缺卡/未打视为旷工一天(7.5小时)";
  400. beLate_belate_ex.Deduction = day_deduction;
  401. ex_reissuecard_Items.Add(beLate_belate_ex);
  402. }
  403. }
  404. }
  405. else
  406. {
  407. day_deduction = dailyWage;
  408. meal_deduction += 10.00M;
  409. absenteeism_deduction += day_deduction;
  410. beLate_belate_ex.Reason = "上午-下午 缺卡/未打卡为旷工一天";
  411. beLate_belate_ex.Deduction = day_deduction;
  412. ex_reissuecard_Items.Add(beLate_belate_ex);
  413. }
  414. }
  415. else if (root.exception_infos.Count == 1)
  416. {
  417. if (earliest_time == lastest_time)
  418. {
  419. DateTime thisDt1 = Convert.ToDateTime(thisDtStr + " 12:00");
  420. if (thisDt <= thisDt1) //旷工 下午
  421. {
  422. day_deduction = ConvertToDecimal(dailyWage / 2); //4.5小时
  423. meal_deduction += 10.00M;
  424. beLate_belate_ex.Duration = 270;
  425. absenteeism_deduction += day_deduction; //矿工半日
  426. beLate_belate_ex.Reason = thisDtStr + " 下午(18:00)缺卡/未打卡视为下午旷工(4.5小时)";
  427. beLate_belate_ex.Deduction = day_deduction;
  428. ex_reissuecard_Items.Add(beLate_belate_ex);
  429. }
  430. else if (thisDt >= thisDt1) //旷工 上午
  431. {
  432. day_deduction = ConvertToDecimal(dailyWage / 2); //3小时
  433. meal_deduction += 10.00M;
  434. absenteeism_deduction += day_deduction; //矿工半日
  435. beLate_belate_ex.Duration = 180;
  436. beLate_belate_ex.Reason = thisDtStr + " 上午(09:00)缺卡/未打卡视为上午旷工(3小时)";
  437. beLate_belate_ex.Deduction = day_deduction;
  438. ex_reissuecard_Items.Add(beLate_belate_ex);
  439. }
  440. else //矿工一日
  441. {
  442. day_deduction = ConvertToDecimal(dailyWage);
  443. meal_deduction += 10.00M;
  444. absenteeism_deduction += day_deduction;
  445. beLate_belate_ex.Reason = thisDtStr + " 上午(09:00)-下午(18:00) 缺卡/未打视为旷工一天(7.5小时)";
  446. beLate_belate_ex.Deduction = day_deduction;
  447. ex_reissuecard_Items.Add(beLate_belate_ex);
  448. }
  449. }
  450. }
  451. }
  452. else if (exception == 4) //旷工
  453. {
  454. if (timelength >= 60 && timelength <= 180)
  455. {
  456. day_deduction = ConvertToDecimal(dailyWage / 2); //3小时
  457. beLate_belate_ex.Reason = thisDtStr + " 缺卡/未打视为旷工半天";
  458. meal_deduction += 10.00M;
  459. absenteeism_deduction += day_deduction; //矿工半日
  460. }
  461. else if (timelength > 180 && timelength <= 270)
  462. {
  463. day_deduction = ConvertToDecimal(dailyWage / 2); //3小时
  464. beLate_belate_ex.Reason = thisDtStr + " 缺卡/未打视为旷工半天";
  465. meal_deduction += 10.00M;
  466. absenteeism_deduction += day_deduction; //矿工半日
  467. }
  468. else
  469. {
  470. day_deduction = ConvertToDecimal(dailyWage);
  471. beLate_belate_ex.Reason = thisDtStr + " 上午(09:00)-下午(18:00) 缺卡/未打视为旷工一天(7.5小时)";
  472. meal_deduction += 10.00M;
  473. absenteeism_deduction += day_deduction; //矿工一日
  474. }
  475. beLate_belate_ex.Deduction = day_deduction;
  476. ex_reissuecard_Items.Add(beLate_belate_ex);
  477. }
  478. }
  479. }
  480. #endregion
  481. #region 外出打卡 迟到 早退 旷工
  482. if (checkInData_outPunch.Count > 0)
  483. {
  484. List<Sp_Detail> sp_gooutpunch_details = new List<Sp_Detail>();
  485. sp_gooutpunch_details = await _qiYeWeChatApiService.GetApprovalDetailsAsync(startDt, endDt, acctid, 2, 4); //时间段内所有 已同意的 外出打卡 审批数据
  486. if (sp_gooutpunch_details.Count <= 0)
  487. {
  488. _result.Msg += $"{_name}:{startDt} - {endDt} 外出打卡 审批数据获取未获取到!\r\n";
  489. }
  490. List<LeaveDetails> goOutPunchDetails = new List<LeaveDetails>();
  491. foreach (Sp_Detail sp_item in sp_gooutpunch_details)
  492. {
  493. Apply_data? apply_data = sp_item.apply_data;
  494. if (apply_data != null)
  495. {
  496. List<ContentsItem> contents = apply_data.contents;
  497. ContentsItem content_Attendance = contents.Where(it => it.control == "Attendance").FirstOrDefault(); //请假类型
  498. ContentsItem content_Textarea = contents.Where(it => it.control == "Textarea").FirstOrDefault(); //多行文本
  499. if (content_Attendance != null)
  500. {
  501. Attendance attendance = content_Attendance.value.attendance; //假勤组件
  502. string goOutText = string.Empty;
  503. if (content_Textarea != null)
  504. {
  505. goOutText = content_Textarea.value.text;
  506. }
  507. Date_range date_Range = attendance.date_range;
  508. //筛选 不在工作日内的假勤申请
  509. if (Convert.ToDateTime(date_Range.new_begin_dt) < startDt || Convert.ToDateTime(date_Range.new_end_dt.ToString("yyyy-MM-dd")) > endDt)
  510. {
  511. continue;
  512. }
  513. LeaveDetails leaveDetails1 = new LeaveDetails()
  514. {
  515. TypeId = 0,
  516. TypeName = "外出打卡",
  517. StartDt = date_Range.new_begin_dt,
  518. EndDt = date_Range.new_end_dt,
  519. DtType = date_Range.type,
  520. New_Duration = date_Range.new_duration
  521. };
  522. goOutPunchDetails.Add(leaveDetails1);
  523. }
  524. }
  525. }
  526. foreach (var goOutPunchItem in goOutPunchDetails)
  527. {
  528. string thisDay = goOutPunchItem.StartDt.ToString("yyyy-MM-dd");
  529. TimeSpan sp_gooutpunchStartTime = goOutPunchItem.StartDt.TimeOfDay;
  530. TimeSpan sp_gooutpunchEndTime = goOutPunchItem.EndDt.TimeOfDay;
  531. List<CheckInDataInfo> goOut_checkInDataInfos = checkInData_outPunch.Where(it => it.checkin_time_dt.ToString("yyyy-MM-dd").Equals(thisDay)).ToList();
  532. //单天
  533. if (goOut_checkInDataInfos.Count > 1)
  534. {
  535. DateTime gooutStartDt = goOut_checkInDataInfos[0].checkin_time_dt;
  536. DateTime gooutendDt = goOut_checkInDataInfos[goOut_checkInDataInfos.Count - 1].checkin_time_dt;
  537. Ex_Item beLate_belate_ex = new Ex_Item()
  538. {
  539. SubTypeId = 4,
  540. SubType = "旷工",
  541. Duration = 0,
  542. StartTimeDt = Convert.ToDateTime(goOutPunchItem.StartDt),
  543. Unit = "分钟",
  544. Reason = "数据来源【外出打卡】"
  545. };
  546. decimal day_deduction = 0.00M;
  547. //迟到
  548. if (gooutStartDt.TimeOfDay > sp_gooutpunchStartTime)
  549. {
  550. int timeLong = gooutStartDt.Subtract(goOutPunchItem.StartDt).Minutes;
  551. beLate_belate_ex.Duration = timeLong;
  552. if (timeLong > 0 && timeLong < 10)
  553. {
  554. user_cd_zt_num++;
  555. beLate_belate_ex.SubTypeId = 1;
  556. beLate_belate_ex.SubType = "迟到";
  557. if (user_cd_zt_num >= 3)
  558. {
  559. day_deduction = 50.00M;
  560. }
  561. else
  562. {
  563. day_deduction = 0.00M;
  564. }
  565. beLate_deduction += day_deduction; //迟到扣款 总额
  566. }
  567. else if (timeLong >= 10 && timeLong < 60)
  568. {
  569. day_deduction = 50.00M;
  570. beLate_deduction += day_deduction; //迟到扣款 总额
  571. beLate_belate_ex.SubTypeId = 1;
  572. beLate_belate_ex.SubType = "迟到";
  573. }
  574. else if (timeLong >= 60 && timeLong <= 180)
  575. {
  576. day_deduction = ConvertToDecimal(dailyWage / 2); //3小时 按半天计算
  577. meal_deduction += 10.00M; //餐补扣款
  578. absenteeism_deduction += day_deduction; //矿工半日
  579. beLate_belate_ex.Reason = "数据来源【外出打卡】" + thisDay + " 上午(09:00)缺卡/未打卡视为旷工半天";
  580. }
  581. else
  582. {
  583. day_deduction = ConvertToDecimal(dailyWage);
  584. absenteeism_deduction += day_deduction; //矿工一日
  585. meal_deduction += 10.00M;
  586. beLate_belate_ex.Reason = "数据来源【外出打卡】" + thisDay + " 上午(09:00)-下午(18:00) 缺卡/未打视为旷工一天(7.5小时)";
  587. }
  588. beLate_belate_ex.Deduction = day_deduction;
  589. ex_reissuecard_Items.Add(beLate_belate_ex);
  590. }
  591. //早退
  592. if (gooutendDt.TimeOfDay < sp_gooutpunchEndTime)
  593. {
  594. int timeLong = goOutPunchItem.EndDt.Subtract(gooutendDt).Minutes;
  595. beLate_belate_ex.Duration = timeLong;
  596. if (timeLong > 0 && timeLong < 10)
  597. {
  598. user_cd_zt_num++;
  599. beLate_belate_ex.SubTypeId = 1;
  600. beLate_belate_ex.SubType = "早退";
  601. if (user_cd_zt_num >= 3)
  602. {
  603. day_deduction = 50.00M;
  604. }
  605. else
  606. {
  607. day_deduction = 0.00M;
  608. }
  609. early_deduction += day_deduction; //迟到扣款 总额
  610. }
  611. else if (timeLong >= 10 && timeLong < 60)
  612. {
  613. day_deduction = 50.00M;
  614. early_deduction += day_deduction; //迟到扣款 总额
  615. beLate_belate_ex.SubTypeId = 1;
  616. beLate_belate_ex.SubType = "早退";
  617. }
  618. else if (timeLong >= 60 && timeLong <= 180)
  619. {
  620. day_deduction = ConvertToDecimal(dailyWage / 2); //3小时 按半天计算
  621. meal_deduction += 10.00M; //餐补扣款
  622. absenteeism_deduction += day_deduction; //矿工半日
  623. beLate_belate_ex.Reason = "数据来源【外出打卡】" + thisDay + " 上午(09:00)缺卡/未打卡视为旷工半天";
  624. }
  625. else
  626. {
  627. day_deduction = ConvertToDecimal(dailyWage);
  628. absenteeism_deduction += day_deduction; //矿工一日
  629. meal_deduction += 10.00M;
  630. beLate_belate_ex.Reason = "数据来源【外出打卡】" + thisDay + " 上午(09:00)-下午(18:00) 缺卡/未打视为旷工一天(7.5小时)";
  631. }
  632. beLate_belate_ex.Deduction = day_deduction;
  633. ex_reissuecard_Items.Add(beLate_belate_ex);
  634. }
  635. }
  636. //多天
  637. }
  638. }
  639. #endregion
  640. #region 迟到早团旷工 日期排序
  641. if (ex_reissuecard_Items.Count > 0)
  642. {
  643. ex_reissuecard_Items = ex_reissuecard_Items.OrderBy(it => it.StartTimeDt).ToList();
  644. }
  645. #endregion
  646. #region 假勤/补卡次数 审批
  647. int leaveNum = 0; //请假次数
  648. int reissuecardNum = 0; //补卡次数
  649. int evectionNum = 0; //出差次数
  650. //类型:1 - 请假;2 - 补卡;3 - 出差;4 - 外出;100 - 外勤
  651. leaveNum = acc_sp_items.Where(it => it.type == 1).ToList().Count();
  652. reissuecardNum = acc_sp_items.Where(it => it.type == 2).ToList().Count();
  653. List<Sp_items> acc_sp_items_evection = new List<Sp_items>();
  654. acc_sp_items_evection = acc_sp_items.Where(it => it.type == 3).ToList();
  655. evectionNum = acc_sp_items_evection.Count();
  656. //请假审批
  657. if (leaveNum > 0)
  658. {
  659. List<Sp_Detail> sp_leave_details = new List<Sp_Detail>();
  660. sp_leave_details = await _qiYeWeChatApiService.GetApprovalDetailsAsync(startDt, endDt, acctid, 2, 1); //时间段内所有 已同意的 请假 审批数据
  661. if (sp_leave_details.Count <= 0)
  662. {
  663. _result.Msg += $"{_name}: {startDt} - {endDt} 请假 审批数据获取未获取到!\r\n";
  664. //continue;
  665. }
  666. List<Ex_Item> ex_ItemInfos = new List<Ex_Item>();
  667. List<LeaveDetails> leaveDetails = new List<LeaveDetails>();
  668. foreach (Sp_Detail sp_item in sp_leave_details)
  669. {
  670. Apply_data? apply_data = sp_item.apply_data;
  671. if (apply_data != null)
  672. {
  673. List<ContentsItem> contents = apply_data.contents;
  674. ContentsItem content_Vacation = contents.Where(it => it.control == "Vacation").FirstOrDefault(); //请假类型
  675. ContentsItem content_Textarea = contents.Where(it => it.control == "Textarea").FirstOrDefault(); //多行文本
  676. if (content_Vacation != null)
  677. {
  678. Vacation vacation = content_Vacation.value.vacation;
  679. Attendance attendance = vacation.attendance; //假勤组件
  680. Selector selector = vacation.selector; //请假类型
  681. List<OptionsItem> optionsItems = selector.options; //key 请假类型 id
  682. List<TitleItem> value = optionsItems[0].value; // value 文本描述值
  683. int leaveType = int.Parse(optionsItems[0].key); //key 请假子类型 id
  684. Date_range date_Range = attendance.date_range;
  685. //筛选 不在工作日内的假勤申请
  686. //if (Convert.ToDateTime(date_Range.new_begin_dt) < startDt || Convert.ToDateTime(date_Range.new_end_dt.ToString("yyyy-MM-dd")) > endDt)
  687. //{
  688. // continue;
  689. //}
  690. //假期只要开始时间,结束时间在计算时间范围 即纳入计算
  691. if ((Convert.ToDateTime(date_Range.new_begin_dt) < startDt || Convert.ToDateTime(date_Range.new_begin_dt) > endDt) &&
  692. (Convert.ToDateTime(date_Range.new_end_dt) < startDt || Convert.ToDateTime(date_Range.new_end_dt) > endDt))
  693. {
  694. continue;
  695. }
  696. string leave_starttime = date_Range.new_begin_dt.ToString("HH:mm");
  697. string leave_endtime = date_Range.new_end_dt.ToString("HH:mm");
  698. string typeName = string.Empty;
  699. string unit = string.Empty;
  700. int leaveTypeId = leaveType;
  701. var leaveTypeData = vacationLeaveTypes.Where(it => it.id == leaveTypeId).FirstOrDefault();
  702. if (leaveTypeData != null) { typeName = leaveTypeData.name; }
  703. string startTime = string.Empty;
  704. string endTime = string.Empty;
  705. string startTime1 = string.Empty;
  706. string endTime1 = string.Empty;
  707. Slice_info slice_info = new Slice_info();
  708. //2事假;3病假;
  709. if (leaveTypeId == 2 || leaveTypeId == 3)
  710. {
  711. slice_info = vacation.attendance.slice_info;
  712. }
  713. DateTime date_Range_new_begin_dt = date_Range.new_begin_dt;
  714. DateTime date_Range_new_end_dt = date_Range.new_end_dt;
  715. //计算请假类型扣款金额
  716. decimal new_duration = 0.00M;
  717. if (date_Range.type == "halfday")
  718. {
  719. new_duration = Convert.ToDecimal(date_Range.new_duration) / 86400.00M;
  720. if (date_Range.new_begin_dt < startDt)
  721. {
  722. decimal new_duration_count = new_duration;
  723. new_duration = 0.00M;
  724. for (int i = 0; i < new_duration_count; i++)
  725. {
  726. DateTime thisDt = date_Range.new_begin_dt.AddDays(i);
  727. Sys_Calendar sys_Calendar = new Sys_Calendar();
  728. sys_Calendar = sys_Calendars.Where(it => it.Dt == thisDt.ToString("yyyy-MM-dd")).FirstOrDefault();
  729. if (sys_Calendar != null)
  730. {
  731. if (sys_Calendar.IsWorkDay)
  732. {
  733. new_duration++;
  734. }
  735. }
  736. }
  737. }
  738. unit = "天";
  739. startTime = date_Range_new_begin_dt.ToString("yyyy-MM-dd") + " 09:00";
  740. endTime = date_Range_new_end_dt.ToString("yyyy-MM-dd") + " 18:00";
  741. if (new_duration > 0.50M)
  742. {
  743. if (slice_info != null)
  744. {
  745. if (slice_info.day_items != null)
  746. {
  747. if (slice_info.day_items.Count > 1)
  748. {
  749. date_Range_new_begin_dt = slice_info.day_items[0].daytimeDt;
  750. date_Range_new_end_dt = slice_info.day_items[slice_info.day_items.Count - 1].daytimeDt;
  751. decimal startTime11 = slice_info.day_items[0].duration;
  752. decimal startTime11_11 = startTime11 / 3600.00M;
  753. decimal endTime11 = slice_info.day_items[slice_info.day_items.Count - 1].duration;
  754. decimal endTime11_11 = endTime11 / 3600.00M;
  755. if (startTime11_11 == 3.00M)
  756. {
  757. startTime1 = "09:00";
  758. }
  759. else if (startTime11_11 == 4.50M)
  760. {
  761. startTime1 = "12:00";
  762. }
  763. else if (startTime11_11 == 7.50M)
  764. {
  765. startTime1 = "09:00";
  766. }
  767. if (endTime11_11 == 3.00M)
  768. {
  769. endTime1 = "12:00";
  770. }
  771. else if (endTime11_11 == 4.50M)
  772. {
  773. endTime1 = "18:00";
  774. }
  775. else if (endTime11_11 == 7.50M)
  776. {
  777. endTime1 = "18:00";
  778. }
  779. }
  780. else
  781. {
  782. decimal qjLongTime = slice_info.duration / 3600.00M;
  783. if (qjLongTime == 4.50M)
  784. {
  785. startTime1 = "12:00";
  786. endTime1 = "18:00:00";
  787. }
  788. else if (qjLongTime == 3.00M)
  789. {
  790. startTime1 = "09:00";
  791. endTime1 = "12:00:00";
  792. }
  793. else if (qjLongTime % 7.50M == 0)
  794. {
  795. startTime1 = "09:00";
  796. endTime1 = "18:00:00";
  797. }
  798. }
  799. }
  800. else
  801. {
  802. if (new_duration % 1 == 0)
  803. {
  804. startTime1 = "09:00";
  805. endTime1 = "18:00";
  806. }
  807. }
  808. }
  809. else
  810. {
  811. if (new_duration % 1 == 0)
  812. {
  813. startTime1 = "09:00";
  814. endTime1 = "18:00";
  815. }
  816. }
  817. }
  818. else
  819. {
  820. if (new_duration % 1 == 0)
  821. {
  822. startTime1 = "09:00";
  823. endTime1 = "18:00";
  824. }
  825. else
  826. {
  827. startTime1 = date_Range_new_begin_dt.ToString("HH:mm:ss");
  828. endTime1 = date_Range_new_end_dt.ToString("HH:mm:ss");
  829. }
  830. }
  831. }
  832. else if (date_Range.type == "hour")
  833. {
  834. new_duration = Convert.ToDecimal(date_Range.new_duration) / 3600.00M;
  835. unit = "小时";
  836. startTime = date_Range_new_begin_dt.ToString("yyyy-MM-dd HH:mm:ss");
  837. endTime = date_Range_new_end_dt.ToString("yyyy-MM-dd HH:mm:ss");
  838. startTime1 = date_Range_new_begin_dt.ToString("HH:mm:ss");
  839. endTime1 = date_Range_new_end_dt.ToString("HH:mm:ss");
  840. }
  841. LeaveDetails leaveDetails1 = new LeaveDetails()
  842. {
  843. TypeId = leaveType,
  844. TypeName = typeName,
  845. StartDt = Convert.ToDateTime(date_Range_new_begin_dt.ToString("yyyy-MM-dd") + " " + startTime1),
  846. EndDt = Convert.ToDateTime(date_Range_new_end_dt.ToString("yyyy-MM-dd") + " " + endTime1),
  847. DtType = date_Range.type,
  848. Unit = unit,
  849. New_Duration = new_duration,
  850. SliceInfo = slice_info
  851. };
  852. leaveDetails.Add(leaveDetails1);
  853. }
  854. }
  855. }
  856. #region 年假测试数据
  857. //leaveDetails.Add(new LeaveDetails() {
  858. // TypeId = 1,
  859. // TypeName = "年假",
  860. // StartDt = Convert.ToDateTime("2023-11-21 09:00:00"),
  861. // EndDt = Convert.ToDateTime("2023-11-21 12:00:00"),
  862. // DtType = "halfday",
  863. // Unit = "天",
  864. // New_Duration = 0.50M
  865. //});
  866. //leaveDetails.Add(new LeaveDetails()
  867. //{
  868. // TypeId = 1,
  869. // TypeName = "年假",
  870. // StartDt = Convert.ToDateTime("2023-11-21 12:00:00"),
  871. // EndDt = Convert.ToDateTime("2023-11-23 18:00:00"),
  872. // DtType = "halfday",
  873. // Unit = "天",
  874. // New_Duration = 2.50M
  875. //});
  876. #endregion
  877. if (leaveDetails.Count > 0)
  878. {
  879. leaveDetails = leaveDetails.OrderBy(it => it.StartDt).OrderBy(it => it.EndDt).ToList();
  880. foreach (LeaveDetails leave_item in leaveDetails)
  881. {
  882. decimal leave_meals = 0.00M;
  883. decimal thisTypeDeduction = 0.00M;//当前类型扣款
  884. int leaveType = leave_item.TypeId;
  885. decimal new_duration = leave_item.New_Duration;
  886. #region 处理跨月天数
  887. if (leave_item.EndDt > endDt)
  888. {
  889. DateTime dt1 = Convert.ToDateTime(leave_item.StartDt.ToString("yyyy-MM-dd") + " 12:00");
  890. DateTime dt2 = Convert.ToDateTime(leave_item.StartDt.ToString("yyyy-MM-dd") + " 09:00");
  891. TimeSpan ts = Convert.ToDateTime(endDt.ToString("yyyy-MM-dd") + " 18:00") - Convert.ToDateTime(leave_item.StartDt.ToString("yyyy-MM-dd"));
  892. if (dt2 >= leave_item.StartDt && leave_item.StartDt <= dt1)
  893. {
  894. new_duration = ts.Days + 1;
  895. }
  896. else
  897. {
  898. new_duration = ts.Days + 1.00M + 0.50M;
  899. }
  900. }
  901. #endregion
  902. //计算餐补 假勤类型扣款
  903. CalculateTypeFee1(leaveDetails, leaveType, leave_item.DtType, leave_item.StartDt, leave_item.EndDt, amountPayable, work_days,
  904. new_duration, out leave_meals, out thisTypeDeduction);
  905. if (leave_meals != 0)
  906. {
  907. leave_item.IsDeduction = true;
  908. }
  909. #region 累计类型扣款
  910. //1年假;2事假;3病假;4调休假;5婚假;6产假;7陪产假;8其他;9丧假
  911. if (leaveType == 2) //事假
  912. {
  913. personalLeaveTotal += thisTypeDeduction;
  914. }
  915. else if (leaveType == 3) //病假
  916. {
  917. sickLeaveTotal += thisTypeDeduction;
  918. }
  919. #endregion
  920. meal_deduction += leave_meals;
  921. Ex_Item ex_Item = new Ex_Item()
  922. {
  923. SubTypeId = leaveType,
  924. SubType = leave_item.TypeName,
  925. StartTimeDt = leave_item.StartDt,
  926. EndTimeDt = leave_item.EndDt,
  927. Duration = new_duration,
  928. Unit = leave_item.Unit,
  929. Deduction = thisTypeDeduction,
  930. //Reason = apply_data.reason,
  931. Apply_time_dt = leave_item.ApplyDt,
  932. //Approval_name = sp_item.approval_name,
  933. };
  934. ex_ItemInfos.Add(ex_Item);
  935. }
  936. }
  937. if (ex_ItemInfos.Count > 0)
  938. {
  939. ex_Items_jq.Ex_ItemInfo = ex_ItemInfos.OrderBy(it => it.StartTimeDt).ThenBy(it => it.Apply_time_dt).ToList();
  940. ex_Items.Add(ex_Items_jq);
  941. }
  942. }
  943. //打卡补卡
  944. //补卡:员工发现自己漏打卡时,需及时提起补卡申请,并说明情况。
  945. //试用期员工每月有 2 次补卡机会,超过 2 次不足 5 次的部分,按 10 元/次处罚,5 次及以上的漏卡,按 50 元/次处罚;
  946. //正式员工每月 3 次以内的补卡,按 10 元/次处罚,3 次及以上的漏卡,按 50 元/次处罚。
  947. if (reissuecardNum > 0)
  948. {
  949. List<Sp_Detail> sp_buka_details = new List<Sp_Detail>();
  950. sp_buka_details = await _qiYeWeChatApiService.GetApprovalDetailsAsync(startDt, endDt, acctid, 2, 2); //时间段内所有 已同意的 请假 审批数据
  951. //外出审批 已通过的数据 且 外出未打卡
  952. List<Sp_Detail> sp_goout_details = new List<Sp_Detail>();
  953. sp_goout_details = await _qiYeWeChatApiService.GetApprovalDetailsAsync(startDt, endDt, acctid, 2, 4); //时间段内所有 已同意的 外出 审批数据
  954. //打卡记录-未打卡 处理日期范围内的数据
  955. List<CheckInDataInfo> filtratePrefix_checkInData = new List<CheckInDataInfo>();
  956. //打卡记录-未打卡 扣款
  957. if (sp_goout_details.Count > 0)
  958. {
  959. //找出外出的具体日期
  960. List<string> goOutDts = new List<string>();
  961. foreach (var goOutItem in sp_goout_details)
  962. {
  963. Apply_data? apply_data = goOutItem.apply_data;
  964. if (apply_data != null)
  965. {
  966. List<ContentsItem> contents = apply_data.contents;
  967. ContentsItem content_Vacation = contents.Where(it => it.control == "Attendance").FirstOrDefault(); //请假类型
  968. ContentsItem content_Textarea = contents.Where(it => it.control == "Textarea").FirstOrDefault(); //多行文本
  969. if (content_Vacation != null)
  970. {
  971. var attendance = content_Vacation.value.attendance;
  972. DateTime goOutDt = attendance.date_range.new_begin_dt;
  973. DateTime goOutDtJudge = Convert.ToDateTime(goOutDt.ToString("yyyy-MM-dd"));
  974. //筛选 不在工作日内的假勤申请
  975. if (startDt >= goOutDtJudge || goOutDtJudge > endDt)
  976. {
  977. continue;
  978. }
  979. goOutDts.Add(goOutDt.ToString("yyyy-MM-dd"));
  980. }
  981. }
  982. }
  983. if (goOutDts.Count > 0)
  984. {
  985. foreach (var goOutDtItem in goOutDts)
  986. {
  987. List<CheckInDataInfo> filtrate_checkInData = new List<CheckInDataInfo>();
  988. filtrate_checkInData = checkInData2.Where(it => it.checkin_time_dt.ToString("yyyy-MM-dd").Equals(goOutDtItem)).ToList();
  989. if (filtrate_checkInData.Count > 0)
  990. {
  991. filtratePrefix_checkInData.AddRange(filtrate_checkInData);
  992. }
  993. }
  994. }
  995. }
  996. int bukaNum = 1;
  997. foreach (var item in sp_buka_details)
  998. {
  999. Apply_data? apply_data = item.apply_data;
  1000. if (apply_data != null)
  1001. {
  1002. List<ContentsItem> contents = apply_data.contents;
  1003. ContentsItem content_Vacation = contents.Where(it => it.control == "PunchCorrection").FirstOrDefault(); //请假类型
  1004. ContentsItem content_Textarea = contents.Where(it => it.control == "Textarea").FirstOrDefault(); //多行文本
  1005. if (content_Vacation != null)
  1006. {
  1007. var punch_correction = content_Vacation.value.punch_correction;
  1008. DateTime bukaDt = punch_correction.time_dt;
  1009. DateTime bukaDtJudge = Convert.ToDateTime(bukaDt.ToString("yyyy-MM-dd"));
  1010. //筛选 不在工作日内的假勤申请
  1011. if (startDt > bukaDtJudge || bukaDtJudge > endDt)
  1012. {
  1013. continue;
  1014. }
  1015. decimal bukaPrice = 0.00M;
  1016. if (user_probationary_bk_decimal == 0) //计算试用员工补卡次数
  1017. {
  1018. if (bukaNum <= 2) bukaPrice = 0.00M;
  1019. else if (bukaNum <= 4 && bukaNum > 2) bukaPrice = 10.00M;
  1020. else bukaPrice = 50.00M;
  1021. }
  1022. else //计算正式员工补卡次数
  1023. {
  1024. if (bukaNum <= 2) bukaPrice = 10.00M;
  1025. else bukaPrice = 50.00M;
  1026. }
  1027. var app_data = item.apply_data;
  1028. var punch_correction1 = app_data.contents[0].value.punch_correction; //未打卡时间
  1029. var punch_correction2 = app_data.contents[1].value;
  1030. #region 处理未打卡记录表数据 已补卡的数据
  1031. if (filtratePrefix_checkInData.Count > 0)
  1032. {
  1033. var filtratePrefix_checkInItems = filtratePrefix_checkInData.Where(it => it.sch_checkin_time_dt.ToString("yyyy-MM-dd")
  1034. .Equals(punch_correction1.time_dt.ToString("yyyy-MM-dd"))).ToList();
  1035. if (filtratePrefix_checkInItems.Count > 0)
  1036. {
  1037. //按时间段移除 上午补卡时间段 09:00 - 12:00 下午补卡时间段 12:00 - 18:00
  1038. TimeSpan _strWorkingDayAM = DateTime.Parse("09:00").TimeOfDay;
  1039. TimeSpan _endWorkingDayAM = DateTime.Parse("12:00").TimeOfDay;
  1040. TimeSpan _strWorkingDayPM = DateTime.Parse("13:30").TimeOfDay;
  1041. TimeSpan _endWorkingDayPM = DateTime.Parse("18:00").TimeOfDay;
  1042. TimeSpan _dspNow = punch_correction1.time_dt.TimeOfDay;
  1043. //上午时间段 打卡记录数据
  1044. var filtratePrefix_checkInItemAMs = filtratePrefix_checkInItems.Where(it => it.sch_checkin_time_dt.TimeOfDay >= _strWorkingDayAM &&
  1045. it.sch_checkin_time_dt.TimeOfDay <= _endWorkingDayAM).ToList();
  1046. if (filtratePrefix_checkInItemAMs.Count > 0)
  1047. {
  1048. foreach (var filtratePrefix_checkInItem1 in filtratePrefix_checkInItemAMs)
  1049. {
  1050. filtratePrefix_checkInData.Remove(filtratePrefix_checkInItem1);
  1051. }
  1052. }
  1053. //下午时间段 打卡记录数据
  1054. var filtratePrefix_checkInItemPMs = filtratePrefix_checkInItems.Where(it => it.sch_checkin_time_dt.TimeOfDay >= _strWorkingDayPM &&
  1055. it.sch_checkin_time_dt.TimeOfDay <= _endWorkingDayPM).ToList();
  1056. if (filtratePrefix_checkInItemPMs.Count > 0)
  1057. {
  1058. foreach (var filtratePrefix_checkInItem1 in filtratePrefix_checkInItemPMs)
  1059. {
  1060. filtratePrefix_checkInData.Remove(filtratePrefix_checkInItem1);
  1061. }
  1062. }
  1063. }
  1064. }
  1065. #endregion
  1066. Ex_Item ex_reissueCard = new Ex_Item()
  1067. {
  1068. SubTypeId = 7,
  1069. SubType = "打卡补卡",
  1070. StartTimeDt = Convert.ToDateTime(punch_correction1.time_dt.ToString("yyyy-MM-dd HH:mm:ss")), //未打卡时间
  1071. Deduction = bukaPrice,
  1072. Reason = punch_correction2.text,
  1073. Unit = string.Empty
  1074. };
  1075. unprinted_deduction += bukaPrice;
  1076. ex_reissuecard_Items.Add(ex_reissueCard);
  1077. bukaNum++;
  1078. }
  1079. }
  1080. }
  1081. //打卡记录里抓取的未打卡数据 扣款
  1082. foreach (var item in filtratePrefix_checkInData)
  1083. {
  1084. decimal bukaPrice = 0.00M;
  1085. if (user_probationary_bk_decimal == 0) //计算试用员工补卡次数
  1086. {
  1087. if (bukaNum <= 2) bukaPrice = 0.00M;
  1088. else if (bukaNum <= 4 && bukaNum > 2) bukaPrice = 10.00M;
  1089. else bukaPrice = 50.00M;
  1090. }
  1091. else //计算正式员工补卡次数
  1092. {
  1093. if (bukaNum <= 2) bukaPrice = 10.00M;
  1094. else bukaPrice = 50.00M;
  1095. }
  1096. Ex_Item ex_reissueCard = new Ex_Item()
  1097. {
  1098. SubTypeId = 7,
  1099. SubType = "打卡补卡",
  1100. StartTimeDt = Convert.ToDateTime(item.checkin_time_dt.ToString("yyyy-MM-dd HH:mm:ss")), //未打卡时间
  1101. Deduction = bukaPrice,
  1102. Reason = "[打卡记录]抓取到的未打卡数据!",
  1103. Unit = string.Empty
  1104. };
  1105. unprinted_deduction += bukaPrice;
  1106. ex_reissuecard_Items.Add(ex_reissueCard);
  1107. bukaNum++;
  1108. }
  1109. }
  1110. if (ex_reissuecard_Items.Count > 0)
  1111. {
  1112. ex_Items_dk.Ex_ItemInfo = ex_reissuecard_Items;
  1113. ex_Items_dk.Ex_ItemInfo = ex_reissuecard_Items.OrderBy(it => it.SubTypeId).ThenBy(it => it.StartTimeDt).ToList();
  1114. ex_Items.Add(ex_Items_dk);
  1115. }
  1116. //出差申请
  1117. if (evectionNum > 0)
  1118. {
  1119. List<Sp_Detail> sp_leave_details = new List<Sp_Detail>();
  1120. sp_leave_details = await _qiYeWeChatApiService.GetApprovalDetailsAsync(startDt, endDt, acctid, 2, 3); //时间段内所有 已同意的 出差 审批数据
  1121. if (sp_leave_details.Count <= 0)
  1122. {
  1123. _result.Msg += $"{_name}: {startDt} - {endDt} 请假 审批数据获取未获取到!\r\n";
  1124. //continue;
  1125. }
  1126. List<Ex_Item> cc_ex_ItemInfos = new List<Ex_Item>();
  1127. foreach (Sp_Detail sp_item in sp_leave_details)
  1128. {
  1129. Apply_data? apply_data = sp_item.apply_data;
  1130. if (apply_data != null)
  1131. {
  1132. List<ContentsItem> contents = apply_data.contents;
  1133. ContentsItem content_Vacation = contents.Where(it => it.control == "Attendance").FirstOrDefault(); //出差类型
  1134. ContentsItem content_Textarea = contents.Where(it => it.control == "Textarea").FirstOrDefault(); //多行文本
  1135. if (content_Vacation != null)
  1136. {
  1137. //Vacation vacation = content_Vacation.value.vacation;
  1138. Attendance attendance = content_Vacation.value.attendance; //假勤组件
  1139. //Selector selector = vacation.selector; //请假类型
  1140. //List<OptionsItem> optionsItems = selector.options; //key 请假类型 id
  1141. //List<TitleItem> value = optionsItems[0].value; // value 文本描述值
  1142. int leaveType = int.Parse("3"); //key 请假子类型 id
  1143. Date_range date_Range = attendance.date_range;
  1144. //筛选 不在工作日内的假勤申请
  1145. if (date_Range.new_begin_dt < startDt || date_Range.new_end_dt > endDt)
  1146. {
  1147. continue;
  1148. }
  1149. string leave_starttime = date_Range.new_begin_dt.ToString("HH:mm");
  1150. string leave_endtime = date_Range.new_end_dt.ToString("HH:mm");
  1151. string typeName = string.Empty;
  1152. string unit = string.Empty;
  1153. int leaveTypeId = leaveType;
  1154. typeName = "出差";
  1155. string startTime = string.Empty;
  1156. string endTime = string.Empty;
  1157. string startTime1 = string.Empty;
  1158. string endTime1 = string.Empty;
  1159. //计算请假类型扣款金额
  1160. decimal new_duration = 0.00M;
  1161. if (date_Range.type == "halfday")
  1162. {
  1163. new_duration = Convert.ToDecimal(date_Range.new_duration) / 86400.00M;
  1164. unit = "天";
  1165. startTime = date_Range.new_begin_dt.ToString("yyyy-MM-dd") + " 00:00";
  1166. endTime = date_Range.new_end_dt.ToString("yyyy-MM-dd") + " 00:00";
  1167. startTime1 = "00:00:00";
  1168. endTime1 = "00:00:00";
  1169. }
  1170. else if (date_Range.type == "hour")
  1171. {
  1172. new_duration = Convert.ToDecimal(date_Range.new_duration) / 3600.00M;
  1173. unit = "小时";
  1174. startTime = date_Range.new_begin_dt.ToString("yyyy-MM-dd HH:mm:ss");
  1175. endTime = date_Range.new_end_dt.ToString("yyyy-MM-dd HH:mm:ss");
  1176. startTime1 = date_Range.new_begin_dt.ToString("HH:mm:ss");
  1177. endTime1 = date_Range.new_end_dt.ToString("HH:mm:ss");
  1178. }
  1179. //出差扣款
  1180. decimal cckk = 0.00M;
  1181. int days = (int)(Convert.ToDateTime(date_Range.new_end_dt.ToString("yyyy-MM-dd")) -
  1182. Convert.ToDateTime(date_Range.new_begin_dt.ToString("yyyy-MM-dd"))).TotalDays + 1;
  1183. for (int i = 0; i < days; i++)
  1184. {
  1185. DateTime thisDt = date_Range.new_begin_dt.AddDays(i);
  1186. //处理开始时间 是否在当天工作时间内
  1187. if (i == 0) //开始时间
  1188. {
  1189. if (!date_Range.type.Equals("halfday"))
  1190. {
  1191. string ccStartTime = thisDt.ToString("HH:mm:ss");
  1192. if (!IsWorkTime(ccStartTime))
  1193. {
  1194. continue;
  1195. }
  1196. }
  1197. }
  1198. //处理结束时间 是否在当天工作时间内
  1199. if (i == days - 1)
  1200. {
  1201. if (!date_Range.type.Equals("halfday"))
  1202. {
  1203. string ccStartTime = date_Range.new_end_dt.ToString("HH:mm:ss");
  1204. if (!IsWorkTime(ccStartTime))
  1205. {
  1206. continue;
  1207. }
  1208. }
  1209. }
  1210. Sys_Calendar sys_Calendar = new Sys_Calendar();
  1211. sys_Calendar = sys_Calendars.Where(it => it.Dt == thisDt.ToString("yyyy-MM-dd")).FirstOrDefault();
  1212. if (sys_Calendar != null)
  1213. {
  1214. if (sys_Calendar.IsWorkDay)
  1215. {
  1216. cckk += 10.00M;
  1217. }
  1218. }
  1219. }
  1220. meal_deduction += cckk;
  1221. Ex_Item ex_Item = new Ex_Item()
  1222. {
  1223. SubTypeId = leaveType,
  1224. SubType = typeName,
  1225. StartTimeDt = Convert.ToDateTime(date_Range.new_begin_dt.ToString("yyyy-MM-dd") + " " + startTime1),
  1226. EndTimeDt = Convert.ToDateTime(date_Range.new_end_dt.ToString("yyyy-MM-dd") + " " + endTime1),
  1227. Duration = new_duration,
  1228. Unit = unit,
  1229. Deduction = 0.00M,
  1230. //Reason = apply_data.reason,
  1231. Apply_time_dt = Convert.ToDateTime(sp_item.apply_time_dt.ToString("yyyy-MM-dd HH:mm:ss"))
  1232. //Approval_name = sp_item.approval_name,
  1233. };
  1234. cc_ex_ItemInfos.Add(ex_Item);
  1235. }
  1236. }
  1237. }
  1238. if (cc_ex_ItemInfos.Count > 0)
  1239. {
  1240. //ex_Items_cc.Ex_ItemInfo = cc_ex_ItemInfos.OrderBy(it => it.StartTimeDt).ThenBy(it => it.Apply_time_dt).ToList();
  1241. //;
  1242. //ex_Items.Add(ex_Items_cc);
  1243. List<Ex_Item> ex_jq_Items = new List<Ex_Item>();
  1244. List<Ex_Item> ex_Items1 = new List<Ex_Item>();
  1245. ex_Items1 = (List<Ex_Item>)ex_Items_jq.Ex_ItemInfo;
  1246. if (ex_Items1 != null && ex_Items1.Count > 0)
  1247. {
  1248. ex_jq_Items = ex_Items1;
  1249. }
  1250. ex_jq_Items.AddRange(cc_ex_ItemInfos);
  1251. ex_Items.Remove(ex_Items_jq);
  1252. ex_Items.Add(
  1253. new Ex_Items()
  1254. {
  1255. Type = "假勤",
  1256. Ex_ItemInfo = ex_jq_Items.OrderBy(it => it.StartTimeDt).ThenBy(it => it.Apply_time_dt).ToList()
  1257. }
  1258. );
  1259. }
  1260. }
  1261. #endregion
  1262. }
  1263. else
  1264. {
  1265. meal_subsidy = work_days * 10.00M;
  1266. }
  1267. #region 应发合计 实发合计 扣款合计(假勤扣款,其他扣款,社保扣款,公积金代扣,个税扣款)
  1268. int workDays = dk_work_days + spe_offdays;
  1269. decimal mealTotal = meal_subsidy - meal_deduction; //餐补
  1270. decimal salaryTotal = 0.00M;
  1271. if (dk_work_days >= work_days)
  1272. {
  1273. dk_work_days = work_days;
  1274. salaryTotal = amountPayable + mealTotal + pm_wsInfo.OtherHandle; //应发合计
  1275. }
  1276. else
  1277. {
  1278. if (_name.Equals("张海麟"))
  1279. {
  1280. salaryTotal = amountPayable + mealTotal + pm_wsInfo.OtherHandle; //应发合计
  1281. }
  1282. else
  1283. {
  1284. salaryTotal = (workDays * dailyWage) + mealTotal + pm_wsInfo.OtherHandle; //应发合计
  1285. }
  1286. }
  1287. //扣款合计 不含个税
  1288. decimal eductionTotal = sickLeaveTotal + personalLeaveTotal + beLate_deduction + early_deduction + absenteeism_deduction + unprinted_deduction + other_deduction +
  1289. pm_wsInfo.WithholdingInsurance + pm_wsInfo.ReservedFunds + pm_wsInfo.OtherDeductions;
  1290. decimal actualReleaseTotal = salaryTotal - eductionTotal; //实发合计 * 不含个税
  1291. #endregion
  1292. #region 处理当月工资数据
  1293. pm_wsInfo.YearMonth = thisYearMonth;
  1294. pm_wsInfo.StartDate = startDt.ToString("yyyy-MM-dd");
  1295. pm_wsInfo.EndDate = endDt.ToString("yyyy-MM-dd");
  1296. pm_wsInfo.WorkDays = work_days; //当月应出勤天数
  1297. pm_wsInfo.RegularDays = workDays; //当月正常出勤天数
  1298. pm_wsInfo.SickLeave = sickLeaveTotal; //病假
  1299. pm_wsInfo.SomethingFalse = personalLeaveTotal; //事假
  1300. pm_wsInfo.LateTo = beLate_deduction; //迟到
  1301. pm_wsInfo.LeaveEarly = early_deduction; //早退
  1302. pm_wsInfo.Absenteeism = absenteeism_deduction; //旷工
  1303. pm_wsInfo.NotPunch = unprinted_deduction; //未打卡
  1304. pm_wsInfo.OtherDeductions = other_deduction; //其他
  1305. pm_wsInfo.Ex_ItemsRemark = JsonConvert.SerializeObject(ex_Items); //
  1306. pm_wsInfo.Mealsupplement = mealTotal; //餐补
  1307. pm_wsInfo.Should = ConvertToDecimal(salaryTotal); //应发合计
  1308. pm_wsInfo.TotalDeductions = ConvertToDecimal(eductionTotal); //扣款合计
  1309. pm_wsInfo.TotalRealHair = ConvertToDecimal(actualReleaseTotal - pm_wsInfo.WithholdingTax); //实发合计
  1310. pm_wsInfo.AfterTax = ConvertToDecimal(actualReleaseTotal - pm_wsInfo.WithholdingTax); //税后工资
  1311. pm_wsInfo.LastUpdateUserId = userId;
  1312. pm_wsInfo.LastUpdateDt = DateTime.Now;
  1313. pm_wsInfo.CreateUserId = userId;
  1314. pm_wsInfo.CreateTime = DateTime.Now;
  1315. pm_wsInfo.DeleteUserId = null;
  1316. pm_wsInfo.DeleteTime = string.Empty;
  1317. #endregion
  1318. }
  1319. }
  1320. catch (Exception ex)
  1321. {
  1322. _result.Msg = $"【{_name}】【Msg:{ex.Message}】";
  1323. return _result;
  1324. }
  1325. _result.Code = 0;
  1326. _result.Data = pm_WageSheetDattaSources;
  1327. return _result;
  1328. }
  1329. /// <summary>
  1330. /// 是否在工作时间内
  1331. /// </summary>
  1332. /// <param name="timeStr"></param>
  1333. /// <returns></returns>
  1334. public static bool IsWorkTime(string timeStr)
  1335. {
  1336. string thisDayWorkStartTime = "09:00:00";
  1337. string thisDayWorkEndTime = "18:00:00";
  1338. TimeSpan dspWorkingDayAM = DateTime.Parse(thisDayWorkStartTime).TimeOfDay;
  1339. TimeSpan dspWorkingDayPM = DateTime.Parse(thisDayWorkEndTime).TimeOfDay;
  1340. DateTime dt = Convert.ToDateTime(timeStr);
  1341. TimeSpan dspNow = dt.TimeOfDay;
  1342. if (dspNow >= dspWorkingDayAM && dspNow <= dspWorkingDayPM)
  1343. {
  1344. return true;
  1345. }
  1346. return false;
  1347. }
  1348. /// <summary>
  1349. /// decimal 保留两位小数 不四舍五入
  1350. /// </summary>
  1351. /// <param name="myDecimal"></param>
  1352. /// <returns></returns>
  1353. public static decimal ConvertToDecimal(decimal myDecimal)
  1354. {
  1355. var subDecimal = Math.Floor(myDecimal * 100) / 100;//保留两位小数,直接截取
  1356. return subDecimal;
  1357. }
  1358. /// <summary>
  1359. /// decimal 保留两位小数 不四舍五入
  1360. /// </summary>
  1361. /// <param name="myDecimal"></param>
  1362. /// <returns></returns>
  1363. public static decimal ConvertToDecimal1(this decimal myDecimal)
  1364. {
  1365. var subDecimal = Math.Floor(myDecimal * 100) / 100;//保留两位小数,直接截取
  1366. return subDecimal;
  1367. }
  1368. /// <summary>
  1369. /// 列表的成员移动到列表的前面
  1370. /// </summary>
  1371. /// <typeparam name="T"></typeparam>
  1372. /// <param name="list"></param>
  1373. /// <param name="index"></param>
  1374. public static void MoveItemAtIndexToFront<T>(this List<T> list, int index)
  1375. {
  1376. T item = list[index];
  1377. list.RemoveAt(index);
  1378. list.Insert(0, item);
  1379. }
  1380. /// <summary>
  1381. /// 获取请假类型
  1382. /// </summary>
  1383. /// <param name="template_id"></param>
  1384. /// <returns></returns>
  1385. public static async Task<List<VacationLeaveTypeView>> GetVacationLeaveTypes(string template_id)
  1386. {
  1387. List<VacationLeaveTypeView> vacationLeaveTypes = new List<VacationLeaveTypeView>();
  1388. TemplateDetailView templateDetailView = new TemplateDetailView();
  1389. templateDetailView = await _qiYeWeChatApiService.GetTemplateDetailAsync(template_id);
  1390. if (templateDetailView.errcode != 0)
  1391. {
  1392. Serilog.Log.Error("【企业微信】【审批】【获取假勤类型的审批】【Msg】" + templateDetailView.errmsg);
  1393. return vacationLeaveTypes;
  1394. }
  1395. List<VacationItemInfo> VacationItemInfos = templateDetailView.vacation_list.item;
  1396. foreach (var item in VacationItemInfos)
  1397. {
  1398. ValueItem valueInfo = item.name.Where(it => it.lang == "zh_CN").FirstOrDefault();
  1399. if (valueInfo != null)
  1400. {
  1401. vacationLeaveTypes.Add(
  1402. new VacationLeaveTypeView()
  1403. {
  1404. id = item.id,
  1405. name = valueInfo.text
  1406. });
  1407. }
  1408. }
  1409. return vacationLeaveTypes;
  1410. }
  1411. /// <summary>
  1412. /// 计算类型费用
  1413. /// 病假 事假 计算 按天计算
  1414. /// </summary>
  1415. /// <param name="leaveDetails"></param>
  1416. /// <param name="leaveType">1年假;2事假;3病假;4调休假;5婚假;6产假;7陪产假;8其他;9丧假</param>
  1417. /// <param name="date_Range_type"></param>
  1418. /// <param name="startTime"></param>
  1419. /// <param name="endTime"></param>
  1420. /// <param name="amountPayable"></param>
  1421. /// <param name="work_days"></param>
  1422. /// <param name="duration"></param>
  1423. /// <param name="mealDeduction"></param>
  1424. /// <param name="typeDeduction"></param>
  1425. public static void CalculateTypeFee1(List<LeaveDetails> leaveDetails, int leaveType, string date_Range_type, DateTime startTime, DateTime endTime,
  1426. decimal amountPayable, int work_days, decimal duration, out decimal mealDeduction, out decimal typeDeduction)
  1427. {
  1428. typeDeduction = 0;
  1429. mealDeduction = 0;
  1430. decimal personalkLeave_dailywage_day = amountPayable / work_days; //日薪 = 事假日薪 *计算方式:日平均工资 = 当月应发工资 /当月应出勤天数。
  1431. //半小时单位
  1432. //decimal halfHour = 7.50M / 0.50M;
  1433. switch (leaveType)
  1434. {
  1435. case 1: //年假
  1436. if (date_Range_type == "halfday")
  1437. {
  1438. if (duration >= 0.5M && duration <= 1M) //一天
  1439. {
  1440. var njItem = leaveDetails.Where(it => it.StartDt.ToString("yyyy-MM-dd") == startTime.ToString("yyyy-MM-dd") &&
  1441. it.EndDt.ToString("yyyy-MM-dd") == endTime.ToString("yyyy-MM-dd")).ToList();
  1442. if (njItem.Count > 1)
  1443. {
  1444. if (njItem[0].StartDt == startTime)
  1445. {
  1446. mealDeduction = 10; //餐补扣款
  1447. }
  1448. }
  1449. else
  1450. {
  1451. mealDeduction = 10; //餐补扣款
  1452. }
  1453. }
  1454. else // 多天
  1455. {
  1456. var njManyDaysItem = leaveDetails.Where(it => it.StartDt.ToString("yyyy-MM-dd") == startTime.ToString("yyyy-MM-dd")).ToList();
  1457. if (njManyDaysItem.Count > 1)
  1458. {
  1459. var njManyDaysItem1 = njManyDaysItem.Where(it => it.StartDt != startTime).ToList();
  1460. if (njManyDaysItem1.Count > 0)
  1461. {
  1462. if (njManyDaysItem1[0].Unit.Equals("天"))
  1463. {
  1464. mealDeduction = 10 * Math.Floor(duration);
  1465. }
  1466. else if (njManyDaysItem1[0].Unit.Equals("小时") && njManyDaysItem1[0].New_Duration >= 3)
  1467. {
  1468. mealDeduction = 10 * Math.Floor(duration);
  1469. }
  1470. else
  1471. {
  1472. mealDeduction = 10 * Math.Ceiling(duration);
  1473. }
  1474. }
  1475. }
  1476. else
  1477. {
  1478. mealDeduction = 10 * Math.Ceiling(duration);
  1479. }
  1480. }
  1481. }
  1482. break;
  1483. case 2: //2事假
  1484. // 事假日薪 *计算方式:日平均工资 = 当月应发工资 /当月应出勤天数。
  1485. decimal personalkLeave_dailywage_halfhour = personalkLeave_dailywage_day / 7.50M; //事假单位 0.5小时
  1486. if (date_Range_type == "halfday")
  1487. {
  1488. #region 处理当天是否扣除餐补
  1489. string formatDt_begin = startTime.ToString("yyyy-MM-dd");
  1490. List<LeaveDetails> leaveDetails1 = leaveDetails.Where(it => it.IsDeduction && it.EndDt.ToString("yyyy-MM-dd") == formatDt_begin).ToList();
  1491. if (leaveDetails1.Count > 0) mealDeduction = 10.00M * Math.Floor(duration); //餐补扣款
  1492. else mealDeduction = 10.00M * Math.Ceiling(duration); //餐补扣款
  1493. #endregion
  1494. if (duration % 1 == 0) //整天
  1495. {
  1496. typeDeduction = ConvertToDecimal(personalkLeave_dailywage_day * duration);
  1497. }
  1498. else //多含 半天 另外处理
  1499. {
  1500. decimal sj_wholeDay = Math.Floor(duration); //整天
  1501. decimal sj_halfDay = duration % 1; //半天
  1502. if (duration % 1 > 0)
  1503. {
  1504. typeDeduction = (personalkLeave_dailywage_day / 2.00M) * (duration / 0.50M);
  1505. }
  1506. else
  1507. {
  1508. typeDeduction = (personalkLeave_dailywage_day / 2.00M);
  1509. }
  1510. typeDeduction = ConvertToDecimal(typeDeduction);
  1511. }
  1512. }
  1513. else if (date_Range_type == "hour")
  1514. {
  1515. decimal leave_halfHour = Convert.ToDecimal(duration) / Convert.ToDecimal(0.5);
  1516. typeDeduction = ConvertToDecimal(personalkLeave_dailywage_halfhour * leave_halfHour);
  1517. //duration = 11M;
  1518. if (duration >= 3 && duration < 7.5M) //单天请假三小时
  1519. {
  1520. mealDeduction = 10; //餐补扣款
  1521. }
  1522. else if (duration >= 7.5M) //多天计算
  1523. {
  1524. decimal leave_halfHour1 = Convert.ToDecimal(duration) / Convert.ToDecimal(0.5);
  1525. decimal leaveDays = duration / 7.5M;
  1526. if (leaveDays % 1 == 0)
  1527. {
  1528. typeDeduction = ConvertToDecimal(personalkLeave_dailywage_day * leaveDays);
  1529. mealDeduction = 10 * leaveDays; //餐补扣款
  1530. }
  1531. else
  1532. {
  1533. typeDeduction = personalkLeave_dailywage_day * Convert.ToInt32(leaveDays);
  1534. decimal sy_shijiaunit = leave_halfHour1 - Convert.ToDecimal(15.00M * Convert.ToInt32(leaveDays));
  1535. if (sy_shijiaunit > 0)
  1536. {
  1537. typeDeduction += ConvertToDecimal(personalkLeave_dailywage_halfhour * sy_shijiaunit);
  1538. }
  1539. mealDeduction = 10 * Convert.ToInt32(leaveDays);
  1540. //得到最后一天的请假时间 是否有餐补
  1541. int lastHours = (Convert.ToDateTime(endTime) - Convert.ToDateTime("09:00")).Hours;
  1542. if (lastHours >= 3)
  1543. {
  1544. mealDeduction += 10; //餐补扣款
  1545. }
  1546. }
  1547. }
  1548. }
  1549. break;
  1550. case 3: //3病假
  1551. // 病假日薪 *计算方式:日平均工资 = 成都市最低工资标准的80% /当月应出勤天数。 短期病假=当月15天内
  1552. decimal chengDuMinimumWage_Day = _chengDuMinimumWage / work_days;
  1553. decimal chengDuMinimumWage_halrHour = chengDuMinimumWage_Day / 7.50M;
  1554. decimal sickLeave_dailywage_halfhour_deduction1 = (personalkLeave_dailywage_day / 7.50M) - chengDuMinimumWage_halrHour; //病假单位 0.5小时 扣款金额
  1555. if (date_Range_type == "halfday")
  1556. {
  1557. mealDeduction = 10.00M * Math.Ceiling(duration); //餐补扣款
  1558. decimal pl_dailywage_day = personalkLeave_dailywage_day - chengDuMinimumWage_Day;
  1559. if (duration % 1 == 0) //整天
  1560. {
  1561. typeDeduction = ConvertToDecimal(pl_dailywage_day * duration);
  1562. }
  1563. else //多含 半天 另外处理
  1564. {
  1565. #region 处理当天是否扣除餐补
  1566. string formatDt_begin = startTime.ToString("yyyy-MM-dd");
  1567. List<LeaveDetails> leaveDetails1 = leaveDetails.Where(it => it.IsDeduction && it.EndDt.ToString("yyyy-MM-dd") == formatDt_begin).ToList();
  1568. if (leaveDetails1.Count > 0) mealDeduction = 10.00M * Math.Floor(duration); //餐补扣款
  1569. else mealDeduction = 10.00M * Math.Ceiling(duration); //餐补扣款
  1570. #endregion
  1571. if (duration % 1 > 0)
  1572. {
  1573. typeDeduction = (pl_dailywage_day / 2.00M) * (duration / 0.50M); ;
  1574. }
  1575. else
  1576. {
  1577. typeDeduction = (pl_dailywage_day / 2.00M);
  1578. }
  1579. typeDeduction = ConvertToDecimal(typeDeduction);
  1580. }
  1581. }
  1582. else if (date_Range_type == "hour")
  1583. {
  1584. decimal sickLeave_halfHour = duration / 0.5M;
  1585. typeDeduction = ConvertToDecimal(sickLeave_dailywage_halfhour_deduction1 * sickLeave_halfHour);
  1586. if (duration >= 3 && duration < 7.5M) //单天请假三小时 && 请假时间在上午 则没有餐补
  1587. {
  1588. mealDeduction = 10; //餐补扣款
  1589. }
  1590. else if (duration >= 7.5M) //多天计算
  1591. {
  1592. decimal sickLeave_halfHour1 = duration / 0.5M;
  1593. decimal leaveDays = Convert.ToDecimal(duration / 7.5M);
  1594. typeDeduction = ConvertToDecimal(sickLeave_dailywage_halfhour_deduction1 * sickLeave_halfHour1);
  1595. if (leaveDays % 1 == 0)
  1596. {
  1597. mealDeduction = 10 * leaveDays; //餐补扣款
  1598. }
  1599. else
  1600. {
  1601. mealDeduction = 10 * Convert.ToInt32(leaveDays);
  1602. typeDeduction = ConvertToDecimal(sickLeave_dailywage_halfhour_deduction1 * Convert.ToInt32(leaveDays));
  1603. decimal sy_bingjiaunit = sickLeave_halfHour1 - Convert.ToDecimal(15.00M * Convert.ToInt32(leaveDays));
  1604. if (sy_bingjiaunit > 0)
  1605. {
  1606. typeDeduction += ConvertToDecimal(sickLeave_dailywage_halfhour_deduction1 * sy_bingjiaunit);
  1607. }
  1608. //得到最后一天的请假时间 是否有餐补
  1609. int lastHours = (Convert.ToDateTime(endTime) - Convert.ToDateTime("09:00")).Hours;
  1610. if (lastHours >= 3)
  1611. {
  1612. mealDeduction += 10; //餐补扣款
  1613. }
  1614. }
  1615. }
  1616. }
  1617. break;
  1618. case 4: //4调休假
  1619. CalculateTypeFeeSub(leaveDetails, date_Range_type, startTime, endTime, duration, out mealDeduction);
  1620. break;
  1621. case 5: //5婚假
  1622. CalculateTypeFeeSub(leaveDetails, date_Range_type, startTime, endTime, duration, out mealDeduction);
  1623. break;
  1624. case 6: //6产假
  1625. CalculateTypeFeeSub(leaveDetails, date_Range_type, startTime, endTime, duration, out mealDeduction);
  1626. break;
  1627. case 7: //7陪产假
  1628. CalculateTypeFeeSub(leaveDetails, date_Range_type, startTime, endTime, duration, out mealDeduction);
  1629. break;
  1630. case 8: //8其他
  1631. CalculateTypeFeeSub(leaveDetails, date_Range_type, startTime, endTime, duration, out mealDeduction);
  1632. break;
  1633. case 9: //9丧假
  1634. if (date_Range_type == "halfday")
  1635. {
  1636. if (duration >= 0.5M && duration <= 1M) //一天
  1637. {
  1638. var njItem = leaveDetails.Where(it => it.StartDt.ToString("yyyy-MM-dd") == startTime.ToString("yyyy-MM-dd") &&
  1639. it.EndDt.ToString("yyyy-MM-dd") == endTime.ToString("yyyy-MM-dd")).ToList();
  1640. if (njItem.Count > 1)
  1641. {
  1642. if (njItem[0].StartDt == startTime)
  1643. {
  1644. mealDeduction = 10; //餐补扣款
  1645. }
  1646. }
  1647. else
  1648. {
  1649. mealDeduction = 10; //餐补扣款
  1650. }
  1651. }
  1652. else // 多天
  1653. {
  1654. var njManyDaysItem = leaveDetails.Where(it => it.StartDt.ToString("yyyy-MM-dd") == startTime.ToString("yyyy-MM-dd")).ToList();
  1655. if (njManyDaysItem.Count > 1)
  1656. {
  1657. var njManyDaysItem1 = njManyDaysItem.Where(it => it.StartDt != startTime).ToList();
  1658. if (njManyDaysItem1.Count > 0)
  1659. {
  1660. if (njManyDaysItem1[0].Unit.Equals("天"))
  1661. {
  1662. mealDeduction = 10 * Math.Floor(duration);
  1663. }
  1664. else if (njManyDaysItem1[0].Unit.Equals("小时") && njManyDaysItem1[0].New_Duration >= 3)
  1665. {
  1666. mealDeduction = 10 * Math.Floor(duration);
  1667. }
  1668. else
  1669. {
  1670. mealDeduction = 10 * Math.Ceiling(duration);
  1671. }
  1672. }
  1673. }
  1674. else
  1675. {
  1676. mealDeduction = 10 * Math.Ceiling(duration);
  1677. }
  1678. }
  1679. }
  1680. break;
  1681. }
  1682. }
  1683. /// <summary>
  1684. /// 计算类型费用
  1685. /// 病假 事假 计算 按小时计算
  1686. /// </summary>
  1687. /// <param name="leaveDetails"></param>
  1688. /// <param name="leaveType">1年假;2事假;3病假;4调休假;5婚假;6产假;7陪产假;8其他;9丧假</param>
  1689. /// <param name="date_Range_type"> halfday 全天 hour 小时</param>
  1690. /// <param name="startTime"></param>
  1691. /// <param name="endTime"></param>
  1692. /// <param name="amountPayable"></param>
  1693. /// <param name="work_days"></param>
  1694. /// <param name="duration"></param>
  1695. /// <param name="mealDeduction"></param>
  1696. /// <param name="typeDeduction"></param>
  1697. public static void CalculateTypeFee2(List<LeaveDetails> leaveDetails, int leaveType, string date_Range_type, DateTime startTime, DateTime endTime,
  1698. decimal amountPayable, int work_days, decimal duration, out decimal mealDeduction, out decimal typeDeduction)
  1699. {
  1700. typeDeduction = 0;
  1701. mealDeduction = 0;
  1702. //string am_starttime = "08:59";
  1703. //string am_endtime = "13:01";
  1704. decimal personalkLeave_dailywage_day = amountPayable / work_days; //日薪 = 事假日薪 *计算方式:日平均工资 = 当月应发工资 /当月应出勤天数。
  1705. //半小时单位
  1706. //decimal halfHour = 7.50M / 0.50M;
  1707. switch (leaveType)
  1708. {
  1709. case 1: //年假
  1710. if (date_Range_type == "halfday")
  1711. {
  1712. if (duration >= 0.5M && duration <= 1M) //一天
  1713. {
  1714. var njItem = leaveDetails.Where(it => it.StartDt.ToString("yyyy-MM-dd") == startTime.ToString("yyyy-MM-dd") &&
  1715. it.EndDt.ToString("yyyy-MM-dd") == endTime.ToString("yyyy-MM-dd")).ToList();
  1716. if (njItem.Count > 1)
  1717. {
  1718. if (njItem[0].StartDt == startTime)
  1719. {
  1720. mealDeduction = 10; //餐补扣款
  1721. }
  1722. }
  1723. else
  1724. {
  1725. mealDeduction = 10; //餐补扣款
  1726. }
  1727. }
  1728. else // 多天
  1729. {
  1730. var njManyDaysItem = leaveDetails.Where(it => it.StartDt.ToString("yyyy-MM-dd") == startTime.ToString("yyyy-MM-dd")).ToList();
  1731. if (njManyDaysItem.Count > 1)
  1732. {
  1733. var njManyDaysItem1 = njManyDaysItem.Where(it => it.StartDt != startTime).ToList();
  1734. if (njManyDaysItem1.Count > 0)
  1735. {
  1736. if (njManyDaysItem1[0].Unit.Equals("天"))
  1737. {
  1738. mealDeduction = 10 * Math.Floor(duration);
  1739. }
  1740. else if (njManyDaysItem1[0].Unit.Equals("小时") && njManyDaysItem1[0].New_Duration >= 3)
  1741. {
  1742. mealDeduction = 10 * Math.Floor(duration);
  1743. }
  1744. else
  1745. {
  1746. mealDeduction = 10 * Math.Ceiling(duration);
  1747. }
  1748. }
  1749. }
  1750. else
  1751. {
  1752. mealDeduction = 10 * Math.Ceiling(duration);
  1753. }
  1754. }
  1755. }
  1756. break;
  1757. case 2: //2事假
  1758. // 事假日薪 *计算方式:日平均工资 = 当月应发工资 /当月应出勤天数。
  1759. decimal personalkLeave_dailywage_halfhour = personalkLeave_dailywage_day / 7.50M; //事假单位 0.5小时
  1760. if (date_Range_type == "halfday")
  1761. {
  1762. mealDeduction = 10.00M * Math.Floor(duration); //餐补扣款
  1763. if (duration % 1 == 0) //整天
  1764. {
  1765. typeDeduction = ConvertToDecimal(personalkLeave_dailywage_day * duration);
  1766. }
  1767. else //多含 半天 另外处理
  1768. {
  1769. decimal sj_wholeDay = Math.Floor(duration); //整天
  1770. decimal sj_halfDay = duration % 1; //半天
  1771. if (sj_halfDay > 0)
  1772. {
  1773. LeaveDetails sjDetails = leaveDetails.Where(it => it.StartDt == startTime && it.EndDt == endTime).FirstOrDefault();
  1774. //decimal sjPrice = 0.00M;
  1775. if (sjDetails != null)
  1776. {
  1777. Slice_info sj_slice_Info = sjDetails.SliceInfo;
  1778. if (sj_slice_Info != null)
  1779. {
  1780. decimal sjLongTime = (sj_slice_Info.duration / 3600.00M);
  1781. typeDeduction = (personalkLeave_dailywage_day / 7.50M) * sjLongTime;
  1782. }
  1783. }
  1784. LeaveDetails sjDetailsMeal = leaveDetails.Where(it => it.EndDt == startTime).FirstOrDefault();
  1785. if (sjDetailsMeal == null)
  1786. {
  1787. mealDeduction += 10.00M;
  1788. }
  1789. }
  1790. else
  1791. {
  1792. typeDeduction = personalkLeave_dailywage_day * sj_wholeDay;
  1793. }
  1794. typeDeduction = ConvertToDecimal(typeDeduction);
  1795. }
  1796. }
  1797. else if (date_Range_type == "hour")
  1798. {
  1799. decimal leave_halfHour = Convert.ToDecimal(duration) / Convert.ToDecimal(0.5);
  1800. typeDeduction = ConvertToDecimal(personalkLeave_dailywage_halfhour * leave_halfHour);
  1801. //duration = 11M;
  1802. if (duration >= 3 && duration < 7.5M) //单天请假三小时
  1803. {
  1804. mealDeduction = 10; //餐补扣款
  1805. }
  1806. else if (duration >= 7.5M) //多天计算
  1807. {
  1808. decimal leave_halfHour1 = Convert.ToDecimal(duration) / Convert.ToDecimal(0.5);
  1809. decimal leaveDays = duration / 7.5M;
  1810. if (leaveDays % 1 == 0)
  1811. {
  1812. typeDeduction = ConvertToDecimal(personalkLeave_dailywage_day * leaveDays);
  1813. mealDeduction = 10 * leaveDays; //餐补扣款
  1814. }
  1815. else
  1816. {
  1817. typeDeduction = personalkLeave_dailywage_day * Convert.ToInt32(leaveDays);
  1818. decimal sy_shijiaunit = leave_halfHour1 - Convert.ToDecimal(15.00M * Convert.ToInt32(leaveDays));
  1819. if (sy_shijiaunit > 0)
  1820. {
  1821. typeDeduction += ConvertToDecimal(personalkLeave_dailywage_halfhour * sy_shijiaunit);
  1822. }
  1823. mealDeduction = 10 * Convert.ToInt32(leaveDays);
  1824. //得到最后一天的请假时间 是否有餐补
  1825. int lastHours = (Convert.ToDateTime(endTime) - Convert.ToDateTime("09:00")).Hours;
  1826. if (lastHours >= 3)
  1827. {
  1828. mealDeduction += 10; //餐补扣款
  1829. }
  1830. }
  1831. }
  1832. }
  1833. break;
  1834. case 3: //3病假
  1835. // 病假日薪 *计算方式:日平均工资 = 成都市最低工资标准的80% /当月应出勤天数。 短期病假=当月15天内
  1836. decimal chengDuMinimumWage_Day = _chengDuMinimumWage / work_days;
  1837. decimal chengDuMinimumWage_halrHour = chengDuMinimumWage_Day / 7.50M;
  1838. decimal sickLeave_dailywage_halfhour_deduction1 = (personalkLeave_dailywage_day / 7.50M) - chengDuMinimumWage_halrHour; //病假单位 0.5小时 扣款金额
  1839. if (date_Range_type == "halfday")
  1840. {
  1841. mealDeduction = 10.00M * Math.Ceiling(duration); //餐补扣款
  1842. decimal pl_dailywage_day = personalkLeave_dailywage_day - chengDuMinimumWage_Day;
  1843. if (duration % 1 == 0) //整天
  1844. {
  1845. typeDeduction = ConvertToDecimal(pl_dailywage_day * duration);
  1846. }
  1847. else //多含 半天 另外处理
  1848. {
  1849. decimal bj_wholeDay = Math.Floor(duration); //整天
  1850. decimal bj_halfDay = duration % 1; //半天
  1851. decimal bj_wholeDayWage = pl_dailywage_day * bj_wholeDay;
  1852. decimal bj_halfDayWage = 0.00M;
  1853. if (bj_halfDay > 0)
  1854. {
  1855. LeaveDetails bjDetails = leaveDetails.Where(it => it.StartDt == startTime && it.EndDt == endTime).FirstOrDefault();
  1856. //decimal bjPrice = 0.00M;
  1857. if (bjDetails != null)
  1858. {
  1859. Slice_info bj_slice_Info = bjDetails.SliceInfo;
  1860. decimal bjLongTime = bj_slice_Info.duration / 3600.00M;
  1861. if (bjLongTime == 3.00M)
  1862. {
  1863. bj_halfDayWage = (pl_dailywage_day / 7.50M) * 3.00M;
  1864. }
  1865. else if (bjLongTime == 4.50M)
  1866. {
  1867. bj_halfDayWage = (pl_dailywage_day / 7.50M) * 4.50M;
  1868. }
  1869. }
  1870. }
  1871. typeDeduction = ConvertToDecimal(bj_wholeDayWage + bj_halfDayWage);
  1872. }
  1873. }
  1874. else if (date_Range_type == "hour")
  1875. {
  1876. decimal sickLeave_halfHour = duration / 0.5M;
  1877. typeDeduction = ConvertToDecimal(sickLeave_dailywage_halfhour_deduction1 * sickLeave_halfHour);
  1878. if (duration >= 3 && duration < 7.5M) //单天请假三小时 && 请假时间在上午 则没有餐补
  1879. {
  1880. mealDeduction = 10; //餐补扣款
  1881. }
  1882. else if (duration >= 7.5M) //多天计算
  1883. {
  1884. decimal sickLeave_halfHour1 = duration / 0.5M;
  1885. decimal leaveDays = Convert.ToDecimal(duration / 7.5M);
  1886. typeDeduction = ConvertToDecimal(sickLeave_dailywage_halfhour_deduction1 * sickLeave_halfHour1);
  1887. if (leaveDays % 1 == 0)
  1888. {
  1889. mealDeduction = 10 * leaveDays; //餐补扣款
  1890. }
  1891. else
  1892. {
  1893. mealDeduction = 10 * Convert.ToInt32(leaveDays);
  1894. typeDeduction = ConvertToDecimal(sickLeave_dailywage_halfhour_deduction1 * Convert.ToInt32(leaveDays));
  1895. decimal sy_bingjiaunit = sickLeave_halfHour1 - Convert.ToDecimal(15.00M * Convert.ToInt32(leaveDays));
  1896. if (sy_bingjiaunit > 0)
  1897. {
  1898. typeDeduction += ConvertToDecimal(sickLeave_dailywage_halfhour_deduction1 * sy_bingjiaunit);
  1899. }
  1900. //得到最后一天的请假时间 是否有餐补
  1901. int lastHours = (Convert.ToDateTime(endTime) - Convert.ToDateTime("09:00")).Hours;
  1902. if (lastHours >= 3)
  1903. {
  1904. mealDeduction += 10; //餐补扣款
  1905. }
  1906. }
  1907. }
  1908. }
  1909. break;
  1910. case 4: //4调休假
  1911. CalculateTypeFeeSub(leaveDetails, date_Range_type, startTime, endTime, duration, out mealDeduction);
  1912. break;
  1913. case 5: //5婚假
  1914. CalculateTypeFeeSub(leaveDetails, date_Range_type, startTime, endTime, duration, out mealDeduction);
  1915. break;
  1916. case 6: //6产假
  1917. CalculateTypeFeeSub(leaveDetails, date_Range_type, startTime, endTime, duration, out mealDeduction);
  1918. break;
  1919. case 7: //7陪产假
  1920. CalculateTypeFeeSub(leaveDetails, date_Range_type, startTime, endTime, duration, out mealDeduction);
  1921. break;
  1922. case 8: //8其他
  1923. CalculateTypeFeeSub(leaveDetails, date_Range_type, startTime, endTime, duration, out mealDeduction);
  1924. break;
  1925. case 9: //9丧假
  1926. CalculateTypeFeeSub(leaveDetails, date_Range_type, startTime, endTime, duration, out mealDeduction);
  1927. break;
  1928. }
  1929. }
  1930. /// <summary>
  1931. /// 计算类型费用
  1932. /// </summary>
  1933. /// <param name="leaveDetails"></param>
  1934. /// <param name="date_Range_type"></param>
  1935. /// <param name="startTime1"></param>
  1936. /// <param name="endTime1"></param>
  1937. /// <param name="duration"></param>
  1938. /// <param name="mealDeduction"></param>
  1939. public static void CalculateTypeFeeSub(List<LeaveDetails> leaveDetails, string date_Range_type, DateTime startTime1, DateTime endTime1,
  1940. decimal duration, out decimal mealDeduction)
  1941. {
  1942. mealDeduction = 0;
  1943. //string am_starttime = "09:00";
  1944. //string am_endtime = "11:59";
  1945. string startTime = startTime1.ToString("HH:mm:ss");
  1946. string endTime = endTime1.ToString("HH:mm:ss");
  1947. if (date_Range_type == "halfday")
  1948. {
  1949. mealDeduction = Math.Ceiling(duration) * 10; //餐补扣款
  1950. }
  1951. else if (date_Range_type == "hour")
  1952. {
  1953. List<LeaveDetails> leaveDetails1 = new List<LeaveDetails>();
  1954. leaveDetails1 = leaveDetails.Where(it => it.StartDt.ToString("yyyy-MM-dd").Equals(startTime1.ToString("yyyy-MM-dd")))
  1955. .OrderBy(it => it.StartDt).ToList();
  1956. if (leaveDetails1.Count > 1)
  1957. {
  1958. decimal timelenTatoal = leaveDetails1.Sum(it => it.New_Duration);
  1959. if (timelenTatoal >= 3.00M)
  1960. {
  1961. if (leaveDetails1[0].StartDt == startTime1)
  1962. {
  1963. mealDeduction = 10; //餐补扣款
  1964. }
  1965. }
  1966. }
  1967. else
  1968. {
  1969. if (duration >= 3 && duration < 7) //单天请假三小时 && 请假时间在上午 则没有餐补
  1970. {
  1971. mealDeduction = 10; //餐补扣款
  1972. }
  1973. else if (duration >= 7 && duration <= 7.50M)
  1974. {
  1975. mealDeduction = 10; //餐补扣款
  1976. }
  1977. else if (duration >= 7.50M) //多天计算
  1978. {
  1979. decimal leaveDays = Convert.ToDecimal(duration / 7.50M);
  1980. if (leaveDays % 1 == 0)
  1981. {
  1982. mealDeduction = 10 * leaveDays; //餐补扣款
  1983. }
  1984. else
  1985. {
  1986. mealDeduction = 10 * Convert.ToInt32(leaveDays);
  1987. //得到最后一天的请假时间 是否有餐补
  1988. int lastHours = (Convert.ToDateTime(endTime) - Convert.ToDateTime("09:00")).Hours;
  1989. if (lastHours >= 3)
  1990. {
  1991. mealDeduction += 10; //餐补扣款
  1992. ////处理结束时间
  1993. //if (endTime.CompareTo(am_starttime) > 0 && endTime.CompareTo(am_endtime) < 0)
  1994. //{
  1995. // mealDeduction += 10; //餐补扣款
  1996. //}
  1997. }
  1998. }
  1999. }
  2000. }
  2001. }
  2002. }
  2003. /// <summary>
  2004. /// 获取打卡补卡类型
  2005. /// </summary>
  2006. /// <param name="template_id"></param>
  2007. /// <returns></returns>
  2008. public static async Task<List<VacationLeaveTypeView>> GetVacationReissueCardTypes(string template_id)
  2009. {
  2010. List<VacationLeaveTypeView> vacationLeaveTypes = new List<VacationLeaveTypeView>();
  2011. TemplateDetailView templateDetailView = new TemplateDetailView();
  2012. templateDetailView = await _qiYeWeChatApiService.GetTemplateDetailAsync(template_id);
  2013. if (templateDetailView.errcode != 0)
  2014. {
  2015. return vacationLeaveTypes;
  2016. }
  2017. List<VacationItemInfo> VacationItemInfos = templateDetailView.vacation_list.item;
  2018. foreach (var item in VacationItemInfos)
  2019. {
  2020. ValueItem valueInfo = item.name.Where(it => it.lang == "zh_CN").FirstOrDefault();
  2021. if (valueInfo != null)
  2022. {
  2023. vacationLeaveTypes.Add(
  2024. new VacationLeaveTypeView()
  2025. {
  2026. id = item.id,
  2027. name = valueInfo.text
  2028. });
  2029. }
  2030. }
  2031. return vacationLeaveTypes;
  2032. }
  2033. /// <summary>
  2034. /// 打卡数据
  2035. /// 假勤数据 统计
  2036. /// </summary>
  2037. /// <param name="datas">数据源</param>
  2038. /// <param name="type">
  2039. /// 1-请假;2-补卡;3-出差;4-外出;100-外勤;
  2040. /// </param>
  2041. /// <param name="subTypeName">
  2042. /// 年假 事假 病假 调休假 婚嫁 产假 陪产假 丧假 补卡次数 出差 外出数 外勤 其他
  2043. /// </param>
  2044. /// <returns></returns>
  2045. private static int Fallibilitydispose(List<Sp_Item> datas, int type, string? subTypeName)
  2046. {
  2047. int num = 0;
  2048. Sp_Item _Info = datas.Where(it => it.type == type && it.name == subTypeName).FirstOrDefault();
  2049. if (_Info != null) { num = _Info.count; }
  2050. return num;
  2051. }
  2052. /// <summary>
  2053. /// 打卡数据
  2054. /// 异常数据 统计
  2055. /// </summary>
  2056. /// <returns></returns>
  2057. private static int ExceptionStatistics(List<Exception_Info> datas, int type)
  2058. {
  2059. int num = 0;
  2060. Exception_Info _Info = datas.Where(it => it.exception == type).FirstOrDefault();
  2061. if (_Info != null) { num = _Info.count; }
  2062. return num;
  2063. }
  2064. /// <summary>
  2065. /// 获取时间段内除周末 节假日外的 工作日
  2066. /// </summary>
  2067. /// <param name="yearMonth"></param>
  2068. /// <returns></returns>
  2069. public static async Task<int> GetWorkDays(string yearMonth)
  2070. {
  2071. int workdays = 0;
  2072. string sql = string.Format(@"Select * From Pm_WageIssueWorkingDay
  2073. Where Isdel = 0 And YearMonth = '{0}' ", yearMonth);
  2074. var data = await _usersRep._sqlSugar.SqlQueryable<WageYearMonthView>(sql).FirstAsync();
  2075. if (data != null)
  2076. {
  2077. workdays = data.Workdays;
  2078. }
  2079. return workdays;
  2080. }
  2081. /// <summary>
  2082. /// 获取一个类指定的属性值
  2083. /// </summary>
  2084. /// <param name="info">object对象</param>
  2085. /// <param name="field">属性名称</param>
  2086. /// <returns></returns>
  2087. public static object GetPropertyValue(object info, string field)
  2088. {
  2089. if (info == null) return null;
  2090. System.Type t = info.GetType();
  2091. IEnumerable<System.Reflection.PropertyInfo> property = from pi in t.GetProperties() where pi.Name.ToLower() == field.ToLower() select pi;
  2092. return property.First().GetValue(info, null);
  2093. }
  2094. }
  2095. }