mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 12:20:31 +00:00
feat(Sales & Purchases ): add setfieldvalue exchange rate.
This commit is contained in:
@@ -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(),
|
||||
|
||||
@@ -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 }}
|
||||
/>
|
||||
|
||||
@@ -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)],
|
||||
};
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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 }}
|
||||
/>
|
||||
|
||||
@@ -44,6 +44,7 @@ export const defaultBill = {
|
||||
open: '',
|
||||
branch_id: '',
|
||||
warehouse_id: '',
|
||||
exchange_rate: '',
|
||||
entries: [...repeatValue(defaultBillEntry, MIN_LINES_NUMBER)],
|
||||
};
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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 }}
|
||||
/>
|
||||
|
||||
@@ -41,6 +41,7 @@ export const defaultVendorsCreditNote = {
|
||||
note: '',
|
||||
branch_id: '',
|
||||
warehouse_id: '',
|
||||
exchange_rate: '',
|
||||
entries: [...repeatValue(defaultCreditNoteEntry, MIN_LINES_NUMBER)],
|
||||
};
|
||||
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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 }}
|
||||
/>
|
||||
|
||||
@@ -35,6 +35,7 @@ export const defaultPaymentMade = {
|
||||
statement: '',
|
||||
currency_code: '',
|
||||
branch_id: '',
|
||||
exchange_rate: '',
|
||||
entries: [],
|
||||
};
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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 }}
|
||||
/>
|
||||
|
||||
@@ -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]);
|
||||
};
|
||||
};
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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 }}
|
||||
/>
|
||||
|
||||
@@ -39,6 +39,7 @@ export const defaultEstimate = {
|
||||
terms_conditions: '',
|
||||
branch_id: '',
|
||||
warehouse_id: '',
|
||||
exchange_rate: '',
|
||||
entries: [...repeatValue(defaultEstimateEntry, MIN_LINES_NUMBER)],
|
||||
};
|
||||
|
||||
|
||||
@@ -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 }}
|
||||
/>
|
||||
|
||||
@@ -100,6 +100,7 @@ function InvoiceFormProvider({ invoiceId, baseCurrency, ...props }) {
|
||||
invoiceId,
|
||||
submitPayload,
|
||||
selectCustomer,
|
||||
baseCurrency,
|
||||
branches,
|
||||
warehouses,
|
||||
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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 }}
|
||||
/>
|
||||
|
||||
@@ -34,6 +34,7 @@ export const defaultPaymentReceive = {
|
||||
full_amount: '',
|
||||
currency_code: '',
|
||||
branch_id: '',
|
||||
exchange_rate:'',
|
||||
entries: [],
|
||||
};
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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 }}
|
||||
/>
|
||||
|
||||
@@ -39,6 +39,7 @@ export const defaultReceipt = {
|
||||
closed: '',
|
||||
branch_id: '',
|
||||
warehouse_id: '',
|
||||
exchange_rate: '',
|
||||
entries: [...repeatValue(defaultReceiptEntry, MIN_LINES_NUMBER)],
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user