Пример #1
0
        public ActionResult _MakePayment(int id)
        {
            var vm = new MakePaymentVM();

            var cust = _customerService.GetCustomer(id);

            if (!DoesCustomerHaveAccounts(id))
            {
                vm.IsError      = true;
                vm.ErrorMessage = "Payments can only be collected on Customers with existing Accounts";
            }
            else
            {
                var rolledTransactions =
                    _paymentService.GetRolledTransactions(id).Where(s => s.Amount != 0).OrderBy(s => s.BillCycle.Date);
                vm = new MakePaymentVM
                {
                    CustomerId = id,
                    PreferredPaymentSourceId = cust.PreferredPaymentSourceId,
                    Balance            = _transactionsService.GetBalanceForCustomer(id),
                    RolledTransactions =
                        AutoMapperSetup.MapList <PaymentService.RolledTransaction, RolledTransactionVM>(
                            rolledTransactions).ToList(),
                    CreditedAccountId = cust.CustomerAccounts.Min(c => c.CustomerAccountId),
                    CustomerAccounts  = cust.CustomerAccounts
                };
            }
            return(PartialView(vm));
        }
Пример #2
0
        public ActionResult _MakePayment(MakePaymentVM mVm)
        {
            if (TryValidateModel(mVm))
            {
                var pymnt = new Payment
                {
                    CustomerId      = mVm.CustomerId,
                    PaymentDate     = DateTime.Today,
                    PaymentSourceId = mVm.PreferredPaymentSourceId,
                    Amount          = mVm.TenderedAmount,
                    Reference       = mVm.Reference,
                    PaymentItems    = new List <PaymentItem>()
                };

                if (mVm.RolledTransactions != null)
                {
                    foreach (var rolldTransVm in mVm.RolledTransactions.Where(p => p.Payment != 0))
                    {
                        var pmtItm = new PaymentItem
                        {
                            Amount            = rolldTransVm.Payment,
                            BillCycle         = new BillCycle(rolldTransVm.BillCycleNo),
                            PaymentItemTypeId = (int)PaymentItemTypes.InvoiceSettlement,
                            CustomerAccountId = rolldTransVm.CustomerAccountId
                        };
                        pymnt.PaymentItems.Add(pmtItm);
                    }
                }

                if (mVm.CreditedAmount != 0)
                {
                    var crdPmt = new PaymentItem
                    {
                        CustomerAccountId = mVm.CreditedAccountId,
                        BillCycle         = new BillCycle(DateTime.Today).AddCycles(1),
                        PaymentItemTypeId = (int)PaymentItemTypes.Credit,
                        Amount            = mVm.CreditedAmount
                    };
                    pymnt.PaymentItems.Add(crdPmt);
                }

                if (ExecuteRepositoryAction(() =>
                {
                    _paymentService.AddPayment(pymnt);
                    _paymentService.CommitChanges();
                }))
                {
                    return(ReturnJsonFormSuccess());
                }
            }
            mVm.CustomerAccounts = _customerService.GetCustomer(mVm.CustomerId).CustomerAccounts;
            return(PartialView(mVm));
        }