VERSION 5.00
Object = "{F0D2F211-CCB0-11D0-A316-00AA00688B10}#1.0#0"; "MSDATLST.OCX"
Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Begin VB.Form fbuscardocumentos 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Buscar Transacciones (05.035.00)"
   ClientHeight    =   6300
   ClientLeft      =   150
   ClientTop       =   435
   ClientWidth     =   11985
   ClipControls    =   0   'False
   BeginProperty Font 
      Name            =   "Arial"
      Size            =   9.75
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   6300
   ScaleWidth      =   11985
   StartUpPosition =   3  'Windows Default
   Begin MSDataListLib.DataCombo dtcalmacen 
      Height          =   360
      Left            =   4080
      TabIndex        =   14
      Top             =   120
      Width           =   3015
      _ExtentX        =   5318
      _ExtentY        =   635
      _Version        =   393216
      Style           =   2
      Text            =   ""
   End
   Begin VB.TextBox txt_NBRDOCUMENT 
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   320
      Left            =   4920
      MaxLength       =   10
      TabIndex        =   2
      Top             =   540
      Width           =   1395
   End
   Begin MSComCtl2.DTPicker dtp_fechaini 
      Height          =   375
      Left            =   1560
      TabIndex        =   0
      Top             =   113
      Width           =   1395
      _ExtentX        =   2461
      _ExtentY        =   661
      _Version        =   393216
      CustomFormat    =   "dd/MM/yyyy"
      Format          =   20774915
      CurrentDate     =   37613
   End
   Begin VB.CommandButton CMB_BUSCAR 
      BackColor       =   &H00E0E0E0&
      Caption         =   "&Buscar"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   735
      Left            =   7200
      Picture         =   "fbuscardocumentos.frx":0000
      Style           =   1  'Graphical
      TabIndex        =   3
      Top             =   180
      Width           =   1155
   End
   Begin VB.CommandButton CMD_CANCELAR 
      BackColor       =   &H00E0E0E0&
      Cancel          =   -1  'True
      Caption         =   "&Salir"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   795
      Left            =   10740
      Picture         =   "fbuscardocumentos.frx":030A
      Style           =   1  'Graphical
      TabIndex        =   7
      Top             =   5400
      Width           =   1155
   End
   Begin VB.CommandButton cmd_Mostrar 
      BackColor       =   &H00E0E0E0&
      Caption         =   "&Anular"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   795
      Left            =   10740
      Picture         =   "fbuscardocumentos.frx":0614
      Style           =   1  'Graphical
      TabIndex        =   5
      Tag             =   "R ASDASD"
      Top             =   3600
      Width           =   1155
   End
   Begin VB.CommandButton cmd_eliminar 
      BackColor       =   &H00E0E0E0&
      Caption         =   "&Eliminar"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   795
      Left            =   10740
      Picture         =   "fbuscardocumentos.frx":091E
      Style           =   1  'Graphical
      TabIndex        =   6
      Tag             =   "R ASDASD"
      Top             =   4500
      Width           =   1155
   End
   Begin MSDataGridLib.DataGrid DBCABEZERA 
      Height          =   2535
      Left            =   0
      TabIndex        =   4
      Top             =   1020
      Width           =   11895
      _ExtentX        =   20981
      _ExtentY        =   4471
      _Version        =   393216
      HeadLines       =   1
      RowHeight       =   17
      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            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Caption         =   "Ventas"
      ColumnCount     =   2
      BeginProperty Column00 
         DataField       =   ""
         Caption         =   ""
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   3082
            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            =   3082
            SubFormatType   =   0
         EndProperty
      EndProperty
      SplitCount      =   1
      BeginProperty Split0 
         BeginProperty Column00 
         EndProperty
         BeginProperty Column01 
         EndProperty
      EndProperty
   End
   Begin MSDataGridLib.DataGrid DBDetalle 
      Height          =   2595
      Left            =   0
      TabIndex        =   8
      Top             =   3600
      Width           =   10695
      _ExtentX        =   18865
      _ExtentY        =   4577
      _Version        =   393216
      AllowUpdate     =   0   'False
      Enabled         =   -1  'True
      HeadLines       =   1
      RowHeight       =   19
      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            =   "Arial"
         Size            =   9.75
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Caption         =   "Detalle de Ventas "
      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 MSComCtl2.DTPicker dtp_fechafin 
      Height          =   375
      Left            =   1560
      TabIndex        =   1
      Top             =   513
      Width           =   1395
      _ExtentX        =   2461
      _ExtentY        =   661
      _Version        =   393216
      CustomFormat    =   "dd/MM/yyyy"
      Format          =   20774915
      CurrentDate     =   37613
   End
   Begin VB.Label Label4 
      AutoSize        =   -1  'True
      Caption         =   "Almacén"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   240
      Left            =   3120
      TabIndex        =   13
      Top             =   180
      Width           =   840
   End
   Begin VB.Label Label5 
      AutoSize        =   -1  'True
      Caption         =   "Nro.Documento:"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   240
      Left            =   3120
      TabIndex        =   12
      Top             =   580
      Width           =   1680
   End
   Begin VB.Label Label3 
      AutoSize        =   -1  'True
      Caption         =   "Fecha Final:"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   240
      Left            =   120
      TabIndex        =   11
      Top             =   580
      Width           =   1290
   End
   Begin VB.Label Label2 
      AutoSize        =   -1  'True
      Caption         =   "Fecha Inicial:"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   240
      Left            =   120
      TabIndex        =   10
      Top             =   180
      Width           =   1395
   End
   Begin VB.Label Label1 
      Caption         =   "[F12] Eliminar [F11] Anular"
      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            =   8520
      TabIndex        =   9
      Top             =   660
      Width           =   3375
   End
