Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
package com.gitrekt.resort.controller;

import com.gitrekt.resort.model.entities.Booking;
import com.gitrekt.resort.model.services.BookingService;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TableView;

/**
* FXML Controller class for the booking details screen.
*/
public class BookingDetailsScreenController implements Initializable {

@FXML
private Button backButton;

@FXML
private Button cancelBookingButton;

@FXML
private Button viewBillButton;

// TODO fix rawtype
@FXML
Expand All @@ -39,27 +31,41 @@ public class BookingDetailsScreenController implements Initializable {
@FXML
private Label checkOutDateLabel;

private Booking booking;

/**
* Initializes the controller class.
*/
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
// TODO: Remove test code
BookingService bookingService = new BookingService();
this.booking = bookingService.getBookingById(1L);
}

public void onBackButtonClicked() {
@FXML
private void onBackButtonClicked() {
ScreenManager.getInstance().switchToScreen(
"/fxml/GuestHomeScreen.fxml"
);
}

public void onViewBillButtonClicked() {
ScreenManager.getInstance().switchToScreen(
@FXML
private void onViewBillButtonClicked() {
Object temp = ScreenManager.getInstance().switchToScreen(
"/fxml/CustomerBillScreen.fxml"
);
CustomerBillScreenController controller;
controller = (CustomerBillScreenController) temp;

// Fix LazyInitializationException by forcing initialization here.
System.out.println(this.booking.toString());

controller.initializeData(this.booking);
}

public void onCancelBookingButtonClicked() {
@FXML
private void onCancelBookingButtonClicked() {
// TODO
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package com.gitrekt.resort.controller;

import com.gitrekt.resort.model.entities.Bill;
import com.gitrekt.resort.model.entities.BillItem;
import com.gitrekt.resort.model.entities.Booking;
import com.gitrekt.resort.model.services.BillService;
import com.gitrekt.resort.model.services.BookingService;
import java.awt.print.PrinterException;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.concurrent.ThreadLocalRandom;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
Expand All @@ -24,46 +29,75 @@ public class CustomerBillScreenController implements Initializable {
@FXML
private Label customerNameText;

@FXML
private Label billingPeriodText;

@FXML
private Label bookingNumberText;

// TODO: Fix rawtype
@FXML
private TableView billTable;
private TableView<BillItem> billTable;

// TODO: Fix rawtype
@FXML
private TableColumn itemNameColumn;
private TableColumn<BillItem, String> itemNameColumn;

// TODO: Fix rawtype
@FXML
private TableColumn qtyColumn;
private TableColumn<BillItem,Integer> qtyColumn;

// TODO: Fix rawtype
@FXML
private TableColumn priceColumn;
private TableColumn<BillItem, String> priceColumn;

private Bill bill;
private Booking booking;

private Long bookingNumber;

private String customerName;
private ObservableList<BillItem> billItems;

/**
* Initializes the controller class.
*/
@Override
public void initialize(URL url, ResourceBundle rb) {
String formattedPrice = String.format("%.2f", bill.getTotal());
billTotalText.setText(formattedPrice);
public void initialize(URL url, ResourceBundle rb) {
billItems = FXCollections.observableArrayList();

itemNameColumn.setCellValueFactory((param) -> {
return new SimpleStringProperty(param.getValue().getName());
});

qtyColumn.setCellValueFactory((param) -> {
return new SimpleIntegerProperty(param.getValue().getQuantity())
.asObject();
});

priceColumn.setCellValueFactory((param) -> {
return new SimpleStringProperty(
String.format("%.2f", param.getValue().getTotalPrice())
);
});

billTable.setItems(billItems);
}

public void initializeData(Long bookingNumber) {
this.bookingNumber = bookingNumber;
bookingNumberText.setText(String.valueOf(bookingNumber));
/**
* Initializes the view bill screen with the data for the bill to display.
* Once this method is called, the proper data is displayed on the screen.
*
* It's not ideal to have to send the entire booking into this class to
* display just the bill, but we need several bits of extra information
* that the bill itself just doesn't contain (such as the guest name), and
* I don't have the time to implement a more robust solution, so for now, it
* works.
*
* @param booking The booking to display the bill for.
*/
public void initializeData(Booking booking) {
this.booking = booking;

// TODO: Remove test code
for(int i = 0; i < 30; i++) {
double price = ThreadLocalRandom.current().nextDouble(0,500);
int qty = ThreadLocalRandom.current().nextInt(10);
booking.getBill().getCharges().add(new BillItem("Test bill item", price, qty));
}

billItems.addAll(booking.getBill().getCharges());
initializeInfoLabels();
prepareTableView();
}

@FXML
Expand All @@ -73,12 +107,36 @@ private void onBackButtonClicked() {
);
}

/**
* Prints the guest bill on a physical printer. The user is first prompted
* with a print options dialog.
*
* @throws IOException
* @throws PrinterException
*/
@FXML
private void onPrintBillButtonClicked()
throws IOException, PrinterException {
// TODO: Replace with an actual bill, not an empty one.
BillService billService = new BillService();
billService.printBill(new Bill());
billService.printBillForBooking(booking);
}

/**
* Initializes the information displayed in the various labels displayed on
* this screen, such as the customer name label, the total price label, etc.
*/
private void initializeInfoLabels() {
bookingNumberText.setText(String.valueOf(booking.getId()));
String lastName = booking.getGuest().getFirstName();
String firstName = booking.getGuest().getLastName();
customerNameText.setText(lastName + ", " + firstName);
billTotalText.setText(
String.format("$%.2f", booking.getBill().getTotal())
);
}

private void prepareTableView() {
// TODO
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public class ScreenManager {

private static Stage mainStage;

private final FXMLLoader fxmlLoader;
private FXMLLoader fxmlLoader;

private static ScreenManager instance;

private ScreenManager() {
fxmlLoader = new FXMLLoader();
//fxmlLoader = new FXMLLoader();
}

/**
Expand Down Expand Up @@ -56,7 +56,8 @@ public Object switchToScreen(String fxmlPath) {

try {
URL pathToFxml = getClass().getResource(fxmlPath);
newScreenRoot = fxmlLoader.load(pathToFxml);
fxmlLoader = new FXMLLoader(pathToFxml);
newScreenRoot = fxmlLoader.load();
} catch (IOException e) {
throw new IllegalArgumentException("Failed to load FXML", e);
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/gitrekt/resort/model/entities/Guest.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,6 @@ public boolean isCheckedIn() {

public Long getId(){
return id;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
import org.apache.pdfbox.pdmodel.font.PDFont;
import org.apache.pdfbox.pdmodel.font.PDType1Font;

/**
* Responsible for generating a PDF representation of the guest bill.
*
* Currently very crude and incomplete, although the most basic functionality
* is in place and usable. This class still needs a lot of work.
*/
public class BillPdfGenerator {

private static final String LINE_ITEM_FORMAT = "%-40s %11s %13s %13s";
Expand Down Expand Up @@ -105,6 +111,14 @@ private String getBillTotalLine() {
);
}

/**
* Gathers the fields from the guest bill items and converts them into their
* formatted string representation to be displayed as a single line-item
* on the printed guest bill.
*
* @param item The bill item to format.
* @return The formatted bill item.
*/
private String convertBillItemToLineItem(BillItem item) {
String lineItem;
double totalPrice = item.getPrice() * item.getQuantity();
Expand Down
50 changes: 34 additions & 16 deletions src/main/java/com/gitrekt/resort/model/services/BillService.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,51 @@

package com.gitrekt.resort.model.services;

import com.gitrekt.resort.model.entities.Bill;
import com.gitrekt.resort.model.entities.BillItem;
import com.gitrekt.resort.model.entities.Booking;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.io.IOException;
import javax.print.PrintService;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.printing.PDFPageable;

/**
* This class is responsible for handling all business logic related to bills.
*
* At the moment, the only real business logic that belongs here is printing
* related, though this may change in the future as features are implemented.
*/
public class BillService {

public void printBill(Bill bill) throws IOException, PrinterException {
// TODO: Remove test code;
for(int i = 0; i < 20; i++) {
bill.getCharges().add(new BillItem("Test bill item name printed here", 15.52623, 3));
}
/**
* Prints the bill associated with the provided booking on a printer.
*
* @param booking The booking to print the bill for.
*
* @throws IOException
* @throws PrinterException
*/
public void printBillForBooking(Booking booking)
throws IOException, PrinterException {

BillPdfGenerator pdfGenerator = new BillPdfGenerator(bill);
PDDocument pdf = pdfGenerator.getBillAsPdf();

PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintService(choosePrinter());
job.setPageable(new PDFPageable(pdf));
job.print();
pdf.close();
BillPdfGenerator pdfGenerator = new BillPdfGenerator(booking.getBill());
try (PDDocument pdf = pdfGenerator.getBillAsPdf()) {
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintService(choosePrinter());
job.setPageable(new PDFPageable(pdf));
job.print();
}
}

/**
* Prompts the user to choose a printer to print from, using a standard
* dialog box.
*
* The user is also able to selected from other properties such as the
* number of copies to print, collation, etc., independently of our
* software.
*
* @return The PrintService (a.k.a the printer) selected by the user.
*/
public static PrintService choosePrinter() {
PrinterJob printJob = PrinterJob.getPrinterJob();
if(printJob.printDialog()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.util.List;
import javax.mail.MessagingException;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceException;
import javax.persistence.Query;

Expand All @@ -22,7 +21,6 @@
*/
public class BookingService {

@PersistenceContext
private final EntityManager entityManager;

/**
Expand Down
Loading