Restricted invoice export to 1 at a time BOD-139

This commit is contained in:
Patrick Fic
2020-06-02 16:43:00 -07:00
parent 73c457e972
commit 6060def9f4
6 changed files with 75 additions and 31 deletions

View File

@@ -13,7 +13,8 @@ export default function AccountingPayablesTableComponent({
invoices, invoices,
}) { }) {
const { t } = useTranslation(); const { t } = useTranslation();
const [selectedInvoices, setSelectedInvoices] = useState([]);
const [transInProgress, setTransInProgress] = useState(false);
const [state, setState] = useState({ const [state, setState] = useState({
sortedInfo: {}, sortedInfo: {},
search: "", search: "",
@@ -64,6 +65,17 @@ export default function AccountingPayablesTableComponent({
</Link> </Link>
), ),
}, },
{
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:
state.sortedInfo.columnKey === "ro_number" && state.sortedInfo.order,
render: (text, record) => (
<Link to={`/manage/jobs/${record.job.id}`}>{record.job.ro_number}</Link>
),
},
{ {
title: t("invoices.fields.date"), title: t("invoices.fields.date"),
dataIndex: "date", dataIndex: "date",
@@ -107,14 +119,16 @@ export default function AccountingPayablesTableComponent({
render: (text, record) => ( render: (text, record) => (
<div> <div>
<InvoiceExportButton <InvoiceExportButton
invoiceId={record.id} invoiceId={record.id}
disabled={!!record.exported} disabled={transInProgress || !!record.exported}
loadingCallback={setTransInProgress}
/> />
</div> </div>
), ),
}, },
]; ];
console.log('transInProgress', transInProgress)
const handleSearch = (e) => { const handleSearch = (e) => {
setState({ ...state, search: e.target.value }); setState({ ...state, search: e.target.value });
}; };
@@ -149,10 +163,22 @@ export default function AccountingPayablesTableComponent({
}} }}
dataSource={dataSource} dataSource={dataSource}
size="small" size="small"
pagination={{ position: "top" }} pagination={{ position: "top", pageSize: 50 }}
columns={columns} columns={columns}
rowKey="id" rowKey="id"
onChange={handleTableChange} onChange={handleTableChange}
rowSelection={{
onSelectAll: (selected, selectedRows) =>
setSelectedInvoices(selectedRows.map((i) => i.id)),
onSelect: (record, selected, selectedRows, nativeEvent) => {
setSelectedInvoices(selectedRows.map((i) => i.id));
},
getCheckboxProps: (record) => ({
disabled: record.exported,
}),
selectedRowKeys: selectedInvoices,
type: "checkbox",
}}
/> />
</div> </div>
); );

View File

@@ -12,13 +12,20 @@ const mapStateToProps = createStructuredSelector({
bodyshop: selectBodyshop, bodyshop: selectBodyshop,
}); });
export function InvoiceExportButton({ bodyshop, invoiceId, disabled }) { export function InvoiceExportButton({
bodyshop,
invoiceId,
disabled,
loadingCallback,
}) {
const { t } = useTranslation(); const { t } = useTranslation();
const [updateInvoice] = useMutation(UPDATE_INVOICE); const [updateInvoice] = useMutation(UPDATE_INVOICE);
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const handleQbxml = async () => { const handleQbxml = async () => {
setLoading(true); setLoading(true);
if (!!loadingCallback) loadingCallback(true);
let QbXmlResponse; let QbXmlResponse;
try { try {
QbXmlResponse = await axios.post( QbXmlResponse = await axios.post(
@@ -38,6 +45,7 @@ export function InvoiceExportButton({ bodyshop, invoiceId, disabled }) {
error: "Unable to retrieve QBXML. " + JSON.stringify(error.message), error: "Unable to retrieve QBXML. " + JSON.stringify(error.message),
}), }),
}); });
if (loadingCallback) loadingCallback(false);
setLoading(false); setLoading(false);
return; return;
} }
@@ -45,7 +53,7 @@ export function InvoiceExportButton({ bodyshop, invoiceId, disabled }) {
let PartnerResponse; let PartnerResponse;
try { try {
PartnerResponse = await axios.post( PartnerResponse = await axios.post(
"http://e9c5a8ed9079.ngrok.io/qb/receivables", "http://e9c5a8ed9079.ngrok.io/qb/",
QbXmlResponse.data QbXmlResponse.data
); );
} catch (error) { } catch (error) {
@@ -53,33 +61,34 @@ export function InvoiceExportButton({ bodyshop, invoiceId, disabled }) {
notification["error"]({ notification["error"]({
message: t("invoices.errors.exporting-partner"), message: t("invoices.errors.exporting-partner"),
}); });
if (!!loadingCallback) loadingCallback(false);
setLoading(false); setLoading(false);
return; return;
} }
console.log("PartnerResponse", PartnerResponse); const invoiceUpdateResponse = await updateInvoice({
// const invoiceUpdateResponse = await updateInvoice({ variables: {
// variables: { invoiceId: invoiceId,
// invoiceId: invoiceId, invoice: {
// invoice: { exported: true,
// exported: true, exported_at: new Date(),
// exported_at: new Date(), },
// }, },
// }, });
// });
// if (!!!invoiceUpdateResponse.errors) { if (!!!invoiceUpdateResponse.errors) {
// notification["success"]({ notification["success"]({
// message: t("jobs.successes.exported"), message: t("jobs.successes.exported"),
// }); });
// } else { } else {
// notification["error"]({ notification["error"]({
// message: t("jobs.errors.exporting", { message: t("jobs.errors.exporting", {
// error: JSON.stringify(invoiceUpdateResponse.error), error: JSON.stringify(invoiceUpdateResponse.error),
// }), }),
// }); });
// } }
if (!!loadingCallback) loadingCallback(false);
setLoading(false); setLoading(false);
}; };

View File

@@ -44,7 +44,7 @@ export function JobsCloseExportButton({ bodyshop, jobId, disabled }) {
let PartnerResponse; let PartnerResponse;
try { try {
PartnerResponse = await axios.post( PartnerResponse = await axios.post(
"http://localhost:1337/qb/receivables", "http://localhost:1337/qb/",
QbXmlResponse.data, QbXmlResponse.data,
{ {
headers: { headers: {

View File

@@ -35,7 +35,12 @@ export const QUERY_INVOICES_FOR_EXPORT = gql`
exported exported
date date
invoice_number invoice_number
is_credit_memo
total total
job {
id
ro_number
}
vendor { vendor {
name name
id id

View File

@@ -160,6 +160,10 @@ export const MARK_LATEST_APPOINTMENT_AS_ARRIVED = gql`
_set: { arrived: true } _set: { arrived: true }
) { ) {
affected_rows affected_rows
returning {
id
arrived
}
} }
} }
`; `;

View File

@@ -49,8 +49,8 @@ const generateBill = (invoice) => {
QBXML: { QBXML: {
QBXMLMsgsRq: { QBXMLMsgsRq: {
"@onError": "continueOnError", "@onError": "continueOnError",
BillAddRq: { [`${invoice.is_credit_memo ? "VendorCreditAddRq" : "BillAddRq"}`]: {
BillAdd: { [`${invoice.is_credit_memo ? "VendorCreditAdd" : "BillAdd"}`]: {
VendorRef: { VendorRef: {
FullName: invoice.vendor.name, FullName: invoice.vendor.name,
}, },