feat: apply credit note to invoice module

This commit is contained in:
Ahmed Bouhuolia
2025-05-04 01:32:08 +02:00
parent 1d53063e09
commit 4f6ad2b293
28 changed files with 633 additions and 707 deletions

View File

@@ -82,6 +82,7 @@ import { AttachmentsModule } from '../Attachments/Attachment.module';
import { S3Module } from '../S3/S3.module'; import { S3Module } from '../S3/S3.module';
import { ExportModule } from '../Export/Export.module'; import { ExportModule } from '../Export/Export.module';
import { ImportModule } from '../Import/Import.module'; import { ImportModule } from '../Import/Import.module';
import { CreditNotesApplyInvoiceModule } from '../CreditNotesApplyInvoice/CreditNotesApplyInvoice.module';
@Module({ @Module({
imports: [ imports: [
@@ -169,6 +170,7 @@ import { ImportModule } from '../Import/Import.module';
VendorCreditApplyBillsModule, VendorCreditApplyBillsModule,
VendorCreditsRefundModule, VendorCreditsRefundModule,
CreditNoteRefundsModule, CreditNoteRefundsModule,
CreditNotesApplyInvoiceModule,
BillPaymentsModule, BillPaymentsModule,
PaymentsReceivedModule, PaymentsReceivedModule,
LedgerModule, LedgerModule,

View File

@@ -1,4 +1,4 @@
import bluebird from 'bluebird'; import * as bluebird from 'bluebird';
import { difference } from 'lodash'; import { difference } from 'lodash';
import { import {
validateLinkModelEntryExists, validateLinkModelEntryExists,

View File

@@ -1,4 +1,4 @@
import { Module } from '@nestjs/common'; import { forwardRef, Module } from '@nestjs/common';
import { CreateRefundCreditNoteService } from './commands/CreateRefundCreditNote.service'; import { CreateRefundCreditNoteService } from './commands/CreateRefundCreditNote.service';
import { DeleteRefundCreditNoteService } from './commands/DeleteRefundCreditNote.service'; import { DeleteRefundCreditNoteService } from './commands/DeleteRefundCreditNote.service';
import { RefundCreditNoteService } from './commands/RefundCreditNote.service'; import { RefundCreditNoteService } from './commands/RefundCreditNote.service';
@@ -8,7 +8,7 @@ import { CreditNoteRefundsController } from './CreditNoteRefunds.controller';
import { CreditNotesModule } from '../CreditNotes/CreditNotes.module'; import { CreditNotesModule } from '../CreditNotes/CreditNotes.module';
@Module({ @Module({
imports: [CreditNotesModule], imports: [forwardRef(() => CreditNotesModule)],
providers: [ providers: [
CreateRefundCreditNoteService, CreateRefundCreditNoteService,
DeleteRefundCreditNoteService, DeleteRefundCreditNoteService,
@@ -16,6 +16,9 @@ import { CreditNotesModule } from '../CreditNotes/CreditNotes.module';
RefundSyncCreditNoteBalanceService, RefundSyncCreditNoteBalanceService,
CreditNotesRefundsApplication, CreditNotesRefundsApplication,
], ],
exports: [
RefundSyncCreditNoteBalanceService
],
controllers: [CreditNoteRefundsController], controllers: [CreditNoteRefundsController],
}) })
export class CreditNoteRefundsModule {} export class CreditNoteRefundsModule {}

View File

@@ -1,160 +1,162 @@
// import { Inject, Service } from 'typedi'; import { LedgerStorageService } from '@/modules/Ledger/LedgerStorage.service';
// import { Knex } from 'knex'; import { Inject, Injectable } from '@nestjs/common';
// import { AccountNormal, ILedgerEntry, IRefundCreditNote } from '@/interfaces'; import { RefundCreditNote } from '../models/RefundCreditNote';
// import HasTenancyService from '@/services/Tenancy/TenancyService'; import { Ledger } from '@/modules/Ledger/Ledger';
// import LedgerStorageService from '@/services/Accounting/LedgerStorageService'; import { Knex } from 'knex';
// import Ledger from '@/services/Accounting/Ledger'; import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
import { Account } from '@/modules/Accounts/models/Account.model';
import { ILedgerEntry } from '@/modules/Ledger/types/Ledger.types';
import { AccountNormal } from '@/interfaces/Account';
// @Service() @Injectable()
// export default class RefundCreditNoteGLEntries { export class RefundCreditNoteGLEntries {
// @Inject() constructor(
// ledgerStorage: LedgerStorageService; private readonly ledgerStorage: LedgerStorageService,
// @Inject() @Inject(Account.name)
// tenancy: HasTenancyService; private readonly accountModel: TenantModelProxy<typeof Account>,
// /** @Inject(RefundCreditNote.name)
// * Retrieves the refund credit common GL entry. private readonly refundCreditNoteModel: TenantModelProxy<
// * @param {IRefundCreditNote} refundCreditNote typeof RefundCreditNote
// * @returns >,
// */ ) {}
// private getRefundCreditCommonGLEntry = (
// refundCreditNote: IRefundCreditNote
// ) => {
// return {
// currencyCode: refundCreditNote.currencyCode,
// exchangeRate: refundCreditNote.exchangeRate,
// transactionType: 'RefundCreditNote', /**
// transactionId: refundCreditNote.id, * Retrieves the refund credit common GL entry.
// date: refundCreditNote.date, * @param {IRefundCreditNote} refundCreditNote
// userId: refundCreditNote.userId, * @returns
*/
private getRefundCreditCommonGLEntry = (
refundCreditNote: RefundCreditNote,
) => {
return {
currencyCode: refundCreditNote.currencyCode,
exchangeRate: refundCreditNote.exchangeRate,
// referenceNumber: refundCreditNote.referenceNo, transactionType: 'RefundCreditNote',
transactionId: refundCreditNote.id,
date: refundCreditNote.date,
userId: refundCreditNote.userId,
// createdAt: refundCreditNote.createdAt, referenceNumber: refundCreditNote.referenceNo,
// indexGroup: 10,
// credit: 0, createdAt: refundCreditNote.createdAt,
// debit: 0, indexGroup: 10,
// note: refundCreditNote.description, credit: 0,
// branchId: refundCreditNote.branchId, debit: 0,
// };
// };
// /** note: refundCreditNote.description,
// * Retrieves the refudn credit receivable GL entry. branchId: refundCreditNote.branchId,
// * @param {IRefundCreditNote} refundCreditNote };
// * @param {number} ARAccountId };
// * @returns {ILedgerEntry}
// */
// private getRefundCreditGLReceivableEntry = (
// refundCreditNote: IRefundCreditNote,
// ARAccountId: number
// ): ILedgerEntry => {
// const commonEntry = this.getRefundCreditCommonGLEntry(refundCreditNote);
// return { /**
// ...commonEntry, * Retrieves the refudn credit receivable GL entry.
// debit: refundCreditNote.amount, * @param {IRefundCreditNote} refundCreditNote
// accountId: ARAccountId, * @param {number} ARAccountId
// contactId: refundCreditNote.creditNote.customerId, * @returns {ILedgerEntry}
// index: 1, */
// accountNormal: AccountNormal.DEBIT, private getRefundCreditGLReceivableEntry = (
// }; refundCreditNote: RefundCreditNote,
// }; ARAccountId: number,
): ILedgerEntry => {
const commonEntry = this.getRefundCreditCommonGLEntry(refundCreditNote);
// /** return {
// * Retrieves the refund credit withdrawal GL entry. ...commonEntry,
// * @param {number} refundCreditNote debit: refundCreditNote.amount,
// * @returns {ILedgerEntry} accountId: ARAccountId,
// */ contactId: refundCreditNote.creditNote.customerId,
// private getRefundCreditGLWithdrawalEntry = ( index: 1,
// refundCreditNote: IRefundCreditNote accountNormal: AccountNormal.DEBIT,
// ): ILedgerEntry => { };
// const commonEntry = this.getRefundCreditCommonGLEntry(refundCreditNote); };
// return { /**
// ...commonEntry, * Retrieves the refund credit withdrawal GL entry.
// credit: refundCreditNote.amount, * @param {number} refundCreditNote
// accountId: refundCreditNote.fromAccountId, * @returns {ILedgerEntry}
// index: 2, */
// accountNormal: AccountNormal.DEBIT, private getRefundCreditGLWithdrawalEntry = (
// }; refundCreditNote: RefundCreditNote,
// }; ): ILedgerEntry => {
const commonEntry = this.getRefundCreditCommonGLEntry(refundCreditNote);
// /** return {
// * Retrieve the refund credit note GL entries. ...commonEntry,
// * @param {IRefundCreditNote} refundCreditNote credit: refundCreditNote.amount,
// * @param {number} receivableAccount accountId: refundCreditNote.fromAccountId,
// * @returns {ILedgerEntry[]} index: 2,
// */ accountNormal: AccountNormal.DEBIT,
// public getRefundCreditGLEntries( };
// refundCreditNote: IRefundCreditNote, };
// ARAccountId: number
// ): ILedgerEntry[] {
// const receivableEntry = this.getRefundCreditGLReceivableEntry(
// refundCreditNote,
// ARAccountId
// );
// const withdrawalEntry =
// this.getRefundCreditGLWithdrawalEntry(refundCreditNote);
// return [receivableEntry, withdrawalEntry]; /**
// } * Retrieve the refund credit note GL entries.
* @param {IRefundCreditNote} refundCreditNote
* @param {number} receivableAccount
* @returns {ILedgerEntry[]}
*/
public getRefundCreditGLEntries(
refundCreditNote: RefundCreditNote,
ARAccountId: number,
): ILedgerEntry[] {
const receivableEntry = this.getRefundCreditGLReceivableEntry(
refundCreditNote,
ARAccountId,
);
const withdrawalEntry =
this.getRefundCreditGLWithdrawalEntry(refundCreditNote);
// /** return [receivableEntry, withdrawalEntry];
// * Creates refund credit GL entries. }
// * @param {number} tenantId
// * @param {IRefundCreditNote} refundCreditNote
// * @param {Knex.Transaction} trx
// */
// public createRefundCreditGLEntries = async (
// tenantId: number,
// refundCreditNoteId: number,
// trx?: Knex.Transaction
// ) => {
// const { Account, RefundCreditNote } = this.tenancy.models(tenantId);
// // Retrieve the refund with associated credit note. /**
// const refundCreditNote = await RefundCreditNote.query(trx) * Creates refund credit GL entries.
// .findById(refundCreditNoteId) * @param {IRefundCreditNote} refundCreditNote
// .withGraphFetched('creditNote'); * @param {Knex.Transaction} trx
*/
public createRefundCreditGLEntries = async (
refundCreditNoteId: number,
trx?: Knex.Transaction,
) => {
// Retrieve the refund with associated credit note.
const refundCreditNote = await this.refundCreditNoteModel().query(trx)
.findById(refundCreditNoteId)
.withGraphFetched('creditNote');
// // Receivable account A/R. // Receivable account A/R.
// const receivableAccount = await Account.query().findOne( const receivableAccount = await this.accountModel().query().findOne(
// 'slug', 'slug',
// 'accounts-receivable' 'accounts-receivable',
// ); );
// // Retrieve refund credit GL entries. // Retrieve refund credit GL entries.
// const refundGLEntries = this.getRefundCreditGLEntries( const refundGLEntries = this.getRefundCreditGLEntries(
// refundCreditNote, refundCreditNote,
// receivableAccount.id receivableAccount.id,
// ); );
// const ledger = new Ledger(refundGLEntries); const ledger = new Ledger(refundGLEntries);
// // Saves refund ledger entries. // Saves refund ledger entries.
// await this.ledgerStorage.commit(tenantId, ledger, trx); await this.ledgerStorage.commit(ledger, trx);
// }; };
// /** /**
// * Reverts refund credit note GL entries. * Reverts refund credit note GL entries.
// * @param {number} tenantId * @param {number} refundCreditNoteId
// * @param {number} refundCreditNoteId * @param {number} receivableAccount
// * @param {number} receivableAccount * @param {Knex.Transaction} trx
// * @param {Knex.Transaction} trx */
// */ public revertRefundCreditGLEntries = async (
// public revertRefundCreditGLEntries = async ( refundCreditNoteId: number,
// tenantId: number, trx?: Knex.Transaction,
// refundCreditNoteId: number, ) => {
// trx?: Knex.Transaction await this.ledgerStorage.deleteByReference(
// ) => { refundCreditNoteId,
// await this.ledgerStorage.deleteByReference( 'RefundCreditNote',
// tenantId, trx,
// refundCreditNoteId, );
// 'RefundCreditNote', };
// trx }
// );
// };
// }

View File

@@ -4,8 +4,9 @@ import { Model, mixin } from 'objection';
// import CustomViewBaseModel from './CustomViewBaseModel'; // import CustomViewBaseModel from './CustomViewBaseModel';
// import ModelSearchable from './ModelSearchable'; // import ModelSearchable from './ModelSearchable';
import { BaseModel } from '@/models/Model'; import { BaseModel } from '@/models/Model';
import { CreditNote } from '@/modules/CreditNotes/models/CreditNote';
export class RefundCreditNote extends BaseModel{ export class RefundCreditNote extends BaseModel {
date: Date; date: Date;
referenceNo: string; referenceNo: string;
amount: number; amount: number;
@@ -14,12 +15,14 @@ export class RefundCreditNote extends BaseModel{
fromAccountId: number; fromAccountId: number;
description: string; description: string;
creditNoteId: number; creditNoteId: number;
userId?: number; userId?: number;
branchId?: number; branchId?: number;
createdAt?: Date | null; createdAt?: Date | null;
creditNote!: CreditNote;
/** /**
* Table name. * Table name.
*/ */

View File

@@ -1,4 +1,4 @@
import { Module } from '@nestjs/common'; import { forwardRef, Module } from '@nestjs/common';
import { CreateCreditNoteService } from './commands/CreateCreditNote.service'; import { CreateCreditNoteService } from './commands/CreateCreditNote.service';
import { CommandCreditNoteDTOTransform } from './commands/CommandCreditNoteDTOTransform.service'; import { CommandCreditNoteDTOTransform } from './commands/CommandCreditNoteDTOTransform.service';
import { EditCreditNoteService } from './commands/EditCreditNote.service'; import { EditCreditNoteService } from './commands/EditCreditNote.service';
@@ -26,6 +26,13 @@ import { GetCreditNotesService } from './queries/GetCreditNotes.service';
import { DynamicListModule } from '../DynamicListing/DynamicList.module'; import { DynamicListModule } from '../DynamicListing/DynamicList.module';
import { CreditNotesExportable } from './commands/CreditNotesExportable'; import { CreditNotesExportable } from './commands/CreditNotesExportable';
import { CreditNotesImportable } from './commands/CreditNotesImportable'; import { CreditNotesImportable } from './commands/CreditNotesImportable';
import { CreditNoteInventoryTransactionsSubscriber } from './subscribers/CreditNoteInventoryTransactionsSubscriber';
import { RefundSyncCreditNoteBalanceSubscriber } from './subscribers/RefundSyncCreditNoteBalanceSubscriber';
import { DeleteCustomerLinkedCreditSubscriber } from './subscribers/DeleteCustomerLinkedCreditSubscriber';
import { CreditNoteInventoryTransactions } from './commands/CreditNotesInventoryTransactions';
import { InventoryCostModule } from '../InventoryCost/InventoryCost.module';
import { CreditNoteRefundsModule } from '../CreditNoteRefunds/CreditNoteRefunds.module';
import { CreditNotesApplyInvoiceModule } from '../CreditNotesApplyInvoice/CreditNotesApplyInvoice.module';
@Module({ @Module({
imports: [ imports: [
@@ -39,6 +46,9 @@ import { CreditNotesImportable } from './commands/CreditNotesImportable';
LedgerModule, LedgerModule,
AccountsModule, AccountsModule,
DynamicListModule, DynamicListModule,
InventoryCostModule,
forwardRef(() => CreditNoteRefundsModule),
forwardRef(() => CreditNotesApplyInvoiceModule)
], ],
providers: [ providers: [
CreateCreditNoteService, CreateCreditNoteService,
@@ -57,6 +67,10 @@ import { CreditNotesImportable } from './commands/CreditNotesImportable';
CreditNoteGLEntriesSubscriber, CreditNoteGLEntriesSubscriber,
CreditNotesExportable, CreditNotesExportable,
CreditNotesImportable, CreditNotesImportable,
CreditNoteInventoryTransactions,
CreditNoteInventoryTransactionsSubscriber,
RefundSyncCreditNoteBalanceSubscriber,
DeleteCustomerLinkedCreditSubscriber,
], ],
exports: [ exports: [
CreateCreditNoteService, CreateCreditNoteService,

View File

@@ -22,7 +22,7 @@ export class CreditNoteBrandingTemplate {
// Retrieves the organization branding attributes. // Retrieves the organization branding attributes.
const commonOrgBrandingAttrs = const commonOrgBrandingAttrs =
await this.getOrgBrandingAttributes.getOrganizationBrandingAttributes(); await this.getOrgBrandingAttributes.execute();
// Merges the default branding attributes with common organization branding attrs. // Merges the default branding attributes with common organization branding attrs.
const organizationBrandingAttrs = { const organizationBrandingAttrs = {

View File

@@ -1,30 +1,21 @@
// import { Service, Inject } from 'typedi'; import { Injectable } from '@nestjs/common';
// import events from '@/subscribers/events'; import { OnEvent } from '@nestjs/event-emitter';
// import BaseCreditNotes from '../commands/CommandCreditNoteDTOTransform.service'; import { CreditNoteAutoIncrementService } from '../commands/CreditNoteAutoIncrement.service';
// import { ICreditNoteCreatedPayload } from '@/interfaces'; import { ICreditNoteCreatedPayload } from '../types/CreditNotes.types';
import { events } from '@/common/events/events';
// @Service() @Injectable()
// export default class CreditNoteAutoSerialSubscriber { export default class CreditNoteAutoSerialSubscriber {
// @Inject() constructor(
// creditNotesService: BaseCreditNotes; private readonly creditNoteIncrementService: CreditNoteAutoIncrementService,
) {}
// /** /**
// * Attaches events with handlers. * Auto serial increment once credit note created.
// */ * @param {ICreditNoteCreatedPayload} payload -
// public attach(bus) { */
// bus.subscribe( @OnEvent(events.creditNote.onCreated)
// events.creditNote.onCreated, async autoSerialIncrementOnceCreated({}: ICreditNoteCreatedPayload) {
// this.autoSerialIncrementOnceCreated await this.creditNoteIncrementService.incrementSerialNumber();
// ); }
// } }
// /**
// * Auto serial increment once credit note created.
// * @param {ICreditNoteCreatedPayload} payload -
// */
// private autoSerialIncrementOnceCreated = async ({
// tenantId,
// }: ICreditNoteCreatedPayload) => {
// await this.creditNotesService.incrementSerialNumber(tenantId);
// };
// }

View File

@@ -1,48 +1,34 @@
// import { Inject, Service } from 'typedi'; import { OnEvent } from '@nestjs/event-emitter';
// import { ServiceError } from '@/exceptions'; import { Injectable } from '@nestjs/common';
// import TenancyService from '@/services/Tenancy/TenancyService'; import { DeleteCustomerLinkedCreditNoteService } from '@/modules/CreditNotesApplyInvoice/commands/DeleteCustomerLinkedCreditNote.service';
// import events from '@/subscribers/events'; import { events } from '@/common/events/events';
// import { ICustomerDeletingPayload } from '@/interfaces'; import { ICustomerDeletingPayload } from '@/modules/Customers/types/Customers.types';
// import DeleteCustomerLinkedCreidtNote from '../commands/DeleteCustomerLinkedCreditNote.service'; import { ServiceError } from '@/modules/Items/ServiceError';
// const ERRORS = { const ERRORS = {
// CUSTOMER_HAS_TRANSACTIONS: 'CUSTOMER_HAS_TRANSACTIONS', CUSTOMER_HAS_TRANSACTIONS: 'CUSTOMER_HAS_TRANSACTIONS',
// }; };
// @Service() @Injectable()
// export default class DeleteCustomerLinkedCreditSubscriber { export class DeleteCustomerLinkedCreditSubscriber {
// @Inject() constructor(
// tenancy: TenancyService; private readonly deleteCustomerLinkedCredit: DeleteCustomerLinkedCreditNoteService,
) {}
// @Inject() /**
// deleteCustomerLinkedCredit: DeleteCustomerLinkedCreidtNote; * Validate vendor has no associated credit transaction once the vendor deleting.
* @param {IVendorEventDeletingPayload} payload -
// /** */
// * Attaches events with handlers. @OnEvent(events.customers.onDeleting)
// * @param bus public async validateCustomerHasNoLinkedCreditsOnDeleting({
// */ customerId,
// public attach = (bus) => { }: ICustomerDeletingPayload) {
// bus.subscribe( try {
// events.customers.onDeleting, await this.deleteCustomerLinkedCredit.validateCustomerHasNoCreditTransaction(
// this.validateCustomerHasNoLinkedCreditsOnDeleting customerId,
// ); );
// }; } catch (error) {
throw new ServiceError(ERRORS.CUSTOMER_HAS_TRANSACTIONS);
// /** }
// * Validate vendor has no associated credit transaction once the vendor deleting. }
// * @param {IVendorEventDeletingPayload} payload - }
// */
// public validateCustomerHasNoLinkedCreditsOnDeleting = async ({
// tenantId,
// customerId,
// }: ICustomerDeletingPayload) => {
// try {
// await this.deleteCustomerLinkedCredit.validateCustomerHasNoCreditTransaction(
// tenantId,
// customerId
// );
// } catch (error) {
// throw new ServiceError(ERRORS.CUSTOMER_HAS_TRANSACTIONS);
// }
// };
// }

View File

@@ -1,61 +1,47 @@
// import { Service, Inject } from 'typedi'; import { events } from '@/common/events/events';
// import events from '@/subscribers/events'; import { RefundCreditNoteGLEntries } from '@/modules/CreditNoteRefunds/commands/RefundCreditNoteGLEntries';
// import RefundCreditNoteGLEntries from '../commands/RefundCreditNoteGLEntries'; import {
// import { IRefundCreditNoteCreatedPayload,
// IRefundCreditNoteCreatedPayload, IRefundCreditNoteDeletedPayload,
// IRefundCreditNoteDeletedPayload, } from '@/modules/CreditNoteRefunds/types/CreditNoteRefunds.types';
// } from '@/interfaces'; import { Injectable } from '@nestjs/common';
import { OnEvent } from '@nestjs/event-emitter';
// @Service() @Injectable()
// export default class RefundCreditNoteGLEntriesSubscriber { export class RefundCreditNoteGLEntriesSubscriber {
// @Inject() constructor(
// refundCreditGLEntries: RefundCreditNoteGLEntries; private readonly refundCreditGLEntries: RefundCreditNoteGLEntries,
) {}
// /** /**
// * Attaches events with handlers. * Writes refund credit note GL entries once the transaction created.
// */ * @param {IRefundCreditNoteCreatedPayload} payload -
// public attach = (bus) => { */
// bus.subscribe( @OnEvent(events.creditNote.onRefundCreated)
// events.creditNote.onRefundCreated, async writeRefundCreditGLEntriesOnceCreated({
// this.writeRefundCreditGLEntriesOnceCreated trx,
// ); refundCreditNote,
// bus.subscribe( creditNote,
// events.creditNote.onRefundDeleted, }: IRefundCreditNoteCreatedPayload) {
// this.revertRefundCreditGLEntriesOnceDeleted await this.refundCreditGLEntries.createRefundCreditGLEntries(
// ); refundCreditNote.id,
// }; trx,
);
}
// /** /**
// * Writes refund credit note GL entries once the transaction created. * Reverts refund credit note GL entries once the transaction deleted.
// * @param {IRefundCreditNoteCreatedPayload} payload - * @param {IRefundCreditNoteDeletedPayload} payload -
// */ */
// private writeRefundCreditGLEntriesOnceCreated = async ({ @OnEvent(events.creditNote.onRefundDeleted)
// trx, async revertRefundCreditGLEntriesOnceDeleted({
// refundCreditNote, trx,
// creditNote, refundCreditId,
// tenantId, oldRefundCredit,
// }: IRefundCreditNoteCreatedPayload) => { }: IRefundCreditNoteDeletedPayload) {
// await this.refundCreditGLEntries.createRefundCreditGLEntries( await this.refundCreditGLEntries.revertRefundCreditGLEntries(
// tenantId, refundCreditId,
// refundCreditNote.id, trx,
// trx );
// ); }
// }; }
// /**
// * Reverts refund credit note GL entries once the transaction deleted.
// * @param {IRefundCreditNoteDeletedPayload} payload -
// */
// private revertRefundCreditGLEntriesOnceDeleted = async ({
// trx,
// refundCreditId,
// oldRefundCredit,
// tenantId,
// }: IRefundCreditNoteDeletedPayload) => {
// await this.refundCreditGLEntries.revertRefundCreditGLEntries(
// tenantId,
// refundCreditId,
// trx
// );
// };
// }

View File

@@ -1,62 +1,47 @@
// import { Inject, Service } from 'typedi'; import { events } from '@/common/events/events';
// import { import { RefundSyncCreditNoteBalanceService } from '@/modules/CreditNoteRefunds/commands/RefundSyncCreditNoteBalance';
// IRefundCreditNoteCreatedPayload, import {
// IRefundCreditNoteDeletedPayload, IRefundCreditNoteCreatedPayload,
// } from '@/interfaces'; IRefundCreditNoteDeletedPayload,
// import events from '@/subscribers/events'; } from '@/modules/CreditNoteRefunds/types/CreditNoteRefunds.types';
// import RefundSyncCreditNoteBalance from '../commands/RefundSyncCreditNoteBalance'; import { Injectable } from '@nestjs/common';
import { OnEvent } from '@nestjs/event-emitter';
// @Service() @Injectable()
// export default class RefundSyncCreditNoteBalanceSubscriber { export class RefundSyncCreditNoteBalanceSubscriber {
// @Inject() constructor(
// refundSyncCreditBalance: RefundSyncCreditNoteBalance; private readonly refundSyncCreditBalance: RefundSyncCreditNoteBalanceService,
) {}
// /** /**
// * Attaches events with handlers. * Increment credit note refunded amount once associated refund transaction created.
// */ * @param {IRefundCreditNoteCreatedPayload} payload -
// attach(bus) { */
// bus.subscribe( @OnEvent(events.creditNote.onRefundCreated)
// events.creditNote.onRefundCreated, async incrementRefundedAmountOnceRefundCreated({
// this.incrementRefundedAmountOnceRefundCreated trx,
// ); refundCreditNote,
// bus.subscribe( }: IRefundCreditNoteCreatedPayload) {
// events.creditNote.onRefundDeleted, await this.refundSyncCreditBalance.incrementCreditNoteRefundAmount(
// this.decrementRefundedAmountOnceRefundDeleted refundCreditNote.creditNoteId,
// ); refundCreditNote.amount,
// return bus; trx,
// } );
}
// /** /**
// * Increment credit note refunded amount once associated refund transaction created. * Decrement credit note refunded amount once associated refuned transaction deleted.
// * @param {IRefundCreditNoteCreatedPayload} payload - * @param {IRefundCreditNoteDeletedPayload} payload -
// */ */
// private incrementRefundedAmountOnceRefundCreated = async ({ @OnEvent(events.creditNote.onRefundDeleted)
// trx, async decrementRefundedAmountOnceRefundDeleted({
// refundCreditNote, trx,
// tenantId, oldRefundCredit,
// }: IRefundCreditNoteCreatedPayload) => { }: IRefundCreditNoteDeletedPayload) {
// await this.refundSyncCreditBalance.incrementCreditNoteRefundAmount( await this.refundSyncCreditBalance.decrementCreditNoteRefundAmount(
// tenantId, oldRefundCredit.creditNoteId,
// refundCreditNote.creditNoteId, oldRefundCredit.amount,
// refundCreditNote.amount, trx,
// trx );
// ); }
// }; }
// /**
// * Decrement credit note refunded amount once associated refuned transaction deleted.
// * @param {IRefundCreditNoteDeletedPayload} payload -
// */
// private decrementRefundedAmountOnceRefundDeleted = async ({
// trx,
// oldRefundCredit,
// tenantId,
// }: IRefundCreditNoteDeletedPayload) => {
// await this.refundSyncCreditBalance.decrementCreditNoteRefundAmount(
// tenantId,
// oldRefundCredit.creditNoteId,
// oldRefundCredit.amount,
// trx
// );
// };
// }

View File

@@ -0,0 +1,27 @@
import { forwardRef, Module } from '@nestjs/common';
import { DeleteCustomerLinkedCreditNoteService } from './commands/DeleteCustomerLinkedCreditNote.service';
import { DeleteCreditNoteApplyToInvoices } from './commands/DeleteCreditNoteApplyToInvoices.service';
import { CreditNoteApplyToInvoices } from './commands/CreditNoteApplyToInvoices.service';
import { CreditNoteApplySyncInvoicesCreditedAmount } from './commands/CreditNoteApplySyncInvoices.service';
import { CreditNoteApplySyncCredit } from './commands/CreditNoteApplySyncCredit.service';
import { PaymentsReceivedModule } from '../PaymentReceived/PaymentsReceived.module';
import { CreditNotesModule } from '../CreditNotes/CreditNotes.module';
import { GetCreditNoteAssociatedAppliedInvoices } from './queries/GetCreditNoteAssociatedAppliedInvoices.service';
import { GetCreditNoteAssociatedInvoicesToApply } from './queries/GetCreditNoteAssociatedInvoicesToApply.service';
@Module({
providers: [
DeleteCustomerLinkedCreditNoteService,
DeleteCreditNoteApplyToInvoices,
CreditNoteApplyToInvoices,
CreditNoteApplySyncInvoicesCreditedAmount,
CreditNoteApplySyncCredit,
// GetCreditNoteAssociatedAppliedInvoices,
// GetCreditNoteAssociatedInvoicesToApply
],
exports: [
DeleteCustomerLinkedCreditNoteService,
],
imports: [PaymentsReceivedModule, forwardRef(() => CreditNotesModule)],
})
export class CreditNotesApplyInvoiceModule {}

View File

@@ -11,7 +11,7 @@ import { ERRORS } from '../../CreditNotes/constants';
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel'; import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
@Injectable() @Injectable()
export default class DeleteCreditNoteApplyToInvoices { export class DeleteCreditNoteApplyToInvoices {
/** /**
* @param {UnitOfWork} uow - Unit of work. * @param {UnitOfWork} uow - Unit of work.
* @param {EventEmitter2} eventPublisher - Event emitter. * @param {EventEmitter2} eventPublisher - Event emitter.

View File

@@ -1,67 +1,52 @@
// import { Service, Inject } from 'typedi'; import { sumBy } from 'lodash';
// import { sumBy } from 'lodash'; import { Injectable } from '@nestjs/common';
// import events from '@/subscribers/events'; import {
// import { IApplyCreditToInvoicesCreatedPayload,
// IApplyCreditToInvoicesCreatedPayload, IApplyCreditToInvoicesDeletedPayload,
// IApplyCreditToInvoicesDeletedPayload, } from '../types/CreditNoteApplyInvoice.types';
// } from '@/interfaces'; import { CreditNoteApplySyncCredit } from '../commands/CreditNoteApplySyncCredit.service';
// import CreditNoteApplySyncCredit from '../commands/CreditNoteApplySyncCredit.service'; import { OnEvent } from '@nestjs/event-emitter';
import { events } from '@/common/events/events';
// @Service() @Injectable()
// export default class CreditNoteApplySyncCreditSubscriber { export class CreditNoteApplySyncCreditSubscriber {
// @Inject() constructor(
// syncInvoicedAmountWithCredit: CreditNoteApplySyncCredit; private readonly syncInvoicedAmountWithCredit: CreditNoteApplySyncCredit,
) {}
// /** /**
// * * Increment credited amount of credit note transaction once the transaction created.
// * @param bus * @param {IApplyCreditToInvoicesCreatedPayload} payload -
// */ */
// attach(bus) { @OnEvent(events.creditNote.onApplyToInvoicesCreated)
// bus.subscribe( async incrementCreditedAmountOnceApplyToInvoicesCreated({
// events.creditNote.onApplyToInvoicesCreated, trx,
// this.incrementCreditedAmountOnceApplyToInvoicesCreated creditNote,
// ); creditNoteAppliedInvoices,
// bus.subscribe( }: IApplyCreditToInvoicesCreatedPayload) {
// events.creditNote.onApplyToInvoicesDeleted, const totalCredited = sumBy(creditNoteAppliedInvoices, 'amount');
// this.decrementCreditedAmountOnceApplyToInvoicesDeleted
// );
// }
// /** await this.syncInvoicedAmountWithCredit.incrementCreditNoteInvoicedAmount(
// * Increment credited amount of credit note transaction once the transaction created. creditNote.id,
// * @param {IApplyCreditToInvoicesCreatedPayload} payload - totalCredited,
// */ trx,
// private incrementCreditedAmountOnceApplyToInvoicesCreated = async ({ );
// trx, }
// creditNote,
// tenantId,
// creditNoteAppliedInvoices,
// }: IApplyCreditToInvoicesCreatedPayload) => {
// const totalCredited = sumBy(creditNoteAppliedInvoices, 'amount');
// await this.syncInvoicedAmountWithCredit.incrementCreditNoteInvoicedAmount( /**
// tenantId, * Decrement credited amount of credit note transaction once the transaction deleted.
// creditNote.id, * @param {IApplyCreditToInvoicesDeletedPayload} payload -
// totalCredited, */
// trx @OnEvent(events.creditNote.onApplyToInvoicesDeleted)
// ); async decrementCreditedAmountOnceApplyToInvoicesDeleted({
// }; creditNote,
creditNoteAppliedToInvoice,
// /** trx,
// * Decrement credited amount of credit note transaction once the transaction deleted. }: IApplyCreditToInvoicesDeletedPayload) {
// * @param {IApplyCreditToInvoicesDeletedPayload} payload - await this.syncInvoicedAmountWithCredit.decrementCreditNoteInvoicedAmount(
// */ creditNote.id,
// private decrementCreditedAmountOnceApplyToInvoicesDeleted = async ({ creditNoteAppliedToInvoice.amount,
// tenantId, trx,
// creditNote, );
// creditNoteAppliedToInvoice, }
// trx, }
// }: IApplyCreditToInvoicesDeletedPayload) => {
// await this.syncInvoicedAmountWithCredit.decrementCreditNoteInvoicedAmount(
// tenantId,
// creditNote.id,
// creditNoteAppliedToInvoice.amount,
// trx
// );
// };
// }

View File

@@ -1,61 +1,47 @@
// import { Service, Inject } from 'typedi'; import { OnEvent } from '@nestjs/event-emitter';
// import events from '@/subscribers/events'; import { Injectable } from '@nestjs/common';
// import { import {
// IApplyCreditToInvoicesCreatedPayload, IApplyCreditToInvoicesCreatedPayload,
// IApplyCreditToInvoicesDeletedPayload, IApplyCreditToInvoicesDeletedPayload,
// } from '@/interfaces'; } from '../types/CreditNoteApplyInvoice.types';
// import CreditNoteApplySyncInvoicesCreditedAmount from '../commands/CreditNoteApplySyncInvoices.service'; import { CreditNoteApplySyncInvoicesCreditedAmount } from '../commands/CreditNoteApplySyncInvoices.service';
import { events } from '@/common/events/events';
// @Service() @Injectable()
// export default class CreditNoteApplySyncInvoicesCreditedAmountSubscriber { export default class CreditNoteApplySyncInvoicesCreditedAmountSubscriber {
// @Inject() constructor(
// private syncInvoicesWithCreditNote: CreditNoteApplySyncInvoicesCreditedAmount; private readonly syncInvoicesWithCreditNote: CreditNoteApplySyncInvoicesCreditedAmount,
) {}
// /** /**
// * Attaches events with handlers. * Increment invoices credited amount once the credit note apply to invoices transaction
// */ * @param {IApplyCreditToInvoicesCreatedPayload} payload -
// public attach(bus) { */
// bus.subscribe( @OnEvent(events.creditNote.onApplyToInvoicesCreated)
// events.creditNote.onApplyToInvoicesCreated, async incrementAppliedInvoicesOnceCreditCreated({
// this.incrementAppliedInvoicesOnceCreditCreated trx,
// ); creditNoteAppliedInvoices,
// bus.subscribe( }: IApplyCreditToInvoicesCreatedPayload) {
// events.creditNote.onApplyToInvoicesDeleted, await this.syncInvoicesWithCreditNote.incrementInvoicesCreditedAmount(
// this.decrementAppliedInvoicesOnceCreditDeleted creditNoteAppliedInvoices,
// ); trx,
// } );
}
// /** /**
// * Increment invoices credited amount once the credit note apply to invoices transaction *
// * @param {IApplyCreditToInvoicesCreatedPayload} payload - * @param {IApplyCreditToInvoicesDeletedPayload} payload -
// */ */
// private incrementAppliedInvoicesOnceCreditCreated = async ({ @OnEvent(events.creditNote.onApplyToInvoicesDeleted)
// trx, async decrementAppliedInvoicesOnceCreditDeleted({
// tenantId, trx,
// creditNoteAppliedInvoices, creditNoteAppliedToInvoice,
// }: IApplyCreditToInvoicesCreatedPayload) => { }: IApplyCreditToInvoicesDeletedPayload) {
// await this.syncInvoicesWithCreditNote.incrementInvoicesCreditedAmount( // Decrement invoice credited amount.
// tenantId, await this.syncInvoicesWithCreditNote.decrementInvoiceCreditedAmount(
// creditNoteAppliedInvoices, creditNoteAppliedToInvoice.invoiceId,
// trx creditNoteAppliedToInvoice.amount,
// ); trx,
// }; );
}
// /** }
// *
// * @param {IApplyCreditToInvoicesDeletedPayload} payload -
// */
// private decrementAppliedInvoicesOnceCreditDeleted = async ({
// trx,
// creditNoteAppliedToInvoice,
// tenantId,
// }: IApplyCreditToInvoicesDeletedPayload) => {
// // Decrement invoice credited amount.
// await this.syncInvoicesWithCreditNote.decrementInvoiceCreditedAmount(
// tenantId,
// creditNoteAppliedToInvoice.invoiceId,
// creditNoteAppliedToInvoice.amount,
// trx
// );
// };
// }

View File

@@ -1,5 +1,6 @@
import { CreditNote } from '@/modules/CreditNotes/models/CreditNote'; import { CreditNote } from '@/modules/CreditNotes/models/CreditNote';
import { Knex } from 'knex'; import { Knex } from 'knex';
import { CreditNoteAppliedInvoice } from '../models/CreditNoteAppliedInvoice';
export interface ICreditNoteApplyInvoiceDTO { export interface ICreditNoteApplyInvoiceDTO {
entries: { invoiceId: number; amount: number }[]; entries: { invoiceId: number; amount: number }[];
@@ -17,12 +18,12 @@ export interface IApplyCreditToInvoicesDTO {
export interface IApplyCreditToInvoicesCreatedPayload { export interface IApplyCreditToInvoicesCreatedPayload {
trx: Knex.Transaction; trx: Knex.Transaction;
creditNote: CreditNote; creditNote: CreditNote;
creditNoteAppliedInvoices: ICreditNoteAppliedToInvoice[]; creditNoteAppliedInvoices: CreditNoteAppliedInvoice[];
} }
export interface IApplyCreditToInvoicesDeletedPayload { export interface IApplyCreditToInvoicesDeletedPayload {
trx: Knex.Transaction; trx: Knex.Transaction;
creditNote: CreditNote; creditNote: CreditNote;
creditNoteAppliedToInvoice: ICreditNoteAppliedToInvoice; creditNoteAppliedToInvoice: CreditNoteAppliedInvoice;
} }
export interface ICreditNoteAppliedToInvoice { export interface ICreditNoteAppliedToInvoice {

View File

@@ -0,0 +1,3 @@
interface ReportsEvents {
tenantId: number;
}

View File

@@ -18,6 +18,7 @@ import { PaymentMethodEventsTracker } from './events/PaymentMethodEventsTracker'
import { PaymentLinkEventsTracker } from './events/PaymentLinkEventsTracker'; import { PaymentLinkEventsTracker } from './events/PaymentLinkEventsTracker';
import { StripeIntegrationEventsTracker } from './events/StripeIntegrationEventsTracker'; import { StripeIntegrationEventsTracker } from './events/StripeIntegrationEventsTracker';
import { PostHogModule } from './postHog.module'; import { PostHogModule } from './postHog.module';
import { ReportsEventsTracker } from './events/ReportsEventsTracker';
@Module({ @Module({
imports: [PostHogModule], imports: [PostHogModule],
@@ -40,7 +41,7 @@ import { PostHogModule } from './postHog.module';
PaymentMethodEventsTracker, PaymentMethodEventsTracker,
PaymentLinkEventsTracker, PaymentLinkEventsTracker,
StripeIntegrationEventsTracker, StripeIntegrationEventsTracker,
// ReportsEventsTracker, ReportsEventsTracker,
], ],
}) })
export class EventTrackerModule {} export class EventTrackerModule {}

View File

@@ -1,240 +1,161 @@
// import { Inject, Service } from 'typedi'; import { Inject, Injectable } from '@nestjs/common';
// import { EventSubscriber } from '@/lib/EventPublisher/EventPublisher'; import { OnEvent } from '@nestjs/event-emitter';
// import { ReportsEvents } from '@/constants/event-tracker'; import {
// import { PosthogService } from '../EventTracker.service'; BALANCE_SHEET_VIEWED,
// import events from '@/subscribers/events'; TRIAL_BALANCE_SHEET_VIEWED,
// import { PROFIT_LOSS_SHEET_VIEWED,
// BALANCE_SHEET_VIEWED, CASHFLOW_STATEMENT_VIEWED,
// TRIAL_BALANCE_SHEET_VIEWED, GENERAL_LEDGER_VIEWED,
// PROFIT_LOSS_SHEET_VIEWED, JOURNAL_VIEWED,
// CASHFLOW_STATEMENT_VIEWED, RECEIVABLE_AGING_VIEWED,
// GENERAL_LEDGER_VIEWED, PAYABLE_AGING_VIEWED,
// JOURNAL_VIEWED, CUSTOMER_BALANCE_SUMMARY_VIEWED,
// RECEIVABLE_AGING_VIEWED, VENDOR_BALANCE_SUMMARY_VIEWED,
// PAYABLE_AGING_VIEWED, INVENTORY_VALUATION_VIEWED,
// CUSTOMER_BALANCE_SUMMARY_VIEWED, CUSTOMER_TRANSACTIONS_VIEWED,
// VENDOR_BALANCE_SUMMARY_VIEWED, VENDOR_TRANSACTIONS_VIEWED,
// INVENTORY_VALUATION_VIEWED, SALES_BY_ITEM_VIEWED,
// CUSTOMER_TRANSACTIONS_VIEWED, PURCHASES_BY_ITEM_VIEWED,
// VENDOR_TRANSACTIONS_VIEWED, } from '../event-tracker';
// SALES_BY_ITEM_VIEWED, import { events } from '@/common/events/events';
// PURCHASES_BY_ITEM_VIEWED, import { POSTHOG_PROVIDER } from '../PostHog.constants';
// } from '@/constants/event-tracker';
// @Service() @Injectable()
// export class ReportsEventsTracker extends EventSubscriber { export class ReportsEventsTracker {
// @Inject() constructor(@Inject(POSTHOG_PROVIDER) private readonly posthog: any) {}
// private posthog: PosthogService;
// /** @OnEvent(events.reports.onBalanceSheetViewed)
// * Constructor method. handleTrackBalanceSheetViewedEvent({ tenantId }: ReportsEvents) {
// */ this.posthog.trackEvent({
// public attach(bus) { distinctId: `tenant-${tenantId}`,
// bus.subscribe( event: BALANCE_SHEET_VIEWED,
// events.reports.onBalanceSheetViewed, properties: {},
// this.handleTrackBalanceSheetViewedEvent });
// ); }
// bus.subscribe(
// events.reports.onTrialBalanceSheetView,
// this.handleTrackTrialBalanceSheetViewedEvent
// );
// bus.subscribe(
// events.reports.onProfitLossSheetViewed,
// this.handleTrackProfitLossSheetViewedEvent
// );
// bus.subscribe(
// events.reports.onCashflowStatementViewed,
// this.handleTrackCashflowStatementViewedEvent
// );
// bus.subscribe(
// events.reports.onGeneralLedgerViewed,
// this.handleTrackGeneralLedgerViewedEvent
// );
// bus.subscribe(
// events.reports.onJournalViewed,
// this.handleTrackJournalViewedEvent
// );
// bus.subscribe(
// events.reports.onReceivableAgingViewed,
// this.handleTrackReceivableAgingViewedEvent
// );
// bus.subscribe(
// events.reports.onPayableAgingViewed,
// this.handleTrackPayableAgingViewedEvent
// );
// bus.subscribe(
// events.reports.onCustomerBalanceSummaryViewed,
// this.handleTrackCustomerBalanceSummaryViewedEvent
// );
// bus.subscribe(
// events.reports.onVendorBalanceSummaryViewed,
// this.handleTrackVendorBalanceSummaryViewedEvent
// );
// bus.subscribe(
// events.reports.onInventoryValuationViewed,
// this.handleTrackInventoryValuationViewedEvent
// );
// bus.subscribe(
// events.reports.onCustomerTransactionsViewed,
// this.handleTrackCustomerTransactionsViewedEvent
// );
// bus.subscribe(
// events.reports.onVendorTransactionsViewed,
// this.handleTrackVendorTransactionsViewedEvent
// );
// bus.subscribe(
// events.reports.onSalesByItemViewed,
// this.handleTrackSalesByItemViewedEvent
// );
// bus.subscribe(
// events.reports.onPurchasesByItemViewed,
// this.handleTrackPurchasesByItemViewedEvent
// );
// }
// private handleTrackBalanceSheetViewedEvent( @OnEvent(events.reports.onTrialBalanceSheetView)
// { tenantId }: ReportsEvents handleTrackTrialBalanceSheetViewedEvent({ tenantId }: ReportsEvents) {
// ) { this.posthog.trackEvent({
// this.posthog.trackEvent({ distinctId: `tenant-${tenantId}`,
// distinctId: `tenant-${tenantId}`, event: TRIAL_BALANCE_SHEET_VIEWED,
// event: BALANCE_SHEET_VIEWED, properties: {},
// properties: {}, });
// }); }
// }
// private handleTrackTrialBalanceSheetViewedEvent( @OnEvent(events.reports.onProfitLossSheetViewed)
// { tenantId }: ReportsEvents handleTrackProfitLossSheetViewedEvent({ tenantId }: ReportsEvents) {
// ) { this.posthog.trackEvent({
// this.posthog.trackEvent({ distinctId: `tenant-${tenantId}`,
// distinctId: `tenant-${tenantId}`, event: PROFIT_LOSS_SHEET_VIEWED,
// event: TRIAL_BALANCE_SHEET_VIEWED, properties: {},
// properties: {}, });
// }); }
// }
// private handleTrackProfitLossSheetViewedEvent( @OnEvent(events.reports.onCashflowStatementViewed)
// { tenantId }: ReportsEvents handleTrackCashflowStatementViewedEvent({ tenantId }: ReportsEvents) {
// ) { this.posthog.trackEvent({
// this.posthog.trackEvent({ distinctId: `tenant-${tenantId}`,
// distinctId: `tenant-${tenantId}`, event: CASHFLOW_STATEMENT_VIEWED,
// event: PROFIT_LOSS_SHEET_VIEWED, properties: {},
// properties: {}, });
// }); }
// }
// private handleTrackCashflowStatementViewedEvent( @OnEvent(events.reports.onGeneralLedgerViewed)
// { tenantId }: ReportsEvents handleTrackGeneralLedgerViewedEvent({ tenantId }: ReportsEvents) {
// ) { this.posthog.trackEvent({
// this.posthog.trackEvent({ distinctId: `tenant-${tenantId}`,
// distinctId: `tenant-${tenantId}`, event: GENERAL_LEDGER_VIEWED,
// event: CASHFLOW_STATEMENT_VIEWED, properties: {},
// properties: {}, });
// }); }
// }
// private handleTrackGeneralLedgerViewedEvent( @OnEvent(events.reports.onJournalViewed)
// { tenantId }: ReportsEvents handleTrackJournalViewedEvent({ tenantId }: ReportsEvents) {
// ) { this.posthog.trackEvent({
// this.posthog.trackEvent({ distinctId: `tenant-${tenantId}`,
// distinctId: `tenant-${tenantId}`, event: JOURNAL_VIEWED,
// event: GENERAL_LEDGER_VIEWED, properties: {},
// properties: {}, });
// }); }
// }
// private handleTrackJournalViewedEvent({ tenantId }: ReportsEvents) { @OnEvent(events.reports.onReceivableAgingViewed)
// this.posthog.trackEvent({ handleTrackReceivableAgingViewedEvent({ tenantId }: ReportsEvents) {
// distinctId: `tenant-${tenantId}`, this.posthog.trackEvent({
// event: JOURNAL_VIEWED, distinctId: `tenant-${tenantId}`,
// properties: {}, event: RECEIVABLE_AGING_VIEWED,
// }); properties: {},
// } });
}
// private handleTrackReceivableAgingViewedEvent( @OnEvent(events.reports.onPayableAgingViewed)
// { tenantId }: ReportsEvents handleTrackPayableAgingViewedEvent({ tenantId }: ReportsEvents) {
// ) { this.posthog.trackEvent({
// this.posthog.trackEvent({ distinctId: `tenant-${tenantId}`,
// distinctId: `tenant-${tenantId}`, event: PAYABLE_AGING_VIEWED,
// event: RECEIVABLE_AGING_VIEWED, properties: {},
// properties: {}, });
// }); }
// }
// private handleTrackPayableAgingViewedEvent( @OnEvent(events.reports.onCustomerBalanceSummaryViewed)
// { tenantId }: ReportsEvents handleTrackCustomerBalanceSummaryViewedEvent({ tenantId }: ReportsEvents) {
// ) { this.posthog.trackEvent({
// this.posthog.trackEvent({ distinctId: `tenant-${tenantId}`,
// distinctId: `tenant-${tenantId}`, event: CUSTOMER_BALANCE_SUMMARY_VIEWED,
// event: PAYABLE_AGING_VIEWED, properties: {},
// properties: {}, });
// }); }
// }
// private handleTrackCustomerBalanceSummaryViewedEvent( @OnEvent(events.reports.onVendorBalanceSummaryViewed)
// { tenantId }: ReportsEvents handleTrackVendorBalanceSummaryViewedEvent({ tenantId }: ReportsEvents) {
// ) { this.posthog.trackEvent({
// this.posthog.trackEvent({ distinctId: `tenant-${tenantId}`,
// distinctId: `tenant-${tenantId}`, event: VENDOR_BALANCE_SUMMARY_VIEWED,
// event: CUSTOMER_BALANCE_SUMMARY_VIEWED, properties: {},
// properties: {}, });
// }); }
// }
// private handleTrackVendorBalanceSummaryViewedEvent( @OnEvent(events.reports.onInventoryValuationViewed)
// { tenantId }: ReportsEvents handleTrackInventoryValuationViewedEvent({ tenantId }: ReportsEvents) {
// ) { this.posthog.trackEvent({
// this.posthog.trackEvent({ distinctId: `tenant-${tenantId}`,
// distinctId: `tenant-${tenantId}`, event: INVENTORY_VALUATION_VIEWED,
// event: VENDOR_BALANCE_SUMMARY_VIEWED, properties: {},
// properties: {}, });
// }); }
// }
// private handleTrackInventoryValuationViewedEvent( @OnEvent(events.reports.onCustomerTransactionsViewed)
// { tenantId }: ReportsEvents handleTrackCustomerTransactionsViewedEvent({ tenantId }: ReportsEvents) {
// ) { this.posthog.trackEvent({
// this.posthog.trackEvent({ distinctId: `tenant-${tenantId}`,
// distinctId: `tenant-${tenantId}`, event: CUSTOMER_TRANSACTIONS_VIEWED,
// event: INVENTORY_VALUATION_VIEWED, properties: {},
// properties: {}, });
// }); }
// }
// private handleTrackCustomerTransactionsViewedEvent( @OnEvent(events.reports.onVendorTransactionsViewed)
// { tenantId }: ReportsEvents handleTrackVendorTransactionsViewedEvent({ tenantId }: ReportsEvents) {
// ) { this.posthog.trackEvent({
// this.posthog.trackEvent({ distinctId: `tenant-${tenantId}`,
// distinctId: `tenant-${tenantId}`, event: VENDOR_TRANSACTIONS_VIEWED,
// event: CUSTOMER_TRANSACTIONS_VIEWED, properties: {},
// properties: {}, });
// }); }
// }
// private handleTrackVendorTransactionsViewedEvent( @OnEvent(events.reports.onSalesByItemViewed)
// { tenantId }: ReportsEvents handleTrackSalesByItemViewedEvent({ tenantId }: ReportsEvents) {
// ) { this.posthog.trackEvent({
// this.posthog.trackEvent({ distinctId: `tenant-${tenantId}`,
// distinctId: `tenant-${tenantId}`, event: SALES_BY_ITEM_VIEWED,
// event: VENDOR_TRANSACTIONS_VIEWED, properties: {},
// properties: {}, });
// }); }
// }
// private handleTrackSalesByItemViewedEvent({ tenantId }: ReportsEvents) { @OnEvent(events.reports.onPurchasesByItemViewed)
// this.posthog.trackEvent({ handleTrackPurchasesByItemViewedEvent({ tenantId }: ReportsEvents) {
// distinctId: `tenant-${tenantId}`, this.posthog.trackEvent({
// event: SALES_BY_ITEM_VIEWED, distinctId: `tenant-${tenantId}`,
// properties: {}, event: PURCHASES_BY_ITEM_VIEWED,
// }); properties: {},
// } });
}
// private handleTrackPurchasesByItemViewedEvent( }
// { tenantId }: ReportsEvents
// ) {
// this.posthog.trackEvent({
// distinctId: `tenant-${tenantId}`,
// event: PURCHASES_BY_ITEM_VIEWED,
// properties: {},
// });
// }
// }

View File

@@ -70,6 +70,7 @@ import { PaymentsReceivedImportable } from './commands/PaymentsReceivedImportabl
PaymentReceivedGLEntries, PaymentReceivedGLEntries,
PaymentsReceivedExportable, PaymentsReceivedExportable,
PaymentsReceivedImportable, PaymentsReceivedImportable,
PaymentReceivedValidators
], ],
imports: [ imports: [
ChromiumlyTenancyModule, ChromiumlyTenancyModule,

View File

@@ -14,15 +14,14 @@ export class PaymentReceivedBrandingTemplate {
/** /**
* Retrieves the payment received pdf template. * Retrieves the payment received pdf template.
* @param {number} paymentTemplateId * @param {number} paymentTemplateId
* @returns * @returns
*/ */
public async getPaymentReceivedPdfTemplate(paymentTemplateId: number) { public async getPaymentReceivedPdfTemplate(paymentTemplateId: number) {
const template = await this.getPdfTemplateService.getPdfTemplate( const template =
paymentTemplateId await this.getPdfTemplateService.getPdfTemplate(paymentTemplateId);
);
// Retrieves the organization branding attributes. // Retrieves the organization branding attributes.
const commonOrgBrandingAttrs = const commonOrgBrandingAttrs =
await this.getOrgBrandingAttributes.getOrganizationBrandingAttributes(); await this.getOrgBrandingAttributes.execute();
// Merges the default branding attributes with common organization branding attrs. // Merges the default branding attributes with common organization branding attrs.
const organizationBrandingAttrs = { const organizationBrandingAttrs = {
@@ -35,7 +34,7 @@ export class PaymentReceivedBrandingTemplate {
}; };
const attributes = mergePdfTemplateWithDefaultAttributes( const attributes = mergePdfTemplateWithDefaultAttributes(
brandingTemplateAttrs, brandingTemplateAttrs,
organizationBrandingAttrs organizationBrandingAttrs,
); );
return { return {
...template, ...template,

View File

@@ -6,6 +6,8 @@ import { GetPdfTemplateService } from './queries/GetPdfTemplate.service';
import { EditPdfTemplateService } from './commands/EditPdfTemplate.service'; import { EditPdfTemplateService } from './commands/EditPdfTemplate.service';
import { AssignPdfTemplateDefaultService } from './commands/AssignPdfTemplateDefault.service'; import { AssignPdfTemplateDefaultService } from './commands/AssignPdfTemplateDefault.service';
import { GetOrganizationBrandingAttributesService } from './queries/GetOrganizationBrandingAttributes.service'; import { GetOrganizationBrandingAttributesService } from './queries/GetOrganizationBrandingAttributes.service';
import { GetPdfTemplates } from './queries/GetPdfTemplates.service';
import { GetPdfTemplateBrandingState } from './queries/GetPdfTemplateBrandingState.service';
@Injectable() @Injectable()
export class PdfTemplateApplication { export class PdfTemplateApplication {
@@ -13,11 +15,11 @@ export class PdfTemplateApplication {
private readonly createPdfTemplateService: CreatePdfTemplateService, private readonly createPdfTemplateService: CreatePdfTemplateService,
private readonly getPdfTemplateService: GetPdfTemplateService, private readonly getPdfTemplateService: GetPdfTemplateService,
private readonly deletePdfTemplateService: DeletePdfTemplateService, private readonly deletePdfTemplateService: DeletePdfTemplateService,
// private readonly getPdfTemplatesService: GetPdfTemplatesService, private readonly getPdfTemplatesService: GetPdfTemplates,
private readonly editPdfTemplateService: EditPdfTemplateService, private readonly editPdfTemplateService: EditPdfTemplateService,
private readonly assignPdfTemplateDefaultService: AssignPdfTemplateDefaultService, private readonly assignPdfTemplateDefaultService: AssignPdfTemplateDefaultService,
// private readonly getPdfTemplateBrandingStateService: GetPdfTemplateBrandingStateService, private readonly getPdfTemplateBrandingStateService: GetPdfTemplateBrandingState,
// private readonly getOrganizationBrandingAttributesService: GetOrganizationBrandingAttributesService, private readonly getOrganizationBrandingAttributesService: GetOrganizationBrandingAttributesService,
) {} ) {}
/** /**
@@ -59,8 +61,8 @@ export class PdfTemplateApplication {
* Retrieves all PDF templates. * Retrieves all PDF templates.
* @param {string} resource - The resource type to filter templates. * @param {string} resource - The resource type to filter templates.
*/ */
public async getPdfTemplates(resource: string) { public async getPdfTemplates(query?: { resource?: string }) {
// return this.getPdfTemplatesService.execute(resource); return this.getPdfTemplatesService.getPdfTemplates(query);
} }
/** /**
@@ -77,10 +79,9 @@ export class PdfTemplateApplication {
/** /**
* Gets the PDF template branding state. * Gets the PDF template branding state.
* @param {number} tenantId - The tenant ID.
*/ */
public async getPdfTemplateBrandingState(tenantId: number) { public async getPdfTemplateBrandingState() {
// return this.getPdfTemplateBrandingStateService.execute(tenantId); return this.getPdfTemplateBrandingStateService.execute();
} }
/** /**
@@ -93,4 +94,12 @@ export class PdfTemplateApplication {
templateId, templateId,
); );
} }
/**
* Retrieves the organization branding attributes.
* @returns {Promise<CommonOrganizationBrandingAttributes>} The organization branding attributes.
*/
getOrganizationBrandingAttributes() {
return this.getOrganizationBrandingAttributesService.execute();
}
} }

View File

@@ -65,7 +65,7 @@ export class PdfTemplatesController {
description: 'The PDF templates have been successfully retrieved.', description: 'The PDF templates have been successfully retrieved.',
}) })
async getPdfTemplates(@Body('resource') resource: string) { async getPdfTemplates(@Body('resource') resource: string) {
return this.pdfTemplateApplication.getPdfTemplates(resource); return this.pdfTemplateApplication.getPdfTemplates({ resource });
} }
@Put(':id') @Put(':id')

View File

@@ -11,6 +11,8 @@ import { PdfTemplatesController } from './PdfTemplates.controller';
import { GetPdfTemplateService } from './queries/GetPdfTemplate.service'; import { GetPdfTemplateService } from './queries/GetPdfTemplate.service';
import { BrandingTemplateDTOTransformer } from './BrandingTemplateDTOTransformer'; import { BrandingTemplateDTOTransformer } from './BrandingTemplateDTOTransformer';
import { GetOrganizationBrandingAttributesService } from './queries/GetOrganizationBrandingAttributes.service'; import { GetOrganizationBrandingAttributesService } from './queries/GetOrganizationBrandingAttributes.service';
import { GetPdfTemplates } from './queries/GetPdfTemplates.service';
import { GetPdfTemplateBrandingState } from './queries/GetPdfTemplateBrandingState.service';
@Module({ @Module({
exports: [ exports: [
@@ -25,12 +27,14 @@ import { GetOrganizationBrandingAttributesService } from './queries/GetOrganizat
CreatePdfTemplateService, CreatePdfTemplateService,
DeletePdfTemplateService, DeletePdfTemplateService,
GetPdfTemplateService, GetPdfTemplateService,
GetPdfTemplates,
EditPdfTemplateService, EditPdfTemplateService,
AssignPdfTemplateDefaultService, AssignPdfTemplateDefaultService,
TenancyContext, TenancyContext,
TransformerInjectable, TransformerInjectable,
BrandingTemplateDTOTransformer, BrandingTemplateDTOTransformer,
GetOrganizationBrandingAttributesService, GetOrganizationBrandingAttributesService,
GetPdfTemplateBrandingState
], ],
}) })
export class PdfTemplatesModule {} export class PdfTemplatesModule {}

View File

@@ -10,7 +10,7 @@ export class GetOrganizationBrandingAttributesService {
* Retrieves the given organization branding attributes initial state. * Retrieves the given organization branding attributes initial state.
* @returns {Promise<CommonOrganizationBrandingAttributes>} * @returns {Promise<CommonOrganizationBrandingAttributes>}
*/ */
public async getOrganizationBrandingAttributes(): Promise<CommonOrganizationBrandingAttributes> { public async execute(): Promise<CommonOrganizationBrandingAttributes> {
const tenant = await this.tenancyContext.getTenant(true); const tenant = await this.tenancyContext.getTenant(true);
const tenantMetadata = tenant.metadata; const tenantMetadata = tenant.metadata;

View File

@@ -0,0 +1,16 @@
import { Injectable } from '@nestjs/common';
import { GetOrganizationBrandingAttributesService } from './GetOrganizationBrandingAttributes.service';
@Injectable()
export class GetPdfTemplateBrandingState {
constructor(
private readonly getOrgBrandingAttributes: GetOrganizationBrandingAttributesService,
) {}
async execute() {
const brandingAttributes =
await this.getOrgBrandingAttributes.execute();
return brandingAttributes;
}
}

View File

@@ -19,9 +19,9 @@ export class SaleEstimatePdfTemplate {
public async getEstimatePdfTemplate(estimateTemplateId: number) { public async getEstimatePdfTemplate(estimateTemplateId: number) {
const template = const template =
await this.getPdfTemplateService.getPdfTemplate(estimateTemplateId); await this.getPdfTemplateService.getPdfTemplate(estimateTemplateId);
// Retreives the organization branding attributes. // Retreives the organization branding attributes.
const commonOrgBrandingAttrs = const commonOrgBrandingAttrs = await this.getOrgBrandingAttrs.execute();
await this.getOrgBrandingAttrs.getOrganizationBrandingAttributes();
// Merge the default branding attributes with organization attrs. // Merge the default branding attributes with organization attrs.
const orgainizationBrandingAttrs = { const orgainizationBrandingAttrs = {

View File

@@ -19,9 +19,10 @@ export class SaleInvoicePdfTemplate {
async getInvoicePdfTemplate(invoiceTemplateId: number) { async getInvoicePdfTemplate(invoiceTemplateId: number) {
const template = const template =
await this.getPdfTemplateService.getPdfTemplate(invoiceTemplateId); await this.getPdfTemplateService.getPdfTemplate(invoiceTemplateId);
// Retrieves the organization branding attributes. // Retrieves the organization branding attributes.
const commonOrgBrandingAttrs = const commonOrgBrandingAttrs =
await this.getOrgBrandingAttributes.getOrganizationBrandingAttributes(); await this.getOrgBrandingAttributes.execute();
const organizationBrandingAttrs = { const organizationBrandingAttrs = {
...defaultInvoicePdfTemplateAttributes, ...defaultInvoicePdfTemplateAttributes,