Ejemplo n.º 1
0
        public static void ApplyPostdatedCheckAsPayment(DateTime entryDate, DateTime transactionDate,int receiptId, decimal InterestPayment, decimal LoanPayment, decimal TotalPayment)
        {
            int paymentId = Payment.GetReceiptPayment(receiptId).Id;
            var check = Context.Cheques.SingleOrDefault(entity => entity.PaymentId == paymentId);
            var checkStatus = check.ChequeStatus.SingleOrDefault(entity => entity.IsActive == true && entity.CheckId == check.Id);
            var checkLoanAssoc = Context.ChequeLoanAssocs.SingleOrDefault(entity => entity.ChequeId == check.Id);
            var receipt = Receipt.GetById(receiptId);
            var tempReceiptBalance = receipt.ReceiptBalance;

            if (checkLoanAssoc != null && TotalPayment > 0)
            {
                var loanAccount = Context.LoanAccounts.SingleOrDefault(entity => entity.FinancialAccountId == checkLoanAssoc.FinancialAccountId);
                var agreement = loanAccount.FinancialAccount.Agreement;
                var amortizationSchedule = Context.AmortizationSchedules.SingleOrDefault(entity => entity.AgreementId == agreement.Id && entity.EndDate == null);
                var amortizationScheduleItem = amortizationSchedule.AmortizationScheduleItems.SingleOrDefault(entity => entity.ScheduledPaymentDate == check.CheckDate);
                var agreementItem = agreement.AgreementItems.SingleOrDefault(entity => entity.IsActive == true);
                var principalDue = amortizationScheduleItem.PrincipalPayment;

                Payment ParentPayment = Payment.CreatePayment(entryDate,
                                                       transactionDate,
                                                        check.Payment.ProcessedToPartyRoleId.Value,
                                                        check.Payment.ProcessedByPartyRoleId,
                                                        TotalPayment,
                                                        PaymentType.LoanPayment.Id,
                                                        PaymentMethodType.CashType.Id,
                                                        SpecificPaymentType.LoanPaymentType.Id,
                                                        null);

                Context.Payments.AddObject(ParentPayment);
                Context.SaveChanges();
                var customerPartyRole = PartyRole.GetById(check.Payment.ProcessedToPartyRoleId.Value);
                LoanPayment newLoanPayment = Payment.CreateLoanPayment(ParentPayment, customerPartyRole);
                Context.LoanPayments.AddObject(newLoanPayment);

                //For Payment Breakdown
                Payment paymentBreakdown = new Payment();
                paymentBreakdown.Payment2 = ParentPayment;
                paymentBreakdown.ProcessedByPartyRoleId = check.Payment.ProcessedByPartyRoleId;
                paymentBreakdown.ProcessedToPartyRoleId = check.Payment.ProcessedToPartyRoleId;
                paymentBreakdown.PaymentType = PaymentType.LoanPayment;
                paymentBreakdown.PaymentMethodTypeId = check.Payment.PaymentMethodTypeId;
                paymentBreakdown.TransactionDate = transactionDate;
                paymentBreakdown.TotalAmount = TotalPayment;
                paymentBreakdown.EntryDate = entryDate;
                paymentBreakdown.SpecificPaymentType = SpecificPaymentType.LoanPaymentType;
                Context.Payments.AddObject(paymentBreakdown);
                Context.SaveChanges();

                ReceiptPaymentAssoc assoc = new ReceiptPaymentAssoc();
                assoc.Receipt = receipt;
                assoc.Payment = paymentBreakdown;
                Context.ReceiptPaymentAssocs.AddObject(assoc);
                Context.SaveChanges();

                var finAcctTran = FinAcctTran.CreateFinAcctTran(loanAccount.FinancialAccountId, ParentPayment, transactionDate, entryDate, FinlAcctTransType.AccountPaymentType);
                Context.FinAcctTrans.AddObject(finAcctTran);
                Context.SaveChanges();

                //SaveInterestPayment
                SaveInterestPayment(entryDate, InterestPayment, loanAccount, ParentPayment);
                Context.SaveChanges();

                //SavePrincipalPayment
                LoanPayment = SaveLoanPayment(entryDate, LoanPayment, loanAccount, ParentPayment);

                //UpdateReceiptBalance and Status
                receipt.ReceiptBalance -= TotalPayment;
                var receiptStatus = ReceiptStatu.GetActive(receipt);
                if (receipt.ReceiptBalance == 0 && receiptStatus.ReceiptStatusType.Id != ReceiptStatusType.ClosedReceiptStatusType.Id)
                {
                    ReceiptStatu.ChangeStatus(receipt, ReceiptStatusType.ClosedReceiptStatusType, string.Empty);
                }
                else if (receipt.ReceiptBalance > 0 && receiptStatus.ReceiptStatusType.Id != ReceiptStatusType.AppliedReceiptStatusType.Id)
                {
                    ReceiptStatu.ChangeStatus(receipt, ReceiptStatusType.AppliedReceiptStatusType, string.Empty);
                }

                ControlNumberFacade.Create(FormType.PaymentFormType, ParentPayment);
                Context.SaveChanges();
            }
        }
Ejemplo n.º 2
0
        public static ReceiptPaymentAssoc CreateReceiptPaymentAssoc(Receipt receipt, Payment payment, decimal amount)
        {
            ReceiptPaymentAssoc receiptPaymentAssoc = new ReceiptPaymentAssoc();
            receiptPaymentAssoc.Payment = payment;
            receiptPaymentAssoc.Receipt = receipt;
            receiptPaymentAssoc.Amount = amount;

            return receiptPaymentAssoc;
        }
Ejemplo n.º 3
0
        public static ReceiptPaymentAssoc CreateReceiptPaymentAssoc(Receipt receipt, Payment payment)
        {
            ReceiptPaymentAssoc receiptPaymentAssoc = new ReceiptPaymentAssoc();
            receiptPaymentAssoc.Payment = payment;
            receiptPaymentAssoc.Receipt = receipt;
            receiptPaymentAssoc.Amount = receipt.ReceiptBalance.Value;

            return receiptPaymentAssoc;
        }
        public ReceiptPaymentAssoc CreateReceiptPaymentAssoc(Payment payment, Receipt receipt)
        {
            ReceiptPaymentAssoc newReceiptAssoc = new ReceiptPaymentAssoc();
            newReceiptAssoc.Payment = payment;
            newReceiptAssoc.Receipt = receipt;

            Context.ReceiptPaymentAssocs.AddObject(newReceiptAssoc);

            return newReceiptAssoc;
        }