refactor: branches and warehouses to nestjs

This commit is contained in:
Ahmed Bouhuolia
2024-12-21 00:10:09 +02:00
parent dc52f784b6
commit cb8fd68d46
126 changed files with 5419 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
// import { Request, Response, NextFunction } from 'express';
// import { ServiceError } from '@/exceptions';
// /**
// * Handles branches integration service errors.
// * @param {Error} error
// * @param {Request} req
// * @param {Response} res
// * @param {NextFunction} next
// */
// export function BranchIntegrationErrorsMiddleware(
// error: Error,
// req: Request,
// res: Response,
// next: NextFunction
// ) {
// if (error instanceof ServiceError) {
// if (error.errorType === 'WAREHOUSE_ID_NOT_FOUND') {
// return res.boom.badRequest(null, {
// errors: [{ type: 'WAREHOUSE_ID_NOT_FOUND', code: 5000 }],
// });
// }
// if (error.errorType === 'BRANCH_ID_REQUIRED') {
// return res.boom.badRequest(null, {
// errors: [{ type: 'BRANCH_ID_REQUIRED', code: 5100 }],
// });
// }
// if (error.errorType === 'BRANCH_ID_NOT_FOUND') {
// return res.boom.badRequest(null, {
// errors: [{ type: 'BRANCH_ID_NOT_FOUND', code: 5300 }],
// });
// }
// }
// next(error);
// }

View File

@@ -0,0 +1,51 @@
import {
Controller,
Get,
Post,
Put,
Delete,
Body,
Param,
} from '@nestjs/common';
import { BranchesApplication } from './BranchesApplication.service';
import { ICreateBranchDTO, IEditBranchDTO } from './Branches.types';
@Controller('branches')
export class BranchesController {
constructor(private readonly branchesApplication: BranchesApplication) {}
@Get()
getBranches() {
// return this.branchesApplication.getBranches();
}
@Get(':id')
getBranch(@Param('id') id: string) {
return this.branchesApplication.getBranch(Number(id));
}
@Post()
createBranch(@Body() createBranchDTO: ICreateBranchDTO) {
return this.branchesApplication.createBranch(createBranchDTO);
}
@Put(':id')
editBranch(@Param('id') id: string, @Body() editBranchDTO: IEditBranchDTO) {
return this.branchesApplication.editBranch(Number(id), editBranchDTO);
}
@Delete(':id')
deleteBranch(@Param('id') id: string) {
return this.branchesApplication.deleteBranch(Number(id));
}
@Post('activate')
activateBranches() {
return this.branchesApplication.activateBranches();
}
@Put(':id/mark-as-primary')
markBranchAsPrimary(@Param('id') id: string) {
return this.branchesApplication.markBranchAsPrimary(Number(id));
}
}

View File

@@ -0,0 +1,31 @@
import { Module } from '@nestjs/common';
import { TenancyContext } from '../Tenancy/TenancyContext.service';
import { TenancyDatabaseModule } from '../Tenancy/TenancyDB/TenancyDB.module';
import { TransformerInjectable } from '../Transformer/TransformerInjectable.service';
import { BranchesController } from './Branches.controller';
import { CreateBranchService } from './commands/CreateBranch.service';
import { DeleteBranchService } from './commands/DeleteBranch.service';
import { EditBranchService } from './commands/EditBranch.service';
import { MarkBranchAsPrimaryService } from './commands/MarkBranchAsPrimary.service';
import { GetBranchService } from './queries/GetBranch.service';
import { GetBranchesService } from './queries/GetBranches.service';
import { ActivateBranches } from './commands/ActivateBranchesFeature.service';
import { BranchesApplication } from './BranchesApplication.service';
@Module({
imports: [TenancyDatabaseModule],
controllers: [BranchesController],
providers: [
CreateBranchService,
EditBranchService,
DeleteBranchService,
GetBranchService,
GetBranchesService,
MarkBranchAsPrimaryService,
ActivateBranches,
BranchesApplication,
TenancyContext,
TransformerInjectable,
],
})
export class BranchesModule {}

View File

@@ -0,0 +1,50 @@
import { Knex } from 'knex';
export interface IBranch {
id?: number;
}
export interface ICreateBranchDTO {
name: string;
code: string;
primary?: boolean;
}
export interface IEditBranchDTO {
code: string;
}
export interface IBranchCreatePayload {
tenantId: number;
createBranchDTO: ICreateBranchDTO;
trx: Knex.Transaction;
}
export interface IBranchCreatedPayload {}
export interface IBranchEditPayload {}
export interface IBranchEditedPayload {}
export interface IBranchDeletePayload {}
export interface IBranchDeletedPayload {}
export interface IBranchesActivatePayload {
// tenantId: number;
trx: Knex.Transaction;
}
export interface IBranchesActivatedPayload {
// tenantId: number;
primaryBranch: IBranch;
trx: Knex.Transaction;
}
export interface IBranchMarkAsPrimaryPayload {
// tenantId: number;
oldBranch: IBranch;
trx: Knex.Transaction;
}
export interface IBranchMarkedAsPrimaryPayload {
// tenantId: number;
oldBranch: IBranch;
markedBranch: IBranch;
trx: Knex.Transaction;
}

View File

@@ -0,0 +1,99 @@
import { IBranch, ICreateBranchDTO, IEditBranchDTO } from './Branches.types';
import { ActivateBranches } from './commands/ActivateBranchesFeature.service';
import {
CreateBranchService,
} from './commands/CreateBranch.service';
import {
DeleteBranchService,
} from './commands/DeleteBranch.service';
import { EditBranchService } from './commands/EditBranch.service';
import { GetBranchService } from './queries/GetBranch.service';
import { GetBranchesService } from './queries/GetBranches.service';
import { MarkBranchAsPrimaryService } from './commands/MarkBranchAsPrimary.service';
import { Branch } from './models/Branch.model';
import { Injectable } from '@nestjs/common';
@Injectable()
export class BranchesApplication {
constructor(
private readonly createBranchService: CreateBranchService,
private readonly editBranchService: EditBranchService,
private readonly deleteBranchService: DeleteBranchService,
private readonly getBranchService: GetBranchService,
private readonly getBranchesService: GetBranchesService,
private readonly activateBranchesService: ActivateBranches,
private readonly markBranchAsPrimaryService: MarkBranchAsPrimaryService,
) {}
/**
* Retrieves branches list.
* @param {number} tenantId
* @returns {IBranch}
*/
// public getBranches = (): Promise<Branch[]> => {
// // return this.getBranchesService.getBranches(tenantId);
// };
/**
* Retrieves the given branch details.
* @param {number} branchId - Branch id.
* @returns {Promise<IBranch>}
*/
public getBranch = (branchId: number): Promise<IBranch> => {
return this.getBranchService.getBranch(branchId);
};
/**
* Creates a new branch.
* @param {number} tenantId -
* @param {ICreateBranchDTO} createBranchDTO
* @returns {Promise<IBranch>}
*/
public createBranch = (
createBranchDTO: ICreateBranchDTO,
): Promise<Branch> => {
return this.createBranchService.createBranch(createBranchDTO);
};
/**
* Edits the given branch.
* @param {number} branchId - Branch id.
* @param {IEditBranchDTO} editBranchDTO - Edit branch DTO.
* @returns {Promise<Branch>}
*/
public editBranch = (
branchId: number,
editBranchDTO: IEditBranchDTO,
): Promise<Branch> => {
return this.editBranchService.editBranch(branchId, editBranchDTO);
};
/**
* Deletes the given branch.
* @param {number} branchId - Branch id.
* @returns {Promise<void>}
*/
public deleteBranch = (branchId: number): Promise<void> => {
return this.deleteBranchService.deleteBranch(branchId);
};
/**
* Activates the given branches.
* @returns {Promise<void>}
*/
public activateBranches = (): Promise<void> => {
return this.activateBranchesService.activateBranches();
};
/**
* Marks the given branch as primary.
* @param {number} tenantId
* @param {number} branchId
* @returns {Promise<IBranch>}
*/
public markBranchAsPrimary = async (
branchId: number,
): Promise<Branch> => {
return this.markBranchAsPrimaryService.markAsPrimary(branchId);
};
}

View File

@@ -0,0 +1,29 @@
import { Service, Inject } from 'typedi';
import { Features } from '@/interfaces';
import HasTenancyService from '@/services/Tenancy/TenancyService';
@Service()
export class BranchesSettings {
@Inject()
private tenancy: HasTenancyService;
/**
* Marks multi-branches as activated.
* @param {number} tenantId -
*/
public markMultiBranchesAsActivated = (tenantId: number) => {
const settings = this.tenancy.settings(tenantId);
settings.set({ group: 'features', key: Features.BRANCHES, value: 1 });
};
/**
* Retrieves whether multi-branches is active.
* @param {number} tenantId
*/
public isMultiBranchesActive = (tenantId: number) => {
const settings = this.tenancy.settings(tenantId);
return settings.get({ group: 'features', key: Features.BRANCHES });
};
}

View File

@@ -0,0 +1,30 @@
// import { Inject } from "typedi";
// import { ServiceError } from "exceptions";
// import HasTenancyService from "services/Tenancy/TenancyService";
// import { ERRORS } from "./constants";
// export class CURDBranch {
// @Inject()
// tenancy: HasTenancyService;
// /**
// *
// * @param branch
// */
// throwIfBranchNotFound = (branch) => {
// if (!branch) {
// throw new ServiceError(ERRORS.BRANCH_NOT_FOUND);
// }
// }
// getBranchOrThrowNotFound = async (tenantId: number, branchId: number) => {
// const { Branch } = this.tenancy.models(tenantId);
// const foundBranch = await Branch.query().findById(branchId);
// if (!foundBranch) {
// throw new ServiceError(ERRORS.BRANCH_NOT_FOUND);
// }
// return foundBranch;
// }
// }

