Aggiornamento lato PERSONALE
This commit is contained in:
@@ -620,7 +620,7 @@
|
||||
)
|
||||
|
||||
VALUES (
|
||||
'IN LAVORAZIONE',
|
||||
'inserito',
|
||||
1
|
||||
)
|
||||
");
|
||||
|
||||
+607
-22
@@ -1,24 +1,609 @@
|
||||
<?php
|
||||
require_once __DIR__ . "/../includes/auth.php";
|
||||
requireRole("personale");
|
||||
require_once __DIR__ . "/../config/database.php";
|
||||
$idPersonale = (int) $_SESSION["idUtente"];
|
||||
$soloInRitardo = ($_GET["filtro"] ?? "") === "ritardo";
|
||||
$ordini = [];
|
||||
/*
|
||||
* QUERY 5 - Ordini non ancora messi in preparazione dopo più di un'ora
|
||||
* Input: nessuno; $soloInRitardo controlla la vista richiesta dalla UI
|
||||
* Output atteso: idOrdine, dataOraCreazione, orarioConsegna, totale,
|
||||
* nomeCliente, cognomeCliente, via, numeroCivico, nomeComune,
|
||||
* nomeStato, timestampUltimoStato, minutiAttesa
|
||||
* TODO SQL: implementare manualmente la Query 5.
|
||||
*/
|
||||
/* Per la vista completa degli ordini correnti predisporre inoltre una query
|
||||
* di supporto con gli stessi campi, senza il vincolo "oltre un'ora". */
|
||||
$pageTitle = "Ordini correnti"; $basePath = "..";
|
||||
require __DIR__ . "/../includes/header.php";
|
||||
|
||||
require_once __DIR__ . "/../includes/auth.php";
|
||||
|
||||
requireRole("personale");
|
||||
|
||||
require_once __DIR__ . "/../config/database.php";
|
||||
|
||||
$idPersonale = (int) $_SESSION["idUtente"];
|
||||
|
||||
$soloInRitardo = ($_GET["filtro"] ?? "") === "ritardo";
|
||||
|
||||
$ordini = [];
|
||||
|
||||
$stmt = $pdo->prepare("
|
||||
SELECT
|
||||
o1.idOrdine,
|
||||
o1.dataOraCreazione,
|
||||
o1.orarioConsegna,
|
||||
o1.totale,
|
||||
o1.idCliente,
|
||||
o1.idIndirizzo,
|
||||
abitazione.via,
|
||||
abitazione.numeroCivico,
|
||||
abitazione.nomeComune,
|
||||
clienti.nome AS nomeCliente,
|
||||
clienti.cognome AS cognomeCliente,
|
||||
stati.nomeStato,
|
||||
stati.timestampUltimoStato,
|
||||
TIMESTAMPDIFF(
|
||||
MINUTE,
|
||||
stati.timestampUltimoStato,
|
||||
CURRENT_TIMESTAMP
|
||||
) AS minutiAttesa
|
||||
|
||||
FROM
|
||||
ordine AS o1
|
||||
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
ss2.idOrdine,
|
||||
so2.nomeStato,
|
||||
ss2.timestamp AS timestampUltimoStato
|
||||
|
||||
FROM
|
||||
storicoStato AS ss2
|
||||
|
||||
JOIN statoOrdine AS so2
|
||||
ON ss2.idStatoOrdine = so2.idStatoOrdine
|
||||
|
||||
WHERE
|
||||
so2.posizione = (
|
||||
SELECT
|
||||
MAX(so3.posizione)
|
||||
|
||||
FROM
|
||||
storicoStato AS ss3
|
||||
|
||||
JOIN statoOrdine AS so3
|
||||
ON ss3.idStatoOrdine = so3.idStatoOrdine
|
||||
|
||||
WHERE
|
||||
ss3.idOrdine = ss2.idOrdine
|
||||
)
|
||||
) AS stati
|
||||
ON o1.idOrdine = stati.idOrdine
|
||||
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
c4.idUtente,
|
||||
u4.nome,
|
||||
u4.cognome
|
||||
|
||||
FROM
|
||||
cliente AS c4
|
||||
|
||||
JOIN utente AS u4
|
||||
ON u4.idUtente = c4.idUtente
|
||||
) AS clienti
|
||||
ON o1.idCliente = clienti.idUtente
|
||||
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
i5.idIndirizzo,
|
||||
i5.via,
|
||||
i5.numeroCivico,
|
||||
c5.nome AS nomeComune
|
||||
|
||||
FROM
|
||||
indirizzo AS i5
|
||||
|
||||
JOIN comune AS c5
|
||||
ON i5.idComune = c5.idComune
|
||||
) AS abitazione
|
||||
ON o1.idIndirizzo = abitazione.idIndirizzo
|
||||
|
||||
WHERE
|
||||
1
|
||||
");
|
||||
|
||||
$stmt->execute();
|
||||
|
||||
$ordini = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
|
||||
// Dati di riepilogo ottenuti dagli ordini già caricati
|
||||
$numeroOrdini = count($ordini);
|
||||
|
||||
$numeroInRitardo = count(
|
||||
array_filter(
|
||||
$ordini,
|
||||
function ($ordine) {
|
||||
return isset($ordine["minutiAttesa"])
|
||||
&& (int) $ordine["minutiAttesa"] >= 60;
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
$valoreTotaleOrdini = array_sum(
|
||||
array_map(
|
||||
function ($ordine) {
|
||||
return (float) ($ordine["totale"] ?? 0);
|
||||
},
|
||||
$ordini
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
$pageTitle = "Ordini correnti";
|
||||
$basePath = "..";
|
||||
|
||||
require __DIR__ . "/../includes/header.php";
|
||||
|
||||
?>
|
||||
|
||||
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
|
||||
<div>
|
||||
<h1 class="h3 mb-1">
|
||||
Ordini correnti
|
||||
</h1>
|
||||
|
||||
<div class="text-muted">
|
||||
Gestione degli ordini attualmente presenti nel sistema
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<a
|
||||
class="btn btn-outline-secondary"
|
||||
href="ordini.php"
|
||||
>
|
||||
Tutti
|
||||
</a>
|
||||
|
||||
<a
|
||||
class="btn btn-warning"
|
||||
href="?filtro=ritardo"
|
||||
>
|
||||
In attesa da oltre un'ora (Q5)
|
||||
</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<!-- RIEPILOGO -->
|
||||
|
||||
<div class="row g-3 mb-4">
|
||||
|
||||
<div class="col-md-4">
|
||||
|
||||
<div class="card shadow-sm h-100">
|
||||
|
||||
<div class="card-body">
|
||||
|
||||
<div class="text-muted small">
|
||||
Ordini visualizzati
|
||||
</div>
|
||||
|
||||
<div class="fs-3 fw-bold">
|
||||
<?= e($numeroOrdini) ?>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div class="col-md-4">
|
||||
|
||||
<div class="card shadow-sm h-100">
|
||||
|
||||
<div class="card-body">
|
||||
|
||||
<div class="text-muted small">
|
||||
In attesa da almeno 60 minuti
|
||||
</div>
|
||||
|
||||
<div class="fs-3 fw-bold text-danger">
|
||||
<?= e($numeroInRitardo) ?>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div class="col-md-4">
|
||||
|
||||
<div class="card shadow-sm h-100">
|
||||
|
||||
<div class="card-body">
|
||||
|
||||
<div class="text-muted small">
|
||||
Valore complessivo
|
||||
</div>
|
||||
|
||||
<div class="fs-3 fw-bold">
|
||||
<?= number_format(
|
||||
$valoreTotaleOrdini,
|
||||
2,
|
||||
",",
|
||||
"."
|
||||
) ?> €
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<?php if (!$ordini): ?>
|
||||
|
||||
<div class="alert alert-info">
|
||||
Nessun risultato: completare la Query 5 o il caricamento di supporto.
|
||||
</div>
|
||||
|
||||
<?php else: ?>
|
||||
|
||||
|
||||
<div class="card shadow-sm">
|
||||
|
||||
<div class="card-header">
|
||||
|
||||
<strong>
|
||||
Elenco ordini
|
||||
</strong>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div class="table-responsive">
|
||||
|
||||
<table class="table table-hover align-middle mb-0">
|
||||
|
||||
<thead class="table-light">
|
||||
|
||||
<tr>
|
||||
|
||||
<th>
|
||||
Ordine
|
||||
</th>
|
||||
|
||||
<th>
|
||||
Cliente
|
||||
</th>
|
||||
|
||||
<th>
|
||||
Indirizzo
|
||||
</th>
|
||||
|
||||
<th>
|
||||
Creato
|
||||
</th>
|
||||
|
||||
<th>
|
||||
Stato
|
||||
</th>
|
||||
|
||||
<th>
|
||||
Ultimo aggiornamento
|
||||
</th>
|
||||
|
||||
<th>
|
||||
Attesa
|
||||
</th>
|
||||
|
||||
<th>
|
||||
Consegna
|
||||
</th>
|
||||
|
||||
<th class="text-end">
|
||||
Totale
|
||||
</th>
|
||||
|
||||
<th>
|
||||
</th>
|
||||
|
||||
</tr>
|
||||
|
||||
</thead>
|
||||
|
||||
|
||||
<tbody>
|
||||
|
||||
<?php foreach ($ordini as $o): ?>
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
$minutiAttesa = null;
|
||||
|
||||
if (isset($o["minutiAttesa"])) {
|
||||
$minutiAttesa = (int) $o["minutiAttesa"];
|
||||
}
|
||||
|
||||
|
||||
// Colore badge attesa
|
||||
|
||||
if ($minutiAttesa === null) {
|
||||
|
||||
$classeAttesa = "bg-secondary";
|
||||
|
||||
} elseif ($minutiAttesa >= 60) {
|
||||
|
||||
$classeAttesa = "bg-danger";
|
||||
|
||||
} elseif ($minutiAttesa >= 30) {
|
||||
|
||||
$classeAttesa = "bg-warning text-dark";
|
||||
|
||||
} else {
|
||||
|
||||
$classeAttesa = "bg-success";
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Colore badge stato
|
||||
|
||||
switch ($o["nomeStato"] ?? "") {
|
||||
|
||||
case "inserito":
|
||||
$classeStato = "bg-secondary";
|
||||
break;
|
||||
|
||||
case "in preparazione":
|
||||
$classeStato = "bg-warning text-dark";
|
||||
break;
|
||||
|
||||
case "pronto":
|
||||
$classeStato = "bg-info text-dark";
|
||||
break;
|
||||
|
||||
case "in consegna":
|
||||
$classeStato = "bg-primary";
|
||||
break;
|
||||
|
||||
case "consegnato":
|
||||
$classeStato = "bg-success";
|
||||
break;
|
||||
|
||||
default:
|
||||
$classeStato = "bg-secondary";
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
|
||||
<tr>
|
||||
|
||||
|
||||
<!-- ID ORDINE -->
|
||||
|
||||
<td>
|
||||
|
||||
<strong>
|
||||
#<?= e($o["idOrdine"]) ?>
|
||||
</strong>
|
||||
|
||||
</td>
|
||||
|
||||
|
||||
<!-- CLIENTE -->
|
||||
|
||||
<td>
|
||||
|
||||
<div class="fw-semibold">
|
||||
|
||||
<?= e(
|
||||
($o["nomeCliente"] ?? "")
|
||||
. " "
|
||||
. ($o["cognomeCliente"] ?? "")
|
||||
) ?>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="small text-muted">
|
||||
|
||||
Cliente #<?= e($o["idCliente"]) ?>
|
||||
|
||||
</div>
|
||||
|
||||
</td>
|
||||
|
||||
|
||||
<!-- INDIRIZZO -->
|
||||
|
||||
<td>
|
||||
|
||||
<div>
|
||||
|
||||
<?= e(
|
||||
($o["via"] ?? "")
|
||||
. " "
|
||||
. ($o["numeroCivico"] ?? "")
|
||||
) ?>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="small text-muted">
|
||||
|
||||
<?= e(
|
||||
$o["nomeComune"] ?? ""
|
||||
) ?>
|
||||
|
||||
</div>
|
||||
|
||||
</td>
|
||||
|
||||
|
||||
<!-- DATA CREAZIONE -->
|
||||
|
||||
<td>
|
||||
|
||||
<?php if (!empty($o["dataOraCreazione"])): ?>
|
||||
|
||||
<?= e(
|
||||
date(
|
||||
"d/m/Y H:i",
|
||||
strtotime(
|
||||
$o["dataOraCreazione"]
|
||||
)
|
||||
)
|
||||
) ?>
|
||||
|
||||
<?php else: ?>
|
||||
|
||||
<span class="text-muted">
|
||||
—
|
||||
</span>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
</td>
|
||||
|
||||
|
||||
<!-- STATO -->
|
||||
|
||||
<td>
|
||||
|
||||
<span class="badge <?= $classeStato ?>">
|
||||
|
||||
<?= e(
|
||||
$o["nomeStato"] ?? "Sconosciuto"
|
||||
) ?>
|
||||
|
||||
</span>
|
||||
|
||||
</td>
|
||||
|
||||
|
||||
<!-- TIMESTAMP ULTIMO STATO -->
|
||||
|
||||
<td>
|
||||
|
||||
<?php if (!empty($o["timestampUltimoStato"])): ?>
|
||||
|
||||
<?= e(
|
||||
date(
|
||||
"d/m/Y H:i",
|
||||
strtotime(
|
||||
$o["timestampUltimoStato"]
|
||||
)
|
||||
)
|
||||
) ?>
|
||||
|
||||
<?php else: ?>
|
||||
|
||||
<span class="text-muted">
|
||||
—
|
||||
</span>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
</td>
|
||||
|
||||
|
||||
<!-- MINUTI ATTESA -->
|
||||
|
||||
<td>
|
||||
|
||||
<?php if ($minutiAttesa !== null): ?>
|
||||
|
||||
<span class="badge <?= $classeAttesa ?>">
|
||||
|
||||
<?= e($minutiAttesa) ?> min
|
||||
|
||||
</span>
|
||||
|
||||
<?php else: ?>
|
||||
|
||||
<span class="text-muted">
|
||||
—
|
||||
</span>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
</td>
|
||||
|
||||
|
||||
<!-- ORARIO CONSEGNA -->
|
||||
|
||||
<td>
|
||||
|
||||
<?php if (!empty($o["orarioConsegna"])): ?>
|
||||
|
||||
<?= e(
|
||||
date(
|
||||
"d/m/Y H:i",
|
||||
strtotime(
|
||||
$o["orarioConsegna"]
|
||||
)
|
||||
)
|
||||
) ?>
|
||||
|
||||
<?php else: ?>
|
||||
|
||||
<span class="text-muted">
|
||||
Non definita
|
||||
</span>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
</td>
|
||||
|
||||
|
||||
<!-- TOTALE -->
|
||||
|
||||
<td class="text-end fw-semibold">
|
||||
|
||||
<?= number_format(
|
||||
(float) ($o["totale"] ?? 0),
|
||||
2,
|
||||
",",
|
||||
"."
|
||||
) ?> €
|
||||
|
||||
</td>
|
||||
|
||||
|
||||
<!-- DETTAGLIO -->
|
||||
|
||||
<td class="text-end">
|
||||
|
||||
<a
|
||||
class="btn btn-sm btn-primary"
|
||||
href="dettaglio_ordine.php?idOrdine=<?= e($o["idOrdine"]) ?>"
|
||||
>
|
||||
Dettaglio
|
||||
</a>
|
||||
|
||||
</td>
|
||||
|
||||
|
||||
</tr>
|
||||
|
||||
|
||||
<?php endforeach; ?>
|
||||
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
require __DIR__ . "/../includes/footer.php";
|
||||
|
||||
?>
|
||||
<div class="d-flex justify-content-between align-items-center mb-3"><h1 class="h3">Ordini correnti</h1><div><a class="btn btn-outline-secondary" href="ordini.php">Tutti</a> <a class="btn btn-warning" href="?filtro=ritardo">In attesa da oltre un'ora (Q5)</a></div></div>
|
||||
<?php if (!$ordini): ?><div class="alert alert-info">Nessun risultato: completare la Query 5 o il caricamento di supporto.</div><?php endif; ?>
|
||||
<div class="table-responsive"><table class="table table-striped align-middle"><thead><tr><th>Ordine</th><th>Cliente</th><th>Creato</th><th>Stato</th><th>Attesa</th><th>Consegna</th><th></th></tr></thead><tbody><?php foreach ($ordini as $o): ?><tr><td>#<?= e($o["idOrdine"]) ?></td><td><?= e(($o["nomeCliente"] ?? "") . " " . ($o["cognomeCliente"] ?? "")) ?></td><td><?= e($o["dataOraCreazione"]) ?></td><td><span class="badge bg-secondary"><?= e($o["nomeStato"]) ?></span></td><td><?= e($o["minutiAttesa"] ?? "—") ?> min</td><td><?= e($o["orarioConsegna"]) ?></td><td><a class="btn btn-sm btn-primary" href="dettaglio_ordine.php?idOrdine=<?= e($o["idOrdine"]) ?>">Dettaglio</a></td></tr><?php endforeach; ?></tbody></table></div>
|
||||
<?php require __DIR__ . "/../includes/footer.php"; ?>
|
||||
|
||||
+7
-1
@@ -88,7 +88,13 @@ CREATE TABLE ordine (
|
||||
-- CREAZIONE RELAZIONE STATO ORDINE
|
||||
CREATE TABLE statoOrdine (
|
||||
idStatoOrdine INT PRIMARY KEY AUTO_INCREMENT NOT NULL,
|
||||
nomeStato VARCHAR(30) NOT NULL,
|
||||
nomeStato ENUM(
|
||||
'inserito',
|
||||
'in preparazione',
|
||||
'pronto',
|
||||
'in consegna',
|
||||
'consegnato'
|
||||
),
|
||||
posizione TINYINT NOT NULL
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user