VERSION 5.00
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 
   Caption         =   "Buscar Transacciones (05.035.00)"
   ClientHeight    =   6300
   ClientLeft      =   165
   ClientTop       =   450
   ClientWidth     =   11610
   LinkTopic       =   "Form1"
   ScaleHeight     =   6300
   ScaleWidth      =   11610
   StartUpPosition =   3  'Windows Default
   Begin VB.TextBox txt_NBRDOCUMENT 
      Height          =   320
      Left            =   1980
      MaxLength       =   10
      TabIndex        =   2
      Top             =   900
      Width           =   1455
   End
   Begin MSComCtl2.DTPicker dtp_fechaini 
      Height          =   375
      Left            =   1980
      TabIndex        =   0
      Top             =   60
      Width           =   1395
      _ExtentX        =   2461
      _ExtentY        =   661
      _Version        =   393216
      CustomFormat    =   "dd/MM/yyyy"
      Format          =   60948483
      CurrentDate     =   37613
   End
   Begin VB.CommandButton CMB_BUSCAR 
      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            =   3660
      Picture         =   "fbuscardocumentos.frx":0000
      Style           =   1  'Graphical
      TabIndex        =   3
      Top             =   480
      Width           =   1395
   End
   Begin VB.CommandButton CMD_CANCELAR 
      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            =   10440
      Picture         =   "fbuscardocumentos.frx":030A
      Style           =   1  'Graphical
      TabIndex        =   7
      Top             =   5460
      Width           =   1155
   End
   Begin VB.CommandButton cmd_Mostrar 
      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            =   10440
      Picture         =   "fbuscardocumentos.frx":0614
      Style           =   1  'Graphical
      TabIndex        =   5
      Tag             =   "R ASDASD"
      Top             =   3660
      Width           =   1155
   End
   Begin VB.CommandButton cmd_eliminar 
      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            =   10440
      Picture         =   "fbuscardocumentos.frx":091E
      Style           =   1  'Graphical
      TabIndex        =   6
      Tag             =   "R ASDASD"
      Top             =   4560
      Width           =   1155
   End
   Begin MSDataGridLib.DataGrid DBCABEZERA 
      Height          =   2295
      Left            =   0
      TabIndex        =   4
      Top             =   1260
      Width           =   11535
      _ExtentX        =   20346
      _ExtentY        =   4048
      _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         =   "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          =   2655
      Left            =   0
      TabIndex        =   8
      Top             =   3600
      Width           =   10395
      _ExtentX        =   18336
      _ExtentY        =   4683
      _Version        =   393216
      AllowUpdate     =   0   'False
      Enabled         =   -1  'True
      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         =   "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            =   1980
      TabIndex        =   1
      Top             =   480
      Width           =   1395
      _ExtentX        =   2461
      _ExtentY        =   661
      _Version        =   393216
      CustomFormat    =   "dd/MM/yyyy"
      Format          =   60948483
      CurrentDate     =   37613
   End
   Begin VB.Label Label5 
      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          =   255
      Left            =   240
      TabIndex        =   12
      Top             =   960
      Width           =   1755
   End
   Begin VB.Label Label3 
      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          =   255
      Left            =   300
      TabIndex        =   11
      Top             =   540
      Width           =   1755
   End
   Begin VB.Label Label2 
      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          =   255
      Left            =   300
      TabIndex        =   10
      Top             =   120
      Width           =   1755
   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            =   7740
      TabIndex        =   9
      Top             =   960
      Width           =   3675
   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 RS_TEMP As ADODB.Recordset


Public Sub FormatoGrilladet()
DBDetalle.Columns(0).Caption = "Seq"
DBDetalle.Columns(0).Width = 380

DBDetalle.Columns(1).Caption = "Id.Producto"
DBDetalle.Columns(1).Width = 1200

DBDetalle.Columns(2).Caption = "Descripcion"
DBDetalle.Columns(2).Width = 3500

DBDetalle.Columns(3).Caption = "Precio"
DBDetalle.Columns(3).Width = 1200  'Precio
DBDetalle.Columns(3).Alignment = dbgRight
DBDetalle.Columns(3).NumberFormat = GMascara(GintDecPrecio)

