VERSION 5.00
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 FClienteCredito 
   BorderStyle     =   1  'Fixed Single
   ClientHeight    =   4050
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   9660
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   Picture         =   "FClienteCredito.frx":0000
   ScaleHeight     =   4050
   ScaleWidth      =   9660
   StartUpPosition =   2  'CenterScreen
   Begin MiControl.CtrlNumber ctnMontoTotal 
      Height          =   375
      Left            =   3120
      TabIndex        =   0
      Top             =   120
      Width           =   2055
      _ExtentX        =   3625
      _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.CommandButton cmdcancelar 
      Caption         =   "Cancelar"
      Height          =   735
      Left            =   8280
      Picture         =   "FClienteCredito.frx":030A
      Style           =   1  'Graphical
      TabIndex        =   6
      Top             =   3240
      Width           =   1215
   End
   Begin VB.CommandButton cmdaceptar 
      Caption         =   "&Grabar"
      Height          =   735
      Left            =   6960
      Picture         =   "FClienteCredito.frx":0614
      Style           =   1  'Graphical
      TabIndex        =   5
      Top             =   3240
      Width           =   1335
   End
   Begin MiControl.CtrlNumber ctnPorcentaje 
      Height          =   255
      Left            =   2760
      TabIndex        =   3
      Top             =   1680
      Width           =   1095
      _ExtentX        =   1931
      _ExtentY        =   450
      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 cmdBusAlmacen 
      Height          =   375
      Left            =   5160
      MouseIcon       =   "FClienteCredito.frx":091E
      MousePointer    =   99  'Custom
      Picture         =   "FClienteCredito.frx":0A70
      Style           =   1  'Graphical
      TabIndex        =   2
      ToolTipText     =   "Buscar Almacén"
      Top             =   1080
      Width           =   375
   End
   Begin MiControl.CtrlNumber ctnPorcExceso 
      Height          =   375
      Left            =   2760
      TabIndex        =   4
      Top             =   2280
      Width           =   1095
      _ExtentX        =   1931
      _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 MSDataListLib.DataCombo dtcAlmacen 
      Height          =   315
      Left            =   1200
      TabIndex        =   1
      Top             =   1080
      Width           =   3855
      _ExtentX        =   6800
      _ExtentY        =   556
      _Version        =   393216
      Style           =   2
      Text            =   ""
   End
   Begin VB.Label lblPorcentaje 
      Alignment       =   1  'Right Justify
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   600
      TabIndex        =   19
      Top             =   3360
      Width           =   1335
   End
   Begin VB.Label lblMensaje 
      Caption         =   "% de Límite de Crédito Disponible"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   1920
      TabIndex        =   18
      Top             =   3360
      Width           =   4335
   End
   Begin VB.Image Image3 
      Height          =   480
      Left            =   8880
      Picture         =   "FClienteCredito.frx":0FA2
      Top             =   2160
      Width           =   480
   End
   Begin VB.Label lblMontoExedente 
      Alignment       =   1  'Right Justify
      BorderStyle     =   1  'Fixed Single
      Height          =   255
      Left            =   6840
      TabIndex        =   17
      Top             =   2280
      Width           =   1935
   End
   Begin VB.Label Label7 
      Caption         =   "Porcentaje de Exedente de Límite de Credito de Almacen "
      Height          =   375
      Left            =   360
      TabIndex        =   16
      Top             =   2160
      Width           =   2175
   End
   Begin VB.Image Image2 
      Height          =   480
      Left            =   8880
      Picture         =   "FClienteCredito.frx":12AC
      Top             =   1440
      Width           =   480
   End
   Begin VB.Label Label6 
      Caption         =   "%"
      Height          =   255
      Left            =   3960
      TabIndex        =   15
      Top             =   2280
      Width           =   255
   End
   Begin VB.Image Image1 
      Height          =   480
      Left            =   7800
      Picture         =   "FClienteCredito.frx":15B6
      Top             =   120
      Width           =   480
   End
   Begin VB.Label lblMensajeMoneda 
      Caption         =   "(En Moneda del Cliente)"
      Height          =   255
      Left            =   5400
      TabIndex        =   14
      Top             =   120
      Width           =   1815
   End
   Begin VB.Label lblMontoLimite 
      Alignment       =   1  'Right Justify
      BorderStyle     =   1  'Fixed Single
      Height          =   255
      Left            =   6840
      TabIndex        =   13
      Top             =   1680
      Width           =   1935
   End
   Begin VB.Label Label3 
      Caption         =   "%"
      Height          =   255
      Left            =   3960
      TabIndex        =   12
      Top             =   1680
      Width           =   255
   End
   Begin VB.Label Label2 
      Caption         =   "Porcentaje de Límite de Credito de Almacen "
      Height          =   375
      Left            =   360
      TabIndex        =   11
      Top             =   1680
      Width           =   2295
   End
   Begin VB.Label lblMonto 
      Caption         =   "Monto Total de Límite de Crédito"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   720
      TabIndex        =   10
      Top             =   120
      Width           =   2295
   End
   Begin VB.Line Line2 
      X1              =   360
      X2              =   9480
      Y1              =   3120
      Y2              =   3120
   End
   Begin VB.Line Line1 
      X1              =   120
      X2              =   9480
      Y1              =   840
      Y2              =   840
   End
   Begin VB.Label lblMontoExceso 
      Caption         =   "Monto de Excedente de Límite de Crédito de Almacen"
      Height          =   375
      Left            =   4440
      TabIndex        =   9
      Top             =   2280
      Width           =   2175
   End
   Begin VB.Label lblMontoCred 
      Caption         =   "Monto de Límite de Crédito de Almacen"
      Height          =   375
      Left            =   4440
      TabIndex        =   8
      Top             =   1680
      Width           =   2295
   End
   Begin VB.Label lblAlmacen 
      AutoSize        =   -1  'True
      Caption         =   "Almacen"
      Height          =   195
      Left            =   360
      TabIndex        =   7
      Top             =   1080
      Width           =   615
   End
