PayrollComputation.cs 98 KB

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