IO-1345 IO-43 Related Job linking
This commit is contained in:
@@ -24800,6 +24800,27 @@
|
||||
</translation>
|
||||
</translations>
|
||||
</concept_node>
|
||||
<concept_node>
|
||||
<name>relatedros</name>
|
||||
<definition_loaded>false</definition_loaded>
|
||||
<description></description>
|
||||
<comment></comment>
|
||||
<default_text></default_text>
|
||||
<translations>
|
||||
<translation>
|
||||
<language>en-US</language>
|
||||
<approved>false</approved>
|
||||
</translation>
|
||||
<translation>
|
||||
<language>es-MX</language>
|
||||
<approved>false</approved>
|
||||
</translation>
|
||||
<translation>
|
||||
<language>fr-CA</language>
|
||||
<approved>false</approved>
|
||||
</translation>
|
||||
</translations>
|
||||
</concept_node>
|
||||
<concept_node>
|
||||
<name>returntotals</name>
|
||||
<definition_loaded>false</definition_loaded>
|
||||
|
||||
@@ -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 }) {
|
||||
<span style={{ margin: "0rem .5rem" }}>/</span>
|
||||
<CurrencyFormatter>{job.owner_owing}</CurrencyFormatter>
|
||||
</DataLabel>
|
||||
{job.converted && (
|
||||
<DataLabel label={t("jobs.labels.relatedros")}>
|
||||
<JobsRelatedRos jobid={job.id} />
|
||||
</DataLabel>
|
||||
)}
|
||||
<DataLabel label={t("jobs.fields.alt_transport")}>
|
||||
{job.alt_transport}
|
||||
<JobAltTransportChange job={job} />
|
||||
|
||||
@@ -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 <LoadingSpinner />;
|
||||
if (error) return <AlertComponent message={error.message} type="error" />;
|
||||
|
||||
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 = (
|
||||
<Card style={{ minWidth: "25rem" }}>
|
||||
<Form layout="vertical" onFinish={handleAddRo}>
|
||||
<Form.Item
|
||||
name="relatedjobid"
|
||||
label={t("jobs.fields.ro_number")}
|
||||
rules={[{ required: true }]}
|
||||
>
|
||||
<JobSearchSelectComponent convertedOnly />
|
||||
</Form.Item>
|
||||
<Space>
|
||||
<Button loading={saveLoading} htmlType="submit">
|
||||
{t("general.actions.add")}
|
||||
</Button>
|
||||
<Button onClick={() => setRoSearchVisible(false)}>
|
||||
{t("general.actions.cancel")}
|
||||
</Button>
|
||||
</Space>
|
||||
</Form>
|
||||
</Card>
|
||||
);
|
||||
|
||||
return (
|
||||
<Space wrap>
|
||||
{relatedJobs.map((r) => (
|
||||
<Tag key={r.id} closable onClose={() => handleDelete(r.relationshipid)}>
|
||||
<Link to={`/manage/jobs/${r?.id}`}>{r.ro_number}</Link>
|
||||
</Tag>
|
||||
))}
|
||||
<Popover content={popContent} visible={roSearchVisible}>
|
||||
<Button type="link" onClick={() => setRoSearchVisible(true)}>
|
||||
<PlusCircleOutlined />
|
||||
</Button>
|
||||
</Popover>
|
||||
</Space>
|
||||
);
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -1469,6 +1469,7 @@
|
||||
"removedpartsstrikethrough": ""
|
||||
},
|
||||
"reconciliationheader": "",
|
||||
"relatedros": "",
|
||||
"returntotals": "",
|
||||
"rosaletotal": "",
|
||||
"sale_labor": "",
|
||||
|
||||
@@ -1469,6 +1469,7 @@
|
||||
"removedpartsstrikethrough": ""
|
||||
},
|
||||
"reconciliationheader": "",
|
||||
"relatedros": "",
|
||||
"returntotals": "",
|
||||
"rosaletotal": "",
|
||||
"sale_labor": "",
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
- type: run_sql
|
||||
args:
|
||||
cascade: false
|
||||
read_only: false
|
||||
sql: DROP TABLE "public"."relatedjobs";
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -0,0 +1,7 @@
|
||||
- type: rename_relationship
|
||||
args:
|
||||
name: parentjob_rel
|
||||
new_name: job
|
||||
table:
|
||||
name: relatedjobs
|
||||
schema: public
|
||||
@@ -0,0 +1,7 @@
|
||||
- type: rename_relationship
|
||||
args:
|
||||
name: job
|
||||
new_name: parentjob_rel
|
||||
table:
|
||||
name: relatedjobs
|
||||
schema: public
|
||||
@@ -0,0 +1,7 @@
|
||||
- type: rename_relationship
|
||||
args:
|
||||
name: childjob_rel
|
||||
new_name: jobByChildjob
|
||||
table:
|
||||
name: relatedjobs
|
||||
schema: public
|
||||
@@ -0,0 +1,7 @@
|
||||
- type: rename_relationship
|
||||
args:
|
||||
name: jobByChildjob
|
||||
new_name: childjob_rel
|
||||
table:
|
||||
name: relatedjobs
|
||||
schema: public
|
||||
@@ -0,0 +1,7 @@
|
||||
- type: rename_relationship
|
||||
args:
|
||||
name: relatedjobs_parent
|
||||
new_name: relatedjobs
|
||||
table:
|
||||
name: jobs
|
||||
schema: public
|
||||
@@ -0,0 +1,7 @@
|
||||
- type: rename_relationship
|
||||
args:
|
||||
name: relatedjobs
|
||||
new_name: relatedjobs_parent
|
||||
table:
|
||||
name: jobs
|
||||
schema: public
|
||||
@@ -0,0 +1,7 @@
|
||||
- type: rename_relationship
|
||||
args:
|
||||
name: relatedjobs_child
|
||||
new_name: relatedjobsByChildjob
|
||||
table:
|
||||
name: jobs
|
||||
schema: public
|
||||
@@ -0,0 +1,7 @@
|
||||
- type: rename_relationship
|
||||
args:
|
||||
name: relatedjobsByChildjob
|
||||
new_name: relatedjobs_child
|
||||
table:
|
||||
name: jobs
|
||||
schema: public
|
||||
@@ -0,0 +1,6 @@
|
||||
- type: drop_insert_permission
|
||||
args:
|
||||
role: user
|
||||
table:
|
||||
name: relatedjobs
|
||||
schema: public
|
||||
@@ -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
|
||||
@@ -0,0 +1,6 @@
|
||||
- type: drop_select_permission
|
||||
args:
|
||||
role: user
|
||||
table:
|
||||
name: relatedjobs
|
||||
schema: public
|
||||
@@ -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
|
||||
@@ -0,0 +1,6 @@
|
||||
- type: drop_update_permission
|
||||
args:
|
||||
role: user
|
||||
table:
|
||||
name: relatedjobs
|
||||
schema: public
|
||||
@@ -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
|
||||
@@ -0,0 +1,6 @@
|
||||
- type: drop_delete_permission
|
||||
args:
|
||||
role: user
|
||||
table:
|
||||
name: relatedjobs
|
||||
schema: public
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user