mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +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 = {
|
||||
name: 'Tax Payable',
|
||||
slug: 'tax-payable',
|
||||
account_type: 'other-current-liability',
|
||||
account_type: 'tax-payable',
|
||||
code: '20006',
|
||||
description: '',
|
||||
active: 1,
|
||||
|
||||
@@ -31,14 +31,17 @@ export class SalesTaxLiabilitySummaryRepository {
|
||||
public async taxesPayableSumGroupedByRateId(
|
||||
tenantId: number
|
||||
): Promise<SalesTaxLiabilitySummaryPayableById> {
|
||||
const { AccountTransaction } = this.tenancy.models(tenantId);
|
||||
const { accountRepository } = this.tenancy.repositories(tenantId);
|
||||
const { AccountTransaction, Account } = this.tenancy.models(tenantId);
|
||||
|
||||
// Finds or creates tax payable account.
|
||||
const payableTaxAccount = await accountRepository.findOrCreateTaxPayable();
|
||||
// Retrieves tax payable accounts.
|
||||
const taxPayableAccounts = await Account.query().whereIn('accountType', [
|
||||
ACCOUNT_TYPE.TAX_PAYABLE,
|
||||
]);
|
||||
const payableAccountsIds = taxPayableAccounts.map((account) => account.id);
|
||||
|
||||
const groupedTaxesById = await AccountTransaction.query()
|
||||
.where('account_id', payableTaxAccount.id)
|
||||
.whereIn('account_id', payableAccountsIds)
|
||||
.whereNot('tax_rate_id', null)
|
||||
.groupBy('tax_rate_id')
|
||||
.select(['tax_rate_id'])
|
||||
.sum('credit as credit')
|
||||
@@ -65,6 +68,7 @@ export class SalesTaxLiabilitySummaryRepository {
|
||||
|
||||
const groupedTaxesById = await AccountTransaction.query()
|
||||
.whereIn('account_id', incomeAccountsIds)
|
||||
.whereNot('tax_rate_id', null)
|
||||
.groupBy('tax_rate_id')
|
||||
.select(['tax_rate_id'])
|
||||
.sum('credit as credit')
|
||||
|
||||
Reference in New Issue
Block a user