<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE cXML SYSTEM "http://xml.cxml.org/schemas/cXML/{{ version }}/cXML.dtd">
<cXML xml:lang="{{ language }}" payloadID="{{ payloadId }}" timestamp="{{ timestamp }}">
  <Header>
    <From>
      <Credential domain="{{ from.domain }}">
        <Identity>{{ from.id }}</Identity>
      </Credential>
    </From>
    <To>
      <Credential domain="{{ to.domain }}">
        <Identity>{{ to.id }}</Identity>
      </Credential>
    </To>
    <Sender>
      <Credential domain="{{ sender.domain }}">
        <Identity>{{ sender.id }}</Identity>
        <SharedSecret>{{ sender.secret }}</SharedSecret>
      </Credential>
      <UserAgent>{{ sender.ua }}</UserAgent>
    </Sender>
  </Header>
  <Request>
    <OrderRequest>
        <OrderRequestHeader orderID="{{ id }}" orderDate="{{ date }}" orderType="{{ orderType }}" type="{{ requestType }}">
          <Total>
            <Money currency="{{ total.currency }}">{{ total.amount }}</Money>
          </Total>
          <ShipTo>
            <Address addressID="{{ shipTo.address.id }}">
              <Name xml:lang="{{ language }}">{{ shipTo.address.companyName }}</Name>
              <PostalAddress name="{{ shipTo.address.nickname }}">
                {% for value in shipTo.address.attn %}
                <DeliverTo>{{ value }}</DeliverTo>
                {% endfor %}
                <Street>{{ shipTo.address.street }}</Street>
                <City>{{ shipTo.address.city }}</City>
                <State>{{ shipTo.address.state }}</State>
                <PostalCode>{{ shipTo.address.postalCode }}</PostalCode>
                <Country isoCountryCode="{{ shipTo.address.countryCode }}">{{ shipTo.address.countryName }}</Country>
              </PostalAddress>
              {% if shipTo.email %}
              <Email name="{{ shipTo.email.nickname }}">{{ shipTo.email.address }}</Email>
              {% endif %}
              {% if shipTo.phone %}
              <Phone name="{{ shipTo.phone.nickname }}">
                <TelephoneNumber>
                  <CountryCode>{{ shipTo.phone.countryCode }}</CountryCode>
                  <AreaOrCityCode>{{ shipTo.phone.areaOrCityCode }}</AreaOrCityCode>
                  <Number>{{ shipTo.phone.number }}</Number>
                </TelephoneNumber>
              </Phone>
              {% endif %}
            </Address>
          </ShipTo>
          <BillTo>
            <Address addressID="{{ billTo.address.id }}">
              {% if billTo.address.companyName %}
              <Name xml:lang="{{ language }}">{{ billTo.address.companyName }}</Name>
              {% endif %}
              {% if billTo.address.street %}
              <PostalAddress name="{{ billTo.address.nickname }}">
                <Street>{{ billTo.address.street }}</Street>
                <City>{{ billTo.address.city }}</City>
                <State>{{ billTo.address.state }}</State>
                <PostalCode>{{ billTo.address.postalCode }}</PostalCode>
                <Country isoCountryCode="{{ billTo.address.countryCode }}">{{ billTo.address.countryName }}</Country>
              </PostalAddress>
              {% endif %}
              {% if billTo.email %}
              <Email name="{{ billTo.email.nickname }}">{{ billTo.email.address }}</Email>
              {% endif %}
              {% if billTo.phone %}
              <Phone name="{{ billTo.phone.nickname }}">
                <TelephoneNumber>
                  <CountryCode>{{ billTo.phone.countryCode }}</CountryCode>
                  <AreaOrCityCode>{{ billTo.phone.areaOrCityCode }}</AreaOrCityCode>
                  <Number>{{ billTo.phone.number }}</Number>
                </TelephoneNumber>
              </Phone>
              {% endif %}
            </Address>
          </BillTo>
          {% if order.shipping %}
          <Shipping>
            <Money currency="{{ order.shipping.currency }}">{{ order.shipping.amount }}</Money>
            <Description xml:lang="{{ language }}">{{ order.shipping.description }}</Description>
          </Shipping>
          {% endif %}
          {% if order.tax %}
          <Tax>
            <Money currency="{{ order.tax.currency }}">{{ order.tax.amount }}</Money>
            <Description xml:lang="{{ language }}">{{ order.tax.description }}</Description>
          </Tax>
          {% endif %}
          {% if order.pcard %}
          <Payment>
            <PCard number="{{ order.pcard.acct }}" expiration="{{ order.pcard.exp }}"/>
          </Payment>
          {% endif %}
          {% for key, value in extrinsics %}
          <Extrinsic name="{{ key }}">{{ value }}</Extrinsic>
          {% endfor %}
        </OrderRequestHeader>
        {% for item in items %}
        <ItemOut quantity="{{ item.quantity }}" lineNumber="{{ item.lineNumber }}">
          <ItemID>
            <SupplierPartID>{{ item.supplierPartId }}</SupplierPartID>
            <SupplierPartAuxiliaryID>{{ item.supplierPartAuxId }}</SupplierPartAuxiliaryID>
          </ItemID>
          <ItemDetail>
            <UnitPrice>
              <Money currency="{{ item.currency }}">{{ item.unitPrice }}</Money>
            </UnitPrice>
            <Description xml:lang="{{ language }}">{{ item.name }}</Description>
            <UnitOfMeasure>{{ item.uom }}</UnitOfMeasure>
            {% for key, value in item.classification %}
            <Classification domain="{{ key }}">{{ value }}</Classification>
            {% endfor %}
          </ItemDetail>
        </ItemOut>
        {% endfor %}
    </OrderRequest>
  </Request>
</cXML>