private void RemoveUnpaidPaymentIfExists(PendingPayment existingPendingPayment) { var existingPayment = Model.PaymentModels.SingleOrDefault(x => x.PendingPaymentId == existingPendingPayment.Id); if (existingPayment != null) { if (Model.PaymentModels.Remove(existingPayment)) { AddEvent(new PaymentDeleted(Model.Account.Id, Model.Account.AccountLegalEntityId, Model.Apprenticeship.UniqueLearnerNumber, existingPayment)); } } }
public bool EquivalentTo(PendingPayment pendingPayment) { if (pendingPayment == null) { return(false); } return(Amount == pendingPayment.Amount && CollectionPeriod == pendingPayment.CollectionPeriod && DueDate == pendingPayment.DueDate && PaymentMadeDate == pendingPayment.PaymentMadeDate && EarningType == pendingPayment.EarningType && ClawedBack == pendingPayment.ClawedBack); }
private void AddPendingPaymentsAndClawbackWhereRequired(ValueObjects.Payment payment, CollectionCalendar collectionCalendar) { var pendingPayment = PendingPayment.New( Guid.NewGuid(), Model.Account, Model.Id, payment.Amount, payment.PaymentDate, DateTime.Now, payment.EarningType); pendingPayment.SetPaymentPeriod(collectionCalendar); var existingPendingPayment = PendingPayments.SingleOrDefault(x => x.EarningType == pendingPayment.EarningType && !x.ClawedBack); if (existingPendingPayment == null) { Model.PendingPaymentModels.Add(pendingPayment.GetModel()); return; } if (ExistingPendingPaymentHasBeenPaid(existingPendingPayment)) { if (!existingPendingPayment.RequiresNewPayment(pendingPayment)) { return; } AddClawback(existingPendingPayment, collectionCalendar.GetActivePeriod()); Model.PendingPaymentModels.Add(pendingPayment.GetModel()); return; } RemoveUnpaidPaymentIfExists(existingPendingPayment); if (!existingPendingPayment.EquivalentTo(pendingPayment)) { if (!existingPendingPayment.RequiresNewPaymentAfterBreakInLearning(Model.BreakInLearnings)) { return; } var existingPendingPaymentModel = existingPendingPayment.GetModel(); if (Model.PendingPaymentModels.Remove(existingPendingPaymentModel)) { AddEvent(new PendingPaymentDeleted(Model.Account.Id, Model.Account.AccountLegalEntityId, Model.Apprenticeship.UniqueLearnerNumber, existingPendingPaymentModel)); } Model.PendingPaymentModels.Add(pendingPayment.GetModel()); } }
private bool ExistingPendingPaymentHasBeenPaid(PendingPayment existingPendingPayment) { if (existingPendingPayment.PaymentMadeDate == null) { return(false); } var existingPayment = Model.PaymentModels.SingleOrDefault(x => x.PendingPaymentId == existingPendingPayment.Id); if (existingPayment == null || existingPayment.PaidDate == null) { return(false); } return(true); }
private void AddClawback(PendingPayment pendingPayment, CollectionPeriod collectionPeriod) { pendingPayment.ClawBack(); var payment = Model.PaymentModels.Single(p => p.PendingPaymentId == pendingPayment.Id); if (!Model.ClawbackPaymentModels.Any(c => c.PendingPaymentId == pendingPayment.Id)) { var clawback = ClawbackPayment.New( Guid.NewGuid(), Model.Account, Model.Id, pendingPayment.Id, -pendingPayment.Amount, DateTime.Now, payment.SubnominalCode, payment.Id); clawback.SetPaymentPeriod(collectionPeriod); Model.ClawbackPaymentModels.Add(clawback.GetModel()); } }
public bool RequiresNewPayment(PendingPayment pendingPayment) { return(Amount != pendingPayment.Amount || CollectionPeriod != pendingPayment.CollectionPeriod); }
private void AddPayment(Guid pendingPaymentId, short collectionYear, byte collectionPeriod, PendingPayment pendingPayment, DateTime paymentDate) { var subnominalCode = DetermineSubnominalCode(); var payment = Payment.New( Guid.NewGuid(), Model.Account, Model.Id, pendingPaymentId, pendingPayment.Amount, paymentDate, collectionYear, collectionPeriod, subnominalCode); Model.PaymentModels.Add(payment.GetModel()); }
public bool RequiresNewPayment(PendingPayment pendingPayment) { return(Amount != pendingPayment.Amount || PeriodNumber != pendingPayment.PeriodNumber || PaymentYear != pendingPayment.PaymentYear); }
private void AddPayment(Guid pendingPaymentId, CollectionPeriod collectionPeriod, PendingPayment pendingPayment, DateTime paymentDate) { var subnominalCode = DetermineSubnominalCode(); var account = Model.Account; var payment = Payment.New( Guid.NewGuid(), Model.Account, Model.Id, pendingPaymentId, pendingPayment.Amount, paymentDate, collectionPeriod.AcademicYear, collectionPeriod.PeriodNumber, subnominalCode, string.Empty); Model.PaymentModels.Add(payment.GetModel()); }