object fMainStockMoveEdit: TfMainStockMoveEdit
  Left = 0
  Top = 0
  BorderStyle = bsDialog
  Caption = #1058#1052#1062': '#1056#1077#1076#1072#1082#1090#1080#1088#1086#1074#1072#1085#1080#1077
  ClientHeight = 448
  ClientWidth = 690
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  Position = poMainFormCenter
  OnClose = FormClose
  OnShow = FormShow
  PixelsPerInch = 96
  TextHeight = 13
  object Panel1: TPanel
    Left = 0
    Top = 407
    Width = 690
    Height = 41
    Align = alBottom
    BevelOuter = bvNone
    TabOrder = 0
    DesignSize = (
      690
      41)
    object bbOk: TBitBtn
      Left = 511
      Top = 8
      Width = 83
      Height = 25
      Anchors = [akTop, akRight]
      Caption = 'Ok'
      Glyph.Data = {
        A6010000424DA601000000000000520000002800000011000000110000000100
        08000000000054010000C30E0000C30E0000070000000700000000000000FFFF
        FF008000000000FF000000800000C0C0C000FFFFFF0005050505050505050505
        0505050505050500000005050505020205050505050505050505050000000505
        0502040402050505050505050505050000000505020404040402050505050505
        0505050000000502040404040404020505050505050505000000020404040304
        0404040205050505050505000000040404030503040404040205050505050500
        0000030403050505030404040402050505050500000005030505050505030404
        0404020505050500000005050505050505050304040404020505050000000505
        0505050505050503040404040205050000000505050505050505050503040404
        0402050000000505050505050505050505030404040402000000050505050505
        0505050505050304040402000000050505050505050505050505050304040400
        0000050505050505050505050505050503030500000005050505050505050505
        05050505050505060606}
      ModalResult = 1
      TabOrder = 0
    end
    object bbCancel: TBitBtn
      Left = 600
      Top = 8
      Width = 83
      Height = 25
      Anchors = [akTop, akRight]
      Caption = #1054#1090#1084#1077#1085#1072
      Glyph.Data = {
        A6010000424DA601000000000000520000002800000011000000110000000100
        08000000000054010000C30E0000C30E0000070000000700000000000000FFFF
        FF000000FF0000008000C0C0C00080808000FFFFFF0004040404040404040404
        0404040404040400000004040405050404040404040404040404040000000404
        0203030504040404040205040404040000000404020303030504040402030305
        0404040000000404020303030305040203030303050404000000040404020303
        0303050303030303050404000000040404040203030303030303030504040400
        0000040404040402030303030303050404040400000004040404040403030303
        0305040404040400000004040404040402030303030504040404040000000404
        0404040203030303030504040404040000000404040402030303050303030504
        0404040000000404040203030305040203030305040404000000040404020303
        0504040402030303050404000000040404040203040404040402030303040400
        0000040404040404040404040404020302040400000004040404040404040404
        04040404040404060606}
      ModalResult = 2
      TabOrder = 1
    end
  end
  object GroupBox1: TGroupBox
    Left = 0
    Top = 0
    Width = 690
    Height = 81
    Align = alTop
    Caption = #1053#1072#1080#1084#1077#1085#1086#1074#1072#1085#1080#1077
    TabOrder = 1
    object DBLookupComboboxEh1: TDBLookupComboboxEh
      Left = 10
      Top = 20
      Width = 671
      Height = 21
      DynProps = <>
      DataField = 'value_id'
      DataSource = fMainEdit.dsStockMove
      DropDownBox.Columns = <
        item
          FieldName = 'vendor'
          Title.Caption = #1040#1088#1090#1080#1082#1091#1083
          Width = 150
        end
        item
          FieldName = 'name'
          Title.Caption = #1053#1072#1080#1084#1077#1085#1086#1074#1072#1085#1080#1077
          Width = 300
        end>
      DropDownBox.UseMultiTitle = True
      DropDownBox.ShowTitles = True
      EditButtons = <>
      KeyField = 'id'
      ListField = 'name'
      ListSource = dsValue
      TabOrder = 0
      Visible = True
      OnChange = DBLookupComboboxEh1Change
    end
    object DBEditEh1: TDBEditEh
      Left = 632
      Top = 47
      Width = 48
      Height = 21
      ControlLabel.Width = 47
      ControlLabel.Height = 13
      ControlLabel.Caption = #1054#1089#1090#1072#1090#1086#1082':'
      ControlLabel.Visible = True
      ControlLabelLocation.Position = lpLeftTextBaselineEh
      DataField = 'total'
      DataSource = dsResidues
      DynProps = <>
      EditButtons = <>
      Enabled = False
      TabOrder = 1
      Visible = True
    end
  end
  object GroupBox2: TGroupBox
    Left = 0
    Top = 133
    Width = 690
    Height = 274
    Align = alClient
    Caption = #1048#1085#1092#1086#1088#1084#1072#1094#1080#1103
    TabOrder = 2
    object DBGridEh1: TDBGridEh
      Left = 2
      Top = 15
      Width = 686
      Height = 257
      Align = alClient
      DataSource = dsStockMove
      DynProps = <>
      IndicatorOptions = [gioShowRowIndicatorEh]
      Options = [dgTitles, dgIndicator, dgColumnResize, dgColLines, dgRowLines, dgTabs, dgRowSelect, dgAlwaysShowSelection, dgConfirmDelete, dgCancelOnExit]
      TabOrder = 0
      Columns = <
        item
          DynProps = <>
          EditButtons = <>
          FieldName = 'vendor'
          Footers = <>
          Title.Caption = #1040#1088#1090#1080#1082#1091#1083
          Width = 90
        end
        item
          DynProps = <>
          EditButtons = <>
          FieldName = 'name'
          Footers = <>
          Title.Caption = #1053#1072#1080#1084#1077#1085#1086#1074#1072#1085#1080#1077
          Width = 200
        end
        item
          DynProps = <>
          EditButtons = <>
          FieldName = 'move_in'
          Footers = <>
          Title.Caption = #1054#1087#1077#1088#1072#1094#1080#1103
          Width = 100
        end
        item
          DynProps = <>
          EditButtons = <>
          FieldName = 'quantity'
          Footers = <>
          Title.Caption = #1050#1086#1083'-'#1074#1086
          Width = 70
        end
        item
          DynProps = <>
          EditButtons = <>
          FieldName = 'buyPrice'
          Footers = <>
          Title.Caption = #1062#1077#1085#1072' ('#1079#1072#1082#1091#1087'.)'
          Width = 80
        end
        item
          DynProps = <>
          EditButtons = <>
          FieldName = 'price'
          Footers = <>
          Title.Caption = #1062#1077#1085#1072' ('#1088#1086#1079#1085'.)'
          Width = 80
        end>
      object RowDetailData: TRowDetailPanelControlEh
      end
    end
  end
  object GroupBox3: TGroupBox
    Left = 0
    Top = 81
    Width = 690
    Height = 52
    Align = alTop
    TabOrder = 3
    object DBEditEh2: TDBEditEh
      Left = 10
      Top = 22
      Width = 121
      Height = 21
      ControlLabel.Width = 64
      ControlLabel.Height = 13
      ControlLabel.Caption = #1050#1086#1083#1080#1095#1077#1089#1090#1074#1086':'
      ControlLabel.Visible = True
      DataField = 'quantity'
      DataSource = fMainEdit.dsStockMove
      DynProps = <>
      EditButtons = <>
      TabOrder = 0
      Visible = True
    end
    object DBEditEh3: TDBEditEh
      Left = 432
      Top = 22
      Width = 121
      Height = 21
      ControlLabel.Width = 70
      ControlLabel.Height = 13
      ControlLabel.Caption = #1062#1077#1085#1072' ('#1079#1072#1082#1091#1087'.)'
      ControlLabel.Visible = True
      DataField = 'buyPrice'
      DataSource = fMainEdit.dsStockMove
      DynProps = <>
      EditButtons = <>
      TabOrder = 1
      Visible = True
    end
    object DBEditEh4: TDBEditEh
      Left = 559
      Top = 22
      Width = 121
      Height = 21
      ControlLabel.Width = 64
      ControlLabel.Height = 13
      ControlLabel.Caption = #1062#1077#1085#1072' ('#1088#1086#1079#1085'.)'
      ControlLabel.Visible = True
      DataField = 'price'
      DataSource = fMainEdit.dsStockMove
      DynProps = <>
      EditButtons = <>
      TabOrder = 2
      Visible = True
    end
  end
  object dsStockMove: TDataSource
    DataSet = qStockMove
    Left = 136
    Top = 344
  end
  object qStockMove: TADOQuery
    Connection = DM.Conn
    CursorType = ctStatic
    Parameters = <
      item
        Name = 'vid'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 32
        Precision = 255
        Size = 255
        Value = '0'
      end>
    SQL.Strings = (
      'SELECT'
      '  sm.*,'
      '  s.moveIn,'
      '  IF(s.moveIn=1,'#39#1054#1087#1088#1080#1093#1086#1076#1086#1074#1072#1085#1080#1077#39','#39#1057#1087#1080#1089#1072#1085#1080#1077#39') AS move_in,'
      '  v.name,'
      '  v.vendor'
      'FROM'
      '  stockmove AS sm'
      'LEFT JOIN'
      '  stock AS s ON sm.stock_id=s.id'
      'LEFT JOIN'
      '  value AS v ON sm.value_id=v.id'
      'WHERE'
      '  sm.value_id = :vid')
    Left = 200
    Top = 344
    object qStockMoveid: TAutoIncField
      FieldName = 'id'
      ReadOnly = True
    end
    object qStockMovestock_id: TIntegerField
      FieldName = 'stock_id'
    end
    object qStockMovevalue_id: TIntegerField
      FieldName = 'value_id'
    end
    object qStockMovequantity: TIntegerField
      FieldName = 'quantity'
    end
    object qStockMovebuyPrice: TFloatField
      FieldName = 'buyPrice'
    end
    object qStockMoveprice: TFloatField
      FieldName = 'price'
    end
    object qStockMovemoveIn: TSmallintField
      FieldName = 'moveIn'
    end
    object qStockMovename: TWideStringField
      FieldName = 'name'
      Size = 250
    end
    object qStockMovevendor: TWideStringField
      FieldName = 'vendor'
      Size = 50
    end
    object qStockMovemove_in: TWideStringField
      FieldName = 'move_in'
      ReadOnly = True
      Size = 13
    end
  end
  object dsValue: TDataSource
    DataSet = DM.tValue
    Left = 24
    Top = 24
  end
  object qResidues: TADOQuery
    Connection = DM.Conn
    CursorType = ctStatic
    Parameters = <
      item
        Name = 'vid'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 240
        Precision = 255
        Size = 255
        Value = '0'
      end>
    SQL.Strings = (
      'SELECT'
      '  v.*,'
      '  IF(tIn.quantityIn IS NULL,0,tIn.quantityIn) AS quantityIn,'
      
        '  IF(tOut.quantityOut IS NULL,0,tOut.quantityOut) AS quantityOut' +
        ','
      
        '  (IF(tIn.quantityIn IS NULL,0,tIn.quantityIn) - IF(tOut.quantit' +
        'yOut IS NULL,0,tOut.quantityOut)) AS total'
      'FROM'
      '  value AS v'
      'LEFT JOIN'
      '  ('
      '    SELECT'
      '      tIn.quantityIn,'
      '      tIn.value_id'
      '    FROM'
      '      ('
      '        SELECT'
      '          SUM(quantity) AS quantityIn,'
      '          sm.value_id AS value_id'
      '        FROM stockmove sm'
      '        LEFT JOIN stock s ON s.id=sm.stock_id'
      '        WHERE s.moveIn=1'
      '        GROUP BY sm.value_id'
      '      ) tIn'
      '  ) tIn ON tIn.value_id=v.id'
      'LEFT JOIN'
      '  ('
      '    SELECT'
      '      tOut.quantityOut,'
      '      tOut.value_id'
      '    FROM'
      '      ('
      '        SELECT'
      '          SUM(quantity) AS quantityOut,'
      '          sm.value_id AS value_id'
      '        FROM stockmove sm'
      '        LEFT JOIN stock s ON s.id=sm.stock_id'
      '        WHERE s.moveIn=0'
      '        GROUP BY sm.value_id'
      '      ) tOut'
      '  ) AS tOut ON tOut.value_id=v.id'
      'WHERE'
      '  v.id=:vid')
    Left = 432
    Top = 48
    object qResiduesid: TAutoIncField
      FieldName = 'id'
      ReadOnly = True
    end
    object qResiduesdeviceType_id: TIntegerField
      FieldName = 'deviceType_id'
    end
    object qResiduesvendor: TWideStringField
      FieldName = 'vendor'
      Size = 50
    end
    object qResiduesname: TWideStringField
      FieldName = 'name'
      Size = 250
    end
    object qResiduesisFolder: TSmallintField
      FieldName = 'isFolder'
    end
    object qResiduesquantityIn: TFMTBCDField
      FieldName = 'quantityIn'
      ReadOnly = True
      Precision = 32
      Size = 0
    end
    object qResiduesquantityOut: TFMTBCDField
      FieldName = 'quantityOut'
      ReadOnly = True
      Precision = 32
      Size = 0
    end
    object qResiduestotal: TFMTBCDField
      FieldName = 'total'
      ReadOnly = True
      Precision = 33
      Size = 0
    end
  end
  object dsResidues: TDataSource
    DataSet = qResidues
    Left = 480
    Top = 48
  end
end
