コード例 #1
0
        public void PutGlPostings(int glpostingsid, GlPosting glpostingstoUpdate)
        {
            IGlPostingDb glPostingDb = new GlPostingDb();

            glPostingDb.RetrieveById(glpostingsid);
            glPostingDb.UpdateData(glpostingstoUpdate);
        }
コード例 #2
0
        public ActionResult Create([Bind(Include = "ID,CreditAmount,DebitAmount,Narration,DrGlAccountID,CrGlAccountID")] GlPosting glPosting)
        {
            if (eodLogic.isBusinessClosed())
            {
                // return business closed view , for now use model error.
                AddError("Sorry, business closed");
                return(View(glPosting));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var drAct = db.GlAccounts.Find(glPosting.DrGlAccountID);
                    var crAct = db.GlAccounts.Find(glPosting.CrGlAccountID);

                    if (crAct.AccountName.ToLower().Contains("till") || crAct.AccountName.ToLower().Contains("vault"))
                    {
                        if (crAct.AccountBalance < glPosting.CreditAmount)
                        {// is it really better to return an insuficient balance partial view ?
                            AddError("Insufficient funds in asset account to be credited");
                            return(View(glPosting));
                        }
                    }

                    //glPosting.PostInitiatorId = new ApplicationDbContext().Users.Where(u => u.UserName.Equals(User.Identity.Name)).FirstOrDefault().Id;
                    glPosting.PostInitiatorId = GetLoggedInUserId();
                    glPosting.Date            = DateTime.Now;

                    glPosting.Status = PostStatus.Pending;

                    db.GlPostings.Add(glPosting);
                    db.SaveChanges();

                    //all this is happening after transaction is approved by checker.
                    //decimal amt = glPosting.CreditAmount;

                    //busLogic.CreditGl(crAct, amt);
                    //busLogic.DebitGl(drAct, amt);

                    //db.Entry(drAct).State = EntityState.Modified;
                    //db.Entry(crAct).State = EntityState.Modified;

                    //db.GlPostings.Add(glPosting);
                    //db.SaveChanges();

                    //reportLogic.CreateTransaction(drAct, amt, TransactionType.Debit);
                    //reportLogic.CreateTransaction(crAct, amt, TransactionType.Credit);

                    return(RedirectToAction("Index")); // success post partial view or pop-up on post page ?
                }
                catch (Exception ex)
                {
                    AddError(ex.ToString());
                    return(View(glPosting));
                }
            }
            AddError("Please, enter valid data");
            return(View(glPosting));
        }
コード例 #3
0
ファイル: GlPostingController.cs プロジェクト: Jayora50/JUCBA
        public ActionResult DeleteConfirmed(int id)
        {
            GlPosting glPosting = db.GlPostings.Find(id);

            db.GlPostings.Remove(glPosting);
            db.SaveChanges();
            return(RedirectToAction("UserPosts"));
        }
コード例 #4
0
        public void InsertGlPostings(string REQUESTURI, GlPosting glPosting)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(LocalhostAddress);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                HttpResponseMessage response = client.PostAsJsonAsync(
                    REQUESTURI,
                    glPosting).Result;
            }
        }
コード例 #5
0
ファイル: GlPostingController.cs プロジェクト: Jayora50/JUCBA
        // GET: GlPosting/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            GlPosting glPosting = db.GlPostings.Find(id);

            if (glPosting == null)
            {
                return(HttpNotFound());
            }
            return(View(glPosting));
        }
コード例 #6
0
        public ActionResult DeclineGlPost(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            GlPosting glPosting = db.GlPostings.Find(id);

            if (glPosting == null)
            {
                return(HttpNotFound());
            }
            glPosting.Status          = PostStatus.Declined;
            db.Entry(glPosting).State = EntityState.Modified;
            db.SaveChanges();

            return(RedirectToAction("GlPosts"));
        }
