<?xml version="1.0" encoding="UTF-8"?>
<Document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.02">
  <pain.001.001.02>
    <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>
			<Grpg>MIXD</Grpg>
			<InitgPty>
				<Nm><%= @name %></Nm>
				<Id>
					<OrgId>
						<PrtryId>
							<Id>123456700011</Id>
						</PrtryId>
					</OrgId>
				</Id>
			</InitgPty>
			
			
    </GrpHdr>
    <PmtInf>
      <PmtInfId><%= @prelevement_date.strftime("%d/%m/%Y") %></PmtInfId>
      <PmtMtd>TRF</PmtMtd>
      <PmtTpInf>
        <SvcLvl>
          <Cd>SEPA</Cd>
        </SvcLvl>
      </PmtTpInf>
      <ReqdExctnDt><%= @prelevement_date.strftime("%Y-%m-%d") %></ReqdExctnDt>
      <Dbtr>
        <Nm><%= @name %></Nm>
      </Dbtr>
      <DbtrAcct>
        <Id>
          <IBAN><%= @iban.upcase.to_s.gsub(" ", "") %></IBAN>
        </Id>
      </DbtrAcct>
      <DbtrAgt>
        <FinInstnId>
          <BIC><%= @bic.upcase.to_s.gsub(" ", "") %></BIC>
        </FinInstnId>
      </DbtrAgt>
      <ChrgBr>SLEV</ChrgBr>
      
      
      <% @m_odr_virements.all.each do |m_odr_virement| %>
      <CdtTrfTxInf>
        <PmtId>
					<InstrId>ABC<%= m_odr_virement.token %></InstrId>
          <EndToEndId><%= m_odr_virement.token %></EndToEndId>
        </PmtId>
        <Amt>
          <InstdAmt Ccy="EUR"><%= '%.2f' % m_odr_virement.amount %></InstdAmt>
        </Amt>
        
        <CdtrAgt>
          <FinInstnId>
            <BIC><%= m_odr_virement.bic_to.upcase %></BIC>
          </FinInstnId>
        </CdtrAgt>
				
        <Cdtr>
          <Nm><%= m_odr_virement.m_odr_rep.long_name %></Nm>
        </Cdtr>
				
        
				
				
        <CdtrAcct>
          <Id>
            <IBAN><%= m_odr_virement.iban_to.upcase.gsub(" ", "") %></IBAN>
          </Id>
        </CdtrAcct>
        <RmtInf>
          <Ustrd><%= m_odr_virement.token %></Ustrd>
        </RmtInf>
      </CdtTrfTxInf>
			
      <% end %>
      
    </PmtInf>
  </pain.001.001.02>
</Document>
