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"
Object = "{00025600-0000-0000-C000-000000000046}#5.2#0"; "crystl32.ocx"
Begin VB.Form FConfigCarasVendedor 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Configuración de Caras-Vendedor (05.055.00)"
   ClientHeight    =   7635
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   9015
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   7635
   ScaleWidth      =   9015
   Begin VB.ComboBox cmbTurnos 
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H80000002&
      Height          =   360
      Left            =   1215
      Style           =   2  'Dropdown List
      TabIndex        =   23
      Top             =   2160
      Width           =   1575
   End
   Begin VB.CommandButton cmdBusVendedor 
      Height          =   375
      Left            =   3750
      MouseIcon       =   "FConfigCarasVendedor.frx":0000
      MousePointer    =   99  'Custom
      Picture         =   "FConfigCarasVendedor.frx":0152
      Style           =   1  'Graphical
      TabIndex        =   20
      ToolTipText     =   "Buscar Vendedor"
      Top             =   1575
      Width           =   375
   End
   Begin MSComCtl2.DTPicker dtpFechaPos2 
      Height          =   330
      Left            =   3375
      TabIndex        =   18
      Top             =   630
      Width           =   1320
      _ExtentX        =   2328
      _ExtentY        =   582
      _Version        =   393216
      Format          =   61931521
      CurrentDate     =   37631
   End
   Begin VB.ListBox lstCaras 
      BackColor       =   &H00FFFFC0&
      Columns         =   2
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H80000002&
      Height          =   1410
      Left            =   4410
      Style           =   1  'Checkbox
      TabIndex        =   17
      Top             =   1350
      Width           =   3435
   End
   Begin VB.CommandButton cmdBusAlmacen 
      Height          =   375
      Left            =   4770
      MouseIcon       =   "FConfigCarasVendedor.frx":0684
      MousePointer    =   99  'Custom
      Picture         =   "FConfigCarasVendedor.frx":07D6
      Style           =   1  'Graphical
      TabIndex        =   16
      ToolTipText     =   "Buscar Almacén"
      Top             =   225
      Width           =   375
   End
   Begin VB.CommandButton cmdBuscar 
      Enabled         =   0   'False
      Height          =   495
      Left            =   8235
      MouseIcon       =   "FConfigCarasVendedor.frx":0D08
      MousePointer    =   99  'Custom
      Picture         =   "FConfigCarasVendedor.frx":0E5A
      Style           =   1  'Graphical
      TabIndex        =   15
      ToolTipText     =   "Buscar Documento"
      Top             =   180
      Width           =   615
   End
   Begin VB.ComboBox cmbCara 
      Height          =   315
      Left            =   5970
      Style           =   2  'Dropdown List
      TabIndex        =   4
      Top             =   630
      Visible         =   0   'False
      Width           =   1215
   End
   Begin VB.CheckBox chkEstado 
      Alignment       =   1  'Right Justify
      Caption         =   "Estado"
      Height          =   255
      Left            =   6930
      TabIndex        =   3
      Top             =   270
      Width           =   930
   End
   Begin MSComCtl2.DTPicker dtpHasta 
      Height          =   330
      Left            =   7515
      TabIndex        =   0
      Top             =   4050
      Width           =   1275
      _ExtentX        =   2249
      _ExtentY        =   582
      _Version        =   393216
      Enabled         =   0   'False
      Format          =   61931521
      CurrentDate     =   37624
   End
   Begin MSComCtl2.DTPicker dtpDesde 
      Height          =   330
      Left            =   7515
      TabIndex        =   1
      Top             =   3645
      Width           =   1275
      _ExtentX        =   2249
      _ExtentY        =   582
      _Version        =   393216
      Enabled         =   0   'False
      Format          =   61931521
      CurrentDate     =   37624
   End
   Begin MSDataGridLib.DataGrid dbListar 
      Height          =   4560
      Left            =   135
      TabIndex        =   2
      Top             =   3015
      Width           =   6630
      _ExtentX        =   11695
      _ExtentY        =   8043
      _Version        =   393216
      BackColor       =   16777152
      ForeColor       =   -2147483646
      HeadLines       =   1
      RowHeight       =   19
      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            =   9.75
         Charset         =   0
         Weight          =   700
         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            =   3082
            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            =   3082
            SubFormatType   =   0
         EndProperty
      EndProperty
      SplitCount      =   1
      BeginProperty Split0 
         BeginProperty Column00 
         EndProperty
         BeginProperty Column01 
         EndProperty
      EndProperty
   End
   Begin MSDataListLib.DataCombo dtcAlmacen 
      Height          =   315
      Left            =   1095
      TabIndex        =   5
      Top             =   225
      Width           =   3615
      _ExtentX        =   6376
      _ExtentY        =   556
      _Version        =   393216
      Style           =   2
      Text            =   ""
   End
   Begin MSComCtl2.DTPicker dtpFechaPos 
      Height          =   330
      Left            =   1125
      TabIndex        =   6
      Top             =   645
      Width           =   1335
      _ExtentX        =   2355
      _ExtentY        =   582
      _Version        =   393216
      Format          =   61931521
      CurrentDate     =   37582
   End
   Begin Crystal.CrystalReport crTurnos 
      Left            =   8325
      Top             =   975
      _ExtentX        =   741
      _ExtentY        =   741
      _Version        =   348160
      PrintFileLinesPerPage=   60
   End
   Begin MSDataListLib.DataCombo dtcVendedor 
      Height          =   315
      Left            =   1200
      TabIndex        =   21
      Top             =   1575
      Width           =   2535
      _ExtentX        =   4471
      _ExtentY        =   556
      _Version        =   393216
      Style           =   2
      Text            =   ""
   End
   Begin VB.Label lblRegistro 
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   555
      Left            =   6885
      TabIndex        =   10
      Top             =   6975
      Width           =   2055
   End
   Begin VB.Label lblTurno 
      Caption         =   "Turno"
      Height          =   255
      Left            =   360
      TabIndex        =   24
      Top             =   2160
      Width           =   615
   End
   Begin VB.Label lblVendecor 
      AutoSize        =   -1  'True
      Caption         =   "Vendedor"
      Height          =   195
      Left            =   360
      TabIndex        =   22
      Top             =   1575
      Width           =   690
   End
   Begin VB.Shape Shape3 
      Height          =   1635
      Left            =   135
      Top             =   1260
      Width           =   7890
   End
   Begin VB.Label Label5 
      Caption         =   "Fecha "
      Height          =   240
      Left            =   2745
      TabIndex        =   19
      Top             =   675
      Width           =   645
   End
   Begin VB.Image Image2 
      Height          =   480
      Left            =   8325
      Picture         =   "FConfigCarasVendedor.frx":138C
      Top             =   3105
      Width           =   480
   End
   Begin VB.Shape Shape2 
      Height          =   1545
      Left            =   6840
      Top             =   3015
      Width           =   2085
   End
   Begin VB.Image Image1 
      Height          =   480
      Left            =   8190
      Picture         =   "FConfigCarasVendedor.frx":1696
      Top             =   2430
      Width           =   480
   End
   Begin VB.Label lblAlmacen 
      AutoSize        =   -1  'True
      Caption         =   "Almacen"
      Height          =   195
      Left            =   255
      TabIndex        =   14
      Top             =   225
      Width           =   615
   End
   Begin VB.Label lblFecha 
      Caption         =   "Fecha de Proceso"
      Height          =   375
      Left            =   270
      TabIndex        =   13
      Top             =   675
      Width           =   735
   End
   Begin VB.Label Label2 
      Caption         =   "Label2"
      Height          =   15
      Left            =   1935
      TabIndex        =   12
      Top             =   285
      Width           =   135
   End
   Begin VB.Label lblCara 
      Caption         =   "Cara"
      Height          =   255
      Left            =   5370
      TabIndex        =   11
      Top             =   630
      Visible         =   0   'False
      Width           =   615
   End
   Begin VB.Label Label1 
      Caption         =   "Imprimir"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   285
      Left            =   6975
      TabIndex        =   9
      Top             =   3240
      Width           =   915
   End
   Begin VB.Label Label3 
      Caption         =   "Hasta"
      Height          =   240
      Left            =   6975
      TabIndex        =   8
      Top             =   4095
      Width           =   690
   End
   Begin VB.Label Label4 
      Caption         =   "Desde"
      Height          =   195
      Left            =   6975
      TabIndex        =   7
      Top             =   3735
      Width           =   600
   End
   Begin VB.Shape Shape1 
      BackColor       =   &H80000004&
      BackStyle       =   1  'Opaque
      BorderColor     =   &H80000006&
      FillColor       =   &H00E0E0E0&
      Height          =   1035
      Left            =   135
      Top             =   135
      Width           =   7890
   End