コード例 #7
0
ファイル: GlPostingController.cs プロジェクト: Jayora50/JUCBA
        public ActionResult Create([Bind(Include = "ID,CreditAmount,DebitAmount,Narration,DrGlAccountID,CrGlAccountID")] GlPosting glPosting)
        {
            if (eodLogic.isBusinessClosed())
            {
                // return business closed view , for now use model error.
                AddError("Sorry, business closed");
                return(View(glPosting));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var drAct = db.GlAccounts.Find(glPosting.DrGlAccountID);
                    var crAct = db.GlAccounts.Find(glPosting.CrGlAccountID);

                    if (crAct.AccountName.ToLower().Contains("till") || crAct.AccountName.ToLower().Contains("vault"))
                    {
                        if (crAct.AccountBalance < glPosting.CreditAmount)
                        {// is it really better to return an insuficient balance partial view ?
                            AddError("Insufficient funds in asset account to be credited");
                            return(View(glPosting));
                        }
                    }

                    glPosting.PostInitiatorId = GetLoggedInUserId();
                    glPosting.Date            = DateTime.Now;

                    glPosting.Status = PostStatus.Pending;

                    db.GlPostings.Add(glPosting);
                    db.SaveChanges();

                    return(RedirectToAction("UserPosts")); // success post partial view or pop-up on post page ?
                }
                catch (Exception ex)
                {
                    AddError(ex.ToString());
                    return(View(glPosting));
                }
            }
            AddError("Please, enter valid data");
            return(View(glPosting));
        }
コード例 #8
0
        public ActionResult ApproveGlPost(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            GlPosting glPosting = db.GlPostings.Find(id);

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

            var drAct = glPosting.DrGlAccount;
            var crAct = glPosting.CrGlAccount;

            if (crAct.AccountName.ToLower().Contains("till") || crAct.AccountName.ToLower().Contains("vault"))
            {
                if (crAct.AccountBalance < glPosting.CreditAmount)
                {// is it really better to return an insuficient balance partial view ?
                    return(RedirectToAction("GlPosts", new { message = "Insufficient funds in asset account to be credited" }));
                }
            }

            //all this is happening after transaction is approved by checker.
            decimal amt = glPosting.CreditAmount;

            //this enforces the double entry for the GL posting
            //total credit in GLaccount = total debit in GLaccount.
            busLogic.CreditGl(crAct, amt);
            busLogic.DebitGl(drAct, amt);

            glPosting.Status          = PostStatus.Approved;
            db.Entry(glPosting).State = EntityState.Modified;
            db.Entry(drAct).State     = EntityState.Modified;
            db.Entry(crAct).State     = EntityState.Modified;

            db.SaveChanges();

            reportLogic.CreateTransaction(drAct, amt, TransactionType.Debit);
            reportLogic.CreateTransaction(crAct, amt, TransactionType.Credit);

            return(RedirectToAction("GlPosts", new { message = "Transaction Approved!" }));// success post partial view or pop-up on post page ?
        }
コード例 #9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            IList <EOD> eod = Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IEODDb>().RetrieveAll();

            if (eod.Count == 0 || eod[0].IsClosed == false)
            {
                if (!IsPostBack)
                {
                    var glAccount =
                        Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IGlAccountDb>().RetrieveAll();
                    DropDownListGlAcctToDebit.DataSource     = glAccount;
                    DropDownListGlAcctToDebit.DataValueField = "Id";
                    DropDownListGlAcctToDebit.DataTextField  = "GlAccountName";
                    DropDownListGlAcctToDebit.DataBind();

                    DropDownListGlAcctToCredit.DataSource     = glAccount;
                    DropDownListGlAcctToCredit.DataValueField = "Id";
                    DropDownListGlAcctToCredit.DataTextField  = "GlAccountName";
                    DropDownListGlAcctToCredit.DataBind();
                    if (!string.IsNullOrWhiteSpace(Request.QueryString["id"]))
                    {
                        int       id        = Convert.ToInt32(Request.QueryString["id"]);
                        GlPosting glPosting =
                            Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IGlPostingDb>()
                            .RetrieveById(id);
                        TextBoxNameDebitNarration.Value          = glPosting.DebitNarration;
                        TextBoxNameCreditNarration.Value         = glPosting.CreditNarration;
                        TextBoxNameDebitOrCreditAmnt.Value       = glPosting.Amount.ToString();
                        DropDownListGlAcctToDebit.SelectedValue  = glPosting.GlAccountToDebit.GlAccountName;
                        DropDownListGlAcctToCredit.SelectedValue = glPosting.GlAccountToCredit.GlAccountName;
                        TextBoxId.Value = glPosting.Id.ToString();
                    }
                }
            }

            else if (eod[0].IsClosed)
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", "<script type='text/javascript'>alertify.alert('Message', '" + "Business is closed. Open Business" +
                                                            "', function(){location = '/Start/Default.aspx';});</script>", false);
            }
        }
