Files
Backend-Api/Company.Domain/CustomizeWorkshopSettingsAgg/Entities/CustomizeWorkshopSettings.cs

147 lines
6.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using _0_Framework.Domain;
using _0_Framework.Domain.CustomizeCheckoutShared.Base;
using _0_Framework.Domain.CustomizeCheckoutShared.Enums;
using _0_Framework.Domain.CustomizeCheckoutShared.ValueObjects;
using Company.Domain.CustomizeWorkshopGroupSettingsAgg.Entities;
using Company.Domain.WorkshopAgg;
namespace Company.Domain.CustomizeWorkshopSettingsAgg.Entities;
public class CustomizeWorkshopSettings : BaseCustomizeEntity
{
private CustomizeWorkshopSettings()
{
}
public CustomizeWorkshopSettings(long workshopId,
ICollection<CustomizeWorkshopSettingsShift> customizeWorkshopSettingsShifts, int leavePermittedDays,
WorkshopShiftStatus workshopShiftStatus,HolidayWork holidayWork, List<WeeklyOffDay> weeklyOffDays)
{
FridayPay = new FridayPay(FridayPayType.None, 0);
OverTimePay = new OverTimePay(OverTimePayType.None, 0);
BaseYearsPay = new BaseYearsPay(BaseYearsPayType.None, 0, BaseYearsPaymentType.None);
BonusesPay = new BonusesPay(BonusesType.None, 0, BonusesPaymentType.None);
NightWorkPay = new NightWorkPay(NightWorkType.None, 0);
MarriedAllowance = new MarriedAllowance(MarriedAllowanceType.None, 0);
ShiftPay = new ShiftPay(ShiftType.None, ShiftPayType.None, 0);
FamilyAllowance = new FamilyAllowance(FamilyAllowanceType.None, 0);
LeavePay = new LeavePay(LeavePayType.None, 0);
InsuranceDeduction = new InsuranceDeduction(InsuranceDeductionType.None, 0);
FineAbsenceDeduction = new FineAbsenceDeduction(FineAbsenceDeductionType.None, 0, new());
LateToWork = new LateToWork(LateToWorkType.None, new(), 0);
EarlyExit = new EarlyExit(EarlyExitType.None, new(), 0);
WorkshopId = workshopId;
CustomizeWorkshopSettingsShifts = customizeWorkshopSettingsShifts;
LeavePermittedDays = leavePermittedDays == 0 ? 2 : leavePermittedDays;
OverTimeThresholdMinute = 0;
Currency = Currency.Rial;
MaxMonthDays = MaxMonthDays.Default;
BonusesPaysInEndOfMonth = BonusesPaysInEndOfYear.EndOfYear;
WorkshopShiftStatus = workshopShiftStatus;
WeeklyOffDays = weeklyOffDays;
HolidayWork = holidayWork;
if (workshopShiftStatus == WorkshopShiftStatus.Irregular)
return;
if (customizeWorkshopSettingsShifts is not { Count: > 0 })
return;
var date = new DateOnly();
var firstStartShift = new DateTime(date, CustomizeWorkshopSettingsShifts.MinBy(x => x.Placement).StartTime);
var lastEndShift = new DateTime(date, CustomizeWorkshopSettingsShifts.MaxBy(x => x.Placement).EndTime);
if (lastEndShift > firstStartShift)
firstStartShift = firstStartShift.AddDays(1);
var offSet = (firstStartShift - lastEndShift).Divide(2);
EndTimeOffSet = TimeOnly.FromDateTime(lastEndShift.Add(offSet));
}
/// <summary>
/// نوع محاسبه تعداد روز های ماه برای محاسبه فیش حقوقی
/// </summary>
public MaxMonthDays MaxMonthDays { get; private set; }
/// <summary>
/// آیا عیدی همیشه آخر سال تعلق میگیره یا در زمان ترک کار هم تعلق میگیره
/// </summary>
public BonusesPaysInEndOfYear BonusesPaysInEndOfMonth { get; private set; }
public BaseYearsPayInEndOfYear BaseYearsPayInEndOfYear { get; private set; }
public long WorkshopId { get; private set; }
public Workshop Workshop { get; set; }
public TimeOnly EndTimeOffSet { get; private set; }
public Currency Currency { get; private set; }
public int OverTimeThresholdMinute { get; private set; }
public WorkshopShiftStatus WorkshopShiftStatus { get; private set; }
public ICollection<CustomizeWorkshopGroupSettings> CustomizeWorkshopGroupSettingsCollection { get; set; }
public ICollection<CustomizeWorkshopSettingsShift> CustomizeWorkshopSettingsShifts { get; set; }
public void Edit(FridayPay fridayPay, OverTimePay overTimePay, BaseYearsPay baseYearsPay, BonusesPay bonusesPay,
NightWorkPay nightWorkPay, MarriedAllowance marriedAllowance, ShiftPay shiftPay,
FamilyAllowance familyAllowance, LeavePay leavePay, InsuranceDeduction insuranceDeduction,
FineAbsenceDeduction fineAbsenceDeduction, LateToWork lateToWork, EarlyExit earlyExit, HolidayWork holidayWork, BonusesPaysInEndOfYear bonusesPaysInEndOfYear,
int leavePermittedDays, BaseYearsPayInEndOfYear baseYearsPayInEndOfYear, int overTimeThresholdMinute)
{
FridayPay = fridayPay;
OverTimePay = overTimePay;
BaseYearsPay = baseYearsPay;
BonusesPay = bonusesPay;
NightWorkPay = nightWorkPay;
MarriedAllowance = marriedAllowance;
ShiftPay = shiftPay;
FamilyAllowance = familyAllowance;
LeavePay = leavePay;
InsuranceDeduction = insuranceDeduction;
FineAbsenceDeduction = fineAbsenceDeduction;
LateToWork = lateToWork;
EarlyExit = earlyExit;
HolidayWork = holidayWork;
BonusesPaysInEndOfMonth = bonusesPaysInEndOfYear;
LeavePermittedDays = leavePermittedDays;
BaseYearsPayInEndOfYear = baseYearsPayInEndOfYear;
OverTimeThresholdMinute = overTimeThresholdMinute;
}
//edits the shifts of workshop
public void ChangeCurrency(Currency currency)
{
if (currency == Currency)
return;
Currency = currency;
}
public void ChangeWorkshopShifts(ICollection<CustomizeWorkshopSettingsShift> customizeWorkshopSettingsShifts,
WorkshopShiftStatus workshopShiftStatus,HolidayWork holidayWork, List<WeeklyOffDay> weeklyOffDays)
{
WorkshopShiftStatus = workshopShiftStatus;
HolidayWork = holidayWork;
CustomizeWorkshopSettingsShifts = workshopShiftStatus == WorkshopShiftStatus.Regular ? customizeWorkshopSettingsShifts : new List<CustomizeWorkshopSettingsShift>();
WeeklyOffDays = weeklyOffDays;
if (workshopShiftStatus == WorkshopShiftStatus.Regular)
{
var date = new DateOnly();
var firstStartShift = new DateTime(date, CustomizeWorkshopSettingsShifts.MinBy(x => x.Placement).StartTime);
var lastEndShift = new DateTime(date, CustomizeWorkshopSettingsShifts.MaxBy(x => x.Placement).EndTime);
if (lastEndShift > firstStartShift)
firstStartShift = firstStartShift.AddDays(1);
var offSet = (firstStartShift - lastEndShift).Divide(2);
EndTimeOffSet = TimeOnly.FromDateTime(lastEndShift.Add(offSet));
}
}
}