End
Attribute VB_Name = "FConfigCarasVendedor"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'PROGRAMADOR: EDGAR CANCHO RUIZ

Option Explicit
Public pb_editar As Boolean
Public pb_agregar As Boolean
Public pb_primerregistro As Boolean
Public pb_ultimoregistro As Boolean

Public pbderecho_agregar As Boolean
Public pbderecho_consultar As Boolean
Public pbderecho_editar As Boolean
Public pbderecho_borrar As Boolean
Public pbderecho_imprimir As Boolean
Public pbderecho_ANULAR As Boolean
Public pbderecho_EMITIR As Boolean
Public pb_tiposcreen As String

Public GrecibeUbicacion As BookmarkEnum
Public GrecibeColumnaID As String
Public GrecibeColumnaOpcional As String

Public objAlmacen As DB_INV_MANTENIMIENTOS.C_ALMACEN
Public objVendedor As DB_OP_MANTENIMIENTOS.C_VENDEDOR
Public objCarasVendedor As DB_OP_MANTENIMIENTOS.C_CARAS_VENDEDOR
Public rsobtieneRegistros As ADODB.Recordset

Dim objCorrelativo As DB_CORRELATIVO.C_Correlativos
Dim lngCorrelativo As Long

Dim MdatFecha As Date
Dim Mdatfecha2 As Date

