public ActionResult RemoveOPASubItems(FormCollection frm)
        {
            SL.LogInfo(User.Identity.Name, Request.RawUrl, "User Deleted Item! (Maintenance Nature of Payments Sub Items) - from Terminal:" + ipaddress);
            SearchOPAccountsViewModel SearchOPASubItemsViewModels = new SearchOPAccountsViewModel();
            int         parsedID  = Convert.ToInt32(frm["RemSubItemsId"]);
            int         OPAId     = Convert.ToInt32(frm["RemOPAId"]);
            OPASubItems opaccount = db.OPASubItems.Find(parsedID);

            db.OPASubItems.Remove(opaccount);
            db.SaveChanges();
            SearchOPASubItemsViewModels.OPASubItemsList = db.OPASubItems.Where(x => x.OPAccountId == OPAId).ToList();
            SearchOPASubItemsViewModels.DivisionList    = db.Division.SqlQuery("Select * from Divisions").ToList();
            foreach (var results in db.OrderOfPaymentDetail.Where(b => b.OPAccountId == OPAId))
            {
                results.Amount      = SearchOPASubItemsViewModels.OPASubItemsList.Sum(x => x.Fee);
                results.TotalAmount = SearchOPASubItemsViewModels.OPASubItemsList.Sum(x => x.Fee);
            }
            db.SaveChanges();
            foreach (var results2 in dc.OPAccount.Where(b => b.OPAccountId == OPAId))
            {
                results2.OPAccountFee = SearchOPASubItemsViewModels.OPASubItemsList.Sum(x => x.Fee);
            }
            dc.SaveChanges();
            TempData["TransactionSuccess"]          = "delete";
            TempData["SearchOPASubItemsViewModels"] = SearchOPASubItemsViewModels;
            return(RedirectToAction("ViewOPASubItems", "MaintenanceOrderOfPaymentAccounts", new { OPAId = OPAId }));
        }
        // Add Sub Items
        public ActionResult AddOPASubItems(FormCollection frmcollection)
        {
            SL.LogInfo(User.Identity.Name, Request.RawUrl, "User Added Item! (Maintenance Nature of Payments Sub Items) - from Terminal:" + ipaddress);
            SearchOPAccountsViewModel SearchOPAccountViewModels = new SearchOPAccountsViewModel();
            ApplicationDbContext      context = new ApplicationDbContext();
            var FeeVal = frmcollection["OPAccountFee"];
            int OPAId  = Convert.ToInt32(frmcollection["OPAId"]);

            if (FeeVal.Contains("."))
            {
            }
            else
            {
                FeeVal = FeeVal + ".00";
            }
            var         userid                = User.Identity.GetUserId();
            string      ZoneGroup             = context.Users.FirstOrDefault(m => m.Id == userid).ZoneGroup;
            string      Division              = context.Users.FirstOrDefault(x => x.Id == userid).Division;
            OPASubItems OPASubItemsAssignment = new OPASubItems();

            //CONDITION
            OPASubItemsAssignment.Code        = frmcollection["OPAccountCode"].ToString();
            OPASubItemsAssignment.NGASCode    = frmcollection["OPAccountNGASCode"].ToString();
            OPASubItemsAssignment.Description = frmcollection["OPAccountDescription"].ToString();
            OPASubItemsAssignment.OPAccountId = OPAId;
            OPASubItemsAssignment.Fee         = Convert.ToDecimal(FeeVal);
            db.OPASubItems.Add(OPASubItemsAssignment);
            db.SaveChanges();
            //SearchOPAccountViewModels.OPAccountList = db.OPAccount.Where(x => x.ZoneGroupCode == ZoneGroup).OrderBy(x => x.OPAccountDescription).ToList();
            SearchOPAccountViewModels.OPASubItemsList = db.OPASubItems.Where(x => x.OPAccountId == OPAId).ToList();
            SearchOPAccountViewModels.DivisionList    = db.Division.SqlQuery("Select * from Divisions").ToList();
            foreach (var results2 in dc.OPAccount.Where(b => b.OPAccountId == OPAId))
            {
                results2.OPAccountFee = SearchOPAccountViewModels.OPASubItemsList.Sum(x => x.Fee);
            }
            dc.SaveChanges();
            foreach (var results in db.OrderOfPaymentDetail.Where(b => b.OPAccountId == OPAId))
            {
                results.Amount      = SearchOPAccountViewModels.OPASubItemsList.Sum(x => x.Fee);
                results.TotalAmount = SearchOPAccountViewModels.OPASubItemsList.Sum(x => x.Fee);
            }
            db.SaveChanges();
            TempData["TransactionSuccess"]          = "Add";
            TempData["SearchOPASubItemsViewModels"] = SearchOPAccountViewModels;
            return(RedirectToAction("ViewOPASubItems", "MaintenanceOrderOfPaymentAccounts", new { OPAId = OPAId }));
        }
        public ActionResult UpdateOPASubItems(FormCollection frmcollection)
        {
            SL.LogInfo(User.Identity.Name, Request.RawUrl, "User Updated Item! (Maintenance Nature of Payments Sub Items) - from Terminal:" + ipaddress);
            OPASubItems opaccountinfo      = null;
            var         OPAFee             = frmcollection["EditFee"].ToString().Replace(",", "");
            int         ParsedIntCompanyID = int.Parse(frmcollection["EditSubItemsId"]);
            int         OPAId = Convert.ToInt32(frmcollection["EditOPAId"]);

            opaccountinfo = db.OPASubItems.Find(ParsedIntCompanyID);
            if (opaccountinfo != null)
            {
                opaccountinfo.Code            = frmcollection["EditCode"].ToString();
                opaccountinfo.NGASCode        = frmcollection["EditNGASCode"].ToString();
                opaccountinfo.Description     = frmcollection["EditDescription"].ToString();
                opaccountinfo.OPAccountId     = Convert.ToInt32(frmcollection["EditOPAId"]);
                opaccountinfo.Fee             = Convert.ToDecimal(frmcollection["EditFee"]);
                db.Entry(opaccountinfo).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }
            db.SaveChanges();
            int parsedOPAId = Convert.ToInt32(frmcollection["EditOPAId"]);
            SearchOPAccountsViewModel searchopaccount = new SearchOPAccountsViewModel();

            //searchopaccount.OPAccountList = db.OPAccount.Where(x => x.ZoneGroupCode == ZoneGroup).OrderBy(x => x.OPAccountDescription).Take(10).ToList();
            searchopaccount.OPASubItemsList = db.OPASubItems.Where(x => x.OPAccountId == parsedOPAId).ToList();
            searchopaccount.DivisionList    = db.Division.SqlQuery("Select * from Divisions").ToList();
            foreach (var results in db.OrderOfPaymentDetail.Where(b => b.OPAccountId == OPAId))
            {
                results.Amount      = searchopaccount.OPASubItemsList.Sum(x => x.Fee);
                results.TotalAmount = searchopaccount.OPASubItemsList.Sum(x => x.Fee);
            }
            db.SaveChanges();
            foreach (var results2 in dc.OPAccount.Where(b => b.OPAccountId == OPAId))
            {
                results2.OPAccountFee = searchopaccount.OPASubItemsList.Sum(x => x.Fee);
            }
            dc.SaveChanges();
            ViewBag.TransactionSuccess = "Edit";
            ViewBag.CompanySelected    = "OK";
            TempData["OPAId"]          = parsedOPAId;
            return(View("ViewOPASubItems", searchopaccount));
        }