mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 22:30:31 +00:00
fix(server): sales tax liability summary report
This commit is contained in:
@@ -0,0 +1,16 @@
|
|||||||
|
import { TenantSeeder } from '@/lib/Seeder/TenantSeeder';
|
||||||
|
import { InitialTaxRates } from '../data/TaxRates';
|
||||||
|
|
||||||
|
export default class UpdateTaxPayableAccount extends TenantSeeder {
|
||||||
|
/**
|
||||||
|
* Seeds initial tax rates to the organization.
|
||||||
|
*/
|
||||||
|
up(knex) {
|
||||||
|
return knex('accounts').then(async () => {
|
||||||
|
// Inserts seed entries.
|
||||||
|
return knex('accounts').where('slug', 'tax-payable').update({
|
||||||
|
account_type: 'tax-payable',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
export const TaxPayableAccount = {
|
export const TaxPayableAccount = {
|
||||||
name: 'Tax Payable',
|
name: 'Tax Payable',
|
||||||
slug: 'tax-payable',
|
slug: 'tax-payable',
|
||||||
account_type: 'other-current-liability',
|
account_type: 'tax-payable',
|
||||||
code: '20006',
|
code: '20006',
|
||||||
description: '',
|
description: '',
|
||||||
active: 1,
|
active: 1,
|
||||||
|
|||||||
@@ -31,14 +31,17 @@ export class SalesTaxLiabilitySummaryRepository {
|
|||||||
public async taxesPayableSumGroupedByRateId(
|
public async taxesPayableSumGroupedByRateId(
|
||||||
tenantId: number
|
tenantId: number
|
||||||
): Promise<SalesTaxLiabilitySummaryPayableById> {
|
): Promise<SalesTaxLiabilitySummaryPayableById> {
|
||||||
const { AccountTransaction } = this.tenancy.models(tenantId);
|
const { AccountTransaction, Account } = this.tenancy.models(tenantId);
|
||||||
const { accountRepository } = this.tenancy.repositories(tenantId);
|
|
||||||
|
|
||||||
// Finds or creates tax payable account.
|
// Retrieves tax payable accounts.
|
||||||
const payableTaxAccount = await accountRepository.findOrCreateTaxPayable();
|
const taxPayableAccounts = await Account.query().whereIn('accountType', [
|
||||||
|
ACCOUNT_TYPE.TAX_PAYABLE,
|
||||||
|
]);
|
||||||
|
const payableAccountsIds = taxPayableAccounts.map((account) => account.id);
|
||||||
|
|
||||||
const groupedTaxesById = await AccountTransaction.query()
|
const groupedTaxesById = await AccountTransaction.query()
|
||||||
.where('account_id', payableTaxAccount.id)
|
.whereIn('account_id', payableAccountsIds)
|
||||||
|
.whereNot('tax_rate_id', null)
|
||||||
.groupBy('tax_rate_id')
|
.groupBy('tax_rate_id')
|
||||||
.select(['tax_rate_id'])
|
.select(['tax_rate_id'])
|
||||||
.sum('credit as credit')
|
.sum('credit as credit')
|
||||||
@@ -65,6 +68,7 @@ export class SalesTaxLiabilitySummaryRepository {
|
|||||||
|
|
||||||
const groupedTaxesById = await AccountTransaction.query()
|
const groupedTaxesById = await AccountTransaction.query()
|
||||||
.whereIn('account_id', incomeAccountsIds)
|
.whereIn('account_id', incomeAccountsIds)
|
||||||
|
.whereNot('tax_rate_id', null)
|
||||||
.groupBy('tax_rate_id')
|
.groupBy('tax_rate_id')
|
||||||
.select(['tax_rate_id'])
|
.select(['tax_rate_id'])
|
||||||
.sum('credit as credit')
|
.sum('credit as credit')
|
||||||
|
|||||||
Reference in New Issue
Block a user