mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 14:50:32 +00:00
feat: tax rate transformer
This commit is contained in:
@@ -67,6 +67,8 @@ export default class SalesTaxLiabilitySummary extends BaseFinancialReportControl
|
|||||||
|
|
||||||
return res.status(200).send({
|
return res.status(200).send({
|
||||||
table: salesTaxLiabilityTable.table,
|
table: salesTaxLiabilityTable.table,
|
||||||
|
query: salesTaxLiabilityTable.query,
|
||||||
|
meta: salesTaxLiabilityTable.meta,
|
||||||
});
|
});
|
||||||
case 'json':
|
case 'json':
|
||||||
default:
|
default:
|
||||||
@@ -76,7 +78,9 @@ export default class SalesTaxLiabilitySummary extends BaseFinancialReportControl
|
|||||||
filter
|
filter
|
||||||
);
|
);
|
||||||
return res.status(200).send({
|
return res.status(200).send({
|
||||||
data: salesTaxLiability,
|
data: salesTaxLiability.data,
|
||||||
|
query: salesTaxLiability.query,
|
||||||
|
meta: salesTaxLiability.meta,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -43,3 +43,8 @@ export type SalesTaxLiabilitySummarySalesById = Record<
|
|||||||
string,
|
string,
|
||||||
{ taxRateId: number; credit: number; debit: number }
|
{ taxRateId: number; credit: number; debit: number }
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
export interface SalesTaxLiabilitySummaryMeta {
|
||||||
|
organizationName: string;
|
||||||
|
baseCurrency: string;
|
||||||
|
}
|
||||||
|
|||||||
@@ -111,6 +111,7 @@ export default class ItemEntry extends TenantModel {
|
|||||||
const SaleEstimate = require('models/SaleEstimate');
|
const SaleEstimate = require('models/SaleEstimate');
|
||||||
const ProjectTask = require('models/Task');
|
const ProjectTask = require('models/Task');
|
||||||
const Expense = require('models/Expense');
|
const Expense = require('models/Expense');
|
||||||
|
const TaxRate = require('models/TaxRate');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
item: {
|
item: {
|
||||||
@@ -204,6 +205,18 @@ export default class ItemEntry extends TenantModel {
|
|||||||
to: 'bills.id',
|
to: 'bills.id',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tax rate reference.
|
||||||
|
*/
|
||||||
|
tax: {
|
||||||
|
relation: Model.HasOneRelation,
|
||||||
|
modelClass: TaxRate.default,
|
||||||
|
join: {
|
||||||
|
from: 'items_entries.taxRateId',
|
||||||
|
to: 'tax_rates.id',
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,21 @@
|
|||||||
import { Inject, Service } from 'typedi';
|
import { Inject, Service } from 'typedi';
|
||||||
import { SalesTaxLiabilitySummaryRepository } from './SalesTaxLiabilitySummaryRepository';
|
import { SalesTaxLiabilitySummaryRepository } from './SalesTaxLiabilitySummaryRepository';
|
||||||
import { SalesTaxLiabilitySummaryQuery } from '@/interfaces/SalesTaxLiabilitySummary';
|
import {
|
||||||
|
SalesTaxLiabilitySummaryMeta,
|
||||||
|
SalesTaxLiabilitySummaryQuery,
|
||||||
|
} from '@/interfaces/SalesTaxLiabilitySummary';
|
||||||
import { SalesTaxLiabilitySummary } from './SalesTaxLiabilitySummary';
|
import { SalesTaxLiabilitySummary } from './SalesTaxLiabilitySummary';
|
||||||
import { SalesTaxLiabilitySummaryTable } from './SalesTaxLiabilitySummaryTable';
|
import { SalesTaxLiabilitySummaryTable } from './SalesTaxLiabilitySummaryTable';
|
||||||
|
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export class SalesTaxLiabilitySummaryService {
|
export class SalesTaxLiabilitySummaryService {
|
||||||
@Inject()
|
@Inject()
|
||||||
private repostiory: SalesTaxLiabilitySummaryRepository;
|
private repostiory: SalesTaxLiabilitySummaryRepository;
|
||||||
|
|
||||||
|
@Inject()
|
||||||
|
private tenancy: HasTenancyService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve sales tax liability summary.
|
* Retrieve sales tax liability summary.
|
||||||
* @param {number} tenantId
|
* @param {number} tenantId
|
||||||
@@ -36,7 +43,7 @@ export class SalesTaxLiabilitySummaryService {
|
|||||||
return {
|
return {
|
||||||
data: taxLiabilitySummary.reportData(),
|
data: taxLiabilitySummary.reportData(),
|
||||||
query,
|
query,
|
||||||
meta: {},
|
meta: this.reportMetadata(tenantId),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,6 +67,32 @@ export class SalesTaxLiabilitySummaryService {
|
|||||||
rows: table.tableRows(),
|
rows: table.tableRows(),
|
||||||
columns: table.tableColumns(),
|
columns: table.tableColumns(),
|
||||||
},
|
},
|
||||||
|
data: report.data,
|
||||||
|
query: report.query,
|
||||||
|
meta: report.meta,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the report meta.
|
||||||
|
* @param {number} tenantId -
|
||||||
|
* @returns {IBalanceSheetMeta}
|
||||||
|
*/
|
||||||
|
private reportMetadata(tenantId: number): SalesTaxLiabilitySummaryMeta {
|
||||||
|
const settings = this.tenancy.settings(tenantId);
|
||||||
|
|
||||||
|
const organizationName = settings.get({
|
||||||
|
group: 'organization',
|
||||||
|
key: 'name',
|
||||||
|
});
|
||||||
|
const baseCurrency = settings.get({
|
||||||
|
group: 'organization',
|
||||||
|
key: 'base_currency',
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
organizationName,
|
||||||
|
baseCurrency,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ export class GetSaleInvoice {
|
|||||||
const saleInvoice = await SaleInvoice.query()
|
const saleInvoice = await SaleInvoice.query()
|
||||||
.findById(saleInvoiceId)
|
.findById(saleInvoiceId)
|
||||||
.withGraphFetched('entries.item')
|
.withGraphFetched('entries.item')
|
||||||
|
.withGraphFetched('entries.tax')
|
||||||
.withGraphFetched('customer')
|
.withGraphFetched('customer')
|
||||||
.withGraphFetched('branch')
|
.withGraphFetched('branch')
|
||||||
.withGraphFetched('taxes.taxRate');
|
.withGraphFetched('taxes.taxRate');
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { Inject, Service } from 'typedi';
|
import { Inject, Service } from 'typedi';
|
||||||
import HasTenancyService from '../Tenancy/TenancyService';
|
import HasTenancyService from '../Tenancy/TenancyService';
|
||||||
import { CommandTaxRatesValidators } from './CommandTaxRatesValidators';
|
import { CommandTaxRatesValidators } from './CommandTaxRatesValidators';
|
||||||
|
import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
|
||||||
|
import { TaxRateTransformer } from './TaxRateTransformer';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export class GetTaxRateService {
|
export class GetTaxRateService {
|
||||||
@@ -10,6 +12,9 @@ export class GetTaxRateService {
|
|||||||
@Inject()
|
@Inject()
|
||||||
private validators: CommandTaxRatesValidators;
|
private validators: CommandTaxRatesValidators;
|
||||||
|
|
||||||
|
@Inject()
|
||||||
|
private transformer: TransformerInjectable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the given tax rate.
|
* Retrieves the given tax rate.
|
||||||
* @param {number} tenantId
|
* @param {number} tenantId
|
||||||
@@ -24,6 +29,11 @@ export class GetTaxRateService {
|
|||||||
// Validates the tax rate existance.
|
// Validates the tax rate existance.
|
||||||
this.validators.validateTaxRateExistance(taxRate);
|
this.validators.validateTaxRateExistance(taxRate);
|
||||||
|
|
||||||
return taxRate;
|
// Transforms the tax rate.
|
||||||
|
return this.transformer.transform(
|
||||||
|
tenantId,
|
||||||
|
taxRate,
|
||||||
|
new TaxRateTransformer()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
import { Inject, Service } from 'typedi';
|
import { Inject, Service } from 'typedi';
|
||||||
import HasTenancyService from '../Tenancy/TenancyService';
|
import HasTenancyService from '../Tenancy/TenancyService';
|
||||||
|
import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
|
||||||
|
import { TaxRateTransformer } from './TaxRateTransformer';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export class GetTaxRatesService {
|
export class GetTaxRatesService {
|
||||||
@Inject()
|
@Inject()
|
||||||
private tenancy: HasTenancyService;
|
private tenancy: HasTenancyService;
|
||||||
|
|
||||||
|
@Inject()
|
||||||
|
private transformer: TransformerInjectable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the tax rates list.
|
* Retrieves the tax rates list.
|
||||||
* @param {number} tenantId
|
* @param {number} tenantId
|
||||||
@@ -16,6 +21,11 @@ export class GetTaxRatesService {
|
|||||||
|
|
||||||
const taxRates = await TaxRate.query();
|
const taxRates = await TaxRate.query();
|
||||||
|
|
||||||
return taxRates;
|
// Transforms the tax rates.
|
||||||
|
return this.transformer.transform(
|
||||||
|
tenantId,
|
||||||
|
taxRates,
|
||||||
|
new TaxRateTransformer()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
20
packages/server/src/services/TaxRates/TaxRateTransformer.ts
Normal file
20
packages/server/src/services/TaxRates/TaxRateTransformer.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import { Transformer } from '@/lib/Transformer/Transformer';
|
||||||
|
|
||||||
|
export class TaxRateTransformer extends Transformer {
|
||||||
|
/**
|
||||||
|
* Include these attributes to tax rate object.
|
||||||
|
* @returns {Array}
|
||||||
|
*/
|
||||||
|
public includeAttributes = (): string[] => {
|
||||||
|
return ['nameFormatted'];
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Formats the tax rate name.
|
||||||
|
* @param taxRate
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
protected nameFormatted = (taxRate): string => {
|
||||||
|
return `${taxRate.name} (${taxRate.rate}%)`;
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user