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