fix(server): branches activation not marking bills and payments with primary branch
When activating the multi-branches feature, existing bills, vendor credits, and bill payments were not being marked with the default primary branch. Changes: - Add missing @Inject decorators to BillActivateBranches, VendorCreditActivateBranches, and BillPaymentsActivateBranches services - Create BillBranchesActivateSubscriber to listen to onActivated event - Create VendorCreditBranchesActivateSubscriber to listen to onActivated event - Register BillPaymentsActivateBranches and PaymentMadeActivateBranchesSubscriber in BranchesModule - Add branch object to BillResponseDto for API responses - Add branch to BillTransformer includeAttributes Fixes: #935
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
import { ApiProperty } from '@nestjs/swagger';
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
import { Type } from 'class-transformer';
|
||||||
import { ItemEntryDto } from '@/modules/TransactionItemEntry/dto/ItemEntry.dto';
|
import { ItemEntryDto } from '@/modules/TransactionItemEntry/dto/ItemEntry.dto';
|
||||||
import { AttachmentLinkDto } from '@/modules/Attachments/dtos/Attachment.dto';
|
import { AttachmentLinkDto } from '@/modules/Attachments/dtos/Attachment.dto';
|
||||||
|
import { BranchResponseDto } from '@/modules/Branches/dtos/BranchResponse.dto';
|
||||||
import { DiscountType } from '@/common/types/Discount';
|
import { DiscountType } from '@/common/types/Discount';
|
||||||
|
|
||||||
export class BillResponseDto {
|
export class BillResponseDto {
|
||||||
@@ -89,6 +91,14 @@ export class BillResponseDto {
|
|||||||
})
|
})
|
||||||
branchId?: number;
|
branchId?: number;
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'Branch details',
|
||||||
|
type: () => BranchResponseDto,
|
||||||
|
required: false,
|
||||||
|
})
|
||||||
|
@Type(() => BranchResponseDto)
|
||||||
|
branch?: BranchResponseDto;
|
||||||
|
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
description: 'The ID of the project',
|
description: 'The ID of the project',
|
||||||
example: 301,
|
example: 301,
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ export class BillTransformer extends Transformer {
|
|||||||
'taxes',
|
'taxes',
|
||||||
'entries',
|
'entries',
|
||||||
'attachments',
|
'attachments',
|
||||||
|
'branch',
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,12 @@ import { ValidateBranchExistance } from './integrations/ValidateBranchExistance'
|
|||||||
import { ManualJournalBranchesValidator } from './integrations/ManualJournals/ManualJournalsBranchesValidator';
|
import { ManualJournalBranchesValidator } from './integrations/ManualJournals/ManualJournalsBranchesValidator';
|
||||||
import { CashflowTransactionsActivateBranches } from './integrations/Cashflow/CashflowActivateBranches';
|
import { CashflowTransactionsActivateBranches } from './integrations/Cashflow/CashflowActivateBranches';
|
||||||
import { ExpensesActivateBranches } from './integrations/Expense/ExpensesActivateBranches';
|
import { ExpensesActivateBranches } from './integrations/Expense/ExpensesActivateBranches';
|
||||||
|
import { BillActivateBranches } from './integrations/Purchases/BillBranchesActivate';
|
||||||
|
import { VendorCreditActivateBranches } from './integrations/Purchases/VendorCreditBranchesActivate';
|
||||||
|
import { BillPaymentsActivateBranches } from './integrations/Purchases/PaymentMadeBranchesActivate';
|
||||||
|
import { BillBranchesActivateSubscriber } from './subscribers/Activate/BillBranchesActivateSubscriber';
|
||||||
|
import { VendorCreditBranchesActivateSubscriber } from './subscribers/Activate/VendorCreditBranchesActivateSubscriber';
|
||||||
|
import { PaymentMadeActivateBranchesSubscriber } from './subscribers/Activate/PaymentMadeBranchesActivateSubscriber';
|
||||||
import { FeaturesModule } from '../Features/Features.module';
|
import { FeaturesModule } from '../Features/Features.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
@@ -66,7 +72,13 @@ import { FeaturesModule } from '../Features/Features.module';
|
|||||||
ValidateBranchExistance,
|
ValidateBranchExistance,
|
||||||
ManualJournalBranchesValidator,
|
ManualJournalBranchesValidator,
|
||||||
CashflowTransactionsActivateBranches,
|
CashflowTransactionsActivateBranches,
|
||||||
ExpensesActivateBranches
|
ExpensesActivateBranches,
|
||||||
|
BillActivateBranches,
|
||||||
|
VendorCreditActivateBranches,
|
||||||
|
BillPaymentsActivateBranches,
|
||||||
|
BillBranchesActivateSubscriber,
|
||||||
|
VendorCreditBranchesActivateSubscriber,
|
||||||
|
PaymentMadeActivateBranchesSubscriber
|
||||||
],
|
],
|
||||||
exports: [
|
exports: [
|
||||||
BranchesSettingsService,
|
BranchesSettingsService,
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
import { Knex } from 'knex';
|
import { Knex } from 'knex';
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||||
import { Bill } from '@/modules/Bills/models/Bill';
|
import { Bill } from '@/modules/Bills/models/Bill';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class BillActivateBranches {
|
export class BillActivateBranches {
|
||||||
constructor(private readonly billModel: TenantModelProxy<typeof Bill>) {}
|
constructor(
|
||||||
|
@Inject(Bill.name)
|
||||||
|
private readonly billModel: TenantModelProxy<typeof Bill>,
|
||||||
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates all bills transactions with the primary branch.
|
* Updates all bills transactions with the primary branch.
|
||||||
@@ -17,7 +20,7 @@ export class BillActivateBranches {
|
|||||||
primaryBranchId: number,
|
primaryBranchId: number,
|
||||||
trx?: Knex.Transaction,
|
trx?: Knex.Transaction,
|
||||||
) => {
|
) => {
|
||||||
// Updates the sale invoice with primary branch.
|
// Updates the bills with primary branch.
|
||||||
await Bill.query(trx).update({ branchId: primaryBranchId });
|
await this.billModel().query(trx).update({ branchId: primaryBranchId });
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
import { Knex } from 'knex';
|
import { Knex } from 'knex';
|
||||||
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||||
import { BillPayment } from '@/modules/BillPayments/models/BillPayment';
|
import { BillPayment } from '@/modules/BillPayments/models/BillPayment';
|
||||||
import { Injectable } from '@nestjs/common';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class BillPaymentsActivateBranches {
|
export class BillPaymentsActivateBranches {
|
||||||
constructor(
|
constructor(
|
||||||
|
@Inject(BillPayment.name)
|
||||||
private readonly billPaymentModel: TenantModelProxy<typeof BillPayment>,
|
private readonly billPaymentModel: TenantModelProxy<typeof BillPayment>,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
import { Knex } from 'knex';
|
import { Knex } from 'knex';
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||||
import { VendorCredit } from '@/modules/VendorCredit/models/VendorCredit';
|
import { VendorCredit } from '@/modules/VendorCredit/models/VendorCredit';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class VendorCreditActivateBranches {
|
export class VendorCreditActivateBranches {
|
||||||
constructor(
|
constructor(
|
||||||
|
@Inject(VendorCredit.name)
|
||||||
private readonly vendorCreditModel: TenantModelProxy<typeof VendorCredit>,
|
private readonly vendorCreditModel: TenantModelProxy<typeof VendorCredit>,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import { IBranchesActivatedPayload } from '../../Branches.types';
|
||||||
|
import { events } from '@/common/events/events';
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { BillActivateBranches } from '../../integrations/Purchases/BillBranchesActivate';
|
||||||
|
import { OnEvent } from '@nestjs/event-emitter';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class BillBranchesActivateSubscriber {
|
||||||
|
constructor(
|
||||||
|
private readonly billActivateBranches: BillActivateBranches,
|
||||||
|
) { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates bills transactions with the primary branch once
|
||||||
|
* the multi-branches is activated.
|
||||||
|
* @param {IBranchesActivatedPayload}
|
||||||
|
*/
|
||||||
|
@OnEvent(events.branch.onActivated)
|
||||||
|
async updateBillsWithBranchOnActivated({
|
||||||
|
primaryBranch,
|
||||||
|
trx,
|
||||||
|
}: IBranchesActivatedPayload) {
|
||||||
|
await this.billActivateBranches.updateBillsWithBranch(
|
||||||
|
primaryBranch.id,
|
||||||
|
trx,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import { IBranchesActivatedPayload } from '../../Branches.types';
|
||||||
|
import { events } from '@/common/events/events';
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { VendorCreditActivateBranches } from '../../integrations/Purchases/VendorCreditBranchesActivate';
|
||||||
|
import { OnEvent } from '@nestjs/event-emitter';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class VendorCreditBranchesActivateSubscriber {
|
||||||
|
constructor(
|
||||||
|
private readonly vendorCreditActivateBranches: VendorCreditActivateBranches,
|
||||||
|
) { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates vendor credits transactions with the primary branch once
|
||||||
|
* the multi-branches is activated.
|
||||||
|
* @param {IBranchesActivatedPayload}
|
||||||
|
*/
|
||||||
|
@OnEvent(events.branch.onActivated)
|
||||||
|
async updateVendorCreditsWithBranchOnActivated({
|
||||||
|
primaryBranch,
|
||||||
|
trx,
|
||||||
|
}: IBranchesActivatedPayload) {
|
||||||
|
await this.vendorCreditActivateBranches.updateVendorCreditsWithBranch(
|
||||||
|
primaryBranch.id,
|
||||||
|
trx,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user