mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-26 09:39:49 +00:00
Compare commits
1 Commits
feat/accou
...
20260129-2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f395cce710 |
@@ -35,4 +35,4 @@ WORKDIR /app/packages/server
|
|||||||
RUN git clone https://github.com/vishnubob/wait-for-it.git
|
RUN git clone https://github.com/vishnubob/wait-for-it.git
|
||||||
|
|
||||||
# Once we listen the mysql port run the migration task.
|
# Once we listen the mysql port run the migration task.
|
||||||
CMD ./wait-for-it/wait-for-it.sh mysql:3306 -- sh -c "node dist/cli.js system:migrate:latest && node dist/cli.js tenants:migrate:latest"
|
CMD ./wait-for-it/wait-for-it.sh mysql:3306 -- sh -c "pnpm run system:migrate:latest && pnpm run tenants:migrate:latest"
|
||||||
|
|||||||
@@ -75,9 +75,6 @@ COPY --from=builder --chown=nodejs:nodejs /app/packages/server/src/i18n ./packag
|
|||||||
COPY --from=builder --chown=nodejs:nodejs /app/packages/server/public ./packages/server/public
|
COPY --from=builder --chown=nodejs:nodejs /app/packages/server/public ./packages/server/public
|
||||||
COPY --from=builder --chown=nodejs:nodejs /app/packages/server/static ./packages/server/static
|
COPY --from=builder --chown=nodejs:nodejs /app/packages/server/static ./packages/server/static
|
||||||
|
|
||||||
# Copy database migration files (needed for running migrations)
|
|
||||||
COPY --from=builder --chown=nodejs:nodejs /app/packages/server/src/database ./packages/server/src/database
|
|
||||||
|
|
||||||
# Copy built shared packages (dist folders and package.json for module resolution)
|
# Copy built shared packages (dist folders and package.json for module resolution)
|
||||||
COPY --from=builder --chown=nodejs:nodejs /app/shared/bigcapital-utils/dist ./shared/bigcapital-utils/dist
|
COPY --from=builder --chown=nodejs:nodejs /app/shared/bigcapital-utils/dist ./shared/bigcapital-utils/dist
|
||||||
COPY --from=builder --chown=nodejs:nodejs /app/shared/pdf-templates/dist ./shared/pdf-templates/dist
|
COPY --from=builder --chown=nodejs:nodejs /app/shared/pdf-templates/dist ./shared/pdf-templates/dist
|
||||||
|
|||||||
@@ -2,23 +2,10 @@
|
|||||||
"$schema": "https://json.schemastore.org/nest-cli",
|
"$schema": "https://json.schemastore.org/nest-cli",
|
||||||
"collection": "@nestjs/schematics",
|
"collection": "@nestjs/schematics",
|
||||||
"sourceRoot": "src",
|
"sourceRoot": "src",
|
||||||
"entryFile": "main",
|
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"deleteOutDir": true,
|
"deleteOutDir": true,
|
||||||
"assets": [
|
"assets": [
|
||||||
{ "include": "i18n/**/*", "watchAssets": true },
|
{ "include": "i18n/**/*", "watchAssets": true }
|
||||||
{ "include": "database/**/*", "exclude": "**/*.ts", "watchAssets": true }
|
|
||||||
]
|
]
|
||||||
},
|
|
||||||
"projects": {
|
|
||||||
"cli": {
|
|
||||||
"type": "application",
|
|
||||||
"root": "src",
|
|
||||||
"entryFile": "cli",
|
|
||||||
"sourceRoot": "src",
|
|
||||||
"compilerOptions": {
|
|
||||||
"tsConfigPath": "tsconfig.json"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,5 +6,4 @@ export default registerAs('s3', () => ({
|
|||||||
secretAccessKey: process.env.S3_SECRET_ACCESS_KEY,
|
secretAccessKey: process.env.S3_SECRET_ACCESS_KEY,
|
||||||
endpoint: process.env.S3_ENDPOINT,
|
endpoint: process.env.S3_ENDPOINT,
|
||||||
bucket: process.env.S3_BUCKET,
|
bucket: process.env.S3_BUCKET,
|
||||||
forcePathStyle: process.env.S3_FORCE_PATH_STYLE === 'true',
|
|
||||||
}));
|
}));
|
||||||
|
|||||||
@@ -9,10 +9,5 @@
|
|||||||
"net_cash_financing": "Net cash provided by financing activities",
|
"net_cash_financing": "Net cash provided by financing activities",
|
||||||
"cash_beginning_period": "Cash at beginning of period",
|
"cash_beginning_period": "Cash at beginning of period",
|
||||||
"net_cash_increase": "NET CASH INCREASE FOR PERIOD",
|
"net_cash_increase": "NET CASH INCREASE FOR PERIOD",
|
||||||
"cash_end_period": "CASH AT END OF PERIOD",
|
"cash_end_period": "CASH AT END OF PERIOD"
|
||||||
"account_name": "Account name",
|
|
||||||
"total": "Total",
|
|
||||||
"sheet_name": "Statement of Cash Flow",
|
|
||||||
"from_date": "From",
|
|
||||||
"to_date": "To"
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
{
|
|
||||||
"account_name": "Account name",
|
|
||||||
"total": "Total",
|
|
||||||
"percentage_column": "% of Column"
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
{
|
|
||||||
"opening_balance": "Opening balance",
|
|
||||||
"closing_balance": "Closing balance",
|
|
||||||
"date": "Date",
|
|
||||||
"transaction_type": "Transaction type",
|
|
||||||
"transaction_number": "Transaction #",
|
|
||||||
"quantity": "Quantity",
|
|
||||||
"rate": "Rate",
|
|
||||||
"total": "Total",
|
|
||||||
"value": "Value",
|
|
||||||
"profit_margin": "Profit Margin",
|
|
||||||
"running_quantity": "Running quantity",
|
|
||||||
"running_value": "Running Value"
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"opening_balance": "Opening balance",
|
|
||||||
"closing_balance": "Closing balance"
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"account": "Account",
|
|
||||||
"debit": "Debit",
|
|
||||||
"credit": "Credit",
|
|
||||||
"total": "Total"
|
|
||||||
}
|
|
||||||
@@ -9,7 +9,6 @@ import {
|
|||||||
ParseIntPipe,
|
ParseIntPipe,
|
||||||
Put,
|
Put,
|
||||||
HttpCode,
|
HttpCode,
|
||||||
UseGuards,
|
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { AccountsApplication } from './AccountsApplication.service';
|
import { AccountsApplication } from './AccountsApplication.service';
|
||||||
import { CreateAccountDTO } from './CreateAccount.dto';
|
import { CreateAccountDTO } from './CreateAccount.dto';
|
||||||
@@ -33,11 +32,6 @@ import {
|
|||||||
BulkDeleteDto,
|
BulkDeleteDto,
|
||||||
ValidateBulkDeleteResponseDto,
|
ValidateBulkDeleteResponseDto,
|
||||||
} from '@/common/dtos/BulkDelete.dto';
|
} from '@/common/dtos/BulkDelete.dto';
|
||||||
import { RequirePermission } from '@/modules/Roles/RequirePermission.decorator';
|
|
||||||
import { PermissionGuard } from '@/modules/Roles/Permission.guard';
|
|
||||||
import { AuthorizationGuard } from '@/modules/Roles/Authorization.guard';
|
|
||||||
import { AbilitySubject } from '@/modules/Roles/Roles.types';
|
|
||||||
import { AccountAction } from './Accounts.types';
|
|
||||||
|
|
||||||
@Controller('accounts')
|
@Controller('accounts')
|
||||||
@ApiTags('Accounts')
|
@ApiTags('Accounts')
|
||||||
@@ -46,13 +40,11 @@ import { AccountAction } from './Accounts.types';
|
|||||||
@ApiExtraModels(GetAccountTransactionResponseDto)
|
@ApiExtraModels(GetAccountTransactionResponseDto)
|
||||||
@ApiExtraModels(ValidateBulkDeleteResponseDto)
|
@ApiExtraModels(ValidateBulkDeleteResponseDto)
|
||||||
@ApiCommonHeaders()
|
@ApiCommonHeaders()
|
||||||
@UseGuards(AuthorizationGuard, PermissionGuard)
|
|
||||||
export class AccountsController {
|
export class AccountsController {
|
||||||
constructor(private readonly accountsApplication: AccountsApplication) { }
|
constructor(private readonly accountsApplication: AccountsApplication) { }
|
||||||
|
|
||||||
@Post('validate-bulk-delete')
|
@Post('validate-bulk-delete')
|
||||||
@HttpCode(200)
|
@HttpCode(200)
|
||||||
@RequirePermission(AccountAction.DELETE, AbilitySubject.Account)
|
|
||||||
@ApiOperation({
|
@ApiOperation({
|
||||||
summary:
|
summary:
|
||||||
'Validates which accounts can be deleted and returns counts of deletable and non-deletable accounts.',
|
'Validates which accounts can be deleted and returns counts of deletable and non-deletable accounts.',
|
||||||
@@ -75,7 +67,6 @@ export class AccountsController {
|
|||||||
|
|
||||||
@Post('bulk-delete')
|
@Post('bulk-delete')
|
||||||
@HttpCode(200)
|
@HttpCode(200)
|
||||||
@RequirePermission(AccountAction.DELETE, AbilitySubject.Account)
|
|
||||||
@ApiOperation({ summary: 'Deletes multiple accounts in bulk.' })
|
@ApiOperation({ summary: 'Deletes multiple accounts in bulk.' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
@@ -90,7 +81,6 @@ export class AccountsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@RequirePermission(AccountAction.CREATE, AbilitySubject.Account)
|
|
||||||
@ApiOperation({ summary: 'Create an account' })
|
@ApiOperation({ summary: 'Create an account' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
@@ -101,7 +91,6 @@ export class AccountsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Put(':id')
|
@Put(':id')
|
||||||
@RequirePermission(AccountAction.EDIT, AbilitySubject.Account)
|
|
||||||
@ApiOperation({ summary: 'Edit the given account.' })
|
@ApiOperation({ summary: 'Edit the given account.' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
@@ -122,7 +111,6 @@ export class AccountsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Delete(':id')
|
@Delete(':id')
|
||||||
@RequirePermission(AccountAction.DELETE, AbilitySubject.Account)
|
|
||||||
@ApiOperation({ summary: 'Delete the given account.' })
|
@ApiOperation({ summary: 'Delete the given account.' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
@@ -141,7 +129,6 @@ export class AccountsController {
|
|||||||
|
|
||||||
@Post(':id/activate')
|
@Post(':id/activate')
|
||||||
@HttpCode(200)
|
@HttpCode(200)
|
||||||
@RequirePermission(AccountAction.EDIT, AbilitySubject.Account)
|
|
||||||
@ApiOperation({ summary: 'Activate the given account.' })
|
@ApiOperation({ summary: 'Activate the given account.' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
@@ -160,7 +147,6 @@ export class AccountsController {
|
|||||||
|
|
||||||
@Post(':id/inactivate')
|
@Post(':id/inactivate')
|
||||||
@HttpCode(200)
|
@HttpCode(200)
|
||||||
@RequirePermission(AccountAction.EDIT, AbilitySubject.Account)
|
|
||||||
@ApiOperation({ summary: 'Inactivate the given account.' })
|
@ApiOperation({ summary: 'Inactivate the given account.' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
@@ -178,7 +164,6 @@ export class AccountsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get('types')
|
@Get('types')
|
||||||
@RequirePermission(AccountAction.VIEW, AbilitySubject.Account)
|
|
||||||
@ApiOperation({ summary: 'Retrieves the account types.' })
|
@ApiOperation({ summary: 'Retrieves the account types.' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
@@ -195,7 +180,6 @@ export class AccountsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get('transactions')
|
@Get('transactions')
|
||||||
@RequirePermission(AccountAction.VIEW, AbilitySubject.Account)
|
|
||||||
@ApiOperation({ summary: 'Retrieves the account transactions.' })
|
@ApiOperation({ summary: 'Retrieves the account transactions.' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
@@ -214,7 +198,6 @@ export class AccountsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
@RequirePermission(AccountAction.VIEW, AbilitySubject.Account)
|
|
||||||
@ApiOperation({ summary: 'Retrieves the account details.' })
|
@ApiOperation({ summary: 'Retrieves the account details.' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
@@ -233,7 +216,6 @@ export class AccountsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
@RequirePermission(AccountAction.VIEW, AbilitySubject.Account)
|
|
||||||
@ApiOperation({ summary: 'Retrieves the accounts.' })
|
@ApiOperation({ summary: 'Retrieves the accounts.' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import { AccountsExportable } from './AccountsExportable.service';
|
|||||||
import { AccountsImportable } from './AccountsImportable.service';
|
import { AccountsImportable } from './AccountsImportable.service';
|
||||||
import { BulkDeleteAccountsService } from './BulkDeleteAccounts.service';
|
import { BulkDeleteAccountsService } from './BulkDeleteAccounts.service';
|
||||||
import { ValidateBulkDeleteAccountsService } from './ValidateBulkDeleteAccounts.service';
|
import { ValidateBulkDeleteAccountsService } from './ValidateBulkDeleteAccounts.service';
|
||||||
import { AccountsSettingsService } from './AccountsSettings.service';
|
|
||||||
|
|
||||||
const models = [RegisterTenancyModel(BankAccount)];
|
const models = [RegisterTenancyModel(BankAccount)];
|
||||||
|
|
||||||
@@ -30,7 +29,6 @@ const models = [RegisterTenancyModel(BankAccount)];
|
|||||||
controllers: [AccountsController],
|
controllers: [AccountsController],
|
||||||
providers: [
|
providers: [
|
||||||
AccountsApplication,
|
AccountsApplication,
|
||||||
AccountsSettingsService,
|
|
||||||
CreateAccountService,
|
CreateAccountService,
|
||||||
TenancyContext,
|
TenancyContext,
|
||||||
CommandAccountValidators,
|
CommandAccountValidators,
|
||||||
@@ -51,10 +49,9 @@ const models = [RegisterTenancyModel(BankAccount)];
|
|||||||
exports: [
|
exports: [
|
||||||
AccountRepository,
|
AccountRepository,
|
||||||
CreateAccountService,
|
CreateAccountService,
|
||||||
AccountsSettingsService,
|
|
||||||
...models,
|
...models,
|
||||||
AccountsExportable,
|
AccountsExportable,
|
||||||
AccountsImportable,
|
AccountsImportable
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class AccountsModule {}
|
export class AccountsModule {}
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
import { Inject, Injectable } from '@nestjs/common';
|
|
||||||
import { SettingsStore } from '../Settings/SettingsStore';
|
|
||||||
import { SETTINGS_PROVIDER } from '../Settings/Settings.types';
|
|
||||||
|
|
||||||
export interface IAccountsSettings {
|
|
||||||
accountCodeRequired: boolean;
|
|
||||||
accountCodeUnique: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class AccountsSettingsService {
|
|
||||||
constructor(
|
|
||||||
@Inject(SETTINGS_PROVIDER)
|
|
||||||
private readonly settingsStore: () => SettingsStore,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves account settings (account code required, account code unique).
|
|
||||||
*/
|
|
||||||
public async getAccountsSettings(): Promise<IAccountsSettings> {
|
|
||||||
const settingsStore = await this.settingsStore();
|
|
||||||
return {
|
|
||||||
accountCodeRequired: settingsStore.get(
|
|
||||||
{ group: 'accounts', key: 'account_code_required' },
|
|
||||||
false,
|
|
||||||
),
|
|
||||||
accountCodeUnique: settingsStore.get(
|
|
||||||
{ group: 'accounts', key: 'account_code_unique' },
|
|
||||||
true,
|
|
||||||
),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -106,20 +106,6 @@ export class CommandAccountValidators {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Throws error if account code is missing or blank when required.
|
|
||||||
* @param {string|undefined} code - Account code.
|
|
||||||
*/
|
|
||||||
public validateAccountCodeRequiredOrThrow(code: string | undefined) {
|
|
||||||
const trimmed = typeof code === 'string' ? code.trim() : '';
|
|
||||||
if (!trimmed) {
|
|
||||||
throw new ServiceError(
|
|
||||||
ERRORS.ACCOUNT_CODE_REQUIRED,
|
|
||||||
'Account code is required.',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates the account name uniquiness.
|
* Validates the account name uniquiness.
|
||||||
* @param {string} accountName - Account name.
|
* @param {string} accountName - Account name.
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import { events } from '@/common/events/events';
|
|||||||
import { CreateAccountDTO } from './CreateAccount.dto';
|
import { CreateAccountDTO } from './CreateAccount.dto';
|
||||||
import { PartialModelObject } from 'objection';
|
import { PartialModelObject } from 'objection';
|
||||||
import { TenantModelProxy } from '../System/models/TenantBaseModel';
|
import { TenantModelProxy } from '../System/models/TenantBaseModel';
|
||||||
import { AccountsSettingsService } from './AccountsSettings.service';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CreateAccountService {
|
export class CreateAccountService {
|
||||||
@@ -33,7 +32,6 @@ export class CreateAccountService {
|
|||||||
private readonly uow: UnitOfWork,
|
private readonly uow: UnitOfWork,
|
||||||
private readonly validator: CommandAccountValidators,
|
private readonly validator: CommandAccountValidators,
|
||||||
private readonly tenancyContext: TenancyContext,
|
private readonly tenancyContext: TenancyContext,
|
||||||
private readonly accountsSettings: AccountsSettingsService,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,21 +43,14 @@ export class CreateAccountService {
|
|||||||
baseCurrency: string,
|
baseCurrency: string,
|
||||||
params?: CreateAccountParams,
|
params?: CreateAccountParams,
|
||||||
) => {
|
) => {
|
||||||
const { accountCodeRequired, accountCodeUnique } =
|
|
||||||
await this.accountsSettings.getAccountsSettings();
|
|
||||||
|
|
||||||
// Validate account code required when setting is enabled.
|
|
||||||
if (accountCodeRequired) {
|
|
||||||
this.validator.validateAccountCodeRequiredOrThrow(accountDTO.code);
|
|
||||||
}
|
|
||||||
// Validate the account code uniquiness when setting is enabled.
|
|
||||||
if (accountCodeUnique && accountDTO.code?.trim()) {
|
|
||||||
await this.validator.isAccountCodeUniqueOrThrowError(accountDTO.code);
|
|
||||||
}
|
|
||||||
// Validate account name uniquiness.
|
// Validate account name uniquiness.
|
||||||
if (!params.ignoreUniqueName) {
|
if (!params.ignoreUniqueName) {
|
||||||
await this.validator.validateAccountNameUniquiness(accountDTO.name);
|
await this.validator.validateAccountNameUniquiness(accountDTO.name);
|
||||||
}
|
}
|
||||||
|
// Validate the account code uniquiness.
|
||||||
|
if (accountDTO.code) {
|
||||||
|
await this.validator.isAccountCodeUniqueOrThrowError(accountDTO.code);
|
||||||
|
}
|
||||||
// Retrieve the account type meta or throw service error if not found.
|
// Retrieve the account type meta or throw service error if not found.
|
||||||
this.validator.getAccountTypeOrThrowError(accountDTO.accountType);
|
this.validator.getAccountTypeOrThrowError(accountDTO.accountType);
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import { UnitOfWork } from '../Tenancy/TenancyDB/UnitOfWork.service';
|
|||||||
import { events } from '@/common/events/events';
|
import { events } from '@/common/events/events';
|
||||||
import { EditAccountDTO } from './EditAccount.dto';
|
import { EditAccountDTO } from './EditAccount.dto';
|
||||||
import { TenantModelProxy } from '../System/models/TenantBaseModel';
|
import { TenantModelProxy } from '../System/models/TenantBaseModel';
|
||||||
import { AccountsSettingsService } from './AccountsSettings.service';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class EditAccount {
|
export class EditAccount {
|
||||||
@@ -18,8 +17,7 @@ export class EditAccount {
|
|||||||
|
|
||||||
@Inject(Account.name)
|
@Inject(Account.name)
|
||||||
private readonly accountModel: TenantModelProxy<typeof Account>,
|
private readonly accountModel: TenantModelProxy<typeof Account>,
|
||||||
private readonly accountsSettings: AccountsSettingsService,
|
) { }
|
||||||
) {}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Authorize the account editing.
|
* Authorize the account editing.
|
||||||
@@ -32,24 +30,6 @@ export class EditAccount {
|
|||||||
accountDTO: EditAccountDTO,
|
accountDTO: EditAccountDTO,
|
||||||
oldAccount: Account,
|
oldAccount: Account,
|
||||||
) => {
|
) => {
|
||||||
const { accountCodeRequired, accountCodeUnique } =
|
|
||||||
await this.accountsSettings.getAccountsSettings();
|
|
||||||
|
|
||||||
// Validate account code required when setting is enabled.
|
|
||||||
if (accountCodeRequired) {
|
|
||||||
this.validator.validateAccountCodeRequiredOrThrow(accountDTO.code);
|
|
||||||
}
|
|
||||||
// Validate the account code uniquiness when setting is enabled.
|
|
||||||
if (
|
|
||||||
accountCodeUnique &&
|
|
||||||
accountDTO.code?.trim() &&
|
|
||||||
accountDTO.code !== oldAccount.code
|
|
||||||
) {
|
|
||||||
await this.validator.isAccountCodeUniqueOrThrowError(
|
|
||||||
accountDTO.code,
|
|
||||||
oldAccount.id,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
// Validate account name uniquiness.
|
// Validate account name uniquiness.
|
||||||
await this.validator.validateAccountNameUniquiness(
|
await this.validator.validateAccountNameUniquiness(
|
||||||
accountDTO.name,
|
accountDTO.name,
|
||||||
@@ -60,6 +40,13 @@ export class EditAccount {
|
|||||||
oldAccount,
|
oldAccount,
|
||||||
accountDTO,
|
accountDTO,
|
||||||
);
|
);
|
||||||
|
// Validate the account code not exists on the storage.
|
||||||
|
if (accountDTO.code && accountDTO.code !== oldAccount.code) {
|
||||||
|
await this.validator.isAccountCodeUniqueOrThrowError(
|
||||||
|
accountDTO.code,
|
||||||
|
oldAccount.id,
|
||||||
|
);
|
||||||
|
}
|
||||||
// Retrieve the parent account of throw not found service error.
|
// Retrieve the parent account of throw not found service error.
|
||||||
if (accountDTO.parentAccountId) {
|
if (accountDTO.parentAccountId) {
|
||||||
const parentAccount = await this.validator.getParentAccountOrThrowError(
|
const parentAccount = await this.validator.getParentAccountOrThrowError(
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ export const ERRORS = {
|
|||||||
ACCOUNT_TYPE_NOT_FOUND: 'account_type_not_found',
|
ACCOUNT_TYPE_NOT_FOUND: 'account_type_not_found',
|
||||||
PARENT_ACCOUNT_NOT_FOUND: 'parent_account_not_found',
|
PARENT_ACCOUNT_NOT_FOUND: 'parent_account_not_found',
|
||||||
ACCOUNT_CODE_NOT_UNIQUE: 'account_code_not_unique',
|
ACCOUNT_CODE_NOT_UNIQUE: 'account_code_not_unique',
|
||||||
ACCOUNT_CODE_REQUIRED: 'account_code_required',
|
|
||||||
ACCOUNT_NAME_NOT_UNIQUE: 'account_name_not_unqiue',
|
ACCOUNT_NAME_NOT_UNIQUE: 'account_name_not_unqiue',
|
||||||
PARENT_ACCOUNT_HAS_DIFFERENT_TYPE: 'parent_has_different_type',
|
PARENT_ACCOUNT_HAS_DIFFERENT_TYPE: 'parent_has_different_type',
|
||||||
ACCOUNT_TYPE_NOT_ALLOWED_TO_CHANGE: 'account_type_not_allowed_to_changed',
|
ACCOUNT_TYPE_NOT_ALLOWED_TO_CHANGE: 'account_type_not_allowed_to_changed',
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { ModuleRef } from '@nestjs/core';
|
import { ModuleRef } from '@nestjs/core';
|
||||||
import * as bluebird from 'bluebird';
|
import bluebird from 'bluebird';
|
||||||
import { Knex } from 'knex';
|
import { Knex } from 'knex';
|
||||||
import {
|
import {
|
||||||
validateLinkModelEntryExists,
|
validateLinkModelEntryExists,
|
||||||
@@ -53,8 +53,7 @@ export class LinkAttachment {
|
|||||||
const foundLinkModel = await LinkModel().query(trx).findById(modelId);
|
const foundLinkModel = await LinkModel().query(trx).findById(modelId);
|
||||||
validateLinkModelEntryExists(foundLinkModel);
|
validateLinkModelEntryExists(foundLinkModel);
|
||||||
|
|
||||||
const foundLinks = await this.documentLinkModel()
|
const foundLinks = await this.documentLinkModel().query(trx)
|
||||||
.query(trx)
|
|
||||||
.where('modelRef', modelRef)
|
.where('modelRef', modelRef)
|
||||||
.where('modelId', modelId)
|
.where('modelId', modelId)
|
||||||
.where('documentId', foundFile.id);
|
.where('documentId', foundFile.id);
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ export class AuthController {
|
|||||||
return this.authApp.signUp(signupDto);
|
return this.authApp.signUp(signupDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('/signup/verify')
|
@Post('/signup/confirm')
|
||||||
@ApiOperation({ summary: 'Confirm user signup' })
|
@ApiOperation({ summary: 'Confirm user signup' })
|
||||||
@ApiBody({
|
@ApiBody({
|
||||||
schema: {
|
schema: {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ export class AuthenticationMailMesssages {
|
|||||||
* @returns {Mail}
|
* @returns {Mail}
|
||||||
*/
|
*/
|
||||||
resetPasswordMessage(user: ModelObject<SystemUser>, token: string) {
|
resetPasswordMessage(user: ModelObject<SystemUser>, token: string) {
|
||||||
const baseURL = this.configService.get('app.baseUrl');
|
const baseURL = this.configService.get('baseURL');
|
||||||
|
|
||||||
return new Mail()
|
return new Mail()
|
||||||
.setSubject('Bigcapital - Password Reset')
|
.setSubject('Bigcapital - Password Reset')
|
||||||
@@ -54,7 +54,7 @@ export class AuthenticationMailMesssages {
|
|||||||
* @returns {Mail}
|
* @returns {Mail}
|
||||||
*/
|
*/
|
||||||
signupVerificationMail(email: string, fullName: string, token: string) {
|
signupVerificationMail(email: string, fullName: string, token: string) {
|
||||||
const baseURL = this.configService.get('app.baseUrl');
|
const baseURL = this.configService.get('baseURL');
|
||||||
const verifyUrl = `${baseURL}/auth/email_confirmation?token=${token}&email=${email}`;
|
const verifyUrl = `${baseURL}/auth/email_confirmation?token=${token}&email=${email}`;
|
||||||
|
|
||||||
return new Mail()
|
return new Mail()
|
||||||
|
|||||||
@@ -7,13 +7,17 @@ import {
|
|||||||
import { GetAuthenticatedAccount } from './queries/GetAuthedAccount.service';
|
import { GetAuthenticatedAccount } from './queries/GetAuthedAccount.service';
|
||||||
import { Controller, Get, Post } from '@nestjs/common';
|
import { Controller, Get, Post } from '@nestjs/common';
|
||||||
import { Throttle } from '@nestjs/throttler';
|
import { Throttle } from '@nestjs/throttler';
|
||||||
import { TenantAgnosticRoute } from '../Tenancy/TenancyGlobal.guard';
|
import { IgnoreTenantSeededRoute } from '../Tenancy/EnsureTenantIsSeeded.guards';
|
||||||
|
import { IgnoreTenantInitializedRoute } from '../Tenancy/EnsureTenantIsInitialized.guard';
|
||||||
import { AuthenticationApplication } from './AuthApplication.sevice';
|
import { AuthenticationApplication } from './AuthApplication.sevice';
|
||||||
|
import { TenancyContext } from '../Tenancy/TenancyContext.service';
|
||||||
import { IgnoreUserVerifiedRoute } from './guards/EnsureUserVerified.guard';
|
import { IgnoreUserVerifiedRoute } from './guards/EnsureUserVerified.guard';
|
||||||
|
|
||||||
@Controller('/auth')
|
@Controller('/auth')
|
||||||
@ApiTags('Auth')
|
@ApiTags('Auth')
|
||||||
@TenantAgnosticRoute()
|
@ApiExcludeController()
|
||||||
|
@IgnoreTenantSeededRoute()
|
||||||
|
@IgnoreTenantInitializedRoute()
|
||||||
@IgnoreUserVerifiedRoute()
|
@IgnoreUserVerifiedRoute()
|
||||||
@Throttle({ auth: {} })
|
@Throttle({ auth: {} })
|
||||||
export class AuthedController {
|
export class AuthedController {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
IAuthSignedUpEventPayload,
|
IAuthSignedUpEventPayload,
|
||||||
IAuthSigningUpEventPayload,
|
IAuthSigningUpEventPayload,
|
||||||
} from '../Auth.interfaces';
|
} from '../Auth.interfaces';
|
||||||
|
import { defaultTo } from 'ramda';
|
||||||
import { ERRORS } from '../Auth.constants';
|
import { ERRORS } from '../Auth.constants';
|
||||||
import { hashPassword } from '../Auth.utils';
|
import { hashPassword } from '../Auth.utils';
|
||||||
import { ClsService } from 'nestjs-cls';
|
import { ClsService } from 'nestjs-cls';
|
||||||
@@ -50,7 +51,7 @@ export class AuthSignupService {
|
|||||||
const signupConfirmation = this.configService.get('signupConfirmation');
|
const signupConfirmation = this.configService.get('signupConfirmation');
|
||||||
|
|
||||||
const verifyTokenCrypto = crypto.randomBytes(64).toString('hex');
|
const verifyTokenCrypto = crypto.randomBytes(64).toString('hex');
|
||||||
const verifiedEnabed = signupConfirmation.enabled ?? false;
|
const verifiedEnabed = defaultTo(signupConfirmation.enabled, false);
|
||||||
const verifyToken = verifiedEnabed ? verifyTokenCrypto : '';
|
const verifyToken = verifiedEnabed ? verifyTokenCrypto : '';
|
||||||
const verified = !verifiedEnabed;
|
const verified = !verifiedEnabed;
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { SystemUser } from '@/modules/System/models/SystemUser';
|
|||||||
import { ServiceError } from '@/modules/Items/ServiceError';
|
import { ServiceError } from '@/modules/Items/ServiceError';
|
||||||
import { ERRORS } from '../Auth.constants';
|
import { ERRORS } from '../Auth.constants';
|
||||||
import { events } from '@/common/events/events';
|
import { events } from '@/common/events/events';
|
||||||
|
import { ModelObject } from 'objection';
|
||||||
import { ISignUpConfigmResendedEventPayload } from '../Auth.interfaces';
|
import { ISignUpConfigmResendedEventPayload } from '../Auth.interfaces';
|
||||||
import { TenancyContext } from '@/modules/Tenancy/TenancyContext.service';
|
import { TenancyContext } from '@/modules/Tenancy/TenancyContext.service';
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
import { Processor, WorkerHost } from '@nestjs/bullmq';
|
import { Processor, WorkerHost } from '@nestjs/bullmq';
|
||||||
import { Scope } from '@nestjs/common';
|
import { Scope } from '@nestjs/common';
|
||||||
import { SendResetPasswordMailQueue } from '../Auth.constants';
|
import {
|
||||||
|
SendResetPasswordMailJob,
|
||||||
|
SendResetPasswordMailQueue,
|
||||||
|
} from '../Auth.constants';
|
||||||
|
import { Process } from '@nestjs/bull';
|
||||||
import { Job } from 'bullmq';
|
import { Job } from 'bullmq';
|
||||||
import { AuthenticationMailMesssages } from '../AuthMailMessages.esrvice';
|
import { AuthenticationMailMesssages } from '../AuthMailMessages.esrvice';
|
||||||
import { MailTransporter } from '@/modules/Mail/MailTransporter.service';
|
import { MailTransporter } from '@/modules/Mail/MailTransporter.service';
|
||||||
@@ -19,6 +23,7 @@ export class SendResetPasswordMailProcessor extends WorkerHost {
|
|||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Process(SendResetPasswordMailJob)
|
||||||
async process(job: Job<SendResetPasswordMailJobPayload>) {
|
async process(job: Job<SendResetPasswordMailJobPayload>) {
|
||||||
try {
|
try {
|
||||||
await this.authMailMesssages.sendResetPasswordMail(
|
await this.authMailMesssages.sendResetPasswordMail(
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
import { Scope } from '@nestjs/common';
|
import { Scope } from '@nestjs/common';
|
||||||
import { Job } from 'bullmq';
|
import { Job } from 'bullmq';
|
||||||
|
import { Process } from '@nestjs/bull';
|
||||||
import { Processor, WorkerHost } from '@nestjs/bullmq';
|
import { Processor, WorkerHost } from '@nestjs/bullmq';
|
||||||
import { SendSignupVerificationMailQueue } from '../Auth.constants';
|
import {
|
||||||
|
SendSignupVerificationMailJob,
|
||||||
|
SendSignupVerificationMailQueue,
|
||||||
|
} from '../Auth.constants';
|
||||||
import { MailTransporter } from '@/modules/Mail/MailTransporter.service';
|
import { MailTransporter } from '@/modules/Mail/MailTransporter.service';
|
||||||
import { AuthenticationMailMesssages } from '../AuthMailMessages.esrvice';
|
import { AuthenticationMailMesssages } from '../AuthMailMessages.esrvice';
|
||||||
|
|
||||||
@@ -17,6 +21,7 @@ export class SendSignupVerificationMailProcessor extends WorkerHost {
|
|||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Process(SendSignupVerificationMailJob)
|
||||||
async process(job: Job<SendSignupVerificationMailJobPayload>) {
|
async process(job: Job<SendSignupVerificationMailJobPayload>) {
|
||||||
try {
|
try {
|
||||||
await this.authMailMesssages.sendSignupVerificationMail(
|
await this.authMailMesssages.sendSignupVerificationMail(
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import { ToNumber } from '@/common/decorators/Validators';
|
|||||||
|
|
||||||
class BankRuleConditionDto {
|
class BankRuleConditionDto {
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
@IsIn(['description', 'amount', 'payee'])
|
@IsIn(['description', 'amount'])
|
||||||
field: string;
|
field: string;
|
||||||
|
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
|
import { Process } from '@nestjs/bull';
|
||||||
import { UseCls } from 'nestjs-cls';
|
import { UseCls } from 'nestjs-cls';
|
||||||
import { Processor, WorkerHost } from '@nestjs/bullmq';
|
import { Processor, WorkerHost } from '@nestjs/bullmq';
|
||||||
import { Scope } from '@nestjs/common';
|
import { Scope } from '@nestjs/common';
|
||||||
import { Job } from 'bullmq';
|
import { Job } from 'bullmq';
|
||||||
import {
|
import {
|
||||||
PlaidFetchTransitonsEventPayload,
|
PlaidFetchTransitonsEventPayload,
|
||||||
|
UpdateBankingPlaidTransitionsJob,
|
||||||
UpdateBankingPlaidTransitionsQueueJob,
|
UpdateBankingPlaidTransitionsQueueJob,
|
||||||
} from '../types/BankingPlaid.types';
|
} from '../types/BankingPlaid.types';
|
||||||
import { PlaidUpdateTransactions } from '../command/PlaidUpdateTransactions';
|
import { PlaidUpdateTransactions } from '../command/PlaidUpdateTransactions';
|
||||||
@@ -26,6 +28,7 @@ export class PlaidFetchTransactionsProcessor extends WorkerHost {
|
|||||||
/**
|
/**
|
||||||
* Triggers the function.
|
* Triggers the function.
|
||||||
*/
|
*/
|
||||||
|
@Process(UpdateBankingPlaidTransitionsJob)
|
||||||
@UseCls()
|
@UseCls()
|
||||||
async process(job: Job<PlaidFetchTransitonsEventPayload>) {
|
async process(job: Job<PlaidFetchTransitonsEventPayload>) {
|
||||||
const { plaidItemId } = job.data;
|
const { plaidItemId } = job.data;
|
||||||
|
|||||||
@@ -15,13 +15,8 @@ export const RecognizeUncategorizedTransactionsJob =
|
|||||||
export const RecognizeUncategorizedTransactionsQueue =
|
export const RecognizeUncategorizedTransactionsQueue =
|
||||||
'recognize-uncategorized-transactions-queue';
|
'recognize-uncategorized-transactions-queue';
|
||||||
|
|
||||||
|
|
||||||
export interface RecognizeUncategorizedTransactionsJobPayload extends TenantJobPayload {
|
export interface RecognizeUncategorizedTransactionsJobPayload extends TenantJobPayload {
|
||||||
ruleId: number,
|
ruleId: number,
|
||||||
transactionsCriteria?: RecognizeTransactionsCriteria;
|
transactionsCriteria: any;
|
||||||
/**
|
|
||||||
* When true, first reverts recognized transactions before recognizing again.
|
|
||||||
* Used when a bank rule is edited to ensure transactions previously recognized
|
|
||||||
* by lower-priority rules are re-evaluated against the updated rule.
|
|
||||||
*/
|
|
||||||
shouldRevert?: boolean;
|
|
||||||
}
|
}
|
||||||
@@ -93,10 +93,6 @@ export class RecognizeTranasctionsService {
|
|||||||
q.whereIn('id', rulesIds);
|
q.whereIn('id', rulesIds);
|
||||||
}
|
}
|
||||||
q.withGraphFetched('conditions');
|
q.withGraphFetched('conditions');
|
||||||
|
|
||||||
// Order by the 'order' field to ensure higher priority rules (lower order values)
|
|
||||||
// are matched first.
|
|
||||||
q.orderBy('order', 'asc');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const bankRulesByAccountId = transformToMapBy(
|
const bankRulesByAccountId = transformToMapBy(
|
||||||
|
|||||||
@@ -69,13 +69,10 @@ export class TriggerRecognizedTransactionsSubscriber {
|
|||||||
const tenantPayload = await this.tenancyContect.getTenantJobPayload();
|
const tenantPayload = await this.tenancyContect.getTenantJobPayload();
|
||||||
const payload = {
|
const payload = {
|
||||||
ruleId: bankRule.id,
|
ruleId: bankRule.id,
|
||||||
shouldRevert: true,
|
|
||||||
...tenantPayload,
|
...tenantPayload,
|
||||||
} as RecognizeUncategorizedTransactionsJobPayload;
|
} as RecognizeUncategorizedTransactionsJobPayload;
|
||||||
|
|
||||||
// Re-recognize the transactions based on the new rules.
|
// Re-recognize the transactions based on the new rules.
|
||||||
// Setting shouldRevert to true ensures that transactions previously recognized
|
|
||||||
// by this or lower-priority rules are re-evaluated against the updated rule.
|
|
||||||
await this.recognizeTransactionsQueue.add(
|
await this.recognizeTransactionsQueue.add(
|
||||||
RecognizeUncategorizedTransactionsJob,
|
RecognizeUncategorizedTransactionsJob,
|
||||||
payload,
|
payload,
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ import { Processor, WorkerHost } from '@nestjs/bullmq';
|
|||||||
import { Scope } from '@nestjs/common';
|
import { Scope } from '@nestjs/common';
|
||||||
import { ClsService, UseCls } from 'nestjs-cls';
|
import { ClsService, UseCls } from 'nestjs-cls';
|
||||||
import { RecognizeTranasctionsService } from '../commands/RecognizeTranasctions.service';
|
import { RecognizeTranasctionsService } from '../commands/RecognizeTranasctions.service';
|
||||||
import { RevertRecognizedTransactionsService } from '../commands/RevertRecognizedTransactions.service';
|
|
||||||
import {
|
import {
|
||||||
RecognizeUncategorizedTransactionsJobPayload,
|
RecognizeUncategorizedTransactionsJobPayload,
|
||||||
RecognizeUncategorizedTransactionsQueue,
|
RecognizeUncategorizedTransactionsQueue,
|
||||||
} from '../_types';
|
} from '../_types';
|
||||||
|
import { Process } from '@nestjs/bull';
|
||||||
|
|
||||||
@Processor({
|
@Processor({
|
||||||
name: RecognizeUncategorizedTransactionsQueue,
|
name: RecognizeUncategorizedTransactionsQueue,
|
||||||
@@ -16,12 +16,10 @@ import {
|
|||||||
export class RegonizeTransactionsPrcessor extends WorkerHost {
|
export class RegonizeTransactionsPrcessor extends WorkerHost {
|
||||||
/**
|
/**
|
||||||
* @param {RecognizeTranasctionsService} recognizeTranasctionsService -
|
* @param {RecognizeTranasctionsService} recognizeTranasctionsService -
|
||||||
* @param {RevertRecognizedTransactionsService} revertRecognizedTransactionsService -
|
|
||||||
* @param {ClsService} clsService -
|
* @param {ClsService} clsService -
|
||||||
*/
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
private readonly recognizeTranasctionsService: RecognizeTranasctionsService,
|
private readonly recognizeTranasctionsService: RecognizeTranasctionsService,
|
||||||
private readonly revertRecognizedTransactionsService: RevertRecognizedTransactionsService,
|
|
||||||
private readonly clsService: ClsService,
|
private readonly clsService: ClsService,
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
@@ -30,23 +28,15 @@ export class RegonizeTransactionsPrcessor extends WorkerHost {
|
|||||||
/**
|
/**
|
||||||
* Triggers sending invoice mail.
|
* Triggers sending invoice mail.
|
||||||
*/
|
*/
|
||||||
|
@Process(RecognizeUncategorizedTransactionsQueue)
|
||||||
@UseCls()
|
@UseCls()
|
||||||
async process(job: Job<RecognizeUncategorizedTransactionsJobPayload>) {
|
async process(job: Job<RecognizeUncategorizedTransactionsJobPayload>) {
|
||||||
const { ruleId, transactionsCriteria, shouldRevert } = job.data;
|
const { ruleId, transactionsCriteria } = job.data;
|
||||||
|
|
||||||
this.clsService.set('organizationId', job.data.organizationId);
|
this.clsService.set('organizationId', job.data.organizationId);
|
||||||
this.clsService.set('userId', job.data.userId);
|
this.clsService.set('userId', job.data.userId);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// If shouldRevert is true, first revert recognized transactions before re-recognizing.
|
|
||||||
// This is used when a bank rule is edited to ensure transactions previously recognized
|
|
||||||
// by lower-priority rules are re-evaluated against the updated rule.
|
|
||||||
if (shouldRevert) {
|
|
||||||
await this.revertRecognizedTransactionsService.revertRecognizedTransactions(
|
|
||||||
ruleId,
|
|
||||||
transactionsCriteria,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
await this.recognizeTranasctionsService.recognizeTransactions(
|
await this.recognizeTranasctionsService.recognizeTransactions(
|
||||||
ruleId,
|
ruleId,
|
||||||
transactionsCriteria,
|
transactionsCriteria,
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ export enum CASHFLOW_DIRECTION {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export enum CASHFLOW_TRANSACTION_TYPE {
|
export enum CASHFLOW_TRANSACTION_TYPE {
|
||||||
OWNERS_DRAWING = 'OwnerDrawing',
|
ONWERS_DRAWING = 'OwnerDrawing',
|
||||||
OWNER_CONTRIBUTION = 'OwnerContribution',
|
OWNER_CONTRIBUTION = 'OwnerContribution',
|
||||||
OTHER_INCOME = 'OtherIncome',
|
OTHER_INCOME = 'OtherIncome',
|
||||||
TRANSFER_FROM_ACCOUNT = 'TransferFromAccount',
|
TRANSFER_FROM_ACCOUNT = 'TransferFromAccount',
|
||||||
@@ -36,7 +36,7 @@ export enum CASHFLOW_TRANSACTION_TYPE {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const CASHFLOW_TRANSACTION_TYPE_META = {
|
export const CASHFLOW_TRANSACTION_TYPE_META = {
|
||||||
[`${CASHFLOW_TRANSACTION_TYPE.OWNERS_DRAWING}`]: {
|
[`${CASHFLOW_TRANSACTION_TYPE.ONWERS_DRAWING}`]: {
|
||||||
type: 'OwnerDrawing',
|
type: 'OwnerDrawing',
|
||||||
direction: CASHFLOW_DIRECTION.OUT,
|
direction: CASHFLOW_DIRECTION.OUT,
|
||||||
creditType: [ACCOUNT_TYPE.EQUITY],
|
creditType: [ACCOUNT_TYPE.EQUITY],
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import {
|
|||||||
Post,
|
Post,
|
||||||
Put,
|
Put,
|
||||||
Query,
|
Query,
|
||||||
UseGuards,
|
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { BillPaymentsApplication } from './BillPaymentsApplication.service';
|
import { BillPaymentsApplication } from './BillPaymentsApplication.service';
|
||||||
import {
|
import {
|
||||||
@@ -27,18 +26,12 @@ import { BillPaymentsPages } from './commands/BillPaymentsPages.service';
|
|||||||
import { BillPaymentResponseDto } from './dtos/BillPaymentResponse.dto';
|
import { BillPaymentResponseDto } from './dtos/BillPaymentResponse.dto';
|
||||||
import { PaginatedResponseDto } from '@/common/dtos/PaginatedResults.dto';
|
import { PaginatedResponseDto } from '@/common/dtos/PaginatedResults.dto';
|
||||||
import { ApiCommonHeaders } from '@/common/decorators/ApiCommonHeaders';
|
import { ApiCommonHeaders } from '@/common/decorators/ApiCommonHeaders';
|
||||||
import { RequirePermission } from '@/modules/Roles/RequirePermission.decorator';
|
|
||||||
import { PermissionGuard } from '@/modules/Roles/Permission.guard';
|
|
||||||
import { AuthorizationGuard } from '@/modules/Roles/Authorization.guard';
|
|
||||||
import { AbilitySubject } from '@/modules/Roles/Roles.types';
|
|
||||||
import { IPaymentMadeAction } from './types/BillPayments.types';
|
|
||||||
|
|
||||||
@Controller('bill-payments')
|
@Controller('bill-payments')
|
||||||
@ApiTags('Bill Payments')
|
@ApiTags('Bill Payments')
|
||||||
@ApiExtraModels(BillPaymentResponseDto)
|
@ApiExtraModels(BillPaymentResponseDto)
|
||||||
@ApiExtraModels(PaginatedResponseDto)
|
@ApiExtraModels(PaginatedResponseDto)
|
||||||
@ApiCommonHeaders()
|
@ApiCommonHeaders()
|
||||||
@UseGuards(AuthorizationGuard, PermissionGuard)
|
|
||||||
export class BillPaymentsController {
|
export class BillPaymentsController {
|
||||||
constructor(
|
constructor(
|
||||||
private billPaymentsApplication: BillPaymentsApplication,
|
private billPaymentsApplication: BillPaymentsApplication,
|
||||||
@@ -46,14 +39,12 @@ export class BillPaymentsController {
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@RequirePermission(IPaymentMadeAction.Create, AbilitySubject.PaymentMade)
|
|
||||||
@ApiOperation({ summary: 'Create a new bill payment.' })
|
@ApiOperation({ summary: 'Create a new bill payment.' })
|
||||||
public createBillPayment(@Body() billPaymentDTO: CreateBillPaymentDto) {
|
public createBillPayment(@Body() billPaymentDTO: CreateBillPaymentDto) {
|
||||||
return this.billPaymentsApplication.createBillPayment(billPaymentDTO);
|
return this.billPaymentsApplication.createBillPayment(billPaymentDTO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete(':billPaymentId')
|
@Delete(':billPaymentId')
|
||||||
@RequirePermission(IPaymentMadeAction.Delete, AbilitySubject.PaymentMade)
|
|
||||||
@ApiOperation({ summary: 'Delete the given bill payment.' })
|
@ApiOperation({ summary: 'Delete the given bill payment.' })
|
||||||
@ApiParam({
|
@ApiParam({
|
||||||
name: 'billPaymentId',
|
name: 'billPaymentId',
|
||||||
@@ -68,7 +59,6 @@ export class BillPaymentsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Put(':billPaymentId')
|
@Put(':billPaymentId')
|
||||||
@RequirePermission(IPaymentMadeAction.Edit, AbilitySubject.PaymentMade)
|
|
||||||
@ApiOperation({ summary: 'Edit the given bill payment.' })
|
@ApiOperation({ summary: 'Edit the given bill payment.' })
|
||||||
@ApiParam({
|
@ApiParam({
|
||||||
name: 'billPaymentId',
|
name: 'billPaymentId',
|
||||||
@@ -87,7 +77,6 @@ export class BillPaymentsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get('/new-page/entries')
|
@Get('/new-page/entries')
|
||||||
@RequirePermission(IPaymentMadeAction.View, AbilitySubject.PaymentMade)
|
|
||||||
@ApiOperation({
|
@ApiOperation({
|
||||||
summary:
|
summary:
|
||||||
'Retrieves the payable entries of the new page once vendor be selected.',
|
'Retrieves the payable entries of the new page once vendor be selected.',
|
||||||
@@ -106,7 +95,6 @@ export class BillPaymentsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get(':billPaymentId/bills')
|
@Get(':billPaymentId/bills')
|
||||||
@RequirePermission(IPaymentMadeAction.View, AbilitySubject.PaymentMade)
|
|
||||||
@ApiOperation({ summary: 'Retrieves the bills of the given bill payment.' })
|
@ApiOperation({ summary: 'Retrieves the bills of the given bill payment.' })
|
||||||
@ApiParam({
|
@ApiParam({
|
||||||
name: 'billPaymentId',
|
name: 'billPaymentId',
|
||||||
@@ -119,7 +107,6 @@ export class BillPaymentsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get('/:billPaymentId/edit-page')
|
@Get('/:billPaymentId/edit-page')
|
||||||
@RequirePermission(IPaymentMadeAction.View, AbilitySubject.PaymentMade)
|
|
||||||
@ApiOperation({
|
@ApiOperation({
|
||||||
summary: 'Retrieves the edit page of the given bill payment.',
|
summary: 'Retrieves the edit page of the given bill payment.',
|
||||||
})
|
})
|
||||||
@@ -139,7 +126,6 @@ export class BillPaymentsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get(':billPaymentId')
|
@Get(':billPaymentId')
|
||||||
@RequirePermission(IPaymentMadeAction.View, AbilitySubject.PaymentMade)
|
|
||||||
@ApiOperation({ summary: 'Retrieves the bill payment details.' })
|
@ApiOperation({ summary: 'Retrieves the bill payment details.' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
@@ -159,7 +145,6 @@ export class BillPaymentsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
@RequirePermission(IPaymentMadeAction.View, AbilitySubject.PaymentMade)
|
|
||||||
@ApiOperation({ summary: 'Retrieves the bill payments list.' })
|
@ApiOperation({ summary: 'Retrieves the bill payments list.' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import {
|
|||||||
Get,
|
Get,
|
||||||
Query,
|
Query,
|
||||||
HttpCode,
|
HttpCode,
|
||||||
UseGuards,
|
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { BillsApplication } from './Bills.application';
|
import { BillsApplication } from './Bills.application';
|
||||||
import { IBillsFilter } from './Bills.types';
|
import { IBillsFilter } from './Bills.types';
|
||||||
@@ -29,11 +28,6 @@ import {
|
|||||||
BulkDeleteDto,
|
BulkDeleteDto,
|
||||||
ValidateBulkDeleteResponseDto,
|
ValidateBulkDeleteResponseDto,
|
||||||
} from '@/common/dtos/BulkDelete.dto';
|
} from '@/common/dtos/BulkDelete.dto';
|
||||||
import { RequirePermission } from '@/modules/Roles/RequirePermission.decorator';
|
|
||||||
import { PermissionGuard } from '@/modules/Roles/Permission.guard';
|
|
||||||
import { AuthorizationGuard } from '@/modules/Roles/Authorization.guard';
|
|
||||||
import { AbilitySubject } from '@/modules/Roles/Roles.types';
|
|
||||||
import { BillAction } from './Bills.types';
|
|
||||||
|
|
||||||
@Controller('bills')
|
@Controller('bills')
|
||||||
@ApiTags('Bills')
|
@ApiTags('Bills')
|
||||||
@@ -41,12 +35,10 @@ import { BillAction } from './Bills.types';
|
|||||||
@ApiExtraModels(PaginatedResponseDto)
|
@ApiExtraModels(PaginatedResponseDto)
|
||||||
@ApiCommonHeaders()
|
@ApiCommonHeaders()
|
||||||
@ApiExtraModels(ValidateBulkDeleteResponseDto)
|
@ApiExtraModels(ValidateBulkDeleteResponseDto)
|
||||||
@UseGuards(AuthorizationGuard, PermissionGuard)
|
|
||||||
export class BillsController {
|
export class BillsController {
|
||||||
constructor(private billsApplication: BillsApplication) { }
|
constructor(private billsApplication: BillsApplication) { }
|
||||||
|
|
||||||
@Post('validate-bulk-delete')
|
@Post('validate-bulk-delete')
|
||||||
@RequirePermission(BillAction.Delete, AbilitySubject.Bill)
|
|
||||||
@ApiOperation({
|
@ApiOperation({
|
||||||
summary: 'Validate which bills can be deleted and return the results.',
|
summary: 'Validate which bills can be deleted and return the results.',
|
||||||
})
|
})
|
||||||
@@ -66,7 +58,6 @@ export class BillsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Post('bulk-delete')
|
@Post('bulk-delete')
|
||||||
@RequirePermission(BillAction.Delete, AbilitySubject.Bill)
|
|
||||||
@ApiOperation({ summary: 'Deletes multiple bills.' })
|
@ApiOperation({ summary: 'Deletes multiple bills.' })
|
||||||
@HttpCode(200)
|
@HttpCode(200)
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
@@ -82,14 +73,12 @@ export class BillsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@RequirePermission(BillAction.Create, AbilitySubject.Bill)
|
|
||||||
@ApiOperation({ summary: 'Create a new bill.' })
|
@ApiOperation({ summary: 'Create a new bill.' })
|
||||||
createBill(@Body() billDTO: CreateBillDto) {
|
createBill(@Body() billDTO: CreateBillDto) {
|
||||||
return this.billsApplication.createBill(billDTO);
|
return this.billsApplication.createBill(billDTO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put(':id')
|
@Put(':id')
|
||||||
@RequirePermission(BillAction.Edit, AbilitySubject.Bill)
|
|
||||||
@ApiOperation({ summary: 'Edit the given bill.' })
|
@ApiOperation({ summary: 'Edit the given bill.' })
|
||||||
@ApiParam({
|
@ApiParam({
|
||||||
name: 'id',
|
name: 'id',
|
||||||
@@ -102,7 +91,6 @@ export class BillsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Delete(':id')
|
@Delete(':id')
|
||||||
@RequirePermission(BillAction.Delete, AbilitySubject.Bill)
|
|
||||||
@ApiOperation({ summary: 'Delete the given bill.' })
|
@ApiOperation({ summary: 'Delete the given bill.' })
|
||||||
@ApiParam({
|
@ApiParam({
|
||||||
name: 'id',
|
name: 'id',
|
||||||
@@ -115,7 +103,6 @@ export class BillsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
@RequirePermission(BillAction.View, AbilitySubject.Bill)
|
|
||||||
@ApiOperation({ summary: 'Retrieves the bills.' })
|
@ApiOperation({ summary: 'Retrieves the bills.' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
@@ -145,7 +132,6 @@ export class BillsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get(':id/payment-transactions')
|
@Get(':id/payment-transactions')
|
||||||
@RequirePermission(BillAction.View, AbilitySubject.Bill)
|
|
||||||
@ApiOperation({
|
@ApiOperation({
|
||||||
summary: 'Retrieve the specific bill associated payment transactions.',
|
summary: 'Retrieve the specific bill associated payment transactions.',
|
||||||
})
|
})
|
||||||
@@ -160,7 +146,6 @@ export class BillsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
@RequirePermission(BillAction.View, AbilitySubject.Bill)
|
|
||||||
@ApiOperation({ summary: 'Retrieves the bill details.' })
|
@ApiOperation({ summary: 'Retrieves the bill details.' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
@@ -180,7 +165,6 @@ export class BillsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Patch(':id/open')
|
@Patch(':id/open')
|
||||||
@RequirePermission(BillAction.Edit, AbilitySubject.Bill)
|
|
||||||
@ApiOperation({ summary: 'Open the given bill.' })
|
@ApiOperation({ summary: 'Open the given bill.' })
|
||||||
@ApiParam({
|
@ApiParam({
|
||||||
name: 'id',
|
name: 'id',
|
||||||
@@ -193,7 +177,6 @@ export class BillsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get('due')
|
@Get('due')
|
||||||
@RequirePermission(BillAction.View, AbilitySubject.Bill)
|
|
||||||
@ApiOperation({ summary: 'Retrieves the due bills.' })
|
@ApiOperation({ summary: 'Retrieves the due bills.' })
|
||||||
getDueBills(@Body('vendorId') vendorId?: number) {
|
getDueBills(@Body('vendorId') vendorId?: number) {
|
||||||
return this.billsApplication.getDueBills(vendorId);
|
return this.billsApplication.getDueBills(vendorId);
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import { ApiProperty } from '@nestjs/swagger';
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
import { Type } from 'class-transformer';
|
|
||||||
import { ItemEntryDto } from '@/modules/TransactionItemEntry/dto/ItemEntry.dto';
|
import { ItemEntryDto } from '@/modules/TransactionItemEntry/dto/ItemEntry.dto';
|
||||||
import { AttachmentLinkDto } from '@/modules/Attachments/dtos/Attachment.dto';
|
import { AttachmentLinkDto } from '@/modules/Attachments/dtos/Attachment.dto';
|
||||||
import { BranchResponseDto } from '@/modules/Branches/dtos/BranchResponse.dto';
|
|
||||||
import { DiscountType } from '@/common/types/Discount';
|
import { DiscountType } from '@/common/types/Discount';
|
||||||
|
|
||||||
export class BillResponseDto {
|
export class BillResponseDto {
|
||||||
@@ -91,14 +89,6 @@ export class BillResponseDto {
|
|||||||
})
|
})
|
||||||
branchId?: number;
|
branchId?: number;
|
||||||
|
|
||||||
@ApiProperty({
|
|
||||||
description: 'Branch details',
|
|
||||||
type: () => BranchResponseDto,
|
|
||||||
required: false,
|
|
||||||
})
|
|
||||||
@Type(() => BranchResponseDto)
|
|
||||||
branch?: BranchResponseDto;
|
|
||||||
|
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
description: 'The ID of the project',
|
description: 'The ID of the project',
|
||||||
example: 301,
|
example: 301,
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ export class BillTransformer extends Transformer {
|
|||||||
'taxes',
|
'taxes',
|
||||||
'entries',
|
'entries',
|
||||||
'attachments',
|
'attachments',
|
||||||
'branch',
|
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -31,12 +31,6 @@ import { ValidateBranchExistance } from './integrations/ValidateBranchExistance'
|
|||||||
import { ManualJournalBranchesValidator } from './integrations/ManualJournals/ManualJournalsBranchesValidator';
|
import { ManualJournalBranchesValidator } from './integrations/ManualJournals/ManualJournalsBranchesValidator';
|
||||||
import { CashflowTransactionsActivateBranches } from './integrations/Cashflow/CashflowActivateBranches';
|
import { CashflowTransactionsActivateBranches } from './integrations/Cashflow/CashflowActivateBranches';
|
||||||
import { ExpensesActivateBranches } from './integrations/Expense/ExpensesActivateBranches';
|
import { ExpensesActivateBranches } from './integrations/Expense/ExpensesActivateBranches';
|
||||||
import { BillActivateBranches } from './integrations/Purchases/BillBranchesActivate';
|
|
||||||
import { VendorCreditActivateBranches } from './integrations/Purchases/VendorCreditBranchesActivate';
|
|
||||||
import { BillPaymentsActivateBranches } from './integrations/Purchases/PaymentMadeBranchesActivate';
|
|
||||||
import { BillBranchesActivateSubscriber } from './subscribers/Activate/BillBranchesActivateSubscriber';
|
|
||||||
import { VendorCreditBranchesActivateSubscriber } from './subscribers/Activate/VendorCreditBranchesActivateSubscriber';
|
|
||||||
import { PaymentMadeActivateBranchesSubscriber } from './subscribers/Activate/PaymentMadeBranchesActivateSubscriber';
|
|
||||||
import { FeaturesModule } from '../Features/Features.module';
|
import { FeaturesModule } from '../Features/Features.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
@@ -72,13 +66,7 @@ import { FeaturesModule } from '../Features/Features.module';
|
|||||||
ValidateBranchExistance,
|
ValidateBranchExistance,
|
||||||
ManualJournalBranchesValidator,
|
ManualJournalBranchesValidator,
|
||||||
CashflowTransactionsActivateBranches,
|
CashflowTransactionsActivateBranches,
|
||||||
ExpensesActivateBranches,
|
ExpensesActivateBranches
|
||||||
BillActivateBranches,
|
|
||||||
VendorCreditActivateBranches,
|
|
||||||
BillPaymentsActivateBranches,
|
|
||||||
BillBranchesActivateSubscriber,
|
|
||||||
VendorCreditBranchesActivateSubscriber,
|
|
||||||
PaymentMadeActivateBranchesSubscriber
|
|
||||||
],
|
],
|
||||||
exports: [
|
exports: [
|
||||||
BranchesSettingsService,
|
BranchesSettingsService,
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
import { Knex } from 'knex';
|
import { Knex } from 'knex';
|
||||||
import { Inject, Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
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';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class BillActivateBranches {
|
export class BillActivateBranches {
|
||||||
constructor(
|
constructor(private readonly billModel: TenantModelProxy<typeof Bill>) {}
|
||||||
@Inject(Bill.name)
|
|
||||||
private readonly billModel: TenantModelProxy<typeof Bill>,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates all bills transactions with the primary branch.
|
* Updates all bills transactions with the primary branch.
|
||||||
@@ -20,7 +17,7 @@ export class BillActivateBranches {
|
|||||||
primaryBranchId: number,
|
primaryBranchId: number,
|
||||||
trx?: Knex.Transaction,
|
trx?: Knex.Transaction,
|
||||||
) => {
|
) => {
|
||||||
// Updates the bills with primary branch.
|
// Updates the sale invoice with primary branch.
|
||||||
await this.billModel().query(trx).update({ branchId: primaryBranchId });
|
await Bill.query(trx).update({ branchId: primaryBranchId });
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
import { Knex } from 'knex';
|
import { Knex } from 'knex';
|
||||||
import { Inject, Injectable } from '@nestjs/common';
|
|
||||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||||
import { BillPayment } from '@/modules/BillPayments/models/BillPayment';
|
import { BillPayment } from '@/modules/BillPayments/models/BillPayment';
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class BillPaymentsActivateBranches {
|
export class BillPaymentsActivateBranches {
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(BillPayment.name)
|
|
||||||
private readonly billPaymentModel: TenantModelProxy<typeof BillPayment>,
|
private readonly billPaymentModel: TenantModelProxy<typeof BillPayment>,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
import { Knex } from 'knex';
|
import { Knex } from 'knex';
|
||||||
import { Inject, Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||||
import { VendorCredit } from '@/modules/VendorCredit/models/VendorCredit';
|
import { VendorCredit } from '@/modules/VendorCredit/models/VendorCredit';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class VendorCreditActivateBranches {
|
export class VendorCreditActivateBranches {
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(VendorCredit.name)
|
|
||||||
private readonly vendorCreditModel: TenantModelProxy<typeof VendorCredit>,
|
private readonly vendorCreditModel: TenantModelProxy<typeof VendorCredit>,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
import { IBranchesActivatedPayload } from '../../Branches.types';
|
|
||||||
import { events } from '@/common/events/events';
|
|
||||||
import { Injectable } from '@nestjs/common';
|
|
||||||
import { BillActivateBranches } from '../../integrations/Purchases/BillBranchesActivate';
|
|
||||||
import { OnEvent } from '@nestjs/event-emitter';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class BillBranchesActivateSubscriber {
|
|
||||||
constructor(
|
|
||||||
private readonly billActivateBranches: BillActivateBranches,
|
|
||||||
) { }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates bills transactions with the primary branch once
|
|
||||||
* the multi-branches is activated.
|
|
||||||
* @param {IBranchesActivatedPayload}
|
|
||||||
*/
|
|
||||||
@OnEvent(events.branch.onActivated)
|
|
||||||
async updateBillsWithBranchOnActivated({
|
|
||||||
primaryBranch,
|
|
||||||
trx,
|
|
||||||
}: IBranchesActivatedPayload) {
|
|
||||||
await this.billActivateBranches.updateBillsWithBranch(
|
|
||||||
primaryBranch.id,
|
|
||||||
trx,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
import { IBranchesActivatedPayload } from '../../Branches.types';
|
|
||||||
import { events } from '@/common/events/events';
|
|
||||||
import { Injectable } from '@nestjs/common';
|
|
||||||
import { VendorCreditActivateBranches } from '../../integrations/Purchases/VendorCreditBranchesActivate';
|
|
||||||
import { OnEvent } from '@nestjs/event-emitter';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class VendorCreditBranchesActivateSubscriber {
|
|
||||||
constructor(
|
|
||||||
private readonly vendorCreditActivateBranches: VendorCreditActivateBranches,
|
|
||||||
) { }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates vendor credits transactions with the primary branch once
|
|
||||||
* the multi-branches is activated.
|
|
||||||
* @param {IBranchesActivatedPayload}
|
|
||||||
*/
|
|
||||||
@OnEvent(events.branch.onActivated)
|
|
||||||
async updateVendorCreditsWithBranchOnActivated({
|
|
||||||
primaryBranch,
|
|
||||||
trx,
|
|
||||||
}: IBranchesActivatedPayload) {
|
|
||||||
await this.vendorCreditActivateBranches.updateVendorCreditsWithBranch(
|
|
||||||
primaryBranch.id,
|
|
||||||
trx,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -22,7 +22,6 @@ export abstract class BaseCommand extends CommandRunner {
|
|||||||
},
|
},
|
||||||
migrations: {
|
migrations: {
|
||||||
directory: this.configService.get('systemDatabase.migrationDir'),
|
directory: this.configService.get('systemDatabase.migrationDir'),
|
||||||
loadExtensions: ['.js'],
|
|
||||||
},
|
},
|
||||||
seeds: {
|
seeds: {
|
||||||
directory: this.configService.get('systemDatabase.seedsDir'),
|
directory: this.configService.get('systemDatabase.seedsDir'),
|
||||||
@@ -44,7 +43,6 @@ export abstract class BaseCommand extends CommandRunner {
|
|||||||
},
|
},
|
||||||
migrations: {
|
migrations: {
|
||||||
directory: this.configService.get('tenantDatabase.migrationsDir') || './src/database/migrations',
|
directory: this.configService.get('tenantDatabase.migrationsDir') || './src/database/migrations',
|
||||||
loadExtensions: ['.js'],
|
|
||||||
},
|
},
|
||||||
seeds: {
|
seeds: {
|
||||||
directory: this.configService.get('tenantDatabase.seedsDir') || './src/database/seeds/core',
|
directory: this.configService.get('tenantDatabase.seedsDir') || './src/database/seeds/core',
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ export interface IContactAddress {
|
|||||||
billingAddressCity: string;
|
billingAddressCity: string;
|
||||||
billingAddressCountry: string;
|
billingAddressCountry: string;
|
||||||
billingAddressEmail: string;
|
billingAddressEmail: string;
|
||||||
billingAddressPostcode: string;
|
billingAddressZipcode: string;
|
||||||
billingAddressPhone: string;
|
billingAddressPhone: string;
|
||||||
billingAddressState: string;
|
billingAddressState: string;
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ export interface IContactAddress {
|
|||||||
shippingAddressCity: string;
|
shippingAddressCity: string;
|
||||||
shippingAddressCountry: string;
|
shippingAddressCountry: string;
|
||||||
shippingAddressEmail: string;
|
shippingAddressEmail: string;
|
||||||
shippingAddressPostcode: string;
|
shippingAddressZipcode: string;
|
||||||
shippingAddressPhone: string;
|
shippingAddressPhone: string;
|
||||||
shippingAddressState: string;
|
shippingAddressState: string;
|
||||||
}
|
}
|
||||||
@@ -29,7 +29,7 @@ export interface IContactAddressDTO {
|
|||||||
billingAddressCity?: string;
|
billingAddressCity?: string;
|
||||||
billingAddressCountry?: string;
|
billingAddressCountry?: string;
|
||||||
billingAddressEmail?: string;
|
billingAddressEmail?: string;
|
||||||
billingAddressPostcode?: string;
|
billingAddressZipcode?: string;
|
||||||
billingAddressPhone?: string;
|
billingAddressPhone?: string;
|
||||||
billingAddressState?: string;
|
billingAddressState?: string;
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ export interface IContactAddressDTO {
|
|||||||
shippingAddressCity?: string;
|
shippingAddressCity?: string;
|
||||||
shippingAddressCountry?: string;
|
shippingAddressCountry?: string;
|
||||||
shippingAddressEmail?: string;
|
shippingAddressEmail?: string;
|
||||||
shippingAddressPostcode?: string;
|
shippingAddressZipcode?: string;
|
||||||
shippingAddressPhone?: string;
|
shippingAddressPhone?: string;
|
||||||
shippingAddressState?: string;
|
shippingAddressState?: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,35 +1,20 @@
|
|||||||
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||||
import {
|
import { Body, Controller, Delete, Get, Param, Post } from '@nestjs/common';
|
||||||
Body,
|
|
||||||
Controller,
|
|
||||||
Delete,
|
|
||||||
Get,
|
|
||||||
Param,
|
|
||||||
Post,
|
|
||||||
UseGuards,
|
|
||||||
} from '@nestjs/common';
|
|
||||||
import { ICreditNoteRefundDTO } from '../CreditNotes/types/CreditNotes.types';
|
import { ICreditNoteRefundDTO } from '../CreditNotes/types/CreditNotes.types';
|
||||||
import { CreditNotesRefundsApplication } from './CreditNotesRefundsApplication.service';
|
import { CreditNotesRefundsApplication } from './CreditNotesRefundsApplication.service';
|
||||||
import { RefundCreditNote } from './models/RefundCreditNote';
|
import { RefundCreditNote } from './models/RefundCreditNote';
|
||||||
import { CreditNoteRefundDto } from './dto/CreditNoteRefund.dto';
|
import { CreditNoteRefundDto } from './dto/CreditNoteRefund.dto';
|
||||||
import { ApiCommonHeaders } from '@/common/decorators/ApiCommonHeaders';
|
import { ApiCommonHeaders } from '@/common/decorators/ApiCommonHeaders';
|
||||||
import { RequirePermission } from '@/modules/Roles/RequirePermission.decorator';
|
|
||||||
import { PermissionGuard } from '@/modules/Roles/Permission.guard';
|
|
||||||
import { AuthorizationGuard } from '@/modules/Roles/Authorization.guard';
|
|
||||||
import { AbilitySubject } from '@/modules/Roles/Roles.types';
|
|
||||||
import { CreditNoteAction } from '../CreditNotes/types/CreditNotes.types';
|
|
||||||
|
|
||||||
@Controller('credit-notes')
|
@Controller('credit-notes')
|
||||||
@ApiTags('Credit Note Refunds')
|
@ApiTags('Credit Note Refunds')
|
||||||
@ApiCommonHeaders()
|
@ApiCommonHeaders()
|
||||||
@UseGuards(AuthorizationGuard, PermissionGuard)
|
|
||||||
export class CreditNoteRefundsController {
|
export class CreditNoteRefundsController {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly creditNotesRefundsApplication: CreditNotesRefundsApplication,
|
private readonly creditNotesRefundsApplication: CreditNotesRefundsApplication,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@Get(':creditNoteId/refunds')
|
@Get(':creditNoteId/refunds')
|
||||||
@RequirePermission(CreditNoteAction.View, AbilitySubject.CreditNote)
|
|
||||||
@ApiOperation({ summary: 'Retrieve the credit note graph.' })
|
@ApiOperation({ summary: 'Retrieve the credit note graph.' })
|
||||||
getCreditNoteRefunds(@Param('creditNoteId') creditNoteId: number) {
|
getCreditNoteRefunds(@Param('creditNoteId') creditNoteId: number) {
|
||||||
return this.creditNotesRefundsApplication.getCreditNoteRefunds(
|
return this.creditNotesRefundsApplication.getCreditNoteRefunds(
|
||||||
@@ -44,7 +29,6 @@ export class CreditNoteRefundsController {
|
|||||||
* @returns {Promise<RefundCreditNote>}
|
* @returns {Promise<RefundCreditNote>}
|
||||||
*/
|
*/
|
||||||
@Post(':creditNoteId/refunds')
|
@Post(':creditNoteId/refunds')
|
||||||
@RequirePermission(CreditNoteAction.Refund, AbilitySubject.CreditNote)
|
|
||||||
@ApiOperation({ summary: 'Create a refund for the given credit note.' })
|
@ApiOperation({ summary: 'Create a refund for the given credit note.' })
|
||||||
createRefundCreditNote(
|
createRefundCreditNote(
|
||||||
@Param('creditNoteId') creditNoteId: number,
|
@Param('creditNoteId') creditNoteId: number,
|
||||||
@@ -62,7 +46,6 @@ export class CreditNoteRefundsController {
|
|||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
@Delete('refunds/:refundCreditId')
|
@Delete('refunds/:refundCreditId')
|
||||||
@RequirePermission(CreditNoteAction.Refund, AbilitySubject.CreditNote)
|
|
||||||
@ApiOperation({ summary: 'Delete a refund for the given credit note.' })
|
@ApiOperation({ summary: 'Delete a refund for the given credit note.' })
|
||||||
deleteRefundCreditNote(
|
deleteRefundCreditNote(
|
||||||
@Param('refundCreditId') refundCreditId: number,
|
@Param('refundCreditId') refundCreditId: number,
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ import {
|
|||||||
Put,
|
Put,
|
||||||
Query,
|
Query,
|
||||||
Res,
|
Res,
|
||||||
UseGuards,
|
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { CreditNoteApplication } from './CreditNoteApplication.service';
|
import { CreditNoteApplication } from './CreditNoteApplication.service';
|
||||||
import { ICreditNotesQueryDTO } from './types/CreditNotes.types';
|
import { ICreditNotesQueryDTO } from './types/CreditNotes.types';
|
||||||
@@ -31,11 +30,6 @@ import {
|
|||||||
ValidateBulkDeleteResponseDto,
|
ValidateBulkDeleteResponseDto,
|
||||||
} from '@/common/dtos/BulkDelete.dto';
|
} from '@/common/dtos/BulkDelete.dto';
|
||||||
import { AcceptType } from '@/constants/accept-type';
|
import { AcceptType } from '@/constants/accept-type';
|
||||||
import { RequirePermission } from '@/modules/Roles/RequirePermission.decorator';
|
|
||||||
import { PermissionGuard } from '@/modules/Roles/Permission.guard';
|
|
||||||
import { AuthorizationGuard } from '@/modules/Roles/Authorization.guard';
|
|
||||||
import { AbilitySubject } from '@/modules/Roles/Roles.types';
|
|
||||||
import { CreditNoteAction } from './types/CreditNotes.types';
|
|
||||||
|
|
||||||
@Controller('credit-notes')
|
@Controller('credit-notes')
|
||||||
@ApiTags('Credit Notes')
|
@ApiTags('Credit Notes')
|
||||||
@@ -43,7 +37,6 @@ import { CreditNoteAction } from './types/CreditNotes.types';
|
|||||||
@ApiExtraModels(PaginatedResponseDto)
|
@ApiExtraModels(PaginatedResponseDto)
|
||||||
@ApiExtraModels(ValidateBulkDeleteResponseDto)
|
@ApiExtraModels(ValidateBulkDeleteResponseDto)
|
||||||
@ApiCommonHeaders()
|
@ApiCommonHeaders()
|
||||||
@UseGuards(AuthorizationGuard, PermissionGuard)
|
|
||||||
export class CreditNotesController {
|
export class CreditNotesController {
|
||||||
/**
|
/**
|
||||||
* @param {CreditNoteApplication} creditNoteApplication - The credit note application service.
|
* @param {CreditNoteApplication} creditNoteApplication - The credit note application service.
|
||||||
@@ -51,7 +44,6 @@ export class CreditNotesController {
|
|||||||
constructor(private creditNoteApplication: CreditNoteApplication) { }
|
constructor(private creditNoteApplication: CreditNoteApplication) { }
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@RequirePermission(CreditNoteAction.Create, AbilitySubject.CreditNote)
|
|
||||||
@ApiOperation({ summary: 'Create a new credit note' })
|
@ApiOperation({ summary: 'Create a new credit note' })
|
||||||
@ApiResponse({ status: 201, description: 'Credit note successfully created' })
|
@ApiResponse({ status: 201, description: 'Credit note successfully created' })
|
||||||
@ApiResponse({ status: 400, description: 'Invalid input data' })
|
@ApiResponse({ status: 400, description: 'Invalid input data' })
|
||||||
@@ -60,7 +52,6 @@ export class CreditNotesController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get('state')
|
@Get('state')
|
||||||
@RequirePermission(CreditNoteAction.View, AbilitySubject.CreditNote)
|
|
||||||
@ApiOperation({ summary: 'Get credit note state' })
|
@ApiOperation({ summary: 'Get credit note state' })
|
||||||
@ApiResponse({ status: 200, description: 'Returns the credit note state' })
|
@ApiResponse({ status: 200, description: 'Returns the credit note state' })
|
||||||
getCreditNoteState() {
|
getCreditNoteState() {
|
||||||
@@ -68,7 +59,6 @@ export class CreditNotesController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
@RequirePermission(CreditNoteAction.View, AbilitySubject.CreditNote)
|
|
||||||
@ApiOperation({ summary: 'Get a specific credit note by ID' })
|
@ApiOperation({ summary: 'Get a specific credit note by ID' })
|
||||||
@ApiParam({ name: 'id', description: 'Credit note ID', type: 'number' })
|
@ApiParam({ name: 'id', description: 'Credit note ID', type: 'number' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
@@ -102,7 +92,6 @@ export class CreditNotesController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
@RequirePermission(CreditNoteAction.View, AbilitySubject.CreditNote)
|
|
||||||
@ApiOperation({ summary: 'Get all credit notes' })
|
@ApiOperation({ summary: 'Get all credit notes' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
@@ -126,7 +115,6 @@ export class CreditNotesController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Put(':id')
|
@Put(':id')
|
||||||
@RequirePermission(CreditNoteAction.Edit, AbilitySubject.CreditNote)
|
|
||||||
@ApiOperation({ summary: 'Update a credit note' })
|
@ApiOperation({ summary: 'Update a credit note' })
|
||||||
@ApiParam({ name: 'id', description: 'Credit note ID', type: 'number' })
|
@ApiParam({ name: 'id', description: 'Credit note ID', type: 'number' })
|
||||||
@ApiResponse({ status: 200, description: 'Credit note successfully updated' })
|
@ApiResponse({ status: 200, description: 'Credit note successfully updated' })
|
||||||
@@ -143,7 +131,6 @@ export class CreditNotesController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Put(':id/open')
|
@Put(':id/open')
|
||||||
@RequirePermission(CreditNoteAction.Edit, AbilitySubject.CreditNote)
|
|
||||||
@ApiOperation({ summary: 'Open a credit note' })
|
@ApiOperation({ summary: 'Open a credit note' })
|
||||||
@ApiParam({ name: 'id', description: 'Credit note ID', type: 'number' })
|
@ApiParam({ name: 'id', description: 'Credit note ID', type: 'number' })
|
||||||
@ApiResponse({ status: 200, description: 'Credit note successfully opened' })
|
@ApiResponse({ status: 200, description: 'Credit note successfully opened' })
|
||||||
@@ -153,7 +140,6 @@ export class CreditNotesController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Post('validate-bulk-delete')
|
@Post('validate-bulk-delete')
|
||||||
@RequirePermission(CreditNoteAction.Delete, AbilitySubject.CreditNote)
|
|
||||||
@ApiOperation({
|
@ApiOperation({
|
||||||
summary:
|
summary:
|
||||||
'Validates which credit notes can be deleted and returns the results.',
|
'Validates which credit notes can be deleted and returns the results.',
|
||||||
@@ -175,7 +161,6 @@ export class CreditNotesController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Post('bulk-delete')
|
@Post('bulk-delete')
|
||||||
@RequirePermission(CreditNoteAction.Delete, AbilitySubject.CreditNote)
|
|
||||||
@ApiOperation({ summary: 'Deletes multiple credit notes.' })
|
@ApiOperation({ summary: 'Deletes multiple credit notes.' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
@@ -188,7 +173,6 @@ export class CreditNotesController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Delete(':id')
|
@Delete(':id')
|
||||||
@RequirePermission(CreditNoteAction.Delete, AbilitySubject.CreditNote)
|
|
||||||
@ApiOperation({ summary: 'Delete a credit note' })
|
@ApiOperation({ summary: 'Delete a credit note' })
|
||||||
@ApiParam({ name: 'id', description: 'Credit note ID', type: 'number' })
|
@ApiParam({ name: 'id', description: 'Credit note ID', type: 'number' })
|
||||||
@ApiResponse({ status: 200, description: 'Credit note successfully deleted' })
|
@ApiResponse({ status: 200, description: 'Credit note successfully deleted' })
|
||||||
|
|||||||
@@ -1,39 +1,15 @@
|
|||||||
import {
|
import { Body, Controller, Get, Param, Post } from '@nestjs/common';
|
||||||
Body,
|
|
||||||
Controller,
|
|
||||||
Delete,
|
|
||||||
Get,
|
|
||||||
Param,
|
|
||||||
Post,
|
|
||||||
UseGuards,
|
|
||||||
} from '@nestjs/common';
|
|
||||||
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
||||||
import { GetCreditNoteAssociatedAppliedInvoices } from './queries/GetCreditNoteAssociatedAppliedInvoices.service';
|
import { GetCreditNoteAssociatedAppliedInvoices } from './queries/GetCreditNoteAssociatedAppliedInvoices.service';
|
||||||
import { ApiCommonHeaders } from '@/common/decorators/ApiCommonHeaders';
|
|
||||||
import { RequirePermission } from '@/modules/Roles/RequirePermission.decorator';
|
|
||||||
import { PermissionGuard } from '@/modules/Roles/Permission.guard';
|
|
||||||
import { AuthorizationGuard } from '@/modules/Roles/Authorization.guard';
|
|
||||||
import { AbilitySubject } from '@/modules/Roles/Roles.types';
|
|
||||||
import { CreditNoteAction } from '../CreditNotes/types/CreditNotes.types';
|
|
||||||
import { GetCreditNoteAssociatedInvoicesToApply } from './queries/GetCreditNoteAssociatedInvoicesToApply.service';
|
|
||||||
import { CreditNoteApplyToInvoices } from './commands/CreditNoteApplyToInvoices.service';
|
|
||||||
import { DeleteCreditNoteApplyToInvoices } from './commands/DeleteCreditNoteApplyToInvoices.service';
|
|
||||||
import { ApplyCreditNoteToInvoicesDto } from './dtos/ApplyCreditNoteToInvoices.dto';
|
|
||||||
|
|
||||||
@Controller('credit-notes')
|
@Controller('credit-notes')
|
||||||
@ApiTags('Credit Notes Apply Invoice')
|
@ApiTags('Credit Notes Apply Invoice')
|
||||||
@ApiCommonHeaders()
|
|
||||||
@UseGuards(AuthorizationGuard, PermissionGuard)
|
|
||||||
export class CreditNotesApplyInvoiceController {
|
export class CreditNotesApplyInvoiceController {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly getCreditNoteAssociatedAppliedInvoicesService: GetCreditNoteAssociatedAppliedInvoices,
|
private readonly getCreditNoteAssociatedAppliedInvoicesService: GetCreditNoteAssociatedAppliedInvoices,
|
||||||
private readonly getCreditNoteAssociatedInvoicesToApplyService: GetCreditNoteAssociatedInvoicesToApply,
|
|
||||||
private readonly creditNoteApplyToInvoicesService: CreditNoteApplyToInvoices,
|
|
||||||
private readonly deleteCreditNoteApplyToInvoicesService: DeleteCreditNoteApplyToInvoices,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@Get(':creditNoteId/applied-invoices')
|
@Get(':creditNoteId/applied-invoices')
|
||||||
@RequirePermission(CreditNoteAction.View, AbilitySubject.CreditNote)
|
|
||||||
@ApiOperation({ summary: 'Applied credit note to invoices' })
|
@ApiOperation({ summary: 'Applied credit note to invoices' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
@@ -47,25 +23,7 @@ export class CreditNotesApplyInvoiceController {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get(':creditNoteId/apply-invoices')
|
|
||||||
@RequirePermission(CreditNoteAction.View, AbilitySubject.CreditNote)
|
|
||||||
@ApiOperation({ summary: 'Get credit note associated invoices to apply' })
|
|
||||||
@ApiResponse({
|
|
||||||
status: 200,
|
|
||||||
description: 'Credit note associated invoices to apply',
|
|
||||||
})
|
|
||||||
@ApiResponse({ status: 404, description: 'Credit note not found' })
|
|
||||||
@ApiResponse({ status: 400, description: 'Invalid input data' })
|
|
||||||
getCreditNoteAssociatedInvoicesToApply(
|
|
||||||
@Param('creditNoteId') creditNoteId: number,
|
|
||||||
) {
|
|
||||||
return this.getCreditNoteAssociatedInvoicesToApplyService.getCreditAssociatedInvoicesToApply(
|
|
||||||
creditNoteId,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post(':creditNoteId/apply-invoices')
|
@Post(':creditNoteId/apply-invoices')
|
||||||
@RequirePermission(CreditNoteAction.Edit, AbilitySubject.CreditNote)
|
|
||||||
@ApiOperation({ summary: 'Apply credit note to invoices' })
|
@ApiOperation({ summary: 'Apply credit note to invoices' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
@@ -73,32 +31,9 @@ export class CreditNotesApplyInvoiceController {
|
|||||||
})
|
})
|
||||||
@ApiResponse({ status: 404, description: 'Credit note not found' })
|
@ApiResponse({ status: 404, description: 'Credit note not found' })
|
||||||
@ApiResponse({ status: 400, description: 'Invalid input data' })
|
@ApiResponse({ status: 400, description: 'Invalid input data' })
|
||||||
applyCreditNoteToInvoices(
|
applyCreditNoteToInvoices(@Param('creditNoteId') creditNoteId: number) {
|
||||||
@Param('creditNoteId') creditNoteId: number,
|
return this.getCreditNoteAssociatedAppliedInvoicesService.getCreditAssociatedAppliedInvoices(
|
||||||
@Body() applyDto: ApplyCreditNoteToInvoicesDto,
|
|
||||||
) {
|
|
||||||
return this.creditNoteApplyToInvoicesService.applyCreditNoteToInvoices(
|
|
||||||
creditNoteId,
|
creditNoteId,
|
||||||
applyDto,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Delete('applied-invoices/:applyCreditToInvoicesId')
|
|
||||||
@RequirePermission(CreditNoteAction.Edit, AbilitySubject.CreditNote)
|
|
||||||
@ApiOperation({ summary: 'Delete applied credit note to invoice' })
|
|
||||||
@ApiResponse({
|
|
||||||
status: 200,
|
|
||||||
description: 'Credit note application successfully deleted',
|
|
||||||
})
|
|
||||||
@ApiResponse({
|
|
||||||
status: 404,
|
|
||||||
description: 'Credit note application not found',
|
|
||||||
})
|
|
||||||
deleteApplyCreditNoteToInvoices(
|
|
||||||
@Param('applyCreditToInvoicesId') applyCreditToInvoicesId: number,
|
|
||||||
) {
|
|
||||||
return this.deleteCreditNoteApplyToInvoicesService.deleteApplyCreditNoteToInvoices(
|
|
||||||
applyCreditToInvoicesId,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ import { CreditNotesModule } from '../CreditNotes/CreditNotes.module';
|
|||||||
import { GetCreditNoteAssociatedAppliedInvoices } from './queries/GetCreditNoteAssociatedAppliedInvoices.service';
|
import { GetCreditNoteAssociatedAppliedInvoices } from './queries/GetCreditNoteAssociatedAppliedInvoices.service';
|
||||||
import { GetCreditNoteAssociatedInvoicesToApply } from './queries/GetCreditNoteAssociatedInvoicesToApply.service';
|
import { GetCreditNoteAssociatedInvoicesToApply } from './queries/GetCreditNoteAssociatedInvoicesToApply.service';
|
||||||
import { CreditNotesApplyInvoiceController } from './CreditNotesApplyInvoice.controller';
|
import { CreditNotesApplyInvoiceController } from './CreditNotesApplyInvoice.controller';
|
||||||
import { CreditNoteApplySyncCreditSubscriber } from './subscribers/CreditNoteApplySyncCreditSubscriber';
|
|
||||||
import { CreditNoteApplySyncInvoicesCreditedAmountSubscriber } from './subscribers/CreditNoteApplySyncInvoicesSubscriber';
|
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
providers: [
|
providers: [
|
||||||
@@ -21,8 +19,6 @@ import { CreditNoteApplySyncInvoicesCreditedAmountSubscriber } from './subscribe
|
|||||||
CreditNoteApplySyncCredit,
|
CreditNoteApplySyncCredit,
|
||||||
GetCreditNoteAssociatedAppliedInvoices,
|
GetCreditNoteAssociatedAppliedInvoices,
|
||||||
GetCreditNoteAssociatedInvoicesToApply,
|
GetCreditNoteAssociatedInvoicesToApply,
|
||||||
CreditNoteApplySyncCreditSubscriber,
|
|
||||||
CreditNoteApplySyncInvoicesCreditedAmountSubscriber,
|
|
||||||
],
|
],
|
||||||
exports: [DeleteCustomerLinkedCreditNoteService],
|
exports: [DeleteCustomerLinkedCreditNoteService],
|
||||||
imports: [PaymentsReceivedModule, forwardRef(() => CreditNotesModule)],
|
imports: [PaymentsReceivedModule, forwardRef(() => CreditNotesModule)],
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Knex } from 'knex';
|
import { Knex } from 'knex';
|
||||||
import { Injectable, Inject } from '@nestjs/common';
|
import { Injectable, Inject } from '@nestjs/common';
|
||||||
import * as Bluebird from 'bluebird';
|
import Bluebird from 'bluebird';
|
||||||
import { ICreditNoteAppliedToInvoice } from '../types/CreditNoteApplyInvoice.types';
|
import { ICreditNoteAppliedToInvoice } from '../types/CreditNoteApplyInvoice.types';
|
||||||
import { SaleInvoice } from '@/modules/SaleInvoices/models/SaleInvoice';
|
import { SaleInvoice } from '@/modules/SaleInvoices/models/SaleInvoice';
|
||||||
import { CreditNoteAppliedInvoice } from '../models/CreditNoteAppliedInvoice';
|
import { CreditNoteAppliedInvoice } from '../models/CreditNoteAppliedInvoice';
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { Inject, Injectable } from '@nestjs/common';
|
|||||||
import { Knex } from 'knex';
|
import { Knex } from 'knex';
|
||||||
import { sumBy } from 'lodash';
|
import { sumBy } from 'lodash';
|
||||||
import {
|
import {
|
||||||
ICreditNoteAppliedToInvoice,
|
|
||||||
ICreditNoteAppliedToInvoiceModel,
|
ICreditNoteAppliedToInvoiceModel,
|
||||||
IApplyCreditToInvoicesDTO,
|
IApplyCreditToInvoicesDTO,
|
||||||
IApplyCreditToInvoicesCreatedPayload,
|
IApplyCreditToInvoicesCreatedPayload,
|
||||||
@@ -18,7 +17,6 @@ import { CreditNote } from '@/modules/CreditNotes/models/CreditNote';
|
|||||||
import { CreditNoteAppliedInvoice } from '../models/CreditNoteAppliedInvoice';
|
import { CreditNoteAppliedInvoice } from '../models/CreditNoteAppliedInvoice';
|
||||||
import { CommandCreditNoteDTOTransform } from '@/modules/CreditNotes/commands/CommandCreditNoteDTOTransform.service';
|
import { CommandCreditNoteDTOTransform } from '@/modules/CreditNotes/commands/CommandCreditNoteDTOTransform.service';
|
||||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||||
import { ApplyCreditNoteToInvoicesDto } from '../dtos/ApplyCreditNoteToInvoices.dto';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CreditNoteApplyToInvoices {
|
export class CreditNoteApplyToInvoices {
|
||||||
@@ -50,7 +48,7 @@ export class CreditNoteApplyToInvoices {
|
|||||||
*/
|
*/
|
||||||
public async applyCreditNoteToInvoices(
|
public async applyCreditNoteToInvoices(
|
||||||
creditNoteId: number,
|
creditNoteId: number,
|
||||||
applyCreditToInvoicesDTO: ApplyCreditNoteToInvoicesDto,
|
applyCreditToInvoicesDTO: IApplyCreditToInvoicesDTO,
|
||||||
): Promise<CreditNoteAppliedInvoice[]> {
|
): Promise<CreditNoteAppliedInvoice[]> {
|
||||||
// Saves the credit note or throw not found service error.
|
// Saves the credit note or throw not found service error.
|
||||||
const creditNote = await this.creditNoteModel()
|
const creditNote = await this.creditNoteModel()
|
||||||
@@ -73,7 +71,7 @@ export class CreditNoteApplyToInvoices {
|
|||||||
// Validate invoices has remaining amount to apply.
|
// Validate invoices has remaining amount to apply.
|
||||||
this.validateInvoicesRemainingAmount(
|
this.validateInvoicesRemainingAmount(
|
||||||
appliedInvoicesEntries,
|
appliedInvoicesEntries,
|
||||||
creditNoteAppliedModel.entries,
|
creditNoteAppliedModel.amount,
|
||||||
);
|
);
|
||||||
// Validate the credit note remaining amount.
|
// Validate the credit note remaining amount.
|
||||||
this.creditNoteDTOTransform.validateCreditRemainingAmount(
|
this.creditNoteDTOTransform.validateCreditRemainingAmount(
|
||||||
@@ -124,20 +122,18 @@ export class CreditNoteApplyToInvoices {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate each invoice has sufficient remaining amount for the applied credit.
|
* Validate the invoice remaining amount.
|
||||||
* @param {ISaleInvoice[]} invoices
|
* @param {ISaleInvoice[]} invoices
|
||||||
* @param {ICreditNoteAppliedToInvoice[]} entries
|
* @param {number} amount
|
||||||
*/
|
*/
|
||||||
private validateInvoicesRemainingAmount = (
|
private validateInvoicesRemainingAmount = (
|
||||||
invoices: SaleInvoice[],
|
invoices: SaleInvoice[],
|
||||||
entries: ICreditNoteAppliedToInvoice[],
|
amount: number,
|
||||||
) => {
|
) => {
|
||||||
const invoiceMap = new Map(invoices.map((inv) => [inv.id, inv]));
|
const invalidInvoices = invoices.filter(
|
||||||
const invalidEntries = entries.filter((entry) => {
|
(invoice) => invoice.dueAmount < amount,
|
||||||
const invoice = invoiceMap.get(entry.invoiceId);
|
);
|
||||||
return invoice != null && invoice.dueAmount < entry.amount;
|
if (invalidInvoices.length > 0) {
|
||||||
});
|
|
||||||
if (invalidEntries.length > 0) {
|
|
||||||
throw new ServiceError(ERRORS.INVOICES_HAS_NO_REMAINING_AMOUNT);
|
throw new ServiceError(ERRORS.INVOICES_HAS_NO_REMAINING_AMOUNT);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
import { ApiProperty } from '@nestjs/swagger';
|
|
||||||
import { Type } from 'class-transformer';
|
|
||||||
import {
|
|
||||||
ArrayMinSize,
|
|
||||||
IsArray,
|
|
||||||
IsInt,
|
|
||||||
IsNotEmpty,
|
|
||||||
IsNumber,
|
|
||||||
ValidateNested,
|
|
||||||
} from 'class-validator';
|
|
||||||
|
|
||||||
export class ApplyCreditNoteInvoiceEntryDto {
|
|
||||||
@IsNotEmpty()
|
|
||||||
@IsInt()
|
|
||||||
@ApiProperty({ description: 'Invoice ID to apply credit to', example: 1 })
|
|
||||||
invoiceId: number;
|
|
||||||
|
|
||||||
@IsNotEmpty()
|
|
||||||
@IsNumber()
|
|
||||||
@ApiProperty({ description: 'Amount to apply', example: 100.5 })
|
|
||||||
amount: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class ApplyCreditNoteToInvoicesDto {
|
|
||||||
@IsArray()
|
|
||||||
@ArrayMinSize(1)
|
|
||||||
@ValidateNested({ each: true })
|
|
||||||
@Type(() => ApplyCreditNoteInvoiceEntryDto)
|
|
||||||
@ApiProperty({
|
|
||||||
description: 'Entries of invoice ID and amount to apply',
|
|
||||||
type: [ApplyCreditNoteInvoiceEntryDto],
|
|
||||||
example: [
|
|
||||||
{ invoice_id: 1, amount: 100.5 },
|
|
||||||
{ invoice_id: 2, amount: 50 },
|
|
||||||
],
|
|
||||||
})
|
|
||||||
entries: ApplyCreditNoteInvoiceEntryDto[];
|
|
||||||
}
|
|
||||||
@@ -8,7 +8,7 @@ import { CreditNoteApplySyncInvoicesCreditedAmount } from '../commands/CreditNot
|
|||||||
import { events } from '@/common/events/events';
|
import { events } from '@/common/events/events';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CreditNoteApplySyncInvoicesCreditedAmountSubscriber {
|
export default class CreditNoteApplySyncInvoicesCreditedAmountSubscriber {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly syncInvoicesWithCreditNote: CreditNoteApplySyncInvoicesCreditedAmount,
|
private readonly syncInvoicesWithCreditNote: CreditNoteApplySyncInvoicesCreditedAmount,
|
||||||
) {}
|
) {}
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ export interface IApplyCreditToInvoicesDeletedPayload {
|
|||||||
export interface ICreditNoteAppliedToInvoice {
|
export interface ICreditNoteAppliedToInvoice {
|
||||||
amount: number;
|
amount: number;
|
||||||
creditNoteId: number;
|
creditNoteId: number;
|
||||||
invoiceId: number;
|
|
||||||
}
|
}
|
||||||
export interface ICreditNoteAppliedToInvoiceModel {
|
export interface ICreditNoteAppliedToInvoiceModel {
|
||||||
amount: number;
|
amount: number;
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import {
|
|||||||
Post,
|
Post,
|
||||||
Put,
|
Put,
|
||||||
Query,
|
Query,
|
||||||
UseGuards,
|
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { CustomersApplication } from './CustomersApplication.service';
|
import { CustomersApplication } from './CustomersApplication.service';
|
||||||
import { CustomerOpeningBalanceEditDto } from './dtos/CustomerOpeningBalanceEdit.dto';
|
import { CustomerOpeningBalanceEditDto } from './dtos/CustomerOpeningBalanceEdit.dto';
|
||||||
@@ -27,22 +26,15 @@ import {
|
|||||||
ValidateBulkDeleteCustomersResponseDto,
|
ValidateBulkDeleteCustomersResponseDto,
|
||||||
} from './dtos/BulkDeleteCustomers.dto';
|
} from './dtos/BulkDeleteCustomers.dto';
|
||||||
import { ApiCommonHeaders } from '@/common/decorators/ApiCommonHeaders';
|
import { ApiCommonHeaders } from '@/common/decorators/ApiCommonHeaders';
|
||||||
import { RequirePermission } from '@/modules/Roles/RequirePermission.decorator';
|
|
||||||
import { PermissionGuard } from '@/modules/Roles/Permission.guard';
|
|
||||||
import { AuthorizationGuard } from '@/modules/Roles/Authorization.guard';
|
|
||||||
import { AbilitySubject } from '@/modules/Roles/Roles.types';
|
|
||||||
import { CustomerAction } from './types/Customers.types';
|
|
||||||
|
|
||||||
@Controller('customers')
|
@Controller('customers')
|
||||||
@ApiTags('Customers')
|
@ApiTags('Customers')
|
||||||
@ApiExtraModels(CustomerResponseDto)
|
@ApiExtraModels(CustomerResponseDto)
|
||||||
@ApiCommonHeaders()
|
@ApiCommonHeaders()
|
||||||
@UseGuards(AuthorizationGuard, PermissionGuard)
|
|
||||||
export class CustomersController {
|
export class CustomersController {
|
||||||
constructor(private customersApplication: CustomersApplication) { }
|
constructor(private customersApplication: CustomersApplication) { }
|
||||||
|
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
@RequirePermission(CustomerAction.View, AbilitySubject.Customer)
|
|
||||||
@ApiOperation({ summary: 'Retrieves the customer details.' })
|
@ApiOperation({ summary: 'Retrieves the customer details.' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
@@ -54,7 +46,6 @@ export class CustomersController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
@RequirePermission(CustomerAction.View, AbilitySubject.Customer)
|
|
||||||
@ApiOperation({ summary: 'Retrieves the customers paginated list.' })
|
@ApiOperation({ summary: 'Retrieves the customers paginated list.' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
@@ -69,7 +60,6 @@ export class CustomersController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@RequirePermission(CustomerAction.Create, AbilitySubject.Customer)
|
|
||||||
@ApiOperation({ summary: 'Create a new customer.' })
|
@ApiOperation({ summary: 'Create a new customer.' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 201,
|
status: 201,
|
||||||
@@ -81,7 +71,6 @@ export class CustomersController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Put(':id')
|
@Put(':id')
|
||||||
@RequirePermission(CustomerAction.Edit, AbilitySubject.Customer)
|
|
||||||
@ApiOperation({ summary: 'Edit the given customer.' })
|
@ApiOperation({ summary: 'Edit the given customer.' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
@@ -96,7 +85,6 @@ export class CustomersController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Delete(':id')
|
@Delete(':id')
|
||||||
@RequirePermission(CustomerAction.Delete, AbilitySubject.Customer)
|
|
||||||
@ApiOperation({ summary: 'Delete the given customer.' })
|
@ApiOperation({ summary: 'Delete the given customer.' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
@@ -107,7 +95,6 @@ export class CustomersController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Put(':id/opening-balance')
|
@Put(':id/opening-balance')
|
||||||
@RequirePermission(CustomerAction.Edit, AbilitySubject.Customer)
|
|
||||||
@ApiOperation({ summary: 'Edit the opening balance of the given customer.' })
|
@ApiOperation({ summary: 'Edit the opening balance of the given customer.' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
@@ -125,7 +112,6 @@ export class CustomersController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Post('validate-bulk-delete')
|
@Post('validate-bulk-delete')
|
||||||
@RequirePermission(CustomerAction.Delete, AbilitySubject.Customer)
|
|
||||||
@ApiOperation({
|
@ApiOperation({
|
||||||
summary:
|
summary:
|
||||||
'Validates which customers can be deleted and returns counts of deletable and non-deletable customers.',
|
'Validates which customers can be deleted and returns counts of deletable and non-deletable customers.',
|
||||||
@@ -145,7 +131,6 @@ export class CustomersController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Post('bulk-delete')
|
@Post('bulk-delete')
|
||||||
@RequirePermission(CustomerAction.Delete, AbilitySubject.Customer)
|
|
||||||
@ApiOperation({ summary: 'Deletes multiple customers in bulk.' })
|
@ApiOperation({ summary: 'Deletes multiple customers in bulk.' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
|
|||||||
@@ -27,10 +27,10 @@ export class ContactAddressDto {
|
|||||||
@IsEmail()
|
@IsEmail()
|
||||||
billingAddressEmail?: string;
|
billingAddressEmail?: string;
|
||||||
|
|
||||||
@ApiProperty({ required: false, description: 'Billing address postcode' })
|
@ApiProperty({ required: false, description: 'Billing address zipcode' })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
billingAddressPostcode?: string;
|
billingAddressZipcode?: string;
|
||||||
|
|
||||||
@ApiProperty({ required: false, description: 'Billing address phone' })
|
@ApiProperty({ required: false, description: 'Billing address phone' })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@@ -67,10 +67,10 @@ export class ContactAddressDto {
|
|||||||
@IsEmail()
|
@IsEmail()
|
||||||
shippingAddressEmail?: string;
|
shippingAddressEmail?: string;
|
||||||
|
|
||||||
@ApiProperty({ required: false, description: 'Shipping address postcode' })
|
@ApiProperty({ required: false, description: 'Shipping address zipcode' })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
shippingAddressPostcode?: string;
|
shippingAddressZipcode?: string;
|
||||||
|
|
||||||
@ApiProperty({ required: false, description: 'Shipping address phone' })
|
@ApiProperty({ required: false, description: 'Shipping address phone' })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import {
|
|||||||
Post,
|
Post,
|
||||||
Put,
|
Put,
|
||||||
Query,
|
Query,
|
||||||
UseGuards,
|
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { ExpensesApplication } from './ExpensesApplication.service';
|
import { ExpensesApplication } from './ExpensesApplication.service';
|
||||||
import { IExpensesFilter } from './Expenses.types';
|
import { IExpensesFilter } from './Expenses.types';
|
||||||
@@ -26,11 +25,6 @@ import {
|
|||||||
BulkDeleteDto,
|
BulkDeleteDto,
|
||||||
ValidateBulkDeleteResponseDto,
|
ValidateBulkDeleteResponseDto,
|
||||||
} from '@/common/dtos/BulkDelete.dto';
|
} from '@/common/dtos/BulkDelete.dto';
|
||||||
import { RequirePermission } from '@/modules/Roles/RequirePermission.decorator';
|
|
||||||
import { PermissionGuard } from '@/modules/Roles/Permission.guard';
|
|
||||||
import { AuthorizationGuard } from '@/modules/Roles/Authorization.guard';
|
|
||||||
import { AbilitySubject } from '@/modules/Roles/Roles.types';
|
|
||||||
import { ExpenseAction } from './Expenses.types';
|
|
||||||
|
|
||||||
@Controller('expenses')
|
@Controller('expenses')
|
||||||
@ApiTags('Expenses')
|
@ApiTags('Expenses')
|
||||||
@@ -40,12 +34,10 @@ import { ExpenseAction } from './Expenses.types';
|
|||||||
ValidateBulkDeleteResponseDto,
|
ValidateBulkDeleteResponseDto,
|
||||||
)
|
)
|
||||||
@ApiCommonHeaders()
|
@ApiCommonHeaders()
|
||||||
@UseGuards(AuthorizationGuard, PermissionGuard)
|
|
||||||
export class ExpensesController {
|
export class ExpensesController {
|
||||||
constructor(private readonly expensesApplication: ExpensesApplication) { }
|
constructor(private readonly expensesApplication: ExpensesApplication) { }
|
||||||
|
|
||||||
@Post('validate-bulk-delete')
|
@Post('validate-bulk-delete')
|
||||||
@RequirePermission(ExpenseAction.Delete, AbilitySubject.Expense)
|
|
||||||
@ApiOperation({
|
@ApiOperation({
|
||||||
summary: 'Validate which expenses can be deleted and return the results.',
|
summary: 'Validate which expenses can be deleted and return the results.',
|
||||||
})
|
})
|
||||||
@@ -66,7 +58,6 @@ export class ExpensesController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Post('bulk-delete')
|
@Post('bulk-delete')
|
||||||
@RequirePermission(ExpenseAction.Delete, AbilitySubject.Expense)
|
|
||||||
@ApiOperation({ summary: 'Deletes multiple expenses.' })
|
@ApiOperation({ summary: 'Deletes multiple expenses.' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
@@ -85,7 +76,6 @@ export class ExpensesController {
|
|||||||
* @param {IExpenseCreateDTO} expenseDTO
|
* @param {IExpenseCreateDTO} expenseDTO
|
||||||
*/
|
*/
|
||||||
@Post()
|
@Post()
|
||||||
@RequirePermission(ExpenseAction.Create, AbilitySubject.Expense)
|
|
||||||
@ApiOperation({ summary: 'Create a new expense transaction.' })
|
@ApiOperation({ summary: 'Create a new expense transaction.' })
|
||||||
public createExpense(@Body() expenseDTO: CreateExpenseDto) {
|
public createExpense(@Body() expenseDTO: CreateExpenseDto) {
|
||||||
return this.expensesApplication.createExpense(expenseDTO);
|
return this.expensesApplication.createExpense(expenseDTO);
|
||||||
@@ -97,7 +87,6 @@ export class ExpensesController {
|
|||||||
* @param {IExpenseEditDTO} expenseDTO
|
* @param {IExpenseEditDTO} expenseDTO
|
||||||
*/
|
*/
|
||||||
@Put(':id')
|
@Put(':id')
|
||||||
@RequirePermission(ExpenseAction.Edit, AbilitySubject.Expense)
|
|
||||||
@ApiOperation({ summary: 'Edit the given expense transaction.' })
|
@ApiOperation({ summary: 'Edit the given expense transaction.' })
|
||||||
public editExpense(
|
public editExpense(
|
||||||
@Param('id') expenseId: number,
|
@Param('id') expenseId: number,
|
||||||
@@ -111,7 +100,6 @@ export class ExpensesController {
|
|||||||
* @param {number} expenseId
|
* @param {number} expenseId
|
||||||
*/
|
*/
|
||||||
@Delete(':id')
|
@Delete(':id')
|
||||||
@RequirePermission(ExpenseAction.Delete, AbilitySubject.Expense)
|
|
||||||
@ApiOperation({ summary: 'Delete the given expense transaction.' })
|
@ApiOperation({ summary: 'Delete the given expense transaction.' })
|
||||||
public deleteExpense(@Param('id') expenseId: number) {
|
public deleteExpense(@Param('id') expenseId: number) {
|
||||||
return this.expensesApplication.deleteExpense(expenseId);
|
return this.expensesApplication.deleteExpense(expenseId);
|
||||||
@@ -122,7 +110,6 @@ export class ExpensesController {
|
|||||||
* @param {number} expenseId
|
* @param {number} expenseId
|
||||||
*/
|
*/
|
||||||
@Post(':id/publish')
|
@Post(':id/publish')
|
||||||
@RequirePermission(ExpenseAction.Edit, AbilitySubject.Expense)
|
|
||||||
@ApiOperation({ summary: 'Publish the given expense transaction.' })
|
@ApiOperation({ summary: 'Publish the given expense transaction.' })
|
||||||
public publishExpense(@Param('id') expenseId: number) {
|
public publishExpense(@Param('id') expenseId: number) {
|
||||||
return this.expensesApplication.publishExpense(expenseId);
|
return this.expensesApplication.publishExpense(expenseId);
|
||||||
@@ -132,7 +119,6 @@ export class ExpensesController {
|
|||||||
* Get the expense transaction details.
|
* Get the expense transaction details.
|
||||||
*/
|
*/
|
||||||
@Get()
|
@Get()
|
||||||
@RequirePermission(ExpenseAction.View, AbilitySubject.Expense)
|
|
||||||
@ApiOperation({ summary: 'Get the expense transactions.' })
|
@ApiOperation({ summary: 'Get the expense transactions.' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
@@ -160,7 +146,6 @@ export class ExpensesController {
|
|||||||
* @param {number} expenseId
|
* @param {number} expenseId
|
||||||
*/
|
*/
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
@RequirePermission(ExpenseAction.View, AbilitySubject.Expense)
|
|
||||||
@ApiOperation({ summary: 'Get the expense transaction details.' })
|
@ApiOperation({ summary: 'Get the expense transaction details.' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ export class FinancialSheet {
|
|||||||
negativeFormat: 'mines',
|
negativeFormat: 'mines',
|
||||||
};
|
};
|
||||||
public baseCurrency: string;
|
public baseCurrency: string;
|
||||||
public dateFormat: string = 'YYYY MMM DD';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transformes the number format query to settings
|
* Transformes the number format query to settings
|
||||||
@@ -141,10 +140,9 @@ export class FinancialSheet {
|
|||||||
* @param {string} format
|
* @param {string} format
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
protected getDateMeta(date: moment.MomentInput, format?: string) {
|
protected getDateMeta(date: moment.MomentInput, format = 'YYYY-MM-DD') {
|
||||||
const dateFormat = format || this.dateFormat || 'YYYY MMM DD';
|
|
||||||
return {
|
return {
|
||||||
formattedDate: moment(date).format(dateFormat),
|
formattedDate: moment(date).format(format),
|
||||||
date: moment(date).toDate(),
|
date: moment(date).toDate(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { Controller, Get, Headers, Query, Res, UseGuards } from '@nestjs/common';
|
import { Controller, Get, Headers, Query, Res } from '@nestjs/common';
|
||||||
import { APAgingSummaryApplication } from './APAgingSummaryApplication';
|
import { APAgingSummaryApplication } from './APAgingSummaryApplication';
|
||||||
import { AcceptType } from '@/constants/accept-type';
|
import { AcceptType } from '@/constants/accept-type';
|
||||||
import {
|
import {
|
||||||
@@ -11,21 +11,14 @@ import {
|
|||||||
import { APAgingSummaryQueryDto } from './APAgingSummaryQuery.dto';
|
import { APAgingSummaryQueryDto } from './APAgingSummaryQuery.dto';
|
||||||
import { APAgingSummaryResponseExample } from './APAgingSummary.swagger';
|
import { APAgingSummaryResponseExample } from './APAgingSummary.swagger';
|
||||||
import { ApiCommonHeaders } from '@/common/decorators/ApiCommonHeaders';
|
import { ApiCommonHeaders } from '@/common/decorators/ApiCommonHeaders';
|
||||||
import { RequirePermission } from '@/modules/Roles/RequirePermission.decorator';
|
|
||||||
import { PermissionGuard } from '@/modules/Roles/Permission.guard';
|
|
||||||
import { AuthorizationGuard } from '@/modules/Roles/Authorization.guard';
|
|
||||||
import { AbilitySubject } from '@/modules/Roles/Roles.types';
|
|
||||||
import { ReportsAction } from '../../types/Report.types';
|
|
||||||
|
|
||||||
@Controller('reports/payable-aging-summary')
|
@Controller('reports/payable-aging-summary')
|
||||||
@ApiTags('Reports')
|
@ApiTags('Reports')
|
||||||
@ApiCommonHeaders()
|
@ApiCommonHeaders()
|
||||||
@UseGuards(AuthorizationGuard, PermissionGuard)
|
|
||||||
export class APAgingSummaryController {
|
export class APAgingSummaryController {
|
||||||
constructor(private readonly APAgingSummaryApp: APAgingSummaryApplication) { }
|
constructor(private readonly APAgingSummaryApp: APAgingSummaryApplication) { }
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
@RequirePermission(ReportsAction.READ_AP_AGING_SUMMARY, AbilitySubject.Report)
|
|
||||||
@ApiOperation({ summary: 'Get payable aging summary' })
|
@ApiOperation({ summary: 'Get payable aging summary' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
|
|||||||
@@ -32,19 +32,18 @@ export class APAgingSummaryService {
|
|||||||
this.APAgingSummaryRepository.setFilter(filter);
|
this.APAgingSummaryRepository.setFilter(filter);
|
||||||
await this.APAgingSummaryRepository.load();
|
await this.APAgingSummaryRepository.load();
|
||||||
|
|
||||||
// Retrieve the aging summary report meta first to get date format.
|
|
||||||
const meta = await this.APAgingSummaryMeta.meta(filter);
|
|
||||||
|
|
||||||
// A/P aging summary report instance.
|
// A/P aging summary report instance.
|
||||||
const APAgingSummaryReport = new APAgingSummarySheet(
|
const APAgingSummaryReport = new APAgingSummarySheet(
|
||||||
filter,
|
filter,
|
||||||
this.APAgingSummaryRepository,
|
this.APAgingSummaryRepository,
|
||||||
{ baseCurrency: meta.baseCurrency, dateFormat: meta.dateFormat },
|
|
||||||
);
|
);
|
||||||
// A/P aging summary report data and columns.
|
// A/P aging summary report data and columns.
|
||||||
const data = APAgingSummaryReport.reportData();
|
const data = APAgingSummaryReport.reportData();
|
||||||
const columns = APAgingSummaryReport.reportColumns();
|
const columns = APAgingSummaryReport.reportColumns();
|
||||||
|
|
||||||
|
// Retrieve the aging summary report meta.
|
||||||
|
const meta = await this.APAgingSummaryMeta.meta(filter);
|
||||||
|
|
||||||
// Triggers `onPayableAgingViewed` event.
|
// Triggers `onPayableAgingViewed` event.
|
||||||
await this.eventPublisher.emitAsync(events.reports.onPayableAgingViewed, {
|
await this.eventPublisher.emitAsync(events.reports.onPayableAgingViewed, {
|
||||||
query,
|
query,
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import { allPassedConditionsPass } from '@/utils/all-conditions-passed';
|
|||||||
import { APAgingSummaryRepository } from './APAgingSummaryRepository';
|
import { APAgingSummaryRepository } from './APAgingSummaryRepository';
|
||||||
import { Bill } from '@/modules/Bills/models/Bill';
|
import { Bill } from '@/modules/Bills/models/Bill';
|
||||||
import { APAgingSummaryQueryDto } from './APAgingSummaryQuery.dto';
|
import { APAgingSummaryQueryDto } from './APAgingSummaryQuery.dto';
|
||||||
import { IFinancialReportMeta, DEFAULT_REPORT_META } from '../../types/Report.types';
|
|
||||||
|
|
||||||
export class APAgingSummarySheet extends AgingSummaryReport {
|
export class APAgingSummarySheet extends AgingSummaryReport {
|
||||||
readonly repository: APAgingSummaryRepository;
|
readonly repository: APAgingSummaryRepository;
|
||||||
@@ -32,14 +31,12 @@ export class APAgingSummarySheet extends AgingSummaryReport {
|
|||||||
constructor(
|
constructor(
|
||||||
query: APAgingSummaryQueryDto,
|
query: APAgingSummaryQueryDto,
|
||||||
repository: APAgingSummaryRepository,
|
repository: APAgingSummaryRepository,
|
||||||
meta: IFinancialReportMeta,
|
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.query = query;
|
this.query = query;
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
this.numberFormat = this.query.numberFormat;
|
this.numberFormat = this.query.numberFormat;
|
||||||
this.dateFormat = meta.dateFormat || DEFAULT_REPORT_META.dateFormat;
|
|
||||||
|
|
||||||
this.overdueInvoicesByContactId = this.repository.overdueBillsByVendorId;
|
this.overdueInvoicesByContactId = this.repository.overdueBillsByVendorId;
|
||||||
this.currentInvoicesByContactId = this.repository.dueBillsByVendorId;
|
this.currentInvoicesByContactId = this.repository.dueBillsByVendorId;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Controller, Get, Headers, Query, Res, UseGuards } from '@nestjs/common';
|
import { Controller, Get, Headers } from '@nestjs/common';
|
||||||
|
import { Query, Res } from '@nestjs/common';
|
||||||
import { ARAgingSummaryApplication } from './ARAgingSummaryApplication';
|
import { ARAgingSummaryApplication } from './ARAgingSummaryApplication';
|
||||||
import { AcceptType } from '@/constants/accept-type';
|
import { AcceptType } from '@/constants/accept-type';
|
||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
@@ -11,21 +12,14 @@ import {
|
|||||||
import { ARAgingSummaryQueryDto } from './ARAgingSummaryQuery.dto';
|
import { ARAgingSummaryQueryDto } from './ARAgingSummaryQuery.dto';
|
||||||
import { ARAgingSummaryResponseExample } from './ARAgingSummary.swagger';
|
import { ARAgingSummaryResponseExample } from './ARAgingSummary.swagger';
|
||||||
import { ApiCommonHeaders } from '@/common/decorators/ApiCommonHeaders';
|
import { ApiCommonHeaders } from '@/common/decorators/ApiCommonHeaders';
|
||||||
import { RequirePermission } from '@/modules/Roles/RequirePermission.decorator';
|
|
||||||
import { PermissionGuard } from '@/modules/Roles/Permission.guard';
|
|
||||||
import { AuthorizationGuard } from '@/modules/Roles/Authorization.guard';
|
|
||||||
import { AbilitySubject } from '@/modules/Roles/Roles.types';
|
|
||||||
import { ReportsAction } from '../../types/Report.types';
|
|
||||||
|
|
||||||
@Controller('reports/receivable-aging-summary')
|
@Controller('reports/receivable-aging-summary')
|
||||||
@ApiTags('Reports')
|
@ApiTags('Reports')
|
||||||
@ApiCommonHeaders()
|
@ApiCommonHeaders()
|
||||||
@UseGuards(AuthorizationGuard, PermissionGuard)
|
|
||||||
export class ARAgingSummaryController {
|
export class ARAgingSummaryController {
|
||||||
constructor(private readonly ARAgingSummaryApp: ARAgingSummaryApplication) {}
|
constructor(private readonly ARAgingSummaryApp: ARAgingSummaryApplication) {}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
@RequirePermission(ReportsAction.READ_AR_AGING_SUMMARY, AbilitySubject.Report)
|
|
||||||
@ApiOperation({ summary: 'Get receivable aging summary' })
|
@ApiOperation({ summary: 'Get receivable aging summary' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
|
|||||||
@@ -28,19 +28,18 @@ export class ARAgingSummaryService {
|
|||||||
this.ARAgingSummaryRepository.setFilter(filter);
|
this.ARAgingSummaryRepository.setFilter(filter);
|
||||||
await this.ARAgingSummaryRepository.load();
|
await this.ARAgingSummaryRepository.load();
|
||||||
|
|
||||||
// Retrieve the aging summary report meta first to get date format.
|
|
||||||
const meta = await this.ARAgingSummaryMeta.meta(filter);
|
|
||||||
|
|
||||||
// A/R aging summary report instance.
|
// A/R aging summary report instance.
|
||||||
const ARAgingSummaryReport = new ARAgingSummarySheet(
|
const ARAgingSummaryReport = new ARAgingSummarySheet(
|
||||||
filter,
|
filter,
|
||||||
this.ARAgingSummaryRepository,
|
this.ARAgingSummaryRepository,
|
||||||
{ baseCurrency: meta.baseCurrency, dateFormat: meta.dateFormat },
|
|
||||||
);
|
);
|
||||||
// A/R aging summary report data and columns.
|
// A/R aging summary report data and columns.
|
||||||
const data = ARAgingSummaryReport.reportData();
|
const data = ARAgingSummaryReport.reportData();
|
||||||
const columns = ARAgingSummaryReport.reportColumns();
|
const columns = ARAgingSummaryReport.reportColumns();
|
||||||
|
|
||||||
|
// Retrieve the aging summary report meta.
|
||||||
|
const meta = await this.ARAgingSummaryMeta.meta(filter);
|
||||||
|
|
||||||
// Triggers `onReceivableAgingViewed` event.
|
// Triggers `onReceivableAgingViewed` event.
|
||||||
await this.eventPublisher.emitAsync(
|
await this.eventPublisher.emitAsync(
|
||||||
events.reports.onReceivableAgingViewed,
|
events.reports.onReceivableAgingViewed,
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import { ARAgingSummaryRepository } from './ARAgingSummaryRepository';
|
|||||||
import { Customer } from '@/modules/Customers/models/Customer';
|
import { Customer } from '@/modules/Customers/models/Customer';
|
||||||
import { SaleInvoice } from '@/modules/SaleInvoices/models/SaleInvoice';
|
import { SaleInvoice } from '@/modules/SaleInvoices/models/SaleInvoice';
|
||||||
import { ARAgingSummaryQueryDto } from './ARAgingSummaryQuery.dto';
|
import { ARAgingSummaryQueryDto } from './ARAgingSummaryQuery.dto';
|
||||||
import { IFinancialReportMeta, DEFAULT_REPORT_META } from '../../types/Report.types';
|
|
||||||
|
|
||||||
export class ARAgingSummarySheet extends AgingSummaryReport {
|
export class ARAgingSummarySheet extends AgingSummaryReport {
|
||||||
readonly query: ARAgingSummaryQueryDto;
|
readonly query: ARAgingSummaryQueryDto;
|
||||||
@@ -33,19 +32,16 @@ export class ARAgingSummarySheet extends AgingSummaryReport {
|
|||||||
* Constructor method.
|
* Constructor method.
|
||||||
* @param {ARAgingSummaryQueryDto} query - Query
|
* @param {ARAgingSummaryQueryDto} query - Query
|
||||||
* @param {ARAgingSummaryRepository} repository - Repository.
|
* @param {ARAgingSummaryRepository} repository - Repository.
|
||||||
* @param {IFinancialReportMeta} meta - Report meta.
|
|
||||||
*/
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
query: ARAgingSummaryQueryDto,
|
query: ARAgingSummaryQueryDto,
|
||||||
repository: ARAgingSummaryRepository,
|
repository: ARAgingSummaryRepository,
|
||||||
meta: IFinancialReportMeta,
|
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.query = query;
|
this.query = query;
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
this.numberFormat = this.query.numberFormat;
|
this.numberFormat = this.query.numberFormat;
|
||||||
this.dateFormat = meta.dateFormat || DEFAULT_REPORT_META.dateFormat;
|
|
||||||
|
|
||||||
this.overdueInvoicesByContactId =
|
this.overdueInvoicesByContactId =
|
||||||
this.repository.overdueInvoicesByContactId;
|
this.repository.overdueInvoicesByContactId;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export class AgingSummaryMeta {
|
|||||||
*/
|
*/
|
||||||
public async meta(query: IAgingSummaryQuery): Promise<IAgingSummaryMeta> {
|
public async meta(query: IAgingSummaryQuery): Promise<IAgingSummaryMeta> {
|
||||||
const commonMeta = await this.financialSheetMeta.meta();
|
const commonMeta = await this.financialSheetMeta.meta();
|
||||||
const formattedAsDate = moment(query.asDate).format(commonMeta.dateFormat);
|
const formattedAsDate = moment(query.asDate).format('YYYY/MM/DD');
|
||||||
const formattedDateRange = `As ${formattedAsDate}`;
|
const formattedDateRange = `As ${formattedAsDate}`;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { Controller, Get, Headers, Query, Res, UseGuards } from '@nestjs/common';
|
import { Controller, Get, Headers, Query, Res } from '@nestjs/common';
|
||||||
import { AcceptType } from '@/constants/accept-type';
|
import { AcceptType } from '@/constants/accept-type';
|
||||||
import { BalanceSheetApplication } from './BalanceSheetApplication';
|
import { BalanceSheetApplication } from './BalanceSheetApplication';
|
||||||
import {
|
import {
|
||||||
@@ -11,16 +11,10 @@ import {
|
|||||||
import { BalanceSheetQueryDto } from './BalanceSheet.dto';
|
import { BalanceSheetQueryDto } from './BalanceSheet.dto';
|
||||||
import { BalanceSheetResponseExample } from './BalanceSheet.swagger';
|
import { BalanceSheetResponseExample } from './BalanceSheet.swagger';
|
||||||
import { ApiCommonHeaders } from '@/common/decorators/ApiCommonHeaders';
|
import { ApiCommonHeaders } from '@/common/decorators/ApiCommonHeaders';
|
||||||
import { RequirePermission } from '@/modules/Roles/RequirePermission.decorator';
|
|
||||||
import { PermissionGuard } from '@/modules/Roles/Permission.guard';
|
|
||||||
import { AuthorizationGuard } from '@/modules/Roles/Authorization.guard';
|
|
||||||
import { AbilitySubject } from '@/modules/Roles/Roles.types';
|
|
||||||
import { ReportsAction } from '../../types/Report.types';
|
|
||||||
|
|
||||||
@Controller('/reports/balance-sheet')
|
@Controller('/reports/balance-sheet')
|
||||||
@ApiTags('Reports')
|
@ApiTags('Reports')
|
||||||
@ApiCommonHeaders()
|
@ApiCommonHeaders()
|
||||||
@UseGuards(AuthorizationGuard, PermissionGuard)
|
|
||||||
export class BalanceSheetStatementController {
|
export class BalanceSheetStatementController {
|
||||||
constructor(private readonly balanceSheetApp: BalanceSheetApplication) {}
|
constructor(private readonly balanceSheetApp: BalanceSheetApplication) {}
|
||||||
|
|
||||||
@@ -31,7 +25,6 @@ export class BalanceSheetStatementController {
|
|||||||
* @param {string} acceptHeader - Accept header.
|
* @param {string} acceptHeader - Accept header.
|
||||||
*/
|
*/
|
||||||
@Get('')
|
@Get('')
|
||||||
@RequirePermission(ReportsAction.READ_BALANCE_SHEET, AbilitySubject.Report)
|
|
||||||
@ApiOperation({ summary: 'Get balance sheet statement' })
|
@ApiOperation({ summary: 'Get balance sheet statement' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
|
|||||||
@@ -24,14 +24,14 @@ export class BalanceSheetQueryDto extends FinancialSheetBranchesQueryDto {
|
|||||||
displayColumnsType: 'total' | 'date_periods' = 'total';
|
displayColumnsType: 'total' | 'date_periods' = 'total';
|
||||||
|
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
enum: ['day', 'month', 'year', 'quarter'],
|
enum: ['day', 'month', 'year'],
|
||||||
default: 'year',
|
default: 'year',
|
||||||
description: 'Time period for column display',
|
description: 'Time period for column display',
|
||||||
})
|
})
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsEnum(['day', 'month', 'year', 'quarter'])
|
@IsEnum(['day', 'month', 'year'])
|
||||||
displayColumnsBy: 'day' | 'month' | 'year' | 'quarter' = 'year';
|
displayColumnsBy: 'day' | 'month' | 'year' = 'year';
|
||||||
|
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
description: 'Start date for the balance sheet period',
|
description: 'Start date for the balance sheet period',
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import { BalanceSheetFiltering } from './BalanceSheetFiltering';
|
|||||||
import { BalanceSheetNetIncome } from './BalanceSheetNetIncome';
|
import { BalanceSheetNetIncome } from './BalanceSheetNetIncome';
|
||||||
import { BalanceSheetAggregators } from './BalanceSheetAggregators';
|
import { BalanceSheetAggregators } from './BalanceSheetAggregators';
|
||||||
import { BalanceSheetAccounts } from './BalanceSheetAccounts';
|
import { BalanceSheetAccounts } from './BalanceSheetAccounts';
|
||||||
import { INumberFormatQuery, IFinancialReportMeta, DEFAULT_REPORT_META } from '../../types/Report.types';
|
import { INumberFormatQuery } from '../../types/Report.types';
|
||||||
import { FinancialSheet } from '../../common/FinancialSheet';
|
import { FinancialSheet } from '../../common/FinancialSheet';
|
||||||
|
|
||||||
export class BalanceSheet extends R.pipe(
|
export class BalanceSheet extends R.pipe(
|
||||||
@@ -66,23 +66,21 @@ export class BalanceSheet extends R.pipe(
|
|||||||
/**
|
/**
|
||||||
* Constructor method.
|
* Constructor method.
|
||||||
* @param {IBalanceSheetQuery} query -
|
* @param {IBalanceSheetQuery} query -
|
||||||
* @param {BalanceSheetRepository} repository -
|
* @param {IAccount[]} accounts -
|
||||||
* @param {I18nService} i18n -
|
* @param {string} baseCurrency -
|
||||||
* @param {IFinancialReportMeta} meta -
|
|
||||||
*/
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
query: IBalanceSheetQuery,
|
query: IBalanceSheetQuery,
|
||||||
repository: BalanceSheetRepository,
|
repository: BalanceSheetRepository,
|
||||||
|
baseCurrency: string,
|
||||||
i18n: I18nService,
|
i18n: I18nService,
|
||||||
meta: IFinancialReportMeta,
|
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.query = new BalanceSheetQuery(query);
|
this.query = new BalanceSheetQuery(query);
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
this.baseCurrency = meta.baseCurrency;
|
this.baseCurrency = baseCurrency;
|
||||||
this.numberFormat = this.query.query.numberFormat;
|
this.numberFormat = this.query.query.numberFormat;
|
||||||
this.dateFormat = meta.dateFormat || DEFAULT_REPORT_META.dateFormat;
|
|
||||||
this.i18n = i18n;
|
this.i18n = i18n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,19 +40,19 @@ export class BalanceSheetInjectable {
|
|||||||
// Loads all resources.
|
// Loads all resources.
|
||||||
await this.balanceSheetRepository.asyncInitialize(filter);
|
await this.balanceSheetRepository.asyncInitialize(filter);
|
||||||
|
|
||||||
// Balance sheet meta first to get date format.
|
|
||||||
const meta = await this.balanceSheetMeta.meta(filter);
|
|
||||||
|
|
||||||
// Balance sheet report instance.
|
// Balance sheet report instance.
|
||||||
const balanceSheetInstanace = new BalanceSheet(
|
const balanceSheetInstanace = new BalanceSheet(
|
||||||
filter,
|
filter,
|
||||||
this.balanceSheetRepository,
|
this.balanceSheetRepository,
|
||||||
|
tenantMetadata.baseCurrency,
|
||||||
this.i18n,
|
this.i18n,
|
||||||
{ baseCurrency: tenantMetadata.baseCurrency, dateFormat: meta.dateFormat },
|
|
||||||
);
|
);
|
||||||
// Balance sheet data.
|
// Balance sheet data.
|
||||||
const data = balanceSheetInstanace.reportData();
|
const data = balanceSheetInstanace.reportData();
|
||||||
|
|
||||||
|
// Balance sheet meta.
|
||||||
|
const meta = await this.balanceSheetMeta.meta(filter);
|
||||||
|
|
||||||
// Triggers `onBalanceSheetViewed` event.
|
// Triggers `onBalanceSheetViewed` event.
|
||||||
await this.eventPublisher.emitAsync(events.reports.onBalanceSheetViewed, {
|
await this.eventPublisher.emitAsync(events.reports.onBalanceSheetViewed, {
|
||||||
query,
|
query,
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export class BalanceSheetMetaInjectable {
|
|||||||
*/
|
*/
|
||||||
public async meta(query: IBalanceSheetQuery): Promise<IBalanceSheetMeta> {
|
public async meta(query: IBalanceSheetQuery): Promise<IBalanceSheetMeta> {
|
||||||
const commonMeta = await this.financialSheetMeta.meta();
|
const commonMeta = await this.financialSheetMeta.meta();
|
||||||
const formattedAsDate = moment(query.toDate).format(commonMeta.dateFormat);
|
const formattedAsDate = moment(query.toDate).format('YYYY/MM/DD');
|
||||||
const formattedDateRange = `As ${formattedAsDate}`;
|
const formattedDateRange = `As ${formattedAsDate}`;
|
||||||
const sheetName = 'Balance Sheet Statement';
|
const sheetName = 'Balance Sheet Statement';
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import { DISPLAY_COLUMNS_BY } from './constants';
|
|||||||
import { FinancialSheetStructure } from '../../common/FinancialSheetStructure';
|
import { FinancialSheetStructure } from '../../common/FinancialSheetStructure';
|
||||||
import { Account } from '@/modules/Accounts/models/Account.model';
|
import { Account } from '@/modules/Accounts/models/Account.model';
|
||||||
import { ILedger } from '@/modules/Ledger/types/Ledger.types';
|
import { ILedger } from '@/modules/Ledger/types/Ledger.types';
|
||||||
import { INumberFormatQuery, IFinancialReportMeta, DEFAULT_REPORT_META } from '../../types/Report.types';
|
import { INumberFormatQuery } from '../../types/Report.types';
|
||||||
import { transformToMapBy } from '@/utils/transform-to-map-by';
|
import { transformToMapBy } from '@/utils/transform-to-map-by';
|
||||||
import { accumSum } from '@/utils/accum-sum';
|
import { accumSum } from '@/utils/accum-sum';
|
||||||
import { ModelObject } from 'objection';
|
import { ModelObject } from 'objection';
|
||||||
@@ -62,12 +62,12 @@ export class CashFlowStatement extends R.pipe(
|
|||||||
cashLedger: ILedger,
|
cashLedger: ILedger,
|
||||||
netIncomeLedger: ILedger,
|
netIncomeLedger: ILedger,
|
||||||
query: ICashFlowStatementQuery,
|
query: ICashFlowStatementQuery,
|
||||||
|
baseCurrency: string,
|
||||||
i18n: I18nService,
|
i18n: I18nService,
|
||||||
meta: IFinancialReportMeta,
|
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.baseCurrency = meta.baseCurrency;
|
this.baseCurrency = baseCurrency;
|
||||||
this.i18n = i18n;
|
this.i18n = i18n;
|
||||||
this.ledger = ledger;
|
this.ledger = ledger;
|
||||||
this.cashLedger = cashLedger;
|
this.cashLedger = cashLedger;
|
||||||
@@ -76,7 +76,6 @@ export class CashFlowStatement extends R.pipe(
|
|||||||
this.accountsByRootType = transformToMapBy(accounts, 'accountRootType');
|
this.accountsByRootType = transformToMapBy(accounts, 'accountRootType');
|
||||||
this.query = query;
|
this.query = query;
|
||||||
this.numberFormat = this.query.numberFormat;
|
this.numberFormat = this.query.numberFormat;
|
||||||
this.dateFormat = meta.dateFormat || DEFAULT_REPORT_META.dateFormat;
|
|
||||||
this.dateRangeSet = [];
|
this.dateRangeSet = [];
|
||||||
this.comparatorDateType =
|
this.comparatorDateType =
|
||||||
query.displayColumnsType === 'total' ? 'day' : query.displayColumnsBy;
|
query.displayColumnsType === 'total' ? 'day' : query.displayColumnsBy;
|
||||||
|
|||||||
@@ -85,9 +85,6 @@ export class CashFlowStatementService {
|
|||||||
const cashLedger = Ledger.fromTransactions(cashAtBeginningTransactions);
|
const cashLedger = Ledger.fromTransactions(cashAtBeginningTransactions);
|
||||||
const netIncomeLedger = Ledger.fromTransactions(netIncome);
|
const netIncomeLedger = Ledger.fromTransactions(netIncome);
|
||||||
|
|
||||||
// Retrieve the cashflow sheet meta first to get date format.
|
|
||||||
const meta = await this.cashflowSheetMeta.meta(filter);
|
|
||||||
|
|
||||||
// Cash flow statement.
|
// Cash flow statement.
|
||||||
const cashFlowInstance = new CashFlowStatement(
|
const cashFlowInstance = new CashFlowStatement(
|
||||||
accounts,
|
accounts,
|
||||||
@@ -95,9 +92,11 @@ export class CashFlowStatementService {
|
|||||||
cashLedger,
|
cashLedger,
|
||||||
netIncomeLedger,
|
netIncomeLedger,
|
||||||
filter,
|
filter,
|
||||||
|
tenant.metadata.baseCurrency,
|
||||||
this.i18n,
|
this.i18n,
|
||||||
{ baseCurrency: tenant.metadata.baseCurrency, dateFormat: meta.dateFormat },
|
|
||||||
);
|
);
|
||||||
|
// Retrieve the cashflow sheet meta.
|
||||||
|
const meta = await this.cashflowSheetMeta.meta(filter);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
data: cashFlowInstance.reportData(),
|
data: cashFlowInstance.reportData(),
|
||||||
|
|||||||
@@ -34,13 +34,13 @@ export class CashFlowStatementQueryDto extends FinancialSheetBranchesQueryDto {
|
|||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
description: 'Display columns by time period',
|
description: 'Display columns by time period',
|
||||||
required: false,
|
required: false,
|
||||||
enum: ['day', 'month', 'year', 'quarter'],
|
enum: ['day', 'month', 'year'],
|
||||||
default: 'year',
|
default: 'year',
|
||||||
})
|
})
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsEnum(['day', 'month', 'year', 'quarter'])
|
@IsEnum(['day', 'month', 'year'])
|
||||||
displayColumnsBy: 'day' | 'month' | 'year' | 'quarter' = 'year';
|
displayColumnsBy: 'day' | 'month' | 'year' = 'year';
|
||||||
|
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
description: 'Type of column display',
|
description: 'Type of column display',
|
||||||
|
|||||||
@@ -239,7 +239,7 @@ export class CashFlowTable {
|
|||||||
section: ICashFlowStatementSection,
|
section: ICashFlowStatementSection,
|
||||||
): ICashFlowStatementSection => {
|
): ICashFlowStatementSection => {
|
||||||
const label = section.footerLabel
|
const label = section.footerLabel
|
||||||
? this.i18n.t(section.footerLabel)
|
? section.footerLabel
|
||||||
: this.i18n.t('financial_sheet.total_row', {
|
: this.i18n.t('financial_sheet.total_row', {
|
||||||
args: { value: section.label },
|
args: { value: section.label },
|
||||||
});
|
});
|
||||||
@@ -302,7 +302,7 @@ export class CashFlowTable {
|
|||||||
* @returns {ITableColumn}
|
* @returns {ITableColumn}
|
||||||
*/
|
*/
|
||||||
private totalColumns = (): ITableColumn[] => {
|
private totalColumns = (): ITableColumn[] => {
|
||||||
return [{ key: 'total', label: this.i18n.t('cash_flow_statement.total') }];
|
return [{ key: 'total', label: this.i18n.t('Total') }];
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -366,7 +366,7 @@ export class CashFlowTable {
|
|||||||
*/
|
*/
|
||||||
public tableColumns = (): ITableColumn[] => {
|
public tableColumns = (): ITableColumn[] => {
|
||||||
return R.compose(
|
return R.compose(
|
||||||
R.concat([{ key: 'name', label: this.i18n.t('cash_flow_statement.account_name') }]),
|
R.concat([{ key: 'name', label: this.i18n.t('Account name') }]),
|
||||||
R.when(
|
R.when(
|
||||||
R.always(this.isDisplayColumnsBy(DISPLAY_COLUMNS_BY.DATE_PERIODS)),
|
R.always(this.isDisplayColumnsBy(DISPLAY_COLUMNS_BY.DATE_PERIODS)),
|
||||||
R.concat(this.datePeriodsColumns()),
|
R.concat(this.datePeriodsColumns()),
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { Controller, Get, Headers, Query, Res, UseGuards } from '@nestjs/common';
|
import { Controller, Get, Headers, Query, Res } from '@nestjs/common';
|
||||||
import { AcceptType } from '@/constants/accept-type';
|
import { AcceptType } from '@/constants/accept-type';
|
||||||
import { CashflowSheetApplication } from './CashflowSheetApplication';
|
import { CashflowSheetApplication } from './CashflowSheetApplication';
|
||||||
import {
|
import {
|
||||||
@@ -11,21 +11,14 @@ import {
|
|||||||
import { CashFlowStatementQueryDto } from './CashFlowStatementQuery.dto';
|
import { CashFlowStatementQueryDto } from './CashFlowStatementQuery.dto';
|
||||||
import { CashflowStatementResponseExample } from './CashflowStatement.swagger';
|
import { CashflowStatementResponseExample } from './CashflowStatement.swagger';
|
||||||
import { ApiCommonHeaders } from '@/common/decorators/ApiCommonHeaders';
|
import { ApiCommonHeaders } from '@/common/decorators/ApiCommonHeaders';
|
||||||
import { RequirePermission } from '@/modules/Roles/RequirePermission.decorator';
|
|
||||||
import { PermissionGuard } from '@/modules/Roles/Permission.guard';
|
|
||||||
import { AuthorizationGuard } from '@/modules/Roles/Authorization.guard';
|
|
||||||
import { AbilitySubject } from '@/modules/Roles/Roles.types';
|
|
||||||
import { ReportsAction } from '../../types/Report.types';
|
|
||||||
|
|
||||||
@Controller('reports/cashflow-statement')
|
@Controller('reports/cashflow-statement')
|
||||||
@ApiTags('Reports')
|
@ApiTags('Reports')
|
||||||
@ApiCommonHeaders()
|
@ApiCommonHeaders()
|
||||||
@UseGuards(AuthorizationGuard, PermissionGuard)
|
|
||||||
export class CashflowController {
|
export class CashflowController {
|
||||||
constructor(private readonly cashflowSheetApp: CashflowSheetApplication) { }
|
constructor(private readonly cashflowSheetApp: CashflowSheetApplication) { }
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
@RequirePermission(ReportsAction.READ_CASHFLOW, AbilitySubject.Report)
|
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
description: 'Cashflow statement report',
|
description: 'Cashflow statement report',
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import * as moment from 'moment';
|
import * as moment from 'moment';
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { I18nService } from 'nestjs-i18n';
|
|
||||||
import { FinancialSheetMeta } from '../../common/FinancialSheetMeta';
|
import { FinancialSheetMeta } from '../../common/FinancialSheetMeta';
|
||||||
import {
|
import {
|
||||||
ICashFlowStatementMeta,
|
ICashFlowStatementMeta,
|
||||||
@@ -9,10 +8,7 @@ import {
|
|||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CashflowSheetMeta {
|
export class CashflowSheetMeta {
|
||||||
constructor(
|
constructor(private readonly financialSheetMeta: FinancialSheetMeta) {}
|
||||||
private readonly financialSheetMeta: FinancialSheetMeta,
|
|
||||||
private readonly i18n: I18nService,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cashflow sheet meta.
|
* Cashflow sheet meta.
|
||||||
@@ -23,13 +19,11 @@ export class CashflowSheetMeta {
|
|||||||
query: ICashFlowStatementQuery,
|
query: ICashFlowStatementQuery,
|
||||||
): Promise<ICashFlowStatementMeta> {
|
): Promise<ICashFlowStatementMeta> {
|
||||||
const meta = await this.financialSheetMeta.meta();
|
const meta = await this.financialSheetMeta.meta();
|
||||||
const formattedToDate = moment(query.toDate).format(meta.dateFormat);
|
const formattedToDate = moment(query.toDate).format('YYYY/MM/DD');
|
||||||
const formattedFromDate = moment(query.fromDate).format(meta.dateFormat);
|
const formattedFromDate = moment(query.fromDate).format('YYYY/MM/DD');
|
||||||
const fromLabel = this.i18n.t('cash_flow_statement.from_date');
|
const formattedDateRange = `From ${formattedFromDate} | To ${formattedToDate}`;
|
||||||
const toLabel = this.i18n.t('cash_flow_statement.to_date');
|
|
||||||
const formattedDateRange = `${fromLabel} ${formattedFromDate} | ${toLabel} ${formattedToDate}`;
|
|
||||||
|
|
||||||
const sheetName = this.i18n.t('cash_flow_statement.sheet_name');
|
const sheetName = 'Statement of Cash Flow';
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...meta,
|
...meta,
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
import { ContactBalanceSummaryReport } from '../ContactBalanceSummary/ContactBalanceSummary';
|
import { ContactBalanceSummaryReport } from '../ContactBalanceSummary/ContactBalanceSummary';
|
||||||
import { ILedger } from '@/modules/Ledger/types/Ledger.types';
|
import { ILedger } from '@/modules/Ledger/types/Ledger.types';
|
||||||
import { ModelObject } from 'objection';
|
import { ModelObject } from 'objection';
|
||||||
import { INumberFormatQuery, IFinancialReportMeta, DEFAULT_REPORT_META } from '../../types/Report.types';
|
import { INumberFormatQuery } from '../../types/Report.types';
|
||||||
import { Customer } from '@/modules/Customers/models/Customer';
|
import { Customer } from '@/modules/Customers/models/Customer';
|
||||||
|
|
||||||
export class CustomerBalanceSummaryReport extends ContactBalanceSummaryReport {
|
export class CustomerBalanceSummaryReport extends ContactBalanceSummaryReport {
|
||||||
@@ -23,22 +23,21 @@ export class CustomerBalanceSummaryReport extends ContactBalanceSummaryReport {
|
|||||||
* @param {IJournalPoster} receivableLedger
|
* @param {IJournalPoster} receivableLedger
|
||||||
* @param {ICustomer[]} customers
|
* @param {ICustomer[]} customers
|
||||||
* @param {ICustomerBalanceSummaryQuery} filter
|
* @param {ICustomerBalanceSummaryQuery} filter
|
||||||
* @param {IFinancialReportMeta} meta
|
* @param {string} baseCurrency
|
||||||
*/
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
ledger: ILedger,
|
ledger: ILedger,
|
||||||
customers: ModelObject<Customer>[],
|
customers: ModelObject<Customer>[],
|
||||||
filter: ICustomerBalanceSummaryQuery,
|
filter: ICustomerBalanceSummaryQuery,
|
||||||
meta: IFinancialReportMeta,
|
baseCurrency: string
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.ledger = ledger;
|
this.ledger = ledger;
|
||||||
this.baseCurrency = meta.baseCurrency;
|
this.baseCurrency = baseCurrency;
|
||||||
this.customers = customers;
|
this.customers = customers;
|
||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
this.numberFormat = this.filter.numberFormat;
|
this.numberFormat = this.filter.numberFormat;
|
||||||
this.dateFormat = meta.dateFormat || DEFAULT_REPORT_META.dateFormat;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export class CustomerBalanceSummaryMeta {
|
|||||||
query: ICustomerBalanceSummaryQuery,
|
query: ICustomerBalanceSummaryQuery,
|
||||||
): Promise<ICustomerBalanceSummaryMeta> {
|
): Promise<ICustomerBalanceSummaryMeta> {
|
||||||
const commonMeta = await this.financialSheetMeta.meta();
|
const commonMeta = await this.financialSheetMeta.meta();
|
||||||
const formattedAsDate = moment(query.asDate).format(commonMeta.dateFormat);
|
const formattedAsDate = moment(query.asDate).format('YYYY/MM/DD');
|
||||||
const formattedDateRange = `As ${formattedAsDate}`;
|
const formattedDateRange = `As ${formattedAsDate}`;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -63,16 +63,15 @@ export class CustomerBalanceSummaryService {
|
|||||||
// Ledger query.
|
// Ledger query.
|
||||||
const ledger = new Ledger(customersEntries);
|
const ledger = new Ledger(customersEntries);
|
||||||
|
|
||||||
// Retrieve the customer balance summary meta first to get date format.
|
|
||||||
const meta = await this.customerBalanceSummaryMeta.meta(filter);
|
|
||||||
|
|
||||||
// Report instance.
|
// Report instance.
|
||||||
const report = new CustomerBalanceSummaryReport(
|
const report = new CustomerBalanceSummaryReport(
|
||||||
ledger,
|
ledger,
|
||||||
customers,
|
customers,
|
||||||
filter,
|
filter,
|
||||||
{ baseCurrency: tenantMetadata.baseCurrency, dateFormat: meta.dateFormat },
|
tenantMetadata.baseCurrency,
|
||||||
);
|
);
|
||||||
|
// Retrieve the customer balance summary meta.
|
||||||
|
const meta = await this.customerBalanceSummaryMeta.meta(filter);
|
||||||
|
|
||||||
// Triggers `onCustomerBalanceSummaryViewed` event.
|
// Triggers `onCustomerBalanceSummaryViewed` event.
|
||||||
await this.eventPublisher.emitAsync(
|
await this.eventPublisher.emitAsync(
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ export class CustomerBalanceSummaryTable {
|
|||||||
*/
|
*/
|
||||||
private getTotalColumnsAccessor = (): IColumnMapperMeta[] => {
|
private getTotalColumnsAccessor = (): IColumnMapperMeta[] => {
|
||||||
const columns = [
|
const columns = [
|
||||||
{ key: 'name', value: this.i18n.t('contact_summary_balance.total') },
|
{ key: 'name', value: this.i18n.t('Total') },
|
||||||
{ key: 'total', accessor: 'total.formattedAmount' },
|
{ key: 'total', accessor: 'total.formattedAmount' },
|
||||||
];
|
];
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
|||||||
@@ -5,29 +5,22 @@ import {
|
|||||||
ApiTags,
|
ApiTags,
|
||||||
} from '@nestjs/swagger';
|
} from '@nestjs/swagger';
|
||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { Controller, Get, Headers, Query, Res, UseGuards } from '@nestjs/common';
|
import { Controller, Get, Headers, Query, Res } from '@nestjs/common';
|
||||||
import { GeneralLedgerApplication } from './GeneralLedgerApplication';
|
import { GeneralLedgerApplication } from './GeneralLedgerApplication';
|
||||||
import { AcceptType } from '@/constants/accept-type';
|
import { AcceptType } from '@/constants/accept-type';
|
||||||
import { GeneralLedgerQueryDto } from './GeneralLedgerQuery.dto';
|
import { GeneralLedgerQueryDto } from './GeneralLedgerQuery.dto';
|
||||||
import { GeneralLedgerResponseExample } from './GeneralLedger.swagger';
|
import { GeneralLedgerResponseExample } from './GeneralLedger.swagger';
|
||||||
import { ApiCommonHeaders } from '@/common/decorators/ApiCommonHeaders';
|
import { ApiCommonHeaders } from '@/common/decorators/ApiCommonHeaders';
|
||||||
import { RequirePermission } from '@/modules/Roles/RequirePermission.decorator';
|
|
||||||
import { PermissionGuard } from '@/modules/Roles/Permission.guard';
|
|
||||||
import { AuthorizationGuard } from '@/modules/Roles/Authorization.guard';
|
|
||||||
import { AbilitySubject } from '@/modules/Roles/Roles.types';
|
|
||||||
import { ReportsAction } from '../../types/Report.types';
|
|
||||||
|
|
||||||
@Controller('/reports/general-ledger')
|
@Controller('/reports/general-ledger')
|
||||||
@ApiTags('Reports')
|
@ApiTags('Reports')
|
||||||
@ApiCommonHeaders()
|
@ApiCommonHeaders()
|
||||||
@UseGuards(AuthorizationGuard, PermissionGuard)
|
|
||||||
export class GeneralLedgerController {
|
export class GeneralLedgerController {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly generalLedgerApplication: GeneralLedgerApplication,
|
private readonly generalLedgerApplication: GeneralLedgerApplication,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
@RequirePermission(ReportsAction.READ_GENERAL_LEDGET, AbilitySubject.Report)
|
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
description: 'General ledger report',
|
description: 'General ledger report',
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ import { Account } from '@/modules/Accounts/models/Account.model';
|
|||||||
import { ModelObject } from 'objection';
|
import { ModelObject } from 'objection';
|
||||||
import { flatToNestedArray } from '@/utils/flat-to-nested-array';
|
import { flatToNestedArray } from '@/utils/flat-to-nested-array';
|
||||||
import { getTransactionTypeLabel } from '@/modules/BankingTransactions/utils';
|
import { getTransactionTypeLabel } from '@/modules/BankingTransactions/utils';
|
||||||
import { IFinancialReportMeta, DEFAULT_REPORT_META } from '../../types/Report.types';
|
|
||||||
|
|
||||||
export class GeneralLedgerSheet extends R.compose(FinancialSheetStructure)(
|
export class GeneralLedgerSheet extends R.compose(FinancialSheetStructure)(
|
||||||
FinancialSheet,
|
FinancialSheet,
|
||||||
@@ -34,21 +33,18 @@ export class GeneralLedgerSheet extends R.compose(FinancialSheetStructure)(
|
|||||||
* @param {IGeneralLedgerSheetQuery} query -
|
* @param {IGeneralLedgerSheetQuery} query -
|
||||||
* @param {GeneralLedgerRepository} repository -
|
* @param {GeneralLedgerRepository} repository -
|
||||||
* @param {I18nService} i18n -
|
* @param {I18nService} i18n -
|
||||||
* @param {IFinancialReportMeta} meta -
|
|
||||||
*/
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
query: IGeneralLedgerSheetQuery,
|
query: IGeneralLedgerSheetQuery,
|
||||||
repository: GeneralLedgerRepository,
|
repository: GeneralLedgerRepository,
|
||||||
i18n: I18nService,
|
i18n: I18nService,
|
||||||
meta: IFinancialReportMeta,
|
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.query = query;
|
this.query = query;
|
||||||
this.numberFormat = this.query.numberFormat;
|
this.numberFormat = this.query.numberFormat;
|
||||||
this.dateFormat = meta.dateFormat || DEFAULT_REPORT_META.dateFormat;
|
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
this.baseCurrency = meta.baseCurrency;
|
this.baseCurrency = this.repository.tenant.metadata.baseCurrency;
|
||||||
this.i18n = i18n;
|
this.i18n = i18n;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,7 +87,7 @@ export class GeneralLedgerSheet extends R.compose(FinancialSheetStructure)(
|
|||||||
return {
|
return {
|
||||||
id: entry.id,
|
id: entry.id,
|
||||||
date: entry.date,
|
date: entry.date,
|
||||||
dateFormatted: moment(entry.date).format(this.dateFormat),
|
dateFormatted: moment(entry.date).format('YYYY MMM DD'),
|
||||||
|
|
||||||
referenceType: entry.transactionType,
|
referenceType: entry.transactionType,
|
||||||
referenceId: entry.transactionId,
|
referenceId: entry.transactionId,
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ export interface IGeneralLedgerSheetQuery {
|
|||||||
toDate: Date | string;
|
toDate: Date | string;
|
||||||
basis: string;
|
basis: string;
|
||||||
numberFormat: IGeneralLedgerNumberFormat;
|
numberFormat: IGeneralLedgerNumberFormat;
|
||||||
dateFormat?: string;
|
|
||||||
noneTransactions: boolean;
|
noneTransactions: boolean;
|
||||||
accountsIds: number[];
|
accountsIds: number[];
|
||||||
branchesIds?: number[];
|
branchesIds?: number[];
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ export class GeneralLedgerMeta {
|
|||||||
): Promise<IGeneralLedgerMeta> {
|
): Promise<IGeneralLedgerMeta> {
|
||||||
const commonMeta = await this.financialSheetMeta.meta();
|
const commonMeta = await this.financialSheetMeta.meta();
|
||||||
|
|
||||||
const formattedToDate = moment(query.toDate).format(commonMeta.dateFormat);
|
const formattedToDate = moment(query.toDate).format('YYYY/MM/DD');
|
||||||
const formattedFromDate = moment(query.fromDate).format(commonMeta.dateFormat);
|
const formattedFromDate = moment(query.fromDate).format('YYYY/MM/DD');
|
||||||
const formattedDateRange = `From ${formattedFromDate} | To ${formattedToDate}`;
|
const formattedDateRange = `From ${formattedFromDate} | To ${formattedToDate}`;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -37,19 +37,18 @@ export class GeneralLedgerService {
|
|||||||
this.generalLedgerRepository.setFilter(filter);
|
this.generalLedgerRepository.setFilter(filter);
|
||||||
await this.generalLedgerRepository.asyncInitialize();
|
await this.generalLedgerRepository.asyncInitialize();
|
||||||
|
|
||||||
// Retrieve general ledger report metadata first to get the date format.
|
|
||||||
const meta = await this.generalLedgerMeta.meta(filter);
|
|
||||||
|
|
||||||
// General ledger report instance.
|
// General ledger report instance.
|
||||||
const generalLedgerInstance = new GeneralLedgerSheet(
|
const generalLedgerInstance = new GeneralLedgerSheet(
|
||||||
filter,
|
filter,
|
||||||
this.generalLedgerRepository,
|
this.generalLedgerRepository,
|
||||||
this.i18n,
|
this.i18n,
|
||||||
{ baseCurrency: meta.baseCurrency, dateFormat: meta.dateFormat },
|
|
||||||
);
|
);
|
||||||
// Retrieve general ledger report data.
|
// Retrieve general ledger report data.
|
||||||
const reportData = generalLedgerInstance.reportData();
|
const reportData = generalLedgerInstance.reportData();
|
||||||
|
|
||||||
|
// Retrieve general ledger report metadata.
|
||||||
|
const meta = await this.generalLedgerMeta.meta(filter);
|
||||||
|
|
||||||
// Triggers `onGeneralLedgerViewed` event.
|
// Triggers `onGeneralLedgerViewed` event.
|
||||||
await this.eventEmitter.emitAsync(events.reports.onGeneralLedgerViewed, {});
|
await this.eventEmitter.emitAsync(events.reports.onGeneralLedgerViewed, {});
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import { InventoryDetails } from './InventoryItemDetails';
|
|||||||
import { InventoryItemDetailsRepository } from './InventoryItemDetailsRepository';
|
import { InventoryItemDetailsRepository } from './InventoryItemDetailsRepository';
|
||||||
import { InventoryDetailsMetaInjectable } from './InventoryItemDetailsMeta';
|
import { InventoryDetailsMetaInjectable } from './InventoryItemDetailsMeta';
|
||||||
import { getInventoryItemDetailsDefaultQuery } from './constant';
|
import { getInventoryItemDetailsDefaultQuery } from './constant';
|
||||||
import { TenancyContext } from '@/modules/Tenancy/TenancyContext.service';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class InventoryDetailsService {
|
export class InventoryDetailsService {
|
||||||
@@ -16,7 +15,6 @@ export class InventoryDetailsService {
|
|||||||
private readonly inventoryItemDetailsRepository: InventoryItemDetailsRepository,
|
private readonly inventoryItemDetailsRepository: InventoryItemDetailsRepository,
|
||||||
private readonly inventoryDetailsMeta: InventoryDetailsMetaInjectable,
|
private readonly inventoryDetailsMeta: InventoryDetailsMetaInjectable,
|
||||||
private readonly i18n: I18nService,
|
private readonly i18n: I18nService,
|
||||||
private readonly tenancyContext: TenancyContext,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -36,16 +34,13 @@ export class InventoryDetailsService {
|
|||||||
this.inventoryItemDetailsRepository.setFilter(filter);
|
this.inventoryItemDetailsRepository.setFilter(filter);
|
||||||
await this.inventoryItemDetailsRepository.asyncInit();
|
await this.inventoryItemDetailsRepository.asyncInit();
|
||||||
|
|
||||||
// Retrieve the meta first to get date format.
|
|
||||||
const meta = await this.inventoryDetailsMeta.meta(query);
|
|
||||||
|
|
||||||
// Inventory details report mapper.
|
// Inventory details report mapper.
|
||||||
const inventoryDetailsInstance = new InventoryDetails(
|
const inventoryDetailsInstance = new InventoryDetails(
|
||||||
filter,
|
filter,
|
||||||
this.inventoryItemDetailsRepository,
|
this.inventoryItemDetailsRepository,
|
||||||
this.i18n,
|
this.i18n,
|
||||||
{ baseCurrency: meta.baseCurrency, dateFormat: meta.dateFormat },
|
|
||||||
);
|
);
|
||||||
|
const meta = await this.inventoryDetailsMeta.meta(query);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
data: inventoryDetailsInstance.reportData(),
|
data: inventoryDetailsInstance.reportData(),
|
||||||
|
|||||||
@@ -17,8 +17,6 @@ import { Item } from '@/modules/Items/models/Item';
|
|||||||
import {
|
import {
|
||||||
IFormatNumberSettings,
|
IFormatNumberSettings,
|
||||||
INumberFormatQuery,
|
INumberFormatQuery,
|
||||||
IFinancialReportMeta,
|
|
||||||
DEFAULT_REPORT_META,
|
|
||||||
} from '../../types/Report.types';
|
} from '../../types/Report.types';
|
||||||
import { InventoryTransaction } from '@/modules/InventoryCost/models/InventoryTransaction';
|
import { InventoryTransaction } from '@/modules/InventoryCost/models/InventoryTransaction';
|
||||||
import { InventoryItemDetailsRepository } from './InventoryItemDetailsRepository';
|
import { InventoryItemDetailsRepository } from './InventoryItemDetailsRepository';
|
||||||
@@ -37,13 +35,11 @@ export class InventoryDetails extends FinancialSheet {
|
|||||||
* Constructor method.
|
* Constructor method.
|
||||||
* @param {InventoryItemDetailsRepository} repository - The repository.
|
* @param {InventoryItemDetailsRepository} repository - The repository.
|
||||||
* @param {I18nService} i18n - The i18n service.
|
* @param {I18nService} i18n - The i18n service.
|
||||||
* @param {IFinancialReportMeta} meta - Report meta.
|
|
||||||
*/
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
filter: IInventoryDetailsQuery,
|
filter: IInventoryDetailsQuery,
|
||||||
repository: InventoryItemDetailsRepository,
|
repository: InventoryItemDetailsRepository,
|
||||||
i18n: I18nService,
|
i18n: I18nService,
|
||||||
meta: IFinancialReportMeta,
|
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
@@ -52,7 +48,6 @@ export class InventoryDetails extends FinancialSheet {
|
|||||||
this.query = filter;
|
this.query = filter;
|
||||||
this.numberFormat = this.query.numberFormat;
|
this.numberFormat = this.query.numberFormat;
|
||||||
this.i18n = i18n;
|
this.i18n = i18n;
|
||||||
this.dateFormat = meta.dateFormat || DEFAULT_REPORT_META.dateFormat;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -94,7 +89,7 @@ export class InventoryDetails extends FinancialSheet {
|
|||||||
*/
|
*/
|
||||||
public getDateMeta(date: Date | string): IInventoryDetailsDate {
|
public getDateMeta(date: Date | string): IInventoryDetailsDate {
|
||||||
return {
|
return {
|
||||||
formattedDate: moment(date).format(this.dateFormat),
|
formattedDate: moment(date).format('YYYY-MM-DD'),
|
||||||
date: moment(date).toDate(),
|
date: moment(date).toDate(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ export class InventoryDetailsMetaInjectable {
|
|||||||
): Promise<IInventoryItemDetailMeta> {
|
): Promise<IInventoryItemDetailMeta> {
|
||||||
const commonMeta = await this.financialSheetMeta.meta();
|
const commonMeta = await this.financialSheetMeta.meta();
|
||||||
|
|
||||||
const formattedFromDate = moment(query.fromDate).format(commonMeta.dateFormat);
|
const formattedFromDate = moment(query.fromDate).format('YYYY/MM/DD');
|
||||||
const formattedToDay = moment(query.toDate).format(commonMeta.dateFormat);
|
const formattedToDay = moment(query.toDate).format('YYYY/MM/DD');
|
||||||
const formattedDateRange = `From ${formattedFromDate} | To ${formattedToDay}`;
|
const formattedDateRange = `From ${formattedFromDate} | To ${formattedToDay}`;
|
||||||
|
|
||||||
const sheetName = 'Inventory Item Details';
|
const sheetName = 'Inventory Item Details';
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ export class InventoryItemDetailsTable {
|
|||||||
): ITableRow => {
|
): ITableRow => {
|
||||||
const columns: Array<IColumnMapperMeta> = [
|
const columns: Array<IColumnMapperMeta> = [
|
||||||
{ key: 'date', accessor: 'date.formattedDate' },
|
{ key: 'date', accessor: 'date.formattedDate' },
|
||||||
{ key: 'closing', value: this.i18n.t('inventory_item_details.opening_balance') },
|
{ key: 'closing', value: this.i18n.t('Opening balance') },
|
||||||
{ key: 'empty', value: '' },
|
{ key: 'empty', value: '' },
|
||||||
{ key: 'quantity', accessor: 'quantity.formattedNumber' },
|
{ key: 'quantity', accessor: 'quantity.formattedNumber' },
|
||||||
{ key: 'empty', value: '' },
|
{ key: 'empty', value: '' },
|
||||||
@@ -115,7 +115,7 @@ export class InventoryItemDetailsTable {
|
|||||||
): ITableRow => {
|
): ITableRow => {
|
||||||
const columns: Array<IColumnMapperMeta> = [
|
const columns: Array<IColumnMapperMeta> = [
|
||||||
{ key: 'date', accessor: 'date.formattedDate' },
|
{ key: 'date', accessor: 'date.formattedDate' },
|
||||||
{ key: 'closing', value: this.i18n.t('inventory_item_details.closing_balance') },
|
{ key: 'closing', value: this.i18n.t('Closing balance') },
|
||||||
{ key: 'empty', value: '' },
|
{ key: 'empty', value: '' },
|
||||||
{ key: 'quantity', accessor: 'quantity.formattedNumber' },
|
{ key: 'quantity', accessor: 'quantity.formattedNumber' },
|
||||||
{ key: 'empty', value: '' },
|
{ key: 'empty', value: '' },
|
||||||
@@ -193,16 +193,16 @@ export class InventoryItemDetailsTable {
|
|||||||
*/
|
*/
|
||||||
public tableColumns = (): ITableColumn[] => {
|
public tableColumns = (): ITableColumn[] => {
|
||||||
return [
|
return [
|
||||||
{ key: 'date', label: this.i18n.t('inventory_item_details.date') },
|
{ key: 'date', label: this.i18n.t('Date') },
|
||||||
{ key: 'transaction_type', label: this.i18n.t('inventory_item_details.transaction_type') },
|
{ key: 'transaction_type', label: this.i18n.t('Transaction type') },
|
||||||
{ key: 'transaction_id', label: this.i18n.t('inventory_item_details.transaction_number') },
|
{ key: 'transaction_id', label: this.i18n.t('Transaction #') },
|
||||||
{ key: 'quantity', label: this.i18n.t('inventory_item_details.quantity') },
|
{ key: 'quantity', label: this.i18n.t('Quantity') },
|
||||||
{ key: 'rate', label: this.i18n.t('inventory_item_details.rate') },
|
{ key: 'rate', label: this.i18n.t('Rate') },
|
||||||
{ key: 'total', label: this.i18n.t('inventory_item_details.total') },
|
{ key: 'total', label: this.i18n.t('Total') },
|
||||||
{ key: 'value', label: this.i18n.t('inventory_item_details.value') },
|
{ key: 'value', label: this.i18n.t('Value') },
|
||||||
{ key: 'profit_margin', label: this.i18n.t('inventory_item_details.profit_margin') },
|
{ key: 'profit_margin', label: this.i18n.t('Profit Margin') },
|
||||||
{ key: 'running_quantity', label: this.i18n.t('inventory_item_details.running_quantity') },
|
{ key: 'running_quantity', label: this.i18n.t('Running quantity') },
|
||||||
{ key: 'running_value', label: this.i18n.t('inventory_item_details.running_value') },
|
{ key: 'running_value', label: this.i18n.t('Running Value') },
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import { InventoryCostLotTracker } from '@/modules/InventoryCost/models/Inventor
|
|||||||
import { FinancialSheet } from '../../common/FinancialSheet';
|
import { FinancialSheet } from '../../common/FinancialSheet';
|
||||||
import { InventoryValuationSheetRepository } from './InventoryValuationSheetRepository';
|
import { InventoryValuationSheetRepository } from './InventoryValuationSheetRepository';
|
||||||
import { allPassedConditionsPass } from '@/utils/all-conditions-passed';
|
import { allPassedConditionsPass } from '@/utils/all-conditions-passed';
|
||||||
import { IFinancialReportMeta, DEFAULT_REPORT_META } from '../../types/Report.types';
|
|
||||||
|
|
||||||
export class InventoryValuationSheet extends FinancialSheet {
|
export class InventoryValuationSheet extends FinancialSheet {
|
||||||
readonly query: IInventoryValuationReportQuery;
|
readonly query: IInventoryValuationReportQuery;
|
||||||
@@ -22,19 +21,16 @@ export class InventoryValuationSheet extends FinancialSheet {
|
|||||||
* Constructor method.
|
* Constructor method.
|
||||||
* @param {IInventoryValuationReportQuery} query - Inventory valuation query.
|
* @param {IInventoryValuationReportQuery} query - Inventory valuation query.
|
||||||
* @param {InventoryValuationSheetRepository} repository - Inventory valuation sheet repository.
|
* @param {InventoryValuationSheetRepository} repository - Inventory valuation sheet repository.
|
||||||
* @param {IFinancialReportMeta} meta - Report meta.
|
|
||||||
*/
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
query: IInventoryValuationReportQuery,
|
query: IInventoryValuationReportQuery,
|
||||||
repository: InventoryValuationSheetRepository,
|
repository: InventoryValuationSheetRepository,
|
||||||
meta: IFinancialReportMeta,
|
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.query = query;
|
this.query = query;
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
this.numberFormat = this.query.numberFormat;
|
this.numberFormat = this.query.numberFormat;
|
||||||
this.dateFormat = meta.dateFormat || DEFAULT_REPORT_META.dateFormat;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export class InventoryValuationMetaInjectable {
|
|||||||
query: IInventoryValuationReportQuery,
|
query: IInventoryValuationReportQuery,
|
||||||
): Promise<IInventoryValuationSheetMeta> {
|
): Promise<IInventoryValuationSheetMeta> {
|
||||||
const commonMeta = await this.financialSheetMeta.meta();
|
const commonMeta = await this.financialSheetMeta.meta();
|
||||||
const formattedAsDate = moment(query.asDate).format(commonMeta.dateFormat);
|
const formattedAsDate = moment(query.asDate).format('YYYY/MM/DD');
|
||||||
const formattedDateRange = `As ${formattedAsDate}`;
|
const formattedDateRange = `As ${formattedAsDate}`;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -34,17 +34,16 @@ export class InventoryValuationSheetService {
|
|||||||
this.inventoryValuationSheetRepository.setFilter(filter);
|
this.inventoryValuationSheetRepository.setFilter(filter);
|
||||||
await this.inventoryValuationSheetRepository.asyncInit();
|
await this.inventoryValuationSheetRepository.asyncInit();
|
||||||
|
|
||||||
// Retrieves the inventorty valuation meta first to get date format.
|
|
||||||
const meta = await this.inventoryValuationMeta.meta(filter);
|
|
||||||
|
|
||||||
const inventoryValuationInstance = new InventoryValuationSheet(
|
const inventoryValuationInstance = new InventoryValuationSheet(
|
||||||
filter,
|
filter,
|
||||||
this.inventoryValuationSheetRepository,
|
this.inventoryValuationSheetRepository,
|
||||||
{ baseCurrency: meta.baseCurrency, dateFormat: meta.dateFormat },
|
|
||||||
);
|
);
|
||||||
// Retrieve the inventory valuation report data.
|
// Retrieve the inventory valuation report data.
|
||||||
const inventoryValuationData = inventoryValuationInstance.reportData();
|
const inventoryValuationData = inventoryValuationInstance.reportData();
|
||||||
|
|
||||||
|
// Retrieves the inventorty valuation meta.
|
||||||
|
const meta = await this.inventoryValuationMeta.meta(filter);
|
||||||
|
|
||||||
// Triggers `onInventoryValuationViewed` event.
|
// Triggers `onInventoryValuationViewed` event.
|
||||||
await this.eventPublisher.emitAsync(
|
await this.eventPublisher.emitAsync(
|
||||||
events.reports.onInventoryValuationViewed,
|
events.reports.onInventoryValuationViewed,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Controller, Get, Headers, Query, Res, UseGuards } from '@nestjs/common';
|
import { Controller, Get, Headers, Query, Res } from '@nestjs/common';
|
||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { AcceptType } from '@/constants/accept-type';
|
import { AcceptType } from '@/constants/accept-type';
|
||||||
import { JournalSheetApplication } from './JournalSheetApplication';
|
import { JournalSheetApplication } from './JournalSheetApplication';
|
||||||
@@ -11,21 +11,14 @@ import {
|
|||||||
import { JournalSheetQueryDto } from './JournalSheetQuery.dto';
|
import { JournalSheetQueryDto } from './JournalSheetQuery.dto';
|
||||||
import { JournalSheetResponseExample } from './JournalSheet.swagger';
|
import { JournalSheetResponseExample } from './JournalSheet.swagger';
|
||||||
import { ApiCommonHeaders } from '@/common/decorators/ApiCommonHeaders';
|
import { ApiCommonHeaders } from '@/common/decorators/ApiCommonHeaders';
|
||||||
import { RequirePermission } from '@/modules/Roles/RequirePermission.decorator';
|
|
||||||
import { PermissionGuard } from '@/modules/Roles/Permission.guard';
|
|
||||||
import { AuthorizationGuard } from '@/modules/Roles/Authorization.guard';
|
|
||||||
import { AbilitySubject } from '@/modules/Roles/Roles.types';
|
|
||||||
import { ReportsAction } from '../../types/Report.types';
|
|
||||||
|
|
||||||
@Controller('/reports/journal')
|
@Controller('/reports/journal')
|
||||||
@ApiTags('Reports')
|
@ApiTags('Reports')
|
||||||
@ApiCommonHeaders()
|
@ApiCommonHeaders()
|
||||||
@UseGuards(AuthorizationGuard, PermissionGuard)
|
|
||||||
export class JournalSheetController {
|
export class JournalSheetController {
|
||||||
constructor(private readonly journalSheetApp: JournalSheetApplication) {}
|
constructor(private readonly journalSheetApp: JournalSheetApplication) {}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
@RequirePermission(ReportsAction.READ_JOURNAL, AbilitySubject.Report)
|
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
description: 'Journal report',
|
description: 'Journal report',
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import { FinancialSheet } from '../../common/FinancialSheet';
|
|||||||
import { JournalSheetRepository } from './JournalSheetRepository';
|
import { JournalSheetRepository } from './JournalSheetRepository';
|
||||||
import { ILedgerEntry } from '@/modules/Ledger/types/Ledger.types';
|
import { ILedgerEntry } from '@/modules/Ledger/types/Ledger.types';
|
||||||
import { getTransactionTypeLabel } from '@/modules/BankingTransactions/utils';
|
import { getTransactionTypeLabel } from '@/modules/BankingTransactions/utils';
|
||||||
import { IFinancialReportMeta, DEFAULT_REPORT_META } from '../../types/Report.types';
|
|
||||||
|
|
||||||
export class JournalSheet extends FinancialSheet {
|
export class JournalSheet extends FinancialSheet {
|
||||||
readonly query: IJournalReportQuery;
|
readonly query: IJournalReportQuery;
|
||||||
@@ -23,24 +22,20 @@ export class JournalSheet extends FinancialSheet {
|
|||||||
* @param {IJournalReportQuery} query -
|
* @param {IJournalReportQuery} query -
|
||||||
* @param {JournalSheetRepository} repository -
|
* @param {JournalSheetRepository} repository -
|
||||||
* @param {I18nService} i18n -
|
* @param {I18nService} i18n -
|
||||||
* @param {IFinancialReportMeta} meta -
|
|
||||||
*/
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
query: IJournalReportQuery,
|
query: IJournalReportQuery,
|
||||||
repository: JournalSheetRepository,
|
repository: JournalSheetRepository,
|
||||||
i18n: I18nService,
|
i18n: I18nService,
|
||||||
meta: IFinancialReportMeta,
|
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.query = query;
|
this.query = query;
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
this.baseCurrency = meta.baseCurrency;
|
|
||||||
this.numberFormat = {
|
this.numberFormat = {
|
||||||
...this.numberFormat,
|
...this.numberFormat,
|
||||||
...this.query.numberFormat,
|
...this.query.numberFormat,
|
||||||
};
|
};
|
||||||
this.dateFormat = meta.dateFormat || DEFAULT_REPORT_META.dateFormat;
|
|
||||||
this.i18n = i18n;
|
this.i18n = i18n;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,7 +94,7 @@ export class JournalSheet extends FinancialSheet {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
date: moment(groupEntry.date).toDate(),
|
date: moment(groupEntry.date).toDate(),
|
||||||
dateFormatted: moment(groupEntry.date).format(this.dateFormat),
|
dateFormatted: moment(groupEntry.date).format('YYYY MMM DD'),
|
||||||
|
|
||||||
transactionType: groupEntry.transactionType,
|
transactionType: groupEntry.transactionType,
|
||||||
referenceId: groupEntry.transactionId,
|
referenceId: groupEntry.transactionId,
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ export interface IJournalReportQuery {
|
|||||||
noCents: boolean;
|
noCents: boolean;
|
||||||
divideOn1000: boolean;
|
divideOn1000: boolean;
|
||||||
};
|
};
|
||||||
dateFormat?: string;
|
|
||||||
transactionType: string;
|
transactionType: string;
|
||||||
transactionId: string;
|
transactionId: string;
|
||||||
|
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ export class JournalSheetMeta {
|
|||||||
): Promise<IJournalSheetMeta> {
|
): Promise<IJournalSheetMeta> {
|
||||||
const common = await this.financialSheetMeta.meta();
|
const common = await this.financialSheetMeta.meta();
|
||||||
|
|
||||||
const formattedToDate = moment(query.toDate).format(common.dateFormat);
|
const formattedToDate = moment(query.toDate).format('YYYY/MM/DD');
|
||||||
const formattedFromDate = moment(query.fromDate).format(common.dateFormat);
|
const formattedFromDate = moment(query.fromDate).format('YYYY/MM/DD');
|
||||||
const formattedDateRange = `From ${formattedFromDate} | To ${formattedToDate}`;
|
const formattedDateRange = `From ${formattedFromDate} | To ${formattedToDate}`;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -30,19 +30,18 @@ export class JournalSheetService {
|
|||||||
this.journalRepository.setFilter(query);
|
this.journalRepository.setFilter(query);
|
||||||
await this.journalRepository.load();
|
await this.journalRepository.load();
|
||||||
|
|
||||||
// Retrieve the journal sheet meta first to get the date format.
|
|
||||||
const meta = await this.journalSheetMeta.meta(filter);
|
|
||||||
|
|
||||||
// Journal report instance.
|
// Journal report instance.
|
||||||
const journalSheetInstance = new JournalSheet(
|
const journalSheetInstance = new JournalSheet(
|
||||||
filter,
|
filter,
|
||||||
this.journalRepository,
|
this.journalRepository,
|
||||||
this.i18n,
|
this.i18n,
|
||||||
{ baseCurrency: meta.baseCurrency, dateFormat: meta.dateFormat },
|
|
||||||
);
|
);
|
||||||
// Retrieve journal report columns.
|
// Retrieve journal report columns.
|
||||||
const journalSheetData = journalSheetInstance.reportData();
|
const journalSheetData = journalSheetInstance.reportData();
|
||||||
|
|
||||||
|
// Retrieve the journal sheet meta.
|
||||||
|
const meta = await this.journalSheetMeta.meta(filter);
|
||||||
|
|
||||||
// Triggers `onJournalViewed` event.
|
// Triggers `onJournalViewed` event.
|
||||||
await this.eventPublisher.emitAsync(events.reports.onJournalViewed, {
|
await this.eventPublisher.emitAsync(events.reports.onJournalViewed, {
|
||||||
query,
|
query,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { Controller, Get, Headers, Query, Res, UseGuards } from '@nestjs/common';
|
import { Controller, Get, Headers, Query, Res } from '@nestjs/common';
|
||||||
import { ProfitLossSheetApplication } from './ProfitLossSheetApplication';
|
import { ProfitLossSheetApplication } from './ProfitLossSheetApplication';
|
||||||
import { AcceptType } from '@/constants/accept-type';
|
import { AcceptType } from '@/constants/accept-type';
|
||||||
import {
|
import {
|
||||||
@@ -11,16 +11,10 @@ import {
|
|||||||
import { ProfitLossSheetQueryDto } from './ProfitLossSheetQuery.dto';
|
import { ProfitLossSheetQueryDto } from './ProfitLossSheetQuery.dto';
|
||||||
import { ProfitLossSheetResponseExample } from './ProfitLossSheet.swagger';
|
import { ProfitLossSheetResponseExample } from './ProfitLossSheet.swagger';
|
||||||
import { ApiCommonHeaders } from '@/common/decorators/ApiCommonHeaders';
|
import { ApiCommonHeaders } from '@/common/decorators/ApiCommonHeaders';
|
||||||
import { RequirePermission } from '@/modules/Roles/RequirePermission.decorator';
|
|
||||||
import { PermissionGuard } from '@/modules/Roles/Permission.guard';
|
|
||||||
import { AuthorizationGuard } from '@/modules/Roles/Authorization.guard';
|
|
||||||
import { AbilitySubject } from '@/modules/Roles/Roles.types';
|
|
||||||
import { ReportsAction } from '../../types/Report.types';
|
|
||||||
|
|
||||||
@Controller('/reports/profit-loss-sheet')
|
@Controller('/reports/profit-loss-sheet')
|
||||||
@ApiTags('Reports')
|
@ApiTags('Reports')
|
||||||
@ApiCommonHeaders()
|
@ApiCommonHeaders()
|
||||||
@UseGuards(AuthorizationGuard, PermissionGuard)
|
|
||||||
export class ProfitLossSheetController {
|
export class ProfitLossSheetController {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly profitLossSheetApp: ProfitLossSheetApplication,
|
private readonly profitLossSheetApp: ProfitLossSheetApplication,
|
||||||
@@ -33,7 +27,6 @@ export class ProfitLossSheetController {
|
|||||||
* @param {string} acceptHeader
|
* @param {string} acceptHeader
|
||||||
*/
|
*/
|
||||||
@Get('/')
|
@Get('/')
|
||||||
@RequirePermission(ReportsAction.READ_PROFIT_LOSS, AbilitySubject.Report)
|
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
description: 'Profit & loss statement',
|
description: 'Profit & loss statement',
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import { FinancialSheetStructure } from '../../common/FinancialSheetStructure';
|
|||||||
import { FinancialSheet } from '../../common/FinancialSheet';
|
import { FinancialSheet } from '../../common/FinancialSheet';
|
||||||
import { Account } from '@/modules/Accounts/models/Account.model';
|
import { Account } from '@/modules/Accounts/models/Account.model';
|
||||||
import { flatToNestedArray } from '@/utils/flat-to-nested-array';
|
import { flatToNestedArray } from '@/utils/flat-to-nested-array';
|
||||||
import { IFinancialReportMeta, DEFAULT_REPORT_META } from '../../types/Report.types';
|
|
||||||
|
|
||||||
export default class ProfitLossSheet extends R.pipe(
|
export default class ProfitLossSheet extends R.pipe(
|
||||||
ProfitLossSheetPreviousYear,
|
ProfitLossSheetPreviousYear,
|
||||||
@@ -72,24 +71,20 @@ export default class ProfitLossSheet extends R.pipe(
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor method.
|
* Constructor method.
|
||||||
* @param {ProfitLossSheetRepository} repository -
|
|
||||||
* @param {IProfitLossSheetQuery} query -
|
* @param {IProfitLossSheetQuery} query -
|
||||||
* @param {I18nService} i18n -
|
* @param {IAccount[]} accounts -
|
||||||
* @param {IFinancialReportMeta} meta -
|
* @param {IJournalPoster} transactionsJournal -
|
||||||
*/
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
repository: ProfitLossSheetRepository,
|
repository: ProfitLossSheetRepository,
|
||||||
query: IProfitLossSheetQuery,
|
query: IProfitLossSheetQuery,
|
||||||
i18n: I18nService,
|
i18n: I18nService,
|
||||||
meta: IFinancialReportMeta,
|
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.query = new ProfitLossSheetQuery(query);
|
this.query = new ProfitLossSheetQuery(query);
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
this.baseCurrency = meta.baseCurrency;
|
|
||||||
this.numberFormat = this.query.query.numberFormat;
|
this.numberFormat = this.query.query.numberFormat;
|
||||||
this.dateFormat = meta.dateFormat || DEFAULT_REPORT_META.dateFormat;
|
|
||||||
this.i18n = i18n;
|
this.i18n = i18n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ export class ProfitLossSheetMeta {
|
|||||||
query: IProfitLossSheetQuery,
|
query: IProfitLossSheetQuery,
|
||||||
): Promise<IProfitLossSheetMeta> {
|
): Promise<IProfitLossSheetMeta> {
|
||||||
const commonMeta = await this.financialSheetMeta.meta();
|
const commonMeta = await this.financialSheetMeta.meta();
|
||||||
const formattedToDate = moment(query.toDate).format(commonMeta.dateFormat);
|
const formattedToDate = moment(query.toDate).format('YYYY/MM/DD');
|
||||||
const formattedFromDate = moment(query.fromDate).format(commonMeta.dateFormat);
|
const formattedFromDate = moment(query.fromDate).format('YYYY/MM/DD');
|
||||||
const formattedDateRange = `From ${formattedFromDate} | To ${formattedToDate}`;
|
const formattedDateRange = `From ${formattedFromDate} | To ${formattedToDate}`;
|
||||||
|
|
||||||
const sheetName = 'Cashflow Statement';
|
const sheetName = 'Cashflow Statement';
|
||||||
|
|||||||
@@ -64,10 +64,10 @@ export class ProfitLossSheetQueryDto extends FinancialSheetBranchesQueryDto {
|
|||||||
displayColumnsType: 'total' | 'date_periods';
|
displayColumnsType: 'total' | 'date_periods';
|
||||||
|
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsEnum(['day', 'month', 'year', 'quarter'])
|
@IsEnum(['day', 'month', 'year'])
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@ApiProperty({ description: 'How to display columns' })
|
@ApiProperty({ description: 'How to display columns' })
|
||||||
displayColumnsBy: 'day' | 'month' | 'year' | 'quarter' = 'year';
|
displayColumnsBy: 'day' | 'month' | 'year' = 'year';
|
||||||
|
|
||||||
@Transform(({ value }) => parseBoolean(value, false))
|
@Transform(({ value }) => parseBoolean(value, false))
|
||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
|
|||||||
@@ -40,19 +40,18 @@ export class ProfitLossSheetService {
|
|||||||
this.profitLossRepository.setFilter(filter);
|
this.profitLossRepository.setFilter(filter);
|
||||||
await this.profitLossRepository.asyncInitialize();
|
await this.profitLossRepository.asyncInitialize();
|
||||||
|
|
||||||
// Retrieve the profit/loss sheet meta first to get date format.
|
|
||||||
const meta = await this.profitLossSheetMeta.meta(filter);
|
|
||||||
|
|
||||||
// Profit/Loss report instance.
|
// Profit/Loss report instance.
|
||||||
const profitLossInstance = new ProfitLossSheet(
|
const profitLossInstance = new ProfitLossSheet(
|
||||||
this.profitLossRepository,
|
this.profitLossRepository,
|
||||||
filter,
|
filter,
|
||||||
this.i18nService,
|
this.i18nService,
|
||||||
{ baseCurrency: meta.baseCurrency, dateFormat: meta.dateFormat },
|
|
||||||
);
|
);
|
||||||
// Profit/loss report data and columns.
|
// Profit/loss report data and columns.
|
||||||
const data = profitLossInstance.reportData();
|
const data = profitLossInstance.reportData();
|
||||||
|
|
||||||
|
// Retrieve the profit/loss sheet meta.
|
||||||
|
const meta = await this.profitLossSheetMeta.meta(filter);
|
||||||
|
|
||||||
// Triggers `onProfitLossSheetViewed` event.
|
// Triggers `onProfitLossSheetViewed` event.
|
||||||
await this.eventPublisher.emitAsync(
|
await this.eventPublisher.emitAsync(
|
||||||
events.reports.onProfitLossSheetViewed,
|
events.reports.onProfitLossSheetViewed,
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user