VERSION 5.00
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 FFormulas 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Fórmulas (01.100.00)"
   ClientHeight    =   5550
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   9270
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   ScaleHeight     =   5550
   ScaleWidth      =   9270
   Begin VB.Frame Frame1 
      Height          =   825
      Left            =   120
      TabIndex        =   19
      Top             =   4560
      Width           =   9015
      Begin VB.Label lblCostoTotalUSD 
         Alignment       =   1  'Right Justify
         Appearance      =   0  'Flat
         BackColor       =   &H80000000&
         BorderStyle     =   1  'Fixed Single
         Caption         =   "0"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H80000008&
         Height          =   255
         Left            =   7320
         TabIndex        =   26
         Top             =   240
         Width           =   1455
      End
      Begin VB.Label lblDolares 
         AutoSize        =   -1  'True
         Caption         =   "En Dolares"
         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            =   6240
         TabIndex        =   25
         Top             =   240
         Width           =   945
      End
      Begin VB.Label lblSoles 
         AutoSize        =   -1  'True
         Caption         =   "En Soles "
         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            =   3120
         TabIndex        =   24
         Top             =   240
         Width           =   825
      End
      Begin VB.Label lblCostoTotal 
         Caption         =   "Costo Total de la Fórmula :"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   9.75
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H8000000D&
         Height          =   495
         Left            =   840
         TabIndex        =   21
         Top             =   240
         Width           =   1935
      End
      Begin VB.Label lblCostoTotalPEN 
         Alignment       =   1  'Right Justify
         Appearance      =   0  'Flat
         BackColor       =   &H80000000&
         BorderStyle     =   1  'Fixed Single
         Caption         =   "0"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H80000008&
         Height          =   255
         Left            =   4125
         TabIndex        =   20
         Top             =   225
         Width           =   1455
      End
   End
   Begin VB.CommandButton cmdBuscar 
      Enabled         =   0   'False
      Height          =   375
      Left            =   3120
      MouseIcon       =   "0110000.frx":0000
      MousePointer    =   99  'Custom
      Picture         =   "0110000.frx":0152
      Style           =   1  'Graphical
      TabIndex        =   1
      ToolTipText     =   "Buscar"
      Top             =   360
      Width           =   375
   End
   Begin VB.TextBox txtDescripcion 
      Height          =   285
      Left            =   1200
      TabIndex        =   2
      Top             =   795
      Width           =   4695
   End
   Begin VB.TextBox txtCodigo 
      Height          =   285
      Left            =   1200
      TabIndex        =   0
      Top             =   360
      Width           =   1695
   End
   Begin VB.CommandButton cmdBusUnimed 
      Height          =   375
      Left            =   8760
      MouseIcon       =   "0110000.frx":0684
      MousePointer    =   99  'Custom
      Picture         =   "0110000.frx":07D6
      Style           =   1  'Graphical
      TabIndex        =   4
      ToolTipText     =   "Buscar"
      Top             =   315
      Visible         =   0   'False
      Width           =   375
   End
   Begin VB.Frame fraDatosItem 
      Appearance      =   0  'Flat
      BackColor       =   &H80000004&
      ForeColor       =   &H80000008&
      Height          =   1095
      Left            =   120
      TabIndex        =   5
      Top             =   3360
      Width           =   9015
      Begin VB.CommandButton cmdBuscaArticulo 
         Height          =   375
         Left            =   3240
         Picture         =   "0110000.frx":0D08
         Style           =   1  'Graphical
         TabIndex        =   9
         TabStop         =   0   'False
         Top             =   240
         Width           =   375
      End
      Begin VB.CommandButton cmdNuevoItem 
         Caption         =   "Nuevo"
         Height          =   495
         Left            =   6480
         Picture         =   "0110000.frx":123A
         Style           =   1  'Graphical
         TabIndex        =   11
         Top             =   600
         Visible         =   0   'False
         Width           =   855
      End
      Begin VB.TextBox txtArticulo 
         Height          =   285
         Left            =   1080
         TabIndex        =   8
         Top             =   240
         Width           =   2055
      End
      Begin VB.CommandButton cmdEliminarItem 
         Caption         =   "Eliminar"
         Height          =   495
         Left            =   7320
         Picture         =   "0110000.frx":176C
         Style           =   1  'Graphical
         TabIndex        =   12
         Top             =   600
         Visible         =   0   'False
         Width           =   855
      End
      Begin VB.CommandButton cmdActualizaItem 
         Caption         =   "Actualizar"
         Height          =   495
         Left            =   8160
         Picture         =   "0110000.frx":186E
         Style           =   1  'Graphical
         TabIndex        =   6
         Top             =   600
         Visible         =   0   'False
         Width           =   855
      End
      Begin MiControl.CtrlNumber ctnCantidad 
         Height          =   375
         Left            =   1080
         TabIndex        =   10
         Top             =   645
         Width           =   1575
         _ExtentX        =   2778
         _ExtentY        =   661
         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.Label lblMensaje 
         Caption         =   "(Solo se pueden asignar a la Fórmula aquellos artículos a los que se les ingreso algún costo en el Maestro de Artículos)"
         ForeColor       =   &H00800000&
         Height          =   400
         Left            =   3720
         TabIndex        =   27
         Top             =   600
         Width           =   4935
      End
      Begin VB.Label lblCostoUSD 
         BorderStyle     =   1  'Fixed Single
         Height          =   375
         Left            =   4800
         TabIndex        =   23
         Top             =   600
         Visible         =   0   'False
         Width           =   1575
      End
      Begin VB.Label lblCostoPEN 
         BorderStyle     =   1  'Fixed Single
         Height          =   375
         Left            =   2880
         TabIndex        =   22
         Top             =   600
         Visible         =   0   'False
         Width           =   1695
      End
      Begin VB.Label lblCantidad 
         Caption         =   "Cantidad"
         Height          =   255
         Left            =   240
         TabIndex        =   15
         Top             =   645
         Width           =   855
      End
      Begin VB.Label lblArticulo 
         Caption         =   "Artículo"
         Height          =   255
         Left            =   240
         TabIndex        =   14
         Top             =   240
         Width           =   615
      End
      Begin VB.Label lblDescripcionArticulo 
         BorderStyle     =   1  'Fixed Single
         Height          =   285
         Left            =   3720
         TabIndex        =   13
         Top             =   240
         Width           =   4335
      End
   End
   Begin MSDataGridLib.DataGrid DBDetalle 
      Height          =   1935
      Left            =   120
      TabIndex        =   7
      Top             =   1320
      Width           =   9015
      _ExtentX        =   15901
      _ExtentY        =   3413
      _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         =   "[Enter]_Modificar_[F3]_Eliminar Registro"
      ColumnCount     =   2
      BeginProperty Column00 
         DataField       =   ""
         Caption         =   ""
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   10250
            SubFormatType   =   0
         EndProperty
      EndProperty
      BeginProperty Column01 
         DataField       =   ""
         Caption         =   ""
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   10250
            SubFormatType   =   0
         EndProperty
      EndProperty
      SplitCount      =   1
      BeginProperty Split0 
         BeginProperty Column00 
         EndProperty
         BeginProperty Column01 
         EndProperty
      EndProperty
   End
   Begin MSDataListLib.DataCombo dtcUnimed 
      Height          =   315
      Left            =   7080
      TabIndex        =   3
      Top             =   315
      Width           =   1575
      _ExtentX        =   2778
      _ExtentY        =   556
      _Version        =   393216
      Style           =   2
      Text            =   ""
   End
   Begin VB.Label lblDescripcion 
      Caption         =   "Descripción"
      Height          =   255
      Left            =   240
      TabIndex        =   18
      Top             =   795
      Width           =   975
   End
   Begin VB.Label lblCodigo 
      Caption         =   "Código"
      Height          =   255
      Left            =   240
      TabIndex        =   17
      Top             =   360
      Width           =   615
   End
   Begin VB.Label lblUnidad 
      Caption         =   "Unidad"
      Height          =   255
      Left            =   6360
      TabIndex        =   16
      Top             =   315
      Width           =   615
   End
