From 22e30ae5cba5cc2c1fdfe5e3c898f17911145ec0 Mon Sep 17 00:00:00 2001 From: Patrick Fic <> Date: Thu, 9 Sep 2021 15:18:43 -0700 Subject: [PATCH] IO-233 WIP CDK --- .../labor-allocations-table.component.jsx | 1 + .../labor-allocations-table.utility.js | 1 + server/cdk/cdk-job-export.js | 46 ++++++++++++++++++- server/graphql-client/queries.js | 27 +++++++++++ 4 files changed, 74 insertions(+), 1 deletion(-) diff --git a/client/src/components/labor-allocations-table/labor-allocations-table.component.jsx b/client/src/components/labor-allocations-table/labor-allocations-table.component.jsx index 50144f157..5bb74b8c8 100644 --- a/client/src/components/labor-allocations-table/labor-allocations-table.component.jsx +++ b/client/src/components/labor-allocations-table/labor-allocations-table.component.jsx @@ -57,6 +57,7 @@ export function LaborAllocationsTable({ sorter: (a, b) => alphaSort(a.cost_center, b.cost_center), sortOrder: state.sortedInfo.columnKey === "cost_center" && state.sortedInfo.order, + render: (text, record) => `${record.cost_center} (${record.mod_lbr_ty})`, }, { title: t("jobs.labels.hrs_total"), diff --git a/client/src/components/labor-allocations-table/labor-allocations-table.utility.js b/client/src/components/labor-allocations-table/labor-allocations-table.utility.js index 87f55c4c5..29f8001f7 100644 --- a/client/src/components/labor-allocations-table/labor-allocations-table.utility.js +++ b/client/src/components/labor-allocations-table/labor-allocations-table.utility.js @@ -16,6 +16,7 @@ export const CalculateAllocationsTotals = ( const r = { opcode: value, cost_center: responsibilitycenters.defaults.costs[value], + mod_lbr_ty: value, total: joblines.reduce((acc2, val2) => { return val2.mod_lbr_ty === value ? acc2 + val2.mod_lb_hrs : acc2; }, 0), diff --git a/server/cdk/cdk-job-export.js b/server/cdk/cdk-job-export.js index c9121093c..af566d67d 100644 --- a/server/cdk/cdk-job-export.js +++ b/server/cdk/cdk-job-export.js @@ -181,6 +181,8 @@ async function CdkSelectedCustomer(socket, selectedCustomerId) { "DEBUG", `{8} Successfully posted sransaction to DMS.` ); + + await MarkJobExported(socket, socket.JobData.id); } else { //Get the error code CdkBase.createLogEvent( @@ -217,6 +219,7 @@ async function CdkSelectedCustomer(socket, selectedCustomerId) { "ERROR", `Error encountered in CdkSelectedCustomer. ${error}` ); + await InsertFailedExportLog(socket, error); } finally { //Ensure we always insert logEvents //GQL to insert logevents. @@ -568,7 +571,7 @@ async function InsertDmsCustomer(socket, newCustomerNumber) { await soapClientCustomerInsertUpdate.insertAsync( { arg0: CDK_CREDENTIALS, - arg1: { dealerId: socket.JobData.bodyshop.cdk_dealerid }, //TODO: Verify why this does not follow the other standards. + arg1: { dealerId: socket.JobData.bodyshop.cdk_dealerid }, arg2: { userId: null }, arg3: { //Copied the required fields from the other integration. @@ -1219,3 +1222,44 @@ async function DeleteDmsWip(socket) { throw new Error(error); } } + +async function MarkJobExported(socket, jobid) { + CdkBase.createLogEvent(socket, "DEBUG", `Querying job data for id ${jobid}`); + const client = new GraphQLClient(process.env.GRAPHQL_ENDPOINT, {}); + const result = await client + .setHeaders({ Authorization: `Bearer ${socket.handshake.auth.token}` }) + .request(queries.MARK_JOB_EXPORTED, { + jobId: jobid, + job: { + status: + socket.JobData.bodyshop.md_ro_statuses.default_exported || + "Exported*", + date_exported: new Date(), + }, + log: { + bodyshopid: socket.JobData.bodyshop.id, + jobid: jobid, + successful: true, + useremail: socket.user.email, + }, + }); + + return result; +} + +async function InsertFailedExportLog(socket, error) { + const client = new GraphQLClient(process.env.GRAPHQL_ENDPOINT, {}); + const result = await client + .setHeaders({ Authorization: `Bearer ${socket.handshake.auth.token}` }) + .request(queries.INSERT_EXPORT_LOG, { + log: { + bodyshopid: socket.JobData.bodyshop.id, + jobid: socket.JobData.id, + successful: false, + message: [error], + useremail: socket.user.email, + }, + }); + + return result; +} diff --git a/server/graphql-client/queries.js b/server/graphql-client/queries.js index c08047b85..550fecd77 100644 --- a/server/graphql-client/queries.js +++ b/server/graphql-client/queries.js @@ -177,6 +177,7 @@ query QUERY_JOBS_FOR_CDK_EXPORT($id: uuid!) { ca_customer_gst bodyshop { id + md_ro_statuses md_responsibility_centers accountingconfig cdk_dealerid @@ -1067,3 +1068,29 @@ exports.SET_QBO_AUTH = `mutation SET_QBO_AUTH($email: String!, $qbo_auth: jsonb! } } `; + +exports.MARK_JOB_EXPORTED = ` +mutation MARK_JOB_EXPORTED($jobId: uuid!, $job: jobs_set_input!, $log: exportlog_insert_input!) { + update_jobs(where: {id: {_eq: $jobId}}, _set: $job) { + returning { + id + date_exported + status + alt_transport + ro_number + production_vars + lbr_adjustments + } + } + insert_exportlog_one(object: $log) { + id + } +} +`; +exports.INSERT_EXPORT_LOG = ` +mutation INSERT_EXPORT_LOG($log: exportlog_insert_input!) { + insert_exportlog_one(object: $log) { + id + } +} +`;