VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
Begin VB.Form frmOperacionParalelaConsulta 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Operaciones Paralelas"
   ClientHeight    =   7410
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   9225
   BeginProperty Font 
      Name            =   "Tahoma"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   7410
   ScaleWidth      =   9225
   StartUpPosition =   1  'CenterOwner
   Begin VB.CommandButton cmdSalir 
      Caption         =   "&Salir"
      Height          =   375
      Left            =   3960
      TabIndex        =   9
      Top             =   6930
      Width           =   1215
   End
   Begin VB.CommandButton cmdBuscar 
      Caption         =   "&Buscar"
      Height          =   375
      Left            =   7905
      TabIndex        =   4
      Top             =   105
      Width           =   1215
   End
   Begin MSComCtl2.DTPicker DTDesde 
      Height          =   330
      Left            =   1755
      TabIndex        =   2
      Top             =   555
      Width           =   1290
      _ExtentX        =   2275
      _ExtentY        =   582
      _Version        =   393216
      Format          =   50593793
      CurrentDate     =   38764
   End
   Begin VB.Frame Frame2 
      Caption         =   " Productos "
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   2835
      Left            =   225
      TabIndex        =   7
      Top             =   3960
      Width           =   8880
      Begin MSComctlLib.ListView lvwProducto 
         Height          =   2475
         Left            =   105
         TabIndex        =   8
         Top             =   240
         Width           =   8655
         _ExtentX        =   15266
         _ExtentY        =   4366
         View            =   3
         LabelEdit       =   1
         LabelWrap       =   -1  'True
         HideSelection   =   0   'False
         FullRowSelect   =   -1  'True
         _Version        =   393217
         ForeColor       =   -2147483640
         BackColor       =   -2147483643
         BorderStyle     =   1
         Appearance      =   1
         NumItems        =   0
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   " Operación "
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   2835
      Left            =   225
      TabIndex        =   5
      Top             =   1065
      Width           =   8880
      Begin MSComctlLib.ListView lvwOperacion 
         Height          =   2475
         Left            =   105
         TabIndex        =   6
         Top             =   255
         Width           =   8655
         _ExtentX        =   15266
         _ExtentY        =   4366
         View            =   3
         LabelEdit       =   1
         LabelWrap       =   -1  'True
         HideSelection   =   0   'False
         FullRowSelect   =   -1  'True
         _Version        =   393217
         ForeColor       =   -2147483640
         BackColor       =   -2147483643
         BorderStyle     =   1
         Appearance      =   1
         NumItems        =   0
      End
   End
   Begin VB.ComboBox cboEstado 
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   315
      Left            =   5175
      Style           =   2  'Dropdown List
      TabIndex        =   1
      Top             =   135
      Width           =   1860
   End
   Begin VB.ComboBox cboTipoVenta 
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   315
      Left            =   1755
      Style           =   2  'Dropdown List
      TabIndex        =   0
      Top             =   135
      Width           =   2355
   End
   Begin MSComCtl2.DTPicker DTHasta 
      Height          =   330
      Left            =   3270
      TabIndex        =   3
      Top             =   555
      Width           =   1290
      _ExtentX        =   2275
      _ExtentY        =   582
      _Version        =   393216
      Format          =   50593793
      CurrentDate     =   38764
   End
   Begin VB.Label Label4 
      AutoSize        =   -1  'True
      Caption         =   "-"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   14.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   345
      Left            =   3090
      TabIndex        =   13
      Top             =   540
      Width           =   120
   End
   Begin VB.Label Label3 
      AutoSize        =   -1  'True
      Caption         =   "Fechas:"
      Height          =   195
      Left            =   1020
      TabIndex        =   12
      Top             =   600
      Width           =   570
   End
   Begin VB.Label Label2 
      AutoSize        =   -1  'True
      Caption         =   "Estado:"
      Height          =   195
      Left            =   4500
      TabIndex        =   11
      Top             =   195
      Width           =   555
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "Tipo de Operación:"
      Height          =   195
      Left            =   225
      TabIndex        =   10
      Top             =   195
      Width           =   1365
   End
End
Attribute VB_Name = "frmOperacionParalelaConsulta"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Dim iTipoVenta As Integer, iEstado As Integer

