From df93357cec0156ad9ff2d0022084f2c3265db9ee Mon Sep 17 00:00:00 2001 From: Allan Carr Date: Wed, 14 Aug 2024 11:38:35 -0700 Subject: [PATCH] IO-2856 Mark Exported Button Signed-off-by: Allan Carr --- ...accounting-receivables-table.component.jsx | 24 ++-- .../jobs-mark-selected-exported.jsx | 105 ++++++++++++++++++ ...yable-mark-selected-exported.component.jsx | 2 +- ...yment-mark-selected-exported.component.jsx | 2 +- 4 files changed, 124 insertions(+), 9 deletions(-) create mode 100644 client/src/components/jobs-mark-selected-exported/jobs-mark-selected-exported.jsx diff --git a/client/src/components/accounting-receivables-table/accounting-receivables-table.component.jsx b/client/src/components/accounting-receivables-table/accounting-receivables-table.component.jsx index 83b139827..fb2681623 100644 --- a/client/src/components/accounting-receivables-table/accounting-receivables-table.component.jsx +++ b/client/src/components/accounting-receivables-table/accounting-receivables-table.component.jsx @@ -13,6 +13,7 @@ import { createStructuredSelector } from "reselect"; import { selectBodyshop } from "../../redux/user/user.selectors"; import { DateFormatter } from "../../utils/DateFormatter"; import ExportLogsCountDisplay from "../export-logs-count-display/export-logs-count-display.component"; +import JobMarkSelectedExported from "../jobs-mark-selected-exported/jobs-mark-selected-exported"; import OwnerNameDisplay, { OwnerNameDisplayFunction } from "../owner-name-display/owner-name-display.component"; import QboAuthorizeComponent from "../qbo-authorize/qbo-authorize.component"; @@ -170,13 +171,22 @@ export function AccountingReceivablesTableComponent({ bodyshop, loading, jobs, r extra={ {!bodyshop.cdk_dealerid && !bodyshop.pbs_serialnumber && ( - + <> + + + )} {bodyshop.accountingconfig && bodyshop.accountingconfig.qbo && } ({ + insertAuditTrail: ({ jobid, operation, type }) => dispatch(insertAuditTrail({ jobid, operation, type })) +}); + +export default connect(mapStateToProps, mapDispatchToProps)(JobMarkSelectedExported); + +export function JobMarkSelectedExported({ + bodyshop, + currentUser, + jobIds, + disabled, + loadingCallback, + completedCallback, + refetch, + insertAuditTrail +}) { + const { t } = useTranslation(); + const [loading, setLoading] = useState(false); + const [open, setOpen] = useState(false); + const [insertExportLog] = useMutation(INSERT_EXPORT_LOG); + + const [updateJob] = useMutation(UPDATE_JOBS); + const handleUpdate = async () => { + setLoading(true); + loadingCallback(true); + const result = await updateJob({ + variables: { + jobIds: jobIds, + fields: { + status: bodyshop.md_ro_statuses.default_exported || "Exported*", + date_exported: new Date() + } + }, + update(cache) {} + }); + + await insertExportLog({ + variables: { + logs: jobIds.map((id) => { + return { + bodyshopid: bodyshop.id, + jobid: id, + successful: true, + message: JSON.stringify([t("general.labels.markedexported")]), + useremail: currentUser.email + }; + }) + } + }); + + if (!result.errors) { + notification["success"]({ message: t("jobs.successes.save") }); + result.data.update_jobs.returning.forEach((job) => { + console.log("results job", job.id, "audit: ", AuditTrailMapping.admin_jobmarkexported()); + insertAuditTrail({ + jobid: job.id, + operation: AuditTrailMapping.admin_jobmarkexported(), + type: "admin_jobmarkexported" + }); + }); + } else { + notification["error"]({ + message: t("jobs.errors.saving", { + error: JSON.stringify(result.errors) + }) + }); + } + loadingCallback(false); + completedCallback && completedCallback([]); + setLoading(false); + refetch && refetch(); + setOpen(false); + }; + + return ( + setOpen(false)} + onConfirm={handleUpdate} + disabled={disabled} + > + + + ); +} diff --git a/client/src/components/payable-mark-selected-exported/payable-mark-selected-exported.component.jsx b/client/src/components/payable-mark-selected-exported/payable-mark-selected-exported.component.jsx index 08cd00b43..ccd480547 100644 --- a/client/src/components/payable-mark-selected-exported/payable-mark-selected-exported.component.jsx +++ b/client/src/components/payable-mark-selected-exported/payable-mark-selected-exported.component.jsx @@ -90,7 +90,7 @@ export function BillMarkSelectedExported({ onConfirm={handleUpdate} disabled={disabled} > - diff --git a/client/src/components/payment-mark-selected-exported/payment-mark-selected-exported.component.jsx b/client/src/components/payment-mark-selected-exported/payment-mark-selected-exported.component.jsx index 3727e23eb..8dbd2ae45 100644 --- a/client/src/components/payment-mark-selected-exported/payment-mark-selected-exported.component.jsx +++ b/client/src/components/payment-mark-selected-exported/payment-mark-selected-exported.component.jsx @@ -90,7 +90,7 @@ export function PaymentMarkSelectedExported({ onConfirm={handleUpdate} disabled={disabled} > -