mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 15:20:34 +00:00
fix(Currency Code): add the missing the currency codes.
This commit is contained in:
@@ -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>
|
||||||
|
|||||||
@@ -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,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -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