End
Attribute VB_Name = "fbuscardocumentos"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim mobj_cventasgen As DB_OP_FACTURACION.C_VENTASGENERAL
Dim MOBJ_CVENTASCSTORE As DB_OP_FACTURACION.C_VENTASCSTORE
Dim MobjMovimientos As DB_INV_MOVIMIENTOS.C_MOVIMIENTOS
Dim MOBJALMACEN As DB_INV_MANTENIMIENTOS.C_ALMACEN

Dim RS_TEMP As ADODB.Recordset
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_ANULAR As Boolean
Public pb_tiposcreen As String
Public pbderecho_EMITIR As Boolean
Public bln_deletedoc As Boolean
Public pstr_tnegocio As String



Public NumBonus As Double

Function ElimNumGuiaFacC(TipoDoc As String, NumDocu As Double, CodCli As String, _
                                Estacion As String, NumGuia As Double) As Boolean
'Autor: Jorge
'Operatividad: Permite eliminar el numero de vale(Guia) de una venta credito
'                                                           (Factura Credito)
On Error GoTo elerror
Dim cnCon As ADODB.Connection
Dim SqlElimGuia As String

Set cnCon = New ADODB.Connection
    cnCon.ConnectionString = _
        "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;" & _
        "Initial Catalog=sies;Data Source=server"
    cnCon.Open

SqlElimGuia = _
    "DELETE FROM OP_BONUS " & _
        "WHERE DOCTYPEID = '" & TipoDoc & "' AND NBRDOCUMENT = " & NumDocu & " AND " & _
            "CUSTIDSS = '" & CodCli & "' AND SITEID = '" & Estacion & "' AND " & _
            "NBRBONUS = " & NumGuia & ""

cnCon.BeginTrans
    cnCon.Execute (SqlElimGuia)
cnCon.CommitTrans

ElimNumGuiaFacC = True

cnCon.Close
Exit Function

elerror:
    MsgBox "Error: " & CStr(Err.Number) + Chr(13) + _
           "Descripcion: " & Err.Description, vbCritical, "William ha ocurrido un error"

    If cnCon.State = adStateOpen Then
        cnCon.RollbackTrans
    End If
    ElimNumGuiaFacC = False
    Exit Function
    
End Function

