PayrollComputation.cs 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971
  1. using Google.Protobuf.WellKnownTypes;
  2. using NPOI.OpenXmlFormats.Spreadsheet;
  3. using OASystem.API.OAMethodLib.QiYeWeChatAPI;
  4. using OASystem.Domain;
  5. using OASystem.Domain.Entities.PersonnelModule;
  6. using OASystem.Domain.ViewModels.PersonnelModule;
  7. using OASystem.Domain.ViewModels.QiYeWeChat;
  8. using OASystem.Infrastructure.Repositories.Groups;
  9. using System;
  10. using System.Linq.Expressions;
  11. using TencentCloud.Ocr.V20181119.Models;
  12. namespace OASystem.API.OAMethodLib
  13. {
  14. /// <summary>
  15. /// 工资计算
  16. /// </summary>
  17. public static class PayrollComputation
  18. {
  19. private static Result _result = new Result();
  20. private static readonly IQiYeWeChatApiService _qiYeWeChatApiService = AutofacIocManager.Instance.GetService<IQiYeWeChatApiService>();
  21. private static readonly UsersRepository _usersRep = AutofacIocManager.Instance.GetService<UsersRepository>();
  22. private static readonly IMapper _mapper = AutofacIocManager.Instance.GetService<IMapper>();
  23. private static readonly decimal _chengDuMinimumWage = 2100.00M;
  24. /// <summary>
  25. /// 计算工资
  26. /// </summary>
  27. /// <param name="pm_WageSheetDattaSources"></param>
  28. /// <param name="userNames"></param>
  29. /// <param name="thisYearMonth"></param>
  30. /// <param name="startDt"></param>
  31. /// <param name="endDt"></param>
  32. /// <returns></returns>
  33. public static async Task<Result> SalaryCalculatorAsync(
  34. List<Pm_WageSheet> pm_WageSheetDattaSources, List<UserNameView> userNames,int userId, string thisYearMonth, DateTime startDt, DateTime endDt)
  35. {
  36. if (pm_WageSheetDattaSources.Count <= 0)
  37. {
  38. _result.Msg = "计算工资传入数据为空!";
  39. return _result;
  40. }
  41. if (userNames.Count <= 0 )
  42. {
  43. var nameData = await _usersRep.GetUserNameList(1);
  44. userNames = nameData.Data;
  45. }
  46. //获取所有打卡数据
  47. CheckInView checkIn = await _qiYeWeChatApiService.GetCheckin_MonthDataAsync(startDt, endDt); //时间段内所有 打卡数据
  48. if (checkIn.errcode != 0)
  49. {
  50. _result.Msg = checkIn.errmsg;
  51. return _result;
  52. }
  53. List<Data> checkInDatas = checkIn.datas;
  54. //获取 请假类型 Sp_Detail.template_id
  55. string leave_template_id = "C4NzTJCh1onCUK915rRkvy7Fh5Vqz4YbiEV9jrBY1";
  56. List<VacationLeaveTypeView> vacationLeaveTypes = await GetVacationLeaveTypes(leave_template_id);
  57. if (vacationLeaveTypes.Count <= 0)
  58. {
  59. _result.Msg = startDt + " - " + endDt + "请假 类型数据 获取失败!";
  60. return _result;
  61. }
  62. foreach (var pm_wsInfo in pm_WageSheetDattaSources)
  63. {
  64. string itemName = userNames.Where(it => it.Id == pm_wsInfo.UserId).FirstOrDefault().CnName;
  65. //补贴 金额
  66. decimal meal_subsidy = 0.00M; // 午餐(午餐10元/天) 补贴 * 计算方式:单日上午请假时长(小时)大于或者等于三小时 没有餐补
  67. //事假 病假 总金额
  68. decimal personalLeaveTotal = 0.00M, // 事假 日薪 *计算方式:日平均工资 = 月工资/当月应出勤天数。
  69. sickLeaveTotal = 0.00M; // 病假 日薪 *计算方式:日平均工资 = 成都市最低工资标准的80%/当月应出勤天数。 短期病假=当月15天内
  70. //扣款金额
  71. decimal beLate_deduction = 0.00M, // 迟到 扣款金额 *计算方式:
  72. // 一个自然月内,不足 10 分钟的迟到/早退,不超过 2 次的部分,不做处罚;3 次及以上,按50元 / 次处罚;
  73. // 超过 10 分钟(含 10 分钟),不足 60 分钟的迟到/早退,按 50 元/次处罚;
  74. // 超过 60 分钟(含 60 分钟),不足 3 小时的迟到/早退,且无请假者,按旷工半日处理;超过3 小时的迟到 / 早退,且无请假者,按旷工一日处理。
  75. early_deduction = 0.00M, // 早退 扣款金额
  76. absenteeism_deduction = 0.00M, // 旷工 扣款金额 *计算方式:旷工扣发当日工资
  77. unprinted_deduction = 0.00M, // 未打卡 扣款金额 *计算方式:
  78. // 试用期员工每月有 2 次 补卡机会,超过 2 次不足 5 次的部分,按 10 元 / 次处罚,5 次及以上的漏卡,按 50 元 / 次处罚;
  79. // 正式员工每月 3 次以内的补卡,按 10 元 / 次处罚,3 次及以上的漏卡,按 50 元 / 次处罚。
  80. sickLeave_deduction = 0.00M,
  81. other_deduction = 0.00M; // 其他 扣款金额
  82. decimal meal_deduction = 0.00M; // 餐补 扣款金额
  83. decimal reissuecard_deduction = 0.00M; // 补卡 扣款金额
  84. //打卡数据
  85. Data? checkInData = checkInDatas.Where(it => it.base_info.name == itemName).FirstOrDefault();
  86. if (checkInData == null) { continue; }
  87. string acctid = checkInData.base_info.acctid; //用户Id
  88. //当月总计数据
  89. Summary_Info? summary_Info = checkInData.summary_info;
  90. if (summary_Info == null) { continue; }
  91. int work_days = summary_Info.work_days; //应出勤天数
  92. int regular_days = summary_Info.regular_days; //正常出勤天数
  93. meal_subsidy = work_days * 10; //应发放餐补
  94. #region 计算日工资 正常日薪 事假日薪 病假日薪
  95. //月 - 应发工资
  96. decimal amountPayable = pm_wsInfo.Basic + pm_wsInfo.Floats + pm_wsInfo.PostAllowance + pm_wsInfo.GarmentWashSubsidies + pm_wsInfo.CommunicationSubsidies +
  97. pm_wsInfo.TrafficSubsidies + pm_wsInfo.InformationSecurityFee + pm_wsInfo.OperationBonus + pm_wsInfo.SpecialAllowance + pm_wsInfo.OtherSubsidies + pm_wsInfo.GroupCost;
  98. // 日薪 = *计算方式:日平均工资 = 月工资/当月应出勤天数。
  99. decimal dailyWage = amountPayable / work_days;
  100. // 病假日薪 *计算方式:日平均工资 = 成都市最低工资标准的80%/当月应出勤天数。 短期病假=当月15天内
  101. decimal sickLeave_dailywage = _chengDuMinimumWage / work_days;
  102. //病假 一天扣款
  103. sickLeave_deduction = dailyWage - sickLeave_dailywage;
  104. #endregion
  105. int annualLeaveNum = 0, //年假
  106. personalLeaveNum = 0, //事假
  107. sickLeaveNum = 0, //病假
  108. lieuLeaveNum = 0, //调休假
  109. marriageLeaveNum = 0, //婚嫁
  110. maternityLeaveNum = 0, //产假
  111. paternityLeaveNum = 0, //陪产假
  112. funeralLeaveNum = 0, //丧假
  113. reissueCardNum = 0, //补卡 次数
  114. evectionNum = 0, //出差 次数
  115. outIngNum = 0, //外出 次数
  116. outWorkNum = 0, //外勤 次数
  117. otherLeaveNum = 0; //其他
  118. #region 假勤 处理 1-请假;2-补卡;3-出差;4-外出;100-外勤;
  119. List<Sp_Item>? sp_items = checkInData.sp_items.Where(it => it.count != 0).ToList();
  120. if (sp_items != null && sp_items.Count > 0)
  121. {
  122. annualLeaveNum = Fallibilitydispose(sp_items, 1, "年假");
  123. personalLeaveNum = Fallibilitydispose(sp_items, 1, "事假");
  124. sickLeaveNum = Fallibilitydispose(sp_items, 1, "病假");
  125. lieuLeaveNum = Fallibilitydispose(sp_items, 1, "调休假");
  126. marriageLeaveNum = Fallibilitydispose(sp_items, 1, "婚嫁");
  127. maternityLeaveNum = Fallibilitydispose(sp_items, 1, "产假");
  128. paternityLeaveNum = Fallibilitydispose(sp_items, 1, "陪产假");
  129. funeralLeaveNum = Fallibilitydispose(sp_items, 1, "丧假");
  130. otherLeaveNum = Fallibilitydispose(sp_items, 1, "其他");
  131. reissueCardNum = Fallibilitydispose(sp_items, 2, "补卡次数");
  132. evectionNum = Fallibilitydispose(sp_items, 3, "出差");
  133. outIngNum = Fallibilitydispose(sp_items, 4, "外出");
  134. outWorkNum = Fallibilitydispose(sp_items, 3, "外勤");
  135. }
  136. #region 请假类型金额/餐补 处理
  137. List<Sp_Detail> sp_leave_details = new List<Sp_Detail>();
  138. sp_leave_details = await _qiYeWeChatApiService.GetApprovalDetailsAsync(startDt, endDt, acctid, 2 , 1); //时间段内所有 已同意的 请假 审批数据
  139. if (sp_leave_details.Count <= 0)
  140. {
  141. _result.Msg += startDt + " - " + endDt +" "+itemName + " 请假 审批数据获取未获取到!\r\n";
  142. continue;
  143. }
  144. List<Ex_Items> ex_Items = new List<Ex_Items>();//假勤 And 打卡备注集合
  145. Ex_Items ex_Items_jq = new Ex_Items() { Type = "假勤" }; //假勤
  146. List<Ex_Item> ex_ItemInfos = new List<Ex_Item>();
  147. foreach (Sp_Detail sp_item in sp_leave_details)
  148. {
  149. Apply_data? apply_data = sp_item.apply_data;
  150. if (apply_data != null)
  151. {
  152. List<ContentsItem> contents = apply_data.contents;
  153. ContentsItem content_Vacation = contents.Where(it => it.control== "Vacation").FirstOrDefault(); //请假类型
  154. ContentsItem content_Textarea = contents.Where(it => it.control == "Textarea").FirstOrDefault(); //多行文本
  155. if (content_Vacation != null)
  156. {
  157. Vacation vacation = content_Vacation.value.vacation;
  158. Attendance attendance = vacation.attendance; //假勤组件
  159. Selector selector = vacation.selector; //请假类型
  160. List<OptionsItem> optionsItems = selector.options; //key 请假类型 id
  161. List<TitleItem> value = optionsItems[0].value; // value 文本描述值
  162. int leaveType = int.Parse(optionsItems[0].key); //key 请假子类型 id
  163. Date_range date_Range = attendance.date_range;
  164. decimal thisTypeDeduction = 0.00M;//当前类型扣款
  165. string leave_starttime = date_Range.new_begin_dt.ToString("HH:mm");
  166. string leave_endtime = date_Range.new_end_dt.ToString("HH:mm");
  167. string typeName = string.Empty;
  168. int leaveTypeId = leaveType;
  169. var leaveTypeData = vacationLeaveTypes.Where(it => it.id == leaveTypeId).FirstOrDefault();
  170. if (leaveTypeData != null) { typeName = leaveTypeData.name; }
  171. //计算请假类型扣款金额
  172. int new_duration = 0;
  173. if (date_Range.type == "halfday")
  174. {
  175. new_duration =date_Range.new_duration / 86400;
  176. }
  177. else if (date_Range.type == "hour")
  178. {
  179. new_duration =date_Range.new_duration / 3600;
  180. }
  181. decimal leave_meals = 0.00M;
  182. CalculateTypeFee(leaveType, date_Range.type, leave_starttime, leave_endtime, amountPayable, work_days, new_duration,
  183. out leave_meals, out thisTypeDeduction);
  184. meal_deduction += leave_meals;
  185. string startEndTiime = startEndTiime = date_Range.new_begin_dt.ToString("yyyy-MM-dd HH:mm") + " - " +
  186. date_Range.new_end_dt.ToString("yyyy-MM-dd HH:mm");
  187. Ex_Item ex_Item = new Ex_Item()
  188. {
  189. SubTypeId = leaveType,
  190. SubType = typeName,
  191. StartTimeDt = date_Range.new_begin_dt,
  192. EndTimeDt = date_Range.new_end_dt,
  193. Duration = new_duration,
  194. Deduction = thisTypeDeduction,
  195. //Reason = apply_data.reason,
  196. Apply_time_dt = sp_item.apply_time_dt,
  197. //Approval_name = sp_item.approval_name,
  198. };
  199. ex_ItemInfos.Add(ex_Item);
  200. }
  201. }
  202. }
  203. if (ex_ItemInfos.Count > 0)
  204. {
  205. ex_Items_jq.Ex_ItemInfo = ex_ItemInfos.OrderBy(it => it.SubTypeId).ThenBy(it => it.Apply_time_dt).ToList();
  206. ex_Items.Add(ex_Items_jq);
  207. }
  208. #endregion
  209. #endregion
  210. Ex_Items ex_Items_dk = new Ex_Items() { Type = "打卡" }; //打卡
  211. List<Ex_Item> ex_Item_Infos = new List<Ex_Item>();
  212. #region 打卡补卡 补卡次数 处理
  213. if (reissueCardNum > 0)
  214. {
  215. if (reissueCardNum <= 3)
  216. {
  217. reissuecard_deduction += 10 * reissueCardNum;
  218. }
  219. else if (reissueCardNum > 3) //补卡超过三 每补卡一次 50 CNY
  220. {
  221. int for_reissueCardNum = reissueCardNum - 3;
  222. for (int i = 0; i < for_reissueCardNum; i++)
  223. {
  224. reissuecard_deduction += 50;
  225. }
  226. }
  227. Ex_Item ex_reissueCard = new Ex_Item()
  228. {
  229. SubTypeId = 7,
  230. SubType = "补卡次数",
  231. Deduction = reissuecard_deduction,
  232. Reason = "补卡:员工发现自己漏打卡时,需及时提起补卡申请,并说明情况。试用期员工每月有 2 次\r\n补卡机会,超过 2 次不足 5 次的部分,按 10 元/次处罚,5 次及以上的漏卡,按 50 元/次处罚;正式员工每月 3 次以内的补卡,按 10 元/次处罚,3 次及以上的漏卡,按 50 元/次处罚。\r\n补卡路径为:企微-工作台-审批-打卡补卡。",
  233. unit = string.Empty
  234. };
  235. ex_Item_Infos.Add(ex_reissueCard);
  236. }
  237. #endregion
  238. List<Ex_Item> ex_reissuecard_Items = new List<Ex_Item>();
  239. //List<dynamic> ex_reissuecard_Items = new List<dynamic>();
  240. List<Sp_Detail> sp_reissuecard_details = new List<Sp_Detail>();
  241. //统计迟到次数
  242. int beLateNum = 0, // 1-迟到;
  243. leaveEarlyNum = 0, // 2-早退;
  244. dummyDeckNum = 0, // 3-缺卡;
  245. minerNum = 0, // 4-旷工;
  246. locationAnomalyNum = 0, // 5-地点异常;
  247. unitExNum = 0; // 6-设备异常;
  248. if (summary_Info.except_days > 0)
  249. {
  250. List<Exception_Info>? ex_infos = checkInData.exception_infos;
  251. if (ex_infos != null && ex_infos.Count >= 0)
  252. {
  253. beLateNum = ExceptionStatistics(ex_infos, 1);
  254. leaveEarlyNum = ExceptionStatistics(ex_infos, 2);
  255. dummyDeckNum = ExceptionStatistics(ex_infos, 3);
  256. minerNum = ExceptionStatistics(ex_infos, 4);
  257. locationAnomalyNum = ExceptionStatistics(ex_infos, 5);
  258. unitExNum = ExceptionStatistics(ex_infos, 6);
  259. }
  260. }
  261. //打卡记录
  262. CheckInDataView checkInDataView = new CheckInDataView();
  263. checkInDataView = await _qiYeWeChatApiService.GetCheckinDataAsync(new List<string>() { acctid },3,startDt,endDt);
  264. if (checkInDataView.errcode != 0)
  265. {
  266. _result.Msg += startDt + " - " + endDt + " " + itemName + " 打卡记录 "+ checkInDataView.errmsg + " \r\n";
  267. }
  268. //筛选时间异常的打卡记录
  269. List<CheckInDataInfo> checkInDataInfos = checkInDataView.checkindata.Where(it => !string.IsNullOrEmpty(it.exception_type)).ToList();
  270. //处理 未打卡的记录是否已经通过假勤审批
  271. List<CheckInDataInfo> leave_checkInDataInfos = new List<CheckInDataInfo>();
  272. if (checkInDataInfos.Count > 0)
  273. {
  274. foreach (var leaveItem in ex_ItemInfos)
  275. {
  276. if (leaveItem.StartTimeDt.ToString("yyyy-MM-dd").Equals(leaveItem.EndTimeDt.ToString("yyyy-MM-dd"))) //单天
  277. {
  278. leave_checkInDataInfos.AddRange(checkInDataInfos.Where(it => it.checkin_time_dt.ToString("yyyy-MM-dd") == leaveItem.StartTimeDt.ToString("yyyy-MM-dd")).ToList());
  279. }
  280. else //多天
  281. {
  282. leave_checkInDataInfos.AddRange(checkInDataInfos.Where(it => it.checkin_time_dt >= leaveItem.StartTimeDt && it.checkin_time_dt <=leaveItem.EndTimeDt ).ToList());
  283. }
  284. }
  285. }
  286. //处理 时间异常的记录是否已经通过补卡审批
  287. List<CheckInDataInfo> pullcard_checkInDataInfos = new List<CheckInDataInfo>();
  288. if (leave_checkInDataInfos.Count > 0)
  289. {
  290. //获取异常打卡数据 并且 未通过假勤审批
  291. pullcard_checkInDataInfos = checkInDataInfos.Except(leave_checkInDataInfos).ToList();
  292. if (pullcard_checkInDataInfos.Count > 0)
  293. {
  294. #region 打卡异常处理 统计 1-迟到;2-早退;3-缺卡;4-旷工;5-地点异常;6-设备异常;
  295. //sp_reissuecard_details = await _qiYeWeChatApiService.GetApprovalDetailsAsync(startDt, endDt, acctid, 2, 2); //时间段内所有 已同意的 补卡 审批数据
  296. //if (sp_reissuecard_details.Count <= 0)
  297. //{
  298. // _result.Msg += startDt + " - " + endDt + " " + itemName + " 打卡补卡 审批数据获取未获取到!\r\n";
  299. // continue;
  300. //}
  301. //#region 打卡补卡
  302. //foreach (var pullcardItem in sp_reissuecard_details)
  303. //{
  304. // Apply_data? apply_data = pullcardItem.apply_data;
  305. // if (apply_data != null)
  306. // {
  307. // List<ContentsItem> contents = apply_data.contents;
  308. // ContentsItem content_Vacation = contents.Where(it => it.control == "Vacation").FirstOrDefault(); //请假类型
  309. // ContentsItem content_Textarea = contents.Where(it => it.control == "Textarea").FirstOrDefault(); //多行文本
  310. // if (content_Vacation != null)
  311. // {
  312. // Vacation vacation = content_Vacation.value.vacation;
  313. // Attendance attendance = vacation.attendance; //假勤组件
  314. // Selector selector = vacation.selector; //请假类型
  315. // List<OptionsItem> optionsItems = selector.options; //key 请假类型 id
  316. // List<TitleItem> value = optionsItems[0].value; // value 文本描述值
  317. // int leaveType = int.Parse(optionsItems[0].key); //key 请假子类型 id
  318. // Date_range date_Range = attendance.date_range;
  319. // decimal thisTypeDeduction = 0.00M;//当前类型扣款
  320. // string leave_starttime = date_Range.new_begin_dt.ToString("HH:mm");
  321. // string leave_endtime = date_Range.new_end_dt.ToString("HH:mm");
  322. // string typeName = string.Empty;
  323. // int leaveTypeId = leaveType;
  324. // var leaveTypeData = vacationLeaveTypes.Where(it => it.id == leaveTypeId).FirstOrDefault();
  325. // if (leaveTypeData != null) { typeName = leaveTypeData.name; }
  326. // //计算请假类型扣款金额
  327. // int new_duration = 0;
  328. // if (date_Range.type == "halfday")
  329. // {
  330. // new_duration = date_Range.new_duration / 86400;
  331. // }
  332. // else if (date_Range.type == "hour")
  333. // {
  334. // new_duration = date_Range.new_duration / 3600;
  335. // }
  336. // decimal leave_meals = 0.00M;
  337. // CalculateTypeFee(leaveType, date_Range.type, leave_starttime, leave_endtime, amountPayable, work_days, new_duration,
  338. // out leave_meals, out thisTypeDeduction);
  339. // meal_deduction += leave_meals;
  340. // string startEndTiime = startEndTiime = date_Range.new_begin_dt.ToString("yyyy-MM-dd HH:mm") + " - " +
  341. // date_Range.new_end_dt.ToString("yyyy-MM-dd HH:mm");
  342. // }
  343. // }
  344. //}
  345. #endregion
  346. foreach (var pc_ex_item in pullcard_checkInDataInfos)
  347. {
  348. CheckInDayDataView checkInDayDataView = await _qiYeWeChatApiService.GetCheckInDayDataAsync(new List<string>() { acctid },startDt,endDt);
  349. if (checkInDayDataView.errcode != 0)
  350. {
  351. _result.Msg += startDt + " - " + endDt + " " + itemName + " 异常信息数据获取未获取到!\r\n";
  352. continue;
  353. }
  354. List<Root> roots_words= checkInDayDataView.datas.Where(it => it.base_info.day_type == 0).ToList(); //获取工作日日报信息
  355. List<Root> roots_exs = checkInDayDataView.datas.Where(it => it.exception_infos.Count > 0).ToList();
  356. Root roots_ex = roots_exs.Where(it => it.base_info.dateDt == pc_ex_item.sch_checkin_time_dt).FirstOrDefault();
  357. List<Exception_infos> exception_infos = roots_ex.exception_infos;
  358. List<Exception_infos> exception_infos1 = checkInDayDataView.datas[29].exception_infos;
  359. string exc_type = pc_ex_item.exception_type;
  360. if (exc_type.Contains("时间异常") || exc_type.Contains("未打卡")) // 时间异常 未打卡
  361. {
  362. int day_time_minute = (60 * 7) + 30;
  363. Exception_infos beLate_ex = exception_infos.Where(it => it.exception == 1).FirstOrDefault(); //迟到
  364. decimal day_miner_unit = dailyWage / 15; //以0.5小时为单位
  365. if (beLate_ex != null)
  366. {
  367. if (beLateNum > 0) //迟到次数
  368. {
  369. //1:一个自然月内,不足 10 分钟的迟到/早退,不超过 2 次的部分,不做处罚;3 次及以上,按50 元 / 次处罚;
  370. //2:超过 10 分钟(含 10 分钟),不足 60 分钟的迟到 / 早退,按 50 元 / 次处罚;
  371. //3:超过 60 分钟(含 60 分钟),不足 3 小时的迟到 / 早退,且无请假者,按旷工半日处理;超过 3 小时的迟到 / 早退,且无请假者,按旷工一日处理。
  372. Ex_Item beLate_belate_ex = new Ex_Item()
  373. {
  374. SubTypeId = 4,
  375. SubType = "旷工",
  376. unit = "分钟",
  377. };
  378. decimal day_beLate_deduction = 0.00M;
  379. if (beLate_ex.duration >= 10 && beLate_ex.duration <= 60)
  380. {
  381. day_beLate_deduction = beLateNum * 50;
  382. beLate_belate_ex.SubTypeId = 1;
  383. beLate_belate_ex.SubType = "迟到";
  384. }
  385. else if (beLate_ex.duration > 60 && beLate_ex.duration <= 180)
  386. {
  387. day_beLate_deduction = day_miner_unit * 6; //3小时
  388. }
  389. else day_beLate_deduction = dailyWage;
  390. beLate_deduction += day_beLate_deduction;
  391. beLate_belate_ex.Duration = beLate_ex.duration;
  392. beLate_belate_ex.Deduction = day_beLate_deduction;
  393. ex_reissuecard_Items.Add(beLate_belate_ex);
  394. }
  395. if (leaveEarlyNum > 0) // 早退次数
  396. {
  397. //1:一个自然月内,不足 10 分钟的迟到/早退,不超过 2 次的部分,不做处罚;3 次及以上,按50 元 / 次处罚;
  398. //2:超过 10 分钟(含 10 分钟),不足 60 分钟的迟到 / 早退,按 50 元 / 次处罚;
  399. //3:超过 60 分钟(含 60 分钟),不足 3 小时的迟到 / 早退,且无请假者,按旷工半日处理;超过 3 小时的迟到 / 早退,且无请假者,按旷工一日处理。
  400. Ex_Item beLate_belate_ex = new Ex_Item()
  401. {
  402. SubTypeId = 4,
  403. SubType = "旷工",
  404. unit = "分钟",
  405. };
  406. decimal day_beLate_deduction = 0.00M;
  407. if (beLate_ex.duration >= 10 && beLate_ex.duration <= 60)
  408. {
  409. day_beLate_deduction = beLateNum * 50;
  410. beLate_belate_ex.SubTypeId = 3;
  411. beLate_belate_ex.SubType = "未打卡/漏卡";
  412. }
  413. else if (beLate_ex.duration > 60 && beLate_ex.duration <= 180)
  414. {
  415. day_beLate_deduction = day_miner_unit * 6; //3小时
  416. }
  417. else day_beLate_deduction = dailyWage;
  418. beLate_deduction += day_beLate_deduction;
  419. beLate_belate_ex.Duration = beLate_ex.duration;
  420. beLate_belate_ex.Deduction = day_beLate_deduction;
  421. ex_reissuecard_Items.Add(beLate_belate_ex);
  422. }
  423. if (dummyDeckNum > 0) //缺卡
  424. {
  425. Ex_Item beLate_belate_ex = new Ex_Item()
  426. {
  427. SubTypeId = 4,
  428. SubType = "旷工",
  429. unit = "分钟",
  430. };
  431. decimal day_beLate_deduction = 0.00M;
  432. if (beLate_ex.duration >= 10 && beLate_ex.duration <= 60)
  433. {
  434. day_beLate_deduction = beLateNum * 50;
  435. beLate_belate_ex.SubTypeId = 2;
  436. beLate_belate_ex.SubType = "早退";
  437. }
  438. else if (beLate_ex.duration > 60 && beLate_ex.duration <= 180)
  439. {
  440. day_beLate_deduction = day_miner_unit * 6; //3小时
  441. }
  442. else day_beLate_deduction = dailyWage;
  443. beLate_deduction += day_beLate_deduction;
  444. beLate_belate_ex.Duration = beLate_ex.duration;
  445. beLate_belate_ex.Deduction = day_beLate_deduction;
  446. ex_reissuecard_Items.Add(beLate_belate_ex);
  447. }
  448. if (minerNum > 0) //矿工
  449. {
  450. Ex_Item beLate_belate_ex = new Ex_Item()
  451. {
  452. SubTypeId = 4,
  453. SubType = "旷工",
  454. unit = "分钟",
  455. };
  456. decimal day_beLate_deduction = 0.00M;
  457. if (beLate_ex.duration > 60 && beLate_ex.duration <= 180)
  458. {
  459. day_beLate_deduction = day_miner_unit * 6; //3小时
  460. }
  461. else day_beLate_deduction = dailyWage;
  462. beLate_deduction += day_beLate_deduction;
  463. beLate_belate_ex.Duration = beLate_ex.duration;
  464. beLate_belate_ex.Deduction = day_beLate_deduction;
  465. ex_reissuecard_Items.Add(beLate_belate_ex);
  466. }
  467. }
  468. }
  469. }
  470. }
  471. }
  472. if (ex_reissuecard_Items.Count > 0)
  473. {
  474. ex_Items_dk.Ex_ItemInfo = ex_reissuecard_Items;
  475. }
  476. #region 应发合计 实发合计 扣款合计(假勤扣款,其他扣款,社保扣款,公积金代扣,个税扣款)
  477. decimal mealTotal = meal_subsidy - meal_deduction; //餐补
  478. decimal salaryTotal = amountPayable + mealTotal; //应发合计
  479. //扣款合计 不含个税
  480. decimal eductionTotal = sickLeaveTotal + personalLeaveTotal + beLate_deduction + early_deduction + absenteeism_deduction + unprinted_deduction + other_deduction +
  481. pm_wsInfo.WithholdingInsurance + pm_wsInfo.ReservedFunds;
  482. decimal actualReleaseTotal = salaryTotal - eductionTotal; //实发合计 * 不含个税
  483. #endregion
  484. #region 处理当月工资数据
  485. pm_wsInfo.YearMonth = thisYearMonth;
  486. pm_wsInfo.StartDate = startDt.ToString("yyyy-MM-dd");
  487. pm_wsInfo.EndDate = endDt.ToString("yyyy-MM-dd");
  488. pm_wsInfo.SickLeave = sickLeaveTotal; //病假
  489. pm_wsInfo.SomethingFalse = personalLeaveTotal; //事假
  490. pm_wsInfo.LateTo = beLate_deduction; //迟到
  491. pm_wsInfo.LeaveEarly = early_deduction; //早退
  492. pm_wsInfo.Absenteeism = absenteeism_deduction; //旷工
  493. pm_wsInfo.NotPunch = unprinted_deduction; //未打卡
  494. pm_wsInfo.OtherDeductions = other_deduction; //其他
  495. pm_wsInfo.Ex_ItemsRemark = JsonConvert.SerializeObject(ex_Items); //
  496. pm_wsInfo.Mealsupplement = mealTotal; //餐补
  497. pm_wsInfo.Should = salaryTotal; //应发合计
  498. pm_wsInfo.TotalDeductions = eductionTotal; //扣款合计
  499. pm_wsInfo.TotalRealHair = actualReleaseTotal; //实发合计
  500. pm_wsInfo.AfterTax = actualReleaseTotal - pm_wsInfo.WithholdingTax; //税后工资
  501. pm_wsInfo.LastUpdateUserId = userId;
  502. pm_wsInfo.LastUpdateDt = DateTime.Now;
  503. pm_wsInfo.CreateUserId = userId;
  504. pm_wsInfo.CreateTime = DateTime.Now;
  505. pm_wsInfo.DeleteUserId = null;
  506. pm_wsInfo.DeleteTime = null;
  507. #endregion
  508. }
  509. _result.Code = 0;
  510. _result.Data = pm_WageSheetDattaSources;
  511. return _result;
  512. }
  513. /// <summary>
  514. /// 获取请假类型
  515. /// </summary>
  516. /// <param name="template_id"></param>
  517. /// <returns></returns>
  518. public static async Task<List<VacationLeaveTypeView>> GetVacationLeaveTypes(string template_id)
  519. {
  520. List<VacationLeaveTypeView> vacationLeaveTypes = new List<VacationLeaveTypeView>();
  521. TemplateDetailView templateDetailView = new TemplateDetailView();
  522. templateDetailView = await _qiYeWeChatApiService.GetTemplateDetailAsync(template_id);
  523. if (templateDetailView.errcode != 0)
  524. {
  525. return vacationLeaveTypes;
  526. }
  527. List<VacationItemInfo> VacationItemInfos = templateDetailView.vacation_list.item;
  528. foreach (var item in VacationItemInfos)
  529. {
  530. ValueItem valueInfo = item.name.Where(it => it.lang == "zh_CN").FirstOrDefault();
  531. if (valueInfo != null)
  532. {
  533. vacationLeaveTypes.Add(
  534. new VacationLeaveTypeView()
  535. {
  536. id = item.id,
  537. name = valueInfo.text
  538. });
  539. }
  540. }
  541. return vacationLeaveTypes;
  542. }
  543. /// <summary>
  544. /// 计算类型费用
  545. /// </summary>
  546. /// <param name="leaveType">
  547. /// 1年假;2事假;3病假;4调休假;5婚假;6产假;7陪产假;8其他;9丧假
  548. /// </param>
  549. /// <param name="date_Range_type">
  550. /// halfday 全天
  551. /// hour 小时
  552. /// </param>
  553. /// <param name="startTime"></param>
  554. /// <param name="endTime"></param>
  555. /// <param name="duration"></param>
  556. /// <param name="mealDeduction"></param>
  557. /// <param name="typeDeduction"></param>
  558. public static void CalculateTypeFee(int leaveType, string date_Range_type, string startTime, string endTime,decimal amountPayable,int work_days,
  559. int duration, out decimal mealDeduction, out decimal typeDeduction)
  560. {
  561. typeDeduction = 0;
  562. mealDeduction = 0;
  563. string am_starttime = "08:59";
  564. string am_endtime = "13:01";
  565. decimal personalkLeave_dailywage_day = amountPayable / work_days; //日薪 = 事假日薪 *计算方式:日平均工资 = 当月应发工资 /当月应出勤天数。
  566. //半小时单位
  567. decimal halfHour = Convert.ToDecimal(7.5) / Convert.ToDecimal(0.5);
  568. switch (leaveType)
  569. {
  570. case 1: //年假
  571. CalculateTypeFeeSub(date_Range_type, startTime, endTime, duration, out mealDeduction);
  572. break;
  573. case 2: //2事假
  574. // 事假日薪 *计算方式:日平均工资 = 当月应发工资 /当月应出勤天数。
  575. decimal personalkLeave_dailywage_halfhour = personalkLeave_dailywage_day / halfHour; //事假单位 0.5小时
  576. if (date_Range_type == "halfday")
  577. {
  578. mealDeduction = 10; //餐补扣款
  579. typeDeduction = personalkLeave_dailywage_day;
  580. }
  581. else if (date_Range_type == "hour")
  582. {
  583. int leave_halfHour = duration / Convert.ToInt32(0.5);
  584. typeDeduction = personalkLeave_dailywage_halfhour * leave_halfHour;
  585. if (duration >= 3) //单天请假三小时 && 请假时间在上午 则没有餐补
  586. {
  587. //处理开始时间
  588. if (startTime.CompareTo(am_starttime) > 0 && startTime.CompareTo(am_endtime) < 0)
  589. {
  590. //处理结束时间
  591. if (endTime.CompareTo(am_starttime) > 0 && endTime.CompareTo(am_endtime) < 0)
  592. {
  593. mealDeduction = 10; //餐补扣款
  594. }
  595. }
  596. }
  597. else if (duration > 7.5) //多天计算
  598. {
  599. int leave_halfHour1 = duration / Convert.ToInt32(0.5);
  600. typeDeduction = personalkLeave_dailywage_halfhour * leave_halfHour1;
  601. decimal leaveDays = Convert.ToDecimal(duration / 7.5);
  602. if (leaveDays % 1 == 0)
  603. {
  604. mealDeduction = 10 * leaveDays; //餐补扣款
  605. }
  606. else
  607. {
  608. mealDeduction = 10 * Convert.ToInt32(leaveDays);
  609. //得到最后一天的请假时间 是否有餐补
  610. int lastHours = (Convert.ToDateTime(endTime) - Convert.ToDateTime("09:00")).Hours;
  611. if (lastHours >= 3)
  612. {
  613. //处理结束时间
  614. if (endTime.CompareTo(am_starttime) > 0 && endTime.CompareTo(am_endtime) < 0)
  615. {
  616. mealDeduction += 10; //餐补扣款
  617. }
  618. }
  619. }
  620. }
  621. }
  622. break;
  623. case 3: //3病假
  624. // 病假日薪 *计算方式:日平均工资 = 成都市最低工资标准的80% /当月应出勤天数。 短期病假=当月15天内
  625. decimal chengDuMinimumWage_halrHour = _chengDuMinimumWage / work_days / halfHour;
  626. decimal sickLeave_dailywage_halfhour_deduction = personalkLeave_dailywage_day - chengDuMinimumWage_halrHour; //病假单位 0.5小时 扣款金额
  627. if (date_Range_type == "halfday")
  628. {
  629. mealDeduction = 10; //餐补扣款
  630. typeDeduction = sickLeave_dailywage_halfhour_deduction * halfHour;
  631. }
  632. else if (date_Range_type == "hour")
  633. {
  634. int sickLeave_halfHour = duration / Convert.ToInt32(0.5);
  635. typeDeduction = sickLeave_dailywage_halfhour_deduction *sickLeave_halfHour ;
  636. if (duration >= 3 && duration <= 7.5) //单天请假三小时 && 请假时间在上午 则没有餐补
  637. {
  638. //处理开始时间
  639. if (startTime.CompareTo(am_starttime) > 0 && startTime.CompareTo(am_endtime) < 0)
  640. {
  641. //处理结束时间
  642. if (endTime.CompareTo(am_starttime) > 0 && endTime.CompareTo(am_endtime) < 0)
  643. {
  644. mealDeduction = 10; //餐补扣款
  645. }
  646. }
  647. }
  648. else if (duration > 7.5) //多天计算
  649. {
  650. int sickLeave_halfHour1 = duration / Convert.ToInt32(0.5);
  651. typeDeduction = sickLeave_dailywage_halfhour_deduction * sickLeave_halfHour1;
  652. decimal leaveDays = Convert.ToDecimal(duration / 7.5);
  653. if (leaveDays % 1 == 0)
  654. {
  655. mealDeduction = 10 * leaveDays; //餐补扣款
  656. }
  657. else
  658. {
  659. mealDeduction = 10 * Convert.ToInt32(leaveDays);
  660. //得到最后一天的请假时间 是否有餐补
  661. int lastHours = (Convert.ToDateTime(endTime) - Convert.ToDateTime("09:00")).Hours;
  662. if (lastHours >= 3)
  663. {
  664. //处理结束时间
  665. if (endTime.CompareTo(am_starttime) > 0 && endTime.CompareTo(am_endtime) < 0)
  666. {
  667. mealDeduction += 10; //餐补扣款
  668. }
  669. }
  670. }
  671. }
  672. }
  673. break;
  674. case 4: //4调休假
  675. CalculateTypeFeeSub(date_Range_type, startTime, endTime, duration, out mealDeduction);
  676. break;
  677. case 5: //5婚假
  678. CalculateTypeFeeSub(date_Range_type, startTime, endTime, duration, out mealDeduction);
  679. break;
  680. case 6: //6产假
  681. CalculateTypeFeeSub(date_Range_type, startTime, endTime, duration, out mealDeduction);
  682. break;
  683. case 7: //7陪产假
  684. CalculateTypeFeeSub(date_Range_type, startTime, endTime, duration, out mealDeduction);
  685. break;
  686. case 8: //8其他
  687. CalculateTypeFeeSub(date_Range_type, startTime, endTime, duration, out mealDeduction);
  688. break;
  689. case 9: //9丧假
  690. CalculateTypeFeeSub(date_Range_type, startTime, endTime, duration, out mealDeduction);
  691. break;
  692. }
  693. }
  694. /// <summary>
  695. /// 计算类型费用
  696. /// </summary>
  697. /// <param name="date_Range_type">
  698. /// halfday 全天
  699. /// hour 小时
  700. /// </param>
  701. /// <param name="startTime"></param>
  702. /// <param name="endTime"></param>
  703. /// <param name="duration"></param>
  704. /// <param name="mealDeduction"></param>
  705. public static void CalculateTypeFeeSub(string date_Range_type, string startTime, string endTime, int duration, out decimal mealDeduction)
  706. {
  707. mealDeduction = 0;
  708. string am_starttime = "08:59";
  709. string am_endtime = "13:01";
  710. if (date_Range_type == "halfday")
  711. {
  712. mealDeduction = 10; //餐补扣款
  713. }
  714. else if (date_Range_type == "hour")
  715. {
  716. if (duration >= 3 && duration < 7) //单天请假三小时 && 请假时间在上午 则没有餐补
  717. {
  718. //处理开始时间
  719. if (startTime.CompareTo(am_starttime) > 0 && startTime.CompareTo(am_endtime) < 0)
  720. {
  721. //处理结束时间
  722. if (endTime.CompareTo(am_starttime) > 0 && endTime.CompareTo(am_endtime) < 0)
  723. {
  724. mealDeduction = 10; //餐补扣款
  725. }
  726. }
  727. }
  728. else if (duration >= 7 && duration <= 7.5 )
  729. {
  730. mealDeduction = 10; //餐补扣款
  731. }
  732. else if (duration >= 7.5) //多天计算
  733. {
  734. decimal leaveDays = Convert.ToDecimal(duration / 7.5);
  735. if (leaveDays % 1 == 0)
  736. {
  737. mealDeduction = 10 * leaveDays; //餐补扣款
  738. }
  739. else
  740. {
  741. mealDeduction = 10 * Convert.ToInt32(leaveDays);
  742. //得到最后一天的请假时间 是否有餐补
  743. int lastHours = (Convert.ToDateTime(endTime) - Convert.ToDateTime("09:00")).Hours;
  744. if (lastHours >= 3)
  745. {
  746. //处理结束时间
  747. if (endTime.CompareTo(am_starttime) > 0 && endTime.CompareTo(am_endtime) < 0)
  748. {
  749. mealDeduction += 10; //餐补扣款
  750. }
  751. }
  752. }
  753. }
  754. }
  755. }
  756. /// <summary>
  757. /// 获取打卡补卡类型
  758. /// </summary>
  759. /// <param name="template_id"></param>
  760. /// <returns></returns>
  761. public static async Task<List<VacationLeaveTypeView>> GetVacationReissueCardTypes(string template_id)
  762. {
  763. List<VacationLeaveTypeView> vacationLeaveTypes = new List<VacationLeaveTypeView>();
  764. TemplateDetailView templateDetailView = new TemplateDetailView();
  765. templateDetailView = await _qiYeWeChatApiService.GetTemplateDetailAsync(template_id);
  766. if (templateDetailView.errcode != 0)
  767. {
  768. return vacationLeaveTypes;
  769. }
  770. List<VacationItemInfo> VacationItemInfos = templateDetailView.vacation_list.item;
  771. foreach (var item in VacationItemInfos)
  772. {
  773. ValueItem valueInfo = item.name.Where(it => it.lang == "zh_CN").FirstOrDefault();
  774. if (valueInfo != null)
  775. {
  776. vacationLeaveTypes.Add(
  777. new VacationLeaveTypeView()
  778. {
  779. id = item.id,
  780. name = valueInfo.text
  781. });
  782. }
  783. }
  784. return vacationLeaveTypes;
  785. }
  786. /// <summary>
  787. /// 打卡数据
  788. /// 假勤数据 统计
  789. /// </summary>
  790. /// <param name="datas">数据源</param>
  791. /// <param name="type">
  792. /// 1-请假;2-补卡;3-出差;4-外出;100-外勤;
  793. /// </param>
  794. /// <param name="subTypeName">
  795. /// 年假 事假 病假 调休假 婚嫁 产假 陪产假 丧假 补卡次数 出差 外出数 外勤 其他
  796. /// </param>
  797. /// <returns></returns>
  798. private static int Fallibilitydispose(List<Sp_Item> datas, int type, string? subTypeName)
  799. {
  800. int num = 0;
  801. Sp_Item _Info = datas.Where(it => it.type == type && it.name == subTypeName).FirstOrDefault();
  802. if (_Info != null) { num = _Info.count; }
  803. return num;
  804. }
  805. /// <summary>
  806. /// 打卡数据
  807. /// 异常数据 统计
  808. /// </summary>
  809. /// <returns></returns>
  810. private static int ExceptionStatistics(List<Exception_Info> datas, int type)
  811. {
  812. int num = 0;
  813. Exception_Info _Info = datas.Where(it => it.exception == type).FirstOrDefault();
  814. if (_Info != null) { num = _Info.count; }
  815. return num;
  816. }
  817. }
  818. }