VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Object = "{F0D2F211-CCB0-11D0-A316-00AA00688B10}#1.0#0"; "msdatlst.ocx"
Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
Object = "{BDC217C8-ED16-11CD-956C-0000C04E4C0A}#1.1#0"; "tabctl32.ocx"
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "msdatgrd.ocx"
Object = "{0D6234D1-DBA2-11D1-B5DF-0060976089D0}#6.0#0"; "todg6.ocx"
Begin VB.Form frmCajaFacturacionPagos 
   Caption         =   "Modulo de Venta Futura"
   ClientHeight    =   8685
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   13725
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form3"
   MaxButton       =   0   'False
   ScaleHeight     =   8685
   ScaleWidth      =   13725
   StartUpPosition =   3  'Windows Default
   Begin TabDlg.SSTab SSTab1 
      Height          =   8535
      Left            =   0
      TabIndex        =   0
      Top             =   120
      Width           =   13695
      _ExtentX        =   24156
      _ExtentY        =   15055
      _Version        =   393216
      Tabs            =   4
      TabsPerRow      =   4
      TabHeight       =   520
      TabCaption(0)   =   "Facturacion"
      TabPicture(0)   =   "frmCajaFacturacionPagos.frx":0000
      Tab(0).ControlEnabled=   -1  'True
      Tab(0).Control(0)=   "fraTotal"
      Tab(0).Control(0).Enabled=   0   'False
      Tab(0).Control(1)=   "Frame5"
      Tab(0).Control(1).Enabled=   0   'False
      Tab(0).Control(2)=   "Frame1"
      Tab(0).Control(2).Enabled=   0   'False
      Tab(0).Control(3)=   "Frame2"
      Tab(0).Control(3).Enabled=   0   'False
      Tab(0).Control(4)=   "cmdGrabarFactura"
      Tab(0).Control(4).Enabled=   0   'False
      Tab(0).Control(5)=   "cmdSalir"
      Tab(0).Control(5).Enabled=   0   'False
      Tab(0).Control(6)=   "Frame3"
      Tab(0).Control(6).Enabled=   0   'False
      Tab(0).Control(7)=   "txtsupervisor"
      Tab(0).Control(7).Enabled=   0   'False
      Tab(0).Control(8)=   "txtEfectivoDolares"
      Tab(0).Control(8).Enabled=   0   'False
      Tab(0).Control(9)=   "txtEfectivoSoles"
      Tab(0).Control(9).Enabled=   0   'False
      Tab(0).ControlCount=   10
      TabCaption(1)   =   "Pagos a Cuenta"
      TabPicture(1)   =   "frmCajaFacturacionPagos.frx":001C
      Tab(1).ControlEnabled=   0   'False
      Tab(1).Control(0)=   "Frame4"
      Tab(1).Control(1)=   "FraRegistroPago"
      Tab(1).Control(2)=   "Frame9"
      Tab(1).ControlCount=   3
      TabCaption(2)   =   "Nota de Consumo"
      TabPicture(2)   =   "frmCajaFacturacionPagos.frx":0038
      Tab(2).ControlEnabled=   0   'False
      Tab(2).Control(0)=   "Frame6"
      Tab(2).Control(1)=   "Frame7"
      Tab(2).Control(2)=   "Frame11"
      Tab(2).Control(3)=   "cmdGrabarNC"
      Tab(2).Control(4)=   "Command3"
      Tab(2).Control(5)=   "txtTX"
      Tab(2).Control(6)=   "txtVueltoSoles"
      Tab(2).Control(7)=   "txtVueltoDolares"
      Tab(2).ControlCount=   8
      TabCaption(3)   =   "Liquidacion"
      TabPicture(3)   =   "frmCajaFacturacionPagos.frx":0054
      Tab(3).ControlEnabled=   0   'False
      Tab(3).Control(0)=   "Label47"
      Tab(3).Control(1)=   "Frame12"
      Tab(3).Control(2)=   "Frame13"
      Tab(3).Control(3)=   "frmVuelto"
      Tab(3).Control(4)=   "Frame14"
      Tab(3).Control(5)=   "Command1"
      Tab(3).Control(6)=   "cmdGrabaLiq"
      Tab(3).Control(7)=   "cboTipoDocumento3"
      Tab(3).Control(8)=   "txtLiq"
      Tab(3).Control(9)=   "txtliqvueltodolares"
      Tab(3).Control(10)=   "txtliqvueltosoles"
      Tab(3).Control(11)=   "txtliqefectivosoles"
      Tab(3).Control(12)=   "txtliqefectivodolares"
      Tab(3).Control(13)=   "txtliqpade"
      Tab(3).ControlCount=   14
      Begin VB.TextBox txtliqpade 
         Height          =   465
         Left            =   -70440
         TabIndex        =   166
         Top             =   6960
         Visible         =   0   'False
         Width           =   2100
      End
      Begin VB.TextBox txtliqefectivodolares 
         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            =   -74400
         MaxLength       =   6
         TabIndex        =   165
         Top             =   7200
         Visible         =   0   'False
         Width           =   1230
      End
      Begin VB.TextBox txtliqefectivosoles 
         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            =   -74400
         MaxLength       =   6
         TabIndex        =   164
         Top             =   7680
         Visible         =   0   'False
         Width           =   1230
      End
      Begin VB.TextBox txtliqvueltosoles 
         Height          =   375
         Left            =   -67560
         TabIndex        =   163
         Top             =   6960
         Visible         =   0   'False
         Width           =   1695
      End
      Begin VB.TextBox txtliqvueltodolares 
         Height          =   285
         Left            =   -67560
         TabIndex        =   162
         Top             =   7560
         Visible         =   0   'False
         Width           =   1695
      End
      Begin VB.TextBox txtLiq 
         Height          =   375
         Left            =   -69240
         TabIndex        =   161
         Top             =   7680
         Visible         =   0   'False
         Width           =   1095
      End
      Begin VB.ComboBox cboTipoDocumento3 
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   9.75
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00800000&
         Height          =   360
         ItemData        =   "frmCajaFacturacionPagos.frx":0070
         Left            =   -69240
         List            =   "frmCajaFacturacionPagos.frx":0072
         Style           =   2  'Dropdown List
         TabIndex        =   159
         Top             =   600
         Width           =   2775
      End
      Begin VB.CommandButton cmdGrabaLiq 
         Caption         =   "&Grabar"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   15.75
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   735
         Left            =   -73200
         TabIndex        =   158
         Top             =   7200
         Width           =   2295
      End
      Begin VB.CommandButton Command1 
         Caption         =   "&Salir"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   15.75
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   735
         Left            =   -65040
         TabIndex        =   157
         Top             =   7320
         Width           =   2295
      End
      Begin VB.Frame Frame14 
         Height          =   1575
         Left            =   -66720
         TabIndex        =   152
         Top             =   5280
         Width           =   4695
         Begin VB.TextBox txtDolaresLQ 
            Alignment       =   1  'Right Justify
            Appearance      =   0  'Flat
            BackColor       =   &H8000000F&
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   20.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   615
            Left            =   1080
            Locked          =   -1  'True
            TabIndex        =   154
            TabStop         =   0   'False
            Text            =   "0.00"
            Top             =   870
            Width           =   3375
         End
         Begin VB.TextBox txtSolesLQ 
            Alignment       =   1  'Right Justify
            Appearance      =   0  'Flat
            BackColor       =   &H8000000F&
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   20.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   615
            Left            =   1080
            Locked          =   -1  'True
            TabIndex        =   153
            TabStop         =   0   'False
            Text            =   "0.00"
            Top             =   165
            Width           =   3375
         End
         Begin VB.Label Label46 
            AutoSize        =   -1  'True
            Caption         =   "U$"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   20.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   495
            Left            =   360
            TabIndex        =   156
            Top             =   915
            Width           =   555
         End
         Begin VB.Label Label45 
            AutoSize        =   -1  'True
            Caption         =   "S/."
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   20.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   495
            Left            =   360
            TabIndex        =   155
            Top             =   225
            Width           =   615
         End
      End
      Begin VB.Frame frmVuelto 
         Height          =   1605
         Left            =   -73920
         TabIndex        =   143
         Top             =   5280
         Visible         =   0   'False
         Width           =   6945
         Begin VB.TextBox txtEfectivoSolesLQ 
            Alignment       =   1  'Right Justify
            BackColor       =   &H00FFFFFF&
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   14.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   465
            Left            =   1680
            Locked          =   -1  'True
            TabIndex        =   147
            Text            =   "0.00"
            Top             =   555
            Width           =   2415
         End
         Begin VB.TextBox txtVueltoSolesLQ 
            Alignment       =   1  'Right Justify
            BackColor       =   &H80000018&
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   14.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   465
            Left            =   1620
            Locked          =   -1  'True
            TabIndex        =   146
            TabStop         =   0   'False
            Text            =   "0.00"
            Top             =   1065
            Width           =   2415
         End
         Begin VB.TextBox txtVueltoDolaresLQ 
            Alignment       =   1  'Right Justify
            BackColor       =   &H00FFFFFF&
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   14.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   465
            Left            =   4080
            TabIndex        =   145
            Text            =   "0.00"
            Top             =   1050
            Width           =   2415
         End
         Begin VB.TextBox txtEfectivoDolaresLQ 
            Alignment       =   1  'Right Justify
            BackColor       =   &H00FFFFFF&
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   14.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   465
            Left            =   4065
            Locked          =   -1  'True
            TabIndex        =   144
            Text            =   "0.00"
            Top             =   540
            Width           =   2415
         End
         Begin VB.Label Label44 
            AutoSize        =   -1  'True
            Caption         =   "&Efectivo:"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   14.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   345
            Left            =   495
            TabIndex        =   151
            Top             =   510
            Width           =   1080
         End
         Begin VB.Label Label43 
            AutoSize        =   -1  'True
            Caption         =   "Vuelto:"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   14.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   345
            Left            =   480
            TabIndex        =   150
            Top             =   1050
            Width           =   885
         End
         Begin VB.Label Label42 
            AutoSize        =   -1  'True
            Caption         =   "(S/.)"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   12
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   285
            Left            =   2730
            TabIndex        =   149
            Top             =   180
            Width           =   570
         End
         Begin VB.Label Label41 
            AutoSize        =   -1  'True
            Caption         =   "(U$)"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   12
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   285
            Left            =   5220
            TabIndex        =   148
            Top             =   165
            Width           =   540
         End
      End
      Begin VB.Frame Frame13 
         Height          =   3975
         Left            =   -73920
         TabIndex        =   134
         Top             =   1080
         Width           =   5850
         Begin VB.TextBox txtTXL 
            Alignment       =   2  'Center
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   315
            Index           =   0
            Left            =   1320
            TabIndex        =   140
            Top             =   200
            Width           =   1215
         End
         Begin VB.CommandButton cmdTXL 
            Caption         =   "..."
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   300
            Index           =   0
            Left            =   2565
            TabIndex        =   139
            Top             =   200
            Width           =   330
         End
         Begin VB.CommandButton CmdAdd 
            Caption         =   "+"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   300
            Index           =   0
            Left            =   4680
            TabIndex        =   137
            Top             =   200
            Visible         =   0   'False
            Width           =   330
         End
         Begin VB.CommandButton CmdDel 
            Caption         =   "-"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   300
            Index           =   0
            Left            =   5280
            TabIndex        =   136
            Top             =   200
            Width           =   330
         End
         Begin VB.TextBox txtTotalPA 
            Alignment       =   1  'Right Justify
            BackColor       =   &H80000018&
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   11.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   360
            Left            =   3480
            Locked          =   -1  'True
            TabIndex        =   135
            TabStop         =   0   'False
            Text            =   "0.00"
            Top             =   3120
            Width           =   1980
         End
         Begin MSComctlLib.ListView lvwTX 
            Height          =   2445
            Index           =   0
            Left            =   90
            TabIndex        =   138
            Top             =   600
            Width           =   5625
            _ExtentX        =   9922
            _ExtentY        =   4313
            View            =   3
            LabelEdit       =   1
            LabelWrap       =   -1  'True
            HideSelection   =   0   'False
            FullRowSelect   =   -1  'True
            _Version        =   393217
            ForeColor       =   -2147483640
            BackColor       =   -2147483643
            BorderStyle     =   1
            Appearance      =   1
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            NumItems        =   0
         End
         Begin VB.Label Label40 
            AutoSize        =   -1  'True
            Caption         =   "FADE/BADE:"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   240
            Left            =   165
            TabIndex        =   142
            Top             =   240
            Width           =   1050
         End
         Begin VB.Label Label39 
            AutoSize        =   -1  'True
            Caption         =   "Total FADE/BADE (S/.):"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   11.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   270
            Left            =   240
            TabIndex        =   141
            Top             =   3135
            Width           =   2655
         End
      End
      Begin VB.Frame Frame12 
         Height          =   3975
         Left            =   -67920
         TabIndex        =   125
         Top             =   1080
         Width           =   5850
         Begin VB.TextBox txtTXL 
            Alignment       =   2  'Center
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   315
            Index           =   1
            Left            =   705
            TabIndex        =   130
            Top             =   200
            Visible         =   0   'False
            Width           =   1215
         End
         Begin VB.CommandButton cmdTXL 
            Caption         =   "..."
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   300
            Index           =   1
            Left            =   1965
            TabIndex        =   129
            Top             =   200
            Visible         =   0   'False
            Width           =   330
         End
         Begin VB.CommandButton CmdAdd 
            Caption         =   "+"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   300
            Index           =   1
            Left            =   4920
            TabIndex        =   128
            Top             =   200
            Visible         =   0   'False
            Width           =   330
         End
         Begin VB.CommandButton CmdDel 
            Caption         =   "-"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   300
            Index           =   1
            Left            =   5400
            TabIndex        =   127
            Top             =   200
            Visible         =   0   'False
            Width           =   330
         End
         Begin VB.TextBox txtTotalNC 
            Alignment       =   1  'Right Justify
            BackColor       =   &H80000018&
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   11.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   360
            Left            =   3720
            Locked          =   -1  'True
            TabIndex        =   126
            TabStop         =   0   'False
            Text            =   "0.00"
            Top             =   3090
            Width           =   1980
         End
         Begin MSComctlLib.ListView lvwTX 
            Height          =   2445
            Index           =   1
            Left            =   105
            TabIndex        =   131
            Top             =   600
            Width           =   5625
            _ExtentX        =   9922
            _ExtentY        =   4313
            View            =   3
            LabelEdit       =   1
            LabelWrap       =   -1  'True
            HideSelection   =   0   'False
            FullRowSelect   =   -1  'True
            _Version        =   393217
            ForeColor       =   -2147483640
            BackColor       =   -2147483643
            BorderStyle     =   1
            Appearance      =   1
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            NumItems        =   0
         End
         Begin VB.Label Label38 
            AutoSize        =   -1  'True
            Caption         =   "N/C:"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   240
            Left            =   255
            TabIndex        =   133
            Top             =   240
            Width           =   390
         End
         Begin VB.Label Label37 
            AutoSize        =   -1  'True
            Caption         =   "Total N/C (S/.):"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   11.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   270
            Left            =   1200
            TabIndex        =   132
            Top             =   3135
            Width           =   1800
         End
      End
      Begin VB.TextBox txtVueltoDolares 
         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            =   -68880
         MaxLength       =   6
         TabIndex        =   110
         Top             =   7380
         Visible         =   0   'False
         Width           =   1230
      End
      Begin VB.TextBox txtVueltoSoles 
         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            =   -68880
         MaxLength       =   6
         TabIndex        =   109
         Top             =   6900
         Visible         =   0   'False
         Width           =   1230
      End
      Begin VB.TextBox txtTX 
         Height          =   375
         Left            =   -70320
         TabIndex        =   108
         Top             =   6900
         Visible         =   0   'False
         Width           =   1095
      End
      Begin VB.TextBox txtEfectivoSoles 
         Height          =   375
         Left            =   5400
         TabIndex        =   96
         Top             =   8100
         Visible         =   0   'False
         Width           =   1455
      End
      Begin VB.TextBox txtEfectivoDolares 
         Height          =   375
         Left            =   5280
         TabIndex        =   95
         Top             =   7500
         Visible         =   0   'False
         Width           =   1575
      End
      Begin VB.TextBox txtsupervisor 
         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            =   3600
         MaxLength       =   6
         TabIndex        =   94
         Top             =   7500
         Visible         =   0   'False
         Width           =   1230
      End
      Begin VB.CommandButton Command3 
         Caption         =   "&Salir"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   15.75
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   735
         Left            =   -65040
         TabIndex        =   91
         Top             =   7560
         Width           =   2295
      End
      Begin VB.CommandButton cmdGrabarNC 
         Caption         =   "&Grabar"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   15.75
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   735
         Left            =   -73920
         TabIndex        =   90
         Top             =   7560
         Width           =   2295
      End
      Begin VB.Frame Frame11 
         Height          =   1695
         Left            =   -67200
         TabIndex        =   79
         Top             =   5760
         Width           =   4695
         Begin VB.TextBox txtDolaresNC 
            Alignment       =   1  'Right Justify
            Appearance      =   0  'Flat
            BackColor       =   &H8000000F&
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   20.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   615
            Left            =   1080
            Locked          =   -1  'True
            TabIndex        =   106
            TabStop         =   0   'False
            Text            =   "0.00"
            Top             =   840
            Width           =   3375
         End
         Begin VB.TextBox txtSolesNC 
            Alignment       =   1  'Right Justify
            Appearance      =   0  'Flat
            BackColor       =   &H8000000F&
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   20.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   615
            Left            =   1080
            Locked          =   -1  'True
            TabIndex        =   80
            TabStop         =   0   'False
            Text            =   "0.00"
            Top             =   165
            Width           =   3375
         End
         Begin VB.Label Label30 
            AutoSize        =   -1  'True
            Caption         =   "U$"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   20.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   495
            Left            =   240
            TabIndex        =   107
            Top             =   840
            Width           =   555
         End
         Begin VB.Label Label21 
            AutoSize        =   -1  'True
            Caption         =   "S/."
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   20.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   495
            Left            =   360
            TabIndex        =   81
            Top             =   225
            Width           =   615
         End
      End
      Begin VB.Frame Frame7 
         Caption         =   "Ingrese su Consumo"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   9.75
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   3015
         Left            =   -74280
         TabIndex        =   78
         Top             =   2700
         Width           =   12735
         Begin VB.CommandButton CmdDelArt 
            Caption         =   "E&liminar"
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   375
            Index           =   0
            Left            =   1680
            TabIndex        =   170
            Top             =   2520
            Width           =   1455
         End
         Begin VB.CommandButton CmdAddArt 
            Caption         =   "A&dicionar"
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   375
            Index           =   0
            Left            =   120
            TabIndex        =   169
            Top             =   2520
            Width           =   1455
         End
         Begin TrueOleDBGrid60.TDBGrid TDGNotaConsumo 
            Height          =   2040
            Left            =   240
            OleObjectBlob   =   "frmCajaFacturacionPagos.frx":0074
            TabIndex        =   118
            Top             =   360
            Width           =   12495
         End
      End
      Begin VB.Frame Frame6 
         Caption         =   "Datos de la Boleta/Factura"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   9.75
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   2055
         Left            =   -74280
         TabIndex        =   73
         Top             =   660
         Width           =   12735
         Begin VB.TextBox txtMontoPorConsumirDocumento 
            Alignment       =   1  'Right Justify
            Appearance      =   0  'Flat
            BackColor       =   &H8000000F&
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   20.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   615
            Left            =   10560
            Locked          =   -1  'True
            TabIndex        =   122
            TabStop         =   0   'False
            Text            =   "0.00"
            Top             =   960
            Width           =   2055
         End
         Begin VB.TextBox txtMontoDocumento 
            Alignment       =   1  'Right Justify
            Appearance      =   0  'Flat
            BackColor       =   &H8000000F&
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   20.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   615
            Left            =   10560
            Locked          =   -1  'True
            TabIndex        =   120
            TabStop         =   0   'False
            Text            =   "0.00"
            Top             =   240
            Width           =   2055
         End
         Begin VB.ComboBox cboTipoDocumento2 
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            ForeColor       =   &H00800000&
            Height          =   360
            ItemData        =   "frmCajaFacturacionPagos.frx":835B
            Left            =   6000
            List            =   "frmCajaFacturacionPagos.frx":835D
            Style           =   2  'Dropdown List
            TabIndex        =   76
            Top             =   240
            Width           =   2775
         End
         Begin VB.CommandButton cmdBuscarDocumentoNC 
            Caption         =   "..."
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   375
            Left            =   4440
            TabIndex        =   74
            Top             =   240
            Width           =   375
         End
         Begin VB.Label Label36 
            AutoSize        =   -1  'True
            Caption         =   "Monto Por Consumir:"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   480
            Left            =   8880
            TabIndex        =   124
            Top             =   1080
            Width           =   1080
            WordWrap        =   -1  'True
         End
         Begin VB.Label Label26 
            AutoSize        =   -1  'True
            Caption         =   "S/."
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   20.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   495
            Left            =   9960
            TabIndex        =   123
            Top             =   1080
            Width           =   615
         End
         Begin VB.Label Label35 
            AutoSize        =   -1  'True
            Caption         =   "S/."
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   20.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   495
            Left            =   9960
            TabIndex        =   121
            Top             =   360
            Width           =   615
         End
         Begin VB.Label Label32 
            AutoSize        =   -1  'True
            Caption         =   "Monto Documento:"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   480
            Left            =   8880
            TabIndex        =   119
            Top             =   240
            Width           =   1395
            WordWrap        =   -1  'True
         End
         Begin VB.Label lblNroDocumentoNC 
            BorderStyle     =   1  'Fixed Single
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   375
            Left            =   1920
            TabIndex        =   92
            Top             =   240
            Width           =   2295
         End
         Begin VB.Label lblCreditoaNC 
            BorderStyle     =   1  'Fixed Single
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   375
            Left            =   6000
            TabIndex        =   89
            Top             =   1320
            Width           =   2775
         End
         Begin VB.Label labelCredito 
            AutoSize        =   -1  'True
            Caption         =   "Credito a:"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   240
            Left            =   4920
            TabIndex        =   88
            Top             =   1440
            Width           =   960
         End
         Begin VB.Label lblFecEmisionNC 
            BorderStyle     =   1  'Fixed Single
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   375
            Left            =   1920
            TabIndex        =   87
            Top             =   1320
            Width           =   1455
         End
         Begin VB.Label Label29 
            AutoSize        =   -1  'True
            Caption         =   "F. de Emision:"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   240
            Left            =   240
            TabIndex        =   86
            Top             =   1320
            Width           =   1290
         End
         Begin VB.Label lblLocalNC 
            BorderStyle     =   1  'Fixed Single
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   375
            Left            =   6000
            TabIndex        =   85
            Top             =   720
            Width           =   2775
         End
         Begin VB.Label Label24 
            AutoSize        =   -1  'True
            Caption         =   "Local:"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   240
            Left            =   5400
            TabIndex        =   84
            Top             =   840
            Width           =   570
         End
         Begin VB.Label Label23 
            AutoSize        =   -1  'True
            Caption         =   "Cliente:"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   240
            Left            =   240
            TabIndex        =   83
            Top             =   840
            Width           =   735
         End
         Begin VB.Label lblClienteNC 
            BorderStyle     =   1  'Fixed Single
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   375
            Left            =   1920
            TabIndex        =   82
            Top             =   720
            Width           =   3375
         End
         Begin VB.Label Label14 
            AutoSize        =   -1  'True
            Caption         =   "Tipo Doc:"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   240
            Left            =   5040
            TabIndex        =   77
            Top             =   240
            Width           =   885
         End
         Begin VB.Label Label20 
            AutoSize        =   -1  'True
            Caption         =   "Nro Documento:"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   240
            Left            =   240
            TabIndex        =   75
            Top             =   240
            Width           =   1560
         End
      End
      Begin VB.Frame Frame3 
         Caption         =   "Datos del Credito"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   9.75
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   1965
         Left            =   9360
         TabIndex        =   60
         Top             =   660
         Width           =   4095
         Begin VB.TextBox txtRUC 
            Height          =   375
            Left            =   1920
            MaxLength       =   11
            TabIndex        =   65
            Top             =   1080
            Width           =   1935
         End
         Begin MSDataListLib.DataCombo dcbTipoCredito 
            Height          =   360
            Left            =   1920
            TabIndex        =   61
            Top             =   360
            Width           =   2055
            _ExtentX        =   3625
            _ExtentY        =   635
            _Version        =   393216
            Style           =   2
            ForeColor       =   8388608
            Text            =   ""
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
         End
         Begin MSComCtl2.DTPicker DTPFechaEmision 
            Height          =   375
            Left            =   1920
            TabIndex        =   62
            Top             =   720
            Width           =   1455
            _ExtentX        =   2566
            _ExtentY        =   661
            _Version        =   393216
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "MS Sans Serif"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Format          =   68222977
            CurrentDate     =   40491
         End
         Begin VB.Label Label9 
            AutoSize        =   -1  'True
            Caption         =   "&RUC Cliente:"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   240
            Left            =   120
            TabIndex        =   66
            Top             =   1080
            Width           =   1170
         End
         Begin VB.Label Label3 
            AutoSize        =   -1  'True
            Caption         =   "Credito a:"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   240
            Left            =   120
            TabIndex        =   64
            Top             =   360
            Width           =   960
         End
         Begin VB.Label Label5 
            AutoSize        =   -1  'True
            Caption         =   "Fecha de Emision:"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   240
            Left            =   120
            TabIndex        =   63
            Top             =   720
            Width           =   1695
         End
      End
      Begin VB.CommandButton cmdSalir 
         Caption         =   "&Salir"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   15.75
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   735
         Left            =   8760
         TabIndex        =   48
         Top             =   7380
         Width           =   2295
      End
      Begin VB.CommandButton cmdGrabarFactura 
         Caption         =   "&Grabar"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   15.75
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   735
         Left            =   600
         TabIndex        =   47
         Top             =   7260
         Width           =   2295
      End
      Begin VB.Frame Frame2 
         Caption         =   "Detalle"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   9.75
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   2775
         Left            =   240
         TabIndex        =   42
         Top             =   2880
         Width           =   13215
         Begin VB.CommandButton CmdAddArt 
            Caption         =   "A&dicionar"
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   375
            Index           =   2
            Left            =   480
            TabIndex        =   168
            Top             =   2280
            Width           =   1455
         End
         Begin VB.CommandButton CmdDelArt 
            Caption         =   "E&liminar"
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   375
            Index           =   2
            Left            =   2040
            TabIndex        =   167
            Top             =   2280
            Width           =   1455
         End
         Begin TrueOleDBGrid60.TDBGrid TDGFacturacion 
            Height          =   1920
            Left            =   120
            OleObjectBlob   =   "frmCajaFacturacionPagos.frx":835F
            TabIndex        =   43
            Top             =   360
            Width           =   12975
         End
      End
      Begin VB.Frame Frame1 
         Caption         =   " Datos del Cliente "
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   9.75
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   2010
         Left            =   240
         TabIndex        =   34
         Top             =   660
         Width           =   4845
         Begin VB.CommandButton cmdNuevoCliente 
            Caption         =   "Nuevo Cliente"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   375
            Left            =   1440
            TabIndex        =   59
            Top             =   1560
            Width           =   3255
         End
         Begin VB.TextBox txtTarjeta 
            Alignment       =   2  'Center
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   12
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            ForeColor       =   &H00800000&
            Height          =   405
            Left            =   1440
            MaxLength       =   8
            TabIndex        =   2
            Top             =   225
            Width           =   1710
         End
         Begin VB.TextBox txtNombres 
            BackColor       =   &H80000009&
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   420
            Left            =   1440
            MultiLine       =   -1  'True
            ScrollBars      =   2  'Vertical
            TabIndex        =   37
            Top             =   720
            Width           =   3375
         End
         Begin VB.CommandButton txtBuscaCliente 
            Caption         =   "..."
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   315
            Left            =   3840
            TabIndex        =   36
            Top             =   240
            Width           =   330
         End
         Begin VB.TextBox txtLocal 
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   12
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   405
            Left            =   3360
            MaxLength       =   1
            TabIndex        =   35
            Top             =   225
            Width           =   375
         End
         Begin MSDataListLib.DataCombo dcbLocal 
            Height          =   360
            Left            =   1440
            TabIndex        =   58
            Top             =   1200
            Width           =   3375
            _ExtentX        =   5953
            _ExtentY        =   635
            _Version        =   393216
            Enabled         =   0   'False
            Style           =   2
            ForeColor       =   8388608
            Text            =   ""
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
         End
         Begin VB.Label Label1 
            AutoSize        =   -1  'True
            Caption         =   "Nro. &Tarjeta:"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   240
            Left            =   120
            TabIndex        =   41
            Top             =   285
            Width           =   1230
         End
         Begin VB.Label Label2 
            AutoSize        =   -1  'True
            Caption         =   "&Nombres:"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   240
            Left            =   120
            TabIndex        =   40
            Top             =   780
            Width           =   915
         End
         Begin VB.Label lblLocal 
            AutoSize        =   -1  'True
            Caption         =   "&Local:"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   240
            Left            =   120
            TabIndex        =   39
            Top             =   1200
            Width           =   570
         End
         Begin VB.Label Label28 
            Alignment       =   2  'Center
            Caption         =   "_"
            Height          =   375
            Left            =   3120
            TabIndex        =   38
            Top             =   240
            Width           =   255
         End
      End
      Begin VB.Frame Frame5 
         Caption         =   "Datos del Documento"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   9.75
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   2010
         Left            =   5160
         TabIndex        =   29
         Top             =   660
         Width           =   4080
         Begin VB.CommandButton cmdAnulacionFact 
            Caption         =   "Anular Documento"
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   375
            Left            =   960
            TabIndex        =   111
            Top             =   1560
            Width           =   2895
         End
         Begin VB.ComboBox cboMoneda 
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            ForeColor       =   &H00800000&
            Height          =   360
            ItemData        =   "frmCajaFacturacionPagos.frx":10646
            Left            =   1920
            List            =   "frmCajaFacturacionPagos.frx":10648
            Style           =   2  'Dropdown List
            TabIndex        =   100
            Top             =   1080
            Width           =   1935
         End
         Begin VB.ComboBox cboTipoDocumento 
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            ForeColor       =   &H00800000&
            Height          =   360
            ItemData        =   "frmCajaFacturacionPagos.frx":1064A
            Left            =   1920
            List            =   "frmCajaFacturacionPagos.frx":1064C
            Style           =   2  'Dropdown List
            TabIndex        =   30
            Top             =   720
            Width           =   1935
         End
         Begin VB.Label Label16 
            AutoSize        =   -1  'True
            Caption         =   "Moneda:"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   240
            Left            =   120
            TabIndex        =   97
            Top             =   1080
            Width           =   840
         End
         Begin VB.Label lblNroDocumento 
            BorderStyle     =   1  'Fixed Single
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   375
            Left            =   1920
            TabIndex        =   33
            Top             =   360
            Width           =   1935
         End
         Begin VB.Label Label8 
            AutoSize        =   -1  'True
            Caption         =   "Tipo Documento:"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   240
            Left            =   120
            TabIndex        =   32
            Top             =   720
            Width           =   1620
         End
         Begin VB.Label Label10 
            AutoSize        =   -1  'True
            Caption         =   "Nro Documento:"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   240
            Left            =   120
            TabIndex        =   31
            Top             =   360
            Width           =   1560
         End
      End
      Begin VB.Frame fraTotal 
         Height          =   1575
         Left            =   6840
         TabIndex        =   24
         Top             =   5580
         Width           =   4695
         Begin VB.TextBox txtDolares 
            Alignment       =   1  'Right Justify
            Appearance      =   0  'Flat
            BackColor       =   &H8000000F&
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   20.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   615
            Left            =   1065
            Locked          =   -1  'True
            TabIndex        =   26
            TabStop         =   0   'False
            Text            =   "0.00"
            Top             =   870
            Width           =   3375
         End
         Begin VB.TextBox txtSoles 
            Alignment       =   1  'Right Justify
            Appearance      =   0  'Flat
            BackColor       =   &H8000000F&
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   20.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   615
            Left            =   1080
            Locked          =   -1  'True
            TabIndex        =   25
            TabStop         =   0   'False
            Text            =   "0.00"
            Top             =   165
            Width           =   3375
         End
         Begin VB.Label Label6 
            AutoSize        =   -1  'True
            Caption         =   "U$"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   20.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   495
            Left            =   360
            TabIndex        =   28
            Top             =   915
            Width           =   555
         End
         Begin VB.Label Label7 
            AutoSize        =   -1  'True
            Caption         =   "S/."
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   20.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   495
            Left            =   360
            TabIndex        =   27
            Top             =   225
            Width           =   615
         End
      End
      Begin VB.Frame Frame4 
         Caption         =   "Pagos Realizados"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   9.75
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   3135
         Left            =   -74640
         TabIndex        =   23
         Top             =   5280
         Width           =   12015
         Begin VB.CommandButton cmdAnularTransaccionPag 
            Caption         =   "Anular Pago"
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   375
            Left            =   4800
            TabIndex        =   112
            Top             =   2640
            Width           =   2775
         End
         Begin MSDataGridLib.DataGrid dgdPagos 
            Height          =   2295
            Left            =   120
            TabIndex        =   67
            Top             =   240
            Width           =   11775
            _ExtentX        =   20770
            _ExtentY        =   4048
            _Version        =   393216
            AllowUpdate     =   0   'False
            BackColor       =   -2147483624
            HeadLines       =   1
            RowHeight       =   19
            RowDividerStyle =   5
            FormatLocked    =   -1  'True
            BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   12
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            ColumnCount     =   15
            BeginProperty Column00 
               DataField       =   "cSerieDocPago"
               Caption         =   "Serie PADE"
               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       =   "NroDocPago"
               Caption         =   "Nro PADE"
               BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
                  Type            =   0
                  Format          =   ""
                  HaveTrueFalseNull=   0
                  FirstDayOfWeek  =   0
                  FirstWeekOfYear =   0
                  LCID            =   10250
                  SubFormatType   =   0
               EndProperty
            EndProperty
            BeginProperty Column02 
               DataField       =   "fechapago"
               Caption         =   "Fecha Pago"
               BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
                  Type            =   0
                  Format          =   ""
                  HaveTrueFalseNull=   0
                  FirstDayOfWeek  =   0
                  FirstWeekOfYear =   0
                  LCID            =   10250
                  SubFormatType   =   0
               EndProperty
            EndProperty
            BeginProperty Column03 
               DataField       =   "FormaPagoDsc"
               Caption         =   "Forma Pago"
               BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
                  Type            =   0
                  Format          =   ""
                  HaveTrueFalseNull=   0
                  FirstDayOfWeek  =   0
                  FirstWeekOfYear =   0
                  LCID            =   10250
                  SubFormatType   =   0
               EndProperty
            EndProperty
            BeginProperty Column04 
               DataField       =   "DocFormaPago"
               Caption         =   "Anx"
               BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
                  Type            =   0
                  Format          =   ""
                  HaveTrueFalseNull=   0
                  FirstDayOfWeek  =   0
                  FirstWeekOfYear =   0
                  LCID            =   10250
                  SubFormatType   =   0
               EndProperty
            EndProperty
            BeginProperty Column05 
               DataField       =   "monto"
               Caption         =   "Monto"
               BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
                  Type            =   0
                  Format          =   ""
                  HaveTrueFalseNull=   0
                  FirstDayOfWeek  =   0
                  FirstWeekOfYear =   0
                  LCID            =   10250
                  SubFormatType   =   0
               EndProperty
            EndProperty
            BeginProperty Column06 
               DataField       =   "moneda"
               Caption         =   "Moneda"
               BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
                  Type            =   0
                  Format          =   ""
                  HaveTrueFalseNull=   0
                  FirstDayOfWeek  =   0
                  FirstWeekOfYear =   0
                  LCID            =   10250
                  SubFormatType   =   0
               EndProperty
            EndProperty
            BeginProperty Column07 
               DataField       =   "IdTarjeta"
               Caption         =   "IdTarjeta"
               BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
                  Type            =   0
                  Format          =   ""
                  HaveTrueFalseNull=   0
                  FirstDayOfWeek  =   0
                  FirstWeekOfYear =   0
                  LCID            =   10250
                  SubFormatType   =   0
               EndProperty
            EndProperty
            BeginProperty Column08 
               DataField       =   "IdBanco"
               Caption         =   "IdBanco"
               BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
                  Type            =   0
                  Format          =   ""
                  HaveTrueFalseNull=   0
                  FirstDayOfWeek  =   0
                  FirstWeekOfYear =   0
                  LCID            =   10250
                  SubFormatType   =   0
               EndProperty
            EndProperty
            BeginProperty Column09 
               DataField       =   "NroCtaBancaria"
               Caption         =   "NroCtaBancaria"
               BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
                  Type            =   0
                  Format          =   ""
                  HaveTrueFalseNull=   0
                  FirstDayOfWeek  =   0
                  FirstWeekOfYear =   0
                  LCID            =   10250
                  SubFormatType   =   0
               EndProperty
            EndProperty
            BeginProperty Column10 
               DataField       =   "NroOperacion"
               Caption         =   "NroOperacion"
               BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
                  Type            =   0
                  Format          =   ""
                  HaveTrueFalseNull=   0
                  FirstDayOfWeek  =   0
                  FirstWeekOfYear =   0
                  LCID            =   10250
                  SubFormatType   =   0
               EndProperty
            EndProperty
            BeginProperty Column11 
               DataField       =   "NroCertificadoRetencion"
               Caption         =   "NroCertificadoRetencion"
               BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
                  Type            =   0
                  Format          =   ""
                  HaveTrueFalseNull=   0
                  FirstDayOfWeek  =   0
                  FirstWeekOfYear =   0
                  LCID            =   10250
                  SubFormatType   =   0
               EndProperty
            EndProperty
            BeginProperty Column12 
               DataField       =   "NroDepositoDetraccion"
               Caption         =   "NroDepositoDetraccion"
               BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
                  Type            =   0
                  Format          =   ""
                  HaveTrueFalseNull=   0
                  FirstDayOfWeek  =   0
                  FirstWeekOfYear =   0
                  LCID            =   10250
                  SubFormatType   =   0
               EndProperty
            EndProperty
            BeginProperty Column13 
               DataField       =   "cClieCode"
               Caption         =   "cClieCode"
               BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
                  Type            =   0
                  Format          =   ""
                  HaveTrueFalseNull=   0
                  FirstDayOfWeek  =   0
                  FirstWeekOfYear =   0
                  LCID            =   10250
                  SubFormatType   =   0
               EndProperty
            EndProperty
            BeginProperty Column14 
               DataField       =   "IdLocal"
               Caption         =   "IdLocal"
               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 
               MarqueeStyle    =   3
               BeginProperty Column00 
               EndProperty
               BeginProperty Column01 
               EndProperty
               BeginProperty Column02 
                  ColumnWidth     =   1635.024
               EndProperty
               BeginProperty Column03 
                  ColumnWidth     =   1785.26
               EndProperty
               BeginProperty Column04 
                  ColumnWidth     =   2085.166
               EndProperty
               BeginProperty Column05 
               EndProperty
               BeginProperty Column06 
               EndProperty
               BeginProperty Column07 
                  Object.Visible         =   0   'False
               EndProperty
               BeginProperty Column08 
                  Object.Visible         =   0   'False
               EndProperty
               BeginProperty Column09 
                  Object.Visible         =   0   'False
               EndProperty
               BeginProperty Column10 
                  Object.Visible         =   0   'False
               EndProperty
               BeginProperty Column11 
                  Object.Visible         =   0   'False
               EndProperty
               BeginProperty Column12 
                  Object.Visible         =   0   'False
               EndProperty
               BeginProperty Column13 
                  Object.Visible         =   0   'False
               EndProperty
               BeginProperty Column14 
                  Object.Visible         =   0   'False
               EndProperty
            EndProperty
         End
      End
      Begin VB.Frame FraRegistroPago 
         Caption         =   "Registro de Pago:"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   9.75
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   2850
         Left            =   -74640
         TabIndex        =   7
         Top             =   2400
         Width           =   12000
         Begin VB.CheckBox chkEsDetraccion 
            Caption         =   "Es detracción"
            Enabled         =   0   'False
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   9960
            TabIndex        =   116
            Top             =   1150
            Value           =   1  'Checked
            Visible         =   0   'False
            Width           =   1935
         End
         Begin VB.TextBox txtMontoDolares 
            Alignment       =   1  'Right Justify
            Height          =   285
            Left            =   9960
            TabIndex        =   103
            Top             =   240
            Width           =   1095
         End
         Begin VB.ComboBox cboMoneda1 
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            ForeColor       =   &H00800000&
            Height          =   360
            ItemData        =   "frmCajaFacturacionPagos.frx":1064E
            Left            =   1920
            List            =   "frmCajaFacturacionPagos.frx":10650
            Style           =   2  'Dropdown List
            TabIndex        =   102
            Top             =   1440
            Width           =   1935
         End
         Begin VB.Frame Frame8 
            Height          =   750
            Left            =   9120
            TabIndex        =   68
            Top             =   2040
            Width           =   2295
            Begin VB.CommandButton cmdBoton 
               Appearance      =   0  'Flat
               Caption         =   "&Grabar"
               Height          =   540
               Index           =   3
               Left            =   1320
               Picture         =   "frmCajaFacturacionPagos.frx":10652
               Style           =   1  'Graphical
               TabIndex        =   72
               ToolTipText     =   "Ver "
               Top             =   120
               Width           =   675
            End
            Begin VB.CommandButton cmdBoton 
               Appearance      =   0  'Flat
               Caption         =   "&Eliminar"
               Height          =   540
               Index           =   2
               Left            =   1320
               Picture         =   "frmCajaFacturacionPagos.frx":10A94
               Style           =   1  'Graphical
               TabIndex        =   71
               ToolTipText     =   "Eliminar"
               Top             =   120
               Visible         =   0   'False
               Width           =   735
            End
            Begin VB.CommandButton cmdBoton 
               Appearance      =   0  'Flat
               Caption         =   "&Modific."
               Height          =   540
               Index           =   1
               Left            =   1320
               Picture         =   "frmCajaFacturacionPagos.frx":10BDE
               Style           =   1  'Graphical
               TabIndex        =   70
               ToolTipText     =   "Modificar"
               Top             =   120
               Visible         =   0   'False
               Width           =   675
            End
            Begin VB.CommandButton cmdBoton 
               Appearance      =   0  'Flat
               Caption         =   "&Nuevo"
               Height          =   540
               Index           =   0
               Left            =   360
               MaskColor       =   &H00FFFFFF&
               Picture         =   "frmCajaFacturacionPagos.frx":10F68
               Style           =   1  'Graphical
               TabIndex        =   69
               ToolTipText     =   "Ingresar registro"
               Top             =   120
               UseMaskColor    =   -1  'True
               Width           =   795
            End
         End
         Begin VB.TextBox txtNroOperacion 
            Height          =   285
            Left            =   8400
            MaxLength       =   15
            TabIndex        =   55
            Top             =   1620
            Width           =   1455
         End
         Begin VB.TextBox txtNroCuenta 
            Height          =   285
            Left            =   8400
            MaxLength       =   15
            TabIndex        =   53
            Top             =   1125
            Width           =   1455
         End
         Begin VB.TextBox txtMontoSoles 
            Alignment       =   1  'Right Justify
            Height          =   285
            Left            =   8400
            TabIndex        =   10
            Top             =   240
            Width           =   1095
         End
         Begin VB.TextBox txtNroCertificadoRetencion 
            Height          =   285
            Left            =   8400
            MaxLength       =   15
            TabIndex        =   9
            Top             =   720
            Width           =   2655
         End
         Begin VB.TextBox txtNroDepositoDetraccion 
            Height          =   285
            Left            =   8400
            MaxLength       =   15
            TabIndex        =   8
            Top             =   720
            Width           =   2655
         End
         Begin MSComCtl2.DTPicker DTPFechaPago 
            Height          =   375
            Left            =   1920
            TabIndex        =   11
            Top             =   1920
            Width           =   1455
            _ExtentX        =   2566
            _ExtentY        =   661
            _Version        =   393216
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "MS Sans Serif"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Format          =   68222977
            CurrentDate     =   40491
         End
         Begin MSDataListLib.DataCombo dcbBanco 
            Height          =   360
            Left            =   8400
            TabIndex        =   49
            Top             =   720
            Width           =   2655
            _ExtentX        =   4683
            _ExtentY        =   635
            _Version        =   393216
            Style           =   2
            ForeColor       =   8388608
            Text            =   "DataCombo1"
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
         End
         Begin MSDataListLib.DataCombo dcbFormaPago 
            Height          =   360
            Left            =   1920
            TabIndex        =   50
            Top             =   960
            Width           =   2655
            _ExtentX        =   4683
            _ExtentY        =   635
            _Version        =   393216
            Style           =   2
            ForeColor       =   8388608
            Text            =   ""
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
         End
         Begin MSDataListLib.DataCombo dcbTarjeta 
            Height          =   360
            Left            =   8400
            TabIndex        =   57
            Top             =   720
            Width           =   2655
            _ExtentX        =   4683
            _ExtentY        =   635
            _Version        =   393216
            Style           =   2
            ForeColor       =   8388608
            Text            =   ""
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
         End
         Begin VB.Label Label34 
            AutoSize        =   -1  'True
            Caption         =   "$/."
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   240
            Left            =   9600
            TabIndex        =   114
            Top             =   240
            Width           =   300
         End
         Begin VB.Label Label33 
            AutoSize        =   -1  'True
            Caption         =   "S/."
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   240
            Left            =   8040
            TabIndex        =   113
            Top             =   240
            Width           =   300
         End
         Begin VB.Label Label25 
            AutoSize        =   -1  'True
            Caption         =   "Moneda:"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   240
            Left            =   120
            TabIndex        =   101
            Top             =   1440
            Width           =   840
         End
         Begin VB.Label lblTipoTarjeta 
            AutoSize        =   -1  'True
            Caption         =   "Tipo Tarjeta:"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   240
            Left            =   6240
            TabIndex        =   56
            Top             =   720
            Width           =   1230
         End
         Begin VB.Label lblNroOperacion 
            AutoSize        =   -1  'True
            Caption         =   "Nro Operacion:"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   240
            Left            =   6240
            TabIndex        =   54
            Top             =   1620
            Width           =   1440
         End
         Begin VB.Label lblNroCuenta 
            AutoSize        =   -1  'True
            Caption         =   "Nro Cuenta:"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   240
            Left            =   6240
            TabIndex        =   52
            Top             =   1125
            Width           =   1155
         End
         Begin VB.Label lblBanco 
            AutoSize        =   -1  'True
            Caption         =   "Banco:"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   240
            Left            =   6240
            TabIndex        =   51
            Top             =   720
            Width           =   660
         End
         Begin VB.Label Label4 
            AutoSize        =   -1  'True
            Caption         =   "Nro PADE:"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   240
            Left            =   120
            TabIndex        =   22
            Top             =   240
            Width           =   975
         End
         Begin VB.Label Label11 
            AutoSize        =   -1  'True
            Caption         =   "Forma de Pago:"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   240
            Left            =   120
            TabIndex        =   21
            Top             =   1000
            Width           =   1500
         End
         Begin VB.Label Label12 
            AutoSize        =   -1  'True
            Caption         =   "Fecha de Pago:"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   240
            Left            =   120
            TabIndex        =   20
            Top             =   1920
            Width           =   1470
         End
         Begin VB.Label lblNroPade 
            BorderStyle     =   1  'Fixed Single
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   1920
            TabIndex        =   19
            Top             =   240
            Width           =   2535
         End
         Begin VB.Label Label17 
            AutoSize        =   -1  'True
            Caption         =   "Monto:"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   240
            Left            =   6240
            TabIndex        =   18
            Top             =   240
            Width           =   690
         End
         Begin VB.Label Label13 
            AutoSize        =   -1  'True
            Caption         =   "Tipo Documento:"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   240
            Left            =   120
            TabIndex        =   17
            Top             =   600
            Width           =   1620
         End
         Begin VB.Label Label19 
            AutoSize        =   -1  'True
            Caption         =   "Monto Dolares:"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   240
            Left            =   5640
            TabIndex        =   16
            Top             =   2400
            Visible         =   0   'False
            Width           =   1485
         End
         Begin VB.Label lblMontoDolares 
            BorderStyle     =   1  'Fixed Single
            Height          =   255
            Left            =   7200
            TabIndex        =   15
            Top             =   2400
            Visible         =   0   'False
            Width           =   1095
         End
         Begin VB.Label lblCertificadoRetencion 
            AutoSize        =   -1  'True
            Caption         =   "Nro Cert. Retencion:"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   240
            Left            =   6240
            TabIndex        =   14
            Top             =   720
            Width           =   1980
         End
         Begin VB.Label lblDepositoDetraccion 
            AutoSize        =   -1  'True
            Caption         =   "Nro Dep. Detraccion:"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   240
            Left            =   6240
            TabIndex        =   13
            Top             =   720
            Width           =   2010
         End
         Begin VB.Label lblTipoDocumento2 
            BorderStyle     =   1  'Fixed Single
            Caption         =   "PADE"
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   1920
            TabIndex        =   12
            Top             =   600
            Width           =   2535
         End
      End
      Begin VB.Frame Frame9 
         Caption         =   "Datos de la Boleta/Factura"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   9.75
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   2055
         Left            =   -74640
         TabIndex        =   1
         Top             =   360
         Width           =   12015
         Begin VB.CommandButton cmdActualizarDetracc 
            Caption         =   "Actualizar Pago Detracc."
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   375
            Left            =   720
            TabIndex        =   117
            Top             =   1560
            Visible         =   0   'False
            Width           =   2775
         End
         Begin VB.ComboBox cboTipoDocumento1 
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            ForeColor       =   &H00800000&
            Height          =   360
            ItemData        =   "frmCajaFacturacionPagos.frx":112F2
            Left            =   8160
            List            =   "frmCajaFacturacionPagos.frx":112F4
            Style           =   2  'Dropdown List
            TabIndex        =   93
            Top             =   240
            Width           =   3375
         End
         Begin VB.Frame Frame10 
            Caption         =   "Saldo por Pagar"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   615
            Left            =   6120
            TabIndex        =   44
            Top             =   600
            Width           =   5415
            Begin VB.Label Label22 
               AutoSize        =   -1  'True
               Caption         =   "Dolares"
               BeginProperty Font 
                  Name            =   "Tahoma"
                  Size            =   9.75
                  Charset         =   0
                  Weight          =   700
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Height          =   240
               Left            =   3960
               TabIndex        =   99
               Top             =   240
               Width           =   735
            End
            Begin VB.Label lblSaldoDolares 
               BorderStyle     =   1  'Fixed Single
               BeginProperty Font 
                  Name            =   "MS Sans Serif"
                  Size            =   9.75
                  Charset         =   0
                  Weight          =   700
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Height          =   255
               Left            =   2520
               TabIndex        =   98
               Top             =   240
               Width           =   1215
            End
            Begin VB.Label lblSaldoSoles 
               BorderStyle     =   1  'Fixed Single
               BeginProperty Font 
                  Name            =   "MS Sans Serif"
                  Size            =   9.75
                  Charset         =   0
                  Weight          =   700
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Height          =   255
               Left            =   120
               TabIndex        =   46
               Top             =   240
               Width           =   1215
            End
            Begin VB.Label Label31 
               AutoSize        =   -1  'True
               Caption         =   "Soles"
               BeginProperty Font 
                  Name            =   "Tahoma"
                  Size            =   9.75
                  Charset         =   0
                  Weight          =   700
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Height          =   240
               Left            =   1440
               TabIndex        =   45
               Top             =   240
               Width           =   510
            End
         End
         Begin VB.CommandButton cmdBuscarDocumento 
            Caption         =   "..."
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   375
            Left            =   4800
            TabIndex        =   3
            Top             =   240
            Width           =   375
         End
         Begin VB.Label lblDetraccion 
            Caption         =   "(*) El documento registra pago de detracción pendiente"
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            ForeColor       =   &H000000C0&
            Height          =   255
            Left            =   120
            TabIndex        =   115
            Top             =   1320
            Visible         =   0   'False
            Width           =   4815
         End
         Begin VB.Label lblMoneda 
            BorderStyle     =   1  'Fixed Single
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   2160
            TabIndex        =   105
            Top             =   840
            Width           =   2535
         End
         Begin VB.Label Label27 
            AutoSize        =   -1  'True
            Caption         =   "Moneda:"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   240
            Left            =   240
            TabIndex        =   104
            Top             =   800
            Width           =   840
         End
         Begin VB.Label Label15 
            AutoSize        =   -1  'True
            Caption         =   "Nro Documento:"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   240
            Left            =   240
            TabIndex        =   6
            Top             =   240
            Width           =   1560
         End
         Begin VB.Label lblNroDocumento2 
            BorderStyle     =   1  'Fixed Single
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   2160
            TabIndex        =   5
            Top             =   240
            Width           =   2535
         End
         Begin VB.Label Label18 
            AutoSize        =   -1  'True
            Caption         =   "Tipo Documento:"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   240
            Left            =   6240
            TabIndex        =   4
            Top             =   240
            Width           =   1620
         End
      End
      Begin VB.Label Label47 
         AutoSize        =   -1  'True
         Caption         =   "Tipo Doc:"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   9.75
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   240
         Left            =   -70200
         TabIndex        =   160
         Top             =   600
         Width           =   885
      End
   End
End
Attribute VB_Name = "frmCajaFacturacionPagos"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public lcProdCode As String
Public lnProdPrecUnit As String
Public lsProdDescCrta As String
Public lsProdDesc As String
Public lsCodCatalogo As String
Public lsCanje As String
Public lsPtos As String
Public lsServ As String
Public iEfectivo As Double

Public bAcceso As Boolean
Dim nTotIGV As Double

Public gfax As New XArrayDB
Public gfax2 As New XArrayDB

Public nProducto As Long 'Cantidad de productos por transaccion - doc
Public nProducto2 As Long 'Cantidad de productos por transaccion - nc

Dim Producto() As tProducto 'Almacena los datos de cada producto que se va registrando - Doc
Dim Producto2() As tProducto 'Almacena los datos de cada producto que se va registrando - NC

'''variables de pagos
Public P_TipoDoc As String
Public P_cSerieDoc As String
Public P_NroDoc As String
Public P_FechaEmision As String
Public P_DscCliente As String
Public P_cClienteCode As String
Public P_IdLocal As String
Public P_Moneda As String
Public P_TotVta As Double
Public P_TotVtaUSD As Double
Public P_MontoRestante As Double
Public P_MontoRestanteUSD As Double

'''variables de NC
Public NC_cCodVta As String
Public NC_NroDoc As String
Public NC_DscCliente As String
Public NC_cClienteCode As String
Public NC_DscLocal As String
Public NC_IdLocal As String
Public NC_NroRuc As String
Public NC_DscTipoCredito As String
Public NC_TotVta As Double
Public NC_TotVtaUSD As Double
Public NC_FecEmision As String

'Variables para recargar listado
Dim iTipoDoc As String
Dim iSerieDoc As String
Dim iNroDoc As String
Dim iMonedaDoc As String
Dim iSaldo As Double
Dim iSaldoUSD As Double

Private Sub Inicio()
  On Error GoTo LineaError

  bLiquidaNC = False
  bAcceso = False
  txtsupervisor.Text = ""
  sFlag = False

  Dim sSQL As String
  Dim ADORS As ADODB.Recordset
  Dim i As Long, j As Long
  Dim iInicio As Long, iFin As Long
  Dim sTecla1 As String, sTecla2 As String, sTecla3 As String

  'Reglas por punto e importe
  If bolExistenProblemasConexionBDCliente = False Then
    ConectarBDCliente     'Abrimos conexion
  End If
  
  If bolExisteConexionBDCliente = True Then
    sSQL = "SELECT * FROM Regla_Punto"
    If Not oDBAdmin.EjecutarConsulta(ADOCnn2, sSQL, ADORS) Then GoTo Salir
    
    If ADORS.EOF Then
      MsgBox "Reglas en relación a los puntos no han sido establecidos", vbOKOnly + vbInformation
      GoTo Salir
    End If
    lReglaImporteMaximo = LeerCampo(ADORS!nImpoMaxi)
    lReglaPuntoImporte = CLng(LeerCampo(ADORS!nPuntImpo))
    lReglaPuntoCantidad = CLng(LeerCampo(ADORS!nPuntCant))
    oDBAdmin.CerrarBD ADOCnn2     'Cerramos conexion
    bolExisteConexionBDCliente = False
    
    'Actualizamos estos parametros en la BD Local
    sSQL = " UPDATE Regla_Punto " & _
           "    SET nImpoMaxi = " & lReglaImporteMaximo & "," & _
           "        nPuntImpo = " & lReglaPuntoImporte & "," & _
           "        nPuntCant = " & lReglaPuntoCantidad
    If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
    
  Else
    sSQL = "SELECT * FROM Regla_Punto"
    If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
    
    If ADORS.EOF Then
      MsgBox "Reglas en relación a los puntos no han sido establecidos", vbOKOnly + vbInformation
      GoTo Salir
    End If
    lReglaImporteMaximo = LeerCampo(ADORS!nImpoMaxi)
    lReglaPuntoImporte = CLng(LeerCampo(ADORS!nPuntImpo))
    lReglaPuntoCantidad = CLng(LeerCampo(ADORS!nPuntCant))
  End If
  
  GoTo Salir
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation

Salir:
  Set ADORS = Nothing
  Screen.MousePointer = vbDefault
  
End Sub

Public Sub CargarDocumentoNC()
Dim cnSQL As ADODB.Connection
Dim ADORS As ADODB.Recordset
Dim sSQL As String
Dim i As Integer

sSQL = "select nroitem,cCodArtic,sProdDscCrta,nPrecioOrig,nQtdVendida,nDescuento,nServicio from venta02 where ccodvta='" & NC_cCodVta & "' order by nroitem"

If Not oDBAdmin.AbrirBD(cnSQL, psConnectString) Then GoTo Salir 'OMNISYS

If Not oDBAdmin.EjecutarConsulta(cnSQL, sSQL, ADORS) Then GoTo Salir

'Set dgdDetalleNC.DataSource = ADORS



'gfax2.ReDim 0, ADORS.RecordCount - 1, 0, 9
'For i = 0 To ADORS.RecordCount - 1
'    gfax2.Value(i, 0) = LeerCampo(ADORS!NroItem)
'    gfax2.Value(i, 1) = LeerCampo(ADORS!cCodArtic)
'    gfax2.Value(i, 2) = LeerCampo(ADORS!sProdDscCrta)
'    gfax2.Value(i, 3) = LeerCampo(ADORS!nPrecioOrig)
'    gfax2.Value(i, 4) = LeerCampo(ADORS!nQtdVendida)
'    gfax2.Value(i, 5) = LeerCampo(ADORS!nDescuento)
'    gfax2.Value(i, 6) = LeerCampo(ADORS!nServicio)
'    gfax2.Value(i, 7) = ""
'    gfax2.Value(i, 8) = "0"
'    gfax2.Value(i, 9) = ""
'
'    ADORS.MoveNext
'Next
'  ADORS.Close
'  TDGNotaConsumo.Array = gfax2
'  TDGNotaConsumo.ReBind
'  TDGNotaConsumo.MoveFirst
'  TDGNotaConsumo.Update
'  TDGNotaConsumo.Refresh


lblNroDocumentoNC = NC_NroDoc
lblClienteNC = NC_DscCliente
lblLocalNC = NC_DscLocal
'lblRUCNC = NC_NroRuc
'txtSolesNC = Format(NC_TotVta, "0.00")
'txtDolaresNC = Format(NC_TotVtaUSD, "0.00")
txtMontoDocumento = Format(NC_TotVta, "0.00")
txtMontoPorConsumirDocumento = Format(NC_TotVta - RetornarConsumoxDocumento(NC_cCodVta), "0.00")
lblFecEmisionNC = Format(NC_FecEmision, "dd/MM/yyyy")
lblCreditoaNC = NC_DscTipoCredito

Salir:
Set cnSQL = Nothing


End Sub
Private Sub LimpiarNC()

lblNroDocumentoNC.Caption = ""
lblClienteNC.Caption = ""
lblLocalNC.Caption = ""
'lblRUCNC.Caption = ""
lblFecEmisionNC.Caption = ""
lblCreditoaNC.Caption = ""
txtSolesNC.Text = "0.00"
txtDolaresNC.Text = "0.00"

txtMontoDocumento.Text = "0.00"
txtMontoPorConsumirDocumento.Text = "0.00"

NC_cCodVta = ""
NC_NroDoc = ""
NC_DscCliente = ""
NC_cClienteCode = ""
NC_DscLocal = ""
NC_IdLocal = ""
NC_NroRuc = ""
NC_DscTipoCredito = ""
NC_TotVta = 0
NC_TotVtaUSD = 0
NC_FecEmision = ""


gfax2.Clear
gfax2.ReDim 0, 0, 0, 15
Set TDGNotaConsumo.Array = gfax2
TDGNotaConsumo.ReBind
TDGNotaConsumo.MoveFirst
TDGNotaConsumo.Update
TDGNotaConsumo.Refresh

End Sub
Public Sub LimpiarPagos()

lblNroDocumento2.Caption = ""
'lblTipoDocumento.Caption = ""
'cboTipoDocumento1.Text = ""
cboTipoDocumento1.Enabled = True
lblSaldoSoles.Caption = ""
lblSaldoDolares.Caption = ""
dcbFormaPago.Text = ""
txtMontoSoles.Text = ""
txtMontoDolares.Text = ""
lblMontoDolares.Caption = ""
txtNroCertificadoRetencion.Text = ""
dcbBanco.Text = ""
txtNroCuenta.Text = ""
txtNroOperacion.Text = ""
txtNroDepositoDetraccion.Text = ""
dcbTarjeta.Text = ""
DTPFechaPago.Value = Now
lblMoneda.Caption = ""
lblDetraccion.Caption = ""

P_TipoDoc = ""
P_cSerieDoc = ""
P_NroDoc = ""
P_FechaEmision = ""
P_DscCliente = ""
P_cClienteCode = ""
P_IdLocal = ""

P_Moneda = ""
P_TotVta = 0
P_TotVtaUSD = 0
P_MontoRestante = 0
P_MontoRestanteUSD = 0

cboMoneda1.Text = "SOLES"

chkEsDetraccion.Visible = False
lblDetraccion.Visible = False
cmdActualizarDetracc.Visible = False
Set dgdPagos.DataSource = Nothing
dgdPagos.Refresh

End Sub

Private Function ValidarPagos() As Boolean
Dim bValor As Boolean



If lblNroDocumento2.Caption = "" Then
    ValidarPagos = False
    MsgBox "Seleccione el documento (BADE o FADE)"
    cmdBuscarDocumento.SetFocus
    Exit Function
End If


If val(lblSaldoSoles) = 0 Then
        MsgBox "Ya no hay saldo por cancelar para este documento"
        
        Exit Function

End If




If dcbFormaPago.Text = "" Then
    ValidarPagos = False
    MsgBox "Ingrese la Forma de Pago"
    dcbFormaPago.SetFocus
    Exit Function
Else
    If dcbFormaPago.BoundText = "01" Then

    ElseIf dcbFormaPago.BoundText = "02" Then
        If dcbTarjeta.Text = "" Then
            ValidarPagos = False
            MsgBox "Seleccione Tarjeta"
            dcbTarjeta.SetFocus
            Exit Function
        End If
    ElseIf dcbFormaPago.BoundText = "03" Then
        If txtNroCertificadoRetencion.Text = "" Then
            ValidarPagos = False
            MsgBox "Ingrese Nro.Cert.Retencion"
            txtNroCertificadoRetencion.SetFocus
            Exit Function
        End If
'    ElseIf dcbFormaPago.BoundText = "04" Then
'        If txtNroDepositoDetraccion.Text = "" Then
'            ValidarPagos = False
'            MsgBox "Ingrese Nro.Dep.Detraccion"
'            Exit Function
'        End If
    ElseIf dcbFormaPago.BoundText = "04" Then
           If dcbBanco.Text = "" Then
                ValidarPagos = False
                MsgBox "Seleccione Banco"
                dcbBanco.SetFocus
                Exit Function
           End If
            
           If txtNroCuenta.Text = "" Then
                ValidarPagos = False
                MsgBox "Ingrese Nro Cuenta"
                txtNroCuenta.SetFocus
                Exit Function
           End If
           
           If txtNroOperacion.Text = "" Then
                ValidarPagos = False
                MsgBox "Ingrese Nro Operacion"
                txtNroOperacion.SetFocus
                Exit Function
           End If
    End If
End If

If cboMoneda1.Text = "" Then
    ValidarPagos = False
    MsgBox "Seleccione moneda"
    cboMoneda1.SetFocus
    Exit Function
ElseIf cboMoneda1.Text = "SOLES" Then

    If txtMontoSoles.Text = "" Then
        ValidarPagos = False
        MsgBox "Ingrese monto del pago"
        txtMontoSoles.SetFocus
        Exit Function
    Else
        If Not IsNumeric(txtMontoSoles.Text) Then
            ValidarPagos = False
            MsgBox "Ingrese valor numerico"
            txtMontoSoles.SetFocus
            Exit Function
        End If
    End If

ElseIf cboMoneda1.Text = "DOLARES" Then

    If txtMontoDolares.Text = "" Then
        ValidarPagos = False
        MsgBox "Ingrese monto del pago"
        txtMontoDolares.SetFocus
        Exit Function
    Else
        If Not IsNumeric(txtMontoDolares.Text) Then
            ValidarPagos = False
            MsgBox "Ingrese valor numerico"
            txtMontoDolares.SetFocus
            Exit Function
        End If
    End If
    
End If


If cboMoneda1.Text = "SOLES" Then
    If val(txtMontoSoles) > val(lblSaldoSoles) Then
        ValidarPagos = False
        MsgBox "El monto a pagar no debe ser mayor que el saldo"
        txtMontoSoles.SetFocus
        Exit Function
    End If
    
ElseIf cboMoneda1.Text = "DOLARES" Then
    If val(txtMontoDolares) > val(lblSaldoDolares) Then
        ValidarPagos = False
        MsgBox "El monto a pagar no debe ser mayor que el saldo"
        txtMontoDolares.SetFocus
        Exit Function
    End If
    
End If




ValidarPagos = True




End Function

Private Function ValidarConsumo() As Boolean
    

  For i = gfax2.LowerBound(1) To gfax2.UpperBound(1)
    If gfax2(i, 1) = "" Then
      gfax2(i, 0) = CStr(i + 1)

        MsgBox "Debe registrar un artìculo."
        ValidarConsumo = False
        Exit Function
           
    End If
  Next
  
  ValidarConsumo = True
End Function

Private Function ValidarFactura() As Boolean
Dim bValor As Boolean
If txtTarjeta = "" Or txtLocal = "" Or txtNombres = "" Or dcbLocal.Text = "" Then
    ValidarFactura = False
    MsgBox "Ingrese correctamente el cliente"
    txtTarjeta.SetFocus
    Exit Function
End If

If cboTipoDocumento.Text = "" Then
    ValidarFactura = False
    MsgBox "Ingrese el Tipo Documento"
    cboTipoDocumento.SetFocus
    Exit Function
End If

If dcbTipoCredito.Text = "" Then
    ValidarFactura = False
    MsgBox "Ingrese el Tipo Credito"
    dcbTipoCredito.SetFocus
    Exit Function
End If

If cboTipoDocumento.Text = "FADE" And txtRUC = "" Then
    ValidarFactura = False
    MsgBox "Ingrese el RUC del cliente"
    txtRUC.SetFocus
    Exit Function
End If


  For i = gfax.LowerBound(1) To gfax.UpperBound(1)
    If gfax(i, 1) = "" Then
      gfax(i, 0) = CStr(i + 1)
        If gfax(i, 6) = "" Then gfax(i, 6) = "1.00"
        If gfax(i, 7) = "" Then gfax(i, 7) = "0.00"
        If gfax(i, 8) = "" Then gfax(i, 8) = "0.00"
        If gfax(i, 9) = "" Then gfax(i, 9) = "0.00"
        If gfax(i, 11) = "" Then gfax(i, 9) = "0"
        If gfax(i, 12) = "" Then gfax(i, 9) = "0.00"
        MsgBox "Debe registrar un artìculo."
        ValidarFactura = False
        Exit Function
           
    End If
  Next


ValidarFactura = True


End Function
Private Function BuscarProducto(sCodCatalogo)
Dim cnSQL As ADODB.Connection
Dim sSQL As String
Dim ADORS As ADODB.Recordset
Dim xCod As String

xCod = ""

 If Not oDBAdmin.AbrirBD(cnSQL, psConnectString) Then GoTo Salir

  sSQL = "SELECT cCodArtic FROM Articulo WHERE cCodCatal='" & sCodCatalogo & "'"
  
  If Not oDBAdmin.EjecutarConsulta(cnSQL, sSQL, ADORS) Then GoTo Salir
  
   If Not ADORS.EOF Then
        xCod = ADORS!CCODARTIC
   Else
        xCod = ""
   End If
   
   BuscarProducto = xCod
Salir:
Set ADORS = Nothing
Set cnSQL = Nothing

  
End Function
Private Function ObtenerSaldoDocumento(TipoDoc As String, SerieDoc As String, NroDoc As String)
Dim cnSQL As ADODB.Connection
Dim ADORS As ADODB.Recordset
Dim sSQL As String

sSQL = "select MontoRestante=v.TotVta-(select isnull(sum(Monto),0) as TotalPago from pagos where TipoDoc=v.TipoDoc and cSerieDoc=v.cSerieDoc and NroDoc=v.NroDoc) " _
& "from venta01 v Where v.TipoDoc='" & TipoDoc & "' and v.cSerieDoc='" & SerieDoc & "' and v.NroDoc='000032' "

If Not oDBAdmin.AbrirBD(cnSQL, psConnectString) Then GoTo Salir 'OMNISYS
If Not oDBAdmin.EjecutarConsulta(cnSQL, sSQL, ADORS) Then GoTo Salir

If Not ADORS.EOF Then
    ObtenerSaldoDocumento = ADORS("MontoRestante")
Else
    ObtenerSaldoDocumento = 0
End If

Salir:
Set cnSQL = Nothing
End Function

Public Sub CargarPagos(TipoDoc As String, SerieDoc As String, NroDoc As String, Moneda As String, Saldo As Double, SaldoUSD As Double)
Dim cnSQL As ADODB.Connection
Dim ADORS As ADODB.Recordset
Dim sSQL As String

iTipoDoc = TipoDoc
iSerieDoc = SerieDoc
iNroDoc = NroDoc
iMonedaDoc = Moneda
iSaldo = Saldo
iSaldoUSD = SaldoUSD

sSQL = "select cSerieDocPago,NroDocPago,fechapago,FormaPagoDsc=(select vDscTipoPago from tipoformapago where cCodTipoPago=P.FormaPago), " _
& "DocFormaPago= " _
& "Case FormaPago " _
& "when '02' then (select descrip from tipo_tarjeta where cod_tar=P.IdTarjeta) " _
& "when '03' then P.NroCertificadoRetencion " _
& "when '04' then(select vDscBanco from banco where cCodBanco= P.IdBanco) " _
& "Else '' end, monto, " _
& "moneda= Case moneda when 'N' then 'Soles' Else 'Dolares' End, " _
& "P.IdTarjeta,P.IdBanco,P.NroCtaBancaria,P.NroOperacion,P.NroCertificadoRetencion,P.NroDepositoDetraccion,P.cClieCode,p.idLocal " _
& "from pagos P Where P.TipoDoc='" & TipoDoc & "' and P.cSerieDoc='" & SerieDoc & "' and P.NroDoc='" & NroDoc & "' and P.FechaAnulacion is null order by P.NroItem "

If Not oDBAdmin.AbrirBD(cnSQL, psConnectString) Then GoTo Salir 'OMNISYS

If Not oDBAdmin.EjecutarConsulta(cnSQL, sSQL, ADORS) Then GoTo Salir

Set dgdPagos.DataSource = ADORS


lblNroDocumento2.Caption = NroDoc

 lblMoneda = Moneda
 lblSaldoSoles.Caption = Format(Saldo, "0.00")
 lblSaldoDolares.Caption = Format(SaldoUSD, "0.00")

If TipoDoc = "01" Then
    'lblTipoDocumento.Caption = "FADE"
    cboTipoDocumento1.Text = "FADE"
    
    If RetornarPendientePagoDetracc(SerieDoc, NroDoc) = True Then
        If val(lblSaldoSoles) = 0 Then
            'si no hay saldo quiere decir que el cliente pago todo y la detracc debe ser cancelada por GV
            lblDetraccion.Visible = True
            cmdActualizarDetracc.Visible = True
        Else
            'aun hay saldo x cancelar la detracc puede ser pagada por el cliente o por GV
            lblDetraccion.Visible = False
            cmdActualizarDetracc.Visible = False
        End If
        'lblDetraccion.Visible = True
    Else
        lblDetraccion.Visible = False
        cmdActualizarDetracc.Visible = False
    End If
    
ElseIf TipoDoc = "02" Then
    'lblTipoDocumento.Caption = "BADE"
    cboTipoDocumento1.Text = "BADE"
    
    lblDetraccion.Visible = False
    cmdActualizarDetracc.Visible = False
End If

cboTipoDocumento1.Enabled = False
Salir:
Set cnSQL = Nothing


End Sub
Private Sub RegistrarPago()
Dim cnSQL As ADODB.Connection
Dim ADORS As ADODB.Recordset
Dim sSQL As String
Dim iCodPago As Integer
Dim iNroItem As Integer
Dim sTipoDoc As String
Dim scSerieDoc As String
Dim sNroDoc As String
Dim sFormaPago As String
Dim dFechaPago As Date
Dim iTipoVenta As Integer
Dim sTipoTarjeta 'As String
Dim sCodBanco 'As String
Dim sNroCuenta 'As String
Dim sNroOperacion 'As String
Dim sNroDepDetraccion 'As String
Dim sNroCertRetencion 'As String
Dim nMontoSoles As Double
Dim nMontoDolares As Double
Dim nCodCliente As Long
Dim nCodLocal As Integer
Dim smoneda As String
Dim nMonto As Double
Dim sssql As String
Dim rs1 As Recordset
Dim Texto_imprimir As String
Dim p_1 As Integer
Dim sTarjeta As String
Dim cdocTipo As String
Dim cDocSerie As String
Dim cDocCodigofull As Long
Dim nImporte As Double, iServicio, nPuntos As Double, nPtosImp As Double
Dim idLocal As String

On Error GoTo Salir

sFormaPago = dcbFormaPago.BoundText
dFechaPago = DTPFechaPago


sTipoDoc = P_TipoDoc
scSerieDoc = P_cSerieDoc
sNroDoc = lblNroDocumento2
nCodCliente = P_cClienteCode
nCodLocal = P_IdLocal



If sFormaPago = "01" Then
    iTipoVenta = 6

    sTipoTarjeta = "Null"
    sNroCertRetencion = "Null"
    sNroDepDetraccion = "Null"
    sCodBanco = "Null"
    sNroCuenta = "Null"
    sNroOperacion = "Null"
ElseIf sFormaPago = "02" Then
    iTipoVenta = 7

    sTipoTarjeta = "'" & dcbTarjeta.BoundText & "'"
    sNroCertRetencion = "Null"
    sNroDepDetraccion = "Null"
    sCodBanco = "Null"
    sNroCuenta = "Null"
    sNroOperacion = "Null"
ElseIf sFormaPago = "03" Then
    iTipoVenta = 7
    
    sNroCertRetencion = "'" & txtNroCertificadoRetencion & "'"
    sTipoTarjeta = "Null"
    sNroDepDetraccion = "Null"
    sCodBanco = "Null"
    sNroCuenta = "Null"
    sNroOperacion = "Null"
'ElseIf sFormaPago = "04" Then
'    sNroDepDetraccion = "'" & txtNroDepositoDetraccion & "'"
'    sTipoTarjeta = "Null"
'    sNroCertRetencion = "Null"
'    sCodBanco = "Null"
'    sNroCuenta = "Null"
'    sNroOperacion = "Null"
ElseIf sFormaPago = "04" Then
    iTipoVenta = 7

    sCodBanco = "'" & dcbBanco.BoundText & "'"
    sNroCuenta = "'" & txtNroCuenta & "'"
    sNroOperacion = "'" & txtNroOperacion & "'"
    sNroDepDetraccion = "Null"
    sTipoTarjeta = "Null"
    sNroCertRetencion = "Null"
    
End If

If cboMoneda1.Text = "SOLES" Then
    smoneda = "N"
    nMonto = txtMontoSoles.Text
ElseIf cboMoneda1.Text = "DOLARES" Then
    smoneda = "E"
    nMonto = txtMontoDolares.Text
End If


nMontoSoles = Format(Abs(txtMontoSoles.Text), "0.00")
nMontoDolares = Format(Abs(nMontoSoles / nTipoCambio), "0.00")

  If Not oDBAdmin.AbrirBD(cnSQL, psConnectString) Then GoTo Salir 'OMNISYS
  
  cnSQL.BeginTrans
  ADOCnn.BeginTrans

'INICIO GRABA ACCESS-------------------------------------------------------------------------------------
'  If piEmitevoucher <> 1 Then
'    CalculaTotales
'    CalculoVuelto
'  End If
  cDocCodigofull = 0
  p_1 = 0
  
  ConectarBDCliente
  'Verifica si es Factura
  If Not Trim(Me.txtRUC.Text) = "" Then
    blnfactura = True
    cRuc = Trim(Me.txtRUC.Text)
    cdocTipo = "01"
    cDocSerie = kSERIE_FACTURA
  Else
    cRuc = ""
    cdocTipo = "02"
    cDocSerie = kSERIE
  End If
  
  '--------------------
  '-- Registra Venta --
  '--------------------

   
     'SE OBTIENE FECHA DEL SISTEMA DE LA BASE DE DATOS DE SQL - version 2.0.5
   
   Dim cnFECHASQL As ADODB.Connection
   Dim sqlFECHASIS As String
   Dim rsFEchaSis As ADODB.Recordset
      
   If oDBAdmin.AbrirBD(cnFECHASQL, psConnectString, False) = True Then
     
     sqlFECHASIS = "select convert(varchar,getdate(),120) as fechasis"
     If oDBAdmin.EjecutarConsulta(cnFECHASQL, sqlFECHASIS, rsFEchaSis) = True Then
         
         If rsFEchaSis!fechasis <> "" Then
             sFecha = rsFEchaSis!fechasis
         End If

     Else
         'no pudo abrir el rs: que consulte al access
         'MsgBox "No se pudo obtener la fecha, hay problemas de conexión de la red con la Base de Datos Principal", vbOKOnly + vbExclamation, "Aviso"
         sFecha = Format(Now(), "DD/MM/YYYY hh:mm")
         'Unload Me
     End If

     Set cnFECHASQL = Nothing

   Else
     'no pudo conectarse al sql: que consulte al access
      'MsgBox "No se pudo obtener la fecha, hay problemas de conexión de la red con la Base de Datos Principal", vbOKOnly + vbExclamation, "Aviso"
      sFecha = Format(Now(), "DD/MM/YYYY hh:mm")
      'Unload Me
   End If
   
   'FIN FECHA DEL SISTEMA DE LA BASE DE DATOS DE SQL


  'sFecha = Format(Now(), "DD/MM/YYYY hh:mm")

  Set ADORS = Nothing
  
  'iTipoVenta = 6 ''PADE igual en el otro form
  
  iFlagTipo = iTipoVenta
  If iTipoVenta = 4 Then
    iSigno = -1
    iFlagTipo = 1
  Else
    iSigno = 1
    iFlagTipo = iTipoVenta
  End If
  If iTipoVenta = 5 Then
    iFlagTipo = 1
  End If
  
  iCodOperRela = 0
  
  'vd 05/08/07 TDBGrid1.Update
      
  'Verifica si es un tipo de operaciòn que necesita password: Anulación o Descuento
  For i = gfax.LowerBound(1) To gfax.UpperBound(1)
    sTexto = IIf(Replace(gfax(i, 9), ",", "") = "", "0", Replace(gfax(i, 9), ",", ""))
    If val(sTexto) <> 0 Then
      bAcceso = True
      Exit For
    End If
  Next
  
  If bAcceso Then
    bAcceso = False
    Load frmAutorizarOperacion
    Set frmAutorizarOperacion.frmPadre = Me
    frmAutorizarOperacion.Show vbModal
    If Not bAcceso Then Exit Sub
    'bAcceso = False
  End If
  '--------Abre la gaveta de dinero automaticamente al aceptar la venta ----
  Dim opc_gaveta As String
  opc_gaveta = LeerCfg("PARAMETROS", "GAVETA", psArchivoCfg)
  If Trim(UCase(opc_gaveta)) = "S" Then
    Abre_Gaveta_Dinero (LeerCfg("PARAMETROS", "PRINTER", psArchivoCfg))
  End If
  '-------------------------------------------------------------------------
  If iTipoVenta = 6 Or iTipoVenta = 7 Then
'VALIDACIONES
'    If Not IsNumeric(Replace(IIf(txtPagoAdelantado = "", "0.00", txtPagoAdelantado), ",", "")) Then Exit Sub
'    If Not IsNumeric(Replace(IIf(txtPADEDolares = "", "0.00", txtPADEDolares), ",", "")) Then Exit Sub
'    If val(Replace(IIf(txtPagoAdelantado = "", "0.00", txtPagoAdelantado), ",", "")) = 0 And _
'       val(Replace(IIf(txtPADEDolares = "", "0.00", txtPADEDolares), ",", "")) = 0 Then
'      MsgBox "Debe registar una cantidad mayor que cero."
'      txtPagoAdelantado.SetFocus
'      Exit Sub
'    End If

  End If
 
  'Calculo de vueltos
  Dim iVueltoSoles As Double
  
  If iTipoVenta = 1 Or iTipoVenta = 4 Then   'Or iTipoVenta = 8
    If Trim(Me.txtEfectivoDolares.Text) = "" Then Me.txtEfectivoDolares.Text = "0.00"
    If Trim(Me.txtEfectivoSoles.Text) = "" Then Me.txtEfectivoSoles.Text = "0.00"
    
    If val(Replace(Me.txtEfectivoDolares.Text, ",", "")) = 0 And _
      val(Replace(Me.txtEfectivoSoles.Text, ",", "")) = 0 Then
      Me.txtEfectivoSoles.Text = Me.txtSoles
    End If
  End If

  'Configura la Impresora por default
  'sw 1 = Efectivo
  'sw 2 = VOUCHER
  'sw 3 = O/C
  'sw 4 = N/C
  'sw 5 = PADE
  'sw 6 = PADV
  'sw 7 = LIQPAD
  'sw 8 = ANULAR TRANSACCION
  'sw 9 = RECAUDACION
  
  Select Case iTipoVenta
    Case 4, 5, 6, 7, 8
      If iTipoVenta = 4 Then iTipoVenta = 20 ' O/C
      If iTipoVenta = 5 Then iTipoVenta = 21 ' N/C
      If iTipoVenta = 6 Then iTipoVenta = 22 ' PADE
      If iTipoVenta = 7 Then iTipoVenta = 23 ' PADV
      If iTipoVenta = 8 Then iTipoVenta = 24 ' LIQPAD
      ConfiguraImpresora kPAR_IMPRESORA_ALTERNA
    Case Else
      ConfiguraImpresora kPAR_IMPRESORA
  End Select
  
  Select Case iTipoVenta
    Case 20, 21, 22, 23, 24
      sSQL = "SELECT MAX(cOperCode) AS maximo FROM OperacionParalela"
    Case Else
      sSQL = "SELECT MAX(cOperCode) AS maximo FROM Operacion"
  End Select
  
  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
      'EscribirCfg "PARAMETROS", "cOpeB", psArchivoCfg, Str(iCodOper + 1)
    End If
  End If
  
  'Inicializa Recorset
  If iTipoVenta <> 2 And piEmitevoucher <> 1 Then
    Set rsPagTar = New Recordset
  End If

  If iCodOper = 1 Then
'    kOPERACION = LeerCfg("PARAMETROS", "cOpeB", psArchivoCfg)
'    iCodOper = Val(kOPERACION)
  End If
  
  'Si hay vuelto se convierte en iTipo = 5
  If iTipoVenta = 1 And (val(Replace(txtVueltoSoles, ",", "")) <> 0 Or val(Replace(txtVueltoDolares, ",", "")) <> 0) Then
    iTipoVenta = 5
  End If
  
  'Asigna valor para liquidar NC
  If iTipoVenta = 24 Then blLiquidaVenta = True
    
  'Registra los datos del producto
  If iTipoVenta = 22 Or iTipoVenta = 23 Or iTipoVenta = 24 Then
    nProducto = -1
  Else
    ReDim Producto(gfax.UpperBound(1))
    
    For i = gfax.LowerBound(1) To gfax.UpperBound(1)
      Producto(i).Almacen = kPAR_ALMACEN
      Producto(i).Cant = Replace(gfax(i, 6), ",", "")
      Producto(i).PUnit = Replace(gfax(i, 7), ",", "")
      Producto(i).Codigo = gfax(i, 1)
      Producto(i).nombre = gfax(i, 3)
      If gfax(i, 8) = "+" Then
        Producto(i).Dscto = Replace(IIf(gfax(i, 9) = "", 0, gfax(i, 9)), ",", "")
      Else
        Producto(i).Dscto = -1 * Replace(IIf(gfax(i, 9) = "", 0, gfax(i, 9)), ",", "")
      End If
      
      Producto(i).Canje = gfax(i, 11)
      Producto(i).Ptos = val(Replace(gfax(i, 12), ",", ""))
      Producto(i).Serv = gfax(i, 13)
    Next
    nProducto = gfax.UpperBound(1)
  End If
  

  If Trim(P_cClienteCode) <> "" Then
    sTarjeta = Right("00000000" + Trim(P_cClienteCode), 8)
  Else
    sTarjeta = ""
  End If
  
  'sw To SQL Server add
  idLocal = IIf(Trim(P_IdLocal) = "", "NULL", Trim(P_IdLocal))
  
  'Calcula el total de las ventas
  iTotalVenta = Replace(txtSoles, ",", "")
  'lblTotal.Caption = "TOT:" + Right("               " + Format(CStr(iTotalVenta), "0.00"), 14)
  
  'Captura Serie y Codigo del Documento
  
  Select Case iTipoVenta
    Case 20
      cdocTipo = "10"
    Case 21
      cdocTipo = "11"
   Case 22
      cdocTipo = "12"
   Case 23
      cdocTipo = "13"
   Case 24
      cdocTipo = "14"
  End Select
  
  Dim dbCalculado As Boolean
  Dim ddtotefectivo, ddtotvuelto As Double
  Dim mon As Integer
  Dim ierroritm As Integer
  ierroritm = 0
  dbCalculado = False
  
  Do While dbCalculado = False And ierroritm < 3
    Select Case iTipoVenta
      Case 20, 21, 22, 23, 24
        If iTipoVenta = 22 Or iTipoVenta = 23 Then 'PADE o PADV
'          iDolaresEfectivo = val(Replace(txtPADEDolares, ",", ""))
'          iEfectivo = val(Replace(txtPagoAdelantado, ",", ""))
'
'          If iEfectivo > 0 Then
'            mon = 1
'          End If
'          If iDolaresEfectivo > 0 Then
'            mon = 2
'          End If
'
'          If mon = 1 Then 'Soles
'            iTotal = val(Replace(txtPagoAdelantado, ",", ""))
'            iMontoDolares = CDbl(Format(CStr(iTotal / nTipoCambio), "0.00"))
'            'iMontoDolares = CDbl(Format(CStr(iTotal / nTipoCambio), "0.00"))
'          End If
'
'          If mon = 2 Then 'Dolares
'            iMontoDolares = val(Replace(txtPADEDolares, ",", ""))
'            iTotal = CDbl(Format(CStr(iMontoDolares * nTipoCambio), "0.00"))
'            'iTotal = CDbl(Format(CStr(iMontoDolares * nTipoCambio), "0.00"))
'          End If
          
          iDolaresEfectivo = txtMontoDolares
          iEfectivo = txtMontoSoles
          If cboMoneda1.Text = "SOLES" Then
            mon = 1
            iTotal = val(Replace(txtMontoSoles, ",", ""))
            iMontoDolares = CDbl(Format(CStr(iTotal / nTipoCambio), "0.00"))
          ElseIf cboMoneda1.Text = "DOLARES" Then
            mon = 2
            iMontoDolares = val(Replace(txtMontoDolares, ",", ""))
            iTotal = CDbl(Format(CStr(iMontoDolares * nTipoCambio), "0.00"))
          End If
          
          
          iSolesEfectivo = iEfectivo
          iVuelto = 0
          iVueltoDolares = 0
        Else
          
          iTotal = val(Replace(txtSoles, ",", ""))
          iMontoDolares = val(Replace(txtDolares, ",", ""))
          If piEmitevoucher = 1 And blLiquidaVenta = True Then
            iDolaresEfectivo = val(Replace(txtliqefectivodolares, ",", ""))
            iSolesEfectivo = val(Replace(txtliqefectivosoles, ",", ""))
            iEfectivo = val(Replace(txtliqefectivosoles, ",", ""))
            iVuelto = val(Replace(txtliqvueltosoles, ",", ""))
            iVueltoDolares = val(Replace(ttxliqvueltodolares, ",", ""))
          Else
            iDolaresEfectivo = val(Replace(txtEfectivoDolares, ",", ""))
            iSolesEfectivo = val(Replace(txtEfectivoSoles, ",", ""))
            iEfectivo = val(Replace(txtEfectivoSoles, ",", ""))
            iVuelto = val(Replace(txtVueltoSoles, ",", ""))
            iVueltoDolares = val(Replace(txtVueltoDolares, ",", ""))
          End If
          If iVuelto < 0 Then iVuelto = 0
          If iDolaresEfectivo < 0 Then iDolaresEfectivo = 0
          If iVueltoDolares < 0 Then iVueltoDolares = 0
          If iTipoVenta = 21 Then iCodOperRela = val(txtTX.Text)
          If iTipoVenta = 20 And Trim(txtLiq.Text) <> "" Then iCodOperRela = val(txtLiq.Text)
        End If
      Case Else
        iVuelto = val(Replace(txtVueltoSoles, ",", ""))
        iTotal = val(Replace(txtSoles, ",", ""))
        If iVuelto < 0 Then iVuelto = 0
        If piEmitevoucher = 1 And bLiquidaNC Then
          iEfectivo = val(Replace(txtliqefectivosoles, ",", ""))
          iDolaresEfectivo = val(Replace(txtliqefectivodolares, ",", ""))
          iVueltoDolares = val(Replace(ttxliqvueltodolares, ",", ""))
          iVuelto = val(Replace(Me.txtliqvueltosoles, ",", ""))
        Else
          iEfectivo = val(Replace(txtEfectivoSoles, ",", ""))
          iDolaresEfectivo = val(Replace(txtEfectivoDolares, ",", ""))
          iSolesEfectivo = val(Replace(txtEfectivoSoles, ",", ""))
          iVueltoDolares = val(Replace(txtVueltoDolares, ",", ""))
        End If
        If iVueltoDolares < 0 Then iVueltoDolares = 0
    End Select
    
    ddtotefectivo = 0 'Round(iSolesEfectivo + (iDolaresEfectivo * nTipoCambio), 2)
    ddtotvuelto = 0 'Round(iVuelto + (iVueltoDolares * nTipoCambio), 2)
    
    If (iTipoVenta <> 2 And iTipoVenta <> 22 And iTipoVenta <> 23 And iTipoVenta <> 21 And iTipoVenta <> 24) And (Round(ddtotefectivo - ddtotvuelto, 2) <> Round(iTotal, 2)) Then
      MsgBox "Ocurrio un error de Cálculo"
      dbCalculado = False
      ierroritm = ierroritm + 1
    Else
      dbCalculado = True
      ierroritm = 0
    End If
  Loop
  '------------------------
  '-- Captura Parámetros --
  '------------------------

  Texto_imprimir = ""
  Call CabeceraImpresion
  sTexto = ""
  
  sssql = "SELECT sImpresora, sImpresoraAlterna from Configuracion"
  If Not oDBAdmin.EjecutarConsulta(ADOCnn, sssql, rs1) Then GoTo Salir
  impr_1 = rs1.Fields("sImpresora")
  impr_2 = rs1.Fields("sImpresoraAlterna")
  
  'Pregunta si x.Devicename tiene el mismo nombre que el nombre de la impresora por donde necesitas sacar la impresion.
  If iTipoVenta = 1 Or iTipoVenta = 2 Or iTipoVenta = 5 Then
    p_1 = 1
  Else
    p_1 = 2
  End If
  
  printer.FontSize = 8 '11
  printer.FontName = "Courier New"
  
  Select Case iTipoVenta
    Case 20, 21, 22, 23, 24
    Case Else
      For i = 0 To UBound(sCabecera) - 1
        If Not Trim(sCabecera(i)) = "" Then
          sTexto = sTexto + Right(Space(60) + sCabecera(i), Int(Len(Space(40) + sCabecera(i)) / 2)) + vbCrLf
        End If
      Next
  End Select
  
  'Linea de Datos del Socio
  If Not sTarjeta = "" Then
    sTexto = sTexto + vbCrLf + " COD.TARJ.: " + sTarjeta + " "
    If Not blnfactura = True Then
      sTexto = sTexto + vbCrLf + " NOMBRE: " + P_DscCliente + vbCrLf
    End If
  Else
    If Not blnfactura = True And Not Trim(txtNombres.Text) = "" Then
      sTexto = sTexto + vbCrLf + " NOMBRE: " + UCase(Trim(P_DscCliente)) + vbCrLf
    End If
  End If
  
  If blnfactura = True Then
    sTexto = sTexto + vbCrLf + " NOMBRE: " & "____________________________"
    sTexto = sTexto + vbCrLf + vbCrLf + "         " & "____________________________" + vbCrLf
    sTexto = sTexto + vbCrLf + " RUC Cliente: " & Trim(Me.txtRUC.Text) + vbCrLf
  End If
  
  ' Obteniendo Nro de documento
  sSQL = "SELECT  * FROM Config_Documento WHERE cTipoDoc='" & cdocTipo & "'"
  If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir


  
  
  If blnfactura = True Then
    If ADORS.EOF Then
      kSERIE_FACTURA = "F01"
      sSQL = "INSERT INTO Config_Documento (cTipoDoc,cOperCode,nDocCodigo,cSerieDoc,cUserDesc,dUltAct,observacion) " & _
             " VALUES ('01',0, 0, 'F01','',#" & Date & "#,'Primer Registro') "
      If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
      cDocCodigofull = 1
    Else
      kSERIE_FACTURA = LeerCampo(ADORS!cSerieDoc)
      cDocCodigofull = LeerCampo(ADORS!nDocCodigo) + 1
    End If
    cDocSerie = kSERIE_FACTURA
  Else
    Select Case cdocTipo
      Case "10"
        If ADORS.EOF Then
          KSERIE_PARALELO = "OC1"
          sSQL = "INSERT INTO Config_Documento (cTipoDoc,cOperCode,nDocCodigo,cSerieDoc,cUserDesc,dUltAct,observacion) " & _
                 " VALUES ('10',0, 0, 'OC1','',#" & Date & "#,'Primer Registro') "
          If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
          cDocCodigofull = 1
        Else
          KSERIE_PARALELO = LeerCampo(ADORS!cSerieDoc)
          cDocCodigofull = LeerCampo(ADORS!nDocCodigo) + 1
        End If
        cDocSerie = KSERIE_PARALELO
            
      Case "11"
        If ADORS.EOF Then
          KSERIE_PARALELO = "NC1"
          sSQL = "INSERT INTO Config_Documento (cTipoDoc,cOperCode,nDocCodigo,cSerieDoc,cUserDesc,dUltAct,observacion) " & _
                 " VALUES ('11',0, 0, 'NC1','',#" & Date & "#,'Primer Registro') "
          If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
          cDocCodigofull = 1
        Else
          KSERIE_PARALELO = LeerCampo(ADORS!cSerieDoc)
          cDocCodigofull = LeerCampo(ADORS!nDocCodigo) + 1
        End If
        cDocSerie = KSERIE_PARALELO
            
      Case "12"
        If ADORS.EOF Then
          KSERIE_PARALELO = "PA1"
          sSQL = "INSERT INTO Config_Documento (cTipoDoc,cOperCode,nDocCodigo,cSerieDoc,cUserDesc,dUltAct,observacion) " & _
                 " VALUES ('12',0, 0, 'PA1','',#" & Date & "#,'Primer Registro') "
          If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
          cDocCodigofull = 1
        Else
          KSERIE_PARALELO = LeerCampo(ADORS!cSerieDoc)
          cDocCodigofull = LeerCampo(ADORS!nDocCodigo) + 1
        End If
        cDocSerie = KSERIE_PARALELO
            
      Case "13"
        If ADORS.EOF Then
          KSERIE_PARALELO = "PV1"
          sSQL = "INSERT INTO Config_Documento (cTipoDoc,cOperCode,nDocCodigo,cSerieDoc,cUserDesc,dUltAct,observacion) " & _
                 " VALUES ('13',0, 0, 'PV1','',#" & Date & "#,'Primer Registro') "
          If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
          cDocCodigofull = 1
        Else
          KSERIE_PARALELO = LeerCampo(ADORS!cSerieDoc)
          cDocCodigofull = LeerCampo(ADORS!nDocCodigo) + 1
        End If
        cDocSerie = KSERIE_PARALELO
          
      Case "14"
        If ADORS.EOF Then
          KSERIE_PARALELO = "LQ1"
          sSQL = "INSERT INTO Config_Documento (cTipoDoc,cOperCode,nDocCodigo,cSerieDoc,cUserDesc,dUltAct,observacion) " & _
                 " VALUES ('14',0, 0, 'LQ1','',#" & Date & "#,'Primer Registro') "
          If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
          cDocCodigofull = 1
        Else
          KSERIE_PARALELO = LeerCampo(ADORS!cSerieDoc)
          cDocCodigofull = LeerCampo(ADORS!nDocCodigo) + 1
        End If
        cDocSerie = KSERIE_PARALELO
          
      Case Else
        If ADORS.EOF Then
          kSERIE = "B01"
          sSQL = "INSERT INTO Config_Documento (cTipoDoc,cOperCode,nDocCodigo,cSerieDoc,cUserDesc,dUltAct,observacion)" & _
                 " VALUES ('02',0, 0, 'B01', '', #" & Date & "#,'Primer Registro') "
          If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
          cDocCodigofull = 1
        Else
          kSERIE = LeerCampo(ADORS!cSerieDoc)
          cDocCodigofull = LeerCampo(ADORS!nDocCodigo) + 1
        End If
        cDocSerie = kSERIE
    End Select
  End If
  
  '------------------Validacion de Numeración Correlativa ----------------------------
  'ACA TENGO QUE VALIDARLO CONTRA LA TABLA PAGOS DEL SQL

  
  
  
  If cdocTipo = "01" Or cdocTipo = "02" Then
    sSQL = "SELECT MAX(cDocCodigo) AS maximo FROM Operacion WHERE cDocTipo = '" & cdocTipo & "'"
  Else
  
        'aca se tendria que primero determinar cual es mayor el valor del access o el sql
            Dim nValorAccess As Long
            Dim nValorSQL As Long
            Dim nValorMaximo As Long
            Dim ADORS1 As ADODB.Recordset
        
        sSQL = "SELECT IIf(IsNull(Max([cDocCodigo])),0,Max([cDocCodigo])) AS maximo FROM OperacionParalela WHERE cDocTipo = '" & cdocTipo & "'"
        
        'sSQL = "SELECT MAX(cDocCodigo) AS maximo FROM Operacion WHERE cDocTipo = '" & cdocTipo & "'"
        If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS1) Then GoTo Salir
        nValorAccess = ADORS1!Maximo
        
        
        
'        If iTipoVenta = 6 Then
'            ' Es PA--> Access cDocTipo=12
'        Else
'            ' Es PV--> Access cDocTipo=13
'            sSQL = "SELECT MAX(cDocCodigo) AS maximo FROM OperacionParalela WHERE cDocTipo = '" & cdocTipo & "'"
'        End If
  
        
        sSQL = "SELECT  ISNULL(MAX(CAST(NroDocPago AS INT)),0) AS maximo FROM Pagos WHERE cSerieDocPago='" & KSERIE_PARALELO & "'"
        If Not oDBAdmin.EjecutarConsulta(cnSQL, sSQL, ADORS) Then GoTo Salir
        nValorSQL = ADORS!Maximo
        
        
        If nValorAccess > nValorSQL Then
           nValorMaximo = nValorAccess
        Else
           nValorMaximo = nValorSQL
        End If
  
  End If
  'If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
  'If Not oDBAdmin.EjecutarConsulta(cnSQL, sSQL, ADORS) Then GoTo Salir
  
  If val(cDocCodigofull) <> val("0" & (nValorMaximo) + 1) And val("0" & nValorMaximo) > 0 Then
    Dim NameArchivo As String
    Dim archivo
    Dim Texto As String
    Dim fso, MyFile
    Set fso = CreateObject("Scripting.FileSystemObject")
    archivo = "Error_Full_1" & cdocTipo & cDocCodigofull
    If Trim(archivo) = "" Then
      archivo = "textfile"
    End If
    Texto = Texto + "Codigo generado " & cDocCodigofull & Chr(13)
    
    NameArchivo = "C:\Temp\" + Trim(archivo) + ".log"
    Set MyFile = fso.CreateTextFile(NameArchivo, True)
    cDocCodigofull = ("0" & (nValorMaximo)) + 1
    Texto = Texto + "Nuevo Codigo " & cDocCodigofull & Chr(13)
    Texto = Texto + CStr(Now)
    MyFile.WriteLine (Texto)
    MsgBox "Ocurrio un error en la numeración, se asignará el " & cDocCodigofull & " al documento "
    MyFile.Close
  End If
  '---------------Actualizando el valor de la numeración ----------------
  sSQL = "UPDATE Config_Documento " & _
         " SET cSerieDoc='" & cDocSerie & "'," & _
         " nDocCodigo=" & cDocCodigofull & " " & _
         " WHERE cTipodoc='" & cdocTipo & "'"
  If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
  '------------------Impresión de Ticket----------------------------
  
  
  If blnfactura = True Then
    sTexto = sTexto + vbCrLf + " TK NRO: " & kSERIE_FACTURA & "-" & Right("000000" & CStr(cDocCodigofull), 6) & " NS:" & kSERIE_DISCO_DURO
  Else
    Select Case iTipoVenta
      Case 20, 22, 23, 24, 21
        sTexto = sTexto + vbCrLf + " TK NRO: " & KSERIE_PARALELO & "-" & Right("000000" & CStr(cDocCodigofull), 6) & " NS:" & kSERIE_DISCO_DURO1
      Case Else
        sTexto = sTexto + vbCrLf + " TK NRO: " & kSERIE & "-" & Right("000000" & CStr(cDocCodigofull), 6) & " NS:" & kSERIE_DISCO_DURO
    End Select
  End If
  
  'Printer.Print sTexto
  Texto_imprimir = Texto_imprimir + vbCrLf + sTexto
  sTexto = ""
  
  'Cabecera segun tipo de venta
  Select Case iTipoVenta
    Case 2 'Voucher
      sTexto = "VOUCHER"
      sTexto = Right(Space(60) + sTexto, Int(Len(Space(40) + sTexto) / 2)) + vbCrLf
    Case 1, 5 ' EFECTIVO EX Dolares
      If iDolaresEfectivo > 0 Then
        sTexto = "U$(TC: " + Format(CStr(nTipoCambio), "###,##0.00") + ")"
        sTexto = Right(Space(60) + sTexto, Int(Len(Space(40) + sTexto) / 2)) + vbCrLf
      End If
    Case 4 'Anula Productos
      sTexto = "ANULA PROD"
      sTexto = Right(Space(60) + sTexto, Int(Len(Space(40) + sTexto) / 2)) + vbCrLf
    Case 20 'O/C
      sTexto = "O/C"
      sTexto = Right(Space(60) + sTexto, Int(Len(Space(40) + sTexto) / 2)) + vbCrLf
    Case 21 'NC
      sTexto = "N/C"
      sTexto = Right(Space(60) + sTexto, Int(Len(Space(40) + sTexto) / 2)) + vbCrLf
    Case 22 'PADE
      sTexto = "PADE"
      sTexto = Right(Space(60) + sTexto, Int(Len(Space(40) + sTexto) / 2)) + vbCrLf
    Case 23 'PADV
      sTexto = "PADV"
      sTexto = Right(Space(60) + sTexto, Int(Len(Space(40) + sTexto) / 2)) + vbCrLf
    Case 24 'LIQ
      sTexto = "LIQPAD"
      sTexto = Right(Space(60) + sTexto, Int(Len(Space(40) + sTexto) / 2)) + vbCrLf
  End Select
  'Printer.Print sTexto
  Texto_imprimir = Texto_imprimir + vbCrLf + sTexto + vbCrLf
  sTexto = ""
  
  'Ancho de linea = 27
  
  iSubTotal = 0
  If iTipoVenta <> 22 And iTipoVenta <> 23 Then
    iTotal = 0
  End If
  iTotItems = 0
  iTotalDscto = 0
  iServicio = 0
  iPtoItm = 0
  iPtoVta = 0
    
    
  '<<<<<<<<<<<<<<<<<<<<<<<<<-------------------------------->>>>>>>>>>>>>>>>>>>>>>>>>>>>
  If iTipoVenta = 22 Or iTipoVenta = 23 Or iTipoVenta = 24 Then
    If iTipoVenta = 24 Then
      iTotal = val(Replace(txtPagoAdelantado, ",", ""))
    End If
    
    '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 sProdDesc As String
    Dim nDscto As Double
    Dim sTeclDesc As String
    Dim toti As Double
    Dim isubtotal_1 As Double
    Dim PUnit As Double
    
    If iTipoVenta = 24 Then
      iTotal = 0
      iTotItems = 0
      
      sTexto = sTexto + "Producto         Cant Precio  SubTotal " + vbCrLf
      sTexto = sTexto + "---------------------------------------" + vbCrLf
      
'      For i = 1 To lvwTX(1).ListItems.Count
'        iOperNC = lvwTX(1).ListItems(i).Text
'        sSQL = " SELECT O.cOperCode, O.cProdCode, O.nProdCant, O.nProdPrecUnit, O.nDscto,P.sProdDesc, P.sProdDescCrta," & _
'               " O.nProdCant * O.nProdPrecUnit 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(iOperNC)
'                'O.nProdCant * O.nProdPrecUnit * (100 - O.nDscto) / 100 As TotalMonto,
'        If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
'
'        nSubtotal = 0
'        sTexto = sTexto + "TX" + CStr(iOperNC) + vbCrLf
'        Do While Not ADORS.EOF
'          nItems = LeerCampo(ADORS("nProdCant"))
'          PUnit = LeerCampo(ADORS("nProdPrecUnit"))
'          sProdDescCrta = LeerCampo(ADORS("sProdDescCrta"))
'          sProdDesc = LeerCampo(ADORS("sProdDesc"))
'
'          nDscto = LeerCampo(ADORS("nDscto"))
'          If nDscto > 0 Then
'            PUnit = PUnit * nDscto / 100 + PUnit
'          End If
'
'          sTexto = sTexto + Left(sProdDescCrta + Space(16), 16) & _
'                    " " + Right(Space(4) & CStr(nItems), 4) & _
'                    " " + Right(Space(6) & Format(CStr(PUnit), "0.00"), 6) & _
'                    " " + Right(Space(9) & Format(CStr(PUnit * nItems), "0.00"), 9) + vbCrLf
'          If nDscto < 0 Then
'             sTexto = sTexto + Left("*Dscto " + CStr(Abs(nDscto)) + " %" + Space(16), 16) & _
'                      " " + Space(11) & _
'                      " " + Right(Space(9) & Format(CStr(PUnit * nItems * nDscto / 100), "0.00"), 9) + vbCrLf
'             PUnit = PUnit * nDscto / 100 + PUnit
'
'          End If
'          nSubtotal = nSubtotal + (PUnit * nItems)
'
'          ADORS.MoveNext
'          iTotItems = iTotItems + nItems
'        Loop
'        sTexto = sTexto + Chr(13) + Left(" AV./ITEM" & Space(23), 23) + Right(Space(15) & Format(CStr(nItems), "0.00"), 15) + vbCrLf
'        iTotal = iTotal + nSubtotal
'      Next
    End If
    '----------------------------
  Else
    
    sTexto = sTexto + "Producto         Cant Precio  SubTotal " + vbCrLf
    sTexto = sTexto + "---------------------------------------" + vbCrLf
    iServicio = 0
    igvf = 0
    For i = 0 To gfax.UpperBound(1)
      If blnfactura = True Then
            
        If (Trim(gfax(i, 13)) = "SI") Then
          iSubTotal = (val(Replace(gfax(i, 6), ",", "")) * val(Replace(gfax(i, 7), ",", "")) + (val(Replace(gfax(i, 6), ",", "")) * val(Replace(gfax(i, 7), ",", "")) * Producto(i).Dscto / 100)) / (1 + kIGV + kPAR_PORCSERV * (IIf(gfax(i, 13) = "SI", 1, 0)) / 100)
          isubtotal_1 = val(Replace(gfax(i, 6), ",", "")) * val(Replace(gfax(i, 7), ",", ""))
          toti = (kPAR_PORCSERV * iSubTotal * IIf(gfax(i, 13) = "SI", 1, 0)) / 100
          IGV_1 = val(Replace(gfax(i, 15), ",", ""))
          iServicio = iServicio + val(Replace(gfax(i, 14), ",", ""))
          PUnit = val(Replace(gfax(i, 7), ",", "")) / (1 + kIGV + kPAR_PORCSERV * (IIf(gfax(i, 13) = "SI", 1, 0)) / 100)
        Else
          iSubTotal = val(Replace(gfax(i, 6), ",", "")) * val(Replace(gfax(i, 7), ",", ""))
          PUnit = val(Replace(gfax(i, 7), ",", ""))
          IGV_1 = val(Replace(gfax(i, 15), ",", ""))
        End If
            
        nDscto = Producto(i).Dscto
                        
        PUnit = val(Replace(gfax(i, 7), ",", ""))
        If nDscto > 0 Then
          PUnit = PUnit * nDscto / 100 + PUnit
        End If
        
        sTexto = sTexto + Left(Producto(i).nombre + Space(16), 16) & _
               " " + Right(Space(4) & CStr(val(Replace(gfax(i, 6), ",", ""))), 4) & _
               " " + Right(Space(6) & Format(CStr(PUnit), "0.00"), 6) & _
               " " + Right(Space(9) & Format(CStr(PUnit * val(Replace(gfax(i, 6), ",", ""))), "0.00"), 9) + vbCrLf
                         
        iTotal = iTotal + iSubTotal
        igvf = igvf + IGV_1
        iTotItems = iTotItems + val(Replace(gfax(i, 6), ",", ""))
        
      Else ' tk boleta de venta
                                                         
        If (Trim(gfax(i, 13)) = "SI") Then
          iSubTotal = (val(Replace(gfax(i, 6), ",", "")) * val(Replace(gfax(i, 7), ",", "")) + (val(Replace(gfax(i, 6), ",", "")) * val(Replace(gfax(i, 7), ",", "")) * Producto(i).Dscto / 100)) / (1 + kIGV + kPAR_PORCSERV * (IIf(gfax(i, 13) = "SI", 1, 0)) / 100)
          isubtotal_1 = val(Replace(gfax(i, 6), ",", "")) * val(Replace(gfax(i, 7), ",", ""))
          toti = (kPAR_PORCSERV * iSubTotal * IIf(gfax(i, 13) = "SI", 1, 0)) / 100
          IGV_1 = isubtotal_1 - iSubTotal - toti
          PUnit = val(Replace(gfax(i, 7), ",", "")) / (1 + kIGV + kPAR_PORCSERV * (IIf(gfax(i, 13) = "SI", 1, 0)) / 100)
        Else
          iSubTotal = val(Replace(gfax(i, 6), ",", "")) * val(Replace(gfax(i, 7), ",", ""))
          PUnit = val(Replace(gfax(i, 7), ",", ""))
          IGV_1 = 0
        End If
            
        nDscto = Producto(i).Dscto
        PUnit = val(Replace(gfax(i, 7), ",", ""))
        If nDscto > 0 Then
          PUnit = PUnit * nDscto / 100 + PUnit
        End If
        
        sTexto = sTexto + Left(Producto(i).nombre + Space(16), 16) & _
               " " + Right(Space(4) & CStr(val(Replace(gfax(i, 6), ",", ""))), 4) & _
               " " + Right(Space(6) & Format(CStr(PUnit), "0.00"), 6) & _
               " " + Right(Space(9) & Format(CStr(PUnit * val(Replace(gfax(i, 6), ",", ""))), "0.00"), 9) + vbCrLf
        
        iServicio = iServicio + val(Replace(gfax(i, 14), ",", ""))
        iTotal = iTotal + iSubTotal
        iTotItems = iTotItems + val(Replace(gfax(i, 6), ",", ""))
      End If
      'Controla el total de puntos por item y por venta
      iPtoItm = 0
      iPtoVta = 0
      IGV_1 = 0
      
      'Descuentos
      nDscto = (Producto(i).Dscto * val(Replace(gfax(i, 7), ",", "")) / 100)
      
      iSubTotalDscto = val(Replace(gfax(i, 6), ",", "")) * val(Replace(gfax(i, 7), ",", "")) + (nDscto / 100 * (val(Replace(gfax(i, 6), ",", "")) * val(Replace(gfax(i, 7), ",", ""))))
      Dim Serv As Double
       
      If Producto(i).Dscto < 0 Then
        sTexto = sTexto + Left("*Dscto " + CStr(Abs(Producto(i).Dscto)) + " %" + Space(16), 16) & _
               " " + Space(11) & _
               " " + Right(Space(9) & Format(CStr(PUnit * val(Replace(gfax(i, 6), ",", "")) * Producto(i).Dscto / 100), "0.00"), 9) + vbCrLf
      End If
            
      iTotalDscto = iTotalDscto + nDscto
        
    Next
  End If
 
  
  'Añade el % de servicio al total
    
  sTexto = sTexto + "---------------------------------------"
  Texto_imprimir = Texto_imprimir + vbCrLf + sTexto
  sTexto = ""
  
  'Total segun tipo de venta
  
  Select Case iTipoVenta
    Case 2 'Normal, Voucher
    
        If blnfactura = True Then
            sTexto = Left(" VALOR VTA" + Space(23), 23) + Right(Space(15) + Format(CStr(val(Replace(txtSoles.Text, ",", "")) - igvf - iServicio), "0.00"), 15) + vbCrLf
                       
            sTexto = sTexto + Left(" IGV" + Space(23), 23) + Right(Space(15) + Format(CStr(igvf), "0.00"), 15) + vbCrLf
            If iServicio > 0 Then
                sTexto = sTexto + Left(" SERVICIO" + "(" + kPAR_PORCSERV + " %)" + Space(23), 23) + Right(Space(15) + Format(CStr(iServicio), "0.00"), 15) + vbCrLf
            End If
            sTexto = sTexto + Left(" TOTAL VTA" + Space(23), 23) + Right(Space(15) + Format(CStr(val(Replace(txtSoles.Text, ",", ""))), "0.00"), 15) + vbCrLf + vbCrLf
                        
            toti = val(Replace(txtSoles, ",", ""))
            iTotal = 0
            If rsPagTar.RecordCount > 0 Then
                rsPagTar.MoveFirst
                Do While Not rsPagTar.EOF
                    sTexto = sTexto + Left(" " + rsPagTar.Fields("descrip") + Space(23), 23) + Right(Space(15) + Format(CStr(rsPagTar.Fields("pago")), "0.00"), 15) + vbCrLf
                    toti = toti - rsPagTar.Fields("pago")
                    iTotal = iTotal + rsPagTar.Fields("pago")
                    rsPagTar.MoveNext
                Loop
            End If
            If val(Replace(txtSoles, ",", "")) > iTotal Then
                ivuelto_1 = 0
            Else
                ivuelto_1 = toti - iTotal
            End If
        
        Else
            IGV_1 = (val(Replace(txtSoles.Text, ",", "")) - val(CStr(iTotal)))
            'Validacion
            If Round(IGV_1 + iTotal, 2) <> val(Replace(txtSoles.Text, ",", "")) Then
               MsgBox "Inconsistencia de Datos"
               iTotal = val(Replace(txtSoles.Text, ",", "")) - IGV_1
            End If
                        
            sTexto = Left(" VALOR VTA" + Space(23), 23) + Right(Space(15) + Format(CStr(val(Replace(txtSoles.Text, ",", ""))), "0.00"), 15) + vbCrLf
            
            If iServicio > 0 Then
                sTexto = sTexto + Left(" SERVICIO" + "(" + kPAR_PORCSERV + " %)" + Space(23), 23) + Right(Space(15) + Format(CStr(iServicio), "0.00"), 15) + vbCrLf
            End If
            
            toti = val(Replace(txtSoles.Text, ",", ""))
            
            If rsPagTar.RecordCount > 0 Then
                rsPagTar.MoveFirst
                Do While Not rsPagTar.EOF
                    sTexto = sTexto + Left(" " + rsPagTar.Fields("descrip") + Space(23), 23) + Right(Space(15) + Format(CStr(rsPagTar.Fields("pago")), "0.00"), 15) + vbCrLf
                    toti = toti - rsPagTar.Fields("pago")
                    iTotal = iTotal + rsPagTar.Fields("pago")
                    rsPagTar.MoveNext
                Loop
            End If
            
           
            iTotal = 0
            If val(Replace(txtSoles, ",", "")) > iTotal Then
                ivuelto_1 = 0
            Else
                ivuelto_1 = toti - iTotal
            End If
            
                        
        End If
        If bLiquidaNC = False Then
            If toti > 0 Then
               sTexto = sTexto + Left(" EFECTIVO S/." + Space(23), 23) + Right(Space(15) + Format(CStr(toti), "0.00"), 15) + vbCrLf
            End If
            If ivuelto_1 > 0 Then
               sTexto = sTexto + Left(" VUELTO" + Space(23), 23) + Right(Space(15) + Format(CStr(ivuelto_1), "0.00"), 15) + vbCrLf
            End If
        Else
         If Trim(txtliqefectivosoles.Text) = "" Then txtliqefectivosoles.Text = "0.00"
         If Trim(txtliqefectivodolares.Text) = "" Then txtliqefectivodolares.Text = "0.00"
         If Trim(txtliqpade.Text) = "" Then txtliqpade.Text = "0.00"
         If Trim(txtliqvueltosoles.Text) = "" Then txtliqvueltosoles.Text = "0.00"
         If Trim(ttxliqvueltodolares.Text) = "" Then ttxliqvueltodolares.Text = "0.00"
         
         If CDbl(txtliqefectivosoles.Text) > 0 Then
            sTexto = sTexto + Left(" EFECTIVO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqefectivosoles.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqefectivodolares.Text) > 0 Then
            sTexto = sTexto + Left(" EFECTIVO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqefectivodolares.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqpade.Text) > 0 Then
           sTexto = sTexto + Left(" PADE/PADV" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqpade.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqvueltosoles.Text) <> 0 Then
            sTexto = sTexto + Left(" VUELTO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqvueltosoles.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(ttxliqvueltodolares.Text) <> 0 Then
            sTexto = sTexto + Left(" VUELTO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(ttxliqvueltodolares.Text), "0.00"), 15)
         End If
        End If
       ' Set rsPagTar = Nothing
      
   Case 4 'Anula Productos
      sTexto = Left(" CASH/TL" + Space(23), 23) + Right(Space(15) + Format(CStr(iTotal), "0.00"), 15)
    Case 5, 1 'Efectivo
       If blnfactura = True Then
          sTexto = Left(" VALOR VTA" + Space(23), 23) + Right(Space(15) + Format(CStr(val(Replace(txtSoles.Text, ",", "")) - igvf - iServicio), "0.00"), 15) + vbCrLf
          sTexto = sTexto + Left(" IGV" + Space(23), 23) + Right(Space(15) + Format(CStr(igvf), "0.00"), 15) + vbCrLf
          If iServicio > 0 Then
            sTexto = sTexto + Left(" SERVICIO" + "(" + kPAR_PORCSERV + " %)" + Space(23), 23) + Right(Space(15) + Format(CStr(iServicio), "0.00"), 15) + vbCrLf
          End If
          sTexto = sTexto + Left(" TOTAL VTA" + Space(23), 23) + Right(Space(15) + Format(CStr(val(Replace(txtSoles.Text, ",", ""))), "0.00"), 15) + vbCrLf + vbCrLf
      Else 'adicionado
            sTexto = Left(" VALOR VTA" + Space(23), 23) + Right(Space(15) + Format(CStr(val(Replace(txtSoles.Text, ",", ""))), "0.00"), 15) + vbCrLf
            If iServicio > 0 Then
               sTexto = sTexto + Left(" SERVICIO" + "(" + kPAR_PORCSERV + " %)" + Space(23), 23) + Right(Space(15) + Format(CStr(iServicio), "0.00"), 15) + vbCrLf
            End If
      End If
     If bLiquidaNC = False Then
        If iEfectivo > 0 Then
           sTexto = sTexto + Left(" EFECTIVO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(iEfectivo), "0.00"), 15) + vbCrLf
        End If
        If iDolaresEfectivo > 0 Then
           sTexto = sTexto + Left(" EFECTIVO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(iDolaresEfectivo), "0.00"), 15) + vbCrLf
        End If
        If iVuelto <> 0 Then
           sTexto = sTexto + Left(" VUELTO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(iVuelto), "0.00"), 15) + vbCrLf
        End If
        If iVueltoDolares <> 0 Then
           sTexto = sTexto + Right(" VUELTO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(iVueltoDolares), "0.00"), 15)
        End If
      Else
         If Trim(txtliqefectivosoles.Text) = "" Then txtliqefectivosoles.Text = "0.00"
         If Trim(txtliqefectivodolares.Text) = "" Then txtliqefectivodolares.Text = "0.00"
         If Trim(txtliqpade.Text) = "" Then txtliqpade.Text = "0.00"
         If Trim(txtliqvueltosoles.Text) = "" Then txtliqvueltosoles.Text = "0.00"
         If Trim(ttxliqvueltodolares.Text) = "" Then ttxliqvueltodolares.Text = "0.00"
         
         If piEmitevoucher = 1 Then
            If rsPagTar.RecordCount > 0 Then
                rsPagTar.MoveFirst
               
                Do While Not rsPagTar.EOF
                    sTexto = sTexto + Left(" " + rsPagTar.Fields("descrip") + Space(23), 23) + Right(Space(15) + Format(CStr(rsPagTar.Fields("pago")), "0.00"), 15) + vbCrLf
                    toti = toti - rsPagTar.Fields("pago")
                    iTotal = iTotal + rsPagTar.Fields("pago")
                    rsPagTar.MoveNext
                Loop
            End If
         End If
         
         If CDbl(txtliqefectivosoles.Text) > 0 Then
            sTexto = sTexto + Left(" EFECTIVO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqefectivosoles.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqefectivodolares.Text) > 0 Then
            sTexto = sTexto + Left(" EFECTIVO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqefectivodolares.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqpade.Text) > 0 Then
             sTexto = sTexto + Left(" PADE/PADV" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqpade.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqvueltosoles.Text) <> 0 Then
             sTexto = sTexto + Left(" VUELTO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqvueltosoles.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(ttxliqvueltodolares.Text) <> 0 Then
             sTexto = sTexto + Left(" VUELTO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(ttxliqvueltodolares.Text), "0.00"), 15)
         End If
        End If
    Case 20 'O/C
          
    If bLiquidaNC = False Then
         sTexto = Left(" VALOR VTA" + Space(23), 23) + Right(Space(15) + Format(CStr(txtSoles.Text), "0.00"), 15) + vbCrLf
         If iServicio > 0 Then
             sTexto = sTexto + Left(" SERVICIO" + "(" + kPAR_PORCSERV + " %)" + Space(23), 23) + Right(Space(15) + Format(CStr(iServicio), "0.00"), 15) + vbCrLf
         End If
       
         If iEfectivo > 0 Then
            sTexto = sTexto + Left(" EFECTIVO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtEfectivoSoles.Text), "0.00"), 15) + vbCrLf
         End If
         If iDolaresEfectivo > 0 Then
             sTexto = sTexto + Left(" EFECTIVO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtEfectivoDolares.Text), "0.00"), 15) + vbCrLf
         End If
         If iVuelto <> 0 Then
              sTexto = sTexto + Left(" VUELTO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(iVuelto), "0.00"), 15) + vbCrLf
         End If
         If iVueltoDolares <> 0 Then
             sTexto = sTexto + Left(" VUELTO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(iVueltoDolares), "0.00"), 15)
         End If
     Else
         sTexto = Left(" VALOR VTA" + Space(23), 23) + Right(Space(15) + Format(CStr(txtSoles.Text), "0.00"), 15) + vbCrLf
         If iServicio > 0 Then
             sTexto = sTexto + Left(" SERVICIO" + "(" + kPAR_PORCSERV + " %)" + Space(23), 23) + Right(Space(15) + Format(CStr(iServicio), "0.00"), 15) + vbCrLf
         End If
       
         If CDbl(txtliqefectivosoles.Text) > 0 Then
             sTexto = sTexto + Left(" EFECTIVO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqefectivosoles.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqefectivodolares.Text) > 0 Then
              sTexto = sTexto + Left(" EFECTIVO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqefectivodolares.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqpade.Text) > 0 Then
              sTexto = sTexto + Left(" PADE/PADV" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqpade.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqvueltosoles.Text) <> 0 Then
             sTexto = sTexto + Left(" VUELTO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqvueltosoles.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(ttxliqvueltodolares.Text) <> 0 Then
              sTexto = sTexto + Left(" VUELTO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(ttxliqvueltodolares.Text), "0.00"), 15)
         End If
     
     End If
    Case 21 'N/C
         sTexto = Left(" TOTAL S/." + Space(23), 23) + Right(Space(15) + Format(CStr(txtSoles), "0.00"), 15)
    Case 22 'PADE
      Select Case mon
       Case 2
          'sTexto = Left(" CASH/TL" + Space(19), 19) + Right(Space(19) + "US$ " + Format(CStr(iMontoDolares), "0.00"), 19)
          sTexto = Left(" " + dcbFormaPago.Text + Space(19), 19) + Right(Space(19) + "US$ " + Format(CStr(iMontoDolares), "0.00"), 19)
       Case Else
          'sTexto = Left(" CASH/TL" + Space(19), 19) + Right(Space(19) + "S/. " + Format(CStr(iTotal), "0.00"), 19)
          sTexto = Left(" " + dcbFormaPago.Text + Space(19), 19) + Right(Space(19) + "S/. " + Format(CStr(iTotal), "0.00"), 19)
      End Select
      
    Case 23 'PADV
    'jpcb270710
      Select Case mon
       Case 2
        If iTipoVenta = 23 Then
            sTexto = Left(" " + UCase(dcbFormaPago.Text) + Space(19), 19) + Right(Space(19) + "US$ " + Format(CStr(iMontoDolares), "0.00"), 19)
        Else
           sTexto = Left(" CASH/TL" + Space(19), 19) + Right(Space(19) + "US$ " + Format(CStr(iMontoDolares), "0.00"), 19)
        End If
           
       Case Else
        If iTipoVenta = 23 Then

            sTexto = Left(" " + UCase(dcbFormaPago.Text) + Space(19), 19) + Right(Space(19) + "S/. " + Format(CStr(iTotal), "0.00"), 19)
            
        Else
            sTexto = Left(" CASH/TL" + Space(19), 19) + Right(Space(19) + "S/. " + Format(CStr(iTotal), "0.00"), 19)
        End If
      End Select
      
    Case 24 'LIQPAD
          sTexto = Left(" SUB/TOTL" + Space(23), 23) + Right(Space(15) + Format(CStr(iTotal), "0.00"), 15) + vbCrLf
          sTexto = sTexto + Left(" PADE/PADV" + Space(23), 23) + Right(Space(15) + txtTotalPA.Text, 15) + vbCrLf
          sTexto = sTexto + Left(" TOT-PAGAR" + Space(23), 23) + Right(Space(15) + txtSoles.Text, 15) + vbCrLf
         If iEfectivo > 0 Then
            sTexto = sTexto + Left(" EFECTIVO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(iEfectivo), "0.00"), 15) + vbCrLf
         End If
        If iDolaresEfectivo > 0 Then
           sTexto = sTexto + Left(" EFECTIVO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(iDolaresEfectivo), "0.00"), 15) + vbCrLf
        End If
           
      If piEmitevoucher = 1 Then
         If rsPagTar.RecordCount > 0 Then
            rsPagTar.MoveFirst
               
            Do While Not rsPagTar.EOF
               'sTexto = sTexto + Left(" " + rsPagTar.Fields("descrip") + Space(23), 23) + Right(Space(15) + Format(CStr(rsPagTar.Fields("pago")), "0.00"), 15) + vbCrLf
               sTexto = sTexto + Left(" " + rsPagTar.Fields("descrip") + Space(23), 23) + Right(Space(15) + Format(CStr(rsPagTar.Fields("pago")), "0.00"), 15) + vbCrLf
               toti = toti - rsPagTar.Fields("pago")
               iTotal = iTotal + rsPagTar.Fields("pago")
              rsPagTar.MoveNext
            Loop
         End If
       End If
      If iVuelto <> 0 Then
          sTexto = sTexto + Left(" VUELTO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(iVuelto), "0.00"), 15) + vbCrLf
      End If
      If iVueltoDolares <> 0 Then
          sTexto = sTexto + Left(" VUELTO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(iVueltoDolares), "0.00"), 15)
      End If
           
  End Select
  

  
  printer.FontSize = 9 '12
  printer.FontBold = True
  Texto_imprimir = Texto_imprimir + vbCrLf + sTexto
  sTexto = ""
  If iTotItems > 0 Then
     sTexto = Left(" ITEM" + Space(23), 23) + Right(Space(15) + Format(CStr(iTotItems), "0.00"), 15)
 End If
  Select Case iTipoVenta
    Case 4 'Anula Productos
      sTexto = sTexto + vbCrLf + "VO-POSTN"
  End Select
  
  Texto_imprimir = Texto_imprimir + vbCrLf + sTexto + vbCrLf
  'Printer.Print sTexto
    
  'Printer.Print " "
  
  sTexto = ""
'
'  sTexto = sTexto + "---------------------------------------" + vbCrLf
'  sTexto = sTexto + Left(" TRANSACCION" + Space(23), 23) + Right(Space(15) + CStr(iCodOper), 15) + vbCrLf
'  sTexto = sTexto + "---------------------------------------" + vbCrLf


'jpcb no se otorga puntos segun luis vasquez
 ''---Puntos----------
' nImporte = CDbl(Me.txtMontoSoles.Text)
' If nImporte > 0 And sTarjeta <> "" Then
'   iPuntos = Int(nImporte / lReglaPuntoImporte) * lReglaPuntoCantidad
' End If
'
'
'  If sTarjeta <> "" Then
'     'sw 'sw Add 19/06/2009, era solo >>> intPuntosAcumulados = ObtenerPuntosAcumulados(sTarjeta)
'     intPuntosAcumulados = ObtenerPuntosAcumulados(sTarjeta, CStr(idLocal))
'     If (intPuntosAcumulados + iPuntos) >= 0 And iPuntos > 0 And intPuntosAcumulados <> -1 Then
'         sTexto = sTexto & " UD. ACUMULO: " & iPuntos & " PUNTOS" & vbCrLf
'         sTexto = sTexto & " TIENE ACUMULADO: " & IIf(intPuntosAcumulados + iPuntos < 0, "**", intPuntosAcumulados + iPuntos) & " PUNTOS" & vbCrLf & vbCrLf
'     End If
'  End If
  
 '---Fin Puntos------
 
 ''impresion saldo por pagar
  Dim nSaldoxPagar As Double
  Dim sTextoSaldoxPagar As String
  nSaldoxPagar = CDbl(lblSaldoSoles.Caption) - CDbl(txtMontoSoles.Text)
  sTextoSaldoxPagar = Left("  Saldo x pagar (S/) " + Space(23), 23) + Right(Space(15) + Format(CStr(nSaldoxPagar), "0.00"), 15) + vbCrLf
  sTextoSaldoxPagar = sTextoSaldoxPagar + "  Ref: " + cboTipoDocumento1.Text + " " + Trim(scSerieDoc) + "-" + Trim(sNroDoc) + vbCrLf
  sTexto = sTexto + sTextoSaldoxPagar + vbCrLf
 
 ''fin impresion saldo por pagar
 
  sTexto = sTexto + Space(9) + Format(CStr(Now()), "(DDD) DD/MM/YYYY ") + Format(CStr(Now()), "hh:mm") + vbCrLf 'Hora: 6 + 1
  If bAcceso = True Then
    sTexto = sTexto + "       SUPERVISOR: " + txtsupervisor + vbCrLf
  End If
  sTexto = sTexto + Space(3) + Left(psUsuario_Descripcion, 10) + " " 'Usuario: 10 + 1
  sTexto = sTexto + Space(1) + "Cj:" + kPAR_CAJA + " T:" + kPAR_TURNO
  sTexto = sTexto + Space(1) + "v" & App.Major & "." & App.Minor & "." & App.Revision
  sTexto = sTexto + vbCrLf & "         Correlativo: " & ObtenerCorrelativo(p_1)

  Select Case iTipoVenta
 Case 20, 22, 23, 21
 Case 24
     If piEmitevoucher <> 1 Then
        txtliqefectivodolares.Text = IIf(Trim(txtEfectivoDolares.Text) = "", "0.00", txtEfectivoDolares.Text)
        txtliqefectivosoles.Text = IIf(Trim(txtEfectivoSoles.Text) = "", "0.00", txtEfectivoSoles.Text)
        txtliqvueltosoles.Text = IIf(Trim(txtVueltoSoles.Text) = "", "0.00", txtVueltoSoles.Text)
        ttxliqvueltodolares.Text = IIf(Trim(txtVueltoDolares.Text) = "", "0.00", txtVueltoDolares.Text)
     End If
     txtliqpade.Text = IIf(Trim(txtTotalPA.Text) = "", "0.00", txtTotalPA.Text)
     txtLiq.Text = iCodOper
 Case Else
    sTexto = sTexto + vbCrLf + vbCrLf + "   " + kPIE_TICKET
 End Select
  
  printer.FontSize = 8 '11
  printer.FontBold = False
  '-------------segun impresora seleccionada --------
  Texto_imprimir = Texto_imprimir + vbCrLf + sTexto

If p_1 = 1 Then
  ConfiguraImpresora kPAR_IMPRESORA
  Select Case KImpresora
     Case 1
         Call CortePapel(Texto_imprimir, p_1, CStr(iCodOper))
     Case 0
         printer.Print Texto_imprimir
         printer.Print " "
         printer.Print " "
         printer.EndDoc
   End Select
Else
   ConfiguraImpresora kPAR_IMPRESORA_ALTERNA
  Select Case KImpresoraALT
      Case 1
          Call CortePapel(Texto_imprimir, p_1)
      Case 0
          printer.Print Texto_imprimir
          printer.Print " "
          printer.Print " "
          printer.EndDoc
    End Select
End If
  

  '-------------------Graba operacion -------------------------
   Select Case iTipoVenta
    Case 20, 21, 22, 23, 24
      If iTipoVenta = 22 Or iTipoVenta = 23 Or iTipoVenta = 24 Then
      Else
        
        iDolaresEfectivo = val(Replace(txtEfectivoDolares, ",", ""))
        iSolesEfectivo = val(Replace(txtEfectivoSoles, ",", ""))
        iTotal = val(Replace(txtSoles, ",", ""))
        iMontoDolares = val(Replace(txtDolares, ",", ""))
        iEfectivo = val(Replace(txtEfectivoSoles, ",", ""))
        'iVuelto = val(Replace(Me.txtVueltoSoles, ",", ""))
        If iVuelto < 0 Then iVuelto = 0
        'iVueltoDolares = val(Replace(Me.txtVueltoDolares, ",", ""))
        If iVueltoDolares < 0 Then iVueltoDolares = 0
        If iTipoVenta = 21 Then
            iCodOperRela = val(txtTX.Text)
        Else
            'jpcb 17/12/2008
            If iTipoVenta = 20 And Trim(txtLiq.Text) <> "" Then
            Else
                iCodOperRela = 0
            End If
        End If
      End If
          
      
      '------------------Validacion de Numeración Correlativa -------------------------//
'      'ACA SE VALIDA CONTRA EL SQL
'      If cdocTipo = "01" Or cdocTipo = "02" Then
'         sSQL = "SELECT MAX(cDocCodigo) AS maximo FROM Operacion WHERE cDocTipo = '" & cdocTipo & "'"
'      Else
'         'sSQL = "SELECT MAX(cDocCodigo) AS maximo FROM OperacionParalela WHERE cDocTipo = '" & cdocTipo & "'"
'          sSQL = "SELECT ISNULL(MAX(NroDocPago),0) AS maximo  FROM Pagos WHERE cSerieDocPago='" & KSERIE_PARALELO & "'"
'      End If
'      'If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
'       If Not oDBAdmin.EjecutarConsulta(cnSQL, sSQL, ADORS) Then GoTo Salir
'    If cDocCodigofull <> ((ADORS!Maximo) + 1) And val("0" & ADORS!Maximo) > 0 Then
'      Set fso = CreateObject("Scripting.FileSystemObject")
'      archivo = "Error_Full2" & cdocTipo & cDocCodigofull
'      If Trim(archivo) = "" Then
'          archivo = "textfile"
'      End If
'      Texto = Texto + "Codigo generado " & cDocCodigofull & Chr(13)
'
'      NameArchivo = "C:\Temp\" + Trim(archivo) + ".log"
'      Set MyFile = fso.CreateTextFile(NameArchivo, True)
'      cDocCodigofull = ("0" & (ADORS!Maximo)) + 1
'      Texto = Texto + "Nuevo Codigo " & cDocCodigofull & Chr(13)
'      Texto = Texto + CStr(Now)
'      MyFile.WriteLine (Texto)
'      MsgBox "Ocurrio un error en la numeración, se asignará el " & cDocCodigofull & " al documento "
'      MyFile.Close
'    End If
'
'    '---------------Actualizando el valor de la numeración --------------------------------//
'    sSQL = "UPDATE Config_Documento " & _
'          " SET cOperCode=" & CStr(iCodOper) & "," & _
'          " nDocCodigo=" & cDocCodigofull & ", " & _
'          " cUserDesc='" & psUsuario_Descripcion & "' " & _
'          " WHERE cTipodoc='" & cdocTipo & "'"
'    If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
    
  If cdocTipo = "01" Or cdocTipo = "02" Then
    sSQL = "SELECT MAX(cDocCodigo) AS maximo FROM Operacion WHERE cDocTipo = '" & cdocTipo & "'"
  Else
        
        'aca se tendria que primero determinar cual es mayor el valor del access o el sql
            Dim nValorAccess_ As Long
            Dim nValorSQL_ As Long
            Dim nValorMaximo_ As Long
            Dim ADORS1_ As ADODB.Recordset
        
        sSQL = "SELECT MAX(cDocCodigo) AS maximo FROM OperacionParalela WHERE cDocTipo = '" & cdocTipo & "'"
        
        'sSQL = "SELECT MAX(cDocCodigo) AS maximo FROM Operacion WHERE cDocTipo = '" & cdocTipo & "'"
        If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS1_) Then GoTo Salir
        nValorAccess_ = ADORS1!Maximo
        
        
'        If iTipoVenta = 6 Then
'            ' Es PA--> Access cDocTipo=12
'        Else
'            ' Es PV--> Access cDocTipo=13
'            sSQL = "SELECT MAX(cDocCodigo) AS maximo FROM OperacionParalela WHERE cDocTipo = '" & cdocTipo & "'"
'        End If
  
        
        sSQL = "SELECT  ISNULL(MAX(CAST(NroDocPago AS INT)),0) AS maximo FROM Pagos WHERE cSerieDocPago='" & KSERIE_PARALELO & "'"
        If Not oDBAdmin.EjecutarConsulta(cnSQL, sSQL, ADORS) Then GoTo Salir
        nValorSQL_ = ADORS!Maximo
        
        
        If nValorAccess_ > nValorSQL_ Then
           nValorMaximo_ = nValorAccess_
        Else
           nValorMaximo_ = nValorSQL_
        End If
        
        
        
  End If
  'If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir

  If val(cDocCodigofull) <> val("0" & (nValorMaximo) + 1) And val("0" & nValorMaximo) > 0 Then
    'Dim NameArchivo As String
    'Dim archivo
    'Dim Texto As String
    'Dim fso, MyFile
    Set fso = CreateObject("Scripting.FileSystemObject")
    archivo = "Error_Full_1" & cdocTipo & cDocCodigofull
    If Trim(archivo) = "" Then
      archivo = "textfile"
    End If
    Texto = Texto + "Codigo generado " & cDocCodigofull & Chr(13)
    
    NameArchivo = "C:\Temp\" + Trim(archivo) + ".log"
    Set MyFile = fso.CreateTextFile(NameArchivo, True)
    cDocCodigofull = ("0" & (nValorMaximo_)) + 1
    Texto = Texto + "Nuevo Codigo " & cDocCodigofull & Chr(13)
    Texto = Texto + CStr(Now)
    MyFile.WriteLine (Texto)
    MsgBox "Ocurrio un error en la numeración, se asignará el " & cDocCodigofull & " al documento "
    MyFile.Close
  End If
  '---------------Actualizando el valor de la numeración ----------------
  sSQL = "UPDATE Config_Documento " & _
         " SET cSerieDoc='" & cDocSerie & "'," & _
         " nDocCodigo=" & cDocCodigofull & " " & _
         " WHERE cTipodoc='" & cdocTipo & "'"
  If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
    
    
    
    '------------------fin Validacion de Numeración Correlativa -----------------------
      
     If iTipoVenta = 23 Then
     '170810 VALIDA EL ERROR DE DUPLICIDAD DE PADV  (por error se graba otro registro inmediatamente e igual que el anterior)
             
            sSQL = "SELECT dOperFech,nTarjNumb,nMoneda,nMontoSoles,nMontoDolares,nEfectivoSoles,sGlosa FROM OPERACIONPARALELA WHERE cOperCode=" & iCodOper - 1 & ""
            
            If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
            
            If Format(ADORS!dOperFech, "DD/MM/YYYY hh:mm") = sFecha And ADORS!nTarjNumb = sTarjeta And ADORS!nMoneda = CStr(mon) And _
                ADORS!nMontoSoles = iTotal And ADORS!nMontoDolares = iMontoDolares And _
                 ADORS!nEfectivoSoles = iEfectivo And ADORS!sGlosa = txtGlosa Then
                
                
                sSQL = "UPDATE Config_Documento " & _
                      " SET cOperCode=" & CStr(iCodOper - 1) & "," & _
                      " nDocCodigo=" & cDocCodigofull - 1 & ", " & _
                      " cUserDesc='" & psUsuario_Descripcion & "' " & _
                      " WHERE cTipodoc='" & cdocTipo & "'"
                If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
                
                GoTo Salir
                
            Else
      
                    sSQL = " INSERT INTO OPERACIONPARALELA (cOperCode, cOperTipo, dOperFech, nTarjNumb," & _
                           " nMoneda, nMontoSoles, nMontoDolares, nEfectivoSoles, nVueltoSoles, sGlosa," & _
                           " cEstado, cCajaCodi, cFlagSincronizacion, cTurnoCodi, cUserDesc, cOpercodeRela, " & _
                           " nEfectivoDolares, nVueltoDolares, cDocSerie, cDocCodigo, cDocTipo ) " & _
                           " VALUES" + _
                           " ($, $, '$', '$', $, $, $, $, $, '$', '$', '$', '$', '$', '$', $ ,$ ,$,'$',$,'$')"
                    sSQL = VBsprintf(sSQL, CStr(iCodOper), CStr(iTipoVenta), sFecha, sTarjeta, CStr(mon), CStr(iTotal), _
                                           CStr(iMontoDolares), CStr(iEfectivo), CStr(iVuelto), txtGlosa, CStr(1), _
                                           kPAR_CAJA, CStr(0), kPAR_TURNO, psUsuario_Descripcion, CStr(iCodOperRela), _
                                           CStr(iDolaresEfectivo), CStr(iVueltoDolares), KSERIE_PARALELO, cDocCodigofull, cdocTipo)
                    If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
                    
            End If
        
     Else
            sSQL = " INSERT INTO OPERACIONPARALELA (cOperCode, cOperTipo, dOperFech, nTarjNumb," & _
                   " nMoneda, nMontoSoles, nMontoDolares, nEfectivoSoles, nVueltoSoles, sGlosa," & _
                   " cEstado, cCajaCodi, cFlagSincronizacion, cTurnoCodi, cUserDesc, cOpercodeRela, " & _
                   " nEfectivoDolares, nVueltoDolares, cDocSerie, cDocCodigo, cDocTipo ) " & _
                   " VALUES" + _
                   " ($, $, '$', '$', $, $, $, $, $, '$', '$', '$', '$', '$', '$', $ ,$ ,$,'$',$,'$')"
            sSQL = VBsprintf(sSQL, CStr(iCodOper), CStr(iTipoVenta), sFecha, sTarjeta, CStr(mon), CStr(iTotal), _
                                   CStr(iMontoDolares), CStr(iEfectivo), CStr(iVuelto), txtGlosa, CStr(1), _
                                   kPAR_CAJA, CStr(1), kPAR_TURNO, psUsuario_Descripcion, CStr(iCodOperRela), _
                                   CStr(iDolaresEfectivo), CStr(iVueltoDolares), KSERIE_PARALELO, cDocCodigofull, cdocTipo)
            If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
      End If
               
               
'      sSql = " INSERT INTO OPERACIONPARALELA (cOperCode, cOperTipo, dOperFech, nTarjNumb," & _
'             " nMoneda, nMontoSoles, nMontoDolares, nEfectivoSoles, nVueltoSoles, sGlosa," & _
'             " cEstado, cCajaCodi, cFlagSincronizacion, cTurnoCodi, cUserDesc, cOpercodeRela, " & _
'             " nEfectivoDolares, nVueltoDolares, cDocSerie, cDocCodigo, cDocTipo ) " & _
'             " VALUES" + _
'             " ($, $, '$', '$', $, $, $, $, $, '$', '$', '$', '$', '$', '$', $ ,$ ,$,'$',$,'$')"
'      sSql = VBsprintf(sSql, CStr(iCodOper), CStr(iTipoVenta), sFecha, sTarjeta, CStr(mon), CStr(iTotal), _
'                             CStr(iMontoDolares), CStr(iEfectivo), CStr(iVuelto), txtGlosa, CStr(1), _
'                             kPAR_CAJA, CStr(0), kPAR_TURNO, psUsuario_Descripcion, CStr(iCodOperRela), _
'                             CStr(iDolaresEfectivo), CStr(iVueltoDolares), KSERIE_PARALELO, cDocCodigofull, cdocTipo)
'      If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSql) Then GoTo Salir
      
      
      nImporte = 0
      nPtosImp = 0
      nPuntos = 0
      
'      For i = 0 To gfax.UpperBound(1)
      For i = 0 To nProducto
        'TDBGrid1.Row = i
        sSQL = " INSERT INTO OPERACIONPARALELAPRODUCTO (cAlmaCode, cOperCode, cProdCode, nProdCant," & _
               " nProdPrecUnit, nDscto, nServicio)" & _
               " VALUES" + _
               " ('$', $, $, $, $, $,$)"
        sSQL = VBsprintf(sSQL, kPAR_ALMACEN, CStr(iCodOper), CStr(Producto(i).Codigo), CStr(Abs(val(Replace(gfax(i, 6), ",", "")))), _
                         CStr(val(Replace(gfax(i, 7), ",", ""))), CStr(Producto(i).Dscto), IIf(gfax(i, 13) = "SI", kPAR_PORCSERV, "0"))
        If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
        
  
        'CONTABILIZA PUNTOS
        '------------------
'        nImporte = nImporte + _
'                   Producto(i).Cant * val(TDBGrid1.Columns(7).Text) * (100 - Producto(i).Dscto) * _
'                   IIf(Producto(i).Canje = "VNTA", 1, 0) / 100
'        nPtosImp = nPtosImp + _
'                   Producto(i).Cant * Producto(i).PUnit * (100 - Producto(i).Dscto) * _
'                   IIf(Producto(i).Canje = "PTOS", 1, 0) / 100
'        nPuntos = nPuntos + IIf(Producto(i).Canje = "PTOS", 1, 0) * Producto(i).Ptos * Producto(i).Cant
      Next
      Dim CodLiq As Long
      If iTipoVenta = 1 Or _
         iTipoVenta = 20 And (iDolaresEfectivo > 0 Or iSolesEfectivo > 0) Or _
         iTipoVenta = 5 And (iDolaresEfectivo > 0 Or iSolesEfectivo > 0) Or _
         iTipoVenta = 24 And (iDolaresEfectivo > 0 Or iSolesEfectivo > 0) Then
         Dim iCodTipo As Long
         If iTipoVenta = 24 Then
         txtLiq.Text = iCodOper
         End If
         
         If bLiquidaNC = False Then
            If piEmitevoucher = 1 And iEfectivo = 0 Then
              iCodTipo = 2
            Else
              iCodTipo = 1
            End If
            CodLiq = 0
            
         Else
            iCodTipo = 3
            CodLiq = val(txtLiq.Text)
         End If
        '---primera
           If iDolaresEfectivo <= 0 And iEfectivo <= 0 Then iEfectivo = Replace(txtSoles, ",", "")
           
           sSQL = " INSERT INTO OPERACION (cOperCode, cUserDesc, nTarjNumb, cProdCode, nProdCant, nProdPrecUnit," & _
               " nMontoDolares, dOperFech, cOperTipo, cCajaCodi, cTurnoCodi, nmontosoles, nVueltoDolares,  cDocSerie, cDoccodigo, cdocTipo, cOpercodeAnula, IdLocal) " + _
               " VALUES" + _
               " ($, '$', '$', $, $, $, $, '$', $, '$', '$',$ ,$, '$', $, '$', $, $)"
           sSQL = VBsprintf(sSQL, CStr(iCodOper), psUsuario_Descripcion, sTarjeta, CStr(0), CStr(1), _
                           CStr(-1 * iVuelto), CStr(iDolaresEfectivo), sFecha, CStr(iCodTipo), kPAR_CAJA, kPAR_TURNO, CStr(iEfectivo), CStr(iVueltoDolares), cDocSerie, cDocCodigofull, cdocTipo, CodLiq, idLocal)

        If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
        iVuelto = val(Replace(txtVueltoSoles, ",", ""))
        If iVuelto < 0 Then iVuelto = 0
      End If
      
      
      nImporte = CDbl(Me.txtMontoSoles.Text)
      nPuntos = 0
      '--------------------------Inserta linea voucher liq------------------------------------
      Dim importevoucher As Double
      
      If piEmitevoucher = 1 Then
         importevoucher = nImporte - iEfectivo + iVuelto
         sSQL = " INSERT INTO OPERACION (cOperCode, cUserDesc, nTarjNumb, cProdCode, nProdCant, nProdPrecUnit," & _
               " nMontoDolares, dOperFech, cOperTipo, cCajaCodi, cTurnoCodi, nmontosoles, nVueltoDolares,  cDocSerie, cDoccodigo, cdocTipo, cOpercodeAnula, cemisor, IdLocal) " + _
               " VALUES" + _
               " ($, '$', '$', $, $, $, $, '$', $, '$', '$',$ ,$, '$', $, '$', $, '$', $)"
         sSQL = VBsprintf(sSQL, CStr(iCodOper), psUsuario_Descripcion, sTarjeta, CStr(0), CStr(1), _
                           0, 0, sFecha, 2, kPAR_CAJA, kPAR_TURNO, CStr(importevoucher), 0, cDocSerie, cDocCodigofull, cdocTipo, CodLiq, cEmisor, idLocal)
         If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
                          
      End If
      
      '-----------------------------------------------------------------------------
'jpcb no se otorga puntos segun luis vasquez
'      'ACTUALIZA PUNTOS
'      '----------------
'      If nImporte > 0 And sTarjeta <> "" Then
'        Call Guarda_Puntos(sTarjeta, "VNTA", cdocTipo, cDocSerie, cDocCodigofull, nImporte, , idLocal)
'        iPuntos = Int(nImporte / lReglaPuntoImporte) * lReglaPuntoCantidad
'      End If
'      If nPuntos > 0 And sTarjeta <> "" Then
'        Call Guarda_Puntos(sTarjeta, "PTOS", cdocTipo, cDocSerie, cDocCodigofull, nPuntos, nPtosImp, idLocal)
'      End If
      '----------------
      
      If iTipoVenta = 24 Then
'        sSQL = " UPDATE OPERACIONPARALELA" & _
'               " SET cEstado = 2" + _
'               " WHERE cOperCode = $"
'        sSQL = VBsprintf(sSQL, CStr(iCodOper))
'        If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
'
'        For i = 1 To lvwTX(0).ListItems.Count
'          iCodOperRela = val(lvwTX(0).ListItems(i).Text)
'          sSQL = " UPDATE OPERACIONPARALELA" & _
'                 " SET cOpercodeRela = $," & _
'                 " cEstado = 2" + _
'                 " WHERE cOperCode = $"
'          sSQL = VBsprintf(sSQL, CStr(iCodOper), CStr(iCodOperRela))
'          If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
'        Next
'
'        For i = 1 To lvwTX(1).ListItems.Count
'          iCodOperRela = val(lvwTX(1).ListItems(i).Text)
'          sSQL = " UPDATE OPERACIONPARALELA" & _
'                 " SET cOpercodeRela = $," & _
'                 " cEstado = 2" + _
'                 " WHERE cOperCode = $" ' AND cOperCodeRela = 0"
'          sSQL = VBsprintf(sSQL, CStr(iCodOper), CStr(iCodOperRela))
'          If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
'        Next
      End If
  
      
    Case Else
      
      nImporte = 0
      nPtosImp = 0
      nPuntos = 0
      If rsPagTar.state = adStateOpen Then
      If rsPagTar.RecordCount > 0 Then
        rsPagTar.MoveFirst
        Do While Not rsPagTar.EOF
            cEmisor = cEmisor + "," + rsPagTar.Fields("cod_tar")
            rsPagTar.MoveNext
        Loop
      End If
      End If
      
  '------------------Validacion de Numeración Correlativa -------------------------//
  sSQL = "SELECT MAX(cDocCodigo) AS maximo FROM Operacion WHERE cDocTipo = '" & cdocTipo & "'"
         If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
         
  If cDocCodigofull <> ((ADORS!Maximo) + 1) And val("0" & ADORS!Maximo) > 0 Then
    Set fso = CreateObject("Scripting.FileSystemObject")
    archivo = "Error_Full2" & cdocTipo & cDocCodigofull
    If Trim(archivo) = "" Then
        archivo = "textfile"
    End If
    Texto = Texto + "Codigo generado " & cDocCodigofull & Chr(13)
    
    NameArchivo = "C:\Temp\" + Trim(archivo) + ".log"
    Set MyFile = fso.CreateTextFile(NameArchivo, True)
    cDocCodigofull = ("0" & (ADORS!Maximo)) + 1
    Texto = Texto + "Nuevo Codigo " & cDocCodigofull & Chr(13)
    Texto = Texto + CStr(Now)
    MyFile.WriteLine (Texto)
    MsgBox "Ocurrio un error en la numeración, se asignará el " & cDocCodigofull & " al documento "
  End If
  
  '---------------Actualizando el valor de la numeración --------------------------------//
  sSQL = "UPDATE Config_Documento " & _
        " SET cOperCode=" & CStr(iCodOper) & "," & _
        " cUserDesc='" & psUsuario_Descripcion & "' " & _
        " WHERE cTipodoc='" & cdocTipo & "'"
  If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
  
  '------------------fin Validacion de Numeración Correlativa ---------------------------//
          
      For i = 0 To gfax.UpperBound(1)
         'TDBGrid1.Row = i
         If bLiquidaNC Then iFlagTipo = 3
         
         If iFlagTipo = 3 Then
            CodLiq = val(txtLiq.Text)
         Else
            CodLiq = 0
         End If
         sSQL = " INSERT INTO OPERACION (cOperCode, cUserDesc, nTarjNumb, cAlmaCode, cProdCode, nProdCant, nProdPrecUnit," & _
                " nMontoDolares, dOperFech, cOperTipo, cCajaCodi, cTurnoCodi, nDscto, nServicio, cDocCodigo, cRuc, cDocSerie, cDocTipo, cEmisor, cOpercodeanula, idLocal) " + _
                " VALUES" + _
                " ($, '$', '$', '$', $, $, $, $, '$', $, '$', '$', $, $, $, '$', '$', '$', '$', $, $)"
         
         sSQL = VBsprintf(sSQL, CStr(iCodOper), psUsuario_Descripcion, sTarjeta, kPAR_ALMACEN, CStr(Producto(i).Codigo), CStr(val(Replace(gfax(i, 6), ",", "") * iSigno)), _
                CStr(val(Replace(gfax(i, 7), ",", ""))), CStr(0), sFecha, CStr(iFlagTipo), kPAR_CAJA, kPAR_TURNO, CStr(Producto(i).Dscto), IIf(gfax(i, 13) = "SI", kPAR_PORCSERV, "0"), cDocCodigofull, cRuc, cDocSerie, cdocTipo, cEmisor, CodLiq, idLocal)
               
         If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
         iEfectivo = val(Replace(txtEfectivoSoles, ",", ""))
         iVuelto = val(Replace(txtVueltoSoles, ",", ""))
         If iVuelto < 0 Then iVuelto = 0
    
      Next
       
      nImporte = CDbl(Me.txtSoles.Text)
      nPuntos = 0
         
      iVuelto = val(Replace(txtVueltoSoles, ",", ""))
      iDolaresEfectivo = val(Replace(txtEfectivoDolares, ",", ""))
      iSolesEfectivo = val(Replace(txtEfectivoSoles, ",", ""))
      'iVueltoDolares = val(Replace(Me.txtVueltoDolares, ",", ""))
      If iVuelto < 0 Then iVuelto = 0
      If iVueltoDolares < 0 Then iVueltoDolares = 0
      'ACTUALIZA PUNTOS
      '----------------
      If Not blLiquidaVenta Then
        If nImporte > 0 And sTarjeta <> "" Then
          Call Guarda_Puntos(sTarjeta, "VNTA", cdocTipo, cDocSerie, cDocCodigofull, nImporte, , idLocal)
          iPuntos = Int(nImporte / lReglaPuntoImporte) * lReglaPuntoCantidad
        End If
        If nPuntos > 0 And sTarjeta <> "" Then
          Call Guarda_Puntos(sTarjeta, "PTOS", cdocTipo, cDocSerie, cDocCodigofull, nPuntos, nPtosImp, idLocal)
        End If
    
      End If
      '---------------
      
      If iTipoVenta = 1 And (iDolaresEfectivo > 0 Or iSolesEfectivo > 0) Or _
         iTipoVenta = 20 And (iDolaresEfectivo > 0 Or iSolesEfectivo > 0) Or _
         iTipoVenta = 5 And (iDolaresEfectivo > 0 Or iSolesEfectivo > 0) Or _
         iTipoVenta = 3 And (iDolaresEfectivo > 0 Or iSolesEfectivo > 0) Or _
         iTipoVenta = 24 And (iDolaresEfectivo > 0 Or iSolesEfectivo > 0) Or _
         (iTipoVenta = 2 And (iDolaresEfectivo > 0 Or iSolesEfectivo > 0)) Then
        '-----segunda
         If bLiquidaNC = False Then
            iCodTipo = 1
            CodLiq = 0
         Else
            iCodTipo = 3
            CodLiq = val(txtLiq.Text)
         End If
        
            sSQL = " INSERT INTO OPERACION (cOperCode, cUserDesc, nTarjNumb, cProdCode, nProdCant, nProdPrecUnit," & _
                   " nMontoDolares, dOperFech, cOperTipo, cCajaCodi, cTurnoCodi,nmontosoles, nVueltoDolares, cDocCodigo, cRuc, cDocSerie, cDocTipo,cEmisor, cOpercodeAnula, IdLocal) " + _
                   " VALUES" + _
                   " ($, '$', '$', $, $, $, $, '$', $, '$', '$',$ ,$, $, '$', '$', '$', '$', $, $)"
            sSQL = VBsprintf(sSQL, CStr(iCodOper), psUsuario_Descripcion, sTarjeta, CStr(0), CStr(1), _
                               CStr(-1 * iVuelto), CStr(iDolaresEfectivo), sFecha, CStr(iCodTipo), kPAR_CAJA, kPAR_TURNO, CStr(iSolesEfectivo), CStr(iVueltoDolares), CStr(cDocCodigofull), cRuc, cDocSerie, cdocTipo, cEmisor, CodLiq, idLocal)

    
     If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
        iVuelto = val(Replace(txtVueltoSoles, ",", ""))
        If iVuelto < 0 Then iVuelto = 0
    End If
            
  End Select
   
  
  bLiquidaNC = False
  '-------------------Fin Graba operacion -------------------------


'FIN GRABA ACCESS-----------------------------------------------------------------------------------------
'INICIO GRABA SQL PAGOS-----------------------------------------------------------------------------------


'
'sSQL = "SELECT isnull(max(CAST(IdPago AS INT)),0) as maximo FROM Pagos"
'If Not oDBAdmin.EjecutarConsulta(cnSQL, sSQL, ADORS) Then GoTo Salir
''
''
'If ADORS.RecordCount = 1 Then
'    If IsNull(ADORS("maximo")) Then
'      iCodPago = 1
'    Else
'      iCodPago = LeerCampo(ADORS("maximo")) + 1
'    End If
'End If

iCodPago = cDocCodigofull

sSQL = "SELECT isnull(max(CAST(NroItem AS INT)),0) as maximo FROM Pagos where tipodoc='" & sTipoDoc & "' and cSerieDoc='" & scSerieDoc & "'  and nrodoc='" & sNroDoc & "'"
If Not oDBAdmin.EjecutarConsulta(cnSQL, sSQL, ADORS) Then GoTo Salir


If ADORS.RecordCount = 1 Then
    If IsNull(ADORS("maximo")) Then
      iNroItem = 1
    Else
      iNroItem = LeerCampo(ADORS("maximo")) + 1
    End If
End If


sSQL = "INSERT INTO PAGOS(cSerieDocPago,NroDocPago,TipoDoc,cSerieDoc,NroDoc,NroItem,FormaPago,FechaPago,Monto,Moneda,nTipoCambio,IdTarjeta,IdBanco,NroCtaBancaria,NroOperacion,NroCertificadoRetencion,NroDepositoDetraccion,cClieCode,idLocal,bEsPagoDetraccion) VALUES " _
& "('" & KSERIE_PARALELO & "','" & Format(iCodPago, "000000") & "','" & sTipoDoc & "','" & scSerieDoc & "','" & sNroDoc & "'," & iNroItem & ",'" & sFormaPago & "','" & Format(dFechaPago, "yyyyMMdd") & "'," & nMonto & ",'" & smoneda & "'," & nTipoCambio & "," & sTipoTarjeta & "," & sCodBanco & "," & sNroCuenta & "," & sNroOperacion & "," & sNroCertRetencion & "," & sNroDepDetraccion & "," & nCodCliente & "," & nCodLocal & "," & IIf(chkEsDetraccion.Visible = True, 1, 0) & ")"

If Not oDBAdmin.EjecutarSentencia(cnSQL, sSQL) Then GoTo Salir

If chkEsDetraccion.Visible = True Then
    sSQL = "UPDATE DETRACCION SET Estado='C' WHERE SerieDoc='" & scSerieDoc & "' AND NroDoc='" & sNroDoc & "' "
    
    If Not oDBAdmin.EjecutarSentencia(cnSQL, sSQL) Then GoTo Salir
End If


    ADOCnn.CommitTrans
    cnSQL.CommitTrans

Set cnSQL = Nothing


Exit Sub
Salir:
MsgBox Err.Description
ADOCnn.RollbackTrans
cnSQL.RollbackTrans
Set cnSQL = Nothing

End Sub
Private Sub RegistrarLiquidacion()
  'GoTo prueba
  On Error GoTo Salir
  
  Dim cnSQL As ADODB.Connection
  Dim sSQL As String
  Dim ADORS As ADODB.Recordset
  Dim i As Long, j As Long, iCodOper As Long, iCodOperRela As Long
  Dim iTotal, iTotalVenta As Double, iSubTotal As Double, iSubTotalDscto As Double
  Dim iTotalDscto As Double, iTotItems As Double
  Dim sFecha As String
  Dim sTexto As String
  Dim iSigno As Integer
  Dim iFlagTipo As Integer
  Dim sTarjeta As String
  Dim ivuelto_1 As Double
  Dim iMontoDolares As Double
  Dim iMontoSoles As Double
  Dim iDolaresEfectivo As Double
  Dim iSolesEfectivo As Double
  Dim rs1 As Recordset
  Dim p_1 As Integer
  Dim impr_1 As String
  Dim impr_2 As String
  Dim nImporte As Double, iServicio, nPuntos As Double, nPtosImp As Double
  Dim iPtoVta, iPtoItm As Double, iPagoAdelantado As Double
  Dim blLiquidaVenta As Boolean
  Dim Texto_imprimir As String
  Dim iPuntos As Long
  Dim sssql As String
  Dim blnfactura As Boolean
  Dim intPuntosAcumulados As Long
  Dim x As printer
  
  Dim cEmisor As String
  Dim cDocCodigofull As Long
  Dim cDocSerie As String
  Dim cdocTipo As String
  Dim cRuc As String
  Dim IGV_1 As Double
  blLiquidaVenta = False
  blnfactura = False
  Dim KSERIE_PARALELO As String
  
  'sw To SQL Server add
  Dim idLocal As String
  
  'TDBGrid1.Update
  If piEmitevoucher <> 1 Then
    'CalculaTotales
    'CalculoVuelto
  End If
  cDocCodigofull = 0
  p_1 = 0
  
  ConectarBDCliente
  'Verifica si es Factura
  If Not Trim(Me.txtRUC.Text) = "" Then
    blnfactura = True
    cRuc = Trim(Me.txtRUC.Text)
    cdocTipo = "01"
    cDocSerie = kSERIE_FACTURA
  Else
    cRuc = ""
    cdocTipo = "02"
    cDocSerie = kSERIE
  End If
  
  iTipoVenta = 8 ' Liquidacion
  
  '--------------------
  '-- Registra Venta --
  '--------------------
  
  If Not oDBAdmin.AbrirBD(cnSQL, psConnectString) Then GoTo Salir 'OMNISYS
  
  'If Not oDBAdmin.AbrirBD(cnSQL, psCadenaConexionSQLServer) Then GoTo Salir 'OMNICLIENT
  
  cnSQL.BeginTrans
  ADOCnn.BeginTrans
  
   
    'SE OBTIENE FECHA DEL SISTEMA DE LA BASE DE DATOS DE SQL - version 2.0.5
   
   Dim cnFECHASQL As ADODB.Connection
   Dim sqlFECHASIS As String
   Dim rsFEchaSis As ADODB.Recordset
      
   If oDBAdmin.AbrirBD(cnFECHASQL, psConnectString, False) = True Then
     
     sqlFECHASIS = "select convert(varchar,getdate(),120) as fechasis"
     If oDBAdmin.EjecutarConsulta(cnFECHASQL, sqlFECHASIS, rsFEchaSis) = True Then
         
         If rsFEchaSis!fechasis <> "" Then
             sFecha = rsFEchaSis!fechasis
         End If

     Else
         'no pudo abrir el rs: que consulte al access
         'MsgBox "No se pudo obtener la fecha, hay problemas de conexión de la red con la Base de Datos Principal", vbOKOnly + vbExclamation, "Aviso"
         sFecha = Format(Now(), "DD/MM/YYYY hh:mm")
         'Unload Me
     End If

     Set cnFECHASQL = Nothing

   Else
     'no pudo conectarse al sql: que consulte al access
      'MsgBox "No se pudo obtener la fecha, hay problemas de conexión de la red con la Base de Datos Principal", vbOKOnly + vbExclamation, "Aviso"
      sFecha = Format(Now(), "DD/MM/YYYY hh:mm")
      'Unload Me
   End If
   
   'FIN FECHA DEL SISTEMA DE LA BASE DE DATOS DE SQL

  
  'sFecha = Format(Now(), "DD/MM/YYYY hh:mm")

  Set ADORS = Nothing
  
  iFlagTipo = iTipoVenta
  If iTipoVenta = 4 Then
    iSigno = -1
    iFlagTipo = 1
  Else
    iSigno = 1
    iFlagTipo = iTipoVenta
  End If
  If iTipoVenta = 5 Then
    iFlagTipo = 1
  End If
  
  iCodOperRela = 0
  
  'vd 05/08/07 TDBGrid1.Update
      
  'Verifica si es un tipo de operaciòn que necesita password: Anulación o Descuento
  For i = gfax.LowerBound(1) To gfax.UpperBound(1)
    sTexto = IIf(Replace(gfax(i, 9), ",", "") = "", "0", Replace(gfax(i, 9), ",", ""))
    If val(sTexto) <> 0 Then
      bAcceso = True
      Exit For
    End If
  Next
  
  If bAcceso Then
    bAcceso = False
    Load frmAutorizarOperacion
    Set frmAutorizarOperacion.frmPadre = Me
    frmAutorizarOperacion.Show vbModal
    If Not bAcceso Then Exit Sub
    'bAcceso = False
  End If
  '--------Abre la gaveta de dinero automaticamente al aceptar la venta ----
  Dim opc_gaveta As String
  opc_gaveta = LeerCfg("PARAMETROS", "GAVETA", psArchivoCfg)
  If Trim(UCase(opc_gaveta)) = "S" Then
    Abre_Gaveta_Dinero (LeerCfg("PARAMETROS", "PRINTER", psArchivoCfg))
  End If
  '-------------------------------------------------------------------------
  If iTipoVenta = 6 Or iTipoVenta = 7 Then
    If Not IsNumeric(Replace(IIf(txtPagoAdelantado = "", "0.00", txtPagoAdelantado), ",", "")) Then Exit Sub
    If Not IsNumeric(Replace(IIf(txtPADEDolares = "", "0.00", txtPADEDolares), ",", "")) Then Exit Sub
    If val(Replace(IIf(txtPagoAdelantado = "", "0.00", txtPagoAdelantado), ",", "")) = 0 And _
       val(Replace(IIf(txtPADEDolares = "", "0.00", txtPADEDolares), ",", "")) = 0 Then
      MsgBox "Debe registar una cantidad mayor que cero."
      txtPagoAdelantado.SetFocus
      Exit Sub
    End If
  End If
 
  'Calculo de vueltos
  Dim iVueltoSoles As Double
  
  If iTipoVenta = 1 Or iTipoVenta = 4 Then   'Or iTipoVenta = 8
    If Trim(Me.txtEfectivoDolares.Text) = "" Then Me.txtEfectivoDolares.Text = "0.00"
    If Trim(Me.txtEfectivoSoles.Text) = "" Then Me.txtEfectivoSoles.Text = "0.00"
    
    If val(Replace(Me.txtEfectivoDolares.Text, ",", "")) = 0 And _
      val(Replace(Me.txtEfectivoSoles.Text, ",", "")) = 0 Then
      Me.txtEfectivoSoles.Text = Me.txtSoles
    End If
  End If

  'Configura la Impresora por default
  'sw 1 = Efectivo
  'sw 2 = VOUCHER
  'sw 3 = O/C
  'sw 4 = N/C
  'sw 5 = PADE
  'sw 6 = PADV
  'sw 7 = LIQPAD
  'sw 8 = ANULAR TRANSACCION
  'sw 9 = RECAUDACION
  
  Select Case iTipoVenta
    Case 4, 5, 6, 7, 8
      If iTipoVenta = 4 Then iTipoVenta = 20 ' O/C
      If iTipoVenta = 5 Then iTipoVenta = 21 ' N/C
      If iTipoVenta = 6 Then iTipoVenta = 22 ' PADE
      If iTipoVenta = 7 Then iTipoVenta = 23 ' PADV
      If iTipoVenta = 8 Then iTipoVenta = 24 ' LIQPAD
      ConfiguraImpresora kPAR_IMPRESORA_ALTERNA
    Case Else
      ConfiguraImpresora kPAR_IMPRESORA
  End Select
  
  Select Case iTipoVenta
    Case 20, 21, 22, 23, 24
      sSQL = "SELECT MAX(cOperCode) AS maximo FROM OperacionParalela"
    Case Else
      sSQL = "SELECT MAX(cOperCode) AS maximo FROM Operacion"
  End Select
  
  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
      'EscribirCfg "PARAMETROS", "cOpeB", psArchivoCfg, Str(iCodOper + 1)
    End If
  End If
  
  'Inicializa Recorset
  If iTipoVenta <> 2 And piEmitevoucher <> 1 Then
    Set rsPagTar = New Recordset
  End If

  If iCodOper = 1 Then
'    kOPERACION = LeerCfg("PARAMETROS", "cOpeB", psArchivoCfg)
'    iCodOper = Val(kOPERACION)
  End If
  
  'Si hay vuelto se convierte en iTipo = 5
  If iTipoVenta = 1 And (val(Replace(txtVueltoSoles, ",", "")) <> 0 Or val(Replace(txtVueltoDolares, ",", "")) <> 0) Then
    iTipoVenta = 5
  End If
  
  'Asigna valor para liquidar NC
  If iTipoVenta = 24 Then blLiquidaVenta = True
    
  'Registra los datos del producto
  If iTipoVenta = 22 Or iTipoVenta = 23 Or iTipoVenta = 24 Then
    nProducto = -1
  Else
    ReDim Producto(gfax.UpperBound(1))
    
    For i = gfax.LowerBound(1) To gfax.UpperBound(1)
      Producto(i).Almacen = kPAR_ALMACEN
      Producto(i).Cant = Replace(gfax(i, 6), ",", "")
      Producto(i).PUnit = Replace(gfax(i, 7), ",", "")
      Producto(i).Codigo = gfax(i, 1)
      Producto(i).nombre = gfax(i, 3)
      If gfax(i, 8) = "+" Then
        Producto(i).Dscto = Replace(IIf(gfax(i, 9) = "", 0, gfax(i, 9)), ",", "")
      Else
        Producto(i).Dscto = -1 * Replace(IIf(gfax(i, 9) = "", 0, gfax(i, 9)), ",", "")
      End If
      
      Producto(i).Canje = gfax(i, 11)
      Producto(i).Ptos = val(Replace(gfax(i, 12), ",", ""))
      Producto(i).Serv = gfax(i, 13)
    Next
    nProducto = gfax.UpperBound(1)
  End If
  
  
    
  If Trim(txtTarjeta.Text) <> "" Then
    sTarjeta = Right("00000000" + Trim(txtTarjeta.Text), 8)
  Else
    sTarjeta = ""
  End If
  
  'sw To SQL Server add
  idLocal = IIf(Trim(Me.txtLocal.Text) = "", "NULL", Trim(Me.txtLocal.Text))
  
  'Calcula el total de las ventas
  iTotalVenta = Replace(txtSolesLQ, ",", "")
  'lblTotal.Caption = "TOT:" + Right("               " + Format(CStr(iTotalVenta), "0.00"), 14)
  
  'Captura Serie y Codigo del Documento
  
  Select Case iTipoVenta
    Case 20
      cdocTipo = "10"
    Case 21
      cdocTipo = "11"
   Case 22
      cdocTipo = "12"
   Case 23
      cdocTipo = "13"
   Case 24
      cdocTipo = "14"
  End Select
  

  
  Dim dbCalculado As Boolean
  Dim ddtotefectivo, ddtotvuelto As Double
  Dim mon As Integer
  Dim ierroritm As Integer
  ierroritm = 0
  dbCalculado = False
  
  Do While dbCalculado = False And ierroritm < 3
    Select Case iTipoVenta
      Case 20, 21, 22, 23, 24
        If iTipoVenta = 22 Or iTipoVenta = 23 Then 'PADE o PADV
          iDolaresEfectivo = val(Replace(txtPADEDolares, ",", ""))
          iEfectivo = val(Replace(txtPagoAdelantado, ",", ""))
          If iEfectivo > 0 Then
            mon = 1
          End If
          If iDolaresEfectivo > 0 Then
            mon = 2
          End If
          If mon = 1 Then 'Soles
            iTotal = val(Replace(txtPagoAdelantado, ",", ""))
            iMontoDolares = CDbl(Format(CStr(iTotal / nTipoCambio), "0.00"))
            'iMontoDolares = CDbl(Format(CStr(iTotal / nTipoCambio), "0.00"))
          End If
          If mon = 2 Then 'Dolares
            iMontoDolares = val(Replace(txtPADEDolares, ",", ""))
            iTotal = CDbl(Format(CStr(iMontoDolares * nTipoCambio), "0.00"))
            'iTotal = CDbl(Format(CStr(iMontoDolares * nTipoCambio), "0.00"))
          End If
          
          iSolesEfectivo = iEfectivo
          iVuelto = 0
          iVueltoDolares = 0
        Else
          
          iTotal = val(Replace(txtSolesLQ, ",", ""))
          iMontoDolares = val(Replace(txtDolaresLQ, ",", ""))
          If piEmitevoucher = 1 And blLiquidaVenta = True Then
            iDolaresEfectivo = val(Replace(txtliqefectivodolares, ",", ""))
            iSolesEfectivo = val(Replace(txtliqefectivosoles, ",", ""))
            iEfectivo = val(Replace(txtliqefectivosoles, ",", ""))
            iVuelto = val(Replace(txtliqvueltosoles, ",", ""))
            iVueltoDolares = val(Replace(ttxliqvueltodolares, ",", ""))
          Else
            iDolaresEfectivo = val(Replace(txtEfectivoDolaresLQ, ",", ""))
            iSolesEfectivo = val(Replace(txtEfectivoSolesLQ, ",", ""))
            iEfectivo = val(Replace(txtEfectivoSolesLQ, ",", ""))
            iVuelto = val(Replace(txtSolesLQ, ",", "")) * -1 'val(Replace(txtVueltoSolesLQ, ",", ""))
            iVueltoDolares = 0 'val(Replace(txtDolaresLQ, ",", "")) * -1 'val(Replace(txtVueltoDolaresLQ, ",", ""))
          End If
          If iVuelto < 0 Then iVuelto = 0
          If iDolaresEfectivo < 0 Then iDolaresEfectivo = 0
          If iVueltoDolares < 0 Then iVueltoDolares = 0
          If iTipoVenta = 21 Then iCodOperRela = val(txtTX.Text)
          If iTipoVenta = 20 And Trim(txtLiq.Text) <> "" Then iCodOperRela = val(txtLiq.Text)
        End If
      Case Else
        iVuelto = val(Replace(txtVueltoSoles, ",", ""))
        iTotal = val(Replace(txtSoles, ",", ""))
        If iVuelto < 0 Then iVuelto = 0
        If piEmitevoucher = 1 And bLiquidaNC Then
          iEfectivo = val(Replace(txtliqefectivosoles, ",", ""))
          iDolaresEfectivo = val(Replace(txtliqefectivodolares, ",", ""))
          iVueltoDolares = val(Replace(ttxliqvueltodolares, ",", ""))
          iVuelto = val(Replace(Me.txtliqvueltosoles, ",", ""))
        Else
          iEfectivo = val(Replace(txtEfectivoSoles, ",", ""))
          iDolaresEfectivo = val(Replace(txtEfectivoDolares, ",", ""))
          iSolesEfectivo = val(Replace(txtEfectivoSoles, ",", ""))
          iVueltoDolares = val(Replace(txtVueltoDolares, ",", ""))
        End If
        If iVueltoDolares < 0 Then iVueltoDolares = 0
    End Select
    
    ddtotefectivo = Round(iSolesEfectivo + (iDolaresEfectivo * nTipoCambio), 2)
    ddtotvuelto = Round(iVuelto + (iVueltoDolares * nTipoCambio), 2)
    
    If (iTipoVenta <> 2 And iTipoVenta <> 22 And iTipoVenta <> 23 And iTipoVenta <> 21 And iTipoVenta <> 24) And (Round(ddtotefectivo - ddtotvuelto, 2) <> Round(iTotal, 2)) Then
      MsgBox "Ocurrio un error de Cálculo"
      dbCalculado = False
      ierroritm = ierroritm + 1
    Else
      dbCalculado = True
      ierroritm = 0
    End If
  Loop
  '------------------------
  '-- Captura Parámetros --
  '------------------------
  Texto_imprimir = ""
  Call CabeceraImpresion
  sTexto = ""
  
  sssql = "SELECT sImpresora, sImpresoraAlterna from Configuracion"
  If Not oDBAdmin.EjecutarConsulta(ADOCnn, sssql, rs1) Then GoTo Salir
  impr_1 = rs1.Fields("sImpresora")
  impr_2 = rs1.Fields("sImpresoraAlterna")
  
  'Pregunta si x.Devicename tiene el mismo nombre que el nombre de la impresora por donde necesitas sacar la impresion.
  If iTipoVenta = 1 Or iTipoVenta = 2 Or iTipoVenta = 5 Then
    p_1 = 1
  Else
    p_1 = 2
  End If
  
  printer.FontSize = 8 '11
  printer.FontName = "Courier New"
  
  Select Case iTipoVenta
    Case 20, 21, 22, 23, 24
    Case Else
      For i = 0 To UBound(sCabecera) - 1
        If Not Trim(sCabecera(i)) = "" Then
          sTexto = sTexto + Right(Space(60) + sCabecera(i), Int(Len(Space(40) + sCabecera(i)) / 2)) + vbCrLf
        End If
      Next
  End Select
  
  'Linea de Datos del Socio
  If Not sTarjeta = "" Then
    sTexto = sTexto + vbCrLf + " COD.TARJ.: " + sTarjeta + " "
    If Not blnfactura = True Then
      sTexto = sTexto + vbCrLf + " NOMBRE: " + txtNombres.Text + vbCrLf
    End If
  Else
    If Not blnfactura = True And Not Trim(txtNombres.Text) = "" Then
      sTexto = sTexto + vbCrLf + " NOMBRE: " + UCase(Trim(txtNombres.Text)) + vbCrLf
    End If
  End If
  
  If blnfactura = True Then
    sTexto = sTexto + vbCrLf + " NOMBRE: " & "____________________________"
    sTexto = sTexto + vbCrLf + vbCrLf + "         " & "____________________________" + vbCrLf
    sTexto = sTexto + vbCrLf + " RUC Cliente: " & Trim(Me.txtRUC.Text) + vbCrLf
  End If
  
  ' Obteniendo Nro de documento
  sSQL = "SELECT  * FROM Config_Documento WHERE cTipoDoc='" & cdocTipo & "'"
  If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
     
     

  If blnfactura = True Then
    If ADORS.EOF Then
      kSERIE_FACTURA = "F01"
      sSQL = "INSERT INTO Config_Documento (cTipoDoc,cOperCode,nDocCodigo,cSerieDoc,cUserDesc,dUltAct,observacion) " & _
             " VALUES ('01',0, 0, 'F01','',#" & Date & "#,'Primer Registro') "
      If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
      cDocCodigofull = 1
    Else
      kSERIE_FACTURA = LeerCampo(ADORS!cSerieDoc)
      cDocCodigofull = LeerCampo(ADORS!nDocCodigo) + 1
    End If
    cDocSerie = kSERIE_FACTURA
  Else
    Select Case cdocTipo
      Case "10"
        If ADORS.EOF Then
          KSERIE_PARALELO = "OC1"
          sSQL = "INSERT INTO Config_Documento (cTipoDoc,cOperCode,nDocCodigo,cSerieDoc,cUserDesc,dUltAct,observacion) " & _
                 " VALUES ('10',0, 0, 'OC1','',#" & Date & "#,'Primer Registro') "
          If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
          cDocCodigofull = 1
        Else
          KSERIE_PARALELO = LeerCampo(ADORS!cSerieDoc)
          cDocCodigofull = LeerCampo(ADORS!nDocCodigo) + 1
        End If
        cDocSerie = KSERIE_PARALELO
            
      Case "11"
        If ADORS.EOF Then
          KSERIE_PARALELO = "NC1"
          sSQL = "INSERT INTO Config_Documento (cTipoDoc,cOperCode,nDocCodigo,cSerieDoc,cUserDesc,dUltAct,observacion) " & _
                 " VALUES ('11',0, 0, 'NC1','',#" & Date & "#,'Primer Registro') "
          If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
          cDocCodigofull = 1
        Else
          KSERIE_PARALELO = LeerCampo(ADORS!cSerieDoc)
          cDocCodigofull = LeerCampo(ADORS!nDocCodigo) + 1
        End If
        cDocSerie = KSERIE_PARALELO
            
      Case "12"
        If ADORS.EOF Then
          KSERIE_PARALELO = "PA1"
          sSQL = "INSERT INTO Config_Documento (cTipoDoc,cOperCode,nDocCodigo,cSerieDoc,cUserDesc,dUltAct,observacion) " & _
                 " VALUES ('12',0, 0, 'PA1','',#" & Date & "#,'Primer Registro') "
          If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
          cDocCodigofull = 1
        Else
          KSERIE_PARALELO = LeerCampo(ADORS!cSerieDoc)
          cDocCodigofull = LeerCampo(ADORS!nDocCodigo) + 1
        End If
        cDocSerie = KSERIE_PARALELO
            
      Case "13"
        If ADORS.EOF Then
          KSERIE_PARALELO = "PV1"
          sSQL = "INSERT INTO Config_Documento (cTipoDoc,cOperCode,nDocCodigo,cSerieDoc,cUserDesc,dUltAct,observacion) " & _
                 " VALUES ('13',0, 0, 'PV1','',#" & Date & "#,'Primer Registro') "
          If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
          cDocCodigofull = 1
        Else
          KSERIE_PARALELO = LeerCampo(ADORS!cSerieDoc)
          cDocCodigofull = LeerCampo(ADORS!nDocCodigo) + 1
        End If
        cDocSerie = KSERIE_PARALELO
          
      Case "14"
        If ADORS.EOF Then
          KSERIE_PARALELO = "LQ1"
          sSQL = "INSERT INTO Config_Documento (cTipoDoc,cOperCode,nDocCodigo,cSerieDoc,cUserDesc,dUltAct,observacion) " & _
                 " VALUES ('14',0, 0, 'LQ1','',#" & Date & "#,'Primer Registro') "
          If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
          cDocCodigofull = 1
        Else
          KSERIE_PARALELO = LeerCampo(ADORS!cSerieDoc)
          cDocCodigofull = LeerCampo(ADORS!nDocCodigo) + 1
        End If
        cDocSerie = KSERIE_PARALELO
          
      Case Else
        If ADORS.EOF Then
          kSERIE = "B01"
          sSQL = "INSERT INTO Config_Documento (cTipoDoc,cOperCode,nDocCodigo,cSerieDoc,cUserDesc,dUltAct,observacion)" & _
                 " VALUES ('02',0, 0, 'B01', '', #" & Date & "#,'Primer Registro') "
          If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
          cDocCodigofull = 1
        Else
          kSERIE = LeerCampo(ADORS!cSerieDoc)
          cDocCodigofull = LeerCampo(ADORS!nDocCodigo) + 1
        End If
        cDocSerie = kSERIE
    End Select
  End If
  
  '------------------Validacion de Numeración Correlativa ----------------------------
  If cdocTipo = "01" Or cdocTipo = "02" Then
    sSQL = "SELECT MAX(cDocCodigo) AS maximo FROM Operacion WHERE cDocTipo = '" & cdocTipo & "'"
  Else
    sSQL = "SELECT MAX(cDocCodigo) AS maximo FROM OperacionParalela WHERE cDocTipo = '" & cdocTipo & "'"
  End If
  If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
  If val(cDocCodigofull) <> val("0" & (ADORS!Maximo) + 1) And val("0" & ADORS!Maximo) > 0 Then
    Dim NameArchivo As String
    Dim archivo
    Dim Texto As String
    Dim fso, MyFile
    Set fso = CreateObject("Scripting.FileSystemObject")
    archivo = "Error_Full_1" & cdocTipo & cDocCodigofull
    If Trim(archivo) = "" Then
      archivo = "textfile"
    End If
    Texto = Texto + "Codigo generado " & cDocCodigofull & Chr(13)
    
    NameArchivo = "C:\Temp\" + Trim(archivo) + ".log"
    Set MyFile = fso.CreateTextFile(NameArchivo, True)
    cDocCodigofull = ("0" & (ADORS!Maximo)) + 1
    Texto = Texto + "Nuevo Codigo " & cDocCodigofull & Chr(13)
    Texto = Texto + CStr(Now)
    MyFile.WriteLine (Texto)
    MsgBox "Ocurrio un error en la numeración, se asignará el " & cDocCodigofull & " al documento "
    MyFile.Close
  End If
  '---------------Actualizando el valor de la numeración ----------------
  sSQL = "UPDATE Config_Documento " & _
         " SET cSerieDoc='" & cDocSerie & "'," & _
         " nDocCodigo=" & cDocCodigofull & " " & _
         " WHERE cTipodoc='" & cdocTipo & "'"
  If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
  '------------------Impresión de Ticket----------------------------
  
  
  If blnfactura = True Then
    sTexto = sTexto + vbCrLf + " TK NRO: " & kSERIE_FACTURA & "-" & Right("000000" & CStr(cDocCodigofull), 6) & " NS:" & kSERIE_DISCO_DURO
  Else
    Select Case iTipoVenta
      Case 20, 22, 23, 24, 21
        sTexto = sTexto + vbCrLf + " TK NRO: " & KSERIE_PARALELO & "-" & Right("000000" & CStr(cDocCodigofull), 6) & " NS:" & kSERIE_DISCO_DURO1
      Case Else
        sTexto = sTexto + vbCrLf + " TK NRO: " & kSERIE & "-" & Right("000000" & CStr(cDocCodigofull), 6) & " NS:" & kSERIE_DISCO_DURO
    End Select
  End If
  
  'Printer.Print sTexto
  Texto_imprimir = Texto_imprimir + vbCrLf + sTexto
  sTexto = ""
  
  'Cabecera segun tipo de venta
  Select Case iTipoVenta
    Case 2 'Voucher
      sTexto = "VOUCHER"
      sTexto = Right(Space(60) + sTexto, Int(Len(Space(40) + sTexto) / 2)) + vbCrLf
    Case 1, 5 ' EFECTIVO EX Dolares
      If iDolaresEfectivo > 0 Then
        sTexto = "U$(TC: " + Format(CStr(nTipoCambio), "###,##0.00") + ")"
        sTexto = Right(Space(60) + sTexto, Int(Len(Space(40) + sTexto) / 2)) + vbCrLf
      End If
    Case 4 'Anula Productos
      sTexto = "ANULA PROD"
      sTexto = Right(Space(60) + sTexto, Int(Len(Space(40) + sTexto) / 2)) + vbCrLf
    Case 20 'O/C
      sTexto = "O/C"
      sTexto = Right(Space(60) + sTexto, Int(Len(Space(40) + sTexto) / 2)) + vbCrLf
    Case 21 'NC
      sTexto = "N/C"
      sTexto = Right(Space(60) + sTexto, Int(Len(Space(40) + sTexto) / 2)) + vbCrLf
    Case 22 'PADE
      sTexto = "PADE"
      sTexto = Right(Space(60) + sTexto, Int(Len(Space(40) + sTexto) / 2)) + vbCrLf
    Case 23 'PADV
      sTexto = "PADV"
      sTexto = Right(Space(60) + sTexto, Int(Len(Space(40) + sTexto) / 2)) + vbCrLf
    Case 24 'LIQ
      sTexto = "LIQPAD"
      sTexto = Right(Space(60) + sTexto, Int(Len(Space(40) + sTexto) / 2)) + vbCrLf
  End Select
  'Printer.Print sTexto
  Texto_imprimir = Texto_imprimir + vbCrLf + sTexto + vbCrLf
  sTexto = ""
  
  'Ancho de linea = 27
  
  iSubTotal = 0
  If iTipoVenta <> 22 And iTipoVenta <> 23 Then
    iTotal = 0
  End If
  iTotItems = 0
  iTotalDscto = 0
  iServicio = 0
  iPtoItm = 0
  iPtoVta = 0
    
    
  '<<<<<<<<<<<<<<<<<<<<<<<<<-------------------------------->>>>>>>>>>>>>>>>>>>>>>>>>>>>
  
  If iTipoVenta = 22 Or iTipoVenta = 23 Or iTipoVenta = 24 Then
    If iTipoVenta = 24 Then
      iTotal = val(Replace(txtPagoAdelantado, ",", ""))
    End If
    
    '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 sProdDesc As String
    Dim nDscto As Double
    Dim sTeclDesc As String
    Dim toti As Double
    Dim isubtotal_1 As Double
    Dim PUnit As Double
    
    If iTipoVenta = 24 Then
      iTotal = 0
      iTotItems = 0
      
      sTexto = sTexto + "Producto         Cant Precio  SubTotal " + vbCrLf
      sTexto = sTexto + "---------------------------------------" + vbCrLf
      
      For i = 1 To lvwTX(1).ListItems.Count
        iOperNC = lvwTX(1).ListItems(i).Text
        sSQL = " SELECT O.cOperCode, O.cProdCode, O.nProdCant, O.nProdPrecUnit, O.nDscto,P.sProdDesc, P.sProdDescCrta," & _
               " O.nProdCant * O.nProdPrecUnit 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(iOperNC)
                'O.nProdCant * O.nProdPrecUnit * (100 - O.nDscto) / 100 As TotalMonto,
        If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
  
        nSubtotal = 0
        sTexto = sTexto + "TX" + CStr(iOperNC) + vbCrLf
        Do While Not ADORS.EOF
          nItems = LeerCampo(ADORS("nProdCant"))
          PUnit = LeerCampo(ADORS("nProdPrecUnit"))
          sProdDescCrta = LeerCampo(ADORS("sProdDescCrta"))
          sProdDesc = LeerCampo(ADORS("sProdDesc"))
          
          nDscto = LeerCampo(ADORS("nDscto"))
          If nDscto > 0 Then
            PUnit = PUnit * nDscto / 100 + PUnit
          End If
                    
          sTexto = sTexto + Left(sProdDescCrta + Space(16), 16) & _
                    " " + Right(Space(4) & CStr(nItems), 4) & _
                    " " + Right(Space(6) & Format(CStr(PUnit), "0.00"), 6) & _
                    " " + Right(Space(9) & Format(CStr(PUnit * nItems), "0.00"), 9) + vbCrLf
          If nDscto < 0 Then
             sTexto = sTexto + Left("*Dscto " + CStr(Abs(nDscto)) + " %" + Space(16), 16) & _
                      " " + Space(11) & _
                      " " + Right(Space(9) & Format(CStr(PUnit * nItems * nDscto / 100), "0.00"), 9) + vbCrLf
             PUnit = PUnit * nDscto / 100 + PUnit
                     
          End If
          nSubtotal = nSubtotal + (PUnit * nItems)
          
          ADORS.MoveNext
          iTotItems = iTotItems + nItems
        Loop
        sTexto = sTexto + Chr(13) + Left(" AV./ITEM" & Space(23), 23) + Right(Space(15) & Format(CStr(nItems), "0.00"), 15) + vbCrLf
        iTotal = iTotal + nSubtotal
      Next
    End If
    '----------------------------
  Else
    
    sTexto = sTexto + "Producto         Cant Precio  SubTotal " + vbCrLf
    sTexto = sTexto + "---------------------------------------" + vbCrLf
    iServicio = 0
    igvf = 0
    For i = 0 To gfax.UpperBound(1)
      If blnfactura = True Then
            
        If (Trim(gfax(i, 13)) = "SI") Then
          iSubTotal = (val(Replace(gfax(i, 6), ",", "")) * val(Replace(gfax(i, 7), ",", "")) + (val(Replace(gfax(i, 6), ",", "")) * val(Replace(gfax(i, 7), ",", "")) * Producto(i).Dscto / 100)) / (1 + kIGV + kPAR_PORCSERV * (IIf(gfax(i, 13) = "SI", 1, 0)) / 100)
          isubtotal_1 = val(Replace(gfax(i, 6), ",", "")) * val(Replace(gfax(i, 7), ",", ""))
          toti = (kPAR_PORCSERV * iSubTotal * IIf(gfax(i, 13) = "SI", 1, 0)) / 100
          IGV_1 = val(Replace(gfax(i, 15), ",", ""))
          iServicio = iServicio + val(Replace(gfax(i, 14), ",", ""))
          PUnit = val(Replace(gfax(i, 7), ",", "")) / (1 + kIGV + kPAR_PORCSERV * (IIf(gfax(i, 13) = "SI", 1, 0)) / 100)
        Else
          iSubTotal = val(Replace(gfax(i, 6), ",", "")) * val(Replace(gfax(i, 7), ",", ""))
          PUnit = val(Replace(gfax(i, 7), ",", ""))
          IGV_1 = val(Replace(gfax(i, 15), ",", ""))
        End If
            
        nDscto = Producto(i).Dscto
                        
        PUnit = val(Replace(gfax(i, 7), ",", ""))
        If nDscto > 0 Then
          PUnit = PUnit * nDscto / 100 + PUnit
        End If
        
        sTexto = sTexto + Left(Producto(i).nombre + Space(16), 16) & _
               " " + Right(Space(4) & CStr(val(Replace(gfax(i, 6), ",", ""))), 4) & _
               " " + Right(Space(6) & Format(CStr(PUnit), "0.00"), 6) & _
               " " + Right(Space(9) & Format(CStr(PUnit * val(Replace(gfax(i, 6), ",", ""))), "0.00"), 9) + vbCrLf
                         
        iTotal = iTotal + iSubTotal
        igvf = igvf + IGV_1
        iTotItems = iTotItems + val(Replace(gfax(i, 6), ",", ""))
        
      Else ' tk boleta de venta
                                                         
        If (Trim(gfax(i, 13)) = "SI") Then
          iSubTotal = (val(Replace(gfax(i, 6), ",", "")) * val(Replace(gfax(i, 7), ",", "")) + (val(Replace(gfax(i, 6), ",", "")) * val(Replace(gfax(i, 7), ",", "")) * Producto(i).Dscto / 100)) / (1 + kIGV + kPAR_PORCSERV * (IIf(gfax(i, 13) = "SI", 1, 0)) / 100)
          isubtotal_1 = val(Replace(gfax(i, 6), ",", "")) * val(Replace(gfax(i, 7), ",", ""))
          toti = (kPAR_PORCSERV * iSubTotal * IIf(gfax(i, 13) = "SI", 1, 0)) / 100
          IGV_1 = isubtotal_1 - iSubTotal - toti
          PUnit = val(Replace(gfax(i, 7), ",", "")) / (1 + kIGV + kPAR_PORCSERV * (IIf(gfax(i, 13) = "SI", 1, 0)) / 100)
        Else
          iSubTotal = val(Replace(gfax(i, 6), ",", "")) * val(Replace(gfax(i, 7), ",", ""))
          PUnit = val(Replace(gfax(i, 7), ",", ""))
          IGV_1 = 0
        End If
            
        nDscto = Producto(i).Dscto
        PUnit = val(Replace(gfax(i, 7), ",", ""))
        If nDscto > 0 Then
          PUnit = PUnit * nDscto / 100 + PUnit
        End If
        
        sTexto = sTexto + Left(Producto(i).nombre + Space(16), 16) & _
               " " + Right(Space(4) & CStr(val(Replace(gfax(i, 6), ",", ""))), 4) & _
               " " + Right(Space(6) & Format(CStr(PUnit), "0.00"), 6) & _
               " " + Right(Space(9) & Format(CStr(PUnit * val(Replace(gfax(i, 6), ",", ""))), "0.00"), 9) + vbCrLf
        
        iServicio = iServicio + val(Replace(gfax(i, 14), ",", ""))
        iTotal = iTotal + iSubTotal
        iTotItems = iTotItems + val(Replace(gfax(i, 6), ",", ""))
      End If
      'Controla el total de puntos por item y por venta
      iPtoItm = 0
      iPtoVta = 0
      IGV_1 = 0
      
      'Descuentos
      nDscto = (Producto(i).Dscto * val(Replace(gfax(i, 7), ",", "")) / 100)
      
      iSubTotalDscto = val(Replace(gfax(i, 6), ",", "")) * val(Replace(gfax(i, 7), ",", "")) + (nDscto / 100 * (val(Replace(gfax(i, 6), ",", "")) * val(Replace(gfax(i, 7), ",", ""))))
      Dim Serv As Double
       
      If Producto(i).Dscto < 0 Then
        sTexto = sTexto + Left("*Dscto " + CStr(Abs(Producto(i).Dscto)) + " %" + Space(16), 16) & _
               " " + Space(11) & _
               " " + Right(Space(9) & Format(CStr(PUnit * val(Replace(gfax(i, 6), ",", "")) * Producto(i).Dscto / 100), "0.00"), 9) + vbCrLf
      End If
            
      iTotalDscto = iTotalDscto + nDscto
        
    Next
  End If
 

  'Añade el % de servicio al total
    
  sTexto = sTexto + "---------------------------------------"
  Texto_imprimir = Texto_imprimir + vbCrLf + sTexto
  sTexto = ""
  
  'Total segun tipo de venta
  
  Select Case iTipoVenta
    Case 2 'Normal, Voucher
    
        If blnfactura = True Then
            sTexto = Left(" VALOR VTA" + Space(23), 23) + Right(Space(15) + Format(CStr(val(Replace(txtSoles.Text, ",", "")) - igvf - iServicio), "0.00"), 15) + vbCrLf
                       
            sTexto = sTexto + Left(" IGV" + Space(23), 23) + Right(Space(15) + Format(CStr(igvf), "0.00"), 15) + vbCrLf
            If iServicio > 0 Then
                sTexto = sTexto + Left(" SERVICIO" + "(" + kPAR_PORCSERV + " %)" + Space(23), 23) + Right(Space(15) + Format(CStr(iServicio), "0.00"), 15) + vbCrLf
            End If
            sTexto = sTexto + Left(" TOTAL VTA" + Space(23), 23) + Right(Space(15) + Format(CStr(val(Replace(txtSoles.Text, ",", ""))), "0.00"), 15) + vbCrLf + vbCrLf
                        
            toti = val(Replace(txtSoles, ",", ""))
            iTotal = 0
            If rsPagTar.RecordCount > 0 Then
                rsPagTar.MoveFirst
                Do While Not rsPagTar.EOF
                    sTexto = sTexto + Left(" " + rsPagTar.Fields("descrip") + Space(23), 23) + Right(Space(15) + Format(CStr(rsPagTar.Fields("pago")), "0.00"), 15) + vbCrLf
                    toti = toti - rsPagTar.Fields("pago")
                    iTotal = iTotal + rsPagTar.Fields("pago")
                    rsPagTar.MoveNext
                Loop
            End If
            If val(Replace(txtSoles, ",", "")) > iTotal Then
                ivuelto_1 = 0
            Else
                ivuelto_1 = toti - iTotal
            End If
        
        Else
            IGV_1 = (val(Replace(txtSoles.Text, ",", "")) - val(CStr(iTotal)))
            'Validacion
            If Round(IGV_1 + iTotal, 2) <> val(Replace(txtSoles.Text, ",", "")) Then
               MsgBox "Inconsistencia de Datos"
               iTotal = val(Replace(txtSoles.Text, ",", "")) - IGV_1
            End If
                        
            sTexto = Left(" VALOR VTA" + Space(23), 23) + Right(Space(15) + Format(CStr(val(Replace(txtSoles.Text, ",", ""))), "0.00"), 15) + vbCrLf
            
            If iServicio > 0 Then
                sTexto = sTexto + Left(" SERVICIO" + "(" + kPAR_PORCSERV + " %)" + Space(23), 23) + Right(Space(15) + Format(CStr(iServicio), "0.00"), 15) + vbCrLf
            End If
            
            toti = val(Replace(txtSoles.Text, ",", ""))
            
            If rsPagTar.RecordCount > 0 Then
                rsPagTar.MoveFirst
                Do While Not rsPagTar.EOF
                    sTexto = sTexto + Left(" " + rsPagTar.Fields("descrip") + Space(23), 23) + Right(Space(15) + Format(CStr(rsPagTar.Fields("pago")), "0.00"), 15) + vbCrLf
                    toti = toti - rsPagTar.Fields("pago")
                    iTotal = iTotal + rsPagTar.Fields("pago")
                    rsPagTar.MoveNext
                Loop
            End If
            
           
            iTotal = 0
            If val(Replace(txtSoles, ",", "")) > iTotal Then
                ivuelto_1 = 0
            Else
                ivuelto_1 = toti - iTotal
            End If
            
                        
        End If
        If bLiquidaNC = False Then
            If toti > 0 Then
               sTexto = sTexto + Left(" EFECTIVO S/." + Space(23), 23) + Right(Space(15) + Format(CStr(toti), "0.00"), 15) + vbCrLf
            End If
            If ivuelto_1 > 0 Then
               sTexto = sTexto + Left(" VUELTO" + Space(23), 23) + Right(Space(15) + Format(CStr(ivuelto_1), "0.00"), 15) + vbCrLf
            End If
        Else
         If Trim(txtliqefectivosoles.Text) = "" Then txtliqefectivosoles.Text = "0.00"
         If Trim(txtliqefectivodolares.Text) = "" Then txtliqefectivodolares.Text = "0.00"
         If Trim(txtliqpade.Text) = "" Then txtliqpade.Text = "0.00"
         If Trim(txtliqvueltosoles.Text) = "" Then txtliqvueltosoles.Text = "0.00"
         If Trim(ttxliqvueltodolares.Text) = "" Then ttxliqvueltodolares.Text = "0.00"
         
         If CDbl(txtliqefectivosoles.Text) > 0 Then
            sTexto = sTexto + Left(" EFECTIVO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqefectivosoles.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqefectivodolares.Text) > 0 Then
            sTexto = sTexto + Left(" EFECTIVO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqefectivodolares.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqpade.Text) > 0 Then
           sTexto = sTexto + Left(" PADE/PADV" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqpade.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqvueltosoles.Text) <> 0 Then
            sTexto = sTexto + Left(" VUELTO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqvueltosoles.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(ttxliqvueltodolares.Text) <> 0 Then
            sTexto = sTexto + Left(" VUELTO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(ttxliqvueltodolares.Text), "0.00"), 15)
         End If
        End If
       ' Set rsPagTar = Nothing
      
   Case 4 'Anula Productos
      sTexto = Left(" CASH/TL" + Space(23), 23) + Right(Space(15) + Format(CStr(iTotal), "0.00"), 15)
    Case 5, 1 'Efectivo
       If blnfactura = True Then
          sTexto = Left(" VALOR VTA" + Space(23), 23) + Right(Space(15) + Format(CStr(val(Replace(txtSoles.Text, ",", "")) - igvf - iServicio), "0.00"), 15) + vbCrLf
          sTexto = sTexto + Left(" IGV" + Space(23), 23) + Right(Space(15) + Format(CStr(igvf), "0.00"), 15) + vbCrLf
          If iServicio > 0 Then
            sTexto = sTexto + Left(" SERVICIO" + "(" + kPAR_PORCSERV + " %)" + Space(23), 23) + Right(Space(15) + Format(CStr(iServicio), "0.00"), 15) + vbCrLf
          End If
          sTexto = sTexto + Left(" TOTAL VTA" + Space(23), 23) + Right(Space(15) + Format(CStr(val(Replace(txtSoles.Text, ",", ""))), "0.00"), 15) + vbCrLf + vbCrLf
      Else 'adicionado
            sTexto = Left(" VALOR VTA" + Space(23), 23) + Right(Space(15) + Format(CStr(val(Replace(txtSoles.Text, ",", ""))), "0.00"), 15) + vbCrLf
            If iServicio > 0 Then
               sTexto = sTexto + Left(" SERVICIO" + "(" + kPAR_PORCSERV + " %)" + Space(23), 23) + Right(Space(15) + Format(CStr(iServicio), "0.00"), 15) + vbCrLf
            End If
      End If
     If bLiquidaNC = False Then
        If iEfectivo > 0 Then
           sTexto = sTexto + Left(" EFECTIVO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(iEfectivo), "0.00"), 15) + vbCrLf
        End If
        If iDolaresEfectivo > 0 Then
           sTexto = sTexto + Left(" EFECTIVO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(iDolaresEfectivo), "0.00"), 15) + vbCrLf
        End If
        If iVuelto <> 0 Then
           sTexto = sTexto + Left(" VUELTO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(iVuelto), "0.00"), 15) + vbCrLf
        End If
        If iVueltoDolares <> 0 Then
           sTexto = sTexto + Right(" VUELTO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(iVueltoDolares), "0.00"), 15)
        End If
      Else
         If Trim(txtliqefectivosoles.Text) = "" Then txtliqefectivosoles.Text = "0.00"
         If Trim(txtliqefectivodolares.Text) = "" Then txtliqefectivodolares.Text = "0.00"
         If Trim(txtliqpade.Text) = "" Then txtliqpade.Text = "0.00"
         If Trim(txtliqvueltosoles.Text) = "" Then txtliqvueltosoles.Text = "0.00"
         If Trim(ttxliqvueltodolares.Text) = "" Then ttxliqvueltodolares.Text = "0.00"
         
         If piEmitevoucher = 1 Then
            If rsPagTar.RecordCount > 0 Then
                rsPagTar.MoveFirst
               
                Do While Not rsPagTar.EOF
                    sTexto = sTexto + Left(" " + rsPagTar.Fields("descrip") + Space(23), 23) + Right(Space(15) + Format(CStr(rsPagTar.Fields("pago")), "0.00"), 15) + vbCrLf
                    toti = toti - rsPagTar.Fields("pago")
                    iTotal = iTotal + rsPagTar.Fields("pago")
                    rsPagTar.MoveNext
                Loop
            End If
         End If
         
         If CDbl(txtliqefectivosoles.Text) > 0 Then
            sTexto = sTexto + Left(" EFECTIVO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqefectivosoles.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqefectivodolares.Text) > 0 Then
            sTexto = sTexto + Left(" EFECTIVO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqefectivodolares.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqpade.Text) > 0 Then
             sTexto = sTexto + Left(" PADE/PADV" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqpade.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqvueltosoles.Text) <> 0 Then
             sTexto = sTexto + Left(" VUELTO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqvueltosoles.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(ttxliqvueltodolares.Text) <> 0 Then
             sTexto = sTexto + Left(" VUELTO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(ttxliqvueltodolares.Text), "0.00"), 15)
         End If
        End If
    Case 20 'O/C
          
    If bLiquidaNC = False Then
         sTexto = Left(" VALOR VTA" + Space(23), 23) + Right(Space(15) + Format(CStr(txtSoles.Text), "0.00"), 15) + vbCrLf
         If iServicio > 0 Then
             sTexto = sTexto + Left(" SERVICIO" + "(" + kPAR_PORCSERV + " %)" + Space(23), 23) + Right(Space(15) + Format(CStr(iServicio), "0.00"), 15) + vbCrLf
         End If
       
         If iEfectivo > 0 Then
            sTexto = sTexto + Left(" EFECTIVO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtEfectivoSoles.Text), "0.00"), 15) + vbCrLf
         End If
         If iDolaresEfectivo > 0 Then
             sTexto = sTexto + Left(" EFECTIVO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtEfectivoDolares.Text), "0.00"), 15) + vbCrLf
         End If
         If iVuelto <> 0 Then
              sTexto = sTexto + Left(" VUELTO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(iVuelto), "0.00"), 15) + vbCrLf
         End If
         If iVueltoDolares <> 0 Then
             sTexto = sTexto + Left(" VUELTO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(iVueltoDolares), "0.00"), 15)
         End If
     Else
         sTexto = Left(" VALOR VTA" + Space(23), 23) + Right(Space(15) + Format(CStr(txtSoles.Text), "0.00"), 15) + vbCrLf
         If iServicio > 0 Then
             sTexto = sTexto + Left(" SERVICIO" + "(" + kPAR_PORCSERV + " %)" + Space(23), 23) + Right(Space(15) + Format(CStr(iServicio), "0.00"), 15) + vbCrLf
         End If
       
         If CDbl(txtliqefectivosoles.Text) > 0 Then
             sTexto = sTexto + Left(" EFECTIVO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqefectivosoles.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqefectivodolares.Text) > 0 Then
              sTexto = sTexto + Left(" EFECTIVO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqefectivodolares.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqpade.Text) > 0 Then
              sTexto = sTexto + Left(" PADE/PADV" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqpade.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqvueltosoles.Text) <> 0 Then
             sTexto = sTexto + Left(" VUELTO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqvueltosoles.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(ttxliqvueltodolares.Text) <> 0 Then
              sTexto = sTexto + Left(" VUELTO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(ttxliqvueltodolares.Text), "0.00"), 15)
         End If
     
     End If
    Case 21 'N/C
         sTexto = Left(" TOTAL S/." + Space(23), 23) + Right(Space(15) + Format(CStr(txtSoles), "0.00"), 15)
    Case 22 'PADE
      Select Case mon
       Case 2
          sTexto = Left(" CASH/TL" + Space(19), 19) + Right(Space(19) + "US$ " + Format(CStr(iMontoDolares), "0.00"), 19)
       Case Else
          sTexto = Left(" CASH/TL" + Space(19), 19) + Right(Space(19) + "S/. " + Format(CStr(iTotal), "0.00"), 19)
      End Select
      
    Case 23 'PADV
    'jpcb270710
      Select Case mon
       Case 2
        If iTipoVenta = 23 Then
            sTexto = Left(" TARJETA" + Space(19), 19) + Right(Space(19) + "US$ " + Format(CStr(iMontoDolares), "0.00"), 19)
        Else
           sTexto = Left(" CASH/TL" + Space(19), 19) + Right(Space(19) + "US$ " + Format(CStr(iMontoDolares), "0.00"), 19)
        End If
           
       Case Else
        If iTipoVenta = 23 Then
            sTexto = Left(" TARJETA" + Space(19), 19) + Right(Space(19) + "S/. " + Format(CStr(iTotal), "0.00"), 19)
        Else
            sTexto = Left(" CASH/TL" + Space(19), 19) + Right(Space(19) + "S/. " + Format(CStr(iTotal), "0.00"), 19)
        End If
      End Select
      
    Case 24 'LIQPAD
          sTexto = Left(" SUB/TOTL" + Space(23), 23) + Right(Space(15) + Format(CStr(iTotal), "0.00"), 15) + vbCrLf
          sTexto = sTexto + Left(" FADE/BADE" + Space(23), 23) + Right(Space(15) + txtTotalPA.Text, 15) + vbCrLf
          sTexto = sTexto + Left(" TOT-PAGAR" + Space(23), 23) + Right(Space(15) + txtSolesLQ.Text, 15) + vbCrLf
         If iEfectivo > 0 Then
            sTexto = sTexto + Left(" EFECTIVO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(iEfectivo), "0.00"), 15) + vbCrLf
         End If
        If iDolaresEfectivo > 0 Then
           sTexto = sTexto + Left(" EFECTIVO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(iDolaresEfectivo), "0.00"), 15) + vbCrLf
        End If
           
      If piEmitevoucher = 1 Then
         If rsPagTar.RecordCount > 0 Then
            rsPagTar.MoveFirst
               
            Do While Not rsPagTar.EOF
               'sTexto = sTexto + Left(" " + rsPagTar.Fields("descrip") + Space(23), 23) + Right(Space(15) + Format(CStr(rsPagTar.Fields("pago")), "0.00"), 15) + vbCrLf
               sTexto = sTexto + Left(" " + rsPagTar.Fields("descrip") + Space(23), 23) + Right(Space(15) + Format(CStr(rsPagTar.Fields("pago")), "0.00"), 15) + vbCrLf
               toti = toti - rsPagTar.Fields("pago")
               iTotal = iTotal + rsPagTar.Fields("pago")
              rsPagTar.MoveNext
            Loop
         End If
       End If
      If iVuelto <> 0 Then
          sTexto = sTexto + Left(" VUELTO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(iVuelto), "0.00"), 15) + vbCrLf
      End If
      If iVueltoDolares <> 0 Then
          sTexto = sTexto + Left(" VUELTO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(iVueltoDolares), "0.00"), 15)
      End If
           
  End Select

  
  printer.FontSize = 9 '12
  printer.FontBold = True
  Texto_imprimir = Texto_imprimir + vbCrLf + sTexto
  sTexto = ""
  If iTotItems > 0 Then
     sTexto = Left(" ITEM" + Space(23), 23) + Right(Space(15) + Format(CStr(iTotItems), "0.00"), 15)
 End If
  Select Case iTipoVenta
    Case 4 'Anula Productos
      sTexto = sTexto + vbCrLf + "VO-POSTN"
  End Select
  
  Texto_imprimir = Texto_imprimir + vbCrLf + sTexto + vbCrLf
  'Printer.Print sTexto
    
  'Printer.Print " "
  
  sTexto = ""
'
'  sTexto = sTexto + "---------------------------------------" + vbCrLf
'  sTexto = sTexto + Left(" TRANSACCION" + Space(23), 23) + Right(Space(15) + CStr(iCodOper), 15) + vbCrLf
'  sTexto = sTexto + "---------------------------------------" + vbCrLf

 '---Puntos----------
' nImporte = CDbl(Me.txtSoles.Text)
' If nImporte > 0 And sTarjeta <> "" Then
'   iPuntos = Int(nImporte / lReglaPuntoImporte) * lReglaPuntoCantidad
' End If
'
'
'  If sTarjeta <> "" Then
'     'sw 'sw Add 19/06/2009, era solo >>> intPuntosAcumulados = ObtenerPuntosAcumulados(sTarjeta)
'     intPuntosAcumulados = ObtenerPuntosAcumulados(sTarjeta, Trim(Me.txtLocal.Text))
'     If (intPuntosAcumulados + iPuntos) >= 0 And iPuntos > 0 And intPuntosAcumulados <> -1 Then
'         sTexto = sTexto & " UD. ACUMULO: " & iPuntos & " PUNTOS" & vbCrLf
'         sTexto = sTexto & " TIENE ACUMULADO: " & IIf(intPuntosAcumulados + iPuntos < 0, "**", intPuntosAcumulados + iPuntos) & " PUNTOS" & vbCrLf & vbCrLf
'     End If
'  End If
  
 '---Fin Puntos------
  
  sTexto = sTexto + Space(9) + Format(CStr(Now()), "(DDD) DD/MM/YYYY ") + Format(CStr(Now()), "hh:mm") + vbCrLf 'Hora: 6 + 1
  If bAcceso = True Then
    sTexto = sTexto + "       SUPERVISOR: " + txtsupervisor + vbCrLf
  End If
  sTexto = sTexto + Space(3) + Left(psUsuario_Descripcion, 10) + " " 'Usuario: 10 + 1
  sTexto = sTexto + Space(1) + "Cj:" + kPAR_CAJA + " T:" + kPAR_TURNO
  sTexto = sTexto + Space(1) + "v" & App.Major & "." & App.Minor & "." & App.Revision
  sTexto = sTexto + vbCrLf & "         Correlativo: " & ObtenerCorrelativo(p_1)

  Select Case iTipoVenta
 Case 20, 22, 23, 21
 Case 24
     If piEmitevoucher <> 1 Then
        txtliqefectivodolares.Text = IIf(Trim(txtEfectivoDolares.Text) = "", "0.00", txtEfectivoDolares.Text)
        txtliqefectivosoles.Text = IIf(Trim(txtEfectivoSoles.Text) = "", "0.00", txtEfectivoSoles.Text)
        txtliqvueltosoles.Text = IIf(Trim(txtVueltoSoles.Text) = "", "0.00", txtVueltoSoles.Text)
        txtliqvueltodolares.Text = IIf(Trim(txtVueltoDolares.Text) = "", "0.00", txtVueltoDolares.Text)
     End If
     txtliqpade.Text = IIf(Trim(txtTotalPA.Text) = "", "0.00", txtTotalPA.Text)
     txtLiq.Text = iCodOper
 Case Else
    sTexto = sTexto + vbCrLf + vbCrLf + "   " + kPIE_TICKET
 End Select
  
  printer.FontSize = 8 '11
  printer.FontBold = False
  '-------------segun impresora seleccionada --------
  Texto_imprimir = Texto_imprimir + vbCrLf + sTexto
  
If p_1 = 1 Then
  ConfiguraImpresora kPAR_IMPRESORA
  Select Case KImpresora
     Case 1
         Call CortePapel(Texto_imprimir, p_1, CStr(iCodOper))
     Case 0
         printer.Print Texto_imprimir
         printer.Print " "
         printer.Print " "
         printer.EndDoc
   End Select
Else
   ConfiguraImpresora kPAR_IMPRESORA_ALTERNA
  Select Case KImpresoraALT
     Case 1
          Call CortePapel(Texto_imprimir, p_1)
      Case 0
          printer.Print Texto_imprimir
          printer.Print " "
          printer.Print " "
          printer.EndDoc
    End Select
End If
  

  '-------------------Graba operacion -------------------------
   Select Case iTipoVenta
    Case 20, 21, 22, 23, 24
      If iTipoVenta = 22 Or iTipoVenta = 23 Or iTipoVenta = 24 Then
      Else
        
        iDolaresEfectivo = val(Replace(txtEfectivoDolares, ",", ""))
        iSolesEfectivo = val(Replace(txtEfectivoSoles, ",", ""))
        iTotal = val(Replace(txtSoles, ",", ""))
        iMontoDolares = val(Replace(txtDolares, ",", ""))
        iEfectivo = val(Replace(txtEfectivoSoles, ",", ""))
        iVuelto = val(Replace(Me.txtVueltoSoles, ",", ""))
        If iVuelto < 0 Then iVuelto = 0
        iVueltoDolares = val(Replace(Me.txtVueltoDolares, ",", ""))
        If iVueltoDolares < 0 Then iVueltoDolares = 0
        If iTipoVenta = 21 Then
            iCodOperRela = val(txtTX.Text)
        Else
            'jpcb 17/12/2008
            If iTipoVenta = 20 And Trim(txtLiq.Text) <> "" Then
            Else
                iCodOperRela = 0
            End If
        End If
      End If
          
      
      '------------------Validacion de Numeración Correlativa -------------------------//
      If cdocTipo = "01" Or cdocTipo = "02" Then
         sSQL = "SELECT MAX(cDocCodigo) AS maximo FROM Operacion WHERE cDocTipo = '" & cdocTipo & "'"
      Else
         sSQL = "SELECT MAX(cDocCodigo) AS maximo FROM OperacionParalela WHERE cDocTipo = '" & cdocTipo & "'"
      End If
      If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
    If cDocCodigofull <> ((ADORS!Maximo) + 1) And val("0" & ADORS!Maximo) > 0 Then
      Set fso = CreateObject("Scripting.FileSystemObject")
      archivo = "Error_Full2" & cdocTipo & cDocCodigofull
      If Trim(archivo) = "" Then
          archivo = "textfile"
      End If
      Texto = Texto + "Codigo generado " & cDocCodigofull & Chr(13)
      
      NameArchivo = "C:\Temp\" + Trim(archivo) + ".log"
      Set MyFile = fso.CreateTextFile(NameArchivo, True)
      cDocCodigofull = ("0" & (ADORS!Maximo)) + 1
      Texto = Texto + "Nuevo Codigo " & cDocCodigofull & Chr(13)
      Texto = Texto + CStr(Now)
      MyFile.WriteLine (Texto)
      MsgBox "Ocurrio un error en la numeración, se asignará el " & cDocCodigofull & " al documento "
      MyFile.Close
    End If
    
    '---------------Actualizando el valor de la numeración --------------------------------//
    sSQL = "UPDATE Config_Documento " & _
          " SET cOperCode=" & CStr(iCodOper) & "," & _
          " nDocCodigo=" & cDocCodigofull & ", " & _
          " cUserDesc='" & psUsuario_Descripcion & "' " & _
          " WHERE cTipodoc='" & cdocTipo & "'"
    If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
    
    '------------------fin Validacion de Numeración Correlativa -----------------------
      
     If iTipoVenta = 23 Then
     '170810 VALIDA EL ERROR DE DUPLICIDAD DE PADV  (por error se graba otro registro inmediatamente e igual que el anterior)
             
            sSQL = "SELECT dOperFech,nTarjNumb,nMoneda,nMontoSoles,nMontoDolares,nEfectivoSoles,sGlosa FROM OPERACIONPARALELA WHERE cOperCode=" & iCodOper - 1 & ""
            
            If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
            
            If Format(ADORS!dOperFech, "DD/MM/YYYY hh:mm") = sFecha And ADORS!nTarjNumb = sTarjeta And ADORS!nMoneda = CStr(mon) And _
                ADORS!nMontoSoles = iTotal And ADORS!nMontoDolares = iMontoDolares And _
                 ADORS!nEfectivoSoles = iEfectivo And ADORS!sGlosa = txtGlosa Then
                
                
                sSQL = "UPDATE Config_Documento " & _
                      " SET cOperCode=" & CStr(iCodOper - 1) & "," & _
                      " nDocCodigo=" & cDocCodigofull - 1 & ", " & _
                      " cUserDesc='" & psUsuario_Descripcion & "' " & _
                      " WHERE cTipodoc='" & cdocTipo & "'"
                If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
                
                GoTo Salir
                
            Else
      
                    sSQL = " INSERT INTO OPERACIONPARALELA (cOperCode, cOperTipo, dOperFech, nTarjNumb," & _
                           " nMoneda, nMontoSoles, nMontoDolares, nEfectivoSoles, nVueltoSoles, sGlosa," & _
                           " cEstado, cCajaCodi, cFlagSincronizacion, cTurnoCodi, cUserDesc, cOpercodeRela, " & _
                           " nEfectivoDolares, nVueltoDolares, cDocSerie, cDocCodigo, cDocTipo ) " & _
                           " VALUES" + _
                           " ($, $, '$', '$', $, $, $, $, $, '$', '$', '$', '$', '$', '$', $ ,$ ,$,'$',$,'$')"
                    sSQL = VBsprintf(sSQL, CStr(iCodOper), CStr(iTipoVenta), sFecha, sTarjeta, CStr(mon), CStr(iTotal), _
                                           CStr(iMontoDolares), CStr(iEfectivo), CStr(iVuelto), txtGlosa, CStr(1), _
                                           kPAR_CAJA, CStr(0), kPAR_TURNO, psUsuario_Descripcion, CStr(iCodOperRela), _
                                           CStr(iDolaresEfectivo), CStr(iVueltoDolares), KSERIE_PARALELO, cDocCodigofull, cdocTipo)
                    If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
                    
            End If
        
     Else
            sSQL = " INSERT INTO OPERACIONPARALELA (cOperCode, cOperTipo, dOperFech, nTarjNumb," & _
                   " nMoneda, nMontoSoles, nMontoDolares, nEfectivoSoles, nVueltoSoles, sGlosa," & _
                   " cEstado, cCajaCodi, cFlagSincronizacion, cTurnoCodi, cUserDesc, cOpercodeRela, " & _
                   " nEfectivoDolares, nVueltoDolares, cDocSerie, cDocCodigo, cDocTipo ) " & _
                   " VALUES" + _
                   " ($, $, '$', '$', $, $, $, $, $, '$', '$', '$', '$', '$', '$', $ ,$ ,$,'$',$,'$')"
            sSQL = VBsprintf(sSQL, CStr(iCodOper), CStr(iTipoVenta), sFecha, sTarjeta, CStr(mon), CStr(iTotal), _
                                   CStr(iMontoDolares), CStr(iEfectivo), CStr(iVuelto), txtGlosa, CStr(1), _
                                   kPAR_CAJA, CStr(0), kPAR_TURNO, psUsuario_Descripcion, CStr(iCodOperRela), _
                                   CStr(iDolaresEfectivo), CStr(iVueltoDolares), KSERIE_PARALELO, cDocCodigofull, cdocTipo)
            If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
      End If
               
               
'      sSql = " INSERT INTO OPERACIONPARALELA (cOperCode, cOperTipo, dOperFech, nTarjNumb," & _
'             " nMoneda, nMontoSoles, nMontoDolares, nEfectivoSoles, nVueltoSoles, sGlosa," & _
'             " cEstado, cCajaCodi, cFlagSincronizacion, cTurnoCodi, cUserDesc, cOpercodeRela, " & _
'             " nEfectivoDolares, nVueltoDolares, cDocSerie, cDocCodigo, cDocTipo ) " & _
'             " VALUES" + _
'             " ($, $, '$', '$', $, $, $, $, $, '$', '$', '$', '$', '$', '$', $ ,$ ,$,'$',$,'$')"
'      sSql = VBsprintf(sSql, CStr(iCodOper), CStr(iTipoVenta), sFecha, sTarjeta, CStr(mon), CStr(iTotal), _
'                             CStr(iMontoDolares), CStr(iEfectivo), CStr(iVuelto), txtGlosa, CStr(1), _
'                             kPAR_CAJA, CStr(0), kPAR_TURNO, psUsuario_Descripcion, CStr(iCodOperRela), _
'                             CStr(iDolaresEfectivo), CStr(iVueltoDolares), KSERIE_PARALELO, cDocCodigofull, cdocTipo)
'      If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSql) Then GoTo Salir
      
      
      nImporte = 0
      nPtosImp = 0
      nPuntos = 0
      
'      For i = 0 To gfax.UpperBound(1)
      For i = 0 To nProducto
        'TDBGrid1.Row = i
        sSQL = " INSERT INTO OPERACIONPARALELAPRODUCTO (cAlmaCode, cOperCode, cProdCode, nProdCant," & _
               " nProdPrecUnit, nDscto, nServicio)" & _
               " VALUES" + _
               " ('$', $, $, $, $, $,$)"
        sSQL = VBsprintf(sSQL, kPAR_ALMACEN, CStr(iCodOper), CStr(Producto(i).Codigo), CStr(Abs(val(Replace(gfax(i, 6), ",", "")))), _
                         CStr(val(Replace(gfax(i, 7), ",", ""))), CStr(Producto(i).Dscto), IIf(gfax(i, 13) = "SI", kPAR_PORCSERV, "0"))
        If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
        
  
        'CONTABILIZA PUNTOS
        '------------------
'        nImporte = nImporte + _
'                   Producto(i).Cant * val(TDBGrid1.Columns(7).Text) * (100 - Producto(i).Dscto) * _
'                   IIf(Producto(i).Canje = "VNTA", 1, 0) / 100
'        nPtosImp = nPtosImp + _
'                   Producto(i).Cant * Producto(i).PUnit * (100 - Producto(i).Dscto) * _
'                   IIf(Producto(i).Canje = "PTOS", 1, 0) / 100
'        nPuntos = nPuntos + IIf(Producto(i).Canje = "PTOS", 1, 0) * Producto(i).Ptos * Producto(i).Cant
      Next
      Dim CodLiq As Long
      If iTipoVenta = 1 Or _
         iTipoVenta = 20 And (iDolaresEfectivo > 0 Or iSolesEfectivo > 0) Or _
         iTipoVenta = 5 And (iDolaresEfectivo > 0 Or iSolesEfectivo > 0) Or _
         iTipoVenta = 24 And (iDolaresEfectivo > 0 Or iSolesEfectivo > 0) Then
         Dim iCodTipo As Long
         If iTipoVenta = 24 Then
         txtLiq.Text = iCodOper
         End If
         
         If bLiquidaNC = False Then
            If piEmitevoucher = 1 And iEfectivo = 0 Then
              iCodTipo = 2
            Else
              iCodTipo = 1
            End If
            CodLiq = 0
            
         Else
            iCodTipo = 3
            CodLiq = val(txtLiq.Text)
         End If
        '---primera
           If iDolaresEfectivo <= 0 And iEfectivo <= 0 Then iEfectivo = Replace(txtSoles, ",", "")
           
           sSQL = " INSERT INTO OPERACION (cOperCode, cUserDesc, nTarjNumb, cProdCode, nProdCant, nProdPrecUnit," & _
               " nMontoDolares, dOperFech, cOperTipo, cCajaCodi, cTurnoCodi, nmontosoles, nVueltoDolares,  cDocSerie, cDoccodigo, cdocTipo, cOpercodeAnula, IdLocal) " + _
               " VALUES" + _
               " ($, '$', '$', $, $, $, $, '$', $, '$', '$',$ ,$, '$', $, '$', $, $)"
           sSQL = VBsprintf(sSQL, CStr(iCodOper), psUsuario_Descripcion, sTarjeta, CStr(0), CStr(1), _
                           CStr(-1 * iVuelto), CStr(iDolaresEfectivo), sFecha, CStr(iCodTipo), kPAR_CAJA, kPAR_TURNO, CStr(iEfectivo), CStr(iVueltoDolares), cDocSerie, cDocCodigofull, cdocTipo, CodLiq, idLocal)

        If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
        iVuelto = val(Replace(txtVueltoSoles, ",", ""))
        If iVuelto < 0 Then iVuelto = 0
      End If
      
      
      nImporte = CDbl(Me.txtSoles.Text)
      nPuntos = 0
      '--------------------------Inserta linea voucher liq------------------------------------
      Dim importevoucher As Double
      
      If piEmitevoucher = 1 Then
         importevoucher = nImporte - iEfectivo + iVuelto
         sSQL = " INSERT INTO OPERACION (cOperCode, cUserDesc, nTarjNumb, cProdCode, nProdCant, nProdPrecUnit," & _
               " nMontoDolares, dOperFech, cOperTipo, cCajaCodi, cTurnoCodi, nmontosoles, nVueltoDolares,  cDocSerie, cDoccodigo, cdocTipo, cOpercodeAnula, cemisor, IdLocal) " + _
               " VALUES" + _
               " ($, '$', '$', $, $, $, $, '$', $, '$', '$',$ ,$, '$', $, '$', $, '$', $)"
         sSQL = VBsprintf(sSQL, CStr(iCodOper), psUsuario_Descripcion, sTarjeta, CStr(0), CStr(1), _
                           0, 0, sFecha, 2, kPAR_CAJA, kPAR_TURNO, CStr(importevoucher), 0, cDocSerie, cDocCodigofull, cdocTipo, CodLiq, cEmisor, idLocal)
         If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
                          
      End If
      
      '-----------------------------------------------------------------------------
       
      'ACTUALIZA PUNTOS
      '----------------
      If nImporte > 0 And sTarjeta <> "" Then
        Call Guarda_Puntos(sTarjeta, "VNTA", cdocTipo, cDocSerie, cDocCodigofull, nImporte, , nIdClienteLocal)
        iPuntos = Int(nImporte / lReglaPuntoImporte) * lReglaPuntoCantidad
      End If
      If nPuntos > 0 And sTarjeta <> "" Then
        Call Guarda_Puntos(sTarjeta, "PTOS", cdocTipo, cDocSerie, cDocCodigofull, nPuntos, nPtosImp, nIdClienteLocal)
      End If
      '----------------
      
      If iTipoVenta = 24 Then
        sSQL = " UPDATE OPERACIONPARALELA" & _
               " SET cEstado = 2" + _
               " WHERE cOperCode = $"
        sSQL = VBsprintf(sSQL, CStr(iCodOper))
        If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
                
        For i = 1 To lvwTX(0).ListItems.Count
          iCodOperRela = val(lvwTX(0).ListItems(i).Text)
          sSQL = " UPDATE OPERACIONPARALELA" & _
                 " SET cOpercodeRela = $," & _
                 " cEstado = 2" + _
                 " WHERE cOperCode = $"
                 
                 
          'sSQL = VBsprintf(sSQL, CStr(iCodOper), CStr(iCodOperRela))
          sSQL = VBsprintf(sSQL, CStr(iCodOperRela), CStr(iCodOper))
          If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
        Next
        
        For i = 1 To lvwTX(1).ListItems.Count
          iCodOperRela = val(lvwTX(1).ListItems(i).Text)
'          sSQL = " UPDATE OPERACIONPARALELA" & _
'                 " SET cOpercodeRela = $," & _
'                 " cEstado = 2" + _
'                 " WHERE cOperCode = $"
'          sSQL = VBsprintf(sSQL, CStr(iCodOper), CStr(iCodOperRela))
          
          sSQL = " UPDATE OPERACIONPARALELA" & _
                 " SET " & _
                 " cEstado = 2" + _
                 " WHERE cOperCode = $"
          sSQL = VBsprintf(sSQL, CStr(iCodOperRela))
          
          If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
        Next
      End If
  
      
    Case Else
      
      nImporte = 0
      nPtosImp = 0
      nPuntos = 0
      If rsPagTar.state = adStateOpen Then
      If rsPagTar.RecordCount > 0 Then
        rsPagTar.MoveFirst
        Do While Not rsPagTar.EOF
            cEmisor = cEmisor + "," + rsPagTar.Fields("cod_tar")
            rsPagTar.MoveNext
        Loop
      End If
      End If
      
  '------------------Validacion de Numeración Correlativa -------------------------//
  sSQL = "SELECT MAX(cDocCodigo) AS maximo FROM Operacion WHERE cDocTipo = '" & cdocTipo & "'"
         If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
         
  If cDocCodigofull <> ((ADORS!Maximo) + 1) And val("0" & ADORS!Maximo) > 0 Then
    Set fso = CreateObject("Scripting.FileSystemObject")
    archivo = "Error_Full2" & cdocTipo & cDocCodigofull
    If Trim(archivo) = "" Then
        archivo = "textfile"
    End If
    Texto = Texto + "Codigo generado " & cDocCodigofull & Chr(13)
    
    NameArchivo = "C:\Temp\" + Trim(archivo) + ".log"
    Set MyFile = fso.CreateTextFile(NameArchivo, True)
    cDocCodigofull = ("0" & (ADORS!Maximo)) + 1
    Texto = Texto + "Nuevo Codigo " & cDocCodigofull & Chr(13)
    Texto = Texto + CStr(Now)
    MyFile.WriteLine (Texto)
    MsgBox "Ocurrio un error en la numeración, se asignará el " & cDocCodigofull & " al documento "
  End If
  
  '---------------Actualizando el valor de la numeración --------------------------------//
  sSQL = "UPDATE Config_Documento " & _
        " SET cOperCode=" & CStr(iCodOper) & "," & _
        " cUserDesc='" & psUsuario_Descripcion & "' " & _
        " WHERE cTipodoc='" & cdocTipo & "'"
  If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
  
  '------------------fin Validacion de Numeración Correlativa ---------------------------//
          
      For i = 0 To gfax.UpperBound(1)
         'TDBGrid1.Row = i
         If bLiquidaNC Then iFlagTipo = 3
         
         If iFlagTipo = 3 Then
            CodLiq = val(txtLiq.Text)
         Else
            CodLiq = 0
         End If
         sSQL = " INSERT INTO OPERACION (cOperCode, cUserDesc, nTarjNumb, cAlmaCode, cProdCode, nProdCant, nProdPrecUnit," & _
                " nMontoDolares, dOperFech, cOperTipo, cCajaCodi, cTurnoCodi, nDscto, nServicio, cDocCodigo, cRuc, cDocSerie, cDocTipo, cEmisor, cOpercodeanula, idLocal) " + _
                " VALUES" + _
                " ($, '$', '$', '$', $, $, $, $, '$', $, '$', '$', $, $, $, '$', '$', '$', '$', $, $)"
         
         sSQL = VBsprintf(sSQL, CStr(iCodOper), psUsuario_Descripcion, sTarjeta, kPAR_ALMACEN, CStr(Producto(i).Codigo), CStr(val(Replace(gfax(i, 6), ",", "") * iSigno)), _
                CStr(val(Replace(gfax(i, 7), ",", ""))), CStr(0), sFecha, CStr(iFlagTipo), kPAR_CAJA, kPAR_TURNO, CStr(Producto(i).Dscto), IIf(gfax(i, 13) = "SI", kPAR_PORCSERV, "0"), cDocCodigofull, cRuc, cDocSerie, cdocTipo, cEmisor, CodLiq, idLocal)
               
         If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
         iEfectivo = val(Replace(txtEfectivoSoles, ",", ""))
         iVuelto = val(Replace(txtVueltoSoles, ",", ""))
         If iVuelto < 0 Then iVuelto = 0
    
      Next
       
      nImporte = CDbl(Me.txtSoles.Text)
      nPuntos = 0
         
      iVuelto = val(Replace(txtVueltoSoles, ",", ""))
      iDolaresEfectivo = val(Replace(txtEfectivoDolares, ",", ""))
      iSolesEfectivo = val(Replace(txtEfectivoSoles, ",", ""))
      iVueltoDolares = val(Replace(Me.txtVueltoDolares, ",", ""))
      If iVuelto < 0 Then iVuelto = 0
      If iVueltoDolares < 0 Then iVueltoDolares = 0
      'ACTUALIZA PUNTOS
      '----------------
      If Not blLiquidaVenta Then
        If nImporte > 0 And sTarjeta <> "" Then
          Call Guarda_Puntos(sTarjeta, "VNTA", cdocTipo, cDocSerie, cDocCodigofull, nImporte, , nIdClienteLocal)
          iPuntos = Int(nImporte / lReglaPuntoImporte) * lReglaPuntoCantidad
        End If
        If nPuntos > 0 And sTarjeta <> "" Then
          Call Guarda_Puntos(sTarjeta, "PTOS", cdocTipo, cDocSerie, cDocCodigofull, nPuntos, nPtosImp, nIdClienteLocal)
        End If
    
      End If
      '---------------
      
      If iTipoVenta = 1 And (iDolaresEfectivo > 0 Or iSolesEfectivo > 0) Or _
         iTipoVenta = 20 And (iDolaresEfectivo > 0 Or iSolesEfectivo > 0) Or _
         iTipoVenta = 5 And (iDolaresEfectivo > 0 Or iSolesEfectivo > 0) Or _
         iTipoVenta = 3 And (iDolaresEfectivo > 0 Or iSolesEfectivo > 0) Or _
         iTipoVenta = 24 And (iDolaresEfectivo > 0 Or iSolesEfectivo > 0) Or _
         (iTipoVenta = 2 And (iDolaresEfectivo > 0 Or iSolesEfectivo > 0)) Then
        '-----segunda
         If bLiquidaNC = False Then
            iCodTipo = 1
            CodLiq = 0
         Else
            iCodTipo = 3
            CodLiq = val(txtLiq.Text)
         End If
        
            sSQL = " INSERT INTO OPERACION (cOperCode, cUserDesc, nTarjNumb, cProdCode, nProdCant, nProdPrecUnit," & _
                   " nMontoDolares, dOperFech, cOperTipo, cCajaCodi, cTurnoCodi,nmontosoles, nVueltoDolares, cDocCodigo, cRuc, cDocSerie, cDocTipo,cEmisor, cOpercodeAnula, IdLocal) " + _
                   " VALUES" + _
                   " ($, '$', '$', $, $, $, $, '$', $, '$', '$',$ ,$, $, '$', '$', '$', '$', $, $)"
            sSQL = VBsprintf(sSQL, CStr(iCodOper), psUsuario_Descripcion, sTarjeta, CStr(0), CStr(1), _
                               CStr(-1 * iVuelto), CStr(iDolaresEfectivo), sFecha, CStr(iCodTipo), kPAR_CAJA, kPAR_TURNO, CStr(iSolesEfectivo), CStr(iVueltoDolares), CStr(cDocCodigofull), cRuc, cDocSerie, cdocTipo, cEmisor, CodLiq, idLocal)
'        Else
'             ssql = " INSERT INTO OPERACION (cOperCode, cUserDesc, nTarjNumb, cProdCode, nProdCant, nProdPrecUnit," & _
'               " nMontoDolares, dOperFech, cOperTipo, cCajaCodi, cTurnoCodi, nmontosoles, nVueltoDolares,  cDocSerie, cDoccodigo, cdocTipo) " + _
'               " VALUES" + _
'               " ($, '$', '$', $, $, $, $, '$', $, '$', '$',$ ,$, '$', $, '$')"
'            ssql = VBsprintf(ssql, CStr(iCodOper), psUsuario_Descripcion, sTarjeta, CStr(0), CStr(1), _
'                           CStr(0), CStr(0), sFecha, CStr(iCodTipo), kPAR_CAJA, kPAR_TURNO, CStr(-1 * (Replace(txtSoles.Text, ",", ""))), CStr(0), cDocSerie, cDocCodigofull, cdocTipo)
            
       ' End If
    
     If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
        'iEfectivo = Val(Replace(txtEfectivoDolares, ",", ""))
        iVuelto = val(Replace(txtVueltoSoles, ",", ""))
        If iVuelto < 0 Then iVuelto = 0
    End If
            
  End Select
    
  ''actualizar en el SQL el campo bLiquidado a 1
  
  sSQL = "UPDATE Venta01 SET bLiquidado=1 WHERE cCodVta=" & txtTXL(0)
  
  If Not oDBAdmin.EjecutarSentencia(cnSQL, sSQL) Then GoTo Salir
  
    ADOCnn.CommitTrans
    cnSQL.CommitTrans
  
  
  
  bLiquidaNC = False
  '-------------------Fin Graba operacion -------------------------
  
  '----------------------
  '-- Blanquea la Caja --
  '----------------------
  bProducto = False
  iTotalVenta = 0
  'cmdTecla_Click (0)
  
  'SINCRONIZAR
  'Sincronizar
  
  'Inicializa variables y controles
  gfax.Clear
  'gfax.ReDim 0, 0, 0, 14
  gfax.ReDim 0, 0, 0, 15
  'TDBGrid1.ReBind
  'TDBGrid1.MoveFirst
  'TDBGrid1.Update
  'cmdTecla_Click (0)
    
  'inicio
  txtTarjeta.SetFocus
  If blLiquidaVenta Then
     'Call LiquidaNC(iCodOper)
  End If
  
 LimpiarLiquidacion
 
 
  Set cnSQL = Nothing
Exit Sub
Salir:
MsgBox Err.Description
ADOCnn.RollbackTrans
cnSQL.RollbackTrans
Set cnSQL = Nothing

Set ADORS = Nothing
  If piEmitevoucher <> 1 Then
    Set rsPagTar = Nothing
  End If


End Sub
Private Sub RegistrarConsumo()

  'GoTo prueba
  On Error GoTo LineaError
  
  Dim sSQL As String
  Dim ADORS As ADODB.Recordset
  Dim i As Long, j As Long, iCodOper As Long, iCodOperRela As Long
  Dim iTotal, iTotalVenta As Double, iSubTotal As Double, iSubTotalDscto As Double
  Dim iTotalDscto As Double, iTotItems As Double
  Dim sFecha As String
  Dim sTexto As String
  Dim iSigno As Integer
  Dim iFlagTipo As Integer
  Dim sTarjeta As String
  Dim ivuelto_1 As Double
  Dim iMontoDolares As Double
  Dim iMontoSoles As Double
  Dim iDolaresEfectivo As Double
  Dim iSolesEfectivo As Double
  Dim rs1 As Recordset
  Dim p_1 As Integer
  Dim impr_1 As String
  Dim impr_2 As String
  Dim nImporte As Double, iServicio, nPuntos As Double, nPtosImp As Double
  Dim iPtoVta, iPtoItm As Double, iPagoAdelantado As Double
  Dim blLiquidaVenta As Boolean
  Dim Texto_imprimir As String
  Dim iPuntos As Long
  Dim sssql As String
  Dim blnfactura As Boolean
  Dim intPuntosAcumulados As Long
  Dim x As printer
  
  Dim cEmisor As String
  Dim cDocCodigofull As Long
  Dim cDocSerie As String
  Dim cdocTipo As String
  Dim cRuc As String
  Dim IGV_1 As Double
  blLiquidaVenta = False
  blnfactura = False
  Dim KSERIE_PARALELO As String
  
  'sw To SQL Server add
  Dim idLocal As String
  
  
    iTipoVenta = 5 ''NC
  
  
  TDGNotaConsumo.Update
  If piEmitevoucher <> 1 Then
    'CalculaTotales
    'CalculoVuelto
  End If
  cDocCodigofull = 0
  p_1 = 0
  
  ConectarBDCliente
  'Verifica si es Factura
  If Not Trim(Me.txtRUC.Text) = "" Then
    blnfactura = True
    cRuc = Trim(Me.txtRUC.Text)
    cdocTipo = "01"
    cDocSerie = kSERIE_FACTURA
  Else
    cRuc = ""
    cdocTipo = "02"
    cDocSerie = kSERIE
  End If
  
  '--------------------
  '-- Registra Venta --
  '--------------------

    'SE OBTIENE FECHA DEL SISTEMA DE LA BASE DE DATOS DE SQL - version 2.0.5
   
   Dim cnFECHASQL As ADODB.Connection
   Dim sqlFECHASIS As String
   Dim rsFEchaSis As ADODB.Recordset
      
   If oDBAdmin.AbrirBD(cnFECHASQL, psConnectString, False) = True Then
     
     sqlFECHASIS = "select convert(varchar,getdate(),120) as fechasis"
     If oDBAdmin.EjecutarConsulta(cnFECHASQL, sqlFECHASIS, rsFEchaSis) = True Then
         
         If rsFEchaSis!fechasis <> "" Then
             sFecha = rsFEchaSis!fechasis
         End If

     Else
         'no pudo abrir el rs: que consulte al access
         'MsgBox "No se pudo obtener la fecha, hay problemas de conexión de la red con la Base de Datos Principal", vbOKOnly + vbExclamation, "Aviso"
         sFecha = Format(Now(), "DD/MM/YYYY hh:mm")
         'Unload Me
     End If

     Set cnFECHASQL = Nothing

   Else
     'no pudo conectarse al sql: que consulte al access
      'MsgBox "No se pudo obtener la fecha, hay problemas de conexión de la red con la Base de Datos Principal", vbOKOnly + vbExclamation, "Aviso"
      sFecha = Format(Now(), "DD/MM/YYYY hh:mm")
      'Unload Me
   End If
   
   'FIN FECHA DEL SISTEMA DE LA BASE DE DATOS DE SQL



  'sFecha = Format(Now(), "DD/MM/YYYY hh:mm")
  Set ADORS = Nothing
  
  iFlagTipo = iTipoVenta
  If iTipoVenta = 4 Then
    iSigno = -1
    iFlagTipo = 1
  Else
    iSigno = 1
    iFlagTipo = iTipoVenta
  End If
  If iTipoVenta = 5 Then
    iFlagTipo = 1
  End If
  
  iCodOperRela = 0
  
  'vd 05/08/07 TDGNotaConsumo.Update
      
  'Verifica si es un tipo de operaciòn que necesita password: Anulación o Descuento
  For i = gfax2.LowerBound(1) To gfax2.UpperBound(1)
    sTexto = IIf(Replace(gfax2(i, 9), ",", "") = "", "0", Replace(gfax2(i, 9), ",", ""))
    If val(sTexto) <> 0 Then
      bAcceso = True
      Exit For
    End If
  Next
  
  If bAcceso Then
    bAcceso = False
    Load frmAutorizarOperacion
    Set frmAutorizarOperacion.frmPadre = Me
    frmAutorizarOperacion.Show vbModal
    If Not bAcceso Then Exit Sub
    'bAcceso = False
  End If
  '--------Abre la gaveta de dinero automaticamente al aceptar la venta ----
  Dim opc_gaveta As String
  opc_gaveta = LeerCfg("PARAMETROS", "GAVETA", psArchivoCfg)
  If Trim(UCase(opc_gaveta)) = "S" Then
    Abre_Gaveta_Dinero (LeerCfg("PARAMETROS", "PRINTER", psArchivoCfg))
  End If
  '-------------------------------------------------------------------------
  If iTipoVenta = 6 Or iTipoVenta = 7 Then
    If Not IsNumeric(Replace(IIf(txtPagoAdelantado = "", "0.00", txtPagoAdelantado), ",", "")) Then Exit Sub
    If Not IsNumeric(Replace(IIf(txtPADEDolares = "", "0.00", txtPADEDolares), ",", "")) Then Exit Sub
    If val(Replace(IIf(txtPagoAdelantado = "", "0.00", txtPagoAdelantado), ",", "")) = 0 And _
       val(Replace(IIf(txtPADEDolares = "", "0.00", txtPADEDolares), ",", "")) = 0 Then
      MsgBox "Debe registar una cantidad mayor que cero."
      txtPagoAdelantado.SetFocus
      Exit Sub
    End If
  End If
 
  'Calculo de vueltos
  Dim iVueltoSoles As Double
  
  If iTipoVenta = 1 Or iTipoVenta = 4 Then   'Or iTipoVenta = 8
    If Trim(Me.txtEfectivoDolares.Text) = "" Then Me.txtEfectivoDolares.Text = "0.00"
    If Trim(Me.txtEfectivoSoles.Text) = "" Then Me.txtEfectivoSoles.Text = "0.00"
    
    If val(Replace(Me.txtEfectivoDolares.Text, ",", "")) = 0 And _
      val(Replace(Me.txtEfectivoSoles.Text, ",", "")) = 0 Then
      Me.txtEfectivoSoles.Text = Me.txtSoles
    End If
  End If

  'Configura la Impresora por default
  'sw 1 = Efectivo
  'sw 2 = VOUCHER
  'sw 3 = O/C
  'sw 4 = N/C
  'sw 5 = PADE
  'sw 6 = PADV
  'sw 7 = LIQPAD
  'sw 8 = ANULAR TRANSACCION
  'sw 9 = RECAUDACION
  
  Select Case iTipoVenta
    Case 4, 5, 6, 7, 8
      If iTipoVenta = 4 Then iTipoVenta = 20 ' O/C
      If iTipoVenta = 5 Then iTipoVenta = 21 ' N/C
      If iTipoVenta = 6 Then iTipoVenta = 22 ' PADE
      If iTipoVenta = 7 Then iTipoVenta = 23 ' PADV
      If iTipoVenta = 8 Then iTipoVenta = 24 ' LIQPAD
      ConfiguraImpresora kPAR_IMPRESORA_ALTERNA
    Case Else
      ConfiguraImpresora kPAR_IMPRESORA
  End Select
  
  Select Case iTipoVenta
    Case 20, 21, 22, 23, 24
      sSQL = "SELECT MAX(cOperCode) AS maximo FROM OperacionParalela"
    Case Else
      sSQL = "SELECT MAX(cOperCode) AS maximo FROM Operacion"
  End Select
  
  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
      'EscribirCfg "PARAMETROS", "cOpeB", psArchivoCfg, Str(iCodOper + 1)
    End If
  End If
  
  'Inicializa Recorset
  If iTipoVenta <> 2 And piEmitevoucher <> 1 Then
    Set rsPagTar = New Recordset
  End If

  If iCodOper = 1 Then
'    kOPERACION = LeerCfg("PARAMETROS", "cOpeB", psArchivoCfg)
'    iCodOper = Val(kOPERACION)
  End If
  
  'Si hay vuelto se convierte en iTipo = 5
  If iTipoVenta = 1 And (val(Replace(txtVueltoSoles, ",", "")) <> 0 Or val(Replace(txtVueltoDolares, ",", "")) <> 0) Then
    iTipoVenta = 5
  End If
  
  'Asigna valor para liquidar NC
  If iTipoVenta = 24 Then blLiquidaVenta = True
    
  'Registra los datos del producto
  If iTipoVenta = 22 Or iTipoVenta = 23 Or iTipoVenta = 24 Then
    nProducto2 = -1
  Else
    ReDim Producto2(gfax2.UpperBound(1))
    
    For i = gfax2.LowerBound(1) To gfax2.UpperBound(1)
      Producto2(i).Almacen = kPAR_ALMACEN
      Producto2(i).Cant = Replace(gfax2(i, 6), ",", "")
      Producto2(i).PUnit = Replace(gfax2(i, 7), ",", "")
      Producto2(i).Codigo = gfax2(i, 1)
      Producto2(i).nombre = gfax2(i, 3)
      If gfax2(i, 8) = "+" Then
        Producto2(i).Dscto = Replace(IIf(gfax2(i, 9) = "", 0, gfax2(i, 9)), ",", "")
      Else
        Producto2(i).Dscto = -1 * Replace(IIf(gfax2(i, 9) = "", 0, gfax2(i, 9)), ",", "")
      End If
      
      Producto2(i).Canje = gfax2(i, 11)
      Producto2(i).Ptos = val(Replace(gfax2(i, 12), ",", ""))
      Producto2(i).Serv = gfax2(i, 13)
    Next
    nProducto2 = gfax2.UpperBound(1)
  End If
  
  
    
  If Trim(NC_cClienteCode) <> "" Then
    sTarjeta = Right("00000000" + Trim(NC_cClienteCode), 8)
  Else
    sTarjeta = ""
  End If
  
  'sw To SQL Server add
  idLocal = IIf(Trim(NC_IdLocal) = "", "NULL", Trim(NC_IdLocal))
  
  'Calcula el total de las ventas
  iTotalVenta = Replace(txtSolesNC, ",", "")
  'lblTotal.Caption = "TOT:" + Right("               " + Format(CStr(iTotalVenta), "0.00"), 14)
  
  'Captura Serie y Codigo del Documento
  
  Select Case iTipoVenta
    Case 20
      cdocTipo = "10"
    Case 21
      cdocTipo = "11"
   Case 22
      cdocTipo = "12"
   Case 23
      cdocTipo = "13"
   Case 24
      cdocTipo = "14"
  End Select
  

  
  Dim dbCalculado As Boolean
  Dim ddtotefectivo, ddtotvuelto As Double
  Dim mon As Integer
  Dim ierroritm As Integer
  ierroritm = 0
  dbCalculado = False
  
  Do While dbCalculado = False And ierroritm < 3
    Select Case iTipoVenta
      Case 20, 21, 22, 23, 24
        If iTipoVenta = 22 Or iTipoVenta = 23 Then 'PADE o PADV
          iDolaresEfectivo = val(Replace(txtPADEDolares, ",", ""))
          iEfectivo = val(Replace(txtPagoAdelantado, ",", ""))
          If iEfectivo > 0 Then
            mon = 1
          End If
          If iDolaresEfectivo > 0 Then
            mon = 2
          End If
          If mon = 1 Then 'Soles
            iTotal = val(Replace(txtPagoAdelantado, ",", ""))
            iMontoDolares = CDbl(Format(CStr(iTotal / nTipoCambio), "0.00"))
            'iMontoDolares = CDbl(Format(CStr(iTotal / nTipoCambio), "0.00"))
          End If
          If mon = 2 Then 'Dolares
            iMontoDolares = val(Replace(txtPADEDolares, ",", ""))
            iTotal = CDbl(Format(CStr(iMontoDolares * nTipoCambio), "0.00"))
            'iTotal = CDbl(Format(CStr(iMontoDolares * nTipoCambio), "0.00"))
          End If
          
          iSolesEfectivo = iEfectivo
          iVuelto = 0
          iVueltoDolares = 0
        Else
          
          iTotal = val(Replace(txtSolesNC, ",", ""))
          iMontoDolares = val(Replace(txtDolaresNC, ",", ""))
          If piEmitevoucher = 1 And blLiquidaVenta = True Then
            iDolaresEfectivo = val(Replace(txtliqefectivodolares, ",", ""))
            iSolesEfectivo = val(Replace(txtliqefectivosoles, ",", ""))
            iEfectivo = val(Replace(txtliqefectivosoles, ",", ""))
            iVuelto = val(Replace(txtliqvueltosoles, ",", ""))
            iVueltoDolares = val(Replace(ttxliqvueltodolares, ",", ""))
          Else
            iDolaresEfectivo = val(Replace(txtEfectivoDolares, ",", ""))
            iSolesEfectivo = val(Replace(txtEfectivoSoles, ",", ""))
            iEfectivo = val(Replace(txtEfectivoSoles, ",", ""))
            iVuelto = val(Replace(txtVueltoSoles, ",", ""))
            iVueltoDolares = val(Replace(txtVueltoDolares, ",", ""))
          End If
          If iVuelto < 0 Then iVuelto = 0
          If iDolaresEfectivo < 0 Then iDolaresEfectivo = 0
          If iVueltoDolares < 0 Then iVueltoDolares = 0
          If iTipoVenta = 21 Then iCodOperRela = val(NC_cCodVta) 'val(txtTX.Text)
          If iTipoVenta = 20 And Trim(txtLiq.Text) <> "" Then iCodOperRela = val(txtLiq.Text)
        End If
      Case Else
        iVuelto = val(Replace(txtVueltoSoles, ",", ""))
        iTotal = val(Replace(txtSoles, ",", ""))
        If iVuelto < 0 Then iVuelto = 0
        If piEmitevoucher = 1 And bLiquidaNC Then
          iEfectivo = val(Replace(txtliqefectivosoles, ",", ""))
          iDolaresEfectivo = val(Replace(txtliqefectivodolares, ",", ""))
          iVueltoDolares = val(Replace(ttxliqvueltodolares, ",", ""))
          iVuelto = val(Replace(Me.txtliqvueltosoles, ",", ""))
        Else
          iEfectivo = val(Replace(txtEfectivoSoles, ",", ""))
          iDolaresEfectivo = val(Replace(txtEfectivoDolares, ",", ""))
          iSolesEfectivo = val(Replace(txtEfectivoSoles, ",", ""))
          iVueltoDolares = val(Replace(txtVueltoDolares, ",", ""))
        End If
        If iVueltoDolares < 0 Then iVueltoDolares = 0
    End Select
    
    ddtotefectivo = Round(iSolesEfectivo + (iDolaresEfectivo * nTipoCambio), 2)
    ddtotvuelto = Round(iVuelto + (iVueltoDolares * nTipoCambio), 2)
    
    If (iTipoVenta <> 2 And iTipoVenta <> 22 And iTipoVenta <> 23 And iTipoVenta <> 21 And iTipoVenta <> 24) And (Round(ddtotefectivo - ddtotvuelto, 2) <> Round(iTotal, 2)) Then
      MsgBox "Ocurrio un error de Cálculo"
      dbCalculado = False
      ierroritm = ierroritm + 1
    Else
      dbCalculado = True
      ierroritm = 0
    End If
  Loop
  '------------------------
  '-- Captura Parámetros --
  '------------------------
  Texto_imprimir = ""
  Call CabeceraImpresion
  sTexto = ""
  
  sssql = "SELECT sImpresora, sImpresoraAlterna from Configuracion"
  If Not oDBAdmin.EjecutarConsulta(ADOCnn, sssql, rs1) Then GoTo Salir
  impr_1 = rs1.Fields("sImpresora")
  impr_2 = rs1.Fields("sImpresoraAlterna")
  
  'Pregunta si x.Devicename tiene el mismo nombre que el nombre de la impresora por donde necesitas sacar la impresion.
  If iTipoVenta = 1 Or iTipoVenta = 2 Or iTipoVenta = 5 Then
    p_1 = 1
  Else
    p_1 = 2
  End If
  
  printer.FontSize = 8 '11
  printer.FontName = "Courier New"
  
  Select Case iTipoVenta
    Case 20, 21, 22, 23, 24
    Case Else
      For i = 0 To UBound(sCabecera) - 1
        If Not Trim(sCabecera(i)) = "" Then
          sTexto = sTexto + Right(Space(60) + sCabecera(i), Int(Len(Space(40) + sCabecera(i)) / 2)) + vbCrLf
        End If
      Next
  End Select
  
  'Linea de Datos del Socio
  If Not sTarjeta = "" Then
    sTexto = sTexto + vbCrLf + " COD.TARJ.: " + sTarjeta + " "
    If Not blnfactura = True Then
      sTexto = sTexto + vbCrLf + " NOMBRE: " + NC_DscCliente + vbCrLf
    End If
  Else
    If Not blnfactura = True And Not Trim(txtNombres.Text) = "" Then
      sTexto = sTexto + vbCrLf + " NOMBRE: " + UCase(Trim(NC_DscCliente)) + vbCrLf
    End If
  End If
  
  If blnfactura = True Then
    sTexto = sTexto + vbCrLf + " NOMBRE: " & "____________________________"
    sTexto = sTexto + vbCrLf + vbCrLf + "         " & "____________________________" + vbCrLf
    sTexto = sTexto + vbCrLf + " RUC Cliente: " & Trim(Me.txtRUC.Text) + vbCrLf
  End If
  
  ' Obteniendo Nro de documento
  sSQL = "SELECT  * FROM Config_Documento WHERE cTipoDoc='" & cdocTipo & "'"
  If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
     
     

  If blnfactura = True Then
    If ADORS.EOF Then
      kSERIE_FACTURA = "F01"
      sSQL = "INSERT INTO Config_Documento (cTipoDoc,cOperCode,nDocCodigo,cSerieDoc,cUserDesc,dUltAct,observacion) " & _
             " VALUES ('01',0, 0, 'F01','',#" & Date & "#,'Primer Registro') "
      If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
      cDocCodigofull = 1
    Else
      kSERIE_FACTURA = LeerCampo(ADORS!cSerieDoc)
      cDocCodigofull = LeerCampo(ADORS!nDocCodigo) + 1
    End If
    cDocSerie = kSERIE_FACTURA
  Else
    Select Case cdocTipo
      Case "10"
        If ADORS.EOF Then
          KSERIE_PARALELO = "OC1"
          sSQL = "INSERT INTO Config_Documento (cTipoDoc,cOperCode,nDocCodigo,cSerieDoc,cUserDesc,dUltAct,observacion) " & _
                 " VALUES ('10',0, 0, 'OC1','',#" & Date & "#,'Primer Registro') "
          If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
          cDocCodigofull = 1
        Else
          KSERIE_PARALELO = LeerCampo(ADORS!cSerieDoc)
          cDocCodigofull = LeerCampo(ADORS!nDocCodigo) + 1
        End If
        cDocSerie = KSERIE_PARALELO
            
      Case "11"
        If ADORS.EOF Then
          KSERIE_PARALELO = "NC1"
          sSQL = "INSERT INTO Config_Documento (cTipoDoc,cOperCode,nDocCodigo,cSerieDoc,cUserDesc,dUltAct,observacion) " & _
                 " VALUES ('11',0, 0, 'NC1','',#" & Date & "#,'Primer Registro') "
          If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
          cDocCodigofull = 1
        Else
          KSERIE_PARALELO = LeerCampo(ADORS!cSerieDoc)
          cDocCodigofull = LeerCampo(ADORS!nDocCodigo) + 1
        End If
        cDocSerie = KSERIE_PARALELO
            
      Case "12"
        If ADORS.EOF Then
          KSERIE_PARALELO = "PA1"
          sSQL = "INSERT INTO Config_Documento (cTipoDoc,cOperCode,nDocCodigo,cSerieDoc,cUserDesc,dUltAct,observacion) " & _
                 " VALUES ('12',0, 0, 'PA1','',#" & Date & "#,'Primer Registro') "
          If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
          cDocCodigofull = 1
        Else
          KSERIE_PARALELO = LeerCampo(ADORS!cSerieDoc)
          cDocCodigofull = LeerCampo(ADORS!nDocCodigo) + 1
        End If
        cDocSerie = KSERIE_PARALELO
            
      Case "13"
        If ADORS.EOF Then
          KSERIE_PARALELO = "PV1"
          sSQL = "INSERT INTO Config_Documento (cTipoDoc,cOperCode,nDocCodigo,cSerieDoc,cUserDesc,dUltAct,observacion) " & _
                 " VALUES ('13',0, 0, 'PV1','',#" & Date & "#,'Primer Registro') "
          If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
          cDocCodigofull = 1
        Else
          KSERIE_PARALELO = LeerCampo(ADORS!cSerieDoc)
          cDocCodigofull = LeerCampo(ADORS!nDocCodigo) + 1
        End If
        cDocSerie = KSERIE_PARALELO
          
      Case "14"
        If ADORS.EOF Then
          KSERIE_PARALELO = "LQ1"
          sSQL = "INSERT INTO Config_Documento (cTipoDoc,cOperCode,nDocCodigo,cSerieDoc,cUserDesc,dUltAct,observacion) " & _
                 " VALUES ('14',0, 0, 'LQ1','',#" & Date & "#,'Primer Registro') "
          If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
          cDocCodigofull = 1
        Else
          KSERIE_PARALELO = LeerCampo(ADORS!cSerieDoc)
          cDocCodigofull = LeerCampo(ADORS!nDocCodigo) + 1
        End If
        cDocSerie = KSERIE_PARALELO
          
      Case Else
        If ADORS.EOF Then
          kSERIE = "B01"
          sSQL = "INSERT INTO Config_Documento (cTipoDoc,cOperCode,nDocCodigo,cSerieDoc,cUserDesc,dUltAct,observacion)" & _
                 " VALUES ('02',0, 0, 'B01', '', #" & Date & "#,'Primer Registro') "
          If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
          cDocCodigofull = 1
        Else
          kSERIE = LeerCampo(ADORS!cSerieDoc)
          cDocCodigofull = LeerCampo(ADORS!nDocCodigo) + 1
        End If
        cDocSerie = kSERIE
    End Select
  End If
  
  '------------------Validacion de Numeración Correlativa ----------------------------
  If cdocTipo = "01" Or cdocTipo = "02" Then
    sSQL = "SELECT MAX(cDocCodigo) AS maximo FROM Operacion WHERE cDocTipo = '" & cdocTipo & "'"
  Else
    sSQL = "SELECT MAX(cDocCodigo) AS maximo FROM OperacionParalela WHERE cDocTipo = '" & cdocTipo & "'"
  End If
  If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
  If val(cDocCodigofull) <> val("0" & (ADORS!Maximo) + 1) And val("0" & ADORS!Maximo) > 0 Then
    Dim NameArchivo As String
    Dim archivo
    Dim Texto As String
    Dim fso, MyFile
    Set fso = CreateObject("Scripting.FileSystemObject")
    archivo = "Error_Full_1" & cdocTipo & cDocCodigofull
    If Trim(archivo) = "" Then
      archivo = "textfile"
    End If
    Texto = Texto + "Codigo generado " & cDocCodigofull & Chr(13)
    
    NameArchivo = "C:\Temp\" + Trim(archivo) + ".log"
    Set MyFile = fso.CreateTextFile(NameArchivo, True)
    cDocCodigofull = ("0" & (ADORS!Maximo)) + 1
    Texto = Texto + "Nuevo Codigo " & cDocCodigofull & Chr(13)
    Texto = Texto + CStr(Now)
    MyFile.WriteLine (Texto)
    MsgBox "Ocurrio un error en la numeración, se asignará el " & cDocCodigofull & " al documento "
    MyFile.Close
  End If
  '---------------Actualizando el valor de la numeración ----------------
  sSQL = "UPDATE Config_Documento " & _
         " SET cSerieDoc='" & cDocSerie & "'," & _
         " nDocCodigo=" & cDocCodigofull & " " & _
         " WHERE cTipodoc='" & cdocTipo & "'"
  If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
  '------------------Impresión de Ticket----------------------------
  
  
  If blnfactura = True Then
    sTexto = sTexto + vbCrLf + " TK NRO: " & kSERIE_FACTURA & "-" & Right("000000" & CStr(cDocCodigofull), 6) & " NS:" & kSERIE_DISCO_DURO
  Else
    Select Case iTipoVenta
      Case 20, 22, 23, 24, 21
        sTexto = sTexto + vbCrLf + " TK NRO: " & KSERIE_PARALELO & "-" & Right("000000" & CStr(cDocCodigofull), 6) & " NS:" & kSERIE_DISCO_DURO1
      Case Else
        sTexto = sTexto + vbCrLf + " TK NRO: " & kSERIE & "-" & Right("000000" & CStr(cDocCodigofull), 6) & " NS:" & kSERIE_DISCO_DURO
    End Select
  End If
  
  'Printer.Print sTexto
  Texto_imprimir = Texto_imprimir + vbCrLf + sTexto
  sTexto = ""
  
  'Cabecera segun tipo de venta
  Select Case iTipoVenta
    Case 2 'Voucher
      sTexto = "VOUCHER"
      sTexto = Right(Space(60) + sTexto, Int(Len(Space(40) + sTexto) / 2)) + vbCrLf
    Case 1, 5 ' EFECTIVO EX Dolares
      If iDolaresEfectivo > 0 Then
        sTexto = "U$(TC: " + Format(CStr(nTipoCambio), "###,##0.00") + ")"
        sTexto = Right(Space(60) + sTexto, Int(Len(Space(40) + sTexto) / 2)) + vbCrLf
      End If
    Case 4 'Anula Productos
      sTexto = "ANULA PROD"
      sTexto = Right(Space(60) + sTexto, Int(Len(Space(40) + sTexto) / 2)) + vbCrLf
    Case 20 'O/C
      sTexto = "O/C"
      sTexto = Right(Space(60) + sTexto, Int(Len(Space(40) + sTexto) / 2)) + vbCrLf
    Case 21 'NC
      sTexto = "N/C"
      sTexto = Right(Space(60) + sTexto, Int(Len(Space(40) + sTexto) / 2)) + vbCrLf
    Case 22 'PADE
      sTexto = "PADE"
      sTexto = Right(Space(60) + sTexto, Int(Len(Space(40) + sTexto) / 2)) + vbCrLf
    Case 23 'PADV
      sTexto = "PADV"
      sTexto = Right(Space(60) + sTexto, Int(Len(Space(40) + sTexto) / 2)) + vbCrLf
    Case 24 'LIQ
      sTexto = "LIQPAD"
      sTexto = Right(Space(60) + sTexto, Int(Len(Space(40) + sTexto) / 2)) + vbCrLf
  End Select
  'Printer.Print sTexto
  Texto_imprimir = Texto_imprimir + vbCrLf + sTexto + vbCrLf
  sTexto = ""
  
  'Ancho de linea = 27
  
  iSubTotal = 0
  If iTipoVenta <> 22 And iTipoVenta <> 23 Then
    iTotal = 0
  End If
  iTotItems = 0
  iTotalDscto = 0
  iServicio = 0
  iPtoItm = 0
  iPtoVta = 0
    
    
  '<<<<<<<<<<<<<<<<<<<<<<<<<-------------------------------->>>>>>>>>>>>>>>>>>>>>>>>>>>>
  
  If iTipoVenta = 22 Or iTipoVenta = 23 Or iTipoVenta = 24 Then
    If iTipoVenta = 24 Then
      iTotal = val(Replace(txtPagoAdelantado, ",", ""))
    End If
    
    '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 sProdDesc As String
    Dim nDscto As Double
    Dim sTeclDesc As String
    Dim toti As Double
    Dim isubtotal_1 As Double
    Dim PUnit As Double
    
    If iTipoVenta = 24 Then
      iTotal = 0
      iTotItems = 0
      
      sTexto = sTexto + "Producto         Cant Precio  SubTotal " + vbCrLf
      sTexto = sTexto + "---------------------------------------" + vbCrLf
      
'      For i = 1 To lvwTX(1).ListItems.Count
'        iOperNC = lvwTX(1).ListItems(i).Text
'        sSQL = " SELECT O.cOperCode, O.cProdCode, O.nProdCant, O.nProdPrecUnit, O.nDscto,P.sProdDesc, P.sProdDescCrta," & _
'               " O.nProdCant * O.nProdPrecUnit 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(iOperNC)
'                'O.nProdCant * O.nProdPrecUnit * (100 - O.nDscto) / 100 As TotalMonto,
'        If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
'
'        nSubtotal = 0
'        sTexto = sTexto + "TX" + CStr(iOperNC) + vbCrLf
'        Do While Not ADORS.EOF
'          nItems = LeerCampo(ADORS("nProdCant"))
'          PUnit = LeerCampo(ADORS("nProdPrecUnit"))
'          sProdDescCrta = LeerCampo(ADORS("sProdDescCrta"))
'          sProdDesc = LeerCampo(ADORS("sProdDesc"))
'
'          nDscto = LeerCampo(ADORS("nDscto"))
'          If nDscto > 0 Then
'            PUnit = PUnit * nDscto / 100 + PUnit
'          End If
'
'          sTexto = sTexto + Left(sProdDescCrta + Space(16), 16) & _
'                    " " + Right(Space(4) & CStr(nItems), 4) & _
'                    " " + Right(Space(6) & Format(CStr(PUnit), "0.00"), 6) & _
'                    " " + Right(Space(9) & Format(CStr(PUnit * nItems), "0.00"), 9) + vbCrLf
'          If nDscto < 0 Then
'             sTexto = sTexto + Left("*Dscto " + CStr(Abs(nDscto)) + " %" + Space(16), 16) & _
'                      " " + Space(11) & _
'                      " " + Right(Space(9) & Format(CStr(PUnit * nItems * nDscto / 100), "0.00"), 9) + vbCrLf
'             PUnit = PUnit * nDscto / 100 + PUnit
'
'          End If
'          nSubtotal = nSubtotal + (PUnit * nItems)
'
'          ADORS.MoveNext
'          iTotItems = iTotItems + nItems
'        Loop
'        sTexto = sTexto + Chr(13) + Left(" AV./ITEM" & Space(23), 23) + Right(Space(15) & Format(CStr(nItems), "0.00"), 15) + vbCrLf
'        iTotal = iTotal + nSubtotal
'      Next
    End If
    '----------------------------
  Else
    
    sTexto = sTexto + "Producto         Cant Precio  SubTotal " + vbCrLf
    sTexto = sTexto + "---------------------------------------" + vbCrLf
    iServicio = 0
    igvf = 0
    For i = 0 To gfax2.UpperBound(1)
      If blnfactura = True Then
            
        If (Trim(gfax2(i, 13)) = "SI") Then
          iSubTotal = (val(Replace(gfax2(i, 6), ",", "")) * val(Replace(gfax2(i, 7), ",", "")) + (val(Replace(gfax2(i, 6), ",", "")) * val(Replace(gfax2(i, 7), ",", "")) * Producto2(i).Dscto / 100)) / (1 + kIGV + kPAR_PORCSERV * (IIf(gfax2(i, 13) = "SI", 1, 0)) / 100)
          isubtotal_1 = val(Replace(gfax2(i, 6), ",", "")) * val(Replace(gfax2(i, 7), ",", ""))
          toti = (kPAR_PORCSERV * iSubTotal * IIf(gfax2(i, 13) = "SI", 1, 0)) / 100
          IGV_1 = val(Replace(gfax2(i, 15), ",", ""))
          iServicio = iServicio + val(Replace(gfax2(i, 14), ",", ""))
          PUnit = val(Replace(gfax2(i, 7), ",", "")) / (1 + kIGV + kPAR_PORCSERV * (IIf(gfax2(i, 13) = "SI", 1, 0)) / 100)
        Else
          iSubTotal = val(Replace(gfax2(i, 6), ",", "")) * val(Replace(gfax2(i, 7), ",", ""))
          PUnit = val(Replace(gfax2(i, 7), ",", ""))
          IGV_1 = val(Replace(gfax2(i, 15), ",", ""))
        End If
            
        nDscto = Producto2(i).Dscto
                        
        PUnit = val(Replace(gfax2(i, 7), ",", ""))
        If nDscto > 0 Then
          PUnit = PUnit * nDscto / 100 + PUnit
        End If
        
        sTexto = sTexto + Left(Producto2(i).nombre + Space(16), 16) & _
               " " + Right(Space(4) & CStr(val(Replace(gfax2(i, 6), ",", ""))), 4) & _
               " " + Right(Space(6) & Format(CStr(PUnit), "0.00"), 6) & _
               " " + Right(Space(9) & Format(CStr(PUnit * val(Replace(gfax2(i, 6), ",", ""))), "0.00"), 9) + vbCrLf
                         
        iTotal = iTotal + iSubTotal
        igvf = igvf + IGV_1
        iTotItems = iTotItems + val(Replace(gfax2(i, 6), ",", ""))
        
      Else ' tk boleta de venta
                                                         
        If (Trim(gfax2(i, 13)) = "SI") Then
          iSubTotal = (val(Replace(gfax2(i, 6), ",", "")) * val(Replace(gfax2(i, 7), ",", "")) + (val(Replace(gfax2(i, 6), ",", "")) * val(Replace(gfax2(i, 7), ",", "")) * Producto2(i).Dscto / 100)) / (1 + kIGV + kPAR_PORCSERV * (IIf(gfax2(i, 13) = "SI", 1, 0)) / 100)
          isubtotal_1 = val(Replace(gfax2(i, 6), ",", "")) * val(Replace(gfax2(i, 7), ",", ""))
          toti = (kPAR_PORCSERV * iSubTotal * IIf(gfax2(i, 13) = "SI", 1, 0)) / 100
          IGV_1 = isubtotal_1 - iSubTotal - toti
          PUnit = val(Replace(gfax2(i, 7), ",", "")) / (1 + kIGV + kPAR_PORCSERV * (IIf(gfax2(i, 13) = "SI", 1, 0)) / 100)
        Else
          iSubTotal = val(Replace(gfax2(i, 6), ",", "")) * val(Replace(gfax2(i, 7), ",", ""))
          PUnit = val(Replace(gfax2(i, 7), ",", ""))
          IGV_1 = 0
        End If
            
        nDscto = Producto2(i).Dscto
        PUnit = val(Replace(gfax2(i, 7), ",", ""))
        If nDscto > 0 Then
          PUnit = PUnit * nDscto / 100 + PUnit
        End If
        
        sTexto = sTexto + Left(Producto2(i).nombre + Space(16), 16) & _
               " " + Right(Space(4) & CStr(val(Replace(gfax2(i, 6), ",", ""))), 4) & _
               " " + Right(Space(6) & Format(CStr(PUnit), "0.00"), 6) & _
               " " + Right(Space(9) & Format(CStr(PUnit * val(Replace(gfax2(i, 6), ",", ""))), "0.00"), 9) + vbCrLf
        
        iServicio = iServicio + val(Replace(gfax2(i, 14), ",", ""))
        iTotal = iTotal + iSubTotal
        iTotItems = iTotItems + val(Replace(gfax2(i, 6), ",", ""))
      End If
      'Controla el total de puntos por item y por venta
      iPtoItm = 0
      iPtoVta = 0
      IGV_1 = 0
      
      'Descuentos
      nDscto = (Producto2(i).Dscto * val(Replace(gfax2(i, 7), ",", "")) / 100)
      
      iSubTotalDscto = val(Replace(gfax2(i, 6), ",", "")) * val(Replace(gfax2(i, 7), ",", "")) + (nDscto / 100 * (val(Replace(gfax2(i, 6), ",", "")) * val(Replace(gfax2(i, 7), ",", ""))))
      Dim Serv As Double
       
      If Producto2(i).Dscto < 0 Then
        sTexto = sTexto + Left("*Dscto " + CStr(Abs(Producto2(i).Dscto)) + " %" + Space(16), 16) & _
               " " + Space(11) & _
               " " + Right(Space(9) & Format(CStr(PUnit * val(Replace(gfax2(i, 6), ",", "")) * Producto2(i).Dscto / 100), "0.00"), 9) + vbCrLf
      End If
            
      iTotalDscto = iTotalDscto + nDscto
        
    Next
  End If
 

  'Añade el % de servicio al total
    
  sTexto = sTexto + "---------------------------------------"
  Texto_imprimir = Texto_imprimir + vbCrLf + sTexto
  sTexto = ""
  
  'Total segun tipo de venta
  
  Select Case iTipoVenta
    Case 2 'Normal, Voucher
    
        If blnfactura = True Then
            sTexto = Left(" VALOR VTA" + Space(23), 23) + Right(Space(15) + Format(CStr(val(Replace(txtSoles.Text, ",", "")) - igvf - iServicio), "0.00"), 15) + vbCrLf
                       
            sTexto = sTexto + Left(" IGV" + Space(23), 23) + Right(Space(15) + Format(CStr(igvf), "0.00"), 15) + vbCrLf
            If iServicio > 0 Then
                sTexto = sTexto + Left(" SERVICIO" + "(" + kPAR_PORCSERV + " %)" + Space(23), 23) + Right(Space(15) + Format(CStr(iServicio), "0.00"), 15) + vbCrLf
            End If
            sTexto = sTexto + Left(" TOTAL VTA" + Space(23), 23) + Right(Space(15) + Format(CStr(val(Replace(txtSoles.Text, ",", ""))), "0.00"), 15) + vbCrLf + vbCrLf
                        
            toti = val(Replace(txtSoles, ",", ""))
            iTotal = 0
            If rsPagTar.RecordCount > 0 Then
                rsPagTar.MoveFirst
                Do While Not rsPagTar.EOF
                    sTexto = sTexto + Left(" " + rsPagTar.Fields("descrip") + Space(23), 23) + Right(Space(15) + Format(CStr(rsPagTar.Fields("pago")), "0.00"), 15) + vbCrLf
                    toti = toti - rsPagTar.Fields("pago")
                    iTotal = iTotal + rsPagTar.Fields("pago")
                    rsPagTar.MoveNext
                Loop
            End If
            If val(Replace(txtSoles, ",", "")) > iTotal Then
                ivuelto_1 = 0
            Else
                ivuelto_1 = toti - iTotal
            End If
        
        Else
            IGV_1 = (val(Replace(txtSoles.Text, ",", "")) - val(CStr(iTotal)))
            'Validacion
            If Round(IGV_1 + iTotal, 2) <> val(Replace(txtSoles.Text, ",", "")) Then
               MsgBox "Inconsistencia de Datos"
               iTotal = val(Replace(txtSoles.Text, ",", "")) - IGV_1
            End If
                        
            sTexto = Left(" VALOR VTA" + Space(23), 23) + Right(Space(15) + Format(CStr(val(Replace(txtSoles.Text, ",", ""))), "0.00"), 15) + vbCrLf
            
            If iServicio > 0 Then
                sTexto = sTexto + Left(" SERVICIO" + "(" + kPAR_PORCSERV + " %)" + Space(23), 23) + Right(Space(15) + Format(CStr(iServicio), "0.00"), 15) + vbCrLf
            End If
            
            toti = val(Replace(txtSoles.Text, ",", ""))
            
            If rsPagTar.RecordCount > 0 Then
                rsPagTar.MoveFirst
                Do While Not rsPagTar.EOF
                    sTexto = sTexto + Left(" " + rsPagTar.Fields("descrip") + Space(23), 23) + Right(Space(15) + Format(CStr(rsPagTar.Fields("pago")), "0.00"), 15) + vbCrLf
                    toti = toti - rsPagTar.Fields("pago")
                    iTotal = iTotal + rsPagTar.Fields("pago")
                    rsPagTar.MoveNext
                Loop
            End If
            
           
            iTotal = 0
            If val(Replace(txtSoles, ",", "")) > iTotal Then
                ivuelto_1 = 0
            Else
                ivuelto_1 = toti - iTotal
            End If
            
                        
        End If
        If bLiquidaNC = False Then
            If toti > 0 Then
               sTexto = sTexto + Left(" EFECTIVO S/." + Space(23), 23) + Right(Space(15) + Format(CStr(toti), "0.00"), 15) + vbCrLf
            End If
            If ivuelto_1 > 0 Then
               sTexto = sTexto + Left(" VUELTO" + Space(23), 23) + Right(Space(15) + Format(CStr(ivuelto_1), "0.00"), 15) + vbCrLf
            End If
        Else
         If Trim(txtliqefectivosoles.Text) = "" Then txtliqefectivosoles.Text = "0.00"
         If Trim(txtliqefectivodolares.Text) = "" Then txtliqefectivodolares.Text = "0.00"
         If Trim(txtliqpade.Text) = "" Then txtliqpade.Text = "0.00"
         If Trim(txtliqvueltosoles.Text) = "" Then txtliqvueltosoles.Text = "0.00"
         If Trim(ttxliqvueltodolares.Text) = "" Then ttxliqvueltodolares.Text = "0.00"
         
         If CDbl(txtliqefectivosoles.Text) > 0 Then
            sTexto = sTexto + Left(" EFECTIVO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqefectivosoles.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqefectivodolares.Text) > 0 Then
            sTexto = sTexto + Left(" EFECTIVO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqefectivodolares.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqpade.Text) > 0 Then
           sTexto = sTexto + Left(" PADE/PADV" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqpade.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqvueltosoles.Text) <> 0 Then
            sTexto = sTexto + Left(" VUELTO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqvueltosoles.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(ttxliqvueltodolares.Text) <> 0 Then
            sTexto = sTexto + Left(" VUELTO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(ttxliqvueltodolares.Text), "0.00"), 15)
         End If
        End If
       ' Set rsPagTar = Nothing
      
   Case 4 'Anula Productos
      sTexto = Left(" CASH/TL" + Space(23), 23) + Right(Space(15) + Format(CStr(iTotal), "0.00"), 15)
    Case 5, 1 'Efectivo
       If blnfactura = True Then
          sTexto = Left(" VALOR VTA" + Space(23), 23) + Right(Space(15) + Format(CStr(val(Replace(txtSoles.Text, ",", "")) - igvf - iServicio), "0.00"), 15) + vbCrLf
          sTexto = sTexto + Left(" IGV" + Space(23), 23) + Right(Space(15) + Format(CStr(igvf), "0.00"), 15) + vbCrLf
          If iServicio > 0 Then
            sTexto = sTexto + Left(" SERVICIO" + "(" + kPAR_PORCSERV + " %)" + Space(23), 23) + Right(Space(15) + Format(CStr(iServicio), "0.00"), 15) + vbCrLf
          End If
          sTexto = sTexto + Left(" TOTAL VTA" + Space(23), 23) + Right(Space(15) + Format(CStr(val(Replace(txtSoles.Text, ",", ""))), "0.00"), 15) + vbCrLf + vbCrLf
      Else 'adicionado
            sTexto = Left(" VALOR VTA" + Space(23), 23) + Right(Space(15) + Format(CStr(val(Replace(txtSoles.Text, ",", ""))), "0.00"), 15) + vbCrLf
            If iServicio > 0 Then
               sTexto = sTexto + Left(" SERVICIO" + "(" + kPAR_PORCSERV + " %)" + Space(23), 23) + Right(Space(15) + Format(CStr(iServicio), "0.00"), 15) + vbCrLf
            End If
      End If
     If bLiquidaNC = False Then
        If iEfectivo > 0 Then
           sTexto = sTexto + Left(" EFECTIVO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(iEfectivo), "0.00"), 15) + vbCrLf
        End If
        If iDolaresEfectivo > 0 Then
           sTexto = sTexto + Left(" EFECTIVO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(iDolaresEfectivo), "0.00"), 15) + vbCrLf
        End If
        If iVuelto <> 0 Then
           sTexto = sTexto + Left(" VUELTO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(iVuelto), "0.00"), 15) + vbCrLf
        End If
        If iVueltoDolares <> 0 Then
           sTexto = sTexto + Right(" VUELTO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(iVueltoDolares), "0.00"), 15)
        End If
      Else
         If Trim(txtliqefectivosoles.Text) = "" Then txtliqefectivosoles.Text = "0.00"
         If Trim(txtliqefectivodolares.Text) = "" Then txtliqefectivodolares.Text = "0.00"
         If Trim(txtliqpade.Text) = "" Then txtliqpade.Text = "0.00"
         If Trim(txtliqvueltosoles.Text) = "" Then txtliqvueltosoles.Text = "0.00"
         If Trim(ttxliqvueltodolares.Text) = "" Then ttxliqvueltodolares.Text = "0.00"
         
         If piEmitevoucher = 1 Then
            If rsPagTar.RecordCount > 0 Then
                rsPagTar.MoveFirst
               
                Do While Not rsPagTar.EOF
                    sTexto = sTexto + Left(" " + rsPagTar.Fields("descrip") + Space(23), 23) + Right(Space(15) + Format(CStr(rsPagTar.Fields("pago")), "0.00"), 15) + vbCrLf
                    toti = toti - rsPagTar.Fields("pago")
                    iTotal = iTotal + rsPagTar.Fields("pago")
                    rsPagTar.MoveNext
                Loop
            End If
         End If
         
         If CDbl(txtliqefectivosoles.Text) > 0 Then
            sTexto = sTexto + Left(" EFECTIVO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqefectivosoles.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqefectivodolares.Text) > 0 Then
            sTexto = sTexto + Left(" EFECTIVO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqefectivodolares.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqpade.Text) > 0 Then
             sTexto = sTexto + Left(" PADE/PADV" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqpade.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqvueltosoles.Text) <> 0 Then
             sTexto = sTexto + Left(" VUELTO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqvueltosoles.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(ttxliqvueltodolares.Text) <> 0 Then
             sTexto = sTexto + Left(" VUELTO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(ttxliqvueltodolares.Text), "0.00"), 15)
         End If
        End If
    Case 20 'O/C
          
    If bLiquidaNC = False Then
         sTexto = Left(" VALOR VTA" + Space(23), 23) + Right(Space(15) + Format(CStr(txtSoles.Text), "0.00"), 15) + vbCrLf
         If iServicio > 0 Then
             sTexto = sTexto + Left(" SERVICIO" + "(" + kPAR_PORCSERV + " %)" + Space(23), 23) + Right(Space(15) + Format(CStr(iServicio), "0.00"), 15) + vbCrLf
         End If
       
         If iEfectivo > 0 Then
            sTexto = sTexto + Left(" EFECTIVO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtEfectivoSoles.Text), "0.00"), 15) + vbCrLf
         End If
         If iDolaresEfectivo > 0 Then
             sTexto = sTexto + Left(" EFECTIVO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtEfectivoDolares.Text), "0.00"), 15) + vbCrLf
         End If
         If iVuelto <> 0 Then
              sTexto = sTexto + Left(" VUELTO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(iVuelto), "0.00"), 15) + vbCrLf
         End If
         If iVueltoDolares <> 0 Then
             sTexto = sTexto + Left(" VUELTO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(iVueltoDolares), "0.00"), 15)
         End If
     Else
         sTexto = Left(" VALOR VTA" + Space(23), 23) + Right(Space(15) + Format(CStr(txtSoles.Text), "0.00"), 15) + vbCrLf
         If iServicio > 0 Then
             sTexto = sTexto + Left(" SERVICIO" + "(" + kPAR_PORCSERV + " %)" + Space(23), 23) + Right(Space(15) + Format(CStr(iServicio), "0.00"), 15) + vbCrLf
         End If
       
         If CDbl(txtliqefectivosoles.Text) > 0 Then
             sTexto = sTexto + Left(" EFECTIVO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqefectivosoles.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqefectivodolares.Text) > 0 Then
              sTexto = sTexto + Left(" EFECTIVO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqefectivodolares.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqpade.Text) > 0 Then
              sTexto = sTexto + Left(" PADE/PADV" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqpade.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqvueltosoles.Text) <> 0 Then
             sTexto = sTexto + Left(" VUELTO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqvueltosoles.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(ttxliqvueltodolares.Text) <> 0 Then
              sTexto = sTexto + Left(" VUELTO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(ttxliqvueltodolares.Text), "0.00"), 15)
         End If
     
     End If
    Case 21 'N/C
         sTexto = Left(" TOTAL S/." + Space(23), 23) + Right(Space(15) + Format(CStr(txtSolesNC), "0.00"), 15)
    Case 22 'PADE
      Select Case mon
       Case 2
          sTexto = Left(" CASH/TL" + Space(19), 19) + Right(Space(19) + "US$ " + Format(CStr(iMontoDolares), "0.00"), 19)
       Case Else
          sTexto = Left(" CASH/TL" + Space(19), 19) + Right(Space(19) + "S/. " + Format(CStr(iTotal), "0.00"), 19)
      End Select
      
    Case 23 'PADV
    'jpcb270710
      Select Case mon
       Case 2
        If iTipoVenta = 23 Then
            sTexto = Left(" TARJETA" + Space(19), 19) + Right(Space(19) + "US$ " + Format(CStr(iMontoDolares), "0.00"), 19)
        Else
           sTexto = Left(" CASH/TL" + Space(19), 19) + Right(Space(19) + "US$ " + Format(CStr(iMontoDolares), "0.00"), 19)
        End If
           
       Case Else
        If iTipoVenta = 23 Then
            sTexto = Left(" TARJETA" + Space(19), 19) + Right(Space(19) + "S/. " + Format(CStr(iTotal), "0.00"), 19)
        Else
            sTexto = Left(" CASH/TL" + Space(19), 19) + Right(Space(19) + "S/. " + Format(CStr(iTotal), "0.00"), 19)
        End If
      End Select
      
    Case 24 'LIQPAD
          sTexto = Left(" SUB/TOTL" + Space(23), 23) + Right(Space(15) + Format(CStr(iTotal), "0.00"), 15) + vbCrLf
          sTexto = sTexto + Left(" PADE/PADV" + Space(23), 23) + Right(Space(15) + txtTotalPA.Text, 15) + vbCrLf
          sTexto = sTexto + Left(" TOT-PAGAR" + Space(23), 23) + Right(Space(15) + txtSoles.Text, 15) + vbCrLf
         If iEfectivo > 0 Then
            sTexto = sTexto + Left(" EFECTIVO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(iEfectivo), "0.00"), 15) + vbCrLf
         End If
        If iDolaresEfectivo > 0 Then
           sTexto = sTexto + Left(" EFECTIVO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(iDolaresEfectivo), "0.00"), 15) + vbCrLf
        End If
           
      If piEmitevoucher = 1 Then
         If rsPagTar.RecordCount > 0 Then
            rsPagTar.MoveFirst
               
            Do While Not rsPagTar.EOF
               'sTexto = sTexto + Left(" " + rsPagTar.Fields("descrip") + Space(23), 23) + Right(Space(15) + Format(CStr(rsPagTar.Fields("pago")), "0.00"), 15) + vbCrLf
               sTexto = sTexto + Left(" " + rsPagTar.Fields("descrip") + Space(23), 23) + Right(Space(15) + Format(CStr(rsPagTar.Fields("pago")), "0.00"), 15) + vbCrLf
               toti = toti - rsPagTar.Fields("pago")
               iTotal = iTotal + rsPagTar.Fields("pago")
              rsPagTar.MoveNext
            Loop
         End If
       End If
      If iVuelto <> 0 Then
          sTexto = sTexto + Left(" VUELTO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(iVuelto), "0.00"), 15) + vbCrLf
      End If
      If iVueltoDolares <> 0 Then
          sTexto = sTexto + Left(" VUELTO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(iVueltoDolares), "0.00"), 15)
      End If
           
  End Select

  
  printer.FontSize = 9 '12
  printer.FontBold = True
  Texto_imprimir = Texto_imprimir + vbCrLf + sTexto
  sTexto = ""
  If iTotItems > 0 Then
     sTexto = Left(" ITEM" + Space(23), 23) + Right(Space(15) + Format(CStr(iTotItems), "0.00"), 15)
 End If
  Select Case iTipoVenta
    Case 4 'Anula Productos
      sTexto = sTexto + vbCrLf + "VO-POSTN"
  End Select
  
  Texto_imprimir = Texto_imprimir + vbCrLf + sTexto + vbCrLf
  'Printer.Print sTexto
    
  'Printer.Print " "
  
  sTexto = ""
'
'  sTexto = sTexto + "---------------------------------------" + vbCrLf
'  sTexto = sTexto + Left(" TRANSACCION" + Space(23), 23) + Right(Space(15) + CStr(iCodOper), 15) + vbCrLf
'  sTexto = sTexto + "---------------------------------------" + vbCrLf

 '---Puntos----------
' nImporte = CDbl(Me.txtSolesNC.Text)
' If nImporte > 0 And sTarjeta <> "" Then
'   iPuntos = Int(nImporte / lReglaPuntoImporte) * lReglaPuntoCantidad
' End If
 
 
'  If sTarjeta <> "" Then
'     'sw 'sw Add 19/06/2009, era solo >>> intPuntosAcumulados = ObtenerPuntosAcumulados(sTarjeta)
'     intPuntosAcumulados = ObtenerPuntosAcumulados(sTarjeta, Trim(Me.txtLocal.Text))
'     If (intPuntosAcumulados + iPuntos) >= 0 And iPuntos > 0 And intPuntosAcumulados <> -1 Then
'         sTexto = sTexto & " UD. ACUMULO: " & iPuntos & " PUNTOS" & vbCrLf
'         sTexto = sTexto & " TIENE ACUMULADO: " & IIf(intPuntosAcumulados + iPuntos < 0, "**", intPuntosAcumulados + iPuntos) & " PUNTOS" & vbCrLf & vbCrLf
'     End If
'  End If
  
 '---Fin Puntos------
  
  sTexto = sTexto + Space(9) + Format(CStr(Now()), "(DDD) DD/MM/YYYY ") + Format(CStr(Now()), "hh:mm") + vbCrLf 'Hora: 6 + 1
  If bAcceso = True Then
    sTexto = sTexto + "       SUPERVISOR: " + txtsupervisor + vbCrLf
  End If
  sTexto = sTexto + Space(3) + Left(psUsuario_Descripcion, 10) + " " 'Usuario: 10 + 1
  sTexto = sTexto + Space(1) + "Cj:" + kPAR_CAJA + " T:" + kPAR_TURNO
  sTexto = sTexto + Space(1) + "v" & App.Major & "." & App.Minor & "." & App.Revision
  sTexto = sTexto + vbCrLf & "         Correlativo: " & ObtenerCorrelativo(p_1)

  Select Case iTipoVenta
 Case 20, 22, 23, 21
 Case 24
     If piEmitevoucher <> 1 Then
        txtliqefectivodolares.Text = IIf(Trim(txtEfectivoDolares.Text) = "", "0.00", txtEfectivoDolares.Text)
        txtliqefectivosoles.Text = IIf(Trim(txtEfectivoSoles.Text) = "", "0.00", txtEfectivoSoles.Text)
        txtliqvueltosoles.Text = IIf(Trim(txtVueltoSoles.Text) = "", "0.00", txtVueltoSoles.Text)
        ttxliqvueltodolares.Text = IIf(Trim(txtVueltoDolares.Text) = "", "0.00", txtVueltoDolares.Text)
     End If
     txtliqpade.Text = IIf(Trim(txtTotalPA.Text) = "", "0.00", txtTotalPA.Text)
     txtLiq.Text = iCodOper
 Case Else
    sTexto = sTexto + vbCrLf + vbCrLf + "   " + kPIE_TICKET
 End Select
  
  printer.FontSize = 8 '11
  printer.FontBold = False
  '-------------segun impresora seleccionada --------
  Texto_imprimir = Texto_imprimir + vbCrLf + sTexto
  
If p_1 = 1 Then
  ConfiguraImpresora kPAR_IMPRESORA
  Select Case KImpresora
     Case 1
         Call CortePapel(Texto_imprimir, p_1, CStr(iCodOper))
     Case 0
         printer.Print Texto_imprimir
         printer.Print " "
         printer.Print " "
         printer.EndDoc
   End Select
Else
   ConfiguraImpresora kPAR_IMPRESORA_ALTERNA
  Select Case KImpresoraALT
     Case 1
          Call CortePapel(Texto_imprimir, p_1)
      Case 0
          printer.Print Texto_imprimir
          printer.Print " "
          printer.Print " "
          printer.EndDoc
    End Select
End If
  

  '-------------------Graba operacion -------------------------
   Select Case iTipoVenta
    Case 20, 21, 22, 23, 24
      If iTipoVenta = 22 Or iTipoVenta = 23 Or iTipoVenta = 24 Then
      Else
        
        iDolaresEfectivo = val(Replace(txtEfectivoDolares, ",", ""))
        iSolesEfectivo = val(Replace(txtEfectivoSoles, ",", ""))
        iTotal = val(Replace(txtSolesNC, ",", ""))
        iMontoDolares = val(Replace(txtDolaresNC, ",", ""))
        iEfectivo = val(Replace(txtEfectivoSoles, ",", ""))
        iVuelto = val(Replace(Me.txtVueltoSoles, ",", ""))
        If iVuelto < 0 Then iVuelto = 0
        iVueltoDolares = val(Replace(Me.txtVueltoDolares, ",", ""))
        If iVueltoDolares < 0 Then iVueltoDolares = 0
        If iTipoVenta = 21 Then
            iCodOperRela = val(NC_cCodVta) 'val(txtTX.Text)
        Else
            'jpcb 17/12/2008
            If iTipoVenta = 20 And Trim(txtLiq.Text) <> "" Then
            Else
                iCodOperRela = 0
            End If
        End If
      End If
          
      
      '------------------Validacion de Numeración Correlativa -------------------------//
      If cdocTipo = "01" Or cdocTipo = "02" Then
         sSQL = "SELECT MAX(cDocCodigo) AS maximo FROM Operacion WHERE cDocTipo = '" & cdocTipo & "'"
      Else
         sSQL = "SELECT MAX(cDocCodigo) AS maximo FROM OperacionParalela WHERE cDocTipo = '" & cdocTipo & "'"
      End If
      If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
    If cDocCodigofull <> ((ADORS!Maximo) + 1) And val("0" & ADORS!Maximo) > 0 Then
      Set fso = CreateObject("Scripting.FileSystemObject")
      archivo = "Error_Full2" & cdocTipo & cDocCodigofull
      If Trim(archivo) = "" Then
          archivo = "textfile"
      End If
      Texto = Texto + "Codigo generado " & cDocCodigofull & Chr(13)
      
      NameArchivo = "C:\Temp\" + Trim(archivo) + ".log"
      Set MyFile = fso.CreateTextFile(NameArchivo, True)
      cDocCodigofull = ("0" & (ADORS!Maximo)) + 1
      Texto = Texto + "Nuevo Codigo " & cDocCodigofull & Chr(13)
      Texto = Texto + CStr(Now)
      MyFile.WriteLine (Texto)
      MsgBox "Ocurrio un error en la numeración, se asignará el " & cDocCodigofull & " al documento "
      MyFile.Close
    End If
    
    '---------------Actualizando el valor de la numeración --------------------------------//
    sSQL = "UPDATE Config_Documento " & _
          " SET cOperCode=" & CStr(iCodOper) & "," & _
          " nDocCodigo=" & cDocCodigofull & ", " & _
          " cUserDesc='" & psUsuario_Descripcion & "' " & _
          " WHERE cTipodoc='" & cdocTipo & "'"
    If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
    
    '------------------fin Validacion de Numeración Correlativa -----------------------
      
     If iTipoVenta = 23 Then
     '170810 VALIDA EL ERROR DE DUPLICIDAD DE PADV  (por error se graba otro registro inmediatamente e igual que el anterior)
             
            sSQL = "SELECT dOperFech,nTarjNumb,nMoneda,nMontoSoles,nMontoDolares,nEfectivoSoles,sGlosa FROM OPERACIONPARALELA WHERE cOperCode=" & iCodOper - 1 & ""
            
            If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
            
            If Format(ADORS!dOperFech, "DD/MM/YYYY hh:mm") = sFecha And ADORS!nTarjNumb = sTarjeta And ADORS!nMoneda = CStr(mon) And _
                ADORS!nMontoSoles = iTotal And ADORS!nMontoDolares = iMontoDolares And _
                 ADORS!nEfectivoSoles = iEfectivo And ADORS!sGlosa = txtGlosa Then
                
                
                sSQL = "UPDATE Config_Documento " & _
                      " SET cOperCode=" & CStr(iCodOper - 1) & "," & _
                      " nDocCodigo=" & cDocCodigofull - 1 & ", " & _
                      " cUserDesc='" & psUsuario_Descripcion & "' " & _
                      " WHERE cTipodoc='" & cdocTipo & "'"
                If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
                
                GoTo Salir
                
            Else
      
                    sSQL = " INSERT INTO OPERACIONPARALELA (cOperCode, cOperTipo, dOperFech, nTarjNumb," & _
                           " nMoneda, nMontoSoles, nMontoDolares, nEfectivoSoles, nVueltoSoles, sGlosa," & _
                           " cEstado, cCajaCodi, cFlagSincronizacion, cTurnoCodi, cUserDesc, cOpercodeRela, " & _
                           " nEfectivoDolares, nVueltoDolares, cDocSerie, cDocCodigo, cDocTipo ) " & _
                           " VALUES" + _
                           " ($, $, '$', '$', $, $, $, $, $, '$', '$', '$', '$', '$', '$', $ ,$ ,$,'$',$,'$')"
                    sSQL = VBsprintf(sSQL, CStr(iCodOper), CStr(iTipoVenta), sFecha, sTarjeta, CStr(mon), CStr(iTotal), _
                                           CStr(iMontoDolares), CStr(iEfectivo), CStr(iVuelto), txtGlosa, CStr(1), _
                                           kPAR_CAJA, CStr(0), kPAR_TURNO, psUsuario_Descripcion, CStr(iCodOperRela), _
                                           CStr(iDolaresEfectivo), CStr(iVueltoDolares), KSERIE_PARALELO, cDocCodigofull, cdocTipo)
                    If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
                    
            End If
        
     Else
            sSQL = " INSERT INTO OPERACIONPARALELA (cOperCode, cOperTipo, dOperFech, nTarjNumb," & _
                   " nMoneda, nMontoSoles, nMontoDolares, nEfectivoSoles, nVueltoSoles, sGlosa," & _
                   " cEstado, cCajaCodi, cFlagSincronizacion, cTurnoCodi, cUserDesc, cOpercodeRela, " & _
                   " nEfectivoDolares, nVueltoDolares, cDocSerie, cDocCodigo, cDocTipo ) " & _
                   " VALUES" + _
                   " ($, $, '$', '$', $, $, $, $, $, '$', '$', '$', '$', '$', '$', $ ,$ ,$,'$',$,'$')"
            sSQL = VBsprintf(sSQL, CStr(iCodOper), CStr(iTipoVenta), sFecha, sTarjeta, CStr(mon), CStr(iTotal), _
                                   CStr(iMontoDolares), CStr(iEfectivo), CStr(iVuelto), "REF. SIST. LOGISTICA", CStr(1), _
                                   kPAR_CAJA, CStr(0), kPAR_TURNO, psUsuario_Descripcion, CStr(iCodOperRela), _
                                   CStr(iDolaresEfectivo), CStr(iVueltoDolares), KSERIE_PARALELO, cDocCodigofull, cdocTipo)
            If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
      End If
               
               
'      sSql = " INSERT INTO OPERACIONPARALELA (cOperCode, cOperTipo, dOperFech, nTarjNumb," & _
'             " nMoneda, nMontoSoles, nMontoDolares, nEfectivoSoles, nVueltoSoles, sGlosa," & _
'             " cEstado, cCajaCodi, cFlagSincronizacion, cTurnoCodi, cUserDesc, cOpercodeRela, " & _
'             " nEfectivoDolares, nVueltoDolares, cDocSerie, cDocCodigo, cDocTipo ) " & _
'             " VALUES" + _
'             " ($, $, '$', '$', $, $, $, $, $, '$', '$', '$', '$', '$', '$', $ ,$ ,$,'$',$,'$')"
'      sSql = VBsprintf(sSql, CStr(iCodOper), CStr(iTipoVenta), sFecha, sTarjeta, CStr(mon), CStr(iTotal), _
'                             CStr(iMontoDolares), CStr(iEfectivo), CStr(iVuelto), txtGlosa, CStr(1), _
'                             kPAR_CAJA, CStr(0), kPAR_TURNO, psUsuario_Descripcion, CStr(iCodOperRela), _
'                             CStr(iDolaresEfectivo), CStr(iVueltoDolares), KSERIE_PARALELO, cDocCodigofull, cdocTipo)
'      If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSql) Then GoTo Salir
      
      
      nImporte = 0
      nPtosImp = 0
      nPuntos = 0
      
'      For i = 0 To gfax.UpperBound(1)
      For i = 0 To nProducto2
        'TDGNotaConsumo.Row = i
        sSQL = " INSERT INTO OPERACIONPARALELAPRODUCTO (cAlmaCode, cOperCode, cProdCode, nProdCant," & _
               " nProdPrecUnit, nDscto, nServicio)" & _
               " VALUES" + _
               " ('$', $, $, $, $, $,$)"
        sSQL = VBsprintf(sSQL, kPAR_ALMACEN, CStr(iCodOper), CStr(Producto2(i).Codigo), CStr(Abs(val(Replace(gfax2(i, 6), ",", "")))), _
                         CStr(val(Replace(gfax2(i, 7), ",", ""))), CStr(Producto2(i).Dscto), IIf(gfax2(i, 13) = "SI", kPAR_PORCSERV, "0"))
        If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
        
  
        'CONTABILIZA PUNTOS
        '------------------
'        nImporte = nImporte + _
'                   Producto(i).Cant * val(TDGNotaConsumo.Columns(7).Text) * (100 - Producto(i).Dscto) * _
'                   IIf(Producto(i).Canje = "VNTA", 1, 0) / 100
'        nPtosImp = nPtosImp + _
'                   Producto(i).Cant * Producto(i).PUnit * (100 - Producto(i).Dscto) * _
'                   IIf(Producto(i).Canje = "PTOS", 1, 0) / 100
'        nPuntos = nPuntos + IIf(Producto(i).Canje = "PTOS", 1, 0) * Producto(i).Ptos * Producto(i).Cant
      Next
      Dim CodLiq As Long
      If iTipoVenta = 1 Or _
         iTipoVenta = 20 And (iDolaresEfectivo > 0 Or iSolesEfectivo > 0) Or _
         iTipoVenta = 5 And (iDolaresEfectivo > 0 Or iSolesEfectivo > 0) Or _
         iTipoVenta = 24 And (iDolaresEfectivo > 0 Or iSolesEfectivo > 0) Then
         Dim iCodTipo As Long
         If iTipoVenta = 24 Then
         txtLiq.Text = iCodOper
         End If
         
         If bLiquidaNC = False Then
            If piEmitevoucher = 1 And iEfectivo = 0 Then
              iCodTipo = 2
            Else
              iCodTipo = 1
            End If
            CodLiq = 0
            
         Else
            iCodTipo = 3
            CodLiq = val(txtLiq.Text)
         End If
        '---primera
           If iDolaresEfectivo <= 0 And iEfectivo <= 0 Then iEfectivo = Replace(txtSoles, ",", "")
           
           sSQL = " INSERT INTO OPERACION (cOperCode, cUserDesc, nTarjNumb, cProdCode, nProdCant, nProdPrecUnit," & _
               " nMontoDolares, dOperFech, cOperTipo, cCajaCodi, cTurnoCodi, nmontosoles, nVueltoDolares,  cDocSerie, cDoccodigo, cdocTipo, cOpercodeAnula, IdLocal) " + _
               " VALUES" + _
               " ($, '$', '$', $, $, $, $, '$', $, '$', '$',$ ,$, '$', $, '$', $, $)"
           sSQL = VBsprintf(sSQL, CStr(iCodOper), psUsuario_Descripcion, sTarjeta, CStr(0), CStr(1), _
                           CStr(-1 * iVuelto), CStr(iDolaresEfectivo), sFecha, CStr(iCodTipo), kPAR_CAJA, kPAR_TURNO, CStr(iEfectivo), CStr(iVueltoDolares), cDocSerie, cDocCodigofull, cdocTipo, CodLiq, idLocal)

        If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
        iVuelto = val(Replace(txtVueltoSoles, ",", ""))
        If iVuelto < 0 Then iVuelto = 0
      End If
      
      
      nImporte = CDbl(Me.txtSolesNC.Text)
      nPuntos = 0
      '--------------------------Inserta linea voucher liq------------------------------------
      Dim importevoucher As Double
      
      If piEmitevoucher = 1 Then
         importevoucher = nImporte - iEfectivo + iVuelto
         sSQL = " INSERT INTO OPERACION (cOperCode, cUserDesc, nTarjNumb, cProdCode, nProdCant, nProdPrecUnit," & _
               " nMontoDolares, dOperFech, cOperTipo, cCajaCodi, cTurnoCodi, nmontosoles, nVueltoDolares,  cDocSerie, cDoccodigo, cdocTipo, cOpercodeAnula, cemisor, IdLocal) " + _
               " VALUES" + _
               " ($, '$', '$', $, $, $, $, '$', $, '$', '$',$ ,$, '$', $, '$', $, '$', $)"
         sSQL = VBsprintf(sSQL, CStr(iCodOper), psUsuario_Descripcion, sTarjeta, CStr(0), CStr(1), _
                           0, 0, sFecha, 2, kPAR_CAJA, kPAR_TURNO, CStr(importevoucher), 0, cDocSerie, cDocCodigofull, cdocTipo, CodLiq, cEmisor, idLocal)
         If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
                          
      End If
      
      '-----------------------------------------------------------------------------
       
      'ACTUALIZA PUNTOS
      '----------------
'      If nImporte > 0 And sTarjeta <> "" Then
'        Call Guarda_Puntos(sTarjeta, "VNTA", cdocTipo, cDocSerie, cDocCodigofull, nImporte, , nIdClienteLocal)
'        iPuntos = Int(nImporte / lReglaPuntoImporte) * lReglaPuntoCantidad
'      End If
'      If nPuntos > 0 And sTarjeta <> "" Then
'        Call Guarda_Puntos(sTarjeta, "PTOS", cdocTipo, cDocSerie, cDocCodigofull, nPuntos, nPtosImp, nIdClienteLocal)
'      End If
      '----------------
      
      If iTipoVenta = 24 Then
        sSQL = " UPDATE OPERACIONPARALELA" & _
               " SET cEstado = 2" + _
               " WHERE cOperCode = $"
        sSQL = VBsprintf(sSQL, CStr(iCodOper))
        If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
                
'        For i = 1 To lvwTX(0).ListItems.Count
'          iCodOperRela = val(lvwTX(0).ListItems(i).Text)
'          sSQL = " UPDATE OPERACIONPARALELA" & _
'                 " SET cOpercodeRela = $," & _
'                 " cEstado = 2" + _
'                 " WHERE cOperCode = $"
'          sSQL = VBsprintf(sSQL, CStr(iCodOper), CStr(iCodOperRela))
'          If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
'        Next
        
'        For i = 1 To lvwTX(1).ListItems.Count
'          iCodOperRela = val(lvwTX(1).ListItems(i).Text)
'          sSQL = " UPDATE OPERACIONPARALELA" & _
'                 " SET cOpercodeRela = $," & _
'                 " cEstado = 2" + _
'                 " WHERE cOperCode = $" ' AND cOperCodeRela = 0"
'          sSQL = VBsprintf(sSQL, CStr(iCodOper), CStr(iCodOperRela))
'          If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
'        Next
      End If
  
      
    Case Else
      
      nImporte = 0
      nPtosImp = 0
      nPuntos = 0
      If rsPagTar.state = adStateOpen Then
      If rsPagTar.RecordCount > 0 Then
        rsPagTar.MoveFirst
        Do While Not rsPagTar.EOF
            cEmisor = cEmisor + "," + rsPagTar.Fields("cod_tar")
            rsPagTar.MoveNext
        Loop
      End If
      End If
      
  '------------------Validacion de Numeración Correlativa -------------------------//
  sSQL = "SELECT MAX(cDocCodigo) AS maximo FROM Operacion WHERE cDocTipo = '" & cdocTipo & "'"
         If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
         
  If cDocCodigofull <> ((ADORS!Maximo) + 1) And val("0" & ADORS!Maximo) > 0 Then
    Set fso = CreateObject("Scripting.FileSystemObject")
    archivo = "Error_Full2" & cdocTipo & cDocCodigofull
    If Trim(archivo) = "" Then
        archivo = "textfile"
    End If
    Texto = Texto + "Codigo generado " & cDocCodigofull & Chr(13)
    
    NameArchivo = "C:\Temp\" + Trim(archivo) + ".log"
    Set MyFile = fso.CreateTextFile(NameArchivo, True)
    cDocCodigofull = ("0" & (ADORS!Maximo)) + 1
    Texto = Texto + "Nuevo Codigo " & cDocCodigofull & Chr(13)
    Texto = Texto + CStr(Now)
    MyFile.WriteLine (Texto)
    MsgBox "Ocurrio un error en la numeración, se asignará el " & cDocCodigofull & " al documento "
  End If
  
  '---------------Actualizando el valor de la numeración --------------------------------//
  sSQL = "UPDATE Config_Documento " & _
        " SET cOperCode=" & CStr(iCodOper) & "," & _
        " cUserDesc='" & psUsuario_Descripcion & "' " & _
        " WHERE cTipodoc='" & cdocTipo & "'"
  If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
  
  '------------------fin Validacion de Numeración Correlativa ---------------------------//
          
      For i = 0 To gfax2.UpperBound(1)
         'TDGNotaConsumo.Row = i
         If bLiquidaNC Then iFlagTipo = 3
         
         If iFlagTipo = 3 Then
            CodLiq = val(txtLiq.Text)
         Else
            CodLiq = 0
         End If
         sSQL = " INSERT INTO OPERACION (cOperCode, cUserDesc, nTarjNumb, cAlmaCode, cProdCode, nProdCant, nProdPrecUnit," & _
                " nMontoDolares, dOperFech, cOperTipo, cCajaCodi, cTurnoCodi, nDscto, nServicio, cDocCodigo, cRuc, cDocSerie, cDocTipo, cEmisor, cOpercodeanula, idLocal) " + _
                " VALUES" + _
                " ($, '$', '$', '$', $, $, $, $, '$', $, '$', '$', $, $, $, '$', '$', '$', '$', $, $)"
         
         sSQL = VBsprintf(sSQL, CStr(iCodOper), psUsuario_Descripcion, sTarjeta, kPAR_ALMACEN, CStr(Producto2(i).Codigo), CStr(val(Replace(gfax2(i, 6), ",", "") * iSigno)), _
                CStr(val(Replace(gfax2(i, 7), ",", ""))), CStr(0), sFecha, CStr(iFlagTipo), kPAR_CAJA, kPAR_TURNO, CStr(Producto2(i).Dscto), IIf(gfax2(i, 13) = "SI", kPAR_PORCSERV, "0"), cDocCodigofull, cRuc, cDocSerie, cdocTipo, cEmisor, CodLiq, idLocal)
               
         If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
         iEfectivo = val(Replace(txtEfectivoSoles, ",", ""))
         iVuelto = val(Replace(txtVueltoSoles, ",", ""))
         If iVuelto < 0 Then iVuelto = 0
    
      Next
       
      nImporte = CDbl(Me.txtSoles.Text)
      nPuntos = 0
         
      iVuelto = val(Replace(txtVueltoSoles, ",", ""))
      iDolaresEfectivo = val(Replace(txtEfectivoDolares, ",", ""))
      iSolesEfectivo = val(Replace(txtEfectivoSoles, ",", ""))
      iVueltoDolares = val(Replace(Me.txtVueltoDolares, ",", ""))
      If iVuelto < 0 Then iVuelto = 0
      If iVueltoDolares < 0 Then iVueltoDolares = 0
      'ACTUALIZA PUNTOS
      '----------------
      If Not blLiquidaVenta Then
        If nImporte > 0 And sTarjeta <> "" Then
          Call Guarda_Puntos(sTarjeta, "VNTA", cdocTipo, cDocSerie, cDocCodigofull, nImporte, , nIdClienteLocal)
          iPuntos = Int(nImporte / lReglaPuntoImporte) * lReglaPuntoCantidad
        End If
        If nPuntos > 0 And sTarjeta <> "" Then
          Call Guarda_Puntos(sTarjeta, "PTOS", cdocTipo, cDocSerie, cDocCodigofull, nPuntos, nPtosImp, nIdClienteLocal)
        End If
    
      End If
      '---------------
      
      If iTipoVenta = 1 And (iDolaresEfectivo > 0 Or iSolesEfectivo > 0) Or _
         iTipoVenta = 20 And (iDolaresEfectivo > 0 Or iSolesEfectivo > 0) Or _
         iTipoVenta = 5 And (iDolaresEfectivo > 0 Or iSolesEfectivo > 0) Or _
         iTipoVenta = 3 And (iDolaresEfectivo > 0 Or iSolesEfectivo > 0) Or _
         iTipoVenta = 24 And (iDolaresEfectivo > 0 Or iSolesEfectivo > 0) Or _
         (iTipoVenta = 2 And (iDolaresEfectivo > 0 Or iSolesEfectivo > 0)) Then
        '-----segunda
         If bLiquidaNC = False Then
            iCodTipo = 1
            CodLiq = 0
         Else
            iCodTipo = 3
            CodLiq = val(txtLiq.Text)
         End If
        
            sSQL = " INSERT INTO OPERACION (cOperCode, cUserDesc, nTarjNumb, cProdCode, nProdCant, nProdPrecUnit," & _
                   " nMontoDolares, dOperFech, cOperTipo, cCajaCodi, cTurnoCodi,nmontosoles, nVueltoDolares, cDocCodigo, cRuc, cDocSerie, cDocTipo,cEmisor, cOpercodeAnula, IdLocal) " + _
                   " VALUES" + _
                   " ($, '$', '$', $, $, $, $, '$', $, '$', '$',$ ,$, $, '$', '$', '$', '$', $, $)"
            sSQL = VBsprintf(sSQL, CStr(iCodOper), psUsuario_Descripcion, sTarjeta, CStr(0), CStr(1), _
                               CStr(-1 * iVuelto), CStr(iDolaresEfectivo), sFecha, CStr(iCodTipo), kPAR_CAJA, kPAR_TURNO, CStr(iSolesEfectivo), CStr(iVueltoDolares), CStr(cDocCodigofull), cRuc, cDocSerie, cdocTipo, cEmisor, CodLiq, idLocal)
'        Else
'             ssql = " INSERT INTO OPERACION (cOperCode, cUserDesc, nTarjNumb, cProdCode, nProdCant, nProdPrecUnit," & _
'               " nMontoDolares, dOperFech, cOperTipo, cCajaCodi, cTurnoCodi, nmontosoles, nVueltoDolares,  cDocSerie, cDoccodigo, cdocTipo) " + _
'               " VALUES" + _
'               " ($, '$', '$', $, $, $, $, '$', $, '$', '$',$ ,$, '$', $, '$')"
'            ssql = VBsprintf(ssql, CStr(iCodOper), psUsuario_Descripcion, sTarjeta, CStr(0), CStr(1), _
'                           CStr(0), CStr(0), sFecha, CStr(iCodTipo), kPAR_CAJA, kPAR_TURNO, CStr(-1 * (Replace(txtSoles.Text, ",", ""))), CStr(0), cDocSerie, cDocCodigofull, cdocTipo)
            
       ' End If
    
     If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
        'iEfectivo = Val(Replace(txtEfectivoDolares, ",", ""))
        iVuelto = val(Replace(txtVueltoSoles, ",", ""))
        If iVuelto < 0 Then iVuelto = 0
    End If
            
  End Select
   
  
  bLiquidaNC = False
  '-------------------Fin Graba operacion -------------------------
  
  '----------------------
  '-- Blanquea la Caja --
  '----------------------
  bProducto = False
  iTotalVenta = 0
  'cmdTecla_Click (0)
  
  'SINCRONIZAR
  'Sincronizar
  
  'Inicializa variables y controles
  gfax2.Clear
  'gfax2.ReDim 0, 0, 0, 14
  gfax2.ReDim 0, 0, 0, 15
  TDGNotaConsumo.ReBind
  TDGNotaConsumo.MoveFirst
  TDGNotaConsumo.Update
  'cmdTecla_Click (0)
    
  Inicio
  txtTarjeta.SetFocus
  If blLiquidaVenta Then
     'Call LiquidaNC(iCodOper)
  End If
  
 LimpiarNC
 
  GoTo Salir
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  Screen.MousePointer = vbDefault

Salir:
  Set ADORS = Nothing
  If piEmitevoucher <> 1 Then
    Set rsPagTar = Nothing
  End If

End Sub
Private Sub RegistrarVentaNew()

On Error GoTo LineaError
  
  Dim sSQL As String
  Dim ADORS As ADODB.Recordset
  Dim i As Long, j As Long, iCodOper As Long, iCodOperRela As Long
  Dim iTotal, iTotalVenta As Double, iSubTotal As Double, iSubTotalDscto As Double
  Dim iTotalDscto As Double, iTotItems As Double
  Dim sFecha As String
  Dim sTexto As String
  Dim iSigno As Integer
  Dim iFlagTipo As Integer
  Dim sTarjeta As String
  Dim ivuelto_1 As Double
  Dim iMontoDolares As Double
  Dim iMontoSoles As Double
  Dim iDolaresEfectivo As Double
  Dim iSolesEfectivo As Double
  Dim rs1 As Recordset
  Dim p_1 As Integer
  Dim impr_1 As String
  Dim impr_2 As String
  Dim nImporte As Double, iServicio, nPuntos As Double, nPtosImp As Double
  Dim iPtoVta, iPtoItm As Double, iPagoAdelantado As Double
  Dim blLiquidaVenta As Boolean
  Dim Texto_imprimir As String
  Dim iPuntos As Long
  Dim sssql As String
  Dim blnfactura As Boolean
  Dim intPuntosAcumulados As Long
  Dim x As printer
  
  Dim cEmisor As String
  Dim cDocCodigofull As Long
  Dim cDocSerie As String
  Dim cdocTipo As String
  Dim cRuc As String
  Dim IGV_1 As Double
  blLiquidaVenta = False
  blnfactura = False
  Dim KSERIE_PARALELO As String
  
  'sw To SQL Server add
  Dim idLocal As String
  
  TDBGrid1.Update
  If piEmitevoucher <> 1 Then
    'CalculaTotales
    'CalculoVuelto
  End If
  cDocCodigofull = 0
  p_1 = 0
  
  ConectarBDCliente
  'Verifica si es Factura
'  If Not Trim(Me.txtRUC.Text) = "" Then
'    blnfactura = True
'    cRuc = Trim(Me.txtRUC.Text)
'    cdocTipo = "01"
'    cDocSerie = kSERIE_FACTURA
'  Else
'    cRuc = ""
'    cdocTipo = "02"
'    cDocSerie = kSERIE
'  End If
  
  
iTipoVenta = cboTipoDocumento.ListIndex

If iTipoVenta = -1 Then
    Exit Sub
ElseIf iTipoVenta = 0 Then
    blnfactura = True
    cRuc = Trim(Me.txtRUC.Text)
    cdocTipo = "01"
    cDocSerie = kSERIE_FACTURA
ElseIf iTipoVenta = 1 Then
    cRuc = ""
    cdocTipo = "02"
    cDocSerie = kSERIE
End If
  
  
  
  
  
  '--------------------
  '-- Registra Venta --
  '--------------------

    'SE OBTIENE FECHA DEL SISTEMA DE LA BASE DE DATOS DE SQL - version 2.0.5
   
   Dim cnFECHASQL As ADODB.Connection
   Dim sqlFECHASIS As String
   Dim rsFEchaSis As ADODB.Recordset
      
   If oDBAdmin.AbrirBD(cnFECHASQL, psConnectString, False) = True Then
     
     sqlFECHASIS = "select convert(varchar,getdate(),120) as fechasis"
     If oDBAdmin.EjecutarConsulta(cnFECHASQL, sqlFECHASIS, rsFEchaSis) = True Then
         
         If rsFEchaSis!fechasis <> "" Then
             sFecha = rsFEchaSis!fechasis
         End If

     Else
         'no pudo abrir el rs: que consulte al access
         'MsgBox "No se pudo obtener la fecha, hay problemas de conexión de la red con la Base de Datos Principal", vbOKOnly + vbExclamation, "Aviso"
         sFecha = Format(Now(), "DD/MM/YYYY hh:mm")
         'Unload Me
     End If

     Set cnFECHASQL = Nothing

   Else
     'no pudo conectarse al sql: que consulte al access
      'MsgBox "No se pudo obtener la fecha, hay problemas de conexión de la red con la Base de Datos Principal", vbOKOnly + vbExclamation, "Aviso"
      sFecha = Format(Now(), "DD/MM/YYYY hh:mm")
      'Unload Me
   End If
   
   'FIN FECHA DEL SISTEMA DE LA BASE DE DATOS DE SQL

  'sFecha = Format(Now(), "DD/MM/YYYY hh:mm")

  Set ADORS = Nothing
  
  iFlagTipo = iTipoVenta
  If iTipoVenta = 4 Then
    iSigno = -1
    iFlagTipo = 1
  Else
    iSigno = 1
    iFlagTipo = iTipoVenta
  End If
  If iTipoVenta = 5 Then
    iFlagTipo = 1
  End If
  
  iCodOperRela = 0
  
  'vd 05/08/07 TDBGrid1.Update
      
  'Verifica si es un tipo de operaciòn que necesita password: Anulación o Descuento
  For i = gfax.LowerBound(1) To gfax.UpperBound(1)
    sTexto = IIf(Replace(gfax(i, 9), ",", "") = "", "0", Replace(gfax(i, 9), ",", ""))
    If val(sTexto) <> 0 Then
      bAcceso = True
      Exit For
    End If
  Next
  
  If bAcceso Then
    bAcceso = False
    Load frmAutorizarOperacion
    Set frmAutorizarOperacion.frmPadre = Me
    frmAutorizarOperacion.Show vbModal
    If Not bAcceso Then Exit Sub
    'bAcceso = False
  End If
  '--------Abre la gaveta de dinero automaticamente al aceptar la venta ----
  Dim opc_gaveta As String
  opc_gaveta = LeerCfg("PARAMETROS", "GAVETA", psArchivoCfg)
  If Trim(UCase(opc_gaveta)) = "S" Then
    Abre_Gaveta_Dinero (LeerCfg("PARAMETROS", "PRINTER", psArchivoCfg))
  End If
  '-------------------------------------------------------------------------
  If iTipoVenta = 6 Or iTipoVenta = 7 Then
    If Not IsNumeric(Replace(IIf(txtPagoAdelantado = "", "0.00", txtPagoAdelantado), ",", "")) Then Exit Sub
    If Not IsNumeric(Replace(IIf(txtPADEDolares = "", "0.00", txtPADEDolares), ",", "")) Then Exit Sub
    If val(Replace(IIf(txtPagoAdelantado = "", "0.00", txtPagoAdelantado), ",", "")) = 0 And _
       val(Replace(IIf(txtPADEDolares = "", "0.00", txtPADEDolares), ",", "")) = 0 Then
      MsgBox "Debe registar una cantidad mayor que cero."
      txtPagoAdelantado.SetFocus
      Exit Sub
    End If
  End If
 
  'Calculo de vueltos
  Dim iVueltoSoles As Double
  
  If iTipoVenta = 1 Or iTipoVenta = 4 Then   'Or iTipoVenta = 8
    If Trim(Me.txtEfectivoDolares.Text) = "" Then Me.txtEfectivoDolares.Text = "0.00"
    If Trim(Me.txtEfectivoSoles.Text) = "" Then Me.txtEfectivoSoles.Text = "0.00"
    
    If val(Replace(Me.txtEfectivoDolares.Text, ",", "")) = 0 And _
      val(Replace(Me.txtEfectivoSoles.Text, ",", "")) = 0 Then
      Me.txtEfectivoSoles.Text = Me.txtSoles
    End If
  End If

  'Configura la Impresora por default
  'sw 1 = Efectivo
  'sw 2 = VOUCHER
  'sw 3 = O/C
  'sw 4 = N/C
  'sw 5 = PADE
  'sw 6 = PADV
  'sw 7 = LIQPAD
  'sw 8 = ANULAR TRANSACCION
  'sw 9 = RECAUDACION
  
  Select Case iTipoVenta
    Case 4, 5, 6, 7, 8
      If iTipoVenta = 4 Then iTipoVenta = 20 ' O/C
      If iTipoVenta = 5 Then iTipoVenta = 21 ' N/C
      If iTipoVenta = 6 Then iTipoVenta = 22 ' PADE
      If iTipoVenta = 7 Then iTipoVenta = 23 ' PADV
      If iTipoVenta = 8 Then iTipoVenta = 24 ' LIQPAD
      ConfiguraImpresora kPAR_IMPRESORA_ALTERNA
    Case Else
      ConfiguraImpresora kPAR_IMPRESORA
  End Select
  
  Select Case iTipoVenta
    Case 20, 21, 22, 23, 24
      sSQL = "SELECT MAX(cOperCode) AS maximo FROM OperacionParalela"
    Case Else
      sSQL = "SELECT MAX(cOperCode) AS maximo FROM Operacion"
  End Select
  
  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
      'EscribirCfg "PARAMETROS", "cOpeB", psArchivoCfg, Str(iCodOper + 1)
    End If
  End If
  
  'Inicializa Recorset
  If iTipoVenta <> 2 And piEmitevoucher <> 1 Then
    Set rsPagTar = New Recordset
  End If

  If iCodOper = 1 Then
'    kOPERACION = LeerCfg("PARAMETROS", "cOpeB", psArchivoCfg)
'    iCodOper = Val(kOPERACION)
  End If
  
  'Si hay vuelto se convierte en iTipo = 5
  If iTipoVenta = 1 And (val(Replace(txtVueltoSoles, ",", "")) <> 0 Or val(Replace(txtVueltoDolares, ",", "")) <> 0) Then
    iTipoVenta = 5
  End If
  
  'Asigna valor para liquidar NC
  If iTipoVenta = 24 Then blLiquidaVenta = True
    
  'Registra los datos del producto
  If iTipoVenta = 22 Or iTipoVenta = 23 Or iTipoVenta = 24 Then
    nProducto = -1
  Else
    ReDim Producto(gfax.UpperBound(1))
    
    For i = gfax.LowerBound(1) To gfax.UpperBound(1)
      Producto(i).Almacen = kPAR_ALMACEN
      Producto(i).Cant = Replace(gfax(i, 6), ",", "")
      Producto(i).PUnit = Replace(gfax(i, 7), ",", "")
      Producto(i).Codigo = gfax(i, 1)
      Producto(i).nombre = gfax(i, 3)
      If gfax(i, 8) = "+" Then
        Producto(i).Dscto = Replace(IIf(gfax(i, 9) = "", 0, gfax(i, 9)), ",", "")
      Else
        Producto(i).Dscto = -1 * Replace(IIf(gfax(i, 9) = "", 0, gfax(i, 9)), ",", "")
      End If
      
      Producto(i).Canje = gfax(i, 11)
      Producto(i).Ptos = val(Replace(gfax(i, 12), ",", ""))
      Producto(i).Serv = gfax(i, 13)
    Next
    nProducto = gfax.UpperBound(1)
  End If
    
  If Trim(txtTarjeta.Text) <> "" Then
    sTarjeta = Right("00000000" + Trim(txtTarjeta.Text), 8)
  Else
    sTarjeta = ""
  End If
  
  'sw To SQL Server add
  idLocal = IIf(Trim(Me.txtLocal.Text) = "", "NULL", Trim(Me.txtLocal.Text))
  
  'Calcula el total de las ventas
  iTotalVenta = Replace(txtSoles, ",", "")
  'lblTotal.Caption = "TOT:" + Right("               " + Format(CStr(iTotalVenta), "0.00"), 14)
  
  'Captura Serie y Codigo del Documento
  
  Select Case iTipoVenta
    Case 20
      cdocTipo = "10"
    Case 21
      cdocTipo = "11"
   Case 22
      cdocTipo = "12"
   Case 23
      cdocTipo = "13"
   Case 24
      cdocTipo = "14"
  End Select
  
  Dim dbCalculado As Boolean
  Dim ddtotefectivo, ddtotvuelto As Double
  Dim mon As Integer
  Dim ierroritm As Integer
  ierroritm = 0
  dbCalculado = False
  
  Do While dbCalculado = False And ierroritm < 3
    Select Case iTipoVenta
      Case 20, 21, 22, 23, 24
        If iTipoVenta = 22 Or iTipoVenta = 23 Then 'PADE o PADV
          iDolaresEfectivo = val(Replace(txtPADEDolares, ",", ""))
          iEfectivo = val(Replace(txtPagoAdelantado, ",", ""))
          If iEfectivo > 0 Then
            mon = 1
          End If
          If iDolaresEfectivo > 0 Then
            mon = 2
          End If
          If mon = 1 Then 'Soles
            iTotal = val(Replace(txtPagoAdelantado, ",", ""))
            iMontoDolares = CDbl(Format(CStr(iTotal / nTipoCambio), "0.00"))
            'iMontoDolares = CDbl(Format(CStr(iTotal / nTipoCambio), "0.00"))
          End If
          If mon = 2 Then 'Dolares
            iMontoDolares = val(Replace(txtPADEDolares, ",", ""))
            iTotal = CDbl(Format(CStr(iMontoDolares * nTipoCambio), "0.00"))
            'iTotal = CDbl(Format(CStr(iMontoDolares * nTipoCambio), "0.00"))
          End If
          
          iSolesEfectivo = iEfectivo
          iVuelto = 0
          iVueltoDolares = 0
        Else
          
          iTotal = val(Replace(txtSoles, ",", ""))
          iMontoDolares = val(Replace(txtDolares, ",", ""))
          If piEmitevoucher = 1 And blLiquidaVenta = True Then
            iDolaresEfectivo = val(Replace(txtliqefectivodolares, ",", ""))
            iSolesEfectivo = val(Replace(txtliqefectivosoles, ",", ""))
            iEfectivo = val(Replace(txtliqefectivosoles, ",", ""))
            iVuelto = val(Replace(txtliqvueltosoles, ",", ""))
            iVueltoDolares = val(Replace(ttxliqvueltodolares, ",", ""))
          Else
            iDolaresEfectivo = val(Replace(txtEfectivoDolares, ",", ""))
            iSolesEfectivo = val(Replace(txtEfectivoSoles, ",", ""))
            iEfectivo = val(Replace(txtEfectivoSoles, ",", ""))
            iVuelto = val(Replace(txtVueltoSoles, ",", ""))
            iVueltoDolares = val(Replace(txtVueltoDolares, ",", ""))
          End If
          If iVuelto < 0 Then iVuelto = 0
          If iDolaresEfectivo < 0 Then iDolaresEfectivo = 0
          If iVueltoDolares < 0 Then iVueltoDolares = 0
          If iTipoVenta = 21 Then iCodOperRela = val(txtTX.Text)
          If iTipoVenta = 20 And Trim(txtLiq.Text) <> "" Then iCodOperRela = val(txtLiq.Text)
        End If
      Case Else
        iVuelto = val(Replace(txtVueltoSoles, ",", ""))
        iTotal = val(Replace(txtSoles, ",", ""))
        If iVuelto < 0 Then iVuelto = 0
        If piEmitevoucher = 1 And bLiquidaNC Then
          iEfectivo = val(Replace(txtliqefectivosoles, ",", ""))
          iDolaresEfectivo = val(Replace(txtliqefectivodolares, ",", ""))
          iVueltoDolares = val(Replace(ttxliqvueltodolares, ",", ""))
          iVuelto = val(Replace(Me.txtliqvueltosoles, ",", ""))
        Else
          iEfectivo = val(Replace(txtEfectivoSoles, ",", ""))
          iDolaresEfectivo = val(Replace(txtEfectivoDolares, ",", ""))
          iSolesEfectivo = val(Replace(txtEfectivoSoles, ",", ""))
          iVueltoDolares = val(Replace(txtVueltoDolares, ",", ""))
        End If
        If iVueltoDolares < 0 Then iVueltoDolares = 0
    End Select
    
    ddtotefectivo = Round(iSolesEfectivo + (iDolaresEfectivo * nTipoCambio), 2)
    ddtotvuelto = Round(iVuelto + (iVueltoDolares * nTipoCambio), 2)
    
    If (iTipoVenta <> 2 And iTipoVenta <> 22 And iTipoVenta <> 23 And iTipoVenta <> 21 And iTipoVenta <> 24) And (Round(ddtotefectivo - ddtotvuelto, 2) <> Round(iTotal, 2)) Then
      MsgBox "Ocurrio un error de Cálculo"
      dbCalculado = False
      ierroritm = ierroritm + 1
    Else
      dbCalculado = True
      ierroritm = 0
    End If
  Loop
  '------------------------
  '-- Captura Parámetros --
  '------------------------
  Texto_imprimir = ""
  Call CabeceraImpresion
  sTexto = ""
  
  sssql = "SELECT sImpresora, sImpresoraAlterna from Configuracion"
  If Not oDBAdmin.EjecutarConsulta(ADOCnn, sssql, rs1) Then GoTo Salir
  impr_1 = rs1.Fields("sImpresora")
  impr_2 = rs1.Fields("sImpresoraAlterna")
  
  'Pregunta si x.Devicename tiene el mismo nombre que el nombre de la impresora por donde necesitas sacar la impresion.
  If iTipoVenta = 1 Or iTipoVenta = 2 Or iTipoVenta = 5 Then
    p_1 = 1
  Else
    p_1 = 2
  End If
  
  printer.FontSize = 8 '11
  printer.FontName = "Courier New"
  
  Select Case iTipoVenta
    Case 20, 21, 22, 23, 24
    Case Else
      For i = 0 To UBound(sCabecera) - 1
        If Not Trim(sCabecera(i)) = "" Then
          sTexto = sTexto + Right(Space(60) + sCabecera(i), Int(Len(Space(40) + sCabecera(i)) / 2)) + vbCrLf
        End If
      Next
  End Select
  
  'Linea de Datos del Socio
  If Not sTarjeta = "" Then
    sTexto = sTexto + vbCrLf + " COD.TARJ.: " + sTarjeta + " "
    If Not blnfactura = True Then
      sTexto = sTexto + vbCrLf + " NOMBRE: " + txtNombres.Text + vbCrLf
    End If
  Else
    If Not blnfactura = True And Not Trim(txtNombres.Text) = "" Then
      sTexto = sTexto + vbCrLf + " NOMBRE: " + UCase(Trim(txtNombres.Text)) + vbCrLf
    End If
  End If
  
  If blnfactura = True Then
    sTexto = sTexto + vbCrLf + " NOMBRE: " & "____________________________"
    sTexto = sTexto + vbCrLf + vbCrLf + "         " & "____________________________" + vbCrLf
    sTexto = sTexto + vbCrLf + " RUC Cliente: " & Trim(Me.txtRUC.Text) + vbCrLf
  End If
  
  ' Obteniendo Nro de documento
  sSQL = "SELECT  * FROM Config_Documento WHERE cTipoDoc='" & cdocTipo & "'"
  If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
     
  If blnfactura = True Then
    If ADORS.EOF Then
      kSERIE_FACTURA = "F01"
      sSQL = "INSERT INTO Config_Documento (cTipoDoc,cOperCode,nDocCodigo,cSerieDoc,cUserDesc,dUltAct,observacion) " & _
             " VALUES ('01',0, 0, 'F01','',#" & Date & "#,'Primer Registro') "
      If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
      cDocCodigofull = 1
    Else
      kSERIE_FACTURA = LeerCampo(ADORS!cSerieDoc)
      cDocCodigofull = LeerCampo(ADORS!nDocCodigo) + 1
    End If
    cDocSerie = kSERIE_FACTURA
  Else
    Select Case cdocTipo
      Case "10"
        If ADORS.EOF Then
          KSERIE_PARALELO = "OC1"
          sSQL = "INSERT INTO Config_Documento (cTipoDoc,cOperCode,nDocCodigo,cSerieDoc,cUserDesc,dUltAct,observacion) " & _
                 " VALUES ('10',0, 0, 'OC1','',#" & Date & "#,'Primer Registro') "
          If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
          cDocCodigofull = 1
        Else
          KSERIE_PARALELO = LeerCampo(ADORS!cSerieDoc)
          cDocCodigofull = LeerCampo(ADORS!nDocCodigo) + 1
        End If
        cDocSerie = KSERIE_PARALELO
            
      Case "11"
        If ADORS.EOF Then
          KSERIE_PARALELO = "NC1"
          sSQL = "INSERT INTO Config_Documento (cTipoDoc,cOperCode,nDocCodigo,cSerieDoc,cUserDesc,dUltAct,observacion) " & _
                 " VALUES ('11',0, 0, 'NC1','',#" & Date & "#,'Primer Registro') "
          If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
          cDocCodigofull = 1
        Else
          KSERIE_PARALELO = LeerCampo(ADORS!cSerieDoc)
          cDocCodigofull = LeerCampo(ADORS!nDocCodigo) + 1
        End If
        cDocSerie = KSERIE_PARALELO
            
      Case "12"
        If ADORS.EOF Then
          KSERIE_PARALELO = "PA1"
          sSQL = "INSERT INTO Config_Documento (cTipoDoc,cOperCode,nDocCodigo,cSerieDoc,cUserDesc,dUltAct,observacion) " & _
                 " VALUES ('12',0, 0, 'PA1','',#" & Date & "#,'Primer Registro') "
          If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
          cDocCodigofull = 1
        Else
          KSERIE_PARALELO = LeerCampo(ADORS!cSerieDoc)
          cDocCodigofull = LeerCampo(ADORS!nDocCodigo) + 1
        End If
        cDocSerie = KSERIE_PARALELO
            
      Case "13"
        If ADORS.EOF Then
          KSERIE_PARALELO = "PV1"
          sSQL = "INSERT INTO Config_Documento (cTipoDoc,cOperCode,nDocCodigo,cSerieDoc,cUserDesc,dUltAct,observacion) " & _
                 " VALUES ('13',0, 0, 'PV1','',#" & Date & "#,'Primer Registro') "
          If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
          cDocCodigofull = 1
        Else
          KSERIE_PARALELO = LeerCampo(ADORS!cSerieDoc)
          cDocCodigofull = LeerCampo(ADORS!nDocCodigo) + 1
        End If
        cDocSerie = KSERIE_PARALELO
          
      Case "14"
        If ADORS.EOF Then
          KSERIE_PARALELO = "LQ1"
          sSQL = "INSERT INTO Config_Documento (cTipoDoc,cOperCode,nDocCodigo,cSerieDoc,cUserDesc,dUltAct,observacion) " & _
                 " VALUES ('14',0, 0, 'LQ1','',#" & Date & "#,'Primer Registro') "
          If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
          cDocCodigofull = 1
        Else
          KSERIE_PARALELO = LeerCampo(ADORS!cSerieDoc)
          cDocCodigofull = LeerCampo(ADORS!nDocCodigo) + 1
        End If
        cDocSerie = KSERIE_PARALELO
          
      Case Else
        If ADORS.EOF Then
          kSERIE = "B01"
          sSQL = "INSERT INTO Config_Documento (cTipoDoc,cOperCode,nDocCodigo,cSerieDoc,cUserDesc,dUltAct,observacion)" & _
                 " VALUES ('02',0, 0, 'B01', '', #" & Date & "#,'Primer Registro') "
          If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
          cDocCodigofull = 1
        Else
          kSERIE = LeerCampo(ADORS!cSerieDoc)
          cDocCodigofull = LeerCampo(ADORS!nDocCodigo) + 1
        End If
        cDocSerie = kSERIE
    End Select
  End If
  
  
  
  '------------------Validacion de Numeración Correlativa ----------------------------
  If cdocTipo = "01" Or cdocTipo = "02" Then
    sSQL = "SELECT MAX(cDocCodigo) AS maximo FROM Operacion WHERE cDocTipo = '" & cdocTipo & "'"
  Else
    sSQL = "SELECT MAX(cDocCodigo) AS maximo FROM OperacionParalela WHERE cDocTipo = '" & cdocTipo & "'"
  End If
  If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
  If val(cDocCodigofull) <> val("0" & (ADORS!Maximo) + 1) And val("0" & ADORS!Maximo) > 0 Then
    Dim NameArchivo As String
    Dim archivo
    Dim Texto As String
    Dim fso, MyFile
    Set fso = CreateObject("Scripting.FileSystemObject")
    archivo = "Error_Full_1" & cdocTipo & cDocCodigofull
    If Trim(archivo) = "" Then
      archivo = "textfile"
    End If
    Texto = Texto + "Codigo generado " & cDocCodigofull & Chr(13)
    
    NameArchivo = "C:\Temp\" + Trim(archivo) + ".log"
    Set MyFile = fso.CreateTextFile(NameArchivo, True)
    cDocCodigofull = ("0" & (ADORS!Maximo)) + 1
    Texto = Texto + "Nuevo Codigo " & cDocCodigofull & Chr(13)
    Texto = Texto + CStr(Now)
    MyFile.WriteLine (Texto)
    MsgBox "Ocurrio un error en la numeración, se asignará el " & cDocCodigofull & " al documento "
    MyFile.Close
  End If
  '---------------Actualizando el valor de la numeración ----------------
  sSQL = "UPDATE Config_Documento " & _
         " SET cSerieDoc='" & cDocSerie & "'," & _
         " nDocCodigo=" & cDocCodigofull & " " & _
         " WHERE cTipodoc='" & cdocTipo & "'"
  If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
  '------------------Impresión de Ticket----------------------------
  
  If blnfactura = True Then
    sTexto = sTexto + vbCrLf + " TK NRO: " & kSERIE_FACTURA & "-" & Right("000000" & CStr(cDocCodigofull), 6) & " NS:" & kSERIE_DISCO_DURO
  Else
    Select Case iTipoVenta
      Case 20, 22, 23, 24, 21
        sTexto = sTexto + vbCrLf + " TK NRO: " & KSERIE_PARALELO & "-" & Right("000000" & CStr(cDocCodigofull), 6) & " NS:" & kSERIE_DISCO_DURO1
      Case Else
        sTexto = sTexto + vbCrLf + " TK NRO: " & kSERIE & "-" & Right("000000" & CStr(cDocCodigofull), 6) & " NS:" & kSERIE_DISCO_DURO
    End Select
  End If
  
  'Printer.Print sTexto
  Texto_imprimir = Texto_imprimir + vbCrLf + sTexto
  sTexto = ""
  
  'Cabecera segun tipo de venta
  Select Case iTipoVenta
    Case 2 'Voucher
      sTexto = "VOUCHER"
      sTexto = Right(Space(60) + sTexto, Int(Len(Space(40) + sTexto) / 2)) + vbCrLf
    Case 1, 5 ' EFECTIVO EX Dolares
      If iDolaresEfectivo > 0 Then
        sTexto = "U$(TC: " + Format(CStr(nTipoCambio), "###,##0.00") + ")"
        sTexto = Right(Space(60) + sTexto, Int(Len(Space(40) + sTexto) / 2)) + vbCrLf
      End If
    Case 4 'Anula Productos
      sTexto = "ANULA PROD"
      sTexto = Right(Space(60) + sTexto, Int(Len(Space(40) + sTexto) / 2)) + vbCrLf
    Case 20 'O/C
      sTexto = "O/C"
      sTexto = Right(Space(60) + sTexto, Int(Len(Space(40) + sTexto) / 2)) + vbCrLf
    Case 21 'NC
      sTexto = "N/C"
      sTexto = Right(Space(60) + sTexto, Int(Len(Space(40) + sTexto) / 2)) + vbCrLf
    Case 22 'PADE
      sTexto = "PADE"
      sTexto = Right(Space(60) + sTexto, Int(Len(Space(40) + sTexto) / 2)) + vbCrLf
    Case 23 'PADV
      sTexto = "PADV"
      sTexto = Right(Space(60) + sTexto, Int(Len(Space(40) + sTexto) / 2)) + vbCrLf
    Case 24 'LIQ
      sTexto = "LIQPAD"
      sTexto = Right(Space(60) + sTexto, Int(Len(Space(40) + sTexto) / 2)) + vbCrLf
  End Select
  'Printer.Print sTexto
  Texto_imprimir = Texto_imprimir + vbCrLf + sTexto + vbCrLf
  sTexto = ""
  
  'Ancho de linea = 27
  
  iSubTotal = 0
  If iTipoVenta <> 22 And iTipoVenta <> 23 Then
    iTotal = 0
  End If
  iTotItems = 0
  iTotalDscto = 0
  iServicio = 0
  iPtoItm = 0
  iPtoVta = 0
    
  '<<<<<<<<<<<<<<<<<<<<<<<<<-------------------------------->>>>>>>>>>>>>>>>>>>>>>>>>>>>
  If iTipoVenta = 22 Or iTipoVenta = 23 Or iTipoVenta = 24 Then
    If iTipoVenta = 24 Then
      iTotal = val(Replace(txtPagoAdelantado, ",", ""))
    End If
    
    '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 sProdDesc As String
    Dim nDscto As Double
    Dim sTeclDesc As String
    Dim toti As Double
    Dim isubtotal_1 As Double
    Dim PUnit As Double
    
    If iTipoVenta = 24 Then
      iTotal = 0
      iTotItems = 0
      
      sTexto = sTexto + "Producto         Cant Precio  SubTotal " + vbCrLf
      sTexto = sTexto + "---------------------------------------" + vbCrLf
      
      For i = 1 To lvwTX(1).ListItems.Count
        iOperNC = lvwTX(1).ListItems(i).Text
        sSQL = " SELECT O.cOperCode, O.cProdCode, O.nProdCant, O.nProdPrecUnit, O.nDscto,P.sProdDesc, P.sProdDescCrta," & _
               " O.nProdCant * O.nProdPrecUnit 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(iOperNC)
                'O.nProdCant * O.nProdPrecUnit * (100 - O.nDscto) / 100 As TotalMonto,
        If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
  
        nSubtotal = 0
        sTexto = sTexto + "TX" + CStr(iOperNC) + vbCrLf
        Do While Not ADORS.EOF
          nItems = LeerCampo(ADORS("nProdCant"))
          PUnit = LeerCampo(ADORS("nProdPrecUnit"))
          sProdDescCrta = LeerCampo(ADORS("sProdDescCrta"))
          sProdDesc = LeerCampo(ADORS("sProdDesc"))
          
          nDscto = LeerCampo(ADORS("nDscto"))
          If nDscto > 0 Then
            PUnit = PUnit * nDscto / 100 + PUnit
          End If
                    
          sTexto = sTexto + Left(sProdDescCrta + Space(16), 16) & _
                    " " + Right(Space(4) & CStr(nItems), 4) & _
                    " " + Right(Space(6) & Format(CStr(PUnit), "0.00"), 6) & _
                    " " + Right(Space(9) & Format(CStr(PUnit * nItems), "0.00"), 9) + vbCrLf
          If nDscto < 0 Then
             sTexto = sTexto + Left("*Dscto " + CStr(Abs(nDscto)) + " %" + Space(16), 16) & _
                      " " + Space(11) & _
                      " " + Right(Space(9) & Format(CStr(PUnit * nItems * nDscto / 100), "0.00"), 9) + vbCrLf
             PUnit = PUnit * nDscto / 100 + PUnit
                     
          End If
          nSubtotal = nSubtotal + (PUnit * nItems)
          
          ADORS.MoveNext
          iTotItems = iTotItems + nItems
        Loop
        sTexto = sTexto + Chr(13) + Left(" AV./ITEM" & Space(23), 23) + Right(Space(15) & Format(CStr(nItems), "0.00"), 15) + vbCrLf
        iTotal = iTotal + nSubtotal
      Next
    End If
    '----------------------------
  Else
    
    sTexto = sTexto + "Producto         Cant Precio  SubTotal " + vbCrLf
    sTexto = sTexto + "---------------------------------------" + vbCrLf
    iServicio = 0
    igvf = 0
    For i = 0 To gfax.UpperBound(1)
      If blnfactura = True Then
            
        If (Trim(gfax(i, 13)) = "SI") Then
          iSubTotal = (val(Replace(gfax(i, 6), ",", "")) * val(Replace(gfax(i, 7), ",", "")) + (val(Replace(gfax(i, 6), ",", "")) * val(Replace(gfax(i, 7), ",", "")) * Producto(i).Dscto / 100)) / (1 + kIGV + kPAR_PORCSERV * (IIf(gfax(i, 13) = "SI", 1, 0)) / 100)
          isubtotal_1 = val(Replace(gfax(i, 6), ",", "")) * val(Replace(gfax(i, 7), ",", ""))
          toti = (kPAR_PORCSERV * iSubTotal * IIf(gfax(i, 13) = "SI", 1, 0)) / 100
          IGV_1 = val(Replace(gfax(i, 15), ",", ""))
          iServicio = iServicio + val(Replace(gfax(i, 14), ",", ""))
          PUnit = val(Replace(gfax(i, 7), ",", "")) / (1 + kIGV + kPAR_PORCSERV * (IIf(gfax(i, 13) = "SI", 1, 0)) / 100)
        Else
          iSubTotal = val(Replace(gfax(i, 6), ",", "")) * val(Replace(gfax(i, 7), ",", ""))
          PUnit = val(Replace(gfax(i, 7), ",", ""))
          IGV_1 = val(Replace(gfax(i, 15), ",", ""))
        End If
            
        nDscto = Producto(i).Dscto
                        
        PUnit = val(Replace(gfax(i, 7), ",", ""))
        If nDscto > 0 Then
          PUnit = PUnit * nDscto / 100 + PUnit
        End If
        
        sTexto = sTexto + Left(Producto(i).nombre + Space(16), 16) & _
               " " + Right(Space(4) & CStr(val(Replace(gfax(i, 6), ",", ""))), 4) & _
               " " + Right(Space(6) & Format(CStr(PUnit), "0.00"), 6) & _
               " " + Right(Space(9) & Format(CStr(PUnit * val(Replace(gfax(i, 6), ",", ""))), "0.00"), 9) + vbCrLf
                         
        iTotal = iTotal + iSubTotal
        igvf = igvf + IGV_1
        iTotItems = iTotItems + val(Replace(gfax(i, 6), ",", ""))
        
      Else ' tk boleta de venta
                                                         
        If (Trim(gfax(i, 13)) = "SI") Then
          iSubTotal = (val(Replace(gfax(i, 6), ",", "")) * val(Replace(gfax(i, 7), ",", "")) + (val(Replace(gfax(i, 6), ",", "")) * val(Replace(gfax(i, 7), ",", "")) * Producto(i).Dscto / 100)) / (1 + kIGV + kPAR_PORCSERV * (IIf(gfax(i, 13) = "SI", 1, 0)) / 100)
          isubtotal_1 = val(Replace(gfax(i, 6), ",", "")) * val(Replace(gfax(i, 7), ",", ""))
          toti = (kPAR_PORCSERV * iSubTotal * IIf(gfax(i, 13) = "SI", 1, 0)) / 100
          IGV_1 = isubtotal_1 - iSubTotal - toti
          PUnit = val(Replace(gfax(i, 7), ",", "")) / (1 + kIGV + kPAR_PORCSERV * (IIf(gfax(i, 13) = "SI", 1, 0)) / 100)
        Else
          iSubTotal = val(Replace(gfax(i, 6), ",", "")) * val(Replace(gfax(i, 7), ",", ""))
          PUnit = val(Replace(gfax(i, 7), ",", ""))
          IGV_1 = 0
        End If
            
        nDscto = Producto(i).Dscto
        PUnit = val(Replace(gfax(i, 7), ",", ""))
        If nDscto > 0 Then
          PUnit = PUnit * nDscto / 100 + PUnit
        End If
        
        sTexto = sTexto + Left(Producto(i).nombre + Space(16), 16) & _
               " " + Right(Space(4) & CStr(val(Replace(gfax(i, 6), ",", ""))), 4) & _
               " " + Right(Space(6) & Format(CStr(PUnit), "0.00"), 6) & _
               " " + Right(Space(9) & Format(CStr(PUnit * val(Replace(gfax(i, 6), ",", ""))), "0.00"), 9) + vbCrLf
        
        iServicio = iServicio + val(Replace(gfax(i, 14), ",", ""))
        iTotal = iTotal + iSubTotal
        iTotItems = iTotItems + val(Replace(gfax(i, 6), ",", ""))
      End If
      'Controla el total de puntos por item y por venta
      iPtoItm = 0
      iPtoVta = 0
      IGV_1 = 0
      
      'Descuentos
      nDscto = (Producto(i).Dscto * val(Replace(gfax(i, 7), ",", "")) / 100)
      
      iSubTotalDscto = val(Replace(gfax(i, 6), ",", "")) * val(Replace(gfax(i, 7), ",", "")) + (nDscto / 100 * (val(Replace(gfax(i, 6), ",", "")) * val(Replace(gfax(i, 7), ",", ""))))
      Dim Serv As Double
       
      If Producto(i).Dscto < 0 Then
        sTexto = sTexto + Left("*Dscto " + CStr(Abs(Producto(i).Dscto)) + " %" + Space(16), 16) & _
               " " + Space(11) & _
               " " + Right(Space(9) & Format(CStr(PUnit * val(Replace(gfax(i, 6), ",", "")) * Producto(i).Dscto / 100), "0.00"), 9) + vbCrLf
      End If
            
      iTotalDscto = iTotalDscto + nDscto
        
    Next
  End If

  'Añade el % de servicio al total
    
  sTexto = sTexto + "---------------------------------------"
  Texto_imprimir = Texto_imprimir + vbCrLf + sTexto
  sTexto = ""
  
  'Total segun tipo de venta
  
  Select Case iTipoVenta
    Case 2 'Normal, Voucher
    
        If blnfactura = True Then
            sTexto = Left(" VALOR VTA" + Space(23), 23) + Right(Space(15) + Format(CStr(val(Replace(txtSoles.Text, ",", "")) - igvf - iServicio), "0.00"), 15) + vbCrLf
                       
            sTexto = sTexto + Left(" IGV" + Space(23), 23) + Right(Space(15) + Format(CStr(igvf), "0.00"), 15) + vbCrLf
            If iServicio > 0 Then
                sTexto = sTexto + Left(" SERVICIO" + "(" + kPAR_PORCSERV + " %)" + Space(23), 23) + Right(Space(15) + Format(CStr(iServicio), "0.00"), 15) + vbCrLf
            End If
            sTexto = sTexto + Left(" TOTAL VTA" + Space(23), 23) + Right(Space(15) + Format(CStr(val(Replace(txtSoles.Text, ",", ""))), "0.00"), 15) + vbCrLf + vbCrLf
                        
            toti = val(Replace(txtSoles, ",", ""))
            iTotal = 0
            If rsPagTar.RecordCount > 0 Then
                rsPagTar.MoveFirst
                Do While Not rsPagTar.EOF
                    sTexto = sTexto + Left(" " + rsPagTar.Fields("descrip") + Space(23), 23) + Right(Space(15) + Format(CStr(rsPagTar.Fields("pago")), "0.00"), 15) + vbCrLf
                    toti = toti - rsPagTar.Fields("pago")
                    iTotal = iTotal + rsPagTar.Fields("pago")
                    rsPagTar.MoveNext
                Loop
            End If
            If val(Replace(txtSoles, ",", "")) > iTotal Then
                ivuelto_1 = 0
            Else
                ivuelto_1 = toti - iTotal
            End If
        
        Else
            IGV_1 = (val(Replace(txtSoles.Text, ",", "")) - val(CStr(iTotal)))
            'Validacion
            If Round(IGV_1 + iTotal, 2) <> val(Replace(txtSoles.Text, ",", "")) Then
               MsgBox "Inconsistencia de Datos"
               iTotal = val(Replace(txtSoles.Text, ",", "")) - IGV_1
            End If
                        
            sTexto = Left(" VALOR VTA" + Space(23), 23) + Right(Space(15) + Format(CStr(val(Replace(txtSoles.Text, ",", ""))), "0.00"), 15) + vbCrLf
            
            If iServicio > 0 Then
                sTexto = sTexto + Left(" SERVICIO" + "(" + kPAR_PORCSERV + " %)" + Space(23), 23) + Right(Space(15) + Format(CStr(iServicio), "0.00"), 15) + vbCrLf
            End If
            
            toti = val(Replace(txtSoles.Text, ",", ""))
            
            If rsPagTar.RecordCount > 0 Then
                rsPagTar.MoveFirst
                Do While Not rsPagTar.EOF
                    sTexto = sTexto + Left(" " + rsPagTar.Fields("descrip") + Space(23), 23) + Right(Space(15) + Format(CStr(rsPagTar.Fields("pago")), "0.00"), 15) + vbCrLf
                    toti = toti - rsPagTar.Fields("pago")
                    iTotal = iTotal + rsPagTar.Fields("pago")
                    rsPagTar.MoveNext
                Loop
            End If
            
           
            iTotal = 0
            If val(Replace(txtSoles, ",", "")) > iTotal Then
                ivuelto_1 = 0
            Else
                ivuelto_1 = toti - iTotal
            End If
            
                        
        End If
        If bLiquidaNC = False Then
            If toti > 0 Then
               sTexto = sTexto + Left(" EFECTIVO S/." + Space(23), 23) + Right(Space(15) + Format(CStr(toti), "0.00"), 15) + vbCrLf
            End If
            If ivuelto_1 > 0 Then
               sTexto = sTexto + Left(" VUELTO" + Space(23), 23) + Right(Space(15) + Format(CStr(ivuelto_1), "0.00"), 15) + vbCrLf
            End If
        Else
         If Trim(txtliqefectivosoles.Text) = "" Then txtliqefectivosoles.Text = "0.00"
         If Trim(txtliqefectivodolares.Text) = "" Then txtliqefectivodolares.Text = "0.00"
         If Trim(txtliqpade.Text) = "" Then txtliqpade.Text = "0.00"
         If Trim(txtliqvueltosoles.Text) = "" Then txtliqvueltosoles.Text = "0.00"
         If Trim(ttxliqvueltodolares.Text) = "" Then ttxliqvueltodolares.Text = "0.00"
         
         If CDbl(txtliqefectivosoles.Text) > 0 Then
            sTexto = sTexto + Left(" EFECTIVO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqefectivosoles.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqefectivodolares.Text) > 0 Then
            sTexto = sTexto + Left(" EFECTIVO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqefectivodolares.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqpade.Text) > 0 Then
           sTexto = sTexto + Left(" PADE/PADV" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqpade.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqvueltosoles.Text) <> 0 Then
            sTexto = sTexto + Left(" VUELTO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqvueltosoles.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(ttxliqvueltodolares.Text) <> 0 Then
            sTexto = sTexto + Left(" VUELTO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(ttxliqvueltodolares.Text), "0.00"), 15)
         End If
        End If
       ' Set rsPagTar = Nothing
      
   Case 4 'Anula Productos
      sTexto = Left(" CASH/TL" + Space(23), 23) + Right(Space(15) + Format(CStr(iTotal), "0.00"), 15)
    Case 5, 1 'Efectivo
       If blnfactura = True Then
          sTexto = Left(" VALOR VTA" + Space(23), 23) + Right(Space(15) + Format(CStr(val(Replace(txtSoles.Text, ",", "")) - igvf - iServicio), "0.00"), 15) + vbCrLf
          sTexto = sTexto + Left(" IGV" + Space(23), 23) + Right(Space(15) + Format(CStr(igvf), "0.00"), 15) + vbCrLf
          If iServicio > 0 Then
            sTexto = sTexto + Left(" SERVICIO" + "(" + kPAR_PORCSERV + " %)" + Space(23), 23) + Right(Space(15) + Format(CStr(iServicio), "0.00"), 15) + vbCrLf
          End If
          sTexto = sTexto + Left(" TOTAL VTA" + Space(23), 23) + Right(Space(15) + Format(CStr(val(Replace(txtSoles.Text, ",", ""))), "0.00"), 15) + vbCrLf + vbCrLf
      Else 'adicionado
            sTexto = Left(" VALOR VTA" + Space(23), 23) + Right(Space(15) + Format(CStr(val(Replace(txtSoles.Text, ",", ""))), "0.00"), 15) + vbCrLf
            If iServicio > 0 Then
               sTexto = sTexto + Left(" SERVICIO" + "(" + kPAR_PORCSERV + " %)" + Space(23), 23) + Right(Space(15) + Format(CStr(iServicio), "0.00"), 15) + vbCrLf
            End If
      End If
     If bLiquidaNC = False Then
        If iEfectivo > 0 Then
           sTexto = sTexto + Left(" EFECTIVO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(iEfectivo), "0.00"), 15) + vbCrLf
        End If
        If iDolaresEfectivo > 0 Then
           sTexto = sTexto + Left(" EFECTIVO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(iDolaresEfectivo), "0.00"), 15) + vbCrLf
        End If
        If iVuelto <> 0 Then
           sTexto = sTexto + Left(" VUELTO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(iVuelto), "0.00"), 15) + vbCrLf
        End If
        If iVueltoDolares <> 0 Then
           sTexto = sTexto + Right(" VUELTO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(iVueltoDolares), "0.00"), 15)
        End If
      Else
         If Trim(txtliqefectivosoles.Text) = "" Then txtliqefectivosoles.Text = "0.00"
         If Trim(txtliqefectivodolares.Text) = "" Then txtliqefectivodolares.Text = "0.00"
         If Trim(txtliqpade.Text) = "" Then txtliqpade.Text = "0.00"
         If Trim(txtliqvueltosoles.Text) = "" Then txtliqvueltosoles.Text = "0.00"
         If Trim(ttxliqvueltodolares.Text) = "" Then ttxliqvueltodolares.Text = "0.00"
         
         If piEmitevoucher = 1 Then
            If rsPagTar.RecordCount > 0 Then
                rsPagTar.MoveFirst
               
                Do While Not rsPagTar.EOF
                    sTexto = sTexto + Left(" " + rsPagTar.Fields("descrip") + Space(23), 23) + Right(Space(15) + Format(CStr(rsPagTar.Fields("pago")), "0.00"), 15) + vbCrLf
                    toti = toti - rsPagTar.Fields("pago")
                    iTotal = iTotal + rsPagTar.Fields("pago")
                    rsPagTar.MoveNext
                Loop
            End If
         End If
         
         If CDbl(txtliqefectivosoles.Text) > 0 Then
            sTexto = sTexto + Left(" EFECTIVO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqefectivosoles.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqefectivodolares.Text) > 0 Then
            sTexto = sTexto + Left(" EFECTIVO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqefectivodolares.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqpade.Text) > 0 Then
             sTexto = sTexto + Left(" PADE/PADV" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqpade.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqvueltosoles.Text) <> 0 Then
             sTexto = sTexto + Left(" VUELTO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqvueltosoles.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(ttxliqvueltodolares.Text) <> 0 Then
             sTexto = sTexto + Left(" VUELTO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(ttxliqvueltodolares.Text), "0.00"), 15)
         End If
        End If
    Case 20 'O/C
          
    If bLiquidaNC = False Then
         sTexto = Left(" VALOR VTA" + Space(23), 23) + Right(Space(15) + Format(CStr(txtSoles.Text), "0.00"), 15) + vbCrLf
         If iServicio > 0 Then
             sTexto = sTexto + Left(" SERVICIO" + "(" + kPAR_PORCSERV + " %)" + Space(23), 23) + Right(Space(15) + Format(CStr(iServicio), "0.00"), 15) + vbCrLf
         End If
       
         If iEfectivo > 0 Then
            sTexto = sTexto + Left(" EFECTIVO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtEfectivoSoles.Text), "0.00"), 15) + vbCrLf
         End If
         If iDolaresEfectivo > 0 Then
             sTexto = sTexto + Left(" EFECTIVO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtEfectivoDolares.Text), "0.00"), 15) + vbCrLf
         End If
         If iVuelto <> 0 Then
              sTexto = sTexto + Left(" VUELTO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(iVuelto), "0.00"), 15) + vbCrLf
         End If
         If iVueltoDolares <> 0 Then
             sTexto = sTexto + Left(" VUELTO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(iVueltoDolares), "0.00"), 15)
         End If
     Else
         sTexto = Left(" VALOR VTA" + Space(23), 23) + Right(Space(15) + Format(CStr(txtSoles.Text), "0.00"), 15) + vbCrLf
         If iServicio > 0 Then
             sTexto = sTexto + Left(" SERVICIO" + "(" + kPAR_PORCSERV + " %)" + Space(23), 23) + Right(Space(15) + Format(CStr(iServicio), "0.00"), 15) + vbCrLf
         End If
       
         If CDbl(txtliqefectivosoles.Text) > 0 Then
             sTexto = sTexto + Left(" EFECTIVO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqefectivosoles.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqefectivodolares.Text) > 0 Then
              sTexto = sTexto + Left(" EFECTIVO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqefectivodolares.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqpade.Text) > 0 Then
              sTexto = sTexto + Left(" PADE/PADV" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqpade.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqvueltosoles.Text) <> 0 Then
             sTexto = sTexto + Left(" VUELTO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqvueltosoles.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(ttxliqvueltodolares.Text) <> 0 Then
              sTexto = sTexto + Left(" VUELTO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(ttxliqvueltodolares.Text), "0.00"), 15)
         End If
     
     End If
    Case 21 'N/C
         sTexto = Left(" TOTAL S/." + Space(23), 23) + Right(Space(15) + Format(CStr(txtSoles), "0.00"), 15)
    Case 22 'PADE
      Select Case mon
       Case 2
          sTexto = Left(" CASH/TL" + Space(19), 19) + Right(Space(19) + "US$ " + Format(CStr(iMontoDolares), "0.00"), 19)
       Case Else
          sTexto = Left(" CASH/TL" + Space(19), 19) + Right(Space(19) + "S/. " + Format(CStr(iTotal), "0.00"), 19)
      End Select
      
    Case 23 'PADV
    'jpcb270710
      Select Case mon
       Case 2
        If iTipoVenta = 23 Then
            sTexto = Left(" TARJETA" + Space(19), 19) + Right(Space(19) + "US$ " + Format(CStr(iMontoDolares), "0.00"), 19)
        Else
           sTexto = Left(" CASH/TL" + Space(19), 19) + Right(Space(19) + "US$ " + Format(CStr(iMontoDolares), "0.00"), 19)
        End If
           
       Case Else
        If iTipoVenta = 23 Then
            sTexto = Left(" TARJETA" + Space(19), 19) + Right(Space(19) + "S/. " + Format(CStr(iTotal), "0.00"), 19)
        Else
            sTexto = Left(" CASH/TL" + Space(19), 19) + Right(Space(19) + "S/. " + Format(CStr(iTotal), "0.00"), 19)
        End If
      End Select
      
    Case 24 'LIQPAD
          sTexto = Left(" SUB/TOTL" + Space(23), 23) + Right(Space(15) + Format(CStr(iTotal), "0.00"), 15) + vbCrLf
          sTexto = sTexto + Left(" PADE/PADV" + Space(23), 23) + Right(Space(15) + txtTotalPA.Text, 15) + vbCrLf
          sTexto = sTexto + Left(" TOT-PAGAR" + Space(23), 23) + Right(Space(15) + txtSoles.Text, 15) + vbCrLf
         If iEfectivo > 0 Then
            sTexto = sTexto + Left(" EFECTIVO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(iEfectivo), "0.00"), 15) + vbCrLf
         End If
        If iDolaresEfectivo > 0 Then
           sTexto = sTexto + Left(" EFECTIVO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(iDolaresEfectivo), "0.00"), 15) + vbCrLf
        End If
           
      If piEmitevoucher = 1 Then
         If rsPagTar.RecordCount > 0 Then
            rsPagTar.MoveFirst
               
            Do While Not rsPagTar.EOF
               'sTexto = sTexto + Left(" " + rsPagTar.Fields("descrip") + Space(23), 23) + Right(Space(15) + Format(CStr(rsPagTar.Fields("pago")), "0.00"), 15) + vbCrLf
               sTexto = sTexto + Left(" " + rsPagTar.Fields("descrip") + Space(23), 23) + Right(Space(15) + Format(CStr(rsPagTar.Fields("pago")), "0.00"), 15) + vbCrLf
               toti = toti - rsPagTar.Fields("pago")
               iTotal = iTotal + rsPagTar.Fields("pago")
              rsPagTar.MoveNext
            Loop
         End If
       End If
      If iVuelto <> 0 Then
          sTexto = sTexto + Left(" VUELTO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(iVuelto), "0.00"), 15) + vbCrLf
      End If
      If iVueltoDolares <> 0 Then
          sTexto = sTexto + Left(" VUELTO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(iVueltoDolares), "0.00"), 15)
      End If
           
  End Select
  
  printer.FontSize = 9 '12
  printer.FontBold = True
  Texto_imprimir = Texto_imprimir + vbCrLf + sTexto
  sTexto = ""
  If iTotItems > 0 Then
     sTexto = Left(" ITEM" + Space(23), 23) + Right(Space(15) + Format(CStr(iTotItems), "0.00"), 15)
 End If
  Select Case iTipoVenta
    Case 4 'Anula Productos
      sTexto = sTexto + vbCrLf + "VO-POSTN"
  End Select
  
  Texto_imprimir = Texto_imprimir + vbCrLf + sTexto + vbCrLf
  'Printer.Print sTexto
    
  'Printer.Print " "
  
  sTexto = ""
'
'  sTexto = sTexto + "---------------------------------------" + vbCrLf
'  sTexto = sTexto + Left(" TRANSACCION" + Space(23), 23) + Right(Space(15) + CStr(iCodOper), 15) + vbCrLf
'  sTexto = sTexto + "---------------------------------------" + vbCrLf

 '---Puntos----------
 nImporte = CDbl(Me.txtSoles.Text)
 If nImporte > 0 And sTarjeta <> "" Then
   iPuntos = Int(nImporte / lReglaPuntoImporte) * lReglaPuntoCantidad
 End If
 
 
  If sTarjeta <> "" Then
     'sw 'sw Add 19/06/2009, era solo >>> intPuntosAcumulados = ObtenerPuntosAcumulados(sTarjeta)
     intPuntosAcumulados = ObtenerPuntosAcumulados(sTarjeta, Trim(Me.txtLocal.Text))
     If (intPuntosAcumulados + iPuntos) >= 0 And iPuntos > 0 And intPuntosAcumulados <> -1 Then
         sTexto = sTexto & " UD. ACUMULO: " & iPuntos & " PUNTOS" & vbCrLf
         sTexto = sTexto & " TIENE ACUMULADO: " & IIf(intPuntosAcumulados + iPuntos < 0, "**", intPuntosAcumulados + iPuntos) & " PUNTOS" & vbCrLf & vbCrLf
     End If
  End If
  
 '---Fin Puntos------
  
  sTexto = sTexto + Space(9) + Format(CStr(Now()), "(DDD) DD/MM/YYYY ") + Format(CStr(Now()), "hh:mm") + vbCrLf 'Hora: 6 + 1
  If bAcceso = True Then
    sTexto = sTexto + "       SUPERVISOR: " + txtsupervisor + vbCrLf
  End If
  sTexto = sTexto + Space(3) + Left(psUsuario_Descripcion, 10) + " " 'Usuario: 10 + 1
  sTexto = sTexto + Space(1) + "Cj:" + kPAR_CAJA + " T:" + kPAR_TURNO
  sTexto = sTexto + Space(1) + "v" & App.Major & "." & App.Minor & "." & App.Revision
  sTexto = sTexto + vbCrLf & "         Correlativo: " & ObtenerCorrelativo(p_1)

  Select Case iTipoVenta
 Case 20, 22, 23, 21
 Case 24
     If piEmitevoucher <> 1 Then
        txtliqefectivodolares.Text = IIf(Trim(txtEfectivoDolares.Text) = "", "0.00", txtEfectivoDolares.Text)
        txtliqefectivosoles.Text = IIf(Trim(txtEfectivoSoles.Text) = "", "0.00", txtEfectivoSoles.Text)
        txtliqvueltosoles.Text = IIf(Trim(txtVueltoSoles.Text) = "", "0.00", txtVueltoSoles.Text)
        ttxliqvueltodolares.Text = IIf(Trim(txtVueltoDolares.Text) = "", "0.00", txtVueltoDolares.Text)
     End If
     txtliqpade.Text = IIf(Trim(txtTotalPA.Text) = "", "0.00", txtTotalPA.Text)
     txtLiq.Text = iCodOper
 Case Else
    sTexto = sTexto + vbCrLf + vbCrLf + "   " + kPIE_TICKET
 End Select
  
  printer.FontSize = 8 '11
  printer.FontBold = False
  '-------------segun impresora seleccionada --------
  Texto_imprimir = Texto_imprimir + vbCrLf + sTexto
  
If p_1 = 1 Then
  ConfiguraImpresora kPAR_IMPRESORA
  Select Case KImpresora
     Case 1
         Call CortePapel(Texto_imprimir, p_1, CStr(iCodOper))
     Case 0
         printer.Print Texto_imprimir
         printer.Print " "
         printer.Print " "
         printer.EndDoc
   End Select
Else
   ConfiguraImpresora kPAR_IMPRESORA_ALTERNA
  Select Case KImpresoraALT
     Case 1
          Call CortePapel(Texto_imprimir, p_1)
      Case 0
          printer.Print Texto_imprimir
          printer.Print " "
          printer.Print " "
          printer.EndDoc
    End Select
End If
  

  '-------------------Graba operacion -------------------------
   Select Case iTipoVenta
    Case 20, 21, 22, 23, 24
      If iTipoVenta = 22 Or iTipoVenta = 23 Or iTipoVenta = 24 Then
      Else
        
        iDolaresEfectivo = val(Replace(txtEfectivoDolares, ",", ""))
        iSolesEfectivo = val(Replace(txtEfectivoSoles, ",", ""))
        iTotal = val(Replace(txtSoles, ",", ""))
        iMontoDolares = val(Replace(txtDolares, ",", ""))
        iEfectivo = val(Replace(txtEfectivoSoles, ",", ""))
        iVuelto = val(Replace(Me.txtVueltoSoles, ",", ""))
        If iVuelto < 0 Then iVuelto = 0
        iVueltoDolares = val(Replace(Me.txtVueltoDolares, ",", ""))
        If iVueltoDolares < 0 Then iVueltoDolares = 0
        If iTipoVenta = 21 Then
            iCodOperRela = val(txtTX.Text)
        Else
            'jpcb 17/12/2008
            If iTipoVenta = 20 And Trim(txtLiq.Text) <> "" Then
            Else
                iCodOperRela = 0
            End If
        End If
      End If
          
      '------------------Validacion de Numeración Correlativa -------------------------//
      If cdocTipo = "01" Or cdocTipo = "02" Then
         sSQL = "SELECT MAX(cDocCodigo) AS maximo FROM Operacion WHERE cDocTipo = '" & cdocTipo & "'"
      Else
         sSQL = "SELECT MAX(cDocCodigo) AS maximo FROM OperacionParalela WHERE cDocTipo = '" & cdocTipo & "'"
      End If
      If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
    If cDocCodigofull <> ((ADORS!Maximo) + 1) And val("0" & ADORS!Maximo) > 0 Then
      Set fso = CreateObject("Scripting.FileSystemObject")
      archivo = "Error_Full2" & cdocTipo & cDocCodigofull
      If Trim(archivo) = "" Then
          archivo = "textfile"
      End If
      Texto = Texto + "Codigo generado " & cDocCodigofull & Chr(13)
      
      NameArchivo = "C:\Temp\" + Trim(archivo) + ".log"
      Set MyFile = fso.CreateTextFile(NameArchivo, True)
      cDocCodigofull = ("0" & (ADORS!Maximo)) + 1
      Texto = Texto + "Nuevo Codigo " & cDocCodigofull & Chr(13)
      Texto = Texto + CStr(Now)
      MyFile.WriteLine (Texto)
      MsgBox "Ocurrio un error en la numeración, se asignará el " & cDocCodigofull & " al documento "
      MyFile.Close
    End If
    
    '---------------Actualizando el valor de la numeración --------------------------------//
    sSQL = "UPDATE Config_Documento " & _
          " SET cOperCode=" & CStr(iCodOper) & "," & _
          " nDocCodigo=" & cDocCodigofull & ", " & _
          " cUserDesc='" & psUsuario_Descripcion & "' " & _
          " WHERE cTipodoc='" & cdocTipo & "'"
    If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
    
    '------------------fin Validacion de Numeración Correlativa -----------------------
      
     If iTipoVenta = 23 Then
     '170810 VALIDA EL ERROR DE DUPLICIDAD DE PADV  (por error se graba otro registro inmediatamente e igual que el anterior)
             
            sSQL = "SELECT dOperFech,nTarjNumb,nMoneda,nMontoSoles,nMontoDolares,nEfectivoSoles,sGlosa FROM OPERACIONPARALELA WHERE cOperCode=" & iCodOper - 1 & ""
            
            If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
            
            If Format(ADORS!dOperFech, "DD/MM/YYYY hh:mm") = sFecha And ADORS!nTarjNumb = sTarjeta And ADORS!nMoneda = CStr(mon) And _
                ADORS!nMontoSoles = iTotal And ADORS!nMontoDolares = iMontoDolares And _
                 ADORS!nEfectivoSoles = iEfectivo And ADORS!sGlosa = txtGlosa Then
                
                
                sSQL = "UPDATE Config_Documento " & _
                      " SET cOperCode=" & CStr(iCodOper - 1) & "," & _
                      " nDocCodigo=" & cDocCodigofull - 1 & ", " & _
                      " cUserDesc='" & psUsuario_Descripcion & "' " & _
                      " WHERE cTipodoc='" & cdocTipo & "'"
                If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
                
                GoTo Salir
                
            Else
      
                    sSQL = " INSERT INTO OPERACIONPARALELA (cOperCode, cOperTipo, dOperFech, nTarjNumb," & _
                           " nMoneda, nMontoSoles, nMontoDolares, nEfectivoSoles, nVueltoSoles, sGlosa," & _
                           " cEstado, cCajaCodi, cFlagSincronizacion, cTurnoCodi, cUserDesc, cOpercodeRela, " & _
                           " nEfectivoDolares, nVueltoDolares, cDocSerie, cDocCodigo, cDocTipo ) " & _
                           " VALUES" + _
                           " ($, $, '$', '$', $, $, $, $, $, '$', '$', '$', '$', '$', '$', $ ,$ ,$,'$',$,'$')"
                    sSQL = VBsprintf(sSQL, CStr(iCodOper), CStr(iTipoVenta), sFecha, sTarjeta, CStr(mon), CStr(iTotal), _
                                           CStr(iMontoDolares), CStr(iEfectivo), CStr(iVuelto), txtGlosa, CStr(1), _
                                           kPAR_CAJA, CStr(0), kPAR_TURNO, psUsuario_Descripcion, CStr(iCodOperRela), _
                                           CStr(iDolaresEfectivo), CStr(iVueltoDolares), KSERIE_PARALELO, cDocCodigofull, cdocTipo)
                    If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
                    
            End If
        
     Else
            sSQL = " INSERT INTO OPERACIONPARALELA (cOperCode, cOperTipo, dOperFech, nTarjNumb," & _
                   " nMoneda, nMontoSoles, nMontoDolares, nEfectivoSoles, nVueltoSoles, sGlosa," & _
                   " cEstado, cCajaCodi, cFlagSincronizacion, cTurnoCodi, cUserDesc, cOpercodeRela, " & _
                   " nEfectivoDolares, nVueltoDolares, cDocSerie, cDocCodigo, cDocTipo ) " & _
                   " VALUES" + _
                   " ($, $, '$', '$', $, $, $, $, $, '$', '$', '$', '$', '$', '$', $ ,$ ,$,'$',$,'$')"
            sSQL = VBsprintf(sSQL, CStr(iCodOper), CStr(iTipoVenta), sFecha, sTarjeta, CStr(mon), CStr(iTotal), _
                                   CStr(iMontoDolares), CStr(iEfectivo), CStr(iVuelto), txtGlosa, CStr(1), _
                                   kPAR_CAJA, CStr(0), kPAR_TURNO, psUsuario_Descripcion, CStr(iCodOperRela), _
                                   CStr(iDolaresEfectivo), CStr(iVueltoDolares), KSERIE_PARALELO, cDocCodigofull, cdocTipo)
            If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
      End If
               
               
      
      nImporte = 0
      nPtosImp = 0
      nPuntos = 0

      For i = 0 To nProducto
        'TDBGrid1.Row = i
        sSQL = " INSERT INTO OPERACIONPARALELAPRODUCTO (cAlmaCode, cOperCode, cProdCode, nProdCant," & _
               " nProdPrecUnit, nDscto, nServicio)" & _
               " VALUES" + _
               " ('$', $, $, $, $, $,$)"
        sSQL = VBsprintf(sSQL, kPAR_ALMACEN, CStr(iCodOper), CStr(Producto(i).Codigo), CStr(Abs(val(Replace(gfax(i, 6), ",", "")))), _
                         CStr(val(Replace(gfax(i, 7), ",", ""))), CStr(Producto(i).Dscto), IIf(gfax(i, 13) = "SI", kPAR_PORCSERV, "0"))
        If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
        
  
      Next
      Dim CodLiq As Long
      If iTipoVenta = 1 Or _
         iTipoVenta = 20 And (iDolaresEfectivo > 0 Or iSolesEfectivo > 0) Or _
         iTipoVenta = 5 And (iDolaresEfectivo > 0 Or iSolesEfectivo > 0) Or _
         iTipoVenta = 24 And (iDolaresEfectivo > 0 Or iSolesEfectivo > 0) Then
         Dim iCodTipo As Long
         If iTipoVenta = 24 Then
         txtLiq.Text = iCodOper
         End If
         
         If bLiquidaNC = False Then
            If piEmitevoucher = 1 And iEfectivo = 0 Then
              iCodTipo = 2
            Else
              iCodTipo = 1
            End If
            CodLiq = 0
            
         Else
            iCodTipo = 3
            CodLiq = val(txtLiq.Text)
         End If
        '---primera
           If iDolaresEfectivo <= 0 And iEfectivo <= 0 Then iEfectivo = Replace(txtSoles, ",", "")
           
           sSQL = " INSERT INTO OPERACION (cOperCode, cUserDesc, nTarjNumb, cProdCode, nProdCant, nProdPrecUnit," & _
               " nMontoDolares, dOperFech, cOperTipo, cCajaCodi, cTurnoCodi, nmontosoles, nVueltoDolares,  cDocSerie, cDoccodigo, cdocTipo, cOpercodeAnula, IdLocal) " + _
               " VALUES" + _
               " ($, '$', '$', $, $, $, $, '$', $, '$', '$',$ ,$, '$', $, '$', $, $)"
           sSQL = VBsprintf(sSQL, CStr(iCodOper), psUsuario_Descripcion, sTarjeta, CStr(0), CStr(1), _
                           CStr(-1 * iVuelto), CStr(iDolaresEfectivo), sFecha, CStr(iCodTipo), kPAR_CAJA, kPAR_TURNO, CStr(iEfectivo), CStr(iVueltoDolares), cDocSerie, cDocCodigofull, cdocTipo, CodLiq, idLocal)

        If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
        iVuelto = val(Replace(txtVueltoSoles, ",", ""))
        If iVuelto < 0 Then iVuelto = 0
      End If
      
      
      nImporte = CDbl(Me.txtSoles.Text)
      nPuntos = 0
      '--------------------------Inserta linea voucher liq------------------------------------
      Dim importevoucher As Double
      
      If piEmitevoucher = 1 Then
         importevoucher = nImporte - iEfectivo + iVuelto
         sSQL = " INSERT INTO OPERACION (cOperCode, cUserDesc, nTarjNumb, cProdCode, nProdCant, nProdPrecUnit," & _
               " nMontoDolares, dOperFech, cOperTipo, cCajaCodi, cTurnoCodi, nmontosoles, nVueltoDolares,  cDocSerie, cDoccodigo, cdocTipo, cOpercodeAnula, cemisor, IdLocal) " + _
               " VALUES" + _
               " ($, '$', '$', $, $, $, $, '$', $, '$', '$',$ ,$, '$', $, '$', $, '$', $)"
         sSQL = VBsprintf(sSQL, CStr(iCodOper), psUsuario_Descripcion, sTarjeta, CStr(0), CStr(1), _
                           0, 0, sFecha, 2, kPAR_CAJA, kPAR_TURNO, CStr(importevoucher), 0, cDocSerie, cDocCodigofull, cdocTipo, CodLiq, cEmisor, idLocal)
         If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
                          
      End If
      
      '-----------------------------------------------------------------------------
       
      'ACTUALIZA PUNTOS
      '----------------
      If nImporte > 0 And sTarjeta <> "" Then
        Call Guarda_Puntos(sTarjeta, "VNTA", cdocTipo, cDocSerie, cDocCodigofull, nImporte, , nIdClienteLocal)
        iPuntos = Int(nImporte / lReglaPuntoImporte) * lReglaPuntoCantidad
      End If
      If nPuntos > 0 And sTarjeta <> "" Then
        Call Guarda_Puntos(sTarjeta, "PTOS", cdocTipo, cDocSerie, cDocCodigofull, nPuntos, nPtosImp, nIdClienteLocal)
      End If
      '----------------
      
      If iTipoVenta = 24 Then
        sSQL = " UPDATE OPERACIONPARALELA" & _
               " SET cEstado = 2" + _
               " WHERE cOperCode = $"
        sSQL = VBsprintf(sSQL, CStr(iCodOper))
        If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
                
        For i = 1 To lvwTX(0).ListItems.Count
          iCodOperRela = val(lvwTX(0).ListItems(i).Text)
          sSQL = " UPDATE OPERACIONPARALELA" & _
                 " SET cOpercodeRela = $," & _
                 " cEstado = 2" + _
                 " WHERE cOperCode = $"
          sSQL = VBsprintf(sSQL, CStr(iCodOper), CStr(iCodOperRela))
          If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
        Next
        
        For i = 1 To lvwTX(1).ListItems.Count
          iCodOperRela = val(lvwTX(1).ListItems(i).Text)
          sSQL = " UPDATE OPERACIONPARALELA" & _
                 " SET cOpercodeRela = $," & _
                 " cEstado = 2" + _
                 " WHERE cOperCode = $" ' AND cOperCodeRela = 0"
          sSQL = VBsprintf(sSQL, CStr(iCodOper), CStr(iCodOperRela))
          If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
        Next
      End If
  
      
    Case Else
      
      nImporte = 0
      nPtosImp = 0
      nPuntos = 0
      If rsPagTar.state = adStateOpen Then
      If rsPagTar.RecordCount > 0 Then
        rsPagTar.MoveFirst
        Do While Not rsPagTar.EOF
            cEmisor = cEmisor + "," + rsPagTar.Fields("cod_tar")
            rsPagTar.MoveNext
        Loop
      End If
      End If
      
  '------------------Validacion de Numeración Correlativa -------------------------//
  sSQL = "SELECT MAX(cDocCodigo) AS maximo FROM Operacion WHERE cDocTipo = '" & cdocTipo & "'"
         If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
         
  If cDocCodigofull <> ((ADORS!Maximo) + 1) And val("0" & ADORS!Maximo) > 0 Then
    Set fso = CreateObject("Scripting.FileSystemObject")
    archivo = "Error_Full2" & cdocTipo & cDocCodigofull
    If Trim(archivo) = "" Then
        archivo = "textfile"
    End If
    Texto = Texto + "Codigo generado " & cDocCodigofull & Chr(13)
    
    NameArchivo = "C:\Temp\" + Trim(archivo) + ".log"
    Set MyFile = fso.CreateTextFile(NameArchivo, True)
    cDocCodigofull = ("0" & (ADORS!Maximo)) + 1
    Texto = Texto + "Nuevo Codigo " & cDocCodigofull & Chr(13)
    Texto = Texto + CStr(Now)
    MyFile.WriteLine (Texto)
    MsgBox "Ocurrio un error en la numeración, se asignará el " & cDocCodigofull & " al documento "
  End If
  
  '---------------Actualizando el valor de la numeración --------------------------------//
  sSQL = "UPDATE Config_Documento " & _
        " SET cOperCode=" & CStr(iCodOper) & "," & _
        " cUserDesc='" & psUsuario_Descripcion & "' " & _
        " WHERE cTipodoc='" & cdocTipo & "'"
  If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
  
  '------------------fin Validacion de Numeración Correlativa ---------------------------//
          
      For i = 0 To gfax.UpperBound(1)
         'TDBGrid1.Row = i
         If bLiquidaNC Then iFlagTipo = 3
         
         If iFlagTipo = 3 Then
            CodLiq = val(txtLiq.Text)
         Else
            CodLiq = 0
         End If
         sSQL = " INSERT INTO OPERACION (cOperCode, cUserDesc, nTarjNumb, cAlmaCode, cProdCode, nProdCant, nProdPrecUnit," & _
                " nMontoDolares, dOperFech, cOperTipo, cCajaCodi, cTurnoCodi, nDscto, nServicio, cDocCodigo, cRuc, cDocSerie, cDocTipo, cEmisor, cOpercodeanula, idLocal) " + _
                " VALUES" + _
                " ($, '$', '$', '$', $, $, $, $, '$', $, '$', '$', $, $, $, '$', '$', '$', '$', $, $)"
         
         sSQL = VBsprintf(sSQL, CStr(iCodOper), psUsuario_Descripcion, sTarjeta, kPAR_ALMACEN, CStr(Producto(i).Codigo), CStr(val(Replace(gfax(i, 6), ",", "") * iSigno)), _
                CStr(val(Replace(gfax(i, 7), ",", ""))), CStr(0), sFecha, CStr(iFlagTipo), kPAR_CAJA, kPAR_TURNO, CStr(Producto(i).Dscto), IIf(gfax(i, 13) = "SI", kPAR_PORCSERV, "0"), cDocCodigofull, cRuc, cDocSerie, cdocTipo, cEmisor, CodLiq, idLocal)
               
         If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
         iEfectivo = val(Replace(txtEfectivoSoles, ",", ""))
         iVuelto = val(Replace(txtVueltoSoles, ",", ""))
         If iVuelto < 0 Then iVuelto = 0
    
      Next
       
      nImporte = CDbl(Me.txtSoles.Text)
      nPuntos = 0
         
      iVuelto = val(Replace(txtVueltoSoles, ",", ""))
      iDolaresEfectivo = val(Replace(txtEfectivoDolares, ",", ""))
      iSolesEfectivo = val(Replace(txtEfectivoSoles, ",", ""))
      iVueltoDolares = val(Replace(Me.txtVueltoDolares, ",", ""))
      If iVuelto < 0 Then iVuelto = 0
      If iVueltoDolares < 0 Then iVueltoDolares = 0
      'ACTUALIZA PUNTOS
      '----------------
      If Not blLiquidaVenta Then
        If nImporte > 0 And sTarjeta <> "" Then
          Call Guarda_Puntos(sTarjeta, "VNTA", cdocTipo, cDocSerie, cDocCodigofull, nImporte, , nIdClienteLocal)
          iPuntos = Int(nImporte / lReglaPuntoImporte) * lReglaPuntoCantidad
        End If
        If nPuntos > 0 And sTarjeta <> "" Then
          Call Guarda_Puntos(sTarjeta, "PTOS", cdocTipo, cDocSerie, cDocCodigofull, nPuntos, nPtosImp, nIdClienteLocal)
        End If
    
      End If
      '---------------
      
      If iTipoVenta = 1 And (iDolaresEfectivo > 0 Or iSolesEfectivo > 0) Or _
         iTipoVenta = 20 And (iDolaresEfectivo > 0 Or iSolesEfectivo > 0) Or _
         iTipoVenta = 5 And (iDolaresEfectivo > 0 Or iSolesEfectivo > 0) Or _
         iTipoVenta = 3 And (iDolaresEfectivo > 0 Or iSolesEfectivo > 0) Or _
         iTipoVenta = 24 And (iDolaresEfectivo > 0 Or iSolesEfectivo > 0) Or _
         (iTipoVenta = 2 And (iDolaresEfectivo > 0 Or iSolesEfectivo > 0)) Then
        '-----segunda
         If bLiquidaNC = False Then
            iCodTipo = 1
            CodLiq = 0
         Else
            iCodTipo = 3
            CodLiq = val(txtLiq.Text)
         End If
        
            sSQL = " INSERT INTO OPERACION (cOperCode, cUserDesc, nTarjNumb, cProdCode, nProdCant, nProdPrecUnit," & _
                   " nMontoDolares, dOperFech, cOperTipo, cCajaCodi, cTurnoCodi,nmontosoles, nVueltoDolares, cDocCodigo, cRuc, cDocSerie, cDocTipo,cEmisor, cOpercodeAnula, IdLocal) " + _
                   " VALUES" + _
                   " ($, '$', '$', $, $, $, $, '$', $, '$', '$',$ ,$, $, '$', '$', '$', '$', $, $)"
            sSQL = VBsprintf(sSQL, CStr(iCodOper), psUsuario_Descripcion, sTarjeta, CStr(0), CStr(1), _
                               CStr(-1 * iVuelto), CStr(iDolaresEfectivo), sFecha, CStr(iCodTipo), kPAR_CAJA, kPAR_TURNO, CStr(iSolesEfectivo), CStr(iVueltoDolares), CStr(cDocCodigofull), cRuc, cDocSerie, cdocTipo, cEmisor, CodLiq, idLocal)
    
     If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
        iVuelto = val(Replace(txtVueltoSoles, ",", ""))
        If iVuelto < 0 Then iVuelto = 0
    End If
            
  End Select
   
  
  bLiquidaNC = False
  '-------------------Fin Graba operacion -------------------------
  
  
  
  
  
  
  



  GoTo Salir
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  Screen.MousePointer = vbDefault

Salir:
  Set ADORS = Nothing
  If piEmitevoucher <> 1 Then
    Set rsPagTar = Nothing
  End If
End Sub
Private Sub RegistrarVenta()

Dim cnSQL As ADODB.Connection
Dim ADORS As ADODB.Recordset
Dim ADORS1 As ADODB.Recordset
Dim sSQL As String
Dim blnfactura As Boolean
Dim cDocSerie As String
Dim cdocTipo As String
Dim iCodOper As Long
Dim cRuc As String
Dim cDocCodigofull As Long
Dim iTotal, iTotalVenta As Double, iSubTotal As Double, iSubTotalDscto As Double
Dim iIGV As Double
Dim i As Integer
Dim iTipoVenta As Integer
Dim sTexto As String
Dim sTarjeta As String


Dim rs1 As Recordset
Dim p_1 As Integer
Dim impr_1 As String
Dim impr_2 As String
Dim nImporte As Double, iServicio, nPuntos As Double, nPtosImp As Double
Dim iPtoVta, iPtoItm As Double, iPagoAdelantado As Double
Dim blLiquidaVenta As Boolean
Dim Texto_imprimir As String
Dim iPuntos As Long
Dim sssql As String
Dim iMoneda As Integer
Dim smoneda As String
Dim bAfectoDetraccion As Boolean



On Error GoTo Salir

iTipoVenta = cboTipoDocumento.ListIndex
iMoneda = cboMoneda.ListIndex

bAfectoDetraccion = False

If iTipoVenta = -1 Then
    Exit Sub
ElseIf iTipoVenta = 0 Then
    blnfactura = True
    cRuc = Trim(Me.txtRUC.Text)
    cdocTipo = "01"
    cDocSerie = kSERIE_FACTURA
ElseIf iTipoVenta = 1 Then
    blnfactura = False
    cRuc = ""
    cdocTipo = "02"
    cDocSerie = kSERIE
End If

If iMoneda = -1 Then
    Exit Sub
ElseIf iMoneda = 0 Then
    smoneda = "N"
ElseIf iMoneda = 1 Then
    smoneda = "E"
End If
  

ConfiguraImpresora kPAR_IMPRESORA_ALTERNA


  'Verifica si es un tipo de operaciòn que necesita password: Anulación o Descuento
  For i = gfax.LowerBound(1) To gfax.UpperBound(1)
    sTexto = IIf(Replace(gfax(i, 9), ",", "") = "", "0", Replace(gfax(i, 9), ",", ""))
    If val(sTexto) <> 0 Then
      bAcceso = True
      Exit For
    End If
  Next
  
  If bAcceso Then
    bAcceso = False
    Load frmAutorizarOperacion
    Set frmAutorizarOperacion.frmPadre = Me
    frmAutorizarOperacion.Show vbModal
    If Not bAcceso Then Exit Sub
    'bAcceso = False
  End If
  

  'sSQL = "SELECT sImpresora, sImpresoraAlterna from Configuracion"
  'If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, rs1) Then GoTo Salir--->ACCESS
  
  If Not oDBAdmin.AbrirBD(cnSQL, psConnectString) Then GoTo Salir 'OMNISYS
  
  'If Not oDBAdmin.AbrirBD(cnSQL, psCadenaConexionSQLServer) Then GoTo Salir 'OMNICLIENT
  
  cnSQL.BeginTrans
  ADOCnn.BeginTrans
  
  sSQL = "SELECT isnull(max(CAST(cCodVta AS INT)),0) as maximo FROM venta01" '-->operacion paralela


  
  If Not oDBAdmin.EjecutarConsulta(cnSQL, 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
  
  'Inicializa Recorset
  If iTipoVenta <> 2 And piEmitevoucher <> 1 Then
    Set rsPagTar = New Recordset
  End If
  
  
  '------------------------
  '-- Captura Parámetros --
  '------------------------
  Texto_imprimir = ""
  Call CabeceraImpresion
  sTexto = ""
  
  sssql = "SELECT sImpresora, sImpresoraAlterna from Configuracion"
  If Not oDBAdmin.EjecutarConsulta(ADOCnn, sssql, rs1) Then GoTo Salir
  impr_1 = rs1.Fields("sImpresora")
  impr_2 = rs1.Fields("sImpresoraAlterna")
  
  'Pregunta si x.Devicename tiene el mismo nombre que el nombre de la impresora por donde necesitas sacar la impresion.
'  If iTipoVenta = 1 Or iTipoVenta = 2 Or iTipoVenta = 5 Then
    p_1 = 1
'  Else
'    p_1 = 2
'  End If
  
  printer.FontSize = 8 '11
  printer.FontName = "Courier New"
  
  Select Case iTipoVenta
    Case 20, 21, 22, 23, 24
    Case Else
      For i = 0 To UBound(sCabecera) - 1
        If Not Trim(sCabecera(i)) = "" Then
          sTexto = sTexto + Right(Space(60) + sCabecera(i), Int(Len(Space(40) + sCabecera(i)) / 2)) + vbCrLf
        End If
      Next
  End Select
  
  'Linea de Datos del Socio
  If Not sTarjeta = "" Then
    sTexto = sTexto + vbCrLf + " COD.TARJ.: " + sTarjeta + " "
    If Not blnfactura = True Then
      sTexto = sTexto + vbCrLf + " NOMBRE: " + txtNombres.Text + vbCrLf
    End If
  Else
    If Not blnfactura = True And Not Trim(txtNombres.Text) = "" Then
      sTexto = sTexto + vbCrLf + " NOMBRE: " + UCase(Trim(txtNombres.Text)) + vbCrLf
    End If
  End If
  
  If blnfactura = True Then
    sTexto = sTexto + vbCrLf + " NOMBRE: " & "____________________________"
    sTexto = sTexto + vbCrLf + vbCrLf + "         " & "____________________________" + vbCrLf
    sTexto = sTexto + vbCrLf + " RUC Cliente: " & Trim(Me.txtRUC.Text) + vbCrLf
  End If
  
  
  
  ' Obteniendo Nro de documento
  'sSQL = "SELECT  * FROM Config_Documento WHERE cTipoDoc='" & cdocTipo & "'"
  sSQL = "SELECT  * FROM Config_Documento WHERE cTipoDoc='" & IIf(cdocTipo = "01", "02", cdocTipo) & "'"
  If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
     
  If blnfactura = True Then
    If ADORS.EOF Then
      'kSERIE_FACTURA = "F01"
      kSERIE_FACTURA = Right("00" & Right(kPAR_CAJA, 2), 3)
      sSQL = "INSERT INTO Config_Documento (cTipoDoc,cOperCode,nDocCodigo,cSerieDoc,cUserDesc,dUltAct,observacion) " & _
             " VALUES ('01',0, 0, 'F01','',#" & Date & "#,'Primer Registro') "
      If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
      cDocCodigofull = 1
    Else
      kSERIE_FACTURA = LeerCampo(ADORS!cSerieDoc)
      cDocCodigofull = LeerCampo(ADORS!nDocCodigo) + 1
    End If
    cDocSerie = kSERIE_FACTURA
  Else
        If ADORS.EOF Then
          'kSERIE = "B01"
          kSERIE = Right("00" & Right(kPAR_CAJA, 2), 3)
          sSQL = "INSERT INTO Config_Documento (cTipoDoc,cOperCode,nDocCodigo,cSerieDoc,cUserDesc,dUltAct,observacion)" & _
                 " VALUES ('02',0, 0, 'B01', '', #" & Date & "#,'Primer Registro') "
          If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
          cDocCodigofull = 1
        Else
          kSERIE = LeerCampo(ADORS!cSerieDoc)
          cDocCodigofull = LeerCampo(ADORS!nDocCodigo) + 1
        End If
        cDocSerie = kSERIE
  End If
  
  
  
  '------------------Validacion de Numeración Correlativa ----------------------------
' aca se tendria que primero determinar cual es mayor el valor del access o el sql
    Dim nValorAccess As Long
    Dim nValorSQL As Long
    Dim nValorMaximo As Long
  'sSQL = "select isnull(max(cast(NroDoc as int)),0) as maximo from venta01 WHERE TipoDoc = '" & cdocTipo & "'"
  
  
  sSQL = "select isnull(max(cast(NroDoc as int)),0) as maximo from venta01 WHERE TipoDoc = '" & IIf(cdocTipo = "01", "02", cdocTipo) & "'"
  If Not oDBAdmin.EjecutarConsulta(ADOCnnSQL, sSQL, ADORS) Then GoTo Salir
  nValorSQL = ADORS!Maximo
  
  'sSQL = "SELECT MAX(cDocCodigo) AS maximo FROM Operacion WHERE cDocTipo = '" & cdocTipo & "'"
  sSQL = "SELECT MAX(cDocCodigo) AS maximo FROM Operacion WHERE cDocTipo in ('01','02')"
  If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS1) Then GoTo Salir
  nValorAccess = ADORS1!Maximo

    
  If nValorAccess > nValorSQL Then
     nValorMaximo = nValorAccess
  Else
     nValorMaximo = nValorSQL
  End If
  
  
  
  'sSQL = "select isnull(max(cast(NroDoc as int)),0) as maximo from venta01 WHERE TipoDoc = '" & cdocTipo & "'"
  'If Not oDBAdmin.EjecutarConsulta(ADOCnnSQL, sSQL, ADORS) Then GoTo Salir
  
  If val(cDocCodigofull) <> val("0" & (nValorMaximo) + 1) And val("0" & nValorMaximo) > 0 Then
    Dim NameArchivo As String
    Dim archivo
    Dim Texto As String
    Dim fso, MyFile
    Set fso = CreateObject("Scripting.FileSystemObject")
    archivo = "Error_Full_1" & cdocTipo & cDocCodigofull
    If Trim(archivo) = "" Then
      archivo = "textfile"
    End If
    Texto = Texto + "Codigo generado " & cDocCodigofull & Chr(13)
    
    NameArchivo = "C:\Temp\" + Trim(archivo) + ".log"
    Set MyFile = fso.CreateTextFile(NameArchivo, True)
    cDocCodigofull = ("0" & (nValorMaximo)) + 1
    Texto = Texto + "Nuevo Codigo " & cDocCodigofull & Chr(13)
    Texto = Texto + CStr(Now)
    MyFile.WriteLine (Texto)
    MsgBox "Ocurrio un error en la numeración, se asignará el " & cDocCodigofull & " al documento "
    MyFile.Close
  End If
  
  
  '---------------Actualizando el valor de la numeración ----------------
  sSQL = "UPDATE Config_Documento " & _
         " SET cSerieDoc='" & cDocSerie & "'," & _
         " nDocCodigo=" & cDocCodigofull & " " & _
         " WHERE cTipodoc='" & IIf(cdocTipo = "01", "02", cdocTipo) & "'"
  If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
  

iTotal = val(Replace(txtSoles, ",", ""))
iMontoDolares = val(Replace(txtDolares, ",", ""))
iMontoSoles = iTotal
iIGV = Round(nTotIGV, 2)
'--------------------------------------------------------
    ReDim Producto(gfax.UpperBound(1))
    
    For i = gfax.LowerBound(1) To gfax.UpperBound(1)
      Producto(i).Almacen = kPAR_ALMACEN
      Producto(i).Cant = Replace(gfax(i, 6), ",", "")
      Producto(i).PUnit = Replace(gfax(i, 7), ",", "")
      Producto(i).Codigo = gfax(i, 1)
      Producto(i).nombre = gfax(i, 3)
      If gfax(i, 8) = "+" Then
        Producto(i).Dscto = Replace(IIf(gfax(i, 9) = "", 0, gfax(i, 9)), ",", "")
      Else
        Producto(i).Dscto = -1 * Replace(IIf(gfax(i, 9) = "", 0, gfax(i, 9)), ",", "")
      End If
      
      Producto(i).Canje = gfax(i, 11)
      Producto(i).Ptos = val(Replace(gfax(i, 12), ",", ""))
      Producto(i).Serv = gfax(i, 13)
    Next
    nProducto = gfax.UpperBound(1)
  
    For i = 0 To UBound(Producto)
        If RetornarAfectoDetraccion(Producto(i).Codigo) = True Then
            bAfectoDetraccion = True
            Exit For
        End If
    Next
    
    If bAfectoDetraccion = True Then
        
        If cdocTipo = "01" And val(txtSoles) > RetornarMontoDetracc Then
            Dim nPorcDetracc As Double
            Dim sNroCtaBN As String
            Dim nMontoDetracc As Double
            
            
            nPorcDetracc = RetornarPorcDetracc
            sNroCtaBN = RetornarNroCtaBN
            nMontoDetracc = val(txtSoles) * (nPorcDetracc / 100)
            
        Else
            bAfectoDetraccion = False
        End If
    End If
  
  
    If Trim(txtTarjeta.Text) <> "" Then
      sTarjeta = Right("00000000" + Trim(txtTarjeta.Text), 8)
    Else
      sTarjeta = ""
    End If


  '------------------Impresión de Ticket----------------------------
  
  If blnfactura = True Then
        sTexto = sTexto + vbCrLf + " TK NRO: " & kSERIE_FACTURA & "-" & Right("000000" & CStr(cDocCodigofull), 6) & " NS:" & kSERIE_DISCO_DURO
  Else

        sTexto = sTexto + vbCrLf + " TK NRO: " & kSERIE & "-" & Right("000000" & CStr(cDocCodigofull), 6) & " NS:" & kSERIE_DISCO_DURO

  End If
  
  'Printer.Print sTexto
  Texto_imprimir = Texto_imprimir + vbCrLf + sTexto
  sTexto = ""
  
  'Cabecera segun tipo de venta
  Select Case iTipoVenta
    Case 0
      If smoneda = "E" Then
        sTexto = "U$(TC: " + Format(CStr(nTipoCambio), "###,##0.00") + ")"
        sTexto = Right(Space(60) + sTexto, Int(Len(Space(40) + sTexto) / 2)) + vbCrLf
      End If
    Case 2 'Voucher
      sTexto = "VOUCHER"
      sTexto = Right(Space(60) + sTexto, Int(Len(Space(40) + sTexto) / 2)) + vbCrLf
    Case 1, 5  ' EFECTIVO EX Dolares
      'If iDolaresEfectivo > 0 Then
      If smoneda = "E" Then
        sTexto = "U$(TC: " + Format(CStr(nTipoCambio), "###,##0.00") + ")"
        sTexto = Right(Space(60) + sTexto, Int(Len(Space(40) + sTexto) / 2)) + vbCrLf
      End If
    Case 4 'Anula Productos
      sTexto = "ANULA PROD"
      sTexto = Right(Space(60) + sTexto, Int(Len(Space(40) + sTexto) / 2)) + vbCrLf
    Case 20 'O/C
      sTexto = "O/C"
      sTexto = Right(Space(60) + sTexto, Int(Len(Space(40) + sTexto) / 2)) + vbCrLf
    Case 21 'NC
      sTexto = "N/C"
      sTexto = Right(Space(60) + sTexto, Int(Len(Space(40) + sTexto) / 2)) + vbCrLf
    Case 22 'PADE
      sTexto = "PADE"
      sTexto = Right(Space(60) + sTexto, Int(Len(Space(40) + sTexto) / 2)) + vbCrLf
    Case 23 'PADV
      sTexto = "PADV"
      sTexto = Right(Space(60) + sTexto, Int(Len(Space(40) + sTexto) / 2)) + vbCrLf
    Case 24 'LIQ
      sTexto = "LIQPAD"
      sTexto = Right(Space(60) + sTexto, Int(Len(Space(40) + sTexto) / 2)) + vbCrLf
  End Select
  'Printer.Print sTexto
  Texto_imprimir = Texto_imprimir + vbCrLf + sTexto + vbCrLf
  sTexto = ""
  
  'Ancho de linea = 27
  
  iSubTotal = 0
  If iTipoVenta <> 22 And iTipoVenta <> 23 Then
    iTotal = 0
  End If
  iTotItems = 0
  iTotalDscto = 0
  iServicio = 0
  iPtoItm = 0
  iPtoVta = 0
    
  '<<<<<<<<<<<<<<<<<<<<<<<<<-------------------------------->>>>>>>>>>>>>>>>>>>>>>>>>>>>




    sTexto = sTexto + "Producto         Cant Precio  SubTotal " + vbCrLf
    sTexto = sTexto + "---------------------------------------" + vbCrLf
    iServicio = 0
    igvf = 0
    For i = 0 To gfax.UpperBound(1)
      If blnfactura = True Then
            
        If (Trim(gfax(i, 13)) = "SI") Then
          iSubTotal = (val(Replace(gfax(i, 6), ",", "")) * val(Replace(gfax(i, 7), ",", "")) + (val(Replace(gfax(i, 6), ",", "")) * val(Replace(gfax(i, 7), ",", "")) * Producto(i).Dscto / 100)) / (1 + kIGV + kPAR_PORCSERV * (IIf(gfax(i, 13) = "SI", 1, 0)) / 100)
          isubtotal_1 = val(Replace(gfax(i, 6), ",", "")) * val(Replace(gfax(i, 7), ",", ""))
          toti = (kPAR_PORCSERV * iSubTotal * IIf(gfax(i, 13) = "SI", 1, 0)) / 100
          IGV_1 = val(Replace(gfax(i, 15), ",", ""))
          iServicio = iServicio + val(Replace(gfax(i, 14), ",", ""))
          PUnit = val(Replace(gfax(i, 7), ",", "")) / (1 + kIGV + kPAR_PORCSERV * (IIf(gfax(i, 13) = "SI", 1, 0)) / 100)
        Else
          iSubTotal = val(Replace(gfax(i, 6), ",", "")) * val(Replace(gfax(i, 7), ",", ""))
          PUnit = val(Replace(gfax(i, 7), ",", ""))
          IGV_1 = val(Replace(gfax(i, 15), ",", ""))
        End If
            
        nDscto = Producto(i).Dscto
                        
        PUnit = val(Replace(gfax(i, 7), ",", ""))
        If nDscto > 0 Then
          PUnit = PUnit * nDscto / 100 + PUnit
        End If
        
        sTexto = sTexto + Left(Producto(i).nombre + Space(16), 16) & _
               " " + Right(Space(4) & CStr(val(Replace(gfax(i, 6), ",", ""))), 4) & _
               " " + Right(Space(6) & Format(CStr(PUnit), "0.00"), 6) & _
               " " + Right(Space(9) & Format(CStr(PUnit * val(Replace(gfax(i, 6), ",", ""))), "0.00"), 9) + vbCrLf
                         
        iTotal = iTotal + iSubTotal
        igvf = igvf + IGV_1
        iTotItems = iTotItems + val(Replace(gfax(i, 6), ",", ""))
        
      Else ' tk boleta de venta
                                                         
        If (Trim(gfax(i, 13)) = "SI") Then
          iSubTotal = (val(Replace(gfax(i, 6), ",", "")) * val(Replace(gfax(i, 7), ",", "")) + (val(Replace(gfax(i, 6), ",", "")) * val(Replace(gfax(i, 7), ",", "")) * Producto(i).Dscto / 100)) / (1 + kIGV + kPAR_PORCSERV * (IIf(gfax(i, 13) = "SI", 1, 0)) / 100)
          isubtotal_1 = val(Replace(gfax(i, 6), ",", "")) * val(Replace(gfax(i, 7), ",", ""))
          toti = (kPAR_PORCSERV * iSubTotal * IIf(gfax(i, 13) = "SI", 1, 0)) / 100
          IGV_1 = isubtotal_1 - iSubTotal - toti
          PUnit = val(Replace(gfax(i, 7), ",", "")) / (1 + kIGV + kPAR_PORCSERV * (IIf(gfax(i, 13) = "SI", 1, 0)) / 100)
        Else
          iSubTotal = val(Replace(gfax(i, 6), ",", "")) * val(Replace(gfax(i, 7), ",", ""))
          PUnit = val(Replace(gfax(i, 7), ",", ""))
          IGV_1 = 0
        End If
            
        nDscto = Producto(i).Dscto
        PUnit = val(Replace(gfax(i, 7), ",", ""))
        If nDscto > 0 Then
          PUnit = PUnit * nDscto / 100 + PUnit
        End If
        
        sTexto = sTexto + Left(Producto(i).nombre + Space(16), 16) & _
               " " + Right(Space(4) & CStr(val(Replace(gfax(i, 6), ",", ""))), 4) & _
               " " + Right(Space(6) & Format(CStr(PUnit), "0.00"), 6) & _
               " " + Right(Space(9) & Format(CStr(PUnit * val(Replace(gfax(i, 6), ",", ""))), "0.00"), 9) + vbCrLf
        
        iServicio = iServicio + val(Replace(gfax(i, 14), ",", ""))
        iTotal = iTotal + iSubTotal
        iTotItems = iTotItems + val(Replace(gfax(i, 6), ",", ""))
      End If
      'Controla el total de puntos por item y por venta
      iPtoItm = 0
      iPtoVta = 0
      IGV_1 = 0
      
      'Descuentos
      nDscto = (Producto(i).Dscto * val(Replace(gfax(i, 7), ",", "")) / 100)
      
      iSubTotalDscto = val(Replace(gfax(i, 6), ",", "")) * val(Replace(gfax(i, 7), ",", "")) + (nDscto / 100 * (val(Replace(gfax(i, 6), ",", "")) * val(Replace(gfax(i, 7), ",", ""))))
      Dim Serv As Double
       
      If Producto(i).Dscto < 0 Then
        sTexto = sTexto + Left("*Dscto " + CStr(Abs(Producto(i).Dscto)) + " %" + Space(16), 16) & _
               " " + Space(11) & _
               " " + Right(Space(9) & Format(CStr(PUnit * val(Replace(gfax(i, 6), ",", "")) * Producto(i).Dscto / 100), "0.00"), 9) + vbCrLf
      End If
            
      iTotalDscto = iTotalDscto + nDscto
        
    Next
    
    
    
    
    
  'Añade el % de servicio al total
    
  sTexto = sTexto + "---------------------------------------"
  Texto_imprimir = Texto_imprimir + vbCrLf + sTexto
  sTexto = ""
  
  'Total segun tipo de venta
  
  Select Case iTipoVenta
    Case 0, 1 'Normal, Voucher
    
        If blnfactura = True Then
            sTexto = Left(" VALOR VTA" + Space(23), 23) + Right(Space(15) + Format(CStr(val(Replace(txtSoles.Text, ",", "")) - igvf - iServicio), "0.00"), 15) + vbCrLf
                       
            sTexto = sTexto + Left(" IGV" + Space(23), 23) + Right(Space(15) + Format(CStr(igvf), "0.00"), 15) + vbCrLf
            If iServicio > 0 Then
                sTexto = sTexto + Left(" SERVICIO" + "(" + kPAR_PORCSERV + " %)" + Space(23), 23) + Right(Space(15) + Format(CStr(iServicio), "0.00"), 15) + vbCrLf
            End If
            sTexto = sTexto + Left(" TOTAL VTA" + Space(23), 23) + Right(Space(15) + Format(CStr(val(Replace(txtSoles.Text, ",", ""))), "0.00"), 15) + vbCrLf + vbCrLf
            If smoneda = "E" Then
            toti = val(Replace(txtDolares, ",", ""))
            Else
            toti = val(Replace(txtSoles, ",", ""))
            End If
            iTotal = 0
            
            If rsPagTar.state = adStateOpen Then
                If rsPagTar.RecordCount > 0 Then
                    rsPagTar.MoveFirst
                    Do While Not rsPagTar.EOF
                        sTexto = sTexto + Left(" " + rsPagTar.Fields("descrip") + Space(23), 23) + Right(Space(15) + Format(CStr(rsPagTar.Fields("pago")), "0.00"), 15) + vbCrLf
                        toti = toti - rsPagTar.Fields("pago")
                        iTotal = iTotal + rsPagTar.Fields("pago")
                        rsPagTar.MoveNext
                    Loop
                End If
            End If
            
            If val(Replace(txtSoles, ",", "")) > iTotal Then
                ivuelto_1 = 0
            Else
                ivuelto_1 = toti - iTotal
            End If
        
        Else
            IGV_1 = (val(Replace(txtSoles.Text, ",", "")) - val(CStr(iTotal)))
            'Validacion
            If Round(IGV_1 + iTotal, 2) <> val(Replace(txtSoles.Text, ",", "")) Then
               MsgBox "Inconsistencia de Datos"
               iTotal = val(Replace(txtSoles.Text, ",", "")) - IGV_1
            End If
                        
            sTexto = Left(" VALOR VTA" + Space(23), 23) + Right(Space(15) + Format(CStr(val(Replace(txtSoles.Text, ",", ""))), "0.00"), 15) + vbCrLf

            If iServicio > 0 Then
                sTexto = sTexto + Left(" SERVICIO" + "(" + kPAR_PORCSERV + " %)" + Space(23), 23) + Right(Space(15) + Format(CStr(iServicio), "0.00"), 15) + vbCrLf
            End If
            
            If smoneda = "E" Then
                toti = val(Replace(txtDolares.Text, ",", ""))
            Else
                toti = val(Replace(txtSoles.Text, ",", ""))
            End If
            If rsPagTar.state = adStateOpen Then
                If rsPagTar.RecordCount > 0 Then
                    rsPagTar.MoveFirst
                    Do While Not rsPagTar.EOF
                        sTexto = sTexto + Left(" " + rsPagTar.Fields("descrip") + Space(23), 23) + Right(Space(15) + Format(CStr(rsPagTar.Fields("pago")), "0.00"), 15) + vbCrLf
                        toti = toti - rsPagTar.Fields("pago")
                        iTotal = iTotal + rsPagTar.Fields("pago")
                        rsPagTar.MoveNext
                    Loop
                End If
            End If
            
           
            iTotal = 0
            If val(Replace(txtSoles, ",", "")) > iTotal Then
                ivuelto_1 = 0
            Else
                ivuelto_1 = toti - iTotal
            End If
            
                        
        End If
        If bLiquidaNC = False Then
            If toti > 0 Then
                If smoneda = "E" Then
                    sTexto = sTexto + Left(" " & Trim(cboTipoDocumento.Text) & "(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(toti), "0.00"), 15) + vbCrLf
                Else
                    sTexto = sTexto + Left(" " & Trim(cboTipoDocumento.Text) & "(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(toti), "0.00"), 15) + vbCrLf
                End If
            End If
            If ivuelto_1 > 0 Then
               sTexto = sTexto + Left(" VUELTO" + Space(23), 23) + Right(Space(15) + Format(CStr(ivuelto_1), "0.00"), 15) + vbCrLf
            End If
        Else
         If Trim(txtliqefectivosoles.Text) = "" Then txtliqefectivosoles.Text = "0.00"
         If Trim(txtliqefectivodolares.Text) = "" Then txtliqefectivodolares.Text = "0.00"
         If Trim(txtliqpade.Text) = "" Then txtliqpade.Text = "0.00"
         If Trim(txtliqvueltosoles.Text) = "" Then txtliqvueltosoles.Text = "0.00"
         If Trim(ttxliqvueltodolares.Text) = "" Then ttxliqvueltodolares.Text = "0.00"
         
         If CDbl(txtliqefectivosoles.Text) > 0 Then
            sTexto = sTexto + Left(" EFECTIVO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqefectivosoles.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqefectivodolares.Text) > 0 Then
            sTexto = sTexto + Left(" EFECTIVO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqefectivodolares.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqpade.Text) > 0 Then
           sTexto = sTexto + Left(" PADE/PADV" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqpade.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqvueltosoles.Text) <> 0 Then
            sTexto = sTexto + Left(" VUELTO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqvueltosoles.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(ttxliqvueltodolares.Text) <> 0 Then
            sTexto = sTexto + Left(" VUELTO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(ttxliqvueltodolares.Text), "0.00"), 15)
         End If
        End If
       ' Set rsPagTar = Nothing
      
   Case 4 'Anula Productos
      sTexto = Left(" CASH/TL" + Space(23), 23) + Right(Space(15) + Format(CStr(iTotal), "0.00"), 15)
    Case 5, 1 'Efectivo
       If blnfactura = True Then
          sTexto = Left(" VALOR VTA" + Space(23), 23) + Right(Space(15) + Format(CStr(val(Replace(txtSoles.Text, ",", "")) - igvf - iServicio), "0.00"), 15) + vbCrLf
          sTexto = sTexto + Left(" IGV" + Space(23), 23) + Right(Space(15) + Format(CStr(igvf), "0.00"), 15) + vbCrLf
          If iServicio > 0 Then
            sTexto = sTexto + Left(" SERVICIO" + "(" + kPAR_PORCSERV + " %)" + Space(23), 23) + Right(Space(15) + Format(CStr(iServicio), "0.00"), 15) + vbCrLf
          End If
          sTexto = sTexto + Left(" TOTAL VTA" + Space(23), 23) + Right(Space(15) + Format(CStr(val(Replace(txtSoles.Text, ",", ""))), "0.00"), 15) + vbCrLf + vbCrLf
      Else 'adicionado
            sTexto = Left(" VALOR VTA" + Space(23), 23) + Right(Space(15) + Format(CStr(val(Replace(txtSoles.Text, ",", ""))), "0.00"), 15) + vbCrLf
            If iServicio > 0 Then
               sTexto = sTexto + Left(" SERVICIO" + "(" + kPAR_PORCSERV + " %)" + Space(23), 23) + Right(Space(15) + Format(CStr(iServicio), "0.00"), 15) + vbCrLf
            End If
      End If
     If bLiquidaNC = False Then
        If iEfectivo > 0 Then
           sTexto = sTexto + Left(" EFECTIVO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(iEfectivo), "0.00"), 15) + vbCrLf
        End If
        If iDolaresEfectivo > 0 Then
           sTexto = sTexto + Left(" EFECTIVO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(iDolaresEfectivo), "0.00"), 15) + vbCrLf
        End If
        If iVuelto <> 0 Then
           sTexto = sTexto + Left(" VUELTO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(iVuelto), "0.00"), 15) + vbCrLf
        End If
        If iVueltoDolares <> 0 Then
           sTexto = sTexto + Right(" VUELTO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(iVueltoDolares), "0.00"), 15)
        End If
      Else
         If Trim(txtliqefectivosoles.Text) = "" Then txtliqefectivosoles.Text = "0.00"
         If Trim(txtliqefectivodolares.Text) = "" Then txtliqefectivodolares.Text = "0.00"
         If Trim(txtliqpade.Text) = "" Then txtliqpade.Text = "0.00"
         If Trim(txtliqvueltosoles.Text) = "" Then txtliqvueltosoles.Text = "0.00"
         If Trim(ttxliqvueltodolares.Text) = "" Then ttxliqvueltodolares.Text = "0.00"
         
         If piEmitevoucher = 1 Then
            If rsPagTar.RecordCount > 0 Then
                rsPagTar.MoveFirst
               
                Do While Not rsPagTar.EOF
                    sTexto = sTexto + Left(" " + rsPagTar.Fields("descrip") + Space(23), 23) + Right(Space(15) + Format(CStr(rsPagTar.Fields("pago")), "0.00"), 15) + vbCrLf
                    toti = toti - rsPagTar.Fields("pago")
                    iTotal = iTotal + rsPagTar.Fields("pago")
                    rsPagTar.MoveNext
                Loop
            End If
         End If
         
         If CDbl(txtliqefectivosoles.Text) > 0 Then
            sTexto = sTexto + Left(" EFECTIVO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqefectivosoles.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqefectivodolares.Text) > 0 Then
            sTexto = sTexto + Left(" EFECTIVO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqefectivodolares.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqpade.Text) > 0 Then
             sTexto = sTexto + Left(" PADE/PADV" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqpade.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqvueltosoles.Text) <> 0 Then
             sTexto = sTexto + Left(" VUELTO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqvueltosoles.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(ttxliqvueltodolares.Text) <> 0 Then
             sTexto = sTexto + Left(" VUELTO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(ttxliqvueltodolares.Text), "0.00"), 15)
         End If
        End If
    Case 20 'O/C
          
    If bLiquidaNC = False Then
         sTexto = Left(" VALOR VTA" + Space(23), 23) + Right(Space(15) + Format(CStr(txtSoles.Text), "0.00"), 15) + vbCrLf
         If iServicio > 0 Then
             sTexto = sTexto + Left(" SERVICIO" + "(" + kPAR_PORCSERV + " %)" + Space(23), 23) + Right(Space(15) + Format(CStr(iServicio), "0.00"), 15) + vbCrLf
         End If
       
         If iEfectivo > 0 Then
            sTexto = sTexto + Left(" EFECTIVO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtEfectivoSoles.Text), "0.00"), 15) + vbCrLf
         End If
         If iDolaresEfectivo > 0 Then
             sTexto = sTexto + Left(" EFECTIVO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtEfectivoDolares.Text), "0.00"), 15) + vbCrLf
         End If
         If iVuelto <> 0 Then
              sTexto = sTexto + Left(" VUELTO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(iVuelto), "0.00"), 15) + vbCrLf
         End If
         If iVueltoDolares <> 0 Then
             sTexto = sTexto + Left(" VUELTO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(iVueltoDolares), "0.00"), 15)
         End If
     Else
         sTexto = Left(" VALOR VTA" + Space(23), 23) + Right(Space(15) + Format(CStr(txtSoles.Text), "0.00"), 15) + vbCrLf
         If iServicio > 0 Then
             sTexto = sTexto + Left(" SERVICIO" + "(" + kPAR_PORCSERV + " %)" + Space(23), 23) + Right(Space(15) + Format(CStr(iServicio), "0.00"), 15) + vbCrLf
         End If
       
         If CDbl(txtliqefectivosoles.Text) > 0 Then
             sTexto = sTexto + Left(" EFECTIVO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqefectivosoles.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqefectivodolares.Text) > 0 Then
              sTexto = sTexto + Left(" EFECTIVO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqefectivodolares.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqpade.Text) > 0 Then
              sTexto = sTexto + Left(" PADE/PADV" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqpade.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(txtliqvueltosoles.Text) <> 0 Then
             sTexto = sTexto + Left(" VUELTO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(txtliqvueltosoles.Text), "0.00"), 15) + vbCrLf
         End If
         If CDbl(ttxliqvueltodolares.Text) <> 0 Then
              sTexto = sTexto + Left(" VUELTO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(ttxliqvueltodolares.Text), "0.00"), 15)
         End If
     
     End If
    Case 21 'N/C
         sTexto = Left(" TOTAL S/." + Space(23), 23) + Right(Space(15) + Format(CStr(txtSoles), "0.00"), 15)
    Case 22 'PADE
      Select Case mon
       Case 2
          sTexto = Left(" CASH/TL" + Space(19), 19) + Right(Space(19) + "US$ " + Format(CStr(iMontoDolares), "0.00"), 19)
       Case Else
          sTexto = Left(" CASH/TL" + Space(19), 19) + Right(Space(19) + "S/. " + Format(CStr(iTotal), "0.00"), 19)
      End Select
      
    Case 23 'PADV
    'jpcb270710
      Select Case mon
       Case 2
        If iTipoVenta = 23 Then
            sTexto = Left(" TARJETA" + Space(19), 19) + Right(Space(19) + "US$ " + Format(CStr(iMontoDolares), "0.00"), 19)
        Else
           sTexto = Left(" CASH/TL" + Space(19), 19) + Right(Space(19) + "US$ " + Format(CStr(iMontoDolares), "0.00"), 19)
        End If
           
       Case Else
        If iTipoVenta = 23 Then
            sTexto = Left(" TARJETA" + Space(19), 19) + Right(Space(19) + "S/. " + Format(CStr(iTotal), "0.00"), 19)
        Else
            sTexto = Left(" CASH/TL" + Space(19), 19) + Right(Space(19) + "S/. " + Format(CStr(iTotal), "0.00"), 19)
        End If
      End Select
      
    Case 24 'LIQPAD
          sTexto = Left(" SUB/TOTL" + Space(23), 23) + Right(Space(15) + Format(CStr(iTotal), "0.00"), 15) + vbCrLf
          sTexto = sTexto + Left(" PADE/PADV" + Space(23), 23) + Right(Space(15) + txtTotalPA.Text, 15) + vbCrLf
          sTexto = sTexto + Left(" TOT-PAGAR" + Space(23), 23) + Right(Space(15) + txtSoles.Text, 15) + vbCrLf
         If iEfectivo > 0 Then
            sTexto = sTexto + Left(" EFECTIVO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(iEfectivo), "0.00"), 15) + vbCrLf
         End If
        If iDolaresEfectivo > 0 Then
           sTexto = sTexto + Left(" EFECTIVO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(iDolaresEfectivo), "0.00"), 15) + vbCrLf
        End If
           
      If piEmitevoucher = 1 Then
         If rsPagTar.RecordCount > 0 Then
            rsPagTar.MoveFirst
               
            Do While Not rsPagTar.EOF
               'sTexto = sTexto + Left(" " + rsPagTar.Fields("descrip") + Space(23), 23) + Right(Space(15) + Format(CStr(rsPagTar.Fields("pago")), "0.00"), 15) + vbCrLf
               sTexto = sTexto + Left(" " + rsPagTar.Fields("descrip") + Space(23), 23) + Right(Space(15) + Format(CStr(rsPagTar.Fields("pago")), "0.00"), 15) + vbCrLf
               toti = toti - rsPagTar.Fields("pago")
               iTotal = iTotal + rsPagTar.Fields("pago")
              rsPagTar.MoveNext
            Loop
         End If
       End If
      If iVuelto <> 0 Then
          sTexto = sTexto + Left(" VUELTO(S/)" + Space(23), 23) + Right(Space(15) + Format(CStr(iVuelto), "0.00"), 15) + vbCrLf
      End If
      If iVueltoDolares <> 0 Then
          sTexto = sTexto + Left(" VUELTO(U$)" + Space(23), 23) + Right(Space(15) + Format(CStr(iVueltoDolares), "0.00"), 15)
      End If
           
  End Select
  
  
  


  printer.FontSize = 9 '12
  printer.FontBold = True
  Texto_imprimir = Texto_imprimir + vbCrLf + sTexto
  sTexto = ""
  If iTotItems > 0 Then
     sTexto = Left(" ITEM" + Space(23), 23) + Right(Space(15) + Format(CStr(iTotItems), "0.00"), 15)
 End If
 
 If bAfectoDetraccion = True Then
    sTexto = sTexto & vbCrLf & vbCrLf & " OPERACION AFECTA A LA DETRACCION " & vbCrLf & " NRO CTA BN: " & sNroCtaBN & vbCrLf & " Monto S/." & Format(nMontoDetracc, "0.00")
 End If
 
 
  Select Case iTipoVenta
    Case 4 'Anula Productos
      sTexto = sTexto + vbCrLf + "VO-POSTN"
  End Select
  
  Texto_imprimir = Texto_imprimir + vbCrLf + sTexto + vbCrLf
  'Printer.Print sTexto
    
  'Printer.Print " "
  
  sTexto = ""
  
  
  
 '---Puntos----------
' nImporte = CDbl(Me.txtSoles.Text)
' If nImporte > 0 And sTarjeta <> "" Then
'   iPuntos = Int(nImporte / lReglaPuntoImporte) * lReglaPuntoCantidad
' End If
'
'
'  If sTarjeta <> "" Then
'     'sw 'sw Add 19/06/2009, era solo >>> intPuntosAcumulados = ObtenerPuntosAcumulados(sTarjeta)
'     intPuntosAcumulados = ObtenerPuntosAcumulados(sTarjeta, Trim(Me.txtLocal.Text))
'     If (intPuntosAcumulados + iPuntos) >= 0 And iPuntos > 0 And intPuntosAcumulados <> -1 Then
'         sTexto = sTexto & " UD. ACUMULO: " & iPuntos & " PUNTOS" & vbCrLf
'         sTexto = sTexto & " TIENE ACUMULADO: " & IIf(intPuntosAcumulados + iPuntos < 0, "**", intPuntosAcumulados + iPuntos) & " PUNTOS" & vbCrLf & vbCrLf
'     End If
'  End If
  
 '---Fin Puntos------
 
 
  sTexto = sTexto + Space(9) + Format(CStr(Now()), "(DDD) DD/MM/YYYY ") + Format(CStr(Now()), "hh:mm") + vbCrLf 'Hora: 6 + 1
  If bAcceso = True Then
    sTexto = sTexto + "       SUPERVISOR: " + txtsupervisor + vbCrLf
  End If
  sTexto = sTexto + Space(3) + Left(psUsuario_Descripcion, 10) + " " 'Usuario: 10 + 1
  sTexto = sTexto + Space(1) + "Cj:" + kPAR_CAJA + " T:" + kPAR_TURNO
  sTexto = sTexto + Space(1) + "v" & App.Major & "." & App.Minor & "." & App.Revision
  sTexto = sTexto + vbCrLf & "         Correlativo: " & ObtenerCorrelativo(p_1)

  Select Case iTipoVenta
 Case 20, 22, 23, 21
 Case 24
     If piEmitevoucher <> 1 Then
        txtliqefectivodolares.Text = IIf(Trim(txtEfectivoDolares.Text) = "", "0.00", txtEfectivoDolares.Text)
        txtliqefectivosoles.Text = IIf(Trim(txtEfectivoSoles.Text) = "", "0.00", txtEfectivoSoles.Text)
        txtliqvueltosoles.Text = IIf(Trim(txtVueltoSoles.Text) = "", "0.00", txtVueltoSoles.Text)
        ttxliqvueltodolares.Text = IIf(Trim(txtVueltoDolares.Text) = "", "0.00", txtVueltoDolares.Text)
     End If
     txtliqpade.Text = IIf(Trim(txtTotalPA.Text) = "", "0.00", txtTotalPA.Text)
     txtLiq.Text = iCodOper
 Case Else
    sTexto = sTexto + vbCrLf + vbCrLf + "   " + kPIE_TICKET
 End Select
  
  printer.FontSize = 8 '11
  printer.FontBold = False
  '-------------segun impresora seleccionada --------
  Texto_imprimir = Texto_imprimir + vbCrLf + sTexto
  
If p_1 = 1 Then
  ConfiguraImpresora kPAR_IMPRESORA
  Select Case KImpresora
     Case 1
         Call CortePapel(Texto_imprimir, p_1, CStr(iCodOper))
     Case 0
         printer.Print Texto_imprimir
         printer.Print " "
         printer.Print " "
         printer.EndDoc
   End Select
Else
   ConfiguraImpresora kPAR_IMPRESORA_ALTERNA
  Select Case KImpresoraALT
     Case 1
          Call CortePapel(Texto_imprimir, p_1)
      Case 0
          printer.Print Texto_imprimir
          printer.Print " "
          printer.Print " "
          printer.EndDoc
    End Select
End If






'-------------------Graba operacion -------------------------
''sacar el valor de servicio

    Dim nMontoServicio As Double


  For i = 0 To gfax.UpperBound(1)
    If UCase(gfax(i, 13)) = "SI" Then
        nMontoServicio = nMontoServicio + gfax(i, 14)
    End If
  Next


    sSQL = "INSERT INTO Venta01(cCodVta,TipoDoc,cSerieDoc,NroDoc,cCodCaja,cClienteCode,IdLocal,DscCliente,NroRuc,ValorVta,Igv,Serv,TotVta,nPorcIGV,TotVtaUSD,cCodMoneda,nTipoCambio,cCodTipoCredito,fechaemision,FechaAnulacion,FechaVencimiento,cCodCabVtaRef,bTieneDetraccion) " _
& "VALUES (" & iCodOper & ",'" & cdocTipo & "','" & cDocSerie & "','" & Format(cDocCodigofull, "000000") & "','" & kPAR_CAJA & "','" & txtTarjeta.Text & "','" & txtLocal.Text & "','" & txtNombres.Text & "','" & txtRUC.Text & "'," & iMontoSoles - iIGV - nMontoServicio & "," & iIGV & "," & nMontoServicio & "," & iMontoSoles & "," & kIGV & "," & iMontoDolares & ",'" & smoneda & "'," & nTipoCambio & ",'" & dcbTipoCredito.BoundText & "','" & Format(DTPFechaEmision.Value, "yyyyMMdd") & "',null,null,null," & IIf(bAfectoDetraccion = False, 0, 1) & ")"

  If Not oDBAdmin.EjecutarSentencia(cnSQL, sSQL) Then GoTo Salir
  
  
    Dim xNumItem As Integer
    xNumItem = 1
    For i = 0 To nProducto

        sSQL = "INSERT INTO Venta02(cCodVta,NroItem,cCodartic,sProdDscCrta,nPrecioOrig,nQtdVendida,nDescuento,nServicio) " _
        & "VALUES (" & iCodOper & "," & xNumItem & ",'" & CStr(Producto(i).Codigo) & "','" & Producto(i).nombre & "'," & Producto(i).PUnit & "," & Producto(i).Cant & "," & CStr(Producto(i).Dscto) & "," & IIf(gfax(i, 13) = "SI", kPAR_PORCSERV, "0") & ")"

        If Not oDBAdmin.EjecutarSentencia(cnSQL, sSQL) Then GoTo Salir

        xNumItem = xNumItem + 1
    Next
  
   If bAfectoDetraccion = True Then
        sSQL = "INSERT INTO Detraccion (SerieDoc,NroDoc,MontoDetracc,PorcDetracc,Estado)VALUES ('" & cDocSerie & "','" & Format(cDocCodigofull, "000000") & "'," & nMontoDetracc & "," & (nPorcDetracc / 100) & ",'P')"
        
        If Not oDBAdmin.EjecutarSentencia(cnSQL, sSQL) Then GoTo Salir
   End If
    
    
    
    ADOCnn.CommitTrans
    cnSQL.CommitTrans
  
  
Set cnSQL = Nothing
Exit Sub
Salir:
MsgBox Err.Description
ADOCnn.RollbackTrans
cnSQL.RollbackTrans
Set cnSQL = Nothing


End Sub



Private Sub LlamarCliente()
  On Error GoTo LineaError
  
  If frmBusquedaArticulos.Visible Then Exit Sub
  
  Dim sSQL As String
  Dim ADORS As ADODB.Recordset
  Dim i As Long, j As Long
  Dim sTarjeta As String
  'sw To SQL Server era >>> nIdLocal
  Dim idLocal As Integer
  
  If Trim(txtTarjeta.Text) = "" Then
    txtNombres = ""
    dcbLocal.BoundText = -1
    GoTo Salir
  End If
  
  sTarjeta = Right("00000000" + Trim(txtTarjeta.Text), 8)
  'sw To SQL Server era >>> nIdLocal
  idLocal = val(txtLocal.Text)
  
  txtTarjeta.Text = sTarjeta
  
'  sSQL = "SELECT a.cClieCode, sClieApel + ' ' + sClieName AS sName, dNacmDate, " + _
'         "nPuntCant, nTickCant, dUltTDate, sTranDesc " + _
'         "FROM Cliente a, Transaccion b, Tarjeta c " + _
'         "WHERE a.cTranCode = b.cTranCode AND " + _
'         "a.cClieCode = c.cClieCode AND " + _
'         "nTarjNumb = '$'"
         
  'sw To SQL Server era >>> nIdLocal >>> Date()
  sSQL = " SELECT a.cClieCode, sClieApel , sClieName , dNacmDate, a.IdLocal, " + _
         "        nPuntCant, nTickCant, dUltTDate" + _
         "   FROM Cliente a, Tarjeta c " + _
         "  WHERE a.cClieCode = c.cClieCode and a.IdLocal=c.IdLocal and (c.cTarjActi=1 and Convert(Char(10), dcadudate,112)>=Convert(Char(10), getdate(),112)) " + _
         "    AND nTarjNumb = '$'"
         
  'sw To SQL Server era >>> nIdLocal
  If idLocal = 1 Or idLocal = 2 Then
    sSQL = sSQL + "    AND a.IdLocal = $ "
  End If
  
  'sw To SQL Server era >>> nIdLocal
  sSQL = VBsprintf(sSQL, sTarjeta, CInt(idLocal))
  
  If bolExistenProblemasConexionBDCliente = False Then
    ConectarBDCliente     'Abrimos conexion
  End If
  
  If Not oDBAdmin.EjecutarConsulta(ADOCnn2, sSQL, ADORS) Then GoTo Salir
  
  If ADORS.RecordCount = 0 Then
    txtTarjeta.Text = ""
    txtNombres.Text = ""
    dcbLocal.BoundText = -1
    txtLocal.Text = ""
    MsgBox "El Código de cliente no existe o la tarjeta se encuentra inactiva"
    txtTarjeta.SetFocus
  ElseIf ADORS.RecordCount = 1 Then
    'lblLocal.Visible = False
    'dcbLocal.Visible = False
    txtNombres.Text = LeerCampo(ADORS("sClieApel")) + " " + LeerCampo(ADORS("sClieName"))
    'lblLocal.Visible = True: dcbLocal.Visible = True
    'sw To SQL Server eran >>> nIdLocal
    dcbLocal.BoundText = ADORS("IdLocal")
    txtLocal.Text = ADORS("IdLocal")
  ElseIf ADORS.RecordCount = 2 Then
    txtNombres.Text = ""
    lblLocal.Visible = True: dcbLocal.Visible = True
    'MsgBox "Seleccione local al cual pertenece!!", vbInformation + vbOKOnly, "Mensaje"
    dcbLocal.BoundText = -1
    'dcbLocal.SetFocus
    txtBuscaCliente_Click
  End If
  
  GoTo Salir
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  Screen.MousePointer = vbDefault

Salir:
  Set ADORS = Nothing
End Sub

Private Sub CargarCombos()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sSQL As String


cboTipoDocumento.AddItem "FADE", 0
cboTipoDocumento.AddItem "BADE", 1

cboTipoDocumento1.AddItem "FADE", 0
cboTipoDocumento1.AddItem "BADE", 1
    
cboTipoDocumento2.AddItem "FADE", 0
cboTipoDocumento2.AddItem "BADE", 1
    
cboTipoDocumento3.AddItem "FADE", 0
cboTipoDocumento3.AddItem "BADE", 1
    
cboMoneda.AddItem "SOLES", 0
cboMoneda.AddItem "DOLARES", 1
    
cboMoneda1.AddItem "SOLES", 0
cboMoneda1.AddItem "DOLARES", 1
    
Set cn = New ADODB.Connection
 
  'Conectar a BD (SQL)
  If Not oDBAdmin.AbrirBD(cn, psCadenaConexionSQLServer) Then GoTo Salir
  sSQL = "SELECT idlocal,dsclocal FROM local"
  If Not oDBAdmin.EjecutarConsulta(cn, sSQL, rs) Then GoTo Salir
  With dcbLocal
    Set dcbLocal.RowSource = rs
    dcbLocal.BoundColumn = "idlocal"
    dcbLocal.ListField = "dsclocal"
  End With


  If Not oDBAdmin.AbrirBD(cn, psConnectString) Then GoTo Salir
  
  sSQL = "select cCodTipoCredito,vDscTipoCredito from TipoCredito"
  If Not oDBAdmin.EjecutarConsulta(cn, sSQL, rs) Then GoTo Salir

  With dcbTipoCredito
    Set .RowSource = rs
    .BoundColumn = "cCodTipoCredito"
    .ListField = "vDscTipoCredito"
  End With
    
'  sSQL = "select cCodEstadoDocumento,vDscEstadoDocumento from tipoestadodocumentopago"
'  If Not oDBAdmin.EjecutarConsulta(cn, sSQL, rs) Then GoTo Salir
'  With dcbEstadoDocumento
'    Set .RowSource = rs
'    .BoundColumn = "cCodEstadoDocumento"
'    .ListField = "vDscEstadoDocumento"
'  End With

  sSQL = "select cCodTipoPago,vDscTipoPago from tipoformapago order by vDscTipoPago"
  If Not oDBAdmin.EjecutarConsulta(cn, sSQL, rs) Then GoTo Salir
  With dcbFormaPago
    Set .RowSource = rs
    .BoundColumn = "cCodTipoPago"
    .ListField = "vDscTipoPago"
  End With

  sSQL = "select cCodBanco,vDscBanco from banco order by vDscBanco"
  If Not oDBAdmin.EjecutarConsulta(cn, sSQL, rs) Then GoTo Salir
  With dcbBanco
    Set .RowSource = rs
    .BoundColumn = "cCodBanco"
    .ListField = "vDscBanco"
  End With

  sSQL = "select cod_tar,descrip from tipo_tarjeta order by descrip"
  If Not oDBAdmin.EjecutarConsulta(cn, sSQL, rs) Then GoTo Salir
  With dcbTarjeta
    Set .RowSource = rs
    .BoundColumn = "cod_tar"
    .ListField = "descrip"
  End With



Salir:
Set rs = Nothing
Set cn = Nothing

End Sub
Private Sub LimpiarLiquidacion()

'cboTipoDocumento3.ListIndex = -1
txtTXL(0).Text = ""
txtTXL(1).Text = ""
txtTotalPA.Text = ""
txtTotalNC.Text = ""
txtSolesLQ.Text = ""
txtDolaresLQ.Text = ""

lvwTX(0).ListItems.Clear
lvwTX(1).ListItems.Clear

End Sub
Private Sub LimpiarFactura()
txtTarjeta.Text = ""
txtLocal.Text = ""
txtNombres.Text = ""
dcbLocal.Text = ""
lblNroDocumento.Caption = ""
cboTipoDocumento.ListIndex = -1
dcbTipoCredito.Text = ""
DTPFechaEmision = Now
txtRUC.Text = ""
txtSoles.Text = "0.00"
txtDolares.Text = "0.00"
cboMoneda.ListIndex = -1

gfax.Clear
gfax.ReDim 0, 0, 0, 15
Set TDGFacturacion.Array = gfax
TDGFacturacion.ReBind
TDGFacturacion.MoveFirst
TDGFacturacion.Update
TDGFacturacion.Refresh
End Sub
Private Sub IniciarControlesPago()
    lblTipoTarjeta.Visible = False: dcbTarjeta.Visible = False
    lblBanco.Visible = False: dcbBanco.Visible = False
    lblCertificadoRetencion.Visible = False: txtNroCertificadoRetencion.Visible = False
    lblDepositoDetraccion.Visible = False: txtNroDepositoDetraccion.Visible = False
    lblNroCuenta.Visible = False: txtNroCuenta.Visible = False
    lblNroOperacion.Visible = False: txtNroOperacion.Visible = False
End Sub


Private Sub cboMoneda1_Click()
If cboMoneda1.Text = "SOLES" Then
    txtMontoSoles.Enabled = True
    txtMontoDolares.Enabled = False
    txtMontoDolares.BackColor = &H80000004
    txtMontoSoles.BackColor = &H80000005
ElseIf cboMoneda1.Text = "DOLARES" Then
    txtMontoSoles.Enabled = False
    txtMontoDolares.Enabled = True
    txtMontoSoles.BackColor = &H80000004
    txtMontoDolares.BackColor = &H80000005
End If
End Sub

Private Sub cboTipoDocumento2_Click()
LimpiarNC
End Sub

Private Sub cboTipoDocumento3_Click()
LimpiarLiquidacion
End Sub

Private Sub cmdActualizarDetracc_Click()
Dim sCadena, sSQL As String
Dim cnSQL As ADODB.Connection

On Error GoTo Salir
sCadena = InputBox("Ingrese Nro Voucher Pago:", "Requerido")

If sCadena <> "" Then
    sCadena = "Cancelado por GV - Nro Voucher: " & sCadena

    If Not oDBAdmin.AbrirBD(cnSQL, psConnectString) Then GoTo Salir 'OMNISYS

    sSQL = "UPDATE Detraccion SET Estado='C',Observaciones='" & sCadena & "' WHERE SerieDoc='" & Trim(P_cSerieDoc) & "' AND NroDoc='" & Trim(lblNroDocumento2) & "'"
  
    If Not oDBAdmin.EjecutarSentencia(cnSQL, sSQL) Then GoTo Salir
  
    Set cnSQL = Nothing

    MsgBox "Se actualizó el pago de Detraccion satisfactoriamente...", vbOKOnly + vbInformation, "Mensaje"
    
    LimpiarPagos
End If



Exit Sub
Salir:
MsgBox Err.Description
Set cnSQL = Nothing

End Sub

Public Sub CmdAdd_Click(Index As Integer)
  Dim i As Long
  Dim iOper As Long
  Dim itm As ListItem
  Dim ADORS As ADODB.Recordset
  Dim sSQL As String
  Dim bControl As Boolean
  Dim cnSQL As ADODB.Connection
  
  bControl = False
  
  If Trim(txtTXL(Index)) = "" Then
    MsgBox "Debe ingresar el código de transacción."
    txtTXL(Index).SetFocus
    Exit Sub
  End If
  
  iOper = val(txtTXL(Index))
  
  'Verifica si el numero de TX ya existe 'es correcto
  For i = 1 To lvwTX(Index).ListItems.Count
    If lvwTX(Index).ListItems(i).Text = iOper Then
      MsgBox "El código de transacciòn ya existe."
      Exit Sub
    End If
  Next
  
  'Verifica si el numero de TX es correcto
'  sSQL = " SELECT b.cOperCode, b.nTarjNumb, C.cClieCode, c.sName, b.nMoneda, b.nMontoDolares," & _
'         " b.dOperFech, b.nMontoSoles, b.cOperTipo, b.sGlosa, cOpercodeRela, cdocserie, cdoccodigo" & _
'         " FROM OperacionParalela b LEFT JOIN" & _
'         " (SELECT Cliente.cClieCode, Tarjeta.nTarjNumb, sClieApel + ' ' + sClieName as sName" & _
'         " FROM CLIENTE inner join Tarjeta" & _
'         " ON Cliente.cClieCode = Tarjeta.cClieCode) c" & _
'         " ON b.nTarjNumb = c.nTarjNumb" & _
'         " WHERE cOperCode = " + CStr(iOper) & _
'         " AND b.cEstado = '1'"

sSQL = "Select cCodVta,v.TipoDoc, v.cSerieDoc,v.NroDoc,v.FechaEmision,v.DscCliente,v.cClienteCode,v.IdLocal, " _
& "Moneda=Case v.cCodMoneda when 'N' then 'SOLES' when 'E' then 'DOLARES' end, " _
& "v.TotVta , v.TotVtaUSD from venta01 v " _
& "where cCodVta=" & CStr(iOper) & " "


''''''''''''''

'''''''''''''
If Not oDBAdmin.AbrirBD(cnSQL, psConnectString) Then GoTo Salir 'OMNISYS
   If oDBAdmin.EjecutarConsulta(cnSQL, sSQL, ADORS) Then
  'If oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then
    Do While Not ADORS.EOF
      If Index = 0 Then
        'Dim mon As Integer
        Dim mon As String
        mon = LeerCampo(ADORS("Moneda"))
        Set itm = lvwTX(Index).ListItems.Add(, , Trim(CStr(LeerCampo(ADORS("cCodVta")))))
        itm.SubItems(1) = IIf(LeerCampo(ADORS("TipoDoc")) = "01", "FADE", "BADE")
        itm.SubItems(2) = LeerCampo(ADORS("cseriedoc")) & "-" & LeerCampo(ADORS("nrodoc"))
        itm.SubItems(3) = LeerCampo(ADORS("cClienteCode")) 'LeerCampo(ADORS("nTarjNumb"))
        itm.SubItems(4) = Format(LeerCampo(ADORS("TotVta")), "0.00") 'Format(LeerCampo(ADORS("nMontoSoles")), "0.00")
        itm.SubItems(5) = Format(LeerCampo(ADORS("FechaEmision")), "dd/mm/yyyy") 'Format(LeerCampo(ADORS("dOperFech")), "dd/mm/yyyy")
        If mon = "DOLARES" Then

          itm.SubItems(6) = "US$ " + Format(LeerCampo(ADORS("TotVtaUSD")), "0.00") 'Format(LeerCampo(ADORS("nMontoDolares")), "0.00")
        Else

          itm.SubItems(6) = "S/. " + Format(LeerCampo(ADORS("TotVta")), "0.00") 'Format(LeerCampo(ADORS("nMontoSoles")), "0.00")
        End If
        itm.SubItems(7) = LeerCampo(ADORS("DscCliente")) 'LeerCampo(ADORS("sName")) + " - " + LeerCampo(ADORS("sGlosa"))
      
      
'      With lvwTX(Index).ListItems.Add(, , Trim(CStr(LeerCampo(ADORS("cCodVta")))))
'        .SubItems(1) = IIf(LeerCampo(ADORS("TipoDoc")) = "01", "FADE", "BADE")
'        .SubItems(2) = LeerCampo(ADORS("cseriedoc")) & "-" & LeerCampo(ADORS("nrodoc"))
'        .SubItems(3) = CStr(LeerCampo(ADORS("cClienteCode")))
'        .SubItems(4) = Format(LeerCampo(ADORS("TotVta")), "0.00")
'        .SubItems(5) = Format(LeerCampo(ADORS("FechaEmision")), "dd/mm/yyyy")
'        If mon = "DOLARES" Then
'        .SubItems(6) = "US$ " + Format(LeerCampo(ADORS("TotVtaUSD")), "0.00")
'        Else
'        .SubItems(6) = "S/. " + Format(LeerCampo(ADORS("TotVta")), "0.00")
'        End If
'        .SubItems(7) = LeerCampo(ADORS("DscCliente"))
'      End With
    End If
    
    
      If Index = 1 Then
        Set itm = lvwTX(Index).ListItems.Add(, , CStr(LeerCampo(ADORS("cOperCode"))))
        itm.SubItems(1) = IIf(LeerCampo(ADORS("cOperTipo")) = 12, "PADE", IIf(LeerCampo(ADORS("cOperTipo")) = 13, "PADV", "N/C"))
        itm.SubItems(2) = LeerCampo(ADORS("cdocserie")) & "-" & LeerCampo(ADORS("cdoccodigo"))
        itm.SubItems(3) = LeerCampo(ADORS("nTarjNumb"))
        itm.SubItems(4) = Format(LeerCampo(ADORS("nMontoSoles")), "0.00")
        itm.SubItems(5) = Format(LeerCampo(ADORS("dOperFech")), "dd/mm/yyyy")
        itm.SubItems(6) = LeerCampo(ADORS("cOpercodeRela"))
      End If
      ADORS.MoveNext
      bControl = True
    Loop
  End If
  
  If bControl Then
    If Index = 0 Then
      sSQL = " SELECT b.cOperCode, c.nTarjNumb, C.cClieCode, c.sName," & _
             " b.dOperFech, b.nMontoSoles, b.cOperTipo, b.sGlosa, b.cOpercodeRela, cdocserie, cdoccodigo" & _
             " FROM OperacionParalela b LEFT JOIN" & _
             " (SELECT Cliente.cClieCode, Tarjeta.nTarjNumb, sClieApel + ' ' + sClieName as sName" & _
             " FROM CLIENTE inner join Tarjeta" & _
             " ON Cliente.cClieCode = Tarjeta.cClieCode) c" & _
             " ON b.nTarjNumb = c.nTarjNumb" & _
             " WHERE cOperCodeRela = " + CStr(iOper) & _
             " AND b.cEstado = '1'"
      If oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then
        Do While Not ADORS.EOF
          Dim numoper As Long
          Dim exist As Boolean
          exist = False
          numoper = LeerCampo(ADORS("cOperCode"))
          
          'Verifica si el numero de TX ya existe
          For i = 1 To lvwTX(1).ListItems.Count
            If lvwTX(1).ListItems(i).Text = numoper Then
              exist = True
            End If
          Next
          
          If Not exist Then
            Set itm = lvwTX(1).ListItems.Add(, , CStr(numoper))
            itm.SubItems(1) = IIf(LeerCampo(ADORS("cOperTipo")) = 12, "PADE", IIf(LeerCampo(ADORS("cOperTipo")) = 13, "PADV", "N/C"))
            itm.SubItems(2) = LeerCampo(ADORS("cdocserie")) & "-" & LeerCampo(ADORS("cdoccodigo"))
            itm.SubItems(3) = LeerCampo(ADORS("nTarjNumb"))
            'itm.SubItems(4) = Format(LeerCampo(adoRS("nMontoSoles")), "###,##0.00")
            itm.SubItems(4) = Format(LeerCampo(ADORS("nMontoSoles")), "0.00")
            itm.SubItems(5) = Format(LeerCampo(ADORS("dOperFech")), "dd/mm/yyyy")
            itm.SubItems(6) = LeerCampo(ADORS("cOpercodeRela"))
          End If
          ADORS.MoveNext
        Loop
      End If
    End If
  End If
  
  TotalLiquidadas

Exit Sub
Salir:
Set cnSQL = Nothing
MsgBox Err.Description
End Sub

Private Sub CmdAddArt_Click(Index As Integer)

If Index = 2 Then
  If Me.TDGFacturacion.Row >= 0 And Trim(TDGFacturacion.Columns(1).Text) <> "" Then
    Me.TDGFacturacion.Row = gfax.UpperBound(1) + 1
  End If
  
  Me.TDGFacturacion.Col = 1
  Me.TDGFacturacion.SetFocus
ElseIf Index = 0 Then
  If Me.TDGNotaConsumo.Row >= 0 And Trim(TDGNotaConsumo.Columns(1).Text) <> "" Then
    Me.TDGNotaConsumo.Row = gfax2.UpperBound(1) + 1
  End If
  
  Me.TDGNotaConsumo.Col = 1
  Me.TDGNotaConsumo.SetFocus
End If

End Sub

Private Sub cmdAnulacionFact_Click()
  If cboTipoDocumento.ListIndex = -1 Then
    MsgBox "Debe elegir un tipo de documento...!", vbInformation + vbOKOnly, "Mensaje"
    Exit Sub
  End If
  
  frmAnularTransaccionCtaCte.iTipo = cboTipoDocumento.ListIndex
  frmAnularTransaccionCtaCte.Show vbModal
End Sub

Private Sub cmdAnularTransaccionPag_Click()
  Dim nFilas As Integer
  Dim strSerie As String
  Dim strNroDoc As String
  
  If dgdPagos.Row = -1 Then
    MsgBox "Debe seleccionar un pago...!", vbInformation + vbOKOnly, "Mensaje"
    Exit Sub
  End If
  
  strSerie = dgdPagos.Columns(0).Value
  strNroDoc = dgdPagos.Columns(1).Value
  
  strSerie = Trim(strSerie)
  strNroDoc = Trim(strNroDoc)
  
  frmAnularTransaccionCtaCte.sNroSerie = strSerie
  frmAnularTransaccionCtaCte.sNroDoc = strNroDoc
  frmAnularTransaccionCtaCte.iTipo = 2
  frmAnularTransaccionCtaCte.Show vbModal
  
  Call CargarPagos(iTipoDoc, iSerieDoc, iNroDoc, iMonedaDoc, iSaldo, iSaldoUSD)
End Sub

Private Sub cmdBoton_Click(Index As Integer)

Select Case Index
Case 0:
    LimpiarPagos
    'cboTipoDocumento1.Enabled = True
Case 1
Case 2
Case 3
    If ValidarPagos = True Then
        RegistrarPago
        'CargarPagos P_TipoDoc, P_cSerieDoc, P_NroDoc, P_Moneda, 0, 0 ' ObtenerSaldoDocumento(P_TipoDoc, P_cSerieDoc, P_NroDoc)
        LimpiarPagos
    End If
End Select

End Sub

Private Sub cmdBuscarDocumento_Click()
Dim sTipoDoc As String

If cboTipoDocumento1.Text = "FADE" Then
    sTipoDoc = "01"
ElseIf cboTipoDocumento1.Text = "BADE" Then
    sTipoDoc = "02"
Else
    MsgBox "Seleccione tipo documento", vbInformation + vbOKOnly, "Mensaje"
    cboTipoDocumento1.SetFocus
    Exit Sub
End If

frmDocumentosPendientesPago.sTipoDoc = sTipoDoc
frmDocumentosPendientesPago.Show vbModal
End Sub

Private Sub cmdBuscarDocumentoNC_Click()
Dim sTipoDoc As String

If cboTipoDocumento2 = "FADE" Then
    sTipoDoc = "01"
ElseIf cboTipoDocumento2 = "BADE" Then
    sTipoDoc = "02"
Else
    MsgBox "Seleccione tipo documento", vbInformation + vbOKOnly
    cboTipoDocumento2.SetFocus
    Exit Sub
End If

frmDocumentosPendientesNC.sTipoDoc = sTipoDoc
frmDocumentosPendientesNC.Show 1

End Sub
Private Function ValidarLiquidacion() As Boolean
'Dim bValor As Boolean

If cboTipoDocumento3.Text = "" Then
    ValidarLiquidacion = False
    MsgBox "Ingrese el Tipo Documento"
    cboTipoDocumento3.SetFocus
    Exit Function
End If

If txtTXL(0).Text = "" Then
    ValidarLiquidacion = False
    MsgBox "Ingrese correctamente el nro documento"
    txtTXL(0).SetFocus
    Exit Function
End If

If lvwTX(0).ListItems.Count = 0 Then
    ValidarLiquidacion = False
    MsgBox "Debe ingresar 1 documento"
    lvwTX(0).SetFocus
    
    Exit Function
    
End If

If lvwTX(0).ListItems.Count > 1 Then
    ValidarLiquidacion = False
    MsgBox "Debe ingresar solo 1 documento"
    lvwTX(0).SetFocus
    
    Exit Function
    
End If


ValidarLiquidacion = True

End Function

Private Sub CMDdel_Click(Index As Integer)
  Dim iOperRela As Long, i As Long
  
  If lvwTX(Index).ListItems.Count < 1 Then Exit Sub
  If Index = 0 Then iOperRela = lvwTX(0).SelectedItem.Text
  
  lvwTX(Index).ListItems.Remove (lvwTX(Index).SelectedItem.Index)
  
  If Index = 0 Then
    For i = lvwTX(1).ListItems.Count To 1 Step -1
      If val(lvwTX(1).ListItems(i).SubItems(6)) = iOperRela Then
        lvwTX(1).ListItems.Remove i
      End If
    Next
  End If
  
  TotalLiquidadas
End Sub

Private Sub CmdDelArt_Click(Index As Integer)
  Dim i As Integer
  
If Index = 2 Then
  If TDGFacturacion.Row <> -1 Then
    TDGFacturacion.Delete
    TDGFacturacion.Update
    TDGFacturacion.Refresh
  End If
  
  TDGFacturacion.Col = 1
  
  CalculaTotales
  CalculoVuelto
  Me.TDGFacturacion.SetFocus

ElseIf Index = 0 Then
  If TDGNotaConsumo.Row <> -1 Then
    TDGNotaConsumo.Delete
    TDGNotaConsumo.Update
    TDGNotaConsumo.Refresh
  End If
  
  TDGNotaConsumo.Col = 1
  
  CalculaTotales2
  'CalculoVuelto
  Me.TDGNotaConsumo.SetFocus

End If

End Sub

Private Sub cmdGrabaLiq_Click()

If ValidarLiquidacion = True Then

    If val(txtSolesLQ) < 0 Then
        If MsgBox("Hay un saldo a favor del cliente...¿Desea liquidar de todas maneras?", vbQuestion + vbYesNo, "Confirmar") = vbNo Then
            Exit Sub
        End If
    End If
    
    RegistrarLiquidacion
End If

End Sub

Private Sub cmdGrabarFactura_Click()
If ValidarFactura = True Then
    RegistrarVenta
    LimpiarFactura
End If
End Sub

Private Sub cmdGrabarNC_Click()

If ValidarConsumo = True Then
    If val(txtSolesNC.Text) > val(txtMontoPorConsumirDocumento) Then
        MsgBox "No puede consumir mas de " & txtMontoPorConsumirDocumento.Text & " Soles.", vbInformation + vbOKOnly
    Else
        RegistrarConsumo
    End If
End If

End Sub

Private Sub cmdNuevoCliente_Click()
frmCliente.Show 1
End Sub

Private Sub cmdsalir_Click()
Unload Me
End Sub


Private Sub cmdTXL_Click(Index As Integer)
If Index = 0 Then
Dim sTipoDoc As String

If cboTipoDocumento3 = "FADE" Then
    sTipoDoc = "01"
ElseIf cboTipoDocumento3 = "BADE" Then
    sTipoDoc = "02"
Else
    MsgBox "Seleccione tipo documento", vbInformation + vbOKOnly
    cboTipoDocumento3.SetFocus
    Exit Sub
End If

frmDocumentosPendientesLQ.sTipoDoc = sTipoDoc
frmDocumentosPendientesLQ.Show vbModal
'  frmBusquedaArticulos.frmPadre = "frmCajaRegistradoraFull"
'  frmBusquedaArticulos.pOpcion = "Liquidacion" + CStr(Index)
'  frmBusquedaArticulos.inicio
'  frmBusquedaArticulos.Show vbModal

End If
End Sub




Private Sub Command1_Click()
Unload Me
End Sub




Private Sub Command3_Click()
Unload Me
End Sub



Private Sub dcbBanco_Click(Area As Integer)
If dcbBanco.BoundText = "02" Then
    chkEsDetraccion.Visible = True
    txtNroCuenta.Text = RetornarNroCtaBN
    txtNroCuenta.Locked = True
    cboMoneda1.Text = "SOLES"
    txtMontoSoles.Text = RetornarMontoDetraccDocumento(P_cSerieDoc, P_NroDoc)
    txtMontoSoles_Change
    txtMontoSoles.Locked = True
    
Else
    chkEsDetraccion.Visible = False
    txtNroCuenta.Text = ""
    txtMontoSoles.Text = ""
    txtMontoSoles.Locked = False
    txtNroCuenta.Text = ""
    txtNroCuenta.Locked = False
    txtNroOperacion.Text = ""
    txtMontoDolares.Text = ""
End If
End Sub

Private Sub dcbFormaPago_Change()
If dcbFormaPago.BoundText = "01" Then 'efectivo
    lblTipoTarjeta.Visible = False: dcbTarjeta.Visible = False
    lblBanco.Visible = False: dcbBanco.Visible = False
    lblCertificadoRetencion.Visible = False: txtNroCertificadoRetencion.Visible = False
    lblDepositoDetraccion.Visible = False: txtNroDepositoDetraccion.Visible = False
    lblNroCuenta.Visible = False: txtNroCuenta.Visible = False
    lblNroOperacion.Visible = False: txtNroOperacion.Visible = False
    chkEsDetraccion.Visible = False: txtNroCuenta.Text = ""
    txtMontoSoles.Text = "": txtMontoDolares.Text = "": txtMontoSoles.Locked = False
    
ElseIf dcbFormaPago.BoundText = "02" Then 'tarjeta
    lblTipoTarjeta.Visible = True: dcbTarjeta.Visible = True
    lblBanco.Visible = False: dcbBanco.Visible = False
    lblCertificadoRetencion.Visible = False: txtNroCertificadoRetencion.Visible = False
    lblDepositoDetraccion.Visible = False: txtNroDepositoDetraccion.Visible = False
    lblNroCuenta.Visible = False: txtNroCuenta.Visible = False
    lblNroOperacion.Visible = False: txtNroOperacion.Visible = False
    chkEsDetraccion.Visible = False: txtNroCuenta.Text = ""
    txtMontoSoles.Text = "": txtMontoDolares.Text = "": txtMontoSoles.Locked = False
ElseIf dcbFormaPago.BoundText = "03" Then 'cert. retencion
    lblTipoTarjeta.Visible = False: dcbTarjeta.Visible = False
    lblBanco.Visible = False: dcbBanco.Visible = False
    lblCertificadoRetencion.Visible = True: txtNroCertificadoRetencion.Visible = True
    lblDepositoDetraccion.Visible = False: txtNroDepositoDetraccion.Visible = False
    lblNroCuenta.Visible = False: txtNroCuenta.Visible = False
    lblNroOperacion.Visible = False: txtNroOperacion.Visible = False
    chkEsDetraccion.Visible = False: txtNroCuenta.Text = ""
    txtMontoSoles.Text = "": txtMontoDolares.Text = "": txtMontoSoles.Locked = False
'ElseIf dcbFormaPago.BoundText = "04" Then 'dep. detraccion
'    lblTipoTarjeta.Visible = False: dcbTarjeta.Visible = False
'    lblBanco.Visible = False: dcbBanco.Visible = False
'    lblCertificadoRetencion.Visible = False: txtNroCertificadoRetencion.Visible = False
'    lblDepositoDetraccion.Visible = True: txtNroDepositoDetraccion.Visible = True
'    lblNroCuenta.Visible = False: txtNroCuenta.Visible = False
'    lblNroOperacion.Visible = False: txtNroOperacion.Visible = False
ElseIf dcbFormaPago.BoundText = "04" Then 'dep. cta cte
    lblTipoTarjeta.Visible = False: dcbTarjeta.Visible = False
    lblBanco.Visible = True: dcbBanco.Visible = True
    lblCertificadoRetencion.Visible = False: txtNroCertificadoRetencion.Visible = False
    lblDepositoDetraccion.Visible = False: txtNroDepositoDetraccion.Visible = False
    lblNroCuenta.Visible = True: txtNroCuenta.Visible = True
    lblNroOperacion.Visible = True: txtNroOperacion.Visible = True
    If dcbBanco.BoundText = "02" Then
        chkEsDetraccion.Visible = True
        txtNroCuenta.Text = RetornarNroCtaBN
        txtMontoSoles.Text = RetornarMontoDetraccDocumento(P_cSerieDoc, P_NroDoc)
        txtMontoSoles.Locked = True
    Else
        chkEsDetraccion.Visible = False
        txtNroCuenta.Text = ""
        txtMontoSoles.Locked = False
    End If
    
    'txtMontoSoles.Text = "": txtMontoDolares.Text = "": txtMontoSoles.Locked = False
End If
End Sub

Private Sub Form_Activate()

If SSTab1.Tab = 0 Then

    If Screen.ActiveControl.Name = "TDGFacturacion" Then
    Else
        txtTarjeta.SetFocus
    End If

    
End If

End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

  On Error Resume Next
  
If frmBusquedaArticulos.Visible = True Then
    'Unload frmBusquedaArticulos
    Exit Sub
End If

'SHIFT
'-----
'1, se está pulsando la tecla Shift (mayúsculas)
'2, se está pulsando Control
'4, se está pulsando Alt
'3, se están pulsando Shift y Ctrl,
'5, se están pulsando Shift y Alt,
'6, se están pulsando Ctrl y Alt,
'7, se están pulsando las tres teclas.

  Select Case Shift
  
    Case 0
      Select Case KeyCode
        Case vbKeyF1, vbKeyF4, vbKeyF6, vbKeyF7, vbKeyF8, _
             vbKeyF9, vbKeyF10, vbKeyF11, vbKeyF12 '112 To 123 ---- 01 - 12
'          Call cmdTecla_Click(KeyCode - 111)
           
        Case vbKeySpace
'            If Not iTipoVenta = 6 And Not iTipoVenta = 7 Then
'                Call cmdCambio_Click
'            End If
          
        Case vbKeyF5
          'Me.TDBGrid1.Row = gfax.UpperBound(1) + 1
          'Me.CalculaTotales
          'TDBGrid1.MoveLast
            If SSTab1.Tab = 0 Then
                Call CmdAddArt_Click(2)
                Call TDGFacturacion_ButtonClick(4)
            ElseIf SSTab1.Tab = 2 Then
                Call CmdAddArt_Click(0)
                Call TDGNotaConsumo_ButtonClick(4)
            End If
        Case vbKeyF2
            If SSTab1.Tab = 0 Then
                Call txtBuscaCliente_Click
            End If
        Case vbKeyF3
'          If TDBGrid1.Columns(8).Caption = "Dscto(S/.)" Then
'             TDBGrid1.Columns(8).Caption = "Recar(S/.)"
'          Else
'             TDBGrid1.Columns(8).Caption = "Dscto(S/.)"
'          End If
       
      End Select
    Case 1
'        Select Case KeyCode
'          Case vbKeyF1, vbKeyF2, vbKeyF3, vbKeyF4, vbKeyF5, vbKeyF6, vbKeyF7, vbKeyF8, _
'             vbKeyF9, vbKeyF10, vbKeyF11, vbKeyF12 '112 To 123 ---- 13 - 24
''          Call cmdTecla_Click(KeyCode - 99)
'        End Select
    Case 2
'        Select Case KeyCode
'         Case 13
'          cmdTecla(2).SetFocus
'          Call cmdTecla_Click(2) 'AC/TC
'         'Case 17
''          If frapade.Visible = True Then
''           Call cmdBuscaPago_Click
''          End If
'        End Select
    Case 4
'      Select Case KeyCode
''        Case vbKeyU
''           Me.txtVueltoDolares.SetFocus
'        Case vbKeyV
'          Me.txtVueltoDolares.SetFocus
'        Case 82
'            Me.txtRUC.SetFocus
'        Case vbKeyF4
'          Unload Me
'        Case vbKeyE
'          Me.txtEfectivoSoles.SetFocus
'        Case vbKeyT
'          Me.txtTarjeta.SetFocus
'        Case vbKey1
'          Me.SSTab1.Tab = 0
'        Case vbKey2
'          Me.SSTab1.Tab = 1
'        Case vbKey3
'          Me.SSTab1.Tab = 2
'        Case vbKeyX
'          Me.txtTX.SetFocus
        
'      End Select
    End Select
    
  Exit Sub

End Sub

Private Sub Form_Load()
Dim cont As Integer


  ConfiguraColumnas
  
  
    gfax.ReDim 0, 0, 0, 15
    gfax.Clear
    TDGFacturacion.ReBind
    cont = gfax.LowerBound(1)
    
    Set TDGFacturacion.Array = gfax
    TDGFacturacion.Update
    TDGFacturacion.Refresh
    TDGFacturacion.MoveFirst


    gfax2.ReDim 0, 0, 0, 15
    gfax2.Clear
    TDGNotaConsumo.ReBind
    'cont = gfax2.LowerBound(1)


    Set TDGNotaConsumo.Array = gfax2
    TDGNotaConsumo.Update
    TDGNotaConsumo.Refresh
    TDGNotaConsumo.MoveFirst

'    gfax2.ReDim 0, 0, 0, 13
'    gfax2.Clear
'    TDGPagos.ReBind
'    cont = gfax2.LowerBound(1)
'    Set TDGPagos.Array = gfax2
'    TDGPagos.Update
'    TDGPagos.Refresh
'    TDGPagos.MoveFirst

    DTPFechaEmision.Value = Now
    DTPFechaPago = Now

    CargarCombos
    IniciarControlesPago
    Inicio
    
    SSTab1.Tab = 0
    
End Sub

Private Sub SSTab1_Click(PreviousTab As Integer)
On Error Resume Next

If SSTab1.Tab = 0 Then
    txtTarjeta.SetFocus
ElseIf SSTab1.Tab = 2 Then
    cboTipoDocumento2.SetFocus
End If

End Sub

Private Sub TDGFacturacion_AfterColEdit(ByVal ColIndex As Integer)
  CalculaTotales
  TDGFacturacion.Update
  TDGFacturacion.Refresh
End Sub

Private Sub TDGFacturacion_AfterDelete()
  CalculaTotales
  TDGFacturacion.Update
  TDGFacturacion.Refresh
End Sub

Private Sub TDGFacturacion_BeforeColUpdate(ByVal ColIndex As Integer, OldValue As Variant, Cancel As Integer)
  Dim sSQL As String
  Dim ADORS As ADODB.Recordset
  Dim Texto As String
  Dim flag_1 As Integer
  Texto = TDGFacturacion.Text
  If TDGFacturacion.Columns(1) = "" And (ColIndex <> 2 And ColIndex <> 1) Then
    Beep
    Cancel = True
    Exit Sub
  End If
  
  Select Case ColIndex
    Case 0
    Case 1
      TDGFacturacion.Columns(1) = Right("000000" + Trim(Texto), 6)
      'Captura la descripción y precio unitario del articulo
      sSQL = " SELECT sProdDescCrta, nProdPrecUnit, cProdEstd, cFlagCanje, nPuntos, cFlagServicio, nActivo, ccodcatalogo, cprodcode FROM Producto" & _
             " WHERE cAlmaCode = '" & kPAR_ALMACEN & "' AND cProdCode = " + CStr(Texto)
        
      If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo LineaError
      If ADORS.RecordCount = 1 Then
        If LeerCampo(ADORS("cProdEstd")) <> 1 Or LeerCampo(ADORS("nActivo")) <> 1 Then
          MsgBox "El Producto no se encuentra activo."
          GoTo Salir
        End If
        TDGFacturacion.Columns(2) = LeerCampo(ADORS("ccodcatalogo"))
        TDGFacturacion.Columns(3) = LeerCampo(ADORS("sProdDescCrta"))
        TDGFacturacion.Columns(6) = "1.00"
        TDGFacturacion.Columns(7) = Format(LeerCampo(ADORS("nProdPrecUnit")), "0.00")
        TDGFacturacion.Columns(11) = IIf(LeerCampo(ADORS("cFlagCanje")) = 0, "NO", IIf(LeerCampo(ADORS("cFlagCanje")) = 1, "VNTA", "PTOS"))
        TDGFacturacion.Columns(12) = LeerCampo(ADORS("nPuntos"))
        TDGFacturacion.Columns(13) = IIf(LeerCampo(ADORS("cFlagServicio")) = 1, "SI", "NO")
        TDGFacturacion.Columns(8) = "-"
        TDGFacturacion.Columns(9) = "0.00"
        CalculaTotales
      End If
    
    Case 2
      sSQL = " SELECT  cProdCode, sProdDescCrta, nProdPrecUnit, cProdEstd, cFlagCanje, nPuntos, cFlagServicio, nActivo, ccodcatalogo FROM Producto" & _
             " WHERE cAlmaCode = '" & kPAR_ALMACEN & "' and nactivo=1" & _
             " AND ccodcatalogo like  '%" & Trim(Texto) & "' "
      
      If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo LineaError
      If Not ADORS.EOF Then
        TDGFacturacion.Columns(1) = Right("000000" + Trim(LeerCampo(ADORS("cProdCode"))), 6)
        TDGFacturacion.Columns(2) = LeerCampo(ADORS("ccodcatalogo"))
        TDGFacturacion.Columns(3) = LeerCampo(ADORS("sProdDescCrta"))
        TDGFacturacion.Columns(6) = "1.00"
        TDGFacturacion.Columns(7) = Format(LeerCampo(ADORS("nProdPrecUnit")), "0.00")
        TDGFacturacion.Columns(11) = IIf(LeerCampo(ADORS("cFlagCanje")) = 0, "NO", IIf(LeerCampo(ADORS("cFlagCanje")) = 1, "VNTA", "PTOS"))
        TDGFacturacion.Columns(12) = LeerCampo(ADORS("nPuntos"))
        TDGFacturacion.Columns(13) = IIf(LeerCampo(ADORS("cFlagServicio")) = 1, "SI", "NO")
        TDGFacturacion.Columns(8) = "-"
        TDGFacturacion.Columns(9) = "0.00"
        CalculaTotales
        Exit Sub
      End If
      
      '---------Buscando intensamente ---------------
      Texto = Replace(Texto, ".", "")
      
      If Not IsNumeric(Texto) Then
        Beep
        MsgBox "Articulo No Existe...!!!"
        Cancel = True
        flag_1 = 0
      Else
        'Captura la descripción y precio unitario del articulo
        flag_1 = 1
        sSQL = " SELECT cProdCode, sProdDescCrta, nProdPrecUnit, cProdEstd, cFlagCanje, nPuntos, cFlagServicio, nActivo, ccodcatalogo FROM Producto" & _
               " WHERE cAlmaCode = '" & kPAR_ALMACEN & "' and nactivo=1"
        
        If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo LineaError
        
        Texto = CDbl(Replace(Texto, ".", ""))
        
        Dim Buscar As Boolean
        Dim icatalogo As Long
        Dim sCatalogo As String
        Buscar = True
        If ADORS.RecordCount > 0 Then
          ADORS.MoveFirst
          Do While (Not ADORS.EOF)
            If Buscar = False Then
              Exit Do
            End If
            
            icatalogo = val(Replace(LeerCampo(ADORS("ccodcatalogo")), ".", ""))
            
            If icatalogo = val(Texto) Then
              Buscar = False
              Exit Do
              If LeerCampo(ADORS("cProdEstd")) <> 1 Or LeerCampo(ADORS("nActivo")) <> 1 Then
                MsgBox "El Producto no se encuentra activo."
                GoTo Salir
              End If
            End If
            ADORS.MoveNext
          Loop
        End If
      End If
      If Buscar = False Then
        If flag_1 = 1 Then
          TDGFacturacion.Columns(1) = Right("000000" + Trim(LeerCampo(ADORS("cProdCode"))), 6)
          TDGFacturacion.Columns(2) = LeerCampo(ADORS("ccodcatalogo"))
          TDGFacturacion.Columns(3) = LeerCampo(ADORS("sProdDescCrta"))
          TDGFacturacion.Columns(6) = "1.00"
          TDGFacturacion.Columns(7) = Format(LeerCampo(ADORS("nProdPrecUnit")), "0.00")
          
          TDGFacturacion.Columns(11) = IIf(LeerCampo(ADORS("cFlagCanje")) = 0, "NO", IIf(LeerCampo(ADORS("cFlagCanje")) = 1, "VNTA", "PTOS"))
          TDGFacturacion.Columns(12) = LeerCampo(ADORS("nPuntos"))
          TDGFacturacion.Columns(13) = IIf(LeerCampo(ADORS("cFlagServicio")) = 1, "SI", "NO")
          CalculaTotales
        End If
      Else
        TDGFacturacion.Columns(3) = ""
      End If
      If icatalogo <> val(Texto) Then
        MsgBox "Articulo No Existe...!!!"
        Beep
        Cancel = True
        Exit Sub
      End If
    
    Case 7, 9, 10
      If Not IsNumeric(Texto) Or val(Texto) < 0 Then
        Beep
        Cancel = True
      Else
        If ColIndex = 9 And (val(Texto) > 100 Or val(Texto) < 0) Then
          Beep
          MsgBox "Porcentaje Recargo/ Descuento incorrecto "
          Cancel = True
        Else
          TDGFacturacion.Text = Format(Texto, "0.00")
          CalculaTotales
        End If
      End If
      
    Case 6
      
      If Not IsNumeric(Texto) Or val(Texto) <= 0 Then
        Beep
        Cancel = True
      Else
        If Trim(TDGFacturacion.Text) <> "-" And val(Replace(TDGFacturacion.Columns(6), ",", "")) * val(Replace(TDGFacturacion.Columns(7), ",", "")) Then
          TDGFacturacion.Columns(9) = "0.00"
          CalculaTotales
        End If
        TDGFacturacion.Text = Format(Round(Texto, 0), "0.00")
        CalculaTotales
      End If
      
    Case 8
      If Trim(TDGFacturacion.Text) <> "-" And Trim(TDGFacturacion.Text) <> "+" Then
        TDGFacturacion.Text = "-"
        CalculaTotales
      Else
        If Trim(TDGFacturacion.Text) <> "-" And val(Replace(TDGFacturacion.Columns(6), ",", "")) * val(Replace(TDGFacturacion.Columns(7), ",", "")) Then
          TDGFacturacion.Columns(9) = "0.00"
          CalculaTotales
        End If
      End If
  End Select
  
  GoTo Salir
  
LineaError:
  MsgBox ("No se pudo seleccionar el artìculo")
Salir:
  Set ADORS = Nothing
  Me.TDGFacturacion.Update
  Me.TDGFacturacion.Refresh

End Sub

Private Sub TDGFacturacion_ButtonClick(ByVal ColIndex As Integer)
  On Error Resume Next
  Select Case ColIndex
    Case 4
      TDGFacturacion_LostFocus
      lcProdCode = ""
      frmBusquedaArticulos.frmPadre = "frmCajaFacturacionPagos"
      frmBusquedaArticulos.pOpcion = "Producto"
      frmBusquedaArticulos.Inicio
      frmBusquedaArticulos.Show vbModal
      If Trim(lcProdCode) <> "" Then
        TDGFacturacion.Columns(1) = lcProdCode
        TDGFacturacion.Columns(2) = lsCodCatalogo
        TDGFacturacion.Columns(6) = "1.00"
        TDGFacturacion.Columns(7) = lnProdPrecUnit
        TDGFacturacion.Columns(3) = lsProdDescCrta
        TDGFacturacion.Columns(11) = Me.lsCanje
        TDGFacturacion.Columns(12) = Me.lsPtos
        TDGFacturacion.Columns(13) = Me.lsServ
        TDGFacturacion.Columns(8) = "-"
        TDGFacturacion.Columns(9) = "0.00"
        TDGFacturacion.Columns(10) = "0.00"
        TDGFacturacion.Col = 6
        CalculaTotales
      End If
  End Select
  Me.TDGFacturacion.Update
  Me.TDGFacturacion.Refresh
  Me.TDGFacturacion.SetFocus
  Me.TDGFacturacion.SetFocus
End Sub

Private Sub TDGFacturacion_FootClick(ByVal ColIndex As Integer)
  'Descending sort
  Select Case ColIndex
    Case 0, 1
      gfax.QuickSort gfax.LowerBound(1), gfax.UpperBound(1), ColIndex, XORDER_DESCEND, XTYPE_STRING
    Case Else
      gfax.QuickSort gfax.LowerBound(1), gfax.UpperBound(1), ColIndex, XORDER_DESCEND, XTYPE_INTEGER
  End Select
  Me.TDGFacturacion.Update
  Me.TDGFacturacion.Refresh
  'Me.TDBGrid1.Refresh
End Sub

Private Sub TDGFacturacion_HeadClick(ByVal ColIndex As Integer)
  'Ascending sort
  Select Case ColIndex
    Case 0, 1
      gfax.QuickSort gfax.LowerBound(1), gfax.UpperBound(1), ColIndex, XORDER_ASCEND, XTYPE_STRING
    Case Else
      gfax.QuickSort gfax.LowerBound(1), gfax.UpperBound(1), ColIndex, XORDER_ASCEND, XTYPE_INTEGER
  End Select
  Me.TDGFacturacion.Update
  Me.TDGFacturacion.Refresh
  '  TDBGrid1.Refresh
End Sub

Private Sub TDGFacturacion_LostFocus()
  On Error Resume Next

  Dim i As Long
  CalculaTotales
  
  'TDBGrid1.ReBind
  TDGFacturacion.Refresh
  Set TDGFacturacion.Array = gfax
  TDGFacturacion.Update
  
'  TDBGrid1.Array = gfax
'  TDBGrid1.Update
End Sub

Private Sub TDGFacturacion_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
  On Error Resume Next
  Dim a, b, c As Double
  'TDBGrid1.Update
  'TDBGrid1.Refresh
  If IsNull(LastRow) Or IsNull(LastCol) Then Exit Sub
  
  If IsNull(gfax(LastRow, 6)) Or gfax(LastRow, 6) = "" Then gfax(LastRow, 6) = "1.00"
  If IsNull(gfax(LastRow, 7)) Or gfax(LastRow, 7) = "" Then gfax(LastRow, 7) = "0.00"
  If IsNull(gfax(LastRow, 9)) Or gfax(LastRow, 9) = "" Then gfax(LastRow, 9) = "0.00"
  If IsNull(gfax(LastRow, 10)) Or gfax(LastRow, 10) = "" Then gfax(LastRow, 10) = "0.00"
  If IsNull(gfax(LastRow, 0)) Or gfax(LastRow, 0) = "" Then gfax(LastRow, 0) = CStr(LastRow + 1)
  
  If IsNull(gfax(LastRow, 6)) Or gfax(LastRow, 6) = "" Then
    a = 0
  Else
    a = val(Replace(gfax(LastRow, 6), ",", ""))
  End If
  If IsNull(gfax(LastRow, 7)) Or gfax(LastRow, 7) = "" Then
    b = 0
  Else
    b = val(Replace(gfax(LastRow, 7), ",", ""))
  End If
  
  If IsNull(gfax(LastRow, 9)) Or gfax(LastRow, 9) = "" Then
    c = 0
  Else
    c = val(Replace(gfax(LastRow, 9), ",", ""))
  End If
  gfax(LastRow, 10) = Format(a * b * (100 - c) / 100, "0.00")
  'gfax(LastRow, 10) = Format(a * b * (100 - c) / 100, "###,###,###,###,##0.00")
    
  CalculaTotales
  Me.TDGFacturacion.Update
  Me.TDGFacturacion.Refresh

End Sub

Private Sub TDGNotaConsumo_AfterColEdit(ByVal ColIndex As Integer)
  CalculaTotales2
  TDGNotaConsumo.Update
  TDGNotaConsumo.Refresh
End Sub

Private Sub TDGNotaConsumo_AfterDelete()
  CalculaTotales2
  TDGNotaConsumo.Update
  TDGNotaConsumo.Refresh
End Sub

Private Sub TDGNotaConsumo_BeforeColUpdate(ByVal ColIndex As Integer, OldValue As Variant, Cancel As Integer)
  Dim sSQL As String
  Dim ADORS As ADODB.Recordset
  Dim Texto As String
  Dim flag_1 As Integer
  Texto = TDGNotaConsumo.Text
  If TDGNotaConsumo.Columns(1) = "" And (ColIndex <> 2 And ColIndex <> 1) Then
    Beep
    Cancel = True
    Exit Sub
  End If
  
  Select Case ColIndex
    Case 0
    Case 1
      TDGNotaConsumo.Columns(1) = Right("000000" + Trim(Texto), 6)
      'Captura la descripción y precio unitario del articulo
      sSQL = " SELECT sProdDescCrta, nProdPrecUnit, cProdEstd, cFlagCanje, nPuntos, cFlagServicio, nActivo, ccodcatalogo, cprodcode FROM Producto" & _
             " WHERE cAlmaCode = '" & kPAR_ALMACEN & "' AND cProdCode = " + CStr(Texto)
        
      If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo LineaError
      If ADORS.RecordCount = 1 Then
        If LeerCampo(ADORS("cProdEstd")) <> 1 Or LeerCampo(ADORS("nActivo")) <> 1 Then
          MsgBox "El Producto no se encuentra activo."
          GoTo Salir
        End If
        TDGNotaConsumo.Columns(2) = LeerCampo(ADORS("ccodcatalogo"))
        TDGNotaConsumo.Columns(3) = LeerCampo(ADORS("sProdDescCrta"))
        TDGNotaConsumo.Columns(6) = "1.00"
        TDGNotaConsumo.Columns(7) = Format(LeerCampo(ADORS("nProdPrecUnit")), "0.00")
        TDGNotaConsumo.Columns(11) = IIf(LeerCampo(ADORS("cFlagCanje")) = 0, "NO", IIf(LeerCampo(ADORS("cFlagCanje")) = 1, "VNTA", "PTOS"))
        TDGNotaConsumo.Columns(12) = LeerCampo(ADORS("nPuntos"))
        TDGNotaConsumo.Columns(13) = IIf(LeerCampo(ADORS("cFlagServicio")) = 1, "SI", "NO")
        TDGNotaConsumo.Columns(8) = "-"
        TDGNotaConsumo.Columns(9) = "0.00"
        CalculaTotales2
      End If
    
    Case 2
      sSQL = " SELECT  cProdCode, sProdDescCrta, nProdPrecUnit, cProdEstd, cFlagCanje, nPuntos, cFlagServicio, nActivo, ccodcatalogo FROM Producto" & _
             " WHERE cAlmaCode = '" & kPAR_ALMACEN & "' and nactivo=1" & _
             " AND ccodcatalogo like  '%" & Trim(Texto) & "' "
      
      If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo LineaError
      If Not ADORS.EOF Then
        TDGNotaConsumo.Columns(1) = Right("000000" + Trim(LeerCampo(ADORS("cProdCode"))), 6)
        TDGNotaConsumo.Columns(2) = LeerCampo(ADORS("ccodcatalogo"))
        TDGNotaConsumo.Columns(3) = LeerCampo(ADORS("sProdDescCrta"))
        TDGNotaConsumo.Columns(6) = "1.00"
        TDGNotaConsumo.Columns(7) = Format(LeerCampo(ADORS("nProdPrecUnit")), "0.00")
        TDGNotaConsumo.Columns(11) = IIf(LeerCampo(ADORS("cFlagCanje")) = 0, "NO", IIf(LeerCampo(ADORS("cFlagCanje")) = 1, "VNTA", "PTOS"))
        TDGNotaConsumo.Columns(12) = LeerCampo(ADORS("nPuntos"))
        TDGNotaConsumo.Columns(13) = IIf(LeerCampo(ADORS("cFlagServicio")) = 1, "SI", "NO")
        TDGNotaConsumo.Columns(8) = "-"
        TDGNotaConsumo.Columns(9) = "0.00"
        CalculaTotales2
        Exit Sub
      End If
      
      '---------Buscando intensamente ---------------
      Texto = Replace(Texto, ".", "")
      
      If Not IsNumeric(Texto) Then
        Beep
        MsgBox "Articulo No Existe...!!!"
        Cancel = True
        flag_1 = 0
      Else
        'Captura la descripción y precio unitario del articulo
        flag_1 = 1
        sSQL = " SELECT cProdCode, sProdDescCrta, nProdPrecUnit, cProdEstd, cFlagCanje, nPuntos, cFlagServicio, nActivo, ccodcatalogo FROM Producto" & _
               " WHERE cAlmaCode = '" & kPAR_ALMACEN & "' and nactivo=1"
        
        If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo LineaError
        
        Texto = CDbl(Replace(Texto, ".", ""))
        
        Dim Buscar As Boolean
        Dim icatalogo As Long
        Dim sCatalogo As String
        Buscar = True
        If ADORS.RecordCount > 0 Then
          ADORS.MoveFirst
          Do While (Not ADORS.EOF)
            If Buscar = False Then
              Exit Do
            End If
            
            icatalogo = val(Replace(LeerCampo(ADORS("ccodcatalogo")), ".", ""))
            
            If icatalogo = val(Texto) Then
              Buscar = False
              Exit Do
              If LeerCampo(ADORS("cProdEstd")) <> 1 Or LeerCampo(ADORS("nActivo")) <> 1 Then
                MsgBox "El Producto no se encuentra activo."
                GoTo Salir
              End If
            End If
            ADORS.MoveNext
          Loop
        End If
      End If
      If Buscar = False Then
        If flag_1 = 1 Then
          TDGNotaConsumo.Columns(1) = Right("000000" + Trim(LeerCampo(ADORS("cProdCode"))), 6)
          TDGNotaConsumo.Columns(2) = LeerCampo(ADORS("ccodcatalogo"))
          TDGNotaConsumo.Columns(3) = LeerCampo(ADORS("sProdDescCrta"))
          TDGNotaConsumo.Columns(6) = "1.00"
          TDGNotaConsumo.Columns(7) = Format(LeerCampo(ADORS("nProdPrecUnit")), "0.00")
          
          TDGNotaConsumo.Columns(11) = IIf(LeerCampo(ADORS("cFlagCanje")) = 0, "NO", IIf(LeerCampo(ADORS("cFlagCanje")) = 1, "VNTA", "PTOS"))
          TDGNotaConsumo.Columns(12) = LeerCampo(ADORS("nPuntos"))
          TDGNotaConsumo.Columns(13) = IIf(LeerCampo(ADORS("cFlagServicio")) = 1, "SI", "NO")
          CalculaTotales2
        End If
      Else
        TDGNotaConsumo.Columns(3) = ""
      End If
      If icatalogo <> val(Texto) Then
        MsgBox "Articulo No Existe...!!!"
        Beep
        Cancel = True
        Exit Sub
      End If
    
    Case 7, 9, 10
      If Not IsNumeric(Texto) Or val(Texto) < 0 Then
        Beep
        Cancel = True
      Else
        If ColIndex = 9 And (val(Texto) > 100 Or val(Texto) < 0) Then
          Beep
          MsgBox "Porcentaje Recargo/ Descuento incorrecto "
          Cancel = True
        Else
          TDGNotaConsumo.Text = Format(Texto, "0.00")
          CalculaTotales2
        End If
      End If
      
    Case 6
      
      If Not IsNumeric(Texto) Or val(Texto) <= 0 Then
        Beep
        Cancel = True
      Else
        If Trim(TDGNotaConsumo.Text) <> "-" And val(Replace(TDGNotaConsumo.Columns(6), ",", "")) * val(Replace(TDGNotaConsumo.Columns(7), ",", "")) Then
          TDGNotaConsumo.Columns(9) = "0.00"
          CalculaTotales2
        End If
        TDGNotaConsumo.Text = Format(Round(Texto, 0), "0.00")
        CalculaTotales2
      End If
      
    Case 8
      If Trim(TDGNotaConsumo.Text) <> "-" And Trim(TDGNotaConsumo.Text) <> "+" Then
        TDGNotaConsumo.Text = "-"
        CalculaTotales2
      Else
        If Trim(TDGNotaConsumo.Text) <> "-" And val(Replace(TDGNotaConsumo.Columns(6), ",", "")) * val(Replace(TDGNotaConsumo.Columns(7), ",", "")) Then
          TDGNotaConsumo.Columns(9) = "0.00"
          CalculaTotales2
        End If
      End If
  End Select
  
  GoTo Salir
  
LineaError:
  MsgBox ("No se pudo seleccionar el artìculo")
Salir:
  Set ADORS = Nothing
  Me.TDGNotaConsumo.Update
  Me.TDGNotaConsumo.Refresh

End Sub

Private Sub TDGNotaConsumo_ButtonClick(ByVal ColIndex As Integer)
  On Error Resume Next
  Select Case ColIndex
    Case 4
      TDGNotaConsumo_LostFocus
      lcProdCode = ""
      frmBusquedaArticulos.frmPadre = "frmCajaFacturacionPagos"
      frmBusquedaArticulos.pOpcion = "Producto"
      frmBusquedaArticulos.Inicio
      frmBusquedaArticulos.Show vbModal
      If Trim(lcProdCode) <> "" Then
        TDGNotaConsumo.Columns(1) = lcProdCode
        TDGNotaConsumo.Columns(2) = lsCodCatalogo
        TDGNotaConsumo.Columns(6) = "1.00"
        TDGNotaConsumo.Columns(7) = lnProdPrecUnit
        TDGNotaConsumo.Columns(3) = lsProdDescCrta
        TDGNotaConsumo.Columns(11) = Me.lsCanje
        TDGNotaConsumo.Columns(12) = Me.lsPtos
        TDGNotaConsumo.Columns(13) = Me.lsServ
        TDGNotaConsumo.Columns(8) = "-"
        TDGNotaConsumo.Columns(9) = "0.00"
        TDGNotaConsumo.Columns(10) = "0.00"
        TDGNotaConsumo.Col = 6
        CalculaTotales
      End If
  End Select
  Me.TDGNotaConsumo.Update
  Me.TDGNotaConsumo.Refresh
  Me.TDGNotaConsumo.SetFocus
End Sub

Private Sub TDGNotaConsumo_FootClick(ByVal ColIndex As Integer)
  'Descending sort
  Select Case ColIndex
    Case 0, 1
      gfax2.QuickSort gfax2.LowerBound(1), gfax2.UpperBound(1), ColIndex, XORDER_DESCEND, XTYPE_STRING
    Case Else
      gfax2.QuickSort gfax2.LowerBound(1), gfax2.UpperBound(1), ColIndex, XORDER_DESCEND, XTYPE_INTEGER
  End Select
  Me.TDGNotaConsumo.Update
  Me.TDGNotaConsumo.Refresh
  'Me.TDBGrid1.Refresh
End Sub

Private Sub TDGNotaConsumo_HeadClick(ByVal ColIndex As Integer)
  'Ascending sort
  Select Case ColIndex
    Case 0, 1
      gfax2.QuickSort gfax2.LowerBound(1), gfax2.UpperBound(1), ColIndex, XORDER_ASCEND, XTYPE_STRING
    Case Else
      gfax2.QuickSort gfax2.LowerBound(1), gfax2.UpperBound(1), ColIndex, XORDER_ASCEND, XTYPE_INTEGER
  End Select
  Me.TDGNotaConsumo.Update
  Me.TDGNotaConsumo.Refresh
  '  TDBGrid1.Refresh
End Sub

Private Sub TDGNotaConsumo_LostFocus()
  On Error Resume Next

  Dim i As Long
  CalculaTotales2
  
  'TDBGrid1.ReBind
  TDGNotaConsumo.Refresh
  Set TDGNotaConsumo.Array = gfax2
  TDGNotaConsumo.Update
  
'  TDBGrid1.Array = gfax
'  TDBGrid1.Update

End Sub

Private Sub TDGNotaConsumo_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
  On Error Resume Next
  Dim a, b, c As Double
  'TDBGrid1.Update
  'TDBGrid1.Refresh
  If IsNull(LastRow) Or IsNull(LastCol) Then Exit Sub
  
  If IsNull(gfax2(LastRow, 6)) Or gfax2(LastRow, 6) = "" Then gfax2(LastRow, 6) = "1.00"
  If IsNull(gfax2(LastRow, 7)) Or gfax2(LastRow, 7) = "" Then gfax2(LastRow, 7) = "0.00"
  If IsNull(gfax2(LastRow, 9)) Or gfax2(LastRow, 9) = "" Then gfax2(LastRow, 9) = "0.00"
  If IsNull(gfax2(LastRow, 10)) Or gfax2(LastRow, 10) = "" Then gfax2(LastRow, 10) = "0.00"
  If IsNull(gfax2(LastRow, 0)) Or gfax2(LastRow, 0) = "" Then gfax2(LastRow, 0) = CStr(LastRow + 1)
  
  If IsNull(gfax2(LastRow, 6)) Or gfax2(LastRow, 6) = "" Then
    a = 0
  Else
    a = val(Replace(gfax2(LastRow, 6), ",", ""))
  End If
  If IsNull(gfax2(LastRow, 7)) Or gfax2(LastRow, 7) = "" Then
    b = 0
  Else
    b = val(Replace(gfax2(LastRow, 7), ",", ""))
  End If
  
  If IsNull(gfax2(LastRow, 9)) Or gfax2(LastRow, 9) = "" Then
    c = 0
  Else
    c = val(Replace(gfax2(LastRow, 9), ",", ""))
  End If
  gfax2(LastRow, 10) = Format(a * b * (100 - c) / 100, "0.00")
  'gfax(LastRow, 10) = Format(a * b * (100 - c) / 100, "###,###,###,###,##0.00")
    
  CalculaTotales2
  Me.TDGNotaConsumo.Update
  Me.TDGNotaConsumo.Refresh

End Sub

Private Sub txtBuscaCliente_Click()
  frmBusquedaArticulos.frmPadre = "frmCajaFacturacionPagos"
  frmBusquedaArticulos.pOpcion = "Cliente"
  frmBusquedaArticulos.Inicio
  frmBusquedaArticulos.txtBuscar.Text = txtTarjeta.Text
  frmBusquedaArticulos.cmdBuscar_Click
  frmBusquedaArticulos.Show vbModal
  txtNombres.Enabled = (Trim(txtTarjeta.Text) = "")
  txtNombres.Locked = Not (Trim(txtTarjeta.Text) = "")
End Sub


Public Sub CalculaTotales()
  On Error Resume Next
  Dim i As Long
  Dim lTotal, lSubtotal, lCant, lPrec, lDscto, lservicio As Double
  Dim sCant, sPrec, sDscto, sFlagServicio As String
  Dim iEfectivoSoles As Double
  
  iEfectivoSoles = 0
  If iTipoVenta = 8 Then
    'txtDolares.Text = Format((lTotal / nTipoCambio), "###,###,###,###,###.00")
  Else
    'TDBGrid1.Update
    'TDBGrid1.Refresh
    lTotal = 0
    nTotIGV = 0
    
    For i = gfax.LowerBound(1) To gfax.UpperBound(1)
      sCant = IIf(IsEmpty(gfax(i, 6)), "1.00", gfax(i, 6))
      sPrec = IIf(IsEmpty(gfax(i, 7)), "0.00", gfax(i, 7))
      sDscto = IIf(IsEmpty(gfax(i, 9)), "0.00", gfax(i, 9))
      sFlagServicio = IIf(gfax(i, 13) = "SI", "1", "0")
    
      sCant = IIf(sCant = "", "0.00", sCant)
      sPrec = IIf(sPrec = "", "0.00", sPrec)
      sDscto = IIf(sDscto = "", "0.00", sDscto)
    
      sCant = Replace(sCant, ",", "")
      sPrec = Replace(sPrec, ",", "")
      sDscto = Replace(sDscto, ",", "")
    
      If IsNumeric(sCant) And IsNumeric(sPrec) Then
        lCant = val(sCant)
        lPrec = val(sPrec)
        lDscto = (val(sDscto) / 100 * lCant * lPrec)
'        If iTipoVenta = 1 Or iTipoVenta = 2 Or iTipoVenta = 3 Or iTipoVenta = 5 Or iTipoVenta = 4 Then
'          lservicio = val(sFlagServicio) * kPAR_PORCSERV / 100
'        Else
'          lservicio = 0
'        End If
                
        lservicio = val(sFlagServicio) * kPAR_PORCSERV / 100

        lSubtotal = lCant * lPrec
        If gfax(i, 8) = "+" Then
          lSubtotal = lSubtotal + lDscto
        Else
          lSubtotal = lSubtotal - lDscto
        End If
      
        gfax(i, 10) = Format(lSubtotal, "0.00")
        Dim Serv As Double
        Dim Igv As Double
        
        Serv = ((lSubtotal / (kIGV + lservicio + 1))) * lservicio
        Igv = ((lSubtotal / (kIGV + lservicio + 1))) * kIGV
               
        gfax(i, 14) = Format(Serv, "0.00")
        gfax(i, 15) = Format(Igv, "0.00")
        
        lTotal = lTotal + lSubtotal
        
        nTotIGV = nTotIGV + Igv
      End If
    Next
    
     txtSoles.Text = Format(Abs(lTotal), "0.00")
     txtDolares.Text = Format(Abs(lTotal / nTipoCambio), "0.00")
  End If
  
  'CalculoVuelto
  
  ' vd 05-09-07
  'TDBGrid1.Update
  'TDBGrid1.Refresh
  
End Sub
Public Sub CalculaTotales2()
  On Error Resume Next
  Dim i As Long
  Dim lTotal, lSubtotal, lCant, lPrec, lDscto, lservicio As Double
  Dim sCant, sPrec, sDscto, sFlagServicio As String
  Dim iEfectivoSoles As Double
  
  iEfectivoSoles = 0
  If iTipoVenta = 8 Then
    'txtDolares.Text = Format((lTotal / nTipoCambio), "###,###,###,###,###.00")
  Else
    'TDBGrid1.Update
    'TDBGrid1.Refresh
    lTotal = 0
    'nTotIGV = 0
    
    For i = gfax2.LowerBound(1) To gfax2.UpperBound(1)
      sCant = IIf(IsEmpty(gfax2(i, 6)), "1.00", gfax2(i, 6))
      sPrec = IIf(IsEmpty(gfax2(i, 7)), "0.00", gfax2(i, 7))
      sDscto = IIf(IsEmpty(gfax2(i, 9)), "0.00", gfax2(i, 9))
      sFlagServicio = IIf(gfax2(i, 13) = "SI", "1", "0")
    
      sCant = IIf(sCant = "", "0.00", sCant)
      sPrec = IIf(sPrec = "", "0.00", sPrec)
      sDscto = IIf(sDscto = "", "0.00", sDscto)
    
      sCant = Replace(sCant, ",", "")
      sPrec = Replace(sPrec, ",", "")
      sDscto = Replace(sDscto, ",", "")
    
      If IsNumeric(sCant) And IsNumeric(sPrec) Then
        lCant = val(sCant)
        lPrec = val(sPrec)
        lDscto = (val(sDscto) / 100 * lCant * lPrec)
'        If iTipoVenta = 1 Or iTipoVenta = 2 Or iTipoVenta = 3 Or iTipoVenta = 5 Or iTipoVenta = 4 Then
'          lservicio = val(sFlagServicio) * kPAR_PORCSERV / 100
'        Else
'          lservicio = 0
'        End If
          lservicio = val(sFlagServicio) * kPAR_PORCSERV / 100
        
                
        lSubtotal = lCant * lPrec
        If gfax2(i, 8) = "+" Then
          lSubtotal = lSubtotal + lDscto
        Else
          lSubtotal = lSubtotal - lDscto
        End If
      
        gfax2(i, 10) = Format(lSubtotal, "0.00")
        Dim Serv As Double
        Dim Igv As Double
        
        Serv = ((lSubtotal / (kIGV + lservicio + 1))) * lservicio
        Igv = ((lSubtotal / (kIGV + lservicio + 1))) * kIGV
               
        gfax2(i, 14) = Format(Serv, "0.00")
        gfax2(i, 15) = Format(Igv, "0.00")
        
        lTotal = lTotal + lSubtotal
        
        'nTotIGV = nTotIGV + Igv
      End If
    Next
    
     txtSolesNC.Text = Format(Abs(lTotal), "0.00")
     txtDolaresNC.Text = Format(Abs(lTotal / nTipoCambio), "0.00")
  End If
  
  'CalculoVuelto
  
  ' vd 05-09-07
  'TDBGrid1.Update
  'TDBGrid1.Refresh
End Sub

Private Sub txtLocal_KeyDown(KeyCode As Integer, Shift As Integer)
  Select Case KeyCode
    Case 13
      If IsNumeric(txtLocal.Text) And (val(txtLocal.Text) = 1 Or val(txtLocal.Text) = 2) Then
        'Call txtTarjeta_LostFocus
        Call LlamarCliente
      End If
  End Select
End Sub

Private Sub txtMontoDolares_Change()
If cboMoneda1.Text = "DOLARES" Then
    If txtMontoDolares.Text <> "" And IsNumeric(txtMontoDolares.Text) Then
        'lblMontoDolares.Caption = Format(Abs(txtMontoSoles / nTipoCambio), "0.00")
        txtMontoSoles.Text = Format(Abs(txtMontoDolares * nTipoCambio), "0.00")
    Else
        If txtMontoDolares.Text = "" Then
            txtMontoSoles.Text = ""
        End If
        
    End If
End If
End Sub

Private Sub txtMontoDolares_KeyDown(KeyCode As Integer, Shift As Integer)
If cboMoneda1.Text = "" Then
    MsgBox "Seleccione moneda", vbInformation + vbOKOnly, "Mensaje"
    txtMontoDolares.Text = ""
    Exit Sub
End If
End Sub

Private Sub txtMontoSoles_Change()



If cboMoneda1.Text = "SOLES" Then
    If txtMontoSoles.Text <> "" And IsNumeric(txtMontoSoles.Text) Then
        'lblMontoDolares.Caption = Format(Abs(txtMontoSoles / nTipoCambio), "0.00")
        txtMontoDolares.Text = Format(Abs(txtMontoSoles / nTipoCambio), "0.00")
    
    Else
        If txtMontoSoles.Text = "" Then
            txtMontoDolares.Text = ""
        End If
    
    End If
End If
End Sub

Private Sub txtMontoSoles_KeyDown(KeyCode As Integer, Shift As Integer)
If cboMoneda1.Text = "" Then
    MsgBox "Seleccione moneda", vbInformation + vbOKOnly, "Mensaje"
    txtMontoSoles.Text = ""
    Exit Sub
End If
End Sub

Private Sub txtTarjeta_KeyDown(KeyCode As Integer, Shift As Integer)
  Select Case KeyCode
    Case vbKeyF5
      'txtBuscaCliente_Click
    Case 13
      'Call txtTarjeta_LostFocus
      Call LlamarCliente
  End Select
End Sub

Private Sub RegistrarVentaBCK()

Dim cnSQL As ADODB.Connection
Dim ADORS As ADODB.Recordset
Dim sSQL As String
Dim blnfactura As Boolean
Dim cDocSerie As String
Dim cdocTipo As String
Dim iCodOper As Long
Dim cRuc As String
Dim cDocCodigofull As Long
Dim nImporte As Double
Dim iTotal, iTotalVenta As Double, iSubTotal As Double, iSubTotalDscto As Double
Dim iIGV As Double
Dim i As Integer
Dim iTipoVenta As Integer
Dim sTexto As String
Dim sTarjeta As String

On Error GoTo Salir

iTipoVenta = cboTipoDocumento.ListIndex


If iTipoVenta = -1 Then
    Exit Sub
ElseIf iTipoVenta = 0 Then
    blnfactura = True
    cRuc = Trim(Me.txtRUC.Text)
    cdocTipo = "01"
    cDocSerie = kSERIE_FACTURA
ElseIf iTipoVenta = 1 Then
    cRuc = ""
    cdocTipo = "02"
    cDocSerie = kSERIE
End If

  

ConfiguraImpresora kPAR_IMPRESORA_ALTERNA

  'Verifica si es un tipo de operaciòn que necesita password: Anulación o Descuento
  For i = gfax.LowerBound(1) To gfax.UpperBound(1)
    sTexto = IIf(Replace(gfax(i, 9), ",", "") = "", "0", Replace(gfax(i, 9), ",", ""))
    If val(sTexto) <> 0 Then
      bAcceso = True
      Exit For
    End If
  Next
  
  If bAcceso Then
    bAcceso = False
    Load frmAutorizarOperacion
    Set frmAutorizarOperacion.frmPadre = Me
    frmAutorizarOperacion.Show vbModal
    If Not bAcceso Then Exit Sub
    'bAcceso = False
  End If
  

  'sSQL = "SELECT sImpresora, sImpresoraAlterna from Configuracion"
  'If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, rs1) Then GoTo Salir--->ACCESS
  
  If Not oDBAdmin.AbrirBD(cnSQL, psConnectString) Then GoTo Salir 'OMNISYS
  
  'If Not oDBAdmin.AbrirBD(cnSQL, psCadenaConexionSQLServer) Then GoTo Salir 'OMNICLIENT
  
  cnSQL.BeginTrans
  ADOCnn.BeginTrans
  
  sSQL = "SELECT isnull(max(CAST(cCodVta AS INT)),0) as maximo FROM venta01"


  
  If Not oDBAdmin.EjecutarConsulta(cnSQL, 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
  
  
  ' Obteniendo Nro de documento
  sSQL = "SELECT  * FROM Config_Documento WHERE cTipoDoc='" & cdocTipo & "'"
  If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
     
  If blnfactura = True Then
    If ADORS.EOF Then
      kSERIE_FACTURA = "F01"
      sSQL = "INSERT INTO Config_Documento (cTipoDoc,cOperCode,nDocCodigo,cSerieDoc,cUserDesc,dUltAct,observacion) " & _
             " VALUES ('01',0, 0, 'F01','',#" & Date & "#,'Primer Registro') "
      If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
      cDocCodigofull = 1
    Else
      kSERIE_FACTURA = LeerCampo(ADORS!cSerieDoc)
      cDocCodigofull = LeerCampo(ADORS!nDocCodigo) + 1
    End If
    cDocSerie = kSERIE_FACTURA
  Else
        If ADORS.EOF Then
          kSERIE = "B01"
          sSQL = "INSERT INTO Config_Documento (cTipoDoc,cOperCode,nDocCodigo,cSerieDoc,cUserDesc,dUltAct,observacion)" & _
                 " VALUES ('02',0, 0, 'B01', '', #" & Date & "#,'Primer Registro') "
          If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
          cDocCodigofull = 1
        Else
          kSERIE = LeerCampo(ADORS!cSerieDoc)
          cDocCodigofull = LeerCampo(ADORS!nDocCodigo) + 1
        End If
        cDocSerie = kSERIE
  End If
  
  
  
  '---------------Actualizando el valor de la numeración ----------------
  sSQL = "UPDATE Config_Documento " & _
         " SET cSerieDoc='" & cDocSerie & "'," & _
         " nDocCodigo=" & cDocCodigofull & " " & _
         " WHERE cTipodoc='" & cdocTipo & "'"
  If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
  

iTotal = val(Replace(txtSoles, ",", ""))
iMontoDolares = val(Replace(txtDolares, ",", ""))
iIGV = Round(nTotIGV, 2)



'    sSql = "INSERT INTO Venta01(cCodVta,TipoDoc,cSerieDoc,NroDoc,cCodCaja,cClienteCode,IdLocal,DscCliente,NroRuc,ValorVta,Igv,TotVta,nPorcIGV,TotVtaUSD,cCodMoneda,nTipoCambio,cCodTipoCredito,fechaemision,FechaAnulacion,FechaVencimiento,cCodCabVtaRef) " _
'& "VALUES (" & iCodOper & ",'" & cdocTipo & "','" & cDocSerie & "','" & Format(cDocCodigofull, "000000") & "','" & kPAR_CAJA & "','" & txtTarjeta.Text & "','" & txtLocal.Text & "','" & txtNombres.Text & "','" & txtRUC.Text & "'," & iTotal - iIGV & "," & iIGV & "," & iTotal & "," & kIGV & "," & iMontoDolares & ",'N'," & nTipoCambio & ",'" & dcbTipoCredito.BoundText & "','" & Format(DTPFechaEmision.Value, "dd/MM/yyyy") & "',null,null,null)"
'
'  If Not oDBAdmin.EjecutarSentencia(cnSQL, sSql) Then GoTo Salir
  
  Dim xNumItem As Integer
  xNumItem = 1
  
  
    ReDim Producto(gfax.UpperBound(1))
    
    For i = gfax.LowerBound(1) To gfax.UpperBound(1)
      Producto(i).Almacen = kPAR_ALMACEN
      Producto(i).Cant = Replace(gfax(i, 6), ",", "")
      Producto(i).PUnit = Replace(gfax(i, 7), ",", "")
      Producto(i).Codigo = gfax(i, 1)
      Producto(i).nombre = gfax(i, 3)
      If gfax(i, 8) = "+" Then
        Producto(i).Dscto = Replace(IIf(gfax(i, 9) = "", 0, gfax(i, 9)), ",", "")
      Else
        Producto(i).Dscto = -1 * Replace(IIf(gfax(i, 9) = "", 0, gfax(i, 9)), ",", "")
      End If
      
      Producto(i).Canje = gfax(i, 11)
      Producto(i).Ptos = val(Replace(gfax(i, 12), ",", ""))
      Producto(i).Serv = gfax(i, 13)
    Next
    nProducto = gfax.UpperBound(1)
  
  
  If Trim(txtTarjeta.Text) <> "" Then
    sTarjeta = Right("00000000" + Trim(txtTarjeta.Text), 8)
  Else
    sTarjeta = ""
  End If
  
  
  
  
  
  
  
  
  
  
  
    For i = 0 To nProducto

        sSQL = "INSERT INTO Venta02(cCodVta,NroItem,cCodartic,sProdDscCrta,nPrecioOrig,nQtdVendida,nDescuento,nServicio) " _
        & "VALUES (" & iCodOper & "," & xNumItem & ",'" & CStr(Producto(i).Codigo) & "','" & Producto(i).nombre & "'," & Producto(i).PUnit & "," & Producto(i).Cant & "," & CStr(Producto(i).Dscto) & "," & IIf(gfax(i, 13) = "SI", kPAR_PORCSERV, "0") & ")"

        If Not oDBAdmin.EjecutarSentencia(cnSQL, sSQL) Then GoTo Salir

        xNumItem = xNumItem + 1
    Next
  
  
    
    
    
    ADOCnn.CommitTrans
    cnSQL.CommitTrans
  
  
Set cnSQL = Nothing
Exit Sub
Salir:
MsgBox Err.Description
ADOCnn.RollbackTrans
cnSQL.RollbackTrans
Set cnSQL = Nothing


End Sub

Private Function RetornarPorcDetracc() As Double
Dim nRetorno As Double
Dim cnSQL As ADODB.Connection
Dim sSQL As String
Dim ADORS As ADODB.Recordset

nRetorno = 0

If Not oDBAdmin.AbrirBD(cnSQL, psConnectString) Then GoTo Salir 'OMNISYS

sSQL = "select nmonto1 from parametro where cCodParam='DETRP'"
If Not oDBAdmin.EjecutarConsulta(cnSQL, sSQL, ADORS) Then GoTo Salir
  
  If ADORS.RecordCount > 0 Then
    nRetorno = ADORS!nmonto1
  End If

RetornarPorcDetracc = nRetorno

Set cnSQL = Nothing
Exit Function
Salir:
RetornarPorcDetracc = 0
Set cnSQL = Nothing
MsgBox Err.Description

End Function
Private Function RetornarMontoDetraccDocumento(sSerie As String, sNumero As String) As Double
Dim nRetorno As Double
Dim cnSQL As ADODB.Connection
Dim sSQL As String
Dim ADORS As ADODB.Recordset

nRetorno = 0

If Not oDBAdmin.AbrirBD(cnSQL, psConnectString) Then GoTo Salir 'OMNISYS

sSQL = "SELECT MontoDetracc FROM DETRACCION WHERE SerieDoc='" & sSerie & "' and NroDoc='" & sNumero & "'"


If Not oDBAdmin.EjecutarConsulta(cnSQL, sSQL, ADORS) Then GoTo Salir
  
  If ADORS.RecordCount > 0 Then
    nRetorno = ADORS!MontoDetracc
  End If

RetornarMontoDetraccDocumento = nRetorno

Set cnSQL = Nothing
Exit Function
Salir:
RetornarMontoDetraccDocumento = 0
Set cnSQL = Nothing
MsgBox Err.Description


End Function
Private Function RetornarMontoDetracc() As Double
Dim nRetorno As Double
Dim cnSQL As ADODB.Connection
Dim sSQL As String
Dim ADORS As ADODB.Recordset

nRetorno = 0

If Not oDBAdmin.AbrirBD(cnSQL, psConnectString) Then GoTo Salir 'OMNISYS

sSQL = "select nmonto1 from parametro where cCodParam='DETRS'"


If Not oDBAdmin.EjecutarConsulta(cnSQL, sSQL, ADORS) Then GoTo Salir
  
  If ADORS.RecordCount > 0 Then
    nRetorno = ADORS!nmonto1
  End If

RetornarMontoDetracc = nRetorno

Set cnSQL = Nothing
Exit Function
Salir:
RetornarMontoDetracc = 0
Set cnSQL = Nothing
MsgBox Err.Description


End Function
Private Function RetornarPendientePagoDetracc(ByVal Serie As String, ByVal numero As String) As Boolean
Dim bRetorno As Boolean
Dim cnSQL As ADODB.Connection
Dim sSQL As String
Dim ADORS As ADODB.Recordset


bRetorno = False
If Not oDBAdmin.AbrirBD(cnSQL, psConnectString) Then GoTo Salir 'OMNISYS

sSQL = "select MontoDetracc from detraccion where SerieDoc='" & Serie & "' and NroDoc='" & numero & "' and estado='P' "

If Not oDBAdmin.EjecutarConsulta(cnSQL, sSQL, ADORS) Then GoTo Salir


  If ADORS.RecordCount > 0 Then
    bRetorno = True
  End If
  
RetornarPendientePagoDetracc = bRetorno

Set cnSQL = Nothing
Exit Function
Salir:
RetornarPendientePagoDetracc = False
Set cnSQL = Nothing
MsgBox Err.Description

End Function

Private Function RetornarNroCtaBN() As String
Dim sRetorno As String
Dim cnSQL As ADODB.Connection
Dim sSQL As String
Dim ADORS As ADODB.Recordset


If Not oDBAdmin.AbrirBD(cnSQL, psConnectString) Then GoTo Salir 'OMNISYS

sSQL = "select vtexto1 from parametro where cCodParam='CTABN'"

If Not oDBAdmin.EjecutarConsulta(cnSQL, sSQL, ADORS) Then GoTo Salir


  If ADORS.RecordCount > 0 Then
    sRetorno = ADORS!vtexto1
  End If
  
RetornarNroCtaBN = sRetorno

Set cnSQL = Nothing
Exit Function
Salir:
RetornarNroCtaBN = ""
Set cnSQL = Nothing
MsgBox Err.Description

End Function

Private Function RetornarMontoxPagar() As String

End Function

Private Function RetornarAfectoDetraccion(ByVal sCod As String) As Boolean
Dim bRetorno As Boolean
Dim sSQL As String
Dim ADORS As ADODB.Recordset

bRetorno = False


  sSQL = "SELECT  cFlagDetracc FROM Producto WHERE cProdCode=" & sCod & ""
  
  If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir

  If ADORS.RecordCount > 0 Then
    If ADORS!cFlagDetracc = "1" Then
        bRetorno = True
    Else
        bRetorno = False
    End If
  End If

RetornarAfectoDetraccion = bRetorno

Exit Function
Salir:
RetornarAfectoDetraccion = False
MsgBox Err.Description

End Function

Private Function RetornarConsumoxDocumento(ByVal cCodVta As String) As Double

Dim nRetorno As Double
Dim sSQL As String
Dim ADORS As ADODB.Recordset

nRetorno = 0


  sSQL = "SELECT  SUM(nMontoSoles) as Total FROM OperacionParalela WHERE cOperCodeRela=" & cCodVta & " AND cDocTipo='11' and sGlosa like '*REF. SIST. LOGISTICA*'"
  
  If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir

  If ADORS.RecordCount > 0 Then
        If IsNull(ADORS!Total) Then
            nRetorno = 0
        Else
        
        nRetorno = ADORS!Total
        End If
  End If

RetornarConsumoxDocumento = nRetorno

Exit Function
Salir:
RetornarConsumoxDocumento = 0
MsgBox Err.Description

End Function

Private Sub ConfiguraColumnas()
  Dim i As Integer, x As Integer
  Dim clmX As ColumnHeader
  Dim aColumnTitle() As String
  Dim aColumnWidth() As Single
  Dim aColumnAlign() As Integer
     
  ReDim aColumnTitle(15) As String
  ReDim aColumnWidth(15) As Single
  ReDim aColumnAlign(15) As Integer
    
  aColumnTitle(0) = "TX"
  aColumnTitle(1) = "Tipo"
  aColumnTitle(2) = "Doc"
  aColumnTitle(3) = "Tarjeta"
  aColumnTitle(4) = "Total(S/.)"
  aColumnTitle(5) = "Fecha"
  aColumnTitle(6) = "Monto Orig."
  aColumnTitle(7) = "Cliente - Glosa"
  'aColumnTitle(2) = "Tarjeta"
  'aColumnTitle(3) = "Cliente"
 
  aColumnWidth(0) = 0
  aColumnWidth(1) = 0
  aColumnWidth(2) = 0.15
  aColumnWidth(3) = 0.15
  aColumnWidth(4) = 0.2
  aColumnWidth(5) = 0.23
  aColumnWidth(6) = 0.25
  aColumnWidth(7) = 0.5
        
  aColumnAlign(0) = lvwColumnLeft
  aColumnAlign(1) = lvwColumnLeft
  aColumnAlign(2) = lvwColumnCenter
  aColumnAlign(3) = lvwColumnLeft
  aColumnAlign(4) = lvwColumnRight
  aColumnAlign(5) = lvwColumnCenter
  aColumnAlign(6) = lvwColumnCenter
    
  For i = 0 To (UBound(aColumnTitle) - 1)
    Set clmX = lvwTX(0).ColumnHeaders.Add(, , aColumnTitle(i), _
                                            lvwTX(0).Width * aColumnWidth(i), _
                                            aColumnAlign(i))
  Next
  
  ReDim aColumnTitle(15) As String
  ReDim aColumnWidth(15) As Single
  ReDim aColumnAlign(15) As Integer
    
  aColumnTitle(0) = "TX"
  aColumnTitle(1) = "Tipo"
  aColumnTitle(2) = "Doc"
  aColumnTitle(3) = "Tarjeta"
  'aColumnTitle(2) = "Tarjeta"
  'aColumnTitle(3) = "Cliente"
  aColumnTitle(4) = "Total(S/.)"
  aColumnTitle(5) = "Fecha"
  aColumnTitle(6) = "FADE/BADE"
    
  aColumnWidth(0) = 0
  aColumnWidth(1) = 0
  aColumnWidth(2) = 0.15
  aColumnWidth(3) = 0.15
  aColumnWidth(4) = 0.2
  aColumnWidth(5) = 0.23
  aColumnWidth(6) = 0.22
        
  aColumnAlign(0) = lvwColumnLeft
  aColumnAlign(1) = lvwColumnLeft
  aColumnAlign(2) = lvwColumnCenter
  aColumnAlign(3) = lvwColumnLeft
  aColumnAlign(4) = lvwColumnRight
  aColumnAlign(5) = lvwColumnCenter
    
  For i = 0 To (UBound(aColumnTitle) - 1)
    Set clmX = lvwTX(1).ColumnHeaders.Add(, , aColumnTitle(i), _
                                            lvwTX(1).Width * aColumnWidth(i), _
                                            aColumnAlign(i))
  Next
  
End Sub


Private Sub TotalLiquidadas()
  Dim i As Long
  Dim iTotal1 As Double, iTotal2 As Double, iEfectivoSoles As Double
  iTotal1 = 0
  iTotal2 = 0
       
  For i = 1 To lvwTX(0).ListItems.Count
    iTotal1 = iTotal1 + val(Replace(lvwTX(0).ListItems(i).SubItems(4), ",", ""))
  Next
  For i = 1 To lvwTX(1).ListItems.Count
    iTotal2 = iTotal2 + val(Replace(lvwTX(1).ListItems(i).SubItems(4), ",", ""))
  Next
  'txtTotalPA = Format(iTotal1, "0.00")
  'txtTotalNC = Format(iTotal2, "0.00")
  'txtSoles = Format((iTotal2 - iTotal1), "0.00")
 'txtDolares = Format((iTotal2 - iTotal1) / nTipoCambio, "0.00")
  txtTotalPA = Format(iTotal1, "0.00")
  txtTotalNC = Format(iTotal2, "0.00")
  txtSolesLQ = Format((iTotal2 - iTotal1), "0.00")
  txtDolaresLQ = Format((iTotal2 - iTotal1) / nTipoCambio, "0.00")
'  txtEfectivoSoles = "0.00"
'  txtEfectivoDolares = "0.00"
'  txtVueltoDolares = "0.00"
'  txtVueltoSoles = "0.00"
  
'  If txtSoles = "0.00" Then
'    txtEfectivoSoles = "0.00"
'     txtEfectivoSoles.BackColor = &H80000018
'     txtEfectivoSoles.Locked = True
'   Else
'     txtEfectivoSoles.BackColor = &HFFFFFF
'     txtEfectivoSoles.Locked = False
'   End If
   'CalculoVuelto
End Sub

Private Sub CalculoVuelto()

  If Trim(txtEfectivoSoles.Text) = "" Then txtEfectivoSoles.Text = "0.00"
  If Trim(txtEfectivoDolares.Text) = "" Then txtEfectivoDolares.Text = "0.00"
  If Trim(txtVueltoDolares.Text) = "" Then txtVueltoDolares.Text = "0.00"
  'txtVueltoDolares.Text = Format(txtVueltoDolares.Text, "0.00")
  txtVueltoDolares.Text = Format(txtVueltoDolares.Text, "0.00")
  If val(Replace(txtEfectivoDolares, ",", "")) <= val(Replace(txtVueltoDolares, ",", "")) Then
    txtVueltoDolares.Text = "0.00"
  End If
  
  If ((val(Replace(txtEfectivoDolares, ",", "")) - val(Replace(txtVueltoDolares, ",", ""))) * nTipoCambio) >= val(Replace(txtSoles, ",", "")) Then
    txtEfectivoSoles.Text = "0.00"
  End If
      
  If (iTipoVenta = 1 Or iTipoVenta = 4 Or iTipoVenta = 8) And (Trim(txtEfectivoSoles.Tag) = "") Then
    
    txtEfectivoSoles.Text = Format(val(Replace(txtSoles, ",", "")) - _
                            val(Replace(txtEfectivoDolares, ",", "")) * nTipoCambio + _
                            val(Replace(txtVueltoDolares, ",", "")) * nTipoCambio + _
                            val(Replace(txtVueltoSoles, ",", "")), "0.00")
                            'Val(Replace(txtVueltoSoles, ",", "")), "0.00")
      
    If val(Replace(txtEfectivoSoles.Text, ",", "")) < 0 Then
      'txtVueltoSoles.Text = Format(-Val(Replace(txtEfectivoSoles.Text, ",", "")), "0.00")
      txtVueltoSoles.Text = Format(-val(Replace(txtEfectivoSoles.Text, ",", "")), "0.00")
      txtEfectivoSoles.Text = "0.00"
    End If
    
  End If
  
  'EfectivoSolesCambia
  
End Sub


