Explorar o código

计算工资 5.3

leiy hai 1 ano
pai
achega
ae20aba0d3

+ 5 - 5
OASystem/OASystem.Api/Controllers/PersonnelModuleController.cs

@@ -229,9 +229,9 @@ namespace OASystem.API.Controllers
             string thisYearMonth = dto.yearMonth;
             string preYearMonth = yearMonthDt.AddMonths(-1).ToString("yyyy-MM");
 
-            //计算本月工资起止时间
+            //计算本月工资起止时间 比如是2月的1号-28号,那就是2月1号的零点到3月1号的零点 
             DateTime thisStartDt = startDt;
-            DateTime thisEndDt = endDt;
+            DateTime thisEndDt = endDt.AddDays(1); //
 
             //本月工资是否有数据 有数据则不计算
             result = await _wageSheetRep.Get_WageSheet_ListByYearMonthAsync(thisYearMonth);
@@ -292,7 +292,7 @@ namespace OASystem.API.Controllers
             #endregion
 
             sw.Stop();
-            return Ok(JsonView(true, "操作成功! 耗时:" + sw.ElapsedMilliseconds + "ms"));
+            return Ok(JsonView(true, "操作成功! 耗时:" + (sw.ElapsedMilliseconds/1000) + "s"));
         }
 
 
@@ -329,7 +329,7 @@ namespace OASystem.API.Controllers
             var nameData = await _usersRep.GetUserNameList(1);
             List<UserNameView>? userNames = nameData.Data;
 
-            _result = await PayrollComputation.SalaryCalculatorAsync(wageSheets, userNames, dto.UserId, dto.YearMonth, startDt, endDt);
+            _result = await PayrollComputation.SalaryCalculatorAsync(wageSheets, userNames, dto.UserId, dto.YearMonth, startDt, endDt.AddDays(1));
 
             if (_result.Code != 0)
             {
@@ -359,7 +359,7 @@ namespace OASystem.API.Controllers
                 #endregion
 
             sw.Stop();
-                return Ok(JsonView(true, "操作成功!耗时:"+ sw.ElapsedMilliseconds +"ms", wageSheetItems[0]));
+            return Ok(JsonView(true, "操作成功!耗时:" + (sw.ElapsedMilliseconds / 1000) + "s", wageSheetItems[0]));
            
             
         }

+ 150 - 202
OASystem/OASystem.Api/OAMethodLib/PayrollComputation.cs

@@ -67,6 +67,11 @@ namespace OASystem.API.OAMethodLib
             }
 
             _result.Msg = string.Empty;
