mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 14:50:32 +00:00
fix(invoice): foreign customer.
This commit is contained in:
@@ -57,7 +57,8 @@ function InvoiceFormHeaderFields({
|
|||||||
invoiceNextNumber,
|
invoiceNextNumber,
|
||||||
}) {
|
}) {
|
||||||
// Invoice form context.
|
// Invoice form context.
|
||||||
const { customers, isForeignCustomer } = useInvoiceFormContext();
|
const { customers, isForeignCustomer, setSelectCustomer } =
|
||||||
|
useInvoiceFormContext();
|
||||||
|
|
||||||
// Handle invoice number changing.
|
// Handle invoice number changing.
|
||||||
const handleInvoiceNumberChange = () => {
|
const handleInvoiceNumberChange = () => {
|
||||||
@@ -109,6 +110,7 @@ function InvoiceFormHeaderFields({
|
|||||||
defaultSelectText={<T id={'select_customer_account'} />}
|
defaultSelectText={<T id={'select_customer_account'} />}
|
||||||
onContactSelected={(customer) => {
|
onContactSelected={(customer) => {
|
||||||
form.setFieldValue('customer_id', customer.id);
|
form.setFieldValue('customer_id', customer.id);
|
||||||
|
setSelectCustomer(customer);
|
||||||
}}
|
}}
|
||||||
popoverFill={true}
|
popoverFill={true}
|
||||||
allowCreate={true}
|
allowCreate={true}
|
||||||
@@ -120,7 +122,7 @@ function InvoiceFormHeaderFields({
|
|||||||
</FastField>
|
</FastField>
|
||||||
|
|
||||||
{/* ----------- Exchange rate ----------- */}
|
{/* ----------- Exchange rate ----------- */}
|
||||||
<If condition={true}>
|
<If condition={isForeignCustomer}>
|
||||||
<ExchangeRateInputGroup
|
<ExchangeRateInputGroup
|
||||||
fromCurrency={'USD'}
|
fromCurrency={'USD'}
|
||||||
toCurrency={'LYD'}
|
toCurrency={'LYD'}
|
||||||
|
|||||||
@@ -5,17 +5,23 @@ import 'style/pages/SaleInvoice/PageForm.scss';
|
|||||||
|
|
||||||
import InvoiceForm from './InvoiceForm';
|
import InvoiceForm from './InvoiceForm';
|
||||||
import { InvoiceFormProvider } from './InvoiceFormProvider';
|
import { InvoiceFormProvider } from './InvoiceFormProvider';
|
||||||
|
import withCurrentOrganization from 'containers/Organization/withCurrentOrganization';
|
||||||
|
import { compose } from 'utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoice form page.
|
* Invoice form page.
|
||||||
*/
|
*/
|
||||||
export default function InvoiceFormPage() {
|
function InvoiceFormPage({
|
||||||
|
// #withCurrentOrganization
|
||||||
|
organization: { base_currency },
|
||||||
|
}) {
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
const idAsInteger = parseInt(id, 10);
|
const idAsInteger = parseInt(id, 10);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<InvoiceFormProvider invoiceId={idAsInteger}>
|
<InvoiceFormProvider invoiceId={idAsInteger} baseCurrency={base_currency}>
|
||||||
<InvoiceForm />
|
<InvoiceForm />
|
||||||
</InvoiceFormProvider>
|
</InvoiceFormProvider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
export default compose(withCurrentOrganization())(InvoiceFormPage);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { createContext, useState } from 'react';
|
import React, { createContext, useState } from 'react';
|
||||||
import { isEmpty, pick } from 'lodash';
|
import { isEmpty, pick, isEqual, isUndefined } from 'lodash';
|
||||||
import { useLocation } from 'react-router-dom';
|
import { useLocation } from 'react-router-dom';
|
||||||
import DashboardInsider from 'components/Dashboard/DashboardInsider';
|
import DashboardInsider from 'components/Dashboard/DashboardInsider';
|
||||||
import { transformToEditForm, ITEMS_FILTER_ROLES_QUERY } from './utils';
|
import { transformToEditForm, ITEMS_FILTER_ROLES_QUERY } from './utils';
|
||||||
@@ -20,7 +20,7 @@ const InvoiceFormContext = createContext();
|
|||||||
/**
|
/**
|
||||||
* Accounts chart data provider.
|
* Accounts chart data provider.
|
||||||
*/
|
*/
|
||||||
function InvoiceFormProvider({ invoiceId, ...props }) {
|
function InvoiceFormProvider({ invoiceId, baseCurrency, ...props }) {
|
||||||
const { state } = useLocation();
|
const { state } = useLocation();
|
||||||
const estimateId = state?.action;
|
const estimateId = state?.action;
|
||||||
|
|
||||||
@@ -70,6 +70,7 @@ function InvoiceFormProvider({ invoiceId, ...props }) {
|
|||||||
|
|
||||||
// Form submit payload.
|
// Form submit payload.
|
||||||
const [submitPayload, setSubmitPayload] = useState();
|
const [submitPayload, setSubmitPayload] = useState();
|
||||||
|
const [selectCustomer, setSelectCustomer] = useState(null);
|
||||||
|
|
||||||
// Detarmines whether the form in new mode.
|
// Detarmines whether the form in new mode.
|
||||||
const isNewMode = !invoiceId;
|
const isNewMode = !invoiceId;
|
||||||
@@ -78,9 +79,10 @@ function InvoiceFormProvider({ invoiceId, ...props }) {
|
|||||||
const isFeatureLoading = isWarehouesLoading || isBranchesLoading;
|
const isFeatureLoading = isWarehouesLoading || isBranchesLoading;
|
||||||
|
|
||||||
// Determines whether the foreign customer.
|
// Determines whether the foreign customer.
|
||||||
const isForeignCustomer = false;
|
const isForeignCustomer =
|
||||||
|
!isEqual(selectCustomer?.currency_code, baseCurrency) &&
|
||||||
|
!isUndefined(selectCustomer?.currency_code);
|
||||||
|
|
||||||
// Provider payload.
|
|
||||||
const provider = {
|
const provider = {
|
||||||
invoice,
|
invoice,
|
||||||
items,
|
items,
|
||||||
@@ -89,6 +91,7 @@ function InvoiceFormProvider({ invoiceId, ...props }) {
|
|||||||
estimateId,
|
estimateId,
|
||||||
invoiceId,
|
invoiceId,
|
||||||
submitPayload,
|
submitPayload,
|
||||||
|
selectCustomer,
|
||||||
branches,
|
branches,
|
||||||
warehouses,
|
warehouses,
|
||||||
|
|
||||||
@@ -104,6 +107,7 @@ function InvoiceFormProvider({ invoiceId, ...props }) {
|
|||||||
createInvoiceMutate,
|
createInvoiceMutate,
|
||||||
editInvoiceMutate,
|
editInvoiceMutate,
|
||||||
setSubmitPayload,
|
setSubmitPayload,
|
||||||
|
setSelectCustomer,
|
||||||
isNewMode,
|
isNewMode,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user