VERSION 5.00
Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Begin VB.Form FSeleccionDocument 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Seleccionar Documentos"
   ClientHeight    =   6675
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   9120
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   6675
   ScaleWidth      =   9120
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton cmdDesmarcar 
      Height          =   615
      Left            =   8520
      Picture         =   "FSeleccionDocument.frx":0000
      Style           =   1  'Graphical
      TabIndex        =   21
      ToolTipText     =   "Desmarcar Todo"
      Top             =   1440
      Width           =   495
   End
   Begin VB.CommandButton cmdMarcar 
      Height          =   615
      Left            =   8040
      Picture         =   "FSeleccionDocument.frx":030A
      Style           =   1  'Graphical
      TabIndex        =   20
      ToolTipText     =   "Seleccionar Todo"
      Top             =   1440
      Width           =   495
   End
   Begin VB.TextBox txttotal 
      Enabled         =   0   'False
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   405
      Left            =   7320
      Locked          =   -1  'True
      TabIndex        =   19
      Top             =   6000
      Width           =   1455
   End
   Begin VB.CheckBox ChkCliente 
      Caption         =   "Por Cliente"
      Height          =   255
      Left            =   360
      TabIndex        =   17
      Top             =   120
      Width           =   1335
   End
   Begin VB.Frame frmtipoventa 
      Caption         =   "Tipo de Venta"
      Height          =   855
      Left            =   4200
      TabIndex        =   13
      Top             =   1080
      Width           =   1815
      Begin VB.OptionButton opcontado 
         Caption         =   "Contado"
         Height          =   255
         Left            =   240
         TabIndex        =   15
         Top             =   480
         Value           =   -1  'True
         Width           =   1215
      End
      Begin VB.OptionButton Optcredito 
         Caption         =   "Crédito"
         Height          =   195
         Left            =   240
         TabIndex        =   14
         Top             =   240
         Width           =   1335
      End
   End
   Begin VB.CommandButton CMD_CANCELAR 
      Caption         =   "Cancelar"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   735
      Left            =   5640
      Picture         =   "FSeleccionDocument.frx":0614
      Style           =   1  'Graphical
      TabIndex        =   12
      Top             =   5640
      Width           =   1425
   End
   Begin VB.CommandButton CMD_ACEPTAR 
      Caption         =   "Aceptar"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   735
      Left            =   4200
      Picture         =   "FSeleccionDocument.frx":091E
      Style           =   1  'Graphical
      TabIndex        =   11
      Tag             =   "R ASDASD"
      Top             =   5640
      Width           =   1425
   End
   Begin VB.CommandButton cmdfiltrar 
      Caption         =   "Filtrar"
      Height          =   615
      Left            =   6360
      Picture         =   "FSeleccionDocument.frx":0C28
      Style           =   1  'Graphical
      TabIndex        =   3
      Top             =   1320
      Width           =   1095
   End
   Begin MSDataGridLib.DataGrid DBGListarDocu 
      Height          =   3255
      Left            =   120
      TabIndex        =   2
      Top             =   2160
      Width           =   8895
      _ExtentX        =   15690
      _ExtentY        =   5741
      _Version        =   393216
      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
      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.Frame Frame2 
      Caption         =   "Rango de Fechas"
      Height          =   855
      Left            =   120
      TabIndex        =   1
      Top             =   1080
      Width           =   3975
      Begin MSComCtl2.DTPicker DtpFechaAL 
         Height          =   300
         Left            =   2280
         TabIndex        =   7
         Top             =   360
         Width           =   1335
         _ExtentX        =   2355
         _ExtentY        =   529
         _Version        =   393216
         Format          =   71499777
         CurrentDate     =   37844
      End
      Begin MSComCtl2.DTPicker DtpFechaDel 
         Height          =   300
         Left            =   600
         TabIndex        =   6
         Top             =   360
         Width           =   1335
         _ExtentX        =   2355
         _ExtentY        =   529
         _Version        =   393216
         Format          =   71499777
         CurrentDate     =   37844
      End
      Begin VB.Label Label4 
         Caption         =   "Al"
         Height          =   255
         Left            =   2040
         TabIndex        =   5
         Top             =   360
         Width           =   375
      End
      Begin VB.Label Label3 
         Caption         =   "Del "
         Height          =   255
         Left            =   120
         TabIndex        =   4
         Top             =   360
         Width           =   495
      End
   End
   Begin VB.Frame Frame1 
      Height          =   855
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   8175
      Begin VB.CommandButton cmdBuscar 
         Enabled         =   0   'False
         Height          =   375
         Left            =   2160
         Picture         =   "FSeleccionDocument.frx":0D72
         Style           =   1  'Graphical
         TabIndex        =   9
         Top             =   360
         Width           =   375
      End
      Begin VB.TextBox txtcodcliente 
         Height          =   285
         Left            =   120
         TabIndex        =   8
         Top             =   360
         Width           =   1935
      End
      Begin VB.Label lbldesrcliente 
         BorderStyle     =   1  'Fixed Single
         Height          =   285
         Left            =   2640
         TabIndex        =   10
         Top             =   360
         Width           =   5175
      End
   End
   Begin VB.Label lblSeleccion 
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   120
      TabIndex        =   22
      Top             =   5880
      Width           =   3975
   End
   Begin VB.Label Label1 
      Caption         =   "Total"
      Height          =   225
      Left            =   7440
      TabIndex        =   18
      Top             =   5640
      Width           =   1095
   End
   Begin VB.Line Line1 
      X1              =   7200
      X2              =   8880
      Y1              =   5880
      Y2              =   5880
   End
   Begin VB.Shape Shape1 
      Height          =   975
      Left            =   7200
      Top             =   5520
      Width           =   1695
   End
   Begin VB.Label lblmensaje 
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   120
      TabIndex        =   16
      Top             =   5520
      Width           =   3855
   End
