コード例 #1
0
 static void DebitCustomer(CustomerAccount act, decimal amt)
 {
     blogic.DebitCustomerAccount(act, amt);
     actRepo.Update(act);
     frLogic.CreateTransaction(act, amt, TransactionType.Debit);    //records every Dr and Cr entries to ensure a balance FR
     UtilityLogic.LogMessage("Customer account: " + act.AccountNumber + " debitted NGN" + amt);
 }
コード例 #2
0
        public ActionResult CreateLoan([Bind(Include = "AccountName,LoanAmount,TermsOfLoan,NumberOfYears,InterestRate,BranchID,CustomerID,ServicingAccountNumber")] CreateLoanAccountViewModel model)
        {
            ViewBag.BranchID = new SelectList(db.Branches, "ID", "Name", model.BranchID);

            if (ModelState.IsValid)
            {
                try
                {
                    // general settings
                    CustomerAccount customerAccount = new CustomerAccount();
                    customerAccount.AccountName    = model.AccountName;
                    customerAccount.AccountType    = AccountType.Loan;
                    customerAccount.CustomerID     = model.CustomerID;
                    customerAccount.AccountNumber  = custActLogic.GenerateCustomerAccountNumber(AccountType.Loan, model.CustomerID);
                    customerAccount.DateCreated    = DateTime.Now;
                    customerAccount.BranchID       = model.BranchID;
                    customerAccount.AccountStatus  = AccountStatus.Closed;
                    customerAccount.AccountBalance = 0;

                    // loan specific settings
                    customerAccount.LoanAmount  = model.LoanAmount;
                    customerAccount.TermsOfLoan = model.TermsOfLoan;

                    long actNo = Convert.ToInt64(model.ServicingAccountNumber);

                    var servAct = db.CustomerAccounts.Where(a => a.AccountNumber == actNo).SingleOrDefault();
                    if (servAct == null)
                    {
                        AddError("Servicing account number does not exist");
                        return(View(model));
                    }
                    // check if servicing account number actually belongs to customer and is either savings or current.
                    if (servAct.AccountType == AccountType.Loan || servAct.CustomerID != model.CustomerID)
                    {
                        AddError("Invalid servicing account");
                        return(View(model));
                    }

                    if (servAct.AccountStatus == AccountStatus.Closed)
                    {
                        AddError("Servicing account is closed");
                        return(View(model));
                    }

                    // get the id
                    customerAccount.ServicingAccountID = servAct.ID;

                    customerAccount.LoanInterestRatePerMonth = Convert.ToDecimal(model.InterestRate);
                    switch (model.TermsOfLoan)
                    {
                    case TermsOfLoan.Fixed:
                        custActLogic.ComputeFixedRepayment(customerAccount, model.NumberOfYears, model.InterestRate);
                        break;

                    case TermsOfLoan.Reducing:
                        custActLogic.ComputeReducingRepayment(customerAccount, model.NumberOfYears, model.InterestRate);
                        break;

                    default:
                        break;
                    }

                    // loan disbursement
                    busLogic.DebitCustomerAccount(customerAccount, customerAccount.LoanAmount);
                    busLogic.CreditCustomerAccount(servAct, customerAccount.LoanAmount);

                    db.Entry(servAct).State = EntityState.Modified;
                    db.CustomerAccounts.Add(customerAccount);
                    db.SaveChanges();

                    // financial report logging
                    reportLogic.CreateTransaction(customerAccount, customerAccount.LoanAmount, TransactionType.Debit);
                    reportLogic.CreateTransaction(servAct, customerAccount.LoanAmount, TransactionType.Credit);

                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    AddError(ex.ToString());
                    return(View(model));
                }
            }
            AddError("Please enter valid data");
            return(View(model));
        }
