예제 #1
0
 public static void CreatePaymentCurrencyAssoc(Payment payment, int CurrencyId)
 {
     if (CurrencyId != -1)
     {
         PaymentCurrencyAssoc assoc = new PaymentCurrencyAssoc();
         assoc.Payment = payment;
         assoc.CurrencyId = CurrencyId;
         ObjectContext.PaymentCurrencyAssocs.AddObject(assoc);
     }
 }
예제 #2
0
        public static FinAcctTran CreateFinAcctTran(int financialAccountId, Payment payment, DateTime transactionDate, DateTime entryDate, FinlAcctTransType finAcctTransactionType)
        {
            FinAcctTran newFinAcctTran = new FinAcctTran();
            newFinAcctTran.FinancialAccountId = financialAccountId;
            newFinAcctTran.PaymentId = payment.Id;
            newFinAcctTran.TransactionDate = transactionDate;
            newFinAcctTran.EntryDate = entryDate;
            newFinAcctTran.FinancialAcctTransTypeId = finAcctTransactionType.Id;
            newFinAcctTran.Amount = payment.TotalAmount;

            return newFinAcctTran;
        }
예제 #3
0
 public static FormDetail Create(int formTypeId, Payment payment, string RoleString, string Person, string Signature)
 {
     FormDetail form = new FormDetail();
     form.FormTypeId = formTypeId;
     form.Payment = payment;
     form.RoleString = RoleString;
     if (string.IsNullOrWhiteSpace(Person) == false)
         form.PersonString = Person;
     if (string.IsNullOrWhiteSpace(Signature) == false)
         form.Signature = Signature;
     return form;
 }
        private static List<PaymentModel> GetATMPayments(Payment loanPayment)
        {
            var atmReceiptPayments = from p in Context.Payments
                                     join rpa in Context.ReceiptPaymentAssocs on p.Id equals rpa.PaymentId
                                     where p.ParentPaymentId == loanPayment.Id
                                     && (p.PaymentMethodTypeId == PaymentMethodType.ATMType.Id)
                                     && p.PaymentTypeId == PaymentType.LoanPayment.Id
                                     select rpa;

            var customerAtmPayments = from crp in atmReceiptPayments
                                      join rpa in Context.ReceiptPaymentAssocs on crp.ReceiptId equals rpa.ReceiptId
                                      join p in Context.Payments on rpa.PaymentId equals p.Id
                                      where p.PaymentTypeId == PaymentType.Receipt.Id
                                      select new { ActualPayment = crp.Payment, ReceivePayment = p};

            var models = new List<PaymentModel>();
            foreach (var atmPayment in customerAtmPayments)
            {
                var amountTendered = atmReceiptPayments.FirstOrDefault(entity => entity.PaymentId == atmPayment.ActualPayment.Id);
                PaymentModel model = new PaymentModel();
                model.PaymentMethod = atmPayment.ActualPayment.PaymentMethodType.Name;
                model.BankName = "NA";
                model.BankBranch = "NA";
                model.CheckNumber = atmPayment.ReceivePayment.PaymentReferenceNumber;
                model.TransactionDate = atmPayment.ReceivePayment.TransactionDate;
                model.AmountTendered = amountTendered.Amount;
                model.AmountApplied = atmPayment.ActualPayment.TotalAmount;
                models.Add(model);
            }

            return models;
        }
        private static void FillListOfCashReceiptsUsed(Payment loanPayment, PrintLoanPayment loanPaymentModel)
        {
            var cashPayments = from p in Context.Payments
                               join rpa in Context.ReceiptPaymentAssocs on p.Id equals rpa.PaymentId
                               where p.ParentPaymentId == loanPayment.Id
                               && p.PaymentMethodTypeId == PaymentMethodType.CashType.Id
                               && p.PaymentTypeId == PaymentType.LoanPayment.Id
                               select rpa;

            var customerCashPayments = from crp in cashPayments
                                       join rpa in Context.ReceiptPaymentAssocs on crp.ReceiptId equals rpa.ReceiptId
                                       join p in Context.Payments on rpa.PaymentId equals p.Id
                                       where p.PaymentTypeId == PaymentType.Receipt.Id
                                       && p.TransactionDate < loanPayment.TransactionDate
                                       select new { ActualPayment = crp.Payment, ReceivePayment = p};

            var customerCashPaymentsToday = from crp in cashPayments
                                            join rpa in Context.ReceiptPaymentAssocs on crp.ReceiptId equals rpa.ReceiptId
                                            join p in Context.Payments on rpa.PaymentId equals p.Id
                                       where p.PaymentTypeId == PaymentType.Receipt.Id
                                       && p.TransactionDate == loanPayment.TransactionDate
                                            select new { ActualPayment = crp.Payment, ReceivePayment = p };

            var modelsFromPreviousReceipts = new List<PaymentModel>();
            foreach (var cashPayment in customerCashPayments)
            {
                var amountTendered = cashPayments.FirstOrDefault(entity => entity.PaymentId == cashPayment.ActualPayment.Id);

                PaymentModel paymentCash = new PaymentModel();
                paymentCash.PaymentMethod = "Cash Previous Receipt";
                paymentCash.BankName = "NA";
                paymentCash.BankBranch = "NA";
                paymentCash.CheckNumber = "NA";
                paymentCash.TransactionDate = cashPayment.ReceivePayment.TransactionDate;
                paymentCash.AmountTendered = amountTendered.Amount;
                paymentCash.AmountApplied = cashPayment.ActualPayment.TotalAmount;
                modelsFromPreviousReceipts.Add(paymentCash);
            }

            loanPaymentModel.CashReceiptsFromPreviousTransaction = modelsFromPreviousReceipts;

            var models = new List<PaymentModel>();
            foreach (var cashPayment in customerCashPaymentsToday)
            {
                var amountTendered = cashPayments.FirstOrDefault(entity => entity.PaymentId == cashPayment.ActualPayment.Id);
                PaymentModel paymentCash = new PaymentModel();
                paymentCash.PaymentMethod = "Cash";
                paymentCash.BankName = "NA";
                paymentCash.BankBranch = "NA";
                paymentCash.CheckNumber = "NA";
                paymentCash.TransactionDate = cashPayment.ReceivePayment.TransactionDate;
                paymentCash.AmountTendered = amountTendered.Amount;
                paymentCash.AmountApplied = cashPayment.ActualPayment.TotalAmount;
                models.Add(paymentCash);
            }

            loanPaymentModel.CashPayments = models;
        }