End
Attribute VB_Name = "FSeleccionDocument"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' Variables para las Búsquedas
Public GrecibeUbicacion As BookmarkEnum
Public GrecibeColumnaID As String
Public GrecibeColumnaOpcional As String
Public GrecibeColumnaOpcional2 As String
Public GrecibeColumnaOpcional3 As String

' Variable para la Busqueda de Clientes

Private MobjCliente As DB_MA_MANTENIMIENTOS.C_CLIENTE
Private MrsCliente As ADODB.Recordset
Private MobjVentas As DB_OP_FACTURACION.C_VENTASGENERAL
Sub FormatoGrilla()

    DBGListarDocu.Columns(0).Width = 900
    DBGListarDocu.Columns(1).Width = 1200
    DBGListarDocu.Columns(2).Width = 1700
    DBGListarDocu.Columns(3).Width = 1550
    DBGListarDocu.Columns(4).NumberFormat = GMascara(GintDecResultado)
    DBGListarDocu.Columns(4).Width = 1200
    DBGListarDocu.Columns(4).Alignment = dbgRight
    DBGListarDocu.Columns(5).Visible = False
    DBGListarDocu.Columns(6).Alignment = dbgCenter
    
End Sub


Private Sub ChkCliente_Click()
    
    If ChkCliente.Value = 0 Then
       txtcodcliente.Text = Empty
       lbldesrcliente.Caption = Empty
       Frame1.Enabled = False
       cmdBuscar.Enabled = False
    Else
       Frame1.Enabled = True
       cmdBuscar.Enabled = True
    End If
     
End Sub

Private Sub CMD_ACEPTAR_Click()
Screen.MousePointer = 11
 RetornarValores
Screen.MousePointer = 0
 Unload Me
End Sub

Private Sub cmd_Cancelar_Click()
Unload Me
End Sub

