Refine Desktop Pricing

This commit is contained in:
2026-04-09 17:29:03 -06:00
parent 1205459e53
commit 8b4e39416b
7 changed files with 79 additions and 68 deletions

View File

@@ -85,6 +85,7 @@ public class AdoptionController {
colAdoptionDate.setCellValueFactory(new PropertyValueFactory<>("adoptionDate")); colAdoptionDate.setCellValueFactory(new PropertyValueFactory<>("adoptionDate"));
colAdoptionFee.setCellValueFactory(new PropertyValueFactory<>("adoptionFee")); colAdoptionFee.setCellValueFactory(new PropertyValueFactory<>("adoptionFee"));
colAdoptionStatus.setCellValueFactory(new PropertyValueFactory<>("adoptionStatus")); colAdoptionStatus.setCellValueFactory(new PropertyValueFactory<>("adoptionStatus"));
TableViewSupport.applyCurrencyColumn(colAdoptionFee);
displayAdoptions(); displayAdoptions();
TableViewSupport.installDoubleClickAction(tvAdoptions, selected -> openDialog(selected, "Edit")); TableViewSupport.installDoubleClickAction(tvAdoptions, selected -> openDialog(selected, "Edit"));

View File

@@ -183,6 +183,7 @@ public class PetController {
colPetAge.setCellValueFactory(new PropertyValueFactory<Pet,Integer>("petAge")); colPetAge.setCellValueFactory(new PropertyValueFactory<Pet,Integer>("petAge"));
colPetStatus.setCellValueFactory(new PropertyValueFactory<Pet,String>("petStatus")); colPetStatus.setCellValueFactory(new PropertyValueFactory<Pet,String>("petStatus"));
colPetPrice.setCellValueFactory(new PropertyValueFactory<Pet,Double>("petPrice")); colPetPrice.setCellValueFactory(new PropertyValueFactory<Pet,Double>("petPrice"));
TableViewSupport.applyCurrencyColumn(colPetPrice);
colCustomerName.setCellValueFactory(new PropertyValueFactory<Pet,String>("customerName")); colCustomerName.setCellValueFactory(new PropertyValueFactory<Pet,String>("customerName"));
colStoreName.setCellValueFactory(new PropertyValueFactory<Pet,String>("storeName")); colStoreName.setCellValueFactory(new PropertyValueFactory<Pet,String>("storeName"));
configureImageColumn(colPetImage); configureImageColumn(colPetImage);

View File

@@ -98,6 +98,7 @@ public class ProductController {
colProductPrice.setCellValueFactory(new PropertyValueFactory<ProductDTO,Double>("prodPrice")); colProductPrice.setCellValueFactory(new PropertyValueFactory<ProductDTO,Double>("prodPrice"));
colProductCategory.setCellValueFactory(new PropertyValueFactory<ProductDTO,String>("categoryName")); colProductCategory.setCellValueFactory(new PropertyValueFactory<ProductDTO,String>("categoryName"));
colProductDesc.setCellValueFactory(new PropertyValueFactory<ProductDTO,String>("prodDesc")); colProductDesc.setCellValueFactory(new PropertyValueFactory<ProductDTO,String>("prodDesc"));
TableViewSupport.applyCurrencyColumn(colProductPrice);
configureImageColumn(colProductImage); configureImageColumn(colProductImage);
loadCategoryFilter(); loadCategoryFilter();

View File

@@ -11,7 +11,6 @@ import javafx.scene.Scene;
import javafx.scene.control.Alert; import javafx.scene.control.Alert;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.ComboBox; import javafx.scene.control.ComboBox;
import javafx.scene.control.TableCell;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.control.SelectionMode; import javafx.scene.control.SelectionMode;
import javafx.scene.control.Spinner; import javafx.scene.control.Spinner;
@@ -157,8 +156,8 @@ public class SaleController {
colCartQty.setCellValueFactory(new PropertyValueFactory<>("quantity")); colCartQty.setCellValueFactory(new PropertyValueFactory<>("quantity"));
colCartUnitPrice.setCellValueFactory(new PropertyValueFactory<>("unitPrice")); colCartUnitPrice.setCellValueFactory(new PropertyValueFactory<>("unitPrice"));
colCartTotal.setCellValueFactory(new PropertyValueFactory<>("total")); colCartTotal.setCellValueFactory(new PropertyValueFactory<>("total"));
colCartUnitPrice.setCellFactory(column -> currencyCell()); TableViewSupport.applyCurrencyColumn(colCartUnitPrice);
colCartTotal.setCellFactory(column -> currencyCell()); TableViewSupport.applyCurrencyColumn(colCartTotal);
tvCart.setItems(cartItems); tvCart.setItems(cartItems);
tvCart.getSelectionModel().setSelectionMode(SelectionMode.SINGLE); tvCart.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
@@ -172,8 +171,8 @@ public class SaleController {
colSaleUnitPrice.setCellValueFactory(new PropertyValueFactory<>("unitPrice")); colSaleUnitPrice.setCellValueFactory(new PropertyValueFactory<>("unitPrice"));
colSaleTotal.setCellValueFactory(new PropertyValueFactory<>("total")); colSaleTotal.setCellValueFactory(new PropertyValueFactory<>("total"));
colSalePaymentType.setCellValueFactory(new PropertyValueFactory<>("paymentMethod")); colSalePaymentType.setCellValueFactory(new PropertyValueFactory<>("paymentMethod"));
colSaleUnitPrice.setCellFactory(column -> currencyCell()); TableViewSupport.applyCurrencyColumn(colSaleUnitPrice);
colSaleTotal.setCellFactory(column -> currencyCell()); TableViewSupport.applyCurrencyColumn(colSaleTotal);
filteredSales = new FilteredList<>(saleItems, s -> true); filteredSales = new FilteredList<>(saleItems, s -> true);
TableViewSupport.bindSortedItems(tvSales, filteredSales); TableViewSupport.bindSortedItems(tvSales, filteredSales);
@@ -544,20 +543,6 @@ public class SaleController {
lblCartTotal.setText(currency.format(total)); lblCartTotal.setText(currency.format(total));
} }
private <S> TableCell<S, Double> currencyCell() {
return new TableCell<>() {
@Override
protected void updateItem(Double value, boolean empty) {
super.updateItem(value, empty);
if (empty || value == null) {
setText(null);
} else {
setText(currency.format(value));
}
}
};
}
private void setCreateSaleControlsDisabled(boolean disabled) { private void setCreateSaleControlsDisabled(boolean disabled) {
cbProduct.setDisable(disabled); cbProduct.setDisable(disabled);
spQuantity.setDisable(disabled); spQuantity.setDisable(disabled);

View File

@@ -56,6 +56,7 @@ public class ServiceController {
colServiceDesc.setCellValueFactory(new PropertyValueFactory<>("serviceDesc")); colServiceDesc.setCellValueFactory(new PropertyValueFactory<>("serviceDesc"));
colServiceDuration.setCellValueFactory(new PropertyValueFactory<>("serviceDuration")); colServiceDuration.setCellValueFactory(new PropertyValueFactory<>("serviceDuration"));
colServicePrice.setCellValueFactory(new PropertyValueFactory<>("servicePrice")); colServicePrice.setCellValueFactory(new PropertyValueFactory<>("servicePrice"));
TableViewSupport.applyCurrencyColumn(colServicePrice);
displayServices(); displayServices();
TableViewSupport.installDoubleClickAction(tvServices, selected -> openDialog(selected, "Edit")); TableViewSupport.installDoubleClickAction(tvServices, selected -> openDialog(selected, "Edit"));

View File

@@ -3,12 +3,16 @@ package org.example.petshopdesktop.util;
import javafx.collections.transformation.FilteredList; import javafx.collections.transformation.FilteredList;
import javafx.collections.transformation.SortedList; import javafx.collections.transformation.SortedList;
import javafx.animation.PauseTransition; import javafx.animation.PauseTransition;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.control.TableRow; import javafx.scene.control.TableRow;
import javafx.scene.control.TableView; import javafx.scene.control.TableView;
import javafx.scene.input.MouseButton; import javafx.scene.input.MouseButton;
import javafx.util.Duration; import javafx.util.Duration;
import java.text.NumberFormat;
import java.util.Locale;
import java.util.function.Consumer; import java.util.function.Consumer;
public final class TableViewSupport { public final class TableViewSupport {
@@ -39,6 +43,21 @@ public final class TableViewSupport {
delay.playFromStart(); delay.playFromStart();
} }
public static <S, T extends Number> void applyCurrencyColumn(TableColumn<S, T> column) {
if (column == null) {
return;
}
column.setCellFactory(col -> new TableCell<>() {
private final NumberFormat currency = NumberFormat.getCurrencyInstance(Locale.CANADA);
@Override
protected void updateItem(T value, boolean empty) {
super.updateItem(value, empty);
setText(empty || value == null ? null : currency.format(value.doubleValue()));
}
});
}
public static <T> void installDoubleClickAction(TableView<T> tableView, Consumer<T> action) { public static <T> void installDoubleClickAction(TableView<T> tableView, Consumer<T> action) {
tableView.setRowFactory(tv -> { tableView.setRowFactory(tv -> {
TableRow<T> row = new TableRow<>(); TableRow<T> row = new TableRow<>();

View File

@@ -14,31 +14,39 @@
<?import javafx.scene.layout.VBox?> <?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?> <?import javafx.scene.text.Font?>
<VBox minHeight="-Infinity" minWidth="-Infinity" spacing="20.0" style="-fx-font-size: 14px;" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.example.petshopdesktop.controllers.SaleController"> <VBox minHeight="-Infinity" minWidth="-Infinity" spacing="6.0" style="-fx-font-size: 14px;" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.example.petshopdesktop.controllers.SaleController">
<padding> <padding>
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" /> <Insets bottom="6.0" left="6.0" right="6.0" top="6.0" />
</padding> </padding>
<children> <children>
<HBox alignment="CENTER_LEFT" prefHeight="100.0" spacing="20.0"> <HBox alignment="CENTER_LEFT" prefHeight="58.0" spacing="10.0">
<children> <children>
<Label text="Sales" textFill="#2c3e50"> <Label text="Sales" textFill="#2c3e50">
<font> <font>
<Font name="System Bold" size="30.0" /> <Font name="System Bold" size="22.0" />
</font> </font>
<HBox.margin> <HBox.margin>
<Insets /> <Insets />
</HBox.margin> </HBox.margin>
</Label> </Label>
<Label fx:id="lblModeNote" text="" textFill="#7f8c8d"> <Label fx:id="lblModeNote" text="" textFill="#7f8c8d">
<font> <font>
<Font name="System Bold" size="16.0" /> <Font name="System Bold" size="12.0" />
</font> </font>
<padding> <padding>
<Insets top="10.0" /> <Insets top="6.0" />
</padding> </padding>
</Label> </Label>
<Region HBox.hgrow="ALWAYS" /> <Label fx:id="lblStatus" text="" textFill="#16a085" visible="false" managed="true">
<Button fx:id="btnRefund" mnemonicParsing="false" onAction="#btnRefund" prefHeight="44.0" style="-fx-background-color: #FF6b6b; -fx-cursor: hand; -fx-background-radius: 8;" text="Process Refund" textFill="WHITE"> <font>
<Font name="System Bold" size="12.0" />
</font>
<padding>
<Insets right="10.0" />
</padding>
</Label>
<Region HBox.hgrow="ALWAYS" />
<Button fx:id="btnRefund" mnemonicParsing="false" onAction="#btnRefund" prefHeight="36.0" style="-fx-background-color: #FF6b6b; -fx-cursor: hand; -fx-background-radius: 8;" text="Process Refund" textFill="WHITE">
<font> <font>
<Font name="System Bold" size="14.0" /> <Font name="System Bold" size="14.0" />
</font> </font>
@@ -46,7 +54,7 @@
<Insets bottom="12.0" left="24.0" right="24.0" top="12.0" /> <Insets bottom="12.0" left="24.0" right="24.0" top="12.0" />
</padding> </padding>
</Button> </Button>
<Button fx:id="btnRefresh" mnemonicParsing="false" onAction="#btnRefresh" prefHeight="44.0" prefWidth="118.0" style="-fx-background-color: #4ECDC4; -fx-cursor: hand; -fx-background-radius: 8;" text="Refresh" textFill="WHITE"> <Button fx:id="btnRefresh" mnemonicParsing="false" onAction="#btnRefresh" prefHeight="36.0" prefWidth="104.0" style="-fx-background-color: #4ECDC4; -fx-cursor: hand; -fx-background-radius: 8;" text="Refresh" textFill="WHITE">
<font> <font>
<Font name="System Bold" size="14.0" /> <Font name="System Bold" size="14.0" />
</font> </font>
@@ -57,21 +65,21 @@
</children> </children>
</HBox> </HBox>
<VBox fx:id="vbCreateSale" spacing="12.0" style="-fx-background-color: #ffffff; -fx-background-radius: 12; -fx-border-color: #e6e6e6; -fx-border-radius: 12; -fx-border-width: 1;"> <VBox fx:id="vbCreateSale" spacing="4.0" style="-fx-background-color: #ffffff; -fx-background-radius: 12; -fx-border-color: #e6e6e6; -fx-border-radius: 12; -fx-border-width: 1;">
<padding> <padding>
<Insets bottom="15.0" left="15.0" right="15.0" top="15.0" /> <Insets bottom="6.0" left="6.0" right="6.0" top="6.0" />
</padding> </padding>
<children> <children>
<Label text="Create Sale" textFill="#2c3e50"> <Label text="Create Sale" textFill="#2c3e50">
<font> <font>
<Font name="System Bold" size="18.0" /> <Font name="System Bold" size="14.0" />
</font> </font>
</Label> </Label>
<HBox alignment="CENTER_LEFT" spacing="10.0"> <HBox alignment="CENTER_LEFT" spacing="6.0">
<children> <children>
<ComboBox fx:id="cbProduct" prefHeight="36.0" prefWidth="360.0" promptText="Select a product" /> <ComboBox fx:id="cbProduct" prefHeight="28.0" prefWidth="260.0" promptText="Select a product" />
<Spinner fx:id="spQuantity" prefHeight="36.0" prefWidth="110.0" /> <Spinner fx:id="spQuantity" prefHeight="28.0" prefWidth="78.0" />
<Button fx:id="btnAddToCart" mnemonicParsing="false" onAction="#btnAddToCart" prefHeight="36.0" style="-fx-background-color: #FF6b6b; -fx-cursor: hand; -fx-background-radius: 8;" text="Add" textFill="WHITE"> <Button fx:id="btnAddToCart" mnemonicParsing="false" onAction="#btnAddToCart" prefHeight="28.0" style="-fx-background-color: #FF6b6b; -fx-cursor: hand; -fx-background-radius: 8;" text="Add" textFill="WHITE">
<font> <font>
<Font name="System Bold" size="13.0" /> <Font name="System Bold" size="13.0" />
</font> </font>
@@ -79,7 +87,7 @@
<Insets bottom="8.0" left="18.0" right="18.0" top="8.0" /> <Insets bottom="8.0" left="18.0" right="18.0" top="8.0" />
</padding> </padding>
</Button> </Button>
<Button fx:id="btnRemoveSelected" mnemonicParsing="false" onAction="#btnRemoveSelected" prefHeight="36.0" style="-fx-background-color: #34495E; -fx-cursor: hand; -fx-background-radius: 8;" text="Remove Selected" textFill="WHITE"> <Button fx:id="btnRemoveSelected" mnemonicParsing="false" onAction="#btnRemoveSelected" prefHeight="28.0" style="-fx-background-color: #34495E; -fx-cursor: hand; -fx-background-radius: 8;" text="Remove Selected" textFill="WHITE">
<font> <font>
<Font name="System Bold" size="13.0" /> <Font name="System Bold" size="13.0" />
</font> </font>
@@ -89,12 +97,7 @@
</Button> </Button>
</children> </children>
</HBox> </HBox>
<Label fx:id="lblStatus" text="" textFill="#64748b" visible="false" managed="true"> <TableView fx:id="tvCart" prefHeight="96.0" style="-fx-background-color: white; -fx-background-radius: 10;" VBox.vgrow="NEVER">
<font>
<Font size="13.0" />
</font>
</Label>
<TableView fx:id="tvCart" prefHeight="170.0" style="-fx-background-color: white; -fx-background-radius: 10;" VBox.vgrow="NEVER">
<columns> <columns>
<TableColumn fx:id="colCartProduct" prefWidth="310.0" text="Product" /> <TableColumn fx:id="colCartProduct" prefWidth="310.0" text="Product" />
<TableColumn fx:id="colCartQty" prefWidth="90.0" text="Qty" /> <TableColumn fx:id="colCartQty" prefWidth="90.0" text="Qty" />
@@ -103,16 +106,16 @@
</columns> </columns>
</TableView> </TableView>
<Separator /> <Separator />
<HBox alignment="CENTER_LEFT" spacing="12.0"> <HBox alignment="CENTER_LEFT" spacing="12.0">
<children> <children>
<Label text="Payment" textFill="#2c3e50"> <Label text="Payment" textFill="#2c3e50">
<font> <font>
<Font name="System Bold" size="13.0" /> <Font name="System Bold" size="13.0" />
</font> </font>
</Label> </Label>
<ComboBox fx:id="cbPaymentMethod" prefHeight="34.0" prefWidth="160.0" /> <ComboBox fx:id="cbPaymentMethod" prefHeight="34.0" prefWidth="160.0" />
<Region HBox.hgrow="ALWAYS" /> <Region HBox.hgrow="ALWAYS" />
<Label text="Total:" textFill="#2c3e50"> <Label text="Total:" textFill="#2c3e50">
<font> <font>
<Font name="System Bold" size="13.0" /> <Font name="System Bold" size="13.0" />
</font> </font>
@@ -144,19 +147,19 @@
</children> </children>
</VBox> </VBox>
<HBox alignment="CENTER_LEFT" prefHeight="37.0" spacing="10.0" style="-fx-background-color: white; -fx-background-radius: 14; -fx-border-width: 1; -fx-border-radius: 14; -fx-border-color: #e6e6e6;"> <HBox alignment="CENTER_LEFT" prefHeight="28.0" spacing="10.0" style="-fx-background-color: white; -fx-background-radius: 14; -fx-border-width: 1; -fx-border-radius: 14; -fx-border-color: #e6e6e6;">
<padding> <padding>
<Insets bottom="10.0" left="15.0" right="15.0" top="10.0" /> <Insets bottom="10.0" left="15.0" right="15.0" top="10.0" />
</padding> </padding>
<children> <children>
<TextField fx:id="txtSearch" prefHeight="31.0" prefWidth="150.0" promptText="Search sales..." style="-fx-border-width: 0; -fx-background-color: transparent;" HBox.hgrow="ALWAYS"> <TextField fx:id="txtSearch" prefHeight="24.0" prefWidth="150.0" promptText="Search sales..." style="-fx-border-width: 0; -fx-background-color: transparent;" HBox.hgrow="ALWAYS">
<font> <font>
<Font size="15.0" /> <Font size="15.0" />
</font> </font>
</TextField> </TextField>
</children> </children>
</HBox> </HBox>
<TableView fx:id="tvSales" prefHeight="362.0" style="-fx-background-color: white; -fx-background-radius: 12; -fx-padding: 6;" VBox.vgrow="ALWAYS"> <TableView fx:id="tvSales" prefHeight="310.0" style="-fx-background-color: white; -fx-background-radius: 12; -fx-padding: 2;" VBox.vgrow="ALWAYS">
<columns> <columns>
<TableColumn fx:id="colSaleId" minWidth="48.0" prefWidth="52.0" text="ID" /> <TableColumn fx:id="colSaleId" minWidth="48.0" prefWidth="52.0" text="ID" />
<TableColumn fx:id="colSaleDate" minWidth="115.0" prefWidth="140.0" text="Date" /> <TableColumn fx:id="colSaleDate" minWidth="115.0" prefWidth="140.0" text="Date" />