refactor: financial reports to nestjs

This commit is contained in:
Ahmed Bouhuolia
2025-01-18 23:51:29 +02:00
parent dfc5674088
commit 6550e88af3
22 changed files with 552 additions and 71 deletions

View File

@@ -13,7 +13,7 @@ import { CreateAccountDTO } from './CreateAccount.dto';
import { EditAccountDTO } from './EditAccount.dto'; import { EditAccountDTO } from './EditAccount.dto';
import { PublicRoute } from '../Auth/Jwt.guard'; import { PublicRoute } from '../Auth/Jwt.guard';
import { IAccountsFilter, IAccountsTransactionsFilter } from './Accounts.types'; import { IAccountsFilter, IAccountsTransactionsFilter } from './Accounts.types';
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; import { ApiOperation, ApiParam, ApiResponse, ApiTags } from '@nestjs/swagger';
// import { IAccountsFilter, IAccountsTransactionsFilter } from './Accounts.types'; // import { IAccountsFilter, IAccountsTransactionsFilter } from './Accounts.types';
// import { ZodValidationPipe } from '@/common/pipes/ZodValidation.pipe'; // import { ZodValidationPipe } from '@/common/pipes/ZodValidation.pipe';
@@ -39,6 +39,13 @@ export class AccountsController {
status: 200, status: 200,
description: 'The account has been successfully updated.', description: 'The account has been successfully updated.',
}) })
@ApiResponse({ status: 404, description: 'The account not found.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The account id',
})
async editAccount( async editAccount(
@Param('id', ParseIntPipe) id: number, @Param('id', ParseIntPipe) id: number,
@Body() accountDTO: EditAccountDTO, @Body() accountDTO: EditAccountDTO,
@@ -52,6 +59,13 @@ export class AccountsController {
status: 200, status: 200,
description: 'The account has been successfully deleted.', description: 'The account has been successfully deleted.',
}) })
@ApiResponse({ status: 404, description: 'The account not found.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The account id',
})
async deleteAccount(@Param('id', ParseIntPipe) id: number) { async deleteAccount(@Param('id', ParseIntPipe) id: number) {
return this.accountsApplication.deleteAccount(id); return this.accountsApplication.deleteAccount(id);
} }
@@ -62,12 +76,30 @@ export class AccountsController {
status: 200, status: 200,
description: 'The account has been successfully activated.', description: 'The account has been successfully activated.',
}) })
@ApiResponse({ status: 404, description: 'The account not found.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The account id',
})
async activateAccount(@Param('id', ParseIntPipe) id: number) { async activateAccount(@Param('id', ParseIntPipe) id: number) {
return this.accountsApplication.activateAccount(id); return this.accountsApplication.activateAccount(id);
} }
@Post(':id/inactivate') @Post(':id/inactivate')
@ApiOperation({ summary: 'Inactivate the given account.' }) @ApiOperation({ summary: 'Inactivate the given account.' })
@ApiResponse({
status: 200,
description: 'The account has been successfully inactivated.',
})
@ApiResponse({ status: 404, description: 'The account not found.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The account id',
})
async inactivateAccount(@Param('id', ParseIntPipe) id: number) { async inactivateAccount(@Param('id', ParseIntPipe) id: number) {
return this.accountsApplication.inactivateAccount(id); return this.accountsApplication.inactivateAccount(id);
} }
@@ -98,6 +130,13 @@ export class AccountsController {
status: 200, status: 200,
description: 'The account details have been successfully retrieved.', description: 'The account details have been successfully retrieved.',
}) })
@ApiResponse({ status: 404, description: 'The account not found.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The account id',
})
async getAccount(@Param('id', ParseIntPipe) id: number) { async getAccount(@Param('id', ParseIntPipe) id: number) {
return this.accountsApplication.getAccount(id); return this.accountsApplication.getAccount(id);
} }

View File

