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

@@ -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: [],
};