View File

@@ -0,0 +1,50 @@
// import {
// CreditNoteActivateBranchesSubscriber,
// PaymentReceiveActivateBranchesSubscriber,
// SaleEstimatesActivateBranchesSubscriber,
// SaleInvoicesActivateBranchesSubscriber,
// PaymentMadeActivateBranchesSubscriber,
// SaleReceiptsActivateBranchesSubscriber,
// } from './Subscribers/Activate';
// import {
// BillBranchValidateSubscriber,
// VendorCreditBranchValidateSubscriber,
// PaymentMadeBranchValidateSubscriber,
// SaleEstimateBranchValidateSubscriber,
// CreditNoteBranchValidateSubscriber,
// ExpenseBranchValidateSubscriber,
// SaleReceiptBranchValidateSubscriber,
// ManualJournalBranchValidateSubscriber,
// PaymentReceiveBranchValidateSubscriber,
// CreditNoteRefundBranchValidateSubscriber,
// CashflowBranchDTOValidatorSubscriber,
// VendorCreditRefundBranchValidateSubscriber,
// InvoiceBranchValidateSubscriber,
// ContactBranchValidateSubscriber,
// InventoryAdjustmentBranchValidateSubscriber
// } from './Subscribers/Validators';
// export default () => [
// BillBranchValidateSubscriber,
// CreditNoteBranchValidateSubscriber,
// ExpenseBranchValidateSubscriber,
// PaymentMadeBranchValidateSubscriber,
// SaleReceiptBranchValidateSubscriber,
// VendorCreditBranchValidateSubscriber,
// SaleEstimateBranchValidateSubscriber,
// ManualJournalBranchValidateSubscriber,
// PaymentReceiveBranchValidateSubscriber,
// CreditNoteRefundBranchValidateSubscriber,
// VendorCreditRefundBranchValidateSubscriber,
// CreditNoteActivateBranchesSubscriber,
// PaymentReceiveActivateBranchesSubscriber,
// SaleEstimatesActivateBranchesSubscriber,
// SaleInvoicesActivateBranchesSubscriber,
// PaymentMadeActivateBranchesSubscriber,
// SaleReceiptsActivateBranchesSubscriber,
// CashflowBranchDTOValidatorSubscriber,
// InvoiceBranchValidateSubscriber,
// ContactBranchValidateSubscriber,
// InventoryAdjustmentBranchValidateSubscriber
// ];

View File

@@ -0,0 +1,80 @@
import { Knex } from 'knex';
import { Inject, Injectable } from '@nestjs/common';
import { I18nService } from 'nestjs-i18n';
import { EventEmitter2 } from '@nestjs/event-emitter';
import { ERRORS } from '../constants';
import {
IBranchesActivatedPayload,
IBranchesActivatePayload,
} from '../Branches.types';
import { CreateBranchService } from './CreateBranch.service';
import { BranchesSettings } from '../BranchesSettings';
import { ServiceError } from '@/modules/Items/ServiceError';
import { UnitOfWork } from '@/modules/Tenancy/TenancyDB/UnitOfWork.service';
import { Branch } from '../models/Branch.model';
import { events } from '@/common/events/events';
@Injectable()
export class ActivateBranches {
constructor(
private readonly uow: UnitOfWork,
private readonly eventPublisher: EventEmitter2,
private readonly createBranch: CreateBranchService,
private readonly branchesSettings: BranchesSettings,
private readonly i18n: I18nService,
@Inject(Branch.name)
private readonly branchModel: typeof Branch,
) {}
/**
* Throws service error if multi-branches feature is already activated.
*/
private throwIfMultiBranchesActivated = (isActivated: boolean) => {
if (isActivated) {
throw new ServiceError(ERRORS.MUTLI_BRANCHES_ALREADY_ACTIVATED);
}
};
/**
* Creates a new initial branch.
*/
private createInitialBranch = () => {
return this.createBranch.createBranch({
name: this.i18n.t('branches.head_branch'),
code: '10001',
primary: true,
});
};
/**
* Activate multi-branches feature.
* @returns {Promise<void>}
*/
public activateBranches = (): Promise<void> => {
const isActivated = this.branchesSettings.isMultiBranchesActive();
// Throw error if mutli-branches is already activated.
this.throwIfMultiBranchesActivated(isActivated);
// Activate multi-branches under unit-of-work environment.
return this.uow.withTransaction(async (trx: Knex.Transaction) => {
// Triggers `onBranchActivate` branch.
await this.eventPublisher.emitAsync(events.branch.onActivate, {
trx,
} as IBranchesActivatePayload);
// Create a new branch as primary branch.
const primaryBranch = await this.createInitialBranch();
// Mark the mutli-branches is activated.
await this.branchesSettings.markMultiBranchesAsActivated();
// Triggers `onBranchActivated` branch.
await this.eventPublisher.emitAsync(events.branch.onActivated, {
primaryBranch,
trx,
} as IBranchesActivatedPayload);
});
};
}

View File

@@ -0,0 +1,50 @@
import { Inject, Injectable } from '@nestjs/common';
import { ERRORS } from '../constants';
import { Branch } from '../models/Branch.model';
import { ServiceError } from '../../Items/ServiceError';
@Injectable()
export class BranchCommandValidator {
constructor(
@Inject(Branch.name)
private readonly branchModel: typeof Branch,
) {}
/**
* Validates the given branch whether is not only warehouse.
* @param {number} branchId
*/
public validateBranchNotOnlyWarehouse = async (branchId: number) => {
const warehouses = await this.branchModel.query().whereNot('id', branchId);
if (warehouses.length === 0) {
throw new ServiceError(ERRORS.COULD_NOT_DELETE_ONLY_BRANCH);
}
};
/**
* Validates the given branch whether is unique.
* @param {string} code - Branch code.
* @param {number} exceptBranchId - Branch id to except.
*/
public validateBranchCodeUnique = async (
code: string,
exceptBranchId?: number,
): Promise<void> => {
const branch = await this.branchModel
.query()
.onBuild((query) => {
query.select(['id']);
query.where('code', code);
if (exceptBranchId) {
query.whereNot('id', exceptBranchId);
}
})
.first();
if (branch) {
throw new ServiceError(ERRORS.BRANCH_CODE_NOT_UNIQUE);
}
};
}

View File

@@ -0,0 +1,55 @@
import { Inject, Injectable } from '@nestjs/common';
import { Knex } from 'knex';
import {
IBranchCreatedPayload,
IBranchCreatePayload,
ICreateBranchDTO,
} from '../Branches.types';
import { BranchCommandValidator } from './BranchCommandValidator.service';
import { UnitOfWork } from '../../Tenancy/TenancyDB/UnitOfWork.service';
import { EventEmitter2 } from '@nestjs/event-emitter';
import { Branch } from '../models/Branch.model';
import { events } from '@/common/events/events';
@Injectable()
export class CreateBranchService {
constructor(
private readonly uow: UnitOfWork,
private readonly eventPublisher: EventEmitter2,
private readonly validator: BranchCommandValidator,
@Inject(Branch.name)
private readonly branchModel: typeof Branch,
) {}
/**
* Creates a new branch.
* @param {ICreateBranchDTO} createBranchDTO
* @returns {Promise<IBranch>}
*/
public createBranch = async (
createBranchDTO: ICreateBranchDTO,
): Promise<Branch> => {
// Creates a new branch under unit-of-work.
return this.uow.withTransaction(async (trx: Knex.Transaction) => {
// Triggers `onBranchCreate` event.
await this.eventPublisher.emitAsync(events.warehouse.onEdit, {
createBranchDTO,
trx,
} as IBranchCreatePayload);
const branch = await this.branchModel.query().insertAndFetch({
...createBranchDTO,
});
// Triggers `onBranchCreated` event.
await this.eventPublisher.emitAsync(events.warehouse.onEdited, {
createBranchDTO,
branch,
trx,
} as IBranchCreatedPayload);
return branch;
});
};
}

View File

@@ -0,0 +1,65 @@
import { Inject, Injectable } from '@nestjs/common';
import { Knex } from 'knex';
import { IBranchDeletedPayload, IBranchDeletePayload } from './Branch.types';
import { BranchCommandValidator } from './BranchCommandValidator.service';
import { ERRORS } from '../constants';
import { Branch } from '../models/Branch.model';
import { UnitOfWork } from '../../Tenancy/TenancyDB/UnitOfWork.service';
import { EventEmitter2 } from '@nestjs/event-emitter';
import { events } from '@/common/events/events';
@Injectable()
export class DeleteBranchService {
constructor(
@Inject(Branch.name)
private readonly branchModel: typeof Branch,
private readonly uow: UnitOfWork,
private readonly eventPublisher: EventEmitter2,
private readonly validator: BranchCommandValidator,
) {}
/**
* Validates the branch deleting.
* @param {number} branchId
* @returns {Promise<void>}
*/
private authorize = async (branchId: number): Promise<void> => {
await this.validator.validateBranchNotOnlyWarehouse(branchId);
};
/**
* Deletes branch.
* @param {number} branchId
* @returns {Promise<void>}
*/
public deleteBranch = async (branchId: number): Promise<void> => {
// Retrieves the old branch or throw not found service error.
const oldBranch = await this.branchModel
.query()
.findById(branchId)
.throwIfNotFound()
.queryAndThrowIfHasRelations({
type: ERRORS.BRANCH_HAS_ASSOCIATED_TRANSACTIONS,
});
// Authorize the branch before deleting.
await this.authorize(branchId);
// Deletes branch under unit-of-work.
return this.uow.withTransaction(async (trx: Knex.Transaction) => {
// Triggers `onBranchCreate` event.
await this.eventPublisher.emitAsync(events.warehouse.onEdit, {
oldBranch,
trx,
} as IBranchDeletePayload);
await this.branchModel.query().findById(branchId).delete();
// Triggers `onBranchCreate` event.
await this.eventPublisher.emitAsync(events.warehouse.onEdited, {
oldBranch,
trx,
} as IBranchDeletedPayload);
});
};
}

