Search in sources :

Example 1 with OverbookingException

use of com.github.drbookings.OverbookingException in project drbookings by DrBookings.

the class DataStore method load.

public void load(final MainManager manager) {
    final List<BookingBean> bookingsToAdd = new ArrayList<>();
    for (final BookingBeanSer bb : (Iterable<BookingBeanSer>) () -> getBookingsSer().stream().sorted((b1, b2) -> b1.checkInDate.compareTo(b2.checkInDate)).iterator()) {
        try {
            final BookingBean b = manager.createBooking(bb.bookingId, bb.checkInDate, bb.checkOutDate, bb.guestName, bb.roomName, bb.source);
            // b.setGrossEarnings(bb.grossEarnings);
            b.setGrossEarningsExpression(bb.grossEarningsExpression);
            b.setWelcomeMailSend(bb.welcomeMailSend);
            b.setCheckInNote(bb.checkInNote);
            b.setPaymentDone(bb.paymentDone);
            b.setSpecialRequestNote(bb.specialRequestNote);
            b.setCheckOutNote(bb.checkOutNote);
            b.setExternalId(bb.externalId);
            b.setCalendarIds(bb.calendarIds);
            b.setCleaningFees(bb.cleaningFees);
            b.setServiceFeesPercent(bb.serviceFeePercent);
            b.setDateOfPayment(bb.dateOfPayment);
            b.setSplitBooking(bb.splitBooking);
            b.setPayments(Payment.transform(bb.paymentsSoFar));
            bookingsToAdd.add(b);
        } catch (final Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error(e.getLocalizedMessage(), e);
            }
        }
    }
    bookingsToAdd.forEach(b -> {
        try {
            manager.addBooking(b);
        } catch (final OverbookingException e) {
            if (logger.isWarnEnabled()) {
                logger.warn(e.getLocalizedMessage());
            }
        }
    });
    if (logger.isDebugEnabled()) {
        logger.debug(bookingsToAdd.size() + " added");
    }
    for (final CleaningBeanSer cb : getCleaningsSer()) {
        final Optional<BookingBean> b = manager.getBooking(cb.bookingId);
        if (b.isPresent()) {
            manager.addCleaning(cb.date, cb.name, b.get()).setCalendarIds(cb.calendarIds).setCleaningCosts(cb.cleaningCosts);
        } else {
            if (logger.isWarnEnabled()) {
                logger.warn("Failed to add cleaning " + cb + ", failed to find booking for ID " + cb.bookingId);
            }
        }
    }
}
Also used : CleaningBeanSer(com.github.drbookings.model.ser.CleaningBeanSer) ArrayList(java.util.ArrayList) BookingBeanSer(com.github.drbookings.model.ser.BookingBeanSer) OverbookingException(com.github.drbookings.OverbookingException) BookingBean(com.github.drbookings.model.data.BookingBean) OverbookingException(com.github.drbookings.OverbookingException)

Example 2 with OverbookingException

use of com.github.drbookings.OverbookingException in project drbookings by DrBookings.

the class AddBookingController method handleButtonOK.

@FXML
void handleButtonOK(final ActionEvent event) {
    final boolean valid = validateInput();
    if (valid) {
        try {
            final BookingBean b = getManager().createBooking(datePickerCheckIn.getValue(), datePickerCheckOut.getValue(), textFieldGuestName.getText().trim(), comboBoxRoom.getSelectionModel().getSelectedItem(), textFieldSource.getText().trim());
            b.setGrossEarningsExpression(getGrossEarnings() + "");
            b.setCleaningFees(SettingsManager.getInstance().getCleaningFees());
            try {
                b.setServiceFeesPercent(Float.parseFloat(textFieldServiceFeesPercent.getText()));
            } catch (final NumberFormatException e) {
                if (logger.isDebugEnabled()) {
                    logger.debug(e.toString());
                }
            }
            try {
                b.setServiceFee(Float.parseFloat(textFieldServiceFees.getText()));
            } catch (final NumberFormatException e) {
                if (logger.isDebugEnabled()) {
                    logger.debug(e.toString());
                }
            }
            getManager().addBooking(b);
        } catch (final OverbookingException e) {
            if (logger.isDebugEnabled()) {
                logger.debug(e.getLocalizedMessage());
            }
            UIUtils.showError("Overbooking", e.getLocalizedMessage());
        }
        final Stage stage = (Stage) buttonOK.getScene().getWindow();
        stage.close();
    }
}
Also used : Stage(javafx.stage.Stage) BookingBean(com.github.drbookings.model.data.BookingBean) OverbookingException(com.github.drbookings.OverbookingException) FXML(javafx.fxml.FXML)

Aggregations

OverbookingException (com.github.drbookings.OverbookingException)2 BookingBean (com.github.drbookings.model.data.BookingBean)2 BookingBeanSer (com.github.drbookings.model.ser.BookingBeanSer)1 CleaningBeanSer (com.github.drbookings.model.ser.CleaningBeanSer)1 ArrayList (java.util.ArrayList)1 FXML (javafx.fxml.FXML)1 Stage (javafx.stage.Stage)1