mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +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 { BillGLEntries } from './BillGLEntries';
|
||||
|
||||
@@ -37,13 +38,12 @@ export class BillGLEntriesSubscriber {
|
||||
*/
|
||||
private handlerWriteJournalEntriesOnCreate = async ({
|
||||
tenantId,
|
||||
billId,
|
||||
bill,
|
||||
trx,
|
||||
}: IBillCreatedPayload) => {
|
||||
}: IBillCreatedPayload | IBillOpenedPayload) => {
|
||||
if (!bill.openedAt) return null;
|
||||
|
||||
await this.billGLEntries.writeBillGLEntries(tenantId, billId, trx);
|
||||
await this.billGLEntries.writeBillGLEntries(tenantId, bill.id, trx);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -50,10 +50,13 @@ export class OpenBill {
|
||||
oldBill,
|
||||
} as IBillOpeningPayload);
|
||||
|
||||
// Record the bill opened at on the storage.
|
||||
const bill = await Bill.query(trx).patchAndFetchById(billId, {
|
||||
openedAt: moment().toMySqlDateTime(),
|
||||
});
|
||||
// Save the bill opened at on the storage.
|
||||
const bill = await Bill.query(trx)
|
||||
.patchAndFetchById(billId, {
|
||||
openedAt: moment().toMySqlDateTime(),
|
||||
})
|
||||
.withGraphFetched('entries');
|
||||
|
||||
// Triggers `onBillCreating` event.
|
||||
await this.eventPublisher.emitAsync(events.bill.onOpened, {
|
||||
trx,
|
||||
|
||||
@@ -10,7 +10,7 @@ import VendorCreditInventoryTransactions from './VendorCreditInventoryTransactio
|
||||
@Service()
|
||||
export default class VendorCreditInventoryTransactionsSubscriber {
|
||||
@Inject()
|
||||
inventoryTransactions: VendorCreditInventoryTransactions;
|
||||
private inventoryTransactions: VendorCreditInventoryTransactions;
|
||||
|
||||
/**
|
||||
* Attaches events with handlers.
|
||||
@@ -21,6 +21,10 @@ export default class VendorCreditInventoryTransactionsSubscriber {
|
||||
events.vendorCredit.onCreated,
|
||||
this.writeInventoryTransactionsOnceCreated
|
||||
);
|
||||
bus.subscribe(
|
||||
events.vendorCredit.onOpened,
|
||||
this.writeInventoryTransactionsOnceCreated
|
||||
);
|
||||
bus.subscribe(
|
||||
events.vendorCredit.onEdited,
|
||||
this.rewriteInventroyTransactionsOnceEdited
|
||||
@@ -40,6 +44,9 @@ export default class VendorCreditInventoryTransactionsSubscriber {
|
||||
vendorCredit,
|
||||
trx,
|
||||
}: IVendorCreditCreatedPayload) => {
|
||||
// Can't continue if vendor credit is not opened.
|
||||
if (!vendorCredit.openedAt) return null;
|
||||
|
||||
await this.inventoryTransactions.createInventoryTransactions(
|
||||
tenantId,
|
||||
vendorCredit,
|
||||
@@ -57,6 +64,9 @@ export default class VendorCreditInventoryTransactionsSubscriber {
|
||||
vendorCredit,
|
||||
trx,
|
||||
}: IVendorCreditEditedPayload) => {
|
||||
// Can't continue if vendor credit is not opened.
|
||||
if (!vendorCredit.openedAt) return null;
|
||||
|
||||
await this.inventoryTransactions.editInventoryTransactions(
|
||||
tenantId,
|
||||
vendorCreditId,
|
||||
|
||||
Reference in New Issue
Block a user