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 { useMutation, useQuery } from "@apollo/client";
|
||||
import { useMutation } from "@apollo/client";
|
||||
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 { connect } from "react-redux";
|
||||
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 { selectJobReadOnly } from "../../redux/application/application.selectors";
|
||||
import { setModalContext } from "../../redux/modals/modals.actions";
|
||||
@@ -48,26 +47,26 @@ export function JobLinesComponent({
|
||||
}) {
|
||||
const [deleteJobLine] = useMutation(DELETE_JOB_LINE_BY_PK);
|
||||
|
||||
const {
|
||||
loading: billLinesLoading,
|
||||
error: billLinesError,
|
||||
data: billLinesData,
|
||||
} = useQuery(QUERY_BILLS_BY_JOB_REF, {
|
||||
variables: { jobId: job && job.id },
|
||||
skip: loading || !job,
|
||||
});
|
||||
// const {
|
||||
// loading: billLinesLoading,
|
||||
// error: billLinesError,
|
||||
// data: billLinesData,
|
||||
// } = useQuery(QUERY_BILLS_BY_JOB_REF, {
|
||||
// variables: { jobId: job && job.id },
|
||||
// skip: loading || !job,
|
||||
// });
|
||||
|
||||
const billLinesDataObj = useMemo(() => {
|
||||
if (!billLinesData) return {};
|
||||
const ret = {};
|
||||
billLinesData.billlines.map((b) => {
|
||||
if (b.joblineid) {
|
||||
ret[b.joblineid] = { ...b, total: b.actual_price * b.quantity };
|
||||
}
|
||||
return null;
|
||||
});
|
||||
return ret;
|
||||
}, [billLinesData]);
|
||||
// const billLinesDataObj = useMemo(() => {
|
||||
// if (!billLinesData) return {};
|
||||
// const ret = {};
|
||||
// billLinesData.billlines.map((b) => {
|
||||
// if (b.joblineid) {
|
||||
// ret[b.joblineid] = { ...b, total: b.actual_price * b.quantity };
|
||||
// }
|
||||
// return null;
|
||||
// });
|
||||
// return ret;
|
||||
// }, [billLinesData]);
|
||||
|
||||
const [state, setState] = useState({
|
||||
sortedInfo: {},
|
||||
@@ -231,14 +230,7 @@ export function JobLinesComponent({
|
||||
title: t("joblines.labels.billref"),
|
||||
dataIndex: "billref",
|
||||
key: "billref",
|
||||
render: (text, record) => (
|
||||
<JobLinesBillRefernece
|
||||
jobline={record}
|
||||
loading={billLinesLoading}
|
||||
error={billLinesError}
|
||||
billLinesObject={billLinesDataObj}
|
||||
/>
|
||||
),
|
||||
render: (text, record) => <JobLinesBillRefernece jobline={record} />,
|
||||
},
|
||||
{
|
||||
title: t("joblines.fields.status"),
|
||||
|
||||
@@ -1,26 +1,10 @@
|
||||
import { Spin } from "antd";
|
||||
import React from "react";
|
||||
import AlertComponent from "../alert/alert.component";
|
||||
|
||||
export default function JobLinesBillRefernece({
|
||||
jobline,
|
||||
loading,
|
||||
error,
|
||||
billLinesObject,
|
||||
}) {
|
||||
if (loading)
|
||||
return (
|
||||
<div>
|
||||
<Spin size="small" className="loading-spinner" />
|
||||
</div>
|
||||
);
|
||||
if (!billLinesObject) return null;
|
||||
export default function JobLinesBillRefernece({ jobline }) {
|
||||
const billLine = jobline.billlines && jobline.billlines[0];
|
||||
|
||||
const billLine = billLinesObject[jobline.id];
|
||||
if (!billLine) return null;
|
||||
|
||||
if (error) return <AlertComponent message={error.message} type="error" />;
|
||||
|
||||
return (
|
||||
<div>{`${(billLine.actual_price * billLine.quantity).toFixed(2)} (${
|
||||
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
|
||||
db_ref
|
||||
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 {
|
||||
id
|
||||
parts_order {
|
||||
|
||||
Reference in New Issue
Block a user