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 = "{69F9D01E-F1DE-11D4-9536-002018603DA2}#7.0#0"; "ControlNumber.ocx"
Begin VB.Form FEditarDepositos 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Form1"
   ClientHeight    =   4755
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   8220
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   4755
   ScaleWidth      =   8220
   StartUpPosition =   2  'CenterScreen
   Begin VB.TextBox txtDoc 
      Enabled         =   0   'False
      Height          =   285
      Left            =   5160
      TabIndex        =   20
      Top             =   4170
      Width           =   1215
   End
   Begin VB.CommandButton cmdGeneraDoc 
      Caption         =   "Obtiene Nro Documento"
      Height          =   1095
      Left            =   3960
      Picture         =   "FEditarDepositos.frx":0000
      Style           =   1  'Graphical
      TabIndex        =   19
      Top             =   3360
      Width           =   1095
   End
   Begin VB.CommandButton cmdBusCliente 
      Height          =   375
      Left            =   3960
      MouseIcon       =   "FEditarDepositos.frx":030A
      MousePointer    =   99  'Custom
      Picture         =   "FEditarDepositos.frx":045C
      Style           =   1  'Graphical
      TabIndex        =   18
      ToolTipText     =   "Buscar Tipo de Ingreso"
      Top             =   360
      Width           =   375
   End
   Begin VB.CommandButton cmdElimina 
      Caption         =   "Eliminar Referencia"
      Height          =   825
      Left            =   180
      Picture         =   "FEditarDepositos.frx":098E
      Style           =   1  'Graphical
      TabIndex        =   17
      ToolTipText     =   "Eliminar Referencia"
      Top             =   3240
      Width           =   1035
   End
   Begin VB.ListBox lstNumeros 
      Height          =   2205
      Left            =   1320
      Sorted          =   -1  'True
      TabIndex        =   16
      Top             =   2220
      Width           =   2385
   End
   Begin VB.CommandButton cmdAgregar 
      Caption         =   "Agregar Referencia"
      Height          =   825
      Left            =   180
      Picture         =   "FEditarDepositos.frx":0C98
      Style           =   1  'Graphical
      TabIndex        =   15
      ToolTipText     =   "Agregar Referencia"
      Top             =   2280
      Width           =   1035
   End
   Begin MSDataListLib.DataCombo dtcCliente 
      Height          =   315
      Left            =   975
      TabIndex        =   0
      Top             =   360
      Width           =   2985
      _ExtentX        =   5265
      _ExtentY        =   556
      _Version        =   393216
      Style           =   2
      Text            =   ""
   End
   Begin VB.CommandButton cmdDescartar 
      Caption         =   "&Descartar"
      Height          =   690
      Left            =   6960
      Picture         =   "FEditarDepositos.frx":0FA2
      Style           =   1  'Graphical
      TabIndex        =   8
      Top             =   2880
      Width           =   975
   End
   Begin MSComCtl2.DTPicker dtpFecha 
      Height          =   330
      Left            =   975
      TabIndex        =   6
      Top             =   840
      Width           =   1275
      _ExtentX        =   2249
      _ExtentY        =   582
      _Version        =   393216
      CalendarBackColor=   16777152
      Format          =   61341697
      CurrentDate     =   37637
   End
   Begin MiControl.CtrlNumber ctnMonto 
      Height          =   375
      Left            =   5175
      TabIndex        =   5
      Top             =   840
      Width           =   1500
      _ExtentX        =   2646
      _ExtentY        =   661
      BackColor       =   -2147483643
      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
   End
   Begin VB.TextBox txtClave 
      Enabled         =   0   'False
      Height          =   285
      Left            =   3960
      TabIndex        =   3
      Top             =   2760
      Width           =   1230
   End
   Begin VB.CommandButton cmdGenerar 
      Caption         =   "Generar Clave"
      Height          =   690
      Left            =   3960
      Picture         =   "FEditarDepositos.frx":12AC
      Style           =   1  'Graphical
      TabIndex        =   2
      ToolTipText     =   "Generar Clave"
      Top             =   1920
      Width           =   1155
   End
   Begin VB.TextBox txtNumero 
      Height          =   285
      Left            =   2640
      MaxLength       =   10
      TabIndex        =   10
      Top             =   960
      Visible         =   0   'False
      Width           =   1500
   End
   Begin VB.ComboBox cmbReferencia 
      Height          =   315
      Left            =   1320
      Sorted          =   -1  'True
      Style           =   2  'Dropdown List
      TabIndex        =   1
      Top             =   1800
      Width           =   2385
   End
   Begin VB.CommandButton cmdAceptar 
      Caption         =   "&Grabar"
      Height          =   690
      Left            =   6960
      Picture         =   "FEditarDepositos.frx":16EE
      Style           =   1  'Graphical
      TabIndex        =   7
      Top             =   2160
      Width           =   975
   End
   Begin MSDataListLib.DataCombo dtcMoneda 
      Height          =   315
      Left            =   5175
      TabIndex        =   4
      Top             =   360
      Width           =   2775
      _ExtentX        =   4895
      _ExtentY        =   556
      _Version        =   393216
      Style           =   2
      Text            =   ""
   End
   Begin VB.Label lblMensaje 
      Caption         =   "Solo en caso no encuentre un numero de referencia"
      Height          =   855
      Left            =   5160
      TabIndex        =   21
      Top             =   3360
      Width           =   1215
   End
   Begin VB.Shape Shape3 
      Height          =   1335
      Left            =   3840
      Top             =   3240
      Width           =   2655
   End
   Begin VB.Shape Shape2 
      Height          =   2925
      Left            =   120
      Top             =   1680
      Width           =   6675
   End
   Begin VB.Shape Shape1 
      Height          =   1350
      Left            =   90
      Top             =   135
      Width           =   7965
   End
   Begin VB.Label lblCliente 
      Caption         =   "Cliente"
      Height          =   195
      Left            =   270
      TabIndex        =   14
      Top             =   405
      Width           =   780
   End
   Begin VB.Label lblReferencia 
      Caption         =   "Referencias"
      Height          =   285
      Left            =   300
      TabIndex        =   13
      Top             =   1830
      Width           =   915
   End
   Begin VB.Label lblFecha 
      Caption         =   "Fecha"
      Height          =   285
      Left            =   240
      TabIndex        =   12
      Top             =   840
      Width           =   510
   End
   Begin VB.Label lblMonto 
      Caption         =   "Monto"
      Height          =   285
      Left            =   4440
      TabIndex        =   11
      Top             =   840
      Width           =   690
   End
   Begin VB.Image Image1 
      Height          =   480
      Left            =   7200
      Picture         =   "FEditarDepositos.frx":1C20
      Top             =   840
      Width           =   480
   End
   Begin VB.Label lblMoneda 
      AutoSize        =   -1  'True
      Caption         =   "Moneda"
      Height          =   195
      Left            =   4440
      TabIndex        =   9
      Top             =   360
      Width           =   585
   End
