Esempio n. 1
0
        public void ProcessRequest(HttpContext context)
        {
            if (context.Request.Files.Count > 0)
            {
                BCS_Context          db    = new BCS_Context();
                ApplicationDbContext appdb = new ApplicationDbContext();
                HttpFileCollection   files = context.Request.Files;
                HttpPostedFile       file  = files["uploadData"];

                var    logUSer        = HttpContext.Current.User.Identity.Name;
                string ZoneGroup      = appdb.Users.FirstOrDefault(m => m.UserName == logUSer).ZoneGroup;
                var    billingPeriod1 = db.BillingPeriod.Where(m => m.groupCode == ZoneGroup).ToList();
                var    billPeriod     = billingPeriod1.Max(m => m.BillingPeriodId);
                if ((file != null) && (file.ContentLength > 0) && !string.IsNullOrEmpty(file.FileName))
                {
                    string filename        = file.FileName;
                    string filecontenttype = file.ContentType;
                    byte[] filebytes       = new byte[file.ContentLength];
                    var    data            = file.InputStream.Read(filebytes, 0, Convert.ToInt32(file.ContentLength));

                    using (var transaction = db.Database.BeginTransaction())
                    {
                        var excelHelper = new Helper.ExcelHelper();
                        List <AssessmentBilling> assessments     = new List <AssessmentBilling>();
                        List <AssessmentBilling> tempAssessments = new List <AssessmentBilling>();
                        db.SaveChanges();
                        try
                        {
                            var prop  = excelHelper.GetProperties(typeof(AssessmentBilling), new[] { "REF_NO", "TRANS_NO", "COMP_CODE", "TRANS_DATE", "RATE_CODE", "RATE_TYPE", "TYPE_DESC", "ACCT_CODE", "NGAS_CODE", "DUE_DATE", "ZONE_CODE", "AMOUNT_DUE", "BILL_PERIOD_MONTH", "BILL_PERIOD_YEAR", "BILL_REFERENCE_NO", "BILL_PERIOD_ID", "BILL_DATE", "BILL_GENERATION_DATE", "CURRENT_BILLING_PERIOD" });
                            var data1 = excelHelper.ReadData <AssessmentBilling>(file.InputStream, file.FileName, prop, billPeriod, "Billing", "");
                            assessments.AddRange(data1);
                            foreach (var item in assessments)
                            {
                                AssessmentBilling assessmentBilling = new AssessmentBilling();
                                assessmentBilling = item;
                                var compId = db.Company.Where(m => m.CompanyCode == item.COMP_CODE).Select(x => (int?)x.CompanyID).FirstOrDefault() ?? 0;
                                assessmentBilling.COMPANY_ID = compId.ToString();
                                tempAssessments.Add(assessmentBilling);
                            }
                            db.AssessmentBilling.AddRange(tempAssessments);
                            db.SaveChanges();
                            transaction.Commit();
                        }
                        catch (Exception ex)
                        {
                            transaction.Rollback();
                        }
                    }
                }
            }
        }
Esempio n. 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));
            }
        }
Esempio n. 3
0
        public PartialViewResult Create(string DivisionCode, string DivisionName)
        {
            IEnumerable <Division> divisions = new List <Division>();
            BCS_Context            db        = new BCS_Context();

            try
            {
                using (var dbtransaction = db.Database.BeginTransaction())
                {
                    Division division = new Division();
                    division.Code = DivisionCode;
                    division.Name = DivisionName;
                    db.Division.Add(division);
                    db.SaveChanges();
                    dbtransaction.Commit();
                    divisions = db.Division.ToList().OrderBy(m => m.Name);

                    SL.LogInfo(User.Identity.Name, Request.RawUrl, "Division - Division Created  - from Terminal: " + ipaddress);

                    return(PartialView("_DivisionPartial", divisions));
                }
            }
            catch (Exception)
            {
                SL.LogInfo(User.Identity.Name, Request.RawUrl, "Division - Create Division failed  - from Terminal: " + ipaddress);
                divisions = db.Division.ToList().OrderBy(m => m.Name);
                return(PartialView("_DivisionPartial", divisions));
            }
        }
        // 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 }));
        }
        // GET: MaintenanceHolidayTable

        public ActionResult ViewHolidayTable(FormCollection frm)
        {
            if (frm.Count == 0)
            {
                SearchHolidayTableViewModel SearchHolidayViewModels = new SearchHolidayTableViewModel();
                SearchHolidayViewModels.HolidayList = db.HolidayTable.SqlQuery("Select * from HolidayTables").ToList();
                return(View(SearchHolidayViewModels));
            }
            else if (frm.Count >= 1)
            {
                int          parsedID = int.Parse(frm["HolidayTableId"]);
                HolidayTable holiday  = db.HolidayTable.Find(parsedID);
                db.HolidayTable.Remove(holiday);
                db.SaveChanges();
                return(RedirectToAction("ViewHolidayTable"));
            }
            return(View());
        }
