PayrollComputation.cs 134 KB

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