Skip to content

Commit be60a13

Browse files
committed
Add purchase and restock reports
1 parent d435a7a commit be60a13

File tree

3 files changed

+71
-7
lines changed

3 files changed

+71
-7
lines changed

src/components/Navigation/Navigation.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export default function Navigation({ children }) {
5151
to="/transaction-stats"
5252
activeClassName="NavigationLinkActive"
5353
>
54-
Transaction Analysis
54+
Transaction Statistics & Reports
5555
</NavLink>
5656

5757
<NavLink

src/components/Transaction/TransactionStats.jsx

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ function TransactionStats() {
4343
});
4444
}, []);
4545

46+
console.log(transactions);
47+
4648
const salesInRange = dataUtil.getSalesInRange(
4749
transactions,
4850
startDate,
@@ -51,12 +53,24 @@ function TransactionStats() {
5153

5254
const incomeByDay = dataUtil.getIncomeByDay(salesInRange);
5355

56+
const purchasesInRange = dataUtil.getPurchasesInRange(
57+
transactions,
58+
startDate,
59+
endDate,
60+
);
61+
62+
const restocksInRange = dataUtil.getRestocksInRange(
63+
transactions,
64+
startDate,
65+
endDate,
66+
);
67+
5468
const renderPlot = () => {
5569
if (loading) return <ReactLoading color="#e26d5c" />;
5670
if (incomeByDay.length > 0)
5771
return (
5872
<div>
59-
<h3>Net Income vs. Date</h3>
73+
<h3>Income vs. Date</h3>
6074
<LineChart width={600} height={400} data={incomeByDay}>
6175
<CartesianGrid strokeDasharray="3 3" />
6276
<XAxis label="Date" dataKey="date" interval="preserveEnd" />
@@ -99,11 +113,11 @@ function TransactionStats() {
99113
);
100114
};
101115

102-
const filteredList = () => {
116+
const filteredSales = () => {
103117
if (loading) return <ReactLoading color="#e26d5c" />;
104118
return (
105119
<>
106-
<h3>Transaction List</h3>
120+
<h3>Sales Transactions in Date Range</h3>
107121
{salesInRange.map((transaction) => (
108122
<TransactionListItem
109123
transaction={transaction}
@@ -114,15 +128,45 @@ function TransactionStats() {
114128
);
115129
};
116130

131+
const filteredPurchases = () => {
132+
if (loading) return <ReactLoading color="#e26d5c" />;
133+
return (
134+
<>
135+
<h3>Purchase Transactions in Date Range</h3>
136+
{purchasesInRange.map((transaction) => (
137+
<TransactionListItem
138+
transaction={transaction}
139+
key={transaction.transactionID}
140+
/>
141+
))}
142+
</>
143+
);
144+
};
145+
146+
const filteredRestocks = () => {
147+
if (loading) return <ReactLoading color="#e26d5c" />;
148+
return (
149+
<>
150+
<h3>Restock Transactions in Date Range</h3>
151+
{restocksInRange.map((transaction) => (
152+
<TransactionListItem
153+
transaction={transaction}
154+
key={transaction.transactionID}
155+
/>
156+
))}
157+
</>
158+
);
159+
};
160+
117161
return (
118162
<div className="container">
119163
<Header />
120164
<HeaderPadding />
121165
<div className="DateInputs">{dateInputs()}</div>
122166
<div className="SalesPlot">{renderPlot()}</div>
123-
<Header />
124-
<HeaderPadding />
125-
<div className="FilteredData">{filteredList()}</div>
167+
<div className="FilteredSales">{filteredSales()}</div>
168+
<div className="FilteredPurchases">{filteredPurchases()}</div>
169+
<div className="FilteredRestocks">{filteredRestocks()}</div>
126170
</div>
127171
);
128172
}

src/components/Transaction/dataUtil.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ const getSales = (transactions) => {
22
return transactions.filter((t) => t.endLoc === 'sold');
33
};
44

5+
const getPurchases = (transactions) => {
6+
return transactions.filter((t) => t.endLoc === 'inventory');
7+
};
8+
9+
const getRestocks = (transactions) => {
10+
return transactions.filter((t) => t.endLoc === 'shelf');
11+
};
12+
513
const filterByDate = (transactions, startDate, endDate) => {
614
return transactions.filter((t) => {
715
return (
@@ -15,6 +23,14 @@ const getSalesInRange = (transactions, startDate, endDate) => {
1523
return filterByDate(getSales(transactions), startDate, endDate);
1624
};
1725

26+
const getPurchasesInRange = (transactions, startDate, endDate) => {
27+
return filterByDate(getPurchases(transactions), startDate, endDate);
28+
};
29+
30+
const getRestocksInRange = (transactions, startDate, endDate) => {
31+
return filterByDate(getRestocks(transactions), startDate, endDate);
32+
};
33+
1834
const getNetIncome = (sale) => {
1935
return sale.price * sale.productQty;
2036
};
@@ -55,4 +71,8 @@ module.exports = {
5571
getNetIncome,
5672
addSimpleDate,
5773
getIncomeByDay,
74+
getPurchases,
75+
getRestocks,
76+
getPurchasesInRange,
77+
getRestocksInRange,
5878
};

0 commit comments

Comments
 (0)