diff --git a/client/src/components/jobs-available-new/jobs-available-new.container.jsx b/client/src/components/jobs-available-new/jobs-available-new.container.jsx
index f76481c6a..1f1504836 100644
--- a/client/src/components/jobs-available-new/jobs-available-new.container.jsx
+++ b/client/src/components/jobs-available-new/jobs-available-new.container.jsx
@@ -1,4 +1,4 @@
-import { useMutation, useQuery } from "@apollo/react-hooks";
+import { useApolloClient, useMutation, useQuery } from "@apollo/react-hooks";
import { notification } from "antd";
import Axios from "axios";
import Dinero from "dinero.js";
@@ -13,6 +13,7 @@ import {
QUERY_AVAILABLE_NEW_JOBS,
} from "../../graphql/available-jobs.queries";
import { INSERT_NEW_JOB } from "../../graphql/jobs.queries";
+import { SEARCH_VEHICLE_BY_VIN } from "../../graphql/vehicles.queries";
import { selectBodyshop } from "../../redux/user/user.selectors";
import AlertComponent from "../alert/alert.component";
import LoadingSpinner from "../loading-spinner/loading-spinner.component";
@@ -39,6 +40,7 @@ export function JobsAvailableContainer({
const [insertLoading, setInsertLoading] = useState(false);
const [deleteAllNewJobs] = useMutation(DELETE_ALL_AVAILABLE_NEW_JOBS);
const [insertNewJob] = useMutation(INSERT_NEW_JOB);
+ const client = useApolloClient();
const [loadEstData, estData] = estDataLazyLoad;
const onModalOk = async () => {
@@ -59,63 +61,72 @@ export function JobsAvailableContainer({
notification["error"]({
message: t("jobs.errors.creating", { error: "No job data present." }),
});
- } else {
- const newTotals = (
- await Axios.post("/job/totals", {
- job: {
- ...estData.data.available_jobs_by_pk.est_data,
- joblines: estData.data.available_jobs_by_pk.est_data.joblines.data,
- },
- })
- ).data;
+ return;
+ }
- const newJob = {
- ...estData.data.available_jobs_by_pk.est_data,
- clm_total: Dinero(newTotals.totals.total_repairs).toFormat("0.00"),
- owner_owing: Dinero(newTotals.custPayable.total).toFormat("0.00"),
- job_totals: newTotals,
- queued_for_parts: true,
- };
-
- insertNewJob({
- variables: {
- job: selectedOwner
- ? Object.assign(
- {},
- newJob,
- { owner: null },
- { ownerid: selectedOwner }
- )
- : newJob,
+ const newTotals = (
+ await Axios.post("/job/totals", {
+ job: {
+ ...estData.data.available_jobs_by_pk.est_data,
+ joblines: estData.data.available_jobs_by_pk.est_data.joblines.data,
},
})
- .then((r) => {
- notification["success"]({
- message: t("jobs.successes.created"),
- onClick: () => {
- history.push(
- `/manage/jobs/${r.data.insert_jobs.returning[0].id}`
- );
- },
- });
- //Job has been inserted. Clean up the available jobs record.
+ ).data;
- deleteJob({
- variables: { id: estData.data.available_jobs_by_pk.id },
- }).then((r) => {
- refetch();
- setInsertLoading(false);
- });
- })
- .catch((r) => {
- //error while inserting
- notification["error"]({
- message: t("jobs.errors.creating", { error: r.message }),
- });
+ const existingVehicles = await client.query({
+ query: SEARCH_VEHICLE_BY_VIN,
+ variables: {
+ vin: estData.data.available_jobs_by_pk.est_data.vehicle.data.v_vin,
+ },
+ });
+
+ const newJob = {
+ ...estData.data.available_jobs_by_pk.est_data,
+ clm_total: Dinero(newTotals.totals.total_repairs).toFormat("0.00"),
+ owner_owing: Dinero(newTotals.totals.custPayable.total).toFormat("0.00"),
+ job_totals: newTotals,
+ queued_for_parts: true,
+ ...(existingVehicles.data.vehicles.length > 0
+ ? { vehicleid: existingVehicles.data.vehicles[0].id, vehicle: null }
+ : {}),
+ };
+
+ insertNewJob({
+ variables: {
+ job: selectedOwner
+ ? Object.assign(
+ {},
+ newJob,
+ { owner: null },
+ { ownerid: selectedOwner }
+ )
+ : newJob,
+ },
+ })
+ .then((r) => {
+ notification["success"]({
+ message: t("jobs.successes.created"),
+ onClick: () => {
+ history.push(`/manage/jobs/${r.data.insert_jobs.returning[0].id}`);
+ },
+ });
+ //Job has been inserted. Clean up the available jobs record.
+
+ deleteJob({
+ variables: { id: estData.data.available_jobs_by_pk.id },
+ }).then((r) => {
refetch();
setInsertLoading(false);
});
- }
+ })
+ .catch((r) => {
+ //error while inserting
+ notification["error"]({
+ message: t("jobs.errors.creating", { error: r.message }),
+ });
+ refetch();
+ setInsertLoading(false);
+ });
};
const onModalCancel = () => {
diff --git a/client/src/components/jobs-available-supplement/jobs-available-supplement.component.jsx b/client/src/components/jobs-available-supplement/jobs-available-supplement.component.jsx
index fbe6712b0..bb8c01e08 100644
--- a/client/src/components/jobs-available-supplement/jobs-available-supplement.component.jsx
+++ b/client/src/components/jobs-available-supplement/jobs-available-supplement.component.jsx
@@ -62,7 +62,14 @@ export default function JobsAvailableSupplementComponent({
sorter: (a, b) => alphaSort(a, b),
sortOrder:
state.sortedInfo.columnKey === "cieca_id" && state.sortedInfo.order,
- render: (text, record) =>
{record.job && record.job.ro_number}
,
+ render: (text, record) => (
+ {`${(record.job && record.job.est_number) || ""}${
+ (record.job &&
+ record.job.ro_number &&
+ ` / ${record.job.ro_number}`) ||
+ ""
+ }`}
+ ),
},
{
title: t("jobs.fields.owner"),
diff --git a/client/src/components/jobs-available-supplement/jobs-available-supplement.container.jsx b/client/src/components/jobs-available-supplement/jobs-available-supplement.container.jsx
index b712ad82f..c796caf74 100644
--- a/client/src/components/jobs-available-supplement/jobs-available-supplement.container.jsx
+++ b/client/src/components/jobs-available-supplement/jobs-available-supplement.container.jsx
@@ -102,7 +102,9 @@ export function JobsAvailableSupplementContainer({
job: {
...supp,
clm_total: Dinero(newTotals.totals.total_repairs).toFormat("0.00"),
- owner_owing: Dinero(newTotals.custPayable.total).toFormat("0.00"),
+ owner_owing: Dinero(newTotals.totals.custPayable.total).toFormat(
+ "0.00"
+ ),
job_totals: newTotals,
queued_for_parts: true,
},
diff --git a/client/src/graphql/available-jobs.queries.js b/client/src/graphql/available-jobs.queries.js
index f9a6db9ed..b548505e1 100644
--- a/client/src/graphql/available-jobs.queries.js
+++ b/client/src/graphql/available-jobs.queries.js
@@ -17,6 +17,7 @@ export const QUERY_AVAILABLE_NEW_JOBS = gql`
supplement_number
updated_at
uploaded_by
+ ins_co_nm
vehicle_info
}
}
@@ -39,10 +40,12 @@ export const QUERY_AVAILABLE_SUPPLEMENT_JOBS = gql`
supplement_number
updated_at
uploaded_by
+ ins_co_nm
vehicle_info
job {
id
ro_number
+ est_number
}
}
}
diff --git a/hasura/migrations/1601928069594_alter_table_public_available_jobs_add_column_ins_co_nm/down.yaml b/hasura/migrations/1601928069594_alter_table_public_available_jobs_add_column_ins_co_nm/down.yaml
new file mode 100644
index 000000000..9ba3b36da
--- /dev/null
+++ b/hasura/migrations/1601928069594_alter_table_public_available_jobs_add_column_ins_co_nm/down.yaml
@@ -0,0 +1,5 @@
+- args:
+ cascade: false
+ read_only: false
+ sql: ALTER TABLE "public"."available_jobs" DROP COLUMN "ins_co_nm";
+ type: run_sql
diff --git a/hasura/migrations/1601928069594_alter_table_public_available_jobs_add_column_ins_co_nm/up.yaml b/hasura/migrations/1601928069594_alter_table_public_available_jobs_add_column_ins_co_nm/up.yaml
new file mode 100644
index 000000000..50a3d33c8
--- /dev/null
+++ b/hasura/migrations/1601928069594_alter_table_public_available_jobs_add_column_ins_co_nm/up.yaml
@@ -0,0 +1,5 @@
+- args:
+ cascade: false
+ read_only: false
+ sql: ALTER TABLE "public"."available_jobs" ADD COLUMN "ins_co_nm" text NULL;
+ type: run_sql
diff --git a/hasura/migrations/1601928079284_update_permission_user_public_table_available_jobs/down.yaml b/hasura/migrations/1601928079284_update_permission_user_public_table_available_jobs/down.yaml
new file mode 100644
index 000000000..7d4619ec6
--- /dev/null
+++ b/hasura/migrations/1601928079284_update_permission_user_public_table_available_jobs/down.yaml
@@ -0,0 +1,39 @@
+- args:
+ role: user
+ table:
+ name: available_jobs
+ schema: public
+ type: drop_insert_permission
+- args:
+ permission:
+ check:
+ bodyshop:
+ associations:
+ _and:
+ - user:
+ authid:
+ _eq: X-Hasura-User-Id
+ - active:
+ _eq: true
+ columns:
+ - id
+ - created_at
+ - updated_at
+ - uploaded_by
+ - cieca_id
+ - bodyshopid
+ - est_data
+ - issupplement
+ - jobid
+ - supplement_number
+ - ownr_name
+ - vehicle_info
+ - clm_amt
+ - clm_no
+ - source_system
+ set: {}
+ role: user
+ table:
+ name: available_jobs
+ schema: public
+ type: create_insert_permission
diff --git a/hasura/migrations/1601928079284_update_permission_user_public_table_available_jobs/up.yaml b/hasura/migrations/1601928079284_update_permission_user_public_table_available_jobs/up.yaml
new file mode 100644
index 000000000..c9e93cebd
--- /dev/null
+++ b/hasura/migrations/1601928079284_update_permission_user_public_table_available_jobs/up.yaml
@@ -0,0 +1,40 @@
+- args:
+ role: user
+ table:
+ name: available_jobs
+ schema: public
+ type: drop_insert_permission
+- args:
+ permission:
+ check:
+ bodyshop:
+ associations:
+ _and:
+ - user:
+ authid:
+ _eq: X-Hasura-User-Id
+ - active:
+ _eq: true
+ columns:
+ - bodyshopid
+ - cieca_id
+ - clm_amt
+ - clm_no
+ - created_at
+ - est_data
+ - id
+ - ins_co_nm
+ - issupplement
+ - jobid
+ - ownr_name
+ - source_system
+ - supplement_number
+ - updated_at
+ - uploaded_by
+ - vehicle_info
+ set: {}
+ role: user
+ table:
+ name: available_jobs
+ schema: public
+ type: create_insert_permission
diff --git a/hasura/migrations/1601928094828_update_permission_user_public_table_available_jobs/down.yaml b/hasura/migrations/1601928094828_update_permission_user_public_table_available_jobs/down.yaml
new file mode 100644
index 000000000..e27919805
--- /dev/null
+++ b/hasura/migrations/1601928094828_update_permission_user_public_table_available_jobs/down.yaml
@@ -0,0 +1,40 @@
+- args:
+ role: user
+ table:
+ name: available_jobs
+ schema: public
+ type: drop_select_permission
+- args:
+ permission:
+ allow_aggregations: false
+ columns:
+ - issupplement
+ - supplement_number
+ - est_data
+ - clm_amt
+ - cieca_id
+ - clm_no
+ - ownr_name
+ - source_system
+ - uploaded_by
+ - vehicle_info
+ - created_at
+ - updated_at
+ - bodyshopid
+ - id
+ - jobid
+ computed_fields: []
+ filter:
+ bodyshop:
+ associations:
+ _and:
+ - user:
+ authid:
+ _eq: X-Hasura-User-Id
+ - active:
+ _eq: true
+ role: user
+ table:
+ name: available_jobs
+ schema: public
+ type: create_select_permission
diff --git a/hasura/migrations/1601928094828_update_permission_user_public_table_available_jobs/up.yaml b/hasura/migrations/1601928094828_update_permission_user_public_table_available_jobs/up.yaml
new file mode 100644
index 000000000..19f6031a3
--- /dev/null
+++ b/hasura/migrations/1601928094828_update_permission_user_public_table_available_jobs/up.yaml
@@ -0,0 +1,41 @@
+- args:
+ role: user
+ table:
+ name: available_jobs
+ schema: public
+ type: drop_select_permission
+- args:
+ permission:
+ allow_aggregations: false
+ columns:
+ - bodyshopid
+ - cieca_id
+ - clm_amt
+ - clm_no
+ - created_at
+ - est_data
+ - id
+ - ins_co_nm
+ - issupplement
+ - jobid
+ - ownr_name
+ - source_system
+ - supplement_number
+ - updated_at
+ - uploaded_by
+ - vehicle_info
+ computed_fields: []
+ filter:
+ bodyshop:
+ associations:
+ _and:
+ - user:
+ authid:
+ _eq: X-Hasura-User-Id
+ - active:
+ _eq: true
+ role: user
+ table:
+ name: available_jobs
+ schema: public
+ type: create_select_permission
diff --git a/hasura/migrations/1601928115551_update_permission_user_public_table_available_jobs/down.yaml b/hasura/migrations/1601928115551_update_permission_user_public_table_available_jobs/down.yaml
new file mode 100644
index 000000000..ea3838750
--- /dev/null
+++ b/hasura/migrations/1601928115551_update_permission_user_public_table_available_jobs/down.yaml
@@ -0,0 +1,33 @@
+- args:
+ role: user
+ table:
+ name: available_jobs
+ schema: public
+ type: drop_update_permission
+- args:
+ permission:
+ columns:
+ - cieca_id
+ - clm_amt
+ - est_data
+ - issupplement
+ - ownr_name
+ - source_system
+ - supplement_number
+ - uploaded_by
+ - vehicle_info
+ filter:
+ bodyshop:
+ associations:
+ _and:
+ - user:
+ authid:
+ _eq: X-Hasura-User-Id
+ - active:
+ _eq: true
+ set: {}
+ role: user
+ table:
+ name: available_jobs
+ schema: public
+ type: create_update_permission
diff --git a/hasura/migrations/1601928115551_update_permission_user_public_table_available_jobs/up.yaml b/hasura/migrations/1601928115551_update_permission_user_public_table_available_jobs/up.yaml
new file mode 100644
index 000000000..d4293e24d
--- /dev/null
+++ b/hasura/migrations/1601928115551_update_permission_user_public_table_available_jobs/up.yaml
@@ -0,0 +1,34 @@
+- args:
+ role: user
+ table:
+ name: available_jobs
+ schema: public
+ type: drop_update_permission
+- args:
+ permission:
+ columns:
+ - cieca_id
+ - clm_amt
+ - est_data
+ - ins_co_nm
+ - issupplement
+ - ownr_name
+ - source_system
+ - supplement_number
+ - uploaded_by
+ - vehicle_info
+ filter:
+ bodyshop:
+ associations:
+ _and:
+ - user:
+ authid:
+ _eq: X-Hasura-User-Id
+ - active:
+ _eq: true
+ set: {}
+ role: user
+ table:
+ name: available_jobs
+ schema: public
+ type: create_update_permission
diff --git a/hasura/migrations/metadata.yaml b/hasura/migrations/metadata.yaml
index 8b2ef1bbc..f5b748995 100644
--- a/hasura/migrations/metadata.yaml
+++ b/hasura/migrations/metadata.yaml
@@ -276,40 +276,42 @@ tables:
- active:
_eq: true
columns:
- - id
- - created_at
- - updated_at
- - uploaded_by
- - cieca_id
- bodyshopid
- - est_data
- - issupplement
- - jobid
- - supplement_number
- - ownr_name
- - vehicle_info
+ - cieca_id
- clm_amt
- clm_no
+ - created_at
+ - est_data
+ - id
+ - ins_co_nm
+ - issupplement
+ - jobid
+ - ownr_name
- source_system
+ - supplement_number
+ - updated_at
+ - uploaded_by
+ - vehicle_info
select_permissions:
- role: user
permission:
columns:
- - issupplement
- - supplement_number
- - est_data
- - clm_amt
+ - bodyshopid
- cieca_id
+ - clm_amt
- clm_no
+ - created_at
+ - est_data
+ - id
+ - ins_co_nm
+ - issupplement
+ - jobid
- ownr_name
- source_system
+ - supplement_number
+ - updated_at
- uploaded_by
- vehicle_info
- - created_at
- - updated_at
- - bodyshopid
- - id
- - jobid
filter:
bodyshop:
associations:
@@ -326,6 +328,7 @@ tables:
- cieca_id
- clm_amt
- est_data
+ - ins_co_nm
- issupplement
- ownr_name
- source_system