End
Attribute VB_Name = "FEditarDepositos"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' Programador: Edgar Cancho Ruiz
' Empresa Texaco
' EDICION DE REGISTRO DE DEPOSITOS

Public GrecibeUbicacion As BookmarkEnum
Public GrecibeColumnaID As String
Public GrecibeColumnaOpcional As String
Public GrecibeColumnaOpcional2 As String
Public GrecibeColumnaOpcional3 As String

Public MlngCorrelativo As Long
Public MblnAgregando As Boolean

Public MstrCodAlmacen As String
Public MdatFecha As Date

Public MstrMoneda As String
Public MstrCodCliente As String
Public MdblMontopen As Double
Public MdblMontousd As Double
Public MdatFechaDeposito As Date
Public MintSecuencia As Integer
Public MstrReferencia As String
Public MstrClave As String

Public MdblCambio As Double

Private objMoneda As DB_MA_MANTENIMIENTOS.C_MONEDA
Private ObjDepositos As DB_OP_MANTENIMIENTOS.C_DEPOSITOS
Private objCliente As DB_MA_MANTENIMIENTOS.C_CLIENTE

Private Sub cmbReferencia_Change()
txtNumero.Text = GVDATO(cmbReferencia.Text)
End Sub

Private Sub cmbReferencia_Click()
txtNumero.Text = GVDATO(cmbReferencia.Text)
End Sub

