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"
Object = "{F0D2F211-CCB0-11D0-A316-00AA00688B10}#1.0#0"; "MSDATLST.OCX"
Object = "{69F9D01E-F1DE-11D4-9536-002018603DA2}#7.0#0"; "MiControl.ocx"
Begin VB.Form FCobranzas 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Cobranza de Documentos (08.030.00)"
   ClientHeight    =   7455
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   11145
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   ScaleHeight     =   7455
   ScaleWidth      =   11145
   Begin VB.CommandButton cmdCancelar 
      Caption         =   "&Cancelar"
      Height          =   735
      Left            =   7920
      Picture         =   "0803000.frx":0000
      Style           =   1  'Graphical
      TabIndex        =   34
      Top             =   5520
      Visible         =   0   'False
      Width           =   1215
   End
   Begin VB.CommandButton cmdcobranzas 
      Caption         =   "Cancelar Pago"
      Height          =   855
      Left            =   9600
      TabIndex        =   33
      Top             =   5565
      Width           =   1215
   End
   Begin VB.CommandButton cmdfiltrar 
      Caption         =   "Filtrar"
      Height          =   855
      Left            =   9600
      TabIndex        =   32
      Top             =   3000
      Width           =   1215
   End
   Begin VB.CommandButton cmdcomentario 
      Caption         =   "Comentario"
      Height          =   735
      Left            =   7920
      Picture         =   "0803000.frx":030A
      Style           =   1  'Graphical
      TabIndex        =   31
      Top             =   4800
      Visible         =   0   'False
      Width           =   1215
   End
   Begin VB.Frame Frame1 
      Caption         =   "Bucar Pagos"
      Height          =   1815
      Left            =   9240
      TabIndex        =   19
      Top             =   90
      Width           =   1800
      Begin VB.CommandButton cmdBuscar 
         Height          =   375
         Left            =   1290
         MouseIcon       =   "0803000.frx":0614
         MousePointer    =   99  'Custom
         Picture         =   "0803000.frx":0766
         Style           =   1  'Graphical
         TabIndex        =   20
         ToolTipText     =   "Buscar Documento"
         Top             =   360
         Width           =   375
      End
      Begin VB.Label Label3 
         AutoSize        =   -1  'True
         Caption         =   "Nro de Pago"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   435
         Left            =   120
         TabIndex        =   23
         Top             =   390
         Width           =   720
         WordWrap        =   -1  'True
      End
      Begin VB.Label lblCorrel 
         Alignment       =   2  'Center
         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          =   375
         Left            =   120
         TabIndex        =   22
         Top             =   840
         Width           =   1545
      End
      Begin VB.Label lblEstado 
         Alignment       =   2  'Center
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   345
         Left            =   120
         TabIndex        =   21
         Top             =   1320
         Width           =   1545
      End
   End
   Begin VB.CommandButton cmdAnular 
      Caption         =   "&Anular"
      Height          =   855
      Left            =   9600
      Picture         =   "0803000.frx":0C98
      Style           =   1  'Graphical
      TabIndex        =   11
      Top             =   4710
      Width           =   1215
   End
   Begin VB.CommandButton cmdPagar 
      Caption         =   "Efectuar Pago"
      Height          =   855
      Left            =   9600
      Picture         =   "0803000.frx":0FA2
      Style           =   1  'Graphical
      TabIndex        =   10
      Top             =   3855
      Width           =   1215
   End
   Begin VB.CommandButton cmdNuevo 
      Caption         =   "&Nuevo"
      Height          =   735
      Left            =   7920
      Picture         =   "0803000.frx":12AC
      Style           =   1  'Graphical
      TabIndex        =   9
      Top             =   4080
      Visible         =   0   'False
      Width           =   1215
   End
   Begin VB.Frame fraHead 
      Caption         =   "Datos Generales"
      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          =   2985
      Left            =   60
      TabIndex        =   13
      Top             =   90
      Width           =   9105
      Begin VB.TextBox txtDeposito 
         Height          =   315
         Left            =   1530
         TabIndex        =   38
         Top             =   1770
         Width           =   1605
      End
      Begin VB.ComboBox cmbPago 
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   315
         ItemData        =   "0803000.frx":15B6
         Left            =   1530
         List            =   "0803000.frx":15C3
         Style           =   2  'Dropdown List
         TabIndex        =   35
         Top             =   1140
         Width           =   2745
      End
      Begin VB.CommandButton cmdBusDeposito 
         Height          =   375
         Left            =   3180
         MouseIcon       =   "0803000.frx":15F0
         MousePointer    =   99  'Custom
         Picture         =   "0803000.frx":1742
         Style           =   1  'Graphical
         TabIndex        =   2
         ToolTipText     =   "Buscar Tipo de Ingreso"
         Top             =   1740
         Width           =   375
      End
      Begin VB.CommandButton cmbBusRerefencia 
         Height          =   375
         Left            =   3180
         MouseIcon       =   "0803000.frx":1C74
         MousePointer    =   99  'Custom
         Picture         =   "0803000.frx":1DC6
         Style           =   1  'Graphical
         TabIndex        =   3
         ToolTipText     =   "Buscar Tipo de Ingreso"
         Top             =   2160
         Width           =   375
      End
      Begin MiControl.CtrlNumber ctnMontoDep 
         Height          =   315
         Left            =   7170
         TabIndex        =   5
         Top             =   2520
         Width           =   1605
         _ExtentX        =   2831
         _ExtentY        =   556
         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.CommandButton cmdBusCliente 
         Height          =   375
         Left            =   5190
         MouseIcon       =   "0803000.frx":22F8
         MousePointer    =   99  'Custom
         Picture         =   "0803000.frx":244A
         Style           =   1  'Graphical
         TabIndex        =   0
         ToolTipText     =   "Buscar Tipo de Ingreso"
         Top             =   360
         Width           =   375
      End
      Begin VB.CommandButton cmdBusMoneda 
         Height          =   375
         Left            =   4350
         MouseIcon       =   "0803000.frx":297C
         MousePointer    =   99  'Custom
         Picture         =   "0803000.frx":2ACE
         Style           =   1  'Graphical
         TabIndex        =   1
         ToolTipText     =   "Buscar Tipo de Moneda"
         Top             =   750
         Visible         =   0   'False
         Width           =   375
      End
      Begin VB.CommandButton cmdConfirmar 
         Caption         =   "Confirmar"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   12
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   540
         Left            =   7170
         Style           =   1  'Graphical
         TabIndex        =   6
         Top             =   1920
         Width           =   1605
      End
      Begin MSComCtl2.DTPicker dtpFecha 
         Height          =   315
         Left            =   7170
         TabIndex        =   4
         Top             =   1140
         Width           =   1605
         _ExtentX        =   2831
         _ExtentY        =   556
         _Version        =   393216
         Format          =   22872065
         CurrentDate     =   37693
      End
      Begin MSDataListLib.DataCombo dtcCliente 
         Height          =   315
         Left            =   1530
         TabIndex        =   36
         Top             =   360
         Width           =   3615
         _ExtentX        =   6376
         _ExtentY        =   556
         _Version        =   393216
         Style           =   2
         Text            =   ""
      End
      Begin MSDataListLib.DataCombo dtcMoneda 
         Height          =   315
         Left            =   1530
         TabIndex        =   37
         Top             =   750
         Width           =   2745
         _ExtentX        =   4842
         _ExtentY        =   556
         _Version        =   393216
         Style           =   2
         Text            =   ""
      End
      Begin MSComCtl2.DTPicker DTPFechaDepo 
         Height          =   315
         Left            =   1530
         TabIndex        =   39
         Top             =   2520
         Width           =   1605
         _ExtentX        =   2831
         _ExtentY        =   556
         _Version        =   393216
         Format          =   22872065
         CurrentDate     =   37693
      End
      Begin VB.Line Line1 
         BorderColor     =   &H8000000D&
         BorderWidth     =   2
         X1              =   240
         X2              =   8775
         Y1              =   1560
         Y2              =   1575
      End
      Begin VB.Label lblMoneda 
         AutoSize        =   -1  'True
         Caption         =   "Moneda"
         Height          =   195
         Left            =   240
         TabIndex        =   46
         Top             =   810
         Width           =   585
      End
      Begin VB.Label lblDescripcion 
         AutoSize        =   -1  'True
         Caption         =   "Cliente"
         Height          =   195
         Left            =   240
         TabIndex        =   45
         Top             =   420
         Width           =   480
      End
      Begin VB.Label lblTipo 
         AutoSize        =   -1  'True
         Caption         =   "Tipo"
         Height          =   195
         Left            =   240
         TabIndex        =   44
         Top             =   1200
         Width           =   315
      End
      Begin VB.Label Label5 
         AutoSize        =   -1  'True
         Caption         =   "Nro Depósito"
         Height          =   195
         Left            =   240
         TabIndex        =   43
         Top             =   1830
         Width           =   930
      End
      Begin VB.Label Label6 
         AutoSize        =   -1  'True
         Caption         =   "Nro Referencia"
         Height          =   195
         Left            =   240
         TabIndex        =   42
         Top             =   2205
         Width           =   1080
      End
      Begin VB.Label Label4 
         AutoSize        =   -1  'True
         Caption         =   "Fecha Depósito"
         Height          =   195
         Left            =   240
         TabIndex        =   41
         Top             =   2580
         Width           =   1125
      End
      Begin VB.Label lblReferencia 
         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          =   315
         Left            =   1530
         TabIndex        =   40
         Top             =   2145
         Width           =   1605
      End
      Begin VB.Label lblMonto 
         AutoSize        =   -1  'True
         Caption         =   "Monto"
         Height          =   195
         Left            =   5760
         TabIndex        =   30
         Top             =   2580
         Width           =   450
      End
      Begin VB.Label lblRuc 
         AutoSize        =   -1  'True
         Caption         =   "RUC"
         Height          =   195
         Left            =   3720
         TabIndex        =   27
         Top             =   2520
         Visible         =   0   'False
         Width           =   345
      End
      Begin VB.Label lblmonedacliente 
         AutoSize        =   -1  'True
         Caption         =   "MONCLIENTE"
         Height          =   195
         Left            =   3720
         TabIndex        =   24
         Top             =   2280
         Visible         =   0   'False
         Width           =   1050
      End
      Begin VB.Image Image1 
         Height          =   540
         Left            =   5760
         Picture         =   "0803000.frx":3000
         Stretch         =   -1  'True
         Top             =   1920
         Width           =   540
      End
      Begin VB.Label lblFecha 
         AutoSize        =   -1  'True
         Caption         =   "Fecha Proceso"
         Height          =   195
         Left            =   5760
         TabIndex        =   16
         Top             =   1200
         Width           =   1080
      End
      Begin VB.Shape Shape2 
         Height          =   465
         Left            =   5760
         Top             =   330
         Width           =   3015
      End
      Begin VB.Label Label1 
         Caption         =   "T CAMBIO :"
         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            =   6180
         TabIndex        =   15
         Top             =   420
         Width           =   1230
      End
      Begin VB.Label lblCambio 
         Caption         =   "0.00"
         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            =   7485
         TabIndex        =   14
         Top             =   420
         Width           =   960
      End
   End
   Begin MiControl.CtrlNumber ctnMonto 
      Height          =   375
      Left            =   7200
      TabIndex        =   8
      Top             =   6795
      Width           =   1335
      _ExtentX        =   2355
      _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 MSDataGridLib.DataGrid dbDetalle 
      Height          =   3195
      Left            =   60
      TabIndex        =   7
      Top             =   3210
      Width           =   9105
      _ExtentX        =   16060
      _ExtentY        =   5636
      _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
      Caption         =   "Haga Click en la cabecera de la columna que desee ordenar"
      ColumnCount     =   2
      BeginProperty Column00 
         DataField       =   ""
         Caption         =   ""
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   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 VB.Label Label8 
      Height          =   255
      Left            =   2400
      TabIndex        =   29
      Top             =   6960
      Width           =   1215
   End
   Begin VB.Label lblcorrdeposito 
      Height          =   255
      Left            =   9600
      TabIndex        =   28
      Top             =   6840
      Width           =   1215
   End
   Begin VB.Label lbloriusdNC 
      Caption         =   "lbloriusdNC"
      Height          =   495
      Left            =   3720
      TabIndex        =   26
      Top             =   6720
      Visible         =   0   'False
      Width           =   1335
   End
   Begin VB.Label lbloripenNC 
      Caption         =   "lbloripenNC"
      Height          =   375
      Left            =   2400
      TabIndex        =   25
      Top             =   6720
      Visible         =   0   'False
      Width           =   1335
   End
   Begin VB.Shape Shape1 
      Height          =   675
      Left            =   5670
      Top             =   6630
      Width           =   3495
   End
   Begin VB.Label lblTotGen 
      Alignment       =   1  'Right Justify
      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          =   375
      Left            =   120
      TabIndex        =   18
      Top             =   6930
      Width           =   1725
   End
   Begin VB.Label Label7 
      Alignment       =   1  'Right Justify
      AutoSize        =   -1  'True
      Caption         =   "TOTAL A PAGAR"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   195
      Left            =   120
      TabIndex        =   17
      Top             =   6600
      Width           =   1725
   End
   Begin VB.Image Image2 
      Height          =   480
      Left            =   8580
      Picture         =   "0803000.frx":330A
      Top             =   6690
      Width           =   480
   End
   Begin VB.Label Label2 
      AutoSize        =   -1  'True
      Caption         =   "Monto a Pagar"
      Height          =   195
      Left            =   5850
      TabIndex        =   12
      Top             =   6840
      Width           =   1050
   End
