PayrollComputation.cs 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368
  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> SalaryCalculatorAsync(
  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 = GetWorkDays(startDt, endDt);
  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> SalaryCalculatorAsync1(
  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 = GetWorkDays(startDt, endDt);
  629. UserIdListView userIdListView = await _qiYeWeChatApiService.GetUserIdListAsync();
  630. if (userIdListView.errcode != 0)
  631. {
  632. _result.Msg = "【企业微信】【打卡】【获取员工ID】【Msg】" + userIdListView.errmsg;
  633. return _result;
  634. }
  635. List<string> qyWhchatIdList = userIdListView.dept_user.Select(it => it.userid).ToList();
  636. CheckInDayDataView checkInDayDataView = await _qiYeWeChatApiService.GetCheckInDayDataAsync(qyWhchatIdList, startDt, endDt);
  637. if (checkInDayDataView.errcode != 0)
  638. {
  639. _result.Msg = "【企业微信】【打卡】【获取时间段内所有日打卡】【Msg】" + checkInDayDataView.errmsg;
  640. return _result;
  641. }
  642. //筛选出工作日日报
  643. List<Root> workday_userRoots = checkInDayDataView.datas.Where(it => it.base_info.day_type == 0).ToList(); //工作日日报
  644. //获取 请假类型 Sp_Detail.template_id
  645. string leave_template_id = "C4NzTJCh1onCUK915rRkvy7Fh5Vqz4YbiEV9jrBY1";
  646. List<VacationLeaveTypeView> vacationLeaveTypes = await GetVacationLeaveTypes(leave_template_id);
  647. if (vacationLeaveTypes.Count <= 0)
  648. {
  649. _result.Msg = "【企业微信】【审批】【获取审批类型】【Msg】" + startDt + " - " + endDt + "请假 类型数据 获取失败!";
  650. return _result;
  651. }
  652. try
  653. {
  654. foreach (var pm_wsInfo in pm_WageSheetDattaSources)
  655. {
  656. string itemName = userNames.Where(it => it.Id == pm_wsInfo.UserId).FirstOrDefault().CnName;
  657. //补贴 金额
  658. decimal meal_subsidy = 0.00M; // 午餐(午餐10元/天) 补贴 * 计算方式:单日上午请假时长(小时)大于或者等于三小时 没有餐补
  659. //事假 病假 总金额
  660. decimal personalLeaveTotal = 0.00M, // 事假 日薪 *计算方式:日平均工资 = 月工资/当月应出勤天数。
  661. sickLeaveTotal = 0.00M; // 病假 日薪 *计算方式:日平均工资 = 成都市最低工资标准的80%/当月应出勤天数。 短期病假=当月15天内
  662. //扣款金额
  663. decimal beLate_deduction = 0.00M, // 迟到 扣款金额 *计算方式:
  664. // 一个自然月内,不足 10 分钟的迟到/早退,不超过 2 次的部分,不做处罚;3 次及以上,按50元 / 次处罚;
  665. // 超过 10 分钟(含 10 分钟),不足 60 分钟的迟到/早退,按 50 元/次处罚;
  666. // 超过 60 分钟(含 60 分钟),不足 3 小时的迟到/早退,且无请假者,按旷工半日处理;超过3 小时的迟到 / 早退,且无请假者,按旷工一日处理。
  667. early_deduction = 0.00M, // 早退 扣款金额
  668. absenteeism_deduction = 0.00M, // 旷工 扣款金额 *计算方式:旷工扣发当日工资
  669. unprinted_deduction = 0.00M, // 未打卡 扣款金额 *计算方式:
  670. // 试用期员工每月有 2 次 补卡机会,超过 2 次不足 5 次的部分,按 10 元 / 次处罚,5 次及以上的漏卡,按 50 元 / 次处罚;
  671. // 正式员工每月 3 次以内的补卡,按 10 元 / 次处罚,3 次及以上的漏卡,按 50 元 / 次处罚。
  672. sickLeave_deduction = 0.00M, // 病假
  673. other_deduction = 0.00M; // 其他 扣款金额
  674. decimal meal_deduction = 0.00M; // 餐补 扣款金额
  675. decimal reissuecard_deduction = 0.00M; // 补卡 扣款金额
  676. #region 计算日工资 正常日薪 事假日薪 病假日薪
  677. //月 - 应发工资
  678. decimal amountPayable = pm_wsInfo.Basic + pm_wsInfo.Floats + pm_wsInfo.PostAllowance + pm_wsInfo.InformationSecurityFee + pm_wsInfo.OtherSubsidies;
  679. // 日薪 = *计算方式:日平均工资 = 月工资/当月应出勤天数。
  680. decimal dailyWage = ConvertToDecimal(amountPayable / work_days);
  681. // 病假日薪 *计算方式:日平均工资 = 成都市最低工资标准的80%/当月应出勤天数。 短期病假=当月15天内
  682. decimal sickLeave_dailywage = ConvertToDecimal(_chengDuMinimumWage / work_days);
  683. //病假 一天扣款
  684. sickLeave_deduction = dailyWage - sickLeave_dailywage;
  685. List<Ex_Items> ex_Items = new List<Ex_Items>();//假勤 And 打卡备注集合
  686. #endregion
  687. List<Root> userRoots = workday_userRoots.Where(it => it.base_info.name == itemName && it.base_info.day_type == 0).ToList(); //工作日日报
  688. int dk_work_days = userRoots.Count; //应出勤天数
  689. meal_subsidy = dk_work_days * 10; //应发放餐补
  690. if (!itemName.Equals("张海麟"))
  691. {
  692. foreach (var root in userRoots)
  693. {
  694. List<Holiday_infos> holiday_Infos = root.holiday_infos; //当天假勤信息
  695. List<Exception_infos> exception_infos = root.exception_infos; //当天校准状态信息
  696. List<Sp_items> sp_Items = root.sp_items;//当天假勤统计信息
  697. #region 假勤处理
  698. if (sp_Items.Count > 0)
  699. {
  700. }
  701. #endregion
  702. #region 打卡补卡
  703. #endregion
  704. #region 迟到 早退 矿工
  705. #endregion
  706. }
  707. }
  708. else
  709. {
  710. meal_subsidy = work_days * 10.00M;
  711. }
  712. #region 应发合计 实发合计 扣款合计(假勤扣款,其他扣款,社保扣款,公积金代扣,个税扣款)
  713. decimal mealTotal = meal_subsidy - meal_deduction; //餐补
  714. decimal salaryTotal = 0.00M;
  715. if (dk_work_days >= work_days)
  716. {
  717. dk_work_days = work_days;
  718. salaryTotal = amountPayable + mealTotal; //应发合计
  719. }
  720. else
  721. {
  722. salaryTotal = (dk_work_days * dailyWage) + mealTotal; //应发合计
  723. }
  724. //扣款合计 不含个税
  725. decimal eductionTotal = sickLeaveTotal + personalLeaveTotal + beLate_deduction + early_deduction + absenteeism_deduction + unprinted_deduction + other_deduction +
  726. pm_wsInfo.WithholdingInsurance + pm_wsInfo.ReservedFunds + pm_wsInfo.OtherDeductions;
  727. decimal actualReleaseTotal = salaryTotal - eductionTotal; //实发合计 * 不含个税
  728. #endregion
  729. #region 处理当月工资数据
  730. pm_wsInfo.YearMonth = thisYearMonth;
  731. pm_wsInfo.StartDate = startDt.ToString("yyyy-MM-dd");
  732. pm_wsInfo.EndDate = endDt.AddDays(-1).ToString("yyyy-MM-dd");
  733. pm_wsInfo.WorkDays = work_days; //当月应出勤天数
  734. pm_wsInfo.RegularDays = dk_work_days; //当月正常出勤天数
  735. pm_wsInfo.SickLeave = sickLeaveTotal; //病假
  736. pm_wsInfo.SomethingFalse = personalLeaveTotal; //事假
  737. pm_wsInfo.LateTo = beLate_deduction; //迟到
  738. pm_wsInfo.LeaveEarly = early_deduction; //早退
  739. pm_wsInfo.Absenteeism = absenteeism_deduction; //旷工
  740. pm_wsInfo.NotPunch = unprinted_deduction; //未打卡
  741. pm_wsInfo.OtherDeductions = other_deduction; //其他
  742. pm_wsInfo.Ex_ItemsRemark = JsonConvert.SerializeObject(ex_Items); //
  743. pm_wsInfo.Mealsupplement = mealTotal; //餐补
  744. pm_wsInfo.Should = salaryTotal; //应发合计
  745. pm_wsInfo.TotalDeductions = eductionTotal; //扣款合计
  746. pm_wsInfo.TotalRealHair = actualReleaseTotal; //实发合计
  747. pm_wsInfo.AfterTax = actualReleaseTotal - pm_wsInfo.WithholdingTax; //税后工资
  748. pm_wsInfo.LastUpdateUserId = userId;
  749. pm_wsInfo.LastUpdateDt = DateTime.Now;
  750. pm_wsInfo.CreateUserId = userId;
  751. pm_wsInfo.CreateTime = DateTime.Now;
  752. pm_wsInfo.DeleteUserId = null;
  753. pm_wsInfo.DeleteTime = null;
  754. #endregion
  755. }
  756. }
  757. catch (Exception ex)
  758. {
  759. _result.Msg = ex.Message;
  760. return _result;
  761. }
  762. _result.Code = 0;
  763. _result.Data = pm_WageSheetDattaSources;
  764. return _result;
  765. }
  766. /// <summary>
  767. /// decimal 保留两位小数 不四舍五入
  768. /// </summary>
  769. /// <param name="number"></param>
  770. /// <returns></returns>
  771. public static decimal ConvertToDecimal(decimal number)
  772. {
  773. return Convert.ToDecimal(number.ToString("0.00"));
  774. }
  775. /// <summary>
  776. /// 获取请假类型
  777. /// </summary>
  778. /// <param name="template_id"></param>
  779. /// <returns></returns>
  780. public static async Task<List<VacationLeaveTypeView>> GetVacationLeaveTypes(string template_id)
  781. {
  782. List<VacationLeaveTypeView> vacationLeaveTypes = new List<VacationLeaveTypeView>();
  783. TemplateDetailView templateDetailView = new TemplateDetailView();
  784. templateDetailView = await _qiYeWeChatApiService.GetTemplateDetailAsync(template_id);
  785. if (templateDetailView.errcode != 0)
  786. {
  787. Serilog.Log.Error("【企业微信】【审批】【获取假勤类型的审批】【Msg】"+ templateDetailView.errmsg);
  788. return vacationLeaveTypes;
  789. }
  790. List<VacationItemInfo> VacationItemInfos = templateDetailView.vacation_list.item;
  791. foreach (var item in VacationItemInfos)
  792. {
  793. ValueItem valueInfo = item.name.Where(it => it.lang == "zh_CN").FirstOrDefault();
  794. if (valueInfo != null)
  795. {
  796. vacationLeaveTypes.Add(
  797. new VacationLeaveTypeView()
  798. {
  799. id = item.id,
  800. name = valueInfo.text
  801. });
  802. }
  803. }
  804. return vacationLeaveTypes;
  805. }
  806. /// <summary>
  807. /// 计算类型费用
  808. /// </summary>
  809. /// <param name="leaveType">
  810. /// 1年假;2事假;3病假;4调休假;5婚假;6产假;7陪产假;8其他;9丧假
  811. /// </param>
  812. /// <param name="date_Range_type">
  813. /// halfday 全天
  814. /// hour 小时
  815. /// </param>
  816. /// <param name="startTime"></param>
  817. /// <param name="endTime"></param>
  818. /// <param name="duration"></param>
  819. /// <param name="mealDeduction"></param>
  820. /// <param name="typeDeduction"></param>
  821. public static void CalculateTypeFee(int leaveType, string date_Range_type, string startTime, string endTime,decimal amountPayable,int work_days,
  822. decimal duration, out decimal mealDeduction, out decimal typeDeduction)
  823. {
  824. typeDeduction = 0;
  825. mealDeduction = 0;
  826. string am_starttime = "08:59";
  827. string am_endtime = "13:01";
  828. decimal personalkLeave_dailywage_day = ConvertToDecimal( amountPayable / work_days); //日薪 = 事假日薪 *计算方式:日平均工资 = 当月应发工资 /当月应出勤天数。
  829. //半小时单位
  830. decimal halfHour = Convert.ToDecimal(7.5) / Convert.ToDecimal(0.5);
  831. switch (leaveType)
  832. {
  833. case 1: //年假
  834. CalculateTypeFeeSub(date_Range_type, startTime, endTime, duration, out mealDeduction);
  835. break;
  836. case 2: //2事假
  837. // 事假日薪 *计算方式:日平均工资 = 当月应发工资 /当月应出勤天数。
  838. decimal personalkLeave_dailywage_halfhour = ConvertToDecimal( personalkLeave_dailywage_day / halfHour); //事假单位 0.5小时
  839. if (date_Range_type == "halfday")
  840. {
  841. mealDeduction = 10; //餐补扣款
  842. typeDeduction = personalkLeave_dailywage_day;
  843. }
  844. else if (date_Range_type == "hour")
  845. {
  846. decimal leave_halfHour = Convert.ToDecimal(duration) / Convert.ToDecimal(0.5);
  847. typeDeduction = personalkLeave_dailywage_halfhour * leave_halfHour;
  848. if (duration >= 3 && duration <= 7.5M) //单天请假三小时 && 请假时间在上午 则没有餐补
  849. {
  850. //处理开始时间
  851. if (startTime.CompareTo(am_starttime) > 0 && startTime.CompareTo(am_endtime) < 0)
  852. {
  853. //处理结束时间
  854. //if (endTime.CompareTo(am_starttime) > 0 && endTime.CompareTo(am_endtime) > 0)
  855. //{
  856. mealDeduction = 10; //餐补扣款
  857. //}
  858. }
  859. }
  860. else if (duration > 7.5M) //多天计算
  861. {
  862. decimal leave_halfHour1 = Convert.ToDecimal(duration) / Convert.ToDecimal(0.5);
  863. typeDeduction = personalkLeave_dailywage_halfhour * leave_halfHour1;
  864. decimal leaveDays = duration / 7.5M;
  865. if (leaveDays % 1 == 0)
  866. {
  867. mealDeduction = 10 * leaveDays; //餐补扣款
  868. }
  869. else
  870. {
  871. mealDeduction = 10 * Convert.ToInt32(leaveDays);
  872. //得到最后一天的请假时间 是否有餐补
  873. int lastHours = (Convert.ToDateTime(endTime) - Convert.ToDateTime("09:00")).Hours;
  874. if (lastHours >= 3)
  875. {
  876. //处理结束时间
  877. if (endTime.CompareTo(am_starttime) > 0 && endTime.CompareTo(am_endtime) < 0)
  878. {
  879. mealDeduction += 10; //餐补扣款
  880. }
  881. }
  882. }
  883. }
  884. }
  885. break;
  886. case 3: //3病假
  887. // 病假日薪 *计算方式:日平均工资 = 成都市最低工资标准的80% /当月应出勤天数。 短期病假=当月15天内
  888. decimal chengDuMinimumWage_halrHour = ConvertToDecimal( _chengDuMinimumWage / work_days) / halfHour;
  889. decimal sickLeave_dailywage_halfhour_deduction = personalkLeave_dailywage_day - chengDuMinimumWage_halrHour; //病假单位 0.5小时 扣款金额
  890. if (date_Range_type == "halfday")
  891. {
  892. mealDeduction = 10; //餐补扣款
  893. typeDeduction = sickLeave_dailywage_halfhour_deduction * halfHour;
  894. }
  895. else if (date_Range_type == "hour")
  896. {
  897. decimal sickLeave_halfHour = duration / 0.5M;
  898. typeDeduction = sickLeave_dailywage_halfhour_deduction *sickLeave_halfHour ;
  899. if (duration >= 3 && duration <= 7.5M) //单天请假三小时 && 请假时间在上午 则没有餐补
  900. {
  901. //处理开始时间
  902. if (startTime.CompareTo(am_starttime) > 0 && startTime.CompareTo(am_endtime) < 0)
  903. {
  904. //处理结束时间
  905. if (endTime.CompareTo(am_starttime) > 0 && endTime.CompareTo(am_endtime) < 0)
  906. {
  907. mealDeduction = 10; //餐补扣款
  908. }
  909. }
  910. }
  911. else if (duration > 7.5M) //多天计算
  912. {
  913. decimal sickLeave_halfHour1 = duration / 0.5M;
  914. typeDeduction = sickLeave_dailywage_halfhour_deduction * sickLeave_halfHour1;
  915. decimal leaveDays = Convert.ToDecimal(duration / 7.5M);
  916. if (leaveDays % 1 == 0)
  917. {
  918. mealDeduction = 10 * leaveDays; //餐补扣款
  919. }
  920. else
  921. {
  922. mealDeduction = 10 * Convert.ToInt32(leaveDays);
  923. //得到最后一天的请假时间 是否有餐补
  924. int lastHours = (Convert.ToDateTime(endTime) - Convert.ToDateTime("09:00")).Hours;
  925. if (lastHours >= 3)
  926. {
  927. //处理结束时间
  928. if (endTime.CompareTo(am_starttime) > 0 && endTime.CompareTo(am_endtime) < 0)
  929. {
  930. mealDeduction += 10; //餐补扣款
  931. }
  932. }
  933. }
  934. }
  935. }
  936. break;
  937. case 4: //4调休假
  938. CalculateTypeFeeSub(date_Range_type, startTime, endTime, duration, out mealDeduction);
  939. break;
  940. case 5: //5婚假
  941. CalculateTypeFeeSub(date_Range_type, startTime, endTime, duration, out mealDeduction);
  942. break;
  943. case 6: //6产假
  944. CalculateTypeFeeSub(date_Range_type, startTime, endTime, duration, out mealDeduction);
  945. break;
  946. case 7: //7陪产假
  947. CalculateTypeFeeSub(date_Range_type, startTime, endTime, duration, out mealDeduction);
  948. break;
  949. case 8: //8其他
  950. CalculateTypeFeeSub(date_Range_type, startTime, endTime, duration, out mealDeduction);
  951. break;
  952. case 9: //9丧假
  953. CalculateTypeFeeSub(date_Range_type, startTime, endTime, duration, out mealDeduction);
  954. break;
  955. }
  956. }
  957. /// <summary>
  958. /// 计算类型费用
  959. /// </summary>
  960. /// <param name="date_Range_type">
  961. /// halfday 全天
  962. /// hour 小时
  963. /// </param>
  964. /// <param name="startTime"></param>
  965. /// <param name="endTime"></param>
  966. /// <param name="duration"></param>
  967. /// <param name="mealDeduction"></param>
  968. public static void CalculateTypeFeeSub(string date_Range_type, string startTime, string endTime, decimal duration, out decimal mealDeduction)
  969. {
  970. mealDeduction = 0;
  971. string am_starttime = "08:59";
  972. string am_endtime = "13:01";
  973. if (date_Range_type == "halfday")
  974. {
  975. mealDeduction = 10; //餐补扣款
  976. }
  977. else if (date_Range_type == "hour")
  978. {
  979. if (duration >= 3 && duration < 7) //单天请假三小时 && 请假时间在上午 则没有餐补
  980. {
  981. //处理开始时间
  982. if (startTime.CompareTo(am_starttime) > 0 && startTime.CompareTo(am_endtime) < 0)
  983. {
  984. //处理结束时间
  985. if (endTime.CompareTo(am_starttime) > 0 && endTime.CompareTo(am_endtime) < 0)
  986. {
  987. mealDeduction = 10; //餐补扣款
  988. }
  989. }
  990. }
  991. else if (duration >= 7 && duration <= 7.50M )
  992. {
  993. mealDeduction = 10; //餐补扣款
  994. }
  995. else if (duration >= 7.50M) //多天计算
  996. {
  997. decimal leaveDays = Convert.ToDecimal(duration / 7.50M);
  998. if (leaveDays % 1 == 0)
  999. {
  1000. mealDeduction = 10 * leaveDays; //餐补扣款
  1001. }
  1002. else
  1003. {
  1004. mealDeduction = 10 * Convert.ToInt32(leaveDays);
  1005. //得到最后一天的请假时间 是否有餐补
  1006. int lastHours = (Convert.ToDateTime(endTime) - Convert.ToDateTime("09:00")).Hours;
  1007. if (lastHours >= 3)
  1008. {
  1009. //处理结束时间
  1010. if (endTime.CompareTo(am_starttime) > 0 && endTime.CompareTo(am_endtime) < 0)
  1011. {
  1012. mealDeduction += 10; //餐补扣款
  1013. }
  1014. }
  1015. }
  1016. }
  1017. }
  1018. }
  1019. /// <summary>
  1020. /// 获取打卡补卡类型
  1021. /// </summary>
  1022. /// <param name="template_id"></param>
  1023. /// <returns></returns>
  1024. public static async Task<List<VacationLeaveTypeView>> GetVacationReissueCardTypes(string template_id)
  1025. {
  1026. List<VacationLeaveTypeView> vacationLeaveTypes = new List<VacationLeaveTypeView>();
  1027. TemplateDetailView templateDetailView = new TemplateDetailView();
  1028. templateDetailView = await _qiYeWeChatApiService.GetTemplateDetailAsync(template_id);
  1029. if (templateDetailView.errcode != 0)
  1030. {
  1031. return vacationLeaveTypes;
  1032. }
  1033. List<VacationItemInfo> VacationItemInfos = templateDetailView.vacation_list.item;
  1034. foreach (var item in VacationItemInfos)
  1035. {
  1036. ValueItem valueInfo = item.name.Where(it => it.lang == "zh_CN").FirstOrDefault();
  1037. if (valueInfo != null)
  1038. {
  1039. vacationLeaveTypes.Add(
  1040. new VacationLeaveTypeView()
  1041. {
  1042. id = item.id,
  1043. name = valueInfo.text
  1044. });
  1045. }
  1046. }
  1047. return vacationLeaveTypes;
  1048. }
  1049. /// <summary>
  1050. /// 打卡数据
  1051. /// 假勤数据 统计
  1052. /// </summary>
  1053. /// <param name="datas">数据源</param>
  1054. /// <param name="type">
  1055. /// 1-请假;2-补卡;3-出差;4-外出;100-外勤;
  1056. /// </param>
  1057. /// <param name="subTypeName">
  1058. /// 年假 事假 病假 调休假 婚嫁 产假 陪产假 丧假 补卡次数 出差 外出数 外勤 其他
  1059. /// </param>
  1060. /// <returns></returns>
  1061. private static int Fallibilitydispose(List<Sp_Item> datas, int type, string? subTypeName)
  1062. {
  1063. int num = 0;
  1064. Sp_Item _Info = datas.Where(it => it.type == type && it.name == subTypeName).FirstOrDefault();
  1065. if (_Info != null) { num = _Info.count; }
  1066. return num;
  1067. }
  1068. /// <summary>
  1069. /// 打卡数据
  1070. /// 异常数据 统计
  1071. /// </summary>
  1072. /// <returns></returns>
  1073. private static int ExceptionStatistics(List<Exception_Info> datas, int type)
  1074. {
  1075. int num = 0;
  1076. Exception_Info _Info = datas.Where(it => it.exception == type).FirstOrDefault();
  1077. if (_Info != null) { num = _Info.count; }
  1078. return num;
  1079. }
  1080. /// <summary>
  1081. /// 获取时间段内除周末 节假日外的 工作日
  1082. /// </summary>
  1083. /// <param name="startDt"></param>
  1084. /// <param name="endDt"></param>
  1085. /// <returns></returns>
  1086. public static int GetWorkDays(DateTime startDt,DateTime endDt)
  1087. {
  1088. string startYear = startDt.ToString("yyyy");
  1089. string endYear = endDt.ToString("yyyy");
  1090. var holidays = AppSettingsHelper.Get<HoliDaysDataSourceView>("HoliDayDataSource");
  1091. List<HoliDaysDataSourceView> holiDatas = new List<HoliDaysDataSourceView>();
  1092. if (startYear.Equals(endYear))
  1093. {
  1094. holiDatas.Add(holidays.Where(it => it.Year == startYear).FirstOrDefault());
  1095. }
  1096. else
  1097. {
  1098. holiDatas.Add(holidays.Where(it => it.Year == startYear).FirstOrDefault());
  1099. holiDatas.Add(holidays.Where(it => it.Year == endYear).FirstOrDefault());
  1100. }
  1101. int _totalDays = (int)(endDt - startDt).TotalDays;
  1102. List<HolidaysInfo> _holidays = new List<HolidaysInfo>();
  1103. List<HolidaysInfo> _weekdys = new List<HolidaysInfo>();
  1104. List<HolidaysInfo> _workdays = new List<HolidaysInfo>();
  1105. string[] Day = new string[] { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
  1106. for (int i = 0; i <= _totalDays; i++)
  1107. {
  1108. string thisYear = startDt.ToString("yyyy");
  1109. string thisDt = startDt.ToString("MM-dd");
  1110. string thisYMD = startDt.ToString("yyyy-MM-dd");
  1111. string thisWeek = Day[Convert.ToInt32(startDt.DayOfWeek.ToString("d"))].ToString();
  1112. HoliDaysDataSourceView holiDaysData = new HoliDaysDataSourceView();
  1113. holiDaysData = holiDatas.Where(it => it.Year == thisYear).FirstOrDefault();
  1114. //周末
  1115. if (thisWeek.Equals("星期六") || thisWeek.Equals("星期日"))
  1116. {
  1117. HolidaysInfo holidaysInfo = new HolidaysInfo();
  1118. holidaysInfo = holiDaysData.Holidays.Where(it => it.HoliDate == thisDt).FirstOrDefault();
  1119. if (holidaysInfo != null)
  1120. {
  1121. if (holidaysInfo.HoliName.Equals("工作日"))
  1122. {
  1123. _workdays.Add(new HolidaysInfo { HoliDate = thisYMD, HoliName = Day[Convert.ToInt32(startDt.DayOfWeek.ToString("d"))].ToString() });
  1124. startDt = startDt.AddDays(1);
  1125. continue;
  1126. }
  1127. }
  1128. _weekdys.Add(new HolidaysInfo { HoliDate = thisYMD, HoliName = thisWeek });
  1129. startDt = startDt.AddDays(1);
  1130. continue;
  1131. }
  1132. //节假日
  1133. if (holiDaysData != null)
  1134. {
  1135. HolidaysInfo holidaysInfo = new HolidaysInfo();
  1136. holidaysInfo = holiDaysData.Holidays.Where(it => it.HoliDate == thisDt).FirstOrDefault();
  1137. if (holidaysInfo != null)
  1138. {
  1139. _holidays.Add(new HolidaysInfo { HoliDate = thisYMD, HoliName = holidaysInfo.HoliName });
  1140. startDt = startDt.AddDays(1);
  1141. continue;
  1142. }
  1143. }
  1144. //工作日
  1145. _workdays.Add(new HolidaysInfo { HoliDate = thisYMD, HoliName = Day[Convert.ToInt32(startDt.DayOfWeek.ToString("d"))].ToString() });
  1146. startDt = startDt.AddDays(1);
  1147. }
  1148. return _workdays.Count();
  1149. }
  1150. }
  1151. }