Refine Desktop Pricing

This commit is contained in:
2026-04-09 17:29:03 -06:00
parent 6e21e4fd6c
commit fe7e81986d
7 changed files with 79 additions and 68 deletions

View File

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

View File

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

View File

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

View File

@@ -11,7 +11,6 @@ import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TableCell;
import javafx.scene.control.Label;
import javafx.scene.control.SelectionMode;
import javafx.scene.control.Spinner;
@@ -157,8 +156,8 @@ public class SaleController {
colCartQty.setCellValueFactory(new PropertyValueFactory<>("quantity"));
colCartUnitPrice.setCellValueFactory(new PropertyValueFactory<>("unitPrice"));
colCartTotal.setCellValueFactory(new PropertyValueFactory<>("total"));
colCartUnitPrice.setCellFactory(column -> currencyCell());
colCartTotal.setCellFactory(column -> currencyCell());
TableViewSupport.applyCurrencyColumn(colCartUnitPrice);
TableViewSupport.applyCurrencyColumn(colCartTotal);
tvCart.setItems(cartItems);
tvCart.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
@@ -172,8 +171,8 @@ public class SaleController {
colSaleUnitPrice.setCellValueFactory(new PropertyValueFactory<>("unitPrice"));
colSaleTotal.setCellValueFactory(new PropertyValueFactory<>("total"));
colSalePaymentType.setCellValueFactory(new PropertyValueFactory<>("paymentMethod"));
colSaleUnitPrice.setCellFactory(column -> currencyCell());
colSaleTotal.setCellFactory(column -> currencyCell());
TableViewSupport.applyCurrencyColumn(colSaleUnitPrice);
TableViewSupport.applyCurrencyColumn(colSaleTotal);
filteredSales = new FilteredList<>(saleItems, s -> true);
TableViewSupport.bindSortedItems(tvSales, filteredSales);
@@ -544,20 +543,6 @@ public class SaleController {
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) {
cbProduct.setDisable(disabled);
spQuantity.setDisable(disabled);

View File

@@ -56,6 +56,7 @@ public class ServiceController {
colServiceDesc.setCellValueFactory(new PropertyValueFactory<>("serviceDesc"));
colServiceDuration.setCellValueFactory(new PropertyValueFactory<>("serviceDuration"));
colServicePrice.setCellValueFactory(new PropertyValueFactory<>("servicePrice"));
TableViewSupport.applyCurrencyColumn(colServicePrice);
displayServices();
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.SortedList;
import javafx.animation.PauseTransition;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.Label;
import javafx.scene.control.TableRow;
import javafx.scene.control.TableView;
import javafx.scene.input.MouseButton;
import javafx.util.Duration;
import java.text.NumberFormat;
import java.util.Locale;
import java.util.function.Consumer;
public final class TableViewSupport {
@@ -39,6 +43,21 @@ public final class TableViewSupport {
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) {
tableView.setRowFactory(tv -> {
TableRow<T> row = new TableRow<>();

View File

@@ -14,31 +14,39 @@
<?import javafx.scene.layout.VBox?>
<?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">
<padding>
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
</padding>
<children>
<HBox alignment="CENTER_LEFT" prefHeight="100.0" spacing="20.0">
<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>
<Insets bottom="6.0" left="6.0" right="6.0" top="6.0" />
</padding>
<children>
<HBox alignment="CENTER_LEFT" prefHeight="58.0" spacing="10.0">
<children>
<Label text="Sales" textFill="#2c3e50">
<font>
<Font name="System Bold" size="30.0" />
</font>
<Label text="Sales" textFill="#2c3e50">
<font>
<Font name="System Bold" size="22.0" />
</font>
<HBox.margin>
<Insets />
</HBox.margin>
</Label>
<Label fx:id="lblModeNote" text="" textFill="#7f8c8d">
<font>
<Font name="System Bold" size="16.0" />
</font>
<padding>
<Insets top="10.0" />
</padding>
</Label>
<Region HBox.hgrow="ALWAYS" />
<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 name="System Bold" size="12.0" />
</font>
<padding>
<Insets top="6.0" />
</padding>
</Label>
<Label fx:id="lblStatus" text="" textFill="#16a085" visible="false" managed="true">
<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 name="System Bold" size="14.0" />
</font>
@@ -46,7 +54,7 @@
<Insets bottom="12.0" left="24.0" right="24.0" top="12.0" />
</padding>
</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 name="System Bold" size="14.0" />
</font>
@@ -57,21 +65,21 @@
</children>
</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;">
<padding>
<Insets bottom="15.0" left="15.0" right="15.0" top="15.0" />
</padding>
<children>
<Label text="Create Sale" textFill="#2c3e50">
<font>
<Font name="System Bold" size="18.0" />
</font>
</Label>
<HBox alignment="CENTER_LEFT" spacing="10.0">
<children>
<ComboBox fx:id="cbProduct" prefHeight="36.0" prefWidth="360.0" promptText="Select a product" />
<Spinner fx:id="spQuantity" prefHeight="36.0" prefWidth="110.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">
<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>
<Insets bottom="6.0" left="6.0" right="6.0" top="6.0" />
</padding>
<children>
<Label text="Create Sale" textFill="#2c3e50">
<font>
<Font name="System Bold" size="14.0" />
</font>
</Label>
<HBox alignment="CENTER_LEFT" spacing="6.0">
<children>
<ComboBox fx:id="cbProduct" prefHeight="28.0" prefWidth="260.0" promptText="Select a product" />
<Spinner fx:id="spQuantity" prefHeight="28.0" prefWidth="78.0" />
<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 name="System Bold" size="13.0" />
</font>
@@ -79,7 +87,7 @@
<Insets bottom="8.0" left="18.0" right="18.0" top="8.0" />
</padding>
</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 name="System Bold" size="13.0" />
</font>
@@ -89,12 +97,7 @@
</Button>
</children>
</HBox>
<Label fx:id="lblStatus" text="" textFill="#64748b" visible="false" managed="true">
<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">
<TableView fx:id="tvCart" prefHeight="96.0" style="-fx-background-color: white; -fx-background-radius: 10;" VBox.vgrow="NEVER">
<columns>
<TableColumn fx:id="colCartProduct" prefWidth="310.0" text="Product" />
<TableColumn fx:id="colCartQty" prefWidth="90.0" text="Qty" />
@@ -103,16 +106,16 @@
</columns>
</TableView>
<Separator />
<HBox alignment="CENTER_LEFT" spacing="12.0">
<children>
<HBox alignment="CENTER_LEFT" spacing="12.0">
<children>
<Label text="Payment" textFill="#2c3e50">
<font>
<Font name="System Bold" size="13.0" />
</font>
</Label>
<ComboBox fx:id="cbPaymentMethod" prefHeight="34.0" prefWidth="160.0" />
<Region HBox.hgrow="ALWAYS" />
<Label text="Total:" textFill="#2c3e50">
<ComboBox fx:id="cbPaymentMethod" prefHeight="34.0" prefWidth="160.0" />
<Region HBox.hgrow="ALWAYS" />
<Label text="Total:" textFill="#2c3e50">
<font>
<Font name="System Bold" size="13.0" />
</font>
@@ -144,19 +147,19 @@
</children>
</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>
<Insets bottom="10.0" left="15.0" right="15.0" top="10.0" />
</padding>
<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 size="15.0" />
</font>
</TextField>
</children>
</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>
<TableColumn fx:id="colSaleId" minWidth="48.0" prefWidth="52.0" text="ID" />
<TableColumn fx:id="colSaleDate" minWidth="115.0" prefWidth="140.0" text="Date" />