private List <AbsencePolicyEntitlement> GenerateAbsencePolicyAbsenceTypeEntitlements(IEnumerable <AbsencePolicyEntitlement> absencePolicyEntitlements, AbsencePolicyPeriod absencePolicyPeriod) { var absencePeriodAbsencePolicyAbsenceTypeEntitlements = new List <AbsencePolicyEntitlement>(); if (absencePolicyPeriod == null) { return(null); } if (absencePolicyEntitlements != null) { foreach (var dcEntitlement in absencePolicyEntitlements) { dcEntitlement.StartDate = absencePolicyPeriod.AbsencePeriod.StartDate; if (dcEntitlement.Frequency.Name.Trim().ToLower() == "yearly") { dcEntitlement.EndDate = absencePolicyPeriod.AbsencePeriod.EndDate; absencePeriodAbsencePolicyAbsenceTypeEntitlements.Add(dcEntitlement); } else { dcEntitlement.EndDate = absencePolicyPeriod.AbsencePeriod.StartDate.AddMonths(3).AddDays(-1); absencePeriodAbsencePolicyAbsenceTypeEntitlements.Add(dcEntitlement); for (int i = 1; i < 4; i++) { var extraEntitlement = dcEntitlement.Copy(); extraEntitlement.StartDate = absencePolicyPeriod.AbsencePeriod.StartDate.AddMonths(i * 3); extraEntitlement.EndDate = extraEntitlement.StartDate.Value.AddMonths(3).AddDays(-1); absencePeriodAbsencePolicyAbsenceTypeEntitlements.Add(extraEntitlement); } } } } // Set to -1 so we can set to null later var nullOthersEntitlement = new AbsencePolicyEntitlement { OrganisationId = absencePolicyPeriod.OrganisationId, AbsenceTypeId = 0, FrequencyId = 1, Entitlement = 0, MaximumCarryForward = 0, AbsencePolicyId = absencePolicyPeriod.AbsencePolicyId, Frequency = new Frequency { FrequencyId = 1, Name = "yearly" }, StartDate = absencePolicyPeriod.AbsencePeriod.StartDate, EndDate = absencePolicyPeriod.AbsencePeriod.EndDate, //HasEntitlement = false }; absencePeriodAbsencePolicyAbsenceTypeEntitlements.Add(nullOthersEntitlement); return(absencePeriodAbsencePolicyAbsenceTypeEntitlements); }
public AbsencePolicyEntitlement CreateAbsencePolicyEntitlement(int organisationId, int absencePolicyId, int absenceTypeId) { var absencepolicyEntitlement = new AbsencePolicyEntitlement() { OrganisationId = organisationId, AbsenceTypeId = absenceTypeId, FrequencyId = 1, IsPaid = false, IsUnplanned = false, HasEntitlement = false, MaximumCarryForward = 0, AbsencePolicyId = absencePolicyId }; return(_hrDataService.CreateAbsencePolicyEntitlement(organisationId, absencePolicyId, absencepolicyEntitlement)); }
public double?CalculateProRataEntitlement(AbsencePolicyEntitlement absencePolicyEntitlement, WorkingPattern absencePolicyWorkingPattern, DateTime periodStartDate, DateTime periodEndDate, DateTime employmentStartDate) { if (absencePolicyEntitlement == null || absencePolicyWorkingPattern == null) { return(null); } if (absencePolicyEntitlement.Entitlement == 0) { return(0); } if (employmentStartDate == periodStartDate) { return(absencePolicyEntitlement.Entitlement); } var entitlementForWeek = (absencePolicyEntitlement.Entitlement * 7) / (absencePolicyEntitlement.EndDate.Value - absencePolicyEntitlement.StartDate.Value).TotalDays; var weekLeft = ((periodEndDate - employmentStartDate).TotalDays) / 7; var entitlement = (entitlementForWeek * weekLeft); // round to nearest half day return(Math.Round(entitlement * 2, MidpointRounding.AwayFromZero) / 2); }
public AbsencePolicyEntitlement UpdateAbsencePolicyEntitlement(int organisationId, AbsencePolicyEntitlement absencePolicyEntitlement) { absencePolicyEntitlement = _hrDataService.UpdateOrganisationEntityEntry(organisationId, absencePolicyEntitlement); var employments = _hrDataService.RetrieveActiveEmploymentsByAbsencePolicy(organisationId, absencePolicyEntitlement.AbsencePolicyId); CreatePersonnelAbsenceEntitlements(organisationId, employments, absencePolicyEntitlement.AbsencePolicyId); return(absencePolicyEntitlement); }
public AbsencePolicyEntitlement CreateAbsencePolicyEntitlement(int organisationId, int absencePolicyId, AbsencePolicyEntitlement absencepolicyEntitlement) { using (var context = _databaseFactory.Create(organisationId)) { var result = context.AbsencePolicyEntitlements.Add(absencepolicyEntitlement); context.SaveChanges(); return(result); } }