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 FDepositos 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Depósitos (05.120.00)"
   ClientHeight    =   5985
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   8835
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   ScaleHeight     =   5985
   ScaleWidth      =   8835
   Begin MSDataListLib.DataCombo dtcTipoNegocio 
      Height          =   315
      Left            =   4320
      TabIndex        =   21
      Top             =   1440
      Width           =   1695
      _ExtentX        =   2990
      _ExtentY        =   556
      _Version        =   393216
      Enabled         =   0   'False
      Style           =   2
      Text            =   ""
   End
   Begin VB.CommandButton cmdimprimirdep 
      Caption         =   "Imprimir Déposito"
      Enabled         =   0   'False
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   735
      Left            =   7320
      TabIndex        =   20
      Top             =   5160
      Width           =   1095
   End
   Begin VB.CommandButton cmdAgregar 
      Caption         =   "&Agregar"
      Enabled         =   0   'False
      Height          =   735
      Left            =   6360
      Picture         =   "0512000.frx":0000
      Style           =   1  'Graphical
      TabIndex        =   19
      Top             =   5160
      Width           =   1005
   End
   Begin VB.CommandButton cmdBuscar 
      Height          =   465
      Left            =   4320
      MouseIcon       =   "0512000.frx":030A
      MousePointer    =   99  'Custom
      Picture         =   "0512000.frx":045C
      Style           =   1  'Graphical
      TabIndex        =   2
      ToolTipText     =   "Buscar Registro de Depósitos"
      Top             =   135
      Width           =   645
   End
   Begin VB.CommandButton cmdBusAlmacen 
      Enabled         =   0   'False
      Height          =   375
      Left            =   4680
      MouseIcon       =   "0512000.frx":098E
      MousePointer    =   99  'Custom
      Picture         =   "0512000.frx":0AE0
      Style           =   1  'Graphical
      TabIndex        =   1
      ToolTipText     =   "Buscar Almacén"
      Top             =   900
      Width           =   375
   End
   Begin VB.CommandButton cmdConfirmar 
      Caption         =   "Confirmar"
      Enabled         =   0   'False
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   420
      Left            =   6240
      Picture         =   "0512000.frx":1012
      TabIndex        =   0
      Top             =   1440
      Width           =   1470
   End
   Begin Crystal.CrystalReport crDeposito 
      Left            =   6600
      Top             =   120
      _ExtentX        =   741
      _ExtentY        =   741
      _Version        =   348160
      PrintFileLinesPerPage=   60
   End
   Begin MSDataGridLib.DataGrid DBDetalle 
      Height          =   2985
      Left            =   120
      TabIndex        =   3
      Top             =   2100
      Width           =   8625
      _ExtentX        =   15214
      _ExtentY        =   5265
      _Version        =   393216
      BackColor       =   16777152
      ForeColor       =   0
      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         =   "Seleccione y presione Enter para editar un registro, Eliminar [F3] , Imprimir Registro [F12]"
      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 MSDataListLib.DataCombo dtcAlmacen 
      Height          =   315
      Left            =   1080
      TabIndex        =   4
      Top             =   915
      Width           =   3495
      _ExtentX        =   6165
      _ExtentY        =   556
      _Version        =   393216
      Enabled         =   0   'False
      Style           =   2
      Text            =   ""
   End
   Begin MSComCtl2.DTPicker dtpFechaProc 
      Height          =   315
      Left            =   6360
      TabIndex        =   5
      Top             =   915
      Width           =   1335
      _ExtentX        =   2355
      _ExtentY        =   556
      _Version        =   393216
      Enabled         =   0   'False
      CalendarBackColor=   16777215
      Format          =   67698689
      CurrentDate     =   37567
   End
   Begin VB.Label Label4 
      AutoSize        =   -1  'True
      Caption         =   "T. Negocio"
      Height          =   195
      Left            =   3360
      TabIndex        =   22
      Top             =   1440
      Width           =   795
   End
   Begin VB.Label lblcol 
      Height          =   285
      Left            =   5160
      TabIndex        =   18
      Top             =   1200
      Width           =   735
   End
   Begin VB.Shape Shape3 
      Height          =   615
      Left            =   120
      Top             =   5160
      Width           =   5880
   End
   Begin VB.Label lblusd 
      Alignment       =   1  'Right Justify
      BackColor       =   &H00FFFFFF&
      BorderStyle     =   1  'Fixed Single
      Caption         =   "0"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   315
      Left            =   4680
      TabIndex        =   17
      Top             =   5280
      Width           =   1140
   End
   Begin VB.Label lblpen 
      Alignment       =   1  'Right Justify
      BackColor       =   &H00FFFFFF&
      BorderStyle     =   1  'Fixed Single
      Caption         =   "0"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   310
      Left            =   1680
      TabIndex        =   16
      Top             =   5300
      Width           =   1095
   End
   Begin VB.Label Label3 
      Caption         =   "Total Dólares :"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   330
      Left            =   3000
      TabIndex        =   15
      Top             =   5295
      Width           =   1515
   End
   Begin VB.Label Label2 
      Caption         =   "Total Soles :"
      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            =   270
      TabIndex        =   14
      Top             =   5300
      Width           =   1350
   End
   Begin VB.Label Label1 
      Caption         =   "Tipo de Cambio"
      Height          =   285
      Left            =   240
      TabIndex        =   13
      Top             =   1440
      Width           =   1455
   End
   Begin VB.Label lblCambio 
      BorderStyle     =   1  'Fixed Single
      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            =   1680
      TabIndex        =   12
      Top             =   1440
      Width           =   1200
   End
   Begin VB.Label lblNroLista 
      AutoSize        =   -1  'True
      Caption         =   "Nro. Depósito :"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H8000000D&
      Height          =   300
      Left            =   480
      TabIndex        =   10
      Top             =   165
      Width           =   1815
   End
   Begin VB.Label lblEtiqueta 
      AutoSize        =   -1  'True
      Caption         =   "NUEVO REGISTRO DE DEPOSITO"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H8000000D&
      Height          =   240
      Left            =   840
      TabIndex        =   11
      Top             =   165
      Width           =   3630
   End
   Begin VB.Label lblNumero 
      Alignment       =   2  'Center
      BorderStyle     =   1  'Fixed Single
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   285
      Left            =   2640
      TabIndex        =   9
      Top             =   225
      Width           =   1575
   End
   Begin VB.Label lblAlmacen 
      AutoSize        =   -1  'True
      Caption         =   "Almacen"
      Height          =   195
      Left            =   240
      TabIndex        =   8
      Top             =   915
      Width           =   615
   End
   Begin VB.Label lblFechaInicio 
      Caption         =   "Fecha Proceso"
      Height          =   315
      Left            =   5160
      TabIndex        =   7
      Top             =   915
      Width           =   1320
   End
   Begin VB.Shape Shape1 
      Height          =   1335
      Left            =   120
      Top             =   675
      Width           =   8625
   End
   Begin VB.Label lblEstado 
      Appearance      =   0  'Flat
      AutoSize        =   -1  'True
      BackColor       =   &H80000004&
      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          =   120
      Left            =   5310
      TabIndex        =   6
      Top             =   345
      Width           =   75
   End
   Begin VB.Image Image1 
      Height          =   465
      Left            =   7920
      Picture         =   "0512000.frx":131C
      Stretch         =   -1  'True
      Top             =   1200
      Width           =   630
   End
