From 1449e83a0f66a183df602d291ce7f53a00de0167 Mon Sep 17 00:00:00 2001 From: Mahan Ch Date: Sun, 30 Mar 2025 18:28:39 +0330 Subject: [PATCH] fix bug! --- .../Repository/RollCallMandatoryRepository.cs | 92 ++++++++++++++++++- 1 file changed, 87 insertions(+), 5 deletions(-) diff --git a/CompanyManagment.EFCore/Repository/RollCallMandatoryRepository.cs b/CompanyManagment.EFCore/Repository/RollCallMandatoryRepository.cs index ee5750e8..6f7a5ab8 100644 --- a/CompanyManagment.EFCore/Repository/RollCallMandatoryRepository.cs +++ b/CompanyManagment.EFCore/Repository/RollCallMandatoryRepository.cs @@ -1613,7 +1613,9 @@ CreateWorkingHoursTemp command, bool holidayWorking) public CustomizeCheckoutMandatoryViewModel CustomizeCheckoutMandatoryComputeForKebabMahdi(long employeeId, long workshopId, DateTime contractStart, DateTime contractEnd) { - if (employeeId is 45084 or 7980 or 5976 or 45214 or 45215) + var checkoutEnd = contractEnd; + var checkoutStart = contractStart; + if (employeeId is 45084 or 7980 or 5976 or 45214 or 45215) { return CheckoutWithoutCalculationForKebabMahdi(workshopId,employeeId,contractStart,contractEnd); } @@ -1968,7 +1970,7 @@ CreateWorkingHoursTemp command, bool holidayWorking) #region SalaryAidDeduction var salaryAidViewModel = _context.SalaryAids - .Where(x => x.SalaryAidDateTime >= contractStart && x.SalaryAidDateTime <= contractEnd && x.EmployeeId == employeeId && x.WorkshopId == workshopId).Select(x => new SalaryAidViewModel() + .Where(x => x.SalaryAidDateTime >= checkoutStart && x.SalaryAidDateTime <= checkoutEnd && x.EmployeeId == employeeId && x.WorkshopId == workshopId).Select(x => new SalaryAidViewModel() { Amount = x.Amount.ToMoney(), AmountDouble = x.Amount, @@ -2182,8 +2184,8 @@ CreateWorkingHoursTemp command, bool holidayWorking) #region Reward var rewardViewModels = _context.Rewards.Where(x => - x.WorkshopId == workshopId && x.EmployeeId == employeeId && x.GrantDate <= contractEnd && - x.GrantDate >= contractStart).Select(x => new RewardViewModel + x.WorkshopId == workshopId && x.EmployeeId == employeeId && x.GrantDate <= checkoutEnd && + x.GrantDate >= checkoutStart).Select(x => new RewardViewModel { Title = x.Title, Amount = x.Amount.ToMoney(), @@ -2414,9 +2416,89 @@ CreateWorkingHoursTemp command, bool holidayWorking) var mandatoryDays = totalDays; - return new CustomizeCheckoutMandatoryViewModel() + #region SalaryAidDeduction + + var salaryAidViewModel = _context.SalaryAids + .Where(x => x.SalaryAidDateTime >= contractStart && x.SalaryAidDateTime <= contractEnd && x.EmployeeId == employeeId && x.WorkshopId == workshopId).Select(x => new SalaryAidViewModel() + { + Amount = x.Amount.ToMoney(), + AmountDouble = x.Amount, + SalaryAidDateTimeFa = x.SalaryAidDateTime.ToFarsi(), + SalaryAidDateTimeGe = x.SalaryAidDateTime, + }).ToList(); + double salaryAidDeduction = salaryAidViewModel.Sum(x => x.AmountDouble); + + #endregion + + #region Loan + + var loanInstallments = _context.Loans + .Where(x => x.EmployeeId == employeeId && x.WorkshopId == workshopId) + .SelectMany(x => x.LoanInstallments) + .Where(i => i.InstallmentDate > contractStart && i.InstallmentDate < contractEnd && i.IsActive == IsActive.True) + .Select(x => new LoanInstallmentViewModel() + { + Month = x.Month, + IsActive = x.IsActive, + Amount = x.AmountForMonth.ToMoney(), + Year = x.Year, + AmountDouble = x.AmountForMonth, + RemainingAmount = _context.Loans.SelectMany(l => l.LoanInstallments).Where(i => i.LoanId == x.LoanId && i.IsActive == IsActive.True && i.InstallmentDate > x.InstallmentDate) + .Sum(i => i.AmountForMonth).ToMoney() + }).ToList(); + + double loanDeduction = loanInstallments.Sum(x => x.AmountDouble); + + #endregion + + #region Fine + + var fineViewModels = _context.Fines.Where(x => + x.EmployeeId == employeeId && x.WorkshopId == workshopId && x.FineDate >= contractStart && + x.FineDate <= contractEnd && x.IsActive == IsActive.True).Select(x => new FineViewModel() + { + IsActive = x.IsActive, + Amount = x.Amount.ToMoney(), + FineDate = x.FineDate.ToFarsi(), + Id = x.id, + Title = x.Title, + EmployeeId = x.EmployeeId, + CreationDate = x.CreationDate.ToFarsi() + }).ToList(); + double fineDeduction = fineViewModels.Sum(x => x.Amount.MoneyToDouble()); + + #endregion + #region Reward + + var rewardViewModels = _context.Rewards.Where(x => + x.WorkshopId == workshopId && x.EmployeeId == employeeId && x.GrantDate <= contractEnd && + x.GrantDate >= contractStart).Select(x => new RewardViewModel + { + Title = x.Title, + Amount = x.Amount.ToMoney(), + AmountDouble = x.Amount, + Description = x.Description, + GrantDateGr = x.GrantDate, + GrantDateFa = x.GrantDate.ToFarsi(), + IsActive = x.IsActive, + }).ToList(); + + double rewardPay = rewardViewModels.Sum(x => x.AmountDouble); + #endregion + + + + return new CustomizeCheckoutMandatoryViewModel() { MonthlySalary = dailyWage * mandatoryDays, + RewardPay = rewardPay, + RewardViewModels = rewardViewModels, + SalaryAidDeduction = salaryAidDeduction, + SalaryAidViewModels = salaryAidViewModel, + InstallmentDeduction = loanDeduction, + InstallmentViewModels = loanInstallments, + FineDeduction = fineDeduction, + FineViewModels = fineViewModels }; }