<?xml version="1.0" encoding="UTF-8"?>
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.09">{o.lang=en-us}{o.timezone=Europe/Berlin}{#sepa($text, $max) = $text:unaccent:replace('ß', 'ss'):substr(0, $max)}
  <CstmrCdtTrfInitn>
    <GrpHdr>
      <MsgId>{d.messageId}</MsgId>
      <CreDtTm>{d.createdAt:formatD('YYYY-MM-DDTHH:mm:ssZ')}</CreDtTm>
      <NbOfTxs>{d.batches[].payments[].amount:aggCount}</NbOfTxs>
      <CtrlSum>{d.batches[].payments[].amount:aggSum:formatN(2):replace(',', '')}</CtrlSum>
      <InitgPty>
        <Nm>{$sepa(d.debtor.name, 70):replace('&amp;', '+')}</Nm>
      </InitgPty>
    </GrpHdr>{d.batches[i]}
    <PmtInf>
      <PmtInfId>{d.batches[i].id}</PmtInfId>
      <PmtMtd>TRF</PmtMtd>
      <BtchBookg>{d.batches[i].batchBooking}</BtchBookg>
      <NbOfTxs>{d.batches[i].payments[].amount:aggCount}</NbOfTxs>
      <CtrlSum>{d.batches[i].payments[].amount:aggSum:formatN(2):replace(',', '')}</CtrlSum>
      <PmtTpInf>
        <SvcLvl>
          <Cd>SEPA</Cd>
        </SvcLvl>
        <CtgyPurp>
          <Cd>SUPP</Cd>
        </CtgyPurp>
      </PmtTpInf>
      <ReqdExctnDt>
        <Dt>{d.batches[i].executionDate:formatD('YYYY-MM-DD')}</Dt>
      </ReqdExctnDt>
      <Dbtr>
        <Nm>{$sepa(d.debtor.name, 70):replace('&amp;', '+')}</Nm>
        <PstlAdr>
          <StrtNm>{$sepa(d.debtor.street, 70)}</StrtNm>
          <BldgNb>{d.debtor.buildingNumber}</BldgNb>
          <PstCd>{d.debtor.postCode}</PstCd>
          <TwnNm>{$sepa(d.debtor.town, 35)}</TwnNm>
          <Ctry>{d.debtor.country}</Ctry>
        </PstlAdr>
      </Dbtr>
      <DbtrAcct>
        <Id>
          <IBAN>{d.debtor.iban}</IBAN>
        </Id>
      </DbtrAcct>
      <DbtrAgt>
        <FinInstnId>
          <BICFI>{d.debtor.bic}</BICFI>
        </FinInstnId>
      </DbtrAgt>
      <ChrgBr>SLEV</ChrgBr>{d.batches[i].payments[i]}
      <CdtTrfTxInf>
        <PmtId>
          <EndToEndId>{d.batches[i].payments[i].endToEndId}</EndToEndId>
        </PmtId>
        <Amt>
          <InstdAmt Ccy="EUR">{d.batches[i].payments[i].amount:formatN(2):replace(',', '')}</InstdAmt>
        </Amt>{d.batches[i].payments[i].supplier.bic:ifNEM:showBegin}
        <CdtrAgt>
          <FinInstnId>
            <BICFI>{d.batches[i].payments[i].supplier.bic}</BICFI>
          </FinInstnId>
        </CdtrAgt>{d.batches[i].payments[i].supplier.bic:showEnd}
        <Cdtr>
          <Nm>{$sepa(d.batches[i].payments[i].supplier.name, 70):replace('&amp;', '+')}</Nm>
          <PstlAdr>
            <StrtNm>{$sepa(d.batches[i].payments[i].supplier.street, 70)}</StrtNm>
            <BldgNb>{d.batches[i].payments[i].supplier.buildingNumber}</BldgNb>
            <PstCd>{d.batches[i].payments[i].supplier.postCode}</PstCd>
            <TwnNm>{$sepa(d.batches[i].payments[i].supplier.town, 35)}</TwnNm>
            <Ctry>{d.batches[i].payments[i].supplier.country}</Ctry>
          </PstlAdr>
        </Cdtr>
        <CdtrAcct>
          <Id>
            <IBAN>{d.batches[i].payments[i].supplier.iban}</IBAN>
          </Id>
        </CdtrAcct>
        <RmtInf>{d.batches[i].payments[i].creditorReference:ifNEM:showBegin}
          <Strd>
            <CdtrRefInf>
              <Tp>
                <CdOrPrtry>
                  <Cd>SCOR</Cd>
                </CdOrPrtry>
                <Issr>ISO</Issr>
              </Tp>
              <Ref>{d.batches[i].payments[i].creditorReference}</Ref>
            </CdtrRefInf>
          </Strd>{d.batches[i].payments[i].creditorReference:showEnd}{d.batches[i].payments[i].creditorReference:ifEM:showBegin}
          <Ustrd>Inv. {d.batches[i].payments[i].invoices[].number:aggStr(', ')}, cust. no. {d.batches[i].payments[i].customerNumber}</Ustrd>{d.batches[i].payments[i].creditorReference:showEnd}
        </RmtInf>
      </CdtTrfTxInf>{d.batches[i].payments[i+1]}
    </PmtInf>{d.batches[i+1]}
  </CstmrCdtTrfInitn>
</Document>