예제 #6
0
        private static decimal SaveLoanPayment(DateTime entryDate, decimal LoanPayment, LoanAccount loanAccount, Payment ParentPayment)
        {
            if (LoanPayment > 0)
            {
                decimal amountapplied = 0;
                if (loanAccount.LoanBalance <= LoanPayment)
                    amountapplied = loanAccount.LoanBalance;
                else amountapplied = LoanPayment;
                PaymentApplication loanpaymentApplication = new PaymentApplication();
                loanpaymentApplication.Payment = ParentPayment;
                loanpaymentApplication.FinancialAccountId = loanAccount.FinancialAccountId;
                loanpaymentApplication.AmountApplied = amountapplied;
                Context.PaymentApplications.AddObject(loanpaymentApplication);

                loanAccount.LoanBalance -= amountapplied;
                LoanPayment -= amountapplied;
                LoanAccount.UpdateLoanStatus(entryDate, loanAccount, loanAccount.LoanBalance);

            }
            return LoanPayment;
        }
예제 #7
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();
            }
        }
예제 #8
0
        public override bool initiatePaymentDirectDebit()
        {
            LogRequest("initiatePaymentDirectDebit", "start");

            DataClassesDataContext DB = (DataClassesDataContext) PaymentData["DB"] ?? new DataClassesDataContext();

            DirectDebit currentDirectDebit = DirectDebit.GetByID(DB, (int) PaymentData["DirectDebitID"]);
            //Invoice currentInvoice = currentDirectDebit.Invoice; // Invoice.GetByID(DB, (int)PaymentData["InvoiceID"]);
            Invoice currentInvoice = currentDirectDebit.Invoice ?? Invoice.GetByID(DB, (int) PaymentData["InvoiceID"]);
                // Invoice.GetByID(DB, (int)PaymentData["InvoiceID"]);
            CreditCard currentCreditCard = currentDirectDebit.CreditCard;
                // CreditCard.GetById(DB, currentDirectDebit.ddd_CreditCardID);

            if (!currentDirectDebit.ddd_IsActive ||
                (currentDirectDebit.ddd_IsNumberOfPayments &&
                 currentDirectDebit.ddd_PaymentsCommited >= currentDirectDebit.ddd_NumberOfPayments.Value) ||
                (currentInvoice.inv_StatusID != (int) InvoiceStatusEnum.Outstanding &&
                 currentInvoice.inv_StatusID != (int) InvoiceStatusEnum.PartPaid) ||
                currentInvoice.inv_IsRemovedByUser ||
                currentCreditCard.cca_IsDeleted ||
                !currentCreditCard.cca_IsActive
                )
            {
                return false;
            }
            decimal amountToPay = currentInvoice.inv_DueAmount - (currentInvoice.inv_PaidAmount ?? 0);
            if (currentDirectDebit.ddd_IsSingle &&
                Convert.ToDecimal(currentDirectDebit.ddd_ScheduledPaymentAmount.Value) < amountToPay)
            {
                amountToPay = Convert.ToDecimal(currentDirectDebit.ddd_ScheduledPaymentAmount.Value);
            }

            string email;
            if (currentCreditCard.cca_UserID == null)
            {
                //E SP case, so we take the email from the first payment
                email = currentCreditCard.Payments.Last().pay_Email;
            }
            else
            {
                //E take all notification emails for that user

                //:TODO Last() exception error
                //email = ConsumerEmail.ConsumerGetSendNotificationEmails(DB, currentCreditCard.cca_UserID.Value).Last().cem_Email;

                IList<string> emails = new List<string>();
                emails =
                    ConsumerEmail.ConsumerGetSendNotificationEmails(DB, currentCreditCard.cca_UserID.Value).Select(
                        ce => ce.cem_Email).ToList();
                email = emails[emails.Count - 1];
            }

            var currentPayment = new Payment
                                     {
                                         pay_IsPaidByService = true,
                                         pay_TypeID = (int) PaymentTypeEnum.CreditCard,
                                         pay_StatusID = (int) PaymentStatusEnum.Initiated,
                                         pay_InvoiceID = (int) PaymentData["InvoiceID"],
                                         pay_CreditCardID = currentDirectDebit.CreditCard.cca_ID,
                                         // (int) PaymentData["CreditCardID"],
                                         pay_UserID = currentDirectDebit.CreditCard.cca_UserID,
                                         // (int) PaymentData["UserID"],
                                         pay_DateModified = DateTime.Now,
                                         pay_DatePaid = DateTime.Now,
                                         pay_Amount = amountToPay,
                                         // (decimal) PaymentData["Amount"],
                                         pay_Email = email,
                                         //(string) PaymentData["Email"]?? "",
                                         pay_InternalRefID = (string) PaymentData["TransactionID"],
                                         pay_ExternalRefID = (string) PaymentData["TransactionID"]
                                     };

            currentPayment.Add(DB, "", "");

            PaymentData["PaymentID"] = currentPayment.pay_ID;
            PaymentData["PaycorpCID"] = currentPayment.Invoice.Merchant.mer_PaycorpCID;
            PaymentData["Amount"] = amountToPay;
            PaymentData["TransactionID"] = "DD_PID_" + PaymentData["PaymentID"].ToString().PadLeft(7, '0');
            PaymentData["TokenID"] = currentCreditCard.cca_IPCTokenID;
            PaymentData["ExpDate"] = currentCreditCard.cca_ExpirationDate;

            return true;
        }
