PurchaseOrder Update
This commit is contained in:
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,52 @@
|
|||||||
package org.example.petshopdesktop.database;
|
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 class PurchaseOrderDB {
|
||||||
|
|
||||||
|
public static ObservableList<PurchaseOrderDTO> getPurchaseOrders()
|
||||||
|
throws SQLException {
|
||||||
|
|
||||||
|
ObservableList<PurchaseOrderDTO> 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,39 +1,35 @@
|
|||||||
package org.example.petshopdesktop.models;
|
package org.example.petshopdesktop.models;
|
||||||
|
|
||||||
import javafx.beans.property.SimpleIntegerProperty;
|
|
||||||
import javafx.beans.property.SimpleStringProperty;
|
|
||||||
|
|
||||||
public class PurchaseOrder {
|
public class PurchaseOrder {
|
||||||
|
|
||||||
private SimpleIntegerProperty orderId;
|
private int purchaseOrderId;
|
||||||
private SimpleStringProperty supplierName;
|
private int supId;
|
||||||
private SimpleStringProperty orderDate;
|
private String orderDate;
|
||||||
private SimpleStringProperty status;
|
private String status;
|
||||||
|
|
||||||
public PurchaseOrder(int orderId,
|
public PurchaseOrder(int purchaseOrderId,
|
||||||
String supplierName,
|
int supId,
|
||||||
String orderDate,
|
String orderDate,
|
||||||
String status) {
|
String status) {
|
||||||
|
this.purchaseOrderId = purchaseOrderId;
|
||||||
this.orderId = new SimpleIntegerProperty(orderId);
|
this.supId = supId;
|
||||||
this.supplierName = new SimpleStringProperty(supplierName);
|
this.orderDate = orderDate;
|
||||||
this.orderDate = new SimpleStringProperty(orderDate);
|
this.status = status;
|
||||||
this.status = new SimpleStringProperty(status);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getOrderId() {
|
public int getPurchaseOrderId() {
|
||||||
return orderId.get();
|
return purchaseOrderId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSupplierName() {
|
public int getSupId() {
|
||||||
return supplierName.get();
|
return supId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getOrderDate() {
|
public String getOrderDate() {
|
||||||
return orderDate.get();
|
return orderDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getStatus() {
|
public String getStatus() {
|
||||||
return status.get();
|
return status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user