Intégration fonctionnalites V1

This commit is contained in:
bastien
2026-07-04 22:30:18 +02:00
parent 55a558b536
commit 10ee859602
54 changed files with 4802 additions and 1018 deletions
+31 -36
View File
@@ -1,9 +1,9 @@
<script setup>
import Checkbox from '@/Components/Checkbox.vue';
import InputError from '@/Components/InputError.vue';
import InputLabel from '@/Components/InputLabel.vue';
import PrimaryButton from '@/Components/PrimaryButton.vue';
import TextInput from '@/Components/TextInput.vue';
import LaverieLogo from '@/Components/LaverieLogo.vue';
import { inputClass, labelClass } from '@/Components/Supervisor/ui.js';
import { Head, useForm } from '@inertiajs/vue3';
defineProps({
@@ -29,65 +29,60 @@ const submit = () => {
<template>
<Head title="Connexion superviseur" />
<div class="flex min-h-screen flex-col items-center justify-center bg-gray-100 px-4">
<div class="flex min-h-screen flex-col items-center justify-center bg-gradient-to-br from-slate-900 via-slate-900 to-indigo-950 px-4 py-12">
<div class="mb-8 text-center">
<h1 class="text-2xl font-bold text-gray-900">Laverie Back-office</h1>
<p class="mt-1 text-sm text-gray-600">Connexion exploitant</p>
<div class="mx-auto mb-4 flex h-14 w-14 items-center justify-center rounded-2xl bg-white/10 ring-1 ring-white/20">
<LaverieLogo class="h-8 w-8 text-white" />
</div>
<h1 class="text-2xl font-bold tracking-tight text-white">Laverie</h1>
<p class="mt-1 text-sm text-indigo-200/80">Back-office Connexion exploitant</p>
</div>
<div class="w-full max-w-md overflow-hidden rounded-lg bg-white px-6 py-8 shadow-md">
<div v-if="status" class="mb-4 text-sm font-medium text-green-600">
<div class="w-full max-w-md overflow-hidden rounded-2xl border border-white/10 bg-white p-8 shadow-2xl">
<div v-if="status" class="mb-4 rounded-xl bg-emerald-50 px-4 py-3 text-sm font-medium text-emerald-700">
{{ status }}
</div>
<form @submit.prevent="submit">
<form @submit.prevent="submit" class="space-y-5">
<div>
<InputLabel for="email" value="Adresse e-mail" />
<TextInput
<label for="email" :class="labelClass">Adresse e-mail</label>
<input
id="email"
type="email"
class="mt-1 block w-full"
v-model="form.email"
type="email"
required
autofocus
autocomplete="username"
:class="inputClass"
/>
<InputError class="mt-2" :message="form.errors.email" />
</div>
<div class="mt-4">
<InputLabel for="password" value="Mot de passe" />
<TextInput
<div>
<label for="password" :class="labelClass">Mot de passe</label>
<input
id="password"
type="password"
class="mt-1 block w-full"
v-model="form.password"
type="password"
required
autocomplete="current-password"
:class="inputClass"
/>
<InputError class="mt-2" :message="form.errors.password" />
</div>
<div class="mt-4">
<label class="flex items-center">
<Checkbox name="remember" v-model:checked="form.remember" />
<span class="ms-2 text-sm text-gray-600">Se souvenir de moi</span>
</label>
</div>
<label class="flex items-center gap-2">
<Checkbox name="remember" v-model:checked="form.remember" />
<span class="text-sm text-slate-600">Se souvenir de moi</span>
</label>
<div class="mt-6">
<PrimaryButton
class="w-full justify-center"
:class="{ 'opacity-25': form.processing }"
:disabled="form.processing"
>
Se connecter
</PrimaryButton>
</div>
<PrimaryButton
class="w-full justify-center"
:class="{ 'opacity-50': form.processing }"
:disabled="form.processing"
>
Se connecter
</PrimaryButton>
</form>
</div>
</div>
+148 -122
View File
@@ -1,13 +1,31 @@
<script setup>
import DataTable from '@/Components/Supervisor/DataTable.vue';
import Pagination from '@/Components/Supervisor/Pagination.vue';
import StatusBadge from '@/Components/Supervisor/StatusBadge.vue';
import TableHeaderCell from '@/Components/Supervisor/TableHeaderCell.vue';
import { useListFilters } from '@/Components/Supervisor/useListFilters.js';
import {
bookingStatusColors,
filterInputClass,
filterSelectClass,
getStatusColor,
linkClass,
rowClass,
tdClass,
} from '@/Components/Supervisor/ui.js';
import SupervisorLayout from '@/Layouts/SupervisorLayout.vue';
import { Head, Link, router } from '@inertiajs/vue3';
import { reactive, watch } from 'vue';
import { Head, Link } from '@inertiajs/vue3';
import { computed } from 'vue';
const props = defineProps({
bookings: {
type: Object,
required: true,
},
establishments: {
type: Array,
default: () => [],
},
filters: {
type: Object,
default: () => ({}),
@@ -18,17 +36,19 @@ const props = defineProps({
},
});
const localFilters = reactive({
const { localFilters, toggleSort } = useListFilters('supervisor.bookings.index', {
establishment_id: props.filters.establishment_id ?? '',
user: props.filters.user ?? '',
status: props.filters.status ?? '',
date: props.filters.date ?? '',
});
sort: props.filters.sort ?? 'slot_start',
direction: props.filters.direction ?? 'desc',
per_page: props.filters.per_page ?? 10,
}, { debounceKeys: ['user'] });
watch(localFilters, () => {
router.get(route('supervisor.bookings.index'), localFilters, {
preserveState: true,
replace: true,
});
});
const showEstablishmentFilter = computed(() => props.establishments.length > 1);
const handleSort = (key) => toggleSort(key, ['slot_start', 'booking_fee']);
const formatDate = (iso) => {
if (!iso) return '—';
@@ -40,124 +60,130 @@ const formatDate = (iso) => {
const formatCurrency = (value) =>
new Intl.NumberFormat('fr-FR', { style: 'currency', currency: 'EUR' }).format(value ?? 0);
const statusColor = (status) => {
const colors = {
pending: 'bg-gray-100 text-gray-800',
confirmed: 'bg-blue-100 text-blue-800',
expired: 'bg-orange-100 text-orange-800',
active: 'bg-green-100 text-green-800',
completed: 'bg-indigo-100 text-indigo-800',
cancelled: 'bg-yellow-100 text-yellow-800',
no_show: 'bg-red-100 text-red-800',
};
return colors[status] ?? 'bg-gray-100 text-gray-800';
};
</script>
<template>
<Head title="Réservations" />
<SupervisorLayout title="Réservations">
<div class="mb-6 flex flex-wrap gap-4 rounded-lg bg-white p-4 shadow">
<div>
<label class="block text-xs font-medium text-gray-500">Statut</label>
<select
v-model="localFilters.status"
class="mt-1 block rounded-md border-gray-300 text-sm shadow-sm focus:border-indigo-500 focus:ring-indigo-500"
>
<option value="">Tous</option>
<option v-for="(label, value) in statusOptions" :key="value" :value="value">
{{ label }}
</option>
</select>
</div>
<div>
<label class="block text-xs font-medium text-gray-500">Date</label>
<input
v-model="localFilters.date"
type="date"
class="mt-1 block rounded-md border-gray-300 text-sm shadow-sm focus:border-indigo-500 focus:ring-indigo-500"
/>
</div>
</div>
<div class="overflow-hidden rounded-lg bg-white shadow">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-4 py-3 text-left text-xs font-medium uppercase text-gray-500">Créneau</th>
<th class="px-4 py-3 text-left text-xs font-medium uppercase text-gray-500">Utilisateur</th>
<th class="px-4 py-3 text-left text-xs font-medium uppercase text-gray-500">Machine</th>
<th class="px-4 py-3 text-left text-xs font-medium uppercase text-gray-500">Statut</th>
<th class="px-4 py-3 text-left text-xs font-medium uppercase text-gray-500">Frais</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-100">
<tr v-if="bookings.data.length === 0">
<td colspan="5" class="px-4 py-8 text-center text-sm text-gray-500">
Aucune réservation trouvée.
</td>
</tr>
<tr v-for="booking in bookings.data" :key="booking.uuid" class="hover:bg-gray-50">
<td class="whitespace-nowrap px-4 py-3 text-sm">
<div>{{ formatDate(booking.slot_start) }}</div>
<div class="text-xs text-gray-500"> {{ formatDate(booking.slot_end) }}</div>
</td>
<td class="px-4 py-3 text-sm">
<div class="font-medium text-gray-800">{{ booking.user?.name ?? '—' }}</div>
<div class="text-xs text-gray-500">{{ booking.user?.email }}</div>
</td>
<td class="px-4 py-3 text-sm">
<Link
v-if="booking.machine"
:href="route('supervisor.machines.show', booking.machine.uuid)"
class="text-indigo-600 hover:text-indigo-800"
>
{{ booking.machine.name }}
</Link>
<span v-else></span>
<div v-if="booking.machine?.establishment_name" class="text-xs text-gray-500">
{{ booking.machine.establishment_name }}
</div>
</td>
<td class="px-4 py-3">
<span
class="rounded-full px-2.5 py-0.5 text-xs font-medium"
:class="statusColor(booking.status)"
>
{{ booking.status_label }}
</span>
</td>
<td class="whitespace-nowrap px-4 py-3 text-sm text-gray-600">
{{ formatCurrency(booking.booking_fee) }}
</td>
</tr>
</tbody>
</table>
<div v-if="bookings.links.length > 3" class="flex items-center justify-between border-t px-4 py-3">
<p class="text-sm text-gray-600">
{{ bookings.from ?? 0 }}{{ bookings.to ?? 0 }} sur {{ bookings.total }}
</p>
<div class="flex gap-1">
<Link
v-for="link in bookings.links"
:key="link.label"
:href="link.url"
v-html="link.label"
class="rounded px-3 py-1 text-sm"
:class="
link.active
? 'bg-indigo-600 text-white'
: link.url
? 'text-gray-600 hover:bg-gray-100'
: 'cursor-not-allowed text-gray-300'
"
preserve-state
<DataTable>
<template #head>
<tr>
<TableHeaderCell
label="Créneau"
sortable
sort-key="slot_start"
:active-sort="localFilters.sort"
:sort-direction="localFilters.direction"
@sort="handleSort"
>
<input v-model="localFilters.date" type="date" :class="filterInputClass" />
</TableHeaderCell>
<TableHeaderCell
label="Utilisateur"
sortable
sort-key="user"
:active-sort="localFilters.sort"
:sort-direction="localFilters.direction"
@sort="handleSort"
>
<input
v-model="localFilters.user"
type="text"
placeholder="Nom ou e-mail…"
:class="filterInputClass"
/>
</TableHeaderCell>
<TableHeaderCell
label="Machine"
sortable
sort-key="machine"
:active-sort="localFilters.sort"
:sort-direction="localFilters.direction"
@sort="handleSort"
>
<select
v-if="showEstablishmentFilter"
v-model="localFilters.establishment_id"
:class="filterSelectClass"
>
<option value="">Toutes</option>
<option v-for="est in establishments" :key="est.id" :value="est.id">
{{ est.name }}
</option>
</select>
</TableHeaderCell>
<TableHeaderCell
label="Statut"
sortable
sort-key="status"
:active-sort="localFilters.sort"
:sort-direction="localFilters.direction"
@sort="handleSort"
>
<select v-model="localFilters.status" :class="filterSelectClass">
<option value="">Tous</option>
<option v-for="(label, value) in statusOptions" :key="value" :value="value">
{{ label }}
</option>
</select>
</TableHeaderCell>
<TableHeaderCell
label="Frais"
sortable
sort-key="booking_fee"
:active-sort="localFilters.sort"
:sort-direction="localFilters.direction"
@sort="handleSort"
/>
</div>
</div>
</div>
</tr>
</template>
<tr v-if="bookings.data.length === 0">
<td colspan="5" class="px-6 py-12 text-center text-sm text-slate-400">
Aucune réservation trouvée.
</td>
</tr>
<tr v-for="booking in bookings.data" :key="booking.uuid" :class="rowClass">
<td :class="tdClass">
<div class="font-medium text-slate-800">{{ formatDate(booking.slot_start) }}</div>
<div class="mt-0.5 text-xs text-slate-400"> {{ formatDate(booking.slot_end) }}</div>
</td>
<td :class="tdClass">
<div class="font-medium text-slate-800">{{ booking.user?.name ?? '—' }}</div>
<div class="text-xs text-slate-400">{{ booking.user?.email }}</div>
</td>
<td :class="tdClass">
<Link
v-if="booking.machine"
:href="route('supervisor.machines.show', booking.machine.uuid)"
:class="linkClass"
>
{{ booking.machine.name }}
</Link>
<span v-else></span>
<div v-if="booking.machine?.establishment_name" class="mt-0.5 text-xs text-slate-400">
{{ booking.machine.establishment_name }}
</div>
</td>
<td :class="tdClass">
<StatusBadge
:label="booking.status_label"
:color-class="getStatusColor(booking.status, bookingStatusColors)"
/>
</td>
<td :class="[tdClass, 'font-semibold text-slate-800']">
{{ formatCurrency(booking.booking_fee) }}
</td>
</tr>
<template #footer>
<Pagination
:paginator="bookings"
:per-page="localFilters.per_page"
@update:per-page="(value) => { localFilters.per_page = value; }"
/>
</template>
</DataTable>
</SupervisorLayout>
</template>
+486 -72
View File
@@ -1,8 +1,10 @@
<script setup>
import SupervisorLayout from '@/Layouts/SupervisorLayout.vue';
import { Head, Link } from '@inertiajs/vue3';
import OutlineSelect from '@/Components/Supervisor/OutlineSelect.vue';
import {Head, Link, router, usePage} from '@inertiajs/vue3';
import {computed, ref, watch} from 'vue';
defineProps({
const props = defineProps({
kpis: {
type: Object,
required: true,
@@ -15,10 +17,94 @@ defineProps({
type: Array,
default: () => [],
},
machineStatusBreakdown: {
type: Object,
default: () => ({}),
},
recentWashes: {
type: Array,
default: () => [],
},
context: {
type: Object,
default: () => ({}),
},
establishments: {
type: Array,
default: () => [],
},
showEstablishmentFilter: {
type: Boolean,
default: false,
},
filters: {
type: Object,
default: () => ({}),
},
});
const page = usePage();
const supervisor = computed(() => page.props.auth.supervisor);
const greeting = computed(() => {
const hour = new Date().getHours();
if (hour < 12) return 'Bonjour';
if (hour < 18) return 'Bon après-midi';
return 'Bonsoir';
});
const todayLabel = computed(() => {
const formatted = new Intl.DateTimeFormat('fr-FR', {
weekday: 'long',
day: 'numeric',
month: 'long',
}).format(new Date());
return formatted.charAt(0).toUpperCase() + formatted.slice(1);
});
const firstName = computed(() => supervisor.value?.name?.split(' ')[0] ?? '');
const scopeTitle = computed(() => {
if (props.context.is_all_establishments) {
return 'Toutes les enseignes';
}
return props.context.establishment_name ?? 'Enseigne sélectionnée';
});
const establishmentOptions = computed(() => [
{ value: '', label: 'Toutes les enseignes' },
...props.establishments.map((establishment) => ({
value: establishment.id,
label: establishment.name,
})),
]);
const selectedEstablishmentId = ref(props.filters.establishment_id ?? '');
watch(
() => props.filters.establishment_id,
(value) => {
selectedEstablishmentId.value = value ?? '';
},
);
const onEstablishmentChange = () => {
router.get(
route('supervisor.dashboard'),
{
establishment_id: selectedEstablishmentId.value || undefined,
},
{
preserveScroll: true,
replace: true,
},
);
};
const formatCurrency = (value) =>
new Intl.NumberFormat('fr-FR', { style: 'currency', currency: 'EUR' }).format(value ?? 0);
new Intl.NumberFormat('fr-FR', {style: 'currency', currency: 'EUR'}).format(value ?? 0);
const formatDate = (iso) => {
if (!iso) return '—';
@@ -30,110 +116,438 @@ const formatDate = (iso) => {
const statusColor = (status) => {
const colors = {
available: 'bg-green-100 text-green-800',
reserved: 'bg-yellow-100 text-yellow-800',
running: 'bg-blue-100 text-blue-800',
maintenance: 'bg-orange-100 text-orange-800',
offline: 'bg-gray-100 text-gray-800',
error: 'bg-red-100 text-red-800',
available: 'bg-emerald-100 text-emerald-800 ring-emerald-600/20',
reserved: 'bg-amber-100 text-amber-800 ring-amber-600/20',
running: 'bg-sky-100 text-sky-800 ring-sky-600/20',
maintenance: 'bg-orange-100 text-orange-800 ring-orange-600/20',
offline: 'bg-slate-100 text-slate-600 ring-slate-500/20',
error: 'bg-red-100 text-red-800 ring-red-600/20',
pending_start: 'bg-slate-100 text-slate-600 ring-slate-500/20',
completed: 'bg-emerald-100 text-emerald-800 ring-emerald-600/20',
failed: 'bg-red-100 text-red-800 ring-red-600/20',
cancelled: 'bg-slate-100 text-slate-500 ring-slate-500/20',
};
return colors[status] ?? 'bg-gray-100 text-gray-800';
return colors[status] ?? 'bg-slate-100 text-slate-800';
};
const statusDotColor = (status) => {
const colors = {
available: 'bg-emerald-500',
reserved: 'bg-amber-500',
running: 'bg-sky-500',
maintenance: 'bg-orange-500',
offline: 'bg-slate-400',
error: 'bg-red-500',
};
return colors[status] ?? 'bg-slate-400';
};
const severityColor = (severity) => {
return severity === 'high' ? 'border-red-400 bg-red-50' : 'border-yellow-400 bg-yellow-50';
return severity === 'high'
? 'border-red-400 bg-red-50 ring-red-100'
: 'border-amber-400 bg-amber-50 ring-amber-100';
};
const machineAnomalyCount = computed(() => {
const breakdown = props.machineStatusBreakdown;
return (breakdown.offline ?? 0) + (breakdown.maintenance ?? 0) + (breakdown.error ?? 0);
});
const kpiCards = computed(() => {
const hasMachineAnomaly = machineAnomalyCount.value > 0;
return [
{
label: "Chiffre d'affaires",
sublabel: "Aujourd'hui",
value: formatCurrency(props.kpis.revenue_today),
icon: 'revenue',
bg: 'bg-emerald-50',
text: 'text-emerald-600',
ring: 'ring-emerald-100',
},
{
label: 'Lavages',
sublabel: "Aujourd'hui",
value: props.kpis.washes_today,
icon: 'washes',
bg: 'bg-sky-50',
text: 'text-sky-600',
ring: 'ring-sky-100',
},
{
label: 'Réservations',
sublabel: "Aujourd'hui",
value: props.kpis.bookings_today,
icon: 'bookings',
bg: 'bg-violet-50',
text: 'text-violet-600',
ring: 'ring-violet-100',
},
{
label: 'Machines actives',
sublabel: `${props.kpis.running_machines ?? 0} en cours · ${props.kpis.available_machines ?? 0} dispo.`,
value: `${props.kpis.machines_total - machineAnomalyCount.value}`,
suffix: `/ ${props.kpis.machines_total}`,
icon: 'machines',
bg: hasMachineAnomaly ? 'bg-red-50' : 'bg-indigo-50',
text: hasMachineAnomaly ? 'text-red-600' : 'text-indigo-600',
ring: hasMachineAnomaly ? 'ring-red-100' : 'ring-indigo-100',
alert: hasMachineAnomaly ? `${machineAnomalyCount.value} indisponible${machineAnomalyCount.value > 1 ? 's' : ''}` : null,
},
];
});
const statusBreakdownItems = computed(() => {
const labels = {
available: 'Disponibles',
reserved: 'Réservées',
running: 'En cours',
maintenance: 'Maintenance',
offline: 'Hors ligne',
error: 'Erreur',
};
const total = props.kpis.machines_total || 1;
return Object.entries(props.machineStatusBreakdown)
.filter(([, count]) => count > 0)
.map(([status, count]) => ({
status,
label: labels[status] ?? status,
count,
percent: Math.round((count / total) * 100),
}))
.sort((a, b) => b.count - a.count);
});
const quickActions = [
{
label: 'Voir les machines',
route: 'supervisor.machines.index',
icon: 'machines',
color: 'hover:border-indigo-300 hover:bg-indigo-50'
},
{
label: 'Réservations du jour',
route: 'supervisor.bookings.index',
icon: 'bookings',
color: 'hover:border-violet-300 hover:bg-violet-50'
},
{
label: 'Historique lavages',
route: 'supervisor.washes.index',
icon: 'washes',
color: 'hover:border-sky-300 hover:bg-sky-50'
},
{
label: 'Gérer les tarifs',
route: 'supervisor.pricing.index',
icon: 'pricing',
color: 'hover:border-emerald-300 hover:bg-emerald-50'
},
];
const kpiIconPaths = {
revenue: 'M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z',
washes: 'M5 3v4M3 5h4M6 17v4m-2-2h4m5-16l2.286 6.857L21 12l-5.714 2.143L13 21l-2.286-6.857L5 12l5.714-2.143L13 3z',
bookings: 'M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z',
machines: 'M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15',
pricing: 'M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z',
};
</script>
<template>
<Head title="Tableau de bord" />
<Head title="Tableau de bord"/>
<SupervisorLayout title="Tableau de bord">
<!-- KPI cards -->
<div class="grid grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-4">
<div class="rounded-lg bg-white p-5 shadow">
<p class="text-sm font-medium text-gray-500">Chiffre d'affaires aujourd'hui</p>
<p class="mt-2 text-2xl font-bold text-gray-900">
{{ formatCurrency(kpis.revenue_today) }}
</p>
<SupervisorLayout>
<template #header>
<span class="hidden text-sm text-slate-400 sm:inline">/</span>
<span class="hidden text-sm text-slate-500 sm:inline">Tableau de bord</span>
</template>
<!-- Welcome banner -->
<div
class="relative overflow-visible rounded-2xl border border-indigo-500/20 bg-gradient-to-br from-slate-900 via-indigo-950 to-indigo-900 shadow-xl shadow-indigo-950/20">
<!-- Décorations (clipées sans couper le sélecteur) -->
<div class="pointer-events-none absolute inset-0 overflow-hidden rounded-2xl">
<div
class="absolute inset-0 opacity-[0.35]"
style="background-image: radial-gradient(circle at 1px 1px, rgb(255 255 255 / 0.08) 1px, transparent 0); background-size: 24px 24px;"
/>
<div class="absolute -right-16 -top-16 h-56 w-56 rounded-full bg-indigo-500/25 blur-3xl"/>
<div class="absolute -bottom-20 -left-10 h-48 w-48 rounded-full bg-violet-600/20 blur-3xl"/>
</div>
<div class="rounded-lg bg-white p-5 shadow">
<p class="text-sm font-medium text-gray-500">Lavages aujourd'hui</p>
<p class="mt-2 text-2xl font-bold text-gray-900">{{ kpis.washes_today }}</p>
</div>
<div class="rounded-lg bg-white p-5 shadow">
<p class="text-sm font-medium text-gray-500">Réservations aujourd'hui</p>
<p class="mt-2 text-2xl font-bold text-gray-900">{{ kpis.bookings_today }}</p>
</div>
<div class="rounded-lg bg-white p-5 shadow">
<p class="text-sm font-medium text-gray-500">Machines hors ligne</p>
<p class="mt-2 text-2xl font-bold" :class="kpis.offline_machines > 0 ? 'text-red-600' : 'text-gray-900'">
{{ kpis.offline_machines }}
<span class="text-sm font-normal text-gray-500">/ {{ kpis.machines_total }}</span>
</p>
<div class="relative flex flex-col gap-6 p-6 sm:p-8 lg:flex-row lg:items-center lg:justify-between">
<div class="flex min-w-0 items-start gap-4 sm:gap-5">
<div class="min-w-0">
<p class="inline-flex items-center rounded-full bg-white/10 px-3 py-1 text-xs font-medium text-indigo-200 ring-1 ring-white/10">
{{ todayLabel }}
</p>
<h2 class="mt-3 text-2xl font-bold tracking-tight text-white sm:text-3xl">
{{ greeting }}<span v-if="firstName">, {{ firstName }}</span>
</h2>
<div class="mt-4 flex flex-wrap items-center gap-2">
<span
class="inline-flex items-center gap-2 rounded-xl bg-white/10 px-3 py-1.5 text-sm font-medium text-white ring-1 ring-white/10">
<svg class="h-4 w-4 shrink-0 text-indigo-300" fill="none" viewBox="0 0 24 24"
stroke="currentColor" stroke-width="1.75">
<path stroke-linecap="round" stroke-linejoin="round"
d="M15 10.5a3 3 0 11-6 0 3 3 0 016 0z"/>
<path stroke-linecap="round" stroke-linejoin="round"
d="M19.5 10.5c0 7.142-7.5 11.25-7.5 11.25S4.5 17.642 4.5 10.5a7.5 7.5 0 1115 0z"/>
</svg>
<span class="truncate">{{ scopeTitle }}</span>
</span>
<span
v-if="kpis.active_bookings > 0"
class="inline-flex items-center gap-1.5 rounded-xl bg-amber-400/15 px-3 py-1.5 text-sm font-medium text-amber-100 ring-1 ring-amber-300/20"
>
<span class="h-1.5 w-1.5 animate-pulse rounded-full bg-amber-300"/>
{{ kpis.active_bookings }} réservation{{ kpis.active_bookings > 1 ? 's' : '' }} en cours
</span>
</div>
</div>
</div>
<div v-if="showEstablishmentFilter" class="relative z-20 w-full shrink-0 lg:w-72">
<OutlineSelect
id="dashboard-establishment"
v-model="selectedEstablishmentId"
:options="establishmentOptions"
variant="dark"
@change="onEstablishmentChange"
/>
</div>
</div>
</div>
<div class="mt-8 grid grid-cols-1 gap-6 lg:grid-cols-2">
<!-- Alerts -->
<div class="rounded-lg bg-white p-5 shadow">
<h2 class="mb-4 text-lg font-semibold text-gray-800">Alertes</h2>
<div v-if="alerts.length === 0" class="text-sm text-gray-500">
Aucune alerte pour le moment.
<!-- KPI cards -->
<div class="mt-6 grid grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-4">
<div
v-for="card in kpiCards"
:key="card.label"
class="rounded-2xl border border-slate-200/80 bg-white p-4 shadow-sm transition hover:shadow-md sm:p-5"
>
<div class="flex items-center gap-4">
<!-- Icône à gauche -->
<div
class="flex h-14 w-14 flex-shrink-0 items-center justify-center rounded-2xl ring-4"
:class="[card.bg, card.ring]"
>
<svg
class="h-7 w-7"
:class="card.text"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
stroke-width="1.75"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
:d="kpiIconPaths[card.icon]"
/>
</svg>
</div>
<!-- Chiffres à droite -->
<div class="min-w-0 flex-1 text-right">
<p class="text-sm font-medium text-slate-500">{{ card.label }}</p>
<p class="mt-0.5 flex items-baseline justify-end gap-1">
<span class="text-2xl font-bold tracking-tight text-slate-900">{{ card.value }}</span>
<span v-if="card.suffix" class="text-base font-normal text-slate-400">{{
card.suffix
}}</span>
</p>
<p class="mt-0.5 text-xs text-slate-400">{{ card.sublabel }}</p>
<p
v-if="card.alert"
class="mt-1.5 inline-flex items-center gap-1 rounded-full bg-red-100 px-2 py-0.5 text-xs font-medium text-red-700"
>
<span class="h-1.5 w-1.5 rounded-full bg-red-500"/>
{{ card.alert }}
</p>
</div>
</div>
<ul v-else class="space-y-3">
</div>
</div>
<!-- Quick actions -->
<div class="mt-6">
<h3 class="mb-3 text-sm font-semibold uppercase tracking-wider text-slate-400">Accès rapides</h3>
<div class="grid grid-cols-2 gap-3 sm:grid-cols-4">
<Link
v-for="action in quickActions"
:key="action.route"
:href="route(action.route)"
class="flex items-center gap-3 rounded-xl border border-slate-200 bg-white px-4 py-3 text-sm font-medium text-slate-700 shadow-sm transition"
:class="action.color"
>
<svg class="h-4 w-4 flex-shrink-0 text-slate-400" fill="none" viewBox="0 0 24 24"
stroke="currentColor" stroke-width="1.75">
<path stroke-linecap="round" stroke-linejoin="round" :d="kpiIconPaths[action.icon]"/>
</svg>
{{ action.label }}
</Link>
</div>
</div>
<div class="mt-8 grid grid-cols-1 gap-6 lg:grid-cols-3">
<!-- Machine status breakdown -->
<div class="rounded-2xl border border-slate-200/80 bg-white p-5 shadow-sm lg:col-span-1">
<h2 class="text-base font-semibold text-slate-900">État du parc</h2>
<p class="mt-0.5 text-sm text-slate-500">{{ kpis.machines_total }}
machine{{ kpis.machines_total > 1 ? 's' : '' }} au total</p>
<div v-if="statusBreakdownItems.length === 0" class="mt-6 text-sm text-slate-400">
Aucune machine dans votre périmètre.
</div>
<div v-else class="mt-5 space-y-3">
<div v-for="item in statusBreakdownItems" :key="item.status">
<div class="mb-1 flex items-center justify-between text-sm">
<span class="flex items-center gap-2 text-slate-600">
<span class="h-2 w-2 rounded-full" :class="statusDotColor(item.status)"/>
{{ item.label }}
</span>
<span class="font-medium text-slate-900">{{ item.count }}</span>
</div>
<div class="h-2 overflow-hidden rounded-full bg-slate-100">
<div
class="h-full rounded-full transition-all duration-500"
:class="statusDotColor(item.status)"
:style="{ width: `${item.percent}%` }"
/>
</div>
</div>
</div>
</div>
<!-- Alerts -->
<div class="rounded-2xl border border-slate-200/80 bg-white p-5 shadow-sm lg:col-span-1">
<div class="flex items-center justify-between">
<h2 class="text-base font-semibold text-slate-900">Alertes</h2>
<span
v-if="alerts.length > 0"
class="rounded-full bg-red-100 px-2 py-0.5 text-xs font-medium text-red-700"
>
{{ alerts.length }}
</span>
</div>
<div v-if="alerts.length === 0" class="mt-8 flex flex-col items-center py-4 text-center">
<div class="flex h-12 w-12 items-center justify-center rounded-full bg-emerald-50">
<svg class="h-6 w-6 text-emerald-500" fill="none" viewBox="0 0 24 24" stroke="currentColor"
stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7"/>
</svg>
</div>
<p class="mt-3 text-sm font-medium text-slate-600">Tout va bien</p>
<p class="mt-1 text-xs text-slate-400">Aucune alerte pour le moment.</p>
</div>
<ul v-else class="mt-4 max-h-72 space-y-2 overflow-y-auto">
<li
v-for="(alert, index) in alerts"
:key="index"
class="rounded-md border-l-4 px-3 py-2 text-sm"
class="rounded-xl border-l-4 px-3 py-2.5 text-sm ring-1 ring-inset"
:class="severityColor(alert.severity)"
>
<p class="font-medium text-gray-800">{{ alert.message }}</p>
<p class="mt-1 text-xs text-gray-500">{{ formatDate(alert.occurred_at) }}</p>
<p class="font-medium text-slate-800">{{ alert.message }}</p>
<p class="mt-1 text-xs text-slate-500">{{ formatDate(alert.occurred_at) }}</p>
</li>
</ul>
</div>
<!-- Machines overview -->
<div class="rounded-lg bg-white p-5 shadow">
<div class="mb-4 flex items-center justify-between">
<h2 class="text-lg font-semibold text-gray-800">Parc machines</h2>
<!-- Recent washes -->
<div class="rounded-2xl border border-slate-200/80 bg-white p-5 shadow-sm lg:col-span-1">
<div class="flex items-center justify-between">
<h2 class="text-base font-semibold text-slate-900">Derniers lavages</h2>
<Link
:href="route('supervisor.machines.index')"
class="text-sm text-indigo-600 hover:text-indigo-800"
:href="route('supervisor.washes.index')"
class="text-xs font-medium text-indigo-600 hover:text-indigo-800"
>
Voir tout
Tout voir
</Link>
</div>
<div v-if="machinesOverview.length === 0" class="text-sm text-gray-500">
Aucune machine dans votre périmètre.
<div v-if="recentWashes.length === 0" class="mt-6 text-sm text-slate-400">
Aucun lavage récent.
</div>
<ul v-else class="divide-y divide-gray-100">
<ul v-else class="mt-4 divide-y divide-slate-100">
<li
v-for="machine in machinesOverview"
:key="machine.uuid"
class="flex items-center justify-between py-3"
v-for="wash in recentWashes"
:key="wash.uuid"
class="flex items-center justify-between py-3 first:pt-0"
>
<div>
<Link
:href="route('supervisor.machines.show', machine.uuid)"
class="font-medium text-gray-800 hover:text-indigo-600"
>
{{ machine.name }}
</Link>
<p class="text-xs text-gray-500">
{{ machine.establishment_name }} · {{ machine.type_label }}
<div class="min-w-0">
<p class="truncate text-sm font-medium text-slate-800">{{ wash.machine_name }}</p>
<p class="truncate text-xs text-slate-400">
{{ wash.establishment_name }} · {{ formatDate(wash.started_at) }}
</p>
</div>
<span
class="rounded-full px-2.5 py-0.5 text-xs font-medium"
:class="statusColor(machine.status)"
>
{{ machine.status_label }}
</span>
<div class="ml-3 flex-shrink-0 text-right">
<p class="text-sm font-semibold text-slate-900">{{ formatCurrency(wash.cost) }}</p>
<span
class="mt-0.5 inline-block rounded-full px-2 py-0.5 text-[10px] font-medium ring-1 ring-inset"
:class="statusColor(wash.status)"
>
{{ wash.status_label }}
</span>
</div>
</li>
</ul>
</div>
</div>
<!-- Machines overview -->
<div class="mt-6 rounded-2xl border border-slate-200/80 bg-white p-5 shadow-sm">
<div class="mb-4 flex items-center justify-between">
<div>
<h2 class="text-base font-semibold text-slate-900">Parc machines</h2>
<p class="mt-0.5 text-sm text-slate-500">Aperçu en temps réel de vos équipements</p>
</div>
<Link
:href="route('supervisor.machines.index')"
class="rounded-lg bg-indigo-50 px-3 py-1.5 text-sm font-medium text-indigo-700 transition hover:bg-indigo-100"
>
Gérer le parc
</Link>
</div>
<div v-if="machinesOverview.length === 0" class="py-8 text-center text-sm text-slate-400">
Aucune machine dans votre périmètre.
</div>
<div v-else class="grid grid-cols-1 gap-3 sm:grid-cols-2 xl:grid-cols-3">
<Link
v-for="machine in machinesOverview"
:key="machine.uuid"
:href="route('supervisor.machines.show', machine.uuid)"
class="group flex items-center gap-3 rounded-xl border border-slate-200 p-4 transition hover:border-indigo-200 hover:bg-indigo-50/30 hover:shadow-sm"
>
<div
class="flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-lg bg-slate-100 transition group-hover:bg-white"
>
<span class="h-2.5 w-2.5 rounded-full" :class="statusDotColor(machine.status)"/>
</div>
<div class="min-w-0 flex-1">
<p class="truncate text-sm font-medium text-slate-800 group-hover:text-indigo-700">
{{ machine.name }}
</p>
<p class="truncate text-xs text-slate-400">
{{ machine.establishment_name }} · {{ machine.type_label }}
</p>
</div>
<span
class="flex-shrink-0 rounded-full px-2.5 py-0.5 text-xs font-medium ring-1 ring-inset"
:class="statusColor(machine.status)"
>
{{ machine.status_label }}
</span>
</Link>
</div>
</div>
</SupervisorLayout>
</template>
+287 -138
View File
@@ -1,13 +1,42 @@
<script setup>
import AlertBanner from '@/Components/Supervisor/AlertBanner.vue';
import DataTable from '@/Components/Supervisor/DataTable.vue';
import FormField from '@/Components/Supervisor/FormField.vue';
import FormModal from '@/Components/Supervisor/FormModal.vue';
import Pagination from '@/Components/Supervisor/Pagination.vue';
import StatusBadge from '@/Components/Supervisor/StatusBadge.vue';
import TableHeaderCell from '@/Components/Supervisor/TableHeaderCell.vue';
import { useListFilters } from '@/Components/Supervisor/useListFilters.js';
import {
filterInputClass,
filterSelectClass,
getStatusColor,
inputClass,
linkClass,
machineStatusColors,
rowClass,
selectClass,
tdClass,
} from '@/Components/Supervisor/ui.js';
import ConfirmDeleteModal from '@/Components/ConfirmDeleteModal.vue';
import PrimaryButton from '@/Components/PrimaryButton.vue';
import SupervisorLayout from '@/Layouts/SupervisorLayout.vue';
import { Head, Link, router } from '@inertiajs/vue3';
import { reactive, watch } from 'vue';
import { Head, Link, useForm, usePage } from '@inertiajs/vue3';
import { ref, computed } from 'vue';
const props = defineProps({
machines: {
type: Object,
required: true,
},
establishments: {
type: Array,
default: () => [],
},
canManageMachines: {
type: Boolean,
default: false,
},
filters: {
type: Object,
default: () => ({}),
@@ -22,34 +51,93 @@ const props = defineProps({
},
});
const localFilters = reactive({
const page = usePage();
const editingUuid = ref(null);
const showForm = ref(false);
const deleteTarget = ref(null);
const deleteForm = useForm({});
const { localFilters, toggleSort } = useListFilters('supervisor.machines.index', {
establishment_id: props.filters.establishment_id ?? '',
search: props.filters.search ?? '',
status: props.filters.status ?? '',
type: props.filters.type ?? '',
sort: props.filters.sort ?? 'name',
direction: props.filters.direction ?? 'asc',
per_page: props.filters.per_page ?? 10,
}, { debounceKeys: ['search'] });
const showEstablishmentFilter = computed(() => props.establishments.length > 1);
const handleSort = (key) => toggleSort(key, ['last_heartbeat_at']);
const emptyForm = () => ({
establishment_id: props.establishments[0]?.id ?? '',
name: '',
type: '',
qr_code: '',
status: 'available',
});
let debounceTimer = null;
const form = useForm(emptyForm());
watch(localFilters, () => {
clearTimeout(debounceTimer);
debounceTimer = setTimeout(() => {
router.get(route('supervisor.machines.index'), localFilters, {
preserveState: true,
replace: true,
});
}, 300);
});
const startCreate = () => {
editingUuid.value = null;
form.defaults(emptyForm());
form.reset();
showForm.value = true;
};
const statusColor = (status) => {
const colors = {
available: 'bg-green-100 text-green-800',
reserved: 'bg-yellow-100 text-yellow-800',
running: 'bg-blue-100 text-blue-800',
maintenance: 'bg-orange-100 text-orange-800',
offline: 'bg-gray-100 text-gray-800',
error: 'bg-red-100 text-red-800',
const startEdit = (machine) => {
editingUuid.value = machine.uuid;
form.defaults({
establishment_id: machine.establishment_id,
name: machine.name,
type: machine.type,
qr_code: machine.qr_code,
status: machine.status,
});
form.reset();
showForm.value = true;
};
const cancelForm = () => {
showForm.value = false;
editingUuid.value = null;
form.reset();
};
const submit = () => {
const payload = {
...form.data(),
qr_code: form.qr_code || null,
};
return colors[status] ?? 'bg-gray-100 text-gray-800';
if (editingUuid.value) {
form.transform(() => payload).put(route('supervisor.machines.update', editingUuid.value), {
onSuccess: cancelForm,
});
} else {
form.transform(() => payload).post(route('supervisor.machines.store'), {
onSuccess: cancelForm,
});
}
};
const openDeleteModal = (machine) => {
deleteTarget.value = machine;
};
const closeDeleteModal = () => {
deleteTarget.value = null;
};
const confirmDelete = () => {
if (!deleteTarget.value) return;
deleteForm.delete(route('supervisor.machines.destroy', deleteTarget.value.uuid), {
onSuccess: closeDeleteModal,
});
};
const formatDate = (iso) => {
@@ -65,124 +153,185 @@ const formatDate = (iso) => {
<Head title="Machines" />
<SupervisorLayout title="Machines">
<!-- Filters -->
<div class="mb-6 flex flex-wrap gap-4 rounded-lg bg-white p-4 shadow">
<div class="min-w-[200px] flex-1">
<label class="block text-xs font-medium text-gray-500">Recherche</label>
<input
v-model="localFilters.search"
type="text"
placeholder="Nom ou QR code…"
class="mt-1 block w-full rounded-md border-gray-300 text-sm shadow-sm focus:border-indigo-500 focus:ring-indigo-500"
/>
</div>
<div>
<label class="block text-xs font-medium text-gray-500">Statut</label>
<select
v-model="localFilters.status"
class="mt-1 block w-full rounded-md border-gray-300 text-sm shadow-sm focus:border-indigo-500 focus:ring-indigo-500"
>
<option value="">Tous</option>
<option v-for="(label, value) in statusOptions" :key="value" :value="value">
{{ label }}
</option>
</select>
</div>
<div>
<label class="block text-xs font-medium text-gray-500">Type</label>
<select
v-model="localFilters.type"
class="mt-1 block w-full rounded-md border-gray-300 text-sm shadow-sm focus:border-indigo-500 focus:ring-indigo-500"
>
<option value="">Tous</option>
<option v-for="(label, value) in typeOptions" :key="value" :value="value">
{{ label }}
</option>
</select>
</div>
</div>
<template #actions>
<PrimaryButton
v-if="canManageMachines && establishments.length > 0"
@click="startCreate"
>
Nouvelle machine
</PrimaryButton>
</template>
<!-- Table -->
<div class="overflow-hidden rounded-lg bg-white shadow">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-4 py-3 text-left text-xs font-medium uppercase tracking-wider text-gray-500">
Machine
</th>
<th class="px-4 py-3 text-left text-xs font-medium uppercase tracking-wider text-gray-500">
Établissement
</th>
<th class="px-4 py-3 text-left text-xs font-medium uppercase tracking-wider text-gray-500">
Type
</th>
<th class="px-4 py-3 text-left text-xs font-medium uppercase tracking-wider text-gray-500">
Statut
</th>
<th class="px-4 py-3 text-left text-xs font-medium uppercase tracking-wider text-gray-500">
Dernier signal
</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-100 bg-white">
<tr v-if="machines.data.length === 0">
<td colspan="5" class="px-4 py-8 text-center text-sm text-gray-500">
Aucune machine trouvée.
</td>
</tr>
<tr v-for="machine in machines.data" :key="machine.uuid" class="hover:bg-gray-50">
<td class="whitespace-nowrap px-4 py-3">
<Link
:href="route('supervisor.machines.show', machine.uuid)"
class="font-medium text-indigo-600 hover:text-indigo-800"
>
{{ machine.name }}
</Link>
</td>
<td class="whitespace-nowrap px-4 py-3 text-sm text-gray-600">
{{ machine.establishment_name ?? '—' }}
</td>
<td class="whitespace-nowrap px-4 py-3 text-sm text-gray-600">
{{ machine.type_label }}
</td>
<td class="whitespace-nowrap px-4 py-3">
<span
class="rounded-full px-2.5 py-0.5 text-xs font-medium"
:class="statusColor(machine.status)"
>
{{ machine.status_label }}
</span>
</td>
<td class="whitespace-nowrap px-4 py-3 text-sm text-gray-500">
{{ formatDate(machine.last_heartbeat_at) }}
</td>
</tr>
</tbody>
</table>
<AlertBanner v-if="page.props.errors?.delete">
{{ page.props.errors.delete }}
</AlertBanner>
<!-- Pagination -->
<div v-if="machines.links.length > 3" class="flex items-center justify-between border-t px-4 py-3">
<p class="text-sm text-gray-600">
{{ machines.from ?? 0 }}{{ machines.to ?? 0 }} sur {{ machines.total }}
</p>
<div class="flex gap-1">
<Link
v-for="link in machines.links"
:key="link.label"
:href="link.url"
v-html="link.label"
class="rounded px-3 py-1 text-sm"
:class="
link.active
? 'bg-indigo-600 text-white'
: link.url
? 'text-gray-600 hover:bg-gray-100'
: 'cursor-not-allowed text-gray-300'
"
preserve-state
<FormModal
:show="showForm"
:title="editingUuid ? 'Modifier la machine' : 'Nouvelle machine'"
:submit-label="editingUuid ? 'Enregistrer' : 'Créer'"
:processing="form.processing"
@close="cancelForm"
@submit="submit"
>
<div class="grid grid-cols-1 gap-4 sm:grid-cols-2">
<FormField label="Enseigne">
<select v-model="form.establishment_id" required :class="selectClass">
<option v-for="est in establishments" :key="est.id" :value="est.id">
{{ est.name }}
</option>
</select>
</FormField>
<FormField label="Nom">
<input v-model="form.name" type="text" required :class="inputClass" />
</FormField>
<FormField label="Type">
<select v-model="form.type" required :class="selectClass">
<option value="" disabled>Sélectionner</option>
<option v-for="(label, value) in typeOptions" :key="value" :value="value">
{{ label }}
</option>
</select>
</FormField>
<FormField label="QR code" :hint="editingUuid ? '' : 'Généré automatiquement si vide'">
<input v-model="form.qr_code" type="text" :class="inputClass" />
</FormField>
<FormField label="Statut">
<select v-model="form.status" required :class="selectClass">
<option v-for="(label, value) in statusOptions" :key="value" :value="value">
{{ label }}
</option>
</select>
</FormField>
</div>
</FormModal>
<DataTable>
<template #head>
<tr>
<TableHeaderCell
label="Machine"
sortable
sort-key="name"
:active-sort="localFilters.sort"
:sort-direction="localFilters.direction"
@sort="handleSort"
>
<input
v-model="localFilters.search"
type="text"
placeholder="Nom ou QR…"
:class="filterInputClass"
/>
</TableHeaderCell>
<TableHeaderCell
label="Enseigne"
sortable
sort-key="establishment"
:active-sort="localFilters.sort"
:sort-direction="localFilters.direction"
@sort="handleSort"
>
<select
v-if="showEstablishmentFilter"
v-model="localFilters.establishment_id"
:class="filterSelectClass"
>
<option value="">Toutes</option>
<option v-for="est in establishments" :key="est.id" :value="est.id">
{{ est.name }}
</option>
</select>
</TableHeaderCell>
<TableHeaderCell
label="Type"
sortable
sort-key="type"
:active-sort="localFilters.sort"
:sort-direction="localFilters.direction"
@sort="handleSort"
>
<select v-model="localFilters.type" :class="filterSelectClass">
<option value="">Tous</option>
<option v-for="(label, value) in typeOptions" :key="value" :value="value">
{{ label }}
</option>
</select>
</TableHeaderCell>
<TableHeaderCell
label="Statut"
sortable
sort-key="status"
:active-sort="localFilters.sort"
:sort-direction="localFilters.direction"
@sort="handleSort"
>
<select v-model="localFilters.status" :class="filterSelectClass">
<option value="">Tous</option>
<option v-for="(label, value) in statusOptions" :key="value" :value="value">
{{ label }}
</option>
</select>
</TableHeaderCell>
<TableHeaderCell
label="Dernier signal"
sortable
sort-key="last_heartbeat_at"
:active-sort="localFilters.sort"
:sort-direction="localFilters.direction"
@sort="handleSort"
/>
</div>
</div>
</div>
<TableHeaderCell v-if="canManageMachines" label="Actions" align="right" />
</tr>
</template>
<tr v-if="machines.data.length === 0">
<td :colspan="canManageMachines ? 6 : 5" class="px-6 py-12 text-center text-sm text-slate-400">
Aucune machine trouvée.
</td>
</tr>
<tr v-for="machine in machines.data" :key="machine.uuid" :class="rowClass">
<td :class="tdClass">
<Link :href="route('supervisor.machines.show', machine.uuid)" :class="linkClass">
{{ machine.name }}
</Link>
<p class="mt-0.5 font-mono text-xs text-slate-400">{{ machine.qr_code }}</p>
</td>
<td :class="tdClass">{{ machine.establishment_name ?? '—' }}</td>
<td :class="tdClass">{{ machine.type_label }}</td>
<td :class="tdClass">
<StatusBadge
:label="machine.status_label"
:color-class="getStatusColor(machine.status, machineStatusColors)"
/>
</td>
<td :class="tdClass">{{ formatDate(machine.last_heartbeat_at) }}</td>
<td v-if="canManageMachines" :class="[tdClass, 'text-right']">
<button class="font-medium text-indigo-600 transition hover:text-indigo-800" @click="startEdit(machine)">
Modifier
</button>
<button class="ms-3 font-medium text-red-600 transition hover:text-red-800" @click="openDeleteModal(machine)">
Supprimer
</button>
</td>
</tr>
<template #footer>
<Pagination
:paginator="machines"
:per-page="localFilters.per_page"
@update:per-page="(value) => { localFilters.per_page = value; }"
/>
</template>
</DataTable>
<ConfirmDeleteModal
:show="deleteTarget !== null"
title="Supprimer la machine"
:message="deleteTarget ? `Voulez-vous supprimer « ${deleteTarget.name} » ?` : ''"
:processing="deleteForm.processing"
@close="closeDeleteModal"
@confirm="confirmDelete"
/>
</SupervisorLayout>
</template>
+58 -70
View File
@@ -1,4 +1,6 @@
<script setup>
import StatusBadge from '@/Components/Supervisor/StatusBadge.vue';
import { cardClass, getStatusColor, machineStatusColors } from '@/Components/Supervisor/ui.js';
import SupervisorLayout from '@/Layouts/SupervisorLayout.vue';
import { Head, Link } from '@inertiajs/vue3';
@@ -20,18 +22,6 @@ const formatDate = (iso) => {
timeStyle: 'short',
}).format(new Date(iso));
};
const statusColor = (status) => {
const colors = {
available: 'bg-green-100 text-green-800',
reserved: 'bg-yellow-100 text-yellow-800',
running: 'bg-blue-100 text-blue-800',
maintenance: 'bg-orange-100 text-orange-800',
offline: 'bg-gray-100 text-gray-800',
error: 'bg-red-100 text-red-800',
};
return colors[status] ?? 'bg-gray-100 text-gray-800';
};
</script>
<template>
@@ -41,99 +31,97 @@ const statusColor = (status) => {
<template #header>
<Link
:href="route('supervisor.machines.index')"
class="text-sm text-indigo-600 hover:text-indigo-800"
class="text-sm font-medium text-indigo-600 transition hover:text-indigo-800"
>
Retour aux machines
</Link>
</template>
<div class="mb-4">
<h1 class="text-2xl font-bold text-gray-900">{{ machine.name }}</h1>
<p class="text-sm text-gray-500">{{ machine.establishment?.name }}</p>
<div class="mb-6">
<div class="flex flex-wrap items-start gap-4">
<div class="flex-1">
<h1 class="text-2xl font-bold tracking-tight text-slate-900">{{ machine.name }}</h1>
<p class="mt-1 text-sm text-slate-500">{{ machine.establishment?.name }}</p>
</div>
<StatusBadge
:label="machine.status_label"
:color-class="getStatusColor(machine.status, machineStatusColors)"
/>
</div>
</div>
<div class="grid grid-cols-1 gap-6 lg:grid-cols-2">
<!-- Details -->
<div class="rounded-lg bg-white p-6 shadow">
<h2 class="mb-4 text-lg font-semibold text-gray-800">Informations</h2>
<dl class="space-y-3 text-sm">
<div class="flex justify-between">
<dt class="text-gray-500">Type</dt>
<dd class="font-medium text-gray-800">{{ machine.type_label }}</dd>
<div :class="[cardClass, 'p-6']">
<h2 class="mb-5 text-base font-semibold text-slate-900">Informations</h2>
<dl class="space-y-4 text-sm">
<div class="flex items-center justify-between gap-4 border-b border-slate-100 pb-3">
<dt class="text-slate-500">Type</dt>
<dd class="font-medium text-slate-800">{{ machine.type_label }}</dd>
</div>
<div class="flex justify-between">
<dt class="text-gray-500">Statut</dt>
<dd>
<span
class="rounded-full px-2.5 py-0.5 text-xs font-medium"
:class="statusColor(machine.status)"
>
{{ machine.status_label }}
</span>
</dd>
<div class="flex items-center justify-between gap-4 border-b border-slate-100 pb-3">
<dt class="text-slate-500">QR code</dt>
<dd class="font-mono text-slate-800">{{ machine.qr_code }}</dd>
</div>
<div class="flex justify-between">
<dt class="text-gray-500">QR code</dt>
<dd class="font-mono text-gray-800">{{ machine.qr_code }}</dd>
<div class="flex items-center justify-between gap-4 border-b border-slate-100 pb-3">
<dt class="text-slate-500">Dernier signal</dt>
<dd class="text-slate-800">{{ formatDate(machine.last_heartbeat_at) }}</dd>
</div>
<div class="flex justify-between">
<dt class="text-gray-500">Dernier signal</dt>
<dd class="text-gray-800">{{ formatDate(machine.last_heartbeat_at) }}</dd>
<div v-if="machine.cycle_started_at" class="flex items-center justify-between gap-4 border-b border-slate-100 pb-3">
<dt class="text-slate-500">Cycle démarré</dt>
<dd class="text-slate-800">{{ formatDate(machine.cycle_started_at) }}</dd>
</div>
<div v-if="machine.cycle_started_at" class="flex justify-between">
<dt class="text-gray-500">Cycle démarré</dt>
<dd class="text-gray-800">{{ formatDate(machine.cycle_started_at) }}</dd>
<div v-if="machine.cycle_ends_at" class="flex items-center justify-between gap-4 border-b border-slate-100 pb-3">
<dt class="text-slate-500">Fin de cycle prévue</dt>
<dd class="text-slate-800">{{ formatDate(machine.cycle_ends_at) }}</dd>
</div>
<div v-if="machine.cycle_ends_at" class="flex justify-between">
<dt class="text-gray-500">Fin de cycle prévue</dt>
<dd class="text-gray-800">{{ formatDate(machine.cycle_ends_at) }}</dd>
</div>
<div v-if="machine.current_user" class="flex justify-between">
<dt class="text-gray-500">Utilisateur actuel</dt>
<dd class="text-gray-800">
<div v-if="machine.current_user" class="flex items-center justify-between gap-4">
<dt class="text-slate-500">Utilisateur actuel</dt>
<dd class="text-right text-slate-800">
{{ machine.current_user.name }}
<span class="text-gray-500">({{ machine.current_user.email }})</span>
<span class="block text-xs text-slate-400">{{ machine.current_user.email }}</span>
</dd>
</div>
</dl>
<div v-if="machine.establishment" class="mt-6 border-t pt-4">
<h3 class="mb-2 text-sm font-semibold text-gray-700">Établissement</h3>
<p class="text-sm text-gray-600">{{ machine.establishment.address }}</p>
<p v-if="machine.establishment.city" class="text-sm text-gray-600">
<div v-if="machine.establishment" class="mt-6 rounded-xl bg-slate-50 p-4">
<h3 class="mb-2 text-xs font-semibold uppercase tracking-wide text-slate-500">Établissement</h3>
<p class="text-sm text-slate-700">{{ machine.establishment.address }}</p>
<p v-if="machine.establishment.city" class="text-sm text-slate-700">
{{ machine.establishment.city }}
</p>
</div>
<div v-if="machine.integration" class="mt-6 border-t pt-4">
<h3 class="mb-2 text-sm font-semibold text-gray-700">Intégration</h3>
<div v-if="machine.integration" class="mt-4 rounded-xl bg-indigo-50/50 p-4 ring-1 ring-indigo-100">
<h3 class="mb-3 text-xs font-semibold uppercase tracking-wide text-indigo-600">Intégration</h3>
<dl class="space-y-2 text-sm">
<div class="flex justify-between">
<dt class="text-gray-500">Fournisseur</dt>
<dd>{{ machine.integration.provider }}</dd>
<dt class="text-slate-500">Fournisseur</dt>
<dd class="font-medium text-slate-800">{{ machine.integration.provider }}</dd>
</div>
<div class="flex justify-between">
<dt class="text-gray-500">Mode</dt>
<dd>{{ machine.integration.mode }}</dd>
<dt class="text-slate-500">Mode</dt>
<dd class="font-medium text-slate-800">{{ machine.integration.mode }}</dd>
</div>
<div class="flex justify-between">
<dt class="text-gray-500">Active</dt>
<dd>{{ machine.integration.is_active ? 'Oui' : 'Non' }}</dd>
<dt class="text-slate-500">Active</dt>
<dd class="font-medium text-slate-800">{{ machine.integration.is_active ? 'Oui' : 'Non' }}</dd>
</div>
</dl>
</div>
</div>
<!-- Events -->
<div class="rounded-lg bg-white p-6 shadow">
<h2 class="mb-4 text-lg font-semibold text-gray-800">Événements récents</h2>
<div v-if="recentEvents.length === 0" class="text-sm text-gray-500">
<div :class="[cardClass, 'p-6']">
<h2 class="mb-5 text-base font-semibold text-slate-900">Événements récents</h2>
<div v-if="recentEvents.length === 0" class="py-8 text-center text-sm text-slate-400">
Aucun événement enregistré.
</div>
<ul v-else class="divide-y divide-gray-100">
<li v-for="(event, index) in recentEvents" :key="index" class="py-3">
<p class="text-sm font-medium text-gray-800">{{ event.event_type_label }}</p>
<p class="text-xs text-gray-500">{{ formatDate(event.occurred_at) }}</p>
<ul v-else class="divide-y divide-slate-100">
<li v-for="(event, index) in recentEvents" :key="index" class="flex items-start gap-3 py-3 first:pt-0">
<span class="mt-1.5 h-2 w-2 flex-shrink-0 rounded-full bg-indigo-400" />
<div>
<p class="text-sm font-medium text-slate-800">{{ event.event_type_label }}</p>
<p class="mt-0.5 text-xs text-slate-400">{{ formatDate(event.occurred_at) }}</p>
</div>
</li>
</ul>
</div>
@@ -0,0 +1,490 @@
<script setup>
import AddressAutocomplete from '@/Components/Supervisor/AddressAutocomplete.vue';
import AlertBanner from '@/Components/Supervisor/AlertBanner.vue';
import DataTable from '@/Components/Supervisor/DataTable.vue';
import FormField from '@/Components/Supervisor/FormField.vue';
import FormModal from '@/Components/Supervisor/FormModal.vue';
import Pagination from '@/Components/Supervisor/Pagination.vue';
import StatusBadge from '@/Components/Supervisor/StatusBadge.vue';
import TableHeaderCell from '@/Components/Supervisor/TableHeaderCell.vue';
import { useListFilters } from '@/Components/Supervisor/useListFilters.js';
import {
activeStatusColors,
cardClass,
filterInputClass,
filterSelectClass,
getStatusColor,
inputClass,
rowClass,
tdClass,
} from '@/Components/Supervisor/ui.js';
import ConfirmDeleteModal from '@/Components/ConfirmDeleteModal.vue';
import PrimaryButton from '@/Components/PrimaryButton.vue';
import SupervisorLayout from '@/Layouts/SupervisorLayout.vue';
import { Head, useForm } from '@inertiajs/vue3';
import { computed, onMounted, ref } from 'vue';
const props = defineProps({
establishments: {
type: [Array, Object],
default: () => [],
},
viewMode: {
type: String,
default: 'list',
},
canManageEstablishments: {
type: Boolean,
default: false,
},
canCreateEstablishments: {
type: Boolean,
default: false,
},
filters: {
type: Object,
default: () => ({}),
},
});
const { localFilters, toggleSort } = useListFilters('supervisor.organizations.index', {
search: props.filters.search ?? '',
is_active: props.filters.is_active ?? '',
sort: props.filters.sort ?? 'name',
direction: props.filters.direction ?? 'asc',
per_page: props.filters.per_page ?? 10,
}, { debounceKeys: ['search'] });
const handleSort = (key) => toggleSort(key);
const isSingleView = computed(() => props.viewMode === 'single');
const singleEstablishment = computed(() => {
if (!isSingleView.value || !Array.isArray(props.establishments)) {
return null;
}
return props.establishments[0] ?? null;
});
const establishmentRows = computed(() => {
if (isSingleView.value) {
return Array.isArray(props.establishments) ? props.establishments : [];
}
return props.establishments?.data ?? [];
});
const establishmentListCount = computed(() => {
if (isSingleView.value) {
return establishmentRows.value.length;
}
return props.establishments?.total ?? establishmentRows.value.length;
});
const editingEstablishmentId = ref(null);
const showEstablishmentForm = ref(false);
const toggleTarget = ref(null);
const toggleForm = useForm({});
const establishmentFormTitle = computed(() => {
if (editingEstablishmentId.value || isSingleView.value) {
return 'Modifier l\'enseigne';
}
return 'Nouvelle enseigne';
});
const establishmentSubmitLabel = computed(() => {
if (editingEstablishmentId.value || isSingleView.value) {
return 'Enregistrer';
}
return 'Créer';
});
const establishmentToForm = (establishment) => ({
name: establishment?.name ?? '',
address: establishment?.address ?? '',
city: establishment?.city ?? '',
zip_code: establishment?.zip_code ?? '',
timezone: establishment?.timezone ?? 'Europe/Paris',
is_active: establishment?.is_active ?? true,
});
const emptyEstablishmentForm = () => ({
name: '',
address: '',
city: '',
zip_code: '',
timezone: 'Europe/Paris',
is_active: true,
});
const establishmentForm = useForm(
isSingleView.value && singleEstablishment.value
? establishmentToForm(singleEstablishment.value)
: emptyEstablishmentForm(),
);
const startCreateEstablishment = () => {
editingEstablishmentId.value = null;
establishmentForm.defaults(emptyEstablishmentForm());
establishmentForm.reset();
showEstablishmentForm.value = true;
};
const startEditEstablishment = (establishment) => {
editingEstablishmentId.value = establishment.id;
establishmentForm.defaults(establishmentToForm(establishment));
establishmentForm.reset();
showEstablishmentForm.value = true;
};
onMounted(() => {
if (!isSingleView.value && establishmentListCount.value === 0 && props.canCreateEstablishments) {
startCreateEstablishment();
}
});
const cancelEstablishmentForm = () => {
showEstablishmentForm.value = false;
editingEstablishmentId.value = null;
if (isSingleView.value && singleEstablishment.value) {
establishmentForm.defaults(establishmentToForm(singleEstablishment.value));
}
establishmentForm.reset();
};
const submitEstablishment = () => {
const targetId = isSingleView.value ? singleEstablishment.value?.id : editingEstablishmentId.value;
const wasActive = isSingleView.value
? singleEstablishment.value?.is_active
: establishmentRows.value.find((e) => e.id === editingEstablishmentId.value)?.is_active;
if (targetId && wasActive && !establishmentForm.is_active) {
toggleTarget.value = { action: 'deactivate', source: 'form' };
return;
}
if (targetId && !wasActive && establishmentForm.is_active) {
toggleTarget.value = { action: 'reactivate', source: 'form' };
return;
}
performSubmit();
};
const isReactivateAction = computed(() => toggleTarget.value?.action === 'reactivate');
const toggleModalTitle = computed(() =>
isReactivateAction.value ? 'Réactiver l\'enseigne' : 'Désactiver l\'enseigne',
);
const toggleModalMessage = computed(() => {
if (!toggleTarget.value) return '';
if (toggleTarget.value.action === 'reactivate') {
if (toggleTarget.value.source === 'toggle') {
return `Voulez-vous réactiver « ${toggleTarget.value.establishment.name} » ? Elle redeviendra visible par les utilisateurs.`;
}
return 'Voulez-vous réactiver cette enseigne ? Elle redeviendra visible par les utilisateurs.';
}
if (toggleTarget.value.source === 'toggle') {
return `Voulez-vous désactiver « ${toggleTarget.value.establishment.name} » ? Elle ne sera plus visible par les utilisateurs.`;
}
return 'Voulez-vous désactiver cette enseigne ? Elle ne sera plus visible par les utilisateurs.';
});
const toggleModalWarning = computed(() =>
isReactivateAction.value
? 'Vérifiez que le nom, l\'adresse et le fuseau horaire sont corrects avant de réactiver.'
: 'Vous pourrez la réactiver à tout moment.',
);
const toggleModalConfirmLabel = computed(() =>
isReactivateAction.value ? 'Réactiver' : 'Désactiver',
);
const toggleFormErrors = computed(() => Object.values(toggleForm.errors));
const performSubmit = () => {
const targetId = isSingleView.value ? singleEstablishment.value?.id : editingEstablishmentId.value;
if (targetId) {
establishmentForm.put(
route('supervisor.organizations.establishments.update', targetId),
{
onSuccess: () => {
closeToggleModal();
cancelEstablishmentForm();
},
},
);
} else {
establishmentForm.post(route('supervisor.organizations.establishments.store'), {
onSuccess: () => {
closeToggleModal();
cancelEstablishmentForm();
},
});
}
};
const requestToggle = (establishment) => {
toggleTarget.value = {
action: establishment.is_active ? 'deactivate' : 'reactivate',
source: 'toggle',
establishment,
};
};
const closeToggleModal = () => {
toggleTarget.value = null;
};
const confirmToggle = () => {
if (!toggleTarget.value) return;
if (toggleTarget.value.source === 'toggle') {
toggleForm.patch(
route('supervisor.organizations.establishments.toggle-active', toggleTarget.value.establishment.id),
{
preserveScroll: true,
onSuccess: closeToggleModal,
},
);
} else {
performSubmit();
}
};
const formatAddress = (establishment) => {
const parts = [establishment.address, establishment.zip_code, establishment.city].filter(Boolean);
return parts.join(', ');
};
</script>
<template>
<Head title="Enseignes" />
<SupervisorLayout title="Enseignes">
<template #actions>
<PrimaryButton
v-if="!isSingleView && canCreateEstablishments"
@click="startCreateEstablishment"
>
Nouvelle enseigne
</PrimaryButton>
</template>
<AlertBanner v-if="toggleFormErrors.length > 0">
<ul class="space-y-1">
<li v-for="(error, index) in toggleFormErrors" :key="index">{{ error }}</li>
</ul>
</AlertBanner>
<section v-if="isSingleView && singleEstablishment">
<div class="mb-6 flex items-center justify-between">
<p class="text-sm text-slate-500">Informations de votre laverie</p>
<StatusBadge
:label="singleEstablishment.is_active ? 'Active' : 'Inactive'"
:color-class="getStatusColor(singleEstablishment.is_active ? 'active' : 'inactive', activeStatusColors)"
/>
</div>
<div :class="[cardClass, 'p-6']">
<dl class="grid grid-cols-1 gap-4 sm:grid-cols-2">
<div>
<dt class="text-xs font-medium uppercase tracking-wide text-slate-400">Nom</dt>
<dd class="mt-1 text-sm font-medium text-slate-900">{{ singleEstablishment.name }}</dd>
</div>
<div>
<dt class="text-xs font-medium uppercase tracking-wide text-slate-400">Adresse</dt>
<dd class="mt-1 text-sm text-slate-700">{{ formatAddress(singleEstablishment) }}</dd>
</div>
<div>
<dt class="text-xs font-medium uppercase tracking-wide text-slate-400">Fuseau horaire</dt>
<dd class="mt-1 text-sm text-slate-700">{{ singleEstablishment.timezone }}</dd>
</div>
<div v-if="singleEstablishment.latitude != null && singleEstablishment.longitude != null">
<dt class="text-xs font-medium uppercase tracking-wide text-slate-400">Coordonnées GPS</dt>
<dd class="mt-1 text-sm text-slate-700">
{{ singleEstablishment.latitude }}, {{ singleEstablishment.longitude }}
</dd>
<p class="mt-0.5 text-xs text-slate-400">Calculées automatiquement à partir de l'adresse.</p>
</div>
</dl>
<div v-if="canManageEstablishments" class="mt-6">
<PrimaryButton @click="startEditEstablishment(singleEstablishment)">
Modifier
</PrimaryButton>
</div>
</div>
<p v-if="!canManageEstablishments" class="mt-4 rounded-xl bg-slate-50 px-4 py-3 text-sm text-slate-500">
Consultation seule — contactez votre administrateur pour modifier ces informations.
</p>
</section>
<section v-else>
<p class="mb-4 text-sm text-slate-500">
{{ establishmentListCount }} enseigne(s)
</p>
<DataTable>
<template #head>
<tr>
<TableHeaderCell
label="Nom"
sortable
sort-key="name"
:active-sort="localFilters.sort"
:sort-direction="localFilters.direction"
@sort="handleSort"
>
<input
v-model="localFilters.search"
type="text"
placeholder="Nom, adresse…"
:class="filterInputClass"
/>
</TableHeaderCell>
<TableHeaderCell
label="Adresse"
sortable
sort-key="city"
:active-sort="localFilters.sort"
:sort-direction="localFilters.direction"
@sort="handleSort"
/>
<TableHeaderCell
label="Machines"
sortable
sort-key="machines_count"
:active-sort="localFilters.sort"
:sort-direction="localFilters.direction"
@sort="handleSort"
/>
<TableHeaderCell
label="Statut"
sortable
sort-key="is_active"
:active-sort="localFilters.sort"
:sort-direction="localFilters.direction"
@sort="handleSort"
>
<select v-model="localFilters.is_active" :class="filterSelectClass">
<option value="">Tous</option>
<option value="1">Active</option>
<option value="0">Inactive</option>
</select>
</TableHeaderCell>
<TableHeaderCell v-if="canManageEstablishments" label="Actions" align="right" />
</tr>
</template>
<tr v-if="establishmentRows.length === 0">
<td :colspan="canManageEstablishments ? 5 : 4" class="px-6 py-12 text-center text-sm text-slate-400">
Aucune enseigne trouvée.
</td>
</tr>
<tr v-for="establishment in establishmentRows" :key="establishment.id" :class="rowClass">
<td :class="[tdClass, 'font-medium text-slate-800']">{{ establishment.name }}</td>
<td :class="tdClass">{{ formatAddress(establishment) }}</td>
<td :class="tdClass">{{ establishment.machines_count }}</td>
<td :class="tdClass">
<StatusBadge
:label="establishment.is_active ? 'Active' : 'Inactive'"
:color-class="getStatusColor(establishment.is_active ? 'active' : 'inactive', activeStatusColors)"
/>
</td>
<td v-if="canManageEstablishments" :class="[tdClass, 'text-right']">
<button class="font-medium text-indigo-600 transition hover:text-indigo-800" @click="startEditEstablishment(establishment)">
Modifier
</button>
<button
class="ms-3 font-medium transition"
:class="establishment.is_active ? 'text-orange-600 hover:text-orange-800' : 'text-emerald-600 hover:text-emerald-800'"
:disabled="toggleForm.processing || establishmentForm.processing"
@click="requestToggle(establishment)"
>
{{ establishment.is_active ? 'Désactiver' : 'Réactiver' }}
</button>
</td>
</tr>
<template #footer>
<Pagination
:paginator="establishments"
:per-page="localFilters.per_page"
@update:per-page="(value) => { localFilters.per_page = value; }"
/>
</template>
</DataTable>
</section>
<FormModal
:show="showEstablishmentForm"
:title="establishmentFormTitle"
:submit-label="establishmentSubmitLabel"
:processing="establishmentForm.processing"
max-width="3xl"
@close="cancelEstablishmentForm"
@submit="submitEstablishment"
>
<div class="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3">
<FormField label="Nom">
<input v-model="establishmentForm.name" type="text" required :class="inputClass" />
</FormField>
<FormField label="Adresse" field-class="sm:col-span-2">
<AddressAutocomplete
v-model:address="establishmentForm.address"
v-model:city="establishmentForm.city"
v-model:zip-code="establishmentForm.zip_code"
required
/>
<p class="mt-1 text-xs text-slate-400">
Les coordonnées GPS seront calculées automatiquement à l'enregistrement.
</p>
</FormField>
<FormField label="Code postal">
<input v-model="establishmentForm.zip_code" type="text" :class="inputClass" />
</FormField>
<FormField label="Ville">
<input v-model="establishmentForm.city" type="text" :class="inputClass" />
</FormField>
<FormField label="Fuseau horaire">
<input v-model="establishmentForm.timezone" type="text" required :class="inputClass" />
</FormField>
<div class="sm:col-span-2 lg:col-span-3">
<label class="flex items-center gap-2 text-sm text-slate-700">
<input v-model="establishmentForm.is_active" type="checkbox" class="rounded border-slate-300 text-indigo-600 focus:ring-indigo-500/20" />
Enseigne active
</label>
<p class="mt-1 text-xs text-slate-400">
Décochez pour désactiver cette enseigne sans la supprimer.
</p>
</div>
</div>
</FormModal>
<ConfirmDeleteModal
:show="toggleTarget !== null"
:title="toggleModalTitle"
:message="toggleModalMessage"
:confirm-label="toggleModalConfirmLabel"
:warning="toggleModalWarning"
:danger="!isReactivateAction"
:processing="toggleForm.processing || establishmentForm.processing"
@close="closeToggleModal"
@confirm="confirmToggle"
/>
</SupervisorLayout>
</template>
+230 -117
View File
@@ -1,14 +1,31 @@
<script setup>
import DataTable from '@/Components/Supervisor/DataTable.vue';
import FormField from '@/Components/Supervisor/FormField.vue';
import FormModal from '@/Components/Supervisor/FormModal.vue';
import Pagination from '@/Components/Supervisor/Pagination.vue';
import StatusBadge from '@/Components/Supervisor/StatusBadge.vue';
import TableHeaderCell from '@/Components/Supervisor/TableHeaderCell.vue';
import { useListFilters } from '@/Components/Supervisor/useListFilters.js';
import {
activeStatusColors,
filterInputClass,
filterSelectClass,
getStatusColor,
inputClass,
rowClass,
selectClass,
tdClass,
} from '@/Components/Supervisor/ui.js';
import ConfirmDeleteModal from '@/Components/ConfirmDeleteModal.vue';
import PrimaryButton from '@/Components/PrimaryButton.vue';
import SecondaryButton from '@/Components/SecondaryButton.vue';
import SupervisorLayout from '@/Layouts/SupervisorLayout.vue';
import { Head, useForm } from '@inertiajs/vue3';
import { ref } from 'vue';
import { computed, ref } from 'vue';
const props = defineProps({
rules: {
type: Array,
default: () => [],
type: Object,
required: true,
},
establishments: {
type: Array,
@@ -22,10 +39,30 @@ const props = defineProps({
type: Object,
default: () => ({}),
},
filters: {
type: Object,
default: () => ({}),
},
});
const { localFilters, toggleSort } = useListFilters('supervisor.pricing.index', {
establishment_id: props.filters.establishment_id ?? '',
machine_type: props.filters.machine_type ?? '',
day_type: props.filters.day_type ?? '',
is_active: props.filters.is_active ?? '',
search: props.filters.search ?? '',
sort: props.filters.sort ?? 'priority',
direction: props.filters.direction ?? 'asc',
per_page: props.filters.per_page ?? 10,
}, { debounceKeys: ['search'] });
const showEstablishmentFilter = computed(() => props.establishments.length > 1);
const handleSort = (key) => toggleSort(key);
const editingId = ref(null);
const showForm = ref(false);
const deleteTarget = ref(null);
const deleteForm = useForm({});
const emptyForm = () => ({
establishment_id: props.establishments[0]?.id ?? '',
@@ -93,10 +130,20 @@ const submit = () => {
}
};
const destroy = (id) => {
if (confirm('Supprimer cette règle tarifaire ?')) {
useForm({}).delete(route('supervisor.pricing.destroy', id));
}
const openDeleteModal = (rule) => {
deleteTarget.value = rule;
};
const closeDeleteModal = () => {
deleteTarget.value = null;
};
const confirmDelete = () => {
if (!deleteTarget.value) return;
deleteForm.delete(route('supervisor.pricing.destroy', deleteTarget.value.id), {
onSuccess: closeDeleteModal,
});
};
const formatCurrency = (value) =>
@@ -107,136 +154,202 @@ const formatCurrency = (value) =>
<Head title="Tarifs" />
<SupervisorLayout title="Tarifs">
<div class="mb-4 flex justify-end">
<PrimaryButton v-if="!showForm" @click="startCreate">
<template #actions>
<PrimaryButton @click="startCreate">
Nouvelle règle
</PrimaryButton>
</div>
</template>
<!-- Inline form -->
<div v-if="showForm" class="mb-6 rounded-lg border border-indigo-200 bg-white p-6 shadow">
<h2 class="mb-4 text-lg font-semibold text-gray-800">
{{ editingId ? 'Modifier la règle' : 'Nouvelle règle tarifaire' }}
</h2>
<form @submit.prevent="submit" class="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3">
<div>
<label class="block text-xs font-medium text-gray-500">Établissement</label>
<select
v-model="form.establishment_id"
required
class="mt-1 block w-full rounded-md border-gray-300 text-sm shadow-sm"
>
<FormModal
:show="showForm"
:title="editingId ? 'Modifier la règle' : 'Nouvelle règle tarifaire'"
:submit-label="editingId ? 'Enregistrer' : 'Créer'"
:processing="form.processing"
max-width="3xl"
@close="cancelForm"
@submit="submit"
>
<div class="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3">
<FormField label="Établissement">
<select v-model="form.establishment_id" required :class="selectClass">
<option v-for="est in establishments" :key="est.id" :value="est.id">
{{ est.name }}
</option>
</select>
</div>
<div>
<label class="block text-xs font-medium text-gray-500">Type de machine</label>
<select v-model="form.machine_type" class="mt-1 block w-full rounded-md border-gray-300 text-sm shadow-sm">
</FormField>
<FormField label="Type de machine">
<select v-model="form.machine_type" :class="selectClass">
<option value="">Tous types</option>
<option v-for="(label, value) in machineTypes" :key="value" :value="value">
{{ label }}
</option>
</select>
</div>
<div>
<label class="block text-xs font-medium text-gray-500">Jour</label>
<select v-model="form.day_type" required class="mt-1 block w-full rounded-md border-gray-300 text-sm shadow-sm">
</FormField>
<FormField label="Jour">
<select v-model="form.day_type" required :class="selectClass">
<option v-for="(label, value) in dayTypes" :key="value" :value="value">
{{ label }}
</option>
</select>
</div>
<div>
<label class="block text-xs font-medium text-gray-500">Début créneau</label>
<input v-model="form.slot_start" type="time" required class="mt-1 block w-full rounded-md border-gray-300 text-sm shadow-sm" />
</div>
<div>
<label class="block text-xs font-medium text-gray-500">Fin créneau</label>
<input v-model="form.slot_end" type="time" required class="mt-1 block w-full rounded-md border-gray-300 text-sm shadow-sm" />
</div>
<div>
<label class="block text-xs font-medium text-gray-500">Prix ()</label>
<input v-model="form.price" type="number" step="0.01" min="0" required class="mt-1 block w-full rounded-md border-gray-300 text-sm shadow-sm" />
</div>
<div>
<label class="block text-xs font-medium text-gray-500">Libellé</label>
<input v-model="form.label" type="text" class="mt-1 block w-full rounded-md border-gray-300 text-sm shadow-sm" />
</div>
<div>
<label class="block text-xs font-medium text-gray-500">Priorité</label>
<input v-model="form.priority" type="number" min="0" class="mt-1 block w-full rounded-md border-gray-300 text-sm shadow-sm" />
</div>
<div class="flex items-end gap-4">
<label class="flex items-center gap-2 text-sm">
<input v-model="form.requires_app" type="checkbox" class="rounded border-gray-300 text-indigo-600" />
</FormField>
<FormField label="Début créneau">
<input v-model="form.slot_start" type="time" required :class="inputClass" />
</FormField>
<FormField label="Fin créneau">
<input v-model="form.slot_end" type="time" required :class="inputClass" />
</FormField>
<FormField label="Prix (€)">
<input v-model="form.price" type="number" step="0.01" min="0" required :class="inputClass" />
</FormField>
<FormField label="Libellé">
<input v-model="form.label" type="text" :class="inputClass" />
</FormField>
<FormField label="Priorité">
<input v-model="form.priority" type="number" min="0" :class="inputClass" />
</FormField>
<div class="flex items-end gap-4 sm:col-span-2 lg:col-span-3">
<label class="flex items-center gap-2 text-sm text-slate-700">
<input v-model="form.requires_app" type="checkbox" class="rounded border-slate-300 text-indigo-600 focus:ring-indigo-500/20" />
App requise
</label>
<label class="flex items-center gap-2 text-sm">
<input v-model="form.is_active" type="checkbox" class="rounded border-gray-300 text-indigo-600" />
<label class="flex items-center gap-2 text-sm text-slate-700">
<input v-model="form.is_active" type="checkbox" class="rounded border-slate-300 text-indigo-600 focus:ring-indigo-500/20" />
Active
</label>
</div>
<div class="flex gap-2 sm:col-span-2 lg:col-span-3">
<PrimaryButton type="submit" :disabled="form.processing">
{{ editingId ? 'Enregistrer' : 'Créer' }}
</PrimaryButton>
<SecondaryButton type="button" @click="cancelForm">Annuler</SecondaryButton>
</div>
</form>
</div>
</div>
</FormModal>
<!-- Rules list -->
<div class="overflow-hidden rounded-lg bg-white shadow">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-4 py-3 text-left text-xs font-medium uppercase text-gray-500">Établissement</th>
<th class="px-4 py-3 text-left text-xs font-medium uppercase text-gray-500">Créneau</th>
<th class="px-4 py-3 text-left text-xs font-medium uppercase text-gray-500">Type</th>
<th class="px-4 py-3 text-left text-xs font-medium uppercase text-gray-500">Prix</th>
<th class="px-4 py-3 text-left text-xs font-medium uppercase text-gray-500">Statut</th>
<th class="px-4 py-3 text-right text-xs font-medium uppercase text-gray-500">Actions</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-100">
<tr v-if="rules.length === 0">
<td colspan="6" class="px-4 py-8 text-center text-sm text-gray-500">
Aucune règle tarifaire configurée.
</td>
</tr>
<tr v-for="rule in rules" :key="rule.id" class="hover:bg-gray-50">
<td class="px-4 py-3 text-sm text-gray-800">{{ rule.establishment_name }}</td>
<td class="px-4 py-3 text-sm text-gray-600">
{{ rule.slot_start }} {{ rule.slot_end }}
<span class="text-xs text-gray-400">({{ rule.day_type_label }})</span>
</td>
<td class="px-4 py-3 text-sm text-gray-600">
{{ rule.machine_type_label ?? 'Tous' }}
</td>
<td class="px-4 py-3 text-sm font-medium text-gray-800">
{{ formatCurrency(rule.price) }}
</td>
<td class="px-4 py-3">
<span
class="rounded-full px-2.5 py-0.5 text-xs font-medium"
:class="rule.is_active ? 'bg-green-100 text-green-800' : 'bg-gray-100 text-gray-600'"
>
{{ rule.is_active ? 'Active' : 'Inactive' }}
</span>
</td>
<td class="px-4 py-3 text-right text-sm">
<button @click="startEdit(rule)" class="text-indigo-600 hover:text-indigo-800">
Modifier
</button>
<button @click="destroy(rule.id)" class="ms-3 text-red-600 hover:text-red-800">
Supprimer
</button>
</td>
</tr>
</tbody>
</table>
</div>
<DataTable>
<template #head>
<tr>
<TableHeaderCell
label="Établissement"
sortable
sort-key="establishment"
:active-sort="localFilters.sort"
:sort-direction="localFilters.direction"
@sort="handleSort"
>
<select
v-if="showEstablishmentFilter"
v-model="localFilters.establishment_id"
:class="filterSelectClass"
>
<option value="">Toutes</option>
<option v-for="est in establishments" :key="est.id" :value="est.id">
{{ est.name }}
</option>
</select>
</TableHeaderCell>
<TableHeaderCell
label="Créneau"
sortable
sort-key="slot_start"
:active-sort="localFilters.sort"
:sort-direction="localFilters.direction"
@sort="handleSort"
>
<select v-model="localFilters.day_type" :class="filterSelectClass">
<option value="">Tous</option>
<option v-for="(label, value) in dayTypes" :key="value" :value="value">
{{ label }}
</option>
</select>
</TableHeaderCell>
<TableHeaderCell
label="Type"
sortable
sort-key="machine_type"
:active-sort="localFilters.sort"
:sort-direction="localFilters.direction"
@sort="handleSort"
>
<select v-model="localFilters.machine_type" :class="filterSelectClass">
<option value="">Tous</option>
<option v-for="(label, value) in machineTypes" :key="value" :value="value">
{{ label }}
</option>
</select>
</TableHeaderCell>
<TableHeaderCell
label="Prix"
sortable
sort-key="price"
:active-sort="localFilters.sort"
:sort-direction="localFilters.direction"
@sort="handleSort"
>
<input
v-model="localFilters.search"
type="text"
placeholder="Libellé…"
:class="filterInputClass"
/>
</TableHeaderCell>
<TableHeaderCell
label="Statut"
sortable
sort-key="is_active"
:active-sort="localFilters.sort"
:sort-direction="localFilters.direction"
@sort="handleSort"
>
<select v-model="localFilters.is_active" :class="filterSelectClass">
<option value="">Tous</option>
<option value="1">Active</option>
<option value="0">Inactive</option>
</select>
</TableHeaderCell>
<TableHeaderCell label="Actions" align="right" />
</tr>
</template>
<tr v-if="rules.data.length === 0">
<td colspan="6" class="px-6 py-12 text-center text-sm text-slate-400">
Aucune règle tarifaire trouvée.
</td>
</tr>
<tr v-for="rule in rules.data" :key="rule.id" :class="rowClass">
<td :class="[tdClass, 'font-medium text-slate-800']">{{ rule.establishment_name }}</td>
<td :class="tdClass">
{{ rule.slot_start }} {{ rule.slot_end }}
<span class="text-xs text-slate-400">({{ rule.day_type_label }})</span>
</td>
<td :class="tdClass">{{ rule.machine_type_label ?? 'Tous' }}</td>
<td :class="[tdClass, 'font-semibold text-slate-800']">{{ formatCurrency(rule.price) }}</td>
<td :class="tdClass">
<StatusBadge
:label="rule.is_active ? 'Active' : 'Inactive'"
:color-class="getStatusColor(rule.is_active ? 'active' : 'inactive', activeStatusColors)"
/>
</td>
<td :class="[tdClass, 'text-right']">
<button class="font-medium text-indigo-600 transition hover:text-indigo-800" @click="startEdit(rule)">
Modifier
</button>
<button class="ms-3 font-medium text-red-600 transition hover:text-red-800" @click="openDeleteModal(rule)">
Supprimer
</button>
</td>
</tr>
<template #footer>
<Pagination
:paginator="rules"
:per-page="localFilters.per_page"
@update:per-page="(value) => { localFilters.per_page = value; }"
/>
</template>
</DataTable>
<ConfirmDeleteModal
:show="deleteTarget !== null"
title="Supprimer la règle tarifaire"
:message="deleteTarget ? `Voulez-vous supprimer la règle « ${deleteTarget.label || deleteTarget.establishment_name} » ?` : ''"
:processing="deleteForm.processing"
@close="closeDeleteModal"
@confirm="confirmDelete"
/>
</SupervisorLayout>
</template>
+231 -114
View File
@@ -1,14 +1,29 @@
<script setup>
import DataTable from '@/Components/Supervisor/DataTable.vue';
import FormField from '@/Components/Supervisor/FormField.vue';
import FormModal from '@/Components/Supervisor/FormModal.vue';
import Pagination from '@/Components/Supervisor/Pagination.vue';
import StatusBadge from '@/Components/Supervisor/StatusBadge.vue';
import TableHeaderCell from '@/Components/Supervisor/TableHeaderCell.vue';
import { useListFilters } from '@/Components/Supervisor/useListFilters.js';
import {
filterInputClass,
filterSelectClass,
inputClass,
rowClass,
selectClass,
tdClass,
} from '@/Components/Supervisor/ui.js';
import ConfirmDeleteModal from '@/Components/ConfirmDeleteModal.vue';
import PrimaryButton from '@/Components/PrimaryButton.vue';
import SecondaryButton from '@/Components/SecondaryButton.vue';
import SupervisorLayout from '@/Layouts/SupervisorLayout.vue';
import { Head, useForm } from '@inertiajs/vue3';
import { ref } from 'vue';
import { computed, ref } from 'vue';
const props = defineProps({
promotions: {
type: Array,
default: () => [],
type: Object,
required: true,
},
establishments: {
type: Array,
@@ -22,10 +37,29 @@ const props = defineProps({
type: Object,
default: () => ({}),
},
filters: {
type: Object,
default: () => ({}),
},
});
const { localFilters, toggleSort } = useListFilters('supervisor.promotions.index', {
establishment_id: props.filters.establishment_id ?? '',
machine_type: props.filters.machine_type ?? '',
is_active: props.filters.is_active ?? '',
search: props.filters.search ?? '',
sort: props.filters.sort ?? 'starts_at',
direction: props.filters.direction ?? 'desc',
per_page: props.filters.per_page ?? 10,
}, { debounceKeys: ['search'] });
const showEstablishmentFilter = computed(() => props.establishments.length > 1);
const handleSort = (key) => toggleSort(key, ['starts_at', 'ends_at', 'discount_value']);
const editingId = ref(null);
const showForm = ref(false);
const deleteTarget = ref(null);
const deleteForm = useForm({});
const emptyForm = () => ({
establishment_id: props.establishments[0]?.id ?? '',
@@ -81,10 +115,20 @@ const submit = () => {
}
};
const destroy = (id) => {
if (confirm('Supprimer cette promotion ?')) {
useForm({}).delete(route('supervisor.promotions.destroy', id));
}
const openDeleteModal = (promotion) => {
deleteTarget.value = promotion;
};
const closeDeleteModal = () => {
deleteTarget.value = null;
};
const confirmDelete = () => {
if (!deleteTarget.value) return;
deleteForm.delete(route('supervisor.promotions.destroy', deleteTarget.value.id), {
onSuccess: closeDeleteModal,
});
};
const formatDate = (iso) => {
@@ -110,137 +154,210 @@ const isCurrentlyActive = (promotion) => {
new Date(promotion.ends_at) >= now
);
};
const promotionStatusColor = (promotion) => {
if (isCurrentlyActive(promotion)) {
return 'bg-emerald-100 text-emerald-800 ring-emerald-600/20';
}
if (promotion.is_active) {
return 'bg-amber-100 text-amber-800 ring-amber-600/20';
}
return 'bg-slate-100 text-slate-600 ring-slate-500/20';
};
const promotionStatusLabel = (promotion) => {
if (isCurrentlyActive(promotion)) return 'En cours';
if (promotion.is_active) return 'Programmée';
return 'Inactive';
};
</script>
<template>
<Head title="Promotions" />
<SupervisorLayout title="Promotions">
<div class="mb-4 flex justify-end">
<PrimaryButton v-if="!showForm" @click="startCreate">
<template #actions>
<PrimaryButton @click="startCreate">
Nouvelle promotion
</PrimaryButton>
</div>
</template>
<div v-if="showForm" class="mb-6 rounded-lg border border-indigo-200 bg-white p-6 shadow">
<h2 class="mb-4 text-lg font-semibold text-gray-800">
{{ editingId ? 'Modifier la promotion' : 'Nouvelle promotion' }}
</h2>
<form @submit.prevent="submit" class="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3">
<div>
<label class="block text-xs font-medium text-gray-500">Établissement</label>
<select v-model="form.establishment_id" required class="mt-1 block w-full rounded-md border-gray-300 text-sm shadow-sm">
<FormModal
:show="showForm"
:title="editingId ? 'Modifier la promotion' : 'Nouvelle promotion'"
:submit-label="editingId ? 'Enregistrer' : 'Créer'"
:processing="form.processing"
max-width="3xl"
@close="cancelForm"
@submit="submit"
>
<div class="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3">
<FormField label="Établissement">
<select v-model="form.establishment_id" required :class="selectClass">
<option v-for="est in establishments" :key="est.id" :value="est.id">
{{ est.name }}
</option>
</select>
</div>
<div>
<label class="block text-xs font-medium text-gray-500">Type de machine</label>
<select v-model="form.machine_type" required class="mt-1 block w-full rounded-md border-gray-300 text-sm shadow-sm">
</FormField>
<FormField label="Type de machine">
<select v-model="form.machine_type" required :class="selectClass">
<option v-for="(label, value) in machineTypes" :key="value" :value="value">
{{ label }}
</option>
</select>
</div>
<div>
<label class="block text-xs font-medium text-gray-500">Type de remise</label>
<select v-model="form.discount_type" required class="mt-1 block w-full rounded-md border-gray-300 text-sm shadow-sm">
</FormField>
<FormField label="Type de remise">
<select v-model="form.discount_type" required :class="selectClass">
<option v-for="(label, value) in discountTypes" :key="value" :value="value">
{{ label }}
</option>
</select>
</div>
<div>
<label class="block text-xs font-medium text-gray-500">Valeur</label>
<input v-model="form.discount_value" type="number" step="0.01" min="0" required class="mt-1 block w-full rounded-md border-gray-300 text-sm shadow-sm" />
</div>
<div>
<label class="block text-xs font-medium text-gray-500">Début</label>
<input v-model="form.starts_at" type="datetime-local" required class="mt-1 block w-full rounded-md border-gray-300 text-sm shadow-sm" />
</div>
<div>
<label class="block text-xs font-medium text-gray-500">Fin</label>
<input v-model="form.ends_at" type="datetime-local" required class="mt-1 block w-full rounded-md border-gray-300 text-sm shadow-sm" />
</div>
<div class="sm:col-span-2 lg:col-span-3">
<label class="block text-xs font-medium text-gray-500">Description</label>
<textarea v-model="form.description" rows="2" class="mt-1 block w-full rounded-md border-gray-300 text-sm shadow-sm" />
</div>
<div class="flex items-center">
<label class="flex items-center gap-2 text-sm">
<input v-model="form.is_active" type="checkbox" class="rounded border-gray-300 text-indigo-600" />
</FormField>
<FormField label="Valeur">
<input v-model="form.discount_value" type="number" step="0.01" min="0" required :class="inputClass" />
</FormField>
<FormField label="Début">
<input v-model="form.starts_at" type="datetime-local" required :class="inputClass" />
</FormField>
<FormField label="Fin">
<input v-model="form.ends_at" type="datetime-local" required :class="inputClass" />
</FormField>
<FormField label="Description" field-class="sm:col-span-2 lg:col-span-3">
<textarea v-model="form.description" rows="2" :class="inputClass" />
</FormField>
<div class="flex items-center sm:col-span-2 lg:col-span-3">
<label class="flex items-center gap-2 text-sm text-slate-700">
<input v-model="form.is_active" type="checkbox" class="rounded border-slate-300 text-indigo-600 focus:ring-indigo-500/20" />
Active
</label>
</div>
<div class="flex gap-2 sm:col-span-2 lg:col-span-3">
<PrimaryButton type="submit" :disabled="form.processing">
{{ editingId ? 'Enregistrer' : 'Créer' }}
</PrimaryButton>
<SecondaryButton type="button" @click="cancelForm">Annuler</SecondaryButton>
</div>
</form>
</div>
</div>
</FormModal>
<div class="overflow-hidden rounded-lg bg-white shadow">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-4 py-3 text-left text-xs font-medium uppercase text-gray-500">Établissement</th>
<th class="px-4 py-3 text-left text-xs font-medium uppercase text-gray-500">Remise</th>
<th class="px-4 py-3 text-left text-xs font-medium uppercase text-gray-500">Période</th>
<th class="px-4 py-3 text-left text-xs font-medium uppercase text-gray-500">Machines</th>
<th class="px-4 py-3 text-left text-xs font-medium uppercase text-gray-500">Statut</th>
<th class="px-4 py-3 text-right text-xs font-medium uppercase text-gray-500">Actions</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-100">
<tr v-if="promotions.length === 0">
<td colspan="6" class="px-4 py-8 text-center text-sm text-gray-500">
Aucune promotion configurée.
</td>
</tr>
<tr v-for="promotion in promotions" :key="promotion.id" class="hover:bg-gray-50">
<td class="px-4 py-3 text-sm text-gray-800">{{ promotion.establishment_name }}</td>
<td class="px-4 py-3 text-sm font-medium text-green-700">
{{ formatDiscount(promotion) }}
</td>
<td class="px-4 py-3 text-sm text-gray-600">
<div>{{ formatDate(promotion.starts_at) }}</div>
<div class="text-xs text-gray-400"> {{ formatDate(promotion.ends_at) }}</div>
</td>
<td class="px-4 py-3 text-sm text-gray-600">{{ promotion.machine_type_label }}</td>
<td class="px-4 py-3">
<span
class="rounded-full px-2.5 py-0.5 text-xs font-medium"
:class="
isCurrentlyActive(promotion)
? 'bg-green-100 text-green-800'
: promotion.is_active
? 'bg-yellow-100 text-yellow-800'
: 'bg-gray-100 text-gray-600'
"
<DataTable>
<template #head>
<tr>
<TableHeaderCell
label="Établissement"
sortable
sort-key="establishment"
:active-sort="localFilters.sort"
:sort-direction="localFilters.direction"
@sort="handleSort"
>
<div class="flex flex-col gap-1.5">
<select
v-if="showEstablishmentFilter"
v-model="localFilters.establishment_id"
:class="filterSelectClass"
>
{{
isCurrentlyActive(promotion)
? 'En cours'
: promotion.is_active
? 'Programmée'
: 'Inactive'
}}
</span>
</td>
<td class="px-4 py-3 text-right text-sm">
<button @click="startEdit(promotion)" class="text-indigo-600 hover:text-indigo-800">
Modifier
</button>
<button @click="destroy(promotion.id)" class="ms-3 text-red-600 hover:text-red-800">
Supprimer
</button>
</td>
</tr>
</tbody>
</table>
</div>
<option value="">Toutes</option>
<option v-for="est in establishments" :key="est.id" :value="est.id">
{{ est.name }}
</option>
</select>
<input
v-model="localFilters.search"
type="text"
placeholder="Description…"
:class="filterInputClass"
/>
</div>
</TableHeaderCell>
<TableHeaderCell
label="Remise"
sortable
sort-key="discount_value"
:active-sort="localFilters.sort"
:sort-direction="localFilters.direction"
@sort="handleSort"
/>
<TableHeaderCell
label="Période"
sortable
sort-key="starts_at"
:active-sort="localFilters.sort"
:sort-direction="localFilters.direction"
@sort="handleSort"
/>
<TableHeaderCell
label="Machines"
sortable
sort-key="machine_type"
:active-sort="localFilters.sort"
:sort-direction="localFilters.direction"
@sort="handleSort"
>
<select v-model="localFilters.machine_type" :class="filterSelectClass">
<option value="">Toutes</option>
<option v-for="(label, value) in machineTypes" :key="value" :value="value">
{{ label }}
</option>
</select>
</TableHeaderCell>
<TableHeaderCell
label="Statut"
sortable
sort-key="is_active"
:active-sort="localFilters.sort"
:sort-direction="localFilters.direction"
@sort="handleSort"
>
<select v-model="localFilters.is_active" :class="filterSelectClass">
<option value="">Tous</option>
<option value="1">Active</option>
<option value="0">Inactive</option>
</select>
</TableHeaderCell>
<TableHeaderCell label="Actions" align="right" />
</tr>
</template>
<tr v-if="promotions.data.length === 0">
<td colspan="6" class="px-6 py-12 text-center text-sm text-slate-400">
Aucune promotion trouvée.
</td>
</tr>
<tr v-for="promotion in promotions.data" :key="promotion.id" :class="rowClass">
<td :class="[tdClass, 'font-medium text-slate-800']">{{ promotion.establishment_name }}</td>
<td :class="[tdClass, 'font-semibold text-emerald-700']">{{ formatDiscount(promotion) }}</td>
<td :class="tdClass">
<div>{{ formatDate(promotion.starts_at) }}</div>
<div class="text-xs text-slate-400"> {{ formatDate(promotion.ends_at) }}</div>
</td>
<td :class="tdClass">{{ promotion.machine_type_label }}</td>
<td :class="tdClass">
<StatusBadge
:label="promotionStatusLabel(promotion)"
:color-class="promotionStatusColor(promotion)"
/>
</td>
<td :class="[tdClass, 'text-right']">
<button class="font-medium text-indigo-600 transition hover:text-indigo-800" @click="startEdit(promotion)">
Modifier
</button>
<button class="ms-3 font-medium text-red-600 transition hover:text-red-800" @click="openDeleteModal(promotion)">
Supprimer
</button>
</td>
</tr>
<template #footer>
<Pagination
:paginator="promotions"
:per-page="localFilters.per_page"
@update:per-page="(value) => { localFilters.per_page = value; }"
/>
</template>
</DataTable>
<ConfirmDeleteModal
:show="deleteTarget !== null"
title="Supprimer la promotion"
:message="deleteTarget ? `Voulez-vous supprimer la promotion « ${deleteTarget.description || deleteTarget.establishment_name} » ?` : ''"
:processing="deleteForm.processing"
@close="closeDeleteModal"
@confirm="confirmDelete"
/>
</SupervisorLayout>
</template>
+155 -120
View File
@@ -1,13 +1,31 @@
<script setup>
import DataTable from '@/Components/Supervisor/DataTable.vue';
import Pagination from '@/Components/Supervisor/Pagination.vue';
import StatusBadge from '@/Components/Supervisor/StatusBadge.vue';
import TableHeaderCell from '@/Components/Supervisor/TableHeaderCell.vue';
import { useListFilters } from '@/Components/Supervisor/useListFilters.js';
import {
filterInputClass,
filterSelectClass,
getStatusColor,
linkClass,
rowClass,
tdClass,
washStatusColors,
} from '@/Components/Supervisor/ui.js';
import SupervisorLayout from '@/Layouts/SupervisorLayout.vue';
import { Head, Link, router } from '@inertiajs/vue3';
import { reactive, watch } from 'vue';
import { Head, Link } from '@inertiajs/vue3';
import { computed } from 'vue';
const props = defineProps({
washes: {
type: Object,
required: true,
},
establishments: {
type: Array,
default: () => [],
},
filters: {
type: Object,
default: () => ({}),
@@ -18,17 +36,19 @@ const props = defineProps({
},
});
const localFilters = reactive({
const { localFilters, toggleSort } = useListFilters('supervisor.washes.index', {
establishment_id: props.filters.establishment_id ?? '',
user: props.filters.user ?? '',
status: props.filters.status ?? '',
date: props.filters.date ?? '',
});
sort: props.filters.sort ?? 'started_at',
direction: props.filters.direction ?? 'desc',
per_page: props.filters.per_page ?? 10,
}, { debounceKeys: ['user'] });
watch(localFilters, () => {
router.get(route('supervisor.washes.index'), localFilters, {
preserveState: true,
replace: true,
});
});
const showEstablishmentFilter = computed(() => props.establishments.length > 1);
const handleSort = (key) => toggleSort(key, ['started_at', 'duration_minutes', 'cost']);
const formatDate = (iso) => {
if (!iso) return '—';
@@ -40,122 +60,137 @@ const formatDate = (iso) => {
const formatCurrency = (value) =>
new Intl.NumberFormat('fr-FR', { style: 'currency', currency: 'EUR' }).format(value ?? 0);
const statusColor = (status) => {
const colors = {
pending_start: 'bg-gray-100 text-gray-800',
running: 'bg-blue-100 text-blue-800',
completed: 'bg-green-100 text-green-800',
failed: 'bg-red-100 text-red-800',
cancelled: 'bg-yellow-100 text-yellow-800',
};
return colors[status] ?? 'bg-gray-100 text-gray-800';
};
</script>
<template>
<Head title="Lavages" />
<SupervisorLayout title="Lavages">
<div class="mb-6 flex flex-wrap gap-4 rounded-lg bg-white p-4 shadow">
<div>
<label class="block text-xs font-medium text-gray-500">Statut</label>
<select
v-model="localFilters.status"
class="mt-1 block rounded-md border-gray-300 text-sm shadow-sm focus:border-indigo-500 focus:ring-indigo-500"
>
<option value="">Tous</option>
<option v-for="(label, value) in statusOptions" :key="value" :value="value">
{{ label }}
</option>
</select>
</div>
<div>
<label class="block text-xs font-medium text-gray-500">Date</label>
<input
v-model="localFilters.date"
type="date"
class="mt-1 block rounded-md border-gray-300 text-sm shadow-sm focus:border-indigo-500 focus:ring-indigo-500"
/>
</div>
</div>
<div class="overflow-hidden rounded-lg bg-white shadow">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-4 py-3 text-left text-xs font-medium uppercase text-gray-500">Début</th>
<th class="px-4 py-3 text-left text-xs font-medium uppercase text-gray-500">Utilisateur</th>
<th class="px-4 py-3 text-left text-xs font-medium uppercase text-gray-500">Machine</th>
<th class="px-4 py-3 text-left text-xs font-medium uppercase text-gray-500">Statut</th>
<th class="px-4 py-3 text-left text-xs font-medium uppercase text-gray-500">Durée</th>
<th class="px-4 py-3 text-left text-xs font-medium uppercase text-gray-500">Coût</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-100">
<tr v-if="washes.data.length === 0">
<td colspan="6" class="px-4 py-8 text-center text-sm text-gray-500">
Aucun lavage trouvé.
</td>
</tr>
<tr v-for="wash in washes.data" :key="wash.uuid" class="hover:bg-gray-50">
<td class="whitespace-nowrap px-4 py-3 text-sm text-gray-800">
{{ formatDate(wash.started_at) }}
</td>
<td class="px-4 py-3 text-sm">
<div class="font-medium text-gray-800">{{ wash.user?.name ?? '—' }}</div>
<div class="text-xs text-gray-500">{{ wash.user?.email }}</div>
</td>
<td class="px-4 py-3 text-sm">
<Link
v-if="wash.machine"
:href="route('supervisor.machines.show', wash.machine.uuid)"
class="text-indigo-600 hover:text-indigo-800"
>
{{ wash.machine.name }}
</Link>
<span v-else></span>
</td>
<td class="px-4 py-3">
<span
class="rounded-full px-2.5 py-0.5 text-xs font-medium"
:class="statusColor(wash.status)"
>
{{ wash.status_label }}
</span>
</td>
<td class="whitespace-nowrap px-4 py-3 text-sm text-gray-600">
{{ wash.duration_minutes ? `${wash.duration_minutes} min` : '—' }}
</td>
<td class="whitespace-nowrap px-4 py-3 text-sm font-medium text-gray-800">
{{ formatCurrency(wash.cost) }}
</td>
</tr>
</tbody>
</table>
<div v-if="washes.links.length > 3" class="flex items-center justify-between border-t px-4 py-3">
<p class="text-sm text-gray-600">
{{ washes.from ?? 0 }}{{ washes.to ?? 0 }} sur {{ washes.total }}
</p>
<div class="flex gap-1">
<Link
v-for="link in washes.links"
:key="link.label"
:href="link.url"
v-html="link.label"
class="rounded px-3 py-1 text-sm"
:class="
link.active
? 'bg-indigo-600 text-white'
: link.url
? 'text-gray-600 hover:bg-gray-100'
: 'cursor-not-allowed text-gray-300'
"
preserve-state
<DataTable>
<template #head>
<tr>
<TableHeaderCell
label="Début"
sortable
sort-key="started_at"
:active-sort="localFilters.sort"
:sort-direction="localFilters.direction"
@sort="handleSort"
>
<input v-model="localFilters.date" type="date" :class="filterInputClass" />
</TableHeaderCell>
<TableHeaderCell
label="Utilisateur"
sortable
sort-key="user"
:active-sort="localFilters.sort"
:sort-direction="localFilters.direction"
@sort="handleSort"
>
<input
v-model="localFilters.user"
type="text"
placeholder="Nom ou e-mail…"
:class="filterInputClass"
/>
</TableHeaderCell>
<TableHeaderCell
label="Machine"
sortable
sort-key="machine"
:active-sort="localFilters.sort"
:sort-direction="localFilters.direction"
@sort="handleSort"
>
<select
v-if="showEstablishmentFilter"
v-model="localFilters.establishment_id"
:class="filterSelectClass"
>
<option value="">Toutes</option>
<option v-for="est in establishments" :key="est.id" :value="est.id">
{{ est.name }}
</option>
</select>
</TableHeaderCell>
<TableHeaderCell
label="Statut"
sortable
sort-key="status"
:active-sort="localFilters.sort"
:sort-direction="localFilters.direction"
@sort="handleSort"
>
<select v-model="localFilters.status" :class="filterSelectClass">
<option value="">Tous</option>
<option v-for="(label, value) in statusOptions" :key="value" :value="value">
{{ label }}
</option>
</select>
</TableHeaderCell>
<TableHeaderCell
label="Durée"
sortable
sort-key="duration_minutes"
:active-sort="localFilters.sort"
:sort-direction="localFilters.direction"
@sort="handleSort"
/>
</div>
</div>
</div>
<TableHeaderCell
label="Coût"
sortable
sort-key="cost"
:active-sort="localFilters.sort"
:sort-direction="localFilters.direction"
@sort="handleSort"
/>
</tr>
</template>
<tr v-if="washes.data.length === 0">
<td colspan="6" class="px-6 py-12 text-center text-sm text-slate-400">
Aucun lavage trouvé.
</td>
</tr>
<tr v-for="wash in washes.data" :key="wash.uuid" :class="rowClass">
<td :class="[tdClass, 'font-medium text-slate-800']">
{{ formatDate(wash.started_at) }}
</td>
<td :class="tdClass">
<div class="font-medium text-slate-800">{{ wash.user?.name ?? '—' }}</div>
<div class="text-xs text-slate-400">{{ wash.user?.email }}</div>
</td>
<td :class="tdClass">
<Link
v-if="wash.machine"
:href="route('supervisor.machines.show', wash.machine.uuid)"
:class="linkClass"
>
{{ wash.machine.name }}
</Link>
<span v-else></span>
</td>
<td :class="tdClass">
<StatusBadge
:label="wash.status_label"
:color-class="getStatusColor(wash.status, washStatusColors)"
/>
</td>
<td :class="tdClass">
{{ wash.duration_minutes ? `${wash.duration_minutes} min` : '—' }}
</td>
<td :class="[tdClass, 'font-semibold text-slate-800']">
{{ formatCurrency(wash.cost) }}
</td>
</tr>
<template #footer>
<Pagination
:paginator="washes"
:per-page="localFilters.per_page"
@update:per-page="(value) => { localFilters.per_page = value; }"
/>
</template>
</DataTable>
</SupervisorLayout>
</template>