mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
Merge branch 'develop' into fix-spelling-a-char
This commit is contained in:
@@ -1,20 +1,17 @@
|
||||
import { Service, Inject } from 'typedi';
|
||||
import events from '@/subscribers/events';
|
||||
import TenancyService from '@/services/Tenancy/TenancyService';
|
||||
import BillsService from '@/services/Purchases/Bills';
|
||||
import {
|
||||
IBillCreatedPayload,
|
||||
IBillEditedPayload,
|
||||
IBIllEventDeletedPayload,
|
||||
IBillOpenedPayload,
|
||||
} from '@/interfaces';
|
||||
import { BillInventoryTransactions } from '@/services/Purchases/Bills/BillInventoryTransactions';
|
||||
|
||||
@Service()
|
||||
export default class BillWriteInventoryTransactionsSubscriber {
|
||||
@Inject()
|
||||
tenancy: TenancyService;
|
||||
|
||||
@Inject()
|
||||
billsService: BillsService;
|
||||
private billsInventory: BillInventoryTransactions;
|
||||
|
||||
/**
|
||||
* Attaches events with handles.
|
||||
@@ -24,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
|
||||
@@ -36,15 +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) => {
|
||||
await this.billsService.recordInventoryTransactions(
|
||||
}: 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,13 +57,18 @@ export default class BillWriteInventoryTransactionsSubscriber {
|
||||
|
||||
/**
|
||||
* Handles the overwriting the inventory transactions once bill edited.
|
||||
* @param {IBillEditedPayload} payload -
|
||||
*/
|
||||
private handleOverwritingInventoryTransactions = async ({
|
||||
tenantId,
|
||||
billId,
|
||||
bill,
|
||||
trx,
|
||||
}: IBillEditedPayload) => {
|
||||
await this.billsService.recordInventoryTransactions(
|
||||
// Can't continue if the bill is not opened yet.
|
||||
if (!bill.openedAt) return null;
|
||||
|
||||
await this.billsInventory.recordInventoryTransactions(
|
||||
tenantId,
|
||||
billId,
|
||||
true,
|
||||
@@ -68,12 +78,17 @@ export default class BillWriteInventoryTransactionsSubscriber {
|
||||
|
||||
/**
|
||||
* Handles the reverting the inventory transactions once the bill deleted.
|
||||
* @param {IBIllEventDeletedPayload} payload -
|
||||
*/
|
||||
private handleRevertInventoryTransactions = async ({
|
||||
tenantId,
|
||||
billId,
|
||||
trx,
|
||||
}: IBIllEventDeletedPayload) => {
|
||||
await this.billsService.revertInventoryTransactions(tenantId, billId, trx);
|
||||
await this.billsInventory.revertInventoryTransactions(
|
||||
tenantId,
|
||||
billId,
|
||||
trx
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ export default class BillWriteGLEntriesSubscriber {
|
||||
/**
|
||||
* Attaches events with handles.
|
||||
*/
|
||||
attach(bus) {
|
||||
public attach(bus) {
|
||||
bus.subscribe(
|
||||
events.bill.onCreated,
|
||||
this.handlerWriteJournalEntriesOnCreate
|
||||
@@ -38,8 +38,12 @@ export default class BillWriteGLEntriesSubscriber {
|
||||
private handlerWriteJournalEntriesOnCreate = async ({
|
||||
tenantId,
|
||||
billId,
|
||||
bill,
|
||||
trx,
|
||||
}: IBillCreatedPayload) => {
|
||||
// Can't continue if the bill is not opened yet.
|
||||
if (!bill.openedAt) return null;
|
||||
|
||||
await this.billsService.recordJournalTransactions(
|
||||
tenantId,
|
||||
billId,
|
||||
@@ -55,8 +59,12 @@ export default class BillWriteGLEntriesSubscriber {
|
||||
private handleOverwriteJournalEntriesOnEdit = async ({
|
||||
tenantId,
|
||||
billId,
|
||||
bill,
|
||||
trx,
|
||||
}: IBillEditedPayload) => {
|
||||
// Can't continue if the bill is not opened yet.
|
||||
if (!bill.openedAt) return null;
|
||||
|
||||
await this.billsService.recordJournalTransactions(
|
||||
tenantId,
|
||||
billId,
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
import { Container } from 'typedi';
|
||||
import { EventSubscriber, On } from 'event-dispatch';
|
||||
import { map, head } from 'lodash';
|
||||
import events from '@/subscribers/events';
|
||||
import TenancyService from '@/services/Tenancy/TenancyService';
|
||||
import SaleInvoicesCost from '@/services/Sales/SalesInvoicesCost';
|
||||
import InventoryItemsQuantitySync from '@/services/Inventory/InventoryItemsQuantitySync';
|
||||
import InventoryService from '@/services/Inventory/Inventory';
|
||||
|
||||
@EventSubscriber()
|
||||
export class OwnerContributionCashflowSubscriber {
|
||||
depends: number = 0;
|
||||
startingDate: Date;
|
||||
saleInvoicesCost: SaleInvoicesCost;
|
||||
tenancy: TenancyService;
|
||||
itemsQuantitySync: InventoryItemsQuantitySync;
|
||||
inventoryService: InventoryService;
|
||||
agenda: any;
|
||||
|
||||
/**
|
||||
* Constructor method.
|
||||
*/
|
||||
constructor() {
|
||||
this.tenancy = Container.get(TenancyService);
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks items cost compute running state.
|
||||
*/
|
||||
@On(events.cashflow.onOwnerContributionCreate)
|
||||
async writeOwnerContributionJournalEntries({
|
||||
|
||||
}) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +1,6 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { map, head } from 'lodash';
|
||||
|
||||
import events from '@/subscribers/events';
|
||||
import TenancyService from '@/services/Tenancy/TenancyService';
|
||||
import SaleInvoicesCost from '@/services/Sales/SalesInvoicesCost';
|
||||
import InventoryItemsQuantitySync from '@/services/Inventory/InventoryItemsQuantitySync';
|
||||
import InventoryService from '@/services/Inventory/Inventory';
|
||||
import {
|
||||
@@ -12,23 +9,21 @@ import {
|
||||
IInventoryTransactionsDeletedPayload,
|
||||
} from '@/interfaces';
|
||||
import { runAfterTransaction } from '@/services/UnitOfWork/TransactionsHooks';
|
||||
import { SaleInvoicesCost } from '@/services/Sales/Invoices/SalesInvoicesCost';
|
||||
|
||||
@Service()
|
||||
export default class InventorySubscriber {
|
||||
@Inject()
|
||||
saleInvoicesCost: SaleInvoicesCost;
|
||||
private saleInvoicesCost: SaleInvoicesCost;
|
||||
|
||||
@Inject()
|
||||
tenancy: TenancyService;
|
||||
private itemsQuantitySync: InventoryItemsQuantitySync;
|
||||
|
||||
@Inject()
|
||||
itemsQuantitySync: InventoryItemsQuantitySync;
|
||||
|
||||
@Inject()
|
||||
inventoryService: InventoryService;
|
||||
private inventoryService: InventoryService;
|
||||
|
||||
@Inject('agenda')
|
||||
agenda: any;
|
||||
private agenda: any;
|
||||
|
||||
/**
|
||||
* Attaches events with handlers.
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
import events from '@/subscribers/events';
|
||||
import { EventSubscriber } from '@/lib/EventPublisher/EventPublisher';
|
||||
import { Service } from 'typedi';
|
||||
|
||||
@Service()
|
||||
export default class ItemSubscriber extends EventSubscriber {
|
||||
/**
|
||||
* Attaches the events with handles.
|
||||
* @param bus
|
||||
*/
|
||||
attach(bus) {
|
||||
bus.subscribe(events.item.onCreated, this.handleItemCreated);
|
||||
}
|
||||
|
||||
handleItemCreated() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import events from '@/subscribers/events';
|
||||
import BillPaymentsService from '@/services/Purchases/BillPayments/BillPayments';
|
||||
import TenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { BillPaymentBillSync } from '@/services/Purchases/BillPayments/BillPaymentBillSync';
|
||||
import {
|
||||
IBillPaymentEventCreatedPayload,
|
||||
IBillPaymentEventDeletedPayload,
|
||||
@@ -11,16 +10,13 @@ import {
|
||||
@Service()
|
||||
export default class PaymentSyncBillBalance {
|
||||
@Inject()
|
||||
tenancy: TenancyService;
|
||||
|
||||
@Inject()
|
||||
billPaymentsService: BillPaymentsService;
|
||||
private billPaymentsService: BillPaymentBillSync;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param bus
|
||||
*/
|
||||
attach(bus) {
|
||||
public attach(bus) {
|
||||
bus.subscribe(
|
||||
events.billPayment.onCreated,
|
||||
this.handleBillsIncrementPaymentAmount
|
||||
@@ -34,6 +30,7 @@ export default class PaymentSyncBillBalance {
|
||||
this.handleBillDecrementPaymentAmount
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle bill payment amount increment/decrement once bill payment created or edited.
|
||||
*/
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { Service, Inject } from 'typedi';
|
||||
import events from '@/subscribers/events';
|
||||
import { EventSubscriber } from '@/lib/EventPublisher/EventPublisher';
|
||||
import PaymentReceiveService from '@/services/Sales/PaymentReceives/PaymentsReceives';
|
||||
import { PaymentReceiveIncrement } from '@/services/Sales/PaymentReceives/PaymentReceiveIncrement';
|
||||
import { IPaymentReceiveCreatedPayload } from '@/interfaces';
|
||||
|
||||
@Service()
|
||||
export default class PaymentReceiveAutoSerialSubscriber extends EventSubscriber {
|
||||
@Inject()
|
||||
paymentReceivesService: PaymentReceiveService;
|
||||
private paymentIncrement: PaymentReceiveIncrement;
|
||||
|
||||
/**
|
||||
* Attaches the events with handles.
|
||||
@@ -29,8 +29,6 @@ export default class PaymentReceiveAutoSerialSubscriber extends EventSubscriber
|
||||
paymentReceiveId,
|
||||
trx,
|
||||
}: IPaymentReceiveCreatedPayload) => {
|
||||
await this.paymentReceivesService.incrementNextPaymentReceiveNumber(
|
||||
tenantId
|
||||
);
|
||||
await this.paymentIncrement.incrementNextPaymentReceiveNumber(tenantId);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import events from '@/subscribers/events';
|
||||
import PaymentReceiveService from '@/services/Sales/PaymentReceives/PaymentsReceives';
|
||||
import { PaymentReceiveInvoiceSync } from '@/services/Sales/PaymentReceives/PaymentReceiveInvoiceSync';
|
||||
import {
|
||||
IPaymentReceiveCreatedPayload,
|
||||
IPaymentReceiveDeletedPayload,
|
||||
@@ -8,15 +8,15 @@ import {
|
||||
} from '@/interfaces';
|
||||
|
||||
@Service()
|
||||
export default class PaymentReceiveSyncInvoices {
|
||||
export default class PaymentReceiveSyncInvoicesSubscriber {
|
||||
@Inject()
|
||||
paymentReceivesService: PaymentReceiveService;
|
||||
private paymentSyncInvoice: PaymentReceiveInvoiceSync;
|
||||
|
||||
/**
|
||||
* Attaches the events to handles.
|
||||
* @param bus
|
||||
*/
|
||||
attach(bus) {
|
||||
public attach(bus) {
|
||||
bus.subscribe(
|
||||
events.paymentReceive.onCreated,
|
||||
this.handleInvoiceIncrementPaymentOnceCreated
|
||||
@@ -37,11 +37,10 @@ export default class PaymentReceiveSyncInvoices {
|
||||
*/
|
||||
private handleInvoiceIncrementPaymentOnceCreated = async ({
|
||||
tenantId,
|
||||
paymentReceiveId,
|
||||
paymentReceive,
|
||||
trx,
|
||||
}: IPaymentReceiveCreatedPayload) => {
|
||||
await this.paymentReceivesService.saveChangeInvoicePaymentAmount(
|
||||
await this.paymentSyncInvoice.saveChangeInvoicePaymentAmount(
|
||||
tenantId,
|
||||
paymentReceive.entries,
|
||||
null,
|
||||
@@ -59,7 +58,7 @@ export default class PaymentReceiveSyncInvoices {
|
||||
oldPaymentReceive,
|
||||
trx,
|
||||
}: IPaymentReceiveEditedPayload) => {
|
||||
await this.paymentReceivesService.saveChangeInvoicePaymentAmount(
|
||||
await this.paymentSyncInvoice.saveChangeInvoicePaymentAmount(
|
||||
tenantId,
|
||||
paymentReceive.entries,
|
||||
oldPaymentReceive?.entries || null,
|
||||
@@ -76,7 +75,7 @@ export default class PaymentReceiveSyncInvoices {
|
||||
oldPaymentReceive,
|
||||
trx,
|
||||
}: IPaymentReceiveDeletedPayload) => {
|
||||
await this.paymentReceivesService.saveChangeInvoicePaymentAmount(
|
||||
await this.paymentSyncInvoice.saveChangeInvoicePaymentAmount(
|
||||
tenantId,
|
||||
oldPaymentReceive.entries.map((entry) => ({
|
||||
...entry,
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { Service, Inject } from 'typedi';
|
||||
import events from '@/subscribers/events';
|
||||
import PaymentReceiveNotifyBySms from '@/services/Sales/PaymentReceives/PaymentReceiveSmsNotify';
|
||||
import { PaymentReceiveNotifyBySms } from '@/services/Sales/PaymentReceives/PaymentReceiveSmsNotify';
|
||||
import { IPaymentReceiveCreatedPayload } from '@/interfaces';
|
||||
import { runAfterTransaction } from '@/services/UnitOfWork/TransactionsHooks';
|
||||
|
||||
@Service()
|
||||
export default class SendSmsNotificationPaymentReceive {
|
||||
@Inject()
|
||||
paymentReceiveSmsNotify: PaymentReceiveNotifyBySms;
|
||||
private paymentReceiveSmsNotify: PaymentReceiveNotifyBySms;
|
||||
|
||||
/**
|
||||
* Attach events.
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import events from '@/subscribers/events';
|
||||
import SaleEstimateNotifyBySms from '@/services/Sales/Estimates/SaleEstimateSmsNotify';
|
||||
import { SaleEstimateNotifyBySms } from '@/services/Sales/Estimates/SaleEstimateSmsNotify';
|
||||
import { ISaleEstimateCreatedPayload } from '@/interfaces';
|
||||
import { runAfterTransaction } from '@/services/UnitOfWork/TransactionsHooks';
|
||||
|
||||
@Service()
|
||||
export default class SaleEstimateSmsNotificationSubscriber {
|
||||
@Inject()
|
||||
saleEstimateNotifyBySms: SaleEstimateNotifyBySms;
|
||||
private saleEstimateNotifyBySms: SaleEstimateNotifyBySms;
|
||||
|
||||
/**
|
||||
* Attaches events to handles.events.saleEstimate.onCreated
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { EventSubscriber } from '@/lib/EventPublisher/EventPublisher';
|
||||
import events from '@/subscribers/events';
|
||||
import SaleInvoicesService from '@/services/Sales/SalesInvoices';
|
||||
import { SaleInvoiceIncrement } from '@/services/Sales/Invoices/SaleInvoiceIncrement';
|
||||
import { ISaleInvoiceCreatedPayload } from '@/interfaces';
|
||||
|
||||
@Service()
|
||||
export default class SaleInvoiceAutoIncrementSubscriber extends EventSubscriber {
|
||||
@Inject()
|
||||
saleInvoicesService: SaleInvoicesService;
|
||||
private saleInvoicesService: SaleInvoiceIncrement;
|
||||
|
||||
/**
|
||||
* Constructor method.
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { EventSubscriber } from '@/lib/EventPublisher/EventPublisher';
|
||||
import events from '@/subscribers/events';
|
||||
import SaleEstimateService from '@/services/Sales/SalesEstimate';
|
||||
import { ConvertSaleEstimate } from '@/services/Sales/Estimates/ConvetSaleEstimate';
|
||||
import { ISaleInvoiceCreatedPayload } from '@/interfaces';
|
||||
import events from '@/subscribers/events';
|
||||
|
||||
@Service()
|
||||
export default class SaleInvoiceConvertFromEstimateSubscriber extends EventSubscriber {
|
||||
@Inject()
|
||||
saleEstimatesService: SaleEstimateService;
|
||||
private convertEstimateToInvoiceService: ConvertSaleEstimate;
|
||||
|
||||
/**
|
||||
* Constructor method.
|
||||
@@ -30,7 +30,7 @@ export default class SaleInvoiceConvertFromEstimateSubscriber extends EventSubsc
|
||||
trx,
|
||||
}: ISaleInvoiceCreatedPayload) => {
|
||||
if (saleInvoiceDTO.fromEstimateId) {
|
||||
await this.saleEstimatesService.convertEstimateToInvoice(
|
||||
await this.convertEstimateToInvoiceService.convertEstimateToInvoice(
|
||||
tenantId,
|
||||
saleInvoiceDTO.fromEstimateId,
|
||||
saleInvoiceId,
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import events from '@/subscribers/events';
|
||||
import SaleInvoiceNotifyBySms from '@/services/Sales/SaleInvoiceNotifyBySms';
|
||||
import { SaleInvoiceNotifyBySms } from '@/services/Sales/Invoices/SaleInvoiceNotifyBySms';
|
||||
import { ISaleInvoiceCreatedPayload } from '@/interfaces';
|
||||
import { runAfterTransaction } from '@/services/UnitOfWork/TransactionsHooks';
|
||||
|
||||
@Service()
|
||||
export default class SendSmsNotificationToCustomer {
|
||||
@Inject()
|
||||
saleInvoiceNotifyBySms: SaleInvoiceNotifyBySms;
|
||||
private saleInvoiceNotifyBySms: SaleInvoiceNotifyBySms;
|
||||
|
||||
/**
|
||||
* Attaches events with handlers.
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
import { Service, Inject } from 'typedi';
|
||||
import events from '@/subscribers/events';
|
||||
import TenancyService from '@/services/Tenancy/TenancyService';
|
||||
import SaleInvoicesService from '@/services/Sales/SalesInvoices';
|
||||
import {
|
||||
ISaleInvoiceCreatedPayload,
|
||||
ISaleInvoiceDeletedPayload,
|
||||
ISaleInvoiceEditedPayload,
|
||||
ISaleInvoiceEventDeliveredPayload,
|
||||
} from '@/interfaces';
|
||||
import { InvoiceInventoryTransactions } from '@/services/Sales/Invoices/InvoiceInventoryTransactions';
|
||||
|
||||
@Service()
|
||||
export default class WriteInventoryTransactions {
|
||||
@Inject()
|
||||
tenancy: TenancyService;
|
||||
|
||||
@Inject()
|
||||
saleInvoicesService: SaleInvoicesService;
|
||||
private saleInvoiceInventory: InvoiceInventoryTransactions;
|
||||
|
||||
/**
|
||||
* Attaches events with handles
|
||||
@@ -24,6 +21,10 @@ export default class WriteInventoryTransactions {
|
||||
events.saleInvoice.onCreated,
|
||||
this.handleWritingInventoryTransactions
|
||||
);
|
||||
bus.subscribe(
|
||||
events.saleInvoice.onDelivered,
|
||||
this.handleWritingInventoryTransactions
|
||||
);
|
||||
bus.subscribe(
|
||||
events.saleInvoice.onEdited,
|
||||
this.handleRewritingInventoryTransactions
|
||||
@@ -42,8 +43,11 @@ export default class WriteInventoryTransactions {
|
||||
tenantId,
|
||||
saleInvoice,
|
||||
trx,
|
||||
}: ISaleInvoiceCreatedPayload) => {
|
||||
await this.saleInvoicesService.recordInventoryTranscactions(
|
||||
}: ISaleInvoiceCreatedPayload | ISaleInvoiceEventDeliveredPayload) => {
|
||||
// Can't continue if the sale invoice is not delivered yet.
|
||||
if (!saleInvoice.deliveredAt) return null;
|
||||
|
||||
await this.saleInvoiceInventory.recordInventoryTranscactions(
|
||||
tenantId,
|
||||
saleInvoice,
|
||||
false,
|
||||
@@ -53,14 +57,14 @@ export default class WriteInventoryTransactions {
|
||||
|
||||
/**
|
||||
* Rewriting the inventory transactions once the sale invoice be edited.
|
||||
* @param {ISaleInvoiceEditPayload} payload -
|
||||
* @param {ISaleInvoiceEditPayload} payload -
|
||||
*/
|
||||
private handleRewritingInventoryTransactions = async ({
|
||||
tenantId,
|
||||
saleInvoice,
|
||||
trx,
|
||||
}: ISaleInvoiceEditedPayload) => {
|
||||
await this.saleInvoicesService.recordInventoryTranscactions(
|
||||
await this.saleInvoiceInventory.recordInventoryTranscactions(
|
||||
tenantId,
|
||||
saleInvoice,
|
||||
true,
|
||||
@@ -70,7 +74,7 @@ export default class WriteInventoryTransactions {
|
||||
|
||||
/**
|
||||
* Handles deleting the inventory transactions once the invoice deleted.
|
||||
* @param {ISaleInvoiceDeletedPayload} payload -
|
||||
* @param {ISaleInvoiceDeletedPayload} payload -
|
||||
*/
|
||||
private handleDeletingInventoryTransactions = async ({
|
||||
tenantId,
|
||||
@@ -78,7 +82,7 @@ export default class WriteInventoryTransactions {
|
||||
oldSaleInvoice,
|
||||
trx,
|
||||
}: ISaleInvoiceDeletedPayload) => {
|
||||
await this.saleInvoicesService.revertInventoryTransactions(
|
||||
await this.saleInvoiceInventory.revertInventoryTransactions(
|
||||
tenantId,
|
||||
saleInvoiceId,
|
||||
trx
|
||||
|
||||
@@ -15,11 +15,15 @@ export default class SaleInvoiceWriteGLEntriesSubscriber {
|
||||
/**
|
||||
* Constructor method.
|
||||
*/
|
||||
attach(bus) {
|
||||
public attach(bus) {
|
||||
bus.subscribe(
|
||||
events.saleInvoice.onCreated,
|
||||
this.handleWriteJournalEntriesOnInvoiceCreated
|
||||
);
|
||||
bus.subscribe(
|
||||
events.saleInvoice.onDelivered,
|
||||
this.handleWriteJournalEntriesOnInvoiceCreated
|
||||
);
|
||||
bus.subscribe(
|
||||
events.saleInvoice.onEdited,
|
||||
this.handleRewriteJournalEntriesOnceInvoiceEdit
|
||||
@@ -32,12 +36,18 @@ export default class SaleInvoiceWriteGLEntriesSubscriber {
|
||||
|
||||
/**
|
||||
* Records journal entries of the non-inventory invoice.
|
||||
* @param {ISaleInvoiceCreatedPayload} payload -
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
private handleWriteJournalEntriesOnInvoiceCreated = async ({
|
||||
tenantId,
|
||||
saleInvoiceId,
|
||||
saleInvoice,
|
||||
trx,
|
||||
}: ISaleInvoiceCreatedPayload) => {
|
||||
// Can't continue if the sale invoice is not delivered yet.
|
||||
if (!saleInvoice.deliveredAt) return null;
|
||||
|
||||
await this.saleInvoiceGLEntries.writeInvoiceGLEntries(
|
||||
tenantId,
|
||||
saleInvoiceId,
|
||||
@@ -47,12 +57,17 @@ export default class SaleInvoiceWriteGLEntriesSubscriber {
|
||||
|
||||
/**
|
||||
* Records journal entries of the non-inventory invoice.
|
||||
* @param {ISaleInvoiceEditedPayload} payload -
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
private handleRewriteJournalEntriesOnceInvoiceEdit = async ({
|
||||
tenantId,
|
||||
saleInvoice,
|
||||
trx,
|
||||
}: ISaleInvoiceEditedPayload) => {
|
||||
// Can't continue if the sale invoice is not delivered yet.
|
||||
if (!saleInvoice.deliveredAt) return null;
|
||||
|
||||
await this.saleInvoiceGLEntries.rewritesInvoiceGLEntries(
|
||||
tenantId,
|
||||
saleInvoice.id,
|
||||
@@ -62,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,
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { Service, Inject } from 'typedi';
|
||||
import events from '@/subscribers/events';
|
||||
import SalesReceiptService from '@/services/Sales/SalesReceipts';
|
||||
import { SaleReceiptIncrement } from '@/services/Sales/Receipts/SaleReceiptIncrement';
|
||||
import { ISaleReceiptCreatedPayload } from '@/interfaces';
|
||||
|
||||
@Service()
|
||||
export default class SaleReceiptAutoSerialSubscriber {
|
||||
@Inject()
|
||||
saleReceiptsService: SalesReceiptService;
|
||||
private saleReceiptsService: SaleReceiptIncrement;
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import events from '@/subscribers/events';
|
||||
import SaleReceiptNotifyBySms from '@/services/Sales/SaleReceiptNotifyBySms';
|
||||
import { SaleReceiptNotifyBySms } from '@/services/Sales/Receipts/SaleReceiptNotifyBySms';
|
||||
import { ISaleReceiptCreatedPayload } from '@/interfaces';
|
||||
import { runAfterTransaction } from '@/services/UnitOfWork/TransactionsHooks';
|
||||
|
||||
@Service()
|
||||
export default class SendSmsNotificationSaleReceipt {
|
||||
@Inject()
|
||||
saleReceiptNotifyBySms: SaleReceiptNotifyBySms;
|
||||
private saleReceiptNotifyBySms: SaleReceiptNotifyBySms;
|
||||
|
||||
/**
|
||||
* Attaches events with handlers.
|
||||
|
||||
@@ -1,26 +1,22 @@
|
||||
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';
|
||||
import { SaleReceiptInventoryTransactions } from '@/services/Sales/Receipts/SaleReceiptInventoryTransactions';
|
||||
|
||||
@EventSubscriber()
|
||||
export default class SaleReceiptInventoryTransactionsSubscriber {
|
||||
@Inject()
|
||||
tenancy: TenancyService;
|
||||
|
||||
@Inject()
|
||||
saleReceiptsService: SalesReceiptService;
|
||||
private saleReceiptInventory: SaleReceiptInventoryTransactions;
|
||||
|
||||
/**
|
||||
* Subscribe events to handles.
|
||||
*/
|
||||
attach(bus) {
|
||||
public attach(bus) {
|
||||
bus.subscribe(
|
||||
events.saleReceipt.onCreated,
|
||||
this.handleWritingInventoryTransactions
|
||||
@@ -44,7 +40,10 @@ export default class SaleReceiptInventoryTransactionsSubscriber {
|
||||
saleReceipt,
|
||||
trx,
|
||||
}: ISaleReceiptCreatedPayload) => {
|
||||
await this.saleReceiptsService.recordInventoryTransactions(
|
||||
// Can't continue if the sale receipt is not closed yet.
|
||||
if (!saleReceipt.closedAt) return null;
|
||||
|
||||
await this.saleReceiptInventory.recordInventoryTransactions(
|
||||
tenantId,
|
||||
saleReceipt,
|
||||
false,
|
||||
@@ -61,7 +60,10 @@ export default class SaleReceiptInventoryTransactionsSubscriber {
|
||||
saleReceipt,
|
||||
trx,
|
||||
}: ISaleReceiptEditedPayload) => {
|
||||
await this.saleReceiptsService.recordInventoryTransactions(
|
||||
// Can't continue if the sale receipt is not closed yet.
|
||||
if (!saleReceipt.closedAt) return null;
|
||||
|
||||
await this.saleReceiptInventory.recordInventoryTransactions(
|
||||
tenantId,
|
||||
saleReceipt,
|
||||
true,
|
||||
@@ -78,7 +80,7 @@ export default class SaleReceiptInventoryTransactionsSubscriber {
|
||||
saleReceiptId,
|
||||
trx,
|
||||
}: ISaleReceiptEventDeletedPayload) => {
|
||||
await this.saleReceiptsService.revertInventoryTransactions(
|
||||
await this.saleReceiptInventory.revertInventoryTransactions(
|
||||
tenantId,
|
||||
saleReceiptId,
|
||||
trx
|
||||
|
||||
@@ -1,21 +1,17 @@
|
||||
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';
|
||||
import { SaleReceiptGLEntries } from '@/services/Sales/Receipts/SaleReceiptGLEntries';
|
||||
|
||||
@Service()
|
||||
export default class SaleReceiptWriteGLEntriesSubscriber {
|
||||
@Inject()
|
||||
tenancy: TenancyService;
|
||||
|
||||
@Inject()
|
||||
saleReceiptGLEntries: SaleReceiptGLEntries;
|
||||
private saleReceiptGLEntries: SaleReceiptGLEntries;
|
||||
|
||||
/**
|
||||
* Attaches events with handlers.
|
||||
@@ -25,6 +21,10 @@ export default class SaleReceiptWriteGLEntriesSubscriber {
|
||||
events.saleReceipt.onCreated,
|
||||
this.handleWriteReceiptIncomeJournalEntrieOnCreate
|
||||
);
|
||||
bus.subscribe(
|
||||
events.saleReceipt.onClosed,
|
||||
this.handleWriteReceiptIncomeJournalEntrieOnCreate
|
||||
);
|
||||
bus.subscribe(
|
||||
events.saleReceipt.onEdited,
|
||||
this.handleWriteReceiptIncomeJournalEntrieOnEdited
|
||||
@@ -42,8 +42,12 @@ export default class SaleReceiptWriteGLEntriesSubscriber {
|
||||
public handleWriteReceiptIncomeJournalEntrieOnCreate = async ({
|
||||
tenantId,
|
||||
saleReceiptId,
|
||||
saleReceipt,
|
||||
trx,
|
||||
}: ISaleReceiptCreatedPayload) => {
|
||||
// Can't continue if the sale receipt is not closed yet.
|
||||
if (!saleReceipt.closedAt) return null;
|
||||
|
||||
// Writes the sale receipt income journal entries.
|
||||
await this.saleReceiptGLEntries.writeIncomeGLEntries(
|
||||
tenantId,
|
||||
@@ -75,8 +79,12 @@ export default class SaleReceiptWriteGLEntriesSubscriber {
|
||||
private handleWriteReceiptIncomeJournalEntrieOnEdited = async ({
|
||||
tenantId,
|
||||
saleReceiptId,
|
||||
saleReceipt,
|
||||
trx,
|
||||
}: ISaleReceiptEditedPayload) => {
|
||||
// Can't continue if the sale receipt is not closed yet.
|
||||
if (!saleReceipt.closedAt) return null;
|
||||
|
||||
// Writes the sale receipt income journal entries.
|
||||
await this.saleReceiptGLEntries.rewriteReceiptGLEntries(
|
||||
tenantId,
|
||||
|
||||
@@ -220,6 +220,9 @@ export default {
|
||||
|
||||
onPublishing: 'onBillPublishing',
|
||||
onPublished: 'onBillPublished',
|
||||
|
||||
onOpening: 'onBillOpening',
|
||||
onOpened: 'onBillOpened',
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user