PurchaseOrder Display(Data)
This commit is contained in:
@@ -1,57 +1,25 @@
|
||||
package org.example.petshopdesktop.DTOs;
|
||||
|
||||
import javafx.beans.property.*;
|
||||
|
||||
public class PurchaseOrderDTO {
|
||||
|
||||
private int purchaseOrderId;
|
||||
private String supplierName;
|
||||
private String productName;
|
||||
private int quantity;
|
||||
private double unitCost;
|
||||
private String orderDate;
|
||||
private String status;
|
||||
private IntegerProperty purchaseOrderId;
|
||||
private StringProperty supplierName;
|
||||
private StringProperty orderDate;
|
||||
private StringProperty status;
|
||||
|
||||
public PurchaseOrderDTO(int purchaseOrderId,
|
||||
String supplierName,
|
||||
String productName,
|
||||
int quantity,
|
||||
double unitCost,
|
||||
String orderDate,
|
||||
String status) {
|
||||
public PurchaseOrderDTO(int id, String supplierName,
|
||||
String orderDate, String status) {
|
||||
|
||||
this.purchaseOrderId = purchaseOrderId;
|
||||
this.supplierName = supplierName;
|
||||
this.productName = productName;
|
||||
this.quantity = quantity;
|
||||
this.unitCost = unitCost;
|
||||
this.orderDate = orderDate;
|
||||
this.status = status;
|
||||
this.purchaseOrderId = new SimpleIntegerProperty(id);
|
||||
this.supplierName = new SimpleStringProperty(supplierName);
|
||||
this.orderDate = new SimpleStringProperty(orderDate);
|
||||
this.status = new SimpleStringProperty(status);
|
||||
}
|
||||
|
||||
public int getPurchaseOrderId() {
|
||||
return purchaseOrderId;
|
||||
}
|
||||
|
||||
public String getSupplierName() {
|
||||
return supplierName;
|
||||
}
|
||||
|
||||
public String getProductName() {
|
||||
return productName;
|
||||
}
|
||||
|
||||
public int getQuantity() {
|
||||
return quantity;
|
||||
}
|
||||
|
||||
public double getUnitCost() {
|
||||
return unitCost;
|
||||
}
|
||||
|
||||
public String getOrderDate() {
|
||||
return orderDate;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
public int getPurchaseOrderId() { return purchaseOrderId.get(); }
|
||||
public String getSupplierName() { return supplierName.get(); }
|
||||
public String getOrderDate() { return orderDate.get(); }
|
||||
public String getStatus() { return status.get(); }
|
||||
}
|
||||
@@ -2,26 +2,53 @@ package org.example.petshopdesktop.controllers;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.control.cell.PropertyValueFactory;
|
||||
import org.example.petshopdesktop.DTOs.PurchaseOrderDTO;
|
||||
import org.example.petshopdesktop.database.PurchaseOrderDB;
|
||||
|
||||
public class PurchaseOrderController {
|
||||
|
||||
@FXML private Button btnRefresh;
|
||||
@FXML private TextField txtSearch;
|
||||
|
||||
@FXML private TableView<?> tvPurchaseOrders;
|
||||
@FXML private TableView<PurchaseOrderDTO> tvPurchaseOrders;
|
||||
|
||||
@FXML private TableColumn<?, ?> colOrderId;
|
||||
@FXML private TableColumn<?, ?> colSupplier;
|
||||
@FXML private TableColumn<?, ?> colOrderDate;
|
||||
@FXML private TableColumn<?, ?> colStatus;
|
||||
@FXML private TableColumn<PurchaseOrderDTO,Integer> colOrderId;
|
||||
@FXML private TableColumn<PurchaseOrderDTO,String> colSupplier;
|
||||
@FXML private TableColumn<PurchaseOrderDTO,String> colOrderDate;
|
||||
@FXML private TableColumn<PurchaseOrderDTO,String> colStatus;
|
||||
|
||||
@FXML
|
||||
public void initialize() {
|
||||
// View-only page for now
|
||||
|
||||
colOrderId.setCellValueFactory(
|
||||
new PropertyValueFactory<>("purchaseOrderId"));
|
||||
|
||||
colSupplier.setCellValueFactory(
|
||||
new PropertyValueFactory<>("supplierName"));
|
||||
|
||||
colOrderDate.setCellValueFactory(
|
||||
new PropertyValueFactory<>("orderDate"));
|
||||
|
||||
colStatus.setCellValueFactory(
|
||||
new PropertyValueFactory<>("status"));
|
||||
|
||||
loadPurchaseOrders();
|
||||
}
|
||||
|
||||
private void loadPurchaseOrders() {
|
||||
try {
|
||||
tvPurchaseOrders.setItems(
|
||||
PurchaseOrderDB.getPurchaseOrders()
|
||||
);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
new Alert(Alert.AlertType.ERROR,
|
||||
"Unable to load purchase orders").showAndWait();
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
void btnRefresh() {
|
||||
// Later: reload data
|
||||
loadPurchaseOrders();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,16 +18,12 @@ public class PurchaseOrderDB {
|
||||
|
||||
String sql = """
|
||||
SELECT po.purchaseOrderId,
|
||||
s.supCompany AS supplierName,
|
||||
p.prodName AS productName,
|
||||
poi.quantity,
|
||||
poi.unitCost,
|
||||
s.supCompany,
|
||||
po.orderDate,
|
||||
po.status
|
||||
FROM purchaseOrder po
|
||||
JOIN supplier s ON po.supId = s.supId
|
||||
JOIN purchaseOrderItem poi ON po.purchaseOrderId = poi.purchaseOrderId
|
||||
JOIN product p ON poi.prodId = p.prodId
|
||||
ORDER BY po.purchaseOrderId
|
||||
""";
|
||||
|
||||
Statement stmt = conn.createStatement();
|
||||
@@ -37,10 +33,7 @@ public class PurchaseOrderDB {
|
||||
|
||||
list.add(new PurchaseOrderDTO(
|
||||
rs.getInt("purchaseOrderId"),
|
||||
rs.getString("supplierName"),
|
||||
rs.getString("productName"),
|
||||
rs.getInt("quantity"),
|
||||
rs.getDouble("unitCost"),
|
||||
rs.getString("supCompany"),
|
||||
rs.getString("orderDate"),
|
||||
rs.getString("status")
|
||||
));
|
||||
|
||||
Reference in New Issue
Block a user