End
Attribute VB_Name = "FCobranzas"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' Programador: Edgar Cancho Ruiz
' Empresa Texaco
' Modulo de Cuenta Corriente : COBRANZA DE DOCUMENTOS

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
Public GrecibeColumnaOpcional4 As String
Public GrecibeColumnaOpcional5 As String
'*************************************
' Objetos para cargar las ayudas
Private objCliente As DB_MA_MANTENIMIENTOS.C_CLIENTE
Private objMoneda As DB_MA_MANTENIMIENTOS.C_MONEDA
Private objCobranza As DB_AR_CUENTASCOBRAR.C_CANCELACION
Private MobjVentasGeneral As DB_OP_FACTURACION.C_VENTASGENERAL
Private MobjSetup As UTIL_SETUP.C_SETUP


Dim objCorrelativo As DB_CORRELATIVO.C_Correlativos
Dim lngCorrelativo As Long 'correlativo por usuario, que se almacenara en cada insert en temporal

Dim RS_Documentos As ADODB.Recordset
Dim RS_Filtrado As ADODB.Recordset
Private MstrOrden As String

Dim blnModificando As Boolean
Dim blnConfirmar As Boolean
Dim blnModoConsulta As Boolean


Private Sub cmbBusRerefencia_Click()
    'Lineas que llaman al Formulario de Búsqueda
     
     Dim ArrayBusqueda(1 To 6, 1 To 3) As Variant
     ArrayBusqueda(1, 1) = "Numero"
     ArrayBusqueda(1, 2) = "Nta_Crédito "
     ArrayBusqueda(1, 3) = 1500
     ArrayBusqueda(2, 1) = "Saldo_PEN"
     ArrayBusqueda(2, 2) = "Saldo_PEN "
     ArrayBusqueda(2, 3) = 1500
     ArrayBusqueda(3, 1) = "Saldo_USD"
     ArrayBusqueda(3, 2) = "Saldo_USD "
     ArrayBusqueda(3, 3) = 1500
     ArrayBusqueda(4, 1) = "Fech_Emision"
     ArrayBusqueda(4, 2) = "Fech_Emision "
     ArrayBusqueda(4, 3) = 1500
     ArrayBusqueda(5, 1) = "ORIPEN"
     ArrayBusqueda(5, 2) = "ORIPEN"
     ArrayBusqueda(5, 3) = 0
     ArrayBusqueda(6, 1) = "ORIUSD"
     ArrayBusqueda(6, 2) = "ORIUSD"
     ArrayBusqueda(6, 3) = 0
               
              
     FBusquedaCCobrar.GObtenerRegistros objCobranza.ObtenerDocReferencias(dtcCliente.BoundText), ArrayBusqueda, 4, 2
     FBusquedaCCobrar.Show vbModal
     
     If GrecibeUbicacion <> 0 Then
         lblReferencia.Caption = GrecibeColumnaID
         If dtcmoneda.BoundText = GstrCodMonedaBase Then
            ctnMontoDep.Text = GFormatodeNumero(CDbl(GrecibeColumnaOpcional), GintDecResultado)
         Else
            ctnMontoDep.Text = GFormatodeNumero(CDbl(GrecibeColumnaOpcional2), GintDecResultado)
         End If
         
         lbloripenNC.Caption = GrecibeColumnaOpcional4
         lbloriusdNC.Caption = GrecibeColumnaOpcional5
         
         GrecibeUbicacion = 0
     End If
     
