mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 22:00:31 +00:00
refactor: inventory cost to nestjs
This commit is contained in:
@@ -1,55 +1,54 @@
|
||||
// import { Knex } from 'knex';
|
||||
// import { Inject, Service } from 'typedi';
|
||||
// import HasTenancyService from '../Tenancy/TenancyService';
|
||||
import { Knex } from 'knex';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { Item } from '../Items/models/Item';
|
||||
import { TenantModelProxy } from '../System/models/TenantBaseModel';
|
||||
|
||||
// @Service()
|
||||
// export class SyncItemTaxRateOnEditTaxRate {
|
||||
// @Inject()
|
||||
// private tenancy: HasTenancyService;
|
||||
@Injectable()
|
||||
export class SyncItemTaxRateOnEditTaxRate {
|
||||
constructor(
|
||||
@Inject(Item.name)
|
||||
private readonly itemModel: TenantModelProxy<typeof Item>,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Syncs the new tax rate created to item default sell tax rate.
|
||||
// * @param {number} tenantId
|
||||
// * @param {number} itemId
|
||||
// * @param {number} sellTaxRateId
|
||||
// */
|
||||
// public updateItemSellTaxRate = async (
|
||||
// tenantId: number,
|
||||
// oldSellTaxRateId: number,
|
||||
// sellTaxRateId: number,
|
||||
// trx?: Knex.Transaction
|
||||
// ) => {
|
||||
// const { Item } = this.tenancy.models(tenantId);
|
||||
/**
|
||||
* Syncs the new tax rate created to item default sell tax rate.
|
||||
* @param {number} itemId - Item id.
|
||||
* @param {number} sellTaxRateId - Sell tax rate id.
|
||||
*/
|
||||
public updateItemSellTaxRate = async (
|
||||
oldSellTaxRateId: number,
|
||||
sellTaxRateId: number,
|
||||
trx?: Knex.Transaction,
|
||||
) => {
|
||||
// Can't continue if the old and new sell tax rate id are equal.
|
||||
if (oldSellTaxRateId === sellTaxRateId) return;
|
||||
|
||||
// // Can't continue if the old and new sell tax rate id are equal.
|
||||
// if (oldSellTaxRateId === sellTaxRateId) return;
|
||||
await this.itemModel()
|
||||
.query()
|
||||
.where('sellTaxRateId', oldSellTaxRateId)
|
||||
.update({
|
||||
sellTaxRateId,
|
||||
});
|
||||
};
|
||||
|
||||
// await Item.query().where('sellTaxRateId', oldSellTaxRateId).update({
|
||||
// sellTaxRateId,
|
||||
// });
|
||||
// };
|
||||
/**
|
||||
* Syncs the new tax rate created to item default purchase tax rate.
|
||||
* @param {number} itemId
|
||||
* @param {number} purchaseTaxRateId
|
||||
*/
|
||||
public updateItemPurchaseTaxRate = async (
|
||||
oldPurchaseTaxRateId: number,
|
||||
purchaseTaxRateId: number,
|
||||
trx?: Knex.Transaction,
|
||||
) => {
|
||||
// Can't continue if the old and new sell tax rate id are equal.
|
||||
if (oldPurchaseTaxRateId === purchaseTaxRateId) return;
|
||||
|
||||
// /**
|
||||
// * Syncs the new tax rate created to item default purchase tax rate.
|
||||
// * @param {number} tenantId
|
||||
// * @param {number} itemId
|
||||
// * @param {number} purchaseTaxRateId
|
||||
// */
|
||||
// public updateItemPurchaseTaxRate = async (
|
||||
// tenantId: number,
|
||||
// oldPurchaseTaxRateId: number,
|
||||
// purchaseTaxRateId: number,
|
||||
// trx?: Knex.Transaction
|
||||
// ) => {
|
||||
// const { Item } = this.tenancy.models(tenantId);
|
||||
|
||||
// // Can't continue if the old and new sell tax rate id are equal.
|
||||
// if (oldPurchaseTaxRateId === purchaseTaxRateId) return;
|
||||
|
||||
// await Item.query(trx)
|
||||
// .where('purchaseTaxRateId', oldPurchaseTaxRateId)
|
||||
// .update({
|
||||
// purchaseTaxRateId,
|
||||
// });
|
||||
// };
|
||||
// }
|
||||
await this.itemModel()
|
||||
.query(trx)
|
||||
.where('purchaseTaxRateId', oldPurchaseTaxRateId)
|
||||
.update({
|
||||
purchaseTaxRateId,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
// import { Inject, Service } from 'typedi';
|
||||
// import { SyncItemTaxRateOnEditTaxRate } from './SyncItemTaxRateOnEditTaxRate';
|
||||
// import events from '@/subscribers/events';
|
||||
// import { ITaxRateEditedPayload } from '@/interfaces';
|
||||
// import { runAfterTransaction } from '../UnitOfWork/TransactionsHooks';
|
||||
|
||||
// @Service()
|
||||
// export class SyncItemTaxRateOnEditTaxSubscriber {
|
||||
// @Inject()
|
||||
// private syncItemRateOnEdit: SyncItemTaxRateOnEditTaxRate;
|
||||
|
||||
// /**
|
||||
// * Attaches events with handles.
|
||||
// */
|
||||
// public attach(bus) {
|
||||
// bus.subscribe(
|
||||
// events.taxRates.onEdited,
|
||||
// this.handleSyncNewTaxRateToItemTaxRate
|
||||
// );
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Syncs the new tax rate created to default item tax rates.
|
||||
// * @param {ITaxRateEditedPayload} payload -
|
||||
// */
|
||||
// private handleSyncNewTaxRateToItemTaxRate = async ({
|
||||
// taxRate,
|
||||
// tenantId,
|
||||
// oldTaxRate,
|
||||
// trx,
|
||||
// }: ITaxRateEditedPayload) => {
|
||||
// runAfterTransaction(trx, async () => {
|
||||
// await this.syncItemRateOnEdit.updateItemPurchaseTaxRate(
|
||||
// tenantId,
|
||||
// oldTaxRate.id,
|
||||
// taxRate.id
|
||||
// );
|
||||
// await this.syncItemRateOnEdit.updateItemSellTaxRate(
|
||||
// tenantId,
|
||||
// oldTaxRate.id,
|
||||
// taxRate.id
|
||||
// );
|
||||
// });
|
||||
// };
|
||||
// }
|
||||
@@ -12,6 +12,11 @@ import { TenancyContext } from '../Tenancy/TenancyContext.service';
|
||||
import { TaxRatesApplication } from './TaxRate.application';
|
||||
import { ItemEntriesTaxTransactions } from './ItemEntriesTaxTransactions.service';
|
||||
import { GetTaxRatesService } from './queries/GetTaxRates.service';
|
||||
import { WriteBillTaxTransactionsSubscriber } from './subscribers/WriteBillTaxTransactionsSubscriber';
|
||||
import { WriteInvoiceTaxTransactionsSubscriber } from './subscribers/WriteInvoiceTaxTransactionsSubscriber';
|
||||
import { BillTaxRateValidateSubscriber } from './subscribers/BillTaxRateValidateSubscriber';
|
||||
import { SaleInvoiceTaxRateValidateSubscriber } from './subscribers/SaleInvoiceTaxRateValidateSubscriber';
|
||||
import { SyncItemTaxRateOnEditTaxSubscriber } from './subscribers/SyncItemTaxRateOnEditTaxSubscriber';
|
||||
|
||||
@Module({
|
||||
imports: [],
|
||||
@@ -28,7 +33,12 @@ import { GetTaxRatesService } from './queries/GetTaxRates.service';
|
||||
TransformerInjectable,
|
||||
TenancyContext,
|
||||
TaxRatesApplication,
|
||||
ItemEntriesTaxTransactions
|
||||
ItemEntriesTaxTransactions,
|
||||
WriteBillTaxTransactionsSubscriber,
|
||||
WriteInvoiceTaxTransactionsSubscriber,
|
||||
BillTaxRateValidateSubscriber,
|
||||
SaleInvoiceTaxRateValidateSubscriber,
|
||||
SyncItemTaxRateOnEditTaxSubscriber,
|
||||
],
|
||||
exports: [ItemEntriesTaxTransactions],
|
||||
})
|
||||
|
||||
@@ -1,99 +1,105 @@
|
||||
// import { sumBy, chain, keyBy } from 'lodash';
|
||||
// import { IItemEntry, ITaxTransaction } from '@/interfaces';
|
||||
// import HasTenancyService from '../Tenancy/TenancyService';
|
||||
// import { Inject, Service } from 'typedi';
|
||||
// import { Knex } from 'knex';
|
||||
import { sumBy, chain, keyBy } from 'lodash';
|
||||
import { Knex } from 'knex';
|
||||
import { SaleInvoice } from '../SaleInvoices/models/SaleInvoice';
|
||||
import { TenantModelProxy } from '../System/models/TenantBaseModel';
|
||||
import { TaxRateModel } from './models/TaxRate.model';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { ModelObject } from 'objection';
|
||||
import { ItemEntry } from '../TransactionItemEntry/models/ItemEntry';
|
||||
|
||||
// @Service()
|
||||
// export class WriteTaxTransactionsItemEntries {
|
||||
// @Inject()
|
||||
// private tenancy: HasTenancyService;
|
||||
@Injectable()
|
||||
export class WriteTaxTransactionsItemEntries {
|
||||
constructor(
|
||||
@Inject(SaleInvoice.name)
|
||||
private readonly taxRateTransactionModel: TenantModelProxy<
|
||||
typeof SaleInvoice
|
||||
>,
|
||||
|
||||
// /**
|
||||
// * Writes the tax transactions from the given item entries.
|
||||
// * @param {number} tenantId
|
||||
// * @param {IItemEntry[]} itemEntries
|
||||
// */
|
||||
// public async writeTaxTransactionsFromItemEntries(
|
||||
// tenantId: number,
|
||||
// itemEntries: IItemEntry[],
|
||||
// trx?: Knex.Transaction
|
||||
// ) {
|
||||
// const { TaxRateTransaction, TaxRate } = this.tenancy.models(tenantId);
|
||||
// const aggregatedEntries = this.aggregateItemEntriesByTaxCode(itemEntries);
|
||||
@Inject(TaxRateModel.name)
|
||||
private readonly taxRateModel: TenantModelProxy<typeof TaxRateModel>,
|
||||
) {}
|
||||
|
||||
// const entriesTaxRateIds = aggregatedEntries.map((entry) => entry.taxRateId);
|
||||
/**
|
||||
* Writes the tax transactions from the given item entries.
|
||||
* @param {number} tenantId
|
||||
* @param {IItemEntry[]} itemEntries
|
||||
*/
|
||||
public async writeTaxTransactionsFromItemEntries(
|
||||
itemEntries: ModelObject<ItemEntry>[],
|
||||
trx?: Knex.Transaction,
|
||||
) {
|
||||
const aggregatedEntries = this.aggregateItemEntriesByTaxCode(itemEntries);
|
||||
const entriesTaxRateIds = aggregatedEntries.map((entry) => entry.taxRateId);
|
||||
|
||||
// const taxRates = await TaxRate.query(trx).whereIn('id', entriesTaxRateIds);
|
||||
// const taxRatesById = keyBy(taxRates, 'id');
|
||||
const taxRates = await this.taxRateModel()
|
||||
.query(trx)
|
||||
.whereIn('id', entriesTaxRateIds);
|
||||
const taxRatesById = keyBy(taxRates, 'id');
|
||||
|
||||
// const taxTransactions = aggregatedEntries.map((entry) => ({
|
||||
// taxRateId: entry.taxRateId,
|
||||
// referenceType: entry.referenceType,
|
||||
// referenceId: entry.referenceId,
|
||||
// rate: entry.taxRate || taxRatesById[entry.taxRateId]?.rate,
|
||||
// })) as ITaxTransaction[];
|
||||
const taxTransactions = aggregatedEntries.map((entry) => ({
|
||||
taxRateId: entry.taxRateId,
|
||||
referenceType: entry.referenceType,
|
||||
referenceId: entry.referenceId,
|
||||
rate: entry.taxRate || taxRatesById[entry.taxRateId]?.rate,
|
||||
}));
|
||||
await this.taxRateTransactionModel()
|
||||
.query(trx)
|
||||
.upsertGraph(taxTransactions);
|
||||
}
|
||||
|
||||
// await TaxRateTransaction.query(trx).upsertGraph(taxTransactions);
|
||||
// }
|
||||
/**
|
||||
* Rewrites the tax rate transactions from the given item entries.
|
||||
* @param {number} tenantId
|
||||
* @param {IItemEntry[]} itemEntries
|
||||
* @param {string} referenceType
|
||||
* @param {number} referenceId
|
||||
* @param {Knex.Transaction} trx
|
||||
*/
|
||||
public async rewriteTaxRateTransactionsFromItemEntries(
|
||||
itemEntries: ModelObject<ItemEntry>[],
|
||||
referenceType: string,
|
||||
referenceId: number,
|
||||
trx?: Knex.Transaction,
|
||||
) {
|
||||
await Promise.all([
|
||||
this.removeTaxTransactionsFromItemEntries(
|
||||
referenceId,
|
||||
referenceType,
|
||||
trx,
|
||||
),
|
||||
this.writeTaxTransactionsFromItemEntries(itemEntries, trx),
|
||||
]);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Rewrites the tax rate transactions from the given item entries.
|
||||
// * @param {number} tenantId
|
||||
// * @param {IItemEntry[]} itemEntries
|
||||
// * @param {string} referenceType
|
||||
// * @param {number} referenceId
|
||||
// * @param {Knex.Transaction} trx
|
||||
// */
|
||||
// public async rewriteTaxRateTransactionsFromItemEntries(
|
||||
// tenantId: number,
|
||||
// itemEntries: IItemEntry[],
|
||||
// referenceType: string,
|
||||
// referenceId: number,
|
||||
// trx?: Knex.Transaction
|
||||
// ) {
|
||||
// await Promise.all([
|
||||
// this.removeTaxTransactionsFromItemEntries(
|
||||
// tenantId,
|
||||
// referenceId,
|
||||
// referenceType,
|
||||
// trx
|
||||
// ),
|
||||
// this.writeTaxTransactionsFromItemEntries(tenantId, itemEntries, trx),
|
||||
// ]);
|
||||
// }
|
||||
/**
|
||||
* Aggregates by tax code id and sums the amount.
|
||||
* @param {IItemEntry[]} itemEntries
|
||||
* @returns {IItemEntry[]}
|
||||
*/
|
||||
private aggregateItemEntriesByTaxCode = (
|
||||
itemEntries: ModelObject<ItemEntry>[],
|
||||
): ModelObject<ItemEntry>[] => {
|
||||
return chain(itemEntries.filter((item) => item.taxRateId))
|
||||
.groupBy((item) => item.taxRateId)
|
||||
.values()
|
||||
.map((group) => ({ ...group[0], amount: sumBy(group, 'amount') }))
|
||||
.value();
|
||||
};
|
||||
|
||||
// /**
|
||||
// * Aggregates by tax code id and sums the amount.
|
||||
// * @param {IItemEntry[]} itemEntries
|
||||
// * @returns {IItemEntry[]}
|
||||
// */
|
||||
// private aggregateItemEntriesByTaxCode = (
|
||||
// itemEntries: IItemEntry[]
|
||||
// ): IItemEntry[] => {
|
||||
// return chain(itemEntries.filter((item) => item.taxRateId))
|
||||
// .groupBy((item) => item.taxRateId)
|
||||
// .values()
|
||||
// .map((group) => ({ ...group[0], amount: sumBy(group, 'amount') }))
|
||||
// .value();
|
||||
// };
|
||||
|
||||
// /**
|
||||
// * Removes the tax transactions from the given item entries.
|
||||
// * @param {number} tenantId - Tenant id.
|
||||
// * @param {string} referenceType - Reference type.
|
||||
// * @param {number} referenceId - Reference id.
|
||||
// */
|
||||
// public async removeTaxTransactionsFromItemEntries(
|
||||
// tenantId: number,
|
||||
// referenceId: number,
|
||||
// referenceType: string,
|
||||
// trx?: Knex.Transaction
|
||||
// ) {
|
||||
// const { TaxRateTransaction } = this.tenancy.models(tenantId);
|
||||
|
||||
// await TaxRateTransaction.query(trx)
|
||||
// .where({ referenceType, referenceId })
|
||||
// .delete();
|
||||
// }
|
||||
// }
|
||||
/**
|
||||
* Removes the tax transactions from the given item entries.
|
||||
* @param {number} tenantId - Tenant id.
|
||||
* @param {string} referenceType - Reference type.
|
||||
* @param {number} referenceId - Reference id.
|
||||
*/
|
||||
public async removeTaxTransactionsFromItemEntries(
|
||||
referenceId: number,
|
||||
referenceType: string,
|
||||
trx?: Knex.Transaction,
|
||||
) {
|
||||
await this.taxRateTransactionModel()
|
||||
.query(trx)
|
||||
.where({ referenceType, referenceId })
|
||||
.delete();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import { Inject } from '@nestjs/common';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { ServiceError } from '@/modules/Items/ServiceError';
|
||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||
import { IItemEntryDTO } from '@/modules/TransactionItemEntry/ItemEntry.types';
|
||||
|
||||
@Injectable()
|
||||
export class CommandTaxRatesValidators {
|
||||
@@ -70,46 +71,46 @@ export class CommandTaxRatesValidators {
|
||||
* @param {IItemEntryDTO[]} itemEntriesDTO
|
||||
* @throws {ServiceError}
|
||||
*/
|
||||
// public async validateItemEntriesTaxCode(itemEntriesDTO: IItemEntryDTO[]) {
|
||||
// const filteredTaxEntries = itemEntriesDTO.filter((e) => e.taxCode);
|
||||
// const taxCodes = filteredTaxEntries.map((e) => e.taxCode);
|
||||
public async validateItemEntriesTaxCode(itemEntriesDTO: IItemEntryDTO[]) {
|
||||
const filteredTaxEntries = itemEntriesDTO.filter((e) => e.taxCode);
|
||||
const taxCodes = filteredTaxEntries.map((e) => e.taxCode);
|
||||
|
||||
// // Can't validate if there is no tax codes.
|
||||
// if (taxCodes.length === 0) return;
|
||||
// Can't validate if there is no tax codes.
|
||||
if (taxCodes.length === 0) return;
|
||||
|
||||
// const foundTaxCodes = await this.taxRateModel
|
||||
// .query()
|
||||
// .whereIn('code', taxCodes);
|
||||
// const foundCodes = foundTaxCodes.map((tax) => tax.code);
|
||||
const foundTaxCodes = await this.taxRateModel()
|
||||
.query()
|
||||
.whereIn('code', taxCodes);
|
||||
const foundCodes = foundTaxCodes.map((tax) => tax.code);
|
||||
|
||||
// const notFoundTaxCodes = difference(taxCodes, foundCodes);
|
||||
const notFoundTaxCodes = difference(taxCodes, foundCodes);
|
||||
|
||||
// if (notFoundTaxCodes.length > 0) {
|
||||
// throw new ServiceError(ERRORS.ITEM_ENTRY_TAX_RATE_CODE_NOT_FOUND);
|
||||
// }
|
||||
// }
|
||||
if (notFoundTaxCodes.length > 0) {
|
||||
throw new ServiceError(ERRORS.ITEM_ENTRY_TAX_RATE_CODE_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the tax rate id of the given item entries DTO.
|
||||
* @param {IItemEntryDTO[]} itemEntriesDTO
|
||||
* @throws {ServiceError}
|
||||
*/
|
||||
// public async validateItemEntriesTaxCodeId(itemEntriesDTO: IItemEntryDTO[]) {
|
||||
// const filteredTaxEntries = itemEntriesDTO.filter((e) => e.taxRateId);
|
||||
// const taxRatesIds = filteredTaxEntries.map((e) => e.taxRateId);
|
||||
public async validateItemEntriesTaxCodeId(itemEntriesDTO: IItemEntryDTO[]) {
|
||||
const filteredTaxEntries = itemEntriesDTO.filter((e) => e.taxRateId);
|
||||
const taxRatesIds = filteredTaxEntries.map((e) => e.taxRateId);
|
||||
|
||||
// // Can't validate if there is no tax codes.
|
||||
// if (taxRatesIds.length === 0) return;
|
||||
// Can't validate if there is no tax codes.
|
||||
if (taxRatesIds.length === 0) return;
|
||||
|
||||
// const foundTaxCodes = await this.taxRateModel
|
||||
// .query()
|
||||
// .whereIn('id', taxRatesIds);
|
||||
// const foundTaxRatesIds = foundTaxCodes.map((tax) => tax.id);
|
||||
const foundTaxCodes = await this.taxRateModel()
|
||||
.query()
|
||||
.whereIn('id', taxRatesIds);
|
||||
const foundTaxRatesIds = foundTaxCodes.map((tax) => tax.id);
|
||||
|
||||
// const notFoundTaxCodes = difference(taxRatesIds, foundTaxRatesIds);
|
||||
const notFoundTaxCodes = difference(taxRatesIds, foundTaxRatesIds);
|
||||
|
||||
// if (notFoundTaxCodes.length > 0) {
|
||||
// throw new ServiceError(ERRORS.ITEM_ENTRY_TAX_RATE_ID_NOT_FOUND);
|
||||
// }
|
||||
// }
|
||||
if (notFoundTaxCodes.length > 0) {
|
||||
throw new ServiceError(ERRORS.ITEM_ENTRY_TAX_RATE_ID_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,13 @@ import { mixin, Model, raw } from 'objection';
|
||||
import { BaseModel } from '@/models/Model';
|
||||
|
||||
export class TaxRateTransaction extends BaseModel {
|
||||
id: number;
|
||||
taxRateId: number;
|
||||
referenceType: string;
|
||||
referenceId: number;
|
||||
rate: number;
|
||||
taxAccountId: number;
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*/
|
||||
|
||||
@@ -1,89 +1,61 @@
|
||||
// import { Inject, Service } from 'typedi';
|
||||
// import { IBillCreatingPayload, IBillEditingPayload } from '@/interfaces';
|
||||
// import events from '@/subscribers/events';
|
||||
// import { CommandTaxRatesValidators } from '../commands/CommandTaxRatesValidator.service';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { events } from '@/common/events/events';
|
||||
import { CommandTaxRatesValidators } from '../commands/CommandTaxRatesValidator.service';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { IBillCreatingPayload } from '@/modules/Bills/Bills.types';
|
||||
import { IBillEditingPayload } from '@/modules/Bills/Bills.types';
|
||||
|
||||
// @Service()
|
||||
// export class BillTaxRateValidateSubscriber {
|
||||
// @Inject()
|
||||
// private taxRateDTOValidator: CommandTaxRatesValidators;
|
||||
@Injectable()
|
||||
export class BillTaxRateValidateSubscriber {
|
||||
constructor(
|
||||
private readonly taxRateDTOValidator: CommandTaxRatesValidators,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// public attach(bus) {
|
||||
// bus.subscribe(
|
||||
// events.bill.onCreating,
|
||||
// this.validateBillEntriesTaxCodeExistanceOnCreating
|
||||
// );
|
||||
// bus.subscribe(
|
||||
// events.bill.onCreating,
|
||||
// this.validateBillEntriesTaxIdExistanceOnCreating
|
||||
// );
|
||||
// bus.subscribe(
|
||||
// events.bill.onEditing,
|
||||
// this.validateBillEntriesTaxCodeExistanceOnEditing
|
||||
// );
|
||||
// bus.subscribe(
|
||||
// events.bill.onEditing,
|
||||
// this.validateBillEntriesTaxIdExistanceOnEditing
|
||||
// );
|
||||
// return bus;
|
||||
// }
|
||||
/**
|
||||
* Validate bill entries tax rate code existance when creating.
|
||||
* @param {IBillCreatingPayload}
|
||||
*/
|
||||
@OnEvent(events.bill.onCreating)
|
||||
async validateBillEntriesTaxCodeExistanceOnCreating({
|
||||
billDTO,
|
||||
}: IBillCreatingPayload) {
|
||||
await this.taxRateDTOValidator.validateItemEntriesTaxCode(billDTO.entries);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Validate bill entries tax rate code existance when creating.
|
||||
// * @param {IBillCreatingPayload}
|
||||
// */
|
||||
// private validateBillEntriesTaxCodeExistanceOnCreating = async ({
|
||||
// billDTO,
|
||||
// tenantId,
|
||||
// }: IBillCreatingPayload) => {
|
||||
// await this.taxRateDTOValidator.validateItemEntriesTaxCode(
|
||||
// tenantId,
|
||||
// billDTO.entries
|
||||
// );
|
||||
// };
|
||||
/**
|
||||
* Validate the tax rate id existance when creating.
|
||||
* @param {IBillCreatingPayload}
|
||||
*/
|
||||
@OnEvent(events.bill.onCreating)
|
||||
async validateBillEntriesTaxIdExistanceOnCreating({
|
||||
billDTO,
|
||||
}: IBillCreatingPayload) {
|
||||
await this.taxRateDTOValidator.validateItemEntriesTaxCodeId(
|
||||
billDTO.entries,
|
||||
);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Validate the tax rate id existance when creating.
|
||||
// * @param {IBillCreatingPayload}
|
||||
// */
|
||||
// private validateBillEntriesTaxIdExistanceOnCreating = async ({
|
||||
// billDTO,
|
||||
// tenantId,
|
||||
// }: IBillCreatingPayload) => {
|
||||
// await this.taxRateDTOValidator.validateItemEntriesTaxCodeId(
|
||||
// tenantId,
|
||||
// billDTO.entries
|
||||
// );
|
||||
// };
|
||||
/**
|
||||
* Validate bill entries tax rate code existance when editing.
|
||||
* @param {IBillEditingPayload}
|
||||
*/
|
||||
@OnEvent(events.bill.onEditing)
|
||||
async validateBillEntriesTaxCodeExistanceOnEditing({
|
||||
billDTO,
|
||||
}: IBillEditingPayload) {
|
||||
await this.taxRateDTOValidator.validateItemEntriesTaxCode(billDTO.entries);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Validate bill entries tax rate code existance when editing.
|
||||
// * @param {IBillEditingPayload}
|
||||
// */
|
||||
// private validateBillEntriesTaxCodeExistanceOnEditing = async ({
|
||||
// tenantId,
|
||||
// billDTO,
|
||||
// }: IBillEditingPayload) => {
|
||||
// await this.taxRateDTOValidator.validateItemEntriesTaxCode(
|
||||
// tenantId,
|
||||
// billDTO.entries
|
||||
// );
|
||||
// };
|
||||
|
||||
// /**
|
||||
// * Validates the bill entries tax rate id existance when editing.
|
||||
// * @param {ISaleInvoiceEditingPayload} payload -
|
||||
// */
|
||||
// private validateBillEntriesTaxIdExistanceOnEditing = async ({
|
||||
// tenantId,
|
||||
// billDTO,
|
||||
// }: IBillEditingPayload) => {
|
||||
// await this.taxRateDTOValidator.validateItemEntriesTaxCodeId(
|
||||
// tenantId,
|
||||
// billDTO.entries
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Validates the bill entries tax rate id existance when editing.
|
||||
* @param {ISaleInvoiceEditingPayload} payload -
|
||||
*/
|
||||
@OnEvent(events.bill.onEditing)
|
||||
async validateBillEntriesTaxIdExistanceOnEditing({
|
||||
billDTO,
|
||||
}: IBillEditingPayload) {
|
||||
await this.taxRateDTOValidator.validateItemEntriesTaxCodeId(
|
||||
billDTO.entries,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,92 +1,67 @@
|
||||
// import { Inject, Service } from 'typedi';
|
||||
// import {
|
||||
// ISaleInvoiceCreatingPaylaod,
|
||||
// ISaleInvoiceEditingPayload,
|
||||
// } from '@/interfaces';
|
||||
// import events from '@/subscribers/events';
|
||||
// import { CommandTaxRatesValidators } from '../commands/CommandTaxRatesValidator.service';
|
||||
import { CommandTaxRatesValidators } from '../commands/CommandTaxRatesValidator.service';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import {
|
||||
ISaleInvoiceCreatingPaylaod,
|
||||
ISaleInvoiceEditingPayload,
|
||||
} from '@/modules/SaleInvoices/SaleInvoice.types';
|
||||
import { events } from '@/common/events/events';
|
||||
|
||||
// @Service()
|
||||
// export class SaleInvoiceTaxRateValidateSubscriber {
|
||||
// @Inject()
|
||||
// private taxRateDTOValidator: CommandTaxRatesValidators;
|
||||
@Injectable()
|
||||
export class SaleInvoiceTaxRateValidateSubscriber {
|
||||
constructor(
|
||||
private readonly taxRateDTOValidator: CommandTaxRatesValidators,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// public attach(bus) {
|
||||
// bus.subscribe(
|
||||
// events.saleInvoice.onCreating,
|
||||
// this.validateSaleInvoiceEntriesTaxCodeExistanceOnCreating
|
||||
// );
|
||||
// bus.subscribe(
|
||||
// events.saleInvoice.onCreating,
|
||||
// this.validateSaleInvoiceEntriesTaxIdExistanceOnCreating
|
||||
// );
|
||||
// bus.subscribe(
|
||||
// events.saleInvoice.onEditing,
|
||||
// this.validateSaleInvoiceEntriesTaxCodeExistanceOnEditing
|
||||
// );
|
||||
// bus.subscribe(
|
||||
// events.saleInvoice.onEditing,
|
||||
// this.validateSaleInvoiceEntriesTaxIdExistanceOnEditing
|
||||
// );
|
||||
// return bus;
|
||||
// }
|
||||
/**
|
||||
* Validate invoice entries tax rate code existance when creating.
|
||||
* @param {ISaleInvoiceCreatingPaylaod}
|
||||
*/
|
||||
@OnEvent(events.saleInvoice.onCreating)
|
||||
async validateSaleInvoiceEntriesTaxCodeExistanceOnCreating({
|
||||
saleInvoiceDTO,
|
||||
}: ISaleInvoiceCreatingPaylaod) {
|
||||
await this.taxRateDTOValidator.validateItemEntriesTaxCode(
|
||||
saleInvoiceDTO.entries,
|
||||
);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Validate invoice entries tax rate code existance when creating.
|
||||
// * @param {ISaleInvoiceCreatingPaylaod}
|
||||
// */
|
||||
// private validateSaleInvoiceEntriesTaxCodeExistanceOnCreating = async ({
|
||||
// saleInvoiceDTO,
|
||||
// tenantId,
|
||||
// }: ISaleInvoiceCreatingPaylaod) => {
|
||||
// await this.taxRateDTOValidator.validateItemEntriesTaxCode(
|
||||
// tenantId,
|
||||
// saleInvoiceDTO.entries
|
||||
// );
|
||||
// };
|
||||
/**
|
||||
* Validate the tax rate id existance when creating.
|
||||
* @param {ISaleInvoiceCreatingPaylaod}
|
||||
*/
|
||||
@OnEvent(events.saleInvoice.onCreating)
|
||||
async validateSaleInvoiceEntriesTaxIdExistanceOnCreating({
|
||||
saleInvoiceDTO,
|
||||
}: ISaleInvoiceCreatingPaylaod) {
|
||||
await this.taxRateDTOValidator.validateItemEntriesTaxCodeId(
|
||||
saleInvoiceDTO.entries,
|
||||
);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Validate the tax rate id existance when creating.
|
||||
// * @param {ISaleInvoiceCreatingPaylaod}
|
||||
// */
|
||||
// private validateSaleInvoiceEntriesTaxIdExistanceOnCreating = async ({
|
||||
// saleInvoiceDTO,
|
||||
// tenantId,
|
||||
// }: ISaleInvoiceCreatingPaylaod) => {
|
||||
// await this.taxRateDTOValidator.validateItemEntriesTaxCodeId(
|
||||
// tenantId,
|
||||
// saleInvoiceDTO.entries
|
||||
// );
|
||||
// };
|
||||
/**
|
||||
* Validate invoice entries tax rate code existance when editing.
|
||||
* @param {ISaleInvoiceEditingPayload}
|
||||
*/
|
||||
@OnEvent(events.saleInvoice.onEditing)
|
||||
async validateSaleInvoiceEntriesTaxCodeExistanceOnEditing({
|
||||
saleInvoiceDTO,
|
||||
}: ISaleInvoiceEditingPayload) {
|
||||
await this.taxRateDTOValidator.validateItemEntriesTaxCode(
|
||||
saleInvoiceDTO.entries,
|
||||
);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Validate invoice entries tax rate code existance when editing.
|
||||
// * @param {ISaleInvoiceEditingPayload}
|
||||
// */
|
||||
// private validateSaleInvoiceEntriesTaxCodeExistanceOnEditing = async ({
|
||||
// tenantId,
|
||||
// saleInvoiceDTO,
|
||||
// }: ISaleInvoiceEditingPayload) => {
|
||||
// await this.taxRateDTOValidator.validateItemEntriesTaxCode(
|
||||
// tenantId,
|
||||
// saleInvoiceDTO.entries
|
||||
// );
|
||||
// };
|
||||
|
||||
// /**
|
||||
// * Validates the invoice entries tax rate id existance when editing.
|
||||
// * @param {ISaleInvoiceEditingPayload} payload -
|
||||
// */
|
||||
// private validateSaleInvoiceEntriesTaxIdExistanceOnEditing = async ({
|
||||
// tenantId,
|
||||
// saleInvoiceDTO,
|
||||
// }: ISaleInvoiceEditingPayload) => {
|
||||
// await this.taxRateDTOValidator.validateItemEntriesTaxCodeId(
|
||||
// tenantId,
|
||||
// saleInvoiceDTO.entries
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Validates the invoice entries tax rate id existance when editing.
|
||||
* @param {ISaleInvoiceEditingPayload} payload -
|
||||
*/
|
||||
@OnEvent(events.saleInvoice.onEditing)
|
||||
async validateSaleInvoiceEntriesTaxIdExistanceOnEditing({
|
||||
saleInvoiceDTO,
|
||||
}: ISaleInvoiceEditingPayload) {
|
||||
await this.taxRateDTOValidator.validateItemEntriesTaxCodeId(
|
||||
saleInvoiceDTO.entries,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { ITaxRateEditedPayload } from '../TaxRates.types';
|
||||
import { runAfterTransaction } from '@/modules/Tenancy/TenancyDB/TransactionsHooks';
|
||||
import { events } from '@/common/events/events';
|
||||
import { SyncItemTaxRateOnEditTaxRate } from '../SyncItemTaxRateOnEditTaxRate';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
|
||||
@Injectable()
|
||||
export class SyncItemTaxRateOnEditTaxSubscriber {
|
||||
constructor(
|
||||
private readonly syncItemRateOnEdit: SyncItemTaxRateOnEditTaxRate,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Syncs the new tax rate created to default item tax rates.
|
||||
* @param {ITaxRateEditedPayload} payload -
|
||||
*/
|
||||
@OnEvent(events.taxRates.onEdited)
|
||||
async handleSyncNewTaxRateToItemTaxRate({
|
||||
taxRate,
|
||||
oldTaxRate,
|
||||
trx,
|
||||
}: ITaxRateEditedPayload) {
|
||||
runAfterTransaction(trx, async () => {
|
||||
await this.syncItemRateOnEdit.updateItemPurchaseTaxRate(
|
||||
oldTaxRate.id,
|
||||
taxRate.id,
|
||||
);
|
||||
await this.syncItemRateOnEdit.updateItemSellTaxRate(
|
||||
oldTaxRate.id,
|
||||
taxRate.id,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,87 +1,65 @@
|
||||
// import { Inject, Service } from 'typedi';
|
||||
// import {
|
||||
// IBIllEventDeletedPayload,
|
||||
// IBillCreatedPayload,
|
||||
// IBillEditedPayload,
|
||||
// ISaleInvoiceCreatedPayload,
|
||||
// ISaleInvoiceDeletedPayload,
|
||||
// ISaleInvoiceEditedPayload,
|
||||
// } from '@/interfaces';
|
||||
// import events from '@/subscribers/events';
|
||||
// import { WriteTaxTransactionsItemEntries } from '../WriteTaxTransactionsItemEntries';
|
||||
import {
|
||||
IBIllEventDeletedPayload,
|
||||
IBillCreatedPayload,
|
||||
IBillEditedPayload,
|
||||
} from '@/modules/Bills/Bills.types';
|
||||
import { WriteTaxTransactionsItemEntries } from '../WriteTaxTransactionsItemEntries';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { events } from '@/common/events/events';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
|
||||
// @Service()
|
||||
// export class WriteBillTaxTransactionsSubscriber {
|
||||
// @Inject()
|
||||
// private writeTaxTransactions: WriteTaxTransactionsItemEntries;
|
||||
@Injectable()
|
||||
export class WriteBillTaxTransactionsSubscriber {
|
||||
constructor(
|
||||
@Inject()
|
||||
private readonly writeTaxTransactions: WriteTaxTransactionsItemEntries,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// public attach(bus) {
|
||||
// bus.subscribe(
|
||||
// events.bill.onCreated,
|
||||
// this.writeInvoiceTaxTransactionsOnCreated
|
||||
// );
|
||||
// bus.subscribe(
|
||||
// events.bill.onEdited,
|
||||
// this.rewriteInvoiceTaxTransactionsOnEdited
|
||||
// );
|
||||
// bus.subscribe(
|
||||
// events.bill.onDeleted,
|
||||
// this.removeInvoiceTaxTransactionsOnDeleted
|
||||
// );
|
||||
// return bus;
|
||||
// }
|
||||
/**
|
||||
* Writes the bill tax transactions on invoice created.
|
||||
* @param {ISaleInvoiceCreatingPaylaod}
|
||||
*/
|
||||
@OnEvent(events.bill.onCreated)
|
||||
async writeInvoiceTaxTransactionsOnCreated({
|
||||
bill,
|
||||
trx,
|
||||
}: IBillCreatedPayload) {
|
||||
await this.writeTaxTransactions.writeTaxTransactionsFromItemEntries(
|
||||
bill.entries,
|
||||
trx,
|
||||
);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Writes the bill tax transactions on invoice created.
|
||||
// * @param {ISaleInvoiceCreatingPaylaod}
|
||||
// */
|
||||
// private writeInvoiceTaxTransactionsOnCreated = async ({
|
||||
// tenantId,
|
||||
// bill,
|
||||
// trx,
|
||||
// }: IBillCreatedPayload) => {
|
||||
// await this.writeTaxTransactions.writeTaxTransactionsFromItemEntries(
|
||||
// tenantId,
|
||||
// bill.entries,
|
||||
// trx
|
||||
// );
|
||||
// };
|
||||
/**
|
||||
* Rewrites the bill tax transactions on invoice edited.
|
||||
* @param {IBillEditedPayload} payload -
|
||||
*/
|
||||
@OnEvent(events.bill.onEdited)
|
||||
async rewriteInvoiceTaxTransactionsOnEdited({
|
||||
bill,
|
||||
trx,
|
||||
}: IBillEditedPayload) {
|
||||
await this.writeTaxTransactions.rewriteTaxRateTransactionsFromItemEntries(
|
||||
bill.entries,
|
||||
'Bill',
|
||||
bill.id,
|
||||
trx,
|
||||
);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Rewrites the bill tax transactions on invoice edited.
|
||||
// * @param {IBillEditedPayload} payload -
|
||||
// */
|
||||
// private rewriteInvoiceTaxTransactionsOnEdited = async ({
|
||||
// tenantId,
|
||||
// bill,
|
||||
// trx,
|
||||
// }: IBillEditedPayload) => {
|
||||
// await this.writeTaxTransactions.rewriteTaxRateTransactionsFromItemEntries(
|
||||
// tenantId,
|
||||
// bill.entries,
|
||||
// 'Bill',
|
||||
// bill.id,
|
||||
// trx
|
||||
// );
|
||||
// };
|
||||
|
||||
// /**
|
||||
// * Removes the invoice tax transactions on invoice deleted.
|
||||
// * @param {IBIllEventDeletedPayload}
|
||||
// */
|
||||
// private removeInvoiceTaxTransactionsOnDeleted = async ({
|
||||
// tenantId,
|
||||
// oldBill,
|
||||
// trx,
|
||||
// }: IBIllEventDeletedPayload) => {
|
||||
// await this.writeTaxTransactions.removeTaxTransactionsFromItemEntries(
|
||||
// tenantId,
|
||||
// oldBill.id,
|
||||
// 'Bill',
|
||||
// trx
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Removes the invoice tax transactions on invoice deleted.
|
||||
* @param {IBIllEventDeletedPayload}
|
||||
*/
|
||||
@OnEvent(events.bill.onDeleted)
|
||||
async removeInvoiceTaxTransactionsOnDeleted({
|
||||
oldBill,
|
||||
trx,
|
||||
}: IBIllEventDeletedPayload) {
|
||||
await this.writeTaxTransactions.removeTaxTransactionsFromItemEntries(
|
||||
oldBill.id,
|
||||
'Bill',
|
||||
trx,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,84 +1,64 @@
|
||||
// import { Inject, Service } from 'typedi';
|
||||
// import {
|
||||
// ISaleInvoiceCreatedPayload,
|
||||
// ISaleInvoiceDeletedPayload,
|
||||
// ISaleInvoiceEditedPayload,
|
||||
// } from '@/interfaces';
|
||||
// import events from '@/subscribers/events';
|
||||
// import { WriteTaxTransactionsItemEntries } from '../WriteTaxTransactionsItemEntries';
|
||||
import {
|
||||
ISaleInvoiceDeletedPayload,
|
||||
ISaleInvoiceEditedPayload,
|
||||
} from '@/modules/SaleInvoices/SaleInvoice.types';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { WriteTaxTransactionsItemEntries } from '../WriteTaxTransactionsItemEntries';
|
||||
import { events } from '@/common/events/events';
|
||||
import { ISaleInvoiceCreatedPayload } from '@/modules/SaleInvoices/SaleInvoice.types';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
// @Service()
|
||||
// export class WriteInvoiceTaxTransactionsSubscriber {
|
||||
// @Inject()
|
||||
// private writeTaxTransactions: WriteTaxTransactionsItemEntries;
|
||||
@Injectable()
|
||||
export class WriteInvoiceTaxTransactionsSubscriber {
|
||||
constructor(
|
||||
private readonly writeTaxTransactions: WriteTaxTransactionsItemEntries,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// public attach(bus) {
|
||||
// bus.subscribe(
|
||||
// events.saleInvoice.onCreated,
|
||||
// this.writeInvoiceTaxTransactionsOnCreated
|
||||
// );
|
||||
// bus.subscribe(
|
||||
// events.saleInvoice.onEdited,
|
||||
// this.rewriteInvoiceTaxTransactionsOnEdited
|
||||
// );
|
||||
// bus.subscribe(
|
||||
// events.saleInvoice.onDelete,
|
||||
// this.removeInvoiceTaxTransactionsOnDeleted
|
||||
// );
|
||||
// return bus;
|
||||
// }
|
||||
/**
|
||||
* Writes the invoice tax transactions on invoice created.
|
||||
* @param {ISaleInvoiceCreatingPaylaod}
|
||||
*/
|
||||
@OnEvent(events.saleInvoice.onCreated)
|
||||
async writeInvoiceTaxTransactionsOnCreated({
|
||||
saleInvoice,
|
||||
trx,
|
||||
}: ISaleInvoiceCreatedPayload) {
|
||||
await this.writeTaxTransactions.writeTaxTransactionsFromItemEntries(
|
||||
saleInvoice.entries,
|
||||
trx,
|
||||
);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Writes the invoice tax transactions on invoice created.
|
||||
// * @param {ISaleInvoiceCreatingPaylaod}
|
||||
// */
|
||||
// private writeInvoiceTaxTransactionsOnCreated = async ({
|
||||
// tenantId,
|
||||
// saleInvoice,
|
||||
// trx
|
||||
// }: ISaleInvoiceCreatedPayload) => {
|
||||
// await this.writeTaxTransactions.writeTaxTransactionsFromItemEntries(
|
||||
// tenantId,
|
||||
// saleInvoice.entries,
|
||||
// trx
|
||||
// );
|
||||
// };
|
||||
/**
|
||||
* Rewrites the invoice tax transactions on invoice edited.
|
||||
* @param {ISaleInvoiceEditedPayload} payload -
|
||||
*/
|
||||
@OnEvent(events.saleInvoice.onEdited)
|
||||
async rewriteInvoiceTaxTransactionsOnEdited({
|
||||
saleInvoice,
|
||||
trx,
|
||||
}: ISaleInvoiceEditedPayload) {
|
||||
await this.writeTaxTransactions.rewriteTaxRateTransactionsFromItemEntries(
|
||||
saleInvoice.entries,
|
||||
'SaleInvoice',
|
||||
saleInvoice.id,
|
||||
trx,
|
||||
);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Rewrites the invoice tax transactions on invoice edited.
|
||||
// * @param {ISaleInvoiceEditedPayload} payload -
|
||||
// */
|
||||
// private rewriteInvoiceTaxTransactionsOnEdited = async ({
|
||||
// tenantId,
|
||||
// saleInvoice,
|
||||
// trx,
|
||||
// }: ISaleInvoiceEditedPayload) => {
|
||||
// await this.writeTaxTransactions.rewriteTaxRateTransactionsFromItemEntries(
|
||||
// tenantId,
|
||||
// saleInvoice.entries,
|
||||
// 'SaleInvoice',
|
||||
// saleInvoice.id,
|
||||
// trx
|
||||
// );
|
||||
// };
|
||||
|
||||
// /**
|
||||
// * Removes the invoice tax transactions on invoice deleted.
|
||||
// * @param {ISaleInvoiceEditingPayload}
|
||||
// */
|
||||
// private removeInvoiceTaxTransactionsOnDeleted = async ({
|
||||
// tenantId,
|
||||
// oldSaleInvoice,
|
||||
// trx
|
||||
// }: ISaleInvoiceDeletedPayload) => {
|
||||
// await this.writeTaxTransactions.removeTaxTransactionsFromItemEntries(
|
||||
// tenantId,
|
||||
// oldSaleInvoice.id,
|
||||
// 'SaleInvoice',
|
||||
// trx
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Removes the invoice tax transactions on invoice deleted.
|
||||
* @param {ISaleInvoiceEditingPayload}
|
||||
*/
|
||||
@OnEvent(events.saleInvoice.onDelete)
|
||||
async removeInvoiceTaxTransactionsOnDeleted({
|
||||
oldSaleInvoice,
|
||||
trx,
|
||||
}: ISaleInvoiceDeletedPayload) {
|
||||
await this.writeTaxTransactions.removeTaxTransactionsFromItemEntries(
|
||||
oldSaleInvoice.id,
|
||||
'SaleInvoice',
|
||||
trx,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user