Skip to content

Commit

Permalink
Merge pull request #661 from bigcapitalhq/fix-payment-made-full-amount
Browse files Browse the repository at this point in the history
fix: Payment made filling the form full amount field
  • Loading branch information
abouolia authored Sep 4, 2024
2 parents 16f5cb7 + 3fcb6fe commit c032a5d
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ import {
Button,
} from '@blueprintjs/core';
import { DateInput } from '@blueprintjs/datetime';
import { FastField, Field, useFormikContext, ErrorMessage } from 'formik';
import { FormattedMessage as T, VendorsSelect } from '@/components';
import { FastField, useFormikContext, ErrorMessage } from 'formik';
import {
FInputGroup,
FMoneyInputGroup,
FormattedMessage as T,
VendorsSelect,
} from '@/components';
import { CLASSES } from '@/constants/classes';

import {
Expand All @@ -25,7 +30,6 @@ import {
Hint,
Icon,
VendorDrawerLink,
MoneyInputGroup,
} from '@/components';
import withCurrentOrganization from '@/containers/Organization/withCurrentOrganization';
import { usePaymentMadeFormContext } from './PaymentMadeFormProvider';
Expand All @@ -49,7 +53,7 @@ import { accountsFieldShouldUpdate, vendorsFieldShouldUpdate } from './utils';
function PaymentMadeFormHeaderFields({ organization: { base_currency } }) {
// Formik form context.
const {
values: { entries },
values: { entries, currency_code },
setFieldValue,
} = useFormikContext();

Expand Down Expand Up @@ -115,47 +119,34 @@ function PaymentMadeFormHeaderFields({ organization: { base_currency } }) {
</FastField>

{/* ------------ Full amount ------------ */}
<Field name={'amount'}>
{({
form: {
values: { currency_code, entries },
},
field: { value },
meta: { error, touched },
}) => (
<FormGroup
label={<T id={'full_amount'} />}
inline={true}
className={('form-group--full-amount', Classes.FILL)}
intent={inputIntent({ error, touched })}
labelInfo={<Hint />}
helperText={<ErrorMessage name="amount" />}
>
<ControlGroup>
<InputPrependText text={currency_code} />
<MoneyInputGroup
value={value}
onChange={(value) => {
setFieldValue('amount', value);
}}
onBlurValue={onFullAmountBlur}
/>
</ControlGroup>
<FFormGroup
name={'amount'}
label={<T id={'full_amount'} />}
inline={true}
labelInfo={<Hint />}
fastField
>
<ControlGroup>
<InputPrependText text={currency_code} />
<FMoneyInputGroup
fastField
name={'amount'}
onBlurValue={onFullAmountBlur}
/>
</ControlGroup>

{!isEmpty(entries) && (
<Button
onClick={handleReceiveFullAmountClick}
className={'receive-full-amount'}
small={true}
minimal={true}
>
<T id={'receive_full_amount'} /> (
<Money amount={payableFullAmount} currency={currency_code} />)
</Button>
)}
</FormGroup>
{!isEmpty(entries) && (
<Button
onClick={handleReceiveFullAmountClick}
className={'receive-full-amount'}
small={true}
minimal={true}
>
<T id={'receive_full_amount'} /> (
<Money amount={payableFullAmount} currency={currency_code} />)
</Button>
)}
</Field>
</FFormGroup>

{/* ------------ Payment number ------------ */}
<FastField name={'payment_number'}>
Expand Down Expand Up @@ -203,23 +194,14 @@ function PaymentMadeFormHeaderFields({ organization: { base_currency } }) {
</FFormGroup>

{/* ------------ Reference ------------ */}
<FastField name={'reference'}>
{({ form, field, meta: { error, touched } }) => (
<FormGroup
label={<T id={'reference'} />}
inline={true}
className={classNames('form-group--reference', Classes.FILL)}
intent={inputIntent({ error, touched })}
helperText={<ErrorMessage name="reference" />}
>
<InputGroup
intent={inputIntent({ error, touched })}
minimal={true}
{...field}
/>
</FormGroup>
)}
</FastField>
<FFormGroup
name={'reference'}
label={<T id={'reference'} />}
inline={true}
fastField
>
<FInputGroup name={'reference'} minimal={true} fastField />
</FFormGroup>
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export const defaultPaymentMade = {

export const transformToEditForm = (paymentMade, paymentMadeEntries) => {
const attachments = transformAttachmentsToForm(paymentMade);
const appliedAmount = safeSumBy(paymentMadeEntries, 'payment_amount');

return {
...transformToForm(paymentMade, defaultPaymentMade),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const Schema = Yup.object().shape({
deposit_account_id: Yup.number()
.required()
.label(intl.get('deposit_account_')),
full_amount: Yup.number().nullable(),
amount: Yup.number().required().label('Amount'),
payment_receive_no: Yup.string()
.nullable()
.max(DATATYPES_LENGTH.STRING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function PaymentReceiveFormAlerts() {
const handleClearingAllLines = () => {
const newEntries = clearAllPaymentEntries(entries);
setFieldValue('entries', newEntries);
setFieldValue('full_amount', '');
setFieldValue('amount', '');
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ import {
} from '@blueprintjs/core';
import { DateInput } from '@blueprintjs/datetime';
import { isEmpty, toSafeInteger } from 'lodash';
import { FastField, Field, useFormikContext, ErrorMessage } from 'formik';
import { FastField, useFormikContext, ErrorMessage } from 'formik';

import {
FeatureCan,
CustomersSelect,
FormattedMessage as T,
FMoneyInputGroup,
} from '@/components';
import { CLASSES } from '@/constants/classes';
import {
Expand All @@ -32,7 +33,6 @@ import {
AccountsSelect,
FieldRequiredHint,
Icon,
MoneyInputGroup,
InputPrependText,
CustomerDrawerLink,
Hint,
Expand Down Expand Up @@ -64,7 +64,7 @@ export default function PaymentReceiveHeaderFields() {

// Formik form context.
const {
values: { entries },
values: { entries, currency_code },
setFieldValue,
} = useFormikContext();

Expand All @@ -79,7 +79,7 @@ export default function PaymentReceiveHeaderFields() {
const fullAmount = safeSumBy(newEntries, 'payment_amount');

setFieldValue('entries', newEntries);
setFieldValue('full_amount', fullAmount);
setFieldValue('amount', fullAmount);
};
// Handles the full-amount field blur.
const onFullAmountBlur = (value) => {
Expand Down Expand Up @@ -124,48 +124,34 @@ export default function PaymentReceiveHeaderFields() {
</FastField>

{/* ------------ Full amount ------------ */}
<Field name={'amount'}>
{({
form: {
setFieldValue,
values: { currency_code, entries },
},
field: { value, onChange },
meta: { error, touched },
}) => (
<FormGroup
label={<T id={'full_amount'} />}
inline={true}
className={('form-group--full-amount', CLASSES.FILL)}
intent={inputIntent({ error, touched })}
labelInfo={<Hint />}
helperText={<ErrorMessage name="full_amount" />}
>
<ControlGroup>
<InputPrependText text={currency_code} />
<MoneyInputGroup
value={value}
onChange={(value) => {
setFieldValue('amount', value);
}}
onBlurValue={onFullAmountBlur}
/>
</ControlGroup>
<FFormGroup
name={'amount'}
label={<T id={'full_amount'} />}
inline={true}
labelInfo={<Hint />}
fastField
>
<ControlGroup>
<InputPrependText text={currency_code} />
<FMoneyInputGroup
name={'amount'}
onBlurValue={onFullAmountBlur}
fastField
/>
</ControlGroup>

{!isEmpty(entries) && (
<Button
onClick={handleReceiveFullAmountClick}
className={'receive-full-amount'}
small={true}
minimal={true}
>
<T id={'receive_full_amount'} /> (
<Money amount={totalDueAmount} currency={currency_code} />)
</Button>
)}
</FormGroup>
{!isEmpty(entries) && (
<Button
onClick={handleReceiveFullAmountClick}
className={'receive-full-amount'}
small={true}
minimal={true}
>
<T id={'receive_full_amount'} /> (
<Money amount={totalDueAmount} currency={currency_code} />)
</Button>
)}
</Field>
</FFormGroup>

{/* ------------ Payment receive no. ------------ */}
<PaymentReceivePaymentNoField />
Expand Down Expand Up @@ -197,23 +183,14 @@ export default function PaymentReceiveHeaderFields() {
</FFormGroup>

{/* ------------ Reference No. ------------ */}
<FastField name={'reference_no'}>
{({ form, field, meta: { error, touched } }) => (
<FormGroup
label={<T id={'reference'} />}
inline={true}
className={classNames('form-group--reference', CLASSES.FILL)}
intent={inputIntent({ error, touched })}
helperText={<ErrorMessage name="reference" />}
>
<InputGroup
intent={inputIntent({ error, touched })}
minimal={true}
{...field}
/>
</FormGroup>
)}
</FastField>
<FFormGroup
name={'reference_no'}
label={<T id={'reference'} />}
inline={true}
fastField
>
<InputGroup name={'reference_no'} minimal={true} fastField />
</FFormGroup>

{/*------------ Project name -----------*/}
<FeatureCan feature={Features.Projects}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ export const defaultRequestPayment = {
*/
export const transformToEditForm = (paymentReceive, paymentReceiveEntries) => ({
...transformToForm(paymentReceive, defaultPaymentReceive),
full_amount: safeSumBy(paymentReceiveEntries, 'payment_amount'),
entries: [
...paymentReceiveEntries.map((paymentReceiveEntry) => ({
...transformToForm(paymentReceiveEntry, defaultPaymentReceiveEntry),
Expand Down

0 comments on commit c032a5d

Please sign in to comment.