End Sub

Private Sub cmbPago_Click()
If cmbPago.ListIndex = 0 Then
    ctnMontoDep.Enabled = True
    txtDeposito.Enabled = True
    cmdBusDeposito.Enabled = True
    lblReferencia.Caption = Empty
    lbloripenNC.Caption = Empty
    lbloriusdNC.Caption = Empty
    cmbBusRerefencia.Enabled = False
    Label5.Caption = "Nro Depósito"
Else
   If cmbPago.ListIndex = 1 Then
      ctnMontoDep.ValorPorDefecto
      ctnMontoDep.Enabled = False
      txtDeposito.Text = Empty
      txtDeposito.Enabled = False
      cmbBusRerefencia.Enabled = True
      cmdBusDeposito.Enabled = False
      Label5.Caption = "Nro Depósito"
   Else  ' Es un Ajuste de Nota de Crédito
      ctnMontoDep.Enabled = True
      txtDeposito.Enabled = True
      cmdBusDeposito.Enabled = True
      lblReferencia.Caption = Empty
      lbloripenNC.Caption = Empty
      lbloriusdNC.Caption = Empty
      cmbBusRerefencia.Enabled = False
      Label5.Caption = "Referencia del Ajuste"
   End If
End If
End Sub
Private Sub cmdAnular_Click()
On Error GoTo TrataError
    If pbderecho_anular = False Then
       MsgBox "No tiene derecho de Anular", vbDefaultButton1 + vbExclamation, "Advertencia"
       Exit Sub
    End If

    If GVDATO(lblCorrel.Caption) = Empty Then
        MsgBox "Selecione un munero de pago que desee Anular", vbExclamation, "Anular"
        cmdBuscar.SetFocus
        Exit Sub
    End If

    If lblEstado.Caption = "ANULADO" Then
        MsgBox "El pago ya fué anulado ", vbExclamation, "Anular"
        Exit Sub
    End If

    If MsgBox("Desea Anular el Documento", vbQuestion + vbYesNo, "Anular") = vbYes Then
        objCobranza.ANULAR_COBRANZA CDbl(lblCorrel.Caption), dtcmoneda.BoundText, GstrSiteProce, dtcCliente.BoundText, CDbl(lblTotGen.Caption), GCUSERID
        lblEstado.Caption = "ANULADO"
        MsgBox "Anulación realizada con éxito", vbInformation, "Anular"
    End If

    Exit Sub
TrataError:
    MsgBox MensajedeError(Err.Number, Err.Description), vbDefaultButton1 + vbCritical, "Error"
End Sub

Private Sub cmdBuscar_Click()
    FBuscarPagos.Show vbModal
End Sub

Private Sub cmdBusDeposito_Click()

    'Lineas que llaman al Formulario de Búsqueda
    ' StrSql = " SELECT DEPOSITPASSWORD as Deposito,TOTALPEN as PAGO_ORIGINAL," & _
    '          " DOCBALPEN As SALDO, DATEDEPOSIT As Fech_Deposito " & _
    '          " From AR_CCDOC_PAYMENT WHERE  CUSTIDSS='" & strCUSTIDSS & "'" & _
    '          " AND DOCBALPEN <> 0 " & _
    '          " AND SITEID=(SELECT SOURCESITE FROM SETUP)  "
    
     Dim ArrayBusqueda(1 To 5, 1 To 3) As Variant
     Dim IntMonBase As Integer
     
     ArrayBusqueda(1, 1) = "Deposito"
     ArrayBusqueda(1, 2) = "Nro_Deposito "
     ArrayBusqueda(1, 3) = 1500
              
     If dtcmoneda.BoundText = GstrCodMonedaBase Then
        IntMonBase = 0
        ArrayBusqueda(2, 1) = "PAGO_ORIGINAL"
        ArrayBusqueda(2, 2) = "PAGO_ORIGINAL"
        ArrayBusqueda(2, 3) = 1500
        ArrayBusqueda(3, 1) = "SALDO"
        ArrayBusqueda(3, 2) = "SALDO"
        ArrayBusqueda(3, 3) = 1500
        ArrayBusqueda(4, 1) = "Fech_Deposito"
        ArrayBusqueda(4, 2) = "Fech_Deposito "
        ArrayBusqueda(4, 3) = 1500
     Else
        IntMonBase = 1
        ArrayBusqueda(2, 1) = "PAGO_ORIGINAL"
        ArrayBusqueda(2, 2) = "PAGO_ORIGINAL"
        ArrayBusqueda(2, 3) = 1500
        ArrayBusqueda(3, 1) = "SALDO"
        ArrayBusqueda(3, 2) = "SALDO"
        ArrayBusqueda(3, 3) = 1500
        ArrayBusqueda(4, 1) = "Fech_Deposito"
        ArrayBusqueda(4, 2) = "Fech_Deposito "
        ArrayBusqueda(4, 3) = 1500
     End If
     ArrayBusqueda(5, 1) = "BATNBRAR_CCDOCDET"
     ArrayBusqueda(5, 2) = "BATNBRAR_CCDOCDET"
     ArrayBusqueda(5, 3) = 0
           
     If cmbPago.ListIndex = 0 Then
        ''FBusquedaCCobrar.GObtenerRegistros objCobranza.ObtenerPagos(dtcCliente.BoundText, IntMonBase, 0), ArrayBusqueda, 5, 2
        FBusquedaCCobrar.GObtenerRegistros objCobranza.ObtenerPagos(dtcCliente.BoundText, IntMonBase, 0), ArrayBusqueda, 5, 2
     Else
        FBusquedaCCobrar.GObtenerRegistros objCobranza.ObtenerPagos(dtcCliente.BoundText, IntMonBase, 1), ArrayBusqueda, 5, 2
     End If
     
     FBusquedaCCobrar.Show vbModal
     
     If GrecibeUbicacion <> 0 Then
         txtDeposito.Text = GrecibeColumnaID
          If dtcmoneda.BoundText = GstrCodMonedaBase Then
             ctnMontoDep.Text = GFormatodeNumero(CDbl(GrecibeColumnaOpcional2), GintDecResultado)
          Else
             ctnMontoDep.Text = GFormatodeNumero(CDbl(GrecibeColumnaOpcional2), GintDecResultado)
          End If
          lblcorrdeposito.Caption = GrecibeColumnaOpcional4
          GrecibeUbicacion = 0
     End If
     
