VERSION 5.00
Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
Object = "{F0D2F211-CCB0-11D0-A316-00AA00688B10}#1.0#0"; "MSDATLST.OCX"
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Object = "{BDC217C8-ED16-11CD-956C-0000C04E4C0A}#1.1#0"; "TABCTL32.OCX"
Object = "{00025600-0000-0000-C000-000000000046}#5.2#0"; "crystl32.ocx"
Object = "{69F9D01E-F1DE-11D4-9536-002018603DA2}#7.0#0"; "ControlNumber.ocx"
Begin VB.Form fnotacreditodebito 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Nota de Crédito (05.030.00)"
   ClientHeight    =   6930
   ClientLeft      =   1845
   ClientTop       =   1560
   ClientWidth     =   11820
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   ScaleHeight     =   6930
   ScaleWidth      =   11820
   Begin TabDlg.SSTab SSTab1 
      Height          =   6855
      Left            =   0
      TabIndex        =   0
      Top             =   0
      Width           =   11775
      _ExtentX        =   20770
      _ExtentY        =   12091
      _Version        =   393216
      Tabs            =   2
      TabHeight       =   520
      TabCaption(0)   =   "Generar"
      TabPicture(0)   =   "fnotacreditodebito.frx":0000
      Tab(0).ControlEnabled=   -1  'True
      Tab(0).Control(0)=   "lbl_noafecto"
      Tab(0).Control(0).Enabled=   0   'False
      Tab(0).Control(1)=   "lbl_totalgen"
      Tab(0).Control(1).Enabled=   0   'False
      Tab(0).Control(2)=   "lbligv"
      Tab(0).Control(2).Enabled=   0   'False
      Tab(0).Control(3)=   "lblsubtotal"
      Tab(0).Control(3).Enabled=   0   'False
      Tab(0).Control(4)=   "Shape1"
      Tab(0).Control(4).Enabled=   0   'False
      Tab(0).Control(5)=   "Line1"
      Tab(0).Control(5).Enabled=   0   'False
      Tab(0).Control(6)=   "dbdetalle"
      Tab(0).Control(6).Enabled=   0   'False
      Tab(0).Control(7)=   "Frame2"
      Tab(0).Control(7).Enabled=   0   'False
      Tab(0).Control(8)=   "fraDatosItem"
      Tab(0).Control(8).Enabled=   0   'False
      Tab(0).Control(9)=   "cmd_Cancelar"
      Tab(0).Control(9).Enabled=   0   'False
      Tab(0).Control(10)=   "cmdnuevo"
      Tab(0).Control(10).Enabled=   0   'False
      Tab(0).Control(11)=   "TXT_NOAFECTO"
      Tab(0).Control(11).Enabled=   0   'False
      Tab(0).Control(12)=   "TXT_MONEDATOTAL"
      Tab(0).Control(12).Enabled=   0   'False
      Tab(0).Control(13)=   "txt_total"
      Tab(0).Control(13).Enabled=   0   'False
      Tab(0).Control(14)=   "txt_igv"
      Tab(0).Control(14).Enabled=   0   'False
      Tab(0).Control(15)=   "txt_subtotal"
      Tab(0).Control(15).Enabled=   0   'False
      Tab(0).Control(16)=   "cmddocumentos"
      Tab(0).Control(16).Enabled=   0   'False
      Tab(0).Control(17)=   "cmd_efectivo"
      Tab(0).Control(17).Enabled=   0   'False
      Tab(0).Control(18)=   "cmd_salir"
      Tab(0).Control(18).Enabled=   0   'False
      Tab(0).Control(19)=   "cmdMarcar"
      Tab(0).Control(19).Enabled=   0   'False
      Tab(0).Control(20)=   "cmdDesmarcar"
      Tab(0).Control(20).Enabled=   0   'False
      Tab(0).Control(21)=   "crReporte"
      Tab(0).Control(21).Enabled=   0   'False
      Tab(0).ControlCount=   22
      TabCaption(1)   =   "Consultar/Anular"
      TabPicture(1)   =   "fnotacreditodebito.frx":001C
      Tab(1).ControlEnabled=   0   'False
      Tab(1).Control(0)=   "lbltotalpen"
      Tab(1).Control(0).Enabled=   0   'False
      Tab(1).Control(1)=   "lbltotalusd"
      Tab(1).Control(1).Enabled=   0   'False
      Tab(1).Control(2)=   "DBConsNotadeCredito"
      Tab(1).Control(2).Enabled=   0   'False
      Tab(1).Control(3)=   "Frame3"
      Tab(1).Control(3).Enabled=   0   'False
      Tab(1).Control(4)=   "Frame4"
      Tab(1).Control(4).Enabled=   0   'False
      Tab(1).Control(5)=   "cmdAnulaDoc"
      Tab(1).Control(5).Enabled=   0   'False
      Tab(1).Control(6)=   "cmdReimprimir"
      Tab(1).Control(6).Enabled=   0   'False
      Tab(1).ControlCount=   7
      Begin Crystal.CrystalReport crReporte 
         Left            =   1920
         Top             =   6000
         _ExtentX        =   741
         _ExtentY        =   741
         _Version        =   348160
         PrintFileLinesPerPage=   60
      End
      Begin VB.CommandButton cmdDesmarcar 
         Enabled         =   0   'False
         Height          =   495
         Left            =   10440
         Picture         =   "fnotacreditodebito.frx":0038
         Style           =   1  'Graphical
         TabIndex        =   101
         ToolTipText     =   "Descartar devolver todos los item"
         Top             =   3120
         Width           =   735
      End
      Begin VB.CommandButton cmdMarcar 
         Enabled         =   0   'False
         Height          =   495
         Left            =   10440
         Picture         =   "fnotacreditodebito.frx":0342
         Style           =   1  'Graphical
         TabIndex        =   102
         ToolTipText     =   "Devolver todos los item"
         Top             =   2640
         Width           =   735
      End
      Begin VB.CommandButton cmd_salir 
         Cancel          =   -1  'True
         Caption         =   "&Salir"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   9.75
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   855
         Left            =   10440
         Picture         =   "fnotacreditodebito.frx":064C
         Style           =   1  'Graphical
         TabIndex        =   100
         ToolTipText     =   "Salir del Formulario"
         Top             =   5520
         Width           =   1050
      End
      Begin VB.CommandButton cmd_efectivo 
         Caption         =   "Grabar "
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   9.75
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   855
         Left            =   10440
         Picture         =   "fnotacreditodebito.frx":0956
         Style           =   1  'Graphical
         TabIndex        =   99
         Tag             =   "R ASDASD"
         ToolTipText     =   "Generar Nota de Credito"
         Top             =   4680
         Width           =   1050
      End
      Begin VB.CommandButton cmddocumentos 
         Caption         =   "Documentos"
         Enabled         =   0   'False
         Height          =   855
         Left            =   10440
         Picture         =   "fnotacreditodebito.frx":0E88
         Style           =   1  'Graphical
         TabIndex        =   98
         ToolTipText     =   "Utilize esta opcion si desea emitir una Nota de Credito para multiples documentos"
         Top             =   3840
         Width           =   1050
      End
      Begin VB.TextBox txt_subtotal 
         Alignment       =   1  'Right Justify
         BackColor       =   &H00E0E0E0&
         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          =   360
         Left            =   3840
         TabIndex        =   93
         TabStop         =   0   'False
         Text            =   "0.00"
         Top             =   6240
         Width           =   1335
      End
      Begin VB.TextBox txt_igv 
         Alignment       =   1  'Right Justify
         BackColor       =   &H00E0E0E0&
         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          =   360
         Left            =   6960
         TabIndex        =   92
         TabStop         =   0   'False
         Text            =   "0.00"
         Top             =   6240
         Width           =   1215
      End
      Begin VB.TextBox txt_total 
         Alignment       =   1  'Right Justify
         BackColor       =   &H00E0E0E0&
         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          =   360
         Left            =   8640
         TabIndex        =   91
         TabStop         =   0   'False
         Text            =   "0.00"
         Top             =   6240
         Width           =   1335
      End
      Begin VB.TextBox TXT_MONEDATOTAL 
         Alignment       =   1  'Right Justify
         BackColor       =   &H00E0E0E0&
         Enabled         =   0   'False
         Height          =   360
         Left            =   8280
         TabIndex        =   90
         TabStop         =   0   'False
         Top             =   6240
         Width           =   375
      End
      Begin VB.TextBox TXT_NOAFECTO 
         Alignment       =   1  'Right Justify
         BackColor       =   &H00E0E0E0&
         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          =   360
         Left            =   5400
         TabIndex        =   89
         TabStop         =   0   'False
         Text            =   "0.00"
         Top             =   6240
         Width           =   1215
      End
      Begin VB.CommandButton cmdnuevo 
         Caption         =   "Nuevo"
         Height          =   255
         Left            =   10440
         TabIndex        =   88
         Top             =   6240
         Visible         =   0   'False
         Width           =   1050
      End
      Begin VB.CommandButton cmd_Cancelar 
         Caption         =   "Cancelar"
         Height          =   855
         Left            =   10440
         Picture         =   "fnotacreditodebito.frx":1192
         Style           =   1  'Graphical
         TabIndex        =   85
         Top             =   5400
         Visible         =   0   'False
         Width           =   1050
      End
      Begin VB.CommandButton cmdReimprimir 
         Caption         =   "Imprimir"
         Height          =   825
         Left            =   -64560
         Picture         =   "fnotacreditodebito.frx":149C
         Style           =   1  'Graphical
         TabIndex        =   84
         Top             =   5280
         Width           =   1155
      End
      Begin VB.CommandButton cmdAnulaDoc 
         Caption         =   "ANULAR"
         Height          =   855
         Left            =   -64560
         MouseIcon       =   "fnotacreditodebito.frx":17A6
         MousePointer    =   99  'Custom
         Picture         =   "fnotacreditodebito.frx":1AB0
         Style           =   1  'Graphical
         TabIndex        =   77
         ToolTipText     =   "Anular Documento"
         Top             =   4440
         Width           =   1155
      End
      Begin VB.Frame Frame4 
         Height          =   735
         Left            =   -74880
         TabIndex        =   63
         Top             =   5520
         Width           =   10095
         Begin VB.TextBox txtsubtotal 
            Alignment       =   1  'Right Justify
            BackColor       =   &H00E0E0E0&
            Enabled         =   0   'False
            Height          =   360
            Left            =   1320
            TabIndex        =   68
            TabStop         =   0   'False
            Top             =   240
            Width           =   1335
         End
         Begin VB.TextBox txtigv 
            Alignment       =   1  'Right Justify
            BackColor       =   &H00E0E0E0&
            Enabled         =   0   'False
            Height          =   360
            Left            =   5880
            TabIndex        =   67
            TabStop         =   0   'False
            Top             =   240
            Width           =   975
         End
         Begin VB.TextBox txttotal 
            Alignment       =   1  'Right Justify
            BackColor       =   &H00E0E0E0&
            Enabled         =   0   'False
            Height          =   360
            Left            =   8280
            TabIndex        =   66
            TabStop         =   0   'False
            Top             =   240
            Width           =   1335
         End
         Begin VB.TextBox txtsimbolo 
            Alignment       =   1  'Right Justify
            BackColor       =   &H00E0E0E0&
            Enabled         =   0   'False
            Height          =   360
            Left            =   7920
            TabIndex        =   65
            TabStop         =   0   'False
            Top             =   240
            Width           =   375
         End
         Begin VB.TextBox txtnoafecto 
            Alignment       =   1  'Right Justify
            BackColor       =   &H00E0E0E0&
            Enabled         =   0   'False
            Height          =   360
            Left            =   4200
            TabIndex        =   64
            TabStop         =   0   'False
            Top             =   240
            Width           =   975
         End
         Begin VB.Label Label25 
            Caption         =   "Sub Total"
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   12
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   120
            TabIndex        =   72
            Top             =   240
            Width           =   1215
         End
         Begin VB.Label Label24 
            Caption         =   "IGV"
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   12
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   5400
            TabIndex        =   71
            Top             =   240
            Width           =   495
         End
         Begin VB.Label Label23 
            Caption         =   "Total"
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   12
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   7200
            TabIndex        =   70
            Top             =   240
            Width           =   615
         End
         Begin VB.Label Label22 
            Caption         =   "No Afecto"
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   12
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   3000
            TabIndex        =   69
            Top             =   240
            Width           =   1215
         End
      End
      Begin VB.Frame Frame3 
         Height          =   2175
         Left            =   -74880
         TabIndex        =   43
         Top             =   360
         Width           =   11295
         Begin VB.ComboBox cmbReferencia 
            Height          =   315
            Left            =   8400
            Style           =   2  'Dropdown List
            TabIndex        =   103
            Top             =   240
            Width           =   2655
         End
         Begin VB.TextBox txtnumerodocu 
            Height          =   315
            Left            =   1560
            MaxLength       =   10
            TabIndex        =   78
            Top             =   240
            Width           =   1575
         End
         Begin VB.CommandButton cmdnumerodocumento 
            Height          =   375
            Left            =   3240
            MouseIcon       =   "fnotacreditodebito.frx":1DBA
            MousePointer    =   99  'Custom
            Picture         =   "fnotacreditodebito.frx":1F0C
            Style           =   1  'Graphical
            TabIndex        =   76
            ToolTipText     =   "Buscar Documento"
            Top             =   240
            Width           =   585
         End
         Begin VB.TextBox txtruc 
            Enabled         =   0   'False
            Height          =   320
            Left            =   8640
            MaxLength       =   11
            TabIndex        =   54
            Top             =   960
            Width           =   1900
         End
         Begin VB.TextBox txtdireccion 
            Enabled         =   0   'False
            Height          =   285
            Left            =   5640
            TabIndex        =   53
            Top             =   1680
            Width           =   4935
         End
         Begin VB.TextBox txtapellido 
            BeginProperty DataFormat 
               Type            =   0
               Format          =   "HH:mm:ss"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   3082
               SubFormatType   =   0
            EndProperty
            Enabled         =   0   'False
            Height          =   285
            Left            =   5640
            TabIndex        =   52
            Top             =   1320
            Width           =   4935
         End
         Begin VB.TextBox txtcodcliente 
            Enabled         =   0   'False
            Height          =   320
            Left            =   5640
            MaxLength       =   11
            TabIndex        =   51
            Top             =   960
            Width           =   2055
         End
         Begin VB.Label lblReferencias 
            Caption         =   "Referencias"
            Height          =   255
            Left            =   7320
            TabIndex        =   104
            Top             =   300
            Width           =   975
         End
         Begin VB.Label Lblestado 
            BackColor       =   &H8000000E&
            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          =   315
            Left            =   1560
            TabIndex        =   87
            Top             =   1680
            Width           =   1695
         End
         Begin VB.Label Label26 
            Caption         =   "Estado"
            Height          =   255
            Left            =   120
            TabIndex        =   86
            Top             =   1680
            Width           =   1215
         End
         Begin VB.Label lblstatus 
            Height          =   255
            Left            =   1440
            TabIndex        =   83
            Top             =   1800
            Visible         =   0   'False
            Width           =   1935
         End
         Begin VB.Label lbltipopagocons 
            Height          =   255
            Left            =   240
            TabIndex        =   82
            Top             =   1800
            Visible         =   0   'False
            Width           =   1575
         End
         Begin VB.Label lblmonedacons 
            Height          =   255
            Left            =   1560
            TabIndex        =   79
            Top             =   1800
            Visible         =   0   'False
            Width           =   1695
         End
         Begin VB.Label lbltiporeferencia 
            BackColor       =   &H80000009&
            BorderStyle     =   1  'Fixed Single
            Height          =   315
            Left            =   5640
            TabIndex        =   75
            Top             =   240
            Visible         =   0   'False
            Width           =   1575
         End
         Begin VB.Label lblnumerorefer 
            BackColor       =   &H80000009&
            BorderStyle     =   1  'Fixed Single
            Height          =   315
            Left            =   8880
            TabIndex        =   74
            Top             =   240
            Visible         =   0   'False
            Width           =   1575
         End
         Begin VB.Label lblfecharefer 
            BackColor       =   &H80000009&
            BorderStyle     =   1  'Fixed Single
            Height          =   315
            Left            =   5640
            TabIndex        =   73
            Top             =   600
            Visible         =   0   'False
            Width           =   1575
         End
         Begin VB.Label Label21 
            Alignment       =   1  'Right Justify
            AutoSize        =   -1  'True
            Caption         =   "Fecha Doc.Ref.:"
            Height          =   195
            Left            =   4080
            TabIndex        =   61
            Top             =   600
            Visible         =   0   'False
            Width           =   1185
         End
         Begin VB.Label Label20 
            Alignment       =   1  'Right Justify
            AutoSize        =   -1  'True
            Caption         =   "Ruc:"
            Height          =   285
            Left            =   8160
            TabIndex        =   60
            Top             =   960
            Width           =   345
         End
         Begin VB.Label Label19 
            Alignment       =   1  'Right Justify
            AutoSize        =   -1  'True
            Caption         =   "Direccion:"
            Height          =   225
            Left            =   4080
            TabIndex        =   59
            Top             =   1680
            Width           =   720
         End
         Begin VB.Label Label18 
            Alignment       =   1  'Right Justify
            AutoSize        =   -1  'True
            Caption         =   "Apellido/R.S.:"
            Height          =   195
            Left            =   4080
            TabIndex        =   58
            Top             =   1320
            Width           =   990
         End
         Begin VB.Label Label17 
            Alignment       =   1  'Right Justify
            AutoSize        =   -1  'True
            Caption         =   "Codigo Cliente:"
            Height          =   195
            Left            =   4080
            TabIndex        =   57
            Top             =   960
            Width           =   1065
         End
         Begin VB.Label Label16 
            Alignment       =   1  'Right Justify
            AutoSize        =   -1  'True
            Caption         =   "Tipo Doc.Referencia:"
            Height          =   195
            Left            =   4080
            TabIndex        =   56
            Top             =   240
            Visible         =   0   'False
            Width           =   1530
         End
         Begin VB.Label Label15 
            Alignment       =   1  'Right Justify
            AutoSize        =   -1  'True
            Caption         =   "No.Doc.Referencia:"
            Height          =   195
            Left            =   7320
            TabIndex        =   55
            Top             =   240
            Visible         =   0   'False
            Width           =   1425
         End
         Begin VB.Label lbltipodecambio 
            BackColor       =   &H80000009&
            BorderStyle     =   1  'Fixed Single
            Height          =   315
            Left            =   1560
            TabIndex        =   50
            Top             =   1320
            Width           =   1095
         End
         Begin VB.Label Label14 
            Alignment       =   1  'Right Justify
            AutoSize        =   -1  'True
            Caption         =   "Tipo Cambio:"
            Height          =   285
            Left            =   120
            TabIndex        =   49
            Top             =   1320
            Width           =   930
         End
         Begin VB.Label lblfechadocumento 
            BackColor       =   &H80000009&
            BorderStyle     =   1  'Fixed Single
            Height          =   315
            Left            =   1560
            TabIndex        =   48
            Top             =   960
            Width           =   2055
         End
         Begin VB.Label lblfechaproceso 
            BackColor       =   &H80000009&
            BorderStyle     =   1  'Fixed Single
            Height          =   315
            Left            =   1560
            TabIndex        =   47
            Top             =   600
            Width           =   1575
         End
         Begin VB.Label Label13 
            Caption         =   "Fecha Documento"
            Height          =   255
            Left            =   120
            TabIndex        =   46
            Top             =   960
            Width           =   1455
         End
         Begin VB.Label Label10 
            Caption         =   "Fecha Proceso"
            Height          =   255
            Left            =   120
            TabIndex        =   45
            Top             =   600
            Width           =   1215
         End
         Begin VB.Label lblnumerodocumento 
            Caption         =   "Nro. Documento"
            Height          =   255
            Left            =   120
            TabIndex        =   44
            Top             =   240
            Width           =   1335
         End
      End
      Begin VB.Frame fraDatosItem 
         Appearance      =   0  'Flat
         BackColor       =   &H80000004&
         ForeColor       =   &H80000008&
         Height          =   855
         Left            =   120
         TabIndex        =   13
         Top             =   4800
         Width           =   9975
         Begin VB.CommandButton cmdNuevoItem 
            Caption         =   "Nuevo"
            Height          =   495
            Left            =   5880
            Picture         =   "fnotacreditodebito.frx":243E
            Style           =   1  'Graphical
            TabIndex        =   37
            Top             =   1080
            Visible         =   0   'False
            Width           =   855
         End
         Begin VB.CommandButton cmdEliminarItem 
            Caption         =   "Eliminar"
            Height          =   495
            Left            =   6840
            Picture         =   "fnotacreditodebito.frx":2970
            Style           =   1  'Graphical
            TabIndex        =   36
            Top             =   1080
            Visible         =   0   'False
            Width           =   855
         End
         Begin VB.CommandButton cmdActualizaItem 
            Caption         =   "Actualizar"
            Height          =   495
            Left            =   7920
            Picture         =   "fnotacreditodebito.frx":2A72
            Style           =   1  'Graphical
            TabIndex        =   35
            Top             =   1080
            Visible         =   0   'False
            Width           =   855
         End
         Begin MiControl.CtrlNumber ctnadevolver 
            Height          =   375
            Left            =   8280
            TabIndex        =   14
            Top             =   360
            Width           =   1215
            _ExtentX        =   2143
            _ExtentY        =   661
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
         End
         Begin VB.Label lblarticulo 
            BorderStyle     =   1  'Fixed Single
            Height          =   255
            Left            =   1800
            TabIndex        =   42
            Top             =   360
            Width           =   4215
         End
         Begin VB.Label lbletiarticulo 
            Caption         =   "Código "
            Height          =   230
            Left            =   240
            TabIndex        =   41
            Top             =   120
            Width           =   735
         End
         Begin VB.Label lblcodigo 
            BorderStyle     =   1  'Fixed Single
            Height          =   255
            Left            =   240
            TabIndex        =   40
            Top             =   360
            Width           =   1335
         End
         Begin VB.Label Label12 
            Caption         =   "Descripción"
            Height          =   195
            Left            =   1800
            TabIndex        =   39
            Top             =   120
            Width           =   1335
         End
         Begin VB.Label lbl_total 
            AutoSize        =   -1  'True
            Caption         =   "Cantidad a Devolver"
            Height          =   195
            Left            =   6480
            TabIndex        =   38
            Top             =   360
            Width           =   1575
         End
      End
      Begin VB.Frame Frame2 
         Enabled         =   0   'False
         Height          =   2175
         Left            =   120
         TabIndex        =   1
         Top             =   360
         Width           =   11535
         Begin VB.TextBox txt_NBRDOCUMENTref 
            Height          =   320
            Left            =   5520
            MaxLength       =   10
            TabIndex        =   6
            Top             =   600
            Width           =   1815
         End
         Begin VB.TextBox TXT_IDCLIENTE 
            Enabled         =   0   'False
            Height          =   320
            Left            =   5520
            MaxLength       =   11
            TabIndex        =   8
            Top             =   960
            Width           =   1815
         End
         Begin VB.TextBox txt_razonsocial 
            BeginProperty DataFormat 
               Type            =   0
               Format          =   "HH:mm:ss"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   3082
               SubFormatType   =   0
            EndProperty
            Enabled         =   0   'False
            Height          =   285
            Left            =   5520
            TabIndex        =   10
            Top             =   1320
            Width           =   4815
         End
         Begin VB.TextBox txt_direccion 
            Enabled         =   0   'False
            Height          =   285
            Left            =   5520
            TabIndex        =   11
            Top             =   1680
            Width           =   4815
         End
         Begin VB.TextBox txt_tipodoc 
            BackColor       =   &H80000004&
            Enabled         =   0   'False
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   13.5
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   525
            Left            =   10920
            TabIndex        =   16
            TabStop         =   0   'False
            Text            =   "NOTA DE CREDITO "
            Top             =   1440
            Visible         =   0   'False
            Width           =   375
         End
         Begin VB.TextBox txt_tcambio 
            DataField       =   "NBRDOCUMENT"
            DataMember      =   "OP_SALES"
            DataSource      =   "DataEnvironment1"
            Enabled         =   0   'False
            Height          =   285
            Left            =   1560
            TabIndex        =   15
            TabStop         =   0   'False
            Top             =   1680
            Width           =   735
         End
         Begin VB.TextBox txt_NBRDOCUMENT 
            Height          =   320
            Left            =   2280
            MaxLength       =   10
            TabIndex        =   4
            Top             =   600
            Width           =   1455
         End
         Begin VB.TextBox txt_ruc 
            Enabled         =   0   'False
            Height          =   320
            Left            =   8040
            MaxLength       =   11
            TabIndex        =   9
            Top             =   960
            Width           =   1635
         End
         Begin VB.CommandButton cmdbuscarnumero 
            Height          =   375
            Left            =   7440
            MouseIcon       =   "fnotacreditodebito.frx":2FA4
            MousePointer    =   99  'Custom
            Picture         =   "fnotacreditodebito.frx":30F6
            Style           =   1  'Graphical
            TabIndex        =   7
            ToolTipText     =   "Buscar Documento"
            Top             =   600
            Width           =   465
         End
         Begin MSComCtl2.DTPicker dtp_fecha 
            Height          =   300
            Left            =   1560
            TabIndex        =   17
            Top             =   1320
            Width           =   1305
            _ExtentX        =   2302
            _ExtentY        =   529
            _Version        =   393216
            Enabled         =   0   'False
            CustomFormat    =   "dd/MM/yyyy"
            Format          =   61800451
            CurrentDate     =   37592
         End
         Begin MSDataListLib.DataCombo dtc_serie 
            Height          =   315
            Left            =   1560
            TabIndex        =   3
            Top             =   600
            Width           =   735
            _ExtentX        =   1296
            _ExtentY        =   556
            _Version        =   393216
            Style           =   2
            Text            =   ""
         End
         Begin MSDataListLib.DataCombo dtc_tdocumento 
            Height          =   315
            Left            =   1560
            TabIndex        =   2
            Top             =   240
            Width           =   2175
            _ExtentX        =   3836
            _ExtentY        =   556
            _Version        =   393216
            Style           =   2
            Text            =   ""
         End
         Begin MSComCtl2.DTPicker dtp_fechapro 
            Height          =   300
            Left            =   1560
            TabIndex        =   18
            Top             =   960
            Width           =   1305
            _ExtentX        =   2302
            _ExtentY        =   529
            _Version        =   393216
            Enabled         =   0   'False
            CustomFormat    =   "dd/MM/yyyy"
            Format          =   61800451
            CurrentDate     =   37592
         End
         Begin MSDataListLib.DataCombo dtc_tdocumentoref 
            Height          =   315
            Left            =   5520
            TabIndex        =   5
            Top             =   240
            Width           =   2175
            _ExtentX        =   3836
            _ExtentY        =   556
            _Version        =   393216
            Style           =   2
            Text            =   ""
         End
         Begin MSComCtl2.DTPicker dtp_fecharef 
            Height          =   300
            Left            =   9480
            TabIndex        =   19
            Top             =   600
            Width           =   1305
            _ExtentX        =   2302
            _ExtentY        =   529
            _Version        =   393216
            Enabled         =   0   'False
            CustomFormat    =   "dd/MM/yyyy"
            Format          =   61800451
            CurrentDate     =   37592
         End
         Begin VB.Label lbltipodepago 
            Height          =   255
            Left            =   2520
            TabIndex        =   34
            Top             =   1920
            Visible         =   0   'False
            Width           =   1575
         End
         Begin VB.Label lblmoneda 
            Height          =   255
            Left            =   120
            TabIndex        =   33
            Top             =   2040
            Visible         =   0   'False
            Width           =   1695
         End
         Begin VB.Label lbltipodetipocmb 
            Height          =   255
            Left            =   2400
            TabIndex        =   32
            Top             =   1800
            Visible         =   0   'False
            Width           =   855
         End
         Begin VB.Label Label9 
            Alignment       =   1  'Right Justify
            AutoSize        =   -1  'True
            Caption         =   "No.Doc.Referencia:"
            Height          =   195
            Left            =   3960
            TabIndex        =   31
            Top             =   600
            Width           =   1425
         End
         Begin VB.Label Label8 
            Alignment       =   1  'Right Justify
            AutoSize        =   -1  'True
            Caption         =   "Fecha Proceso:"
            Height          =   195
            Left            =   120
            TabIndex        =   30
            Top             =   960
            Width           =   1125
         End
         Begin VB.Label Label7 
            Alignment       =   1  'Right Justify
            AutoSize        =   -1  'True
            Caption         =   "Tipo Doc.Referencia:"
            Height          =   195
            Left            =   3960
            TabIndex        =   29
            Top             =   240
            Width           =   1530
         End
         Begin VB.Label Label1 
            Alignment       =   1  'Right Justify
            AutoSize        =   -1  'True
            Caption         =   "Codigo Cliente:"
            Height          =   195
            Left            =   3960
            TabIndex        =   28
            Top             =   960
            Width           =   1065
         End
         Begin VB.Label Label2 
            Alignment       =   1  'Right Justify
            AutoSize        =   -1  'True
            Caption         =   "Apellido/R.S.:"
            Height          =   195
            Left            =   3960
            TabIndex        =   27
            Top             =   1320
            Width           =   990
         End
         Begin VB.Label Label3 
            Alignment       =   1  'Right Justify
            AutoSize        =   -1  'True
            Caption         =   "Direccion:"
            Height          =   225
            Left            =   3960
            TabIndex        =   26
            Top             =   1680
            Width           =   720
         End
         Begin VB.Label Label5 
            Alignment       =   1  'Right Justify
            AutoSize        =   -1  'True
            Caption         =   "Fecha Documento:"
            Height          =   195
            Left            =   120
            TabIndex        =   25
            Top             =   1320
            Width           =   1365
         End
         Begin VB.Label Label6 
            Alignment       =   1  'Right Justify
            AutoSize        =   -1  'True
            Caption         =   "Ruc:"
            Height          =   285
            Left            =   7440
            TabIndex        =   24
            Top             =   1000
            Width           =   345
         End
         Begin VB.Label Label11 
            Alignment       =   1  'Right Justify
            AutoSize        =   -1  'True
            Caption         =   "Tipo Cambio:"
            Height          =   285
            Left            =   120
            TabIndex        =   23
            Top             =   1680
            Width           =   930
         End
         Begin VB.Label lblFieldLabel 
            Alignment       =   1  'Right Justify
            AutoSize        =   -1  'True
            Caption         =   "Nro.Documento:"
            Height          =   195
            Left            =   120
            TabIndex        =   22
            Top             =   600
            Width           =   1170
         End
         Begin VB.Label lbl_tdocumento 
            Alignment       =   1  'Right Justify
            AutoSize        =   -1  'True
            Caption         =   "Tipo Documento:"
            Height          =   195
            Left            =   120
            TabIndex        =   21
            Top             =   240
            Width           =   1230
         End
         Begin VB.Label Label4 
            Alignment       =   1  'Right Justify
            AutoSize        =   -1  'True
            Caption         =   "Fecha Doc.Ref.:"
            Height          =   195
            Left            =   8280
            TabIndex        =   20
            Top             =   600
            Width           =   1185
         End
      End
      Begin MSDataGridLib.DataGrid dbdetalle 
         Height          =   2055
         Left            =   120
         TabIndex        =   12
         Top             =   2640
         Width           =   9975
         _ExtentX        =   17595
         _ExtentY        =   3625
         _Version        =   393216
         HeadLines       =   1
         RowHeight       =   15
         BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Caption         =   "[Enter]_Modificar_          [Escape] Descartar Documento"
         ColumnCount     =   2
         BeginProperty Column00 
            DataField       =   ""
            Caption         =   ""
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   10250
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column01 
            DataField       =   ""
            Caption         =   ""
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   10250
               SubFormatType   =   0
            EndProperty
         EndProperty
         SplitCount      =   1
         BeginProperty Split0 
            BeginProperty Column00 
            EndProperty
            BeginProperty Column01 
            EndProperty
         EndProperty
      End
      Begin MSDataGridLib.DataGrid DBConsNotadeCredito 
         Height          =   2775
         Left            =   -74880
         TabIndex        =   62
         Top             =   2640
         Width           =   10095
         _ExtentX        =   17806
         _ExtentY        =   4895
         _Version        =   393216
         HeadLines       =   1
         RowHeight       =   15
         BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Caption         =   "[Enter]_Modificar_          [Escape] Descartar Documento"
         ColumnCount     =   2
         BeginProperty Column00 
            DataField       =   ""
            Caption         =   ""
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   10250
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column01 
            DataField       =   ""
            Caption         =   ""
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   10250
               SubFormatType   =   0
            EndProperty
         EndProperty
         SplitCount      =   1
         BeginProperty Split0 
            BeginProperty Column00 
            EndProperty
            BeginProperty Column01 
            EndProperty
         EndProperty
      End
      Begin VB.Line Line1 
         X1              =   3480
         X2              =   10080
         Y1              =   6120
         Y2              =   6120
      End
      Begin VB.Shape Shape1 
         Height          =   975
         Left            =   3480
         Top             =   5760
         Width           =   6615
      End
      Begin VB.Label lblsubtotal 
         Caption         =   "Sub Total"
         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            =   3840
         TabIndex        =   97
         Top             =   5880
         Width           =   1215
      End
      Begin VB.Label lbligv 
         Caption         =   "IGV"
         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            =   6960
         TabIndex        =   96
         Top             =   5880
         Width           =   495
      End
      Begin VB.Label lbl_totalgen 
         Caption         =   "Total"
         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            =   8280
         TabIndex        =   95
         Top             =   5880
         Width           =   615
      End
      Begin VB.Label lbl_noafecto 
         Caption         =   "No Afecto"
         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            =   5400
         TabIndex        =   94
         Top             =   5880
         Width           =   1215
      End
      Begin VB.Label lbltotalusd 
         Height          =   255
         Left            =   -68160
         TabIndex        =   81
         Top             =   6360
         Visible         =   0   'False
         Width           =   1335
      End
      Begin VB.Label lbltotalpen 
         Height          =   255
         Left            =   -69120
         TabIndex        =   80
         Top             =   6360
         Visible         =   0   'False
         Width           =   1335
      End
   End
