object consumosfito: Tconsumosfito
  Left = 0
  Top = 0
  Caption = 'Estado de stocks de materias primas'
  ClientHeight = 649
  ClientWidth = 1245
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  Position = poOwnerFormCenter
  OnShow = FormShow
  PixelsPerInch = 96
  TextHeight = 13
  object Panel1: TPanel
    Left = 0
    Top = 0
    Width = 1245
    Height = 44
    Align = alTop
    TabOrder = 0
    ExplicitTop = -5
    ExplicitWidth = 1139
    object Label1: TLabel
      Left = 8
      Top = 5
      Width = 70
      Height = 13
      Alignment = taRightJustify
      Caption = 'Fecha Inicio:'
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'Tahoma'
      Font.Style = [fsBold]
      ParentFont = False
    end
    object Label2: TLabel
      Left = 23
      Top = 24
      Width = 55
      Height = 13
      Alignment = taRightJustify
      Caption = 'Fecha Fin:'
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'Tahoma'
      Font.Style = [fsBold]
      ParentFont = False
    end
    object Label3: TLabel
      Left = 186
      Top = 5
      Width = 148
      Height = 13
      Alignment = taRightJustify
      Caption = 'Stock inicial de inventario:'
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'Tahoma'
      Font.Style = [fsBold]
      ParentFont = False
    end
    object Label4: TLabel
      Left = 195
      Top = 24
      Width = 139
      Height = 13
      Alignment = taRightJustify
      Caption = 'Stock inicial de historico:'
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'Tahoma'
      Font.Style = [fsBold]
      ParentFont = False
    end
    object finicio: TDateTimePicker
      Left = 84
      Top = 1
      Width = 81
      Height = 21
      Date = 45390.382988483800000000
      Time = 45390.382988483800000000
      TabOrder = 0
    end
    object ffin: TDateTimePicker
      Left = 84
      Top = 21
      Width = 81
      Height = 21
      Date = 45390.383022696760000000
      Time = 45390.383022696760000000
      TabOrder = 1
    end
    object Panel4: TPanel
      Left = 456
      Top = 1
      Width = 788
      Height = 42
      Align = alRight
      TabOrder = 2
      object Button2: TButton
        Left = 199
        Top = 1
        Width = 66
        Height = 40
        Align = alLeft
        Caption = 'Imprimir'
        Font.Charset = DEFAULT_CHARSET
        Font.Color = clWindowText
        Font.Height = -11
        Font.Name = 'Tahoma'
        Font.Style = [fsBold]
        ImageAlignment = iaBottom
        ImageIndex = 10
        Images = BASE.listaiconos
        ParentFont = False
        TabOrder = 0
      end
      object Button1: TButton
        Left = 133
        Top = 1
        Width = 66
        Height = 40
        Align = alLeft
        Caption = 'Exportar'
        Font.Charset = DEFAULT_CHARSET
        Font.Color = clWindowText
        Font.Height = -11
        Font.Name = 'Tahoma'
        Font.Style = [fsBold]
        ImageAlignment = iaBottom
        ImageIndex = 11
        Images = BASE.listaiconos
        ParentFont = False
        TabOrder = 1
        OnClick = Button1Click
      end
      object Button3: TButton
        Left = 67
        Top = 1
        Width = 66
        Height = 40
        Align = alLeft
        Caption = 'Borrar'
        Font.Charset = DEFAULT_CHARSET
        Font.Color = clWindowText
        Font.Height = -11
        Font.Name = 'Tahoma'
        Font.Style = [fsBold]
        ImageAlignment = iaBottom
        ImageIndex = 1
        Images = BASE.listaiconos
        ParentFont = False
        TabOrder = 2
        OnClick = Button3Click
        ExplicitLeft = 61
        ExplicitTop = -2
      end
      object Button4: TButton
        Left = 1
        Top = 1
        Width = 66
        Height = 40
        Align = alLeft
        Caption = 'Nuevo'
        Font.Charset = DEFAULT_CHARSET
        Font.Color = clWindowText
        Font.Height = -11
        Font.Name = 'Tahoma'
        Font.Style = [fsBold]
        ImageAlignment = iaBottom
        ImageIndex = 0
        Images = BASE.listaiconos
        ParentFont = False
        TabOrder = 3
        OnClick = Button4Click
      end
    end
    object GroupBox1: TGroupBox
      Left = 435
      Top = 3
      Width = 27
      Height = 40
      TabOrder = 3
      object checkinventario: TRadioButton
        Left = 5
        Top = -1
        Width = 23
        Height = 21
        TabOrder = 0
      end
      object checkhistorico: TRadioButton
        Left = 5
        Top = 17
        Width = 21
        Height = 23
        Checked = True
        TabOrder = 1
        TabStop = True
      end
    end
    object comboinventarios: TDBLookupComboBox
      Left = 340
      Top = 1
      Width = 93
      Height = 21
      DropDownRows = 10
      DropDownWidth = 200
      KeyField = 'fecha'
      ListField = 'fecha'
      ListSource = dsqultimoinventario
      TabOrder = 4
    end
    object combohistoricos: TDBLookupComboBox
      Left = 340
      Top = 21
      Width = 93
      Height = 21
      DropDownWidth = 300
      KeyField = 'fecha_inicio'
      ListField = 'fecha_inicio;fecha_fin;id'
      ListSource = dsqhistoricoconsumos2
      TabOrder = 5
    end
  end
  object Panel2: TPanel
    Left = 0
    Top = 44
    Width = 165
    Height = 605
    Align = alLeft
    TabOrder = 1
    object DBGrid1: TDBGrid
      Left = 1
      Top = 27
      Width = 163
      Height = 577
      Align = alClient
      DataSource = dsqhistoricoconsumos
      TabOrder = 0
      TitleFont.Charset = DEFAULT_CHARSET
      TitleFont.Color = clWindowText
      TitleFont.Height = -11
      TitleFont.Name = 'Tahoma'
      TitleFont.Style = []
      Columns = <
        item
          Expanded = False
          FieldName = 'fecha_inicio'
          Visible = True
        end
        item
          Expanded = False
          FieldName = 'fecha_fin'
          Visible = True
        end>
    end
    object Panel5: TPanel
      Left = 1
      Top = 1
      Width = 163
      Height = 26
      Align = alTop
      Alignment = taLeftJustify
      Caption = '  Historico'
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'Tahoma'
      Font.Style = [fsBold]
      ParentFont = False
      TabOrder = 1
    end
  end
  object Panel3: TPanel
    Left = 165
    Top = 44
    Width = 1080
    Height = 605
    Align = alClient
    TabOrder = 2
    ExplicitWidth = 974
    object DBGrid2: TDBGrid
      Left = 1
      Top = 27
      Width = 1078
      Height = 577
      Align = alClient
      DataSource = dsqconsumostratamientos
      TabOrder = 0
      TitleFont.Charset = DEFAULT_CHARSET
      TitleFont.Color = clWindowText
      TitleFont.Height = -11
      TitleFont.Name = 'Tahoma'
      TitleFont.Style = []
      Columns = <
        item
          Expanded = False
          FieldName = 'idaf'
          Title.Caption = 'Id Art.'
          Width = 37
          Visible = True
        end
        item
          Expanded = False
          FieldName = 'codigo'
          Title.Caption = 'C'#243'digo'
          Width = 137
          Visible = True
        end
        item
          Expanded = False
          FieldName = 'descripcion_af'
          Title.Caption = 'Descripci'#243'n'
          Width = 175
          Visible = True
        end
        item
          Expanded = False
          FieldName = 'familia'
          Title.Caption = 'Familia'
          Width = 88
          Visible = True
        end
        item
          Expanded = False
          FieldName = 'registro'
          Title.Caption = 'N'#186' Registro'
          Width = 69
          Visible = True
        end
        item
          Expanded = False
          FieldName = 'stock_anterior'
          Title.Caption = 'Stock inicial'
          Width = 58
          Visible = True
        end
        item
          Expanded = False
          FieldName = 'consumo_periodo'
          Title.Caption = 'Consumo'
          Width = 47
          Visible = True
        end
        item
          Expanded = False
          FieldName = 'compras_periodo'
          Title.Caption = 'Compras y devoluciones'
          Visible = True
        end
        item
          Expanded = False
          FieldName = 'regularizacion'
          Title.Caption = 'Regularizaci'#243'n'
          Width = 64
          Visible = True
        end
        item
          Expanded = False
          FieldName = 'stock_final'
          Title.Caption = 'Stock final'
          Width = 51
          Visible = True
        end
        item
          Expanded = False
          FieldName = 'unidades'
          Title.Caption = 'Unidades'
          Width = 47
          Visible = True
        end
        item
          Expanded = False
          FieldName = 'precio_medio'
          Title.Caption = 'PM stock'
          Width = 47
          Visible = True
        end
        item
          Expanded = False
          FieldName = 'valor_stock'
          Title.Caption = 'Valor Stock'
          Visible = True
        end>
    end
    object Panel6: TPanel
      Left = 1
      Top = 1
      Width = 1078
      Height = 26
      Align = alTop
      Alignment = taLeftJustify
      Caption = '  ESTADO DE STOCKS MATERIAS PRIMAS'
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'Tahoma'
      Font.Style = [fsBold]
      ParentFont = False
      TabOrder = 1
      ExplicitWidth = 972
    end
  end
  object qconsumostratamientos: TFDQuery
    Connection = DM.DBagrigest
    SQL.Strings = (
      
        'select * from consumos_tratamientos where id=:ID order by famili' +
        'a, descripcion_af'
      '')
    Params = <
      item
        DataType = ftUnknown
        Name = 'ID'
        ParamType = ptUnknown
      end>
    Left = 88
    Top = 360
    ParamData = <
      item
        DataType = ftUnknown
        Name = 'ID'
        ParamType = ptUnknown
      end>
    object qconsumostratamientosid: TIntegerField
      FieldName = 'id'
      Required = True
    end
    object qconsumostratamientoside: TIntegerField
      FieldName = 'ide'
      Required = True
    end
    object qconsumostratamientosidaf: TIntegerField
      FieldName = 'idaf'
      Required = True
    end
    object qconsumostratamientosdescripcion_af: TWideStringField
      FieldName = 'descripcion_af'
      Size = 100
    end
    object qconsumostratamientosregistro: TWideStringField
      FieldName = 'registro'
      Size = 90
    end
    object qconsumostratamientosstock_anterior: TFloatField
      FieldName = 'stock_anterior'
    end
    object qconsumostratamientosconsumo_periodo: TFloatField
      FieldName = 'consumo_periodo'
    end
    object qconsumostratamientoscompras_periodo: TFloatField
      FieldName = 'compras_periodo'
    end
    object qconsumostratamientosregularizacion: TFloatField
      FieldName = 'regularizacion'
    end
    object qconsumostratamientosstock_final: TFloatField
      FieldName = 'stock_final'
    end
    object qconsumostratamientosunidades: TWideStringField
      FieldName = 'unidades'
      Size = 90
    end
    object qconsumostratamientosprecio_medio: TFloatField
      FieldName = 'precio_medio'
    end
    object qconsumostratamientosvalor_stock: TFloatField
      FieldName = 'valor_stock'
    end
    object qconsumostratamientosfecha_inicio: TDateField
      FieldName = 'fecha_inicio'
    end
    object qconsumostratamientosfecha_fin: TDateField
      FieldName = 'fecha_fin'
    end
    object qconsumostratamientoscodigo: TWideStringField
      FieldName = 'codigo'
      Size = 90
    end
    object qconsumostratamientosfamilia: TWideStringField
      FieldName = 'familia'
      Size = 90
    end
  end
  object qultimoinventario: TFDQuery
    Connection = DM.DBagrigest
    SQL.Strings = (
      
        'select * from control_stock where regularizado=1 order by fecha ' +
        'desc')
    Params = <>
    Left = 728
    Top = 112
    object qultimoinventarioide: TIntegerField
      FieldName = 'ide'
      Required = True
    end
    object qultimoinventariofecha: TDateField
      FieldName = 'fecha'
      Required = True
      DisplayFormat = 'dd/mm/yy'
    end
    object qultimoinventarioregularizado: TIntegerField
      FieldName = 'regularizado'
      Required = True
    end
  end
  object dsqultimoinventario: TDataSource
    DataSet = qultimoinventario
    Left = 728
    Top = 72
  end
  object dsqconsumostratamientos: TDataSource
    DataSet = qconsumostratamientos
    Left = 88
    Top = 328
  end
  object qconsumos: TFDQuery
    Connection = DM.DBagrigest
    SQL.Strings = (
      
        'select distinct(idaf),(select codigo from articulosf where id=a.' +
        'idaf) as codigo,ide,(select descripcion from articulosf where id' +
        '=a.idaf) as descripcion,ifnull((select registro from articulosf ' +
        'where id=a.idaf),'#39' '#39') as registro,(select descripcion from famil' +
        'ias where id=(select familia from articulosf where id=a.idaf)) a' +
        's familia,'
      
        'ifnull((select sum(cantidad_materia) from tratamientos_detalle  ' +
        'where idaf=a.idaf and (ide,idt) in (select ide,id from tratamien' +
        'tos where fecha>=:FINICIO and fecha<=:FFIN) group by idaf),0) as' +
        ' consumo,'
      
        'ifnull((select sum(cantidad) from entradas_detalle where id_prop' +
        'io=(select codigo from articulosf where id=a.idaf) and identrada' +
        ' in (select id from entradas where fecha>=:FINICIO and fecha<=:F' +
        'FIN) group by id_propio),0) as compras,'
      
        '(select unidad_medida from articulosf where id=a.idaf) as unidad' +
        '_medida,ifnull((select preciocoste from articulosf where id=a.id' +
        'af),0) as PM_stock  from'
      '('
      
        '(select distinct(idaf),ide from tratamientos_detalle where idt i' +
        'n (select id from tratamientos where fecha>=:FINICIO and fecha <' +
        '=:FFIN) and idaf in (select id from articulosf where familia in ' +
        '(select id from familias where (ABONOS=1 or FITOSANITARIOS=1))))'
      ' union all'
      
        '(select distinct(select id from articulosf where codigo=ed.id_pr' +
        'opio) as idaf,idempresa from entradas_detalle ed where identrada' +
        ' in (select id from entradas where fecha>=:FINICIO and fecha<=:F' +
        'FIN) and id_propio in (select codigo from articulosf where famil' +
        'ia in (select id from familias where (ABONOS=1 or FITOSANITARIOS' +
        '=1)) and idproveedor<>0))'
      ') as a  order by familia,descripcion;')
    Params = <
      item
        DataType = ftUnknown
        Name = 'FINICIO'
        ParamType = ptUnknown
      end
      item
        DataType = ftUnknown
        Name = 'FFIN'
        ParamType = ptUnknown
      end>
    Left = 720
    Top = 216
    ParamData = <
      item
        DataType = ftUnknown
        Name = 'FINICIO'
        ParamType = ptUnknown
      end
      item
        DataType = ftUnknown
        Name = 'FFIN'
        ParamType = ptUnknown
      end>
    object qconsumosidaf: TIntegerField
      FieldName = 'idaf'
      ReadOnly = True
    end
    object qconsumoside: TIntegerField
      FieldName = 'ide'
      ReadOnly = True
    end
    object qconsumosdescripcion: TWideStringField
      FieldName = 'descripcion'
      ReadOnly = True
      Size = 100
    end
    object qconsumosregistro: TWideStringField
      FieldName = 'registro'
      ReadOnly = True
      Size = 100
    end
    object qconsumosfamilia: TWideStringField
      FieldName = 'familia'
      ReadOnly = True
      Size = 50
    end
    object qconsumosconsumo: TFloatField
      FieldName = 'consumo'
      ReadOnly = True
    end
    object qconsumoscompras: TFloatField
      FieldName = 'compras'
      ReadOnly = True
    end
    object qconsumosPM_stock: TFloatField
      FieldName = 'PM_stock'
      ReadOnly = True
    end
    object qconsumosunidad_medida: TWideStringField
      FieldName = 'unidad_medida'
      ReadOnly = True
      Size = 90
    end
    object qconsumoscodigo: TWideStringField
      FieldName = 'codigo'
      ReadOnly = True
      Size = 40
    end
  end
  object qstockinventario: TFDQuery
    Connection = DM.DBagrigest
    SQL.Strings = (
      
        'select ifnull(stock_real,0) as stock_final from control_stock_de' +
        'talle where codigo=(select codigo from articulosf where id=:IDAF' +
        ') and fecha=:FECHA')
    Params = <
      item
        DataType = ftUnknown
        Name = 'IDAF'
        ParamType = ptUnknown
      end
      item
        DataType = ftUnknown
        Name = 'FECHA'
        ParamType = ptUnknown
      end>
    Left = 464
    Top = 280
    ParamData = <
      item
        DataType = ftUnknown
        Name = 'IDAF'
        ParamType = ptUnknown
      end
      item
        DataType = ftUnknown
        Name = 'FECHA'
        ParamType = ptUnknown
      end>
    object qstockinventariostock_final: TFloatField
      FieldName = 'stock_final'
      ReadOnly = True
    end
  end
  object qstockhistorico: TFDQuery
    Connection = DM.DBagrigest
    SQL.Strings = (
      
        'select ifnull(stock_final,0) as stock_final from consumos_tratam' +
        'ientos where id=:IDANTERIOR and idaf=:IDAF')
    Params = <
      item
        DataType = ftUnknown
        Name = 'IDANTERIOR'
        ParamType = ptUnknown
      end
      item
        DataType = ftUnknown
        Name = 'IDAF'
        ParamType = ptUnknown
      end>
    Left = 720
    Top = 280
    ParamData = <
      item
        DataType = ftUnknown
        Name = 'IDANTERIOR'
        ParamType = ptUnknown
      end
      item
        DataType = ftUnknown
        Name = 'IDAF'
        ParamType = ptUnknown
      end>
    object qstockhistoricostock_final: TFloatField
      FieldName = 'stock_final'
      ReadOnly = True
    end
  end
  object qidconsumo: TFDQuery
    Connection = DM.DBagrigest
    SQL.Strings = (
      'select ifnull(max(id),0)+1 as id from consumos_tratamientos')
    Params = <>
    Left = 912
    Top = 112
    object qidconsumoid: TLargeintField
      FieldName = 'id'
      ReadOnly = True
    end
  end
  object dsqstockinventario: TDataSource
    DataSet = qstockinventario
    Left = 464
    Top = 240
  end
  object qhistoricoconsumos: TFDQuery
    Connection = DM.DBagrigest
    SQL.Strings = (
      
        'select distinct(fecha_inicio),fecha_fin,id,ide from consumos_tra' +
        'tamientos order by fecha_inicio desc')
    Params = <>
    Left = 88
    Top = 272
    object qhistoricoconsumosfecha_inicio: TDateField
      FieldName = 'fecha_inicio'
    end
    object qhistoricoconsumosfecha_fin: TDateField
      FieldName = 'fecha_fin'
    end
    object qhistoricoconsumosid: TIntegerField
      FieldName = 'id'
      Required = True
    end
    object qhistoricoconsumoside: TIntegerField
      FieldName = 'ide'
      Required = True
    end
  end
  object dsqhistoricoconsumos: TDataSource
    DataSet = qhistoricoconsumos
    OnDataChange = dsqhistoricoconsumosDataChange
    Left = 88
    Top = 232
  end
  object dsqhistoricoconsumos2: TDataSource
    DataSet = qhistoricoconsumos2
    Left = 248
    Top = 208
  end
  object qhistoricoconsumos2: TFDQuery
    Connection = DM.DBagrigest
    SQL.Strings = (
      
        'select distinct(fecha_inicio),fecha_fin,id,ide from consumos_tra' +
        'tamientos order by fecha_inicio desc')
    Params = <>
    Left = 248
    Top = 248
    object qhistoricoconsumos2fecha_inicio: TDateField
      FieldName = 'fecha_inicio'
    end
    object qhistoricoconsumos2fecha_fin: TDateField
      FieldName = 'fecha_fin'
    end
    object qhistoricoconsumos2id: TIntegerField
      FieldName = 'id'
      Required = True
    end
    object qhistoricoconsumos2ide: TIntegerField
      FieldName = 'ide'
      Required = True
    end
  end
  object qborrar: TFDQuery
    Connection = DM.DBagrigest
    SQL.Strings = (
      'delete from consumos_tratamientos where id=:ID')
    Params = <
      item
        DataType = ftUnknown
        Name = 'ID'
        ParamType = ptUnknown
      end>
    Left = 912
    Top = 176
    ParamData = <
      item
        DataType = ftUnknown
        Name = 'ID'
        ParamType = ptUnknown
      end>
  end
  object SaveDialog1: TSaveDialog
    Left = 344
    Top = 16
  end
end
