4481- Print service refactor #1064
|
@ -1783,6 +1783,11 @@ INSERT INTO `vn`.`claimEnd`(`id`, `saleFk`, `claimFk`, `workerFk`, `claimDestina
|
||||||
(1, 31, 4, 21, 2),
|
(1, 31, 4, 21, 2),
|
||||||
(2, 32, 3, 21, 3);
|
(2, 32, 3, 21, 3);
|
||||||
|
|
||||||
|
INSERT INTO `vn`.`claimConfig`(`id`, `pickupContact`, `maxResponsibility`)
|
||||||
|
VALUES
|
||||||
|
(1, 'Contact description', 50),
|
||||||
|
(2, 'Contact description', 30);
|
||||||
|
|
||||||
INSERT INTO `hedera`.`tpvMerchant`(`id`, `description`, `companyFk`, `bankFk`, `secretKey`)
|
INSERT INTO `hedera`.`tpvMerchant`(`id`, `description`, `companyFk`, `bankFk`, `secretKey`)
|
||||||
VALUES
|
VALUES
|
||||||
(1, 'Arkham Bank', 442, 1, 'h12387193H10238'),
|
(1, 'Arkham Bank', 442, 1, 'h12387193H10238'),
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
const {Report, Email, smtp} = require('vn-print');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('claimPickupEmail', {
|
||||||
|
description: 'Sends the the claim pickup order email with an attached PDF',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
description: 'The client id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'recipient',
|
||||||
|
type: 'string',
|
||||||
|
description: 'The recipient email',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'replyTo',
|
||||||
|
type: 'string',
|
||||||
|
description: 'The sender email to reply to',
|
||||||
|
required: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'recipientId',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The recipient id to send to the recipient preferred language',
|
||||||
|
required: false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
returns: {
|
||||||
|
type: ['object'],
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: '/:id/claim-pickup-email',
|
||||||
|
verb: 'POST'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.claimPickupEmail = async(ctx, id) => {
|
||||||
|
const args = Object.assign({}, ctx.args);
|
||||||
|
const params = {
|
||||||
|
recipient: args.recipient,
|
||||||
|
lang: ctx.req.getLocale()
|
||||||
|
};
|
||||||
|
|
||||||
|
delete args.ctx;
|
||||||
|
for (const param in args)
|
||||||
|
params[param] = args[param];
|
||||||
|
|
||||||
|
const email = new Email('claim-pickup-order', params);
|
||||||
|
|
||||||
|
return email.send();
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,55 @@
|
||||||
|
const { Report } = require('vn-print');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('claimPickupPdf', {
|
||||||
|
description: 'Returns the claim pickup order 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/claim-pickup-pdf',
|
||||||
|
verb: 'GET'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.claimPickupPdf = 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('claim-pickup-order', params);
|
||||||
|
const stream = await report.toPdfStream();
|
||||||
|
|
||||||
|
return [stream, 'application/pdf', `filename="doc-${id}.pdf"`];
|
||||||
|
};
|
||||||
|
};
|
|
@ -9,4 +9,6 @@ module.exports = Self => {
|
||||||
require('../methods/claim/isEditable')(Self);
|
require('../methods/claim/isEditable')(Self);
|
||||||
require('../methods/claim/updateClaimDestination')(Self);
|
require('../methods/claim/updateClaimDestination')(Self);
|
||||||
require('../methods/claim/downloadFile')(Self);
|
require('../methods/claim/downloadFile')(Self);
|
||||||
|
require('../methods/claim/claimPickupPdf')(Self);
|
||||||
|
require('../methods/claim/claimPickupEmail')(Self);
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,11 +5,15 @@
|
||||||
<slot-menu>
|
<slot-menu>
|
||||||
<vn-item
|
<vn-item
|
||||||
ng-click="$ctrl.showPickupOrder()"
|
ng-click="$ctrl.showPickupOrder()"
|
||||||
|
vn-acl="salesPerson"
|
||||||
|
vn-acl-action="remove"
|
||||||
translate>
|
translate>
|
||||||
Show Pickup order
|
Show Pickup order
|
||||||
</vn-item>
|
</vn-item>
|
||||||
<vn-item
|
<vn-item
|
||||||
ng-click="confirmPickupOrder.show()"
|
ng-click="confirmPickupOrder.show()"
|
||||||
|
vn-acl="salesPerson"
|
||||||
|
vn-acl-action="remove"
|
||||||
translate>
|
translate>
|
||||||
Send Pickup order
|
Send Pickup order
|
||||||
</vn-item>
|
</vn-item>
|
||||||
|
|
|
@ -11,17 +11,15 @@ class Controller extends Descriptor {
|
||||||
}
|
}
|
||||||
|
|
||||||
showPickupOrder() {
|
showPickupOrder() {
|
||||||
this.vnReport.show('claim-pickup-order', {
|
this.vnReport.show(`Claims/${this.claim.id}/claim-pickup-pdf`, {
|
||||||
recipientId: this.claim.clientFk,
|
recipientId: this.claim.clientFk
|
||||||
claimId: this.claim.id
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
sendPickupOrder() {
|
sendPickupOrder() {
|
||||||
return this.vnEmail.send('claim-pickup-order', {
|
return this.vnEmail.send(`Claims/${this.claim.id}/claim-pickup-email`, {
|
||||||
recipient: this.claim.client.email,
|
recipient: this.claim.client.email,
|
||||||
recipientId: this.claim.clientFk,
|
recipientId: this.claim.clientFk
|
||||||
claimId: this.claim.id
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ const { Report } = require('vn-print');
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('campaignMetricsPdf', {
|
Self.remoteMethodCtx('campaignMetricsPdf', {
|
||||||
description: 'Returns the delivery note pdf',
|
description: 'Returns the campaign metrics note pdf',
|
||||||
accepts: [
|
accepts: [
|
||||||
{
|
{
|
||||||
arg: 'id',
|
arg: 'id',
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
const Stylesheet = require(`${appPath}/core/stylesheet`);
|
const Stylesheet = require(`vn-print/core/stylesheet`);
|
||||||
|
|
||||||
|
const path = require('path');
|
||||||
|
const vnPrintPath = path.resolve('print');
|
||||||
|
|
||||||
module.exports = new Stylesheet([
|
module.exports = new Stylesheet([
|
||||||
`${appPath}/common/css/spacing.css`,
|
`${vnPrintPath}/common/css/spacing.css`,
|
||||||
`${appPath}/common/css/misc.css`,
|
`${vnPrintPath}/common/css/misc.css`,
|
||||||
`${appPath}/common/css/layout.css`,
|
`${vnPrintPath}/common/css/layout.css`,
|
||||||
`${appPath}/common/css/email.css`])
|
`${vnPrintPath}/common/css/email.css`])
|
||||||
.mergeStyles();
|
.mergeStyles();
|
|
@ -1,4 +1,4 @@
|
||||||
const Component = require(`${appPath}/core/component`);
|
const Component = require(`vn-print/core/component`);
|
||||||
const emailHeader = new Component('email-header');
|
const emailHeader = new Component('email-header');
|
||||||
const emailFooter = new Component('email-footer');
|
const emailFooter = new Component('email-footer');
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ module.exports = {
|
||||||
'email-footer': emailFooter.build()
|
'email-footer': emailFooter.build()
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
claimId: {
|
id: {
|
||||||
type: [Number, String],
|
type: [Number, String],
|
||||||
required: true
|
required: true
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
const Stylesheet = require(`${appPath}/core/stylesheet`);
|
const Stylesheet = require(`vn-print/core/stylesheet`);
|
||||||
|
|
||||||
|
const path = require('path');
|
||||||
|
const vnPrintPath = path.resolve('print');
|
||||||
|
|
||||||
module.exports = new Stylesheet([
|
module.exports = new Stylesheet([
|
||||||
`${appPath}/common/css/spacing.css`,
|
`${vnPrintPath}/common/css/spacing.css`,
|
||||||
`${appPath}/common/css/misc.css`,
|
`${vnPrintPath}/common/css/misc.css`,
|
||||||
`${appPath}/common/css/layout.css`,
|
`${vnPrintPath}/common/css/layout.css`,
|
||||||
`${appPath}/common/css/report.css`,
|
`${vnPrintPath}/common/css/report.css`,
|
||||||
`${__dirname}/style.css`])
|
`${__dirname}/style.css`])
|
||||||
.mergeStyles();
|
.mergeStyles();
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
const Component = require(`${appPath}/core/component`);
|
const Component = require(`vn-print/core/component`);
|
||||||
const reportHeader = new Component('report-header');
|
const reportHeader = new Component('report-header');
|
||||||
const reportFooter = new Component('report-footer');
|
const reportFooter = new Component('report-footer');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'claim-pickup-order',
|
name: 'claim-pickup-order',
|
||||||
async serverPrefetch() {
|
async serverPrefetch() {
|
||||||
this.client = await this.fetchClient(this.claimId);
|
this.client = await this.fetchClient(this.id);
|
||||||
this.sales = await this.fetchSales(this.claimId);
|
this.sales = await this.fetchSales(this.id);
|
||||||
this.claimConfig = await this.fetchClaimConfig();
|
this.claimConfig = await this.fetchClaimConfig();
|
||||||
|
|
||||||
if (!this.client)
|
if (!this.client)
|
||||||
|
@ -20,11 +20,11 @@ module.exports = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
fetchClient(claimId) {
|
fetchClient(id) {
|
||||||
return this.findOneFromDef('client', [claimId]);
|
return this.findOneFromDef('client', [id]);
|
||||||
},
|
},
|
||||||
fetchSales(claimId) {
|
fetchSales(id) {
|
||||||
return this.rawSqlFromDef('sales', [claimId]);
|
return this.rawSqlFromDef('sales', [id]);
|
||||||
},
|
},
|
||||||
fetchClaimConfig() {
|
fetchClaimConfig() {
|
||||||
return this.findOneFromDef('claimConfig');
|
return this.findOneFromDef('claimConfig');
|
||||||
|
@ -35,7 +35,7 @@ module.exports = {
|
||||||
'report-footer': reportFooter.build()
|
'report-footer': reportFooter.build()
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
claimId: {
|
id: {
|
||||||
type: [Number, String],
|
type: [Number, String],
|
||||||
required: true
|
required: true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue