-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcatalogo-pedidos.php
346 lines (297 loc) · 18.1 KB
/
catalogo-pedidos.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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
<?php
require_once("control/validarusuario.php");
if (!isset($_SESSION['nombre_usuario'])) {
header("Location:login.php");
}
$usuario = $_SESSION["nombre_usuario"];
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Catalogo de Pedidos</title>
<!-- Google Web Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;600&family=Roboto:wght@500;700&display=swap" rel="stylesheet">
<!-- Icon Font Stylesheet -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.10.0/css/all.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css" rel="stylesheet">
<link href="img/favicon.ico" rel="icon">
<!-- Libraries Stylesheet -->
<link href="lib/owlcarousel/assets/owl.carousel.min.css" rel="stylesheet">
<link href="lib/tempusdominus/css/tempusdominus-bootstrap-4.min.css" rel="stylesheet" />
<!-- Customized Bootstrap Stylesheet -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Template Stylesheet -->
<link href="css/style.css" rel="stylesheet">
<link href="css/login.css" rel="stylesheet">
</head>
<body>
<div class="container-fluid position-relative d-flex p-0">
<?php
$usuario = $_SESSION['nombre_usuario'];
require_once('control/conexion.php');
$tipo = "SELECT tipo_usuario FROM Usuarios WHERE nombre_usuario='$usuario';";
$nivel = mysqli_query($conexion, $tipo);
$fila = mysqli_fetch_array($nivel);
if ($fila['tipo_usuario'] == "Admin") {
include('modulos/nav-admin.php');
} elseif ($fila['tipo_usuario'] == "Colaborador") {
include('modulos/nav-colab.php');
}
?>
<div class="content">
<nav class="navbar navbar-expand rojizo navbar-dark sticky-top px-4 py-0">
<a href="index.php" class="navbar-brand d-flex d-lg-none d-sm-block me-4">
<h2 class="text-primary mb-0"> <img src="img/Logo.png" width="200" height="80"><i class="fa "></i></h2>
</a>
<a href="#" class="sidebar-toggler flex-shrink-0">
<i class="fa fa-bars"></i>
</a>
<div class="navbar-nav align-items-center ms-auto">
<div class="nav-item dropdown">
<a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown">
<img class="rounded-circle me-lg-2" src="<?php
$usuario = $_SESSION['nombre_usuario'];
$img = "SELECT imagen FROM Trabajadores, Usuarios WHERE Trabajadores.id=Usuarios.id_trabajador AND Usuarios.nombre_usuario='$usuario';";
$imagen = mysqli_query($conexion, $img);
$src = mysqli_fetch_array($imagen);
$url = $src['imagen'];
echo $url; ?>" alt="" style="width: 40px; height: 40px;">
<span class="d-none d-lg-inline-flex"><?php echo $usuario; ?></span>
</a>
<div class="dropdown-menu dropdown-menu-end cafeoscuro border-0 rounded-0 rounded-bottom m-0">
<a href="ajustes.php" class="dropdown-item">Ajustes</a>
<a href="control/cerrar.php" class="dropdown-item">Cerrar Sesión</a>
</div>
</div>
</div>
</nav>
<div class="container-fluid pt-3 px-3">
<div class="cafeclaro rounded p-4">
<div class="naranja BarraEtiqueta pb-1 mt-2 rounded">
<h5 class=" pt-2 text-center ">CATALOGO PEDIDOS</h5>
</div>
<!-- Form Start -->
<div class="container-fluid px-4">
<div class="cafeoscuro rounded h-100 p-3 pt-3 pb-1 w-100">
<form class="row" method="post" name="formularioPedido">
<div class="col-sm-12 col-xl-12">
<div class="mb-3">
<label for="floatingTextarea" class="Text">Nombre del cliente</label>
<select class="form-select mb-3 grispan" name="nombre" aria-label="Default select example" oninput="obtenerPrecios()">
<option selected>Seleccionar cliente</option>
<?php
$nomCliente = "SELECT nombre FROM Clientes;";
$conNom = mysqli_query($conexion, $nomCliente);
while ($fila = mysqli_fetch_array($conNom)) {
printf('<option class="naranja" value="%s">%s</option>', $fila['nombre'], $fila['nombre']);
}
?>
</select>
</div>
<div>
<label class="Text">Producto</label>
<table class="table table-bordered table-hover p-4">
<thead>
<tr>
<th scope="col">Producto</th>
<th scope="col">Cantidad</th>
<th scope="col">Precio</th>
<th scope="col">Costo Total</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<select class="form-select grispan" name="producto" id="productoInput">
<option selected>Seleccionar producto</option>
<?php
$nomProducto = "SELECT nombre_producto FROM Productos;";
$conNom = mysqli_query($conexion, $nomProducto);
while ($fila = mysqli_fetch_array($conNom)) {
printf('<option class="naranja" value="%s">%s</option>', $fila['nombre_producto'], $fila['nombre_producto']);
}
?>
</select>
</td>
<td>
<input class="form-control" id="cantidad" name="cantidad" type="number">
</td>
<td>
<select class="form-select grispan" id="costo" name="costo" oninput="obtenerPrecios()">
<option selected>Selecciona Precio</option>
<option value="1">Mayoreo</option>
<option value="2">Menudeo</option>
</select>
</td>
<td>
<input style="background: #9c886f;" class="form-control" readonly name="total">
</td>
</tr>
</tbody>
</table>
</div>
<div>
<button class="btn" type="button" onclick="agregarProductos()">Agregar un Producto</button>
</div>
</div>
<div class="col-sm-12 col-xl-12">
<div class="mb-3 ">
<label for="floatingTextarea" class="Text mt-2">Productos Agregados</label>
<textarea readonly class="form-control grispan mt-2" name="agregados" placeholder="Agrega un Producto" id="floatingTextarea" style="height: 100px;background: #9c886f;"></textarea>
</div>
<div>
<button class="btn" type="button" onclick="eliminarUltimaLinea()">Eliminar un Producto</button>
</div>
<div class="mb-3">
<label for="floatingTextarea" class="Text mt-2">Descripción del pedido</label>
<textarea class="form-control grispan mt-2" name="descripcion" placeholder="Descripción" id="floatingTextarea" style="height: 100px;"></textarea>
</div>
<div class=" col-lg-6">
<div class="row">
<h6> Costo Total:</h6>
<div class="col-lg-1">
<label class="display-4 pt-3" style="color: white;">$</label>
</div>
<div class="col-lg-6 " >
<input type="text" id="costo_total" name="costo_total" readonly class="display-4 form-control-plaintext white"value="">
</div>
</div>
</div>
<div class="pt-4">
<div class="row">
<label class="Text col-6">Fecha Realizado</label>
<label class="Text col-6">Fecha Entrega</label>
</div>
<div class="row">
<div class="col-6">
<input type="date" id="fechaActual" name="fechaRegistro" value="<?php echo date('Y-m-d'); ?>" readonly>
</div>
<div class="col-6">
<input type="date" name="fechaEntrega" class="date col-9">
</div>
</div>
</div>
</div>
<div class="BarraBtn rounded border col-sm-12 col-lg-12 p-3 mt-3">
<div class=" row ">
<div class="col"><button type="submit" class="btn col-sm-12 col-lg-12" name="agregar">Agregar Pedido</button></div>
</div>
</div>
<?php
include('control/agregarpedido.php');
?>
</form>
</div>
</div>
</div>
<!-- Form End -->
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script src="lib/chart/chart.min.js"></script>
<script src="lib/easing/easing.min.js"></script>
<script src="lib/waypoints/waypoints.min.js"></script>
<script src="lib/owlcarousel/owl.carousel.min.js"></script>
<script src="lib/tempusdominus/js/moment.min.js"></script>
<script src="lib/tempusdominus/js/moment-timezone.min.js"></script>
<script src="lib/tempusdominus/js/tempusdominus-bootstrap-4.min.js"></script>
<script>
var costo_total=0;
var total=0;
function obtenerPrecios() {
var productoSeleccionado = document.getElementById("productoInput").value;
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
var datosProducto = JSON.parse(xhr.responseText);
if (datosProducto !== null && datosProducto !== undefined) {
var cantidad = document.getElementById("cantidad").value;
var costo = document.getElementById("costo").value;
var totalInput = document.getElementsByName("total")[0];
if (!isNaN(cantidad)) {
cantidad = parseFloat(cantidad);
if (costo == 1) {
var may = parseFloat(datosProducto.precio_mayoreo);
var result = cantidad * may;
totalInput.value = result;
} else if (costo == 2) {
var men = parseFloat(datosProducto.precio_menudeo);
var result = cantidad * men;
totalInput.value = result;
} else {
}
} else {
alert('Ingresa una cantidad válida.');
}
}
}
}
};
xhr.open("GET", "obtener_precios.php?nombre_producto=" + encodeURIComponent(productoSeleccionado), true);
xhr.send();
}
function eliminarUltimaLinea() {
var txt = document.getElementById('floatingTextarea');
// Obtén el contenido del textarea
var contenido = txt.value;
// Dividir el contenido en líneas
var lineas = contenido.split('\n');
// Elimina la última línea
lineas.pop();
// Actualiza el contenido del textarea
txt.value = lineas.join('\n');
costo_total=parseFloat(costo_total)-parseFloat(total);
document.getElementById('costo_total').value =costo_total;
}
function agregarProductos() {
var producto = document.getElementById('productoInput').value;
var cantidad = document.getElementById('cantidad').value;
var costo = document.getElementById('costo').value;
total = document.querySelector('[name="total"]').value;
costo_total=parseFloat(costo_total)+parseFloat(total);
var textoCosto = "";
if (costo == 1) {
textoCosto = "Mayoreo";
} else if (costo == 2) {
textoCosto = "Menudeo";
} else {
// Manejar otro caso si es necesario
textoCosto = "Valor no válido";
}
var textArea = document.getElementById('floatingTextarea').value;
if(textArea==""){
textArea = textArea + producto + '-' + cantidad + '-' + textoCosto + '- $' + total;
}else{
textArea = textArea + '\n' + producto + '-' + cantidad + '-' + textoCosto + '- $' + total;
}
document.getElementById('floatingTextarea').value = textArea;
// Referencia a la segunda tabla
document.getElementById('costo_total').value =costo_total;
document.getElementById('productoInput').value = "Seleccionar producto";
document.getElementById('cantidad').value = "";
document.getElementById('costo').value = "Selecciona Precio";
document.querySelector('[name="total"]').value = "";
}
</script>
<!-- Template Javascript -->
<script src="js/main.js"></script>
<script>
window.setTimeout(function() {
$(".alert").fadeTo(500, 0).slideUp(500, function() {
$(this).remove();
window.location.href = 'catalogo-pedidos.php';
});
}, 3000);
</script>
<script src="js/main.js"></script>
<script src="script/script.js"></script>
<script src="script/showHide.js"></script>
</body>
</html>