public ActionResult UpdateHoliday(FormCollection frmcollection)
        {
            HolidayTable holiinfo    = null;
            int          ParsedIntID = int.Parse(frmcollection["ID"]);

            holiinfo = db.HolidayTable.Find(ParsedIntID);

            if (holiinfo != null)
            {
                //compinfo.CompanyCode = frmcollection["CompanyCode"].ToString();
                holiinfo.HolidayTableDate        = Convert.ToDateTime(frmcollection["Date"].ToString()).Date;
                holiinfo.HolidayTableDescription = frmcollection["Description"].ToString();
                db.Entry(holiinfo).State         = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }
            else
            {
                throw new Exception("Invalid transaction.");
            }
            int parsedID = int.Parse(frmcollection["ID"]);
            SearchHolidayTableViewModel searchholiday = new SearchHolidayTableViewModel();

            searchholiday.HolidayList = db.HolidayTable.SqlQuery("Select * from HolidayTables").ToList();
            return(View("ViewHolidayTable", searchholiday));
        }
Example #2
0
        public PartialViewResult Edit(int DivisionIdEdit, string DivisionCodeEdit, string DivisionNameEdit)
        {
            IEnumerable <Division> divisions = new List <Division>();
            BCS_Context            db        = new BCS_Context();

            try
            {
                using (var dbtransaction = db.Database.BeginTransaction())
                {
                    Division division = new Division();
                    division                 = db.Division.FirstOrDefault(m => m.DivisionId == DivisionIdEdit);
                    division.Code            = DivisionCodeEdit;
                    division.Name            = DivisionNameEdit;
                    db.Entry(division).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                    dbtransaction.Commit();
                    divisions = db.Division.ToList().OrderBy(m => m.Name);
                    //divisions.Add(division);
                    SL.LogInfo(User.Identity.Name, Request.RawUrl, "Division - Division Edited  - from Terminal: " + ipaddress);

                    return(PartialView("_DivisionPartial", divisions));
                }
            }
            catch (Exception)
            {
                SL.LogInfo(User.Identity.Name, Request.RawUrl, "Division - Edit division failed  - from Terminal: " + ipaddress);
                divisions = db.Division.ToList().OrderBy(m => m.Name);
                return(PartialView("_DivisionPartial", divisions));
            }
        }
        public ActionResult UpdateOPAccount(FormCollection frmcollection)
        {
            SL.LogInfo(User.Identity.Name, Request.RawUrl, "User Updated Item! (Maintenance Nature of Payments) - from Terminal:" + ipaddress);
            OPAccount            opaccountinfo = null;
            ApplicationDbContext context       = new ApplicationDbContext();
            var    OPAFee             = frmcollection["OPAccountFee"].ToString().Replace(",", "");
            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;
            int    ParsedIntCompanyID = int.Parse(frmcollection["OPAccountId1"]);

            opaccountinfo = db.OPAccount.Find(ParsedIntCompanyID);
            if (opaccountinfo != null)
            {
                opaccountinfo.OPAccountCode        = frmcollection["OPAccountCode"].ToString();
                opaccountinfo.NGASCode             = frmcollection["OPAccountNGASCode"].ToString();
                opaccountinfo.OPAccountDescription = frmcollection["OPAccountDescription"].ToString();
                opaccountinfo.OPAccountFee         = Convert.ToDecimal(OPAFee);
                opaccountinfo.DivisionCode         = frmcollection["DivisionCode"];
                opaccountinfo.ZoneGroupCode        = ZoneGroup;
                opaccountinfo.OPAccountDescription = frmcollection["OPAccountDescription"].ToString();
                opaccountinfo.OPAccountValidity    = frmcollection["OPAccountValidity"].ToString();
                opaccountinfo.AccountTag           = frmcollection["AccountTag"].ToString();
                db.Entry(opaccountinfo).State      = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }
            foreach (var results in db.OrderOfPaymentDetail.Where(b => b.OPAccountId == ParsedIntCompanyID))
            {
                results.AccountTag = frmcollection["AccountTag"].ToString();
            }
            db.SaveChanges();
            int parsedCompanyID = int.Parse(frmcollection["OPAccountId1"]);
            SearchOPAccountsViewModel searchopaccount = new SearchOPAccountsViewModel();

            //searchopaccount.OPAccountList = db.OPAccount.Where(x => x.ZoneGroupCode == ZoneGroup).OrderBy(x => x.OPAccountDescription).Take(10).ToList();
            searchopaccount.OPAccountList = db.OPAccount.Where(x => x.OPAccountId == parsedCompanyID).ToList();
            searchopaccount.DivisionList  = db.Division.SqlQuery("Select * from Divisions").ToList();
            ViewBag.TransactionSuccess    = "Edit";
            ViewBag.CompanySelected       = "OK";
            return(View("ViewOrderOfPaymentAccounts", searchopaccount));
        }
Example #4
0
        public ActionResult UpdateZoneGroup(FormCollection frmcollection)
        {
            ZoneGroup zonegroupinfo = null;
            int       ParsedIntID   = int.Parse(frmcollection["ZoneGId"]);

            string zonegroupcode = frmcollection["ZoneGroupCode"].ToString();

            zonegroupinfo = db.ZoneGroup.Find(ParsedIntID);
            string zoneCodeOrig  = db.ZoneGroup.FirstOrDefault(m => m.ZoneGroupId == ParsedIntID).ZoneGroupCode;
            int    newzonecodeId = 0;

            if (db.ZoneGroup.Any(m => m.ZoneGroupCode == zonegroupcode))
            {
                newzonecodeId = db.ZoneGroup.FirstOrDefault(m => m.ZoneGroupCode == zonegroupcode).ZoneGroupId;
            }

            if ((db.ZoneGroup.Any(m => m.ZoneGroupCode == zonegroupcode) && newzonecodeId == ParsedIntID) || (!db.ZoneGroup.Any(m => m.ZoneGroupCode == zonegroupcode)))
            {
                if (zonegroupinfo != null)
                {
                    zonegroupinfo.ZoneGroupCode     = frmcollection["ZoneGroupCode"].ToString();
                    zonegroupinfo.ZoneGroupName     = frmcollection["ZoneGroupName"].ToString();
                    zonegroupinfo.ZoneGroupAddress  = frmcollection["ZoneGroupAddress"].ToString();
                    zonegroupinfo.ZoneGroupRole     = frmcollection["ZoneGroupRole"].ToString();
                    zonegroupinfo.ZoneGroupInitials = frmcollection["ZoneGroupInitial"].ToString();
                    db.Entry(zonegroupinfo).State   = System.Data.Entity.EntityState.Modified;

                    SL.LogInfo(User.Identity.Name, Request.RawUrl, "Admin Zone - Zone Group Edited  - from Terminal: " + ipaddress);

                    db.SaveChanges();
                    TempData["TransactionSuccess"] = "Edit";
                }
            }
            else
            {
                TempData["TransactionSuccess"] = "Duplicate";
            }

            return(RedirectToAction("ViewZoneGroup"));
        }
