Skip to content

Commit c81e3cf

Browse files
committed
2 parents f3fb021 + 3bd61f3 commit c81e3cf

File tree

2 files changed

+85
-10
lines changed

2 files changed

+85
-10
lines changed

client/src/pages/manager/ExcessReport.js

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,59 @@ import { useTable } from "react-table";
44
import { useEffect, useState } from "react";
55

66
const ExcessReport = () => {
7+
const [items, setExcessReport] = useState([]);
78

9+
const [beginning, setBeginningDate] = useState('');
810

9-
return (
10-
<div>
11-
Hi
12-
13-
14-
15-
16-
17-
11+
const handleBeginningChange = (event) => {
12+
setBeginningDate(event.target.value);
13+
};
1814

15+
const handleSubmit = async () => {
1916

17+
const res = await fetch("http://localhost:3001/excessReport/" + beginning);
18+
const getdata= await res.json();
19+
setExcessReport(getdata);
20+
console.log(getdata);
21+
};
2022

23+
return (
24+
<div className="container">
25+
<h2>Excess Report</h2>
26+
<form>
27+
28+
<input
29+
type = "date"
30+
id = "beginningdate"
31+
name ="Beginning Date"
32+
required = "required"
33+
placeholder="Enter Beginning Date"
34+
value = {beginning}
35+
onChange = {handleBeginningChange}
36+
/>
37+
<button type ="button" onClick ={handleSubmit}>Output Excess Report</button>
38+
</form>
39+
40+
<table className="table table-bordered text-white">
41+
<thead>
42+
<tr>
43+
<th>item_name</th>
44+
<th>qty</th>
45+
<th>quantity</th>
46+
</tr>
47+
</thead>
48+
<tbody>
49+
{items.map((excess) =>(
50+
<tr>
51+
<td>{excess.item_name}</td>
52+
<td>{excess.qty}</td>
53+
<td>{excess.quantity}</td>
54+
</tr>
55+
))}
56+
</tbody>
57+
</table>
2158
</div>
59+
2260
);
2361
};
2462

server/server.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,44 @@ app.get("/xreportdefault", async (req, res) => {
319319
}
320320
}
321321
});
322-
/*Need Assistance to Test*/
322+
323+
app.get("/excessReport/:beginning", async (req, res) => {
324+
325+
const date = getLocalDate();
326+
const result = await pool.query(
327+
"SELECT item_name, SUM(qty) AS qty, quantity FROM " +
328+
"(SELECT coalesce(j.qty,0) AS qty, item_name, quantity FROM inventory FULL OUTER JOIN "+
329+
330+
"(SELECT inventory_id, quantity*count AS qty FROM "+
331+
332+
"(SELECT m.menu_item_id, SUM(count) AS count FROM " +
333+
334+
"(SELECT order_items.menu_item_id, quantity*count(*) AS count FROM order_items JOIN orders ON " +
335+
"orders.order_id=order_items.order_id JOIN menu_items ON order_items.menu_item_id = menu_items.menu_item_id "
336+
+
337+
"WHERE order_time::date >= '" + req.params.beginning + "' AND order_time::date <= '" + date
338+
+ "' GROUP BY order_items.menu_item_id, quantity ORDER BY menu_item_id) m"+
339+
340+
" GROUP BY menu_item_id) k " +
341+
342+
"JOIN recipes ON k.menu_item_id = recipes.menu_item_id GROUP BY inventory_id, qty) j"+
343+
344+
" ON j.inventory_id = inventory.item_id" +
345+
" WHERE quantity > 0" +
346+
" GROUP BY item_name, qty, quantity ORDER BY item_name) n"+
347+
348+
" GROUP BY item_name, quantity" +
349+
" HAVING SUM(qty) < 0.1 * (SUM(qty) + quantity);" ,
350+
(err, result) => {
351+
if (err) {
352+
return res.status(500).send("cant retrieve from db");
353+
} else {
354+
return res.send(result.rows);
355+
}
356+
}
357+
);
358+
});
359+
323360
app.get("/xreport/:date", async (req, res) => {
324361
//const id = await pool.query("SELECT sales_date FROM sales WHERE sales_id=(SELECT max(sales_id) FROM sales)");
325362
console.log(req.params.date);

0 commit comments

Comments
 (0)