mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
WIP: Arabic localization.|
This commit is contained in:
@@ -1,14 +1,22 @@
|
||||
import { Service } from 'typedi';
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { IAccountsTypesService, IAccountType } from 'interfaces';
|
||||
import AccountTypesUtils from 'lib/AccountTypes';
|
||||
import I18nService from 'services/I18n/I18nService';
|
||||
|
||||
|
||||
@Service()
|
||||
export default class AccountsTypesService implements IAccountsTypesService {
|
||||
@Inject()
|
||||
i18nService: I18nService;
|
||||
|
||||
/**
|
||||
* Retrieve all accounts types.
|
||||
* @param {number} tenantId -
|
||||
* @return {IAccountType}
|
||||
*/
|
||||
getAccountsTypes(): IAccountType[] {
|
||||
return AccountTypesUtils.getList();
|
||||
public getAccountsTypes(tenantId: number): IAccountType[] {
|
||||
const accountTypes = AccountTypesUtils.getList();
|
||||
|
||||
return this.i18nService.i18nMapper(accountTypes, ['name'], tenantId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ import {
|
||||
} from 'utils/deepdash';
|
||||
import { ACCOUNT_ROOT_TYPE } from 'data/AccountTypes';
|
||||
import CashFlowDatePeriods from './CashFlowDatePeriods';
|
||||
import I18nService from 'services/I18n/I18nService';
|
||||
|
||||
const MAP_CONFIG = { childrenPath: 'children', pathFormat: 'array' };
|
||||
|
||||
@@ -47,6 +48,7 @@ const DISPLAY_COLUMNS_BY = {
|
||||
|
||||
class CashFlowStatement extends FinancialSheet implements ICashFlowStatement {
|
||||
readonly baseCurrency: string;
|
||||
readonly i18n: I18nService;
|
||||
readonly sectionsByIds = {};
|
||||
readonly cashFlowSchemaMap: Map<string, ICashFlowSchemaSection>;
|
||||
readonly cashFlowSchemaSeq: Array<string>;
|
||||
@@ -58,7 +60,6 @@ class CashFlowStatement extends FinancialSheet implements ICashFlowStatement {
|
||||
readonly schemaSectionParserIteratee: any;
|
||||
readonly query: ICashFlowStatementQuery;
|
||||
readonly numberFormat: INumberFormatQuery;
|
||||
|
||||
readonly comparatorDateType: string;
|
||||
readonly dateRangeSet: { fromDate: Date; toDate: Date }[];
|
||||
|
||||
@@ -72,11 +73,13 @@ class CashFlowStatement extends FinancialSheet implements ICashFlowStatement {
|
||||
cashLedger: ILedger,
|
||||
netIncomeLedger: ILedger,
|
||||
query: ICashFlowStatementQuery,
|
||||
baseCurrency: string
|
||||
baseCurrency: string,
|
||||
i18n
|
||||
) {
|
||||
super();
|
||||
|
||||
this.baseCurrency = baseCurrency;
|
||||
this.i18n = i18n;
|
||||
this.ledger = ledger;
|
||||
this.cashLedger = cashLedger;
|
||||
this.netIncomeLedger = netIncomeLedger;
|
||||
@@ -87,8 +90,8 @@ class CashFlowStatement extends FinancialSheet implements ICashFlowStatement {
|
||||
this.numberFormat = this.query.numberFormat;
|
||||
this.dateRangeSet = [];
|
||||
|
||||
this.comparatorDateType =
|
||||
query.displayColumnsType === 'total' ? 'day' : query.displayColumnsBy;
|
||||
this.comparatorDateType = query.displayColumnsType === 'total'
|
||||
? 'day' : query.displayColumnsBy;
|
||||
|
||||
this.initDateRangeCollection();
|
||||
}
|
||||
@@ -177,7 +180,7 @@ class CashFlowStatement extends FinancialSheet implements ICashFlowStatement {
|
||||
)
|
||||
)({
|
||||
id: sectionSchema.id,
|
||||
label: sectionSchema.label,
|
||||
label: this.i18n.__(sectionSchema.label),
|
||||
total: this.getAmountMeta(netIncome),
|
||||
sectionType: ICashFlowStatementSectionType.NET_INCOME,
|
||||
});
|
||||
@@ -283,8 +286,8 @@ class CashFlowStatement extends FinancialSheet implements ICashFlowStatement {
|
||||
)({
|
||||
sectionType: ICashFlowStatementSectionType.ACCOUNTS,
|
||||
id: sectionSchema.id,
|
||||
label: sectionSchema.label,
|
||||
footerLabel: sectionSchema.footerLabel,
|
||||
label: this.i18n.__(sectionSchema.label),
|
||||
footerLabel: this.i18n.__(sectionSchema.footerLabel),
|
||||
children: accounts,
|
||||
total: this.getTotalAmountMeta(total),
|
||||
});
|
||||
@@ -317,8 +320,8 @@ class CashFlowStatement extends FinancialSheet implements ICashFlowStatement {
|
||||
): ICashFlowStatementSection {
|
||||
return {
|
||||
id: schemaSection.id,
|
||||
label: schemaSection.label,
|
||||
footerLabel: schemaSection.footerLabel,
|
||||
label: this.i18n.__(schemaSection.label),
|
||||
footerLabel: this.i18n.__(schemaSection.footerLabel),
|
||||
sectionType: ICashFlowStatementSectionType.REGULAR,
|
||||
};
|
||||
}
|
||||
@@ -383,7 +386,7 @@ class CashFlowStatement extends FinancialSheet implements ICashFlowStatement {
|
||||
)({
|
||||
sectionType: ICashFlowStatementSectionType.TOTAL,
|
||||
id: sectionSchema.id,
|
||||
label: sectionSchema.label,
|
||||
label: this.i18n.__(sectionSchema.label),
|
||||
total: this.getTotalAmountMeta(total),
|
||||
});
|
||||
}
|
||||
@@ -477,7 +480,7 @@ class CashFlowStatement extends FinancialSheet implements ICashFlowStatement {
|
||||
)({
|
||||
sectionType: ICashFlowStatementSectionType.CASH_AT_BEGINNING,
|
||||
id: sectionSchema.id,
|
||||
label: sectionSchema.label,
|
||||
label: this.i18n.__(sectionSchema.label),
|
||||
children,
|
||||
total: this.getTotalAmountMeta(total),
|
||||
});
|
||||
|
||||
@@ -94,6 +94,8 @@ export default class CashFlowStatementService
|
||||
tenantId: number,
|
||||
query: ICashFlowStatementQuery
|
||||
): Promise<ICashFlowStatementDOO> {
|
||||
const i18n = this.tenancy.i18n(tenantId);
|
||||
|
||||
// Retrieve all accounts on the storage.
|
||||
const accounts = await this.cashFlowRepo.cashFlowAccounts(tenantId);
|
||||
|
||||
@@ -135,7 +137,8 @@ export default class CashFlowStatementService
|
||||
cashLedger,
|
||||
netIncomeLedger,
|
||||
filter,
|
||||
baseCurrency
|
||||
baseCurrency,
|
||||
i18n
|
||||
);
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import * as R from 'ramda';
|
||||
import { isEmpty } from 'lodash';
|
||||
import { isEmpty, times } from 'lodash';
|
||||
import moment from 'moment';
|
||||
import {
|
||||
ICashFlowStatementSection,
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
ITableColumn,
|
||||
ICashFlowStatementQuery,
|
||||
IDateRange,
|
||||
ICashFlowStatementDOO
|
||||
ICashFlowStatementDOO,
|
||||
} from 'interfaces';
|
||||
import { dateRangeFromToCollection, tableRowMapper } from 'utils';
|
||||
import { mapValuesDeep } from 'utils/deepdash';
|
||||
@@ -27,29 +27,30 @@ const DISPLAY_COLUMNS_BY = {
|
||||
TOTAL: 'total',
|
||||
};
|
||||
|
||||
|
||||
export default class CashFlowTable implements ICashFlowTable {
|
||||
private report: ICashFlowStatementDOO;
|
||||
private i18n;
|
||||
private dateRangeSet: IDateRange[];
|
||||
|
||||
/**
|
||||
* Constructor method.
|
||||
* @param {ICashFlowStatement} reportStatement
|
||||
*/
|
||||
constructor(reportStatement: ICashFlowStatementDOO) {
|
||||
constructor(reportStatement: ICashFlowStatementDOO, i18n) {
|
||||
this.report = reportStatement;
|
||||
this.i18n = i18n;
|
||||
this.dateRangeSet = [];
|
||||
this.initDateRangeCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Initialize date range set.
|
||||
*/
|
||||
private initDateRangeCollection() {
|
||||
this.dateRangeSet = dateRangeFromToCollection(
|
||||
this.report.query.fromDate,
|
||||
this.report.query.toDate,
|
||||
this.report.query.displayColumnsBy,
|
||||
this.report.query.displayColumnsBy
|
||||
);
|
||||
}
|
||||
|
||||
@@ -78,9 +79,9 @@ export default class CashFlowTable implements ICashFlowTable {
|
||||
R.concat([{ key: 'label', accessor: 'label' }]),
|
||||
R.when(
|
||||
R.always(this.isDisplayColumnsBy(DISPLAY_COLUMNS_BY.DATE_PERIODS)),
|
||||
R.concat(this.datePeriodsColumnsAccessors()),
|
||||
R.concat(this.datePeriodsColumnsAccessors())
|
||||
),
|
||||
R.concat(this.totalColumnAccessor()),
|
||||
R.concat(this.totalColumnAccessor())
|
||||
)([]);
|
||||
}
|
||||
|
||||
@@ -230,7 +231,7 @@ export default class CashFlowTable implements ICashFlowTable {
|
||||
): ICashFlowStatementSection {
|
||||
const label = section.footerLabel
|
||||
? section.footerLabel
|
||||
: `Total ${section.label}`;
|
||||
: this.i18n.__('Total {{accountName}}', { accountName: section.label });
|
||||
|
||||
section.children.push({
|
||||
sectionType: ICashFlowStatementSectionType.TOTAL,
|
||||
@@ -288,12 +289,12 @@ export default class CashFlowTable implements ICashFlowTable {
|
||||
* @returns {ITableColumn}
|
||||
*/
|
||||
private totalColumns(): ITableColumn[] {
|
||||
return [{ key: 'total', label: 'Total' }];
|
||||
return [{ key: 'total', label: this.i18n.__('Total') }];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the formatted column label from the given date range.
|
||||
* @param {ICashFlowDateRange} dateRange -
|
||||
* @param {ICashFlowDateRange} dateRange -
|
||||
* @return {string}
|
||||
*/
|
||||
private formatColumnLabel(dateRange: ICashFlowDateRange) {
|
||||
@@ -308,9 +309,13 @@ export default class CashFlowTable implements ICashFlowTable {
|
||||
['quarter', monthFormat],
|
||||
['week', dayFormat],
|
||||
];
|
||||
const conditionsPairs = R.map(([type, formatFn]) => ([
|
||||
R.always(this.isDisplayColumnsType(type)), formatFn,
|
||||
]), conditions);
|
||||
const conditionsPairs = R.map(
|
||||
([type, formatFn]) => [
|
||||
R.always(this.isDisplayColumnsType(type)),
|
||||
formatFn,
|
||||
],
|
||||
conditions
|
||||
);
|
||||
|
||||
return R.compose(R.cond(conditionsPairs))(dateRange);
|
||||
}
|
||||
@@ -336,11 +341,11 @@ export default class CashFlowTable implements ICashFlowTable {
|
||||
|
||||
/**
|
||||
* Detarmines whether the given display columns type is the current.
|
||||
* @param {string} displayColumnsBy
|
||||
* @param {string} displayColumnsBy
|
||||
* @returns {boolean}
|
||||
*/
|
||||
private isDisplayColumnsType(displayColumnsBy: string): Boolean {
|
||||
return this.report.query.displayColumnsBy === displayColumnsBy;
|
||||
return this.report.query.displayColumnsBy === displayColumnsBy;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -349,7 +354,7 @@ export default class CashFlowTable implements ICashFlowTable {
|
||||
*/
|
||||
public tableColumns(): ITableColumn[] {
|
||||
return R.compose(
|
||||
R.concat([{ key: 'name', label: 'Account name' }]),
|
||||
R.concat([{ key: 'name', label: this.i18n.__('Account name') }]),
|
||||
R.when(
|
||||
R.always(this.isDisplayColumnsBy(DISPLAY_COLUMNS_BY.DATE_PERIODS)),
|
||||
R.concat(this.datePeriodsColumns())
|
||||
|
||||
@@ -22,6 +22,7 @@ export default class GeneralLedgerSheet extends FinancialSheet {
|
||||
transactions: IJournalPoster;
|
||||
contactsMap: Map<number, IContact>;
|
||||
baseCurrency: string;
|
||||
i18n: any;
|
||||
|
||||
/**
|
||||
* Constructor method.
|
||||
@@ -38,8 +39,8 @@ export default class GeneralLedgerSheet extends FinancialSheet {
|
||||
contactsByIdMap: Map<number, IContact>,
|
||||
transactions: IJournalPoster,
|
||||
openingBalancesJournal: IJournalPoster,
|
||||
|
||||
baseCurrency: string
|
||||
baseCurrency: string,
|
||||
i18n
|
||||
) {
|
||||
super();
|
||||
|
||||
@@ -51,6 +52,7 @@ export default class GeneralLedgerSheet extends FinancialSheet {
|
||||
this.transactions = transactions;
|
||||
this.openingBalancesJournal = openingBalancesJournal;
|
||||
this.baseCurrency = baseCurrency;
|
||||
this.i18n = i18n;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,7 +92,7 @@ export default class GeneralLedgerSheet extends FinancialSheet {
|
||||
|
||||
referenceType: entry.referenceType,
|
||||
referenceId: entry.referenceId,
|
||||
referenceTypeFormatted: entry.referenceTypeFormatted,
|
||||
referenceTypeFormatted: this.i18n.__(entry.referenceTypeFormatted),
|
||||
|
||||
contactName: get(contact, 'displayName'),
|
||||
contactType: get(contact, 'contactService'),
|
||||
|
||||
@@ -106,6 +106,7 @@ export default class GeneralLedgerService {
|
||||
contactRepository
|
||||
} = this.tenancy.repositories(tenantId);
|
||||
const settings = this.tenancy.settings(tenantId);
|
||||
const i18n = this.tenancy.i18n(tenantId);
|
||||
|
||||
const filter = {
|
||||
...this.defaultQuery,
|
||||
@@ -157,7 +158,8 @@ export default class GeneralLedgerService {
|
||||
contactsByIdMap,
|
||||
transactionsJournal,
|
||||
openingTransJournal,
|
||||
baseCurrency
|
||||
baseCurrency,
|
||||
i18n
|
||||
);
|
||||
// Retrieve general ledger report data.
|
||||
const reportData = generalLedgerInstance.reportData();
|
||||
|
||||
@@ -21,12 +21,16 @@ enum IROW_TYPE {
|
||||
const MAP_CONFIG = { childrenPath: 'children', pathFormat: 'array' };
|
||||
|
||||
export default class InventoryDetailsTable {
|
||||
i18n: any;
|
||||
report: any;
|
||||
|
||||
/**
|
||||
* Constructor method.
|
||||
* @param {ICashFlowStatement} reportStatement - Report statement.
|
||||
*/
|
||||
constructor(reportStatement) {
|
||||
constructor(reportStatement, i18n) {
|
||||
this.report = reportStatement;
|
||||
this.i18n = i18n;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,7 +67,10 @@ export default class InventoryDetailsTable {
|
||||
{ key: 'value', accessor: 'valueMovement.formattedNumber' },
|
||||
{ key: 'profit_margin', accessor: 'profitMargin.formattedNumber' },
|
||||
{ key: 'running_quantity', accessor: 'runningQuantity.formattedNumber' },
|
||||
{ key: 'running_valuation', accessor: 'runningValuation.formattedNumber' },
|
||||
{
|
||||
key: 'running_valuation',
|
||||
accessor: 'runningValuation.formattedNumber',
|
||||
},
|
||||
];
|
||||
return tableRowMapper(transaction, columns, {
|
||||
rowTypes: [IROW_TYPE.TRANSACTION],
|
||||
@@ -168,16 +175,16 @@ export default class InventoryDetailsTable {
|
||||
*/
|
||||
public tableColumns(): ITableColumn[] {
|
||||
return [
|
||||
{ key: 'date', label: 'Date' },
|
||||
{ key: 'transaction_type', label: 'Transaction type' },
|
||||
{ key: 'transaction_id', label: 'Transaction #' },
|
||||
{ key: 'quantity', label: 'Quantity' },
|
||||
{ key: 'rate', label: 'Rate' },
|
||||
{ key: 'total', label: 'Total' },
|
||||
{ key: 'value', label: 'Value' },
|
||||
{ key: 'profit_margin', label: 'Profit Margin' },
|
||||
{ key: 'running_quantity', label: 'Running quantity' },
|
||||
{ key: 'running_value', label: 'Running Value' },
|
||||
{ key: 'date', label: this.i18n.__('Date') },
|
||||
{ key: 'transaction_type', label: this.i18n.__('Transaction type') },
|
||||
{ key: 'transaction_id', label: this.i18n.__('Transaction #') },
|
||||
{ key: 'quantity', label: this.i18n.__('Quantity') },
|
||||
{ key: 'rate', label: this.i18n.__('Rate') },
|
||||
{ key: 'total', label: this.i18n.__('Total') },
|
||||
{ key: 'value', label: this.i18n.__('Value') },
|
||||
{ key: 'profit_margin', label: this.i18n.__('Profit Margin') },
|
||||
{ key: 'running_quantity', label: this.i18n.__('Running quantity') },
|
||||
{ key: 'running_value', label: this.i18n.__('Running Value') },
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,8 @@ export default class JournalSheet extends FinancialSheet {
|
||||
journal: IJournalPoster,
|
||||
accountsGraph: any,
|
||||
contactsById: Map<number | string, IContact>,
|
||||
baseCurrency: string
|
||||
baseCurrency: string,
|
||||
i18n
|
||||
) {
|
||||
super();
|
||||
|
||||
@@ -38,6 +39,7 @@ export default class JournalSheet extends FinancialSheet {
|
||||
this.accountsGraph = accountsGraph;
|
||||
this.contactsById = contactsById;
|
||||
this.baseCurrency = baseCurrency;
|
||||
this.i18n = i18n;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,7 +98,7 @@ export default class JournalSheet extends FinancialSheet {
|
||||
date: groupEntry.date,
|
||||
referenceType: groupEntry.referenceType,
|
||||
referenceId: groupEntry.referenceId,
|
||||
referenceTypeFormatted: groupEntry.referenceTypeFormatted,
|
||||
referenceTypeFormatted: this.i18n.__(groupEntry.referenceTypeFormatted),
|
||||
|
||||
entries: this.entriesMapper(entriesGroup),
|
||||
|
||||
|
||||
@@ -70,6 +70,7 @@ export default class JournalSheetService {
|
||||
* @param {IJournalSheetFilterQuery} query
|
||||
*/
|
||||
async journalSheet(tenantId: number, query: IJournalReportQuery) {
|
||||
const i18n = this.tenancy.i18n(tenantId);
|
||||
const {
|
||||
accountRepository,
|
||||
transactionsRepository,
|
||||
@@ -120,7 +121,8 @@ export default class JournalSheetService {
|
||||
transactionsJournal,
|
||||
accountsGraph,
|
||||
contactsByIdMap,
|
||||
baseCurrency
|
||||
baseCurrency,
|
||||
i18n
|
||||
);
|
||||
// Retrieve journal report columns.
|
||||
const journalSheetData = journalSheetInstance.reportData();
|
||||
|
||||
29
server/src/services/I18n/I18nService.ts
Normal file
29
server/src/services/I18n/I18nService.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import HasTenancyService from 'services/Tenancy/TenancyService';
|
||||
import { Service, Inject } from 'typedi';
|
||||
|
||||
@Service()
|
||||
export default class I18nService {
|
||||
@Inject()
|
||||
tenancy: HasTenancyService;
|
||||
|
||||
/**
|
||||
* Mappes array collection to i18n localization based in given attributes.
|
||||
* @param {Array<any>} data - Array collection.
|
||||
* @param {string[]} attributes - Attributes.
|
||||
* @param {number} tenantId - Tenant id.
|
||||
*/
|
||||
public i18nMapper(
|
||||
data: Array<any>,
|
||||
attributes: string[] = [],
|
||||
tenantId: number
|
||||
) {
|
||||
const i18n = this.tenancy.i18n(tenantId);
|
||||
|
||||
return data.map((_data) => {
|
||||
return {
|
||||
label: i18n.__(_data.label),
|
||||
..._data,
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user