End
Attribute VB_Name = "fnotacreditodebito"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Public mobj_cseguridad As DB_SE_MANTENIMIENTOS.c_seguridad
Public MOBJ_CMONEDA As DB_MA_MANTENIMIENTOS.C_MONEDA
Public mobj_cdocumento As DB_MA_MANTENIMIENTOS.C_DOCUMENTO
Public mobj_cventasgen As DB_OP_FACTURACION.C_VENTASGENERAL
Public MOBJ_CVENTASCSTORE As DB_OP_FACTURACION.C_VENTASCSTORE
Public Mobj_Correlativo As DB_CORRELATIVO.C_Correlativos
'--------------------------------------------------------------------------
'datos del clientes
Public mstr_monedacliente
Public mint_limitecredito
Public mbln_afectoimpuesto
'--------------------------------------------------------------------------
Public pb_editar As Boolean
Public pb_agregar As Boolean
Public pb_primerregistro As Boolean
Public pb_ultimoregistro As Boolean
Public pbderecho_agregar As Boolean
Public pbderecho_consultar As Boolean
Public pbderecho_editar As Boolean
Public pbderecho_borrar As Boolean
Public pbderecho_imprimir As Boolean
Public pbderecho_EMITIR As Boolean
Public pbderecho_ANULAR As Boolean
Public pb_tiposcreen As String

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

