mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 14:50:32 +00:00
refactor: settings module
This commit is contained in:
@@ -1,23 +1,31 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
|
import { SettingsStore } from '../Settings/SettingsStore';
|
||||||
|
import { SETTINGS_PROVIDER } from '../Settings/Settings.types';
|
||||||
|
import { transactionIncrement } from '@/utils/transaction-increment';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Auto increment orders service.
|
* Auto increment orders service.
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AutoIncrementOrdersService {
|
export class AutoIncrementOrdersService {
|
||||||
|
constructor(
|
||||||
|
@Inject(SETTINGS_PROVIDER)
|
||||||
|
private readonly settingsStore: () => SettingsStore,
|
||||||
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the auto increment is enabled for the given settings group.
|
* Check if the auto increment is enabled for the given settings group.
|
||||||
* @param {string} settingsGroup - Settings group.
|
* @param {string} settingsGroup - Settings group.
|
||||||
* @returns {boolean}
|
* @returns {Promise<boolean>}
|
||||||
*/
|
*/
|
||||||
public autoIncrementEnabled = (settingsGroup: string): boolean => {
|
public autoIncrementEnabled = async (
|
||||||
// const settings = this.tenancy.settings(tenantId);
|
settingsGroup: string,
|
||||||
// const group = settingsGroup;
|
): Promise<boolean> => {
|
||||||
|
const settingsStore = await this.settingsStore();
|
||||||
|
const group = settingsGroup;
|
||||||
|
|
||||||
// // Settings service transaction number and prefix.
|
// Settings service transaction number and prefix.
|
||||||
// return settings.get({ group, key: 'auto_increment' }, false);
|
return settingsStore.get({ group, key: 'auto_increment' }, false);
|
||||||
|
|
||||||
return true;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -26,18 +34,18 @@ export class AutoIncrementOrdersService {
|
|||||||
* @param {Function} getMaxTransactionNo
|
* @param {Function} getMaxTransactionNo
|
||||||
* @return {Promise<string>}
|
* @return {Promise<string>}
|
||||||
*/
|
*/
|
||||||
getNextTransactionNumber(group: string): string {
|
async getNextTransactionNumber(group: string): Promise<string> {
|
||||||
// const settings = this.tenancy.settings(tenantId);
|
const settingsStore = await this.settingsStore();
|
||||||
|
|
||||||
// // Settings service transaction number and prefix.
|
// Settings service transaction number and prefix.
|
||||||
// const autoIncrement = this.autoIncrementEnabled(tenantId, group);
|
const autoIncrement = await this.autoIncrementEnabled(group);
|
||||||
|
|
||||||
// const settingNo = settings.get({ group, key: 'next_number' }, '');
|
const settingNo = settingsStore.get({ group, key: 'next_number' }, '');
|
||||||
// const settingPrefix = settings.get({ group, key: 'number_prefix' }, '');
|
const settingPrefix = settingsStore.get(
|
||||||
|
{ group, key: 'number_prefix' },
|
||||||
// return autoIncrement ? `${settingPrefix}${settingNo}` : '';
|
'',
|
||||||
|
);
|
||||||
return '1';
|
return autoIncrement ? `${settingPrefix}${settingNo}` : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -46,17 +54,19 @@ export class AutoIncrementOrdersService {
|
|||||||
* @param {string} orderNumber -Order number.
|
* @param {string} orderNumber -Order number.
|
||||||
*/
|
*/
|
||||||
async incrementSettingsNextNumber(group: string) {
|
async incrementSettingsNextNumber(group: string) {
|
||||||
// const settings = this.tenancy.settings(tenantId);
|
const settingsStore = await this.settingsStore();
|
||||||
// const settingNo = settings.get({ group, key: 'next_number' });
|
|
||||||
// const autoIncrement = settings.get({ group, key: 'auto_increment' });
|
const settingNo = settingsStore.get({ group, key: 'next_number' });
|
||||||
|
const autoIncrement = settingsStore.get({ group, key: 'auto_increment' });
|
||||||
|
|
||||||
// // Can't continue if the auto-increment of the service was disabled.
|
// // Can't continue if the auto-increment of the service was disabled.
|
||||||
// if (!autoIncrement) {
|
if (!autoIncrement) {
|
||||||
// return;
|
return;
|
||||||
// }
|
}
|
||||||
// settings.set(
|
settingsStore.set(
|
||||||
// { group, key: 'next_number' },
|
{ group, key: 'next_number' },
|
||||||
// transactionIncrement(settingNo)
|
transactionIncrement(settingNo),
|
||||||
// );
|
);
|
||||||
// await settings.save();
|
await settingsStore.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export class BankTransactionAutoIncrement {
|
|||||||
* Retrieve the next unique invoice number.
|
* Retrieve the next unique invoice number.
|
||||||
* @return {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
public getNextTransactionNumber = (): string => {
|
public getNextTransactionNumber = (): Promise<string> => {
|
||||||
return this.autoIncrementOrdersService.getNextTransactionNumber('cashflow');
|
return this.autoIncrementOrdersService.getNextTransactionNumber('cashflow');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -61,11 +61,11 @@ export class CreateBankTransactionService {
|
|||||||
* @param {ICashflowNewCommandDTO} newCashflowTransactionDTO - New transaction DTO.
|
* @param {ICashflowNewCommandDTO} newCashflowTransactionDTO - New transaction DTO.
|
||||||
* @returns {ICashflowTransactionInput} - Cashflow transaction object.
|
* @returns {ICashflowTransactionInput} - Cashflow transaction object.
|
||||||
*/
|
*/
|
||||||
private transformCashflowTransactionDTO = (
|
private transformCashflowTransactionDTO = async (
|
||||||
newCashflowTransactionDTO: ICashflowNewCommandDTO,
|
newCashflowTransactionDTO: ICashflowNewCommandDTO,
|
||||||
cashflowAccount: Account,
|
cashflowAccount: Account,
|
||||||
userId: number,
|
userId: number,
|
||||||
): BankTransaction => {
|
): Promise<BankTransaction> => {
|
||||||
const amount = newCashflowTransactionDTO.amount;
|
const amount = newCashflowTransactionDTO.amount;
|
||||||
|
|
||||||
const fromDTO = pick(newCashflowTransactionDTO, [
|
const fromDTO = pick(newCashflowTransactionDTO, [
|
||||||
@@ -81,7 +81,7 @@ export class CreateBankTransactionService {
|
|||||||
'uncategorizedTransactionId',
|
'uncategorizedTransactionId',
|
||||||
]);
|
]);
|
||||||
// Retreive the next invoice number.
|
// Retreive the next invoice number.
|
||||||
const autoNextNumber = this.autoIncrement.getNextTransactionNumber();
|
const autoNextNumber = await this.autoIncrement.getNextTransactionNumber();
|
||||||
|
|
||||||
// Retrieve the transaction number.
|
// Retrieve the transaction number.
|
||||||
const transactionNumber =
|
const transactionNumber =
|
||||||
@@ -134,7 +134,7 @@ export class CreateBankTransactionService {
|
|||||||
await this.authorize(newTransactionDTO, creditAccount);
|
await this.authorize(newTransactionDTO, creditAccount);
|
||||||
|
|
||||||
// Transformes owner contribution DTO to cashflow transaction.
|
// Transformes owner contribution DTO to cashflow transaction.
|
||||||
const cashflowTransactionObj = this.transformCashflowTransactionDTO(
|
const cashflowTransactionObj = await this.transformCashflowTransactionDTO(
|
||||||
newTransactionDTO,
|
newTransactionDTO,
|
||||||
cashflowAccount,
|
cashflowAccount,
|
||||||
userId,
|
userId,
|
||||||
|
|||||||
@@ -27,8 +27,14 @@ import { PaymentMadeBranchValidateSubscriber } from './subscribers/Validators/Pa
|
|||||||
import { PaymentReceiveBranchValidateSubscriber } from './subscribers/Validators/PaymentReceiveBranchSubscriber';
|
import { PaymentReceiveBranchValidateSubscriber } from './subscribers/Validators/PaymentReceiveBranchSubscriber';
|
||||||
import { SaleReceiptBranchValidateSubscriber } from './subscribers/Validators/SaleReceiptBranchesSubscriber';
|
import { SaleReceiptBranchValidateSubscriber } from './subscribers/Validators/SaleReceiptBranchesSubscriber';
|
||||||
import { VendorCreditBranchValidateSubscriber } from './subscribers/Validators/VendorCreditBranchSubscriber';
|
import { VendorCreditBranchValidateSubscriber } from './subscribers/Validators/VendorCreditBranchSubscriber';
|
||||||
|
import { ValidateBranchExistance } from './Integrations/ValidateBranchExistance';
|
||||||
|
import { ManualJournalBranchesValidator } from './Integrations/ManualJournals/ManualJournalsBranchesValidator';
|
||||||
|
import { CashflowTransactionsActivateBranches } from './integrations/Cashflow/CashflowActivateBranches';
|
||||||
|
import { ExpensesActivateBranches } from './integrations/Expense/ExpensesActivateBranches';
|
||||||
|
import { FeaturesModule } from '../Features/Features.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [TenancyDatabaseModule],
|
imports: [TenancyDatabaseModule, FeaturesModule],
|
||||||
controllers: [BranchesController],
|
controllers: [BranchesController],
|
||||||
providers: [
|
providers: [
|
||||||
CreateBranchService,
|
CreateBranchService,
|
||||||
@@ -45,18 +51,22 @@ import { VendorCreditBranchValidateSubscriber } from './subscribers/Validators/V
|
|||||||
BranchCommandValidator,
|
BranchCommandValidator,
|
||||||
BranchTransactionDTOTransformer,
|
BranchTransactionDTOTransformer,
|
||||||
ManualJournalBranchesDTOTransformer,
|
ManualJournalBranchesDTOTransformer,
|
||||||
BillBranchValidateSubscriber,
|
// BillBranchValidateSubscriber,
|
||||||
CreditNoteBranchValidateSubscriber,
|
// CreditNoteBranchValidateSubscriber,
|
||||||
CreditNoteRefundBranchValidateSubscriber,
|
// CreditNoteRefundBranchValidateSubscriber,
|
||||||
ContactBranchValidateSubscriber,
|
// ContactBranchValidateSubscriber,
|
||||||
ExpenseBranchValidateSubscriber,
|
// ExpenseBranchValidateSubscriber,
|
||||||
InventoryAdjustmentBranchValidateSubscriber,
|
// InventoryAdjustmentBranchValidateSubscriber,
|
||||||
ManualJournalBranchValidateSubscriber,
|
// ManualJournalBranchValidateSubscriber,
|
||||||
PaymentMadeBranchValidateSubscriber,
|
// PaymentMadeBranchValidateSubscriber,
|
||||||
PaymentReceiveBranchValidateSubscriber,
|
// PaymentReceiveBranchValidateSubscriber,
|
||||||
SaleEstimateBranchValidateSubscriber,
|
// SaleEstimateBranchValidateSubscriber,
|
||||||
SaleReceiptBranchValidateSubscriber,
|
// SaleReceiptBranchValidateSubscriber,
|
||||||
VendorCreditBranchValidateSubscriber,
|
// VendorCreditBranchValidateSubscriber,
|
||||||
|
// ValidateBranchExistance,
|
||||||
|
// ManualJournalBranchesValidator,
|
||||||
|
// CashflowTransactionsActivateBranches,
|
||||||
|
// ExpensesActivateBranches
|
||||||
],
|
],
|
||||||
exports: [
|
exports: [
|
||||||
BranchesSettingsService,
|
BranchesSettingsService,
|
||||||
|
|||||||
@@ -23,9 +23,6 @@ export class ActivateBranches {
|
|||||||
private readonly createBranch: CreateBranchService,
|
private readonly createBranch: CreateBranchService,
|
||||||
private readonly branchesSettings: BranchesSettingsService,
|
private readonly branchesSettings: BranchesSettingsService,
|
||||||
private readonly i18n: I18nService,
|
private readonly i18n: I18nService,
|
||||||
|
|
||||||
@Inject(Branch.name)
|
|
||||||
private readonly branchModel: TenantModelProxy<typeof Branch>,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export class CreditNoteAutoIncrementService {
|
|||||||
* Retrieve the next unique credit number.
|
* Retrieve the next unique credit number.
|
||||||
* @return {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
public getNextCreditNumber(): string {
|
public getNextCreditNumber(): Promise<string> {
|
||||||
return this.autoIncrementOrdersService.getNextTransactionNumber(
|
return this.autoIncrementOrdersService.getNextTransactionNumber(
|
||||||
'credit_note',
|
'credit_note',
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2,12 +2,14 @@ import { Module } from '@nestjs/common';
|
|||||||
import { FeaturesConfigureManager } from './FeaturesConfigureManager';
|
import { FeaturesConfigureManager } from './FeaturesConfigureManager';
|
||||||
import { FeaturesManager } from './FeaturesManager';
|
import { FeaturesManager } from './FeaturesManager';
|
||||||
import { FeaturesSettingsDriver } from './FeaturesSettingsDriver';
|
import { FeaturesSettingsDriver } from './FeaturesSettingsDriver';
|
||||||
|
import { FeaturesConfigure } from './FeaturesConfigure';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
providers: [
|
providers: [
|
||||||
FeaturesManager,
|
FeaturesManager,
|
||||||
FeaturesSettingsDriver,
|
FeaturesSettingsDriver,
|
||||||
FeaturesConfigureManager,
|
FeaturesConfigureManager,
|
||||||
|
FeaturesConfigure
|
||||||
],
|
],
|
||||||
exports: [FeaturesManager],
|
exports: [FeaturesManager],
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ export class FeaturesConfigure {
|
|||||||
constructor(private readonly configService: ConfigService) {}
|
constructor(private readonly configService: ConfigService) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Get the feature configure.
|
||||||
|
* @returns {IFeatureConfiugration[]}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
getConfigure(): IFeatureConfiugration[] {
|
getConfigure(): IFeatureConfiugration[] {
|
||||||
|
|||||||
@@ -9,10 +9,10 @@ import { FeaturesConfigure } from './FeaturesConfigure';
|
|||||||
export class FeaturesSettingsDriver {
|
export class FeaturesSettingsDriver {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly configure: FeaturesConfigureManager,
|
private readonly configure: FeaturesConfigureManager,
|
||||||
private readonly featuresConfigure: FeaturesConfigure
|
private readonly featuresConfigure: FeaturesConfigure,
|
||||||
|
|
||||||
@Inject(SETTINGS_PROVIDER)
|
@Inject(SETTINGS_PROVIDER)
|
||||||
private readonly settings: SettingsStore,
|
private readonly settings: () => SettingsStore,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -21,7 +21,7 @@ export class FeaturesSettingsDriver {
|
|||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
async turnOn(feature: string) {
|
async turnOn(feature: string) {
|
||||||
this.settings.set({ group: 'features', key: feature, value: true });
|
this.settings().set({ group: 'features', key: feature, value: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -30,7 +30,7 @@ export class FeaturesSettingsDriver {
|
|||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
async turnOff(feature: string) {
|
async turnOff(feature: string) {
|
||||||
this.settings.set({ group: 'features', key: feature, value: false });
|
this.settings().set({ group: 'features', key: feature, value: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -43,7 +43,7 @@ export class FeaturesSettingsDriver {
|
|||||||
feature,
|
feature,
|
||||||
'defaultValue',
|
'defaultValue',
|
||||||
);
|
);
|
||||||
const settingValue = this.settings.get(
|
const settingValue = this.settings().get(
|
||||||
{ group: 'features', key: feature },
|
{ group: 'features', key: feature },
|
||||||
defaultValue,
|
defaultValue,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ export class ItemCategoryApplication {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new item category.
|
* Creates a new item category.
|
||||||
* @param {number} tenantId - The tenant id.
|
|
||||||
* @param {IItemCategoryOTD} itemCategoryDTO - The item category data.
|
* @param {IItemCategoryOTD} itemCategoryDTO - The item category data.
|
||||||
* @returns {Promise<ItemCategory>} The created item category.
|
* @returns {Promise<ItemCategory>} The created item category.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -23,8 +23,9 @@ export class AutoIncrementManualJournal {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the next journal number.
|
* Retrieve the next journal number.
|
||||||
|
* @returns {Promise<string>}
|
||||||
*/
|
*/
|
||||||
public getNextJournalNumber = (): string => {
|
public getNextJournalNumber = (): Promise<string> => {
|
||||||
return this.autoIncrementOrdersService.getNextTransactionNumber(
|
return this.autoIncrementOrdersService.getNextTransactionNumber(
|
||||||
'manual_journals'
|
'manual_journals'
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ export class PaymentReceiveDTOTransformer {
|
|||||||
sumBy(paymentReceiveDTO.entries, 'paymentAmount');
|
sumBy(paymentReceiveDTO.entries, 'paymentAmount');
|
||||||
|
|
||||||
// Retreive the next invoice number.
|
// Retreive the next invoice number.
|
||||||
const autoNextNumber = this.increments.getNextPaymentReceiveNumber();
|
const autoNextNumber = await this.increments.getNextPaymentReceiveNumber();
|
||||||
|
|
||||||
// Retrieve the next payment receive number.
|
// Retrieve the next payment receive number.
|
||||||
const paymentReceiveNo =
|
const paymentReceiveNo =
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ export class PaymentReceivedIncrement {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the next unique payment receive number.
|
* Retrieve the next unique payment receive number.
|
||||||
* @return {string}
|
* @return {Promise<string>}
|
||||||
*/
|
*/
|
||||||
public getNextPaymentReceiveNumber(): string {
|
public getNextPaymentReceiveNumber(): Promise<string> {
|
||||||
return this.autoIncrementOrdersService.getNextTransactionNumber(
|
return this.autoIncrementOrdersService.getNextTransactionNumber(
|
||||||
'payment_receives',
|
'payment_receives',
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ export class SaleEstimateDTOTransformer {
|
|||||||
this.itemEntryModel().calcAmount(e),
|
this.itemEntryModel().calcAmount(e),
|
||||||
);
|
);
|
||||||
// Retrieve the next invoice number.
|
// Retrieve the next invoice number.
|
||||||
const autoNextNumber = this.estimateIncrement.getNextEstimateNumber();
|
const autoNextNumber = await this.estimateIncrement.getNextEstimateNumber();
|
||||||
|
|
||||||
// Retrieve the next estimate number.
|
// Retrieve the next estimate number.
|
||||||
const estimateNumber =
|
const estimateNumber =
|
||||||
@@ -103,11 +103,11 @@ export class SaleEstimateDTOTransformer {
|
|||||||
* @param {ISaleEstimateDTO} saleEstimateDTO
|
* @param {ISaleEstimateDTO} saleEstimateDTO
|
||||||
* @param {ISaleEstimate} oldSaleEstimate
|
* @param {ISaleEstimate} oldSaleEstimate
|
||||||
*/
|
*/
|
||||||
public transformEstimateNumberToModel(
|
public async transformEstimateNumberToModel(
|
||||||
saleEstimateDTO: ISaleEstimateDTO,
|
saleEstimateDTO: ISaleEstimateDTO,
|
||||||
oldSaleEstimate?: SaleEstimate,
|
oldSaleEstimate?: SaleEstimate,
|
||||||
): string {
|
): Promise<string> {
|
||||||
const autoNextNumber = this.estimateIncrement.getNextEstimateNumber();
|
const autoNextNumber = await this.estimateIncrement.getNextEstimateNumber();
|
||||||
|
|
||||||
if (saleEstimateDTO.estimateNumber) {
|
if (saleEstimateDTO.estimateNumber) {
|
||||||
return saleEstimateDTO.estimateNumber;
|
return saleEstimateDTO.estimateNumber;
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ export class SaleEstimateIncrement {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the next unique estimate number.
|
* Retrieve the next unique estimate number.
|
||||||
* @return {string}
|
* @return {Promise<string>}
|
||||||
*/
|
*/
|
||||||
public getNextEstimateNumber(): string {
|
public getNextEstimateNumber(): Promise<string> {
|
||||||
return this.autoIncrementOrdersService.getNextTransactionNumber(
|
return this.autoIncrementOrdersService.getNextTransactionNumber(
|
||||||
'sales_estimates',
|
'sales_estimates',
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,78 +1,73 @@
|
|||||||
// import { Inject, Service } from 'typedi';
|
import { Knex } from 'knex';
|
||||||
// import { Knex } from 'knex';
|
import { Injectable } from '@nestjs/common';
|
||||||
// import { ISaleInvoice } from '@/interfaces';
|
import { ItemsEntriesService } from '../Items/ItemsEntries.service';
|
||||||
// import ItemsEntriesService from '@/services/Items/ItemsEntriesService';
|
import { ModelObject } from 'objection';
|
||||||
// import InventoryService from '@/services/Inventory/Inventory';
|
import { SaleInvoice } from './models/SaleInvoice';
|
||||||
|
|
||||||
// @Service()
|
@Injectable()
|
||||||
// export class InvoiceInventoryTransactions {
|
export class InvoiceInventoryTransactions {
|
||||||
// @Inject()
|
constructor(
|
||||||
// private itemsEntriesService: ItemsEntriesService;
|
private readonly itemsEntriesService: ItemsEntriesService,
|
||||||
|
// private readonly inventoryService: InventoryService,
|
||||||
|
) {}
|
||||||
|
|
||||||
// @Inject()
|
/**
|
||||||
// private inventoryService: InventoryService;
|
* Records the inventory transactions of the given sale invoice in case
|
||||||
|
* the invoice has inventory entries only.
|
||||||
|
*
|
||||||
|
* @param {number} tenantId - Tenant id.
|
||||||
|
* @param {SaleInvoice} saleInvoice - Sale invoice DTO.
|
||||||
|
* @param {number} saleInvoiceId - Sale invoice id.
|
||||||
|
* @param {boolean} override - Allow to override old transactions.
|
||||||
|
* @return {Promise<void>}
|
||||||
|
*/
|
||||||
|
public async recordInventoryTranscactions(
|
||||||
|
saleInvoice: ModelObject<SaleInvoice>,
|
||||||
|
override?: boolean,
|
||||||
|
trx?: Knex.Transaction,
|
||||||
|
): Promise<void> {
|
||||||
|
// Loads the inventory items entries of the given sale invoice.
|
||||||
|
const inventoryEntries =
|
||||||
|
await this.itemsEntriesService.filterInventoryEntries(
|
||||||
|
saleInvoice.entries,
|
||||||
|
trx,
|
||||||
|
);
|
||||||
|
const transaction = {
|
||||||
|
transactionId: saleInvoice.id,
|
||||||
|
transactionType: 'SaleInvoice',
|
||||||
|
transactionNumber: saleInvoice.invoiceNo,
|
||||||
|
|
||||||
// /**
|
exchangeRate: saleInvoice.exchangeRate,
|
||||||
// * Records the inventory transactions of the given sale invoice in case
|
warehouseId: saleInvoice.warehouseId,
|
||||||
// * the invoice has inventory entries only.
|
|
||||||
// *
|
|
||||||
// * @param {number} tenantId - Tenant id.
|
|
||||||
// * @param {SaleInvoice} saleInvoice - Sale invoice DTO.
|
|
||||||
// * @param {number} saleInvoiceId - Sale invoice id.
|
|
||||||
// * @param {boolean} override - Allow to override old transactions.
|
|
||||||
// * @return {Promise<void>}
|
|
||||||
// */
|
|
||||||
// public async recordInventoryTranscactions(
|
|
||||||
// tenantId: number,
|
|
||||||
// saleInvoice: ISaleInvoice,
|
|
||||||
// override?: boolean,
|
|
||||||
// trx?: Knex.Transaction
|
|
||||||
// ): Promise<void> {
|
|
||||||
// // Loads the inventory items entries of the given sale invoice.
|
|
||||||
// const inventoryEntries =
|
|
||||||
// await this.itemsEntriesService.filterInventoryEntries(
|
|
||||||
// tenantId,
|
|
||||||
// saleInvoice.entries,
|
|
||||||
// trx
|
|
||||||
// );
|
|
||||||
// const transaction = {
|
|
||||||
// transactionId: saleInvoice.id,
|
|
||||||
// transactionType: 'SaleInvoice',
|
|
||||||
// transactionNumber: saleInvoice.invoiceNo,
|
|
||||||
|
|
||||||
// exchangeRate: saleInvoice.exchangeRate,
|
date: saleInvoice.invoiceDate,
|
||||||
// warehouseId: saleInvoice.warehouseId,
|
direction: 'OUT',
|
||||||
|
entries: inventoryEntries,
|
||||||
// date: saleInvoice.invoiceDate,
|
createdAt: saleInvoice.createdAt,
|
||||||
// direction: 'OUT',
|
};
|
||||||
// entries: inventoryEntries,
|
// await this.inventoryService.recordInventoryTransactionsFromItemsEntries(
|
||||||
// createdAt: saleInvoice.createdAt,
|
// transaction,
|
||||||
// };
|
// override,
|
||||||
// await this.inventoryService.recordInventoryTransactionsFromItemsEntries(
|
// trx,
|
||||||
// tenantId,
|
// );
|
||||||
// transaction,
|
}
|
||||||
// override,
|
/**
|
||||||
// trx
|
* Reverting the inventory transactions once the invoice deleted.
|
||||||
// );
|
* @param {number} tenantId - Tenant id.
|
||||||
// }
|
* @param {number} billId - Bill id.
|
||||||
// /**
|
* @return {Promise<void>}
|
||||||
// * Reverting the inventory transactions once the invoice deleted.
|
*/
|
||||||
// * @param {number} tenantId - Tenant id.
|
public async revertInventoryTransactions(
|
||||||
// * @param {number} billId - Bill id.
|
tenantId: number,
|
||||||
// * @return {Promise<void>}
|
saleInvoiceId: number,
|
||||||
// */
|
trx?: Knex.Transaction,
|
||||||
// public async revertInventoryTransactions(
|
): Promise<void> {
|
||||||
// tenantId: number,
|
// Delete the inventory transaction of the given sale invoice.
|
||||||
// saleInvoiceId: number,
|
// const { oldInventoryTransactions } =
|
||||||
// trx?: Knex.Transaction
|
// await this.inventoryService.deleteInventoryTransactions(
|
||||||
// ): Promise<void> {
|
// saleInvoiceId,
|
||||||
// // Delete the inventory transaction of the given sale invoice.
|
// 'SaleInvoice',
|
||||||
// const { oldInventoryTransactions } =
|
// trx,
|
||||||
// await this.inventoryService.deleteInventoryTransactions(
|
// );
|
||||||
// tenantId,
|
}
|
||||||
// saleInvoiceId,
|
}
|
||||||
// 'SaleInvoice',
|
|
||||||
// trx
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ export class CommandSaleInvoiceDTOTransformer {
|
|||||||
private invoiceIncrement: SaleInvoiceIncrement,
|
private invoiceIncrement: SaleInvoiceIncrement,
|
||||||
private taxDTOTransformer: ItemEntriesTaxTransactions,
|
private taxDTOTransformer: ItemEntriesTaxTransactions,
|
||||||
private brandingTemplatesTransformer: BrandingTemplateDTOTransformer,
|
private brandingTemplatesTransformer: BrandingTemplateDTOTransformer,
|
||||||
private tenancyContext: TenancyContext
|
private tenancyContext: TenancyContext,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -61,7 +61,7 @@ export class CommandSaleInvoiceDTOTransformer {
|
|||||||
const amount = this.getDueBalanceItemEntries(entriesModels);
|
const amount = this.getDueBalanceItemEntries(entriesModels);
|
||||||
|
|
||||||
// Retreive the next invoice number.
|
// Retreive the next invoice number.
|
||||||
const autoNextNumber = this.invoiceIncrement.getNextInvoiceNumber();
|
const autoNextNumber = await this.invoiceIncrement.getNextInvoiceNumber();
|
||||||
|
|
||||||
// Retrieve the authorized user.
|
// Retrieve the authorized user.
|
||||||
const authorizedUser = await this.tenancyContext.getSystemUser();
|
const authorizedUser = await this.tenancyContext.getSystemUser();
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ export class SaleInvoiceIncrement {
|
|||||||
/**
|
/**
|
||||||
* Retrieves the next unique invoice number.
|
* Retrieves the next unique invoice number.
|
||||||
* @param {number} tenantId - Tenant id.
|
* @param {number} tenantId - Tenant id.
|
||||||
* @return {string}
|
* @return {Promise<string>}
|
||||||
*/
|
*/
|
||||||
public getNextInvoiceNumber(): string {
|
public getNextInvoiceNumber(): Promise<string> {
|
||||||
return this.autoIncrementOrdersService.getNextTransactionNumber(
|
return this.autoIncrementOrdersService.getNextTransactionNumber(
|
||||||
'sales_invoices',
|
'sales_invoices',
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export class SaleReceiptIncrement {
|
|||||||
* @param {number} tenantId - Tenant id.
|
* @param {number} tenantId - Tenant id.
|
||||||
* @return {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
public getNextReceiptNumber(): string {
|
public getNextReceiptNumber(): Promise<string> {
|
||||||
return this.autoIncrementOrdersService.getNextTransactionNumber(
|
return this.autoIncrementOrdersService.getNextTransactionNumber(
|
||||||
'sales_receipts',
|
'sales_receipts',
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { Global, Module } from '@nestjs/common';
|
||||||
import { SettingRepository } from './repositories/Setting.repository';
|
import { SettingRepository } from './repositories/Setting.repository';
|
||||||
import { SettingsStore } from './SettingsStore';
|
import { SettingsStore } from './SettingsStore';
|
||||||
import { SettingsApplicationService } from './SettingsApplication.service';
|
import { SettingsApplicationService } from './SettingsApplication.service';
|
||||||
@@ -6,13 +6,15 @@ import { SaveSettingsService } from './commands/SaveSettings.service';
|
|||||||
import { SettingsController } from './Settings.controller';
|
import { SettingsController } from './Settings.controller';
|
||||||
import { SETTINGS_PROVIDER } from './Settings.types';
|
import { SETTINGS_PROVIDER } from './Settings.types';
|
||||||
import { GetSettingsService } from './queries/GetSettings.service';
|
import { GetSettingsService } from './queries/GetSettings.service';
|
||||||
|
import { ClsModule } from 'nestjs-cls';
|
||||||
|
|
||||||
|
@Global()
|
||||||
@Module({
|
@Module({
|
||||||
providers: [
|
imports: [
|
||||||
SettingRepository,
|
ClsModule.forFeatureAsync({
|
||||||
{
|
|
||||||
provide: SETTINGS_PROVIDER,
|
provide: SETTINGS_PROVIDER,
|
||||||
useFactory: async (settingRepository: SettingRepository) => {
|
inject: [SettingRepository],
|
||||||
|
useFactory: (settingRepository: SettingRepository) => async () => {
|
||||||
const settings = new SettingsStore(settingRepository);
|
const settings = new SettingsStore(settingRepository);
|
||||||
|
|
||||||
// Load settings from database.
|
// Load settings from database.
|
||||||
@@ -20,13 +22,18 @@ import { GetSettingsService } from './queries/GetSettings.service';
|
|||||||
|
|
||||||
return settings;
|
return settings;
|
||||||
},
|
},
|
||||||
inject: [SettingRepository],
|
global: true,
|
||||||
},
|
strict: true,
|
||||||
|
type: 'function',
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
providers: [
|
||||||
|
SettingRepository,
|
||||||
GetSettingsService,
|
GetSettingsService,
|
||||||
SettingsApplicationService,
|
SettingsApplicationService,
|
||||||
SaveSettingsService,
|
SaveSettingsService,
|
||||||
],
|
],
|
||||||
|
exports: [SettingRepository],
|
||||||
controllers: [SettingsController],
|
controllers: [SettingsController],
|
||||||
exports: [SETTINGS_PROVIDER],
|
|
||||||
})
|
})
|
||||||
export class SettingsModule {}
|
export class SettingsModule {}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { IOptionDTO, ISettingsDTO, SETTINGS_PROVIDER } from '../Settings.types';
|
|||||||
export class SaveSettingsService {
|
export class SaveSettingsService {
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(SETTINGS_PROVIDER)
|
@Inject(SETTINGS_PROVIDER)
|
||||||
private readonly settingsStore: SettingsStore,
|
private readonly settingsStore: () => SettingsStore,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -15,6 +15,7 @@ export class SaveSettingsService {
|
|||||||
* @param {ISettingsDTO} settingsDTO
|
* @param {ISettingsDTO} settingsDTO
|
||||||
*/
|
*/
|
||||||
public async saveSettings(settingsDTO: ISettingsDTO) {
|
public async saveSettings(settingsDTO: ISettingsDTO) {
|
||||||
|
const settingsStore = await this.settingsStore();
|
||||||
const notDefinedOptions = this.validateNotDefinedSettings(
|
const notDefinedOptions = this.validateNotDefinedSettings(
|
||||||
settingsDTO.options,
|
settingsDTO.options,
|
||||||
);
|
);
|
||||||
@@ -30,9 +31,9 @@ export class SaveSettingsService {
|
|||||||
throw new Error(JSON.stringify(errorReasons));
|
throw new Error(JSON.stringify(errorReasons));
|
||||||
}
|
}
|
||||||
settingsDTO.options.forEach((option: IOptionDTO) => {
|
settingsDTO.options.forEach((option: IOptionDTO) => {
|
||||||
this.settingsStore.set({ ...option });
|
settingsStore.set({ ...option });
|
||||||
});
|
});
|
||||||
await this.settingsStore.save();
|
await settingsStore.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -44,7 +45,7 @@ export class SaveSettingsService {
|
|||||||
const notDefined = [];
|
const notDefined = [];
|
||||||
|
|
||||||
options.forEach((option) => {
|
options.forEach((option) => {
|
||||||
const setting = this.settingsStore.config.getMetaConfig(
|
const setting = this.settingsStore().config.getMetaConfig(
|
||||||
option.key,
|
option.key,
|
||||||
option.group,
|
option.group,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -5,10 +5,11 @@ import { SETTINGS_PROVIDER } from '../Settings.types';
|
|||||||
@Injectable()
|
@Injectable()
|
||||||
export class GetSettingsService {
|
export class GetSettingsService {
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(SETTINGS_PROVIDER) private readonly settingsStore: SettingsStore,
|
@Inject(SETTINGS_PROVIDER)
|
||||||
|
private readonly settingsStore: () => SettingsStore,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public async execute() {
|
public async execute() {
|
||||||
return this.settingsStore.all();
|
return (await this.settingsStore()).all();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
import { Knex } from 'knex';
|
import { Knex } from 'knex';
|
||||||
import { Inject } from '@nestjs/common';
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
import { TenantRepository } from '@/common/repository/TenantRepository';
|
import { TenantRepository } from '@/common/repository/TenantRepository';
|
||||||
import { TENANCY_DB_CONNECTION } from '@/modules/Tenancy/TenancyDB/TenancyDB.constants';
|
import { TENANCY_DB_CONNECTION } from '@/modules/Tenancy/TenancyDB/TenancyDB.constants';
|
||||||
import { Setting } from '../models/Setting';
|
import { Setting } from '../models/Setting';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
export class SettingRepository extends TenantRepository {
|
export class SettingRepository extends TenantRepository {
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(TENANCY_DB_CONNECTION)
|
@Inject(TENANCY_DB_CONNECTION)
|
||||||
private readonly tenantKnex: Knex,
|
private readonly tenantKnex: () => Knex,
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
@@ -16,6 +17,6 @@ export class SettingRepository extends TenantRepository {
|
|||||||
* Gets the repository's model.
|
* Gets the repository's model.
|
||||||
*/
|
*/
|
||||||
get model(): typeof Setting {
|
get model(): typeof Setting {
|
||||||
return Setting.bindKnex(this.tenantKnex);
|
return Setting.bindKnex(this.tenantKnex());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,8 +85,6 @@ const models = [
|
|||||||
* @param model The model class to register
|
* @param model The model class to register
|
||||||
*/
|
*/
|
||||||
export function RegisterTenancyModel(model: typeof Model) {
|
export function RegisterTenancyModel(model: typeof Model) {
|
||||||
console.log(model.name);
|
|
||||||
|
|
||||||
return ClsModule.forFeatureAsync({
|
return ClsModule.forFeatureAsync({
|
||||||
provide: model.name,
|
provide: model.name,
|
||||||
inject: [TENANCY_DB_CONNECTION],
|
inject: [TENANCY_DB_CONNECTION],
|
||||||
|
|||||||
@@ -8,11 +8,13 @@ import {
|
|||||||
import { Inject, Injectable } from '@nestjs/common';
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
import { SettingsStore } from '../Settings/SettingsStore';
|
import { SettingsStore } from '../Settings/SettingsStore';
|
||||||
import { SETTINGS_PROVIDER } from '../Settings/Settings.types';
|
import { SETTINGS_PROVIDER } from '../Settings/Settings.types';
|
||||||
|
import { SettingsApplicationService } from '../Settings/SettingsApplication.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TransactionsLockingRepository {
|
export class TransactionsLockingRepository {
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(SETTINGS_PROVIDER) private readonly settingsStore: SettingsStore,
|
@Inject(SETTINGS_PROVIDER)
|
||||||
|
private readonly settingsStore: () => SettingsStore,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -25,57 +27,58 @@ export class TransactionsLockingRepository {
|
|||||||
transactionlocking,
|
transactionlocking,
|
||||||
) {
|
) {
|
||||||
const group = `transactions-locking`;
|
const group = `transactions-locking`;
|
||||||
|
const settingsStore = await this.settingsStore();
|
||||||
|
|
||||||
if (!isUndefined(transactionlocking.active)) {
|
if (!isUndefined(transactionlocking.active)) {
|
||||||
this.settingsStore.set({
|
settingsStore.set({
|
||||||
group,
|
group,
|
||||||
key: `${lockingGroup}.active`,
|
key: `${lockingGroup}.active`,
|
||||||
value: transactionlocking.active,
|
value: transactionlocking.active,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (!isUndefined(transactionlocking.lockToDate)) {
|
if (!isUndefined(transactionlocking.lockToDate)) {
|
||||||
this.settingsStore.set({
|
settingsStore.set({
|
||||||
group,
|
group,
|
||||||
key: `${lockingGroup}.lock_to_date`,
|
key: `${lockingGroup}.lock_to_date`,
|
||||||
value: parseDate(transactionlocking.lockToDate),
|
value: parseDate(transactionlocking.lockToDate),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (!isUndefined(transactionlocking.unlockFromDate)) {
|
if (!isUndefined(transactionlocking.unlockFromDate)) {
|
||||||
this.settingsStore.set({
|
settingsStore.set({
|
||||||
group,
|
group,
|
||||||
key: `${lockingGroup}.unlock_from_date`,
|
key: `${lockingGroup}.unlock_from_date`,
|
||||||
value: parseDate(transactionlocking.unlockFromDate),
|
value: parseDate(transactionlocking.unlockFromDate),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (!isUndefined(transactionlocking.unlockToDate)) {
|
if (!isUndefined(transactionlocking.unlockToDate)) {
|
||||||
this.settingsStore.set({
|
settingsStore.set({
|
||||||
group,
|
group,
|
||||||
key: `${lockingGroup}.unlock_to_date`,
|
key: `${lockingGroup}.unlock_to_date`,
|
||||||
value: parseDate(transactionlocking.unlockToDate),
|
value: parseDate(transactionlocking.unlockToDate),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (!isUndefined(transactionlocking.lockReason)) {
|
if (!isUndefined(transactionlocking.lockReason)) {
|
||||||
this.settingsStore.set({
|
settingsStore.set({
|
||||||
group,
|
group,
|
||||||
key: `${lockingGroup}.lock_reason`,
|
key: `${lockingGroup}.lock_reason`,
|
||||||
value: transactionlocking.lockReason,
|
value: transactionlocking.lockReason,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (!isUndefined(transactionlocking.unlockReason)) {
|
if (!isUndefined(transactionlocking.unlockReason)) {
|
||||||
this.settingsStore.set({
|
settingsStore.set({
|
||||||
group,
|
group,
|
||||||
key: `${lockingGroup}.unlock_reason`,
|
key: `${lockingGroup}.unlock_reason`,
|
||||||
value: transactionlocking.unlockReason,
|
value: transactionlocking.unlockReason,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (!isUndefined(transactionlocking.partialUnlockReason)) {
|
if (!isUndefined(transactionlocking.partialUnlockReason)) {
|
||||||
this.settingsStore.set({
|
settingsStore.set({
|
||||||
group,
|
group,
|
||||||
key: `${lockingGroup}.partial_unlock_reason`,
|
key: `${lockingGroup}.partial_unlock_reason`,
|
||||||
value: transactionlocking.partialUnlockReason,
|
value: transactionlocking.partialUnlockReason,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
await this.settingsStore.save();
|
await settingsStore.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -83,40 +86,41 @@ export class TransactionsLockingRepository {
|
|||||||
* @param {string} lockingGroup - The group of the transactions locking
|
* @param {string} lockingGroup - The group of the transactions locking
|
||||||
* @returns {ITransactionMeta} - The transactions locking settings
|
* @returns {ITransactionMeta} - The transactions locking settings
|
||||||
*/
|
*/
|
||||||
public getTransactionsLocking(
|
public async getTransactionsLocking(
|
||||||
lockingGroup: string = TransactionsLockingGroup.All,
|
lockingGroup: string = TransactionsLockingGroup.All,
|
||||||
): ITransactionMeta {
|
): Promise<ITransactionMeta> {
|
||||||
const group = `transactions-locking`;
|
const group = `transactions-locking`;
|
||||||
|
const settingsStore = await this.settingsStore();
|
||||||
|
|
||||||
const isEnabled = this.settingsStore.get({
|
const isEnabled = settingsStore.get({
|
||||||
group,
|
group,
|
||||||
key: `${lockingGroup}.active`,
|
key: `${lockingGroup}.active`,
|
||||||
});
|
});
|
||||||
const lockFromDate = this.settingsStore.get({
|
const lockFromDate = settingsStore.get({
|
||||||
group,
|
group,
|
||||||
key: `${lockingGroup}.lock_from_date`,
|
key: `${lockingGroup}.lock_from_date`,
|
||||||
});
|
});
|
||||||
const lockToDate = this.settingsStore.get({
|
const lockToDate = settingsStore.get({
|
||||||
group,
|
group,
|
||||||
key: `${lockingGroup}.lock_to_date`,
|
key: `${lockingGroup}.lock_to_date`,
|
||||||
});
|
});
|
||||||
const unlockFromDate = this.settingsStore.get({
|
const unlockFromDate = settingsStore.get({
|
||||||
group,
|
group,
|
||||||
key: `${lockingGroup}.unlock_from_date`,
|
key: `${lockingGroup}.unlock_from_date`,
|
||||||
});
|
});
|
||||||
const unlockToDate = this.settingsStore.get({
|
const unlockToDate = settingsStore.get({
|
||||||
group,
|
group,
|
||||||
key: `${lockingGroup}.unlock_to_date`,
|
key: `${lockingGroup}.unlock_to_date`,
|
||||||
});
|
});
|
||||||
const lockReason = this.settingsStore.get({
|
const lockReason = settingsStore.get({
|
||||||
group,
|
group,
|
||||||
key: `${lockingGroup}.lock_reason`,
|
key: `${lockingGroup}.lock_reason`,
|
||||||
});
|
});
|
||||||
const unlockReason = this.settingsStore.get({
|
const unlockReason = settingsStore.get({
|
||||||
group,
|
group,
|
||||||
key: `${lockingGroup}.unlock_reason`,
|
key: `${lockingGroup}.unlock_reason`,
|
||||||
});
|
});
|
||||||
const partialUnlockReason = this.settingsStore.get({
|
const partialUnlockReason = settingsStore.get({
|
||||||
group,
|
group,
|
||||||
key: `${lockingGroup}.partial_unlock_reason`,
|
key: `${lockingGroup}.partial_unlock_reason`,
|
||||||
});
|
});
|
||||||
@@ -137,8 +141,10 @@ export class TransactionsLockingRepository {
|
|||||||
* Get transactions locking type
|
* Get transactions locking type
|
||||||
* @returns {string} - The transactions locking type
|
* @returns {string} - The transactions locking type
|
||||||
*/
|
*/
|
||||||
public getTransactionsLockingType() {
|
public async getTransactionsLockingType() {
|
||||||
const lockingType = this.settingsStore.get({
|
const settingsStore = await this.settingsStore();
|
||||||
|
|
||||||
|
const lockingType = settingsStore.get({
|
||||||
group: 'transactions-locking',
|
group: 'transactions-locking',
|
||||||
key: 'locking-type',
|
key: 'locking-type',
|
||||||
});
|
});
|
||||||
@@ -149,14 +155,17 @@ export class TransactionsLockingRepository {
|
|||||||
* Flag transactions locking type
|
* Flag transactions locking type
|
||||||
* @param {TransactionsLockingType} transactionsType - The transactions locking type
|
* @param {TransactionsLockingType} transactionsType - The transactions locking type
|
||||||
*/
|
*/
|
||||||
public flagTransactionsLockingType(
|
public async flagTransactionsLockingType(
|
||||||
transactionsType: TransactionsLockingType,
|
transactionsType: TransactionsLockingType,
|
||||||
) {
|
) {
|
||||||
this.settingsStore.set({
|
const settingsStore = await this.settingsStore();
|
||||||
|
|
||||||
|
settingsStore.set({
|
||||||
group: 'transactions-locking',
|
group: 'transactions-locking',
|
||||||
key: 'locking-type',
|
key: 'locking-type',
|
||||||
value: transactionsType,
|
value: transactionsType,
|
||||||
});
|
});
|
||||||
|
await settingsStore.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ export class TransactionsLockingService {
|
|||||||
|
|
||||||
// Retrieve the current transactions locking type.
|
// Retrieve the current transactions locking type.
|
||||||
const lockingType =
|
const lockingType =
|
||||||
this.transactionsLockingRepo.getTransactionsLockingType();
|
await this.transactionsLockingRepo.getTransactionsLockingType();
|
||||||
|
|
||||||
if (moduleGroup !== TransactionsLockingGroup.All) {
|
if (moduleGroup !== TransactionsLockingGroup.All) {
|
||||||
this.validateLockingTypeNotAll(lockingType);
|
this.validateLockingTypeNotAll(lockingType);
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ export class FinancialTransactionLocking {
|
|||||||
* @param {Date} transactionDate - The transaction date.
|
* @param {Date} transactionDate - The transaction date.
|
||||||
* @throws {ServiceError(TRANSACTIONS_DATE_LOCKED)}
|
* @throws {ServiceError(TRANSACTIONS_DATE_LOCKED)}
|
||||||
*/
|
*/
|
||||||
public transactionLockingGuard = (transactionDate: Date) => {
|
public transactionLockingGuard = async (transactionDate: Date) => {
|
||||||
this.transactionLockingGuardService.transactionsLockingGuard(
|
await this.transactionLockingGuardService.transactionsLockingGuard(
|
||||||
transactionDate,
|
transactionDate,
|
||||||
TransactionsLockingGroup.Financial,
|
TransactionsLockingGroup.Financial,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ export class PurchasesTransactionLockingGuard {
|
|||||||
public transactionLockingGuard = async (
|
public transactionLockingGuard = async (
|
||||||
transactionDate: MomentInput
|
transactionDate: MomentInput
|
||||||
) => {
|
) => {
|
||||||
this.transactionLockingGuardService.transactionsLockingGuard(
|
await this.transactionLockingGuardService.transactionsLockingGuard(
|
||||||
transactionDate,
|
transactionDate,
|
||||||
TransactionsLockingGroup.Purchases
|
TransactionsLockingGroup.Purchases
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -18,14 +18,12 @@ export class TransactionsLockingGuard {
|
|||||||
* @param {TransactionsLockingGroup} lockingGroup - The transaction group.
|
* @param {TransactionsLockingGroup} lockingGroup - The transaction group.
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
public isTransactionsLocking = (
|
public isTransactionsLocking = async (
|
||||||
transactionDate: MomentInput,
|
transactionDate: MomentInput,
|
||||||
lockingGroup: string = TransactionsLockingGroup.All
|
lockingGroup: string = TransactionsLockingGroup.All,
|
||||||
): boolean => {
|
): Promise<boolean> => {
|
||||||
const { isEnabled, unlockFromDate, unlockToDate, lockToDate } =
|
const { isEnabled, unlockFromDate, unlockToDate, lockToDate } =
|
||||||
this.transactionsLockingRepo.getTransactionsLocking(
|
await this.transactionsLockingRepo.getTransactionsLocking(lockingGroup);
|
||||||
lockingGroup
|
|
||||||
);
|
|
||||||
// Returns false anyway in case if the transaction locking is disabled.
|
// Returns false anyway in case if the transaction locking is disabled.
|
||||||
if (!isEnabled) return false;
|
if (!isEnabled) return false;
|
||||||
|
|
||||||
@@ -49,14 +47,15 @@ export class TransactionsLockingGuard {
|
|||||||
*
|
*
|
||||||
* @throws {ServiceError}
|
* @throws {ServiceError}
|
||||||
*/
|
*/
|
||||||
public validateTransactionsLocking = (
|
public validateTransactionsLocking = async (
|
||||||
transactionDate: MomentInput,
|
transactionDate: MomentInput,
|
||||||
lockingGroup: TransactionsLockingGroup
|
lockingGroup: TransactionsLockingGroup,
|
||||||
) => {
|
) => {
|
||||||
const isLocked = this.isTransactionsLocking(
|
const isLocked = await this.isTransactionsLocking(
|
||||||
transactionDate,
|
transactionDate,
|
||||||
lockingGroup
|
lockingGroup,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (isLocked) {
|
if (isLocked) {
|
||||||
this.throwTransactionsLockError(lockingGroup);
|
this.throwTransactionsLockError(lockingGroup);
|
||||||
}
|
}
|
||||||
@@ -66,12 +65,11 @@ export class TransactionsLockingGuard {
|
|||||||
* Throws transactions locking error.
|
* Throws transactions locking error.
|
||||||
* @param {TransactionsLockingGroup} lockingGroup - The transaction group.
|
* @param {TransactionsLockingGroup} lockingGroup - The transaction group.
|
||||||
*/
|
*/
|
||||||
public throwTransactionsLockError = (
|
public throwTransactionsLockError = async (
|
||||||
lockingGroup: TransactionsLockingGroup
|
lockingGroup: TransactionsLockingGroup,
|
||||||
) => {
|
) => {
|
||||||
const { lockToDate } = this.transactionsLockingRepo.getTransactionsLocking(
|
const { lockToDate } =
|
||||||
lockingGroup
|
await this.transactionsLockingRepo.getTransactionsLocking(lockingGroup);
|
||||||
);
|
|
||||||
throw new ServiceError(ERRORS.TRANSACTIONS_DATE_LOCKED, null, {
|
throw new ServiceError(ERRORS.TRANSACTIONS_DATE_LOCKED, null, {
|
||||||
lockedToDate: lockToDate,
|
lockedToDate: lockToDate,
|
||||||
formattedLockedToDate: moment(lockToDate).format('YYYY/MM/DD'),
|
formattedLockedToDate: moment(lockToDate).format('YYYY/MM/DD'),
|
||||||
@@ -83,24 +81,21 @@ export class TransactionsLockingGuard {
|
|||||||
* @param {TransactionsLockingGroup} lockingGroup - The transaction group.
|
* @param {TransactionsLockingGroup} lockingGroup - The transaction group.
|
||||||
* @param {Date} transactionDate - The transaction date.
|
* @param {Date} transactionDate - The transaction date.
|
||||||
*/
|
*/
|
||||||
public transactionsLockingGuard = (
|
public transactionsLockingGuard = async (
|
||||||
transactionDate: MomentInput,
|
transactionDate: MomentInput,
|
||||||
moduleType: TransactionsLockingGroup
|
moduleType: TransactionsLockingGroup,
|
||||||
) => {
|
) => {
|
||||||
const lockingType =
|
const lockingType =
|
||||||
this.transactionsLockingRepo.getTransactionsLockingType();
|
await this.transactionsLockingRepo.getTransactionsLockingType();
|
||||||
|
|
||||||
//
|
//
|
||||||
if (lockingType === TransactionsLockingGroup.All) {
|
if (lockingType === TransactionsLockingGroup.All) {
|
||||||
return this.validateTransactionsLocking(
|
return this.validateTransactionsLocking(
|
||||||
transactionDate,
|
transactionDate,
|
||||||
TransactionsLockingGroup.All
|
TransactionsLockingGroup.All,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
return this.validateTransactionsLocking(
|
return this.validateTransactionsLocking(transactionDate, moduleType);
|
||||||
transactionDate,
|
|
||||||
moduleType
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ export class QueryTransactionsLocking {
|
|||||||
* Retrieve transactions locking modules.
|
* Retrieve transactions locking modules.
|
||||||
* @returns {ITransactionLockingMetaPOJO[]}
|
* @returns {ITransactionLockingMetaPOJO[]}
|
||||||
*/
|
*/
|
||||||
public getTransactionsLockingModules = (): Promise<
|
public getTransactionsLockingModules = async (): Promise<
|
||||||
ITransactionLockingMetaPOJO[]
|
ITransactionLockingMetaPOJO[]
|
||||||
> => {
|
> => {
|
||||||
const modules = TRANSACTIONS_LOCKING_SCHEMA.map(
|
const modules = TRANSACTIONS_LOCKING_SCHEMA.map(
|
||||||
@@ -47,10 +47,12 @@ export class QueryTransactionsLocking {
|
|||||||
* @param {TransactionsLockingGroup} module -
|
* @param {TransactionsLockingGroup} module -
|
||||||
* @returns {ITransactionLockingMetaPOJO}
|
* @returns {ITransactionLockingMetaPOJO}
|
||||||
*/
|
*/
|
||||||
public getTransactionsLockingModuleMeta = (
|
public getTransactionsLockingModuleMeta = async (
|
||||||
module: TransactionsLockingGroup,
|
module: TransactionsLockingGroup,
|
||||||
): Promise<ITransactionLockingMetaPOJO> => {
|
): Promise<ITransactionLockingMetaPOJO> => {
|
||||||
const meta = this.transactionsLockingRepo.getTransactionsLocking(module);
|
const meta =
|
||||||
|
await this.transactionsLockingRepo.getTransactionsLocking(module);
|
||||||
|
|
||||||
return this.transformer.transform(
|
return this.transformer.transform(
|
||||||
meta,
|
meta,
|
||||||
new TransactionsLockingMetaTransformer(),
|
new TransactionsLockingMetaTransformer(),
|
||||||
@@ -66,7 +68,7 @@ export class QueryTransactionsLocking {
|
|||||||
async (): Promise<ITransactionsLockingListPOJO> => {
|
async (): Promise<ITransactionsLockingListPOJO> => {
|
||||||
// Retrieve the current transactions locking type.
|
// Retrieve the current transactions locking type.
|
||||||
const lockingType =
|
const lockingType =
|
||||||
this.transactionsLockingRepo.getTransactionsLockingType();
|
await this.transactionsLockingRepo.getTransactionsLockingType();
|
||||||
|
|
||||||
const all = await this.getTransactionsLockingAll();
|
const all = await this.getTransactionsLockingAll();
|
||||||
const modules = await this.getTransactionsLockingModules();
|
const modules = await this.getTransactionsLockingModules();
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ export class CreateVendorCreditService {
|
|||||||
);
|
);
|
||||||
// Transforms the credit DTO to storage layer.
|
// Transforms the credit DTO to storage layer.
|
||||||
const vendorCreditModel =
|
const vendorCreditModel =
|
||||||
this.vendorCreditDTOTransformService.transformCreateEditDTOToModel(
|
await this.vendorCreditDTOTransformService.transformCreateEditDTOToModel(
|
||||||
vendorCreditCreateDTO,
|
vendorCreditCreateDTO,
|
||||||
vendor.currencyCode,
|
vendor.currencyCode,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ export class EditVendorCreditService {
|
|||||||
);
|
);
|
||||||
// Transformes edit DTO to model storage layer.
|
// Transformes edit DTO to model storage layer.
|
||||||
const vendorCreditModel =
|
const vendorCreditModel =
|
||||||
this.vendorCreditDTOTransform.transformCreateEditDTOToModel(
|
await this.vendorCreditDTOTransform.transformCreateEditDTOToModel(
|
||||||
vendorCreditDTO,
|
vendorCreditDTO,
|
||||||
vendor.currencyCode,
|
vendor.currencyCode,
|
||||||
oldVendorCredit,
|
oldVendorCredit,
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export class VendorCreditAutoIncrementService {
|
|||||||
* @param {number} tenantId - Tenant id.
|
* @param {number} tenantId - Tenant id.
|
||||||
* @return {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
public getNextCreditNumber = (): string => {
|
public getNextCreditNumber = (): Promise<string> => {
|
||||||
return this.autoIncrementOrdersService.getNextTransactionNumber(
|
return this.autoIncrementOrdersService.getNextTransactionNumber(
|
||||||
'vendor_credit',
|
'vendor_credit',
|
||||||
);
|
);
|
||||||
@@ -22,7 +22,6 @@ export class VendorCreditAutoIncrementService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Increment the vendor credit serial next number.
|
* Increment the vendor credit serial next number.
|
||||||
* @param {number} tenantId -
|
|
||||||
*/
|
*/
|
||||||
public incrementSerialNumber = () => {
|
public incrementSerialNumber = () => {
|
||||||
return this.autoIncrementOrdersService.incrementSettingsNextNumber(
|
return this.autoIncrementOrdersService.incrementSettingsNextNumber(
|
||||||
|
|||||||
@@ -38,11 +38,11 @@ export class VendorCreditDTOTransformService {
|
|||||||
* @param {IVendorCredit} oldVendorCredit -
|
* @param {IVendorCredit} oldVendorCredit -
|
||||||
* @returns {VendorCredit}
|
* @returns {VendorCredit}
|
||||||
*/
|
*/
|
||||||
public transformCreateEditDTOToModel = (
|
public transformCreateEditDTOToModel = async (
|
||||||
vendorCreditDTO: IVendorCreditCreateDTO | IVendorCreditEditDTO,
|
vendorCreditDTO: IVendorCreditCreateDTO | IVendorCreditEditDTO,
|
||||||
vendorCurrencyCode: string,
|
vendorCurrencyCode: string,
|
||||||
oldVendorCredit?: VendorCredit,
|
oldVendorCredit?: VendorCredit,
|
||||||
): VendorCredit => {
|
): Promise<VendorCredit> => {
|
||||||
// Calculates the total amount of items entries.
|
// Calculates the total amount of items entries.
|
||||||
const amount = this.itemsEntriesService.getTotalItemsEntries(
|
const amount = this.itemsEntriesService.getTotalItemsEntries(
|
||||||
vendorCreditDTO.entries,
|
vendorCreditDTO.entries,
|
||||||
@@ -59,7 +59,8 @@ export class VendorCreditDTOTransformService {
|
|||||||
)(vendorCreditDTO.entries);
|
)(vendorCreditDTO.entries);
|
||||||
|
|
||||||
// Retreive the next vendor credit number.
|
// Retreive the next vendor credit number.
|
||||||
const autoNextNumber = this.vendorCreditAutoIncrement.getNextCreditNumber();
|
const autoNextNumber =
|
||||||
|
await this.vendorCreditAutoIncrement.getNextCreditNumber();
|
||||||
|
|
||||||
// Detarmines the credit note number.
|
// Detarmines the credit note number.
|
||||||
const vendorCreditNumber =
|
const vendorCreditNumber =
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
import { Knex } from 'knex';
|
import { Knex } from 'knex';
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
import { AccountTransaction } from '../Accounts/models/AccountTransaction.model';
|
import { AccountTransaction } from '../Accounts/models/AccountTransaction.model';
|
||||||
import { TenantModelProxy } from '../System/models/TenantBaseModel';
|
import { TenantModelProxy } from '../System/models/TenantBaseModel';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class InventoryTransactionsWarehouses {
|
export class InventoryTransactionsWarehouses {
|
||||||
constructor(
|
constructor(
|
||||||
|
@Inject(AccountTransaction.name)
|
||||||
private readonly accountTransactionModel: TenantModelProxy<typeof AccountTransaction>,
|
private readonly accountTransactionModel: TenantModelProxy<typeof AccountTransaction>,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
import { Injectable } from "@nestjs/common";
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
import { Warehouse } from "../models/Warehouse.model";
|
import { Warehouse } from '../models/Warehouse.model';
|
||||||
import { TenantModelProxy } from "@/modules/System/models/TenantBaseModel";
|
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||||
import { Bill } from "@/modules/Bills/models/Bill";
|
import { Bill } from '@/modules/Bills/models/Bill';
|
||||||
import { ItemEntry } from "@/modules/TransactionItemEntry/models/ItemEntry";
|
import { ItemEntry } from '@/modules/TransactionItemEntry/models/ItemEntry';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class BillActivateWarehouses {
|
export class BillActivateWarehouses {
|
||||||
constructor(
|
constructor(
|
||||||
|
@Inject(Bill.name)
|
||||||
private readonly billModel: TenantModelProxy<typeof Bill>,
|
private readonly billModel: TenantModelProxy<typeof Bill>,
|
||||||
|
|
||||||
|
@Inject(ItemEntry.name)
|
||||||
private readonly itemEntryModel: TenantModelProxy<typeof ItemEntry>,
|
private readonly itemEntryModel: TenantModelProxy<typeof ItemEntry>,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@@ -17,17 +20,14 @@ export class BillActivateWarehouses {
|
|||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
public updateBillsWithWarehouse = async (
|
public updateBillsWithWarehouse = async (
|
||||||
primaryWarehouse: Warehouse
|
primaryWarehouse: Warehouse,
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
// Updates the sale estimates with primary warehouse.
|
// Updates the sale estimates with primary warehouse.
|
||||||
await this.billModel().query().update({
|
await this.billModel().query().update({
|
||||||
warehouseId: primaryWarehouse.id,
|
warehouseId: primaryWarehouse.id,
|
||||||
});
|
});
|
||||||
// Update the sale estimates entries with primary warehouse.
|
// Update the sale estimates entries with primary warehouse.
|
||||||
await this.itemEntryModel()
|
await this.itemEntryModel().query().where('referenceType', 'Bill').update({
|
||||||
.query()
|
|
||||||
.where('referenceType', 'Bill')
|
|
||||||
.update({
|
|
||||||
warehouseId: primaryWarehouse.id,
|
warehouseId: primaryWarehouse.id,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||||
import { ItemEntry } from '@/modules/TransactionItemEntry/models/ItemEntry';
|
import { ItemEntry } from '@/modules/TransactionItemEntry/models/ItemEntry';
|
||||||
import { CreditNote } from '@/modules/CreditNotes/models/CreditNote';
|
import { CreditNote } from '@/modules/CreditNotes/models/CreditNote';
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
import { Warehouse } from '../models/Warehouse.model';
|
import { Warehouse } from '../models/Warehouse.model';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CreditNotesActivateWarehouses {
|
export class CreditNotesActivateWarehouses {
|
||||||
constructor(
|
constructor(
|
||||||
|
@Inject(CreditNote.name)
|
||||||
private readonly creditNoteModel: TenantModelProxy<typeof CreditNote>,
|
private readonly creditNoteModel: TenantModelProxy<typeof CreditNote>,
|
||||||
|
|
||||||
|
@Inject(ItemEntry.name)
|
||||||
private readonly itemEntryModel: TenantModelProxy<typeof ItemEntry>,
|
private readonly itemEntryModel: TenantModelProxy<typeof ItemEntry>,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +1,26 @@
|
|||||||
import { Injectable } from "@nestjs/common";
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
import { Warehouse } from "../models/Warehouse.model";
|
import { Warehouse } from '../models/Warehouse.model';
|
||||||
import { SaleInvoice } from "@/modules/SaleInvoices/models/SaleInvoice";
|
import { SaleInvoice } from '@/modules/SaleInvoices/models/SaleInvoice';
|
||||||
import { ItemEntry } from "@/modules/TransactionItemEntry/models/ItemEntry";
|
import { ItemEntry } from '@/modules/TransactionItemEntry/models/ItemEntry';
|
||||||
import { TenantModelProxy } from "@/modules/System/models/TenantBaseModel";
|
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class InvoicesActivateWarehouses {
|
export class InvoicesActivateWarehouses {
|
||||||
constructor(
|
constructor(
|
||||||
|
@Inject(SaleInvoice.name)
|
||||||
private readonly saleInvoiceModel: TenantModelProxy<typeof SaleInvoice>,
|
private readonly saleInvoiceModel: TenantModelProxy<typeof SaleInvoice>,
|
||||||
|
|
||||||
|
@Inject(ItemEntry.name)
|
||||||
private readonly itemEntryModel: TenantModelProxy<typeof ItemEntry>,
|
private readonly itemEntryModel: TenantModelProxy<typeof ItemEntry>,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates all inventory transactions with the primary warehouse.
|
* Updates all inventory transactions with the primary warehouse.
|
||||||
* @param {Warehouse} primaryWarehouse
|
* @param {Warehouse} primaryWarehouse
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
updateInvoicesWithWarehouse = async (
|
updateInvoicesWithWarehouse = async (
|
||||||
primaryWarehouse: Warehouse
|
primaryWarehouse: Warehouse,
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
// Updates the sale invoices with primary warehouse.
|
// Updates the sale invoices with primary warehouse.
|
||||||
await this.saleInvoiceModel().query().update({
|
await this.saleInvoiceModel().query().update({
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||||
import { ItemEntry } from '@/modules/TransactionItemEntry/models/ItemEntry';
|
import { ItemEntry } from '@/modules/TransactionItemEntry/models/ItemEntry';
|
||||||
import { Warehouse } from '../models/Warehouse.model';
|
import { Warehouse } from '../models/Warehouse.model';
|
||||||
@@ -7,7 +7,10 @@ import { SaleReceipt } from '@/modules/SaleReceipts/models/SaleReceipt';
|
|||||||
@Injectable()
|
@Injectable()
|
||||||
export class ReceiptActivateWarehouses {
|
export class ReceiptActivateWarehouses {
|
||||||
constructor(
|
constructor(
|
||||||
|
@Inject(SaleReceipt.name)
|
||||||
private readonly saleReceiptModel: TenantModelProxy<typeof SaleReceipt>,
|
private readonly saleReceiptModel: TenantModelProxy<typeof SaleReceipt>,
|
||||||
|
|
||||||
|
@Inject(ItemEntry.name)
|
||||||
private readonly itemEntryModel: TenantModelProxy<typeof ItemEntry>,
|
private readonly itemEntryModel: TenantModelProxy<typeof ItemEntry>,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
|||||||
@@ -2,12 +2,15 @@ import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
|||||||
import { VendorCredit } from '@/modules/VendorCredit/models/VendorCredit';
|
import { VendorCredit } from '@/modules/VendorCredit/models/VendorCredit';
|
||||||
import { ItemEntry } from '@/modules/TransactionItemEntry/models/ItemEntry';
|
import { ItemEntry } from '@/modules/TransactionItemEntry/models/ItemEntry';
|
||||||
import { Warehouse } from '../models/Warehouse.model';
|
import { Warehouse } from '../models/Warehouse.model';
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class VendorCreditActivateWarehouses {
|
export class VendorCreditActivateWarehouses {
|
||||||
constructor(
|
constructor(
|
||||||
|
@Inject(VendorCredit.name)
|
||||||
private readonly vendorCreditModel: TenantModelProxy<typeof VendorCredit>,
|
private readonly vendorCreditModel: TenantModelProxy<typeof VendorCredit>,
|
||||||
|
|
||||||
|
@Inject(ItemEntry.name)
|
||||||
private readonly itemEntryModel: TenantModelProxy<typeof ItemEntry>,
|
private readonly itemEntryModel: TenantModelProxy<typeof ItemEntry>,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { chain, difference } from 'lodash';
|
import { chain, difference } from 'lodash';
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
import { ERRORS } from './constants';
|
import { ERRORS } from './constants';
|
||||||
import { ServiceError } from '@/modules/Items/ServiceError';
|
import { ServiceError } from '@/modules/Items/ServiceError';
|
||||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||||
@@ -11,6 +11,7 @@ export class ValidateWarehouseExistance {
|
|||||||
* @param {TenantModelProxy<typeof Warehouse>} warehouseModel - Warehouse model.
|
* @param {TenantModelProxy<typeof Warehouse>} warehouseModel - Warehouse model.
|
||||||
*/
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
|
@Inject(Warehouse.name)
|
||||||
private readonly warehouseModel: TenantModelProxy<typeof Warehouse>,
|
private readonly warehouseModel: TenantModelProxy<typeof Warehouse>,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
|||||||
@@ -31,9 +31,22 @@ import { SaleReceiptWarehousesValidateSubscriber } from './subscribers/Validator
|
|||||||
import { CreditNoteWarehousesValidateSubscriber } from './subscribers/Validators/Sales/CreditNoteWarehousesSubscriber';
|
import { CreditNoteWarehousesValidateSubscriber } from './subscribers/Validators/Sales/CreditNoteWarehousesSubscriber';
|
||||||
import { BillWarehousesValidateSubscriber } from './subscribers/Validators/Purchases/BillWarehousesSubscriber';
|
import { BillWarehousesValidateSubscriber } from './subscribers/Validators/Purchases/BillWarehousesSubscriber';
|
||||||
import { AccountsTransactionsWarehousesSubscribe } from './AccountsTransactionsWarehousesSubscribe';
|
import { AccountsTransactionsWarehousesSubscribe } from './AccountsTransactionsWarehousesSubscribe';
|
||||||
|
import { BillActivateWarehouses } from './Activate/BillWarehousesActivate';
|
||||||
|
import { CreditNotesActivateWarehouses } from './Activate/CreditNoteWarehousesActivate';
|
||||||
|
import { VendorCreditActivateWarehouses } from './Activate/VendorCreditWarehousesActivate';
|
||||||
|
import { InvoicesActivateWarehouses } from './Activate/InvoiceWarehousesActivate';
|
||||||
|
import { ReceiptActivateWarehouses } from './Activate/ReceiptWarehousesActivate';
|
||||||
|
import { WarehousesDTOValidators } from './Integrations/WarehousesDTOValidators';
|
||||||
|
import { DeleteItemWarehousesQuantity } from './commands/DeleteItemWarehousesQuantity';
|
||||||
|
import { InventoryTransactionsWarehouses } from './AccountsTransactionsWarehouses';
|
||||||
|
import { RegisterTenancyModel } from '../Tenancy/TenancyModels/Tenancy.module';
|
||||||
|
import { Warehouse } from './models/Warehouse.model';
|
||||||
|
import { ValidateWarehouseExistance } from './Integrations/ValidateWarehouseExistance';
|
||||||
|
|
||||||
|
const models = [RegisterTenancyModel(Warehouse)];
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [TenancyDatabaseModule],
|
imports: [TenancyDatabaseModule, ...models],
|
||||||
controllers: [WarehousesController],
|
controllers: [WarehousesController],
|
||||||
providers: [
|
providers: [
|
||||||
CreateWarehouse,
|
CreateWarehouse,
|
||||||
@@ -66,7 +79,17 @@ import { AccountsTransactionsWarehousesSubscribe } from './AccountsTransactionsW
|
|||||||
SaleInvoicesWarehousesValidateSubscriber,
|
SaleInvoicesWarehousesValidateSubscriber,
|
||||||
VendorCreditWarehousesValidateSubscriber,
|
VendorCreditWarehousesValidateSubscriber,
|
||||||
AccountsTransactionsWarehousesSubscribe,
|
AccountsTransactionsWarehousesSubscribe,
|
||||||
|
BillActivateWarehouses,
|
||||||
|
CreditNotesActivateWarehouses,
|
||||||
|
VendorCreditActivateWarehouses,
|
||||||
|
CreditNotesActivateWarehouses,
|
||||||
|
InvoicesActivateWarehouses,
|
||||||
|
ReceiptActivateWarehouses,
|
||||||
|
WarehousesDTOValidators,
|
||||||
|
DeleteItemWarehousesQuantity,
|
||||||
|
InventoryTransactionsWarehouses,
|
||||||
|
ValidateWarehouseExistance
|
||||||
],
|
],
|
||||||
exports: [WarehouseTransactionDTOTransform],
|
exports: [WarehouseTransactionDTOTransform, ...models],
|
||||||
})
|
})
|
||||||
export class WarehousesModule {}
|
export class WarehousesModule {}
|
||||||
|
|||||||
1
packages/server-nest/src/utils/transaction-increment.ts
Normal file
1
packages/server-nest/src/utils/transaction-increment.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export const transactionIncrement = (s) => s.replace(/([0-8]|\d?9+)?$/, (e) => ++e);
|
||||||
Reference in New Issue
Block a user