VERSION 5.00
Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
Object = "{F0D2F211-CCB0-11D0-A316-00AA00688B10}#1.0#0"; "MSDATLST.OCX"
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Begin VB.Form Fdocumentoreferencia 
   Caption         =   "Búsqueda de Documentos"
   ClientHeight    =   5865
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   7890
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   5865
   ScaleWidth      =   7890
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton cmdFiltar 
      Caption         =   "&Filtrar"
      Height          =   735
      Left            =   6720
      Picture         =   "Fdocumentoreferencia.frx":0000
      Style           =   1  'Graphical
      TabIndex        =   6
      ToolTipText     =   "Filtar"
      Top             =   240
      Width           =   855
   End
   Begin VB.Frame Frame1 
      Caption         =   "Filtrar por"
      Height          =   1575
      Left            =   0
      TabIndex        =   0
      Top             =   0
      Width           =   6495
      Begin MSDataListLib.DataCombo DtcTipoDocumento 
         Height          =   315
         Left            =   1800
         TabIndex        =   3
         Top             =   600
         Width           =   3615
         _ExtentX        =   6376
         _ExtentY        =   556
         _Version        =   393216
         Style           =   2
         Text            =   ""
      End
      Begin VB.CheckBox ChkAlmacen 
         Caption         =   "Todos"
         Height          =   255
         Left            =   5520
         TabIndex        =   2
         Top             =   240
         Value           =   1  'Checked
         Width           =   855
      End
      Begin MSDataListLib.DataCombo dtcAlmacen 
         Height          =   315
         Left            =   1800
         TabIndex        =   1
         Top             =   240
         Width           =   3615
         _ExtentX        =   6376
         _ExtentY        =   556
         _Version        =   393216
         Style           =   2
         Text            =   ""
      End
      Begin MSComCtl2.DTPicker dtpFechaFin 
         Height          =   315
         Left            =   3840
         TabIndex        =   5
         Top             =   1080
         Width           =   1335
         _ExtentX        =   2355
         _ExtentY        =   556
         _Version        =   393216
         CalendarBackColor=   16777152
         Format          =   62521345
         CurrentDate     =   37533
      End
      Begin MSComCtl2.DTPicker dtpFechaIni 
         Height          =   315
         Left            =   2160
         TabIndex        =   4
         Top             =   1080
         Width           =   1335
         _ExtentX        =   2355
         _ExtentY        =   556
         _Version        =   393216
         CalendarBackColor=   16777152
         Format          =   62521345
         CurrentDate     =   37533
      End
      Begin VB.Label Label1 
         Caption         =   "Tipo de Documento"
         Height          =   255
         Left            =   120
         TabIndex        =   12
         Top             =   600
         Width           =   1455
      End
      Begin VB.Label Label2 
         Caption         =   "Almacen"
         Height          =   255
         Left            =   120
         TabIndex        =   11
         Top             =   270
         Width           =   735
      End
      Begin VB.Label Label4 
         AutoSize        =   -1  'True
         Caption         =   "Al"
         Height          =   195
         Left            =   3600
         TabIndex        =   10
         Top             =   1080
         Width           =   135
      End
      Begin VB.Label Label3 
         AutoSize        =   -1  'True
         Caption         =   "Del"
         Height          =   195
         Left            =   1800
         TabIndex        =   9
         Top             =   1080
         Width           =   240
      End
      Begin VB.Label Label5 
         Caption         =   "Fecha de Proceso :"
         Height          =   255
         Left            =   120
         TabIndex        =   8
         Top             =   1080
         Width           =   1455
      End
   End
   Begin MSDataGridLib.DataGrid DBListar 
      Height          =   4095
      Left            =   0
      TabIndex        =   7
      ToolTipText     =   "Haga Doble Click para Seleccionar"
      Top             =   1680
      Width           =   7845
      _ExtentX        =   13838
      _ExtentY        =   7223
      _Version        =   393216
      BackColor       =   16777152
      HeadLines       =   1
      RowHeight       =   15
      BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Caption         =   "Haga Click en la cabecera de la columna que desee ordenar"
      ColumnCount     =   2
      BeginProperty Column00 
         DataField       =   ""
         Caption         =   ""
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   10250
            SubFormatType   =   0
         EndProperty
      EndProperty
      BeginProperty Column01 
         DataField       =   ""
         Caption         =   ""
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   10250
            SubFormatType   =   0
         EndProperty
      EndProperty
      SplitCount      =   1
      BeginProperty Split0 
         BeginProperty Column00 
         EndProperty
         BeginProperty Column01 
         EndProperty
      EndProperty
   End
   Begin VB.Label lbltipoticket 
      Height          =   255
      Left            =   6720
      TabIndex        =   13
      Top             =   1200
      Visible         =   0   'False
      Width           =   735
   End