Public Sub FormatoGrilladet()
DBDetalle.Columns(0).Caption = "Seq"
DBDetalle.Columns(0).Width = 380
DBDetalle.Columns(0).AllowSizing = False
DBDetalle.Columns(1).Caption = "Id.Producto"
DBDetalle.Columns(1).Width = 1200
DBDetalle.Columns(1).AllowSizing = False
DBDetalle.Columns(2).Caption = "Descripcion"
DBDetalle.Columns(2).Width = 4500
DBDetalle.Columns(2).AllowSizing = False
DBDetalle.Columns(3).Caption = "Precio"
DBDetalle.Columns(3).Width = 1200  'Precio
DBDetalle.Columns(3).Alignment = dbgRight
DBDetalle.Columns(3).NumberFormat = GMascara(GintDecPrecio)
DBDetalle.Columns(3).AllowSizing = False
DBDetalle.Columns(4).Caption = "%Impto"
DBDetalle.Columns(4).Width = 590
DBDetalle.Columns(4).Alignment = dbgRight
DBDetalle.Columns(4).NumberFormat = GMascara(GintDecPrecio)
DBDetalle.Columns(4).AllowSizing = False
DBDetalle.Columns(5).Caption = "Cantidad"
DBDetalle.Columns(5).Width = 920
DBDetalle.Columns(5).Alignment = dbgRight
DBDetalle.Columns(5).NumberFormat = GMascara(GintDecStock)
DBDetalle.Columns(5).AllowSizing = False
DBDetalle.Columns(6).Caption = "Sub Total"
DBDetalle.Columns(6).Visible = True
DBDetalle.Columns(6).Width = 1500 'Total Base
DBDetalle.Columns(6).Alignment = dbgRight
DBDetalle.Columns(6).NumberFormat = GMascara(GintDecPrecio)
DBDetalle.Columns(6).Caption = "Total"
DBDetalle.Columns(6).AllowSizing = False
End Sub

Function VerifCantGuiasFC(NumDoc As Double) As Double
'Permite saber si existe mas de una Guia Emitida por cada Ticket Factura emitida
'On Error GoTo elerror
Dim cnCon As ADODB.Connection
Dim rsComprueba As ADODB.Recordset
Dim sqlComp As String
Dim numReg As Integer
Set cnCon = New ADODB.Connection
    cnCon.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=sies;Data Source=server"
sqlComp = _
    "SELECT NBRBONUS FROM OP_BONUS WHERE NBRDOCUMENT = " & NumDoc & ""

'cnCon.BeginTrans
    Set rsComprueba = cnCon.Execute(sqlComp)
'cnCon.CommitTrans

Do While Not rsComprueba.EOF
    numReg = numReg + 1
    rsComprueba.MoveNext
Loop

If numReg > 1 Then
    VerifCantGuiasFC = 0
ElseIf numReg = 1 Then
    rsComprueba.MoveFirst
    NumBonus = rsComprueba!NBRBONUS
    VerifCantGuiasFC = NumBonus
End If

rsComprueba.Close
cnCon.Close

Exit Function
elerror:
'    cnCon.RollbackTrans
    Exit Function
    
End Function

Private Sub CMB_BUSCAR_Click()
Screen.MousePointer = 11
Call FormatoGrillacab
Screen.MousePointer = 0
End Sub

Private Sub cmd_Cancelar_Click()
Call cierraobjetos
Unload Me
End Sub

Private Sub cmd_eliminar_Click()
If Not RS_TEMP.EOF Or RS_TEMP.RecordCount > 0 Then
     Call borrar_venta
End If
End Sub


Private Sub cmd_Mostrar_Click()
    If Not RS_TEMP.EOF Or RS_TEMP.RecordCount > 0 Then
        Screen.MousePointer = 11
        Call anular_venta
        Screen.MousePointer = 0
    End If
End Sub
Private Sub DBCABEZERA_KeyDown(KeyCode As Integer, Shift As Integer)

If KeyCode = vbKeyDown Or KeyCode = vbKeyUp Then
    Call ACTUALIZADETALLEGRILLA
End If

If KeyCode = vbKeyEscape Then
    Call cmd_Cancelar_Click
End If

If KeyCode = vbKeyF12 Then
    If Not RS_TEMP.EOF Or RS_TEMP.RecordCount > 0 Then
        Call borrar_venta
    End If
End If

If KeyCode = 13 Then
    If Not RS_TEMP.EOF Or RS_TEMP.RecordCount > 0 Then
        'Call recuperar
    End If