Public grscliente As ADODB.Recordset

Private WithEvents MrsGrilla As ADODB.Recordset
Attribute MrsGrilla.VB_VarHelpID = -1
Public rs_prod As ADODB.Recordset

Public mbln_editandoproducto As Boolean
Public MBLN_INICIO  As Boolean

Public mbln_articuloencontrado As Boolean
Public MintTipoCliente As Integer
Public GstrTipoClienteDescr As String
Public GdblLimiteCredito As Double
Public GdblDeudaVigente As Double
Public GdblSaldoDisponible As Double
Public GstrIddeEstado As String
Public GstrDescrEstado As String
Public GstrTipodeCambio As String
Public gdblMontoTipoCambio  As Double

Public GintDiasdeGracia As Integer
Public GdblMontoExtra As Double
Public GblnconPlacas As Boolean
Public GblnAfecto As Boolean
Public GStrNumeroPlaca As String
Public GintNumeroVale As Double
Public MBlndatosasignados As Boolean
Public mbln_cabezeraprotegida As Boolean

Public LdblTotalBase As Double
Public LdblTotalExt As Double
Public LDblIGVBase As Double
Public LDblIGVExt As Double
Public LDblSubAfectoBase As Double
Public LDblSubAfectoExt As Double
Public LDblNoAfectoBase As Double
Public LDblNoAfectoExt As Double

Public LDblTOTALNOTAFFECTPEN As Double
Public LDblTOTALNOTAFFECTUSD As Double
Public LDblTOTRETURNEDPEN As Double
Public LDblTOTRETURNEDUSD As Double
Public LDblTOTCASHPEN As Double
Public LDblTOTCASHUSD As Double

Public pdbl_documentobuscado As Double
Public pbln_consulta As Boolean
Public pbln_errorcab As Boolean
Public GINT_TIPOPAGO As Integer

Public MrsDatos As ADODB.Recordset
Public MBlnDatosCargados As Boolean
Public GstrMonedaLimiteCredito As String

'Datos del Producto en la Grilla

Public MdblProcIgv As Double
Public MintInventaribale As Integer
Public MdblPrecioVenta As Double
Public MstrAlmacen As String
Public MstrArticulo As String
Public MstrTipodeTicket As String
Public MBlnConsultaCargada As Boolean
Public MdblGraboCorrectamente As Boolean

Public pdbl_correlativo2 As Double          'correlativo interno de para la tabla de varios documentos
Public intMultiplesDocumentos As Integer

Public Sub salir_formulario()
    cmd_salir_Click
End Sub
Private Sub cmd_Cancelar_Click()
'If MsgBox("Esta Seguro de Cancelar la Venta Actual", vbYesNo + vbQuestion, "Precaucion") = vbYes Then
    txt_NBRDOCUMENTref.Text = Empty
    MBLN_INICIO = True
    MBlnDatosCargados = False
    Call borrar_valores
    Call INICIO
    
    ctnadevolver.Enabled = False
    Frame2.Enabled = False
    fraDatosItem.Enabled = False
    cmddocumentos.Enabled = False
    cmdMarcar.Enabled = False
    cmdDesmarcar.Enabled = False

    Call enfoque_inicial
'End If
End Sub

Private Sub cmd_efectivo_Click()
If Val(txt_total.Text) > 0 Then
     MdblGraboCorrectamente = False
     GRABAR_VENTA
     
     If MdblGraboCorrectamente = True Then
        Me.pb_agregar = False
        Me.pb_editar = False
        Call gactualiza_barra(Me)
         'Call gHabilitarReg(frm, frm.pb_editar)
        Call gactualizaopcion(Me.pbderecho_agregar, Me.pbderecho_editar, Me.pbderecho_borrar, Me.pbderecho_imprimir)
         'LimpiaFormulario
        actualizar_registro
     End If
     cmddocumentos.Enabled = False
     cmdMarcar.Enabled = False
     cmdDesmarcar.Enabled = False

Else
   MsgBox "El total del Documento es Cero", vbDefaultButton1 + vbExclamation, "No se puede Grabar"
   MdblGraboCorrectamente = False
   Exit Sub
End If
End Sub
Private Sub cmd_salir_Click()
If Val(txt_total.Text) > 0 Then
    If MsgBox("Esta Seguro de Salir " + Chr(13) + "Los Cambios hechos se perderan ", vbYesNo + vbQuestion, "Precaucion") = vbNo Then
        Exit Sub
    End If
End If
Call cierra_objetos
Unload Me
End Sub

Private Sub cmdAnulaDoc_Click()

Dim LintcontadoCredito As Integer

If MBlnConsultaCargada = False Then
   MsgBox "Debe Ingresar el Documento a Anular", vbDefaultButton1 + vbExclamation, "Advertencia"
   txtnumerodocu.SetFocus
   Exit Sub
End If

If pbderecho_ANULAR = False Then
   MsgBox "No tiene derecho de Anular", vbDefaultButton1 + vbExclamation, "Advertencia"
   Exit Sub
End If

If lblstatus.Caption = "AN" Then
  MsgBox "Documento ya ha sido Anulado", vbDefaultButton1 + vbExclamation, "Advertencia"
Else
 If MsgBox("Está seguro que desea Anular la Nota de Crédito " & txtnumerodocu.Text, vbYesNo + vbQuestion) = vbYes Then
    If lbltipopagocons.Caption = GC_VALESCRED Or lbltipopagocons.Caption = "10" Then
      LintcontadoCredito = 0
    Else
      LintcontadoCredito = 1
    End If
    
    mobj_cventasgen.AnularNotaCredito txtnumerodocu.Text, mobj_cventasgen.obtenertiponc, GstrSiteProce, txtcodcliente.Text, _
                                      lblmonedacons, lbltotalpen.Caption, lbltotalusd.Caption, LintcontadoCredito
    MsgBox "Documento Fue Anulado con éxito ", vbDefaultButton1 + vbInformation, "Mensaje"
    lblstatus.Caption = "AN"
 End If
End If

End Sub

Private Sub cmdbuscarnumero_Click()
  Fdocumentoreferencia.lbltipoticket.Caption = MstrTipodeTicket
  Fdocumentoreferencia.Show vbModal
End Sub

Private Sub cmdDesmarcar_Click()
On Error GoTo trataerror
If Not IsNull(dbdetalle.Bookmark) Then
 'ACA SE INSERTA EN LA TABLA TEMPORAL
    Dim LARRAY(1, 2) As Variant
    Dim LRSFIL As ADODB.Recordset
        
    LARRAY(1, 1) = pdbl_correlativo
    LARRAY(1, 2) = 0
    
    mobj_cventasgen.Auxiliar5 LARRAY
   
  '''''''''''''''''''''''''''''''''''''
    Call CARGAGRILLA(pdbl_correlativo)