End
Attribute VB_Name = "Fdocumentoreferencia"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private MobjAlmacen As DB_INV_MANTENIMIENTOS.C_ALMACEN
Private MObjDocumentos  As DB_MA_MANTENIMIENTOS.C_DOCUMENTO
Private MObjVentasGeneral As DB_OP_FACTURACION.C_VENTASGENERAL
Private MrsobtieneRegistros As ADODB.Recordset

Private MstrOrden As String

Sub FormatoGrilla()

  'StrSql = " SELECT SITE.SITEID,SITE.NAME as Almacén, " & _
             " OP_SALES.DOCTYPEID,DOCTYPE.DESCR as Tipo_Doc.,NBRDOCUMENT as Número " & _
             " ,DATEDOC as Fec.Documento ,DATEPROCESALES as Fec.Proeso,DOCSTATUSID as Estado " & _
             " FROM (OP_SALES INNER JOIN DOCTYPE " & _
             " ON OP_SALES.DOCTYPEID=DOCTYPE.DOCTYPEID) INNER JOIN " & _
             " SITE ON OP_SALES.SITEID=SITE.SITEID " & _
             " WHERE OP_SALES.DOCTYPEID='" & StrTipoDocumento & "'" & _
               StrAlmacenes & " AND " & _
             " DATEPROCESALES Between '" & Format(DatFechaDesde, "yyyymmdd") & "' AND '" & Format(DatFechaHasta, "yyyymmdd") & "'"
    
  DBListar.Columns(0).Visible = False
  DBListar.Columns(1).Width = 1400
  DBListar.Columns(2).Visible = False
  DBListar.Columns(3).Width = 1100
  DBListar.Columns(4).Width = 1100
  DBListar.Columns(5).Width = 1900
  DBListar.Columns(6).Width = 1300
  DBListar.Columns(7).Width = 500
   
End Sub

Private Sub cmdFiltar_Click()
Dim LblnAlmacen As Boolean

    If ChkAlmacen.Value = 1 Then
       LblnAlmacen = True
    Else
       LblnAlmacen = False
    End If
    Set MrsobtieneRegistros = MObjVentasGeneral.MostrarDocumentos(LblnAlmacen, dtcAlmacen.BoundText, DtcTipoDocumento.BoundText, _
                                                                 dtpFechaIni.Value, dtpFechaFin.Value)
                                                                 
    Set DBListar.DataSource = MrsobtieneRegistros
    FormatoGrilla
    DBListar.Refresh
    
End Sub

Private Sub DBListar_DblClick()
     RetornarValores
     Unload Me
End Sub

Private Sub DBListar_HeadClick(ByVal ColIndex As Integer)

