fix(server): hotbug the invoice and payment receipt printing

This commit is contained in:
Ahmed Bouhuolia
2024-01-20 15:51:57 +02:00
parent 03bc78a068
commit 8f431597d9
5 changed files with 34 additions and 57 deletions

View File

@@ -56,5 +56,5 @@ GOTENBERG_URL=http://gotenberg:3000
GOTENBERG_DOCS_URL=http://server:3000/public/ GOTENBERG_DOCS_URL=http://server:3000/public/
# Gotenberg API - (development) # Gotenberg API - (development)
# GOTENBERG_URL=http://gotenberg:3000 # GOTENBERG_URL=http://localhost:9000
# GOTENBERG_DOCS_URL=http://server:3000/public/ # GOTENBERG_DOCS_URL=http://host.docker.internal:3000/public/

View File

@@ -418,33 +418,26 @@ export default class SaleInvoicesController extends BaseController {
* @param {Request} req - Request object. * @param {Request} req - Request object.
* @param {Response} res - Response object. * @param {Response} res - Response object.
*/ */
private async getSaleInvoice( private async getSaleInvoice(req: Request, res: Response) {
req: Request,
res: Response,
next: NextFunction
) {
const { id: saleInvoiceId } = req.params; const { id: saleInvoiceId } = req.params;
const { tenantId, user } = req; const { tenantId, user } = req;
try { // Response formatter.
return res.format({
// JSON content type.
[ACCEPT_TYPE.APPLICATION_JSON]: async () => {
const saleInvoice = await this.saleInvoiceApplication.getSaleInvoice( const saleInvoice = await this.saleInvoiceApplication.getSaleInvoice(
tenantId, tenantId,
saleInvoiceId, saleInvoiceId,
user user
); );
// Response formatter. return res.status(200).send(this.transfromToResponse({ saleInvoice }));
res.format({
// JSON content type.
[ACCEPT_TYPE.APPLICATION_JSON]: () => {
return res
.status(200)
.send(this.transfromToResponse({ saleInvoice }));
}, },
// PDF content type. // PDF content type.
[ACCEPT_TYPE.APPLICATION_PDF]: async () => { [ACCEPT_TYPE.APPLICATION_PDF]: async () => {
const pdfContent = await this.saleInvoiceApplication.saleInvoicePdf( const pdfContent = await this.saleInvoiceApplication.saleInvoicePdf(
tenantId, tenantId,
saleInvoice saleInvoiceId
); );
res.set({ res.set({
'Content-Type': 'application/pdf', 'Content-Type': 'application/pdf',
@@ -453,9 +446,6 @@ export default class SaleInvoicesController extends BaseController {
res.send(pdfContent); res.send(pdfContent);
}, },
}); });
} catch (error) {
next(error);
}
} }
/** /**
* Retrieve paginated sales invoices with custom view metadata. * Retrieve paginated sales invoices with custom view metadata.

View File

@@ -1,8 +1,7 @@
import { Inject, Service } from 'typedi'; import { Inject, Service } from 'typedi';
import { ChromiumlyTenancy } from '@/services/ChromiumlyTenancy/ChromiumlyTenancy'; import { ChromiumlyTenancy } from '@/services/ChromiumlyTenancy/ChromiumlyTenancy';
import { TemplateInjectable } from '@/services/TemplateInjectable/TemplateInjectable'; import { TemplateInjectable } from '@/services/TemplateInjectable/TemplateInjectable';
import HasTenancyService from '@/services/Tenancy/TenancyService'; import { GetSaleInvoice } from './GetSaleInvoice';
import { CommandSaleInvoiceValidators } from './CommandSaleInvoiceValidators';
@Service() @Service()
export class SaleInvoicePdf { export class SaleInvoicePdf {
@@ -13,10 +12,7 @@ export class SaleInvoicePdf {
private templateInjectable: TemplateInjectable; private templateInjectable: TemplateInjectable;
@Inject() @Inject()
private validators: CommandSaleInvoiceValidators; private getInvoiceService: GetSaleInvoice;
@Inject()
private tenancy: HasTenancyService;
/** /**
* Retrieve sale invoice pdf content. * Retrieve sale invoice pdf content.
@@ -28,18 +24,10 @@ export class SaleInvoicePdf {
tenantId: number, tenantId: number,
invoiceId: number invoiceId: number
): Promise<Buffer> { ): Promise<Buffer> {
const { SaleInvoice } = this.tenancy.models(tenantId); const saleInvoice = await this.getInvoiceService.getSaleInvoice(
tenantId,
const saleInvoice = await SaleInvoice.query() invoiceId
.findById(invoiceId) );
.withGraphFetched('entries.item')
.withGraphFetched('entries.tax')
.withGraphFetched('customer')
.withGraphFetched('taxes.taxRate');
// Validates the given sale invoice existance.
this.validators.validateInvoiceExistance(saleInvoice);
const htmlContent = await this.templateInjectable.render( const htmlContent = await this.templateInjectable.render(
tenantId, tenantId,
'modules/invoice-regular', 'modules/invoice-regular',

View File

@@ -8,7 +8,7 @@ export class PaymentReceiveEntryTransfromer extends Transformer {
* @returns {Array} * @returns {Array}
*/ */
public includeAttributes = (): string[] => { public includeAttributes = (): string[] => {
return ['paymentAmountFormatted', 'entry']; return ['paymentAmountFormatted', 'invoice'];
}; };
/** /**

View File

@@ -1,7 +1,6 @@
import { IPaymentReceive, IPaymentReceiveEntry } from '@/interfaces'; import { IPaymentReceive, IPaymentReceiveEntry } from '@/interfaces';
import { Transformer } from '@/lib/Transformer/Transformer'; import { Transformer } from '@/lib/Transformer/Transformer';
import { formatNumber } from 'utils'; import { formatNumber } from 'utils';
import { SaleInvoiceTransformer } from '../Invoices/SaleInvoiceTransformer';
import { PaymentReceiveEntryTransfromer } from './PaymentReceiveEntryTransformer'; import { PaymentReceiveEntryTransfromer } from './PaymentReceiveEntryTransformer';
export class PaymentReceiveTransfromer extends Transformer { export class PaymentReceiveTransfromer extends Transformer {