+
+            try
+            {
+
+           
             foreach (var pm_wsInfo in pm_WageSheetDattaSources)
             {
                 string itemName = userNames.Where(it => it.Id == pm_wsInfo.UserId).FirstOrDefault().CnName;
@@ -251,7 +256,7 @@ namespace OASystem.API.OAMethodLib
                             {
                                 SubTypeId = leaveType,
                                 SubType = typeName,
-                                StartTimeDt = Convert.ToDateTime( date_Range.new_begin_dt.ToString("yyyy-MM-dd HH:mm:ss")),
+                                StartTimeDt = Convert.ToDateTime(date_Range.new_begin_dt.ToString("yyyy-MM-dd HH:mm:ss")),
                                 EndTimeDt = Convert.ToDateTime(date_Range.new_end_dt.ToString("yyyy-MM-dd HH:mm:ss")),
                                 Duration = new_duration,
                                 Deduction = thisTypeDeduction,
@@ -274,7 +279,6 @@ namespace OASystem.API.OAMethodLib
 
                 #endregion
 
-
                 Ex_Items ex_Items_dk = new Ex_Items() { Type = "打卡" };    //打卡
                 List<Ex_Item> ex_Item_Infos = new List<Ex_Item>();
                 #region 打卡补卡 补卡次数 处理
@@ -299,6 +303,7 @@ namespace OASystem.API.OAMethodLib
                     {
                         SubTypeId = 7,
                         SubType = "补卡次数",
+                        Duration = reissueCardNum,
                         Deduction = reissuecard_deduction,
                         Reason = "补卡:员工发现自己漏打卡时,需及时提起补卡申请,并说明情况。试用期员工每月有 2 次\r\n补卡机会,超过 2 次不足 5 次的部分,按 10 元/次处罚,5 次及以上的漏卡,按 50 元/次处罚;正式员工每月 3 次以内的补卡,按 10 元/次处罚,3 次及以上的漏卡,按 50 元/次处罚。\r\n补卡路径为:企微-工作台-审批-打卡补卡。",
                         unit = string.Empty
@@ -336,7 +341,6 @@ namespace OASystem.API.OAMethodLib
                     }
                 }
 
-
                 //打卡记录
                 CheckInDataView checkInDataView = new CheckInDataView();
                 checkInDataView = await _qiYeWeChatApiService.GetCheckinDataAsync(new List<string>() { acctid },3,startDt,endDt);
@@ -376,225 +380,160 @@ namespace OASystem.API.OAMethodLib
 
                     if (pullcard_checkInDataInfos.Count > 0)
                     {
-
-
-                        #region 打卡异常处理 统计 1-迟到;2-早退;3-缺卡;4-旷工;5-地点异常;6-设备异常;
-
-                        //sp_reissuecard_details = await _qiYeWeChatApiService.GetApprovalDetailsAsync(startDt, endDt, acctid, 2, 2); //时间段内所有 已同意的 补卡 审批数据
-                        //if (sp_reissuecard_details.Count <= 0)
-                        //{
-                        //    _result.Msg += startDt + " - " + endDt + "  " + itemName + "  打卡补卡 审批数据获取未获取到!\r\n";
-                        //    continue;
-                        //}
-
-                        //#region 打卡补卡
-
-                        //foreach (var pullcardItem in sp_reissuecard_details)
-                        //{
-                        //    Apply_data? apply_data = pullcardItem.apply_data;
-                        //    if (apply_data != null)
-                        //    {
-                        //        List<ContentsItem> contents = apply_data.contents;
-                        //        ContentsItem content_Vacation = contents.Where(it => it.control == "Vacation").FirstOrDefault();  //请假类型 
-                        //        ContentsItem content_Textarea = contents.Where(it => it.control == "Textarea").FirstOrDefault();  //多行文本 
-
-                        //        if (content_Vacation != null)
-                        //        {
-                        //            Vacation vacation = content_Vacation.value.vacation;
-                        //            Attendance attendance = vacation.attendance; //假勤组件
-                        //            Selector selector = vacation.selector;       //请假类型
-
-                        //            List<OptionsItem> optionsItems = selector.options; //key 请假类型 id
-                        //            List<TitleItem> value = optionsItems[0].value; // value 文本描述值
-
-                        //            int leaveType = int.Parse(optionsItems[0].key);  //key 请假子类型 id
-                        //            Date_range date_Range = attendance.date_range;
-
-                        //            decimal thisTypeDeduction = 0.00M;//当前类型扣款
-                        //            string leave_starttime = date_Range.new_begin_dt.ToString("HH:mm");
-                        //            string leave_endtime = date_Range.new_end_dt.ToString("HH:mm");
-
-                        //            string typeName = string.Empty;
-                        //            int leaveTypeId = leaveType;
-                        //            var leaveTypeData = vacationLeaveTypes.Where(it => it.id == leaveTypeId).FirstOrDefault();
-
-                        //            if (leaveTypeData != null) { typeName = leaveTypeData.name; }
-                        //            //计算请假类型扣款金额
-
-                        //            int new_duration = 0;
-                        //            if (date_Range.type == "halfday")
-                        //            {
-                        //                new_duration = date_Range.new_duration / 86400;
-                        //            }
-                        //            else if (date_Range.type == "hour")
-                        //            {
-                        //                new_duration = date_Range.new_duration / 3600;
-                        //            }
-                        //            decimal leave_meals = 0.00M;
-                        //            CalculateTypeFee(leaveType, date_Range.type, leave_starttime, leave_endtime, amountPayable, work_days, new_duration,
-                        //                out leave_meals, out thisTypeDeduction);
-
-                        //            meal_deduction += leave_meals;
-                        //            string startEndTiime = startEndTiime = date_Range.new_begin_dt.ToString("yyyy-MM-dd HH:mm") + " - " +
-                        //                date_Range.new_end_dt.ToString("yyyy-MM-dd HH:mm");
-
-                        //        }
-                        //    }
-                        //}
-
-                        #endregion
-
                         foreach (var pc_ex_item in pullcard_checkInDataInfos)
                         {
 
-                            CheckInDayDataView checkInDayDataView = await _qiYeWeChatApiService.GetCheckInDayDataAsync(new List<string>() { acctid },startDt,endDt);
+                            //CheckInDayDataView checkInDayDataView = await _qiYeWeChatApiService.GetCheckInDayDataAsync(new List<string>() { acctid },startDt,endDt);
 
-                            if (checkInDayDataView.errcode != 0)
-                            {
-                                _result.Msg += startDt + " - " + endDt + "  " + itemName + "  异常信息数据获取未获取到!\r\n";
-                                continue;
-                            }
-                            List<Root> roots_words= checkInDayDataView.datas.Where(it => it.base_info.day_type == 0).ToList(); //获取工作日日报信息
-                            List<Root> roots_exs = checkInDayDataView.datas.Where(it => it.exception_infos.Count > 0).ToList();
-                            Root roots_ex = roots_exs.Where(it => it.base_info.dateDt == pc_ex_item.sch_checkin_time_dt).FirstOrDefault();
-                            if (roots_ex != null) { 
-                            List<Exception_infos> exception_infos = roots_ex.exception_infos;
+                            //var checkInDayDataView = await _qiYeWeChatApiService.GetCheckInDayDataAsync(new List<string>() { acctid }, startDt, endDt);
 
-                            List<Exception_infos> exception_infos1 = checkInDayDataView.datas[29].exception_infos;
-                            string exc_type = pc_ex_item.exception_type;
+                            //if (checkInDayDataView.errcode != 0)
+                            //{
+                            //    _result.Msg += startDt + " - " + endDt + "  " + itemName + "  异常信息数据获取未获取到!\r\n";
+                            //    continue;
+                            //}
+                            //List<Root> roots_words = checkInDayDataView.datas.Where(it => it.base_info.day_type == 0).ToList(); //获取工作日日报信息
+                            //List<Root> roots_exs = checkInDayDataView.datas.Where(it => it.exception_infos.Count > 0).ToList();
+                            //Root roots_ex = roots_exs.Where(it => it.base_info.dateDt == pc_ex_item.sch_checkin_time_dt).FirstOrDefault();
+                            //if (roots_ex != null)
+                            //{
+                                //List<Exception_infos> exception_infos = roots_ex.exception_infos;
 
-                            if (exc_type.Contains("时间异常") || exc_type.Contains("未打卡")) // 时间异常  未打卡
-                            {
-                                int day_time_minute = (60 * 7) + 30;
+                                //List<Exception_infos> exception_infos1 = checkInDayDataView.datas[29].exception_infos;
+                                string exc_type = pc_ex_item.exception_type;
 
-                                Exception_infos beLate_ex = exception_infos.Where(it => it.exception == 1).FirstOrDefault(); //迟到
-                                decimal day_miner_unit = dailyWage / 15;  //以0.5小时为单位 
-
-                                if (beLate_ex != null)
+                                if (exc_type.Contains("时间异常") || exc_type.Contains("未打卡")) // 时间异常  未打卡
                                 {
-                                    if (beLateNum > 0) //迟到次数
-                                    {
-                                        //1:一个自然月内,不足 10 分钟的迟到/早退,不超过 2 次的部分,不做处罚;3 次及以上,按50 元 / 次处罚;
-                                        //2:超过 10 分钟(含 10 分钟),不足 60 分钟的迟到 / 早退,按 50 元 / 次处罚;
-                                        //3:超过 60 分钟(含 60 分钟),不足 3 小时的迟到 / 早退,且无请假者,按旷工半日处理;超过 3 小时的迟到 / 早退,且无请假者,按旷工一日处理。
-
-                                        Ex_Item beLate_belate_ex = new Ex_Item()
-                                        {
-                                            SubTypeId = 4,
-                                            SubType = "旷工",
-                                            unit = "分钟",
-                                        };
-                                        decimal day_beLate_deduction = 0.00M;
-                                        if (beLate_ex.duration >= 10 && beLate_ex.duration <= 60)
-                                        {
-                                            day_beLate_deduction = beLateNum * 50;
-                                            beLate_belate_ex.SubTypeId = 1;
-                                            beLate_belate_ex.SubType = "迟到";
-                                        }
-                                        else if (beLate_ex.duration > 60 && beLate_ex.duration <= 180)
-                                        {
-                                            day_beLate_deduction = day_miner_unit * 6; //3小时
-
-                                        }
-                                        else day_beLate_deduction = dailyWage;
-
-                                        beLate_deduction += day_beLate_deduction;
+                                    int day_time_minute = (60 * 7) + 30;
 
+                                    //Exception_infos beLate_ex = exception_infos.Where(it => it.exception == 1).FirstOrDefault(); //迟到
+                                    Exception_infos beLate_ex = new Exception_infos();
+                                    decimal day_miner_unit = dailyWage / 15;  //以0.5小时为单位 
 
-                                        beLate_belate_ex.Duration = beLate_ex.duration;
-                                        beLate_belate_ex.Deduction = day_beLate_deduction;
-                                        ex_reissuecard_Items.Add(beLate_belate_ex);
-                                    }
-
-
-                                    if (leaveEarlyNum > 0) // 早退次数
-                                    {
-                                        //1:一个自然月内,不足 10 分钟的迟到/早退,不超过 2 次的部分,不做处罚;3 次及以上,按50 元 / 次处罚;
-                                        //2:超过 10 分钟(含 10 分钟),不足 60 分钟的迟到 / 早退,按 50 元 / 次处罚;
-                                        //3:超过 60 分钟(含 60 分钟),不足 3 小时的迟到 / 早退,且无请假者,按旷工半日处理;超过 3 小时的迟到 / 早退,且无请假者,按旷工一日处理。
-
-                                        Ex_Item beLate_belate_ex = new Ex_Item()
-                                        {
-                                            SubTypeId = 4,
-                                            SubType = "旷工",
-                                            unit = "分钟",
-                                        };
-                                        decimal day_beLate_deduction = 0.00M;
-                                        if (beLate_ex.duration >= 10 && beLate_ex.duration <= 60)
-                                        {
-                                            day_beLate_deduction = beLateNum * 50;
-                                            beLate_belate_ex.SubTypeId = 3;
-                                            beLate_belate_ex.SubType = "未打卡/漏卡";
-                                        }
-                                        else if (beLate_ex.duration > 60 && beLate_ex.duration <= 180)
+                                    //if (beLate_ex != null)
+                                    //{
+                                        if (beLateNum > 0) //迟到次数
                                         {
-                                            day_beLate_deduction = day_miner_unit * 6; //3小时
-
+                                            //1:一个自然月内,不足 10 分钟的迟到/早退,不超过 2 次的部分,不做处罚;3 次及以上,按50 元 / 次处罚;
+                                            //2:超过 10 分钟(含 10 分钟),不足 60 分钟的迟到 / 早退,按 50 元 / 次处罚;
+                                            //3:超过 60 分钟(含 60 分钟),不足 3 小时的迟到 / 早退,且无请假者,按旷工半日处理;超过 3 小时的迟到 / 早退,且无请假者,按旷工一日处理。
+
+                                            Ex_Item beLate_belate_ex = new Ex_Item()
+                                            {
+                                                SubTypeId = 4,
+                                                SubType = "旷工",
+                                                unit = "分钟",
+                                            };
+                                            decimal day_beLate_deduction = 0.00M;
+                                            if (beLate_ex.duration >= 10 && beLate_ex.duration <= 60)
+                                            {
+                                                day_beLate_deduction = beLateNum * 50;
+                                                beLate_belate_ex.SubTypeId = 1;
+                                                beLate_belate_ex.SubType = "迟到";
+                                            }
+                                            else if (beLate_ex.duration > 60 && beLate_ex.duration <= 180)
+                                            {
+                                                day_beLate_deduction = day_miner_unit * 6; //3小时
+
+                                            }
+                                            else day_beLate_deduction = dailyWage;
+
+                                            beLate_deduction += day_beLate_deduction;
+
+
+                                            beLate_belate_ex.Duration = beLate_ex.duration;
+                                            beLate_belate_ex.Deduction = day_beLate_deduction;
+                                            ex_reissuecard_Items.Add(beLate_belate_ex);
                                         }
-                                        else day_beLate_deduction = dailyWage;
-
-                                        beLate_deduction += day_beLate_deduction;
-
-                                        beLate_belate_ex.Duration = beLate_ex.duration;
-                                        beLate_belate_ex.Deduction = day_beLate_deduction;
-                                        ex_reissuecard_Items.Add(beLate_belate_ex);
-                                    }
 
-                                    if (dummyDeckNum > 0)  //缺卡
-                                    {
-                                        Ex_Item beLate_belate_ex = new Ex_Item()
+                                        else if (leaveEarlyNum > 0) // 早退次数
                                         {
-                                            SubTypeId = 4,
-                                            SubType = "旷工",
-                                            unit = "分钟",
-                                        };
-                                        decimal day_beLate_deduction = 0.00M;
-                                        if (beLate_ex.duration >= 10 && beLate_ex.duration <= 60)
-                                        {
-                                            day_beLate_deduction = beLateNum * 50;
-                                            beLate_belate_ex.SubTypeId = 2;
-                                            beLate_belate_ex.SubType = "早退";
+                                            //1:一个自然月内,不足 10 分钟的迟到/早退,不超过 2 次的部分,不做处罚;3 次及以上,按50 元 / 次处罚;
+                                            //2:超过 10 分钟(含 10 分钟),不足 60 分钟的迟到 / 早退,按 50 元 / 次处罚;
+                                            //3:超过 60 分钟(含 60 分钟),不足 3 小时的迟到 / 早退,且无请假者,按旷工半日处理;超过 3 小时的迟到 / 早退,且无请假者,按旷工一日处理。
+
+                                            Ex_Item beLate_belate_ex = new Ex_Item()
+                                            {
+                                                SubTypeId = 4,
+                                                SubType = "旷工",
+                                                unit = "分钟",
+                                            };
+                                            decimal day_beLate_deduction = 0.00M;
+                                            if (beLate_ex.duration >= 10 && beLate_ex.duration <= 60)
+                                            {
+                                                day_beLate_deduction = beLateNum * 50;
+                                                beLate_belate_ex.SubTypeId = 3;
+                                                beLate_belate_ex.SubType = "未打卡/漏卡";
+                                            }
+                                            else if (beLate_ex.duration > 60 && beLate_ex.duration <= 180)
+                                            {
+                                                day_beLate_deduction = day_miner_unit * 6; //3小时
+
+                                            }
+                                            else day_beLate_deduction = dailyWage;
+
+                                            beLate_deduction += day_beLate_deduction;
+
+                                            beLate_belate_ex.Duration = beLate_ex.duration;
+                                            beLate_belate_ex.Deduction = day_beLate_deduction;
+                                            ex_reissuecard_Items.Add(beLate_belate_ex);
                                         }
-                                        else if (beLate_ex.duration > 60 && beLate_ex.duration <= 180)
-                                        {
-                                            day_beLate_deduction = day_miner_unit * 6; //3小时
 
+                                       else if (dummyDeckNum > 0)  //缺卡
+                                        {
+                                            Ex_Item beLate_belate_ex = new Ex_Item()
+                                            {
+                                                SubTypeId = 4,
+                                                SubType = "旷工",
+                                                unit = "分钟",
+                                            };
+                                            decimal day_beLate_deduction = 0.00M;
+                                            if (beLate_ex.duration >= 10 && beLate_ex.duration <= 60)
+                                            {
+                                                day_beLate_deduction = beLateNum * 50;
+                                                beLate_belate_ex.SubTypeId = 2;
+                                                beLate_belate_ex.SubType = "早退";
+                                            }
+                                            else if (beLate_ex.duration > 60 && beLate_ex.duration <= 180)
+                                            {
+                                                day_beLate_deduction = day_miner_unit * 6; //3小时
+
+                                            }
+                                            else day_beLate_deduction = dailyWage;
+
+                                            beLate_deduction += day_beLate_deduction;
+
+                                            beLate_belate_ex.Duration = beLate_ex.duration;
+                                            beLate_belate_ex.Deduction = day_beLate_deduction;
+                                            ex_reissuecard_Items.Add(beLate_belate_ex);
                                         }
-                                        else day_beLate_deduction = dailyWage;
-
-                                        beLate_deduction += day_beLate_deduction;
-
-                                        beLate_belate_ex.Duration = beLate_ex.duration;
-                                        beLate_belate_ex.Deduction = day_beLate_deduction;
-                                        ex_reissuecard_Items.Add(beLate_belate_ex);
-                                    }
 
-                                    if (minerNum > 0)   //矿工
-                                    {
-                                        Ex_Item beLate_belate_ex = new Ex_Item()
-                                        {
-                                            SubTypeId = 4,
-                                            SubType = "旷工",
-                                            unit = "分钟",
-                                        };
-                                        decimal day_beLate_deduction = 0.00M;
-                                        
-                                        if (beLate_ex.duration > 60 && beLate_ex.duration <= 180)
+                                        else if (minerNum > 0)   //矿工
                                         {
-                                            day_beLate_deduction = day_miner_unit * 6; //3小时
-
+                                            Ex_Item beLate_belate_ex = new Ex_Item()
+                                            {
+                                                SubTypeId = 4,
+                                                SubType = "旷工",
+                                                unit = "分钟",
+                                            };
+                                            decimal day_beLate_deduction = 0.00M;
+
+                                            if (beLate_ex.duration > 60 && beLate_ex.duration <= 180)
+                                            {
+                                                day_beLate_deduction = day_miner_unit * 6; //3小时
+
+                                            }
+                                            else day_beLate_deduction = dailyWage;
+
+                                            beLate_deduction += day_beLate_deduction;
+
+                                            beLate_belate_ex.Duration = beLate_ex.duration;
+                                            beLate_belate_ex.Deduction = day_beLate_deduction;
+                                            ex_reissuecard_Items.Add(beLate_belate_ex);
                                         }
-                                        else day_beLate_deduction = dailyWage;
-
-                                        beLate_deduction += day_beLate_deduction;
-
-                                        beLate_belate_ex.Duration = beLate_ex.duration;
-                                        beLate_belate_ex.Deduction = day_beLate_deduction;
-                                        ex_reissuecard_Items.Add(beLate_belate_ex);
-                                    }
+                                    //}
                                 }
-                            }
-                            }
+                            //}
                         }
                     }
                 }
@@ -647,7 +586,16 @@ namespace OASystem.API.OAMethodLib
                 #endregion
 
             }
-            
+
+            }
+            catch (Exception ex)
+            {
+
+                _result.Msg = ex.Message;
+
+                return _result;
+            }
+
             _result.Code = 0;
             _result.Data = pm_WageSheetDattaSources;
 

+ 10 - 0
OASystem/OASystem.Domain/Dtos/PersonnelModule/WageSheetDto.cs

@@ -73,6 +73,16 @@ namespace OASystem.Domain.Dtos.PersonnelModule
         /// </summary>
         public string? EndDate { get; set; }
 
+        /// <summary>
+        /// 应出勤天数
+        /// </summary>
+        public int WorkDays { get; set; }
+
+        /// <summary>
+        /// 正常出勤天数
+        /// </summary>
+        public int RegularDays { get; set; }
+
         /// <summary>
         /// 基本工资
         /// </summary>

+ 11 - 0
OASystem/OASystem.Domain/ViewModels/PersonnelModule/WageSheetView.cs

@@ -255,6 +255,17 @@ namespace OASystem.Domain.ViewModels.PersonnelModule
         /// </summary>
         public decimal WithholdingTax { get; set; }
 
+        /// <summary>
+        /// 税前合计
+        /// </summary>
+        public decimal BeforeTax
+        {
+            get
+            {
+                return WithholdingTax + AfterTax;
+            }
+        }
+
         /// <summary>
         /// 税后工资
         /// </summary>