End If
Exit Sub

trataerror:
End Sub

Private Sub cmddocumentos_Click()
  Set MrsDatos = mobj_cventasgen.cargar_referencias(0, 0, GstrSiteProce, pdbl_correlativo)
  CargaDatosCabecera
  FSeleccionDocument.Show vbModal
End Sub

Private Sub cmdMarcar_Click()
On Error GoTo trataerror
If Not IsNull(dbdetalle.Bookmark) Then
 'ACA SE INSERTA EN LA TABLA TEMPORAL
    Dim LARRAY(1, 2) As Variant
    Dim LRSFIL As ADODB.Recordset
        
    LARRAY(1, 1) = pdbl_correlativo
    LARRAY(1, 2) = 1
    
    mobj_cventasgen.Auxiliar5 LARRAY
   
  '''''''''''''''''''''''''''''''''''''
    Call CARGAGRILLA(pdbl_correlativo)
End If
Exit Sub

trataerror:
End Sub

Private Sub cmdnuevo_Click()

  ctnadevolver.Enabled = True
  Frame2.Enabled = True
  fraDatosItem.Enabled = True
  cmddocumentos.Enabled = True
  cmdMarcar.Enabled = True
  cmdDesmarcar.Enabled = True
End Sub

Private Sub cmdnumerodocumento_Click()
  FBuscarNotaCredito.Show vbModal
End Sub

Private Sub cmdReimprimir_Click()
Call imprimir
End Sub

Private Sub ctnadevolver_KeyPress(KeyAscii As Integer)
 
' Select sequence as Lin,InvtidSku,DESCRINVENTORY,SLSPRICESALE,
'        cantidad_original,PORCENTTAXIGV,TOTALPEN,TOTALUSD,
'        ROUND(TOTALPEN-TAXPEN,@NDECIMAL) AS SUBTOTALPEN,
'        ROUND(TOTALUSD-TAXUSD,@NDECIMAL) AS SUBTOTALUSD,
'        TAXPEN,TAXUSD,DEVUELTO,QTY,STKITEM
'        from tmp_op_salesdetnc where CORRNBR=@CORRELATIVO  order by sequence
  
End Sub

Sub editar_producto()
   mbln_articuloencontrado = True
   mbln_editandoproducto = True
End Sub

Private Sub ctnadevolver_KeyUp(KeyCode As Integer, Shift As Integer)
 If KeyCode = 13 Then
   ' Hay que Validar que la Cantidad a Devolver sea Menor o igual que la Cantidad menos
   ' lo ya devuelto
   If ctnadevolver.Text > Val(dbdetalle.Columns(4).Value) - Val(dbdetalle.Columns(12).Value) Then
      MsgBox "Cantidad no disponible, Ingrese otra Cantidad ", vbDefaultButton1 + vbExclamation, "Advertencia"
      dbdetalle.SetFocus
      Exit Sub
   End If
   
   Call grabarregistro
   dbdetalle.SetFocus
 End If
 
 If KeyCode = vbKeyUp Or KeyCode = vbKeyLeft Then
    dbdetalle.SetFocus
 End If
 
End Sub

Private Sub DBDETALLE_KeyDown(KeyCode As Integer, Shift As Integer)
 
 If KeyCode = vbKeyF7 Then
   Call cmd_efectivo_Click
 End If
  
End Sub

Private Sub DBDetalle_KeyUp(KeyCode As Integer, Shift As Integer)
  
 If KeyCode = 13 Then
    Call editar_producto
    ctnadevolver.SetFocus
 End If
  
End Sub

Private Sub DBDetalle_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
 
' Select sequence as Lin,InvtidSku,DESCRINVENTORY,SLSPRICESALE,
'        cantidad_original,PORCENTTAXIGV,TOTALPEN,TOTALUSD,
'        ROUND(TOTALPEN-TAXPEN,@NDECIMAL) AS SUBTOTALPEN,
'        ROUND(TOTALUSD-TAXUSD,@NDECIMAL) AS SUBTOTALUSD,
'        TAXPEN , TAXUSD, DEVUELTO, QTY,STKITEM,SITEID
'        from tmp_op_salesdetnc where CORRNBR=@CORRELATIVO  order by sequence
    
    
If Not IsNull(dbdetalle.Bookmark) Then
    MdblProcIgv = dbdetalle.Columns(5).Value
    MintInventaribale = dbdetalle.Columns(14).Value
    MdblPrecioVenta = dbdetalle.Columns(3).Value
    MstrAlmacen = dbdetalle.Columns(15).Value
    MstrArticulo = dbdetalle.Columns(1).Value
    lblarticulo = dbdetalle.Columns(2).Value
    lblcodigo.Caption = dbdetalle.Columns(1).Value
    ctnadevolver.Text = GFormatodeNumero(dbdetalle.Columns(13).Value, GintDecStock)
End If

End Sub

Private Sub dtc_serie_Change()
txt_NBRDOCUMENT.Text = mobj_cventasgen.obtenernrodocumento(dtc_tdocumento.BoundText, dtc_serie.BoundText, GstrSiteProce)
End Sub
Private Sub dtc_serie_GotFocus()
dtc_serie.BackColor = vbCyan
Call valida_cabezera1
End Sub
Private Sub dtc_serie_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Or KeyCode = vbKeyDown Then
    txt_NBRDOCUMENT.Text = mobj_cventasgen.obtenernrodocumento(dtc_tdocumento.BoundText, dtc_serie.BoundText, GstrSiteProce)
    txt_NBRDOCUMENT.SetFocus
End If
If KeyCode = vbKeyUp Then
    dtc_tdocumento.SetFocus
End If
End Sub
Private Sub dtc_serie_LostFocus()
If dtc_tdocumento.Text <> "" Then
    txt_NBRDOCUMENT.Text = mobj_cventasgen.obtenernrodocumento(dtc_tdocumento.BoundText, dtc_serie.BoundText, GstrSiteProce)
End If
dtc_serie.BackColor = vbWhite
End Sub
Private Sub dtc_tdocumento_Change()
  
  txt_tipodoc.Text = dtc_tdocumento.Text
  TXT_IDCLIENTE.Text = ""
  txt_ruc.Text = ""
  txt_direccion.Text = ""
  txt_razonsocial.Text = ""
  
  
 'buscar numeros de serie para ese tipo de documento
 
  Call CargaDataCombo(dtc_serie, mobj_cventasgen.obtenerseriesdoc(dtc_tdocumento.BoundText, GstrSiteProce), "nbrseries", "nbrseries")
  txt_NBRDOCUMENT.Text = mobj_cventasgen.obtenernrodocumento(dtc_tdocumento.BoundText, dtc_serie.BoundText, GstrSiteProce)
  
End Sub
Private Sub dtc_tdocumento_GotFocus()
 dtc_tdocumento.BackColor = vbCyan
End Sub

Private Sub dtc_tdocumento_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Or KeyCode = vbKeyDown Then
   dtc_serie.SetFocus
End If
End Sub
Private Sub dtc_tdocumento_LostFocus()
dtc_tdocumento.BackColor = vbWhite
End Sub

Private Sub dtc_tdocumentoref_GotFocus()
Call valida_cabezera1
End Sub

Private Sub dtc_tdocumentoref_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Or KeyCode = vbKeyDown Then
    txt_NBRDOCUMENTref.SetFocus
End If
End Sub

Private Sub dtp_fecha_GotFocus()
Call valida_cabezera1
End Sub
Private Sub dtp_fecha_LostFocus()
Call valida_cabezera1
End Sub
Private Sub dtp_fechapro_GotFocus()
Call valida_cabezera1
End Sub
Private Sub dtp_fechapro_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
    dtp_fecha.SetFocus
End If
End Sub

Private Sub dtp_fechapro_LostFocus()
Call valida_cabezera1
End Sub
Private Sub Form_Activate()

Call gactualizaopcion(pbderecho_agregar, pbderecho_editar, pbderecho_borrar, pbderecho_imprimir)
Call gactualiza_barra(Me)

If pbderecho_consultar = False Then
    Unload Me
End If
Call enfoque_inicial

MBLN_INICIO = False

End Sub
Private Sub enfoque_inicial()
If MBLN_INICIO Then
    If gstrtipoventas = "A" Then
        TXT_IDCLIENTE.SetFocus
    Else
       If Frame2.Enabled = True Then
        dtc_tdocumento.SetFocus
       End If
    End If
    MBLN_INICIO = False
End If
End Sub

Private Sub Form_Load()

Call gseguridad(Me)
If pbderecho_consultar Then
    Call instancia_objetos
    Me.Left = (MDIFVENTAS.Width - Me.Width) / 2
    Me.Top = 100
    
    dtp_fecha.Value = GDatFechaProceso
    dtp_fechapro.Value = GDatFechaProceso
    
    ctnadevolver.PermitirNegativos = False
    ctnadevolver.Enteros = 11
    ctnadevolver.Decimales = GintDecStock
    ctnadevolver.ValorPorDefecto
    
    MstrTipodeTicket = mobj_cventasgen.obtenertipoticket
    
    MBlnConsultaCargada = False
    
    MBlnDatosCargados = False
    MdblGraboCorrectamente = False
                                            
    Call CargaDataCombo(dtc_tdocumento, mobj_cventasgen.ListarDocumentosnc(GstrSiteProce), "DOCTYPEID", "DESCR")
    Call CargaDataCombo(dtc_tdocumentoref, mobj_cventasgen.Listartiposdocumentos(), "DOCTYPEID", "DESCR")
    
    dtc_tdocumentoref.BoundText = MstrTipodeTicket
    
    Call INICIO
    
    Frame2.Enabled = False
    fraDatosItem.Enabled = False
    ctnadevolver.Enabled = False
    
    SSTab1.Tab = 0
Else
    MsgBox ("No tiene Derechos de Consultar en este formulario")
End If

End Sub
Sub INICIO()

    Call ESTADO_CABEZERA(True)
    'GstrTipodeCambio
    pdbl_correlativo = Mobj_Correlativo.ObtenerCorrelativo(GCUSERID)
    GstrTipodeCambio = GstrTipoCambioVentas
        dtp_fecha.Enabled = True
        dtp_fechapro.Enabled = True
        If gblnsaltarcorrelativo Then
            txt_NBRDOCUMENT.Enabled = True
            txt_NBRDOCUMENT.Locked = True
        Else
            txt_NBRDOCUMENT.Enabled = True
            txt_NBRDOCUMENT.Locked = False
        End If
        lbl_tdocumento.Visible = True
        dtc_tdocumento.Visible = True
        dtc_tdocumento.Enabled = True
        dtc_tdocumento.Text = ""
        dtc_serie.Enabled = True
        txt_NBRDOCUMENT.MaxLength = 7
        dtc_tdocumento.BoundText = mobj_cventasgen.obtenertiponc
        dtc_tdocumentoref.BoundText = mobj_cventasgen.obtenertipoticket
        'dtc_tdocumentoref.BoundText

    'INDICA QUE EL FORMULARIO ACABA DE INCIARSE
    TXT_MONEDATOTAL.Text = GstrSimboloMoneda    'moneda de la caja cuando se inicia
    MBLN_INICIO = True
    mbln_editandoproducto = False
    gbln_ventaefectuada = False
    mbln_articuloencontrado = False
    dtp_fechapro.Value = GDatFechaProceso
    dtp_fecha.Value = GDatFechaProcesoVentas
    
    txt_tcambio.Text = gdblMontoTipoCambio
    'Call CARGAGRILLA(pdbl_correlativo)
    
    intMultiplesDocumentos = 0
    pdbl_correlativo2 = 0
End Sub
Sub instancia_objetos()
Set mobj_cseguridad = New DB_SE_MANTENIMIENTOS.c_seguridad
Set MOBJ_CMONEDA = New DB_MA_MANTENIMIENTOS.C_MONEDA
Set mobj_cventasgen = New DB_OP_FACTURACION.C_VENTASGENERAL
Set MOBJ_CVENTASCSTORE = New DB_OP_FACTURACION.C_VENTASCSTORE
Set Mobj_Correlativo = New DB_CORRELATIVO.C_Correlativos
Set mobj_cdocumento = New DB_MA_MANTENIMIENTOS.C_DOCUMENTO
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    If Me.pb_editar Then
        If MsgBox("Desea Cancelar los Cambios", vbYesNo + vbQuestion, "Esta Ingresando una Nota de Crédito") = vbNo Then
            Cancel = True
        Else
            Me.pb_agregar = False
            Me.pb_editar = False
            Call gdesactiva_barra
        End If
    Else
        Me.pb_agregar = False
        Me.pb_editar = False
        Call gdesactiva_barra
    End If
End Sub

Private Sub txt_NBRDOCUMENT_GotFocus()
txt_NBRDOCUMENT.BackColor = vbCyan
Call valida_cabezera1
End Sub

Private Sub txt_NBRDOCUMENT_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyDown Or KeyCode = 13 Then
    Call valida_NUMERODOCUMENTO("KD")
End If
If KeyCode = vbKeyUp Then
    dtc_serie.SetFocus
End If

If KeyCode = vbKeyEscape Then
    cmd_Cancelar.SetFocus
End If

End Sub

Private Sub txt_NBRDOCUMENT_KeyPress(KeyAscii As Integer)
KeyAscii = GBloqueanonumeros(KeyAscii)
End Sub

Private Sub txt_NBRDOCUMENT_LostFocus()
txt_NBRDOCUMENT.BackColor = vbWhite
Call FORMATONBRDOCUMENT
End Sub

Public Sub CARGAGRILLA(ByVal MDblIdentificador As Double)

Dim LdblImpuesto As Double
Dim BlnExisteunNoAfecto As Boolean
Dim BlnTodosLosImpIguales As Boolean
 
