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