@@ -6,32 +6,32 @@ import { Account } from './Account.model';
// import { getTransactionTypeLabel } from '@/utils/transactions-types'; // import { getTransactionTypeLabel } from '@/utils/transactions-types';
export class AccountTransaction extends BaseModel { export class AccountTransaction extends BaseModel {
referenceType: string; public readonly referenceType: string;
referenceId: number; public readonly referenceId: number;
accountId: number; public readonly accountId: number;
contactId: number; public readonly contactId: number;
credit: number; public readonly credit: number;
debit: number; public readonly debit: number;
exchangeRate: number; public readonly exchangeRate: number;
taxRate: number; public readonly taxRate: number;
date: Date | string; public readonly date: Date | string;
transactionType: string; public readonly transactionType: string;
currencyCode: string; public readonly currencyCode: string;
referenceTypeFormatted: string; public readonly referenceTypeFormatted: string;
transactionNumber!: string; public readonly transactionNumber!: string;
referenceNumber!: string; public readonly referenceNumber!: string;
note!: string; public readonly note!: string;
index!: number; public readonly index!: number;
indexGroup!: number; public readonly indexGroup!: number;
taxRateId!: number; public readonly taxRateId!: number;
branchId!: number; public readonly branchId!: number;
userId!: number; public readonly userId!: number;
itemId!: number; public readonly itemId!: number;
projectId!: number; public readonly projectId!: number;
account: Account; public readonly account: Account;
/** /**
* Table name * Table name

View File

@@ -9,7 +9,7 @@ import {
} from '@nestjs/common'; } from '@nestjs/common';
import { BillPaymentsApplication } from './BillPaymentsApplication.service'; import { BillPaymentsApplication } from './BillPaymentsApplication.service';
import { IBillPaymentDTO } from './types/BillPayments.types'; import { IBillPaymentDTO } from './types/BillPayments.types';
import { ApiOperation, ApiTags } from '@nestjs/swagger'; import { ApiOperation, ApiParam, ApiTags } from '@nestjs/swagger';
@Controller('bill-payments') @Controller('bill-payments')
@ApiTags('bill-payments') @ApiTags('bill-payments')
@@ -24,6 +24,12 @@ export class BillPaymentsController {
@Delete(':billPaymentId') @Delete(':billPaymentId')
@ApiOperation({ summary: 'Delete the given bill payment.' }) @ApiOperation({ summary: 'Delete the given bill payment.' })
@ApiParam({
name: 'billPaymentId',
required: true,
type: Number,
description: 'The bill payment id',
})
public deleteBillPayment(@Param('billPaymentId') billPaymentId: string) { public deleteBillPayment(@Param('billPaymentId') billPaymentId: string) {
return this.billPaymentsApplication.deleteBillPayment( return this.billPaymentsApplication.deleteBillPayment(
Number(billPaymentId), Number(billPaymentId),
@@ -32,6 +38,12 @@ export class BillPaymentsController {
@Put(':billPaymentId') @Put(':billPaymentId')
@ApiOperation({ summary: 'Edit the given bill payment.' }) @ApiOperation({ summary: 'Edit the given bill payment.' })
@ApiParam({
name: 'billPaymentId',
required: true,
type: Number,
description: 'The bill payment id',
})
public editBillPayment( public editBillPayment(
@Param('billPaymentId') billPaymentId: string, @Param('billPaymentId') billPaymentId: string,
@Body() billPaymentDTO: IBillPaymentDTO, @Body() billPaymentDTO: IBillPaymentDTO,
@@ -44,12 +56,24 @@ export class BillPaymentsController {
@Get(':billPaymentId') @Get(':billPaymentId')
@ApiOperation({ summary: 'Retrieves the bill payment details.' }) @ApiOperation({ summary: 'Retrieves the bill payment details.' })
@ApiParam({
name: 'billPaymentId',
required: true,
type: Number,
description: 'The bill payment id',
})
public getBillPayment(@Param('billPaymentId') billPaymentId: string) { public getBillPayment(@Param('billPaymentId') billPaymentId: string) {
return this.billPaymentsApplication.getBillPayment(Number(billPaymentId)); return this.billPaymentsApplication.getBillPayment(Number(billPaymentId));
} }
@Get(':billPaymentId/bills') @Get(':billPaymentId/bills')
@ApiOperation({ summary: 'Retrieves the bills of the given bill payment.' }) @ApiOperation({ summary: 'Retrieves the bills of the given bill payment.' })
@ApiParam({
name: 'billPaymentId',
required: true,
type: Number,
description: 'The bill payment id',
})
public getPaymentBills(@Param('billPaymentId') billPaymentId: string) { public getPaymentBills(@Param('billPaymentId') billPaymentId: string) {
return this.billPaymentsApplication.getPaymentBills(Number(billPaymentId)); return this.billPaymentsApplication.getPaymentBills(Number(billPaymentId));
} }

View File

@@ -1,4 +1,4 @@
import { ApiOperation, ApiTags } from '@nestjs/swagger'; import { ApiOperation, ApiParam, ApiTags } from '@nestjs/swagger';
import { import {
Controller, Controller,
Post, Post,
@@ -13,7 +13,6 @@ import { BillsApplication } from './Bills.application';
import { IBillDTO, IBillEditDTO, IBillsFilter } from './Bills.types'; import { IBillDTO, IBillEditDTO, IBillsFilter } from './Bills.types';
import { PublicRoute } from '../Auth/Jwt.guard'; import { PublicRoute } from '../Auth/Jwt.guard';
@Controller('bills') @Controller('bills')
@ApiTags('bills') @ApiTags('bills')
@PublicRoute() @PublicRoute()
@@ -28,30 +27,60 @@ export class BillsController {
@Put(':id') @Put(':id')
@ApiOperation({ summary: 'Edit the given bill.' }) @ApiOperation({ summary: 'Edit the given bill.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The bill id',
})
editBill(@Param('id') billId: number, @Body() billDTO: IBillEditDTO) { editBill(@Param('id') billId: number, @Body() billDTO: IBillEditDTO) {
return this.billsApplication.editBill(billId, billDTO); return this.billsApplication.editBill(billId, billDTO);
} }
@Delete(':id') @Delete(':id')
@ApiOperation({ summary: 'Delete the given bill.' }) @ApiOperation({ summary: 'Delete the given bill.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The bill id',
})
deleteBill(@Param('id') billId: number) { deleteBill(@Param('id') billId: number) {
return this.billsApplication.deleteBill(billId); return this.billsApplication.deleteBill(billId);
} }
@Get() @Get()
@ApiOperation({ summary: 'Retrieves the bills.' }) @ApiOperation({ summary: 'Retrieves the bills.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The bill id',
})
getBills(@Query() filterDTO: IBillsFilter) { getBills(@Query() filterDTO: IBillsFilter) {
return this.billsApplication.getBills(filterDTO); return this.billsApplication.getBills(filterDTO);
} }
@Get(':id') @Get(':id')
@ApiOperation({ summary: 'Retrieves the bill details.' }) @ApiOperation({ summary: 'Retrieves the bill details.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The bill id',
})
getBill(@Param('id') billId: number) { getBill(@Param('id') billId: number) {
return this.billsApplication.getBill(billId); return this.billsApplication.getBill(billId);
} }
@Post(':id/open') @Post(':id/open')
@ApiOperation({ summary: 'Open the given bill.' }) @ApiOperation({ summary: 'Open the given bill.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The bill id',
})
openBill(@Param('id') billId: number) { openBill(@Param('id') billId: number) {
return this.billsApplication.openBill(billId); return this.billsApplication.openBill(billId);
} }

View File

@@ -66,6 +66,7 @@ export class ContactBalanceSummaryReport extends FinancialSheet {
const node = { const node = {
total: this.getTotalFormat(customersTotal), total: this.getTotalFormat(customersTotal),
}; };
// @ts-ignore
return R.compose( return R.compose(
R.when( R.when(
R.always(this.filter.percentageColumn), R.always(this.filter.percentageColumn),
@@ -107,6 +108,7 @@ export class ContactBalanceSummaryReport extends FinancialSheet {
this.contactCamparsionPercentageOfColumnMapper this.contactCamparsionPercentageOfColumnMapper
)(customersTotal); )(customersTotal);
// @ts-ignore
return contacts.map(camparsionPercentageOfColummn); return contacts.map(camparsionPercentageOfColummn);
}; };
@@ -154,7 +156,7 @@ export class ContactBalanceSummaryReport extends FinancialSheet {
/** /**
* Filters customer has none transactions. * Filters customer has none transactions.
* @param {ICustomerBalanceSummaryCustomer} customer - * @param {ICustomerBalanceSummaryCustomer} customer - Customer total node.
* @returns {boolean} * @returns {boolean}
*/ */
private filterContactNoneTransactions = ( private filterContactNoneTransactions = (
@@ -167,7 +169,7 @@ export class ContactBalanceSummaryReport extends FinancialSheet {
/** /**
* Filters the customer that has zero total amount. * Filters the customer that has zero total amount.
* @param {ICustomerBalanceSummaryCustomer} customer * @param {ICustomerBalanceSummaryCustomer} customer - Customer total node.
* @returns {boolean} * @returns {boolean}
*/ */
private filterContactNoneZero = ( private filterContactNoneZero = (
@@ -178,7 +180,7 @@ export class ContactBalanceSummaryReport extends FinancialSheet {
/** /**
* Filters the given customer node; * Filters the given customer node;
* @param {ICustomerBalanceSummaryCustomer} customer * @param {ICustomerBalanceSummaryCustomer} customer - Customer total node.
*/ */
private contactNodeFilter = (contact: IContactBalanceSummaryContact) => { private contactNodeFilter = (contact: IContactBalanceSummaryContact) => {
const { noneTransactions, noneZero } = this.filter; const { noneTransactions, noneZero } = this.filter;

View File

@@ -19,6 +19,7 @@ export interface IContactBalanceSummaryPercentage {
} }
export interface IContactBalanceSummaryContact { export interface IContactBalanceSummaryContact {
id: number;
total: IContactBalanceSummaryAmount; total: IContactBalanceSummaryAmount;
percentageOfColumn?: IContactBalanceSummaryPercentage; percentageOfColumn?: IContactBalanceSummaryPercentage;
} }

View File

@@ -86,6 +86,7 @@ export class CustomerBalanceSummaryReport extends ContactBalanceSummaryReport {
private getCustomersSection = ( private getCustomersSection = (
customers: ModelObject<Customer>[] customers: ModelObject<Customer>[]
): ICustomerBalanceSummaryCustomer[] => { ): ICustomerBalanceSummaryCustomer[] => {
// @ts-ignore
return R.compose( return R.compose(
R.when(this.isCustomersPostFilter, this.contactsFilter), R.when(this.isCustomersPostFilter, this.contactsFilter),
R.when( R.when(

View File

@@ -35,6 +35,7 @@ export class CustomerBalanceSummaryService {
await this.reportRepository.getCustomersTransactions(asDate); await this.reportRepository.getCustomersTransactions(asDate);
const commonProps = { accountNormal: 'debit', date: asDate }; const commonProps = { accountNormal: 'debit', date: asDate };
// @ts-ignore
return R.map(R.merge(commonProps))(transactions); return R.map(R.merge(commonProps))(transactions);
} }

View File

@@ -94,6 +94,7 @@ export class CustomerBalanceSummaryTable {
{ key: 'name', value: this.i18n.t('Total') }, { key: 'name', value: this.i18n.t('Total') },
{ key: 'total', accessor: 'total.formattedAmount' }, { key: 'total', accessor: 'total.formattedAmount' },
]; ];
// @ts-ignore
return R.compose( return R.compose(
R.concat(columns), R.concat(columns),
R.when( R.when(
@@ -142,6 +143,7 @@ export class CustomerBalanceSummaryTable {
}, },
{ key: 'total', label: this.i18n.t('contact_summary_balance.total') }, { key: 'total', label: this.i18n.t('contact_summary_balance.total') },
]; ];
// @ts-ignore
return R.compose( return R.compose(
R.when( R.when(
R.always(this.query.percentageColumn), R.always(this.query.percentageColumn),

View File

@@ -6,6 +6,7 @@ import {
IGeneralLedgerSheetAccount, IGeneralLedgerSheetAccount,
IGeneralLedgerSheetAccountBalance, IGeneralLedgerSheetAccountBalance,
IGeneralLedgerSheetAccountTransaction, IGeneralLedgerSheetAccountTransaction,
IGeneralLedgerNumberFormat,
} from './GeneralLedger.types'; } from './GeneralLedger.types';
import { GeneralLedgerRepository } from './GeneralLedgerRepository'; import { GeneralLedgerRepository } from './GeneralLedgerRepository';
import { calculateRunningBalance } from './_utils'; import { calculateRunningBalance } from './_utils';
@@ -43,7 +44,7 @@ export class GeneralLedgerSheet extends R.compose(FinancialSheetStructure)(
this.query = query; this.query = query;
this.numberFormat = this.query.numberFormat; this.numberFormat = this.query.numberFormat;
this.repository = repository; this.repository = repository;
this.baseCurrency = this.repository.tenant.metadata.currencyCode; this.baseCurrency = this.repository.tenant.metadata.baseCurrency;
this.i18n = i18n; this.i18n = i18n;
} }

View File

@@ -1,19 +1,19 @@
import { IFinancialSheetCommonMeta } from "../../types/Report.types"; import { IFinancialSheetCommonMeta, INumberFormatQuery } from "../../types/Report.types";
import { IFinancialTable } from "../../types/Table.types"; import { IFinancialTable } from "../../types/Table.types";
export interface IGeneralLedgerSheetQuery { export interface IGeneralLedgerSheetQuery {
fromDate: Date | string; fromDate: Date | string;
toDate: Date | string; toDate: Date | string;
basis: string; basis: string;
numberFormat: { numberFormat: IGeneralLedgerNumberFormat;
noCents: boolean;
divideOn1000: boolean;
};
noneTransactions: boolean; noneTransactions: boolean;
accountsIds: number[]; accountsIds: number[];
branchesIds?: number[]; branchesIds?: number[];
} }
export interface IGeneralLedgerNumberFormat extends INumberFormatQuery{
}
export interface IGeneralLedgerSheetAccountTransaction { export interface IGeneralLedgerSheetAccountTransaction {
id: number; id: number;

View File

@@ -78,6 +78,7 @@ export class GeneralLedgerRepository {
* Initialize the accounts. * Initialize the accounts.
*/ */
public async initAccounts() { public async initAccounts() {
// @ts-ignore
this.accounts = await this.accountRepository this.accounts = await this.accountRepository
.all() .all()
.orderBy('name', 'ASC'); .orderBy('name', 'ASC');
@@ -170,7 +171,7 @@ export class GeneralLedgerRepository {
return R.concat(childrenIds, parentIds); return R.concat(childrenIds, parentIds);
}); });
// @ts-ignore\
this.accountNodeInclude = R.compose( this.accountNodeInclude = R.compose(
R.uniq, R.uniq,
R.flatten, R.flatten,

View File

@@ -168,7 +168,8 @@ export class GeneralLedgerTable extends R.compose(
/** /**
* Maps the given transaction node to table row. * Maps the given transaction node to table row.
* @param {IGeneralLedgerSheetAccountTransaction} transaction * @param {IGeneralLedgerSheetAccount} account - Account.
* @param {IGeneralLedgerSheetAccountTransaction} transaction - Transaction.
* @returns {ITableRow} * @returns {ITableRow}
*/ */
private transactionMapper = R.curry( private transactionMapper = R.curry(
@@ -195,6 +196,7 @@ export class GeneralLedgerTable extends R.compose(
): ITableRow[] => { ): ITableRow[] => {
const transactionMapper = this.transactionMapper(account); const transactionMapper = this.transactionMapper(account);
// @ts-ignore
return R.map(transactionMapper)(account.transactions); return R.map(transactionMapper)(account.transactions);
}; };
@@ -279,6 +281,7 @@ export class GeneralLedgerTable extends R.compose(
const isAppendClosingSubaccounts = () => const isAppendClosingSubaccounts = () =>
account.children?.length > 0 && !!account.closingBalanceSubaccounts; account.children?.length > 0 && !!account.closingBalanceSubaccounts;
// @ts-ignore
const children = R.compose( const children = R.compose(
R.when( R.when(
isAppendClosingSubaccounts, isAppendClosingSubaccounts,

View File

@@ -12,7 +12,7 @@ export class GeneralLedgerTableInjectable {
/** /**
* Retrieves the G/L table. * Retrieves the G/L table.
* @param {IGeneralLedgerSheetQuery} query * @param {IGeneralLedgerSheetQuery} query - general ledger query.
* @returns {Promise<IGeneralLedgerTableData>} * @returns {Promise<IGeneralLedgerTableData>}
*/ */
public async table( public async table(

View File

@@ -1,6 +1,7 @@
import * as R from 'ramda'; import * as R from 'ramda';
import { import {
ISalesByItemsItem, ISalesByItemsItem,
ISalesByItemsSheetData,
ISalesByItemsTotal, ISalesByItemsTotal,
} from './SalesByItems.types'; } from './SalesByItems.types';
import { ROW_TYPE } from './constants'; import { ROW_TYPE } from './constants';
@@ -14,13 +15,13 @@ export class SalesByItemsTable extends R.compose(
FinancialTable, FinancialTable,
FinancialSheetStructure FinancialSheetStructure
)(FinancialSheet) { )(FinancialSheet) {
private readonly data: ISalesByItemsSheetStatement; private readonly data: ISalesByItemsSheetData;
/** /**
* Constructor method. * Constructor method.
* @param {ISalesByItemsSheetStatement} data * @param {ISalesByItemsSheetStatement} data
*/ */
constructor(data: ISalesByItemsSheetStatement) { constructor(data: ISalesByItemsSheetData) {
super(); super();
this.data = data; this.data = data;
} }

View File

@@ -14,8 +14,15 @@ import { TenantController } from '../Tenancy/Tenant.controller';
import { SubscriptionGuard } from '../Subscription/interceptors/Subscription.guard'; import { SubscriptionGuard } from '../Subscription/interceptors/Subscription.guard';
import { PublicRoute } from '../Auth/Jwt.guard'; import { PublicRoute } from '../Auth/Jwt.guard';
import { ItemsApplicationService } from './ItemsApplication.service'; import { ItemsApplicationService } from './ItemsApplication.service';
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; import {
ApiOperation,
ApiParam,
ApiQuery,
ApiResponse,
ApiTags,
} from '@nestjs/swagger';
import { IItemsFilter } from './types/Items.types'; import { IItemsFilter } from './types/Items.types';
import { IItemDTO } from '@/interfaces/Item';
@Controller('/items') @Controller('/items')
@UseGuards(SubscriptionGuard) @UseGuards(SubscriptionGuard)
@@ -32,6 +39,67 @@ export class ItemsController extends TenantController {
status: 200, status: 200,
description: 'The item list has been successfully retrieved.', description: 'The item list has been successfully retrieved.',
}) })
@ApiQuery({
name: 'customViewId',
required: false,
type: Number,
description: 'Custom view ID for filtering',
})
@ApiQuery({
name: 'filterRoles',
required: false,
type: Array,
description: 'Array of filter roles',
})
@ApiQuery({
name: 'columnSortBy',
required: false,
type: String,
description: 'Column sort direction',
})
@ApiQuery({
name: 'sortOrder',
required: false,
type: String,
enum: ['DESC', 'ASC'],
description: 'Sort order direction',
})
@ApiQuery({
name: 'stringifiedFilterRoles',
required: false,
type: String,
description: 'Stringified filter roles',
})
@ApiQuery({
name: 'searchKeyword',
required: false,
type: String,
description: 'Search keyword',
})
@ApiQuery({
name: 'viewSlug',
required: false,
type: String,
description: 'View slug for filtering',
})
@ApiQuery({
name: 'page',
required: false,
type: Number,
description: 'Page number for pagination',
})
@ApiQuery({
name: 'pageSize',
required: false,
type: Number,
description: 'Number of items per page',
})
@ApiQuery({
name: 'inactiveMode',
required: false,
type: Boolean,
description: 'Filter for inactive items',
})
async getItems(@Query() filterDTO: IItemsFilter): Promise<any> { async getItems(@Query() filterDTO: IItemsFilter): Promise<any> {
return this.itemsApplication.getItems(filterDTO); return this.itemsApplication.getItems(filterDTO);
} }
@@ -52,7 +120,7 @@ export class ItemsController extends TenantController {
// @UsePipes(new ZodValidationPipe(createItemSchema)) // @UsePipes(new ZodValidationPipe(createItemSchema))
async editItem( async editItem(
@Param('id') id: string, @Param('id') id: string,
@Body() editItemDto: any, @Body() editItemDto: IItemDTO,
): Promise<number> { ): Promise<number> {
const itemId = parseInt(id, 10); const itemId = parseInt(id, 10);
return this.itemsApplication.editItem(itemId, editItemDto); return this.itemsApplication.editItem(itemId, editItemDto);
@@ -70,7 +138,7 @@ export class ItemsController extends TenantController {
description: 'The item has been successfully created.', description: 'The item has been successfully created.',
}) })
// @UsePipes(new ZodValidationPipe(createItemSchema)) // @UsePipes(new ZodValidationPipe(createItemSchema))
async createItem(@Body() createItemDto: any): Promise<number> { async createItem(@Body() createItemDto: IItemDTO): Promise<number> {
return this.itemsApplication.createItem(createItemDto); return this.itemsApplication.createItem(createItemDto);
} }
@@ -85,6 +153,12 @@ export class ItemsController extends TenantController {
description: 'The item has been successfully deleted.', description: 'The item has been successfully deleted.',
}) })
@ApiResponse({ status: 404, description: 'The item not found.' }) @ApiResponse({ status: 404, description: 'The item not found.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The item id',
})
async deleteItem(@Param('id') id: string): Promise<void> { async deleteItem(@Param('id') id: string): Promise<void> {
const itemId = parseInt(id, 10); const itemId = parseInt(id, 10);
return this.itemsApplication.deleteItem(itemId); return this.itemsApplication.deleteItem(itemId);
@@ -101,6 +175,12 @@ export class ItemsController extends TenantController {
description: 'The item has been successfully inactivated.', description: 'The item has been successfully inactivated.',
}) })
@ApiResponse({ status: 404, description: 'The item not found.' }) @ApiResponse({ status: 404, description: 'The item not found.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The item id',
})
async inactivateItem(@Param('id') id: string): Promise<void> { async inactivateItem(@Param('id') id: string): Promise<void> {
console.log(id, 'XXXXXX'); console.log(id, 'XXXXXX');
@@ -119,6 +199,12 @@ export class ItemsController extends TenantController {
description: 'The item has been successfully activated.', description: 'The item has been successfully activated.',
}) })
@ApiResponse({ status: 404, description: 'The item not found.' }) @ApiResponse({ status: 404, description: 'The item not found.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The item id',
})
async activateItem(@Param('id') id: string): Promise<void> { async activateItem(@Param('id') id: string): Promise<void> {
const itemId = parseInt(id, 10); const itemId = parseInt(id, 10);
return this.itemsApplication.activateItem(itemId); return this.itemsApplication.activateItem(itemId);
@@ -135,6 +221,12 @@ export class ItemsController extends TenantController {
description: 'The item has been successfully retrieved.', description: 'The item has been successfully retrieved.',
}) })
@ApiResponse({ status: 404, description: 'The item not found.' }) @ApiResponse({ status: 404, description: 'The item not found.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The item id',
})
async getItem(@Param('id') id: string): Promise<any> { async getItem(@Param('id') id: string): Promise<any> {
const itemId = parseInt(id, 10); const itemId = parseInt(id, 10);
return this.itemsApplication.getItem(itemId); return this.itemsApplication.getItem(itemId);
@@ -149,6 +241,17 @@ export class ItemsController extends TenantController {
@ApiOperation({ @ApiOperation({
summary: 'Retrieves the item associated invoices transactions.', summary: 'Retrieves the item associated invoices transactions.',
}) })
@ApiResponse({
status: 200,
description: 'The item associated invoices transactions have been successfully retrieved.',
})
@ApiResponse({ status: 404, description: 'The item not found.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The item id',
})
async getItemInvoicesTransactions(@Param('id') id: string): Promise<any> { async getItemInvoicesTransactions(@Param('id') id: string): Promise<any> {
const itemId = parseInt(id, 10); const itemId = parseInt(id, 10);
return this.itemsApplication.getItemInvoicesTransactions(itemId); return this.itemsApplication.getItemInvoicesTransactions(itemId);
@@ -163,6 +266,18 @@ export class ItemsController extends TenantController {
@ApiOperation({ @ApiOperation({
summary: 'Retrieves the item associated bills transactions.', summary: 'Retrieves the item associated bills transactions.',
}) })
@ApiResponse({
status: 200,
description:
'The item associated bills transactions have been successfully retrieved.',
})
@ApiResponse({ status: 404, description: 'The item not found.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The item id',
})
async getItemBillTransactions(@Param('id') id: string): Promise<any> { async getItemBillTransactions(@Param('id') id: string): Promise<any> {
const itemId = parseInt(id, 10); const itemId = parseInt(id, 10);
return this.itemsApplication.getItemBillTransactions(itemId); return this.itemsApplication.getItemBillTransactions(itemId);
@@ -179,9 +294,16 @@ export class ItemsController extends TenantController {
}) })
@ApiResponse({ @ApiResponse({
status: 200, status: 200,
description: 'The item associated estimate transactions have been successfully retrieved.', description:
'The item associated estimate transactions have been successfully retrieved.',
}) })
@ApiResponse({ status: 404, description: 'The item not found.' }) @ApiResponse({ status: 404, description: 'The item not found.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The item id',
})
async getItemEstimatesTransactions(@Param('id') id: string): Promise<any> { async getItemEstimatesTransactions(@Param('id') id: string): Promise<any> {
const itemId = parseInt(id, 10); const itemId = parseInt(id, 10);
return this.itemsApplication.getItemEstimatesTransactions(itemId); return this.itemsApplication.getItemEstimatesTransactions(itemId);
@@ -198,9 +320,16 @@ export class ItemsController extends TenantController {
}) })
@ApiResponse({ @ApiResponse({
status: 200, status: 200,
description: 'The item associated receipts transactions have been successfully retrieved.', description:
'The item associated receipts transactions have been successfully retrieved.',
}) })
@ApiResponse({ status: 404, description: 'The item not found.' }) @ApiResponse({ status: 404, description: 'The item not found.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The item id',
})
async getItemReceiptTransactions(@Param('id') id: string): Promise<any> { async getItemReceiptTransactions(@Param('id') id: string): Promise<any> {
const itemId = parseInt(id, 10); const itemId = parseInt(id, 10);
return this.itemsApplication.getItemReceiptsTransactions(itemId); return this.itemsApplication.getItemReceiptsTransactions(itemId);

View File

@@ -30,8 +30,11 @@ export interface ILedger {
} }
export interface ILedgerEntry { export interface ILedgerEntry {
id?: number;
credit: number; credit: number;
debit: number; debit: number;
currencyCode: string; currencyCode: string;
exchangeRate: number; exchangeRate: number;

View File

@@ -10,7 +10,7 @@ import {
import { ManualJournalsApplication } from './ManualJournalsApplication.service'; import { ManualJournalsApplication } from './ManualJournalsApplication.service';
import { IManualJournalDTO } from './types/ManualJournals.types'; import { IManualJournalDTO } from './types/ManualJournals.types';
import { PublicRoute } from '../Auth/Jwt.guard'; import { PublicRoute } from '../Auth/Jwt.guard';
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; import { ApiOperation, ApiParam, ApiResponse, ApiTags } from '@nestjs/swagger';
@Controller('manual-journals') @Controller('manual-journals')
@ApiTags('manual-journals') @ApiTags('manual-journals')
@@ -31,6 +31,12 @@ export class ManualJournalsController {
description: 'The manual journal has been successfully edited.', description: 'The manual journal has been successfully edited.',
}) })
@ApiResponse({ status: 404, description: 'The manual journal not found.' }) @ApiResponse({ status: 404, description: 'The manual journal not found.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The manual journal id',
})
public editManualJournal( public editManualJournal(
@Param('id') manualJournalId: number, @Param('id') manualJournalId: number,
@Body() manualJournalDTO: IManualJournalDTO, @Body() manualJournalDTO: IManualJournalDTO,
@@ -48,6 +54,12 @@ export class ManualJournalsController {
description: 'The manual journal has been successfully deleted.', description: 'The manual journal has been successfully deleted.',
}) })
@ApiResponse({ status: 404, description: 'The manual journal not found.' }) @ApiResponse({ status: 404, description: 'The manual journal not found.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The manual journal id',
})
public deleteManualJournal(@Param('id') manualJournalId: number) { public deleteManualJournal(@Param('id') manualJournalId: number) {
return this.manualJournalsApplication.deleteManualJournal(manualJournalId); return this.manualJournalsApplication.deleteManualJournal(manualJournalId);
} }
@@ -59,6 +71,12 @@ export class ManualJournalsController {
description: 'The manual journal has been successfully published.', description: 'The manual journal has been successfully published.',
}) })
@ApiResponse({ status: 404, description: 'The manual journal not found.' }) @ApiResponse({ status: 404, description: 'The manual journal not found.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The manual journal id',
})
public publishManualJournal(@Param('id') manualJournalId: number) { public publishManualJournal(@Param('id') manualJournalId: number) {
return this.manualJournalsApplication.publishManualJournal(manualJournalId); return this.manualJournalsApplication.publishManualJournal(manualJournalId);
} }
@@ -70,6 +88,12 @@ export class ManualJournalsController {
description: 'The manual journal details have been successfully retrieved.', description: 'The manual journal details have been successfully retrieved.',
}) })
@ApiResponse({ status: 404, description: 'The manual journal not found.' }) @ApiResponse({ status: 404, description: 'The manual journal not found.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The manual journal id',
})
public getManualJournal(@Param('id') manualJournalId: number) { public getManualJournal(@Param('id') manualJournalId: number) {
return this.manualJournalsApplication.getManualJournal(manualJournalId); return this.manualJournalsApplication.getManualJournal(manualJournalId);
} }

View File

@@ -1,19 +1,12 @@
import { CreateSaleEstimate } from './commands/CreateSaleEstimate.service'; import { CreateSaleEstimate } from './commands/CreateSaleEstimate.service';
import { import {
// IFilterMeta,
// IPaginationMeta,
// IPaymentReceivedSmsDetails,
ISaleEstimateDTO, ISaleEstimateDTO,
ISalesEstimatesFilter, ISalesEstimatesFilter,
SaleEstimateMailOptionsDTO, SaleEstimateMailOptionsDTO,
// ISalesEstimatesFilter,
// SaleEstimateMailOptions,
// SaleEstimateMailOptionsDTO,
} from './types/SaleEstimates.types'; } from './types/SaleEstimates.types';
import { EditSaleEstimate } from './commands/EditSaleEstimate.service'; import { EditSaleEstimate } from './commands/EditSaleEstimate.service';
import { DeleteSaleEstimate } from './commands/DeleteSaleEstimate.service'; import { DeleteSaleEstimate } from './commands/DeleteSaleEstimate.service';
import { GetSaleEstimate } from './queries/GetSaleEstimate.service'; import { GetSaleEstimate } from './queries/GetSaleEstimate.service';
// import { GetSaleEstimates } from './queries/GetSaleEstimates';
import { DeliverSaleEstimateService } from './commands/DeliverSaleEstimate.service'; import { DeliverSaleEstimateService } from './commands/DeliverSaleEstimate.service';
import { ApproveSaleEstimateService } from './commands/ApproveSaleEstimate.service'; import { ApproveSaleEstimateService } from './commands/ApproveSaleEstimate.service';
import { RejectSaleEstimateService } from './commands/RejectSaleEstimate.service'; import { RejectSaleEstimateService } from './commands/RejectSaleEstimate.service';
@@ -22,7 +15,6 @@ import { SendSaleEstimateMail } from './commands/SendSaleEstimateMail';
import { GetSaleEstimateState } from './queries/GetSaleEstimateState.service'; import { GetSaleEstimateState } from './queries/GetSaleEstimateState.service';
import { GetSaleEstimatesService } from './queries/GetSaleEstimates.service'; import { GetSaleEstimatesService } from './queries/GetSaleEstimates.service';
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { IFilterMeta, IPaginationMeta } from '@/interfaces/Model';
import { GetSaleEstimatePdf } from './queries/GetSaleEstimatePdf'; import { GetSaleEstimatePdf } from './queries/GetSaleEstimatePdf';
@Injectable() @Injectable()
@@ -141,9 +133,7 @@ export class SaleEstimatesApplication {
* @returns {Promise<[Buffer, string]>} * @returns {Promise<[Buffer, string]>}
*/ */
public getSaleEstimatePdf(saleEstimateId: number) { public getSaleEstimatePdf(saleEstimateId: number) {
return this.saleEstimatesPdfService.getSaleEstimatePdf( return this.saleEstimatesPdfService.getSaleEstimatePdf(saleEstimateId);
saleEstimateId,
);
} }
/** /**
@@ -168,9 +158,7 @@ export class SaleEstimatesApplication {
* @returns {Promise<SaleEstimateMailOptions>} * @returns {Promise<SaleEstimateMailOptions>}
*/ */
public getSaleEstimateMail(saleEstimateId: number) { public getSaleEstimateMail(saleEstimateId: number) {
return this.sendEstimateMailService.getMailOptions( return this.sendEstimateMailService.getMailOptions(saleEstimateId);
saleEstimateId,
);
} }
/** /**

View File

@@ -1,4 +1,4 @@
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; import { ApiOperation, ApiParam, ApiResponse, ApiTags } from '@nestjs/swagger';
import { import {
Body, Body,
Controller, Controller,
@@ -53,6 +53,12 @@ export class SaleEstimatesController {
status: 404, status: 404,
description: 'Sale estimate not found', description: 'Sale estimate not found',
}) })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The sale estimate id',
})
public editSaleEstimate( public editSaleEstimate(
@Param('id', ParseIntPipe) estimateId: number, @Param('id', ParseIntPipe) estimateId: number,
@Body() estimateDTO: ISaleEstimateDTO, @Body() estimateDTO: ISaleEstimateDTO,
@@ -73,6 +79,12 @@ export class SaleEstimatesController {
status: 404, status: 404,
description: 'Sale estimate not found', description: 'Sale estimate not found',
}) })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The sale estimate id',
})
public deleteSaleEstimate( public deleteSaleEstimate(
@Param('id', ParseIntPipe) estimateId: number, @Param('id', ParseIntPipe) estimateId: number,
): Promise<void> { ): Promise<void> {
@@ -105,6 +117,12 @@ export class SaleEstimatesController {
status: 200, status: 200,
description: 'Sale estimate delivered successfully', description: 'Sale estimate delivered successfully',
}) })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The sale estimate id',
})
public deliverSaleEstimate( public deliverSaleEstimate(
@Param('id', ParseIntPipe) saleEstimateId: number, @Param('id', ParseIntPipe) saleEstimateId: number,
): Promise<void> { ): Promise<void> {
@@ -113,6 +131,12 @@ export class SaleEstimatesController {
@Put(':id/approve') @Put(':id/approve')
@ApiOperation({ summary: 'Approve the given sale estimate.' }) @ApiOperation({ summary: 'Approve the given sale estimate.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The sale estimate id',
})
public approveSaleEstimate( public approveSaleEstimate(
@Param('id', ParseIntPipe) saleEstimateId: number, @Param('id', ParseIntPipe) saleEstimateId: number,
): Promise<void> { ): Promise<void> {
@@ -121,6 +145,12 @@ export class SaleEstimatesController {
@Put(':id/reject') @Put(':id/reject')
@ApiOperation({ summary: 'Reject the given sale estimate.' }) @ApiOperation({ summary: 'Reject the given sale estimate.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The sale estimate id',
})
public rejectSaleEstimate( public rejectSaleEstimate(
@Param('id', ParseIntPipe) saleEstimateId: number, @Param('id', ParseIntPipe) saleEstimateId: number,
): Promise<void> { ): Promise<void> {
@@ -129,6 +159,12 @@ export class SaleEstimatesController {
@Post(':id/notify-sms') @Post(':id/notify-sms')
@ApiOperation({ summary: 'Notify the given sale estimate by SMS.' }) @ApiOperation({ summary: 'Notify the given sale estimate by SMS.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The sale estimate id',
})
public notifySaleEstimateBySms( public notifySaleEstimateBySms(
@Param('id', ParseIntPipe) saleEstimateId: number, @Param('id', ParseIntPipe) saleEstimateId: number,
) { ) {
@@ -149,6 +185,12 @@ export class SaleEstimatesController {
@Get(':id/pdf') @Get(':id/pdf')
@ApiOperation({ summary: 'Retrieves the sale estimate PDF.' }) @ApiOperation({ summary: 'Retrieves the sale estimate PDF.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The sale estimate id',
})
public getSaleEstimatePdf(@Param('id', ParseIntPipe) saleEstimateId: number) { public getSaleEstimatePdf(@Param('id', ParseIntPipe) saleEstimateId: number) {
return this.saleEstimatesApplication.getSaleEstimatePdf(saleEstimateId); return this.saleEstimatesApplication.getSaleEstimatePdf(saleEstimateId);
} }
@@ -156,6 +198,12 @@ export class SaleEstimatesController {
@Post(':id/mail') @Post(':id/mail')
@HttpCode(200) @HttpCode(200)
@ApiOperation({ summary: 'Send the given sale estimate by mail.' }) @ApiOperation({ summary: 'Send the given sale estimate by mail.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The sale estimate id',
})
public sendSaleEstimateMail( public sendSaleEstimateMail(
@Param('id', ParseIntPipe) saleEstimateId: number, @Param('id', ParseIntPipe) saleEstimateId: number,
@Body() mailOptions: SaleEstimateMailOptionsDTO, @Body() mailOptions: SaleEstimateMailOptionsDTO,
@@ -168,6 +216,12 @@ export class SaleEstimatesController {
@Get(':id/mail') @Get(':id/mail')
@ApiOperation({ summary: 'Retrieves the sale estimate mail details.' }) @ApiOperation({ summary: 'Retrieves the sale estimate mail details.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The sale estimate id',
})
public getSaleEstimateMail( public getSaleEstimateMail(
@Param('id', ParseIntPipe) saleEstimateId: number, @Param('id', ParseIntPipe) saleEstimateId: number,
) { ) {
@@ -176,6 +230,12 @@ export class SaleEstimatesController {
@Get(':id') @Get(':id')
@ApiOperation({ summary: 'Retrieves the sale estimate details.' }) @ApiOperation({ summary: 'Retrieves the sale estimate details.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The sale estimate id',
})
public getSaleEstimate(@Param('id', ParseIntPipe) estimateId: number) { public getSaleEstimate(@Param('id', ParseIntPipe) estimateId: number) {
return this.saleEstimatesApplication.getSaleEstimate(estimateId); return this.saleEstimatesApplication.getSaleEstimate(estimateId);
} }

View File

@@ -20,10 +20,20 @@ import {
} from './SaleInvoice.types'; } from './SaleInvoice.types';
import { SaleInvoiceApplication } from './SaleInvoices.application'; import { SaleInvoiceApplication } from './SaleInvoices.application';
import { PublicRoute } from '../Auth/Jwt.guard'; import { PublicRoute } from '../Auth/Jwt.guard';
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; import { ApiHeader, ApiOperation, ApiParam, ApiResponse, ApiTags } from '@nestjs/swagger';
@Controller('sale-invoices') @Controller('sale-invoices')
@ApiTags('sale-invoices') @ApiTags('sale-invoices')
@ApiHeader({
name: 'organization-id',
description: 'The organization id',
required: true,
})
@ApiHeader({
name: 'x-access-token',
description: 'The authentication token',
required: true,
})
@PublicRoute() @PublicRoute()
export class SaleInvoicesController { export class SaleInvoicesController {
constructor(private saleInvoiceApplication: SaleInvoiceApplication) {} constructor(private saleInvoiceApplication: SaleInvoiceApplication) {}
@@ -44,6 +54,13 @@ export class SaleInvoicesController {
status: 200, status: 200,
description: 'Sale invoice mail sent successfully', description: 'Sale invoice mail sent successfully',
}) })
@ApiResponse({ status: 404, description: 'The sale invoice not found.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The sale invoice id',
})
sendSaleInvoiceMail( sendSaleInvoiceMail(
@Param('id', ParseIntPipe) id: number, @Param('id', ParseIntPipe) id: number,
@Body() messageDTO: SendInvoiceMailDTO, @Body() messageDTO: SendInvoiceMailDTO,
@@ -57,6 +74,13 @@ export class SaleInvoicesController {
status: 200, status: 200,
description: 'Sale invoice edited successfully', description: 'Sale invoice edited successfully',
}) })
@ApiResponse({ status: 404, description: 'The sale invoice not found.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The sale invoice id',
})
editSaleInvoice( editSaleInvoice(
@Param('id', ParseIntPipe) id: number, @Param('id', ParseIntPipe) id: number,
@Body() saleInvoiceDTO: ISaleInvoiceEditDTO, @Body() saleInvoiceDTO: ISaleInvoiceEditDTO,
@@ -66,36 +90,91 @@ export class SaleInvoicesController {
@Delete(':id') @Delete(':id')
@ApiOperation({ summary: 'Delete the given sale invoice.' }) @ApiOperation({ summary: 'Delete the given sale invoice.' })
@ApiResponse({
status: 200,
description: 'The sale invoice has been successfully deleted.',
})
@ApiResponse({ status: 404, description: 'The sale invoice not found.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The sale invoice id',
})
deleteSaleInvoice(@Param('id', ParseIntPipe) id: number) { deleteSaleInvoice(@Param('id', ParseIntPipe) id: number) {
return this.saleInvoiceApplication.deleteSaleInvoice(id); return this.saleInvoiceApplication.deleteSaleInvoice(id);
} }
@Get() @Get()
@ApiOperation({ summary: 'Retrieves the sale invoices.' }) @ApiOperation({ summary: 'Retrieves the sale invoices.' })
@ApiResponse({
status: 200,
description: 'The sale invoices have been successfully retrieved.',
})
getSaleInvoices(@Query() filterDTO: ISalesInvoicesFilter) { getSaleInvoices(@Query() filterDTO: ISalesInvoicesFilter) {
return this.saleInvoiceApplication.getSaleInvoices(filterDTO); return this.saleInvoiceApplication.getSaleInvoices(filterDTO);
} }
@Get(':id') @Get(':id')
@ApiOperation({ summary: 'Retrieves the sale invoice details.' }) @ApiOperation({ summary: 'Retrieves the sale invoice details.' })
@ApiResponse({
status: 200,
description: 'The sale invoice details have been successfully retrieved.',
})
@ApiResponse({ status: 404, description: 'The sale invoice not found.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The sale invoice id',
})
getSaleInvoice(@Param('id', ParseIntPipe) id: number) { getSaleInvoice(@Param('id', ParseIntPipe) id: number) {
return this.saleInvoiceApplication.getSaleInvoice(id); return this.saleInvoiceApplication.getSaleInvoice(id);
} }
@Get(':id/state') @Get(':id/state')
@ApiOperation({ summary: 'Retrieves the sale invoice state.' }) @ApiOperation({ summary: 'Retrieves the sale invoice state.' })
@ApiResponse({
status: 200,
description: 'The sale invoice state has been successfully retrieved.',
})
@ApiResponse({ status: 404, description: 'The sale invoice not found.' })
getSaleInvoiceState() { getSaleInvoiceState() {
return this.saleInvoiceApplication.getSaleInvoiceState(); return this.saleInvoiceApplication.getSaleInvoiceState();
} }
@Post(':id/deliver') @Post(':id/deliver')
@ApiOperation({ summary: 'Deliver the given sale invoice.' }) @ApiOperation({ summary: 'Deliver the given sale invoice.' })
@ApiResponse({
status: 200,
description: 'The sale invoice has been successfully marked asdelivered.',
})
@ApiResponse({ status: 404, description: 'The sale invoice not found.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The sale invoice id',
})
@HttpCode(200) @HttpCode(200)
deliverSaleInvoice(@Param('id', ParseIntPipe) id: number) { deliverSaleInvoice(@Param('id', ParseIntPipe) id: number) {
return this.saleInvoiceApplication.deliverSaleInvoice(id); return this.saleInvoiceApplication.deliverSaleInvoice(id);
} }
@Get('receivable/:customerId?') @Get('receivable/:customerId?')
@ApiOperation({ summary: 'Retrieves the receivable sale invoices.' })
@ApiResponse({
status: 200,
description:
'The receivable sale invoices have been successfully retrieved.',
})
@ApiResponse({ status: 404, description: 'The customer not found.' })
@ApiParam({
name: 'customerId',
required: false,
type: Number,
description: 'The customer id',
})
getReceivableSaleInvoices(@Param('customerId') customerId?: number) { getReceivableSaleInvoices(@Param('customerId') customerId?: number) {
return this.saleInvoiceApplication.getReceivableSaleInvoices(customerId); return this.saleInvoiceApplication.getReceivableSaleInvoices(customerId);
} }
@@ -103,6 +182,17 @@ export class SaleInvoicesController {
@Post(':id/writeoff') @Post(':id/writeoff')
@ApiOperation({ summary: 'Write off the given sale invoice.' }) @ApiOperation({ summary: 'Write off the given sale invoice.' })
@HttpCode(200) @HttpCode(200)
@ApiResponse({
status: 200,
description: 'The sale invoice has been successfully written off.',
})
@ApiResponse({ status: 404, description: 'The sale invoice not found.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The sale invoice id',
})
writeOff( writeOff(
@Param('id', ParseIntPipe) id: number, @Param('id', ParseIntPipe) id: number,
@Body() writeoffDTO: ISaleInvoiceWriteoffDTO, @Body() writeoffDTO: ISaleInvoiceWriteoffDTO,
@@ -112,6 +202,18 @@ export class SaleInvoicesController {
@Post(':id/cancel-writeoff') @Post(':id/cancel-writeoff')
@ApiOperation({ summary: 'Cancel the written off sale invoice.' }) @ApiOperation({ summary: 'Cancel the written off sale invoice.' })
@ApiResponse({
status: 200,
description:
'The sale invoice has been successfully marked as not written off.',
})
@ApiResponse({ status: 404, description: 'The sale invoice not found.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The sale invoice id',
})
@HttpCode(200) @HttpCode(200)
cancelWrittenoff(@Param('id', ParseIntPipe) id: number) { cancelWrittenoff(@Param('id', ParseIntPipe) id: number) {
return this.saleInvoiceApplication.cancelWrittenoff(id); return this.saleInvoiceApplication.cancelWrittenoff(id);
@@ -119,18 +221,39 @@ export class SaleInvoicesController {
@Get(':id/payments') @Get(':id/payments')
@ApiOperation({ summary: 'Retrieves the sale invoice payments.' }) @ApiOperation({ summary: 'Retrieves the sale invoice payments.' })
@ApiResponse({ status: 404, description: 'The sale invoice not found.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The sale invoice id',
})
getInvoicePayments(@Param('id', ParseIntPipe) id: number) { getInvoicePayments(@Param('id', ParseIntPipe) id: number) {
return this.saleInvoiceApplication.getInvoicePayments(id); return this.saleInvoiceApplication.getInvoicePayments(id);
} }
@Get(':id/pdf') @Get(':id/pdf')
@ApiOperation({ summary: 'Retrieves the sale invoice PDF.' }) @ApiOperation({ summary: 'Retrieves the sale invoice PDF.' })
@ApiResponse({ status: 404, description: 'The sale invoice not found.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The sale invoice id',
})
saleInvoicePdf(@Param('id', ParseIntPipe) id: number) { saleInvoicePdf(@Param('id', ParseIntPipe) id: number) {
return this.saleInvoiceApplication.saleInvoicePdf(id); return this.saleInvoiceApplication.saleInvoicePdf(id);
} }
@Get(':id/html') @Get(':id/html')
@ApiOperation({ summary: 'Retrieves the sale invoice HTML.' }) @ApiOperation({ summary: 'Retrieves the sale invoice HTML.' })
@ApiResponse({ status: 404, description: 'The sale invoice not found.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The sale invoice id',
})
saleInvoiceHtml(@Param('id', ParseIntPipe) id: number) { saleInvoiceHtml(@Param('id', ParseIntPipe) id: number) {
return this.saleInvoiceApplication.saleInvoiceHtml(id); return this.saleInvoiceApplication.saleInvoiceHtml(id);
} }
@@ -141,6 +264,13 @@ export class SaleInvoicesController {
status: 200, status: 200,
description: 'Sale invoice mail state retrieved successfully', description: 'Sale invoice mail state retrieved successfully',
}) })
@ApiResponse({ status: 404, description: 'The sale invoice not found.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The sale invoice id',
})
getSaleInvoiceMailState( getSaleInvoiceMailState(
@Param('id', ParseIntPipe) id: number, @Param('id', ParseIntPipe) id: number,
): Promise<SaleInvoiceMailState> { ): Promise<SaleInvoiceMailState> {

View File

@@ -12,7 +12,7 @@ import {
import { ISaleReceiptDTO } from './types/SaleReceipts.types'; import { ISaleReceiptDTO } from './types/SaleReceipts.types';
import { SaleReceiptApplication } from './SaleReceiptApplication.service'; import { SaleReceiptApplication } from './SaleReceiptApplication.service';
import { PublicRoute } from '../Auth/Jwt.guard'; import { PublicRoute } from '../Auth/Jwt.guard';
import { ApiOperation, ApiTags } from '@nestjs/swagger'; import { ApiOperation, ApiParam, ApiTags } from '@nestjs/swagger';
@Controller('sale-receipts') @Controller('sale-receipts')
@ApiTags('sale-receipts') @ApiTags('sale-receipts')
@@ -29,6 +29,12 @@ export class SaleReceiptsController {
@Put(':id/mail') @Put(':id/mail')
@HttpCode(200) @HttpCode(200)
@ApiOperation({ summary: 'Send the sale receipt mail.' }) @ApiOperation({ summary: 'Send the sale receipt mail.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The sale receipt id',
})
sendSaleReceiptMail(@Param('id', ParseIntPipe) id: number) { sendSaleReceiptMail(@Param('id', ParseIntPipe) id: number) {
return this.saleReceiptApplication.getSaleReceiptMail(id); return this.saleReceiptApplication.getSaleReceiptMail(id);
} }
@@ -36,12 +42,24 @@ export class SaleReceiptsController {
@Get(':id/mail') @Get(':id/mail')
@HttpCode(200) @HttpCode(200)
@ApiOperation({ summary: 'Retrieves the sale receipt mail.' }) @ApiOperation({ summary: 'Retrieves the sale receipt mail.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The sale receipt id',
})
getSaleReceiptMail(@Param('id', ParseIntPipe) id: number) { getSaleReceiptMail(@Param('id', ParseIntPipe) id: number) {
return this.saleReceiptApplication.getSaleReceiptMail(id); return this.saleReceiptApplication.getSaleReceiptMail(id);
} }
@Put(':id') @Put(':id')
@ApiOperation({ summary: 'Edit the given sale receipt.' }) @ApiOperation({ summary: 'Edit the given sale receipt.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The sale receipt id',
})
editSaleReceipt( editSaleReceipt(
@Param('id', ParseIntPipe) id: number, @Param('id', ParseIntPipe) id: number,
@Body() saleReceiptDTO: ISaleReceiptDTO, @Body() saleReceiptDTO: ISaleReceiptDTO,
@@ -51,24 +69,48 @@ export class SaleReceiptsController {
@Get(':id') @Get(':id')
@ApiOperation({ summary: 'Retrieves the sale receipt details.' }) @ApiOperation({ summary: 'Retrieves the sale receipt details.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The sale receipt id',
})
getSaleReceipt(@Param('id', ParseIntPipe) id: number) { getSaleReceipt(@Param('id', ParseIntPipe) id: number) {
return this.saleReceiptApplication.getSaleReceipt(id); return this.saleReceiptApplication.getSaleReceipt(id);
} }
@Delete(':id') @Delete(':id')
@ApiOperation({ summary: 'Delete the given sale receipt.' }) @ApiOperation({ summary: 'Delete the given sale receipt.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The sale receipt id',
})
deleteSaleReceipt(@Param('id', ParseIntPipe) id: number) { deleteSaleReceipt(@Param('id', ParseIntPipe) id: number) {
return this.saleReceiptApplication.deleteSaleReceipt(id); return this.saleReceiptApplication.deleteSaleReceipt(id);
} }
@Post(':id/close') @Post(':id/close')
@ApiOperation({ summary: 'Close the given sale receipt.' }) @ApiOperation({ summary: 'Close the given sale receipt.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The sale receipt id',
})
closeSaleReceipt(@Param('id', ParseIntPipe) id: number) { closeSaleReceipt(@Param('id', ParseIntPipe) id: number) {
return this.saleReceiptApplication.closeSaleReceipt(id); return this.saleReceiptApplication.closeSaleReceipt(id);
} }
@Get(':id/pdf') @Get(':id/pdf')
@ApiOperation({ summary: 'Retrieves the sale receipt PDF.' }) @ApiOperation({ summary: 'Retrieves the sale receipt PDF.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The sale receipt id',
})
getSaleReceiptPdf(@Param('id', ParseIntPipe) id: number) { getSaleReceiptPdf(@Param('id', ParseIntPipe) id: number) {
return this.saleReceiptApplication.getSaleReceiptPdf(0, id); return this.saleReceiptApplication.getSaleReceiptPdf(0, id);
} }