End Sub

'Private Sub cmdBusTipoPago_Click()
'    'Lineas que llaman al Formulario de Búsqueda
'
'     Dim ArrayBusqueda(1 To 2, 1 To 3) As Variant
'     ArrayBusqueda(1, 1) = "TYPEPAYMENTID"
'     ArrayBusqueda(1, 2) = "Código "
'     ArrayBusqueda(1, 3) = 1000
'     ArrayBusqueda(2, 1) = "Descr"
'     ArrayBusqueda(2, 2) = "Descripción "
'     ArrayBusqueda(2, 3) = 4000
'
'     FBusquedaCCobrar.GObtenerRegistros objCobranza.ListarCondicionesPago, ArrayBusqueda, 2, 2
'     FBusquedaCCobrar.Show vbModal
'
'     If GrecibeUbicacion <> 0 Then
'         dtcTipoPago.BoundText = GrecibeColumnaID
'     End If
'End Sub

Private Sub cmdcancelar_Click()
    cmdNuevo.Enabled = True
    cmdPagar.Enabled = False
    cmdfiltrar.Enabled = False
    cmdcobranzas.Enabled = False
    
    lngCorrelativo = 0
    dtcCliente.BoundText = Empty
    lblmonedacliente.Caption = Empty
    ctnMonto.ValorPorDefecto
    ctnMonto.Enabled = False
    dtpFecha.Value = GDatFechaProcesoVentas
    lblCambio.Caption = GFormatodeNumero("0", GintDecResultado)
    cmdCancelar.Enabled = False
    cmdAnular.Enabled = True
    fraHead.Enabled = False
    txtDeposito.Text = Empty
    lblReferencia.Caption = Empty
    ctnMontoDep.Text = lblCambio.Caption
    blnModoConsulta = True
    cmdBuscar.Enabled = True
    lblcorrdeposito.Caption = Empty
    lbloripenNC.Caption = Empty
    lbloriusdNC.Caption = Empty
    
End Sub

Private Sub cmdcobranzas_Click()
    
    Dim LobjProcesos As DB_UT_MANTENIMIENTOS.C_PROCESOS
    Dim LstrCadenaCancel As String
    Dim Ldblnotacredito As Double
    Dim ldblcorrelativoPago As Double
    
On Error GoTo errhandler:
    
    If MsgBox("Seguro que desea cancelar el saldo restante del Pago/Nota de Crédito", vbYesNo + vbQuestion, "Mensaje") = vbNo Then
       Exit Sub
    End If
    
    Screen.MousePointer = 11
    
    If Trim(lblReferencia.Caption) = Empty Then
       Ldblnotacredito = 0
    Else
       Ldblnotacredito = Val(lblReferencia.Caption)
    End If
    
    If Trim(lblcorrdeposito.Caption) = Empty Then
       ldblcorrelativoPago = 0
    Else
       ldblcorrelativoPago = Val(lblcorrdeposito.Caption)
    End If
    
    Set LobjProcesos = New DB_UT_MANTENIMIENTOS.C_PROCESOS
    
    LstrCadenaCancel = "AR_CANCELARPAGOS_Proc " & ldblcorrelativoPago & "," & Ldblnotacredito & ",'" & GstrSiteProce & "','" & _
                        dtcCliente.BoundText & "','" & txtDeposito.Text & "','" & Format(dtpFecha.Value, "yyyymmdd") & "','" & _
                        dtcmoneda.BoundText & "','" & GCUSERID & "'"

    LobjProcesos.Auxiliar1 LstrCadenaCancel
    
    ' Reiniciar Formulario
   
    cmdPagar.Enabled = False
    cmdfiltrar.Enabled = False
    cmdcobranzas.Enabled = False
    
    cmdNuevo.Enabled = True
    cmdAnular.Enabled = True
    cmdCancelar.Enabled = False
    blnConfirmar = False
    ctnMonto.Enabled = False
    lblEstado.Caption = "PROCESADO"
    blnModoConsulta = True
    cmdBuscar.Enabled = True
       
    Me.pb_agregar = False
    Me.pb_editar = False
    Call gactualiza_barra(Me)
    'Call gHabilitarReg(frm, frm.pb_editar)
    Call gactualizaopcion(Me.pbderecho_agregar, Me.pbderecho_editar, Me.pbderecho_borrar, Me.pbderecho_imprimir)
    'LimpiaFormulario
    Actualizar_Registro
    Screen.MousePointer = 0
    
    MsgBox "Pago Cancelado Correctamente", vbDefaultButton1 + vbInformation, "Mensaje"
    
    ' Fin de Reiniciar Formulario
    
Exit Sub
       
errhandler:
       
    MsgBox Err.Description, vbDefaultButton1 + vbExclamation, "Mensaje"
    
End Sub

Private Sub cmdConfirmar_Click()
If GVDATO(dtcCliente.BoundText) = Empty Then
    MsgBox "Seleccione un Cliente", vbExclamation, "Mensaje"
    dtcCliente.SetFocus
    Exit Sub
End If

If GVDATO(dtcmoneda.BoundText) = Empty Then
    MsgBox "Seleccione moneda", vbExclamation, "Mensaje"
    dtcmoneda.SetFocus
    Exit Sub
End If

' Hay que Obtener el Tipo de Cambio de esa Fecha
  
lblCambio.Caption = GFormatodeNumero(objCobranza.ObtieneTipoCambio(dtpFecha.Value, GstrCodMonedaBase), GintDecResultado)

' Fin de Obtener el Tipo de Cambio de esa Fecha

If CDbl(lblCambio.Caption) = 0 Then
    MsgBox "Ingrese Tipo de Cambio del " & Format(dtpFecha.Value, "DD/MM/YYYY"), vbExclamation, "Mensaje"
    Exit Sub
End If