End If

If KeyCode = vbKeyF11 Then
    If Not RS_TEMP.EOF Or RS_TEMP.RecordCount > 0 Then
        Call anular_venta
    End If
End If
End Sub

Private Sub DBCABEZERA_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
    Call ACTUALIZADETALLEGRILLA
End Sub
Sub ACTUALIZADETALLEGRILLA()
Dim ldbo_nro As Double
Dim lstr_tipodoc As String
If Not RS_TEMP.EOF And RS_TEMP.RecordCount > 0 Then
    ldbo_nro = RS_TEMP!nro
    lstr_tipodoc = RS_TEMP!DOCTYPEID
    Set DBDetalle.DataSource = mobj_cventasgen.obtenerventasdetayuda(lstr_tipodoc, ldbo_nro, GstrSiteProce)
    Call FormatoGrilladet
End If
End Sub


Private Sub dtp_fechafin_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
    txt_NBRDOCUMENT.SetFocus
End If
End Sub

Private Sub dtp_fechaini_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
    dtp_fechafin.SetFocus
End If
End Sub

Private Sub Form_Activate()
If Not pbderecho_consultar Then
    Call cierraobjetos
    Unload Me
    Exit Sub
End If
dtp_fechaini.Value = Date
dtp_fechafin.Value = Date
Call FormatoGrillacab
dtp_fechaini.SetFocus
bln_deletedoc = mobj_cventasgen.obtenerdeletedoc(GstrPuntodeVenta)

End Sub

Private Sub Form_Load()
Call gseguridad(Me)
If pbderecho_consultar Then
    
    Set mobj_cventasgen = New DB_OP_FACTURACION.C_VENTASGENERAL
    Set MOBJ_CVENTASCSTORE = New DB_OP_FACTURACION.C_VENTASCSTORE
    Set MobjMovimientos = New DB_INV_MOVIMIENTOS.C_MOVIMIENTOS
    Set MOBJALMACEN = New DB_INV_MANTENIMIENTOS.C_ALMACEN
    
    
    Call CargaDataCombo(dtcalmacen, MOBJALMACEN.ListarAlmacenesPorStatus(1), "SiteId", "Name")
    
    dtcalmacen.BoundText = GstrSiteProce
Else
    MsgBox "No tiene Derechos de Consultar en este formulario", vbInformation, "Atencion"
End If

End Sub
Public Sub FormatoGrillacab()
Dim ldat_fi As Date
Dim ldat_ff As Date
Dim LDBL_NDOC As Double
ldat_fi = dtp_fechaini.Value
ldat_ff = dtp_fechafin.Value
LDBL_NDOC = Val(Trim(txt_NBRDOCUMENT.Text))
'Set RS_TEMP = mobj_cventasgen.op_obtenerventasayuda(GstrSiteProce, ldat_fi, ldat_ff, LDBL_NDOC, pstr_tnegocio)

Set RS_TEMP = mobj_cventasgen.op_obtenerventasayuda(dtcalmacen.BoundText, ldat_fi, ldat_ff, LDBL_NDOC, pstr_tnegocio)

Set DBCABEZERA.DataSource = RS_TEMP
DBCABEZERA.Columns(0).Width = 950      'Tipo Documento.
DBCABEZERA.Columns(0).AllowSizing = False
DBCABEZERA.Columns(1).Width = 1200      'numero
DBCABEZERA.Columns(1).AllowSizing = False

DBCABEZERA.Columns(2).Width = 1000      'Estado
DBCABEZERA.Columns(2).AllowSizing = False

DBCABEZERA.Columns(3).Width = 1650      'Forma pago
DBCABEZERA.Columns(3).AllowSizing = False

DBCABEZERA.Columns(4).Width = 950      'Fecha proceso
DBCABEZERA.Columns(4).Alignment = dbgRight
DBCABEZERA.Columns(4).AllowSizing = False

DBCABEZERA.Columns(5).Width = 2100      'Fecha documento
DBCABEZERA.Columns(5).Alignment = dbgRight
DBCABEZERA.Columns(5).AllowSizing = False