コード例 #3
0
        public ActionResult ApproveTellerPost(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TellerPosting tellerPosting = db.TellerPostings.Find(id);

            if (tellerPosting == null)
            {
                return(HttpNotFound());
            }

            var amt = tellerPosting.Amount;

            var tillAct = tellerPosting.TillAccount;
            var custAct = tellerPosting.CustomerAccount;

            if (tellerPosting.PostingType == TellerPostingType.Withdrawal)
            {
                if (custActLogic.CustomerAccountHasSufficientBalance(custAct, amt))
                {
                    if (!(tillAct.AccountBalance >= amt))
                    {
                        // i have no choice but to send the error messages with partial views.
                        return(RedirectToAction("TellerPosts", new { message = "Insuficient funds in till account" }));
                    }

                    //all this is happening after transaction is approved by checker.
                    string result = telPostLogic.PostTeller(custAct, tillAct, amt, TellerPostingType.Withdrawal);
                    if (!result.Equals("success"))
                    {
                        return(RedirectToAction("TellerPosts", new { message = result }));
                    }

                    tellerPosting.Status          = PostStatus.Approved;
                    db.Entry(tellerPosting).State = EntityState.Modified;
                    db.Entry(custAct).State       = EntityState.Modified;
                    db.Entry(tillAct).State       = EntityState.Modified;

                    db.SaveChanges();

                    reportLogic.CreateTransaction(tillAct, amt, TransactionType.Credit);
                    reportLogic.CreateTransaction(custAct, amt, TransactionType.Debit);

                    return(RedirectToAction("TellerPosts", new { message = "Transaction Approved!" }));
                }
                else
                {
                    return(RedirectToAction("TellerPosts", new { message = "Insufficient funds in customer account" }));
                }
            }
            else
            {
                string result = telPostLogic.PostTeller(custAct, tillAct, amt, TellerPostingType.Deposit);
                if (!result.Equals("success"))
                {
                    return(RedirectToAction("TellerPosts", new { message = result }));
                }

                tellerPosting.Status          = PostStatus.Approved;
                db.Entry(tellerPosting).State = EntityState.Modified;
                db.Entry(custAct).State       = EntityState.Modified;
                db.Entry(tillAct).State       = EntityState.Modified;

                db.SaveChanges();

                reportLogic.CreateTransaction(tillAct, amt, TransactionType.Debit);
                reportLogic.CreateTransaction(custAct, amt, TransactionType.Credit);

                return(RedirectToAction("TellerPosts", new { message = "Transaction Approved!" }));
            }
        }
