-
Notifications
You must be signed in to change notification settings - Fork 0
/
dashboard.php
259 lines (240 loc) · 9.2 KB
/
dashboard.php
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<?php
session_start();
if (!isset($_SESSION['activa'])) header('location: index.php');
include 'templates/head.php';
$versiones = getRegistros('SELECT * FROM versiones ORDER BY id DESC');
$data = getAPI(
'https://s3.amazonaws.com/dolartoday/data.json',
__DIR__ . '/storage/dolarToday.json'
);
$dolarFecha = $data['_timestamp']['fecha'];
$dolarT = $data['USD']['transferencia'];
$dolarE = $data['USD']['efectivo'];
$data = getAPI(
'https://api.exchangedyn.com/markets/quotes/usdves/bcv',
__DIR__ . '/storage/bcv.json'
);
$dolarBCV = round($data['sources']['BCV']['quote'], 2);
$sql = <<<SQL
SELECT fecha, foto, nombre, usuario FROM log
INNER JOIN usuarios ON usuario_id=id
WHERE negocio_id={$_SESSION['negocioID']}
GROUP BY usuario_id ORDER BY fecha DESC LIMIT 3
SQL;
$recientes = getRegistros($sql);
$sql = <<<SQL
SELECT id FROM ventas WHERE negocio_id={$_SESSION['negocioID']}
SQL;
$cantidadVentas = count(getRegistros($sql));
/*---------- PRODUCTOS MÁS VENDIDOS ----------*/
$sql = <<<SQL
SELECT v.fecha, v.producto_id, i.producto, v.unidades FROM ventas v
INNER JOIN inventario i ON v.producto_id=i.id
WHERE v.negocio_id={$_SESSION['negocioID']}
SQL;
$ventas = getRegistros($sql);
$ventas = filtrarFecha('semanal', $ventas);
$ventasCombinadas = [];
foreach ($ventas as $venta):
$id = $venta['producto_id'];
if (count($ventasCombinadas) > 2) break;
if (!array_key_exists($id, $ventasCombinadas))
$ventasCombinadas[$id] = $venta;
else $ventasCombinadas[$id]['unidades'] += $venta['unidades'];
endforeach;
if ($ventasCombinadas && $_SESSION['cargo'] === 'a'):
$nombresProductos = [];
$cantidadProductos = [];
foreach ($ventasCombinadas as $venta):
$nombresProductos[] = $venta['producto'];
$cantidadProductos[] = $venta['unidades'];
endforeach;
$cantidadProductos[] = 0;
$nombresProductos = json_encode($nombresProductos, JSON_INVALID_UTF8_IGNORE);
$cantidadProductos = json_encode($cantidadProductos, JSON_INVALID_UTF8_IGNORE);
$script .= <<<HTML
<script>
const xValues = $nombresProductos
const yValues = $cantidadProductos
const barColors = ['red', 'green', 'yellow', 'black', 'blue']
new Chart('productosMasVendidos', {
type: 'bar',
data: {
labels: xValues,
datasets: [{
backgroundColor: barColors,
data: yValues
}]
},
options: {
legend: {display: false},
scales: {
y: {
beginAtZero: true
}
}
}
})
</script>
HTML;
endif;
$sql = <<<SQL
SELECT id FROM inventario WHERE negocio_id={$_SESSION['negocioID']}
SQL;
$cantidadProductos = consulta($sql);
?>
<main class="w3-container w3-light-gray">
<?=LOADER?>
<h1 class="w3-xlarge w3-padding-16">
<i class="icon-dashboard"></i> Administración
</h1>
<!--=============================
= WIDGETS =
==============================-->
<section class="w3-row-padding w3-margin-bottom">
<?php if($_SESSION['cargo'] === 'a'): ?>
<div class="w3-col s6 m3 w3-dropdown-hover w3-transparent">
<a href="views/ventas.php" role="navegacion" class="w3-hover-opacity">
<div class="w3-container w3-red w3-padding-16">
<i class="icon-list-alt w3-xxxlarge w3-left"></i>
<span class="w3-right w3-xlarge"><?=$cantidadVentas?></span>
<div class="w3-clear"></div>
<span class="w3-large w3-block w3-margin-top">Ventas</span>
</div>
</a>
<?=generarTooltip('Ver Ventas')?>
</div>
<div class="w3-col s6 m3 w3-dropdown-hover w3-transparent">
<a href="views/compras.php" role="navegacion" class="w3-hover-opacity">
<div class="w3-container w3-blue w3-padding-16">
<i class="icon-handshake-o w3-xxxlarge w3-left"></i>
<span class="w3-right w3-xlarge"><?=contarRegistros('compras')?></span>
<div class="w3-clear"></div>
<span class="w3-large w3-block w3-margin-top">Compras</span>
</div>
</a>
<?=generarTooltip('Ver Compras')?>
</div>
<?php endif ?>
<div class="w3-col <?=$_SESSION['cargo'] === 'a' ? 's6 m3' : 's6'?> w3-dropdown-hover w3-transparent">
<a href="views/inventario.php" role="navegacion" class="w3-hover-opacity">
<div class="w3-container w3-teal w3-padding-16">
<i class="icon-product-hunt w3-xxxlarge w3-left"></i>
<span class="w3-right w3-xlarge"><?=$cantidadProductos?></span>
<div class="w3-clear"></div>
<span class="w3-large w3-block w3-margin-top">Productos</span>
</div>
</a>
<?=generarTooltip('Ver Inventario')?>
</div>
<div class="w3-col <?=$_SESSION['cargo'] === 'a' ? 's6 m3' : 's6'?> w3-dropdown-hover w3-transparent">
<a href="<?=$_SESSION['cargo'] === 'a' ? 'views/usuarios.php' : 'views/clientes.php'?>" role="navegacion" class="w3-hover-opacity">
<div class="w3-container w3-orange w3-text-white w3-padding-16">
<i class="icon-users w3-xxxlarge w3-left"></i>
<span class="w3-right w3-xlarge">
<?=$_SESSION['cargo'] === 'a' ? contarRegistros('usuarios') - 1 : contarRegistros('clientes') - 1?>
</span>
<div class="w3-clear"></div>
<span class="w3-large w3-block w3-margin-top">
<?=$_SESSION['cargo'] === 'a' ? 'Usuarios' : 'Clientes'?>
</span>
</div>
</a>
<?=generarTooltip($_SESSION['cargo'] === 'a' ? 'Ver Usuarios' : 'Ver Clientes')?>
</div>
</section>
<!--=============================
= MONEDAS =
==============================-->
<div class="w3-row">
<?php include 'templates/monedas.php' ?>
<section class="w3-half w3-container w3-padding-24 w3-animate-opacity">
<h2 class="w3-large w3-text-green">DOLAR TODAY</h2>
<table class="w3-table w3-bordered w3-border w3-hoverable w3-pale-green">
<tr>
<td>Fecha</td>
<td colspan="3">
<b><i class="w3-small"><?=$dolarFecha?></i></b>
</td>
</tr>
<tr>
<td>DÓLAR (Bs.)</td>
<td><b><i class="w3-small">BCV </i><?=$dolarBCV?></b></td>
<td><b><i class="w3-small">Transferencia </i><?=$dolarT?></b></td>
<td><b><i class="w3-small">Efectivo </i><?=$dolarE?></b></td>
</tr>
</table>
</section>
</div>
<?php if($_SESSION['cargo'] === 'a' && $recientes): ?>
<section class="w3-row w3-container w3-border-bottom w3-padding-24">
<!--========================================
= USUARIOS RECIENTES =
=========================================-->
<ul class="w3-col s12 m5 w3-ul w3-card-4 w3-white">
<div class="w3-dropdown-hover w3-transparent w3-block">
<a href="views/log.php" role="navegacion" class="w3-button w3-block w3-border-bottom w3-light-gray w3-text-indigo w3-xlarge">
Usuarios recientes
</a>
<?=generarTooltip('Ver Registro de Sesiones')?>
</div>
<?php foreach($recientes as $usuario): ?>
<li class="w3-padding-16">
<img src="<?=!empty($usuario['foto']) ? "assets/images/perfil/{$usuario['foto']}" : "images/avatar2.png"?>" class="w3-circle w3-margin-right" style="width: 50px">
<span class="w3-large"><?=$usuario['nombre']?></span>
</li>
<?php endforeach ?>
</ul>
<div class="w3-col s0 m1"> </div>
<!--============================================
= PRODUCTOS MÁS VENDIDOS =
=============================================-->
<?php
$tooltipProductosMasVendidos = generarTooltip('Ver Finanzas');
if ($ventasCombinadas)
echo <<<HTML
<div class="w3-col s12 m6 w3-ul w3-card-4 w3-white">
<div class="w3-dropdown-hover w3-transparent w3-block">
<a href="views/finanzas.php" role="navegacion" class="w3-button w3-block w3-border-bottom w3-light-gray w3-text-indigo w3-xlarge">
Productos más Vendidos
</a>
$tooltipProductosMasVendidos
</div>
<canvas id="productosMasVendidos"></canvas>
</div>
HTML;
?>
</section>
<?php endif ?>
<!--===================================
= PIE DE PÁGINA =
====================================-->
<footer class="w3-dark-grey w3-container" style="margin: 0 -16px">
<div class="w3-row">
<div class="w3-container w3-third">
<h2 class="w3-xlarge oswald w3-bottombar w3-border-orange">Sistema</h2>
<button onclick="modal(this)" data-target="#acercaDe" class="w3-block w3-left-align w3-button w3-transparent">Acerca De</button>
<button onclick="modal(this)" data-target="#registroCambios" class="w3-block w3-left-align w3-button w3-transparent">Registro de cambios</button>
<button onclick="modal(this)" data-target="#soporte" class="w3-block w3-left-align w3-button w3-transparent">Soporte Técnico</button>
<button onclick="modal(this)" data-target="#manual" class="w3-hide w3-block w3-left-align w3-button w3-transparent">Manual de Usuario</button>
</div>
</div>
<p class="w3-center w3-large">
Powered by
<a href="https://www.w3schools.com/w3css/default.asp" target="_blank">
w3.css
</a>
| <i class="icon-copyright"></i> UPTM <?=date('Y')?>
</p>
</footer>
<?php
$mostrarChangelog = true;
$mostrarSoporteTecnico = true;
$mostrarManual = true;
include 'templates/registroCambios.php';
include 'templates/soporteTecnico.php';
include 'templates/manual.php';
?>
<footer id="botones"><?=BOTONES['NUEVA_VENTA']?></footer>
</main>
<?php include 'templates/footer.php';