-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathreporte_ventas.php
More file actions
134 lines (126 loc) · 5.3 KB
/
reporte_ventas.php
File metadata and controls
134 lines (126 loc) · 5.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
include_once "encabezado.php";
include_once "navbar.php";
include_once "funciones.php";
session_start();
if(empty($_SESSION['usuario'])) header("location: login.php");
if(isset($_POST['buscar'])){
if(empty($_POST['inicio']) || empty($_POST['fin'])) header("location: reporte_ventas.php");
}
if(isset($_POST['buscarPorUsuario'])){
if(empty($_POST['idUsuario'])) header("location: reporte_ventas.php");
}
if(isset($_POST['buscarPorCliente'])){
if(empty($_POST['idCliente'])) header("location: reporte_ventas.php");
}
$fechaInicio = (isset($_POST['inicio'])) ? $_POST['inicio'] : null;
$fechaFin = (isset($_POST['fin'])) ? $_POST['fin'] : null;
$usuario = (isset($_POST['idUsuario'])) ? $_POST['idUsuario'] : null;
$cliente = (isset($_POST['idCliente'])) ? $_POST['idCliente'] : null;
$ventas = obtenerVentas($fechaInicio, $fechaFin, $cliente, $usuario);
$cartas = [
["titulo" => "No. ventas", "icono" => "fa fa-shopping-cart", "total" => count($ventas), "color" => "#A71D45"],
["titulo" => "Total ventas", "icono" => "fa fa-money-bill", "total" => "$".calcularTotalVentas($ventas), "color" => "#2A8D22"],
["titulo" => "Productos vendidos", "icono" => "fa fa-box", "total" =>calcularProductosVendidos($ventas), "color" => "#223D8D"],
["titulo" => "Ganancia", "icono" => "fa fa-wallet", "total" => "$". obtenerGananciaVentas($ventas), "color" => "#D55929"],
];
$clientes = obtenerClientes();
$usuarios = obtenerUsuarios();
?>
<div class="container">
<h2>Reporte de ventas :
<?php
if(empty($fechaInicio)) echo HOY;
if(isset($fechaInicio) && isset($fechaFin)) echo $fechaInicio ." al ". $fechaFin;
?>
</h2>
<form class="row mb-3" method="post">
<div class="col-5">
<label for="inicio" class="form-label">Fecha busqueda inicial</label>
<input type="date" name="inicio" class="form-control" id="inicio" >
</div>
<div class="col-5">
<label for="fin" class="form-label">Fecha busqueda final</label>
<input type="date" name="fin" class="form-control" id="fin" >
</div>
<div class="col">
<input type="submit" name="buscar" value="Buscar" class="btn btn-primary mt-4">
</div>
</form>
<div class="row mb-2">
<div class="col">
<form action="" method="post" class="row">
<div class="col-6">
<select class="form-select" aria-label="Default select example" name="idUsuario">
<option selected value="">Selecciona un usuario</option>
<?php foreach($usuarios as $usuario) {?>
<option value="<?= $usuario->id?>"><?= $usuario->usuario?></option>
<?php }?>
</select>
</div>
<div class="col-1">
<input type="submit" name="buscarPorUsuario" value="Buscar por usuario" class="btn btn-secondary">
</div>
</form>
</div>
<div class="col">
<form action="" method="post" class="row">
<div class="col-6">
<select class="form-select" aria-label="Default select example" name="idCliente">
<option selected value="">Selecciona un cliente</option>
<?php foreach($clientes as $cliente) {?>
<option value="<?= $cliente->id?>"><?= $cliente->nombre?></option>
<?php }?>
</select>
</div>
<div class="col-1">
<input type="submit" name="buscarPorCliente" value="Buscar por cliente" class="btn btn-secondary">
</div>
</form>
</div>
</div>
<?php include_once "cartas_totales.php"?>
<?php if(count($ventas) > 0){?>
<table class="table">
<thead>
<tr>
<th>#</th>
<th>Fecha</th>
<th>Cliente</th>
<th>Total</th>
<th>Usuario</th>
<th>Productos</th>
</tr>
</thead>
<tbody>
<?php foreach($ventas as $venta) {?>
<tr>
<td><?= $venta->id;?></td>
<td><?= $venta->fecha;?></td>
<td><?= $venta->cliente;?></td>
<td>$<?= $venta->total;?></td>
<td><?= $venta->usuario;?></td>
<td>
<table class="table">
<?php foreach($venta->productos as $producto) {?>
<tr>
<td><?= $producto->nombre;?></td>
<td><?= $producto->cantidad;?></td>
<td> X </td>
<td>$<?= $producto->precio ;?></td>
<th>$<?= $producto->cantidad * $producto->precio ;?></th>
</tr>
<?php }?>
</table>
</td>
</tr>
<?php }?>
</tbody>
</table>
<?php }?>
<?php if(count($ventas) < 1){?>
<div class="alert alert-warning mt-3" role="alert">
<h1>No se han encontrado ventas</h1>
</div>
<?php }?>
</div>