mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +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) => (
|
||||
<Tooltip
|
||||
content={<AmountPopoverContent journalEntries={r.entries} />}
|
||||
content={
|
||||
<AmountPopoverContent
|
||||
journalEntries={r.entries}
|
||||
currencyCode={r.currency_code}
|
||||
/>
|
||||
}
|
||||
position={Position.RIGHT_TOP}
|
||||
boundary={'viewport'}
|
||||
>
|
||||
<Money amount={r.amount} currency={'USD'} />
|
||||
{r.amount_formatted}
|
||||
</Tooltip>
|
||||
);
|
||||
|
||||
/**
|
||||
* Amount popover content line.
|
||||
*/
|
||||
export const AmountPopoverContentLine = ({ journalEntry }) => {
|
||||
export const AmountPopoverContentLine = ({ journalEntry, currencyCode }) => {
|
||||
const isCredit = !!journalEntry.credit;
|
||||
const isDebit = !!journalEntry.debit;
|
||||
const { account } = journalEntry;
|
||||
@@ -42,14 +47,14 @@ export const AmountPopoverContentLine = ({ journalEntry }) => {
|
||||
<Choose>
|
||||
<Choose.When condition={isDebit}>
|
||||
<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>
|
||||
</div>
|
||||
</Choose.When>
|
||||
|
||||
<Choose.When condition={isCredit}>
|
||||
<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>
|
||||
</div>
|
||||
</Choose.When>
|
||||
@@ -60,7 +65,7 @@ export const AmountPopoverContentLine = ({ journalEntry }) => {
|
||||
/**
|
||||
* Amount popover content.
|
||||
*/
|
||||
export function AmountPopoverContent({ journalEntries }) {
|
||||
export function AmountPopoverContent({ journalEntries, currencyCode }) {
|
||||
const journalLinesProps = journalEntries.map((journalEntry) => ({
|
||||
journalEntry,
|
||||
accountId: journalEntry.account_id,
|
||||
@@ -72,6 +77,7 @@ export function AmountPopoverContent({ journalEntries }) {
|
||||
<AmountPopoverContentLine
|
||||
journalEntry={journalEntry}
|
||||
accountId={accountId}
|
||||
currencyCode={currencyCode}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
@@ -181,16 +181,16 @@ export const useItemsTableColumns = () => {
|
||||
{
|
||||
id: 'sell_price',
|
||||
Header: formatMessage({ id: 'sell_price' }),
|
||||
Cell: SellPriceCell,
|
||||
accessor: 'sell_price',
|
||||
// Cell: SellPriceCell,
|
||||
accessor: 'sell_price_formatted',
|
||||
className: 'sell-price',
|
||||
width: 150,
|
||||
},
|
||||
{
|
||||
id: 'cost_price',
|
||||
Header: formatMessage({ id: 'cost_price' }),
|
||||
Cell: CostPriceCell,
|
||||
accessor: 'cost_price',
|
||||
// Cell: CostPriceCell,
|
||||
accessor: 'cost_price_formatted',
|
||||
className: 'cost-price',
|
||||
width: 150,
|
||||
},
|
||||
|
||||
@@ -324,7 +324,9 @@ export default class ItemsController extends BaseController {
|
||||
try {
|
||||
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) {
|
||||
next(error);
|
||||
}
|
||||
@@ -356,7 +358,7 @@ export default class ItemsController extends BaseController {
|
||||
} = await this.itemsService.itemsList(tenantId, filter);
|
||||
|
||||
return res.status(200).send({
|
||||
items,
|
||||
items: this.transfromToResponse(items),
|
||||
pagination: this.transfromToResponse(pagination),
|
||||
filter_meta: this.transfromToResponse(filterMeta),
|
||||
});
|
||||
@@ -390,7 +392,7 @@ export default class ItemsController extends BaseController {
|
||||
filter
|
||||
);
|
||||
return res.status(200).send({
|
||||
items,
|
||||
items: this.transfromToResponse(items),
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
|
||||
@@ -6,6 +6,7 @@ exports.up = function(knex) {
|
||||
table.string('reference').index();
|
||||
table.string('journal_type').index();
|
||||
table.decimal('amount', 13, 3);
|
||||
table.string('currency_code', 3);
|
||||
table.date('date').index();
|
||||
table.string('description');
|
||||
table.date('published_at').index();
|
||||
|
||||
@@ -9,6 +9,7 @@ export interface IManualJournal {
|
||||
journalType: string;
|
||||
reference: string;
|
||||
amount: number;
|
||||
currencyCode: string;
|
||||
publishedAt: Date | null;
|
||||
description: string;
|
||||
userId: number;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Model } from 'objection';
|
||||
import TenantModel from 'models/TenantModel';
|
||||
import { query } from 'winston';
|
||||
import { formatNumber } from 'utils';
|
||||
|
||||
export default class ManualJournal extends TenantModel {
|
||||
/**
|
||||
@@ -21,7 +21,14 @@ export default class ManualJournal extends TenantModel {
|
||||
* Virtual attributes.
|
||||
*/
|
||||
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,
|
||||
} from 'data/AccountTypes';
|
||||
import { ERRORS } from './constants';
|
||||
import { formatNumber } from 'utils';
|
||||
|
||||
@Service()
|
||||
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.
|
||||
* @param {numnber} tenantId
|
||||
* @param {IItem} oldItem
|
||||
* @param {IItemDTO} newItemDTO
|
||||
* @returns
|
||||
* @param {numnber} tenantId
|
||||
* @param {IItem} oldItem
|
||||
* @param {IItemDTO} newItemDTO
|
||||
* @returns
|
||||
*/
|
||||
async validateItemInvnetoryAccountModified(
|
||||
tenantId: number,
|
||||
@@ -418,11 +419,7 @@ export default class ItemsService implements IItemsService {
|
||||
);
|
||||
}
|
||||
|
||||
await this.validateItemInvnetoryAccountModified(
|
||||
tenantId,
|
||||
oldItem,
|
||||
itemDTO
|
||||
);
|
||||
await this.validateItemInvnetoryAccountModified(tenantId, oldItem, itemDTO);
|
||||
|
||||
const newItem = await Item.query().patchAndFetchById(itemId, {
|
||||
...itemModel,
|
||||
@@ -525,7 +522,7 @@ export default class ItemsService implements IItemsService {
|
||||
if (!item) {
|
||||
throw new ServiceError(ERRORS.NOT_FOUND);
|
||||
}
|
||||
return item;
|
||||
return this.transformItemToResponse(tenantId, item);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -540,7 +537,7 @@ export default class ItemsService implements IItemsService {
|
||||
Item,
|
||||
itemsFilter
|
||||
);
|
||||
const { results, pagination } = await Item.query()
|
||||
const { results: items, pagination } = await Item.query()
|
||||
.onBuild((builder) => {
|
||||
builder.withGraphFetched('inventoryAccount');
|
||||
builder.withGraphFetched('sellAccount');
|
||||
@@ -551,6 +548,10 @@ export default class ItemsService implements IItemsService {
|
||||
})
|
||||
.pagination(itemsFilter.page - 1, itemsFilter.pageSize);
|
||||
|
||||
const results = items.map((item) =>
|
||||
this.transformItemToResponse(tenantId, item)
|
||||
);
|
||||
|
||||
return {
|
||||
items: results,
|
||||
pagination,
|
||||
@@ -583,7 +584,7 @@ export default class ItemsService implements IItemsService {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
// Settings tenant service.
|
||||
const settings = this.tenancy.settings(tenantId);
|
||||
const currencyCode = settings.get({
|
||||
group: 'organization', key: 'base_currency',
|
||||
});
|
||||
// Validate manual journal number require.
|
||||
this.validateJournalNoRequire(journalNumber);
|
||||
|
||||
@@ -353,6 +358,7 @@ export default class ManualJournalsService implements IManualJournalsService {
|
||||
? { publishedAt: moment().toMySqlDateTime() }
|
||||
: {}),
|
||||
amount,
|
||||
currencyCode,
|
||||
date,
|
||||
journalNumber,
|
||||
userId: authorizedUser.id,
|
||||
|
||||
Reference in New Issue
Block a user