End
Attribute VB_Name = "FDepositos"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' Se retiraron los Fuentes de la red el 24/04/2003
' Programador: Edgar Cancho Ruiz
' Empresa Texaco
' Modulo de Registro de Depositos

Option Explicit

'*************************************
'Variables para el Control de la Barra General
 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
'*******************************************************************************************************************
' Variables para las ayudas
Public GrecibeUbicacion As BookmarkEnum
Public GrecibeColumnaID As String
Public GrecibeColumnaOpcional As String
Public GrecibeColumnaOpcional2 As String
Public GrecibeColumnaOpcional3 As String
'*************************************
' Objetos para cargar las ayudas

Private objAlmacen As DB_INV_MANTENIMIENTOS.C_ALMACEN
Private ObjDeposito As DB_OP_MANTENIMIENTOS.C_DEPOSITOS
Private objTipoNegocio As DB_UT_MANTENIMIENTOS.C_PUNTODEVENTA

'*******************************************************************************

Dim objCorrelativo As DB_CORRELATIVO.C_Correlativos

Dim lngCorrelativo As Long 'correlativo por usuario, que se almacenara en cada insert en temporal
Dim lngNumeroDeposito As Long  'almacenara el correlativo del contómetro de precio obtenido de In_Setup
Dim lngSecuencia As Long ' guardara el número de Item del detalle


