Option Explicit
Const n As Integer = 8
Private i As Integer
Private infoboleta As xrpt
Private Sub Prtrpt()
'On Error Resume Next
Set dbf = db.Execute("select enccomprobante.IdEncComprobante," & _
"clientes.Nombres," & _
"clientes.Paterno," & _
"clientes.Materno," & _
"enccomprobante.Fecha," & _
"enccomprobante.Subtotal," & _
"enccomprobante.IGV," & _
"enccomprobante.Total," & _
"enccomprobante.IdEmpleado " & _
"from EncComprobante inner join clientes " & _
"on enccomprobante.idcliente=clientes.idcliente ") ' & _
'"where enccomprobante.fecha between #" & CDate(Text1(0)) & "# and #" & CDate(Text1(1)) & "#")
With infoboleta
Call .agregar("A" & (n + i) & ":G" & (n + i), "Listado de comprobantes")
i = i + 1
Call .agregar("A" & n + i, "Codigo", True)
Call .agregar("b" & n + 1, "Cliente", True)
Call .agregar("c" & n + i, "Fecha", True)
Call .agregar("d" & n + i, "Empleado", True)
Call .agregar("e" & n + 1, "Subtotal", True)
Call .agregar("f" & n + i, "Total", True)
i = i + 1
Do Until (dbf.EOF)
If (CDate(dbf(4)) < CDate(Text1(1)) And CDate(dbf(4)) > CDate(Text1(0))) Then
Call .agregar("a" & n + i, dbf(0), True) 'codigo
Call .agregar("b" & n + i, dbf(1) & " " & dbf(2) & " " & dbf(3), True) 'cliente
Call .agregar("c" & n + i, dbf(4), True) 'fecha
'Call .agregar("d" & n + i, empleado(dbf(8)), True) 'empleado
Call .agregar("e" & n + i, dbf(5), True) 'subtotal
Call .agregar("f" & n + i, dbf(6), True) 'igv
Call .agregar("g" & n + i, dbf(7), True) 'total
i = i + 1
End If
dbf.MoveNext
Loop
End With
End Sub
Private Sub prtcf(ByVal x As String) 'imprimir frecuencia cliente
On Error GoTo bug
Set dbf = db.Execute("SELECT (IdCliente) AS clientes, COUNT(IdCliente) AS veces " & _
"From EncComprobante " & _
"where fecha between #" & CDate(Text1(0)) & "# and #" & CDate(Text1(1)) & "#" & _
" GROUP BY IdCliente " & _
"ORDER BY min(IdCliente) " & x)
i = i + 1
If (x = "desc") Then
Call infoboleta.agregar("a" & n + i, "El cliente más frecuente es: " & cliente(dbf("clientes")) & " con " & dbf("veces") & " compras")
Else
Call infoboleta.agregar("a" & n + i, "El cliente menos frecuente es: " & cliente(dbf("clientes")) & " con " & dbf("veces") & " compras")
End If
bug:
End Sub
Private Sub prtvd() 'impriomir ventas diarias
Set dbf = db.Execute("SELECT Fecha, SUM(Total) AS Expr1 " & _
"From EncComprobante " & _
"where fecha between #" & CDate(Text1(0)) & "# and #" & CDate(Text1(1)) & "# " & _
"GROUP BY Fecha " & _
"ORDER BY Fecha")
i = i + 1
With infoboleta
Call .agregar("a" & n + i & ":g" & n + i, "Ventas Diarias")
i = i + 1
Call .agregar("a" & n + i, "fecha", True)
Call .agregar("b" & n + i, "Total", True)
i = i + 1
Do Until dbf.EOF
Call .agregar("a" & n + i, dbf(0), True)
Call .agregar("b" & n + i, dbf(1), True)
i = i + 1
dbf.MoveNext
Loop
End With
End Sub
Private Sub prtpv(x As String)
Set dbf = db.Execute("SELECT Idproducto, SUM(Cantidad) AS total " & _
"From Kardex " & _
"WHERE (Motivo LIKE 'venta') " & _
"GROUP BY Idproducto " & _
"ORDER BY SUM(Cantidad)")
If (x = "desc") Then
x = " más "
Else
x = " menos "
End If
i = i + 1
Call infoboleta.agregar("a" & n + i, "El producto" & x & "vendido es: " & dbf(0) & " con una cantidad de: " & dbf(1) & " unidades")
End Sub
Private Sub prtkx()
Set dbf = db.Execute("select * from kardex")
Dim a As Integer
With infoboleta
i = i + 1
.neg = True
.agregar "a" & n + i & ":g" & n + i, "Kardex"
.agregar "a" & n + i, "Producto", True
.agregar "b" & n + i, "Cantidad", True
.agregar "c" & n + i, "Motivo", True
.agregar "d" & n + i, "Tipo de doc.", True
.agregar "e" & n + i, "N° Documento", True
.agregar "f" & n + i, "Fecha", True
i = i + 1
.neg = False
Do Until dbf.EOF
.agregar "a" & n + i, dbf(1), True
.agregar "b" & n + i, dbf(2), True
.agregar "c" & n + i, dbf(3), True
.agregar "d" & n + i, dbf(4), True
.agregar "e" & n + i, dbf(5), True
.agregar "f" & n + i, dbf(6), True
dbf.MoveNext
Loop
End With
End Sub
Private Sub prtp(x As String)
Set dbf = db.Execute("SELECT Productos.IdProveedor, COUNT(Productos.Idproducto) AS Expr1 " & _
"FROM Productos INNER JOIN " & _
"Proveedores ON Productos.IdProveedor = Proveedores.IdProveedor " & _
"GROUP BY Productos.IdProveedor " & _
"ORDER BY COUNT(Productos.Idproducto)" & n)
If (x = "desc") Then
x = " mejor "
Else:
x = " peor "
End If
i = i + 1
infoboleta.agregar "a" & n + i, "el" & x & "proveedor es:"
'aqui falta completar la oraci{on
End Sub
Private Sub Command1_Click()
'Listado de comprobantes.YA
'Cliente más frecuente.YA
'Cliente menos frecuente.YA
'Ventas diarias.YA
'Producto mas vendido.YA
'Producto menos vendido.YA
'Kardex.YA
'Mejor proveedor.YA
'Peor proveedor.YA
i = 0
Set infoboleta = New xrpt
infoboleta.nuevo_doc (App.Path + "\Reportes\general.xlt")
infoboleta.mostrar_doc = True
If (List1.Selected(0) = True) Then Call Prtrpt
If (List1.Selected(1) = True) Then Call prtcf("desc")
If (List1.Selected(2) = True) Then Call prtcf("asc")
If (List1.Selected(3) = True) Then Call prtvd
If (List1.Selected(4) = True) Then Call prtpv("desc")
If (List1.Selected(5) = True) Then Call prtpv("asc")
If (List1.Selected(6) = True) Then Call prtkx
If (List1.Selected(7) = True) Then Call prtp("desc")
If (List1.Selected(8) = True) Then Call prtp("asc")
Unload Me
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Function cliente(id As String) As String
On Error Resume Next
Dim cli As New ADODB.Recordset
Set cli = db.Execute("select nombres,paterno,materno from clientes where idcliente='" & id & "'")
cliente = cli(0) & " " & cli(1) & " " & cli(2)
End Function
Private Function empleado(id As String) As String
On Error Resume Next
Dim emp As New ADODB.Recordset
Set emp = db.Execute("select nombres,paterno,materno from personal where idempleado='" & id & "'")
empleado = emp
End Function
Private Sub Form_Load()
Text1(0) = Date
Text1(1) = Date
i = 0
End Sub