View File

@@ -0,0 +1,61 @@
import { Injectable } from '@nestjs/common';
import { Knex } from 'knex';
import {
IBranchEditedPayload,
IBranchEditPayload,
IEditBranchDTO,
} from '../Branches.types';
import { Branch } from '../models/Branch.model';
import { UnitOfWork } from '../../Tenancy/TenancyDB/UnitOfWork.service';
import { EventEmitter2 } from '@nestjs/event-emitter';
import { events } from '@/common/events/events';
@Injectable()
export class EditBranchService {
constructor(
private readonly branchModel: typeof Branch,
private readonly uow: UnitOfWork,
private readonly eventPublisher: EventEmitter2,
) {}
/**
* Edits branch.
* @param {number} branchId - Branch id.
* @param {IEditBranchDTO} editBranchDTO - Edit branch data.
*/
public editBranch = async (
branchId: number,
editBranchDTO: IEditBranchDTO,
) => {
// Retrieves the old branch or throw not found service error.
const oldBranch = await this.branchModel
.query()
.findById(branchId)
.throwIfNotFound();
// Deletes branch under unit-of-work.
return this.uow.withTransaction(async (trx: Knex.Transaction) => {
// Triggers `onBranchEdit` event.
await this.eventPublisher.emitAsync(events.warehouse.onEdit, {
oldBranch,
trx,
} as IBranchEditPayload);
// Edits the branch on the storage.
const branch = await this.branchModel
.query()
.patchAndFetchById(branchId, {
...editBranchDTO,
});
// Triggers `onBranchEdited` event.
await this.eventPublisher.emitAsync(events.warehouse.onEdited, {
oldBranch,
branch,
trx,
} as IBranchEditedPayload);
return branch;
});
};
}

View File

@@ -0,0 +1,62 @@
import { Inject, Injectable } from '@nestjs/common';
import { Knex } from 'knex';
import {
IBranchMarkAsPrimaryPayload,
IBranchMarkedAsPrimaryPayload,
} from '../Branches.types';
import { EventEmitter2 } from '@nestjs/event-emitter';
import { UnitOfWork } from '../../Tenancy/TenancyDB/UnitOfWork.service';
import { Branch } from '../models/Branch.model';
import { events } from '@/common/events/events';
@Injectable()
export class MarkBranchAsPrimaryService {
constructor(
private readonly uow: UnitOfWork,
private readonly eventPublisher: EventEmitter2,
@Inject(Branch.name)
private readonly branchModel: typeof Branch,
) {}
/**
* Marks the given branch as primary.
* @param {number} branchId
* @returns {Promise<IBranch>}
*/
public async markAsPrimary(branchId: number): Promise<Branch> {
// Retrieves the old branch or throw not found service error.
const oldBranch = await this.branchModel
.query()
.findById(branchId)
.throwIfNotFound();
// Updates the branches under unit-of-work environment.
return this.uow.withTransaction(async (trx: Knex.Transaction) => {
// Triggers `onBranchMarkPrimary` event.
await this.eventPublisher.emitAsync(events.branch.onMarkPrimary, {
oldBranch,
trx,
} as IBranchMarkAsPrimaryPayload);
// Updates all branches as not primary.
await this.branchModel.query(trx).update({ primary: false });
// Updates the given branch as primary.
const markedBranch = await this.branchModel
.query(trx)
.patchAndFetchById(branchId, {
primary: true,
});
// Triggers `onBranchMarkedPrimary` event.
await this.eventPublisher.emitAsync(events.branch.onMarkedPrimary, {
markedBranch,
oldBranch,
trx,
} as IBranchMarkedAsPrimaryPayload);
return markedBranch;
});
}
}

View File

@@ -0,0 +1,7 @@
export const ERRORS = {
BRANCH_NOT_FOUND: 'BRANCH_NOT_FOUND',
MUTLI_BRANCHES_ALREADY_ACTIVATED: 'MUTLI_BRANCHES_ALREADY_ACTIVATED',
COULD_NOT_DELETE_ONLY_BRANCH: 'COULD_NOT_DELETE_ONLY_BRANCH',
BRANCH_CODE_NOT_UNIQUE: 'BRANCH_CODE_NOT_UNIQUE',
BRANCH_HAS_ASSOCIATED_TRANSACTIONS: 'BRANCH_HAS_ASSOCIATED_TRANSACTIONS'
};

View File

@@ -0,0 +1,35 @@
// import { Service, Inject } from 'typedi';
// import { omit } from 'lodash';
// import { BranchesSettings } from '../BranchesSettings';
// @Service()
// export class BranchTransactionDTOTransform {
// @Inject()
// branchesSettings: BranchesSettings;
// /**
// * Excludes DTO branch id when mutli-warehouses feature is inactive.
// * @param {number} tenantId
// * @returns {any}
// */
// private excludeDTOBranchIdWhenInactive = <T extends { branchId?: number }>(
// tenantId: number,
// DTO: T
// ): Omit<T, 'branchId'> | T => {
// const isActive = this.branchesSettings.isMultiBranchesActive(tenantId);
// return !isActive ? omit(DTO, ['branchId']) : DTO;
// };
// /**
// * Transformes the input DTO for branches feature.
// * @param {number} tenantId -
// * @param {T} DTO -
// * @returns {Omit<T, 'branchId'> | T}
// */
// public transformDTO =
// <T extends { branchId?: number }>(tenantId: number) =>
// (DTO: T): Omit<T, 'branchId'> | T => {
// return this.excludeDTOBranchIdWhenInactive<T>(tenantId, DTO);
// };
// }

View File

@@ -0,0 +1,26 @@
// import { Service, Inject } from 'typedi';
// import { Knex } from 'knex';
// import HasTenancyService from '@/services/Tenancy/TenancyService';
// @Service()
// export class CashflowTransactionsActivateBranches {
// @Inject()
// private tenancy: HasTenancyService;
// /**
// * Updates all cashflow transactions with the primary branch.
// * @param {number} tenantId
// * @param {number} primaryBranchId
// * @returns {Promise<void>}
// */
// public updateCashflowTransactionsWithBranch = async (
// tenantId: number,
// primaryBranchId: number,
// trx?: Knex.Transaction
// ) => {
// const { CashflowTransaction } = this.tenancy.models(tenantId);
// // Updates the cashflow transactions with primary branch.
// await CashflowTransaction.query(trx).update({ branchId: primaryBranchId });
// };
// }

View File

@@ -0,0 +1,26 @@
// import { Service, Inject } from 'typedi';
// import { Knex } from 'knex';
// import HasTenancyService from '@/services/Tenancy/TenancyService';
// @Service()
// export class ExpensesActivateBranches {
// @Inject()
// private tenancy: HasTenancyService;
// /**
// * Updates all expenses transactions with the primary branch.
// * @param {number} tenantId
// * @param {number} primaryBranchId
// * @returns {Promise<void>}
// */
// public updateExpensesWithBranch = async (
// tenantId: number,
// primaryBranchId: number,
// trx?: Knex.Transaction
// ) => {
// const { Expense } = this.tenancy.models(tenantId);
// // Updates the expenses with primary branch.
// await Expense.query(trx).update({ branchId: primaryBranchId });
// };
// }

View File

@@ -0,0 +1,26 @@
// import { Service, Inject } from 'typedi';
// import HasTenancyService from '@/services/Tenancy/TenancyService';
// import { Knex } from 'knex';
// @Service()
// export class ManualJournalsActivateBranches {
// @Inject()
// private tenancy: HasTenancyService;
// /**
// * Updates all manual journals transactions with the primary branch.
// * @param {number} tenantId
// * @param {number} primaryBranchId
// * @returns {Promise<void>}
// */
// public updateManualJournalsWithBranch = async (
// tenantId: number,
// primaryBranchId: number,
// trx?: Knex.Transaction
// ) => {
// const { ManualJournal } = this.tenancy.models(tenantId);
// // Updates the manual journal with primary branch.
// await ManualJournal.query(trx).update({ branchId: primaryBranchId });
// };
// }

View File

@@ -0,0 +1,32 @@
// import { omit } from 'lodash';
// import { Inject, Service } from 'typedi';
// import { IManualJournal } from '@/interfaces';
// import { BranchesSettings } from '../../BranchesSettings';
// @Service()
// export class ManualJournalBranchesDTOTransformer {
// @Inject()
// branchesSettings: BranchesSettings;
// private excludeDTOBranchIdWhenInactive = (
// tenantId: number,
// DTO: IManualJournal
// ): IManualJournal => {
// const isActive = this.branchesSettings.isMultiBranchesActive(tenantId);
// if (isActive) return DTO;
// return {
// ...DTO,
// entries: DTO.entries.map((e) => omit(e, ['branchId'])),
// };
// };
// /**
// *
// */
// public transformDTO =
// (tenantId: number) =>
// (DTO: IManualJournal): IManualJournal => {
// return this.excludeDTOBranchIdWhenInactive(tenantId, DTO);
// };
// }

