IO-1817 Delete existing bill line.
This commit is contained in:
@@ -14,6 +14,7 @@ import React, { useEffect, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useLocation, useHistory } from "react-router-dom";
|
||||
import {
|
||||
DELETE_BILL_LINE,
|
||||
INSERT_NEW_BILL_LINES,
|
||||
UPDATE_BILL_LINE,
|
||||
} from "../../graphql/bill-lines.queries";
|
||||
@@ -58,6 +59,7 @@ export function BillDetailEditcontainer({
|
||||
const [update_bill] = useMutation(UPDATE_BILL);
|
||||
const [insertBillLine] = useMutation(INSERT_NEW_BILL_LINES);
|
||||
const [updateBillLine] = useMutation(UPDATE_BILL_LINE);
|
||||
const [deleteBillLine] = useMutation(DELETE_BILL_LINE);
|
||||
|
||||
const selectedBreakpoint = Object.entries(Grid.useBreakpoint())
|
||||
.filter((screen) => !!screen[1])
|
||||
@@ -107,6 +109,20 @@ export function BillDetailEditcontainer({
|
||||
})
|
||||
);
|
||||
|
||||
//Find bill lines that were deleted.
|
||||
const deletedJobLines = [];
|
||||
|
||||
data.bills_by_pk.billlines.forEach((a) => {
|
||||
const matchingRecord = billlines.find((b) => b.id === a.id);
|
||||
if (!matchingRecord) {
|
||||
deletedJobLines.push(a);
|
||||
}
|
||||
});
|
||||
|
||||
deletedJobLines.forEach((d) => {
|
||||
updates.push(deleteBillLine({ variables: { id: d.id } }));
|
||||
});
|
||||
|
||||
billlines.forEach((billline) => {
|
||||
const { deductedfromlbr, jobline, ...il } = billline;
|
||||
delete il.__typename;
|
||||
@@ -142,6 +158,7 @@ export function BillDetailEditcontainer({
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
await Promise.all(updates);
|
||||
|
||||
insertAuditTrail({
|
||||
@@ -160,6 +177,8 @@ export function BillDetailEditcontainer({
|
||||
useEffect(() => {
|
||||
if (search.billid && data) {
|
||||
form.resetFields();
|
||||
form.resetFields();
|
||||
form.setFieldsValue(transformData(data));
|
||||
}
|
||||
}, [form, search.billid, data]);
|
||||
|
||||
|
||||
@@ -81,11 +81,6 @@ export function JobLinesComponent({
|
||||
(c) => c.name === job.ins_co_nm
|
||||
)?.private;
|
||||
|
||||
console.log(
|
||||
"🚀 ~ file: job-lines.component.jsx ~ line 81 ~ jobIsPrivate",
|
||||
jobIsPrivate
|
||||
);
|
||||
|
||||
const columns = [
|
||||
{
|
||||
title: "#",
|
||||
|
||||
@@ -12,6 +12,13 @@ export const UPDATE_BILL_LINE = gql`
|
||||
}
|
||||
}
|
||||
`;
|
||||
export const DELETE_BILL_LINE = gql`
|
||||
mutation DELETE_BILL_LINE($id: uuid!) {
|
||||
delete_billlines_by_pk(id: $id) {
|
||||
id
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const INSERT_NEW_BILL_LINES = gql`
|
||||
mutation INSERT_NEW_BILL_LINES($billLines: [billlines_insert_input!]!) {
|
||||
|
||||
Reference in New Issue
Block a user