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