View File

@@ -0,0 +1,23 @@
// import { Service, Inject } from 'typedi';
// import { ServiceError } from '@/exceptions';
// import { IManualJournalDTO, IManualJournalEntryDTO } from '@/interfaces';
// import { ERRORS } from './constants';
// @Service()
// export class ManualJournalBranchesValidator {
// /**
// * Validates the DTO entries should have branch id.
// * @param {IManualJournalDTO} manualJournalDTO
// */
// public validateEntriesHasBranchId = async (
// manualJournalDTO: IManualJournalDTO
// ) => {
// const hasNoIdEntries = manualJournalDTO.entries.filter(
// (entry: IManualJournalEntryDTO) =>
// !entry.branchId && !manualJournalDTO.branchId
// );
// if (hasNoIdEntries.length > 0) {
// throw new ServiceError(ERRORS.MANUAL_JOURNAL_ENTRIES_HAVE_NO_BRANCH_ID);
// }
// };
// }

View File

@@ -0,0 +1,4 @@
export const ERRORS = {
MANUAL_JOURNAL_ENTRIES_HAVE_NO_BRANCH_ID:
'MANUAL_JOURNAL_ENTRIES_HAVE_NO_BRANCH_ID',
};

View File

@@ -0,0 +1,26 @@
// import { Service, Inject } from 'typedi';
// import HasTenancyService from '@/services/Tenancy/TenancyService';
// import { Knex } from 'knex';
// @Service()
// export class BillActivateBranches {
// @Inject()
// private tenancy: HasTenancyService;
// /**
// * Updates all bills transactions with the primary branch.
// * @param {number} tenantId
// * @param {number} primaryBranchId
// * @returns {Promise<void>}
// */
// public updateBillsWithBranch = async (
// tenantId: number,
// primaryBranchId: number,
// trx?: Knex.Transaction
// ) => {
// const { Bill } = this.tenancy.models(tenantId);
// // Updates the sale invoice with primary branch.
// await Bill.query(trx).update({ branchId: primaryBranchId });
// };
// }

View File

@@ -0,0 +1,26 @@
// import { Service, Inject } from 'typedi';
// import HasTenancyService from '@/services/Tenancy/TenancyService';
// import { Knex } from 'knex';
// @Service()
// export class BillPaymentsActivateBranches {
// @Inject()
// tenancy: HasTenancyService;
// /**
// * Updates all bills payments transcations with the primary branch.
// * @param {number} tenantId
// * @param {number} primaryBranchId
// * @returns {Promise<void>}
// */
// public updateBillPaymentsWithBranch = async (
// tenantId: number,
// primaryBranchId: number,
// trx?: Knex.Transaction
// ) => {
// const { BillPayment } = this.tenancy.models(tenantId);
// // Updates the bill payments with primary branch.
// await BillPayment.query(trx).update({ branchId: primaryBranchId });
// };
// }

View File

@@ -0,0 +1,26 @@
// import { Service, Inject } from 'typedi';
// import HasTenancyService from '@/services/Tenancy/TenancyService';
// import { Knex } from 'knex';
// @Service()
// export class VendorCreditActivateBranches {
// @Inject()
// tenancy: HasTenancyService;
// /**
// * Updates all vendor credits transcations with the primary branch.
// * @param {number} tenantId
// * @param {number} primaryBranchId
// * @returns {Promise<void>}
// */
// public updateVendorCreditsWithBranch = async (
// tenantId: number,
// primaryBranchId: number,
// trx?: Knex.Transaction
// ) => {
// const { VendorCredit } = this.tenancy.models(tenantId);
// // Updates the vendors credits with primary branch.
// await VendorCredit.query(trx).update({ branchId: primaryBranchId });
// };
// }

View File

@@ -0,0 +1,26 @@
// import { Service, Inject } from 'typedi';
// import HasTenancyService from '@/services/Tenancy/TenancyService';
// import { Knex } from 'knex';
// @Service()
// export class CreditNoteActivateBranches {
// @Inject()
// private tenancy: HasTenancyService;
// /**
// * Updates all creidt notes transactions with the primary branch.
// * @param {number} tenantId
// * @param {number} primaryBranchId
// * @returns {Promise<void>}
// */
// public updateCreditsWithBranch = async (
// tenantId: number,
// primaryBranchId: number,
// trx?: Knex.Transaction
// ) => {
// const { CreditNote } = this.tenancy.models(tenantId);
// // Updates the sale invoice with primary branch.
// await CreditNote.query(trx).update({ branchId: primaryBranchId });
// };
// }

View File

@@ -0,0 +1,26 @@
// import { Service, Inject } from 'typedi';
// import HasTenancyService from '@/services/Tenancy/TenancyService';
// import { Knex } from 'knex';
// @Service()
// export class PaymentReceiveActivateBranches {
// @Inject()
// tenancy: HasTenancyService;
// /**
// * Updates all creidt notes transactions with the primary branch.
// * @param {number} tenantId
// * @param {number} primaryBranchId
// * @returns {Promise<void>}
// */
// public updatePaymentsWithBranch = async (
// tenantId: number,
// primaryBranchId: number,
// trx?: Knex.Transaction
// ) => {
// const { PaymentReceive } = this.tenancy.models(tenantId);
// // Updates the sale invoice with primary branch.
// await PaymentReceive.query(trx).update({ branchId: primaryBranchId });
// };
// }

View File

@@ -0,0 +1,26 @@
// import { Service, Inject } from 'typedi';
// import HasTenancyService from '@/services/Tenancy/TenancyService';
// import { Knex } from 'knex';
// @Service()
// export class SaleEstimateActivateBranches {
// @Inject()
// tenancy: HasTenancyService;
// /**
// * Updates all sale estimates transactions with the primary branch.
// * @param {number} tenantId
// * @param {number} primaryBranchId
// * @returns {Promise<void>}
// */
// public updateEstimatesWithBranch = async (
// tenantId: number,
// primaryBranchId: number,
// trx?: Knex.Transaction
// ) => {
// const { PaymentReceive } = this.tenancy.models(tenantId);
// // Updates the sale invoice with primary branch.
// await PaymentReceive.query(trx).update({ branchId: primaryBranchId });
// };
// }

View File

@@ -0,0 +1,26 @@
// import { Service, Inject } from 'typedi';
// import HasTenancyService from '@/services/Tenancy/TenancyService';
// import { Knex } from 'knex';
// @Service()
// export class SaleInvoiceActivateBranches {
// @Inject()
// private tenancy: HasTenancyService;
// /**
// * Updates all sale invoices transactions with the primary branch.
// * @param {number} tenantId
// * @param {number} primaryBranchId
// * @returns {Promise<void>}
// */
// public updateInvoicesWithBranch = async (
// tenantId: number,
// primaryBranchId: number,
// trx?: Knex.Transaction
// ) => {
// const { SaleInvoice } = this.tenancy.models(tenantId);
// // Updates the sale invoice with primary branch.
// await SaleInvoice.query(trx).update({ branchId: primaryBranchId });
// };
// }

View File

@@ -0,0 +1,26 @@
// import { Service, Inject } from 'typedi';
// import HasTenancyService from '@/services/Tenancy/TenancyService';
// import { Knex } from 'knex';
// @Service()
// export class SaleReceiptActivateBranches {
// @Inject()
// tenancy: HasTenancyService;
// /**
// * Updates all sale receipts transactions with the primary branch.
// * @param {number} tenantId
// * @param {number} primaryBranchId
// * @returns {Promise<void>}
// */
// public updateReceiptsWithBranch = async (
// tenantId: number,
// primaryBranchId: number,
// trx?: Knex.Transaction
// ) => {
// const { SaleReceipt } = this.tenancy.models(tenantId);
// // Updates the sale receipt with primary branch.
// await SaleReceipt.query(trx).update({ branchId: primaryBranchId });
// };
// }

View File

@@ -0,0 +1,75 @@
// import { ServiceError } from '@/exceptions';
// import HasTenancyService from '@/services/Tenancy/TenancyService';
// import { Service, Inject } from 'typedi';
// import { BranchesSettings } from '../BranchesSettings';
// import { ERRORS } from './constants';
// @Service()
// export class ValidateBranchExistance {
// @Inject()
// tenancy: HasTenancyService;
// @Inject()
// branchesSettings: BranchesSettings;
// /**
// * Validate transaction branch id when the feature is active.
// * @param {number} tenantId
// * @param {number} branchId
// * @returns {Promise<void>}
// */
// public validateTransactionBranchWhenActive = async (
// tenantId: number,
// branchId: number | null
// ) => {
// const isActive = this.branchesSettings.isMultiBranchesActive(tenantId);
// // Can't continue if the multi-warehouses feature is inactive.
// if (!isActive) return;
// return this.validateTransactionBranch(tenantId, branchId);
// };
// /**
// * Validate transaction branch id existance.
// * @param {number} tenantId
// * @param {number} branchId
// * @return {Promise<void>}
// */
// public validateTransactionBranch = async (
// tenantId: number,
// branchId: number | null
// ) => {
// this.validateBranchIdExistance(branchId);
// await this.validateBranchExistance(tenantId, branchId);
// };
// /**
// *
// * @param branchId
// */
// public validateBranchIdExistance = (branchId: number | null) => {
// if (!branchId) {
// throw new ServiceError(ERRORS.BRANCH_ID_REQUIRED);
// }
// };
// /**
// *
// * @param tenantId
// * @param branchId
// */
// public validateBranchExistance = async (
// tenantId: number,
// branchId: number
// ) => {
// const { Branch } = this.tenancy.models(tenantId);
// const branch = await Branch.query().findById(branchId);
// if (!branch) {
// throw new ServiceError(ERRORS.BRANCH_ID_NOT_FOUND);
// }
// };
// }

