Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
rename Purchase to Restock` for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
jhdcruz committed Dec 8, 2022
1 parent 77755fe commit ca6d874
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 45 deletions.
57 changes: 29 additions & 28 deletions src/main/java/com/pharmacy/Controllers/ProductController.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void addProduct(ProductModel productModel) {
}
}

public void addPurchaseInfo(ProductModel productModel) {
public void addRestockInfo(ProductModel productModel) {
java.sql.Date date = new java.sql.Date(productModel.getDate().getTime());

try {
Expand Down Expand Up @@ -171,11 +171,12 @@ public void updateProduct(ProductModel productModel) {

/**
* Handling of stocks in Purchase page (-)
* when a restocking info is deleted
*
* @param code product code
* @param quantity quantity of product
*/
public void updatePurchaseStock(String code, int quantity) {
public void reduceProductStock(String code, int quantity) {
try {
String query = "SELECT * FROM products WHERE product_code='" + code + "'";
resultSet = statement.executeQuery(query);
Expand Down Expand Up @@ -232,7 +233,7 @@ public void deleteProduct(int pid) {
}
}

public void deletePurchaseInfo(int id) {
public void deleteRestockInfo(int id) {
try {
String query = "DELETE FROM purchaseinfo WHERE purchase_id=?";
preparedStatement = connection.prepareStatement(query);
Expand Down Expand Up @@ -297,8 +298,8 @@ public void sellProduct(ProductModel productModel, String username) {
public ResultSet getProducts() {
try {
String query = """
SELECT pid, product_code, product_name, description, quantity, cost_price, sell_price, supplied_by, expiration_date, last_updated FROM products;
""";
SELECT pid, product_code, product_name, description, quantity, cost_price, sell_price, supplied_by, expiration_date, last_updated FROM products;
""";

resultSet = statement.executeQuery(query);
} catch (SQLException throwables) {
Expand All @@ -309,7 +310,7 @@ public ResultSet getProducts() {
}

// Purchase table data set retrieval
public ResultSet getPurchaseInfo() {
public ResultSet getRestockInfo() {
try {
String query = "SELECT purchase_id, purchaseinfo.product_code,product_name,purchaseinfo.quantity,total_cost "
+ "FROM purchaseinfo INNER JOIN products "
Expand All @@ -326,14 +327,14 @@ public ResultSet getPurchaseInfo() {
public ResultSet getSalesInfo() {
try {
String query = """
SELECT sales_id, products.product_name AS products_code,
customers.full_name AS customer_code, salesinfo.quantity, revenue,
date, users.name AS sold_by
FROM salesinfo
INNER JOIN products ON salesinfo.product_code = products.product_code
INNER JOIN customers ON salesinfo.customer_code = customers.customer_code
INNER JOIN users ON salesinfo.sold_by = users.name;
""";
SELECT sales_id, products.product_name AS products_code,
customers.full_name AS customer_code, salesinfo.quantity, revenue,
date, users.name AS sold_by
FROM salesinfo
INNER JOIN products ON salesinfo.product_code = products.product_code
INNER JOIN customers ON salesinfo.customer_code = customers.customer_code
INNER JOIN users ON salesinfo.sold_by = users.name;
""";

resultSet = statement.executeQuery(query);
} catch (SQLException throwables) {
Expand All @@ -347,7 +348,7 @@ public ResultSet getSalesInfo() {
public ResultSet getProductSearch(String text) {
try {
String query = "SELECT pid, product_code, product_name, description, quantity, cost_price, sell_price, supplied_by, expiration_date, last_updated FROM products "
+ "WHERE product_code LIKE '%" + text + "%' OR product_name LIKE '%" + text + "%' OR supplied_by LIKE '%" + text + "%'";
+ "WHERE product_code LIKE '%" + text + "%' OR product_name LIKE '%" + text + "%' OR supplied_by LIKE '%" + text + "%'";
resultSet = statement.executeQuery(query);
} catch (SQLException e) {
e.printStackTrace();
Expand All @@ -373,18 +374,18 @@ public ResultSet getProdFromCode(String text) {
public ResultSet getSalesSearch(String text) {
try {
String query = """
SELECT sales_id, products.product_name AS products_code,
customers.full_name AS customer_code, salesinfo.quantity, revenue,
date, users.name AS sold_by
FROM salesinfo
INNER JOIN products ON salesinfo.product_code = products.product_code
INNER JOIN customers ON salesinfo.customer_code = customers.customer_code
INNER JOIN users ON salesinfo.sold_by = users.name
WHERE salesinfo.product_code LIKE '%""" + text + "%'"
+ "OR product_name LIKE '%" + text + "%' "
+ "OR users.name LIKE '%" + text + "%'"
+ "OR customers.full_name LIKE '%" + text + "%'"
+ "ORDER BY sales_id;";
SELECT sales_id, products.product_name AS products_code,
customers.full_name AS customer_code, salesinfo.quantity, revenue,
date, users.name AS sold_by
FROM salesinfo
INNER JOIN products ON salesinfo.product_code = products.product_code
INNER JOIN customers ON salesinfo.customer_code = customers.customer_code
INNER JOIN users ON salesinfo.sold_by = users.name
WHERE salesinfo.product_code LIKE '%""" + text + "%'"
+ "OR product_name LIKE '%" + text + "%' "
+ "OR users.name LIKE '%" + text + "%'"
+ "OR customers.full_name LIKE '%" + text + "%'"
+ "ORDER BY sales_id;";

resultSet = statement.executeQuery(query);
} catch (SQLException e) {
Expand All @@ -395,7 +396,7 @@ public ResultSet getSalesSearch(String text) {
}

// Search method for purchase logs
public ResultSet getPurchaseSearch(String text) {
public ResultSet getRestockSearch(String text) {
try {
String query = "SELECT purchase_id,purchaseinfo.product_code,products.product_name,quantity,total_cost\n"
+ "FROM purchaseinfo INNER JOIN products ON purchaseinfo.product_code=products.product_code\n"
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/pharmacy/Views/Dashboard.form
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Liberation Sans" size="15" style="1"/>
</Property>
<Property name="text" type="java.lang.String" value="Purchase"/>
<Property name="text" type="java.lang.String" value="Restock"/>
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
<Color id="Hand Cursor"/>
</Property>
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/pharmacy/Views/Dashboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Dashboard(String username, String userType, UserModel userModel) {
displayPanel.add("Products", new ProductPage(this));
displayPanel.add("Suppliers", new SupplierPage());
displayPanel.add("Sales", new SalesPage(username, this));
displayPanel.add("Purchase", new PurchasePage(this));
displayPanel.add("Restock", new RestockPage(this));
displayPanel.add("Logs", new UserLogsPage());

this.addWindowListener(new WindowAdapter() {
Expand Down Expand Up @@ -97,8 +97,8 @@ public void addSalesPage() {
layout.show(displayPanel, "Sales");
}

public void addPurchasePage() {
layout.show(displayPanel, "Purchase");
public void addRestockPage() {
layout.show(displayPanel, "Restock");
}

public void addLogsPage() {
Expand Down Expand Up @@ -190,7 +190,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
});

purchaseButton.setFont(new java.awt.Font("Liberation Sans", 1, 15)); // NOI18N
purchaseButton.setText("Purchase");
purchaseButton.setText("Restock");
purchaseButton.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
purchaseButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Expand Down Expand Up @@ -354,7 +354,7 @@ private void homeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FI
}//GEN-LAST:event_homeButtonActionPerformed

private void purchaseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_purchaseButtonActionPerformed
addPurchasePage();
addRestockPage();
}//GEN-LAST:event_purchaseButtonActionPerformed

private void logsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_logsButtonActionPerformed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Impact" size="24" style="1"/>
</Property>
<Property name="text" type="java.lang.String" value="PURCHASE"/>
<Property name="text" type="java.lang.String" value="RESTOCK"/>
</Properties>
</Component>
<Component class="javax.swing.JSeparator" name="jSeparator1">
Expand All @@ -76,7 +76,7 @@
<Properties>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.TitledBorderInfo">
<TitledBorder title="Purchase Product"/>
<TitledBorder title="Restock Product"/>
</Border>
</Property>
</Properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
import java.sql.ResultSet;
import java.sql.SQLException;

public class PurchasePage extends javax.swing.JPanel {
public class RestockPage extends javax.swing.JPanel {

ProductModel productModel;
Dashboard dashboard;

int quantity;
String prodCode = null;

public PurchasePage(Dashboard dashboard) {
public RestockPage(Dashboard dashboard) {
this.dashboard = dashboard;

initComponents();
Expand Down Expand Up @@ -63,9 +63,9 @@ private void initComponents() {
jLabel10 = new javax.swing.JLabel();

jLabel1.setFont(new java.awt.Font("Impact", 1, 24)); // NOI18N
jLabel1.setText("PURCHASE");
jLabel1.setText("RESTOCK");

jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Purchase Product"));
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Restock Product"));

jLabel2.setText("Supplier:");

Expand Down Expand Up @@ -342,7 +342,7 @@ private void purchaseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GE
productModel.setTotalCost(totalCost);

EventQueue.invokeLater(() -> {
new ProductController().addPurchaseInfo(productModel);
new ProductController().addRestockInfo(productModel);
loadDataSet();
});
} else {
Expand All @@ -368,8 +368,8 @@ private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
JOptionPane.YES_NO_OPTION);
if (opt == JOptionPane.YES_OPTION) {
EventQueue.invokeLater(() -> {
new ProductController().deletePurchaseInfo((int) purchaseTable.getValueAt(purchaseTable.getSelectedRow(), 0));
new ProductController().updatePurchaseStock(prodCode, quantity);
new ProductController().deleteRestockInfo((int) purchaseTable.getValueAt(purchaseTable.getSelectedRow(), 0));
new ProductController().reduceProductStock(prodCode, quantity);
loadDataSet();
});
}
Expand Down Expand Up @@ -446,7 +446,7 @@ public void loadDataSet() {
EventQueue.invokeLater(() -> {
try {
ProductController productController = new ProductController();
purchaseTable.setModel(new DataTableModel().buildTableModel(productController.getPurchaseInfo()));
purchaseTable.setModel(new DataTableModel().buildTableModel(productController.getRestockInfo()));
} catch (SQLException throwables) {
throwables.printStackTrace();
}
Expand All @@ -458,7 +458,7 @@ public void loadSearchData(String text) {
EventQueue.invokeLater(() -> {
try {
ProductController productController = new ProductController();
purchaseTable.setModel(new DataTableModel().buildTableModel(productController.getPurchaseSearch(text)));
purchaseTable.setModel(new DataTableModel().buildTableModel(productController.getRestockSearch(text)));
} catch (SQLException e) {
e.printStackTrace();
}
Expand Down

0 comments on commit ca6d874

Please sign in to comment.