diff --git a/electron/decoder/decoder.js b/electron/decoder/decoder.js index 0199932..5fc5b74 100644 --- a/electron/decoder/decoder.js +++ b/electron/decoder/decoder.js @@ -326,28 +326,27 @@ async function DecodeLinFile(extensionlessFilePath) { } ); }) - .filter( - (jobline) => - jobline.part_type && - !jobline.db_ref.startsWith("900") && - !jobline.line_desc.toLowerCase().startsWith("urethane") && - !jobline.line_desc.toLowerCase().startsWith("wheel") && - !jobline.line_desc.toLowerCase().startsWith("hazardous") && - !jobline.line_desc.toLowerCase().startsWith("detail") && - !jobline.line_desc.toLowerCase().startsWith("clean") && - jobline.part_type.toUpperCase() !== "PAG" && - jobline.part_type.toUpperCase() !== "PAS" && - jobline.part_type.toUpperCase() !== "PASL" && - jobline.part_type.toUpperCase() !== "PAE" && - jobline.glass_flag === false - ) + // .filter( + // (jobline) => + // jobline.part_type && + // !jobline.db_ref.startsWith("900") && + // !jobline.line_desc.toLowerCase().startsWith("urethane") && + // !jobline.line_desc.toLowerCase().startsWith("wheel") && + // !jobline.line_desc.toLowerCase().startsWith("hazardous") && + // !jobline.line_desc.toLowerCase().startsWith("detail") && + // !jobline.line_desc.toLowerCase().startsWith("clean") && + // jobline.part_type.toUpperCase() !== "PAG" && + // jobline.part_type.toUpperCase() !== "PAS" && + // jobline.part_type.toUpperCase() !== "PASL" && + // jobline.part_type.toUpperCase() !== "PAE" && + // jobline.glass_flag === false + // ) .map((jobline) => { if ( (jobline.db_price === null || jobline.db_price === 0) && !!jobline.act_price && jobline.act_price > 0 ) { - console.log(1, jobline.line_desc, jobline.db_price, jobline.act_price); log.info( "DB Price null/lower than act price", jobline.line_desc, @@ -368,10 +367,25 @@ async function DecodeLinFile(extensionlessFilePath) { jobline.db_price, jobline.act_price ); - console.log(2, jobline.line_desc, jobline.db_price, jobline.act_price); jobline.db_price = jobline.act_price; } + if ( + !jobline.part_type || + jobline.db_ref.startsWith("900") || + jobline.line_desc.toLowerCase().startsWith("urethane") || + jobline.line_desc.toLowerCase().startsWith("wheel") || + jobline.line_desc.toLowerCase().startsWith("hazardous") || + jobline.line_desc.toLowerCase().startsWith("detail") || + jobline.line_desc.toLowerCase().startsWith("clean") || + jobline.part_type.toUpperCase() === "PAG" || + jobline.part_type.toUpperCase() === "PAS" || + jobline.part_type.toUpperCase() === "PASL" || + jobline.part_type.toUpperCase() === "PAE" || + jobline.glass_flag === true + ) + jobline.ignore = true; + delete jobline.glass_flag; return jobline; }); diff --git a/hasura/migrations/1603216465074_alter_table_public_joblines_add_column_ignore/down.yaml b/hasura/migrations/1603216465074_alter_table_public_joblines_add_column_ignore/down.yaml new file mode 100644 index 0000000..155b5e1 --- /dev/null +++ b/hasura/migrations/1603216465074_alter_table_public_joblines_add_column_ignore/down.yaml @@ -0,0 +1,5 @@ +- args: + cascade: false + read_only: false + sql: ALTER TABLE "public"."joblines" DROP COLUMN "ignore"; + type: run_sql diff --git a/hasura/migrations/1603216465074_alter_table_public_joblines_add_column_ignore/up.yaml b/hasura/migrations/1603216465074_alter_table_public_joblines_add_column_ignore/up.yaml new file mode 100644 index 0000000..253741d --- /dev/null +++ b/hasura/migrations/1603216465074_alter_table_public_joblines_add_column_ignore/up.yaml @@ -0,0 +1,6 @@ +- args: + cascade: false + read_only: false + sql: ALTER TABLE "public"."joblines" ADD COLUMN "ignore" boolean NOT NULL DEFAULT + false; + type: run_sql diff --git a/hasura/migrations/1603216471209_update_permission_user_public_table_joblines/down.yaml b/hasura/migrations/1603216471209_update_permission_user_public_table_joblines/down.yaml new file mode 100644 index 0000000..1b9527e --- /dev/null +++ b/hasura/migrations/1603216471209_update_permission_user_public_table_joblines/down.yaml @@ -0,0 +1,39 @@ +- args: + role: user + table: + name: joblines + schema: public + type: drop_insert_permission +- args: + permission: + backend_only: false + check: + job: + bodyshop: + associations: + user: + authid: + _eq: X-Hasura-User-Id + columns: + - act_price + - created_at + - db_price + - db_ref + - id + - jobid + - line_desc + - line_ind + - line_no + - oem_partno + - part_qty + - part_type + - price_diff + - price_diff_pc + - unq_seq + - updated_at + set: {} + role: user + table: + name: joblines + schema: public + type: create_insert_permission diff --git a/hasura/migrations/1603216471209_update_permission_user_public_table_joblines/up.yaml b/hasura/migrations/1603216471209_update_permission_user_public_table_joblines/up.yaml new file mode 100644 index 0000000..86afc84 --- /dev/null +++ b/hasura/migrations/1603216471209_update_permission_user_public_table_joblines/up.yaml @@ -0,0 +1,40 @@ +- args: + role: user + table: + name: joblines + schema: public + type: drop_insert_permission +- args: + permission: + backend_only: false + check: + job: + bodyshop: + associations: + user: + authid: + _eq: X-Hasura-User-Id + columns: + - act_price + - created_at + - db_price + - db_ref + - id + - ignore + - jobid + - line_desc + - line_ind + - line_no + - oem_partno + - part_qty + - part_type + - price_diff + - price_diff_pc + - unq_seq + - updated_at + set: {} + role: user + table: + name: joblines + schema: public + type: create_insert_permission diff --git a/hasura/migrations/1603216476135_update_permission_user_public_table_joblines/down.yaml b/hasura/migrations/1603216476135_update_permission_user_public_table_joblines/down.yaml new file mode 100644 index 0000000..518eff7 --- /dev/null +++ b/hasura/migrations/1603216476135_update_permission_user_public_table_joblines/down.yaml @@ -0,0 +1,39 @@ +- args: + role: user + table: + name: joblines + schema: public + type: drop_select_permission +- args: + permission: + allow_aggregations: false + columns: + - act_price + - created_at + - db_price + - db_ref + - id + - jobid + - line_desc + - line_ind + - line_no + - oem_partno + - part_qty + - part_type + - price_diff + - price_diff_pc + - unq_seq + - updated_at + computed_fields: [] + filter: + job: + bodyshop: + associations: + user: + authid: + _eq: X-Hasura-User-Id + role: user + table: + name: joblines + schema: public + type: create_select_permission diff --git a/hasura/migrations/1603216476135_update_permission_user_public_table_joblines/up.yaml b/hasura/migrations/1603216476135_update_permission_user_public_table_joblines/up.yaml new file mode 100644 index 0000000..873ee04 --- /dev/null +++ b/hasura/migrations/1603216476135_update_permission_user_public_table_joblines/up.yaml @@ -0,0 +1,40 @@ +- args: + role: user + table: + name: joblines + schema: public + type: drop_select_permission +- args: + permission: + allow_aggregations: false + columns: + - act_price + - created_at + - db_price + - db_ref + - id + - ignore + - jobid + - line_desc + - line_ind + - line_no + - oem_partno + - part_qty + - part_type + - price_diff + - price_diff_pc + - unq_seq + - updated_at + computed_fields: [] + filter: + job: + bodyshop: + associations: + user: + authid: + _eq: X-Hasura-User-Id + role: user + table: + name: joblines + schema: public + type: create_select_permission diff --git a/hasura/migrations/1603216480562_update_permission_user_public_table_joblines/down.yaml b/hasura/migrations/1603216480562_update_permission_user_public_table_joblines/down.yaml new file mode 100644 index 0000000..f753d5a --- /dev/null +++ b/hasura/migrations/1603216480562_update_permission_user_public_table_joblines/down.yaml @@ -0,0 +1,38 @@ +- args: + role: user + table: + name: joblines + schema: public + type: drop_update_permission +- args: + permission: + columns: + - act_price + - created_at + - db_price + - db_ref + - id + - jobid + - line_desc + - line_ind + - line_no + - oem_partno + - part_qty + - part_type + - price_diff + - price_diff_pc + - unq_seq + - updated_at + filter: + job: + bodyshop: + associations: + user: + authid: + _eq: X-Hasura-User-Id + set: {} + role: user + table: + name: joblines + schema: public + type: create_update_permission diff --git a/hasura/migrations/1603216480562_update_permission_user_public_table_joblines/up.yaml b/hasura/migrations/1603216480562_update_permission_user_public_table_joblines/up.yaml new file mode 100644 index 0000000..5f6a028 --- /dev/null +++ b/hasura/migrations/1603216480562_update_permission_user_public_table_joblines/up.yaml @@ -0,0 +1,39 @@ +- args: + role: user + table: + name: joblines + schema: public + type: drop_update_permission +- args: + permission: + columns: + - act_price + - created_at + - db_price + - db_ref + - id + - ignore + - jobid + - line_desc + - line_ind + - line_no + - oem_partno + - part_qty + - part_type + - price_diff + - price_diff_pc + - unq_seq + - updated_at + filter: + job: + bodyshop: + associations: + user: + authid: + _eq: X-Hasura-User-Id + set: {} + role: user + table: + name: joblines + schema: public + type: create_update_permission diff --git a/hasura/migrations/metadata.yaml b/hasura/migrations/metadata.yaml index 2942282..c3aca2f 100644 --- a/hasura/migrations/metadata.yaml +++ b/hasura/migrations/metadata.yaml @@ -89,6 +89,7 @@ tables: - db_price - db_ref - id + - ignore - jobid - line_desc - line_ind @@ -110,6 +111,7 @@ tables: - db_price - db_ref - id + - ignore - jobid - line_desc - line_ind @@ -137,6 +139,7 @@ tables: - db_price - db_ref - id + - ignore - jobid - line_desc - line_ind diff --git a/src/components/atoms/ignore-job-line/ignore-job-line.atom.jsx b/src/components/atoms/ignore-job-line/ignore-job-line.atom.jsx new file mode 100644 index 0000000..b9e2cdc --- /dev/null +++ b/src/components/atoms/ignore-job-line/ignore-job-line.atom.jsx @@ -0,0 +1,24 @@ +import { useMutation } from "@apollo/client"; +import { message, Switch } from "antd"; +import React, { useState } from "react"; +import { UPDATE_JOB_LINE } from "../../../graphql/joblines.queries"; +const { log } = window; + +export default function IgnoreJobLineAtom({ ignore, lineId }) { + const [updateJobLine] = useMutation(UPDATE_JOB_LINE); + const [loading, setLoading] = useState(false); + const handleChange = async (checked) => { + setLoading(true); + const result = await updateJobLine({ + variables: { lineId: lineId, line: { ignore: checked } }, + }); + if (result.errors) { + message.error("Error updating line."); + log.error("Error updating job.", result.errors); + } else { + } + setLoading(false); + }; + + return ; +} diff --git a/src/components/atoms/jobs-parts-graph/jobs-parts-graph.atom.jsx b/src/components/atoms/jobs-parts-graph/jobs-parts-graph.atom.jsx index 358d889..ff3a765 100644 --- a/src/components/atoms/jobs-parts-graph/jobs-parts-graph.atom.jsx +++ b/src/components/atoms/jobs-parts-graph/jobs-parts-graph.atom.jsx @@ -12,17 +12,19 @@ export default function JobPartsGraphAtom({ const data = useMemo(() => { if (!job) return []; - const sums = job.joblines.reduce((acc, val) => { - if (!acc[val.part_type]) { - acc[val.part_type] = Dinero(); - } + const sums = job.joblines + .filter((j) => !j.ignore) + .reduce((acc, val) => { + if (!acc[val.part_type]) { + acc[val.part_type] = Dinero(); + } - acc[val.part_type] = acc[val.part_type].add( - Dinero({ amount: Math.round((val[price] || 0) * 100) }) - ); + acc[val.part_type] = acc[val.part_type].add( + Dinero({ amount: Math.round((val[price] || 0) * 100) }) + ); - return acc; - }, {}); + return acc; + }, {}); return Object.keys(sums).map((key) => { return { diff --git a/src/components/molecules/jobs-lines-table/jobs-lines-table.molecule.jsx b/src/components/molecules/jobs-lines-table/jobs-lines-table.molecule.jsx index 526961a..2749b7a 100644 --- a/src/components/molecules/jobs-lines-table/jobs-lines-table.molecule.jsx +++ b/src/components/molecules/jobs-lines-table/jobs-lines-table.molecule.jsx @@ -1,16 +1,19 @@ -import { Table } from "antd"; -import React from "react"; +import { Input, Table } from "antd"; +import React, { useState } from "react"; import CurrencyFormatterAtom from "../../atoms/currency-formatter/currency-formatter.atom"; +import IgnoreJobLine from "../../atoms/ignore-job-line/ignore-job-line.atom"; import partTypeConverterAtom from "../../atoms/part-type-converter/part-type-converter.atom"; import PriceDiffPcFormatterAtom from "../../atoms/price-diff-pc-formatter/price-diff-pc-formatter.atom"; export default function JobLinesTableMolecule({ loading, job }) { + const [searchText, setSearchText] = useState(""); + const { joblines } = job; const columns = [ { title: "#", - dataIndex: "unq_seq", - key: "unq_seq", + dataIndex: "line_no", + key: "line_no", }, { title: "S#", @@ -73,17 +76,47 @@ export default function JobLinesTableMolecule({ loading, job }) { /> ), }, + { + title: "Ignore?", + dataIndex: "ignore", + key: "ignore", + filters: [ + { text: "True", value: true }, + { text: "False", value: false }, + ], + onFilter: (value, record) => value === record.ignore, + render: (text, record) => ( + + ), + }, ]; + const data = + searchText !== "" + ? joblines.filter((j) => + j.line_desc.toLowerCase().includes(searchText.toLowerCase()) + ) + : joblines; + return (
( + { + setSearchText(val); + }} + enterButton + allowClear + /> + )} columns={columns} rowKey="id" loading={loading} size="small" pagination={false} - dataSource={joblines} + dataSource={data} scroll={{ x: true, y: "20rem", diff --git a/src/components/molecules/jobs-targets-stats/jobs-targets-stats.molecule.jsx b/src/components/molecules/jobs-targets-stats/jobs-targets-stats.molecule.jsx index b5dc058..82b53ab 100644 --- a/src/components/molecules/jobs-targets-stats/jobs-targets-stats.molecule.jsx +++ b/src/components/molecules/jobs-targets-stats/jobs-targets-stats.molecule.jsx @@ -26,15 +26,17 @@ export function JobsTargetsStatsMolecule({ if (!job) { return 0; } - return job.joblines.reduce((acc, val) => { - if (val.price_diff > 0) { - return acc.add( - Dinero({ amount: Math.round((val.price_diff || 0) * 100) }) - ); - } else { - return acc; - } - }, Dinero()); + return job.joblines + .filter((j) => !j.ignore) + .reduce((acc, val) => { + if (val.price_diff > 0) { + return acc.add( + Dinero({ amount: Math.round((val.price_diff || 0) * 100) }) + ); + } else { + return acc; + } + }, Dinero()); }, [job]); const currentRpsPc = useMemo(() => { @@ -42,9 +44,11 @@ export function JobsTargetsStatsMolecule({ if (!job) { return 0; } - const dbPriceSum = job.joblines.reduce((acc, val) => { - return acc + val.db_price; - }, 0); + const dbPriceSum = job.joblines + .filter((j) => !j.ignore) + .reduce((acc, val) => { + return acc + val.db_price; + }, 0); return (currentRpsDollars.getAmount() / dbPriceSum).toFixed(1); }, [job, currentRpsDollars]); diff --git a/src/graphql/joblines.queries.js b/src/graphql/joblines.queries.js new file mode 100644 index 0000000..8f1879a --- /dev/null +++ b/src/graphql/joblines.queries.js @@ -0,0 +1,23 @@ +import gql from "graphql-tag"; + +export const UPDATE_JOB_LINE = gql` + mutation UPDATE_JOB_LINE($lineId: uuid!, $line: joblines_set_input!) { + update_joblines(where: { id: { _eq: $lineId } }, _set: $line) { + returning { + id + line_no + act_price + db_price + line_desc + line_ind + oem_partno + part_qty + part_type + unq_seq + price_diff + price_diff_pc + ignore + } + } + } +`; diff --git a/src/graphql/jobs.queries.js b/src/graphql/jobs.queries.js index 0528fbf..73be1ad 100644 --- a/src/graphql/jobs.queries.js +++ b/src/graphql/jobs.queries.js @@ -10,21 +10,6 @@ export const INSERT_NEW_JOB = gql` } `; -// on_conflict: { -// constraint: jobs_clm_no_bodyshopid_key -// update_columns: [ -// ins_co_nm -// clm_no -// clm_total -// ownr_ln -// ownr_fn -// v_vin -// v_make_desc -// v_model_desc -// v_type -// ] -// } - export const QUERY_ALL_JOBS_PAGINATED = gql` query QUERY_ALL_JOBS_PAGINATED( $offset: Int @@ -106,6 +91,7 @@ export const QUERY_JOB_BY_PK = gql` close_date joblines(order_by: { line_no: asc }) { id + line_no act_price db_price line_desc @@ -116,6 +102,7 @@ export const QUERY_JOB_BY_PK = gql` unq_seq price_diff price_diff_pc + ignore } } }