diff --git a/src/containers/Dialogs/QuickPaymentMadeFormDialog/utils.js b/src/containers/Dialogs/QuickPaymentMadeFormDialog/utils.js index 427f7e194..29fb9237c 100644 --- a/src/containers/Dialogs/QuickPaymentMadeFormDialog/utils.js +++ b/src/containers/Dialogs/QuickPaymentMadeFormDialog/utils.js @@ -2,7 +2,8 @@ import React from 'react'; import moment from 'moment'; import intl from 'react-intl-universal'; import { first, isEqual } from 'lodash'; - +import { Intent } from '@blueprintjs/core'; +import { AppToaster } from 'components'; import { useFormikContext } from 'formik'; import { useQuickPaymentMadeContext } from './QuickPaymentMadeFormProvider'; @@ -31,6 +32,12 @@ export const transformErrors = (errors, { setFieldError }) => { intl.get('the_payment_amount_bigger_than_invoice_due_amount'), ); } + if (getError('WITHDRAWAL_ACCOUNT_CURRENCY_INVALID')) { + AppToaster.show({ + message: intl.get('payment_made.error.withdrawal_account_currency_invalid'), + intent: Intent.DANGER, + }); + } }; export const useSetPrimaryBranchToForm = () => { diff --git a/src/containers/Dialogs/QuickPaymentReceiveFormDialog/utils.js b/src/containers/Dialogs/QuickPaymentReceiveFormDialog/utils.js index bac86a4a9..c3641d32b 100644 --- a/src/containers/Dialogs/QuickPaymentReceiveFormDialog/utils.js +++ b/src/containers/Dialogs/QuickPaymentReceiveFormDialog/utils.js @@ -2,6 +2,8 @@ import React from 'react'; import moment from 'moment'; import intl from 'react-intl-universal'; import { first } from 'lodash'; +import { Intent } from '@blueprintjs/core'; +import { AppToaster } from 'components'; import { useFormikContext } from 'formik'; import { useQuickPaymentReceiveContext } from './QuickPaymentReceiveFormProvider'; @@ -39,6 +41,12 @@ export const transformErrors = (errors, { setFieldError }) => { intl.get('the_payment_amount_bigger_than_invoice_due_amount'), ); } + if (getError('PAYMENT_ACCOUNT_CURRENCY_INVALID')) { + AppToaster.show({ + message: intl.get('payment_Receive.error.payment_account_currency_invalid'), + intent: Intent.DANGER, + }); + } }; export const useSetPrimaryBranchToForm = () => { diff --git a/src/containers/Purchases/PaymentMades/PaymentForm/PaymentMadeForm.js b/src/containers/Purchases/PaymentMades/PaymentForm/PaymentMadeForm.js index 1d988ca0c..a1652c045 100644 --- a/src/containers/Purchases/PaymentMades/PaymentForm/PaymentMadeForm.js +++ b/src/containers/Purchases/PaymentMades/PaymentForm/PaymentMadeForm.js @@ -27,7 +27,7 @@ import { usePaymentMadeFormContext } from './PaymentMadeFormProvider'; import { defaultPaymentMade, transformToEditForm, - ERRORS, + transformErrors, transformFormToRequest, } from './utils'; @@ -111,14 +111,10 @@ function PaymentMadeForm({ data: { errors }, }, }) => { - const getError = (errorType) => errors.find((e) => e.type === errorType); - - if (getError(ERRORS.PAYMENT_NUMBER_NOT_UNIQUE)) { - setFieldError( - 'payment_number', - intl.get('payment_number_is_not_unique'), - ); + if (errors) { + transformErrors(errors, { setFieldError }); } + setSubmitting(false); }; diff --git a/src/containers/Purchases/PaymentMades/PaymentForm/PaymentMadeFormProvider.js b/src/containers/Purchases/PaymentMades/PaymentForm/PaymentMadeFormProvider.js index ffdae93ba..a2796fd48 100644 --- a/src/containers/Purchases/PaymentMades/PaymentForm/PaymentMadeFormProvider.js +++ b/src/containers/Purchases/PaymentMades/PaymentForm/PaymentMadeFormProvider.js @@ -1,5 +1,7 @@ import React, { createContext, useContext } from 'react'; import { isEqual, isUndefined } from 'lodash'; +import { Features } from 'common'; +import { useFeatureCan } from 'hooks/state'; import { useAccounts, useVendors, @@ -18,11 +20,21 @@ const PaymentMadeFormContext = createContext(); /** * Payment made form provider. */ -function PaymentMadeFormProvider({ paymentMadeId, baseCurrency, ...props }) { +function PaymentMadeFormProvider({ + query, + paymentMadeId, + baseCurrency, + ...props +}) { const [submitPayload, setSubmitPayload] = React.useState({}); const [paymentVendorId, setPaymentVendorId] = React.useState(null); const [selectVendor, setSelectVendor] = React.useState(null); + // Features guard. + const { featureCan } = useFeatureCan(); + const isBranchFeatureCan = featureCan(Features.Branches); + + // Handle fetch accounts data. const { data: accounts, isLoading: isAccountsLoading } = useAccounts(); @@ -53,7 +65,8 @@ function PaymentMadeFormProvider({ paymentMadeId, baseCurrency, ...props }) { data: branches, isLoading: isBranchesLoading, isSuccess: isBranchesSuccess, - } = useBranches(); + } = useBranches(query, { enabled: isBranchFeatureCan }); + // Fetch payment made settings. useSettings(); diff --git a/src/containers/Purchases/PaymentMades/PaymentForm/utils.js b/src/containers/Purchases/PaymentMades/PaymentForm/utils.js index b93e3404e..07be02f51 100644 --- a/src/containers/Purchases/PaymentMades/PaymentForm/utils.js +++ b/src/containers/Purchases/PaymentMades/PaymentForm/utils.js @@ -1,7 +1,10 @@ import React from 'react'; import moment from 'moment'; +import intl from 'react-intl-universal'; import { pick, first } from 'lodash'; import { useFormikContext } from 'formik'; +import { Intent } from '@blueprintjs/core'; +import { AppToaster } from 'components'; import { usePaymentMadeFormContext } from './PaymentMadeFormProvider'; import { defaultFastFieldShouldUpdate, @@ -111,3 +114,20 @@ export const useSetPrimaryBranchToForm = () => { } }, [isBranchesSuccess, setFieldValue, branches]); }; + +/** + * Transformes the response errors types. + */ +export const transformErrors = (errors, { setFieldError }) => { + const getError = (errorType) => errors.find((e) => e.type === errorType); + + if (getError('PAYMENT_NUMBER_NOT_UNIQUE')) { + setFieldError('payment_number', intl.get('payment_number_is_not_unique')); + } + if (getError('WITHDRAWAL_ACCOUNT_CURRENCY_INVALID')) { + AppToaster.show({ + message: intl.get('payment_made.error.withdrawal_account_currency_invalid'), + intent: Intent.DANGER, + }); + } +}; diff --git a/src/containers/Sales/PaymentReceives/PaymentReceiveForm/PaymentReceiveForm.js b/src/containers/Sales/PaymentReceives/PaymentReceiveForm/PaymentReceiveForm.js index 47ce25493..22ad40f2c 100644 --- a/src/containers/Sales/PaymentReceives/PaymentReceiveForm/PaymentReceiveForm.js +++ b/src/containers/Sales/PaymentReceives/PaymentReceiveForm/PaymentReceiveForm.js @@ -33,6 +33,7 @@ import { defaultPaymentReceive, transformToEditForm, transformFormToRequest, + transformErrors, } from './utils'; /** @@ -135,19 +136,8 @@ function PaymentReceiveForm({ data: { errors }, }, }) => { - const getError = (errorType) => errors.find((e) => e.type === errorType); - - if (getError('PAYMENT_RECEIVE_NO_EXISTS')) { - setFieldError( - 'payment_receive_no', - intl.get('payment_number_is_not_unique'), - ); - } - if (getError('PAYMENT_RECEIVE_NO_REQUIRED')) { - setFieldError( - 'payment_receive_no', - intl.get('payment_receive.field.error.payment_receive_no_required'), - ); + if (errors) { + transformErrors(errors, { setFieldError }); } setSubmitting(false); }; diff --git a/src/containers/Sales/PaymentReceives/PaymentReceiveForm/PaymentReceiveFormProvider.js b/src/containers/Sales/PaymentReceives/PaymentReceiveForm/PaymentReceiveFormProvider.js index db29921e2..7274a4ade 100644 --- a/src/containers/Sales/PaymentReceives/PaymentReceiveForm/PaymentReceiveFormProvider.js +++ b/src/containers/Sales/PaymentReceives/PaymentReceiveForm/PaymentReceiveFormProvider.js @@ -1,6 +1,7 @@ import React, { createContext, useContext } from 'react'; -import { isEmpty, pick, isEqual, isUndefined } from 'lodash'; - +import {isEqual, isUndefined } from 'lodash'; +import { Features } from 'common'; +import { useFeatureCan } from 'hooks/state'; import { DashboardInsider } from 'components'; import { useSettingsPaymentReceives, @@ -19,6 +20,7 @@ const PaymentReceiveFormContext = createContext(); * Payment receive form provider. */ function PaymentReceiveFormProvider({ + query, paymentReceiveId, baseCurrency, ...props @@ -28,6 +30,10 @@ function PaymentReceiveFormProvider({ const [selectCustomer, setSelectCustomer] = React.useState(null); + // Features guard. + const { featureCan } = useFeatureCan(); + const isBranchFeatureCan = featureCan(Features.Branches); + // Fetches payment recevie details. const { data: { @@ -56,7 +62,7 @@ function PaymentReceiveFormProvider({ data: branches, isLoading: isBranchesLoading, isSuccess: isBranchesSuccess, - } = useBranches(); + } = useBranches(query, { enabled: isBranchFeatureCan }); // Detarmines whether the new mode. const isNewMode = !paymentReceiveId; diff --git a/src/containers/Sales/PaymentReceives/PaymentReceiveForm/utils.js b/src/containers/Sales/PaymentReceives/PaymentReceiveForm/utils.js index 9191e9f58..ada3570e8 100644 --- a/src/containers/Sales/PaymentReceives/PaymentReceiveForm/utils.js +++ b/src/containers/Sales/PaymentReceives/PaymentReceiveForm/utils.js @@ -1,7 +1,10 @@ import React from 'react'; -import { useFormikContext } from 'formik'; import moment from 'moment'; +import intl from 'react-intl-universal'; import { omit, pick, first } from 'lodash'; +import { useFormikContext } from 'formik'; +import { Intent } from '@blueprintjs/core'; +import { AppToaster } from 'components'; import { usePaymentReceiveFormContext } from './PaymentReceiveFormProvider'; import { defaultFastFieldShouldUpdate, @@ -182,3 +185,31 @@ export const useSetPrimaryBranchToForm = () => { } }, [isBranchesSuccess, setFieldValue, branches]); }; + +/** + * Transformes the response errors types. + */ +export const transformErrors = (errors, { setFieldError }) => { + const getError = (errorType) => errors.find((e) => e.type === errorType); + + if (getError('PAYMENT_RECEIVE_NO_EXISTS')) { + setFieldError( + 'payment_receive_no', + intl.get('payment_number_is_not_unique'), + ); + } + if (getError('PAYMENT_RECEIVE_NO_REQUIRED')) { + setFieldError( + 'payment_receive_no', + intl.get('payment_receive.field.error.payment_receive_no_required'), + ); + } + if (getError('PAYMENT_ACCOUNT_CURRENCY_INVALID')) { + AppToaster.show({ + message: intl.get( + 'payment_Receive.error.payment_account_currency_invalid', + ), + intent: Intent.DANGER, + }); + } +}; diff --git a/src/lang/ar/index.json b/src/lang/ar/index.json index c6f04093b..38a065316 100644 --- a/src/lang/ar/index.json +++ b/src/lang/ar/index.json @@ -1914,5 +1914,7 @@ "warehouse.error.warehouse_code_not_unique": "رمز المخزن ليس فريدًا ", "warehouse.error.warehouse_has_associated_transactions": "لا يمكنك حذف هذا المخزن لأنه لديه معاملات مرتبطة به. ", "branche.error.warehouse_code_not_unique": "رمز الفرع ليس فريدًا ", - "branche.error.branch_has_associated_transactions": "لا يمكنك حذف هذا الفرع لأنه لديه معاملات مرتبطة به." + "branche.error.branch_has_associated_transactions": "لا يمكنك حذف هذا الفرع لأنه لديه معاملات مرتبطة به.", + "payment_Receive.error.payment_account_currency_invalid":"يجب أن تكون عملة حساب الإيداع هي نفس عملة العميل أو العملة الأساسية للمنشأة.", + "payment_made.error.withdrawal_account_currency_invalid":"يجب أن تكون عملة حساب السحب هي نفس عملة المورد أو العملة الأساسية للمنشأة." } \ No newline at end of file diff --git a/src/lang/en/index.json b/src/lang/en/index.json index 2ed31c5b5..fba99b819 100644 --- a/src/lang/en/index.json +++ b/src/lang/en/index.json @@ -1909,5 +1909,7 @@ "warehouse.error.warehouse_code_not_unique": "Warehouse code not unique", "warehouse.error.warehouse_has_associated_transactions": "You could not delete the warehouse that has associated transactions.", "branche.error.warehouse_code_not_unique": "Branch code not unique", - "branche.error.branch_has_associated_transactions": "You could not delete the branch that has associated transactions." + "branche.error.branch_has_associated_transactions": "You could not delete the branch that has associated transactions.", + "payment_Receive.error.payment_account_currency_invalid":"The deposit account currency should be same customer currency or organization base currency.", + "payment_made.error.withdrawal_account_currency_invalid":"The withdrawal account currency should be same vendor currency or organization base currency." } \ No newline at end of file