コード例 #10
0
        public bool BuyCash(decimal amount, int userId)
        {
            //Get teller till account
            var tillAccountId = _tillAccount.GetUserId(userId).AccountManagementId;
            var tillGlAccount = _glContext.Get(tillAccountId);

            //Get Vault Gl Account
            var VaultGl = _glContext.GetVault();


            var check = (VaultGl.AccountBalance < tillGlAccount.AccountBalance)
                ? "You Cannot Buy this amount"
                : "false";

            if (check == "false")
            {
                DebitGlAccount(amount, tillGlAccount);
                CreditGlAccount(amount, VaultGl);

                //Log Transaction
                GlPosting post = new GlPosting()
                {
                    Amount                 = amount,
                    DatePosted             = DateTime.Now,
                    CreditAccountId        = VaultGl.Id,
                    DebitAccountId         = tillGlAccount.Id,
                    CreditAccountNarration = "I sold to the till",
                    DebitAccountNarration  = "I bought from the vault",
                    UserId                 = userId
                };

                _glPost.Add(post);
                _glPost.Save(post);

                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #11
0
ファイル: GlPostingController.cs プロジェクト: Jayora50/JUCBA
        // GET: GlPosting/Create
        public ActionResult Create(int?crId, int?drId)
        {
            if (crId == null || drId == null || crId == drId)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            GlAccount drglAccount = db.GlAccounts.Find(drId);
            GlAccount crglAccount = db.GlAccounts.Find(crId);

            if (drglAccount == null || crglAccount == null)
            {
                return(HttpNotFound());
            }

            GlPosting model = new GlPosting();

            model.DrGlAccountID = drglAccount.ID;
            model.CrGlAccountID = crglAccount.ID;

            return(View(model));
        }
        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"));
        }
コード例 #13
0
        protected void searchsubmit_OnServerClick(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(TextBoxNameDebitNarration.Value))
                {
                    throw new Exception("Debit Narration field is required");
                }
                if (string.IsNullOrWhiteSpace(TextBoxNameCreditNarration.Value))
                {
                    throw new Exception("Credit Narration field is required");
                }
                if (string.IsNullOrWhiteSpace(TextBoxNameDebitOrCreditAmnt.Value))
                {
                    throw new Exception("Amount field is required");
                }
                if (string.IsNullOrWhiteSpace(TextBoxId.Value))
                {
                    GlPosting posting = new GlPosting();

                    //GlPosting glPosting = new GlPosting();
                    GlAccount glAccount =
                        Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IGlAccountDb>()
                        .RetrieveById(int.Parse(DropDownListGlAcctToCredit.SelectedValue));
                    GlAccount glAccounts =
                        Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IGlAccountDb>()
                        .RetrieveById(int.Parse(DropDownListGlAcctToDebit.SelectedValue));
                    posting.GlAccountToDebit    = new GlAccount();
                    posting.GlAccountToDebit.Id = int.Parse(DropDownListGlAcctToDebit.SelectedValue);
                    var glPostings =
                        Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IGlAccountDb>()
                        .RetrieveById(posting.GlAccountToDebit.Id);
                    posting.GlAccountToCredit    = new GlAccount();
                    posting.GlAccountToCredit.Id = int.Parse(DropDownListGlAcctToCredit.SelectedValue);
                    var glPosting =
                        Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IGlAccountDb>()
                        .RetrieveById(posting.GlAccountToCredit.Id);
                    posting.DebitNarration  = TextBoxNameDebitNarration.Value;
                    posting.CreditNarration = TextBoxNameCreditNarration.Value;
                    posting.Amount          = double.Parse(TextBoxNameDebitOrCreditAmnt.Value);

                    IList <EOD> eod =
                        Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IEODDb>().RetrieveAll();
                    posting.TransactionDate = eod[0].FinancialDate;
                    posting.DateAdded       = DateTime.Now;
                    posting.DateUpdated     = DateTime.Now;
                    GlPostingLogic glPostingLogic = new GlPostingLogic();
                    //try
                    //{
                    //    glPosting.Balance = glPostingLogic.CreditGlAccount(glAccount, posting.Amount);
                    //    glPostings.Balance = glPostingLogic.DebitGlAccount(glAccounts, posting.Amount);
                    //}
                    //catch (Exception)
                    //{
                    //    if (glPosting.Balance < 0 || glPostings.Balance < 0)
                    //    {
                    //        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", "<script type='text/javascript'>alertify.alert('Message', '" + "GL Account Balance Cannot Be Negative. Please Post Appropriately " + "', function(){});</script>", false);
                    //    }
                    //    else if (glPosting.Balance >= 0 || glPostings.Balance >= 0)
                    //    {
                    //        Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance<IGlPostingDb>().InsertData(posting);
                    //        Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance<IGlAccountDb>().UpdateData(glPosting);
                    //        Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance<IGlAccountDb>().UpdateData(glPostings);
                    //    }
                    //}
                    glPosting.Balance  = glPostingLogic.CreditGlAccount(glAccount, posting.Amount);
                    glPostings.Balance = glPostingLogic.DebitGlAccount(glAccounts, posting.Amount);


                    if (glPosting.Balance >= 0 && glPostings.Balance >= 0)
                    {
                        Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IGlPostingDb>().InsertData(posting);
                        Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IGlAccountDb>()
                        .UpdateData(glPosting);
                        Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IGlAccountDb>()
                        .UpdateData(glPostings);
                    }
                    else if (glPosting.Balance < 0 || glPostings.Balance < 0)
                    {
                        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", "<script type='text/javascript'>alertify.alert('Message', '" + "GL Account Balance Cannot Be Negative. Please Post Appropriately " + "', function(){});</script>", false);
                    }
                }

                else
                {
                    //adjust code to tally with the one in 'if' clause
                    GlAccount glAccount = new GlAccount();
                    GlPosting glPosting =
                        Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IGlPostingDb>()
                        .RetrieveById(Convert.ToInt32(TextBoxId.Value));
                    glPosting.GlAccountToDebit     = new GlAccount();
                    glPosting.GlAccountToDebit.Id  = int.Parse(DropDownListGlAcctToDebit.SelectedValue);
                    glPosting.GlAccountToCredit    = new GlAccount();
                    glPosting.GlAccountToCredit.Id = int.Parse(DropDownListGlAcctToCredit.SelectedValue);
                    glPosting.DebitNarration       = TextBoxNameDebitNarration.Value;
                    glPosting.CreditNarration      = TextBoxNameCreditNarration.Value;
                    glPosting.Amount = double.Parse(TextBoxNameDebitOrCreditAmnt.Value);
                    GlPostingLogic glPostingLogic = new GlPostingLogic();
                    //glAccount.Balance = glPostingLogic.PostIntoGlAccounts(glAccount, glPosting.Amount);
                    glPosting.GlAccountToCredit.Balance = glPostingLogic.CreditGlAccount(glAccount, glPosting.Amount);
                    glPosting.GlAccountToDebit.Balance  = glPostingLogic.CreditGlAccount(glAccount, glPosting.Amount);
                    glPosting.DateUpdated = DateTime.Now;

                    Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IGlPostingDb>()
                    .UpdateData(glPosting);
                    //Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance<IGlAccountDb>().UpdateData(glAccount);
                }


                TextBoxNameDebitNarration.Value    = String.Empty;
                TextBoxNameCreditNarration.Value   = String.Empty;
                TextBoxNameDebitOrCreditAmnt.Value = String.Empty;


                if (!Page.ClientScript.IsClientScriptBlockRegistered(this.GetType(), "message"))
                {
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", "<script type='text/javascript'>alertify.alert('Message', '" + "Gl Posting Saved Successfully" + "', function(){location = '/GlPostingMgt/PostTransactionsIntoGLs.aspx';});</script>", false);
                }
            }
            catch (Exception ex)
            {
                var glPostings =
                    Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IGlAccountDb>()
                    .RetrieveById(int.Parse(DropDownListGlAcctToDebit.SelectedValue));
                var glPosting =
                    Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IGlAccountDb>()
                    .RetrieveById(int.Parse(DropDownListGlAcctToCredit.SelectedValue));
                if (glPosting.Balance < 0 || glPostings.Balance < 0)
                {
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", "<script type='text/javascript'>alertify.alert('Message', '" + "GL Account Balance Cannot Be Negative. Please Post Appropriately " + "', function(){});</script>", false);
                }
                if (DropDownListGlAcctToDebit.SelectedValue == "0")
                {
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", "<script type='text/javascript'>alertify.alert('Message', '" + "GL Acct to Debit Not Selected. Please Select One " + "', function(){});</script>", false);
                }
                if (DropDownListGlAcctToCredit.SelectedValue == "0")
                {
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", "<script type='text/javascript'>alertify.alert('Message', '" + "GL Acct to Credit Not Selected. Please Select One " + "', function(){});</script>", false);
                }
                string errorMessage = ex.InnerException == null ? ex.Message : ex.InnerException.Message;
                if (!Page.ClientScript.IsClientScriptBlockRegistered(this.GetType(), "message"))
                {
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", @"<script type='text/javascript'>alertify.alert('Message', """ + errorMessage.Replace("\n", "").Replace("\r", "") + @""", function(){});</script>", false);
                }
            }
        }
