From 908c17aa6870c4bbc747e66c10b508b5e3ebe486 Mon Sep 17 00:00:00 2001 From: Patrick Fic <> Date: Mon, 30 May 2022 17:39:43 -0700 Subject: [PATCH] IO-1914 Schema for inventory and basic adding to inventory. --- bodyshop_translations.babel | 130 +++++++++++++++ .../bill-detail-edit.container.jsx | 4 +- .../bill-enter-modal.container.jsx | 31 +++- .../bill-form/bill-form.component.jsx | 12 +- .../bill-form/bill-form.container.jsx | 20 +++ .../bill-form/bill-form.lines.component.jsx | 21 ++- .../bill-form/bill-form.totals.utility.js | 1 + .../bill-inventory-table.component.jsx | 153 ++++++++++++++++++ .../bill-inventory-table.styles.scss | 19 +++ .../billline-add-inventory.component.jsx | 103 ++++++++++++ client/src/graphql/inventory.queries.js | 49 ++++++ 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 | 119 ++++++++++++++ .../down.sql | 1 + .../up.sql | 18 +++ .../down.sql | 1 + .../up.sql | 5 + .../down.sql | 1 + .../up.sql | 5 + .../down.sql | 1 + .../up.sql | 1 + .../down.sql | 4 + .../up.sql | 2 + .../down.sql | 1 + .../up.sql | 5 + .../down.sql | 5 + .../up.sql | 5 + .../down.sql | 5 + .../up.sql | 5 + .../down.sql | 1 + .../up.sql | 2 + .../down.sql | 1 + .../up.sql | 2 + 35 files changed, 769 insertions(+), 9 deletions(-) create mode 100644 client/src/components/bill-inventory-table/bill-inventory-table.component.jsx create mode 100644 client/src/components/bill-inventory-table/bill-inventory-table.styles.scss create mode 100644 client/src/components/billline-add-inventory/billline-add-inventory.component.jsx create mode 100644 client/src/graphql/inventory.queries.js create mode 100644 hasura/migrations/1653933012524_create_table_public_inventory/down.sql create mode 100644 hasura/migrations/1653933012524_create_table_public_inventory/up.sql create mode 100644 hasura/migrations/1653933089451_set_fk_public_inventory_billid/down.sql create mode 100644 hasura/migrations/1653933089451_set_fk_public_inventory_billid/up.sql create mode 100644 hasura/migrations/1653933105635_set_fk_public_inventory_shopid/down.sql create mode 100644 hasura/migrations/1653933105635_set_fk_public_inventory_shopid/up.sql create mode 100644 hasura/migrations/1653935727610_alter_table_public_inventory_alter_column_billid/down.sql create mode 100644 hasura/migrations/1653935727610_alter_table_public_inventory_alter_column_billid/up.sql create mode 100644 hasura/migrations/1653953166273_alter_table_public_inventory_add_column_consumedbybillid/down.sql create mode 100644 hasura/migrations/1653953166273_alter_table_public_inventory_add_column_consumedbybillid/up.sql create mode 100644 hasura/migrations/1653953259127_set_fk_public_inventory_consumedbybillid/down.sql create mode 100644 hasura/migrations/1653953259127_set_fk_public_inventory_consumedbybillid/up.sql create mode 100644 hasura/migrations/1653953283374_set_fk_public_inventory_consumedbybillid/down.sql create mode 100644 hasura/migrations/1653953283374_set_fk_public_inventory_consumedbybillid/up.sql create mode 100644 hasura/migrations/1653953288756_set_fk_public_inventory_consumedbybillid/down.sql create mode 100644 hasura/migrations/1653953288756_set_fk_public_inventory_consumedbybillid/up.sql create mode 100644 hasura/migrations/1653953385835_create_index_inventory_consumedbybillid/down.sql create mode 100644 hasura/migrations/1653953385835_create_index_inventory_consumedbybillid/up.sql create mode 100644 hasura/migrations/1653953399350_create_index_inventory_shopididx/down.sql create mode 100644 hasura/migrations/1653953399350_create_index_inventory_shopididx/up.sql diff --git a/bodyshop_translations.babel b/bodyshop_translations.babel index 5f5bb62e5..ec94be6a6 100644 --- a/bodyshop_translations.babel +++ b/bodyshop_translations.babel @@ -17213,6 +17213,136 @@ + + inventory + + + actions + + + addtoinventory + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + + + consumefrominventory + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + + + + + errors + + + inserting + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + + + + + labels + + + inventory + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + + + + + successes + + + inserted + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + + + + + joblines diff --git a/client/src/components/bill-detail-edit/bill-detail-edit.container.jsx b/client/src/components/bill-detail-edit/bill-detail-edit.container.jsx index 9bbca0a60..f2f03e90d 100644 --- a/client/src/components/bill-detail-edit/bill-detail-edit.container.jsx +++ b/client/src/components/bill-detail-edit/bill-detail-edit.container.jsx @@ -73,8 +73,8 @@ export function BillDetailEditcontainer({ sm: "100%", md: "100%", lg: "100%", - xl: "80%", - xxl: "80%", + xl: "90%", + xxl: "90%", }; const drawerPercentage = selectedBreakpoint ? bpoints[selectedBreakpoint[0]] diff --git a/client/src/components/bill-enter-modal/bill-enter-modal.container.jsx b/client/src/components/bill-enter-modal/bill-enter-modal.container.jsx index bfadbcd37..82948fe88 100644 --- a/client/src/components/bill-enter-modal/bill-enter-modal.container.jsx +++ b/client/src/components/bill-enter-modal/bill-enter-modal.container.jsx @@ -12,6 +12,7 @@ import { UPDATE_JOB, } from "../../graphql/jobs.queries"; import { MUTATION_MARK_RETURN_RECEIVED } from "../../graphql/parts-orders.queries"; +import { UPDATE_INVENTORY_LINES } from "../../graphql/inventory.queries"; import { insertAuditTrail } from "../../redux/application/application.actions"; import { toggleModalVisible } from "../../redux/modals/modals.actions"; import { selectBillEnterModal } from "../../redux/modals/modals.selectors"; @@ -50,6 +51,7 @@ function BillEnterModalContainer({ const [insertBill] = useMutation(INSERT_NEW_BILL); const [updateJobLines] = useMutation(UPDATE_JOB_LINE); const [updatePartsOrderLines] = useMutation(MUTATION_MARK_RETURN_RECEIVED); + const [updateInventoryLines] = useMutation(UPDATE_INVENTORY_LINES); const [loading, setLoading] = useState(false); const client = useApolloClient(); @@ -79,8 +81,13 @@ function BillEnterModalContainer({ } setLoading(true); - const { upload, location, outstanding_returns, ...remainingValues } = - values; + const { + upload, + location, + outstanding_returns, + inventory, + ...remainingValues + } = values; let adjustmentsToInsert = {}; @@ -190,6 +197,26 @@ function BillEnterModalContainer({ } const billId = r1.data.insert_bills.returning[0].id; + const markInventoryConsumed = + inventory && inventory.filter((i) => i.consumefrominventory); + + if (markInventoryConsumed && markInventoryConsumed.length > 0) { + const r2 = await updateInventoryLines({ + variables: { + InventoryIds: markInventoryConsumed.map((p) => p.id), + consumedbybillid: billId, + }, + }); + if (!!r2.errors) { + setLoading(false); + setEnterAgain(false); + notification["error"]({ + message: t("inventory.errors.updating", { + message: JSON.stringify(r2.errors), + }), + }); + } + } await Promise.all( remainingValues.billlines diff --git a/client/src/components/bill-form/bill-form.component.jsx b/client/src/components/bill-form/bill-form.component.jsx index f57c56819..7d7eb793a 100644 --- a/client/src/components/bill-form/bill-form.component.jsx +++ b/client/src/components/bill-form/bill-form.component.jsx @@ -48,6 +48,7 @@ export function BillFormComponent({ disableInvNumber, job, loadOutstandingReturns, + loadInventory, }) { const { t } = useTranslation(); const client = useApolloClient(); @@ -61,6 +62,7 @@ export function BillFormComponent({ setDiscount(opt.discount); opt && + !billEdit && loadOutstandingReturns({ variables: { jobId: form.getFieldValue("jobid"), @@ -86,7 +88,7 @@ export function BillFormComponent({ const jobId = form.getFieldValue("jobid"); if (jobId) { loadLines({ variables: { id: jobId } }); - if (form.getFieldValue("is_credit_memo") && vendorId) { + if (form.getFieldValue("is_credit_memo") && vendorId && !billEdit) { loadOutstandingReturns({ variables: { jobId: jobId, @@ -95,12 +97,19 @@ export function BillFormComponent({ }); } } + + if (vendorId === bodyshop.inhousevendorid) { + loadInventory(); + } }, [ form, + billEdit, loadOutstandingReturns, + loadInventory, setDiscount, vendorAutoCompleteOptions, loadLines, + bodyshop.inhousevendorid, ]); return ( @@ -425,6 +434,7 @@ export function BillFormComponent({ form={form} responsibilityCenters={responsibilityCenters} disabled={disabled} + billEdit={billEdit} /> )} diff --git a/client/src/components/bill-form/bill-form.container.jsx b/client/src/components/bill-form/bill-form.container.jsx index 4fe056667..836a24be4 100644 --- a/client/src/components/bill-form/bill-form.container.jsx +++ b/client/src/components/bill-form/bill-form.container.jsx @@ -8,6 +8,9 @@ import { selectBodyshop } from "../../redux/user/user.selectors"; import BillFormComponent from "./bill-form.component"; import BillCmdReturnsTableComponent from "../bill-cm-returns-table/bill-cm-returns-table.component"; import { QUERY_UNRECEIVED_LINES } from "../../graphql/parts-orders.queries"; +import BillInventoryTable from "../bill-inventory-table/bill-inventory-table.component"; +import { QUERY_OUTSTANDING_INVENTORY } from "../../graphql/inventory.queries"; +import { useTreatments } from "@splitsoftware/splitio-react"; const mapStateToProps = createStructuredSelector({ bodyshop: selectBodyshop, @@ -20,6 +23,12 @@ export function BillFormContainer({ disabled, disableInvNumber, }) { + const { Simple_Inventory } = useTreatments( + ["Simple_Inventory"], + {}, + bodyshop && bodyshop.imexshopid + ); + const { data: VendorAutoCompleteData } = useQuery( SEARCH_VENDOR_AUTOCOMPLETE, { fetchPolicy: "network-only", nextFetchPolicy: "network-only" } @@ -31,6 +40,8 @@ export function BillFormContainer({ const [loadOutstandingReturns, { loading: returnLoading, data: returnData }] = useLazyQuery(QUERY_UNRECEIVED_LINES); + const [loadInventory, { loading: inventoryLoading, data: inventoryData }] = + useLazyQuery(QUERY_OUTSTANDING_INVENTORY); return ( <> @@ -47,6 +58,7 @@ export function BillFormContainer({ responsibilityCenters={bodyshop.md_responsibility_centers || null} disableInvNumber={disableInvNumber} loadOutstandingReturns={loadOutstandingReturns} + loadInventory={loadInventory} /> {!billEdit && ( )} + {!billEdit && Simple_Inventory.treatment === "on" && ( + + )} ); } diff --git a/client/src/components/bill-form/bill-form.lines.component.jsx b/client/src/components/bill-form/bill-form.lines.component.jsx index b8a1b5c9d..b3d6209c5 100644 --- a/client/src/components/bill-form/bill-form.lines.component.jsx +++ b/client/src/components/bill-form/bill-form.lines.component.jsx @@ -8,7 +8,7 @@ import { Space, Switch, Table, - Tooltip + Tooltip, } from "antd"; import React from "react"; import { useTranslation } from "react-i18next"; @@ -18,6 +18,7 @@ import { selectBodyshop } from "../../redux/user/user.selectors"; import CiecaSelect from "../../utils/Ciecaselect"; import BillLineSearchSelect from "../bill-line-search-select/bill-line-search-select.component"; import CurrencyInput from "../form-items-formatted/currency-form-item.component"; +import BilllineAddInventory from "../billline-add-inventory/billline-add-inventory.component"; const mapStateToProps = createStructuredSelector({ //currentUser: selectCurrentUser @@ -34,6 +35,7 @@ export function BillEnterModalLinesComponent({ discount, form, responsibilityCenters, + billEdit, }) { const { t } = useTranslation(); const { setFieldsValue, getFieldsValue, getFieldValue } = form; @@ -477,9 +479,20 @@ export function BillEnterModalLinesComponent({ dataIndex: "actions", render: (text, record) => ( - + + + + {() => ( + + )} + + ), }, ]; diff --git a/client/src/components/bill-form/bill-form.totals.utility.js b/client/src/components/bill-form/bill-form.totals.utility.js index df84ec86e..05396e66c 100644 --- a/client/src/components/bill-form/bill-form.totals.utility.js +++ b/client/src/components/bill-form/bill-form.totals.utility.js @@ -18,6 +18,7 @@ export const CalculateBillTotal = (invoice) => { amount: Math.round((i.actual_cost || 0) * 100), }).multiply(i.quantity || 1); + console.log(i, itemTotal.toFormat); subtotal = subtotal.add(itemTotal); if (i.applicable_taxes.federal) { federalTax = federalTax.add( diff --git a/client/src/components/bill-inventory-table/bill-inventory-table.component.jsx b/client/src/components/bill-inventory-table/bill-inventory-table.component.jsx new file mode 100644 index 000000000..d8fb121d0 --- /dev/null +++ b/client/src/components/bill-inventory-table/bill-inventory-table.component.jsx @@ -0,0 +1,153 @@ +import { Checkbox, Form, Skeleton, Typography } from "antd"; +import React, { useEffect } from "react"; +import { useTranslation } from "react-i18next"; +import ReadOnlyFormItemComponent from "../form-items-formatted/read-only-form-item.component"; +import "./bill-inventory-table.styles.scss"; + +import { connect } from "react-redux"; +import { createStructuredSelector } from "reselect"; +import { selectBodyshop } from "../../redux/user/user.selectors"; + +const mapStateToProps = createStructuredSelector({ + bodyshop: selectBodyshop, +}); +const mapDispatchToProps = (dispatch) => ({ + //setUserLanguage: language => dispatch(setUserLanguage(language)) +}); +export default connect(mapStateToProps, mapDispatchToProps)(BillInventoryTable); + +export function BillInventoryTable({ + bodyshop, + form, + billEdit, + inventoryLoading, + inventoryData, +}) { + const { t } = useTranslation(); + + useEffect(() => { + if (inventoryData) { + form.setFieldsValue({ + inventory: inventoryData.inventory, + }); + } + }, [inventoryData, form]); + + return ( + prev.vendorid !== cur.vendorid} + noStyle + > + {() => { + const is_inhouse = + form.getFieldValue("vendorid") === bodyshop.inhousevendorid; + + if (!is_inhouse || billEdit) { + return null; + } + + if (inventoryLoading) return ; + + return ( + + {(fields, { add, remove, move }) => { + return ( + <> + + {t("inventory.labels.inventory")} + + + + + + + + + + + + + + {fields.map((field, index) => ( + + + + + + + + + + + ))} + +
{t("billlines.fields.line_desc")}{t("vendors.fields.name")}{t("billlines.fields.quantity")}{t("billlines.fields.actual_price")}{t("billlines.fields.actual_cost")}{t("inventory.actions.consumefrominventory")}
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + ); + }} +
+ ); + }} +
+ ); +} diff --git a/client/src/components/bill-inventory-table/bill-inventory-table.styles.scss b/client/src/components/bill-inventory-table/bill-inventory-table.styles.scss new file mode 100644 index 000000000..67bc0543b --- /dev/null +++ b/client/src/components/bill-inventory-table/bill-inventory-table.styles.scss @@ -0,0 +1,19 @@ +.bill-inventory-table { + table-layout: fixed; + width: 100%; + + th, + td { + padding: 8px; + text-align: left; + border-bottom: 1px solid #ddd; + + .ant-form-item { + margin-bottom: 0px !important; + } + } + + tr:hover { + background-color: #f5f5f5; + } +} \ No newline at end of file diff --git a/client/src/components/billline-add-inventory/billline-add-inventory.component.jsx b/client/src/components/billline-add-inventory/billline-add-inventory.component.jsx new file mode 100644 index 000000000..c6e9f63f4 --- /dev/null +++ b/client/src/components/billline-add-inventory/billline-add-inventory.component.jsx @@ -0,0 +1,103 @@ +import { FileAddFilled } from "@ant-design/icons"; +import { useApolloClient, useMutation } from "@apollo/client"; +import { Button, notification, Tooltip } from "antd"; +import { json } from "body-parser"; +import { t } from "i18next"; +import moment from "moment"; +import React, { useState } from "react"; +import { connect } from "react-redux"; +import { createStructuredSelector } from "reselect"; +import { INSERT_INVENTORY_AND_CREDIT } from "../../graphql/inventory.queries"; +import { selectBodyshop } from "../../redux/user/user.selectors"; +import { CalculateBillTotal } from "../bill-form/bill-form.totals.utility"; + +const mapStateToProps = createStructuredSelector({ + bodyshop: selectBodyshop, +}); +const mapDispatchToProps = (dispatch) => ({ + //setUserLanguage: language => dispatch(setUserLanguage(language)) +}); +export default connect( + mapStateToProps, + mapDispatchToProps +)(BilllineAddInventory); + +export function BilllineAddInventory({ bodyshop, billline, disabled, jobid }) { + const [loading, setLoading] = useState(false); + + const [insertInventoryLine] = useMutation(INSERT_INVENTORY_AND_CREDIT); + + const addToInventory = async () => { + setLoading(true); + + //Check to make sure there are no existing items already in the inventory. + + const cm = { + vendorid: bodyshop.inhousevendorid, + invoice_number: "ih", + jobid: jobid, + isinhouse: true, + is_credit_memo: true, + date: moment().format("YYYY-MM-DD"), + federal_tax_rate: bodyshop.bill_tax_rates.federal_tax_rate, + state_tax_rate: bodyshop.bill_tax_rates.state_tax_rate, + local_tax_rate: bodyshop.bill_tax_rates.local_tax_rate, + total: 0, + billlines: [ + { + actual_price: billline.actual_price, + actual_cost: billline.actual_cost, + quantity: billline.quantity, + line_desc: billline.line_desc, + cost_center: billline.cost_center, + deductedfromlbr: billline.deductedfromlbr, + applicable_taxes: { + local: billline.applicable_taxes.local, + state: billline.applicable_taxes.state, + federal: billline.applicable_taxes.federal, + }, + }, + ], + }; + + cm.total = CalculateBillTotal(cm).enteredTotal.getAmount() / 100; + + const insertResult = await insertInventoryLine({ + variables: { + inv: { + shopid: bodyshop.id, + billlineid: billline.id, + actual_price: billline.actual_price, + actual_cost: billline.actual_cost, + quantity: billline.quantity, + line_desc: billline.line_desc, + }, + cm: { ...cm, billlines: { data: cm.billlines } }, //Fix structure for apollo insert. + }, + }); + + if (!insertResult.errors) { + notification.open({ + type: "success", + message: t("inventory.successes.inserted"), + }); + } else { + notification.open({ + type: "error", + message: t("inventory.errors.inserting", { + error: JSON.stringify(insertResult.errors), + }), + }); + } + + setLoading(false); + }; + + return ( + + + + ); +} diff --git a/client/src/graphql/inventory.queries.js b/client/src/graphql/inventory.queries.js new file mode 100644 index 000000000..8c5bb7a4b --- /dev/null +++ b/client/src/graphql/inventory.queries.js @@ -0,0 +1,49 @@ +import { gql } from "@apollo/client"; + +export const INSERT_INVENTORY_AND_CREDIT = gql` + mutation INSERT_INVENTORY_AND_CREDIT( + $inv: inventory_insert_input! + $cm: bills_insert_input! + ) { + insert_inventory_one(object: $inv) { + id + } + insert_bills_one(object: $cm) { + id + } + } +`; +export const UPDATE_INVENTORY_LINES = gql` + mutation UPDATE_INVENTORY_LINES( + $InventoryIds: [uuid!]! + $consumedbybillid: uuid! + ) { + update_inventory( + where: { id: { _in: $InventoryIds } } + _set: { consumedbybillid: $consumedbybillid } + ) { + affected_rows + } + } +`; + +export const QUERY_OUTSTANDING_INVENTORY = gql` + query QUERY_OUTSTANDING_INVENTORY { + inventory(where: { consumedbybillid: { _is_null: true } }) { + id + actual_cost + actual_price + quantity + billlineid + line_desc + billline { + bill { + invoice_number + vendor { + name + } + } + } + } + } +`; diff --git a/client/src/translations/en_us/common.json b/client/src/translations/en_us/common.json index c684228ce..e34a885b6 100644 --- a/client/src/translations/en_us/common.json +++ b/client/src/translations/en_us/common.json @@ -1069,6 +1069,21 @@ "printpack": "Intake Print Pack" } }, + "inventory": { + "actions": { + "addtoinventory": "Add to Inventory", + "consumefrominventory": "Consume from Inventory?" + }, + "errors": { + "inserting": "Error inserting inventory item. {{error}}" + }, + "labels": { + "inventory": "Inventory" + }, + "successes": { + "inserted": "Added line to inventory." + } + }, "joblines": { "actions": { "new": "New Line" diff --git a/client/src/translations/es/common.json b/client/src/translations/es/common.json index af04f5bb1..c7bc888ca 100644 --- a/client/src/translations/es/common.json +++ b/client/src/translations/es/common.json @@ -1069,6 +1069,21 @@ "printpack": "" } }, + "inventory": { + "actions": { + "addtoinventory": "", + "consumefrominventory": "" + }, + "errors": { + "inserting": "" + }, + "labels": { + "inventory": "" + }, + "successes": { + "inserted": "" + } + }, "joblines": { "actions": { "new": "" diff --git a/client/src/translations/fr/common.json b/client/src/translations/fr/common.json index fbd28bd87..bc00188b9 100644 --- a/client/src/translations/fr/common.json +++ b/client/src/translations/fr/common.json @@ -1069,6 +1069,21 @@ "printpack": "" } }, + "inventory": { + "actions": { + "addtoinventory": "", + "consumefrominventory": "" + }, + "errors": { + "inserting": "" + }, + "labels": { + "inventory": "" + }, + "successes": { + "inserted": "" + } + }, "joblines": { "actions": { "new": "" diff --git a/hasura/metadata/tables.yaml b/hasura/metadata/tables.yaml index 18224906e..b2d9e60d1 100644 --- a/hasura/metadata/tables.yaml +++ b/hasura/metadata/tables.yaml @@ -402,6 +402,14 @@ - name: jobline using: foreign_key_constraint_on: joblineid + array_relationships: + - name: inventories + using: + foreign_key_constraint_on: + column: billlineid + table: + schema: public + name: inventory insert_permissions: - role: user permission: @@ -541,6 +549,13 @@ table: schema: public name: exportlog + - name: inventories + using: + foreign_key_constraint_on: + column: consumedbybillid + table: + schema: public + name: inventory - name: parts_orders using: foreign_key_constraint_on: @@ -751,6 +766,13 @@ table: schema: public name: exportlog + - name: inventories + using: + foreign_key_constraint_on: + column: shopid + table: + schema: public + name: inventory - name: jobs using: foreign_key_constraint_on: @@ -2112,6 +2134,96 @@ - active: _eq: true allow_aggregations: true +- table: + schema: public + name: inventory + object_relationships: + - name: bill + using: + foreign_key_constraint_on: consumedbybillid + - name: billline + using: + foreign_key_constraint_on: billlineid + - name: bodyshop + using: + foreign_key_constraint_on: shopid + - name: jobline + using: + foreign_key_constraint_on: joblineid + insert_permissions: + - role: user + permission: + check: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + columns: + - actual_cost + - actual_price + - billlineid + - consumedbybillid + - created_at + - id + - joblineid + - line_desc + - quantity + - shopid + - updated_at + backend_only: false + select_permissions: + - role: user + permission: + columns: + - actual_cost + - actual_price + - billlineid + - consumedbybillid + - created_at + - id + - joblineid + - line_desc + - quantity + - shopid + - updated_at + filter: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + update_permissions: + - role: user + permission: + columns: + - actual_cost + - actual_price + - billlineid + - consumedbybillid + - created_at + - id + - joblineid + - line_desc + - quantity + - shopid + - updated_at + filter: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + check: null - table: schema: public name: ioevents @@ -2211,6 +2323,13 @@ table: schema: public name: billlines + - name: inventories + using: + foreign_key_constraint_on: + column: joblineid + table: + schema: public + name: inventory - name: parts_order_lines using: foreign_key_constraint_on: diff --git a/hasura/migrations/1653933012524_create_table_public_inventory/down.sql b/hasura/migrations/1653933012524_create_table_public_inventory/down.sql new file mode 100644 index 000000000..8fac4e21a --- /dev/null +++ b/hasura/migrations/1653933012524_create_table_public_inventory/down.sql @@ -0,0 +1 @@ +DROP TABLE "public"."inventory"; diff --git a/hasura/migrations/1653933012524_create_table_public_inventory/up.sql b/hasura/migrations/1653933012524_create_table_public_inventory/up.sql new file mode 100644 index 000000000..32e80acb1 --- /dev/null +++ b/hasura/migrations/1653933012524_create_table_public_inventory/up.sql @@ -0,0 +1,18 @@ +CREATE TABLE "public"."inventory" ("id" uuid NOT NULL DEFAULT gen_random_uuid(), "created_at" timestamptz NOT NULL DEFAULT now(), "updated_at" timestamptz NOT NULL DEFAULT now(), "shopid" uuid NOT NULL, "billid" uuid, "joblineid" uuid, "line_desc" text NOT NULL, "actual_price" numeric NOT NULL, "actual_cost" numeric NOT NULL, "quantity" numeric NOT NULL, PRIMARY KEY ("id") , FOREIGN KEY ("joblineid") REFERENCES "public"."joblines"("id") ON UPDATE restrict ON DELETE restrict); +CREATE OR REPLACE FUNCTION "public"."set_current_timestamp_updated_at"() +RETURNS TRIGGER AS $$ +DECLARE + _new record; +BEGIN + _new := NEW; + _new."updated_at" = NOW(); + RETURN _new; +END; +$$ LANGUAGE plpgsql; +CREATE TRIGGER "set_public_inventory_updated_at" +BEFORE UPDATE ON "public"."inventory" +FOR EACH ROW +EXECUTE PROCEDURE "public"."set_current_timestamp_updated_at"(); +COMMENT ON TRIGGER "set_public_inventory_updated_at" ON "public"."inventory" +IS 'trigger to set value of column "updated_at" to current timestamp on row update'; +CREATE EXTENSION IF NOT EXISTS pgcrypto; diff --git a/hasura/migrations/1653933089451_set_fk_public_inventory_billid/down.sql b/hasura/migrations/1653933089451_set_fk_public_inventory_billid/down.sql new file mode 100644 index 000000000..10359e17b --- /dev/null +++ b/hasura/migrations/1653933089451_set_fk_public_inventory_billid/down.sql @@ -0,0 +1 @@ +alter table "public"."inventory" drop constraint "inventory_billid_fkey"; diff --git a/hasura/migrations/1653933089451_set_fk_public_inventory_billid/up.sql b/hasura/migrations/1653933089451_set_fk_public_inventory_billid/up.sql new file mode 100644 index 000000000..083b9da5f --- /dev/null +++ b/hasura/migrations/1653933089451_set_fk_public_inventory_billid/up.sql @@ -0,0 +1,5 @@ +alter table "public"."inventory" + add constraint "inventory_billid_fkey" + foreign key ("billid") + references "public"."billlines" + ("id") on update restrict on delete restrict; diff --git a/hasura/migrations/1653933105635_set_fk_public_inventory_shopid/down.sql b/hasura/migrations/1653933105635_set_fk_public_inventory_shopid/down.sql new file mode 100644 index 000000000..2fb006d66 --- /dev/null +++ b/hasura/migrations/1653933105635_set_fk_public_inventory_shopid/down.sql @@ -0,0 +1 @@ +alter table "public"."inventory" drop constraint "inventory_shopid_fkey"; diff --git a/hasura/migrations/1653933105635_set_fk_public_inventory_shopid/up.sql b/hasura/migrations/1653933105635_set_fk_public_inventory_shopid/up.sql new file mode 100644 index 000000000..b577f28bf --- /dev/null +++ b/hasura/migrations/1653933105635_set_fk_public_inventory_shopid/up.sql @@ -0,0 +1,5 @@ +alter table "public"."inventory" + add constraint "inventory_shopid_fkey" + foreign key ("shopid") + references "public"."bodyshops" + ("id") on update restrict on delete restrict; diff --git a/hasura/migrations/1653935727610_alter_table_public_inventory_alter_column_billid/down.sql b/hasura/migrations/1653935727610_alter_table_public_inventory_alter_column_billid/down.sql new file mode 100644 index 000000000..9ec9e56ea --- /dev/null +++ b/hasura/migrations/1653935727610_alter_table_public_inventory_alter_column_billid/down.sql @@ -0,0 +1 @@ +alter table "public"."inventory" rename column "billlineid" to "billid"; diff --git a/hasura/migrations/1653935727610_alter_table_public_inventory_alter_column_billid/up.sql b/hasura/migrations/1653935727610_alter_table_public_inventory_alter_column_billid/up.sql new file mode 100644 index 000000000..aaf49eceb --- /dev/null +++ b/hasura/migrations/1653935727610_alter_table_public_inventory_alter_column_billid/up.sql @@ -0,0 +1 @@ +alter table "public"."inventory" rename column "billid" to "billlineid"; diff --git a/hasura/migrations/1653953166273_alter_table_public_inventory_add_column_consumedbybillid/down.sql b/hasura/migrations/1653953166273_alter_table_public_inventory_add_column_consumedbybillid/down.sql new file mode 100644 index 000000000..0e361bc38 --- /dev/null +++ b/hasura/migrations/1653953166273_alter_table_public_inventory_add_column_consumedbybillid/down.sql @@ -0,0 +1,4 @@ +-- Could not auto-generate a down migration. +-- Please write an appropriate down migration for the SQL below: +-- alter table "public"."inventory" add column "consumedbybillid" uuid +-- null; diff --git a/hasura/migrations/1653953166273_alter_table_public_inventory_add_column_consumedbybillid/up.sql b/hasura/migrations/1653953166273_alter_table_public_inventory_add_column_consumedbybillid/up.sql new file mode 100644 index 000000000..8b21a892a --- /dev/null +++ b/hasura/migrations/1653953166273_alter_table_public_inventory_add_column_consumedbybillid/up.sql @@ -0,0 +1,2 @@ +alter table "public"."inventory" add column "consumedbybillid" uuid + null; diff --git a/hasura/migrations/1653953259127_set_fk_public_inventory_consumedbybillid/down.sql b/hasura/migrations/1653953259127_set_fk_public_inventory_consumedbybillid/down.sql new file mode 100644 index 000000000..5d24c2671 --- /dev/null +++ b/hasura/migrations/1653953259127_set_fk_public_inventory_consumedbybillid/down.sql @@ -0,0 +1 @@ +alter table "public"."inventory" drop constraint "inventory_consumedbybillid_fkey"; diff --git a/hasura/migrations/1653953259127_set_fk_public_inventory_consumedbybillid/up.sql b/hasura/migrations/1653953259127_set_fk_public_inventory_consumedbybillid/up.sql new file mode 100644 index 000000000..76c4bd767 --- /dev/null +++ b/hasura/migrations/1653953259127_set_fk_public_inventory_consumedbybillid/up.sql @@ -0,0 +1,5 @@ +alter table "public"."inventory" + add constraint "inventory_consumedbybillid_fkey" + foreign key ("consumedbybillid") + references "public"."bills" + ("id") on update restrict on delete restrict; diff --git a/hasura/migrations/1653953283374_set_fk_public_inventory_consumedbybillid/down.sql b/hasura/migrations/1653953283374_set_fk_public_inventory_consumedbybillid/down.sql new file mode 100644 index 000000000..2e6cdae18 --- /dev/null +++ b/hasura/migrations/1653953283374_set_fk_public_inventory_consumedbybillid/down.sql @@ -0,0 +1,5 @@ +alter table "public"."inventory" drop constraint "inventory_consumedbybillid_fkey", + add constraint "inventory_consumedbybillid_fkey" + foreign key ("shopid") + references "public"."bodyshops" + ("id") on update restrict on delete restrict; diff --git a/hasura/migrations/1653953283374_set_fk_public_inventory_consumedbybillid/up.sql b/hasura/migrations/1653953283374_set_fk_public_inventory_consumedbybillid/up.sql new file mode 100644 index 000000000..ee8578516 --- /dev/null +++ b/hasura/migrations/1653953283374_set_fk_public_inventory_consumedbybillid/up.sql @@ -0,0 +1,5 @@ +alter table "public"."inventory" drop constraint "inventory_consumedbybillid_fkey", + add constraint "inventory_consumedbybillid_fkey" + foreign key ("consumedbybillid") + references "public"."bills" + ("id") on update restrict on delete set null; diff --git a/hasura/migrations/1653953288756_set_fk_public_inventory_consumedbybillid/down.sql b/hasura/migrations/1653953288756_set_fk_public_inventory_consumedbybillid/down.sql new file mode 100644 index 000000000..2e6cdae18 --- /dev/null +++ b/hasura/migrations/1653953288756_set_fk_public_inventory_consumedbybillid/down.sql @@ -0,0 +1,5 @@ +alter table "public"."inventory" drop constraint "inventory_consumedbybillid_fkey", + add constraint "inventory_consumedbybillid_fkey" + foreign key ("shopid") + references "public"."bodyshops" + ("id") on update restrict on delete restrict; diff --git a/hasura/migrations/1653953288756_set_fk_public_inventory_consumedbybillid/up.sql b/hasura/migrations/1653953288756_set_fk_public_inventory_consumedbybillid/up.sql new file mode 100644 index 000000000..ac2008fc6 --- /dev/null +++ b/hasura/migrations/1653953288756_set_fk_public_inventory_consumedbybillid/up.sql @@ -0,0 +1,5 @@ +alter table "public"."inventory" drop constraint "inventory_consumedbybillid_fkey", + add constraint "inventory_consumedbybillid_fkey" + foreign key ("consumedbybillid") + references "public"."bills" + ("id") on update cascade on delete set null; diff --git a/hasura/migrations/1653953385835_create_index_inventory_consumedbybillid/down.sql b/hasura/migrations/1653953385835_create_index_inventory_consumedbybillid/down.sql new file mode 100644 index 000000000..d2d1f2b46 --- /dev/null +++ b/hasura/migrations/1653953385835_create_index_inventory_consumedbybillid/down.sql @@ -0,0 +1 @@ +DROP INDEX IF EXISTS "public"."inventory_consumedbybillid"; diff --git a/hasura/migrations/1653953385835_create_index_inventory_consumedbybillid/up.sql b/hasura/migrations/1653953385835_create_index_inventory_consumedbybillid/up.sql new file mode 100644 index 000000000..f547132c9 --- /dev/null +++ b/hasura/migrations/1653953385835_create_index_inventory_consumedbybillid/up.sql @@ -0,0 +1,2 @@ +CREATE INDEX "inventory_consumedbybillid" on + "public"."inventory" using btree ("consumedbybillid"); diff --git a/hasura/migrations/1653953399350_create_index_inventory_shopididx/down.sql b/hasura/migrations/1653953399350_create_index_inventory_shopididx/down.sql new file mode 100644 index 000000000..1b7d82158 --- /dev/null +++ b/hasura/migrations/1653953399350_create_index_inventory_shopididx/down.sql @@ -0,0 +1 @@ +DROP INDEX IF EXISTS "public"."inventory_shopididx"; diff --git a/hasura/migrations/1653953399350_create_index_inventory_shopididx/up.sql b/hasura/migrations/1653953399350_create_index_inventory_shopididx/up.sql new file mode 100644 index 000000000..f987787cc --- /dev/null +++ b/hasura/migrations/1653953399350_create_index_inventory_shopididx/up.sql @@ -0,0 +1,2 @@ +CREATE INDEX "inventory_shopididx" on + "public"."inventory" using btree ("shopid");