View File

@@ -0,0 +1,6 @@
export const ERRORS = {
BRANCH_ID_REQUIRED: 'BRANCH_ID_REQUIRED',
BRANCH_ID_NOT_FOUND: 'BRANCH_ID_NOT_FOUND'
}

View File

@@ -0,0 +1,192 @@
import { Model, mixin } from 'objection';
import TenantModel from 'models/TenantModel';
import BranchMetadata from './Branch.settings';
import ModelSetting from './ModelSetting';
import { BaseModel } from '@/models/Model';
export class Branch extends BaseModel{
name!: string;
code!: string;
address!: string;
city!: string;
country!: string;
phoneNumber!: string;
email!: string;
website!: string;
primary!: boolean;
/**
* Table name.
*/
static get tableName() {
return 'branches';
}
/**
* Timestamps columns.
*/
get timestamps() {
return ['created_at', 'updated_at'];
}
/**
* Model modifiers.
*/
static get modifiers() {
return {
/**
* Filters accounts by the given ids.
* @param {Query} query
* @param {number[]} accountsIds
*/
isPrimary(query) {
query.where('primary', true);
},
};
}
/**
* Relationship mapping.
*/
// static get relationMappings() {
// const SaleInvoice = require('models/SaleInvoice');
// const SaleEstimate = require('models/SaleEstimate');
// const SaleReceipt = require('models/SaleReceipt');
// const Bill = require('models/Bill');
// const PaymentReceive = require('models/PaymentReceive');
// const PaymentMade = require('models/BillPayment');
// const VendorCredit = require('models/VendorCredit');
// const CreditNote = require('models/CreditNote');
// const AccountTransaction = require('models/AccountTransaction');
// const InventoryTransaction = require('models/InventoryTransaction');
// return {
// /**
// * Branch may belongs to associated sale invoices.
// */
// invoices: {
// relation: Model.HasManyRelation,
// modelClass: SaleInvoice.default,
// join: {
// from: 'branches.id',
// to: 'sales_invoices.branchId',
// },
// },
// /**
// * Branch may belongs to associated sale estimates.
// */
// estimates: {
// relation: Model.HasManyRelation,
// modelClass: SaleEstimate.default,
// join: {
// from: 'branches.id',
// to: 'sales_estimates.branchId',
// },
// },
// /**
// * Branch may belongs to associated sale receipts.
// */
// receipts: {
// relation: Model.HasManyRelation,
// modelClass: SaleReceipt.default,
// join: {
// from: 'branches.id',
// to: 'sales_receipts.branchId',
// },
// },
// /**
// * Branch may belongs to associated payment receives.
// */
// paymentReceives: {
// relation: Model.HasManyRelation,
// modelClass: PaymentReceive.default,
// join: {
// from: 'branches.id',
// to: 'payment_receives.branchId',
// },
// },
// /**
// * Branch may belongs to associated bills.
// */
// bills: {
// relation: Model.HasManyRelation,
// modelClass: Bill.default,
// join: {
// from: 'branches.id',
// to: 'bills.branchId',
// },
// },
// /**
// * Branch may belongs to associated payment mades.
// */
// paymentMades: {
// relation: Model.HasManyRelation,
// modelClass: PaymentMade.default,
// join: {
// from: 'branches.id',
// to: 'bills_payments.branchId',
// },
// },
// /**
// * Branch may belongs to associated credit notes.
// */
// creditNotes: {
// relation: Model.HasManyRelation,
// modelClass: CreditNote.default,
// join: {
// from: 'branches.id',
// to: 'credit_notes.branchId',
// },
// },
// /**
// * Branch may belongs to associated to vendor credits.
// */
// vendorCredit: {
// relation: Model.HasManyRelation,
// modelClass: VendorCredit.default,
// join: {
// from: 'branches.id',
// to: 'vendor_credits.branchId',
// },
// },
// /**
// * Branch may belongs to associated to accounts transactions.
// */
// accountsTransactions: {
// relation: Model.HasManyRelation,
// modelClass: AccountTransaction.default,
// join: {
// from: 'branches.id',
// to: 'accounts_transactions.branchId',
// },
// },
// /**
// * Branch may belongs to associated to inventory transactions.
// */
// inventoryTransactions: {
// relation: Model.HasManyRelation,
// modelClass: InventoryTransaction.default,
// join: {
// from: 'branches.id',
// to: 'inventory_transactions.branchId',
// },
// },
// };
// }
/**
* Model settings.
*/
static get meta() {
return BranchMetadata;
}
}

View File

@@ -0,0 +1,25 @@
import { Inject } from '@nestjs/common';
import { Injectable } from '@nestjs/common';
import { Branch } from '../models/Branch.model';
@Injectable()
export class GetBranchService {
constructor(
@Inject(Branch.name)
private readonly branch: typeof Branch,
) {}
/**
* Retrieves the given branch details.
* @param {number} branchId
* @returns {Promise<IBranch>}
*/
public getBranch = async (branchId: number): Promise<Branch> => {
const branch = await this.branch
.query()
.findById(branchId)
.throwIfNotFound();
return branch;
};
}

View File

@@ -0,0 +1,20 @@
import { Inject, Injectable } from '@nestjs/common';
import { Branch } from '../models/Branch.model';
@Injectable()
export class GetBranchesService {
constructor(
@Inject(Branch.name)
private readonly branch: typeof Branch,
) {}
/**
* Retrieves branches list.
* @returns
*/
public getBranches = async () => {
const branches = await this.branch.query().orderBy('name', 'DESC');
return branches;
};
}

View File

@@ -0,0 +1,38 @@
// import { IBranchesActivatedPayload } from '@/interfaces';
// import { Service, Inject } from 'typedi';
// import events from '@/subscribers/events';
// import { CashflowTransactionsActivateBranches } from '../../Integrations/Cashflow/CashflowActivateBranches';
// @Service()
// export class CreditNoteActivateBranchesSubscriber {
// @Inject()
// private cashflowActivateBranches: CashflowTransactionsActivateBranches;
// /**
// * Attaches events with handlers.
// */
// public attach(bus) {
// bus.subscribe(
// events.branch.onActivated,
// this.updateCashflowWithBranchOnActivated
// );
// return bus;
// }
// /**
// * Updates accounts transactions with the primary branch once
// * the multi-branches is activated.
// * @param {IBranchesActivatedPayload}
// */
// private updateCashflowWithBranchOnActivated = async ({
// tenantId,
// primaryBranch,
// trx,
// }: IBranchesActivatedPayload) => {
// await this.cashflowActivateBranches.updateCashflowTransactionsWithBranch(
// tenantId,
// primaryBranch.id,
// trx
// );
// };
// }

View File

@@ -0,0 +1,38 @@
// import { IBranchesActivatedPayload } from '@/interfaces';
// import { Service, Inject } from 'typedi';
// import { CreditNoteActivateBranches } from '../../Integrations/Sales/CreditNoteBranchesActivate';
// import events from '@/subscribers/events';
// @Service()
// export class CreditNoteActivateBranchesSubscriber {
// @Inject()
// private creditNotesActivateBranches: CreditNoteActivateBranches;
// /**
// * Attaches events with handlers.
// */
// public attach(bus) {
// bus.subscribe(
// events.branch.onActivated,
// this.updateCreditNoteWithBranchOnActivated
// );
// return bus;
// }
// /**
// * Updates accounts transactions with the primary branch once
// * the multi-branches is activated.
// * @param {IBranchesActivatedPayload}
// */
// private updateCreditNoteWithBranchOnActivated = async ({
// tenantId,
// primaryBranch,
// trx,
// }: IBranchesActivatedPayload) => {
// await this.creditNotesActivateBranches.updateCreditsWithBranch(
// tenantId,
// primaryBranch.id,
// trx
// );
// };
// }

View File

@@ -0,0 +1,38 @@
// import { IBranchesActivatedPayload } from '@/interfaces';
// import { Service, Inject } from 'typedi';
// import events from '@/subscribers/events';
// import { ExpensesActivateBranches } from '../../Integrations/Expense/ExpensesActivateBranches';
// @Service()
// export class ExpenseActivateBranchesSubscriber {
// @Inject()
// private expensesActivateBranches: ExpensesActivateBranches;
// /**
// * Attaches events with handlers.
// */
// public attach(bus) {
// bus.subscribe(
// events.branch.onActivated,
// this.updateExpensesWithBranchOnActivated
// );
// return bus;
// }
// /**
// * Updates accounts transactions with the primary branch once
// * the multi-branches is activated.
// * @param {IBranchesActivatedPayload}
// */
// private updateExpensesWithBranchOnActivated = async ({
// tenantId,
// primaryBranch,
// trx,
// }: IBranchesActivatedPayload) => {
// await this.expensesActivateBranches.updateExpensesWithBranch(
// tenantId,
// primaryBranch.id,
// trx
// );
// };
// }

View File

