fixed cancellata
This commit is contained in:
@@ -256,6 +256,8 @@ foreach ($rows as $r) {
|
||||
<td>
|
||||
<?php if ($r['is_gift'] === 'Y' || $r['idorder'] === null) : ?>
|
||||
<span class="badge-soft badge-gift">Omaggio</span>
|
||||
<?php elseif ($r['reprogrammed_incremented'] === 'L') : ?>
|
||||
<span class="badge-soft badge-late">Limite superato: lezione persa</span>
|
||||
<?php elseif ($r['reprogrammed_incremented'] === 'Y') : ?>
|
||||
<span class="badge-soft badge-neutral">
|
||||
Sì<?php if ($r['reprogrammed'] !== null) : ?> (<?php echo (int) $r['reprogrammed']; ?>/<?php echo (int) $r['maxreschedule']; ?>)<?php endif; ?>
|
||||
|
||||
@@ -117,6 +117,7 @@ if ($classTime->format('Y-m-d') === $currentTime->format('Y-m-d')) {
|
||||
$idOrder = $bk['idorder'] !== null ? (int) $bk['idorder'] : null;
|
||||
$ord = null;
|
||||
$incremented = 'N';
|
||||
$ticketLost = false;
|
||||
|
||||
try {
|
||||
$conn->begin_transaction();
|
||||
@@ -132,11 +133,13 @@ try {
|
||||
|
||||
if ($ord) {
|
||||
if ((int) $ord['reprogrammed'] >= (int) $ord['maxreschedule']) {
|
||||
throw new RuntimeException('limit');
|
||||
}
|
||||
// Limite raggiunto: può cancellare (libera il posto) ma il ticket va perso
|
||||
$ticketLost = true;
|
||||
} else {
|
||||
$incremented = 'Y';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Copia nello storico (prima di eliminare)
|
||||
$stmt = $conn->prepare("
|
||||
@@ -150,7 +153,8 @@ try {
|
||||
FROM bookingclass
|
||||
WHERE idbookingclass = ? AND iduser = ?
|
||||
");
|
||||
$stmt->bind_param("isii", $userId, $incremented, $id, $userId);
|
||||
$storicoFlag = $ticketLost ? 'L' : $incremented;
|
||||
$stmt->bind_param("isii", $userId, $storicoFlag, $id, $userId);
|
||||
$stmt->execute();
|
||||
$copied = $stmt->affected_rows;
|
||||
$stmt->close();
|
||||
@@ -166,8 +170,14 @@ try {
|
||||
$stmt->close();
|
||||
}
|
||||
|
||||
// Eliminazione della prenotazione
|
||||
// Limite raggiunto: la prenotazione resta come persa (status 'lost'),
|
||||
// il posto in sala si libera ma il ticket non torna da programmare.
|
||||
// Altrimenti eliminazione normale: il ticket torna disponibile.
|
||||
if ($ticketLost) {
|
||||
$stmt = $conn->prepare("UPDATE bookingclass SET status = 'lost', lostlesson = 'Y' WHERE idbookingclass = ? AND iduser = ?");
|
||||
} else {
|
||||
$stmt = $conn->prepare("DELETE FROM bookingclass WHERE idbookingclass = ? AND iduser = ?");
|
||||
}
|
||||
$stmt->bind_param("ii", $id, $userId);
|
||||
$stmt->execute();
|
||||
$deleted = $stmt->affected_rows;
|
||||
@@ -245,7 +255,8 @@ try {
|
||||
$mail->Body = "
|
||||
<div style='font-family:Arial,sans-serif;font-size:14px;color:#222'>
|
||||
<p>Ciao " . htmlspecialchars($userName ?: 'Yogi') . ",</p>
|
||||
<p>La tua lezione è stata <b>cancellata</b>.</p>
|
||||
<p>La tua lezione è stata <b>cancellata</b>.</p>" . ($ticketLost ? "
|
||||
<p>Avendo già usato tutte le riprogrammazioni del pacchetto, questa lezione non potrà essere recuperata.</p>" : "") . "
|
||||
<p>
|
||||
<b>Lezione:</b> " . htmlspecialchars($className) . "<br>
|
||||
<b>Data/ora prevista:</b> " . htmlspecialchars($classDateTxt) . "<br>
|
||||
@@ -265,5 +276,5 @@ try {
|
||||
}
|
||||
|
||||
// Redirect
|
||||
header("Location: userpanel.php?deleted=1");
|
||||
header("Location: userpanel.php?deleted=" . ($ticketLost ? 'lost' : '1'));
|
||||
exit();
|
||||
|
||||
@@ -4,3 +4,7 @@
|
||||
[2026-10-14 08:44:30] OK inviata. booking_id=70 user_id=2 to=info@claudiosironi.com lezione='Aerial Yoga - base' prevista='21-10-2026 18:30' cancellata='14-10-2026 08:44'
|
||||
[2026-10-14 08:46:52] SMTP in uso host=mail.yogasoul.it porta=465 enc=ssl user=info@yogasoul.it
|
||||
[2026-10-14 08:46:54] OK inviata. booking_id=60 user_id=2 to=info@claudiosironi.com lezione='Aerial Yoga - base' prevista='29-10-2026 20:15' cancellata='14-10-2026 08:46'
|
||||
[2026-10-14 13:46:38] SMTP in uso host=mail.yogasoul.it porta=465 enc=ssl user=info@yogasoul.it
|
||||
[2026-10-14 13:46:39] OK inviata. booking_id=58 user_id=2 to=info@claudiosironi.com lezione='Aerial Yoga - base' prevista='15-10-2026 20:15' cancellata='14-10-2026 13:46'
|
||||
[2026-10-14 13:55:35] SMTP in uso host=mail.yogasoul.it porta=465 enc=ssl user=info@yogasoul.it
|
||||
[2026-10-14 13:55:35] OK inviata. booking_id=71 user_id=2 to=info@claudiosironi.com lezione='Aerial Yoga - base' prevista='22-10-2026 20:15' cancellata='14-10-2026 13:55'
|
||||
|
||||
@@ -26,10 +26,10 @@ SELECT
|
||||
MAX(cert.ultima_scadenza) AS ultima_scadenza_cert,
|
||||
MAX(CASE WHEN cert.ultima_scadenza IS NULL OR cert.ultima_scadenza < CURDATE() THEN 1 ELSE 0 END) AS certificato_scaduto,
|
||||
COUNT(CASE WHEN bookingclass.bookingstart <= CURDATE() AND bookingclass.lostlesson = 'N' THEN 1 END) AS lezioni_praticate,
|
||||
COUNT(CASE WHEN bookingclass.bookingstart > CURDATE() THEN 1 END) AS lezioni_programmate,
|
||||
COUNT(CASE WHEN bookingclass.bookingstart > CURDATE() AND bookingclass.lostlesson = 'N' THEN 1 END)AS lezioni_programmate,
|
||||
COUNT(CASE WHEN bookingclass.lostlesson = 'Y' THEN 1 END) AS lezioni_perse,
|
||||
COALESCE(orderbook_lessons.lezioni_acquistate, 0)
|
||||
- COUNT(CASE WHEN bookingclass.bookingstart > CURDATE() THEN 1 END)
|
||||
- COUNT(CASE WHEN bookingclass.bookingstart > CURDATE() AND bookingclass.lostlesson = 'N' THEN 1 END)
|
||||
- COUNT(CASE WHEN bookingclass.bookingstart <= CURDATE() AND bookingclass.lostlesson = 'N' THEN 1 END)
|
||||
- COUNT(CASE WHEN bookingclass.lostlesson = 'Y' THEN 1 END) AS lezioni_da_programmare
|
||||
FROM auth_users
|
||||
|
||||
+25
-13
@@ -498,20 +498,23 @@ $italianMonths = [
|
||||
});
|
||||
}
|
||||
|
||||
function confirmDeleteOnly(idbookingclass, expirydate) {
|
||||
Swal.fire({
|
||||
title: "Attenzione",
|
||||
html: `
|
||||
<strong>Confermi di voler cancellare questa lezione?</strong><br><br>
|
||||
function confirmDeleteOnly(idbookingclass, expirydate, ticketLost) {
|
||||
var html = ticketLost ?
|
||||
`<strong>Confermi di voler cancellare questa lezione?</strong><br><br>
|
||||
Hai già usato <strong>tutte le riprogrammazioni</strong> del tuo pacchetto.<br>
|
||||
Cancellando liberi il posto in sala, ma
|
||||
<strong style="color:#d33;">la lezione non potrà essere recuperata.</strong> ` :
|
||||
`<strong>Confermi di voler cancellare questa lezione?</strong><br><br>
|
||||
<strong>RICORDA:</strong> dovrai riprogrammarla entro la scadenza del tuo abbonamento per non perderla!<br><br>
|
||||
La cancellazione conta come <strong>una delle riprogrammazioni</strong> disponibili per il tuo pacchetto.<br><br>
|
||||
<span style="font-size:20px;color:#d33;font-weight:bold;">
|
||||
Scadenza: ${expirydate}
|
||||
</span>
|
||||
`,
|
||||
<span style="font-size:20px;color:#d33;font-weight:bold;">Scadenza: ${expirydate}</span>`;
|
||||
|
||||
Swal.fire({
|
||||
title: "Attenzione",
|
||||
html: html,
|
||||
icon: "warning",
|
||||
showCancelButton: true,
|
||||
confirmButtonText: "Procedi",
|
||||
confirmButtonText: ticketLost ? "Cancella comunque" : "Procedi",
|
||||
cancelButtonText: "Annulla",
|
||||
confirmButtonColor: "#d33",
|
||||
cancelButtonColor: "#3085d6"
|
||||
@@ -667,6 +670,13 @@ $italianMonths = [
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php if (($_GET['deleted'] ?? '') === 'lost') { ?>
|
||||
<div class="alert alert-warning alert-dismissible fade show" role="alert">
|
||||
<i class="fas fa-info-circle me-2"></i>
|
||||
Lezione cancellata.
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php if (($_GET['deleted'] ?? '') === '1') { ?>
|
||||
<div class="alert alert-success alert-dismissible fade show" role="alert">
|
||||
<i class="mdi mdi-check-all me-2"></i>
|
||||
@@ -880,16 +890,18 @@ $italianMonths = [
|
||||
<button class="custom-action-button" onclick="addToCalendar(this)" data-eventname="<?php echo e($servicename); ?>" data-eventdate="<?php echo e($newDateFormat); ?>">
|
||||
<i class="far fa-calendar-plus"></i> Cal
|
||||
</button>
|
||||
<?php if ($canBeDeleted && $canReprogram) : ?>
|
||||
<?php if ($canBeDeleted) : ?>
|
||||
<?php if ($canReprogram) : ?>
|
||||
<button class="custom-action-button" onclick="confirmDelete(<?php echo $idbookingclass; ?>, <?php echo $idservice; ?>, 'bookingpanel.php')">
|
||||
<i class="fas fa-calendar-alt"></i> Riprogramma
|
||||
</button>
|
||||
<?php endif; ?>
|
||||
<button class="custom-action-button"
|
||||
onclick="confirmDeleteOnly(<?php echo $idbookingclass; ?>, '<?php echo e($expirydate); ?>')">
|
||||
onclick="confirmDeleteOnly(<?php echo $idbookingclass; ?>, '<?php echo e($expirydate); ?>', <?php echo $canReprogram ? 'false' : 'true'; ?>)">
|
||||
<i class="fas fa-trash"></i> Cancella
|
||||
</button>
|
||||
<?php else : ?>
|
||||
<button class="custom-action-button"><i class="fas fa-exclamation-circle"></i> Non puoi riprogrammare</button>
|
||||
<button class="custom-action-button"><i class="fas fa-exclamation-circle"></i> Non più cancellabile</button>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user