Private Sub cmdBuscar_Click()
  
    Dim ArrayBusqueda(1 To 2, 1 To 3) As Variant
    ArrayBusqueda(1, 1) = "CUSTIDSS"
    ArrayBusqueda(1, 2) = "Código "
    ArrayBusqueda(1, 3) = 1500
    ArrayBusqueda(2, 1) = "CUSTNAME"
    ArrayBusqueda(2, 2) = "Nombre "
    ArrayBusqueda(2, 3) = 4000
      
    FBusquedasVta2.GnroPantalla = 1
    FBusquedasVta2.GObtenerRegistros MobjCliente.ListarClientesAyudaTPC, ArrayBusqueda, 2, 2
    FBusquedasVta2.Show vbModal
    
    If GrecibeUbicacion <> 0 Then
        txtcodcliente.Text = GrecibeColumnaID
        lbldesrcliente.Caption = GrecibeColumnaOpcional
    End If
      
End Sub

Private Sub cmdDesmarcar_Click()
If Not IsNull(DBGListarDocu.Bookmark) Then
    Dim LARRAY(1, 4) As Variant
    Dim bk As Variant
    Dim LRSFIL As ADODB.Recordset
    bk = DBGListarDocu.Bookmark
    
    LARRAY(1, 1) = DBGListarDocu.Columns(7).Text
    LARRAY(1, 2) = DBGListarDocu.Columns(1).Text
    LARRAY(1, 3) = 0
    LARRAY(1, 4) = 1
    
    Set LRSFIL = MobjVentas.Auxiliar2(LARRAY, 0)
    Set DBGListarDocu.DataSource = LRSFIL
    FormatoGrilla
    DBGListarDocu.Refresh
    DBGListarDocu.Bookmark = bk
    txttotal.Text = GFormatodeNumero(0, GintDecResultado)
    lblSeleccion.Caption = "0 registros seleccionados."
End If
End Sub

Private Sub cmdfiltrar_Click()
   
   ' Variables
   
     Dim Lrsfiltro As ADODB.Recordset
     Dim LintContCred As Integer
     Dim LarrayParam(1, 6) As Variant
     Dim LintFiltroCliente As Integer
     
   ' ---------
'   If ChkCliente.Value = 1 And Trim(txtcodcliente.Text) = EMPY And Optcredito.Value Then
'        MsgBox "El filtado por Crédito requiere cliente"
'        txtcodcliente.SetFocus
'   End If
    
   If Optcredito.Value = True Then
      LintContCred = 1  ' Es Crédito
   Else
      LintContCred = 0  ' Es Contado
   End If
   
   If ChkCliente.Value = 1 Then
      LintFiltroCliente = 1
   Else
      LintFiltroCliente = 0
   End If
      
   LarrayParam(1, 1) = LintContCred
   LarrayParam(1, 2) = LintFiltroCliente
   LarrayParam(1, 3) = Format(DtpFechaDel.Value, "YYYYMMDD")
   LarrayParam(1, 4) = Format(DtpFechaAL.Value, "YYYYMMDD")
   LarrayParam(1, 5) = GstrSiteProce
   LarrayParam(1, 6) = txtcodcliente.Text
   
   
   Set Lrsfiltro = MobjVentas.Auxiliar1(LarrayParam)
   
   Set DBGListarDocu.DataSource = Lrsfiltro
   FormatoGrilla
   DBGListarDocu.Refresh
   lblmensaje.Caption = Lrsfiltro.RecordCount & " registros encontrados."
   lblSeleccion.Caption = "0 registros seleccionados."
    
End Sub

Private Sub cmdMarcar_Click()
If Not IsNull(DBGListarDocu.Bookmark) Then
    Dim LARRAY(1, 4) As Variant
    Dim bk As Variant
    Dim LRSFIL As ADODB.Recordset
    bk = DBGListarDocu.Bookmark
    
    LARRAY(1, 1) = DBGListarDocu.Columns(7).Text
    LARRAY(1, 2) = DBGListarDocu.Columns(1).Text
    LARRAY(1, 3) = 1
    LARRAY(1, 4) = 1
    
    Set LRSFIL = MobjVentas.Auxiliar2(LARRAY, 0)
    Set DBGListarDocu.DataSource = LRSFIL
    FormatoGrilla
    DBGListarDocu.Refresh
    DBGListarDocu.Bookmark = bk
    txttotal.Text = GFormatodeNumero(MobjVentas.Auxiliar2(LARRAY(1, 1), 1)!TOT, GintDecResultado)
    lblSeleccion.Caption = MobjVentas.Auxiliar2(LARRAY(1, 1), 1)!CANTREG & " registros seleccionados."
