mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 07:10:33 +00:00
feat(qucikpayment):add exchange rate muted.
This commit is contained in:
@@ -18,6 +18,8 @@ const Schema = Yup.object().shape({
|
|||||||
.label(intl.get('payment_account_')),
|
.label(intl.get('payment_account_')),
|
||||||
reference: Yup.string().min(1).max(DATATYPES_LENGTH.STRING).nullable(),
|
reference: Yup.string().min(1).max(DATATYPES_LENGTH.STRING).nullable(),
|
||||||
// statement: Yup.string().nullable().max(DATATYPES_LENGTH.TEXT),
|
// statement: Yup.string().nullable().max(DATATYPES_LENGTH.TEXT),
|
||||||
|
branch_id: Yup.string(),
|
||||||
|
exchange_rate: Yup.number(),
|
||||||
entries: Yup.array().of(
|
entries: Yup.array().of(
|
||||||
Yup.object().shape({
|
Yup.object().shape({
|
||||||
payment_amount: Yup.number().nullable(),
|
payment_amount: Yup.number().nullable(),
|
||||||
|
|||||||
@@ -5,17 +5,30 @@ import 'style/pages/PaymentReceive/QuickPaymentReceiveDialog.scss';
|
|||||||
import { QuickPaymentMadeFormProvider } from './QuickPaymentMadeFormProvider';
|
import { QuickPaymentMadeFormProvider } from './QuickPaymentMadeFormProvider';
|
||||||
import QuickPaymentMadeForm from './QuickPaymentMadeForm';
|
import QuickPaymentMadeForm from './QuickPaymentMadeForm';
|
||||||
|
|
||||||
|
import withCurrentOrganization from 'containers/Organization/withCurrentOrganization';
|
||||||
|
import { compose } from 'utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Quick payment made form dialog content.
|
* Quick payment made form dialog content.
|
||||||
*/
|
*/
|
||||||
export default function QuickPaymentMadeFormDialogContent({
|
function QuickPaymentMadeFormDialogContent({
|
||||||
// #ownProps
|
// #ownProps
|
||||||
dialogName,
|
dialogName,
|
||||||
bill,
|
bill,
|
||||||
|
// #withCurrentOrganization
|
||||||
|
organization: { base_currency },
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<QuickPaymentMadeFormProvider billId={bill} dialogName={dialogName}>
|
<QuickPaymentMadeFormProvider
|
||||||
|
billId={bill}
|
||||||
|
baseCurrency={base_currency}
|
||||||
|
dialogName={dialogName}
|
||||||
|
>
|
||||||
<QuickPaymentMadeForm />
|
<QuickPaymentMadeForm />
|
||||||
</QuickPaymentMadeFormProvider>
|
</QuickPaymentMadeFormProvider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default compose(withCurrentOrganization())(
|
||||||
|
QuickPaymentMadeFormDialogContent,
|
||||||
|
);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { FastField, ErrorMessage } from 'formik';
|
import styled from 'styled-components';
|
||||||
|
import { FastField, ErrorMessage, useFormikContext } from 'formik';
|
||||||
import { FormattedMessage as T } from 'components';
|
import { FormattedMessage as T } from 'components';
|
||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
import {
|
import {
|
||||||
@@ -16,11 +17,17 @@ import { CLASSES } from 'common/classes';
|
|||||||
import { DateInput } from '@blueprintjs/datetime';
|
import { DateInput } from '@blueprintjs/datetime';
|
||||||
import { FieldRequiredHint, Col, Row } from 'components';
|
import { FieldRequiredHint, Col, Row } from 'components';
|
||||||
import { ACCOUNT_TYPE } from 'common/accountTypes';
|
import { ACCOUNT_TYPE } from 'common/accountTypes';
|
||||||
|
import { Features } from 'common';
|
||||||
import {
|
import {
|
||||||
AccountsSuggestField,
|
AccountsSuggestField,
|
||||||
InputPrependText,
|
InputPrependText,
|
||||||
MoneyInputGroup,
|
MoneyInputGroup,
|
||||||
Icon,
|
Icon,
|
||||||
|
If,
|
||||||
|
FeatureCan,
|
||||||
|
ExchangeRateMutedField,
|
||||||
|
BranchSelect,
|
||||||
|
BranchSelectButton,
|
||||||
} from 'components';
|
} from 'components';
|
||||||
import {
|
import {
|
||||||
inputIntent,
|
inputIntent,
|
||||||
@@ -28,20 +35,44 @@ import {
|
|||||||
tansformDateValue,
|
tansformDateValue,
|
||||||
handleDateChange,
|
handleDateChange,
|
||||||
} from 'utils';
|
} from 'utils';
|
||||||
|
import { useSetPrimaryBranchToForm, useForeignAccount } from './utils';
|
||||||
import { useQuickPaymentMadeContext } from './QuickPaymentMadeFormProvider';
|
import { useQuickPaymentMadeContext } from './QuickPaymentMadeFormProvider';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Quick payment made form fields.
|
* Quick payment made form fields.
|
||||||
*/
|
*/
|
||||||
export default function QuickPaymentMadeFormFields() {
|
export default function QuickPaymentMadeFormFields() {
|
||||||
const { accounts } = useQuickPaymentMadeContext();
|
const { accounts, branches, baseCurrency } = useQuickPaymentMadeContext();
|
||||||
|
const isForeigAccount = useForeignAccount();
|
||||||
|
|
||||||
// Intl context.
|
// Intl context.
|
||||||
|
const { values } = useFormikContext();
|
||||||
|
|
||||||
const paymentMadeFieldRef = useAutofocus();
|
const paymentMadeFieldRef = useAutofocus();
|
||||||
|
|
||||||
|
// Sets the primary branch to form.
|
||||||
|
useSetPrimaryBranchToForm();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={Classes.DIALOG_BODY}>
|
<div className={Classes.DIALOG_BODY}>
|
||||||
|
<FeatureCan feature={Features.Branches}>
|
||||||
|
<Row>
|
||||||
|
<Col xs={5}>
|
||||||
|
<FormGroup
|
||||||
|
label={<T id={'branch'} />}
|
||||||
|
className={classNames('form-group--select-list', Classes.FILL)}
|
||||||
|
>
|
||||||
|
<BranchSelect
|
||||||
|
name={'branch_id'}
|
||||||
|
branches={branches}
|
||||||
|
input={BranchSelectButton}
|
||||||
|
popoverProps={{ minimal: true }}
|
||||||
|
/>
|
||||||
|
</FormGroup>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
<BranchRowDivider />
|
||||||
|
</FeatureCan>
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
{/* ------------- Vendor name ------------- */}
|
{/* ------------- Vendor name ------------- */}
|
||||||
@@ -114,6 +145,17 @@ export default function QuickPaymentMadeFormFields() {
|
|||||||
</FormGroup>
|
</FormGroup>
|
||||||
)}
|
)}
|
||||||
</FastField>
|
</FastField>
|
||||||
|
<If condition={isForeigAccount}>
|
||||||
|
{/*------------ exchange rate -----------*/}
|
||||||
|
<ExchangeRateMutedField
|
||||||
|
name={'exchange_rate'}
|
||||||
|
fromCurrency={baseCurrency}
|
||||||
|
toCurrency={values.currency_code}
|
||||||
|
formGroupProps={{ label: '', inline: false }}
|
||||||
|
date={values.payment_date}
|
||||||
|
exchangeRate={values.exchange_rate}
|
||||||
|
/>
|
||||||
|
</If>
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
{/* ------------- Payment date ------------- */}
|
{/* ------------- Payment date ------------- */}
|
||||||
@@ -206,3 +248,9 @@ export default function QuickPaymentMadeFormFields() {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const BranchRowDivider = styled.div`
|
||||||
|
height: 1px;
|
||||||
|
background: #ebf1f6;
|
||||||
|
margin-bottom: 15px;
|
||||||
|
`;
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { DialogContent } from 'components';
|
import { DialogContent } from 'components';
|
||||||
import { useBill, useAccounts, useCreatePaymentMade } from 'hooks/query';
|
import {
|
||||||
|
useBill,
|
||||||
|
useAccounts,
|
||||||
|
useBranches,
|
||||||
|
useCreatePaymentMade,
|
||||||
|
} from 'hooks/query';
|
||||||
|
|
||||||
import { pick } from 'lodash';
|
import { pick } from 'lodash';
|
||||||
|
|
||||||
@@ -9,7 +14,12 @@ const QuickPaymentMadeContext = React.createContext();
|
|||||||
/**
|
/**
|
||||||
* Quick payment made dialog provider.
|
* Quick payment made dialog provider.
|
||||||
*/
|
*/
|
||||||
function QuickPaymentMadeFormProvider({ billId, dialogName, ...props }) {
|
function QuickPaymentMadeFormProvider({
|
||||||
|
billId,
|
||||||
|
baseCurrency,
|
||||||
|
dialogName,
|
||||||
|
...props
|
||||||
|
}) {
|
||||||
// Handle fetch bill details.
|
// Handle fetch bill details.
|
||||||
const { isLoading: isBillLoading, data: bill } = useBill(billId, {
|
const { isLoading: isBillLoading, data: bill } = useBill(billId, {
|
||||||
enabled: !!billId,
|
enabled: !!billId,
|
||||||
@@ -21,6 +31,13 @@ function QuickPaymentMadeFormProvider({ billId, dialogName, ...props }) {
|
|||||||
// Create payment made mutations.
|
// Create payment made mutations.
|
||||||
const { mutateAsync: createPaymentMadeMutate } = useCreatePaymentMade();
|
const { mutateAsync: createPaymentMadeMutate } = useCreatePaymentMade();
|
||||||
|
|
||||||
|
// Fetches the branches list.
|
||||||
|
const {
|
||||||
|
data: branches,
|
||||||
|
isLoading: isBranchesLoading,
|
||||||
|
isSuccess: isBranchesSuccess,
|
||||||
|
} = useBranches();
|
||||||
|
|
||||||
// State provider.
|
// State provider.
|
||||||
const provider = {
|
const provider = {
|
||||||
bill: {
|
bill: {
|
||||||
@@ -29,12 +46,17 @@ function QuickPaymentMadeFormProvider({ billId, dialogName, ...props }) {
|
|||||||
payment_amount: bill?.due_amount,
|
payment_amount: bill?.due_amount,
|
||||||
},
|
},
|
||||||
accounts,
|
accounts,
|
||||||
|
branches,
|
||||||
dialogName,
|
dialogName,
|
||||||
|
baseCurrency,
|
||||||
createPaymentMadeMutate,
|
createPaymentMadeMutate,
|
||||||
|
isBranchesSuccess,
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DialogContent isLoading={isAccountsLoading || isBillLoading}>
|
<DialogContent
|
||||||
|
isLoading={isAccountsLoading || isBillLoading || isBranchesLoading}
|
||||||
|
>
|
||||||
<QuickPaymentMadeContext.Provider value={provider} {...props} />
|
<QuickPaymentMadeContext.Provider value={provider} {...props} />
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
|
import React from 'react';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import intl from 'react-intl-universal';
|
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.
|
// Default initial values of payment made.
|
||||||
export const defaultPaymentMade = {
|
export const defaultPaymentMade = {
|
||||||
@@ -9,6 +14,8 @@ export const defaultPaymentMade = {
|
|||||||
reference: '',
|
reference: '',
|
||||||
payment_number: '',
|
payment_number: '',
|
||||||
// statement: '',
|
// statement: '',
|
||||||
|
exchange_rate: 1,
|
||||||
|
branch_id: '',
|
||||||
entries: [{ bill_id: '', payment_amount: '' }],
|
entries: [{ bill_id: '', payment_amount: '' }],
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -16,10 +23,7 @@ export const transformErrors = (errors, { setFieldError }) => {
|
|||||||
const getError = (errorType) => errors.find((e) => e.type === errorType);
|
const getError = (errorType) => errors.find((e) => e.type === errorType);
|
||||||
|
|
||||||
if (getError('PAYMENT.NUMBER.NOT.UNIQUE')) {
|
if (getError('PAYMENT.NUMBER.NOT.UNIQUE')) {
|
||||||
setFieldError(
|
setFieldError('payment_number', intl.get('payment_number_is_not_unique'));
|
||||||
'payment_number',
|
|
||||||
intl.get('payment_number_is_not_unique'),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if (getError('INVALID_BILL_PAYMENT_AMOUNT')) {
|
if (getError('INVALID_BILL_PAYMENT_AMOUNT')) {
|
||||||
setFieldError(
|
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);
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { FastField, ErrorMessage } from 'formik';
|
import styled from 'styled-components';
|
||||||
|
import { FastField, ErrorMessage, useFormikContext } from 'formik';
|
||||||
import { FormattedMessage as T } from 'components';
|
import { FormattedMessage as T } from 'components';
|
||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
import { useAutofocus } from 'hooks';
|
import { useAutofocus } from 'hooks';
|
||||||
@@ -20,32 +21,61 @@ import {
|
|||||||
InputPrependText,
|
InputPrependText,
|
||||||
MoneyInputGroup,
|
MoneyInputGroup,
|
||||||
Icon,
|
Icon,
|
||||||
|
If,
|
||||||
|
FeatureCan,
|
||||||
|
ExchangeRateMutedField,
|
||||||
|
BranchSelect,
|
||||||
|
BranchSelectButton,
|
||||||
} from 'components';
|
} from 'components';
|
||||||
|
import { Features } from 'common';
|
||||||
import { ACCOUNT_TYPE } from 'common/accountTypes';
|
import { ACCOUNT_TYPE } from 'common/accountTypes';
|
||||||
import {
|
import {
|
||||||
inputIntent,
|
inputIntent,
|
||||||
momentFormatter,
|
momentFormatter,
|
||||||
tansformDateValue,
|
tansformDateValue,
|
||||||
handleDateChange,
|
handleDateChange,
|
||||||
compose
|
compose,
|
||||||
} from 'utils';
|
} from 'utils';
|
||||||
|
import { useSetPrimaryBranchToForm, useForeignAccount } from './utils';
|
||||||
import { useQuickPaymentReceiveContext } from './QuickPaymentReceiveFormProvider';
|
import { useQuickPaymentReceiveContext } from './QuickPaymentReceiveFormProvider';
|
||||||
import withSettings from 'containers/Settings/withSettings';
|
import withSettings from 'containers/Settings/withSettings';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Quick payment receive form fields.
|
* Quick payment receive form fields.
|
||||||
*/
|
*/
|
||||||
function QuickPaymentReceiveFormFields({
|
function QuickPaymentReceiveFormFields({ paymentReceiveAutoIncrement }) {
|
||||||
paymentReceiveAutoIncrement
|
const { accounts, branches, baseCurrency } = useQuickPaymentReceiveContext();
|
||||||
}) {
|
|
||||||
const { accounts } = useQuickPaymentReceiveContext();
|
const isForeigAccount = useForeignAccount();
|
||||||
|
|
||||||
// Intl context.
|
// Intl context.
|
||||||
|
const { values } = useFormikContext();
|
||||||
|
|
||||||
const paymentReceiveFieldRef = useAutofocus();
|
const paymentReceiveFieldRef = useAutofocus();
|
||||||
|
|
||||||
|
// Sets the primary branch to form.
|
||||||
|
useSetPrimaryBranchToForm();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={Classes.DIALOG_BODY}>
|
<div className={Classes.DIALOG_BODY}>
|
||||||
|
<FeatureCan feature={Features.Branches}>
|
||||||
|
<Row>
|
||||||
|
<Col xs={5}>
|
||||||
|
<FormGroup
|
||||||
|
label={<T id={'branch'} />}
|
||||||
|
className={classNames('form-group--select-list', Classes.FILL)}
|
||||||
|
>
|
||||||
|
<BranchSelect
|
||||||
|
name={'branch_id'}
|
||||||
|
branches={branches}
|
||||||
|
input={BranchSelectButton}
|
||||||
|
popoverProps={{ minimal: true }}
|
||||||
|
/>
|
||||||
|
</FormGroup>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
<BranchRowDivider />
|
||||||
|
</FeatureCan>
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
{/* ------------- Customer name ------------- */}
|
{/* ------------- Customer name ------------- */}
|
||||||
@@ -120,6 +150,19 @@ function QuickPaymentReceiveFormFields({
|
|||||||
</FormGroup>
|
</FormGroup>
|
||||||
)}
|
)}
|
||||||
</FastField>
|
</FastField>
|
||||||
|
|
||||||
|
<If condition={isForeigAccount}>
|
||||||
|
{/*------------ exchange rate -----------*/}
|
||||||
|
<ExchangeRateMutedField
|
||||||
|
name={'exchange_rate'}
|
||||||
|
fromCurrency={baseCurrency}
|
||||||
|
toCurrency={values.currency_code}
|
||||||
|
formGroupProps={{ label: '', inline: false }}
|
||||||
|
date={values.payment_date}
|
||||||
|
exchangeRate={values.exchange_rate}
|
||||||
|
/>
|
||||||
|
</If>
|
||||||
|
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
{/* ------------- Payment date ------------- */}
|
{/* ------------- Payment date ------------- */}
|
||||||
@@ -218,4 +261,10 @@ export default compose(
|
|||||||
withSettings(({ paymentReceiveSettings }) => ({
|
withSettings(({ paymentReceiveSettings }) => ({
|
||||||
paymentReceiveAutoIncrement: paymentReceiveSettings?.autoIncrement,
|
paymentReceiveAutoIncrement: paymentReceiveSettings?.autoIncrement,
|
||||||
})),
|
})),
|
||||||
)(QuickPaymentReceiveFormFields)
|
)(QuickPaymentReceiveFormFields);
|
||||||
|
|
||||||
|
export const BranchRowDivider = styled.div`
|
||||||
|
height: 1px;
|
||||||
|
background: #ebf1f6;
|
||||||
|
margin-bottom: 15px;
|
||||||
|
`;
|
||||||
|
|||||||
@@ -1,14 +1,25 @@
|
|||||||
import React, { useContext, createContext } from 'react';
|
import React, { useContext, createContext } from 'react';
|
||||||
import { pick } from 'lodash';
|
import { pick } from 'lodash';
|
||||||
import { DialogContent } from 'components';
|
import { DialogContent } from 'components';
|
||||||
import { useAccounts, useInvoice, useSettingsPaymentReceives, useCreatePaymentReceive } from 'hooks/query';
|
import {
|
||||||
|
useAccounts,
|
||||||
|
useInvoice,
|
||||||
|
useBranches,
|
||||||
|
useSettingsPaymentReceives,
|
||||||
|
useCreatePaymentReceive,
|
||||||
|
} from 'hooks/query';
|
||||||
|
|
||||||
const QuickPaymentReceiveContext = createContext();
|
const QuickPaymentReceiveContext = createContext();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Quick payment receive dialog provider.
|
* Quick payment receive dialog provider.
|
||||||
*/
|
*/
|
||||||
function QuickPaymentReceiveFormProvider({ invoiceId, dialogName, ...props }) {
|
function QuickPaymentReceiveFormProvider({
|
||||||
|
invoiceId,
|
||||||
|
dialogName,
|
||||||
|
baseCurrency,
|
||||||
|
...props
|
||||||
|
}) {
|
||||||
// Handle fetch accounts data.
|
// Handle fetch accounts data.
|
||||||
const { data: accounts, isLoading: isAccountsLoading } = useAccounts();
|
const { data: accounts, isLoading: isAccountsLoading } = useAccounts();
|
||||||
|
|
||||||
@@ -22,9 +33,19 @@ function QuickPaymentReceiveFormProvider({ invoiceId, dialogName, ...props }) {
|
|||||||
// Fetch payment made settings.
|
// Fetch payment made settings.
|
||||||
const { isLoading: isSettingsLoading } = useSettingsPaymentReceives();
|
const { isLoading: isSettingsLoading } = useSettingsPaymentReceives();
|
||||||
|
|
||||||
|
// Fetches the branches list.
|
||||||
|
const {
|
||||||
|
data: branches,
|
||||||
|
isLoading: isBranchesLoading,
|
||||||
|
isSuccess: isBranchesSuccess,
|
||||||
|
} = useBranches();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// State provider.
|
// State provider.
|
||||||
const provider = {
|
const provider = {
|
||||||
accounts,
|
accounts,
|
||||||
|
branches,
|
||||||
invoice: {
|
invoice: {
|
||||||
...pick(invoice, ['id', 'due_amount', 'customer', 'currency_code']),
|
...pick(invoice, ['id', 'due_amount', 'customer', 'currency_code']),
|
||||||
customer_id: invoice?.customer?.display_name,
|
customer_id: invoice?.customer?.display_name,
|
||||||
@@ -32,13 +53,16 @@ function QuickPaymentReceiveFormProvider({ invoiceId, dialogName, ...props }) {
|
|||||||
},
|
},
|
||||||
isAccountsLoading,
|
isAccountsLoading,
|
||||||
isSettingsLoading,
|
isSettingsLoading,
|
||||||
|
isBranchesSuccess,
|
||||||
dialogName,
|
dialogName,
|
||||||
|
baseCurrency,
|
||||||
createPaymentReceiveMutate,
|
createPaymentReceiveMutate,
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DialogContent isLoading={isAccountsLoading || isInvoiceLoading}>
|
<DialogContent
|
||||||
|
isLoading={isAccountsLoading || isInvoiceLoading || isBranchesLoading}
|
||||||
|
>
|
||||||
<QuickPaymentReceiveContext.Provider value={provider} {...props} />
|
<QuickPaymentReceiveContext.Provider value={provider} {...props} />
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
|
import React from 'react';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
|
import { first, isEqual } from 'lodash';
|
||||||
|
|
||||||
|
import { useFormikContext } from 'formik';
|
||||||
|
import { useQuickPaymentReceiveContext } from './QuickPaymentReceiveFormProvider';
|
||||||
|
|
||||||
export const defaultInitialValues = {
|
export const defaultInitialValues = {
|
||||||
customer_id: '',
|
customer_id: '',
|
||||||
@@ -8,6 +13,8 @@ export const defaultInitialValues = {
|
|||||||
payment_date: moment(new Date()).format('YYYY-MM-DD'),
|
payment_date: moment(new Date()).format('YYYY-MM-DD'),
|
||||||
reference_no: '',
|
reference_no: '',
|
||||||
// statement: '',
|
// statement: '',
|
||||||
|
exchange_rate: 1,
|
||||||
|
branch_id: '',
|
||||||
entries: [{ invoice_id: '', payment_amount: '' }],
|
entries: [{ invoice_id: '', payment_amount: '' }],
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -33,3 +40,25 @@ export const transformErrors = (errors, { setFieldError }) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useSetPrimaryBranchToForm = () => {
|
||||||
|
const { setFieldValue } = useFormikContext();
|
||||||
|
const { branches, isBranchesSuccess } = useQuickPaymentReceiveContext();
|
||||||
|
|
||||||
|
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 } = useQuickPaymentReceiveContext();
|
||||||
|
|
||||||
|
return !isEqual(baseCurrency, values.currency_code);
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
.dialog--quick-payment-receive {
|
.dialog--quick-payment-receive {
|
||||||
|
.bp3-dialog-body {
|
||||||
|
line-height: 10px;
|
||||||
.bp3-form-group {
|
.bp3-form-group {
|
||||||
// margin-bottom: 15px;
|
margin-bottom: 10px;
|
||||||
|
|
||||||
label.bp3-label {
|
label.bp3-label {
|
||||||
margin-bottom: 3px;
|
margin-bottom: 7px;
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -19,7 +21,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
.bp3-dialog-footer {
|
.bp3-dialog-footer {
|
||||||
padding-top: 10px;
|
padding-top: 10px;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user