IO-2261 Add Delete function, Correct Payment edit, add Totals to Bills handler
This commit is contained in:
@@ -6,7 +6,7 @@ import { useTranslation } from "react-i18next";
|
||||
import { DELETE_BILL } from "../../graphql/bills.queries";
|
||||
import RbacWrapper from "../rbac-wrapper/rbac-wrapper.component";
|
||||
|
||||
export default function BillDeleteButton({ bill }) {
|
||||
export default function BillDeleteButton({ bill, callback }) {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const { t } = useTranslation();
|
||||
const [deleteBill] = useMutation(DELETE_BILL);
|
||||
@@ -36,6 +36,8 @@ export default function BillDeleteButton({ bill }) {
|
||||
|
||||
if (!!!result.errors) {
|
||||
notification["success"]({ message: t("bills.successes.deleted") });
|
||||
|
||||
if (callback && typeof callback === "function") callback(bill.id);
|
||||
} else {
|
||||
//Check if it's an fkey violation.
|
||||
const error = JSON.stringify(result.errors);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { EditFilled, SyncOutlined } from "@ant-design/icons";
|
||||
import { useApolloClient } from "@apollo/client";
|
||||
import { Button, Card, Input, Space, Table, Typography } from "antd";
|
||||
import axios from "axios";
|
||||
import queryString from "query-string";
|
||||
@@ -7,6 +8,7 @@ import { useTranslation } from "react-i18next";
|
||||
import { connect } from "react-redux";
|
||||
import { Link, useHistory, useLocation } from "react-router-dom";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { QUERY_PAYMENT_BY_ID } from "../../graphql/payments.queries";
|
||||
import { setModalContext } from "../../redux/modals/modals.actions";
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
import CurrencyFormatter from "../../utils/CurrencyFormatter";
|
||||
@@ -43,6 +45,7 @@ export function PaymentsListPaginated({
|
||||
const [openSearchResults, setOpenSearchResults] = useState([]);
|
||||
const [searchLoading, setSearchLoading] = useState(false);
|
||||
const { page, sortcolumn, sortorder } = search;
|
||||
const client = useApolloClient();
|
||||
const history = useHistory();
|
||||
const [state, setState] = useState({
|
||||
sortedInfo: {},
|
||||
@@ -154,10 +157,20 @@ export function PaymentsListPaginated({
|
||||
<Space>
|
||||
<Button
|
||||
disabled={record.exportedat}
|
||||
onClick={() => {
|
||||
onClick={async () => {
|
||||
let apolloResults;
|
||||
if (search.search) {
|
||||
const { data } = await client.query({
|
||||
query: QUERY_PAYMENT_BY_ID,
|
||||
variables: {
|
||||
paymentId: record.id,
|
||||
},
|
||||
});
|
||||
apolloResults = data.payments_by_pk;
|
||||
}
|
||||
setPaymentContext({
|
||||
actions: { refetch: refetch },
|
||||
context: record,
|
||||
context: apolloResults ? record : apolloResults,
|
||||
});
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -114,3 +114,37 @@ export const QUERY_JOB_PAYMENT_TOTALS = gql`
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
|
||||
export const QUERY_PAYMENT_BY_ID = gql`query QUERY_PAYMENT_BY_ID($paymentId: uuid!) {
|
||||
payments_by_pk(id: $paymentId) {
|
||||
id
|
||||
created_at
|
||||
jobid
|
||||
paymentnum
|
||||
date
|
||||
job {
|
||||
id
|
||||
ro_number
|
||||
ownerid
|
||||
ownr_co_nm
|
||||
ownr_fn
|
||||
ownr_ln
|
||||
owner {
|
||||
id
|
||||
ownr_co_nm
|
||||
ownr_fn
|
||||
ownr_ln
|
||||
}
|
||||
}
|
||||
transactionid
|
||||
memo
|
||||
type
|
||||
amount
|
||||
stripeid
|
||||
exportedat
|
||||
stripeid
|
||||
payer
|
||||
}
|
||||
}
|
||||
`
|
||||
@@ -177,7 +177,15 @@ export function BillsListPage({
|
||||
// {t("bills.actions.return")}
|
||||
// </Button>
|
||||
}
|
||||
<BillDeleteButton bill={record} />
|
||||
<BillDeleteButton
|
||||
bill={record}
|
||||
callback={(deletedBillid) => {
|
||||
//Filter out the state and set it again.
|
||||
setOpenSearchResults((currentResults) =>
|
||||
currentResults.filter((bill) => bill.id !== deletedBillid)
|
||||
);
|
||||
}}
|
||||
/>
|
||||
{record.isinhouse && (
|
||||
<PrintWrapperComponent
|
||||
templateObject={{
|
||||
|
||||
@@ -210,6 +210,7 @@ async function OpenSearchUpdateHandler(req, res) {
|
||||
id
|
||||
date
|
||||
exported
|
||||
exported_at
|
||||
invoice_number
|
||||
is_credit_memo
|
||||
total
|
||||
|
||||
@@ -131,8 +131,10 @@ async function OpenSearchUpdateHandler(req, res) {
|
||||
"id",
|
||||
"date",
|
||||
"exported",
|
||||
"exported_at",
|
||||
"invoice_number",
|
||||
"is_credit_memo",
|
||||
"total"
|
||||
]),
|
||||
...bill.bills_by_pk,
|
||||
bodyshopid: bill.bills_by_pk.job.shopid,
|
||||
|
||||
Reference in New Issue
Block a user