コード例 #1
0
        public Invoice AddInvoice(Client client, ReservationArrangementType arrangement, DateTime from, DateTime until, List <Car> cars, Double vatPercent)
        {
            TimeSpan diffTime   = until - from;
            Double   totalHours = diffTime.TotalHours;

            List <InvoiceItem> invoiceItems = new List <InvoiceItem>();

            foreach (Car car in cars)
            {
                Double price = car.GetPrice(from, until, arrangement);

                InvoiceItem ii;
                switch (arrangement)
                {
                case ReservationArrangementType.NIGHT:
                    if (car.PriceNight <= 0)
                    {
                        throw new DomainException("Car with ID " + car.ID + " can't be booked for the night arragement");
                    }
                    ii = new InvoiceItem(1, "#" + car.ID + " " + car.Brand + " " + car.Type + " (" + car.Color + ") - Night " + totalHours + "h", price, price, 0);
                    break;

                case ReservationArrangementType.WEDDING:
                    if (car.PriceWedding <= 0)
                    {
                        throw new DomainException("Car with ID " + car.ID + " can't be booked for the wedding arragement");
                    }
                    ii = new InvoiceItem(1, "#" + car.ID + " " + car.Brand + " " + car.Type + " (" + car.Color + ") - Wedding " + totalHours + "h", price, price, 0);
                    break;

                case ReservationArrangementType.WELLNESS:
                    if (car.PriceWellness <= 0)
                    {
                        throw new DomainException("Car with ID " + car.ID + " can't be booked for the wellness arragement");
                    }
                    ii = new InvoiceItem(1, "#" + car.ID + " " + car.Brand + " " + car.Type + " (" + car.Color + ") - Wellness " + totalHours + "h", price, price, 0);
                    break;

                default:
                    ii = new InvoiceItem(1, "#" + car.ID + " " + car.Brand + " " + car.Type + " (" + car.Color + ") " + totalHours + "h", price, price, 0);
                    break;
                }
                uow.InvoiceItems.AddInvoiceItem(ii);
                invoiceItems.Add(ii);
            }

            Invoice invoice = new Invoice(client.ID, DateTime.Now, invoiceItems, client.GetDiscount(uow.Clients.GetYealyReservations(client, DateTime.Now.Year)), vatPercent);

            uow.Invoices.AddInvoice(invoice);
            uow.Complete();
            foreach (InvoiceItem ii in invoiceItems)
            {
                ii.InvoiceID = invoice.ID;
            }
            uow.Complete();

            return(invoice);
        }
コード例 #2
0
 public Reservation(Client client, List <CarReservation> carReservations, DateTime orderDate, DateTime reservationDate, string startLocation, string endLocation, ReservationArrangementType arrangement, DateTime reservedUntil, DateTime reservationEnded, Invoice invoice)
 {
     Client           = client;
     ClientID         = client.ID;
     CarReservations  = carReservations;
     OrderDate        = orderDate;
     ReservationDate  = reservationDate;
     StartLocation    = startLocation;
     EndLocation      = endLocation;
     Arrangement      = arrangement;
     ReservedUntil    = reservedUntil;
     ReservationEnded = reservationEnded;
     InvoiceID        = invoice.ID;
 }
コード例 #3
0
        public Reservation AddReservation(Client client, ReservationArrangementType arrangement, DateTime from, DateTime until, String startLocation, String endLocation, List <Car> cars, DateTime orderDate, Double vatPercent)
        {
            if (from == null || until == null)
            {
                throw new DomainException("The pickup and return dates must be given");
            }
            TimeSpan diffTime    = until - from;
            double   amountHours = diffTime.TotalHours;

            if (client == null)
            {
                throw new DomainException("There must a client be given");
            }
            if (amountHours > 11)
            {
                throw new DomainException("Reservations can't be more than 11 hours long");
            }
            if (arrangement == ReservationArrangementType.NIGHT && !TimeUtilities.IsBetweenTimes(from, TimeSpan.FromHours(20), TimeSpan.FromHours(0)))
            {
                throw new DomainException("Night arragement must start between 20:00 and 00:00");
            }
            if (arrangement == ReservationArrangementType.WEDDING && !TimeUtilities.IsBetweenTimes(from, TimeSpan.FromHours(7), TimeSpan.FromHours(15)))
            {
                throw new DomainException("Wedding arragement must start between 07:00 and 15:00");
            }
            if (arrangement == ReservationArrangementType.WELLNESS && !TimeUtilities.IsBetweenTimes(from, TimeSpan.FromHours(7), TimeSpan.FromHours(12)))
            {
                throw new DomainException("Wellness arragement must start between 07:00 and 12:00");
            }
            if (cars.Count <= 0)
            {
                throw new DomainException("You must select at least one car");
            }

            Invoice     invoice     = AddInvoice(client, arrangement, from, until, cars, vatPercent);
            Reservation reservation = new Reservation(client, new List <CarReservation>(), orderDate, from, startLocation, endLocation, arrangement, until, DateTime.MinValue, invoice);

            uow.Reservations.AddReservation(reservation);
            uow.Complete();
            AddCarReservations(reservation, cars);

            return(reservation);
        }
