Added invoice number checkingBOD-411

This commit is contained in:
Patrick Fic
2020-09-29 14:40:39 -07:00
parent c222e027dd
commit 456ec10942
7 changed files with 82 additions and 1 deletions

View File

@@ -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({
<Form.Item
label={t("bills.fields.invoice_number")}
name="invoice_number"
validateTrigger="onBlur"
hasFeedback
rules={[
{
required: true,
message: t("general.validation.required"),
},
({ getFieldValue }) => ({
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();
}
},
}),
]}
>
<Input disabled={disabled} />

View File

@@ -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]);