End
Attribute VB_Name = "FFormulas"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' Programador: Edgar Cancho Ruiz
' Empresa Texaco
' Modulo de Mantenimiento de Fórmulas
' Fecha : 10/09/2002

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

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

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

Public rs_formulas As ADODB.Recordset
Private objFormula As DB_INV_MANTENIMIENTOS.C_FORMULA
Private objUnidad As DB_INV_MANTENIMIENTOS.C_UNIDADMEDIDA
Private objCorrelativo As DB_CORRELATIVO.C_Correlativos

Dim lngCorrelativo As Long 'correlativo por usuario, que se almacenara en cada insert en temporal
Dim lngSecuencia As Long ' guardara el número de Item del detalle

Dim blnActualizandoItem As Boolean ' flag para controlar la modificación de un Item

Private Sub cmdActualizaItem_Click()

    Call objFormula.ActualizaTmpDetalleFormula(txtArticulo.Text, DBDetalle.Columns(0).Text, _
                                         CDbl(ctnCantidad.Text), lngCorrelativo)
                                         
    Call CargaGrid(txtCodigo)
    Call LimpiaCajaDetalle
    'Call PonerDatosGrig
    Call ActualizaPie
    'blnActualizandoItem = False
    txtArticulo.Enabled = True
    txtArticulo.SetFocus
    