'If dbDetalle.Bookmark = 0 Or IsNull(dbDetalle.Bookmark) Then
'    MsgBox "No existen documentos por cancelar para Cliente elegido", vbExclamation, "Mensaje"
'    Exit Sub
'End If

If cmbPago.ListIndex = 0 Then
    If GVDATO(txtDeposito.Text) = Empty Then
        MsgBox "Ingrese número de deposito", vbExclamation, "Mensaje"
        Exit Sub
    End If
    
    If CDbl(ctnMontoDep.Text) = 0 Or GVDATO(ctnMontoDep.Text) = Empty Then
        MsgBox "Ingrese monto de deposito", vbExclamation, "Mensaje"
        Exit Sub
    End If
End If

If cmbPago.ListIndex = 2 Then
    If GVDATO(txtDeposito.Text) = Empty Then
        MsgBox "Ingrese la referencia del Ajuste", vbExclamation, "Mensaje"
        txtDeposito.SetFocus
        Exit Sub
    End If
    
    If CDbl(ctnMontoDep.Text) = 0 Or GVDATO(ctnMontoDep.Text) = Empty Then
        MsgBox "Ingrese monto de deposito", vbExclamation, "Mensaje"
        ctnMontoDep.SetFocus
        Exit Sub
    End If
End If


Screen.MousePointer = 11
    lngCorrelativo = objCorrelativo.ObtenerCorrelativo(GCUSERID)
    
    objCobranza.CARGA_TEMPORAL lngCorrelativo, dtcCliente.BoundText
    
    ' CARGAR EL DATAGRID CON LOS DATOS DEL TEMPORAL
    
    Set RS_Filtrado = objCobranza.SeleccionaEnTemporal(lngCorrelativo)
    CargaDataGrid
    
    ctnMonto.Enabled = True
    fraHead.Enabled = False
    cmdPagar.Enabled = True
    cmdfiltrar.Enabled = True
    cmdcobranzas.Enabled = True
    
    blnConfirmar = True
    'dbDetalle.SetFocus
    

Screen.MousePointer = 0

End Sub

Private Sub cmdfiltrar_Click()

   frmfiltro.lbltotalfilt.Caption = lblTotGen.Caption
   frmfiltro.GlngCorrelativo = lngCorrelativo
   frmfiltro.Show vbModal
   
End Sub

Private Sub cmdNuevo_Click()

    fraHead.Enabled = True
    cmdNuevo.Enabled = False
    cmdCancelar.Enabled = True
    cmdAnular.Enabled = False
    blnModoConsulta = False
    cmdBuscar.Enabled = False
    
    lngCorrelativo = 0
    dtcCliente.BoundText = Empty
    lblmonedacliente.Caption = Empty
    
    dtpFecha.Value = GDatFechaProcesoVentas
    lblCambio.Caption = GFormatodeNumero(objCobranza.ObtieneTipoCambio(dtpFecha.Value, GstrCodMonedaBase), GintDecResultado)
    ctnMontoDep.Text = GFormatodeNumero("0", GintDecResultado)
    lblReferencia.Caption = Empty
    txtDeposito.Text = Empty
    cmbPago.ListIndex = 0
    dtpFecha.Value = GDatFechaProcesoVentas
    lblCorrel.Caption = Empty
    lblEstado.Caption = Empty
    lblcorrdeposito.Caption = Empty
    lblTotGen.Caption = GFormatodeNumero("0", GintDecResultado)
    
End Sub

Private Sub cmdPagar_Click()
 On Error GoTo TrataError
 Dim dblREF As Double
 Dim dblNumero As Double
 Dim StrDocumentoPago As String
 
 Screen.MousePointer = 11
 
 'Validaciones Previas a la Grabacion
  
 If CDbl(lblTotGen.Caption) = 0 Then
 
    If RS_Filtrado.EOF Then
         If MsgBox("Seguro que desea grabar el Pago sin aplicar documentos ", vbQuestion + vbYesNo, "Mensaje") = vbNo Then
            dbDetalle.SetFocus
            Screen.MousePointer = 0
            Exit Sub
         End If
    End If

    'MsgBox "Total a pagar no puede ser cero", vbExclamation, "Error"
    'dbDetalle.SetFocus
    'Screen.MousePointer = 0
    'Exit Sub
 End If
 
 If CDbl(lblTotGen.Caption) > CDbl(ctnMontoDep.Text) Then
    MsgBox "Total a pagar no puede ser mayor al monto de un deposito o de un anota de crédito", vbExclamation, "Error"
    dbDetalle.SetFocus
    Screen.MousePointer = 0
    Exit Sub
 End If
   
 'Fin de Validaciones Previas
 
 If GVDATO(lblReferencia.Caption) = Empty Then
    dblREF = 0
 Else
    dblREF = CDbl(lblReferencia.Caption)
 End If
     
    If cmbPago.ListIndex = 0 Then
       StrDocumentoPago = ""
    Else  ' Es Con una Nota de Crédito
       If cmbPago.ListIndex = 1 Then
          StrDocumentoPago = MobjVentasGeneral.obtenertiponc
       Else
          StrDocumentoPago = GStrTipoNotaCreditoAjuste
       End If
    End If
     
     
    lblCorrel.Caption = objCobranza.EFECTUAR_PAGO(lngCorrelativo, GstrSiteProce, StrDocumentoPago, dblREF, txtDeposito.Text, _
                               GstrTipoCambioVentas, dtpFecha.Value, DTPFechaDepo.Value, dtcmoneda.BoundText, GFormatodeNumero(CDbl(lblTotGen.Caption), _
                               GintDecResultado), GFormatodeNumero(CDbl(lblCambio.Caption), _
                               GintDecResultado), dtcCliente.BoundText, _
                               lblRuc.Caption, GCUSERID, _
                               Val(IIf(lblcorrdeposito = "", 0, lblcorrdeposito)), CDbl(IIf(lbloripenNC.Caption = "", 0, lbloripenNC.Caption)), CDbl(IIf(lbloriusdNC.Caption = "", 0, lbloriusdNC.Caption)), ctnMontoDep.Text)
    
    
    cmdPagar.Enabled = False
    cmdfiltrar.Enabled = False
    cmdcobranzas.Enabled = False
    
    cmdNuevo.Enabled = True
    cmdAnular.Enabled = True
    cmdCancelar.Enabled = False
    blnConfirmar = False
    ctnMonto.Enabled = False
    lblEstado.Caption = "PROCESADO"
    blnModoConsulta = True
    cmdBuscar.Enabled = True
       
    Me.pb_agregar = False
    Me.pb_editar = False
    Call gactualiza_barra(Me)
    'Call gHabilitarReg(frm, frm.pb_editar)
    Call gactualizaopcion(Me.pbderecho_agregar, Me.pbderecho_editar, Me.pbderecho_borrar, Me.pbderecho_imprimir)
    'LimpiaFormulario
    Actualizar_Registro
    Screen.MousePointer = 0
    
    MsgBox "Datos Grabados Correctamente", vbInformation, "Cobranzas"
     
 Exit Sub
TrataError:
    Screen.MousePointer = 0
    MsgBox MensajedeError(Err.Number, Err.Description), vbDefaultButton1 + vbCritical, "Error"
    
End Sub

Private Sub Command1_Click()
 frmfiltro.Show
End Sub