Public Sub inicio()
  'Llena el combo de Tipo de Venta
  cboTipoVenta.Clear
  cboTipoVenta.AddItem "-->", 0
  cboTipoVenta.AddItem "O/C", 1
  cboTipoVenta.AddItem "N/C", 2
  cboTipoVenta.AddItem "PADE", 3
  cboTipoVenta.AddItem "PADV", 4
  cboTipoVenta.AddItem "LIQPAD", 5
  
  cboEstado.Clear
  cboEstado.AddItem "-->", 0
  cboEstado.AddItem "Vigente", 1
  cboEstado.AddItem "Liquidado", 2
  cboEstado.AddItem "Anulado", 3
  
  ConfiguraColumnas
  
  DTDesde.Value = Now() - 7
  DTHasta.Value = Now()
End Sub

Private Sub cboEstado_Click()
  Select Case cboEstado.ListIndex
    Case 1
      iEstado = 1
    Case 2
      iEstado = 2
    Case 3
      iEstado = 0
    Case Else
      iEstado = 9
  End Select
End Sub

Private Sub RecuperaOperacion()
  Dim sSQL As String
  Dim oRs As ADODB.Recordset
  Dim sDesde As String, sHasta As String, sTipoVenta As String, sEstado As String
  Dim itm As ListItem
  
  lvwOperacion.ListItems.Clear
  
  sDesde = Format(DTDesde.Value, "YYYY.MM.DD")
  sHasta = Format(DTHasta.Value, "YYYY.MM.DD")
  
  sSQL = " SELECT * FROM OperacionParalela WHERE 1 = 1"
  If iTipoVenta <> 0 Then sSQL = sSQL & " AND cOperTipo = " & CStr(iTipoVenta)
  If iEstado <> 9 Then sSQL = sSQL & " AND cEstado = '" & CStr(iEstado) & "'"
  sSQL = sSQL & " AND FORMAT(dOperFech, 'YYYY.MM.DD') >= '" & sDesde & "'" & _
                " AND FORMAT(dOperFech, 'YYYY.MM.DD') <= '" & sHasta & "'"

  'sSQL = " SELECT * FROM OperacionParalela WHERE cOperTipo = $"
  'sSQL = VBsprintf(sSQL, CStr(iTipoVenta))
  
  'cOperCode, cOperTipo, dOperFech, nTarjNumb, nMoneda, nMontoSoles,
'nMontoDolares, nEfectivoSoles, sGlosa, nVueltoSoles, cEstado, cCajaCodi,
'cFlagSincronizacion, cTurnoCodi, cUserDesc, cOperCodeRela, cOperCodeAnul
'FROM OperacionParalela;

  If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, oRs) Then GoTo LineaError
  
  Do While Not oRs.EOF
    Set itm = lvwOperacion.ListItems.Add(, , CStr(LeerCampo(oRs("cOperCode"))))
    Select Case LeerCampo(oRs("cOperTipo"))
      Case 20
        sTipoVenta = "O/C"
      Case 21
        sTipoVenta = "N/C"
      Case 22
        sTipoVenta = "PADE"
      Case 23
        sTipoVenta = "PADV"
      Case 24
        sTipoVenta = "LIQPAD"
      Case Else
        sTipoVenta = ""
    End Select
    
    Select Case LeerCampo(oRs("cEstado"))
      Case "1"
        sEstado = "VIGT"
      Case "2"
        sEstado = "LIQU"
      Case "3"
        sEstado = "ANUL"
      Case Else
        sEstado = ""
    End Select
        
    itm.SubItems(1) = sTipoVenta
    itm.SubItems(2) = Format(LeerCampo(oRs("dOperFech")), "dd/mm/yyyy hh:mm:ss")
    itm.SubItems(3) = LeerCampo(oRs("nTarjNumb"))
    itm.SubItems(4) = LeerCampo(oRs("cDocSerie")) + "-" + CStr(val("0" & oRs!cDocCodigo))
    itm.SubItems(5) = LeerCampo(oRs("sGlosa"))
    itm.SubItems(6) = Format(LeerCampo(oRs("nMontoSoles")), "###,###,##0.00")
    itm.SubItems(7) = Format(LeerCampo(oRs("nEfectivoSoles")), "###,###,##0.00")
    itm.SubItems(8) = Format(LeerCampo(oRs("nVueltoSoles")), "###,###,##0.00")
    itm.SubItems(9) = sEstado
    itm.SubItems(10) = LeerCampo(oRs("cCajaCodi"))
    itm.SubItems(11) = LeerCampo(oRs("cFlagSincronizacion"))
    itm.SubItems(12) = LeerCampo(oRs("cTurnoCodi"))
    itm.SubItems(13) = LeerCampo(oRs("cUserDesc"))
    itm.SubItems(14) = LeerCampo(oRs("cOperCodeRela"))
    itm.SubItems(15) = LeerCampo(oRs("cOperCodeAnul"))
    oRs.MoveNext
  Loop
  
  lvwOperacion.SetFocus
  
  RecuperaProducto
  
