hotFix(receipt): add receiptPdf
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
32dcdf8f8d
commit
6a17a634d4
|
@ -0,0 +1,55 @@
|
|||
const {Report} = require('vn-print');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('receiptPdf', {
|
||||
description: 'Returns the receipt pdf',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'id',
|
||||
type: 'number',
|
||||
required: true,
|
||||
description: 'The claim id',
|
||||
http: {source: 'path'}
|
||||
},
|
||||
{
|
||||
arg: 'recipientId',
|
||||
type: 'number',
|
||||
description: 'The recipient id',
|
||||
required: false
|
||||
}
|
||||
],
|
||||
returns: [
|
||||
{
|
||||
arg: 'body',
|
||||
type: 'file',
|
||||
root: true
|
||||
}, {
|
||||
arg: 'Content-Type',
|
||||
type: 'String',
|
||||
http: {target: 'header'}
|
||||
}, {
|
||||
arg: 'Content-Disposition',
|
||||
type: 'String',
|
||||
http: {target: 'header'}
|
||||
}
|
||||
],
|
||||
http: {
|
||||
path: '/:id/receipt-pdf',
|
||||
verb: 'GET'
|
||||
}
|
||||
});
|
||||
|
||||
Self.receiptPdf = async(ctx, id) => {
|
||||
const args = Object.assign({}, ctx.args);
|
||||
const params = {lang: ctx.req.getLocale()};
|
||||
|
||||
delete args.ctx;
|
||||
for (const param in args)
|
||||
params[param] = args[param];
|
||||
|
||||
const report = new Report('receipt', params);
|
||||
const stream = await report.toPdfStream();
|
||||
|
||||
return [stream, 'application/pdf', `filename="doc-${id}.pdf"`];
|
||||
};
|
||||
};
|
|
@ -2,6 +2,7 @@ const LoopBackContext = require('loopback-context');
|
|||
|
||||
module.exports = function(Self) {
|
||||
require('../methods/receipt/filter')(Self);
|
||||
require('../methods/receipt/receiptPdf')(Self);
|
||||
|
||||
Self.validateBinded('amountPaid', isNotZero, {
|
||||
message: 'Amount cannot be zero',
|
||||
|
|
|
@ -144,12 +144,8 @@ class Controller extends Dialog {
|
|||
})
|
||||
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')))
|
||||
.then(() => {
|
||||
if (this.viewReceipt) {
|
||||
this.vnReport.show('receipt', {
|
||||
receiptId: receiptId,
|
||||
companyId: this.companyFk
|
||||
});
|
||||
}
|
||||
if (this.viewReceipt)
|
||||
this.vnReport.show(`Receipts/${receiptId}/receipt-pdf`);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -85,6 +85,8 @@ describe('Client', () => {
|
|||
});
|
||||
|
||||
it('should make an http POST query and then call to the report show() method', () => {
|
||||
const receiptId = 1;
|
||||
|
||||
jest.spyOn(controller.vnApp, 'showSuccess');
|
||||
jest.spyOn(controller.vnReport, 'show');
|
||||
window.open = jest.fn();
|
||||
|
@ -92,14 +94,12 @@ describe('Client', () => {
|
|||
controller.$params = {id: 1101};
|
||||
controller.viewReceipt = true;
|
||||
|
||||
$httpBackend.expect('POST', `Clients/1101/createReceipt`).respond({id: 1});
|
||||
$httpBackend.expect('POST', `Clients/1101/createReceipt`).respond({id: receiptId});
|
||||
controller.responseHandler('accept');
|
||||
$httpBackend.flush();
|
||||
|
||||
const expectedParams = {receiptId: 1, companyId: 442};
|
||||
|
||||
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
||||
expect(controller.vnReport.show).toHaveBeenCalledWith('receipt', expectedParams);
|
||||
expect(controller.vnReport.show).toHaveBeenCalledWith(`Receipts/${receiptId}/receipt-pdf`);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue