info:
  name: elixPro - Template Delibera
  type: http
  seq: 28

http:
  method: POST
  url: "{{elixFormsApiUrl}}/eftl/process/v1"
  headers:
    - name: x-requested-with
      value: XMLHttpRequest
    - name: x-api-key
      value: "{{elixFormsWsAuthenticationToken}}"
    - name: x-ef-request-id
      value: "31630"
    - name: x-ef-request-id
      value: "31499"
      disabled: true
    - name: x-ef-request-id
      value: "31801"
      disabled: true
  body:
    type: json
    data: |-
      {
        "userDocument": "{{elixBase64EftlDocument}}", // see the pre-request script
        "userContext": {
          "lang": "IT",
          "crlf": "\r\n"
        }
      }
  auth: inherit

runtime:
  scripts:
    - type: before-request
      code: |-
        const { prepareEftlDocument } = require("./elixFormsJs.js")
        // Copy-pasta your EFTL document below inside the template literals (`)
        prepareEftlDocument(String.raw`
        <!DOCTYPE html>
        <html>
        [EFTL]
        <head>
        <style>
        body {
          font-family: Calibri, Arial, Sans-serif;
          font-size: 10pt;
          text-align: justify;
        }

        @media print {
          @page {
            size: A4;
            margin-top: 4cm !important;
            margin-right: 2cm !important;
            margin-bottom: 2cm !important;
            margin-left: 2cm !important;
            
            @top-left {
              margin: 0;
              width: 45%;
              background-image: url("https://procedure.unipr.it/UploadImgs/8_marchio_UNIPR_pos_b1_small.png");
              background-attachment: fixed;
              background-repeat: no-repeat;
              background-position: 2cm 0.5cm;
              padding-top: 95px;
              padding-left: 90px;
              content: "[TAG]GETVALUEBYTAG,STRUTTURA_PRINCIPALE_DESC_UPPER,REQUEST,ID_OBJECT[/TAG]";
              font-family: Calibri, Arial, Sans-serif;
              font-size: 11pt;
              font-weight: bold;
              text-align: left;
              color: #005ab9;
            }

            @bottom-center {
              margin: 0px;
              content: url("https://procedure.unipr.it/UploadImgs/9_text4.png");
              font-size: 8pt;
              font-weight: bold;
              text-align: center;
              color: #005ab9;
            }

            body {
              font-family: Calibri, Arial, Sans-serif;
              font-size: 10pt;
              text-align: justify;
            }

            td {
              text-align: left;
            }
          }
        }
        </style>
        </head>
        <body>
        <div>&nbsp;</div>
        <div>Il direttore sottopone al Consiglio la richiesta pervenuta da [TAG]GETVALUEBYTAG,RICHIEDENTE_NOMINATIVO,REQUEST,ID_OBJECT[/TAG], (corredata dalla documentazione richiesta dalla procedura per la liquidazione dei compensi e acquisita al protocollo di dipartimento col num. <span style="background-color: #ffff00;">NUM_PROT</span> del <span style="background-color: #ffff00;">DATA_PROT</span>), con la quale il richiedente, in qualit&agrave; di Responsabile Scientifico del contratto di tipologia &ldquo;[TAG]SCHEMAID,542,COL0003,ID_OBJECT, , [/TAG]&rdquo; dal titolo &ldquo;[TAG]GETVALUEBYTAG,TITOLO_CONTRATTO,REQUEST,ID_OBJECT[/TAG]&rdquo; stipulato con [TAG]GETVALUEBYTAG,CONTRATTO_CONTRAENTI,REQUEST,ID_OBJECT[/TAG], chiede di ripartire gli utili sul contratto su menzionato come segue:</div>
        <div>&nbsp;</div>
        <div>&nbsp;</div>
        <div>[VAR name="insertCodiciFiscali" type="string"][TAG]SCHEMAID,862,COL0001,IUQOID, ,##[/TAG][/VAR] [VAR name="insertImporti" type="string"][TAG]SCHEMAID,862,COL0002,IUQOID, ,##[/TAG][/VAR] [VAR name="insertModalita" type="string"][TAG]SCHEMAID,862,COL0003,IUQOID, ,##[/TAG][/VAR] [VAR name="codiciFiscaliIterable" type="iterable"][SPLIT regex="##"][VALUE_OF varname="insertCodiciFiscali" /][/SPLIT][/VAR] [VAR name="importiIterable" type="iterable"][SPLIT regex="##"][VALUE_OF varname="insertImporti" /][/SPLIT][/VAR] [VAR name="modalitaIterable" type="iterable"][SPLIT regex="##"][VALUE_OF varname="insertModalita" /][/SPLIT][/VAR] [VAR name="insertCount" type="number"][SIZE_OF varname="codiciFiscaliIterable" /][/VAR] [VAR name="datiRipartizioneIterable" type="iterable"][SPLIT regex="##" emptyIfBlank="true"][TAG]GETVALUEBYTAG,RIPARTIZIONE_DATI_COMPLETI,REQUEST,IUQOID,CONCAT,##[/TAG][/SPLIT][/VAR] [VAR name="item1" type="number"][% item1 = 0; %][/VAR] [VAR name="item2" type="number"][% item2 = 1; %][/VAR] [VAR name="item3" type="number"][% item3 = 2; %][/VAR] [VAR name="item4" type="number"][% item4 = 3; %][/VAR] [VAR name="item5" type="number"][% item5 = 4; %][/VAR] &lt;table style='width: 95%; margin: 0 auto;'&gt; &lt;tr&gt; &lt;th&gt;Nominativo&lt;/th&gt; &lt;th&gt;Codice fiscale&lt;/th&gt; &lt;th&gt;Qualifica&lt;/th&gt; &lt;th&gt;Struttura&lt;/th&gt; &lt;th&gt;Importo (&euro;)&lt;/th&gt; &lt;/tr&gt;[FOR varName="ripartizione" iterable="datiRipartizioneIterable"] [VAR name="datiIterable" type="iterable"][SPLIT regex=";;" emptyIfBlank="true"][VALUE_OF varname="ripartizione" /][/SPLIT][/VAR] [VAR name="importoDentro" type="number"][% importoDentro = 0; %][/VAR] [VAR name="importoFuori" type="number"][% importoFuori = 0; %][/VAR] [% insertIdx = 0; %] [WHILE threshold="99"] [CONDITION][% insertIdx &lt; insertCount %][/CONDITION] [DO] [VAR name="codiceFiscaleCorrente"][VALUE_OF varname="datiIterable" index="item2" /][/VAR] [VAR name="codiceFiscale"][VALUE_OF varname="codiciFiscaliIterable" index="insertIdx" /][/VAR] [VAR name="modalita"][VALUE_OF varname="modalitaIterable" index="insertIdx" /][/VAR] [VAR name="importo"][VALUE_OF varname="importiIterable" index="insertIdx" /][/VAR] [IF] [CONDITION][% codiceFiscale == codiceFiscaleCorrente &amp;&amp; modalita == "In orario di lavoro" %][/CONDITION] [THEN][VAR name="importoDentro" type="number"][VALUE_OF varname="importiIterable" index="insertIdx" /][/VAR][/THEN] [/IF] [IF] [CONDITION][% codiceFiscale == codiceFiscaleCorrente &amp;&amp; modalita == "Fuori orario di lavoro" %][/CONDITION] [THEN][VAR name="importoFuori" type="number"][VALUE_OF varname="importiIterable" index="insertIdx" /][/VAR][/THEN] [/IF] [% insertIdx = insertIdx + 1; %] [/DO] [/WHILE] &lt;tr&gt; &lt;td style='text-align: left;'&gt;[VALUE_OF varname="datiIterable" index="item1" /]&lt;/td&gt; &lt;td&gt;[VALUE_OF varname="datiIterable" index="item2" /]&lt;/td&gt; &lt;td&gt;[VALUE_OF varname="datiIterable" index="item3" /]&lt;/td&gt; &lt;td&gt;[VALUE_OF varname="datiIterable" index="item4" /]&lt;/td&gt; &lt;td style='text-align: right;'&gt;[FORMAT type="number" pattern="#,##0.00"][VALUE_OF varname="datiIterable" index="item5" /][/FORMAT]&lt;/td&gt; &lt;/tr&gt; [IF] [CONDITION][% importoDentro == 0 && importoFuori == 0 %][/CONDITION] [THEN][/THEN] [ELSE]&lt;tr&gt; &lt;td colspan="4" style='text-align: right;'&gt;di cui in orario di lavoro&lt;/td&gt; &lt;td style='text-align: right;'&gt;[VALUE_OF varname="importoDentro" /]&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="4" style='text-align: right;'&gt;fuori orario di lavoro&lt;/td&gt; &lt;td style='text-align: right;'&gt;[VALUE_OF varname="importoFuori" /]&lt;/td&gt; &lt;/tr&gt;[/ELSE] [/IF] [/FOR] &lt;/table&gt;</div>
        <div>&nbsp;</div>
        <div>&nbsp;</div>
        <div>A seguito di discussione, il Consiglio adotta la seguente delibera:</div>
        <div>&nbsp;</div>
        <div>&nbsp;</div>
        <div><span style="background-color: #ffff00;">TESTO DELIBERA</span></div>
        <div>&nbsp;</div>
        <div>&nbsp;</div>
        <div><span style="background-color: #ffff00;">__/AAAA/__</span> Approvazione della ripartizione di Utili richiesta da [TAG]GETVALUEBYTAG,RICHIEDENTE_NOMINATIVO,REQUEST,ID_OBJECT[/TAG],[% ripartizioneIdx = 0; %][FOR varName="ripartizione" iterable="datiRipartizioneIterable"][VAR name="datiIterable" type="iterable"][SPLIT regex=";;" emptyIfBlank="true"][VALUE_OF varname="ripartizione" /][/SPLIT][/VAR] di [FORMAT type="number" pattern="currency"][VALUE_OF varname="datiIterable" index="item5" /][/FORMAT] a [VALUE_OF varname="datiIterable" index="item1" /],[/FOR] e autorizzazione alla U.O. Stipendi e Compensi al pagamento dei compensi per un importo lordo comprensivo totale di [FORMAT type="number" pattern="currency"][TAG]GETVALUEBYTAG,RIPARTIZIONI_TOTALE_PROPOSTA,REQUEST,ID_OBJECT[/TAG][/FORMAT] da imputare al Budget dell&rsquo;anno <span style="background-color: #ffff00;">YYYY</span> assegnato alla <span style="background-color: #ffff00;">UA.XX.Y.ZZZ1</span>, Progetto [TAG]GETVALUEBYTAG,ID_CONTRATTO,REQUEST,ID_OBJECT[/TAG], vincolo n. <span style="background-color: #ffff00;">NNNN</span>;</div>
        <p>&nbsp;</p>
        <div>Il Consiglio, preso atto di quanto illustrato da [TAG]GETVALUEBYTAG,RSP_TITOLO,REQUEST,ID_OBJECT[/TAG]&nbsp;[TAG]GETVALUEBYTAG,RSP_COGNOME,REQUEST,ID_OBJECT[/TAG]&nbsp;[TAG]GETVALUEBYTAG,RSP_NOME,REQUEST,ID_OBJECT[/TAG], esprime parere favorevole all&rsquo;approvazione della ripartizione di Utili richiesta da [TAG]GETVALUEBYTAG,RICHIEDENTE_NOMINATIVO,REQUEST,ID_OBJECT[/TAG], e d&agrave; mandato agli uffici dell&rsquo;Amministrazione Centrale per ogni successivo adempimento necessario al suo perfezionamento.</div>
        </body>
        [/EFTL]
        </html>
        `);
    - type: after-response
      code: |-
        var status = res.status;

        if (status !== 200) {
          console.log("ERRORE HTTP! Response status code: " + status);
          return;
        }

        var decodedDocument = "";
        var response = res.getBody();

        if (response.value.code === "ERROR") {
          decodedDocument = "ERRORE EFTL!\n";
          decodedDocument += response.value.description.split("\n").slice(0, 3).join("\n");
        }
        else {
          decodedDocument = atob(response.value.processedDocument);
        }

        bru.visualize('html', {
          name: 'HTML',
          content: decodedDocument
        });

settings:
  encodeUrl: true
  timeout: 0
  followRedirects: true
  maxRedirects: 5
  forwardAuthorizationHeader: true
