Intégration fonctionnalites V1
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user