コード例 #14
0
 public void SavePost(GlPosting savePost)
 {
     //saving into the database
     _loan.Add(savePost);
     _loan.Save(savePost);
 }
コード例 #15
0
 public void UpdatePost(GlPosting savePost)
 {
     //Updating database values
     _loan.Save(savePost);
 }
コード例 #16
0
        protected void searchsubmit_OnServerClick(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(TextBoxNameCustAcctNo.Value))
                {
                    throw new Exception("Account Number field is required");
                }
                if (string.IsNullOrWhiteSpace(TextBoxNameAmount.Value))
                {
                    throw new Exception("Amount field is required");
                }
                if (string.IsNullOrWhiteSpace(TextBoxNameDuration.Value))
                {
                    throw new Exception("Duration field is required");
                }
                if (string.IsNullOrWhiteSpace(TextBoxNameCustAcctName.Value))
                {
                    throw new Exception("Account Name field is required");
                }
                if (DropDownListPaymentSchedule.SelectedValue == Core.PaymentSchedule.Days.ToString())
                {
                    if (string.IsNullOrWhiteSpace(TextBoxNameNumberOfDays.Value))
                    {
                        throw new Exception("Number of Days field is required");
                    }
                }


                CustomerAccounts checkclosedoropen =
                    Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <ICustomerAccountsDb>()
                    .SearchbyAccountNumber(TextBoxNameCustAcctNo.Value);
                if (checkclosedoropen.IsClosed == false)
                {
                    if (string.IsNullOrWhiteSpace(TextBoxId.Value))
                    {
                        LoanAccount loanAccount = new LoanAccount();

                        CustomerAccounts customerAccounts =
                            Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <ICustomerAccountsDb>()
                            .SearchbyAccountNumber(TextBoxNameCustAcctNo.Value);
                        //LoanConfig getLoanById = Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance<ILoanConfigDb>()
                        //        .RetrieveById(1);
                        IList <LoanConfig> getLoanByIds =
                            Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <ILoanConfigDb>()
                            .RetrieveAll();
                        IList <EOD> eods =
                            Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IEODDb>().RetrieveAll();
                        TextBoxNameCustAcctName.Value = customerAccounts.AccountName;
                        loanAccount.LinkedAccount     = new CustomerAccounts();
                        loanAccount.LinkedAccount.Id  = customerAccounts.Id;
                        loanAccount.LoanConfig        = new LoanConfig();
                        //loanAccount.LoanConfig.Id = getLoanById.Id;
                        loanAccount.LoanConfig.Id = getLoanByIds[0].Id;
                        loanAccount.AccountName   = TextBoxNameCustAcctName.Value;
                        loanAccount.LoanAmount    = double.Parse(TextBoxNameAmount.Value);
                        loanAccount.LoanDuration  = double.Parse(TextBoxNameDuration.Value);
                        loanAccount.LoanInterest  = getLoanByIds[0].debitInterestRate;
                        DateTime today = DateTime.Now;
                        loanAccount.LoanStartDate = today;
                        loanAccount.LoanDueDate   = today.AddDays(loanAccount.LoanDuration);
                        Random rand       = new Random();
                        String randomPart = Convert.ToString(rand.Next(10000, 99999));
                        String customerId = customerAccounts.Customer.Id.ToString();
                        loanAccount.AccountNumber   = '3' + customerId + randomPart;
                        loanAccount.Balance         = loanAccount.Balance + double.Parse(TextBoxNameAmount.Value);
                        loanAccount.DateAdded       = DateTime.Now;
                        loanAccount.DateUpdated     = DateTime.Now;
                        loanAccount.PaymentSchedule = (PaymentSchedule)Enum.Parse(typeof(PaymentSchedule), DropDownListPaymentSchedule.SelectedValue);
                        loanAccount.LoanStatus      = LoanStatus.BeingPaid;
                        loanAccount.TransactionDate = eods[0].FinancialDate;
                        if (DropDownListPaymentSchedule.SelectedValue == Core.PaymentSchedule.Days.ToString())
                        {
                            loanAccount.NumberOfDays = int.Parse(TextBoxNameNumberOfDays.Value);
                        }

                        GlAccount glAccount =
                            Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IGlAccountDb>()
                            .RetrieveById(int.Parse(DropDownListLoanAccount.SelectedValue));
                        GlPostingLogic glPostingLogic = new GlPostingLogic();
                        glAccount.Balance = glPostingLogic.DebitGlAccount(glAccount, loanAccount.LoanAmount);

                        User user = new User();
                        user = (User)Session["User"];
                        //Code to update balance in savings account GL
                        var updateSavingsGlBalance =
                            Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <ISavingsConfigDb>()
                            .RetrieveByBranch(user.Branch.Id);
                        updateSavingsGlBalance.SavingsAccountGL.Balance =
                            glPostingLogic.CreditGlAccount(updateSavingsGlBalance.SavingsAccountGL, loanAccount.LoanAmount);



                        //Put Code to update balance in current account GL here:
                        var updateCurrentGlBalance =
                            Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <ICurrentConfigDb>()
                            .RetrieveByBranch(user.Branch.Id);
                        updateCurrentGlBalance.currentAccountGL.Balance =
                            glPostingLogic.CreditGlAccount(updateCurrentGlBalance.currentAccountGL,
                                                           loanAccount.LoanAmount);


                        IList <EOD> eod =
                            Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IEODDb>().RetrieveAll();
                        //Code to Save savings Transaction in GL Posting:
                        GlPosting savingsGlPosting = new GlPosting();
                        savingsGlPosting.Amount               = loanAccount.LoanAmount;
                        savingsGlPosting.CreditNarration      = String.Format("{0} Credited", updateSavingsGlBalance.SavingsAccountGL.GlAccountName);
                        savingsGlPosting.DebitNarration       = String.Format("{0} Debited", glAccount.GlAccountName);
                        savingsGlPosting.GlAccountToCredit    = new GlAccount();
                        savingsGlPosting.GlAccountToCredit.Id = updateSavingsGlBalance.SavingsAccountGL.Id;
                        savingsGlPosting.GlAccountToDebit     = new GlAccount();
                        savingsGlPosting.GlAccountToDebit.Id  = glAccount.Id;
                        savingsGlPosting.TransactionDate      = eod[0].FinancialDate;
                        savingsGlPosting.DateAdded            = DateTime.Now;
                        savingsGlPosting.DateUpdated          = DateTime.Now;

                        //Code to Save Current A/C Transaction in GL Posting:
                        GlPosting currentGlPosting = new GlPosting();
                        currentGlPosting.Amount               = loanAccount.LoanAmount;
                        currentGlPosting.CreditNarration      = String.Format("{0} Credited", updateCurrentGlBalance.currentAccountGL.GlAccountName);
                        currentGlPosting.DebitNarration       = String.Format("{0} Debited", glAccount.GlAccountName);
                        currentGlPosting.GlAccountToCredit    = new GlAccount();
                        currentGlPosting.GlAccountToCredit.Id = updateCurrentGlBalance.currentAccountGL.Id;
                        currentGlPosting.GlAccountToDebit     = new GlAccount();
                        currentGlPosting.GlAccountToDebit.Id  = glAccount.Id;
                        currentGlPosting.TransactionDate      = eod[0].FinancialDate;
                        currentGlPosting.DateAdded            = DateTime.Now;
                        currentGlPosting.DateUpdated          = DateTime.Now;

                        TellerPostingLogic tellerPostingLogic = new TellerPostingLogic();
                        var updateCustAcctBal =
                            Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <ICustomerAccountsDb>()
                            .SearchbyAccountNumber(TextBoxNameCustAcctNo.Value);
                        updateCustAcctBal.Balance = tellerPostingLogic.CreditCustomerAccounts(customerAccounts,
                                                                                              loanAccount.LoanAmount);



                        Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <ILoanAccountDb>().InsertData(loanAccount);
                        Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IGlAccountDb>().UpdateData(glAccount);
                        Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <ICustomerAccountsDb>().UpdateData(updateCustAcctBal);
                        if (customerAccounts.AccountType == AccountType.Savings)
                        {
                            Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IGlAccountDb>()
                            .UpdateData(updateSavingsGlBalance.SavingsAccountGL);
                        }
                        if (customerAccounts.AccountType == AccountType.Current)
                        {
                            Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IGlAccountDb>()
                            .UpdateData(updateCurrentGlBalance.currentAccountGL);
                        }
                        if (customerAccounts.AccountType == AccountType.Savings)
                        {
                            Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IGlPostingDb>()
                            .InsertData(savingsGlPosting);
                        }
                        if (customerAccounts.AccountType == AccountType.Current)
                        {
                            Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IGlPostingDb>()
                            .InsertData(currentGlPosting);
                        }
                    }

                    else
                    {
                    }


                    TextBoxNameCustAcctNo.Value   = String.Empty;
                    TextBoxNameCustAcctName.Value = String.Empty;
                    TextBoxNameAmount.Value       = String.Empty;
                    TextBoxNameDuration.Value     = String.Empty;

                    if (!Page.ClientScript.IsClientScriptBlockRegistered(this.GetType(), "message"))
                    {
                        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", "<script type='text/javascript'>alertify.alert('Message', '" + "Loan Disbursed Successfully." + "', function(){location = '/ManageCustomerAcct/AddLoanAcct.aspx';});</script>", false);
                    }
                }

                else if (checkclosedoropen.IsClosed)
                {
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message",
                                                                "<script type='text/javascript'>alertify.alert('Message', '" +
                                                                "Customer Account is closed. Open Account" +
                                                                "', function(){location = '/ManageCustomerAcct/AddLoanAcct.aspx';});</script>",
                                                                false);
                }
            }
            catch (Exception ex)
            {
                if (DropDownListLoanAccount.SelectedValue == "0")
                {
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", "<script type='text/javascript'>alertify.alert('Message', '" + "Loan Account Not Selected. Please Select a Loan Account " + "', function(){});</script>", false);
                }
                //if (DropDownListPaymentSchedule.SelectedValue == "10")
                //{
                //    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", "<script type='text/javascript'>alertify.alert('Message', '" + "Payment Schedule Not Selected. Please Select a Payment Schedule" + "', function(){});</script>", false);
                //}
                string errorMessage = ex.InnerException == null ? ex.Message : ex.InnerException.Message;
                if (!Page.ClientScript.IsClientScriptBlockRegistered(this.GetType(), "message"))
                {
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", @"<script type='text/javascript'>alertify.alert('Message', """ + errorMessage.Replace("\n", "").Replace("\r", "") + @""", function(){});</script>", false);
                }
            }
        }