End If
End Sub

Private Sub DBGListarDocu_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeySpace And Not IsNull(DBGListarDocu.Bookmark) Then
    Dim LARRAY(1, 4) As Variant
    Dim bk As Variant
    Dim LRSFIL As ADODB.Recordset
    bk = DBGListarDocu.Bookmark
    
    LARRAY(1, 1) = DBGListarDocu.Columns(7).Text
    LARRAY(1, 2) = DBGListarDocu.Columns(1).Text
    LARRAY(1, 3) = IIf(Trim(DBGListarDocu.Columns(6).Text) = "Si", 0, 1)
    LARRAY(1, 4) = 0
    
    Set LRSFIL = MobjVentas.Auxiliar2(LARRAY, 0)
    Set DBGListarDocu.DataSource = LRSFIL
    FormatoGrilla
    DBGListarDocu.Refresh
    DBGListarDocu.Bookmark = bk
    txttotal.Text = GFormatodeNumero(IIf(IsNull(MobjVentas.Auxiliar2(LARRAY(1, 1), 1)!TOT), 0, MobjVentas.Auxiliar2(LARRAY(1, 1), 1)!TOT), GintDecResultado)
    lblSeleccion.Caption = MobjVentas.Auxiliar2(LARRAY(1, 1), 1)!CANTREG & " registros seleccionados. "
End If
End Sub

Private Sub Form_Load()
  
  Me.Left = (Screen.Width - Me.Width) / 2
  Me.Top = (Screen.Height - Me.Height) / 2
  
  
  'cmdBuscar.Enabled = True
  ChkCliente.Value = 0
  
  InstanciarObjetos
  
  DtpFechaDel.Value = Now
  DtpFechaAL.Value = Now
     
End Sub

Sub InstanciarObjetos()
    
   Set MobjVentas = New DB_OP_FACTURACION.C_VENTASGENERAL
   Set MobjCliente = New DB_MA_MANTENIMIENTOS.C_CLIENTE
   Set MrsCliente = New ADODB.Recordset
      
End Sub

Sub DestruirObjetos()
   Set MobjCliente = Nothing
   Set MrsCliente = Nothing
   Set MobjVentas = Nothing
End Sub

Private Sub Form_Unload(Cancel As Integer)
    
   DestruirObjetos
   
End Sub

Private Sub opcontado_Click()
    Set DBGListarDocu.DataSource = Nothing
    lblmensaje.Caption = ""
    lblSeleccion.Caption = ""
End Sub

Private Sub Optcredito_Click()
    Set DBGListarDocu.DataSource = Nothing
    lblmensaje.Caption = ""
    lblSeleccion.Caption = ""
End Sub

Private Sub txtcodcliente_Change()
If ChkCliente.Value = 1 Then
    cmdfiltrar_Click
End If
End Sub

Private Sub txtcodcliente_KeyPress(KeyAscii As Integer)
      If KeyAscii = 13 Then
      Set MrsCliente = MobjCliente.ListarPorClienteID(txtcodcliente.Text)
      
      If MrsCliente.EOF Then
         MsgBox "Código de cliente no existe", vbDefaultButton1 + vbExclamation, "Advertencia"
         txtcodcliente.SetFocus
         Set MrsCliente = Nothing
         Exit Sub
      Else
         lbldesrcliente.Caption = MrsCliente!custname
      End If
      
      Set MrsCliente = Nothing
   End If

End Sub
Private Sub RetornarValores()


On Error GoTo trataerror

    'ACA SE VALIDA SI SE SELECCIONO ALGUN DOCUMENTO PARA PASAR
    
    With MDIFVENTAS.ActiveForm
        .CargaDatos2 CDbl(DBGListarDocu.Columns(7).Text), ChkCliente.Value, txtcodcliente.Text, IIf(Optcredito.Value, "06", "01")
    End With
Exit Sub
trataerror:
   MsgBox Err.Description, vbDefaultButton1 + vbCritical, "Mensaje"
End Sub