Esempio n. 6
0
        public ActionResult ViewZoneGroup(FormCollection frm)
        {
            if (frm.Count == 0)
            {
                SearchZoneGroupViewModel SearchZoneGroupViewModels = new SearchZoneGroupViewModel();
                SearchZoneGroupViewModels.ZoneGroupList = db.ZoneGroup.SqlQuery("Select * from ZoneGroups where ZoneGroupCode != '99'").ToList();
                ViewBag.TransactionSuccess = TempData["TransactionSuccess"] as string;
                return(View(SearchZoneGroupViewModels));
            }
            else if (frm.Count >= 1)
            {
                int       parsedID  = int.Parse(frm["ZoneGroupId"]);
                ZoneGroup zonegroup = db.ZoneGroup.Find(parsedID);
                db.ZoneGroup.Remove(zonegroup);

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

                db.SaveChanges();
                return(RedirectToAction("ViewZoneGroup"));
            }
            return(View());
        }
Esempio n. 7
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 void ProcessRequest(HttpContext context)
        {
            var                a          = context.Request.QueryString["Copy"].ToString();
            var                b          = context.Request.QueryString["Type"].ToString();
            var                origin     = context.Request.QueryString["Origin"].ToString();
            var                billing    = context.Request.QueryString["Billing"].ToString();
            DateTime           originNew  = Convert.ToDateTime(origin);
            DateTime           billingNew = Convert.ToDateTime(billing);
            HttpFileCollection files      = context.Request.Files;
            HttpPostedFile     file       = files["uploadData"];

            int copy = int.Parse(a);

            BCS_Context db = new BCS_Context();

            if ((file != null) && (file.ContentLength > 0) && (!string.IsNullOrEmpty(file.FileName)))
            {
                using (var dbtransaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        ApplicationDbContext con = new ApplicationDbContext();
                        //db.PassedOnBillingInformation.RemoveRange(db.PassedOnBillingInformation)
                        var userid    = System.Web.HttpContext.Current.User.Identity.GetUserId();
                        var zonegroup = con.Users.FirstOrDefault(m => m.Id == userid).ZoneGroup;
                        SearchCompanyPerGroup searchCompanyPerGroup = new SearchCompanyPerGroup(zonegroup);
                        IEnumerable <Company> company = searchCompanyPerGroup.Companies;
                        using (var package = new ExcelPackage(file.InputStream))
                        {
                            var currentSheet = package.Workbook.Worksheets;
                            var workSheet    = currentSheet.First();
                            var noOfCol      = workSheet.Dimension.End.Column;
                            var noOfRow      = workSheet.Dimension.End.Row;

                            for (int rowIterator = 12; rowIterator <= noOfRow; rowIterator++)
                            {
                                var     compid    = workSheet.Cells[rowIterator, 3].Value;
                                var     newCompId = int.Parse(compid.ToString());
                                Company comp      = company.Where(m => m.CompanyID == newCompId).FirstOrDefault();
                                var     type      = workSheet.Cells[rowIterator, 12].Value.ToString() != null ? workSheet.Cells[rowIterator, 12].Value.ToString() : "";

                                if (type == b)
                                {
                                    PassedOnBillingInformation passedOnBillingInformation = new PassedOnBillingInformation();
                                    passedOnBillingInformation.Type = type;
                                    var cid = workSheet.Cells[rowIterator, 3].Value != null ? workSheet.Cells[rowIterator, 3].Value : 0;
                                    passedOnBillingInformation.CompanyId     = int.Parse(cid.ToString());
                                    passedOnBillingInformation.BillingPeriod = int.Parse(a);
                                    var amt = workSheet.Cells[rowIterator, 13].Value != null ? workSheet.Cells[rowIterator, 13].Value : 0;
                                    passedOnBillingInformation.Amount      = decimal.Parse(amt.ToString());
                                    passedOnBillingInformation.CreatedBy   = userid;
                                    passedOnBillingInformation.CreateDate  = DateTime.Now;
                                    passedOnBillingInformation.OriginDate  = originNew;
                                    passedOnBillingInformation.BillingDate = billingNew;
                                    passedOnBillingInformation.Remarks     = workSheet.Cells[rowIterator, 14].ToString();

                                    db.PassedOnBillingInformation.Add(passedOnBillingInformation);
                                    db.SaveChanges();
                                }
                            }
                        }
                        dbtransaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        var error = ex.Message;
                        dbtransaction.Rollback();
                    }
                }
            }
        }
        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);
        }
