fix(server): wirte GL entries only when publish transaction

This commit is contained in:
Ahmed Bouhuolia
2023-08-17 21:49:07 +02:00
parent 5b2be2ac19
commit 0fcee0eaa7
13 changed files with 65 additions and 43 deletions

View File

@@ -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,

View File

@@ -19,7 +19,7 @@ export default class BillWriteGLEntriesSubscriber {
/**
* Attachs events with handles.
*/
attach(bus) {
public attach(bus) {
bus.subscribe(
events.bill.onCreated,
this.handlerWriteJournalEntriesOnCreate

View File

@@ -37,7 +37,6 @@ export default class PaymentReceiveSyncInvoicesSubscriber {
*/
private handleInvoiceIncrementPaymentOnceCreated = async ({
tenantId,
paymentReceiveId,
paymentReceive,
trx,
}: IPaymentReceiveCreatedPayload) => {

View File

@@ -36,10 +36,8 @@ export default class PaymentReceivesWriteGLEntriesSubscriber {
private handleWriteJournalEntriesOnceCreated = async ({
tenantId,
paymentReceiveId,
paymentReceive,
trx,
}: IPaymentReceiveCreatedPayload) => {
if (paymentReceive)
await this.paymentReceiveGLEntries.writePaymentGLEntries(
tenantId,
paymentReceiveId,

View File

@@ -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,