PayrollComputation.cs 40 KB

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