Private Sub ctnMonto_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
    Dim varBmk As Variant
    
    If Trim(ctnMonto.Text) = Empty Then
       ctnMonto.ValorPorDefecto
    End If
    
    If dtcmoneda.BoundText = GstrCodMonedaBase Then
        If CDbl(ctnMonto.Text) <= CDbl(dbDetalle.Columns(7).Text) Then
            varBmk = dbDetalle.Bookmark
            
            blnModificando = False
            objCobranza.ACTUALIZA_TEMPORAL lngCorrelativo, dbDetalle.Columns(0).Text, GFormatodeNumero(CDbl(dbDetalle.Columns(2).Text), GintDecResultado), GFormatodeNumero(CDbl(ctnMonto.Text), GintDecResultado)
            Set RS_Filtrado = objCobranza.SeleccionaEnTemporal(lngCorrelativo)
            CargaDataGrid
            lblTotGen.Caption = GFormatodeNumero(objCobranza.OntenerTotal(lngCorrelativo), GintDecResultado)
            
            dbDetalle.Bookmark = varBmk
            dbDetalle.SetFocus
        Else
            MsgBox "El monto a pagar de un documento no puede superar al saldo", vbExclamation, "Error"
            ctnMonto.SetFocus
        End If
   Else
        If CDbl(ctnMonto.Text) <= CDbl(dbDetalle.Columns(8).Text) Then
            varBmk = dbDetalle.Bookmark
            blnModificando = False
            objCobranza.ACTUALIZA_TEMPORAL lngCorrelativo, dbDetalle.Columns(0).Text, GFormatodeNumero(CDbl(dbDetalle.Columns(2).Text), GintDecResultado), GFormatodeNumero(CDbl(ctnMonto.Text), GintDecResultado)
            Set RS_Filtrado = objCobranza.SeleccionaEnTemporal(lngCorrelativo)
            CargaDataGrid
            lblTotGen.Caption = GFormatodeNumero(objCobranza.OntenerTotal(lngCorrelativo), GintDecResultado)
            dbDetalle.Bookmark = varBmk
            dbDetalle.SetFocus
        Else
            MsgBox "El monto a pagar de un documento no puede superar al saldo", vbExclamation, "Error"
            ctnMonto.SetFocus
        End If
   End If
End If
End Sub

Private Sub dbDetalle_HeadClick(ByVal ColIndex As Integer)
On Error GoTo TrataError
If Not blnModoConsulta Then
    Select Case ColIndex
        Case 1
            RS_Filtrado.Sort = "Doc" & " " & MstrOrden
        Case 2
            RS_Filtrado.Sort = "Numero" & " " & MstrOrden
        Case 3
            RS_Filtrado.Sort = "Fech_Emision" & " " & MstrOrden
        Case 4
            RS_Filtrado.Sort = "Fech_Venc" & " " & MstrOrden
        Case 5
            RS_Filtrado.Sort = "Monto_PEN" & " " & MstrOrden
        Case 6
            RS_Filtrado.Sort = "Monto_USD" & " " & MstrOrden
        Case 7
            RS_Filtrado.Sort = "Saldo_PEN" & " " & MstrOrden
        Case 8
            RS_Filtrado.Sort = "Saldo_USD" & " " & MstrOrden
        Case 9
            RS_Filtrado.Sort = "Monto_Pagar" & " " & MstrOrden
        Case 10
            RS_Filtrado.Sort = "custidss" & " " & MstrOrden
    End Select
Else
    Select Case ColIndex
        Case 0
            RS_Filtrado.Sort = "Doc" & " " & MstrOrden
        Case 1
            RS_Filtrado.Sort = "Numero" & " " & MstrOrden
        Case 2
            RS_Filtrado.Sort = "Monto_PEN" & " " & MstrOrden
        Case 3
            RS_Filtrado.Sort = "Monto_USD" & " " & MstrOrden
    End Select

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

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

    If KeyCode = vbKeySpace And blnConfirmar Then
        Dim varBmk As Variant
        Dim MontoPen As Double
        Dim TotMonto As Double
        
        TotMonto = dbDetalle
        varBmk = dbDetalle.Bookmark
        
        'Pablo N.
        If (CDbl(ctnMontoDep.Text) - CDbl(lblTotGen)) > CDbl(dbDetalle.Columns(7).Text) Then
            MontoPen = CDbl(dbDetalle.Columns(7).Text)
        Else
            MontoPen = CDbl(ctnMontoDep.Text) - CDbl(lblTotGen)
        End If
        'Pablo N. antes era solo esto:GFormatodeNumero(CDbl(dbDetalle.Columns(8).Text), lo cambié por GFormatodeNumero(CDbl(MontoPen)
        If dtcmoneda.BoundText = GstrCodMonedaBase Then
            objCobranza.ACTUALIZA_TEMPORAL lngCorrelativo, dbDetalle.Columns(0).Text, GFormatodeNumero(CDbl(dbDetalle.Columns(2).Text), GintDecResultado), GFormatodeNumero(CDbl(MontoPen), GintDecResultado)
        Else
            objCobranza.ACTUALIZA_TEMPORAL lngCorrelativo, dbDetalle.Columns(0).Text, GFormatodeNumero(CDbl(dbDetalle.Columns(2).Text), GintDecResultado), GFormatodeNumero(CDbl(MontoPen), GintDecResultado)
        End If
        
        Set RS_Filtrado = objCobranza.SeleccionaEnTemporal(lngCorrelativo)
        CargaDataGrid
        lblTotGen.Caption = GFormatodeNumero(objCobranza.OntenerTotal(lngCorrelativo), GintDecResultado)
        dbDetalle.Bookmark = varBmk
        dbDetalle.SetFocus
        
    End If
    
    If KeyCode = 13 And blnConfirmar Then
        blnModificando = True
        ctnMonto.Enabled = True
        ctnMonto.SetFocus
    End If
    
End Sub

Private Sub dbDetalle_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
 On Error Resume Next
ctnMonto.Text = dbDetalle.Columns(9).Text
End Sub

Private Sub dtcCliente_Change()
On Error Resume Next
    Dim RS_CLIENTE As ADODB.Recordset
    Set RS_CLIENTE = objCobranza.ListarDatosClientes(dtcCliente.BoundText)
    dtcmoneda.BoundText = RS_CLIENTE!CURYID
    lblmonedacliente.Caption = RS_CLIENTE!CURYID
    lblRuc.Caption = RS_CLIENTE!TAXREGNBR
    Set RS_Filtrado = RS_Documentos.Clone
    RS_Filtrado.Filter = "CUSTIDSS='" & dtcCliente.BoundText & "' AND DOCTYPEID<>'07'"
    CargaDataGrid
End Sub

Private Sub dtcCliente_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyF2 Then
    cmdBusCliente_Click
End If
End Sub

Private Sub dtcMoneda_Change()
    CargaDataGrid
End Sub

Private Sub dtcMoneda_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyF2 Then
    cmdBusMoneda_Click
End If
End Sub

Private Sub dtpFecha_Change()
lblCambio.Caption = GFormatodeNumero(objCobranza.ObtieneTipoCambio(dtpFecha.Value, GstrCodMonedaBase), GintDecResultado)
End Sub

