Fix sales UI
This commit is contained in:
@@ -150,12 +150,16 @@ public class SaleController {
|
||||
}
|
||||
|
||||
private void setupTables() {
|
||||
tvCart.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
|
||||
tvCart.setColumnResizePolicy(TableView.UNCONSTRAINED_RESIZE_POLICY);
|
||||
tvCart.setFixedCellSize(34);
|
||||
colCartProduct.setCellValueFactory(new PropertyValueFactory<>("prodName"));
|
||||
colCartQty.setCellValueFactory(new PropertyValueFactory<>("quantity"));
|
||||
colCartUnitPrice.setCellValueFactory(new PropertyValueFactory<>("unitPrice"));
|
||||
colCartTotal.setCellValueFactory(new PropertyValueFactory<>("total"));
|
||||
colCartProduct.setMinWidth(190);
|
||||
colCartQty.setMinWidth(70);
|
||||
colCartUnitPrice.setMinWidth(90);
|
||||
colCartTotal.setMinWidth(90);
|
||||
TableViewSupport.applyCurrencyColumn(colCartUnitPrice);
|
||||
TableViewSupport.applyCurrencyColumn(colCartTotal);
|
||||
tvCart.setItems(cartItems);
|
||||
@@ -171,6 +175,14 @@ public class SaleController {
|
||||
colSaleUnitPrice.setCellValueFactory(new PropertyValueFactory<>("unitPrice"));
|
||||
colSaleTotal.setCellValueFactory(new PropertyValueFactory<>("total"));
|
||||
colSalePaymentType.setCellValueFactory(new PropertyValueFactory<>("paymentMethod"));
|
||||
colSaleId.setMinWidth(50);
|
||||
colSaleDate.setMinWidth(150);
|
||||
colEmployeeName.setMinWidth(150);
|
||||
colServiceProduct.setMinWidth(260);
|
||||
colSaleQuantity.setMinWidth(55);
|
||||
colSaleUnitPrice.setMinWidth(100);
|
||||
colSaleTotal.setMinWidth(100);
|
||||
colSalePaymentType.setMinWidth(95);
|
||||
TableViewSupport.applyCurrencyColumn(colSaleUnitPrice);
|
||||
TableViewSupport.applyCurrencyColumn(colSaleTotal);
|
||||
|
||||
@@ -179,6 +191,12 @@ public class SaleController {
|
||||
TableViewSupport.installDoubleClickAction(tvSales, selected -> openSaleDetailDialog(selected.getSaleId()));
|
||||
|
||||
txtSearch.textProperty().addListener((obs, oldVal, newVal) -> applySalesFilter(newVal));
|
||||
tvSales.widthProperty().addListener((obs, oldWidth, newWidth) -> updateSalesColumnWidths(newWidth.doubleValue()));
|
||||
tvCart.widthProperty().addListener((obs, oldWidth, newWidth) -> updateCartColumnWidths(newWidth.doubleValue()));
|
||||
Platform.runLater(() -> {
|
||||
updateSalesColumnWidths(tvSales.getWidth());
|
||||
updateCartColumnWidths(tvCart.getWidth());
|
||||
});
|
||||
}
|
||||
|
||||
private void setupCreateSale() {
|
||||
@@ -543,6 +561,58 @@ public class SaleController {
|
||||
lblCartTotal.setText(currency.format(total));
|
||||
}
|
||||
|
||||
private void updateSalesColumnWidths(double tableWidth) {
|
||||
double available = Math.max(tableWidth - 28.0, 0.0);
|
||||
double baseWidth = 1125.0;
|
||||
if (available <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (available <= baseWidth) {
|
||||
colSaleId.setPrefWidth(60.0);
|
||||
colSaleDate.setPrefWidth(170.0);
|
||||
colEmployeeName.setPrefWidth(160.0);
|
||||
colServiceProduct.setPrefWidth(320.0);
|
||||
colSaleQuantity.setPrefWidth(70.0);
|
||||
colSaleUnitPrice.setPrefWidth(115.0);
|
||||
colSaleTotal.setPrefWidth(120.0);
|
||||
colSalePaymentType.setPrefWidth(110.0);
|
||||
return;
|
||||
}
|
||||
|
||||
double extra = available - baseWidth;
|
||||
colSaleId.setPrefWidth(60.0);
|
||||
colSaleDate.setPrefWidth(170.0 + extra * 0.18);
|
||||
colEmployeeName.setPrefWidth(160.0 + extra * 0.18);
|
||||
colServiceProduct.setPrefWidth(320.0 + extra * 0.42);
|
||||
colSaleQuantity.setPrefWidth(70.0);
|
||||
colSaleUnitPrice.setPrefWidth(115.0 + extra * 0.08);
|
||||
colSaleTotal.setPrefWidth(120.0 + extra * 0.08);
|
||||
colSalePaymentType.setPrefWidth(110.0 + extra * 0.06);
|
||||
}
|
||||
|
||||
private void updateCartColumnWidths(double tableWidth) {
|
||||
double available = Math.max(tableWidth - 28.0, 0.0);
|
||||
double baseWidth = 640.0;
|
||||
if (available <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (available <= baseWidth) {
|
||||
colCartProduct.setPrefWidth(310.0);
|
||||
colCartQty.setPrefWidth(90.0);
|
||||
colCartUnitPrice.setPrefWidth(120.0);
|
||||
colCartTotal.setPrefWidth(120.0);
|
||||
return;
|
||||
}
|
||||
|
||||
double extra = available - baseWidth;
|
||||
colCartProduct.setPrefWidth(310.0 + extra * 0.55);
|
||||
colCartQty.setPrefWidth(90.0);
|
||||
colCartUnitPrice.setPrefWidth(120.0 + extra * 0.2);
|
||||
colCartTotal.setPrefWidth(120.0 + extra * 0.25);
|
||||
}
|
||||
|
||||
private void setCreateSaleControlsDisabled(boolean disabled) {
|
||||
cbProduct.setDisable(disabled);
|
||||
spQuantity.setDisable(disabled);
|
||||
|
||||
Reference in New Issue
Block a user