DECLARE @xslt NVARCHAR(MAX) = N'<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                xmlns:ext1="urn:hmf-document-extensions" xmlns:ext2="urn:hmf-common-extensions">
  <xsl:param name="ext1:SourceTypeCode" />
  <xsl:param name="ext1:Type" />

  <xsl:variable name="_SetValue">
    <!-- Parametr pracy -->
    <xsl:variable name="PriceTypeId">
      <xsl:choose>
        <xsl:when test="$ext1:Type/Code = ''PAR'' or $ext1:Type/Code = ''PRK''">
          <xsl:value-of select="ext2:GetWorkParameter(''ReceiptPriceType'', ''Item1'')" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="ext2:GetWorkParameter(''DocumentPriceType'', ''Item1'')" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <!-- Netto = 2 / Brutto = 1 => UpdatePriceType -->
    <xsl:variable name="PriceKind">
      <xsl:choose>
        <xsl:when test="$ext1:Type/Code = ''FAS'' or $ext1:Type/Code = ''DEX'' or $ext1:Type/Code = ''WDT'' or $ext1:Type/Code = ''REX''">
          <xsl:value-of select="2" />
        </xsl:when>
        <xsl:when test="$ext1:Type/Code = ''FVT''">
          <xsl:value-of select="1" />
        </xsl:when>
        <xsl:when test="$ext1:Type/Code = ''PAR'' or $ext1:Type/Code = ''PRK''">
          <xsl:value-of select="ext2:GetWorkParameter(''ReceiptPriceType'', ''Item2'') + 1" />
        </xsl:when>
        <!-- DocumentType/Flag != FiscalizationStateEnum.Undefined => PriceKind = PriceKind.Gross -->
        <xsl:when test="$ext1:Type/FiscalizationState != 0">
          <xsl:value-of select="1" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="ext2:GetWorkParameter(''DocumentPriceType'', ''Item2'') + 1" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>

    <!-- Zmienne -->
    <!-- Czy zmieniono charakter? -->
    <xsl:variable name="isTypeChanged">
      <xsl:choose>
        <xsl:when test="$ext1:SourceTypeCode != $ext1:Type/Code">
          <xsl:value-of select="1" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="0" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <!-- Identyfikator kontrahenta -->
    <xsl:variable name="contractorId">
      <xsl:choose>
        <xsl:when test="/SaleDocument/ContractorId = ''''">
          <xsl:value-of select="0" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="/SaleDocument/ContractorId" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <!-- VIES kontrahenta -->
    <xsl:variable name="contractorVies">
      <xsl:choose>
        <xsl:when test="ext2:AreBoolEqual(ext2:GetContractor($contractorId, ''VIES'', ''false''), ''true'')">
          <xsl:value-of select="1" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="0" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <!-- Czy pierwotny typ jest walutowy? -->
    <xsl:variable name="isSrcCurrencyDocumentAndNotInvoice">
      <xsl:choose>
        <xsl:when test="$ext1:SourceTypeCode = ''DEX'' or $ext1:SourceTypeCode = ''WDT'' or $ext1:SourceTypeCode = ''REX''">
          <xsl:value-of select="1" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="0" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:variable name="isSrcCurrencyDocument">
      <xsl:choose>
        <xsl:when test="$isSrcCurrencyDocumentAndNotInvoice = 1 or $ext1:SourceTypeCode = ''FVW''">
          <xsl:value-of select="1" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="0" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <!-- Czy docelowy typ jest walutowy? -->
    <xsl:variable name="isDstCurrencyDocumentAndNotInvoice">
      <xsl:choose>
        <xsl:when test="$ext1:Type/Code = ''DEX'' or $ext1:Type/Code = ''WDT'' or $ext1:Type/Code = ''REX''">
          <xsl:value-of select="1" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="0" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:variable name="isDstCurrencyDocument">
      <xsl:choose>
        <xsl:when test="$isDstCurrencyDocumentAndNotInvoice = 1 or $ext1:Type/Code = ''FVW''">
          <xsl:value-of select="1" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="0" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <!-- Dla DEX, WDT i faktury marża czyszczone pole OO -->
    <xsl:variable name="clearOO">
      <xsl:choose>
        <xsl:when test="$ext1:Type/Code = ''DEX'' or $ext1:Type/Code = ''WDT'' or $ext1:Type/Code = ''FVT''">
          <xsl:value-of select="1" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="0" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <!-- Identyfikator stawki vat NP -->
    <xsl:variable name="npVatRateId" select="ext2:GetVatRate(''STVAT_NIEPODLEGA'', ''Id'', ''0'')" />
    <!-- Czy pierwotny typ jest paragonem? -->
    <xsl:variable name="isSrcPAR">
      <xsl:choose>
        <xsl:when test="$ext1:SourceTypeCode = ''PAR'' or $ext1:SourceTypeCode = ''PRK''">
          <xsl:value-of select="1" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="0" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <!-- Czy docelowy typ jest paragonem? -->
    <xsl:variable name="isDstPAR">
      <xsl:choose>
        <xsl:when test="$ext1:Type/Code = ''PAR'' or $ext1:Type/Code = ''PRK''">
          <xsl:value-of select="1" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="0" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <!-- Czy pierwotny dokument jest SME? -->
    <xsl:variable name="isSrcSME">
      <xsl:choose>
        <xsl:when test="($ext1:SourceTypeCode = ''WDT'' or $ext1:SourceTypeCode = ''FVW'') and ext2:AreBoolEqual(ext1:GetValue(''/SaleDocument/IsSmeProcedure''), ''true'')">
          <xsl:value-of select="1" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="0" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <!-- Czy docelowy typ jest SME? -->
    <xsl:variable name="isDstSME">
      <xsl:choose>
        <xsl:when test="($ext1:Type/Code = ''WDT'' or $ext1:Type/Code = ''FVW'') and ext2:AreBoolEqual($ext1:Type/IsSmeProcedure, ''true'')">
          <xsl:value-of select="1" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="0" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <!-- Czy jest to faktura do paragonu? -->
    <xsl:variable name="createdFromReceipt">
      <xsl:choose>
        <xsl:when test="ext2:AreBoolEqual(/SaleDocument/CreatedFromReceipt, ''true'')">
          <xsl:value-of select="1" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="0" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
	
    <!-- Zmiana z walutowego na niewalutowy => zapamiętanie waluty i kursu => czyszczenie waluty i kursu -->
    <xsl:if test="$isSrcCurrencyDocument = 1 and $isDstCurrencyDocument = 0">
      <xsl:value-of select="ext1:SaveParameter(''Currency'', /SaleDocument/Currency)" />
      <xsl:value-of select="ext1:SaveParameter(''ExchangeRate'', /SaleDocument/ExchangeRate)" />
      <xsl:value-of select="ext1:SaveParameter(''ExchangeRatePIT'', /SaleDocument/ExchangeRatePIT)" />

      <xsl:value-of select="ext1:SetValue(''/SaleDocument/Currency'', '''')" />
      <xsl:value-of select="ext1:SetValue(''/SaleDocument/ExchangeRate'', ''1'')" />
      <xsl:value-of select="ext1:SetValue(''/SaleDocument/ExchangeRatePIT'', ''1'')" />
    </xsl:if>

    <!-- Zmiana z niewalutowego na walutowy => odtworzenie waluty i kursu -->
    <xsl:if test="$isSrcCurrencyDocument = 0 and $isDstCurrencyDocument = 1">
      <xsl:value-of select="ext1:SetValue(''/SaleDocument/Currency'', ext1:RestoreParameter(''Currency'', ''''), False)" />
      <xsl:value-of select="ext1:SetValue(''/SaleDocument/ExchangeRate'', ext1:RestoreParameter(''ExchangeRate'', ''1''))" />
      <xsl:value-of select="ext1:SetValue(''/SaleDocument/ExchangeRatePIT'', ext1:RestoreParameter(''ExchangeRatePIT'', ''1''))" />
    </xsl:if>

    <!-- Nagłówek -->
    <xsl:value-of select="ext1:SetValue(''/SaleDocument/AccountingPattern'', $ext1:Type/AccountingPattern)" />
    <xsl:value-of select="ext1:SetValue(''/SaleDocument/JPK'', $ext1:Type/JpkKind)" />
    <xsl:value-of select="ext1:SetValue(''/SaleDocument/JPK_V7'', $ext1:Type/JpkV7Initial)" />
    <xsl:value-of select="ext1:SetValue(''/SaleDocument/FiscalizationState'', $ext1:Type/FiscalizationState)" />
    <xsl:value-of select="ext1:SetValue(''/SaleDocument/SaleRegister'', $ext1:Type/RegisterId)" />

    <!-- RegisterMethod/InRegisterDate => wymuszenie wywołanie GetRegisterMethod i CalculateInRegisterDate => rozbudowana logika uwzględniająca parametr pracy -->
    <xsl:value-of select="ext1:SetModify(''/SaleDocument/IssueDate'')" />

    <!-- Warunek z wcześniejszej implementacji FVS-PAR, dodatkowo był wykonywany tylko dla PAR -->
    <xsl:if test="ext2:AreBoolEqual(/SaleDocument/RelatedToForeignOrder, ''false'')">

      <xsl:if test="$isSrcPAR != $isDstPAR">
        <xsl:value-of select="ext1:SetValue(''/SaleDocument/PriceTypeId'', $PriceTypeId)" />
      </xsl:if>
      
      <xsl:if test="$createdFromReceipt = 0">
		<xsl:value-of select="ext1:SetValue(''/SaleDocument/PriceKind'', $PriceKind)" />
      </xsl:if>
      
    </xsl:if>

    <!-- OSS -->
    <xsl:value-of select="ext1:SetValue(''/SaleDocument/IsOssProcedure'', $ext1:Type/IsOssProcedure)" />
    <xsl:choose>
      <xsl:when test="ext2:AreBoolEqual($ext1:Type/IsOssProcedure, ''true'')">
        <xsl:if test="/SaleDocument/OssShippingCountryId = '''' or /SaleDocument/OssShippingCountryId = ''0''">
          <xsl:value-of select="ext1:SetDictionaryValue(''/SaleDocument/OssShippingCountryId'', ''PL'', ''Shortcut'')" />
        </xsl:if>
        <xsl:if test="/SaleDocument/OssDeliveryCountryId = '''' or /SaleDocument/OssDeliveryCountryId = ''0''">
          <xsl:value-of select="ext1:SetDictionaryValue(''/SaleDocument/OssDeliveryCountryId'', /SaleDocument/ContractorData/Address/Country, ''Shortcut'')" />
        </xsl:if>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="ext1:SetDictionaryValue(''/SaleDocument/OssShippingCountryId'', '''', ''Shortcut'')" />
        <xsl:value-of select="ext1:SetDictionaryValue(''/SaleDocument/OssDeliveryCountryId'', '''', ''Shortcut'')" />
      </xsl:otherwise>
    </xsl:choose>

    <!-- SME -->
    <xsl:if test="$isSrcSME != $isDstSME">
      <xsl:choose>
        <xsl:when test="$isDstSME = 1">
          <xsl:value-of select="ext1:SetValue(''/SaleDocument/IsSmeProcedure'', ''true'')" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="ext1:SetValue(''/SaleDocument/IsSmeProcedure'', ''false'')" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:if>

    <!-- Pozycje -->
    <xsl:for-each select="//SalePosition">
      <!-- Zmienne -->
      <xsl:variable name="xPositionPath" select="concat(''/SaleDocument/DocumentPositions/SalePosition['', position(), '']'')" />
      <xsl:variable name="productId" select="ext1:GetValue(concat($xPositionPath, ''/ProductId''))" />
      <xsl:variable name="isService" select="ext1:GetValue(concat($xPositionPath, ''/IsService''))" />
      <xsl:variable name="isElementOfSet">
        <xsl:choose>
          <xsl:when test="ext2:AreBoolEqual(ext1:GetValue(concat($xPositionPath, ''/IsElementOfSet'')), ''true'')">
            <xsl:value-of select="1" />
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="0" />
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
      <xsl:variable name="priceTypeId" select="ext1:GetValue(concat($xPositionPath, ''/PriceTypeId''))" />
      <xsl:variable name="vatRateId" select="ext1:GetValue(concat($xPositionPath, ''/VatRateId''))" />
      
      <!-- Zmieniono charakter dokumentu -->
      <xsl:if test="$isTypeChanged = 1">

        <!-- Dla DEX, WDT i faktury marża czyszczone pole OO -->
        <xsl:if test="$clearOO = 1">
          <xsl:value-of select="ext1:SetValue(concat($xPositionPath, ''/OO''), ''false'')" />
        </xsl:if>

        <!-- zmiana typu ceny może zmienić cenę, dlatego zostawiamy cenę użytkownika -->
        <xsl:if test="ext2:AreBoolEqual(/SaleDocument/RelatedToForeignOrder, ''false'') and $priceTypeId != ''0'' and $priceTypeId != $PriceTypeId">
          <xsl:value-of select="ext1:SetValue(concat($xPositionPath, ''/PriceTypeId''), $PriceTypeId)" />
        </xsl:if>

        <!-- VatUE => ShouldSetVatUe -->
        <xsl:if test="$isSrcCurrencyDocumentAndNotInvoice != $isDstCurrencyDocumentAndNotInvoice">
          <xsl:choose>
            <xsl:when test="$isElementOfSet = 1 or $contractorId = 0 or $isDstCurrencyDocumentAndNotInvoice = 0">
              <xsl:value-of select="ext1:SetValue(concat($xPositionPath, ''/VatUE''), ''false'')" />
            </xsl:when>
            <xsl:when test="$contractorVies = 1">
              <xsl:value-of select="ext1:SetValue(concat($xPositionPath, ''/VatUE''), ''true'')" />
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="ext1:SetValue(concat($xPositionPath, ''/VatUE''), ''false'')" />
            </xsl:otherwise>
          </xsl:choose>
        </xsl:if>

        <!-- ServiceExport => SetServiceExportProperty -->
        <xsl:if test="$isSrcCurrencyDocumentAndNotInvoice != $isDstCurrencyDocumentAndNotInvoice">
          <xsl:choose>
            <xsl:when test="ext2:AreBoolEqual($isService, ''true'') and $isDstCurrencyDocumentAndNotInvoice = 1">
              <xsl:value-of select="ext1:SetValue(concat($xPositionPath, ''/ServiceExport''), ''true'')" />
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="ext1:SetValue(concat($xPositionPath, ''/ServiceExport''), ''false'')" />
            </xsl:otherwise>
          </xsl:choose>
        </xsl:if>

      </xsl:if>

      <!-- VatRateId => GetVatRateIdForPosition -->
      <xsl:variable name="productVatRateId" select="ext2:GetProduct($productId, ''VatRateId'', ext2:GetVatRate(''STVAT_PODSTAWOWA'', ''Id'', ext2:GetVatRate('''', ''Id'', ''0'')))" />
      <xsl:variable name="isFVWZero">
        <xsl:choose>
          <xsl:when test="$ext1:Type/Code = ''FVW'' and ext2:AreBoolEqual($ext1:Type/ZeroVatRate, ''true'')">
            <xsl:value-of select="1" />
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="0" />
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
      <xsl:variable name="newVatRateId">
        <xsl:choose>
          <xsl:when test="$isDstSME = 1">
            <xsl:value-of select="$npVatRateId" />
          </xsl:when>
          <xsl:when test="$isFVWZero = 1 or ($ext1:Type/Code = ''DEX'' or $ext1:Type/Code = ''WDT'') and ext2:GetProduct($productId, ''VatRateId'', '''') != $npVatRateId">
            <xsl:value-of select="ext2:GetVatRate(''STVAT_ZEROWA'', ''Id'', ''0'')" />
          </xsl:when>
          <xsl:when test="$ext1:Type/Code != ''FAS'' and $ext1:Type/Code != ''REX''">
            <xsl:value-of select="$productVatRateId" />
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$npVatRateId" />
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
      <xsl:if test="$newVatRateId != $vatRateId">
        <!-- Zmieniamy stawkę tylko wtedy jeśli poprzednia wartość nie jest dostępna dla typu aktualnego -->
        <xsl:choose>
          <!-- jeśli docelowy typ SME to tylko NP -->
          <xsl:when test="$isDstSME = 1">
            <xsl:if test="ext2:AreBoolEqual(ext2:GetVatRate($vatRateId, ''IsNP'', ''false''), ''false'')">
              <xsl:value-of select="ext1:SetValue(concat($xPositionPath, ''/VatRateId''), $newVatRateId)" />
            </xsl:if>
          </xsl:when>
          <!-- jeśli docelowy typ FVW i Zero -->
          <xsl:when test="$isFVWZero = 1">
            <xsl:variable name="isZero">
              <xsl:choose>
                <xsl:when test="ext2:AreBoolEqual(ext2:GetVatRate($vatRateId, ''Type'', ''0''), ''3'')">
                  <xsl:value-of select="1" />
                </xsl:when>
                <xsl:otherwise>
                  <xsl:value-of select="0" />
                </xsl:otherwise>
              </xsl:choose>
            </xsl:variable>
            <xsl:if test="$isZero = 0">
              <xsl:value-of select="ext1:SetValue(concat($xPositionPath, ''/VatRateId''), $newVatRateId)" />
            </xsl:if>
          </xsl:when>
          <!-- jeśli docelowy typ DEX/WDT to ma tylko NP i Zero -->
          <xsl:when test="$ext1:Type/Code = ''DEX'' or $ext1:Type/Code = ''WDT'' or $ext1:Type/Code = ''DXK'' or $ext1:Type/Code = ''WDK''">
            <xsl:if test="$isTypeChanged = 1">
              <xsl:value-of select="ext1:SetValue(concat($xPositionPath, ''/VatRateId''), $newVatRateId)" />
            </xsl:if>
          </xsl:when>
          <!-- jeśli docelowy typ FAS/REX to ma tylko NP -->
          <xsl:when test="$ext1:Type/Code = ''FAS'' or $ext1:Type/Code = ''FAK'' or $ext1:Type/Code = ''REX'' or $ext1:Type/Code = ''RXK''">
            <xsl:variable name="isNP">
              <xsl:choose>
                <xsl:when test="ext2:AreBoolEqual(ext2:GetVatRate($vatRateId, ''IsNP'', ''false''), ''true'')">
                  <xsl:value-of select="1" />
                </xsl:when>
                <xsl:otherwise>
                  <xsl:value-of select="0" />
                </xsl:otherwise>
              </xsl:choose>
            </xsl:variable>
            <xsl:if test="$isNP = 0">
              <xsl:value-of select="ext1:SetValue(concat($xPositionPath, ''/VatRateId''), $newVatRateId)" />
            </xsl:if>
          </xsl:when>
          <!-- jeśli źródłowy typ DEX/WDT/FAS/REX a typ docelowy nie jest z tej grupy (wynika to z poprzednich warunków) => zawsze inicjujemy -->
          <xsl:when test="$ext1:SourceTypeCode = ''DEX'' or $ext1:SourceTypeCode = ''WDT'' or $ext1:SourceTypeCode = ''DXK'' or $ext1:SourceTypeCode = ''WDK'' or $ext1:SourceTypeCode = ''FAS'' or $ext1:SourceTypeCode = ''FAK'' or $ext1:SourceTypeCode = ''REX'' or $ext1:SourceTypeCode = ''RXK''">
            <xsl:if test="$isTypeChanged = 1">
              <xsl:value-of select="ext1:SetValue(concat($xPositionPath, ''/VatRateId''), $newVatRateId)" />
            </xsl:if>
          </xsl:when>
          <!-- w pozostałych przypadkach => zmiany pomiędzy typami gdzie dostępne są wszystkie stawki => nic nie zmieniamy -->
        </xsl:choose>
      </xsl:if>

      <!-- VatRegister => ma być inicjowana na podstawie typu dokumentu -->
      <xsl:variable name="vatRateId2" select="ext1:GetValue(concat($xPositionPath, ''/VatRateId''))" />
      <xsl:choose>
        <xsl:when test="$isDstSME = 1">
          <xsl:value-of select="ext1:SetValue(concat($xPositionPath, ''/VatRegister''), $ext1:Type/RegisterIdSme)" />
        </xsl:when>
        <xsl:when test="ext2:AreBoolEqual(ext1:GetValue(concat($xPositionPath, ''/OO'')), ''true'')">
          <xsl:value-of select="ext1:SetValue(concat($xPositionPath, ''/VatRegister''), $ext1:Type/RegisterIdOO)" />
        </xsl:when>
        <xsl:when test="ext2:AreBoolEqual(ext2:GetVatRate($vatRateId2, ''IsNP'', ''false''), ''true'')">
          <xsl:value-of select="ext1:SetValue(concat($xPositionPath, ''/VatRegister''), $ext1:Type/RegisterIdNp)" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="ext1:SetValue(concat($xPositionPath, ''/VatRegister''), $ext1:Type/RegisterId)" />
        </xsl:otherwise>
      </xsl:choose>

      <!-- DomesticVatRateId (DEX) => GetDomesticVatRateId -->
      <xsl:if test="$ext1:Type/Code = ''DEX''">
        <xsl:value-of select="ext1:SetValue(concat($xPositionPath, ''/DomesticVatRateId''), $productVatRateId, False)" />
      </xsl:if>

    </xsl:for-each>
  </xsl:variable>

  <!-- Template główny -->
  <xsl:template match="/">
    <xsl:copy-of select="." />
  </xsl:template>
  
</xsl:stylesheet>';

update [hm].[DocumentTransformationTemplates]
set [Template]=@xslt
where [Name]='SaleDocument'
