Added job line ignore.
This commit is contained in:
@@ -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} />;
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user