PayrollComputation.cs 134 KB

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