Dim blnModificando As Boolean ' flag para controlar la modificación de un registro
Dim blnEditando As Boolean ' flag para controlar si se esta editando un registro
Dim intCancelar As Integer
Dim blnDatosOK As Boolean

Dim intErr As Integer
Dim MstrFechaProc As String

Public Sub actualizar_registro()
End Sub

Private Sub cmdAgregar_Click()
    If pb_editar Then ' si se esta editando

                If Not cmdConfirmar.Enabled Then
                    FEditarDepositos.MlngCorrelativo = lngCorrelativo
                    FEditarDepositos.MblnAgregando = True
                    FEditarDepositos.MstrCodAlmacen = dtcAlmacen.BoundText
                    FEditarDepositos.MdblCambio = CDbl(lblCambio.Caption)
                    FEditarDepositos.MdatFecha = Format(dtpFechaProc.Value, "DD/MM/YYYY")
                    FEditarDepositos.Show vbModal
                    CargaGrid lngCorrelativo
                    ActualizaTotales
                    Exit Sub
                Else
                    MsgBox "Confirme antes de editar", vbExclamation, "Mensaje"
                    Exit Sub
                End If
    End If
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 CmdBuscar_Click()
    FBuscarDeposito.Show vbModal
End Sub


Private Sub cancelarIngreso()
        blnEditando = False
        
        Call Limpiar
        Call HabilitaCampos(False)
        Call HabilitaBotones(True)

End Sub


Private Sub cmdConfirmar_Click()
    Dim MyCon As New ADODB.Connection, CadSql As String, rsAuxiliar As New ADODB.Recordset
    Dim MnumeroDeposito As Long
    '----------------------
    Dim strSQL As String
    Dim RsTc As ADODB.Recordset
    
    
    MyCon.Open "filedsn=conexionsies"
    
    strSQL = " SELECT RATE FROM CURYRATE WHERE CURYDATE= '" & Format(dtpFechaProc.Value, "yyyymmdd") & "' AND CURYTYPEID=(SELECT CURYTYPEIDSALES FROM SETUP) AND FROMCURYID='" & GstrCodMonedaBase & "' AND CURYTYPEID=(SELECT CURYTYPEIDSALES FROM SETUP) "
    Set RsTc = New Recordset
    RsTc.CursorLocation = adUseClient
    RsTc.Open strSQL, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
    If Not RsTc.EOF Then
        lblCambio.Caption = RsTc!Rate
    Else
        lblCambio.Caption = ObjDeposito.ObtieneTipoCambio(dtpFechaProc.Value, GstrCodMonedaBase)
    End If
    '----------------------
    If CDbl(lblCambio.Caption) = 0 Then
        MsgBox "Ingrese Tipo de Cambio del " & Format(dtpFechaProc.Value, "DD/MM/YYYY"), vbExclamation, "Mensaje"
    Exit Sub
    End If
    
    If Trim(dtcTipoNegocio.Text) = "" Or Len(Trim(dtcTipoNegocio.Text)) < 1 Or Trim(dtcTipoNegocio.BoundText) = "" Or Len(Trim(dtcTipoNegocio.BoundText)) < 1 Then
        MsgBox "Especifique el tipo de negocio al que se va a destinar el deposito", vbExclamation + 0
        dtcTipoNegocio.SetFocus
        Exit Sub
    End If
    
    If ValidaDatosCab Then
        
        CadSql = "select BATNBRDEPOSITSITE from OP_DEPOSITSITE " & _
             " WHERE DATEPROCE='" & Format(dtpFechaProc.Value, "DD/MM/YYYY") & "' AND SITEID='" & Trim(dtcAlmacen.BoundText) & "' and BUSINESSTYPE='" & Trim(dtcTipoNegocio.BoundText) & "'"
        rsAuxiliar.Open CadSql, MyCon, adOpenStatic, adLockOptimistic
        If Not rsAuxiliar.EOF Then
            MnumeroDeposito = rsAuxiliar!BATNBRDEPOSITSITE
        Else
            MnumeroDeposito = 0
        End If
        If MyCon.State = 1 Then Set MyCon = Nothing
        If rsAuxiliar.State = 1 Then Set rsAuxiliar = Nothing
        'MnumeroDeposito = ObjDeposito.ExisteRegistro(dtcAlmacen.BoundText, dtpFechaProc.Value)
    
        If MnumeroDeposito = 0 Then
            CargaGrid lngCorrelativo
            DesabilitaCabecera
        Else
            MsgBox "Datos ya registrados en el Depósito Nro : " & MnumeroDeposito, vbExclamation, "Depósitos"
            Exit Sub
        End If
    End If
