fix checkout bug

This commit is contained in:
2025-06-02 22:02:33 +03:30
parent dec5666eb7
commit 925f43214c
2 changed files with 4015 additions and 3958 deletions

View File

@@ -60,8 +60,8 @@ public class RollCallMandatoryRepository : RepositoryBase<long, RollCall>, IRoll
_leaveRepository = leaveRepository;
_holidayItemRepository = holidayItemRepository;
_testDbContext = testDbContext;
}
}
#region OfficialChckout
public ComputingViewModel MandatoryCompute(long employeeId, long workshopId, DateTime contractStart,
@@ -108,8 +108,8 @@ public class RollCallMandatoryRepository : RepositoryBase<long, RollCall>, IRoll
.Include(x => x.CustomizeWorkshopGroupSettings).FirstOrDefault(x =>
x.WorkshopId == workshopId && x.EmployeeId == employeeId);
//اگر ساعت استراحت پرسنل وجود نداشت صفر است
var breakTime = settings == null ? new BreakTime(false, new TimeOnly()) : settings.BreakTime;
var breakTimeEntity = settings == null ? new BreakTime(false, new TimeOnly()) : settings.BreakTime;
var endOfFarvardin = "1404/01/31".ToGeorgianDateTime();
#endregion
@@ -145,16 +145,31 @@ public class RollCallMandatoryRepository : RepositoryBase<long, RollCall>, IRoll
BreakTimeSpan = x.BreakTimeSpan
}).ToList();
groupedRollCall = rollCallResult.GroupBy(x => x.CreationDate.Date).Select(x => new GroupedRollCalls()
groupedRollCall = rollCallResult.GroupBy(x => x.CreationDate.Date).Select(x =>
{
CreationDate = x.Key,
ShiftList = x.Select(s => new ShiftList() { Start = s.StartDate!.Value, End = s.EndDate!.Value }).ToList(),
HasFriday = x.Any(s => s.StartDate != null && s.EndDate != null && (s.StartDate.Value.DayOfWeek == DayOfWeek.Friday || s.EndDate.Value!.DayOfWeek == DayOfWeek.Friday)),
SumOneDaySpan = new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks)) - CalculateBreakTime(x.First().BreakTimeSpan,
new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks))),
BreakTime = CalculateBreakTime(x.First().BreakTimeSpan, new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks))),
TimeSpan breakTime;
if (contractStart > endOfFarvardin)
{
breakTime = CalculateBreakTime(
x.First().BreakTimeSpan,
new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks)));
}
else
{
breakTime = CalculateBreakTime(breakTimeEntity, new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks)));
}
return 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 != null && s.EndDate != null && (s.StartDate.Value.DayOfWeek == DayOfWeek.Friday ||
s.EndDate.Value!.DayOfWeek == DayOfWeek.Friday)),
SumOneDaySpan = new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks)) - breakTime,
BreakTime = breakTime,
};
}).OrderBy(x => x.CreationDate).ToList();
}
@@ -728,52 +743,52 @@ public class RollCallMandatoryRepository : RepositoryBase<long, RollCall>, IRoll
}
/// <summary>
/// محاسبه ساعات کارکرد پرسنل در صورت داشتن حضور غیاب
/// </summary>
/// <param name="employeeId"></param>
/// <param name="workshopId"></param>
/// <param name="contractStart"></param>
/// <param name="contractEnd"></param>
/// <returns></returns>
public (bool hasRollCall, TimeSpan sumOfSpan) GetRollCallWorkingSpan(long employeeId, long workshopId,
DateTime contractStart, DateTime contractEnd)
{
//bool hasRollcall =
// _rollCallEmployeeRepository.HasRollCallRecord(employeeId, workshopId, contractStart, contractEnd);
//if (!hasRollcall)
// return (false, new TimeSpan());
List<RollCallViewModel> rollCallResult;
List<GroupedRollCalls> groupedRollCall;
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.ShiftDate,
BreakTimeSpan = x.BreakTimeSpan
}).ToList();
groupedRollCall = rollCallResult.GroupBy(x => x.CreationDate.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 != null && s.EndDate != null && (s.StartDate.Value.DayOfWeek == DayOfWeek.Friday || s.EndDate.Value!.DayOfWeek == DayOfWeek.Friday)),
SumOneDaySpan = new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks)) - CalculateBreakTime(x.First().BreakTimeSpan,
new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks))),
BreakTime = CalculateBreakTime(x.First().BreakTimeSpan, new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks))),
}).OrderBy(x => x.CreationDate).ToList();
/// <summary>
/// محاسبه ساعات کارکرد پرسنل در صورت داشتن حضور غیاب
/// </summary>
/// <param name="employeeId"></param>
/// <param name="workshopId"></param>
/// <param name="contractStart"></param>
/// <param name="contractEnd"></param>
/// <returns></returns>
public (bool hasRollCall, TimeSpan sumOfSpan) GetRollCallWorkingSpan(long employeeId, long workshopId,
DateTime contractStart, DateTime contractEnd)
{
//bool hasRollcall =
// _rollCallEmployeeRepository.HasRollCallRecord(employeeId, workshopId, contractStart, contractEnd);
//if (!hasRollcall)
// return (false, new TimeSpan());
List<RollCallViewModel> rollCallResult;
List<GroupedRollCalls> groupedRollCall;
TimeSpan sumSpans = new TimeSpan(groupedRollCall.Sum(x => x.SumOneDaySpan.Ticks));
return (true, sumSpans);
}
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.ShiftDate,
BreakTimeSpan = x.BreakTimeSpan
}).ToList();
groupedRollCall = rollCallResult.GroupBy(x => x.CreationDate.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 != null && s.EndDate != null && (s.StartDate.Value.DayOfWeek == DayOfWeek.Friday || s.EndDate.Value!.DayOfWeek == DayOfWeek.Friday)),
SumOneDaySpan = new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks)) - CalculateBreakTime(x.First().BreakTimeSpan,
new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks))),
BreakTime = CalculateBreakTime(x.First().BreakTimeSpan, new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks))),
}).OrderBy(x => x.CreationDate).ToList();
TimeSpan sumSpans = new TimeSpan(groupedRollCall.Sum(x => x.SumOneDaySpan.Ticks));
return (true, sumSpans);
}
public async Task<ComputingViewModel> RotatingShiftReport(long workshopId, long employeeId, DateTime contractStart, DateTime contractEnd, string shiftwork, bool hasRollCall, CreateWorkingHoursTemp command, bool holidayWorking)
@@ -2090,7 +2105,7 @@ public class RollCallMandatoryRepository : RepositoryBase<long, RollCall>, IRoll
var starTimeSingel1 = Convert.ToDateTime(shift1Start);
var endTimeSingel2 = Convert.ToDateTime(shift1End);
bool hasRestTime = false;
bool hasRestTime = false;
shift1StartGr = new DateTime(cuurentDate.Year, cuurentDate.Month, cuurentDate.Day, starTimeSingel1.Hour, starTimeSingel1.Minute, 0);
@@ -2099,92 +2114,92 @@ public class RollCallMandatoryRepository : RepositoryBase<long, RollCall>, IRoll
if (shift1EndGr.TimeOfDay < shift1StartGr.TimeOfDay)
shift1EndGr = shift1EndGr.AddDays(1);
var shiftEndWithoutRest = shift1EndGr;
var shiftEndWithoutRest = shift1EndGr;
var shiftSpan = (shift1EndGr - shift1StartGr);
if (restTime > TimeSpan.Zero && shiftSpan >= restTime)
{
hasRestTime = true;
shift1EndGr = shift1EndGr.Subtract(restTime);
shiftSpan = (shift1EndGr - shift1StartGr);
}
var shiftSpan = (shift1EndGr - shift1StartGr);
if (restTime > TimeSpan.Zero && shiftSpan >= restTime)
{
hasRestTime = true;
shift1EndGr = shift1EndGr.Subtract(restTime);
shiftSpan = (shift1EndGr - shift1StartGr);
if (!leaveSearchResult.Any(x => x.StartLeaveGr < shift1EndGr && x.EndLeaveGr > shift1StartGr && x.PaidLeaveType =="روزانه"))
{
var hourseLeaveTypeResult = leaveSearchResult.FirstOrDefault(x =>
x.StartLeaveGr < shift1EndGr && x.EndLeaveGr > shift1StartGr && x.PaidLeaveType == "ساعتی");
if (hourseLeaveTypeResult == null)
{
result.Add(new RollCallViewModel()
{
BreakTimeSpan = hasRestTime ? restTime : TimeSpan.Zero,
StartDate = shift1StartGr,
EndDate = shift1EndGr,
ShiftSpan = shiftSpan,
ShiftDate = shift1StartGr,
}
if (!leaveSearchResult.Any(x => x.StartLeaveGr < shift1EndGr && x.EndLeaveGr > shift1StartGr && x.PaidLeaveType == "روزانه"))
{
var hourseLeaveTypeResult = leaveSearchResult.FirstOrDefault(x =>
x.StartLeaveGr < shift1EndGr && x.EndLeaveGr > shift1StartGr && x.PaidLeaveType == "ساعتی");
if (hourseLeaveTypeResult == null)
{
result.Add(new RollCallViewModel()
{
BreakTimeSpan = hasRestTime ? restTime : TimeSpan.Zero,
StartDate = shift1StartGr,
EndDate = shift1EndGr,
ShiftSpan = shiftSpan,
ShiftDate = shift1StartGr,
ShiftEndWithoutRest = shiftEndWithoutRest
});
}
else
{
});
}
else
{
if (hourseLeaveTypeResult.StartLeaveGr <= shift1StartGr && hourseLeaveTypeResult.EndLeaveGr < shift1EndGr)
{
//leave <-------------------->
//shift <---------------------------------->
result.Add(new RollCallViewModel()
{
BreakTimeSpan = hasRestTime ? restTime : TimeSpan.Zero,
StartDate = hourseLeaveTypeResult.EndLeaveGr,
EndDate = shift1EndGr,
ShiftSpan = (shift1EndGr - hourseLeaveTypeResult.EndLeaveGr),
ShiftDate = shift1StartGr,
ShiftEndWithoutRest = shiftEndWithoutRest
if (hourseLeaveTypeResult.StartLeaveGr <= shift1StartGr && hourseLeaveTypeResult.EndLeaveGr < shift1EndGr)
{
//leave <-------------------->
//shift <---------------------------------->
result.Add(new RollCallViewModel()
{
BreakTimeSpan = hasRestTime ? restTime : TimeSpan.Zero,
StartDate = hourseLeaveTypeResult.EndLeaveGr,
EndDate = shift1EndGr,
ShiftSpan = (shift1EndGr - hourseLeaveTypeResult.EndLeaveGr),
ShiftDate = shift1StartGr,
ShiftEndWithoutRest = shiftEndWithoutRest
});
}
else if (hourseLeaveTypeResult.StartLeaveGr > shift1StartGr && hourseLeaveTypeResult.EndLeaveGr < shift1EndGr)
{
//leave <-------------------->
//shift <---------------------------------->
result.Add(new RollCallViewModel()
{
BreakTimeSpan = hasRestTime ? restTime : TimeSpan.Zero,
StartDate = shift1StartGr,
EndDate = hourseLeaveTypeResult.StartLeaveGr,
ShiftSpan = (hourseLeaveTypeResult.StartLeaveGr - shift1StartGr),
ShiftDate = shift1StartGr,
ShiftEndWithoutRest = hourseLeaveTypeResult.StartLeaveGr
});
}
else if (hourseLeaveTypeResult.StartLeaveGr > shift1StartGr && hourseLeaveTypeResult.EndLeaveGr < shift1EndGr)
{
//leave <-------------------->
//shift <---------------------------------->
result.Add(new RollCallViewModel()
{
BreakTimeSpan = hasRestTime ? restTime : TimeSpan.Zero,
StartDate = shift1StartGr,
EndDate = hourseLeaveTypeResult.StartLeaveGr,
ShiftSpan = (hourseLeaveTypeResult.StartLeaveGr - shift1StartGr),
ShiftDate = shift1StartGr,
ShiftEndWithoutRest = hourseLeaveTypeResult.StartLeaveGr
});
});
result.Add(new RollCallViewModel()
{
BreakTimeSpan = hasRestTime ? restTime : TimeSpan.Zero,
StartDate = hourseLeaveTypeResult.EndLeaveGr,
EndDate = shift1EndGr,
ShiftSpan = (shift1EndGr - hourseLeaveTypeResult.EndLeaveGr),
ShiftDate = shift1StartGr,
ShiftEndWithoutRest = shiftEndWithoutRest
result.Add(new RollCallViewModel()
{
BreakTimeSpan = hasRestTime ? restTime : TimeSpan.Zero,
StartDate = hourseLeaveTypeResult.EndLeaveGr,
EndDate = shift1EndGr,
ShiftSpan = (shift1EndGr - hourseLeaveTypeResult.EndLeaveGr),
ShiftDate = shift1StartGr,
ShiftEndWithoutRest = shiftEndWithoutRest
});
}
else if (hourseLeaveTypeResult.StartLeaveGr > shift1StartGr && hourseLeaveTypeResult.EndLeaveGr >= shift1EndGr)
{
//leave <-------------------->
//shift <---------------------------------->
});
}
else if (hourseLeaveTypeResult.StartLeaveGr > shift1StartGr && hourseLeaveTypeResult.EndLeaveGr >= shift1EndGr)
{
//leave <-------------------->
//shift <---------------------------------->
result.Add(new RollCallViewModel()
{
BreakTimeSpan = hasRestTime ? restTime : TimeSpan.Zero,
StartDate = shift1StartGr,
EndDate = hourseLeaveTypeResult.StartLeaveGr,
ShiftSpan = (hourseLeaveTypeResult.StartLeaveGr - shift1StartGr),
ShiftDate = shift1StartGr,
ShiftEndWithoutRest = hourseLeaveTypeResult.StartLeaveGr
result.Add(new RollCallViewModel()
{
BreakTimeSpan = hasRestTime ? restTime : TimeSpan.Zero,
StartDate = shift1StartGr,
EndDate = hourseLeaveTypeResult.StartLeaveGr,
ShiftSpan = (hourseLeaveTypeResult.StartLeaveGr - shift1StartGr),
ShiftDate = shift1StartGr,
ShiftEndWithoutRest = hourseLeaveTypeResult.StartLeaveGr
});
});
}
@@ -3021,13 +3036,13 @@ public class RollCallMandatoryRepository : RepositoryBase<long, RollCall>, IRoll
var endFarvarding = new DateTime(2025, 4, 20);
if (contractStart>endFarvarding)
if (contractStart > endFarvarding)
{
customizeWorkshopEmployeeSettings=_context.CustomizeWorkshopEmployeeSettings
customizeWorkshopEmployeeSettings = _context.CustomizeWorkshopEmployeeSettings
.AsSplitQuery().AsNoTracking().FirstOrDefault(x =>
x.WorkshopId == workshopId && x.EmployeeId == employeeId);
customizeWorkshopSettings =_context.CustomizeWorkshopSettings.AsNoTracking().FirstOrDefault(x => x.WorkshopId == workshopId);
customizeWorkshopSettings = _context.CustomizeWorkshopSettings.AsNoTracking().FirstOrDefault(x => x.WorkshopId == workshopId);
}
else
@@ -3982,40 +3997,40 @@ public class RollCallMandatoryRepository : RepositoryBase<long, RollCall>, IRoll
}).ToList();
}
public List<LoanInstallmentViewModel> LoanInstallmentForCheckout(long employeeId, long workshopId, DateTime contractStart, DateTime contractEnd)
{
return _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()
{
Id = x.Id,
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(),
LoanAmount = _context.Loans.FirstOrDefault(l => l.id == x.LoanId).Amount.ToMoney()
}).ToList();
}
public List<LoanInstallmentViewModel> LoanInstallmentForCheckout(long employeeId, long workshopId, DateTime contractStart, DateTime contractEnd)
{
return _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()
{
Id = x.Id,
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(),
LoanAmount = _context.Loans.FirstOrDefault(l => l.id == x.LoanId).Amount.ToMoney()
}).ToList();
}
public List<SalaryAidViewModel> SalaryAidsForCheckout(long employeeId, long workshopId, DateTime checkoutStart, DateTime checkoutEnd)
{
return _context.SalaryAids
.Where(x => x.CalculationDate >= checkoutStart && x.CalculationDate <= checkoutEnd && x.EmployeeId == employeeId && x.WorkshopId == workshopId).Select(x => new SalaryAidViewModel()
{
Amount = x.Amount.ToMoney(),
AmountDouble = x.Amount,
SalaryAidDateTimeFa = x.SalaryAidDateTime.ToFarsi(),
SalaryAidDateTimeGe = x.SalaryAidDateTime,
CalculationDateTimeGe = x.CalculationDate,
CalculationDateTimeFa = x.CalculationDate.ToFarsi(),
Id = x.id
}).ToList();
}
public List<SalaryAidViewModel> SalaryAidsForCheckout(long employeeId, long workshopId, DateTime checkoutStart, DateTime checkoutEnd)
{
return _context.SalaryAids
.Where(x => x.CalculationDate >= checkoutStart && x.CalculationDate <= checkoutEnd && x.EmployeeId == employeeId && x.WorkshopId == workshopId).Select(x => new SalaryAidViewModel()
{
Amount = x.Amount.ToMoney(),
AmountDouble = x.Amount,
SalaryAidDateTimeFa = x.SalaryAidDateTime.ToFarsi(),
SalaryAidDateTimeGe = x.SalaryAidDateTime,
CalculationDateTimeGe = x.CalculationDate,
CalculationDateTimeFa = x.CalculationDate.ToFarsi(),
Id = x.id
}).ToList();
}
private void CreateRewardForBirthDay(long employeeId, long workshopId, double amount, int month, int year,
DateTime contractStart)

File diff suppressed because it is too large Load Diff