BreakTime Merged
This commit is contained in:
@@ -32,6 +32,9 @@ public interface IRollCallDomainService
|
||||
|
||||
(DateTime start, DateTime end) FindRotatingShift(DateTime startRollCall, DateTime endRollCall, ICollection<CustomizeRotatingShift> rotatingShifts);
|
||||
(DateTime start, DateTime end) FindRotatingShift(List<(DateTime StartDate, DateTime EndDate)> rollcalls, ICollection<CustomizeRotatingShift> rotatingShifts);
|
||||
|
||||
BreakTime GetBreakTime(long employeeId, long workshopId);
|
||||
|
||||
}
|
||||
|
||||
public class RollCallDomainService : IRollCallDomainService
|
||||
@@ -672,6 +675,17 @@ public class RollCallDomainService : IRollCallDomainService
|
||||
return (overlapChosenShift.Shift.Start, end);
|
||||
}
|
||||
|
||||
public BreakTime GetBreakTime(long employeeId, long workshopId)
|
||||
{
|
||||
var employeeSettings = _customizeWorkshopEmployeeSettingsRepository.GetByEmployeeIdAndWorkshopIdIncludeGroupSettings(workshopId,
|
||||
employeeId);
|
||||
if (employeeSettings == null)
|
||||
{
|
||||
return new BreakTime(false, TimeOnly.MinValue);
|
||||
}
|
||||
|
||||
return employeeSettings.BreakTime;
|
||||
}
|
||||
private DateTime CalculateRegularShiftDate(DateTime startDate, TimeOnly offset)
|
||||
{
|
||||
DateTime nextOffSetDateTime;
|
||||
|
||||
@@ -4,6 +4,8 @@ using System;
|
||||
using Company.Domain.RollCallAgg.DomainService;
|
||||
using System.Linq;
|
||||
using _0_Framework.Exceptions;
|
||||
using Company.Domain.EmployeeAgg;
|
||||
using Company.Domain.WorkshopAgg;
|
||||
|
||||
namespace Company.Domain.RollCallAgg
|
||||
{
|
||||
@@ -34,10 +36,10 @@ namespace Company.Domain.RollCallAgg
|
||||
{
|
||||
throw new NotFoundException("اطلاعات گروهبندی شخص نامعتبر است");
|
||||
}
|
||||
|
||||
SetBreakTime(service, employeeId, workshopId);
|
||||
//if (endDate.HasValue)
|
||||
//{
|
||||
// Edit(StartDate.Value,endDate.Value,service);
|
||||
// Edit(StartDate.Value,endDate.Value,service);
|
||||
//}
|
||||
|
||||
}
|
||||
@@ -198,30 +200,7 @@ namespace Company.Domain.RollCallAgg
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Truncates the TimeSpan to only include days, hours, and minutes.
|
||||
/// Removes seconds, milliseconds, and smaller units.
|
||||
/// </summary>
|
||||
/// <param name="time">The original TimeSpan value.</param>
|
||||
/// <returns>A truncated TimeSpan with only days, hours, and minutes.</returns>
|
||||
private TimeSpan TruncateTimeSpan(TimeSpan time)
|
||||
{
|
||||
return new TimeSpan(time.Days, time.Hours, time.Minutes, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Truncates the DateTime to only include Years,Month,days,Hours and Minutes.
|
||||
/// Removes seconds, milliseconds, and smaller units.
|
||||
/// </summary>
|
||||
/// <param name="dateTime">The original DateTime value.</param>
|
||||
/// <returns>A truncated DateTime with only days, hours, and minutes.</returns>
|
||||
private DateTime TruncateDateTime(DateTime dateTime)
|
||||
{
|
||||
return new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour,
|
||||
dateTime.Minute, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void SetEndDateTime(DateTime endDate, IRollCallDomainService service)
|
||||
{
|
||||
@@ -238,7 +217,7 @@ namespace Company.Domain.RollCallAgg
|
||||
////محاسبه اختلاف زمانی(تاخیر و تعجیل)ء
|
||||
service.CalculateTimeDifferences(this);
|
||||
|
||||
|
||||
SetBreakTime(service, EmployeeId, WorkshopId);
|
||||
}
|
||||
|
||||
|
||||
@@ -259,6 +238,8 @@ namespace Company.Domain.RollCallAgg
|
||||
//محاسبه اختلاف زمانی(تاخیر و تعجیل)ء
|
||||
service.CalculateTimeDifferences(this);
|
||||
|
||||
SetBreakTime(service, EmployeeId, WorkshopId);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -331,6 +312,40 @@ namespace Company.Domain.RollCallAgg
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void SetBreakTime(IRollCallDomainService rollCallDomainService, long employeeId, long workshopId)
|
||||
{
|
||||
var breakTime = rollCallDomainService.GetBreakTime(employeeId, workshopId);
|
||||
|
||||
if (breakTime.BreakTimeType == BreakTimeType.WithTime)
|
||||
BreakTimeSpan = breakTime.BreakTimeValue.ToTimeSpan();
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Truncates the TimeSpan to only include days, hours, and minutes.
|
||||
/// Removes seconds, milliseconds, and smaller units.
|
||||
/// </summary>
|
||||
/// <param name="time">The original TimeSpan value.</param>
|
||||
/// <returns>A truncated TimeSpan with only days, hours, and minutes.</returns>
|
||||
private TimeSpan TruncateTimeSpan(TimeSpan time)
|
||||
{
|
||||
return new TimeSpan(time.Days, time.Hours, time.Minutes, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Truncates the DateTime to only include Years,Month,days,Hours and Minutes.
|
||||
/// Removes seconds, milliseconds, and smaller units.
|
||||
/// </summary>
|
||||
/// <param name="dateTime">The original DateTime value.</param>
|
||||
/// <returns>A truncated DateTime with only days, hours, and minutes.</returns>
|
||||
private DateTime TruncateDateTime(DateTime dateTime)
|
||||
{
|
||||
return new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour,
|
||||
dateTime.Minute, 0);
|
||||
}
|
||||
//private static (DateTime start, DateTime end) FindRotatingShift(DateTime startRollCall, DateTime endRollCall, ICollection<CustomizeRotatingShift> rotatingShifts)
|
||||
//{
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace CompanyManagment.App.Contracts.RollCall;
|
||||
public interface IRollCallMandatoryApplication
|
||||
{
|
||||
bool HasRollCallRecord(long employeeId, long workshopId, DateTime contractStart);
|
||||
ComputingViewModel MandatoryCompute(long employeeId, long workshopId, DateTime contractStart, DateTime contractEnd, CreateWorkingHoursTemp command, bool holidayWorking);
|
||||
ComputingViewModel MandatoryCompute(long employeeId, long workshopId, DateTime contractStart, DateTime contractEnd, CreateWorkingHoursTemp command, bool holidayWorking, bool isStaticCheckout);
|
||||
|
||||
/// <summary>
|
||||
/// گزارش نوبت کاری حضور غیاب
|
||||
|
||||
@@ -61,4 +61,8 @@ public class RollCallViewModel
|
||||
/// مقدار تایم شیفت (مدت زمان شیفت کاری)
|
||||
/// </summary>
|
||||
public TimeSpan ShiftDurationTimeSpan { get; set; }
|
||||
/// <summary>
|
||||
/// مدت زمان استراحت
|
||||
/// </summary>
|
||||
public TimeSpan BreakTimeSpan { get; set; }
|
||||
}
|
||||
@@ -793,17 +793,17 @@ public class RollCallApplication : IRollCallApplication
|
||||
{
|
||||
List<DateTime> fromDates = commands.Select(x => x.FromDate.ToGeorgianDateTime()).ToList();
|
||||
var employeeIds = commands.Select(x => x.EmployeeId).ToList();
|
||||
if (_checkoutRepository.Exists(x => x.WorkshopId == workshopId && employeeIds.Contains(x.EmployeeId) && fromDates.Any(a => a <= x.ContractStart)))
|
||||
if (_checkoutRepository.Exists(x => x.WorkshopId == workshopId && employeeIds.Contains(x.EmployeeId) && fromDates.Any(a => a <= x.ContractEnd)))
|
||||
{
|
||||
return operationResult.Failed("پرسنل بعد از تاریخ وارد شده دارای فیش رسمی است");
|
||||
}
|
||||
|
||||
if (_customizeCheckoutRepository.Exists(x => x.WorkshopId == workshopId && employeeIds.Contains(x.EmployeeId) && fromDates.Any(a => a <= x.ContractStart)))
|
||||
if (_customizeCheckoutRepository.Exists(x => x.WorkshopId == workshopId && employeeIds.Contains(x.EmployeeId) && fromDates.Any(a => a <= x.ContractEnd)))
|
||||
{
|
||||
return operationResult.Failed("پرسنل بعد از تاریخ وارد شده دارای فیش غیررسمی نهایی است");
|
||||
}
|
||||
|
||||
if (_customizeCheckoutTempRepository.Exists(x => x.WorkshopId == workshopId && employeeIds.Contains(x.EmployeeId) && fromDates.Any(a => a <= x.ContractStart)))
|
||||
if (_customizeCheckoutTempRepository.Exists(x => x.WorkshopId == workshopId && employeeIds.Contains(x.EmployeeId) && fromDates.Any(a => a <= x.ContractEnd)))
|
||||
{
|
||||
return operationResult.Failed("پرسنل بعد از تاریخ وارد شده دارای فیش غیررسمی موقت است");
|
||||
}
|
||||
|
||||
@@ -191,6 +191,11 @@ public class CustomizeWorkshopEmployeeSettingsRepository(CompanyContext companyC
|
||||
return true;
|
||||
}
|
||||
|
||||
if (command.BreakTime.BreakTimeValue != employeeSettings.BreakTime.BreakTimeValue || command.BreakTime.HasBreakTimeValue != employeeSettings.BreakTime.HasBreakTimeValue)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (employeeSettings.WorkshopShiftStatus)
|
||||
{
|
||||
case WorkshopShiftStatus.Irregular:
|
||||
|
||||
@@ -135,16 +135,19 @@ public class RollCallMandatoryRepository : RepositoryBase<long, RollCall>, IRoll
|
||||
EndDate = x.EndDate,
|
||||
ShiftSpan = (x.EndDate.Value - x.StartDate.Value),
|
||||
CreationDate = x.ShiftDate,
|
||||
}).ToList();
|
||||
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(breakTime,
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -853,18 +856,24 @@ public class RollCallMandatoryRepository : RepositoryBase<long, RollCall>, IRoll
|
||||
|
||||
#endregion
|
||||
}
|
||||
public static TimeSpan CalculateBreakTime(BreakTime breakTime, TimeSpan sumOneDaySpan)
|
||||
//public static TimeSpan CalculateBreakTime(BreakTime breakTime, TimeSpan sumOneDaySpan)
|
||||
//{
|
||||
// if (breakTime.BreakTimeType != BreakTimeType.WithTime)
|
||||
// return new TimeSpan();
|
||||
|
||||
// var breakTimeSpan = breakTime.BreakTimeValue.ToTimeSpan();
|
||||
|
||||
// if (breakTimeSpan * 2 >= sumOneDaySpan)
|
||||
// return new TimeSpan();
|
||||
|
||||
// return breakTimeSpan; ;
|
||||
|
||||
//}
|
||||
public static TimeSpan CalculateBreakTime(TimeSpan breakTimeSpan, TimeSpan sumOneDaySpan)
|
||||
{
|
||||
if (breakTime.BreakTimeType != BreakTimeType.WithTime)
|
||||
return new TimeSpan();
|
||||
|
||||
var breakTimeSpan = breakTime.BreakTimeValue.ToTimeSpan();
|
||||
|
||||
if (breakTimeSpan * 2 >= sumOneDaySpan)
|
||||
return new TimeSpan();
|
||||
|
||||
return breakTimeSpan; ;
|
||||
|
||||
}
|
||||
|
||||
public TimeSpan AfterSubtract(CreateWorkingHoursTemp command, TimeSpan sumOneDaySpan, DateTime creationDate)
|
||||
@@ -2319,6 +2328,7 @@ public class RollCallMandatoryRepository : RepositoryBase<long, RollCall>, IRoll
|
||||
EndDate = x.EndDate,
|
||||
ShiftSpan = (x.EndDate.Value - x.StartDate.Value),
|
||||
CreationDate = x.CreationDate,
|
||||
BreakTimeSpan = x.BreakTimeSpan
|
||||
}).ToList();
|
||||
|
||||
|
||||
@@ -2330,10 +2340,10 @@ public class RollCallMandatoryRepository : RepositoryBase<long, RollCall>, IRoll
|
||||
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)) - CalculateBreakTime(customizeWorkshopEmployeeSettings.BreakTime,
|
||||
SumOneDaySpan = new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks)) - CalculateBreakTime(x.First().BreakTimeSpan,
|
||||
new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks))),
|
||||
|
||||
BreakTime = CalculateBreakTime(customizeWorkshopEmployeeSettings.BreakTime, new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks)))
|
||||
BreakTime = CalculateBreakTime(x.First().BreakTimeSpan, new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks)))
|
||||
}).ToList();
|
||||
|
||||
|
||||
@@ -2946,8 +2956,10 @@ public class RollCallMandatoryRepository : RepositoryBase<long, RollCall>, IRoll
|
||||
LateEntryDuration = x.LateEntryDuration,
|
||||
EarlyExitDuration = x.EarlyExitDuration,
|
||||
LateExitDuration = x.LateExitDuration,
|
||||
ShiftDurationTimeSpan = x.ShiftDurationTimeSpan
|
||||
}).ToList();
|
||||
ShiftDurationTimeSpan = x.ShiftDurationTimeSpan,
|
||||
BreakTimeSpan = x.BreakTimeSpan
|
||||
|
||||
}).ToList();
|
||||
|
||||
|
||||
|
||||
@@ -2963,16 +2975,16 @@ public class RollCallMandatoryRepository : RepositoryBase<long, RollCall>, IRoll
|
||||
EarlyEntryDuration = s.EarlyEntryDuration,
|
||||
EarlyExitDuration = s.EarlyExitDuration,
|
||||
LateEntryDuration = s.LateEntryDuration,
|
||||
LateExitDuration = s.LateExitDuration
|
||||
LateExitDuration = s.LateExitDuration,
|
||||
}).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)) - CalculateBreakTime(
|
||||
customizeWorkshopEmployeeSettings.BreakTime,
|
||||
x.First().BreakTimeSpan,
|
||||
new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks))),
|
||||
|
||||
BreakTime = CalculateBreakTime(customizeWorkshopEmployeeSettings.BreakTime,
|
||||
BreakTime = CalculateBreakTime(x.First().BreakTimeSpan,
|
||||
new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks))),
|
||||
ShiftDate = x.Key,
|
||||
TotalEarlyEntryDuration = new TimeSpan(x.Sum(rollCall => rollCall.EarlyEntryDuration.Ticks)),
|
||||
|
||||
@@ -154,13 +154,13 @@ public class RollCallRepository : RepositoryBase<long, RollCall>, IRollCallRepos
|
||||
|
||||
//گرفتن ساعت استراحت پرسنل از تنظیمات
|
||||
#region breakTime
|
||||
BaseCustomizeEntity settings = _context.CustomizeWorkshopEmployeeSettings.AsSplitQuery().FirstOrDefault(x =>
|
||||
x.WorkshopId == workshopId && x.EmployeeId == employeeId);
|
||||
//اگر ساعت استراحت پرسنل وجود نداشت صفر است
|
||||
var breakTime = settings == null ? new BreakTime(false, new TimeOnly()) : settings.BreakTime;
|
||||
//BaseCustomizeEntity settings = _context.CustomizeWorkshopEmployeeSettings.AsSplitQuery().FirstOrDefault(x =>
|
||||
// x.WorkshopId == workshopId && x.EmployeeId == employeeId);
|
||||
////اگر ساعت استراحت پرسنل وجود نداشت صفر است
|
||||
//var breakTime = settings == null ? new BreakTime(false, new TimeOnly()) : settings.BreakTime;
|
||||
#endregion
|
||||
|
||||
var rollCalls = _context.RollCalls.Where(x =>
|
||||
var rollCalls = _context.RollCalls.Where(x =>
|
||||
x.EmployeeId == employeeId && x.WorkshopId == workshopId && x.StartDate != null && x.EndDate != null && x.RollCallModifyType != RollCallModifyType.Undefined &&
|
||||
x.ShiftDate.Date >= startMonthDay && x.ShiftDate.Date <= endMonthDay).ToList();
|
||||
|
||||
@@ -223,7 +223,7 @@ public class RollCallRepository : RepositoryBase<long, RollCall>, IRollCallRepos
|
||||
|
||||
var rollCallTimeSpanPerDay =
|
||||
new TimeSpan(x.Where(y => y.EndDate != null).Sum(y => (y.EndDate - y.StartDate)!.Value.Ticks));
|
||||
var breakTimePerDay = RollCallMandatoryRepository.CalculateBreakTime(breakTime, rollCallTimeSpanPerDay);
|
||||
var breakTimePerDay = RollCallMandatoryRepository.CalculateBreakTime(x.First().BreakTimeSpan, rollCallTimeSpanPerDay);
|
||||
|
||||
return new CheckoutDailyRollCallViewModel()
|
||||
{
|
||||
|
||||
@@ -65,15 +65,15 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk
|
||||
public IActionResult OnPostShiftDateNew()
|
||||
{
|
||||
var startRollCall = new DateTime(2025, 4, 21);
|
||||
var employees = _context.CustomizeWorkshopEmployeeSettings
|
||||
.Where(x => x.WorkshopShiftStatus == WorkshopShiftStatus.Rotating).Select(x => x.EmployeeId).ToList();
|
||||
//var employees = _context.CustomizeWorkshopEmployeeSettings
|
||||
// .Where(x => x.WorkshopShiftStatus == WorkshopShiftStatus.Rotating).Select(x => x.EmployeeId).ToList();
|
||||
|
||||
var rollCalls = _context.RollCalls.Where(x => x.ShiftDate >= startRollCall && x.EndDate != null &&employees.Contains(x.EmployeeId)).ToList();
|
||||
var rollCalls = _context.RollCalls.Where(x => x.ShiftDate >= startRollCall && x.EndDate != null).ToList();
|
||||
var r1 = rollCalls.ToList();
|
||||
|
||||
Console.ForegroundColor = ConsoleColor.DarkRed;
|
||||
Console.WriteLine("endStep 1 ============");
|
||||
SetRollCall(r1);
|
||||
SetBreakTime(r1);
|
||||
|
||||
|
||||
ViewData["message"] = "تومام یک";
|
||||
@@ -444,6 +444,15 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk
|
||||
|
||||
}
|
||||
|
||||
private void SetBreakTime(List<global::Company.Domain.RollCallAgg.RollCall> r1)
|
||||
{
|
||||
foreach (var rollCall in r1)
|
||||
{
|
||||
rollCall.SetBreakTime(_rollCallDomainService,rollCall.EmployeeId,rollCall.WorkshopId);
|
||||
}
|
||||
|
||||
_context.SaveChanges();
|
||||
}
|
||||
private void SetRollCall(List<global::Company.Domain.RollCallAgg.RollCall> r1)
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user