Private Sub dtpFecha_LostFocus()
 ' Validar que sea Mayor o Igual a la Fecha Proceso de Ventas y Menor Igual a la del Parte diario
 
 Dim LdatFechaProcesoVentas As Date
 Dim LdatFechaProceso As Date
 
 LdatFechaProcesoVentas = MobjSetup.ObtenerSetupVentas!DATEPROCESALES
 LdatFechaProceso = MobjSetup.ObtenerSetupGeneral!DATEPROCE
 
 'If dtpFecha.Value >= LdatFechaProceso Then
 'Else
 '   MsgBox "Fecha de Pago debe ser Mayor o Igual a la Fecha de Proceso", vbDefaultButton1 + vbExclamation, "Advertencia"
 '   dtpFecha.Value = LdatFechaProcesoVentas
 '   Exit Sub
 'End If
  
 If dtpFecha.Value <= LdatFechaProcesoVentas Then
 Else
    MsgBox "Fecha de Pago debe ser Menor o Igual a la Fecha de Proceso de Ventas", vbDefaultButton1 + vbExclamation, "Advertencia"
    dtpFecha.Value = LdatFechaProcesoVentas
    Exit Sub
 End If
 
  
End Sub

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

Private Sub Form_Load()
  
    Call gseguridad(Me)
    
    If pbderecho_consultar Then
        
        Set objCliente = New DB_MA_MANTENIMIENTOS.C_CLIENTE
        Set objMoneda = New DB_MA_MANTENIMIENTOS.C_MONEDA
        Set objCobranza = New DB_AR_CUENTASCOBRAR.C_CANCELACION
        Set objCorrelativo = New DB_CORRELATIVO.C_Correlativos
        Set RS_Documentos = objCobranza.ObtenerDocPorCancelar
        Set MobjVentasGeneral = New DB_OP_FACTURACION.C_VENTASGENERAL
        
        Set MobjSetup = New UTIL_SETUP.C_SETUP
        
                
        Me.Left = (MDIFCcobrar.Width - Me.Width) / 2
        Me.Top = 100
        
        blnModoConsulta = True
        Call CargaDataCombo(dtcCliente, objCliente.ListarClientesAyudaNocontado, "CUSTIDSS", "CUSTNAME")
        Call CargaDataCombo(dtcmoneda, objMoneda.ListarMonedas, "CuryId", "Descr")
        'Call CargaDataCombo(dtcTipoPago, objCobranza.ListarCondicionesPago, "TYPEPAYMENTID", "descr")
        
        dtcmoneda.BoundText = GstrCodMonedaBase
        
        dtpFecha.Value = GDatFechaProcesoVentas
        DTPFechaDepo.Value = Now
        
        ctnMonto.Enteros = 7
        ctnMonto.Decimales = GintDecResultado
        ctnMonto.ValorPorDefecto
        ctnMonto.Enabled = False
        MstrOrden = "ASC"
        lblCambio.Caption = GFormatodeNumero(objCobranza.ObtieneTipoCambio(dtpFecha.Value, GstrCodMonedaBase), GintDecResultado)
        
        ctnMontoDep.Enteros = 7
        ctnMontoDep.Decimales = GintDecResultado
        ctnMontoDep.ValorPorDefecto
        
        cmbPago.ListIndex = 0
        
        blnModificando = False
        blnConfirmar = False
        
        cmdPagar.Enabled = False
        cmdfiltrar.Enabled = False
        cmdcobranzas.Enabled = False
        
        cmdCancelar.Enabled = False
        dtcmoneda.Enabled = False
        
        lblTotGen.Caption = GFormatodeNumero("0", GintDecResultado)
     Else
        MsgBox ("No tiene Derechos de Consultar en este formulario"), vbCritical + vbDefaultButton1, "Mensaje"
     End If
     
End Sub


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 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
      
    FBusquedaCCobrar.GObtenerRegistros objCliente.ListarClientesAyudaNocontado, ArrayBusqueda, 2, 2
    FBusquedaCCobrar.Show vbModal
        
    If GrecibeUbicacion <> 0 Then
        dtcCliente.BoundText = GrecibeColumnaID
        lblmonedacliente.Caption = objCliente.ListarPorClienteID(dtcCliente.BoundText)!CURYID
        GrecibeUbicacion = 0
    End If
        
End Sub

Private Sub cmdBusMoneda_Click()
    'Lineas que llaman al Formulario de Búsqueda
     
     Dim ArrayBusqueda(1 To 2, 1 To 3) As Variant
     ArrayBusqueda(1, 1) = "CuryId"
     ArrayBusqueda(1, 2) = "Código "
     ArrayBusqueda(1, 3) = 1000
     ArrayBusqueda(2, 1) = "Descr"
     ArrayBusqueda(2, 2) = "Descripción "
     ArrayBusqueda(2, 3) = 4000
       
     FBusquedaCCobrar.GObtenerRegistros objMoneda.ListarMonedas, ArrayBusqueda, 2, 2
     FBusquedaCCobrar.Show vbModal
     
     If GrecibeUbicacion <> 0 Then
         dtcmoneda.BoundText = GrecibeColumnaID
         GrecibeUbicacion = 0
     End If
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
     If Me.pb_editar Then
        If MsgBox("Desea Cancelar los Cambios", vbYesNo + vbQuestion, "Esta Modificando un registro") = vbNo Then
            Cancel = True
        Else
            Me.pb_agregar = False
            Me.pb_editar = False
            Call gdesactiva_barra
        End If
     Else
         Me.pb_agregar = False
         Me.pb_editar = False
         Call gdesactiva_barra
     End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
    Set objCliente = Nothing
    Set objMoneda = Nothing
    Set objCobranza = Nothing
    Set objCorrelativo = Nothing
    Set MobjSetup = Nothing
    Set MobjVentasGeneral = Nothing
End Sub

Private Sub CargaDataGrid()
On Error Resume Next
    Set dbDetalle.DataSource = RS_Filtrado
    If dtcmoneda.BoundText = GstrCodMonedaBase Then
        FormatoGrilla True
    Else
        FormatoGrilla False
    End If
    
    dbDetalle.Refresh
    
End Sub

Private Sub CargaDataGrid2()
    Set dbDetalle.DataSource = RS_Filtrado
    If dtcmoneda.BoundText = GstrCodMonedaBase Then
        FormatoGrilla2 True
    Else
        FormatoGrilla2 False
    End If
    
    dbDetalle.Refresh
End Sub

Private Sub FormatoGrilla(blnValor As Boolean)

    dbDetalle.Columns(0).Width = 200
    dbDetalle.Columns(0).Visible = False
    dbDetalle.Columns(1).Width = 600
    dbDetalle.Columns(2).Width = 1200
    dbDetalle.Columns(3).Width = 1200
    dbDetalle.Columns(4).Width = 1200
    dbDetalle.Columns(5).Width = 1200
    dbDetalle.Columns(5).Alignment = dbgRight
    dbDetalle.Columns(5).NumberFormat = GMascara(GintDecResultado)
    dbDetalle.Columns(5).Visible = blnValor
    dbDetalle.Columns(6).Width = 1200
    dbDetalle.Columns(6).Alignment = dbgRight
    dbDetalle.Columns(6).NumberFormat = GMascara(GintDecResultado)
    dbDetalle.Columns(6).Visible = Not blnValor
    dbDetalle.Columns(7).Width = 1200
    dbDetalle.Columns(7).Alignment = dbgRight
    dbDetalle.Columns(7).NumberFormat = GMascara(GintDecResultado)
    dbDetalle.Columns(7).Visible = blnValor
    dbDetalle.Columns(8).Width = 1200
    dbDetalle.Columns(8).Alignment = dbgRight
    dbDetalle.Columns(8).NumberFormat = GMascara(GintDecResultado)
    dbDetalle.Columns(8).Visible = Not blnValor
    dbDetalle.Columns(9).Width = 1200
    dbDetalle.Columns(9).Alignment = dbgRight
    dbDetalle.Columns(9).NumberFormat = GMascara(GintDecResultado)
    dbDetalle.Columns(10).Visible = False