예제 #9
0
 public static Cheque GetByPaymentId(Payment payment)
 {
     return Context.Cheques.SingleOrDefault(entity => entity.PaymentId == payment.Id);
 }
예제 #10
0
        public static List<Receipt> RetrieveAssociatedReceipts(Payment payment, PaymentType type)
        {
            var receipts = from rpa in Context.ReceiptPaymentAssocs
                           join p in Context.Payments on rpa.PaymentId equals p.Id
                           where p.PaymentTypeId == type.Id && rpa.PaymentId == payment.Id
                           select rpa.Receipt;

            return receipts.ToList();
        }
예제 #11
0
 private static decimal GetTotalInterestDue(Payment loanPayment)
 {
     var interestPayments = loanPayment.PaymentApplications.Where(x => x.ReceivableId.HasValue);
     return interestPayments.Sum(x => x.AmountApplied);
 }
예제 #12
0
        // With currency
        public static Payment SaveToDisburseCash(DateTime transactdate, DateTime entrydate, Payment parent, int processedTo, int processedby, decimal AmountTodisburse, SpecificPaymentType specifictype,DisbursementType distype, string DisbursedToName, int CurrencyId)
        {
            Payment cashpayment = SaveToDisburseCash(transactdate, entrydate, parent, processedTo, processedby, AmountTodisburse, specifictype, distype, DisbursedToName);

            Currency.CreatePaymentCurrencyAssoc(cashpayment, CurrencyId);
            return cashpayment;
        }