コード例 #17
0
        public ActionResult Create(GlPosting savePost)
        {
            bool   status  = false;
            string message = "";

            GlPostingViewModels viewModel = new GlPostingViewModels()
            {
                CreditAccount = _contextAccount.GetAll(),
                DebitAccount  = _contextAccount.GetAll()
            };

            try
            {
                //getting values from form
                savePost.Amount = Convert.ToDecimal(Request.Form["Amount"], CultureInfo.InvariantCulture);
                savePost.DebitAccountNarration  = Request.Form["DebitNarration"];
                savePost.DebitAccountId         = Convert.ToInt32(Request.Form["Debit"]);
                savePost.CreditAccountNarration = Request.Form["CreditNarration"];
                savePost.CreditAccountId        = Convert.ToInt32(Request.Form["Credit"]);
                savePost.UserId     = Convert.ToInt32(Request.Form["Id"]);
                savePost.DatePosted = DateTime.Now;

                var checkingAccounts = _logic.CheckAccount(savePost.DebitAccountId, savePost.CreditAccountId);

                if (checkingAccounts)
                {
                    ModelState.AddModelError("AccountEqual", "Accounts are the same, Please check again");
                    return(View(viewModel));
                }

                var creditAcct = _contextAccount.Get(savePost.CreditAccountId);
                var debitAcct  = _contextAccount.Get(savePost.DebitAccountId);
                var amount     = savePost.Amount;

                //Validating amount in account
                if (creditAcct.Name.ToLower().Contains("till") || creditAcct.Name.ToLower().Contains("vault"))
                {
                    if (creditAcct.AccountBalance < amount)
                    {
                        ModelState.AddModelError("AccountEqual", "You are posting an insufficient amount");
                        return(View(viewModel));
                    }
                }

                //getting account code used
                var creditacctcode = creditAcct.AccCode.ToString()[0].ToString();
                var debitacctcode  = debitAcct.AccCode.ToString()[0].ToString();

                //Posting logic
                _logic.CreditPost(amount, creditAcct, creditacctcode);
                _logic.DebitPost(amount, debitAcct, debitacctcode);


                //save post into database
                _logic.SavePost(savePost);
                _contextAccount.Update(creditAcct);
                _contextAccount.Update(debitAcct);


                message = "Post Complete";
                status  = true;

                ViewBag.Message = message;
                ViewBag.Status  = status;
                return(View(viewModel));
            }
            catch (DbEntityValidationException ex)
            {
                var errorMessages = ex.EntityValidationErrors
                                    .SelectMany(x => x.ValidationErrors)
                                    .Select(x => x.ErrorMessage);

                var fullErrorMessage = string.Join("; ", errorMessages);
                var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);

                throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
            }
        }
コード例 #18
0
 public void PostGlPostings(GlPosting item)
 {
     GlPostingDb.InsertData(item);
 }