Files
bigcapital/packages/server/src/modules/Branches/integrations/Purchases/PaymentMadeBranchesActivate.ts
Ahmed Bouhuolia 6af4be9c6c 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
2026-02-05 16:03:57 +02:00

26 lines
829 B
TypeScript

import { Knex } from 'knex';
import { Inject, Injectable } from '@nestjs/common';
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
import { BillPayment } from '@/modules/BillPayments/models/BillPayment';
@Injectable()
export class BillPaymentsActivateBranches {
constructor(
@Inject(BillPayment.name)
private readonly billPaymentModel: TenantModelProxy<typeof BillPayment>,
) {}
/**
* Updates all bills payments transcations with the primary branch.
* @param {number} primaryBranchId
* @returns {Promise<void>}
*/
public updateBillPaymentsWithBranch = async (
primaryBranchId: number,
trx?: Knex.Transaction
) => {
// Updates the bill payments with primary branch.
await this.billPaymentModel().query(trx).update({ branchId: primaryBranchId });
};
}