예제 #13
0
        public static void SaveToDisbursementCheques(DateTime transactdate, DateTime entrydate, Payment parent, List<AddChequesModel> Cheques, int processedTo, int processedby, SpecificPaymentType specifictype, DisbursementType distype, string DisbursedToName, int CurrencyId)
        {
            foreach (var cheque in Cheques)
            {
                PaymentMethodType type = PaymentMethodType.PayCheckType;
                if (cheque.CheckType == PaymentMethodType.PersonalCheckType.Name)
                    type = PaymentMethodType.PersonalCheckType;
                Payment chequepayment = new Payment();

                chequepayment.PaymentMethodType = type;
                chequepayment.Payment2 = parent;
                chequepayment.ProcessedToPartyRoleId = processedTo;
                chequepayment.ProcessedByPartyRoleId = processedby;
                chequepayment.PaymentReferenceNumber = cheque.CheckNumber;
                chequepayment.TransactionDate = transactdate;
                chequepayment.EntryDate = entrydate;
                chequepayment.TotalAmount = cheque.Amount;
                chequepayment.PaymentType = PaymentType.Disbursement;
                chequepayment.SpecificPaymentType = specifictype;
                ObjectContext.Payments.AddObject(chequepayment);

                Disbursement disbursement = new Disbursement();
                disbursement.Payment = chequepayment;
                disbursement.DisbursementType = distype;
                if (string.IsNullOrEmpty(DisbursedToName) == false)
                    disbursement.DisbursedToName = DisbursedToName;
                ObjectContext.Disbursements.AddObject(disbursement);

                Cheque newCheque = new Cheque();
                newCheque.BankPartyRoleId = cheque.BankPartyRoleId;
                newCheque.Payment = chequepayment;
                newCheque.CheckDate = cheque.CheckDate;
                ObjectContext.Cheques.AddObject(newCheque);

                ChequeStatu newChequeStatus = new ChequeStatu();
                newChequeStatus.Cheque = newCheque;
                newChequeStatus.CheckStatusTypeId = ChequeStatusType.ClearedType.Id;
                newChequeStatus.TransitionDateTime = entrydate;
                newChequeStatus.IsActive = true;
                ObjectContext.ChequeStatus.AddObject(newChequeStatus);

                Currency.CreatePaymentCurrencyAssoc(chequepayment, CurrencyId);

            }
        }
예제 #14
0
        // without currency and associated cheque
        public static Payment SaveToDisburseCash(DateTime transactdate, DateTime entrydate, Payment parent, int processedTo, int processedby, decimal AmountTodisburse, SpecificPaymentType specifictype, DisbursementType distype, string DisbursedToName)
        {
            Payment cashpayment = new Payment();
            cashpayment.PaymentMethodType = PaymentMethodType.CashType;
            cashpayment.Payment2 = parent;
            cashpayment.ProcessedToPartyRoleId = processedTo;
            cashpayment.ProcessedByPartyRoleId = processedby;

            cashpayment.TransactionDate = transactdate;
            cashpayment.EntryDate = entrydate;
            cashpayment.TotalAmount = AmountTodisburse;
            cashpayment.PaymentType = PaymentType.Disbursement;
            cashpayment.SpecificPaymentType = specifictype;
            ObjectContext.Payments.AddObject(cashpayment);

            Disbursement disbursement = new Disbursement();
            disbursement.Payment = cashpayment;
            disbursement.DisbursementType = distype;
            if (string.IsNullOrEmpty(DisbursedToName) == false)
                disbursement.DisbursedToName = DisbursedToName;
            ObjectContext.Disbursements.AddObject(disbursement);
            return cashpayment;
        }
예제 #15
0
 //with associated cheque but no currency
 public static void SaveToDisburseCash(DateTime transactdate, DateTime entrydate, Payment parent, string CheckNumber, int processedTo, int processedby, decimal AmountTodisburse, SpecificPaymentType specifictype, DisbursementType distype, string DisbursedToName)
 {
     Payment payment = SaveToDisburseCash(transactdate, entrydate, parent, processedTo, processedby, AmountTodisburse, specifictype, distype, DisbursedToName);
     if (string.IsNullOrEmpty(CheckNumber) == false)
         payment.PaymentReferenceNumber = CheckNumber;
 }
예제 #16
0
 private void FillCheque(Cheque check, Payment payment, string amountInWords)
 {
     lblDate.Text = String.Format("{0: MMMM d, yyyy}", check.CheckDate);
     lblName.Text = "***" + payment.PartyRole1.Party.Name.ToUpper() + "***";
     lblAmount.Text = "***" + payment.TotalAmount.ToString("N") + "***";
     lblAmountInWords.Text = "***" + amountInWords.ToUpper() + " " + "ONLY***";
     var bank = Context.Banks.SingleOrDefault(x => x.PartyRoleId == check.BankPartyRoleId);
     lblBankName.Text = bank.PartyRole.Party.Organization.OrganizationName.ToUpper() + " (" + payment.PaymentReferenceNumber + ")";
     lblCurrency.Text = "PESOS";
 }