LdblTotalBase = 0
LdblTotalExt = 0
LDblIGVBase = 0
LDblIGVExt = 0
LDblSubAfectoBase = 0
LDblSubAfectoExt = 0
LDblNoAfectoBase = 0
LDblNoAfectoExt = 0
 
      Set MrsGrilla = MOBJ_CVENTASCSTORE.ObtenerDatosTMPnc(MDblIdentificador, GintDecPrecio)
              
      '***************************************************
      ' Parte que recalcula los Datos de los Resultados
      '***************************************************
       
      If Not MrsGrilla.EOF Then
       MrsGrilla.MoveFirst
       
       'Capturo el Primer Impuesto de la Grilla
       LdblImpuesto = MrsGrilla.Fields("PORCENTTAXIGV")
       'Inicializo la variable si es falso todos son Afectos
       BlnExisteunNoAfecto = False
       'Inicializo la variable Por defecto todos los impuestos son iguales
       BlnTodosLosImpIguales = True
       
       Do While Not MrsGrilla.EOF
         If MrsGrilla!PORCENTTAXIGV > 0 Then
           'Comparo los impuestos para revisar si son iguales
           If MrsGrilla.Fields("PORCENTTAXIGV") <> LdblImpuesto Then
              BlnTodosLosImpIguales = False
           End If
           LDblSubAfectoBase = LDblSubAfectoBase + MrsGrilla!SUBTOTALPEN
           LDblSubAfectoExt = LDblSubAfectoExt + MrsGrilla!SUBTOTALUSD
         Else
           LDblNoAfectoBase = LDblNoAfectoBase + MrsGrilla!SUBTOTALPEN
           LDblNoAfectoExt = LDblNoAfectoExt + MrsGrilla!SUBTOTALUSD
           BlnExisteunNoAfecto = True
         End If
         
         LDblIGVBase = LDblIGVBase + MrsGrilla!TAXPEN
         LDblIGVExt = LDblIGVExt + MrsGrilla!TAXUSD
         LdblTotalBase = LdblTotalBase + MrsGrilla!TOTALPEN
         LdblTotalExt = LdblTotalExt + MrsGrilla!TOTALUSD
         MrsGrilla.MoveNext
       Loop
          
       If BlnExisteunNoAfecto = False Then ' Es decir Todos son Afectos
          ' Ademas se tiene que verificar que que todos los impuestos son iguales
          If BlnTodosLosImpIguales = True Then
            LDblSubAfectoBase = LdblTotalBase / (1 + (LdblImpuesto / 100))
            LDblSubAfectoExt = LdblTotalExt / (1 + (LdblImpuesto / 100))
            LDblIGVBase = LdblTotalBase - LDblSubAfectoBase
            LDblIGVExt = LdblTotalExt - LDblSubAfectoExt
          End If
       End If
       
      End If
      
  '*********************************************************************************
  'Esta parte asigna a las Etiquetas de los Resultados los Valores Calculados arriba
  'Teniendo en Consideración la Moneda del Cliente y de la Caja
  '*********************************************************************************
  
     If GstrMonedaLimiteCredito = GstrCodMonedaBase Then
       ' Si la Moneda del Cliente no está Vacía Manda su Moneda
       txt_subtotal.Text = GFormatodeNumero(LDblSubAfectoBase, GintDecResultado)
       TXT_NOAFECTO.Text = GFormatodeNumero(LDblNoAfectoBase, GintDecResultado)
       txt_igv.Text = GFormatodeNumero(LDblIGVBase, GintDecResultado)
       txt_total.Text = GFormatodeNumero(LdblTotalBase, GintDecResultado)
     Else
       txt_subtotal.Text = GFormatodeNumero(LDblSubAfectoExt, GintDecResultado)
       TXT_NOAFECTO.Text = GFormatodeNumero(LDblNoAfectoExt, GintDecResultado)
       txt_igv.Text = GFormatodeNumero(LDblIGVExt, GintDecResultado)
       txt_total.Text = GFormatodeNumero(LdblTotalExt, GintDecResultado)
     End If
     
       LDblSubAfectoBase = Round(LDblSubAfectoBase, GintDecResultado)
       LDblNoAfectoBase = Round(LDblNoAfectoBase, GintDecResultado)
       LDblIGVBase = Round(LDblIGVBase, GintDecResultado)
       LdblTotalBase = Round(LdblTotalBase, GintDecResultado)
       LDblSubAfectoExt = Round(LDblSubAfectoExt, GintDecResultado)
       LDblNoAfectoExt = Round(LDblNoAfectoExt, GintDecResultado)
       LDblIGVExt = Round(LDblIGVExt, GintDecResultado)
       LdblTotalExt = Round(LdblTotalExt, GintDecResultado)
       

       Set dbdetalle.DataSource = MrsGrilla
       dbdetalle.Refresh
       Call FormatoGrilla
       If MrsGrilla.RecordCount > 0 Then
          MrsGrilla.MoveLast
       End If
              
End Sub
   
Public Sub FormatoGrilla()

dbdetalle.Columns(0).Caption = "Reg"
dbdetalle.Columns(0).Width = 380
dbdetalle.Columns(0).AllowSizing = False

dbdetalle.Columns(1).Width = 1100
dbdetalle.Columns(1).Caption = "Codigo"
dbdetalle.Columns(1).AllowSizing = False

dbdetalle.Columns(2).Caption = "Descripcion"
dbdetalle.Columns(2).Width = 3800
dbdetalle.Columns(2).AllowSizing = False

dbdetalle.Columns(3).Caption = "Precio"
dbdetalle.Columns(3).Width = 1000  'Precio
dbdetalle.Columns(3).Alignment = dbgRight
dbdetalle.Columns(3).NumberFormat = GMascara(GintDecPrecio)
dbdetalle.Columns(3).AllowSizing = False

dbdetalle.Columns(4).Caption = "Cantidad"
dbdetalle.Columns(4).Width = 920
dbdetalle.Columns(4).Alignment = dbgRight
dbdetalle.Columns(4).NumberFormat = GMascara(GintDecStock)
dbdetalle.Columns(4).AllowSizing = False

dbdetalle.Columns(5).Caption = "%Impto"
dbdetalle.Columns(5).Width = 600
dbdetalle.Columns(5).Alignment = dbgRight
dbdetalle.Columns(5).NumberFormat = GMascara(GintDecPrecio)
dbdetalle.Columns(5).AllowSizing = False

dbdetalle.Columns(6).Visible = False
dbdetalle.Columns(7).Visible = False
dbdetalle.Columns(8).Visible = False
dbdetalle.Columns(9).Visible = False
dbdetalle.Columns(10).Visible = False
dbdetalle.Columns(11).Visible = False

dbdetalle.Columns(12).Caption = "Devuelto"
dbdetalle.Columns(12).Width = 890
dbdetalle.Columns(12).Alignment = dbgRight
dbdetalle.Columns(12).NumberFormat = GMascara(GintDecStock)
dbdetalle.Columns(12).AllowSizing = False

dbdetalle.Columns(13).Caption = "A Devolver"
dbdetalle.Columns(13).Width = 890
dbdetalle.Columns(13).Alignment = dbgRight
dbdetalle.Columns(13).NumberFormat = GMascara(GintDecStock)
dbdetalle.Columns(13).AllowSizing = False

dbdetalle.Columns(14).Visible = False
dbdetalle.Columns(15).Visible = False

End Sub
Public Sub grabarregistro()

Dim dou_CORRNBR As Double
Dim int_nlin As Integer
                                
dou_CORRNBR = pdbl_correlativo

If MrsGrilla.RecordCount > 0 Then
    int_nlin = MrsGrilla!lin
Else
    int_nlin = 0
End If

'Calculo de los Datos para Actualizar ***************************
' MdblProcIgv = DBDetalle.Columns(5).Value
' MintInventaribale = DBDetalle.Columns(14).Value
' MdblPrecioVenta = DBDetalle.Columns(3).Value
' MstrAlmacen = DBDetalle.Columns(15).Value
' MstrArticulo = DBDetalle.Columns(1).Value

' lbltipodetipocmb / txt_tcambio
' lblmoneda

Dim LDblPrecioMonExtranjera As Double
Dim LDblPrecioMonBase As Double
Dim LdblTotalPENNc As Double
Dim LdblTotalUSDNc As Double
Dim LdblSubTotalPENNc As Double
Dim LdblSubTotalUSDNc As Double
Dim LdblTaxPENNC As Double
Dim LdblTaxUSDNC As Double
            
         
If lblmoneda.Caption = GstrCodMonedaBase Then ' La transacción se realizó en Moneda Base
   LDblPrecioMonBase = MdblPrecioVenta
   LDblPrecioMonExtranjera = mobj_cventasgen.ConvertirMoneda(LDblPrecioMonBase, GstrCodMonedaBase, GstrMonedaExtranjeraModgen, Format(dtp_fecharef.Value, "yyyymmdd"), lbltipodetipocmb, GintDecPrecio)
Else ' La transacción se realizó en Moneda Extranjera
   LDblPrecioMonExtranjera = MdblPrecioVenta
   LDblPrecioMonBase = mobj_cventasgen.ConvertirMoneda(LDblPrecioMonExtranjera, GstrMonedaExtranjeraModgen, GstrCodMonedaBase, Format(dtp_fecharef.Value, "yyyymmdd"), lbltipodetipocmb, GintDecPrecio)
End If
                           
              
LdblTotalPENNc = GFormatodeNumero(ctnadevolver.Text * LDblPrecioMonBase, GintDecResultado)
LdblTotalUSDNc = GFormatodeNumero(ctnadevolver.Text * LDblPrecioMonExtranjera, GintDecResultado)

LdblSubTotalPENNc = GFormatodeNumero(LdblTotalPENNc / (1 + (MdblProcIgv / 100)), GintDecResultado)
LdblSubTotalUSDNc = GFormatodeNumero(LdblTotalUSDNc / (1 + (MdblProcIgv / 100)), GintDecResultado)
    
LdblTaxPENNC = LdblTotalPENNc - LdblSubTotalPENNc
LdblTaxUSDNC = LdblTotalUSDNc - LdblSubTotalUSDNc
             
'****************************************************************
    
If mbln_editandoproducto Then
    MOBJ_CVENTASCSTORE.ActualizaNCreditoDetalle dou_CORRNBR, int_nlin, MstrAlmacen, MstrArticulo, _
                                                LdblTotalPENNc, LdblTotalUSDNc, LdblTaxPENNC, LdblTaxUSDNC, ctnadevolver.Text
End If

Call CARGAGRILLA(pdbl_correlativo)

End Sub
Sub valida_NUMERODOCUMENTO(STRID As String)
Dim DOCTYPEID As String
Dim NBRDOCUMENT As Double
        
If Len(Trim(txt_NBRDOCUMENT.Text)) = 0 Then
    MsgBox "Debe Ingresar un numero de documento", vbExclamation, "Atencion"
Else
    DOCTYPEID = dtc_tdocumento.BoundText
    NBRDOCUMENT = Val(dtc_serie.BoundText + txt_NBRDOCUMENT.Text)
           
    If mobj_cventasgen.existedocumento(DOCTYPEID, NBRDOCUMENT, GstrSiteProce) Then
        MsgBox "Documento Ya Existe" + Chr(13) + "Modifique el Numero de Documento", vbExclamation, "Datos Incorrectos"
        Exit Sub
    End If
    If STRID = "KD" Then
        dtc_tdocumentoref.SetFocus
    End If
End If

End Sub
Sub borrar_valores()
    txt_NBRDOCUMENTref = ""
    TXT_IDCLIENTE = ""
    txt_razonsocial.Text = ""
    txt_direccion.Text = ""
    txt_ruc.Text = ""
    txt_subtotal.Text = ""
    txt_igv.Text = ""
    txt_total.Text = ""
    LdblTotalBase = 0
    LdblTotalExt = 0
    LDblIGVBase = 0
    LDblIGVExt = 0
    LDblSubAfectoBase = 0
    LDblSubAfectoExt = 0
    LDblNoAfectoBase = 0
    LDblNoAfectoExt = 0
    LDblTOTALNOTAFFECTPEN = 0
    LDblTOTALNOTAFFECTUSD = 0
    LDblTOTRETURNEDPEN = 0
    LDblTOTRETURNEDUSD = 0
    LDblTOTCASHPEN = 0
    LDblTOTCASHUSD = 0
    txt_tcambio.Text = 0
    'Hay que limpiar la Grilla (OP_EliminarTmpNotaCreditoProc)
    
    LimpiaDatosdeVentas
    
           
End Sub

Public Sub LimpiaDatosdeVentas()
   
    lblmoneda.Caption = Empty
    lbltipodetipocmb.Caption = Empty
    lbltipodepago.Caption = Empty
    lblcodigo.Caption = Empty
    lblarticulo.Caption = Empty
    ctnadevolver.ValorPorDefecto
          
    mobj_cventasgen.EliminarTemporalNotaCredito pdbl_correlativo
    Call CARGAGRILLA(pdbl_correlativo)
   
End Sub

