VERSION 5.00
Begin VB.Form frmAnulaTransaccion_old 
   Caption         =   "Anula Transacción"
   ClientHeight    =   6375
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   5655
   Icon            =   "frmAnulaTransaccion_old.frx":0000
   LinkTopic       =   "Form1"
   ScaleHeight     =   6375
   ScaleWidth      =   5655
   StartUpPosition =   1  'CenterOwner
   Begin VB.CommandButton Command1 
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   360
      Left            =   3525
      Picture         =   "frmAnulaTransaccion_old.frx":08CA
      Style           =   1  'Graphical
      TabIndex        =   6
      Top             =   60
      Width           =   390
   End
   Begin VB.CheckBox chkAlterno 
      Caption         =   "Alterno"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   285
      Left            =   210
      TabIndex        =   5
      Top             =   525
      Width           =   2205
   End
   Begin VB.CommandButton cmdSalir 
      Cancel          =   -1  'True
      Caption         =   "&Salir"
      Height          =   435
      Left            =   2910
      TabIndex        =   4
      Top             =   5805
      Width           =   1185
   End
   Begin VB.CommandButton cmdAnular 
      Caption         =   "&Anular"
      Height          =   435
      Left            =   1320
      TabIndex        =   3
      Top             =   5805
      Width           =   1185
   End
   Begin VB.TextBox txtTexto 
      Appearance      =   0  'Flat
      BeginProperty Font 
         Name            =   "Courier New"
         Size            =   9.75
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   4710
      Left            =   165
      Locked          =   -1  'True
      MultiLine       =   -1  'True
      ScrollBars      =   2  'Vertical
      TabIndex        =   2
      Top             =   900
      Width           =   5310
   End
   Begin VB.TextBox txtTransaccion 
      Alignment       =   2  'Center
      BeginProperty Font 
         Name            =   "Courier New"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   360
      Left            =   1605
      MaxLength       =   6
      TabIndex        =   1
      Top             =   75
      Width           =   1920
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "Transacción:"
      BeginProperty Font 
         Name            =   "Courier New"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   240
      Left            =   165
      TabIndex        =   0
      Top             =   135
      Width           =   1440
   End
End
Attribute VB_Name = "frmAnulaTransaccion_old"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Dim iTipoVenta As Integer '1:Normal 2:Voucher 3:Dolares 4:Transaccion Anulada
Dim nTipoCambio As Double
Dim dFechaOperacion As Date
Dim Producto() As tProducto 'Almacena los datos de cada producto que se va registrando
Dim nProducto As Long 'Cantidad de productos por transaccion
Dim sTarjeta As String 'Tarjeta del Cliente
Dim sUsuario As String 'Usuario que registor transaccion
Dim sTexto0 As String 'Bloques para la impresion
Dim sTexto1 As String 'Bloques para la impresion
Dim sTexto2 As String 'Bloques para la impresion
Dim sTexto3 As String 'Bloques para la impresion

Dim iEfectivo As Double, iVuelto As Double
Public bAcceso As Boolean

Private Sub chkAlterno_Click()
  Buscar
End Sub

