<?xml version="1.0" encoding="UTF-8"?>
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03">
  <CstmrCdtTrfInitn>
    <GrpHdr>
      <MsgId><%=@prelevement_date.strftime("%d/%m/%Y").to_slug %>-<%= @m_odr_remise.id %></MsgId>
      <CreDtTm><%= Time.now.to_time.utc.iso8601 %></CreDtTm>
      <NbOfTxs><%= @m_odr_virements.count %></NbOfTxs>
      <CtrlSum><%= '%.2f' % @m_odr_virements.sum(:amount) %></CtrlSum>
      <InitgPty>
        <Nm><%= @name %></Nm>
      </InitgPty>
    </GrpHdr>
    <PmtInf>
      <PmtInfId><%= @prelevement_date.strftime("%d/%m/%Y") %></PmtInfId>
      <PmtMtd>TRF</PmtMtd>
			<BtchBookg>false</BtchBookg>
      <NbOfTxs><%= @m_odr_virements.count %></NbOfTxs>
      <CtrlSum><%= '%.2f' % @m_odr_virements.sum(:amount) %></CtrlSum>
      <PmtTpInf>
        <SvcLvl>
          <Cd>SEPA</Cd>
        </SvcLvl>
      </PmtTpInf>
      <ReqdExctnDt><%= @prelevement_date.strftime("%Y-%m-%d") %></ReqdExctnDt>
      <Dbtr>
        <Nm><%= @name %></Nm>
      </Dbtr>
      <DbtrAcct>
        <Id>
          <IBAN><%= @iban %></IBAN>
        </Id>
      </DbtrAcct>
      <DbtrAgt>
        <FinInstnId>
          <BIC><%= @bic %></BIC>
        </FinInstnId>
      </DbtrAgt>
      <ChrgBr>SLEV</ChrgBr>
      
      
      <% @m_odr_virements.all.each do |m_odr_virement| %>
      <CdtTrfTxInf>
        <PmtId>
          <EndToEndId><%= m_odr_virement.token %></EndToEndId>
        </PmtId>
        <Amt>
          <InstdAmt Ccy="EUR"><%= '%.2f' % m_odr_virement.amount %></InstdAmt>
        </Amt>
        
        <Cdtr>
          <Nm><%= m_odr_virement.m_odr_rep.long_name %></Nm>
        </Cdtr>
				
        <CdtrAgt>
          <FinInstnId>
            <BIC><%= m_odr_virement.bic_to %></BIC>
          </FinInstnId>
        </CdtrAgt>
				
				
        <CdtrAcct>
          <Id>
            <IBAN><%= m_odr_virement.iban_to.gsub(" ", "") %></IBAN>
          </Id>
        </CdtrAcct>
        <RmtInf>
          <Ustrd><%= m_odr_virement.token %></Ustrd>
        </RmtInf>
      </CdtTrfTxInf>
			
      <% end %>
      
    </PmtInf>
  </CstmrDrctDbtInitn>
</Document>
