<?xml version="1.0" encoding="utf-8"?>
<Entity 
Schema="APS" 
Name="RECIPE_ELEMENTS" 
Description="Элементы рецепта" 
PrimaryKey="RecipeElementsID">
  <Fields>
    <Attribute Name="RecipeElementsID" Index="19380001" Type="guid" Description="Идентификатор" />
    <Attribute Name="Amount" Index="19380002" Type="float" DefaultFormat="{0:F3}" Description="Количество" NumericPrecision="12" NumericScale="2" Required="1" />
    <Attribute Name="Sum" Index="19380006" Type="float" DefaultFormat="{0:F2}" Description="Сумма" NumericPrecision="12" NumericScale="2" />
    <Parent Name="Remains" Index="19380003" Type="STOR.REMAINS" Description="Остатки на складе" Required="1" />
    <Parent Name="Recipe" Index="19380005" Type="APS.RECIPE" Description="Рецепт" Required="1" />
    <Attribute Name="Barcode" Type="string" Description="Штрих-код" CharacterMaximumLength="226" />
    <Attribute Name="SellingPrice" Type="float" DefaultFormat="{0:F2}" Description="Цена продажи" NumericPrecision="12" NumericScale="2" Required="1" />
    <Attribute Name="SellingSum" Type="float" DefaultFormat="{0:F2}" Description="Сумма продажи" NumericPrecision="12" NumericScale="2" />
  </Fields>
  <DbMapping>
    <Table name="T_RECIPE_ELEMENTS">
      <Map Name="RecipeElementsID" Column="RecipeElementsID" />
      <Map Name="Amount" Column="Amount" />
      <Map Name="Remains" Column="Remains" />
      <Map Name="Recipe" Column="Recipe" />
      <Map Name="Barcode" Column="Barcode" />
      <Map Name="SellingPrice" Column="SellingPrice" />
    </Table>
    <Lexem>
      <Map Name="Sum">
        <lx:Case xmlns:lx="lexem">
          <When>
            <lx:Criterion not="1" type="=">
              <lx:Path OwnerQueryLevel="0">
                <lx:StepInt index="19380002" />
              </lx:Path>
              <lx:ConstOperand isNull="1" />
            </lx:Criterion>
          </When>
          <Then>
            <lx:MathOperator sign="*">
              <lx:Path OwnerQueryLevel="0">
                <lx:StepInt index="19380003" />
                <lx:StepInt index="19110003" />
              </lx:Path>
              <lx:Path OwnerQueryLevel="0">
                <lx:StepInt index="19380002" />
              </lx:Path>
            </lx:MathOperator>
          </Then>
          <Else>
            <lx:ConstOperand type="Int32">0</lx:ConstOperand>
          </Else>
        </lx:Case>
      </Map>
      <Map Name="SellingSum">
        <lx:Case xmlns:lx="lexem">
          <When>
            <lx:Criterion not="1" type="=">
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="Amount" />
              </lx:Path>
              <lx:ConstOperand isNull="1" />
            </lx:Criterion>
          </When>
          <Then>
            <lx:MathOperator sign="*">
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="SellingPrice" />
              </lx:Path>
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="Amount" />
              </lx:Path>
            </lx:MathOperator>
          </Then>
          <Else>
            <lx:ConstOperand type="Int32">0</lx:ConstOperand>
          </Else>
        </lx:Case>
      </Map>
    </Lexem>
  </DbMapping>
  <CalculatingAttributes>
    <Attribute Name="RestOnDay" Index="19380007" Type="float" Description="Остаток на складе" NumericPrecision="12" NumericScale="2" RequiredAttributes="{Recipe/IssueDate};{Remains/RestOnDay};{Remains/ cUnitPrice / PackageType};{Remains/ cWriteOff / PackageType};{Remains/PackageCoefficient}; {Remains/PackageCoefficientType}" />
  </CalculatingAttributes>
</Entity>