mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 07:10:33 +00:00
Merge branch 'currencyCode'
This commit is contained in:
@@ -39,7 +39,7 @@ const MoneyFieldCellRenderer = ({
|
|||||||
className={CLASSES.FILL}>
|
className={CLASSES.FILL}>
|
||||||
<MoneyInputGroup
|
<MoneyInputGroup
|
||||||
value={value}
|
value={value}
|
||||||
prefix={'$'}
|
// prefix={'$'}
|
||||||
onChange={handleFieldChange}
|
onChange={handleFieldChange}
|
||||||
onBlur={handleFieldBlur}
|
onBlur={handleFieldBlur}
|
||||||
{...moneyInputGroupProps}
|
{...moneyInputGroupProps}
|
||||||
|
|||||||
@@ -22,18 +22,23 @@ import { formatMessage } from 'services/intl';
|
|||||||
*/
|
*/
|
||||||
export const AmountAccessor = (r) => (
|
export const AmountAccessor = (r) => (
|
||||||
<Tooltip
|
<Tooltip
|
||||||
content={<AmountPopoverContent journalEntries={r.entries} />}
|
content={
|
||||||
|
<AmountPopoverContent
|
||||||
|
journalEntries={r.entries}
|
||||||
|
currencyCode={r.currency_code}
|
||||||
|
/>
|
||||||
|
}
|
||||||
position={Position.RIGHT_TOP}
|
position={Position.RIGHT_TOP}
|
||||||
boundary={'viewport'}
|
boundary={'viewport'}
|
||||||
>
|
>
|
||||||
<Money amount={r.amount} currency={'USD'} />
|
{r.amount_formatted}
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Amount popover content line.
|
* Amount popover content line.
|
||||||
*/
|
*/
|
||||||
export const AmountPopoverContentLine = ({ journalEntry }) => {
|
export const AmountPopoverContentLine = ({ journalEntry, currencyCode }) => {
|
||||||
const isCredit = !!journalEntry.credit;
|
const isCredit = !!journalEntry.credit;
|
||||||
const isDebit = !!journalEntry.debit;
|
const isDebit = !!journalEntry.debit;
|
||||||
const { account } = journalEntry;
|
const { account } = journalEntry;
|
||||||
@@ -42,14 +47,14 @@ export const AmountPopoverContentLine = ({ journalEntry }) => {
|
|||||||
<Choose>
|
<Choose>
|
||||||
<Choose.When condition={isDebit}>
|
<Choose.When condition={isDebit}>
|
||||||
<div>
|
<div>
|
||||||
C. <Money amount={journalEntry.debit} currency={'USD'} /> USD -{' '}
|
C. <Money amount={journalEntry.debit} currency={currencyCode} /> -{' '}
|
||||||
{account.name} <If condition={account.code}>({account.code})</If>
|
{account.name} <If condition={account.code}>({account.code})</If>
|
||||||
</div>
|
</div>
|
||||||
</Choose.When>
|
</Choose.When>
|
||||||
|
|
||||||
<Choose.When condition={isCredit}>
|
<Choose.When condition={isCredit}>
|
||||||
<div>
|
<div>
|
||||||
D. <Money amount={journalEntry.credit} currency={'USD'} /> USD -{' '}
|
D. <Money amount={journalEntry.credit} currency={currencyCode} /> -{' '}
|
||||||
{account.name} <If condition={account.code}>({account.code})</If>
|
{account.name} <If condition={account.code}>({account.code})</If>
|
||||||
</div>
|
</div>
|
||||||
</Choose.When>
|
</Choose.When>
|
||||||
@@ -60,7 +65,7 @@ export const AmountPopoverContentLine = ({ journalEntry }) => {
|
|||||||
/**
|
/**
|
||||||
* Amount popover content.
|
* Amount popover content.
|
||||||
*/
|
*/
|
||||||
export function AmountPopoverContent({ journalEntries }) {
|
export function AmountPopoverContent({ journalEntries, currencyCode }) {
|
||||||
const journalLinesProps = journalEntries.map((journalEntry) => ({
|
const journalLinesProps = journalEntries.map((journalEntry) => ({
|
||||||
journalEntry,
|
journalEntry,
|
||||||
accountId: journalEntry.account_id,
|
accountId: journalEntry.account_id,
|
||||||
@@ -72,6 +77,7 @@ export function AmountPopoverContent({ journalEntries }) {
|
|||||||
<AmountPopoverContentLine
|
<AmountPopoverContentLine
|
||||||
journalEntry={journalEntry}
|
journalEntry={journalEntry}
|
||||||
accountId={accountId}
|
accountId={accountId}
|
||||||
|
currencyCode={currencyCode}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -12,15 +12,16 @@ export default function MakeJournalEntriesField() {
|
|||||||
return (
|
return (
|
||||||
<div className={classNames(CLASSES.PAGE_FORM_BODY)}>
|
<div className={classNames(CLASSES.PAGE_FORM_BODY)}>
|
||||||
<FastField name={'entries'}>
|
<FastField name={'entries'}>
|
||||||
{({ form, field: { value }, meta: { error, touched } }) => (
|
{({ form:{values ,setFieldValue}, field: { value }, meta: { error, touched } }) => (
|
||||||
<MakeJournalEntriesTable
|
<MakeJournalEntriesTable
|
||||||
onChange={(entries) => {
|
onChange={(entries) => {
|
||||||
form.setFieldValue('entries', entries);
|
setFieldValue('entries', entries);
|
||||||
}}
|
}}
|
||||||
entries={value}
|
entries={value}
|
||||||
defaultEntry={defaultEntry}
|
defaultEntry={defaultEntry}
|
||||||
initialLinesNumber={MIN_LINES_NUMBER}
|
initialLinesNumber={MIN_LINES_NUMBER}
|
||||||
error={error}
|
error={error}
|
||||||
|
currencyCode={values.currency_code}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</FastField>
|
</FastField>
|
||||||
|
|||||||
@@ -65,10 +65,10 @@ function MakeJournalEntriesForm({
|
|||||||
}
|
}
|
||||||
: {
|
: {
|
||||||
...defaultManualJournal,
|
...defaultManualJournal,
|
||||||
...(journalAutoIncrement) && ({
|
...(journalAutoIncrement && {
|
||||||
journal_number: defaultTo(journalNumber, ''),
|
journal_number: defaultTo(journalNumber, ''),
|
||||||
}),
|
}),
|
||||||
currency_code: defaultTo(baseCurrency, ''),
|
currency_code: baseCurrency,
|
||||||
entries: orderingLinesIndexes(defaultManualJournal.entries),
|
entries: orderingLinesIndexes(defaultManualJournal.entries),
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
@@ -111,7 +111,7 @@ function MakeJournalEntriesForm({
|
|||||||
}
|
}
|
||||||
const form = {
|
const form = {
|
||||||
...omit(values, ['journal_number', 'journal_number_manually']),
|
...omit(values, ['journal_number', 'journal_number_manually']),
|
||||||
...(values.journal_number_manually) && ({
|
...(values.journal_number_manually && {
|
||||||
journal_number: values.journal_number,
|
journal_number: values.journal_number,
|
||||||
}),
|
}),
|
||||||
entries,
|
entries,
|
||||||
|
|||||||
@@ -2,12 +2,14 @@ import React from 'react';
|
|||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { useFormikContext } from 'formik';
|
import { useFormikContext } from 'formik';
|
||||||
import { CLASSES } from 'common/classes';
|
import { CLASSES } from 'common/classes';
|
||||||
import MakeJournalEntriesHeaderFields from "./MakeJournalEntriesHeaderFields";
|
import MakeJournalEntriesHeaderFields from './MakeJournalEntriesHeaderFields';
|
||||||
import { PageFormBigNumber } from 'components';
|
import { PageFormBigNumber } from 'components';
|
||||||
import { safeSumBy } from 'utils';
|
import { safeSumBy } from 'utils';
|
||||||
|
|
||||||
export default function MakeJournalEntriesHeader() {
|
export default function MakeJournalEntriesHeader() {
|
||||||
const { values: { entries } } = useFormikContext();
|
const {
|
||||||
|
values: { entries, currency_code },
|
||||||
|
} = useFormikContext();
|
||||||
const totalCredit = safeSumBy(entries, 'credit');
|
const totalCredit = safeSumBy(entries, 'credit');
|
||||||
const totalDebit = safeSumBy(entries, 'debit');
|
const totalDebit = safeSumBy(entries, 'debit');
|
||||||
|
|
||||||
@@ -20,8 +22,8 @@ export default function MakeJournalEntriesHeader() {
|
|||||||
<PageFormBigNumber
|
<PageFormBigNumber
|
||||||
label={'Due Amount'}
|
label={'Due Amount'}
|
||||||
amount={total}
|
amount={total}
|
||||||
currencyCode={'USD'}
|
currencyCode={currency_code}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ export default function MakeJournalEntriesTable({
|
|||||||
error,
|
error,
|
||||||
initialLinesNumber = 4,
|
initialLinesNumber = 4,
|
||||||
minLinesNumber = 4,
|
minLinesNumber = 4,
|
||||||
|
currencyCode,
|
||||||
}) {
|
}) {
|
||||||
const { accounts, customers } = useMakeJournalFormContext();
|
const { accounts, customers } = useMakeJournalFormContext();
|
||||||
|
|
||||||
@@ -72,7 +73,8 @@ export default function MakeJournalEntriesTable({
|
|||||||
contact_type: 'customer',
|
contact_type: 'customer',
|
||||||
})),
|
})),
|
||||||
autoFocus: ['account_id', 0],
|
autoFocus: ['account_id', 0],
|
||||||
|
currencyCode,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Intent, Position, Button, Tooltip } from '@blueprintjs/core';
|
import { Intent, Position, Button, Tooltip } from '@blueprintjs/core';
|
||||||
import { FormattedMessage as T, useIntl } from 'react-intl';
|
import { FormattedMessage as T } from 'react-intl';
|
||||||
import { Icon, Money, Hint } from 'components';
|
import { Icon, Money, Hint } from 'components';
|
||||||
|
import { formatMessage } from 'services/intl';
|
||||||
import {
|
import {
|
||||||
AccountsListFieldCell,
|
AccountsListFieldCell,
|
||||||
MoneyFieldCell,
|
MoneyFieldCell,
|
||||||
@@ -25,22 +26,36 @@ export function ContactHeaderCell() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Credit header cell.
|
||||||
|
*/
|
||||||
|
export function CreditHeaderCell({ payload: { currencyCode } }) {
|
||||||
|
return formatMessage({ id: 'credit_currency' }, { currency: currencyCode });
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* debit header cell.
|
||||||
|
*/
|
||||||
|
export function DebitHeaderCell({ payload: { currencyCode } }) {
|
||||||
|
return formatMessage({ id: 'debit_currency' }, { currency: currencyCode });
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Account footer cell.
|
* Account footer cell.
|
||||||
*/
|
*/
|
||||||
function AccountFooterCell() {
|
function AccountFooterCell({ payload: { currencyCode } }) {
|
||||||
return <span>{'Total USD'}</span>;
|
return <span>{`Total ${currencyCode} `}</span>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Total credit table footer cell.
|
* Total credit table footer cell.
|
||||||
*/
|
*/
|
||||||
function TotalCreditFooterCell({ rows }) {
|
function TotalCreditFooterCell({ payload: { currencyCode }, rows }) {
|
||||||
const credit = safeSumBy(rows, 'original.credit');
|
const credit = safeSumBy(rows, 'original.credit');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span>
|
<span>
|
||||||
<Money amount={credit} currency={'USD'} />
|
<Money amount={credit} currency={currencyCode} />
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -48,12 +63,12 @@ function TotalCreditFooterCell({ rows }) {
|
|||||||
/**
|
/**
|
||||||
* Total debit table footer cell.
|
* Total debit table footer cell.
|
||||||
*/
|
*/
|
||||||
function TotalDebitFooterCell({ rows }) {
|
function TotalDebitFooterCell({ payload: { currencyCode }, rows }) {
|
||||||
const debit = safeSumBy(rows, 'original.debit');
|
const debit = safeSumBy(rows, 'original.debit');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span>
|
<span>
|
||||||
<Money amount={debit} currency={'USD'} />
|
<Money amount={debit} currency={currencyCode} />
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -88,8 +103,6 @@ export const ActionsCellRenderer = ({
|
|||||||
* Retrieve columns of make journal entries table.
|
* Retrieve columns of make journal entries table.
|
||||||
*/
|
*/
|
||||||
export const useJournalTableEntriesColumns = () => {
|
export const useJournalTableEntriesColumns = () => {
|
||||||
const { formatMessage } = useIntl();
|
|
||||||
|
|
||||||
return React.useMemo(
|
return React.useMemo(
|
||||||
() => [
|
() => [
|
||||||
{
|
{
|
||||||
@@ -113,7 +126,7 @@ export const useJournalTableEntriesColumns = () => {
|
|||||||
width: 160,
|
width: 160,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Header: formatMessage({ id: 'credit_currency' }, { currency: 'USD' }),
|
Header: CreditHeaderCell,
|
||||||
accessor: 'credit',
|
accessor: 'credit',
|
||||||
Cell: MoneyFieldCell,
|
Cell: MoneyFieldCell,
|
||||||
Footer: TotalCreditFooterCell,
|
Footer: TotalCreditFooterCell,
|
||||||
@@ -122,7 +135,7 @@ export const useJournalTableEntriesColumns = () => {
|
|||||||
width: 100,
|
width: 100,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Header: formatMessage({ id: 'debit_currency' }, { currency: 'USD' }),
|
Header: DebitHeaderCell,
|
||||||
accessor: 'debit',
|
accessor: 'debit',
|
||||||
Cell: MoneyFieldCell,
|
Cell: MoneyFieldCell,
|
||||||
Footer: TotalDebitFooterCell,
|
Footer: TotalDebitFooterCell,
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ export function BalanceCell({ cell }) {
|
|||||||
|
|
||||||
return account.amount !== null ? (
|
return account.amount !== null ? (
|
||||||
<span>
|
<span>
|
||||||
<Money amount={account.amount} currency={'USD'} />
|
<Money amount={account.amount} currency={account.currency_code} />
|
||||||
</span>
|
</span>
|
||||||
) : (
|
) : (
|
||||||
<span class="placeholder">—</span>
|
<span class="placeholder">—</span>
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ export const useAccountsTableColumns = () => {
|
|||||||
{
|
{
|
||||||
id: 'currency',
|
id: 'currency',
|
||||||
Header: formatMessage({ id: 'currency' }),
|
Header: formatMessage({ id: 'currency' }),
|
||||||
accessor: (row) => 'USD',
|
accessor: 'currency_code',
|
||||||
width: 75,
|
width: 75,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ function ItemsEntriesTable({
|
|||||||
errors,
|
errors,
|
||||||
onUpdateData,
|
onUpdateData,
|
||||||
linesNumber,
|
linesNumber,
|
||||||
|
currencyCode,
|
||||||
itemType, // sellable or purchasable
|
itemType, // sellable or purchasable
|
||||||
}) {
|
}) {
|
||||||
const [rows, setRows] = React.useState(initialEntries);
|
const [rows, setRows] = React.useState(initialEntries);
|
||||||
@@ -35,13 +36,14 @@ function ItemsEntriesTable({
|
|||||||
const [cellsLoading, setCellsLoading] = React.useState(null);
|
const [cellsLoading, setCellsLoading] = React.useState(null);
|
||||||
|
|
||||||
// Fetches the item details.
|
// Fetches the item details.
|
||||||
const { data: item, isFetching: isItemFetching, isSuccess: isItemSuccess } = useItem(
|
const {
|
||||||
rowItem && rowItem.itemId,
|
data: item,
|
||||||
{
|
isFetching: isItemFetching,
|
||||||
enabled: !!(rowItem && rowItem.itemId),
|
isSuccess: isItemSuccess,
|
||||||
},
|
} = useItem(rowItem && rowItem.itemId, {
|
||||||
);
|
enabled: !!(rowItem && rowItem.itemId),
|
||||||
|
});
|
||||||
|
|
||||||
// Once the item start loading give the table cells loading state.
|
// Once the item start loading give the table cells loading state.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (rowItem && isItemFetching) {
|
if (rowItem && isItemFetching) {
|
||||||
@@ -141,6 +143,7 @@ function ItemsEntriesTable({
|
|||||||
updateData: handleUpdateData,
|
updateData: handleUpdateData,
|
||||||
removeRow: handleRemoveRow,
|
removeRow: handleRemoveRow,
|
||||||
autoFocus: ['item_id', 0],
|
autoFocus: ['item_id', 0],
|
||||||
|
currencyCode,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
MoneyFieldCell,
|
MoneyFieldCell,
|
||||||
ItemsListCell,
|
ItemsListCell,
|
||||||
PercentFieldCell,
|
PercentFieldCell,
|
||||||
NumericInputCell
|
NumericInputCell,
|
||||||
} from 'components/DataTableCells';
|
} from 'components/DataTableCells';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -62,27 +62,27 @@ export function ActionsCellRenderer({
|
|||||||
*/
|
*/
|
||||||
export function QuantityTotalFooterCell({ rows }) {
|
export function QuantityTotalFooterCell({ rows }) {
|
||||||
const quantity = safeSumBy(rows, 'original.quantity');
|
const quantity = safeSumBy(rows, 'original.quantity');
|
||||||
return <span>{ quantity }</span>;
|
return <span>{quantity}</span>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Total footer cell.
|
* Total footer cell.
|
||||||
*/
|
*/
|
||||||
export function TotalFooterCell({ rows }) {
|
export function TotalFooterCell({ payload: { currencyCode }, rows }) {
|
||||||
const total = safeSumBy(rows, 'original.total');
|
const total = safeSumBy(rows, 'original.total');
|
||||||
return <span>{ formattedAmount(total, 'USD') }</span>;
|
return <span>{formattedAmount(total, currencyCode)}</span>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Total accessor.
|
* Total accessor.
|
||||||
*/
|
*/
|
||||||
export function TotalCell({ value }) {
|
export function TotalCell({ payload: { currencyCode }, value }) {
|
||||||
return <span>{ formattedAmount(value, 'USD', { noZero: true }) }</span>;
|
return <span>{formattedAmount(value, currencyCode, { noZero: true })}</span>;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Index table cell.
|
// Index table cell.
|
||||||
export function IndexTableCell({ row: { index } }){
|
export function IndexTableCell({ row: { index } }) {
|
||||||
return (<span>{index + 1}</span>);
|
return <span>{index + 1}</span>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -167,4 +167,3 @@ export function useEditableItemsEntriesColumns() {
|
|||||||
[formatMessage],
|
[formatMessage],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6,20 +6,23 @@ import { defaultExpenseEntry } from './utils';
|
|||||||
/**
|
/**
|
||||||
* Expense form entries field.
|
* Expense form entries field.
|
||||||
*/
|
*/
|
||||||
export default function ExpenseFormEntriesField({
|
export default function ExpenseFormEntriesField({ linesNumber = 4 }) {
|
||||||
linesNumber = 4,
|
|
||||||
}) {
|
|
||||||
return (
|
return (
|
||||||
<FastField name={'categories'}>
|
<FastField name={'categories'}>
|
||||||
{({ form, field: { value }, meta: { error, touched } }) => (
|
{({
|
||||||
|
form: { values, setFieldValue },
|
||||||
|
field: { value },
|
||||||
|
meta: { error, touched },
|
||||||
|
}) => (
|
||||||
<ExpenseFormEntriesTable
|
<ExpenseFormEntriesTable
|
||||||
entries={value}
|
entries={value}
|
||||||
error={error}
|
error={error}
|
||||||
onChange={(entries) => {
|
onChange={(entries) => {
|
||||||
form.setFieldValue('categories', entries);
|
setFieldValue('categories', entries);
|
||||||
}}
|
}}
|
||||||
defaultEntry={defaultExpenseEntry}
|
defaultEntry={defaultExpenseEntry}
|
||||||
linesNumber={linesNumber}
|
linesNumber={linesNumber}
|
||||||
|
currencyCode={values.currency_code}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</FastField>
|
</FastField>
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ export default function ExpenseFormEntriesTable({
|
|||||||
defaultEntry,
|
defaultEntry,
|
||||||
error,
|
error,
|
||||||
onChange,
|
onChange,
|
||||||
|
currencyCode,
|
||||||
}) {
|
}) {
|
||||||
// Expense form context.
|
// Expense form context.
|
||||||
const { accounts } = useExpenseFormContext();
|
const { accounts } = useExpenseFormContext();
|
||||||
@@ -69,6 +70,7 @@ export default function ExpenseFormEntriesTable({
|
|||||||
updateData: handleUpdateData,
|
updateData: handleUpdateData,
|
||||||
removeRow: handleRemoveRow,
|
removeRow: handleRemoveRow,
|
||||||
autoFocus: ['expense_account_id', 0],
|
autoFocus: ['expense_account_id', 0],
|
||||||
|
currencyCode
|
||||||
}}
|
}}
|
||||||
footer={true}
|
footer={true}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Button, Tooltip, Intent, Position } from '@blueprintjs/core';
|
import { Button, Tooltip, Intent, Position } from '@blueprintjs/core';
|
||||||
import { FormattedMessage as T, useIntl } from 'react-intl';
|
import { FormattedMessage as T } from 'react-intl';
|
||||||
import { Icon, Hint } from 'components';
|
import { Icon, Hint } from 'components';
|
||||||
|
import { formatMessage } from 'services/intl';
|
||||||
import {
|
import {
|
||||||
InputGroupCell,
|
InputGroupCell,
|
||||||
MoneyFieldCell,
|
MoneyFieldCell,
|
||||||
@@ -51,9 +52,16 @@ const ActionsCellRenderer = ({
|
|||||||
/**
|
/**
|
||||||
* Amount footer cell.
|
* Amount footer cell.
|
||||||
*/
|
*/
|
||||||
function AmountFooterCell({ rows }) {
|
function AmountFooterCell({ payload: { currencyCode }, rows }) {
|
||||||
const total = safeSumBy(rows, 'original.amount');
|
const total = safeSumBy(rows, 'original.amount');
|
||||||
return <span>{formattedAmount(total, 'USD')}</span>;
|
return <span>{formattedAmount(total, currencyCode)}</span>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expense amount header cell.
|
||||||
|
*/
|
||||||
|
export function ExpenseAmountHeaderCell({ payload: { currencyCode } }) {
|
||||||
|
return formatMessage({ id: 'amount_currency' }, { currency: currencyCode });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -67,7 +75,6 @@ function ExpenseAccountFooterCell() {
|
|||||||
* Retrieve expense form table entries columns.
|
* Retrieve expense form table entries columns.
|
||||||
*/
|
*/
|
||||||
export function useExpenseFormTableColumns() {
|
export function useExpenseFormTableColumns() {
|
||||||
const { formatMessage } = useIntl();
|
|
||||||
|
|
||||||
return React.useMemo(
|
return React.useMemo(
|
||||||
() => [
|
() => [
|
||||||
@@ -92,7 +99,7 @@ export function useExpenseFormTableColumns() {
|
|||||||
filterAccountsByRootTypes: ['expense'],
|
filterAccountsByRootTypes: ['expense'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Header: formatMessage({ id: 'amount_currency' }, { currency: 'USD' }),
|
Header: ExpenseAmountHeaderCell,
|
||||||
accessor: 'amount',
|
accessor: 'amount',
|
||||||
Cell: MoneyFieldCell,
|
Cell: MoneyFieldCell,
|
||||||
Footer: AmountFooterCell,
|
Footer: AmountFooterCell,
|
||||||
|
|||||||
@@ -181,16 +181,16 @@ export const useItemsTableColumns = () => {
|
|||||||
{
|
{
|
||||||
id: 'sell_price',
|
id: 'sell_price',
|
||||||
Header: formatMessage({ id: 'sell_price' }),
|
Header: formatMessage({ id: 'sell_price' }),
|
||||||
Cell: SellPriceCell,
|
// Cell: SellPriceCell,
|
||||||
accessor: 'sell_price',
|
accessor: 'sell_price_formatted',
|
||||||
className: 'sell-price',
|
className: 'sell-price',
|
||||||
width: 150,
|
width: 150,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'cost_price',
|
id: 'cost_price',
|
||||||
Header: formatMessage({ id: 'cost_price' }),
|
Header: formatMessage({ id: 'cost_price' }),
|
||||||
Cell: CostPriceCell,
|
// Cell: CostPriceCell,
|
||||||
accessor: 'cost_price',
|
accessor: 'cost_price_formatted',
|
||||||
className: 'cost-price',
|
className: 'cost-price',
|
||||||
width: 150,
|
width: 150,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -17,13 +17,17 @@ import { AppToaster } from 'components';
|
|||||||
|
|
||||||
import { ERROR } from 'common/errors';
|
import { ERROR } from 'common/errors';
|
||||||
import { useBillFormContext } from './BillFormProvider';
|
import { useBillFormContext } from './BillFormProvider';
|
||||||
import { orderingLinesIndexes, safeSumBy } from 'utils';
|
import { compose, orderingLinesIndexes, safeSumBy } from 'utils';
|
||||||
import { defaultBill, transformToEditForm } from './utils';
|
import { defaultBill, transformToEditForm } from './utils';
|
||||||
|
import withSettings from 'containers/Settings/withSettings';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bill form.
|
* Bill form.
|
||||||
*/
|
*/
|
||||||
export default function BillForm() {
|
function BillForm({
|
||||||
|
// #withSettings
|
||||||
|
baseCurrency,
|
||||||
|
}) {
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
|
||||||
@@ -46,6 +50,7 @@ export default function BillForm() {
|
|||||||
: {
|
: {
|
||||||
...defaultBill,
|
...defaultBill,
|
||||||
entries: orderingLinesIndexes(defaultBill.entries),
|
entries: orderingLinesIndexes(defaultBill.entries),
|
||||||
|
currency_code: baseCurrency,
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
[bill],
|
[bill],
|
||||||
@@ -142,3 +147,8 @@ export default function BillForm() {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
export default compose(
|
||||||
|
withSettings(({ organizationSettings }) => ({
|
||||||
|
baseCurrency: organizationSettings?.baseCurrency,
|
||||||
|
})),
|
||||||
|
)(BillForm);
|
||||||
|
|||||||
@@ -11,15 +11,20 @@ export default function BillFormBody({ defaultBill }) {
|
|||||||
return (
|
return (
|
||||||
<div className={classNames(CLASSES.PAGE_FORM_BODY)}>
|
<div className={classNames(CLASSES.PAGE_FORM_BODY)}>
|
||||||
<FastField name={'entries'}>
|
<FastField name={'entries'}>
|
||||||
{({ form, field: { value }, meta: { error, touched } }) => (
|
{({
|
||||||
|
form: { values, setFieldValue },
|
||||||
|
field: { value },
|
||||||
|
meta: { error, touched },
|
||||||
|
}) => (
|
||||||
<ItemsEntriesTable
|
<ItemsEntriesTable
|
||||||
entries={value}
|
entries={value}
|
||||||
onUpdateData={(entries) => {
|
onUpdateData={(entries) => {
|
||||||
form.setFieldValue('entries', entries);
|
setFieldValue('entries', entries);
|
||||||
}}
|
}}
|
||||||
items={items}
|
items={items}
|
||||||
errors={error}
|
errors={error}
|
||||||
linesNumber={4}
|
linesNumber={4}
|
||||||
|
currencyCode={values.currency_code}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</FastField>
|
</FastField>
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import { useFormikContext } from 'formik';
|
|||||||
export default function PaymentMadeEntriesTable({
|
export default function PaymentMadeEntriesTable({
|
||||||
onUpdateData,
|
onUpdateData,
|
||||||
entries,
|
entries,
|
||||||
|
currencyCode,
|
||||||
}) {
|
}) {
|
||||||
// Payment made inner context.
|
// Payment made inner context.
|
||||||
const { isNewEntriesFetching } = usePaymentMadeInnerContext();
|
const { isNewEntriesFetching } = usePaymentMadeInnerContext();
|
||||||
@@ -24,7 +25,9 @@ export default function PaymentMadeEntriesTable({
|
|||||||
const columns = usePaymentMadeEntriesTableColumns();
|
const columns = usePaymentMadeEntriesTableColumns();
|
||||||
|
|
||||||
// Formik context.
|
// Formik context.
|
||||||
const { values: { vendor_id } } = useFormikContext();
|
const {
|
||||||
|
values: { vendor_id },
|
||||||
|
} = useFormikContext();
|
||||||
|
|
||||||
// Handle update data.
|
// Handle update data.
|
||||||
const handleUpdateData = useCallback(
|
const handleUpdateData = useCallback(
|
||||||
@@ -54,10 +57,11 @@ export default function PaymentMadeEntriesTable({
|
|||||||
payload={{
|
payload={{
|
||||||
errors: [],
|
errors: [],
|
||||||
updateData: handleUpdateData,
|
updateData: handleUpdateData,
|
||||||
|
currencyCode,
|
||||||
}}
|
}}
|
||||||
noResults={noResultsMessage}
|
noResults={noResultsMessage}
|
||||||
footer={true}
|
footer={true}
|
||||||
/>
|
/>
|
||||||
</CloudLoadingIndicator>
|
</CloudLoadingIndicator>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import { defaultPaymentMade, transformToEditForm, ERRORS } from './utils';
|
|||||||
function PaymentMadeForm({
|
function PaymentMadeForm({
|
||||||
// #withSettings
|
// #withSettings
|
||||||
preferredPaymentAccount,
|
preferredPaymentAccount,
|
||||||
|
baseCurrency,
|
||||||
}) {
|
}) {
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
@@ -54,6 +55,7 @@ function PaymentMadeForm({
|
|||||||
: {
|
: {
|
||||||
...defaultPaymentMade,
|
...defaultPaymentMade,
|
||||||
payment_account_id: defaultTo(preferredPaymentAccount),
|
payment_account_id: defaultTo(preferredPaymentAccount),
|
||||||
|
currency_code: baseCurrency,
|
||||||
entries: orderingLinesIndexes(defaultPaymentMade.entries),
|
entries: orderingLinesIndexes(defaultPaymentMade.entries),
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
@@ -157,9 +159,10 @@ function PaymentMadeForm({
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default compose(
|
export default compose(
|
||||||
withSettings(({ billPaymentSettings }) => ({
|
withSettings(({ billPaymentSettings, organizationSettings }) => ({
|
||||||
paymentNextNumber: billPaymentSettings?.next_number,
|
paymentNextNumber: billPaymentSettings?.next_number,
|
||||||
paymentNumberPrefix: billPaymentSettings?.number_prefix,
|
paymentNumberPrefix: billPaymentSettings?.number_prefix,
|
||||||
preferredPaymentAccount: parseInt(billPaymentSettings?.withdrawalAccount),
|
preferredPaymentAccount: parseInt(billPaymentSettings?.withdrawalAccount),
|
||||||
|
baseCurrency: organizationSettings?.baseCurrency,
|
||||||
})),
|
})),
|
||||||
)(PaymentMadeForm);
|
)(PaymentMadeForm);
|
||||||
|
|||||||
@@ -5,18 +5,23 @@ import { CLASSES } from 'common/classes';
|
|||||||
import PaymentMadeEntriesTable from './PaymentMadeEntriesTable';
|
import PaymentMadeEntriesTable from './PaymentMadeEntriesTable';
|
||||||
|
|
||||||
export default function PaymentMadeFormBody() {
|
export default function PaymentMadeFormBody() {
|
||||||
return (
|
return (
|
||||||
<div className={classNames(CLASSES.PAGE_FORM_BODY)}>
|
<div className={classNames(CLASSES.PAGE_FORM_BODY)}>
|
||||||
<FastField name={'entries'}>
|
<FastField name={'entries'}>
|
||||||
{({ form, field: { value }, meta: { error, touched } }) => (
|
{({
|
||||||
<PaymentMadeEntriesTable
|
form: { setFieldValue, values },
|
||||||
|
field: { value },
|
||||||
|
meta: { error, touched },
|
||||||
|
}) => (
|
||||||
|
<PaymentMadeEntriesTable
|
||||||
entries={value}
|
entries={value}
|
||||||
onUpdateData={(newEntries) => {
|
onUpdateData={(newEntries) => {
|
||||||
form.setFieldValue('entries', newEntries);
|
setFieldValue('entries', newEntries);
|
||||||
}}
|
}}
|
||||||
|
currencyCode={values.currency_code}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</FastField>
|
</FastField>
|
||||||
</div>
|
</div>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { useIntl } from "react-intl";
|
import { useIntl } from 'react-intl';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import { Money } from 'components';
|
import { Money } from 'components';
|
||||||
import { safeSumBy, formattedAmount } from 'utils';
|
import { safeSumBy, formattedAmount } from 'utils';
|
||||||
@@ -10,7 +10,7 @@ function BillNumberAccessor(row) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function IndexTableCell({ row: { index } }) {
|
function IndexTableCell({ row: { index } }) {
|
||||||
return (<span>{index + 1}</span>);
|
return <span>{index + 1}</span>;
|
||||||
}
|
}
|
||||||
|
|
||||||
function BillDateCell({ value }) {
|
function BillDateCell({ value }) {
|
||||||
@@ -19,35 +19,34 @@ function BillDateCell({ value }) {
|
|||||||
/**
|
/**
|
||||||
* Balance footer cell.
|
* Balance footer cell.
|
||||||
*/
|
*/
|
||||||
function AmountFooterCell({ rows }) {
|
function AmountFooterCell({ payload: { currencyCode }, rows }) {
|
||||||
const total = safeSumBy(rows, 'original.amount');
|
const total = safeSumBy(rows, 'original.amount');
|
||||||
return <span>{ formattedAmount(total, 'USD') }</span>;
|
return <span>{formattedAmount(total, currencyCode)}</span>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Due amount footer cell.
|
* Due amount footer cell.
|
||||||
*/
|
*/
|
||||||
function DueAmountFooterCell({ rows }) {
|
function DueAmountFooterCell({ payload: { currencyCode }, rows }) {
|
||||||
const totalDueAmount = safeSumBy(rows, 'original.due_amount');
|
const totalDueAmount = safeSumBy(rows, 'original.due_amount');
|
||||||
return <span>{ formattedAmount(totalDueAmount, 'USD') }</span>;
|
return <span>{formattedAmount(totalDueAmount, currencyCode)}</span>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Payment amount footer cell.
|
* Payment amount footer cell.
|
||||||
*/
|
*/
|
||||||
function PaymentAmountFooterCell({ rows }) {
|
function PaymentAmountFooterCell({ payload: { currencyCode }, rows }) {
|
||||||
const totalPaymentAmount = safeSumBy(rows, 'original.payment_amount');
|
const totalPaymentAmount = safeSumBy(rows, 'original.payment_amount');
|
||||||
return <span>{ formattedAmount(totalPaymentAmount, 'USD') }</span>;
|
return <span>{formattedAmount(totalPaymentAmount, currencyCode)}</span>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mobey table cell.
|
* Mobey table cell.
|
||||||
*/
|
*/
|
||||||
function MoneyTableCell({ value }) {
|
function MoneyTableCell({ row: { original }, value }) {
|
||||||
return <Money amount={value} currency={"USD"} />
|
return <Money amount={value} currency={original.currency_code} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Payment made entries table columns
|
* Payment made entries table columns
|
||||||
*/
|
*/
|
||||||
@@ -63,7 +62,7 @@ export function usePaymentMadeEntriesTableColumns() {
|
|||||||
width: 40,
|
width: 40,
|
||||||
disableResizing: true,
|
disableResizing: true,
|
||||||
disableSortBy: true,
|
disableSortBy: true,
|
||||||
className: 'index'
|
className: 'index',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Header: formatMessage({ id: 'Date' }),
|
Header: formatMessage({ id: 'Date' }),
|
||||||
@@ -106,5 +105,5 @@ export function usePaymentMadeEntriesTableColumns() {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
[formatMessage],
|
[formatMessage],
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ export const defaultPaymentMadeEntry = {
|
|||||||
currency_code:'',
|
currency_code:'',
|
||||||
id: null,
|
id: null,
|
||||||
due_amount: null,
|
due_amount: null,
|
||||||
|
amount:''
|
||||||
};
|
};
|
||||||
|
|
||||||
// Default initial values of payment made.
|
// Default initial values of payment made.
|
||||||
@@ -46,5 +47,7 @@ export const transformToNewPageEntries = (entries) => {
|
|||||||
return entries.map((entry) => ({
|
return entries.map((entry) => ({
|
||||||
...transformToForm(entry, defaultPaymentMadeEntry),
|
...transformToForm(entry, defaultPaymentMadeEntry),
|
||||||
payment_amount: '',
|
payment_amount: '',
|
||||||
|
currency_code:entry.currency_code,
|
||||||
|
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@@ -34,6 +34,7 @@ function EstimateForm({
|
|||||||
estimateNextNumber,
|
estimateNextNumber,
|
||||||
estimateNumberPrefix,
|
estimateNumberPrefix,
|
||||||
estimateIncrementMode,
|
estimateIncrementMode,
|
||||||
|
baseCurrency,
|
||||||
}) {
|
}) {
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
@@ -57,10 +58,11 @@ function EstimateForm({
|
|||||||
? { ...transformToEditForm(estimate) }
|
? { ...transformToEditForm(estimate) }
|
||||||
: {
|
: {
|
||||||
...defaultEstimate,
|
...defaultEstimate,
|
||||||
...(estimateIncrementMode) && ({
|
...(estimateIncrementMode && {
|
||||||
estimate_number: estimateNumber,
|
estimate_number: estimateNumber,
|
||||||
}),
|
}),
|
||||||
entries: orderingLinesIndexes(defaultEstimate.entries),
|
entries: orderingLinesIndexes(defaultEstimate.entries),
|
||||||
|
currency_code: baseCurrency,
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
[estimate, estimateNumber, estimateIncrementMode],
|
[estimate, estimateNumber, estimateIncrementMode],
|
||||||
@@ -101,7 +103,7 @@ function EstimateForm({
|
|||||||
}
|
}
|
||||||
const form = {
|
const form = {
|
||||||
...omit(values, ['estimate_number_manually', 'estimate_number']),
|
...omit(values, ['estimate_number_manually', 'estimate_number']),
|
||||||
...(values.estimate_number_manually) && ({
|
...(values.estimate_number_manually && {
|
||||||
estimate_number: values.estimate_number,
|
estimate_number: values.estimate_number,
|
||||||
}),
|
}),
|
||||||
delivered: submitPayload.deliver,
|
delivered: submitPayload.deliver,
|
||||||
@@ -175,9 +177,10 @@ function EstimateForm({
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default compose(
|
export default compose(
|
||||||
withSettings(({ estimatesSettings }) => ({
|
withSettings(({ estimatesSettings, organizationSettings }) => ({
|
||||||
estimateNextNumber: estimatesSettings?.nextNumber,
|
estimateNextNumber: estimatesSettings?.nextNumber,
|
||||||
estimateNumberPrefix: estimatesSettings?.numberPrefix,
|
estimateNumberPrefix: estimatesSettings?.numberPrefix,
|
||||||
estimateIncrementMode: estimatesSettings?.autoIncrement,
|
estimateIncrementMode: estimatesSettings?.autoIncrement,
|
||||||
|
baseCurrency: organizationSettings?.baseCurrency,
|
||||||
})),
|
})),
|
||||||
)(EstimateForm);
|
)(EstimateForm);
|
||||||
|
|||||||
@@ -14,15 +14,20 @@ export default function EstimateFormItemsEntriesField() {
|
|||||||
return (
|
return (
|
||||||
<div className={classNames(CLASSES.PAGE_FORM_BODY)}>
|
<div className={classNames(CLASSES.PAGE_FORM_BODY)}>
|
||||||
<FastField name={'entries'}>
|
<FastField name={'entries'}>
|
||||||
{({ form, field: { value }, meta: { error, touched } }) => (
|
{({
|
||||||
|
form: { values, setFieldValue },
|
||||||
|
field: { value },
|
||||||
|
meta: { error, touched },
|
||||||
|
}) => (
|
||||||
<ItemsEntriesTable
|
<ItemsEntriesTable
|
||||||
entries={value}
|
entries={value}
|
||||||
onUpdateData={(entries) => {
|
onUpdateData={(entries) => {
|
||||||
form.setFieldValue('entries', entries);
|
setFieldValue('entries', entries);
|
||||||
}}
|
}}
|
||||||
items={items}
|
items={items}
|
||||||
errors={error}
|
errors={error}
|
||||||
linesNumber={4}
|
linesNumber={4}
|
||||||
|
currencyCode={values.currency_code}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</FastField>
|
</FastField>
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ function InvoiceForm({
|
|||||||
invoiceNextNumber,
|
invoiceNextNumber,
|
||||||
invoiceNumberPrefix,
|
invoiceNumberPrefix,
|
||||||
invoiceIncrementMode,
|
invoiceIncrementMode,
|
||||||
|
baseCurrency,
|
||||||
}) {
|
}) {
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
@@ -61,11 +62,12 @@ function InvoiceForm({
|
|||||||
? transformToEditForm(invoice)
|
? transformToEditForm(invoice)
|
||||||
: {
|
: {
|
||||||
...defaultInvoice,
|
...defaultInvoice,
|
||||||
...(invoiceIncrementMode) && ({
|
...(invoiceIncrementMode && {
|
||||||
invoice_no: invoiceNumber,
|
invoice_no: invoiceNumber,
|
||||||
}),
|
}),
|
||||||
entries: orderingLinesIndexes(defaultInvoice.entries),
|
entries: orderingLinesIndexes(defaultInvoice.entries),
|
||||||
...newInvoice,
|
...newInvoice,
|
||||||
|
currency_code: baseCurrency,
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
[invoice, newInvoice, invoiceNumber, invoiceIncrementMode],
|
[invoice, newInvoice, invoiceNumber, invoiceIncrementMode],
|
||||||
@@ -91,7 +93,7 @@ function InvoiceForm({
|
|||||||
}
|
}
|
||||||
const form = {
|
const form = {
|
||||||
...omit(values, ['invoice_no', 'invoice_no_manually']),
|
...omit(values, ['invoice_no', 'invoice_no_manually']),
|
||||||
...(values.invoice_no_manually) && ({
|
...(values.invoice_no_manually && {
|
||||||
invoice_no: values.invoice_no,
|
invoice_no: values.invoice_no,
|
||||||
}),
|
}),
|
||||||
delivered: submitPayload.deliver,
|
delivered: submitPayload.deliver,
|
||||||
@@ -169,9 +171,10 @@ function InvoiceForm({
|
|||||||
export default compose(
|
export default compose(
|
||||||
withDashboardActions,
|
withDashboardActions,
|
||||||
withMediaActions,
|
withMediaActions,
|
||||||
withSettings(({ invoiceSettings }) => ({
|
withSettings(({ invoiceSettings, organizationSettings }) => ({
|
||||||
invoiceNextNumber: invoiceSettings?.nextNumber,
|
invoiceNextNumber: invoiceSettings?.nextNumber,
|
||||||
invoiceNumberPrefix: invoiceSettings?.numberPrefix,
|
invoiceNumberPrefix: invoiceSettings?.numberPrefix,
|
||||||
invoiceIncrementMode: invoiceSettings?.incrementMode,
|
invoiceIncrementMode: invoiceSettings?.incrementMode,
|
||||||
|
baseCurrency: organizationSettings?.baseCurrency,
|
||||||
})),
|
})),
|
||||||
)(InvoiceForm);
|
)(InvoiceForm);
|
||||||
|
|||||||
@@ -14,15 +14,20 @@ export default function InvoiceItemsEntriesEditorField() {
|
|||||||
return (
|
return (
|
||||||
<div className={classNames(CLASSES.PAGE_FORM_BODY)}>
|
<div className={classNames(CLASSES.PAGE_FORM_BODY)}>
|
||||||
<FastField name={'entries'}>
|
<FastField name={'entries'}>
|
||||||
{({ form, field: { value }, meta: { error, touched } }) => (
|
{({
|
||||||
|
form: { values, setFieldValue },
|
||||||
|
field: { value },
|
||||||
|
meta: { error, touched },
|
||||||
|
}) => (
|
||||||
<ItemsEntriesTable
|
<ItemsEntriesTable
|
||||||
entries={value}
|
entries={value}
|
||||||
onUpdateData={(entries) => {
|
onUpdateData={(entries) => {
|
||||||
form.setFieldValue('entries', entries);
|
setFieldValue('entries', entries);
|
||||||
}}
|
}}
|
||||||
items={items}
|
items={items}
|
||||||
errors={error}
|
errors={error}
|
||||||
linesNumber={4}
|
linesNumber={4}
|
||||||
|
currencyCode={values.currency_code}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</FastField>
|
</FastField>
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ function PaymentReceiveForm({
|
|||||||
paymentReceiveNextNumber,
|
paymentReceiveNextNumber,
|
||||||
paymentReceiveNumberPrefix,
|
paymentReceiveNumberPrefix,
|
||||||
paymentReceiveAutoIncrement,
|
paymentReceiveAutoIncrement,
|
||||||
|
baseCurrency,
|
||||||
}) {
|
}) {
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
@@ -68,6 +69,7 @@ function PaymentReceiveForm({
|
|||||||
payment_receive_no: nextPaymentNumber,
|
payment_receive_no: nextPaymentNumber,
|
||||||
deposit_account_id: defaultTo(preferredDepositAccount, ''),
|
deposit_account_id: defaultTo(preferredDepositAccount, ''),
|
||||||
}),
|
}),
|
||||||
|
currency_code: baseCurrency,
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
[
|
[
|
||||||
@@ -199,11 +201,12 @@ function PaymentReceiveForm({
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default compose(
|
export default compose(
|
||||||
withSettings(({ paymentReceiveSettings }) => ({
|
withSettings(({ paymentReceiveSettings, organizationSettings }) => ({
|
||||||
paymentReceiveSettings,
|
paymentReceiveSettings,
|
||||||
paymentReceiveNextNumber: paymentReceiveSettings?.nextNumber,
|
paymentReceiveNextNumber: paymentReceiveSettings?.nextNumber,
|
||||||
paymentReceiveNumberPrefix: paymentReceiveSettings?.numberPrefix,
|
paymentReceiveNumberPrefix: paymentReceiveSettings?.numberPrefix,
|
||||||
paymentReceiveAutoIncrement: paymentReceiveSettings?.autoIncrement,
|
paymentReceiveAutoIncrement: paymentReceiveSettings?.autoIncrement,
|
||||||
preferredDepositAccount: paymentReceiveSettings?.depositAccount,
|
preferredDepositAccount: paymentReceiveSettings?.depositAccount,
|
||||||
|
baseCurrency: organizationSettings?.baseCurrency,
|
||||||
})),
|
})),
|
||||||
)(PaymentReceiveForm);
|
)(PaymentReceiveForm);
|
||||||
|
|||||||
@@ -11,12 +11,13 @@ export default function PaymentReceiveFormBody() {
|
|||||||
return (
|
return (
|
||||||
<div className={classNames(CLASSES.PAGE_FORM_BODY)}>
|
<div className={classNames(CLASSES.PAGE_FORM_BODY)}>
|
||||||
<FastField name={'entries'}>
|
<FastField name={'entries'}>
|
||||||
{({ form, field: { value } }) => (
|
{({ form: { values, setFieldValue }, field: { value } }) => (
|
||||||
<PaymentReceiveItemsTable
|
<PaymentReceiveItemsTable
|
||||||
entries={value}
|
entries={value}
|
||||||
onUpdateData={(newEntries) => {
|
onUpdateData={(newEntries) => {
|
||||||
form.setFieldValue('entries', newEntries);
|
setFieldValue('entries', newEntries);
|
||||||
}}
|
}}
|
||||||
|
currencyCode={values.currency_code}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</FastField>
|
</FastField>
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import { compose, updateTableRow } from 'utils';
|
|||||||
export default function PaymentReceiveItemsTable({
|
export default function PaymentReceiveItemsTable({
|
||||||
entries,
|
entries,
|
||||||
onUpdateData,
|
onUpdateData,
|
||||||
|
currencyCode
|
||||||
}) {
|
}) {
|
||||||
// Payment receive form context.
|
// Payment receive form context.
|
||||||
const {
|
const {
|
||||||
@@ -52,6 +53,7 @@ export default function PaymentReceiveItemsTable({
|
|||||||
payload={{
|
payload={{
|
||||||
errors: [],
|
errors: [],
|
||||||
updateData: handleUpdateData,
|
updateData: handleUpdateData,
|
||||||
|
currencyCode
|
||||||
}}
|
}}
|
||||||
noResults={noResultsMessage}
|
noResults={noResultsMessage}
|
||||||
footer={true}
|
footer={true}
|
||||||
|
|||||||
@@ -9,14 +9,14 @@ import { safeSumBy, formattedAmount } from 'utils';
|
|||||||
* Invoice date cell.
|
* Invoice date cell.
|
||||||
*/
|
*/
|
||||||
function InvoiceDateCell({ value }) {
|
function InvoiceDateCell({ value }) {
|
||||||
return <span>{ moment(value).format('YYYY MMM DD') }</span>
|
return <span>{moment(value).format('YYYY MMM DD')}</span>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Index table cell.
|
* Index table cell.
|
||||||
*/
|
*/
|
||||||
function IndexCell({ row: { index } }) {
|
function IndexCell({ row: { index } }) {
|
||||||
return (<span>{index + 1}</span>);
|
return <span>{index + 1}</span>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -29,33 +29,32 @@ function InvNumberCellAccessor(row) {
|
|||||||
/**
|
/**
|
||||||
* Balance footer cell.
|
* Balance footer cell.
|
||||||
*/
|
*/
|
||||||
function BalanceFooterCell({ rows }) {
|
function BalanceFooterCell({ payload: { currencyCode }, rows }) {
|
||||||
const total = safeSumBy(rows, 'original.amount');
|
const total = safeSumBy(rows, 'original.amount');
|
||||||
return <span>{ formattedAmount(total, 'USD') }</span>;
|
return <span>{formattedAmount(total, currencyCode)}</span>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Due amount footer cell.
|
* Due amount footer cell.
|
||||||
*/
|
*/
|
||||||
function DueAmountFooterCell({ rows }) {
|
function DueAmountFooterCell({ payload: { currencyCode }, rows }) {
|
||||||
const totalDueAmount = safeSumBy(rows, 'original.due_amount');
|
const totalDueAmount = safeSumBy(rows, 'original.due_amount');
|
||||||
return <span>{ formattedAmount(totalDueAmount, 'USD') }</span>;
|
return <span>{formattedAmount(totalDueAmount, currencyCode)}</span>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Payment amount footer cell.
|
* Payment amount footer cell.
|
||||||
*/
|
*/
|
||||||
function PaymentAmountFooterCell({ rows }) {
|
function PaymentAmountFooterCell({ payload: { currencyCode }, rows }) {
|
||||||
const totalPaymentAmount = safeSumBy(rows, 'original.payment_amount');
|
const totalPaymentAmount = safeSumBy(rows, 'original.payment_amount');
|
||||||
return <span>{ formattedAmount(totalPaymentAmount, 'USD') }</span>;
|
return <span>{formattedAmount(totalPaymentAmount, currencyCode)}</span>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mobey table cell.
|
* Mobey table cell.
|
||||||
*/
|
*/
|
||||||
function MoneyTableCell({ value }) {
|
function MoneyTableCell({ row: { original }, value }) {
|
||||||
return <Money amount={value} currency={"USD"} />
|
return <Money amount={value} currency={original.currency_code} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
function DateFooterCell() {
|
function DateFooterCell() {
|
||||||
@@ -77,7 +76,7 @@ export const usePaymentReceiveEntriesColumns = () => {
|
|||||||
width: 40,
|
width: 40,
|
||||||
disableResizing: true,
|
disableResizing: true,
|
||||||
disableSortBy: true,
|
disableSortBy: true,
|
||||||
className: 'index'
|
className: 'index',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Header: formatMessage({ id: 'Date' }),
|
Header: formatMessage({ id: 'Date' }),
|
||||||
@@ -88,7 +87,7 @@ export const usePaymentReceiveEntriesColumns = () => {
|
|||||||
disableSortBy: true,
|
disableSortBy: true,
|
||||||
disableResizing: true,
|
disableResizing: true,
|
||||||
width: 250,
|
width: 250,
|
||||||
className: 'date'
|
className: 'date',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Header: formatMessage({ id: 'invocie_number' }),
|
Header: formatMessage({ id: 'invocie_number' }),
|
||||||
@@ -125,5 +124,5 @@ export const usePaymentReceiveEntriesColumns = () => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
[formatMessage],
|
[formatMessage],
|
||||||
)
|
);
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ export const transformInvoicesNewPageEntries = (invoices) => [
|
|||||||
due_amount: invoice.due_amount,
|
due_amount: invoice.due_amount,
|
||||||
date: invoice.invoice_date,
|
date: invoice.invoice_date,
|
||||||
amount: invoice.balance,
|
amount: invoice.balance,
|
||||||
|
currency_code:invoice.currency_code,
|
||||||
payment_amount: '',
|
payment_amount: '',
|
||||||
invoice_no: invoice.invoice_no,
|
invoice_no: invoice.invoice_no,
|
||||||
total_payment_amount: invoice.payment_amount,
|
total_payment_amount: invoice.payment_amount,
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ function ReceiptForm({
|
|||||||
receiptNumberPrefix,
|
receiptNumberPrefix,
|
||||||
receiptAutoIncrement,
|
receiptAutoIncrement,
|
||||||
preferredDepositAccount,
|
preferredDepositAccount,
|
||||||
|
baseCurrency,
|
||||||
}) {
|
}) {
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
@@ -67,6 +68,7 @@ function ReceiptForm({
|
|||||||
}),
|
}),
|
||||||
deposit_account_id: parseInt(preferredDepositAccount),
|
deposit_account_id: parseInt(preferredDepositAccount),
|
||||||
entries: orderingLinesIndexes(defaultReceipt.entries),
|
entries: orderingLinesIndexes(defaultReceipt.entries),
|
||||||
|
currency_code: baseCurrency,
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
[receipt, preferredDepositAccount, nextReceiptNumber, receiptAutoIncrement],
|
[receipt, preferredDepositAccount, nextReceiptNumber, receiptAutoIncrement],
|
||||||
@@ -105,8 +107,9 @@ function ReceiptForm({
|
|||||||
}
|
}
|
||||||
const form = {
|
const form = {
|
||||||
...omit(values, ['receipt_number_manually', 'receipt_number']),
|
...omit(values, ['receipt_number_manually', 'receipt_number']),
|
||||||
...(values.receipt_number_manually) && ({
|
...(values.receipt_number_manually && {
|
||||||
receipt_number: values.receipt_number,
|
receipt_number: values.receipt_number,
|
||||||
|
currency_code: baseCurrency,
|
||||||
}),
|
}),
|
||||||
closed: submitPayload.status,
|
closed: submitPayload.status,
|
||||||
entries: entries.map((entry) => ({ ...omit(entry, ['total']) })),
|
entries: entries.map((entry) => ({ ...omit(entry, ['total']) })),
|
||||||
@@ -182,10 +185,11 @@ function ReceiptForm({
|
|||||||
|
|
||||||
export default compose(
|
export default compose(
|
||||||
withDashboardActions,
|
withDashboardActions,
|
||||||
withSettings(({ receiptSettings }) => ({
|
withSettings(({ receiptSettings, organizationSettings }) => ({
|
||||||
receiptNextNumber: receiptSettings?.nextNumber,
|
receiptNextNumber: receiptSettings?.nextNumber,
|
||||||
receiptNumberPrefix: receiptSettings?.numberPrefix,
|
receiptNumberPrefix: receiptSettings?.numberPrefix,
|
||||||
receiptAutoIncrement: receiptSettings?.autoIncrement,
|
receiptAutoIncrement: receiptSettings?.autoIncrement,
|
||||||
preferredDepositAccount: receiptSettings?.preferredDepositAccount,
|
preferredDepositAccount: receiptSettings?.preferredDepositAccount,
|
||||||
|
baseCurrency: organizationSettings?.baseCurrency,
|
||||||
})),
|
})),
|
||||||
)(ReceiptForm);
|
)(ReceiptForm);
|
||||||
|
|||||||
@@ -11,15 +11,20 @@ export default function ReceiptItemsEntriesEditor({ defaultReceipt }) {
|
|||||||
return (
|
return (
|
||||||
<div className={classNames(CLASSES.PAGE_FORM_BODY)}>
|
<div className={classNames(CLASSES.PAGE_FORM_BODY)}>
|
||||||
<FastField name={'entries'}>
|
<FastField name={'entries'}>
|
||||||
{({ form, field: { value }, meta: { error, touched } }) => (
|
{({
|
||||||
|
form: { values, setFieldValue },
|
||||||
|
field: { value },
|
||||||
|
meta: { error, touched },
|
||||||
|
}) => (
|
||||||
<ItemsEntriesTable
|
<ItemsEntriesTable
|
||||||
entries={value}
|
entries={value}
|
||||||
onUpdateData={(entries) => {
|
onUpdateData={(entries) => {
|
||||||
form.setFieldValue('entries', entries);
|
setFieldValue('entries', entries);
|
||||||
}}
|
}}
|
||||||
items={items}
|
items={items}
|
||||||
errors={error}
|
errors={error}
|
||||||
linesNumber={4}
|
linesNumber={4}
|
||||||
|
currencyCode={values.currency_code}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</FastField>
|
</FastField>
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ function VendorForm({
|
|||||||
const initialValues = useMemo(
|
const initialValues = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
...defaultInitialValues,
|
...defaultInitialValues,
|
||||||
|
currency_code: baseCurrency,
|
||||||
...transformToForm(vendor, defaultInitialValues),
|
...transformToForm(vendor, defaultInitialValues),
|
||||||
...transformToForm(contactDuplicate, defaultInitialValues),
|
...transformToForm(contactDuplicate, defaultInitialValues),
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -324,7 +324,9 @@ export default class ItemsController extends BaseController {
|
|||||||
try {
|
try {
|
||||||
const storedItem = await this.itemsService.getItem(tenantId, itemId);
|
const storedItem = await this.itemsService.getItem(tenantId, itemId);
|
||||||
|
|
||||||
return res.status(200).send({ item: storedItem });
|
return res.status(200).send({
|
||||||
|
item: this.transfromToResponse(storedItem)
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
}
|
}
|
||||||
@@ -356,7 +358,7 @@ export default class ItemsController extends BaseController {
|
|||||||
} = await this.itemsService.itemsList(tenantId, filter);
|
} = await this.itemsService.itemsList(tenantId, filter);
|
||||||
|
|
||||||
return res.status(200).send({
|
return res.status(200).send({
|
||||||
items,
|
items: this.transfromToResponse(items),
|
||||||
pagination: this.transfromToResponse(pagination),
|
pagination: this.transfromToResponse(pagination),
|
||||||
filter_meta: this.transfromToResponse(filterMeta),
|
filter_meta: this.transfromToResponse(filterMeta),
|
||||||
});
|
});
|
||||||
@@ -390,7 +392,7 @@ export default class ItemsController extends BaseController {
|
|||||||
filter
|
filter
|
||||||
);
|
);
|
||||||
return res.status(200).send({
|
return res.status(200).send({
|
||||||
items,
|
items: this.transfromToResponse(items),
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ exports.up = function(knex) {
|
|||||||
table.string('reference').index();
|
table.string('reference').index();
|
||||||
table.string('journal_type').index();
|
table.string('journal_type').index();
|
||||||
table.decimal('amount', 13, 3);
|
table.decimal('amount', 13, 3);
|
||||||
|
table.string('currency_code', 3);
|
||||||
table.date('date').index();
|
table.date('date').index();
|
||||||
table.string('description');
|
table.string('description');
|
||||||
table.date('published_at').index();
|
table.date('published_at').index();
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ export interface IManualJournal {
|
|||||||
journalType: string;
|
journalType: string;
|
||||||
reference: string;
|
reference: string;
|
||||||
amount: number;
|
amount: number;
|
||||||
|
currencyCode: string;
|
||||||
publishedAt: Date | null;
|
publishedAt: Date | null;
|
||||||
description: string;
|
description: string;
|
||||||
userId: number;
|
userId: number;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Model } from 'objection';
|
import { Model } from 'objection';
|
||||||
import TenantModel from 'models/TenantModel';
|
import TenantModel from 'models/TenantModel';
|
||||||
import { query } from 'winston';
|
import { formatNumber } from 'utils';
|
||||||
|
|
||||||
export default class ManualJournal extends TenantModel {
|
export default class ManualJournal extends TenantModel {
|
||||||
/**
|
/**
|
||||||
@@ -21,7 +21,14 @@ export default class ManualJournal extends TenantModel {
|
|||||||
* Virtual attributes.
|
* Virtual attributes.
|
||||||
*/
|
*/
|
||||||
static get virtualAttributes() {
|
static get virtualAttributes() {
|
||||||
return ['isPublished'];
|
return ['isPublished', 'amountFormatted'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the amount formatted value.
|
||||||
|
*/
|
||||||
|
get amountFormatted() {
|
||||||
|
return formatNumber(this.amount, { currencyCode: this.currencyCode });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import {
|
|||||||
ACCOUNT_TYPE,
|
ACCOUNT_TYPE,
|
||||||
} from 'data/AccountTypes';
|
} from 'data/AccountTypes';
|
||||||
import { ERRORS } from './constants';
|
import { ERRORS } from './constants';
|
||||||
|
import { formatNumber } from 'utils';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class ItemsService implements IItemsService {
|
export default class ItemsService implements IItemsService {
|
||||||
@@ -289,12 +290,12 @@ export default class ItemsService implements IItemsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate the item inventory account whether modified and item
|
* Validate the item inventory account whether modified and item
|
||||||
* has assocaited inventory transactions.
|
* has assocaited inventory transactions.
|
||||||
* @param {numnber} tenantId
|
* @param {numnber} tenantId
|
||||||
* @param {IItem} oldItem
|
* @param {IItem} oldItem
|
||||||
* @param {IItemDTO} newItemDTO
|
* @param {IItemDTO} newItemDTO
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
async validateItemInvnetoryAccountModified(
|
async validateItemInvnetoryAccountModified(
|
||||||
tenantId: number,
|
tenantId: number,
|
||||||
@@ -418,11 +419,7 @@ export default class ItemsService implements IItemsService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.validateItemInvnetoryAccountModified(
|
await this.validateItemInvnetoryAccountModified(tenantId, oldItem, itemDTO);
|
||||||
tenantId,
|
|
||||||
oldItem,
|
|
||||||
itemDTO
|
|
||||||
);
|
|
||||||
|
|
||||||
const newItem = await Item.query().patchAndFetchById(itemId, {
|
const newItem = await Item.query().patchAndFetchById(itemId, {
|
||||||
...itemModel,
|
...itemModel,
|
||||||
@@ -525,7 +522,7 @@ export default class ItemsService implements IItemsService {
|
|||||||
if (!item) {
|
if (!item) {
|
||||||
throw new ServiceError(ERRORS.NOT_FOUND);
|
throw new ServiceError(ERRORS.NOT_FOUND);
|
||||||
}
|
}
|
||||||
return item;
|
return this.transformItemToResponse(tenantId, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -540,7 +537,7 @@ export default class ItemsService implements IItemsService {
|
|||||||
Item,
|
Item,
|
||||||
itemsFilter
|
itemsFilter
|
||||||
);
|
);
|
||||||
const { results, pagination } = await Item.query()
|
const { results: items, pagination } = await Item.query()
|
||||||
.onBuild((builder) => {
|
.onBuild((builder) => {
|
||||||
builder.withGraphFetched('inventoryAccount');
|
builder.withGraphFetched('inventoryAccount');
|
||||||
builder.withGraphFetched('sellAccount');
|
builder.withGraphFetched('sellAccount');
|
||||||
@@ -551,6 +548,10 @@ export default class ItemsService implements IItemsService {
|
|||||||
})
|
})
|
||||||
.pagination(itemsFilter.page - 1, itemsFilter.pageSize);
|
.pagination(itemsFilter.page - 1, itemsFilter.pageSize);
|
||||||
|
|
||||||
|
const results = items.map((item) =>
|
||||||
|
this.transformItemToResponse(tenantId, item)
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
items: results,
|
items: results,
|
||||||
pagination,
|
pagination,
|
||||||
@@ -583,7 +584,7 @@ export default class ItemsService implements IItemsService {
|
|||||||
builder.where('name', 'LIKE', `%${itemsFilter.keyword}%`);
|
builder.where('name', 'LIKE', `%${itemsFilter.keyword}%`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return items;
|
return items.map((item) => this.transformItemToResponse(tenantId, item));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -630,4 +631,24 @@ export default class ItemsService implements IItemsService {
|
|||||||
throw new ServiceError(ERRORS.ITEM_HAS_ASSOCIATED_INVENTORY_ADJUSTMENT);
|
throw new ServiceError(ERRORS.ITEM_HAS_ASSOCIATED_INVENTORY_ADJUSTMENT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transformes the item object to response.
|
||||||
|
* @param {number} tenantId -
|
||||||
|
* @param {IItem} item -
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
private transformItemToResponse(tenantId: number, item: IItem) {
|
||||||
|
// Settings tenant service.
|
||||||
|
const settings = this.tenancy.settings(tenantId);
|
||||||
|
const currencyCode = settings.get({
|
||||||
|
group: 'organization', key: 'base_currency',
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
...item,
|
||||||
|
sellPriceFormatted: formatNumber(item.sellPrice, { currencyCode }),
|
||||||
|
costPriceFormatted: formatNumber(item.costPrice, { currencyCode }),
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -344,6 +344,11 @@ export default class ManualJournalsService implements IManualJournalsService {
|
|||||||
|
|
||||||
const journalNumber = manualJournalDTO.journalNumber || autoNextNumber;
|
const journalNumber = manualJournalDTO.journalNumber || autoNextNumber;
|
||||||
|
|
||||||
|
// Settings tenant service.
|
||||||
|
const settings = this.tenancy.settings(tenantId);
|
||||||
|
const currencyCode = settings.get({
|
||||||
|
group: 'organization', key: 'base_currency',
|
||||||
|
});
|
||||||
// Validate manual journal number require.
|
// Validate manual journal number require.
|
||||||
this.validateJournalNoRequire(journalNumber);
|
this.validateJournalNoRequire(journalNumber);
|
||||||
|
|
||||||
@@ -353,6 +358,7 @@ export default class ManualJournalsService implements IManualJournalsService {
|
|||||||
? { publishedAt: moment().toMySqlDateTime() }
|
? { publishedAt: moment().toMySqlDateTime() }
|
||||||
: {}),
|
: {}),
|
||||||
amount,
|
amount,
|
||||||
|
currencyCode,
|
||||||
date,
|
date,
|
||||||
journalNumber,
|
journalNumber,
|
||||||
userId: authorizedUser.id,
|
userId: authorizedUser.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user