From b8b95c7929f1dbea44a4ea5b47e006b658e2783e Mon Sep 17 00:00:00 2001 From: elforjani13 <39470382+elforjani13@users.noreply.github.com> Date: Mon, 7 Mar 2022 20:57:20 +0200 Subject: [PATCH] feat(refund credit):add exchange rate muted & branch. --- .../RefundCreditNoteForm.js | 1 + .../RefundCreditNoteForm.schema.js | 1 + .../RefundCreditNoteFormFields.js | 193 ++++++++++++------ .../RefundCreditNoteFormProvider.js | 16 +- .../Dialogs/RefundCreditNoteDialog/utils.js | 22 ++ .../RefundCreditNote/RefundCreditNote.scss | 2 +- .../RefundVendorCredit.scss | 2 +- 7 files changed, 169 insertions(+), 68 deletions(-) diff --git a/src/containers/Dialogs/RefundCreditNoteDialog/RefundCreditNoteForm.js b/src/containers/Dialogs/RefundCreditNoteDialog/RefundCreditNoteForm.js index 4250a14b1..0311a2423 100644 --- a/src/containers/Dialogs/RefundCreditNoteDialog/RefundCreditNoteForm.js +++ b/src/containers/Dialogs/RefundCreditNoteDialog/RefundCreditNoteForm.js @@ -19,6 +19,7 @@ const defaultInitialValues = { reference_no: '', description: '', amount: '', + exchange_rate: 1, }; /** diff --git a/src/containers/Dialogs/RefundCreditNoteDialog/RefundCreditNoteForm.schema.js b/src/containers/Dialogs/RefundCreditNoteDialog/RefundCreditNoteForm.schema.js index 8ada6b557..e62d90ea7 100644 --- a/src/containers/Dialogs/RefundCreditNoteDialog/RefundCreditNoteForm.schema.js +++ b/src/containers/Dialogs/RefundCreditNoteDialog/RefundCreditNoteForm.schema.js @@ -8,5 +8,6 @@ const Schema = Yup.object().shape({ reference_no: Yup.string().min(1).max(DATATYPES_LENGTH.STRING).nullable(), from_account_id: Yup.number().required().label(intl.get('deposit_account_')), description: Yup.string().nullable().max(DATATYPES_LENGTH.TEXT), + exchange_rate: Yup.number(), }); export const CreateRefundCreditNoteFormSchema = Schema; diff --git a/src/containers/Dialogs/RefundCreditNoteDialog/RefundCreditNoteFormFields.js b/src/containers/Dialogs/RefundCreditNoteDialog/RefundCreditNoteFormFields.js index 5af43fe97..669a6d438 100644 --- a/src/containers/Dialogs/RefundCreditNoteDialog/RefundCreditNoteFormFields.js +++ b/src/containers/Dialogs/RefundCreditNoteDialog/RefundCreditNoteFormFields.js @@ -1,6 +1,8 @@ import React from 'react'; +import styled from 'styled-components'; import intl from 'react-intl-universal'; -import { FastField, ErrorMessage } from 'formik'; +import { isEqual } from 'lodash'; +import { FastField, ErrorMessage, useFormikContext } from 'formik'; import { Classes, FormGroup, @@ -11,14 +13,22 @@ import { } from '@blueprintjs/core'; import classNames from 'classnames'; import { CLASSES } from 'common/classes'; +import { Features } from 'common'; import { DateInput } from '@blueprintjs/datetime'; import { Icon, + Col, + Row, + If, FieldRequiredHint, AccountsSuggestField, InputPrependText, MoneyInputGroup, FormattedMessage as T, + ExchangeRateMutedField, + BranchSelect, + BranchSelectButton, + FeatureCan, } from 'components'; import { inputIntent, @@ -28,41 +38,111 @@ import { } from 'utils'; import { useAutofocus } from 'hooks'; import { ACCOUNT_TYPE } from 'common/accountTypes'; +import { useSetPrimaryBranchToForm } from './utils'; import { useRefundCreditNoteContext } from './RefundCreditNoteFormProvider'; +import withCurrentOrganization from 'containers/Organization/withCurrentOrganization'; +import { compose } from 'utils'; + /** * Refund credit note form fields. */ -function RefundCreditNoteFormFields() { - const { accounts } = useRefundCreditNoteContext(); +function RefundCreditNoteFormFields({ + // #withCurrentOrganization + organization: { base_currency }, +}) { + const { accounts, branches } = useRefundCreditNoteContext(); + const { values } = useFormikContext(); + const amountFieldRef = useAutofocus(); + + // Sets the primary branch to form. + useSetPrimaryBranchToForm(); + return (
- {/* ------------- Refund date ------------- */} - - {({ form, field: { value }, meta: { error, touched } }) => ( - } - labelInfo={} - className={classNames('form-group--select-list', CLASSES.FILL)} - intent={inputIntent({ error, touched })} - helperText={} - // inline={true} - > - { - form.setFieldValue('date', formattedDate); - })} - popoverProps={{ position: Position.BOTTOM, minimal: true }} - inputProps={{ - leftIcon: , - }} - /> - - )} - + + + + } + className={classNames('form-group--select-list', Classes.FILL)} + > + + + + + + + + + + {/* ------------- Refund date ------------- */} + + {({ form, field: { value }, meta: { error, touched } }) => ( + } + labelInfo={} + className={classNames('form-group--select-list', CLASSES.FILL)} + intent={inputIntent({ error, touched })} + helperText={} + // inline={true} + > + { + form.setFieldValue('date', formattedDate); + })} + popoverProps={{ position: Position.BOTTOM, minimal: true }} + inputProps={{ + leftIcon: , + }} + /> + + )} + + + + {/* ------------ Form account ------------ */} + + {({ form, field: { value }, meta: { error, touched } }) => ( + } + className={classNames( + 'form-group--from_account_id', + 'form-group--select-list', + CLASSES.FILL, + )} + labelInfo={} + intent={inputIntent({ error, touched })} + helperText={} + > + + form.setFieldValue('from_account_id', id) + } + inputProps={{ + placeholder: intl.get('select_account'), + }} + filterByTypes={[ + ACCOUNT_TYPE.BANK, + ACCOUNT_TYPE.CASH, + ACCOUNT_TYPE.FIXED_ASSET, + ]} + /> + + )} + + + {/* ------------- Amount ------------- */} {({ @@ -76,7 +156,6 @@ function RefundCreditNoteFormFields() { className={classNames('form-group--amount', CLASSES.FILL)} intent={inputIntent({ error, touched })} helperText={} - // inline={true} > @@ -93,6 +172,19 @@ function RefundCreditNoteFormFields() { )} + + + {/*------------ exchange rate -----------*/} + + + {/* ------------ Reference No. ------------ */} {({ form, field, meta: { error, touched } }) => ( @@ -101,7 +193,6 @@ function RefundCreditNoteFormFields() { className={classNames('form-group--reference', CLASSES.FILL)} intent={inputIntent({ error, touched })} helperText={} - // inline={true} > - {/* ------------ Form account ------------ */} - - {({ form, field: { value }, meta: { error, touched } }) => ( - } - className={classNames( - 'form-group--from_account_id', - 'form-group--select-list', - CLASSES.FILL, - )} - labelInfo={} - intent={inputIntent({ error, touched })} - helperText={} - // inline={true} - > - - form.setFieldValue('from_account_id', id) - } - inputProps={{ - placeholder: intl.get('select_account'), - }} - filterByTypes={[ - ACCOUNT_TYPE.BANK, - ACCOUNT_TYPE.CASH, - ACCOUNT_TYPE.FIXED_ASSET, - ]} - /> - - )} - {/* --------- Statement --------- */} {({ form, field, meta: { error, touched } }) => ( } className={'form-group--description'} - // inline={true} >