End Sub

Private Sub cmdBuscaArticulo_Click()
   'Lineas que llaman al Formulario de Búsqueda
     GrecibeUbicacion = 0
     GrecibeColumnaID = Empty
     GrecibeColumnaOpcional = Empty
     
     Dim ArrayBusqueda(1 To 4, 1 To 3) As Variant
     Dim blnExiste As Boolean
     ArrayBusqueda(1, 1) = "Invtidsku"
     ArrayBusqueda(1, 2) = "Código "
     ArrayBusqueda(1, 3) = 1000
     ArrayBusqueda(2, 1) = "Descr"
     ArrayBusqueda(2, 2) = "Descripción "
     ArrayBusqueda(2, 3) = 4000
     ArrayBusqueda(3, 1) = "STDCOSTPEN"
     ArrayBusqueda(3, 2) = "Costo_Soles"
     ArrayBusqueda(3, 3) = 4000
     ArrayBusqueda(4, 1) = "STDCOSTUSD"
     ArrayBusqueda(4, 2) = "Costo_Dolares"
     ArrayBusqueda(4, 3) = 4000
         
     FBusquedasMa.GObtenerRegistros objFormula.ListarArticulosParaFormulas(GstrSiteProce, txtCodigo.Text), ArrayBusqueda, 2, 2
     FBusquedasMa.Show vbModal
     
     If GrecibeUbicacion <> 0 Then
         txtArticulo.Text = GrecibeColumnaID
         lblDescripcionArticulo.Caption = GrecibeColumnaOpcional
         lblCostoPEN.Caption = GrecibeColumnaOpcional2
         lblCostoUSD.Caption = GrecibeColumnaOpcional3
         ctnCantidad.ValorPorDefecto
         blnExiste = objFormula.ExisteArticulo(Trim(txtArticulo.Text), lngCorrelativo)
         If blnExiste Then
            LimpiaCajaDetalle
            MsgBox "Código de articulo ya registrado", vbExclamation, "Mensaje"
            Exit Sub
         End If
         'txtArticulo_KeyPress (13)
         ctnCantidad.SetFocus
     End If
End Sub

