Exemple #1
0
        public ActionResult Save(GlPost glPost)
        {
            if (glPost.GlAccountToCreditId == glPost.GlAccountToDebitId)
            {
                TempData["error"] = "You cannot Post to the same account";
                var glAccounts = _glAccountContext.GetAll();
                var viewModel  = new GlPostViewModel
                {
                    GlAccounts = glAccounts
                };
                return(View("GlPostForm", viewModel));
            }

            var postEntry = _context.PostEntry(glPost);

            if (postEntry == "Success")
            {
                glPost.PostedAt = DateTime.Now;
                glPost.UserId   = Convert.ToInt32(Session["id"]);
                _context.Save(glPost);
                TempData["success"] = "gl Posted Successfully";
            }
            else //if gl post fails,  Show error
            {
                TempData["error"] = postEntry;
                var glAccounts = _glAccountContext.GetAll();
                var viewModel  = new GlPostViewModel
                {
                    GlAccounts = glAccounts
                };
                return(View("GlPostForm", viewModel));
            }

            return(RedirectToAction("Index"));
        }
Exemple #2
0
        public string PostEntry(GlPost glPost)
        {
            string result            = "";
            var    glAccountToCredit = _glAccountContext.Get(Convert.ToInt32(glPost.GlAccountToCreditId));
            var    accountToCredit   = glAccountToCredit.AccountCode;
            var    glAccountToDebit  = _glAccountContext.Get(Convert.ToInt32(glPost.GlAccountToDebitId));
            var    accountToDebit    = glAccountToDebit.AccountCode;

            if (GetAccountMainCategory(accountToCredit) == "Asset" || GetAccountMainCategory(accountToCredit) == "Expense") //special case for credit gl accounts do credit then debit
            {
                var creditFeedback = IsCreditable(accountToCredit, glPost.Amount);
                if (creditFeedback == "Success")
                {
                    var debitFeedback = IsDebitable(accountToDebit, glPost.Amount);
                    if (debitFeedback == "Success")
                    {
                        //do the update
                        CreditGlAccount(glAccountToCredit, glPost.Amount);
                        DebitGlAccount(glAccountToDebit, glPost.Amount);
                        result = debitFeedback;
                    }
                    else
                    {
                        //return the feedback from trying to debit gl account
                        result = debitFeedback;
                    }
                }
                else
                {
                    //credit failed return the reason why it failed
                    result = creditFeedback;
                }
            }
            else
            {
                //if it is not the special case perform debit then credit
                var debitFeedback = IsDebitable(accountToDebit, glPost.Amount);
                if (debitFeedback == "Success")
                {
                    var creditFeedback = IsCreditable(accountToCredit, glPost.Amount);
                    if (creditFeedback == "Success")
                    {
                        CreditGlAccount(glAccountToCredit, glPost.Amount);
                        DebitGlAccount(glAccountToDebit, glPost.Amount);
                        result = creditFeedback;
                    }
                    else
                    {
                        result = creditFeedback;
                    }
                }
                else
                {
                    //debit failed return the reason why it failed
                    result = debitFeedback;
                }
            }
            return(result);
        }
Exemple #3
0
        public string SellCash(decimal amount, int tellerId)
        {
            var result      = "";
            var tillAccount = _tellerContext.GetTillAccount(tellerId);
            var glId        = _glAccountContext.GetByAccCode(tillAccount).Id;
            var vault       = _glAccountContext.GetVault();

            if (vault != null) // check if vault exist
            {
                var creditFeedback = IsGlCreditable(tillAccount, amount);
                if (creditFeedback == "Success")
                {
                    CreditGl(tillAccount, amount);
                    DebitGl(vault.AccountCode, amount);
                    //log Transaction in Gl Post Log
                    var glPost = new GlPost
                    {
                        GlAccountToCreditId = vault.Id,
                        GlAccountToDebitId  = glId,
                        Amount    = amount,
                        Narration = "Sell Cash",
                        UserId    = tellerId,
                        PostedAt  = DateTime.Now
                    };
                    _glPostContext.Save(glPost);
                    result = creditFeedback;
                }
                else
                {
                    //insufficient funds in vault
                    result = creditFeedback;
                }
            }
            else
            {
                result = "Vault Doesn't Exist";
            }
            return(result);
        }
Exemple #4
0
 public void Save(GlPost glPost)
 {
     _db.Add(glPost);
     _db.Save(glPost);
 }