Public Sub GAsignarDatosdeCliente()
   If IsNull(grscliente!CREDITO) Then
    MintTipoCliente = 0
   Else
    MintTipoCliente = grscliente!CREDITO
   End If
   If Not IsNull(grscliente!TIPOCLIENTE) Then
     GstrTipoClienteDescr = grscliente!TIPOCLIENTE
   Else
     GstrTipoClienteDescr = Empty       'cambiar por cliente id contado
   End If
   ' Variables de Manejo para el Límite de Crédito
   
   GstrIddeEstado = grscliente!IDESTADO ' A,H,R,I,O
   GstrDescrEstado = grscliente!Estado
      
   If IsNull(grscliente!MONEDACREDITO) Then
      GstrMonedaLimiteCredito = GStrMonedaCaja
   Else
      GstrMonedaLimiteCredito = grscliente!MONEDACREDITO
   End If
        
   If GstrMonedaLimiteCredito = GstrCodMonedaBase Then
      'Establecer Nombres de las Etiquetas
      'Con la Moneda de la Caja por defecto
       TXT_MONEDATOTAL.Text = GstrSimboloMonedaBase
   Else
       TXT_MONEDATOTAL.Text = GstrSimboloMonedaExt
   End If

   If IsNull(grscliente!TIPODECAMBIO) Or Len(Trim(grscliente!TIPODECAMBIO)) = 0 Then
        GstrTipodeCambio = GstrTipoCambioVentas
   Else
        GstrTipodeCambio = grscliente!TIPODECAMBIO
   End If
   
    If GStrMonedaCaja = GstrCodMonedaBase Then
        gdblMontoTipoCambio = mobj_cventasgen.ObtenerMontoTipodeCambio(GstrCodMonedaBase, GstrMonedaExtranjera, GDatFechaProcesoVentas, GstrTipodeCambio)
    Else
        gdblMontoTipoCambio = mobj_cventasgen.ObtenerMontoTipodeCambio(GstrMonedaExtranjera, GstrCodMonedaBase, GDatFechaProcesoVentas, GstrTipodeCambio)
    End If
   'si no hay tipo de cambio no se debe vender
   GintDiasdeGracia = grscliente!DIASDEGRACIA
   GdblLimiteCredito = mobj_cventasgen.ConvertirMoneda(grscliente!LIMITECRED, GstrMonedaLimiteCredito, GStrMonedaCaja, GDatFechaProcesoVentas, GstrTipodeCambio, GintDecResultado)
   GdblDeudaVigente = mobj_cventasgen.ConvertirMoneda(grscliente!DEUDACLIENTE, GstrMonedaLimiteCredito, GStrMonedaCaja, GDatFechaProcesoVentas, GstrTipodeCambio, GintDecResultado)
   GdblSaldoDisponible = GdblLimiteCredito - GdblDeudaVigente
   GdblMontoExtra = mobj_cventasgen.ConvertirMoneda(grscliente!EXTRA, GstrMonedaLimiteCredito, GStrMonedaCaja, GDatFechaProcesoVentas, GstrTipodeCambio, GintDecResultado)
   GblnAfecto = grscliente!afecto
   'Variable que Indica que los Datos del Cliente
   'Fueron Cargados con éxito
      
   MBlndatosasignados = True
End Sub
Public Sub ESTADO_CABEZERA(ByVal BOL_ESTADO As Boolean)
'SI TIPO DE VENTA NO ES AUTOMATICO DESACTIVAR TAMBIEN CAMPOS ADICIONALES

mbln_cabezeraprotegida = Not BOL_ESTADO
dtc_tdocumento.Enabled = BOL_ESTADO
dtc_serie.Enabled = BOL_ESTADO
dtc_tdocumento.Enabled = BOL_ESTADO
dtc_tdocumentoref.Enabled = BOL_ESTADO
dtp_fecha.Enabled = BOL_ESTADO
dtp_fechapro.Enabled = BOL_ESTADO
dtc_serie.Enabled = BOL_ESTADO
txt_NBRDOCUMENT.Enabled = BOL_ESTADO
txt_NBRDOCUMENTref.Enabled = BOL_ESTADO
End Sub
Public Sub FORMATONBRDOCUMENT()
Dim LS_NDOC As String
LS_NDOC = Trim(txt_NBRDOCUMENT.Text)
txt_NBRDOCUMENT.Text = String(7 - Len(LS_NDOC), "0") + LS_NDOC
End Sub
Private Sub GRABAR_CABEZERA_TEMPORAL()
'grabar si existe alguna linea

'Dim ldou_loadsale As Double
'Dim CORRNBR As Double
'Dim DOCTYPEID As String
'Dim NBRDOCUMENT As Double
'Dim TYPEPAYMENTID As String
'Dim STKINVENTORY As Byte
'Dim SITEID As String
'Dim curyid As String
'Dim TERMID As String
'Dim SALESPERID As String
'Dim USERID As String
'Dim DATEDOC As String
'Dim DATEPROCESALES As String
'Dim PERPOST As String
'Dim TAXIGVID As String
'Dim TAXISCID As String
'Dim TOTALPEN As Double
'Dim TOTALUSD As Double
'Dim SUBTOTALPEN As Double
'Dim SUBTOTALUSD As Double
'Dim TAXIGVPEN As Double
'Dim TAXIGVUSD As Double
'Dim TAXISCPEN As Double
'Dim TAXISCUSD As Double
'Dim TOTALNOTAFFECTPEN As Double
'Dim TOTALNOTAFFECTUSD As Double
'Dim TOTRETURNEDPEN As Double
'Dim TOTRETURNEDUSD As Double
'Dim TOTCASHPEN As Double
'Dim TOTCASHUSD As Double
'Dim custidss As String
'Dim taxregnbr As String
'Dim CUSTNAME As String
'Dim ADDR1 As String
'Dim PLACA As String
'Dim NBRBONUS As Double
'Dim CURYTYPEID As String
'Dim CURYRATE As Double
'Dim PROMOTIONCARDID As String
'Dim POINTNUMBER As Integer
'Dim SALESPOINT As String
'Dim KILOMETRAJE As Integer
'Dim typesales As String
'If gstrtipoventas = "A" Then
'    DOCTYPEID = mobj_cventasgen.obtenertipoticket
'Else
'    DOCTYPEID = dtc_tdocumento.BoundText
'End If
'
'NBRDOCUMENT = Val(txt_NBRDOCUMENT.Text)
'TYPEPAYMENTID = "00"
'STKINVENTORY = 1
'SITEID = GstrSiteProce
'curyid = "PEN"
'TERMID = "00"
'SALESPERID = GstrCodigoVENDEDOR
'USERID = GCUSERID
'DATEDOC = CStr(dtp_fecha.Value)
'DATEPROCESALES = CStr(dtp_fechapro.Value)
'PERPOST = ""
'TAXIGVID = 0
'TAXISCID = 0
'TOTALPEN = Val(txt_total.Text)
'TOTALUSD = 0
'SUBTOTALPEN = (txt_subtotal.Text)
'SUBTOTALUSD = 0
'TAXIGVPEN = Val(txt_igv.Text)
'TAXIGVUSD = 0
'TAXISCPEN = 0
'TAXISCUSD = 0
'TOTALNOTAFFECTPEN = Val(TXT_NOAFECTO.Text)
'TOTALNOTAFFECTUSD = 0
'TOTRETURNEDPEN = 0
'TOTRETURNEDUSD = 0
'TOTCASHPEN = 0
'TOTCASHUSD = 0
'custidss = TXT_IDCLIENTE.Text
'taxregnbr = txt_ruc.Text
'CUSTNAME = txt_razonsocial.Text
'ADDR1 = txt_direccion.Text
'PLACA = ""
'NBRBONUS = 0
'CURYTYPEID = GstrTipoCambioVentas
'CURYRATE = Val(txt_tcambio.Text)
'PROMOTIONCARDID = ""
'POINTNUMBER = 0
'SALESPOINT = GstrPuntodeVenta
'KILOMETRAJE = 0
'typesales = gstrtipoventas
'
''MsgBox "Grabando"
''VERIFICAR QUE LA TRANSACION NO ESTE GRABADA YA
'If mobj_cventasgen.existecorrelativotemporal(pdbl_correlativo) Then
'    ' ya esta grabada, hay que actualizar
''MsgBox "actualizando"
'mobj_cventasgen.actualizatransaccion pdbl_correlativo, DOCTYPEID, NBRDOCUMENT, TYPEPAYMENTID, _
'                   STKINVENTORY, SITEID, curyid, TERMID, SALESPERID, USERID, _
'                   DATEDOC, DATEPROCESALES, PERPOST, TAXIGVID, TAXISCID, _
'                   TOTALPEN, TOTALUSD, SUBTOTALPEN, SUBTOTALUSD, TAXIGVPEN, _
'                   TAXIGVUSD, TAXISCPEN, TAXISCUSD, TOTALNOTAFFECTPEN, _
'                   TOTALNOTAFFECTUSD, TOTRETURNEDPEN, _
'                    TOTRETURNEDUSD, TOTCASHPEN, TOTCASHUSD, _
'                   custidss, taxregnbr, CUSTNAME, PLACA, NBRBONUS, CURYTYPEID, _
'                   CURYRATE, PROMOTIONCARDID, POINTNUMBER, SALESPOINT, KILOMETRAJE, _
'                   typesales, ADDR1
'Else
'
''MsgBox "insertando"
'mobj_cventasgen.grabartransaccion pdbl_correlativo, DOCTYPEID, NBRDOCUMENT, TYPEPAYMENTID, _
'                   STKINVENTORY, SITEID, curyid, TERMID, SALESPERID, USERID, _
'                   DATEDOC, DATEPROCESALES, PERPOST, TAXIGVID, TAXISCID, _
'                   TOTALPEN, TOTALUSD, SUBTOTALPEN, SUBTOTALUSD, TAXIGVPEN, _
'                   TAXIGVUSD, TAXISCPEN, TAXISCUSD, TOTALNOTAFFECTPEN, _
'                   TOTALNOTAFFECTUSD, TOTRETURNEDPEN, _
'                    TOTRETURNEDUSD, TOTCASHPEN, TOTCASHUSD, _
'                   custidss, taxregnbr, CUSTNAME, PLACA, NBRBONUS, CURYTYPEID, _
'                   CURYRATE, PROMOTIONCARDID, POINTNUMBER, SALESPOINT, KILOMETRAJE, _
'                   typesales, ADDR1
'
'End If
End Sub
Private Sub GRABAR_VENTA()
On Error GoTo errhandler

'*********************************************************************************
'GC_PAGOEFECTIVO = "01"
'GC_TARJETACRED = "02"
'GC_CHEQUEGERENCIA = "03"
'GC_CHEQUECOMERCIAL = "04"
'GC_CHEQUEDIFERIDOCRED = "05"
'GC_VALESCRED = "06"
'GC_OTROS = "00"

'LDblSubAfectoBase = Round(LDblSubAfectoBase, GintDecResultado)
'LDblNoAfectoBase = Round(LDblNoAfectoBase, GintDecResultado)
'LDblIGVBase = Round(LDblIGVBase, GintDecResultado)
'LdblTotalBase = Round(LdblTotalBase, GintDecResultado)
'LDblSubAfectoExt = Round(LDblSubAfectoExt, GintDecResultado)
'LDblNoAfectoExt = Round(LDblNoAfectoExt, GintDecResultado)
'LDblIGVExt = Round(LDblIGVExt, GintDecResultado)
'LdblTotalExt = Round(LdblTotalExt, GintDecResultado)


Dim LintcontadoCredito As Integer
Dim LrsGeneracion As ADODB.Recordset

If lbltipodepago.Caption = GC_VALESCRED Or lbltipodepago = "10" Then
   ' Si es pago con Vales o si es una Factura Generada de Crédito
   LintcontadoCredito = 0
Else
   LintcontadoCredito = 1
End If

    Dim LARRAY_AUX(1, 2) As Variant
    
    LARRAY_AUX(1, 1) = intMultiplesDocumentos
    LARRAY_AUX(1, 2) = pdbl_correlativo2

If intMultiplesDocumentos = 0 Then
        Set LrsGeneracion = mobj_cventasgen.GenerarNotadeCredito(dtc_tdocumentoref.BoundText, txt_NBRDOCUMENTref.Text, Format(dtp_fechapro.Value, "yyyymmdd"), Format(dtp_fecha.Value, "yyyymmdd"), dtc_serie.BoundText, _
                                                      txt_NBRDOCUMENT.Text, lbltipodepago.Caption, LintcontadoCredito, pdbl_correlativo, lblmoneda.Caption, "", _
                                                      GCUSERID, "", "", LdblTotalBase, LdblTotalExt, LDblSubAfectoBase, LDblSubAfectoExt, LDblIGVBase, _
                                                      LDblIGVExt, _
                                                      0, 0, LDblNoAfectoBase, LDblNoAfectoExt, 0, 0, 0, 0, 0, 0, 0, 0, TXT_IDCLIENTE.Text, _
                                                      txt_ruc.Text, txt_razonsocial.Text, "", lbltipodetipocmb.Caption, txt_tcambio.Text, 0, 0, "", 0, "", "", 0, txt_direccion.Text, "", _
                                                      "", "", "", LARRAY_AUX)
Else
        Set LrsGeneracion = mobj_cventasgen.GenerarNotadeCredito(dtc_tdocumentoref.BoundText, 0, Format(dtp_fechapro.Value, "yyyymmdd"), Format(dtp_fecha.Value, "yyyymmdd"), dtc_serie.BoundText, _
                                                      txt_NBRDOCUMENT.Text, lbltipodepago.Caption, LintcontadoCredito, pdbl_correlativo, lblmoneda.Caption, "", _
                                                      GCUSERID, "", "", LdblTotalBase, LdblTotalExt, LDblSubAfectoBase, LDblSubAfectoExt, LDblIGVBase, _
                                                      LDblIGVExt, _
                                                      0, 0, LDblNoAfectoBase, LDblNoAfectoExt, 0, 0, 0, 0, 0, 0, 0, 0, TXT_IDCLIENTE.Text, _
                                                      txt_ruc.Text, txt_razonsocial.Text, "", lbltipodetipocmb.Caption, txt_tcambio.Text, 0, 0, "", 0, "", "", 0, txt_direccion.Text, "", _
                                                      "", "", "", LARRAY_AUX)
End If

If Trim(LrsGeneracion!STATUSSTOCK) = "" And Trim(LrsGeneracion!TOMAINVENTARIO) = "" Then
   MsgBox "Nota de Crédito Generada con éxito", vbDefaultButton1 + vbInformation, "Mensaje"
   MBLN_INICIO = True
   MBlnDatosCargados = False
   Call borrar_valores
   Call INICIO
   
   Frame2.Enabled = False
   fraDatosItem.Enabled = False
   ctnadevolver.Enabled = False
   MdblGraboCorrectamente = True
   Call enfoque_inicial
 
   Exit Sub
Else
   If Trim(LrsGeneracion!STATUSSTOCK) <> "" Then
     MsgBox "No se puede Generar Nota de Crédito, Stock Insuficiente ", vbDefaultButton1 + vbExclamation, "Advertencia "
     MdblGraboCorrectamente = False
     Exit Sub
   End If
   If Trim(LrsGeneracion!TOMAINVENTARIO) <> "" Then
     MsgBox "No se puede Generar Nota de Crédito, Toma de Inventario Activada ", vbDefaultButton1 + vbExclamation, "Advertencia "
     MdblGraboCorrectamente = False
     Exit Sub
   End If
            