End Sub

Private Sub cmdImprimir_Click()
On Error GoTo TrataError

    If GVDATO(dtcAlmacen.BoundText) = Empty Then
        MsgBox "Seleccione algún registro que desee Imprimir", vbExclamation, "Imprimir"
        Exit Sub
    End If
    
    Screen.MousePointer = 11
    MstrFechaProc = CStr(Format(dtpFechaProc.Value, "YYYYMMdd"))
    crDeposito.ReportFileName = GstrReportesVta + "rpt_Depositos.rpt"
    crDeposito.WindowTitle = "Reporte de Control de Depositos"
    crDeposito.Formulas(1) = "formAlmacen= stringvar DescrAlmacen; DescrAlmacen:='" & dtcAlmacen.Text & "'"
    crDeposito.Formulas(2) = "formusuario=stringvar strusuario; strusuario:='" & GCUSERID & "'"
    crDeposito.Formulas(3) = "formscreen=stringvar strscreen; strscreen:='05.120.00'"
    crDeposito.Formulas(4) = "formFecha= datevar FechaProce; FechaProce:=date(" & Format(dtpFechaProc.Value, "YYYY,MM,dd") & ")"
    crDeposito.Formulas(5) = "formNDStock=" & GintDecStock
    crDeposito.Formulas(6) = "formNDCosto=" & GintDecCosto
    crDeposito.Formulas(7) = "formNDMonto=" & GintDecResultado
    crDeposito.Formulas(8) = "formNDPrecio=" & GintDecPrecio
    crDeposito.Formulas(9) = "formNumeroDep=numbervar numero;numero:=" & GFormatodeNumero(CDbl(lblNumero.Caption), 0)
    crDeposito.Formulas(10) = "formEstado='" & lblEstado.Caption & "'"
    
    crDeposito.StoredProcParam(0) = MstrFechaProc
    crDeposito.StoredProcParam(1) = dtcAlmacen.BoundText
    
    crDeposito.WindowState = crptMaximized
    crDeposito.WindowShowPrintSetupBtn = True
    crDeposito.Action = 1
    crDeposito.Reset
        
    Screen.MousePointer = 0
    Exit Sub

TrataError:
    Screen.MousePointer = 0
    MsgBox "Error Generando reporte", vbExclamation, "Error"
    
End Sub

Private Sub Nuevo_Registro()
    blnEditando = True
        
    Call HabilitaCampos(True)
    Call HabilitaBotones(False)
    Call Limpiar
    
    ' SE OBTIENE EL NUMERO DE CORRELATIVO INDENTIFICADOR POR USUARIO
    lngCorrelativo = objCorrelativo.ObtenerCorrelativo(GCUSERID)
   
    'dtcAlmacen.SetFocus
End Sub


Private Sub Salir()
    Unload Me
End Sub

Public Sub CargaDatos(strSITEID As String, strBATNBRDEPOSITSITE As String)
On Error GoTo TrataError
    Call Limpiar
    Dim rsTemporal As ADODB.Recordset
    Set rsTemporal = ObjDeposito.SeleccionaEnCabecera(strSITEID, strBATNBRDEPOSITSITE)
    
    ' CARGO LA CABECERA
    lblNumero.Caption = rsTemporal!BATNBRDEPOSITSITE

    
    dtcAlmacen.BoundText = rsTemporal!SITEID
    dtpFechaProc.Value = rsTemporal!DATEPROCE
    dtpFechaProc_Change
    
    lblpen.Caption = GFormatodeNumero(rsTemporal!TOTALPEN, GintDecResultado)
    lblusd.Caption = GFormatodeNumero(rsTemporal!TOTALUSD, GintDecResultado)

    If rsTemporal!Status Then
        lblEstado.Caption = "CERRADO"
        cmdimprimirdep.Enabled = True
    Else
        lblEstado.Caption = "NO CERRADO"
        cmdimprimirdep.Enabled = False
    End If
 
    dtcTipoNegocio.BoundText = IIf(IsNull(rsTemporal!BUSINESSTYPE) Or Trim(rsTemporal!BUSINESSTYPE) = "", 0, rsTemporal!BUSINESSTYPE)

    ' CARGO EL DETALLE
    Set DBDetalle.DataSource = ObjDeposito.SeleccionaEnDetalle(strSITEID, strBATNBRDEPOSITSITE)
    Call FormatoGrilla
    DBDetalle.Refresh
    
    Set rsTemporal = Nothing
    
    Exit Sub
        
