mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
57 lines
1.7 KiB
TypeScript
57 lines
1.7 KiB
TypeScript
import { Container, Inject, Service } from 'typedi';
|
|
import { EventSubscriber, On } from 'event-dispatch';
|
|
import events from 'subscribers/events';
|
|
import TenancyService from 'services/Tenancy/TenancyService';
|
|
import VendorsService from 'services/Contacts/VendorsService';
|
|
|
|
@EventSubscriber()
|
|
export default class VendorsSubscriber {
|
|
logger: any;
|
|
tenancy: TenancyService;
|
|
vendorsService: VendorsService;
|
|
|
|
/**
|
|
* Constructor method.
|
|
*/
|
|
constructor() {
|
|
this.logger = Container.get('logger');
|
|
this.vendorsService = Container.get(VendorsService);
|
|
}
|
|
|
|
/**
|
|
* Writes the open balance journal entries once the vendor created.
|
|
*/
|
|
@On(events.vendors.onCreated)
|
|
async handleWriteOpeningBalanceEntries({ tenantId, vendorId, vendor, authorizedUser }) {
|
|
// Writes the vendor opening balance journal entries.
|
|
if (vendor.openingBalance) {
|
|
await this.vendorsService.writeVendorOpeningBalanceJournal(
|
|
tenantId,
|
|
vendor.id,
|
|
vendor.openingBalance,
|
|
vendor.openingBalanceAt,
|
|
authorizedUser.id
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Revert the opening balance journal entries once the vendor deleted.
|
|
*/
|
|
@On(events.vendors.onDeleted)
|
|
async handleRevertOpeningBalanceEntries({ tenantId, vendorId, authorizedUser }) {
|
|
await this.vendorsService.revertOpeningBalanceEntries(
|
|
tenantId, vendorId,
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Revert the opening balance journal entries once the vendors deleted in bulk.
|
|
*/
|
|
@On(events.vendors.onBulkDeleted)
|
|
async handleBulkRevertOpeningBalanceEntries({ tenantId, vendorsIds, authorizedUser }) {
|
|
await this.vendorsService.revertOpeningBalanceEntries(
|
|
tenantId, vendorsIds,
|
|
);
|
|
}
|
|
} |