2020-07-23 00:09:44 +00:00
|
|
|
import React, { useState, useEffect, useRef } from 'react';
|
2020-01-09 22:11:56 +00:00
|
|
|
import { BrowserRouter as Router, Switch, Route, Link, useParams } from 'react-router-dom';
|
2022-01-14 00:32:21 +00:00
|
|
|
import moment from 'moment-timezone';
|
2020-07-23 00:09:44 +00:00
|
|
|
import ReactToPrint from 'react-to-print';
|
2020-01-09 22:11:56 +00:00
|
|
|
import './light.css';
|
2020-07-23 00:09:44 +00:00
|
|
|
import { Button, Container, Divider, Dropdown, Form, Grid, Header, Icon, Image, Menu, Message, Segment, Table } from 'semantic-ui-react';
|
2020-01-31 23:47:52 +00:00
|
|
|
import { MembersDropdown } from './Members.js';
|
2020-01-18 03:34:55 +00:00
|
|
|
import { isAdmin, BasicTable, requester } from './utils.js';
|
2020-01-09 22:11:56 +00:00
|
|
|
import { NotFound, PleaseLogin } from './Misc.js';
|
|
|
|
|
2020-01-18 04:47:54 +00:00
|
|
|
export function TransactionEditor(props) {
|
2020-02-01 02:36:15 +00:00
|
|
|
const { token, input, setInput, error, noMemberSearch } = props;
|
2020-01-18 03:34:55 +00:00
|
|
|
|
2021-04-24 21:51:06 +00:00
|
|
|
const [prevInput, setPrevInput] = useState(input);
|
|
|
|
|
2020-01-18 03:34:55 +00:00
|
|
|
const handleValues = (e, v) => setInput({ ...input, [v.name]: v.value });
|
|
|
|
const handleUpload = (e, v) => setInput({ ...input, [v.name]: e.target.files[0] });
|
|
|
|
const handleChange = (e) => handleValues(e, e.currentTarget);
|
|
|
|
const handleCheck = (e, v) => setInput({ ...input, [v.name]: v.checked });
|
|
|
|
|
|
|
|
const makeProps = (name) => ({
|
|
|
|
name: name,
|
|
|
|
onChange: handleChange,
|
|
|
|
value: input[name] || '',
|
|
|
|
error: error[name],
|
|
|
|
});
|
|
|
|
|
|
|
|
const accountOptions = [
|
2022-01-16 01:15:50 +00:00
|
|
|
{ key: '0', text: 'Cash', value: 'Cash' },
|
|
|
|
{ key: '1', text: 'Interac e-Transfer', value: 'Interac' },
|
|
|
|
{ key: '2', text: 'Square', value: 'Square Pmt' },
|
2020-10-01 22:14:16 +00:00
|
|
|
//{ key: '3', text: 'Dream Payments (Debit/Credit)', value: 'Dream Pmt' },
|
2022-01-16 01:15:50 +00:00
|
|
|
{ key: '4', text: 'Cheque', value: 'TD Chequing' },
|
2020-10-01 22:14:16 +00:00
|
|
|
//{ key: '5', text: 'Member Balance / Protocash', value: 'Member' },
|
|
|
|
{ key: '6', text: 'Membership Adjustment / Clearing', value: 'Clearing' },
|
|
|
|
{ key: '7', text: 'PayPal', value: 'PayPal' },
|
2020-01-18 03:34:55 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
const sourceOptions = [
|
2020-01-19 03:00:05 +00:00
|
|
|
{ key: '0', text: 'Web (Spaceport)', value: 'Web' },
|
2020-01-18 03:34:55 +00:00
|
|
|
{ key: '1', text: 'Database Edit', value: 'DB Edit' },
|
|
|
|
{ key: '2', text: 'System', value: 'System' },
|
|
|
|
{ key: '3', text: 'Receipt or Statement', value: 'Receipt or Stmt' },
|
|
|
|
{ key: '4', text: 'Quicken Import', value: 'Quicken Import' },
|
2020-01-31 23:47:52 +00:00
|
|
|
{ key: '5', text: 'PayPal IPN', value: 'PayPal IPN' },
|
2020-01-18 03:34:55 +00:00
|
|
|
{ key: '6', text: 'Auto', value: 'Auto' },
|
|
|
|
{ key: '7', text: 'Nexus Database Bulk', value: 'Nexus DB Bulk' },
|
|
|
|
{ key: '8', text: 'IPN Trigger', value: 'IPN Trigger' },
|
|
|
|
{ key: '9', text: 'Intranet Receipt', value: 'Intranet Receipt' },
|
|
|
|
{ key: '10', text: 'Automatic', value: 'Automatic' },
|
|
|
|
{ key: '11', text: 'Manual', value: 'Manual' },
|
|
|
|
];
|
|
|
|
|
|
|
|
const categoryOptions = [
|
|
|
|
{ key: '0', text: 'Membership Dues', value: 'Membership' },
|
2022-03-29 22:04:04 +00:00
|
|
|
{ key: '1', text: 'Course Fee', value: 'OnAcct' },
|
|
|
|
{ key: '2', text: 'Snacks / Pop / Coffee', value: 'Snacks' },
|
|
|
|
{ key: '3', text: 'Donation', value: 'Donation' },
|
2020-10-01 22:14:16 +00:00
|
|
|
{ key: '4', text: 'Consumables (Explain in memo)', value: 'Consumables' },
|
2022-03-29 22:04:04 +00:00
|
|
|
{ key: '5', text: 'Purchase of Locker / Materials / Stock', value: 'Purchases' },
|
2020-10-01 22:14:16 +00:00
|
|
|
//{ key: '6', text: 'Auction, Garage Sale, Nearly Free Shelf', value: 'Garage Sale' },
|
2020-01-18 03:34:55 +00:00
|
|
|
{ key: '7', text: 'Reimbursement (Enter a negative value)', value: 'Reimburse' },
|
|
|
|
{ key: '8', text: 'Other (Explain in memo)', value: 'Other' },
|
|
|
|
];
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className='transaction-editor'>
|
2021-04-24 21:51:06 +00:00
|
|
|
{!noMemberSearch && <Form.Field error={error.member_id}>
|
2020-01-31 23:47:52 +00:00
|
|
|
<label>Member (search)</label>
|
|
|
|
<MembersDropdown
|
|
|
|
token={token}
|
|
|
|
{...makeProps('member_id')}
|
|
|
|
onChange={handleValues}
|
|
|
|
initial={input.member_name}
|
|
|
|
/>
|
2020-02-01 02:36:15 +00:00
|
|
|
</Form.Field>}
|
2020-01-31 23:47:52 +00:00
|
|
|
|
2020-01-18 03:34:55 +00:00
|
|
|
<Form.Group widths='equal'>
|
|
|
|
<Form.Input
|
|
|
|
label='Date'
|
|
|
|
fluid
|
|
|
|
{...makeProps('date')}
|
|
|
|
/>
|
|
|
|
<Form.Input
|
|
|
|
label='Amount'
|
|
|
|
fluid
|
|
|
|
{...makeProps('amount')}
|
|
|
|
/>
|
|
|
|
</Form.Group>
|
|
|
|
|
|
|
|
<Form.Select
|
|
|
|
label='Category'
|
|
|
|
fluid
|
|
|
|
options={categoryOptions}
|
|
|
|
{...makeProps('category')}
|
|
|
|
onChange={handleValues}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<Form.Select
|
2020-10-01 22:14:16 +00:00
|
|
|
label='Payment Method / Account'
|
2020-01-18 03:34:55 +00:00
|
|
|
fluid
|
|
|
|
options={accountOptions}
|
|
|
|
{...makeProps('account_type')}
|
|
|
|
onChange={handleValues}
|
|
|
|
/>
|
|
|
|
|
2021-04-24 21:51:06 +00:00
|
|
|
{ input?.account_type != prevInput?.account_type && input?.account_type == 'PayPal' &&
|
|
|
|
<Message visible warning>
|
2022-01-16 01:15:50 +00:00
|
|
|
<Message.Header>Are you sure?</Message.Header>
|
2021-04-24 21:51:06 +00:00
|
|
|
<p>PayPal transactions should be automatic. Double check there's no duplicate. They may take 24h to appear.</p>
|
|
|
|
</Message>
|
|
|
|
}
|
|
|
|
|
2020-10-01 22:14:16 +00:00
|
|
|
{/* <Form.Group widths='equal'>
|
2020-01-18 03:34:55 +00:00
|
|
|
<Form.Input
|
|
|
|
label='Payment Method'
|
|
|
|
fluid
|
|
|
|
{...makeProps('payment_method')}
|
|
|
|
/>
|
|
|
|
<Form.Select
|
|
|
|
label='Info Source'
|
|
|
|
fluid
|
|
|
|
options={sourceOptions}
|
|
|
|
{...makeProps('info_source')}
|
|
|
|
onChange={handleValues}
|
|
|
|
/>
|
2020-10-01 22:14:16 +00:00
|
|
|
</Form.Group> */}
|
2020-01-18 03:34:55 +00:00
|
|
|
|
|
|
|
<Form.Group widths='equal'>
|
|
|
|
<Form.Input
|
|
|
|
label='Reference Number'
|
|
|
|
fluid
|
|
|
|
{...makeProps('reference_number')}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<Form.Input
|
2020-10-01 22:14:16 +00:00
|
|
|
label='Number of Membership Months'
|
2020-01-18 03:34:55 +00:00
|
|
|
fluid
|
|
|
|
{...makeProps('number_of_membership_months')}
|
|
|
|
/>
|
|
|
|
</Form.Group>
|
|
|
|
|
|
|
|
<Form.Input
|
|
|
|
label='Memo / Notes'
|
|
|
|
fluid
|
|
|
|
{...makeProps('memo')}
|
|
|
|
/>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
function EditTransaction(props) {
|
|
|
|
const { transaction, setTransaction, token, refreshUser } = props;
|
|
|
|
const [input, setInput] = useState(transaction);
|
|
|
|
const [error, setError] = useState(false);
|
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
const [success, setSuccess] = useState(false);
|
|
|
|
const { id } = useParams();
|
|
|
|
|
|
|
|
const handleSubmit = (e) => {
|
2020-02-04 07:18:29 +00:00
|
|
|
if (loading) return;
|
2020-01-18 03:34:55 +00:00
|
|
|
setLoading(true);
|
|
|
|
setSuccess(false);
|
2020-01-31 23:47:52 +00:00
|
|
|
const data = { ...input, report_type: null, report_memo: '' };
|
|
|
|
requester('/transactions/'+id+'/', 'PUT', token, data)
|
2020-01-18 03:34:55 +00:00
|
|
|
.then(res => {
|
|
|
|
setLoading(false);
|
|
|
|
setSuccess(true);
|
|
|
|
setError(false);
|
|
|
|
setInput(res);
|
|
|
|
setTransaction(res);
|
|
|
|
if (refreshUser) {
|
|
|
|
refreshUser();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
setLoading(false);
|
|
|
|
console.log(err);
|
|
|
|
setError(err.data);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<Header size='medium'>Edit Transaction</Header>
|
|
|
|
|
|
|
|
<Form onSubmit={handleSubmit}>
|
2020-01-31 23:47:52 +00:00
|
|
|
<TransactionEditor token={token} input={input} setInput={setInput} error={error} />
|
2020-01-18 03:34:55 +00:00
|
|
|
|
|
|
|
<Form.Button loading={loading} error={error.non_field_errors}>
|
2020-02-01 08:56:22 +00:00
|
|
|
{transaction.report_type ? 'Save & Unreport' : 'Save'}
|
|
|
|
</Form.Button>
|
|
|
|
{success && <div>Success!</div>}
|
|
|
|
</Form>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
function ReportTransaction(props) {
|
|
|
|
const { transaction, setTransaction, token, refreshUser } = props;
|
|
|
|
const [input, setInput] = useState(transaction);
|
|
|
|
const [error, setError] = useState(false);
|
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
const [success, setSuccess] = useState(false);
|
|
|
|
const { id } = useParams();
|
|
|
|
|
|
|
|
const handleValues = (e, v) => setInput({ ...input, [v.name]: v.value });
|
|
|
|
const handleUpload = (e, v) => setInput({ ...input, [v.name]: e.target.files[0] });
|
|
|
|
const handleChange = (e) => handleValues(e, e.currentTarget);
|
|
|
|
const handleCheck = (e, v) => setInput({ ...input, [v.name]: v.checked });
|
|
|
|
|
|
|
|
const handleSubmit = (e) => {
|
2020-02-04 07:18:29 +00:00
|
|
|
if (loading) return;
|
2020-02-01 08:56:22 +00:00
|
|
|
setLoading(true);
|
|
|
|
setSuccess(false);
|
|
|
|
requester('/transactions/'+id+'/report/', 'POST', token, input)
|
|
|
|
.then(res => {
|
|
|
|
setLoading(false);
|
|
|
|
setSuccess(true);
|
|
|
|
setError(false);
|
|
|
|
if (refreshUser) {
|
|
|
|
refreshUser();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
setLoading(false);
|
|
|
|
console.log(err);
|
|
|
|
setError(err.data);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const makeProps = (name) => ({
|
|
|
|
name: name,
|
|
|
|
onChange: handleChange,
|
|
|
|
value: input[name] || '',
|
|
|
|
error: error[name],
|
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<Header size='medium'>Report Transaction</Header>
|
|
|
|
|
|
|
|
<p>If this transaction was made in error or there is anything incorrect about it, please report it using this form.</p>
|
|
|
|
<p>A staff member will review the report as soon as possible.</p>
|
|
|
|
<p>Follow up with <a href='mailto:directors@protospace.ca' target='_blank' rel='noopener noreferrer'>directors@protospace.ca</a>.</p>
|
|
|
|
|
|
|
|
<Form onSubmit={handleSubmit}>
|
|
|
|
<Form.TextArea
|
|
|
|
label='Reason'
|
|
|
|
{...makeProps('report_memo')}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<Form.Button loading={loading} error={error.non_field_errors}>
|
|
|
|
Submit Report
|
2020-01-18 03:34:55 +00:00
|
|
|
</Form.Button>
|
2020-01-23 22:44:42 +00:00
|
|
|
{success && <div>Success!</div>}
|
2020-01-18 03:34:55 +00:00
|
|
|
</Form>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-01-18 04:47:54 +00:00
|
|
|
export function TransactionList(props) {
|
2020-02-22 05:22:39 +00:00
|
|
|
const { transactions, noMember, noCategory } = props;
|
2020-01-18 04:47:54 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Table basic='very'>
|
|
|
|
<Table.Header>
|
|
|
|
<Table.Row>
|
|
|
|
<Table.HeaderCell>Date</Table.HeaderCell>
|
2020-02-22 05:22:39 +00:00
|
|
|
{!noMember && <Table.HeaderCell>Member</Table.HeaderCell>}
|
2020-01-18 04:47:54 +00:00
|
|
|
<Table.HeaderCell>Amount</Table.HeaderCell>
|
|
|
|
<Table.HeaderCell>Account</Table.HeaderCell>
|
2020-02-22 05:22:39 +00:00
|
|
|
{!noCategory && <Table.HeaderCell>Category</Table.HeaderCell>}
|
2020-01-18 04:47:54 +00:00
|
|
|
<Table.HeaderCell>Memo</Table.HeaderCell>
|
|
|
|
</Table.Row>
|
|
|
|
</Table.Header>
|
|
|
|
|
|
|
|
<Table.Body>
|
|
|
|
{transactions.length ?
|
|
|
|
transactions.slice().sort((a, b) => a.date < b.date ? 1 : -1).map(x =>
|
|
|
|
<Table.Row key={x.id}>
|
2022-01-14 00:32:21 +00:00
|
|
|
<Table.Cell style={{ minWidth: '8rem' }}>
|
|
|
|
<Link to={'/transactions/'+x.id}>{moment(x.date).format('ll')}</Link>
|
2020-01-18 04:47:54 +00:00
|
|
|
</Table.Cell>
|
2020-02-22 05:22:39 +00:00
|
|
|
{!noMember && <Table.Cell>
|
|
|
|
{x.member_id ?
|
|
|
|
<Link to={'/members/'+x.member_id}>
|
|
|
|
{x.member_name}
|
|
|
|
</Link>
|
|
|
|
:
|
|
|
|
x.member_name
|
|
|
|
}
|
|
|
|
</Table.Cell>}
|
2020-01-18 04:47:54 +00:00
|
|
|
<Table.Cell>${x.amount}</Table.Cell>
|
|
|
|
<Table.Cell>{x.account_type}</Table.Cell>
|
2020-02-22 05:22:39 +00:00
|
|
|
{!noCategory && <Table.Cell>{x.category}</Table.Cell>}
|
2020-01-31 23:47:52 +00:00
|
|
|
<Table.Cell>{x.memo || x.report_memo}</Table.Cell>
|
2020-01-18 04:47:54 +00:00
|
|
|
</Table.Row>
|
|
|
|
)
|
|
|
|
:
|
|
|
|
<Table.Row><Table.Cell>None</Table.Cell></Table.Row>
|
|
|
|
}
|
|
|
|
</Table.Body>
|
|
|
|
</Table>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-01-09 22:11:56 +00:00
|
|
|
export function Transactions(props) {
|
|
|
|
const { user } = props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Container>
|
2021-12-22 05:59:34 +00:00
|
|
|
<Header size='large'>Your Transactions</Header>
|
2020-01-09 22:11:56 +00:00
|
|
|
|
2020-02-22 05:22:39 +00:00
|
|
|
<TransactionList noMember noCategory transactions={user.transactions} />
|
2020-01-09 22:11:56 +00:00
|
|
|
|
|
|
|
</Container>
|
|
|
|
);
|
2020-01-10 06:24:37 +00:00
|
|
|
};
|
2020-01-09 22:11:56 +00:00
|
|
|
|
2020-07-23 00:09:44 +00:00
|
|
|
class TransactionTable extends React.Component {
|
|
|
|
render() {
|
|
|
|
const transaction = this.props.transaction;
|
|
|
|
const user = this.props.user;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<BasicTable>
|
|
|
|
<Table.Body>
|
|
|
|
<Table.Row>
|
|
|
|
<Table.Cell>Member:</Table.Cell>
|
|
|
|
{isAdmin(user) && transaction.member_id ?
|
|
|
|
<Table.Cell>
|
|
|
|
<Link to={'/members/'+transaction.member_id}>
|
|
|
|
{transaction.member_name}
|
|
|
|
</Link>
|
|
|
|
</Table.Cell>
|
|
|
|
:
|
|
|
|
<Table.Cell>{transaction.member_name}</Table.Cell>
|
|
|
|
}
|
|
|
|
</Table.Row>
|
|
|
|
<Table.Row>
|
|
|
|
<Table.Cell>Number:</Table.Cell>
|
|
|
|
<Table.Cell>{transaction.id}</Table.Cell>
|
|
|
|
</Table.Row>
|
|
|
|
<Table.Row>
|
|
|
|
<Table.Cell>Date:</Table.Cell>
|
|
|
|
<Table.Cell>{transaction.date}</Table.Cell>
|
|
|
|
</Table.Row>
|
|
|
|
<Table.Row>
|
|
|
|
<Table.Cell>Amount:</Table.Cell>
|
|
|
|
<Table.Cell>${transaction.amount}</Table.Cell>
|
|
|
|
</Table.Row>
|
|
|
|
<Table.Row>
|
|
|
|
<Table.Cell>Category:</Table.Cell>
|
|
|
|
<Table.Cell>{transaction.category}</Table.Cell>
|
|
|
|
</Table.Row>
|
|
|
|
<Table.Row>
|
|
|
|
<Table.Cell>Account:</Table.Cell>
|
|
|
|
<Table.Cell>{transaction.account_type}</Table.Cell>
|
|
|
|
</Table.Row>
|
2020-10-01 22:14:16 +00:00
|
|
|
{/* <Table.Row>
|
2020-07-23 00:09:44 +00:00
|
|
|
<Table.Cell>Payment Method:</Table.Cell>
|
|
|
|
<Table.Cell>{transaction.payment_method}</Table.Cell>
|
2020-10-01 22:14:16 +00:00
|
|
|
</Table.Row> */}
|
2020-07-23 00:09:44 +00:00
|
|
|
<Table.Row>
|
|
|
|
<Table.Cell>Info Source:</Table.Cell>
|
|
|
|
<Table.Cell>{transaction.info_source}</Table.Cell>
|
|
|
|
</Table.Row>
|
|
|
|
<Table.Row>
|
|
|
|
<Table.Cell>Reference:</Table.Cell>
|
|
|
|
<Table.Cell>{transaction.reference_number}</Table.Cell>
|
|
|
|
</Table.Row>
|
|
|
|
<Table.Row>
|
|
|
|
<Table.Cell>Memo:</Table.Cell>
|
|
|
|
<Table.Cell>{transaction.memo}</Table.Cell>
|
|
|
|
</Table.Row>
|
2021-09-23 21:04:18 +00:00
|
|
|
<Table.Row>
|
|
|
|
<Table.Cell>Recorder:</Table.Cell>
|
|
|
|
<Table.Cell>{transaction.recorder || 'System'}</Table.Cell>
|
|
|
|
</Table.Row>
|
2020-07-23 00:09:44 +00:00
|
|
|
|
|
|
|
{!!transaction.report_type && <Table.Row>
|
|
|
|
<Table.Cell>Report Type:</Table.Cell>
|
|
|
|
<Table.Cell>{transaction.report_type}</Table.Cell>
|
|
|
|
</Table.Row>}
|
|
|
|
{!!transaction.report_memo && <Table.Row>
|
|
|
|
<Table.Cell>Report Memo:</Table.Cell>
|
|
|
|
<Table.Cell>{transaction.report_memo}</Table.Cell>
|
|
|
|
</Table.Row>}
|
|
|
|
</Table.Body>
|
|
|
|
</BasicTable>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class TransactionPrint extends React.Component {
|
|
|
|
render() {
|
|
|
|
const transaction = this.props.transaction;
|
|
|
|
const user = this.props.user;
|
|
|
|
|
|
|
|
return (
|
2022-02-03 06:31:58 +00:00
|
|
|
<div style={{padding: '1in', background: 'white', width: '100%', height: '100%'}}>
|
2020-07-23 00:09:44 +00:00
|
|
|
<Header size='large'>Protospace Transaction Receipt</Header>
|
|
|
|
<p>Calgary Protospace Ltd.</p>
|
|
|
|
<p>Bay 108, 1530 - 27th Ave NE<br />Calgary, AB T2E 7S6<br />protospace.ca</p>
|
|
|
|
<TransactionTable user={user} transaction={transaction} />
|
|
|
|
<p>Thank you!</p>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-09 22:11:56 +00:00
|
|
|
export function TransactionDetail(props) {
|
2020-01-18 03:34:55 +00:00
|
|
|
const { token, user } = props;
|
2020-01-09 22:11:56 +00:00
|
|
|
const { id } = useParams();
|
2020-01-18 03:34:55 +00:00
|
|
|
const ownTransaction = user.transactions.find(x => x.id == id);
|
|
|
|
const [transaction, setTransaction] = useState(ownTransaction || false);
|
|
|
|
const [error, setError] = useState(false);
|
2020-07-23 00:09:44 +00:00
|
|
|
const printRef = useRef();
|
2020-01-09 22:11:56 +00:00
|
|
|
|
2020-01-18 03:34:55 +00:00
|
|
|
useEffect(() => {
|
|
|
|
requester('/transactions/'+id+'/', 'GET', token)
|
|
|
|
.then(res => {
|
|
|
|
setTransaction(res);
|
|
|
|
setError(false);
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
console.log(err);
|
|
|
|
setError(true);
|
|
|
|
});
|
2020-02-01 08:56:22 +00:00
|
|
|
}, [ownTransaction]);
|
2020-01-09 22:11:56 +00:00
|
|
|
|
|
|
|
return (
|
2020-01-18 03:34:55 +00:00
|
|
|
<Container>
|
|
|
|
{!error ?
|
|
|
|
transaction ?
|
|
|
|
<div>
|
|
|
|
<Header size='large'>Transaction Receipt</Header>
|
|
|
|
|
|
|
|
<Grid stackable columns={2}>
|
|
|
|
<Grid.Column>
|
2020-07-23 00:09:44 +00:00
|
|
|
<TransactionTable user={user} transaction={transaction} />
|
|
|
|
|
|
|
|
<div style={{ display: 'none' }}>
|
|
|
|
<TransactionPrint ref={printRef} user={user} transaction={transaction} />
|
|
|
|
</div>
|
|
|
|
<ReactToPrint
|
|
|
|
trigger={() => <Button>Print Receipt</Button>}
|
|
|
|
content={() => printRef.current}
|
|
|
|
/>
|
2020-01-18 03:34:55 +00:00
|
|
|
</Grid.Column>
|
|
|
|
|
|
|
|
<Grid.Column>
|
2020-02-01 08:56:22 +00:00
|
|
|
{isAdmin(user) ?
|
|
|
|
<Segment padded>
|
|
|
|
<EditTransaction transaction={transaction} setTransaction={setTransaction} {...props} />
|
|
|
|
</Segment>
|
|
|
|
:
|
|
|
|
<Segment padded>
|
|
|
|
<ReportTransaction transaction={transaction} setTransaction={setTransaction} {...props} />
|
|
|
|
</Segment>
|
|
|
|
}
|
2020-01-18 03:34:55 +00:00
|
|
|
</Grid.Column>
|
|
|
|
</Grid>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
:
|
|
|
|
<p>Loading...</p>
|
|
|
|
:
|
|
|
|
<NotFound />
|
|
|
|
}
|
|
|
|
</Container>
|
2020-01-09 22:11:56 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|