mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 13:20:31 +00:00
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
29 lines
885 B
TypeScript
29 lines
885 B
TypeScript
import { Knex } from 'knex';
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
|
import { VendorCredit } from '@/modules/VendorCredit/models/VendorCredit';
|
|
|
|
@Injectable()
|
|
export class VendorCreditActivateBranches {
|
|
constructor(
|
|
@Inject(VendorCredit.name)
|
|
private readonly vendorCreditModel: TenantModelProxy<typeof VendorCredit>,
|
|
) {}
|
|
|
|
/**
|
|
* Updates all vendor credits transcations with the primary branch.
|
|
* @param {number} tenantId
|
|
* @param {number} primaryBranchId
|
|
* @returns {Promise<void>}
|
|
*/
|
|
public updateVendorCreditsWithBranch = async (
|
|
primaryBranchId: number,
|
|
trx?: Knex.Transaction,
|
|
) => {
|
|
// Updates the vendors credits with primary branch.
|
|
await this.vendorCreditModel()
|
|
.query(trx)
|
|
.update({ branchId: primaryBranchId });
|
|
};
|
|
}
|