コード例 #1
0
        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));
                }
            }
        }
コード例 #2
0
        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());
            }
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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());
            }
        }
コード例 #6
0
 public bool RequiresNewPayment(PendingPayment pendingPayment)
 {
     return(Amount != pendingPayment.Amount || CollectionPeriod != pendingPayment.CollectionPeriod);
 }
コード例 #7
0
        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());
        }
コード例 #8
0
 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());
        }