VERSION 5.00
Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
Begin VB.Form FCierreZ_Playa 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Cierre Z"
   ClientHeight    =   4215
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   4710
   Icon            =   "FCierreZ_Playa.frx":0000
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   4215
   ScaleWidth      =   4710
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton cmdAceptar 
      Caption         =   "&Aceptar"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   645
      Left            =   3000
      Picture         =   "FCierreZ_Playa.frx":030A
      Style           =   1  'Graphical
      TabIndex        =   4
      Top             =   1680
      Width           =   1485
   End
   Begin VB.CommandButton cmdCancelar 
      Caption         =   "&Cancelar"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   615
      Left            =   3000
      Picture         =   "FCierreZ_Playa.frx":0614
      Style           =   1  'Graphical
      TabIndex        =   5
      Top             =   2400
      Width           =   1485
   End
   Begin VB.Frame fraDestino 
      Appearance      =   0  'Flat
      BackColor       =   &H80000004&
      Caption         =   "Destino"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H80000008&
      Height          =   1305
      Left            =   240
      TabIndex        =   6
      Top             =   1560
      Width           =   2415
      Begin VB.OptionButton optPantalla 
         Caption         =   "Pantalla"
         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            =   360
         TabIndex        =   2
         Top             =   360
         Value           =   -1  'True
         Width           =   1455
      End
      Begin VB.OptionButton optImpresora 
         Caption         =   "Impresora"
         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            =   330
         TabIndex        =   3
         Top             =   720
         Width           =   1665
      End
   End
   Begin VB.Timer Timer1 
      Interval        =   1000
      Left            =   3900
      Top             =   270
   End
   Begin MSComCtl2.Animation Animation1 
      Height          =   615
      Left            =   720
      TabIndex        =   7
      Top             =   3240
      Width           =   3045
      _ExtentX        =   5371
      _ExtentY        =   1085
      _Version        =   393216
      FullWidth       =   203
      FullHeight      =   41
   End
   Begin VB.Label lblfecha 
      Appearance      =   0  'Flat
      BackColor       =   &H80000005&
      BorderStyle     =   1  'Fixed Single
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H80000008&
      Height          =   375
      Left            =   1740
      TabIndex        =   1
      Top             =   840
      Width           =   1590
   End
   Begin VB.Label lblcaja 
      Appearance      =   0  'Flat
      BackColor       =   &H80000005&
      BorderStyle     =   1  'Fixed Single
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H80000008&
      Height          =   345
      Left            =   1740
      TabIndex        =   0
      Top             =   360
      Width           =   1875
   End
   Begin VB.Image Image2 
      Height          =   480
      Left            =   3930
      Picture         =   "FCierreZ_Playa.frx":091E
      Top             =   3240
      Visible         =   0   'False
      Width           =   480
   End
   Begin VB.Image Image3 
      Height          =   480
      Left            =   3960
      Picture         =   "FCierreZ_Playa.frx":0C28
      Top             =   3180
      Visible         =   0   'False
      Width           =   480
   End
   Begin VB.Image Image1 
      Height          =   660
      Left            =   90
      Picture         =   "FCierreZ_Playa.frx":0F32
      Stretch         =   -1  'True
      Top             =   3210
      Visible         =   0   'False
      Width           =   555
   End
   Begin VB.Label Label1 
      Caption         =   "FECHA"
      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            =   570
      TabIndex        =   10
      Top             =   840
      Width           =   825
   End
   Begin VB.Label Label3 
      Caption         =   "CAJA"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   315
      Left            =   600
      TabIndex        =   9
      Top             =   360
      Width           =   1065
   End
   Begin VB.Shape Shape1 
      Height          =   1365
      Left            =   270
      Top             =   150
      Width           =   4155
   End
   Begin VB.Image Image4 
      Height          =   480
      Left            =   3720
      Picture         =   "FCierreZ_Playa.frx":17FC
      Top             =   720
      Width           =   480
   End
   Begin VB.Label lblMensaje 
      Caption         =   "Generando Cierre Z ..."
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   285
      Left            =   1230
      TabIndex        =   8
      Top             =   3900
      Width           =   1995
   End
End
Attribute VB_Name = "FCierreZ_PLaya"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' Se retiraron los Fuentes de la red el 24/04/2003

' Modificacion realizada el 01/08/2003


Dim RS1 As ADODB.Recordset
Dim RS2 As ADODB.Recordset
Dim RS3 As ADODB.Recordset
Dim RS4 As ADODB.Recordset
Dim RS5 As ADODB.Recordset

