mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
fix: writing inventory transactions on invoice and bill created.
This commit is contained in:
@@ -108,4 +108,41 @@ export default class BillSubscriber {
|
||||
oldBill.vendorId
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles writing the inventory transactions once bill created.
|
||||
*/
|
||||
@On(events.bill.onCreated)
|
||||
async handleWritingInventoryTransactions({ tenantId, bill }) {
|
||||
this.logger.info('[bill] writing the inventory transactions', { tenantId });
|
||||
this.billsService.recordInventoryTransactions(
|
||||
tenantId,
|
||||
bill,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the overwriting the inventory transactions once bill edited.
|
||||
*/
|
||||
@On(events.bill.onEdited)
|
||||
async handleOverwritingInventoryTransactions({ tenantId, bill }) {
|
||||
this.logger.info('[bill] overwriting the inventory transactions.', { tenantId });
|
||||
this.billsService.recordInventoryTransactions(
|
||||
tenantId,
|
||||
bill,
|
||||
true,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the reverting the inventory transactions once the bill deleted.
|
||||
*/
|
||||
@On(events.bill.onDeleted)
|
||||
async handleRevertInventoryTransactions({ tenantId, billId }) {
|
||||
this.logger.info('[bill] reverting the bill inventory transactions', { tenantId, billId });
|
||||
this.billsService.revertInventoryTransactions(
|
||||
tenantId,
|
||||
billId,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import events from 'subscribers/events';
|
||||
import TenancyService from 'services/Tenancy/TenancyService';
|
||||
import SettingsService from 'services/Settings/SettingsService';
|
||||
import SaleEstimateService from 'services/Sales/SalesEstimate';
|
||||
import SaleInvoicesService from 'services/Sales/SalesInvoices';
|
||||
|
||||
@EventSubscriber()
|
||||
export default class SaleInvoiceSubscriber {
|
||||
@@ -11,12 +12,14 @@ export default class SaleInvoiceSubscriber {
|
||||
tenancy: TenancyService;
|
||||
settingsService: SettingsService;
|
||||
saleEstimatesService: SaleEstimateService;
|
||||
saleInvoicesService: SaleInvoicesService;
|
||||
|
||||
constructor() {
|
||||
this.logger = Container.get('logger');
|
||||
this.tenancy = Container.get(TenancyService);
|
||||
this.settingsService = Container.get(SettingsService);
|
||||
this.saleEstimatesService = Container.get(SaleEstimateService);
|
||||
this.saleInvoicesService = Container.get(SaleInvoicesService);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,4 +117,32 @@ export default class SaleInvoiceSubscriber {
|
||||
group: 'sales_invoices',
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the writing inventory transactions once the invoice created.
|
||||
*/
|
||||
@On(events.saleInvoice.onCreated)
|
||||
public async handleWritingInventoryTransactions({ tenantId, saleInvoice }) {
|
||||
this.logger.info('[sale_invoice] trying to write inventory transactions.', {
|
||||
tenantId,
|
||||
});
|
||||
await this.saleInvoicesService.recordInventoryTranscactions(
|
||||
tenantId,
|
||||
saleInvoice,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles deleting the inventory transactions once the invoice deleted.
|
||||
*/
|
||||
@On(events.saleInvoice.onDeleted)
|
||||
public async handleDeletingInventoryTransactions({ tenantId, saleInvoiceId }) {
|
||||
this.logger.info('[sale_invoice] trying to revert inventory transactions.', {
|
||||
tenantId, saleInvoiceId,
|
||||
});
|
||||
await this.saleInvoicesService.revertInventoryTransactions(
|
||||
tenantId,
|
||||
saleInvoiceId,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user