PersonnelModuleController.cs 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881
  1. using Autofac.Diagnostics;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Microsoft.AspNetCore.Mvc.RazorPages;
  4. using OASystem.API.OAMethodLib.QiYeWeChatAPI;
  5. using OASystem.Domain;
  6. using OASystem.Domain.Dtos.PersonnelModule;
  7. using OASystem.Domain.Dtos.QiYeWeChat;
  8. using OASystem.Domain.Entities.PersonnelModule;
  9. using OASystem.Domain.ViewModels.JuHeExchangeRate;
  10. using OASystem.Domain.ViewModels.PersonnelModule;
  11. using OASystem.Domain.ViewModels.QiYeWeChat;
  12. using OASystem.Infrastructure.Repositories.PersonnelModule;
  13. using SqlSugar;
  14. using StackExchange.Redis;
  15. using System.Collections.Generic;
  16. using System.Globalization;
  17. namespace OASystem.API.Controllers
  18. {
  19. /// <summary>
  20. /// 人事模块
  21. /// </summary>
  22. [Route("api/[controller]/[action]")]
  23. public class PersonnelModuleController : ControllerBase
  24. {
  25. private Result _result;
  26. private readonly IMapper _mapper;
  27. private readonly decimal _chengDuMinimumWage = 2100.00M;
  28. private readonly IQiYeWeChatApiService _qiYeWeChatApiService;
  29. private readonly WageSheetRepository _wageSheetRep;
  30. private readonly UsersRepository _usersRep;
  31. /// <summary>
  32. /// 初始化
  33. /// </summary>
  34. /// <param name="qiYeWeChatApiService"></param>
  35. /// <param name="wageSheetRep"></param>
  36. /// <param name="usersRep"></param>
  37. /// <param name="mapper"></param>
  38. public PersonnelModuleController(IQiYeWeChatApiService qiYeWeChatApiService,WageSheetRepository wageSheetRep, UsersRepository usersRep, IMapper mapper)
  39. {
  40. _mapper = mapper;
  41. _usersRep = usersRep;
  42. _qiYeWeChatApiService = qiYeWeChatApiService;
  43. _wageSheetRep = wageSheetRep;
  44. _result = new Result();
  45. }
  46. #region 工资表单
  47. /// <summary>
  48. /// 工资表单 基础数据源
  49. /// </summary>
  50. /// <returns></returns>
  51. [HttpPost]
  52. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  53. public async Task<IActionResult> GetWageSheetBasicsDataSource()
  54. {
  55. //获取OA系统内所有用户
  56. var nameData = await _usersRep.GetUserNameList(1);
  57. if (nameData.Code != 0)
  58. {
  59. return Ok(JsonView(false, nameData.Msg));
  60. }
  61. var data = new {
  62. userNames = nameData.Data
  63. };
  64. return Ok(JsonView(true, "查询成功!", data));
  65. }
  66. /// <summary>
  67. /// 获取工资表单
  68. /// </summary>
  69. /// <param name="dto"></param>
  70. /// <returns></returns>
  71. [HttpPost]
  72. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  73. public async Task<IActionResult> GetWageSheetList(WageSheetListDto dto)
  74. {
  75. //参数处理
  76. string ymFormat = "yyyy-MM";
  77. DateTime yearMonthDt;
  78. bool yearMonthDttIsValid = DateTime.TryParseExact(dto.YearMonth, ymFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out yearMonthDt);
  79. if (!yearMonthDttIsValid)
  80. {
  81. _result.Msg = "年月格式错误!正确时间格式:yyyy-MM ";
  82. return Ok(JsonView(false, _result.Msg));
  83. }
  84. //获取月工资数据
  85. string yearMonth = yearMonthDt.ToString("yyyy-MM");
  86. string startDt = yearMonthDt.AddDays(-1).ToString("yyyy-MM") + "-28",
  87. endDt = yearMonth + "-27";
  88. //应发合计 = 基本工资 +绩效工资 + 岗位津贴 + 员工的岗位津贴 + 服装洗理补贴 + 通讯补贴 + 交通补贴 + 保密费 + 操作奖金+ 其他补贴 + 部门集体团建费 + 代扣保险 + 代扣公积金 + 餐补
  89. //事假 病假 合计
  90. //扣款合计 = 迟到 + 早退 + 矿工 + 未打卡 + 其他扣款
  91. _result = await _wageSheetRep.Get_WageSheet_ListByYearMonthAsync(yearMonth);
  92. if (_result.Code != 0)
  93. {
  94. return Ok(JsonView(false, _result.Msg));
  95. }
  96. if (dto.PortType == 1)
  97. {
  98. }
  99. else if (dto.PortType == 2)
  100. { }
  101. else if (dto.PortType == 3)
  102. { }
  103. else
  104. {
  105. return Ok(JsonView(false, "请选择正确的端口参数"));
  106. }
  107. return Ok(JsonView(true, _result.Msg, _result.Data));
  108. }
  109. /// <summary>
  110. /// 获取工资 详情
  111. /// </summary>
  112. /// <param name="dto"></param>
  113. /// <returns></returns>
  114. [HttpPost]
  115. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  116. public async Task<IActionResult> GetWageSheetById(WageSheetInfoDto dto)
  117. {
  118. if (dto.PortType == 1)
  119. {
  120. _result = await _wageSheetRep.Get_WageSheet_InfoByIdAsync(dto.Id);
  121. if (_result.Code != 0)
  122. {
  123. return Ok(JsonView(false, _result.Msg));
  124. }
  125. }
  126. else if (dto.PortType == 2)
  127. { }
  128. else if (dto.PortType == 3)
  129. { }
  130. else
  131. {
  132. return Ok(JsonView(false, "请选择正确的端口参数"));
  133. }
  134. return Ok(JsonView(true, _result.Msg, _result.Data));
  135. }
  136. /// <summary>
  137. /// 人事模块 工资表单 删除
  138. /// </summary>
  139. /// <param name="dto"></param>
  140. /// <returns></returns>
  141. [HttpPost]
  142. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  143. public async Task<IActionResult> PostWageSheetDel(WageDelDto dto)
  144. {
  145. try
  146. {
  147. _result = await _wageSheetRep.Post_WageSheet_DelAsync(dto);
  148. if (_result.Code != 0)
  149. {
  150. return Ok(JsonView(false, _result.Msg));
  151. }
  152. }
  153. catch (Exception ex)
  154. {
  155. return Ok(JsonView(false, ex.Message));
  156. }
  157. return Ok(JsonView(true, _result.Msg, _result.Data));
  158. }
  159. /// <summary>
  160. /// 人事模块 工资表单 添加 Or 修改
  161. /// </summary>
  162. /// <param name="dto"></param>
  163. /// <returns></returns>
  164. [HttpPost]
  165. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  166. public async Task<IActionResult> PostWageSheetAddOrEdit(WageAddOrEditDto dto)
  167. {
  168. try
  169. {
  170. _result = await _wageSheetRep.Post_WageSheet_AddOrEditAsync(dto);
  171. if (_result.Code != 0)
  172. {
  173. return Ok(JsonView(false, _result.Msg));
  174. }
  175. }
  176. catch (Exception ex)
  177. {
  178. return Ok(JsonView(false, ex.Message));
  179. }
  180. return Ok(JsonView(true, _result.Msg, _result.Data));
  181. }
  182. /// <summary>
  183. /// 计算工资
  184. /// </summary>
  185. /// <returns></returns>
  186. [HttpPost]
  187. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  188. public async Task<IActionResult> SalaryCalculatorAsync(SalaryCalculatorDto dto)
  189. {
  190. Result result = new Result();
  191. //参数处理
  192. string ymFormat = "yyyy-MM";
  193. DateTime yearMonthDt;
  194. bool yearMonthDttIsValid = DateTime.TryParseExact(dto.yearMonth, ymFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out yearMonthDt);
  195. if (!yearMonthDttIsValid)
  196. {
  197. return Ok(JsonView(false, "年月格式错误!正确时间格式:yyyy-MM "));
  198. }
  199. string thisYearMonth = dto.yearMonth;
  200. string preYearMonth = yearMonthDt.AddMonths(-1).ToString("yyyy-MM");
  201. //本月工资是否有数据 有数据则不计算
  202. result = await _wageSheetRep.Get_WageSheet_ListByYearMonthAsync(thisYearMonth);
  203. if (result.Code == 0 )
  204. {
  205. return Ok(JsonView(false, thisYearMonth + " 工资数据已存在,若无人员工资请手动添加!"));
  206. }
  207. //获取上个月工资信息
  208. DateTime startDt = Convert.ToDateTime(yearMonthDt.AddMonths(-1).ToString("yyyy-MM") + "-28");
  209. DateTime endDt = Convert.ToDateTime(yearMonthDt.ToString("yyyy-MM") + "-27");
  210. string preWageSheetSql = string.Format(@"Select sys_u1.CnName Name,pm_ws.* From Pm_WageSheet pm_ws
  211. Left Join Sys_Users sys_u1 On pm_ws.UserId = sys_u1.Id Where pm_ws.IsDel = 0 And YearMonth ='{0}'", preYearMonth);
  212. List<WageSheetInfos> preWageSheetItems = await _wageSheetRep._sqlSugar.SqlQueryable<WageSheetInfos>(preWageSheetSql).ToListAsync();
  213. if (preWageSheetItems.Count <= 0)
  214. {
  215. return Ok(JsonView(false, preYearMonth + " 工资数据不存在,请手动添加!"));
  216. }
  217. //获取OA系统内所有用户
  218. var nameData = await _usersRep.GetUserNameList(1);
  219. List<UserNameView>? userNames = nameData.Data;
  220. //获取所有打卡数据
  221. CheckInView checkIn = await _qiYeWeChatApiService.GetCheckin_MonthDataAsync(startDt, endDt); //时间段内所有 打卡数据
  222. if (checkIn.errcode != 0)
  223. {
  224. return Ok(JsonView(false, checkIn.errmsg));
  225. }
  226. List<Data> checkInDatas = checkIn.datas;
  227. //获取所有打卡补卡,审批 数据
  228. DateTime sp_startDt = startDt.AddDays(-10);
  229. DateTime sp_centerDt = sp_startDt.AddDays(30);
  230. DateTime sp_endDt = endDt.AddDays(10);
  231. List<Sp_Info> sp_Infos = new List<Sp_Info>();
  232. string redisName = "ApprovalData_" + sp_startDt.Year + "_" + sp_startDt.Month;
  233. string sp_InfosString = await RedisRepository.RedisFactory
  234. .CreateRedisRepository()
  235. .StringGetAsync<string>(redisName);//string 取
  236. if (string.IsNullOrEmpty(sp_InfosString))
  237. {
  238. ApprovalDataView approvalData_1 = await _qiYeWeChatApiService.GetApprovalDataAsync(sp_startDt, sp_centerDt); //时间段内所有 审批数据
  239. ApprovalDataView approvalData_2 = await _qiYeWeChatApiService.GetApprovalDataAsync(sp_centerDt, sp_endDt); //时间段内所有 审批数据
  240. if (approvalData_1.errcode != 0)
  241. {
  242. result.Msg = "企业微信 获取时间段内审批 Msg:" + approvalData_1.errmsg;
  243. return Ok(JsonView(false, "企业微信 获取时间段内审批 Msg:" + approvalData_1.errmsg));
  244. }
  245. sp_Infos.AddRange(approvalData_1.data);
  246. if (approvalData_2.errcode != 0)
  247. {
  248. return Ok(JsonView(false, "企业微信 获取时间段内审批 Msg:" + approvalData_2.errmsg));
  249. }
  250. sp_Infos.AddRange(approvalData_2.data);
  251. TimeSpan ts = DateTime.Now.AddMinutes(60) - DateTime.Now; //设置redis 过期时间 60分钟
  252. await RedisRepository
  253. .RedisFactory
  254. .CreateRedisRepository()
  255. .StringSetAsync<string>(redisName, JsonConvert.SerializeObject(sp_Infos), ts);//string 存
  256. }
  257. else
  258. {
  259. sp_Infos = JsonConvert.DeserializeObject<List<Sp_Info>>(sp_InfosString);
  260. }
  261. // 筛选 时间段内(请假时间,补卡时间) /审批类型(打卡补卡,请假)/审核通过的数据
  262. List<Sp_Info> sp_leave_InfosData = sp_Infos.Where(it => it.sp_status == 2 && it.spname == "请假" && it.leave.start_time_dt >= startDt && it.leave.start_time_dt <= endDt).ToList(); //请假
  263. List<Sp_Info> sp_reissuecard_InfosData = sp_Infos.Where(it => it.sp_status == 2 && it.spname == "打卡补卡" && it.comm.FillingDt >= startDt && it.comm.FillingDt <= endDt).ToList(); //补卡
  264. List<Pm_WageSheet> wageSheets = new List<Pm_WageSheet>();
  265. foreach (var item in preWageSheetItems)
  266. {
  267. Pm_WageSheet pm_wsInfo = new Pm_WageSheet();
  268. pm_wsInfo = _mapper.Map<Pm_WageSheet>(item);
  269. //补贴 金额
  270. decimal meal_subsidy = 0.00M; // 午餐(午餐10元/天) 补贴 * 计算方式:单日上午请假时长(小时)大于或者等于三小时 没有餐补
  271. //事假 病假 总金额
  272. decimal personalLeaveTotal = 0.00M, // 事假 日薪 *计算方式:日平均工资 = 月工资/当月应出勤天数。
  273. sickLeaveTotal = 0.00M; // 病假 日薪 *计算方式:日平均工资 = 成都市最低工资标准的80%/当月应出勤天数。 短期病假=当月15天内
  274. //扣款金额
  275. decimal beLate_deduction = 0.00M, // 迟到 扣款金额 *计算方式:
  276. // 一个自然月内,不足 10 分钟的迟到/早退,不超过 2 次的部分,不做处罚;3 次及以上,按50元 / 次处罚;
  277. // 超过 10 分钟(含 10 分钟),不足 60 分钟的迟到/早退,按 50 元/次处罚;
  278. // 超过 60 分钟(含 60 分钟),不足 3 小时的迟到/早退,且无请假者,按旷工半日处理;超过3 小时的迟到 / 早退,且无请假者,按旷工一日处理。
  279. early_deduction = 0.00M, // 早退 扣款金额
  280. absenteeism_deduction = 0.00M, // 旷工 扣款金额 *计算方式:旷工扣发当日工资
  281. unprinted_deduction = 0.00M, // 未打卡 扣款金额 *计算方式:
  282. // 试用期员工每月有 2 次 补卡机会,超过 2 次不足 5 次的部分,按 10 元 / 次处罚,5 次及以上的漏卡,按 50 元 / 次处罚;
  283. // 正式员工每月 3 次以内的补卡,按 10 元 / 次处罚,3 次及以上的漏卡,按 50 元 / 次处罚。
  284. sickLeave_deduction = 0.00M,
  285. other_deduction = 0.00M; // 其他 扣款金额
  286. decimal meal_deduction = 0.00M; // 餐补 扣款金额
  287. decimal reissuecard_deduction = 0.00M; // 补卡 扣款金额
  288. //打卡数据
  289. Data? checkInData = checkInDatas.Where(it => it.base_info.name == item.Name).FirstOrDefault();
  290. if (checkInData == null) { continue; }
  291. string acctid = checkInData.base_info.acctid; //用户Id
  292. //当月总计数据
  293. Summary_Info? summary_Info = checkInData.summary_info;
  294. if (summary_Info == null ) { continue; }
  295. int work_days = summary_Info.work_days; //应出勤天数
  296. int regular_days = summary_Info.regular_days; //正常出勤天数
  297. meal_subsidy = work_days * 10; //应发放餐补
  298. #region 计算日工资 正常日薪 事假日薪 病假日薪
  299. //月 - 应发工资
  300. decimal amountPayable = pm_wsInfo.Basic + pm_wsInfo.Floats + pm_wsInfo.PostAllowance + pm_wsInfo.GarmentWashSubsidies + pm_wsInfo.CommunicationSubsidies +
  301. pm_wsInfo.TrafficSubsidies + pm_wsInfo.InformationSecurityFee + pm_wsInfo.OperationBonus + pm_wsInfo.SpecialAllowance + pm_wsInfo.OtherSubsidies + pm_wsInfo.GroupCost;
  302. // 日薪 = 事假日薪 *计算方式:日平均工资 = 月工资/当月应出勤天数。
  303. decimal dailyWage = amountPayable / work_days;
  304. // 病假日薪 *计算方式:日平均工资 = 成都市最低工资标准的80%/当月应出勤天数。 短期病假=当月15天内
  305. decimal sickLeave_dailywage = _chengDuMinimumWage / work_days;
  306. //病假 一天扣款
  307. sickLeave_deduction = dailyWage - sickLeave_dailywage;
  308. #endregion
  309. int annualLeaveNum = 0, //年假
  310. personalLeaveNum = 0, //事假
  311. sickLeaveNum = 0, //病假
  312. lieuLeaveNum = 0, //调休假
  313. marriageLeaveNum = 0, //婚嫁
  314. maternityLeaveNum = 0, //产假
  315. paternityLeaveNum = 0, //陪产假
  316. funeralLeaveNum = 0, //丧假
  317. reissueCardNum = 0, //补卡 次数
  318. evectionNum = 0, //出差 次数
  319. outIngNum = 0, //外出 次数
  320. outWorkNum = 0, //外勤 次数
  321. otherLeaveNum = 0; //其他
  322. #region 假勤 处理 1-请假;2-补卡;3-出差;4-外出;100-外勤;
  323. List<Sp_Item>? sp_items = checkInData.sp_items.Where(it => it.count != 0).ToList();
  324. if (sp_items != null && sp_items.Count > 0)
  325. {
  326. annualLeaveNum = Fallibilitydispose(sp_items, 1, "年假");
  327. personalLeaveNum = Fallibilitydispose(sp_items, 1, "事假");
  328. sickLeaveNum = Fallibilitydispose(sp_items, 1, "病假");
  329. lieuLeaveNum = Fallibilitydispose(sp_items, 1, "调休假");
  330. marriageLeaveNum = Fallibilitydispose(sp_items, 1, "婚嫁");
  331. maternityLeaveNum = Fallibilitydispose(sp_items, 1, "产假");
  332. paternityLeaveNum = Fallibilitydispose(sp_items, 1, "陪产假");
  333. funeralLeaveNum = Fallibilitydispose(sp_items, 1, "丧假");
  334. otherLeaveNum = Fallibilitydispose(sp_items, 1, "其他");
  335. reissueCardNum = Fallibilitydispose(sp_items, 2, "补卡次数");
  336. evectionNum = Fallibilitydispose(sp_items, 3, "出差");
  337. outIngNum = Fallibilitydispose(sp_items, 4, "外出");
  338. outWorkNum = Fallibilitydispose(sp_items, 3, "外勤");
  339. }
  340. #region 请假类型金额/餐补 处理
  341. List<Sp_Info> sp_leave_item_infosData = sp_leave_InfosData.Where(it => it.spname == "请假" && it.apply_name == item.Name).ToList();
  342. List<Ex_Items> ex_Items = new List<Ex_Items>();//假勤 And 打卡备注集合
  343. Ex_Items ex_Items_jq = new Ex_Items() { Type = "假勤" }; //假勤
  344. List<Ex_Item> ex_ItemInfos = new List<Ex_Item>();
  345. foreach (Sp_Info sp_item in sp_leave_item_infosData)
  346. {
  347. Leave? sp_leave = sp_item.leave;
  348. if (sp_leave != null)
  349. {
  350. //请假时长
  351. double leaveLength = (sp_leave.end_time_dt - sp_leave.start_time_dt).TotalHours;
  352. string typeName = string.Empty;
  353. //leave_type 1年假;2事假;3病假;4调休假;5婚假;6产假;7陪产假;8其他
  354. switch (sp_leave.leave_type)
  355. {
  356. case 1: //年假
  357. typeName = "年假";
  358. if (sp_leave.timeunit == 0) //半天
  359. {
  360. meal_deduction += 10;
  361. }
  362. else if (sp_leave.timeunit == 1) //小时
  363. {
  364. if (sp_leave.duration >= 3 && sp_leave.duration <= 7.5) //7.5小时 一天
  365. {
  366. meal_deduction += 10;
  367. }
  368. else if (sp_leave.duration > 7.5)
  369. {
  370. decimal daysPrice = Convert.ToDecimal(sp_leave.duration / 7.5 * 10);
  371. meal_deduction += daysPrice;
  372. }
  373. }
  374. break;
  375. case 2: //事假 需调整
  376. typeName = "事假";
  377. if (sp_leave.timeunit == 0) //半天
  378. {
  379. meal_deduction += 10;
  380. personalLeaveTotal += dailyWage / 2;
  381. }
  382. else if (sp_leave.timeunit == 1) //小时
  383. {
  384. if (sp_leave.duration >= 3 && sp_leave.duration <= 7.5) //7.5小时 一天
  385. {
  386. meal_deduction += 10;
  387. }
  388. else if (sp_leave.duration > 7.5)
  389. {
  390. decimal daysPrice = Convert.ToDecimal(sp_leave.duration / 7.5 * 10);
  391. meal_deduction += daysPrice;
  392. }
  393. }
  394. break;
  395. case 3: //病假 需调整
  396. typeName = "病假";
  397. if (sp_leave.timeunit == 0) //半天
  398. {
  399. meal_deduction += 10;
  400. sickLeaveTotal += sickLeave_deduction / 2;
  401. }
  402. else if (sp_leave.timeunit == 1) //小时
  403. {
  404. if (sp_leave.duration >= 3 && sp_leave.duration <= 7.5) //7.5小时 一天
  405. {
  406. meal_deduction += 10;
  407. }
  408. else if (sp_leave.duration > 7.5)
  409. {
  410. decimal daysPrice = Convert.ToDecimal(sp_leave.duration / 7.5 * 10);
  411. meal_deduction += daysPrice;
  412. }
  413. }
  414. break;
  415. case 4: //调休假
  416. typeName = "调休假";
  417. if (sp_leave.timeunit == 0) //半天
  418. {
  419. meal_deduction += 10;
  420. }
  421. else if (sp_leave.timeunit == 1) //小时
  422. {
  423. if (sp_leave.duration >= 3 && sp_leave.duration <= 7.5) //7.5小时 一天
  424. {
  425. meal_deduction += 10;
  426. }
  427. else if (sp_leave.duration > 7.5)
  428. {
  429. decimal daysPrice = Convert.ToDecimal(sp_leave.duration / 7.5 * 10);
  430. meal_deduction += daysPrice;
  431. }
  432. }
  433. break;
  434. case 5: //婚假
  435. typeName = "婚假";
  436. if (sp_leave.timeunit == 0) //半天
  437. {
  438. meal_deduction += 10;
  439. }
  440. else if (sp_leave.timeunit == 1) //小时
  441. {
  442. if (sp_leave.duration >= 3 && sp_leave.duration <= 7.5) //7.5小时 一天
  443. {
  444. meal_deduction += 10;
  445. }
  446. else if (sp_leave.duration > 7.5)
  447. {
  448. decimal daysPrice = Convert.ToDecimal(sp_leave.duration / 7.5 * 10);
  449. meal_deduction += daysPrice;
  450. }
  451. }
  452. break;
  453. case 6: //产假
  454. typeName = "产假";
  455. if (sp_leave.timeunit == 0) //半天
  456. {
  457. meal_deduction += 10;
  458. }
  459. else if (sp_leave.timeunit == 1) //小时
  460. {
  461. if (sp_leave.duration >= 3 && sp_leave.duration <= 7.5) //7.5小时 一天
  462. {
  463. meal_deduction += 10;
  464. }
  465. else if (sp_leave.duration > 7.5)
  466. {
  467. decimal daysPrice = Convert.ToDecimal(sp_leave.duration / 7.5 * 10);
  468. meal_deduction += daysPrice;
  469. }
  470. }
  471. break;
  472. case 7: //陪产假
  473. typeName = "陪产假";
  474. if (sp_leave.timeunit == 0) //半天
  475. {
  476. meal_deduction += 10;
  477. }
  478. else if (sp_leave.timeunit == 1) //小时
  479. {
  480. if (sp_leave.duration >= 3 && sp_leave.duration <= 7.5) //7.5小时 一天
  481. {
  482. meal_deduction += 10;
  483. }
  484. else if (sp_leave.duration > 7.5)
  485. {
  486. decimal daysPrice = Convert.ToDecimal(sp_leave.duration / 7.5 * 10);
  487. meal_deduction += daysPrice;
  488. }
  489. }
  490. break;
  491. default:
  492. break;
  493. }
  494. Ex_Item ex_Item = new Ex_Item() {
  495. SubTypeId = sp_leave.leave_type,
  496. SubType = typeName,
  497. Start_time_dt = sp_leave.start_time_dt,
  498. End_time_dt = sp_leave.end_time_dt,
  499. Duration = sp_leave.duration,
  500. Reason = sp_leave.reason,
  501. Apply_time_dt = sp_item.apply_time_dt,
  502. Approval_name = sp_item.approval_name,
  503. };
  504. ex_ItemInfos.Add(ex_Item);
  505. }
  506. }
  507. if (ex_ItemInfos.Count > 0)
  508. {
  509. ex_Items_jq.Ex_ItemInfo = ex_ItemInfos.OrderBy(it => it.SubTypeId).ThenBy(it => it.Start_time_dt).ToList();
  510. ex_Items.Add(ex_Items_jq);
  511. }
  512. #endregion
  513. #endregion
  514. #region 打卡补卡 处理
  515. if (reissueCardNum == 3)
  516. {
  517. reissuecard_deduction += 10;
  518. }
  519. else if (reissueCardNum >= 4)
  520. {
  521. reissuecard_deduction += 50;
  522. }
  523. #endregion
  524. Ex_Items ex_Items_dk = new Ex_Items() { Type = "打卡" }; //打卡
  525. //List<Ex_Item> ex_reissuecard_Items = new List<Ex_Item>();
  526. List<dynamic> ex_reissuecard_Items = new List<dynamic>();
  527. List<Sp_Info> sp_reissuecard_item_InfosData = sp_reissuecard_InfosData.Where(it => it.apply_name == item.Name).ToList();
  528. #region 打卡异常处理 统计 1-迟到;2-早退;3-缺卡;4-旷工;5-地点异常;6-设备异常;
  529. int beLateNum = 0, // 1-迟到;
  530. leaveEarlyNum = 0, // 2-早退;
  531. dummyDeckNum = 0, // 3-缺卡;
  532. minerNum = 0, // 4-旷工;
  533. locationAnomalyNum = 0, // 5-地点异常;
  534. unitExNum = 0; // 6-设备异常;
  535. if (summary_Info.except_days > 0)
  536. {
  537. List<Exception_Info>? ex_infos = checkInData.exception_infos;
  538. if (ex_infos != null && ex_infos.Count >= 0)
  539. {
  540. beLateNum = ExceptionStatistics(ex_infos, 1);
  541. leaveEarlyNum = ExceptionStatistics(ex_infos, 2);
  542. dummyDeckNum = ExceptionStatistics(ex_infos, 3);
  543. minerNum = ExceptionStatistics(ex_infos, 4);
  544. locationAnomalyNum = ExceptionStatistics(ex_infos, 5);
  545. unitExNum = ExceptionStatistics(ex_infos, 6);
  546. }
  547. }
  548. foreach (Sp_Info sp_reissuecard_item in sp_reissuecard_item_InfosData)
  549. {
  550. DateTime apply_time_dt = sp_reissuecard_item.apply_time_dt; //申请时间
  551. List<string>? approval_name = sp_reissuecard_item.approval_name; //审核人
  552. Comm sp_comm = sp_reissuecard_item.comm;
  553. if (sp_comm != null)
  554. {
  555. if (sp_comm.applydata != null )
  556. {
  557. List<ApplyInfo> applyInfos = sp_comm.applydata;
  558. if (applyInfos.Count > 0)
  559. {
  560. //Ex_Item ex_reissuecard_Item = new Ex_Item();
  561. dynamic ex_reissuecard_Item = null;
  562. string text = applyInfos.Where(it => it.type == "text").FirstOrDefault().value.ToString(); //异常状态
  563. DateTime? datehour = applyInfos.Where(it => it.type == "datehour").FirstOrDefault().valueDt;//补卡时间
  564. string textarea = applyInfos.Where(it => it.type == "textarea").FirstOrDefault().value.ToString();//补卡事由
  565. if (text.Contains("未打卡"))
  566. {
  567. ex_reissuecard_Item = new
  568. {
  569. SubTypeId = 0,
  570. SubType = "未打卡",
  571. title = text,
  572. datehour = datehour == null ? "" : Convert.ToDateTime(datehour).ToString("yyyy-MM-dd HH:mm:ss"),
  573. textarea = textarea,
  574. apply_time_dt = apply_time_dt,
  575. approval_name = approval_name
  576. };
  577. }
  578. else if (text.Contains("迟到"))
  579. {
  580. ex_reissuecard_Item = new
  581. {
  582. SubTypeId = 1,
  583. SubType = "迟到",
  584. title = text,
  585. datehour = datehour == null? "": Convert.ToDateTime(datehour).ToString("yyyy-MM-dd HH:mm:ss"),
  586. textarea = textarea,
  587. apply_time_dt = apply_time_dt,
  588. approval_name = approval_name
  589. };
  590. }
  591. else if (text.Contains("早退"))
  592. {
  593. ex_reissuecard_Item = new
  594. {
  595. SubTypeId = 2,
  596. SubType = "早退",
  597. title = text,
  598. datehour = datehour == null ? "" : Convert.ToDateTime(datehour).ToString("yyyy-MM-dd HH:mm:ss"),
  599. textarea = textarea,
  600. apply_time_dt = apply_time_dt,
  601. approval_name = approval_name
  602. };
  603. }
  604. else if (text.Contains("缺卡"))
  605. {
  606. ex_reissuecard_Item = new
  607. {
  608. SubTypeId = 3,
  609. SubType = "缺卡",
  610. title = text,
  611. datehour = datehour == null ? "" : Convert.ToDateTime(datehour).ToString("yyyy-MM-dd HH:mm:ss"),
  612. textarea = textarea,
  613. apply_time_dt = apply_time_dt,
  614. approval_name = approval_name
  615. };
  616. }
  617. else if (text.Contains("旷工"))
  618. {
  619. ex_reissuecard_Item = new
  620. {
  621. SubTypeId = 4,
  622. SubType = "旷工",
  623. title = text,
  624. datehour = datehour == null ? "" : Convert.ToDateTime(datehour).ToString("yyyy-MM-dd HH:mm:ss"),
  625. textarea = textarea,
  626. apply_time_dt = apply_time_dt,
  627. approval_name = approval_name
  628. };
  629. }
  630. else if (text.Contains("地点异常"))
  631. {
  632. ex_reissuecard_Item = new
  633. {
  634. SubTypeId = 5,
  635. SubType = "地点异常",
  636. title = text,
  637. datehour = datehour == null ? "" : Convert.ToDateTime(datehour).ToString("yyyy-MM-dd HH:mm:ss"),
  638. textarea = textarea,
  639. apply_time_dt = apply_time_dt,
  640. approval_name = approval_name
  641. };
  642. }
  643. else if (text.Contains("设备异常"))
  644. {
  645. ex_reissuecard_Item = new
  646. {
  647. SubTypeId = 6,
  648. SubType = "设备异常",
  649. title = text,
  650. datehour = datehour == null ? "" : Convert.ToDateTime(datehour).ToString("yyyy-MM-dd HH:mm:ss"),
  651. textarea = textarea,
  652. apply_time_dt = apply_time_dt,
  653. approval_name = approval_name
  654. };
  655. }
  656. if (ex_reissuecard_Item != null)
  657. {
  658. ex_reissuecard_Items.Add(ex_reissuecard_Item);
  659. }
  660. }
  661. }
  662. }
  663. }
  664. if (ex_reissuecard_Items.Count>0)
  665. {
  666. ex_Items_dk.Ex_ItemInfo = ex_reissuecard_Items.OrderBy(it => it.SubTypeId).ThenBy(it => it.datehour).ToList();
  667. ex_Items.Add(ex_Items_dk);
  668. }
  669. #endregion
  670. #region 应发合计 实发合计 扣款合计(假勤扣款,其他扣款,社保扣款,公积金代扣,个税扣款)
  671. decimal mealTotal = meal_subsidy - meal_deduction; //餐补
  672. decimal salaryTotal = amountPayable + mealTotal; //应发合计
  673. //扣款合计 不含个税
  674. decimal eductionTotal = sickLeaveTotal + personalLeaveTotal + beLate_deduction + early_deduction + absenteeism_deduction + unprinted_deduction + other_deduction +
  675. pm_wsInfo.WithholdingInsurance + pm_wsInfo.ReservedFunds;
  676. decimal actualReleaseTotal = salaryTotal - eductionTotal; //实发合计 * 不含个税
  677. #endregion
  678. #region 处理当月工资数据
  679. pm_wsInfo.YearMonth = thisYearMonth;
  680. pm_wsInfo.StartDate = startDt.ToString("yyyy-MM-dd");
  681. pm_wsInfo.EndDate = endDt.ToString("yyyy-MM-dd");
  682. pm_wsInfo.SickLeave = sickLeaveTotal; //病假
  683. pm_wsInfo.SomethingFalse = personalLeaveTotal; //事假
  684. pm_wsInfo.LateTo = beLate_deduction; //迟到
  685. pm_wsInfo.LeaveEarly = early_deduction; //早退
  686. pm_wsInfo.Absenteeism = absenteeism_deduction; //旷工
  687. pm_wsInfo.NotPunch = unprinted_deduction; //未打卡
  688. pm_wsInfo.OtherDeductions = other_deduction; //其他
  689. pm_wsInfo.Ex_ItemsRemark = JsonConvert.SerializeObject(ex_Items); //
  690. pm_wsInfo.Mealsupplement = mealTotal; //餐补
  691. pm_wsInfo.Should = salaryTotal; //应发合计
  692. pm_wsInfo.TotalDeductions = eductionTotal; //扣款合计
  693. pm_wsInfo.TotalRealHair = actualReleaseTotal; //实发合计
  694. pm_wsInfo.AfterTax = actualReleaseTotal - pm_wsInfo.WithholdingTax; //税后工资
  695. pm_wsInfo.LastUpdateUserId = dto.UserId;
  696. pm_wsInfo.LastUpdateDt = DateTime.Now;
  697. pm_wsInfo.CreateUserId = dto.UserId;
  698. pm_wsInfo.CreateTime = DateTime.Now;
  699. #endregion
  700. wageSheets.Add(pm_wsInfo);
  701. }
  702. #region 批量添加
  703. var add = await _wageSheetRep._sqlSugar.Insertable(wageSheets).ExecuteCommandAsync();
  704. if (add <= 0)
  705. {
  706. return Ok(JsonView(false, "操作失败!"));
  707. }
  708. #endregion
  709. #region 处理返回数据
  710. List <WageSheetItemInfoView> wageSheetItems = new List<WageSheetItemInfoView>();
  711. wageSheetItems = _mapper.Map<List<WageSheetItemInfoView>>(wageSheets);
  712. wageSheetItems = wageSheetItems.Select(it =>
  713. {
  714. UserNameView? uName1 = new UserNameView();
  715. UserNameView? uName2 = new UserNameView();
  716. uName1 = userNames.Where(it1 => it.UserId == it1.Id).FirstOrDefault();
  717. if (uName1 != null) it.Name = uName1.CnName;
  718. uName2 = userNames.Where(it1 => it.LastUpdateUserId == it1.Id).FirstOrDefault();
  719. if (uName2 != null) it.LastUpdateUserName = uName2.CnName;
  720. return it; }
  721. ).ToList();
  722. #endregion
  723. return Ok(JsonView(true,"操作成功!", wageSheetItems));
  724. }
  725. /// <summary>
  726. /// 打卡数据
  727. /// 假勤数据 统计
  728. /// </summary>
  729. /// <param name="datas">数据源</param>
  730. /// <param name="type">
  731. /// 1-请假;2-补卡;3-出差;4-外出;100-外勤;
  732. /// </param>
  733. /// <param name="subTypeName">
  734. /// 年假 事假 病假 调休假 婚嫁 产假 陪产假 丧假 补卡次数 出差 外出数 外勤 其他
  735. /// </param>
  736. /// <returns></returns>
  737. private int Fallibilitydispose(List<Sp_Item> datas, int type,string? subTypeName)
  738. {
  739. int num = 0;
  740. Sp_Item _Info = datas.Where(it => it.type == type && it.name == subTypeName).FirstOrDefault();
  741. if (_Info != null) { num = _Info.count; }
  742. return num;
  743. }
  744. /// <summary>
  745. /// 打卡数据
  746. /// 异常数据 统计
  747. /// </summary>
  748. /// <returns></returns>
  749. private int ExceptionStatistics(List<Exception_Info> datas,int type)
  750. {
  751. int num = 0;
  752. Exception_Info _Info = datas.Where(it => it.exception == type).FirstOrDefault();
  753. if (_Info != null) { num = _Info.count; }
  754. return num;
  755. }
  756. #endregion
  757. }
  758. }