TrataError:
    Call Limpiar
    MsgBox "Nro de Ingreso no Registrado en Almacen Seleccionado", vbExclamation, "Error en Consulta"
End Sub

Private Sub cmdimprimirdep_Click()

   FImpresion.GintTodos = 1
   FImpresion.Show vbModal
    
End Sub

Private Sub DBDETALLE_KeyDown(KeyCode As Integer, Shift As Integer)

    If pb_editar Then ' si se esta editando
        If KeyCode = 13 Then
            If DBDetalle.Bookmark <> 0 Or Not IsNull(DBDetalle.Bookmark) Then
                If Not cmdConfirmar.Enabled Then
                    FEditarDepositos.MlngCorrelativo = lngCorrelativo
                    FEditarDepositos.MdblCambio = CDbl(lblCambio.Caption)
                    FEditarDepositos.MblnAgregando = False
                    FEditarDepositos.MstrCodAlmacen = dtcAlmacen.BoundText
                    FEditarDepositos.MdatFecha = Format(dtpFechaProc.Value, "DD/MM/YYYY")
                    FEditarDepositos.MintSecuencia = CInt(DBDetalle.Columns(0).Text)
                    FEditarDepositos.MstrClave = DBDetalle.Columns(1).Text
                    FEditarDepositos.MdatFechaDeposito = CDate(DBDetalle.Columns(2).Text)
                    FEditarDepositos.MstrMoneda = DBDetalle.Columns(3).Text
                    FEditarDepositos.MdblMontopen = CDbl(DBDetalle.Columns(4).Text)
                    FEditarDepositos.MdblMontousd = CDbl(DBDetalle.Columns(5).Text)
                    'FEditarDepositos.MstrReferencia = DBDetalle.Columns(6).Text
                    FEditarDepositos.MstrCodCliente = DBDetalle.Columns(6).Text
                    FEditarDepositos.Show vbModal
                    ActualizaTotales
                    CargaGrid lngCorrelativo
                    Exit Sub
                Else
                    MsgBox "Confirme antes de editar", vbExclamation, "Mensaje"
                    Exit Sub
                End If
            End If
        End If
        If KeyCode = vbKeyF3 Then
            If DBDetalle.Bookmark <> 0 Or Not IsNull(DBDetalle.Bookmark) Then
                If Not cmdConfirmar.Enabled Then
                    ObjDeposito.EliminaEnTemporal lngCorrelativo, dtcAlmacen.BoundText, dtpFechaProc.Value, CInt(DBDetalle.Columns(0).Text)
                    CargaGrid lngCorrelativo
                     ActualizaTotales
                    Exit Sub
                Else
                    MsgBox "Confirme antes de editar o eliminar", vbExclamation, "Mensaje"
                    Exit Sub
                End If
            End If
        End If
        
    End If
    
    If KeyCode = vbKeyF12 Then
             If DBDetalle.Bookmark <> 0 Or Not IsNull(DBDetalle.Bookmark) Then
                FImpresion.GintTodos = 0
                FImpresion.GstrClave = DBDetalle.Columns(1).Text
                FImpresion.Show vbModal
             End If
    End If
   
    
End Sub
Private Sub ActualizaTotales()
    Dim rsTemporal As ADODB.Recordset
    Set rsTemporal = ObjDeposito.ObtieneTotales(lngCorrelativo)
    lblpen.Caption = GFormatodeNumero(IIf(IsNull(rsTemporal(0)), 0, rsTemporal(0)), GintDecResultado)
    lblusd.Caption = GFormatodeNumero(IIf(IsNull(rsTemporal(1)), 0, rsTemporal(1)), GintDecResultado)
End Sub

Private Sub DBDetalle_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
On Error Resume Next
Dim str As String
DBDetalle.ToolTipText = "CLIENTE: " & ObjDeposito.ObtieneDescrCliente(DBDetalle.Columns(7).Text)
End Sub

Private Sub dtcAlmacen_GotFocus()
dtcAlmacen.BackColor = GC_ColorEnfoque
End Sub

Private Sub dtcAlmacen_LostFocus()
dtcAlmacen.BackColor = GC_ColorDefecto
End Sub