Dim MstrFechaIni As String
Dim MstrFechaFin As String

Private Sub cmdBuscar_Click()
    FBuscarCaraVendedor.Show vbModal
End Sub

Private Sub cmdBusAlmacen_Click()
    'Lineas que llaman al Formulario de Búsqueda
    
    Dim ArrayBusqueda(1 To 2, 1 To 3) As Variant
    ArrayBusqueda(1, 1) = "Siteid"
    ArrayBusqueda(1, 2) = "Código "
    ArrayBusqueda(1, 3) = 1000
    ArrayBusqueda(2, 1) = "Name"
    ArrayBusqueda(2, 2) = "Descripción "
    ArrayBusqueda(2, 3) = 4000
      
    FBusquedasVta.GObtenerRegistros objAlmacen.ListarAlmacenesPorStatus(1), ArrayBusqueda, 2, 2
    FBusquedasVta.Show vbModal
    
    If GrecibeUbicacion <> 0 Then
        dtcAlmacen.BoundText = GrecibeColumnaID
    End If
End Sub

Private Sub cmdBusVendedor_Click()
    'Lineas que llaman al Formulario de Búsqueda
    
    Dim ArrayBusqueda(1 To 2, 1 To 3) As Variant
    ArrayBusqueda(1, 1) = "SALESPERID"
    ArrayBusqueda(1, 2) = "Código "
    ArrayBusqueda(1, 3) = 1200
    ArrayBusqueda(2, 1) = "SALESPERNAME"
    ArrayBusqueda(2, 2) = "Nombre "
    ArrayBusqueda(2, 3) = 4000
      
    FBusquedasVta.GObtenerRegistros objVendedor.ListarVendedoresAyuda, ArrayBusqueda, 2, 2
    FBusquedasVta.Show vbModal
    
    If GrecibeUbicacion <> 0 Then
        dtcVendedor.BoundText = GrecibeColumnaID
    End If
End Sub

Private Sub DBListar_Click()
    PonerDatosGrig
End Sub

Private Sub dbListar_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
    'DBListar.Refresh
    PonerDatosGrig
End Sub

Private Sub dtcAlmacen_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyF2 Then cmdBusAlmacen_Click
End Sub

Private Sub dtcVendedor_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyF2 Then cmdBusVendedor_Click
End Sub

Private Sub dtpFechaPos_Change()
    MdatFecha = dtpFechaPos.Value
    Mdatfecha2 = dtpFechaPos2.Value
    dtpFechaPos2.Value = dtpFechaPos.Value
    CargaDataGrid

