public async Task <ActionResult> VaultIn([Bind("TransactionType,AccountCode,Amount")] TellerPostingViewModel viewModel)
        {
            try
            {
                await _postingService.CreateTellerPosting(User.FindFirstValue(ClaimTypes.NameIdentifier), viewModel);

                return(RedirectToAction(nameof(Index)));
            }
            catch (NullReferenceException)
            {
                ViewBag.Message = new StatusMessage
                {
                    Type    = StatusType.Error,
                    Message = "Vault In not successful. No account found with this Account Code"
                };
                return(View(viewModel));
            }
            catch (Exception e)
            {
                ViewBag.Message = new StatusMessage
                {
                    Type    = StatusType.Error,
                    Message = e.Message
                };
                return(View(viewModel));
            }
        }
        public async Task <ActionResult> Create([Bind("TransactionSlipNo,TransactionDate,TransactionType,Amount,AccountNumber,Notes")] TellerPostingViewModel viewModel)
        {
            try
            {
                await _postingService.CreateTellerPosting(User.FindFirstValue(ClaimTypes.NameIdentifier), viewModel);

                return(RedirectToAction(nameof(Index)));
            }
            catch (NullReferenceException)
            {
                ViewBag.Message = new StatusMessage
                {
                    Type    = StatusType.Error,
                    Message = "Customer Account not found."
                };
                return(View(viewModel));
            }
            catch (Exception e)
            {
                ViewBag.Message = new StatusMessage
                {
                    Type    = StatusType.Error,
                    Message = e.Message
                };
                return(View(viewModel));
            }
        }
Пример #3
0
        public ActionResult Postings()
        {
            var customerAccounts = _context.CustomerAccounts.Include(c => c.Customer).Include(c => c.Branch).Include(c => c.AccountType).ToList();
            var count            = _context.TellerPostings.Count();
            var postingType1     = new PostingTypes();

            postingType1.Id   = 1;
            postingType1.Name = "Deposit";
            var postingType2 = new PostingTypes();

            postingType2.Id   = 2;
            postingType2.Name = "Withdrawal";

            var postingTypes = new List <string>
            {
                "Deposit",
                "Withdrawal"
            };

            var viewModel = new TellerPostingViewModel()
            {
                CustomerAccounts = customerAccounts,
                PostingType      = postingTypes.ToList(),
                TellerPosting    = new TellerPosting(),
                count            = count
            };

            return(View("TellerPosting", viewModel));
        }
Пример #4
0
        public async Task <TellerPostingViewModel> GetCreateTellerPosting()
        {
            var accountNumbers = await _context.CustomerAccounts.Where(a => a.IsActivated == true).Select(a => a.AccountNumber).ToListAsync();

            var accountCodes = await _context.InternalAccounts.Where(a => a.IsActivated == true).Select(a => a.AccountCode).ToListAsync();

            var viewModel = new TellerPostingViewModel()
            {
                AccountNumbers = accountNumbers,
                AccountCodes   = accountCodes
            };

            return(viewModel);
        }
Пример #5
0
        public ActionResult Create(TellerPostingViewModel model)
        {
            if (config.IsBusinessOpen == false)
            {
                return(View("BusinessClosed"));
            }

            if (ModelState.IsValid)
            {
                TellerPosting tellerPost = new TellerPosting();
                tellerPost.CreditAmount    = model.CreditAmount;
                tellerPost.DebitAmount     = model.DebitAmount;
                tellerPost.CustomerAccount = context.CustomerAccounts.Find(model.CustomerAccountID);
                tellerPost.Narration       = model.Narration;
                tellerPost.TransactionDate = DateTime.Now;
                tellerPost.PostingType     = (PostingType)model.PostingType;

                string          currentUserId = User.Identity.GetUserId();
                ApplicationUser currentUser   = context.Users.FirstOrDefault(x => x.Id == currentUserId);
                tellerPost.TillAccount = currentUser.GLAccount;

                string result = TellerPostingLogic.PostTeller(tellerPost.CustomerAccount, tellerPost.TillAccount, tellerPost.CreditAmount, tellerPost.PostingType, config);

                if (result == "success")
                {
                    context.TellerPostings.Add(tellerPost);
                    context.SaveChanges();
                    return(RedirectToAction("Index"));
                }

                ViewBag.Message = result;
                return(View(model));
            }

            return(View(model));
        }