Example #5
0
        public ActionResult Edit_Post(RoleAssignmentMatrix roleAssignmentMatrix, string All, string user2)
        {
            roleAssignmentMatrix.UserName = user2;
            ApplicationDbContext context = new ApplicationDbContext();
            string zonegroup             = context.Users.FirstOrDefault(m => m.UserName == roleAssignmentMatrix.UserName).ZoneGroup;

            roleAssignmentMatrix.ZoneGroup = zonegroup;
            TryUpdateModel(roleAssignmentMatrix);
            roleAssignmentMatrix.ZoneGroup = zonegroup;

            if (All == "All")
            {
                roleAssignmentMatrix.Administrative   = true;
                roleAssignmentMatrix.Aging            = true;
                roleAssignmentMatrix.Billing          = true;
                roleAssignmentMatrix.Collection       = true;
                roleAssignmentMatrix.Company          = true;
                roleAssignmentMatrix.Franchise        = true;
                roleAssignmentMatrix.Garbage          = true;
                roleAssignmentMatrix.HO               = true;
                roleAssignmentMatrix.JBR              = true;
                roleAssignmentMatrix.PassedOnBilling  = true;
                roleAssignmentMatrix.Payment          = true;
                roleAssignmentMatrix.Period           = true;
                roleAssignmentMatrix.Pole             = true;
                roleAssignmentMatrix.Rate             = true;
                roleAssignmentMatrix.Rentals          = true;
                roleAssignmentMatrix.Security         = true;
                roleAssignmentMatrix.Sewerage         = true;
                roleAssignmentMatrix.SubsidiaryLedger = true;
                roleAssignmentMatrix.Water            = true;
            }

            db.Entry(roleAssignmentMatrix).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
            TempData["TransactionSuccess"] = "Edit";
            SL.LogInfo(User.Identity.Name, Request.RawUrl, "Role Assignment - Role Edited  - from Terminal: " + ipaddress);
            return(RedirectToAction("Details"));
        }
        public ActionResult UpdatePeriod(FormCollection frmcollection)
        {
            var username = User.Identity.GetUserName();
            RoleAssignmentMatrix roleAssignmentMatrix = db.RoleAssignmentMatrix.SingleOrDefault(m => m.UserName == username);

            ViewBag.IsValidRole = roleAssignmentMatrix.Period;
            BillingPeriod Periodinfo  = null;
            int           ParsedIntID = int.Parse(frmcollection["BillingPeriodId"]);

            string BillingStatus = db.BillingPeriod.Where(m => m.BillingPeriodId == ParsedIntID).SingleOrDefault().Finalized;

            if (BillingStatus.ToUpper() == "NO")
            {
                Periodinfo = db.BillingPeriod.Find(ParsedIntID);
                if (Periodinfo != null)
                {
                    Periodinfo.PeriodText = frmcollection["PeriodText"].ToString();
                    Periodinfo.DateFrom   = Convert.ToDateTime(frmcollection["DateFrom"].ToString());
                    Periodinfo.DateTo     = Convert.ToDateTime(frmcollection["DateTo"].ToString());
                    //Periodinfo.groupCode = Group;
                    db.Entry(Periodinfo).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                }
                else
                {
                    throw new Exception("Invalid transaction.");
                }
            }
            else
            {
                Response.Write("<script>alert('Unable to edit finalized billing period.')</script>");
            }
            int parsedID = int.Parse(frmcollection["BillingPeriodId"]);

            SL.LogInfo(User.Identity.Name, Request.RawUrl, "Maintenance Period Table - Period Table Updated  - from Terminal: " + ipaddress);

            return(RedirectToAction("ViewPeriodTablePRG", "MaintenancePeriodTable"));
        }
        public ActionResult AddPoleRental(FormCollection frm)
        {
            var origamt = frm["Amount"];
            var amt     = frm["Amount"].Split(',');

            var newAmount = "";

            foreach (var item in amt)
            {
                newAmount += item;
            }
            var userid   = User.Identity.GetUserId();
            var username = User.Identity.GetUserName();
            RoleAssignmentMatrix roleAssignmentMatrix = db.RoleAssignmentMatrix.FirstOrDefault(m => m.UserName == username);

            ViewBag.IsValidRole = roleAssignmentMatrix.Pole;
            //SL.LogInfo(User.Identity.Name, Request.RawUrl, "User Added Item! (Data Entry Pole Rental) - from Terminal:" + ipaddress);
            string isEdit = frm["isEdit"].ToString();
            SearchPoleInformationViewModel SearchPoleRentalViewModels = new SearchPoleInformationViewModel();

            PoleInformation PoleRentalAssignment = new PoleInformation();
            int             CompanyId            = int.Parse(frm["CompanyId"].ToString());
            var             errors = ModelState.Values.SelectMany(v => v.Errors);

            TryUpdateModel(PoleRentalAssignment);
            //if (ModelState.IsValid)
            //{
            if (isEdit != "True")
            {
                PoleRentalAssignment.Amount        = Convert.ToDecimal(origamt);
                PoleRentalAssignment.CreatedDate   = DateTime.Now;
                PoleRentalAssignment.CreatedBy     = userid;
                PoleRentalAssignment.BillMode      = frm["BillMode"];
                PoleRentalAssignment.BillingMonths = frm["billingMonths"];
                //PoleRentalAssignment.BillingMonths = "1,2,3,4,5,6,7,8,9,10,11,12";
                db.PoleInformation.Add(PoleRentalAssignment);
                db.SaveChanges();
                TempData["TransactionSuccess"] = "Add";
                SL.LogInfo(User.Identity.Name, Request.RawUrl, "Data Entry Pole Rental- Add  - from Terminal:" + ipaddress);
            }
            else
            {
                int ParsedIntID = int.Parse(frm["ID"]);
                PoleRentalAssignment = db.PoleInformation.Find(ParsedIntID);
                //compinfo.CompanyCode = frmcollection["CompanyCode"].ToString();
                PoleRentalAssignment.Amount        = Convert.ToDecimal(newAmount);
                PoleRentalAssignment.StartDate     = Convert.ToDateTime(frm["StartDate"].ToString());
                PoleRentalAssignment.EndDate       = Convert.ToDateTime(frm["EndDate"].ToString());
                PoleRentalAssignment.UpdateDate    = DateTime.Now;
                PoleRentalAssignment.UpdatedBy     = userid;
                PoleRentalAssignment.BillingMonths = frm["billingMonths"];
                //PoleRentalAssignment.BillingMonths = "1,2,3,4,5,6,7,8,9,10,11,12";
                PoleRentalAssignment.BillMode        = frm["BillMode"];
                db.Entry(PoleRentalAssignment).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
                TempData["TransactionSuccess"] = "Edit";
                SL.LogInfo(User.Identity.Name, Request.RawUrl, "Data Entry Pole Rental- Edit  - from Terminal:" + ipaddress);
                //ViewBag.TransactionSuccess = "Add";
            }
            ViewBag.ValidatePostback = "True";
            //}
            //else
            //{
            //    ViewBag.ValidatePostback = "False";
            //}

            ViewBag.CompanySelected = "OK";
            SearchPoleRentalViewModels.CompanyList         = db.Company.Where(m => m.CompanyID == CompanyId).ToList();
            SearchPoleRentalViewModels.PoleInformationList = db.PoleInformation.Where(m => m.CompanyId == CompanyId).ToList();

            TempData["SearchPoleRentalViewModels"] = SearchPoleRentalViewModels;
            return(RedirectToAction("ViewPoleRentalsRPG", "DataEntryPoleRental"));
            //return View("ViewPoleRentals", SearchPoleRentalViewModels);
        }
        public ActionResult ViewGenerate(FormCollection frm)
        {
            int    generatePerCompanyId  = 0;
            string BillingGenerateValue  = "";
            ApplicationDbContext context = new ApplicationDbContext();
            var    userid     = User.Identity.GetUserId();
            var    username   = User.Identity.GetUserName();
            string ZoneGroup1 = context.Users.SingleOrDefault(m => m.Id == userid).ZoneGroup;
            RoleAssignmentMatrix roleAssignmentMatrix = db.RoleAssignmentMatrix.SingleOrDefault(m => m.UserName == username);

            ViewBag.IsValidRole = roleAssignmentMatrix.Billing;

            //CoverageFrom CoverageTo
            int billingPeriodId = int.Parse(frm["PeriodId"].ToString());

            VerifyBillingPeriod verify = new VerifyBillingPeriod(billingPeriodId, ZoneGroup1);

            if (verify.canGenerate()) //Verify if previous billing already generated a billing.
            {
                string   FxRate         = frm["FxRate"].ToString();
                DateTime dtCoverageFrom = Convert.ToDateTime(frm["CoverageFrom"].ToString());
                DateTime dtCoverageTo   = Convert.ToDateTime(frm["CoverageTo"].ToString());
                DateTime dtBillingDate  = Convert.ToDateTime(frm["BillDate"].ToString());
                DateTime dtBillingDue   = Convert.ToDateTime(frm["DueDate"].ToString());
                Company  company        = new Company();

                string TypeOfBillingGenerate = frm["TypeOfBillingGenerate"].ToString();

                if (TypeOfBillingGenerate == "PerCompany")
                {
                    generatePerCompanyId = Convert.ToInt32(frm["generatePerCompanyId"].ToString());
                    BillingGenerateValue = frm["TypeOfBillingGeneratePerCompany"].ToString();
                }
                else if (TypeOfBillingGenerate == "PerPOB")
                {
                    BillingGenerateValue = frm["TypeOfBillingGeneratePerPOB"].ToString();
                }
                else if (TypeOfBillingGenerate == "PerBillingType")
                {
                    BillingGenerateValue = frm["TypeOfBillingGeneratePerBillingType"].ToString();
                }
                else if (TypeOfBillingGenerate == "PerAdminFee")
                {
                    BillingGenerateValue = frm["TypeOfBillingGeneratePerAdminFee"].ToString();
                }


                //Get the current user
                //ApplicationDbContext context = new ApplicationDbContext();
                string        ZoneGroup     = context.Users.SingleOrDefault(m => m.Id == userid).ZoneGroup;
                BillingPeriod billingPeriod = db.BillingPeriod.Find(billingPeriodId);
                string        isgenerated   = billingPeriod.Generated;
                bool          isGenerated   = true; // delete this line of need to delete first the records in regenerate
                //bool isGenerated = false; //The role is Delete first the data then return as true.
                #region delete_records
                //08-01-2017 do not delete records in regenerate.. update only the changes
                //if (isgenerated.ToLower() == "yes")
                //{
                //    if (!string.IsNullOrEmpty(TypeOfBillingGenerate) && TypeOfBillingGenerate.ToUpper() == "PERCOMPANY") //Delete base on type of billing generate
                //    {
                //        int companyId = Convert.ToInt32(generatePerCompanyId);
                //        BillingRegenerateBLL billingRegenerateBLL = new BillingRegenerateBLL(billingPeriodId, companyId);
                //        isGenerated = billingRegenerateBLL.RegenerateBillingPerCompany();
                //        SL.LogInfo(User.Identity.Name, Request.RawUrl, "Billing Regenerate- Billing generate percompany.  - from Terminal: " + ipaddress);
                //    }
                //    else if (!string.IsNullOrEmpty(TypeOfBillingGenerate) && TypeOfBillingGenerate.ToUpper() == "PERENTERPRISE")
                //    {
                //        BillingRegenerateBLL billingRegenerateBLL = new BillingRegenerateBLL(billingPeriodId, BillingGenerateValue);
                //        isGenerated = billingRegenerateBLL.RegenerateBillingPerEnterprise();
                //        SL.LogInfo(User.Identity.Name, Request.RawUrl, "Billing Regenerate- Billing generate perenterprise.  - from Terminal: " + ipaddress);
                //    }
                //    else if (!string.IsNullOrEmpty(TypeOfBillingGenerate) && TypeOfBillingGenerate.ToUpper() == "PERBILLINGTYPE")
                //    {
                //        BillingRegenerateBLL billingRegenerateBLL = new BillingRegenerateBLL(billingPeriodId, BillingGenerateValue);
                //        isGenerated = billingRegenerateBLL.RegenerateBillingPerBillingType();
                //        SL.LogInfo(User.Identity.Name, Request.RawUrl, "Billing Regenerate- Billing generate perbillingtype.  - from Terminal: " + ipaddress);
                //    }
                //    else if (!string.IsNullOrEmpty(TypeOfBillingGenerate) && TypeOfBillingGenerate.ToUpper() == "PERADMINFEE")
                //    {
                //        BillingRegenerateBLL billingRegenerateBLL = new BillingRegenerateBLL(billingPeriodId, BillingGenerateValue);
                //        isGenerated = billingRegenerateBLL.RegenerateBillingPerAdminFee();
                //        SL.LogInfo(User.Identity.Name, Request.RawUrl, "Billing Regenerate- Billing generate peradminfee.  - from Terminal: " + ipaddress);
                //    }
                //    else
                //    {
                //        BillingRegenerateBLL billingRegenerateBLL = new BillingRegenerateBLL(billingPeriodId);
                //        isGenerated = billingRegenerateBLL.RegenerateBilling();
                //        SL.LogInfo(User.Identity.Name, Request.RawUrl, "Billing Regenerate- Billing generate all company.  - from Terminal: " + ipaddress);
                //    }
                //}
                #endregion delete_records
                //BillingBusinessLayer billingBusinessLayer = new BillingBusinessLayer(ZoneGroup, dtCoverageFrom, dtCoverageTo, dtBillingDate, dtBillingDue, billingPeriodId, userid, FxRate, generatePerCompanyId, TypeOfBillingGenerate);
                BillingBusinessLayerNewAlgo billingBusinessLayerNewAlgoTemp = new BillingBusinessLayerNewAlgo(ZoneGroup, dtCoverageFrom, dtCoverageTo, dtBillingDate, dtBillingDue, billingPeriodId, userid, FxRate, generatePerCompanyId, TypeOfBillingGenerate, BillingGenerateValue);

                //bool isCurrencyValid = true;
                bool isCurrencyValid = billingBusinessLayerNewAlgoTemp.isValidFxRate(FxRate);
                if (dtBillingDue >= dtCoverageFrom && dtBillingDate >= dtCoverageFrom)
                {
                    if (db.BillingRates.Any(m => m.Category == "Sewerage" && m.ZoneGroup == ZoneGroup))
                    {
                        if (isCurrencyValid)
                        {
                            BillingPeriod CloseBillingPeriod = db.BillingPeriod.Find(billingPeriodId);
                            CloseBillingPeriod.IsPaymentOpen   = false;
                            db.Entry(CloseBillingPeriod).State = System.Data.Entity.EntityState.Modified;
                            db.SaveChanges();
                            using (var dbtransaction = db.Database.BeginTransaction())
                            {
                                try //If Custom error is Enabled. Delete this try catch block.. "Using" statement above will automatically rollback transaction when error occur.
                                {
                                    if (isgenerated.ToLower() == "yes" && isGenerated)
                                    {
                                        //BillingBusinessLayerNewAlgo billingBusinessLayerNewAlgo = new BillingBusinessLayerNewAlgo(ZoneGroup, dtCoverageFrom, dtCoverageTo, dtBillingDate, dtBillingDue, billingPeriodId, userid, FxRate, generatePerCompanyId, TypeOfBillingGenerate, BillingGenerateValue);
                                        //billingBusinessLayer.generateBilling();
                                        billingBusinessLayerNewAlgoTemp.generateBilling();
                                        SL.LogInfo(User.Identity.Name, Request.RawUrl, "Billing Regenerate - Billing generate complete.  - from Terminal: " + ipaddress);
                                        TempData["BillingStatus"] = "Billing generate complete";//Response.Write("<script>alert('Billing generate complete.')</script>");
                                    }
                                    else
                                    {
                                        //BillingBusinessLayerNewAlgo billingBusinessLayerNewAlgo = new BillingBusinessLayerNewAlgo(ZoneGroup, dtCoverageFrom, dtCoverageTo, dtBillingDate, dtBillingDue, billingPeriodId, userid, FxRate, generatePerCompanyId, TypeOfBillingGenerate, BillingGenerateValue);
                                        //billingBusinessLayer.generateBilling();
                                        billingBusinessLayerNewAlgoTemp.generateBilling();
                                        SL.LogInfo(User.Identity.Name, Request.RawUrl, "Billing Generate- Billing generate complete.  - from Terminal: " + ipaddress);
                                        TempData["BillingStatus"] = "Billing generate complete"; //Response.Write("<script>alert('Billing generate complete.')</script>");
                                    }
                                }
                                catch (DbEntityValidationException ex)
                                {
                                    //    catch (DbEntityValidationException dbEx)
                                    //{
                                    foreach (var validationErrors in ex.EntityValidationErrors)
                                    {
                                        foreach (var validationError in validationErrors.ValidationErrors)
                                        {
                                            Trace.TraceInformation("Property: {0} Error: {1}",
                                                                   validationError.PropertyName,
                                                                   validationError.ErrorMessage);
                                        }
                                        //    }
                                    }

                                    string ex1 = ex.Message;
                                    TempData["BillingStatus"] = ex1;  //Response.Write("<script>alert('Billing Generation failed.')</script>");
                                    dbtransaction.Rollback();
                                }
                            }//End of using
                             //BillingPeriod OpenBillingPeriod = db.BillingPeriod.Find(billingPeriodId);
                             //OpenBillingPeriod.IsPaymentOpen = true;
                             //db.Entry(OpenBillingPeriod).State = System.Data.Entity.EntityState.Modified;
                             //db.SaveChanges();
                        }//End of is not USD
                        else
                        {
                            TempData["BillingStatus"] = "Billing Generation failed. The system has detected USD type of billing. Please input data in FX Rate field.";
                            SL.LogWarning(User.Identity.Name, Request.RawUrl, "Billing Generate- Billing Generation failed.  - from Terminal: " + ipaddress);
                            //Response.Write("<script>alert('Billing Generation failed. The system has detected USD type of billing. Please input data in FX Rate field.')</script>");
                        }
                    }
                    else
                    {
                        TempData["BillingStatus"] = "Unable to proceed. No Sewerage rate detected.";
                        SL.LogError(User.Identity.Name, Request.RawUrl, "Billing Generate- Unable to proceed.No Sewerage rate detected.  - from Terminal: " + ipaddress);


                        //Response.Write("<script>alert('Unable to proceed. No Sewerage rate detected.')</script>");
                    }
                }
                else
                {
                    TempData["BillingStatus"] = "Unable to proceed. Billing Date/Due Date must be greater than Coverage Date.";
                }
            }
            else
            {
                TempData["BillingStatus"] = "Unable to proceed. Previous billing period already generated a billing.";
                //Response.Write("<script>alert('Unable to proceed. Previous billing period already generated a billing.')</script>");
            }
            //
            List <BillingPeriod> billingperiodlist = new List <BillingPeriod>();
            billingperiodlist = db.BillingPeriod.ToList();
            //return View("ViewGenerate", billingperiodlist);
            TempData["Toggled"] = "Toggled";
            return(RedirectToAction("ViewGeneratePRG", "BillingGenerate"));
        }