Esempio n. 10
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);
        }
Esempio n. 11
0
        public List <T> ReadData <T>(Stream stream, string fileName, List <PropertyInfo> columns, int billperiod, string uploadType, string uploadtype2)
        {
            var list = new List <T>();

            if (fileName.EndsWith("xls"))
            {
                var workbook = new HSSFWorkbook(stream);
                var sheet    = workbook.GetSheetAt(0);

                if (sheet.PhysicalNumberOfRows <= 1)
                {
                    return(list);
                }

                if (uploadType == "Billing")
                {
                    var         test1 = sheet.GetRow(1).GetCell(3).ToString();
                    BCS_Context db    = new BCS_Context();
                    var         lst   = db.AssessmentBilling.Where(m => m.TRANS_DATE == test1).ToList();
                    db.Database.ExecuteSqlCommand("Delete from AssessmentBillings where TRANS_DATE = '" + test1 + "'");
                    //db.AssessmentBilling.RemoveRange(lst);
                    db.SaveChanges();
                }
                else if (uploadType == "Payment")
                {
                    var         test1 = sheet.GetRow(1).GetCell(8).ToString();
                    BCS_Context db    = new BCS_Context();
                    var         lst   = db.AssessmentPayment.Where(m => m.OR_DATE == test1).ToList();
                    db.Database.ExecuteSqlCommand("Delete from AssessmentPayments where OR_DATE = '" + test1 + "'");
                    //db.AssessmentPayment.RemoveRange(lst);
                    db.SaveChanges();
                }
                //else if (uploadType == "Admin")
                //{
                //    BCS_Context db = new BCS_Context();
                //    var lst = db.AdminFee.Where(m => m.BillingPeriodId == billperiod).ToList();
                //    db.Database.ExecuteSqlCommand("delete from AdminFees where BillingPeriodId = '" + billperiod + "'");
                //    //db.AdminFee.RemoveRange(lst);
                //    db.SaveChanges();
                //}



                for (int i = 1; i < sheet.PhysicalNumberOfRows; i++)
                {
                    var item = Activator.CreateInstance <T>();

                    var row = sheet.GetRow(i);

                    var j = 0;

                    foreach (var column in columns)
                    {
                        if (j == row.Cells.Count)
                        {
                            Type t2 = Nullable.GetUnderlyingType(column.PropertyType) ?? column.PropertyType;
                            column.SetValue(item, Convert.ChangeType(billperiod, t2), null);

                            Type t3 = Nullable.GetUnderlyingType(columns[14].PropertyType) ?? columns[14].PropertyType;
                            columns[14].SetValue(item, Convert.ChangeType(uploadtype2, t3), null);

                            break;
                        }

                        var val = row.GetCell(j).ToString();
                        if (val == "AYALA LAND INC")
                        {
                        }
                        if (val.Contains("\n"))
                        {
                            val = val.Substring(0, val.Length - 1);
                        }

                        j++;

                        if (string.IsNullOrWhiteSpace(val))
                        {
                            continue;
                        }
                        Type t = Nullable.GetUnderlyingType(column.PropertyType) ?? column.PropertyType;
                        column.SetValue(item, Convert.ChangeType(val, t), null);
                    }

                    list.Add(item);
                }
            }
            else if (fileName.EndsWith("xlsx"))
            {
                var workbook = new XSSFWorkbook(stream);
                var sheet    = workbook.GetSheetAt(0);

                for (int i = 0; i < sheet.PhysicalNumberOfRows; i++)
                {
                    var item = Activator.CreateInstance <T>();

                    var row = sheet.GetRow(i);

                    var j = 0;

                    foreach (var column in columns)
                    {
                        var val = row.GetCell(j).StringCellValue;

                        if (string.IsNullOrWhiteSpace(val))
                        {
                            continue;
                        }
                        Type t = Nullable.GetUnderlyingType(column.PropertyType) ?? column.PropertyType;
                        column.SetValue(item, Convert.ChangeType(val, t), null);

                        j++;
                    }

                    list.Add(item);
                }
            }

            return(list);
        }
