PayrollComputation.cs 128 KB

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