DBCABEZERA.Columns(6).Width = 850      'Total
DBCABEZERA.Columns(6).Alignment = dbgRight
DBCABEZERA.Columns(6).NumberFormat = GMascara(GintDecPrecio)
DBCABEZERA.Columns(6).AllowSizing = False

DBCABEZERA.Columns(7).Width = 1200      'Idcliente
DBCABEZERA.Columns(7).AllowSizing = False

DBCABEZERA.Columns(8).Width = 2900      'cliente
DBCABEZERA.Columns(8).AllowSizing = False

DBCABEZERA.Columns(9).Visible = False   'site
DBCABEZERA.Columns(10).Visible = False   'site
DBCABEZERA.Columns(11).Visible = False   'site
DBCABEZERA.Columns(12).Visible = False   'site
DBCABEZERA.Columns(13).Visible = False   'site

DBCABEZERA.AllowRowSizing = False
If RS_TEMP.RecordCount > 0 Then
    Call DBCABEZERA_RowColChange(1, 1)
    
End If
End Sub
Public Sub borrar_venta()
If RS_TEMP.EOF Or RS_TEMP.RecordCount = 0 Then
    MsgBox "No Existe Informacion", vbExclamation, "Atencion"
    Exit Sub
End If

If Not bln_deletedoc Then
    MsgBox "No se Puede Eliminar Documentos en este punto de venta", vbExclamation, "Atencion"
    Exit Sub
End If

If Not pbderecho_borrar Then
    MsgBox "No tiene derecho de Eliminar Documentos", vbExclamation, "Atencion"
    Exit Sub
End If

Dim ldbo_nro As Double
Dim lstr_tipodoc As String
Dim lstr_descrdoc As String
Dim lstr_status As String
Dim lstr_tipopago As String
Dim lstr_codcliente As String
Dim ldou_montopen As Double
Dim ldou_montousd As Double
Dim ERROR As Integer

ldbo_nro = RS_TEMP!nro
lstr_tipodoc = RS_TEMP!DOCTYPEID
lstr_descrdoc = RS_TEMP!Tipo_Doc
lstr_codcliente = RS_TEMP!Id_Cliente
ldou_montopen = RS_TEMP!monto
ldou_montousd = RS_TEMP!TOTALUSD
lstr_tipopago = RS_TEMP!TYPEPAYMENTID
lstr_status = RS_TEMP!docstatusid


Dim LrsMesCerrado As ADODB.Recordset
Set LrsMesCerrado = MobjMovimientos.ValidaMesCerrado(GstrSiteProce, RS_TEMP!FECHA)

If LrsMesCerrado!MESCERRADO = 1 Then
   MsgBox " No se puede Anular un Documento de un Mes que ya ha sido Cerrado", vbExclamation + vbDefaultButton1, "Mensaje"
   Exit Sub
Else
  If LrsMesCerrado!PDCERRADO = 1 Then
     MsgBox " No se puede Anular un Documento de un Parte Diario que ya ha sido Cerrado", vbExclamation + vbDefaultButton1, "Mensaje"
     Exit Sub
  End If
End If


'If RS_TEMP!FECHA < GDatFechaProcesoVentas Then
'    MsgBox " No se Puede Eliminar el documento" + Chr(13) + " Es anterior a la fecha de proceso", vbExclamation, "Atencion"
'    Exit Sub
'End If
ldbo_nro = RS_TEMP!nro
lstr_tipodoc = RS_TEMP!DOCTYPEID

If lstr_tipodoc = mobj_cventasgen.obtenertipoticket Then
    MsgBox " No se Puede Eliminar un Ticket", vbExclamation, "Atencion"
    Exit Sub
End If