コード例 #4
0
        public ReservationEdit(Reservation reservation)
        {
            InitializeComponent();
            InitializeComboBox_Clients();
            InitializeComboxBox_Arrangement();
            InitializeComboxBox_StartLocation();
            InitializeComboxBox_EndLocation();
            InitializeAvailbaleCars();
            InitializeService.InitializeSelection(FromTime);
            InitializeService.InitializeSelection(UntilTime);

            this.Title = this.Title.ToString().Replace("{id}", reservation.ID + "");
            Type       = reservation.Arrangement;
            From       = reservation.ReservationDate;
            Until      = reservation.ReservedUntil;

            RentalManager manager = new RentalManager(new UnitOfWork(new RentalContext()));

            client          = manager.GetClient(reservation.ClientID);
            reservationCars = manager.GetReservationCars(reservation.ID);

            Client.SelectedIndex        = manager.GetAllClients().IndexOf(client);
            Arrangement.SelectedIndex   = Arrangement.Items.IndexOf(char.ToUpper(reservation.Arrangement.ToString().ToLower()[0]) + reservation.Arrangement.ToString().ToLower().Substring(1));
            StartLocation.SelectedIndex = StartLocation.Items.IndexOf(char.ToUpper(reservation.StartLocation.ToLower()[0]) + reservation.StartLocation.ToLower().Substring(1));
            EndLocation.SelectedIndex   = EndLocation.Items.IndexOf(char.ToUpper(reservation.EndLocation.ToLower()[0]) + reservation.EndLocation.ToLower().Substring(1));
            FromTime.SelectedIndex      = FromTime.Items.IndexOf(reservation.ReservationDate.ToString("HH:00"));
            UntilTime.SelectedIndex     = UntilTime.Items.IndexOf(reservation.ReservedUntil.ToString("HH:00"));
            if (reservation.ReservationEnded > DateTime.MinValue)
            {
                ReturnedDate.SelectedDate  = reservation.ReservationEnded.Date;
                ReturnedTime.SelectedIndex = ReturnedTime.Items.IndexOf(reservation.ReservationEnded.ToString("HH:00"));
            }

            FromDate.SelectedDate  = reservation.ReservationDate.Date;
            UntilDate.SelectedDate = reservation.ReservedUntil.Date;
        }
コード例 #5
0
        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
                });
            }
        }
コード例 #6
0
        public double GetPrice(DateTime from, DateTime until, ReservationArrangementType arrangement)
        {
            Double price = 0.0;

            TimeSpan diffTime   = until - from;
            Double   totalHours = diffTime.TotalHours;

            switch (arrangement)
            {
            case ReservationArrangementType.NIGHT:
                if (totalHours > 7)
                {
                    from.AddHours(7);
                }
                break;

            case ReservationArrangementType.WEDDING:
                if (totalHours > 7)
                {
                    from.AddHours(7);
                }
                break;

            case ReservationArrangementType.WELLNESS:
                if (totalHours > 10)
                {
                    from.AddHours(10);
                }
                break;

            default:
                break;
            }

            TimeSpan fromTime  = from.TimeOfDay;
            TimeSpan untilTime = until.TimeOfDay;

            Double normalHours = 0.0;
            Double nightHours  = 0.0;

            while (fromTime < untilTime)
            {
                fromTime = fromTime.Add(TimeSpan.FromHours(1));
                if (fromTime >= TimeSpan.FromHours(22) || fromTime <= TimeSpan.FromHours(6))
                {
                    nightHours += 1;
                }
                else
                {
                    normalHours += 1;
                }
            }

            switch (arrangement)
            {
            case ReservationArrangementType.NIGHT:
                price = this.PriceNight;
                if (totalHours > 7)
                {
                    price += normalHours * (this.PriceFirst * 0.65);
                    price += nightHours * (this.PriceFirst * 1.4);
                }
                break;

            case ReservationArrangementType.WEDDING:
                price = this.PriceWedding;
                if (totalHours > 7)
                {
                    price += normalHours * (this.PriceFirst * 0.65);
                    price += nightHours * (this.PriceFirst * 1.4);
                }
                break;

            case ReservationArrangementType.WELLNESS:
                price = this.PriceWedding;
                if (totalHours > 10)
                {
                    price += normalHours * (this.PriceFirst * 0.65);
                    price += nightHours * (this.PriceFirst * 1.4);
                }
                break;

            default:
                if (!TimeUtilities.IsBetweenTimes(from, TimeSpan.FromHours(22), TimeSpan.FromHours(6)))
                {
                    price        = this.PriceFirst;
                    normalHours -= 1;
                }
                price += normalHours * (this.PriceFirst * 0.65);
                price += nightHours * (this.PriceFirst * 1.4);
                break;
            }
            return(Math.Round(price / 5.0) * 5);
        }