204 lines
5.7 KiB
JavaScript
204 lines
5.7 KiB
JavaScript
import { SyncOutlined } from "@ant-design/icons";
|
|
import { Button, Input, Space, Table } from "antd";
|
|
import queryString from "query-string";
|
|
import React, { useState } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import { Link, useHistory, useLocation } from "react-router-dom";
|
|
import CurrencyFormatter from "../../utils/CurrencyFormatter";
|
|
import { DateTimeFormatter } from "../../utils/DateFormatter";
|
|
import { alphaSort } from "../../utils/sorters";
|
|
|
|
import { connect } from "react-redux";
|
|
import { createStructuredSelector } from "reselect";
|
|
import { setModalContext } from "../../redux/modals/modals.actions";
|
|
import PrintWrapperComponent from "../print-wrapper/print-wrapper.component";
|
|
import { TemplateList } from "../../utils/TemplateConstants";
|
|
|
|
const mapStateToProps = createStructuredSelector({
|
|
//currentUser: selectCurrentUser
|
|
});
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
setPaymentContext: (context) =>
|
|
dispatch(setModalContext({ context: context, modal: "payment" })),
|
|
});
|
|
|
|
export function PaymentsListPaginated({
|
|
setPaymentContext,
|
|
refetch,
|
|
loading,
|
|
payments,
|
|
total,
|
|
}) {
|
|
const search = queryString.parse(useLocation().search);
|
|
const { page, sortcolumn, sortorder } = search;
|
|
const history = useHistory();
|
|
const [state, setState] = useState({
|
|
sortedInfo: {},
|
|
filteredInfo: { text: "" },
|
|
});
|
|
|
|
const { t } = useTranslation();
|
|
const columns = [
|
|
{
|
|
title: t("jobs.fields.ro_number"),
|
|
dataIndex: "ro_number",
|
|
key: "ro_number",
|
|
sorter: (a, b) => alphaSort(a.job.ro_number, b.job.ro_number),
|
|
sortOrder: sortcolumn === "ro_number" && sortorder,
|
|
render: (text, record) => (
|
|
<Link to={"/manage/jobs/" + record.job.id}>
|
|
{record.job.ro_number || t("general.labels.na")}
|
|
</Link>
|
|
),
|
|
},
|
|
|
|
{
|
|
title: t("jobs.fields.owner"),
|
|
dataIndex: "owner",
|
|
key: "owner",
|
|
ellipsis: true,
|
|
sorter: (a, b) => alphaSort(a.job.ownr_ln, b.job.ownr_ln),
|
|
sortOrder: sortcolumn === "owner" && sortorder,
|
|
render: (text, record) => {
|
|
return record.job.owner ? (
|
|
<Link to={"/manage/owners/" + record.job.owner.id}>
|
|
{`${record.job.ownr_fn || ""} ${record.job.ownr_ln || ""} ${
|
|
record.job.ownr_co_nm || ""
|
|
}`}
|
|
</Link>
|
|
) : (
|
|
<span>{`${record.job.ownr_fn || ""} ${record.job.ownr_ln || ""} ${
|
|
record.job.ownr_co_nm || ""
|
|
}`}</span>
|
|
);
|
|
},
|
|
},
|
|
{
|
|
title: t("payments.fields.amount"),
|
|
dataIndex: "amount",
|
|
key: "amount",
|
|
render: (text, record) => (
|
|
<CurrencyFormatter>{record.amount}</CurrencyFormatter>
|
|
),
|
|
},
|
|
{
|
|
title: t("payments.fields.memo"),
|
|
dataIndex: "memo",
|
|
key: "memo",
|
|
},
|
|
{
|
|
title: t("payments.fields.payer"),
|
|
dataIndex: "payer",
|
|
key: "payer",
|
|
},
|
|
{
|
|
title: t("payments.fields.type"),
|
|
dataIndex: "type",
|
|
key: "type",
|
|
},
|
|
{
|
|
title: t("payments.fields.transactionid"),
|
|
dataIndex: "transactionid",
|
|
key: "transactionid",
|
|
},
|
|
{
|
|
title: t("payments.fields.stripeid"),
|
|
dataIndex: "stripeid",
|
|
key: "stripeid",
|
|
},
|
|
{
|
|
title: t("payments.fields.created_at"),
|
|
dataIndex: "created_at",
|
|
key: "created_at",
|
|
render: (text, record) => (
|
|
<DateTimeFormatter>{record.created_at}</DateTimeFormatter>
|
|
),
|
|
},
|
|
{
|
|
title: t("payments.fields.exportedat"),
|
|
dataIndex: "exportedat",
|
|
key: "exportedat",
|
|
render: (text, record) => (
|
|
<DateTimeFormatter>{record.exportedat}</DateTimeFormatter>
|
|
),
|
|
},
|
|
{
|
|
title: t("general.labels.actions"),
|
|
dataIndex: "actions",
|
|
key: "actions",
|
|
render: (text, record) => (
|
|
<Space>
|
|
<Button
|
|
disabled={record.exportedat}
|
|
onClick={() => {
|
|
setPaymentContext({
|
|
actions: { refetch: refetch },
|
|
context: record,
|
|
});
|
|
}}
|
|
>
|
|
{t("general.actions.edit")}
|
|
</Button>
|
|
<PrintWrapperComponent
|
|
templateObject={{
|
|
name: TemplateList("payment").payment_receipt.key,
|
|
variables: { id: record.id },
|
|
}}
|
|
/>
|
|
</Space>
|
|
),
|
|
},
|
|
];
|
|
|
|
const handleTableChange = (pagination, filters, sorter) => {
|
|
setState({ ...state, filteredInfo: filters, sortedInfo: sorter });
|
|
search.page = pagination.current;
|
|
search.sortcolumn = sorter.columnKey;
|
|
search.sortorder = sorter.order;
|
|
history.push({ search: queryString.stringify(search) });
|
|
};
|
|
|
|
return (
|
|
<div>
|
|
<Table
|
|
loading={loading}
|
|
size="small"
|
|
scroll={{ x: true }}
|
|
pagination={{
|
|
position: "top",
|
|
pageSize: 25,
|
|
current: parseInt(page || 1),
|
|
total: total,
|
|
}}
|
|
columns={columns}
|
|
rowKey="id"
|
|
dataSource={payments}
|
|
onChange={handleTableChange}
|
|
title={() => {
|
|
return (
|
|
<div className="imex-table-header">
|
|
<Button onClick={() => refetch()}>
|
|
<SyncOutlined />
|
|
</Button>
|
|
<Input.Search
|
|
className="imex-table-header__search"
|
|
placeholder={t("general.labels.search")}
|
|
onSearch={(value) => {
|
|
search.search = value;
|
|
history.push({ search: queryString.stringify(search) });
|
|
}}
|
|
enterButton
|
|
/>
|
|
</div>
|
|
);
|
|
}}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export default connect(
|
|
mapStateToProps,
|
|
mapDispatchToProps
|
|
)(PaymentsListPaginated);
|