From dac93abd7872564bea78dd391db530c7bacf07d3 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Sat, 22 Feb 2020 05:22:39 +0000 Subject: [PATCH] Add historical transactions to Admin Transactions page --- webclient/src/AdminTransactions.js | 89 ++++++++++++++++++++++++++++-- webclient/src/App.js | 4 +- webclient/src/Members.js | 4 +- webclient/src/Transactions.js | 22 ++++++-- 4 files changed, 104 insertions(+), 15 deletions(-) diff --git a/webclient/src/AdminTransactions.js b/webclient/src/AdminTransactions.js index 432d0b8..7001a98 100644 --- a/webclient/src/AdminTransactions.js +++ b/webclient/src/AdminTransactions.js @@ -2,6 +2,8 @@ import React, { useState, useEffect } from 'react'; import { BrowserRouter as Router, Switch, Route, Link, useParams, useHistory } from 'react-router-dom'; import './light.css'; import { Button, Container, Checkbox, Dimmer, Divider, Dropdown, Form, Grid, Header, Icon, Image, Menu, Message, Segment, Table } from 'semantic-ui-react'; +import * as Datetime from 'react-datetime'; +import 'react-datetime/css/react-datetime.css'; import moment from 'moment'; import { statusColor, BasicTable, staticUrl, requester } from './utils.js'; import { TransactionList, TransactionEditor } from './Transactions.js'; @@ -25,9 +27,7 @@ export function AdminReportedTransactions(props) { }, []); return ( - -
Reported Transactions
- +
{!error ? transactions ?
@@ -36,14 +36,91 @@ export function AdminReportedTransactions(props) { :

Loading...

: - +

Error loading.

} +
+ ); +}; - +let transactionsCache = false; + +export function AdminHistoricalTransactions(props) { + const { token, user } = props; + const [input, setInput] = useState({ month: moment() }); + const [transactions, setTransactions] = useState(transactionsCache); + const [loading, setLoading] = useState(false); + const [error, setError] = useState(false); + + const handleDatetime = (v) => setInput({ ...input, month: v }); + + const handleSubmit = (e) => { + if (loading) return; + setLoading(true); + const month = input.month.format('YYYY-MM'); + requester('/transactions/?month=' + month, 'GET', token) + .then(res => { + setLoading(false); + setError(false); + setTransactions(res.results); + transactionsCache = res.results; + }) + .catch(err => { + setLoading(false); + console.log(err); + setError(true); + }); + }; + + return ( +
+
+ + + + + + + + Submit + + +
+ + {!error ? + transactions &&
+

Found {transactions.length} transactions.

+ {!!transactions.length && +
{moment(transactions[0].date, 'YYYY-MM-DD').format('MMMM YYYY')} Transactions
+ } + +
+ : +

Error loading transactions.

+ } +
); }; export function AdminTransactions(props) { + return ( + +
Admin Transactions
+ +
Reported
+ + +
Historical
+ +
+ ); +} + +export function AdminMemberTransactions(props) { const { token, result, refreshResult } = props; const transactions = result.transactions; const [open, setOpen] = useState(false); @@ -92,7 +169,7 @@ export function AdminTransactions(props) { {transactions.length ? open ? - + :
diff --git a/webclient/src/Transactions.js b/webclient/src/Transactions.js index 977afdd..2f30ef9 100644 --- a/webclient/src/Transactions.js +++ b/webclient/src/Transactions.js @@ -49,12 +49,12 @@ export function TransactionEditor(props) { const categoryOptions = [ { key: '0', text: 'Membership Dues', value: 'Membership' }, - { key: '1', text: 'Payment On Account or Prepayment', value: 'OnAcct' }, + { key: '1', text: 'Payment On Account (ie. Course Fee)', value: 'OnAcct' }, { key: '2', text: 'Snack / Pop / Coffee', value: 'Snacks' }, { key: '3', text: 'Donations', value: 'Donation' }, { key: '4', text: 'Consumables (Specify which in memo)', value: 'Consumables' }, - { key: '5', text: 'Purchases of Goods or Parts or Stock', value: 'Purchases' }, - { key: '6', text: 'Auction, Garage Sale, Nearly Free Shelf, Etc.', value: 'Garage Sale' }, + { key: '5', text: 'Purchase of Locker / Goods / Merch / Stock', value: 'Purchases' }, + { key: '6', text: 'Auction, Garage Sale, Nearly Free Shelf', value: 'Garage Sale' }, { key: '7', text: 'Reimbursement (Enter a negative value)', value: 'Reimburse' }, { key: '8', text: 'Other (Explain in memo)', value: 'Other' }, ]; @@ -250,15 +250,17 @@ function ReportTransaction(props) { }; export function TransactionList(props) { - const { transactions } = props; + const { transactions, noMember, noCategory } = props; return ( Date + {!noMember && Member} Amount Account + {!noCategory && Category} Memo @@ -270,8 +272,18 @@ export function TransactionList(props) { {x.date} + {!noMember && + {x.member_id ? + + {x.member_name} + + : + x.member_name + } + } ${x.amount}{x.account_type} + {!noCategory && {x.category}} {x.memo || x.report_memo} ) @@ -290,7 +302,7 @@ export function Transactions(props) {
Transactions
- +
);