@@ -0,0 +1,38 @@
// import { IBranchesActivatedPayload } from '@/interfaces';
// import { Service, Inject } from 'typedi';
// import events from '@/subscribers/events';
// import { BillPaymentsActivateBranches } from '../../Integrations/Purchases/PaymentMadeBranchesActivate';
// @Service()
// export class PaymentMadeActivateBranchesSubscriber {
// @Inject()
// private paymentsActivateBranches: BillPaymentsActivateBranches;
// /**
// * Attaches events with handlers.
// */
// public attach(bus) {
// bus.subscribe(
// events.branch.onActivated,
// this.updatePaymentsWithBranchOnActivated
// );
// return bus;
// }
// /**
// * Updates accounts transactions with the primary branch once
// * the multi-branches is activated.
// * @param {IBranchesActivatedPayload}
// */
// private updatePaymentsWithBranchOnActivated = async ({
// tenantId,
// primaryBranch,
// trx,
// }: IBranchesActivatedPayload) => {
// await this.paymentsActivateBranches.updateBillPaymentsWithBranch(
// tenantId,
// primaryBranch.id,
// trx
// );
// };
// }

View File

@@ -0,0 +1,38 @@
// import { IBranchesActivatedPayload } from '@/interfaces';
// import { Service, Inject } from 'typedi';
// import events from '@/subscribers/events';
// import { PaymentReceiveActivateBranches } from '../../Integrations/Sales/PaymentReceiveBranchesActivate';
// @Service()
// export class PaymentReceiveActivateBranchesSubscriber {
// @Inject()
// private paymentsActivateBranches: PaymentReceiveActivateBranches;
// /**
// * Attaches events with handlers.
// */
// public attach(bus) {
// bus.subscribe(
// events.branch.onActivated,
// this.updateCreditNoteWithBranchOnActivated
// );
// return bus;
// }
// /**
// * Updates accounts transactions with the primary branch once
// * the multi-branches is activated.
// * @param {IBranchesActivatedPayload}
// */
// private updateCreditNoteWithBranchOnActivated = async ({
// tenantId,
// primaryBranch,
// trx,
// }: IBranchesActivatedPayload) => {
// await this.paymentsActivateBranches.updatePaymentsWithBranch(
// tenantId,
// primaryBranch.id,
// trx
// );
// };
// }

View File

@@ -0,0 +1,38 @@
// import { IBranchesActivatedPayload } from '@/interfaces';
// import { Service, Inject } from 'typedi';
// import events from '@/subscribers/events';
// import { SaleEstimateActivateBranches } from '../../Integrations/Sales/SaleEstimatesBranchesActivate';
// @Service()
// export class SaleEstimatesActivateBranchesSubscriber {
// @Inject()
// private estimatesActivateBranches: SaleEstimateActivateBranches;
// /**
// * Attaches events with handlers.
// */
// public attach(bus) {
// bus.subscribe(
// events.branch.onActivated,
// this.updateEstimatesWithBranchOnActivated
// );
// return bus;
// }
// /**
// * Updates accounts transactions with the primary branch once
// * the multi-branches is activated.
// * @param {IBranchesActivatedPayload}
// */
// private updateEstimatesWithBranchOnActivated = async ({
// tenantId,
// primaryBranch,
// trx,
// }: IBranchesActivatedPayload) => {
// await this.estimatesActivateBranches.updateEstimatesWithBranch(
// tenantId,
// primaryBranch.id,
// trx
// );
// };
// }

View File

@@ -0,0 +1,38 @@
// import { IBranchesActivatedPayload } from '@/interfaces';
// import { Service, Inject } from 'typedi';
// import events from '@/subscribers/events';
// import { SaleInvoiceActivateBranches } from '../../Integrations/Sales/SaleInvoiceBranchesActivate';
// @Service()
// export class SaleInvoicesActivateBranchesSubscriber {
// @Inject()
// private invoicesActivateBranches: SaleInvoiceActivateBranches;
// /**
// * Attaches events with handlers.
// */
// public attach(bus) {
// bus.subscribe(
// events.branch.onActivated,
// this.updateInvoicesWithBranchOnActivated
// );
// return bus;
// }
// /**
// * Updates accounts transactions with the primary branch once
// * the multi-branches is activated.
// * @param {IBranchesActivatedPayload}
// */
// private updateInvoicesWithBranchOnActivated = async ({
// tenantId,
// primaryBranch,
// trx,
// }: IBranchesActivatedPayload) => {
// await this.invoicesActivateBranches.updateInvoicesWithBranch(
// tenantId,
// primaryBranch.id,
// trx
// );
// };
// }

View File

@@ -0,0 +1,38 @@
// import { IBranchesActivatedPayload } from '@/interfaces';
// import { Service, Inject } from 'typedi';
// import events from '@/subscribers/events';
// import { SaleReceiptActivateBranches } from '../../Integrations/Sales/SaleReceiptBranchesActivate';
// @Service()
// export class SaleReceiptsActivateBranchesSubscriber {
// @Inject()
// private receiptsActivateBranches: SaleReceiptActivateBranches;
// /**
// * Attaches events with handlers.
// */
// public attach(bus) {
// bus.subscribe(
// events.branch.onActivated,
// this.updateReceiptsWithBranchOnActivated
// );
// return bus;
// }
// /**
// * Updates accounts transactions with the primary branch once
// * the multi-branches is activated.
// * @param {IBranchesActivatedPayload}
// */
// private updateReceiptsWithBranchOnActivated = async ({
// tenantId,
// primaryBranch,
// trx,
// }: IBranchesActivatedPayload) => {
// await this.receiptsActivateBranches.updateReceiptsWithBranch(
// tenantId,
// primaryBranch.id,
// trx
// );
// };
// }

View File

@@ -0,0 +1,8 @@
// export * from './CashflowBranchesActivateSubscriber';
// export * from './CreditNoteBranchesActivateSubscriber';
// export * from './PaymentMadeBranchesActivateSubscriber';
// export * from './PaymentReceiveBranchesActivateSubscriber';
// export * from './SaleReceiptsBranchesActivateSubscriber';
// export * from './SaleEstiamtesBranchesActivateSubscriber';
// export * from './SaleInvoiceBranchesActivateSubscriber';
// export * from './ExpenseBranchesActivateSubscriber';

View File

@@ -0,0 +1,53 @@
// import { Inject, Service } from 'typedi';
// import events from '@/subscribers/events';
// import { IBillCreatingPayload, IBillEditingPayload } from '@/interfaces';
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
// @Service()
// export class BillBranchValidateSubscriber {
// @Inject()
// private validateBranchExistance: ValidateBranchExistance;
// /**
// * Attaches events with handlers.
// */
// public attach = (bus) => {
// bus.subscribe(
// events.bill.onCreating,
// this.validateBranchExistanceOnBillCreating
// );
// bus.subscribe(
// events.bill.onEditing,
// this.validateBranchExistanceOnBillEditing
// );
// return bus;
// };
// /**
// * Validate branch existance on estimate creating.
// * @param {ISaleEstimateCreatedPayload} payload
// */
// private validateBranchExistanceOnBillCreating = async ({
// tenantId,
// billDTO,
// }: IBillCreatingPayload) => {
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
// tenantId,
// billDTO.branchId
// );
// };
// /**
// * Validate branch existance once estimate editing.
// * @param {ISaleEstimateEditingPayload} payload
// */
// private validateBranchExistanceOnBillEditing = async ({
// billDTO,
// tenantId,
// }: IBillEditingPayload) => {
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
// tenantId,
// billDTO.branchId
// );
// };
// }

View File

@@ -0,0 +1,35 @@
// import { Inject, Service } from 'typedi';
// import events from '@/subscribers/events';
// import { ICommandCashflowCreatingPayload } from '@/interfaces';
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
// @Service()
// export class CashflowBranchDTOValidatorSubscriber {
// @Inject()
// private validateBranchExistance: ValidateBranchExistance;
// /**
// * Attaches events with handlers.
// */
// public attach = (bus) => {
// bus.subscribe(
// events.cashflow.onTransactionCreating,
// this.validateBranchExistanceOnCashflowTransactionCreating
// );
// return bus;
// };
// /**
// * Validate branch existance once cashflow transaction creating.
// * @param {ICommandCashflowCreatingPayload} payload
// */
// private validateBranchExistanceOnCashflowTransactionCreating = async ({
// tenantId,
// newTransactionDTO,
// }: ICommandCashflowCreatingPayload) => {
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
// tenantId,
// newTransactionDTO.branchId
// );
// };
// }

View File

