mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 14:50:32 +00:00
feat(qucikpayment):add exchange rate muted.
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
import React from 'react';
|
||||
import moment from 'moment';
|
||||
import intl from 'react-intl-universal';
|
||||
import { first, isEqual } from 'lodash';
|
||||
|
||||
import { useFormikContext } from 'formik';
|
||||
import { useQuickPaymentMadeContext } from './QuickPaymentMadeFormProvider';
|
||||
|
||||
// Default initial values of payment made.
|
||||
export const defaultPaymentMade = {
|
||||
@@ -9,6 +14,8 @@ export const defaultPaymentMade = {
|
||||
reference: '',
|
||||
payment_number: '',
|
||||
// statement: '',
|
||||
exchange_rate: 1,
|
||||
branch_id: '',
|
||||
entries: [{ bill_id: '', payment_amount: '' }],
|
||||
};
|
||||
|
||||
@@ -16,10 +23,7 @@ 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'),
|
||||
);
|
||||
setFieldError('payment_number', intl.get('payment_number_is_not_unique'));
|
||||
}
|
||||
if (getError('INVALID_BILL_PAYMENT_AMOUNT')) {
|
||||
setFieldError(
|
||||
@@ -28,3 +32,25 @@ export const transformErrors = (errors, { setFieldError }) => {
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export const useSetPrimaryBranchToForm = () => {
|
||||
const { setFieldValue } = useFormikContext();
|
||||
const { branches, isBranchesSuccess } = useQuickPaymentMadeContext();
|
||||
|
||||
React.useEffect(() => {
|
||||
if (isBranchesSuccess) {
|
||||
const primaryBranch = branches.find((b) => b.primary) || first(branches);
|
||||
|
||||
if (primaryBranch) {
|
||||
setFieldValue('branch_id', primaryBranch.id);
|
||||
}
|
||||
}
|
||||
}, [isBranchesSuccess, setFieldValue, branches]);
|
||||
};
|
||||
|
||||
export const useForeignAccount = () => {
|
||||
const { values } = useFormikContext();
|
||||
const { baseCurrency } = useQuickPaymentMadeContext();
|
||||
|
||||
return !isEqual(baseCurrency, values.currency_code);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user