Esempio n. 12
0
        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"));
        }
        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));
        }
        public ActionResult ViewCompany(string SearchInput, string Rate, FormCollection frm)
        {
            SearchCompany        searchcompany  = new SearchCompany();
            SearchCompany        searchcompany1 = new SearchCompany();
            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;

            //Result of initial search button
            if (!string.IsNullOrEmpty(SearchInput))
            {
                searchcompany1.SearchInput = SearchInput.ToString();
                List <Company> NewCompanies = new List <Company>();
                NewCompanies = db.Company.Where(x => x.CompanyName.Contains(SearchInput)).ToList().OrderBy(x => x.CompanyName).ToList();
                SearchCompanyPerGroup searchCompanyPerGroup = new SearchCompanyPerGroup(NewCompanies, ZoneGroup);
                searchcompany1.CompanyList = searchCompanyPerGroup.Companies;
                searchcompany1.ZoneList    = db.Zone.Where(x => x.ZoneGroup == SingleZoneGroupId.ToString()).ToList();
                ViewBag.SelectedCompany    = "COMPSHOW";
                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);
                if (CanParse)
                {
                    int            ParsedCompanyID = int.Parse(frm[1].ToString());
                    List <Company> NewCompanies    = new List <Company>();
                    NewCompanies = db.Company.Where(m => m.CompanyID == ParsedCompanyID).ToList();
                    SearchCompanyPerGroup searchCompanyPerGroup = new SearchCompanyPerGroup(NewCompanies, ZoneGroup);
                    searchcompany1.CompanyList = searchCompanyPerGroup.Companies;
                }
                var bill = db.BillingRates.GroupBy(m => m.Category).Select(g => new { Category = g.Key }).ToList();
                foreach (var item in bill)
                {
                    searchcompany1.Category.Add(item.Category);
                }
                searchcompany1.ZoneList = db.Zone.Where(x => x.ZoneGroup == SingleZoneGroupId.ToString()).ToList();
                ViewBag.SelectedCompany = "COMPHIDE";
                return(View(searchcompany1));
            }
            //If returned key/value pairs is > 3. "Add transaction is invoked
            else if (frm.Count > 3)
            {
                SL.LogInfo(User.Identity.Name, Request.RawUrl, "User Added Item! (Maintenance Company) - from Terminal:" + ipaddress);
                Company companyinfo = new Company();
                var     CompCode    = frm["CompanyCode"].ToString();
                companyinfo.CompanyCode        = frm["CompanyCode"].ToString();
                companyinfo.CompanyName        = frm["CompanyName"].ToString();
                companyinfo.Phase              = frm["Phase"].ToString();
                companyinfo.Address            = frm["Address"].ToString();
                companyinfo.CreateDate         = DateTime.Now.Date;
                companyinfo.Status             = frm["Status"].ToString();
                companyinfo.OwnershipType      = frm["OwnershipType"].ToString();
                companyinfo.EnterpriseType     = frm["EnterpriseType"].ToString();
                searchcompany1.ZoneList        = db.Zone.Where(x => x.ZoneGroup == SingleZoneGroupId.ToString()).ToList();
                searchcompany1.BillingRateList = db.BillingRates.Select(z => z).ToList();

                var vat = frm["Vatable"].ToString();
                if (vat == "YES")
                {
                    companyinfo.VatableItems = "YES";
                    companyinfo.Vat          = 12;
                }
                else
                {
                    companyinfo.VatableItems = "NO";
                }
                try
                {
                    if (searchcompany1.ZoneList.Count != 0)
                    {
                        companyinfo.ZoneCode = frm["ZoneCode"].ToString();
                    }
                }
                catch
                {
                }
                try
                {
                    if (searchcompany1.BillingRateList.Count != 0)
                    {
                        companyinfo.WithHolding = frm["WithHolding"].ToString();
                    }
                }
                catch
                {
                }
                companyinfo.SendEmail             = frm["SendEmail"].ToString();
                companyinfo.PrimaryEmailAddress   = frm["AddEmailAddress"].ToString();
                companyinfo.SecondaryEmailAddress = frm["AddSecondaryEmailAddress"].ToString();
                try
                {
                    companyinfo.DateOfRegistration = Convert.ToDateTime(frm["DateOfRegistration"].ToString());
                }
                catch { }
                db.Company.Add(companyinfo);
                db.SaveChanges();

                var bill = db.BillingRates.GroupBy(m => m.Category).Select(g => new { Category = g.Key }).ToList();
                foreach (var item in bill)
                {
                    searchcompany.Category.Add(item.Category);
                }
                List <Company> NewCompanies = new List <Company>();
                NewCompanies = db.Company.Select(x => x).OrderByDescending(x => x.CompanyID).Take(50).ToList();
                SearchCompanyPerGroup searchCompanyPerGroup = new SearchCompanyPerGroup(NewCompanies, ZoneGroup);
                searchcompany.CompanyList      = searchCompanyPerGroup.Companies;
                searchcompany.ZoneList         = db.Zone.Where(x => x.ZoneGroup == SingleZoneGroupId.ToString()).ToList();
                TempData["TransactionSuccess"] = "Add";
                TempData["searchcompany"]      = searchcompany;
                TempData["SelectedCompany"]    = "COMPHIDE";
                return(RedirectToAction("ViewCompany", "MaintenanceCompany"));
            }
            else
            {
                Response.Write("<script> alert('Invalid Transaction!') </script>");
            }
            //Default value
            //searchcompany.CompanyList = searchcompany.CompanyList.Select(x => x).ToList();
            return(View("ViewCompany"));
            //return View();
        }
