PayrollComputation.cs 129 KB

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