mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
refactoring: bills service.
refactoring: bills payments made service.
This commit is contained in:
46
server/src/subscribers/customers.ts
Normal file
46
server/src/subscribers/customers.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { Container, Inject, Service } from 'typedi';
|
||||
import { EventSubscriber, On } from 'event-dispatch';
|
||||
import events from 'subscribers/events';
|
||||
import TenancyService from 'services/Tenancy/TenancyService';
|
||||
import CustomersService from 'services/Contacts/CustomersService';
|
||||
|
||||
@EventSubscriber()
|
||||
export default class CustomersSubscriber {
|
||||
logger: any;
|
||||
tenancy: TenancyService;
|
||||
customersService: CustomersService;
|
||||
|
||||
constructor() {
|
||||
this.logger = Container.get('logger');
|
||||
this.customersService = Container.get(CustomersService);
|
||||
}
|
||||
|
||||
@On(events.customers.onCreated)
|
||||
async handleWriteOpenBalanceEntries({ tenantId, customerId, customer }) {
|
||||
|
||||
// Writes the customer opening balance journal entries.
|
||||
if (customer.openingBalance) {
|
||||
await this.customersService.writeCustomerOpeningBalanceJournal(
|
||||
tenantId,
|
||||
customer.id,
|
||||
customer.openingBalance,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@On(events.customers.onDeleted)
|
||||
async handleRevertOpeningBalanceEntries({ tenantId, customerId }) {
|
||||
|
||||
await this.customersService.revertOpeningBalanceEntries(
|
||||
tenantId, customerId,
|
||||
);
|
||||
}
|
||||
|
||||
@On(events.customers.onBulkDeleted)
|
||||
async handleBulkRevertOpeningBalanceEntries({ tenantId, customersIds }) {
|
||||
|
||||
await this.customersService.revertOpeningBalanceEntries(
|
||||
tenantId, customersIds,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user