feat(Sales & Purchases ): add setfieldvalue exchange rate.

This commit is contained in:
elforjani13
2022-02-23 12:22:27 +02:00
parent cf7d032aae
commit e6a7c7bc58
26 changed files with 118 additions and 66 deletions

View File

@@ -13,13 +13,12 @@ const Schema = Yup.object().shape({
.min(1)
.max(DATATYPES_LENGTH.STRING)
.label(intl.get('journal_type')),
date: Yup.date()
.required()
.label(intl.get('date')),
date: Yup.date().required().label(intl.get('date')),
currency_code: Yup.string().max(3),
publish: Yup.boolean(),
reference: Yup.string().nullable().min(1).max(DATATYPES_LENGTH.STRING),
description: Yup.string().min(1).max(DATATYPES_LENGTH.STRING).nullable(),
exchange_rate: Yup.number(),
entries: Yup.array().of(
Yup.object().shape({
credit: Yup.number().nullable(),

View File

@@ -56,6 +56,7 @@ function MakeJournalEntriesHeader({
currencies,
isForeignJournal,
baseCurrency,
selectJournalCurrency,
setSelactJournalCurrency,
} = useMakeJournalFormContext();
@@ -195,39 +196,37 @@ function MakeJournalEntriesHeader({
{/*------------ Currency -----------*/}
{/* <FeatureCan feature={Features.ManualJournal}> */}
<FastField
name={'currency_code'}
currencies={currencies}
shouldUpdate={currenciesFieldShouldUpdate}
>
{({ form, field: { value }, meta: { error, touched } }) => (
<FormGroup
label={<T id={'currency'} />}
className={classNames('form-group--currency', CLASSES.FILL)}
inline={true}
>
<CurrencySelectList
currenciesList={currencies}
selectedCurrencyCode={value}
onCurrencySelected={(currencyItem) => {
form.setFieldValue(
'currency_code',
currencyItem.currency_code,
);
setSelactJournalCurrency(currencyItem);
}}
defaultSelectText={value}
/>
</FormGroup>
)}
</FastField>
<FastField
name={'currency_code'}
currencies={currencies}
shouldUpdate={currenciesFieldShouldUpdate}
>
{({ form, field: { value }, meta: { error, touched } }) => (
<FormGroup
label={<T id={'currency'} />}
className={classNames('form-group--currency', CLASSES.FILL)}
inline={true}
>
<CurrencySelectList
currenciesList={currencies}
selectedCurrencyCode={value}
onCurrencySelected={(currencyItem) => {
form.setFieldValue('currency_code', currencyItem.currency_code);
form.setFieldValue('exchange_rate', '');
setSelactJournalCurrency(currencyItem);
}}
defaultSelectText={value}
/>
</FormGroup>
)}
</FastField>
{/* </FeatureCan> */}
{/* ----------- Exchange rate ----------- */}
<If condition={isForeignJournal}>
<ExchangeRateInputGroup
fromCurrency={'USD'}
toCurrency={'LYD'}
fromCurrency={baseCurrency}
toCurrency={selectJournalCurrency?.currency_code}
name={'exchange_rate'}
formGroupProps={{ label: ' ', inline: true }}
/>

View File

@@ -9,7 +9,7 @@ import {
repeatValue,
transformToForm,
defaultFastFieldShouldUpdate,
ensureEntriesHasEmptyLine
ensureEntriesHasEmptyLine,
} from 'utils';
import { AppToaster } from 'components';
import intl from 'react-intl-universal';
@@ -44,6 +44,7 @@ export const defaultManualJournal = {
reference: '',
currency_code: '',
publish: '',
exchange_rate: '',
entries: [...repeatValue(defaultEntry, 4)],
};

View File

@@ -25,6 +25,7 @@ const BillFormSchema = Yup.object().shape({
open: Yup.boolean(),
branch_id: Yup.string(),
warehouse_id: Yup.string(),
exchange_rate:Yup.number(),
entries: Yup.array().of(
Yup.object().shape({
quantity: Yup.number()

View File

@@ -37,7 +37,13 @@ import {
*/
function BillFormHeader() {
// Bill form context.
const { vendors, isForeignVendor, setSelectVendor } = useBillFormContext();
const {
vendors,
isForeignVendor,
baseCurrency,
selectVendor,
setSelectVendor,
} = useBillFormContext();
return (
<div className={classNames(CLASSES.PAGE_FORM_HEADER_FIELDS)}>
@@ -63,6 +69,7 @@ function BillFormHeader() {
defaultSelectText={<T id={'select_vender_account'} />}
onContactSelected={(contact) => {
form.setFieldValue('vendor_id', contact.id);
form.setFieldValue('exchange_rate', '');
setSelectVendor(contact);
}}
popoverFill={true}
@@ -77,8 +84,8 @@ function BillFormHeader() {
{/* ----------- Exchange rate ----------- */}
<If condition={isForeignVendor}>
<ExchangeRateInputGroup
fromCurrency={'USD'}
toCurrency={'LYD'}
fromCurrency={baseCurrency}
toCurrency={selectVendor?.currency_code}
name={'exchange_rate'}
formGroupProps={{ label: ' ', inline: true }}
/>

View File

@@ -44,6 +44,7 @@ export const defaultBill = {
open: '',
branch_id: '',
warehouse_id: '',
exchange_rate: '',
entries: [...repeatValue(defaultBillEntry, MIN_LINES_NUMBER)],
};

View File

@@ -18,6 +18,7 @@ const getSchema = Yup.object().shape({
open: Yup.boolean(),
branch_id: Yup.string(),
warehouse_id: Yup.string(),
exchange_rate: Yup.number(),
entries: Yup.array().of(
Yup.object().shape({
quantity: Yup.number()

View File

@@ -51,8 +51,13 @@ function VendorCreditNoteFormHeaderFields({
vendorcreditNextNumber,
}) {
// Vendor Credit form context.
const { vendors, isForeignVendor, setSelectVendor } =
useVendorCreditNoteFormContext();
const {
vendors,
isForeignVendor,
baseCurrency,
selectVendor,
setSelectVendor,
} = useVendorCreditNoteFormContext();
// Handle vendor credit number changing.
const handleVendorCreditNumberChange = () => {
@@ -102,6 +107,7 @@ function VendorCreditNoteFormHeaderFields({
defaultSelectText={<T id={'select_vender_account'} />}
onContactSelected={(contact) => {
form.setFieldValue('vendor_id', contact.id);
form.setFieldValue('exchange_rate', '');
setSelectVendor(contact);
}}
popoverFill={true}
@@ -116,8 +122,8 @@ function VendorCreditNoteFormHeaderFields({
{/* ----------- Exchange rate ----------- */}
<If condition={isForeignVendor}>
<ExchangeRateInputGroup
fromCurrency={'USD'}
toCurrency={'LYD'}
fromCurrency={baseCurrency}
toCurrency={selectVendor?.currency_code}
name={'exchange_rate'}
formGroupProps={{ label: ' ', inline: true }}
/>

View File

@@ -41,6 +41,7 @@ export const defaultVendorsCreditNote = {
note: '',
branch_id: '',
warehouse_id: '',
exchange_rate: '',
entries: [...repeatValue(defaultCreditNoteEntry, MIN_LINES_NUMBER)],
};

View File

@@ -3,12 +3,8 @@ import intl from 'react-intl-universal';
import { DATATYPES_LENGTH } from 'common/dataTypes';
const Schema = Yup.object().shape({
vendor_id: Yup.string()
.label(intl.get('vendor_name_'))
.required(),
payment_date: Yup.date()
.required()
.label(intl.get('payment_date_')),
vendor_id: Yup.string().label(intl.get('vendor_name_')).required(),
payment_date: Yup.date().required().label(intl.get('payment_date_')),
payment_account_id: Yup.number()
.required()
.label(intl.get('payment_account_')),
@@ -20,6 +16,7 @@ const Schema = Yup.object().shape({
reference: Yup.string().min(1).max(DATATYPES_LENGTH.STRING).nullable(),
description: Yup.string().max(DATATYPES_LENGTH.TEXT),
branch_id: Yup.string(),
exchange_rate: Yup.number(),
entries: Yup.array().of(
Yup.object().shape({
id: Yup.number().nullable(),

View File

@@ -60,6 +60,8 @@ function PaymentMadeFormHeaderFields({ organization: { base_currency } }) {
isNewMode,
setPaymentVendorId,
isForeignVendor,
baseCurrency,
selectVendor,
setSelectVendor,
} = usePaymentMadeFormContext();
@@ -108,6 +110,7 @@ function PaymentMadeFormHeaderFields({ organization: { base_currency } }) {
defaultSelectText={<T id={'select_vender_account'} />}
onContactSelected={(contact) => {
form.setFieldValue('vendor_id', contact.id);
form.setFieldValue('exchange_rate', '');
setPaymentVendorId(contact.id);
setSelectVendor(contact);
}}
@@ -124,8 +127,8 @@ function PaymentMadeFormHeaderFields({ organization: { base_currency } }) {
{/* ----------- Exchange rate ----------- */}
<If condition={isForeignVendor}>
<ExchangeRateInputGroup
fromCurrency={'USD'}
toCurrency={'LYD'}
fromCurrency={baseCurrency}
toCurrency={selectVendor?.currency_code}
name={'exchange_rate'}
formGroupProps={{ label: ' ', inline: true }}
/>

View File

@@ -35,6 +35,7 @@ export const defaultPaymentMade = {
statement: '',
currency_code: '',
branch_id: '',
exchange_rate: '',
entries: [],
};

View File

@@ -24,6 +24,7 @@ const getSchema = () =>
.label(intl.get('note')),
branch_id: Yup.string(),
warehouse_id: Yup.string(),
exchange_rate:Yup.number(),
entries: Yup.array().of(
Yup.object().shape({
quantity: Yup.number()

View File

@@ -49,8 +49,13 @@ function CreditNoteFormHeaderFields({
creditNextNumber,
}) {
// Credit note form context.
const { customers, isForeignCustomer, baseCurrency, setSelectCustomer } =
useCreditNoteFormContext();
const {
customers,
isForeignCustomer,
baseCurrency,
selectCustomer,
setSelectCustomer,
} = useCreditNoteFormContext();
// Handle credit number changing.
const handleCreditNumberChange = () => {
@@ -102,6 +107,7 @@ function CreditNoteFormHeaderFields({
defaultSelectText={<T id={'select_customer_account'} />}
onContactSelected={(customer) => {
form.setFieldValue('customer_id', customer.id);
form.setFieldValue('exchange_rate', '');
setSelectCustomer(customer);
}}
popoverFill={true}
@@ -116,8 +122,8 @@ function CreditNoteFormHeaderFields({
{/* ----------- Exchange rate ----------- */}
<If condition={isForeignCustomer}>
<ExchangeRateInputGroup
fromCurrency={'USD'}
toCurrency={'LYD'}
fromCurrency={baseCurrency}
toCurrency={selectCustomer?.currency_code}
name={'exchange_rate'}
formGroupProps={{ label: ' ', inline: true }}
/>

View File

@@ -43,6 +43,7 @@ export const defaultCreditNote = {
terms_conditions: '',
branch_id: '',
warehouse_id: '',
exchange_rate: '',
entries: [...repeatValue(defaultCreditNoteEntry, MIN_LINES_NUMBER)],
};
@@ -165,4 +166,4 @@ export const useSetPrimaryWarehouseToForm = () => {
}
}
}, [isWarehousesSuccess, setFieldValue, warehouses]);
};
};

View File

@@ -30,6 +30,7 @@ const Schema = Yup.object().shape({
delivered: Yup.boolean(),
branch_id: Yup.string(),
warehouse_id: Yup.string(),
exchange_rate: Yup.number(),
entries: Yup.array().of(
Yup.object().shape({
quantity: Yup.number()

View File

@@ -47,8 +47,13 @@ function EstimateFormHeader({
estimateNumberPrefix,
estimateNextNumber,
}) {
const { customers, isForeignCustomer, baseCurrency, setSelectCustomer } =
useEstimateFormContext();
const {
customers,
isForeignCustomer,
baseCurrency,
selectCustomer,
setSelectCustomer,
} = useEstimateFormContext();
const handleEstimateNumberBtnClick = () => {
openDialog('estimate-number-form', {});
@@ -94,6 +99,7 @@ function EstimateFormHeader({
defaultSelectText={<T id={'select_customer_account'} />}
onContactSelected={(customer) => {
form.setFieldValue('customer_id', customer.id);
form.setFieldValue('exchange_rate', '');
setSelectCustomer(customer);
}}
popoverFill={true}
@@ -109,8 +115,8 @@ function EstimateFormHeader({
{/* ----------- Exchange rate ----------- */}
<If condition={isForeignCustomer}>
<ExchangeRateInputGroup
fromCurrency={'USD'}
toCurrency={'LYD'}
fromCurrency={baseCurrency}
toCurrency={selectCustomer?.currency_code}
name={'exchange_rate'}
formGroupProps={{ label: ' ', inline: true }}
/>

View File

@@ -39,6 +39,7 @@ export const defaultEstimate = {
terms_conditions: '',
branch_id: '',
warehouse_id: '',
exchange_rate: '',
entries: [...repeatValue(defaultEstimateEntry, MIN_LINES_NUMBER)],
};

View File

@@ -57,8 +57,13 @@ function InvoiceFormHeaderFields({
invoiceNextNumber,
}) {
// Invoice form context.
const { customers, isForeignCustomer,selectCustomer ,setSelectCustomer } =
useInvoiceFormContext();
const {
customers,
isForeignCustomer,
baseCurrency,
selectCustomer,
setSelectCustomer,
} = useInvoiceFormContext();
// Handle invoice number changing.
const handleInvoiceNumberChange = () => {
@@ -110,6 +115,7 @@ function InvoiceFormHeaderFields({
defaultSelectText={<T id={'select_customer_account'} />}
onContactSelected={(customer) => {
form.setFieldValue('customer_id', customer.id);
form.setFieldValue('exchange_rate', '');
setSelectCustomer(customer);
}}
popoverFill={true}
@@ -124,8 +130,8 @@ function InvoiceFormHeaderFields({
{/* ----------- Exchange rate ----------- */}
<If condition={isForeignCustomer}>
<ExchangeRateInputGroup
fromCurrency={'USD'}
toCurrency={'LYD'}
fromCurrency={baseCurrency}
toCurrency={selectCustomer?.currency_code}
name={'exchange_rate'}
formGroupProps={{ label: ' ', inline: true }}
/>

View File

@@ -100,6 +100,7 @@ function InvoiceFormProvider({ invoiceId, baseCurrency, ...props }) {
invoiceId,
submitPayload,
selectCustomer,
baseCurrency,
branches,
warehouses,

View File

@@ -20,6 +20,7 @@ const Schema = Yup.object().shape({
reference_no: Yup.string().min(1).max(DATATYPES_LENGTH.STRING).nullable(),
// statement: Yup.string().nullable().max(DATATYPES_LENGTH.TEXT),
branch_id: Yup.string(),
exchange_rate:Yup.number(),
entries: Yup.array().of(
Yup.object().shape({
id: Yup.number().nullable(),

View File

@@ -73,6 +73,7 @@ function PaymentReceiveHeaderFields({
isNewMode,
isForeignCustomer,
baseCurrency,
selectCustomer,
setSelectCustomer,
} = usePaymentReceiveFormContext();
@@ -170,8 +171,8 @@ function PaymentReceiveHeaderFields({
{/* ----------- Exchange rate ----------- */}
<If condition={isForeignCustomer}>
<ExchangeRateInputGroup
fromCurrency={'USD'}
toCurrency={'LYD'}
fromCurrency={baseCurrency}
toCurrency={selectCustomer?.currency_code}
name={'exchange_rate'}
formGroupProps={{ label: ' ', inline: true }}
/>

View File

@@ -34,6 +34,7 @@ export const defaultPaymentReceive = {
full_amount: '',
currency_code: '',
branch_id: '',
exchange_rate:'',
entries: [],
};

View File

@@ -27,6 +27,7 @@ const Schema = Yup.object().shape({
closed: Yup.boolean(),
branch_id: Yup.string(),
warehouse_id: Yup.string(),
exchange_rate: Yup.number(),
entries: Yup.array().of(
Yup.object().shape({
quantity: Yup.number()

View File

@@ -54,8 +54,14 @@ function ReceiptFormHeader({
receiptNextNumber,
receiptNumberPrefix,
}) {
const { accounts, customers, isForeignCustomer, setSelectCustomer } =
useReceiptFormContext();
const {
accounts,
customers,
isForeignCustomer,
baseCurrency,
selectCustomer,
setSelectCustomer,
} = useReceiptFormContext();
const handleReceiptNumberChange = useCallback(() => {
openDialog('receipt-number-form', {});
@@ -101,6 +107,7 @@ function ReceiptFormHeader({
defaultSelectText={<T id={'select_customer_account'} />}
onContactSelected={(customer) => {
form.setFieldValue('customer_id', customer.id);
form.setFieldValue('exchange_rate', '');
setSelectCustomer(customer);
}}
popoverFill={true}
@@ -115,8 +122,8 @@ function ReceiptFormHeader({
{/* ----------- Exchange rate ----------- */}
<If condition={isForeignCustomer}>
<ExchangeRateInputGroup
fromCurrency={'USD'}
toCurrency={'LYD'}
fromCurrency={baseCurrency}
toCurrency={selectCustomer?.currency_code}
name={'exchange_rate'}
formGroupProps={{ label: ' ', inline: true }}
/>

View File

@@ -39,6 +39,7 @@ export const defaultReceipt = {
closed: '',
branch_id: '',
warehouse_id: '',
exchange_rate: '',
entries: [...repeatValue(defaultReceiptEntry, MIN_LINES_NUMBER)],
};