@@ -0,0 +1,104 @@
// import { Inject, Service } from 'typedi';
// import events from '@/subscribers/events';
// import {
// ICustomerEventCreatingPayload,
// ICustomerOpeningBalanceEditingPayload,
// IVendorEventCreatingPayload,
// IVendorOpeningBalanceEditingPayload,
// } from '@/interfaces';
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
// @Service()
// export class ContactBranchValidateSubscriber {
// @Inject()
// private validateBranchExistance: ValidateBranchExistance;
// /**
// * Attaches events with handlers.
// */
// public attach = (bus) => {
// bus.subscribe(
// events.customers.onCreating,
// this.validateBranchExistanceOnCustomerCreating
// );
// bus.subscribe(
// events.customers.onOpeningBalanceChanging,
// this.validateBranchExistanceOnCustomerOpeningBalanceEditing
// );
// bus.subscribe(
// events.vendors.onCreating,
// this.validateBranchExistanceonVendorCreating
// );
// bus.subscribe(
// events.vendors.onOpeningBalanceChanging,
// this.validateBranchExistanceOnVendorOpeningBalanceEditing
// );
// return bus;
// };
// /**
// * Validate branch existance on customer creating.
// * @param {ICustomerEventCreatingPayload} payload
// */
// 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,
// customerDTO.openingBalanceBranchId
// );
// };
// /**
// * Validate branch existance once customer opening balance editing.
// * @param {ICustomerOpeningBalanceEditingPayload} payload
// */
// private validateBranchExistanceOnCustomerOpeningBalanceEditing = async ({
// openingBalanceEditDTO,
// tenantId,
// }: ICustomerOpeningBalanceEditingPayload) => {
// if (!openingBalanceEditDTO.openingBalance) return;
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
// tenantId,
// openingBalanceEditDTO.openingBalanceBranchId
// );
// };
// /**
// * Validates the branch existance on vendor creating.
// * @param {IVendorEventCreatingPayload} payload -
// */
// private validateBranchExistanceonVendorCreating = async ({
// vendorDTO,
// tenantId,
// }: IVendorEventCreatingPayload) => {
// // Can't continue if the customer opening balance is zero.
// if (!vendorDTO.openingBalance) return;
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
// tenantId,
// vendorDTO.openingBalanceBranchId
// );
// };
// /**
// * Validate branch existance once the vendor opening balance editing.
// * @param {IVendorOpeningBalanceEditingPayload}
// */
// private validateBranchExistanceOnVendorOpeningBalanceEditing = async ({
// tenantId,
// openingBalanceEditDTO,
// }: IVendorOpeningBalanceEditingPayload) => {
// if (!openingBalanceEditDTO.openingBalance) return;
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
// tenantId,
// openingBalanceEditDTO.openingBalanceBranchId
// );
// };
// }

View File

@@ -0,0 +1,56 @@
// import { Inject, Service } from 'typedi';
// import events from '@/subscribers/events';
// import {
// ICreditNoteCreatingPayload,
// ICreditNoteEditingPayload,
// } from '@/interfaces';
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
// @Service()
// export class CreditNoteBranchValidateSubscriber {
// @Inject()
// private validateBranchExistance: ValidateBranchExistance;
// /**
// * Attaches events with handlers.
// */
// public attach = (bus) => {
// bus.subscribe(
// events.creditNote.onCreating,
// this.validateBranchExistanceOnCreditCreating
// );
// bus.subscribe(
// events.creditNote.onEditing,
// this.validateBranchExistanceOnCreditEditing
// );
// return bus;
// };
// /**
// * Validate branch existance on estimate creating.
// * @param {ICreditNoteCreatingPayload} payload
// */
// private validateBranchExistanceOnCreditCreating = async ({
// tenantId,
// creditNoteDTO,
// }: ICreditNoteCreatingPayload) => {
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
// tenantId,
// creditNoteDTO.branchId
// );
// };
// /**
// * Validate branch existance once estimate editing.
// * @param {ISaleEstimateEditingPayload} payload
// */
// private validateBranchExistanceOnCreditEditing = async ({
// creditNoteEditDTO,
// tenantId,
// }: ICreditNoteEditingPayload) => {
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
// tenantId,
// creditNoteEditDTO.branchId
// );
// };
// }

View File

@@ -0,0 +1,35 @@
// import { Inject, Service } from 'typedi';
// import events from '@/subscribers/events';
// import { IRefundCreditNoteCreatingPayload } from '@/interfaces';
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
// @Service()
// export class CreditNoteRefundBranchValidateSubscriber {
// @Inject()
// private validateBranchExistance: ValidateBranchExistance;
// /**
// * Attaches events with handlers.
// */
// public attach = (bus) => {
// bus.subscribe(
// events.creditNote.onRefundCreating,
// this.validateBranchExistanceOnCreditRefundCreating
// );
// return bus;
// };
// /**
// * Validate branch existance on refund credit note creating.
// * @param {ICreditNoteCreatingPayload} payload
// */
// private validateBranchExistanceOnCreditRefundCreating = async ({
// tenantId,
// newCreditNoteDTO,
// }: IRefundCreditNoteCreatingPayload) => {
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
// tenantId,
// newCreditNoteDTO.branchId
// );
// };
// }

View File

@@ -0,0 +1,56 @@
// import { Inject, Service } from 'typedi';
// import events from '@/subscribers/events';
// import {
// IExpenseCreatingPayload,
// IExpenseEventEditingPayload,
// } from '@/interfaces';
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
// @Service()
// export class ExpenseBranchValidateSubscriber {
// @Inject()
// private validateBranchExistance: ValidateBranchExistance;
// /**
// * Attaches events with handlers.
// */
// public attach = (bus) => {
// bus.subscribe(
// events.expenses.onCreating,
// this.validateBranchExistanceOnExpenseCreating
// );
// bus.subscribe(
// events.expenses.onEditing,
// this.validateBranchExistanceOnExpenseEditing
// );
// return bus;
// };
// /**
// * Validate branch existance once expense transaction creating.
// * @param {ISaleEstimateCreatedPayload} payload
// */
// private validateBranchExistanceOnExpenseCreating = async ({
// tenantId,
// expenseDTO,
// }: IExpenseCreatingPayload) => {
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
// tenantId,
// expenseDTO.branchId
// );
// };
// /**
// * Validate branch existance once expense transaction editing.
// * @param {ISaleEstimateEditingPayload} payload
// */
// private validateBranchExistanceOnExpenseEditing = async ({
// expenseDTO,
// tenantId,
// }: IExpenseEventEditingPayload) => {
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
// tenantId,
// expenseDTO.branchId
// );
// };
// }

View File

@@ -0,0 +1,35 @@
// import { Inject, Service } from 'typedi';
// import events from '@/subscribers/events';
// import { IInventoryAdjustmentCreatingPayload } from '@/interfaces';
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
// @Service()
// export class InventoryAdjustmentBranchValidateSubscriber {
// @Inject()
// private validateBranchExistance: ValidateBranchExistance;
// /**
// * Attaches events with handlers.
// */
// public attach = (bus) => {
// bus.subscribe(
// events.inventoryAdjustment.onQuickCreating,
// this.validateBranchExistanceOnInventoryCreating
// );
// return bus;
// };
// /**
// * Validate branch existance on invoice creating.
// * @param {ISaleInvoiceCreatingPaylaod} payload
// */
// private validateBranchExistanceOnInventoryCreating = async ({
// tenantId,
// quickAdjustmentDTO,
// }: IInventoryAdjustmentCreatingPayload) => {
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
// tenantId,
// quickAdjustmentDTO.branchId
// );
// };
// }

View File

@@ -0,0 +1,56 @@
// import { Inject, Service } from 'typedi';
// import events from '@/subscribers/events';
// import {
// ISaleInvoiceCreatingPaylaod,
// ISaleInvoiceEditingPayload,
// } from '@/interfaces';
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
// @Service()
// export class InvoiceBranchValidateSubscriber {
// @Inject()
// private validateBranchExistance: ValidateBranchExistance;
// /**
// * Attaches events with handlers.
// */
// public attach = (bus) => {
// bus.subscribe(
// events.saleInvoice.onCreating,
// this.validateBranchExistanceOnInvoiceCreating
// );
// bus.subscribe(
// events.saleInvoice.onEditing,
// this.validateBranchExistanceOnInvoiceEditing
// );
// return bus;
// };
// /**
// * Validate branch existance on invoice creating.
// * @param {ISaleInvoiceCreatingPaylaod} payload
// */
// private validateBranchExistanceOnInvoiceCreating = async ({
// tenantId,
// saleInvoiceDTO,
// }: ISaleInvoiceCreatingPaylaod) => {
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
// tenantId,
// saleInvoiceDTO.branchId
// );
// };
// /**
// * Validate branch existance once invoice editing.
// * @param {ISaleInvoiceEditingPayload} payload
// */
// private validateBranchExistanceOnInvoiceEditing = async ({
// saleInvoiceDTO,
// tenantId,
// }: ISaleInvoiceEditingPayload) => {
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
// tenantId,
// saleInvoiceDTO.branchId
// );
// };
// }

View File

@@ -0,0 +1,76 @@
// import { Inject, Service } from 'typedi';
// import events from '@/subscribers/events';
// import {
// Features,
// IManualJournalCreatingPayload,
// IManualJournalEditingPayload,
// } from '@/interfaces';
// import { ManualJournalBranchesValidator } from '../../Integrations/ManualJournals/ManualJournalsBranchesValidator';
// import { FeaturesManager } from '@/services/Features/FeaturesManager';
// @Service()
// export class ManualJournalBranchValidateSubscriber {
// @Inject()
// private validateManualJournalBranch: ManualJournalBranchesValidator;
// @Inject()
// private featuresManager: FeaturesManager;
// /**
// * Attaches events with handlers.
// */
// public attach = (bus) => {
// bus.subscribe(
// events.manualJournals.onCreating,
// this.validateBranchExistanceOnBillCreating
// );
// bus.subscribe(
// events.manualJournals.onEditing,
// this.validateBranchExistanceOnBillEditing
// );
// return bus;
// };
// /**
// * Validate branch existance on estimate creating.
// * @param {IManualJournalCreatingPayload} payload
// */
// private validateBranchExistanceOnBillCreating = async ({
// manualJournalDTO,
// tenantId,
// }: IManualJournalCreatingPayload) => {
// // Detarmines whether the multi-branches is accessible by tenant.
// const isAccessible = await this.featuresManager.accessible(
// tenantId,
// Features.BRANCHES
// );
// // Can't continue if the multi-branches feature is inactive.
// if (!isAccessible) return;
// // Validates the entries whether have branch id.
// await this.validateManualJournalBranch.validateEntriesHasBranchId(
// manualJournalDTO
// );
// };
// /**
// * Validate branch existance once estimate editing.
// * @param {ISaleEstimateEditingPayload} payload
// */
// private validateBranchExistanceOnBillEditing = async ({
// tenantId,
// manualJournalDTO,
// }: IManualJournalEditingPayload) => {
// // Detarmines whether the multi-branches is accessible by tenant.
// const isAccessible = await this.featuresManager.accessible(
// tenantId,
// Features.BRANCHES
// );
// // Can't continue if the multi-branches feature is inactive.
// if (!isAccessible) return;
// await this.validateManualJournalBranch.validateEntriesHasBranchId(
// manualJournalDTO
// );
// };
// }