End Sub

Private Sub dtpFechaPos2_Change()
    If dtpFechaPos2.Value < dtpFechaPos.Value Then
        dtpFechaPos2.Value = dtpFechaPos.Value
    End If
    Mdatfecha2 = dtpFechaPos2.Value
    CargaDataGrid
End Sub

Private Sub dtpHasta_Change()
    If dtpDesde.Value > dtpHasta.Value Then
        dtpHasta.Value = dtpDesde.Value
    End If
End Sub

Private Sub Form_Activate()
    Call gactualizaopcion(pbderecho_agregar, pbderecho_editar, pbderecho_borrar, pbderecho_imprimir)
    Call gactualiza_barra(Me)
    'lineas nuevas
    ActualizaCaras
    If pbderecho_consultar = False Then
        Unload Me
    End If
End Sub


Private Sub Form_Load()
    'seguridad
    Call gseguridad(Me)

    If pbderecho_consultar Then

        Set objAlmacen = New DB_INV_MANTENIMIENTOS.C_ALMACEN

        Set objVendedor = New DB_OP_MANTENIMIENTOS.C_VENDEDOR
        Set objCarasVendedor = New DB_OP_MANTENIMIENTOS.C_CARAS_VENDEDOR
        Set objCorrelativo = New DB_CORRELATIVO.C_Correlativos
        
        Call obtener_datos
        Call CargaDataCombo(dtcAlmacen, objAlmacen.ListarAlmacenesPorStatus(1), "SiteId", "Name")
        Call CargaDataCombo(dtcVendedor, objVendedor.ListarVendedoresAyuda, "SALESPERID", "SALESPERNAME")
       
    
        Call asigna_campos
        Call gHabilitarReg(Me, False)
        
        pb_primerregistro = True
        
        
        CargaTurnos
        CargaCaras
        dtcAlmacen.BoundText = GstrSiteProce
        MdatFecha = GDatFechaProcesoVentas
        Mdatfecha2 = GDatFechaProcesoVentas
        dtpFechaPos.Value = MdatFecha
        dtpFechaPos.Enabled = True
        dtpFechaPos2.Value = Mdatfecha2
        dtpFechaPos2.Enabled = True
        'lstCaras.Enabled = False
        dtpDesde.Value = Now
        dtpHasta.Value = Now
        Call CargaDataGrid
        
    Else

        MsgBox ("No tiene Derechos de Consultar en este formulario"), vbCritical + vbDefaultButton1, "Mensaje"
    End If
    


    Me.Top = 200
    Me.Left = (Screen.Width - Me.Width) / 2
    
End Sub
Public Sub borrar_registro()

On Error GoTo errhandler

    If Not chkEstado.Value Then
        objCarasVendedor.EliminarCarasVendedor dtcAlmacen.BoundText, dtpFechaPos.Value, cmbTurnos.ListIndex + 1, _
                                                 dtcVendedor.BoundText, Mid(cmbCara.Text, Len(cmbCara.Text) - 1, 2)
            
                                                
        Call gborrar_Registro(Me)
        Call actualizar_registro
        Call CargaDataGrid
        dbListar.SetFocus
    Else
        MsgBox "No se puede Eliminar un Registro ya Aprobado", vbExclamation, "Mensaje"
    End If
Exit Sub
errhandler:
    MsgBox MensajedeError(Err.Number, Err.Description), vbDefaultButton1 + vbCritical, "Advertencia"
    
    
End Sub
Function valida_datos()
Dim I As Integer
Dim Flag As Boolean

Flag = True

    If GVDATO(dtcAlmacen.Text) = Empty Then
        valida_datos = False
        MsgBox "Ingrese Almacen", vbInformation, "Error"
        dtcAlmacen.SetFocus
        Exit Function
    End If
        
    If GVDATO(dtcVendedor.Text) = Empty Then
        valida_datos = False
        MsgBox "Ingrese Vendedor", vbInformation, "Error"
        dtcVendedor.SetFocus
        Exit Function
    End If
    
    If GVDATO(cmbTurnos.Text) = Empty Then
        valida_datos = False
        MsgBox "Ingrese Turno", vbInformation, "Error"
        cmbTurnos.SetFocus
        Exit Function
    End If
    
    valida_datos = True
    
    For I = 0 To lstCaras.ListCount - 1
        If lstCaras.Selected(I) Then
            valida_datos = True
            Exit Function
        Else
            Flag = False
            valida_datos = False
        End If
    Next
    
    If Not Flag Then
        MsgBox "Seleccione alguna Cara", vbInformation, "Error"
    End If
    