Пример #6
0
        public async Task CreateTellerPosting(string userId, TellerPostingViewModel viewModel)
        {
            float creditBalance = 0;
            float debitBalance  = 0;

            CBAUser user = await _context.Users.Include(u => u.Till).FirstOrDefaultAsync(u => u.Id == userId);

            InternalAccount tellerAccount = user.Till;

            if ((viewModel.TransactionSlipNo == null) || (await _context.Postings.AnyAsync(p => p.TransactionSlipNo == viewModel.TransactionSlipNo)))
            {
                throw new Exception("Duplicate Transaction. A transaction with this Slip Number has already been posted.");
            }

            InternalAccount vault = await _context.InternalAccounts.SingleOrDefaultAsync(i => i.AccountCode == "10000000000000");

            AccountConfiguration settings = _context.AccountConfigurations.First();
            CustomerAccount      customerAccount;

            var creditPosting = new Posting
            {
                TransactionDate   = viewModel.TransactionDate,
                TransactionSlipNo = viewModel.TransactionSlipNo,
                Credit            = viewModel.Amount,
                Notes             = viewModel.Notes,
                Balance           = creditBalance,
                PostingDate       = DateTime.Now,
                CBAUserId         = userId,
            };

            var debitPosting = new Posting
            {
                TransactionDate   = viewModel.TransactionDate,
                TransactionSlipNo = viewModel.TransactionSlipNo,
                Debit             = viewModel.Amount,
                Notes             = viewModel.Notes,
                Balance           = debitBalance,
                PostingDate       = DateTime.Now,
                CBAUserId         = userId,
            };

            switch (viewModel.TransactionType)
            {
            case TransactionType.Withdrawal:
                if (tellerAccount == null)
                {
                    throw new Exception("You cannot post  a customer transaction. There is no Till associated with this account.");
                }
                customerAccount = await _context.CustomerAccounts
                                  .Where(i => i.AccountNumber == viewModel.AccountNumber)
                                  .FirstOrDefaultAsync();

                if (!customerAccount.IsActivated)
                {
                    throw new Exception("Unable to post transaction. Customer Account is deactivated.");
                }
                if (tellerAccount.AccountBalance < viewModel.Amount)
                {
                    throw new Exception("Unable to post transaction. Insufficient funds in Till.");
                }
                switch (customerAccount.AccountClass)
                {
                case AccountClass.Savings:
                    if (customerAccount.AccountBalance <= settings.SavingsMinBalance)
                    {
                        throw new Exception("Account has reached Minimum Balance limit. Cannot post withdrawal.");
                    }
                    break;

                case AccountClass.Current:
                    if (customerAccount.AccountBalance <= settings.CurrentMinBalance)
                    {
                        throw new Exception("Account has reached Minimum Balance limit. Cannot post withdrawal.");
                    }
                    break;

                case AccountClass.Loan:
                    break;

                default:
                    break;
                }
                creditBalance = tellerAccount.AccountBalance - viewModel.Amount;
                debitBalance  = customerAccount.AccountBalance - viewModel.Amount;

                creditPosting.AccountCode  = tellerAccount.AccountCode;
                debitPosting.AccountNumber = customerAccount.AccountNumber;

                creditPosting.GLAccount = tellerAccount;
                debitPosting.GLAccount  = customerAccount;

                tellerAccount.AccountBalance   = creditBalance;
                customerAccount.AccountBalance = debitBalance;
                _context.Update(customerAccount);
                break;

            case TransactionType.Deposit:
                if (tellerAccount == null)
                {
                    throw new Exception("You cannot post  a customer transaction. There is no Till associated with this account.");
                }
                customerAccount = await _context.CustomerAccounts
                                  .Where(i => i.AccountNumber == viewModel.AccountNumber)
                                  .FirstOrDefaultAsync();

                if (!customerAccount.IsActivated)
                {
                    throw new Exception("Unable to post transaction. Customer Account is deactivated.");
                }
                creditBalance = customerAccount.AccountBalance + viewModel.Amount;
                debitBalance  = tellerAccount.AccountBalance + viewModel.Amount;

                creditPosting.AccountNumber = customerAccount.AccountNumber;
                debitPosting.AccountCode    = tellerAccount.AccountCode;

                creditPosting.GLAccount = customerAccount;
                debitPosting.GLAccount  = tellerAccount;

                tellerAccount.AccountBalance   = debitBalance;
                customerAccount.AccountBalance = creditBalance;
                _context.Update(customerAccount);
                break;

            case TransactionType.VaultIn:
                tellerAccount = await _context.InternalAccounts.FirstOrDefaultAsync(a => a.AccountCode == viewModel.AccountCode);

                if (tellerAccount.AccountBalance < viewModel.Amount)
                {
                    throw new Exception("Unable to post transaction. Insufficient funds in Till.");
                }
                creditBalance = tellerAccount.AccountBalance - viewModel.Amount;
                debitBalance  = vault.AccountBalance + viewModel.Amount;

                creditPosting.AccountCode = tellerAccount.AccountCode;
                debitPosting.AccountCode  = vault.AccountCode;

                creditPosting.GLAccount = tellerAccount;
                debitPosting.GLAccount  = vault;

                creditPosting.TransactionDate = debitPosting.TransactionDate = DateTime.Now;
                creditPosting.Notes           = debitPosting.Notes = "VaultIn";

                tellerAccount.AccountBalance = creditBalance;
                vault.AccountBalance         = debitBalance;
                _context.Update(vault);
                break;

            case TransactionType.VaultOut:
                tellerAccount = await _context.InternalAccounts.FirstOrDefaultAsync(a => a.AccountCode == viewModel.AccountCode);

                if (vault.AccountBalance < viewModel.Amount)
                {
                    throw new Exception("Unable to post transaction. Insufficient funds in Vault.");
                }
                creditBalance = vault.AccountBalance - viewModel.Amount;
                debitBalance  = tellerAccount.AccountBalance + viewModel.Amount;

                creditPosting.AccountCode = vault.AccountCode;
                debitPosting.AccountCode  = tellerAccount.AccountCode;

                creditPosting.GLAccount = vault;
                debitPosting.GLAccount  = tellerAccount;

                creditPosting.TransactionDate = debitPosting.TransactionDate = DateTime.Now;
                creditPosting.Notes           = debitPosting.Notes = "VaultIn";

                tellerAccount.AccountBalance = debitBalance;
                vault.AccountBalance         = creditBalance;
                _context.Update(vault);
                break;

            default:
                break;
            }

            _context.Update(tellerAccount);
            await _context.SaveChangesAsync();

            creditPosting.TransactionDate = DateTime.Now;
            debitPosting.TransactionDate  = DateTime.Now;

            creditPosting.Balance = creditBalance;
            debitPosting.Balance  = debitBalance;

            _context.Add(creditPosting);
            _context.Add(debitPosting);
            await _context.SaveChangesAsync();
        }