Private Sub cmdBuscar_Click()
    'Lineas que llaman al Formulario de Búsqueda
    
    Dim ArrayBusqueda(1 To 2, 1 To 3) As Variant
    ArrayBusqueda(1, 1) = "INVTIDSKU"
    ArrayBusqueda(1, 2) = "Código "
    ArrayBusqueda(1, 3) = 1000
    ArrayBusqueda(2, 1) = "Descr"
    ArrayBusqueda(2, 2) = "Descripción "
    ArrayBusqueda(2, 3) = 4000
      
          
    FBusquedasMa.GObtenerRegistros objFormula.ListarFormulasAyuda, ArrayBusqueda, 2, 2
    FBusquedasMa.Show vbModal
    If GrecibeUbicacion <> 0 Then
          rs_formulas.AbsolutePosition = GrecibeUbicacion
          asigna_campos
          Call gestadoactualrs(Me, rs_formulas)
          Call gactualiza_barra(Me)
    End If
  
End Sub

Private Sub cmdBusUnimed_Click()
    'Lineas que llaman al Formulario de Búsqueda
    
    Dim ArrayBusqueda(1 To 2, 1 To 3) As Variant
    ArrayBusqueda(1, 1) = "STKUNITID"
    ArrayBusqueda(1, 2) = "Código "
    ArrayBusqueda(1, 3) = 1000
    ArrayBusqueda(2, 1) = "descr"
    ArrayBusqueda(2, 2) = "Descripción "
    ArrayBusqueda(2, 3) = 4000
      
    FBusquedasMa.GObtenerRegistros objUnidad.ListarUnitMed, ArrayBusqueda, 2, 2
    FBusquedasMa.Show vbModal
    
    If GrecibeUbicacion <> 0 Then
        dtcUnimed.BoundText = GrecibeColumnaID
    End If
End Sub

Private Sub cmdEliminarItem_Click()
    If MsgBox("Está seguro de Eliminar. ", vbQuestion + vbYesNo, "Eliminar") = vbNo Then
        Exit Sub
    Else
        Call objFormula.EliminarItemEnTmpDetalleFormula(DBDetalle.Columns(1).Text, lngCorrelativo)
        Call objFormula.ActualizaNumRegEnTmpDetalleFormula(txtCodigo.Text, lngCorrelativo)
        Call CargaGrid(txtCodigo.Text)
        Call ActualizaPie
        Call LimpiaCajaDetalle
        Call PonerDatosGrig

    End If
End Sub

Private Sub cmdNuevoItem_Click()
    lngSecuencia = objCorrelativo.SgteItemEnDetalleFormula(lngCorrelativo)

    objFormula.AgregaEnTemporalDetalleFormula lngCorrelativo, txtCodigo.Text, txtArticulo, _
                                              lngSecuencia, CDbl(lblCostoPEN.Caption), CDbl(lblCostoUSD.Caption), CDbl(ctnCantidad.Text)
    
    'Set DBDetalle.DataSource = objFormula.SeleccionaEnTemporalDetalleFormula(txtCodigo.Text, lngCorrelativo)
    Call CargaGrid(txtCodigo.Text)
    Call ActualizaPie
    Call LimpiaCajaDetalle
    txtArticulo.SetFocus
End Sub

Private Sub ctnCantidad_GotFocus()
ctnCantidad.BackColor = GC_ColorEnfoque
End Sub

Private Sub ctnCantidad_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        If Val(ctnCantidad.Text) = 0 Then
            MsgBox "El Campo Cantidad no puede ser cero", vbExclamation, "Ingresos"
            ctnCantidad.SetFocus
            Exit Sub
        End If
        
        If blnActualizandoItem Then
            Call cmdActualizaItem_Click
        Else
            Dim rsTemporal As ADODB.Recordset
            Set rsTemporal = objFormula.ValidaCodigoIngresado(GstrSiteProce, Trim(txtArticulo.Text))
            
            If rsTemporal.RecordCount <> 0 Then ' si no esta vacio
                If objFormula.ExisteArticulo(txtArticulo.Text, lngCorrelativo) Then
                        MsgBox "Código de articulo ya registrado", vbExclamation, "Mensaje"
                        txtArticulo.SetFocus
                        Exit Sub
                End If
                
                cmdNuevoItem_Click
            Else
                MsgBox "Código ingresado no existe", vbExclamation, "Ingresos"
                Set rsTemporal = Nothing
                txtArticulo.SetFocus
                Exit Sub
            End If
            
            Set rsTemporal = Nothing
        End If
        
    End If