예제 #17
0
        private static decimal GetCoBorrowerLoanBalance(PartyRole customer,Payment loanPayment)
        {
            decimal totalPayments = 0;
            decimal totalDisbursements = 0;
            var loanAccounts = from farc in Context.FinancialAccountRoles
                               join pr in Context.PartyRoles on farc.PartyRoleId equals pr.Id
                               join ls in Context.LoanAccountStatus on farc.FinancialAccountId equals ls.FinancialAccountId
                               join vcr in Context.LoanDisbursementVcrs on farc.FinancialAccount.AgreementId equals vcr.AgreementId
                               where pr.PartyId == customer.PartyId
                               && pr.EndDate == null
                               && (pr.RoleTypeId == RoleType.CoOwnerFinancialType.Id
                               || pr.RoleTypeId == RoleType.GuarantorFinancialType.Id)
                               && ls.IsActive == true && ls.StatusTypeId != LoanAccountStatusType.RestructuredType.Id
                                   && farc.FinancialAccount.LoanAccount.LoanReleaseDate < loanPayment.EntryDate
                               select new { loanAccount = farc.FinancialAccount.LoanAccount, voucher = vcr};
            var payments = from la in loanAccounts
                           join pa in Context.PaymentApplications on la.loanAccount.FinancialAccountId equals pa.FinancialAccountId
                           join p in Context.Payments on pa.PaymentId equals p.Id
                           where p.Id > loanPayment.Id
                           select pa;
            var disbursements = from la in loanAccounts
                                join pa in Context.PaymentApplications on la.voucher.Id equals pa.LoanDisbursementVoucherId
                                join p in Context.Payments on pa.PaymentId equals p.Id
                                where p.Id > loanPayment.Id
                                select pa;

            if (disbursements.Count() != 0)
                totalDisbursements = disbursements.Sum(e => e.AmountApplied);

            if (payments.Count() != 0)
                totalPayments = payments.Sum(e => e.AmountApplied);

            decimal balance = 0;
            if (loanAccounts.Count() > 0)
                balance = loanAccounts.Sum(entity => entity.loanAccount.LoanBalance);
            balance += totalPayments;
            balance -= totalDisbursements;
            return balance;
        }
예제 #18
0
 public static ControlNumber Create(FormType formType, Payment payment)
 {
     var controlNumber = _Create(formType);
     controlNumber.Payment = payment;
     return controlNumber;
 }
예제 #19
0
        private static List<PaymentModel> GetListOfCheques(Payment loanPayment)
        {
            var chequeReceiptPayments = from p in Context.Payments
                                 join rpa in Context.ReceiptPaymentAssocs on p.Id equals rpa.PaymentId
                                 where p.ParentPaymentId == loanPayment.Id
                                 && (p.PaymentMethodTypeId == PaymentMethodType.PayCheckType.Id
                                 || p.PaymentMethodTypeId == PaymentMethodType.PersonalCheckType.Id)
                                 && p.PaymentTypeId == PaymentType.LoanPayment.Id
                                 select rpa;

            var customerChequePayments = from crp in chequeReceiptPayments
                                         join rpa in Context.ReceiptPaymentAssocs on crp.ReceiptId equals rpa.ReceiptId
                                         join p in Context.Payments on rpa.PaymentId equals p.Id
                                         join c in Context.Cheques on p.Id equals c.PaymentId
                                         where p.PaymentTypeId == PaymentType.Receipt.Id
                                         select new {ActualPayment = crp.Payment, ReceivePayment = p, Cheque = c};

            var models = new List<PaymentModel>();
            foreach (var chequePayment in customerChequePayments)
            {
                var amountTendered = chequeReceiptPayments.FirstOrDefault(entity => entity.PaymentId == chequePayment.ActualPayment.Id);
                var bankPartyRole = PartyRole.GetById(chequePayment.Cheque.BankPartyRoleId);
                Bank bank = Bank.GetById(bankPartyRole.Id);
                PaymentModel model = new PaymentModel();
                model.PaymentMethod = "Cheque";
                model.BankName = bankPartyRole.Party.Name;
                model.BankBranch = bank.Branch;
                model.CheckNumber = chequePayment.ReceivePayment.PaymentReferenceNumber;
                model.TransactionDate = chequePayment.Cheque.CheckDate;
                model.AmountTendered = amountTendered.Amount;
                model.AmountApplied = chequePayment.ActualPayment.TotalAmount;
                models.Add(model);
            }

            return models;
        }