Example #9
0
        public ActionResult AddPassedOnBilling(int CompanyId, Decimal Amount, DateTime OriginDateAdd, DateTime BillingDateAdd, int BillingPeriod, string Type, string isEdit, string PassedOnBillingInfoId)
        {
            PassedOnBillingViewModel searchcompany = new PassedOnBillingViewModel();
            var    userid    = User.Identity.GetUserId();
            string ZoneGroup = context.Users.FirstOrDefault(m => m.Id == userid).ZoneGroup;
            var    username  = User.Identity.GetUserName();
            RoleAssignmentMatrix roleAssignmentMatrix = db.RoleAssignmentMatrix.FirstOrDefault(m => m.UserName == username);

            ViewBag.IsValidRole = roleAssignmentMatrix.PassedOnBilling;
            //SL.LogInfo(User.Identity.Name, Request.RawUrl, "User Added Item! (Data Entry PassOnBilling) - from Terminal:" + ipaddress);
            PassedOnBillingInformation passedonBillingInfo = null;

            passedonBillingInfo = db.PassedOnBillingInformation.Find(CompanyId);

            if (isEdit != "Edit")
            {
                PassedOnBillingViewModel   passedonBillingViewModels = new PassedOnBillingViewModel();
                PassedOnBillingInformation passedonBillingAssignment = new PassedOnBillingInformation();
                passedonBillingViewModels.ZoneList      = db.Zone.Select(x => x).ToList();
                passedonBillingAssignment.CompanyId     = CompanyId;
                passedonBillingAssignment.Amount        = Amount;
                passedonBillingAssignment.Type          = Type;
                passedonBillingAssignment.OriginDate    = OriginDateAdd;
                passedonBillingAssignment.BillingDate   = BillingDateAdd;
                passedonBillingAssignment.CreateDate    = DateTime.Now;
                passedonBillingAssignment.CreatedBy     = userid;
                passedonBillingAssignment.BillingPeriod = BillingPeriod;
                db.PassedOnBillingInformation.Add(passedonBillingAssignment);
                db.SaveChanges();

                passedonBillingViewModels.CompanyList         = db.Company.Where(m => m.CompanyID == CompanyId).ToList();
                passedonBillingViewModels.PassedOnBillingList = db.PassedOnBillingInformation.Where(m => m.CompanyId == CompanyId).ToList();
                passedonBillingViewModels.TotalAmount         = db.PassedOnBillingInformation.Where(m => m.CompanyId == CompanyId).Sum(x => x.Amount);

                //passedonBillingViewModels.BillingPeriodList = db.BillingPeriod.Where(x => x.groupCode == ZoneGroup).Where(m => m.Finalized.ToUpper() != "YES").ToList();
                passedonBillingViewModels.BillingPeriodList = db.BillingPeriod.Where(x => x.groupCode == ZoneGroup).ToList();
                var billp = passedonBillingViewModels.BillingPeriodList.OrderByDescending(m => m.BillingPeriodId);
                passedonBillingViewModels.BillingPeriodList = billp.ToList();
                //return View("ViewSecurityGuardFee", SearchSecurityGuardFeeViewModels);
                TempData["TransactionSuccess"] = "Add";
                SL.LogInfo(User.Identity.Name, Request.RawUrl, "Data Entry Passed OnBilling - Add -from Terminal:" + ipaddress);
                TempData["PassedOnBillingData"] = passedonBillingViewModels;
            }
            else
            {
                int passedonbillingid = Convert.ToInt32(PassedOnBillingInfoId);
                passedonBillingInfo = db.PassedOnBillingInformation.FirstOrDefault(m => m.PassedOnBillingInformationId == passedonbillingid);
                PassedOnBillingViewModel passedonBillingViewModels = new PassedOnBillingViewModel();
                passedonBillingViewModels.ZoneList  = db.Zone.Select(x => x).ToList();
                passedonBillingInfo.Amount          = Amount;
                passedonBillingInfo.OriginDate      = OriginDateAdd;
                passedonBillingInfo.BillingDate     = BillingDateAdd;
                passedonBillingInfo.BillingPeriod   = BillingPeriod;
                passedonBillingInfo.Type            = Type;
                passedonBillingInfo.UpdatedBy       = userid;
                passedonBillingInfo.UpdateDate      = DateTime.Now;
                db.Entry(passedonBillingInfo).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();

                passedonBillingViewModels.CompanyList         = db.Company.Where(m => m.CompanyID == CompanyId).ToList();
                passedonBillingViewModels.PassedOnBillingList = db.PassedOnBillingInformation.Where(m => m.CompanyId == CompanyId).ToList();
                passedonBillingViewModels.TotalAmount         = db.PassedOnBillingInformation.Where(m => m.CompanyId == CompanyId).Sum(x => x.Amount);
                ViewBag.CompanySelected = "OK";

                //passedonBillingViewModels.BillingPeriodList = db.BillingPeriod.Where(x => x.groupCode == ZoneGroup).Where(m => m.Finalized.ToUpper() != "YES").ToList();
                passedonBillingViewModels.BillingPeriodList = db.BillingPeriod.Where(x => x.groupCode == ZoneGroup).ToList();
                var billp = passedonBillingViewModels.BillingPeriodList.OrderByDescending(m => m.BillingPeriodId);
                passedonBillingViewModels.BillingPeriodList = billp.ToList();
                TempData["TransactionSuccess"] = "Edit";
                SL.LogInfo(User.Identity.Name, Request.RawUrl, "Data Entry Passed OnBilling - Edit -from Terminal:" + ipaddress);
                TempData["PassedOnBillingData"] = passedonBillingViewModels;
            }
            return(RedirectToAction("ViewPassedOnBillingPRG", "DataEntryPassedOnBilling"));
        }