Private Sub cmdAnular_Click()
  On Error GoTo LineaError
  
  Dim sFecha As String, sTexto As String
  Dim iCodOper As Long
  Dim iSigno As Integer
  Dim ssql As String
  Dim ADORS As ADODB.Recordset
  Dim i As Long
  Dim iTransaccion As Long
  
  If Not IsNumeric(txtTransaccion.Text) Then GoTo Salir
  iTransaccion = CLng(txtTransaccion.Text)
  
  bAcceso = False
  Load frmAutorizarOperacion
  Set frmAutorizarOperacion.frmPadre = Me
  frmAutorizarOperacion.Show vbModal
  If Not bAcceso Then Exit Sub
  'bAcceso = False
  
  If chkAlterno.Value = 0 Then
    ssql = " SELECT count(*) as TOTAL" & _
           " FROM Operacion" & _
           " WHERE cOperCodeAnula =$" & _
           " AND cOperFlagAbierto = 1"
           
    ssql = VBsprintf(ssql, CStr(iTransaccion))

    If Not oDBAdmin.EjecutarConsulta(ADOCnn, ssql, ADORS) Then GoTo Salir
  
    If LeerCampo(ADORS("Total")) <> 0 Then
      MsgBox "Este transacción ya ha sido anulada"
      txtTransaccion.SetFocus
      GoTo Salir
    End If
  End If
  '------------------------
  '-- Registra Anulacion --
  '------------------------
  If chkAlterno.Value = 0 Then
    ssql = " SELECT MAX(cOperCode) AS maximo FROM Operacion"
  Else
    ssql = " SELECT MAX(cOperCode) AS maximo FROM OperacionParalela"
  End If
  
  If Not oDBAdmin.EjecutarConsulta(ADOCnn, ssql, ADORS) Then GoTo Salir
  
  If ADORS.RecordCount = 1 Then
    If IsNull(ADORS("maximo")) Then
      iCodOper = 1
    Else
      iCodOper = LeerCampo(ADORS("maximo")) + 1
    End If
  End If
  sFecha = Format(Now(), "DD/MM/YYYY hh:mm")
  Set ADORS = Nothing
  
  iSigno = -1
  
  If chkAlterno.Value = 0 Then
   
    For i = 1 To nProducto
      ssql = "INSERT INTO OPERACION (cOperCode, cUserDesc, cAlmaCode, cProdCode, nProdCant, nProdPrecUnit," & _
                                    " dOperFech, cOperTipo, cOperFlagAnula, cOperCodeAnula, cCajaCodi, cTurnoCodi) " + _
             "VALUES" + _
             "($, '$', $, $, $, '$', '$', $, $, '$', '$', '$')"
      ssql = VBsprintf(ssql, CStr(iCodOper), psUsuario_Descripcion, Producto(i).Almacen, CStr(Producto(i).Codigo), CStr(Producto(i).Cant * iSigno), _
                             CStr(Producto(i).PUnit), sFecha, CStr(iTipoVenta), "1", CStr(CLng(txtTransaccion.Text)), kPAR_CAJA, kPAR_TURNO)
      If Not oDBAdmin.EjecutarSentencia(ADOCnn, ssql) Then GoTo Salir
    Next
  Else
    ssql = " INSERT INTO OPERACIONPARALELA (cOperCode, cOperTipo, dOperFech, " & _
           " sGlosa, cEstado, cCajaCodi, cTurnoCodi, cUserDesc)" & _
           " VALUES" & _
           " ($, $, '$', '$', '$', '$', '$', '$')"
    ssql = VBsprintf(ssql, CStr(iCodOper), CStr(iTipoVenta), sFecha, "ANULACION", CStr(0), _
           kPAR_CAJA, kPAR_TURNO, psUsuario_Descripcion)
    If Not oDBAdmin.EjecutarSentencia(ADOCnn, ssql) Then GoTo Salir
    
    ssql = " UPDATE OPERACIONPARALELA" & _
           " SET cEstado = '0'," & _
           " cOpercodeAnul = $" & _
           " WHERE cOperCode = $"
           
    ssql = VBsprintf(ssql, CStr(iCodOper), CStr(iTransaccion))
    If Not oDBAdmin.EjecutarSentencia(ADOCnn, ssql) Then GoTo Salir
  End If
  
  '---------------------
  '-- Imprime Voucher --
  '---------------------
  Select Case iTipoVenta
    Case 20, 21, 22, 23, 24
      ConfiguraImpresora kPAR_IMPRESORA_ALTERNA
    Case Else
      ConfiguraImpresora kPAR_IMPRESORA
  End Select
  
  Printer.FontSize = 8 ' 11
  Printer.FontName = "Courier New"
  Printer.FontBold = False
  Printer.Print sTexto0
  
  sTexto = "      " + Format(CStr(Now()), "DD/MM/YYYY (DDD)") + vbCrLf
  sTexto = sTexto + Right("              " + "TRANSACCION ANULADA", Int(Len("TRANSACCION ANULADA") / 2) + 14) + vbCrLf
  Printer.FontBold = False
  Printer.Print sTexto
  
  Printer.FontBold = False
  Printer.Print sTexto1
  
  Printer.FontSize = 9 '12
  Printer.FontBold = True
  Printer.Print sTexto2
  
  Printer.FontSize = 8 '11
  Printer.FontBold = False
  Printer.Print sTexto3
  
  Printer.FontBold = False
  sTexto = vbCrLf + Right("              " + "TRANSACCION ANULADA", Int(Len("TRANSACCION ANULADA") / 2) + 14) '+ vbCrLf
  Printer.Print sTexto
  
  sTexto = " " + Left(psUsuario_Descripcion, 10) + " " 'Usuario: 10 + 1
  sTexto = sTexto + Format(CStr(Now()), "hh:mm") + " " 'Hora: 6 + 1
  sTexto = sTexto + Right("000000" + CStr(iCodOper), 6) 'Codigo Transaccion: 6
  sTexto = sTexto + vbCrLf + "CAJA: " + kPAR_CAJA + "   TURNO: " + kPAR_TURNO
  Printer.Print sTexto
  Printer.EndDoc
   
  GoTo Salir
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  Screen.MousePointer = vbDefault

