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:
@@ -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