<?xml version="1.0" encoding="utf-8"?>
<Entity 
Schema="STOR" 
Name="REMAINS" 
Description="Остатки на складе" 
PrimaryKey="RemainsID" 
DNAttributes="{BillOfGoods/DisplayName};{Series};{SupplierContract/Number};{SupplierContract/Date};{SupplierContract/GoodsSupplier/Name}" 
DisplayName="{0}. Серия:{1}. Договор № {2} от {3}. {4}">
  <Fields>
    <Attribute Name="RemainsID" Index="19110001" Type="guid" Description="Идентификатор" />
    <Attribute Name="Price" Index="19110003" Type="float" DefaultFormat="{0:F2}" Description="Цена" NumericPrecision="12" NumericScale="2" Required="1" />
    <Attribute Name="LotNumber" Index="19110010" Type="int" Description="Партия" Required="1" />
    <Attribute Name="Series" Index="19110011" Type="string" Description="Серия" CharacterMaximumLength="100" Required="1" />
    <Attribute Name="Comment" Index="19110017" Type="string" Description="Комментарий" CharacterMaximumLength="255" />
    <Attribute Name="ExpirationDate" Index="19110019" Type="date" Description="Срок годности" Required="1" />
    <Attribute Name="Amount" Index="19110021" Type="float" DefaultFormat="{0:0.#####}" Description="Остаток" NumericPrecision="20" NumericScale="6" Required="1" />
    <Attribute Name="RestOnDay" Index="19110026" Type="float" DefaultFormat="{0:F2}" Description="Остаток на дату" NumericPrecision="20" NumericScale="2">
      <Parameter Name="BeginDate" Description="Дата" Type="date">
        <lx:ParamHolder xmlns:lx="lexem">
          <lx:StepString name="CURRENT_DATE" />
        </lx:ParamHolder>
      </Parameter>
    </Attribute>
    <Attribute Name="RestOnDayAd" Type="float" DefaultFormat="{0:F2}" Description="Остаток на дату(доп)" NumericPrecision="20" NumericScale="2">
      <Parameter Name="BeginDate" Description="Дата" Type="date">
        <lx:ParamHolder xmlns:lx="lexem">
          <lx:StepString name="CURRENT_DATE" />
        </lx:ParamHolder>
      </Parameter>
    </Attribute>
    <Parent Name="Storage" Index="19110002" Type="STOR.STORAGE" Description="Склад" Required="1" />
    <Parent Name="BillOfGoods" Index="19110013" Type="PHARM.BILL_OF_GOODS" Description="Номенклатура товаров" Required="1" />
    <Parent Name="PaymentType" Index="19110016" Type="STOR.PAYMENT_TYPE" Description="Источник финансирования" Required="1" />
    <Parent Name="PackageType" Index="19110022" Type="PHARM.PACKAGE_TYPE" Description="Вид упаковки " Required="1" />
    <Parent Name="DefaultPackageType" Index="19110023" Type="PHARM.PACKAGE_TYPE" Description="Вид упаковки по умолчанию" />
    <Parent Name="SupplierContract" Index="19110025" Type="STOR.SUPPLIER_CONTRACT" Description="Договор от поставщика" Required="1" />
    <Parent Name="StorageInvoiceAdd" Index="19110027" Type="STOR.STORAGE_INVOICE_ADD" Description="Накладная прихода" Required="1" />
    <Parent Name="SupplierContractAbr" Index="19110028" Type="STOR.SUPPLIER_CONTRACT_ABR" Description="Аббревиатура договора" CharacterMaximumLength="20" Required="1" />
    <Child Name="InvoiceItems" Index="19110008" Type="STOR.INVOICE_ITEM" Description="Элемент накладной" ChildAttribute="Remains" />
    <Child Name="StorageRestOnDays" Index="19110024" Type="STOR.STORAGE_REST_ON_DAY" Description="Остатки товара на складе за день" ChildAttribute="Remain" />
    <Child Name="RemainsLinkPackageTypes" Index="19110029" Type="STOR.REMAINS_LINK_PACKAGE_TYPE" Description="Связь формы выпуска с остатком" ChildAttribute="Remains" />
    <Choice Name="VAT" Index="19110012" Description="НДС" Required="1">
      <Item Name="Без НДС" Index="0" />
      <Item Name="10%" Index="1" />
      <Item Name="18%" Index="2" />
      <Item Name="20%" Index="3" />
      <Item Name="5%" Index="4" />
      <Item Name="7%" Index="5" />
      <Item Name="22%" Index="6" />
    </Choice>
    <Attribute Name="ProducerPrice" Index="19110015" Type="float" DefaultFormat="{0:F2}" Description="Цена производителя" NumericPrecision="12" NumericScale="2" />
    <Attribute Name="GTINSerialNumber" Index="19160010" Type="string" Description="GTIN/серийный номер" CharacterMaximumLength="28" />
    <Attribute Name="ConversionId" Type="string" Description="Идентификатор перехода" CharacterMaximumLength="36" />
    <Attribute Name="Sum" Index="19110004" Type="float" DefaultFormat="{0:F2}" Description="Стоимость" NumericPrecision="12" NumericScale="2" RequiredAttributes="{PackageType};{Amount};{Price};{PackageCoefficient};{cUnitPrice/PackageType};{VAT}" />
    <Attribute Name="cAmount" Index="19110014" Type="float" DefaultFormat="{0:0.#####}" Description="Количество товара" RequiredAttributes="{cUnitPrice / PackageType};{PackageType};{PackageCoefficient};{Amount}" />
    <Attribute Name="QuantityInPackage" Type="float" Description="Количество товара в упаковке" Required="1" />
    <Parent Name="ShippingContainer" Type="STOR.SHIPPING_CONTAINER" Description="Транспортная упаковка" />
    <Parent Name="UnitPriceProductForm" Type="STOR.REMAINS_LINK_PACKAGE_TYPE" Description="Форма выпуски покупки" />
    <Attribute Name="SgtinMdlpStatus" Type="string" Description="Статус КИЗ" />
    <Choice Name="MdlpWithdrawalType" Description="Статус вывода из оборота в МДЛП">
      <Item Name="Выбыл по документу" Index="1" />
      <Item Name="Продан в розницу" Index="2" />
      <Item Name="Выбыл через РВ" Index="3" />
      <Item Name="Выбыл для оказания мед. помощи" Index="4" />
      <Item Name="Выбыл по льготному рецепту" Index="5" />
      <Item Name="Продан через дистанционную торговлю" Index="6" />
    </Choice>
    <Attribute Name="CheckedKIZ" Type="bool" Description="Проверен в реестре КИЗ" Required="1" />
    <Parent Name="StorageShelf" Type="STOR.STORAGE_SHELF" Description="Место хранения " />
  </Fields>
  <DbMapping>
    <Table name="T_REMAINS">
      <Map Name="RemainsID" Column="RemainsID" />
      <Map Name="Price" Column="Price" />
      <Map Name="LotNumber" Column="LotNumber" />
      <Map Name="Series" Column="Series" />
      <Map Name="Comment" Column="Comment" />
      <Map Name="ExpirationDate" Column="ExpirationDate" />
      <Map Name="Amount" Column="Amount" />
      <Map Name="Storage" Column="Storage" />
      <Map Name="BillOfGoods" Column="BillOfGoods" />
      <Map Name="PackageType" Column="PackageType" />
      <Map Name="SupplierContract" Column="SupplierContract" />
      <Map Name="StorageInvoiceAdd" Column="StorageInvoiceAdd" />
      <Map Name="SupplierContractAbr" Column="SupplierContractAbr" />
      <Map Name="VAT" Column="VAT" />
      <Map Name="ProducerPrice" Column="ProducerPrice" />
      <Map Name="GTINSerialNumber" Column="GTINSerialNumber" />
      <Map Name="ConversionId" Column="ConversionId" />
      <Map Name="QuantityInPackage" Column="QuantityInPackage" />
      <Map Name="SgtinMdlpStatus" Column="SgtinMdlpStatus" />
      <Map Name="MdlpWithdrawalType" Column="MdlpWithdrawalType" />
      <Map Name="CheckedKIZ" Column="CheckedKIZ" />
      <Map Name="StorageShelf" Column="StorageShelf" />
    </Table>
    <Lexem>
      <Map Name="RestOnDay">
        <lx:IsNull xmlns:lx="lexem">
          <lx:QueryValue entity="STOR.STORAGE_REST_ON_DAY" top="1" offset="0">
            <condition>
              <lx:Criteria type="And">
                <lx:Criterion type="&lt;=">
                  <lx:Path OwnerQueryLevel="0">
                    <lx:StepString name="Date" />
                  </lx:Path>
                  <lx:Argument>
                    <lx:ConstOperand type="Int32">0</lx:ConstOperand>
                  </lx:Argument>
                </lx:Criterion>
                <lx:Criterion type="=">
                  <lx:Path OwnerQueryLevel="0">
                    <lx:StepString name="Remain" />
                    <lx:StepString name="RemainsID" />
                  </lx:Path>
                  <lx:Path OwnerQueryLevel="1">
                    <lx:StepString name="RemainsID" />
                  </lx:Path>
                </lx:Criterion>
              </lx:Criteria>
            </condition>
            <orderBy>
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="Date" />
              </lx:Path>
              <desc>True</desc>
            </orderBy>
            <value>
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="RestOut" />
              </lx:Path>
            </value>
          </lx:QueryValue>
          <lx:ConstOperand type="Decimal">0</lx:ConstOperand>
        </lx:IsNull>
      </Map>
      <Map Name="RestOnDayAd">
        <lx:IsNull xmlns:lx="lexem">
          <lx:QueryValue entity="STOR.STORAGE_REST_ON_DAY" top="1" offset="0">
            <condition>
              <lx:Criteria type="And">
                <lx:Criterion type="&lt;=">
                  <lx:Path OwnerQueryLevel="0">
                    <lx:StepString name="Date" />
                  </lx:Path>
                  <lx:Argument>
                    <lx:ConstOperand type="Int32">0</lx:ConstOperand>
                  </lx:Argument>
                </lx:Criterion>
                <lx:Criterion type="=">
                  <lx:Path OwnerQueryLevel="0">
                    <lx:StepString name="Remain" />
                    <lx:StepString name="RemainsID" />
                  </lx:Path>
                  <lx:Path OwnerQueryLevel="1">
                    <lx:StepString name="RemainsID" />
                  </lx:Path>
                </lx:Criterion>
              </lx:Criteria>
            </condition>
            <orderBy>
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="Date" />
              </lx:Path>
              <desc>True</desc>
            </orderBy>
            <value>
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="RestOut" />
              </lx:Path>
            </value>
          </lx:QueryValue>
          <lx:ConstOperand type="Decimal">0</lx:ConstOperand>
        </lx:IsNull>
      </Map>
      <Map Name="PaymentType" PathAttributes="{SupplierContractAbr/PaymentType}">
        <lx:Path OwnerQueryLevel="0" xmlns:lx="lexem">
          <lx:StepInt index="19110028" />
          <lx:StepInt index="5460003" />
        </lx:Path>
      </Map>
      <Map Name="DefaultPackageType">
        <lx:QueryValue entity="STOR.REMAINS_LINK_PACKAGE_TYPE" top="1" xmlns:lx="lexem">
          <condition>
            <lx:Criteria type="And">
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="UnitPrice" />
                </lx:Path>
                <lx:ConstOperand type="Boolean">True</lx:ConstOperand>
              </lx:Criterion>
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="Remains" />
                  <lx:StepString name="RemainsID" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                  <lx:StepString name="RemainsID" />
                </lx:Path>
              </lx:Criterion>
            </lx:Criteria>
          </condition>
          <value>
            <lx:Path OwnerQueryLevel="0">
              <lx:StepString name="PackageType" />
              <lx:StepString name="PackageTypeID" />
            </lx:Path>
          </value>
        </lx:QueryValue>
      </Map>
      <Map Name="Sum">
        <lx:MathOperator sign="*" xmlns:lx="lexem">
          <lx:MathOperator sign="/">
            <lx:Path OwnerQueryLevel="0">
              <lx:StepString name="Amount" />
            </lx:Path>
            <lx:Path OwnerQueryLevel="0">
              <lx:StepString name="QuantityInPackage" />
            </lx:Path>
          </lx:MathOperator>
          <lx:Path OwnerQueryLevel="0">
            <lx:StepString name="Price" />
          </lx:Path>
        </lx:MathOperator>
      </Map>
      <Map Name="cAmount">
        <lx:MathOperator sign="/" xmlns:lx="lexem">
          <lx:Path OwnerQueryLevel="0">
            <lx:StepString name="Amount" />
          </lx:Path>
          <lx:Path OwnerQueryLevel="0">
            <lx:StepString name="QuantityInPackage" />
          </lx:Path>
        </lx:MathOperator>
      </Map>
      <Map Name="ShippingContainer">
        <lx:QueryValue entity="STOR.INVOICE_ITEM" top="1" offset="0" xmlns:lx="lexem">
          <condition>
            <lx:Criteria type="And">
              <lx:Criterion type="IS">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="StorageInvoice" />
                  <lx:StepString name="ObjectProperties" />
                  <lx:StepString name="ObjectTypeID" />
                </lx:Path>
                <lx:ConstOperand type="String"><![CDATA[STOR.STORAGE_INVOICE_ADD]]></lx:ConstOperand>
              </lx:Criterion>
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="Remains" />
                  <lx:StepString name="RemainsID" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                  <lx:StepString name="RemainsID" />
                </lx:Path>
              </lx:Criterion>
            </lx:Criteria>
          </condition>
          <value>
            <lx:LexemList>
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="SSCC" />
                <lx:StepString name="ShippingContainerID" />
              </lx:Path>
            </lx:LexemList>
          </value>
        </lx:QueryValue>
      </Map>
      <Map Name="UnitPriceProductForm">
        <lx:QueryValue entity="STOR.REMAINS_LINK_PACKAGE_TYPE" top="1" offset="0" xmlns:lx="lexem">
          <condition>
            <lx:Criteria type="And">
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="UnitPrice" />
                </lx:Path>
                <lx:ConstOperand type="Boolean">True</lx:ConstOperand>
              </lx:Criterion>
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="Remains" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                  <lx:StepString name="RemainsID" />
                </lx:Path>
              </lx:Criterion>
            </lx:Criteria>
          </condition>
          <value>
            <lx:Path OwnerQueryLevel="0">
              <lx:StepString name="RemainsLinkPackageTypeID" />
            </lx:Path>
          </value>
        </lx:QueryValue>
      </Map>
    </Lexem>
  </DbMapping>
  <CalculatingAttributes>
    <Attribute Name="PackageCoefficient" Index="19160005" Type="float" Description="Коэффициент вида упаковки" RequiredAttributes="{RemainsLinkPackageTypes / PackageType}; {RemainsLinkPackageTypes / OrdinalNumber}; {RemainsLinkPackageTypes / Amount}; {RemainsLinkPackageTypes /WriteOff}">
      <Parameter Name="Start" Description="Начальное значение" Type="guid" />
      <Parameter Name="End" Description="Конечное значение" Type="guid" />
    </Attribute>
    <Parent Name="cWriteOff" Index="19160007" Type="STOR.REMAINS_LINK_PACKAGE_TYPE" Description="Форма выпуска списание" RequiredAttributes="{RemainsLinkPackageTypes / WriteOff}" PathAttributes="{RemainsLinkPackageTypes}" />
    <Parent Name="cUnitPrice" Index="19160009" Type="STOR.REMAINS_LINK_PACKAGE_TYPE" Description="Единица покупки" RequiredAttributes="{RemainsLinkPackageTypes / UnitPrice}" PathAttributes="{RemainsLinkPackageTypes}" />
    <Parent Name="cAppointment" Type="STOR.REMAINS_LINK_PACKAGE_TYPE" Description="Единица списания по назначениям" RequiredAttributes="{RemainsLinkPackageTypes / Appointment}" PathAttributes="{RemainsLinkPackageTypes}" />
  </CalculatingAttributes>
</Entity>