Private Sub dtpFechaProc_Change()
lblCambio.Caption = GFormatodeNumero(ObjDeposito.ObtieneTipoCambio(dtpFechaProc.Value, GstrCodMonedaBase), GintDecResultado)
End Sub

Private Sub Form_Activate()

    Call gactualizaopcion(pbderecho_agregar, pbderecho_editar, pbderecho_borrar, pbderecho_imprimir)
    Call gactualiza_barra(Me)
    If pbderecho_consultar = False Then
       Unload Me
    End If
    
 '********************************************************************************
    
End Sub

Private Sub Form_Load()
Screen.MousePointer = 11
 '********************************************************************************
 'Código que se Tiene que Copiar para Invocar a la Rutina de Seguridad para poder
  Call gseguridad(Me)
  If pbderecho_consultar Then
         Call InstanciaObjetos
         Call CargaGrid(-1)
         ActualizaTotales

         dtpFechaProc.Value = GDatFechaProceso

         Call HabilitaCampos(False)
         Call HabilitaBotones(True)
         Call LlenaDataCombos
         intErr = 0
    
  Else
     MsgBox ("No tiene Derechos de Consultar en este formulario"), vbCritical + vbDefaultButton1, "Mensaje"
     Screen.MousePointer = 0
     Exit Sub
  End If
 '********************************************************************************
        Me.Top = 100
        Me.Left = (Screen.Width - Me.Width) / 2
        lblCambio.Caption = ObjDeposito.ObtieneTipoCambio(dtpFechaProc.Value, GstrCodMonedaBase)
    
Screen.MousePointer = 0
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    If blnEditando Then
        If MsgBox("Desea Salir y Cancelar el registro de Contómetro actual? ", vbQuestion + vbYesNo, "Salir") = vbNo Then
            Cancel = 1
        Else
            Cancel = 0
            blnEditando = False
            pb_agregar = False
            pb_editar = False
            Call gdesactiva_barra
        End If
    Else
        pb_editar = False
        Call gdesactiva_barra
    End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Call DestruyeObjetos
End Sub

