mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
refactor: branches and warehouses modules
This commit is contained in:
@@ -68,6 +68,7 @@ import { EventTrackerModule } from '../EventsTracker/EventTracker.module';
|
||||
import { MailModule } from '../Mail/Mail.module';
|
||||
import { FinancialStatementsModule } from '../FinancialStatements/FinancialStatements.module';
|
||||
import { StripePaymentModule } from '../StripePayment/StripePayment.module';
|
||||
import { FeaturesModule } from '../Features/Features.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -155,8 +156,9 @@ import { StripePaymentModule } from '../StripePayment/StripePayment.module';
|
||||
BankingTransactionsExcludeModule,
|
||||
BankingTransactionsRegonizeModule,
|
||||
BankingMatchingModule,
|
||||
// TransactionsLockingModule,
|
||||
// SettingsModule,
|
||||
TransactionsLockingModule,
|
||||
SettingsModule,
|
||||
FeaturesModule,
|
||||
InventoryAdjustmentsModule,
|
||||
PostHogModule,
|
||||
EventTrackerModule,
|
||||
|
||||
@@ -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';
|
||||
14
packages/server-nest/src/modules/Features/Features.module.ts
Normal file
14
packages/server-nest/src/modules/Features/Features.module.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { FeaturesConfigureManager } from './FeaturesConfigureManager';
|
||||
import { FeaturesManager } from './FeaturesManager';
|
||||
import { FeaturesSettingsDriver } from './FeaturesSettingsDriver';
|
||||
|
||||
@Module({
|
||||
providers: [
|
||||
FeaturesManager,
|
||||
FeaturesSettingsDriver,
|
||||
FeaturesConfigureManager,
|
||||
],
|
||||
exports: [FeaturesManager],
|
||||
})
|
||||
export class FeaturesModule {}
|
||||
@@ -0,0 +1,30 @@
|
||||
import { Features } from '@/common/types/Features';
|
||||
import { IFeatureConfiugration } from '@/common/types/Features';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
|
||||
@Injectable()
|
||||
export class FeaturesConfigure {
|
||||
constructor(private readonly configService: ConfigService) {}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
getConfigure(): IFeatureConfiugration[] {
|
||||
return [
|
||||
{
|
||||
name: Features.BRANCHES,
|
||||
defaultValue: false,
|
||||
},
|
||||
{
|
||||
name: Features.WAREHOUSES,
|
||||
defaultValue: false,
|
||||
},
|
||||
{
|
||||
name: Features.BankSyncing,
|
||||
defaultValue: this.configService.get('bankSync.enabled') ?? false,
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { get } from 'lodash';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { FeaturesConfigure } from './FeaturesConfigure';
|
||||
|
||||
@Injectable()
|
||||
export class FeaturesConfigureManager {
|
||||
constructor(private readonly featuresConfigure: FeaturesConfigure) {}
|
||||
|
||||
/**
|
||||
* Retrieves the feature configure.
|
||||
* @param {string} featureName
|
||||
* @param {string} accessor
|
||||
* @returns {IFeatureConfiugration}
|
||||
*/
|
||||
getFeatureConfigure = (featureName: string, accessor?: string) => {
|
||||
const meta = this.featuresConfigure.getConfigure().find(
|
||||
(feature) => feature.name === featureName
|
||||
);
|
||||
return accessor ? get(meta, accessor) : meta;
|
||||
};
|
||||
}
|
||||
45
packages/server-nest/src/modules/Features/FeaturesManager.ts
Normal file
45
packages/server-nest/src/modules/Features/FeaturesManager.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { FeaturesSettingsDriver } from './FeaturesSettingsDriver';
|
||||
import { IFeatureAllItem } from '@/common/types/Features';
|
||||
|
||||
@Injectable()
|
||||
export class FeaturesManager {
|
||||
constructor(
|
||||
private drive: FeaturesSettingsDriver,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Turns-on the given feature name.
|
||||
* @param {string} feature
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public turnOn(feature: string) {
|
||||
return this.drive.turnOn(feature);
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns-off the given feature name.
|
||||
* @param {string} feature
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public turnOff(feature: string) {
|
||||
return this.drive.turnOff(feature);
|
||||
}
|
||||
|
||||
/**
|
||||
* Detarmines the given feature name is accessible.
|
||||
* @param {string} feature
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public async accessible(feature: string) {
|
||||
return this.drive.accessible(feature);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the all features and their accessible value and default value.
|
||||
* @returns {Promise<IFeatureAllItem[]>}
|
||||
*/
|
||||
public async all(): Promise<IFeatureAllItem[]> {
|
||||
return this.drive.all();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import { FeaturesConfigureManager } from './FeaturesConfigureManager';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { SETTINGS_PROVIDER } from '../Settings/Settings.types';
|
||||
import { SettingsStore } from '../Settings/SettingsStore';
|
||||
import { IFeatureAllItem } from '@/common/types/Features';
|
||||
import { FeaturesConfigure } from './FeaturesConfigure';
|
||||
|
||||
@Injectable()
|
||||
export class FeaturesSettingsDriver {
|
||||
constructor(
|
||||
private readonly configure: FeaturesConfigureManager,
|
||||
private readonly featuresConfigure: FeaturesConfigure
|
||||
|
||||
@Inject(SETTINGS_PROVIDER)
|
||||
private readonly settings: SettingsStore,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Turns-on the given feature name.
|
||||
* @param {string} feature - The feature name.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async turnOn(feature: string) {
|
||||
this.settings.set({ group: 'features', key: feature, value: true });
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns-off the given feature name.
|
||||
* @param {string} feature - The feature name.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async turnOff(feature: string) {
|
||||
this.settings.set({ group: 'features', key: feature, value: false });
|
||||
}
|
||||
|
||||
/**
|
||||
* Detarmines the given feature name is accessible.
|
||||
* @param {string} feature - The feature name.
|
||||
* @returns {Promise<boolean|null|undefined>}
|
||||
*/
|
||||
async accessible(feature: string) {
|
||||
const defaultValue = this.configure.getFeatureConfigure(
|
||||
feature,
|
||||
'defaultValue',
|
||||
);
|
||||
const settingValue = this.settings.get(
|
||||
{ group: 'features', key: feature },
|
||||
defaultValue,
|
||||
);
|
||||
return settingValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the all features and their accessible value and default value.
|
||||
* @returns {Promise<IFeatureAllItem>}
|
||||
*/
|
||||
async all(): Promise<IFeatureAllItem[]> {
|
||||
const mappedOpers = this.featuresConfigure.getConfigure().map(async (featureConfigure) => {
|
||||
const { name, defaultValue } = featureConfigure;
|
||||
const isAccessible = await this.accessible(featureConfigure.name);
|
||||
return { name, isAccessible, defaultAccessible: defaultValue };
|
||||
});
|
||||
return Promise.all(mappedOpers);
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,12 @@ import { APAgingSummaryApplication } from './APAgingSummaryApplication';
|
||||
import { IAPAgingSummaryQuery } from './APAgingSummary.types';
|
||||
import { AcceptType } from '@/constants/accept-type';
|
||||
import { Response } from 'express';
|
||||
import { ApiOperation } from '@nestjs/swagger';
|
||||
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||
import { PublicRoute } from '@/modules/Auth/Jwt.guard';
|
||||
|
||||
@Controller('reports/payable-aging-summary')
|
||||
@ApiTags('reports')
|
||||
@PublicRoute()
|
||||
export class APAgingSummaryController {
|
||||
constructor(private readonly APAgingSummaryApp: APAgingSummaryApplication) {}
|
||||
|
||||
|
||||
@@ -3,10 +3,11 @@ import { IVendorBalanceSummaryQuery } from './VendorBalanceSummary.types';
|
||||
import { VendorBalanceSummaryApplication } from './VendorBalanceSummaryApplication';
|
||||
import { Response } from 'express';
|
||||
import { AcceptType } from '@/constants/accept-type';
|
||||
import { ApiOperation, ApiResponse } from '@nestjs/swagger';
|
||||
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
||||
import { PublicRoute } from '@/modules/Auth/Jwt.guard';
|
||||
|
||||
@Controller('/reports/vendor-balance-summary')
|
||||
@ApiTags('reports')
|
||||
@PublicRoute()
|
||||
export class VendorBalanceSummaryController {
|
||||
constructor(
|
||||
|
||||
@@ -24,6 +24,8 @@ export class InventoryCostLotTracker extends BaseModel {
|
||||
exchangeRate: number;
|
||||
currencyCode: string;
|
||||
|
||||
warehouseId: number;
|
||||
|
||||
item?: Item;
|
||||
invoice?: SaleInvoice;
|
||||
receipt?: SaleReceipt;
|
||||
|
||||
@@ -32,13 +32,9 @@ export class ItemCategoryApplication {
|
||||
* @returns {Promise<ItemCategory>} The created item category.
|
||||
*/
|
||||
public createItemCategory(
|
||||
tenantId: number,
|
||||
itemCategoryDTO: IItemCategoryOTD,
|
||||
) {
|
||||
return this.createItemCategoryService.newItemCategory(
|
||||
tenantId,
|
||||
itemCategoryDTO,
|
||||
);
|
||||
return this.createItemCategoryService.newItemCategory(itemCategoryDTO);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,14 +27,8 @@ export class ItemCategoryController {
|
||||
|
||||
@Post()
|
||||
@ApiOperation({ summary: 'Create a new item category.' })
|
||||
async createItemCategory(
|
||||
@Body('tenantId') tenantId: number,
|
||||
@Body() itemCategoryDTO: IItemCategoryOTD,
|
||||
) {
|
||||
return this.itemCategoryApplication.createItemCategory(
|
||||
tenantId,
|
||||
itemCategoryDTO,
|
||||
);
|
||||
async createItemCategory(@Body() itemCategoryDTO: IItemCategoryOTD) {
|
||||
return this.itemCategoryApplication.createItemCategory(itemCategoryDTO);
|
||||
}
|
||||
|
||||
@Get()
|
||||
|
||||
@@ -50,7 +50,6 @@ export class CreateItemCategoryService {
|
||||
* @return {Promise<void>}
|
||||
*/
|
||||
public async newItemCategory(
|
||||
tenantId: number,
|
||||
itemCategoryOTD: IItemCategoryOTD,
|
||||
trx?: Knex.Transaction,
|
||||
): Promise<ItemCategory> {
|
||||
@@ -81,7 +80,6 @@ export class CreateItemCategoryService {
|
||||
// Triggers `onItemCategoryCreated` event.
|
||||
await this.eventEmitter.emitAsync(events.itemCategory.onCreated, {
|
||||
itemCategory,
|
||||
tenantId,
|
||||
trx,
|
||||
} as IItemCategoryCreatedPayload);
|
||||
|
||||
|
||||
@@ -18,6 +18,15 @@ import { TenantModelProxy } from '../System/models/TenantBaseModel';
|
||||
|
||||
@Injectable()
|
||||
export class ItemsValidators {
|
||||
/**
|
||||
* @param {typeof Item} itemModel - The Item model.
|
||||
* @param {typeof Account} accountModel - The Account model.
|
||||
* @param {typeof TaxRateModel} taxRateModel - The TaxRateModel model.
|
||||
* @param {typeof ItemEntry} itemEntryModel - The ItemEntry model.
|
||||
* @param {typeof ItemCategory} itemCategoryModel - The ItemCategory model.
|
||||
* @param {typeof AccountTransaction} accountTransactionModel - The AccountTransaction model.
|
||||
* @param {typeof InventoryAdjustment} inventoryAdjustmentEntryModel - The InventoryAdjustment model.
|
||||
*/
|
||||
constructor(
|
||||
@Inject(Item.name) private itemModel: TenantModelProxy<typeof Item>,
|
||||
|
||||
@@ -244,9 +253,9 @@ export class ItemsValidators {
|
||||
/**
|
||||
* Validate the item inventory account whether modified and item
|
||||
* has associated inventory transactions.
|
||||
* @param {Item} oldItem
|
||||
* @param {IItemDTO} newItemDTO
|
||||
* @returns
|
||||
* @param {Item} oldItem - Old item.
|
||||
* @param {IItemDTO} newItemDTO - New item DTO.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async validateItemInvnetoryAccountModified(
|
||||
oldItem: Item,
|
||||
@@ -285,7 +294,7 @@ export class ItemsValidators {
|
||||
|
||||
/**
|
||||
* Validate the purchase tax rate id existance.
|
||||
* @param {number} taxRateId -
|
||||
* @param {number} taxRateId - Tax rate id.
|
||||
*/
|
||||
public async validatePurchaseTaxRateExistance(taxRateId: number) {
|
||||
const foundTaxRate = await this.taxRateModel().query().findById(taxRateId);
|
||||
@@ -297,7 +306,7 @@ export class ItemsValidators {
|
||||
|
||||
/**
|
||||
* Validate the sell tax rate id existance.
|
||||
* @param {number} taxRateId
|
||||
* @param {number} taxRateId - Tax rate id.
|
||||
*/
|
||||
public async validateSellTaxRateExistance(taxRateId: number) {
|
||||
const foundTaxRate = await this.taxRateModel().query().findById(taxRateId);
|
||||
|
||||
@@ -28,6 +28,8 @@ export class ManualJournal extends TenantBaseModel {
|
||||
entries!: ManualJournalEntry[];
|
||||
attachments!: Document[];
|
||||
|
||||
branchId?: number;
|
||||
|
||||
/**
|
||||
* Table name.
|
||||
*/
|
||||
|
||||
@@ -60,7 +60,11 @@ import { SEND_PAYMENT_RECEIVED_MAIL_QUEUE } from './constants';
|
||||
SendPaymentReceiveMailNotification,
|
||||
SendPaymentReceivedMailProcessor,
|
||||
],
|
||||
exports: [PaymentReceivesApplication, CreatePaymentReceivedService],
|
||||
exports: [
|
||||
PaymentReceivesApplication,
|
||||
CreatePaymentReceivedService,
|
||||
PaymentReceivedGLEntries,
|
||||
],
|
||||
imports: [
|
||||
ChromiumlyTenancyModule,
|
||||
TemplateInjectableModule,
|
||||
|
||||
@@ -1,76 +1,70 @@
|
||||
// import { Knex } from 'knex';
|
||||
// import async from 'async';
|
||||
// import { Inject, Service } from 'typedi';
|
||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
// import { PaymentReceivedGLEntries } from '../PaymentReceived/PaymentReceivedGLEntries';
|
||||
import { Knex } from 'knex';
|
||||
import async from 'async';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { PaymentReceivedGLEntries } from '../PaymentReceived/commands/PaymentReceivedGLEntries';
|
||||
import { TenantModelProxy } from '../System/models/TenantBaseModel';
|
||||
import { PaymentReceivedEntry } from '../PaymentReceived/models/PaymentReceivedEntry';
|
||||
|
||||
// @Service()
|
||||
// export class InvoicePaymentsGLEntriesRewrite {
|
||||
// @Inject()
|
||||
// public tenancy: HasTenancyService;
|
||||
@Injectable()
|
||||
export class InvoicePaymentsGLEntriesRewrite {
|
||||
constructor(
|
||||
private readonly paymentGLEntries: PaymentReceivedGLEntries,
|
||||
|
||||
// @Inject()
|
||||
// public paymentGLEntries: PaymentReceivedGLEntries;
|
||||
@Inject(PaymentReceivedEntry.name)
|
||||
private readonly paymentReceivedEntryModel: TenantModelProxy<typeof PaymentReceivedEntry>
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Rewrites the payment GL entries task.
|
||||
// * @param {{ tenantId: number, paymentId: number, trx: Knex?.Transaction }}
|
||||
// * @returns {Promise<void>}
|
||||
// */
|
||||
// public rewritePaymentsGLEntriesTask = async ({
|
||||
// tenantId,
|
||||
// paymentId,
|
||||
// trx,
|
||||
// }) => {
|
||||
// await this.paymentGLEntries.rewritePaymentGLEntries(
|
||||
// tenantId,
|
||||
// paymentId,
|
||||
// trx
|
||||
// );
|
||||
// };
|
||||
/**
|
||||
* Rewrites the payment GL entries task.
|
||||
* @param {{ tenantId: number, paymentId: number, trx: Knex?.Transaction }}
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public rewritePaymentsGLEntriesTask = async ({
|
||||
paymentId,
|
||||
trx,
|
||||
}) => {
|
||||
await this.paymentGLEntries.rewritePaymentGLEntries(
|
||||
paymentId,
|
||||
trx
|
||||
);
|
||||
};
|
||||
|
||||
// /**
|
||||
// * Rewrites the payment GL entries of the given payments ids.
|
||||
// * @param {number} tenantId
|
||||
// * @param {number[]} paymentsIds
|
||||
// * @param {Knex.Transaction} trx
|
||||
// */
|
||||
// public rewritePaymentsGLEntriesQueue = async (
|
||||
// tenantId: number,
|
||||
// paymentsIds: number[],
|
||||
// trx?: Knex.Transaction
|
||||
// ) => {
|
||||
// // Initiate a new queue for accounts balance mutation.
|
||||
// const rewritePaymentGL = async.queue(this.rewritePaymentsGLEntriesTask, 10);
|
||||
/**
|
||||
* Rewrites the payment GL entries of the given payments ids.
|
||||
* @param {number[]} paymentsIds
|
||||
* @param {Knex.Transaction} trx
|
||||
*/
|
||||
public rewritePaymentsGLEntriesQueue = async (
|
||||
paymentsIds: number[],
|
||||
trx?: Knex.Transaction
|
||||
) => {
|
||||
// Initiate a new queue for accounts balance mutation.
|
||||
const rewritePaymentGL = async.queue(this.rewritePaymentsGLEntriesTask, 10);
|
||||
|
||||
// paymentsIds.forEach((paymentId: number) => {
|
||||
// rewritePaymentGL.push({ paymentId, trx, tenantId });
|
||||
// });
|
||||
// if (paymentsIds.length > 0) {
|
||||
// await rewritePaymentGL.drain();
|
||||
// }
|
||||
// };
|
||||
paymentsIds.forEach((paymentId: number) => {
|
||||
rewritePaymentGL.push({ paymentId, trx });
|
||||
});
|
||||
if (paymentsIds.length > 0) {
|
||||
await rewritePaymentGL.drain();
|
||||
}
|
||||
};
|
||||
|
||||
// /**
|
||||
// * Rewrites the payments GL entries that associated to the given invoice.
|
||||
// * @param {number} tenantId
|
||||
// * @param {number} invoiceId
|
||||
// * @param {Knex.Transaction} trx
|
||||
// * @returns {Promise<void>}
|
||||
// */
|
||||
// public invoicePaymentsGLEntriesRewrite = async (
|
||||
// tenantId: number,
|
||||
// invoiceId: number,
|
||||
// trx?: Knex.Transaction
|
||||
// ) => {
|
||||
// const { PaymentReceiveEntry } = this.tenancy.models(tenantId);
|
||||
/**
|
||||
* Rewrites the payments GL entries that associated to the given invoice.
|
||||
* @param {number} invoiceId
|
||||
* @param {Knex.Transaction} trx
|
||||
* @ {Promise<void>}
|
||||
*/
|
||||
public invoicePaymentsGLEntriesRewrite = async (
|
||||
invoiceId: number,
|
||||
trx?: Knex.Transaction
|
||||
) => {
|
||||
const invoicePaymentEntries = await this.paymentReceivedEntryModel()
|
||||
.query()
|
||||
.where('invoiceId', invoiceId);
|
||||
|
||||
// const invoicePaymentEntries = await PaymentReceiveEntry.query().where(
|
||||
// 'invoiceId',
|
||||
// invoiceId
|
||||
// );
|
||||
// const paymentsIds = invoicePaymentEntries.map((e) => e.paymentReceiveId);
|
||||
const paymentsIds = invoicePaymentEntries.map((e) => e.paymentReceiveId);
|
||||
|
||||
// await this.rewritePaymentsGLEntriesQueue(tenantId, paymentsIds, trx);
|
||||
// };
|
||||
// }
|
||||
await this.rewritePaymentsGLEntriesQueue(paymentsIds, trx);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -88,11 +88,9 @@ export interface ISaleInvoiceWriteoffDTO {
|
||||
export type InvoiceNotificationType = 'details' | 'reminder';
|
||||
|
||||
export interface ISaleInvoiceCreatedPayload {
|
||||
// tenantId: number;
|
||||
saleInvoice: SaleInvoice;
|
||||
saleInvoiceDTO: ISaleInvoiceCreateDTO;
|
||||
saleInvoiceId: number;
|
||||
// authorizedUser: SystemUser;
|
||||
trx: Knex.Transaction;
|
||||
}
|
||||
|
||||
@@ -103,17 +101,14 @@ export interface ISaleInvoiceCreatingPaylaod {
|
||||
}
|
||||
|
||||
export interface ISaleInvoiceEditedPayload {
|
||||
// tenantId: number;
|
||||
saleInvoice: SaleInvoice;
|
||||
oldSaleInvoice: SaleInvoice;
|
||||
saleInvoiceDTO: ISaleInvoiceEditDTO;
|
||||
saleInvoiceId: number;
|
||||
// authorizedUser: SystemUser;
|
||||
trx: Knex.Transaction;
|
||||
}
|
||||
|
||||
export interface ISaleInvoiceEditingPayload {
|
||||
// tenantId: number;
|
||||
saleInvoiceDTO: ISaleInvoiceEditDTO;
|
||||
oldSaleInvoice: SaleInvoice;
|
||||
trx: Knex.Transaction;
|
||||
@@ -127,21 +122,18 @@ export interface ISaleInvoiceDeletePayload {
|
||||
}
|
||||
|
||||
export interface ISaleInvoiceDeletingPayload {
|
||||
// tenantId: number;
|
||||
oldSaleInvoice: SaleInvoice;
|
||||
saleInvoiceId: number;
|
||||
trx: Knex.Transaction;
|
||||
}
|
||||
|
||||
export interface ISaleInvoiceDeletedPayload {
|
||||
// tenantId: number;
|
||||
oldSaleInvoice: SaleInvoice;
|
||||
saleInvoiceId: number;
|
||||
trx: Knex.Transaction;
|
||||
}
|
||||
|
||||
export interface ISaleInvoiceWriteoffCreatePayload {
|
||||
// tenantId: number;
|
||||
saleInvoiceId: number;
|
||||
saleInvoice: SaleInvoice;
|
||||
writeoffDTO: ISaleInvoiceWriteoffDTO;
|
||||
@@ -149,33 +141,28 @@ export interface ISaleInvoiceWriteoffCreatePayload {
|
||||
}
|
||||
|
||||
export interface ISaleInvoiceWriteoffCreatedPayload {
|
||||
// tenantId: number;
|
||||
saleInvoiceId: number;
|
||||
saleInvoice: SaleInvoice;
|
||||
writeoffDTO: ISaleInvoiceCreatedPayload;
|
||||
}
|
||||
|
||||
export interface ISaleInvoiceWrittenOffCancelPayload {
|
||||
// tenantId: number;
|
||||
saleInvoice: SaleInvoice;
|
||||
trx: Knex.Transaction;
|
||||
}
|
||||
|
||||
export interface ISaleInvoiceWrittenOffCanceledPayload {
|
||||
// tenantId: number;
|
||||
saleInvoice: SaleInvoice;
|
||||
trx: Knex.Transaction;
|
||||
}
|
||||
|
||||
export interface ISaleInvoiceEventDeliveredPayload {
|
||||
// tenantId: number;
|
||||
saleInvoiceId: number;
|
||||
saleInvoice: SaleInvoice;
|
||||
trx: Knex.Transaction;
|
||||
}
|
||||
|
||||
export interface ISaleInvoiceDeliveringPayload {
|
||||
// tenantId: number;
|
||||
oldSaleInvoice: SaleInvoice;
|
||||
trx: Knex.Transaction;
|
||||
}
|
||||
|
||||
@@ -1,146 +1,148 @@
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import * as R from 'ramda';
|
||||
// import { Knex } from 'knex';
|
||||
// import { AccountNormal, IInventoryLotCost, ILedgerEntry } from '@/interfaces';
|
||||
// import { increment } from 'utils';
|
||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
// import Ledger from '@/services/Accounting/Ledger';
|
||||
// import LedgerStorageService from '@/services/Accounting/LedgerStorageService';
|
||||
// import { groupInventoryTransactionsByTypeId } from '../../Inventory/utils';
|
||||
import * as R from 'ramda';
|
||||
import { Knex } from 'knex';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { TenantModelProxy } from '../System/models/TenantBaseModel';
|
||||
import { InventoryCostLotTracker } from '../InventoryCost/models/InventoryCostLotTracker';
|
||||
import { LedgerStorageService } from '../Ledger/LedgerStorage.service';
|
||||
import { groupInventoryTransactionsByTypeId } from '../InventoryCost/utils';
|
||||
import { Ledger } from '../Ledger/Ledger';
|
||||
import { AccountNormal } from '@/interfaces/Account';
|
||||
import { ILedgerEntry } from '../Ledger/types/Ledger.types';
|
||||
import { increment } from '@/utils/increment';
|
||||
|
||||
// @Service()
|
||||
// export class SaleInvoiceCostGLEntries {
|
||||
// @Inject()
|
||||
// private tenancy: HasTenancyService;
|
||||
@Injectable()
|
||||
export class SaleInvoiceCostGLEntries {
|
||||
constructor(
|
||||
private readonly ledgerStorage: LedgerStorageService,
|
||||
|
||||
// @Inject()
|
||||
// private ledgerStorage: LedgerStorageService;
|
||||
@Inject(InventoryCostLotTracker.name)
|
||||
private readonly inventoryCostLotTracker: TenantModelProxy<
|
||||
typeof InventoryCostLotTracker
|
||||
>,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Writes journal entries from sales invoices.
|
||||
// * @param {number} tenantId - The tenant id.
|
||||
// * @param {Date} startingDate - Starting date.
|
||||
// * @param {boolean} override
|
||||
// */
|
||||
// public writeInventoryCostJournalEntries = async (
|
||||
// tenantId: number,
|
||||
// startingDate: Date,
|
||||
// trx?: Knex.Transaction
|
||||
// ): Promise<void> => {
|
||||
// const { InventoryCostLotTracker } = this.tenancy.models(tenantId);
|
||||
/**
|
||||
* Writes journal entries from sales invoices.
|
||||
* @param {Date} startingDate - Starting date.
|
||||
* @param {boolean} override
|
||||
*/
|
||||
public writeInventoryCostJournalEntries = async (
|
||||
startingDate: Date,
|
||||
trx?: Knex.Transaction,
|
||||
): Promise<void> => {
|
||||
const inventoryCostLotTrans = await this.inventoryCostLotTracker()
|
||||
.query()
|
||||
.where('direction', 'OUT')
|
||||
.where('transaction_type', 'SaleInvoice')
|
||||
.where('cost', '>', 0)
|
||||
.modify('filterDateRange', startingDate)
|
||||
.orderBy('date', 'ASC')
|
||||
.withGraphFetched('invoice')
|
||||
.withGraphFetched('item');
|
||||
|
||||
// const inventoryCostLotTrans = await InventoryCostLotTracker.query()
|
||||
// .where('direction', 'OUT')
|
||||
// .where('transaction_type', 'SaleInvoice')
|
||||
// .where('cost', '>', 0)
|
||||
// .modify('filterDateRange', startingDate)
|
||||
// .orderBy('date', 'ASC')
|
||||
// .withGraphFetched('invoice')
|
||||
// .withGraphFetched('item');
|
||||
const ledger = this.getInventoryCostLotsLedger(inventoryCostLotTrans);
|
||||
|
||||
// const ledger = this.getInventoryCostLotsLedger(inventoryCostLotTrans);
|
||||
// Commit the ledger to the storage.
|
||||
await this.ledgerStorage.commit(ledger, trx);
|
||||
};
|
||||
|
||||
// // Commit the ledger to the storage.
|
||||
// await this.ledgerStorage.commit(tenantId, ledger, trx);
|
||||
// };
|
||||
/**
|
||||
* Retrieves the inventory cost lots ledger.
|
||||
* @param {IInventoryLotCost[]} inventoryCostLots
|
||||
* @returns {Ledger}
|
||||
*/
|
||||
private getInventoryCostLotsLedger = (
|
||||
inventoryCostLots: InventoryCostLotTracker[],
|
||||
) => {
|
||||
// Groups the inventory cost lots transactions.
|
||||
const inventoryTransactions =
|
||||
groupInventoryTransactionsByTypeId(inventoryCostLots);
|
||||
|
||||
// /**
|
||||
// * Retrieves the inventory cost lots ledger.
|
||||
// * @param {IInventoryLotCost[]} inventoryCostLots
|
||||
// * @returns {Ledger}
|
||||
// */
|
||||
// private getInventoryCostLotsLedger = (
|
||||
// inventoryCostLots: IInventoryLotCost[]
|
||||
// ) => {
|
||||
// // Groups the inventory cost lots transactions.
|
||||
// const inventoryTransactions =
|
||||
// groupInventoryTransactionsByTypeId(inventoryCostLots);
|
||||
const entries = inventoryTransactions
|
||||
.map(this.getSaleInvoiceCostGLEntries)
|
||||
.flat();
|
||||
return new Ledger(entries);
|
||||
};
|
||||
|
||||
// const entries = inventoryTransactions
|
||||
// .map(this.getSaleInvoiceCostGLEntries)
|
||||
// .flat();
|
||||
// return new Ledger(entries);
|
||||
// };
|
||||
/**
|
||||
*
|
||||
* @param {IInventoryLotCost} inventoryCostLot
|
||||
* @returns {}
|
||||
*/
|
||||
private getInvoiceCostGLCommonEntry = (
|
||||
inventoryCostLot: InventoryCostLotTracker,
|
||||
) => {
|
||||
return {
|
||||
currencyCode: inventoryCostLot.invoice.currencyCode,
|
||||
exchangeRate: inventoryCostLot.invoice.exchangeRate,
|
||||
|
||||
// /**
|
||||
// *
|
||||
// * @param {IInventoryLotCost} inventoryCostLot
|
||||
// * @returns {}
|
||||
// */
|
||||
// private getInvoiceCostGLCommonEntry = (
|
||||
// inventoryCostLot: IInventoryLotCost
|
||||
// ) => {
|
||||
// return {
|
||||
// currencyCode: inventoryCostLot.invoice.currencyCode,
|
||||
// exchangeRate: inventoryCostLot.invoice.exchangeRate,
|
||||
transactionType: inventoryCostLot.transactionType,
|
||||
transactionId: inventoryCostLot.transactionId,
|
||||
|
||||
// transactionType: inventoryCostLot.transactionType,
|
||||
// transactionId: inventoryCostLot.transactionId,
|
||||
date: inventoryCostLot.date,
|
||||
indexGroup: 20,
|
||||
costable: true,
|
||||
createdAt: inventoryCostLot.createdAt,
|
||||
|
||||
// date: inventoryCostLot.date,
|
||||
// indexGroup: 20,
|
||||
// costable: true,
|
||||
// createdAt: inventoryCostLot.createdAt,
|
||||
debit: 0,
|
||||
credit: 0,
|
||||
|
||||
// debit: 0,
|
||||
// credit: 0,
|
||||
branchId: inventoryCostLot.invoice.branchId,
|
||||
};
|
||||
};
|
||||
|
||||
// branchId: inventoryCostLot.invoice.branchId,
|
||||
// };
|
||||
// };
|
||||
/**
|
||||
* Retrieves the inventory cost GL entry.
|
||||
* @param {IInventoryLotCost} inventoryLotCost
|
||||
* @returns {ILedgerEntry[]}
|
||||
*/
|
||||
private getInventoryCostGLEntry = R.curry(
|
||||
(
|
||||
getIndexIncrement,
|
||||
inventoryCostLot: InventoryCostLotTracker,
|
||||
): ILedgerEntry[] => {
|
||||
const commonEntry = this.getInvoiceCostGLCommonEntry(inventoryCostLot);
|
||||
const costAccountId =
|
||||
inventoryCostLot.costAccountId || inventoryCostLot.item.costAccountId;
|
||||
|
||||
// /**
|
||||
// * Retrieves the inventory cost GL entry.
|
||||
// * @param {IInventoryLotCost} inventoryLotCost
|
||||
// * @returns {ILedgerEntry[]}
|
||||
// */
|
||||
// private getInventoryCostGLEntry = R.curry(
|
||||
// (
|
||||
// getIndexIncrement,
|
||||
// inventoryCostLot: IInventoryLotCost
|
||||
// ): ILedgerEntry[] => {
|
||||
// const commonEntry = this.getInvoiceCostGLCommonEntry(inventoryCostLot);
|
||||
// const costAccountId =
|
||||
// inventoryCostLot.costAccountId || inventoryCostLot.item.costAccountId;
|
||||
// XXX Debit - Cost account.
|
||||
const costEntry = {
|
||||
...commonEntry,
|
||||
debit: inventoryCostLot.cost,
|
||||
accountId: costAccountId,
|
||||
accountNormal: AccountNormal.DEBIT,
|
||||
itemId: inventoryCostLot.itemId,
|
||||
index: getIndexIncrement(),
|
||||
};
|
||||
// XXX Credit - Inventory account.
|
||||
const inventoryEntry = {
|
||||
...commonEntry,
|
||||
credit: inventoryCostLot.cost,
|
||||
accountId: inventoryCostLot.item.inventoryAccountId,
|
||||
accountNormal: AccountNormal.DEBIT,
|
||||
itemId: inventoryCostLot.itemId,
|
||||
index: getIndexIncrement(),
|
||||
};
|
||||
return [costEntry, inventoryEntry];
|
||||
},
|
||||
);
|
||||
|
||||
// // XXX Debit - Cost account.
|
||||
// const costEntry = {
|
||||
// ...commonEntry,
|
||||
// debit: inventoryCostLot.cost,
|
||||
// accountId: costAccountId,
|
||||
// accountNormal: AccountNormal.DEBIT,
|
||||
// itemId: inventoryCostLot.itemId,
|
||||
// index: getIndexIncrement(),
|
||||
// };
|
||||
// // XXX Credit - Inventory account.
|
||||
// const inventoryEntry = {
|
||||
// ...commonEntry,
|
||||
// credit: inventoryCostLot.cost,
|
||||
// accountId: inventoryCostLot.item.inventoryAccountId,
|
||||
// accountNormal: AccountNormal.DEBIT,
|
||||
// itemId: inventoryCostLot.itemId,
|
||||
// index: getIndexIncrement(),
|
||||
// };
|
||||
// return [costEntry, inventoryEntry];
|
||||
// }
|
||||
// );
|
||||
/**
|
||||
* Writes journal entries for given sale invoice.
|
||||
* -----
|
||||
* - Cost of goods sold -> Debit -> YYYY
|
||||
* - Inventory assets -> Credit -> YYYY
|
||||
*-----
|
||||
* @param {ISaleInvoice} saleInvoice
|
||||
* @param {JournalPoster} journal
|
||||
*/
|
||||
public getSaleInvoiceCostGLEntries = (
|
||||
inventoryCostLots: InventoryCostLotTracker[],
|
||||
): ILedgerEntry[] => {
|
||||
const getIndexIncrement = increment(0);
|
||||
const getInventoryLotEntry =
|
||||
this.getInventoryCostGLEntry(getIndexIncrement);
|
||||
|
||||
// /**
|
||||
// * Writes journal entries for given sale invoice.
|
||||
// * -----
|
||||
// * - Cost of goods sold -> Debit -> YYYY
|
||||
// * - Inventory assets -> Credit -> YYYY
|
||||
// *-----
|
||||
// * @param {ISaleInvoice} saleInvoice
|
||||
// * @param {JournalPoster} journal
|
||||
// */
|
||||
// public getSaleInvoiceCostGLEntries = (
|
||||
// inventoryCostLots: IInventoryLotCost[]
|
||||
// ): ILedgerEntry[] => {
|
||||
// const getIndexIncrement = increment(0);
|
||||
// const getInventoryLotEntry =
|
||||
// this.getInventoryCostGLEntry(getIndexIncrement);
|
||||
|
||||
// return inventoryCostLots.map(getInventoryLotEntry).flat();
|
||||
// };
|
||||
// }
|
||||
return inventoryCostLots.map((t) => getInventoryLotEntry(t)).flat();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -47,6 +47,14 @@ import { MailNotificationModule } from '../MailNotification/MailNotification.mod
|
||||
import { SendSaleInvoiceMailProcessor } from './processors/SendSaleInvoiceMail.processor';
|
||||
import { BullModule } from '@nestjs/bull';
|
||||
import { SendSaleInvoiceQueue } from './constants';
|
||||
import { InvoicePaymentIntegrationSubscriber } from './subscribers/InvoicePaymentIntegrationSubscriber';
|
||||
import { InvoiceChangeStatusOnMailSentSubscriber } from './subscribers/InvoiceChangeStatusOnMailSentSubscriber';
|
||||
import { InvoiceCostGLEntriesSubscriber } from './subscribers/InvoiceCostGLEntriesSubscriber';
|
||||
import { InvoicePaymentGLRewriteSubscriber } from './subscribers/InvoicePaymentGLRewriteSubscriber';
|
||||
import { SaleInvoiceWriteInventoryTransactionsSubscriber } from './subscribers/InvoiceWriteInventoryTransactions';
|
||||
import { SaleInvoiceCostGLEntries } from './SaleInvoiceCostGLEntries';
|
||||
import { InvoicePaymentsGLEntriesRewrite } from './InvoicePaymentsGLRewrite';
|
||||
import { PaymentsReceivedModule } from '../PaymentReceived/PaymentsReceived.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -57,6 +65,7 @@ import { SendSaleInvoiceQueue } from './constants';
|
||||
BranchesModule,
|
||||
WarehousesModule,
|
||||
TaxRatesModule,
|
||||
PaymentsReceivedModule,
|
||||
LedgerModule,
|
||||
AccountsModule,
|
||||
MailModule,
|
||||
@@ -100,6 +109,13 @@ import { SendSaleInvoiceQueue } from './constants';
|
||||
GetSaleInvoiceMailState,
|
||||
SendSaleInvoiceMailCommon,
|
||||
SendSaleInvoiceMailProcessor,
|
||||
SaleInvoiceCostGLEntries,
|
||||
InvoicePaymentIntegrationSubscriber,
|
||||
InvoiceChangeStatusOnMailSentSubscriber,
|
||||
InvoiceCostGLEntriesSubscriber,
|
||||
InvoicePaymentGLRewriteSubscriber,
|
||||
SaleInvoiceWriteInventoryTransactionsSubscriber,
|
||||
InvoicePaymentsGLEntriesRewrite
|
||||
],
|
||||
exports: [GetSaleInvoice],
|
||||
})
|
||||
|
||||
@@ -116,7 +116,7 @@ export class CreateSaleInvoice {
|
||||
|
||||
/**
|
||||
* Transformes create DTO to model.
|
||||
* @param {ICustomer} customer -
|
||||
* @param {Customer} customer -
|
||||
* @param {ISaleInvoiceCreateDTO} saleInvoiceDTO -
|
||||
*/
|
||||
private transformCreateDTOToModel = async (
|
||||
|
||||
@@ -16,6 +16,12 @@ import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||
|
||||
@Injectable()
|
||||
export class DeliverSaleInvoice {
|
||||
/**
|
||||
* @param {EventEmitter2} eventEmitter - Event emitter.
|
||||
* @param {UnitOfWork} uow - Unit of work.
|
||||
* @param {CommandSaleInvoiceValidators} validators - Command sale invoice validators.
|
||||
* @param {TenantModelProxy<typeof SaleInvoice>} saleInvoiceModel - Sale invoice model.
|
||||
*/
|
||||
constructor(
|
||||
private eventEmitter: EventEmitter2,
|
||||
private uow: UnitOfWork,
|
||||
|
||||
@@ -11,6 +11,7 @@ import { DiscountType } from '@/common/types/Discount';
|
||||
import { Account } from '@/modules/Accounts/models/Account.model';
|
||||
import { ISearchRole } from '@/modules/DynamicListing/DynamicFilter/DynamicFilter.types';
|
||||
import { TenantBaseModel } from '@/modules/System/models/TenantBaseModel';
|
||||
import { PaymentIntegrationTransactionLink } from '../SaleInvoice.types';
|
||||
|
||||
export class SaleInvoice extends TenantBaseModel{
|
||||
public taxAmountWithheld: number;
|
||||
@@ -51,7 +52,8 @@ export class SaleInvoice extends TenantBaseModel{
|
||||
public entries!: ItemEntry[];
|
||||
public attachments!: Document[];
|
||||
public writtenoffExpenseAccount!: Account;
|
||||
|
||||
public paymentMethods!: PaymentIntegrationTransactionLink[];
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*/
|
||||
|
||||
@@ -1,49 +1,36 @@
|
||||
// import { Inject, Service } from 'typedi';
|
||||
// import events from '@/subscribers/events';
|
||||
// import { ISaleInvoiceMailSent } from '@/interfaces';
|
||||
// import { DeliverSaleInvoice } from '../commands/DeliverSaleInvoice.service';
|
||||
// import { ServiceError } from '@/exceptions';
|
||||
// import { ERRORS } from '../constants';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { DeliverSaleInvoice } from '../commands/DeliverSaleInvoice.service';
|
||||
import { ERRORS } from '../constants';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { events } from '@/common/events/events';
|
||||
import { ServiceError } from '@/modules/Items/ServiceError';
|
||||
import { ISaleInvoiceMailSent } from '../SaleInvoice.types';
|
||||
|
||||
// @Service()
|
||||
// export class InvoiceChangeStatusOnMailSentSubscriber {
|
||||
// @Inject()
|
||||
// private markInvoiceDelivedService: DeliverSaleInvoice;
|
||||
@Injectable()
|
||||
export class InvoiceChangeStatusOnMailSentSubscriber {
|
||||
constructor(private readonly markInvoiceDelivedService: DeliverSaleInvoice) {}
|
||||
|
||||
// /**
|
||||
// * Attaches events.
|
||||
// */
|
||||
// public attach(bus) {
|
||||
// bus.subscribe(events.saleInvoice.onPreMailSend, this.markInvoiceDelivered);
|
||||
// bus.subscribe(
|
||||
// events.saleInvoice.onMailReminderSent,
|
||||
// this.markInvoiceDelivered
|
||||
// );
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Marks the invoice delivered once the invoice mail sent.
|
||||
// * @param {ISaleInvoiceMailSent}
|
||||
// * @returns {Promise<void>}
|
||||
// */
|
||||
// private markInvoiceDelivered = async ({
|
||||
// tenantId,
|
||||
// saleInvoiceId,
|
||||
// messageOptions,
|
||||
// }: ISaleInvoiceMailSent) => {
|
||||
// try {
|
||||
// await this.markInvoiceDelivedService.deliverSaleInvoice(
|
||||
// tenantId,
|
||||
// saleInvoiceId
|
||||
// );
|
||||
// } catch (error) {
|
||||
// if (
|
||||
// error instanceof ServiceError &&
|
||||
// error.errorType === ERRORS.SALE_INVOICE_ALREADY_DELIVERED
|
||||
// ) {
|
||||
// } else {
|
||||
// throw error;
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Marks the invoice delivered once the invoice mail sent.
|
||||
* @param {ISaleInvoiceMailSent}
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
@OnEvent(events.saleInvoice.onMailReminderSent)
|
||||
@OnEvent(events.saleInvoice.onMailSent)
|
||||
async markInvoiceDelivered({
|
||||
saleInvoiceId,
|
||||
messageOptions,
|
||||
}: ISaleInvoiceMailSent) {
|
||||
try {
|
||||
await this.markInvoiceDelivedService.deliverSaleInvoice(saleInvoiceId);
|
||||
} catch (error) {
|
||||
if (
|
||||
error instanceof ServiceError &&
|
||||
error.errorType === ERRORS.SALE_INVOICE_ALREADY_DELIVERED
|
||||
) {
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +1,22 @@
|
||||
// import { Inject, Service } from 'typedi';
|
||||
// import events from '@/subscribers/events';
|
||||
// import { IInventoryCostLotsGLEntriesWriteEvent } from '@/interfaces';
|
||||
// import { SaleInvoiceCostGLEntries } from '../SaleInvoiceCostGLEntries';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { IInventoryCostLotsGLEntriesWriteEvent } from '@/modules/InventoryCost/types/InventoryCost.types';
|
||||
import { SaleInvoiceCostGLEntries } from '../SaleInvoiceCostGLEntries';
|
||||
|
||||
// @Service()
|
||||
// export class InvoiceCostGLEntriesSubscriber {
|
||||
// @Inject()
|
||||
// invoiceCostEntries: SaleInvoiceCostGLEntries;
|
||||
@Injectable()
|
||||
export class InvoiceCostGLEntriesSubscriber {
|
||||
constructor(private readonly invoiceCostEntries: SaleInvoiceCostGLEntries) {}
|
||||
|
||||
// /**
|
||||
// * Attaches events.
|
||||
// */
|
||||
// public attach(bus) {
|
||||
// bus.subscribe(
|
||||
// events.inventory.onCostLotsGLEntriesWrite,
|
||||
// this.writeInvoicesCostEntriesOnCostLotsWritten
|
||||
// );
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Writes the invoices cost GL entries once the inventory cost lots be written.
|
||||
// * @param {IInventoryCostLotsGLEntriesWriteEvent}
|
||||
// */
|
||||
// private writeInvoicesCostEntriesOnCostLotsWritten = async ({
|
||||
// trx,
|
||||
// startingDate,
|
||||
// tenantId,
|
||||
// }: IInventoryCostLotsGLEntriesWriteEvent) => {
|
||||
// await this.invoiceCostEntries.writeInventoryCostJournalEntries(
|
||||
// tenantId,
|
||||
// startingDate,
|
||||
// trx
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Writes the invoices cost GL entries once the inventory cost lots be written.
|
||||
* @param {IInventoryCostLotsGLEntriesWriteEvent}
|
||||
*/
|
||||
async writeInvoicesCostEntriesOnCostLotsWritten({
|
||||
trx,
|
||||
startingDate,
|
||||
}: IInventoryCostLotsGLEntriesWriteEvent) {
|
||||
await this.invoiceCostEntries.writeInventoryCostJournalEntries(
|
||||
startingDate,
|
||||
trx,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,37 +1,27 @@
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import events from '@/subscribers/events';
|
||||
// import { ISaleInvoiceEditingPayload } from '@/interfaces';
|
||||
// import { InvoicePaymentsGLEntriesRewrite } from '../InvoicePaymentsGLRewrite';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { events } from '@/common/events/events';
|
||||
import { ISaleInvoiceEditingPayload } from '../SaleInvoice.types';
|
||||
import { InvoicePaymentsGLEntriesRewrite } from '../InvoicePaymentsGLRewrite';
|
||||
|
||||
// @Service()
|
||||
// export class InvoicePaymentGLRewriteSubscriber {
|
||||
// @Inject()
|
||||
// private invoicePaymentsRewriteGLEntries: InvoicePaymentsGLEntriesRewrite;
|
||||
@Injectable()
|
||||
export class InvoicePaymentGLRewriteSubscriber {
|
||||
constructor(
|
||||
private readonly invoicePaymentsRewriteGLEntries: InvoicePaymentsGLEntriesRewrite,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// public attach = (bus) => {
|
||||
// bus.subscribe(
|
||||
// events.saleInvoice.onEdited,
|
||||
// this.paymentGLEntriesRewriteOnPaymentEdit
|
||||
// );
|
||||
// return bus;
|
||||
// };
|
||||
|
||||
// /**
|
||||
// * Writes associated invoiceso of payment receive once edit.
|
||||
// * @param {ISaleInvoiceEditingPayload} -
|
||||
// */
|
||||
// private paymentGLEntriesRewriteOnPaymentEdit = async ({
|
||||
// tenantId,
|
||||
// oldSaleInvoice,
|
||||
// trx,
|
||||
// }: ISaleInvoiceEditingPayload) => {
|
||||
// await this.invoicePaymentsRewriteGLEntries.invoicePaymentsGLEntriesRewrite(
|
||||
// tenantId,
|
||||
// oldSaleInvoice.id,
|
||||
// trx
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Writes associated invoiceso of payment receive once edit.
|
||||
* @param {ISaleInvoiceEditingPayload} -
|
||||
*/
|
||||
@OnEvent(events.saleInvoice.onEdited)
|
||||
async paymentGLEntriesRewriteOnPaymentEdit({
|
||||
oldSaleInvoice,
|
||||
trx,
|
||||
}: ISaleInvoiceEditingPayload) {
|
||||
await this.invoicePaymentsRewriteGLEntries.invoicePaymentsGLEntriesRewrite(
|
||||
oldSaleInvoice.id,
|
||||
trx,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,93 +1,75 @@
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import { omit } from 'lodash';
|
||||
// import events from '@/subscribers/events';
|
||||
// import {
|
||||
// ISaleInvoiceCreatedPayload,
|
||||
// ISaleInvoiceDeletingPayload,
|
||||
// PaymentIntegrationTransactionLink,
|
||||
// PaymentIntegrationTransactionLinkDeleteEventPayload,
|
||||
// PaymentIntegrationTransactionLinkEventPayload,
|
||||
// } from '@/interfaces';
|
||||
// import { EventPublisher } from '@/lib/EventPublisher/EventPublisher';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { EventEmitter2, OnEvent } from '@nestjs/event-emitter';
|
||||
import { PaymentIntegrationTransactionLinkDeleteEventPayload } from '../SaleInvoice.types';
|
||||
import { PaymentIntegrationTransactionLinkEventPayload } from '../SaleInvoice.types';
|
||||
import { PaymentIntegrationTransactionLink } from '../SaleInvoice.types';
|
||||
import { omit } from 'lodash';
|
||||
import {
|
||||
ISaleInvoiceCreatedPayload,
|
||||
ISaleInvoiceDeletingPayload,
|
||||
} from '../SaleInvoice.types';
|
||||
import { events } from '@/common/events/events';
|
||||
|
||||
// @Service()
|
||||
// export class InvoicePaymentIntegrationSubscriber {
|
||||
// @Inject()
|
||||
// private eventPublisher: EventPublisher;
|
||||
@Injectable()
|
||||
export class InvoicePaymentIntegrationSubscriber {
|
||||
constructor(private readonly eventPublisher: EventEmitter2) {}
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// public attach = (bus) => {
|
||||
// bus.subscribe(
|
||||
// events.saleInvoice.onCreated,
|
||||
// this.handleCreatePaymentIntegrationEvents
|
||||
// );
|
||||
// bus.subscribe(
|
||||
// events.saleInvoice.onDeleting,
|
||||
// this.handleCreatePaymentIntegrationEventsOnDeleteInvoice
|
||||
// );
|
||||
// return bus;
|
||||
// };
|
||||
/**
|
||||
* Handles the creation of payment integration events when a sale invoice is created.
|
||||
* This method filters enabled payment methods from the invoice and emits a payment
|
||||
* integration link event for each method.
|
||||
* @param {ISaleInvoiceCreatedPayload} payload - The payload containing sale invoice creation details.
|
||||
*/
|
||||
@OnEvent(events.saleInvoice.onCreated)
|
||||
public handleCreatePaymentIntegrationEvents({
|
||||
saleInvoiceDTO,
|
||||
saleInvoice,
|
||||
trx,
|
||||
}: ISaleInvoiceCreatedPayload) {
|
||||
const paymentMethods =
|
||||
saleInvoice.paymentMethods?.filter((method) => method.enable) || [];
|
||||
|
||||
// /**
|
||||
// * Handles the creation of payment integration events when a sale invoice is created.
|
||||
// * This method filters enabled payment methods from the invoice and emits a payment
|
||||
// * integration link event for each method.
|
||||
// * @param {ISaleInvoiceCreatedPayload} payload - The payload containing sale invoice creation details.
|
||||
// */
|
||||
// private handleCreatePaymentIntegrationEvents = ({
|
||||
// tenantId,
|
||||
// saleInvoiceDTO,
|
||||
// saleInvoice,
|
||||
// trx,
|
||||
// }: ISaleInvoiceCreatedPayload) => {
|
||||
// const paymentMethods =
|
||||
// saleInvoice.paymentMethods?.filter((method) => method.enable) || [];
|
||||
paymentMethods.map(
|
||||
async (paymentMethod: PaymentIntegrationTransactionLink) => {
|
||||
const payload = {
|
||||
...omit(paymentMethod, ['id']),
|
||||
saleInvoiceId: saleInvoice.id,
|
||||
trx,
|
||||
};
|
||||
await this.eventPublisher.emitAsync(
|
||||
events.paymentIntegrationLink.onPaymentIntegrationLink,
|
||||
payload as PaymentIntegrationTransactionLinkEventPayload,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// paymentMethods.map(
|
||||
// async (paymentMethod: PaymentIntegrationTransactionLink) => {
|
||||
// const payload = {
|
||||
// ...omit(paymentMethod, ['id']),
|
||||
// tenantId,
|
||||
// saleInvoiceId: saleInvoice.id,
|
||||
// trx,
|
||||
// };
|
||||
// await this.eventPublisher.emitAsync(
|
||||
// events.paymentIntegrationLink.onPaymentIntegrationLink,
|
||||
// payload as PaymentIntegrationTransactionLinkEventPayload
|
||||
// );
|
||||
// }
|
||||
// );
|
||||
// };
|
||||
/**
|
||||
*
|
||||
* @param {ISaleInvoiceDeletingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.saleInvoice.onDeleting)
|
||||
public handleCreatePaymentIntegrationEventsOnDeleteInvoice({
|
||||
oldSaleInvoice,
|
||||
trx,
|
||||
}: ISaleInvoiceDeletingPayload) {
|
||||
const paymentMethods =
|
||||
oldSaleInvoice.paymentMethods?.filter((method) => method.enable) || [];
|
||||
|
||||
// /**
|
||||
// *
|
||||
// * @param {ISaleInvoiceDeletingPayload} payload
|
||||
// */
|
||||
// private handleCreatePaymentIntegrationEventsOnDeleteInvoice = ({
|
||||
// tenantId,
|
||||
// oldSaleInvoice,
|
||||
// trx,
|
||||
// }: ISaleInvoiceDeletingPayload) => {
|
||||
// const paymentMethods =
|
||||
// oldSaleInvoice.paymentMethods?.filter((method) => method.enable) || [];
|
||||
paymentMethods.map(
|
||||
async (paymentMethod: PaymentIntegrationTransactionLink) => {
|
||||
const payload = {
|
||||
...omit(paymentMethod, ['id']),
|
||||
oldSaleInvoiceId: oldSaleInvoice.id,
|
||||
trx,
|
||||
} as PaymentIntegrationTransactionLinkDeleteEventPayload;
|
||||
|
||||
// paymentMethods.map(
|
||||
// async (paymentMethod: PaymentIntegrationTransactionLink) => {
|
||||
// const payload = {
|
||||
// ...omit(paymentMethod, ['id']),
|
||||
// tenantId,
|
||||
// oldSaleInvoiceId: oldSaleInvoice.id,
|
||||
// trx,
|
||||
// } as PaymentIntegrationTransactionLinkDeleteEventPayload;
|
||||
|
||||
// // Triggers `onPaymentIntegrationDeleteLink` event.
|
||||
// await this.eventPublisher.emitAsync(
|
||||
// events.paymentIntegrationLink.onPaymentIntegrationDeleteLink,
|
||||
// payload
|
||||
// );
|
||||
// }
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
// Triggers `onPaymentIntegrationDeleteLink` event.
|
||||
await this.eventPublisher.emitAsync(
|
||||
events.paymentIntegrationLink.onPaymentIntegrationDeleteLink,
|
||||
payload,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { Body, Controller, Get, Injectable, Post } from '@nestjs/common';
|
||||
import { StripePaymentApplication } from './StripePaymentApplication';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
|
||||
@Controller('/stripe')
|
||||
@ApiTags('stripe')
|
||||
export class StripeIntegrationController {
|
||||
constructor(private readonly stripePaymentApp: StripePaymentApplication) {}
|
||||
|
||||
|
||||
@@ -35,6 +35,8 @@ export class ItemEntry extends BaseModel {
|
||||
|
||||
public taxRateId: number;
|
||||
|
||||
public warehouseId: number;
|
||||
|
||||
item: Item;
|
||||
allocatedCostEntries: BillLandedCostEntry[];
|
||||
|
||||
|
||||
@@ -44,8 +44,7 @@ export class QueryTransactionsLocking {
|
||||
|
||||
/**
|
||||
* Retrieve the transactions locking module meta.
|
||||
* @param {number} tenantId -
|
||||
* @param {TransactionsLockingGroup} module -
|
||||
* @param {TransactionsLockingGroup} module -
|
||||
* @returns {ITransactionLockingMetaPOJO}
|
||||
*/
|
||||
public getTransactionsLockingModuleMeta = (
|
||||
|
||||
@@ -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 { AccountTransaction } from '../Accounts/models/AccountTransaction.model';
|
||||
import { TenantModelProxy } from '../System/models/TenantBaseModel';
|
||||
|
||||
// @Service()
|
||||
// export class InventoryTransactionsWarehouses {
|
||||
// @Inject()
|
||||
// tenancy: HasTenancyService;
|
||||
|
||||
// /**
|
||||
// * Updates all accounts transctions with the priamry branch.
|
||||
// * @param tenantId
|
||||
// * @param primaryBranchId
|
||||
// */
|
||||
// public updateTransactionsWithWarehouse = async (
|
||||
// tenantId: number,
|
||||
// primaryBranchId: number,
|
||||
// trx?: Knex.Transaction
|
||||
// ) => {
|
||||
// const { AccountTransaction } = await this.tenancy.models(tenantId);
|
||||
|
||||
// await AccountTransaction.query(trx).update({
|
||||
// branchId: primaryBranchId,
|
||||
// });
|
||||
// };
|
||||
// }
|
||||
@Injectable()
|
||||
export class InventoryTransactionsWarehouses {
|
||||
constructor(
|
||||
private readonly accountTransactionModel: TenantModelProxy<typeof AccountTransaction>,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Updates all accounts transctions with the priamry branch.
|
||||
* @param {number} primaryBranchId - The primary branch id.
|
||||
*/
|
||||
public updateTransactionsWithWarehouse = async (
|
||||
primaryBranchId: number,
|
||||
trx?: Knex.Transaction
|
||||
) => {
|
||||
await this.accountTransactionModel().query(trx).update({
|
||||
branchId: primaryBranchId,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,38 +1,28 @@
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import events from '@/subscribers/events';
|
||||
// import { InventoryTransactionsWarehouses } from './AccountsTransactionsWarehouses';
|
||||
// import { IBranchesActivatedPayload } from '@/interfaces';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InventoryTransactionsWarehouses } from './AccountsTransactionsWarehouses';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { IBranchesActivatedPayload } from '../Branches/Branches.types';
|
||||
import { events } from '@/common/events/events';
|
||||
|
||||
// @Service()
|
||||
// export class AccountsTransactionsWarehousesSubscribe {
|
||||
// @Inject()
|
||||
// accountsTransactionsWarehouses: InventoryTransactionsWarehouses;
|
||||
@Injectable()
|
||||
export class AccountsTransactionsWarehousesSubscribe {
|
||||
constructor(
|
||||
private readonly accountsTransactionsWarehouses: InventoryTransactionsWarehouses,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// public attach = (bus) => {
|
||||
// bus.subscribe(
|
||||
// events.branch.onActivated,
|
||||
// this.updateGLTransactionsToPrimaryBranchOnActivated
|
||||
// );
|
||||
// return bus;
|
||||
// };
|
||||
|
||||
// /**
|
||||
// * Updates all GL transactions to primary branch once
|
||||
// * the multi-branches activated.
|
||||
// * @param {IBranchesActivatedPayload}
|
||||
// */
|
||||
// private updateGLTransactionsToPrimaryBranchOnActivated = async ({
|
||||
// tenantId,
|
||||
// primaryBranch,
|
||||
// trx,
|
||||
// }: IBranchesActivatedPayload) => {
|
||||
// await this.accountsTransactionsWarehouses.updateTransactionsWithWarehouse(
|
||||
// tenantId,
|
||||
// primaryBranch.id,
|
||||
// trx
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Updates all GL transactions to primary branch once
|
||||
* the multi-branches activated.
|
||||
* @param {IBranchesActivatedPayload}
|
||||
*/
|
||||
@OnEvent(events.branch.onActivated)
|
||||
async updateGLTransactionsToPrimaryBranchOnActivated({
|
||||
primaryBranch,
|
||||
trx,
|
||||
}: IBranchesActivatedPayload) {
|
||||
await this.accountsTransactionsWarehouses.updateTransactionsWithWarehouse(
|
||||
primaryBranch.id,
|
||||
trx,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,30 +1,34 @@
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import { IWarehouse } from '@/interfaces';
|
||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { Warehouse } from "../models/Warehouse.model";
|
||||
import { TenantModelProxy } from "@/modules/System/models/TenantBaseModel";
|
||||
import { Bill } from "@/modules/Bills/models/Bill";
|
||||
import { ItemEntry } from "@/modules/TransactionItemEntry/models/ItemEntry";
|
||||
|
||||
// @Service()
|
||||
// export class BillActivateWarehouses {
|
||||
// @Inject()
|
||||
// tenancy: HasTenancyService;
|
||||
@Injectable()
|
||||
export class BillActivateWarehouses {
|
||||
constructor(
|
||||
private readonly billModel: TenantModelProxy<typeof Bill>,
|
||||
private readonly itemEntryModel: TenantModelProxy<typeof ItemEntry>,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Updates all credit note transactions with the primary warehouse.
|
||||
// * @param {number} tenantId
|
||||
// * @param {number} primaryWarehouse
|
||||
// * @returns {Promise<void>}
|
||||
// */
|
||||
// public updateBillsWithWarehouse = async (
|
||||
// tenantId: number,
|
||||
// primaryWarehouse: IWarehouse
|
||||
// ): Promise<void> => {
|
||||
// const { Bill, ItemEntry } = this.tenancy.models(tenantId);
|
||||
|
||||
// // Updates the sale estimates with primary warehouse.
|
||||
// await Bill.query().update({ warehouseId: primaryWarehouse.id });
|
||||
|
||||
// // Update the sale estimates entries with primary warehouse.
|
||||
// await ItemEntry.query().where('referenceType', 'Bill').update({
|
||||
// warehouseId: primaryWarehouse.id,
|
||||
// });
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Updates all credit note transactions with the primary warehouse.
|
||||
* @param {Warehouse} primaryWarehouse
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public updateBillsWithWarehouse = async (
|
||||
primaryWarehouse: Warehouse
|
||||
): Promise<void> => {
|
||||
// Updates the sale estimates with primary warehouse.
|
||||
await this.billModel().query().update({
|
||||
warehouseId: primaryWarehouse.id,
|
||||
});
|
||||
// Update the sale estimates entries with primary warehouse.
|
||||
await this.itemEntryModel()
|
||||
.query()
|
||||
.where('referenceType', 'Bill')
|
||||
.update({
|
||||
warehouseId: primaryWarehouse.id,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,30 +1,34 @@
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import { IWarehouse } from '@/interfaces';
|
||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||
import { ItemEntry } from '@/modules/TransactionItemEntry/models/ItemEntry';
|
||||
import { CreditNote } from '@/modules/CreditNotes/models/CreditNote';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Warehouse } from '../models/Warehouse.model';
|
||||
|
||||
// @Service()
|
||||
// export class CreditNotesActivateWarehouses {
|
||||
// @Inject()
|
||||
// tenancy: HasTenancyService;
|
||||
@Injectable()
|
||||
export class CreditNotesActivateWarehouses {
|
||||
constructor(
|
||||
private readonly creditNoteModel: TenantModelProxy<typeof CreditNote>,
|
||||
private readonly itemEntryModel: TenantModelProxy<typeof ItemEntry>,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Updates all credit note transactions with the primary warehouse.
|
||||
// * @param {number} tenantId
|
||||
// * @param {number} primaryWarehouse
|
||||
// * @returns {Promise<void>}
|
||||
// */
|
||||
// public updateCreditsWithWarehouse = async (
|
||||
// tenantId: number,
|
||||
// primaryWarehouse: IWarehouse
|
||||
// ): Promise<void> => {
|
||||
// const { CreditNote, ItemEntry } = this.tenancy.models(tenantId);
|
||||
|
||||
// // Updates the sale estimates with primary warehouse.
|
||||
// await CreditNote.query().update({ warehouseId: primaryWarehouse.id });
|
||||
|
||||
// // Update the sale estimates entries with primary warehouse.
|
||||
// await ItemEntry.query().where('referenceType', 'CreditNote').update({
|
||||
// warehouseId: primaryWarehouse.id,
|
||||
// });
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Updates all credit note transactions with the primary warehouse.
|
||||
* @param {Warehouse} primaryWarehouse
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public updateCreditsWithWarehouse = async (
|
||||
primaryWarehouse: Warehouse
|
||||
): Promise<void> => {
|
||||
// Updates the sale estimates with primary warehouse.
|
||||
await this.creditNoteModel().query().update({
|
||||
warehouseId: primaryWarehouse.id,
|
||||
});
|
||||
// Update the sale estimates entries with primary warehouse.
|
||||
await this.itemEntryModel()
|
||||
.query()
|
||||
.where('referenceType', 'CreditNote')
|
||||
.update({
|
||||
warehouseId: primaryWarehouse.id,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,30 +1,35 @@
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import { IWarehouse } from '@/interfaces';
|
||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { ItemEntry } from '@/modules/TransactionItemEntry/models/ItemEntry';
|
||||
import { SaleEstimate } from '@/modules/SaleEstimates/models/SaleEstimate';
|
||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Warehouse } from '../models/Warehouse.model';
|
||||
|
||||
// @Service()
|
||||
// export class EstimatesActivateWarehouses {
|
||||
// @Inject()
|
||||
// tenancy: HasTenancyService;
|
||||
@Injectable()
|
||||
export class EstimatesActivateWarehouses {
|
||||
constructor(
|
||||
private readonly saleEstimateModel: TenantModelProxy<typeof SaleEstimate>,
|
||||
private readonly itemEntryModel: TenantModelProxy<typeof ItemEntry>,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Updates all inventory transactions with the primary warehouse.
|
||||
// * @param {number} tenantId
|
||||
// * @param {number} primaryWarehouse
|
||||
// * @returns {Promise<void>}
|
||||
// */
|
||||
// public updateEstimatesWithWarehouse = async (
|
||||
// tenantId: number,
|
||||
// primaryWarehouse: IWarehouse
|
||||
// ): Promise<void> => {
|
||||
// const { SaleEstimate, ItemEntry } = this.tenancy.models(tenantId);
|
||||
/**
|
||||
* Updates all inventory transactions with the primary warehouse.
|
||||
* @param {Warehouse} primaryWarehouse
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public updateEstimatesWithWarehouse = async (
|
||||
primaryWarehouse: Warehouse,
|
||||
): Promise<void> => {
|
||||
// Updates the sale estimates with primary warehouse.
|
||||
await this.saleEstimateModel()
|
||||
.query()
|
||||
.update({ warehouseId: primaryWarehouse.id });
|
||||
|
||||
// // Updates the sale estimates with primary warehouse.
|
||||
// await SaleEstimate.query().update({ warehouseId: primaryWarehouse.id });
|
||||
|
||||
// // Update the sale estimates entries with primary warehouse.
|
||||
// await ItemEntry.query().where('referenceType', 'SaleEstimate').update({
|
||||
// warehouseId: primaryWarehouse.id,
|
||||
// });
|
||||
// };
|
||||
// }
|
||||
// Update the sale estimates entries with primary warehouse.
|
||||
await this.itemEntryModel()
|
||||
.query()
|
||||
.where('referenceType', 'SaleEstimate')
|
||||
.update({
|
||||
warehouseId: primaryWarehouse.id,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import { IWarehouse } from '@/interfaces';
|
||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { InventoryTransaction } from "@/modules/InventoryCost/models/InventoryTransaction";
|
||||
import { TenantModelProxy } from "@/modules/System/models/TenantBaseModel";
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { Warehouse } from "../models/Warehouse.model";
|
||||
import { InventoryCostLotTracker } from "@/modules/InventoryCost/models/InventoryCostLotTracker";
|
||||
|
||||
// @Service()
|
||||
// export class InventoryActivateWarehouses {
|
||||
// @Inject()
|
||||
// tenancy: HasTenancyService;
|
||||
@Injectable()
|
||||
export class InventoryActivateWarehouses {
|
||||
constructor(
|
||||
private readonly inventoryTransactionModel: TenantModelProxy<typeof InventoryTransaction>,
|
||||
private readonly inventoryCostLotTrackerModel: TenantModelProxy<typeof InventoryCostLotTracker>,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Updates all inventory transactions with the primary warehouse.
|
||||
// * @param {number} tenantId
|
||||
// * @param {number} primaryWarehouse
|
||||
// * @returns {Promise<void>}
|
||||
// */
|
||||
// public updateInventoryTransactionsWithWarehouse = async (
|
||||
// tenantId: number,
|
||||
// primaryWarehouse: IWarehouse
|
||||
// ): Promise<void> => {
|
||||
// const { InventoryTransaction, InventoryCostLotTracker } =
|
||||
// this.tenancy.models(tenantId);
|
||||
|
||||
// // Updates the inventory transactions with primary warehouse.
|
||||
// await InventoryTransaction.query().update({
|
||||
// warehouseId: primaryWarehouse.id,
|
||||
// });
|
||||
// await InventoryCostLotTracker.query().update({
|
||||
// warehouseId: primaryWarehouse.id,
|
||||
// });
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Updates all inventory transactions with the primary warehouse.
|
||||
* @param {number} tenantId
|
||||
* @param {number} primaryWarehouse
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public updateInventoryTransactionsWithWarehouse = async (
|
||||
primaryWarehouse: Warehouse
|
||||
): Promise<void> => {
|
||||
// Updates the inventory transactions with primary warehouse.
|
||||
await this.inventoryTransactionModel().query().update({
|
||||
warehouseId: primaryWarehouse.id,
|
||||
});
|
||||
await this.inventoryCostLotTrackerModel().query().update({
|
||||
warehouseId: primaryWarehouse.id,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,30 +1,36 @@
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import { IWarehouse } from '@/interfaces';
|
||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { Warehouse } from "../models/Warehouse.model";
|
||||
import { SaleInvoice } from "@/modules/SaleInvoices/models/SaleInvoice";
|
||||
import { ItemEntry } from "@/modules/TransactionItemEntry/models/ItemEntry";
|
||||
import { TenantModelProxy } from "@/modules/System/models/TenantBaseModel";
|
||||
|
||||
// @Service()
|
||||
// export class InvoicesActivateWarehouses {
|
||||
// @Inject()
|
||||
// tenancy: HasTenancyService;
|
||||
@Injectable()
|
||||
export class InvoicesActivateWarehouses {
|
||||
constructor(
|
||||
private readonly saleInvoiceModel: TenantModelProxy<typeof SaleInvoice>,
|
||||
private readonly itemEntryModel: TenantModelProxy<typeof ItemEntry>,
|
||||
) {}
|
||||
|
||||
|
||||
// /**
|
||||
// * Updates all inventory transactions with the primary warehouse.
|
||||
// * @param {number} tenantId
|
||||
// * @param {number} primaryWarehouse
|
||||
// * @returns {Promise<void>}
|
||||
// */
|
||||
// public updateInvoicesWithWarehouse = async (
|
||||
// tenantId: number,
|
||||
// primaryWarehouse: IWarehouse
|
||||
// ): Promise<void> => {
|
||||
// const { SaleInvoice, ItemEntry } = this.tenancy.models(tenantId);
|
||||
/**
|
||||
* Updates all inventory transactions with the primary warehouse.
|
||||
* @param {Warehouse} primaryWarehouse
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
updateInvoicesWithWarehouse = async (
|
||||
primaryWarehouse: Warehouse
|
||||
): Promise<void> => {
|
||||
// Updates the sale invoices with primary warehouse.
|
||||
await this.saleInvoiceModel().query().update({
|
||||
warehouseId: primaryWarehouse.id,
|
||||
});
|
||||
|
||||
// // Updates the sale invoices with primary warehouse.
|
||||
// await SaleInvoice.query().update({ warehouseId: primaryWarehouse.id });
|
||||
|
||||
// // Update the sale invoices entries with primary warehouse.
|
||||
// await ItemEntry.query().where('referenceType', 'SaleInvoice').update({
|
||||
// warehouseId: primaryWarehouse.id,
|
||||
// });
|
||||
// };
|
||||
// }
|
||||
// Update the sale invoices entries with primary warehouse.
|
||||
await this.itemEntryModel()
|
||||
.query()
|
||||
.where('referenceType', 'SaleInvoice')
|
||||
.update({
|
||||
warehouseId: primaryWarehouse.id,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,30 +1,34 @@
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import { IWarehouse } from '@/interfaces';
|
||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||
import { ItemEntry } from '@/modules/TransactionItemEntry/models/ItemEntry';
|
||||
import { Warehouse } from '../models/Warehouse.model';
|
||||
import { SaleReceipt } from '@/modules/SaleReceipts/models/SaleReceipt';
|
||||
|
||||
// @Service()
|
||||
// export class ReceiptActivateWarehouses {
|
||||
// @Inject()
|
||||
// tenancy: HasTenancyService;
|
||||
@Injectable()
|
||||
export class ReceiptActivateWarehouses {
|
||||
constructor(
|
||||
private readonly saleReceiptModel: TenantModelProxy<typeof SaleReceipt>,
|
||||
private readonly itemEntryModel: TenantModelProxy<typeof ItemEntry>,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Updates all sale receipts transactions with the primary warehouse.
|
||||
// * @param {number} tenantId
|
||||
// * @param {number} primaryWarehouse
|
||||
// * @returns {Promise<void>}
|
||||
// */
|
||||
// public updateReceiptsWithWarehouse = async (
|
||||
// tenantId: number,
|
||||
// primaryWarehouse: IWarehouse
|
||||
// ): Promise<void> => {
|
||||
// const { SaleReceipt, ItemEntry } = this.tenancy.models(tenantId);
|
||||
|
||||
// // Updates the vendor credits transactions with primary warehouse.
|
||||
// await SaleReceipt.query().update({ warehouseId: primaryWarehouse.id });
|
||||
|
||||
// // Update the sale invoices entries with primary warehouse.
|
||||
// await ItemEntry.query().where('referenceType', 'SaleReceipt').update({
|
||||
// warehouseId: primaryWarehouse.id,
|
||||
// });
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Updates all sale receipts transactions with the primary warehouse.
|
||||
* @param {Warehouse} primaryWarehouse
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public updateReceiptsWithWarehouse = async (
|
||||
primaryWarehouse: Warehouse,
|
||||
): Promise<void> => {
|
||||
// Updates the vendor credits transactions with primary warehouse.
|
||||
await this.saleReceiptModel().query().update({
|
||||
warehouseId: primaryWarehouse.id,
|
||||
});
|
||||
// Update the sale invoices entries with primary warehouse.
|
||||
await this.itemEntryModel()
|
||||
.query()
|
||||
.where('referenceType', 'SaleReceipt')
|
||||
.update({
|
||||
warehouseId: primaryWarehouse.id,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,30 +1,35 @@
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import { IWarehouse } from '@/interfaces';
|
||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||
import { VendorCredit } from '@/modules/VendorCredit/models/VendorCredit';
|
||||
import { ItemEntry } from '@/modules/TransactionItemEntry/models/ItemEntry';
|
||||
import { Warehouse } from '../models/Warehouse.model';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
// @Service()
|
||||
// export class VendorCreditActivateWarehouses {
|
||||
// @Inject()
|
||||
// tenancy: HasTenancyService;
|
||||
@Injectable()
|
||||
export class VendorCreditActivateWarehouses {
|
||||
constructor(
|
||||
private readonly vendorCreditModel: TenantModelProxy<typeof VendorCredit>,
|
||||
private readonly itemEntryModel: TenantModelProxy<typeof ItemEntry>,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Updates all vendor credits transactions with the primary warehouse.
|
||||
// * @param {number} tenantId
|
||||
// * @param {number} primaryWarehouse
|
||||
// * @returns {Promise<void>}
|
||||
// */
|
||||
// public updateCreditsWithWarehouse = async (
|
||||
// tenantId: number,
|
||||
// primaryWarehouse: IWarehouse
|
||||
// ): Promise<void> => {
|
||||
// const { VendorCredit, ItemEntry } = this.tenancy.models(tenantId);
|
||||
/**
|
||||
* Updates all vendor credits transactions with the primary warehouse.
|
||||
* @param {Warehouse} primaryWarehouse
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public updateCreditsWithWarehouse = async (
|
||||
primaryWarehouse: Warehouse,
|
||||
): Promise<void> => {
|
||||
// Updates the vendor credits transactions with primary warehouse.
|
||||
await this.vendorCreditModel().query().update({
|
||||
warehouseId: primaryWarehouse.id,
|
||||
});
|
||||
|
||||
// // Updates the vendor credits transactions with primary warehouse.
|
||||
// await VendorCredit.query().update({ warehouseId: primaryWarehouse.id });
|
||||
|
||||
// // Update the sale invoices entries with primary warehouse.
|
||||
// await ItemEntry.query().where('referenceType', 'VendorCredit').update({
|
||||
// warehouseId: primaryWarehouse.id,
|
||||
// });
|
||||
// };
|
||||
// }
|
||||
// Update the sale invoices entries with primary warehouse.
|
||||
await this.itemEntryModel()
|
||||
.query()
|
||||
.where('referenceType', 'VendorCredit')
|
||||
.update({
|
||||
warehouseId: primaryWarehouse.id,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,58 +1,39 @@
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import events from '@/subscribers/events';
|
||||
// import { IWarehousesActivatedPayload } from '@/interfaces';
|
||||
// import { UpdateInventoryTransactionsWithWarehouse } from './UpdateInventoryTransactionsWithWarehouse';
|
||||
// import { CreateInitialWarehousesItemsQuantity } from './CreateInitialWarehousesitemsQuantity';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { events } from '@/common/events/events';
|
||||
import { UpdateInventoryTransactionsWithWarehouse } from './UpdateInventoryTransactionsWithWarehouse';
|
||||
import { CreateInitialWarehousesItemsQuantity } from './CreateInitialWarehousesitemsQuantity';
|
||||
import { IWarehousesActivatedPayload } from './Warehouse.types';
|
||||
|
||||
// @Service()
|
||||
// export class ActivateWarehousesSubscriber {
|
||||
// @Inject()
|
||||
// private updateInventoryTransactionsWithWarehouse: UpdateInventoryTransactionsWithWarehouse;
|
||||
@Injectable()
|
||||
export class ActivateWarehousesSubscriber {
|
||||
constructor(
|
||||
private readonly updateInventoryTransactionsWithWarehouse: UpdateInventoryTransactionsWithWarehouse,
|
||||
private readonly createInitialWarehousesItemsQuantity: CreateInitialWarehousesItemsQuantity,
|
||||
) {}
|
||||
|
||||
// @Inject()
|
||||
// private createInitialWarehousesItemsQuantity: CreateInitialWarehousesItemsQuantity;
|
||||
/**
|
||||
* Updates inventory transactiont to primary warehouse once
|
||||
* multi-warehouses activated.
|
||||
* @param {IWarehousesActivatedPayload}
|
||||
*/
|
||||
@OnEvent(events.warehouse.onActivated)
|
||||
async updateInventoryTransactionsWithWarehouseOnActivating({
|
||||
primaryWarehouse,
|
||||
}: IWarehousesActivatedPayload) {
|
||||
await this.updateInventoryTransactionsWithWarehouse.run(
|
||||
primaryWarehouse.id,
|
||||
);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// attach(bus) {
|
||||
// bus.subscribe(
|
||||
// events.warehouse.onActivated,
|
||||
// this.updateInventoryTransactionsWithWarehouseOnActivating
|
||||
// );
|
||||
// bus.subscribe(
|
||||
// events.warehouse.onActivated,
|
||||
// this.createInitialWarehousesItemsQuantityOnActivating
|
||||
// );
|
||||
// return bus;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Updates inventory transactiont to primary warehouse once
|
||||
// * multi-warehouses activated.
|
||||
// * @param {IWarehousesActivatedPayload}
|
||||
// */
|
||||
// private updateInventoryTransactionsWithWarehouseOnActivating = async ({
|
||||
// tenantId,
|
||||
// primaryWarehouse,
|
||||
// }: IWarehousesActivatedPayload) => {
|
||||
// await this.updateInventoryTransactionsWithWarehouse.run(
|
||||
// tenantId,
|
||||
// primaryWarehouse.id
|
||||
// );
|
||||
// };
|
||||
|
||||
// /**
|
||||
// * Creates initial warehouses items quantity once the multi-warehouses activated.
|
||||
// * @param {IWarehousesActivatedPayload}
|
||||
// */
|
||||
// private createInitialWarehousesItemsQuantityOnActivating = async ({
|
||||
// tenantId,
|
||||
// primaryWarehouse,
|
||||
// }: IWarehousesActivatedPayload) => {
|
||||
// await this.createInitialWarehousesItemsQuantity.run(
|
||||
// tenantId,
|
||||
// primaryWarehouse.id
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Creates initial warehouses items quantity once the multi-warehouses activated.
|
||||
* @param {IWarehousesActivatedPayload}
|
||||
*/
|
||||
@OnEvent(events.warehouse.onActivated)
|
||||
async createInitialWarehousesItemsQuantityOnActivating({
|
||||
primaryWarehouse,
|
||||
}: IWarehousesActivatedPayload) {
|
||||
await this.createInitialWarehousesItemsQuantity.run(primaryWarehouse.id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,57 +1,55 @@
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import { Knex } from 'knex';
|
||||
// import { IItem, IItemWarehouseQuantityChange } from '@/interfaces';
|
||||
// import { WarehousesItemsQuantitySync } from './Integrations/WarehousesItemsQuantitySync';
|
||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { Knex } from 'knex';
|
||||
import { WarehousesItemsQuantitySync } from './Integrations/WarehousesItemsQuantitySync';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { IItemWarehouseQuantityChange } from './Warehouse.types';
|
||||
import { Item } from '../Items/models/Item';
|
||||
import { TenantModelProxy } from '../System/models/TenantBaseModel';
|
||||
|
||||
// @Service()
|
||||
// export class CreateInitialWarehousesItemsQuantity {
|
||||
// @Inject()
|
||||
// private warehousesItemsQuantitySync: WarehousesItemsQuantitySync;
|
||||
@Injectable()
|
||||
export class CreateInitialWarehousesItemsQuantity {
|
||||
constructor(
|
||||
private readonly warehousesItemsQuantitySync: WarehousesItemsQuantitySync,
|
||||
|
||||
// @Inject()
|
||||
// private tenancy: HasTenancyService;
|
||||
@Inject(Item.name)
|
||||
private readonly itemModel: TenantModelProxy<typeof Item>,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Retrieves items warehouses quantity changes of the given inventory items.
|
||||
// * @param {IItem[]} items
|
||||
// * @param {IWarehouse} primaryWarehouse
|
||||
// * @returns {IItemWarehouseQuantityChange[]}
|
||||
// */
|
||||
// private getWarehousesItemsChanges = (
|
||||
// items: IItem[],
|
||||
// primaryWarehouseId: number
|
||||
// ): IItemWarehouseQuantityChange[] => {
|
||||
// return items
|
||||
// .filter((item: IItem) => item.quantityOnHand)
|
||||
// .map((item: IItem) => ({
|
||||
// itemId: item.id,
|
||||
// warehouseId: primaryWarehouseId,
|
||||
// amount: item.quantityOnHand,
|
||||
// }));
|
||||
// };
|
||||
/**
|
||||
* Retrieves items warehouses quantity changes of the given inventory items.
|
||||
* @param {IItem[]} items
|
||||
* @param {IWarehouse} primaryWarehouse
|
||||
* @returns {IItemWarehouseQuantityChange[]}
|
||||
*/
|
||||
private getWarehousesItemsChanges = (
|
||||
items: Item[],
|
||||
primaryWarehouseId: number,
|
||||
): IItemWarehouseQuantityChange[] => {
|
||||
return items
|
||||
.filter((item: Item) => item.quantityOnHand)
|
||||
.map((item: Item) => ({
|
||||
itemId: item.id,
|
||||
warehouseId: primaryWarehouseId,
|
||||
amount: item.quantityOnHand,
|
||||
}));
|
||||
};
|
||||
|
||||
// /**
|
||||
// * Creates initial warehouses items quantity.
|
||||
// * @param {number} tenantId
|
||||
// */
|
||||
// public run = async (
|
||||
// tenantId: number,
|
||||
// primaryWarehouseId: number,
|
||||
// trx?: Knex.Transaction
|
||||
// ): Promise<void> => {
|
||||
// const { Item } = this.tenancy.models(tenantId);
|
||||
/**
|
||||
* Creates initial warehouses items quantity.
|
||||
* @param {number} tenantId
|
||||
*/
|
||||
public run = async (
|
||||
primaryWarehouseId: number,
|
||||
trx?: Knex.Transaction,
|
||||
): Promise<void> => {
|
||||
const items = await this.itemModel().query(trx).where('type', 'Inventory');
|
||||
|
||||
// const items = await Item.query(trx).where('type', 'Inventory');
|
||||
|
||||
// const warehousesChanges = this.getWarehousesItemsChanges(
|
||||
// items,
|
||||
// primaryWarehouseId
|
||||
// );
|
||||
// await this.warehousesItemsQuantitySync.mutateWarehousesItemsQuantity(
|
||||
// tenantId,
|
||||
// warehousesChanges,
|
||||
// trx
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
const warehousesChanges = this.getWarehousesItemsChanges(
|
||||
items,
|
||||
primaryWarehouseId,
|
||||
);
|
||||
await this.warehousesItemsQuantitySync.mutateWarehousesItemsQuantity(
|
||||
warehousesChanges,
|
||||
trx,
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
// import {
|
||||
// BillsActivateWarehousesSubscriber,
|
||||
// CreditsActivateWarehousesSubscriber,
|
||||
// InvoicesActivateWarehousesSubscriber,
|
||||
// ReceiptsActivateWarehousesSubscriber,
|
||||
// EstimatesActivateWarehousesSubscriber,
|
||||
// InventoryActivateWarehousesSubscriber,
|
||||
// VendorCreditsActivateWarehousesSubscriber,
|
||||
// } from './Subscribers/Activate';
|
||||
// import {
|
||||
// BillWarehousesValidateSubscriber,
|
||||
// CreditNoteWarehousesValidateSubscriber,
|
||||
// SaleReceiptWarehousesValidateSubscriber,
|
||||
// SaleEstimateWarehousesValidateSubscriber,
|
||||
// SaleInvoicesWarehousesValidateSubscriber,
|
||||
// VendorCreditWarehousesValidateSubscriber,
|
||||
// InventoryAdjustmentWarehouseValidatorSubscriber,
|
||||
// } from './Subscribers/Validators';
|
||||
// import { DeleteItemWarehousesQuantitySubscriber } from './Subscribers/DeleteItemWarehousesQuantitySubscriber';
|
||||
|
||||
// export default () => [
|
||||
// BillsActivateWarehousesSubscriber,
|
||||
// CreditsActivateWarehousesSubscriber,
|
||||
// InvoicesActivateWarehousesSubscriber,
|
||||
// ReceiptsActivateWarehousesSubscriber,,
|
||||
// EstimatesActivateWarehousesSubscriber,
|
||||
// InventoryActivateWarehousesSubscriber,
|
||||
// VendorCreditsActivateWarehousesSubscriber,
|
||||
|
||||
// BillWarehousesValidateSubscriber,
|
||||
// CreditNoteWarehousesValidateSubscriber,
|
||||
// SaleReceiptWarehousesValidateSubscriber,
|
||||
// SaleEstimateWarehousesValidateSubscriber,
|
||||
// SaleInvoicesWarehousesValidateSubscriber,
|
||||
// VendorCreditWarehousesValidateSubscriber,
|
||||
// InventoryAdjustmentWarehouseValidatorSubscriber,
|
||||
|
||||
// DeleteItemWarehousesQuantitySubscriber,
|
||||
// ];
|
||||
@@ -1,79 +1,73 @@
|
||||
// import { Inject, Service } from 'typedi';
|
||||
// import { chain, difference } from 'lodash';
|
||||
// import { ServiceError } from '@/exceptions';
|
||||
// import { ERRORS } from './constants';
|
||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { chain, difference } from 'lodash';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { ERRORS } from './constants';
|
||||
import { ServiceError } from '@/modules/Items/ServiceError';
|
||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||
import { Warehouse } from '../models/Warehouse.model';
|
||||
|
||||
// @Service()
|
||||
// export class ValidateWarehouseExistance {
|
||||
// @Inject()
|
||||
// tenancy: HasTenancyService;
|
||||
@Injectable()
|
||||
export class ValidateWarehouseExistance {
|
||||
/**
|
||||
* @param {TenantModelProxy<typeof Warehouse>} warehouseModel - Warehouse model.
|
||||
*/
|
||||
constructor(
|
||||
private readonly warehouseModel: TenantModelProxy<typeof Warehouse>,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Validate transaction warehouse id existance.
|
||||
// * @param transDTO
|
||||
// * @param entries
|
||||
// */
|
||||
// public validateWarehouseIdExistance = (
|
||||
// transDTO: { warehouseId?: number },
|
||||
// entries: { warehouseId?: number }[] = []
|
||||
// ) => {
|
||||
// const notAssignedWarehouseEntries = entries.filter((e) => !e.warehouseId);
|
||||
/**
|
||||
* Validate transaction warehouse id existance.
|
||||
* @param transDTO
|
||||
* @param entries
|
||||
*/
|
||||
public validateWarehouseIdExistance = (
|
||||
transDTO: { warehouseId?: number },
|
||||
entries: { warehouseId?: number }[] = [],
|
||||
) => {
|
||||
const notAssignedWarehouseEntries = entries.filter((e) => !e.warehouseId);
|
||||
|
||||
// if (notAssignedWarehouseEntries.length > 0 && !transDTO.warehouseId) {
|
||||
// throw new ServiceError(ERRORS.WAREHOUSE_ID_NOT_FOUND);
|
||||
// }
|
||||
// if (entries.length === 0 && !transDTO.warehouseId) {
|
||||
// throw new ServiceError(ERRORS.WAREHOUSE_ID_NOT_FOUND);
|
||||
// }
|
||||
// };
|
||||
if (notAssignedWarehouseEntries.length > 0 && !transDTO.warehouseId) {
|
||||
throw new ServiceError(ERRORS.WAREHOUSE_ID_NOT_FOUND);
|
||||
}
|
||||
if (entries.length === 0 && !transDTO.warehouseId) {
|
||||
throw new ServiceError(ERRORS.WAREHOUSE_ID_NOT_FOUND);
|
||||
}
|
||||
};
|
||||
|
||||
// /**
|
||||
// * Validate warehouse existance.
|
||||
// * @param {number} tenantId
|
||||
// * @param {number} warehouseId
|
||||
// */
|
||||
// public validateWarehouseExistance = (
|
||||
// tenantId: number,
|
||||
// warehouseId: number
|
||||
// ) => {
|
||||
// const { Warehouse } = this.tenancy.models(tenantId);
|
||||
/**
|
||||
* Validate warehouse existance.
|
||||
* @param {number} warehouseId - Warehouse id.
|
||||
*/
|
||||
public validateWarehouseExistance = (warehouseId: number) => {
|
||||
const warehouse = this.warehouseModel().query().findById(warehouseId);
|
||||
|
||||
// const warehouse = Warehouse.query().findById(warehouseId);
|
||||
if (!warehouse) {
|
||||
throw new ServiceError(ERRORS.WAREHOUSE_ID_NOT_FOUND);
|
||||
}
|
||||
};
|
||||
|
||||
// if (!warehouse) {
|
||||
// throw new ServiceError(ERRORS.WAREHOUSE_ID_NOT_FOUND);
|
||||
// }
|
||||
// };
|
||||
/**
|
||||
* Validate item entries warehouses existance.
|
||||
* @param {{ warehouseId?: number }[]} entries
|
||||
*/
|
||||
public validateItemEntriesWarehousesExistance = async (
|
||||
entries: { warehouseId?: number }[],
|
||||
) => {
|
||||
const entriesWarehousesIds = chain(entries)
|
||||
.filter((e) => !!e.warehouseId)
|
||||
.map((e) => e.warehouseId)
|
||||
.uniq()
|
||||
.value();
|
||||
|
||||
// /**
|
||||
// *
|
||||
// * @param {number} tenantId
|
||||
// * @param {{ warehouseId?: number }[]} entries
|
||||
// */
|
||||
// public validateItemEntriesWarehousesExistance = async (
|
||||
// tenantId: number,
|
||||
// entries: { warehouseId?: number }[]
|
||||
// ) => {
|
||||
// const { Warehouse } = this.tenancy.models(tenantId);
|
||||
|
||||
// const entriesWarehousesIds = chain(entries)
|
||||
// .filter((e) => !!e.warehouseId)
|
||||
// .map((e) => e.warehouseId)
|
||||
// .uniq()
|
||||
// .value();
|
||||
|
||||
// const warehouses = await Warehouse.query().whereIn(
|
||||
// 'id',
|
||||
// entriesWarehousesIds
|
||||
// );
|
||||
// const warehousesIds = warehouses.map((e) => e.id);
|
||||
// const notFoundWarehousesIds = difference(
|
||||
// entriesWarehousesIds,
|
||||
// warehousesIds
|
||||
// );
|
||||
// if (notFoundWarehousesIds.length > 0) {
|
||||
// throw new ServiceError(ERRORS.WAREHOUSE_ID_NOT_FOUND);
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
const warehouses = await this.warehouseModel()
|
||||
.query()
|
||||
.whereIn('id', entriesWarehousesIds);
|
||||
const warehousesIds = warehouses.map((e) => e.id);
|
||||
const notFoundWarehousesIds = difference(
|
||||
entriesWarehousesIds,
|
||||
warehousesIds,
|
||||
);
|
||||
if (notFoundWarehousesIds.length > 0) {
|
||||
throw new ServiceError(ERRORS.WAREHOUSE_ID_NOT_FOUND);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,66 +1,58 @@
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import { isEmpty } from 'lodash';
|
||||
// import { ValidateWarehouseExistance } from './ValidateWarehouseExistance';
|
||||
// import { WarehousesSettings } from '../WarehousesSettings';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { isEmpty } from 'lodash';
|
||||
import { ValidateWarehouseExistance } from './ValidateWarehouseExistance';
|
||||
import { WarehousesSettings } from '../WarehousesSettings';
|
||||
|
||||
// interface IWarehouseTransactionDTO {
|
||||
// warehouseId?: number|null;
|
||||
// entries?: { warehouseId?: number|null }[];
|
||||
// }
|
||||
interface IWarehouseTransactionDTO {
|
||||
warehouseId?: number | null;
|
||||
entries?: { warehouseId?: number | null }[];
|
||||
}
|
||||
|
||||
// @Service()
|
||||
// export class WarehousesDTOValidators {
|
||||
// @Inject()
|
||||
// private validateWarehouseExistanceService: ValidateWarehouseExistance;
|
||||
@Injectable()
|
||||
export class WarehousesDTOValidators {
|
||||
constructor(
|
||||
private readonly validateWarehouseExistanceService: ValidateWarehouseExistance,
|
||||
private readonly warehousesSettings: WarehousesSettings,
|
||||
) {}
|
||||
|
||||
// @Inject()
|
||||
// private warehousesSettings: WarehousesSettings;
|
||||
/**
|
||||
* Validates the warehouse existance of sale invoice transaction.
|
||||
* @param {IWarehouseTransactionDTO} DTO
|
||||
*/
|
||||
public validateDTOWarehouseExistance = async (DTO: IWarehouseTransactionDTO) => {
|
||||
// Validates the sale invoice warehouse id existance.
|
||||
this.validateWarehouseExistanceService.validateWarehouseIdExistance(
|
||||
DTO,
|
||||
DTO.entries,
|
||||
);
|
||||
// Validate the sale invoice warehouse existance on the storage.
|
||||
if (DTO.warehouseId) {
|
||||
this.validateWarehouseExistanceService.validateWarehouseExistance(
|
||||
DTO.warehouseId,
|
||||
);
|
||||
}
|
||||
// Validate the sale invoice entries warehouses existance on the storage.
|
||||
if (!isEmpty(DTO.entries)) {
|
||||
await this.validateWarehouseExistanceService.validateItemEntriesWarehousesExistance(
|
||||
DTO.entries,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
// /**
|
||||
// * Validates the warehouse existance of sale invoice transaction.
|
||||
// * @param {number} tenantId
|
||||
// * @param {ISaleInvoiceCreateDTO | ISaleInvoiceEditDTO} saleInvoiceDTO
|
||||
// */
|
||||
// public validateDTOWarehouseExistance = async (
|
||||
// tenantId: number,
|
||||
// DTO: IWarehouseTransactionDTO
|
||||
// ) => {
|
||||
// // Validates the sale invoice warehouse id existance.
|
||||
// this.validateWarehouseExistanceService.validateWarehouseIdExistance(
|
||||
// DTO,
|
||||
// DTO.entries
|
||||
// );
|
||||
// // Validate the sale invoice warehouse existance on the storage.
|
||||
// if (DTO.warehouseId) {
|
||||
// this.validateWarehouseExistanceService.validateWarehouseExistance(
|
||||
// tenantId,
|
||||
// DTO.warehouseId
|
||||
// );
|
||||
// }
|
||||
// // Validate the sale invoice entries warehouses existance on the storage.
|
||||
// if (!isEmpty(DTO.entries)) {
|
||||
// await this.validateWarehouseExistanceService.validateItemEntriesWarehousesExistance(
|
||||
// tenantId,
|
||||
// DTO.entries
|
||||
// );
|
||||
// }
|
||||
// };
|
||||
/**
|
||||
* Validate the warehouse existance of
|
||||
* @param {number} tenantId
|
||||
* @param {IWarehouseTransactionDTO} saleInvoiceDTO
|
||||
* @returns
|
||||
*/
|
||||
public validateDTOWarehouseWhenActive = async (
|
||||
DTO: IWarehouseTransactionDTO,
|
||||
): Promise<void> => {
|
||||
const isActive = this.warehousesSettings.isMultiWarehousesActive();
|
||||
|
||||
// /**
|
||||
// * Validate the warehouse existance of
|
||||
// * @param {number} tenantId
|
||||
// * @param {IWarehouseTransactionDTO} saleInvoiceDTO
|
||||
// * @returns
|
||||
// */
|
||||
// public validateDTOWarehouseWhenActive = async (
|
||||
// tenantId: number,
|
||||
// DTO: IWarehouseTransactionDTO
|
||||
// ): Promise<void> => {
|
||||
// const isActive = this.warehousesSettings.isMultiWarehousesActive(tenantId);
|
||||
// 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.validateDTOWarehouseExistance(tenantId, DTO);
|
||||
// };
|
||||
// }
|
||||
return this.validateDTOWarehouseExistance(DTO);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,117 +1,115 @@
|
||||
// import {
|
||||
// IInventoryTransaction,
|
||||
// IItemWarehouseQuantityChange,
|
||||
// } from '@/interfaces';
|
||||
// import { set, get, chain, toPairs } from 'lodash';
|
||||
import { IItemWarehouseQuantityChange } from '@/modules/Warehouses/Warehouse.types';
|
||||
import { set, get, chain, toPairs } from 'lodash';
|
||||
import { InventoryTransaction } from '@/modules/InventoryCost/models/InventoryTransaction';
|
||||
|
||||
// export class WarehousesItemsQuantity {
|
||||
// balanceMap: { [warehouseId: number]: { [itemId: number]: number } } = {};
|
||||
// /**
|
||||
// *
|
||||
// * @param {number} warehouseId
|
||||
// * @param {number} itemId
|
||||
// * @returns {number}
|
||||
// */
|
||||
// public get = (warehouseId: number, itemId: number): number => {
|
||||
// return get(this.balanceMap, `${warehouseId}.${itemId}`, 0);
|
||||
// };
|
||||
export class WarehousesItemsQuantity {
|
||||
balanceMap: { [warehouseId: number]: { [itemId: number]: number } } = {};
|
||||
/**
|
||||
*
|
||||
* @param {number} warehouseId
|
||||
* @param {number} itemId
|
||||
* @returns {number}
|
||||
*/
|
||||
public get = (warehouseId: number, itemId: number): number => {
|
||||
return get(this.balanceMap, `${warehouseId}.${itemId}`, 0);
|
||||
};
|
||||
|
||||
// /**
|
||||
// *
|
||||
// * @param {number} warehouseId
|
||||
// * @param {number} itemId
|
||||
// * @param {number} amount
|
||||
// * @returns {WarehousesItemsQuantity}
|
||||
// */
|
||||
// public set = (warehouseId: number, itemId: number, amount: number) => {
|
||||
// if (!get(this.balanceMap, warehouseId)) {
|
||||
// set(this.balanceMap, warehouseId, {});
|
||||
// }
|
||||
// set(this.balanceMap, `${warehouseId}.${itemId}`, amount);
|
||||
/**
|
||||
*
|
||||
* @param {number} warehouseId
|
||||
* @param {number} itemId
|
||||
* @param {number} amount
|
||||
* @returns {WarehousesItemsQuantity}
|
||||
*/
|
||||
public set = (warehouseId: number, itemId: number, amount: number) => {
|
||||
if (!get(this.balanceMap, warehouseId)) {
|
||||
set(this.balanceMap, warehouseId, {});
|
||||
}
|
||||
set(this.balanceMap, `${warehouseId}.${itemId}`, amount);
|
||||
|
||||
// return this;
|
||||
// };
|
||||
return this;
|
||||
};
|
||||
|
||||
// /**
|
||||
// *
|
||||
// * @param {number} warehouseId
|
||||
// * @param {number} itemId
|
||||
// * @param {number} amount
|
||||
// * @returns {WarehousesItemsQuantity}
|
||||
// */
|
||||
// public increment = (warehouseId: number, itemId: number, amount: number) => {
|
||||
// const oldAmount = this.get(warehouseId, itemId);
|
||||
/**
|
||||
*
|
||||
* @param {number} warehouseId
|
||||
* @param {number} itemId
|
||||
* @param {number} amount
|
||||
* @returns {WarehousesItemsQuantity}
|
||||
*/
|
||||
public increment = (warehouseId: number, itemId: number, amount: number) => {
|
||||
const oldAmount = this.get(warehouseId, itemId);
|
||||
|
||||
// return this.set(warehouseId, itemId, oldAmount + amount);
|
||||
// };
|
||||
return this.set(warehouseId, itemId, oldAmount + amount);
|
||||
};
|
||||
|
||||
// /**
|
||||
// *
|
||||
// * @param {number} warehouseId
|
||||
// * @param {number} itemId
|
||||
// * @param {number} amount
|
||||
// * @returns {WarehousesItemsQuantity}
|
||||
// */
|
||||
// public decrement = (warehouseId: number, itemId: number, amount: number) => {
|
||||
// const oldAmount = this.get(warehouseId, itemId);
|
||||
/**
|
||||
*
|
||||
* @param {number} warehouseId
|
||||
* @param {number} itemId
|
||||
* @param {number} amount
|
||||
* @returns {WarehousesItemsQuantity}
|
||||
*/
|
||||
public decrement = (warehouseId: number, itemId: number, amount: number) => {
|
||||
const oldAmount = this.get(warehouseId, itemId);
|
||||
|
||||
// return this.set(warehouseId, itemId, oldAmount - amount);
|
||||
// };
|
||||
return this.set(warehouseId, itemId, oldAmount - amount);
|
||||
};
|
||||
|
||||
// /**
|
||||
// *
|
||||
// * @returns {WarehousesItemsQuantity}
|
||||
// */
|
||||
// public reverse = () => {
|
||||
// const collection = this.toArray();
|
||||
/**
|
||||
*
|
||||
* @returns {WarehousesItemsQuantity}
|
||||
*/
|
||||
public reverse = () => {
|
||||
const collection = this.toArray();
|
||||
|
||||
// collection.forEach((change) => {
|
||||
// this.set(change.warehouseId, change.itemId, change.amount * -1);
|
||||
// });
|
||||
// return this;
|
||||
// };
|
||||
collection.forEach((change) => {
|
||||
this.set(change.warehouseId, change.itemId, change.amount * -1);
|
||||
});
|
||||
return this;
|
||||
};
|
||||
|
||||
// /**
|
||||
// *
|
||||
// * @returns {IItemWarehouseQuantityChange[]}
|
||||
// */
|
||||
// public toArray = (): IItemWarehouseQuantityChange[] => {
|
||||
// return chain(this.balanceMap)
|
||||
// .toPairs()
|
||||
// .map(([warehouseId, item]) => {
|
||||
// const pairs = toPairs(item);
|
||||
/**
|
||||
*
|
||||
* @returns {IItemWarehouseQuantityChange[]}
|
||||
*/
|
||||
public toArray = (): IItemWarehouseQuantityChange[] => {
|
||||
return chain(this.balanceMap)
|
||||
.toPairs()
|
||||
.map(([warehouseId, item]) => {
|
||||
const pairs = toPairs(item);
|
||||
|
||||
// return pairs.map(([itemId, amount]) => ({
|
||||
// itemId: parseInt(itemId),
|
||||
// warehouseId: parseInt(warehouseId),
|
||||
// amount,
|
||||
// }));
|
||||
// })
|
||||
// .flatten()
|
||||
// .value();
|
||||
// };
|
||||
return pairs.map(([itemId, amount]) => ({
|
||||
itemId: parseInt(itemId),
|
||||
warehouseId: parseInt(warehouseId),
|
||||
amount,
|
||||
}));
|
||||
})
|
||||
.flatten()
|
||||
.value();
|
||||
};
|
||||
|
||||
// /**
|
||||
// *
|
||||
// * @param {IInventoryTransaction[]} inventoryTransactions
|
||||
// * @returns {WarehousesItemsQuantity}
|
||||
// */
|
||||
// static fromInventoryTransaction = (
|
||||
// inventoryTransactions: IInventoryTransaction[]
|
||||
// ): WarehousesItemsQuantity => {
|
||||
// const warehouseTransactions = inventoryTransactions.filter(
|
||||
// (transaction) => transaction.warehouseId
|
||||
// );
|
||||
// const warehouseItemsQuantity = new WarehousesItemsQuantity();
|
||||
/**
|
||||
*
|
||||
* @param {IInventoryTransaction[]} inventoryTransactions
|
||||
* @returns {WarehousesItemsQuantity}
|
||||
*/
|
||||
static fromInventoryTransaction = (
|
||||
inventoryTransactions: InventoryTransaction[],
|
||||
): WarehousesItemsQuantity => {
|
||||
const warehouseTransactions = inventoryTransactions.filter(
|
||||
(transaction) => transaction.warehouseId,
|
||||
);
|
||||
const warehouseItemsQuantity = new WarehousesItemsQuantity();
|
||||
|
||||
// warehouseTransactions.forEach((transaction: IInventoryTransaction) => {
|
||||
// const change =
|
||||
// transaction.direction === 'IN'
|
||||
// ? warehouseItemsQuantity.increment
|
||||
// : warehouseItemsQuantity.decrement;
|
||||
warehouseTransactions.forEach((transaction: InventoryTransaction) => {
|
||||
const change =
|
||||
transaction.direction === 'IN'
|
||||
? warehouseItemsQuantity.increment
|
||||
: warehouseItemsQuantity.decrement;
|
||||
|
||||
// change(transaction.warehouseId, transaction.itemId, transaction.quantity);
|
||||
// });
|
||||
// return warehouseItemsQuantity;
|
||||
// };
|
||||
// }
|
||||
change(transaction.warehouseId, transaction.itemId, transaction.quantity);
|
||||
});
|
||||
return warehouseItemsQuantity;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,74 +1,57 @@
|
||||
// import events from '@/subscribers/events';
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import { WarehousesItemsQuantitySync } from './WarehousesItemsQuantitySync';
|
||||
// import {
|
||||
// IInventoryTransactionsCreatedPayload,
|
||||
// IInventoryTransactionsDeletedPayload,
|
||||
// } from '@/interfaces';
|
||||
// import { WarehousesSettings } from '../WarehousesSettings';
|
||||
import { WarehousesItemsQuantitySync } from './WarehousesItemsQuantitySync';
|
||||
import { WarehousesSettings } from '../WarehousesSettings';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { events } from '@/common/events/events';
|
||||
import {
|
||||
IInventoryTransactionsCreatedPayload,
|
||||
IInventoryTransactionsDeletedPayload,
|
||||
} from '@/modules/InventoryCost/types/InventoryCost.types';
|
||||
|
||||
// @Service()
|
||||
// export class WarehousesItemsQuantitySyncSubscriber {
|
||||
// @Inject()
|
||||
// private warehousesItemsQuantitySync: WarehousesItemsQuantitySync;
|
||||
@Injectable()
|
||||
export class WarehousesItemsQuantitySyncSubscriber {
|
||||
constructor(
|
||||
private readonly warehousesItemsQuantitySync: WarehousesItemsQuantitySync,
|
||||
private readonly warehousesSettings: WarehousesSettings,
|
||||
) {}
|
||||
|
||||
// @Inject()
|
||||
// private warehousesSettings: WarehousesSettings;
|
||||
/**
|
||||
* Syncs warehouses items quantity once inventory transactions created.
|
||||
* @param {IInventoryTransactionsCreatedPayload}
|
||||
*/
|
||||
@OnEvent(events.inventory.onInventoryTransactionsCreated)
|
||||
async syncWarehousesItemsQuantityOnInventoryTransCreated({
|
||||
inventoryTransactions,
|
||||
trx,
|
||||
}: IInventoryTransactionsCreatedPayload) {
|
||||
const isActive = this.warehousesSettings.isMultiWarehousesActive();
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// public attach(bus) {
|
||||
// bus.subscribe(
|
||||
// events.inventory.onInventoryTransactionsCreated,
|
||||
// this.syncWarehousesItemsQuantityOnInventoryTransCreated
|
||||
// );
|
||||
// bus.subscribe(
|
||||
// events.inventory.onInventoryTransactionsDeleted,
|
||||
// this.syncWarehousesItemsQuantityOnInventoryTransDeleted
|
||||
// );
|
||||
// return bus;
|
||||
// }
|
||||
// Can't continue if the warehouses features is not active.
|
||||
if (!isActive) return;
|
||||
|
||||
// /**
|
||||
// * Syncs warehouses items quantity once inventory transactions created.
|
||||
// * @param {IInventoryTransactionsCreatedPayload}
|
||||
// */
|
||||
// private syncWarehousesItemsQuantityOnInventoryTransCreated = async ({
|
||||
// tenantId,
|
||||
// inventoryTransactions,
|
||||
// trx,
|
||||
// }: IInventoryTransactionsCreatedPayload) => {
|
||||
// const isActive = this.warehousesSettings.isMultiWarehousesActive(tenantId);
|
||||
await this.warehousesItemsQuantitySync.mutateWarehousesItemsQuantityFromTransactions(
|
||||
inventoryTransactions,
|
||||
trx,
|
||||
);
|
||||
}
|
||||
|
||||
// // Can't continue if the warehouses features is not active.
|
||||
// if (!isActive) return;
|
||||
/**
|
||||
* Syncs warehouses items quantity once inventory transactions deleted.
|
||||
* @param {IInventoryTransactionsDeletedPayload}
|
||||
*/
|
||||
@OnEvent(events.inventory.onInventoryTransactionsDeleted)
|
||||
async syncWarehousesItemsQuantityOnInventoryTransDeleted({
|
||||
oldInventoryTransactions,
|
||||
trx,
|
||||
}: IInventoryTransactionsDeletedPayload) {
|
||||
const isActive = this.warehousesSettings.isMultiWarehousesActive();
|
||||
|
||||
// await this.warehousesItemsQuantitySync.mutateWarehousesItemsQuantityFromTransactions(
|
||||
// tenantId,
|
||||
// inventoryTransactions,
|
||||
// trx
|
||||
// );
|
||||
// };
|
||||
// Can't continue if the warehouses feature is not active yet.
|
||||
if (!isActive) return;
|
||||
|
||||
// /**
|
||||
// * Syncs warehouses items quantity once inventory transactions deleted.
|
||||
// * @param {IInventoryTransactionsDeletedPayload}
|
||||
// */
|
||||
// private syncWarehousesItemsQuantityOnInventoryTransDeleted = async ({
|
||||
// tenantId,
|
||||
// oldInventoryTransactions,
|
||||
// trx,
|
||||
// }: IInventoryTransactionsDeletedPayload) => {
|
||||
// const isActive = this.warehousesSettings.isMultiWarehousesActive(tenantId);
|
||||
|
||||
// // Can't continue if the warehouses feature is not active yet.
|
||||
// if (!isActive) return;
|
||||
|
||||
// await this.warehousesItemsQuantitySync.reverseWarehousesItemsQuantityFromTransactions(
|
||||
// tenantId,
|
||||
// oldInventoryTransactions,
|
||||
// trx
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
await this.warehousesItemsQuantitySync.reverseWarehousesItemsQuantityFromTransactions(
|
||||
oldInventoryTransactions,
|
||||
trx,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,131 +1,128 @@
|
||||
// import { Knex } from 'knex';
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import { omit } from 'lodash';
|
||||
// import {
|
||||
// IInventoryTransaction,
|
||||
// IItemWarehouseQuantityChange,
|
||||
// } from '@/interfaces';
|
||||
// import { WarehousesItemsQuantity } from './WarehousesItemsQuantity';
|
||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { InventoryTransaction } from '@/modules/InventoryCost/models/InventoryTransaction';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Knex } from 'knex';
|
||||
import { omit } from 'lodash';
|
||||
import { IItemWarehouseQuantityChange } from '../Warehouse.types';
|
||||
import { WarehousesItemsQuantity } from './WarehousesItemsQuantity';
|
||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||
import { ItemWarehouseQuantity } from '../models/ItemWarehouseQuantity';
|
||||
|
||||
// @Service()
|
||||
// export class WarehousesItemsQuantitySync {
|
||||
// @Inject()
|
||||
// tenancy: HasTenancyService;
|
||||
@Injectable()
|
||||
export class WarehousesItemsQuantitySync {
|
||||
constructor(
|
||||
private readonly warehouseItemsQuantityModel: WarehousesItemsQuantity,
|
||||
private readonly itemWarehouseQuantityModel: TenantModelProxy<
|
||||
typeof ItemWarehouseQuantity
|
||||
>,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Retrieves the reversed warehouses items quantity changes.
|
||||
// * @param {IInventoryTransaction[]} inventoryTransactions
|
||||
// * @returns {IItemWarehouseQuantityChange[]}
|
||||
// */
|
||||
// public getReverseWarehousesItemsQuantityChanges = (
|
||||
// inventoryTransactions: IInventoryTransaction[]
|
||||
// ): IItemWarehouseQuantityChange[] => {
|
||||
// const warehouseItemsQuantity =
|
||||
// WarehousesItemsQuantity.fromInventoryTransaction(inventoryTransactions);
|
||||
/**
|
||||
* Retrieves the reversed warehouses items quantity changes.
|
||||
* @param {InventoryTransaction[]} inventoryTransactions
|
||||
* @returns {IItemWarehouseQuantityChange[]}
|
||||
*/
|
||||
public getReverseWarehousesItemsQuantityChanges = (
|
||||
inventoryTransactions: InventoryTransaction[],
|
||||
): IItemWarehouseQuantityChange[] => {
|
||||
const warehouseItemsQuantity =
|
||||
WarehousesItemsQuantity.fromInventoryTransaction(inventoryTransactions);
|
||||
|
||||
// return warehouseItemsQuantity.reverse().toArray();
|
||||
// };
|
||||
return warehouseItemsQuantity.reverse().toArray();
|
||||
};
|
||||
|
||||
// /**
|
||||
// * Retrieves the warehouses items changes from the given inventory tranasctions.
|
||||
// * @param {IInventoryTransaction[]} inventoryTransactions
|
||||
// * @returns {IItemWarehouseQuantityChange[]}
|
||||
// */
|
||||
// public getWarehousesItemsQuantityChange = (
|
||||
// inventoryTransactions: IInventoryTransaction[]
|
||||
// ): IItemWarehouseQuantityChange[] => {
|
||||
// const warehouseItemsQuantity =
|
||||
// WarehousesItemsQuantity.fromInventoryTransaction(inventoryTransactions);
|
||||
/**
|
||||
* Retrieves the warehouses items changes from the given inventory tranasctions.
|
||||
* @param {InventoryTransaction[]} inventoryTransactions
|
||||
* @returns {IItemWarehouseQuantityChange[]}
|
||||
*/
|
||||
public getWarehousesItemsQuantityChange = (
|
||||
inventoryTransactions: InventoryTransaction[],
|
||||
): IItemWarehouseQuantityChange[] => {
|
||||
const warehouseItemsQuantity =
|
||||
WarehousesItemsQuantity.fromInventoryTransaction(inventoryTransactions);
|
||||
|
||||
// return warehouseItemsQuantity.toArray();
|
||||
// };
|
||||
return warehouseItemsQuantity.toArray();
|
||||
};
|
||||
|
||||
// /**
|
||||
// * Mutates warehouses items quantity on hand on the storage.
|
||||
// * @param {number} tenantId
|
||||
// * @param {IItemWarehouseQuantityChange[]} warehousesItemsQuantity
|
||||
// * @param {Knex.Transaction} trx
|
||||
// */
|
||||
// public mutateWarehousesItemsQuantity = async (
|
||||
// tenantId: number,
|
||||
// warehousesItemsQuantity: IItemWarehouseQuantityChange[],
|
||||
// trx?: Knex.Transaction
|
||||
// ): Promise<void> => {
|
||||
// const mutationsOpers = warehousesItemsQuantity.map(
|
||||
// (change: IItemWarehouseQuantityChange) =>
|
||||
// this.mutateWarehouseItemQuantity(tenantId, change, trx)
|
||||
// );
|
||||
// await Promise.all(mutationsOpers);
|
||||
// };
|
||||
/**
|
||||
* Mutates warehouses items quantity on hand on the storage.
|
||||
* @param {IItemWarehouseQuantityChange[]} warehousesItemsQuantity
|
||||
* @param {Knex.Transaction} trx
|
||||
*/
|
||||
public mutateWarehousesItemsQuantity = async (
|
||||
warehousesItemsQuantity: IItemWarehouseQuantityChange[],
|
||||
trx?: Knex.Transaction,
|
||||
): Promise<void> => {
|
||||
const mutationsOpers = warehousesItemsQuantity.map(
|
||||
(change: IItemWarehouseQuantityChange) =>
|
||||
this.mutateWarehouseItemQuantity(change, trx),
|
||||
);
|
||||
await Promise.all(mutationsOpers);
|
||||
};
|
||||
|
||||
// /**
|
||||
// * Mutates the warehouse item quantity.
|
||||
// * @param {number} tenantId
|
||||
// * @param {number} warehouseItemQuantity
|
||||
// * @param {Knex.Transaction} trx
|
||||
// */
|
||||
// public mutateWarehouseItemQuantity = async (
|
||||
// tenantId: number,
|
||||
// warehouseItemQuantity: IItemWarehouseQuantityChange,
|
||||
// trx: Knex.Transaction
|
||||
// ): Promise<void> => {
|
||||
// const { ItemWarehouseQuantity } = this.tenancy.models(tenantId);
|
||||
/**
|
||||
* Mutates the warehouse item quantity.
|
||||
* @param {number} warehouseItemQuantity
|
||||
* @param {Knex.Transaction} trx
|
||||
*/
|
||||
public mutateWarehouseItemQuantity = async (
|
||||
warehouseItemQuantity: IItemWarehouseQuantityChange,
|
||||
trx: Knex.Transaction,
|
||||
): Promise<void> => {
|
||||
const itemWarehouseQuantity = await this.itemWarehouseQuantityModel()
|
||||
.query(trx)
|
||||
.where('itemId', warehouseItemQuantity.itemId)
|
||||
.where('warehouseId', warehouseItemQuantity.warehouseId)
|
||||
.first();
|
||||
|
||||
// const itemWarehouseQuantity = await ItemWarehouseQuantity.query(trx)
|
||||
// .where('itemId', warehouseItemQuantity.itemId)
|
||||
// .where('warehouseId', warehouseItemQuantity.warehouseId)
|
||||
// .first();
|
||||
if (itemWarehouseQuantity) {
|
||||
// @ts-ignore
|
||||
await ItemWarehouseQuantity.changeAmount(
|
||||
{
|
||||
itemId: warehouseItemQuantity.itemId,
|
||||
warehouseId: warehouseItemQuantity.warehouseId,
|
||||
},
|
||||
'quantityOnHand',
|
||||
warehouseItemQuantity.amount,
|
||||
trx,
|
||||
);
|
||||
} else {
|
||||
await ItemWarehouseQuantity.query(trx).insert({
|
||||
...omit(warehouseItemQuantity, ['amount']),
|
||||
quantityOnHand: warehouseItemQuantity.amount,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// if (itemWarehouseQuantity) {
|
||||
// await ItemWarehouseQuantity.changeAmount(
|
||||
// {
|
||||
// itemId: warehouseItemQuantity.itemId,
|
||||
// warehouseId: warehouseItemQuantity.warehouseId,
|
||||
// },
|
||||
// 'quantityOnHand',
|
||||
// warehouseItemQuantity.amount,
|
||||
// trx
|
||||
// );
|
||||
// } else {
|
||||
// await ItemWarehouseQuantity.query(trx).insert({
|
||||
// ...omit(warehouseItemQuantity, ['amount']),
|
||||
// quantityOnHand: warehouseItemQuantity.amount,
|
||||
// });
|
||||
// }
|
||||
// };
|
||||
/**
|
||||
* Mutates warehouses items quantity from inventory transactions.
|
||||
* @param {number} tenantId -
|
||||
* @param {IInventoryTransaction[]} inventoryTransactions -
|
||||
* @param {Knex.Transaction}
|
||||
*/
|
||||
public mutateWarehousesItemsQuantityFromTransactions = async (
|
||||
inventoryTransactions: InventoryTransaction[],
|
||||
trx?: Knex.Transaction,
|
||||
) => {
|
||||
const changes = this.getWarehousesItemsQuantityChange(
|
||||
inventoryTransactions,
|
||||
);
|
||||
await this.mutateWarehousesItemsQuantity(changes, trx);
|
||||
};
|
||||
|
||||
// /**
|
||||
// * Mutates warehouses items quantity from inventory transactions.
|
||||
// * @param {number} tenantId -
|
||||
// * @param {IInventoryTransaction[]} inventoryTransactions -
|
||||
// * @param {Knex.Transaction}
|
||||
// */
|
||||
// public mutateWarehousesItemsQuantityFromTransactions = async (
|
||||
// tenantId: number,
|
||||
// inventoryTransactions: IInventoryTransaction[],
|
||||
// trx?: Knex.Transaction
|
||||
// ) => {
|
||||
// const changes = this.getWarehousesItemsQuantityChange(
|
||||
// inventoryTransactions
|
||||
// );
|
||||
// await this.mutateWarehousesItemsQuantity(tenantId, changes, trx);
|
||||
// };
|
||||
|
||||
// /**
|
||||
// * Reverses warehouses items quantity from inventory transactions.
|
||||
// * @param {number} tenantId
|
||||
// * @param {IInventoryTransaction[]} inventoryTransactions
|
||||
// * @param {Knex.Transaction} trx
|
||||
// */
|
||||
// public reverseWarehousesItemsQuantityFromTransactions = async (
|
||||
// tenantId: number,
|
||||
// inventoryTransactions: IInventoryTransaction[],
|
||||
// trx?: Knex.Transaction
|
||||
// ) => {
|
||||
// const changes = this.getReverseWarehousesItemsQuantityChanges(
|
||||
// inventoryTransactions
|
||||
// );
|
||||
// await this.mutateWarehousesItemsQuantity(tenantId, changes, trx);
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Reverses warehouses items quantity from inventory transactions.
|
||||
* @param {number} tenantId
|
||||
* @param {IInventoryTransaction[]} inventoryTransactions
|
||||
* @param {Knex.Transaction} trx
|
||||
*/
|
||||
public reverseWarehousesItemsQuantityFromTransactions = async (
|
||||
inventoryTransactions: InventoryTransaction[],
|
||||
trx?: Knex.Transaction,
|
||||
) => {
|
||||
const changes = this.getReverseWarehousesItemsQuantityChanges(
|
||||
inventoryTransactions,
|
||||
);
|
||||
await this.mutateWarehousesItemsQuantity(changes, trx);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
// import { Service, Inject } from 'typedi';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { TenantModelProxy } from '../System/models/TenantBaseModel';
|
||||
import { InventoryTransaction } from '../InventoryCost/models/InventoryTransaction';
|
||||
|
||||
// @Service()
|
||||
// export class UpdateInventoryTransactionsWithWarehouse {
|
||||
// @Inject()
|
||||
// tenancy: HasTenancyService;
|
||||
@Injectable()
|
||||
export class UpdateInventoryTransactionsWithWarehouse {
|
||||
constructor(
|
||||
@Inject(InventoryTransaction.name)
|
||||
private readonly inventoryTransactionModel: TenantModelProxy<
|
||||
typeof InventoryTransaction
|
||||
>,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Updates all inventory transactions with primary warehouse.
|
||||
// * @param {number} tenantId -
|
||||
// * @param {number} warehouseId -
|
||||
// */
|
||||
// public run = async (tenantId: number, primaryWarehouseId: number) => {
|
||||
// const { InventoryTransaction } = this.tenancy.models(tenantId);
|
||||
|
||||
// await InventoryTransaction.query().update({
|
||||
// warehouseId: primaryWarehouseId,
|
||||
// });
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Updates all inventory transactions with primary warehouse.
|
||||
* @param {number} warehouseId - Warehouse ID.
|
||||
*/
|
||||
public run = async (primaryWarehouseId: number) => {
|
||||
await this.inventoryTransactionModel().query().update({
|
||||
warehouseId: primaryWarehouseId,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Knex } from 'knex';
|
||||
import { Warehouse } from './models/Warehouse.model';
|
||||
|
||||
export interface IWarehouse {
|
||||
id?: number;
|
||||
@@ -168,18 +169,18 @@ export interface IWarehousesActivatePayload {
|
||||
}
|
||||
export interface IWarehousesActivatedPayload {
|
||||
// tenantId: number;
|
||||
primaryWarehouse: IWarehouse;
|
||||
primaryWarehouse: Warehouse;
|
||||
}
|
||||
|
||||
export interface IWarehouseMarkAsPrimaryPayload {
|
||||
// tenantId: number;
|
||||
oldWarehouse: IWarehouse;
|
||||
oldWarehouse: Warehouse;
|
||||
trx: Knex.Transaction;
|
||||
}
|
||||
export interface IWarehouseMarkedAsPrimaryPayload {
|
||||
// tenantId: number;
|
||||
oldWarehouse: IWarehouse;
|
||||
markedWarehouse: IWarehouse;
|
||||
oldWarehouse: Warehouse;
|
||||
markedWarehouse: Warehouse;
|
||||
trx: Knex.Transaction;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,20 @@ import { ActivateWarehousesService } from './commands/ActivateWarehouses.service
|
||||
import { CreateInitialWarehouse } from './commands/CreateInitialWarehouse.service';
|
||||
import { WarehousesSettings } from './WarehousesSettings';
|
||||
import { WarehouseTransactionDTOTransform } from './Integrations/WarehouseTransactionDTOTransform';
|
||||
import { BillsActivateWarehousesSubscriber } from './subscribers/Activate/BillWarehousesActivateSubscriber';
|
||||
import { VendorCreditsActivateWarehousesSubscriber } from './subscribers/Activate/VendorCreditWarehousesActivateSubscriber';
|
||||
import { ReceiptsActivateWarehousesSubscriber } from './subscribers/Activate/ReceiptWarehousesActivateSubscriber';
|
||||
import { InvoicesActivateWarehousesSubscriber } from './subscribers/Activate/InvoiceWarehousesActivateSubscriber';
|
||||
import { CreditsActivateWarehousesSubscriber } from './subscribers/Activate/CreditNoteWarehousesActivateSubscriber';
|
||||
import { InventoryAdjustmentWarehouseValidatorSubscriber } from './subscribers/Validators/InventoryAdjustment/InventoryAdjustmentWarehouseValidatorSubscriber';
|
||||
import { DeleteItemWarehousesQuantitySubscriber } from './subscribers/DeleteItemWarehousesQuantitySubscriber';
|
||||
import { VendorCreditWarehousesValidateSubscriber } from './subscribers/Validators/Purchases/VendorCreditWarehousesSubscriber';
|
||||
import { SaleInvoicesWarehousesValidateSubscriber } from './subscribers/Validators/Sales/SaleInvoicesWarehousesSubscriber';
|
||||
import { SaleEstimateWarehousesValidateSubscriber } from './subscribers/Validators/Sales/SaleEstimateWarehousesSubscriber';
|
||||
import { SaleReceiptWarehousesValidateSubscriber } from './subscribers/Validators/Sales/SaleReceiptWarehousesSubscriber';
|
||||
import { CreditNoteWarehousesValidateSubscriber } from './subscribers/Validators/Sales/CreditNoteWarehousesSubscriber';
|
||||
import { BillWarehousesValidateSubscriber } from './subscribers/Validators/Purchases/BillWarehousesSubscriber';
|
||||
import { AccountsTransactionsWarehousesSubscribe } from './AccountsTransactionsWarehousesSubscribe';
|
||||
|
||||
@Module({
|
||||
imports: [TenancyDatabaseModule],
|
||||
@@ -38,6 +52,20 @@ import { WarehouseTransactionDTOTransform } from './Integrations/WarehouseTransa
|
||||
TenancyContext,
|
||||
TransformerInjectable,
|
||||
WarehouseTransactionDTOTransform,
|
||||
BillsActivateWarehousesSubscriber,
|
||||
CreditsActivateWarehousesSubscriber,
|
||||
InvoicesActivateWarehousesSubscriber,
|
||||
ReceiptsActivateWarehousesSubscriber,
|
||||
VendorCreditsActivateWarehousesSubscriber,
|
||||
InventoryAdjustmentWarehouseValidatorSubscriber,
|
||||
DeleteItemWarehousesQuantitySubscriber,
|
||||
BillWarehousesValidateSubscriber,
|
||||
CreditNoteWarehousesValidateSubscriber,
|
||||
SaleReceiptWarehousesValidateSubscriber,
|
||||
SaleEstimateWarehousesValidateSubscriber,
|
||||
SaleInvoicesWarehousesValidateSubscriber,
|
||||
VendorCreditWarehousesValidateSubscriber,
|
||||
AccountsTransactionsWarehousesSubscribe,
|
||||
],
|
||||
exports: [WarehouseTransactionDTOTransform],
|
||||
})
|
||||
|
||||
@@ -1,36 +1,26 @@
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import { IWarehousesActivatedPayload } from '@/interfaces';
|
||||
// import events from '@/subscribers/events';
|
||||
// import { BillActivateWarehouses } from '../../Activate/BillWarehousesActivate';
|
||||
import { BillActivateWarehouses } from '../../Activate/BillWarehousesActivate';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { events } from '@/common/events/events';
|
||||
import { IWarehousesActivatedPayload } from '../../Warehouse.types';
|
||||
|
||||
// @Service()
|
||||
// export class BillsActivateWarehousesSubscriber {
|
||||
// @Inject()
|
||||
// private billsActivateWarehouses: BillActivateWarehouses;
|
||||
@Injectable()
|
||||
export class BillsActivateWarehousesSubscriber {
|
||||
constructor(
|
||||
private readonly billsActivateWarehouses: BillActivateWarehouses,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// public attach(bus) {
|
||||
// bus.subscribe(
|
||||
// events.warehouse.onActivated,
|
||||
// this.updateBillsWithWarehouseOnActivated
|
||||
// );
|
||||
// return bus;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Updates all inventory transactions with the primary warehouse once
|
||||
// * multi-warehouses feature is activated.
|
||||
// * @param {IWarehousesActivatedPayload}
|
||||
// */
|
||||
// private updateBillsWithWarehouseOnActivated = async ({
|
||||
// tenantId,
|
||||
// primaryWarehouse,
|
||||
// }: IWarehousesActivatedPayload) => {
|
||||
// await this.billsActivateWarehouses.updateBillsWithWarehouse(
|
||||
// tenantId,
|
||||
// primaryWarehouse
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Updates all inventory transactions with the primary warehouse once
|
||||
* multi-warehouses feature is activated.
|
||||
* @param {IWarehousesActivatedPayload}
|
||||
*/
|
||||
@OnEvent(events.warehouse.onActivated)
|
||||
async updateBillsWithWarehouseOnActivated ({
|
||||
primaryWarehouse,
|
||||
}: IWarehousesActivatedPayload) {
|
||||
await this.billsActivateWarehouses.updateBillsWithWarehouse(
|
||||
primaryWarehouse
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,36 +1,26 @@
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import { IWarehousesActivatedPayload } from '@/interfaces';
|
||||
// import events from '@/subscribers/events';
|
||||
// import { CreditNotesActivateWarehouses } from '../../Activate/CreditNoteWarehousesActivate';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { CreditNotesActivateWarehouses } from '../../Activate/CreditNoteWarehousesActivate';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { IWarehousesActivatedPayload } from '../../Warehouse.types';
|
||||
import { events } from '@/common/events/events';
|
||||
|
||||
// @Service()
|
||||
// export class CreditsActivateWarehousesSubscriber {
|
||||
// @Inject()
|
||||
// private creditsActivateWarehouses: CreditNotesActivateWarehouses;
|
||||
@Injectable()
|
||||
export class CreditsActivateWarehousesSubscriber {
|
||||
constructor(
|
||||
private readonly creditsActivateWarehouses: CreditNotesActivateWarehouses,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// public attach(bus) {
|
||||
// bus.subscribe(
|
||||
// events.warehouse.onActivated,
|
||||
// this.updateInvoicesWithWarehouseOnActivated
|
||||
// );
|
||||
// return bus;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Updates all inventory transactions with the primary warehouse once
|
||||
// * multi-warehouses feature is activated.
|
||||
// * @param {IWarehousesActivatedPayload}
|
||||
// */
|
||||
// private updateInvoicesWithWarehouseOnActivated = async ({
|
||||
// tenantId,
|
||||
// primaryWarehouse,
|
||||
// }: IWarehousesActivatedPayload) => {
|
||||
// await this.creditsActivateWarehouses.updateCreditsWithWarehouse(
|
||||
// tenantId,
|
||||
// primaryWarehouse
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Updates all inventory transactions with the primary warehouse once
|
||||
* multi-warehouses feature is activated.
|
||||
* @param {IWarehousesActivatedPayload}
|
||||
*/
|
||||
@OnEvent(events.warehouse.onActivated)
|
||||
async updateInvoicesWithWarehouseOnActivated({
|
||||
primaryWarehouse,
|
||||
}: IWarehousesActivatedPayload) {
|
||||
await this.creditsActivateWarehouses.updateCreditsWithWarehouse(
|
||||
primaryWarehouse,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +1,26 @@
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import { IWarehousesActivatedPayload } from '@/interfaces';
|
||||
// import events from '@/subscribers/events';
|
||||
// import { EstimatesActivateWarehouses } from '../../Activate/EstimateWarehousesActivate';
|
||||
import { EstimatesActivateWarehouses } from '../../Activate/EstimateWarehousesActivate';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { events } from '@/common/events/events';
|
||||
import { IWarehousesActivatedPayload } from '../../Warehouse.types';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
// @Service()
|
||||
// export class EstimatesActivateWarehousesSubscriber {
|
||||
// @Inject()
|
||||
// private estimatesActivateWarehouses: EstimatesActivateWarehouses;
|
||||
@Injectable()
|
||||
export class EstimatesActivateWarehousesSubscriber {
|
||||
constructor(
|
||||
private readonly estimatesActivateWarehouses: EstimatesActivateWarehouses,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// public attach(bus) {
|
||||
// bus.subscribe(
|
||||
// events.warehouse.onActivated,
|
||||
// this.updateEstimatessWithWarehouseOnActivated
|
||||
// );
|
||||
// return bus;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Updates all inventory transactions with the primary warehouse once
|
||||
// * multi-warehouses feature is activated.
|
||||
// * @param {IWarehousesActivatedPayload}
|
||||
// */
|
||||
// private updateEstimatessWithWarehouseOnActivated = async ({
|
||||
// tenantId,
|
||||
// primaryWarehouse,
|
||||
// }: IWarehousesActivatedPayload) => {
|
||||
// await this.estimatesActivateWarehouses.updateEstimatesWithWarehouse(
|
||||
// tenantId,
|
||||
// primaryWarehouse
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Updates all inventory transactions with the primary warehouse once
|
||||
* multi-warehouses feature is activated.
|
||||
* @param {IWarehousesActivatedPayload}
|
||||
*/
|
||||
@OnEvent(events.warehouse.onActivated)
|
||||
async updateEstimatessWithWarehouseOnActivated({
|
||||
primaryWarehouse,
|
||||
}: IWarehousesActivatedPayload) {
|
||||
await this.estimatesActivateWarehouses.updateEstimatesWithWarehouse(
|
||||
primaryWarehouse,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +1,26 @@
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import { IWarehousesActivatedPayload } from '@/interfaces';
|
||||
// import events from '@/subscribers/events';
|
||||
// import { InventoryActivateWarehouses } from '../../Activate/InventoryTransactionsWarehousesActivate';
|
||||
import { InventoryActivateWarehouses } from '../../Activate/InventoryTransactionsWarehousesActivate';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { events } from '@/common/events/events';
|
||||
import { IWarehousesActivatedPayload } from '../../Warehouse.types';
|
||||
|
||||
// @Service()
|
||||
// export class InventoryActivateWarehousesSubscriber {
|
||||
// @Inject()
|
||||
// private inventoryActivateWarehouses: InventoryActivateWarehouses;
|
||||
@Injectable()
|
||||
export class InventoryActivateWarehousesSubscriber {
|
||||
constructor(
|
||||
private readonly inventoryActivateWarehouses: InventoryActivateWarehouses,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// public attach(bus) {
|
||||
// bus.subscribe(
|
||||
// events.warehouse.onActivated,
|
||||
// this.updateInventoryTransactionsWithWarehouseOnActivated
|
||||
// );
|
||||
// return bus;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Updates all inventory transactions with the primary warehouse once
|
||||
// * multi-warehouses feature is activated.
|
||||
// * @param {IWarehousesActivatedPayload}
|
||||
// */
|
||||
// private updateInventoryTransactionsWithWarehouseOnActivated = async ({
|
||||
// tenantId,
|
||||
// primaryWarehouse,
|
||||
// }: IWarehousesActivatedPayload) => {
|
||||
// await this.inventoryActivateWarehouses.updateInventoryTransactionsWithWarehouse(
|
||||
// tenantId,
|
||||
// primaryWarehouse
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Updates all inventory transactions with the primary warehouse once
|
||||
* multi-warehouses feature is activated.
|
||||
* @param {IWarehousesActivatedPayload}
|
||||
*/
|
||||
@OnEvent(events.warehouse.onActivated)
|
||||
async updateInventoryTransactionsWithWarehouseOnActivated({
|
||||
primaryWarehouse,
|
||||
}: IWarehousesActivatedPayload) {
|
||||
await this.inventoryActivateWarehouses.updateInventoryTransactionsWithWarehouse(
|
||||
primaryWarehouse,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +1,26 @@
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import { IWarehousesActivatedPayload } from '@/interfaces';
|
||||
// import events from '@/subscribers/events';
|
||||
// import { InvoicesActivateWarehouses } from '../../Activate/InvoiceWarehousesActivate';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InvoicesActivateWarehouses } from '../../Activate/InvoiceWarehousesActivate';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { IWarehousesActivatedPayload } from '../../Warehouse.types';
|
||||
import { events } from '@/common/events/events';
|
||||
|
||||
// @Service()
|
||||
// export class InvoicesActivateWarehousesSubscriber {
|
||||
// @Inject()
|
||||
// private invoicesActivateWarehouses: InvoicesActivateWarehouses;
|
||||
@Injectable()
|
||||
export class InvoicesActivateWarehousesSubscriber {
|
||||
constructor(
|
||||
private readonly invoicesActivateWarehouses: InvoicesActivateWarehouses,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// public attach(bus) {
|
||||
// bus.subscribe(
|
||||
// events.warehouse.onActivated,
|
||||
// this.updateInvoicesWithWarehouseOnActivated
|
||||
// );
|
||||
// return bus;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Updates all inventory transactions with the primary warehouse once
|
||||
// * multi-warehouses feature is activated.
|
||||
// * @param {IWarehousesActivatedPayload}
|
||||
// */
|
||||
// private updateInvoicesWithWarehouseOnActivated = async ({
|
||||
// tenantId,
|
||||
// primaryWarehouse,
|
||||
// }: IWarehousesActivatedPayload) => {
|
||||
// await this.invoicesActivateWarehouses.updateInvoicesWithWarehouse(
|
||||
// tenantId,
|
||||
// primaryWarehouse
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Updates all inventory transactions with the primary warehouse once
|
||||
* multi-warehouses feature is activated.
|
||||
* @param {IWarehousesActivatedPayload}
|
||||
*/
|
||||
@OnEvent(events.warehouse.onActivated)
|
||||
async updateInvoicesWithWarehouseOnActivated({
|
||||
primaryWarehouse,
|
||||
}: IWarehousesActivatedPayload) {
|
||||
await this.invoicesActivateWarehouses.updateInvoicesWithWarehouse(
|
||||
primaryWarehouse,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +1,27 @@
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import { IWarehousesActivatedPayload } from '@/interfaces';
|
||||
// import events from '@/subscribers/events';
|
||||
// import { ReceiptActivateWarehouses } from '../../Activate/ReceiptWarehousesActivate';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { ReceiptActivateWarehouses } from '../../Activate/ReceiptWarehousesActivate';
|
||||
import { events } from '@/common/events/events';
|
||||
import { IWarehousesActivatedPayload } from '../../Warehouse.types';
|
||||
|
||||
// @Service()
|
||||
// export class ReceiptsActivateWarehousesSubscriber {
|
||||
// @Inject()
|
||||
// private receiptsActivateWarehouses: ReceiptActivateWarehouses;
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// public attach(bus) {
|
||||
// bus.subscribe(
|
||||
// events.warehouse.onActivated,
|
||||
// this.updateInventoryTransactionsWithWarehouseOnActivated
|
||||
// );
|
||||
// return bus;
|
||||
// }
|
||||
@Injectable()
|
||||
export class ReceiptsActivateWarehousesSubscriber {
|
||||
constructor(
|
||||
private readonly receiptsActivateWarehouses: ReceiptActivateWarehouses,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Updates all receipts transactions with the primary warehouse once
|
||||
// * multi-warehouses feature is activated.
|
||||
// * @param {IWarehousesActivatedPayload}
|
||||
// */
|
||||
// private updateInventoryTransactionsWithWarehouseOnActivated = async ({
|
||||
// tenantId,
|
||||
// primaryWarehouse,
|
||||
// }: IWarehousesActivatedPayload) => {
|
||||
// await this.receiptsActivateWarehouses.updateReceiptsWithWarehouse(
|
||||
// tenantId,
|
||||
// primaryWarehouse
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Updates all receipts transactions with the primary warehouse once
|
||||
* multi-warehouses feature is activated.
|
||||
* @param {IWarehousesActivatedPayload}
|
||||
*/
|
||||
@OnEvent(events.warehouse.onActivated)
|
||||
async updateInventoryTransactionsWithWarehouseOnActivated({
|
||||
primaryWarehouse,
|
||||
}: IWarehousesActivatedPayload) {
|
||||
await this.receiptsActivateWarehouses.updateReceiptsWithWarehouse(
|
||||
primaryWarehouse
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,36 +1,26 @@
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import { IWarehousesActivatedPayload } from '@/interfaces';
|
||||
// import events from '@/subscribers/events';
|
||||
// import { VendorCreditActivateWarehouses } from '../../Activate/VendorCreditWarehousesActivate';
|
||||
import { VendorCreditActivateWarehouses } from '../../Activate/VendorCreditWarehousesActivate';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { IWarehousesActivatedPayload } from '../../Warehouse.types';
|
||||
import { events } from '@/common/events/events';
|
||||
|
||||
// @Service()
|
||||
// export class VendorCreditsActivateWarehousesSubscriber {
|
||||
// @Inject()
|
||||
// private creditsActivateWarehouses: VendorCreditActivateWarehouses;
|
||||
@Injectable()
|
||||
export class VendorCreditsActivateWarehousesSubscriber {
|
||||
constructor(
|
||||
private readonly creditsActivateWarehouses: VendorCreditActivateWarehouses,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// public attach(bus) {
|
||||
// bus.subscribe(
|
||||
// events.warehouse.onActivated,
|
||||
// this.updateCreditsWithWarehouseOnActivated
|
||||
// );
|
||||
// return bus;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Updates all inventory transactions with the primary warehouse once
|
||||
// * multi-warehouses feature is activated.
|
||||
// * @param {IWarehousesActivatedPayload}
|
||||
// */
|
||||
// private updateCreditsWithWarehouseOnActivated = async ({
|
||||
// tenantId,
|
||||
// primaryWarehouse,
|
||||
// }: IWarehousesActivatedPayload) => {
|
||||
// await this.creditsActivateWarehouses.updateCreditsWithWarehouse(
|
||||
// tenantId,
|
||||
// primaryWarehouse
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Updates all inventory transactions with the primary warehouse once
|
||||
* multi-warehouses feature is activated.
|
||||
* @param {IWarehousesActivatedPayload}
|
||||
*/
|
||||
@OnEvent(events.warehouse.onActivated)
|
||||
async updateCreditsWithWarehouseOnActivated({
|
||||
primaryWarehouse,
|
||||
}: IWarehousesActivatedPayload) {
|
||||
await this.creditsActivateWarehouses.updateCreditsWithWarehouse(
|
||||
primaryWarehouse,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
// /* eslint-disable import/extensions */
|
||||
// export * from './BillWarehousesActivateSubscriber';
|
||||
// export * from './CreditNoteWarehousesActivateSubscriber';
|
||||
// export * from './EstimateWarehousesActivateSubscriber';
|
||||
// export * from './InventoryTransactionsWarehousesActivateSubscriber';
|
||||
// export * from './VendorCreditWarehousesActivateSubscriber';
|
||||
// export * from './ReceiptWarehousesActivateSubscriber';
|
||||
// export * from './InvoiceWarehousesActivateSubscriber';
|
||||
@@ -1,36 +1,27 @@
|
||||
// import { Inject, Service } from 'typedi';
|
||||
// import events from '@/subscribers/events';
|
||||
// import { DeleteItemWarehousesQuantity } from '../commands/DeleteItemWarehousesQuantity';
|
||||
// import { IItemEventDeletingPayload } from '@/interfaces';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { DeleteItemWarehousesQuantity } from '../commands/DeleteItemWarehousesQuantity';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { events } from '@/common/events/events';
|
||||
import { IItemEventDeletingPayload } from '@/interfaces/Item';
|
||||
|
||||
// @Service()
|
||||
// export class DeleteItemWarehousesQuantitySubscriber {
|
||||
// @Inject()
|
||||
// private deleteItemWarehousesQuantity: DeleteItemWarehousesQuantity;
|
||||
@Injectable()
|
||||
export class DeleteItemWarehousesQuantitySubscriber {
|
||||
constructor(
|
||||
private readonly deleteItemWarehousesQuantity: DeleteItemWarehousesQuantity,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Attaches events.
|
||||
// */
|
||||
// public attach(bus) {
|
||||
// bus.subscribe(
|
||||
// events.item.onDeleting,
|
||||
// this.deleteItemWarehouseQuantitiesOnItemDelete
|
||||
// );
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Deletes the given item warehouses quantities once the item deleting.
|
||||
// * @param {IItemEventDeletingPayload} payload -
|
||||
// */
|
||||
// private deleteItemWarehouseQuantitiesOnItemDelete = async ({
|
||||
// tenantId,
|
||||
// oldItem,
|
||||
// trx,
|
||||
// }: IItemEventDeletingPayload) => {
|
||||
// await this.deleteItemWarehousesQuantity.deleteItemWarehousesQuantity(
|
||||
// tenantId,
|
||||
// oldItem.id,
|
||||
// trx
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Deletes the given item warehouses quantities once the item deleting.
|
||||
* @param {IItemEventDeletingPayload} payload -
|
||||
*/
|
||||
@OnEvent(events.item.onDeleting)
|
||||
async deleteItemWarehouseQuantitiesOnItemDelete({
|
||||
oldItem,
|
||||
trx,
|
||||
}: IItemEventDeletingPayload) {
|
||||
await this.deleteItemWarehousesQuantity.deleteItemWarehousesQuantity(
|
||||
oldItem.id,
|
||||
trx,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +1,25 @@
|
||||
// import { Inject, Service } from 'typedi';
|
||||
// import { IInventoryAdjustmentCreatingPayload } from '@/interfaces';
|
||||
// import events from '@/subscribers/events';
|
||||
// import { WarehousesDTOValidators } from '../../../Integrations/WarehousesDTOValidators';
|
||||
import { WarehousesDTOValidators } from '../../../Integrations/WarehousesDTOValidators';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { IInventoryAdjustmentCreatingPayload } from '@/modules/InventoryAdjutments/types/InventoryAdjustments.types';
|
||||
import { events } from '@/common/events/events';
|
||||
|
||||
// @Service()
|
||||
// export class InventoryAdjustmentWarehouseValidatorSubscriber {
|
||||
// @Inject()
|
||||
// private warehouseDTOValidator: WarehousesDTOValidators;
|
||||
@Injectable()
|
||||
export class InventoryAdjustmentWarehouseValidatorSubscriber {
|
||||
constructor(
|
||||
private readonly warehouseDTOValidator: WarehousesDTOValidators,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// public attach(bus) {
|
||||
// bus.subscribe(
|
||||
// events.inventoryAdjustment.onQuickCreating,
|
||||
// this.validateAdjustmentWarehouseExistanceOnCreating
|
||||
// );
|
||||
// return bus;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Validate warehouse existance of sale invoice once creating.
|
||||
// * @param {IBillCreatingPayload}
|
||||
// */
|
||||
// private validateAdjustmentWarehouseExistanceOnCreating = async ({
|
||||
// quickAdjustmentDTO,
|
||||
// tenantId,
|
||||
// }: IInventoryAdjustmentCreatingPayload) => {
|
||||
// await this.warehouseDTOValidator.validateDTOWarehouseWhenActive(
|
||||
// tenantId,
|
||||
// quickAdjustmentDTO
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Validate warehouse existance of sale invoice once creating.
|
||||
* @param {IBillCreatingPayload}
|
||||
*/
|
||||
@OnEvent(events.inventoryAdjustment.onQuickCreating)
|
||||
async validateAdjustmentWarehouseExistanceOnCreating({
|
||||
quickAdjustmentDTO,
|
||||
}: IInventoryAdjustmentCreatingPayload) {
|
||||
await this.warehouseDTOValidator.validateDTOWarehouseWhenActive(
|
||||
quickAdjustmentDTO,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,53 +1,36 @@
|
||||
// import { Inject, Service } from 'typedi';
|
||||
// import { IBillCreatingPayload, IBillEditingPayload } from '@/interfaces';
|
||||
// import events from '@/subscribers/events';
|
||||
// import { WarehousesDTOValidators } from '../../../Integrations/WarehousesDTOValidators';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { events } from '@/common/events/events';
|
||||
import { WarehousesDTOValidators } from '../../../Integrations/WarehousesDTOValidators';
|
||||
import { IBillEditingPayload } from '@/modules/Bills/Bills.types';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { IBillCreatingPayload } from '@/modules/Bills/Bills.types';
|
||||
|
||||
// @Service()
|
||||
// export class BillWarehousesValidateSubscriber {
|
||||
// @Inject()
|
||||
// private warehouseDTOValidator: WarehousesDTOValidators;
|
||||
@Injectable()
|
||||
export class BillWarehousesValidateSubscriber {
|
||||
constructor(
|
||||
private readonly warehouseDTOValidator: WarehousesDTOValidators,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// public attach(bus) {
|
||||
// bus.subscribe(
|
||||
// events.bill.onCreating,
|
||||
// this.validateBillWarehouseExistanceOnCreating
|
||||
// );
|
||||
// bus.subscribe(
|
||||
// events.bill.onEditing,
|
||||
// this.validateSaleEstimateWarehouseExistanceOnEditing
|
||||
// );
|
||||
// return bus;
|
||||
// }
|
||||
/**
|
||||
* Validate warehouse existance of sale invoice once creating.
|
||||
* @param {IBillCreatingPayload}
|
||||
*/
|
||||
@OnEvent(events.bill.onCreating)
|
||||
async validateBillWarehouseExistanceOnCreating({
|
||||
billDTO,
|
||||
}: IBillCreatingPayload) {
|
||||
await this.warehouseDTOValidator.validateDTOWarehouseWhenActive(billDTO);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Validate warehouse existance of sale invoice once creating.
|
||||
// * @param {IBillCreatingPayload}
|
||||
// */
|
||||
// private validateBillWarehouseExistanceOnCreating = async ({
|
||||
// billDTO,
|
||||
// tenantId,
|
||||
// }: IBillCreatingPayload) => {
|
||||
// await this.warehouseDTOValidator.validateDTOWarehouseWhenActive(
|
||||
// tenantId,
|
||||
// billDTO
|
||||
// );
|
||||
// };
|
||||
/**
|
||||
* Validate warehouse existance of sale invoice once editing.
|
||||
* @param {IBillEditingPayload}
|
||||
*/
|
||||
|
||||
// /**
|
||||
// * Validate warehouse existance of sale invoice once editing.
|
||||
// * @param {IBillEditingPayload}
|
||||
// */
|
||||
// private validateSaleEstimateWarehouseExistanceOnEditing = async ({
|
||||
// tenantId,
|
||||
// billDTO,
|
||||
// }: IBillEditingPayload) => {
|
||||
// await this.warehouseDTOValidator.validateDTOWarehouseWhenActive(
|
||||
// tenantId,
|
||||
// billDTO
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
@OnEvent(events.bill.onEditing)
|
||||
async validateSaleEstimateWarehouseExistanceOnEditing({
|
||||
billDTO,
|
||||
}: IBillEditingPayload) {
|
||||
await this.warehouseDTOValidator.validateDTOWarehouseWhenActive(billDTO);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,56 +1,39 @@
|
||||
// import { Inject, Service } from 'typedi';
|
||||
// import {
|
||||
// IVendorCreditCreatingPayload,
|
||||
// IVendorCreditEditingPayload,
|
||||
// } from '@/interfaces';
|
||||
// import events from '@/subscribers/events';
|
||||
// import { WarehousesDTOValidators } from '../../../Integrations/WarehousesDTOValidators';
|
||||
import { WarehousesDTOValidators } from '../../../Integrations/WarehousesDTOValidators';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { IVendorCreditEditingPayload } from '@/modules/VendorCredit/types/VendorCredit.types';
|
||||
import { events } from '@/common/events/events';
|
||||
import { IVendorCreditCreatingPayload } from '@/modules/VendorCredit/types/VendorCredit.types';
|
||||
|
||||
// @Service()
|
||||
// export class VendorCreditWarehousesValidateSubscriber {
|
||||
// @Inject()
|
||||
// warehouseDTOValidator: WarehousesDTOValidators;
|
||||
@Injectable()
|
||||
export class VendorCreditWarehousesValidateSubscriber {
|
||||
constructor(
|
||||
private readonly warehouseDTOValidator: WarehousesDTOValidators,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Attaches events with handlers.
|
||||
// */
|
||||
// public attach(bus) {
|
||||
// bus.subscribe(
|
||||
// events.vendorCredit.onCreating,
|
||||
// this.validateVendorCreditWarehouseExistanceOnCreating
|
||||
// );
|
||||
// bus.subscribe(
|
||||
// events.vendorCredit.onEditing,
|
||||
// this.validateSaleEstimateWarehouseExistanceOnEditing
|
||||
// );
|
||||
// return bus;
|
||||
// }
|
||||
/**
|
||||
* Validate warehouse existance of sale invoice once creating.
|
||||
* @param {IVendorCreditCreatingPayload}
|
||||
*/
|
||||
@OnEvent(events.vendorCredit.onCreating)
|
||||
async validateVendorCreditWarehouseExistanceOnCreating({
|
||||
vendorCreditCreateDTO,
|
||||
}: IVendorCreditCreatingPayload) {
|
||||
await this.warehouseDTOValidator.validateDTOWarehouseWhenActive(
|
||||
vendorCreditCreateDTO,
|
||||
);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Validate warehouse existance of sale invoice once creating.
|
||||
// * @param {IVendorCreditCreatingPayload}
|
||||
// */
|
||||
// private validateVendorCreditWarehouseExistanceOnCreating = async ({
|
||||
// vendorCreditCreateDTO,
|
||||
// tenantId,
|
||||
// }: IVendorCreditCreatingPayload) => {
|
||||
// await this.warehouseDTOValidator.validateDTOWarehouseWhenActive(
|
||||
// tenantId,
|
||||
// vendorCreditCreateDTO
|
||||
// );
|
||||
// };
|
||||
|
||||
// /**
|
||||
// * Validate warehouse existance of sale invoice once editing.
|
||||
// * @param {IVendorCreditEditingPayload}
|
||||
// */
|
||||
// private validateSaleEstimateWarehouseExistanceOnEditing = async ({
|
||||
// tenantId,
|
||||
// vendorCreditDTO,
|
||||
// }: IVendorCreditEditingPayload) => {
|
||||
// await this.warehouseDTOValidator.validateDTOWarehouseWhenActive(
|
||||
// tenantId,
|
||||
// vendorCreditDTO
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Validate warehouse existance of sale invoice once editing.
|
||||
* @param {IVendorCreditEditingPayload}
|
||||
*/
|
||||
@OnEvent(events.vendorCredit.onEditing)
|
||||
async validateSaleEstimateWarehouseExistanceOnEditing({
|
||||
vendorCreditDTO,
|
||||
}: IVendorCreditEditingPayload) {
|
||||
await this.warehouseDTOValidator.validateDTOWarehouseWhenActive(
|
||||
vendorCreditDTO,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user