From 0dcdbc4f34b7164159ff940521384b1ebdcae0ab Mon Sep 17 00:00:00 2001 From: SamSys Date: Wed, 9 Oct 2024 19:21:38 +0330 Subject: [PATCH] CostomizeRollCall Developing --- 0_Framework/Application/Tools.cs | 389 ++++++++++-------- .../MaxMonthDays.cs | 8 +- .../IRollCallMandatoryRepository.cs | 9 + .../CompanyManagment.App.Contracts.csproj | 4 + .../CustomizeCheckoutMandatoryViewModel.cs | 121 ++++++ .../Repository/RollCallMandatoryRepository.cs | 231 +++++++++++ .../Repository/RollCallRepository.cs | 12 +- ServiceHost/Areas/Camera/Pages/Index.cshtml | 10 +- ServiceHost/Program.cs | 1 - ServiceHost/ServiceHost.csproj | 1 - ServiceHost/appsettings.Development.json | 4 +- 11 files changed, 593 insertions(+), 197 deletions(-) create mode 100644 CompanyManagment.App.Contracts/CustomizeCheckout/CustomizeCheckoutMandatoryViewModel.cs diff --git a/0_Framework/Application/Tools.cs b/0_Framework/Application/Tools.cs index 41f46b2d..40e31020 100644 --- a/0_Framework/Application/Tools.cs +++ b/0_Framework/Application/Tools.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; @@ -7,6 +8,7 @@ using System.Globalization; using System.IO; using System.Text.RegularExpressions; using _0_Framework.Infrastructure; +using Microsoft.Extensions.WebEncoders.Testing; using PersianTools.Core; using static System.Net.Mime.MediaTypeNames; using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database; @@ -53,6 +55,35 @@ public static class Tools var pc = new PersianCalendar(); return $"{pc.GetMonth(date)}"; } + /// + /// این متد تاریخ میلادی را گرفته و ماه 31 یا 30 روزه را تشخیص میدهد، ماه اسفند 30 روزه برمگیردد + /// + /// + /// + public static int CountMonthDays(this DateTime date) + { + if (date == new DateTime()) return 0; + var pc = new PersianCalendar(); + + return pc.GetMonth(date) switch + { + 1 => 31, + 2 => 31, + 3 => 31, + 4 => 31, + 5 => 31, + 6 => 31, + + 7 => 30, + 8 => 30, + 9 => 30, + 10 => 30, + 11 => 30, + 12 => 30, + _ => 0, + + }; + } public static string ToFarsiYear2(this DateTime date) { @@ -499,7 +530,7 @@ public static class Tools public static string RestTimeSplit(this string restTime) { string result = string.Empty; - + if (restTime?.Length >= 2) { result = restTime.Substring(0, 2); @@ -510,7 +541,7 @@ public static class Tools { result = "0"; } - + return result; } @@ -540,7 +571,7 @@ public static class Tools case "7777777777": case "8888888888": case "9999999999": - + return "incorrect"; } @@ -564,12 +595,12 @@ public static class Tools return "lessThan10"; } - + } public static string RestTimeMinSplit(this string restTime) { string result = string.Empty; - + if (restTime?.Length > 2) { result = restTime.Substring(3, 2); @@ -581,7 +612,7 @@ public static class Tools { result = "0"; } - + return result; } @@ -999,7 +1030,7 @@ public static class Tools public static DateTime ExtractTimeFromDbbackup(this string value) { var year = value.Substring(10, 4); - var month =value.Substring(15, 2); + var month = value.Substring(15, 2); var day = value.Substring(18, 2); var persianDate = year + "/" + month + "/" + day; var georgianDate = persianDate.ToGeorgianDateTime(); @@ -1032,7 +1063,7 @@ public static class Tools var start = new PersianDateTime(year, month, day); var startAddYear = start.AddMonths(11); - var monthStr= $"{startAddYear.Month}"; + var monthStr = $"{startAddYear.Month}"; if (monthStr.Length < 2) monthStr = $"0{monthStr}"; var lastMonth = $"{startAddYear.Year}/{monthStr}/01"; @@ -1096,122 +1127,122 @@ public static class Tools string pattern = @"^([2][0-3]|[1][0-9]|[0-9]|[0][0-9])([:][0-5][0-9])$"; var match = Regex.Match(input, pattern); - if (!match.Success) + if (!match.Success) return false; return true; } - #region Mahan - public static string ToFarsiDuration(this string date) - { - var today = DateTime.Now.ToFarsi(); - var year = Convert.ToInt32(today.Substring(0, 4)); - var month = Convert.ToInt32(today.Substring(5, 2)); - var day = Convert.ToInt32(today.Substring(8, 2)); - var todayPersianDate = new PersianDateTime(year, month, day); + #region Mahan + public static string ToFarsiDuration(this string date) + { + var today = DateTime.Now.ToFarsi(); + var year = Convert.ToInt32(today.Substring(0, 4)); + var month = Convert.ToInt32(today.Substring(5, 2)); + var day = Convert.ToInt32(today.Substring(8, 2)); + var todayPersianDate = new PersianDateTime(year, month, day); - var planYear = Convert.ToInt32(date.Substring(0, 4)); - var planMonth = Convert.ToInt32(date.Substring(5, 2)); - var planDay = Convert.ToInt32(date.Substring(8, 2)); - var planPersianDate = new PersianDateTime(planYear, planMonth, planDay); + var planYear = Convert.ToInt32(date.Substring(0, 4)); + var planMonth = Convert.ToInt32(date.Substring(5, 2)); + var planDay = Convert.ToInt32(date.Substring(8, 2)); + var planPersianDate = new PersianDateTime(planYear, planMonth, planDay); - if (planPersianDate > todayPersianDate) - { - var countDay = 0; - var counMonth = 0; - var nextMonth = new PersianDateTime(todayPersianDate).AddMonths(1); - for (var start = todayPersianDate; start <= planPersianDate; start = start.AddDays(1)) - { - countDay++; - if (start == nextMonth) - { - counMonth++; - nextMonth = new PersianDateTime(start).AddMonths(1); - countDay = 0; - } - } + if (planPersianDate > todayPersianDate) + { + var countDay = 0; + var counMonth = 0; + var nextMonth = new PersianDateTime(todayPersianDate).AddMonths(1); + for (var start = todayPersianDate; start <= planPersianDate; start = start.AddDays(1)) + { + countDay++; + if (start == nextMonth) + { + counMonth++; + nextMonth = new PersianDateTime(start).AddMonths(1); + countDay = 0; + } + } - if (counMonth > 0) - { - if (countDay == 0) - { - return $"{counMonth} ماه"; - } - return $"{counMonth}ماه و {countDay} روز"; - } - else - { - return $"{countDay}روز"; - } - } - else - { - return ""; - } - } + if (counMonth > 0) + { + if (countDay == 0) + { + return $"{counMonth} ماه"; + } + return $"{counMonth}ماه و {countDay} روز"; + } + else + { + return $"{countDay}روز"; + } + } + else + { + return ""; + } + } - public static string ToFarsiDuration2(this string date) - { - var persianCalendar = new System.Globalization.PersianCalendar(); - var today = DateTime.Now; + public static string ToFarsiDuration2(this string date) + { + var persianCalendar = new System.Globalization.PersianCalendar(); + var today = DateTime.Now; - // Convert today's Gregorian date to Persian date - var todayYear = persianCalendar.GetYear(today); - var todayMonth = persianCalendar.GetMonth(today); - var todayDay = persianCalendar.GetDayOfMonth(today); + // Convert today's Gregorian date to Persian date + var todayYear = persianCalendar.GetYear(today); + var todayMonth = persianCalendar.GetMonth(today); + var todayDay = persianCalendar.GetDayOfMonth(today); - var todayPersianDate = new DateTime(todayYear, todayMonth, todayDay, persianCalendar); + var todayPersianDate = new DateTime(todayYear, todayMonth, todayDay, persianCalendar); - // Parse the target Persian date from the input string - var planYear = int.Parse(date.Substring(0, 4)); - var planMonth = int.Parse(date.Substring(5, 2)); - var planDay = int.Parse(date.Substring(8, 2)); + // Parse the target Persian date from the input string + var planYear = int.Parse(date.Substring(0, 4)); + var planMonth = int.Parse(date.Substring(5, 2)); + var planDay = int.Parse(date.Substring(8, 2)); - var planPersianDate = new DateTime(planYear, planMonth, planDay, persianCalendar); + var planPersianDate = new DateTime(planYear, planMonth, planDay, persianCalendar); - if (planPersianDate > todayPersianDate) - { - // Calculate the exact difference in years, months, and days - int yearDifference = planYear - todayYear; - int monthDifference = planMonth - todayMonth; - int dayDifference = planDay - todayDay; + if (planPersianDate > todayPersianDate) + { + // Calculate the exact difference in years, months, and days + int yearDifference = planYear - todayYear; + int monthDifference = planMonth - todayMonth; + int dayDifference = planDay - todayDay; - if (dayDifference < 0) - { - monthDifference--; - dayDifference += persianCalendar.GetDaysInMonth(todayYear, todayMonth); - } + if (dayDifference < 0) + { + monthDifference--; + dayDifference += persianCalendar.GetDaysInMonth(todayYear, todayMonth); + } - if (monthDifference < 0) - { - yearDifference--; - monthDifference += 12; - } + if (monthDifference < 0) + { + yearDifference--; + monthDifference += 12; + } - // Construct the duration string - var duration = ""; - if (yearDifference > 0) - { - duration += $"{yearDifference} سال "; - } + // Construct the duration string + var duration = ""; + if (yearDifference > 0) + { + duration += $"{yearDifference} سال "; + } - if (monthDifference > 0) - { - duration += $"{monthDifference} ماه "; - } + if (monthDifference > 0) + { + duration += $"{monthDifference} ماه "; + } - if (dayDifference > 0) - { - duration += $"{dayDifference} روز"; - } + if (dayDifference > 0) + { + duration += $"{dayDifference} روز"; + } - return duration.Trim(); - } - else - { - return ""; - } - } + return duration.Trim(); + } + else + { + return ""; + } + } public static string SerializeToBson(object obj) { using var memoryStream = new MemoryStream(); @@ -1245,99 +1276,99 @@ public static class Tools } public static DateTime GetNextDayOfWeek(this DateTime date, DayOfWeek dayOfWeek) - { - int numberOfNextDayOfWeek = ((int)dayOfWeek - (int)date.DayOfWeek + 7) % 7; - return date.AddDays(numberOfNextDayOfWeek == 0 ? 7 : numberOfNextDayOfWeek); - } + { + int numberOfNextDayOfWeek = ((int)dayOfWeek - (int)date.DayOfWeek + 7) % 7; + return date.AddDays(numberOfNextDayOfWeek == 0 ? 7 : numberOfNextDayOfWeek); + } - //این متد آخر همان روز را به صورت دیت تایم برمیگرداند - public static DateTime ToGeorgianDateTime2(this string persianDate) - { - persianDate = persianDate.ToEnglishNumber(); - try - { - var year = Convert.ToInt32(persianDate.Substring(0, 4)); - var month = Convert.ToInt32(persianDate.Substring(5, 2)); - var day = Convert.ToInt32(persianDate.Substring(8, 2)); + //این متد آخر همان روز را به صورت دیت تایم برمیگرداند + public static DateTime ToGeorgianDateTime2(this string persianDate) + { + persianDate = persianDate.ToEnglishNumber(); + try + { + var year = Convert.ToInt32(persianDate.Substring(0, 4)); + var month = Convert.ToInt32(persianDate.Substring(5, 2)); + var day = Convert.ToInt32(persianDate.Substring(8, 2)); - var res = new DateTime(year, month, day, new PersianCalendar()); - res = res.AddHours(23); - res = res.AddMinutes(59); - res = res.AddSeconds(59); + var res = new DateTime(year, month, day, new PersianCalendar()); + res = res.AddHours(23); + res = res.AddMinutes(59); + res = res.AddSeconds(59); - return res; + return res; - } - catch (Exception e) - { - return new DateTime(3000, 12, 20, new PersianCalendar()); - } + } + catch (Exception e) + { + return new DateTime(3000, 12, 20, new PersianCalendar()); + } - } - //تبدیل به تاریخ با ساعت - public static DateTime ToGeorgianDateWithTime(this string persianDate, string persianTime) - { - persianDate = persianDate.ToEnglishNumber(); - try - { - var year = Convert.ToInt32(persianDate.Substring(0, 4)); - var month = Convert.ToInt32(persianDate.Substring(5, 2)); - var day = Convert.ToInt32(persianDate.Substring(8, 2)); + } + //تبدیل به تاریخ با ساعت + public static DateTime ToGeorgianDateWithTime(this string persianDate, string persianTime) + { + persianDate = persianDate.ToEnglishNumber(); + try + { + var year = Convert.ToInt32(persianDate.Substring(0, 4)); + var month = Convert.ToInt32(persianDate.Substring(5, 2)); + var day = Convert.ToInt32(persianDate.Substring(8, 2)); - var hour = int.Parse(persianTime.Substring(0, 2)); - var minute = int.Parse(persianTime.Substring(3, 2)); + var hour = int.Parse(persianTime.Substring(0, 2)); + var minute = int.Parse(persianTime.Substring(3, 2)); - var res = new DateTime(year, month, day, new PersianCalendar()); - res = res.AddHours(hour); - res = res.AddMinutes(minute); - return res; + var res = new DateTime(year, month, day, new PersianCalendar()); + res = res.AddHours(hour); + res = res.AddMinutes(minute); + return res; - } - catch (Exception e) - { - return new DateTime(3000, 12, 20, new PersianCalendar()); - } + } + catch (Exception e) + { + return new DateTime(3000, 12, 20, new PersianCalendar()); + } - } + } - public static string DayOfWeeKToPersian(this DayOfWeek dayOfWeek) - { - return dayOfWeek switch - { - DayOfWeek.Friday => "جمعه", - DayOfWeek.Monday => "دوشنبه", - DayOfWeek.Saturday => "شنبه", - DayOfWeek.Sunday => "یکشنبه", - DayOfWeek.Thursday => "پنجشنبه", - DayOfWeek.Tuesday => "سه شنبه", - DayOfWeek.Wednesday => "چهارشنبه", - _ => "" - }; - } + public static string DayOfWeeKToPersian(this DayOfWeek dayOfWeek) + { + return dayOfWeek switch + { + DayOfWeek.Friday => "جمعه", + DayOfWeek.Monday => "دوشنبه", + DayOfWeek.Saturday => "شنبه", + DayOfWeek.Sunday => "یکشنبه", + DayOfWeek.Thursday => "پنجشنبه", + DayOfWeek.Tuesday => "سه شنبه", + DayOfWeek.Wednesday => "چهارشنبه", + _ => "" + }; + } - public static bool IsInvalidDateTime(this DateTime date) - { - return date == new DateTime(3000, 12, 20, new PersianCalendar()); + public static bool IsInvalidDateTime(this DateTime date) + { + return date == new DateTime(3000, 12, 20, new PersianCalendar()); - } + } - #endregion + #endregion - #region Pooya + #region Pooya - public static DateTime GetUndefinedDateTime() - { - return new DateTime(2121, 03, 21); - } + public static DateTime GetUndefinedDateTime() + { + return new DateTime(2121, 03, 21); + } - public static bool IsDateUndefined(this DateTime date) - { - return date == new DateTime(2121, 03, 21); - } - #endregion + public static bool IsDateUndefined(this DateTime date) + { + return date == new DateTime(2121, 03, 21); + } + #endregion } \ No newline at end of file diff --git a/0_Framework/Domain/CustomizeCheckoutValueObjects/MaxMonthDays.cs b/0_Framework/Domain/CustomizeCheckoutValueObjects/MaxMonthDays.cs index a783a3a8..acba83ea 100644 --- a/0_Framework/Domain/CustomizeCheckoutValueObjects/MaxMonthDays.cs +++ b/0_Framework/Domain/CustomizeCheckoutValueObjects/MaxMonthDays.cs @@ -10,8 +10,8 @@ public enum MaxMonthDays /// تمامی ماه ها 30 روزه حساب شوند /// ThirtyDaysForAllMonth, - /// - /// تمامی ماه ها 30 روزه حساب شوند ولی اسفند 29 روزه - /// - ThirtyDaysForAllMonthExceptEsfand + ///// + ///// تمامی ماه ها 30 روزه حساب شوند ولی اسفند 29 روزه + ///// + //ThirtyDaysForAllMonthExceptEsfand } \ No newline at end of file diff --git a/Company.Domain/RollCallAgg/IRollCallMandatoryRepository.cs b/Company.Domain/RollCallAgg/IRollCallMandatoryRepository.cs index 654545d5..22629691 100644 --- a/Company.Domain/RollCallAgg/IRollCallMandatoryRepository.cs +++ b/Company.Domain/RollCallAgg/IRollCallMandatoryRepository.cs @@ -1,7 +1,10 @@ using System; using System.Collections.Generic; using _0_Framework.Domain; +using Company.Domain.CustomizeWorkshopEmployeeSettingsAgg.Entities; using CompanyManagment.App.Contracts.Contract; +using CompanyManagment.App.Contracts.CustomizeCheckout; +using CompanyManagment.App.Contracts.Leave; using CompanyManagment.App.Contracts.RollCall; using CompanyManagment.App.Contracts.WorkingHoursTemp; @@ -13,4 +16,10 @@ public interface IRollCallMandatoryRepository : IRepository TimeSpan AfterSubtract(CreateWorkingHoursTemp command, TimeSpan sumOneDaySpan, DateTime creationDate); List RotatingShiftCheck(List rollCallList); + + + CustomizeCheckoutMandatoryViewModel CustomizeCheckoutMandatoryCompute(long employeeId, long workshopId, DateTime contractStart, DateTime contractEnd); + + (double lateToWorkSapn, double earlyExit) LateToWorkEarlyExit(List groupedRollCall, + ICollection shiftSettings, List leavList); } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/CompanyManagment.App.Contracts.csproj b/CompanyManagment.App.Contracts/CompanyManagment.App.Contracts.csproj index 2759a76d..cbbc7ba3 100644 --- a/CompanyManagment.App.Contracts/CompanyManagment.App.Contracts.csproj +++ b/CompanyManagment.App.Contracts/CompanyManagment.App.Contracts.csproj @@ -14,4 +14,8 @@ + + + + diff --git a/CompanyManagment.App.Contracts/CustomizeCheckout/CustomizeCheckoutMandatoryViewModel.cs b/CompanyManagment.App.Contracts/CustomizeCheckout/CustomizeCheckoutMandatoryViewModel.cs new file mode 100644 index 00000000..fdee0ea4 --- /dev/null +++ b/CompanyManagment.App.Contracts/CustomizeCheckout/CustomizeCheckoutMandatoryViewModel.cs @@ -0,0 +1,121 @@ +using System; + +namespace CompanyManagment.App.Contracts.CustomizeCheckout; + +public class CustomizeCheckoutMandatoryViewModel +{ + /// + /// حقوق ماهانه + /// + public double MonthlySalary { get; set; } + + + /// + /// جمعه کاری + /// + public double FridayPay { get; set; } + + /// + /// اضافه کاری + /// + public double OverTimePay { get; set; } + + /// + /// سنوات + /// + public double BaseYearsPay { get; set; } + + /// + /// عیدی + /// + public double BonusesPay { get; set; } + + /// + /// شب کاری + /// + public double NightWorkPay { get; set; } + + /// + /// حق تاهل + /// + public double MarriedAllowance { get; set; } + + /// + /// نوبت کاری + /// + public double ShiftPay { get; set; } + + /// + /// حق اولاد(حق فرزند)ء + /// + public double FamilyAllowance { get; set; } + + /// + /// مزد مرخصی + /// + public double LeavePay { get; set; } + + /// + /// حق بیمه + /// + public double InsuranceDeduction { get; set; } + + /// + /// جریمه غیبت + /// + public double FineAbsenceDeduction { get; set; } + + /// + /// تاخیر در ورود + /// + public double LateToWorkDeduction { get; set; } + + /// + /// تعجیل در خروج + /// + public double EarlyExitDeduction { get; set; } + + /// + /// پاداش + /// + public double RewardPay { get; set; } + + /// + /// مساعده + /// + public double SalaryAidDeduction { get; set; } + + /// + /// قسط وام + /// + public double InstallmentDeduction { get; set; } + + /// + /// جریمه + /// + public double FineDeduction { get; set; } + + /// + /// مالیات + /// + public double TaxDeduction { get; set; } + + + /// + /// تعداد روزهای کارکرد + /// + public string SumOfWorkingDays { get; set; } + + /// + /// مجموع مطالبات + /// + public string TotalClaims { get; set; } + /// + /// مجموع کسورات + /// + public string TotalDeductions { get; set; } + /// + /// مجموع پرداختی + /// + public double TotalPayment { get; set; } +} \ No newline at end of file diff --git a/CompanyManagment.EFCore/Repository/RollCallMandatoryRepository.cs b/CompanyManagment.EFCore/Repository/RollCallMandatoryRepository.cs index dba09ed0..54bfac89 100644 --- a/CompanyManagment.EFCore/Repository/RollCallMandatoryRepository.cs +++ b/CompanyManagment.EFCore/Repository/RollCallMandatoryRepository.cs @@ -1,13 +1,19 @@ using System; using System.Collections.Generic; +using System.Diagnostics.Eventing.Reader; using System.Linq; using _0_Framework.Application; +using _0_Framework.Domain.CustomizeCheckoutValueObjects; using _0_Framework.InfraStructure; +using Company.Domain.CustomizeWorkshopEmployeeSettingsAgg.Entities; +using Company.Domain.CustomizeWorkshopSettingsAgg.Entities; using Company.Domain.LeaveAgg; using Company.Domain.LeftWorkAgg; using Company.Domain.RollCallAgg; using Company.Domain.YearlySalaryAgg; using CompanyManagment.App.Contracts.Contract; +using CompanyManagment.App.Contracts.CustomizeCheckout; +using CompanyManagment.App.Contracts.CustomizeWorkshopSettings; using CompanyManagment.App.Contracts.Leave; using CompanyManagment.App.Contracts.LeftWork; using CompanyManagment.App.Contracts.RollCall; @@ -802,7 +808,232 @@ public class RollCallMandatoryRepository : RepositoryBase, IRoll return finalResult; } + + /// + /// متد محاسبه فیش حقوقی دلخواه + /// + /// + /// + /// + /// + /// + public CustomizeCheckoutMandatoryViewModel CustomizeCheckoutMandatoryCompute(long employeeId, long workshopId, DateTime contractStart, + DateTime contractEnd) + { + #region Entities + + int numberOfFridays = 0; + double monthySalary = 0; + int monthDays = 0; + double dailyWage = 0; + int numberOfWorkingDay = 0; + #endregion + + List rollCallResult = _context.RollCalls.Where(x => + x.EmployeeId == employeeId && x.WorkshopId == workshopId && x.StartDate.Value.Date >= contractStart.Date && + x.StartDate.Value.Date <= contractEnd.Date && x.EndDate != null).Select(x => new RollCallViewModel() + { + StartDate = x.StartDate, + EndDate = x.EndDate, + ShiftSpan = (x.EndDate.Value - x.StartDate.Value), + CreationDate = x.CreationDate, + }).ToList(); + List groupedRollCall = rollCallResult.GroupBy(x => x.StartDate!.Value.Date).Select(x => new GroupedRollCalls() + { + CreationDate = x.Key, + ShiftList = x.Select(s => new ShiftList() { Start = s.StartDate!.Value, End = s.EndDate!.Value }).ToList(), + HasFriday = x.Any(s => s.StartDate.Value.DayOfWeek == DayOfWeek.Friday || s.EndDate.Value.DayOfWeek == DayOfWeek.Friday), + SumOneDaySpan = new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks)), + }).ToList(); + TimeSpan sumSpans = new TimeSpan(groupedRollCall.Sum(x => x.SumOneDaySpan.Ticks)); + numberOfFridays = groupedRollCall.Count(x => x.HasFriday); + numberOfWorkingDay = groupedRollCall.Count(); + // یافتن مرخصی ساعتی + #region LeavHourse + + LeaveSearchModel leaveHourseSearch = new LeaveSearchModel() + { + EmployeeId = employeeId, + WorkshopId = workshopId, + LeaveType = "استحقاقی", + PaidLeaveType = "ساعتی", + StartLeaveGr = contractStart, + EndLeaveGr = contractEnd, + IsAccepted = true, + }; + List leaveList = _leaveRepository.search(leaveHourseSearch); + + #endregion + //****افزودن مرخصی پرسنل به مجموع ساعات کار*** + #region AddEmployeeLeavs + LeaveSearchModel leaveSearch = new LeaveSearchModel() + { + EmployeeId = employeeId, + WorkshopId = workshopId, + LeaveType = "استحقاقی", + PaidLeaveType = "روزانه", + StartLeaveGr = contractStart, + EndLeaveGr = contractEnd, + IsAccepted = true, + }; + var leaveSearchResult = _leaveRepository.search(leaveSearch); + if (leaveSearchResult.Count > 0) + { + int leavingDayCout = 0; + //مرخصی های مابین + List beatweenCheckout = leaveSearchResult.Where(x => x.StartLeaveGr >= contractStart && x.EndLeaveGr <= contractEnd).Select(x => new LeaveViewModel() + { + DayCounter = Convert.ToInt32(x.LeaveHourses), + + }).ToList(); + leavingDayCout += beatweenCheckout.Sum(x => x.DayCounter); + // مرخصی که شروعش قبل از شروع تصفیه حساب است + List beforeCheckout = leaveSearchResult.Where(x => x.StartLeaveGr < contractStart).Select(x => new LeaveViewModel() + { + DayCounter = (int)(contractStart - x.EndLeaveGr).TotalDays + 1, + + }).ToList(); + leavingDayCout += beforeCheckout.Sum(x => x.DayCounter); + // مرخصی که پایانش بعد از پایان تصفیه حساب است + List afterCheckout = leaveSearchResult.Where(x => x.EndLeaveGr > contractEnd).Select(x => new LeaveViewModel() + { + DayCounter = (int)(x.StartLeaveGr - contractEnd).TotalDays + 1, + + }).ToList(); + leavingDayCout += afterCheckout.Sum(x => x.DayCounter); + Console.WriteLine(leavingDayCout); + TimeSpan workingPerDayAve = sumSpans / numberOfWorkingDay;//میانگین ساعت کار در روز + TimeSpan sumLeave = new TimeSpan(); + if (workingPerDayAve <= new TimeSpan(7, 20, 0)) + { + sumLeave = leavingDayCout * workingPerDayAve; + } + else + { + sumLeave = leavingDayCout * new TimeSpan(7, 20, 0); + } + + sumSpans = sumSpans.Add(sumLeave); + } + + Console.WriteLine(sumSpans); + #endregion + //***********************************// + //ToTalHourse Employe eWorked + double totalHourses = (sumSpans.TotalMinutes) / 60; + int totalHolidaysAndNotH = (int)sumSpans.TotalHours; + int totalHolidaysAndNotM = (int)(sumSpans.TotalMinutes % 60); + //***********************************// + + CustomizeWorkshopEmployeeSettings customizeWorkshopEmployeeSettings = _context.CustomizeWorkshopEmployeeSettings.FirstOrDefault(x => + x.WorkshopId == workshopId && x.EmployeeId == employeeId); + CustomizeWorkshopSettings customizeWorkshopSettings = + _context.CustomizeWorkshopSettings.FirstOrDefault(x => x.WorkshopId == workshopId); + //ToDo handel exception if is null + monthySalary = customizeWorkshopEmployeeSettings?.Salary?? 0; + monthDays = customizeWorkshopSettings.MaxMonthDays == MaxMonthDays.ThirtyDaysForAllMonth + ? 30 + : contractStart.CountMonthDays(); + dailyWage = monthySalary / monthDays; + var shiftSettings = customizeWorkshopEmployeeSettings.CustomizeWorkshopEmployeeSettingsShifts; + + #region Deductions + + //غیبت + + //تاخیر و تعجیل + #endregion + + + + + + return new CustomizeCheckoutMandatoryViewModel(); + } + + /// + /// محاسبه تاخیر در ورورد و تعجیل در خروج + /// + /// + /// + /// + public (double lateToWorkSapn, double earlyExit) LateToWorkEarlyExit(List groupedRollCall, ICollection shiftSettings, List leavList) + { + List lateToWorkEarlyExistSpannig = new List(); + + foreach (var day in groupedRollCall) + { + + + foreach (var shift in shiftSettings) + { + DateTime start = DateTime.Parse(shift.StartTime); + DateTime end = DateTime.Parse(shift.EndTime); + DateTime startShift = new DateTime(day.CreationDate.Year, day.CreationDate.Month, day.CreationDate.Day, start.Hour,start.Minute,0); + DateTime endShift = new DateTime(day.CreationDate.Year, day.CreationDate.Month, day.CreationDate.Day, end.Hour, end.Minute, 0); + if (start > end) + endShift = endShift.AddDays(1); + + //اگر در بازه شیف تعیین شده حضور غیاب داشت + + var hasRollCall = day.ShiftList.Where(x => + (x.Start <= startShift && x.End > startShift) || + (x.Start >= startShift && x.End <= endShift) || + (x.Start > startShift && x.End > endShift)).ToList(); + if (!hasRollCall.Any())// اگر در بازه شیفت هیچ حضور غیابی نداشت + { + lateToWorkEarlyExistSpannig.Add(new LateToWorkEarlyExistSpannig() + { + StartSpan = startShift, + EndSpan = endShift, + Spanning = (endShift - startShift), + TypeOfSapn = shift.Placement == ShiftPlacement.First ? "LateToWork" : "EarlyExist" + }); + } + else if(hasRollCall.Count() == 1) + { + var singleHasRollCall = hasRollCall.FirstOrDefault(); + if (singleHasRollCall != null && singleHasRollCall.Start > startShift && + singleHasRollCall.End >= endShift) + { + lateToWorkEarlyExistSpannig.Add(new LateToWorkEarlyExistSpannig() + { + StartSpan = startShift, + EndSpan = singleHasRollCall.Start, + Spanning = (singleHasRollCall.Start - startShift), + TypeOfSapn = "LateToWork" + }); + } + else if (singleHasRollCall != null && singleHasRollCall.Start <= startShift && + singleHasRollCall.End < endShift) + { + lateToWorkEarlyExistSpannig.Add(new LateToWorkEarlyExistSpannig() + { + StartSpan = singleHasRollCall.End, + EndSpan = endShift, + Spanning = (endShift - singleHasRollCall.End), + TypeOfSapn = "EarlyExist" + }); + } + } + else if (hasRollCall.Count() > 1) + { + + } + } + } + + return (0, 0); + } } +public class LateToWorkEarlyExistSpannig() +{ + public DateTime StartSpan { get; set; } + public DateTime EndSpan {get; set; } + public TimeSpan Spanning { get; set; } + + public string TypeOfSapn { get; set; } +} \ No newline at end of file diff --git a/CompanyManagment.EFCore/Repository/RollCallRepository.cs b/CompanyManagment.EFCore/Repository/RollCallRepository.cs index 14f1b08c..7083106c 100644 --- a/CompanyManagment.EFCore/Repository/RollCallRepository.cs +++ b/CompanyManagment.EFCore/Repository/RollCallRepository.cs @@ -190,7 +190,7 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos var rollCalls = _context.RollCalls.Where(x => !leavesQuery.Any(y => y.StartLeave.Date <= x.StartDate.Value.Date && y.EndLeave.Date >= x.StartDate.Value.Date) && - x.EmployeeId == employeeId && x.WorkshopId == workshopId && x.StartDate != null && x.EndDate != null && + x.EmployeeId == employeeId && x.WorkshopId == workshopId && x.StartDate != null && x.StartDate >= selectedMonthFirstDay && x.StartDate < nextMonthFirstDay); var personnelCode = @@ -221,9 +221,9 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos new RollCallTimeViewModel() { StartDate = y.StartDate.Value.ToString("HH:mm"), - EndDate = y.EndDate!.Value.ToString("HH:mm") + EndDate = y.EndDate?.ToString("HH:mm")?? "" }), - TotalWorkingHoursSpan = new TimeSpan(rollCallsList.Where(y => x.Date.Date == y.StartDate!.Value.Date) + TotalWorkingHoursSpan = new TimeSpan(rollCallsList.Where(y => x.Date.Date == y.StartDate!.Value.Date && y.EndDate.HasValue) .Sum(y => (y.EndDate!.Value - y.StartDate.Value).Ticks)), Reason = leavesList.FirstOrDefault(y => y.EndLeave >= x.Date.Date && y.StartLeave <= x.Date.Date)?.LeaveType ?? "" }); @@ -296,7 +296,7 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos //roll calls for current workshop where shift start is in dateIndex date (filters today's shifts) var rollCallsQuery = _context.RollCalls - .Where(x => x.WorkshopId == searchModel.WorkshopId && x.StartDate.HasValue && x.EndDate.HasValue && x.StartDate < DateTime.Now.Date && + .Where(x => x.WorkshopId == searchModel.WorkshopId && x.StartDate.HasValue && x.StartDate < DateTime.Now.Date && x.StartDate.Value.Date == dateIndex.Date); @@ -343,12 +343,12 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos Reason = leave == null ? "" : $"{leave.LeaveType}-{leave.PaidLeaveType}", RollCallTimesList = employeeRollCallsForDate.Select(y => new RollCallTimeViewModel() { - EndDate = y.EndDate!.Value.ToString("HH:mm"), + EndDate = y.EndDate?.ToString("HH:mm") ?? "", StartDate = y.StartDate!.Value.ToString("HH:mm") }), HasLeave = leave != null, IsAbsent = !employeeRollCallsForDate.Any(), - TotalWorkingHoursSpan = new TimeSpan(employeeRollCallsForDate.Sum(y => (y.EndDate!.Value - y.StartDate!.Value).Ticks)), + TotalWorkingHoursSpan = new TimeSpan(employeeRollCallsForDate.Where(y=>y.EndDate.HasValue).Sum(y => (y.EndDate!.Value - y.StartDate!.Value).Ticks)), PersonnelCode = personnelCodeList.FirstOrDefault(y => y.EmployeeId == x.EmployeeId)?.PersonnelCode.ToString() }; }) diff --git a/ServiceHost/Areas/Camera/Pages/Index.cshtml b/ServiceHost/Areas/Camera/Pages/Index.cshtml index bffb56e8..d9bd2485 100644 --- a/ServiceHost/Areas/Camera/Pages/Index.cshtml +++ b/ServiceHost/Areas/Camera/Pages/Index.cshtml @@ -1,10 +1,11 @@ @page @model ServiceHost.Areas.Camera.Pages.IndexModel @using System.Diagnostics -@using Version = _0_Framework.Application.Version + @{ - var watch = new Stopwatch(); + string adminVersion = _0_Framework.Application.Version.AdminVersion; + Layout = "Shared/_Layout"; ViewData["Title"] = " - " + "حضور غیاب"; @@ -306,9 +307,10 @@ @* *@ @* *@ - - + + +