LineaError:
End Sub

Private Sub RecuperaProducto()
  Dim sSQL As String
  Dim oRs As ADODB.Recordset
  Dim itm As ListItem
  Dim sOperCode As String
  Dim cFlagServicio As Integer
  Dim cProdEstd As Integer
  
  If lvwOperacion.ListItems.Count < 1 Then Exit Sub
  
  sOperCode = lvwOperacion.SelectedItem.Text
  
  lvwProducto.ListItems.Clear
  
  sSQL = " SELECT OPP.cAlmaCode, OPP.cProdCode, P.cCodCatalogo, P.sProdDesc, P.sProdDescCrta," & _
         " OPP.nProdCant, OPP.nProdPrecUnit, OPP.nDscto, OPP.nServicio, P.cProdEstd," & _
         " P.cProdFlagFicha, P.cProdFichaCant, P.cProdFlagCanje, P.cProdFlagControl," & _
         " P.cFlagCanje, P.nPuntos, P.cFlagServicio, P.cUndSalida, UM.vDscUndMd" & _
         " FROM (OperacionParalelaProducto OPP LEFT JOIN Producto P" & _
         " ON (OPP.cProdCode = P.cProdCode) AND (OPP.cAlmaCode = P.cAlmaCode))" & _
         " LEFT JOIN UnidadMedida UM ON P.cUndSalida = UM.cUndMedid" & _
         " WHERE OPP.cOperCode = " & sOperCode
  
  If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, oRs) Then GoTo LineaError
  
  Do While Not oRs.EOF
    
    If LeerCampo(oRs("cFlagServicio")) = "" Then
        cFlagServicio = 0
    Else
        cFlagServicio = CInt(LeerCampo(oRs("cFlagServicio")))
    End If
    
    If LeerCampo(oRs("cProdEstd")) = "" Then
        cProdEstd = 0
    Else
        cProdEstd = CInt(LeerCampo(oRs("cProdEstd")))
    End If
    
    Set itm = lvwProducto.ListItems.Add(, , CStr(LeerCampo(oRs("cAlmaCode"))))
    itm.SubItems(1) = LeerCampo(oRs("cProdcode"))
    itm.SubItems(2) = LeerCampo(oRs("cCodCatalogo"))
    itm.SubItems(3) = LeerCampo(oRs("sProdDesc"))
    itm.SubItems(4) = LeerCampo(oRs("sProdDescCrta"))
    itm.SubItems(5) = Format(LeerCampo(oRs("nProdCant")), "###,###,##0.00")
    itm.SubItems(6) = Format(LeerCampo(oRs("nProdPrecUnit")), "###,###,##0.00")
    itm.SubItems(7) = Format(LeerCampo(oRs("nDscto")), "###,###,##0.00")
    itm.SubItems(8) = Format(LeerCampo(oRs("nServicio")), "###,###,##0.00")
    itm.SubItems(9) = IIf(oRs("cFlagCanje") = 0, "NO", IIf(oRs("cFlagCanje") = 1, "VNTA", "PTOS"))
    itm.SubItems(10) = LeerCampo(oRs("nPuntos"))
    itm.SubItems(11) = IIf(cFlagServicio = 1, "SI", "NO")
    itm.SubItems(12) = LeerCampo(oRs("vDscUndMd"))
    itm.SubItems(13) = IIf(cProdEstd = 1, "Activo", "Inactivo")
    oRs.MoveNext
  Loop
LineaError:
End Sub

