<?xml version="1.0" encoding="utf-8"?>
<Entity 
Schema="STOR" 
Name="CONTRACT_ELEMENTS" 
Description="Элементы договора" 
PrimaryKey="ContractElementsID" 
DNAttributes="{BillOfGoods/CDisplayName};{SupplierContract/Date};{SupplierContract/Number}" 
DisplayName="Элемент договора № {2} от {1} товар: {0}">
  <Customs>
    <Custom Name="FilterUICondition"><![CDATA[<lx:Criterion type="=" xmlns:lx="lexem">
	<lx:Path OwnerQueryLevel="0">
		<lx:StepString name="BillOfGoods" />
		<lx:StepString name="Active" />
	</lx:Path>
	<lx:ConstOperand type="Boolean">True</lx:ConstOperand>
</lx:Criterion>]]></Custom>
  </Customs>
  <Fields>
    <Attribute Name="ContractElementsID" Index="19360002" Type="guid" Description="Идентификатор" />
    <Attribute Name="Amount" Index="19360003" Type="float" DefaultFormat="{0:0.#####}" Description="Количество" NumericPrecision="20" NumericScale="6" Required="1" />
    <Attribute Name="Price" Index="19360006" Type="float" DefaultFormat="{0:G0}" Description="Цена" NumericPrecision="12" NumericScale="2" Required="1" />
    <Attribute Name="Sum" Index="19360007" Type="float" DefaultFormat="{0:G0}" Description="Сумма" NumericPrecision="18" NumericScale="2" Required="1" />
    <Attribute Name="LotNumber" Index="19360008" Type="int" Description="Номер лота" />
    <Attribute Name="ComeGoods" Index="19360010" Type="float" Description="Пришло товара" />
    <Attribute Name="Return" Index="19360011" Type="float" Description="Возврат" />
    <Attribute Name="Balance" Index="19360012" Type="float" Description="Остаток" />
    <Parent Name="SupplierContract" Index="19360001" Type="STOR.SUPPLIER_CONTRACT" Description="Договор от поставщика" Required="1" />
    <Parent Name="PackageType" Index="19360004" Type="PHARM.PACKAGE_TYPE" Description="Вид упаковки" Required="1" />
    <Parent Name="BillOfGoods" Index="19360005" Type="PHARM.BILL_OF_GOODS" Description="Номенклатура товаров" Required="1" />
    <Parent Name="SupplierContractAbr" Index="19360009" Type="STOR.SUPPLIER_CONTRACT_ABR" Description="Аббревиатура договора" CharacterMaximumLength="20" />
    <Choice Name="VAT" Index="19360013" 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="OrdinalNumber" Index="19360014" Type="int" Description="Порядковый номер" />
  </Fields>
  <DbMapping>
    <Table name="T_CONTRACT_ELEMENTS">
      <Map Name="ContractElementsID" Column="ContractElementsID" />
      <Map Name="Amount" Column="Amount" />
      <Map Name="Price" Column="Price" />
      <Map Name="Sum" Column="Sum" />
      <Map Name="LotNumber" Column="LotNumber" />
      <Map Name="SupplierContract" Column="SupplierContract" />
      <Map Name="PackageType" Column="PackageType" />
      <Map Name="BillOfGoods" Column="BillOfGoods" />
      <Map Name="SupplierContractAbr" Column="SupplierContractAbr" />
      <Map Name="VAT" Column="VAT" />
      <Map Name="OrdinalNumber" Column="OrdinalNumber" />
    </Table>
    <Lexem>
      <Map Name="ComeGoods">
        <lx:QueryValue entity="STOR.INVOICE_ITEM" top="-1" offset="0" xmlns:lx="lexem">
          <condition>
            <lx:Criteria type="And">
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="Price" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                  <lx:StepString name="Price" />
                </lx:Path>
              </lx:Criterion>
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="SupplierContract" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                  <lx:StepString name="SupplierContract" />
                </lx:Path>
              </lx:Criterion>
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="BillOfGoods" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                  <lx:StepString name="BillOfGoods" />
                </lx:Path>
              </lx:Criterion>
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="StorageInvoice" />
                  <lx:StepString name="State" />
                </lx:Path>
                <lx:ChoiceOperand Entity="STOR.STORAGE_INVOICE" AttributeName="State" type="Int32" PrimaryKey="1" />
              </lx:Criterion>
              <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="StorageInvoice" />
                  <lx:StepAs as="STOR.STORAGE_INVOICE_ADD" />
                  <lx:StepString name="InvoiceWriteOffBetweenStorage" />
                </lx:Path>
                <lx:BaseObjectOperand Entity="STOR.INVOICE_WRITE_OFF_BETWEEN_STORAGE" isNull="1" />
              </lx:Criterion>
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="SupplierContractAbr" />
                </lx:Path>
                <lx:IsNull>
                  <lx:Path OwnerQueryLevel="1">
                    <lx:StepString name="SupplierContract" />
                    <lx:StepString name="SupplierContractAbr" />
                  </lx:Path>
                  <lx:Path OwnerQueryLevel="1">
                    <lx:StepString name="SupplierContractAbr" />
                  </lx:Path>
                </lx:IsNull>
              </lx:Criterion>
            </lx:Criteria>
          </condition>
          <value>
            <lx:LexemList>
              <lx:IsNull>
                <lx:Sum>
                  <lx:Path OwnerQueryLevel="0">
                    <lx:StepString name="Amount" />
                  </lx:Path>
                </lx:Sum>
                <lx:ConstOperand type="Int32">0</lx:ConstOperand>
              </lx:IsNull>
            </lx:LexemList>
          </value>
        </lx:QueryValue>
      </Map>
      <Map Name="Return">
        <lx:QueryValue entity="STOR.INVOICE_ITEM" top="-1" offset="0" xmlns:lx="lexem">
          <condition>
            <lx:Criteria type="And">
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="Price" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                  <lx:StepString name="Price" />
                </lx:Path>
              </lx:Criterion>
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="SupplierContract" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                  <lx:StepString name="SupplierContract" />
                </lx:Path>
              </lx:Criterion>
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="BillOfGoods" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                  <lx:StepString name="BillOfGoods" />
                </lx:Path>
              </lx:Criterion>
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="StorageInvoice" />
                  <lx:StepString name="State" />
                </lx:Path>
                <lx:ChoiceOperand Entity="STOR.STORAGE_INVOICE" AttributeName="State" type="Int32" PrimaryKey="1" />
              </lx:Criterion>
              <lx:Criteria type="Or">
                <lx:Criterion type="=">
                  <lx:Path OwnerQueryLevel="0">
                    <lx:StepString name="StorageInvoice" />
                    <lx:StepAs as="STOR.INVOICE_WRITE_OFF_BETWEEN_STORAGE" />
                    <lx:StepString name="Return" />
                  </lx:Path>
                  <lx:ConstOperand type="Boolean">True</lx:ConstOperand>
                </lx:Criterion>
                <lx:Criterion type="=">
                  <lx:Path OwnerQueryLevel="0">
                    <lx:StepString name="StorageInvoice" />
                    <lx:StepAs as="STOR.INVOICE_WRITE_OFF" />
                    <lx:StepString name="Reason" />
                  </lx:Path>
                  <lx:ChoiceOperand Entity="STOR.INVOICE_WRITE_OFF" AttributeName="Reason" type="Int32" PrimaryKey="5" />
                </lx:Criterion>
              </lx:Criteria>
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="SupplierContractAbr" />
                </lx:Path>
                <lx:IsNull>
                  <lx:Path OwnerQueryLevel="1">
                    <lx:StepString name="SupplierContract" />
                    <lx:StepString name="SupplierContractAbr" />
                  </lx:Path>
                  <lx:Path OwnerQueryLevel="1">
                    <lx:StepString name="SupplierContractAbr" />
                  </lx:Path>
                </lx:IsNull>
              </lx:Criterion>
            </lx:Criteria>
          </condition>
          <value>
            <lx:LexemList>
              <lx:IsNull>
                <lx:Sum>
                  <lx:Path OwnerQueryLevel="0">
                    <lx:StepString name="Amount" />
                  </lx:Path>
                </lx:Sum>
                <lx:ConstOperand type="Int32">0</lx:ConstOperand>
              </lx:IsNull>
            </lx:LexemList>
          </value>
        </lx:QueryValue>
      </Map>
      <Map Name="Balance">
        <lx:MathOperator sign="+" xmlns:lx="lexem">
          <lx:MathOperator sign="-">
            <lx:Path OwnerQueryLevel="0">
              <lx:StepInt index="19360003" />
            </lx:Path>
            <lx:Path OwnerQueryLevel="0">
              <lx:StepInt index="19360010" />
            </lx:Path>
          </lx:MathOperator>
          <lx:Path OwnerQueryLevel="0">
            <lx:StepInt index="19360011" />
          </lx:Path>
        </lx:MathOperator>
      </Map>
    </Lexem>
  </DbMapping>
</Entity>