@@ -112,10 +227,9 @@ const Manager = () => {
- ID |
- Name |
- Age |
- Number |
+ {tab.tableData.length > 0 && Object.keys(tab.tableData[0]).map((key) => (
+ {key} |
+ ))}
@@ -125,6 +239,7 @@ const Manager = () => {
{data[key]} |
))}
+
))}
@@ -133,22 +248,13 @@ const Manager = () => {
- {/*
*/}
- {showForm ? (
+
+ {activeTab === 0 ?
+ {showInventoryForm ? (
-
) : (
-
+
)}
-
+
: null}
+ {activeTab === 2 ?
+ {showProductsForm ? (
+
+
+
+ ) : (
+
+
+
+ )}
+
: null}
+ {activeTab === 6 ?
+ {showEmployeesForm ? (
+
+
+
+ ) : (
+
+
+
+ )}
+
: null}
+ {activeTab === 7 ?
+ {showCustomersForm ? (
+
+
+
+ ) : (
+
+
+
+ )}
+
: null}
+ {activeTab === 8 ?
{showRecipesForm ? (
+
+
+
+ ) : (
+
+
+
+ )}
+
: null}
+ {activeTab === 10 ?
+
+
+
+
+
+
+
: null}
+
+
)
From 2931bfafd460cd4ee408606fdf58c8ce44e91b7d Mon Sep 17 00:00:00 2001
From: Chenners13 <123605456+Chenners13@users.noreply.github.com>
Date: Tue, 2 May 2023 14:51:22 -0500
Subject: [PATCH 16/17] Functions added for reports
---
backend/server.js | 27 +++++++++++++--------------
backend/server_functions.js | 18 +++++++++++-------
2 files changed, 24 insertions(+), 21 deletions(-)
diff --git a/backend/server.js b/backend/server.js
index 323c515..8fd6fdb 100644
--- a/backend/server.js
+++ b/backend/server.js
@@ -37,6 +37,7 @@ app.get('/queryInventory/:start/:end', async (req, res) => {
queryToUse = 'SELECT * FROM inventory WHERE id >= ' + start + ' AND id <= ' + end + ' ORDER BY id';
}
console.log(queryToUse);
+
const { rows } = await pool.query(queryToUse);
res.json(rows);
//console.log(rows);
@@ -53,7 +54,7 @@ app.get('/queryProducts/:start/:end', async (req, res) => {
var queryToUse;
if((start === 0) && (end === 0)){
queryToUse = 'SELECT * FROM products ORDER BY id limit 10';
- }
+ }
else{
queryToUse = 'SELECT * FROM products WHERE id >= ' + start + ' AND id <= ' + end + ' ORDER BY id';
}
@@ -317,22 +318,20 @@ app.post('/add-recipes', async (req, res) => {
});
app.get('/salesReport/:start/:end', async (req, res) => {
try {
- const start = parseInt(req.params.start);
- const end = parseInt(req.params.end);
- var queryToUse;
- if((start === 0) && (end === 0)){
- queryToUse = 'SELECT * FROM inventory ORDER BY id limit 10';
- }
- else{
- queryToUse = 'SELECT * FROM inventory WHERE id >= ' + start + ' AND id <= ' + end + ' ORDER BY id';
- }
- console.log(queryToUse);
+ const start = req.params.start;
+ const end = req.params.end;
+ const queryToUse = "SELECT p.product_name, COUNT(*) AS total_sales "+
+ "FROM orders o "+
+ "JOIN sales s ON o.sale_id = s.id " +
+ "JOIN products p ON o.product_id = p.id " +
+ "WHERE s.date BETWEEN '"+start+"' AND '"+end+"' " +
+ "GROUP BY p.product_name "+
+ "ORDER BY total_sales DESC;";
+ // console.log(queryToUse);
const { rows } = await pool.query(queryToUse);
res.json(rows);
- //console.log(rows);
} catch (err) {
-
- console.error("Read query in inventory failed " +err);
+ console.error("Read query in sales failed " + err);
res.status(500).json({ error: 'Internal server error' });
}
});
diff --git a/backend/server_functions.js b/backend/server_functions.js
index e012dba..5bbd4b5 100644
--- a/backend/server_functions.js
+++ b/backend/server_functions.js
@@ -293,19 +293,23 @@ function AddtoRecipes(info) {
handleSubmit()
}
-function SalesReport(start, end){
- return new Promise((resolve, reject) => {
- async function fetchInventoryItems() {
+function GetSalesReport(start, end){
+ const [salesData, setSalesData] = useState([]);
+ //console.log(`${host}/salesHistoryRequest/${start}/${end}`);
+ useEffect(() => {
+ async function fetchSalesReport() {
const response = await fetch(`http://localhost:3001/salesReport/${start}/${end}`);
const data = await response.json();
- resolve(data);
+ setSalesData(data);
+ // console.table(data);
}
- fetchInventoryItems().catch(reject);
- });
+ fetchSalesReport();
+ }, [start, end]);
+ return salesData;
}
export {GetInventoryList, GetCurrentInventoryList, GetProductsList, GetCustomizationsList, GetSalesList, GetOrdersList, GetEmployeesList
, GetCustomersList, GetRecipesList, GetSizesList, AddtoInventory, AddtoCustomers, AddtoEmployees, AddtoProducts,
- AddtoRecipes, SalesReport
+ AddtoRecipes, GetSalesReport
};
From c64de776c5d620238ff8913c46d7dd0ee62ae384 Mon Sep 17 00:00:00 2001
From: Chenners13 <123605456+Chenners13@users.noreply.github.com>
Date: Tue, 2 May 2023 14:51:44 -0500
Subject: [PATCH 17/17] Sales report added
---
pages/Manager.js | 146 +++++++++++++++++++++++++++++++----------------
1 file changed, 98 insertions(+), 48 deletions(-)
diff --git a/pages/Manager.js b/pages/Manager.js
index 92248a4..dbf1c70 100644
--- a/pages/Manager.js
+++ b/pages/Manager.js
@@ -2,17 +2,22 @@ import React, { useState , useEffect} from 'react';
import styled from 'styled-components';
import {GetInventoryList, GetCurrentInventoryList, GetProductsList, GetCustomizationsList, GetSalesList, GetOrdersList, GetEmployeesList
, GetCustomersList, GetRecipesList, GetSizesList, AddtoInventory, AddtoCustomers, AddtoEmployees, AddtoProducts,
- AddtoRecipes, SalesReport} from '../backend/server_functions';
+ AddtoRecipes, GetSalesReport} from '../backend/server_functions';
const Manager = () => {
const [activeTab, setActiveTab] = useState(0); // Define the active tab state
+ const [activeReport, setReport] = useState(0); // Define the active tab state
+ const [startDate, setStartDate] = useState('2020-01-01'); // Define the active tab state
+ const [endDate, setEndDate] = useState('2024-01-01'); // Define the active tab state
+
+
const [showInventoryForm, setShowInventoryForm] = useState(false);
const [showProductsForm, setShowProductsForm] = useState(false);
const [showEmployeesForm, setShowEmployeesForm] = useState(false);
const [showCustomersForm, setShowCustomersForm] = useState(false);
const [showRecipesForm, setShowRecipesForm] = useState(false);
const [showReportForm, setShowReportForm] = useState(false);
-
+
const starting_inventory = GetInventoryList(0, 0)
const productData = GetProductsList(0,0);
@@ -53,7 +58,7 @@ const Manager = () => {
// });
// }, []);
- let tabs = [
+ const tabs = [
{ id: 0, name: 'Inventory', tableData: starting_inventory},
{ id: 1, name: 'Transactions', tableData: []},
{ id: 2, name: 'Products', tableData: productData },
@@ -65,15 +70,16 @@ const Manager = () => {
{ id: 8, name: 'Recipes', tableData: recipeData },
{ id: 9, name: 'Sizes', tableData: sizeData },
{ id: 10, name: 'Reports', tableData: [
- {id: 0, name: 'Sales Report', reportData: []},
- {id: 1, name: 'X Report', reportData: []},
- {id: 2, name: 'Z Report', reportData: []},
- {id: 3, name: 'Excess Report', reportData: []},
- {id: 4, name: 'Restock Report', reportData: []},
- {id: 5, name: 'What Sells Together', reportData: []},
+ {id: 0, name: 'Sales Report', reportData: GetSalesReport(startDate, endDate)},
+ {id: 1, name: 'X Report', reportData: ['X report']},
+ {id: 2, name: 'Z Report', reportData: ['Z report']},
+ {id: 3, name: 'Excess Report', reportData: ['Excess']},
+ {id: 4, name: 'Restock Report', reportData: ['Restock']},
+ {id: 5, name: 'What Sells Together', reportData: ['What Sells together']},
] },
];
-
+ // console.log("SALES REPORT")
+ // console.log(GetSalesReport('2021-01-01', '2024-01-01'))
function handleInventorySubmit(event) {
event.preventDefault();
if(showInventoryForm){
@@ -90,8 +96,11 @@ const Manager = () => {
AddtoInventory(info)
GetCurrentInventoryList(0, 0)
.then(data => {
- tabs[0].tableData = data;
-
+ // tabs[0].tableData = data;
+ let newTabs = [...tabs]
+ newTabs[0].tableData = data;
+ console.log(newTabs)
+
})
.catch(error => {
console.error(error);
@@ -111,7 +120,7 @@ const Manager = () => {
const info = [productID, productName,productType, productPrice, productDescription, DateOfLastUpdate]
console.log("product")
- // console.log(info)
+ console.log(info)
AddtoProducts(info)
}
setShowProductsForm(!showProductsForm);
@@ -165,26 +174,19 @@ const Manager = () => {
}
function handleReportSubmit(event) {
event.preventDefault();
- if(showReportForm){
const start = event.target.elements.start.value;
const end = event.target.elements.end.value;
const info = [start, end]
- console.log("report")
- // console.log(info)
- SalesReport(info)
- .then(data => {
- tabs[0].tableData = data;
-
- })
- .catch(error => {
- console.error(error);
- });
- }
- setShowReportForm(!showReportForm);
+ // console.log("report")
+ setStartDate(start)
+ setEndDate(end)
}
const handleTabClick = (tabIndex) => {
setActiveTab(tabIndex); // Update the active tab state when a tab is clicked
};
+ const handleReportClick = (ReportIndex) => {
+ setReport(ReportIndex); // Update the active tab state when a tab is clicked
+ };
return (
{
{activeTab === 2 ?
{showProductsForm ? (
-
)}
: null}
- {activeTab === 10 ?
+ {activeTab === 10 ?
+
+
+
+
+ {tabs[10].tableData.map((tableData) => (
+
handleReportClick(tableData.id)}
+ style={{
+ backgroundColor: activeReport=== tableData.id ? '#1e3932' : '#00754a',
+ color: 'white',
+ padding: '10px',
+ cursor: 'pointer',
+ }}
+ >
+ {tableData.name}
+
+ ))}
+
+
+ {tabs[10].tableData.map((reportTab) => (
+
+
+
+
+ {reportTab.reportData.length > 0 && Object.keys(reportTab.reportData[0]).map((key) => (
+ {key} |
+ ))}
+
+
+
+ {reportTab.reportData.map((data) => (
+
+ {Object.keys(data).map((key) => (
+ {data[key]} |
+ ))}
+
+
+ ))}
+
+
+
+ ))}
+
+
-