<?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"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2 http://docs.oasis-open.org/ubl/os-UBL-2.1/xsd/maindoc/UBL-Invoice-2.1.xsd">
   <cbc:CustomizationID>urn:cen.eu:en16931:2017#compliant#urn:xoev-de:kosit:standard:xrechnung_2.0</cbc:CustomizationID>
   <cbc:ID>{{ doc.ident }}</cbc:ID>
   <cbc:IssueDate>{{ doc.dateStrISO }}</cbc:IssueDate>
   <cbc:DueDate>{{ doc.dueDateStrISO }}</cbc:DueDate>
   <cbc:InvoiceTypeCode>380</cbc:InvoiceTypeCode>
   <cbc:DocumentCurrencyCode>EUR</cbc:DocumentCurrencyCode>
   <cbc:TaxCurrencyCode>EUR</cbc:TaxCurrencyCode>
   <cbc:BuyerReference>{{ doc.buyerReference }}</cbc:BuyerReference>
   <cac:ProjectReference>
      <cbc:ID>{{ doc.projectLabel }}</cbc:ID>
   </cac:ProjectReference>
   <cac:AccountingSupplierParty>
      <cac:Party>
         <cac:PostalAddress>
            <cbc:StreetName>Hans Kraft Str. 1</cbc:StreetName>
            <cbc:CityName>Berlin</cbc:CityName>
            <cbc:PostalZone>12322</cbc:PostalZone>
            <cac:Country>
               <cbc:IdentificationCode>DE</cbc:IdentificationCode>
            </cac:Country>
         </cac:PostalAddress>
         <cac:PartyTaxScheme>
            <cbc:CompanyID>DE343244324</cbc:CompanyID>
            <cac:TaxScheme>
               <cbc:ID>VAT</cbc:ID>
            </cac:TaxScheme>
         </cac:PartyTaxScheme>
         <cac:PartyTaxScheme>
            <cbc:CompanyID>DE343244324</cbc:CompanyID>
            <cac:TaxScheme>
                <cbc:ID/>
            </cac:TaxScheme>
         </cac:PartyTaxScheme>

         <cac:PartyLegalEntity>
            <cbc:RegistrationName>Goofy Enterprises</cbc:RegistrationName>
         </cac:PartyLegalEntity>
         <cac:Contact>
            <cbc:Name>Goofy Cerbuchcicz</cbc:Name>
            <cbc:Telephone>+49 321 23321</cbc:Telephone>
            <cbc:ElectronicMail>goofy@kraft.de</cbc:ElectronicMail>
         </cac:Contact>
      </cac:Party>
   </cac:AccountingSupplierParty>
   <cac:AccountingCustomerParty>
      <cac:Party>
         <cac:PostalAddress>
            <cbc:StreetName>{{ customer.STREET}}</cbc:StreetName>
            <cbc:AdditionalStreetName/>
            <cbc:CityName>{{ customer.LOCALITY }}</cbc:CityName>
            <cbc:PostalZone>{{ customer.POSTCODE }}</cbc:PostalZone>
            <cac:Country>
               <cbc:IdentificationCode>DE</cbc:IdentificationCode>
            </cac:Country>
         </cac:PostalAddress>
         <cac:PartyLegalEntity>
            <cbc:RegistrationName>{{ customer.ORGANISATION }}</cbc:RegistrationName>
         </cac:PartyLegalEntity>
         <cac:Contact>
            <cbc:Name>{{ customer.NAME }}</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>30</cbc:PaymentMeansCode>
      <cac:PayeeFinancialAccount>
         <cbc:ID>DE55700126000032144324</cbc:ID>
         <cbc:Name>Goofy Enterprises</cbc:Name>
         <cac:FinancialInstitutionBranch>
            <cbc:ID>SUSKDEM1XXX</cbc:ID>
         </cac:FinancialInstitutionBranch>
      </cac:PayeeFinancialAccount>
   </cac:PaymentMeans>

   <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:AllowanceTotalAmount currencyID="EUR">0.00</cbc:AllowanceTotalAmount>
      <cbc:ChargeTotalAmount currencyID="EUR">0.00</cbc:ChargeTotalAmount>
      <cbc:PrepaidAmount currencyID="EUR">0.00</cbc:PrepaidAmount>
      <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:CommodityClassification/>
         <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.nettoPriceNum }}</cbc:PriceAmount>
      </cac:Price>
   </cac:InvoiceLine>
   {% endfor %}

</ubl:Invoice>
