From 613ab4c540acb185599a6ff1029e40082cbc9f52 Mon Sep 17 00:00:00 2001 From: Patrick Fic <> Date: Fri, 19 Mar 2021 15:36:18 -0700 Subject: [PATCH] IO-789 Adjust main job query to pull bill data. --- .../job-detail-lines/job-lines.component.jsx | 52 ++++++++----------- .../job-lines-bill-reference.component.jsx | 20 +------ client/src/graphql/bill-lines.queries.js | 23 -------- client/src/graphql/jobs.queries.js | 14 +++++ 4 files changed, 38 insertions(+), 71 deletions(-) diff --git a/client/src/components/job-detail-lines/job-lines.component.jsx b/client/src/components/job-detail-lines/job-lines.component.jsx index 382f6da86..211ebb909 100644 --- a/client/src/components/job-detail-lines/job-lines.component.jsx +++ b/client/src/components/job-detail-lines/job-lines.component.jsx @@ -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) => ( - - ), + render: (text, record) => , }, { title: t("joblines.fields.status"), diff --git a/client/src/components/job-lines-bill-reference/job-lines-bill-reference.component.jsx b/client/src/components/job-lines-bill-reference/job-lines-bill-reference.component.jsx index fee230c89..02cfb7e73 100644 --- a/client/src/components/job-lines-bill-reference/job-lines-bill-reference.component.jsx +++ b/client/src/components/job-lines-bill-reference/job-lines-bill-reference.component.jsx @@ -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 ( -
- -
- ); - 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 ; - return (
{`${(billLine.actual_price * billLine.quantity).toFixed(2)} (${ billLine.bill.vendor.name diff --git a/client/src/graphql/bill-lines.queries.js b/client/src/graphql/bill-lines.queries.js index 86c4ac943..1b49812c7 100644 --- a/client/src/graphql/bill-lines.queries.js +++ b/client/src/graphql/bill-lines.queries.js @@ -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 - } - } - } - } -`; diff --git a/client/src/graphql/jobs.queries.js b/client/src/graphql/jobs.queries.js index a5ba0086d..f7b6b8730 100644 --- a/client/src/graphql/jobs.queries.js +++ b/client/src/graphql/jobs.queries.js @@ -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 {