mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 14:50:32 +00:00
feat(Sales & Purchases ): add exchange rate input.
This commit is contained in:
@@ -13,7 +13,9 @@ import {
|
||||
VendorSelectField,
|
||||
FieldRequiredHint,
|
||||
InputPrependButton,
|
||||
ExchangeRateInputGroup,
|
||||
Icon,
|
||||
If,
|
||||
FormattedMessage as T,
|
||||
} from 'components';
|
||||
import {
|
||||
@@ -47,7 +49,8 @@ function VendorCreditNoteFormHeaderFields({
|
||||
vendorcreditNextNumber,
|
||||
}) {
|
||||
// Vendor Credit form context.
|
||||
const { vendors } = useVendorCreditNoteFormContext();
|
||||
const { vendors, isForeignVendor, setSelectVendor } =
|
||||
useVendorCreditNoteFormContext();
|
||||
|
||||
// Handle vendor credit number changing.
|
||||
const handleVendorCreditNumberChange = () => {
|
||||
@@ -96,6 +99,7 @@ function VendorCreditNoteFormHeaderFields({
|
||||
defaultSelectText={<T id={'select_vender_account'} />}
|
||||
onContactSelected={(contact) => {
|
||||
form.setFieldValue('vendor_id', contact.id);
|
||||
setSelectVendor(contact);
|
||||
}}
|
||||
popoverFill={true}
|
||||
allowCreate={true}
|
||||
@@ -104,6 +108,16 @@ function VendorCreditNoteFormHeaderFields({
|
||||
)}
|
||||
</FastField>
|
||||
|
||||
{/* ----------- Exchange rate ----------- */}
|
||||
<If condition={isForeignVendor}>
|
||||
<ExchangeRateInputGroup
|
||||
fromCurrency={'USD'}
|
||||
toCurrency={'LYD'}
|
||||
name={'exchange_rate'}
|
||||
formGroupProps={{ label: ' ', inline: true }}
|
||||
/>
|
||||
</If>
|
||||
|
||||
{/* ------- Vendor Credit date ------- */}
|
||||
<FastField name={'vendor_credit_date'}>
|
||||
{({ form, field: { value }, meta: { error, touched } }) => (
|
||||
|
||||
@@ -6,16 +6,26 @@ import '../../../../style/pages/VendorsCreditNote/PageForm.scss';
|
||||
import VendorCreditNoteForm from './VendorCreditNoteForm';
|
||||
import { VendorCreditNoteFormProvider } from './VendorCreditNoteFormProvider';
|
||||
|
||||
import withCurrentOrganization from 'containers/Organization/withCurrentOrganization';
|
||||
import { compose } from 'utils';
|
||||
|
||||
/**
|
||||
* Vendor Credit note form pages.
|
||||
*/
|
||||
export default function VendorCreditNoteFormPage() {
|
||||
function VendorCreditNoteFormPage({
|
||||
// #withCurrentOrganization
|
||||
organization: { base_currency },
|
||||
}) {
|
||||
const { id } = useParams();
|
||||
const idAsInteger = parseInt(id, 10);
|
||||
|
||||
return (
|
||||
<VendorCreditNoteFormProvider vendorCreditId={idAsInteger}>
|
||||
<VendorCreditNoteFormProvider
|
||||
vendorCreditId={idAsInteger}
|
||||
baseCurrency={base_currency}
|
||||
>
|
||||
<VendorCreditNoteForm />
|
||||
</VendorCreditNoteFormProvider>
|
||||
);
|
||||
}
|
||||
export default compose(withCurrentOrganization())(VendorCreditNoteFormPage);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React from 'react';
|
||||
import { useLocation } from 'react-router-dom';
|
||||
import { isEmpty, pick } from 'lodash';
|
||||
import { isEmpty, pick, isEqual, isUndefined } from 'lodash';
|
||||
import DashboardInsider from 'components/Dashboard/DashboardInsider';
|
||||
import { transformToEditForm } from './utils';
|
||||
import {
|
||||
@@ -20,7 +20,11 @@ const VendorCreditNoteFormContext = React.createContext();
|
||||
/**
|
||||
* Vendor Credit note data provider.
|
||||
*/
|
||||
function VendorCreditNoteFormProvider({ vendorCreditId, ...props }) {
|
||||
function VendorCreditNoteFormProvider({
|
||||
vendorCreditId,
|
||||
baseCurrency,
|
||||
...props
|
||||
}) {
|
||||
const { state } = useLocation();
|
||||
|
||||
const billId = state?.billId;
|
||||
@@ -69,6 +73,7 @@ function VendorCreditNoteFormProvider({ vendorCreditId, ...props }) {
|
||||
|
||||
// Form submit payload.
|
||||
const [submitPayload, setSubmitPayload] = React.useState();
|
||||
const [selectVendor, setSelectVendor] = React.useState(null);
|
||||
|
||||
// Create and edit vendor credit mutations.
|
||||
const { mutateAsync: createVendorCreditMutate } = useCreateVendorCredit();
|
||||
@@ -80,6 +85,11 @@ function VendorCreditNoteFormProvider({ vendorCreditId, ...props }) {
|
||||
// Determines whether the warehouse and branches are loading.
|
||||
const isFeatureLoading = isWarehouesLoading || isBranchesLoading;
|
||||
|
||||
// Determines whether the foreign vendor.
|
||||
const isForeignVendor =
|
||||
!isEqual(selectVendor?.currency_code, baseCurrency) &&
|
||||
!isUndefined(selectVendor?.currency_code);
|
||||
|
||||
const newVendorCredit = !isEmpty(bill)
|
||||
? transformToEditForm({
|
||||
...pick(bill, ['vendor_id', 'entries']),
|
||||
@@ -93,6 +103,9 @@ function VendorCreditNoteFormProvider({ vendorCreditId, ...props }) {
|
||||
vendorCredit,
|
||||
warehouses,
|
||||
branches,
|
||||
baseCurrency,
|
||||
selectVendor,
|
||||
setSelectVendor,
|
||||
submitPayload,
|
||||
isNewMode,
|
||||
newVendorCredit,
|
||||
@@ -101,7 +114,8 @@ function VendorCreditNoteFormProvider({ vendorCreditId, ...props }) {
|
||||
isFeatureLoading,
|
||||
isBranchesSuccess,
|
||||
isWarehousesSuccess,
|
||||
|
||||
isForeignVendor,
|
||||
|
||||
createVendorCreditMutate,
|
||||
editVendorCreditMutate,
|
||||
setSubmitPayload,
|
||||
|
||||
Reference in New Issue
Block a user