private void UpdateRentalAccountFromBasket(RentalBasket basket) { var account = _accountService.GetAccount(basket.CustomerAccountId) as RentalAccount; foreach (RentedUnit mRentedUnit in basket.RentedUnits) { var rentedUnit = new RentedUnit { Amount = mRentedUnit.Amount, RentedDate = mRentedUnit.RentedDate, StockId = mRentedUnit.StockId, Stock = _stockService.GetStock(mRentedUnit.StockId), Deposit = basket.FullPayment ? mRentedUnit.Deposit : 0, PaidUntil = mRentedUnit.RentedDate, }; _accountService.AddRentedUnit(account.CustomerAccountId, rentedUnit); } foreach (var oneOffItem in basket.OneOffItems) { var newOneOffItem = new OneOffItem { Description = oneOffItem.Description, Charge = oneOffItem.Charge, Date = basket.StartDate, Quantity = oneOffItem.Quantity, OneOffTypeId = oneOffItem.OneOffTypeId }; account.OneOffItems.Add(newOneOffItem); } _accountService.UpdateAccount(account); }
public ActionResult _AddRentedUnit(int id) { var basket = GetRentalBasket(); var stk = _stockService.GetStock(id); var ru = new RentedUnit { Stock = stk, StockId = id, RentedDate = GetRentalBasket().StartDate, UnitId = GetRentalBasket().RentedUnits.NextIndex(c => c.UnitId), Amount = stk.Model.RentalPrice, Deposit = _miscService.GetDefaultDepositForRentalUnits(), CustomerAccountId = GetRentalBasket().CustomerAccountId, }; if ((ru.Stock.ProductLifeCycleStatus.ProductLifeCycleActions & ProductLifeCycleActions.CanBeRented) != ProductLifeCycleActions.CanBeRented) { return(ReturnJsonError("Unit selected is not available. Status is : " + ru.Stock.ProductLifeCycleStatus.Description)); } if (basket.RentedUnits.Any(u => u.StockId == id)) { return(ReturnJsonFormSuccess()); } basket.RentedUnits.Add(ru); UpdateBasket(basket); return(ReturnJsonFormSuccess()); }
public decimal ToInclude(bool include, RentedUnit rentedUnit) { decimal result = 0; if (!include) { if (rentedUnit.TotalPrice != 0) { result += rentedUnit.TotalPrice; } } else { if (rentedUnit.TotalPrice != 0) { result += rentedUnit.TotalPrice; } else { result += CalculatePrice(rentedUnit); } } return(result); }
public ActionResult AddRentAccountStep5(AddRentAccountVM mAddRentAccountVm) { if (ModelState.IsValid) { var rentAcc = TempAccountAsAddRentAccountVM(); if (TryUpdateModel(rentAcc)) { var newAccount = new RentalAccount { AlternateAddressInstructions = rentAcc.AlternateAddressInstructions, AlternateAddress = rentAcc.AlternateAddress, CustomerId = rentAcc.CustomerId, AttachedContracts = new List <Contract>(), RentedUnits = new List <RentedUnit>(), OneOffItems = new List <OneOffItem>(), }; foreach (RentedUnit mRentedUnit in rentAcc.RentedUnits) { var rentedUnit = new RentedUnit { Amount = mRentedUnit.Amount, RentedDate = mRentedUnit.RentedDate, StockId = mRentedUnit.StockId, Stock = _stockService.GetStock(mRentedUnit.StockId), Deposit = mRentedUnit.Deposit, }; newAccount.AddRentedUnitAndUpdateContract(rentedUnit); } foreach (var oneOffItem in rentAcc.OneOffItems) { var newOneOffItem = new OneOffItem { Description = oneOffItem.Description, Charge = oneOffItem.Charge, Date = rentAcc.StartDate, Quantity = oneOffItem.Quantity, OneOffTypeId = oneOffItem.OneOffTypeId }; newAccount.OneOffItems.Add(newOneOffItem); } if (ExecuteRepositoryAction(() => { _accountService.AddTempAccount(newAccount); _accountService.CommitChanges(); })) { var acceptAccount = new AcceptAccountVM { CustomerAccountId = newAccount.CustomerAccountId, FullPayment = (mAddRentAccountVm.Payment > 0) }; Session["_accountId"] = acceptAccount; return(RedirectToAction(Stepper2.NextStep())); } } } return(View(mAddRentAccountVm)); }
public void RemoveRentedUnit(RentedUnit rentedUnit) { //RentedContract.AddAjustmentPostForRentedUnitRemoval(rentedUnit); rentedUnit.Stock.CustomerAccountId = null; if (RentedUnits.Count(c => c.RemovalDate == null) == 0) { RentedContract.Charge = MonthlyCharge; RentedContract.ExpiryDate = rentedUnit.RemovalDate; } }
private void AddRentUnitRemoveProRata(RentedUnit rentedUnit, int customerAccountId) { if (rentedUnit.PaidUntil != null) { var proErrata = CalcualteProRata((DateTime)rentedUnit.PaidUntil, (DateTime)rentedUnit.RemovalDate, rentedUnit.Amount); _accountTransactionService.AddAccountTransaction(customerAccountId, AccountTransactionType.Rental, proErrata, AccountTransactionInputType.Adjustment, rentedUnit.StockId, rentedUnit.Stock.ManufacturerModel + " Pro-rata"); } }
public void AddRentedUnit(int accountId, RentedUnit rentedUnit) { var account = GetAccount(accountId) as RentalAccount; account.RentedUnits.Add(rentedUnit); rentedUnit.CustomerAccountId = accountId; //UpdateRentalAccountContract(account); UpdateAccount(account); //_customerAccountRepository.Update(account); }
public void UpdateRentalContractUnitStock(RentedUnit rentedUnit, int oldStockId, int oldStockProductCycleId) { var cu = _contractUnitRepsoitory.GetById(rentedUnit.CustomerAccountId) as RentalAccount; rentedUnit.Stock = _stockService.GetStock(rentedUnit.StockId); cu.UpdateRentedUnitAndUpdateContract(rentedUnit); _contractUnitRepsoitory.Update(cu); _stockService.ChangeStockLifeCycle(oldStockId, oldStockProductCycleId); _stockService.SetCustomerAccountId(null, oldStockId); }
public void SwapRentedUnit(RentedUnit rentedUnit, int newStockId, int lifeCycleForPreviousStock) { var curStockid = rentedUnit.StockId; rentedUnit.StockId = newStockId; UpdateUnit(rentedUnit); var oldStock = _stockService.GetStock(curStockid); oldStock.ProductLifeCycleId = lifeCycleForPreviousStock; _stockService.UpdateStock(oldStock); }
public ActionResult _AddRentedUnits(RentedUnitVM mRentedUnitVm) { if (TryValidateModel(mRentedUnitVm)) { var ru = new RentedUnit(); if (TryUpdateModel(ru)) { ru.Stock = _stockService.GetStock(ru.StockId); ru.UnitId = TempAccountAsAddRentAccountVM().RentedUnits.NextIndex(c => c.UnitId); TempAccountAsAddRentAccountVM().RentedUnits.Add(ru); return(ReturnJsonFormSuccess()); } } return(PartialView("_EditRentedUnit", mRentedUnitVm)); }
public void DeleteRentedUnit(RentedUnit rentedUnit, int toProductLifeCycle, bool returnDeposit) { var account = GetAccount(rentedUnit.CustomerAccountId) as RentalAccount; rentedUnit.Stock.ProductLifeCycleId = toProductLifeCycle; AddRentUnitRemoveProRata(rentedUnit, account.CustomerAccountId); if (returnDeposit) { _accountTransactionService.AddAccountTransaction(account.CustomerAccountId, AccountTransactionType.DepositReturn, -rentedUnit.Deposit, AccountTransactionInputType.Charge, rentedUnit.StockId, rentedUnit.Stock.ManufacturerModel); } rentedUnit.PaidUntil = rentedUnit.RemovalDate; _customerAccountRepository.Update(account); }
public void UpdateRentedUnitAndUpdateContract(RentedUnit rentedUnit) { if (RentedUnits == null) { AddRentedUnitAndUpdateContract(rentedUnit); } else { rentedUnit.Stock.ProductLifeCycleId = (int)ProductLifeCycleStatus.Rented; rentedUnit.Stock.CustomerAccountId = this.CustomerAccountId; if (rentedUnit.OldAmount != 0 && rentedUnit.OldAmount != rentedUnit.Amount) { //RentedContract.AddAdjustmentPostForRentedUnitPriceChange(rentedUnit); RentedContract.Charge = MonthlyCharge; } } }
public void AddRentedUnitAndUpdateContract(RentedUnit rentedUnit) { RentedUnits = RentedUnits ?? new List <RentedUnit>(); RentedUnits.Add(rentedUnit); if (GetActiveRentalContract() == null) { RentedContract = new RentalContract(); } RentedContract.StartDate = rentedUnit.RentedDate; RentedContract.ExpiryDate = null; RentedContract.Charge = MonthlyCharge; RentedContract.PaymentPeriodId = 1; RentedContract.NoOfUnits = RentedUnits.Count; //RentedContract.AddAdjustmentPostForAddedRentedUnit(rentedUnit); rentedUnit.Stock.ProductLifeCycleId = (int)ProductLifeCycleStatus.Rented; rentedUnit.Stock.CustomerAccountId = this.CustomerAccountId; }
public ActionResult _AddRentedUnit(int id) { var ru = new RentedUnit(); ru.Stock = _stockService.GetStock(id); ru.StockId = id; ru.RentedDate = TempAccountAsAddRentAccountVM().StartDate; ru.UnitId = TempAccountAsAddRentAccountVM().RentedUnits.NextIndex(c => c.UnitId); ru.Amount = ru.Stock.Model.RentalPrice; ru.Deposit = _miscService.GetDefaultDepositForRentalUnits(); if (ru.Stock.CustomerAccountId > 0) { return(ReturnJsonError("Unit selected is attached to another account!")); } if (TempAccountAsAddRentAccountVM().RentedUnits.Any(u => u.StockId == id)) { return(ReturnJsonFormSuccess()); } TempAccountAsAddRentAccountVM().RentedUnits.Add(ru); return(ReturnJsonFormSuccess()); }
public decimal CalculatePrice(RentedUnit t) { decimal result = 0; var minutesUntilCap = _priceCap / t.PricePerMinute; var resetTime = new DateTime(t.StartTime.Year, t.StartTime.Month, t.StartTime.Day + 1, 0, 0, 0); var tempTime = t.StartTime; var totalTimeUsed = (decimal)t.EndTime.Subtract(t.StartTime).TotalMinutes; //If time until reset is less than time until priceCap and totalTimeUsed goes over reset time if (TimeUntilReset(resetTime, tempTime) < minutesUntilCap && TimeUntilReset(resetTime, tempTime) < totalTimeUsed) { result += TimeUntilReset(resetTime, tempTime) * t.PricePerMinute; totalTimeUsed -= TimeUntilReset(resetTime, tempTime); tempTime = resetTime; resetTime = resetTime.AddDays(1); } //if totalTimeUsed is larger than time until reset (goes over reset time) while (TimeUntilReset(resetTime, tempTime) < totalTimeUsed) { result += _priceCap; totalTimeUsed -= TimeUntilReset(resetTime, tempTime); tempTime = resetTime; resetTime = resetTime.AddDays(1); } //if totalTimeUsed is larger than minutesUntilCap (at this point, it's smaller than reset time, only equal) if (totalTimeUsed >= minutesUntilCap) { result += _priceCap; } //else it doesn't reach minutesUntilCap and needs to be calculated else { result += totalTimeUsed * t.PricePerMinute; } return(Math.Round(result, 2)); }