예제 #20
0
        public override bool initiatePaymentConsumer(CreditCard creditCard)
        {
            LogRequest("initiatePaymentConsumer", "start");

            Errors.Clear();

            var BCResponse = new BankcardTransactionResponse();

            if (string.IsNullOrEmpty((string) PaymentData["TokenID"]))
            {
                BCResponse = GetCreditCardTokenID(PaymentData["Number"].ToString(),
                                                  ((DateTime) PaymentData["ExpDate"]).ToString("MMyy"),
                                                  (int) ((PayCrediCard) PaymentData).Type);
                PaymentData["TokenID"] = BCResponse.PaymentAccountDataToken;

                if (string.IsNullOrEmpty((string) PaymentData["TokenID"]))
                {
                    Errors.Add(1, "Unable to generate a valid payment account data token");
                    return false;
                }
            }
            else
            {
                LogRequest("initiatePaymentConsumer", "Token=" + (string) PaymentData["TokenID"]);
            }

            var PayingInvoiceID = (int?) PaymentData["InvoiceID"];
            var userHostAddress = (string) PaymentData["UserHostAddress"];
            var sessionID = (string) PaymentData["SessionID"];
            var Amount = (decimal) PaymentData["Amount"];
            var AddressLine1 = (string) PaymentData["AddressLine1"];
            var AddressLine2 = (string) PaymentData["AddressLine2"];
            var PostCode = (string) PaymentData["PostalCode"];
            var Town = (string) PaymentData["Town"];
            var Country = (string) PaymentData["Country"];

            var DB = new DataClassesDataContext();
            /*var billingAddress = new Address();

            billingAddress.add_AddressLine1 = AddressLine1;
            billingAddress.add_AddressLine2 = AddressLine2;
            billingAddress.add_DateModified = DateTime.Now;
            billingAddress.add_IsDeleted = false;
            billingAddress.add_PostalCode = PostCode;
            billingAddress.add_Town = Town;
            billingAddress.add_Country = Country;
            billingAddress.Add(DB);*/

            creditCard.cca_IsDeleted = false;
            creditCard.cca_IsActive = true;
            creditCard.cca_Ref = (string) PaymentData["TransactionID"];
            creditCard.cca_IPCTokenID = (string) PaymentData["TokenID"];
            creditCard.cca_Is3DS = false;

            var payment = new Payment();
            payment.pay_IsPaidByService = false;
            payment.pay_TypeID = (int) PaymentTypeEnum.CreditCard;
            payment.pay_StatusID = (int) PaymentStatusEnum.Initiated;
            payment.pay_InvoiceID = PayingInvoiceID;
            payment.pay_UserID = null;
            payment.pay_DateModified = DateTime.Now;
            payment.pay_DatePaid = DateTime.Now;
            payment.pay_IP = userHostAddress;
            payment.pay_Amount = Amount;
            payment.pay_UserID = null;
            payment.pay_UsedPP = Convert.ToInt32(PaymentProcessorEnum.IPCommerce);
            payment.pay_InternalRefID = (string) PaymentData["TransactionID"];

            try
            {
                payment.Add(DB, userHostAddress, sessionID);
            }
            catch (Exception ex)
            {
                LogRequest("initiatePaymentConsumer", "Error Mesage : " + ex.Message);
                LogRequest("initiatePaymentConsumer", "Error Stacktrace : " + ex.StackTrace);
            }

            PaymentData["PaymentID"] = payment.pay_ID;
            PaymentData["TransactionID"] = "PID_" + PaymentData["PaymentID"].ToString().PadLeft(7, '0');

            return Errors.Count == 0;
        }
예제 #21
0
 private static decimal GetTotalPrincipalDue(Payment loanPayment)
 {
     var principalPayments = loanPayment.PaymentApplications.Where(x => x.FinancialAccountId.HasValue);
     return principalPayments.Sum(x => x.AmountApplied);
 }
