Compare commits

...

11 Commits

Author SHA1 Message Date
Ahmed Bouhuolia
9ac0dcbdc3 Merge pull request #651 from bigcapitalhq/bank-transactions-events
feat: Track banking service events
2024-09-02 17:13:49 +02:00
Ahmed Bouhuolia
df588dc4ce Merge branch 'develop' into bank-transactions-events 2024-09-02 17:13:43 +02:00
Ahmed Bouhuolia
d54f14a87a feat: Track banking service events 2024-09-02 17:12:37 +02:00
Ahmed Bouhuolia
a4d4be54c1 Merge pull request #650 from bigcapitalhq/cover-more-tracking-events
feat: Cover more tracking events.
2024-09-02 15:20:11 +02:00
Ahmed Bouhuolia
ddd17e74b5 feat: Cover more tracking events. 2024-09-02 15:19:01 +02:00
Ahmed Bouhuolia
81c0761fbe Merge pull request #649 from bigcapitalhq/import-multi-branches-expenses
fix: Integrate multiple branches with expense resource
2024-09-02 15:02:53 +02:00
Ahmed Bouhuolia
0812e3087e fix: Integrate multiple branches with expense resource 2024-09-02 15:02:02 +02:00
Ahmed Bouhuolia
0dd05493b2 Merge pull request #645 from bigcapitalhq/multi-branches-warehoues-in-importing
feat: integrate multiple branches and warehouses to resource importing
2024-09-02 14:46:08 +02:00
Ahmed Bouhuolia
bfb3909d26 feat: integrate multiple branches and warehouses with import 2024-09-02 14:42:05 +02:00
Ahmed Bouhuolia
266902026e Merge pull request #648 from bigcapitalhq/fix-bank-transactions-infinity-scrolling
fix: Bank transactions infinity scrolling
2024-09-02 10:41:54 +02:00
Ahmed Bouhuolia
791c4a4e9e fix: Bank transactions infinity scrolling 2024-09-02 10:41:16 +02:00
56 changed files with 864 additions and 16 deletions

View File

@@ -34,6 +34,12 @@ export const ITEM_EVENT_DELETED = 'Item deleted';
export const AUTH_SIGNED_UP = 'Auth Signed-up';
export const AUTH_RESET_PASSWORD = 'Auth reset password';
export const BANK_TRANSACTION_MATCHED = 'Bank transaction matching deleted';
export const BANK_TRANSACTION_EXCLUDED = 'Bank transaction excluded';
export const BANK_TRANSACTION_CATEGORIZED = 'Bank transaction categorized';
export const BANK_TRANSACTION_UNCATEGORIZED = 'Bank transaction uncategorized';
export const BANK_ACCOUNT_DISCONNECTED = 'Bank account disconnected';
export const ACCOUNT_GROUP = 'Account';
export const ITEM_GROUP = 'Item';
export const AUTH_GROUP = 'Auth';
@@ -41,3 +47,21 @@ export const SALE_GROUP = 'Sale';
export const PAYMENT_GROUP = 'Payment';
export const BILL_GROUP = 'Bill';
export const EXPENSE_GROUP = 'Expense';
export const MANUAL_JOURNAL_CREATED = 'Manual journal created';
export const MANUAL_JOURNAL_EDITED = 'Manual journal edited';
export const MANUAL_JOURNAL_DELETED = 'Manual journal deleted';
export const MANUAL_JOURNAL_PUBLISHED = 'Manual journal published';
export const CUSTOMER_CREATED = 'Customer created';
export const CUSTOMER_EDITED = 'Customer edited';
export const CUSTOMER_DELETED = 'Customer deleted';
export const VENDOR_CREATED = 'Vendor created';
export const VENDOR_EDITED = 'Vendor edited';
export const VENDOR_DELETED = 'Vendor deleted';
export const BANK_RULE_CREATED = 'Bank rule created';
export const BANK_RULE_EDITED = 'Bank rule edited';
export const BANK_RULE_DELETED = 'Bank rule deleted';

View File