View File

@@ -0,0 +1,56 @@
// import { Inject, Service } from 'typedi';
// import events from '@/subscribers/events';
// import {
// IBillPaymentCreatingPayload,
// IBillPaymentEditingPayload,
// } from '@/interfaces';
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
// @Service()
// export class PaymentMadeBranchValidateSubscriber {
// @Inject()
// private validateBranchExistance: ValidateBranchExistance;
// /**
// * Attaches events with handlers.
// */
// public attach = (bus) => {
// bus.subscribe(
// events.billPayment.onCreating,
// this.validateBranchExistanceOnPaymentCreating
// );
// bus.subscribe(
// events.billPayment.onEditing,
// this.validateBranchExistanceOnPaymentEditing
// );
// return bus;
// };
// /**
// * Validate branch existance on estimate creating.
// * @param {ISaleEstimateCreatedPayload} payload
// */
// private validateBranchExistanceOnPaymentCreating = async ({
// tenantId,
// billPaymentDTO,
// }: IBillPaymentCreatingPayload) => {
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
// tenantId,
// billPaymentDTO.branchId
// );
// };
// /**
// * Validate branch existance once estimate editing.
// * @param {ISaleEstimateEditingPayload} payload
// */
// private validateBranchExistanceOnPaymentEditing = async ({
// billPaymentDTO,
// tenantId,
// }: IBillPaymentEditingPayload) => {
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
// tenantId,
// billPaymentDTO.branchId
// );
// };
// }

View File

@@ -0,0 +1,56 @@
// import { Inject, Service } from 'typedi';
// import events from '@/subscribers/events';
// import {
// IPaymentReceivedCreatingPayload,
// IPaymentReceivedEditingPayload,
// } from '@/interfaces';
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
// @Service()
// export class PaymentReceiveBranchValidateSubscriber {
// @Inject()
// private validateBranchExistance: ValidateBranchExistance;
// /**
// * Attaches events with handlers.
// */
// public attach = (bus) => {
// bus.subscribe(
// events.paymentReceive.onCreating,
// this.validateBranchExistanceOnPaymentCreating
// );
// bus.subscribe(
// events.paymentReceive.onEditing,
// this.validateBranchExistanceOnPaymentEditing
// );
// return bus;
// };
// /**
// * Validate branch existance on estimate creating.
// * @param {IPaymentReceivedCreatingPayload} payload
// */
// private validateBranchExistanceOnPaymentCreating = async ({
// tenantId,
// paymentReceiveDTO,
// }: IPaymentReceivedCreatingPayload) => {
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
// tenantId,
// paymentReceiveDTO.branchId
// );
// };
// /**
// * Validate branch existance once estimate editing.
// * @param {IPaymentReceivedEditingPayload} payload
// */
// private validateBranchExistanceOnPaymentEditing = async ({
// paymentReceiveDTO,
// tenantId,
// }: IPaymentReceivedEditingPayload) => {
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
// tenantId,
// paymentReceiveDTO.branchId
// );
// };
// }

View File

@@ -0,0 +1,56 @@
// import { Inject, Service } from 'typedi';
// import events from '@/subscribers/events';
// import {
// ISaleEstimateCreatingPayload,
// ISaleEstimateEditingPayload,
// } from '@/interfaces';
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
// @Service()
// export class SaleEstimateBranchValidateSubscriber {
// @Inject()
// private validateBranchExistance: ValidateBranchExistance;
// /**
// * Attaches events with handlers.
// */
// public attach = (bus) => {
// bus.subscribe(
// events.saleEstimate.onCreating,
// this.validateBranchExistanceOnEstimateCreating
// );
// bus.subscribe(
// events.saleEstimate.onEditing,
// this.validateBranchExistanceOnEstimateEditing
// );
// return bus;
// };
// /**
// * Validate branch existance on estimate creating.
// * @param {ISaleEstimateCreatedPayload} payload
// */
// private validateBranchExistanceOnEstimateCreating = async ({
// tenantId,
// estimateDTO,
// }: ISaleEstimateCreatingPayload) => {
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
// tenantId,
// estimateDTO.branchId
// );
// };
// /**
// * Validate branch existance once estimate editing.
// * @param {ISaleEstimateEditingPayload} payload
// */
// private validateBranchExistanceOnEstimateEditing = async ({
// estimateDTO,
// tenantId,
// }: ISaleEstimateEditingPayload) => {
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
// tenantId,
// estimateDTO.branchId
// );
// };
// }

View File

@@ -0,0 +1,56 @@
// import { Inject, Service } from 'typedi';
// import events from '@/subscribers/events';
// import {
// ISaleReceiptCreatingPayload,
// ISaleReceiptEditingPayload,
// } from '@/interfaces';
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
// @Service()
// export class SaleReceiptBranchValidateSubscriber {
// @Inject()
// private validateBranchExistance: ValidateBranchExistance;
// /**
// * Attaches events with handlers.
// */
// public attach = (bus) => {
// bus.subscribe(
// events.saleReceipt.onCreating,
// this.validateBranchExistanceOnInvoiceCreating
// );
// bus.subscribe(
// events.saleReceipt.onEditing,
// this.validateBranchExistanceOnInvoiceEditing
// );
// return bus;
// };
// /**
// * Validate branch existance on estimate creating.
// * @param {ISaleReceiptCreatingPayload} payload
// */
// private validateBranchExistanceOnInvoiceCreating = async ({
// tenantId,
// saleReceiptDTO,
// }: ISaleReceiptCreatingPayload) => {
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
// tenantId,
// saleReceiptDTO.branchId
// );
// };
// /**
// * Validate branch existance once estimate editing.
// * @param {ISaleReceiptEditingPayload} payload
// */
// private validateBranchExistanceOnInvoiceEditing = async ({
// saleReceiptDTO,
// tenantId,
// }: ISaleReceiptEditingPayload) => {
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
// tenantId,
// saleReceiptDTO.branchId
// );
// };
// }

View File

@@ -0,0 +1,56 @@
// import { Inject, Service } from 'typedi';
// import events from '@/subscribers/events';
// import {
// IVendorCreditCreatingPayload,
// IVendorCreditEditingPayload,
// } from '@/interfaces';
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
// @Service()
// export class VendorCreditBranchValidateSubscriber {
// @Inject()
// private validateBranchExistance: ValidateBranchExistance;
// /**
// * Attaches events with handlers.
// */
// public attach = (bus) => {
// bus.subscribe(
// events.vendorCredit.onCreating,
// this.validateBranchExistanceOnCreditCreating
// );
// bus.subscribe(
// events.vendorCredit.onEditing,
// this.validateBranchExistanceOnCreditEditing
// );
// return bus;
// };
// /**
// * Validate branch existance on estimate creating.
// * @param {ISaleEstimateCreatedPayload} payload
// */
// private validateBranchExistanceOnCreditCreating = async ({
// tenantId,
// vendorCreditCreateDTO,
// }: IVendorCreditCreatingPayload) => {
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
// tenantId,
// vendorCreditCreateDTO.branchId
// );
// };
// /**
// * Validate branch existance once estimate editing.
// * @param {ISaleEstimateEditingPayload} payload
// */
// private validateBranchExistanceOnCreditEditing = async ({
// vendorCreditDTO,
// tenantId,
// }: IVendorCreditEditingPayload) => {
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
// tenantId,
// vendorCreditDTO.branchId
// );
// };
// }

View File

@@ -0,0 +1,35 @@
// import { Inject, Service } from 'typedi';
// import events from '@/subscribers/events';
// import { IRefundVendorCreditCreatingPayload } from '@/interfaces';
// import { ValidateBranchExistance } from '../../Integrations/ValidateBranchExistance';
// @Service()
// export class VendorCreditRefundBranchValidateSubscriber {
// @Inject()
// private validateBranchExistance: ValidateBranchExistance;
// /**
// * Attaches events with handlers.
// */
// public attach = (bus) => {
// bus.subscribe(
// events.vendorCredit.onRefundCreating,
// this.validateBranchExistanceOnCreditRefundCreating
// );
// return bus;
// };
// /**
// * Validate branch existance on refund credit note creating.
// * @param {IRefundVendorCreditCreatingPayload} payload
// */
// private validateBranchExistanceOnCreditRefundCreating = async ({
// tenantId,
// refundVendorCreditDTO,
// }: IRefundVendorCreditCreatingPayload) => {
// await this.validateBranchExistance.validateTransactionBranchWhenActive(
// tenantId,
// refundVendorCreditDTO.branchId
// );
// };
// }

View File

@@ -0,0 +1,15 @@
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';