End Function
Public Sub grabar_registro()
Dim Flag As Boolean
Dim I As Integer
On Error GoTo errhandler

    If valida_datos() = True Then
        ' llamada al proc de grabacion
        If pb_agregar Then
            
            lngCorrelativo = objCorrelativo.ObtenerCorrelativo(GCUSERID)
            lstCaras.ListIndex = 0
            'Inserto en mi temporal cada una de las caras seleccionadas
            
            For I = 0 To lstCaras.ListCount - 1
                If lstCaras.Selected(I) Then
                    Flag = objCarasVendedor.BuscaRegistro(dtcAlmacen.BoundText, dtpFechaPos.Value, dtpFechaPos2.Value, cmbTurnos.ListIndex + 1, Mid(lstCaras.List(I), Len(lstCaras.List(I)) - 1, 2))
                    If Flag Then
                        MsgBox lstCaras.List(I) + " asignada a otro Vendedor en la misma fecha y turno", vbExclamation, "Mensaje"
                        Exit Sub
                    End If
                    
                End If
            Next
            
            
            For I = 0 To lstCaras.ListCount - 1
                If lstCaras.Selected(I) Then
                    objCarasVendedor.AgregaEnTemporal lngCorrelativo, Mid(lstCaras.List(I), Len(lstCaras.List(I)) - 1, 2)
                End If
            Next
            
            
            
'            Flag = objCarasVendedor.BuscaRegistro(dtcAlmacen.BoundText, dtpFechaPos.Value, cmbTurnos.ListIndex + 1, Mid(cmbCara.Text, Len(cmbCara.Text) - 1, 2))
          ' If Not Flag Then
                objCarasVendedor.AgregaCarasVendedor dtcAlmacen.BoundText, dtpFechaPos.Value, dtpFechaPos2.Value, cmbTurnos.ListIndex + 1, _
                                             dtcVendedor.BoundText, lngCorrelativo
           ' Else
          '      MsgBox "Ya existe un Vendedor registrado con los datos ingresados", vbExclamation, "Mensaje"
           '     Exit Sub
           ' End If
        Else
           ' objTarjetasMonto.ActualizarTarjetaMonto dtcAlmacen.BoundText, dtcTarjetas.BoundText, dtpFechaPos.Value, _
                                            GDatFechaProceso, dtcMoneda.BoundText, GFormatodeNumero(CDbl(ctnMonto.Text), GintDecResultado)
        End If
        Call CargaDataGrid
        Call ggrabar_registro(Me)
        dtpFechaPos.Enabled = True
        dtpFechaPos2.Enabled = True
        
        
    End If
    dbListar.SetFocus
    
Exit Sub

errhandler:
    MsgBox MensajedeError(Err.Number, Err.Description), vbDefaultButton1 + vbCritical, "Advertencia"
    
    
End Sub
Public Sub actualizar_registro()

End Sub
Public Sub agregar_registro()
    Call gagregar_registro(Me, dtcAlmacen)
    'Limpiar
    dtcAlmacen.BoundText = GstrSiteProce
    dtpFechaPos.Value = MdatFecha
    dtpFechaPos.Enabled = True
    dtpFechaPos2.Value = MdatFecha
    dtpFechaPos2.Enabled = True
    chkEstado.Enabled = False
    CargaCaras
End Sub
Public Sub modificar_registro()
    If GVDATO(dtcAlmacen.Text) = Empty Then
        MsgBox "Seleccione un Registro que desee modificar ", vbExclamation, "Mensaje"
        Exit Sub
    End If
    
    Call gmodificar_registro(Me, dtcAlmacen)
    chkEstado.Enabled = False
End Sub

Public Sub descartar_registro()
    ' Revertir cambios
    Call gdescartar_registro(Me)
    Call asigna_campos
    'Limpiar
    dtpFechaPos.Enabled = True
End Sub

Sub obtener_datos()

End Sub