Example #10
0
        public ActionResult AddFranchiseInformation(FormCollection formcollection)
        {
            string isEdit   = formcollection["isEdit"].ToString();
            var    userid   = User.Identity.GetUserId();
            var    username = User.Identity.GetUserName();
            RoleAssignmentMatrix roleAssignmentMatrix = db.RoleAssignmentMatrix.FirstOrDefault(m => m.UserName == username);

            ViewBag.IsValidRole = roleAssignmentMatrix.Franchise;
            SL.LogInfo(User.Identity.Name, Request.RawUrl, "User Added Item! (Data Entry Franchise Information) - from Terminal:" + ipaddress);
            int CompanyId = Convert.ToInt32(formcollection["CompanyId"].ToString());

            //FranchiseFeeInformation fran = new FranchiseFeeInformation();
            //TryUpdateModel(fran);
            //if (ModelState.IsValid)
            //{
            DateTime DateStart = Convert.ToDateTime(formcollection["StartDate"].ToString());
            DateTime EndDate   = Convert.ToDateTime(formcollection["EndDate"].ToString());
            string   BillMode  = formcollection["BillMode"];
            int      DueOn     = Convert.ToInt32(formcollection["DueOn"].ToString());
            decimal  Amount    = Convert.ToDecimal(formcollection["Amount"].ToString());

            if (isEdit != "True")
            {
                FranchiseFeeInformation franchiseFeeInformation = new FranchiseFeeInformation();
                franchiseFeeInformation.CompanyId     = CompanyId;
                franchiseFeeInformation.Amount        = Amount;
                franchiseFeeInformation.BillMode      = BillMode;
                franchiseFeeInformation.DueOn         = DueOn;
                franchiseFeeInformation.StartDate     = DateStart;
                franchiseFeeInformation.EndDate       = EndDate;
                franchiseFeeInformation.BillingMonths = formcollection["billingMonths"];
                //franchiseFeeInformation.BillingMonths = "1,2,3,4,5,6,7,8,9,10,11,12";
                franchiseFeeInformation.CreatedBy  = userid;
                franchiseFeeInformation.CreateDate = DateTime.Now;

                db.FranchiseFeeInformation.Add(franchiseFeeInformation);
                db.SaveChanges();
                TempData["TransactionSuccess"] = "Add";
                SL.LogInfo(User.Identity.Name, Request.RawUrl, "Data Entry Franchise - Franchise Information Added  - from Terminal: " + ipaddress);
                ViewBag.ValidatePostback = "True";
            }
            else
            {
                int FranchiseFeeInformationId = Convert.ToInt32(formcollection["FranchiseFeeInformationId"].ToString());
                FranchiseFeeInformation franchiseFeeInformation = new FranchiseFeeInformation();
                franchiseFeeInformation = db.FranchiseFeeInformation.Where(m => m.FranchiseFeeInformationId == FranchiseFeeInformationId).FirstOrDefault();

                franchiseFeeInformation.Amount        = Amount;
                franchiseFeeInformation.BillMode      = BillMode;
                franchiseFeeInformation.DueOn         = DueOn;
                franchiseFeeInformation.StartDate     = DateStart;
                franchiseFeeInformation.EndDate       = EndDate;
                franchiseFeeInformation.BillingMonths = formcollection["billingMonths"];
                //franchiseFeeInformation.BillingMonths = "1,2,3,4,5,6,7,8,9,10,11,12";
                franchiseFeeInformation.UpdatedBy  = userid;
                franchiseFeeInformation.UpdateDate = DateTime.Now;

                db.Entry(franchiseFeeInformation).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
                TempData["TransactionSuccess"] = "Edit";
                ViewBag.ValidatePostback       = "True";
                SL.LogInfo(User.Identity.Name, Request.RawUrl, "Data Entry Franchise - Franchise Information Edit  - from Terminal: " + ipaddress);
            }
            //}
            //else
            //{
            //    ViewBag.ValidatePostback = "False";
            //}
            ViewBag.CompanySelected = "OK";
            SearchFranchiseViewModel searchFranchiseViewModel = new SearchFranchiseViewModel();

            searchFranchiseViewModel.Companies = db.Company.Where(m => m.CompanyID == CompanyId).ToList();
            searchFranchiseViewModel.FranchiseFeeInformations = db.FranchiseFeeInformation.Where(m => m.CompanyId == CompanyId).ToList();

            TempData["SearchFranchiseViewModels"] = searchFranchiseViewModel;



            return(RedirectToAction("ViewFranchiseRPG", "DataEntryFranchise"));
            //return View("ViewFranchise", searchFranchiseViewModel);
        }
        public ActionResult ViewRentals(string SearchInput, FormCollection frm, RentalInformation rentalinfo, string isEdit)
        {
            ApplicationDbContext context = new ApplicationDbContext();
            var    userid    = User.Identity.GetUserId();
            string ZoneGroup = context.Users.FirstOrDefault(m => m.Id == userid).ZoneGroup;

            var username = User.Identity.GetUserName();
            RoleAssignmentMatrix roleAssignmentMatrix = db.RoleAssignmentMatrix.FirstOrDefault(m => m.UserName == username);

            ViewBag.IsValidRole = roleAssignmentMatrix.Rentals;
            //Result of initial search button
            if (!string.IsNullOrEmpty(SearchInput))
            {
                SearchCompany searchcompany1 = new SearchCompany();
                searchcompany1.SearchInput = SearchInput.ToString();
                List <Company> NewCompanies = new List <Company>();
                NewCompanies = db.Company.SqlQuery("Select * from Companies where CompanyName like '%" + SearchInput + "%'").ToList();
                SearchCompanyPerGroup searchCompanyPerGroup = new SearchCompanyPerGroup(NewCompanies, ZoneGroup);
                searchcompany1.CompanyList = searchCompanyPerGroup.Companies;
                //searchcompany1.CompanyList = db.Company.SqlQuery("Select * from Companies where CompanyName like '%" + SearchInput + "%' and ZoneGroup").ToList();

                ViewBag.CompanySelected = "";
                return(View(searchcompany1));
            }
            //Result of selected company shown by "Search button"
            else if (frm.Count == 2)
            {
                int           OutParseValue;
                bool          CanParse       = int.TryParse(frm[1].ToString(), out OutParseValue);
                SearchCompany searchcompany1 = new SearchCompany();

                if (CanParse)
                {
                    int ParsedCompanyID = int.Parse(frm[1].ToString());
                    searchcompany1.RentalInformationList = db.RentalInformation.Where(m => m.CompanyId == ParsedCompanyID).ToList();
                    searchcompany1.CompanyList           = db.Company.Where(m => m.CompanyID == ParsedCompanyID).ToList();
                    searchcompany1.BillingRate           = db.BillingRates.Where(m => m.Category == "Rental Fee").Where(m => m.ZoneGroup == ZoneGroup).ToList();

                    var bill = searchcompany1.BillingRate.GroupBy(m => m.SubCategory).ToList();
                    foreach (var item in bill)
                    {
                        searchcompany1.SubCategory.Add(item.Key.ToString());
                    }
                    SL.LogInfo(User.Identity.Name, Request.RawUrl, "Data Entry Rental - Search Company  - from Terminal: " + ipaddress);
                    ViewBag.CompanySelected = "OK";
                }
                else
                {
                    ViewBag.CompanySelected = "";
                }


                return(View(searchcompany1));
            }
            else if (isEdit == "True") //Edit transaction
            {
                var area    = frm["Area"].Split(',');
                var newArea = "";
                foreach (var item in area)
                {
                    newArea = newArea + item;
                }
                RentalInformation rent = new RentalInformation();
                int CompanyID          = int.Parse(frm["CompanyID"].ToString());
                //TryUpdateModel(rent);
                //if (ModelState.IsValid)
                //{
                RentalInformation rentinfo = null;
                int ParsedIntRentID        = int.Parse(frm["rentID"]);
                rentinfo = db.RentalInformation.Find(ParsedIntRentID);

                if (rentinfo != null)
                {
                    rentinfo.Type          = frm["Type"].ToString();
                    rentinfo.Rate          = decimal.Parse(frm["Rate"]);
                    rentinfo.Area          = Math.Round(decimal.Parse(newArea), 2);
                    rentinfo.Amount        = Math.Round(decimal.Parse(frm["Rate"]) * decimal.Parse(frm["Area"]), 2);
                    rentinfo.StartDate     = DateTime.Parse(frm["StartDate"].ToString());
                    rentinfo.EndDate       = DateTime.Parse(frm["EndDate"].ToString());
                    rentinfo.BillMode      = frm["BillMode"].ToString();
                    rentinfo.DueOn         = int.Parse(frm["DueOn"]);
                    rentinfo.BillingMonths = frm["billingMonths"];
                    //rentinfo.BillingMonths = "1,2,3,4,5,6,7,8,9,10,11,12";
                    rentinfo.Currency        = frm["Currency"].ToString();
                    rentinfo.UpdateDate      = DateTime.Now;
                    rentinfo.UpdatedBy       = userid;
                    db.Entry(rentinfo).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                    ViewBag.ValidatePostback = "True";
                    SL.LogInfo(User.Identity.Name, Request.RawUrl, "Data Entry Rental - Edit  - from Terminal: " + ipaddress);
                    TempData["TransactionSuccess"] = "Edit";
                    //ViewBag.TransactionSuccess = "Edit";
                }
                //}
                else
                {
                    ViewBag.ValidatePostback = "False";
                }

                SearchCompany searchcompany = new SearchCompany();
                searchcompany.RentalInformationList = db.RentalInformation.Where(m => m.CompanyId == CompanyID).ToList();
                searchcompany.CompanyList           = db.Company.Where(m => m.CompanyID == CompanyID).ToList();
                searchcompany.BillingRate           = db.BillingRates.Where(m => m.Category == "Rental Fee").Where(m => m.ZoneGroup == ZoneGroup).ToList();

                var bill = searchcompany.BillingRate.GroupBy(m => m.SubCategory).ToList();

                foreach (var item in bill)
                {
                    searchcompany.SubCategory.Add(item.Key);
                }
                ViewBag.CompanySelected = "OK";

                TempData["SearchCompany"] = searchcompany;
                return(RedirectToAction("ViewRentalsRPG", "DataEntryRental"));
                //return View(searchcompany);
            }
            //If returned key/value pairs is > 3. "Add transaction is invoked
            else if (frm.Count > 3)
            {
                int     OutIntParse;
                decimal OutDecimalParse;
                bool    canParse        = int.TryParse(frm["CompanyID"].ToString(), out OutIntParse);
                int     parsedCompanyID = (canParse) ? int.Parse(frm["CompanyID"].ToString()) : 0;
                //int ParsedIntRentID = int.Parse(frm["RentalInformationId"]);
                RentalInformation rent = new RentalInformation();
                TryUpdateModel(rent);
                //var errors = ModelState.Values.SelectMany(v => v.Errors);
                //UpdateModel<IRentalInformation>(rent);
                //if (ModelState.IsValid)
                //{
                try
                {
                    var r       = frm["Rate"].ToString();
                    var s       = r.Split(',');
                    var newRate = "";
                    foreach (var item in s)
                    {
                        newRate += item;
                    }
                    decimal rate = Math.Round((decimal.TryParse(newRate, out OutDecimalParse)) ? decimal.Parse(newRate) : 0, 2);
                    decimal area = Math.Round((decimal.TryParse(frm["Area"].ToString(), out OutDecimalParse)) ? decimal.Parse(frm["Area"].ToString()) : 0, 2);
                    decimal amt  = Math.Round(rate * area, 2);

                    int RentalBillMode = (int.TryParse(frm["BillMode"].ToString(), out OutIntParse)) ? int.Parse(frm["BillMode"].ToString()) : 0;

                    RentalInformation rentalinformation = new RentalInformation();

                    rentalinformation.CompanyId = parsedCompanyID;
                    rentalinformation.Type      = frm["Type"].ToString();
                    rentalinformation.Rate      = rate;
                    rentalinformation.Area      = area;

                    string str = frm["StartDate"].ToString();

                    rentalinformation.StartDate = Convert.ToDateTime(frm["StartDate"].ToString());
                    rentalinformation.EndDate   = Convert.ToDateTime(frm["EndDate"].ToString());
                    //rentalinformation.BillMode = (int.TryParse(frm["BillMode"].ToString(), out OutIntParse)) ? int.Parse(frm["BillMode"].ToString()) : 0;
                    rentalinformation.BillMode = frm["BillMode"].ToString();
                    rentalinformation.DueOn    = (int.TryParse(frm["DueOn"].ToString(), out OutIntParse)) ? int.Parse(frm["DueOn"].ToString()) : 0;

                    rentalinformation.BillingMonths = frm["billingMonths"];
                    //rentalinformation.BillingMonths = "1,2,3,4,5,6,7,8,9,10,11,12";
                    rentalinformation.CreatedDate = DateTime.Now;
                    rentalinformation.Amount      = amt;
                    rentalinformation.Currency    = frm["Currency"].ToString();
                    rentalinformation.CreatedBy   = userid;

                    db.RentalInformation.Add(rentalinformation);
                    db.SaveChanges();
                    SL.LogInfo(User.Identity.Name, Request.RawUrl, "Data Entry Rental - Add - from Terminal: " + ipaddress);
                    TempData["TransactionSuccess"] = "Add";
                    //ViewBag.TransactionSuccess = "Add";
                    ViewBag.ValidatePostback = "True";
                }
                catch (Exception)
                {
                    ViewBag.ValidatePostback = "False";
                }
                //}
                //else
                //{
                //    ViewBag.ValidatePostback = "False";
                //}


                ViewBag.CompanySelected = "OK";
                SearchCompany searchcompany = new SearchCompany();
                searchcompany.RentalInformationList = db.RentalInformation.Where(m => m.CompanyId == parsedCompanyID).ToList();
                searchcompany.CompanyList           = db.Company.Where(m => m.CompanyID == parsedCompanyID).ToList();
                searchcompany.BillingRate           = db.BillingRates.Where(m => m.Category == "Rental Fee").Where(m => m.ZoneGroup == ZoneGroup).ToList();

                var bill = searchcompany.BillingRate.GroupBy(m => m.SubCategory).ToList();

                foreach (var item in bill)
                {
                    searchcompany.SubCategory.Add(item.Key);
                }

                TempData["SearchCompany"] = searchcompany;
                return(RedirectToAction("ViewRentalsRPG", "DataEntryRental"));
                //return View(searchcompany);
            }
            //Default value
            else
            {
                SearchCompany searchcompany1 = new SearchCompany();
                return(View(searchcompany1));
            }
        }
        public ActionResult AddMeter(FormCollection frm)
        {
            var    userid    = User.Identity.GetUserId();
            string ZoneGroup = context.Users.FirstOrDefault(m => m.Id == userid).ZoneGroup;
            var    username  = User.Identity.GetUserName();
            RoleAssignmentMatrix roleAssignmentMatrix = db.RoleAssignmentMatrix.FirstOrDefault(m => m.UserName == username);

            ViewBag.IsValidRole = roleAssignmentMatrix.Water;

            string isEdit    = frm["isEdit"].ToString();
            int    CompanyID = int.Parse(frm["CompanyID"].ToString());
            SearchWaterViewModel SearchWaterViewModels = new SearchWaterViewModel();

            WaterMeterAssignment waterMeterAssignment = new WaterMeterAssignment();

            TryUpdateModel(waterMeterAssignment);
            if (ModelState.IsValid)
            {
                if (string.IsNullOrEmpty(isEdit) || isEdit != "True")
                {
                    string   MeterNumber      = frm["MeterNumber"].ToString();
                    DateTime StartDate        = Convert.ToDateTime(frm["StartDate"].ToString());
                    DateTime EndDate          = Convert.ToDateTime(frm["EndDate"].ToString());
                    string   Size             = frm["Size"].ToString();
                    string   Phase            = frm["Phase"].ToString();
                    int      IncludeInBilling = frm["IncludeInBilling"].ToString() == "YES" ? 1 : 0;

                    DateTime             MeterNumberEndDate  = new DateTime();
                    WaterMeterAssignment tempMeterAssignment = new WaterMeterAssignment();
                    tempMeterAssignment = db.WaterMeterAssignment.Where(m => m.MeterNumber == MeterNumber).FirstOrDefault();
                    if (tempMeterAssignment != null)
                    {
                        MeterNumberEndDate = tempMeterAssignment.EndDate;
                    }

                    if (MeterNumberEndDate < StartDate)
                    {
                        waterMeterAssignment.CompanyId      = CompanyID;
                        waterMeterAssignment.MeterNumber    = MeterNumber;
                        waterMeterAssignment.StartDate      = Convert.ToDateTime(StartDate);
                        waterMeterAssignment.EndDate        = Convert.ToDateTime(EndDate);
                        waterMeterAssignment.Size           = Size;
                        waterMeterAssignment.Phase          = Phase;
                        waterMeterAssignment.Createdby      = userid;
                        waterMeterAssignment.CreateDate     = DateTime.Now;
                        waterMeterAssignment.IncludeBilling = IncludeInBilling;

                        db.WaterMeterAssignment.Add(waterMeterAssignment);
                        db.SaveChanges();
                        //ViewBag.TransactionSuccess = "Add";
                        SL.LogInfo(User.Identity.Name, Request.RawUrl, "Data Entry Water - Add Meter  - from Terminal: " + ipaddress);
                        TempData["TransactionSuccess"] = "Add";
                        ViewBag.ValidatePostback       = "True";
                    }
                    else
                    {
                        TempData["TransactionSuccess"] = "MeterNumberExist";
                        ViewBag.ValidatePostback       = "False";
                    }
                }
                else
                {
                    int waterAssignmentId = int.Parse(frm["wid"].ToString());
                    WaterMeterAssignment waterMeterAssignmentEdit = new WaterMeterAssignment();
                    string   MeterNumber      = frm["MeterNumber"].ToString();
                    DateTime StartDate        = Convert.ToDateTime(frm["StartDate"].ToString());
                    DateTime EndDate          = Convert.ToDateTime(frm["EndDate"].ToString());
                    string   Size             = frm["Size"].ToString();
                    string   Phase            = frm["Phase"].ToString();
                    int      IncludeInBilling = frm["IncludeInBilling"].ToString() == "YES" ? 1 : 0;
                    waterMeterAssignmentEdit = db.WaterMeterAssignment.Where(m => m.WaterMeterAssignmentId == waterAssignmentId).Single();

                    waterMeterAssignmentEdit.MeterNumber = MeterNumber;
                    waterMeterAssignmentEdit.StartDate   = Convert.ToDateTime(StartDate);
                    waterMeterAssignmentEdit.EndDate     = Convert.ToDateTime(EndDate);
                    waterMeterAssignmentEdit.Size        = Size;
                    waterMeterAssignmentEdit.Phase       = Phase;

                    waterMeterAssignmentEdit.UpdatedBy      = userid;
                    waterMeterAssignmentEdit.UpdateDate     = DateTime.Now;
                    waterMeterAssignmentEdit.IncludeBilling = IncludeInBilling;

                    db.Entry(waterMeterAssignmentEdit).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                    ViewBag.ValidatePostback = "True";
                    //ViewBag.TransactionSuccess = "Edit";
                    SL.LogInfo(User.Identity.Name, Request.RawUrl, "Data Entry Water - Edit Meter  - from Terminal: " + ipaddress);
                    TempData["TransactionSuccess"] = "Edit";
                }
            }
            else
            {
                ViewBag.ValidatePostback = "False";
            }

            ViewBag.CompanySelected                     = "OK";
            SearchWaterViewModels.Companies             = db.Company.Where(m => m.CompanyID == CompanyID).ToList();
            SearchWaterViewModels.WaterMeterAssignments = db.WaterMeterAssignment.Where(m => m.CompanyId == CompanyID).ToList();

            SearchWaterViewModels.BillingPeriods = BillingPeriods();

            TempData["WaterAssignmentData"] = SearchWaterViewModels;

            SL.LogInfo(User.Identity.Name, Request.RawUrl, "Data Entry Water - Meter Added  - from Terminal: " + ipaddress);

            return(RedirectToAction("ViewWaterPRG", "DataEntryWater"));
            //return View("ViewWater", SearchWaterViewModels);
        }
        public ActionResult UpdateCompany(FormCollection frmcollection)
        {
            ApplicationDbContext context = new ApplicationDbContext();
            var     userid             = User.Identity.GetUserId();
            string  ZoneGroup          = context.Users.FirstOrDefault(m => m.Id == userid).ZoneGroup;
            int     SingleZoneGroupId  = db.ZoneGroup.FirstOrDefault(d => d.ZoneGroupCode == ZoneGroup).ZoneGroupId;
            Company compinfo           = null;
            int     ParsedIntCompanyID = int.Parse(frmcollection["CompanyID"]);

            compinfo = db.Company.Find(ParsedIntCompanyID);
            SearchCompany  searchcompany1 = new SearchCompany();
            List <Company> NewCompanies   = new List <Company>();

            if (compinfo != null)
            {
                //compinfo.CompanyCode = frmcollection["CompanyCode"].ToString();
                compinfo.CompanyName           = frmcollection["CompanyName"].ToString();
                compinfo.Phase                 = frmcollection["Phase"].ToString();
                compinfo.Address               = frmcollection["Address"].ToString();
                searchcompany1.ZoneList        = db.Zone.Where(x => x.ZoneGroup == SingleZoneGroupId.ToString()).ToList();
                searchcompany1.BillingRateList = db.BillingRates.Select(z => z).ToList();
                compinfo.UpdateDate            = DateTime.Now.Date;
                compinfo.Status                = frmcollection["Status"].ToString();
                compinfo.OwnershipType         = frmcollection["EditOwnershipType"].ToString();
                compinfo.EnterpriseType        = frmcollection["EnterpriseType"].ToString();
                compinfo.SendEmail             = frmcollection["SendEmail"].ToString();
                compinfo.PrimaryEmailAddress   = frmcollection["EmailAddress"].ToString();
                compinfo.SecondaryEmailAddress = frmcollection["SecondaryEmailAddress"].ToString();
                if (frmcollection["Vatable"].ToString() == "YES")
                {
                    compinfo.Vat          = 12;
                    compinfo.VatableItems = frmcollection["Vatable"].ToString();
                }
                else if (frmcollection["Vatable"].ToString() == "NO")
                {
                    compinfo.VatableItems = "NO";
                }
                else
                {
                    compinfo.VatableItems = "";
                }
                try
                {
                    compinfo.DateOfRegistration = Convert.ToDateTime(frmcollection["EditDateOfRegistration"].ToString());
                }
                catch { }
                if (searchcompany1.ZoneList.Count != 0)
                {
                    compinfo.ZoneCode = frmcollection["ZoneCode"].ToString();
                }
                try
                {
                    if (searchcompany1.BillingRateList.Count != 0)
                    {
                        compinfo.WithHolding = frmcollection["WithHolding"].ToString();
                    }
                }
                catch (Exception)
                {
                    //compinfo.VatableItems = null;
                    compinfo.WithHolding     = null;
                    db.Entry(compinfo).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                }
                finally
                {
                    db.Entry(compinfo).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                }
            }
            else
            {
                Response.Write("<script> alert('Update Failed!') </script>");
                TempData["IsSuccess"] = false;
            }
            int           parsedCompanyID = int.Parse(frmcollection["CompanyID"]);
            SearchCompany searchcompany   = new SearchCompany();
            int           CompId          = Convert.ToInt32(frmcollection["CompanyID"]);

            //NewCompanies = db.Company.Select(x => x).OrderBy(x => x.CompanyName).Take(10).ToList();
            NewCompanies = db.Company.Where(x => x.CompanyID == CompId).ToList();
            SearchCompanyPerGroup searchCompanyPerGroup = new SearchCompanyPerGroup(NewCompanies, ZoneGroup);

            searchcompany.CompanyList      = searchCompanyPerGroup.Companies;
            searchcompany.ZoneList         = db.Zone.Where(x => x.ZoneGroup == SingleZoneGroupId.ToString()).ToList();
            TempData["IsSuccess"]          = true;
            TempData["TransactionSuccess"] = "Edit";
            TempData["searchcompany"]      = searchcompany;
            TempData["SelectedCompany"]    = "COMPHIDE";
            return(RedirectToAction("ViewCompany", "MaintenanceCompany"));
        }
