From 98979efd46b9d2371850aac6876b41f961f92b85 Mon Sep 17 00:00:00 2001 From: Nikitha Date: Mon, 23 Feb 2026 16:31:30 -0700 Subject: [PATCH] PurchaseOrder Update --- .../petshopdesktop/DTOs/PurchaseOrderDTO.java | 57 +++++++++++++++++++ .../database/PurchaseOrderDB.java | 50 +++++++++++++++- .../petshopdesktop/models/PurchaseOrder.java | 36 ++++++------ 3 files changed, 122 insertions(+), 21 deletions(-) create mode 100644 src/main/java/org/example/petshopdesktop/DTOs/PurchaseOrderDTO.java diff --git a/src/main/java/org/example/petshopdesktop/DTOs/PurchaseOrderDTO.java b/src/main/java/org/example/petshopdesktop/DTOs/PurchaseOrderDTO.java new file mode 100644 index 00000000..5bd3e4b6 --- /dev/null +++ b/src/main/java/org/example/petshopdesktop/DTOs/PurchaseOrderDTO.java @@ -0,0 +1,57 @@ +package org.example.petshopdesktop.DTOs; + +public class PurchaseOrderDTO { + + private int purchaseOrderId; + private String supplierName; + private String productName; + private int quantity; + private double unitCost; + private String orderDate; + private String status; + + public PurchaseOrderDTO(int purchaseOrderId, + String supplierName, + String productName, + int quantity, + double unitCost, + 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; + } + + 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; + } +} \ No newline at end of file diff --git a/src/main/java/org/example/petshopdesktop/database/PurchaseOrderDB.java b/src/main/java/org/example/petshopdesktop/database/PurchaseOrderDB.java index 926c7ce0..1c59b8a9 100644 --- a/src/main/java/org/example/petshopdesktop/database/PurchaseOrderDB.java +++ b/src/main/java/org/example/petshopdesktop/database/PurchaseOrderDB.java @@ -1,4 +1,52 @@ package org.example.petshopdesktop.database; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import org.example.petshopdesktop.DTOs.PurchaseOrderDTO; + +import java.sql.*; + public class PurchaseOrderDB { -} + + public static ObservableList getPurchaseOrders() + throws SQLException { + + ObservableList list = + FXCollections.observableArrayList(); + + Connection conn = ConnectionDB.getConnection(); + + String sql = """ + SELECT po.purchaseOrderId, + s.supCompany AS supplierName, + p.prodName AS productName, + poi.quantity, + poi.unitCost, + 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 + """; + + Statement stmt = conn.createStatement(); + ResultSet rs = stmt.executeQuery(sql); + + while (rs.next()) { + + list.add(new PurchaseOrderDTO( + rs.getInt("purchaseOrderId"), + rs.getString("supplierName"), + rs.getString("productName"), + rs.getInt("quantity"), + rs.getDouble("unitCost"), + rs.getString("orderDate"), + rs.getString("status") + )); + } + + conn.close(); + return list; + } +} \ No newline at end of file diff --git a/src/main/java/org/example/petshopdesktop/models/PurchaseOrder.java b/src/main/java/org/example/petshopdesktop/models/PurchaseOrder.java index 67a25897..3b1cf838 100644 --- a/src/main/java/org/example/petshopdesktop/models/PurchaseOrder.java +++ b/src/main/java/org/example/petshopdesktop/models/PurchaseOrder.java @@ -1,39 +1,35 @@ package org.example.petshopdesktop.models; -import javafx.beans.property.SimpleIntegerProperty; -import javafx.beans.property.SimpleStringProperty; - public class PurchaseOrder { - private SimpleIntegerProperty orderId; - private SimpleStringProperty supplierName; - private SimpleStringProperty orderDate; - private SimpleStringProperty status; + private int purchaseOrderId; + private int supId; + private String orderDate; + private String status; - public PurchaseOrder(int orderId, - String supplierName, + public PurchaseOrder(int purchaseOrderId, + int supId, String orderDate, String status) { - - this.orderId = new SimpleIntegerProperty(orderId); - this.supplierName = new SimpleStringProperty(supplierName); - this.orderDate = new SimpleStringProperty(orderDate); - this.status = new SimpleStringProperty(status); + this.purchaseOrderId = purchaseOrderId; + this.supId = supId; + this.orderDate = orderDate; + this.status = status; } - public int getOrderId() { - return orderId.get(); + public int getPurchaseOrderId() { + return purchaseOrderId; } - public String getSupplierName() { - return supplierName.get(); + public int getSupId() { + return supId; } public String getOrderDate() { - return orderDate.get(); + return orderDate; } public String getStatus() { - return status.get(); + return status; } } \ No newline at end of file