From 936800600b1327175dd7ee10006edd4e6c20a452 Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Wed, 15 Jan 2025 14:14:44 +0200 Subject: [PATCH] refactor: inventory to nestjs --- .../src/modules/Accounts/Accounts.module.ts | 5 +- .../src/modules/Accounts/Accounts.types.ts | 1 + .../modules/Accounts/CreateAccount.service.ts | 18 +- .../modules/Accounts/models/Account.model.ts | 3 +- .../BankingAccounts/BankAccounts.module.ts | 2 +- .../BankingTransactions.module.ts | 14 +- .../BankingTransactions/models/BankAccount.ts | 2 +- .../models/BankTransaction.ts | 7 - .../models/BankTransactionLine.ts | 13 +- .../CashflowTransactionSubscriber.ts | 2 +- .../src/modules/Bills/Bills.module.ts | 12 +- .../src/modules/Bills/models/Bill.ts | 273 +++++++++--------- .../src/modules/Expenses/Expenses.module.ts | 3 +- .../InventoryAdjustments.module.ts | 11 +- .../CreateQuickInventoryAdjustment.service.ts | 3 +- .../DeleteInventoryAdjustment.service.ts | 3 +- .../PublishInventoryAdjustment.service.ts | 3 +- .../ledger/InventoryAdjustmentsGLEntries.ts | 3 +- ...nventoryAdjustmentInventoryTransactions.ts | 6 +- .../models/InventoryAdjustment.ts | 24 +- .../queries/GetInventoryAdjustment.service.ts | 3 +- .../GetInventoryAdjustments.service.ts | 5 +- .../InventoryCost/InventoryCost.module.ts | 4 + .../InventoryCost/InventoryCostMethod.ts | 18 +- .../InventoryTransactions.service.ts | 167 +++++++++++ .../models/InventoryTransaction.ts | 5 +- .../ItemCategories/ItemCategory.module.ts | 5 +- .../src/modules/Mail/Mail.module.ts | 37 ++- .../MailNotification.module.ts | 5 +- .../modules/MailTenancy/MailTenancy.module.ts | 2 +- .../SaleEstimates/SaleEstimates.module.ts | 21 +- .../src/modules/TaxRates/TaxRate.module.ts | 2 + 32 files changed, 455 insertions(+), 227 deletions(-) create mode 100644 packages/server-nest/src/modules/InventoryCost/InventoryTransactions.service.ts diff --git a/packages/server-nest/src/modules/Accounts/Accounts.module.ts b/packages/server-nest/src/modules/Accounts/Accounts.module.ts index f5d27c2f5..7b54096d7 100644 --- a/packages/server-nest/src/modules/Accounts/Accounts.module.ts +++ b/packages/server-nest/src/modules/Accounts/Accounts.module.ts @@ -15,12 +15,14 @@ import { GetAccountTypesService } from './GetAccountTypes.service'; import { GetAccountTransactionsService } from './GetAccountTransactions.service'; import { RegisterTenancyModel } from '../Tenancy/TenancyModels/Tenancy.module'; import { BankAccount } from '../BankingTransactions/models/BankAccount'; +import { GetAccountsService } from './GetAccounts.service'; +import { DynamicListModule } from '../DynamicListing/DynamicList.module'; // import { GetAccountsService } from './GetAccounts.service'; const models = [RegisterTenancyModel(BankAccount)]; @Module({ - imports: [TenancyDatabaseModule], + imports: [TenancyDatabaseModule, DynamicListModule], controllers: [AccountsController], providers: [ AccountsApplication, @@ -35,6 +37,7 @@ const models = [RegisterTenancyModel(BankAccount)]; ActivateAccount, GetAccountTypesService, GetAccountTransactionsService, + GetAccountsService, ...models, ], exports: [AccountRepository, CreateAccountService, ...models], diff --git a/packages/server-nest/src/modules/Accounts/Accounts.types.ts b/packages/server-nest/src/modules/Accounts/Accounts.types.ts index 559f802f6..e5b8af0ca 100644 --- a/packages/server-nest/src/modules/Accounts/Accounts.types.ts +++ b/packages/server-nest/src/modules/Accounts/Accounts.types.ts @@ -41,6 +41,7 @@ export interface IAccountEventCreatingPayload { accountDTO: any; trx: Knex.Transaction; } + export interface IAccountEventCreatedPayload { account: Account; accountId: number; diff --git a/packages/server-nest/src/modules/Accounts/CreateAccount.service.ts b/packages/server-nest/src/modules/Accounts/CreateAccount.service.ts index 5b6d8f33f..fb4ed6b97 100644 --- a/packages/server-nest/src/modules/Accounts/CreateAccount.service.ts +++ b/packages/server-nest/src/modules/Accounts/CreateAccount.service.ts @@ -1,14 +1,11 @@ - import { Inject, Injectable } from '@nestjs/common'; import { kebabCase } from 'lodash'; import { Knex } from 'knex'; import { EventEmitter2 } from '@nestjs/event-emitter'; import { - // IAccount, - // IAccountEventCreatedPayload, - // IAccountCreateDTO, IAccountEventCreatingPayload, CreateAccountParams, + IAccountEventCreatedPayload, } from './Accounts.types'; import { CommandAccountValidators } from './CommandAccountValidators.service'; import { Account } from './models/Account.model'; @@ -16,6 +13,7 @@ import { UnitOfWork } from '../Tenancy/TenancyDB/UnitOfWork.service'; import { TenancyContext } from '../Tenancy/TenancyContext.service'; import { events } from '@/common/events/events'; import { CreateAccountDTO } from './CreateAccount.dto'; +import { PartialModelObject } from 'objection'; @Injectable() export class CreateAccountService { @@ -80,7 +78,7 @@ export class CreateAccountService { private transformDTOToModel = ( createAccountDTO: CreateAccountDTO, baseCurrency: string, - ) => { + ): PartialModelObject => { return { ...createAccountDTO, slug: kebabCase(createAccountDTO.name), @@ -127,11 +125,11 @@ export class CreateAccountService { ...accountInputModel, }); // Triggers `onAccountCreated` event. - // await this.eventEmitter.emitAsync(events.accounts.onCreated, { - // account, - // accountId: account.id, - // trx, - // } as IAccountEventCreatedPayload); + await this.eventEmitter.emitAsync(events.accounts.onCreated, { + account, + accountId: account.id, + trx, + } as IAccountEventCreatedPayload); return account; }, trx); diff --git a/packages/server-nest/src/modules/Accounts/models/Account.model.ts b/packages/server-nest/src/modules/Accounts/models/Account.model.ts index 3a9b3e4bd..f4e194ba7 100644 --- a/packages/server-nest/src/modules/Accounts/models/Account.model.ts +++ b/packages/server-nest/src/modules/Accounts/models/Account.model.ts @@ -33,9 +33,10 @@ export class Account extends TenantBaseModel { public bankBalance!: number; public lastFeedsUpdatedAt!: string | Date | null; public amount!: number; - public plaidItemId!: number; + public plaidItemId!: string; public plaidAccountId!: string | null; public isFeedsActive!: boolean; + public isSyncingOwner!: boolean; public plaidItem!: PlaidItem; /** diff --git a/packages/server-nest/src/modules/BankingAccounts/BankAccounts.module.ts b/packages/server-nest/src/modules/BankingAccounts/BankAccounts.module.ts index feccf9259..3e9face3e 100644 --- a/packages/server-nest/src/modules/BankingAccounts/BankAccounts.module.ts +++ b/packages/server-nest/src/modules/BankingAccounts/BankAccounts.module.ts @@ -18,7 +18,7 @@ import { BankRulesModule } from '../BankRules/BankRules.module'; RefreshBankAccountService, ResumeBankAccountFeedsService, PauseBankAccountFeeds, - // DeleteUncategorizedTransactionsOnAccountDeleting, + DeleteUncategorizedTransactionsOnAccountDeleting, DisconnectPlaidItemOnAccountDeleted, BankAccountsApplication ], diff --git a/packages/server-nest/src/modules/BankingTransactions/BankingTransactions.module.ts b/packages/server-nest/src/modules/BankingTransactions/BankingTransactions.module.ts index 7a79736af..c7c2c6997 100644 --- a/packages/server-nest/src/modules/BankingTransactions/BankingTransactions.module.ts +++ b/packages/server-nest/src/modules/BankingTransactions/BankingTransactions.module.ts @@ -4,7 +4,7 @@ import { UncategorizedBankTransaction } from './models/UncategorizedBankTransact import { BankTransactionLine } from './models/BankTransactionLine'; import { BankTransaction } from './models/BankTransaction'; import { BankTransactionAutoIncrement } from './commands/BankTransactionAutoIncrement.service'; -import BankingTransactionGLEntriesSubscriber from './subscribers/CashflowTransactionSubscriber'; +import { BankingTransactionGLEntriesSubscriber } from './subscribers/CashflowTransactionSubscriber'; import { DecrementUncategorizedTransactionOnCategorizeSubscriber } from './subscribers/DecrementUncategorizedTransactionOnCategorize'; import { DeleteCashflowTransactionOnUncategorizeSubscriber } from './subscribers/DeleteCashflowTransactionOnUncategorize'; import { PreventDeleteTransactionOnDeleteSubscriber } from './subscribers/PreventDeleteTransactionsOnDelete'; @@ -21,15 +21,24 @@ import { BranchTransactionDTOTransformer } from '../Branches/integrations/Branch import { BranchesModule } from '../Branches/Branches.module'; import { RemovePendingUncategorizedTransaction } from './commands/RemovePendingUncategorizedTransaction.service'; import { BankingTransactionsController } from './BankingTransactions.controller'; +import { GetBankAccountsService } from './queries/GetBankAccounts.service'; +import { DynamicListModule } from '../DynamicListing/DynamicList.module'; +import { BankAccount } from './models/BankAccount'; const models = [ RegisterTenancyModel(UncategorizedBankTransaction), RegisterTenancyModel(BankTransaction), RegisterTenancyModel(BankTransactionLine), + RegisterTenancyModel(BankAccount), ]; @Module({ - imports: [AutoIncrementOrdersModule, LedgerModule, BranchesModule], + imports: [ + AutoIncrementOrdersModule, + LedgerModule, + BranchesModule, + DynamicListModule, + ], controllers: [BankingTransactionsController], providers: [ BankTransactionAutoIncrement, @@ -43,6 +52,7 @@ const models = [ DeleteCashflowTransaction, CreateBankTransactionService, GetBankTransactionService, + GetBankAccountsService, CommandBankTransactionValidator, BranchTransactionDTOTransformer, RemovePendingUncategorizedTransaction, diff --git a/packages/server-nest/src/modules/BankingTransactions/models/BankAccount.ts b/packages/server-nest/src/modules/BankingTransactions/models/BankAccount.ts index 268bec5ba..fab1d9db5 100644 --- a/packages/server-nest/src/modules/BankingTransactions/models/BankAccount.ts +++ b/packages/server-nest/src/modules/BankingTransactions/models/BankAccount.ts @@ -45,7 +45,7 @@ export class BankAccount extends TenantBaseModel { /** * Retrieve account type label. */ - get accountTypeLabel() { + get accountTypeLabel(): string { return AccountTypesUtils.getType(this.accountType, 'label'); } diff --git a/packages/server-nest/src/modules/BankingTransactions/models/BankTransaction.ts b/packages/server-nest/src/modules/BankingTransactions/models/BankTransaction.ts index 168e4c907..ba8c4fa6b 100644 --- a/packages/server-nest/src/modules/BankingTransactions/models/BankTransaction.ts +++ b/packages/server-nest/src/modules/BankingTransactions/models/BankTransaction.ts @@ -1,11 +1,4 @@ -/* eslint-disable global-require */ import { Model } from 'objection'; -// import { -// getCashflowAccountTransactionsTypes, -// getCashflowTransactionType, -// } from '@/services/Cashflow/utils'; -// import { CASHFLOW_DIRECTION } from '@/services/Cashflow/constants'; -// import { getCashflowTransactionFormattedType } from '@/utils/transactions-types'; import { BaseModel } from '@/models/Model'; import { getCashflowAccountTransactionsTypes, diff --git a/packages/server-nest/src/modules/BankingTransactions/models/BankTransactionLine.ts b/packages/server-nest/src/modules/BankingTransactions/models/BankTransactionLine.ts index 70b69b8ab..a286bbfa7 100644 --- a/packages/server-nest/src/modules/BankingTransactions/models/BankTransactionLine.ts +++ b/packages/server-nest/src/modules/BankingTransactions/models/BankTransactionLine.ts @@ -1,9 +1,8 @@ /* eslint-disable global-require */ import { Model } from 'objection'; -// import TenantModel from 'models/TenantModel'; -import { BaseModel } from '@/models/Model'; +import { TenantBaseModel } from '@/modules/System/models/TenantBaseModel'; -export class BankTransactionLine extends BaseModel{ +export class BankTransactionLine extends TenantBaseModel{ /** * Table name. */ @@ -18,6 +17,14 @@ export class BankTransactionLine extends BaseModel{ return ['createdAt', 'updatedAt']; } + /** + * Determine whether the model is resourceable. + * @returns {boolean} + */ + static get resourceable(): boolean { + return false; + } + /** * Relationship mapping. */ diff --git a/packages/server-nest/src/modules/BankingTransactions/subscribers/CashflowTransactionSubscriber.ts b/packages/server-nest/src/modules/BankingTransactions/subscribers/CashflowTransactionSubscriber.ts index dd470e808..5da6c8bb1 100644 --- a/packages/server-nest/src/modules/BankingTransactions/subscribers/CashflowTransactionSubscriber.ts +++ b/packages/server-nest/src/modules/BankingTransactions/subscribers/CashflowTransactionSubscriber.ts @@ -6,7 +6,7 @@ import { events } from '@/common/events/events'; import { ICommandCashflowCreatedPayload, ICommandCashflowDeletedPayload } from '../types/BankingTransactions.types'; @Injectable() -export default class BankingTransactionGLEntriesSubscriber { +export class BankingTransactionGLEntriesSubscriber { /** * @param {BankTransactionGLEntriesService} bankTransactionGLEntries - Bank transaction GL entries service. * @param {BankTransactionAutoIncrement} cashflowTransactionAutoIncrement - Cashflow transaction auto increment service. diff --git a/packages/server-nest/src/modules/Bills/Bills.module.ts b/packages/server-nest/src/modules/Bills/Bills.module.ts index 0219b0a87..87280de4c 100644 --- a/packages/server-nest/src/modules/Bills/Bills.module.ts +++ b/packages/server-nest/src/modules/Bills/Bills.module.ts @@ -23,9 +23,18 @@ import { LedgerModule } from '../Ledger/Ledger.module'; import { AccountsModule } from '../Accounts/Accounts.module'; import { BillWriteInventoryTransactionsSubscriber } from './subscribers/BillWriteInventoryTransactionsSubscriber'; import { BillInventoryTransactions } from './commands/BillInventoryTransactions'; +import { GetBillsService } from './queries/GetBills.service'; +import { DynamicListModule } from '../DynamicListing/DynamicList.module'; +import { InventoryCostModule } from '../InventoryCost/InventoryCost.module'; @Module({ - imports: [BillLandedCostsModule, LedgerModule, AccountsModule], + imports: [ + BillLandedCostsModule, + LedgerModule, + AccountsModule, + DynamicListModule, + InventoryCostModule, + ], providers: [ TenancyContext, BillsApplication, @@ -39,6 +48,7 @@ import { BillInventoryTransactions } from './commands/BillInventoryTransactions' GetDueBills, OpenBillService, GetBill, + GetBillsService, DeleteBill, BillDTOTransformer, BillsValidators, diff --git a/packages/server-nest/src/modules/Bills/models/Bill.ts b/packages/server-nest/src/modules/Bills/models/Bill.ts index cfcedb458..2b55f32ea 100644 --- a/packages/server-nest/src/modules/Bills/models/Bill.ts +++ b/packages/server-nest/src/modules/Bills/models/Bill.ts @@ -13,8 +13,9 @@ import { ItemEntry } from '@/modules/TransactionItemEntry/models/ItemEntry'; import { BillLandedCost } from '@/modules/BillLandedCosts/models/BillLandedCost'; import { DiscountType } from '@/common/types/Discount'; import type { Knex, QueryBuilder } from 'knex'; +import { TenantBaseModel } from '@/modules/System/models/TenantBaseModel'; -export class Bill extends BaseModel { +export class Bill extends TenantBaseModel { public amount: number; public paymentAmount: number; public landedCostAmount: number; @@ -95,7 +96,7 @@ export class Bill extends BaseModel { * Invoice amount in base currency. * @returns {number} */ - get amountLocal() { + get amountLocal(): number { return this.amount * this.exchangeRate; } @@ -103,7 +104,7 @@ export class Bill extends BaseModel { * Subtotal. (Tax inclusive) if the tax inclusive is enabled. * @returns {number} */ - get subtotal() { + get subtotal(): number { return this.amount; } @@ -111,7 +112,7 @@ export class Bill extends BaseModel { * Subtotal in base currency. (Tax inclusive) if the tax inclusive is enabled. * @returns {number} */ - get subtotalLocal() { + get subtotalLocal(): number { return this.amountLocal; } @@ -119,7 +120,7 @@ export class Bill extends BaseModel { * Sale invoice amount excluding tax. * @returns {number} */ - get subtotalExcludingTax() { + get subtotalExcludingTax(): number { return this.isInclusiveTax ? this.subtotal - this.taxAmountWithheld : this.subtotal; @@ -129,7 +130,7 @@ export class Bill extends BaseModel { * Tax amount withheld in base currency. * @returns {number} */ - get taxAmountWithheldLocal() { + get taxAmountWithheldLocal(): number { return this.taxAmountWithheld * this.exchangeRate; } @@ -137,7 +138,7 @@ export class Bill extends BaseModel { * Discount amount. * @returns {number} */ - get discountAmount() { + get discountAmount(): number { return this.discountType === DiscountType.Amount ? this.discount : this.subtotal * (this.discount / 100); @@ -147,7 +148,7 @@ export class Bill extends BaseModel { * Discount amount in local currency. * @returns {number | null} */ - get discountAmountLocal() { + get discountAmountLocal(): number | null { return this.discountAmount ? this.discountAmount * this.exchangeRate : null; } @@ -190,6 +191,132 @@ export class Bill extends BaseModel { return this.total * this.exchangeRate; } + /** + * Invoice amount in organization base currency. + * @deprecated + * @returns {number} + */ + get localAmount(): number { + return this.amountLocal; + } + + /** + * Retrieves the local allocated cost amount. + * @returns {number} + */ + get localAllocatedCostAmount(): number { + return this.allocatedCostAmount * this.exchangeRate; + } + + /** + * Retrieves the local landed cost amount. + * @returns {number} + */ + get localLandedCostAmount(): number { + return this.landedCostAmount * this.exchangeRate; + } + + /** + * Retrieves the local unallocated cost amount. + * @returns {number} + */ + get localUnallocatedCostAmount(): number { + return this.unallocatedCostAmount * this.exchangeRate; + } + + /** + * Retrieve the balance of bill. + * @return {number} + */ + get balance(): number { + return this.paymentAmount + this.creditedAmount; + } + + /** + * Due amount of the given. + * @return {number} + */ + get dueAmount(): number { + return Math.max(this.total - this.balance, 0); + } + + /** + * Detarmine whether the bill is open. + * @return {boolean} + */ + get isOpen(): boolean { + return !!this.openedAt; + } + + /** + * Deetarmine whether the bill paid partially. + * @return {boolean} + */ + get isPartiallyPaid(): boolean { + return this.dueAmount !== this.total && this.dueAmount > 0; + } + + /** + * Deetarmine whether the bill paid fully. + * @return {boolean} + */ + get isFullyPaid(): boolean { + return this.dueAmount === 0; + } + + /** + * Detarmines whether the bill paid fully or partially. + * @return {boolean} + */ + get isPaid(): boolean { + return this.isPartiallyPaid || this.isFullyPaid; + } + + /** + * Retrieve the remaining days in number + * @return {number|null} + */ + get remainingDays(): number | null { + const currentMoment = moment(); + const dueDateMoment = moment(this.dueDate); + + return Math.max(dueDateMoment.diff(currentMoment, 'days'), 0); + } + + /** + * Retrieve the overdue days in number. + * @return {number|null} + */ + get overdueDays(): number | null { + const currentMoment = moment(); + const dueDateMoment = moment(this.dueDate); + + return Math.max(currentMoment.diff(dueDateMoment, 'days'), 0); + } + + /** + * Detarmines the due date is over. + * @return {boolean} + */ + get isOverdue(): boolean { + return this.overdueDays > 0; + } + + /** + * Retrieve the unallocated cost amount. + * @return {number} + */ + get unallocatedCostAmount(): number { + return Math.max(this.landedCostAmount - this.allocatedCostAmount, 0); + } + + /** + * Retrieves the calculated amount which have not been invoiced. + */ + get billableAmount(): number { + return Math.max(this.total - this.invoicedAmount, 0); + } + /** * Table name */ @@ -335,132 +462,6 @@ export class Bill extends BaseModel { }; } - /** - * Invoice amount in organization base currency. - * @deprecated - * @returns {number} - */ - get localAmount() { - return this.amountLocal; - } - - /** - * Retrieves the local allocated cost amount. - * @returns {number} - */ - get localAllocatedCostAmount() { - return this.allocatedCostAmount * this.exchangeRate; - } - - /** - * Retrieves the local landed cost amount. - * @returns {number} - */ - get localLandedCostAmount() { - return this.landedCostAmount * this.exchangeRate; - } - - /** - * Retrieves the local unallocated cost amount. - * @returns {number} - */ - get localUnallocatedCostAmount() { - return this.unallocatedCostAmount * this.exchangeRate; - } - - /** - * Retrieve the balance of bill. - * @return {number} - */ - get balance() { - return this.paymentAmount + this.creditedAmount; - } - - /** - * Due amount of the given. - * @return {number} - */ - get dueAmount() { - return Math.max(this.total - this.balance, 0); - } - - /** - * Detarmine whether the bill is open. - * @return {boolean} - */ - get isOpen() { - return !!this.openedAt; - } - - /** - * Deetarmine whether the bill paid partially. - * @return {boolean} - */ - get isPartiallyPaid() { - return this.dueAmount !== this.total && this.dueAmount > 0; - } - - /** - * Deetarmine whether the bill paid fully. - * @return {boolean} - */ - get isFullyPaid() { - return this.dueAmount === 0; - } - - /** - * Detarmines whether the bill paid fully or partially. - * @return {boolean} - */ - get isPaid() { - return this.isPartiallyPaid || this.isFullyPaid; - } - - /** - * Retrieve the remaining days in number - * @return {number|null} - */ - get remainingDays() { - const currentMoment = moment(); - const dueDateMoment = moment(this.dueDate); - - return Math.max(dueDateMoment.diff(currentMoment, 'days'), 0); - } - - /** - * Retrieve the overdue days in number. - * @return {number|null} - */ - get overdueDays() { - const currentMoment = moment(); - const dueDateMoment = moment(this.dueDate); - - return Math.max(currentMoment.diff(dueDateMoment, 'days'), 0); - } - - /** - * Detarmines the due date is over. - * @return {boolean} - */ - get isOverdue() { - return this.overdueDays > 0; - } - - /** - * Retrieve the unallocated cost amount. - * @return {number} - */ - get unallocatedCostAmount() { - return Math.max(this.landedCostAmount - this.allocatedCostAmount, 0); - } - - /** - * Retrieves the calculated amount which have not been invoiced. - */ - get billableAmount() { - return Math.max(this.total - this.invoicedAmount, 0); - } - /** * Bill model settings. */ @@ -482,7 +483,9 @@ export class Bill extends BaseModel { const { Branch } = require('../../Branches/models/Branch.model'); const { Warehouse } = require('../../Warehouses/models/Warehouse.model'); const { TaxRateModel } = require('../../TaxRates/models/TaxRate.model'); - const { TaxRateTransaction } = require('../../TaxRates/models/TaxRateTransaction.model'); + const { + TaxRateTransaction, + } = require('../../TaxRates/models/TaxRateTransaction.model'); const { Document } = require('../../ChromiumlyTenancy/models/Document'); // const { MatchedBankTransaction } = require('models/MatchedBankTransaction'); diff --git a/packages/server-nest/src/modules/Expenses/Expenses.module.ts b/packages/server-nest/src/modules/Expenses/Expenses.module.ts index d54e2c257..889215104 100644 --- a/packages/server-nest/src/modules/Expenses/Expenses.module.ts +++ b/packages/server-nest/src/modules/Expenses/Expenses.module.ts @@ -16,9 +16,10 @@ import { ExpenseGLEntriesService } from './subscribers/ExpenseGLEntries.service' import { LedgerModule } from '../Ledger/Ledger.module'; import { BranchesModule } from '../Branches/Branches.module'; import { GetExpensesService } from './queries/GetExpenses.service'; +import { DynamicListModule } from '../DynamicListing/DynamicList.module'; @Module({ - imports: [LedgerModule, BranchesModule], + imports: [LedgerModule, BranchesModule, DynamicListModule], controllers: [ExpensesController], exports: [ CreateExpense, diff --git a/packages/server-nest/src/modules/InventoryAdjutments/InventoryAdjustments.module.ts b/packages/server-nest/src/modules/InventoryAdjutments/InventoryAdjustments.module.ts index 4cec5d892..057b3341c 100644 --- a/packages/server-nest/src/modules/InventoryAdjutments/InventoryAdjustments.module.ts +++ b/packages/server-nest/src/modules/InventoryAdjutments/InventoryAdjustments.module.ts @@ -5,7 +5,7 @@ import { InventoryAdjustmentEntry } from './models/InventoryAdjustmentEntry'; import { CreateQuickInventoryAdjustmentService } from './commands/CreateQuickInventoryAdjustment.service'; import { PublishInventoryAdjustmentService } from './commands/PublishInventoryAdjustment.service'; import { GetInventoryAdjustmentService } from './queries/GetInventoryAdjustment.service'; -// import { GetInventoryAdjustmentsService } from './queries/GetInventoryAdjustments.service'; +import { GetInventoryAdjustmentsService } from './queries/GetInventoryAdjustments.service'; import { DeleteInventoryAdjustmentService } from './commands/DeleteInventoryAdjustment.service'; import { InventoryAdjustmentsApplicationService } from './InventoryAdjustmentsApplication.service'; import { InventoryAdjustmentsController } from './InventoryAdjustments.controller'; @@ -13,23 +13,24 @@ import { BranchesModule } from '../Branches/Branches.module'; import { WarehousesModule } from '../Warehouses/Warehouses.module'; import { InventoryAdjustmentsGLSubscriber } from './subscribers/InventoryAdjustmentGL.subscriber'; import { InventoryAdjustmentsGLEntries } from './commands/ledger/InventoryAdjustmentsGLEntries'; -import { LedgerModule } from '../Ledger/Ledger.module'; -import { TenancyContext } from '../Tenancy/TenancyContext.service'; import { InventoryAdjustmentInventoryTransactionsSubscriber } from './inventory/InventoryAdjustmentInventoryTransactionsSubscriber'; import { InventoryAdjustmentInventoryTransactions } from './inventory/InventoryAdjustmentInventoryTransactions'; +import { DynamicListModule } from '../DynamicListing/DynamicList.module'; +import { LedgerModule } from '../Ledger/Ledger.module'; +import { TenancyContext } from '../Tenancy/TenancyContext.service'; const models = [ RegisterTenancyModel(InventoryAdjustment), RegisterTenancyModel(InventoryAdjustmentEntry), ]; @Module({ - imports: [BranchesModule, WarehousesModule, LedgerModule], + imports: [BranchesModule, WarehousesModule, LedgerModule, DynamicListModule], controllers: [InventoryAdjustmentsController], providers: [ ...models, CreateQuickInventoryAdjustmentService, PublishInventoryAdjustmentService, - // GetInventoryAdjustmentsService, + GetInventoryAdjustmentsService, GetInventoryAdjustmentService, DeleteInventoryAdjustmentService, InventoryAdjustmentsApplicationService, diff --git a/packages/server-nest/src/modules/InventoryAdjutments/commands/CreateQuickInventoryAdjustment.service.ts b/packages/server-nest/src/modules/InventoryAdjutments/commands/CreateQuickInventoryAdjustment.service.ts index 6710c20bf..0aa8b7bf8 100644 --- a/packages/server-nest/src/modules/InventoryAdjutments/commands/CreateQuickInventoryAdjustment.service.ts +++ b/packages/server-nest/src/modules/InventoryAdjutments/commands/CreateQuickInventoryAdjustment.service.ts @@ -1,5 +1,5 @@ import { Knex } from 'knex'; -import { Inject } from '@nestjs/common'; +import { Inject, Injectable } from '@nestjs/common'; import * as R from 'ramda'; import * as moment from 'moment'; import { omit } from 'lodash'; @@ -20,6 +20,7 @@ import { WarehouseTransactionDTOTransform } from '@/modules/Warehouses/Integrati import { TenancyContext } from '@/modules/Tenancy/TenancyContext.service'; import { ERRORS } from '../constants/InventoryAdjustments.constants'; +@Injectable() export class CreateQuickInventoryAdjustmentService { constructor( @Inject(InventoryAdjustment.name) diff --git a/packages/server-nest/src/modules/InventoryAdjutments/commands/DeleteInventoryAdjustment.service.ts b/packages/server-nest/src/modules/InventoryAdjutments/commands/DeleteInventoryAdjustment.service.ts index e62321907..1c39ed515 100644 --- a/packages/server-nest/src/modules/InventoryAdjutments/commands/DeleteInventoryAdjustment.service.ts +++ b/packages/server-nest/src/modules/InventoryAdjutments/commands/DeleteInventoryAdjustment.service.ts @@ -1,4 +1,4 @@ -import { Inject } from '@nestjs/common'; +import { Inject, Injectable } from '@nestjs/common'; import { Knex } from 'knex'; import { EventEmitter2 } from '@nestjs/event-emitter'; import { events } from '@/common/events/events'; @@ -10,6 +10,7 @@ import { UnitOfWork } from '@/modules/Tenancy/TenancyDB/UnitOfWork.service'; import { InventoryAdjustmentEntry } from '../models/InventoryAdjustmentEntry'; import { InventoryAdjustment } from '../models/InventoryAdjustment'; +@Injectable() export class DeleteInventoryAdjustmentService { constructor( private readonly eventEmitter: EventEmitter2, diff --git a/packages/server-nest/src/modules/InventoryAdjutments/commands/PublishInventoryAdjustment.service.ts b/packages/server-nest/src/modules/InventoryAdjutments/commands/PublishInventoryAdjustment.service.ts index 7949cfae6..feff3cad5 100644 --- a/packages/server-nest/src/modules/InventoryAdjutments/commands/PublishInventoryAdjustment.service.ts +++ b/packages/server-nest/src/modules/InventoryAdjutments/commands/PublishInventoryAdjustment.service.ts @@ -1,5 +1,5 @@ import { Knex } from 'knex'; -import { Inject } from '@nestjs/common'; +import { Inject, Injectable } from '@nestjs/common'; import { EventEmitter2 } from '@nestjs/event-emitter'; import * as moment from 'moment'; import { UnitOfWork } from '@/modules/Tenancy/TenancyDB/UnitOfWork.service'; @@ -12,6 +12,7 @@ import { events } from '@/common/events/events'; import { ServiceError } from '@/modules/Items/ServiceError'; import { ERRORS } from '../constants/InventoryAdjustments.constants'; +@Injectable() export class PublishInventoryAdjustmentService { constructor( private readonly eventEmitter: EventEmitter2, diff --git a/packages/server-nest/src/modules/InventoryAdjutments/commands/ledger/InventoryAdjustmentsGLEntries.ts b/packages/server-nest/src/modules/InventoryAdjutments/commands/ledger/InventoryAdjustmentsGLEntries.ts index 8331e53f4..f68af93db 100644 --- a/packages/server-nest/src/modules/InventoryAdjutments/commands/ledger/InventoryAdjustmentsGLEntries.ts +++ b/packages/server-nest/src/modules/InventoryAdjutments/commands/ledger/InventoryAdjustmentsGLEntries.ts @@ -1,10 +1,11 @@ import { Knex } from 'knex'; -import { Inject } from '@nestjs/common'; +import { Inject, Injectable } from '@nestjs/common'; import { LedgerStorageService } from '../../../Ledger/LedgerStorage.service'; import { InventoryAdjustment } from '../../models/InventoryAdjustment'; import { TenancyContext } from '../../../Tenancy/TenancyContext.service'; import { InventoryAdjustmentsGL } from './InventoryAdjustmentGL'; +@Injectable() export class InventoryAdjustmentsGLEntries { constructor( private readonly ledgerStorage: LedgerStorageService, diff --git a/packages/server-nest/src/modules/InventoryAdjutments/inventory/InventoryAdjustmentInventoryTransactions.ts b/packages/server-nest/src/modules/InventoryAdjutments/inventory/InventoryAdjustmentInventoryTransactions.ts index d9c69cc6b..c6c82d49a 100644 --- a/packages/server-nest/src/modules/InventoryAdjutments/inventory/InventoryAdjustmentInventoryTransactions.ts +++ b/packages/server-nest/src/modules/InventoryAdjutments/inventory/InventoryAdjustmentInventoryTransactions.ts @@ -1,13 +1,13 @@ +import { Injectable } from "@nestjs/common"; import { Knex } from "knex"; import { InventoryAdjustment } from "../models/InventoryAdjustment"; import { InventoryTransaction } from "@/modules/InventoryCost/models/InventoryTransaction"; -import { InventoryService } from "@/modules/InventoryCost/Inventory"; -import { Injectable } from "@nestjs/common"; +import { InventoryTransactionsService } from "@/modules/InventoryCost/InventoryTransactions.service"; @Injectable() export class InventoryAdjustmentInventoryTransactions { constructor( - private readonly inventoryService: InventoryService + private readonly inventoryService: InventoryTransactionsService ) {} /** diff --git a/packages/server-nest/src/modules/InventoryAdjutments/models/InventoryAdjustment.ts b/packages/server-nest/src/modules/InventoryAdjutments/models/InventoryAdjustment.ts index a49db213c..18c0e2cf4 100644 --- a/packages/server-nest/src/modules/InventoryAdjutments/models/InventoryAdjustment.ts +++ b/packages/server-nest/src/modules/InventoryAdjutments/models/InventoryAdjustment.ts @@ -3,21 +3,21 @@ import { InventoryAdjustmentEntry } from './InventoryAdjustmentEntry'; import { TenantBaseModel } from '@/modules/System/models/TenantBaseModel'; export class InventoryAdjustment extends TenantBaseModel { - date!: string; - type!: string; - adjustmentAccountId!: number; - reason?: string; - referenceNo!: string; - description?: string; - userId!: number; - publishedAt?: string; + public readonly date!: string; + public readonly type!: string; + public readonly adjustmentAccountId!: number; + public readonly reason?: string; + public readonly referenceNo!: string; + public readonly description?: string; + public readonly userId!: number; + public readonly publishedAt?: string; - branchId!: number; - warehouseId!: number; + public readonly branchId!: number; + public readonly warehouseId!: number; - createdAt!: Date | string; + public readonly createdAt!: Date | string; - entries: InventoryAdjustmentEntry[]; + public readonly entries: InventoryAdjustmentEntry[]; /** * Table name diff --git a/packages/server-nest/src/modules/InventoryAdjutments/queries/GetInventoryAdjustment.service.ts b/packages/server-nest/src/modules/InventoryAdjutments/queries/GetInventoryAdjustment.service.ts index 267137a64..a20e41dcd 100644 --- a/packages/server-nest/src/modules/InventoryAdjutments/queries/GetInventoryAdjustment.service.ts +++ b/packages/server-nest/src/modules/InventoryAdjutments/queries/GetInventoryAdjustment.service.ts @@ -1,8 +1,9 @@ +import { Inject, Injectable } from '@nestjs/common'; import { TransformerInjectable } from '@/modules/Transformer/TransformerInjectable.service'; import { InventoryAdjustment } from '../models/InventoryAdjustment'; import { InventoryAdjustmentTransformer } from '../InventoryAdjustmentTransformer'; -import { Inject } from '@nestjs/common'; +@Injectable() export class GetInventoryAdjustmentService { constructor( private readonly transformer: TransformerInjectable, diff --git a/packages/server-nest/src/modules/InventoryAdjutments/queries/GetInventoryAdjustments.service.ts b/packages/server-nest/src/modules/InventoryAdjutments/queries/GetInventoryAdjustments.service.ts index b890edba8..8cabfe132 100644 --- a/packages/server-nest/src/modules/InventoryAdjutments/queries/GetInventoryAdjustments.service.ts +++ b/packages/server-nest/src/modules/InventoryAdjutments/queries/GetInventoryAdjustments.service.ts @@ -1,4 +1,4 @@ -import { Inject } from '@nestjs/common'; +import { Inject, Injectable } from '@nestjs/common'; import * as R from 'ramda'; import { IPaginationMeta } from '@/interfaces/Model'; import { InventoryAdjustmentTransformer } from '../InventoryAdjustmentTransformer'; @@ -7,9 +7,10 @@ import { IInventoryAdjustmentsFilter } from '../types/InventoryAdjustments.types import { TransformerInjectable } from '@/modules/Transformer/TransformerInjectable.service'; import { DynamicListService } from '@/modules/DynamicListing/DynamicList.service'; +@Injectable() export class GetInventoryAdjustmentsService { constructor( - public readonly transformer: TransformerInjectable, + private readonly transformer: TransformerInjectable, private readonly dynamicListService: DynamicListService, @Inject(InventoryAdjustment.name) diff --git a/packages/server-nest/src/modules/InventoryCost/InventoryCost.module.ts b/packages/server-nest/src/modules/InventoryCost/InventoryCost.module.ts index 96ed6738e..956529597 100644 --- a/packages/server-nest/src/modules/InventoryCost/InventoryCost.module.ts +++ b/packages/server-nest/src/modules/InventoryCost/InventoryCost.module.ts @@ -6,6 +6,8 @@ import { InventoryTransaction } from './models/InventoryTransaction'; import { InventoryCostGLBeforeWriteSubscriber } from './subscribers/InventoryCostGLBeforeWriteSubscriber'; import { InventoryItemsQuantitySyncService } from './InventoryItemsQuantitySync.service'; import { InventoryCostMethod } from './InventoryCostMethod'; +import { InventoryTransactionsService } from './InventoryTransactions.service'; +import { LedgerModule } from '../Ledger/Ledger.module'; const models = [ RegisterTenancyModel(InventoryCostLotTracker), @@ -13,12 +15,14 @@ const models = [ ]; @Module({ + imports: [LedgerModule], providers: [ ...models, InventoryCostGLBeforeWriteSubscriber, InventoryCostGLStorage, InventoryItemsQuantitySyncService, InventoryCostMethod, + InventoryTransactionsService ], exports: [...models], }) diff --git a/packages/server-nest/src/modules/InventoryCost/InventoryCostMethod.ts b/packages/server-nest/src/modules/InventoryCost/InventoryCostMethod.ts index e52a77134..f7b2c1b6a 100644 --- a/packages/server-nest/src/modules/InventoryCost/InventoryCostMethod.ts +++ b/packages/server-nest/src/modules/InventoryCost/InventoryCostMethod.ts @@ -1,31 +1,33 @@ +import { Knex } from 'knex'; +import { Inject } from '@nestjs/common'; import { omit } from 'lodash'; import { InventoryCostLotTracker } from './models/InventoryCostLotTracker'; -import { Inject } from '@nestjs/common'; -import { Knex } from 'knex'; export class InventoryCostMethod { constructor( @Inject(InventoryCostLotTracker.name) - private readonly inventoryCostLotTracker: typeof InventoryCostLotTracker + private readonly inventoryCostLotTracker: typeof InventoryCostLotTracker, ) {} - /** * Stores the inventory lots costs transactions in bulk. - * @param {IInventoryLotCost[]} costLotsTransactions - * @return {Promise[]} + * @param {InventoryCostLotTracker[]} costLotsTransactions - Inventory lots costs transactions. + * @param {Knex.Transaction} trx - Knex transaction. + * @return {Promise} */ public storeInventoryLotsCost( costLotsTransactions: InventoryCostLotTracker[], - trx: Knex.Transaction + trx: Knex.Transaction, ): Promise { const opers: any = []; costLotsTransactions.forEach((transaction: any) => { if (transaction.lotTransId && transaction.decrement) { - const decrementOper = this.inventoryCostLotTracker.query(trx) + const decrementOper = this.inventoryCostLotTracker + .query(trx) .where('id', transaction.lotTransId) .decrement('remaining', transaction.decrement); + opers.push(decrementOper); } else if (!transaction.lotTransId) { const operation = this.inventoryCostLotTracker.query(trx).insert({ diff --git a/packages/server-nest/src/modules/InventoryCost/InventoryTransactions.service.ts b/packages/server-nest/src/modules/InventoryCost/InventoryTransactions.service.ts new file mode 100644 index 000000000..4bff64639 --- /dev/null +++ b/packages/server-nest/src/modules/InventoryCost/InventoryTransactions.service.ts @@ -0,0 +1,167 @@ +import { IInventoryTransactionsDeletedPayload, TInventoryTransactionDirection } from './types/InventoryCost.types'; +import { EventEmitter2 } from '@nestjs/event-emitter'; +import { InventoryCostLotTracker } from './models/InventoryCostLotTracker'; +import { InventoryTransaction } from './models/InventoryTransaction'; +import { Knex } from 'knex'; +import { events } from '@/common/events/events'; +import { IInventoryTransactionsCreatedPayload } from './types/InventoryCost.types'; +import { transformItemEntriesToInventory } from "./utils"; +import { IItemEntryTransactionType } from '../TransactionItemEntry/ItemEntry.types'; +import { ItemEntry } from '../TransactionItemEntry/models/ItemEntry'; +import { Inject } from '@nestjs/common'; + +export class InventoryTransactionsService { + constructor( + private readonly eventEmitter: EventEmitter2, + + @Inject(InventoryTransaction.name) + private readonly inventoryTransactionModel: typeof InventoryTransaction, + + @Inject(InventoryCostLotTracker.name) + private readonly inventoryCostLotTracker: typeof InventoryCostLotTracker, + ) {} + + /** + * Records the inventory transactions. + * @param {InventoryTransaction[]} transactions - Inventory transactions. + * @param {boolean} override - Override the existing transactions. + * @param {Knex.Transaction} trx - Knex transaction. + * @return {Promise} + */ + async recordInventoryTransactions( + transactions: InventoryTransaction[], + override: boolean = false, + trx?: Knex.Transaction, + ): Promise { + const bulkInsertOpers = []; + + transactions.forEach((transaction: InventoryTransaction) => { + const oper = this.recordInventoryTransaction(transaction, override, trx); + bulkInsertOpers.push(oper); + }); + const inventoryTransactions = await Promise.all(bulkInsertOpers); + + // Triggers `onInventoryTransactionsCreated` event. + await this.eventEmitter.emitAsync( + events.inventory.onInventoryTransactionsCreated, + { + inventoryTransactions, + trx, + } as IInventoryTransactionsCreatedPayload, + ); + } + + /** + * Writes the inventory transactiosn on the storage from the given + * inventory transactions entries. + * @param {InventoryTransaction} inventoryEntry - Inventory transaction. + * @param {boolean} deleteOld - Delete the existing inventory transactions. + * @param {Knex.Transaction} trx - Knex transaction. + * @return {Promise} + */ + async recordInventoryTransaction( + inventoryEntry: InventoryTransaction, + deleteOld: boolean = false, + trx: Knex.Transaction, + ): Promise { + if (deleteOld) { + await this.deleteInventoryTransactions( + inventoryEntry.transactionId, + inventoryEntry.transactionType, + trx, + ); + } + return this.inventoryTransactionModel.query(trx).insertGraph({ + ...inventoryEntry, + }); + } + + /** + * Records the inventory transactions from items entries that have (inventory) type. + * + * @param {number} tenantId + * @param {number} transactionId + * @param {string} transactionType + * @param {Date|string} transactionDate + * @param {boolean} override + */ + async recordInventoryTransactionsFromItemsEntries( + transaction: { + transactionId: number; + transactionType: IItemEntryTransactionType; + exchangeRate: number; + + date: Date | string; + direction: TInventoryTransactionDirection; + entries: ItemEntry[]; + createdAt: Date | string; + + warehouseId?: number; + }, + override: boolean = false, + trx?: Knex.Transaction, + ): Promise { + // Can't continue if there is no entries has inventory items in the invoice. + if (transaction.entries.length <= 0) { + return; + } + // Inventory transactions. + const inventoryTranscations = transformItemEntriesToInventory(transaction); + + // Records the inventory transactions of the given sale invoice. + await this.recordInventoryTransactions( + inventoryTranscations, + override, + trx, + ); + } + + /** + * Deletes the given inventory transactions. + * @param {number} transactionId - Transaction id. + * @param {string} transactionType - Transaction type. + * @param {Knex.Transaction} trx - Knex transaction. + * @return {Promise<{ oldInventoryTransactions: IInventoryTransaction[] }>} + */ + public async deleteInventoryTransactions( + transactionId: number, + transactionType: string, + trx?: Knex.Transaction, + ): Promise<{ oldInventoryTransactions: InventoryTransaction[] }> { + // Retrieve the inventory transactions of the given sale invoice. + const oldInventoryTransactions = await this.inventoryTransactionModel + .query(trx) + .where({ transactionId, transactionType }); + + // Deletes the inventory transactions by the given transaction type and id. + await this.inventoryTransactionModel + .query(trx) + .where({ transactionType, transactionId }) + .delete(); + + // Triggers `onInventoryTransactionsDeleted` event. + await this.eventEmitter.emitAsync( + events.inventory.onInventoryTransactionsDeleted, + { + oldInventoryTransactions, + transactionId, + transactionType, + trx, + } as IInventoryTransactionsDeletedPayload, + ); + return { oldInventoryTransactions }; + } + + /** + * Records the inventory cost lot transaction. + * @param {InventoryCostLotTracker} inventoryLotEntry + * @return {Promise} + */ + async recordInventoryCostLotTransaction( + inventoryLotEntry: Partial, + ): Promise { + return this.inventoryCostLotTracker.query().insert({ + ...inventoryLotEntry, + }); + } +} diff --git a/packages/server-nest/src/modules/InventoryCost/models/InventoryTransaction.ts b/packages/server-nest/src/modules/InventoryCost/models/InventoryTransaction.ts index 81baa356e..15b1e73ef 100644 --- a/packages/server-nest/src/modules/InventoryCost/models/InventoryTransaction.ts +++ b/packages/server-nest/src/modules/InventoryCost/models/InventoryTransaction.ts @@ -4,8 +4,9 @@ import moment, { unitOfTime } from 'moment'; import { BaseModel } from '@/models/Model'; import { getTransactionTypeLabel } from '@/modules/BankingTransactions/utils'; import { TInventoryTransactionDirection } from '../types/InventoryCost.types'; +import { TenantBaseModel } from '@/modules/System/models/TenantBaseModel'; -export class InventoryTransaction extends BaseModel { +export class InventoryTransaction extends TenantBaseModel { date: Date | string; direction: TInventoryTransactionDirection; itemId: number; @@ -39,7 +40,7 @@ export class InventoryTransaction extends BaseModel { * Retrieve formatted reference type. * @return {string} */ - get transcationTypeFormatted() { + get transcationTypeFormatted(): string { return getTransactionTypeLabel(this.transactionType); } diff --git a/packages/server-nest/src/modules/ItemCategories/ItemCategory.module.ts b/packages/server-nest/src/modules/ItemCategories/ItemCategory.module.ts index d9c22fc43..d76b0684b 100644 --- a/packages/server-nest/src/modules/ItemCategories/ItemCategory.module.ts +++ b/packages/server-nest/src/modules/ItemCategories/ItemCategory.module.ts @@ -9,14 +9,17 @@ import { ItemCategoryController } from './ItemCategory.controller'; import { CommandItemCategoryValidatorService } from './commands/CommandItemCategoryValidator.service'; import { TransformerInjectable } from '../Transformer/TransformerInjectable.service'; import { TenancyContext } from '../Tenancy/TenancyContext.service'; +import { GetItemCategoriesService } from './queries/GetItemCategories.service'; +import { DynamicListModule } from '../DynamicListing/DynamicList.module'; @Module({ - imports: [TenancyDatabaseModule], + imports: [TenancyDatabaseModule, DynamicListModule], controllers: [ItemCategoryController], providers: [ CreateItemCategoryService, EditItemCategoryService, GetItemCategoryService, + GetItemCategoriesService, DeleteItemCategoryService, ItemCategoryApplication, CommandItemCategoryValidatorService, diff --git a/packages/server-nest/src/modules/Mail/Mail.module.ts b/packages/server-nest/src/modules/Mail/Mail.module.ts index 43011b9ce..926aa8440 100644 --- a/packages/server-nest/src/modules/Mail/Mail.module.ts +++ b/packages/server-nest/src/modules/Mail/Mail.module.ts @@ -5,29 +5,26 @@ import { MAIL_TRANSPORTER_PROVIDER } from './Mail.constants'; import { MailTransporter } from './MailTransporter.service'; @Module({ - imports: [ + providers: [ { - module: MailModule, - providers: [ - { - provide: MAIL_TRANSPORTER_PROVIDER, - useFactory: (configService: ConfigService) => { - // Create reusable transporter object using the default SMTP transport - const transporter = createTransport({ - host: configService.get('mail.host'), - port: configService.get('mail.port'), - secure: configService.get('mail.secure'), // true for 465, false for other ports - auth: { - user: configService.get('mail.username'), - pass: configService.get('mail.password'), - }, - }); - return transporter; + provide: MAIL_TRANSPORTER_PROVIDER, + inject: [ConfigService], + useFactory: (configService: ConfigService) => { + // Create reusable transporter object using the default SMTP transport + const transporter = createTransport({ + host: configService.get('mail.host'), + port: configService.get('mail.port'), + secure: configService.get('mail.secure'), // true for 465, false for other ports + auth: { + user: configService.get('mail.username'), + pass: configService.get('mail.password'), }, - }, - ], + }); + return transporter; + }, }, - MailTransporter + MailTransporter, ], + exports: [MAIL_TRANSPORTER_PROVIDER, MailTransporter], }) export class MailModule {} diff --git a/packages/server-nest/src/modules/MailNotification/MailNotification.module.ts b/packages/server-nest/src/modules/MailNotification/MailNotification.module.ts index 7be87b9d4..d03073635 100644 --- a/packages/server-nest/src/modules/MailNotification/MailNotification.module.ts +++ b/packages/server-nest/src/modules/MailNotification/MailNotification.module.ts @@ -1,8 +1,11 @@ import { Module } from '@nestjs/common'; import { ContactMailNotification } from './ContactMailNotification'; +import { MailTenancyModule } from '../MailTenancy/MailTenancy.module'; +import { TenancyContext } from '../Tenancy/TenancyContext.service'; @Module({ - imports: [ContactMailNotification], + imports: [MailTenancyModule], + providers: [ContactMailNotification, TenancyContext], exports: [ContactMailNotification], }) export class MailNotificationModule {} diff --git a/packages/server-nest/src/modules/MailTenancy/MailTenancy.module.ts b/packages/server-nest/src/modules/MailTenancy/MailTenancy.module.ts index be1dc9616..56327d5e5 100644 --- a/packages/server-nest/src/modules/MailTenancy/MailTenancy.module.ts +++ b/packages/server-nest/src/modules/MailTenancy/MailTenancy.module.ts @@ -3,7 +3,7 @@ import { MailTenancy } from './MailTenancy.service'; import { TenancyContext } from '../Tenancy/TenancyContext.service'; @Module({ - imports: [], providers: [MailTenancy, TenancyContext], + exports: [MailTenancy], }) export class MailTenancyModule {} diff --git a/packages/server-nest/src/modules/SaleEstimates/SaleEstimates.module.ts b/packages/server-nest/src/modules/SaleEstimates/SaleEstimates.module.ts index ca9a3f830..b5de377fb 100644 --- a/packages/server-nest/src/modules/SaleEstimates/SaleEstimates.module.ts +++ b/packages/server-nest/src/modules/SaleEstimates/SaleEstimates.module.ts @@ -24,11 +24,24 @@ import { DeleteSaleEstimate } from './commands/DeleteSaleEstimate.service'; import { GetSaleEstimate } from './queries/GetSaleEstimate.service'; import { GetSaleEstimateState } from './queries/GetSaleEstimateState.service'; import { SendSaleEstimateMail } from './commands/SendSaleEstimateMail'; +import { GetSaleEstimatesService } from './queries/GetSaleEstimates.service'; +import { DynamicListModule } from '../DynamicListing/DynamicList.module'; +import { GetSaleEstimatePdf } from './queries/GetSaleEstimatePdf'; +import { MailNotificationModule } from '../MailNotification/MailNotification.module'; +import { MailModule } from '../Mail/Mail.module'; +import { ChromiumlyTenancyModule } from '../ChromiumlyTenancy/ChromiumlyTenancy.module'; +import { TemplateInjectableModule } from '../TemplateInjectable/TemplateInjectable.module'; // import { SaleEstimateNotifyBySms } from './commands/SaleEstimateSmsNotify'; -// import { SendSaleEstimateMail } from './commands/SendSaleEstimateMail'; -// + @Module({ - imports: [TenancyDatabaseModule], + imports: [ + TenancyDatabaseModule, + DynamicListModule, + MailNotificationModule, + MailModule, + ChromiumlyTenancyModule, + TemplateInjectableModule + ], controllers: [SaleEstimatesController], providers: [ AutoIncrementOrdersService, @@ -39,6 +52,7 @@ import { SendSaleEstimateMail } from './commands/SendSaleEstimateMail'; EditSaleEstimate, DeleteSaleEstimate, GetSaleEstimate, + GetSaleEstimatesService, GetSaleEstimateState, ApproveSaleEstimateService, DeliverSaleEstimateService, @@ -54,6 +68,7 @@ import { SendSaleEstimateMail } from './commands/SendSaleEstimateMail'; TransformerInjectable, SaleEstimatesApplication, SendSaleEstimateMail, + GetSaleEstimatePdf, // SaleEstimateNotifyBySms, ], }) diff --git a/packages/server-nest/src/modules/TaxRates/TaxRate.module.ts b/packages/server-nest/src/modules/TaxRates/TaxRate.module.ts index b07e6a9c9..94a72c3a1 100644 --- a/packages/server-nest/src/modules/TaxRates/TaxRate.module.ts +++ b/packages/server-nest/src/modules/TaxRates/TaxRate.module.ts @@ -11,6 +11,7 @@ import { CommandTaxRatesValidators } from './commands/CommandTaxRatesValidator.s import { TenancyContext } from '../Tenancy/TenancyContext.service'; import { TaxRatesApplication } from './TaxRate.application'; import { ItemEntriesTaxTransactions } from './ItemEntriesTaxTransactions.service'; +import { GetTaxRatesService } from './queries/GetTaxRates.service'; @Module({ imports: [], @@ -20,6 +21,7 @@ import { ItemEntriesTaxTransactions } from './ItemEntriesTaxTransactions.service EditTaxRateService, DeleteTaxRateService, GetTaxRateService, + GetTaxRatesService, ActivateTaxRateService, InactivateTaxRateService, CommandTaxRatesValidators,