Sub salir_formulario()
    ' validar que no haya procesos pendientes
    ' si no hay problemas
    MDIFVENTAS.Toolbar1.Buttons(18).Caption = "Salir"    ' boton salir
    Unload Me
End Sub

Sub asigna_campos() ' falta decidir si va ha ser public o private

End Sub
Public Sub CargaDatos(Param1 As String, Param2 As String, Param3 As String, Param4 As String, Param5 As String, _
                      Param6 As String, Param7 As String)
                      
    dtcAlmacen.BoundText = Param1
    dtcVendedor.BoundText = Param2
    dtpFechaPos.Value = CDate(Param3)
    dtpFechaPos2.Value = CDate(Param4)
    cmbTurnos.ListIndex = CInt(Param5) - 1
    cmbCara.ListIndex = CInt(Param6) - 1
    chkEstado.Value = IIf(Param7 = "APROBADO", 1, 0)
    
    
    CargaDataGrid
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    If pb_editar Then
        If MsgBox("Desea Cancelar los Cambios", vbYesNo, "Esta Modificando un registro") = vbNo Then
            Cancel = True
        Else
            pb_agregar = False
            pb_editar = False
            Call gdesactiva_barra
        End If
    Else
        pb_agregar = False
        pb_editar = False
        Call gdesactiva_barra
    End If
End Sub

'   Procedimiento GCargaDataCombo
'   Elaborado por : Edgar Cancho Ruiz
'   Fecha : 12/09/2002

Public Sub GCargaDataCombo(objDataCombo As DataCombo, rsSource As Recordset, istrCampo1 As String, istrCampo2 As String)
    Set objDataCombo.DataSource = rsSource
    objDataCombo.DataField = istrCampo2
    Set objDataCombo.RowSource = rsSource
    objDataCombo.ListField = istrCampo2
    objDataCombo.BoundColumn = istrCampo1
    objDataCombo.BoundText = rsSource.Fields(istrCampo2)
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Set objAlmacen = Nothing
    Set objVendedor = Nothing
    Set objCarasVendedor = Nothing
    Set objCorrelativo = Nothing
End Sub

Sub imprimir()

    MstrFechaIni = CStr(Format(dtpDesde.Value, "YYYYMMdd"))
    MstrFechaFin = CStr(Format(dtpHasta.Value, "YYYYMMdd"))
    
    Screen.MousePointer = 11

    crTurnos.ReportFileName = GstrReportesVta + "rpt_Turnos_Vendedor.rpt"
 
                
    crTurnos.WindowTitle = "Reporte de Ventas"
    crTurnos.Formulas(1) = "formusuario=stringvar strusuario; strusuario:='" & GCUSERID & "'"
    crTurnos.Formulas(2) = "formscreen=stringvar strscreen; strscreen:='05.055.00'"
    crTurnos.Formulas(3) = "formFechaIni= datevar FechaIni; FechaIni:=date(" & Format(dtpDesde.Value, "YYYY,MM,dd") & ")"
    crTurnos.Formulas(4) = "formFechaFin= datevar FechaFin; FechaFin:=date(" & Format(dtpHasta.Value, "YYYY,MM,dd") & ")"


    crTurnos.WindowState = crptMaximized
    crTurnos.WindowShowPrintSetupBtn = True
    
    crTurnos.StoredProcParam(0) = dtcAlmacen.BoundText
    crTurnos.StoredProcParam(1) = MstrFechaIni
    crTurnos.StoredProcParam(2) = MstrFechaFin
    
    crTurnos.Connect = "DSN=SIES"
    crTurnos.Action = 1
    
    crTurnos.Reset
    
Screen.MousePointer = 0

End Sub

Private Sub Limpiar()
'funcionabilidad    : pone en blanco todos los controles de un formulario

Dim curcontrol As Control
    With Me
    For Each curcontrol In .Controls
        If TypeOf curcontrol Is TextBox Then
                curcontrol.Text = ""
        End If
         If TypeOf curcontrol Is DataCombo Then
                curcontrol.BoundText = Empty
        End If
         If TypeOf curcontrol Is ComboBox Then
            If curcontrol.Style <> 2 Then
                curcontrol.Text = ""
            End If
        End If
        If TypeOf curcontrol Is CtrlNumber Then
              curcontrol.ValorPorDefecto
        End If
        If TypeOf curcontrol Is CheckBox Then
              curcontrol.Value = 0
        End If
        
        If TypeOf curcontrol Is DTPicker Then
              curcontrol.Value = Now
        End If
    
    Next
    End With
    

    'cmbTurnos.ListIndex = 0
    'cmbCara.ListIndex = 0
        