DBDetalle.Columns(4).Caption = "%Impto"
DBDetalle.Columns(4).Width = 590
DBDetalle.Columns(4).Alignment = dbgRight
DBDetalle.Columns(4).NumberFormat = GMascara(GintDecPrecio)

DBDetalle.Columns(5).Caption = "Cantidad"
DBDetalle.Columns(5).Width = 920
DBDetalle.Columns(5).Alignment = dbgRight
DBDetalle.Columns(5).NumberFormat = GMascara(GintDecStock)

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"

End Sub

Private Sub CMB_BUSCAR_Click()
Call FormatoGrillacab
End Sub

Private Sub cmd_Cancelar_Click()
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
        Call anular_venta
    End If
End Sub
Private Sub DBCABEZERA_KeyDown(KeyCode As Integer, Shift As Integer)

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)
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()
dtp_fechaini.Value = Date
dtp_fechafin.Value = Date
Call FormatoGrillacab
dtp_fechaini.SetFocus
End Sub

Private Sub Form_Load()
Set mobj_cventasgen = New DB_OP_FACTURACION.C_VENTASGENERAL
Set MOBJ_CVENTASCSTORE = New DB_OP_FACTURACION.C_VENTASCSTORE

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)
Set DBCABEZERA.DataSource = RS_TEMP

DBCABEZERA.Columns(0).Width = 950      'Tipo Documento.
DBCABEZERA.Columns(1).Width = 1200      'numero
DBCABEZERA.Columns(2).Width = 1000      'Estado
DBCABEZERA.Columns(3).Width = 1850      'Forma pago
DBCABEZERA.Columns(4).Width = 1000      'Fecha
DBCABEZERA.Columns(5).Width = 1000      'Total
DBCABEZERA.Columns(5).Alignment = dbgRight
DBCABEZERA.Columns(5).NumberFormat = GMascara(GintDecPrecio)
DBCABEZERA.Columns(6).Width = 1200      'Idcliente
DBCABEZERA.Columns(7).Width = 2900      'cliente
DBCABEZERA.Columns(8).Visible = False   'site
DBCABEZERA.Columns(9).Visible = False   'site
DBCABEZERA.Columns(10).Visible = False   'site
DBCABEZERA.Columns(11).Visible = False   'site
DBCABEZERA.Columns(12).Visible = False   'site

If RS_TEMP.RecordCount > 0 Then
    Call DBCABEZERA_RowColChange(1, 1)
    
End If
End Sub
Public Sub borrar_venta()
'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

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

If Not RS_TEMP.EOF Or RS_TEMP.RecordCount > 0 Then
    ldbo_nro = RS_TEMP!nro
    lstr_tipodoc = RS_TEMP!DOCTYPEID
    lstr_descrdoc = RS_TEMP!Tipo_Doc
    If MsgBox("Esta Seguro de Eliminar el siguiente documento " + _
            Chr(13) + lstr_descrdoc + " No. " + Str(ldbo_nro), _
            vbYesNo, "Atencion") = vbYes Then
        
        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 Eliminado Documento", vbExclamation, "Precaucion"
            Case 3
                MsgBox "Documento Tiene pagos Efectuados", vbExclamation, "Precaucion"
        End Select
        
         Call FormatoGrillacab
    End If
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.SetFocus
End If
End Sub

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

End Sub

Public Sub anular_venta()
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

'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 MsgBox("Esta Seguro de Anular el siguiente documento " + _
        Chr(13) + lstr_descrdoc + " No. " + Str(ldbo_nro), _
        vbYesNo, "Atencion") = vbYes Then
        
        error = mobj_cventasgen.anularventa(lstr_tipodoc, ldbo_nro, _
        GstrSiteProce, lstr_status, lstr_tipopago, lstr_codcliente, ldou_montopen, ldou_montousd)
        
        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"
        End Select
        
     Call FormatoGrillacab
     
Else
    Exit Sub
End If

End Sub

