IO-789 Adjust main job query to pull bill data.
This commit is contained in:
@@ -1,11 +1,10 @@
|
|||||||
import { DeleteFilled, FilterFilled, SyncOutlined } from "@ant-design/icons";
|
import { DeleteFilled, FilterFilled, SyncOutlined } from "@ant-design/icons";
|
||||||
import { useMutation, useQuery } from "@apollo/client";
|
import { useMutation } from "@apollo/client";
|
||||||
import { Button, Dropdown, Input, Menu, Space, Table } from "antd";
|
import { Button, Dropdown, Input, Menu, Space, Table } from "antd";
|
||||||
import React, { useMemo, useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { createStructuredSelector } from "reselect";
|
import { createStructuredSelector } from "reselect";
|
||||||
import { QUERY_BILLS_BY_JOB_REF } from "../../graphql/bill-lines.queries";
|
|
||||||
import { DELETE_JOB_LINE_BY_PK } from "../../graphql/jobs-lines.queries";
|
import { DELETE_JOB_LINE_BY_PK } from "../../graphql/jobs-lines.queries";
|
||||||
import { selectJobReadOnly } from "../../redux/application/application.selectors";
|
import { selectJobReadOnly } from "../../redux/application/application.selectors";
|
||||||
import { setModalContext } from "../../redux/modals/modals.actions";
|
import { setModalContext } from "../../redux/modals/modals.actions";
|
||||||
@@ -48,26 +47,26 @@ export function JobLinesComponent({
|
|||||||
}) {
|
}) {
|
||||||
const [deleteJobLine] = useMutation(DELETE_JOB_LINE_BY_PK);
|
const [deleteJobLine] = useMutation(DELETE_JOB_LINE_BY_PK);
|
||||||
|
|
||||||
const {
|
// const {
|
||||||
loading: billLinesLoading,
|
// loading: billLinesLoading,
|
||||||
error: billLinesError,
|
// error: billLinesError,
|
||||||
data: billLinesData,
|
// data: billLinesData,
|
||||||
} = useQuery(QUERY_BILLS_BY_JOB_REF, {
|
// } = useQuery(QUERY_BILLS_BY_JOB_REF, {
|
||||||
variables: { jobId: job && job.id },
|
// variables: { jobId: job && job.id },
|
||||||
skip: loading || !job,
|
// skip: loading || !job,
|
||||||
});
|
// });
|
||||||
|
|
||||||
const billLinesDataObj = useMemo(() => {
|
// const billLinesDataObj = useMemo(() => {
|
||||||
if (!billLinesData) return {};
|
// if (!billLinesData) return {};
|
||||||
const ret = {};
|
// const ret = {};
|
||||||
billLinesData.billlines.map((b) => {
|
// billLinesData.billlines.map((b) => {
|
||||||
if (b.joblineid) {
|
// if (b.joblineid) {
|
||||||
ret[b.joblineid] = { ...b, total: b.actual_price * b.quantity };
|
// ret[b.joblineid] = { ...b, total: b.actual_price * b.quantity };
|
||||||
}
|
// }
|
||||||
return null;
|
// return null;
|
||||||
});
|
// });
|
||||||
return ret;
|
// return ret;
|
||||||
}, [billLinesData]);
|
// }, [billLinesData]);
|
||||||
|
|
||||||
const [state, setState] = useState({
|
const [state, setState] = useState({
|
||||||
sortedInfo: {},
|
sortedInfo: {},
|
||||||
@@ -231,14 +230,7 @@ export function JobLinesComponent({
|
|||||||
title: t("joblines.labels.billref"),
|
title: t("joblines.labels.billref"),
|
||||||
dataIndex: "billref",
|
dataIndex: "billref",
|
||||||
key: "billref",
|
key: "billref",
|
||||||
render: (text, record) => (
|
render: (text, record) => <JobLinesBillRefernece jobline={record} />,
|
||||||
<JobLinesBillRefernece
|
|
||||||
jobline={record}
|
|
||||||
loading={billLinesLoading}
|
|
||||||
error={billLinesError}
|
|
||||||
billLinesObject={billLinesDataObj}
|
|
||||||
/>
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: t("joblines.fields.status"),
|
title: t("joblines.fields.status"),
|
||||||
|
|||||||
@@ -1,26 +1,10 @@
|
|||||||
import { Spin } from "antd";
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import AlertComponent from "../alert/alert.component";
|
|
||||||
|
|
||||||
export default function JobLinesBillRefernece({
|
export default function JobLinesBillRefernece({ jobline }) {
|
||||||
jobline,
|
const billLine = jobline.billlines && jobline.billlines[0];
|
||||||
loading,
|
|
||||||
error,
|
|
||||||
billLinesObject,
|
|
||||||
}) {
|
|
||||||
if (loading)
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<Spin size="small" className="loading-spinner" />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
if (!billLinesObject) return null;
|
|
||||||
|
|
||||||
const billLine = billLinesObject[jobline.id];
|
|
||||||
if (!billLine) return null;
|
if (!billLine) return null;
|
||||||
|
|
||||||
if (error) return <AlertComponent message={error.message} type="error" />;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>{`${(billLine.actual_price * billLine.quantity).toFixed(2)} (${
|
<div>{`${(billLine.actual_price * billLine.quantity).toFixed(2)} (${
|
||||||
billLine.bill.vendor.name
|
billLine.bill.vendor.name
|
||||||
|
|||||||
@@ -22,26 +22,3 @@ export const INSERT_NEW_BILL_LINES = gql`
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export const QUERY_BILLS_BY_JOB_REF = gql`
|
|
||||||
query QUERY_BILLS_BY_JOB_REF($jobId: uuid!) {
|
|
||||||
billlines(
|
|
||||||
where: { bill: { jobid: { _eq: $jobId } } }
|
|
||||||
limit: 1
|
|
||||||
order_by: { bill: { date: desc } }
|
|
||||||
) {
|
|
||||||
id
|
|
||||||
quantity
|
|
||||||
actual_cost
|
|
||||||
actual_price
|
|
||||||
joblineid
|
|
||||||
bill {
|
|
||||||
id
|
|
||||||
vendor {
|
|
||||||
id
|
|
||||||
name
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|||||||
@@ -521,6 +521,20 @@ export const GET_JOB_BY_PK = gql`
|
|||||||
tax_part
|
tax_part
|
||||||
db_ref
|
db_ref
|
||||||
manual_line
|
manual_line
|
||||||
|
billlines(limit: 1, order_by: { bill: { date: desc } }) {
|
||||||
|
id
|
||||||
|
quantity
|
||||||
|
actual_cost
|
||||||
|
actual_price
|
||||||
|
joblineid
|
||||||
|
bill {
|
||||||
|
id
|
||||||
|
vendor {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
parts_order_lines {
|
parts_order_lines {
|
||||||
id
|
id
|
||||||
parts_order {
|
parts_order {
|
||||||
|
|||||||
Reference in New Issue
Block a user