Esempio n. 15
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"));
        }
Esempio n. 16
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);
        }
Esempio n. 17
0
        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));
            }
        }
Esempio n. 18
0
        public void ProcessRequest(HttpContext context)
        {
            if (context.Request.Files.Count > 0)
            {
                var                billPeriodFromContext = context.Request.QueryString["billperiod"].ToString();
                var                zoneTypeFromContext   = context.Request.QueryString["zonetype"].ToString();
                int                billPeriod            = int.Parse(billPeriodFromContext);
                BCS_Context        db    = new BCS_Context();
                HttpFileCollection files = context.Request.Files;
                HttpPostedFile     file  = files["uploadData"];
                if ((file != null) && (file.ContentLength > 0) && !string.IsNullOrEmpty(file.FileName))
                {
                    using (var transaction = db.Database.BeginTransaction())
                    {
                        var             excelHelper = new Helper.ExcelHelper();
                        List <AdminFee> adminfees   = new List <AdminFee>();
                        db.AdminFee.RemoveRange(db.AdminFee.Where(m => m.BillingPeriodId == billPeriod && m.Upload_Type.ToUpper().Trim() == zoneTypeFromContext.ToUpper().Trim()).ToList());
                        db.SaveChanges();
                        try
                        {
                            var uname = HttpContext.Current.User.Identity.Name;
                            ApplicationDbContext dbcontext = new ApplicationDbContext();
                            var user   = dbcontext.Users.Where(m => m.UserName == uname).FirstOrDefault();
                            var zone   = user.ZoneGroup;
                            var zoneid = db.ZoneGroup.Where(m => m.ZoneGroupCode == zone).FirstOrDefault().ZoneGroupId;

                            var prop = excelHelper.GetProperties(typeof(AdminFee), new[] { "Ecozone", "Zone_Type", "Company_Name", "Enterprise_Type", "Employment", "Zone_Code", "Month", "Year", "Comp_Code", "Developer", "Dev_Comp_Code", "Total_Locators", "Total_Employment", "BillingPeriodId", "Upload_Type" });
                            var data = excelHelper.ReadData <AdminFee>(file.InputStream, file.FileName, prop, billPeriod, "Admin", zoneTypeFromContext);

                            foreach (var item in data)
                            {
                                var groupId = "";
                                try
                                {
                                    string tempZone = "";
                                    if (zoneTypeFromContext.ToUpper().Trim() != "ALL")
                                    {
                                        if (item.Zone_Type.ToUpper().Trim() == "IT CENTER" || item.Zone_Type.ToUpper().Trim() == "IT PARK")
                                        {
                                            tempZone = "IT";
                                        }
                                        else if (item.Zone_Type.ToUpper().Trim() != "IT CENTER" && item.Zone_Type.ToUpper().Trim() != "IT PARK" && item.Zone_Type.ToUpper().Trim() != "MANUFACTURING CEZ")
                                        {
                                            tempZone = "OTHERS";
                                        }
                                        else if (item.Zone_Type.ToUpper().Trim() == "MANUFACTURING SEZ")
                                        {
                                            tempZone = "MANUFACTURING";
                                        }
                                        else
                                        {
                                            tempZone = item.Zone_Type.ToUpper().Trim();
                                        }
                                        //tempZone = item.Zone_Type.ToUpper().Trim() == "IT CENTER" || item.Zone_Type.ToUpper().Trim() == "IT PARK" ?
                                        //    "IT" : item.Zone_Type.ToUpper().Trim();

                                        //tempZone = item.Zone_Type.ToUpper().Trim() != "IT CENTER" && item.Zone_Type.ToUpper().Trim() != "IT PARK" && item.Zone_Type.ToUpper().Trim() != "MANUFACTURING CEZ" ?
                                        //    "OTHERS" : item.Zone_Type.ToUpper().Trim();

                                        //tempZone = item.Zone_Type.ToUpper().Trim() == "MANUFACTURING CEZ" ?
                                        //    "MANUFACTURING" : item.Zone_Type.ToUpper().Trim();
                                    }

                                    if (tempZone == zoneTypeFromContext.ToUpper().Trim())
                                    {
                                        try
                                        {
                                            var zoneCode = db.Company.Where(m => m.CompanyCode == item.Dev_Comp_Code).FirstOrDefault().ZoneCode ?? "";
                                            if (zoneCode != null || zoneCode != "")
                                            {
                                                groupId = db.Zone.Where(m => m.ZoneCode == zoneCode).FirstOrDefault().ZoneGroup ?? "";
                                            }
                                        }
                                        catch (Exception)
                                        {
                                            IOHelper.LogTxt(item.Dev_Comp_Code, billPeriodFromContext, zoneTypeFromContext);
                                            //throw new Exception("Zone code is has no match in current record " + item.Dev_Comp_Code);
                                        }
                                    }
                                    else
                                    {
                                        throw new Exception("Missmatch zone type " + tempZone);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    throw new Exception(ex.Message);
                                }

                                if (groupId == zoneid.ToString())
                                {
                                    adminfees.Add(item);
                                }
                            }

                            db.AdminFee.AddRange(adminfees);
                            db.SaveChanges();
                            transaction.Commit();
                        }
                        catch (Exception ex)
                        {
                            transaction.Rollback();
                            HttpContext.Current.Response.ContentType = "text/plain";
                            HttpContext.Current.Response.Write(ex.Message);
                            throw new Exception(ex.Message);
                        }
                    }
                }
                //if ((file != null) && (file.ContentLength > 0) && !string.IsNullOrEmpty(file.FileName))
                //    {
                //        string filename = file.FileName;
                //        string filecontenttype = file.ContentType;

                //        byte[] filebytes = new byte[file.ContentLength];
                //        var data = file.InputStream.Read(filebytes, 0, Convert.ToInt32(file.ContentLength));
                //        //int billingPeriodId = Convert.ToInt32(frm["BillingPeriod"].ToString());

                //        List<AdminFee> adminFee = new List<AdminFee>();
                //        using (var transaction = db.Database.BeginTransaction())
                //        {
                //            db.AdminFee.RemoveRange(db.AdminFee.Where(m => m.BillingPeriodId == billPeriod).ToList());
                //            db.SaveChanges();
                //            try
                //            {
                //                using (var package = new ExcelPackage(file.InputStream))
                //                {
                //                    List<String> notRegisteredCompany = new List<string>();
                //                    var currentSheet = package.Workbook.Worksheets;
                //                    var workSheet = currentSheet.First();
                //                    var noOfCol = workSheet.Dimension.End.Column;
                //                    var noOfRow = workSheet.Dimension.End.Row;

                //                    for (int rowIterator = 2; rowIterator <= noOfRow; rowIterator++)
                //                    {
                //                        AdminFee adminfee = new AdminFee();
                //                        adminfee.Ecozone = workSheet.Cells[rowIterator, 1].Value != null ? workSheet.Cells[rowIterator, 1].Value.ToString() : "";
                //                        adminfee.Zone_Type = workSheet.Cells[rowIterator, 2].Value != null ? workSheet.Cells[rowIterator, 2].Value.ToString() : "";
                //                        adminfee.Company_Name = workSheet.Cells[rowIterator, 3].Value != null ? workSheet.Cells[rowIterator, 3].Value.ToString() : "";
                //                        adminfee.Enterprise_Type = workSheet.Cells[rowIterator, 4].Value != null ? workSheet.Cells[rowIterator, 4].Value.ToString() : "";
                //                        adminfee.Employment = workSheet.Cells[rowIterator, 5].Value != null ? workSheet.Cells[rowIterator, 5].Value.ToString() : "";
                //                        adminfee.Zone_Code = workSheet.Cells[rowIterator, 6].Value != null ? workSheet.Cells[rowIterator, 6].Value.ToString() : "";
                //                        adminfee.Month = workSheet.Cells[rowIterator, 7].Value != null ? workSheet.Cells[rowIterator, 7].Value.ToString() : "";
                //                        adminfee.Year = workSheet.Cells[rowIterator, 8].Value != null ? workSheet.Cells[rowIterator, 8].Value.ToString() : "";
                //                        adminfee.Comp_Code = workSheet.Cells[rowIterator, 9].Value != null ? workSheet.Cells[rowIterator, 9].Value.ToString() : "";
                //                        adminfee.Developer = workSheet.Cells[rowIterator, 10].Value != null ? workSheet.Cells[rowIterator, 10].Value.ToString() : "";
                //                        adminfee.Dev_Comp_Code = workSheet.Cells[rowIterator, 11].Value != null ? workSheet.Cells[rowIterator, 11].Value.ToString() : "";
                //                        adminfee.Total_Locators = workSheet.Cells[rowIterator, 12].Value != null ? workSheet.Cells[rowIterator, 12].Value.ToString() : "";
                //                        adminfee.Total_Employment = workSheet.Cells[rowIterator, 13].Value != null ? workSheet.Cells[rowIterator, 13].Value.ToString() : "";
                //                        adminfee.BillingPeriodId = billPeriod;
                //                        if (!db.Company.Any(m => m.CompanyCode == adminfee.Comp_Code))
                //                            notRegisteredCompany.Add(adminfee.Company_Name);

                //                        db.AdminFee.Add(adminfee);
                //                        db.SaveChanges();
                //                    }
                //                    //TempData["notRegisteredCompany"] = notRegisteredCompany;
                //                    //TempData["TransactionSuccess"] = "Complete";
                //                    transaction.Commit();
                //                }
                //            }
                //            catch (Exception)
                //            {
                //                transaction.Rollback();
                //                //TempData["TransactionSuccess"] = "Failed";
                //            }
                //        }
                //    }
            }
        }
Esempio n. 19
0
        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);
        }