End
Attribute VB_Name = "FClienteCredito"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public GrecibeUbicacion As BookmarkEnum
Public GrecibeColumnaID As String
Public GrecibeColumnaOpcional As String
Public GrecibeColumnaOpcional2 As String
Public GrecibeColumnaOpcional3 As String
Public objAlmacen As DB_INV_MANTENIMIENTOS.C_ALMACEN
Public objCliente As DB_MA_MANTENIMIENTOS.C_CLIENTE

Public GlngCorrelativo As Long
Public GstrcodCliente As String
Public GstrMontoTotal As String
Public GstrPorcentaje As String
Public GstrCodAlmacen As String
Public GblnModificando As Boolean

Private Sub cmdaceptar_Click()
On Error GoTo ErrorHandler

  If Trim(ctnMontoTotal.Text) = Empty Then
     MsgBox "Ingrese Monto Total del Crédito", vbDefaultButton1 + vbExclamation, "Faltan Parámetros"
     ctnMontoTotal.SetFocus
     Exit Sub
  End If
  
  If Trim(dtcAlmacen.BoundText) = Empty Then
     MsgBox "Ingrese Almacen", vbDefaultButton1 + vbExclamation, "Faltan Parámetros"
     dtcAlmacen.SetFocus
     Exit Sub
  End If
  
  If CDbl(ctnPorcentaje.Text) = 0 Then
     MsgBox "Porcentaje de Limite de Crédito no puede ser cero", vbDefaultButton1 + vbExclamation, "Error de Ingreso"
     ctnPorcentaje.SetFocus
     Exit Sub
  End If
  
  If CDbl(ctnPorcentaje.Text) > CDbl(lblPorcentaje.Caption) Then
     MsgBox "Solo tiene disponible el " & lblPorcentaje.Caption & "% del Total de Límite de Crédito", vbDefaultButton1 + vbExclamation, "Error de Ingreso"
     ctnPorcentaje.SetFocus
     Exit Sub
  End If
  
  
    If Not GblnModificando Then
        objCliente.AgregarCreditoEnTmp GlngCorrelativo, dtcAlmacen.BoundText, CDbl(ctnPorcentaje.Text), GFormatodeNumero(CDbl(lblMontoLimite.Caption), GintDecResultado), 0, CDbl(ctnPorcExceso.Text), GFormatodeNumero(CDbl(lblMontoExedente.Caption), GintDecResultado)
    Else
        objCliente.ActualizarCreditoEnTmp GlngCorrelativo, dtcAlmacen.BoundText, CDbl(ctnPorcentaje.Text), GFormatodeNumero(CDbl(lblMontoLimite.Caption), GintDecResultado), CDbl(ctnPorcExceso.Text), GFormatodeNumero(CDbl(lblMontoExedente.Caption), GintDecResultado)
    End If

  Unload Me

