VERSION 5.00
Begin VB.Form FrmApertura 
   BackColor       =   &H80000001&
   Caption         =   "Información de Apertura de Caja"
   ClientHeight    =   2370
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4500
   ControlBox      =   0   'False
   LinkTopic       =   "Form1"
   ScaleHeight     =   2370
   ScaleWidth      =   4500
   StartUpPosition =   1  'CenterOwner
   Begin VB.CommandButton Command1 
      Cancel          =   -1  'True
      Caption         =   "&Cancelar"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   2790
      TabIndex        =   6
      Top             =   1590
      Width           =   1335
   End
   Begin VB.TextBox TxtImporDolares 
      Alignment       =   1  'Right Justify
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   2160
      TabIndex        =   1
      Text            =   "0.00"
      Top             =   1080
      Width           =   1215
   End
   Begin VB.TextBox txtimporsoles 
      Alignment       =   1  'Right Justify
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   2160
      TabIndex        =   0
      Text            =   "0.00"
      Top             =   600
      Width           =   1215
   End
   Begin VB.CommandButton CmdGrabar 
      Caption         =   "&Grabar"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   330
      TabIndex        =   2
      Top             =   1590
      Width           =   1335
   End
   Begin VB.Image Image1 
      Height          =   480
      Left            =   0
      Picture         =   "FrmApertura.frx":0000
      Top             =   0
      Width           =   480
   End
   Begin VB.Label Label3 
      BackStyle       =   0  'Transparent
      Caption         =   "Ingrese Importe Inicial de Caja"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   720
      TabIndex        =   5
      Top             =   120
      Width           =   2775
   End
   Begin VB.Label Label2 
      BackColor       =   &H80000001&
      Caption         =   "Importe Dolares"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H8000000E&
      Height          =   255
      Left            =   240
      TabIndex        =   4
      Top             =   1140
      Width           =   1815
   End
   Begin VB.Label Label1 
      BackColor       =   &H80000001&
      Caption         =   "Importe Soles"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H8000000E&
      Height          =   255
      Left            =   240
      TabIndex        =   3
      Top             =   660
      Width           =   1455
   End
   Begin VB.Shape Shape1 
      BackStyle       =   1  'Opaque
      BorderStyle     =   0  'Transparent
      Height          =   495
      Left            =   0
      Top             =   0
      Width           =   4575
   End
End
Attribute VB_Name = "FrmApertura"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
  Dim sSQL As String
  Dim dImporAperturaSol As Double
  Dim dImporAperturaDol As Double
Private Sub cmdGrabar_Click()
    Dim ADORS As ADODB.Recordset
    Dim cOperId As String
    Dim cOperIdP As String
    
    dImporAperturaSol = CDbl(Me.txtimporsoles.Text)
    dImporAperturaDol = CDbl(Me.TxtImporDolares.Text)
    
    'Id de operacion de la tabla OPERACION
    sSQL = "SELECT IIF(ISNULL(MAX(cOperID)),0, MAX(cOperID)) as cOperIDx FROM Operacion Where coperflagabierto = 0 "
    If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
    
    cOperId = LeerCampo(ADORS("cOperIDx"))
    
    'Id de operacion de la tabla OPERACIONPARALELA
    sSQL = "SELECT IIF(ISNULL(MAX(cOperCode)),0, MAX(cOperCode)) as cOperCodex FROM OperacionParalela Where coperflagabierto = 0 "
    If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
    
    cOperIdP = LeerCampo(ADORS("cOperCodex"))
    
    kPAR_TURNO = "01"
    sSQL = "UPDATE Configuracion SET cCodiTurno = '" + kPAR_TURNO + "' " & _
            ", nImporApertSol=" + CStr(Replace(dImporAperturaSol, ",", "")) & _
            ", nImporApertDol=" + CStr(Replace(dImporAperturaDol, ",", "")) & _
            ", cOperId = " + cOperId + ", cOperIdP = " + cOperIdP
    
    Call oDBAdmin.EjecutarSentencia(ADOCnn, sSQL)
    
    MsgBox "Se ha aperturado la caja."
    
    frmPrincipal.Toolbar1.Buttons(2).Enabled = True
    frmPrincipal.Toolbar1.Buttons(6).Enabled = True
    frmPrincipal.Toolbar1.Buttons(8).Enabled = True
    frmPrincipal.Toolbar1.Buttons(9).Enabled = True
    frmPrincipal.Toolbar1.Buttons(11).Enabled = True
    
    
    frmPrincipal.ProcesoCaja True
    
    sSQL = "SELECT Count(*) As nCount FROM Operacion Where coperflagabierto = 1 " & _
           "AND dOperFech < (SELECT max(fec) FROM _Tmp)"
           
    If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
    
    If ADORS!nCount > 1 Then
      sSQL = "UPDATE Operacion SET coperflagabierto = '0' " & _
             "WHERE dOperFech < (SELECT max(fec) FROM _Tmp)"
      Call oDBAdmin.EjecutarSentencia(ADOCnn, sSQL)
      MsgBox "NO se cerraron operaciones anteriores. " & vbCrLf & "Recuerde que debe procesar el menu SINCRONIZAR DATOS (DIA ANTERIOR) antes del mediodia!!! ", vbInformation + vbOKOnly, "Mensaje"
      
      frmPrincipal.mnu_sincronizar_DiaAnt.Enabled = True
      
      EscribirLog "frmApertura.cmdGrabar_Click - " & "No se cerraron operaciones" & Err.Description
    End If
    
    sSQL = "SELECT count(*) as nCount FROM Operacionparalela Where coperflagabierto = 1 " & _
           "AND  dOperFech < (SELECT max(fec) FROM _Tmp)"
           
    If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
    
    If ADORS!nCount > 1 Then
      sSQL = "UPDATE Operacionparalela SET coperflagabierto = '0' " & _
             "WHERE dOperFech < (SELECT max(fec) FROM _Tmp)"
      Call oDBAdmin.EjecutarSentencia(ADOCnn, sSQL)
      MsgBox "NO se cerraron operaciones anteriores. " & vbCrLf & "Recuerde que debe procesar el menu SINCRONIZAR DATOS (DIA ANTERIOR) antes del mediodia!!! ", vbInformation + vbOKOnly, "Mensaje"
      
      EscribirLog "frmApertura.cmdGrabar_Click - " & "No se cerraron operaciones" & Err.Description
    End If
    
    Unload Me
    GoTo AperturaOK
    
Salir:
    MsgBox "No se pudo aperturar la Caja.", vbInformation + vbOKOnly, "Mensaje"
AperturaOK:
    Screen.MousePointer = vbDefault
End Sub
Private Sub Command1_Click()
    Unload Me
End Sub
Private Sub TxtImporDolares_GotFocus()
    TxtImporDolares.SelStart = 0
    TxtImporDolares.SelLength = Len(Me.TxtImporDolares)
End Sub
Private Sub TxtImporDolares_LostFocus()
    TxtImporDolares.Text = Format(TxtImporDolares.Text, "###,###,###,##0.00")
End Sub
Private Sub txtimporsoles_GotFocus()
    txtimporsoles.SelStart = 0
    txtimporsoles.SelLength = Len(Me.txtimporsoles)
End Sub
Private Sub txtimporsoles_LostFocus()
    txtimporsoles.Text = Format(txtimporsoles.Text, "###,###,###,##0.00")
End Sub

