mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 13:20:31 +00:00
refactor: settings module to Nestjs
This commit is contained in:
@@ -0,0 +1,261 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { FinancialTransactionLocking } from '../guards/FinancialTransactionLockingGuard';
|
||||
import {
|
||||
IManualJournalCreatingPayload,
|
||||
IManualJournalEditingPayload,
|
||||
IManualJournalPublishingPayload,
|
||||
} from '@/modules/ManualJournals/types/ManualJournals.types';
|
||||
import {
|
||||
IExpenseCreatingPayload,
|
||||
IExpenseDeletingPayload,
|
||||
IExpenseEventEditingPayload,
|
||||
IExpensePublishingPayload,
|
||||
} from '@/modules/Expenses/Expenses.types';
|
||||
import {
|
||||
ICommandCashflowCreatingPayload,
|
||||
ICommandCashflowDeletingPayload,
|
||||
} from '@/modules/BankingTransactions/types/BankingTransactions.types';
|
||||
import { events } from '@/common/events/events';
|
||||
|
||||
@Injectable()
|
||||
export class FinancialTransactionLockingGuardSubscriber {
|
||||
constructor(
|
||||
public readonly financialTransactionsLocking: FinancialTransactionLocking,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* ---------------------------------------------
|
||||
* - MANUAL JOURNALS SERVICE.
|
||||
* ---------------------------------------------
|
||||
*/
|
||||
/**
|
||||
* Transaction locking guard on manual journal creating.
|
||||
* @param {IManualJournalCreatingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.manualJournals.onCreating)
|
||||
public async transactionsLockingGuardOnManualJournalCreating({
|
||||
manualJournalDTO,
|
||||
}: IManualJournalCreatingPayload) {
|
||||
// Can't continue if the new journal is not published yet.
|
||||
if (!manualJournalDTO.publish) return;
|
||||
|
||||
await this.financialTransactionsLocking.transactionLockingGuard(
|
||||
manualJournalDTO.date,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transactions locking guard on manual journal deleting.
|
||||
* @param {IManualJournalEditingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.manualJournals.onDeleting)
|
||||
public async transactionsLockingGuardOnManualJournalDeleting({
|
||||
oldManualJournal,
|
||||
}: IManualJournalEditingPayload) {
|
||||
// Can't continue if the old journal is not published.
|
||||
if (!oldManualJournal.isPublished) return;
|
||||
|
||||
await this.financialTransactionsLocking.transactionLockingGuard(
|
||||
oldManualJournal.date,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transactions locking guard on manual journal editing.
|
||||
* @param {IManualJournalDeletingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.manualJournals.onEditing)
|
||||
public async transactionsLockingGuardOnManualJournalEditing({
|
||||
oldManualJournal,
|
||||
manualJournalDTO,
|
||||
}: IManualJournalEditingPayload) {
|
||||
// Can't continue if the old and new journal are not published.
|
||||
if (!oldManualJournal.isPublished && !manualJournalDTO.publish) return;
|
||||
|
||||
// Validate the old journal date.
|
||||
await this.financialTransactionsLocking.transactionLockingGuard(
|
||||
oldManualJournal.date,
|
||||
);
|
||||
// Validate the new journal date.
|
||||
await this.financialTransactionsLocking.transactionLockingGuard(
|
||||
manualJournalDTO.date,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transactions locking guard on manual journal publishing.
|
||||
* @param {IManualJournalPublishingPayload}
|
||||
*/
|
||||
@OnEvent(events.manualJournals.onPublishing)
|
||||
public async transactionsLockingGuardOnManualJournalPublishing({
|
||||
oldManualJournal,
|
||||
}: IManualJournalPublishingPayload) {
|
||||
await this.financialTransactionsLocking.transactionLockingGuard(
|
||||
oldManualJournal.date,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* ---------------------------------------------
|
||||
* - EXPENSES SERVICE.
|
||||
* ---------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Transactions locking guard on expense creating.
|
||||
* @param {IExpenseCreatingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.expenses.onCreating)
|
||||
public async transactionsLockingGuardOnExpenseCreating({
|
||||
expenseDTO,
|
||||
}: IExpenseCreatingPayload) {
|
||||
// Can't continue if the new expense is not published yet.
|
||||
if (!expenseDTO.publish) return;
|
||||
|
||||
await this.financialTransactionsLocking.transactionLockingGuard(
|
||||
expenseDTO.paymentDate,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transactions locking guard on expense deleting.
|
||||
* @param {IExpenseDeletingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.expenses.onDeleting)
|
||||
public async transactionsLockingGuardOnExpenseDeleting({
|
||||
oldExpense,
|
||||
}: IExpenseDeletingPayload) {
|
||||
// Can't continue if expense transaction is not published.
|
||||
if (!oldExpense.isPublished) return;
|
||||
|
||||
await this.financialTransactionsLocking.transactionLockingGuard(
|
||||
oldExpense.paymentDate,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transactions locking guard on expense editing.
|
||||
* @param {IExpenseEventEditingPayload}
|
||||
*/
|
||||
@OnEvent(events.expenses.onEditing)
|
||||
public async transactionsLockingGuardOnExpenseEditing({
|
||||
oldExpense,
|
||||
expenseDTO,
|
||||
}: IExpenseEventEditingPayload) {
|
||||
// Can't continue if the old and new expense is not published.
|
||||
if (!oldExpense.isPublished && !expenseDTO.publish) return;
|
||||
|
||||
// Validate the old expense date.
|
||||
await this.financialTransactionsLocking.transactionLockingGuard(
|
||||
oldExpense.paymentDate,
|
||||
);
|
||||
// Validate the new expense date.
|
||||
await this.financialTransactionsLocking.transactionLockingGuard(
|
||||
expenseDTO.paymentDate,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transactions locking guard on expense publishing.
|
||||
* @param {IExpensePublishingPayload} payload -
|
||||
*/
|
||||
@OnEvent(events.expenses.onPublishing)
|
||||
public async transactionsLockingGuardOnExpensePublishing({
|
||||
oldExpense,
|
||||
}: IExpensePublishingPayload) {
|
||||
await this.financialTransactionsLocking.transactionLockingGuard(
|
||||
oldExpense.paymentDate,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* ---------------------------------------------
|
||||
* - CASHFLOW SERVICE.
|
||||
* ---------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Transactions locking guard on cashflow transaction creating.
|
||||
* @param {ICommandCashflowCreatingPayload}
|
||||
*/
|
||||
@OnEvent(events.cashflow.onTransactionCreating)
|
||||
public async transactionsLockingGuardOnCashflowTransactionCreating({
|
||||
newTransactionDTO,
|
||||
}: ICommandCashflowCreatingPayload) {
|
||||
if (!newTransactionDTO.publish) return;
|
||||
|
||||
await this.financialTransactionsLocking.transactionLockingGuard(
|
||||
newTransactionDTO.date,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transactions locking guard on cashflow transaction deleting.
|
||||
* @param {ICommandCashflowDeletingPayload}
|
||||
*/
|
||||
@OnEvent(events.cashflow.onTransactionDeleting)
|
||||
public async transactionsLockingGuardOnCashflowTransactionDeleting({
|
||||
oldCashflowTransaction,
|
||||
}: ICommandCashflowDeletingPayload) {
|
||||
// Can't continue if the cashflow transaction is not published.
|
||||
if (!oldCashflowTransaction.isPublished) return;
|
||||
|
||||
await this.financialTransactionsLocking.transactionLockingGuard(
|
||||
oldCashflowTransaction.date,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* ---------------------------------------------
|
||||
* - INVENTORY ADJUSTMENT SERVICE.
|
||||
* ---------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Transactions locking guard on inventory adjustment creating.
|
||||
* @param {IInventoryAdjustmentCreatingPayload} payload -
|
||||
*/
|
||||
// @OnEvent(events.inventoryAdjustment.onQuickCreating)
|
||||
// public async transactionsLockingGuardOnInventoryAdjCreating({
|
||||
// tenantId,
|
||||
// quickAdjustmentDTO,
|
||||
// }: IInventoryAdjustmentCreatingPayload) {
|
||||
// // Can't locking if the new adjustment is not published yet.
|
||||
// if (!quickAdjustmentDTO.publish) return;
|
||||
|
||||
// await this.financialTransactionsLocking.transactionLockingGuard(
|
||||
// tenantId,
|
||||
// quickAdjustmentDTO.date
|
||||
// );
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Transaction locking guard on inventory adjustment deleting.
|
||||
// * @param {IInventoryAdjustmentDeletingPayload} payload
|
||||
// */
|
||||
// @OnEvent(events.inventoryAdjustment.onDeleting)
|
||||
// public async transactionsLockingGuardOnInventoryAdjDeleting({
|
||||
// oldInventoryAdjustment,
|
||||
// }: IInventoryAdjustmentDeletingPayload) {
|
||||
// // Can't locking if the adjustment is published yet.
|
||||
// if (!oldInventoryAdjustment.isPublished) return;
|
||||
|
||||
// await this.financialTransactionsLocking.transactionLockingGuard(
|
||||
// oldInventoryAdjustment.date
|
||||
// );
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Transaction locking guard on inventory adjustment publishing.
|
||||
// * @param {IInventoryAdjustmentPublishingPayload} payload
|
||||
// */
|
||||
// @OnEvent(events.inventoryAdjustment.onPublishing)
|
||||
// public async transactionsLockingGuardOnInventoryAdjPublishing({
|
||||
// oldInventoryAdjustment,
|
||||
// }: IInventoryAdjustmentPublishingPayload) {
|
||||
// await this.financialTransactionsLocking.transactionLockingGuard(
|
||||
// oldInventoryAdjustment.date
|
||||
// );
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { events } from '@/common/events/events';
|
||||
import {
|
||||
IRefundVendorCreditCreatingPayload,
|
||||
IRefundVendorCreditDeletingPayload,
|
||||
} from '@/modules/VendorCreditsRefund/types/VendorCreditRefund.types';
|
||||
import {
|
||||
IVendorCreditCreatingPayload,
|
||||
IVendorCreditDeletingPayload,
|
||||
IVendorCreditEditingPayload,
|
||||
} from '@/modules/VendorCredit/types/VendorCredit.types';
|
||||
import {
|
||||
IBillCreatingPayload,
|
||||
IBillEditingPayload,
|
||||
IBillEventDeletingPayload,
|
||||
} from '@/modules/Bills/Bills.types';
|
||||
import {
|
||||
IBillPaymentCreatingPayload,
|
||||
IBillPaymentEditingPayload,
|
||||
} from '@/modules/BillPayments/types/BillPayments.types';
|
||||
import { IBillPaymentDeletingPayload } from '@/modules/BillPayments/types/BillPayments.types';
|
||||
import { PurchasesTransactionLockingGuard } from '../guards/PurchasesTransactionLockingGuard';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
|
||||
@Injectable()
|
||||
export class PurchasesTransactionLockingGuardSubscriber {
|
||||
constructor(
|
||||
public readonly purchasesTransactionsLocking: PurchasesTransactionLockingGuard,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* ---------------------------------------------
|
||||
* PAYMENT MADES.
|
||||
* ---------------------------------------------
|
||||
*/
|
||||
/**
|
||||
* Transaction locking guard on payment editing.
|
||||
* @param {IBillPaymentEditingPayload}
|
||||
*/
|
||||
@OnEvent(events.billPayment.onEditing)
|
||||
public async transactionLockingGuardOnPaymentEditing({
|
||||
oldBillPayment,
|
||||
billPaymentDTO,
|
||||
}: IBillPaymentEditingPayload) {
|
||||
// Validate old payment date.
|
||||
await this.purchasesTransactionsLocking.transactionLockingGuard(
|
||||
oldBillPayment.paymentDate,
|
||||
);
|
||||
// Validate the new payment date.
|
||||
await this.purchasesTransactionsLocking.transactionLockingGuard(
|
||||
billPaymentDTO.paymentDate,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transaction locking guard on payment creating.
|
||||
* @param {IBillPaymentCreatingPayload}
|
||||
*/
|
||||
@OnEvent(events.billPayment.onCreating)
|
||||
public async transactionLockingGuardOnPaymentCreating({
|
||||
billPaymentDTO,
|
||||
}: IBillPaymentCreatingPayload) {
|
||||
await this.purchasesTransactionsLocking.transactionLockingGuard(
|
||||
billPaymentDTO.paymentDate,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transaction locking guard on payment deleting.
|
||||
* @param {IBillPaymentDeletingPayload} payload -
|
||||
*/
|
||||
@OnEvent(events.billPayment.onDeleting)
|
||||
public async transactionLockingGuardOnPaymentDeleting({
|
||||
oldBillPayment,
|
||||
}: IBillPaymentDeletingPayload) {
|
||||
await this.purchasesTransactionsLocking.transactionLockingGuard(
|
||||
oldBillPayment.paymentDate,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* ---------------------------------------------
|
||||
* BILLS.
|
||||
* ---------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Transaction locking guard on bill creating.
|
||||
* @param {IBillCreatingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.bill.onCreating)
|
||||
public async transactionLockingGuardOnBillCreating({
|
||||
billDTO,
|
||||
}: IBillCreatingPayload) {
|
||||
// Can't continue if the new bill is not published.
|
||||
if (!billDTO.open) return;
|
||||
|
||||
await this.purchasesTransactionsLocking.transactionLockingGuard(
|
||||
billDTO.billDate,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transaction locking guard on bill editing.
|
||||
* @param {IBillEditingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.bill.onEditing)
|
||||
public async transactionLockingGuardOnBillEditing({
|
||||
oldBill,
|
||||
billDTO,
|
||||
}: IBillEditingPayload) {
|
||||
// Can't continue if the old and new bill are not published.
|
||||
if (!oldBill.isOpen && !billDTO.open) return;
|
||||
|
||||
// Validate the old bill date.
|
||||
await this.purchasesTransactionsLocking.transactionLockingGuard(
|
||||
oldBill.billDate,
|
||||
);
|
||||
// Validate the new bill date.
|
||||
await this.purchasesTransactionsLocking.transactionLockingGuard(
|
||||
billDTO.billDate,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transaction locking guard on bill deleting.
|
||||
* @param {IBillEventDeletingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.bill.onDeleting)
|
||||
public async transactionLockingGuardOnBillDeleting({
|
||||
oldBill,
|
||||
}: IBillEventDeletingPayload) {
|
||||
// Can't continue if the old bill is not published.
|
||||
if (!oldBill.isOpen) return;
|
||||
|
||||
await this.purchasesTransactionsLocking.transactionLockingGuard(
|
||||
oldBill.billDate,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* ---------------------------------------------
|
||||
* VENDOR CREDITS.
|
||||
* ---------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Transaction locking guard on vendor credit creating.
|
||||
* @param {IVendorCreditCreatingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.vendorCredit.onCreating)
|
||||
public async transactionLockingGuardOnVendorCreditCreating({
|
||||
vendorCreditCreateDTO,
|
||||
}: IVendorCreditCreatingPayload) {
|
||||
// Can't continue if the new vendor credit is not published.
|
||||
if (!vendorCreditCreateDTO.open) return;
|
||||
|
||||
await this.purchasesTransactionsLocking.transactionLockingGuard(
|
||||
vendorCreditCreateDTO.vendorCreditDate,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transaction locking guard on vendor credit deleting.
|
||||
* @param {IVendorCreditDeletingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.vendorCredit.onDeleting)
|
||||
public async transactionLockingGuardOnVendorCreditDeleting({
|
||||
oldVendorCredit,
|
||||
}: IVendorCreditDeletingPayload) {
|
||||
// Can't continue if the old vendor credit is not open.
|
||||
if (!oldVendorCredit.isOpen) return;
|
||||
|
||||
await this.purchasesTransactionsLocking.transactionLockingGuard(
|
||||
oldVendorCredit.vendorCreditDate,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transaction locking guard on vendor credit editing.
|
||||
* @param {IVendorCreditEditingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.vendorCredit.onEditing)
|
||||
public async transactionLockingGuardOnVendorCreditEditing({
|
||||
oldVendorCredit,
|
||||
vendorCreditDTO,
|
||||
}: IVendorCreditEditingPayload) {
|
||||
// Can't continue if the old and new vendor credit are not published.
|
||||
if (!oldVendorCredit.isPublished && !vendorCreditDTO.open) return;
|
||||
|
||||
// Validate the old credit date.
|
||||
await this.purchasesTransactionsLocking.transactionLockingGuard(
|
||||
oldVendorCredit.vendorCreditDate,
|
||||
);
|
||||
// Validate the new credit date.
|
||||
await this.purchasesTransactionsLocking.transactionLockingGuard(
|
||||
vendorCreditDTO.vendorCreditDate,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transaction locking guard on refund vendor credit creating.
|
||||
* @param {IRefundVendorCreditCreatingPayload} payload -
|
||||
*/
|
||||
@OnEvent(events.vendorCredit.onRefundCreating)
|
||||
public async transactionLockingGuardOnRefundVendorCredit({
|
||||
refundVendorCreditDTO,
|
||||
}: IRefundVendorCreditCreatingPayload) {
|
||||
await this.purchasesTransactionsLocking.transactionLockingGuard(
|
||||
refundVendorCreditDTO.date,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transaction locking guard on refund vendor credit deleting.
|
||||
* @param {IRefundVendorCreditDeletingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.vendorCredit.onRefundDeleting)
|
||||
public async transactionLockingGuardOnRefundCreditDeleting({
|
||||
oldRefundCredit,
|
||||
}: IRefundVendorCreditDeletingPayload) {
|
||||
await this.purchasesTransactionsLocking.transactionLockingGuard(
|
||||
oldRefundCredit.date,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,387 @@
|
||||
import { events } from '@/common/events/events';
|
||||
import { SalesTransactionLockingGuard } from '../guards/SalesTransactionLockingGuard';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import {
|
||||
ISaleInvoiceCreatingPaylaod,
|
||||
ISaleInvoiceDeletePayload,
|
||||
ISaleInvoiceEditingPayload,
|
||||
ISaleInvoiceWriteoffCreatePayload,
|
||||
ISaleInvoiceWrittenOffCancelPayload,
|
||||
} from '@/modules/SaleInvoices/SaleInvoice.types';
|
||||
import {
|
||||
IPaymentReceivedCreatingPayload,
|
||||
IPaymentReceivedEditingPayload,
|
||||
IPaymentReceivedDeletingPayload,
|
||||
} from '@/modules/PaymentReceived/types/PaymentReceived.types';
|
||||
import {
|
||||
ISaleEstimateCreatingPayload,
|
||||
ISaleEstimateDeletingPayload,
|
||||
} from '@/modules/SaleEstimates/types/SaleEstimates.types';
|
||||
import { ISaleEstimateEditingPayload } from '@/modules/SaleEstimates/types/SaleEstimates.types';
|
||||
import { IRefundCreditNoteDeletingPayload } from '@/modules/CreditNoteRefunds/types/CreditNoteRefunds.types';
|
||||
import { IRefundCreditNoteCreatingPayload } from '@/modules/CreditNoteRefunds/types/CreditNoteRefunds.types';
|
||||
import {
|
||||
ICreditNoteCreatingPayload,
|
||||
ICreditNoteDeletingPayload,
|
||||
} from '@/modules/CreditNotes/types/CreditNotes.types';
|
||||
import { ICreditNoteEditingPayload } from '@/modules/CreditNotes/types/CreditNotes.types';
|
||||
import {
|
||||
ISaleReceiptCreatingPayload,
|
||||
ISaleReceiptDeletingPayload,
|
||||
ISaleReceiptEditingPayload,
|
||||
} from '@/modules/SaleReceipts/types/SaleReceipts.types';
|
||||
import { ISaleReceiptEventClosingPayload } from '@/modules/SaleReceipts/types/SaleReceipts.types';
|
||||
|
||||
@Injectable()
|
||||
export class SalesTransactionLockingGuardSubscriber {
|
||||
constructor(
|
||||
public readonly salesLockingGuard: SalesTransactionLockingGuard,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* ---------------------------------------------
|
||||
* SALES INVOICES.
|
||||
* ---------------------------------------------
|
||||
*/
|
||||
/**
|
||||
* Transaction locking guard on invoice creating.
|
||||
* @param {ISaleInvoiceCreatingPaylaod} payload
|
||||
*/
|
||||
@OnEvent(events.saleInvoice.onCreating)
|
||||
public async transactionLockingGuardOnInvoiceCreating({
|
||||
saleInvoiceDTO,
|
||||
}: ISaleInvoiceCreatingPaylaod) {
|
||||
// Can't continue if the new invoice is not published yet.
|
||||
if (!saleInvoiceDTO.delivered) return;
|
||||
|
||||
await this.salesLockingGuard.transactionLockingGuard(
|
||||
saleInvoiceDTO.invoiceDate,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transaction locking guard on invoice editing.
|
||||
* @param {ISaleInvoiceEditingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.saleInvoice.onEditing)
|
||||
public async transactionLockingGuardOnInvoiceEditing({
|
||||
oldSaleInvoice,
|
||||
saleInvoiceDTO,
|
||||
}: ISaleInvoiceEditingPayload) {
|
||||
// Can't continue if the old and new invoice are not published yet.
|
||||
if (!oldSaleInvoice.isDelivered && !saleInvoiceDTO.delivered) return;
|
||||
|
||||
// Validate the old invoice date.
|
||||
await this.salesLockingGuard.transactionLockingGuard(
|
||||
oldSaleInvoice.invoiceDate,
|
||||
);
|
||||
// Validate the new invoice date.
|
||||
await this.salesLockingGuard.transactionLockingGuard(
|
||||
saleInvoiceDTO.invoiceDate,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transaction locking guard on invoice deleting.
|
||||
* @param {ISaleInvoiceDeletePayload} payload
|
||||
*/
|
||||
@OnEvent(events.saleInvoice.onDelete)
|
||||
public async transactionLockingGuardOnInvoiceDeleting({
|
||||
oldSaleInvoice,
|
||||
}: ISaleInvoiceDeletePayload) {
|
||||
// Can't continue if the old invoice not published.
|
||||
if (!oldSaleInvoice.isDelivered) return;
|
||||
|
||||
await this.salesLockingGuard.transactionLockingGuard(
|
||||
oldSaleInvoice.invoiceDate,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transaction locking guard on invoice writingoff.
|
||||
* @param {ISaleInvoiceWriteoffCreatePayload} payload
|
||||
*/
|
||||
@OnEvent(events.saleInvoice.onWriteoff)
|
||||
public async transactionLockinGuardOnInvoiceWritingoff({
|
||||
saleInvoice,
|
||||
}: ISaleInvoiceWriteoffCreatePayload) {
|
||||
await this.salesLockingGuard.transactionLockingGuard(
|
||||
saleInvoice.invoiceDate,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transaciton locking guard on canceling written-off invoice.
|
||||
* @param {ISaleInvoiceWrittenOffCancelPayload} payload
|
||||
*/
|
||||
@OnEvent(events.saleInvoice.onWrittenoffCancel)
|
||||
public async transactionLockinGuardOnInvoiceWritingoffCanceling({
|
||||
saleInvoice,
|
||||
}: ISaleInvoiceWrittenOffCancelPayload) {
|
||||
await this.salesLockingGuard.transactionLockingGuard(
|
||||
saleInvoice.invoiceDate,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* ---------------------------------------------
|
||||
* SALES RECEIPTS.
|
||||
* ---------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Transaction locking guard on receipt creating.
|
||||
* @param {ISaleReceiptCreatingPayload}
|
||||
*/
|
||||
@OnEvent(events.saleReceipt.onCreating)
|
||||
public async transactionLockingGuardOnReceiptCreating({
|
||||
saleReceiptDTO,
|
||||
}: ISaleReceiptCreatingPayload) {
|
||||
// Can't continue if the sale receipt is not published.
|
||||
if (!saleReceiptDTO.closed) return;
|
||||
|
||||
await this.salesLockingGuard.transactionLockingGuard(
|
||||
saleReceiptDTO.receiptDate,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transaction locking guard on receipt creating.
|
||||
* @param {ISaleReceiptDeletingPayload}
|
||||
*/
|
||||
@OnEvent(events.saleReceipt.onDeleting)
|
||||
public async transactionLockingGuardOnReceiptDeleting({
|
||||
oldSaleReceipt,
|
||||
}: ISaleReceiptDeletingPayload) {
|
||||
if (!oldSaleReceipt.isClosed) return;
|
||||
|
||||
await this.salesLockingGuard.transactionLockingGuard(
|
||||
oldSaleReceipt.receiptDate,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transaction locking guard on sale receipt editing.
|
||||
* @param {ISaleReceiptEditingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.saleReceipt.onEditing)
|
||||
public async transactionLockingGuardOnReceiptEditing({
|
||||
oldSaleReceipt,
|
||||
saleReceiptDTO,
|
||||
}: ISaleReceiptEditingPayload) {
|
||||
// Validate the old receipt date.
|
||||
await this.salesLockingGuard.transactionLockingGuard(
|
||||
oldSaleReceipt.receiptDate,
|
||||
);
|
||||
// Validate the new receipt date.
|
||||
await this.salesLockingGuard.transactionLockingGuard(
|
||||
saleReceiptDTO.receiptDate,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transaction locking guard on sale receipt closing.
|
||||
* @param {ISaleReceiptEventClosingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.saleReceipt.onClosing)
|
||||
public async transactionLockingGuardOnReceiptClosing({
|
||||
oldSaleReceipt,
|
||||
}: ISaleReceiptEventClosingPayload) {
|
||||
await this.salesLockingGuard.transactionLockingGuard(
|
||||
oldSaleReceipt.receiptDate,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* ---------------------------------------------
|
||||
* CREDIT NOTES.
|
||||
* ---------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Transaction locking guard on credit note deleting.
|
||||
* @param {ICreditNoteDeletingPayload} payload -
|
||||
*/
|
||||
@OnEvent(events.creditNote.onDeleting)
|
||||
public async transactionLockingGuardOnCreditDeleting({
|
||||
oldCreditNote,
|
||||
}: ICreditNoteDeletingPayload) {
|
||||
// Can't continue if the old credit is not published.
|
||||
if (!oldCreditNote.isPublished) return;
|
||||
|
||||
await this.salesLockingGuard.transactionLockingGuard(
|
||||
oldCreditNote.creditNoteDate,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transaction locking guard on credit note creating.
|
||||
* @param {ICreditNoteCreatingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.creditNote.onCreating)
|
||||
public async transactionLockingGuardOnCreditCreating({
|
||||
creditNoteDTO,
|
||||
}: ICreditNoteCreatingPayload) {
|
||||
// Can't continue if the new credit is still draft.
|
||||
if (!creditNoteDTO.open) return;
|
||||
|
||||
await this.salesLockingGuard.transactionLockingGuard(
|
||||
creditNoteDTO.creditNoteDate,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transaction locking guard on credit note editing.
|
||||
* @param {ICreditNoteEditingPayload} payload -
|
||||
*/
|
||||
@OnEvent(events.creditNote.onEditing)
|
||||
public async transactionLockingGuardOnCreditEditing({
|
||||
creditNoteEditDTO,
|
||||
oldCreditNote,
|
||||
}: ICreditNoteEditingPayload) {
|
||||
// Can't continue if the new and old credit note are not published yet.
|
||||
if (!creditNoteEditDTO.open && !oldCreditNote.isPublished) return;
|
||||
|
||||
// Validate the old credit date.
|
||||
await this.salesLockingGuard.transactionLockingGuard(
|
||||
oldCreditNote.creditNoteDate,
|
||||
);
|
||||
// Validate the new credit date.
|
||||
await this.salesLockingGuard.transactionLockingGuard(
|
||||
creditNoteEditDTO.creditNoteDate,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transaction locking guard on payment deleting.
|
||||
* @param {IRefundCreditNoteDeletingPayload} paylaod -
|
||||
*/
|
||||
@OnEvent(events.creditNote.onRefundDeleting)
|
||||
public async transactionLockingGuardOnCreditRefundDeleteing({
|
||||
oldRefundCredit,
|
||||
}: IRefundCreditNoteDeletingPayload) {
|
||||
await this.salesLockingGuard.transactionLockingGuard(oldRefundCredit.date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transaction locking guard on refund credit note creating.
|
||||
* @param {IRefundCreditNoteCreatingPayload} payload -
|
||||
*/
|
||||
@OnEvent(events.creditNote.onRefundCreating)
|
||||
public async transactionLockingGuardOnCreditRefundCreating({
|
||||
newCreditNoteDTO,
|
||||
}: IRefundCreditNoteCreatingPayload) {
|
||||
await this.salesLockingGuard.transactionLockingGuard(newCreditNoteDTO.date);
|
||||
}
|
||||
|
||||
/**
|
||||
* ---------------------------------------------
|
||||
* SALES ESTIMATES.
|
||||
* ---------------------------------------------
|
||||
*/
|
||||
/**
|
||||
* Transaction locking guard on estimate creating.
|
||||
* @param {ISaleEstimateCreatingPayload} payload -
|
||||
*/
|
||||
@OnEvent(events.saleEstimate.onCreating)
|
||||
public async transactionLockingGuardOnEstimateCreating({
|
||||
estimateDTO,
|
||||
}: ISaleEstimateCreatingPayload) {
|
||||
// Can't continue if the new estimate is not published yet.
|
||||
if (!estimateDTO.delivered) return;
|
||||
|
||||
await this.salesLockingGuard.transactionLockingGuard(
|
||||
estimateDTO.estimateDate,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transaction locking guard on estimate deleting.
|
||||
* @param {ISaleEstimateDeletingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.saleEstimate.onDeleting)
|
||||
public async transactionLockingGuardOnEstimateDeleting({
|
||||
oldSaleEstimate,
|
||||
}: ISaleEstimateDeletingPayload) {
|
||||
// Can't continue if the old estimate is not published.
|
||||
if (!oldSaleEstimate.isDelivered) return;
|
||||
|
||||
await this.salesLockingGuard.transactionLockingGuard(
|
||||
oldSaleEstimate.estimateDate,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transaction locking guard on estimate editing.
|
||||
* @param {ISaleEstimateEditingPayload} payload
|
||||
*/
|
||||
@OnEvent(events.saleEstimate.onEditing)
|
||||
public async transactionLockingGuardOnEstimateEditing({
|
||||
oldSaleEstimate,
|
||||
estimateDTO,
|
||||
}: ISaleEstimateEditingPayload) {
|
||||
// Can't continue if the new and old estimate transactions are not published yet.
|
||||
if (!estimateDTO.delivered && !oldSaleEstimate.isDelivered) return;
|
||||
|
||||
// Validate the old estimate date.
|
||||
await this.salesLockingGuard.transactionLockingGuard(
|
||||
oldSaleEstimate.estimateDate,
|
||||
);
|
||||
// Validate the new estimate date.
|
||||
await this.salesLockingGuard.transactionLockingGuard(
|
||||
estimateDTO.estimateDate,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* ---------------------------------------------
|
||||
* PAYMENT RECEIVES.
|
||||
* ---------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Transaction locking guard on payment receive editing.
|
||||
* @param {IPaymentReceivedEditingPayload}
|
||||
*/
|
||||
@OnEvent(events.paymentReceive.onEditing)
|
||||
public async transactionLockingGuardOnPaymentEditing({
|
||||
oldPaymentReceive,
|
||||
paymentReceiveDTO,
|
||||
}: IPaymentReceivedEditingPayload) {
|
||||
// Validate the old payment date.
|
||||
await this.salesLockingGuard.transactionLockingGuard(
|
||||
oldPaymentReceive.paymentDate,
|
||||
);
|
||||
// Validate the new payment date.
|
||||
await this.salesLockingGuard.transactionLockingGuard(
|
||||
paymentReceiveDTO.paymentDate,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transaction locking guard on payment creating.
|
||||
* @param {IPaymentReceivedCreatingPayload}
|
||||
*/
|
||||
@OnEvent(events.paymentReceive.onCreating)
|
||||
public async transactionLockingGuardOnPaymentCreating({
|
||||
paymentReceiveDTO,
|
||||
}: IPaymentReceivedCreatingPayload) {
|
||||
await this.salesLockingGuard.transactionLockingGuard(
|
||||
paymentReceiveDTO.paymentDate,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transaction locking guard on payment deleting.
|
||||
* @param {IPaymentReceivedDeletingPayload} payload -
|
||||
*/
|
||||
@OnEvent(events.paymentReceive.onDeleting)
|
||||
public async transactionLockingGuardPaymentDeleting({
|
||||
oldPaymentReceive,
|
||||
}: IPaymentReceivedDeletingPayload) {
|
||||
await this.salesLockingGuard.transactionLockingGuard(
|
||||
oldPaymentReceive.paymentDate,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user