mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 13:20:31 +00:00
refactor: branches and warehouses modules
This commit is contained in:
@@ -15,7 +15,18 @@ import { BranchesSettingsService } from './BranchesSettings';
|
||||
import { BranchCommandValidator } from './commands/BranchCommandValidator.service';
|
||||
import { BranchTransactionDTOTransformer } from './integrations/BranchTransactionDTOTransform';
|
||||
import { ManualJournalBranchesDTOTransformer } from './integrations/ManualJournals/ManualJournalDTOTransformer.service';
|
||||
|
||||
import { BillBranchValidateSubscriber } from './subscribers/Validators/BillBranchSubscriber';
|
||||
import { InventoryAdjustmentBranchValidateSubscriber } from './subscribers/Validators/InventoryAdjustmentBranchValidatorSubscriber';
|
||||
import { ExpenseBranchValidateSubscriber } from './subscribers/Validators/ExpenseBranchSubscriber';
|
||||
import { CreditNoteBranchValidateSubscriber } from './subscribers/Validators/CreditNoteBranchesSubscriber';
|
||||
import { CreditNoteRefundBranchValidateSubscriber } from './subscribers/Validators/CreditNoteRefundBranchSubscriber';
|
||||
import { ContactBranchValidateSubscriber } from './subscribers/Validators/ContactOpeningBalanceBranchSubscriber';
|
||||
import { ManualJournalBranchValidateSubscriber } from './subscribers/Validators/ManualJournalBranchSubscriber';
|
||||
import { SaleEstimateBranchValidateSubscriber } from './subscribers/Validators/SaleEstimateMultiBranchesSubscriber';
|
||||
import { PaymentMadeBranchValidateSubscriber } from './subscribers/Validators/PaymentMadeBranchSubscriber';
|
||||
import { PaymentReceiveBranchValidateSubscriber } from './subscribers/Validators/PaymentReceiveBranchSubscriber';
|
||||
import { SaleReceiptBranchValidateSubscriber } from './subscribers/Validators/SaleReceiptBranchesSubscriber';
|
||||
import { VendorCreditBranchValidateSubscriber } from './subscribers/Validators/VendorCreditBranchSubscriber';
|
||||
@Module({
|
||||
imports: [TenancyDatabaseModule],
|
||||
controllers: [BranchesController],
|
||||
@@ -34,6 +45,18 @@ import { ManualJournalBranchesDTOTransformer } from './integrations/ManualJourna
|
||||
BranchCommandValidator,
|
||||
BranchTransactionDTOTransformer,
|
||||
ManualJournalBranchesDTOTransformer,
|
||||
BillBranchValidateSubscriber,
|
||||
CreditNoteBranchValidateSubscriber,
|
||||
CreditNoteRefundBranchValidateSubscriber,
|
||||
ContactBranchValidateSubscriber,
|
||||
ExpenseBranchValidateSubscriber,
|
||||
InventoryAdjustmentBranchValidateSubscriber,
|
||||
ManualJournalBranchValidateSubscriber,
|
||||
PaymentMadeBranchValidateSubscriber,
|
||||
PaymentReceiveBranchValidateSubscriber,
|
||||
SaleEstimateBranchValidateSubscriber,
|
||||
SaleReceiptBranchValidateSubscriber,
|
||||
VendorCreditBranchValidateSubscriber,
|
||||
],
|
||||
exports: [
|
||||
BranchesSettingsService,
|
||||
|
||||
@@ -1,26 +1,27 @@
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import { Knex } from 'knex';
|
||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { Knex } from 'knex';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { BankTransaction } from '@/modules/BankingTransactions/models/BankTransaction';
|
||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||
|
||||
// @Service()
|
||||
// export class CashflowTransactionsActivateBranches {
|
||||
// @Inject()
|
||||
// private tenancy: HasTenancyService;
|
||||
@Injectable()
|
||||
export class CashflowTransactionsActivateBranches {
|
||||
constructor(
|
||||
private readonly bankTransaction: TenantModelProxy<typeof BankTransaction>,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Updates all cashflow transactions with the primary branch.
|
||||
// * @param {number} tenantId
|
||||
// * @param {number} primaryBranchId
|
||||
// * @returns {Promise<void>}
|
||||
// */
|
||||
// public updateCashflowTransactionsWithBranch = async (
|
||||
// tenantId: number,
|
||||
// primaryBranchId: number,
|
||||
// trx?: Knex.Transaction
|
||||
// ) => {
|
||||
// const { CashflowTransaction } = this.tenancy.models(tenantId);
|
||||
|
||||
// // Updates the cashflow transactions with primary branch.
|
||||
// await CashflowTransaction.query(trx).update({ branchId: primaryBranchId });
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Updates all cashflow transactions with the primary branch.
|
||||
* @param {number} primaryBranchId - The primary branch id.
|
||||
* @param {Knex.Transaction} trx - The database transaction.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public updateCashflowTransactionsWithBranch = async (
|
||||
primaryBranchId: number,
|
||||
trx?: Knex.Transaction,
|
||||
) => {
|
||||
// Updates the cashflow transactions with primary branch.
|
||||
await this.bankTransaction()
|
||||
.query(trx)
|
||||
.update({ branchId: primaryBranchId });
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,26 +1,24 @@
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import { Knex } from 'knex';
|
||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { Knex } from 'knex';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||
import { Expense } from '@/modules/Expenses/models/Expense.model';
|
||||
|
||||
// @Service()
|
||||
// export class ExpensesActivateBranches {
|
||||
// @Inject()
|
||||
// private tenancy: HasTenancyService;
|
||||
@Injectable()
|
||||
export class ExpensesActivateBranches {
|
||||
constructor(
|
||||
private readonly expenseModel: TenantModelProxy<typeof Expense>,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Updates all expenses transactions with the primary branch.
|
||||
// * @param {number} tenantId
|
||||
// * @param {number} primaryBranchId
|
||||
// * @returns {Promise<void>}
|
||||
// */
|
||||
// public updateExpensesWithBranch = async (
|
||||
// tenantId: number,
|
||||
// primaryBranchId: number,
|
||||
// trx?: Knex.Transaction
|
||||
// ) => {
|
||||
// const { Expense } = this.tenancy.models(tenantId);
|
||||
|
||||
// // Updates the expenses with primary branch.
|
||||
// await Expense.query(trx).update({ branchId: primaryBranchId });
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Updates all expenses transactions with the primary branch.
|
||||
* @param {number} primaryBranchId
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public updateExpensesWithBranch = async (
|
||||
primaryBranchId: number,
|
||||
trx?: Knex.Transaction,
|
||||
) => {
|
||||
// Updates the expenses with primary branch.
|
||||
await this.expenseModel().query(trx).update({ branchId: primaryBranchId });
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
// import { Knex } from 'knex';
|
||||
import { Knex } from 'knex';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||
import { ManualJournal } from '@/modules/ManualJournals/models/ManualJournal';
|
||||
|
||||
// @Service()
|
||||
// export class ManualJournalsActivateBranches {
|
||||
// @Inject()
|
||||
// private tenancy: HasTenancyService;
|
||||
@Injectable()
|
||||
export class ManualJournalsActivateBranches {
|
||||
constructor(
|
||||
private readonly manualJournalModel: TenantModelProxy<typeof ManualJournal>,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Updates all manual journals transactions with the primary branch.
|
||||
// * @param {number} tenantId
|
||||
// * @param {number} primaryBranchId
|
||||
// * @returns {Promise<void>}
|
||||
// */
|
||||
// public updateManualJournalsWithBranch = async (
|
||||
// tenantId: number,
|
||||
// primaryBranchId: number,
|
||||
// trx?: Knex.Transaction
|
||||
// ) => {
|
||||
// const { ManualJournal } = this.tenancy.models(tenantId);
|
||||
|
||||
// // Updates the manual journal with primary branch.
|
||||
// await ManualJournal.query(trx).update({ branchId: primaryBranchId });
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Updates all manual journals transactions with the primary branch.
|
||||
* @param {number} primaryBranchId
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public updateManualJournalsWithBranch = async (
|
||||
primaryBranchId: number,
|
||||
trx?: Knex.Transaction,
|
||||
) => {
|
||||
// Updates the manual journal with primary branch.
|
||||
await this.manualJournalModel()
|
||||
.query(trx)
|
||||
.update({ branchId: primaryBranchId });
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,23 +1,24 @@
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import { ServiceError } from '@/exceptions';
|
||||
// import { IManualJournalDTO, IManualJournalEntryDTO } from '@/interfaces';
|
||||
// import { ERRORS } from './constants';
|
||||
import { IManualJournalDTO } from '@/modules/ManualJournals/types/ManualJournals.types';
|
||||
import { IManualJournalEntryDTO } from '@/modules/ManualJournals/types/ManualJournals.types';
|
||||
import { ERRORS } from './constants';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { ServiceError } from '@/modules/Items/ServiceError';
|
||||
|
||||
// @Service()
|
||||
// export class ManualJournalBranchesValidator {
|
||||
// /**
|
||||
// * Validates the DTO entries should have branch id.
|
||||
// * @param {IManualJournalDTO} manualJournalDTO
|
||||
// */
|
||||
// public validateEntriesHasBranchId = async (
|
||||
// manualJournalDTO: IManualJournalDTO
|
||||
// ) => {
|
||||
// const hasNoIdEntries = manualJournalDTO.entries.filter(
|
||||
// (entry: IManualJournalEntryDTO) =>
|
||||
// !entry.branchId && !manualJournalDTO.branchId
|
||||
// );
|
||||
// if (hasNoIdEntries.length > 0) {
|
||||
// throw new ServiceError(ERRORS.MANUAL_JOURNAL_ENTRIES_HAVE_NO_BRANCH_ID);
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
@Injectable()
|
||||
export class ManualJournalBranchesValidator {
|
||||
/**
|
||||
* Validates the DTO entries should have branch id.
|
||||
* @param {IManualJournalDTO} manualJournalDTO
|
||||
*/
|
||||
public validateEntriesHasBranchId = async (
|
||||
manualJournalDTO: IManualJournalDTO,
|
||||
) => {
|
||||
const hasNoIdEntries = manualJournalDTO.entries.filter(
|
||||
(entry: IManualJournalEntryDTO) =>
|
||||
!entry.branchId && !manualJournalDTO.branchId,
|
||||
);
|
||||
if (hasNoIdEntries.length > 0) {
|
||||
throw new ServiceError(ERRORS.MANUAL_JOURNAL_ENTRIES_HAVE_NO_BRANCH_ID);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,26 +1,23 @@
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
// import { Knex } from 'knex';
|
||||
import { Knex } from 'knex';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||
import { Bill } from '@/modules/Bills/models/Bill';
|
||||
|
||||
// @Service()
|
||||
// export class BillActivateBranches {
|
||||
// @Inject()
|
||||
// private tenancy: HasTenancyService;
|
||||
@Injectable()
|
||||
export class BillActivateBranches {
|
||||
constructor(private readonly billModel: TenantModelProxy<typeof Bill>) {}
|
||||
|
||||
// /**
|
||||
// * Updates all bills transactions with the primary branch.
|
||||
// * @param {number} tenantId
|
||||
// * @param {number} primaryBranchId
|
||||
// * @returns {Promise<void>}
|
||||
// */
|
||||
// public updateBillsWithBranch = async (
|
||||
// tenantId: number,
|
||||
// primaryBranchId: number,
|
||||
// trx?: Knex.Transaction
|
||||
// ) => {
|
||||
// const { Bill } = this.tenancy.models(tenantId);
|
||||
|
||||
// // Updates the sale invoice with primary branch.
|
||||
// await Bill.query(trx).update({ branchId: primaryBranchId });
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Updates all bills transactions with the primary branch.
|
||||
* @param {number} tenantId
|
||||
* @param {number} primaryBranchId
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public updateBillsWithBranch = async (
|
||||
primaryBranchId: number,
|
||||
trx?: Knex.Transaction,
|
||||
) => {
|
||||
// Updates the sale invoice with primary branch.
|
||||
await Bill.query(trx).update({ branchId: primaryBranchId });
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,26 +1,24 @@
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
// import { Knex } from 'knex';
|
||||
import { Knex } from 'knex';
|
||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||
import { BillPayment } from '@/modules/BillPayments/models/BillPayment';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
// @Service()
|
||||
// export class BillPaymentsActivateBranches {
|
||||
// @Inject()
|
||||
// tenancy: HasTenancyService;
|
||||
@Injectable()
|
||||
export class BillPaymentsActivateBranches {
|
||||
constructor(
|
||||
private readonly billPaymentModel: TenantModelProxy<typeof BillPayment>,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Updates all bills payments transcations with the primary branch.
|
||||
// * @param {number} tenantId
|
||||
// * @param {number} primaryBranchId
|
||||
// * @returns {Promise<void>}
|
||||
// */
|
||||
// public updateBillPaymentsWithBranch = async (
|
||||
// tenantId: number,
|
||||
// primaryBranchId: number,
|
||||
// trx?: Knex.Transaction
|
||||
// ) => {
|
||||
// const { BillPayment } = this.tenancy.models(tenantId);
|
||||
|
||||
// // Updates the bill payments with primary branch.
|
||||
// await BillPayment.query(trx).update({ branchId: primaryBranchId });
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Updates all bills payments transcations with the primary branch.
|
||||
* @param {number} primaryBranchId
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public updateBillPaymentsWithBranch = async (
|
||||
primaryBranchId: number,
|
||||
trx?: Knex.Transaction
|
||||
) => {
|
||||
// Updates the bill payments with primary branch.
|
||||
await this.billPaymentModel().query(trx).update({ branchId: primaryBranchId });
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,26 +1,27 @@
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
// import { Knex } from 'knex';
|
||||
import { Knex } from 'knex';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||
import { VendorCredit } from '@/modules/VendorCredit/models/VendorCredit';
|
||||
|
||||
// @Service()
|
||||
// export class VendorCreditActivateBranches {
|
||||
// @Inject()
|
||||
// tenancy: HasTenancyService;
|
||||
@Injectable()
|
||||
export class VendorCreditActivateBranches {
|
||||
constructor(
|
||||
private readonly vendorCreditModel: TenantModelProxy<typeof VendorCredit>,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Updates all vendor credits transcations with the primary branch.
|
||||
// * @param {number} tenantId
|
||||
// * @param {number} primaryBranchId
|
||||
// * @returns {Promise<void>}
|
||||
// */
|
||||
// public updateVendorCreditsWithBranch = async (
|
||||
// tenantId: number,
|
||||
// primaryBranchId: number,
|
||||
// trx?: Knex.Transaction
|
||||
// ) => {
|
||||
// const { VendorCredit } = this.tenancy.models(tenantId);
|
||||
|
||||
// // Updates the vendors credits with primary branch.
|
||||
// await VendorCredit.query(trx).update({ branchId: primaryBranchId });
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Updates all vendor credits transcations with the primary branch.
|
||||
* @param {number} tenantId
|
||||
* @param {number} primaryBranchId
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public updateVendorCreditsWithBranch = async (
|
||||
primaryBranchId: number,
|
||||
trx?: Knex.Transaction,
|
||||
) => {
|
||||
// Updates the vendors credits with primary branch.
|
||||
await this.vendorCreditModel()
|
||||
.query(trx)
|
||||
.update({ branchId: primaryBranchId });
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,26 +1,24 @@
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
// import { Knex } from 'knex';
|
||||
import { Knex } from 'knex';
|
||||
import { CreditNote } from '@/modules/CreditNotes/models/CreditNote';
|
||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
// @Service()
|
||||
// export class CreditNoteActivateBranches {
|
||||
// @Inject()
|
||||
// private tenancy: HasTenancyService;
|
||||
@Injectable()
|
||||
export class CreditNoteActivateBranches {
|
||||
constructor(
|
||||
private readonly creditNoteModel: TenantModelProxy<typeof CreditNote>,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Updates all creidt notes transactions with the primary branch.
|
||||
// * @param {number} tenantId
|
||||
// * @param {number} primaryBranchId
|
||||
// * @returns {Promise<void>}
|
||||
// */
|
||||
// public updateCreditsWithBranch = async (
|
||||
// tenantId: number,
|
||||
// primaryBranchId: number,
|
||||
// trx?: Knex.Transaction
|
||||
// ) => {
|
||||
// const { CreditNote } = this.tenancy.models(tenantId);
|
||||
|
||||
// // Updates the sale invoice with primary branch.
|
||||
// await CreditNote.query(trx).update({ branchId: primaryBranchId });
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Updates all creidt notes transactions with the primary branch.
|
||||
* @param {number} primaryBranchId
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public updateCreditsWithBranch = async (
|
||||
primaryBranchId: number,
|
||||
trx?: Knex.Transaction
|
||||
) => {
|
||||
// Updates the sale invoice with primary branch.
|
||||
await this.creditNoteModel().query(trx).update({ branchId: primaryBranchId });
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,26 +1,24 @@
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
// import { Knex } from 'knex';
|
||||
import { PaymentReceived } from '@/modules/PaymentReceived/models/PaymentReceived';
|
||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Knex } from 'knex';
|
||||
|
||||
// @Service()
|
||||
// export class PaymentReceiveActivateBranches {
|
||||
// @Inject()
|
||||
// tenancy: HasTenancyService;
|
||||
@Injectable()
|
||||
export class PaymentReceiveActivateBranches {
|
||||
constructor(
|
||||
private readonly paymentReceivedModel: TenantModelProxy<typeof PaymentReceived>,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Updates all creidt notes transactions with the primary branch.
|
||||
// * @param {number} tenantId
|
||||
// * @param {number} primaryBranchId
|
||||
// * @returns {Promise<void>}
|
||||
// */
|
||||
// public updatePaymentsWithBranch = async (
|
||||
// tenantId: number,
|
||||
// primaryBranchId: number,
|
||||
// trx?: Knex.Transaction
|
||||
// ) => {
|
||||
// const { PaymentReceive } = this.tenancy.models(tenantId);
|
||||
|
||||
// // Updates the sale invoice with primary branch.
|
||||
// await PaymentReceive.query(trx).update({ branchId: primaryBranchId });
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Updates all creidt notes transactions with the primary branch.
|
||||
* @param {number} primaryBranchId
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public updatePaymentsWithBranch = async (
|
||||
primaryBranchId: number,
|
||||
trx?: Knex.Transaction
|
||||
) => {
|
||||
// Updates the sale invoice with primary branch.
|
||||
await this.paymentReceivedModel().query(trx).update({ branchId: primaryBranchId });
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,26 +1,25 @@
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
// import { Knex } from 'knex';
|
||||
import { Knex } from 'knex';
|
||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||
import { PaymentReceived } from '@/modules/PaymentReceived/models/PaymentReceived';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
|
||||
// @Service()
|
||||
// export class SaleEstimateActivateBranches {
|
||||
// @Inject()
|
||||
// tenancy: HasTenancyService;
|
||||
@Injectable()
|
||||
export class SaleEstimateActivateBranches {
|
||||
constructor(
|
||||
@Inject(PaymentReceived.name)
|
||||
private readonly paymentReceivedModel: TenantModelProxy<typeof PaymentReceived>,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Updates all sale estimates transactions with the primary branch.
|
||||
// * @param {number} tenantId
|
||||
// * @param {number} primaryBranchId
|
||||
// * @returns {Promise<void>}
|
||||
// */
|
||||
// public updateEstimatesWithBranch = async (
|
||||
// tenantId: number,
|
||||
// primaryBranchId: number,
|
||||
// trx?: Knex.Transaction
|
||||
// ) => {
|
||||
// const { PaymentReceive } = this.tenancy.models(tenantId);
|
||||
|
||||
// // Updates the sale invoice with primary branch.
|
||||
// await PaymentReceive.query(trx).update({ branchId: primaryBranchId });
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Updates all sale estimates transactions with the primary branch.
|
||||
* @param {number} primaryBranchId
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public updateEstimatesWithBranch = async (
|
||||
primaryBranchId: number,
|
||||
trx?: Knex.Transaction
|
||||
) => {
|
||||
// Updates the sale invoice with primary branch.
|
||||
await this.paymentReceivedModel().query(trx).update({ branchId: primaryBranchId });
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
// import { Knex } from 'knex';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Knex } from 'knex';
|
||||
import { SaleInvoice } from '@/modules/SaleInvoices/models/SaleInvoice';
|
||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||
|
||||
// @Service()
|
||||
// export class SaleInvoiceActivateBranches {
|
||||
// @Inject()
|
||||
// private tenancy: HasTenancyService;
|
||||
@Injectable()
|
||||
export class SaleInvoiceActivateBranches {
|
||||
constructor(
|
||||
private readonly saleInvoiceModel: TenantModelProxy<typeof SaleInvoice>,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Updates all sale invoices transactions with the primary branch.
|
||||
// * @param {number} tenantId
|
||||
// * @param {number} primaryBranchId
|
||||
// * @returns {Promise<void>}
|
||||
// */
|
||||
// public updateInvoicesWithBranch = async (
|
||||
// tenantId: number,
|
||||
// primaryBranchId: number,
|
||||
// trx?: Knex.Transaction
|
||||
// ) => {
|
||||
// const { SaleInvoice } = this.tenancy.models(tenantId);
|
||||
|
||||
// // Updates the sale invoice with primary branch.
|
||||
// await SaleInvoice.query(trx).update({ branchId: primaryBranchId });
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Updates all sale invoices transactions with the primary branch.
|
||||
* @param {number} primaryBranchId
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public updateInvoicesWithBranch = async (
|
||||
primaryBranchId: number,
|
||||
trx?: Knex.Transaction,
|
||||
) => {
|
||||
// Updates the sale invoice with primary branch.
|
||||
await this.saleInvoiceModel()
|
||||
.query(trx)
|
||||
.update({ branchId: primaryBranchId });
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
// import { Knex } from 'knex';
|
||||
import { Knex } from 'knex';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { SaleReceipt } from '@/modules/SaleReceipts/models/SaleReceipt';
|
||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||
|
||||
// @Service()
|
||||
// export class SaleReceiptActivateBranches {
|
||||
// @Inject()
|
||||
// tenancy: HasTenancyService;
|
||||
@Injectable()
|
||||
export class SaleReceiptActivateBranches {
|
||||
constructor(
|
||||
private readonly saleReceiptModel: TenantModelProxy<typeof SaleReceipt>,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Updates all sale receipts transactions with the primary branch.
|
||||
// * @param {number} tenantId
|
||||
// * @param {number} primaryBranchId
|
||||
// * @returns {Promise<void>}
|
||||
// */
|
||||
// public updateReceiptsWithBranch = async (
|
||||
// tenantId: number,
|
||||
// primaryBranchId: number,
|
||||
// trx?: Knex.Transaction
|
||||
// ) => {
|
||||
// const { SaleReceipt } = this.tenancy.models(tenantId);
|
||||
|
||||
// // Updates the sale receipt with primary branch.
|
||||
// await SaleReceipt.query(trx).update({ branchId: primaryBranchId });
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Updates all sale receipts transactions with the primary branch.
|
||||
* @param {number} primaryBranchId
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public updateReceiptsWithBranch = async (
|
||||
primaryBranchId: number,
|
||||
trx?: Knex.Transaction,
|
||||
) => {
|
||||
// Updates the sale receipt with primary branch.
|
||||
await this.saleReceiptModel()
|
||||
.query(trx)
|
||||
.update({ branchId: primaryBranchId });
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,75 +1,65 @@
|
||||
// import { ServiceError } from '@/exceptions';
|
||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import { BranchesSettings } from '../BranchesSettings';
|
||||
// import { ERRORS } from './constants';
|
||||
import { ServiceError } from '@/modules/Items/ServiceError';
|
||||
import { BranchesSettingsService } from '../BranchesSettings';
|
||||
import { ERRORS } from './constants';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { Branch } from '../models/Branch.model';
|
||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||
|
||||
// @Service()
|
||||
// export class ValidateBranchExistance {
|
||||
// @Inject()
|
||||
// tenancy: HasTenancyService;
|
||||
@Injectable()
|
||||
export class ValidateBranchExistance {
|
||||
constructor(
|
||||
private readonly branchesSettings: BranchesSettingsService,
|
||||
|
||||
// @Inject()
|
||||
// branchesSettings: BranchesSettings;
|
||||
@Inject(Branch.name)
|
||||
private readonly branchModel: TenantModelProxy<typeof Branch>,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Validate transaction branch id when the feature is active.
|
||||
// * @param {number} tenantId
|
||||
// * @param {number} branchId
|
||||
// * @returns {Promise<void>}
|
||||
// */
|
||||
// public validateTransactionBranchWhenActive = async (
|
||||
// tenantId: number,
|
||||
// branchId: number | null
|
||||
// ) => {
|
||||
// const isActive = this.branchesSettings.isMultiBranchesActive(tenantId);
|
||||
/**
|
||||
* Validate transaction branch id when the feature is active.
|
||||
* @param {number} branchId
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public validateTransactionBranchWhenActive = async (
|
||||
branchId: number | null,
|
||||
) => {
|
||||
const isActive = this.branchesSettings.isMultiBranchesActive();
|
||||
|
||||
// // Can't continue if the multi-warehouses feature is inactive.
|
||||
// if (!isActive) return;
|
||||
// Can't continue if the multi-warehouses feature is inactive.
|
||||
if (!isActive) return;
|
||||
|
||||
// return this.validateTransactionBranch(tenantId, branchId);
|
||||
// };
|
||||
return this.validateTransactionBranch(branchId);
|
||||
};
|
||||
|
||||
// /**
|
||||
// * Validate transaction branch id existance.
|
||||
// * @param {number} tenantId
|
||||
// * @param {number} branchId
|
||||
// * @return {Promise<void>}
|
||||
// */
|
||||
// public validateTransactionBranch = async (
|
||||
// tenantId: number,
|
||||
// branchId: number | null
|
||||
// ) => {
|
||||
// this.validateBranchIdExistance(branchId);
|
||||
/**
|
||||
* Validate transaction branch id existance.
|
||||
* @param {number} branchId
|
||||
* @return {Promise<void>}
|
||||
*/
|
||||
public validateTransactionBranch = async (branchId: number | null) => {
|
||||
this.validateBranchIdExistance(branchId);
|
||||
|
||||
// await this.validateBranchExistance(tenantId, branchId);
|
||||
// };
|
||||
await this.validateBranchExistance(branchId);
|
||||
};
|
||||
|
||||
// /**
|
||||
// *
|
||||
// * @param branchId
|
||||
// */
|
||||
// public validateBranchIdExistance = (branchId: number | null) => {
|
||||
// if (!branchId) {
|
||||
// throw new ServiceError(ERRORS.BRANCH_ID_REQUIRED);
|
||||
// }
|
||||
// };
|
||||
/**
|
||||
* Validates the branch id existance.
|
||||
* @param {number} branchId
|
||||
*/
|
||||
public validateBranchIdExistance = (branchId: number | null) => {
|
||||
if (!branchId) {
|
||||
throw new ServiceError(ERRORS.BRANCH_ID_REQUIRED);
|
||||
}
|
||||
};
|
||||
|
||||
// /**
|
||||
// *
|
||||
// * @param tenantId
|
||||
// * @param branchId
|
||||
// */
|
||||
// public validateBranchExistance = async (
|
||||
// tenantId: number,
|
||||
// branchId: number
|
||||
// ) => {
|
||||
// const { Branch } = this.tenancy.models(tenantId);
|
||||
/**
|
||||
* Validates the branch id existance.
|
||||
* @param {number} branchId
|
||||
*/
|
||||
public validateBranchExistance = async (branchId: number) => {
|
||||
const branch = await this.branchModel().query().findById(branchId);
|
||||
|
||||
// const branch = await Branch.query().findById(branchId);
|
||||
|
||||
// if (!branch) {
|
||||
// throw new ServiceError(ERRORS.BRANCH_ID_NOT_FOUND);
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
if (!branch) {
|
||||
throw new ServiceError(ERRORS.BRANCH_ID_NOT_FOUND);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,38 +1,29 @@
|
||||
// import { IBranchesActivatedPayload } from '@/interfaces';
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import events from '@/subscribers/events';
|
||||
// import { CashflowTransactionsActivateBranches } from '../../Integrations/Cashflow/CashflowActivateBranches';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { CashflowTransactionsActivateBranches } from '../../Integrations/Cashflow/CashflowActivateBranches';
|
||||
import { IBranchesActivatedPayload } from '../../Branches.types';
|
||||
import { events } from '@/common/events/events';
|
||||
|
||||
// @Service()
|
||||
// export class CreditNoteActivateBranchesSubscriber {
|
||||
// @Inject()
|
||||
// private cashflowActivateBranches: CashflowTransactionsActivateBranches;
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// public attach(bus) {
|
||||
// bus.subscribe(
|
||||
// events.branch.onActivated,
|
||||
// this.updateCashflowWithBranchOnActivated
|
||||
// );
|
||||
// return bus;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Updates accounts transactions with the primary branch once
|
||||
// * the multi-branches is activated.
|
||||
// * @param {IBranchesActivatedPayload}
|
||||
// */
|
||||
// private updateCashflowWithBranchOnActivated = async ({
|
||||
// tenantId,
|
||||
// primaryBranch,
|
||||
// trx,
|
||||
// }: IBranchesActivatedPayload) => {
|
||||
// await this.cashflowActivateBranches.updateCashflowTransactionsWithBranch(
|
||||
// tenantId,
|
||||
// primaryBranch.id,
|
||||
// trx
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
@Injectable()
|
||||
export class CreditNoteActivateBranchesSubscriber {
|
||||
constructor(
|
||||
private readonly cashflowActivateBranches: CashflowTransactionsActivateBranches,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Updates accounts transactions with the primary branch once
|
||||
* the multi-branches is activated.
|
||||
* @param {IBranchesActivatedPayload}
|
||||
*/
|
||||
@OnEvent(events.branch.onActivated)
|
||||
async updateCashflowWithBranchOnActivated({
|
||||
|
||||
primaryBranch,
|
||||
trx,
|
||||
}: IBranchesActivatedPayload) {
|
||||
await this.cashflowActivateBranches.updateCashflowTransactionsWithBranch(
|
||||
primaryBranch.id,
|
||||
trx
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,38 +1,28 @@
|
||||
// import { IBranchesActivatedPayload } from '@/interfaces';
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import { CreditNoteActivateBranches } from '../../Integrations/Sales/CreditNoteBranchesActivate';
|
||||
// import events from '@/subscribers/events';
|
||||
import { events } from '@/common/events/events';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { IBranchesActivatedPayload } from '../../Branches.types';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { CreditNoteActivateBranches } from '../../integrations/Sales/CreditNoteBranchesActivate';
|
||||
|
||||
// @Service()
|
||||
// export class CreditNoteActivateBranchesSubscriber {
|
||||
// @Inject()
|
||||
// private creditNotesActivateBranches: CreditNoteActivateBranches;
|
||||
@Injectable()
|
||||
export class CreditNoteActivateBranchesSubscriber {
|
||||
constructor(
|
||||
private readonly creditNotesActivateBranches: CreditNoteActivateBranches,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// public attach(bus) {
|
||||
// bus.subscribe(
|
||||
// events.branch.onActivated,
|
||||
// this.updateCreditNoteWithBranchOnActivated
|
||||
// );
|
||||
// return bus;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Updates accounts transactions with the primary branch once
|
||||
// * the multi-branches is activated.
|
||||
// * @param {IBranchesActivatedPayload}
|
||||
// */
|
||||
// private updateCreditNoteWithBranchOnActivated = async ({
|
||||
// tenantId,
|
||||
// primaryBranch,
|
||||
// trx,
|
||||
// }: IBranchesActivatedPayload) => {
|
||||
// await this.creditNotesActivateBranches.updateCreditsWithBranch(
|
||||
// tenantId,
|
||||
// primaryBranch.id,
|
||||
// trx
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Updates accounts transactions with the primary branch once
|
||||
* the multi-branches is activated.
|
||||
* @param {IBranchesActivatedPayload}
|
||||
*/
|
||||
@OnEvent(events.branch.onActivated)
|
||||
async updateCreditNoteWithBranchOnActivated({
|
||||
primaryBranch,
|
||||
trx,
|
||||
}: IBranchesActivatedPayload) {
|
||||
await this.creditNotesActivateBranches.updateCreditsWithBranch(
|
||||
primaryBranch.id,
|
||||
trx
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,38 +1,28 @@
|
||||
// import { IBranchesActivatedPayload } from '@/interfaces';
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import events from '@/subscribers/events';
|
||||
// import { ExpensesActivateBranches } from '../../Integrations/Expense/ExpensesActivateBranches';
|
||||
import { IBranchesActivatedPayload } from '../../Branches.types';
|
||||
import { events } from '@/common/events/events';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { ExpensesActivateBranches } from '../../Integrations/Expense/ExpensesActivateBranches';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
|
||||
// @Service()
|
||||
// export class ExpenseActivateBranchesSubscriber {
|
||||
// @Inject()
|
||||
// private expensesActivateBranches: ExpensesActivateBranches;
|
||||
@Injectable()
|
||||
export class ExpenseActivateBranchesSubscriber {
|
||||
constructor(
|
||||
private readonly expensesActivateBranches: ExpensesActivateBranches,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// public attach(bus) {
|
||||
// bus.subscribe(
|
||||
// events.branch.onActivated,
|
||||
// this.updateExpensesWithBranchOnActivated
|
||||
// );
|
||||
// return bus;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Updates accounts transactions with the primary branch once
|
||||
// * the multi-branches is activated.
|
||||
// * @param {IBranchesActivatedPayload}
|
||||
// */
|
||||
// private updateExpensesWithBranchOnActivated = async ({
|
||||
// tenantId,
|
||||
// primaryBranch,
|
||||
// trx,
|
||||
// }: IBranchesActivatedPayload) => {
|
||||
// await this.expensesActivateBranches.updateExpensesWithBranch(
|
||||
// tenantId,
|
||||
// primaryBranch.id,
|
||||
// trx
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Updates accounts transactions with the primary branch once
|
||||
* the multi-branches is activated.
|
||||
* @param {IBranchesActivatedPayload}
|
||||
*/
|
||||
@OnEvent(events.branch.onActivated)
|
||||
async updateExpensesWithBranchOnActivated({
|
||||
primaryBranch,
|
||||
trx,
|
||||
}: IBranchesActivatedPayload) {
|
||||
await this.expensesActivateBranches.updateExpensesWithBranch(
|
||||
primaryBranch.id,
|
||||
trx,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,38 +1,28 @@
|
||||
// import { IBranchesActivatedPayload } from '@/interfaces';
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import events from '@/subscribers/events';
|
||||
// import { BillPaymentsActivateBranches } from '../../Integrations/Purchases/PaymentMadeBranchesActivate';
|
||||
import { BillPaymentsActivateBranches } from '../../Integrations/Purchases/PaymentMadeBranchesActivate';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { events } from '@/common/events/events';
|
||||
import { IBranchesActivatedPayload } from '../../Branches.types';
|
||||
|
||||
// @Service()
|
||||
// export class PaymentMadeActivateBranchesSubscriber {
|
||||
// @Inject()
|
||||
// private paymentsActivateBranches: BillPaymentsActivateBranches;
|
||||
@Injectable()
|
||||
export class PaymentMadeActivateBranchesSubscriber {
|
||||
constructor(
|
||||
private readonly paymentsActivateBranches: BillPaymentsActivateBranches,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// public attach(bus) {
|
||||
// bus.subscribe(
|
||||
// events.branch.onActivated,
|
||||
// this.updatePaymentsWithBranchOnActivated
|
||||
// );
|
||||
// return bus;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Updates accounts transactions with the primary branch once
|
||||
// * the multi-branches is activated.
|
||||
// * @param {IBranchesActivatedPayload}
|
||||
// */
|
||||
// private updatePaymentsWithBranchOnActivated = async ({
|
||||
// tenantId,
|
||||
// primaryBranch,
|
||||
// trx,
|
||||
// }: IBranchesActivatedPayload) => {
|
||||
// await this.paymentsActivateBranches.updateBillPaymentsWithBranch(
|
||||
// tenantId,
|
||||
// primaryBranch.id,
|
||||
// trx
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Updates accounts transactions with the primary branch once
|
||||
* the multi-branches is activated.
|
||||
* @param {IBranchesActivatedPayload}
|
||||
*/
|
||||
@OnEvent(events.branch.onActivated)
|
||||
async updatePaymentsWithBranchOnActivated({
|
||||
primaryBranch,
|
||||
trx,
|
||||
}: IBranchesActivatedPayload) {
|
||||
await this.paymentsActivateBranches.updateBillPaymentsWithBranch(
|
||||
primaryBranch.id,
|
||||
trx,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,38 +1,28 @@
|
||||
// import { IBranchesActivatedPayload } from '@/interfaces';
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import events from '@/subscribers/events';
|
||||
// import { PaymentReceiveActivateBranches } from '../../Integrations/Sales/PaymentReceiveBranchesActivate';
|
||||
import { events } from '@/common/events/events';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { IBranchesActivatedPayload } from '../../Branches.types';
|
||||
import { PaymentReceiveActivateBranches } from '../../integrations/Sales/PaymentReceiveBranchesActivate';
|
||||
|
||||
// @Service()
|
||||
// export class PaymentReceiveActivateBranchesSubscriber {
|
||||
// @Inject()
|
||||
// private paymentsActivateBranches: PaymentReceiveActivateBranches;
|
||||
@Injectable()
|
||||
export class PaymentReceiveActivateBranchesSubscriber {
|
||||
constructor(
|
||||
private readonly paymentsActivateBranches: PaymentReceiveActivateBranches,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// public attach(bus) {
|
||||
// bus.subscribe(
|
||||
// events.branch.onActivated,
|
||||
// this.updateCreditNoteWithBranchOnActivated
|
||||
// );
|
||||
// return bus;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Updates accounts transactions with the primary branch once
|
||||
// * the multi-branches is activated.
|
||||
// * @param {IBranchesActivatedPayload}
|
||||
// */
|
||||
// private updateCreditNoteWithBranchOnActivated = async ({
|
||||
// tenantId,
|
||||
// primaryBranch,
|
||||
// trx,
|
||||
// }: IBranchesActivatedPayload) => {
|
||||
// await this.paymentsActivateBranches.updatePaymentsWithBranch(
|
||||
// tenantId,
|
||||
// primaryBranch.id,
|
||||
// trx
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Updates accounts transactions with the primary branch once
|
||||
* the multi-branches is activated.
|
||||
* @param {IBranchesActivatedPayload}
|
||||
*/
|
||||
@OnEvent(events.branch.onActivated)
|
||||
async updateCreditNoteWithBranchOnActivated({
|
||||
primaryBranch,
|
||||
trx,
|
||||
}: IBranchesActivatedPayload) {
|
||||
await this.paymentsActivateBranches.updatePaymentsWithBranch(
|
||||
primaryBranch.id,
|
||||
trx
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,38 +1,28 @@
|
||||
// import { IBranchesActivatedPayload } from '@/interfaces';
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import events from '@/subscribers/events';
|
||||
// import { SaleEstimateActivateBranches } from '../../Integrations/Sales/SaleEstimatesBranchesActivate';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { IBranchesActivatedPayload } from '../../Branches.types';
|
||||
import { events } from '@/common/events/events';
|
||||
import { SaleEstimateActivateBranches } from '../../integrations/Sales/SaleEstimatesBranchesActivate';
|
||||
|
||||
// @Service()
|
||||
// export class SaleEstimatesActivateBranchesSubscriber {
|
||||
// @Inject()
|
||||
// private estimatesActivateBranches: SaleEstimateActivateBranches;
|
||||
@Injectable()
|
||||
export class SaleEstimatesActivateBranchesSubscriber {
|
||||
constructor(
|
||||
private readonly estimatesActivateBranches: SaleEstimateActivateBranches,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// public attach(bus) {
|
||||
// bus.subscribe(
|
||||
// events.branch.onActivated,
|
||||
// this.updateEstimatesWithBranchOnActivated
|
||||
// );
|
||||
// return bus;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Updates accounts transactions with the primary branch once
|
||||
// * the multi-branches is activated.
|
||||
// * @param {IBranchesActivatedPayload}
|
||||
// */
|
||||
// private updateEstimatesWithBranchOnActivated = async ({
|
||||
// tenantId,
|
||||
// primaryBranch,
|
||||
// trx,
|
||||
// }: IBranchesActivatedPayload) => {
|
||||
// await this.estimatesActivateBranches.updateEstimatesWithBranch(
|
||||
// tenantId,
|
||||
// primaryBranch.id,
|
||||
// trx
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Updates accounts transactions with the primary branch once
|
||||
* the multi-branches is activated.
|
||||
* @param {IBranchesActivatedPayload}
|
||||
*/
|
||||
@OnEvent(events.branch.onActivated)
|
||||
async updateEstimatesWithBranchOnActivated({
|
||||
primaryBranch,
|
||||
trx,
|
||||
}: IBranchesActivatedPayload) {
|
||||
await this.estimatesActivateBranches.updateEstimatesWithBranch(
|
||||
primaryBranch.id,
|
||||
trx
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,38 +1,28 @@
|
||||
// import { IBranchesActivatedPayload } from '@/interfaces';
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import events from '@/subscribers/events';
|
||||
// import { SaleInvoiceActivateBranches } from '../../Integrations/Sales/SaleInvoiceBranchesActivate';
|
||||
import { events } from '@/common/events/events';
|
||||
import { SaleInvoiceActivateBranches } from '../../Integrations/Sales/SaleInvoiceBranchesActivate';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { IBranchesActivatedPayload } from '../../Branches.types';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
// @Service()
|
||||
// export class SaleInvoicesActivateBranchesSubscriber {
|
||||
// @Inject()
|
||||
// private invoicesActivateBranches: SaleInvoiceActivateBranches;
|
||||
@Injectable()
|
||||
export class SaleInvoicesActivateBranchesSubscriber {
|
||||
constructor(
|
||||
private readonly invoicesActivateBranches: SaleInvoiceActivateBranches,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// public attach(bus) {
|
||||
// bus.subscribe(
|
||||
// events.branch.onActivated,
|
||||
// this.updateInvoicesWithBranchOnActivated
|
||||
// );
|
||||
// return bus;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Updates accounts transactions with the primary branch once
|
||||
// * the multi-branches is activated.
|
||||
// * @param {IBranchesActivatedPayload}
|
||||
// */
|
||||
// private updateInvoicesWithBranchOnActivated = async ({
|
||||
// tenantId,
|
||||
// primaryBranch,
|
||||
// trx,
|
||||
// }: IBranchesActivatedPayload) => {
|
||||
// await this.invoicesActivateBranches.updateInvoicesWithBranch(
|
||||
// tenantId,
|
||||
// primaryBranch.id,
|
||||
// trx
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Updates accounts transactions with the primary branch once
|
||||
* the multi-branches is activated.
|
||||
* @param {IBranchesActivatedPayload}
|
||||
*/
|
||||
@OnEvent(events.branch.onActivated)
|
||||
async updateInvoicesWithBranchOnActivated({
|
||||
primaryBranch,
|
||||
trx,
|
||||
}: IBranchesActivatedPayload) {
|
||||
await this.invoicesActivateBranches.updateInvoicesWithBranch(
|
||||
primaryBranch.id,
|
||||
trx
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,38 +1,28 @@
|
||||
// import { IBranchesActivatedPayload } from '@/interfaces';
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import events from '@/subscribers/events';
|
||||
// import { SaleReceiptActivateBranches } from '../../Integrations/Sales/SaleReceiptBranchesActivate';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { events } from '@/common/events/events';
|
||||
import { IBranchesActivatedPayload } from '../../Branches.types';
|
||||
import { SaleReceiptActivateBranches } from '../../integrations/Sales/SaleReceiptBranchesActivate';
|
||||
|
||||
// @Service()
|
||||
// export class SaleReceiptsActivateBranchesSubscriber {
|
||||
// @Inject()
|
||||
// private receiptsActivateBranches: SaleReceiptActivateBranches;
|
||||
@Injectable()
|
||||
export class SaleReceiptsActivateBranchesSubscriber {
|
||||
constructor(
|
||||
private readonly receiptsActivateBranches: SaleReceiptActivateBranches,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// public attach(bus) {
|
||||
// bus.subscribe(
|
||||
// events.branch.onActivated,
|
||||
// this.updateReceiptsWithBranchOnActivated
|
||||
// );
|
||||
// return bus;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Updates accounts transactions with the primary branch once
|
||||
// * the multi-branches is activated.
|
||||
// * @param {IBranchesActivatedPayload}
|
||||
// */
|
||||
// private updateReceiptsWithBranchOnActivated = async ({
|
||||
// tenantId,
|
||||
// primaryBranch,
|
||||
// trx,
|
||||
// }: IBranchesActivatedPayload) => {
|
||||
// await this.receiptsActivateBranches.updateReceiptsWithBranch(
|
||||
// tenantId,
|
||||
// primaryBranch.id,
|
||||
// trx
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Updates accounts transactions with the primary branch once
|
||||
* the multi-branches is activated.
|
||||
* @param {IBranchesActivatedPayload}
|
||||
*/
|
||||
@OnEvent(events.branch.onActivated)
|
||||
async updateReceiptsWithBranchOnActivated({
|
||||
primaryBranch,
|
||||
trx,
|
||||
}: IBranchesActivatedPayload) {
|
||||
await this.receiptsActivateBranches.updateReceiptsWithBranch(
|
||||
primaryBranch.id,
|
||||
trx,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
// export * from './CashflowBranchesActivateSubscriber';
|
||||
// export * from './CreditNoteBranchesActivateSubscriber';
|
||||
// export * from './PaymentMadeBranchesActivateSubscriber';
|
||||
// export * from './PaymentReceiveBranchesActivateSubscriber';
|
||||
// export * from './SaleReceiptsBranchesActivateSubscriber';
|
||||
// export * from './SaleEstiamtesBranchesActivateSubscriber';
|
||||
// export * from './SaleInvoiceBranchesActivateSubscriber';
|
||||
// export * from './ExpenseBranchesActivateSubscriber';
|
||||
@@ -1,53 +1,39 @@
|
||||
// import { Inject, Service } from 'typedi';
|
||||
// import events from '@/subscribers/events';
|
||||
// import { IBillCreatingPayload, IBillEditingPayload } from '@/interfaces';
|
||||
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { events } from '@/common/events/events';
|
||||
import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||
import {
|
||||
IBillCreatingPayload,
|
||||
IBillEditingPayload,
|
||||
} from '@/modules/Bills/Bills.types';
|
||||
|
||||
// @Service()
|
||||
// export class BillBranchValidateSubscriber {
|
||||
// @Inject()
|
||||
// private validateBranchExistance: ValidateBranchExistance;
|
||||
@Injectable()
|
||||
export class BillBranchValidateSubscriber {
|
||||
constructor(
|
||||
private readonly validateBranchExistance: ValidateBranchExistance,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// public attach = (bus) => {
|
||||
// bus.subscribe(
|
||||
// events.bill.onCreating,
|
||||
// this.validateBranchExistanceOnBillCreating
|
||||
// );
|
||||
// bus.subscribe(
|
||||
// events.bill.onEditing,
|
||||
// this.validateBranchExistanceOnBillEditing
|
||||
// );
|
||||
// return bus;
|
||||
// };
|
||||
/**
|
||||
* Validate branch existance on bill creating.
|
||||
* @param {IBillCreatingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.bill.onCreating)
|
||||
async validateBranchExistanceOnBillCreating({
|
||||
billDTO,
|
||||
}: IBillCreatingPayload) {
|
||||
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
billDTO.branchId,
|
||||
);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Validate branch existance on estimate creating.
|
||||
// * @param {ISaleEstimateCreatedPayload} payload
|
||||
// */
|
||||
// private validateBranchExistanceOnBillCreating = async ({
|
||||
// tenantId,
|
||||
// billDTO,
|
||||
// }: IBillCreatingPayload) => {
|
||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
// tenantId,
|
||||
// billDTO.branchId
|
||||
// );
|
||||
// };
|
||||
|
||||
// /**
|
||||
// * Validate branch existance once estimate editing.
|
||||
// * @param {ISaleEstimateEditingPayload} payload
|
||||
// */
|
||||
// private validateBranchExistanceOnBillEditing = async ({
|
||||
// billDTO,
|
||||
// tenantId,
|
||||
// }: IBillEditingPayload) => {
|
||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
// tenantId,
|
||||
// billDTO.branchId
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Validate branch existance once bill editing.
|
||||
* @param {IBillEditingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.bill.onEditing)
|
||||
async validateBranchExistanceOnBillEditing({ billDTO }: IBillEditingPayload) {
|
||||
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
billDTO.branchId,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +1,25 @@
|
||||
// import { Inject, Service } from 'typedi';
|
||||
// import events from '@/subscribers/events';
|
||||
// import { ICommandCashflowCreatingPayload } from '@/interfaces';
|
||||
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { events } from '@/common/events/events';
|
||||
import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||
import { ICommandCashflowCreatingPayload } from '@/modules/BankingTransactions/types/BankingTransactions.types';
|
||||
|
||||
// @Service()
|
||||
// export class CashflowBranchDTOValidatorSubscriber {
|
||||
// @Inject()
|
||||
// private validateBranchExistance: ValidateBranchExistance;
|
||||
@Injectable()
|
||||
export class CashflowBranchDTOValidatorSubscriber {
|
||||
constructor(
|
||||
private readonly validateBranchExistance: ValidateBranchExistance,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// public attach = (bus) => {
|
||||
// bus.subscribe(
|
||||
// events.cashflow.onTransactionCreating,
|
||||
// this.validateBranchExistanceOnCashflowTransactionCreating
|
||||
// );
|
||||
// return bus;
|
||||
// };
|
||||
|
||||
// /**
|
||||
// * Validate branch existance once cashflow transaction creating.
|
||||
// * @param {ICommandCashflowCreatingPayload} payload
|
||||
// */
|
||||
// private validateBranchExistanceOnCashflowTransactionCreating = async ({
|
||||
// tenantId,
|
||||
// newTransactionDTO,
|
||||
// }: ICommandCashflowCreatingPayload) => {
|
||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
// tenantId,
|
||||
// newTransactionDTO.branchId
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Validate branch existance once cashflow transaction creating.
|
||||
* @param {ICommandCashflowCreatingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.cashflow.onTransactionCreating)
|
||||
async validateBranchExistanceOnCashflowTransactionCreating({
|
||||
newTransactionDTO,
|
||||
}: ICommandCashflowCreatingPayload) {
|
||||
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
newTransactionDTO.branchId,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,104 +1,81 @@
|
||||
// import { Inject, Service } from 'typedi';
|
||||
// import events from '@/subscribers/events';
|
||||
// import {
|
||||
// ICustomerEventCreatingPayload,
|
||||
// ICustomerOpeningBalanceEditingPayload,
|
||||
// IVendorEventCreatingPayload,
|
||||
// IVendorOpeningBalanceEditingPayload,
|
||||
// } from '@/interfaces';
|
||||
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { events } from '@/common/events/events';
|
||||
import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||
import {
|
||||
ICustomerOpeningBalanceEditingPayload,
|
||||
ICustomerEventCreatingPayload,
|
||||
} from '@/modules/Customers/types/Customers.types';
|
||||
import {
|
||||
IVendorEventCreatingPayload,
|
||||
IVendorOpeningBalanceEditingPayload,
|
||||
} from '@/modules/Vendors/types/Vendors.types';
|
||||
|
||||
// @Service()
|
||||
// export class ContactBranchValidateSubscriber {
|
||||
// @Inject()
|
||||
// private validateBranchExistance: ValidateBranchExistance;
|
||||
@Injectable()
|
||||
export class ContactBranchValidateSubscriber {
|
||||
constructor(
|
||||
private readonly validateBranchExistance: ValidateBranchExistance,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// public attach = (bus) => {
|
||||
// bus.subscribe(
|
||||
// events.customers.onCreating,
|
||||
// this.validateBranchExistanceOnCustomerCreating
|
||||
// );
|
||||
// bus.subscribe(
|
||||
// events.customers.onOpeningBalanceChanging,
|
||||
// this.validateBranchExistanceOnCustomerOpeningBalanceEditing
|
||||
// );
|
||||
// bus.subscribe(
|
||||
// events.vendors.onCreating,
|
||||
// this.validateBranchExistanceonVendorCreating
|
||||
// );
|
||||
// bus.subscribe(
|
||||
// events.vendors.onOpeningBalanceChanging,
|
||||
// this.validateBranchExistanceOnVendorOpeningBalanceEditing
|
||||
// );
|
||||
// return bus;
|
||||
// };
|
||||
/**
|
||||
* Validate branch existance on customer creating.
|
||||
* @param {ICustomerEventCreatingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.customers.onCreating)
|
||||
async validateBranchExistanceOnCustomerCreating({
|
||||
customerDTO,
|
||||
}: ICustomerEventCreatingPayload) {
|
||||
// Can't continue if the customer opening balance is zero.
|
||||
if (!customerDTO.openingBalance) return;
|
||||
|
||||
// /**
|
||||
// * Validate branch existance on customer creating.
|
||||
// * @param {ICustomerEventCreatingPayload} payload
|
||||
// */
|
||||
// private validateBranchExistanceOnCustomerCreating = async ({
|
||||
// tenantId,
|
||||
// customerDTO,
|
||||
// }: ICustomerEventCreatingPayload) => {
|
||||
// // Can't continue if the customer opening balance is zero.
|
||||
// if (!customerDTO.openingBalance) return;
|
||||
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
customerDTO.openingBalanceBranchId,
|
||||
);
|
||||
}
|
||||
|
||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
// tenantId,
|
||||
// customerDTO.openingBalanceBranchId
|
||||
// );
|
||||
// };
|
||||
/**
|
||||
* Validate branch existance once customer opening balance editing.
|
||||
* @param {ICustomerOpeningBalanceEditingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.customers.onOpeningBalanceChanging)
|
||||
async validateBranchExistanceOnCustomerOpeningBalanceEditing({
|
||||
openingBalanceEditDTO,
|
||||
}: ICustomerOpeningBalanceEditingPayload) {
|
||||
if (!openingBalanceEditDTO.openingBalance) return;
|
||||
|
||||
// /**
|
||||
// * Validate branch existance once customer opening balance editing.
|
||||
// * @param {ICustomerOpeningBalanceEditingPayload} payload
|
||||
// */
|
||||
// private validateBranchExistanceOnCustomerOpeningBalanceEditing = async ({
|
||||
// openingBalanceEditDTO,
|
||||
// tenantId,
|
||||
// }: ICustomerOpeningBalanceEditingPayload) => {
|
||||
// if (!openingBalanceEditDTO.openingBalance) return;
|
||||
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
openingBalanceEditDTO.openingBalanceBranchId,
|
||||
);
|
||||
}
|
||||
|
||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
// tenantId,
|
||||
// openingBalanceEditDTO.openingBalanceBranchId
|
||||
// );
|
||||
// };
|
||||
/**
|
||||
* Validates the branch existance on vendor creating.
|
||||
* @param {IVendorEventCreatingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.vendors.onCreating)
|
||||
async validateBranchExistanceonVendorCreating({
|
||||
vendorDTO,
|
||||
}: IVendorEventCreatingPayload) {
|
||||
// Can't continue if the customer opening balance is zero.
|
||||
if (!vendorDTO.openingBalance) return;
|
||||
|
||||
// /**
|
||||
// * Validates the branch existance on vendor creating.
|
||||
// * @param {IVendorEventCreatingPayload} payload -
|
||||
// */
|
||||
// private validateBranchExistanceonVendorCreating = async ({
|
||||
// vendorDTO,
|
||||
// tenantId,
|
||||
// }: IVendorEventCreatingPayload) => {
|
||||
// // Can't continue if the customer opening balance is zero.
|
||||
// if (!vendorDTO.openingBalance) return;
|
||||
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
vendorDTO.openingBalanceBranchId,
|
||||
);
|
||||
}
|
||||
|
||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
// tenantId,
|
||||
// vendorDTO.openingBalanceBranchId
|
||||
// );
|
||||
// };
|
||||
/**
|
||||
* Validate branch existance once the vendor opening balance editing.
|
||||
* @param {IVendorOpeningBalanceEditingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.vendors.onOpeningBalanceChanging)
|
||||
async validateBranchExistanceOnVendorOpeningBalanceEditing({
|
||||
openingBalanceEditDTO,
|
||||
}: IVendorOpeningBalanceEditingPayload) {
|
||||
if (!openingBalanceEditDTO.openingBalance) return;
|
||||
|
||||
// /**
|
||||
// * Validate branch existance once the vendor opening balance editing.
|
||||
// * @param {IVendorOpeningBalanceEditingPayload}
|
||||
// */
|
||||
// private validateBranchExistanceOnVendorOpeningBalanceEditing = async ({
|
||||
// tenantId,
|
||||
// openingBalanceEditDTO,
|
||||
// }: IVendorOpeningBalanceEditingPayload) => {
|
||||
// if (!openingBalanceEditDTO.openingBalance) return;
|
||||
|
||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
// tenantId,
|
||||
// openingBalanceEditDTO.openingBalanceBranchId
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
openingBalanceEditDTO.openingBalanceBranchId,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,56 +1,39 @@
|
||||
// import { Inject, Service } from 'typedi';
|
||||
// import events from '@/subscribers/events';
|
||||
// import {
|
||||
// ICreditNoteCreatingPayload,
|
||||
// ICreditNoteEditingPayload,
|
||||
// } from '@/interfaces';
|
||||
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { events } from '@/common/events/events';
|
||||
import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||
import { ICreditNoteEditingPayload } from '@/modules/CreditNotes/types/CreditNotes.types';
|
||||
import { ICreditNoteCreatingPayload } from '@/modules/CreditNotes/types/CreditNotes.types';
|
||||
|
||||
// @Service()
|
||||
// export class CreditNoteBranchValidateSubscriber {
|
||||
// @Inject()
|
||||
// private validateBranchExistance: ValidateBranchExistance;
|
||||
@Injectable()
|
||||
export class CreditNoteBranchValidateSubscriber {
|
||||
constructor(
|
||||
private readonly validateBranchExistance: ValidateBranchExistance,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// public attach = (bus) => {
|
||||
// bus.subscribe(
|
||||
// events.creditNote.onCreating,
|
||||
// this.validateBranchExistanceOnCreditCreating
|
||||
// );
|
||||
// bus.subscribe(
|
||||
// events.creditNote.onEditing,
|
||||
// this.validateBranchExistanceOnCreditEditing
|
||||
// );
|
||||
// return bus;
|
||||
// };
|
||||
/**
|
||||
* Validate branch existance on credit note creating.
|
||||
* @param {ICreditNoteCreatingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.creditNote.onCreating)
|
||||
async validateBranchExistanceOnCreditCreating({
|
||||
creditNoteDTO,
|
||||
}: ICreditNoteCreatingPayload) {
|
||||
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
creditNoteDTO.branchId,
|
||||
);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Validate branch existance on estimate creating.
|
||||
// * @param {ICreditNoteCreatingPayload} payload
|
||||
// */
|
||||
// private validateBranchExistanceOnCreditCreating = async ({
|
||||
// tenantId,
|
||||
// creditNoteDTO,
|
||||
// }: ICreditNoteCreatingPayload) => {
|
||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
// tenantId,
|
||||
// creditNoteDTO.branchId
|
||||
// );
|
||||
// };
|
||||
|
||||
// /**
|
||||
// * Validate branch existance once estimate editing.
|
||||
// * @param {ISaleEstimateEditingPayload} payload
|
||||
// */
|
||||
// private validateBranchExistanceOnCreditEditing = async ({
|
||||
// creditNoteEditDTO,
|
||||
// tenantId,
|
||||
// }: ICreditNoteEditingPayload) => {
|
||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
// tenantId,
|
||||
// creditNoteEditDTO.branchId
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Validate branch existance once credit note editing.
|
||||
* @param {ICreditNoteEditingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.creditNote.onEditing)
|
||||
async validateBranchExistanceOnCreditEditing({
|
||||
creditNoteEditDTO,
|
||||
}: ICreditNoteEditingPayload) {
|
||||
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
creditNoteEditDTO.branchId,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +1,25 @@
|
||||
// import { Inject, Service } from 'typedi';
|
||||
// import events from '@/subscribers/events';
|
||||
// import { IRefundCreditNoteCreatingPayload } from '@/interfaces';
|
||||
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||
import { events } from '@/common/events/events';
|
||||
import { IRefundCreditNoteCreatingPayload } from '@/modules/CreditNoteRefunds/types/CreditNoteRefunds.types';
|
||||
|
||||
// @Service()
|
||||
// export class CreditNoteRefundBranchValidateSubscriber {
|
||||
// @Inject()
|
||||
// private validateBranchExistance: ValidateBranchExistance;
|
||||
@Injectable()
|
||||
export class CreditNoteRefundBranchValidateSubscriber {
|
||||
constructor(
|
||||
private readonly validateBranchExistance: ValidateBranchExistance
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// public attach = (bus) => {
|
||||
// bus.subscribe(
|
||||
// events.creditNote.onRefundCreating,
|
||||
// this.validateBranchExistanceOnCreditRefundCreating
|
||||
// );
|
||||
// return bus;
|
||||
// };
|
||||
|
||||
// /**
|
||||
// * Validate branch existance on refund credit note creating.
|
||||
// * @param {ICreditNoteCreatingPayload} payload
|
||||
// */
|
||||
// private validateBranchExistanceOnCreditRefundCreating = async ({
|
||||
// tenantId,
|
||||
// newCreditNoteDTO,
|
||||
// }: IRefundCreditNoteCreatingPayload) => {
|
||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
// tenantId,
|
||||
// newCreditNoteDTO.branchId
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Validate branch existance on refund credit note creating.
|
||||
* @param {IRefundCreditNoteCreatingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.creditNote.onRefundCreating)
|
||||
async validateBranchExistanceOnCreditRefundCreating({
|
||||
newCreditNoteDTO,
|
||||
}: IRefundCreditNoteCreatingPayload) {
|
||||
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
newCreditNoteDTO.branchId
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,56 +1,40 @@
|
||||
// import { Inject, Service } from 'typedi';
|
||||
// import events from '@/subscribers/events';
|
||||
// import {
|
||||
// IExpenseCreatingPayload,
|
||||
// IExpenseEventEditingPayload,
|
||||
// } from '@/interfaces';
|
||||
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { events } from '@/common/events/events';
|
||||
import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||
import {
|
||||
IExpenseCreatingPayload,
|
||||
IExpenseEventEditingPayload,
|
||||
} from '@/modules/Expenses/Expenses.types';
|
||||
@Injectable()
|
||||
export class ExpenseBranchValidateSubscriber {
|
||||
constructor(
|
||||
private readonly validateBranchExistance: ValidateBranchExistance,
|
||||
) {}
|
||||
|
||||
// @Service()
|
||||
// export class ExpenseBranchValidateSubscriber {
|
||||
// @Inject()
|
||||
// private validateBranchExistance: ValidateBranchExistance;
|
||||
/**
|
||||
* Validate branch existance once expense transaction creating.
|
||||
* @param {IExpenseCreatingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.expenses.onCreating)
|
||||
async validateBranchExistanceOnExpenseCreating({
|
||||
expenseDTO,
|
||||
}: IExpenseCreatingPayload) {
|
||||
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
expenseDTO.branchId,
|
||||
);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// public attach = (bus) => {
|
||||
// bus.subscribe(
|
||||
// events.expenses.onCreating,
|
||||
// this.validateBranchExistanceOnExpenseCreating
|
||||
// );
|
||||
// bus.subscribe(
|
||||
// events.expenses.onEditing,
|
||||
// this.validateBranchExistanceOnExpenseEditing
|
||||
// );
|
||||
// return bus;
|
||||
// };
|
||||
|
||||
// /**
|
||||
// * Validate branch existance once expense transaction creating.
|
||||
// * @param {ISaleEstimateCreatedPayload} payload
|
||||
// */
|
||||
// private validateBranchExistanceOnExpenseCreating = async ({
|
||||
// tenantId,
|
||||
// expenseDTO,
|
||||
// }: IExpenseCreatingPayload) => {
|
||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
// tenantId,
|
||||
// expenseDTO.branchId
|
||||
// );
|
||||
// };
|
||||
|
||||
// /**
|
||||
// * Validate branch existance once expense transaction editing.
|
||||
// * @param {ISaleEstimateEditingPayload} payload
|
||||
// */
|
||||
// private validateBranchExistanceOnExpenseEditing = async ({
|
||||
// expenseDTO,
|
||||
// tenantId,
|
||||
// }: IExpenseEventEditingPayload) => {
|
||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
// tenantId,
|
||||
// expenseDTO.branchId
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Validate branch existance once expense transaction editing.
|
||||
* @param {IExpenseEventEditingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.expenses.onEditing)
|
||||
async validateBranchExistanceOnExpenseEditing({
|
||||
expenseDTO,
|
||||
}: IExpenseEventEditingPayload) {
|
||||
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
expenseDTO.branchId,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +1,25 @@
|
||||
// import { Inject, Service } from 'typedi';
|
||||
// import events from '@/subscribers/events';
|
||||
// import { IInventoryAdjustmentCreatingPayload } from '@/interfaces';
|
||||
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { events } from '@/common/events/events';
|
||||
import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||
import { IInventoryAdjustmentCreatingPayload } from '@/modules/InventoryAdjutments/types/InventoryAdjustments.types';
|
||||
|
||||
// @Service()
|
||||
// export class InventoryAdjustmentBranchValidateSubscriber {
|
||||
// @Inject()
|
||||
// private validateBranchExistance: ValidateBranchExistance;
|
||||
@Injectable()
|
||||
export class InventoryAdjustmentBranchValidateSubscriber {
|
||||
constructor(
|
||||
private readonly validateBranchExistance: ValidateBranchExistance,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// public attach = (bus) => {
|
||||
// bus.subscribe(
|
||||
// events.inventoryAdjustment.onQuickCreating,
|
||||
// this.validateBranchExistanceOnInventoryCreating
|
||||
// );
|
||||
// return bus;
|
||||
// };
|
||||
|
||||
// /**
|
||||
// * Validate branch existance on invoice creating.
|
||||
// * @param {ISaleInvoiceCreatingPaylaod} payload
|
||||
// */
|
||||
// private validateBranchExistanceOnInventoryCreating = async ({
|
||||
// tenantId,
|
||||
// quickAdjustmentDTO,
|
||||
// }: IInventoryAdjustmentCreatingPayload) => {
|
||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
// tenantId,
|
||||
// quickAdjustmentDTO.branchId
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Validate branch existance on inventory adjustment creating.
|
||||
* @param {IInventoryAdjustmentCreatingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.inventoryAdjustment.onQuickCreating)
|
||||
async validateBranchExistanceOnInventoryCreating({
|
||||
quickAdjustmentDTO,
|
||||
}: IInventoryAdjustmentCreatingPayload) {
|
||||
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
quickAdjustmentDTO.branchId,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,56 +1,41 @@
|
||||
// import { Inject, Service } from 'typedi';
|
||||
// import events from '@/subscribers/events';
|
||||
// import {
|
||||
// ISaleInvoiceCreatingPaylaod,
|
||||
// ISaleInvoiceEditingPayload,
|
||||
// } from '@/interfaces';
|
||||
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { events } from '@/common/events/events';
|
||||
import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||
import {
|
||||
ISaleInvoiceCreatingPaylaod,
|
||||
ISaleInvoiceEditingPayload,
|
||||
} from '@/modules/SaleInvoices/SaleInvoice.types';
|
||||
|
||||
// @Service()
|
||||
// export class InvoiceBranchValidateSubscriber {
|
||||
// @Inject()
|
||||
// private validateBranchExistance: ValidateBranchExistance;
|
||||
@Injectable()
|
||||
export class InvoiceBranchValidateSubscriber {
|
||||
constructor(
|
||||
private readonly validateBranchExistance: ValidateBranchExistance,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// public attach = (bus) => {
|
||||
// bus.subscribe(
|
||||
// events.saleInvoice.onCreating,
|
||||
// this.validateBranchExistanceOnInvoiceCreating
|
||||
// );
|
||||
// bus.subscribe(
|
||||
// events.saleInvoice.onEditing,
|
||||
// this.validateBranchExistanceOnInvoiceEditing
|
||||
// );
|
||||
// return bus;
|
||||
// };
|
||||
/**
|
||||
* Validate branch existance on invoice creating.
|
||||
* @param {ISaleInvoiceCreatingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.saleInvoice.onCreating)
|
||||
async validateBranchExistanceOnInvoiceCreating({
|
||||
saleInvoiceDTO,
|
||||
}: ISaleInvoiceCreatingPaylaod) {
|
||||
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
saleInvoiceDTO.branchId,
|
||||
);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Validate branch existance on invoice creating.
|
||||
// * @param {ISaleInvoiceCreatingPaylaod} payload
|
||||
// */
|
||||
// private validateBranchExistanceOnInvoiceCreating = async ({
|
||||
// tenantId,
|
||||
// saleInvoiceDTO,
|
||||
// }: ISaleInvoiceCreatingPaylaod) => {
|
||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
// tenantId,
|
||||
// saleInvoiceDTO.branchId
|
||||
// );
|
||||
// };
|
||||
|
||||
// /**
|
||||
// * Validate branch existance once invoice editing.
|
||||
// * @param {ISaleInvoiceEditingPayload} payload
|
||||
// */
|
||||
// private validateBranchExistanceOnInvoiceEditing = async ({
|
||||
// saleInvoiceDTO,
|
||||
// tenantId,
|
||||
// }: ISaleInvoiceEditingPayload) => {
|
||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
// tenantId,
|
||||
// saleInvoiceDTO.branchId
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Validate branch existance once invoice editing.
|
||||
* @param {ISaleInvoiceEditingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.saleInvoice.onEditing)
|
||||
async validateBranchExistanceOnInvoiceEditing({
|
||||
saleInvoiceDTO,
|
||||
}: ISaleInvoiceEditingPayload) {
|
||||
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
saleInvoiceDTO.branchId,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,76 +1,60 @@
|
||||
// import { Inject, Service } from 'typedi';
|
||||
// import events from '@/subscribers/events';
|
||||
// import {
|
||||
// Features,
|
||||
// IManualJournalCreatingPayload,
|
||||
// IManualJournalEditingPayload,
|
||||
// } from '@/interfaces';
|
||||
// import { ManualJournalBranchesValidator } from '../../Integrations/ManualJournals/ManualJournalsBranchesValidator';
|
||||
// import { FeaturesManager } from '@/services/Features/FeaturesManager';
|
||||
|
||||
// @Service()
|
||||
// export class ManualJournalBranchValidateSubscriber {
|
||||
// @Inject()
|
||||
// private validateManualJournalBranch: ManualJournalBranchesValidator;
|
||||
import {
|
||||
IManualJournalCreatingPayload,
|
||||
IManualJournalEditingPayload,
|
||||
} from '@/modules/ManualJournals/types/ManualJournals.types';
|
||||
import { ManualJournalBranchesValidator } from '../../Integrations/ManualJournals/ManualJournalsBranchesValidator';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { events } from '@/common/events/events';
|
||||
import { Features } from '@/common/types/Features';
|
||||
import { FeaturesManager } from '../../../Features/FeaturesManager';
|
||||
|
||||
// @Inject()
|
||||
// private featuresManager: FeaturesManager;
|
||||
@Injectable()
|
||||
export class ManualJournalBranchValidateSubscriber {
|
||||
constructor(
|
||||
private readonly validateManualJournalBranch: ManualJournalBranchesValidator,
|
||||
private readonly featuresManager: FeaturesManager,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// public attach = (bus) => {
|
||||
// bus.subscribe(
|
||||
// events.manualJournals.onCreating,
|
||||
// this.validateBranchExistanceOnBillCreating
|
||||
// );
|
||||
// bus.subscribe(
|
||||
// events.manualJournals.onEditing,
|
||||
// this.validateBranchExistanceOnBillEditing
|
||||
// );
|
||||
// return bus;
|
||||
// };
|
||||
/**
|
||||
* Validate branch existance on estimate creating.
|
||||
* @param {IManualJournalCreatingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.manualJournals.onCreating)
|
||||
async validateBranchExistanceOnBillCreating({
|
||||
manualJournalDTO,
|
||||
}: IManualJournalCreatingPayload) {
|
||||
// Detarmines whether the multi-branches is accessible by tenant.
|
||||
const isAccessible = await this.featuresManager.accessible(
|
||||
Features.BRANCHES
|
||||
);
|
||||
// Can't continue if the multi-branches feature is inactive.
|
||||
if (!isAccessible) return;
|
||||
|
||||
// /**
|
||||
// * Validate branch existance on estimate creating.
|
||||
// * @param {IManualJournalCreatingPayload} payload
|
||||
// */
|
||||
// private validateBranchExistanceOnBillCreating = async ({
|
||||
// manualJournalDTO,
|
||||
// tenantId,
|
||||
// }: IManualJournalCreatingPayload) => {
|
||||
// // Detarmines whether the multi-branches is accessible by tenant.
|
||||
// const isAccessible = await this.featuresManager.accessible(
|
||||
// tenantId,
|
||||
// Features.BRANCHES
|
||||
// );
|
||||
// // Can't continue if the multi-branches feature is inactive.
|
||||
// if (!isAccessible) return;
|
||||
// Validates the entries whether have branch id.
|
||||
await this.validateManualJournalBranch.validateEntriesHasBranchId(
|
||||
manualJournalDTO
|
||||
);
|
||||
};
|
||||
|
||||
// // Validates the entries whether have branch id.
|
||||
// await this.validateManualJournalBranch.validateEntriesHasBranchId(
|
||||
// manualJournalDTO
|
||||
// );
|
||||
// };
|
||||
/**
|
||||
* Validate branch existance once estimate editing.
|
||||
* @param {ISaleEstimateEditingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.manualJournals.onEditing)
|
||||
async validateBranchExistanceOnBillEditing({
|
||||
manualJournalDTO,
|
||||
}: IManualJournalEditingPayload) {
|
||||
// Detarmines whether the multi-branches is accessible by tenant.
|
||||
const isAccessible = await this.featuresManager.accessible(
|
||||
Features.BRANCHES
|
||||
);
|
||||
// Can't continue if the multi-branches feature is inactive.
|
||||
if (!isAccessible) return;
|
||||
|
||||
// /**
|
||||
// * Validate branch existance once estimate editing.
|
||||
// * @param {ISaleEstimateEditingPayload} payload
|
||||
// */
|
||||
// private validateBranchExistanceOnBillEditing = async ({
|
||||
// tenantId,
|
||||
// manualJournalDTO,
|
||||
// }: IManualJournalEditingPayload) => {
|
||||
// // Detarmines whether the multi-branches is accessible by tenant.
|
||||
// const isAccessible = await this.featuresManager.accessible(
|
||||
// tenantId,
|
||||
// Features.BRANCHES
|
||||
// );
|
||||
// // Can't continue if the multi-branches feature is inactive.
|
||||
// if (!isAccessible) return;
|
||||
|
||||
// await this.validateManualJournalBranch.validateEntriesHasBranchId(
|
||||
// manualJournalDTO
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
await this.validateManualJournalBranch.validateEntriesHasBranchId(
|
||||
manualJournalDTO
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,56 +1,41 @@
|
||||
// import { Inject, Service } from 'typedi';
|
||||
// import events from '@/subscribers/events';
|
||||
// import {
|
||||
// IBillPaymentCreatingPayload,
|
||||
// IBillPaymentEditingPayload,
|
||||
// } from '@/interfaces';
|
||||
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import {
|
||||
IBillPaymentCreatingPayload,
|
||||
IBillPaymentEditingPayload,
|
||||
} from '@/modules/BillPayments/types/BillPayments.types';
|
||||
import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||
import { events } from '@/common/events/events';
|
||||
|
||||
// @Service()
|
||||
// export class PaymentMadeBranchValidateSubscriber {
|
||||
// @Inject()
|
||||
// private validateBranchExistance: ValidateBranchExistance;
|
||||
@Injectable()
|
||||
export class PaymentMadeBranchValidateSubscriber {
|
||||
constructor(
|
||||
private readonly validateBranchExistance: ValidateBranchExistance,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// public attach = (bus) => {
|
||||
// bus.subscribe(
|
||||
// events.billPayment.onCreating,
|
||||
// this.validateBranchExistanceOnPaymentCreating
|
||||
// );
|
||||
// bus.subscribe(
|
||||
// events.billPayment.onEditing,
|
||||
// this.validateBranchExistanceOnPaymentEditing
|
||||
// );
|
||||
// return bus;
|
||||
// };
|
||||
/**
|
||||
* Validate branch existance on estimate creating.
|
||||
* @param {ISaleEstimateCreatedPayload} payload
|
||||
*/
|
||||
@OnEvent(events.billPayment.onCreating)
|
||||
async validateBranchExistanceOnPaymentCreating({
|
||||
billPaymentDTO,
|
||||
}: IBillPaymentCreatingPayload) {
|
||||
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
billPaymentDTO.branchId,
|
||||
);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Validate branch existance on estimate creating.
|
||||
// * @param {ISaleEstimateCreatedPayload} payload
|
||||
// */
|
||||
// private validateBranchExistanceOnPaymentCreating = async ({
|
||||
// tenantId,
|
||||
// billPaymentDTO,
|
||||
// }: IBillPaymentCreatingPayload) => {
|
||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
// tenantId,
|
||||
// billPaymentDTO.branchId
|
||||
// );
|
||||
// };
|
||||
|
||||
// /**
|
||||
// * Validate branch existance once estimate editing.
|
||||
// * @param {ISaleEstimateEditingPayload} payload
|
||||
// */
|
||||
// private validateBranchExistanceOnPaymentEditing = async ({
|
||||
// billPaymentDTO,
|
||||
// tenantId,
|
||||
// }: IBillPaymentEditingPayload) => {
|
||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
// tenantId,
|
||||
// billPaymentDTO.branchId
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Validate branch existance once estimate editing.
|
||||
* @param {ISaleEstimateEditingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.billPayment.onEditing)
|
||||
async validateBranchExistanceOnPaymentEditing({
|
||||
billPaymentDTO,
|
||||
}: IBillPaymentEditingPayload) {
|
||||
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
billPaymentDTO.branchId,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,56 +1,41 @@
|
||||
// import { Inject, Service } from 'typedi';
|
||||
// import events from '@/subscribers/events';
|
||||
// import {
|
||||
// IPaymentReceivedCreatingPayload,
|
||||
// IPaymentReceivedEditingPayload,
|
||||
// } from '@/interfaces';
|
||||
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||
import {
|
||||
IPaymentReceivedCreatingPayload,
|
||||
IPaymentReceivedEditingPayload,
|
||||
} from '@/modules/PaymentReceived/types/PaymentReceived.types';
|
||||
import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { events } from '@/common/events/events';
|
||||
|
||||
// @Service()
|
||||
// export class PaymentReceiveBranchValidateSubscriber {
|
||||
// @Inject()
|
||||
// private validateBranchExistance: ValidateBranchExistance;
|
||||
@Injectable()
|
||||
export class PaymentReceiveBranchValidateSubscriber {
|
||||
constructor(
|
||||
private readonly validateBranchExistance: ValidateBranchExistance,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// public attach = (bus) => {
|
||||
// bus.subscribe(
|
||||
// events.paymentReceive.onCreating,
|
||||
// this.validateBranchExistanceOnPaymentCreating
|
||||
// );
|
||||
// bus.subscribe(
|
||||
// events.paymentReceive.onEditing,
|
||||
// this.validateBranchExistanceOnPaymentEditing
|
||||
// );
|
||||
// return bus;
|
||||
// };
|
||||
/**
|
||||
* Validate branch existance on estimate creating.
|
||||
* @param {IPaymentReceivedCreatingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.paymentReceive.onCreating)
|
||||
async validateBranchExistanceOnPaymentCreating({
|
||||
paymentReceiveDTO,
|
||||
}: IPaymentReceivedCreatingPayload) {
|
||||
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
paymentReceiveDTO.branchId,
|
||||
);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Validate branch existance on estimate creating.
|
||||
// * @param {IPaymentReceivedCreatingPayload} payload
|
||||
// */
|
||||
// private validateBranchExistanceOnPaymentCreating = async ({
|
||||
// tenantId,
|
||||
// paymentReceiveDTO,
|
||||
// }: IPaymentReceivedCreatingPayload) => {
|
||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
// tenantId,
|
||||
// paymentReceiveDTO.branchId
|
||||
// );
|
||||
// };
|
||||
|
||||
// /**
|
||||
// * Validate branch existance once estimate editing.
|
||||
// * @param {IPaymentReceivedEditingPayload} payload
|
||||
// */
|
||||
// private validateBranchExistanceOnPaymentEditing = async ({
|
||||
// paymentReceiveDTO,
|
||||
// tenantId,
|
||||
// }: IPaymentReceivedEditingPayload) => {
|
||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
// tenantId,
|
||||
// paymentReceiveDTO.branchId
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Validate branch existance once estimate editing.
|
||||
* @param {IPaymentReceivedEditingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.paymentReceive.onEditing)
|
||||
async validateBranchExistanceOnPaymentEditing({
|
||||
paymentReceiveDTO,
|
||||
}: IPaymentReceivedEditingPayload) {
|
||||
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
paymentReceiveDTO.branchId,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,56 +1,41 @@
|
||||
// import { Inject, Service } from 'typedi';
|
||||
// import events from '@/subscribers/events';
|
||||
// import {
|
||||
// ISaleEstimateCreatingPayload,
|
||||
// ISaleEstimateEditingPayload,
|
||||
// } from '@/interfaces';
|
||||
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { events } from '@/common/events/events';
|
||||
import {
|
||||
ISaleEstimateCreatingPayload,
|
||||
ISaleEstimateEditingPayload,
|
||||
} from '@/modules/SaleEstimates/types/SaleEstimates.types';
|
||||
import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||
|
||||
// @Service()
|
||||
// export class SaleEstimateBranchValidateSubscriber {
|
||||
// @Inject()
|
||||
// private validateBranchExistance: ValidateBranchExistance;
|
||||
@Injectable()
|
||||
export class SaleEstimateBranchValidateSubscriber {
|
||||
constructor(
|
||||
private readonly validateBranchExistance: ValidateBranchExistance,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// public attach = (bus) => {
|
||||
// bus.subscribe(
|
||||
// events.saleEstimate.onCreating,
|
||||
// this.validateBranchExistanceOnEstimateCreating
|
||||
// );
|
||||
// bus.subscribe(
|
||||
// events.saleEstimate.onEditing,
|
||||
// this.validateBranchExistanceOnEstimateEditing
|
||||
// );
|
||||
// return bus;
|
||||
// };
|
||||
/**
|
||||
* Validate branch existance on estimate creating.
|
||||
* @param {ISaleEstimateCreatedPayload} payload
|
||||
*/
|
||||
@OnEvent(events.saleEstimate.onCreating)
|
||||
async validateBranchExistanceOnEstimateCreating({
|
||||
estimateDTO,
|
||||
}: ISaleEstimateCreatingPayload) {
|
||||
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
estimateDTO.branchId,
|
||||
);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Validate branch existance on estimate creating.
|
||||
// * @param {ISaleEstimateCreatedPayload} payload
|
||||
// */
|
||||
// private validateBranchExistanceOnEstimateCreating = async ({
|
||||
// tenantId,
|
||||
// estimateDTO,
|
||||
// }: ISaleEstimateCreatingPayload) => {
|
||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
// tenantId,
|
||||
// estimateDTO.branchId
|
||||
// );
|
||||
// };
|
||||
|
||||
// /**
|
||||
// * Validate branch existance once estimate editing.
|
||||
// * @param {ISaleEstimateEditingPayload} payload
|
||||
// */
|
||||
// private validateBranchExistanceOnEstimateEditing = async ({
|
||||
// estimateDTO,
|
||||
// tenantId,
|
||||
// }: ISaleEstimateEditingPayload) => {
|
||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
// tenantId,
|
||||
// estimateDTO.branchId
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Validate branch existance once estimate editing.
|
||||
* @param {ISaleEstimateEditingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.saleEstimate.onEditing)
|
||||
async validateBranchExistanceOnEstimateEditing({
|
||||
estimateDTO,
|
||||
}: ISaleEstimateEditingPayload) {
|
||||
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
estimateDTO.branchId,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,56 +1,41 @@
|
||||
// import { Inject, Service } from 'typedi';
|
||||
// import events from '@/subscribers/events';
|
||||
// import {
|
||||
// ISaleReceiptCreatingPayload,
|
||||
// ISaleReceiptEditingPayload,
|
||||
// } from '@/interfaces';
|
||||
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||
import {
|
||||
ISaleReceiptCreatingPayload,
|
||||
ISaleReceiptEditingPayload,
|
||||
} from '@/modules/SaleReceipts/types/SaleReceipts.types';
|
||||
import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { events } from '@/common/events/events';
|
||||
|
||||
// @Service()
|
||||
// export class SaleReceiptBranchValidateSubscriber {
|
||||
// @Inject()
|
||||
// private validateBranchExistance: ValidateBranchExistance;
|
||||
@Injectable()
|
||||
export class SaleReceiptBranchValidateSubscriber {
|
||||
constructor(
|
||||
private readonly validateBranchExistance: ValidateBranchExistance,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// public attach = (bus) => {
|
||||
// bus.subscribe(
|
||||
// events.saleReceipt.onCreating,
|
||||
// this.validateBranchExistanceOnInvoiceCreating
|
||||
// );
|
||||
// bus.subscribe(
|
||||
// events.saleReceipt.onEditing,
|
||||
// this.validateBranchExistanceOnInvoiceEditing
|
||||
// );
|
||||
// return bus;
|
||||
// };
|
||||
/**
|
||||
* Validate branch existance on estimate creating.
|
||||
* @param {ISaleReceiptCreatingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.saleReceipt.onCreating)
|
||||
async validateBranchExistanceOnInvoiceCreating({
|
||||
saleReceiptDTO,
|
||||
}: ISaleReceiptCreatingPayload) {
|
||||
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
saleReceiptDTO.branchId,
|
||||
);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Validate branch existance on estimate creating.
|
||||
// * @param {ISaleReceiptCreatingPayload} payload
|
||||
// */
|
||||
// private validateBranchExistanceOnInvoiceCreating = async ({
|
||||
// tenantId,
|
||||
// saleReceiptDTO,
|
||||
// }: ISaleReceiptCreatingPayload) => {
|
||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
// tenantId,
|
||||
// saleReceiptDTO.branchId
|
||||
// );
|
||||
// };
|
||||
|
||||
// /**
|
||||
// * Validate branch existance once estimate editing.
|
||||
// * @param {ISaleReceiptEditingPayload} payload
|
||||
// */
|
||||
// private validateBranchExistanceOnInvoiceEditing = async ({
|
||||
// saleReceiptDTO,
|
||||
// tenantId,
|
||||
// }: ISaleReceiptEditingPayload) => {
|
||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
// tenantId,
|
||||
// saleReceiptDTO.branchId
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Validate branch existance once estimate editing.
|
||||
* @param {ISaleReceiptEditingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.saleReceipt.onEditing)
|
||||
async validateBranchExistanceOnInvoiceEditing({
|
||||
saleReceiptDTO,
|
||||
}: ISaleReceiptEditingPayload) {
|
||||
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
saleReceiptDTO.branchId,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,56 +1,41 @@
|
||||
// import { Inject, Service } from 'typedi';
|
||||
// import events from '@/subscribers/events';
|
||||
// import {
|
||||
// IVendorCreditCreatingPayload,
|
||||
// IVendorCreditEditingPayload,
|
||||
// } from '@/interfaces';
|
||||
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||
import {
|
||||
IVendorCreditCreatingPayload,
|
||||
IVendorCreditEditingPayload,
|
||||
} from '@/modules/VendorCredit/types/VendorCredit.types';
|
||||
import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { events } from '@/common/events/events';
|
||||
|
||||
// @Service()
|
||||
// export class VendorCreditBranchValidateSubscriber {
|
||||
// @Inject()
|
||||
// private validateBranchExistance: ValidateBranchExistance;
|
||||
@Injectable()
|
||||
export class VendorCreditBranchValidateSubscriber {
|
||||
constructor(
|
||||
private readonly validateBranchExistance: ValidateBranchExistance,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// public attach = (bus) => {
|
||||
// bus.subscribe(
|
||||
// events.vendorCredit.onCreating,
|
||||
// this.validateBranchExistanceOnCreditCreating
|
||||
// );
|
||||
// bus.subscribe(
|
||||
// events.vendorCredit.onEditing,
|
||||
// this.validateBranchExistanceOnCreditEditing
|
||||
// );
|
||||
// return bus;
|
||||
// };
|
||||
/**
|
||||
* Validate branch existance on estimate creating.
|
||||
* @param {ISaleEstimateCreatedPayload} payload
|
||||
*/
|
||||
@OnEvent(events.vendorCredit.onCreating)
|
||||
async validateBranchExistanceOnCreditCreating({
|
||||
vendorCreditCreateDTO,
|
||||
}: IVendorCreditCreatingPayload) {
|
||||
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
vendorCreditCreateDTO.branchId,
|
||||
);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Validate branch existance on estimate creating.
|
||||
// * @param {ISaleEstimateCreatedPayload} payload
|
||||
// */
|
||||
// private validateBranchExistanceOnCreditCreating = async ({
|
||||
// tenantId,
|
||||
// vendorCreditCreateDTO,
|
||||
// }: IVendorCreditCreatingPayload) => {
|
||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
// tenantId,
|
||||
// vendorCreditCreateDTO.branchId
|
||||
// );
|
||||
// };
|
||||
|
||||
// /**
|
||||
// * Validate branch existance once estimate editing.
|
||||
// * @param {ISaleEstimateEditingPayload} payload
|
||||
// */
|
||||
// private validateBranchExistanceOnCreditEditing = async ({
|
||||
// vendorCreditDTO,
|
||||
// tenantId,
|
||||
// }: IVendorCreditEditingPayload) => {
|
||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
// tenantId,
|
||||
// vendorCreditDTO.branchId
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Validate branch existance once estimate editing.
|
||||
* @param {ISaleEstimateEditingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.vendorCredit.onEditing)
|
||||
async validateBranchExistanceOnCreditEditing({
|
||||
vendorCreditDTO,
|
||||
}: IVendorCreditEditingPayload) {
|
||||
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
vendorCreditDTO.branchId,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +1,25 @@
|
||||
// import { Inject, Service } from 'typedi';
|
||||
// import events from '@/subscribers/events';
|
||||
// import { IRefundVendorCreditCreatingPayload } from '@/interfaces';
|
||||
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||
import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { events } from '@/common/events/events';
|
||||
import { IRefundVendorCreditCreatingPayload } from '@/modules/VendorCreditsRefund/types/VendorCreditRefund.types';
|
||||
|
||||
// @Service()
|
||||
// export class VendorCreditRefundBranchValidateSubscriber {
|
||||
// @Inject()
|
||||
// private validateBranchExistance: ValidateBranchExistance;
|
||||
@Injectable()
|
||||
export class VendorCreditRefundBranchValidateSubscriber {
|
||||
constructor(
|
||||
private readonly validateBranchExistance: ValidateBranchExistance,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// public attach = (bus) => {
|
||||
// bus.subscribe(
|
||||
// events.vendorCredit.onRefundCreating,
|
||||
// this.validateBranchExistanceOnCreditRefundCreating
|
||||
// );
|
||||
// return bus;
|
||||
// };
|
||||
|
||||
// /**
|
||||
// * Validate branch existance on refund credit note creating.
|
||||
// * @param {IRefundVendorCreditCreatingPayload} payload
|
||||
// */
|
||||
// private validateBranchExistanceOnCreditRefundCreating = async ({
|
||||
// tenantId,
|
||||
// refundVendorCreditDTO,
|
||||
// }: IRefundVendorCreditCreatingPayload) => {
|
||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
// tenantId,
|
||||
// refundVendorCreditDTO.branchId
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Validate branch existance on refund credit note creating.
|
||||
* @param {IRefundVendorCreditCreatingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.vendorCredit.onRefundCreating)
|
||||
async validateBranchExistanceOnCreditRefundCreating({
|
||||
refundVendorCreditDTO,
|
||||
}: IRefundVendorCreditCreatingPayload) {
|
||||
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||
refundVendorCreditDTO.branchId,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
// export * from './BillBranchSubscriber';
|
||||
// export * from './CashflowBranchDTOValidatorSubscriber';
|
||||
// export * from './CreditNoteBranchesSubscriber';
|
||||
// export * from './CreditNoteRefundBranchSubscriber';
|
||||
// export * from './ExpenseBranchSubscriber';
|
||||
// export * from './ManualJournalBranchSubscriber';
|
||||
// export * from './PaymentMadeBranchSubscriber';
|
||||
// export * from './PaymentReceiveBranchSubscriber';
|
||||
// export * from './SaleEstimateMultiBranchesSubscriber';
|
||||
// export * from './SaleReceiptBranchesSubscriber';
|
||||
// export * from './VendorCreditBranchSubscriber';
|
||||
// export * from './VendorCreditRefundBranchSubscriber';
|
||||
// export * from './InvoiceBranchValidatorSubscriber';
|
||||
// export * from './ContactOpeningBalanceBranchSubscriber';
|
||||
// export * from './InventoryAdjustmentBranchValidatorSubscriber';
|
||||
Reference in New Issue
Block a user