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));
        }
Beispiel #2
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));
        }
Beispiel #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!" }));
            }
        }