Example #14
0
        public ActionResult AddSubCategory(string SubCategory, string Category, string Currency, string SubCat, string TransactionType, string NGAS)
        {
            var    userid    = User.Identity.GetUserId();
            var    username  = User.Identity.GetUserName();
            string ZoneGroup = context.Users.SingleOrDefault(m => m.Id == userid).ZoneGroup;
            RoleAssignmentMatrix roleAssignmentMatrix = db.RoleAssignmentMatrix.SingleOrDefault(m => m.UserName == username);

            ViewBag.IsValidRole = roleAssignmentMatrix.Rate;
            ViewBag.Groups      = db.ZoneGroup.ToList();
            SearchBillingAndCollectionRates searchBillingAndCollectionRates = new SearchBillingAndCollectionRates();

            if (TransactionType.ToUpper() == "ADD") //Add sub category
            {
                if (!string.IsNullOrEmpty(SubCategory))
                {
                    List <BillingRate> billrate = db.BillingRates.Where(m => m.Category.ToUpper() == Category.ToUpper() &&
                                                                        m.SubCategory.ToUpper() == SubCategory.ToUpper() && m.ZoneGroup == ZoneGroup).ToList();

                    if (Category.ToUpper() == "SEWERAGE")
                    {
                        TempData["TransactionSuccess"] = "ErrorSewerage";
                    }
                    else
                    {
                        BillingRate billingRate = new BillingRate();
                        billingRate.Category  = Category;
                        billingRate.ZoneGroup = ZoneGroup;
                        billingRate.NGASCode  = NGAS;

                        if (Category != "Rental Fee") //If billing rate. add prefix currency.
                        {
                            billingRate.SubCategory = SubCategory;
                        }
                        else
                        {
                            billingRate.SubCategory = Currency + " " + SubCategory;
                        }

                        billingRate.Rate = 0;

                        db.BillingRates.Add(billingRate);
                        db.SaveChanges();
                        TempData["TransactionSuccess"] = "Add";
                    }
                }

                searchBillingAndCollectionRates.BillingRate = db.BillingRates.Where(m => m.Category == Category).ToList();
                var bill   = db.BillingRates.Where(x => x.ZoneGroup == ZoneGroup).GroupBy(m => m.Category).Select(g => new { Category = g.Key }).ToList();
                var subcat = db.BillingRates.Where(x => x.ZoneGroup == ZoneGroup).Where(m => m.Category == Category).GroupBy(m => m.SubCategory).Select(g => new { SubCategory = g.Key }).ToList();

                foreach (var item in bill)
                {
                    searchBillingAndCollectionRates.Category.Add(item.Category);
                }

                foreach (var item in subcat)
                {
                    searchBillingAndCollectionRates.SubCategory.Add(item.SubCategory);
                }
            }
            else if (TransactionType.ToUpper() == "EDIT") // Modify subcategory
            {
                if (!string.IsNullOrEmpty(SubCategory))
                {
                    BillingRate billingRate = new BillingRate();
                    //billingRate = db.BillingRates.Where(x => x.ZoneGroup == ZoneGroup).Where(m => m.Category == Category).Where(m => m.SubCategory == SubCat).Single();
                    billingRate = db.BillingRates.FirstOrDefault(x => x.ZoneGroup == ZoneGroup && x.Category == Category && x.SubCategory == SubCat);
                    if (Category != "Rental Fee") //If billing rate. add prefix currency.
                    {
                        billingRate.SubCategory = SubCategory;
                        billingRate.NGASCode    = NGAS;
                    }
                    else
                    {
                        billingRate.SubCategory = Currency + " " + SubCategory;
                        billingRate.NGASCode    = NGAS;
                    }


                    db.Entry(billingRate).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                    TempData["TransactionSuccess"] = "Edit";
                }
                else
                {
                    Response.Write("<script>alert('Unable to edit SubCategory. Please check blank field.')</script>");
                }

                searchBillingAndCollectionRates.BillingRate = db.BillingRates.Where(m => m.Category == Category).ToList();
                var bill   = db.BillingRates.Where(x => x.ZoneGroup == ZoneGroup).GroupBy(m => m.Category).Select(g => new { Category = g.Key }).ToList();
                var subcat = db.BillingRates.Where(x => x.ZoneGroup == ZoneGroup).Where(m => m.Category == Category).GroupBy(m => m.SubCategory).Select(g => new { SubCategory = g.Key }).ToList();

                foreach (var item in bill)
                {
                    searchBillingAndCollectionRates.Category.Add(item.Category);
                }

                foreach (var item in subcat)
                {
                    searchBillingAndCollectionRates.SubCategory.Add(item.SubCategory);
                }
            }
            ViewBag.Category = Category;
            TempData["searchBillingAndCollectionRates"] = searchBillingAndCollectionRates;
            TempData["Category"] = Category;
            return(RedirectToAction("ViewBillingAndCollectionRatesRPG", "MaintenanceBillingAndCollectionRates"));
            //return View("ViewBillingAndCollectionRates", searchBillingAndCollectionRates);
        }