<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.00"
           xmlns:emcs="urn:publicid:-:EC:DGTAXUD:EMCS:PHASE3:EMCS:V2.02"
           xmlns:tms="urn:publicid:-:EC:DGTAXUD:EMCS:PHASE3:TMS:V2.02"
           xmlns:tcl="urn:publicid:-:EC:DGTAXUD:EMCS:PHASE3:TCL:V2.02"
           xmlns:doc="urn:publicid:-:EC:DGTAXUD:EMCS:PHASE3:DOC:V2.02"
           xmlns:ddtypes="http://www.mf.gov.pl/schematy/EDD/DDTYPES/2020/05/"
           xmlns:dd801="http://www.mf.gov.pl/schematy/EDD/DD801/2020/05/"
           targetNamespace="http://www.mf.gov.pl/schematy/EDD/DD801/2020/05/">
  <!--=============================================-->
  <!--=====              DD801                =====-->
  <!--=====      Dokument Dostawy (e-DD)      =====-->
  <!--=============================================-->

  <!--===== Imports =====-->
  <xs:import namespace="urn:publicid:-:EC:DGTAXUD:EMCS:PHASE3:EMCS:V2.02" schemaLocation="types.xsd"/>
  <xs:import namespace="urn:publicid:-:EC:DGTAXUD:EMCS:PHASE3:TMS:V2.02" schemaLocation="tms.xsd"/>
  <xs:import namespace="urn:publicid:-:EC:DGTAXUD:EMCS:PHASE3:TCL:V2.02" schemaLocation="tcl.xsd"/>
  <xs:import namespace="urn:publicid:-:EC:DGTAXUD:EMCS:PHASE3:DOC:V2.02" schemaLocation="doc.xsd"/>
  <xs:import namespace="http://www.mf.gov.pl/schematy/EDD/DDTYPES/2020/05/" schemaLocation="ddTypes.xsd"/>

  <!--===== Root Element =====-->
  <xs:element name="DD801" type="dd801:DD801Type"/>

  <!--===== EMCS Data Groups Declarations =====-->
  <xs:complexType name="DD801Type">
    <xs:sequence>
      <xs:element name="Header" type="tms:HeaderType"/>
      <xs:element name="Body" type="dd801:BodyType"/>
    </xs:sequence>
  </xs:complexType>

  <!--===== IE Specific Data Groups Declarations =====-->
  <xs:complexType name="BodyType">
    <xs:sequence>
      <xs:element name="EDDContainer" type="dd801:EDDContainerType"/>
    </xs:sequence>
  </xs:complexType>

  <!--==========================================================-->
  <!--=====                  EDD Container                 =====-->
  <!--==========================================================-->
  <xs:complexType name="EDDContainerType">
    <xs:sequence>
      <!-- sekcja 1 -->
      <xs:element name="EDD" type="dd801:EDDType"/>

      <!-- sekcja 2 i 4 -->
      <xs:element name="ConsignorTrader" type="ddtypes:DDTraderType" minOccurs="1" maxOccurs="1" />
      <xs:element name="PlaceOfDispatchTrader" type="ddtypes:DDTraderType" minOccurs="0" maxOccurs="1"/>
      <xs:element name="PlaceOfDispatchCustomsOffice" type="ddtypes:DDDispatchAndImportCustomsOfficesType" minOccurs="1" maxOccurs="1"/>

      <!-- sekcja 5 i 7 -->
      <xs:element name="ConsigneeTrader" type="ddtypes:DDTraderType" minOccurs="1" maxOccurs="1"/>
      <xs:element name="DeliveryPlaceTrader" type="ddtypes:DDTraderType" minOccurs="0" maxOccurs="1"/>
      <xs:element name="DeliveryPlaceCustomsOffice" type="ddtypes:DDCustomsOfficeType" minOccurs="1" maxOccurs="1"/>

      <!-- sekcja 8 -->
      <xs:element name="DeliveryGuarantee" type="dd801:DeliveryGuaranteeType" minOccurs="0" maxOccurs="1"/>

      <!-- sekcja 9 -->
      <xs:element name="TransportMode" type="ddtypes:DDTransportModeType"/>

      <!-- sekcja 10 -->
      <xs:element name="TransportDetails" type="ddtypes:DDTransportDetailsType"  maxOccurs="99" />

      <!-- sekcja 11 -->
      <xs:element name="BodyEDD" type="ddtypes:BodyEDDType" maxOccurs="unbounded"/>

      <!-- Dokumenty dodatkowe -->
      <xs:element name="AdditionalDocument" type="ddtypes:DDAdditionalDocType" minOccurs="0" maxOccurs="99"/>
    </xs:sequence>
  </xs:complexType>

  <!--==========================================================-->
  <!--=====                       EDD                      =====-->
  <!--==========================================================-->
  <xs:complexType name="EDDType">
    <xs:annotation>
      <xs:documentation>
        <doc:description value="E-DD"/>
      </xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:element name="DeliveryDocumentReference" type="ddtypes:AdministrativeReferenceType"/>
      <xs:element name="LocalReferenceNumber" type="ddtypes:DeliveryDocumentLocalReferenceNumberType"/>
      <xs:element name="DeliveryDocumentMode" type="ddtypes:DeliveryDocumentModeFlag" minOccurs="1" maxOccurs="1">
        <xs:annotation>
          <xs:documentation>Znacznik zwrotu towarów: 0 - dostawa;  1 - zwrot; 2 - eksport; 3 - zwrot wewnątrzwspólnotowy. Flaga ustawiana nawet w przypadku braku wartości w DD815</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="ExciseDutyRate" minOccurs="1" maxOccurs="1" type="ddtypes:ExciseDutyRateType">
        <xs:annotation>
          <xs:documentation>
            Atrybut moze byc okreslony tylko w DD815 i nie moze byc zmieniony do czasu zakonczenia calej dostawy ze wzgledu na zalozenie,
            ze komunikat modyfikacji dostawy nie moze zmienic pozycji towarowych (ilosci ani typu).
          </xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="DeferredSubmissionFlag" type="tcl:Flag" minOccurs="0" maxOccurs="1">
        <xs:annotation>
          <xs:documentation>Znacznik zgloszenia w trybie odroczonym: 1 - tryb odroczony; 0 albo brak elementu - tryb standardowy</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="DeliveryClosingFlag" minOccurs="1" maxOccurs="1" type="ddtypes:DeliveryClosingFlagType">
        <xs:annotation>
          <xs:documentation>
            Atrybut określa tryb zamknięcia dostawy. Może być zmieniony w wyniku modyfikacji dostawy (np zmiany odbiorcy) pod warunkiem, że był ustawiony
            pierwotnie na 1 albo 2. Zmiana może być dokonana tylko na wartość 1 albo 2.
            Jeśli pierwotnie ustawiony był na 3 to nie może być zmieniany.
          </xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="InvoiceNumber" type="emcs:InvoiceNumberType" minOccurs="1" maxOccurs="1"/>
      <xs:element name="InvoiceDate" type="emcs:DateType" minOccurs="0"/>
      <xs:element name="DateOfDispatch" type="emcs:DateType" minOccurs="1" maxOccurs="1"/>
      <xs:element name="TimeOfDispatch" type="emcs:TimeType" minOccurs="0" maxOccurs="1"/>
      <xs:element name="JourneyTime" type="emcs:JourneyTimeType"/>
      <xs:element name="DateAndTimeOfValidationOfEDD" type="emcs:DateTimeType" minOccurs="1" maxOccurs="1"/>
      <xs:element name="DateAndTimeOfUpdateValidation" type="emcs:DateTimeType" minOccurs="1" maxOccurs="1"/>

      <!-- 1.1 -->
      <xs:element name="ImportSad" type="ddtypes:ImportSadType" minOccurs="0" maxOccurs="9" />
    </xs:sequence>
  </xs:complexType>

  <!--==========================================================-->
  <!--=====               Delivery Guarantee               =====-->
  <!--==========================================================-->
  <xs:complexType name="DeliveryGuaranteeType">
    <xs:annotation>
      <xs:documentation>
        <doc:description value="DELIVERY GUARANTEE"/>
      </xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:element name="GuarantorTypeCode" type="tcl:GuarantorTypeCode"/>
      <xs:element name="GuarantorTrader" type="ddtypes:GuarantorTraderType" minOccurs="0" maxOccurs="1"/>
    </xs:sequence>
  </xs:complexType>

</xs:schema>