End Sub

Private Sub FormatoGrilla2(blnValor As Boolean)

    dbDetalle.Columns(0).Width = 600
    dbDetalle.Columns(1).Width = 1200
    dbDetalle.Columns(2).Width = 1200
    dbDetalle.Columns(2).Alignment = dbgRight
    dbDetalle.Columns(2).NumberFormat = GMascara(GintDecResultado)
    dbDetalle.Columns(2).Visible = blnValor
    dbDetalle.Columns(3).Width = 1200
    dbDetalle.Columns(3).Alignment = dbgRight
    dbDetalle.Columns(3).NumberFormat = GMascara(GintDecResultado)
    dbDetalle.Columns(3).Visible = Not blnValor

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

Private Sub txtDeposito_KeyPress(KeyAscii As Integer)
KeyAscii = ValidaNumeros(KeyAscii)
If KeyAscii = 13 Then
    ctnMontoDep.SetFocus
End If
End Sub

Public Sub CargaDatos(StrAlmacen As String, DblCorrelativo As Double)
 On Error GoTo TrataError
    Dim rsTemporal As ADODB.Recordset
    Set rsTemporal = objCobranza.ObtenerCabDocCancelados(StrAlmacen, DblCorrelativo)
    
    dtcCliente.BoundText = rsTemporal!CUSTIDSS
    lblmonedacliente.Caption = objCliente.ListarPorClienteID(dtcCliente.BoundText)!CURYID
    
    dtpFecha.Value = rsTemporal!DATEPROCEPAIDMENT
    lblCorrel.Caption = rsTemporal!BATNBRAR_CCDOCDET
    
    If rsTemporal!DOCSTATUSID = "OK" Then
        lblEstado.Caption = "PROCESADO"
    Else
        lblEstado.Caption = "ANULADO"
    End If
    
    If rsTemporal!NBRDOCUMENTPAID = 0 Then
        cmbPago.ListIndex = 0
        lblReferencia.Caption = Empty
        txtDeposito.Text = rsTemporal!DEPOSITPASSWORD
    Else
        cmbPago.ListIndex = 1
        lblReferencia.Caption = rsTemporal!NBRDOCUMENTPAID
        txtDeposito.Text = Empty
    End If
    

    Set RS_Filtrado = objCobranza.ObtenerDocCancelados(StrAlmacen, DblCorrelativo)
    CargaDataGrid2
    
    lblTotGen.Caption = GFormatodeNumero(objCobranza.OntenerTotalPago(DblCorrelativo, StrAlmacen, dtcmoneda.BoundText), GintDecResultado)
    ctnMontoDep.Text = lblTotGen.Caption
    
    Exit Sub

TrataError:
    
    cmdcancelar_Click
    
End Sub


Public Sub primer_registro()
End Sub

Public Sub ultimo_registro()
End Sub

Public Sub registro_anterior()
End Sub
Public Sub registro_siguiente()
End Sub

Function valida_datos() As Boolean
  valida_datos = True
End Function

Public Sub grabar_registro()

On Error GoTo errhandler
    
    If valida_datos() = True Then
        ' llamada al proc de grabacion
        If pb_agregar Then
           If cmdPagar.Enabled = True Then
                Screen.MousePointer = 11
                If CDbl(lblTotGen.Caption) = 0 Then
                   MsgBox "Total a pagar no puede ser cero", vbExclamation, "Error"
                   dbDetalle.SetFocus
                   Screen.MousePointer = 0
                   Exit Sub
                End If
 
                If CDbl(lblTotGen.Caption) > CDbl(ctnMontoDep.Text) Then
                   MsgBox "Total a pagar no puede ser mayor al monto de un deposito o de un anota de crédito", vbExclamation, "Error"
                   dbDetalle.SetFocus
                   Screen.MousePointer = 0
                   Exit Sub
                End If
                cmdPagar_Click
                Screen.MousePointer = 0
           Else
                Exit Sub
           End If
        Else
           Exit Sub
        End If
        
        Me.pb_agregar = False
        Me.pb_editar = False
        Call gactualiza_barra(Me)
        'Call gHabilitarReg(frm, frm.pb_editar)
        Call gactualizaopcion(Me.pbderecho_agregar, Me.pbderecho_editar, Me.pbderecho_borrar, Me.pbderecho_imprimir)
        'LimpiaFormulario
        Actualizar_Registro
        
    End If
    Screen.MousePointer = 0
Exit Sub
errhandler:
    MsgBox MensajedeError(Err.Number, Err.Description), vbDefaultButton1 + vbCritical, "Error"
    
End Sub
Public Sub Actualizar_Registro()
    'llamar al procedimiento de carga
    Call obtener_datos
    Call asigna_campos
    'MsgBox ("Registros Actualizados")
End Sub
Public Sub agregar_registro()
    'Call gagregar_registro(Me, TxtRuc)
    
    cmdNuevo_Click
    
    Me.pb_agregar = True
    Me.pb_editar = True
    'gHabilitarReg Me, Me.pb_editar
    Call gactualiza_barra(Me)
    
    
End Sub
Public Sub modificar_registro()
    'Call gmodificar_registro(Me, txtCodigo)
End Sub
Public Sub descartar_registro()
    'Revertir cambios
    'adodc1.Recordset.CancelUpdate
    
    cmdcancelar_Click
    
    'Call gdescartar_registro(Me)
    
    Me.pb_agregar = False
    Me.pb_editar = False
    
    'Call gHabilitarReg(frm, frm.pb_editar)
    
    Call gactualiza_barra(Me)
    Call gactualizaopcion(Me.pbderecho_agregar, Me.pbderecho_editar, Me.pbderecho_borrar, Me.pbderecho_imprimir)
    MsgBox ("Cambios Descartados"), vbInformation + vbDefaultButton1, "Mensaje"
    'Call asigna_campos
End Sub
Sub obtener_datos()
End Sub

Sub salir_formulario()
    ' validar que no haya procesos pendientes
    ' si no hay problemas
    MDIFCcobrar.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

Sub borrar_registro()
End Sub
Sub imprimir()

End Sub

Public Sub ActualizaGrilla(lngCorr As Long)
     Dim LobjCobranza As DB_AR_CUENTASCOBRAR.C_CANCELACION
     Set LobjCobranza = New DB_AR_CUENTASCOBRAR.C_CANCELACION
      
     Set RS_Filtrado = LobjCobranza.SeleccionaEnTemporal(lngCorr)
     CargaDataGrid
     lblTotGen.Caption = GFormatodeNumero(LobjCobranza.OntenerTotal(lngCorr), GintDecResultado)
     
     frmfiltro.lbltotalfilt.Caption = lblTotGen.Caption
     
End Sub




