mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
fix(server): wirte GL entries only when publish transaction
This commit is contained in:
@@ -4,6 +4,7 @@ import {
|
||||
IBillCreatedPayload,
|
||||
IBillEditedPayload,
|
||||
IBIllEventDeletedPayload,
|
||||
IBillOpenedPayload,
|
||||
} from '@/interfaces';
|
||||
import { BillInventoryTransactions } from '@/services/Purchases/Bills/BillInventoryTransactions';
|
||||
|
||||
@@ -20,6 +21,10 @@ export default class BillWriteInventoryTransactionsSubscriber {
|
||||
events.bill.onCreated,
|
||||
this.handleWritingInventoryTransactions
|
||||
);
|
||||
bus.subscribe(
|
||||
events.bill.onOpened,
|
||||
this.handleWritingInventoryTransactions
|
||||
);
|
||||
bus.subscribe(
|
||||
events.bill.onEdited,
|
||||
this.handleOverwritingInventoryTransactions
|
||||
@@ -32,19 +37,19 @@ export default class BillWriteInventoryTransactionsSubscriber {
|
||||
|
||||
/**
|
||||
* Handles writing the inventory transactions once bill created.
|
||||
* @param {IBillCreatedPayload | IBillOpenedPayload} payload -
|
||||
*/
|
||||
private handleWritingInventoryTransactions = async ({
|
||||
tenantId,
|
||||
billId,
|
||||
bill,
|
||||
trx,
|
||||
}: IBillCreatedPayload) => {
|
||||
}: IBillCreatedPayload | IBillOpenedPayload) => {
|
||||
// Can't continue if the bill is not opened yet.
|
||||
if (!bill.openedAt) return null;
|
||||
|
||||
await this.billsInventory.recordInventoryTransactions(
|
||||
tenantId,
|
||||
billId,
|
||||
bill.id,
|
||||
false,
|
||||
trx
|
||||
);
|
||||
@@ -52,6 +57,7 @@ export default class BillWriteInventoryTransactionsSubscriber {
|
||||
|
||||
/**
|
||||
* Handles the overwriting the inventory transactions once bill edited.
|
||||
* @param {IBillEditedPayload} payload -
|
||||
*/
|
||||
private handleOverwritingInventoryTransactions = async ({
|
||||
tenantId,
|
||||
@@ -72,6 +78,7 @@ export default class BillWriteInventoryTransactionsSubscriber {
|
||||
|
||||
/**
|
||||
* Handles the reverting the inventory transactions once the bill deleted.
|
||||
* @param {IBIllEventDeletedPayload} payload -
|
||||
*/
|
||||
private handleRevertInventoryTransactions = async ({
|
||||
tenantId,
|
||||
|
||||
@@ -19,7 +19,7 @@ export default class BillWriteGLEntriesSubscriber {
|
||||
/**
|
||||
* Attachs events with handles.
|
||||
*/
|
||||
attach(bus) {
|
||||
public attach(bus) {
|
||||
bus.subscribe(
|
||||
events.bill.onCreated,
|
||||
this.handlerWriteJournalEntriesOnCreate
|
||||
|
||||
@@ -37,7 +37,6 @@ export default class PaymentReceiveSyncInvoicesSubscriber {
|
||||
*/
|
||||
private handleInvoiceIncrementPaymentOnceCreated = async ({
|
||||
tenantId,
|
||||
paymentReceiveId,
|
||||
paymentReceive,
|
||||
trx,
|
||||
}: IPaymentReceiveCreatedPayload) => {
|
||||
|
||||
@@ -36,10 +36,8 @@ export default class PaymentReceivesWriteGLEntriesSubscriber {
|
||||
private handleWriteJournalEntriesOnceCreated = async ({
|
||||
tenantId,
|
||||
paymentReceiveId,
|
||||
paymentReceive,
|
||||
trx,
|
||||
}: IPaymentReceiveCreatedPayload) => {
|
||||
if (paymentReceive)
|
||||
await this.paymentReceiveGLEntries.writePaymentGLEntries(
|
||||
tenantId,
|
||||
paymentReceiveId,
|
||||
|
||||
@@ -36,6 +36,8 @@ export default class SaleInvoiceWriteGLEntriesSubscriber {
|
||||
|
||||
/**
|
||||
* Records journal entries of the non-inventory invoice.
|
||||
* @param {ISaleInvoiceCreatedPayload} payload -
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
private handleWriteJournalEntriesOnInvoiceCreated = async ({
|
||||
tenantId,
|
||||
@@ -55,6 +57,8 @@ export default class SaleInvoiceWriteGLEntriesSubscriber {
|
||||
|
||||
/**
|
||||
* Records journal entries of the non-inventory invoice.
|
||||
* @param {ISaleInvoiceEditedPayload} payload -
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
private handleRewriteJournalEntriesOnceInvoiceEdit = async ({
|
||||
tenantId,
|
||||
@@ -73,6 +77,8 @@ export default class SaleInvoiceWriteGLEntriesSubscriber {
|
||||
|
||||
/**
|
||||
* Handle reverting journal entries once sale invoice delete.
|
||||
* @param {ISaleInvoiceDeletePayload} payload -
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
private handleRevertingInvoiceJournalEntriesOnDelete = async ({
|
||||
tenantId,
|
||||
|
||||
Reference in New Issue
Block a user