Dim RS_CARAS_POR_PTOVTA As ADODB.Recordset

Dim Mcon As ADODB.Connection
Dim obj As DB_OP_FACTURACION.C_CIERRE
Private MobjSetup As UTIL_SETUP.C_SETUP
Private MobjVentaPlaya As DB_OP_FACTURACION.C_VENTASPLAYA

Private Sub cmdAceptar_Click()
On Error GoTo TrataError

Screen.MousePointer = 11

Me.Height = 4590
If optPantalla.Value = True Then
    Image1.Visible = True
    Image2.Visible = True
Else
    Image1.Visible = True
    Image3.Visible = True
End If

Animation1.Open "c:\sies\ventas\reportes\" & "Proceso.avi"
Animation1.Visible = True
Animation1.Play

Image1.Refresh
Image2.Refresh
Image3.Refresh
lblMensaje.Refresh

'Verifica las transacciones pendientes
'***************************************
Dim intPendientes As Integer

intPendientes = Ver_Transacciones_Pendientes(RS_CARAS_POR_PTOVTA)

If intPendientes = 0 Then
    Screen.MousePointer = 0
    MDestruye_Objetos
    MsgBox "No se ha Configurado Caras para el Punto de Venta " & lblcaja.Caption, vbExclamation, "Cierre X"
    Exit Sub
End If

If intPendientes = 1 Then
    Screen.MousePointer = 0
    MDestruye_Objetos
    MsgBox "Existen Transacciones pendientes", vbExclamation, "Cierre Z"
    Exit Sub
End If

If intPendientes = 3 Then
    Screen.MousePointer = 0
    MDestruye_Objetos
    MsgBox "Error Inesperedo", vbExclamation, "Cierre Z"
    Exit Sub
End If

'**************************************
Set RS1 = obj.OBTIENERESUMEN_PLAYA_CIERREZ(CDate(lblfecha.Caption), lblcaja.Caption, 1)
Set RS2 = obj.OBTIENERESUMEN_PLAYA_CIERREZ(CDate(lblfecha.Caption), lblcaja.Caption, 2)
Set RS3 = obj.OBTIENERESUMEN_PLAYA_CIERREZ(CDate(lblfecha.Caption), lblcaja.Caption, 3)
Set RS4 = obj.OBTIENERESUMEN_PLAYA_CIERREZ(CDate(lblfecha.Caption), lblcaja.Caption, 4)

Set RS5 = obj.OBTIENECABECERA_PLAYA_CIERREZ(CDate(lblfecha.Caption), lblcaja.Caption)

If optPantalla.Value = True Then

    If RS1.EOF Then
       Animation1.Stop
       MsgBox "No existen Ventas para la Fecha de Proceso " & lblfecha.Caption, vbDefaultButton1 + vbExclamation, "Cierre Z"
       Screen.MousePointer = 0
       MDestruye_Objetos
       Unload Me
       Exit Sub
    End If


    Call GVerCierre(1, 0, Empty, GstrSimboloMonedaBase, GstrSimboloMonedaExt, 40, GintDecResultado, RS5, RS1, RS2, RS3, RS4)
    MDestruye_Objetos
    Screen.MousePointer = 0
    Me.Hide
    MsgBox "Cierre Z generado con éxito", vbInformation, "Cierre Z"
    Unload Me

Else
        
    If RS1.EOF Then
       Animation1.Stop
       MsgBox "No existen Ventas para la Fecha de Proceso " & lblfecha.Caption, vbDefaultButton1 + vbExclamation, "Cierre Z"
       Animation1.Play
       Call obj.Actualizar_Datos_LuegodeCierreZ(lblcaja.Caption, CDate(lblfecha.Caption), RS5!TOTZETA, RS5!NBRZETA)
       Screen.MousePointer = 0
       MDestruye_Objetos
       Unload Me
       Exit Sub
    End If
        
    
    Call obj.Actualizar_Datos_LuegodeCierreZ(lblcaja.Caption, CDate(lblfecha.Caption), RS5!TOTZETA, RS5!NBRZETA)
    Call GImprimeCierre(1, 0, Empty, GstrSimboloMonedaBase, GstrSimboloMonedaExt, 40, GintDecResultado, RS5, RS1, RS2, RS3, RS4)
    
    MDestruye_Objetos
    Screen.MousePointer = 0
    Me.Hide
    MsgBox "Cierre Z generado con éxito", vbInformation, "Cierre Z"
    End