End Sub

Private Sub ctnCantidad_LostFocus()
    blnActualizandoItem = False
    txtArticulo.Enabled = True
    cmdBuscaArticulo.Enabled = True
    ctnCantidad.BackColor = GC_ColorDefecto
End Sub

Private Sub DBDetalle_KeyUp(KeyCode As Integer, Shift As Integer)
    DBDetalle.Refresh
    PonerDatosGrig
    
    If pb_editar Then ' si se esta modificando una fórmula
        If KeyCode = vbKeyF3 Then
            If DBDetalle.Bookmark <> 0 Or Not IsNull(DBDetalle.Bookmark) Then
                cmdEliminarItem_Click
                Exit Sub
            End If
        End If
        If KeyCode = 13 Then
            If DBDetalle.Bookmark <> 0 Or Not IsNull(DBDetalle.Bookmark) Then
                    txtArticulo.Enabled = False
                    cmdBuscaArticulo.Enabled = False
                    blnActualizandoItem = True
                    ctnCantidad.SetFocus
                Exit Sub
            End If
        End If
    End If
    
End Sub

Private Sub DBDetalle_LostFocus()
    'Call LimpiaCajaDetalle
End Sub

Private Sub DBDetalle_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
    DBDetalle.Refresh
    PonerDatosGrig
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

Public Sub primer_registro()
    Call Gprimer_registro(Me, rs_formulas)
    Call asigna_campos
End Sub

Public Sub ultimo_registro()
    Call Gultimo_registro(Me, rs_formulas)
    Call gactualiza_barra(Me)
    Call asigna_campos
End Sub

Public Sub registro_anterior()
    Call Gregistro_anterior(Me, rs_formulas)
    Call gactualiza_barra(Me)
    Call asigna_campos
End Sub
Public Sub registro_siguiente()
    Call Gregistro_siguiente(Me, rs_formulas)
    Call asigna_campos
End Sub

Private Sub Form_Initialize()
    Call gHabilitarReg(Me, False)
End Sub

Private Sub Form_Load()
    'seguridad
    Call gseguridad(Me)
    
    If pbderecho_consultar Then
    
        Call InstanciaObjetos
        
        Call obtener_datos
        Call GCargaDataCombo(dtcUnimed, objUnidad.ListarUnitMed, "STKUNITID", "descr")
        Call asigna_campos
        pb_primerregistro = True
    'lineas nuevas
    Else
        MsgBox ("No tiene Derechos de Consultar en este formulario")
    End If
    
    ctnCantidad.Enteros = 7
    ctnCantidad.Decimales = GintDecStock
    PonerDatosGrig
    Me.Top = 1300
    Me.Left = (Screen.Width - Me.Width) / 2
 
End Sub
Public Sub borrar_registro()
    Call gborrar_Registro(Me, rs_formulas, txtCodigo)
End Sub
Function valida_datos()
    valida_datos = True
End Function
Public Sub grabar_registro()

On Error GoTo errhandler

    If valida_datos() = True Then
        Call objFormula.ActualizaDetalleFormula(txtCodigo.Text, lngCorrelativo)
        Call asigna_campos
        Call ggrabar_registro(Me)
        actualizar_registro
    End If
    
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, txtCodigo)
End Sub
Public Sub modificar_registro()
    Call gmodificar_registro(Me, txtCodigo)
    Call DesabilitaCabecera
        
    cmdBuscaArticulo.Enabled = True
    Call LimpiaCajaDetalle
    
    If txtArticulo.Enabled = True Then
       txtArticulo.SetFocus
    End If
    
    lngCorrelativo = objCorrelativo.ObtenerCorrelativo(GCUSERID)
    Call objFormula.CopiarDetalleFormulaAlTemporal(txtCodigo.Text, lngCorrelativo)
    Call CargaGrid(txtCodigo.Text)
