public void CreateFlatRate_Returns_FlatRate_BillingRate() { var flatRate = BillingRate.CreateFlatRate(100); Assert.Equal(BillingRate.FlatRateType, flatRate.Name); Assert.Equal(100, flatRate.UnitPrice); Assert.Equal(flatRate.UnitPrice, flatRate.MinimumCharge); }
public void CreateHourly_Returns_Hourly_BillingRate() { var hourly = BillingRate.CreateHourly(25, 75); Assert.Equal(BillingRate.HourlyType, hourly.Name); Assert.Equal(25, hourly.UnitPrice); Assert.Equal(75, hourly.MinimumCharge); }
private static void ValidateBillingRate(BillingRate billingRate) { if (billingRate.UnitPrice < 0) { throw new DomainValidationException(new ArgumentOutOfRangeException("Unit Price must be greater than or equal to zero")); } if (billingRate.MinimumCharge < 0) { throw new DomainValidationException(new ArgumentOutOfRangeException("Minimum Charge must be greater than or equal to zero")); } }
public void SetBillingRate(string name, decimal unitPrice, decimal minimumCharge) { var billingRate = BillingRate.None; switch (name) { case BillingRate.HourlyType: billingRate = BillingRate.CreateHourly(unitPrice, minimumCharge); break; case BillingRate.FlatRateType: billingRate = BillingRate.CreateFlatRate(unitPrice); break; } ValidateBillingRate(billingRate); this.BaseBillingRate = billingRate; }
public void Insert(int Periodaccountid,int Groupid,double Rate,bool IsDeleted,DateTime? CreatedOn,string CreatedBy,DateTime? ModifiedOn,string ModifiedBy) { BillingRate item = new BillingRate(); item.Periodaccountid = Periodaccountid; item.Groupid = Groupid; item.Rate = Rate; item.IsDeleted = IsDeleted; item.CreatedOn = CreatedOn; item.CreatedBy = CreatedBy; item.ModifiedOn = ModifiedOn; item.ModifiedBy = ModifiedBy; item.Save(UserName); }
public ActionResult EditRates(int?BillRateIdTo, decimal?Rate, string SubCategory, string Category, 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; TempData["Category"] = db.BillingRates.Where(x => x.ZoneGroup == ZoneGroup).Where(m => m.SubCategory == SubCategory).FirstOrDefault().Category; BillingRate BillingRates = new BillingRate(); if (Rate != null) { if (TransactionType == "Add") { List <BillingRate> billrate = db.BillingRates.Where(m => m.Category.ToUpper() == Category.ToUpper() && m.SubCategory.ToUpper() == SubCategory.ToUpper() && m.ZoneGroup == ZoneGroup).ToList(); if (SubCategory.ToUpper() == "SEWERAGE") { TempData["TransactionSuccess"] = "ErrorSewerage"; } else { BillingRates.Category = Category; BillingRates.SubCategory = SubCategory; BillingRates.Rate = Rate; BillingRates.ZoneGroup = ZoneGroup; BillingRates.NGASCode = NGAS; db.BillingRates.Add(BillingRates); db.SaveChanges(); TempData["TransactionSuccess"] = "Add"; } } else if (TransactionType == "Edit") { BillingRates = db.BillingRates.Where(m => m.BillingRateId == BillRateIdTo).Single(); BillingRates.Rate = Rate; db.Entry(BillingRates).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); TempData["TransactionSuccess"] = "Edit"; } else if (TransactionType == "Delete") { BillingRates = db.BillingRates.Where(m => m.BillingRateId == BillRateIdTo).Single(); var rates = db.BillingRates.Where(m => m.Category.ToUpper() == Category.ToUpper() && m.ZoneGroup == ZoneGroup).ToList(); if (rates.Count > 1) { db.Entry(BillingRates).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); TempData["TransactionSuccess"] = "DeleteRate"; } else { TempData["TransactionSuccess"] = "LessThanoneRate"; } } } List <BillingRate> BillingRateList = new List <BillingRate>(); BillingRateList = db.BillingRates.Where(x => x.ZoneGroup == ZoneGroup).Where(m => m.SubCategory == SubCategory).ToList(); TempData["BillingRateList"] = BillingRateList; TempData["NGASCode"] = NGAS; return(RedirectToAction("ViewRatesPRG", "MaintenanceBillingAndCollectionRates")); //return View("ViewRates", BillingRateList); }
public ActionResult AddCategory(string Category) { ApplicationDbContext context = new ApplicationDbContext(); 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(); //ViewBag.Groups = new SelectList(db.ZoneGroup.ToList(), "ZoneGroupCode", "ZoneGroupName"); SearchBillingAndCollectionRates searchBillingAndCollectionRates = new SearchBillingAndCollectionRates(); if (!string.IsNullOrEmpty(Category)) { if (Category.ToUpper() == "SEWERAGE") { TempData["TransactionSuccess"] = "ErrorSewerage"; } else { BillingRate billingRate = new BillingRate(); billingRate.Category = Category; billingRate.ZoneGroup = ZoneGroup; if (Category == "Rental Fee") { billingRate.SubCategory = "PHP Rental"; } else { billingRate.SubCategory = Category; } billingRate.Rate = 0; db.BillingRates.Add(billingRate); db.SaveChanges(); TempData["TransactionSuccess"] = "Add"; } searchBillingAndCollectionRates.BillingRate = db.BillingRates.Where(x => x.ZoneGroup == ZoneGroup).Where(m => m.Category == Category).ToList(); ViewBag.Category = Category; } else { ViewBag.ShowAdd = false; Response.Write("<script>alert('Unable to add Category. Please check blank field.')</script>"); } 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); } TempData["searchBillingAndCollectionRates"] = searchBillingAndCollectionRates; TempData["Category"] = Category; return(RedirectToAction("ViewBillingAndCollectionRatesRPG", "MaintenanceBillingAndCollectionRates")); //return View("ViewBillingAndCollectionRates", searchBillingAndCollectionRates); }
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); }