public void TestRentalManagerRemoveInvoice() { // Pre-setup RentalManager manager = new RentalManager(new UnitOfWork(new RentalContext("development"))); manager.AddClient("Tim", "De Smet", "*****@*****.**", "0493100289", "Azaleastraat", "57", "", "9940", "Evergem", "Belgium", ClientType.AGENCY, "Jetstax", "BE0730.671.009"); Assert.AreNotEqual(manager.GetAllClients().Count, 0); Client client = manager.GetAllClients().Last(); manager.AddCar("Porsche", "Cayenne Limousine", "White", 310, 1500, 1200, 1600, true); Assert.AreNotEqual(manager.GetAllCars().Count, 0); Car car = manager.GetAllCars().Last(); manager.AddInvoice(client, ReservationArrangementType.AIRPORT, new DateTime(2020, 8, 20, 10, 0, 0), new DateTime(2020, 8, 20, 13, 0, 0), new List <Car>() { car }, 6.0); // Setup Assert.AreNotEqual(manager.GetAllInvoices().Count, 0); Invoice invoice = manager.GetAllInvoices().Last(); int count = manager.GetAllInvoices().Count; manager.RemoveInvoice(invoice); // Check Assert.AreEqual(manager.GetAllInvoices().Count, count - 1); }
public void TestRentalManagerAddInvoice() { // Pre-setup RentalManager manager = new RentalManager(new UnitOfWork(new RentalContext("development"))); manager.AddClient("Tim", "De Smet", "*****@*****.**", "0493100289", "Azaleastraat", "57", "", "9940", "Evergem", "Belgium", ClientType.AGENCY, "Jetstax", "BE0730.671.009"); Assert.AreNotEqual(manager.GetAllClients().Count, 0); Client client = manager.GetAllClients().Last(); manager.AddCar("Porsche", "Cayenne Limousine", "White", 310, 1500, 1200, 1600, true); Assert.AreNotEqual(manager.GetAllCars().Count, 0); Car car = manager.GetAllCars().Last(); // Setup manager.AddInvoice(client, ReservationArrangementType.AIRPORT, new DateTime(2020, 8, 20, 10, 0, 0), new DateTime(2020, 8, 20, 13, 0, 0), new List <Car>() { car }, 6.0); // Check Invoice invoice = manager.GetAllInvoices().Last(); List <InvoiceItem> invoiceItems = manager.GetInvoiceItems(invoice.ID); Assert.AreEqual(invoice.ClientID, client.ID); Assert.AreEqual(invoice.DiscountPercent, 0); Assert.AreEqual(invoice.Discount, 0); Assert.AreEqual(invoice.VATPercent, 6.0); Assert.AreEqual(invoice.VAT, 42.9); Assert.AreEqual(invoice.SubTotal, 715); Assert.AreEqual(invoice.TotalExc, 715); Assert.AreEqual(invoice.TotalInc, 757.9); Assert.AreEqual(invoice.PaymentDue, 757.9); Assert.AreEqual(invoiceItems.Count, 1); }
public async static void OpenReservationEditDialog(Reservation reservation) { try { ReservationEdit dialog = new ReservationEdit(reservation); var result = await dialog.ShowAsync(); if (result == ContentDialogResult.Primary) { if (dialog.Client.SelectedIndex < 0) { MainWindow.DisplayThrowbackDialog("Reservation Edit Error", "You must selected a client out of the list"); return; } if (!int.TryParse(dialog.Client.SelectedItem.ToString().Split(" ")[0].Substring(1), out int clientID)) { MainWindow.DisplayThrowbackDialog("Reservation Edit Error", "Something went wrong while retrieving the client from the list"); return; } RentalManager manager = new RentalManager(new UnitOfWork(new RentalContext())); List <Car> oldRentedCars = manager.GetReservationCars(reservation.ID); Client client = manager.GetClient(clientID); if (dialog.Arrangement.SelectedIndex < 0 || !Enum.TryParse(typeof(ReservationArrangementType), dialog.Arrangement.SelectedItem.ToString().ToUpper(), out object typeObj)) { MainWindow.DisplayThrowbackDialog("Reservation Edit Error", "You must select a arrangement from the list"); return; } if (dialog.FromDate.SelectedDate == null || dialog.FromTime.SelectedIndex < 0 || !TimeSpan.TryParse(dialog.FromTime.SelectedItem.ToString(), out TimeSpan fromTime)) { MainWindow.DisplayThrowbackDialog("Reservation Edit Error", "You must select pickup date and time"); return; } if (dialog.UntilDate.SelectedDate == null || dialog.UntilTime.SelectedIndex < 0 || !TimeSpan.TryParse(dialog.UntilTime.SelectedItem.ToString(), out TimeSpan untilTime)) { MainWindow.DisplayThrowbackDialog("Reservation Edit Error", "You must select return date and time"); return; } if (dialog.StartLocation.SelectedIndex < 0) { MainWindow.DisplayThrowbackDialog("Reservation Edit Error", "You must select pickup location"); return; } if (dialog.EndLocation.SelectedIndex < 0) { MainWindow.DisplayThrowbackDialog("Reservation Edit Error", "You must select return location"); return; } if (dialog.CarTable.SelectedItems.Count <= 0) { MainWindow.DisplayThrowbackDialog("Reservation Edit Error", "You must select at least one car"); return; } if (client.Type == ClientType.PRIVATE && dialog.CarTable.SelectedItems.Count > 1) { MainWindow.DisplayThrowbackDialog("Reservation Edit Error", "Private clients can select a maximum of 1 car"); return; } ReservationArrangementType arragement = (ReservationArrangementType)typeObj; String startLocation = dialog.StartLocation.SelectedItem.ToString(); String endLocation = dialog.EndLocation.SelectedItem.ToString(); DateTime fromDate = dialog.FromDate.SelectedDate.Value + fromTime; DateTime untilDate = dialog.UntilDate.SelectedDate.Value + untilTime; DateTime returnedDate = DateTime.MinValue; if (dialog.ReturnedDate.SelectedDate != null && dialog.ReturnedTime.SelectedIndex >= 0 && TimeSpan.TryParse(dialog.ReturnedTime.SelectedItem.ToString(), out TimeSpan returnedTime)) { returnedDate = (DateTime)dialog.ReturnedDate.SelectedDate.Value + returnedTime; } List <int> carIDs = new List <int>(); List <int> selectedCars = dialog.CarTable.SelectedItems.Cast <DataRowView>().Select(x => dialog.AvailableCarsTable.Rows.IndexOf(x.Row)).ToList(); foreach (int i in selectedCars) { if (dialog.AvailableCarsTable.Rows.Count > 1) { DataRow row = dialog.AvailableCarsTable.Rows[i]; carIDs.Add((int)row[0]); } } List <Car> cars = new List <Car>(); foreach (int carID in carIDs) { cars.Add(manager.GetCar(carID)); } bool areCarsChanged = !(cars.All(oldRentedCars.Contains) && cars.Count == oldRentedCars.Count); if (areCarsChanged) { dialog.Hide(); ContentDialog confirmDialog = new ContentDialog { Title = "Override invoice?", Content = "You changed the reserved cars, this will regenerate a new invoice and remove the old one. Are you sure you want to proceed?", PrimaryButtonText = "Yes", CloseButtonText = "No" }; var confirmResult = await confirmDialog.ShowAsync(); if (confirmResult == ContentDialogResult.Primary) { RentalManager carsManager = new RentalManager(new UnitOfWork(new RentalContext())); carsManager.RemoveInvoice(reservation.InvoiceID); DateTime untilInvoice = untilDate; if (returnedDate > DateTime.MinValue) { untilInvoice = returnedDate; } reservation.InvoiceID = carsManager.AddInvoice(client, arragement, fromDate, untilInvoice, cars, 6.0).ID; carsManager.UpdateCarReservations(reservation, cars); } else { return; } } reservation.Client = client; reservation.ClientID = client.ID; reservation.Arrangement = arragement; reservation.StartLocation = startLocation; reservation.EndLocation = endLocation; reservation.ReservationDate = fromDate; reservation.ReservedUntil = untilDate; reservation.ReservationEnded = returnedDate; manager.UpdateReservation(reservation); MainWindow.DisplayThrowbackDialog("Reservation Saved", "All changes have been saved"); return; } } catch (Exception ex) { MainWindow.DisplayThrowbackDialog("System Error", ex.Message + "\n" + "Stack trace has been written to the logs"); LogService.WriteLog(new List <String>() { "Reservation Edit Save Exeption: ", ex.Message, " ", ex.InnerException.ToString(), ex.StackTrace }); } }