End Sub
Public Sub descartar_registro()
    ' Revertir cambios
    Call gdescartar_registro(Me)
    Call asigna_campos
End Sub


Sub obtener_datos()
    Set rs_formulas = objFormula.ListarFormulas
End Sub

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

Sub asigna_campos() ' falta decidir si va ha ser public o private
    Dim rsTemporal As ADODB.Recordset
        If rs_formulas.RecordCount <> 0 And Not rs_formulas.EOF Then
            
            txtCodigo.Text = rs_formulas!INVTIDSKU
            txtDescripcion.Text = rs_formulas!DESCR
            dtcUnimed.BoundText = rs_formulas!StkUnitID
            
            Set DBDetalle.DataSource = objFormula.ListarDetalleDeFormulasPorID(rs_formulas!INVTIDSKU)
            Call FormatoGrilla
            DBDetalle.Refresh
            Set rsTemporal = objFormula.ObtieneCostosTotalesEnFormulas(rs_formulas!INVTIDSKU, 0, 1)
            lblCostoTotalPEN.Caption = Format(IIf(IsNull(rsTemporal!COSTOPEN), 0, rsTemporal!COSTOPEN), GMascara(GintDecCosto))
            lblCostoTotalUSD.Caption = Format(IIf(IsNull(rsTemporal!COSTOUSD), 0, rsTemporal!COSTOUSD), GMascara(GintDecCosto))
            
            Call PonerDatosGrig
        End If
    Set rsTemporal = Nothing

End Sub

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

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

Private Sub txtArticulo_GotFocus()
    'Call LimpiaCajaDetalle
    txtArticulo.BackColor = GC_ColorEnfoque
End Sub

Private Sub txtArticulo_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyF2 Then cmdBuscaArticulo_Click
End Sub

Private Sub txtArticulo_KeyPress(KeyAscii As Integer)
KeyAscii = GBloqueaCaracter(KeyAscii)
    If KeyAscii = 13 Then
    
        Dim rsTemporal As ADODB.Recordset
        Set rsTemporal = objFormula.ValidaCodigoIngresado(GstrSiteProce, Trim(txtArticulo.Text))
        
        If rsTemporal.RecordCount <> 0 Then ' si no esta vacio
            If objFormula.ExisteArticulo(txtArticulo.Text, lngCorrelativo) Then
                    MsgBox "Código de articulo ya registrado", vbExclamation, "Mensaje"
                    txtArticulo.SetFocus
                    Exit Sub
            End If
            
            rsTemporal.MoveFirst ' muevete al primer registro
            
            'cargo valores
            txtArticulo.Text = rsTemporal!INVTIDSKU
            lblDescripcionArticulo.Caption = rsTemporal!DESCR
            lblCostoPEN.Caption = Format(rsTemporal!STDCOSTPEN, GMascara(GintDecCosto))
            lblCostoUSD.Caption = Format(rsTemporal!STDCOSTUSD, GMascara(GintDecCosto))
                
        Else
            MsgBox "Código ingresado no existe", vbExclamation, "Ingresos"
            Set rsTemporal = Nothing
            txtArticulo.SetFocus
            Exit Sub
        End If
        
        Set rsTemporal = Nothing
        'devuelvo el enfoque al campo unidades
        ctnCantidad.SetFocus
    End If
End Sub

Private Sub txtArticulo_LostFocus()
txtArticulo.BackColor = GC_ColorDefecto
End Sub

Private Sub txtDescripcion_KeyPress(KeyAscii As Integer)
    KeyAscii = GBloqueaCaracter(KeyAscii)
    If KeyAscii = 13 Then
        dtcUnimed.SetFocus
    End If
End Sub