End If

Exit Sub

errhandler:
  MsgBox Err.Description, vbDefaultButton1 + vbExclamation, "Advertencia"

End Sub

Sub valida_cabezera1()
    If dtc_tdocumento.Text = "" Then
        MsgBox "Debe Escoger un tipo de documento", vbExclamation, "Precaucion"
        dtc_tdocumento.SetFocus
        pbln_errorcab = True
        Exit Sub
    End If
    If dtc_serie.Text = "" Then
        MsgBox "Debe Escoger una serie de documentos", vbExclamation, "Precaucion"
        dtc_serie.SetFocus
        pbln_errorcab = True
        Exit Sub
    End If
    If Val(txt_NBRDOCUMENT.Text) = 0 Then
        MsgBox "Debe Ingresar un numero de documento", vbExclamation, "Precaucion"
        dtc_serie.SetFocus
        pbln_errorcab = True
        Exit Sub
    End If
    
    If dtc_tdocumento.BoundText = dtc_tdocumentoref.BoundText Then
        MsgBox "Debe Escoger Tipos diferentes de documentos", vbExclamation, "Precaucion"
        dtc_tdocumentoref.SetFocus
        pbln_errorcab = True
        Exit Sub
    End If
    
'    If dtp_fechapro.Value > GDatFechaProcesoVentas Then
'        MsgBox " La fecha de proceso ingresada es mayor que la fecha de Venta", vbExclamation, "Error"
'        dtp_fechapro.SetFocus
'       pbln_errorcab = True
'        Exit Sub
'    End If
'    If dtp_fechapro.Value < GDatFechaProceso Then
'        MsgBox " La fecha Ingresada es menor que la fecha de Proceso", vbExclamation, "Error"
'        dtp_fechapro.SetFocus
'       pbln_errorcab = True
'        Exit Sub
'    End If
'    If dtp_fecha.Value > GDatFechaProcesoVentas Then
'        MsgBox " La fecha de proceso ingresada es mayor que la fecha de Venta", vbExclamation, "Error"
'        dtp_fecha.SetFocus
'        pbln_errorcab = True
'        Exit Sub
'    End If

pbln_errorcab = False
End Sub

Sub cierra_objetos()
Set mobj_cseguridad = Nothing
Set MOBJ_CMONEDA = Nothing
Set mobj_cdocumento = Nothing
Set mobj_cventasgen = Nothing
Set MOBJ_CVENTASCSTORE = Nothing
Set Mobj_Correlativo = Nothing
Set grscliente = Nothing
Set MrsGrilla = Nothing
Set rs_prod = Nothing
End Sub

Private Sub txt_NBRDOCUMENTref_Change()

 If MBlnDatosCargados = True Then
    MBlnDatosCargados = False
    borrar_valores
 End If
 
End Sub

Private Sub txt_NBRDOCUMENTref_GotFocus()
Call valida_cabezera1
End Sub

Private Sub CargaDatosCabecera()
      
   If IsNull(MrsDatos!CodCliente) Then
      TXT_IDCLIENTE.Text = ""
   Else
      TXT_IDCLIENTE.Text = MrsDatos!CodCliente
   End If
   If IsNull(MrsDatos!ruc) Then
      txt_ruc.Text = ""
   Else
      txt_ruc.Text = MrsDatos!ruc
   End If
   If IsNull(MrsDatos!NomCliente) Then
     txt_razonsocial.Text = ""
   Else
     txt_razonsocial.Text = MrsDatos!NomCliente
   End If
   If IsNull(MrsDatos!Tipo_Cambio) Then
     lbltipodetipocmb.Caption = ""
   Else
     lbltipodetipocmb.Caption = MrsDatos!Tipo_Cambio
   End If
   If IsNull(MrsDatos!Monto_Cambio) Then
     txt_tcambio.Text = 0
   Else
     txt_tcambio.Text = MrsDatos!Monto_Cambio
   End If
   If IsNull(MrsDatos!Fechaproceso) Then
     dtp_fecharef = Date
   Else
     dtp_fecharef = MrsDatos!Fechaproceso
   End If
   If IsNull(MrsDatos!Direccion) Then
     txt_direccion.Text = ""
   Else
     txt_direccion.Text = MrsDatos!Direccion
   End If
   
   If IsNull(MrsDatos!Tipo_Pago) Then
      lbltipodepago.Caption = ""
   Else
      lbltipodepago.Caption = MrsDatos!Tipo_Pago
   End If
         
   If IsNull(MrsDatos!MonedaDocu) Then
     lblmoneda.Caption = GstrCodMonedaBase
     GstrMonedaLimiteCredito = GstrCodMonedaBase
     TXT_MONEDATOTAL.Text = GstrSimboloMonedaBase
   Else
     GstrMonedaLimiteCredito = MrsDatos!MonedaDocu
     lblmoneda.Caption = MrsDatos!MonedaDocu
     If lblmoneda.Caption = GstrCodMonedaBase Then
        TXT_MONEDATOTAL.Text = GstrSimboloMonedaBaseModGen
     Else
        TXT_MONEDATOTAL.Text = GstrSimboloMonedaExtModGen
     End If
   End If
      
End Sub

Private Sub txt_NBRDOCUMENTref_KeyDown(KeyCode As Integer, Shift As Integer)
  If KeyCode = vbKeyF2 Then
     cmdbuscarnumero_Click
  End If
End Sub

Private Sub txt_NBRDOCUMENTref_KeyPress(KeyAscii As Integer)

Dim LSTR_DOCTYPE As String
Dim LDOU_NBR As Double

On Error GoTo errhandler

If KeyAscii = 13 Then
    intMultiplesDocumentos = 0
    cmdMarcar.Enabled = True
    cmdDesmarcar.Enabled = True
    
    If Trim(txt_NBRDOCUMENTref.Text) = Empty Then
       MsgBox "Ingrese Número de Referencia", vbDefaultButton1 + vbExclamation, "Advertencia"
       txt_NBRDOCUMENTref.SetFocus
       Exit Sub
    End If
      
    LSTR_DOCTYPE = dtc_tdocumentoref.BoundText
    LDOU_NBR = Val(txt_NBRDOCUMENTref.Text)
    
    If Not mobj_cventasgen.existedocumento(LSTR_DOCTYPE, LDOU_NBR, GstrSiteProce) Then
        MsgBox "Documento no existe", vbExclamation, "Atencion"
        txt_NBRDOCUMENTref.SetFocus
        MBlnDatosCargados = False
        Exit Sub
    Else
        If MBlnDatosCargados = False Then
           Set MrsDatos = mobj_cventasgen.cargar_referencias(LSTR_DOCTYPE, LDOU_NBR, GstrSiteProce, pdbl_correlativo)
        
           If Trim(MrsDatos!Estado) = "AN" Then
              MsgBox "Documento esta Anulado" + Chr(13) + "No Puede Generarse Nota Credito/Debito", vbExclamation, "Documento Incorrecto"
              txt_NBRDOCUMENTref.SetFocus
              Exit Sub
           End If
        
           CargaDatosCabecera
           Set MrsDatos = Nothing
           MBlnDatosCargados = True
           Call CARGAGRILLA(pdbl_correlativo)
        End If
   End If
   
End If

Exit Sub
errhandler:
    MsgBox Err.Description, vbDefaultButton1 + vbExclamation, "Error"
    intMultiplesDocumentos = 0
End Sub

Private Sub txtnumerodocu_Change()

  If MBlnConsultaCargada = True Then
     LimpiaConsulta
     MBlnConsultaCargada = False
  End If
End Sub

Private Sub txtnumerodocu_KeyDown(KeyCode As Integer, Shift As Integer)
  If KeyCode = vbKeyF2 Then
     cmdnumerodocumento_Click
  End If
End Sub

Private Sub txtnumerodocu_KeyPress(KeyAscii As Integer)
  
  If KeyAscii = 13 Then
     If Trim(txtnumerodocu.Text) = Empty Then
       MsgBox "Ingrese el Número de la Nota de Crédito ", vbDefaultButton1 + vbExclamation, "Advertencia"
     Else
       CargarDatosNotaCredito
     End If
  End If
  
End Sub

Sub CargarDatosNotaCredito()
Dim LStrMoneda As String

  '" Select NBRDOCUMENTREF,DESCR,DATEPROCESALES from (OP_DOCREFERENCE INNER JOIN DOCTYPE " & _
             " ON OP_DOCREFERENCE.DOCTYPEIDREF=DOCTYPE.DOCTYPEID) " & _
             " Inner join OP_SALES ON " & _
             " OP_DOCREFERENCE.DOCTYPEIDREF=OP_SALES.DOCTYPEID  AND " & _
             " OP_DOCREFERENCE.NBRDOCUMENTREF=OP_SALES.NBRDOCUMENT  AND " & _
             " OP_DOCREFERENCE.SITEID = OP_SALES.SITEID " & _
             " WHERE OP_DOCREFERENCE.DOCTYPEID='" & StrDOCTYPEID & "' AND " & _
             " OP_DOCREFERENCE.NBRDOCUMENT=" & DblNumeroDocumento & " AND " & _
             " OP_DOCREFERENCE.SITEID='" & StrSITEID & "'"
   
    
  Dim rsDatosNotaCredito As ADODB.Recordset
  Dim rsDocumentosReferencia As ADODB.Recordset
  
  
  Set rsDocumentosReferencia = mobj_cventasgen.ObtenerDocumentoReferencia(txtnumerodocu.Text, mobj_cventasgen.obtenertiponc, GstrSiteProce)
  Set rsDatosNotaCredito = mobj_cventasgen.ObtenerNotadeCredito(txtnumerodocu.Text, mobj_cventasgen.obtenertiponc, GstrSiteProce)
      
      
  If rsDatosNotaCredito.EOF Then
     MBlnConsultaCargada = False
     MsgBox "Documento no existe ", vbDefaultButton1 + vbExclamation, "Advertencia"
     txtnumerodocu.SetFocus
     Exit Sub
  End If
            
  lblfechadocumento.Caption = rsDatosNotaCredito!FechaDocu
  lblfechaproceso.Caption = rsDatosNotaCredito!FechaProce
  lbltipodecambio.Caption = rsDatosNotaCredito!TipoCambio
  If IsNull(rsDatosNotaCredito!CodCliente) Then
    txtcodcliente.Text = Empty
  Else
    txtcodcliente.Text = rsDatosNotaCredito!CodCliente
  End If
  
  If IsNull(rsDatosNotaCredito!ruc) Then
    txtruc.Text = Empty
  Else
    txtruc.Text = rsDatosNotaCredito!ruc
  End If
  
  If IsNull(rsDatosNotaCredito!NomCliente) Then
    txtapellido.Text = Empty
  Else
    txtapellido.Text = rsDatosNotaCredito!NomCliente
  End If
  
  If IsNull(rsDatosNotaCredito!Direccion) Then
   txtdireccion.Text = Empty
  Else
   txtdireccion.Text = rsDatosNotaCredito!Direccion
  End If
  
  LStrMoneda = rsDatosNotaCredito!Moneda
  lblmonedacons = LStrMoneda
  lblstatus.Caption = rsDatosNotaCredito!estadoDOcu
  
  If Trim(lblstatus.Caption) = "CA" Then
     Lblestado.Caption = "CANCELADA"
  End If
  If Trim(lblstatus.Caption) = "PE" Then
     Lblestado.Caption = "PENDIENTE"
  End If
  If Trim(lblstatus.Caption) = "AN" Then
     Lblestado.Caption = "ANULADA"
  End If
  If Trim(lblstatus.Caption) = "OK" Then
     Lblestado.Caption = "OK"
  End If
  
  cmbReferencia.Clear
  While Not rsDocumentosReferencia.EOF
    cmbReferencia.AddItem rsDocumentosReferencia!DESCR & " > " & rsDocumentosReferencia!NBRDOCUMENTREF
    rsDocumentosReferencia.MoveNext
  Wend
  'lbltiporeferencia.Caption = rsDocumentosReferencia!DESCR
  'lblnumerorefer.Caption = rsDocumentosReferencia!NBRDOCUMENTREF
  'lblfecharefer.Caption = rsDocumentosReferencia!DATEPROCESALES
      
  ' Cargar Totales
  
  lbltipopagocons.Caption = rsDatosNotaCredito!TipodePago
  lbltotalpen.Caption = rsDatosNotaCredito!TOTALPEN
  lbltotalusd.Caption = rsDatosNotaCredito!TOTALUSD
      
  If LStrMoneda = GstrCodMonedaBase Then
     txtsubtotal.Text = GFormatodeNumero(rsDatosNotaCredito!SUBTOTALPEN, GintDecResultado)
     txtnoafecto.Text = GFormatodeNumero(rsDatosNotaCredito!NoAfectoPen, GintDecResultado)
     txtigv.Text = GFormatodeNumero(rsDatosNotaCredito!igvpen, GintDecResultado)
     txttotal.Text = GFormatodeNumero(rsDatosNotaCredito!TOTALPEN, GintDecResultado)
     txtsimbolo.Text = GstrSimboloMonedaBaseModGen
  Else
     txtsubtotal.Text = GFormatodeNumero(rsDatosNotaCredito!SUBTOTALUSD, GintDecResultado)
     txtnoafecto.Text = GFormatodeNumero(rsDatosNotaCredito!NoAfectousd, GintDecResultado)
     txtigv.Text = GFormatodeNumero(rsDatosNotaCredito!igvusd, GintDecResultado)
     txttotal.Text = GFormatodeNumero(rsDatosNotaCredito!TOTALUSD, GintDecResultado)
     txtsimbolo.Text = GstrSimboloMonedaExtModGen
  End If
                       
  Set rsDocumentosReferencia = Nothing
  Set DBConsNotadeCredito.DataSource = rsDatosNotaCredito
  FormatoGrillaConsulta
  DBConsNotadeCredito.Refresh
  MBlnConsultaCargada = True
    
End Sub