Private Sub ConfiguraColumnas()
    
  Dim i As Integer, x As Integer
  Dim clmX As ColumnHeader
  Dim aColumnTitle() As String
  Dim aColumnWidth() As Single
  Dim aColumnAlign() As Integer
     
  ReDim aColumnTitle(16) As String
  ReDim aColumnWidth(16) As Single
  ReDim aColumnAlign(16) As Integer
    
  aColumnTitle(0) = "TX"
  aColumnTitle(1) = "Tipo"
  aColumnTitle(2) = "Fecha"
  aColumnTitle(3) = "Tarjeta"
  aColumnTitle(4) = "Documento"
  aColumnTitle(5) = "Glosa"
  aColumnTitle(6) = "(S/.)"
  aColumnTitle(7) = "Efectivo"
  aColumnTitle(8) = "Vuelto"
  aColumnTitle(9) = "Estado"
  aColumnTitle(10) = "Caja"
  aColumnTitle(11) = "Sinc."
  aColumnTitle(12) = "Turno"
  aColumnTitle(13) = "Usuario"
  aColumnTitle(14) = "TXRelac."
  aColumnTitle(15) = "TXAnul."
    
  aColumnWidth(0) = 0.05
  aColumnWidth(1) = 0.1
  aColumnWidth(2) = 0.15
  aColumnWidth(3) = 0.15
  aColumnWidth(4) = 0.15
  aColumnWidth(5) = 0.2
  aColumnWidth(6) = 0.1
  aColumnWidth(7) = 0.1
  aColumnWidth(8) = 0.1
  aColumnWidth(9) = 0.1
  aColumnWidth(10) = 0.1
  aColumnWidth(11) = 0.05
  aColumnWidth(12) = 0.1
  aColumnWidth(13) = 0.1
  aColumnWidth(14) = 0.05
  aColumnWidth(15) = 0.05

        
  aColumnAlign(0) = lvwColumnLeft
  aColumnAlign(1) = lvwColumnCenter
  aColumnAlign(2) = lvwColumnCenter
  aColumnAlign(3) = lvwColumnLeft
  aColumnAlign(4) = lvwColumnLeft
  aColumnAlign(6) = lvwColumnRight
  aColumnAlign(7) = lvwColumnRight
  aColumnAlign(8) = lvwColumnRight
  aColumnAlign(9) = lvwColumnCenter
        
  For i = 0 To (UBound(aColumnTitle) - 1)
    Set clmX = lvwOperacion.ColumnHeaders.Add(, , aColumnTitle(i), _
                                            lvwOperacion.Width * aColumnWidth(i), _
                                            aColumnAlign(i))
  Next
  '----------------------
  'Producto
  
  ReDim aColumnTitle(14) As String
  ReDim aColumnWidth(14) As Single
  ReDim aColumnAlign(14) As Integer
    
  aColumnTitle(0) = "Alm."
  aColumnTitle(1) = "Cod."
  aColumnTitle(2) = "Cod. Catalogo"
  aColumnTitle(3) = "Descripción"
  aColumnTitle(4) = "Abrev."
  aColumnTitle(5) = "Cant."
  aColumnTitle(6) = "PUnit(S/.)"
  aColumnTitle(7) = "Dscto(%)"
  aColumnTitle(8) = "Serv.(%)"
  aColumnTitle(9) = "TipoCanje"
  aColumnTitle(10) = "Puntos"
  aColumnTitle(11) = "Servicio"
  aColumnTitle(12) = "UM"
  aColumnTitle(13) = "Estado"
      
  aColumnWidth(0) = 0.05
  aColumnWidth(1) = 0.05
  aColumnWidth(2) = 0.12
  aColumnWidth(3) = 0.2
  aColumnWidth(4) = 0.1
  aColumnWidth(5) = 0.1
  aColumnWidth(6) = 0.1
  aColumnWidth(7) = 0.1
  aColumnWidth(8) = 0.1
  aColumnWidth(9) = 0.1
  aColumnWidth(10) = 0.1
  aColumnWidth(11) = 0.05
  aColumnWidth(12) = 0.1
  aColumnWidth(13) = 0.1
        
  aColumnAlign(0) = lvwColumnLeft
  aColumnAlign(1) = lvwColumnCenter
  aColumnAlign(2) = lvwColumnLeft
  aColumnAlign(4) = lvwColumnRight
  aColumnAlign(5) = lvwColumnRight
  aColumnAlign(6) = lvwColumnRight
  aColumnAlign(8) = lvwColumnCenter
        
  For i = 0 To (UBound(aColumnTitle) - 1)
    Set clmX = lvwProducto.ColumnHeaders.Add(, , aColumnTitle(i), _
                                            lvwProducto.Width * aColumnWidth(i), _
                                            aColumnAlign(i))
  Next
End Sub

Private Sub cboTipoVenta_Click()
  Select Case cboTipoVenta.ListIndex
    Case 1
      iTipoVenta = 20
    Case 2
      iTipoVenta = 21
    Case 3
      iTipoVenta = 22
    Case 4
      iTipoVenta = 23
    Case 5
      iTipoVenta = 24
    Case Else
      iTipoVenta = 0
  End Select

End Sub

Private Sub cmdBuscar_Click()
  RecuperaOperacion
End Sub

Private Sub cmdsalir_Click()
  Unload Me
End Sub

Private Sub lvwOperacion_ItemClick(ByVal Item As MSComctlLib.ListItem)
  RecuperaProducto
End Sub