Private Sub cmdAceptar_Click()
On Error GoTo errhandler
    
Dim i As Integer
Dim intNroSecuencia As Integer
    
     If GVDATO(dtcCliente.BoundText) = Empty Then
        MsgBox "Ingrese Cliente", vbExclamation, "Mensaje"
        Exit Sub
    End If
    
    If GVDATO(txtClave.Text) = Empty Then
        MsgBox "Genere la clave ", vbExclamation, "Mensaje"
        Exit Sub
    End If
    
    If GVDATO(ctnMonto.Text) = Empty Or GVDATO(ctnMonto.Text) = 0 Then
        MsgBox "Ingrese Monto", vbExclamation, "Mensaje"
        Exit Sub
    End If
    


    If MblnAgregando Then
        If GVDATO(txtDoc.Text) = "" Then
            intNroSecuencia = ObjDepositos.AgregaAlTemporal(MlngCorrelativo, MstrCodAlmacen, MdatFecha, dtcCliente.BoundText, GFormatodeNumero(CDbl(txtNumero.Text), 0), _
                                    txtClave.Text, dtpFecha.Value, dtcMoneda.BoundText, MdblCambio, _
                                    IIf(dtcMoneda.BoundText = GstrCodMonedaBase, CDbl(ctnMonto.Text), GFormatodeNumero(CDbl(ctnMonto.Text) * MdblCambio, GintDecResultado)), _
                                    IIf(dtcMoneda.BoundText <> GstrCodMonedaBase, CDbl(ctnMonto.Text), GFormatodeNumero(CDbl(ctnMonto.Text) / MdblCambio, GintDecResultado)), _
                                    "0", GCUSERID)
            
            'GRABANDO LOS NUMEROS DE REFERENCIAS
        
        
            For i = 0 To lstNumeros.ListCount - 1
                ObjDepositos.AgregaReferenciasAlTemporal MlngCorrelativo, MstrCodAlmacen, MdatFecha, intNroSecuencia, "01", lstNumeros.List(i)
            Next
        Else
        
            intNroSecuencia = ObjDepositos.AgregaAlTemporal(MlngCorrelativo, MstrCodAlmacen, MdatFecha, dtcCliente.BoundText, GFormatodeNumero(CDbl(txtDoc.Text), 0), _
                                    txtClave.Text, dtpFecha.Value, dtcMoneda.BoundText, MdblCambio, _
                                    IIf(dtcMoneda.BoundText = GstrCodMonedaBase, CDbl(ctnMonto.Text), GFormatodeNumero(CDbl(ctnMonto.Text) * MdblCambio, GintDecResultado)), _
                                    IIf(dtcMoneda.BoundText <> GstrCodMonedaBase, CDbl(ctnMonto.Text), GFormatodeNumero(CDbl(ctnMonto.Text) / MdblCambio, GintDecResultado)), _
                                    "0", GCUSERID)
        
            ObjDepositos.AgregaReferenciasAlTemporal MlngCorrelativo, MstrCodAlmacen, MdatFecha, intNroSecuencia, "01", txtDoc.Text
            
            Dim LUt_mant As DB_UT_MANTENIMIENTOS.C_PROCESOS
            Set LUt_mant = New DB_UT_MANTENIMIENTOS.C_PROCESOS
            LUt_mant.Auxiliar1 "Update op_setup set USER1=CAST(USER1 AS NUMERIC(10)) + 1"
            Set LUt_mant = Nothing
            
        End If
    Else

        ObjDepositos.ActualizaTemporal MlngCorrelativo, MstrCodAlmacen, MdatFecha, MintSecuencia, dtpFecha.Value, dtcMoneda.BoundText, _
                                    IIf(dtcMoneda.BoundText = GstrCodMonedaBase, CDbl(ctnMonto.Text), GFormatodeNumero(CDbl(ctnMonto.Text) * MdblCambio, GintDecResultado)), _
                                    IIf(dtcMoneda.BoundText <> GstrCodMonedaBase, CDbl(ctnMonto.Text), GFormatodeNumero(CDbl(ctnMonto.Text) / MdblCambio, GintDecResultado))
                                
    
    End If
    

    
    Unload Me

    Exit Sub

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