End Sub

Private Sub CargaTurnos()
    Dim I As Integer
    For I = 1 To GintCantidadTurnos
        cmbTurnos.AddItem "Turno " & I
    Next
End Sub

Private Sub CargaCaras()
    Dim I As Integer
    lstCaras.Clear
    cmbCara.Clear
    For I = 1 To GintCantidadCaras
        If I < 10 Then
            cmbCara.AddItem "Cara 0" & I
            lstCaras.AddItem "Cara 0" & I
        Else
            cmbCara.AddItem "Cara " & I
            lstCaras.AddItem "Cara " & I
        End If
    Next
End Sub

Private Sub ActualizaCaras()
    Dim I As Integer
    Dim MrsTemporal As ADODB.Recordset
    Set MrsTemporal = objCarasVendedor.ObtenerCarasVendedor(dtcAlmacen.BoundText, dtpFechaPos.Value, dtpFechaPos2.Value, _
                                                            dtcVendedor.BoundText, cmbTurnos.ListIndex + 1)
    CargaCaras
    While Not MrsTemporal.EOF
        lstCaras.Selected(CInt(MrsTemporal!SIDE) - 1) = True
        MrsTemporal.MoveNext
    Wend
    
    Set MrsTemporal = Nothing
End Sub

Private Sub FormatoGrilla()
    dbListar.Columns(0).Width = 800
    dbListar.Columns(0).Visible = False
    dbListar.Columns(1).Width = 2000
    dbListar.Columns(1).Visible = False
    dbListar.Columns(2).Width = 2650
    dbListar.Columns(3).Visible = False
    dbListar.Columns(3).Width = 1000
    dbListar.Columns(4).Width = 1000
    dbListar.Columns(4).Alignment = dbgCenter
    dbListar.Columns(5).Alignment = dbgCenter
    dbListar.Columns(5).Width = 800
    dbListar.Columns(6).Alignment = dbgRight
    dbListar.Columns(6).Width = 1500
End Sub

Private Sub CargaDataGrid()
    Set rsobtieneRegistros = objCarasVendedor.ListarCarasVendedorOnLine(GstrSiteProce, dtpFechaPos.Value, dtpFechaPos2.Value)
    Set dbListar.DataSource = rsobtieneRegistros
    lblRegistro.Caption = rsobtieneRegistros.RecordCount & " registros encontrados"
    FormatoGrilla
    PonerDatosGrig
End Sub

Private Sub PonerDatosGrig()
    On Error GoTo TrataError
    If Not pb_agregar Then
        dtcAlmacen.BoundText = dbListar.Columns(0).Text
        dtcVendedor.BoundText = dbListar.Columns(1).Text
        cmbTurnos.ListIndex = CInt(dbListar.Columns(4).Text) - 1
        cmbCara.ListIndex = CInt(dbListar.Columns(5).Text) - 1
        chkEstado.Value = IIf(Trim(dbListar.Columns(6).Text) = "APROBADO", 1, 0)
        ActualizaCaras
    End If
    Exit Sub
TrataError:
        dtcAlmacen.BoundText = Empty
        dtcVendedor.BoundText = Empty
        cmbTurnos.ListIndex = 0
        cmbCara.ListIndex = 0
        chkEstado.Value = 0
        ActualizaCaras
End Sub

Private Sub lstCaras_ItemCheck(Item As Integer)
On Error GoTo TrataError
If Not pb_agregar Then
    If lstCaras.Selected(Item) Then
        lstCaras.Selected(Item) = False
        Exit Sub
    Else
        lstCaras.Selected(Item) = True
        Exit Sub
    End If
End If
Exit Sub
TrataError:
    
End Sub

Private Sub lstCaras_KeyUp(KeyCode As Integer, Shift As Integer)
    If KeyCode = 32 And (Not pb_agregar) Then
        ActualizaCaras
    End If
End Sub
