179 lines
5.6 KiB
PHP
Executable File
179 lines
5.6 KiB
PHP
Executable File
<?php
|
|
require_once __DIR__."/../includes/auth.php";requireRole("proprietario");require_once __DIR__."/../config/database.php";
|
|
$idOrdine=filter_input(INPUT_GET,"idOrdine",FILTER_VALIDATE_INT);
|
|
$stato=trim($_GET["stato"]??"");
|
|
$ordini=[];
|
|
$personaleOrdine=[];
|
|
|
|
// Ricavo gli ordini
|
|
$stmt = $pdo->prepare("
|
|
SELECT
|
|
o1.idOrdine,
|
|
CONCAT(u1.nome, ' ', u1.cognome) AS cliente,
|
|
o1.dataOraCreazione,
|
|
o1.statoConferma,
|
|
uso1.nomeStato,
|
|
o1.orarioConsegna,
|
|
o1.totale
|
|
|
|
FROM
|
|
ordine AS o1
|
|
|
|
LEFT JOIN ultimoStatoOrdini AS uso1
|
|
ON o1.idOrdine = uso1.idOrdine
|
|
|
|
LEFT JOIN cliente AS c1
|
|
ON o1.idCliente = c1.idUtente
|
|
|
|
LEFT JOIN utente AS u1
|
|
ON c1.idUtente = u1.idUtente
|
|
|
|
WHERE
|
|
1
|
|
");
|
|
|
|
$stmt->execute();
|
|
|
|
$ordini = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
/* TODO SQL DI SUPPORTO - Monitorare ordini passati, attivi ed evasi.
|
|
* Input: $stato. Output: idOrdine, cliente, dataOraCreazione, statoConferma,
|
|
* nomeStato, orarioConsegna, totale, indirizzo. */
|
|
if($idOrdine){
|
|
/*
|
|
* QUERY 13 - Membri del personale che hanno lavorato a un ordine
|
|
* Input: $idOrdine
|
|
* Output atteso: idUtente, nome, cognome, email, numeroCambiStato,
|
|
* primoIntervento, ultimoIntervento
|
|
* TODO SQL: implementare manualmente la Query 13.
|
|
*/
|
|
|
|
// Membri del personale che hanno lavorato a un ordine
|
|
$stmt = $pdo->prepare("
|
|
SELECT
|
|
u1.idUtente,
|
|
u1.nome,
|
|
u1.cognome,
|
|
u1.email,
|
|
COUNT(ss1.idStoricoStato) AS numeroCambiStato,
|
|
MIN(ss1.timestamp) AS primoIntervento,
|
|
MAX(ss1.timestamp) AS ultimoIntervento
|
|
|
|
FROM
|
|
storicoStato AS ss1
|
|
|
|
JOIN personale AS p1
|
|
ON ss1.idPersonale = p1.idUtente
|
|
|
|
JOIN utente AS u1
|
|
ON p1.idUtente = u1.idUtente
|
|
|
|
WHERE
|
|
ss1.idOrdine = :idOrdine
|
|
|
|
GROUP BY
|
|
u1.idUtente,
|
|
u1.nome,
|
|
u1.cognome,
|
|
u1.email
|
|
|
|
ORDER BY
|
|
primoIntervento
|
|
");
|
|
|
|
$stmt->execute([
|
|
"idOrdine" => $idOrdine
|
|
]);
|
|
|
|
$personaleOrdine = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
}
|
|
$pageTitle="Monitoraggio ordini";$basePath="..";require __DIR__."/../includes/header.php";
|
|
?>
|
|
<h1 class="h3">Monitoraggio ordini</h1>
|
|
<form method="get" class="card card-body mb-3">
|
|
<div class="row g-3 align-items-end">
|
|
<div class="col-md-4">
|
|
<label class="form-label">Stato</label>
|
|
<select class="form-select" name="stato">
|
|
<option value="">Tutti</option>
|
|
<?php foreach(["inserito","in preparazione","pronto","in consegna","consegnato"] as $s):?>
|
|
<option <?=$stato===$s?"selected":""?>><?=e($s)?></option>
|
|
<?php endforeach;?>
|
|
</select>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<label class="form-label">ID ordine per personale (Q13)</label>
|
|
<input class="form-control" type="number" min="1" name="idOrdine" value="<?=e($idOrdine)?>">
|
|
</div>
|
|
<div class="col-md-2">
|
|
<button class="btn btn-primary">Applica</button>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
|
|
<?php if(!$ordini):?>
|
|
<div class="alert alert-info">Completare il TODO SQL per visualizzare gli ordini.</div>
|
|
<?php endif;?>
|
|
|
|
<div class="table-responsive">
|
|
<table class="table table-striped">
|
|
<thead>
|
|
<tr>
|
|
<th>ID</th>
|
|
<th>Cliente</th>
|
|
<th>Creazione</th>
|
|
<th>Conferma</th>
|
|
<th>Stato</th>
|
|
<th>Consegna</th>
|
|
<th>Totale</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach($ordini as $o):?>
|
|
<tr>
|
|
<td><?=e($o["idOrdine"])?></td>
|
|
<td><?=e($o["cliente"])?></td>
|
|
<td><?=e($o["dataOraCreazione"])?></td>
|
|
<td><?=e($o["statoConferma"])?></td>
|
|
<td><?=e($o["nomeStato"]??"—")?></td>
|
|
<td><?=e($o["orarioConsegna"])?></td>
|
|
<td>€ <?=e($o["totale"])?></td>
|
|
</tr>
|
|
<?php endforeach;?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<?php if($idOrdine):?>
|
|
<div class="card card-body mt-4">
|
|
<h2 class="h5">Personale dell'ordine #<?=e($idOrdine)?> (Q13)</h2>
|
|
<?php if(!$personaleOrdine):?>
|
|
<p class="text-muted">Risultati disponibili dopo la Query 13.</p>
|
|
<?php endif;?>
|
|
<table class="table">
|
|
<thead>
|
|
<tr>
|
|
<th>Nome</th>
|
|
<th>Email</th>
|
|
<th>Cambi stato</th>
|
|
<th>Primo</th>
|
|
<th>Ultimo</th>
|
|
</tr></thead>
|
|
<tbody>
|
|
<?php foreach($personaleOrdine as $p):?>
|
|
<tr>
|
|
<td><?=e($p["nome"]." ".$p["cognome"])?></td>
|
|
<td><?=e($p["email"])?></td>
|
|
<td><?=e($p["numeroCambiStato"])?></td>
|
|
<td><?=e($p["primoIntervento"])?></td>
|
|
<td><?=e($p["ultimoIntervento"])?></td>
|
|
</tr>
|
|
<?php endforeach;?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<?php endif;?>
|
|
|
|
<?php require __DIR__."/../includes/footer.php";?>
|