End If
'***************************************

'MDestruye_Objetos

'Screen.MousePointer = 0
    
'    Me.Hide
'    MsgBox "Cierre Z generado con éxito", vbInformation, "Cierre Z"
'    Unload Me


Exit Sub
TrataError:
    Screen.MousePointer = 0
    MDestruye_Objetos
    Me.Hide
    MsgBox Err.Description, vbCritical, "Error Generando Cierre Z"
    Unload Me
End Sub

Private Sub cmdCancelar_Click()
Unload Me
End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 27 Then
    Unload Me
End If
End Sub

Private Sub Form_Load()

    Me.Left = (Screen.Width - Me.Width) / 2
    Me.Top = (Screen.Height - Me.Height) / 2
    Me.Height = 3480
        
    KeyPreview = True
    
    Set MobjVentaPlaya = New DB_OP_FACTURACION.C_VENTASPLAYA
    Set obj = New DB_OP_FACTURACION.C_CIERRE
    Set MobjSetup = New UTIL_SETUP.C_SETUP
    
    lblcaja.Caption = GstrPuntodeVenta
    
    'OBTENGO LAS CARAS CONFIGURADAS AL PUNTO DE VENTAS
    Set RS_CARAS_POR_PTOVTA = New ADODB.Recordset
    Set RS_CARAS_POR_PTOVTA = obj.ObtenerCarasdePtovta(lblcaja.Caption)
    
    'lblfecha.Caption = Format(GDatFechaProcesoVentas, "DD/MM/YYYY")
    lblfecha.Caption = Format(MobjSetup.ObtenerSetupVentas!DATEPROCESALES, "DD/MM/YYYY")
        
    'Establecemos la conexion con GASBOY para ver si existen transacciones pendientes
    
    If GIntVentaAutoCombust = 1 Then
        Set Mcon = New ADODB.Connection
        Mcon.Provider = "MSDASQL"
        Mcon.ConnectionString = Trim(GSTRCADENACONECTA) '"FILEDSN=GASBOY"
        Mcon.Open
    End If
     
End Sub

Private Sub MDestruye_Objetos()
Set RS1 = Nothing
Set RS2 = Nothing
Set RS3 = Nothing
Set RS4 = Nothing
Set RS5 = Nothing
Set obj = Nothing

Image1.Visible = False
Image2.Visible = False
Image3.Visible = False
Animation1.AutoPlay = False
Animation1.Stop
Animation1.Visible = False
Me.Height = 3480

End Sub

Private Function Ver_Transacciones_Pendientes(rsTrans As ADODB.Recordset) As Integer
 
    Dim StrSql As String
    Dim rs As ADODB.Recordset
    
On Error GoTo errhandler
       
        Ver_Transacciones_Pendientes = 2 ' se asume inicialmente todo bien
         
        If GIntVentaAutoCombust = 0 Then
           Ver_Transacciones_Pendientes = 2 ' se asume inicialmente todo bien
           Exit Function
        End If
         
        If Not rsTrans.EOF Then
            While Not rsTrans.EOF
                StrSql = "Select * from ventadia where estado<>'CANCEL'"
                'StrSql = "Select * from tran" & rsTrans!side & " where estado<>'CANCEL'"
                Set rs = New ADODB.Recordset
                
                rs.Open StrSql, Mcon, adOpenStatic
                
                ' si hay alguna transaccion pendiente
                If Not rs.EOF Then
                        ' se procede a verificar transacciones en OP_TRAN
                        If Not obj.Tran_Facturado(rs) Then
                            Ver_Transacciones_Pendientes = 1
                            Exit Function
                        End If
                End If
                
                Set rs = Nothing
                
                rsTrans.MoveNext
            Wend
        Else
            Ver_Transacciones_Pendientes = 0
        End If
        
        Exit Function
    
errhandler:
    Ver_Transacciones_Pendientes = 3
    MsgBox "Error - " & Err.Description, vbCritical, "Error"
End Function

Private Sub Form_Unload(Cancel As Integer)
Set Mcon = Nothing
Set MobjSetup = Nothing
End Sub

Private Sub optImpresora_KeyPress(KeyAscii As Integer)
  If KeyAscii = 13 Then
     cmdAceptar.SetFocus
  End If
End Sub

Private Sub optPantalla_KeyPress(KeyAscii As Integer)
  If KeyAscii = 13 Then
     cmdAceptar.SetFocus
  End If
End Sub