Exit Sub

ErrorHandler:
    
    MsgBox MensajedeError(Err.Number, Err.Description), vbCritical + vbDefaultButton1, "Advertencia"
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
      
    FBusquedasMa2.GObtenerRegistros objAlmacen.ListarAlmacenesPorStatus(1), ArrayBusqueda, 2, 2
    FBusquedasMa2.GnroPantalla = 1
    FBusquedasMa2.Show vbModal
    
    If GrecibeUbicacion <> 0 Then
        dtcAlmacen.BoundText = GrecibeColumnaID
    End If
End Sub

Public Sub CargaDataCombo(objDataCombo As DataCombo, rsSource As ADODB.Recordset, istrCampo1 As String, istrCampo2 As String)
    If rsSource.RecordCount <> 0 Then
        Set objDataCombo.DataSource = rsSource
        objDataCombo.DataField = istrCampo2
        Set objDataCombo.RowSource = rsSource
        objDataCombo.ListField = istrCampo2
        objDataCombo.BoundColumn = istrCampo1
        objDataCombo.BoundText = rsSource.Fields(istrCampo2)
    End If
End Sub

Private Sub cmdcancelar_Click()
Unload Me
End Sub

Private Sub ctnMontoTotal_change()
On Error GoTo TrataError
    lblMontoLimite.Caption = GFormatodeNumero((CDbl(ctnMontoTotal.Text) * CDbl(ctnPorcentaje.Text) / 100), GintDecResultado)
    lblMontoExedente.Caption = GFormatodeNumero((CDbl(lblMontoLimite.Caption) * CDbl(ctnPorcExceso.Text) / 100), GintDecResultado)
TrataError:
End Sub

Private Sub ctnPorcentaje_change()
On Error GoTo TrataError
    lblMontoLimite.Caption = GFormatodeNumero((CDbl(ctnMontoTotal.Text) * CDbl(ctnPorcentaje.Text) / 100), GintDecResultado)
    lblMontoExedente.Caption = GFormatodeNumero((CDbl(lblMontoLimite.Caption) * CDbl(ctnPorcExceso.Text) / 100), GintDecResultado)
TrataError:
End Sub

Private Sub ctnPorcentaje_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        ctnPorcExceso.SetFocus
    End If
End Sub

Private Sub ctnPorcExceso_change()
On Error GoTo TrataError
    lblMontoExedente.Caption = GFormatodeNumero((CDbl(lblMontoLimite.Caption) * CDbl(ctnPorcExceso.Text) / 100), GintDecResultado)
TrataError:
End Sub

Private Sub ctnPorcExceso_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        cmdaceptar.SetFocus
    End If
End Sub

Private Sub dtcAlmacen_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        ctnPorcentaje.SetFocus
    End If
End Sub

Private Sub Form_Load()
    
    ctnPorcentaje.ValorPorDefecto
    ctnPorcentaje.Enteros = 3
    ctnPorcentaje.Decimales = 2
    ctnPorcExceso.ValorPorDefecto
    ctnPorcExceso.Enteros = 3
    ctnPorcExceso.Decimales = 2

    
    Set objAlmacen = New DB_INV_MANTENIMIENTOS.C_ALMACEN
    Set objCliente = New DB_MA_MANTENIMIENTOS.C_CLIENTE
    Call CargaDataCombo(dtcAlmacen, objAlmacen.ListarAlmacenesPorStatus(1), "SiteId", "Name")

    dtcAlmacen.BoundText = GstrCodAlmacen
    dtcAlmacen.Enabled = Not GblnModificando
    ctnMontoTotal.Enabled = False
    ctnMontoTotal.Text = GstrMontoTotal
    cmdBusAlmacen.Enabled = Not GblnModificando
    
    If Not GblnModificando Then
        lblPorcentaje.Caption = 100 - (objCliente.ObtienePorcentajeEnTmpCust_Limit(GlngCorrelativo))
    Else
        lblPorcentaje.Caption = 100 - (objCliente.ObtienePorcentajeEnTmpCust_Limit(GlngCorrelativo)) + CDbl(GstrPorcentaje)
    End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Set objAlmacen = Nothing
    Set objCliente = Nothing
    
    GstrMontoTotal = "0"
    GstrCodAlmacen = Empty
    GblnModificando = False
    GstrPorcentaje = "0"
End Sub
