<?xml version="1.0" encoding="UTF-8"?>
<ubl:Invoice xmlns:ubl="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
             xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
             xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">
    <cbc:CustomizationID>urn:cen.eu:en16931:2017#compliant#urn:xeinkauf.de:kosit:xrechnung_3.0</cbc:CustomizationID>
    <cbc:ProfileID>urn:fdc:peppol.eu:2017:poacc:billing:01:1.0</cbc:ProfileID>
    <cbc:ID>{{ doc.ident }}</cbc:ID>
    <cbc:IssueDate>{{ doc.dateStrISO }}</cbc:IssueDate>
    <cbc:InvoiceTypeCode>380</cbc:InvoiceTypeCode>
    <cbc:Note>#ADU#Es gelten unsere Allgem. Geschäftsbedingungen, die Sie unter […] finden.</cbc:Note>
    <cbc:DocumentCurrencyCode>EUR</cbc:DocumentCurrencyCode>
    <cbc:BuyerReference>{{ doc.buyerReference }}</cbc:BuyerReference>
    <cac:ProjectReference>
      <cbc:ID>{{ doc.projectLabel|default:"not set" }}</cbc:ID>
   </cac:ProjectReference>
   
   <cac:AccountingSupplierParty>
       <cac:Party>
           <cbc:EndpointID schemeID="EM">seller@email.de</cbc:EndpointID>
           <cac:PartyName>
               <cbc:Name>[Seller trading name]</cbc:Name>
           </cac:PartyName>
           <cac:PostalAddress>
               <cbc:StreetName>[Seller address line 1]</cbc:StreetName>
               <cbc:CityName>[Seller city]</cbc:CityName>
               <cbc:PostalZone>12345</cbc:PostalZone>
               <cac:Country>
                   <cbc:IdentificationCode>DE</cbc:IdentificationCode>
               </cac:Country>
           </cac:PostalAddress>
           <cac:PartyTaxScheme>
               <cbc:CompanyID>DE 123456789</cbc:CompanyID>
               <cac:TaxScheme>
                   <cbc:ID>VAT</cbc:ID>
               </cac:TaxScheme>
           </cac:PartyTaxScheme>
           <cac:PartyLegalEntity>
               <cbc:RegistrationName>[Seller name]</cbc:RegistrationName>
               <cbc:CompanyID>[HRA-Eintrag]</cbc:CompanyID>
               <cbc:CompanyLegalForm>123/456/7890, HRA-Eintrag in […]</cbc:CompanyLegalForm>
           </cac:PartyLegalEntity>
           <cac:Contact>
               <cbc:Name>nicht vorhanden</cbc:Name>
               <cbc:Telephone>+49 1234-5678</cbc:Telephone>
               <cbc:ElectronicMail>seller@email.de</cbc:ElectronicMail>
           </cac:Contact>
        </cac:Party>
    </cac:AccountingSupplierParty>
    
   <cac:AccountingCustomerParty>
        <cac:Party>
            {% if customer.EMAIL %}
            <cbc:EndpointID schemeID="EM">{{ customer.EMAIL }}</cbc:EndpointID>
            {% endif %}
            <cac:PartyName><cbc:Name>{{ customer.NAME|default:"not set" }}</cbc:Name></cac:PartyName> 
            <cac:PostalAddress>
                <cbc:StreetName>{{ customer.STREET|default:"not set" }}</cbc:StreetName>
                <cbc:CityName>{{ customer.LOCALITY|default:"not set" }}</cbc:CityName>
                <cbc:PostalZone>{{ customer.POSTCODE|default:"not set" }}</cbc:PostalZone>
                <cac:Country>
                    <cbc:IdentificationCode>DE</cbc:IdentificationCode>
                </cac:Country>
            </cac:PostalAddress>
            <cac:PartyLegalEntity>
                <cbc:RegistrationName>{{ customer.ORGANISATION|default:"not set" }}</cbc:RegistrationName>
            </cac:PartyLegalEntity>
            <cac:Contact>
                <cbc:Name>{{ customer.NAME|default:"not set" }}</cbc:Name>
                {% if costumer.EMAIL %}
                <cbc:ElectronicMail>{{ customer.EMAIL }}</cbc:ElectronicMail>
                {% endif %}
                {% if customer.PHONE %}
                <cbc:Telephone>{{ customer.PHONE }}</cbc:Telephone>
                {% endif %}
            </cac:Contact>
        </cac:Party>
    </cac:AccountingCustomerParty>
    <cac:PaymentMeans>
        <cbc:PaymentMeansCode>58</cbc:PaymentMeansCode>
        <cac:PayeeFinancialAccount>
            <!-- dies ist eine nicht existerende aber valide IBAN als test dummy -->
            <cbc:ID>DE75512108001245126199</cbc:ID>
        </cac:PayeeFinancialAccount>
    </cac:PaymentMeans>
    <cac:PaymentTerms>
        <cbc:Note>Zahlbar sofort ohne Abzug.</cbc:Note>
    </cac:PaymentTerms>
    <cac:TaxTotal>
        <cbc:TaxAmount currencyID="EUR">{{ doc.taxSumNum }}</cbc:TaxAmount>
        <cac:TaxSubtotal>
            <cbc:TaxableAmount currencyID="EUR">{{ doc.nettoSumNum }}</cbc:TaxableAmount>
            <cbc:TaxAmount currencyID="EUR">{{ doc.taxSumNum }}</cbc:TaxAmount>
            <cac:TaxCategory>
                <cbc:ID>S</cbc:ID>
                <cbc:Percent>{{ doc.fullTaxPercentNum }}</cbc:Percent>
                <cac:TaxScheme>
                    <cbc:ID>VAT</cbc:ID>
                </cac:TaxScheme>
            </cac:TaxCategory>
        </cac:TaxSubtotal>
    </cac:TaxTotal>
    
    <cac:LegalMonetaryTotal>
      <cbc:LineExtensionAmount currencyID="EUR">{{ doc.nettoSumNum }}</cbc:LineExtensionAmount>
      <cbc:TaxExclusiveAmount currencyID="EUR">{{ doc.nettoSumNum }}</cbc:TaxExclusiveAmount>
      <cbc:TaxInclusiveAmount currencyID="EUR">{{ doc.bruttoSumNum }}</cbc:TaxInclusiveAmount>
      <cbc:PayableAmount currencyID="EUR">{{ doc.bruttoSumNum }}</cbc:PayableAmount>
   </cac:LegalMonetaryTotal>

   {% for item in doc.items %}
   <cac:InvoiceLine>
        <cbc:ID>{{ item.itemNumber }}</cbc:ID>
        <cbc:InvoicedQuantity unitCode="{{ item.unitCode }}">{{ item.amountNum }}</cbc:InvoicedQuantity>
        <cbc:LineExtensionAmount currencyID="EUR">{{ item.nettoPriceNum }}</cbc:LineExtensionAmount>
        <cac:Item>
            <cbc:Description>{{ item.htmlText }}</cbc:Description>
            <cbc:Name>{{ item.htmlText }}</cbc:Name>
            <cac:SellersItemIdentification>
                <cbc:ID>{{ item.itemNumber }}</cbc:ID>
            </cac:SellersItemIdentification>
            <cac:ClassifiedTaxCategory>
                <cbc:ID>S</cbc:ID>
                <cbc:Percent>{{ doc.fullTaxPercentNum }}</cbc:Percent>
                <cac:TaxScheme>
                    <cbc:ID>VAT</cbc:ID>
                </cac:TaxScheme>
            </cac:ClassifiedTaxCategory>
        </cac:Item>
        <cac:Price>
            <cbc:PriceAmount currencyID="EUR">{{ item.unitPriceNum }}</cbc:PriceAmount>
        </cac:Price>
    </cac:InvoiceLine>
    {% endfor %}

</ubl:Invoice>