コード例 #4
0
        public ActionResult Create([Bind(Include = "ID,Amount,Narration,PostingType,CustomerAccountID")] TellerPosting tellerPosting)
        {
            /*if (eodLogic.isBusinessClosed())
             * {
             *  AddError("Sorry, business is closed");
             *  return View(tellerPosting); // closed partial view ?
             * }*/

            if (ModelState.IsValid)
            {
                try
                {
                    string tellerId = GetLoggedInUserId();
                    // if user doesn't have till, error.. implement user till checking earlier ?
                    bool tellerHasTill = db.TillUsers.Any(tu => tu.UserId.Equals(tellerId));
                    if (!tellerHasTill)
                    {
                        AddError("No till associated with logged in teller");
                        return(View(tellerPosting));
                    }
                    // get user's till and do all the necessary jargons
                    int tillId = db.TillUsers.Where(tu => tu.UserId.Equals(tellerId)).First().GlAccountID;
                    tellerPosting.TillAccountID = tillId;
                    var tillAct = db.GlAccounts.Find(tillId);

                    var custAct = db.CustomerAccounts.Find(tellerPosting.CustomerAccountID);

                    tellerPosting.PostInitiatorId = tellerId;
                    tellerPosting.Date            = DateTime.Now;

                    var amt = tellerPosting.Amount;

                    if (tellerPosting.PostingType == TellerPostingType.Withdrawal)
                    {
                        if (custActLogic.CustomerAccountHasSufficientBalance(custAct, amt))
                        {
                            if (!(tillAct.AccountBalance >= amt))
                            {
                                AddError("Insuficient funds in till account");
                                return(View(tellerPosting));
                            }

                            tellerPosting.Status = PostStatus.Approved;
                            //db.TellerPostings.Add(tellerPosting);
                            //db.SaveChanges();

                            //all this is happening after transaction is approved by checker.
                            string result = telPostLogic.PostTeller(custAct, tillAct, amt, TellerPostingType.Withdrawal);
                            if (!result.Equals("success"))
                            {
                                AddError(result);
                                return(View(tellerPosting));
                            }

                            db.Entry(custAct).State = EntityState.Modified;
                            db.Entry(tillAct).State = EntityState.Modified;
                            db.TellerPostings.Add(tellerPosting);
                            db.SaveChanges();

                            reportLogic.CreateTransaction(tillAct, amt, TransactionType.Credit);
                            reportLogic.CreateTransaction(custAct, amt, TransactionType.Debit);

                            return(RedirectToAction("UserPosts")); // suceess partial view or pop-up ?
                        }
                        else
                        {
                            AddError("Insufficient funds in customer account");
                            return(View(tellerPosting));
                        }
                    }
                    else
                    {
                        tellerPosting.Status = PostStatus.Approved;
                        //db.TellerPostings.Add(tellerPosting);
                        //db.SaveChanges();

                        string result = telPostLogic.PostTeller(custAct, tillAct, amt, TellerPostingType.Deposit);
                        custAct.AccountStatus = AccountStatus.Active;
                        if (!result.Equals("success"))
                        {
                            AddError(result);
                            return(View(tellerPosting));
                        }

                        db.Entry(custAct).State = EntityState.Modified;
                        db.Entry(tillAct).State = EntityState.Modified;
                        db.TellerPostings.Add(tellerPosting);
                        db.SaveChanges();

                        reportLogic.CreateTransaction(tillAct, amt, TransactionType.Debit);
                        reportLogic.CreateTransaction(custAct, amt, TransactionType.Credit);

                        return(RedirectToAction("UserPosts"));
                    }
                }
                catch (Exception ex)
                {
                    AddError(ex.ToString());
                    return(View(tellerPosting));
                }
            }
            AddError("Please, enter valid data");
            return(View(tellerPosting));
        }
        public ActionResult PostTransaction(CreateGlPostViewModel model)
        {
            EodLogic logic = new EodLogic();

            if (logic.isBusinessClosed())
            {
                return(PartialView("_Closed"));
            }
            if (ModelState.IsValid)
            {
                try
                {
                    if (model.DrGlAccount_Id == model.CrGlAccount_Id)
                    {
                        return(PartialView("_IncorrectData"));
                    }

                    if (model.CreditAmount == model.DebitAmount && model.CreditAmount > 0)    //double checking
                    {
                        var drAct = glActRepo.GetById(model.DrGlAccount_Id);
                        var crAct = glActRepo.GetById(model.CrGlAccount_Id);
                        //check for sufficient balance on Vault and Tills
                        if (crAct.AccountName.ToLower().Contains("till") || crAct.AccountName.ToLower().Contains("vault"))
                        {
                            if (crAct.AccountBalance < model.CreditAmount)
                            {
                                return(PartialView("_InsufficientBalance"));
                            }
                        }


                        var user = getLoggedInUser();
                        if (user == null || user.Role.ID != 1)  //admin with a role ID of 1
                        {
                            return(RedirectToAction("Login", "UserManager", new { returnUrl = "/glposting/posttransaction" }));
                        }

                        decimal   amt       = model.CreditAmount;
                        GlPosting glPosting = new GlPosting {
                            CreditAmount = amt, DebitAmount = amt, Date = DateTime.Now, CrGlAccount = crAct, DrGlAccount = drAct, Naration = model.Naration, PostInitiator = user
                        };
                        busLogic.CreditGl(crAct, amt);
                        busLogic.DebitGl(drAct, amt);

                        glPostRepo.Insert(glPosting);
                        glActRepo.Update(crAct);
                        glActRepo.Update(drAct);
                        frLogic.CreateTransaction(drAct, amt, TransactionType.Debit);
                        frLogic.CreateTransaction(crAct, amt, TransactionType.Credit);
                        return(PartialView("_SuccessPost"));
                    }
                }
                catch (Exception ex)
                {
                    ErrorLogger.Log("Message= " + ex.Message + "\nInner Exception= " + ex.InnerException + "\n");
                    return(PartialView("Error"));
                }
            }//end if
            ViewBag.DrGlAccount_Id = new SelectList(glActRepo.GetAll(), "ID", "AccountName", model.DrGlAccount_Id);
            ViewBag.CrGlAccount_Id = new SelectList(glActRepo.GetAll(), "ID", "AccountName", model.CrGlAccount_Id);
            return(PartialView("_IncorrectData"));
        }