@@ -99,6 +99,7 @@ export interface IBillsFilter extends IDynamicListFilterDTO {
stringifiedFilterRoles?: string;
page: number;
pageSize: number;
filterQuery?: (q: any) => void;
}
export interface IBillsService {

View File

@@ -241,6 +241,7 @@ export interface ICustomerEventCreatingPayload {
trx: Knex.Transaction;
}
export interface ICustomerEventEditedPayload {
tenantId: number
customerId: number;
customer: ICustomer;
trx: Knex.Transaction;

View File

@@ -130,7 +130,9 @@ export interface ICreditNoteOpenedPayload {
trx: Knex.Transaction;
}
export interface ICreditNotesQueryDTO {}
export interface ICreditNotesQueryDTO {
filterQuery?: (query: any) => void;
}
export interface ICreditNotesQueryDTO extends IDynamicListFilter {
page: number;

View File

@@ -17,6 +17,7 @@ export interface IExpensesFilter {
columnSortBy: string;
sortOrder: string;
viewSlug?: string;
filterQuery?: (query: any) => void;
}
export interface IExpense {

View File

@@ -151,6 +151,7 @@ export interface IModelMetaFieldCommon2 {
importHint?: string;
order?: number;
unique?: number;
features?: Array<any>
}
export interface IModelMetaRelationField2 {

View File

@@ -44,6 +44,7 @@ export interface ISaleEstimateDTO {
export interface ISalesEstimatesFilter extends IDynamicListFilterDTO {
stringifiedFilterRoles?: string;
filterQuery?: (q: any) => void;
}
export interface ISalesEstimatesService {

View File

@@ -79,6 +79,7 @@ export interface ISalesInvoicesFilter extends IDynamicListFilter {
page: number;
pageSize: number;
searchKeyword?: string;
filterQuery?: (q: Knex.QueryBuilder) => void;
}
export interface ISalesInvoicesService {

View File

@@ -29,7 +29,9 @@ export interface ISaleReceipt {
entries?: IItemEntry[];
}
export interface ISalesReceiptsFilter {}
export interface ISalesReceiptsFilter {
filterQuery?: (query: any) => void;
}
export interface ISaleReceiptDTO {
customerId: number;

View File

@@ -106,6 +106,7 @@ export interface IVendorCreditsQueryDTO extends IDynamicListFilter {
page: number;
pageSize: number;
searchKeyword?: string;
filterQuery?: (q: any) => void;
}
export interface IVendorCreditEditingPayload {

View File

@@ -1,3 +1,5 @@
import { Features } from '@/interfaces';
export default {
defaultFilterField: 'vendor',
defaultSort: {
@@ -167,6 +169,18 @@ export default {
},
},
},
branch: {
name: 'Branch',
type: 'text',
accessor: 'branch.name',
features: [Features.BRANCHES],
},
warehouse: {
name: 'Warehouse',
type: 'text',
accessor: 'warehouse.name',
features: [Features.BRANCHES],
},
},
fields2: {
billNumber: {
@@ -238,6 +252,22 @@ export default {
},
},
},
branchId: {
name: 'Branch',
fieldType: 'relation',
relationModel: 'Branch',
relationImportMatch: ['name', 'code'],
features: [Features.BRANCHES],
required: true,
},
warehouseId: {
name: 'Warehouse',
fieldType: 'relation',
relationModel: 'Warehouse',
relationImportMatch: ['name', 'code'],
features: [Features.WAREHOUSES],
required: true,
},
},
};

View File

@@ -402,6 +402,7 @@ export default class Bill extends mixin(TenantModel, [
const ItemEntry = require('models/ItemEntry');
const BillLandedCost = require('models/BillLandedCost');
const Branch = require('models/Branch');
const Warehouse = require('models/Warehouse');
const TaxRateTransaction = require('models/TaxRateTransaction');
const Document = require('models/Document');
const { MatchedBankTransaction } = require('models/MatchedBankTransaction');
@@ -453,6 +454,18 @@ export default class Bill extends mixin(TenantModel, [
},
},
/**
* Bill may has associated warehouse.
*/
warehouse: {
relation: Model.BelongsToOneRelation,
modelClass: Warehouse.default,
join: {
from: 'bills.warehouseId',
to: 'warehouses.id',
},
},
/**
* Bill may has associated tax rate transactions.
*/

View File

@@ -1,3 +1,5 @@
import { Features } from '@/interfaces';
export default {
defaultFilterField: 'vendor',
defaultSort: {
@@ -141,6 +143,12 @@ export default {
},
},
},
branch: {
name: 'Branch',
type: 'text',
accessor: 'branch.name',
features: [Features.BRANCHES],
},
},
fields2: {
vendorId: {
@@ -204,5 +212,13 @@ export default {
},
},
},
branchId: {
name: 'Branch',
fieldType: 'relation',
relationModel: 'Branch',
relationImportMatch: ['name', 'code'],
features: [Features.BRANCHES],
required: true,
},
},
};

View File

@@ -0,0 +1,11 @@
export default {
fields2: {
name: {
name: 'Name',
fieldType: 'text',
required: true,
},
},
columns: {},
fields: {}
};

View File

@@ -1,7 +1,9 @@
import { Model } from 'objection';
import { Model, mixin } from 'objection';
import TenantModel from 'models/TenantModel';
import BranchMetadata from './Branch.settings';
import ModelSetting from './ModelSetting';
export default class Branch extends TenantModel {
export default class Branch extends mixin(TenantModel, [ModelSetting]) {
/**
* Table name.
*/
@@ -169,4 +171,11 @@ export default class Branch extends TenantModel {
},
};
}
/**
* Model settings.
*/
static get meta() {
return BranchMetadata;
}
}

View File

@@ -1,3 +1,5 @@
import { Features } from '@/interfaces';
function StatusFieldFilterQuery(query, role) {
query.modify('filterByStatus', role.value);
}
@@ -100,7 +102,7 @@ export default {
},
creditNoteDate: {
name: 'Credit Note Date',
accessor: 'formattedCreditNoteDate'
accessor: 'formattedCreditNoteDate',
},
referenceNo: {
name: 'Reference No.',
@@ -147,6 +149,18 @@ export default {
},
},
},
branch: {
name: 'Branch',
type: 'text',
accessor: 'branch.name',
features: [Features.BRANCHES],
},
warehouse: {
name: 'Warehouse',
type: 'text',
accessor: 'warehouse.name',
features: [Features.BRANCHES],
},
},
fields2: {
customerId: {
@@ -215,5 +229,21 @@ export default {
},
},
},
branchId: {
name: 'Branch',
fieldType: 'relation',
relationModel: 'Branch',
relationImportMatch: ['name', 'code'],
features: [Features.BRANCHES],
required: true,
},
warehouseId: {
name: 'Warehouse',
fieldType: 'relation',
relationModel: 'Warehouse',
relationImportMatch: ['name', 'code'],
features: [Features.WAREHOUSES],
required: true,
},
},
};

View File

@@ -175,6 +175,7 @@ export default class CreditNote extends mixin(TenantModel, [
const Customer = require('models/Customer');
const Branch = require('models/Branch');
const Document = require('models/Document');
const Warehouse = require('models/Warehouse');
return {
/**
@@ -235,6 +236,18 @@ export default class CreditNote extends mixin(TenantModel, [
},
},
/**
* Credit note may has associated warehouse.
*/
warehouse: {
relation: Model.BelongsToOneRelation,
modelClass: Warehouse.default,
join: {
from: 'credit_notes.warehouseId',
to: 'warehouses.id',
},
},
/**
* Credit note may has many attached attachments.
*/

View File

@@ -1,3 +1,5 @@
import { Features } from '@/interfaces';
/**
* Expense - Settings.
*/
@@ -119,6 +121,12 @@ export default {
type: 'boolean',
printable: false,
},
branch: {
name: 'Branch',
type: 'text',
accessor: 'branch.name',
features: [Features.BRANCHES],
},
},
fields2: {
paymentAccountId: {
@@ -178,6 +186,14 @@ export default {
name: 'expense.field.publish',
fieldType: 'boolean',
},
branchId: {
name: 'Branch',
fieldType: 'relation',
relationModel: 'Branch',
relationImportMatch: ['name', 'code'],
features: [Features.BRANCHES],
required: true,
},
},
};

View File

@@ -1,3 +1,5 @@
import { Features } from '@/interfaces';
export default {
importable: true,
@@ -128,6 +130,12 @@ export default {
type: 'date',
printable: false,
},
branch: {
name: 'Branch',
type: 'text',
accessor: 'branch.name',
features: [Features.BRANCHES],
},
},
fields2: {
customerId: {
@@ -189,5 +197,13 @@ export default {
},
},
},
branchId: {
name: 'Branch',
fieldType: 'relation',
relationModel: 'Branch',
relationImportMatch: ['name', 'code'],
features: [Features.BRANCHES],
required: true,
},
},
};

View File

@@ -1,3 +1,5 @@
import { Features } from '@/interfaces';
export default {
defaultFilterField: 'estimate_date',
defaultSort: {
@@ -174,6 +176,18 @@ export default {
},
},
},
branch: {
name: 'Branch',
type: 'text',
accessor: 'branch.name',
features: [Features.BRANCHES],
},
warehouse: {
name: 'Warehouse',
type: 'text',
accessor: 'warehouse.name',
features: [Features.BRANCHES],
},
},
fields2: {
customerId: {
@@ -252,6 +266,22 @@ export default {
},
},
},
branchId: {
name: 'Branch',
fieldType: 'relation',
relationModel: 'Branch',
relationImportMatch: ['name', 'code'],
features: [Features.BRANCHES],
required: true,
},
warehouseId: {
name: 'Warehouse',
fieldType: 'relation',
relationModel: 'Warehouse',
relationImportMatch: ['name', 'code'],
features: [Features.WAREHOUSES],
required: true,
},
},
};