Public Sub GCargaDataCombo(objDataCombo As DataCombo, rsSource As 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 LimpiaCajaDetalle()
    txtArticulo.Text = Empty
    lblDescripcionArticulo.Caption = Empty
    ctnCantidad.ValorPorDefecto
End Sub

Private Sub PonerDatosGrig()
On Error GoTo TrataError
    If DBDetalle.Bookmark = 0 Or IsNull(DBDetalle.Bookmark) Then
        ctnCantidad.ValorPorDefecto
        txtArticulo.Text = Empty
        lblDescripcionArticulo.Caption = Empty
    Else
        
        ctnCantidad.Text = Format(DBDetalle.Columns(4).Text, GMascara(GintDecStock))
        txtArticulo.Text = DBDetalle.Columns(1).Text
        lblDescripcionArticulo.Caption = DBDetalle.Columns(2).Text
    End If
    Exit Sub
TrataError:
End Sub

Private Sub ActualizaPie()
    Dim rsTemporal As ADODB.Recordset
    Set rsTemporal = objFormula.ObtieneCostosTotalesEnFormulas(txtCodigo.Text, lngCorrelativo, 0)
    lblCostoTotalPEN.Caption = Format(IIf(IsNull(rsTemporal!COSTOPEN), 0, rsTemporal!COSTOPEN), GMascara(GintDecCosto))
    lblCostoTotalUSD.Caption = Format(IIf(IsNull(rsTemporal!COSTOUSD), 0, rsTemporal!COSTOUSD), GMascara(GintDecCosto))
    Set rsTemporal = Nothing
End Sub

Private Sub InstanciaObjetos()
    Set objFormula = New DB_INV_MANTENIMIENTOS.C_FORMULA
    Set objUnidad = New DB_INV_MANTENIMIENTOS.C_UNIDADMEDIDA
    Set objCorrelativo = New DB_CORRELATIVO.C_Correlativos
End Sub

Private Sub DestruyeObjetos()
    Set objFormula = Nothing
    Set objUnidad = Nothing
    Set objCorrelativo = Nothing
    Set rs_formulas = Nothing
End Sub

Private Sub CargaGrid(strCodFormula As String)
    
    Set DBDetalle.DataSource = objFormula.SeleccionaEnTemporalDetalleFormula(strCodFormula, lngCorrelativo)
    Call FormatoGrilla
    DBDetalle.Refresh
    
End Sub
Private Sub FormatoGrilla()

    DBDetalle.Columns(0).Width = 800
    DBDetalle.Columns(0).Width = 800
    DBDetalle.Columns(1).Width = 1000
    DBDetalle.Columns(2).Width = 4000
    DBDetalle.Columns(3).Width = 800
    DBDetalle.Columns(4).Width = 1000
    DBDetalle.Columns(4).Alignment = dbgRight
    DBDetalle.Columns(4).NumberFormat = GMascara(GintDecStock)
    DBDetalle.Columns(5).Width = 1200
    DBDetalle.Columns(5).Alignment = dbgRight
    DBDetalle.Columns(5).NumberFormat = GMascara(GintDecCosto)
    DBDetalle.Columns(6).Width = 1200
    DBDetalle.Columns(6).Alignment = dbgRight
    DBDetalle.Columns(6).NumberFormat = GMascara(GintDecCosto)
    DBDetalle.Columns(7).Width = 1200
    DBDetalle.Columns(7).Alignment = dbgRight
    DBDetalle.Columns(7).NumberFormat = GMascara(GintDecCosto)
    DBDetalle.Columns(8).Width = 1200
    DBDetalle.Columns(8).Alignment = dbgRight
    DBDetalle.Columns(8).NumberFormat = GMascara(GintDecCosto)
    
End Sub

Private Sub DesabilitaCabecera()
    txtDescripcion.Enabled = False
    dtcUnimed.Enabled = False
End Sub

Private Sub DBDetalle_GotFocus()
    txtArticulo.Enabled = True
    blnActualizandoItem = False
End Sub

Sub imprimir()

End Sub
