-
Notifications
You must be signed in to change notification settings - Fork 0
/
sumar_total.php
83 lines (77 loc) · 2.91 KB
/
sumar_total.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
<?php
$aProductos = [];
$aProductos[] = [
"nombre" => "Smart TV 55\" 4K UHD",
"marca" => "Hitachi",
"modelo" => "554KS20",
"stock" => 60,
"precio" => 58000
];
$aProductos[] = [
"nombre" => "Samsung Galaxy A30 Blanco",
"marca" => "Samsung",
"modelo" => "Galaxy A30",
"stock" => 0,
"precio" => 22000
];
$aProductos[] = [
"nombre" => "Aire Acondicionado Split F/C Surrey 2900F",
"marca" => "Surrey",
"modelo" => "553AIQ1201E",
"stock" => 5,
"precio" => 45000
];
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Listado de Productos</title>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.min.js" integrity="sha256-3gQJhtmj7YnV1fmtbVcnAV6eI4ws0Tr48bVZCThtCGQ=" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" integrity="sha256-PI8n5gCcz9cQqQXm3PEtDuPG8qx9oFsFctPg0S5zb8g=" crossorigin="anonymous">
</head>
<body>
<main class="container">
<div class="row py-2">
<div class="col-12">
<h1 class="text-center fw-semibold">Listado de Productos</h1>
</div>
</div>
<div class="col-12">
<table class="table table-hover border align-middle">
<thead>
<tr>
<th>Nombre</th>
<th>Marca</th>
<th>Modelo</th>
<th>Stock</th>
<th>Precio</th>
<th>Acción</th>
</tr>
</thead>
<tbody>
<?php
$subtotal = 0;
for($i = 0; $i < count($aProductos); $i++) {
$subtotal += $aProductos[$i]["precio"];
// $subtotal += $aProductos[$i]["precio"] * $aProductos[$i]["stock"];
?>
<tr>
<td><?php echo $aProductos[$i]["nombre"]; ?></td>
<td><?php echo $aProductos[$i]["marca"]; ?></td>
<td><?php echo $aProductos[$i]["modelo"]; ?></td>
<td><?php echo $aProductos[$i]["stock"] > 10 ? "Hay stock" : ($aProductos[$i]["stock"] > 0 ? "Poco stock" : "Sin stock"); ?></td>
<td>$<?php echo $aProductos[$i]["precio"]; ?></td>
<td>
<button class="btn btn-primary"<?php if(!$aProductos[$i]["stock"] > 0) { echo "disabled"; } ?>>Comprar</button>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<h6 class="fw-semibold">El subtotal es: $<?php echo $subtotal; ?></h6>
</div>
</main>
</body>
</html>