PayrollComputation.cs 108 KB

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