diff --git a/bodyshop_translations.babel b/bodyshop_translations.babel index 3e26652fd..4bb07a045 100644 --- a/bodyshop_translations.babel +++ b/bodyshop_translations.babel @@ -24800,6 +24800,27 @@ + + relatedros + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + returntotals false diff --git a/client/src/components/jobs-detail-header/jobs-detail-header.component.jsx b/client/src/components/jobs-detail-header/jobs-detail-header.component.jsx index 8beebc60d..8f59adfb1 100644 --- a/client/src/components/jobs-detail-header/jobs-detail-header.component.jsx +++ b/client/src/components/jobs-detail-header/jobs-detail-header.component.jsx @@ -15,6 +15,7 @@ import JobAltTransportChange from "../job-at-change/job-at-change.component"; import JobEmployeeAssignments from "../job-employee-assignments/job-employee-assignments.container"; import ProductionListColumnProductionNote from "../production-list-columns/production-list-columns.productionnote.component"; import "./jobs-detail-header.styles.scss"; +import JobsRelatedRos from "../jobs-related-ros/jobs-related-ros.component"; const mapStateToProps = createStructuredSelector({ jobRO: selectJobReadOnly, @@ -80,6 +81,11 @@ export function JobsDetailHeader({ job, bodyshop, disabled }) { / {job.owner_owing} + {job.converted && ( + + + + )} {job.alt_transport} diff --git a/client/src/components/jobs-related-ros/jobs-related-ros.component.jsx b/client/src/components/jobs-related-ros/jobs-related-ros.component.jsx new file mode 100644 index 000000000..a94d1a650 --- /dev/null +++ b/client/src/components/jobs-related-ros/jobs-related-ros.component.jsx @@ -0,0 +1,112 @@ +import React, { useState } from "react"; +import { useQuery, useMutation } from "@apollo/client"; +import { Tag, Space, Button, Popover, Card, Form } from "antd"; +import { + DELETE_RELATED_RO, + INSERT_RELATED_ROS, + QUERY_RELATED_ROS, +} from "../../graphql/jobs.queries"; +import LoadingSpinner from "../loading-spinner/loading-spinner.component"; +import AlertComponent from "../alert/alert.component"; +import { PlusCircleOutlined } from "@ant-design/icons"; +import JobSearchSelectComponent from "../job-search-select/job-search-select.component"; +import { useTranslation } from "react-i18next"; +import { Link } from "react-router-dom"; + +export default function JobsRelatedRos({ jobid }) { + const [roSearchVisible, setRoSearchVisible] = useState(false); + const [saveLoading, setSaveLoading] = useState(false); + const [insertRelationship] = useMutation(INSERT_RELATED_ROS); + const [deleteRelationship] = useMutation(DELETE_RELATED_RO); + const { loading, error, data } = useQuery(QUERY_RELATED_ROS, { + variables: { jobid }, + skip: !jobid, + }); + const { t } = useTranslation(); + if (loading) return ; + if (error) return ; + + const relatedJobs = data.relatedjobs.map((r) => { + if (r.parentjob === jobid) { + return { relationshipid: r.id, ...r.childjob_rel }; + } + return { relationshipid: r.id, ...r.parentjob_rel }; + }); + + const handleAddRo = async ({ relatedjobid }) => { + setSaveLoading(true); + + await insertRelationship({ + variables: { relationship: { parentjob: jobid, childjob: relatedjobid } }, + update(cache, { data }) { + cache.modify({ + fields: { + relatedjobs(rj, { readField }) { + return [rj, data.insert_relatedjobs_one]; + }, + }, + }); + }, + }); + setSaveLoading(false); + setRoSearchVisible(false); + }; + const handleDelete = async (id) => { + setSaveLoading(true); + + await deleteRelationship({ + variables: { + relationshipid: id, + }, + + update(cache, { data }) { + cache.modify({ + fields: { + relatedjobs(rj, { readField }) { + return rj.filter((r) => r.id !== id); + }, + }, + }); + }, + }); + setSaveLoading(false); + setRoSearchVisible(false); + }; + + const popContent = ( + +
+ + + + + + + +
+
+ ); + + return ( + + {relatedJobs.map((r) => ( + handleDelete(r.relationshipid)}> + {r.ro_number} + + ))} + + + + + ); +} diff --git a/client/src/graphql/jobs.queries.js b/client/src/graphql/jobs.queries.js index 068218506..4f957d051 100644 --- a/client/src/graphql/jobs.queries.js +++ b/client/src/graphql/jobs.queries.js @@ -1893,3 +1893,48 @@ export const QUERY_JOB_EXPORT_DMS = gql` } } `; +export const QUERY_RELATED_ROS = gql` + query QUERY_RELATED_ROS($jobid: uuid!) { + relatedjobs( + where: { + _or: [{ childjob: { _eq: $jobid } }, { parentjob: { _eq: $jobid } }] + } + ) { + parentjob + id + parentjob_rel { + id + ro_number + } + childjob + childjob_rel { + id + ro_number + } + } + } +`; +export const INSERT_RELATED_ROS = gql` + mutation INSERT_RELATED_ROS($relationship: relatedjobs_insert_input!) { + insert_relatedjobs_one(object: $relationship) { + parentjob + id + parentjob_rel { + id + ro_number + } + childjob + childjob_rel { + id + ro_number + } + } + } +`; +export const DELETE_RELATED_RO = gql` + mutation DELETE_RELATED_RO($relationshipid: uuid!) { + delete_relatedjobs_by_pk(id: $relationshipid) { + id + } + } +`; diff --git a/client/src/translations/en_us/common.json b/client/src/translations/en_us/common.json index e774da4d5..532a1baa5 100644 --- a/client/src/translations/en_us/common.json +++ b/client/src/translations/en_us/common.json @@ -1033,7 +1033,7 @@ "PAP": "OEM Partial", "PAR": "Recored", "PAS": "Sublet", - "PASL": "Sublet" + "PASL": "Sublet (L)" }, "profitcenter_labor": "Profit Center: Labor", "profitcenter_part": "Profit Center: Part", @@ -1469,6 +1469,7 @@ "removedpartsstrikethrough": "Strike through lines represent parts that have been removed from the estimate. They are included for completeness of reconciliation." }, "reconciliationheader": "Parts & Sublet Reconciliation", + "relatedros": "Related ROs", "returntotals": "Return Totals", "rosaletotal": "RO Parts Total", "sale_labor": "Sales - Labor", diff --git a/client/src/translations/es/common.json b/client/src/translations/es/common.json index 6022fc6ef..1dd2932ba 100644 --- a/client/src/translations/es/common.json +++ b/client/src/translations/es/common.json @@ -1469,6 +1469,7 @@ "removedpartsstrikethrough": "" }, "reconciliationheader": "", + "relatedros": "", "returntotals": "", "rosaletotal": "", "sale_labor": "", diff --git a/client/src/translations/fr/common.json b/client/src/translations/fr/common.json index 207262cc3..e1f87f3a3 100644 --- a/client/src/translations/fr/common.json +++ b/client/src/translations/fr/common.json @@ -1469,6 +1469,7 @@ "removedpartsstrikethrough": "" }, "reconciliationheader": "", + "relatedros": "", "returntotals": "", "rosaletotal": "", "sale_labor": "", diff --git a/hasura/migrations/1631052192511_create_table_public_relatedjobs/down.yaml b/hasura/migrations/1631052192511_create_table_public_relatedjobs/down.yaml new file mode 100644 index 000000000..dee738ebd --- /dev/null +++ b/hasura/migrations/1631052192511_create_table_public_relatedjobs/down.yaml @@ -0,0 +1,5 @@ +- type: run_sql + args: + cascade: false + read_only: false + sql: DROP TABLE "public"."relatedjobs"; diff --git a/hasura/migrations/1631052192511_create_table_public_relatedjobs/up.yaml b/hasura/migrations/1631052192511_create_table_public_relatedjobs/up.yaml new file mode 100644 index 000000000..9cbeaefc2 --- /dev/null +++ b/hasura/migrations/1631052192511_create_table_public_relatedjobs/up.yaml @@ -0,0 +1,31 @@ +- type: run_sql + args: + cascade: false + read_only: false + sql: CREATE EXTENSION IF NOT EXISTS pgcrypto; +- type: run_sql + args: + cascade: false + read_only: false + sql: |- + CREATE TABLE "public"."relatedjobs"("id" uuid NOT NULL DEFAULT gen_random_uuid(), "created_at" timestamptz NOT NULL DEFAULT now(), "updated_at" timestamptz NOT NULL DEFAULT now(), "parentjob" uuid NOT NULL, "childjob" UUID NOT NULL, PRIMARY KEY ("id") , FOREIGN KEY ("parentjob") REFERENCES "public"."jobs"("id") ON UPDATE cascade ON DELETE cascade, FOREIGN KEY ("childjob") REFERENCES "public"."jobs"("id") ON UPDATE cascade ON DELETE cascade, UNIQUE ("id")); + CREATE OR REPLACE FUNCTION "public"."set_current_timestamp_updated_at"() + RETURNS TRIGGER AS $$ + DECLARE + _new record; + BEGIN + _new := NEW; + _new."updated_at" = NOW(); + RETURN _new; + END; + $$ LANGUAGE plpgsql; + CREATE TRIGGER "set_public_relatedjobs_updated_at" + BEFORE UPDATE ON "public"."relatedjobs" + FOR EACH ROW + EXECUTE PROCEDURE "public"."set_current_timestamp_updated_at"(); + COMMENT ON TRIGGER "set_public_relatedjobs_updated_at" ON "public"."relatedjobs" + IS 'trigger to set value of column "updated_at" to current timestamp on row update'; +- type: add_existing_table_or_view + args: + name: relatedjobs + schema: public diff --git a/hasura/migrations/1631052229711_track_all_relationships/down.yaml b/hasura/migrations/1631052229711_track_all_relationships/down.yaml new file mode 100644 index 000000000..fcfd5df33 --- /dev/null +++ b/hasura/migrations/1631052229711_track_all_relationships/down.yaml @@ -0,0 +1,24 @@ +- type: drop_relationship + args: + relationship: relatedjobs + table: + name: jobs + schema: public +- type: drop_relationship + args: + relationship: relatedjobsByChildjob + table: + name: jobs + schema: public +- type: drop_relationship + args: + relationship: job + table: + name: relatedjobs + schema: public +- type: drop_relationship + args: + relationship: jobByChildjob + table: + name: relatedjobs + schema: public diff --git a/hasura/migrations/1631052229711_track_all_relationships/up.yaml b/hasura/migrations/1631052229711_track_all_relationships/up.yaml new file mode 100644 index 000000000..5a0f68607 --- /dev/null +++ b/hasura/migrations/1631052229711_track_all_relationships/up.yaml @@ -0,0 +1,40 @@ +- type: create_array_relationship + args: + name: relatedjobs + table: + name: jobs + schema: public + using: + foreign_key_constraint_on: + column: parentjob + table: + name: relatedjobs + schema: public +- type: create_array_relationship + args: + name: relatedjobsByChildjob + table: + name: jobs + schema: public + using: + foreign_key_constraint_on: + column: childjob + table: + name: relatedjobs + schema: public +- type: create_object_relationship + args: + name: job + table: + name: relatedjobs + schema: public + using: + foreign_key_constraint_on: parentjob +- type: create_object_relationship + args: + name: jobByChildjob + table: + name: relatedjobs + schema: public + using: + foreign_key_constraint_on: childjob diff --git a/hasura/migrations/1631052264437_rename_relationship_job_to_parentjob_rel_schema_public_table_relatedjobs/down.yaml b/hasura/migrations/1631052264437_rename_relationship_job_to_parentjob_rel_schema_public_table_relatedjobs/down.yaml new file mode 100644 index 000000000..7c8d8f3df --- /dev/null +++ b/hasura/migrations/1631052264437_rename_relationship_job_to_parentjob_rel_schema_public_table_relatedjobs/down.yaml @@ -0,0 +1,7 @@ +- type: rename_relationship + args: + name: parentjob_rel + new_name: job + table: + name: relatedjobs + schema: public diff --git a/hasura/migrations/1631052264437_rename_relationship_job_to_parentjob_rel_schema_public_table_relatedjobs/up.yaml b/hasura/migrations/1631052264437_rename_relationship_job_to_parentjob_rel_schema_public_table_relatedjobs/up.yaml new file mode 100644 index 000000000..5dfd63d0f --- /dev/null +++ b/hasura/migrations/1631052264437_rename_relationship_job_to_parentjob_rel_schema_public_table_relatedjobs/up.yaml @@ -0,0 +1,7 @@ +- type: rename_relationship + args: + name: job + new_name: parentjob_rel + table: + name: relatedjobs + schema: public diff --git a/hasura/migrations/1631052277534_rename_relationship_jobByChildjob_to_childjob_rel_schema_public_table_relatedjobs/down.yaml b/hasura/migrations/1631052277534_rename_relationship_jobByChildjob_to_childjob_rel_schema_public_table_relatedjobs/down.yaml new file mode 100644 index 000000000..481e2317b --- /dev/null +++ b/hasura/migrations/1631052277534_rename_relationship_jobByChildjob_to_childjob_rel_schema_public_table_relatedjobs/down.yaml @@ -0,0 +1,7 @@ +- type: rename_relationship + args: + name: childjob_rel + new_name: jobByChildjob + table: + name: relatedjobs + schema: public diff --git a/hasura/migrations/1631052277534_rename_relationship_jobByChildjob_to_childjob_rel_schema_public_table_relatedjobs/up.yaml b/hasura/migrations/1631052277534_rename_relationship_jobByChildjob_to_childjob_rel_schema_public_table_relatedjobs/up.yaml new file mode 100644 index 000000000..66ef2fbee --- /dev/null +++ b/hasura/migrations/1631052277534_rename_relationship_jobByChildjob_to_childjob_rel_schema_public_table_relatedjobs/up.yaml @@ -0,0 +1,7 @@ +- type: rename_relationship + args: + name: jobByChildjob + new_name: childjob_rel + table: + name: relatedjobs + schema: public diff --git a/hasura/migrations/1631052341674_rename_relationship_relatedjobs_to_relatedjobs_parent_schema_public_table_jobs/down.yaml b/hasura/migrations/1631052341674_rename_relationship_relatedjobs_to_relatedjobs_parent_schema_public_table_jobs/down.yaml new file mode 100644 index 000000000..da4b9a3e4 --- /dev/null +++ b/hasura/migrations/1631052341674_rename_relationship_relatedjobs_to_relatedjobs_parent_schema_public_table_jobs/down.yaml @@ -0,0 +1,7 @@ +- type: rename_relationship + args: + name: relatedjobs_parent + new_name: relatedjobs + table: + name: jobs + schema: public diff --git a/hasura/migrations/1631052341674_rename_relationship_relatedjobs_to_relatedjobs_parent_schema_public_table_jobs/up.yaml b/hasura/migrations/1631052341674_rename_relationship_relatedjobs_to_relatedjobs_parent_schema_public_table_jobs/up.yaml new file mode 100644 index 000000000..1ada027a9 --- /dev/null +++ b/hasura/migrations/1631052341674_rename_relationship_relatedjobs_to_relatedjobs_parent_schema_public_table_jobs/up.yaml @@ -0,0 +1,7 @@ +- type: rename_relationship + args: + name: relatedjobs + new_name: relatedjobs_parent + table: + name: jobs + schema: public diff --git a/hasura/migrations/1631052355761_rename_relationship_relatedjobsByChildjob_to_relatedjobs_child_schema_public_table_jobs/down.yaml b/hasura/migrations/1631052355761_rename_relationship_relatedjobsByChildjob_to_relatedjobs_child_schema_public_table_jobs/down.yaml new file mode 100644 index 000000000..02793be54 --- /dev/null +++ b/hasura/migrations/1631052355761_rename_relationship_relatedjobsByChildjob_to_relatedjobs_child_schema_public_table_jobs/down.yaml @@ -0,0 +1,7 @@ +- type: rename_relationship + args: + name: relatedjobs_child + new_name: relatedjobsByChildjob + table: + name: jobs + schema: public diff --git a/hasura/migrations/1631052355761_rename_relationship_relatedjobsByChildjob_to_relatedjobs_child_schema_public_table_jobs/up.yaml b/hasura/migrations/1631052355761_rename_relationship_relatedjobsByChildjob_to_relatedjobs_child_schema_public_table_jobs/up.yaml new file mode 100644 index 000000000..e1dca0def --- /dev/null +++ b/hasura/migrations/1631052355761_rename_relationship_relatedjobsByChildjob_to_relatedjobs_child_schema_public_table_jobs/up.yaml @@ -0,0 +1,7 @@ +- type: rename_relationship + args: + name: relatedjobsByChildjob + new_name: relatedjobs_child + table: + name: jobs + schema: public diff --git a/hasura/migrations/1631052776515_update_permission_user_public_table_relatedjobs/down.yaml b/hasura/migrations/1631052776515_update_permission_user_public_table_relatedjobs/down.yaml new file mode 100644 index 000000000..4a387cccd --- /dev/null +++ b/hasura/migrations/1631052776515_update_permission_user_public_table_relatedjobs/down.yaml @@ -0,0 +1,6 @@ +- type: drop_insert_permission + args: + role: user + table: + name: relatedjobs + schema: public diff --git a/hasura/migrations/1631052776515_update_permission_user_public_table_relatedjobs/up.yaml b/hasura/migrations/1631052776515_update_permission_user_public_table_relatedjobs/up.yaml new file mode 100644 index 000000000..729bb888f --- /dev/null +++ b/hasura/migrations/1631052776515_update_permission_user_public_table_relatedjobs/up.yaml @@ -0,0 +1,36 @@ +- type: create_insert_permission + args: + permission: + allow_upsert: true + backend_only: false + check: + _or: + - parentjob_rel: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + - childjob_rel: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + columns: + - id + - created_at + - updated_at + - parentjob + - childjob + set: {} + role: user + table: + name: relatedjobs + schema: public diff --git a/hasura/migrations/1631052784531_update_permission_user_public_table_relatedjobs/down.yaml b/hasura/migrations/1631052784531_update_permission_user_public_table_relatedjobs/down.yaml new file mode 100644 index 000000000..6a1d610c7 --- /dev/null +++ b/hasura/migrations/1631052784531_update_permission_user_public_table_relatedjobs/down.yaml @@ -0,0 +1,6 @@ +- type: drop_select_permission + args: + role: user + table: + name: relatedjobs + schema: public diff --git a/hasura/migrations/1631052784531_update_permission_user_public_table_relatedjobs/up.yaml b/hasura/migrations/1631052784531_update_permission_user_public_table_relatedjobs/up.yaml new file mode 100644 index 000000000..12d5836f6 --- /dev/null +++ b/hasura/migrations/1631052784531_update_permission_user_public_table_relatedjobs/up.yaml @@ -0,0 +1,37 @@ +- type: create_select_permission + args: + permission: + allow_aggregations: false + backend_only: false + columns: + - created_at + - updated_at + - childjob + - id + - parentjob + computed_fields: [] + filter: + _or: + - parentjob_rel: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + - childjob_rel: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + limit: null + role: user + table: + name: relatedjobs + schema: public diff --git a/hasura/migrations/1631052794082_update_permission_user_public_table_relatedjobs/down.yaml b/hasura/migrations/1631052794082_update_permission_user_public_table_relatedjobs/down.yaml new file mode 100644 index 000000000..1ac6dee97 --- /dev/null +++ b/hasura/migrations/1631052794082_update_permission_user_public_table_relatedjobs/down.yaml @@ -0,0 +1,6 @@ +- type: drop_update_permission + args: + role: user + table: + name: relatedjobs + schema: public diff --git a/hasura/migrations/1631052794082_update_permission_user_public_table_relatedjobs/up.yaml b/hasura/migrations/1631052794082_update_permission_user_public_table_relatedjobs/up.yaml new file mode 100644 index 000000000..b638311d2 --- /dev/null +++ b/hasura/migrations/1631052794082_update_permission_user_public_table_relatedjobs/up.yaml @@ -0,0 +1,35 @@ +- type: create_update_permission + args: + permission: + backend_only: false + columns: + - created_at + - updated_at + - childjob + - id + - parentjob + filter: + _or: + - parentjob_rel: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + - childjob_rel: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + set: {} + role: user + table: + name: relatedjobs + schema: public diff --git a/hasura/migrations/1631056626995_update_permission_user_public_table_relatedjobs/down.yaml b/hasura/migrations/1631056626995_update_permission_user_public_table_relatedjobs/down.yaml new file mode 100644 index 000000000..a65b9a796 --- /dev/null +++ b/hasura/migrations/1631056626995_update_permission_user_public_table_relatedjobs/down.yaml @@ -0,0 +1,6 @@ +- type: drop_delete_permission + args: + role: user + table: + name: relatedjobs + schema: public diff --git a/hasura/migrations/1631056626995_update_permission_user_public_table_relatedjobs/up.yaml b/hasura/migrations/1631056626995_update_permission_user_public_table_relatedjobs/up.yaml new file mode 100644 index 000000000..9d49b8d7c --- /dev/null +++ b/hasura/migrations/1631056626995_update_permission_user_public_table_relatedjobs/up.yaml @@ -0,0 +1,28 @@ +- type: create_delete_permission + args: + permission: + backend_only: false + filter: + _or: + - parentjob_rel: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + - childjob_rel: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + role: user + table: + name: relatedjobs + schema: public