mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +00:00
fix(Currencies): Currency code in services.
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
||||
IAccount,
|
||||
IJournalPoster,
|
||||
IAccountType,
|
||||
INumberFormatQuery,
|
||||
} from 'interfaces';
|
||||
import { dateRangeCollection, flatToNestedArray } from 'utils';
|
||||
import BalanceSheetStructure from 'data/BalanceSheetStructure';
|
||||
@@ -21,6 +22,7 @@ export default class BalanceSheetStatement extends FinancialSheet {
|
||||
readonly comparatorDateType: string;
|
||||
readonly dateRangeSet: string[];
|
||||
readonly baseCurrency: string;
|
||||
readonly numberFormat: INumberFormatQuery;
|
||||
|
||||
/**
|
||||
* Constructor method.
|
||||
|
||||
@@ -2,7 +2,8 @@ import { IFormatNumberSettings, INumberFormatQuery } from 'interfaces';
|
||||
import { formatNumber } from 'utils';
|
||||
|
||||
export default class FinancialSheet {
|
||||
numberFormat: INumberFormatQuery;
|
||||
readonly numberFormat: INumberFormatQuery;
|
||||
readonly baseCurrency: string;
|
||||
|
||||
/**
|
||||
* Transformes the number format query to settings
|
||||
@@ -16,6 +17,7 @@ export default class FinancialSheet {
|
||||
excerptZero: !numberFormat.showZero,
|
||||
negativeFormat: numberFormat.negativeFormat,
|
||||
money: numberFormat.formatMoney === 'always',
|
||||
currencyCode: this.baseCurrency,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ export default class InventoryValuationSheet extends FinancialSheet {
|
||||
* @param {number} itemId
|
||||
* @returns
|
||||
*/
|
||||
getItemTransaction(
|
||||
private getItemTransaction(
|
||||
transactionsMap: Map<number, InventoryCostLotTracker[]>,
|
||||
itemId: number,
|
||||
): { cost: number, quantity: number } {
|
||||
@@ -64,7 +64,7 @@ export default class InventoryValuationSheet extends FinancialSheet {
|
||||
* Retrieve the cost and quantity of the givne item from `IN` transactions.
|
||||
* @param {number} itemId -
|
||||
*/
|
||||
getItemINTransaction(
|
||||
private getItemINTransaction(
|
||||
itemId: number,
|
||||
): { cost: number, quantity: number } {
|
||||
return this.getItemTransaction(this.INInventoryCostLots, itemId);
|
||||
@@ -74,7 +74,7 @@ export default class InventoryValuationSheet extends FinancialSheet {
|
||||
* Retrieve the cost and quantity of the given item from `OUT` transactions.
|
||||
* @param {number} itemId -
|
||||
*/
|
||||
getItemOUTTransaction(
|
||||
private getItemOUTTransaction(
|
||||
itemId: number,
|
||||
): { cost: number, quantity: number } {
|
||||
return this.getItemTransaction(this.OUTInventoryCostLots, itemId);
|
||||
@@ -84,7 +84,7 @@ export default class InventoryValuationSheet extends FinancialSheet {
|
||||
* Retrieve the item closing valuation.
|
||||
* @param {number} itemId - Item id.
|
||||
*/
|
||||
getItemValuation(itemId: number): number {
|
||||
private getItemValuation(itemId: number): number {
|
||||
const { cost: INValuation } = this.getItemINTransaction(itemId);
|
||||
const { cost: OUTValuation } = this.getItemOUTTransaction(itemId);
|
||||
|
||||
@@ -95,7 +95,7 @@ export default class InventoryValuationSheet extends FinancialSheet {
|
||||
* Retrieve the item closing quantity.
|
||||
* @param {number} itemId - Item id.
|
||||
*/
|
||||
getItemQuantity(itemId: number): number {
|
||||
private getItemQuantity(itemId: number): number {
|
||||
const { quantity: INQuantity } = this.getItemINTransaction(itemId);
|
||||
const { quantity: OUTQuantity } = this.getItemOUTTransaction(itemId);
|
||||
|
||||
@@ -108,7 +108,7 @@ export default class InventoryValuationSheet extends FinancialSheet {
|
||||
* @param {number} quantity
|
||||
* @returns {number}
|
||||
*/
|
||||
calcAverage(valuation: number, quantity: number): number {
|
||||
private calcAverage(valuation: number, quantity: number): number {
|
||||
return quantity ? valuation / quantity : 0;
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ export default class InventoryValuationSheet extends FinancialSheet {
|
||||
* @param {IItem} item
|
||||
* @returns {IInventoryValuationItem}
|
||||
*/
|
||||
itemMapper(item: IItem): IInventoryValuationItem {
|
||||
private itemMapper(item: IItem): IInventoryValuationItem {
|
||||
const valuation = this.getItemValuation(item.id);
|
||||
const quantity = this.getItemQuantity(item.id);
|
||||
const average = this.calcAverage(valuation, quantity);
|
||||
@@ -140,7 +140,7 @@ export default class InventoryValuationSheet extends FinancialSheet {
|
||||
* Retrieve the inventory valuation items.
|
||||
* @returns {IInventoryValuationItem[]}
|
||||
*/
|
||||
itemsSection(): IInventoryValuationItem[] {
|
||||
private itemsSection(): IInventoryValuationItem[] {
|
||||
return this.items.map(this.itemMapper.bind(this));
|
||||
}
|
||||
|
||||
@@ -149,15 +149,15 @@ export default class InventoryValuationSheet extends FinancialSheet {
|
||||
* @param {IInventoryValuationItem[]} items
|
||||
* @returns {IInventoryValuationTotal}
|
||||
*/
|
||||
totalSection(items: IInventoryValuationItem[]): IInventoryValuationTotal {
|
||||
private totalSection(items: IInventoryValuationItem[]): IInventoryValuationTotal {
|
||||
const valuation = sumBy(items, item => item.valuation);
|
||||
const quantity = sumBy(items, item => item.quantity);
|
||||
|
||||
return {
|
||||
valuation,
|
||||
quantity,
|
||||
valuationFormatted: this.formatNumber(valuation),
|
||||
quantityFormatted: this.formatNumber(quantity, { money: false }),
|
||||
valuationFormatted: this.formatTotalNumber(valuation),
|
||||
quantityFormatted: this.formatTotalNumber(quantity, { money: false }),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -165,10 +165,10 @@ export default class InventoryValuationSheet extends FinancialSheet {
|
||||
* Retrieve the inventory valuation report data.
|
||||
* @returns {IInventoryValuationStatement}
|
||||
*/
|
||||
reportData(): IInventoryValuationStatement {
|
||||
public reportData(): IInventoryValuationStatement {
|
||||
const items = this.itemsSection();
|
||||
const total = this.totalSection(items);
|
||||
|
||||
return { items, total };
|
||||
return items.length > 0 ? { items, total } : {};
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
} from 'interfaces';
|
||||
import TenancyService from 'services/Tenancy/TenancyService';
|
||||
import InventoryValuationSheet from './InventoryValuationSheet';
|
||||
import InventoryService from 'services/Inventory/Inventory';
|
||||
|
||||
@Service()
|
||||
export default class InventoryValuationSheetService {
|
||||
@@ -15,6 +16,9 @@ export default class InventoryValuationSheetService {
|
||||
@Inject('logger')
|
||||
logger: any;
|
||||
|
||||
@Inject()
|
||||
inventoryService: InventoryService;
|
||||
|
||||
/**
|
||||
* Defaults balance sheet filter query.
|
||||
* @return {IBalanceSheetQuery}
|
||||
@@ -41,6 +45,9 @@ export default class InventoryValuationSheetService {
|
||||
reportMetadata(tenantId: number): IInventoryValuationSheetMeta {
|
||||
const settings = this.tenancy.settings(tenantId);
|
||||
|
||||
const isCostComputeRunning = this.inventoryService
|
||||
.isItemsCostComputeRunning(tenantId);
|
||||
|
||||
const organizationName = settings.get({
|
||||
group: 'organization',
|
||||
key: 'name',
|
||||
@@ -53,6 +60,7 @@ export default class InventoryValuationSheetService {
|
||||
return {
|
||||
organizationName,
|
||||
baseCurrency,
|
||||
isCostComputeRunning
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -10,10 +10,10 @@ import {
|
||||
import FinancialSheet from '../FinancialSheet';
|
||||
|
||||
export default class JournalSheet extends FinancialSheet {
|
||||
tenantId: number;
|
||||
journal: IJournalPoster;
|
||||
query: IJournalReportQuery;
|
||||
baseCurrency: string;
|
||||
readonly tenantId: number;
|
||||
readonly journal: IJournalPoster;
|
||||
readonly query: IJournalReportQuery;
|
||||
readonly baseCurrency: string;
|
||||
readonly contactsById: Map<number | string, IContact>;
|
||||
|
||||
/**
|
||||
|
||||
@@ -76,6 +76,8 @@ export default class JournalSheetService {
|
||||
contactRepository,
|
||||
} = this.tenancy.repositories(tenantId);
|
||||
|
||||
const { AccountTransaction } = this.tenancy.models(tenantId);
|
||||
|
||||
const filter = {
|
||||
...this.defaultQuery,
|
||||
...query,
|
||||
@@ -98,12 +100,12 @@ export default class JournalSheetService {
|
||||
const contactsByIdMap = transformToMap(contacts, 'id');
|
||||
|
||||
// Retrieve all journal transactions based on the given query.
|
||||
const transactions = await transactionsRepository.journal({
|
||||
fromDate: filter.fromDate,
|
||||
toDate: filter.toDate,
|
||||
transactionsTypes: filter.transactionTypes,
|
||||
fromAmount: filter.fromRange,
|
||||
toAmount: filter.toRange,
|
||||
const transactions = await AccountTransaction.query().onBuild((query) => {
|
||||
if (filter.fromRange || filter.toRange) {
|
||||
query.modify('filterAmountRange', filter.fromRange, filter.toRange);
|
||||
}
|
||||
query.modify('filterDateRange', filter.fromDate, filter.toDate);
|
||||
query.orderBy(['date', 'createdAt', 'indexGroup', 'index']);
|
||||
});
|
||||
// Transform the transactions array to journal collection.
|
||||
const transactionsJournal = Journal.fromTransactions(
|
||||
|
||||
@@ -99,10 +99,10 @@ export default class InventoryValuationReport extends FinancialSheet {
|
||||
return {
|
||||
quantityPurchased,
|
||||
purchaseCost,
|
||||
quantityPurchasedFormatted: this.formatNumber(quantityPurchased, {
|
||||
quantityPurchasedFormatted: this.formatTotalNumber(quantityPurchased, {
|
||||
money: false,
|
||||
}),
|
||||
purchaseCostFormatted: this.formatNumber(purchaseCost),
|
||||
purchaseCostFormatted: this.formatTotalNumber(purchaseCost),
|
||||
currencyCode: this.baseCurrency,
|
||||
};
|
||||
}
|
||||
@@ -115,6 +115,6 @@ export default class InventoryValuationReport extends FinancialSheet {
|
||||
const items = this.itemsSection();
|
||||
const total = this.totalSection(items);
|
||||
|
||||
return { items, total };
|
||||
return items.length > 0 ? { items, total } : {};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,10 +99,10 @@ export default class SalesByItemsReport extends FinancialSheet {
|
||||
return {
|
||||
quantitySold,
|
||||
soldCost,
|
||||
quantitySoldFormatted: this.formatNumber(quantitySold, {
|
||||
quantitySoldFormatted: this.formatTotalNumber(quantitySold, {
|
||||
money: false,
|
||||
}),
|
||||
soldCostFormatted: this.formatNumber(soldCost),
|
||||
soldCostFormatted: this.formatTotalNumber(soldCost),
|
||||
currencyCode: this.baseCurrency,
|
||||
};
|
||||
}
|
||||
@@ -115,6 +115,6 @@ export default class SalesByItemsReport extends FinancialSheet {
|
||||
const items = this.itemsSection();
|
||||
const total = this.totalSection(items);
|
||||
|
||||
return { items, total };
|
||||
return items.length > 0 ? { items, total } : {};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user