mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +00:00
Merge branch 'develop' into tax-compliance
This commit is contained in:
@@ -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,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) => {
|
||||
}: 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
|
||||
);
|
||||
@@ -48,12 +57,17 @@ export default class BillWriteInventoryTransactionsSubscriber {
|
||||
|
||||
/**
|
||||
* Handles the overwriting the inventory transactions once bill edited.
|
||||
* @param {IBillEditedPayload} payload -
|
||||
*/
|
||||
private handleOverwritingInventoryTransactions = async ({
|
||||
tenantId,
|
||||
billId,
|
||||
bill,
|
||||
trx,
|
||||
}: IBillEditedPayload) => {
|
||||
// Can't continue if the bill is not opened yet.
|
||||
if (!bill.openedAt) return null;
|
||||
|
||||
await this.billsInventory.recordInventoryTransactions(
|
||||
tenantId,
|
||||
billId,
|
||||
@@ -64,6 +78,7 @@ export default class BillWriteInventoryTransactionsSubscriber {
|
||||
|
||||
/**
|
||||
* Handles the reverting the inventory transactions once the bill deleted.
|
||||
* @param {IBIllEventDeletedPayload} payload -
|
||||
*/
|
||||
private handleRevertInventoryTransactions = async ({
|
||||
tenantId,
|
||||
|
||||
@@ -17,9 +17,9 @@ export default class BillWriteGLEntriesSubscriber {
|
||||
billsService: BillsService;
|
||||
|
||||
/**
|
||||
* Attachs events with handles.
|
||||
* 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,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() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ export default class OrgSyncTenantAdminUserSubscriber {
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign the autorized system user as admin role.
|
||||
* Assign the authorized system user as admin role.
|
||||
*/
|
||||
public assignSystemUserAsAdminRole = async ({
|
||||
tenantId,
|
||||
|
||||
@@ -37,7 +37,6 @@ export default class PaymentReceiveSyncInvoicesSubscriber {
|
||||
*/
|
||||
private handleInvoiceIncrementPaymentOnceCreated = async ({
|
||||
tenantId,
|
||||
paymentReceiveId,
|
||||
paymentReceive,
|
||||
trx,
|
||||
}: IPaymentReceiveCreatedPayload) => {
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
ISaleInvoiceCreatedPayload,
|
||||
ISaleInvoiceDeletedPayload,
|
||||
ISaleInvoiceEditedPayload,
|
||||
ISaleInvoiceEventDeliveredPayload,
|
||||
} from '@/interfaces';
|
||||
import { InvoiceInventoryTransactions } from '@/services/Sales/Invoices/InvoiceInventoryTransactions';
|
||||
|
||||
@@ -20,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
|
||||
@@ -38,7 +43,10 @@ export default class WriteInventoryTransactions {
|
||||
tenantId,
|
||||
saleInvoice,
|
||||
trx,
|
||||
}: ISaleInvoiceCreatedPayload) => {
|
||||
}: ISaleInvoiceCreatedPayload | ISaleInvoiceEventDeliveredPayload) => {
|
||||
// Can't continue if the sale invoice is not delivered yet.
|
||||
if (!saleInvoice.deliveredAt) return null;
|
||||
|
||||
await this.saleInvoiceInventory.recordInventoryTranscactions(
|
||||
tenantId,
|
||||
saleInvoice,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -40,6 +40,9 @@ export default class SaleReceiptInventoryTransactionsSubscriber {
|
||||
saleReceipt,
|
||||
trx,
|
||||
}: ISaleReceiptCreatedPayload) => {
|
||||
// Can't continue if the sale receipt is not closed yet.
|
||||
if (!saleReceipt.closedAt) return null;
|
||||
|
||||
await this.saleReceiptInventory.recordInventoryTransactions(
|
||||
tenantId,
|
||||
saleReceipt,
|
||||
@@ -57,6 +60,9 @@ export default class SaleReceiptInventoryTransactionsSubscriber {
|
||||
saleReceipt,
|
||||
trx,
|
||||
}: ISaleReceiptEditedPayload) => {
|
||||
// Can't continue if the sale receipt is not closed yet.
|
||||
if (!saleReceipt.closedAt) return null;
|
||||
|
||||
await this.saleReceiptInventory.recordInventoryTransactions(
|
||||
tenantId,
|
||||
saleReceipt,
|
||||
|
||||
@@ -21,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
|
||||
@@ -38,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,
|
||||
@@ -71,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