예제 #22
0
        public static LoanPayment CreateLoanPayment(Payment payment, PartyRole customerPartyRole)
        {
            decimal OwnerLoanBalance = 0;
            decimal OwnerInterest = 0;
            decimal CoOwnerBalance = 0;
            decimal CoOwnerInterest = 0;

            var ownerLoans = from farc in Context.FinancialAccountRoles
                               join pr in Context.PartyRoles on farc.PartyRoleId equals pr.Id
                               join ls in Context.LoanAccountStatus on farc.FinancialAccountId equals ls.FinancialAccountId
                               where pr.PartyId == customerPartyRole.PartyId
                               && pr.EndDate == null
                               && (pr.RoleTypeId == RoleType.OwnerFinancialType.Id)
                               && ls.IsActive == true && (ls.StatusTypeId != LoanAccountStatusType.RestructuredType.Id
                               && ls.StatusTypeId != LoanAccountStatusType.PaidOffType.Id)
                               select ls.LoanAccount;
            if (ownerLoans.Count() != 0)
                OwnerLoanBalance = ownerLoans.Sum(entity => entity.LoanBalance);

            var coOwnerLoans = from farc in Context.FinancialAccountRoles
                               join pr in Context.PartyRoles on farc.PartyRoleId equals pr.Id
                               join ls in Context.LoanAccountStatus on farc.FinancialAccountId equals ls.FinancialAccountId
                               where pr.PartyId == customerPartyRole.PartyId
                               && pr.EndDate == null
                               && (pr.RoleTypeId == RoleType.CoOwnerFinancialType.Id
                               || pr.RoleTypeId == RoleType.GuarantorFinancialType.Id)
                               && ls.IsActive == true && (ls.StatusTypeId != LoanAccountStatusType.RestructuredType.Id
                               && ls.StatusTypeId != LoanAccountStatusType.PaidOffType.Id)
                               select ls.LoanAccount;

            if (coOwnerLoans.Count() != 0)
                CoOwnerBalance = coOwnerLoans.Sum(entity => entity.LoanBalance);

            var ownerReceivables = from l in ownerLoans
                              join r in Context.Receivables on l.FinancialAccountId equals r.FinancialAccountId
                              join rs in Context.ReceivableStatus on r.Id equals rs.ReceivableId
                              where rs.IsActive == true && r.Balance > 0 && (rs.StatusTypeId == ReceivableStatusType.OpenType.Id
                              || rs.StatusTypeId == ReceivableStatusType.PartiallyPaidType.Id)
                              select r;

            if (ownerReceivables.Count() != 0)
                OwnerInterest = ownerReceivables.Sum(entity => entity.Balance);

            var coOwnerReceivables = from l in coOwnerLoans
                                   join r in Context.Receivables on l.FinancialAccountId equals r.FinancialAccountId
                                   join rs in Context.ReceivableStatus on r.Id equals rs.ReceivableId
                                   where rs.IsActive == true && r.Balance > 0 && (rs.StatusTypeId == ReceivableStatusType.OpenType.Id
                                   || rs.StatusTypeId == ReceivableStatusType.PartiallyPaidType.Id)
                                   select r;

            if (coOwnerReceivables.Count() != 0)
                CoOwnerInterest = coOwnerReceivables.Sum(entity => entity.Balance);

            LoanPayment loanpayment = new LoanPayment();
            loanpayment.Payment = payment;
            loanpayment.OwnerOutstandingLoan = OwnerLoanBalance;
            loanpayment.OwnerOutstandingInterest = OwnerInterest;
            loanpayment.CoOwnerOutstandingLoan = CoOwnerBalance;
            loanpayment.CoOwnerOutstandingInterest = CoOwnerInterest;
            return loanpayment;
        }
예제 #23
0
 public static Cheque CreateCheque(Payment payment, int bankPartyRoleId, DateTime checkDate)
 {
     Cheque newCheck = new Cheque();
     newCheck.BankPartyRoleId = bankPartyRoleId;
     newCheck.CheckDate = checkDate;
     newCheck.PaymentId = payment.Id;
     return newCheck;
 }
예제 #24
0
        public static Payment CreatePayment(DateTime entryDate,
                                     DateTime transactionDate,
                                     int processedToPartyRoleId, 
                                     int processedByPartyRoleId,
                                     decimal totalAmount,
                                     PaymentType paymentType,
                                     PaymentMethodType paymentMethodType,
                                     SpecificPaymentType specificPaymentType,
                                     string paymentReferenceNumber)
        {
            Payment newPayment = new Payment();
            newPayment.EntryDate = entryDate;
            newPayment.TransactionDate = transactionDate;
            newPayment.ProcessedToPartyRoleId = processedToPartyRoleId;
            newPayment.ProcessedByPartyRoleId = processedByPartyRoleId;//partytroleID of teller
            newPayment.TotalAmount = totalAmount;
            newPayment.PaymentTypeId = paymentType.Id;
            newPayment.PaymentMethodTypeId = paymentMethodType.Id;
            newPayment.SpecificPaymentTypeId = specificPaymentType.Id;
            newPayment.PaymentReferenceNumber = paymentReferenceNumber;

            return newPayment;
        }