End Sub

Private Sub cmdAgregar_Click()
If cmbReferencia.ListIndex <> -1 Then
    lstNumeros.AddItem txtNumero.Text
    cmbReferencia.RemoveItem (cmbReferencia.ListIndex)
End If
End Sub

Private Sub cmdDescartar_Click()
Unload Me
End Sub

Private Sub cmdElimina_Click()
If lstNumeros.ListIndex <> -1 Then
    cmbReferencia.AddItem lstNumeros.List(lstNumeros.ListIndex)
    lstNumeros.RemoveItem (lstNumeros.ListIndex)
End If
End Sub

Private Sub cmdGeneraDoc_Click()
If GVDATO(dtcCliente.BoundText) <> "" Then
    If cmbReferencia.ListCount = 0 Then
        txtDoc.Text = ObjDepositos.Auxiliar1
    Else
        
        MsgBox "Ud. cuenta con números de referencias disponibles para generar claves", vbExclamation, "Depósitos"
        cmbReferencia.SetFocus
    End If
Else
        MsgBox "Debe seleccionar algún cliente", vbExclamation, "Depósitos"
        dtcCliente.SetFocus
End If
End Sub

Private Sub cmdGenerar_Click()
    If lstNumeros.ListCount = 0 And GVDATO(txtDoc.Text) = "" Then
        MsgBox "Selecione un número de referencia o obtenga uno", vbExclamation, "Mensaje"
        Exit Sub
    End If
    
    If GVDATO(txtDoc.Text) = "" Then
        txtClave.Text = GGeneraClaveDeposito(lstNumeros.List(0))
    Else
        txtClave.Text = GGeneraClaveDeposito(GVDATO(txtDoc.Text))
    End If
End Sub

Private Sub ctnMonto_GotFocus()
ctnMonto.BackColor = GC_ColorEnfoque
End Sub

Private Sub ctnMonto_LostFocus()
ctnMonto.BackColor = GC_ColorDefecto
End Sub

Private Sub dtcCliente_Change()
If MblnAgregando Then
    lstNumeros.Clear
    txtClave.Text = ""
    txtDoc.Text = ""
    CargaNumerosPhantom
Else
    CargaNumerosPhantom
End If
End Sub

Private Sub dtcCliente_GotFocus()
dtcCliente.BackColor = GC_ColorEnfoque
End Sub

Private Sub dtcCliente_LostFocus()
dtcCliente.BackColor = GC_ColorDefecto
End Sub

Private Sub dtcMoneda_GotFocus()
dtcMoneda.BackColor = GC_ColorEnfoque
End Sub

Private Sub dtcMoneda_LostFocus()
dtcMoneda.BackColor = GC_ColorDefecto
End Sub

