mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 06:40: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 { MailModule } from '../Mail/Mail.module';
|
||||||
import { FinancialStatementsModule } from '../FinancialStatements/FinancialStatements.module';
|
import { FinancialStatementsModule } from '../FinancialStatements/FinancialStatements.module';
|
||||||
import { StripePaymentModule } from '../StripePayment/StripePayment.module';
|
import { StripePaymentModule } from '../StripePayment/StripePayment.module';
|
||||||
|
import { FeaturesModule } from '../Features/Features.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -155,8 +156,9 @@ import { StripePaymentModule } from '../StripePayment/StripePayment.module';
|
|||||||
BankingTransactionsExcludeModule,
|
BankingTransactionsExcludeModule,
|
||||||
BankingTransactionsRegonizeModule,
|
BankingTransactionsRegonizeModule,
|
||||||
BankingMatchingModule,
|
BankingMatchingModule,
|
||||||
// TransactionsLockingModule,
|
TransactionsLockingModule,
|
||||||
// SettingsModule,
|
SettingsModule,
|
||||||
|
FeaturesModule,
|
||||||
InventoryAdjustmentsModule,
|
InventoryAdjustmentsModule,
|
||||||
PostHogModule,
|
PostHogModule,
|
||||||
EventTrackerModule,
|
EventTrackerModule,
|
||||||
|
|||||||
@@ -15,7 +15,18 @@ import { BranchesSettingsService } from './BranchesSettings';
|
|||||||
import { BranchCommandValidator } from './commands/BranchCommandValidator.service';
|
import { BranchCommandValidator } from './commands/BranchCommandValidator.service';
|
||||||
import { BranchTransactionDTOTransformer } from './integrations/BranchTransactionDTOTransform';
|
import { BranchTransactionDTOTransformer } from './integrations/BranchTransactionDTOTransform';
|
||||||
import { ManualJournalBranchesDTOTransformer } from './integrations/ManualJournals/ManualJournalDTOTransformer.service';
|
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({
|
@Module({
|
||||||
imports: [TenancyDatabaseModule],
|
imports: [TenancyDatabaseModule],
|
||||||
controllers: [BranchesController],
|
controllers: [BranchesController],
|
||||||
@@ -34,6 +45,18 @@ import { ManualJournalBranchesDTOTransformer } from './integrations/ManualJourna
|
|||||||
BranchCommandValidator,
|
BranchCommandValidator,
|
||||||
BranchTransactionDTOTransformer,
|
BranchTransactionDTOTransformer,
|
||||||
ManualJournalBranchesDTOTransformer,
|
ManualJournalBranchesDTOTransformer,
|
||||||
|
BillBranchValidateSubscriber,
|
||||||
|
CreditNoteBranchValidateSubscriber,
|
||||||
|
CreditNoteRefundBranchValidateSubscriber,
|
||||||
|
ContactBranchValidateSubscriber,
|
||||||
|
ExpenseBranchValidateSubscriber,
|
||||||
|
InventoryAdjustmentBranchValidateSubscriber,
|
||||||
|
ManualJournalBranchValidateSubscriber,
|
||||||
|
PaymentMadeBranchValidateSubscriber,
|
||||||
|
PaymentReceiveBranchValidateSubscriber,
|
||||||
|
SaleEstimateBranchValidateSubscriber,
|
||||||
|
SaleReceiptBranchValidateSubscriber,
|
||||||
|
VendorCreditBranchValidateSubscriber,
|
||||||
],
|
],
|
||||||
exports: [
|
exports: [
|
||||||
BranchesSettingsService,
|
BranchesSettingsService,
|
||||||
|
|||||||
@@ -1,26 +1,27 @@
|
|||||||
// import { Service, Inject } from 'typedi';
|
import { Knex } from 'knex';
|
||||||
// import { Knex } from 'knex';
|
import { Injectable } from '@nestjs/common';
|
||||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
import { BankTransaction } from '@/modules/BankingTransactions/models/BankTransaction';
|
||||||
|
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class CashflowTransactionsActivateBranches {
|
export class CashflowTransactionsActivateBranches {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private tenancy: HasTenancyService;
|
private readonly bankTransaction: TenantModelProxy<typeof BankTransaction>,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Updates all cashflow transactions with the primary branch.
|
* Updates all cashflow transactions with the primary branch.
|
||||||
// * @param {number} tenantId
|
* @param {number} primaryBranchId - The primary branch id.
|
||||||
// * @param {number} primaryBranchId
|
* @param {Knex.Transaction} trx - The database transaction.
|
||||||
// * @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
// */
|
*/
|
||||||
// public updateCashflowTransactionsWithBranch = async (
|
public updateCashflowTransactionsWithBranch = async (
|
||||||
// tenantId: number,
|
primaryBranchId: number,
|
||||||
// primaryBranchId: number,
|
trx?: Knex.Transaction,
|
||||||
// trx?: Knex.Transaction
|
) => {
|
||||||
// ) => {
|
// Updates the cashflow transactions with primary branch.
|
||||||
// const { CashflowTransaction } = this.tenancy.models(tenantId);
|
await this.bankTransaction()
|
||||||
|
.query(trx)
|
||||||
// // Updates the cashflow transactions with primary branch.
|
.update({ branchId: primaryBranchId });
|
||||||
// await CashflowTransaction.query(trx).update({ branchId: primaryBranchId });
|
};
|
||||||
// };
|
}
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,26 +1,24 @@
|
|||||||
// import { Service, Inject } from 'typedi';
|
import { Knex } from 'knex';
|
||||||
// import { Knex } from 'knex';
|
import { Injectable } from '@nestjs/common';
|
||||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||||
|
import { Expense } from '@/modules/Expenses/models/Expense.model';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class ExpensesActivateBranches {
|
export class ExpensesActivateBranches {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private tenancy: HasTenancyService;
|
private readonly expenseModel: TenantModelProxy<typeof Expense>,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Updates all expenses transactions with the primary branch.
|
* Updates all expenses transactions with the primary branch.
|
||||||
// * @param {number} tenantId
|
* @param {number} primaryBranchId
|
||||||
// * @param {number} primaryBranchId
|
* @returns {Promise<void>}
|
||||||
// * @returns {Promise<void>}
|
*/
|
||||||
// */
|
public updateExpensesWithBranch = async (
|
||||||
// public updateExpensesWithBranch = async (
|
primaryBranchId: number,
|
||||||
// tenantId: number,
|
trx?: Knex.Transaction,
|
||||||
// primaryBranchId: number,
|
) => {
|
||||||
// trx?: Knex.Transaction
|
// Updates the expenses with primary branch.
|
||||||
// ) => {
|
await this.expenseModel().query(trx).update({ branchId: primaryBranchId });
|
||||||
// const { Expense } = this.tenancy.models(tenantId);
|
};
|
||||||
|
}
|
||||||
// // Updates the expenses with primary branch.
|
|
||||||
// await Expense.query(trx).update({ branchId: primaryBranchId });
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,26 +1,26 @@
|
|||||||
// import { Service, Inject } from 'typedi';
|
import { Knex } from 'knex';
|
||||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
import { Injectable } from '@nestjs/common';
|
||||||
// import { Knex } from 'knex';
|
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||||
|
import { ManualJournal } from '@/modules/ManualJournals/models/ManualJournal';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class ManualJournalsActivateBranches {
|
export class ManualJournalsActivateBranches {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private tenancy: HasTenancyService;
|
private readonly manualJournalModel: TenantModelProxy<typeof ManualJournal>,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Updates all manual journals transactions with the primary branch.
|
* Updates all manual journals transactions with the primary branch.
|
||||||
// * @param {number} tenantId
|
* @param {number} primaryBranchId
|
||||||
// * @param {number} primaryBranchId
|
* @returns {Promise<void>}
|
||||||
// * @returns {Promise<void>}
|
*/
|
||||||
// */
|
public updateManualJournalsWithBranch = async (
|
||||||
// public updateManualJournalsWithBranch = async (
|
primaryBranchId: number,
|
||||||
// tenantId: number,
|
trx?: Knex.Transaction,
|
||||||
// primaryBranchId: number,
|
) => {
|
||||||
// trx?: Knex.Transaction
|
// Updates the manual journal with primary branch.
|
||||||
// ) => {
|
await this.manualJournalModel()
|
||||||
// const { ManualJournal } = this.tenancy.models(tenantId);
|
.query(trx)
|
||||||
|
.update({ branchId: primaryBranchId });
|
||||||
// // Updates the manual journal with primary branch.
|
};
|
||||||
// await ManualJournal.query(trx).update({ branchId: primaryBranchId });
|
}
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,23 +1,24 @@
|
|||||||
// import { Service, Inject } from 'typedi';
|
import { IManualJournalDTO } from '@/modules/ManualJournals/types/ManualJournals.types';
|
||||||
// import { ServiceError } from '@/exceptions';
|
import { IManualJournalEntryDTO } from '@/modules/ManualJournals/types/ManualJournals.types';
|
||||||
// import { IManualJournalDTO, IManualJournalEntryDTO } from '@/interfaces';
|
import { ERRORS } from './constants';
|
||||||
// import { ERRORS } from './constants';
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { ServiceError } from '@/modules/Items/ServiceError';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class ManualJournalBranchesValidator {
|
export class ManualJournalBranchesValidator {
|
||||||
// /**
|
/**
|
||||||
// * Validates the DTO entries should have branch id.
|
* Validates the DTO entries should have branch id.
|
||||||
// * @param {IManualJournalDTO} manualJournalDTO
|
* @param {IManualJournalDTO} manualJournalDTO
|
||||||
// */
|
*/
|
||||||
// public validateEntriesHasBranchId = async (
|
public validateEntriesHasBranchId = async (
|
||||||
// manualJournalDTO: IManualJournalDTO
|
manualJournalDTO: IManualJournalDTO,
|
||||||
// ) => {
|
) => {
|
||||||
// const hasNoIdEntries = manualJournalDTO.entries.filter(
|
const hasNoIdEntries = manualJournalDTO.entries.filter(
|
||||||
// (entry: IManualJournalEntryDTO) =>
|
(entry: IManualJournalEntryDTO) =>
|
||||||
// !entry.branchId && !manualJournalDTO.branchId
|
!entry.branchId && !manualJournalDTO.branchId,
|
||||||
// );
|
);
|
||||||
// if (hasNoIdEntries.length > 0) {
|
if (hasNoIdEntries.length > 0) {
|
||||||
// throw new ServiceError(ERRORS.MANUAL_JOURNAL_ENTRIES_HAVE_NO_BRANCH_ID);
|
throw new ServiceError(ERRORS.MANUAL_JOURNAL_ENTRIES_HAVE_NO_BRANCH_ID);
|
||||||
// }
|
}
|
||||||
// };
|
};
|
||||||
// }
|
}
|
||||||
|
|||||||
@@ -1,26 +1,23 @@
|
|||||||
// import { Service, Inject } from 'typedi';
|
import { Knex } from 'knex';
|
||||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
import { Injectable } from '@nestjs/common';
|
||||||
// import { Knex } from 'knex';
|
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||||
|
import { Bill } from '@/modules/Bills/models/Bill';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class BillActivateBranches {
|
export class BillActivateBranches {
|
||||||
// @Inject()
|
constructor(private readonly billModel: TenantModelProxy<typeof Bill>) {}
|
||||||
// private tenancy: HasTenancyService;
|
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Updates all bills transactions with the primary branch.
|
* Updates all bills transactions with the primary branch.
|
||||||
// * @param {number} tenantId
|
* @param {number} tenantId
|
||||||
// * @param {number} primaryBranchId
|
* @param {number} primaryBranchId
|
||||||
// * @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
// */
|
*/
|
||||||
// public updateBillsWithBranch = async (
|
public updateBillsWithBranch = async (
|
||||||
// tenantId: number,
|
primaryBranchId: number,
|
||||||
// primaryBranchId: number,
|
trx?: Knex.Transaction,
|
||||||
// trx?: Knex.Transaction
|
) => {
|
||||||
// ) => {
|
// Updates the sale invoice with primary branch.
|
||||||
// const { Bill } = this.tenancy.models(tenantId);
|
await Bill.query(trx).update({ branchId: primaryBranchId });
|
||||||
|
};
|
||||||
// // Updates the sale invoice with primary branch.
|
}
|
||||||
// await Bill.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 { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||||
// import { Knex } from 'knex';
|
import { BillPayment } from '@/modules/BillPayments/models/BillPayment';
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class BillPaymentsActivateBranches {
|
export class BillPaymentsActivateBranches {
|
||||||
// @Inject()
|
constructor(
|
||||||
// tenancy: HasTenancyService;
|
private readonly billPaymentModel: TenantModelProxy<typeof BillPayment>,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Updates all bills payments transcations with the primary branch.
|
* Updates all bills payments transcations with the primary branch.
|
||||||
// * @param {number} tenantId
|
* @param {number} primaryBranchId
|
||||||
// * @param {number} primaryBranchId
|
* @returns {Promise<void>}
|
||||||
// * @returns {Promise<void>}
|
*/
|
||||||
// */
|
public updateBillPaymentsWithBranch = async (
|
||||||
// public updateBillPaymentsWithBranch = async (
|
primaryBranchId: number,
|
||||||
// tenantId: number,
|
trx?: Knex.Transaction
|
||||||
// primaryBranchId: number,
|
) => {
|
||||||
// trx?: Knex.Transaction
|
// Updates the bill payments with primary branch.
|
||||||
// ) => {
|
await this.billPaymentModel().query(trx).update({ branchId: primaryBranchId });
|
||||||
// const { BillPayment } = this.tenancy.models(tenantId);
|
};
|
||||||
|
}
|
||||||
// // Updates the bill payments with primary branch.
|
|
||||||
// await BillPayment.query(trx).update({ branchId: primaryBranchId });
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,26 +1,27 @@
|
|||||||
// import { Service, Inject } from 'typedi';
|
import { Knex } from 'knex';
|
||||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
import { Injectable } from '@nestjs/common';
|
||||||
// import { Knex } from 'knex';
|
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||||
|
import { VendorCredit } from '@/modules/VendorCredit/models/VendorCredit';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class VendorCreditActivateBranches {
|
export class VendorCreditActivateBranches {
|
||||||
// @Inject()
|
constructor(
|
||||||
// tenancy: HasTenancyService;
|
private readonly vendorCreditModel: TenantModelProxy<typeof VendorCredit>,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Updates all vendor credits transcations with the primary branch.
|
* Updates all vendor credits transcations with the primary branch.
|
||||||
// * @param {number} tenantId
|
* @param {number} tenantId
|
||||||
// * @param {number} primaryBranchId
|
* @param {number} primaryBranchId
|
||||||
// * @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
// */
|
*/
|
||||||
// public updateVendorCreditsWithBranch = async (
|
public updateVendorCreditsWithBranch = async (
|
||||||
// tenantId: number,
|
primaryBranchId: number,
|
||||||
// primaryBranchId: number,
|
trx?: Knex.Transaction,
|
||||||
// trx?: Knex.Transaction
|
) => {
|
||||||
// ) => {
|
// Updates the vendors credits with primary branch.
|
||||||
// const { VendorCredit } = this.tenancy.models(tenantId);
|
await this.vendorCreditModel()
|
||||||
|
.query(trx)
|
||||||
// // Updates the vendors credits with primary branch.
|
.update({ branchId: primaryBranchId });
|
||||||
// await VendorCredit.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 { CreditNote } from '@/modules/CreditNotes/models/CreditNote';
|
||||||
// import { Knex } from 'knex';
|
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class CreditNoteActivateBranches {
|
export class CreditNoteActivateBranches {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private tenancy: HasTenancyService;
|
private readonly creditNoteModel: TenantModelProxy<typeof CreditNote>,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Updates all creidt notes transactions with the primary branch.
|
* Updates all creidt notes transactions with the primary branch.
|
||||||
// * @param {number} tenantId
|
* @param {number} primaryBranchId
|
||||||
// * @param {number} primaryBranchId
|
* @returns {Promise<void>}
|
||||||
// * @returns {Promise<void>}
|
*/
|
||||||
// */
|
public updateCreditsWithBranch = async (
|
||||||
// public updateCreditsWithBranch = async (
|
primaryBranchId: number,
|
||||||
// tenantId: number,
|
trx?: Knex.Transaction
|
||||||
// primaryBranchId: number,
|
) => {
|
||||||
// trx?: Knex.Transaction
|
// Updates the sale invoice with primary branch.
|
||||||
// ) => {
|
await this.creditNoteModel().query(trx).update({ branchId: primaryBranchId });
|
||||||
// const { CreditNote } = this.tenancy.models(tenantId);
|
};
|
||||||
|
}
|
||||||
// // Updates the sale invoice with primary branch.
|
|
||||||
// await CreditNote.query(trx).update({ branchId: primaryBranchId });
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,26 +1,24 @@
|
|||||||
// import { Service, Inject } from 'typedi';
|
import { PaymentReceived } from '@/modules/PaymentReceived/models/PaymentReceived';
|
||||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||||
// import { Knex } from 'knex';
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { Knex } from 'knex';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class PaymentReceiveActivateBranches {
|
export class PaymentReceiveActivateBranches {
|
||||||
// @Inject()
|
constructor(
|
||||||
// tenancy: HasTenancyService;
|
private readonly paymentReceivedModel: TenantModelProxy<typeof PaymentReceived>,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Updates all creidt notes transactions with the primary branch.
|
* Updates all creidt notes transactions with the primary branch.
|
||||||
// * @param {number} tenantId
|
* @param {number} primaryBranchId
|
||||||
// * @param {number} primaryBranchId
|
* @returns {Promise<void>}
|
||||||
// * @returns {Promise<void>}
|
*/
|
||||||
// */
|
public updatePaymentsWithBranch = async (
|
||||||
// public updatePaymentsWithBranch = async (
|
primaryBranchId: number,
|
||||||
// tenantId: number,
|
trx?: Knex.Transaction
|
||||||
// primaryBranchId: number,
|
) => {
|
||||||
// trx?: Knex.Transaction
|
// Updates the sale invoice with primary branch.
|
||||||
// ) => {
|
await this.paymentReceivedModel().query(trx).update({ branchId: primaryBranchId });
|
||||||
// const { PaymentReceive } = this.tenancy.models(tenantId);
|
};
|
||||||
|
}
|
||||||
// // Updates the sale invoice with primary branch.
|
|
||||||
// await PaymentReceive.query(trx).update({ branchId: primaryBranchId });
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,26 +1,25 @@
|
|||||||
// import { Service, Inject } from 'typedi';
|
import { Knex } from 'knex';
|
||||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||||
// import { Knex } from 'knex';
|
import { PaymentReceived } from '@/modules/PaymentReceived/models/PaymentReceived';
|
||||||
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class SaleEstimateActivateBranches {
|
export class SaleEstimateActivateBranches {
|
||||||
// @Inject()
|
constructor(
|
||||||
// tenancy: HasTenancyService;
|
@Inject(PaymentReceived.name)
|
||||||
|
private readonly paymentReceivedModel: TenantModelProxy<typeof PaymentReceived>,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Updates all sale estimates transactions with the primary branch.
|
* Updates all sale estimates transactions with the primary branch.
|
||||||
// * @param {number} tenantId
|
* @param {number} primaryBranchId
|
||||||
// * @param {number} primaryBranchId
|
* @returns {Promise<void>}
|
||||||
// * @returns {Promise<void>}
|
*/
|
||||||
// */
|
public updateEstimatesWithBranch = async (
|
||||||
// public updateEstimatesWithBranch = async (
|
primaryBranchId: number,
|
||||||
// tenantId: number,
|
trx?: Knex.Transaction
|
||||||
// primaryBranchId: number,
|
) => {
|
||||||
// trx?: Knex.Transaction
|
// Updates the sale invoice with primary branch.
|
||||||
// ) => {
|
await this.paymentReceivedModel().query(trx).update({ branchId: primaryBranchId });
|
||||||
// const { PaymentReceive } = this.tenancy.models(tenantId);
|
};
|
||||||
|
}
|
||||||
// // Updates the sale invoice with primary branch.
|
|
||||||
// await PaymentReceive.query(trx).update({ branchId: primaryBranchId });
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,26 +1,26 @@
|
|||||||
// import { Service, Inject } from 'typedi';
|
import { Injectable } from '@nestjs/common';
|
||||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
import { Knex } from 'knex';
|
||||||
// import { Knex } from 'knex';
|
import { SaleInvoice } from '@/modules/SaleInvoices/models/SaleInvoice';
|
||||||
|
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class SaleInvoiceActivateBranches {
|
export class SaleInvoiceActivateBranches {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private tenancy: HasTenancyService;
|
private readonly saleInvoiceModel: TenantModelProxy<typeof SaleInvoice>,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Updates all sale invoices transactions with the primary branch.
|
* Updates all sale invoices transactions with the primary branch.
|
||||||
// * @param {number} tenantId
|
* @param {number} primaryBranchId
|
||||||
// * @param {number} primaryBranchId
|
* @returns {Promise<void>}
|
||||||
// * @returns {Promise<void>}
|
*/
|
||||||
// */
|
public updateInvoicesWithBranch = async (
|
||||||
// public updateInvoicesWithBranch = async (
|
primaryBranchId: number,
|
||||||
// tenantId: number,
|
trx?: Knex.Transaction,
|
||||||
// primaryBranchId: number,
|
) => {
|
||||||
// trx?: Knex.Transaction
|
// Updates the sale invoice with primary branch.
|
||||||
// ) => {
|
await this.saleInvoiceModel()
|
||||||
// const { SaleInvoice } = this.tenancy.models(tenantId);
|
.query(trx)
|
||||||
|
.update({ branchId: primaryBranchId });
|
||||||
// // Updates the sale invoice with primary branch.
|
};
|
||||||
// await SaleInvoice.query(trx).update({ branchId: primaryBranchId });
|
}
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,26 +1,26 @@
|
|||||||
// import { Service, Inject } from 'typedi';
|
import { Knex } from 'knex';
|
||||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
import { Injectable } from '@nestjs/common';
|
||||||
// import { Knex } from 'knex';
|
import { SaleReceipt } from '@/modules/SaleReceipts/models/SaleReceipt';
|
||||||
|
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class SaleReceiptActivateBranches {
|
export class SaleReceiptActivateBranches {
|
||||||
// @Inject()
|
constructor(
|
||||||
// tenancy: HasTenancyService;
|
private readonly saleReceiptModel: TenantModelProxy<typeof SaleReceipt>,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Updates all sale receipts transactions with the primary branch.
|
* Updates all sale receipts transactions with the primary branch.
|
||||||
// * @param {number} tenantId
|
* @param {number} primaryBranchId
|
||||||
// * @param {number} primaryBranchId
|
* @returns {Promise<void>}
|
||||||
// * @returns {Promise<void>}
|
*/
|
||||||
// */
|
public updateReceiptsWithBranch = async (
|
||||||
// public updateReceiptsWithBranch = async (
|
primaryBranchId: number,
|
||||||
// tenantId: number,
|
trx?: Knex.Transaction,
|
||||||
// primaryBranchId: number,
|
) => {
|
||||||
// trx?: Knex.Transaction
|
// Updates the sale receipt with primary branch.
|
||||||
// ) => {
|
await this.saleReceiptModel()
|
||||||
// const { SaleReceipt } = this.tenancy.models(tenantId);
|
.query(trx)
|
||||||
|
.update({ branchId: primaryBranchId });
|
||||||
// // Updates the sale receipt with primary branch.
|
};
|
||||||
// await SaleReceipt.query(trx).update({ branchId: primaryBranchId });
|
}
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,75 +1,65 @@
|
|||||||
// import { ServiceError } from '@/exceptions';
|
import { ServiceError } from '@/modules/Items/ServiceError';
|
||||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
import { BranchesSettingsService } from '../BranchesSettings';
|
||||||
// import { Service, Inject } from 'typedi';
|
import { ERRORS } from './constants';
|
||||||
// import { BranchesSettings } from '../BranchesSettings';
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
// import { ERRORS } from './constants';
|
import { Branch } from '../models/Branch.model';
|
||||||
|
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class ValidateBranchExistance {
|
export class ValidateBranchExistance {
|
||||||
// @Inject()
|
constructor(
|
||||||
// tenancy: HasTenancyService;
|
private readonly branchesSettings: BranchesSettingsService,
|
||||||
|
|
||||||
// @Inject()
|
@Inject(Branch.name)
|
||||||
// branchesSettings: BranchesSettings;
|
private readonly branchModel: TenantModelProxy<typeof Branch>,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Validate transaction branch id when the feature is active.
|
* Validate transaction branch id when the feature is active.
|
||||||
// * @param {number} tenantId
|
* @param {number} branchId
|
||||||
// * @param {number} branchId
|
* @returns {Promise<void>}
|
||||||
// * @returns {Promise<void>}
|
*/
|
||||||
// */
|
public validateTransactionBranchWhenActive = async (
|
||||||
// public validateTransactionBranchWhenActive = async (
|
branchId: number | null,
|
||||||
// tenantId: number,
|
) => {
|
||||||
// branchId: number | null
|
const isActive = this.branchesSettings.isMultiBranchesActive();
|
||||||
// ) => {
|
|
||||||
// const isActive = this.branchesSettings.isMultiBranchesActive(tenantId);
|
|
||||||
|
|
||||||
// // Can't continue if the multi-warehouses feature is inactive.
|
// Can't continue if the multi-warehouses feature is inactive.
|
||||||
// if (!isActive) return;
|
if (!isActive) return;
|
||||||
|
|
||||||
// return this.validateTransactionBranch(tenantId, branchId);
|
return this.validateTransactionBranch(branchId);
|
||||||
// };
|
};
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Validate transaction branch id existance.
|
* Validate transaction branch id existance.
|
||||||
// * @param {number} tenantId
|
* @param {number} branchId
|
||||||
// * @param {number} branchId
|
* @return {Promise<void>}
|
||||||
// * @return {Promise<void>}
|
*/
|
||||||
// */
|
public validateTransactionBranch = async (branchId: number | null) => {
|
||||||
// public validateTransactionBranch = async (
|
this.validateBranchIdExistance(branchId);
|
||||||
// tenantId: number,
|
|
||||||
// branchId: number | null
|
|
||||||
// ) => {
|
|
||||||
// this.validateBranchIdExistance(branchId);
|
|
||||||
|
|
||||||
// await this.validateBranchExistance(tenantId, branchId);
|
await this.validateBranchExistance(branchId);
|
||||||
// };
|
};
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// *
|
* Validates the branch id existance.
|
||||||
// * @param branchId
|
* @param {number} branchId
|
||||||
// */
|
*/
|
||||||
// public validateBranchIdExistance = (branchId: number | null) => {
|
public validateBranchIdExistance = (branchId: number | null) => {
|
||||||
// if (!branchId) {
|
if (!branchId) {
|
||||||
// throw new ServiceError(ERRORS.BRANCH_ID_REQUIRED);
|
throw new ServiceError(ERRORS.BRANCH_ID_REQUIRED);
|
||||||
// }
|
}
|
||||||
// };
|
};
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// *
|
* Validates the branch id existance.
|
||||||
// * @param tenantId
|
* @param {number} branchId
|
||||||
// * @param branchId
|
*/
|
||||||
// */
|
public validateBranchExistance = async (branchId: number) => {
|
||||||
// public validateBranchExistance = async (
|
const branch = await this.branchModel().query().findById(branchId);
|
||||||
// tenantId: number,
|
|
||||||
// branchId: number
|
|
||||||
// ) => {
|
|
||||||
// const { Branch } = this.tenancy.models(tenantId);
|
|
||||||
|
|
||||||
// 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 { OnEvent } from '@nestjs/event-emitter';
|
||||||
// import { Service, Inject } from 'typedi';
|
import { Injectable } from '@nestjs/common';
|
||||||
// import events from '@/subscribers/events';
|
import { CashflowTransactionsActivateBranches } from '../../Integrations/Cashflow/CashflowActivateBranches';
|
||||||
// import { CashflowTransactionsActivateBranches } from '../../Integrations/Cashflow/CashflowActivateBranches';
|
import { IBranchesActivatedPayload } from '../../Branches.types';
|
||||||
|
import { events } from '@/common/events/events';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class CreditNoteActivateBranchesSubscriber {
|
export class CreditNoteActivateBranchesSubscriber {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private cashflowActivateBranches: CashflowTransactionsActivateBranches;
|
private readonly cashflowActivateBranches: CashflowTransactionsActivateBranches,
|
||||||
|
) {}
|
||||||
// /**
|
|
||||||
// * Attaches events with handlers.
|
/**
|
||||||
// */
|
* Updates accounts transactions with the primary branch once
|
||||||
// public attach(bus) {
|
* the multi-branches is activated.
|
||||||
// bus.subscribe(
|
* @param {IBranchesActivatedPayload}
|
||||||
// events.branch.onActivated,
|
*/
|
||||||
// this.updateCashflowWithBranchOnActivated
|
@OnEvent(events.branch.onActivated)
|
||||||
// );
|
async updateCashflowWithBranchOnActivated({
|
||||||
// return bus;
|
|
||||||
// }
|
primaryBranch,
|
||||||
|
trx,
|
||||||
// /**
|
}: IBranchesActivatedPayload) {
|
||||||
// * Updates accounts transactions with the primary branch once
|
await this.cashflowActivateBranches.updateCashflowTransactionsWithBranch(
|
||||||
// * the multi-branches is activated.
|
primaryBranch.id,
|
||||||
// * @param {IBranchesActivatedPayload}
|
trx
|
||||||
// */
|
);
|
||||||
// private updateCashflowWithBranchOnActivated = async ({
|
};
|
||||||
// tenantId,
|
}
|
||||||
// primaryBranch,
|
|
||||||
// trx,
|
|
||||||
// }: IBranchesActivatedPayload) => {
|
|
||||||
// await this.cashflowActivateBranches.updateCashflowTransactionsWithBranch(
|
|
||||||
// tenantId,
|
|
||||||
// primaryBranch.id,
|
|
||||||
// trx
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,38 +1,28 @@
|
|||||||
// import { IBranchesActivatedPayload } from '@/interfaces';
|
import { events } from '@/common/events/events';
|
||||||
// import { Service, Inject } from 'typedi';
|
import { OnEvent } from '@nestjs/event-emitter';
|
||||||
// import { CreditNoteActivateBranches } from '../../Integrations/Sales/CreditNoteBranchesActivate';
|
import { IBranchesActivatedPayload } from '../../Branches.types';
|
||||||
// import events from '@/subscribers/events';
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { CreditNoteActivateBranches } from '../../integrations/Sales/CreditNoteBranchesActivate';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class CreditNoteActivateBranchesSubscriber {
|
export class CreditNoteActivateBranchesSubscriber {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private creditNotesActivateBranches: CreditNoteActivateBranches;
|
private readonly creditNotesActivateBranches: CreditNoteActivateBranches,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Attaches events with handlers.
|
* Updates accounts transactions with the primary branch once
|
||||||
// */
|
* the multi-branches is activated.
|
||||||
// public attach(bus) {
|
* @param {IBranchesActivatedPayload}
|
||||||
// bus.subscribe(
|
*/
|
||||||
// events.branch.onActivated,
|
@OnEvent(events.branch.onActivated)
|
||||||
// this.updateCreditNoteWithBranchOnActivated
|
async updateCreditNoteWithBranchOnActivated({
|
||||||
// );
|
primaryBranch,
|
||||||
// return bus;
|
trx,
|
||||||
// }
|
}: IBranchesActivatedPayload) {
|
||||||
|
await this.creditNotesActivateBranches.updateCreditsWithBranch(
|
||||||
// /**
|
primaryBranch.id,
|
||||||
// * Updates accounts transactions with the primary branch once
|
trx
|
||||||
// * the multi-branches is activated.
|
);
|
||||||
// * @param {IBranchesActivatedPayload}
|
};
|
||||||
// */
|
}
|
||||||
// private updateCreditNoteWithBranchOnActivated = async ({
|
|
||||||
// tenantId,
|
|
||||||
// primaryBranch,
|
|
||||||
// trx,
|
|
||||||
// }: IBranchesActivatedPayload) => {
|
|
||||||
// await this.creditNotesActivateBranches.updateCreditsWithBranch(
|
|
||||||
// tenantId,
|
|
||||||
// primaryBranch.id,
|
|
||||||
// trx
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,38 +1,28 @@
|
|||||||
// import { IBranchesActivatedPayload } from '@/interfaces';
|
import { IBranchesActivatedPayload } from '../../Branches.types';
|
||||||
// import { Service, Inject } from 'typedi';
|
import { events } from '@/common/events/events';
|
||||||
// import events from '@/subscribers/events';
|
import { Injectable } from '@nestjs/common';
|
||||||
// import { ExpensesActivateBranches } from '../../Integrations/Expense/ExpensesActivateBranches';
|
import { ExpensesActivateBranches } from '../../Integrations/Expense/ExpensesActivateBranches';
|
||||||
|
import { OnEvent } from '@nestjs/event-emitter';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class ExpenseActivateBranchesSubscriber {
|
export class ExpenseActivateBranchesSubscriber {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private expensesActivateBranches: ExpensesActivateBranches;
|
private readonly expensesActivateBranches: ExpensesActivateBranches,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Attaches events with handlers.
|
* Updates accounts transactions with the primary branch once
|
||||||
// */
|
* the multi-branches is activated.
|
||||||
// public attach(bus) {
|
* @param {IBranchesActivatedPayload}
|
||||||
// bus.subscribe(
|
*/
|
||||||
// events.branch.onActivated,
|
@OnEvent(events.branch.onActivated)
|
||||||
// this.updateExpensesWithBranchOnActivated
|
async updateExpensesWithBranchOnActivated({
|
||||||
// );
|
primaryBranch,
|
||||||
// return bus;
|
trx,
|
||||||
// }
|
}: IBranchesActivatedPayload) {
|
||||||
|
await this.expensesActivateBranches.updateExpensesWithBranch(
|
||||||
// /**
|
primaryBranch.id,
|
||||||
// * Updates accounts transactions with the primary branch once
|
trx,
|
||||||
// * the multi-branches is activated.
|
);
|
||||||
// * @param {IBranchesActivatedPayload}
|
}
|
||||||
// */
|
}
|
||||||
// private updateExpensesWithBranchOnActivated = async ({
|
|
||||||
// tenantId,
|
|
||||||
// primaryBranch,
|
|
||||||
// trx,
|
|
||||||
// }: IBranchesActivatedPayload) => {
|
|
||||||
// await this.expensesActivateBranches.updateExpensesWithBranch(
|
|
||||||
// tenantId,
|
|
||||||
// primaryBranch.id,
|
|
||||||
// trx
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,38 +1,28 @@
|
|||||||
// import { IBranchesActivatedPayload } from '@/interfaces';
|
import { BillPaymentsActivateBranches } from '../../Integrations/Purchases/PaymentMadeBranchesActivate';
|
||||||
// import { Service, Inject } from 'typedi';
|
import { OnEvent } from '@nestjs/event-emitter';
|
||||||
// import events from '@/subscribers/events';
|
import { Injectable } from '@nestjs/common';
|
||||||
// import { BillPaymentsActivateBranches } from '../../Integrations/Purchases/PaymentMadeBranchesActivate';
|
import { events } from '@/common/events/events';
|
||||||
|
import { IBranchesActivatedPayload } from '../../Branches.types';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class PaymentMadeActivateBranchesSubscriber {
|
export class PaymentMadeActivateBranchesSubscriber {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private paymentsActivateBranches: BillPaymentsActivateBranches;
|
private readonly paymentsActivateBranches: BillPaymentsActivateBranches,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Attaches events with handlers.
|
* Updates accounts transactions with the primary branch once
|
||||||
// */
|
* the multi-branches is activated.
|
||||||
// public attach(bus) {
|
* @param {IBranchesActivatedPayload}
|
||||||
// bus.subscribe(
|
*/
|
||||||
// events.branch.onActivated,
|
@OnEvent(events.branch.onActivated)
|
||||||
// this.updatePaymentsWithBranchOnActivated
|
async updatePaymentsWithBranchOnActivated({
|
||||||
// );
|
primaryBranch,
|
||||||
// return bus;
|
trx,
|
||||||
// }
|
}: IBranchesActivatedPayload) {
|
||||||
|
await this.paymentsActivateBranches.updateBillPaymentsWithBranch(
|
||||||
// /**
|
primaryBranch.id,
|
||||||
// * Updates accounts transactions with the primary branch once
|
trx,
|
||||||
// * the multi-branches is activated.
|
);
|
||||||
// * @param {IBranchesActivatedPayload}
|
}
|
||||||
// */
|
}
|
||||||
// private updatePaymentsWithBranchOnActivated = async ({
|
|
||||||
// tenantId,
|
|
||||||
// primaryBranch,
|
|
||||||
// trx,
|
|
||||||
// }: IBranchesActivatedPayload) => {
|
|
||||||
// await this.paymentsActivateBranches.updateBillPaymentsWithBranch(
|
|
||||||
// tenantId,
|
|
||||||
// primaryBranch.id,
|
|
||||||
// trx
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,38 +1,28 @@
|
|||||||
// import { IBranchesActivatedPayload } from '@/interfaces';
|
import { events } from '@/common/events/events';
|
||||||
// import { Service, Inject } from 'typedi';
|
import { Injectable } from '@nestjs/common';
|
||||||
// import events from '@/subscribers/events';
|
import { OnEvent } from '@nestjs/event-emitter';
|
||||||
// import { PaymentReceiveActivateBranches } from '../../Integrations/Sales/PaymentReceiveBranchesActivate';
|
import { IBranchesActivatedPayload } from '../../Branches.types';
|
||||||
|
import { PaymentReceiveActivateBranches } from '../../integrations/Sales/PaymentReceiveBranchesActivate';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class PaymentReceiveActivateBranchesSubscriber {
|
export class PaymentReceiveActivateBranchesSubscriber {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private paymentsActivateBranches: PaymentReceiveActivateBranches;
|
private readonly paymentsActivateBranches: PaymentReceiveActivateBranches,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Attaches events with handlers.
|
* Updates accounts transactions with the primary branch once
|
||||||
// */
|
* the multi-branches is activated.
|
||||||
// public attach(bus) {
|
* @param {IBranchesActivatedPayload}
|
||||||
// bus.subscribe(
|
*/
|
||||||
// events.branch.onActivated,
|
@OnEvent(events.branch.onActivated)
|
||||||
// this.updateCreditNoteWithBranchOnActivated
|
async updateCreditNoteWithBranchOnActivated({
|
||||||
// );
|
primaryBranch,
|
||||||
// return bus;
|
trx,
|
||||||
// }
|
}: IBranchesActivatedPayload) {
|
||||||
|
await this.paymentsActivateBranches.updatePaymentsWithBranch(
|
||||||
// /**
|
primaryBranch.id,
|
||||||
// * Updates accounts transactions with the primary branch once
|
trx
|
||||||
// * the multi-branches is activated.
|
);
|
||||||
// * @param {IBranchesActivatedPayload}
|
};
|
||||||
// */
|
}
|
||||||
// private updateCreditNoteWithBranchOnActivated = async ({
|
|
||||||
// tenantId,
|
|
||||||
// primaryBranch,
|
|
||||||
// trx,
|
|
||||||
// }: IBranchesActivatedPayload) => {
|
|
||||||
// await this.paymentsActivateBranches.updatePaymentsWithBranch(
|
|
||||||
// tenantId,
|
|
||||||
// primaryBranch.id,
|
|
||||||
// trx
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,38 +1,28 @@
|
|||||||
// import { IBranchesActivatedPayload } from '@/interfaces';
|
import { OnEvent } from '@nestjs/event-emitter';
|
||||||
// import { Service, Inject } from 'typedi';
|
import { Injectable } from '@nestjs/common';
|
||||||
// import events from '@/subscribers/events';
|
import { IBranchesActivatedPayload } from '../../Branches.types';
|
||||||
// import { SaleEstimateActivateBranches } from '../../Integrations/Sales/SaleEstimatesBranchesActivate';
|
import { events } from '@/common/events/events';
|
||||||
|
import { SaleEstimateActivateBranches } from '../../integrations/Sales/SaleEstimatesBranchesActivate';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class SaleEstimatesActivateBranchesSubscriber {
|
export class SaleEstimatesActivateBranchesSubscriber {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private estimatesActivateBranches: SaleEstimateActivateBranches;
|
private readonly estimatesActivateBranches: SaleEstimateActivateBranches,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Attaches events with handlers.
|
* Updates accounts transactions with the primary branch once
|
||||||
// */
|
* the multi-branches is activated.
|
||||||
// public attach(bus) {
|
* @param {IBranchesActivatedPayload}
|
||||||
// bus.subscribe(
|
*/
|
||||||
// events.branch.onActivated,
|
@OnEvent(events.branch.onActivated)
|
||||||
// this.updateEstimatesWithBranchOnActivated
|
async updateEstimatesWithBranchOnActivated({
|
||||||
// );
|
primaryBranch,
|
||||||
// return bus;
|
trx,
|
||||||
// }
|
}: IBranchesActivatedPayload) {
|
||||||
|
await this.estimatesActivateBranches.updateEstimatesWithBranch(
|
||||||
// /**
|
primaryBranch.id,
|
||||||
// * Updates accounts transactions with the primary branch once
|
trx
|
||||||
// * the multi-branches is activated.
|
);
|
||||||
// * @param {IBranchesActivatedPayload}
|
};
|
||||||
// */
|
}
|
||||||
// private updateEstimatesWithBranchOnActivated = async ({
|
|
||||||
// tenantId,
|
|
||||||
// primaryBranch,
|
|
||||||
// trx,
|
|
||||||
// }: IBranchesActivatedPayload) => {
|
|
||||||
// await this.estimatesActivateBranches.updateEstimatesWithBranch(
|
|
||||||
// tenantId,
|
|
||||||
// primaryBranch.id,
|
|
||||||
// trx
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,38 +1,28 @@
|
|||||||
// import { IBranchesActivatedPayload } from '@/interfaces';
|
import { events } from '@/common/events/events';
|
||||||
// import { Service, Inject } from 'typedi';
|
import { SaleInvoiceActivateBranches } from '../../Integrations/Sales/SaleInvoiceBranchesActivate';
|
||||||
// import events from '@/subscribers/events';
|
import { OnEvent } from '@nestjs/event-emitter';
|
||||||
// import { SaleInvoiceActivateBranches } from '../../Integrations/Sales/SaleInvoiceBranchesActivate';
|
import { IBranchesActivatedPayload } from '../../Branches.types';
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class SaleInvoicesActivateBranchesSubscriber {
|
export class SaleInvoicesActivateBranchesSubscriber {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private invoicesActivateBranches: SaleInvoiceActivateBranches;
|
private readonly invoicesActivateBranches: SaleInvoiceActivateBranches,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Attaches events with handlers.
|
* Updates accounts transactions with the primary branch once
|
||||||
// */
|
* the multi-branches is activated.
|
||||||
// public attach(bus) {
|
* @param {IBranchesActivatedPayload}
|
||||||
// bus.subscribe(
|
*/
|
||||||
// events.branch.onActivated,
|
@OnEvent(events.branch.onActivated)
|
||||||
// this.updateInvoicesWithBranchOnActivated
|
async updateInvoicesWithBranchOnActivated({
|
||||||
// );
|
primaryBranch,
|
||||||
// return bus;
|
trx,
|
||||||
// }
|
}: IBranchesActivatedPayload) {
|
||||||
|
await this.invoicesActivateBranches.updateInvoicesWithBranch(
|
||||||
// /**
|
primaryBranch.id,
|
||||||
// * Updates accounts transactions with the primary branch once
|
trx
|
||||||
// * the multi-branches is activated.
|
);
|
||||||
// * @param {IBranchesActivatedPayload}
|
};
|
||||||
// */
|
}
|
||||||
// private updateInvoicesWithBranchOnActivated = async ({
|
|
||||||
// tenantId,
|
|
||||||
// primaryBranch,
|
|
||||||
// trx,
|
|
||||||
// }: IBranchesActivatedPayload) => {
|
|
||||||
// await this.invoicesActivateBranches.updateInvoicesWithBranch(
|
|
||||||
// tenantId,
|
|
||||||
// primaryBranch.id,
|
|
||||||
// trx
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,38 +1,28 @@
|
|||||||
// import { IBranchesActivatedPayload } from '@/interfaces';
|
import { OnEvent } from '@nestjs/event-emitter';
|
||||||
// import { Service, Inject } from 'typedi';
|
import { Injectable } from '@nestjs/common';
|
||||||
// import events from '@/subscribers/events';
|
import { events } from '@/common/events/events';
|
||||||
// import { SaleReceiptActivateBranches } from '../../Integrations/Sales/SaleReceiptBranchesActivate';
|
import { IBranchesActivatedPayload } from '../../Branches.types';
|
||||||
|
import { SaleReceiptActivateBranches } from '../../integrations/Sales/SaleReceiptBranchesActivate';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class SaleReceiptsActivateBranchesSubscriber {
|
export class SaleReceiptsActivateBranchesSubscriber {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private receiptsActivateBranches: SaleReceiptActivateBranches;
|
private readonly receiptsActivateBranches: SaleReceiptActivateBranches,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Attaches events with handlers.
|
* Updates accounts transactions with the primary branch once
|
||||||
// */
|
* the multi-branches is activated.
|
||||||
// public attach(bus) {
|
* @param {IBranchesActivatedPayload}
|
||||||
// bus.subscribe(
|
*/
|
||||||
// events.branch.onActivated,
|
@OnEvent(events.branch.onActivated)
|
||||||
// this.updateReceiptsWithBranchOnActivated
|
async updateReceiptsWithBranchOnActivated({
|
||||||
// );
|
primaryBranch,
|
||||||
// return bus;
|
trx,
|
||||||
// }
|
}: IBranchesActivatedPayload) {
|
||||||
|
await this.receiptsActivateBranches.updateReceiptsWithBranch(
|
||||||
// /**
|
primaryBranch.id,
|
||||||
// * Updates accounts transactions with the primary branch once
|
trx,
|
||||||
// * the multi-branches is activated.
|
);
|
||||||
// * @param {IBranchesActivatedPayload}
|
}
|
||||||
// */
|
}
|
||||||
// private updateReceiptsWithBranchOnActivated = async ({
|
|
||||||
// tenantId,
|
|
||||||
// primaryBranch,
|
|
||||||
// trx,
|
|
||||||
// }: IBranchesActivatedPayload) => {
|
|
||||||
// await this.receiptsActivateBranches.updateReceiptsWithBranch(
|
|
||||||
// tenantId,
|
|
||||||
// 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 { Injectable } from '@nestjs/common';
|
||||||
// import events from '@/subscribers/events';
|
import { OnEvent } from '@nestjs/event-emitter';
|
||||||
// import { IBillCreatingPayload, IBillEditingPayload } from '@/interfaces';
|
import { events } from '@/common/events/events';
|
||||||
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||||
|
import {
|
||||||
|
IBillCreatingPayload,
|
||||||
|
IBillEditingPayload,
|
||||||
|
} from '@/modules/Bills/Bills.types';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class BillBranchValidateSubscriber {
|
export class BillBranchValidateSubscriber {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private validateBranchExistance: ValidateBranchExistance;
|
private readonly validateBranchExistance: ValidateBranchExistance,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Attaches events with handlers.
|
* Validate branch existance on bill creating.
|
||||||
// */
|
* @param {IBillCreatingPayload} payload
|
||||||
// public attach = (bus) => {
|
*/
|
||||||
// bus.subscribe(
|
@OnEvent(events.bill.onCreating)
|
||||||
// events.bill.onCreating,
|
async validateBranchExistanceOnBillCreating({
|
||||||
// this.validateBranchExistanceOnBillCreating
|
billDTO,
|
||||||
// );
|
}: IBillCreatingPayload) {
|
||||||
// bus.subscribe(
|
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||||
// events.bill.onEditing,
|
billDTO.branchId,
|
||||||
// this.validateBranchExistanceOnBillEditing
|
);
|
||||||
// );
|
}
|
||||||
// return bus;
|
|
||||||
// };
|
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Validate branch existance on estimate creating.
|
* Validate branch existance once bill editing.
|
||||||
// * @param {ISaleEstimateCreatedPayload} payload
|
* @param {IBillEditingPayload} payload
|
||||||
// */
|
*/
|
||||||
// private validateBranchExistanceOnBillCreating = async ({
|
@OnEvent(events.bill.onEditing)
|
||||||
// tenantId,
|
async validateBranchExistanceOnBillEditing({ billDTO }: IBillEditingPayload) {
|
||||||
// billDTO,
|
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||||
// }: IBillCreatingPayload) => {
|
billDTO.branchId,
|
||||||
// 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
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,35 +1,25 @@
|
|||||||
// import { Inject, Service } from 'typedi';
|
import { Injectable } from '@nestjs/common';
|
||||||
// import events from '@/subscribers/events';
|
import { OnEvent } from '@nestjs/event-emitter';
|
||||||
// import { ICommandCashflowCreatingPayload } from '@/interfaces';
|
import { events } from '@/common/events/events';
|
||||||
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||||
|
import { ICommandCashflowCreatingPayload } from '@/modules/BankingTransactions/types/BankingTransactions.types';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class CashflowBranchDTOValidatorSubscriber {
|
export class CashflowBranchDTOValidatorSubscriber {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private validateBranchExistance: ValidateBranchExistance;
|
private readonly validateBranchExistance: ValidateBranchExistance,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Attaches events with handlers.
|
* Validate branch existance once cashflow transaction creating.
|
||||||
// */
|
* @param {ICommandCashflowCreatingPayload} payload
|
||||||
// public attach = (bus) => {
|
*/
|
||||||
// bus.subscribe(
|
@OnEvent(events.cashflow.onTransactionCreating)
|
||||||
// events.cashflow.onTransactionCreating,
|
async validateBranchExistanceOnCashflowTransactionCreating({
|
||||||
// this.validateBranchExistanceOnCashflowTransactionCreating
|
newTransactionDTO,
|
||||||
// );
|
}: ICommandCashflowCreatingPayload) {
|
||||||
// return bus;
|
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||||
// };
|
newTransactionDTO.branchId,
|
||||||
|
);
|
||||||
// /**
|
}
|
||||||
// * Validate branch existance once cashflow transaction creating.
|
}
|
||||||
// * @param {ICommandCashflowCreatingPayload} payload
|
|
||||||
// */
|
|
||||||
// private validateBranchExistanceOnCashflowTransactionCreating = async ({
|
|
||||||
// tenantId,
|
|
||||||
// newTransactionDTO,
|
|
||||||
// }: ICommandCashflowCreatingPayload) => {
|
|
||||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
|
||||||
// tenantId,
|
|
||||||
// newTransactionDTO.branchId
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,104 +1,81 @@
|
|||||||
// import { Inject, Service } from 'typedi';
|
import { Injectable } from '@nestjs/common';
|
||||||
// import events from '@/subscribers/events';
|
import { OnEvent } from '@nestjs/event-emitter';
|
||||||
// import {
|
import { events } from '@/common/events/events';
|
||||||
// ICustomerEventCreatingPayload,
|
import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||||
// ICustomerOpeningBalanceEditingPayload,
|
import {
|
||||||
// IVendorEventCreatingPayload,
|
ICustomerOpeningBalanceEditingPayload,
|
||||||
// IVendorOpeningBalanceEditingPayload,
|
ICustomerEventCreatingPayload,
|
||||||
// } from '@/interfaces';
|
} from '@/modules/Customers/types/Customers.types';
|
||||||
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
import {
|
||||||
|
IVendorEventCreatingPayload,
|
||||||
|
IVendorOpeningBalanceEditingPayload,
|
||||||
|
} from '@/modules/Vendors/types/Vendors.types';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class ContactBranchValidateSubscriber {
|
export class ContactBranchValidateSubscriber {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private validateBranchExistance: ValidateBranchExistance;
|
private readonly validateBranchExistance: ValidateBranchExistance,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Attaches events with handlers.
|
* Validate branch existance on customer creating.
|
||||||
// */
|
* @param {ICustomerEventCreatingPayload} payload
|
||||||
// public attach = (bus) => {
|
*/
|
||||||
// bus.subscribe(
|
@OnEvent(events.customers.onCreating)
|
||||||
// events.customers.onCreating,
|
async validateBranchExistanceOnCustomerCreating({
|
||||||
// this.validateBranchExistanceOnCustomerCreating
|
customerDTO,
|
||||||
// );
|
}: ICustomerEventCreatingPayload) {
|
||||||
// bus.subscribe(
|
// Can't continue if the customer opening balance is zero.
|
||||||
// events.customers.onOpeningBalanceChanging,
|
if (!customerDTO.openingBalance) return;
|
||||||
// this.validateBranchExistanceOnCustomerOpeningBalanceEditing
|
|
||||||
// );
|
|
||||||
// bus.subscribe(
|
|
||||||
// events.vendors.onCreating,
|
|
||||||
// this.validateBranchExistanceonVendorCreating
|
|
||||||
// );
|
|
||||||
// bus.subscribe(
|
|
||||||
// events.vendors.onOpeningBalanceChanging,
|
|
||||||
// this.validateBranchExistanceOnVendorOpeningBalanceEditing
|
|
||||||
// );
|
|
||||||
// return bus;
|
|
||||||
// };
|
|
||||||
|
|
||||||
// /**
|
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||||
// * Validate branch existance on customer creating.
|
customerDTO.openingBalanceBranchId,
|
||||||
// * @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(
|
/**
|
||||||
// tenantId,
|
* Validate branch existance once customer opening balance editing.
|
||||||
// customerDTO.openingBalanceBranchId
|
* @param {ICustomerOpeningBalanceEditingPayload} payload
|
||||||
// );
|
*/
|
||||||
// };
|
@OnEvent(events.customers.onOpeningBalanceChanging)
|
||||||
|
async validateBranchExistanceOnCustomerOpeningBalanceEditing({
|
||||||
|
openingBalanceEditDTO,
|
||||||
|
}: ICustomerOpeningBalanceEditingPayload) {
|
||||||
|
if (!openingBalanceEditDTO.openingBalance) return;
|
||||||
|
|
||||||
// /**
|
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||||
// * Validate branch existance once customer opening balance editing.
|
openingBalanceEditDTO.openingBalanceBranchId,
|
||||||
// * @param {ICustomerOpeningBalanceEditingPayload} payload
|
);
|
||||||
// */
|
}
|
||||||
// private validateBranchExistanceOnCustomerOpeningBalanceEditing = async ({
|
|
||||||
// openingBalanceEditDTO,
|
|
||||||
// tenantId,
|
|
||||||
// }: ICustomerOpeningBalanceEditingPayload) => {
|
|
||||||
// if (!openingBalanceEditDTO.openingBalance) return;
|
|
||||||
|
|
||||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
/**
|
||||||
// tenantId,
|
* Validates the branch existance on vendor creating.
|
||||||
// openingBalanceEditDTO.openingBalanceBranchId
|
* @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;
|
||||||
|
|
||||||
// /**
|
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||||
// * Validates the branch existance on vendor creating.
|
vendorDTO.openingBalanceBranchId,
|
||||||
// * @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(
|
/**
|
||||||
// tenantId,
|
* Validate branch existance once the vendor opening balance editing.
|
||||||
// vendorDTO.openingBalanceBranchId
|
* @param {IVendorOpeningBalanceEditingPayload} payload
|
||||||
// );
|
*/
|
||||||
// };
|
@OnEvent(events.vendors.onOpeningBalanceChanging)
|
||||||
|
async validateBranchExistanceOnVendorOpeningBalanceEditing({
|
||||||
|
openingBalanceEditDTO,
|
||||||
|
}: IVendorOpeningBalanceEditingPayload) {
|
||||||
|
if (!openingBalanceEditDTO.openingBalance) return;
|
||||||
|
|
||||||
// /**
|
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||||
// * Validate branch existance once the vendor opening balance editing.
|
openingBalanceEditDTO.openingBalanceBranchId,
|
||||||
// * @param {IVendorOpeningBalanceEditingPayload}
|
);
|
||||||
// */
|
}
|
||||||
// private validateBranchExistanceOnVendorOpeningBalanceEditing = async ({
|
}
|
||||||
// tenantId,
|
|
||||||
// openingBalanceEditDTO,
|
|
||||||
// }: IVendorOpeningBalanceEditingPayload) => {
|
|
||||||
// if (!openingBalanceEditDTO.openingBalance) return;
|
|
||||||
|
|
||||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
|
||||||
// tenantId,
|
|
||||||
// openingBalanceEditDTO.openingBalanceBranchId
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,56 +1,39 @@
|
|||||||
// import { Inject, Service } from 'typedi';
|
import { Injectable } from '@nestjs/common';
|
||||||
// import events from '@/subscribers/events';
|
import { OnEvent } from '@nestjs/event-emitter';
|
||||||
// import {
|
import { events } from '@/common/events/events';
|
||||||
// ICreditNoteCreatingPayload,
|
import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||||
// ICreditNoteEditingPayload,
|
import { ICreditNoteEditingPayload } from '@/modules/CreditNotes/types/CreditNotes.types';
|
||||||
// } from '@/interfaces';
|
import { ICreditNoteCreatingPayload } from '@/modules/CreditNotes/types/CreditNotes.types';
|
||||||
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class CreditNoteBranchValidateSubscriber {
|
export class CreditNoteBranchValidateSubscriber {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private validateBranchExistance: ValidateBranchExistance;
|
private readonly validateBranchExistance: ValidateBranchExistance,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Attaches events with handlers.
|
* Validate branch existance on credit note creating.
|
||||||
// */
|
* @param {ICreditNoteCreatingPayload} payload
|
||||||
// public attach = (bus) => {
|
*/
|
||||||
// bus.subscribe(
|
@OnEvent(events.creditNote.onCreating)
|
||||||
// events.creditNote.onCreating,
|
async validateBranchExistanceOnCreditCreating({
|
||||||
// this.validateBranchExistanceOnCreditCreating
|
creditNoteDTO,
|
||||||
// );
|
}: ICreditNoteCreatingPayload) {
|
||||||
// bus.subscribe(
|
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||||
// events.creditNote.onEditing,
|
creditNoteDTO.branchId,
|
||||||
// this.validateBranchExistanceOnCreditEditing
|
);
|
||||||
// );
|
}
|
||||||
// return bus;
|
|
||||||
// };
|
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Validate branch existance on estimate creating.
|
* Validate branch existance once credit note editing.
|
||||||
// * @param {ICreditNoteCreatingPayload} payload
|
* @param {ICreditNoteEditingPayload} payload
|
||||||
// */
|
*/
|
||||||
// private validateBranchExistanceOnCreditCreating = async ({
|
@OnEvent(events.creditNote.onEditing)
|
||||||
// tenantId,
|
async validateBranchExistanceOnCreditEditing({
|
||||||
// creditNoteDTO,
|
creditNoteEditDTO,
|
||||||
// }: ICreditNoteCreatingPayload) => {
|
}: ICreditNoteEditingPayload) {
|
||||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||||
// tenantId,
|
creditNoteEditDTO.branchId,
|
||||||
// creditNoteDTO.branchId
|
);
|
||||||
// );
|
}
|
||||||
// };
|
}
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Validate branch existance once estimate editing.
|
|
||||||
// * @param {ISaleEstimateEditingPayload} payload
|
|
||||||
// */
|
|
||||||
// private validateBranchExistanceOnCreditEditing = async ({
|
|
||||||
// creditNoteEditDTO,
|
|
||||||
// tenantId,
|
|
||||||
// }: ICreditNoteEditingPayload) => {
|
|
||||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
|
||||||
// tenantId,
|
|
||||||
// creditNoteEditDTO.branchId
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,35 +1,25 @@
|
|||||||
// import { Inject, Service } from 'typedi';
|
import { Injectable } from '@nestjs/common';
|
||||||
// import events from '@/subscribers/events';
|
import { OnEvent } from '@nestjs/event-emitter';
|
||||||
// import { IRefundCreditNoteCreatingPayload } from '@/interfaces';
|
import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||||
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
import { events } from '@/common/events/events';
|
||||||
|
import { IRefundCreditNoteCreatingPayload } from '@/modules/CreditNoteRefunds/types/CreditNoteRefunds.types';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class CreditNoteRefundBranchValidateSubscriber {
|
export class CreditNoteRefundBranchValidateSubscriber {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private validateBranchExistance: ValidateBranchExistance;
|
private readonly validateBranchExistance: ValidateBranchExistance
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Attaches events with handlers.
|
* Validate branch existance on refund credit note creating.
|
||||||
// */
|
* @param {IRefundCreditNoteCreatingPayload} payload
|
||||||
// public attach = (bus) => {
|
*/
|
||||||
// bus.subscribe(
|
@OnEvent(events.creditNote.onRefundCreating)
|
||||||
// events.creditNote.onRefundCreating,
|
async validateBranchExistanceOnCreditRefundCreating({
|
||||||
// this.validateBranchExistanceOnCreditRefundCreating
|
newCreditNoteDTO,
|
||||||
// );
|
}: IRefundCreditNoteCreatingPayload) {
|
||||||
// return bus;
|
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||||
// };
|
newCreditNoteDTO.branchId
|
||||||
|
);
|
||||||
// /**
|
}
|
||||||
// * Validate branch existance on refund credit note creating.
|
}
|
||||||
// * @param {ICreditNoteCreatingPayload} payload
|
|
||||||
// */
|
|
||||||
// private validateBranchExistanceOnCreditRefundCreating = async ({
|
|
||||||
// tenantId,
|
|
||||||
// newCreditNoteDTO,
|
|
||||||
// }: IRefundCreditNoteCreatingPayload) => {
|
|
||||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
|
||||||
// tenantId,
|
|
||||||
// newCreditNoteDTO.branchId
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,56 +1,40 @@
|
|||||||
// import { Inject, Service } from 'typedi';
|
import { Injectable } from '@nestjs/common';
|
||||||
// import events from '@/subscribers/events';
|
import { OnEvent } from '@nestjs/event-emitter';
|
||||||
// import {
|
import { events } from '@/common/events/events';
|
||||||
// IExpenseCreatingPayload,
|
import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||||
// IExpenseEventEditingPayload,
|
import {
|
||||||
// } from '@/interfaces';
|
IExpenseCreatingPayload,
|
||||||
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
IExpenseEventEditingPayload,
|
||||||
|
} from '@/modules/Expenses/Expenses.types';
|
||||||
|
@Injectable()
|
||||||
|
export class ExpenseBranchValidateSubscriber {
|
||||||
|
constructor(
|
||||||
|
private readonly validateBranchExistance: ValidateBranchExistance,
|
||||||
|
) {}
|
||||||
|
|
||||||
// @Service()
|
/**
|
||||||
// export class ExpenseBranchValidateSubscriber {
|
* Validate branch existance once expense transaction creating.
|
||||||
// @Inject()
|
* @param {IExpenseCreatingPayload} payload
|
||||||
// private validateBranchExistance: ValidateBranchExistance;
|
*/
|
||||||
|
@OnEvent(events.expenses.onCreating)
|
||||||
|
async validateBranchExistanceOnExpenseCreating({
|
||||||
|
expenseDTO,
|
||||||
|
}: IExpenseCreatingPayload) {
|
||||||
|
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||||
|
expenseDTO.branchId,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Attaches events with handlers.
|
* Validate branch existance once expense transaction editing.
|
||||||
// */
|
* @param {IExpenseEventEditingPayload} payload
|
||||||
// public attach = (bus) => {
|
*/
|
||||||
// bus.subscribe(
|
@OnEvent(events.expenses.onEditing)
|
||||||
// events.expenses.onCreating,
|
async validateBranchExistanceOnExpenseEditing({
|
||||||
// this.validateBranchExistanceOnExpenseCreating
|
expenseDTO,
|
||||||
// );
|
}: IExpenseEventEditingPayload) {
|
||||||
// bus.subscribe(
|
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||||
// events.expenses.onEditing,
|
expenseDTO.branchId,
|
||||||
// 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
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,35 +1,25 @@
|
|||||||
// import { Inject, Service } from 'typedi';
|
import { Injectable } from '@nestjs/common';
|
||||||
// import events from '@/subscribers/events';
|
import { OnEvent } from '@nestjs/event-emitter';
|
||||||
// import { IInventoryAdjustmentCreatingPayload } from '@/interfaces';
|
import { events } from '@/common/events/events';
|
||||||
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||||
|
import { IInventoryAdjustmentCreatingPayload } from '@/modules/InventoryAdjutments/types/InventoryAdjustments.types';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class InventoryAdjustmentBranchValidateSubscriber {
|
export class InventoryAdjustmentBranchValidateSubscriber {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private validateBranchExistance: ValidateBranchExistance;
|
private readonly validateBranchExistance: ValidateBranchExistance,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Attaches events with handlers.
|
* Validate branch existance on inventory adjustment creating.
|
||||||
// */
|
* @param {IInventoryAdjustmentCreatingPayload} payload
|
||||||
// public attach = (bus) => {
|
*/
|
||||||
// bus.subscribe(
|
@OnEvent(events.inventoryAdjustment.onQuickCreating)
|
||||||
// events.inventoryAdjustment.onQuickCreating,
|
async validateBranchExistanceOnInventoryCreating({
|
||||||
// this.validateBranchExistanceOnInventoryCreating
|
quickAdjustmentDTO,
|
||||||
// );
|
}: IInventoryAdjustmentCreatingPayload) {
|
||||||
// return bus;
|
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||||
// };
|
quickAdjustmentDTO.branchId,
|
||||||
|
);
|
||||||
// /**
|
}
|
||||||
// * Validate branch existance on invoice creating.
|
}
|
||||||
// * @param {ISaleInvoiceCreatingPaylaod} payload
|
|
||||||
// */
|
|
||||||
// private validateBranchExistanceOnInventoryCreating = async ({
|
|
||||||
// tenantId,
|
|
||||||
// quickAdjustmentDTO,
|
|
||||||
// }: IInventoryAdjustmentCreatingPayload) => {
|
|
||||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
|
||||||
// tenantId,
|
|
||||||
// quickAdjustmentDTO.branchId
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,56 +1,41 @@
|
|||||||
// import { Inject, Service } from 'typedi';
|
import { Injectable } from '@nestjs/common';
|
||||||
// import events from '@/subscribers/events';
|
import { OnEvent } from '@nestjs/event-emitter';
|
||||||
// import {
|
import { events } from '@/common/events/events';
|
||||||
// ISaleInvoiceCreatingPaylaod,
|
import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||||
// ISaleInvoiceEditingPayload,
|
import {
|
||||||
// } from '@/interfaces';
|
ISaleInvoiceCreatingPaylaod,
|
||||||
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
ISaleInvoiceEditingPayload,
|
||||||
|
} from '@/modules/SaleInvoices/SaleInvoice.types';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class InvoiceBranchValidateSubscriber {
|
export class InvoiceBranchValidateSubscriber {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private validateBranchExistance: ValidateBranchExistance;
|
private readonly validateBranchExistance: ValidateBranchExistance,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Attaches events with handlers.
|
* Validate branch existance on invoice creating.
|
||||||
// */
|
* @param {ISaleInvoiceCreatingPayload} payload
|
||||||
// public attach = (bus) => {
|
*/
|
||||||
// bus.subscribe(
|
@OnEvent(events.saleInvoice.onCreating)
|
||||||
// events.saleInvoice.onCreating,
|
async validateBranchExistanceOnInvoiceCreating({
|
||||||
// this.validateBranchExistanceOnInvoiceCreating
|
saleInvoiceDTO,
|
||||||
// );
|
}: ISaleInvoiceCreatingPaylaod) {
|
||||||
// bus.subscribe(
|
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||||
// events.saleInvoice.onEditing,
|
saleInvoiceDTO.branchId,
|
||||||
// this.validateBranchExistanceOnInvoiceEditing
|
);
|
||||||
// );
|
}
|
||||||
// return bus;
|
|
||||||
// };
|
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Validate branch existance on invoice creating.
|
* Validate branch existance once invoice editing.
|
||||||
// * @param {ISaleInvoiceCreatingPaylaod} payload
|
* @param {ISaleInvoiceEditingPayload} payload
|
||||||
// */
|
*/
|
||||||
// private validateBranchExistanceOnInvoiceCreating = async ({
|
@OnEvent(events.saleInvoice.onEditing)
|
||||||
// tenantId,
|
async validateBranchExistanceOnInvoiceEditing({
|
||||||
// saleInvoiceDTO,
|
saleInvoiceDTO,
|
||||||
// }: ISaleInvoiceCreatingPaylaod) => {
|
}: ISaleInvoiceEditingPayload) {
|
||||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||||
// tenantId,
|
saleInvoiceDTO.branchId,
|
||||||
// saleInvoiceDTO.branchId
|
);
|
||||||
// );
|
}
|
||||||
// };
|
}
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Validate branch existance once invoice editing.
|
|
||||||
// * @param {ISaleInvoiceEditingPayload} payload
|
|
||||||
// */
|
|
||||||
// private validateBranchExistanceOnInvoiceEditing = async ({
|
|
||||||
// saleInvoiceDTO,
|
|
||||||
// tenantId,
|
|
||||||
// }: ISaleInvoiceEditingPayload) => {
|
|
||||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
|
||||||
// tenantId,
|
|
||||||
// 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()
|
import {
|
||||||
// export class ManualJournalBranchValidateSubscriber {
|
IManualJournalCreatingPayload,
|
||||||
// @Inject()
|
IManualJournalEditingPayload,
|
||||||
// private validateManualJournalBranch: ManualJournalBranchesValidator;
|
} 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()
|
@Injectable()
|
||||||
// private featuresManager: FeaturesManager;
|
export class ManualJournalBranchValidateSubscriber {
|
||||||
|
constructor(
|
||||||
|
private readonly validateManualJournalBranch: ManualJournalBranchesValidator,
|
||||||
|
private readonly featuresManager: FeaturesManager,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Attaches events with handlers.
|
* Validate branch existance on estimate creating.
|
||||||
// */
|
* @param {IManualJournalCreatingPayload} payload
|
||||||
// public attach = (bus) => {
|
*/
|
||||||
// bus.subscribe(
|
@OnEvent(events.manualJournals.onCreating)
|
||||||
// events.manualJournals.onCreating,
|
async validateBranchExistanceOnBillCreating({
|
||||||
// this.validateBranchExistanceOnBillCreating
|
manualJournalDTO,
|
||||||
// );
|
}: IManualJournalCreatingPayload) {
|
||||||
// bus.subscribe(
|
// Detarmines whether the multi-branches is accessible by tenant.
|
||||||
// events.manualJournals.onEditing,
|
const isAccessible = await this.featuresManager.accessible(
|
||||||
// this.validateBranchExistanceOnBillEditing
|
Features.BRANCHES
|
||||||
// );
|
);
|
||||||
// return bus;
|
// Can't continue if the multi-branches feature is inactive.
|
||||||
// };
|
if (!isAccessible) return;
|
||||||
|
|
||||||
// /**
|
// Validates the entries whether have branch id.
|
||||||
// * Validate branch existance on estimate creating.
|
await this.validateManualJournalBranch.validateEntriesHasBranchId(
|
||||||
// * @param {IManualJournalCreatingPayload} payload
|
manualJournalDTO
|
||||||
// */
|
);
|
||||||
// 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(
|
* Validate branch existance once estimate editing.
|
||||||
// manualJournalDTO
|
* @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;
|
||||||
|
|
||||||
// /**
|
await this.validateManualJournalBranch.validateEntriesHasBranchId(
|
||||||
// * Validate branch existance once estimate editing.
|
manualJournalDTO
|
||||||
// * @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
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,56 +1,41 @@
|
|||||||
// import { Inject, Service } from 'typedi';
|
import { OnEvent } from '@nestjs/event-emitter';
|
||||||
// import events from '@/subscribers/events';
|
import { Injectable } from '@nestjs/common';
|
||||||
// import {
|
import {
|
||||||
// IBillPaymentCreatingPayload,
|
IBillPaymentCreatingPayload,
|
||||||
// IBillPaymentEditingPayload,
|
IBillPaymentEditingPayload,
|
||||||
// } from '@/interfaces';
|
} from '@/modules/BillPayments/types/BillPayments.types';
|
||||||
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||||
|
import { events } from '@/common/events/events';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class PaymentMadeBranchValidateSubscriber {
|
export class PaymentMadeBranchValidateSubscriber {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private validateBranchExistance: ValidateBranchExistance;
|
private readonly validateBranchExistance: ValidateBranchExistance,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Attaches events with handlers.
|
* Validate branch existance on estimate creating.
|
||||||
// */
|
* @param {ISaleEstimateCreatedPayload} payload
|
||||||
// public attach = (bus) => {
|
*/
|
||||||
// bus.subscribe(
|
@OnEvent(events.billPayment.onCreating)
|
||||||
// events.billPayment.onCreating,
|
async validateBranchExistanceOnPaymentCreating({
|
||||||
// this.validateBranchExistanceOnPaymentCreating
|
billPaymentDTO,
|
||||||
// );
|
}: IBillPaymentCreatingPayload) {
|
||||||
// bus.subscribe(
|
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||||
// events.billPayment.onEditing,
|
billPaymentDTO.branchId,
|
||||||
// this.validateBranchExistanceOnPaymentEditing
|
);
|
||||||
// );
|
}
|
||||||
// return bus;
|
|
||||||
// };
|
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Validate branch existance on estimate creating.
|
* Validate branch existance once estimate editing.
|
||||||
// * @param {ISaleEstimateCreatedPayload} payload
|
* @param {ISaleEstimateEditingPayload} payload
|
||||||
// */
|
*/
|
||||||
// private validateBranchExistanceOnPaymentCreating = async ({
|
@OnEvent(events.billPayment.onEditing)
|
||||||
// tenantId,
|
async validateBranchExistanceOnPaymentEditing({
|
||||||
// billPaymentDTO,
|
billPaymentDTO,
|
||||||
// }: IBillPaymentCreatingPayload) => {
|
}: IBillPaymentEditingPayload) {
|
||||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||||
// tenantId,
|
billPaymentDTO.branchId,
|
||||||
// billPaymentDTO.branchId
|
);
|
||||||
// );
|
}
|
||||||
// };
|
}
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Validate branch existance once estimate editing.
|
|
||||||
// * @param {ISaleEstimateEditingPayload} payload
|
|
||||||
// */
|
|
||||||
// private validateBranchExistanceOnPaymentEditing = async ({
|
|
||||||
// billPaymentDTO,
|
|
||||||
// tenantId,
|
|
||||||
// }: IBillPaymentEditingPayload) => {
|
|
||||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
|
||||||
// tenantId,
|
|
||||||
// billPaymentDTO.branchId
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,56 +1,41 @@
|
|||||||
// import { Inject, Service } from 'typedi';
|
import {
|
||||||
// import events from '@/subscribers/events';
|
IPaymentReceivedCreatingPayload,
|
||||||
// import {
|
IPaymentReceivedEditingPayload,
|
||||||
// IPaymentReceivedCreatingPayload,
|
} from '@/modules/PaymentReceived/types/PaymentReceived.types';
|
||||||
// IPaymentReceivedEditingPayload,
|
import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||||
// } from '@/interfaces';
|
import { OnEvent } from '@nestjs/event-emitter';
|
||||||
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { events } from '@/common/events/events';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class PaymentReceiveBranchValidateSubscriber {
|
export class PaymentReceiveBranchValidateSubscriber {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private validateBranchExistance: ValidateBranchExistance;
|
private readonly validateBranchExistance: ValidateBranchExistance,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Attaches events with handlers.
|
* Validate branch existance on estimate creating.
|
||||||
// */
|
* @param {IPaymentReceivedCreatingPayload} payload
|
||||||
// public attach = (bus) => {
|
*/
|
||||||
// bus.subscribe(
|
@OnEvent(events.paymentReceive.onCreating)
|
||||||
// events.paymentReceive.onCreating,
|
async validateBranchExistanceOnPaymentCreating({
|
||||||
// this.validateBranchExistanceOnPaymentCreating
|
paymentReceiveDTO,
|
||||||
// );
|
}: IPaymentReceivedCreatingPayload) {
|
||||||
// bus.subscribe(
|
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||||
// events.paymentReceive.onEditing,
|
paymentReceiveDTO.branchId,
|
||||||
// this.validateBranchExistanceOnPaymentEditing
|
);
|
||||||
// );
|
}
|
||||||
// return bus;
|
|
||||||
// };
|
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Validate branch existance on estimate creating.
|
* Validate branch existance once estimate editing.
|
||||||
// * @param {IPaymentReceivedCreatingPayload} payload
|
* @param {IPaymentReceivedEditingPayload} payload
|
||||||
// */
|
*/
|
||||||
// private validateBranchExistanceOnPaymentCreating = async ({
|
@OnEvent(events.paymentReceive.onEditing)
|
||||||
// tenantId,
|
async validateBranchExistanceOnPaymentEditing({
|
||||||
// paymentReceiveDTO,
|
paymentReceiveDTO,
|
||||||
// }: IPaymentReceivedCreatingPayload) => {
|
}: IPaymentReceivedEditingPayload) {
|
||||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||||
// tenantId,
|
paymentReceiveDTO.branchId,
|
||||||
// paymentReceiveDTO.branchId
|
);
|
||||||
// );
|
}
|
||||||
// };
|
}
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Validate branch existance once estimate editing.
|
|
||||||
// * @param {IPaymentReceivedEditingPayload} payload
|
|
||||||
// */
|
|
||||||
// private validateBranchExistanceOnPaymentEditing = async ({
|
|
||||||
// paymentReceiveDTO,
|
|
||||||
// tenantId,
|
|
||||||
// }: IPaymentReceivedEditingPayload) => {
|
|
||||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
|
||||||
// tenantId,
|
|
||||||
// paymentReceiveDTO.branchId
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,56 +1,41 @@
|
|||||||
// import { Inject, Service } from 'typedi';
|
import { OnEvent } from '@nestjs/event-emitter';
|
||||||
// import events from '@/subscribers/events';
|
import { Injectable } from '@nestjs/common';
|
||||||
// import {
|
import { events } from '@/common/events/events';
|
||||||
// ISaleEstimateCreatingPayload,
|
import {
|
||||||
// ISaleEstimateEditingPayload,
|
ISaleEstimateCreatingPayload,
|
||||||
// } from '@/interfaces';
|
ISaleEstimateEditingPayload,
|
||||||
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
} from '@/modules/SaleEstimates/types/SaleEstimates.types';
|
||||||
|
import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class SaleEstimateBranchValidateSubscriber {
|
export class SaleEstimateBranchValidateSubscriber {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private validateBranchExistance: ValidateBranchExistance;
|
private readonly validateBranchExistance: ValidateBranchExistance,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Attaches events with handlers.
|
* Validate branch existance on estimate creating.
|
||||||
// */
|
* @param {ISaleEstimateCreatedPayload} payload
|
||||||
// public attach = (bus) => {
|
*/
|
||||||
// bus.subscribe(
|
@OnEvent(events.saleEstimate.onCreating)
|
||||||
// events.saleEstimate.onCreating,
|
async validateBranchExistanceOnEstimateCreating({
|
||||||
// this.validateBranchExistanceOnEstimateCreating
|
estimateDTO,
|
||||||
// );
|
}: ISaleEstimateCreatingPayload) {
|
||||||
// bus.subscribe(
|
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||||
// events.saleEstimate.onEditing,
|
estimateDTO.branchId,
|
||||||
// this.validateBranchExistanceOnEstimateEditing
|
);
|
||||||
// );
|
}
|
||||||
// return bus;
|
|
||||||
// };
|
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Validate branch existance on estimate creating.
|
* Validate branch existance once estimate editing.
|
||||||
// * @param {ISaleEstimateCreatedPayload} payload
|
* @param {ISaleEstimateEditingPayload} payload
|
||||||
// */
|
*/
|
||||||
// private validateBranchExistanceOnEstimateCreating = async ({
|
@OnEvent(events.saleEstimate.onEditing)
|
||||||
// tenantId,
|
async validateBranchExistanceOnEstimateEditing({
|
||||||
// estimateDTO,
|
estimateDTO,
|
||||||
// }: ISaleEstimateCreatingPayload) => {
|
}: ISaleEstimateEditingPayload) {
|
||||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||||
// tenantId,
|
estimateDTO.branchId,
|
||||||
// estimateDTO.branchId
|
);
|
||||||
// );
|
}
|
||||||
// };
|
}
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Validate branch existance once estimate editing.
|
|
||||||
// * @param {ISaleEstimateEditingPayload} payload
|
|
||||||
// */
|
|
||||||
// private validateBranchExistanceOnEstimateEditing = async ({
|
|
||||||
// estimateDTO,
|
|
||||||
// tenantId,
|
|
||||||
// }: ISaleEstimateEditingPayload) => {
|
|
||||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
|
||||||
// tenantId,
|
|
||||||
// estimateDTO.branchId
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,56 +1,41 @@
|
|||||||
// import { Inject, Service } from 'typedi';
|
import {
|
||||||
// import events from '@/subscribers/events';
|
ISaleReceiptCreatingPayload,
|
||||||
// import {
|
ISaleReceiptEditingPayload,
|
||||||
// ISaleReceiptCreatingPayload,
|
} from '@/modules/SaleReceipts/types/SaleReceipts.types';
|
||||||
// ISaleReceiptEditingPayload,
|
import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||||
// } from '@/interfaces';
|
import { OnEvent } from '@nestjs/event-emitter';
|
||||||
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { events } from '@/common/events/events';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class SaleReceiptBranchValidateSubscriber {
|
export class SaleReceiptBranchValidateSubscriber {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private validateBranchExistance: ValidateBranchExistance;
|
private readonly validateBranchExistance: ValidateBranchExistance,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Attaches events with handlers.
|
* Validate branch existance on estimate creating.
|
||||||
// */
|
* @param {ISaleReceiptCreatingPayload} payload
|
||||||
// public attach = (bus) => {
|
*/
|
||||||
// bus.subscribe(
|
@OnEvent(events.saleReceipt.onCreating)
|
||||||
// events.saleReceipt.onCreating,
|
async validateBranchExistanceOnInvoiceCreating({
|
||||||
// this.validateBranchExistanceOnInvoiceCreating
|
saleReceiptDTO,
|
||||||
// );
|
}: ISaleReceiptCreatingPayload) {
|
||||||
// bus.subscribe(
|
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||||
// events.saleReceipt.onEditing,
|
saleReceiptDTO.branchId,
|
||||||
// this.validateBranchExistanceOnInvoiceEditing
|
);
|
||||||
// );
|
}
|
||||||
// return bus;
|
|
||||||
// };
|
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Validate branch existance on estimate creating.
|
* Validate branch existance once estimate editing.
|
||||||
// * @param {ISaleReceiptCreatingPayload} payload
|
* @param {ISaleReceiptEditingPayload} payload
|
||||||
// */
|
*/
|
||||||
// private validateBranchExistanceOnInvoiceCreating = async ({
|
@OnEvent(events.saleReceipt.onEditing)
|
||||||
// tenantId,
|
async validateBranchExistanceOnInvoiceEditing({
|
||||||
// saleReceiptDTO,
|
saleReceiptDTO,
|
||||||
// }: ISaleReceiptCreatingPayload) => {
|
}: ISaleReceiptEditingPayload) {
|
||||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||||
// tenantId,
|
saleReceiptDTO.branchId,
|
||||||
// saleReceiptDTO.branchId
|
);
|
||||||
// );
|
}
|
||||||
// };
|
}
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Validate branch existance once estimate editing.
|
|
||||||
// * @param {ISaleReceiptEditingPayload} payload
|
|
||||||
// */
|
|
||||||
// private validateBranchExistanceOnInvoiceEditing = async ({
|
|
||||||
// saleReceiptDTO,
|
|
||||||
// tenantId,
|
|
||||||
// }: ISaleReceiptEditingPayload) => {
|
|
||||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
|
||||||
// tenantId,
|
|
||||||
// saleReceiptDTO.branchId
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,56 +1,41 @@
|
|||||||
// import { Inject, Service } from 'typedi';
|
import {
|
||||||
// import events from '@/subscribers/events';
|
IVendorCreditCreatingPayload,
|
||||||
// import {
|
IVendorCreditEditingPayload,
|
||||||
// IVendorCreditCreatingPayload,
|
} from '@/modules/VendorCredit/types/VendorCredit.types';
|
||||||
// IVendorCreditEditingPayload,
|
import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||||
// } from '@/interfaces';
|
import { OnEvent } from '@nestjs/event-emitter';
|
||||||
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { events } from '@/common/events/events';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class VendorCreditBranchValidateSubscriber {
|
export class VendorCreditBranchValidateSubscriber {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private validateBranchExistance: ValidateBranchExistance;
|
private readonly validateBranchExistance: ValidateBranchExistance,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Attaches events with handlers.
|
* Validate branch existance on estimate creating.
|
||||||
// */
|
* @param {ISaleEstimateCreatedPayload} payload
|
||||||
// public attach = (bus) => {
|
*/
|
||||||
// bus.subscribe(
|
@OnEvent(events.vendorCredit.onCreating)
|
||||||
// events.vendorCredit.onCreating,
|
async validateBranchExistanceOnCreditCreating({
|
||||||
// this.validateBranchExistanceOnCreditCreating
|
vendorCreditCreateDTO,
|
||||||
// );
|
}: IVendorCreditCreatingPayload) {
|
||||||
// bus.subscribe(
|
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||||
// events.vendorCredit.onEditing,
|
vendorCreditCreateDTO.branchId,
|
||||||
// this.validateBranchExistanceOnCreditEditing
|
);
|
||||||
// );
|
}
|
||||||
// return bus;
|
|
||||||
// };
|
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Validate branch existance on estimate creating.
|
* Validate branch existance once estimate editing.
|
||||||
// * @param {ISaleEstimateCreatedPayload} payload
|
* @param {ISaleEstimateEditingPayload} payload
|
||||||
// */
|
*/
|
||||||
// private validateBranchExistanceOnCreditCreating = async ({
|
@OnEvent(events.vendorCredit.onEditing)
|
||||||
// tenantId,
|
async validateBranchExistanceOnCreditEditing({
|
||||||
// vendorCreditCreateDTO,
|
vendorCreditDTO,
|
||||||
// }: IVendorCreditCreatingPayload) => {
|
}: IVendorCreditEditingPayload) {
|
||||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||||
// tenantId,
|
vendorCreditDTO.branchId,
|
||||||
// vendorCreditCreateDTO.branchId
|
);
|
||||||
// );
|
}
|
||||||
// };
|
}
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Validate branch existance once estimate editing.
|
|
||||||
// * @param {ISaleEstimateEditingPayload} payload
|
|
||||||
// */
|
|
||||||
// private validateBranchExistanceOnCreditEditing = async ({
|
|
||||||
// vendorCreditDTO,
|
|
||||||
// tenantId,
|
|
||||||
// }: IVendorCreditEditingPayload) => {
|
|
||||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
|
||||||
// tenantId,
|
|
||||||
// vendorCreditDTO.branchId
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,35 +1,25 @@
|
|||||||
// import { Inject, Service } from 'typedi';
|
import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
||||||
// import events from '@/subscribers/events';
|
import { OnEvent } from '@nestjs/event-emitter';
|
||||||
// import { IRefundVendorCreditCreatingPayload } from '@/interfaces';
|
import { Injectable } from '@nestjs/common';
|
||||||
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
|
import { events } from '@/common/events/events';
|
||||||
|
import { IRefundVendorCreditCreatingPayload } from '@/modules/VendorCreditsRefund/types/VendorCreditRefund.types';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class VendorCreditRefundBranchValidateSubscriber {
|
export class VendorCreditRefundBranchValidateSubscriber {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private validateBranchExistance: ValidateBranchExistance;
|
private readonly validateBranchExistance: ValidateBranchExistance,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Attaches events with handlers.
|
* Validate branch existance on refund credit note creating.
|
||||||
// */
|
* @param {IRefundVendorCreditCreatingPayload} payload
|
||||||
// public attach = (bus) => {
|
*/
|
||||||
// bus.subscribe(
|
@OnEvent(events.vendorCredit.onRefundCreating)
|
||||||
// events.vendorCredit.onRefundCreating,
|
async validateBranchExistanceOnCreditRefundCreating({
|
||||||
// this.validateBranchExistanceOnCreditRefundCreating
|
refundVendorCreditDTO,
|
||||||
// );
|
}: IRefundVendorCreditCreatingPayload) {
|
||||||
// return bus;
|
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
||||||
// };
|
refundVendorCreditDTO.branchId,
|
||||||
|
);
|
||||||
// /**
|
}
|
||||||
// * Validate branch existance on refund credit note creating.
|
}
|
||||||
// * @param {IRefundVendorCreditCreatingPayload} payload
|
|
||||||
// */
|
|
||||||
// private validateBranchExistanceOnCreditRefundCreating = async ({
|
|
||||||
// tenantId,
|
|
||||||
// refundVendorCreditDTO,
|
|
||||||
// }: IRefundVendorCreditCreatingPayload) => {
|
|
||||||
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
|
||||||
// tenantId,
|
|
||||||
// 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 { IAPAgingSummaryQuery } from './APAgingSummary.types';
|
||||||
import { AcceptType } from '@/constants/accept-type';
|
import { AcceptType } from '@/constants/accept-type';
|
||||||
import { Response } from 'express';
|
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')
|
@Controller('reports/payable-aging-summary')
|
||||||
|
@ApiTags('reports')
|
||||||
|
@PublicRoute()
|
||||||
export class APAgingSummaryController {
|
export class APAgingSummaryController {
|
||||||
constructor(private readonly APAgingSummaryApp: APAgingSummaryApplication) {}
|
constructor(private readonly APAgingSummaryApp: APAgingSummaryApplication) {}
|
||||||
|
|
||||||
|
|||||||
@@ -3,10 +3,11 @@ import { IVendorBalanceSummaryQuery } from './VendorBalanceSummary.types';
|
|||||||
import { VendorBalanceSummaryApplication } from './VendorBalanceSummaryApplication';
|
import { VendorBalanceSummaryApplication } from './VendorBalanceSummaryApplication';
|
||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { AcceptType } from '@/constants/accept-type';
|
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';
|
import { PublicRoute } from '@/modules/Auth/Jwt.guard';
|
||||||
|
|
||||||
@Controller('/reports/vendor-balance-summary')
|
@Controller('/reports/vendor-balance-summary')
|
||||||
|
@ApiTags('reports')
|
||||||
@PublicRoute()
|
@PublicRoute()
|
||||||
export class VendorBalanceSummaryController {
|
export class VendorBalanceSummaryController {
|
||||||
constructor(
|
constructor(
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ export class InventoryCostLotTracker extends BaseModel {
|
|||||||
exchangeRate: number;
|
exchangeRate: number;
|
||||||
currencyCode: string;
|
currencyCode: string;
|
||||||
|
|
||||||
|
warehouseId: number;
|
||||||
|
|
||||||
item?: Item;
|
item?: Item;
|
||||||
invoice?: SaleInvoice;
|
invoice?: SaleInvoice;
|
||||||
receipt?: SaleReceipt;
|
receipt?: SaleReceipt;
|
||||||
|
|||||||
@@ -32,13 +32,9 @@ export class ItemCategoryApplication {
|
|||||||
* @returns {Promise<ItemCategory>} The created item category.
|
* @returns {Promise<ItemCategory>} The created item category.
|
||||||
*/
|
*/
|
||||||
public createItemCategory(
|
public createItemCategory(
|
||||||
tenantId: number,
|
|
||||||
itemCategoryDTO: IItemCategoryOTD,
|
itemCategoryDTO: IItemCategoryOTD,
|
||||||
) {
|
) {
|
||||||
return this.createItemCategoryService.newItemCategory(
|
return this.createItemCategoryService.newItemCategory(itemCategoryDTO);
|
||||||
tenantId,
|
|
||||||
itemCategoryDTO,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -27,14 +27,8 @@ export class ItemCategoryController {
|
|||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@ApiOperation({ summary: 'Create a new item category.' })
|
@ApiOperation({ summary: 'Create a new item category.' })
|
||||||
async createItemCategory(
|
async createItemCategory(@Body() itemCategoryDTO: IItemCategoryOTD) {
|
||||||
@Body('tenantId') tenantId: number,
|
return this.itemCategoryApplication.createItemCategory(itemCategoryDTO);
|
||||||
@Body() itemCategoryDTO: IItemCategoryOTD,
|
|
||||||
) {
|
|
||||||
return this.itemCategoryApplication.createItemCategory(
|
|
||||||
tenantId,
|
|
||||||
itemCategoryDTO,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ export class CreateItemCategoryService {
|
|||||||
* @return {Promise<void>}
|
* @return {Promise<void>}
|
||||||
*/
|
*/
|
||||||
public async newItemCategory(
|
public async newItemCategory(
|
||||||
tenantId: number,
|
|
||||||
itemCategoryOTD: IItemCategoryOTD,
|
itemCategoryOTD: IItemCategoryOTD,
|
||||||
trx?: Knex.Transaction,
|
trx?: Knex.Transaction,
|
||||||
): Promise<ItemCategory> {
|
): Promise<ItemCategory> {
|
||||||
@@ -81,7 +80,6 @@ export class CreateItemCategoryService {
|
|||||||
// Triggers `onItemCategoryCreated` event.
|
// Triggers `onItemCategoryCreated` event.
|
||||||
await this.eventEmitter.emitAsync(events.itemCategory.onCreated, {
|
await this.eventEmitter.emitAsync(events.itemCategory.onCreated, {
|
||||||
itemCategory,
|
itemCategory,
|
||||||
tenantId,
|
|
||||||
trx,
|
trx,
|
||||||
} as IItemCategoryCreatedPayload);
|
} as IItemCategoryCreatedPayload);
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,15 @@ import { TenantModelProxy } from '../System/models/TenantBaseModel';
|
|||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ItemsValidators {
|
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(
|
constructor(
|
||||||
@Inject(Item.name) private itemModel: TenantModelProxy<typeof Item>,
|
@Inject(Item.name) private itemModel: TenantModelProxy<typeof Item>,
|
||||||
|
|
||||||
@@ -244,9 +253,9 @@ export class ItemsValidators {
|
|||||||
/**
|
/**
|
||||||
* Validate the item inventory account whether modified and item
|
* Validate the item inventory account whether modified and item
|
||||||
* has associated inventory transactions.
|
* has associated inventory transactions.
|
||||||
* @param {Item} oldItem
|
* @param {Item} oldItem - Old item.
|
||||||
* @param {IItemDTO} newItemDTO
|
* @param {IItemDTO} newItemDTO - New item DTO.
|
||||||
* @returns
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
async validateItemInvnetoryAccountModified(
|
async validateItemInvnetoryAccountModified(
|
||||||
oldItem: Item,
|
oldItem: Item,
|
||||||
@@ -285,7 +294,7 @@ export class ItemsValidators {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate the purchase tax rate id existance.
|
* Validate the purchase tax rate id existance.
|
||||||
* @param {number} taxRateId -
|
* @param {number} taxRateId - Tax rate id.
|
||||||
*/
|
*/
|
||||||
public async validatePurchaseTaxRateExistance(taxRateId: number) {
|
public async validatePurchaseTaxRateExistance(taxRateId: number) {
|
||||||
const foundTaxRate = await this.taxRateModel().query().findById(taxRateId);
|
const foundTaxRate = await this.taxRateModel().query().findById(taxRateId);
|
||||||
@@ -297,7 +306,7 @@ export class ItemsValidators {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate the sell tax rate id existance.
|
* Validate the sell tax rate id existance.
|
||||||
* @param {number} taxRateId
|
* @param {number} taxRateId - Tax rate id.
|
||||||
*/
|
*/
|
||||||
public async validateSellTaxRateExistance(taxRateId: number) {
|
public async validateSellTaxRateExistance(taxRateId: number) {
|
||||||
const foundTaxRate = await this.taxRateModel().query().findById(taxRateId);
|
const foundTaxRate = await this.taxRateModel().query().findById(taxRateId);
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ export class ManualJournal extends TenantBaseModel {
|
|||||||
entries!: ManualJournalEntry[];
|
entries!: ManualJournalEntry[];
|
||||||
attachments!: Document[];
|
attachments!: Document[];
|
||||||
|
|
||||||
|
branchId?: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Table name.
|
* Table name.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -60,7 +60,11 @@ import { SEND_PAYMENT_RECEIVED_MAIL_QUEUE } from './constants';
|
|||||||
SendPaymentReceiveMailNotification,
|
SendPaymentReceiveMailNotification,
|
||||||
SendPaymentReceivedMailProcessor,
|
SendPaymentReceivedMailProcessor,
|
||||||
],
|
],
|
||||||
exports: [PaymentReceivesApplication, CreatePaymentReceivedService],
|
exports: [
|
||||||
|
PaymentReceivesApplication,
|
||||||
|
CreatePaymentReceivedService,
|
||||||
|
PaymentReceivedGLEntries,
|
||||||
|
],
|
||||||
imports: [
|
imports: [
|
||||||
ChromiumlyTenancyModule,
|
ChromiumlyTenancyModule,
|
||||||
TemplateInjectableModule,
|
TemplateInjectableModule,
|
||||||
|
|||||||
@@ -1,76 +1,70 @@
|
|||||||
// import { Knex } from 'knex';
|
import { Knex } from 'knex';
|
||||||
// import async from 'async';
|
import async from 'async';
|
||||||
// import { Inject, Service } from 'typedi';
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
import { PaymentReceivedGLEntries } from '../PaymentReceived/commands/PaymentReceivedGLEntries';
|
||||||
// import { PaymentReceivedGLEntries } from '../PaymentReceived/PaymentReceivedGLEntries';
|
import { TenantModelProxy } from '../System/models/TenantBaseModel';
|
||||||
|
import { PaymentReceivedEntry } from '../PaymentReceived/models/PaymentReceivedEntry';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class InvoicePaymentsGLEntriesRewrite {
|
export class InvoicePaymentsGLEntriesRewrite {
|
||||||
// @Inject()
|
constructor(
|
||||||
// public tenancy: HasTenancyService;
|
private readonly paymentGLEntries: PaymentReceivedGLEntries,
|
||||||
|
|
||||||
// @Inject()
|
@Inject(PaymentReceivedEntry.name)
|
||||||
// public paymentGLEntries: PaymentReceivedGLEntries;
|
private readonly paymentReceivedEntryModel: TenantModelProxy<typeof PaymentReceivedEntry>
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Rewrites the payment GL entries task.
|
* Rewrites the payment GL entries task.
|
||||||
// * @param {{ tenantId: number, paymentId: number, trx: Knex?.Transaction }}
|
* @param {{ tenantId: number, paymentId: number, trx: Knex?.Transaction }}
|
||||||
// * @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
// */
|
*/
|
||||||
// public rewritePaymentsGLEntriesTask = async ({
|
public rewritePaymentsGLEntriesTask = async ({
|
||||||
// tenantId,
|
paymentId,
|
||||||
// paymentId,
|
trx,
|
||||||
// trx,
|
}) => {
|
||||||
// }) => {
|
await this.paymentGLEntries.rewritePaymentGLEntries(
|
||||||
// await this.paymentGLEntries.rewritePaymentGLEntries(
|
paymentId,
|
||||||
// tenantId,
|
trx
|
||||||
// paymentId,
|
);
|
||||||
// trx
|
};
|
||||||
// );
|
|
||||||
// };
|
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Rewrites the payment GL entries of the given payments ids.
|
* Rewrites the payment GL entries of the given payments ids.
|
||||||
// * @param {number} tenantId
|
* @param {number[]} paymentsIds
|
||||||
// * @param {number[]} paymentsIds
|
* @param {Knex.Transaction} trx
|
||||||
// * @param {Knex.Transaction} trx
|
*/
|
||||||
// */
|
public rewritePaymentsGLEntriesQueue = async (
|
||||||
// public rewritePaymentsGLEntriesQueue = async (
|
paymentsIds: number[],
|
||||||
// tenantId: number,
|
trx?: Knex.Transaction
|
||||||
// paymentsIds: number[],
|
) => {
|
||||||
// trx?: Knex.Transaction
|
// Initiate a new queue for accounts balance mutation.
|
||||||
// ) => {
|
const rewritePaymentGL = async.queue(this.rewritePaymentsGLEntriesTask, 10);
|
||||||
// // Initiate a new queue for accounts balance mutation.
|
|
||||||
// const rewritePaymentGL = async.queue(this.rewritePaymentsGLEntriesTask, 10);
|
|
||||||
|
|
||||||
// paymentsIds.forEach((paymentId: number) => {
|
paymentsIds.forEach((paymentId: number) => {
|
||||||
// rewritePaymentGL.push({ paymentId, trx, tenantId });
|
rewritePaymentGL.push({ paymentId, trx });
|
||||||
// });
|
});
|
||||||
// if (paymentsIds.length > 0) {
|
if (paymentsIds.length > 0) {
|
||||||
// await rewritePaymentGL.drain();
|
await rewritePaymentGL.drain();
|
||||||
// }
|
}
|
||||||
// };
|
};
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Rewrites the payments GL entries that associated to the given invoice.
|
* Rewrites the payments GL entries that associated to the given invoice.
|
||||||
// * @param {number} tenantId
|
* @param {number} invoiceId
|
||||||
// * @param {number} invoiceId
|
* @param {Knex.Transaction} trx
|
||||||
// * @param {Knex.Transaction} trx
|
* @ {Promise<void>}
|
||||||
// * @returns {Promise<void>}
|
*/
|
||||||
// */
|
public invoicePaymentsGLEntriesRewrite = async (
|
||||||
// public invoicePaymentsGLEntriesRewrite = async (
|
invoiceId: number,
|
||||||
// tenantId: number,
|
trx?: Knex.Transaction
|
||||||
// invoiceId: number,
|
) => {
|
||||||
// trx?: Knex.Transaction
|
const invoicePaymentEntries = await this.paymentReceivedEntryModel()
|
||||||
// ) => {
|
.query()
|
||||||
// const { PaymentReceiveEntry } = this.tenancy.models(tenantId);
|
.where('invoiceId', invoiceId);
|
||||||
|
|
||||||
// const invoicePaymentEntries = await PaymentReceiveEntry.query().where(
|
const paymentsIds = invoicePaymentEntries.map((e) => e.paymentReceiveId);
|
||||||
// 'invoiceId',
|
|
||||||
// invoiceId
|
|
||||||
// );
|
|
||||||
// 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 type InvoiceNotificationType = 'details' | 'reminder';
|
||||||
|
|
||||||
export interface ISaleInvoiceCreatedPayload {
|
export interface ISaleInvoiceCreatedPayload {
|
||||||
// tenantId: number;
|
|
||||||
saleInvoice: SaleInvoice;
|
saleInvoice: SaleInvoice;
|
||||||
saleInvoiceDTO: ISaleInvoiceCreateDTO;
|
saleInvoiceDTO: ISaleInvoiceCreateDTO;
|
||||||
saleInvoiceId: number;
|
saleInvoiceId: number;
|
||||||
// authorizedUser: SystemUser;
|
|
||||||
trx: Knex.Transaction;
|
trx: Knex.Transaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,17 +101,14 @@ export interface ISaleInvoiceCreatingPaylaod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ISaleInvoiceEditedPayload {
|
export interface ISaleInvoiceEditedPayload {
|
||||||
// tenantId: number;
|
|
||||||
saleInvoice: SaleInvoice;
|
saleInvoice: SaleInvoice;
|
||||||
oldSaleInvoice: SaleInvoice;
|
oldSaleInvoice: SaleInvoice;
|
||||||
saleInvoiceDTO: ISaleInvoiceEditDTO;
|
saleInvoiceDTO: ISaleInvoiceEditDTO;
|
||||||
saleInvoiceId: number;
|
saleInvoiceId: number;
|
||||||
// authorizedUser: SystemUser;
|
|
||||||
trx: Knex.Transaction;
|
trx: Knex.Transaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ISaleInvoiceEditingPayload {
|
export interface ISaleInvoiceEditingPayload {
|
||||||
// tenantId: number;
|
|
||||||
saleInvoiceDTO: ISaleInvoiceEditDTO;
|
saleInvoiceDTO: ISaleInvoiceEditDTO;
|
||||||
oldSaleInvoice: SaleInvoice;
|
oldSaleInvoice: SaleInvoice;
|
||||||
trx: Knex.Transaction;
|
trx: Knex.Transaction;
|
||||||
@@ -127,21 +122,18 @@ export interface ISaleInvoiceDeletePayload {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ISaleInvoiceDeletingPayload {
|
export interface ISaleInvoiceDeletingPayload {
|
||||||
// tenantId: number;
|
|
||||||
oldSaleInvoice: SaleInvoice;
|
oldSaleInvoice: SaleInvoice;
|
||||||
saleInvoiceId: number;
|
saleInvoiceId: number;
|
||||||
trx: Knex.Transaction;
|
trx: Knex.Transaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ISaleInvoiceDeletedPayload {
|
export interface ISaleInvoiceDeletedPayload {
|
||||||
// tenantId: number;
|
|
||||||
oldSaleInvoice: SaleInvoice;
|
oldSaleInvoice: SaleInvoice;
|
||||||
saleInvoiceId: number;
|
saleInvoiceId: number;
|
||||||
trx: Knex.Transaction;
|
trx: Knex.Transaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ISaleInvoiceWriteoffCreatePayload {
|
export interface ISaleInvoiceWriteoffCreatePayload {
|
||||||
// tenantId: number;
|
|
||||||
saleInvoiceId: number;
|
saleInvoiceId: number;
|
||||||
saleInvoice: SaleInvoice;
|
saleInvoice: SaleInvoice;
|
||||||
writeoffDTO: ISaleInvoiceWriteoffDTO;
|
writeoffDTO: ISaleInvoiceWriteoffDTO;
|
||||||
@@ -149,33 +141,28 @@ export interface ISaleInvoiceWriteoffCreatePayload {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ISaleInvoiceWriteoffCreatedPayload {
|
export interface ISaleInvoiceWriteoffCreatedPayload {
|
||||||
// tenantId: number;
|
|
||||||
saleInvoiceId: number;
|
saleInvoiceId: number;
|
||||||
saleInvoice: SaleInvoice;
|
saleInvoice: SaleInvoice;
|
||||||
writeoffDTO: ISaleInvoiceCreatedPayload;
|
writeoffDTO: ISaleInvoiceCreatedPayload;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ISaleInvoiceWrittenOffCancelPayload {
|
export interface ISaleInvoiceWrittenOffCancelPayload {
|
||||||
// tenantId: number;
|
|
||||||
saleInvoice: SaleInvoice;
|
saleInvoice: SaleInvoice;
|
||||||
trx: Knex.Transaction;
|
trx: Knex.Transaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ISaleInvoiceWrittenOffCanceledPayload {
|
export interface ISaleInvoiceWrittenOffCanceledPayload {
|
||||||
// tenantId: number;
|
|
||||||
saleInvoice: SaleInvoice;
|
saleInvoice: SaleInvoice;
|
||||||
trx: Knex.Transaction;
|
trx: Knex.Transaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ISaleInvoiceEventDeliveredPayload {
|
export interface ISaleInvoiceEventDeliveredPayload {
|
||||||
// tenantId: number;
|
|
||||||
saleInvoiceId: number;
|
saleInvoiceId: number;
|
||||||
saleInvoice: SaleInvoice;
|
saleInvoice: SaleInvoice;
|
||||||
trx: Knex.Transaction;
|
trx: Knex.Transaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ISaleInvoiceDeliveringPayload {
|
export interface ISaleInvoiceDeliveringPayload {
|
||||||
// tenantId: number;
|
|
||||||
oldSaleInvoice: SaleInvoice;
|
oldSaleInvoice: SaleInvoice;
|
||||||
trx: Knex.Transaction;
|
trx: Knex.Transaction;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,146 +1,148 @@
|
|||||||
// import { Service, Inject } from 'typedi';
|
import * as R from 'ramda';
|
||||||
// import * as R from 'ramda';
|
import { Knex } from 'knex';
|
||||||
// import { Knex } from 'knex';
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
// import { AccountNormal, IInventoryLotCost, ILedgerEntry } from '@/interfaces';
|
import { TenantModelProxy } from '../System/models/TenantBaseModel';
|
||||||
// import { increment } from 'utils';
|
import { InventoryCostLotTracker } from '../InventoryCost/models/InventoryCostLotTracker';
|
||||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
import { LedgerStorageService } from '../Ledger/LedgerStorage.service';
|
||||||
// import Ledger from '@/services/Accounting/Ledger';
|
import { groupInventoryTransactionsByTypeId } from '../InventoryCost/utils';
|
||||||
// import LedgerStorageService from '@/services/Accounting/LedgerStorageService';
|
import { Ledger } from '../Ledger/Ledger';
|
||||||
// import { groupInventoryTransactionsByTypeId } from '../../Inventory/utils';
|
import { AccountNormal } from '@/interfaces/Account';
|
||||||
|
import { ILedgerEntry } from '../Ledger/types/Ledger.types';
|
||||||
|
import { increment } from '@/utils/increment';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class SaleInvoiceCostGLEntries {
|
export class SaleInvoiceCostGLEntries {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private tenancy: HasTenancyService;
|
private readonly ledgerStorage: LedgerStorageService,
|
||||||
|
|
||||||
// @Inject()
|
@Inject(InventoryCostLotTracker.name)
|
||||||
// private ledgerStorage: LedgerStorageService;
|
private readonly inventoryCostLotTracker: TenantModelProxy<
|
||||||
|
typeof InventoryCostLotTracker
|
||||||
|
>,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Writes journal entries from sales invoices.
|
* Writes journal entries from sales invoices.
|
||||||
// * @param {number} tenantId - The tenant id.
|
* @param {Date} startingDate - Starting date.
|
||||||
// * @param {Date} startingDate - Starting date.
|
* @param {boolean} override
|
||||||
// * @param {boolean} override
|
*/
|
||||||
// */
|
public writeInventoryCostJournalEntries = async (
|
||||||
// public writeInventoryCostJournalEntries = async (
|
startingDate: Date,
|
||||||
// tenantId: number,
|
trx?: Knex.Transaction,
|
||||||
// startingDate: Date,
|
): Promise<void> => {
|
||||||
// trx?: Knex.Transaction
|
const inventoryCostLotTrans = await this.inventoryCostLotTracker()
|
||||||
// ): Promise<void> => {
|
.query()
|
||||||
// const { InventoryCostLotTracker } = this.tenancy.models(tenantId);
|
.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()
|
const ledger = this.getInventoryCostLotsLedger(inventoryCostLotTrans);
|
||||||
// .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);
|
// 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);
|
||||||
|
|
||||||
// /**
|
const entries = inventoryTransactions
|
||||||
// * Retrieves the inventory cost lots ledger.
|
.map(this.getSaleInvoiceCostGLEntries)
|
||||||
// * @param {IInventoryLotCost[]} inventoryCostLots
|
.flat();
|
||||||
// * @returns {Ledger}
|
return new Ledger(entries);
|
||||||
// */
|
};
|
||||||
// private getInventoryCostLotsLedger = (
|
|
||||||
// inventoryCostLots: IInventoryLotCost[]
|
|
||||||
// ) => {
|
|
||||||
// // Groups the inventory cost lots transactions.
|
|
||||||
// const inventoryTransactions =
|
|
||||||
// groupInventoryTransactionsByTypeId(inventoryCostLots);
|
|
||||||
|
|
||||||
// const entries = inventoryTransactions
|
/**
|
||||||
// .map(this.getSaleInvoiceCostGLEntries)
|
*
|
||||||
// .flat();
|
* @param {IInventoryLotCost} inventoryCostLot
|
||||||
// return new Ledger(entries);
|
* @returns {}
|
||||||
// };
|
*/
|
||||||
|
private getInvoiceCostGLCommonEntry = (
|
||||||
|
inventoryCostLot: InventoryCostLotTracker,
|
||||||
|
) => {
|
||||||
|
return {
|
||||||
|
currencyCode: inventoryCostLot.invoice.currencyCode,
|
||||||
|
exchangeRate: inventoryCostLot.invoice.exchangeRate,
|
||||||
|
|
||||||
// /**
|
transactionType: inventoryCostLot.transactionType,
|
||||||
// *
|
transactionId: inventoryCostLot.transactionId,
|
||||||
// * @param {IInventoryLotCost} inventoryCostLot
|
|
||||||
// * @returns {}
|
|
||||||
// */
|
|
||||||
// private getInvoiceCostGLCommonEntry = (
|
|
||||||
// inventoryCostLot: IInventoryLotCost
|
|
||||||
// ) => {
|
|
||||||
// return {
|
|
||||||
// currencyCode: inventoryCostLot.invoice.currencyCode,
|
|
||||||
// exchangeRate: inventoryCostLot.invoice.exchangeRate,
|
|
||||||
|
|
||||||
// transactionType: inventoryCostLot.transactionType,
|
date: inventoryCostLot.date,
|
||||||
// transactionId: inventoryCostLot.transactionId,
|
indexGroup: 20,
|
||||||
|
costable: true,
|
||||||
|
createdAt: inventoryCostLot.createdAt,
|
||||||
|
|
||||||
// date: inventoryCostLot.date,
|
debit: 0,
|
||||||
// indexGroup: 20,
|
credit: 0,
|
||||||
// costable: true,
|
|
||||||
// createdAt: inventoryCostLot.createdAt,
|
|
||||||
|
|
||||||
// debit: 0,
|
branchId: inventoryCostLot.invoice.branchId,
|
||||||
// credit: 0,
|
};
|
||||||
|
};
|
||||||
|
|
||||||
// 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;
|
||||||
|
|
||||||
// /**
|
// XXX Debit - Cost account.
|
||||||
// * Retrieves the inventory cost GL entry.
|
const costEntry = {
|
||||||
// * @param {IInventoryLotCost} inventoryLotCost
|
...commonEntry,
|
||||||
// * @returns {ILedgerEntry[]}
|
debit: inventoryCostLot.cost,
|
||||||
// */
|
accountId: costAccountId,
|
||||||
// private getInventoryCostGLEntry = R.curry(
|
accountNormal: AccountNormal.DEBIT,
|
||||||
// (
|
itemId: inventoryCostLot.itemId,
|
||||||
// getIndexIncrement,
|
index: getIndexIncrement(),
|
||||||
// inventoryCostLot: IInventoryLotCost
|
};
|
||||||
// ): ILedgerEntry[] => {
|
// XXX Credit - Inventory account.
|
||||||
// const commonEntry = this.getInvoiceCostGLCommonEntry(inventoryCostLot);
|
const inventoryEntry = {
|
||||||
// const costAccountId =
|
...commonEntry,
|
||||||
// inventoryCostLot.costAccountId || inventoryCostLot.item.costAccountId;
|
credit: inventoryCostLot.cost,
|
||||||
|
accountId: inventoryCostLot.item.inventoryAccountId,
|
||||||
|
accountNormal: AccountNormal.DEBIT,
|
||||||
|
itemId: inventoryCostLot.itemId,
|
||||||
|
index: getIndexIncrement(),
|
||||||
|
};
|
||||||
|
return [costEntry, inventoryEntry];
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
// // XXX Debit - Cost account.
|
/**
|
||||||
// const costEntry = {
|
* Writes journal entries for given sale invoice.
|
||||||
// ...commonEntry,
|
* -----
|
||||||
// debit: inventoryCostLot.cost,
|
* - Cost of goods sold -> Debit -> YYYY
|
||||||
// accountId: costAccountId,
|
* - Inventory assets -> Credit -> YYYY
|
||||||
// accountNormal: AccountNormal.DEBIT,
|
*-----
|
||||||
// itemId: inventoryCostLot.itemId,
|
* @param {ISaleInvoice} saleInvoice
|
||||||
// index: getIndexIncrement(),
|
* @param {JournalPoster} journal
|
||||||
// };
|
*/
|
||||||
// // XXX Credit - Inventory account.
|
public getSaleInvoiceCostGLEntries = (
|
||||||
// const inventoryEntry = {
|
inventoryCostLots: InventoryCostLotTracker[],
|
||||||
// ...commonEntry,
|
): ILedgerEntry[] => {
|
||||||
// credit: inventoryCostLot.cost,
|
const getIndexIncrement = increment(0);
|
||||||
// accountId: inventoryCostLot.item.inventoryAccountId,
|
const getInventoryLotEntry =
|
||||||
// accountNormal: AccountNormal.DEBIT,
|
this.getInventoryCostGLEntry(getIndexIncrement);
|
||||||
// itemId: inventoryCostLot.itemId,
|
|
||||||
// index: getIndexIncrement(),
|
|
||||||
// };
|
|
||||||
// return [costEntry, inventoryEntry];
|
|
||||||
// }
|
|
||||||
// );
|
|
||||||
|
|
||||||
// /**
|
return inventoryCostLots.map((t) => getInventoryLotEntry(t)).flat();
|
||||||
// * 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();
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -47,6 +47,14 @@ import { MailNotificationModule } from '../MailNotification/MailNotification.mod
|
|||||||
import { SendSaleInvoiceMailProcessor } from './processors/SendSaleInvoiceMail.processor';
|
import { SendSaleInvoiceMailProcessor } from './processors/SendSaleInvoiceMail.processor';
|
||||||
import { BullModule } from '@nestjs/bull';
|
import { BullModule } from '@nestjs/bull';
|
||||||
import { SendSaleInvoiceQueue } from './constants';
|
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({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -57,6 +65,7 @@ import { SendSaleInvoiceQueue } from './constants';
|
|||||||
BranchesModule,
|
BranchesModule,
|
||||||
WarehousesModule,
|
WarehousesModule,
|
||||||
TaxRatesModule,
|
TaxRatesModule,
|
||||||
|
PaymentsReceivedModule,
|
||||||
LedgerModule,
|
LedgerModule,
|
||||||
AccountsModule,
|
AccountsModule,
|
||||||
MailModule,
|
MailModule,
|
||||||
@@ -100,6 +109,13 @@ import { SendSaleInvoiceQueue } from './constants';
|
|||||||
GetSaleInvoiceMailState,
|
GetSaleInvoiceMailState,
|
||||||
SendSaleInvoiceMailCommon,
|
SendSaleInvoiceMailCommon,
|
||||||
SendSaleInvoiceMailProcessor,
|
SendSaleInvoiceMailProcessor,
|
||||||
|
SaleInvoiceCostGLEntries,
|
||||||
|
InvoicePaymentIntegrationSubscriber,
|
||||||
|
InvoiceChangeStatusOnMailSentSubscriber,
|
||||||
|
InvoiceCostGLEntriesSubscriber,
|
||||||
|
InvoicePaymentGLRewriteSubscriber,
|
||||||
|
SaleInvoiceWriteInventoryTransactionsSubscriber,
|
||||||
|
InvoicePaymentsGLEntriesRewrite
|
||||||
],
|
],
|
||||||
exports: [GetSaleInvoice],
|
exports: [GetSaleInvoice],
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ export class CreateSaleInvoice {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Transformes create DTO to model.
|
* Transformes create DTO to model.
|
||||||
* @param {ICustomer} customer -
|
* @param {Customer} customer -
|
||||||
* @param {ISaleInvoiceCreateDTO} saleInvoiceDTO -
|
* @param {ISaleInvoiceCreateDTO} saleInvoiceDTO -
|
||||||
*/
|
*/
|
||||||
private transformCreateDTOToModel = async (
|
private transformCreateDTOToModel = async (
|
||||||
|
|||||||
@@ -16,6 +16,12 @@ import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
|||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class DeliverSaleInvoice {
|
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(
|
constructor(
|
||||||
private eventEmitter: EventEmitter2,
|
private eventEmitter: EventEmitter2,
|
||||||
private uow: UnitOfWork,
|
private uow: UnitOfWork,
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import { DiscountType } from '@/common/types/Discount';
|
|||||||
import { Account } from '@/modules/Accounts/models/Account.model';
|
import { Account } from '@/modules/Accounts/models/Account.model';
|
||||||
import { ISearchRole } from '@/modules/DynamicListing/DynamicFilter/DynamicFilter.types';
|
import { ISearchRole } from '@/modules/DynamicListing/DynamicFilter/DynamicFilter.types';
|
||||||
import { TenantBaseModel } from '@/modules/System/models/TenantBaseModel';
|
import { TenantBaseModel } from '@/modules/System/models/TenantBaseModel';
|
||||||
|
import { PaymentIntegrationTransactionLink } from '../SaleInvoice.types';
|
||||||
|
|
||||||
export class SaleInvoice extends TenantBaseModel{
|
export class SaleInvoice extends TenantBaseModel{
|
||||||
public taxAmountWithheld: number;
|
public taxAmountWithheld: number;
|
||||||
@@ -51,7 +52,8 @@ export class SaleInvoice extends TenantBaseModel{
|
|||||||
public entries!: ItemEntry[];
|
public entries!: ItemEntry[];
|
||||||
public attachments!: Document[];
|
public attachments!: Document[];
|
||||||
public writtenoffExpenseAccount!: Account;
|
public writtenoffExpenseAccount!: Account;
|
||||||
|
public paymentMethods!: PaymentIntegrationTransactionLink[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Table name
|
* Table name
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,49 +1,36 @@
|
|||||||
// import { Inject, Service } from 'typedi';
|
import { Injectable } from '@nestjs/common';
|
||||||
// import events from '@/subscribers/events';
|
import { DeliverSaleInvoice } from '../commands/DeliverSaleInvoice.service';
|
||||||
// import { ISaleInvoiceMailSent } from '@/interfaces';
|
import { ERRORS } from '../constants';
|
||||||
// import { DeliverSaleInvoice } from '../commands/DeliverSaleInvoice.service';
|
import { OnEvent } from '@nestjs/event-emitter';
|
||||||
// import { ServiceError } from '@/exceptions';
|
import { events } from '@/common/events/events';
|
||||||
// import { ERRORS } from '../constants';
|
import { ServiceError } from '@/modules/Items/ServiceError';
|
||||||
|
import { ISaleInvoiceMailSent } from '../SaleInvoice.types';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class InvoiceChangeStatusOnMailSentSubscriber {
|
export class InvoiceChangeStatusOnMailSentSubscriber {
|
||||||
// @Inject()
|
constructor(private readonly markInvoiceDelivedService: DeliverSaleInvoice) {}
|
||||||
// private markInvoiceDelivedService: DeliverSaleInvoice;
|
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Attaches events.
|
* Marks the invoice delivered once the invoice mail sent.
|
||||||
// */
|
* @param {ISaleInvoiceMailSent}
|
||||||
// public attach(bus) {
|
* @returns {Promise<void>}
|
||||||
// bus.subscribe(events.saleInvoice.onPreMailSend, this.markInvoiceDelivered);
|
*/
|
||||||
// bus.subscribe(
|
@OnEvent(events.saleInvoice.onMailReminderSent)
|
||||||
// events.saleInvoice.onMailReminderSent,
|
@OnEvent(events.saleInvoice.onMailSent)
|
||||||
// this.markInvoiceDelivered
|
async markInvoiceDelivered({
|
||||||
// );
|
saleInvoiceId,
|
||||||
// }
|
messageOptions,
|
||||||
|
}: ISaleInvoiceMailSent) {
|
||||||
// /**
|
try {
|
||||||
// * Marks the invoice delivered once the invoice mail sent.
|
await this.markInvoiceDelivedService.deliverSaleInvoice(saleInvoiceId);
|
||||||
// * @param {ISaleInvoiceMailSent}
|
} catch (error) {
|
||||||
// * @returns {Promise<void>}
|
if (
|
||||||
// */
|
error instanceof ServiceError &&
|
||||||
// private markInvoiceDelivered = async ({
|
error.errorType === ERRORS.SALE_INVOICE_ALREADY_DELIVERED
|
||||||
// tenantId,
|
) {
|
||||||
// saleInvoiceId,
|
} else {
|
||||||
// messageOptions,
|
throw error;
|
||||||
// }: ISaleInvoiceMailSent) => {
|
}
|
||||||
// try {
|
}
|
||||||
// await this.markInvoiceDelivedService.deliverSaleInvoice(
|
}
|
||||||
// tenantId,
|
}
|
||||||
// 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 { Injectable } from '@nestjs/common';
|
||||||
// import events from '@/subscribers/events';
|
import { IInventoryCostLotsGLEntriesWriteEvent } from '@/modules/InventoryCost/types/InventoryCost.types';
|
||||||
// import { IInventoryCostLotsGLEntriesWriteEvent } from '@/interfaces';
|
import { SaleInvoiceCostGLEntries } from '../SaleInvoiceCostGLEntries';
|
||||||
// import { SaleInvoiceCostGLEntries } from '../SaleInvoiceCostGLEntries';
|
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class InvoiceCostGLEntriesSubscriber {
|
export class InvoiceCostGLEntriesSubscriber {
|
||||||
// @Inject()
|
constructor(private readonly invoiceCostEntries: SaleInvoiceCostGLEntries) {}
|
||||||
// invoiceCostEntries: SaleInvoiceCostGLEntries;
|
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Attaches events.
|
* Writes the invoices cost GL entries once the inventory cost lots be written.
|
||||||
// */
|
* @param {IInventoryCostLotsGLEntriesWriteEvent}
|
||||||
// public attach(bus) {
|
*/
|
||||||
// bus.subscribe(
|
async writeInvoicesCostEntriesOnCostLotsWritten({
|
||||||
// events.inventory.onCostLotsGLEntriesWrite,
|
trx,
|
||||||
// this.writeInvoicesCostEntriesOnCostLotsWritten
|
startingDate,
|
||||||
// );
|
}: IInventoryCostLotsGLEntriesWriteEvent) {
|
||||||
// }
|
await this.invoiceCostEntries.writeInventoryCostJournalEntries(
|
||||||
|
startingDate,
|
||||||
// /**
|
trx,
|
||||||
// * 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
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,37 +1,27 @@
|
|||||||
// import { Service, Inject } from 'typedi';
|
import { Injectable } from '@nestjs/common';
|
||||||
// import events from '@/subscribers/events';
|
import { OnEvent } from '@nestjs/event-emitter';
|
||||||
// import { ISaleInvoiceEditingPayload } from '@/interfaces';
|
import { events } from '@/common/events/events';
|
||||||
// import { InvoicePaymentsGLEntriesRewrite } from '../InvoicePaymentsGLRewrite';
|
import { ISaleInvoiceEditingPayload } from '../SaleInvoice.types';
|
||||||
|
import { InvoicePaymentsGLEntriesRewrite } from '../InvoicePaymentsGLRewrite';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class InvoicePaymentGLRewriteSubscriber {
|
export class InvoicePaymentGLRewriteSubscriber {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private invoicePaymentsRewriteGLEntries: InvoicePaymentsGLEntriesRewrite;
|
private readonly invoicePaymentsRewriteGLEntries: InvoicePaymentsGLEntriesRewrite,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Attaches events with handlers.
|
* Writes associated invoiceso of payment receive once edit.
|
||||||
// */
|
* @param {ISaleInvoiceEditingPayload} -
|
||||||
// public attach = (bus) => {
|
*/
|
||||||
// bus.subscribe(
|
@OnEvent(events.saleInvoice.onEdited)
|
||||||
// events.saleInvoice.onEdited,
|
async paymentGLEntriesRewriteOnPaymentEdit({
|
||||||
// this.paymentGLEntriesRewriteOnPaymentEdit
|
oldSaleInvoice,
|
||||||
// );
|
trx,
|
||||||
// return bus;
|
}: ISaleInvoiceEditingPayload) {
|
||||||
// };
|
await this.invoicePaymentsRewriteGLEntries.invoicePaymentsGLEntriesRewrite(
|
||||||
|
oldSaleInvoice.id,
|
||||||
// /**
|
trx,
|
||||||
// * 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
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,93 +1,75 @@
|
|||||||
// import { Service, Inject } from 'typedi';
|
import { Injectable } from '@nestjs/common';
|
||||||
// import { omit } from 'lodash';
|
import { EventEmitter2, OnEvent } from '@nestjs/event-emitter';
|
||||||
// import events from '@/subscribers/events';
|
import { PaymentIntegrationTransactionLinkDeleteEventPayload } from '../SaleInvoice.types';
|
||||||
// import {
|
import { PaymentIntegrationTransactionLinkEventPayload } from '../SaleInvoice.types';
|
||||||
// ISaleInvoiceCreatedPayload,
|
import { PaymentIntegrationTransactionLink } from '../SaleInvoice.types';
|
||||||
// ISaleInvoiceDeletingPayload,
|
import { omit } from 'lodash';
|
||||||
// PaymentIntegrationTransactionLink,
|
import {
|
||||||
// PaymentIntegrationTransactionLinkDeleteEventPayload,
|
ISaleInvoiceCreatedPayload,
|
||||||
// PaymentIntegrationTransactionLinkEventPayload,
|
ISaleInvoiceDeletingPayload,
|
||||||
// } from '@/interfaces';
|
} from '../SaleInvoice.types';
|
||||||
// import { EventPublisher } from '@/lib/EventPublisher/EventPublisher';
|
import { events } from '@/common/events/events';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class InvoicePaymentIntegrationSubscriber {
|
export class InvoicePaymentIntegrationSubscriber {
|
||||||
// @Inject()
|
constructor(private readonly eventPublisher: EventEmitter2) {}
|
||||||
// private eventPublisher: EventPublisher;
|
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Attaches events with handlers.
|
* 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
|
||||||
// public attach = (bus) => {
|
* integration link event for each method.
|
||||||
// bus.subscribe(
|
* @param {ISaleInvoiceCreatedPayload} payload - The payload containing sale invoice creation details.
|
||||||
// events.saleInvoice.onCreated,
|
*/
|
||||||
// this.handleCreatePaymentIntegrationEvents
|
@OnEvent(events.saleInvoice.onCreated)
|
||||||
// );
|
public handleCreatePaymentIntegrationEvents({
|
||||||
// bus.subscribe(
|
saleInvoiceDTO,
|
||||||
// events.saleInvoice.onDeleting,
|
saleInvoice,
|
||||||
// this.handleCreatePaymentIntegrationEventsOnDeleteInvoice
|
trx,
|
||||||
// );
|
}: ISaleInvoiceCreatedPayload) {
|
||||||
// return bus;
|
const paymentMethods =
|
||||||
// };
|
saleInvoice.paymentMethods?.filter((method) => method.enable) || [];
|
||||||
|
|
||||||
// /**
|
paymentMethods.map(
|
||||||
// * Handles the creation of payment integration events when a sale invoice is created.
|
async (paymentMethod: PaymentIntegrationTransactionLink) => {
|
||||||
// * This method filters enabled payment methods from the invoice and emits a payment
|
const payload = {
|
||||||
// * integration link event for each method.
|
...omit(paymentMethod, ['id']),
|
||||||
// * @param {ISaleInvoiceCreatedPayload} payload - The payload containing sale invoice creation details.
|
saleInvoiceId: saleInvoice.id,
|
||||||
// */
|
trx,
|
||||||
// private handleCreatePaymentIntegrationEvents = ({
|
};
|
||||||
// tenantId,
|
await this.eventPublisher.emitAsync(
|
||||||
// saleInvoiceDTO,
|
events.paymentIntegrationLink.onPaymentIntegrationLink,
|
||||||
// saleInvoice,
|
payload as PaymentIntegrationTransactionLinkEventPayload,
|
||||||
// trx,
|
);
|
||||||
// }: ISaleInvoiceCreatedPayload) => {
|
},
|
||||||
// const paymentMethods =
|
);
|
||||||
// saleInvoice.paymentMethods?.filter((method) => method.enable) || [];
|
}
|
||||||
|
|
||||||
// paymentMethods.map(
|
/**
|
||||||
// async (paymentMethod: PaymentIntegrationTransactionLink) => {
|
*
|
||||||
// const payload = {
|
* @param {ISaleInvoiceDeletingPayload} payload
|
||||||
// ...omit(paymentMethod, ['id']),
|
*/
|
||||||
// tenantId,
|
@OnEvent(events.saleInvoice.onDeleting)
|
||||||
// saleInvoiceId: saleInvoice.id,
|
public handleCreatePaymentIntegrationEventsOnDeleteInvoice({
|
||||||
// trx,
|
oldSaleInvoice,
|
||||||
// };
|
trx,
|
||||||
// await this.eventPublisher.emitAsync(
|
}: ISaleInvoiceDeletingPayload) {
|
||||||
// events.paymentIntegrationLink.onPaymentIntegrationLink,
|
const paymentMethods =
|
||||||
// payload as PaymentIntegrationTransactionLinkEventPayload
|
oldSaleInvoice.paymentMethods?.filter((method) => method.enable) || [];
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
|
|
||||||
// /**
|
paymentMethods.map(
|
||||||
// *
|
async (paymentMethod: PaymentIntegrationTransactionLink) => {
|
||||||
// * @param {ISaleInvoiceDeletingPayload} payload
|
const payload = {
|
||||||
// */
|
...omit(paymentMethod, ['id']),
|
||||||
// private handleCreatePaymentIntegrationEventsOnDeleteInvoice = ({
|
oldSaleInvoiceId: oldSaleInvoice.id,
|
||||||
// tenantId,
|
trx,
|
||||||
// oldSaleInvoice,
|
} as PaymentIntegrationTransactionLinkDeleteEventPayload;
|
||||||
// trx,
|
|
||||||
// }: ISaleInvoiceDeletingPayload) => {
|
|
||||||
// const paymentMethods =
|
|
||||||
// oldSaleInvoice.paymentMethods?.filter((method) => method.enable) || [];
|
|
||||||
|
|
||||||
// paymentMethods.map(
|
// Triggers `onPaymentIntegrationDeleteLink` event.
|
||||||
// async (paymentMethod: PaymentIntegrationTransactionLink) => {
|
await this.eventPublisher.emitAsync(
|
||||||
// const payload = {
|
events.paymentIntegrationLink.onPaymentIntegrationDeleteLink,
|
||||||
// ...omit(paymentMethod, ['id']),
|
payload,
|
||||||
// tenantId,
|
);
|
||||||
// oldSaleInvoiceId: oldSaleInvoice.id,
|
},
|
||||||
// trx,
|
);
|
||||||
// } as PaymentIntegrationTransactionLinkDeleteEventPayload;
|
}
|
||||||
|
}
|
||||||
// // 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 { Body, Controller, Get, Injectable, Post } from '@nestjs/common';
|
||||||
import { StripePaymentApplication } from './StripePaymentApplication';
|
import { StripePaymentApplication } from './StripePaymentApplication';
|
||||||
|
import { ApiTags } from '@nestjs/swagger';
|
||||||
|
|
||||||
@Controller('/stripe')
|
@Controller('/stripe')
|
||||||
|
@ApiTags('stripe')
|
||||||
export class StripeIntegrationController {
|
export class StripeIntegrationController {
|
||||||
constructor(private readonly stripePaymentApp: StripePaymentApplication) {}
|
constructor(private readonly stripePaymentApp: StripePaymentApplication) {}
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ export class ItemEntry extends BaseModel {
|
|||||||
|
|
||||||
public taxRateId: number;
|
public taxRateId: number;
|
||||||
|
|
||||||
|
public warehouseId: number;
|
||||||
|
|
||||||
item: Item;
|
item: Item;
|
||||||
allocatedCostEntries: BillLandedCostEntry[];
|
allocatedCostEntries: BillLandedCostEntry[];
|
||||||
|
|
||||||
|
|||||||
@@ -44,8 +44,7 @@ export class QueryTransactionsLocking {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the transactions locking module meta.
|
* Retrieve the transactions locking module meta.
|
||||||
* @param {number} tenantId -
|
* @param {TransactionsLockingGroup} module -
|
||||||
* @param {TransactionsLockingGroup} module -
|
|
||||||
* @returns {ITransactionLockingMetaPOJO}
|
* @returns {ITransactionLockingMetaPOJO}
|
||||||
*/
|
*/
|
||||||
public getTransactionsLockingModuleMeta = (
|
public getTransactionsLockingModuleMeta = (
|
||||||
|
|||||||
@@ -1,26 +1,24 @@
|
|||||||
// import { Service, Inject } from 'typedi';
|
import { Knex } from 'knex';
|
||||||
// import { Knex } from 'knex';
|
import { Injectable } from '@nestjs/common';
|
||||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
import { AccountTransaction } from '../Accounts/models/AccountTransaction.model';
|
||||||
|
import { TenantModelProxy } from '../System/models/TenantBaseModel';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class InventoryTransactionsWarehouses {
|
export class InventoryTransactionsWarehouses {
|
||||||
// @Inject()
|
constructor(
|
||||||
// tenancy: HasTenancyService;
|
private readonly accountTransactionModel: TenantModelProxy<typeof AccountTransaction>,
|
||||||
|
) {}
|
||||||
// /**
|
|
||||||
// * Updates all accounts transctions with the priamry branch.
|
/**
|
||||||
// * @param tenantId
|
* Updates all accounts transctions with the priamry branch.
|
||||||
// * @param primaryBranchId
|
* @param {number} primaryBranchId - The primary branch id.
|
||||||
// */
|
*/
|
||||||
// public updateTransactionsWithWarehouse = async (
|
public updateTransactionsWithWarehouse = async (
|
||||||
// tenantId: number,
|
primaryBranchId: number,
|
||||||
// primaryBranchId: number,
|
trx?: Knex.Transaction
|
||||||
// trx?: Knex.Transaction
|
) => {
|
||||||
// ) => {
|
await this.accountTransactionModel().query(trx).update({
|
||||||
// const { AccountTransaction } = await this.tenancy.models(tenantId);
|
branchId: primaryBranchId,
|
||||||
|
});
|
||||||
// await AccountTransaction.query(trx).update({
|
};
|
||||||
// branchId: primaryBranchId,
|
}
|
||||||
// });
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,38 +1,28 @@
|
|||||||
// import { Service, Inject } from 'typedi';
|
import { Injectable } from '@nestjs/common';
|
||||||
// import events from '@/subscribers/events';
|
import { InventoryTransactionsWarehouses } from './AccountsTransactionsWarehouses';
|
||||||
// import { InventoryTransactionsWarehouses } from './AccountsTransactionsWarehouses';
|
import { OnEvent } from '@nestjs/event-emitter';
|
||||||
// import { IBranchesActivatedPayload } from '@/interfaces';
|
import { IBranchesActivatedPayload } from '../Branches/Branches.types';
|
||||||
|
import { events } from '@/common/events/events';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class AccountsTransactionsWarehousesSubscribe {
|
export class AccountsTransactionsWarehousesSubscribe {
|
||||||
// @Inject()
|
constructor(
|
||||||
// accountsTransactionsWarehouses: InventoryTransactionsWarehouses;
|
private readonly accountsTransactionsWarehouses: InventoryTransactionsWarehouses,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Attaches events with handlers.
|
* Updates all GL transactions to primary branch once
|
||||||
// */
|
* the multi-branches activated.
|
||||||
// public attach = (bus) => {
|
* @param {IBranchesActivatedPayload}
|
||||||
// bus.subscribe(
|
*/
|
||||||
// events.branch.onActivated,
|
@OnEvent(events.branch.onActivated)
|
||||||
// this.updateGLTransactionsToPrimaryBranchOnActivated
|
async updateGLTransactionsToPrimaryBranchOnActivated({
|
||||||
// );
|
primaryBranch,
|
||||||
// return bus;
|
trx,
|
||||||
// };
|
}: IBranchesActivatedPayload) {
|
||||||
|
await this.accountsTransactionsWarehouses.updateTransactionsWithWarehouse(
|
||||||
// /**
|
primaryBranch.id,
|
||||||
// * Updates all GL transactions to primary branch once
|
trx,
|
||||||
// * the multi-branches activated.
|
);
|
||||||
// * @param {IBranchesActivatedPayload}
|
}
|
||||||
// */
|
}
|
||||||
// private updateGLTransactionsToPrimaryBranchOnActivated = async ({
|
|
||||||
// tenantId,
|
|
||||||
// primaryBranch,
|
|
||||||
// trx,
|
|
||||||
// }: IBranchesActivatedPayload) => {
|
|
||||||
// await this.accountsTransactionsWarehouses.updateTransactionsWithWarehouse(
|
|
||||||
// tenantId,
|
|
||||||
// primaryBranch.id,
|
|
||||||
// trx
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,30 +1,34 @@
|
|||||||
// import { Service, Inject } from 'typedi';
|
import { Injectable } from "@nestjs/common";
|
||||||
// import { IWarehouse } from '@/interfaces';
|
import { Warehouse } from "../models/Warehouse.model";
|
||||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
import { TenantModelProxy } from "@/modules/System/models/TenantBaseModel";
|
||||||
|
import { Bill } from "@/modules/Bills/models/Bill";
|
||||||
|
import { ItemEntry } from "@/modules/TransactionItemEntry/models/ItemEntry";
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class BillActivateWarehouses {
|
export class BillActivateWarehouses {
|
||||||
// @Inject()
|
constructor(
|
||||||
// tenancy: HasTenancyService;
|
private readonly billModel: TenantModelProxy<typeof Bill>,
|
||||||
|
private readonly itemEntryModel: TenantModelProxy<typeof ItemEntry>,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Updates all credit note transactions with the primary warehouse.
|
* Updates all credit note transactions with the primary warehouse.
|
||||||
// * @param {number} tenantId
|
* @param {Warehouse} primaryWarehouse
|
||||||
// * @param {number} primaryWarehouse
|
* @returns {Promise<void>}
|
||||||
// * @returns {Promise<void>}
|
*/
|
||||||
// */
|
public updateBillsWithWarehouse = async (
|
||||||
// public updateBillsWithWarehouse = async (
|
primaryWarehouse: Warehouse
|
||||||
// tenantId: number,
|
): Promise<void> => {
|
||||||
// primaryWarehouse: IWarehouse
|
// Updates the sale estimates with primary warehouse.
|
||||||
// ): Promise<void> => {
|
await this.billModel().query().update({
|
||||||
// const { Bill, ItemEntry } = this.tenancy.models(tenantId);
|
warehouseId: primaryWarehouse.id,
|
||||||
|
});
|
||||||
// // Updates the sale estimates with primary warehouse.
|
// Update the sale estimates entries with primary warehouse.
|
||||||
// await Bill.query().update({ warehouseId: primaryWarehouse.id });
|
await this.itemEntryModel()
|
||||||
|
.query()
|
||||||
// // Update the sale estimates entries with primary warehouse.
|
.where('referenceType', 'Bill')
|
||||||
// await ItemEntry.query().where('referenceType', 'Bill').update({
|
.update({
|
||||||
// warehouseId: primaryWarehouse.id,
|
warehouseId: primaryWarehouse.id,
|
||||||
// });
|
});
|
||||||
// };
|
};
|
||||||
// }
|
}
|
||||||
|
|||||||
@@ -1,30 +1,34 @@
|
|||||||
// import { Service, Inject } from 'typedi';
|
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||||
// import { IWarehouse } from '@/interfaces';
|
import { ItemEntry } from '@/modules/TransactionItemEntry/models/ItemEntry';
|
||||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
import { CreditNote } from '@/modules/CreditNotes/models/CreditNote';
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { Warehouse } from '../models/Warehouse.model';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class CreditNotesActivateWarehouses {
|
export class CreditNotesActivateWarehouses {
|
||||||
// @Inject()
|
constructor(
|
||||||
// tenancy: HasTenancyService;
|
private readonly creditNoteModel: TenantModelProxy<typeof CreditNote>,
|
||||||
|
private readonly itemEntryModel: TenantModelProxy<typeof ItemEntry>,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Updates all credit note transactions with the primary warehouse.
|
* Updates all credit note transactions with the primary warehouse.
|
||||||
// * @param {number} tenantId
|
* @param {Warehouse} primaryWarehouse
|
||||||
// * @param {number} primaryWarehouse
|
* @returns {Promise<void>}
|
||||||
// * @returns {Promise<void>}
|
*/
|
||||||
// */
|
public updateCreditsWithWarehouse = async (
|
||||||
// public updateCreditsWithWarehouse = async (
|
primaryWarehouse: Warehouse
|
||||||
// tenantId: number,
|
): Promise<void> => {
|
||||||
// primaryWarehouse: IWarehouse
|
// Updates the sale estimates with primary warehouse.
|
||||||
// ): Promise<void> => {
|
await this.creditNoteModel().query().update({
|
||||||
// const { CreditNote, ItemEntry } = this.tenancy.models(tenantId);
|
warehouseId: primaryWarehouse.id,
|
||||||
|
});
|
||||||
// // Updates the sale estimates with primary warehouse.
|
// Update the sale estimates entries with primary warehouse.
|
||||||
// await CreditNote.query().update({ warehouseId: primaryWarehouse.id });
|
await this.itemEntryModel()
|
||||||
|
.query()
|
||||||
// // Update the sale estimates entries with primary warehouse.
|
.where('referenceType', 'CreditNote')
|
||||||
// await ItemEntry.query().where('referenceType', 'CreditNote').update({
|
.update({
|
||||||
// warehouseId: primaryWarehouse.id,
|
warehouseId: primaryWarehouse.id,
|
||||||
// });
|
});
|
||||||
// };
|
};
|
||||||
// }
|
}
|
||||||
|
|||||||
@@ -1,30 +1,35 @@
|
|||||||
// import { Service, Inject } from 'typedi';
|
import { ItemEntry } from '@/modules/TransactionItemEntry/models/ItemEntry';
|
||||||
// import { IWarehouse } from '@/interfaces';
|
import { SaleEstimate } from '@/modules/SaleEstimates/models/SaleEstimate';
|
||||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { Warehouse } from '../models/Warehouse.model';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class EstimatesActivateWarehouses {
|
export class EstimatesActivateWarehouses {
|
||||||
// @Inject()
|
constructor(
|
||||||
// tenancy: HasTenancyService;
|
private readonly saleEstimateModel: TenantModelProxy<typeof SaleEstimate>,
|
||||||
|
private readonly itemEntryModel: TenantModelProxy<typeof ItemEntry>,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Updates all inventory transactions with the primary warehouse.
|
* Updates all inventory transactions with the primary warehouse.
|
||||||
// * @param {number} tenantId
|
* @param {Warehouse} primaryWarehouse
|
||||||
// * @param {number} primaryWarehouse
|
* @returns {Promise<void>}
|
||||||
// * @returns {Promise<void>}
|
*/
|
||||||
// */
|
public updateEstimatesWithWarehouse = async (
|
||||||
// public updateEstimatesWithWarehouse = async (
|
primaryWarehouse: Warehouse,
|
||||||
// tenantId: number,
|
): Promise<void> => {
|
||||||
// primaryWarehouse: IWarehouse
|
// Updates the sale estimates with primary warehouse.
|
||||||
// ): Promise<void> => {
|
await this.saleEstimateModel()
|
||||||
// const { SaleEstimate, ItemEntry } = this.tenancy.models(tenantId);
|
.query()
|
||||||
|
.update({ warehouseId: primaryWarehouse.id });
|
||||||
|
|
||||||
// // Updates the sale estimates with primary warehouse.
|
// Update the sale estimates entries with primary warehouse.
|
||||||
// await SaleEstimate.query().update({ warehouseId: primaryWarehouse.id });
|
await this.itemEntryModel()
|
||||||
|
.query()
|
||||||
// // Update the sale estimates entries with primary warehouse.
|
.where('referenceType', 'SaleEstimate')
|
||||||
// await ItemEntry.query().where('referenceType', 'SaleEstimate').update({
|
.update({
|
||||||
// warehouseId: primaryWarehouse.id,
|
warehouseId: primaryWarehouse.id,
|
||||||
// });
|
});
|
||||||
// };
|
};
|
||||||
// }
|
}
|
||||||
|
|||||||
@@ -1,31 +1,31 @@
|
|||||||
// import { Service, Inject } from 'typedi';
|
import { InventoryTransaction } from "@/modules/InventoryCost/models/InventoryTransaction";
|
||||||
// import { IWarehouse } from '@/interfaces';
|
import { TenantModelProxy } from "@/modules/System/models/TenantBaseModel";
|
||||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
import { Injectable } from "@nestjs/common";
|
||||||
|
import { Warehouse } from "../models/Warehouse.model";
|
||||||
|
import { InventoryCostLotTracker } from "@/modules/InventoryCost/models/InventoryCostLotTracker";
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class InventoryActivateWarehouses {
|
export class InventoryActivateWarehouses {
|
||||||
// @Inject()
|
constructor(
|
||||||
// tenancy: HasTenancyService;
|
private readonly inventoryTransactionModel: TenantModelProxy<typeof InventoryTransaction>,
|
||||||
|
private readonly inventoryCostLotTrackerModel: TenantModelProxy<typeof InventoryCostLotTracker>,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Updates all inventory transactions with the primary warehouse.
|
* Updates all inventory transactions with the primary warehouse.
|
||||||
// * @param {number} tenantId
|
* @param {number} tenantId
|
||||||
// * @param {number} primaryWarehouse
|
* @param {number} primaryWarehouse
|
||||||
// * @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
// */
|
*/
|
||||||
// public updateInventoryTransactionsWithWarehouse = async (
|
public updateInventoryTransactionsWithWarehouse = async (
|
||||||
// tenantId: number,
|
primaryWarehouse: Warehouse
|
||||||
// primaryWarehouse: IWarehouse
|
): Promise<void> => {
|
||||||
// ): Promise<void> => {
|
// Updates the inventory transactions with primary warehouse.
|
||||||
// const { InventoryTransaction, InventoryCostLotTracker } =
|
await this.inventoryTransactionModel().query().update({
|
||||||
// this.tenancy.models(tenantId);
|
warehouseId: primaryWarehouse.id,
|
||||||
|
});
|
||||||
// // Updates the inventory transactions with primary warehouse.
|
await this.inventoryCostLotTrackerModel().query().update({
|
||||||
// await InventoryTransaction.query().update({
|
warehouseId: primaryWarehouse.id,
|
||||||
// warehouseId: primaryWarehouse.id,
|
});
|
||||||
// });
|
};
|
||||||
// await InventoryCostLotTracker.query().update({
|
}
|
||||||
// warehouseId: primaryWarehouse.id,
|
|
||||||
// });
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,30 +1,36 @@
|
|||||||
// import { Service, Inject } from 'typedi';
|
import { Injectable } from "@nestjs/common";
|
||||||
// import { IWarehouse } from '@/interfaces';
|
import { Warehouse } from "../models/Warehouse.model";
|
||||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
import { SaleInvoice } from "@/modules/SaleInvoices/models/SaleInvoice";
|
||||||
|
import { ItemEntry } from "@/modules/TransactionItemEntry/models/ItemEntry";
|
||||||
|
import { TenantModelProxy } from "@/modules/System/models/TenantBaseModel";
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class InvoicesActivateWarehouses {
|
export class InvoicesActivateWarehouses {
|
||||||
// @Inject()
|
constructor(
|
||||||
// tenancy: HasTenancyService;
|
private readonly saleInvoiceModel: TenantModelProxy<typeof SaleInvoice>,
|
||||||
|
private readonly itemEntryModel: TenantModelProxy<typeof ItemEntry>,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Updates all inventory transactions with the primary warehouse.
|
* Updates all inventory transactions with the primary warehouse.
|
||||||
// * @param {number} tenantId
|
* @param {Warehouse} primaryWarehouse
|
||||||
// * @param {number} primaryWarehouse
|
* @returns {Promise<void>}
|
||||||
// * @returns {Promise<void>}
|
*/
|
||||||
// */
|
updateInvoicesWithWarehouse = async (
|
||||||
// public updateInvoicesWithWarehouse = async (
|
primaryWarehouse: Warehouse
|
||||||
// tenantId: number,
|
): Promise<void> => {
|
||||||
// primaryWarehouse: IWarehouse
|
// Updates the sale invoices with primary warehouse.
|
||||||
// ): Promise<void> => {
|
await this.saleInvoiceModel().query().update({
|
||||||
// const { SaleInvoice, ItemEntry } = this.tenancy.models(tenantId);
|
warehouseId: primaryWarehouse.id,
|
||||||
|
});
|
||||||
|
|
||||||
// // Updates the sale invoices with primary warehouse.
|
// Update the sale invoices entries with primary warehouse.
|
||||||
// await SaleInvoice.query().update({ warehouseId: primaryWarehouse.id });
|
await this.itemEntryModel()
|
||||||
|
.query()
|
||||||
// // Update the sale invoices entries with primary warehouse.
|
.where('referenceType', 'SaleInvoice')
|
||||||
// await ItemEntry.query().where('referenceType', 'SaleInvoice').update({
|
.update({
|
||||||
// warehouseId: primaryWarehouse.id,
|
warehouseId: primaryWarehouse.id,
|
||||||
// });
|
});
|
||||||
// };
|
};
|
||||||
// }
|
}
|
||||||
|
|||||||
@@ -1,30 +1,34 @@
|
|||||||
// import { Service, Inject } from 'typedi';
|
import { Injectable } from '@nestjs/common';
|
||||||
// import { IWarehouse } from '@/interfaces';
|
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
import { ItemEntry } from '@/modules/TransactionItemEntry/models/ItemEntry';
|
||||||
|
import { Warehouse } from '../models/Warehouse.model';
|
||||||
|
import { SaleReceipt } from '@/modules/SaleReceipts/models/SaleReceipt';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class ReceiptActivateWarehouses {
|
export class ReceiptActivateWarehouses {
|
||||||
// @Inject()
|
constructor(
|
||||||
// tenancy: HasTenancyService;
|
private readonly saleReceiptModel: TenantModelProxy<typeof SaleReceipt>,
|
||||||
|
private readonly itemEntryModel: TenantModelProxy<typeof ItemEntry>,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Updates all sale receipts transactions with the primary warehouse.
|
* Updates all sale receipts transactions with the primary warehouse.
|
||||||
// * @param {number} tenantId
|
* @param {Warehouse} primaryWarehouse
|
||||||
// * @param {number} primaryWarehouse
|
* @returns {Promise<void>}
|
||||||
// * @returns {Promise<void>}
|
*/
|
||||||
// */
|
public updateReceiptsWithWarehouse = async (
|
||||||
// public updateReceiptsWithWarehouse = async (
|
primaryWarehouse: Warehouse,
|
||||||
// tenantId: number,
|
): Promise<void> => {
|
||||||
// primaryWarehouse: IWarehouse
|
// Updates the vendor credits transactions with primary warehouse.
|
||||||
// ): Promise<void> => {
|
await this.saleReceiptModel().query().update({
|
||||||
// const { SaleReceipt, ItemEntry } = this.tenancy.models(tenantId);
|
warehouseId: primaryWarehouse.id,
|
||||||
|
});
|
||||||
// // Updates the vendor credits transactions with primary warehouse.
|
// Update the sale invoices entries with primary warehouse.
|
||||||
// await SaleReceipt.query().update({ warehouseId: primaryWarehouse.id });
|
await this.itemEntryModel()
|
||||||
|
.query()
|
||||||
// // Update the sale invoices entries with primary warehouse.
|
.where('referenceType', 'SaleReceipt')
|
||||||
// await ItemEntry.query().where('referenceType', 'SaleReceipt').update({
|
.update({
|
||||||
// warehouseId: primaryWarehouse.id,
|
warehouseId: primaryWarehouse.id,
|
||||||
// });
|
});
|
||||||
// };
|
};
|
||||||
// }
|
}
|
||||||
|
|||||||
@@ -1,30 +1,35 @@
|
|||||||
// import { Service, Inject } from 'typedi';
|
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||||
// import { IWarehouse } from '@/interfaces';
|
import { VendorCredit } from '@/modules/VendorCredit/models/VendorCredit';
|
||||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
import { ItemEntry } from '@/modules/TransactionItemEntry/models/ItemEntry';
|
||||||
|
import { Warehouse } from '../models/Warehouse.model';
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class VendorCreditActivateWarehouses {
|
export class VendorCreditActivateWarehouses {
|
||||||
// @Inject()
|
constructor(
|
||||||
// tenancy: HasTenancyService;
|
private readonly vendorCreditModel: TenantModelProxy<typeof VendorCredit>,
|
||||||
|
private readonly itemEntryModel: TenantModelProxy<typeof ItemEntry>,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Updates all vendor credits transactions with the primary warehouse.
|
* Updates all vendor credits transactions with the primary warehouse.
|
||||||
// * @param {number} tenantId
|
* @param {Warehouse} primaryWarehouse
|
||||||
// * @param {number} primaryWarehouse
|
* @returns {Promise<void>}
|
||||||
// * @returns {Promise<void>}
|
*/
|
||||||
// */
|
public updateCreditsWithWarehouse = async (
|
||||||
// public updateCreditsWithWarehouse = async (
|
primaryWarehouse: Warehouse,
|
||||||
// tenantId: number,
|
): Promise<void> => {
|
||||||
// primaryWarehouse: IWarehouse
|
// Updates the vendor credits transactions with primary warehouse.
|
||||||
// ): Promise<void> => {
|
await this.vendorCreditModel().query().update({
|
||||||
// const { VendorCredit, ItemEntry } = this.tenancy.models(tenantId);
|
warehouseId: primaryWarehouse.id,
|
||||||
|
});
|
||||||
|
|
||||||
// // Updates the vendor credits transactions with primary warehouse.
|
// Update the sale invoices entries with primary warehouse.
|
||||||
// await VendorCredit.query().update({ warehouseId: primaryWarehouse.id });
|
await this.itemEntryModel()
|
||||||
|
.query()
|
||||||
// // Update the sale invoices entries with primary warehouse.
|
.where('referenceType', 'VendorCredit')
|
||||||
// await ItemEntry.query().where('referenceType', 'VendorCredit').update({
|
.update({
|
||||||
// warehouseId: primaryWarehouse.id,
|
warehouseId: primaryWarehouse.id,
|
||||||
// });
|
});
|
||||||
// };
|
};
|
||||||
// }
|
}
|
||||||
|
|||||||
@@ -1,58 +1,39 @@
|
|||||||
// import { Service, Inject } from 'typedi';
|
import { Injectable } from '@nestjs/common';
|
||||||
// import events from '@/subscribers/events';
|
import { OnEvent } from '@nestjs/event-emitter';
|
||||||
// import { IWarehousesActivatedPayload } from '@/interfaces';
|
import { events } from '@/common/events/events';
|
||||||
// import { UpdateInventoryTransactionsWithWarehouse } from './UpdateInventoryTransactionsWithWarehouse';
|
import { UpdateInventoryTransactionsWithWarehouse } from './UpdateInventoryTransactionsWithWarehouse';
|
||||||
// import { CreateInitialWarehousesItemsQuantity } from './CreateInitialWarehousesitemsQuantity';
|
import { CreateInitialWarehousesItemsQuantity } from './CreateInitialWarehousesitemsQuantity';
|
||||||
|
import { IWarehousesActivatedPayload } from './Warehouse.types';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class ActivateWarehousesSubscriber {
|
export class ActivateWarehousesSubscriber {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private updateInventoryTransactionsWithWarehouse: UpdateInventoryTransactionsWithWarehouse;
|
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.
|
* Creates initial warehouses items quantity once the multi-warehouses activated.
|
||||||
// */
|
* @param {IWarehousesActivatedPayload}
|
||||||
// attach(bus) {
|
*/
|
||||||
// bus.subscribe(
|
@OnEvent(events.warehouse.onActivated)
|
||||||
// events.warehouse.onActivated,
|
async createInitialWarehousesItemsQuantityOnActivating({
|
||||||
// this.updateInventoryTransactionsWithWarehouseOnActivating
|
primaryWarehouse,
|
||||||
// );
|
}: IWarehousesActivatedPayload) {
|
||||||
// bus.subscribe(
|
await this.createInitialWarehousesItemsQuantity.run(primaryWarehouse.id);
|
||||||
// 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
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,57 +1,55 @@
|
|||||||
// import { Service, Inject } from 'typedi';
|
import { Knex } from 'knex';
|
||||||
// import { Knex } from 'knex';
|
import { WarehousesItemsQuantitySync } from './Integrations/WarehousesItemsQuantitySync';
|
||||||
// import { IItem, IItemWarehouseQuantityChange } from '@/interfaces';
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
// import { WarehousesItemsQuantitySync } from './Integrations/WarehousesItemsQuantitySync';
|
import { IItemWarehouseQuantityChange } from './Warehouse.types';
|
||||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
import { Item } from '../Items/models/Item';
|
||||||
|
import { TenantModelProxy } from '../System/models/TenantBaseModel';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class CreateInitialWarehousesItemsQuantity {
|
export class CreateInitialWarehousesItemsQuantity {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private warehousesItemsQuantitySync: WarehousesItemsQuantitySync;
|
private readonly warehousesItemsQuantitySync: WarehousesItemsQuantitySync,
|
||||||
|
|
||||||
// @Inject()
|
@Inject(Item.name)
|
||||||
// private tenancy: HasTenancyService;
|
private readonly itemModel: TenantModelProxy<typeof Item>,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Retrieves items warehouses quantity changes of the given inventory items.
|
* Retrieves items warehouses quantity changes of the given inventory items.
|
||||||
// * @param {IItem[]} items
|
* @param {IItem[]} items
|
||||||
// * @param {IWarehouse} primaryWarehouse
|
* @param {IWarehouse} primaryWarehouse
|
||||||
// * @returns {IItemWarehouseQuantityChange[]}
|
* @returns {IItemWarehouseQuantityChange[]}
|
||||||
// */
|
*/
|
||||||
// private getWarehousesItemsChanges = (
|
private getWarehousesItemsChanges = (
|
||||||
// items: IItem[],
|
items: Item[],
|
||||||
// primaryWarehouseId: number
|
primaryWarehouseId: number,
|
||||||
// ): IItemWarehouseQuantityChange[] => {
|
): IItemWarehouseQuantityChange[] => {
|
||||||
// return items
|
return items
|
||||||
// .filter((item: IItem) => item.quantityOnHand)
|
.filter((item: Item) => item.quantityOnHand)
|
||||||
// .map((item: IItem) => ({
|
.map((item: Item) => ({
|
||||||
// itemId: item.id,
|
itemId: item.id,
|
||||||
// warehouseId: primaryWarehouseId,
|
warehouseId: primaryWarehouseId,
|
||||||
// amount: item.quantityOnHand,
|
amount: item.quantityOnHand,
|
||||||
// }));
|
}));
|
||||||
// };
|
};
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Creates initial warehouses items quantity.
|
* Creates initial warehouses items quantity.
|
||||||
// * @param {number} tenantId
|
* @param {number} tenantId
|
||||||
// */
|
*/
|
||||||
// public run = async (
|
public run = async (
|
||||||
// tenantId: number,
|
primaryWarehouseId: number,
|
||||||
// primaryWarehouseId: number,
|
trx?: Knex.Transaction,
|
||||||
// trx?: Knex.Transaction
|
): Promise<void> => {
|
||||||
// ): Promise<void> => {
|
const items = await this.itemModel().query(trx).where('type', 'Inventory');
|
||||||
// const { Item } = this.tenancy.models(tenantId);
|
|
||||||
|
|
||||||
// const items = await Item.query(trx).where('type', 'Inventory');
|
const warehousesChanges = this.getWarehousesItemsChanges(
|
||||||
|
items,
|
||||||
// const warehousesChanges = this.getWarehousesItemsChanges(
|
primaryWarehouseId,
|
||||||
// items,
|
);
|
||||||
// primaryWarehouseId
|
await this.warehousesItemsQuantitySync.mutateWarehousesItemsQuantity(
|
||||||
// );
|
warehousesChanges,
|
||||||
// await this.warehousesItemsQuantitySync.mutateWarehousesItemsQuantity(
|
trx,
|
||||||
// tenantId,
|
);
|
||||||
// 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 { chain, difference } from 'lodash';
|
import { Injectable } from '@nestjs/common';
|
||||||
// import { ServiceError } from '@/exceptions';
|
import { ERRORS } from './constants';
|
||||||
// import { ERRORS } from './constants';
|
import { ServiceError } from '@/modules/Items/ServiceError';
|
||||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||||
|
import { Warehouse } from '../models/Warehouse.model';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class ValidateWarehouseExistance {
|
export class ValidateWarehouseExistance {
|
||||||
// @Inject()
|
/**
|
||||||
// tenancy: HasTenancyService;
|
* @param {TenantModelProxy<typeof Warehouse>} warehouseModel - Warehouse model.
|
||||||
|
*/
|
||||||
|
constructor(
|
||||||
|
private readonly warehouseModel: TenantModelProxy<typeof Warehouse>,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Validate transaction warehouse id existance.
|
* Validate transaction warehouse id existance.
|
||||||
// * @param transDTO
|
* @param transDTO
|
||||||
// * @param entries
|
* @param entries
|
||||||
// */
|
*/
|
||||||
// public validateWarehouseIdExistance = (
|
public validateWarehouseIdExistance = (
|
||||||
// transDTO: { warehouseId?: number },
|
transDTO: { warehouseId?: number },
|
||||||
// entries: { warehouseId?: number }[] = []
|
entries: { warehouseId?: number }[] = [],
|
||||||
// ) => {
|
) => {
|
||||||
// const notAssignedWarehouseEntries = entries.filter((e) => !e.warehouseId);
|
const notAssignedWarehouseEntries = entries.filter((e) => !e.warehouseId);
|
||||||
|
|
||||||
// if (notAssignedWarehouseEntries.length > 0 && !transDTO.warehouseId) {
|
if (notAssignedWarehouseEntries.length > 0 && !transDTO.warehouseId) {
|
||||||
// throw new ServiceError(ERRORS.WAREHOUSE_ID_NOT_FOUND);
|
throw new ServiceError(ERRORS.WAREHOUSE_ID_NOT_FOUND);
|
||||||
// }
|
}
|
||||||
// if (entries.length === 0 && !transDTO.warehouseId) {
|
if (entries.length === 0 && !transDTO.warehouseId) {
|
||||||
// throw new ServiceError(ERRORS.WAREHOUSE_ID_NOT_FOUND);
|
throw new ServiceError(ERRORS.WAREHOUSE_ID_NOT_FOUND);
|
||||||
// }
|
}
|
||||||
// };
|
};
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Validate warehouse existance.
|
* Validate warehouse existance.
|
||||||
// * @param {number} tenantId
|
* @param {number} warehouseId - Warehouse id.
|
||||||
// * @param {number} warehouseId
|
*/
|
||||||
// */
|
public validateWarehouseExistance = (warehouseId: number) => {
|
||||||
// public validateWarehouseExistance = (
|
const warehouse = this.warehouseModel().query().findById(warehouseId);
|
||||||
// tenantId: number,
|
|
||||||
// warehouseId: number
|
|
||||||
// ) => {
|
|
||||||
// const { Warehouse } = this.tenancy.models(tenantId);
|
|
||||||
|
|
||||||
// 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();
|
||||||
|
|
||||||
// /**
|
const warehouses = await this.warehouseModel()
|
||||||
// *
|
.query()
|
||||||
// * @param {number} tenantId
|
.whereIn('id', entriesWarehousesIds);
|
||||||
// * @param {{ warehouseId?: number }[]} entries
|
const warehousesIds = warehouses.map((e) => e.id);
|
||||||
// */
|
const notFoundWarehousesIds = difference(
|
||||||
// public validateItemEntriesWarehousesExistance = async (
|
entriesWarehousesIds,
|
||||||
// tenantId: number,
|
warehousesIds,
|
||||||
// entries: { warehouseId?: number }[]
|
);
|
||||||
// ) => {
|
if (notFoundWarehousesIds.length > 0) {
|
||||||
// const { Warehouse } = this.tenancy.models(tenantId);
|
throw new ServiceError(ERRORS.WAREHOUSE_ID_NOT_FOUND);
|
||||||
|
}
|
||||||
// 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);
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,66 +1,58 @@
|
|||||||
// import { Service, Inject } from 'typedi';
|
import { Injectable } from '@nestjs/common';
|
||||||
// import { isEmpty } from 'lodash';
|
import { isEmpty } from 'lodash';
|
||||||
// import { ValidateWarehouseExistance } from './ValidateWarehouseExistance';
|
import { ValidateWarehouseExistance } from './ValidateWarehouseExistance';
|
||||||
// import { WarehousesSettings } from '../WarehousesSettings';
|
import { WarehousesSettings } from '../WarehousesSettings';
|
||||||
|
|
||||||
// interface IWarehouseTransactionDTO {
|
interface IWarehouseTransactionDTO {
|
||||||
// warehouseId?: number|null;
|
warehouseId?: number | null;
|
||||||
// entries?: { warehouseId?: number|null }[];
|
entries?: { warehouseId?: number | null }[];
|
||||||
// }
|
}
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class WarehousesDTOValidators {
|
export class WarehousesDTOValidators {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private validateWarehouseExistanceService: ValidateWarehouseExistance;
|
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.
|
* Validate the warehouse existance of
|
||||||
// * @param {number} tenantId
|
* @param {number} tenantId
|
||||||
// * @param {ISaleInvoiceCreateDTO | ISaleInvoiceEditDTO} saleInvoiceDTO
|
* @param {IWarehouseTransactionDTO} saleInvoiceDTO
|
||||||
// */
|
* @returns
|
||||||
// public validateDTOWarehouseExistance = async (
|
*/
|
||||||
// tenantId: number,
|
public validateDTOWarehouseWhenActive = async (
|
||||||
// DTO: IWarehouseTransactionDTO
|
DTO: IWarehouseTransactionDTO,
|
||||||
// ) => {
|
): Promise<void> => {
|
||||||
// // Validates the sale invoice warehouse id existance.
|
const isActive = this.warehousesSettings.isMultiWarehousesActive();
|
||||||
// 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
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
// /**
|
// Can't continue if the multi-warehouses feature is inactive.
|
||||||
// * Validate the warehouse existance of
|
if (!isActive) return;
|
||||||
// * @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.
|
return this.validateDTOWarehouseExistance(DTO);
|
||||||
// if (!isActive) return;
|
};
|
||||||
|
}
|
||||||
// return this.validateDTOWarehouseExistance(tenantId, DTO);
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,117 +1,115 @@
|
|||||||
// import {
|
import { IItemWarehouseQuantityChange } from '@/modules/Warehouses/Warehouse.types';
|
||||||
// IInventoryTransaction,
|
import { set, get, chain, toPairs } from 'lodash';
|
||||||
// IItemWarehouseQuantityChange,
|
import { InventoryTransaction } from '@/modules/InventoryCost/models/InventoryTransaction';
|
||||||
// } from '@/interfaces';
|
|
||||||
// import { set, get, chain, toPairs } from 'lodash';
|
|
||||||
|
|
||||||
// export class WarehousesItemsQuantity {
|
export class WarehousesItemsQuantity {
|
||||||
// balanceMap: { [warehouseId: number]: { [itemId: number]: number } } = {};
|
balanceMap: { [warehouseId: number]: { [itemId: number]: number } } = {};
|
||||||
// /**
|
/**
|
||||||
// *
|
*
|
||||||
// * @param {number} warehouseId
|
* @param {number} warehouseId
|
||||||
// * @param {number} itemId
|
* @param {number} itemId
|
||||||
// * @returns {number}
|
* @returns {number}
|
||||||
// */
|
*/
|
||||||
// public get = (warehouseId: number, itemId: number): number => {
|
public get = (warehouseId: number, itemId: number): number => {
|
||||||
// return get(this.balanceMap, `${warehouseId}.${itemId}`, 0);
|
return get(this.balanceMap, `${warehouseId}.${itemId}`, 0);
|
||||||
// };
|
};
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// *
|
*
|
||||||
// * @param {number} warehouseId
|
* @param {number} warehouseId
|
||||||
// * @param {number} itemId
|
* @param {number} itemId
|
||||||
// * @param {number} amount
|
* @param {number} amount
|
||||||
// * @returns {WarehousesItemsQuantity}
|
* @returns {WarehousesItemsQuantity}
|
||||||
// */
|
*/
|
||||||
// public set = (warehouseId: number, itemId: number, amount: number) => {
|
public set = (warehouseId: number, itemId: number, amount: number) => {
|
||||||
// if (!get(this.balanceMap, warehouseId)) {
|
if (!get(this.balanceMap, warehouseId)) {
|
||||||
// set(this.balanceMap, warehouseId, {});
|
set(this.balanceMap, warehouseId, {});
|
||||||
// }
|
}
|
||||||
// set(this.balanceMap, `${warehouseId}.${itemId}`, amount);
|
set(this.balanceMap, `${warehouseId}.${itemId}`, amount);
|
||||||
|
|
||||||
// return this;
|
return this;
|
||||||
// };
|
};
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// *
|
*
|
||||||
// * @param {number} warehouseId
|
* @param {number} warehouseId
|
||||||
// * @param {number} itemId
|
* @param {number} itemId
|
||||||
// * @param {number} amount
|
* @param {number} amount
|
||||||
// * @returns {WarehousesItemsQuantity}
|
* @returns {WarehousesItemsQuantity}
|
||||||
// */
|
*/
|
||||||
// public increment = (warehouseId: number, itemId: number, amount: number) => {
|
public increment = (warehouseId: number, itemId: number, amount: number) => {
|
||||||
// const oldAmount = this.get(warehouseId, itemId);
|
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} warehouseId
|
||||||
// * @param {number} itemId
|
* @param {number} itemId
|
||||||
// * @param {number} amount
|
* @param {number} amount
|
||||||
// * @returns {WarehousesItemsQuantity}
|
* @returns {WarehousesItemsQuantity}
|
||||||
// */
|
*/
|
||||||
// public decrement = (warehouseId: number, itemId: number, amount: number) => {
|
public decrement = (warehouseId: number, itemId: number, amount: number) => {
|
||||||
// const oldAmount = this.get(warehouseId, itemId);
|
const oldAmount = this.get(warehouseId, itemId);
|
||||||
|
|
||||||
// return this.set(warehouseId, itemId, oldAmount - amount);
|
return this.set(warehouseId, itemId, oldAmount - amount);
|
||||||
// };
|
};
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// *
|
*
|
||||||
// * @returns {WarehousesItemsQuantity}
|
* @returns {WarehousesItemsQuantity}
|
||||||
// */
|
*/
|
||||||
// public reverse = () => {
|
public reverse = () => {
|
||||||
// const collection = this.toArray();
|
const collection = this.toArray();
|
||||||
|
|
||||||
// collection.forEach((change) => {
|
collection.forEach((change) => {
|
||||||
// this.set(change.warehouseId, change.itemId, change.amount * -1);
|
this.set(change.warehouseId, change.itemId, change.amount * -1);
|
||||||
// });
|
});
|
||||||
// return this;
|
return this;
|
||||||
// };
|
};
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// *
|
*
|
||||||
// * @returns {IItemWarehouseQuantityChange[]}
|
* @returns {IItemWarehouseQuantityChange[]}
|
||||||
// */
|
*/
|
||||||
// public toArray = (): IItemWarehouseQuantityChange[] => {
|
public toArray = (): IItemWarehouseQuantityChange[] => {
|
||||||
// return chain(this.balanceMap)
|
return chain(this.balanceMap)
|
||||||
// .toPairs()
|
.toPairs()
|
||||||
// .map(([warehouseId, item]) => {
|
.map(([warehouseId, item]) => {
|
||||||
// const pairs = toPairs(item);
|
const pairs = toPairs(item);
|
||||||
|
|
||||||
// return pairs.map(([itemId, amount]) => ({
|
return pairs.map(([itemId, amount]) => ({
|
||||||
// itemId: parseInt(itemId),
|
itemId: parseInt(itemId),
|
||||||
// warehouseId: parseInt(warehouseId),
|
warehouseId: parseInt(warehouseId),
|
||||||
// amount,
|
amount,
|
||||||
// }));
|
}));
|
||||||
// })
|
})
|
||||||
// .flatten()
|
.flatten()
|
||||||
// .value();
|
.value();
|
||||||
// };
|
};
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// *
|
*
|
||||||
// * @param {IInventoryTransaction[]} inventoryTransactions
|
* @param {IInventoryTransaction[]} inventoryTransactions
|
||||||
// * @returns {WarehousesItemsQuantity}
|
* @returns {WarehousesItemsQuantity}
|
||||||
// */
|
*/
|
||||||
// static fromInventoryTransaction = (
|
static fromInventoryTransaction = (
|
||||||
// inventoryTransactions: IInventoryTransaction[]
|
inventoryTransactions: InventoryTransaction[],
|
||||||
// ): WarehousesItemsQuantity => {
|
): WarehousesItemsQuantity => {
|
||||||
// const warehouseTransactions = inventoryTransactions.filter(
|
const warehouseTransactions = inventoryTransactions.filter(
|
||||||
// (transaction) => transaction.warehouseId
|
(transaction) => transaction.warehouseId,
|
||||||
// );
|
);
|
||||||
// const warehouseItemsQuantity = new WarehousesItemsQuantity();
|
const warehouseItemsQuantity = new WarehousesItemsQuantity();
|
||||||
|
|
||||||
// warehouseTransactions.forEach((transaction: IInventoryTransaction) => {
|
warehouseTransactions.forEach((transaction: InventoryTransaction) => {
|
||||||
// const change =
|
const change =
|
||||||
// transaction.direction === 'IN'
|
transaction.direction === 'IN'
|
||||||
// ? warehouseItemsQuantity.increment
|
? warehouseItemsQuantity.increment
|
||||||
// : warehouseItemsQuantity.decrement;
|
: warehouseItemsQuantity.decrement;
|
||||||
|
|
||||||
// change(transaction.warehouseId, transaction.itemId, transaction.quantity);
|
change(transaction.warehouseId, transaction.itemId, transaction.quantity);
|
||||||
// });
|
});
|
||||||
// return warehouseItemsQuantity;
|
return warehouseItemsQuantity;
|
||||||
// };
|
};
|
||||||
// }
|
}
|
||||||
|
|||||||
@@ -1,74 +1,57 @@
|
|||||||
// import events from '@/subscribers/events';
|
import { WarehousesItemsQuantitySync } from './WarehousesItemsQuantitySync';
|
||||||
// import { Service, Inject } from 'typedi';
|
import { WarehousesSettings } from '../WarehousesSettings';
|
||||||
// import { WarehousesItemsQuantitySync } from './WarehousesItemsQuantitySync';
|
import { OnEvent } from '@nestjs/event-emitter';
|
||||||
// import {
|
import { Injectable } from '@nestjs/common';
|
||||||
// IInventoryTransactionsCreatedPayload,
|
import { events } from '@/common/events/events';
|
||||||
// IInventoryTransactionsDeletedPayload,
|
import {
|
||||||
// } from '@/interfaces';
|
IInventoryTransactionsCreatedPayload,
|
||||||
// import { WarehousesSettings } from '../WarehousesSettings';
|
IInventoryTransactionsDeletedPayload,
|
||||||
|
} from '@/modules/InventoryCost/types/InventoryCost.types';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class WarehousesItemsQuantitySyncSubscriber {
|
export class WarehousesItemsQuantitySyncSubscriber {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private warehousesItemsQuantitySync: WarehousesItemsQuantitySync;
|
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();
|
||||||
|
|
||||||
// /**
|
// Can't continue if the warehouses features is not active.
|
||||||
// * Attaches events with handlers.
|
if (!isActive) return;
|
||||||
// */
|
|
||||||
// public attach(bus) {
|
|
||||||
// bus.subscribe(
|
|
||||||
// events.inventory.onInventoryTransactionsCreated,
|
|
||||||
// this.syncWarehousesItemsQuantityOnInventoryTransCreated
|
|
||||||
// );
|
|
||||||
// bus.subscribe(
|
|
||||||
// events.inventory.onInventoryTransactionsDeleted,
|
|
||||||
// this.syncWarehousesItemsQuantityOnInventoryTransDeleted
|
|
||||||
// );
|
|
||||||
// return bus;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// /**
|
await this.warehousesItemsQuantitySync.mutateWarehousesItemsQuantityFromTransactions(
|
||||||
// * Syncs warehouses items quantity once inventory transactions created.
|
inventoryTransactions,
|
||||||
// * @param {IInventoryTransactionsCreatedPayload}
|
trx,
|
||||||
// */
|
);
|
||||||
// private syncWarehousesItemsQuantityOnInventoryTransCreated = async ({
|
}
|
||||||
// tenantId,
|
|
||||||
// inventoryTransactions,
|
|
||||||
// trx,
|
|
||||||
// }: IInventoryTransactionsCreatedPayload) => {
|
|
||||||
// const isActive = this.warehousesSettings.isMultiWarehousesActive(tenantId);
|
|
||||||
|
|
||||||
// // 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(
|
// Can't continue if the warehouses feature is not active yet.
|
||||||
// tenantId,
|
if (!isActive) return;
|
||||||
// inventoryTransactions,
|
|
||||||
// trx
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
|
|
||||||
// /**
|
await this.warehousesItemsQuantitySync.reverseWarehousesItemsQuantityFromTransactions(
|
||||||
// * Syncs warehouses items quantity once inventory transactions deleted.
|
oldInventoryTransactions,
|
||||||
// * @param {IInventoryTransactionsDeletedPayload}
|
trx,
|
||||||
// */
|
);
|
||||||
// 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
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,131 +1,128 @@
|
|||||||
// import { Knex } from 'knex';
|
import { InventoryTransaction } from '@/modules/InventoryCost/models/InventoryTransaction';
|
||||||
// import { Service, Inject } from 'typedi';
|
import { Injectable } from '@nestjs/common';
|
||||||
// import { omit } from 'lodash';
|
import { Knex } from 'knex';
|
||||||
// import {
|
import { omit } from 'lodash';
|
||||||
// IInventoryTransaction,
|
import { IItemWarehouseQuantityChange } from '../Warehouse.types';
|
||||||
// IItemWarehouseQuantityChange,
|
import { WarehousesItemsQuantity } from './WarehousesItemsQuantity';
|
||||||
// } from '@/interfaces';
|
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||||
// import { WarehousesItemsQuantity } from './WarehousesItemsQuantity';
|
import { ItemWarehouseQuantity } from '../models/ItemWarehouseQuantity';
|
||||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class WarehousesItemsQuantitySync {
|
export class WarehousesItemsQuantitySync {
|
||||||
// @Inject()
|
constructor(
|
||||||
// tenancy: HasTenancyService;
|
private readonly warehouseItemsQuantityModel: WarehousesItemsQuantity,
|
||||||
|
private readonly itemWarehouseQuantityModel: TenantModelProxy<
|
||||||
|
typeof ItemWarehouseQuantity
|
||||||
|
>,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Retrieves the reversed warehouses items quantity changes.
|
* Retrieves the reversed warehouses items quantity changes.
|
||||||
// * @param {IInventoryTransaction[]} inventoryTransactions
|
* @param {InventoryTransaction[]} inventoryTransactions
|
||||||
// * @returns {IItemWarehouseQuantityChange[]}
|
* @returns {IItemWarehouseQuantityChange[]}
|
||||||
// */
|
*/
|
||||||
// public getReverseWarehousesItemsQuantityChanges = (
|
public getReverseWarehousesItemsQuantityChanges = (
|
||||||
// inventoryTransactions: IInventoryTransaction[]
|
inventoryTransactions: InventoryTransaction[],
|
||||||
// ): IItemWarehouseQuantityChange[] => {
|
): IItemWarehouseQuantityChange[] => {
|
||||||
// const warehouseItemsQuantity =
|
const warehouseItemsQuantity =
|
||||||
// WarehousesItemsQuantity.fromInventoryTransaction(inventoryTransactions);
|
WarehousesItemsQuantity.fromInventoryTransaction(inventoryTransactions);
|
||||||
|
|
||||||
// return warehouseItemsQuantity.reverse().toArray();
|
return warehouseItemsQuantity.reverse().toArray();
|
||||||
// };
|
};
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Retrieves the warehouses items changes from the given inventory tranasctions.
|
* Retrieves the warehouses items changes from the given inventory tranasctions.
|
||||||
// * @param {IInventoryTransaction[]} inventoryTransactions
|
* @param {InventoryTransaction[]} inventoryTransactions
|
||||||
// * @returns {IItemWarehouseQuantityChange[]}
|
* @returns {IItemWarehouseQuantityChange[]}
|
||||||
// */
|
*/
|
||||||
// public getWarehousesItemsQuantityChange = (
|
public getWarehousesItemsQuantityChange = (
|
||||||
// inventoryTransactions: IInventoryTransaction[]
|
inventoryTransactions: InventoryTransaction[],
|
||||||
// ): IItemWarehouseQuantityChange[] => {
|
): IItemWarehouseQuantityChange[] => {
|
||||||
// const warehouseItemsQuantity =
|
const warehouseItemsQuantity =
|
||||||
// WarehousesItemsQuantity.fromInventoryTransaction(inventoryTransactions);
|
WarehousesItemsQuantity.fromInventoryTransaction(inventoryTransactions);
|
||||||
|
|
||||||
// return warehouseItemsQuantity.toArray();
|
return warehouseItemsQuantity.toArray();
|
||||||
// };
|
};
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Mutates warehouses items quantity on hand on the storage.
|
* Mutates warehouses items quantity on hand on the storage.
|
||||||
// * @param {number} tenantId
|
* @param {IItemWarehouseQuantityChange[]} warehousesItemsQuantity
|
||||||
// * @param {IItemWarehouseQuantityChange[]} warehousesItemsQuantity
|
* @param {Knex.Transaction} trx
|
||||||
// * @param {Knex.Transaction} trx
|
*/
|
||||||
// */
|
public mutateWarehousesItemsQuantity = async (
|
||||||
// public mutateWarehousesItemsQuantity = async (
|
warehousesItemsQuantity: IItemWarehouseQuantityChange[],
|
||||||
// tenantId: number,
|
trx?: Knex.Transaction,
|
||||||
// warehousesItemsQuantity: IItemWarehouseQuantityChange[],
|
): Promise<void> => {
|
||||||
// trx?: Knex.Transaction
|
const mutationsOpers = warehousesItemsQuantity.map(
|
||||||
// ): Promise<void> => {
|
(change: IItemWarehouseQuantityChange) =>
|
||||||
// const mutationsOpers = warehousesItemsQuantity.map(
|
this.mutateWarehouseItemQuantity(change, trx),
|
||||||
// (change: IItemWarehouseQuantityChange) =>
|
);
|
||||||
// this.mutateWarehouseItemQuantity(tenantId, change, trx)
|
await Promise.all(mutationsOpers);
|
||||||
// );
|
};
|
||||||
// await Promise.all(mutationsOpers);
|
|
||||||
// };
|
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Mutates the warehouse item quantity.
|
* Mutates the warehouse item quantity.
|
||||||
// * @param {number} tenantId
|
* @param {number} warehouseItemQuantity
|
||||||
// * @param {number} warehouseItemQuantity
|
* @param {Knex.Transaction} trx
|
||||||
// * @param {Knex.Transaction} trx
|
*/
|
||||||
// */
|
public mutateWarehouseItemQuantity = async (
|
||||||
// public mutateWarehouseItemQuantity = async (
|
warehouseItemQuantity: IItemWarehouseQuantityChange,
|
||||||
// tenantId: number,
|
trx: Knex.Transaction,
|
||||||
// warehouseItemQuantity: IItemWarehouseQuantityChange,
|
): Promise<void> => {
|
||||||
// trx: Knex.Transaction
|
const itemWarehouseQuantity = await this.itemWarehouseQuantityModel()
|
||||||
// ): Promise<void> => {
|
.query(trx)
|
||||||
// const { ItemWarehouseQuantity } = this.tenancy.models(tenantId);
|
.where('itemId', warehouseItemQuantity.itemId)
|
||||||
|
.where('warehouseId', warehouseItemQuantity.warehouseId)
|
||||||
|
.first();
|
||||||
|
|
||||||
// const itemWarehouseQuantity = await ItemWarehouseQuantity.query(trx)
|
if (itemWarehouseQuantity) {
|
||||||
// .where('itemId', warehouseItemQuantity.itemId)
|
// @ts-ignore
|
||||||
// .where('warehouseId', warehouseItemQuantity.warehouseId)
|
await ItemWarehouseQuantity.changeAmount(
|
||||||
// .first();
|
{
|
||||||
|
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(
|
* Mutates warehouses items quantity from inventory transactions.
|
||||||
// {
|
* @param {number} tenantId -
|
||||||
// itemId: warehouseItemQuantity.itemId,
|
* @param {IInventoryTransaction[]} inventoryTransactions -
|
||||||
// warehouseId: warehouseItemQuantity.warehouseId,
|
* @param {Knex.Transaction}
|
||||||
// },
|
*/
|
||||||
// 'quantityOnHand',
|
public mutateWarehousesItemsQuantityFromTransactions = async (
|
||||||
// warehouseItemQuantity.amount,
|
inventoryTransactions: InventoryTransaction[],
|
||||||
// trx
|
trx?: Knex.Transaction,
|
||||||
// );
|
) => {
|
||||||
// } else {
|
const changes = this.getWarehousesItemsQuantityChange(
|
||||||
// await ItemWarehouseQuantity.query(trx).insert({
|
inventoryTransactions,
|
||||||
// ...omit(warehouseItemQuantity, ['amount']),
|
);
|
||||||
// quantityOnHand: warehouseItemQuantity.amount,
|
await this.mutateWarehousesItemsQuantity(changes, trx);
|
||||||
// });
|
};
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Mutates warehouses items quantity from inventory transactions.
|
* Reverses warehouses items quantity from inventory transactions.
|
||||||
// * @param {number} tenantId -
|
* @param {number} tenantId
|
||||||
// * @param {IInventoryTransaction[]} inventoryTransactions -
|
* @param {IInventoryTransaction[]} inventoryTransactions
|
||||||
// * @param {Knex.Transaction}
|
* @param {Knex.Transaction} trx
|
||||||
// */
|
*/
|
||||||
// public mutateWarehousesItemsQuantityFromTransactions = async (
|
public reverseWarehousesItemsQuantityFromTransactions = async (
|
||||||
// tenantId: number,
|
inventoryTransactions: InventoryTransaction[],
|
||||||
// inventoryTransactions: IInventoryTransaction[],
|
trx?: Knex.Transaction,
|
||||||
// trx?: Knex.Transaction
|
) => {
|
||||||
// ) => {
|
const changes = this.getReverseWarehousesItemsQuantityChanges(
|
||||||
// const changes = this.getWarehousesItemsQuantityChange(
|
inventoryTransactions,
|
||||||
// inventoryTransactions
|
);
|
||||||
// );
|
await this.mutateWarehousesItemsQuantity(changes, trx);
|
||||||
// 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);
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,21 +1,23 @@
|
|||||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
// import { Service, Inject } from 'typedi';
|
import { TenantModelProxy } from '../System/models/TenantBaseModel';
|
||||||
|
import { InventoryTransaction } from '../InventoryCost/models/InventoryTransaction';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class UpdateInventoryTransactionsWithWarehouse {
|
export class UpdateInventoryTransactionsWithWarehouse {
|
||||||
// @Inject()
|
constructor(
|
||||||
// tenancy: HasTenancyService;
|
@Inject(InventoryTransaction.name)
|
||||||
|
private readonly inventoryTransactionModel: TenantModelProxy<
|
||||||
|
typeof InventoryTransaction
|
||||||
|
>,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Updates all inventory transactions with primary warehouse.
|
* Updates all inventory transactions with primary warehouse.
|
||||||
// * @param {number} tenantId -
|
* @param {number} warehouseId - Warehouse ID.
|
||||||
// * @param {number} warehouseId -
|
*/
|
||||||
// */
|
public run = async (primaryWarehouseId: number) => {
|
||||||
// public run = async (tenantId: number, primaryWarehouseId: number) => {
|
await this.inventoryTransactionModel().query().update({
|
||||||
// const { InventoryTransaction } = this.tenancy.models(tenantId);
|
warehouseId: primaryWarehouseId,
|
||||||
|
});
|
||||||
// await InventoryTransaction.query().update({
|
};
|
||||||
// warehouseId: primaryWarehouseId,
|
}
|
||||||
// });
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Knex } from 'knex';
|
import { Knex } from 'knex';
|
||||||
|
import { Warehouse } from './models/Warehouse.model';
|
||||||
|
|
||||||
export interface IWarehouse {
|
export interface IWarehouse {
|
||||||
id?: number;
|
id?: number;
|
||||||
@@ -168,18 +169,18 @@ export interface IWarehousesActivatePayload {
|
|||||||
}
|
}
|
||||||
export interface IWarehousesActivatedPayload {
|
export interface IWarehousesActivatedPayload {
|
||||||
// tenantId: number;
|
// tenantId: number;
|
||||||
primaryWarehouse: IWarehouse;
|
primaryWarehouse: Warehouse;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IWarehouseMarkAsPrimaryPayload {
|
export interface IWarehouseMarkAsPrimaryPayload {
|
||||||
// tenantId: number;
|
// tenantId: number;
|
||||||
oldWarehouse: IWarehouse;
|
oldWarehouse: Warehouse;
|
||||||
trx: Knex.Transaction;
|
trx: Knex.Transaction;
|
||||||
}
|
}
|
||||||
export interface IWarehouseMarkedAsPrimaryPayload {
|
export interface IWarehouseMarkedAsPrimaryPayload {
|
||||||
// tenantId: number;
|
// tenantId: number;
|
||||||
oldWarehouse: IWarehouse;
|
oldWarehouse: Warehouse;
|
||||||
markedWarehouse: IWarehouse;
|
markedWarehouse: Warehouse;
|
||||||
trx: Knex.Transaction;
|
trx: Knex.Transaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,20 @@ import { ActivateWarehousesService } from './commands/ActivateWarehouses.service
|
|||||||
import { CreateInitialWarehouse } from './commands/CreateInitialWarehouse.service';
|
import { CreateInitialWarehouse } from './commands/CreateInitialWarehouse.service';
|
||||||
import { WarehousesSettings } from './WarehousesSettings';
|
import { WarehousesSettings } from './WarehousesSettings';
|
||||||
import { WarehouseTransactionDTOTransform } from './Integrations/WarehouseTransactionDTOTransform';
|
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({
|
@Module({
|
||||||
imports: [TenancyDatabaseModule],
|
imports: [TenancyDatabaseModule],
|
||||||
@@ -38,6 +52,20 @@ import { WarehouseTransactionDTOTransform } from './Integrations/WarehouseTransa
|
|||||||
TenancyContext,
|
TenancyContext,
|
||||||
TransformerInjectable,
|
TransformerInjectable,
|
||||||
WarehouseTransactionDTOTransform,
|
WarehouseTransactionDTOTransform,
|
||||||
|
BillsActivateWarehousesSubscriber,
|
||||||
|
CreditsActivateWarehousesSubscriber,
|
||||||
|
InvoicesActivateWarehousesSubscriber,
|
||||||
|
ReceiptsActivateWarehousesSubscriber,
|
||||||
|
VendorCreditsActivateWarehousesSubscriber,
|
||||||
|
InventoryAdjustmentWarehouseValidatorSubscriber,
|
||||||
|
DeleteItemWarehousesQuantitySubscriber,
|
||||||
|
BillWarehousesValidateSubscriber,
|
||||||
|
CreditNoteWarehousesValidateSubscriber,
|
||||||
|
SaleReceiptWarehousesValidateSubscriber,
|
||||||
|
SaleEstimateWarehousesValidateSubscriber,
|
||||||
|
SaleInvoicesWarehousesValidateSubscriber,
|
||||||
|
VendorCreditWarehousesValidateSubscriber,
|
||||||
|
AccountsTransactionsWarehousesSubscribe,
|
||||||
],
|
],
|
||||||
exports: [WarehouseTransactionDTOTransform],
|
exports: [WarehouseTransactionDTOTransform],
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,36 +1,26 @@
|
|||||||
// import { Service, Inject } from 'typedi';
|
import { BillActivateWarehouses } from '../../Activate/BillWarehousesActivate';
|
||||||
// import { IWarehousesActivatedPayload } from '@/interfaces';
|
import { OnEvent } from '@nestjs/event-emitter';
|
||||||
// import events from '@/subscribers/events';
|
import { Injectable } from '@nestjs/common';
|
||||||
// import { BillActivateWarehouses } from '../../Activate/BillWarehousesActivate';
|
import { events } from '@/common/events/events';
|
||||||
|
import { IWarehousesActivatedPayload } from '../../Warehouse.types';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class BillsActivateWarehousesSubscriber {
|
export class BillsActivateWarehousesSubscriber {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private billsActivateWarehouses: BillActivateWarehouses;
|
private readonly billsActivateWarehouses: BillActivateWarehouses,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Attaches events with handlers.
|
* Updates all inventory transactions with the primary warehouse once
|
||||||
// */
|
* multi-warehouses feature is activated.
|
||||||
// public attach(bus) {
|
* @param {IWarehousesActivatedPayload}
|
||||||
// bus.subscribe(
|
*/
|
||||||
// events.warehouse.onActivated,
|
@OnEvent(events.warehouse.onActivated)
|
||||||
// this.updateBillsWithWarehouseOnActivated
|
async updateBillsWithWarehouseOnActivated ({
|
||||||
// );
|
primaryWarehouse,
|
||||||
// return bus;
|
}: IWarehousesActivatedPayload) {
|
||||||
// }
|
await this.billsActivateWarehouses.updateBillsWithWarehouse(
|
||||||
|
primaryWarehouse
|
||||||
// /**
|
);
|
||||||
// * 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
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,36 +1,26 @@
|
|||||||
// import { Service, Inject } from 'typedi';
|
import { Injectable } from '@nestjs/common';
|
||||||
// import { IWarehousesActivatedPayload } from '@/interfaces';
|
import { CreditNotesActivateWarehouses } from '../../Activate/CreditNoteWarehousesActivate';
|
||||||
// import events from '@/subscribers/events';
|
import { OnEvent } from '@nestjs/event-emitter';
|
||||||
// import { CreditNotesActivateWarehouses } from '../../Activate/CreditNoteWarehousesActivate';
|
import { IWarehousesActivatedPayload } from '../../Warehouse.types';
|
||||||
|
import { events } from '@/common/events/events';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class CreditsActivateWarehousesSubscriber {
|
export class CreditsActivateWarehousesSubscriber {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private creditsActivateWarehouses: CreditNotesActivateWarehouses;
|
private readonly creditsActivateWarehouses: CreditNotesActivateWarehouses,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Attaches events with handlers.
|
* Updates all inventory transactions with the primary warehouse once
|
||||||
// */
|
* multi-warehouses feature is activated.
|
||||||
// public attach(bus) {
|
* @param {IWarehousesActivatedPayload}
|
||||||
// bus.subscribe(
|
*/
|
||||||
// events.warehouse.onActivated,
|
@OnEvent(events.warehouse.onActivated)
|
||||||
// this.updateInvoicesWithWarehouseOnActivated
|
async updateInvoicesWithWarehouseOnActivated({
|
||||||
// );
|
primaryWarehouse,
|
||||||
// return bus;
|
}: IWarehousesActivatedPayload) {
|
||||||
// }
|
await this.creditsActivateWarehouses.updateCreditsWithWarehouse(
|
||||||
|
primaryWarehouse,
|
||||||
// /**
|
);
|
||||||
// * 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
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,36 +1,26 @@
|
|||||||
// import { Service, Inject } from 'typedi';
|
import { EstimatesActivateWarehouses } from '../../Activate/EstimateWarehousesActivate';
|
||||||
// import { IWarehousesActivatedPayload } from '@/interfaces';
|
import { OnEvent } from '@nestjs/event-emitter';
|
||||||
// import events from '@/subscribers/events';
|
import { events } from '@/common/events/events';
|
||||||
// import { EstimatesActivateWarehouses } from '../../Activate/EstimateWarehousesActivate';
|
import { IWarehousesActivatedPayload } from '../../Warehouse.types';
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class EstimatesActivateWarehousesSubscriber {
|
export class EstimatesActivateWarehousesSubscriber {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private estimatesActivateWarehouses: EstimatesActivateWarehouses;
|
private readonly estimatesActivateWarehouses: EstimatesActivateWarehouses,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Attaches events with handlers.
|
* Updates all inventory transactions with the primary warehouse once
|
||||||
// */
|
* multi-warehouses feature is activated.
|
||||||
// public attach(bus) {
|
* @param {IWarehousesActivatedPayload}
|
||||||
// bus.subscribe(
|
*/
|
||||||
// events.warehouse.onActivated,
|
@OnEvent(events.warehouse.onActivated)
|
||||||
// this.updateEstimatessWithWarehouseOnActivated
|
async updateEstimatessWithWarehouseOnActivated({
|
||||||
// );
|
primaryWarehouse,
|
||||||
// return bus;
|
}: IWarehousesActivatedPayload) {
|
||||||
// }
|
await this.estimatesActivateWarehouses.updateEstimatesWithWarehouse(
|
||||||
|
primaryWarehouse,
|
||||||
// /**
|
);
|
||||||
// * 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
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,36 +1,26 @@
|
|||||||
// import { Service, Inject } from 'typedi';
|
import { InventoryActivateWarehouses } from '../../Activate/InventoryTransactionsWarehousesActivate';
|
||||||
// import { IWarehousesActivatedPayload } from '@/interfaces';
|
import { OnEvent } from '@nestjs/event-emitter';
|
||||||
// import events from '@/subscribers/events';
|
import { Injectable } from '@nestjs/common';
|
||||||
// import { InventoryActivateWarehouses } from '../../Activate/InventoryTransactionsWarehousesActivate';
|
import { events } from '@/common/events/events';
|
||||||
|
import { IWarehousesActivatedPayload } from '../../Warehouse.types';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class InventoryActivateWarehousesSubscriber {
|
export class InventoryActivateWarehousesSubscriber {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private inventoryActivateWarehouses: InventoryActivateWarehouses;
|
private readonly inventoryActivateWarehouses: InventoryActivateWarehouses,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Attaches events with handlers.
|
* Updates all inventory transactions with the primary warehouse once
|
||||||
// */
|
* multi-warehouses feature is activated.
|
||||||
// public attach(bus) {
|
* @param {IWarehousesActivatedPayload}
|
||||||
// bus.subscribe(
|
*/
|
||||||
// events.warehouse.onActivated,
|
@OnEvent(events.warehouse.onActivated)
|
||||||
// this.updateInventoryTransactionsWithWarehouseOnActivated
|
async updateInventoryTransactionsWithWarehouseOnActivated({
|
||||||
// );
|
primaryWarehouse,
|
||||||
// return bus;
|
}: IWarehousesActivatedPayload) {
|
||||||
// }
|
await this.inventoryActivateWarehouses.updateInventoryTransactionsWithWarehouse(
|
||||||
|
primaryWarehouse,
|
||||||
// /**
|
);
|
||||||
// * 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
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,36 +1,26 @@
|
|||||||
// import { Service, Inject } from 'typedi';
|
import { Injectable } from '@nestjs/common';
|
||||||
// import { IWarehousesActivatedPayload } from '@/interfaces';
|
import { InvoicesActivateWarehouses } from '../../Activate/InvoiceWarehousesActivate';
|
||||||
// import events from '@/subscribers/events';
|
import { OnEvent } from '@nestjs/event-emitter';
|
||||||
// import { InvoicesActivateWarehouses } from '../../Activate/InvoiceWarehousesActivate';
|
import { IWarehousesActivatedPayload } from '../../Warehouse.types';
|
||||||
|
import { events } from '@/common/events/events';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class InvoicesActivateWarehousesSubscriber {
|
export class InvoicesActivateWarehousesSubscriber {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private invoicesActivateWarehouses: InvoicesActivateWarehouses;
|
private readonly invoicesActivateWarehouses: InvoicesActivateWarehouses,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Attaches events with handlers.
|
* Updates all inventory transactions with the primary warehouse once
|
||||||
// */
|
* multi-warehouses feature is activated.
|
||||||
// public attach(bus) {
|
* @param {IWarehousesActivatedPayload}
|
||||||
// bus.subscribe(
|
*/
|
||||||
// events.warehouse.onActivated,
|
@OnEvent(events.warehouse.onActivated)
|
||||||
// this.updateInvoicesWithWarehouseOnActivated
|
async updateInvoicesWithWarehouseOnActivated({
|
||||||
// );
|
primaryWarehouse,
|
||||||
// return bus;
|
}: IWarehousesActivatedPayload) {
|
||||||
// }
|
await this.invoicesActivateWarehouses.updateInvoicesWithWarehouse(
|
||||||
|
primaryWarehouse,
|
||||||
// /**
|
);
|
||||||
// * 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
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,36 +1,27 @@
|
|||||||
// import { Service, Inject } from 'typedi';
|
import { OnEvent } from '@nestjs/event-emitter';
|
||||||
// import { IWarehousesActivatedPayload } from '@/interfaces';
|
import { Injectable } from '@nestjs/common';
|
||||||
// import events from '@/subscribers/events';
|
import { ReceiptActivateWarehouses } from '../../Activate/ReceiptWarehousesActivate';
|
||||||
// import { ReceiptActivateWarehouses } from '../../Activate/ReceiptWarehousesActivate';
|
import { events } from '@/common/events/events';
|
||||||
|
import { IWarehousesActivatedPayload } from '../../Warehouse.types';
|
||||||
|
|
||||||
// @Service()
|
|
||||||
// export class ReceiptsActivateWarehousesSubscriber {
|
|
||||||
// @Inject()
|
|
||||||
// private receiptsActivateWarehouses: ReceiptActivateWarehouses;
|
|
||||||
|
|
||||||
// /**
|
@Injectable()
|
||||||
// * Attaches events with handlers.
|
export class ReceiptsActivateWarehousesSubscriber {
|
||||||
// */
|
constructor(
|
||||||
// public attach(bus) {
|
private readonly receiptsActivateWarehouses: ReceiptActivateWarehouses,
|
||||||
// bus.subscribe(
|
) {}
|
||||||
// events.warehouse.onActivated,
|
|
||||||
// this.updateInventoryTransactionsWithWarehouseOnActivated
|
|
||||||
// );
|
|
||||||
// return bus;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Updates all receipts transactions with the primary warehouse once
|
* Updates all receipts transactions with the primary warehouse once
|
||||||
// * multi-warehouses feature is activated.
|
* multi-warehouses feature is activated.
|
||||||
// * @param {IWarehousesActivatedPayload}
|
* @param {IWarehousesActivatedPayload}
|
||||||
// */
|
*/
|
||||||
// private updateInventoryTransactionsWithWarehouseOnActivated = async ({
|
@OnEvent(events.warehouse.onActivated)
|
||||||
// tenantId,
|
async updateInventoryTransactionsWithWarehouseOnActivated({
|
||||||
// primaryWarehouse,
|
primaryWarehouse,
|
||||||
// }: IWarehousesActivatedPayload) => {
|
}: IWarehousesActivatedPayload) {
|
||||||
// await this.receiptsActivateWarehouses.updateReceiptsWithWarehouse(
|
await this.receiptsActivateWarehouses.updateReceiptsWithWarehouse(
|
||||||
// tenantId,
|
primaryWarehouse
|
||||||
// primaryWarehouse
|
);
|
||||||
// );
|
};
|
||||||
// };
|
}
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,36 +1,26 @@
|
|||||||
// import { Service, Inject } from 'typedi';
|
import { VendorCreditActivateWarehouses } from '../../Activate/VendorCreditWarehousesActivate';
|
||||||
// import { IWarehousesActivatedPayload } from '@/interfaces';
|
import { OnEvent } from '@nestjs/event-emitter';
|
||||||
// import events from '@/subscribers/events';
|
import { Injectable } from '@nestjs/common';
|
||||||
// import { VendorCreditActivateWarehouses } from '../../Activate/VendorCreditWarehousesActivate';
|
import { IWarehousesActivatedPayload } from '../../Warehouse.types';
|
||||||
|
import { events } from '@/common/events/events';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class VendorCreditsActivateWarehousesSubscriber {
|
export class VendorCreditsActivateWarehousesSubscriber {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private creditsActivateWarehouses: VendorCreditActivateWarehouses;
|
private readonly creditsActivateWarehouses: VendorCreditActivateWarehouses,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Attaches events with handlers.
|
* Updates all inventory transactions with the primary warehouse once
|
||||||
// */
|
* multi-warehouses feature is activated.
|
||||||
// public attach(bus) {
|
* @param {IWarehousesActivatedPayload}
|
||||||
// bus.subscribe(
|
*/
|
||||||
// events.warehouse.onActivated,
|
@OnEvent(events.warehouse.onActivated)
|
||||||
// this.updateCreditsWithWarehouseOnActivated
|
async updateCreditsWithWarehouseOnActivated({
|
||||||
// );
|
primaryWarehouse,
|
||||||
// return bus;
|
}: IWarehousesActivatedPayload) {
|
||||||
// }
|
await this.creditsActivateWarehouses.updateCreditsWithWarehouse(
|
||||||
|
primaryWarehouse,
|
||||||
// /**
|
);
|
||||||
// * 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
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -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 { Injectable } from '@nestjs/common';
|
||||||
// import events from '@/subscribers/events';
|
import { DeleteItemWarehousesQuantity } from '../commands/DeleteItemWarehousesQuantity';
|
||||||
// import { DeleteItemWarehousesQuantity } from '../commands/DeleteItemWarehousesQuantity';
|
import { OnEvent } from '@nestjs/event-emitter';
|
||||||
// import { IItemEventDeletingPayload } from '@/interfaces';
|
import { events } from '@/common/events/events';
|
||||||
|
import { IItemEventDeletingPayload } from '@/interfaces/Item';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class DeleteItemWarehousesQuantitySubscriber {
|
export class DeleteItemWarehousesQuantitySubscriber {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private deleteItemWarehousesQuantity: DeleteItemWarehousesQuantity;
|
private readonly deleteItemWarehousesQuantity: DeleteItemWarehousesQuantity,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Attaches events.
|
* Deletes the given item warehouses quantities once the item deleting.
|
||||||
// */
|
* @param {IItemEventDeletingPayload} payload -
|
||||||
// public attach(bus) {
|
*/
|
||||||
// bus.subscribe(
|
@OnEvent(events.item.onDeleting)
|
||||||
// events.item.onDeleting,
|
async deleteItemWarehouseQuantitiesOnItemDelete({
|
||||||
// this.deleteItemWarehouseQuantitiesOnItemDelete
|
oldItem,
|
||||||
// );
|
trx,
|
||||||
// }
|
}: IItemEventDeletingPayload) {
|
||||||
|
await this.deleteItemWarehousesQuantity.deleteItemWarehousesQuantity(
|
||||||
// /**
|
oldItem.id,
|
||||||
// * Deletes the given item warehouses quantities once the item deleting.
|
trx,
|
||||||
// * @param {IItemEventDeletingPayload} payload -
|
);
|
||||||
// */
|
}
|
||||||
// private deleteItemWarehouseQuantitiesOnItemDelete = async ({
|
}
|
||||||
// tenantId,
|
|
||||||
// oldItem,
|
|
||||||
// trx,
|
|
||||||
// }: IItemEventDeletingPayload) => {
|
|
||||||
// await this.deleteItemWarehousesQuantity.deleteItemWarehousesQuantity(
|
|
||||||
// tenantId,
|
|
||||||
// oldItem.id,
|
|
||||||
// trx
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,35 +1,25 @@
|
|||||||
// import { Inject, Service } from 'typedi';
|
import { WarehousesDTOValidators } from '../../../Integrations/WarehousesDTOValidators';
|
||||||
// import { IInventoryAdjustmentCreatingPayload } from '@/interfaces';
|
import { OnEvent } from '@nestjs/event-emitter';
|
||||||
// import events from '@/subscribers/events';
|
import { Injectable } from '@nestjs/common';
|
||||||
// import { WarehousesDTOValidators } from '../../../Integrations/WarehousesDTOValidators';
|
import { IInventoryAdjustmentCreatingPayload } from '@/modules/InventoryAdjutments/types/InventoryAdjustments.types';
|
||||||
|
import { events } from '@/common/events/events';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class InventoryAdjustmentWarehouseValidatorSubscriber {
|
export class InventoryAdjustmentWarehouseValidatorSubscriber {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private warehouseDTOValidator: WarehousesDTOValidators;
|
private readonly warehouseDTOValidator: WarehousesDTOValidators,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Attaches events with handlers.
|
* Validate warehouse existance of sale invoice once creating.
|
||||||
// */
|
* @param {IBillCreatingPayload}
|
||||||
// public attach(bus) {
|
*/
|
||||||
// bus.subscribe(
|
@OnEvent(events.inventoryAdjustment.onQuickCreating)
|
||||||
// events.inventoryAdjustment.onQuickCreating,
|
async validateAdjustmentWarehouseExistanceOnCreating({
|
||||||
// this.validateAdjustmentWarehouseExistanceOnCreating
|
quickAdjustmentDTO,
|
||||||
// );
|
}: IInventoryAdjustmentCreatingPayload) {
|
||||||
// return bus;
|
await this.warehouseDTOValidator.validateDTOWarehouseWhenActive(
|
||||||
// }
|
quickAdjustmentDTO,
|
||||||
|
);
|
||||||
// /**
|
}
|
||||||
// * Validate warehouse existance of sale invoice once creating.
|
}
|
||||||
// * @param {IBillCreatingPayload}
|
|
||||||
// */
|
|
||||||
// private validateAdjustmentWarehouseExistanceOnCreating = async ({
|
|
||||||
// quickAdjustmentDTO,
|
|
||||||
// tenantId,
|
|
||||||
// }: IInventoryAdjustmentCreatingPayload) => {
|
|
||||||
// await this.warehouseDTOValidator.validateDTOWarehouseWhenActive(
|
|
||||||
// tenantId,
|
|
||||||
// quickAdjustmentDTO
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,53 +1,36 @@
|
|||||||
// import { Inject, Service } from 'typedi';
|
import { OnEvent } from '@nestjs/event-emitter';
|
||||||
// import { IBillCreatingPayload, IBillEditingPayload } from '@/interfaces';
|
import { events } from '@/common/events/events';
|
||||||
// import events from '@/subscribers/events';
|
import { WarehousesDTOValidators } from '../../../Integrations/WarehousesDTOValidators';
|
||||||
// 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()
|
@Injectable()
|
||||||
// export class BillWarehousesValidateSubscriber {
|
export class BillWarehousesValidateSubscriber {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private warehouseDTOValidator: WarehousesDTOValidators;
|
private readonly warehouseDTOValidator: WarehousesDTOValidators,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Attaches events with handlers.
|
* Validate warehouse existance of sale invoice once creating.
|
||||||
// */
|
* @param {IBillCreatingPayload}
|
||||||
// public attach(bus) {
|
*/
|
||||||
// bus.subscribe(
|
@OnEvent(events.bill.onCreating)
|
||||||
// events.bill.onCreating,
|
async validateBillWarehouseExistanceOnCreating({
|
||||||
// this.validateBillWarehouseExistanceOnCreating
|
billDTO,
|
||||||
// );
|
}: IBillCreatingPayload) {
|
||||||
// bus.subscribe(
|
await this.warehouseDTOValidator.validateDTOWarehouseWhenActive(billDTO);
|
||||||
// events.bill.onEditing,
|
}
|
||||||
// this.validateSaleEstimateWarehouseExistanceOnEditing
|
|
||||||
// );
|
|
||||||
// return bus;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Validate warehouse existance of sale invoice once creating.
|
* Validate warehouse existance of sale invoice once editing.
|
||||||
// * @param {IBillCreatingPayload}
|
* @param {IBillEditingPayload}
|
||||||
// */
|
*/
|
||||||
// private validateBillWarehouseExistanceOnCreating = async ({
|
|
||||||
// billDTO,
|
|
||||||
// tenantId,
|
|
||||||
// }: IBillCreatingPayload) => {
|
|
||||||
// await this.warehouseDTOValidator.validateDTOWarehouseWhenActive(
|
|
||||||
// tenantId,
|
|
||||||
// billDTO
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
|
|
||||||
// /**
|
@OnEvent(events.bill.onEditing)
|
||||||
// * Validate warehouse existance of sale invoice once editing.
|
async validateSaleEstimateWarehouseExistanceOnEditing({
|
||||||
// * @param {IBillEditingPayload}
|
billDTO,
|
||||||
// */
|
}: IBillEditingPayload) {
|
||||||
// private validateSaleEstimateWarehouseExistanceOnEditing = async ({
|
await this.warehouseDTOValidator.validateDTOWarehouseWhenActive(billDTO);
|
||||||
// tenantId,
|
}
|
||||||
// billDTO,
|
}
|
||||||
// }: IBillEditingPayload) => {
|
|
||||||
// await this.warehouseDTOValidator.validateDTOWarehouseWhenActive(
|
|
||||||
// tenantId,
|
|
||||||
// billDTO
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,56 +1,39 @@
|
|||||||
// import { Inject, Service } from 'typedi';
|
import { WarehousesDTOValidators } from '../../../Integrations/WarehousesDTOValidators';
|
||||||
// import {
|
import { OnEvent } from '@nestjs/event-emitter';
|
||||||
// IVendorCreditCreatingPayload,
|
import { Injectable } from '@nestjs/common';
|
||||||
// IVendorCreditEditingPayload,
|
import { IVendorCreditEditingPayload } from '@/modules/VendorCredit/types/VendorCredit.types';
|
||||||
// } from '@/interfaces';
|
import { events } from '@/common/events/events';
|
||||||
// import events from '@/subscribers/events';
|
import { IVendorCreditCreatingPayload } from '@/modules/VendorCredit/types/VendorCredit.types';
|
||||||
// import { WarehousesDTOValidators } from '../../../Integrations/WarehousesDTOValidators';
|
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class VendorCreditWarehousesValidateSubscriber {
|
export class VendorCreditWarehousesValidateSubscriber {
|
||||||
// @Inject()
|
constructor(
|
||||||
// warehouseDTOValidator: WarehousesDTOValidators;
|
private readonly warehouseDTOValidator: WarehousesDTOValidators,
|
||||||
|
) {}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Attaches events with handlers.
|
* Validate warehouse existance of sale invoice once creating.
|
||||||
// */
|
* @param {IVendorCreditCreatingPayload}
|
||||||
// public attach(bus) {
|
*/
|
||||||
// bus.subscribe(
|
@OnEvent(events.vendorCredit.onCreating)
|
||||||
// events.vendorCredit.onCreating,
|
async validateVendorCreditWarehouseExistanceOnCreating({
|
||||||
// this.validateVendorCreditWarehouseExistanceOnCreating
|
vendorCreditCreateDTO,
|
||||||
// );
|
}: IVendorCreditCreatingPayload) {
|
||||||
// bus.subscribe(
|
await this.warehouseDTOValidator.validateDTOWarehouseWhenActive(
|
||||||
// events.vendorCredit.onEditing,
|
vendorCreditCreateDTO,
|
||||||
// this.validateSaleEstimateWarehouseExistanceOnEditing
|
);
|
||||||
// );
|
}
|
||||||
// return bus;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Validate warehouse existance of sale invoice once creating.
|
* Validate warehouse existance of sale invoice once editing.
|
||||||
// * @param {IVendorCreditCreatingPayload}
|
* @param {IVendorCreditEditingPayload}
|
||||||
// */
|
*/
|
||||||
// private validateVendorCreditWarehouseExistanceOnCreating = async ({
|
@OnEvent(events.vendorCredit.onEditing)
|
||||||
// vendorCreditCreateDTO,
|
async validateSaleEstimateWarehouseExistanceOnEditing({
|
||||||
// tenantId,
|
vendorCreditDTO,
|
||||||
// }: IVendorCreditCreatingPayload) => {
|
}: IVendorCreditEditingPayload) {
|
||||||
// await this.warehouseDTOValidator.validateDTOWarehouseWhenActive(
|
await this.warehouseDTOValidator.validateDTOWarehouseWhenActive(
|
||||||
// tenantId,
|
vendorCreditDTO,
|
||||||
// vendorCreditCreateDTO
|
);
|
||||||
// );
|
}
|
||||||
// };
|
}
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Validate warehouse existance of sale invoice once editing.
|
|
||||||
// * @param {IVendorCreditEditingPayload}
|
|
||||||
// */
|
|
||||||
// private validateSaleEstimateWarehouseExistanceOnEditing = async ({
|
|
||||||
// tenantId,
|
|
||||||
// vendorCreditDTO,
|
|
||||||
// }: IVendorCreditEditingPayload) => {
|
|
||||||
// await this.warehouseDTOValidator.validateDTOWarehouseWhenActive(
|
|
||||||
// tenantId,
|
|
||||||
// vendorCreditDTO
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user