PayrollComputation.cs 128 KB

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