Skip to content

Commit

Permalink
Merge pull request #105 from pagopa/feat-add-partial-registration
Browse files Browse the repository at this point in the history
Feat add partial registration
  • Loading branch information
jacopocarlini authored May 14, 2024
2 parents 6b8da6d + 05fec20 commit 82b5206
Show file tree
Hide file tree
Showing 34 changed files with 8,224 additions and 8,451 deletions.
15,820 changes: 7,390 additions & 8,430 deletions node/package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "",
"scripts": {
"start": "node ./pdf-generate/index.js",
"start-detached" : "node ./pdf-generate/index.js > /dev/null 2>&1 &",
"start-detached": "node ./pdf-generate/index.js > /dev/null 2>&1 &",
"dev": "nodemon ./pdf-generate/index.js",
"test": "jest",
"test:coverage": "jest --coverage"
Expand All @@ -13,14 +13,14 @@
"adm-zip": "^0.5.10",
"applicationinsights": "^1.7.4",
"axios": "^1.5.0",
"bitgener": "^1.2.12",
"chromium": "^3.0.3",
"express": "^4.18.2",
"fs-extra": "^11.1.1",
"handlebars": "^4.7.8",
"puppeteer": "^22.4.0",
"multer": "^1.4.5-lts.1",
"nodemon": "^3.0.1",
"puppeteer": "^18.0.2",
"bitgener": "^1.2.12",
"puppeteer": "^22.0.0",
"qrcode-svg": "^1.1.0",
"uuid": "^9.0.1"
},
Expand Down
10 changes: 7 additions & 3 deletions node/pdf-generate/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ const generatePdf = async function (req, res, next) {
fse.outputFile(path.join(workingDir, zipEntry.entryName), zipEntry.getData(), err => {
if(err) {
console.log(err);
} else {
console.log('The file has been saved!');
}
});
}
Expand All @@ -72,6 +70,7 @@ const generatePdf = async function (req, res, next) {

let data = req.body.data;
let title = req.body.title;
let renderMode = req.body.renderMode || 'handlebar';

if (title == undefined) {
title = "Documento PDF PagoPA";
Expand All @@ -85,12 +84,14 @@ const generatePdf = async function (req, res, next) {
}

try {

const jsonData = JSON.parse(data);
let templateFile = readFileSync(path.join(workingDir, "template.html")).toString();
let template = handlebars.compile(templateFile);
const jsonData = JSON.parse(data);
jsonData.tempPath = workingDir;
let html = template(jsonData);
fs.writeFileSync(path.join(workingDir, "compiledTemplate.html"), html);

} catch (err) {
console.log(err)
res.status(500);
Expand All @@ -103,6 +104,8 @@ const generatePdf = async function (req, res, next) {
await page.goto('file:' + path.join(workingDir, "compiledTemplate.html"), {
waitUntil: ['load','domcontentloaded']
});
// path, can be relative or absolute path
//await page.addStyleTag({path: path.join(workingDir, "style.css")});
await waitForRender(page);
await page.pdf({
path: path.join(workingDir, "pagopa-receipt.pdf"),
Expand All @@ -124,6 +127,7 @@ const generatePdf = async function (req, res, next) {
res.send(content);

} catch (err) {
console.log(err);
res.status(500);
res.json(buildResponseBody(500, 'PDFE_902', "Error generating the PDF document"));
} finally {
Expand Down
5 changes: 5 additions & 0 deletions node/pdf-generate/helpers/commons/add.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function add(value, addition) {
return value + addition;
}

module.exports = add;
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions node/pdf-generate/helpers/commons/slice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function slice(arr, start, end) {
return !Array.isArray(arr)
? []
: arr.slice(start, typeof end === "number" ? end : undefined);
}

module.exports = slice;
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ const bitgener = require('bitgener');
const { v4: uuidv4 } = require("uuid");
const path = require('path');

function genDataMatrix(data, path) {
const filename = path.join(saveDir,uuidv4()+".svg");
function genDataMatrix(data, saveDir) {
const filename = path.join(
saveDir,uuidv4()+".svg");
bitgener({
data: data,
type: 'datamatrix',
Expand Down
File renamed without changes.
13 changes: 13 additions & 0 deletions node/pdf-generate/helpers/notices/getPaymentMethodCopy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function getPaymentMethodCopy(website, app) {
if (website && app) {
return "sul sito o app dell'ente, ";
} else if (website && !app) {
return "sul sito dell'ente, ";
} else if (!website && app) {
return "sull'app dell'ente, ";
} else {
return null;
}
}

module.exports = getPaymentMethodCopy;
14 changes: 14 additions & 0 deletions node/pdf-generate/partials/notices/header.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<header class="notice-header">
<section class="main">
<div class="pagopa-header">
<img class="logo" src="assets/pagoPa-logo.svg" />
<p class="h4 notice-title">Avviso di pagamento</p>
</div>
<div class="notice-subject">
<h1 class="h1">{{notice.subject}}</h1>
</div>
</section>
{{#if payee.logo}}
<img class="notice-header-logo" alt="{{payee.name}}" src="{{payee.logo}}" />
{{/if}}
</header>
34 changes: 34 additions & 0 deletions node/pdf-generate/partials/notices/mainInfo.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<section class="notice-main-info">
<div class="payee-title-block start-separator">
<h3 class="small-caps-title">Ente creditore</h3>
<p class="data-small">{{payee.taxCode}}</p>
</div>

<div class="payee-name-block start-grid-cell">
<p class="h2">{{payee.name}}</p>
</div>

<div class="payee-sector-block start-grid-cell">
<p class="h3">{{payee.sector}}</p>
</div>

<div class="payee-info-block start-grid-cell">
<p class="body">{{payee.additionalInfo}}</p>
</div>

<div class="debtor-title-block end-separator">
<h3 class="small-caps-title">Destinatario</h3>
<p class="data-small uppercase">{{debtor.taxCode}}</p>
</div>

<div class="debtor-name-block end-grid-cell">
<p class="h2 forcedCapitalCase">{{lowercase debtor.fullName}}</p>
</div>

<div class="debtor-address-block end-grid-cell">
<p class="h3">
{{debtor.address}} {{debtor.buildingNumber}}<br />
{{debtor.postalCode}} {{debtor.city}} ({{debtor.province}})
</p>
</div>
</section>
86 changes: 86 additions & 0 deletions node/pdf-generate/partials/notices/paymentBollettino.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<div class="payment-details unique-grid-cell">
<div class="poste-italiane-area">
<img class="logo-poste-italiane" src="assets/poste/poste-italiane.svg" alt="Poste Italiane" />
<img class="logo-bollettino-postale" src="assets/poste/bollettino-postale.svg"
alt="circuito bollettino postale BancoPosta" />
<p class="body">Bollettino Postale pagabile in tutti gli Uffici Postali e sui canali fisici o
digitali abilitati di Poste Italiane e dell’Ente Creditore</p>
<p class="caption">
{{notice.posteAuth}}
</p>
</div>

<div class="payment-details-data">

<div class="account-number-and-amount">
<div class="account-number">
<img class="euro-block" src="assets/poste/euro-block.svg" alt="Euro" />
<dl class="data-key-value-inline-monospaced">
<dt>sul C/C n.</dt>
<dd>{{notice.posteAccountNumber}}</dd>
</dl>
</div>

<dl class="data-key-value-inline-monospaced align-right">
<dt>Euro</dt>
<dd>{{this.amount}}</dd>
</dl>
</div>

<div class="payment-details-and-datamatrix">

<div class="payment-details-data-1st-block">

<dl class="data-key-value-inline">
<dt>Intestato a</dt>
<dd>{{payee.name}}</dd>
</dl>


<dl class="data-key-value-inline">
<dt>Destinatario</dt>
<dd class="forcedCapitalCase">{{lowercase debtor.fullName}}</dd>
</dl>


<dl class="data-key-value-inline">
<dt>Oggetto pagamento</dt>
<dd>{{notice.subject}}</dd>
</dl>


</div>

<div class="payment-details-data-2nd-block">

<div class="grid-cell-span-4">
<dl class="data-key-value-monospaced">
<dt>Cod. Avviso</dt>
<dd>{{splitAndSpace this.refNumber}}</dd>
</dl>
</div>

<div class="grid-cell-span-1">
<dl class="data-key-value-monospaced">
<dt>Tipo</dt>
<dd>P1</dd>
</dl>
</div>

<div class="grid-cell-span-3 align-right">
<dl class="data-key-value-monospaced">
<dt>Cod. Fiscale Ente Creditore</dt>
<dd>{{payee.taxCode}}</dd>
</dl>
</div>


</div>

<div class="payment-data-matrix">
<img src={{genDataMatrix this.posteDataMatrix this.tempPath}} alt="Poste DataMatrix" />
</div>
</div>

</div>
</div>
23 changes: 23 additions & 0 deletions node/pdf-generate/partials/notices/paymentData.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<section class="notice-payment-data">
<div class="unique-separator">
<h3 class="small-caps-title">
{{#if title}}
{{title}}
{{else}}
Dati per il pagamento
{{/if}}
</h3>
{{#if subtitle}}
{{{subtitle}}}
{{else}}
{{#if notice.expiryDate}}
<p class='h4'>Rata unica entro il {{notice.expiryDate}}</p>
{{else}}
<p class='h4'>Rata unica</p>
{{/if}}
{{/if}}
</div>

{{> paymentQR}}

</section>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<section class="notice-payment-data">
<div class="unique-separator">
<h3 class="small-caps-title">Dati per il pagamento</h3>
</div>

<section class="instalment-payment-data" style="--columns: 3">

{{#each (slice notice.instalments.items 0 3)}}

<div>
<div class="inner-separator">
<h3 class="small-caps-title">Rata {{add @index 1}}</h3>
</div>
{{#with this}}
{{> paymentQRColCompact
debtor=../debtor
notice=../notice
payee=../payee
tempPath=../tempPath
}}
{{/with}}
</div>

{{/each}}

</section>

</section>
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<section class="notice-payment-data">
<div class="unique-separator">
<h3 class="small-caps-title">Dati per il pagamento</h3>
</div>

<div class="payment-data-compact unique-grid-cell">
<div class="payment-data-compact-row">
<dl class="data-key-value">
<dt>Destinatario</dt>
<dd class="forcedCapitalCase">{{lowercase debtor.fullName}}</dd>
</dl>
<dl class="data-key-value">
<dt>Ente creditore</dt>
<dd>{{payee.name}}</dd>
</dl>
<dl class="data-key-value">
<dt>Oggetto del pagamento</dt>
<dd>{{notice.subject}}</dd>
</dl>
</div>
</div>

<section class="instalment-payment-data" style="--columns: 3">

{{#each (slice notice.instalments.items 3)}}

<div>
<div class="inner-separator">
<h3 class="small-caps-title">Rata {{add @index 4}}</h3>
</div>
{{#with this}}
{{> paymentQRColDense
payee=../payee
tempPath=../tempPath
}}
{{/with}}
</div>

{{/each}}

</section>

</section>
Loading

0 comments on commit 82b5206

Please sign in to comment.