Added job line ignore.

This commit is contained in:
Patrick Fic
2020-10-20 11:20:14 -07:00
parent c277f6d32d
commit 4290c8c497
16 changed files with 394 additions and 58 deletions

View File

@@ -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 <Switch checked={ignore} onChange={handleChange} loading={loading} />;
}

View File

@@ -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 {

View File

@@ -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) => (
<IgnoreJobLine lineId={record.id} ignore={record.ignore} />
),
},
];
const data =
searchText !== ""
? joblines.filter((j) =>
j.line_desc.toLowerCase().includes(searchText.toLowerCase())
)
: joblines;
return (
<div>
<Table
title={() => (
<Input.Search
placeholder="Search"
onSearch={(val) => {
setSearchText(val);
}}
enterButton
allowClear
/>
)}
columns={columns}
rowKey="id"
loading={loading}
size="small"
pagination={false}
dataSource={joblines}
dataSource={data}
scroll={{
x: true,
y: "20rem",

View File

@@ -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]);

View File

@@ -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
}
}
}
`;

View File

@@ -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
}
}
}