Private Sub Form_Load()
    
    Controles
    
    Set objMoneda = New DB_MA_MANTENIMIENTOS.C_MONEDA
    Set ObjDepositos = New DB_OP_MANTENIMIENTOS.C_DEPOSITOS
    Set objCliente = New DB_MA_MANTENIMIENTOS.C_CLIENTE
    
    Call CargaDataCombo(dtcMoneda, objMoneda.ListarMonedas, "CuryId", "Descr")
    'Call CargaDataCombo(dtcTipoDoc, ObjDepositos.ListarTipos_Doc, "DOCSUMMARYTYPEID", "DESCRDOCSUMMARYTYPE")
    Call CargaDataCombo(dtcCliente, objCliente.ListarClientesAyudaTPC, "CUSTIDSS", "CUSTNAME")
    
    CargaNumerosPhantom
    
    If MblnAgregando Then
        dtcMoneda.BoundText = GstrCodMonedaBase
        dtpFecha.Value = GDatFechaProceso
        cmbReferencia.Visible = True
        txtNumero.Visible = False
        FEditarDepositos.Caption = "Agregando Registro"
    Else
        cmbReferencia.Enabled = False
        cmdGenerar.Enabled = False
        cmdAgregar.Enabled = False
        cmdElimina.Enabled = False
        txtClave.Enabled = False
        txtNumero.Enabled = False
        lstNumeros.Enabled = False
        cmdGeneraDoc.Enabled = False
        dtcMoneda.BoundText = MstrMoneda
        txtNumero.Text = MstrReferencia
        txtClave.Text = MstrClave
        
        cmbReferencia.Visible = False
        txtNumero.Visible = True
        
        FEditarDepositos.Caption = "Modificando Registro"
        If MstrMoneda = GstrCodMonedaBase Then
            ctnMonto.Text = GFormatodeNumero(MdblMontopen, GintDecResultado)
        Else
            ctnMonto.Text = GFormatodeNumero(MdblMontousd, GintDecResultado)
        End If
        
        dtcCliente.BoundText = MstrCodCliente
        dtcCliente.Enabled = False
        dtpFecha.Value = MdatFechaDeposito
        
        CargaNumerosPhantomDeItem
        
    End If
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

Private Function MValidaNumeros(KeyAscii As Integer) As Integer
    If (KeyAscii >= 48 And KeyAscii <= 57) Or KeyAscii = 13 Or KeyAscii = 8 Then
        MValidaNumeros = KeyAscii
    Else
        MValidaNumeros = 0
    End If
End Function

Private Sub Controles()

    ctnMonto.Enteros = 7
    ctnMonto.Decimales = GintDecResultado
    ctnMonto.ValorPorDefecto
    ctnMonto.PermitirNegativos = True
    ctnMonto.Enabled = True
  
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Set objMoneda = Nothing
    Set ObjDepositos = Nothing
    Set objCliente = Nothing
End Sub

Private Sub CargaNumerosPhantom()
Dim rsTemporal As ADODB.Recordset
Set rsTemporal = ObjDepositos.ListarNumerosPhantom(dtcCliente.BoundText, 0)
cmbReferencia.Clear
While Not rsTemporal.EOF
    cmbReferencia.AddItem rsTemporal(1)
    rsTemporal.MoveNext
Wend
End Sub

Private Sub CargaNumerosPhantomDeItem()
Dim rsTemporal As ADODB.Recordset
Set rsTemporal = ObjDepositos.SeleccionaEnTemporalDeReferencias(MlngCorrelativo, MstrCodAlmacen, MintSecuencia)
lstNumeros.Clear
While Not rsTemporal.EOF
    lstNumeros.AddItem rsTemporal!NBRDOCSUMMARY
    rsTemporal.MoveNext
Wend

End Sub

Private Sub cmdBusCliente_Click()
    'Lineas que llaman al Formulario de Búsqueda
    
    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.GObtenerRegistros objCliente.ListarClientesAyudaTPC, ArrayBusqueda, 2, 2
    FBusquedasVta2.Show vbModal
    
    If GrecibeUbicacion <> 0 Then
        dtcCliente.BoundText = GrecibeColumnaID
    End If
End Sub