lstr_descrdoc = RS_TEMP!Tipo_Doc
If MsgBox("Esta seguro de Eliminar el siguiente Documento?" + _
        Chr(13) + lstr_descrdoc + " No. " + Str(ldbo_nro), _
        vbQuestion + vbYesNo, "Atencion") = vbYes Then
    
        'VERIFICAR QUE NO TENGA NOTAS DE CREDITO NI NOTAS DE DEBITO
        If mobj_cventasgen.existereferencias(lstr_tipodoc, ldbo_nro, GstrSiteProce) Then
            MsgBox " No se Puede Eliminar el Documento" + Chr(13) + "Tiene Referencias", vbExclamation, "Atencion"
            Exit Sub
        End If
        
        If lstr_status = "CA" Then
            MsgBox "No se Puede Eliminar El Documentos " + Chr(13) + _
                   "Documento esta Cancelado", vbExclamation, "Precaucion"
            Exit Sub
        End If
    
    
    If lstr_tipopago = "10" Or lstr_tipopago = "11" Then
        MsgBox "No se Puede Eliminar El Documentos " + Chr(13) + _
               "Documento es Generado", vbExclamation, "Precaucion"
            Exit Sub
    End If

    ERROR = mobj_cventasgen.eliminarventa(lstr_tipodoc, ldbo_nro, GstrSiteProce, _
        lstr_status, lstr_tipopago, lstr_codcliente, ldou_montopen, ldou_montousd)
    
    
    Select Case ERROR
        Case 0
            MsgBox "Documento Eliminado", vbExclamation, "Precaucion"
        Case 1
            MsgBox "Error Eliminando Documento", vbExclamation, "Precaucion"
        Case 3
            MsgBox "Documento Tiene pagos Efectuados", vbExclamation, "Precaucion"
        Case 4
            MsgBox "Documento Tiene una nota de credito o debito asociado", vbExclamation, "Precaucion"
    End Select
    Call FormatoGrillacab
    txt_NBRDOCUMENT.Text = ""
    txt_NBRDOCUMENT.SetFocus
End If

End Sub

Public Sub recuperar()
Dim ldbo_nro As Double
Dim lstr_tipodoc As String
Dim lstr_descrdoc As String

ldbo_nro = RS_TEMP!nro
lstr_tipodoc = RS_TEMP!DOCTYPEID
lstr_descrdoc = RS_TEMP!Tipo_Doc

If MsgBox("Esta Seguro de Recuperar el siguiente documento " + _
        Chr(13) + lstr_descrdoc + " No. " + Str(ldbo_nro), _
        vbYesNo, "Atencion") = vbYes Then
 Else
    Exit Sub
End If
Unload Me
End Sub

Private Sub txt_NBRDOCUMENT_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
    CMB_BUSCAR_Click
End If
End Sub

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

End Sub

Public Sub anular_venta()
If RS_TEMP.EOF Or RS_TEMP.RecordCount = 0 Then
    MsgBox "No Existe Informacion", vbExclamation, "Atencion"
    Exit Sub
End If

If Not bln_deletedoc Then
    MsgBox "No se Puede Anular Documentos en este punto de venta", vbExclamation, "Atencion"
    Exit Sub
End If

If Not pbderecho_ANULAR Then
    MsgBox "No tiene derecho de anular Documentos", vbExclamation, "Atencion"
    Exit Sub
End If


Dim ldbo_nro As Double
Dim lstr_tipodoc As String
Dim lstr_descrdoc As String
Dim lstr_status As String
Dim lstr_tipopago As String
Dim lstr_codcliente As String
Dim ldou_montopen As Double
Dim ldou_montousd As Double
Dim ERROR As Integer

Dim LrsMesCerrado As ADODB.Recordset
Set LrsMesCerrado = MobjMovimientos.ValidaMesCerrado(GstrSiteProce, RS_TEMP!FECHA)

If LrsMesCerrado!MESCERRADO = 1 Then
   MsgBox " No se puede Anular un Documento de un Mes que ya ha sido Cerrado", vbExclamation + vbDefaultButton1, "Mensaje"
   Exit Sub
Else
  If LrsMesCerrado!PDCERRADO = 1 Then
     MsgBox " No se puede Anular un Documento de un Parte Diario que ya ha sido Cerrado", vbExclamation + vbDefaultButton1, "Mensaje"
     Exit Sub
  End If
End If


'If RS_TEMP!FECHA < GDatFechaProcesoVentas Then
'    MsgBox " No se Puede Anular el documento" + Chr(13) + " Es anterior a la fecha de proceso", vbExclamation, "Atencion"
'    Exit Sub
'End If

