From 4844c424252d62e2b2e3aac85a547d6ae040f95c Mon Sep 17 00:00:00 2001
From: Patrick Fic <>
Date: Wed, 8 Jun 2022 17:45:58 -0700
Subject: [PATCH] IO-1914 Add manual inventory and edit.
---
bodyshop_translations.babel | 194 ++++++++++++++++++
.../inventory-line-delete.component.jsx | 67 ++++++
.../inventory-list.component.jsx | 79 ++++++-
.../inventory-list.container.jsx | 17 +-
.../inventory-upsert-modal.component.jsx | 68 ++++++
.../inventory-upsert-modal.container.jsx | 126 ++++++++++++
.../components/rbac-wrapper/rbac-defaults.js | 1 +
.../shop-info/shop-info.rbac.component.jsx | 63 ++++--
client/src/graphql/inventory.queries.js | 66 ++++++
client/src/pages/inventory/inventory.page.jsx | 2 +
client/src/redux/modals/modals.reducer.js | 1 +
client/src/redux/modals/modals.selectors.js | 4 +
client/src/translations/en_us/common.json | 15 +-
client/src/translations/es/common.json | 15 +-
client/src/translations/fr/common.json | 15 +-
hasura/metadata/tables.yaml | 21 ++
.../down.sql | 4 +
.../up.sql | 2 +
.../down.sql | 4 +
.../up.sql | 2 +
.../down.sql | 4 +
.../up.sql | 2 +
.../down.sql | 1 +
.../up.sql | 1 +
24 files changed, 738 insertions(+), 36 deletions(-)
create mode 100644 client/src/components/inventory-line-delete/inventory-line-delete.component.jsx
create mode 100644 client/src/components/inventory-upsert-modal/inventory-upsert-modal.component.jsx
create mode 100644 client/src/components/inventory-upsert-modal/inventory-upsert-modal.container.jsx
create mode 100644 hasura/migrations/1654731244827_alter_table_public_inventory_add_column_manualinvoicenumber/down.sql
create mode 100644 hasura/migrations/1654731244827_alter_table_public_inventory_add_column_manualinvoicenumber/up.sql
create mode 100644 hasura/migrations/1654731253232_alter_table_public_inventory_add_column_comment/down.sql
create mode 100644 hasura/migrations/1654731253232_alter_table_public_inventory_add_column_comment/up.sql
create mode 100644 hasura/migrations/1654731265455_alter_table_public_inventory_add_column_manualvendor/down.sql
create mode 100644 hasura/migrations/1654731265455_alter_table_public_inventory_add_column_manualvendor/up.sql
create mode 100644 hasura/migrations/1654733904736_alter_table_public_inventory_alter_column_quantity/down.sql
create mode 100644 hasura/migrations/1654733904736_alter_table_public_inventory_alter_column_quantity/up.sql
diff --git a/bodyshop_translations.babel b/bodyshop_translations.babel
index 2bf1b9018..d6fc28db9 100644
--- a/bodyshop_translations.babel
+++ b/bodyshop_translations.babel
@@ -5736,6 +5736,27 @@
inventory
+
+ delete
+ false
+
+
+
+
+
+ en-US
+ false
+
+
+ es-MX
+ false
+
+
+ fr-CA
+ false
+
+
+
list
false
@@ -17371,6 +17392,48 @@
+
+ edit
+ false
+
+
+
+
+
+ en-US
+ false
+
+
+ es-MX
+ false
+
+
+ fr-CA
+ false
+
+
+
+
+ new
+ false
+
+
+
+
+
+ en-US
+ false
+
+
+ es-MX
+ false
+
+
+ fr-CA
+ false
+
+
+
@@ -17399,6 +17462,74 @@
+
+ fields
+
+
+ comment
+ false
+
+
+
+
+
+ en-US
+ false
+
+
+ es-MX
+ false
+
+
+ fr-CA
+ false
+
+
+
+
+ manualinvoicenumber
+ false
+
+
+
+
+
+ en-US
+ false
+
+
+ es-MX
+ false
+
+
+ fr-CA
+ false
+
+
+
+
+ manualvendor
+ false
+
+
+
+
+
+ en-US
+ false
+
+
+ es-MX
+ false
+
+
+ fr-CA
+ false
+
+
+
+
+
labels
@@ -17423,6 +17554,27 @@
+
+ deleteconfirm
+ false
+
+
+
+
+
+ en-US
+ false
+
+
+ es-MX
+ false
+
+
+ fr-CA
+ false
+
+
+
frombillinvoicenumber
false
@@ -17533,6 +17685,27 @@
successes
+
+ deleted
+ false
+
+
+
+
+
+ en-US
+ false
+
+
+ es-MX
+ false
+
+
+ fr-CA
+ false
+
+
+
inserted
false
@@ -17554,6 +17727,27 @@
+
+ updated
+ false
+
+
+
+
+
+ en-US
+ false
+
+
+ es-MX
+ false
+
+
+ fr-CA
+ false
+
+
+
diff --git a/client/src/components/inventory-line-delete/inventory-line-delete.component.jsx b/client/src/components/inventory-line-delete/inventory-line-delete.component.jsx
new file mode 100644
index 000000000..d31be9384
--- /dev/null
+++ b/client/src/components/inventory-line-delete/inventory-line-delete.component.jsx
@@ -0,0 +1,67 @@
+import { DeleteFilled } from "@ant-design/icons";
+import { useMutation } from "@apollo/client";
+import { Button, notification, Popconfirm } from "antd";
+import React, { useState } from "react";
+import { useTranslation } from "react-i18next";
+import { DELETE_INVENTORY_LINE } from "../../graphql/inventory.queries";
+import RbacWrapper from "../rbac-wrapper/rbac-wrapper.component";
+
+export default function InventoryLineDelete({
+ inventoryline,
+ disabled,
+ refetch,
+}) {
+ const [loading, setLoading] = useState(false);
+ const { t } = useTranslation();
+ const [deleteInventoryLine] = useMutation(DELETE_INVENTORY_LINE);
+
+ const handleDelete = async () => {
+ setLoading(true);
+ const result = await deleteInventoryLine({
+ variables: { lineId: inventoryline.id },
+ // update(cache, { errors }) {
+ // cache.modify({
+ // fields: {
+ // inventory(existingInventory, { readField }) {
+ // console.log(existingInventory);
+ // return existingInventory.filter(
+ // (invRef) => inventoryline.id !== readField("id", invRef)
+ // );
+ // },
+ // },
+ // });
+ // },
+ });
+
+ if (!!!result.errors) {
+ notification["success"]({ message: t("inventory.successes.deleted") });
+ } else {
+ //Check if it's an fkey violation.
+
+ notification["error"]({
+ message: t("bills.errors.deleting", {
+ error: JSON.stringify(result.errors),
+ }),
+ });
+ }
+ if (refetch) refetch();
+ setLoading(false);
+ };
+
+ return (
+ >}>
+
+
+
+
+ );
+}
diff --git a/client/src/components/inventory-list/inventory-list.component.jsx b/client/src/components/inventory-list/inventory-list.component.jsx
index 95dcdea13..9baa66de0 100644
--- a/client/src/components/inventory-list/inventory-list.component.jsx
+++ b/client/src/components/inventory-list/inventory-list.component.jsx
@@ -1,4 +1,4 @@
-import { SyncOutlined } from "@ant-design/icons";
+import { EditFilled, SyncOutlined, FileAddFilled } from "@ant-design/icons";
import { Button, Card, Input, Space, Table, Typography } from "antd";
import queryString from "query-string";
import React from "react";
@@ -6,18 +6,28 @@ import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
import { Link, useHistory, useLocation } from "react-router-dom";
import { createStructuredSelector } from "reselect";
+import { setModalContext } from "../../redux/modals/modals.actions";
import { selectBodyshop } from "../../redux/user/user.selectors";
import CurrencyFormatter from "../../utils/CurrencyFormatter";
import InventoryBillRo from "../inventory-bill-ro/inventory-bill-ro.component";
+import InventoryLineDelete from "../inventory-line-delete/inventory-line-delete.component";
const mapStateToProps = createStructuredSelector({
//currentUser: selectCurrentUser
bodyshop: selectBodyshop,
});
const mapDispatchToProps = (dispatch) => ({
- //setUserLanguage: language => dispatch(setUserLanguage(language))
+ setInventoryUpsertContext: (context) =>
+ dispatch(setModalContext({ context: context, modal: "inventoryUpsert" })),
});
-export function JobsList({ bodyshop, refetch, loading, jobs, total }) {
+export function JobsList({
+ bodyshop,
+ refetch,
+ loading,
+ jobs,
+ total,
+ setInventoryUpsertContext,
+}) {
const search = queryString.parse(useLocation().search);
const { page, sortcolumn, sortorder } = search;
const history = useHistory();
@@ -31,6 +41,15 @@ export function JobsList({ bodyshop, refetch, loading, jobs, total }) {
sorter: true, //(a, b) => alphaSort(a.line_desc, b.line_desc),
sortOrder: sortcolumn === "line_desc" && sortorder,
+ render: (text, record) =>
+ record.billline?.bill?.job ? (
+
+
{text}
+
{`(${record.billline?.bill?.job?.v_model_yr} ${record.billline?.bill?.job?.v_make_desc} ${record.billline?.bill?.job?.v_model_desc})`}
+
+ ) : (
+ text
+ ),
},
{
title: t("inventory.labels.frombillinvoicenumber"),
@@ -40,7 +59,12 @@ export function JobsList({ bodyshop, refetch, loading, jobs, total }) {
//sorter: true, // (a, b) => alphaSort(a.ownr_ln, b.ownr_ln),
//sortOrder: sortcolumn === "ownr_ln" && sortorder,
- render: (text, record) => record.billline?.bill?.invoice_number,
+ render: (text, record) =>
+ (
+ (record.billline?.bill?.invoice_number || "") +
+ " " +
+ (record.manualinvoicenumber || "")
+ ).trim(),
},
{
title: t("inventory.labels.fromvendor"),
@@ -50,7 +74,12 @@ export function JobsList({ bodyshop, refetch, loading, jobs, total }) {
//sorter: true, // (a, b) => alphaSort(a.ownr_ln, b.ownr_ln),
//sortOrder: sortcolumn === "ownr_ln" && sortorder,
- render: (text, record) => record.billline?.bill?.vendor?.name,
+ render: (text, record) =>
+ (
+ (record.billline?.bill?.vendor?.name || "") +
+ " " +
+ (record.manualvendor || "")
+ ).trim(),
},
{
title: t("billlines.fields.actual_price"),
@@ -70,6 +99,11 @@ export function JobsList({ bodyshop, refetch, loading, jobs, total }) {
{record.actual_cost}
),
},
+ {
+ title: t("inventory.fields.comment"),
+ dataIndex: "comment",
+ key: "comment",
+ },
{
title: t("inventory.labels.consumedbyjob"),
dataIndex: "consumedbyjob",
@@ -85,6 +119,30 @@ export function JobsList({ bodyshop, refetch, loading, jobs, total }) {
),
},
+ {
+ title: t("general.labels.actions"),
+ dataIndex: "actions",
+ key: "actions",
+
+ ellipsis: true,
+ render: (text, record) => (
+
+
+
+
+ ),
+ },
];
const handleTableChange = (pagination, filters, sorter) => {
@@ -113,7 +171,16 @@ export function JobsList({ bodyshop, refetch, loading, jobs, total }) {
>
)}
-
+