Salir:
  Set ADORS = Nothing
End Sub

Private Sub cmdSalir_Click()
  Unload Me
End Sub

Private Sub Command1_Click()
  Buscar
End Sub

Private Sub txtTransaccion_KeyPress(KeyAscii As Integer)
  On Error GoTo LineaError
  Call ValidKeyPress(KeyAscii, kVKP_NUMERIC_INTEGER_ONLY)
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
End Sub

Private Sub Buscar()
 ' On Error GoTo LineaError
  
  Dim ssql As String
  Dim ADORS As ADODB.Recordset
  Dim i As Long, j As Long
  Dim iTransaccion As Long
  
  If Not IsNumeric(txtTransaccion.Text) Then GoTo Salir
  iTransaccion = CLng(txtTransaccion.Text)
  
  If chkAlterno.Value = 0 Then
    'Normal
    ssql = " SELECT count(*) as TOTAL" & _
           " FROM Operacion" & _
           " WHERE cOperCodeAnula =$" & _
           " AND cOperFlagAbierto = 1"
  Else
    'Alterno
    ssql = " SELECT count(*) as TOTAL" & _
           " FROM OperacionParalela" & _
           " WHERE cOperCode =$" & _
           " AND cEstado = '0'"
  End If
  
  ssql = VBsprintf(ssql, CStr(iTransaccion))
  If Not oDBAdmin.EjecutarConsulta(ADOCnn, ssql, ADORS) Then GoTo Salir
  
  If LeerCampo(ADORS("Total")) <> 0 Then
    MsgBox "Este transacción ya ha sido anulada"
    GoTo Salir
  End If
  
  If chkAlterno.Value = 0 Then
    'Normal
    ssql = " SELECT O.cOperCode, O.cUserDesc, O.nTarjNumb, O.cProdCode, O.cAlmaCode, O.nProdCant, O.nProdPrecUnit," & _
           " O.dOperFech, O.cOperTipo, O.cOperFlagAnula, P.sProdDesc, P.sProdDescCrta, 0 AS nDscto, O.nServicio" & _
           " FROM Operacion AS O INNER JOIN Producto AS P ON O.cProdCode = P.cProdCode and O.cAlmaCode = P.cAlmaCode" & _
           " WHERE O.cOperCode =$ AND O.cOperFlagAbierto = 1 ORDER BY O.cOperID"
  Else
    'Alterno
    ssql = " SELECT O.cOperCode, O.cUserDesc, O.nTarjNumb, O.dOperFech, O.cOperTipo," & _
           " O.cOperCodeRela, O.nVueltoSoles, O.nEfectivoSoles, B.cAlmaCode, B.cProdCode, B.nProdCant," & _
           " B.nProdPrecUnit, B.nDscto, B.sProdDescCrta, B.nServicio" & _
           " FROM OperacionParalela AS O LEFT JOIN" & _
           " (SELECT A.cOperCode, A.cProdCode, A.nProdCant, A.nProdPrecUnit, A.nDscto," & _
           " P.sProdDescCrta, A.cAlmaCode, A.nServicio FROM OperacionParalelaProducto as A INNER JOIN Producto AS P" & _
           " ON A.cProdCode = P.cProdCode AND A.cAlmaCode = P.cAlmaCode) AS B ON O.cOperCode = B.cOperCode" & _
           " WHERE O.cOperCode = $ AND O.cEstado IN ('1')"
  End If
  
  ssql = VBsprintf(ssql, CStr(iTransaccion))

  If Not oDBAdmin.EjecutarConsulta(ADOCnn, ssql, ADORS) Then GoTo Salir
  
  If ADORS.RecordCount < 1 Then
    MsgBox "El número de transacción no existe o ya ha sido cerrada."
    GoTo Salir
  End If
  
  If chkAlterno.Value = 0 Then
    'Normal
    If LeerCampo(ADORS("cOperFlagAnula")) <> "0" Then
      MsgBox "Esta es una transacción de anulación. No puede ser anulada"
      GoTo Salir
    End If
    If LeerCampo(ADORS("cOperTipo")) <> "1" And LeerCampo(ADORS("cOperTipo")) <> "2" And _
      LeerCampo(ADORS("cOperTipo")) <> "3" Then
      MsgBox "No es una transacción de venta."
      GoTo Salir
    End If
  Else
    'Alterno
    iVuelto = LeerCampo(ADORS("nVueltoSoles"))
    iEfectivo = LeerCampo(ADORS("nEfectivoSoles"))
    
    If LeerCampo(ADORS("cOperTipo")) = 24 Then
      MsgBox "Esta es una transacción de liquidación. No puede ser anulada"
      GoTo Salir
    End If
  End If
  
  nProducto = ADORS.RecordCount
  iTipoVenta = LeerCampo(ADORS("cOperTipo"))
  dFechaOperacion = LeerCampo(ADORS("dOperFech"))
  sTarjeta = LeerCampo(ADORS("nTarjNumb"))
  sUsuario = LeerCampo(ADORS("cUserDesc"))
  
  
  ReDim Producto(nProducto)
  i = 1
  Do While Not ADORS.EOF
    Producto(i).Almacen = LeerCampo(ADORS("cAlmaCode"))
    Producto(i).Codigo = IIf(LeerCampo(ADORS("cProdCode")) = "", 0, LeerCampo(ADORS("cProdCode")))
    Producto(i).nombre = LeerCampo(ADORS("sProdDescCrta"))
    Producto(i).Cant = IIf(LeerCampo(ADORS("nProdCant")) = "", 0, LeerCampo(ADORS("nProdCant")))
    Producto(i).PUnit = IIf(LeerCampo(ADORS("nProdPrecUnit")) = "", 0, LeerCampo(ADORS("nProdPrecUnit")))
    Producto(i).Dscto = IIf(LeerCampo(ADORS("nDscto")) = "", 0, LeerCampo(ADORS("nDscto")))
    Producto(i).Serv = LeerCampo(ADORS("nServicio"))
    ADORS.MoveNext
    i = i + 1
  Loop
  
  Call CapturaTipoCambio
  Call MuestraTransaccion
  
  GoTo Salir
  
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  Screen.MousePointer = vbDefault

