PayrollComputation.cs 130 KB

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