mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +00:00
add server to monorepo.
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { Service, Inject } from 'typedi';
|
||||
import events from '@/subscribers/events';
|
||||
import SalesReceiptService from '@/services/Sales/SalesReceipts';
|
||||
import { ISaleReceiptCreatedPayload } from '@/interfaces';
|
||||
|
||||
@Service()
|
||||
export default class SaleReceiptAutoSerialSubscriber {
|
||||
@Inject()
|
||||
saleReceiptsService: SalesReceiptService;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param bus
|
||||
*/
|
||||
public attach(bus) {
|
||||
bus.subscribe(
|
||||
events.saleReceipt.onCreated,
|
||||
this.handleReceiptNextNumberIncrement
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle sale receipt increment next number once be created.
|
||||
*/
|
||||
private handleReceiptNextNumberIncrement = async ({
|
||||
tenantId,
|
||||
saleReceiptId,
|
||||
}: ISaleReceiptCreatedPayload) => {
|
||||
await this.saleReceiptsService.incrementNextReceiptNumber(tenantId);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import events from '@/subscribers/events';
|
||||
import SaleReceiptNotifyBySms from '@/services/Sales/SaleReceiptNotifyBySms';
|
||||
import { ISaleReceiptCreatedPayload } from '@/interfaces';
|
||||
import { runAfterTransaction } from '@/services/UnitOfWork/TransactionsHooks';
|
||||
|
||||
@Service()
|
||||
export default class SendSmsNotificationSaleReceipt {
|
||||
@Inject()
|
||||
saleReceiptNotifyBySms: SaleReceiptNotifyBySms;
|
||||
|
||||
/**
|
||||
* Attaches events with handlers.
|
||||
*/
|
||||
public attach(bus) {
|
||||
bus.subscribe(
|
||||
events.saleReceipt.onCreated,
|
||||
this.handleNotifyViaSmsAfterReceiptCreation
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify via SMS message after receipt transaction creation.
|
||||
* @param {ISaleReceiptCreatedPayload} payload -
|
||||
*/
|
||||
private handleNotifyViaSmsAfterReceiptCreation = ({
|
||||
tenantId,
|
||||
saleReceiptId,
|
||||
saleReceipt,
|
||||
trx,
|
||||
}: ISaleReceiptCreatedPayload) => {
|
||||
// Can't continue if the sale receipt is not closed.
|
||||
if (!saleReceipt.isClosed) return;
|
||||
|
||||
// Notify via sms after transaction complete running.
|
||||
runAfterTransaction(trx, async () => {
|
||||
try {
|
||||
await this.saleReceiptNotifyBySms.notifyViaSmsAfterCreation(
|
||||
tenantId,
|
||||
saleReceiptId
|
||||
);
|
||||
} catch (error) {}
|
||||
});
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
import { Inject } from 'typedi';
|
||||
import { EventSubscriber } from 'event-dispatch';
|
||||
import events from '@/subscribers/events';
|
||||
import TenancyService from '@/services/Tenancy/TenancyService';
|
||||
import SalesReceiptService from '@/services/Sales/SalesReceipts';
|
||||
import {
|
||||
ISaleReceiptCreatedPayload,
|
||||
ISaleReceiptEditedPayload,
|
||||
ISaleReceiptEventDeletedPayload,
|
||||
} from '@/interfaces';
|
||||
|
||||
@EventSubscriber()
|
||||
export default class SaleReceiptInventoryTransactionsSubscriber {
|
||||
@Inject()
|
||||
tenancy: TenancyService;
|
||||
|
||||
@Inject()
|
||||
saleReceiptsService: SalesReceiptService;
|
||||
|
||||
/**
|
||||
* Subscribe events to handles.
|
||||
*/
|
||||
attach(bus) {
|
||||
bus.subscribe(
|
||||
events.saleReceipt.onCreated,
|
||||
this.handleWritingInventoryTransactions
|
||||
);
|
||||
bus.subscribe(
|
||||
events.saleReceipt.onEdited,
|
||||
this.handleRewritingInventoryTransactions
|
||||
);
|
||||
bus.subscribe(
|
||||
events.saleReceipt.onDeleted,
|
||||
this.handleDeletingInventoryTransactions
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the writing inventory transactions once the receipt created.
|
||||
* @param {ISaleReceiptCreatedPayload} payload -
|
||||
*/
|
||||
private handleWritingInventoryTransactions = async ({
|
||||
tenantId,
|
||||
saleReceipt,
|
||||
trx,
|
||||
}: ISaleReceiptCreatedPayload) => {
|
||||
await this.saleReceiptsService.recordInventoryTransactions(
|
||||
tenantId,
|
||||
saleReceipt,
|
||||
false,
|
||||
trx
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Rewriting the inventory transactions once the sale invoice be edited.
|
||||
* @param {ISaleReceiptEditedPayload} payload -
|
||||
*/
|
||||
private handleRewritingInventoryTransactions = async ({
|
||||
tenantId,
|
||||
saleReceipt,
|
||||
trx,
|
||||
}: ISaleReceiptEditedPayload) => {
|
||||
await this.saleReceiptsService.recordInventoryTransactions(
|
||||
tenantId,
|
||||
saleReceipt,
|
||||
true,
|
||||
trx
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Handles deleting the inventory transactions once the receipt deleted.
|
||||
* @param {ISaleReceiptEventDeletedPayload} payload -
|
||||
*/
|
||||
private handleDeletingInventoryTransactions = async ({
|
||||
tenantId,
|
||||
saleReceiptId,
|
||||
trx,
|
||||
}: ISaleReceiptEventDeletedPayload) => {
|
||||
await this.saleReceiptsService.revertInventoryTransactions(
|
||||
tenantId,
|
||||
saleReceiptId,
|
||||
trx
|
||||
);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
import { Service, Inject } from 'typedi';
|
||||
import events from '@/subscribers/events';
|
||||
import TenancyService from '@/services/Tenancy/TenancyService';
|
||||
import SalesReceiptService from '@/services/Sales/SalesReceipts';
|
||||
import {
|
||||
ISaleReceiptCreatedPayload,
|
||||
ISaleReceiptEditedPayload,
|
||||
ISaleReceiptEventDeletedPayload,
|
||||
} from '@/interfaces';
|
||||
import { SaleReceiptGLEntries } from '@/services/Sales/SaleReceiptGLEntries';
|
||||
|
||||
@Service()
|
||||
export default class SaleReceiptWriteGLEntriesSubscriber {
|
||||
@Inject()
|
||||
tenancy: TenancyService;
|
||||
|
||||
@Inject()
|
||||
saleReceiptGLEntries: SaleReceiptGLEntries;
|
||||
|
||||
/**
|
||||
* Attaches events with handlers.
|
||||
*/
|
||||
public attach(bus) {
|
||||
bus.subscribe(
|
||||
events.saleReceipt.onCreated,
|
||||
this.handleWriteReceiptIncomeJournalEntrieOnCreate
|
||||
);
|
||||
bus.subscribe(
|
||||
events.saleReceipt.onEdited,
|
||||
this.handleWriteReceiptIncomeJournalEntrieOnEdited
|
||||
);
|
||||
bus.subscribe(
|
||||
events.saleReceipt.onDeleted,
|
||||
this.handleRevertReceiptJournalEntriesOnDeleted
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles writing sale receipt income journal entries once created.
|
||||
* @param {ISaleReceiptCreatedPayload} payload -
|
||||
*/
|
||||
public handleWriteReceiptIncomeJournalEntrieOnCreate = async ({
|
||||
tenantId,
|
||||
saleReceiptId,
|
||||
trx,
|
||||
}: ISaleReceiptCreatedPayload) => {
|
||||
// Writes the sale receipt income journal entries.
|
||||
await this.saleReceiptGLEntries.writeIncomeGLEntries(
|
||||
tenantId,
|
||||
saleReceiptId,
|
||||
trx
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Handles sale receipt revert jouranl entries once be deleted.
|
||||
* @param {ISaleReceiptEventDeletedPayload} payload -
|
||||
*/
|
||||
public handleRevertReceiptJournalEntriesOnDeleted = async ({
|
||||
tenantId,
|
||||
saleReceiptId,
|
||||
trx,
|
||||
}: ISaleReceiptEventDeletedPayload) => {
|
||||
await this.saleReceiptGLEntries.revertReceiptGLEntries(
|
||||
tenantId,
|
||||
saleReceiptId,
|
||||
trx
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Handles writing sale receipt income journal entries once be edited.
|
||||
* @param {ISaleReceiptEditedPayload} payload -
|
||||
*/
|
||||
private handleWriteReceiptIncomeJournalEntrieOnEdited = async ({
|
||||
tenantId,
|
||||
saleReceiptId,
|
||||
trx,
|
||||
}: ISaleReceiptEditedPayload) => {
|
||||
// Writes the sale receipt income journal entries.
|
||||
await this.saleReceiptGLEntries.rewriteReceiptGLEntries(
|
||||
tenantId,
|
||||
saleReceiptId,
|
||||
trx
|
||||
);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user