ldbo_nro = RS_TEMP!nro
lstr_tipodoc = RS_TEMP!DOCTYPEID
lstr_descrdoc = RS_TEMP!Tipo_Doc
lstr_codcliente = RS_TEMP!Id_Cliente
ldou_montopen = RS_TEMP!monto
ldou_montousd = RS_TEMP!TOTALUSD
lstr_tipopago = RS_TEMP!TYPEPAYMENTID
lstr_status = RS_TEMP!docstatusid

If lstr_status = "AN" Then
        MsgBox "Documento ya esta anulado", vbExclamation, "Precaucion"
        Exit Sub
End If

If lstr_status = "CA" Then
        MsgBox "No se Puede Anular El Documentos " + Chr(13) + _
               "Documento esta Cancelado", vbExclamation, "Precaucion"
        Exit Sub
End If


If lstr_tipopago = "10" Or lstr_tipopago = "11" Then
        MsgBox "No se Puede Anular El Documentos " + Chr(13) + _
               "Documento es Generado", vbExclamation, "Precaucion"
        Exit Sub
End If


If MsgBox("Esta seguro de Anular el siguiente Documento? " + _
        Chr(13) + lstr_descrdoc + " No. " + Str(ldbo_nro), _
        vbQuestion + vbYesNo, "Atencion") = vbYes Then
        
        'VERIFICAR QUE NO TENGA NOTAS DE CREDITO NI NOTAS DE DEBITO
        If mobj_cventasgen.existereferencias(lstr_tipodoc, ldbo_nro, GstrSiteProce) Then
            MsgBox " No se Puede Anular el Documento" + Chr(13) + "Tiene Referencias", vbExclamation, "Atencion"
            Exit Sub
        End If
        Screen.MousePointer = 11
        ERROR = mobj_cventasgen.anularventa(lstr_tipodoc, ldbo_nro, _
        GstrSiteProce, lstr_status, lstr_tipopago, lstr_codcliente, ldou_montopen, ldou_montousd)
        
        'Anadido por: Jorge Illescas para elimiar el numero de Guia(vale) ingresado a una
        'venta credito (Factura Credito) **************************************************
        'Si se trata de Ticket Guia (FACTURA CREDITO) - (TIPO DOC.: 12 Y TIPO PAGO: 06)....
        'se debe eliminar tambien su registro correspondiente en OP_BONUS
        If Trim(lstr_tipodoc) = "12" Or Trim(lstr_tipopago) = "06" Then
            If VerifCantGuiasFC(ldbo_nro) <> 0 Then 'una sola guia encontrado
                If ElimNumGuiaFacC(Trim(lstr_tipodoc), ldbo_nro, Trim(lstr_codcliente), _
                                                Trim(GstrSiteProce), NumBonus) = True Then
                   MsgBox "Se ha elminado guia correctamente.", vbInformation, "Advertencia"
                Else
                   MsgBox "Imposible eliminar guia(s) de factuta credito.", vbCritical, "Advertencia"
                End If
            Else
                MsgBox "Existe mas de un numero de guia registrado en Factura Credito.", vbExclamation, "Advertencia"
            End If
        End If

        Screen.MousePointer = 0
        Select Case ERROR
            Case 0
                MsgBox "Documento Anulado", vbExclamation, "Precaucion"
            Case 1
                MsgBox "Error Anulando Documento", vbExclamation, "Precaucion"
            Case 2
                MsgBox "Documento ya esta anulado", vbExclamation, "Precaucion"
            Case 3
                MsgBox "Documento Tiene pagos Efectuados", vbExclamation, "Precaucion"
            Case 4
                MsgBox "Documento Tiene una nota de credito o debito asociado", vbExclamation, "Precaucion"
        End Select
     Screen.MousePointer = 11
     Call FormatoGrillacab
     Screen.MousePointer = 0
     
     txt_NBRDOCUMENT.Text = ""
     txt_NBRDOCUMENT.SetFocus
Else
    Screen.MousePointer = 0
    Exit Sub
End If

End Sub
Sub cierraobjetos()
    
    Set mobj_cventasgen = Nothing
    Set MOBJ_CVENTASCSTORE = Nothing
    Set RS_TEMP = Nothing
    Set MobjMovimientos = Nothing
    
End Sub