예제 #25
0
        private static void SaveInterestPayment(DateTime entryDate, decimal InterestPayment, LoanAccount loanAccount, Payment ParentPayment)
        {
            if (InterestPayment > 0)
            {
                var receivables = from r in Context.Receivables
                                  join rs in Context.ReceivableStatus on r.Id equals rs.ReceivableId
                                  where r.FinancialAccountId == loanAccount.FinancialAccountId
                                  && rs.IsActive == true && (rs.ReceivableStatusType.Id == ReceivableStatusType.OpenType.Id
                                  || rs.ReceivableStatusType.Id == ReceivableStatusType.PartiallyPaidType.Id)
                                  orderby r.ValidityPeriod
                                  select r;
                foreach (var receivable in receivables)
                {
                    if (InterestPayment > 0)
                    {
                        decimal amountapplied = 0;
                        if (receivable.Balance <= InterestPayment)
                            amountapplied = (decimal)receivable.Balance;
                        else if (receivable.Balance > InterestPayment)
                            amountapplied = InterestPayment;

                        PaymentApplication paymentApplication = new PaymentApplication();
                        paymentApplication.Payment = ParentPayment;
                        paymentApplication.ReceivableId = receivable.Id;
                        paymentApplication.AmountApplied = amountapplied;
                        Context.PaymentApplications.AddObject(paymentApplication);
                        receivable.Balance -= amountapplied;

                        Receivable.InsertReceivableStatus(receivable.Id, receivable.Balance, entryDate);

                        InterestPayment -= amountapplied;

                    }
                    //Context.SaveChanges();

                }
            }
        }
예제 #26
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;
        }
예제 #27
0
 public ChequesTransactionModel(Payment payment)
 {
     this.ProcessedTo = Person.GetPersonFullName((int)payment.ProcessedToPartyRoleId);
     this.ProcessedBy = Person.GetPersonFullName(payment.ProcessedByPartyRoleId);
     this.CheckNumber = payment.PaymentReferenceNumber;
     this.Amount = payment.TotalAmount;
     this.CurrencySymbol = Currency.CurrencySymbolByPaymentId(payment.Id);
     this.TransactionDate = payment.TransactionDate.ToString("MMM dd,yyyy");
 }
예제 #28
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 ChequesReceivedModel(Payment payment)
            {
                var partyRole = ObjectContext.PartyRoles.SingleOrDefault(entity => entity.Id == payment.ProcessedToPartyRoleId && entity.EndDate == null);
                this.ReceivedFrom = Person.GetPersonFullName(partyRole.Party);

                this.CheckNumber = payment.PaymentReferenceNumber;
                this.Amount = payment.TotalAmount;
                this.TransactionDate = payment.TransactionDate.ToString("MMM dd, yyyy");
            }
예제 #30
0
        public static PrintLoanPayment Create(Payment loanPayment)
        {
            if (loanPayment.LoanPayment == null)
                throw new ArgumentException("Please supply the parent of the payments.");

            var customer = PartyRole.GetById(loanPayment.ProcessedToPartyRoleId.Value);
            var teller = PartyRole.GetById(loanPayment.ProcessedByPartyRoleId);
            var district = Context.CustomerClassifications.SingleOrDefault(entity => entity.PartyRoleId == customer.Id);
            decimal ownerOutstandingLoan = loanPayment.LoanPayment.OwnerOutstandingLoan + loanPayment.LoanPayment.OwnerOutstandingInterest;
            decimal coOwnerOutsandingLoan = loanPayment.LoanPayment.CoOwnerOutstandingInterest + loanPayment.LoanPayment.CoOwnerOutstandingLoan;
            PrintLoanPayment model = new PrintLoanPayment();
            model.ReceiveFrom = customer.Party.Name;
            model.Teller = teller.Party.Name;
            model.StationNumber = district != null ? district.ClassificationType.StationNumber : "";
            model.TransactionDate = loanPayment.TransactionDate;
            model.Total = loanPayment.TotalAmount;
            model.TotalPrincipalDue = GetTotalPrincipalDue(loanPayment);
            model.TotalInterestDue = GetTotalInterestDue(loanPayment);
            model.Total = model.TotalPrincipalDue + model.TotalInterestDue;
            model.CustomerLoanBalance = ownerOutstandingLoan;
            model.CustomerAsCoOwnerLoanBalance = coOwnerOutsandingLoan;
            model.TotalLoanBalance = model.CustomerLoanBalance + model.CustomerAsCoOwnerLoanBalance;

            model.Cheques = GetListOfCheques(loanPayment);
            model.ATMPayments = GetATMPayments(loanPayment);
            FillListOfCashReceiptsUsed(loanPayment, model);
            model.CalculateAmountTendered();

            model.Change = model.AmountTendered - model.Total;
            var controlNumber = ControlNumberFacade.GetByPaymentId(loanPayment.Id, FormType.PaymentFormType);
            model.ControlNumber = controlNumber.LastControlNumber;
            return model;
        }