Salir:
  Set ADORS = Nothing
End Sub

Sub MuestraTransaccion()
  On Error GoTo LineaError
  Dim rsNC As ADODB.Recordset, ADORS As ADODB.Recordset
  Dim iTotal As Double, iSubTotal As Double, iTotItems As Double, iDscto As Double
  Dim iPagoAdelantado As Double, iSubTotalDscto As Double, iTotalDscto As Double, iServicio As Double
  Dim i As Integer
  Dim sFecha As String
  Dim sTexto As String
  Dim iSigno As Integer
  Dim iFlagTipo As Integer
  Dim ssql As String
  Dim iTransaccion As Long
  
  sTexto0 = ""
  sTexto1 = ""
  sTexto2 = ""
  sTexto3 = ""
    
  iTransaccion = Replace(txtTransaccion.Text, ",", "")
    
  Call CabeceraImpresion
    
  For i = 0 To UBound(sCabecera) - 1
    If Not Trim(sCabecera(i)) = "" Then
        sTexto0 = sTexto0 + Right("  " + sCabecera(i), Int(Len(sCabecera(i)) / 2) + 23) + vbCrLf
    End If
  Next
  'sTexto0 = sTexto0 + vbCrLf
        
  sTexto1 = sTexto1 + "            " + Format(CStr(dFechaOperacion), "DD/MM/YYYY (DDD)") + vbCrLf
    
  'Cabecera segun tipo de venta
  Select Case iTipoVenta
    Case 2 'Voucher
      sTexto = "VOUCHER"
      sTexto = Right("                  " + sTexto, Int(Len(sTexto) / 2) + 20) + vbCrLf
    Case 3 'Dolares
      sTexto = "U$(TC: " + Format(CStr(nTipoCambio), "###,##0.00") + ")"
      sTexto = Right("                 " + sTexto, Int(Len(sTexto) / 2) + 20) + vbCrLf
    Case 20 'O/C
      sTexto = "O/C"
      sTexto = Right("                  " + sTexto, Int(Len(sTexto) / 2) + 20)
    Case 21 'O/C
      sTexto = "N/C"
      sTexto = Right("                  " + sTexto, Int(Len(sTexto) / 2) + 20)
    Case 22 'O/C
      sTexto = "PADE"
      sTexto = Right("                  " + sTexto, Int(Len(sTexto) / 2) + 20)
    Case 23 'O/C
      sTexto = "PADV"
      sTexto = Right("                  " + sTexto, Int(Len(sTexto) / 2) + 20)
    Case 24 'O/C
      sTexto = "LIQPAD"
      sTexto = Right("                  " + sTexto, Int(Len(sTexto) / 2) + 20)
  End Select
  
  sTexto1 = sTexto1 + sTexto + vbCrLf
    
  iSubTotal = 0
  iTotal = 0
  iTotItems = 0
  sTexto = ""
  
  If iTipoVenta = 22 Or iTipoVenta = 23 Or iTipoVenta = 24 Then
    'Detalle de los N/C relacionados
    Dim iOperNC As Long
    Dim nSubtotal As Double
    Dim nItems As Long
    Dim nPrecUnit As Long
    'Dim nItems As Long
    Dim sProdDescCrta As String
    Dim nDscto As Double
    Dim sTeclDesc As String
    
    If iTipoVenta = 24 Then
      iTotal = 0
      iTotItems = 0
      
      ssql = " SELECT SUM(nMontoSoles) as Adelantado FROM OperacionParalela" & _
             " Where cOperCodeRela = $"
      ssql = VBsprintf(ssql, CStr(iTransaccion))
      If Not oDBAdmin.EjecutarConsulta(ADOCnn, ssql, ADORS) Then GoTo Salir
    
      iPagoAdelantado = LeerCampo(ADORS("Adelantado"))
      
      ssql = " SELECT cOperCode FROM OperacionParalela WHERE cOperCodeRela = " & CStr(iTransaccion) & " AND cEstado <> '0' AND cOperTipo = 21"
      ssql = ssql & " UNION SELECT cOperCode FROM OperacionParalela WHERE cEstado <> '0' AND cOperTipo = 21" & _
             " AND cOperCodeRela IN (SELECT cOperCode FROM OperacionParalela WHERE cOperCodeRela = " & CStr(iTransaccion) & _
             " AND cEstado <> '0' AND cOperTipo IN (22, 23)) "
      If Not oDBAdmin.EjecutarConsulta(ADOCnn, ssql, rsNC) Then GoTo Salir
      
      Do While Not rsNC.EOF
        ssql = " SELECT O.cOperCode, O.cProdCode, O.nProdCant, O.nProdPrecUnit, O.nDscto, P.sProdDescCrta," & _
               " O.nProdCant * O.nProdPrecUnit * (100 - O.nDscto) / 100 As TotalMonto," & _
               " c.cTeclCode , c.sTeclDesc FROM OperacionParalelaProducto O INNER JOIN" & _
               " (Producto P LEFT JOIN ConfiguracionTeclado AS C ON P.cProdCode = C.cProdCode)" & _
               " ON O.cProdCode = P.cProdCode AND O.cAlmaCode = P.cAlmaCode" & _
               " Where cOperCode = " + CStr(LeerCampo(rsNC("cOperCode")))
  
        If Not oDBAdmin.EjecutarConsulta(ADOCnn, ssql, ADORS) Then GoTo Salir
  
        nSubtotal = 0
        sTexto = sTexto + "---------------------------" + vbCrLf
        sTexto = sTexto + "TX" + CStr(LeerCampo(rsNC("cOperCode"))) + vbCrLf
        Do While Not ADORS.EOF
          nItems = LeerCampo(ADORS("nProdCant"))
          nPrecUnit = LeerCampo(ADORS("nProdPrecUnit"))
          sProdDescCrta = LeerCampo(ADORS("sProdDescCrta"))
          nDscto = LeerCampo(ADORS("nDscto"))
          sTeclDesc = IIf(LeerCampo(ADORS("sTeclDesc")) = "", "---", LeerCampo(ADORS("sTeclDesc")))
          
          sTexto = sTexto + Left(sTeclDesc + "          ", 10) + Right("                 @" + Format(CStr(nPrecUnit), "###,###,##0.00"), 17) + vbCrLf
          sTexto = sTexto + Left(sProdDescCrta + "          ", 10) + Right("                 *" + Format(CStr(nItems), "###,###,##0.00"), 17) + vbCrLf
          sTexto = sTexto + Left("%Dscto          ", 10) + Right("                 *" + Format(CStr(nDscto), "###,###,##0.00"), 17) + vbCrLf
        
          nSubtotal = nSubtotal + LeerCampo(ADORS("TotalMonto"))
          ADORS.MoveNext
        Loop
        sTexto = sTexto + "  AV./ITEM" + Right("                 *" + Format(CStr(nSubtotal), "###,###,##0.00"), 17) + vbCrLf
        
        iTotal = iTotal + nSubtotal
        iTotItems = iTotItems + nItems
        
        rsNC.MoveNext
      Loop
    ElseIf iTipoVenta = 22 Or iTipoVenta = 23 Then
      ssql = " SELECT nMontoSoles FROM OperacionParalela" & _
             " Where cOperCode = $"
      ssql = VBsprintf(ssql, CStr(iTransaccion))
      If Not oDBAdmin.EjecutarConsulta(ADOCnn, ssql, ADORS) Then GoTo Salir
    
      iTotal = LeerCampo(ADORS("nMontoSoles"))
    End If
      '----------------------------
          
  Else
    For i = 1 To nProducto
      iSubTotal = Producto(i).Cant * Producto(i).PUnit
      sTexto = sTexto + Right("000" + CStr(Producto(i).Cant), 3) + " "  'Cant de productos: 3 + 1
      sTexto = sTexto + Left(Producto(i).nombre + "          ", 10) + " " ' Descripcion corta del producto: 10 + 1
      sTexto = sTexto + Right("          *" + Format(CStr(iSubTotal), "###,##0.00"), 11) + vbCrLf 'SubTotal 1 + 11
      iTotal = iTotal + iSubTotal
      iTotItems = iTotItems + Producto(i).Cant
    
      'Descuentos por O/C
      If iTipoVenta = 20 Then
        iDscto = Producto(i).Dscto
        iSubTotalDscto = Producto(i).Cant * Producto(i).PUnit * (100 - iDscto) / 100
        If Producto(i).Dscto <> 0 Then
          sTexto = sTexto + "   " + " "  'Cant de productos: 3 + 1
          sTexto = sTexto + Left("%Dscto          ", 10) + " " ' Descripcion corta del producto: 10 + 1
          sTexto = sTexto + Right("          *" + Format(CStr(iDscto), "###,##0.00"), 11) + vbCrLf 'SubTotal 1 + 11
        End If
        iTotalDscto = iTotalDscto + iSubTotalDscto
      Else
        iServicio = iServicio + (Producto(i).PUnit * Producto(i).Cant * (IIf(Producto(i).Serv <> "0", Val(Producto(i).Serv), 0)) / 100)
      End If
    Next
  End If
  'Añade el % de servicio al total
  iTotal = iTotal + iServicio
  
  If iServicio <> 0 Then sTexto = sTexto + "  %SERVICIO" + Right("              *" + Format(CStr(iServicio), "###,###,##0.00"), 15) + vbCrLf
       
  sTexto = sTexto + "--------------------------"
  sTexto1 = sTexto1 + sTexto
  sTexto = ""
  
  '--------------------------------
  'For i = 1 To nProducto
  '  iSubTotal = Producto(i).Cant * Producto(i).PUnit
  '  sTexto = sTexto + Right("000" + CStr(Producto(i).Cant), 3) + " "  'Cant de productos: 3 + 1
  '  sTexto = sTexto + Left(Producto(i).Nombre + "          ", 10) + " " ' Descripcion corta del producto: 10 + 1
  '  sTexto = sTexto + Right("          *" + Format(CStr(iSubTotal), "###,##0.00"), 11) + vbCrLf 'SubTotal 1 + 11
  '  iTotal = iTotal + iSubTotal
  '  iTotItems = iTotItems + Producto(i).Cant
  'Next
    
  'sTexto = sTexto + "--------------------------"
  'sTexto1 = sTexto1 + sTexto
  
  'sTexto = ""
  
  'Total segun tipo de venta
  Select Case iTipoVenta
    Case 1, 2 'Normal, Voucher
      sTexto = "CASH/TL  " + Right("              *" + Format(CStr(iTotal), "###,###,##0.00"), 15)
    Case 3 'Dolares
      sTexto = "CASH/TL  " + Right("              *" + Format(CStr(iTotal), "###,###,##0.00"), 15) + vbCrLf
      sTexto = sTexto + "CASH/TL(U$)" + Right("             *" + Format(CStr(iTotal / nTipoCambio), "###,###,##0.00"), 13)
    Case 4 'Anula Productos
      sTexto = "CASH/TL  " + Right("              *" + Format(CStr(iTotal), "###,###,##0.00"), 15)
    Case 20 'O/C
      If iVuelto <> 0 Then
        sTexto = "SUB/TOTL " + Right("              *" + Format(CStr(iTotalDscto), "###,###,##0.00"), 15) + vbCrLf
        sTexto = sTexto + "EFECTIVO " + Right("             *" + Format(CStr(iEfectivo), "###,###,##0.00"), 15) + vbCrLf
        sTexto = sTexto + "VUELTO   " + Right("             *" + Format(CStr(iVuelto), "###,###,##0.00"), 15)
      Else
        sTexto = "CASH/TL  " + Right("              *" + Format(CStr(iTotalDscto), "###,###,##0.00"), 15)
      End If
    Case 21 'N/C
      sTexto = "CASH/TL  " + Right("              *" + Format(CStr(iTotal), "###,###,##0.00"), 15)
    Case 22 'PADE
      sTexto = "CASH/TL  " + Right("              *" + Format(CStr(iTotal), "###,###,##0.00"), 15)
    Case 23 'PADV
      sTexto = "CASH/TL  " + Right("              *" + Format(CStr(iTotal), "###,###,##0.00"), 15)
    Case 24 'LIQPAD
      sTexto = "SUB/TOTL " + Right("              *" + Format(CStr(iTotal), "###,###,##0.00"), 15) + vbCrLf
      sTexto = sTexto + "PADE/PADV " + Right("              *" + Format(iPagoAdelantado, "###,###,##0.00"), 14) + vbCrLf
      sTexto = sTexto + "TOT-PAGAR " + Right("              *" + Format(iPagoAdelantado - iTotal, "###,###,##0.00"), 14) + vbCrLf
      sTexto = sTexto + "EFECTIVO " + Right("             *" + Format(CStr(iEfectivo), "###,###,##0.00"), 15) + vbCrLf
      sTexto = sTexto + "VUELTO   " + Right("             *" + Format(CStr(iVuelto), "###,###,##0.00"), 15)
  End Select
  
  sTexto2 = sTexto2 + sTexto
    
  sTexto = "   ITEM  " + Right("              *" + Format(CStr(iTotItems), "###,##0.00"), 15)
    
  sTexto2 = sTexto2 + vbCrLf + sTexto + vbCrLf
    
  sTexto = ""
  sTexto = sTexto + "           " + Left(sUsuario, 10) + " " 'Usuario: 10 + 1
  sTexto = sTexto + Format(CStr(dFechaOperacion), "hh:mm") + " " 'Hora: 6 + 1
  sTexto = sTexto + Right("000000" + CStr(txtTransaccion.Text), 6) 'Codigo Transaccion: 6
  sTexto3 = sTexto3 + sTexto
  
  txtTexto.Text = sTexto0 + vbCrLf + sTexto1 + vbCrLf + sTexto2 + vbCrLf + sTexto3
  
  If iTipoVenta = 3 Then iTipoVenta = 1
  
  GoTo Salir
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  Screen.MousePointer = vbDefault

Salir:
End Sub

Sub CapturaTipoCambio()
  On Error GoTo LineaError
  Dim ssql As String
  Dim ADORS As ADODB.Recordset
  
  'Captura el tipo de cambio
  ssql = " SELECT nTipoCambMont FROM Tipo_Cambio" & _
         " WHERE FORMAT(dTipoCambFech, 'yyyy/mm/dd') = '" & Format(CStr(dFechaOperacion), "yyyy/mm/dd") & "'"

  If Not oDBAdmin.EjecutarConsulta(ADOCnn, ssql, ADORS) Then GoTo Salir
  If ADORS.RecordCount <> 1 Then
    MsgBox "Para registrar ventas en dólares debe registrar el tipo de cambio"
  Else
    nTipoCambio = LeerCampo(ADORS("nTipoCambMont"))
  End If
  
  Screen.MousePointer = vbDefault
  
  GoTo Salir
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  Screen.MousePointer = vbDefault

Salir:
  Set ADORS = Nothing
End Sub

Private Sub txtTransaccion_LostFocus()
  Buscar
End Sub