View File

@@ -182,6 +182,7 @@ export default class SaleEstimate extends mixin(TenantModel, [
const ItemEntry = require('models/ItemEntry');
const Customer = require('models/Customer');
const Branch = require('models/Branch');
const Warehouse = require('models/Warehouse');
const Document = require('models/Document');
return {
@@ -221,6 +222,18 @@ export default class SaleEstimate extends mixin(TenantModel, [
},
},
/**
* Sale estimate may has associated warehouse.
*/
warehouse: {
relation: Model.BelongsToOneRelation,
modelClass: Warehouse.default,
join: {
from: 'sales_estimates.warehouseId',
to: 'warehouses.id',
},
},
/**
* Sale estimate transaction may has many attached attachments.
*/

View File

@@ -1,3 +1,5 @@
import { Features } from '@/interfaces';
export default {
defaultFilterField: 'customer',
defaultSort: {
@@ -185,6 +187,18 @@ export default {
},
},
},
branch: {
name: 'Branch',
type: 'text',
accessor: 'branch.name',
features: [Features.BRANCHES],
},
warehouse: {
name: 'Warehouse',
type: 'text',
accessor: 'warehouse.name',
features: [Features.BRANCHES],
},
},
fields2: {
invoiceDate: {
@@ -268,6 +282,22 @@ export default {
fieldType: 'boolean',
printable: false,
},
branchId: {
name: 'Branch',
fieldType: 'relation',
relationModel: 'Branch',
relationImportMatch: ['name', 'code'],
features: [Features.BRANCHES],
required: true,
},
warehouseId: {
name: 'Warehouse',
fieldType: 'relation',
relationModel: 'Warehouse',
relationImportMatch: ['name', 'code'],
features: [Features.WAREHOUSES],
required: true,
},
},
};

View File

@@ -408,6 +408,7 @@ export default class SaleInvoice extends mixin(TenantModel, [
const InventoryCostLotTracker = require('models/InventoryCostLotTracker');
const PaymentReceiveEntry = require('models/PaymentReceiveEntry');
const Branch = require('models/Branch');
const Warehouse = require('models/Warehouse');
const Account = require('models/Account');
const TaxRateTransaction = require('models/TaxRateTransaction');
const Document = require('models/Document');
@@ -499,6 +500,18 @@ export default class SaleInvoice extends mixin(TenantModel, [
},
},
/**
* Invoice may has associated warehouse.
*/
warehouse: {
relation: Model.BelongsToOneRelation,
modelClass: Warehouse.default,
join: {
from: 'sales_invoices.warehouseId',
to: 'warehouses.id',
}
},
/**
* Invoice may has associated written-off expense account.
*/

View File

@@ -1,3 +1,5 @@
import { Features } from '@/interfaces';
export default {
defaultFilterField: 'receipt_date',
defaultSort: {
@@ -169,6 +171,18 @@ export default {
type: 'date',
printable: false,
},
branch: {
name: 'Branch',
type: 'text',
accessor: 'branch.name',
features: [Features.BRANCHES],
},
warehouse: {
name: 'Warehouse',
type: 'text',
accessor: 'warehouse.name',
features: [Features.BRANCHES],
},
},
fields2: {
receiptDate: {
@@ -245,6 +259,22 @@ export default {
name: 'Receipt Message',
fieldType: 'text',
},
branchId: {
name: 'Branch',
fieldType: 'relation',
relationModel: 'Branch',
relationImportMatch: ['name', 'code'],
features: [Features.BRANCHES],
required: true,
},
warehouseId: {
name: 'Warehouse',
fieldType: 'relation',
relationModel: 'Warehouse',
relationImportMatch: ['name', 'code'],
features: [Features.WAREHOUSES],
required: true,
},
},
};

View File

@@ -109,6 +109,7 @@ export default class SaleReceipt extends mixin(TenantModel, [
const ItemEntry = require('models/ItemEntry');
const Branch = require('models/Branch');
const Document = require('models/Document');
const Warehouse = require('models/Warehouse');
return {
customer: {
@@ -169,6 +170,18 @@ export default class SaleReceipt extends mixin(TenantModel, [
},
},
/**
* Sale receipt may has associated warehouse.
*/
warehouse: {
relation: Model.BelongsToOneRelation,
modelClass: Warehouse.default,
join: {
from: 'sales_receipts.warehouseId',
to: 'warehouses.id',
},
},
/**
* Sale receipt transaction may has many attached attachments.
*/

View File

@@ -1,3 +1,5 @@
import { Features } from '@/interfaces';
function StatusFieldFilterQuery(query, role) {
query.modify('filterByStatus', role.value);
}
@@ -160,6 +162,18 @@ export default {
},
},
},
branch: {
name: 'Branch',
type: 'text',
accessor: 'branch.name',
features: [Features.BRANCHES],
},
warehouse: {
name: 'Warehouse',
type: 'text',
accessor: 'warehouse.name',
features: [Features.BRANCHES],
},
},
fields2: {
vendorId: {
@@ -225,5 +239,21 @@ export default {
},
},
},
branchId: {
name: 'Branch',
fieldType: 'relation',
relationModel: 'Branch',
relationImportMatch: ['name', 'code'],
features: [Features.BRANCHES],
required: true
},
warehouseId: {
name: 'Warehouse',
fieldType: 'relation',
relationModel: 'Warehouse',
relationImportMatch: ['name', 'code'],
features: [Features.WAREHOUSES],
required: true
},
},
};

View File

@@ -178,6 +178,7 @@ export default class VendorCredit extends mixin(TenantModel, [
const ItemEntry = require('models/ItemEntry');
const Branch = require('models/Branch');
const Document = require('models/Document');
const Warehouse = require('models/Warehouse');
return {
vendor: {
@@ -217,6 +218,18 @@ export default class VendorCredit extends mixin(TenantModel, [
},
},
/**
* Vendor credit may has associated warehouse.
*/
warehouse: {
relation: Model.BelongsToOneRelation,
modelClass: Warehouse.default,
join: {
from: 'vendor_credits.warehouseId',
to: 'warehouses.id',
},
},
/**
* Vendor credit may has many attached attachments.
*/

View File

@@ -0,0 +1,11 @@
export default {
fields2: {
name: {
name: 'Name',
fieldType: 'text',
required: true,
},
},
columns: {},
fields: {}
};

View File

@@ -65,6 +65,7 @@ export class EditCustomer {
});
// Triggers `onCustomerEdited` event.
await this.eventPublisher.emitAsync(events.customers.onEdited, {
tenantId,
customerId,
customer,
trx,

View File

@@ -15,12 +15,17 @@ export class CreditNotesExportable extends Exportable {
* @returns {}
*/
public exportable(tenantId: number, query: ICreditNotesQueryDTO) {
const filterQuery = (query) => {
query.withGraphFetched('branch');
query.withGraphFetched('warehouse');
};
const parsedQuery = {
sortOrder: 'desc',
columnSortBy: 'created_at',
...query,
page: 1,
pageSize: 12000,
filterQuery,
} as ICreditNotesQueryDTO;
return this.getCreditNotes

View File

@@ -48,6 +48,7 @@ export default class ListCreditNotes extends BaseCreditNotes {
builder.withGraphFetched('entries.item');
builder.withGraphFetched('customer');
dynamicFilter.buildQuery()(builder);
creditNotesQuery?.filterQuery && creditNotesQuery?.filterQuery(builder);
})
.pagination(filter.page - 1, filter.pageSize);

View File

@@ -0,0 +1,68 @@
import { Inject, Service } from 'typedi';
import { EventSubscriber } from '@/lib/EventPublisher/EventPublisher';
import {
IBankRuleEventCreatedPayload,
IBankRuleEventEditedPayload,
IBankRuleEventDeletedPayload,
} from '@/services/Banking/Rules/types'; // Updated import path for interfaces
import { PosthogService } from '../PostHog';
import events from '@/subscribers/events';
import {
BANK_RULE_CREATED,
BANK_RULE_EDITED,
BANK_RULE_DELETED,
} from '@/constants/event-tracker';
@Service()
export class BankRuleEventsTracker extends EventSubscriber {
@Inject()
private posthog: PosthogService;
/**
* Constructor method.
*/
public attach(bus) {
bus.subscribe(
events.bankRules.onCreated,
this.handleTrackBankRuleCreatedEvent
);
bus.subscribe(
events.bankRules.onEdited,
this.handleTrackEditedBankRuleEvent
);
bus.subscribe(
events.bankRules.onDeleted,
this.handleTrackDeletedBankRuleEvent
);
}
private handleTrackBankRuleCreatedEvent = ({
tenantId,
}: IBankRuleEventCreatedPayload) => {
this.posthog.trackEvent({
distinctId: `tenant-${tenantId}`,
event: BANK_RULE_CREATED,
properties: {},
});
};
private handleTrackEditedBankRuleEvent = ({
tenantId,
}: IBankRuleEventEditedPayload) => {
this.posthog.trackEvent({
distinctId: `tenant-${tenantId}`,
event: BANK_RULE_EDITED,
properties: {},
});
};
private handleTrackDeletedBankRuleEvent = ({
tenantId,
}: IBankRuleEventDeletedPayload) => {
this.posthog.trackEvent({
distinctId: `tenant-${tenantId}`,
event: BANK_RULE_DELETED,
properties: {},
});
};
}

View File

@@ -0,0 +1,97 @@
import { Inject, Service } from 'typedi';
import { EventSubscriber } from '@/lib/EventPublisher/EventPublisher';
import { PosthogService } from '../PostHog';
import events from '@/subscribers/events';
import {
BANK_TRANSACTION_MATCHED,
BANK_TRANSACTION_EXCLUDED,
BANK_TRANSACTION_CATEGORIZED,
BANK_TRANSACTION_UNCATEGORIZED,
BANK_ACCOUNT_DISCONNECTED,
} from '@/constants/event-tracker';
import { IBankTransactionMatchedEventPayload } from '@/services/Banking/Matching/types';
import { IBankAccountDisconnectedEventPayload } from '@/services/Banking/BankAccounts/types';
import {
ICashflowTransactionCategorizedPayload,
ICashflowTransactionUncategorizedPayload,
} from '@/interfaces';
import { IBankTransactionExcludedEventPayload } from '@/services/Banking/Exclude/_types';
@Service()
export class BankTransactionEventsTracker extends EventSubscriber {
@Inject()
private posthog: PosthogService;
public attach(bus) {
bus.subscribe(
events.bankMatch.onMatched,
this.handleTrackBankTransactionMatchedEvent
);
bus.subscribe(
events.bankTransactions.onExcluded,
this.handleTrackBankTransactionExcludedEvent
);
bus.subscribe(
events.cashflow.onTransactionCategorized,
this.handleTrackBankTransactionCategorizedEvent
);
bus.subscribe(
events.cashflow.onTransactionUncategorized,
this.handleTrackBankTransactionUncategorizedEvent
);
bus.subscribe(
events.bankAccount.onDisconnected,
this.handleTrackBankAccountDisconnectedEvent
);
}
private handleTrackBankTransactionMatchedEvent = ({
tenantId,
}: IBankTransactionMatchedEventPayload) => {
this.posthog.trackEvent({
distinctId: `tenant-${tenantId}`,
event: BANK_TRANSACTION_MATCHED,
properties: {},
});
};
private handleTrackBankTransactionExcludedEvent = ({
tenantId,
}: IBankTransactionExcludedEventPayload) => {
this.posthog.trackEvent({
distinctId: `tenant-${tenantId}`,
event: BANK_TRANSACTION_EXCLUDED,
properties: {},
});
};
private handleTrackBankTransactionCategorizedEvent = ({
tenantId,
}: ICashflowTransactionCategorizedPayload) => {
this.posthog.trackEvent({
distinctId: `tenant-${tenantId}`,
event: BANK_TRANSACTION_CATEGORIZED,
properties: {},
});
};
private handleTrackBankTransactionUncategorizedEvent = ({
tenantId,
}: ICashflowTransactionUncategorizedPayload) => {
this.posthog.trackEvent({
distinctId: `tenant-${tenantId}`,
event: BANK_TRANSACTION_UNCATEGORIZED,
properties: {},
});
};
private handleTrackBankAccountDisconnectedEvent = ({
tenantId,
}: IBankAccountDisconnectedEventPayload) => {
this.posthog.trackEvent({
distinctId: `tenant-${tenantId}`,
event: BANK_ACCOUNT_DISCONNECTED,
properties: {},
});
};
}

View File

@@ -0,0 +1,68 @@
import { Inject, Service } from 'typedi';
import { EventSubscriber } from '@/lib/EventPublisher/EventPublisher';
import {
ICustomerEventCreatedPayload,
ICustomerEventEditedPayload,
ICustomerEventDeletedPayload,
} from '@/interfaces';
import { PosthogService } from '../PostHog';
import events from '@/subscribers/events';
import {
CUSTOMER_CREATED,
CUSTOMER_EDITED,
CUSTOMER_DELETED,
} from '@/constants/event-tracker';
@Service()
export class CustomerEventsTracker extends EventSubscriber {
@Inject()
private posthog: PosthogService;
/**
* Constructor method.
*/
public attach(bus) {
bus.subscribe(
events.customers.onCreated,
this.handleTrackCustomerCreatedEvent
);
bus.subscribe(
events.customers.onEdited,
this.handleTrackEditedCustomerEvent
);
bus.subscribe(
events.customers.onDeleted,
this.handleTrackDeletedCustomerEvent
);
}
private handleTrackCustomerCreatedEvent = ({
tenantId,
}: ICustomerEventCreatedPayload) => {
this.posthog.trackEvent({
distinctId: `tenant-${tenantId}`,
event: CUSTOMER_CREATED,
properties: {},
});
};
private handleTrackEditedCustomerEvent = ({
tenantId,
}: ICustomerEventEditedPayload) => {
this.posthog.trackEvent({
distinctId: `tenant-${tenantId}`,
event: CUSTOMER_EDITED,
properties: {},
});
};
private handleTrackDeletedCustomerEvent = ({
tenantId,
}: ICustomerEventDeletedPayload) => {
this.posthog.trackEvent({
distinctId: `tenant-${tenantId}`,
event: CUSTOMER_DELETED,
properties: {},
});
};
}

View File

@@ -0,0 +1,68 @@
import { Inject, Service } from 'typedi';
import { EventSubscriber } from '@/lib/EventPublisher/EventPublisher';
import {
IManualJournalEventCreatedPayload,
IManualJournalEventEditedPayload,
IManualJournalEventDeletedPayload,
} from '@/interfaces';
import { PosthogService } from '../PostHog';
import events from '@/subscribers/events';
import {
MANUAL_JOURNAL_CREATED,
MANUAL_JOURNAL_EDITED,
MANUAL_JOURNAL_DELETED,
} from '@/constants/event-tracker';
@Service()
export class ManualJournalEventsTracker extends EventSubscriber {
@Inject()
private posthog: PosthogService;
/**
* Constructor method.
*/
public attach(bus) {
bus.subscribe(
events.manualJournals.onCreated,
this.handleTrackManualJournalCreatedEvent
);
bus.subscribe(
events.manualJournals.onEdited,
this.handleTrackEditedManualJournalEvent
);
bus.subscribe(
events.manualJournals.onDeleted,
this.handleTrackDeletedManualJournalEvent
);
}
private handleTrackManualJournalCreatedEvent = ({
tenantId,
}: IManualJournalEventCreatedPayload) => {
this.posthog.trackEvent({
distinctId: `tenant-${tenantId}`,
event: MANUAL_JOURNAL_CREATED,
properties: {},
});
};
private handleTrackEditedManualJournalEvent = ({
tenantId,
}: IManualJournalEventEditedPayload) => {
this.posthog.trackEvent({
distinctId: `tenant-${tenantId}`,
event: MANUAL_JOURNAL_EDITED,
properties: {},
});
};
private handleTrackDeletedManualJournalEvent = ({
tenantId,
}: IManualJournalEventDeletedPayload) => {
this.posthog.trackEvent({
distinctId: `tenant-${tenantId}`,
event: MANUAL_JOURNAL_DELETED,
properties: {},
});
};
}

View File

@@ -0,0 +1,59 @@
import { Inject, Service } from 'typedi';
import { EventSubscriber } from '@/lib/EventPublisher/EventPublisher';
import {
IVendorEventCreatedPayload,
IVendorEventEditedPayload,
IVendorEventDeletedPayload,
} from '@/interfaces';
import { PosthogService } from '../PostHog';
import events from '@/subscribers/events';
import {
VENDOR_CREATED,
VENDOR_EDITED,
VENDOR_DELETED,
} from '@/constants/event-tracker';
@Service()
export class VendorEventsTracker extends EventSubscriber {
@Inject()
private posthog: PosthogService;
/**
* Constructor method.
*/
public attach(bus) {
bus.subscribe(events.vendors.onCreated, this.handleTrackVendorCreatedEvent);
bus.subscribe(events.vendors.onEdited, this.handleTrackEditedVendorEvent);
bus.subscribe(events.vendors.onDeleted, this.handleTrackDeletedVendorEvent);
}
private handleTrackVendorCreatedEvent = ({
tenantId,
}: IVendorEventCreatedPayload) => {
this.posthog.trackEvent({
distinctId: `tenant-${tenantId}`,
event: VENDOR_CREATED,
properties: {},
});
};
private handleTrackEditedVendorEvent = ({
tenantId,
}: IVendorEventEditedPayload) => {
this.posthog.trackEvent({
distinctId: `tenant-${tenantId}`,
event: VENDOR_EDITED,
properties: {},
});
};
private handleTrackDeletedVendorEvent = ({
tenantId,
}: IVendorEventDeletedPayload) => {
this.posthog.trackEvent({
distinctId: `tenant-${tenantId}`,
event: VENDOR_DELETED,
properties: {},
});
};
}

View File

@@ -7,6 +7,11 @@ import { ExpenseEventsTracker } from './ExpenseEventsTracker';
import { AccountEventsTracker } from './AccountEventsTracker';
import { AuthenticationEventsTracker } from './AuthenticationEventsTracker';
import { ItemEventsTracker } from './ItemEventsTracker';
import { BankTransactionEventsTracker } from './BankTransactionEventsTracker';
import { CustomerEventsTracker } from './CustomerEventsTracker';
import { VendorEventsTracker } from './VendorEventsTracker';
import { ManualJournalEventsTracker } from './ManualJournalEventsTracker';
import { BankRuleEventsTracker } from './BankRuleEventsTracker';
export const EventsTrackerListeners = [
SaleInvoiceEventsTracker,
@@ -17,5 +22,10 @@ export const EventsTrackerListeners = [
AccountEventsTracker,
ExpenseEventsTracker,
AuthenticationEventsTracker,
ItemEventsTracker
ItemEventsTracker,
BankTransactionEventsTracker,
CustomerEventsTracker,
VendorEventsTracker,
ManualJournalEventsTracker,
BankRuleEventsTracker,
];

View File

@@ -54,6 +54,7 @@ export class GetExpenses {
builder.withGraphFetched('categories.expenseAccount');
dynamicList.buildQuery()(builder);
filterDTO?.filterQuery && filterDTO?.filterQuery(builder);
})
.pagination(filter.page - 1, filter.pageSize);

View File

@@ -15,12 +15,16 @@ export class ExpensesExportable extends Exportable {
* @returns
*/
public exportable(tenantId: number, query: IExpensesFilter) {
const filterQuery = (query) => {
query.withGraphFetched('branch');
};
const parsedQuery = {
sortOrder: 'desc',
columnSortBy: 'created_at',
...query,
page: 1,
pageSize: EXPORT_SIZE_LIMIT,
filterQuery,
} as IExpensesFilter;
return this.expensesApplication

View File

@@ -56,7 +56,10 @@ export class ExportResourceService {
) {
const resource = sanitizeResourceName(resourceName);
const resourceMeta = this.getResourceMeta(tenantId, resource);
const resourceColumns = this.resourceService.getResourceColumns(
tenantId,
resource
);
this.validateResourceMeta(resourceMeta);
const data = await this.getExportableData(tenantId, resource);
@@ -64,7 +67,7 @@ export class ExportResourceService {
// Returns the csv, xlsx format.
if (format === ExportFormat.Csv || format === ExportFormat.Xlsx) {
const exportableColumns = this.getExportableColumns(resourceMeta);
const exportableColumns = this.getExportableColumns(resourceColumns);
const workbook = this.createWorkbook(transformed, exportableColumns);
return this.exportWorkbook(workbook, format);
@@ -143,7 +146,7 @@ export class ExportResourceService {
* @param {IModelMeta} resourceMeta - The metadata of the resource.
* @returns An array of exportable columns.
*/
private getExportableColumns(resourceMeta: IModelMeta) {
private getExportableColumns(resourceColumns: any) {
const processColumns = (
columns: { [key: string]: IModelMetaColumn },
parent = ''
@@ -166,7 +169,7 @@ export class ExportResourceService {
}
});
};
return processColumns(resourceMeta.columns);
return processColumns(resourceColumns);
}
private getPrintableColumns(resourceMeta: IModelMeta) {

View File

@@ -33,6 +33,8 @@ export class ImportFileMapping {
// Invalidate the from/to map attributes.
this.validateMapsAttrs(tenantId, importFile, maps);
// @todo validate the required fields.
// Validate the diplicated relations of map attrs.
this.validateDuplicatedMapAttrs(maps);

View File

@@ -16,6 +16,7 @@ export class BillPaymentExportable extends Exportable {
public exportable(tenantId: number, query: any) {
const filterQuery = (builder) => {
builder.withGraphFetched('entries.bill');
builder.withGraphFetched('branch');
};
const parsedQuery = {
sortOrder: 'desc',

View File

@@ -1,8 +1,10 @@
import { Inject, Service } from 'typedi';
import { Knex } from 'knex';
import { IBillsFilter } from '@/interfaces';
import { Exportable } from '@/services/Export/Exportable';
import { BillsApplication } from './BillsApplication';
import { EXPORT_SIZE_LIMIT } from '@/services/Export/constants';
import Objection from 'objection';
@Service()
export class BillsExportable extends Exportable {
@@ -15,12 +17,17 @@ export class BillsExportable extends Exportable {
* @returns
*/
public exportable(tenantId: number, query: IBillsFilter) {
const filterQuery = (query) => {
query.withGraphFetched('branch');
query.withGraphFetched('warehouse');
};
const parsedQuery = {
sortOrder: 'desc',
columnSortBy: 'created_at',
...query,
page: 1,
pageSize: EXPORT_SIZE_LIMIT,
filterQuery,
} as IBillsFilter;
return this.billsApplication

View File

@@ -51,6 +51,9 @@ export class GetBills {
builder.withGraphFetched('vendor');
builder.withGraphFetched('entries.item');
dynamicFilter.buildQuery()(builder);
// Filter query.
filterDTO?.filterQuery && filterDTO?.filterQuery(builder);
})
.pagination(filter.page - 1, filter.pageSize);

View File

@@ -48,6 +48,10 @@ export default class ListVendorCredits extends BaseVendorCredit {
builder.withGraphFetched('entries');
builder.withGraphFetched('vendor');
dynamicFilter.buildQuery()(builder);
// Gives ability to inject custom query to filter results.
vendorCreditQuery?.filterQuery &&
vendorCreditQuery?.filterQuery(builder);
})
.pagination(filter.page - 1, filter.pageSize);

View File

@@ -2,6 +2,7 @@ import { Inject, Service } from 'typedi';
import { IVendorCreditsQueryDTO } from '@/interfaces';
import ListVendorCredits from './ListVendorCredits';
import { Exportable } from '@/services/Export/Exportable';
import { QueryBuilder } from 'knex';
@Service()
export class VendorCreditsExportable extends Exportable {
@@ -15,12 +16,17 @@ export class VendorCreditsExportable extends Exportable {
* @returns {}
*/
public exportable(tenantId: number, query: IVendorCreditsQueryDTO) {
const filterQuery = (query) => {
query.withGraphFetched('branch');
query.withGraphFetched('warehouse');
};
const parsedQuery = {
sortOrder: 'desc',
columnSortBy: 'created_at',
...query,
page: 1,
pageSize: 12000,
filterQuery,
} as IVendorCreditsQueryDTO;
return this.getVendorCredits

View File

@@ -1,11 +1,18 @@
import { Service, Inject } from 'typedi';
import { camelCase, upperFirst, pickBy } from 'lodash';
import { camelCase, upperFirst, pickBy, isEmpty } from 'lodash';
import * as qim from 'qim';
import pluralize from 'pluralize';
import { IModelMeta, IModelMetaField, IModelMetaField2 } from '@/interfaces';
import {
Features,
IModelMeta,
IModelMetaField,
IModelMetaField2,
} from '@/interfaces';
import TenancyService from '@/services/Tenancy/TenancyService';
import { ServiceError } from '@/exceptions';
import I18nService from '@/services/I18n/I18nService';
import { WarehousesSettings } from '../Warehouses/WarehousesSettings';
import { BranchesSettings } from '../Branches/BranchesSettings';
const ERRORS = {
RESOURCE_MODEL_NOT_FOUND: 'RESOURCE_MODEL_NOT_FOUND',
@@ -19,6 +26,12 @@ export default class ResourceService {
@Inject()
i18nService: I18nService;
@Inject()
private branchesSettings: BranchesSettings;
@Inject()
private warehousesSettings: WarehousesSettings;
/**
* Transform resource to model name.
* @param {string} resourceName
@@ -74,13 +87,45 @@ export default class ResourceService {
return meta.fields;
}
public filterSupportFeatures = (
tenantId,
fields: { [key: string]: IModelMetaField2 }
) => {
const isMultiFeaturesEnabled =
this.branchesSettings.isMultiBranchesActive(tenantId);
const isMultiWarehousesEnabled =
this.warehousesSettings.isMultiWarehousesActive(tenantId);
return pickBy(fields, (field) => {
if (
!isMultiWarehousesEnabled &&
field.features?.includes(Features.WAREHOUSES)
) {
return false;
}
if (
!isMultiFeaturesEnabled &&
field.features?.includes(Features.BRANCHES)
) {
return false;
}
return true;
});
};
public getResourceFields2(
tenantId: number,
modelName: string
): { [key: string]: IModelMetaField2 } {
const meta = this.getResourceMeta(tenantId, modelName);
return meta.fields2;
return this.filterSupportFeatures(tenantId, meta.fields2);
}
public getResourceColumns(tenantId: number, modelName: string) {
const meta = this.getResourceMeta(tenantId, modelName);
return this.filterSupportFeatures(tenantId, meta.columns);
}
/**

View File

@@ -53,6 +53,7 @@ export class GetSaleEstimates {
builder.withGraphFetched('entries');
builder.withGraphFetched('entries.item');
dynamicFilter.buildQuery()(builder);
filterDTO?.filterQuery && filterDTO?.filterQuery(builder);
})
.pagination(filter.page - 1, filter.pageSize);

View File

@@ -15,12 +15,17 @@ export class SaleEstimatesExportable extends Exportable {
* @returns
*/
public exportable(tenantId: number, query: ISalesInvoicesFilter) {
const filterQuery = (query) => {
query.withGraphFetched('branch');
query.withGraphFetched('warehouse');
};
const parsedQuery = {
sortOrder: 'desc',
columnSortBy: 'created_at',
...query,
page: 1,
pageSize: EXPORT_SIZE_LIMIT,
filterQuery,
} as ISalesInvoicesFilter;
return this.saleEstimatesApplication

View File

@@ -52,6 +52,7 @@ export class GetSaleInvoices {
builder.withGraphFetched('entries.item');
builder.withGraphFetched('customer');
dynamicFilter.buildQuery()(builder);
filterDTO?.filterQuery && filterDTO?.filterQuery(builder);
})
.pagination(filter.page - 1, filter.pageSize);

View File

@@ -15,12 +15,17 @@ export class SaleInvoicesExportable extends Exportable {
* @returns
*/
public exportable(tenantId: number, query: ISalesInvoicesFilter) {
const filterQuery = (query) => {
query.withGraphFetched('branch');
query.withGraphFetched('warehouse');
};
const parsedQuery = {
sortOrder: 'desc',
columnSortBy: 'created_at',
...query,
page: 1,
pageSize: EXPORT_SIZE_LIMIT,
filterQuery,
} as ISalesInvoicesFilter;
return this.saleInvoicesApplication

View File

@@ -18,6 +18,7 @@ export class PaymentsReceivedExportable extends Exportable {
public exportable(tenantId: number, query: IPaymentsReceivedFilter) {
const filterQuery = (builder) => {
builder.withGraphFetched('entries.invoice');
builder.withGraphFetched('branch');
};
const parsedQuery = {

View File

@@ -56,6 +56,7 @@ export class GetSaleReceipts {
builder.withGraphFetched('entries.item');
dynamicFilter.buildQuery()(builder);
filterDTO?.filterQuery && filterDTO?.filterQuery(builder);
})
.pagination(filter.page - 1, filter.pageSize);

View File

@@ -15,12 +15,17 @@ export class SaleReceiptsExportable extends Exportable {
* @returns
*/
public exportable(tenantId: number, query: ISalesReceiptsFilter) {
const filterQuery = (query) => {
query.withGraphFetched('branch');
query.withGraphFetched('warehouse');
};
const parsedQuery = {
sortOrder: 'desc',
columnSortBy: 'created_at',
...query,
page: 1,
pageSize: EXPORT_SIZE_LIMIT,
filterQuery,
} as ISalesReceiptsFilter;
return this.saleReceiptsApp

View File

@@ -22,6 +22,7 @@ import { withBankingActions } from '../withBankingActions';
import { useMemorizedColumnsWidths } from '@/hooks';
import { useAccountTransactionsColumns, ActionsMenu } from './components';
import { useAccountTransactionsAllContext } from './AccountTransactionsAllBoot';
import { useAccountTransactionsContext } from './AccountTransactionsProvider';
import { useUnmatchMatchedUncategorizedTransaction } from '@/hooks/query/bank-rules';
import { useUncategorizeTransaction } from '@/hooks/query';
import { handleCashFlowTransactionType } from './utils';
@@ -62,6 +63,8 @@ function AccountTransactionsDataTable({
const [initialColumnsWidths, , handleColumnResizing] =
useMemorizedColumnsWidths(TABLES.CASHFLOW_Transactions);
const { scrollableRef } = useAccountTransactionsContext();
// Handle view details action.
const handleViewDetailCashflowTransaction = (referenceType) => {
handleCashFlowTransactionType(referenceType, openDrawer);
@@ -132,7 +135,7 @@ function AccountTransactionsDataTable({
ContextMenu={ActionsMenu}
onCellClick={handleCellClick}
// #TableVirtualizedListRows props.
vListrowHeight={cashflowTansactionsTableSize == 'small' ? 32 : 40}
vListrowHeight={32}
vListOverscanRowCount={0}
initialColumnsWidths={initialColumnsWidths}
onColumnResizing={handleColumnResizing}
@@ -140,6 +143,7 @@ function AccountTransactionsDataTable({
onSelectedRowsChange={handleSelectedRowsChange}
noResults={<T id={'cash_flow.account_transactions.no_results'} />}
className="table-constrant"
windowScrollerProps={{ scrollElement: scrollableRef }}
payload={{
onViewDetails: handleViewDetailCashflowTransaction,
onUncategorize: handleUncategorizeTransaction,

View File

@@ -7,10 +7,10 @@ export default function ReceiptsImport() {
const history = useHistory();
const handleCancelBtnClick = () => {
history.push('/accounts');
history.push('/receipts');
};
const handleImportSuccess = () => {
history.push('/accounts');
history.push('/receipts');
};
return (