' Procedimiento para cargar DataCombos
Public Sub CargaDataCombo(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
    
    If Not rsSource.EOF Then
        objDataCombo.BoundText = rsSource.Fields(istrCampo2)
    End If

End Sub

' Procedimiento de carga de los DataCombos del formulario
Private Sub LlenaDataCombos()
    Call CargaDataCombo(dtcAlmacen, objAlmacen.ListarAlmacenesPorStatus(1), "SiteId", "Name")
    Call CargaDataCombo(dtcTipoNegocio, objTipoNegocio.ListarTiposNegocio(1), "BUSINESSTYPE", "DESCRBUSINESS")
End Sub

Private Sub InstanciaObjetos()
    Set ObjDeposito = New DB_OP_MANTENIMIENTOS.C_DEPOSITOS
    Set objAlmacen = New DB_INV_MANTENIMIENTOS.C_ALMACEN
    Set objCorrelativo = New DB_CORRELATIVO.C_Correlativos
    Set objTipoNegocio = New DB_UT_MANTENIMIENTOS.C_PUNTODEVENTA
End Sub

Private Sub DestruyeObjetos()
    Set ObjDeposito = Nothing
    Set objAlmacen = Nothing
    Set objCorrelativo = Nothing
    Set ObjDeposito = Nothing
    Set objTipoNegocio = Nothing
End Sub

Private Sub HabilitaCampos(blnValor As Boolean)
    lblNroLista.Visible = Not blnValor
    lblNumero.Visible = Not blnValor
    cmdBuscar.Visible = Not blnValor
    lblEtiqueta.Visible = blnValor
    
End Sub

Private Sub HabilitaBotones(blnValor As Boolean)
'    If blnValor Then
'
'        cmdImprimir.Enabled = pbderecho_imprimir
'
'    Else
'
'        cmdImprimir.Enabled = blnValor
'
'    End If
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.Text = ""
        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 = GDatFechaProceso
        End If
    
    Next
    End With
    
    'dtpFechaProceso.Value = GDatFechaProceso
    

    lblNumero.Caption = Empty
    lblEstado.Caption = Empty

    Call CargaGrid(-1)
    Call LlenaDataCombos
    
End Sub

Private Sub CargaGrid(lngId As Long)
    
    Set DBDetalle.DataSource = ObjDeposito.SeleccionaEnTemporal(lngId)
    Call FormatoGrilla
    DBDetalle.Refresh
    
End Sub
Private Sub FormatoGrilla()
    DBDetalle.Columns(0).Width = 400
    DBDetalle.Columns(1).Width = 1000
    DBDetalle.Columns(2).Width = 1000
    DBDetalle.Columns(3).Width = 800
    DBDetalle.Columns(3).Alignment = dbgRight
    DBDetalle.Columns(4).Width = 1200
    DBDetalle.Columns(4).Alignment = dbgRight
    DBDetalle.Columns(4).NumberFormat = GMascara(GintDecResultado)
    DBDetalle.Columns(5).Width = 1200
    DBDetalle.Columns(5).Alignment = dbgRight
    DBDetalle.Columns(5).NumberFormat = GMascara(GintDecResultado)
    DBDetalle.Columns(6).Width = 1200


End Sub

Private Sub GrabaDeposito()
Dim MyCon As New ADODB.Connection, CadSql As New ADODB.Connection

On Error GoTo errhandler

'MyCon.Open "dnsfile=conexionsies"
'MyCon.Open "DSN=SIES"
MyCon.Open "filedsn=conexionsies"
        
    If ValidaDatos = True Then 'si los datos se ingresaron correctamente
        If MsgBox("Desea Grabar datos de Depósito? ", vbQuestion + vbYesNo, "Confirmar Grabación") = vbNo Then
            Call cancelarIngreso
            Exit Sub
        End If

        
        If blnEditando Then 'SI SE ESTA AGREGANDO
            lngNumeroDeposito = ObjDeposito.AgregarDeposito(dtcAlmacen.BoundText, dtpFechaProc.Value, GFormatodeNumero(CDbl(lblpen.Caption), GintDecResultado), GFormatodeNumero(CDbl(lblusd.Caption), GintDecResultado), GCUSERID, lngCorrelativo)
            lblNumero.Caption = lngNumeroDeposito ' se asigna el valor del numero de movimiento
            lblEstado.Caption = "NO CERRADO"
            cmdimprimirdep.Enabled = False
        Else
            ObjDeposito.ModificarDeposito CLng(lblNumero.Caption), dtcAlmacen.BoundText, GFormatodeNumero(CDbl(lblpen.Caption), GintDecResultado), GFormatodeNumero(CDbl(lblusd.Caption), GintDecResultado), lngCorrelativo
        End If
        
        'BATNBRDEPOSITSITE,SITEID
        
        CadSql = "UPDATE OP_DEPOSITSITE SET BUSINESSTYPE ='" & Trim(dtcTipoNegocio.BoundText) & "' " & _
                    "WHERE BATNBRDEPOSITSITE=" & CLng(lblNumero.Caption) & " AND SITEID ='" & Trim(dtcAlmacen.BoundText) & "'"
        
        MyCon.BeginTrans
        MyCon.Execute CadSql, , ADODB.adExecuteNoRecords
        MyCon.CommitTrans
        
        If MyCon.State = 1 Then Set MyCon = Nothing
        
        blnEditando = False
        If MsgBox("Registro de Depósito grabado Correctamente.Desea Imprimir? ", vbQuestion + vbYesNo, "Depósito Nro: " & lblNumero.Caption) = vbNo Then
           GoTo SALTO
        Else
             Call cmdImprimir_Click
        End If
        
SALTO:

        Call HabilitaCampos(False)
        Call HabilitaBotones(True)
        
    End If

Exit Sub

errhandler:
    MsgBox MensajedeError(Err.Number, Err.Description), vbDefaultButton1 + vbCritical, "Advertencia"
    If MyCon.State = 1 Then Set MyCon = Nothing
    intErr = 1
End Sub

Private Function ValidaDatos() As Boolean
ValidaDatos = True
blnDatosOK = True
    If Not (ValidaDatosCab) Then
        ValidaDatos = False
        blnDatosOK = False
        Exit Function
    End If
    If Not (ValidaDatosDet) Then
        ValidaDatos = False
        blnDatosOK = False
        Exit Function
    End If
End Function

Private Function ValidaDatosCab() As Boolean
ValidaDatosCab = True

If DBDetalle.Bookmark = 0 Or IsNull(DBDetalle.Bookmark) Then
    If GVDATO(dtcAlmacen.Text) = Empty Then
        MsgBox "Ingrese Almacen", vbExclamation, "Mensaje"
        dtcAlmacen.SetFocus
        GoTo Final
    End If
    If GVDATO(dtcTipoNegocio.Text) = Empty Then
        MsgBox "Ingrese Tipo de negocio", vbExclamation, "Mensaje"
        dtcAlmacen.SetFocus
        GoTo Final
    End If
End If
    Exit Function
    
Final:
    ValidaDatosCab = False
        
End Function

Private Function ValidaDatosDet() As Boolean
ValidaDatosDet = True

    If IsNull(DBDetalle.Bookmark) Then
        MsgBox "Debe existir al menos un registro en detalle de documento", vbExclamation, "Mensaje"
        ValidaDatosDet = False
    End If
    
End Function

Public Sub agregar_registro()
    
    Call Nuevo_Registro
    pb_agregar = True
    pb_editar = True
    Call gagregar_registro(Me, dtcAlmacen)
    dtcAlmacen.BoundText = GstrSiteProce
    lblpen.Caption = GFormatodeNumero("0", GintDecResultado)
    lblusd.Caption = GFormatodeNumero("0", GintDecResultado)
    cmdAgregar.Enabled = True
    cmdimprimirdep.Enabled = False
    
End Sub

Public Sub descartar_registro()

    cancelarIngreso
    Call gdescartar_registro(Me)
    cmdBuscar.Enabled = True
    cmdConfirmar.Enabled = False
    dtcAlmacen.Enabled = False
    dtcTipoNegocio.Enabled = False
    cmdBusAlmacen.Enabled = False
    dtpFechaProc.Enabled = False
    lblpen.Caption = GFormatodeNumero("0", GintDecResultado)
    lblusd.Caption = GFormatodeNumero("0", GintDecResultado)
    cmdimprimirdep.Enabled = False
    
End Sub

Public Sub modificar_registro()
    If lblNumero.Caption <> Empty Then
        If lblEstado.Caption = "CERRADO" Then
            MsgBox "No se puede Modificar una Registro de Depósito que esta Cerrado", vbExclamation, "Depósitos"
            Exit Sub
        End If
        
        'blnEditando = True

        Call HabilitaBotones(False)
        Call DesabilitaCabecera
            
        lngCorrelativo = objCorrelativo.ObtenerCorrelativo(GCUSERID)
        Call ObjDeposito.CopiarOriginalAlTemporal(CLng(lblNumero.Caption), dtcAlmacen.BoundText, lngCorrelativo)
        Call CargaGrid(lngCorrelativo)
    
        pb_agregar = True
        pb_editar = True
        Call gactualiza_barra(Me)
        
        cmdAgregar.Enabled = True
        cmdimprimirdep.Enabled = False
    Else
        MsgBox "Seleccione un Registro de Contómetro desee Modificar", vbExclamation, "Contómetros Manuales"
    End If
    
Exit Sub

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

Public Sub grabar_registro()
    Call GrabaDeposito
    If intErr = 0 Then
        If blnDatosOK Then
            pb_agregar = False
            pb_editar = False
            Call gactualizaopcion(pbderecho_agregar, pbderecho_editar, pbderecho_borrar, pbderecho_imprimir)
            Call gactualiza_barra(Me)
            cmdBuscar.Enabled = True
        End If
    Else
        intErr = 0
    End If
End Sub


Public Sub salir_formulario()
    Salir
End Sub

Private Sub DesabilitaCabecera()
    dtcAlmacen.Enabled = False
    cmdBusAlmacen.Enabled = False
    dtpFechaProc.Enabled = False
    cmdConfirmar.Enabled = False
    cmdBuscar.Enabled = False
    dtcTipoNegocio.Enabled = False
End Sub

Public Sub imprimir()
    cmdImprimir_Click
End Sub

Public Sub borrar_registro()
    Dim LDatosDeposito(1, 3) As Variant
        
    If Trim(dtcAlmacen.Text) = Empty Then
       MsgBox " Debe seleccionar el depósito a Eliminar ", vbDefaultButton1 + vbExclamation, "Mensaje"
       Exit Sub
    End If
        
    LDatosDeposito(1, 1) = dtcAlmacen.BoundText
    LDatosDeposito(1, 2) = lblNumero.Caption
    LDatosDeposito(1, 3) = Format(dtpFechaProc.Value, "yyyymmdd")
    
    ObjDeposito.Auxiliar2 (LDatosDeposito)
    
    MsgBox "Registro Fue Eliminado ", vbDefaultButton1 + vbInformation, "Mensaje"
    
    Limpiar
    
End Sub