'StrSql = " SELECT SITE.SITEID,SITE.NAME as Almacen, " & _
             " OP_SALES.DOCTYPEID,DOCTYPE.DESCR as Tipo_Doc, " & _
             " NBRDOCUMENT as Número " & _
             " ,DATEDOC as Fec_Documento,DATEPROCESALES as Fec_Proceso,DOCSTATUSID as Estado " & _
             " FROM (OP_SALES INNER JOIN DOCTYPE " & _
             " ON OP_SALES.DOCTYPEID=DOCTYPE.DOCTYPEID) INNER JOIN " & _
             " SITE ON OP_SALES.SITEID=SITE.SITEID " & _
             " WHERE OP_SALES.DOCTYPEID='" & StrTipoDocumento & "'" & _
               StrAlmacenes & " AND " & _
             " DATEPROCESALES Between '" & Format(DatFechaDesde, "yyyymmdd") & "' AND '" & Format(DatFechaHasta, "yyyymmdd") & "'"



 On Error GoTo TrataError
    Select Case ColIndex

        Case 1
            MrsobtieneRegistros.Sort = "Almacen" & " " & MstrOrden
        Case 3
            MrsobtieneRegistros.Sort = "Tipo_Doc" & " " & MstrOrden
        Case 4
            MrsobtieneRegistros.Sort = "Número" & " " & MstrOrden
        Case 5
            MrsobtieneRegistros.Sort = "Fec_Documento" & " " & MstrOrden
        Case 6
            MrsobtieneRegistros.Sort = "Fec_Proceso" & " " & MstrOrden
        Case 7
            MrsobtieneRegistros.Sort = "Estado" & " " & MstrOrden

    End Select
        
    If MstrOrden = "ASC" Then
       MstrOrden = "DESC"
    Else
       MstrOrden = "ASC"
    End If
    
TrataError:
End Sub

Private Sub DBListar_KeyUp(KeyCode As Integer, Shift As Integer)
  Select Case KeyCode
     Case 13
            RetornarValores
            Unload Me
     Case 27
            Unload Me
  End Select
End Sub

Private Sub Form_Activate()
   DtcTipoDocumento.BoundText = lbltipoticket.Caption
End Sub

Private Sub Form_Load()

    MstrOrden = "ASC"
    Set MobjAlmacen = New DB_INV_MANTENIMIENTOS.C_ALMACEN
    Set MObjDocumentos = New DB_MA_MANTENIMIENTOS.C_DOCUMENTO
    Set MObjVentasGeneral = New DB_OP_FACTURACION.C_VENTASGENERAL
    
    Call CargaDataCombo(dtcAlmacen, MobjAlmacen.ListarAlmacenesPorStatus(1), "SiteId", "Name")
    Call CargaDataCombo(DtcTipoDocumento, MObjDocumentos.ListarDocumentos, "DOCTYPEID", "DESCR")

    Me.Top = (Screen.Height - Me.Height) / 2
    Me.Left = (Screen.Width - Me.Width) / 2
    
    dtpFechaIni.Year = Year(Date)
    dtpFechaIni.Month = Month(Date)
    dtpFechaIni.Day = 1
       
    dtpFechaFin.Value = Date
   
End Sub

Private Sub Form_Unload(Cancel As Integer)

    Set MobjAlmacen = Nothing
    Set MObjDocumentos = Nothing
    Set MObjVentasGeneral = Nothing
    
End Sub

Private Sub RetornarValores()

'StrSql = " SELECT SITE.SITEID,SITE.NAME as Almacen, " & _
             " OP_SALES.DOCTYPEID,DOCTYPE.DESCR as Tipo_Doc, " & _
             " NBRDOCUMENT as Número " & _
             " ,DATEDOC as Fec_Documento,DATEPROCESALES as Fec_Proceso,DOCSTATUSID as Estado " & _
             " FROM (OP_SALES INNER JOIN DOCTYPE " & _
             " ON OP_SALES.DOCTYPEID=DOCTYPE.DOCTYPEID) INNER JOIN " & _
             " SITE ON OP_SALES.SITEID=SITE.SITEID " & _
             " WHERE OP_SALES.DOCTYPEID='" & StrTipoDocumento & "'" & _
               StrAlmacenes & " AND " & _
             " DATEPROCESALES Between '" & Format(DatFechaDesde, "yyyymmdd") & "' AND '" & Format(DatFechaHasta, "yyyymmdd") & "'"

On Error GoTo TrataError

    If DBListar.Bookmark = 0 Or IsNull(DBListar.Bookmark) Then
        Exit Sub
    End If
    'Public Sub CargaDatos(strALMACEN As String, strTipoDoc As String, dblNroDoc As Double)
    
    With MDIFVENTAS.ActiveForm
        .CargaDatos DBListar.Columns(0).Text, DBListar.Columns(2).Text, DBListar.Columns(4).Text
    End With
    
TrataError:
End Sub




