From 456ec109425c6c4305874f5cff36b6eca4b54cb4 Mon Sep 17 00:00:00 2001 From: Patrick Fic <> Date: Tue, 29 Sep 2020 14:40:39 -0700 Subject: [PATCH] Added invoice number checkingBOD-411 --- bodyshop_translations.babel | 26 +++++++++++++++++ .../bill-form/bill-form.component.jsx | 29 ++++++++++++++++++- .../job-search-select.component.jsx | 2 ++ client/src/graphql/bills.queries.js | 17 +++++++++++ client/src/translations/en_us/common.json | 3 ++ client/src/translations/es/common.json | 3 ++ client/src/translations/fr/common.json | 3 ++ 7 files changed, 82 insertions(+), 1 deletion(-) diff --git a/bodyshop_translations.babel b/bodyshop_translations.babel index aa388492d..eb11341e2 100644 --- a/bodyshop_translations.babel +++ b/bodyshop_translations.babel @@ -2146,6 +2146,32 @@ + + validation + + + unique_invoice_number + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + + + diff --git a/client/src/components/bill-form/bill-form.component.jsx b/client/src/components/bill-form/bill-form.component.jsx index 6f4e2a60c..96818ab04 100644 --- a/client/src/components/bill-form/bill-form.component.jsx +++ b/client/src/components/bill-form/bill-form.component.jsx @@ -10,9 +10,11 @@ import { Upload, } from "antd"; import React, { useEffect, useState } from "react"; +import { useApolloClient } from "react-apollo"; import { useTranslation } from "react-i18next"; import { connect } from "react-redux"; import { createStructuredSelector } from "reselect"; +import { CHECK_BILL_INVOICE_NUMBER } from "../../graphql/bills.queries"; import { selectBodyshop } from "../../redux/user/user.selectors"; import AlertComponent from "../alert/alert.component"; import FormDatePicker from "../form-date-picker/form-date-picker.component"; @@ -38,7 +40,7 @@ export function BillFormComponent({ billEdit, }) { const { t } = useTranslation(); - + const client = useApolloClient(); const [discount, setDiscount] = useState(0); const handleVendorSelect = (props, opt) => { @@ -106,11 +108,36 @@ export function BillFormComponent({ ({ + async validator(rule, value) { + const vendorid = getFieldValue("vendorid"); + if (vendorid) { + const response = await client.query({ + query: CHECK_BILL_INVOICE_NUMBER, + variables: { + invoice_number: value, + vendorid: vendorid, + }, + }); + + if (response.data.bills_aggregate.aggregate.count === 0) { + return Promise.resolve(); + } + return Promise.reject( + t("bills.validation.unique_invoice_number") + ); + } else { + return Promise.resolve(); + } + }, + }), ]} > diff --git a/client/src/components/job-search-select/job-search-select.component.jsx b/client/src/components/job-search-select/job-search-select.component.jsx index 6d3605dd6..ab4432270 100644 --- a/client/src/components/job-search-select/job-search-select.component.jsx +++ b/client/src/components/job-search-select/job-search-select.component.jsx @@ -33,6 +33,8 @@ const JobSearchSelect = ({ value, onChange, onBlur, disabled }, ref) => { useEffect(() => { if (value === option && value) { + console.log("Calling"); + console.log("value, option :>> ", value, option); callIdSearch({ variables: { id: value } }); } }, [value, option, callIdSearch]); diff --git a/client/src/graphql/bills.queries.js b/client/src/graphql/bills.queries.js index 0356d52f5..73f689816 100644 --- a/client/src/graphql/bills.queries.js +++ b/client/src/graphql/bills.queries.js @@ -214,3 +214,20 @@ export const UPDATE_BILLS = gql` } } `; + +export const CHECK_BILL_INVOICE_NUMBER = gql` + query CHECK_BILL_INVOICE_NUMBER($invoice_number: String!, $vendorid: uuid!) { + bills_aggregate( + where: { + _and: { + invoice_number: { _eq: $invoice_number } + vendorid: { _eq: $vendorid } + } + } + ) { + aggregate { + count + } + } + } +`; diff --git a/client/src/translations/en_us/common.json b/client/src/translations/en_us/common.json index 7f9ce9eb9..a44e1d4e8 100644 --- a/client/src/translations/en_us/common.json +++ b/client/src/translations/en_us/common.json @@ -147,6 +147,9 @@ }, "successes": { "created": "Invoice added successfully." + }, + "validation": { + "unique_invoice_number": "This invoice number has already been entered for this vendor." } }, "bodyshop": { diff --git a/client/src/translations/es/common.json b/client/src/translations/es/common.json index 819f4ff2f..cd395092c 100644 --- a/client/src/translations/es/common.json +++ b/client/src/translations/es/common.json @@ -147,6 +147,9 @@ }, "successes": { "created": "" + }, + "validation": { + "unique_invoice_number": "" } }, "bodyshop": { diff --git a/client/src/translations/fr/common.json b/client/src/translations/fr/common.json index 602418c40..dd073466b 100644 --- a/client/src/translations/fr/common.json +++ b/client/src/translations/fr/common.json @@ -147,6 +147,9 @@ }, "successes": { "created": "" + }, + "validation": { + "unique_invoice_number": "" } }, "bodyshop": {