info:
  name: elixPro - Recupero importi inseriti
  type: http
  seq: 25

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`
        [EFTL][HEADER name="trimDocument" value="true" type="boolean" /]
        [!--
        [% insertCodiciFiscali = "RSSNDR76L16I153I##CHPLCU79H14G337H##RSSNDR76L16I153I##GNTLDN64A67D643P##GNTLDN64A67D643P##CHPLCU79H14G337H"; %]
        [% insertImporti = "1234,56##7890,12##456321,87##14,25##888##777"; %]
        [% insertModalita = "Fuori orario di lavoro##In orario di lavoro##In orario di lavoro##In orario di lavoro##Fuori orario di lavoro##Fuori orario di lavoro"; %]
        --]
        [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]

        CF: [%= codiciFiscaliIterable %]
        IM: [%= importiIterable %]
        MO: [%= modalitaIterable %]
        CN: [%= insertCount %]

        [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][!-- Nominativo --]
        [VAR name="item2" type="number"][% item2 = 1; %][/VAR][!-- Codice fiscale --]
        [VAR name="item3" type="number"][% item3 = 2; %][/VAR][!-- Qualifica --]
        [VAR name="item4" type="number"][% item4 = 3; %][/VAR][!-- Struttura --]
        [VAR name="item5" type="number"][% item5 = 4; %][/VAR][!-- Importo --]

        <table>
          <tr>
            <th>Nominativo</th>
            <th>Codice fiscale</th>
            <th>Qualifica</th>
            <th>Struttura</th>
            <th>Importo (&euro;)</th>
          </tr>[FOR varName="ripartizione" iterable="datiRipartizioneIterable"] [% modalita = ""; %] [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 < 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 && 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 && 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]
          <tr>
            <td>[VALUE_OF varname="datiIterable" index="item1" /]</td>
            <td>[VALUE_OF varname="datiIterable" index="item2" /]</td>
            <td>[VALUE_OF varname="datiIterable" index="item3" /]</td>
            <td>[VALUE_OF varname="datiIterable" index="item4" /]</td>
            <td style="text-align: right;">[FORMAT type="number" pattern="#,##0.00"][VALUE_OF varname="datiIterable" index="item5" /][/FORMAT]</td>
          </tr>
          [IF] [CONDITION][% importoDentro == 0 && importoFuori == 0 %][/CONDITION] [THEN][/THEN] [ELSE]
          <tr>
            <td colspan="3"></td>
            <td style="text-align: right;">di cui in orario di lavoro</td>
            <td style="text-align: right;">[FORMAT type="number" pattern="#,##0.00"][VALUE_OF varname="importoDentro" /][/FORMAT]</td>
          </tr>
          <tr>
            <td colspan="3"></td>
            <td style="text-align: right;">fuori orario di lavoro</td>
            <td style="text-align: right;">[FORMAT type="number" pattern="#,##0.00"][VALUE_OF varname="importoFuori" /][/FORMAT]</td>
          </tr>
          [/ELSE] [/IF]
          [/FOR]
        </table>

        [!--
        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 
        --]

        [/EFTL]
        `);

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