PayrollComputation.cs 126 KB

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