PayrollComputation.cs 133 KB

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