Sub LimpiaConsulta()
  
  lblfechaproceso.Caption = Empty
  lblfechadocumento.Caption = Empty
  lbltipodecambio.Caption = GFormatodeNumero(0, 2)
  lbltiporeferencia.Caption = Empty
  lblnumerorefer.Caption = Empty
  lblfecharefer.Caption = Empty
  txtcodcliente.Text = Empty
  txtruc.Text = Empty
  txtapellido.Text = Empty
  txtdireccion.Text = Empty
  Set DBConsNotadeCredito.DataSource = Nothing
  DBConsNotadeCredito.Refresh
  lblmonedacons.Caption = Empty
  lbltipopagocons.Caption = Empty
  MBlnConsultaCargada = False
  lblstatus.Caption = ""
  Lblestado.Caption = ""
  lbltotalpen.Caption = 0
  lbltotalusd.Caption = 0
          
  txttotal.Text = GFormatodeNumero(0, GintDecResultado)
  txtsubtotal.Text = GFormatodeNumero(0, GintDecResultado)
  txtnoafecto.Text = GFormatodeNumero(0, GintDecResultado)
  txtigv.Text = GFormatodeNumero(0, GintDecResultado)
    
End Sub

Sub FormatoGrillaConsulta()
  '" Select OP_SALES.DATEDOC as FechaDocu ,OP_SALES.DATEPROCESALES as FechaProce," & _
             " OP_SALES.CURYRATE as TipoCambio,OP_SALES.custidss as CodCliente,OP_SALES.CURYID as Moneda, " & _
             " OP_SALES.DOCSTATUSID as EstadoDocu,TYPEPAYMENTID as TipodePago,OP_SALES.taxregnbr as Ruc," & _
             " OP_SALES.CUSTNAME as NomCliente ,CUSTOMER.addr1 as Direccion, " & _
             " OP_SALES.TOTALPEN as Totalpen,OP_SALES.TOTALUSD as TotalUsd,OP_SALES.SUBTOTALPEN as SubtotalPen,OP_SALES.SUBTOTALUSD as SubtotalUsd, " & _
             " OP_SALES.TAXIGVPEN as IgvPen,OP_SALES.TAXIGVUSD as IgvUsd,OP_SALES.TOTALNOTAFFECTPEN as NoAfectoPen,OP_SALES.TOTALNOTAFFECTUSD as NoAfectoUsd," & _
             " op_salesdet.SEQUENCE as Secuencia, INVTIDSKU, DESCRINVENTORY, SLSPRICESALE, QTY, PORCENTTAXIGV " & _
             " from (op_sales inner join op_salesdet on op_sales.DOCTYPEID=op_salesdet.DOCTYPEID and " & _
             " op_sales.NBRDOCUMENT = op_salesdet.NBRDOCUMENT and " & _
             " op_sales.SITEID=op_salesdet.SITEID) " & _
             " LEFT JOIN CUSTOMER ON OP_SALES.custidss=CUSTOMER.custidss " & _
             " where op_sales.NBRDOCUMENT=" & DblNumeroDocumento & " and op_sales.DOCTYPEID='" & DOCTYPEID & "' and  " & _
             " op_sales.SITEID='" & SITEID & "'"
  
  DBConsNotadeCredito.Columns(0).Visible = False
  DBConsNotadeCredito.Columns(1).Visible = False
  DBConsNotadeCredito.Columns(2).Visible = False
  DBConsNotadeCredito.Columns(3).Visible = False
  DBConsNotadeCredito.Columns(4).Visible = False
  DBConsNotadeCredito.Columns(5).Visible = False 'Estado del Documento
  DBConsNotadeCredito.Columns(6).Visible = False
  DBConsNotadeCredito.Columns(7).Visible = False 'Ruc
  DBConsNotadeCredito.Columns(8).Visible = False 'TotalPen
  DBConsNotadeCredito.Columns(9).Visible = False
  DBConsNotadeCredito.Columns(10).Visible = False
  DBConsNotadeCredito.Columns(11).Visible = False
  DBConsNotadeCredito.Columns(12).Visible = False 'Totalusd
  DBConsNotadeCredito.Columns(13).Visible = False
  DBConsNotadeCredito.Columns(14).Visible = False
  DBConsNotadeCredito.Columns(15).Visible = False
  DBConsNotadeCredito.Columns(16).Visible = False
  DBConsNotadeCredito.Columns(17).Visible = False
  DBConsNotadeCredito.Columns(18).Caption = "Secuencia"
  DBConsNotadeCredito.Columns(19).Caption = "Código"
  DBConsNotadeCredito.Columns(19).Width = 1250
  DBConsNotadeCredito.Columns(20).Caption = "Descripción"
  DBConsNotadeCredito.Columns(20).Width = 4000
  DBConsNotadeCredito.Columns(21).Caption = "Precio"
  DBConsNotadeCredito.Columns(21).Alignment = dbgRight
  DBConsNotadeCredito.Columns(21).NumberFormat = GMascara(GintDecPrecio)
  DBConsNotadeCredito.Columns(21).Width = 1150
  DBConsNotadeCredito.Columns(22).Caption = "Cantidad"
  DBConsNotadeCredito.Columns(22).Alignment = dbgRight
  DBConsNotadeCredito.Columns(22).NumberFormat = GMascara(GintDecStock)
  DBConsNotadeCredito.Columns(22).Width = 1150
  DBConsNotadeCredito.Columns(23).Caption = "% Igv"
  DBConsNotadeCredito.Columns(23).Alignment = dbgRight
  DBConsNotadeCredito.Columns(23).NumberFormat = GMascara(GintDecPrecio)
  DBConsNotadeCredito.Columns(23).Width = 1150
End Sub

Public Sub CargaDatos(strAlmacen As String, strTipoDoc As String, dblNroDoc As Double)
   
   dtc_tdocumentoref.BoundText = strTipoDoc
   txt_NBRDOCUMENTref.Text = dblNroDoc
   txt_NBRDOCUMENTref_KeyPress (13)
   
End Sub

Public Sub CargaDatos2(CORREL As Double, intCLIENTE As Integer, STRCODCLIENTE As String, strTIPOPAGO As String)
'ACA SE INSERTA EN LA TABLA TEMPORAL
    Dim LARRAY(1, 2) As Variant
    Dim LRSFIL As ADODB.Recordset
    
    pdbl_correlativo2 = CORREL
    intMultiplesDocumentos = 1
    
    LARRAY(1, 1) = pdbl_correlativo2
    LARRAY(1, 2) = pdbl_correlativo
    
    mobj_cventasgen.Auxiliar3 LARRAY

    Set LRSFIL = mobj_cventasgen.Auxiliar4(STRCODCLIENTE)
  '''''''''''''''''''''''''''''''''''''
    txt_NBRDOCUMENTref.Text = ""
    
    If intCLIENTE = 1 Then
        If IsNull(LRSFIL!CUSTIDSS) Then
            TXT_IDCLIENTE.Text = ""
        Else
            TXT_IDCLIENTE.Text = LRSFIL!CUSTIDSS
        End If
        If IsNull(LRSFIL!taxregnbr) Then
            txt_ruc.Text = ""
        Else
            txt_ruc.Text = LRSFIL!taxregnbr
        End If
        If IsNull(LRSFIL!custname) Then
            txt_razonsocial.Text = ""
        Else
            txt_razonsocial.Text = LRSFIL!custname
        End If
        If IsNull(LRSFIL!addr1) Then
            txt_direccion.Text = ""
        Else
            txt_direccion.Text = LRSFIL!addr1
        End If

    End If
    
    lbltipodetipocmb.Caption = GstrTipoCambioVentas
    txt_tcambio.Text = mobj_cventasgen.ObtenerMontoTipodeCambio(GstrCodMonedaBase, GstrMonedaExtranjeraModgen, dtp_fechapro.Value, GstrTipoCambioVentas)
    lbltipodepago.Caption = Trim(strTIPOPAGO)
    
    lblmoneda.Caption = GstrCodMonedaBase
    GstrMonedaLimiteCredito = GstrCodMonedaBase
    TXT_MONEDATOTAL.Text = GstrSimboloMonedaBase

    cmdMarcar.Enabled = False
    cmdDesmarcar.Enabled = False
  '''''''''''''''''''''''''''''''''''''
    Call CARGAGRILLA(pdbl_correlativo)

End Sub


Public Sub CargaDatosConsultaNc(strAlmacen As String, strTipoDoc As String, dblNroDoc As Double)
      
   txtnumerodocu.Text = dblNroDoc
   txtnumerodocu_KeyPress (13)
   
End Sub

Public Sub agregar_registro()
    'Call gagregar_registro(Me, TxtRuc)
    
    cmdnuevo_Click
    
    Me.pb_agregar = True
    Me.pb_editar = True
    'gHabilitarReg Me, Me.pb_editar
    Call gactualiza_barra(Me)
        
End Sub

Public Sub modificar_registro()
    'Call gmodificar_registro(Me, txtCodigo)
End Sub


Public Sub descartar_registro()
    'Revertir cambios
    'adodc1.Recordset.CancelUpdate
    
    'LimpiaFormulario
     cmd_Cancelar_Click
    
    'Call gdescartar_registro(Me)
    
    Me.pb_agregar = False
    Me.pb_editar = False
    MdblGraboCorrectamente = False
    'Call gHabilitarReg(frm, frm.pb_editar)
    
    Call gactualiza_barra(Me)
    Call gactualizaopcion(Me.pbderecho_agregar, Me.pbderecho_editar, Me.pbderecho_borrar, Me.pbderecho_imprimir)
    MsgBox ("Cambios Descartados"), vbInformation + vbDefaultButton1, "Mensaje"
    'Call asigna_campos
End Sub

Sub obtener_datos()
End Sub

Sub asigna_campos() ' falta decidir si va ha ser public o private
End Sub

Public Sub actualizar_registro()
    'llamar al procedimiento de carga
    Call obtener_datos
    Call asigna_campos
    'MsgBox ("Registros Actualizados")
End Sub

Public Function valida_datos() As Boolean
   valida_datos = True
End Function

Public Sub grabar_registro()

    If valida_datos() = True Then
        ' llamada al proc de grabacion
        If pb_agregar Then
             If cmd_efectivo.Enabled = True Then
                 Screen.MousePointer = 11
                 cmd_efectivo_Click
                 Screen.MousePointer = 0
             Else
                 Screen.MousePointer = 0
                 Exit Sub
             End If
         Else
             Screen.MousePointer = 0
             Exit Sub
         End If
         
         If MdblGraboCorrectamente = True Then
           Me.pb_agregar = False
           Me.pb_editar = False
           Call gactualiza_barra(Me)
           'Call gHabilitarReg(frm, frm.pb_editar)
           Call gactualizaopcion(Me.pbderecho_agregar, Me.pbderecho_editar, Me.pbderecho_borrar, Me.pbderecho_imprimir)
           'LimpiaFormulario
           actualizar_registro
         End If
    End If
    
End Sub

Public Sub borrar_registro()

End Sub
Public Sub imprimir2()
On Error GoTo trataerror

'    If GVDATO(dtcAlmacen.BoundText) = Empty Then
'        MsgBox "Seleccione algún registro que desee Imprimir", vbExclamation, "Imprimir"
'        Exit Sub
'    End If
    
    Screen.MousePointer = 11

'    crDeposito.ReportFileName = GstrReportesVta + "rpt_Reporte_NtaCredito.rpt"
'    crDeposito.WindowTitle = "Reporte de Nota de Credito"
'    crDeposito.Formulas(2) = "formusuario=stringvar strusuario; strusuario:='" & GCUSERID & "'"
'    crDeposito.Formulas(3) = "formscreen=stringvar strscreen; strscreen:='05.120.00'"
'    crDeposito.Formulas(5) = "formNDStock=" & GintDecStock
'    crDeposito.Formulas(6) = "formNDCosto=" & GintDecCosto
'    crDeposito.Formulas(7) = "formNDMonto=" & GintDecResultado
'    crDeposito.Formulas(8) = "formNDPrecio=" & GintDecPrecio
    
'    crDeposito.StoredProcParam(0) = Trim(dtc_serie.Text) + Trim(txt_NBRDOCUMENT.Text)
'    crDeposito.StoredProcParam(1) = GstrSiteProce
    
'    crDeposito.WindowState = crptMaximized
'    crDeposito.WindowShowPrintSetupBtn = True
'    crDeposito.Action = 1
'    crDeposito.Reset
        
    Screen.MousePointer = 0
    Exit Sub

trataerror:
    Screen.MousePointer = 0
    MsgBox "Error Generando reporte", vbExclamation, "Error"
End Sub

Public Sub imprimir()
On Error GoTo trataerror

'    If GVDATO(dtcAlmacen.BoundText) = Empty Then
'        MsgBox "Seleccione algún registro que desee Imprimir", vbExclamation, "Imprimir"
'        Exit Sub
'    End If
    
    Screen.MousePointer = 11

    crReporte.ReportFileName = GstrReportesVta + "rpt_Reporte_NtaCredito.rpt"
    crReporte.WindowTitle = "Reporte de Nota de Credito"
    crReporte.Formulas(1) = "formusuario=stringvar strusuario; strusuario:='" & GCUSERID & "'"
    crReporte.Formulas(2) = "formscreen=stringvar strscreen; strscreen:='05.030.00'"
    crReporte.Formulas(3) = "formNDStock=" & GintDecStock
    crReporte.Formulas(4) = "formNDCosto=" & GintDecCosto
    crReporte.Formulas(5) = "formNDMonto=" & GintDecResultado
    crReporte.Formulas(6) = "formNDPrecio=" & GintDecPrecio
    
    crReporte.StoredProcParam(0) = IIf(txtnumerodocu.Text = "", 0, txtnumerodocu.Text)
    crReporte.StoredProcParam(1) = GstrSiteProce
    crReporte.StoredProcParam(2) = 0
    
    crReporte.WindowState = crptMaximized
    crReporte.WindowShowPrintSetupBtn = True
    crReporte.Action = 1
    crReporte.Reset
        
    Screen.MousePointer = 0
    Exit Sub

trataerror:
    Screen.MousePointer = 0
    MsgBox "Error Generando reporte", vbExclamation, "Error"
End Sub
