316 lines
12 KiB
PHP
316 lines
12 KiB
PHP
<?php
|
|
// my_subscription.php — L'owner vede lo stato del suo abbonamento (area gestionale)
|
|
// Storico pagamenti predisposto ma non attivo (arriverà con Stripe).
|
|
|
|
ini_set('display_errors', 1);
|
|
ini_set('display_startup_errors', 1);
|
|
error_reporting(E_ALL);
|
|
|
|
if (session_status() === PHP_SESSION_NONE) session_start();
|
|
include('include/headscript.php');
|
|
|
|
$dbHandler = DBHandlerSelect::getInstance();
|
|
$pdo = $dbHandler->getConnection();
|
|
|
|
if (!isset($iduserlogin)) {
|
|
header("Location: login.php");
|
|
exit;
|
|
}
|
|
|
|
function e(?string $v): string
|
|
{
|
|
return htmlspecialchars((string)$v, ENT_QUOTES, 'UTF-8');
|
|
}
|
|
function getFlash(): ?array
|
|
{
|
|
if (!isset($_SESSION['flash'])) return null;
|
|
$f = $_SESSION['flash'];
|
|
unset($_SESSION['flash']);
|
|
return $f;
|
|
}
|
|
|
|
// Salone dell'owner (il primo, coerente con appointments.php)
|
|
$stmt = $pdo->prepare("SELECT id, name FROM shops WHERE owner_id = ? ORDER BY created_at ASC LIMIT 1");
|
|
$stmt->execute([$iduserlogin]);
|
|
$shop = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
if (!$shop) {
|
|
header("Location: onboarding_salon.php");
|
|
exit;
|
|
}
|
|
|
|
$shop_id = (int)$shop['id'];
|
|
$shop_name = $shop['name'];
|
|
|
|
// Abbonamento corrente + piano
|
|
$subStmt = $pdo->prepare("
|
|
SELECT sub.status, sub.started_at, sub.expires_at, sub.block_reason,
|
|
p.name AS plan_name, p.price, p.billing_period
|
|
FROM shop_subscriptions sub
|
|
LEFT JOIN subscription_plans p ON sub.plan_id = p.id
|
|
WHERE sub.shop_id = ?
|
|
");
|
|
$subStmt->execute([$shop_id]);
|
|
$sub = $subStmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
// Meta stato
|
|
function subMeta(?string $status): array
|
|
{
|
|
switch ($status) {
|
|
case 'active':
|
|
return ['badge' => 'bg-success', 'label' => 'Attivo', 'ico' => 'bx-check-circle'];
|
|
case 'trialing':
|
|
return ['badge' => 'bg-info text-dark', 'label' => 'In prova', 'ico' => 'bx-time'];
|
|
case 'expired':
|
|
return ['badge' => 'bg-warning text-dark', 'label' => 'Scaduto', 'ico' => 'bx-error-circle'];
|
|
case 'blocked':
|
|
return ['badge' => 'bg-danger', 'label' => 'Bloccato', 'ico' => 'bx-block'];
|
|
case 'pending':
|
|
return ['badge' => 'bg-secondary', 'label' => 'In attesa', 'ico' => 'bx-hourglass'];
|
|
default:
|
|
return ['badge' => 'bg-light text-dark', 'label' => 'Nessun abbonamento', 'ico' => 'bx-info-circle'];
|
|
}
|
|
}
|
|
$meta = subMeta($sub['status'] ?? null);
|
|
|
|
// Giorni alla scadenza
|
|
$daysLeft = null;
|
|
$expLabel = '—';
|
|
if (!empty($sub['expires_at'])) {
|
|
$expLabel = date('d/m/Y', strtotime($sub['expires_at']));
|
|
$today = new DateTime('today');
|
|
$exp = new DateTime($sub['expires_at']);
|
|
$daysLeft = (int)$today->diff($exp)->format('%r%a');
|
|
}
|
|
$flash = getFlash();
|
|
?>
|
|
<!doctype html>
|
|
<html lang="it">
|
|
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<link rel="icon" href="assets/images/favicon-32x32.png" type="image/png" />
|
|
<?php include('cssinclude.php'); ?>
|
|
<?php include('siteinfo.php'); ?>
|
|
<title>Il mio abbonamento - <?= e($shop_name) ?></title>
|
|
<style>
|
|
:root {
|
|
--soft-border: #e9edf3;
|
|
--muted: #6b7280;
|
|
--bg: #f6f7fb;
|
|
}
|
|
|
|
body {
|
|
background: var(--bg);
|
|
}
|
|
|
|
.card-shell {
|
|
border-radius: 14px;
|
|
border: 1px solid var(--soft-border);
|
|
background: #fff;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.page-title {
|
|
font-weight: 900;
|
|
letter-spacing: -0.02em;
|
|
}
|
|
|
|
.sub-hero {
|
|
border-radius: 16px;
|
|
padding: 28px;
|
|
color: #fff;
|
|
background: linear-gradient(120deg, #e6007e, #ff6a3d);
|
|
position: relative;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.sub-hero .plan {
|
|
font-size: 26px;
|
|
font-weight: 900;
|
|
}
|
|
|
|
.sub-hero .price {
|
|
font-size: 15px;
|
|
opacity: .95;
|
|
}
|
|
|
|
.sub-badge {
|
|
display: inline-block;
|
|
padding: .35rem .8rem;
|
|
border-radius: 999px;
|
|
font-weight: 700;
|
|
font-size: .85rem;
|
|
}
|
|
|
|
.info-row {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
padding: 14px 0;
|
|
border-bottom: 1px solid var(--soft-border);
|
|
}
|
|
|
|
.info-row:last-child {
|
|
border-bottom: none;
|
|
}
|
|
|
|
.info-row .k {
|
|
color: var(--muted);
|
|
}
|
|
|
|
.info-row .v {
|
|
font-weight: 700;
|
|
color: #2b2540;
|
|
}
|
|
|
|
.alert-soft {
|
|
border-radius: 12px;
|
|
padding: 14px 18px;
|
|
font-size: 14.5px;
|
|
}
|
|
|
|
.exp-soon {
|
|
color: #b45309;
|
|
}
|
|
|
|
.exp-past {
|
|
color: #dc2626;
|
|
}
|
|
|
|
.locked {
|
|
opacity: .65;
|
|
}
|
|
|
|
.soon-badge {
|
|
background: #fff0e8;
|
|
color: #ff6a3d;
|
|
font-weight: 700;
|
|
font-size: 12px;
|
|
padding: 3px 10px;
|
|
border-radius: 999px;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<div class="wrapper">
|
|
<?php include('include/navbar.php'); ?>
|
|
<?php include('include/topbar.php'); ?>
|
|
|
|
<div class="page-wrapper">
|
|
<div class="page-content">
|
|
|
|
<div class="d-flex align-items-center justify-content-between mb-3">
|
|
<div class="page-title h5 mb-0"><i class="bx bx-credit-card me-1"></i> Il mio abbonamento</div>
|
|
</div>
|
|
|
|
<?php if ($flash): ?>
|
|
<div class="alert alert-<?= e($flash['type']) ?> alert-dismissible fade show" role="alert">
|
|
<?= e($flash['text']) ?>
|
|
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if (!$sub): ?>
|
|
<!-- Nessun abbonamento -->
|
|
<div class="card-shell p-4 text-center">
|
|
<i class="bx bx-info-circle" style="font-size:48px;color:#ff6a3d;"></i>
|
|
<h4 class="mt-2 mb-1">Nessun abbonamento attivo</h4>
|
|
<p class="text-muted mb-3">Il tuo salone non ha ancora un abbonamento. Attivane uno per essere visibile ai clienti.</p>
|
|
<div><a href="../pricing.php" class="btn btn-primary">Vedi i piani</a></div>
|
|
</div>
|
|
<?php else: ?>
|
|
|
|
<div class="row g-3">
|
|
<!-- Colonna sinistra: stato -->
|
|
<div class="col-lg-7">
|
|
<div class="sub-hero mb-3">
|
|
<div class="d-flex justify-content-between align-items-start">
|
|
<div>
|
|
<div class="plan"><?= e($sub['plan_name'] ?: 'Piano personalizzato') ?></div>
|
|
<?php if ($sub['price'] !== null): ?>
|
|
<div class="price">€<?= number_format((float)$sub['price'], 2, ',', '.') ?>/<?= $sub['billing_period'] === 'yearly' ? 'anno' : 'mese' ?></div>
|
|
<?php endif; ?>
|
|
</div>
|
|
<span class="sub-badge" style="background:rgba(255,255,255,.25);">
|
|
<?= e($meta['label']) ?>
|
|
</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card-shell p-4">
|
|
<div class="info-row">
|
|
<span class="k">Stato</span>
|
|
<span class="v"><span class="badge <?= $meta['badge'] ?>"><?= $meta['label'] ?></span></span>
|
|
</div>
|
|
<div class="info-row">
|
|
<span class="k">Attivo dal</span>
|
|
<span class="v"><?= !empty($sub['started_at']) ? date('d/m/Y', strtotime($sub['started_at'])) : '—' ?></span>
|
|
</div>
|
|
<div class="info-row">
|
|
<span class="k">Scadenza</span>
|
|
<span class="v">
|
|
<?= $expLabel ?>
|
|
<?php if ($daysLeft !== null): ?>
|
|
<?php if ($daysLeft < 0): ?>
|
|
<small class="exp-past">(scaduto)</small>
|
|
<?php elseif ($daysLeft <= 7): ?>
|
|
<small class="exp-soon">(tra <?= $daysLeft ?> giorni)</small>
|
|
<?php else: ?>
|
|
<small class="text-muted">(tra <?= $daysLeft ?> giorni)</small>
|
|
<?php endif; ?>
|
|
<?php endif; ?>
|
|
</span>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Avvisi contestuali -->
|
|
<?php if ($sub['status'] === 'blocked'): ?>
|
|
<div class="alert-soft mt-3" style="background:#fdecef;color:#b3143a;border:1px solid #f5c2cd;">
|
|
<i class="bx bx-block me-1"></i> Il tuo salone è stato sospeso dall'amministrazione.
|
|
<?php if (!empty($sub['block_reason'])): ?><br><strong>Motivo:</strong> <?= e($sub['block_reason']) ?><?php endif; ?>
|
|
<br>Contatta il supporto per maggiori informazioni.
|
|
</div>
|
|
<?php elseif ($sub['status'] === 'expired'): ?>
|
|
<div class="alert-soft mt-3" style="background:#fff8e6;color:#9a7a1a;border:1px solid #ffe4a3;">
|
|
<i class="bx bx-error-circle me-1"></i> Il tuo abbonamento è scaduto e il salone non è più visibile ai clienti. Rinnova per riattivarlo.
|
|
</div>
|
|
<?php elseif ($daysLeft !== null && $daysLeft >= 0 && $daysLeft <= 7): ?>
|
|
<div class="alert-soft mt-3" style="background:#fff8e6;color:#9a7a1a;border:1px solid #ffe4a3;">
|
|
<i class="bx bx-time me-1"></i> Il tuo abbonamento scade tra <?= $daysLeft ?> giorni. Rinnova per non interrompere il servizio.
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<!-- Rinnovo: predisposto per Stripe -->
|
|
<div class="mt-3">
|
|
<button class="btn btn-primary" disabled title="Disponibile a breve">
|
|
<i class="bx bx-refresh me-1"></i> Rinnova abbonamento
|
|
</button>
|
|
<span class="soon-badge ms-2">presto con pagamento online</span>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Colonna destra: storico pagamenti (predisposto) -->
|
|
<div class="col-lg-5">
|
|
<div class="card-shell p-4 locked">
|
|
<h5 class="fw-bold mb-3"><i class="bx bx-receipt me-1"></i> Storico pagamenti <span class="soon-badge ms-1">presto</span></h5>
|
|
<div class="text-center py-4 text-muted">
|
|
<i class="bx bx-receipt" style="font-size:44px;opacity:.4;"></i>
|
|
<p class="mt-2 mb-0">Qui vedrai le tue fatture e i pagamenti effettuati non appena attiveremo il pagamento online.</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php endif; ?>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
<?php include('include/footer.php'); ?>
|
|
</div>
|
|
|
|
<?php include('jsinclude.php'); ?>
|
|
</body>
|
|
|
|
</html>
|