<?xml version="1.0" encoding="utf-8"?>
<Entity 
Schema="STOR" 
Name="INVOICE_ITEM" 
Description="Элемент медицинской накладной" 
DNAttributes="{StorageInvoice/Number};{StorageInvoice/Date};{BillOfGoods/DisplayName}" 
DisplayName="Препарат-{2} по накладной {0} от {1}" 
Inherits="STOR.ELEMENT">
  <Fields>
    <Parent Name="StorageInvoice" Index="19090002" Type="STOR.STORAGE_INVOICE" Description="Накладная" Required="1" />
    <Parent Name="Remains" Index="19090003" Type="STOR.REMAINS" Description="Остатки на складе" />
    <Parent Name="PaymentType" Index="19090004" Type="STOR.PAYMENT_TYPE" Description="Источник финансирования" Required="1" />
    <Parent Name="SupplierContract" Index="19090007" Type="STOR.SUPPLIER_CONTRACT" Description="Договор от поставщика" Required="1" />
    <Parent Name="ContractElements" Index="19090008" Type="STOR.CONTRACT_ELEMENTS" Description="Элементы договора" />
    <Parent Name="Storage" Index="19090009" Type="STOR.STORAGE" Description="Склад" />
    <Parent Name="PrepareRemains" Index="19090010" Type="STOR.REMAINS" Description="Предварительный остаток на складе" />
    <Parent Name="StorageInvoiceAdd" Index="19090011" Type="STOR.STORAGE_INVOICE_ADD" Description="Накладная прихода" Required="1" />
    <Parent Name="SupplierContractAbr" Index="19090012" Type="STOR.SUPPLIER_CONTRACT_ABR" Description="Аббревиатура договора" CharacterMaximumLength="20" Required="1" />
    <Attribute Name="ProducerPrice" Index="19090013" Type="float" DefaultFormat="{0:F2}" Description="Цена производителя" NumericPrecision="12" NumericScale="2" />
    <Child Name="PatientDrugDeliverys" Index="19090026" Type="STOR.PATIENT_DRUG_DELIVERY" Description="Списание на пациента" ChildAttribute="InvoiceItem" />
    <Attribute Name="MarkCheck" Type="bool" Description="Проверен в маркировке" Required="1" />
    <Parent Name="UnpackSSCCMarkMessage" Type="STOR.MARK_MESSAGE" Description="Сообщения в МДЛП(расформирование)" />
    <Parent Name="InfoSSCCMarkMessage" Type="STOR.MARK_MESSAGE" Description="Сообщения в МДЛП(структура SSCC)" />
    <Child Name="MarkMessages" Type="STOR.MARK_MESSAGE" Description="Сообщения в МДЛП" ChildAttribute="InvoiceItem" />
    <Attribute Name="ScanerCheck" Type="bool" Description="Проверен сканером" Required="1" />
    <Attribute Name="Barcode" Type="string" Description="Штрих-код" CharacterMaximumLength="226" />
    <Parent Name="InvoiceItem" Type="STOR.INVOICE_ITEM" Description="Элемент накладной передачи" />
    <Link Name="InvoiceItemAdd" Type="STOR.INVOICE_ITEM" Description="Элемент накладной прихода" LinkAttribute="InvoiceItem" />
    <Parent Name="RegistratorMessage" Type="STOR.REGISTRATOR_MESSAGE" Description="Сообщения отправленые в регистратор выбытия" />
    <Parent Name="SSCC" Type="STOR.SHIPPING_CONTAINER" Description="Транспортная упаковка" />
    <Attribute Name="QuantityInPackage" Type="float" Description="Количество товара в упаковке" Required="1" />
    <Attribute Name="Sum" Index="19350006" Type="float" Description="Сумма" NumericPrecision="12" NumericScale="2" />
    <Attribute Name="TotalAmount" Index="19090001" Type="float" Description="Количество упаковок" NumericPrecision="12" NumericScale="2" />
    <Link Name="DestructionItemInfo" Type="STOR.DESTRUCTION_ITEM_INFO" Description="Информация по уничтожению" LinkAttribute="InvoiceItem" />
    <Attribute Name="SellingPrice" Type="float" DefaultFormat="{0:F2}" Description="Цена продажи" NumericPrecision="12" NumericScale="2" Required="1" />
    <Parent Name="StorageShelf" Type="STOR.STORAGE_SHELF" Description="Место хранения" />
  </Fields>
  <DbMapping>
    <Table name="T_INVOICE_ITEM">
      <Map Name="StorageInvoice" Column="StorageInvoice" />
      <Map Name="Remains" Column="Remains" />
      <Map Name="SupplierContract" Column="SupplierContract" />
      <Map Name="PrepareRemains" Column="PrepareRemains" />
      <Map Name="StorageInvoiceAdd" Column="StorageInvoiceAdd" />
      <Map Name="SupplierContractAbr" Column="SupplierContractAbr" />
      <Map Name="ProducerPrice" Column="ProducerPrice" />
      <Map Name="MarkCheck" Column="MarkCheck" />
      <Map Name="ScanerCheck" Column="ScanerCheck" />
      <Map Name="Barcode" Column="Barcode" />
      <Map Name="InvoiceItem" Column="InvoiceItem" />
      <Map Name="SSCC" Column="SSCC" />
      <Map Name="QuantityInPackage" Column="QuantityInPackage" />
      <Map Name="SellingPrice" Column="SellingPrice" />
      <Map Name="StorageShelf" Column="StorageShelf" />
    </Table>
    <Lexem>
      <Map Name="PaymentType" PathAttributes="{SupplierContractAbr/PaymentType}">
        <lx:Path OwnerQueryLevel="0" xmlns:lx="lexem">
          <lx:StepInt index="19090012" />
          <lx:StepInt index="5460003" />
        </lx:Path>
      </Map>
      <Map Name="ContractElements">
        <lx:QueryValue entity="STOR.CONTRACT_ELEMENTS" top="1" xmlns:lx="lexem">
          <condition>
            <lx:Criteria type="And">
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepInt index="19360001" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                  <lx:StepInt index="19090007" />
                </lx:Path>
              </lx:Criterion>
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepInt index="19360006" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                  <lx:StepInt index="19350005" />
                </lx:Path>
              </lx:Criterion>
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepInt index="19360005" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                  <lx:StepInt index="19350012" />
                </lx:Path>
              </lx:Criterion>
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepInt index="19360009" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                  <lx:StepInt index="19090012" />
                </lx:Path>
              </lx:Criterion>
            </lx:Criteria>
          </condition>
          <orderBy>
            <lx:Path OwnerQueryLevel="0">
              <lx:StepInt index="19360008" />
            </lx:Path>
            <desc>True</desc>
          </orderBy>
          <value>
            <lx:Path OwnerQueryLevel="0">
              <lx:StepInt index="19360002" />
            </lx:Path>
          </value>
        </lx:QueryValue>
      </Map>
      <Map Name="Storage">
        <lx:Path OwnerQueryLevel="0" xmlns:lx="lexem">
          <lx:StepInt index="19090002" />
          <lx:StepInt index="19080009" />
        </lx:Path>
      </Map>
      <Map Name="UnpackSSCCMarkMessage" PathAttributes="{MarkMessages}">
        <lx:ChildCount xmlns:lx="lexem">
          <condition>
            <lx:Criteria type="And">
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="MessageType" />
                </lx:Path>
                <lx:ChoiceOperand Entity="STOR.MARK_MESSAGE" AttributeName="MessageType" type="Int32" PrimaryKey="0" />
              </lx:Criterion>
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="Status" />
                </lx:Path>
                <lx:ChoiceOperand Entity="STOR.MARK_MESSAGE" AttributeName="Status" type="Int32" PrimaryKey="1" />
              </lx:Criterion>
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="Schema" />
                  <lx:StepString name="Code" />
                </lx:Path>
                <lx:ConstOperand type="Int32">912</lx:ConstOperand>
              </lx:Criterion>
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="ObjId" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                  <lx:StepString name="ElementID" />
                </lx:Path>
              </lx:Criterion>
            </lx:Criteria>
          </condition>
          <lx:Path OwnerQueryLevel="0">
            <lx:StepString name="MarkMessages" />
          </lx:Path>
          <lx:First>
            <lx:Path OwnerQueryLevel="0">
              <lx:StepCurrent />
            </lx:Path>
          </lx:First>
          <lx:Path OwnerQueryLevel="0">
            <lx:StepString name="SendDateTime" />
          </lx:Path>
          <lx:ConstOperand type="String"><![CDATA[asc]]></lx:ConstOperand>
        </lx:ChildCount>
      </Map>
      <Map Name="InfoSSCCMarkMessage" PathAttributes="{MarkMessages}">
        <lx:ChildCount xmlns:lx="lexem">
          <condition>
            <lx:Criteria type="And">
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="MessageType" />
                </lx:Path>
                <lx:ChoiceOperand Entity="STOR.MARK_MESSAGE" AttributeName="MessageType" type="Int32" PrimaryKey="0" />
              </lx:Criterion>
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="Status" />
                </lx:Path>
                <lx:ChoiceOperand Entity="STOR.MARK_MESSAGE" AttributeName="Status" type="Int32" PrimaryKey="1" />
              </lx:Criterion>
              <lx:Criteria type="Or">
                <lx:Criterion type="=">
                  <lx:Path OwnerQueryLevel="0">
                    <lx:StepString name="Schema" />
                    <lx:StepString name="Code" />
                  </lx:Path>
                  <lx:ConstOperand type="Int32">210</lx:ConstOperand>
                </lx:Criterion>
                <lx:Criterion type="=">
                  <lx:Path OwnerQueryLevel="0">
                    <lx:StepString name="Schema" />
                    <lx:StepString name="Code" />
                  </lx:Path>
                  <lx:ConstOperand type="Int32">220</lx:ConstOperand>
                </lx:Criterion>
              </lx:Criteria>
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="ObjId" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                  <lx:StepString name="ElementID" />
                </lx:Path>
              </lx:Criterion>
            </lx:Criteria>
          </condition>
          <lx:Path OwnerQueryLevel="0">
            <lx:StepString name="MarkMessages" />
          </lx:Path>
          <lx:First>
            <lx:Path OwnerQueryLevel="0">
              <lx:StepCurrent />
            </lx:Path>
          </lx:First>
          <lx:Path OwnerQueryLevel="0">
            <lx:StepString name="SendDateTime" />
          </lx:Path>
          <lx:ConstOperand type="String"><![CDATA[asc]]></lx:ConstOperand>
        </lx:ChildCount>
      </Map>
      <Map Name="RegistratorMessage">
        <lx:QueryValue entity="STOR.REGISTRATOR_MESSAGE" top="1" offset="0" hints="" xmlns:lx="lexem">
          <condition>
            <lx:Criteria type="And">
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="ObjId" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                  <lx:StepString name="ElementID" />
                </lx:Path>
              </lx:Criterion>
              <lx:Criterion not="1" type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="Status" />
                </lx:Path>
                <lx:ChoiceOperand Entity="STOR.REGISTRATOR_MESSAGE" AttributeName="Status" type="Int32" PrimaryKey="5" />
              </lx:Criterion>
            </lx:Criteria>
          </condition>
          <value>
            <lx:Path OwnerQueryLevel="0">
              <lx:StepString name="RegistratorMessageID" />
            </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="TotalApplicationCount" />
            </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="TotalAmount">
        <lx:MathOperator sign="/" xmlns:lx="lexem">
          <lx:Path OwnerQueryLevel="0">
            <lx:StepString name="TotalApplicationCount" />
          </lx:Path>
          <lx:Path OwnerQueryLevel="0">
            <lx:StepString name="QuantityInPackage" />
          </lx:Path>
        </lx:MathOperator>
      </Map>
    </Lexem>
  </DbMapping>
</Entity>