feat: infrastructure assets management with warranty tracking and EAN lookup integration

This commit is contained in:
jeremy bayse
2026-04-09 21:51:43 +02:00
parent 3544c77bd1
commit b28c56c94c
46 changed files with 2961 additions and 414 deletions

View File

@@ -0,0 +1,267 @@
<script setup>
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout.vue'
import { Head, Link, useForm } from '@inertiajs/vue3'
import { ref } from 'vue'
const props = defineProps({
asset: Object,
communes: Array,
commandes: Array,
})
const isEdit = !!props.asset
const form = useForm({
nom: props.asset?.nom || '',
type: props.asset?.type || '',
marque: props.asset?.marque || '',
modele: props.asset?.modele || '',
numero_serie: props.asset?.numero_serie || '',
emplacement: props.asset?.emplacement || '',
commune_id: props.asset?.commune_id || '',
date_achat: props.asset?.date_achat ? props.asset.date_achat.substring(0, 10) : '',
date_fin_garantie: props.asset?.date_fin_garantie ? props.asset.date_fin_garantie.substring(0, 10) : '',
statut: props.asset?.statut || 'en_service',
commande_id: props.asset?.commande_id || '',
code_ean: props.asset?.code_ean || '',
notes: props.asset?.notes || '',
})
const isSearchingEan = ref(false)
const eanError = ref('')
const eanSuccess = ref('')
async function fetchEanDetails() {
if (!form.code_ean) return
isSearchingEan.value = true
eanError.value = ''
eanSuccess.value = ''
try {
const response = await fetch(`/api/ean-lookup/${form.code_ean}`)
if (!response.ok) {
throw new Error('API limit or error')
}
const data = await response.json()
if (data.code === 'OK' && data.items && data.items.length > 0) {
const item = data.items[0]
if (item.title && !form.nom) form.nom = item.title
if (item.brand && !form.marque) form.marque = item.brand
if (item.model && !form.modele) form.modele = item.model
// Infer type loosely
if (!form.type && item.category) {
const cat = item.category.toLowerCase()
if (cat.includes('server') || cat.includes('serveur')) form.type = 'Serveur'
else if (cat.includes('switch') || cat.includes('router') || cat.includes('network')) form.type = 'Switch'
else if (cat.includes('storage') || cat.includes('nas')) form.type = 'NAS'
else form.type = item.category.split('>').pop().trim()
}
eanSuccess.value = "Informations pré-remplies avec succès."
} else {
eanError.value = 'Aucun produit trouvé pour ce code.'
}
} catch (error) {
eanError.value = 'Erreur API ou limite atteinte.'
} finally {
isSearchingEan.value = false
}
}
function submit() {
if (isEdit) {
form.put(route('assets.update', props.asset.id))
} else {
form.post(route('assets.store'))
}
}
</script>
<template>
<Head :title="isEdit ? 'Modifier Asset' : 'Nouvel Asset'" />
<AuthenticatedLayout>
<template #header>
<div class="flex items-center gap-3">
<Link :href="route('assets.index')" class="text-gray-400 hover:text-gray-600 transition-colors">
<svg class="h-5 w-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7" />
</svg>
</Link>
<h1 class="text-xl font-semibold text-gray-900">{{ isEdit ? 'Modifier l\'équipement' : 'Ajouter un équipement' }}</h1>
</div>
</template>
<div class="max-w-4xl pb-12">
<form @submit.prevent="submit" class="space-y-6">
<!-- Autocomplétion EAN -->
<div class="rounded-xl bg-indigo-50 p-6 shadow-sm border border-indigo-100 mb-6">
<h2 class="mb-3 text-sm font-semibold uppercase tracking-wide text-indigo-800 flex items-center gap-2">
<svg class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v1m6 11h2m-6 0h-2v4m0-11v3m0 0h.01M12 12h4.01M16 20h4M4 12h4m12 0h.01M5 8h2a1 1 0 001-1V5a1 1 0 00-1-1H5a1 1 0 00-1 1v2a1 1 0 001 1zm14 0h2a1 1 0 001-1V5a1 1 0 00-1-1h-2a1 1 0 00-1 1v2a1 1 0 001 1zM5 20h2a1 1 0 001-1v-2a1 1 0 00-1-1H5a1 1 0 00-1 1v2a1 1 0 001 1z" />
</svg>
Pré-remplissage Magique par Code-Barres
</h2>
<div class="flex items-end gap-4">
<div class="flex-1">
<label class="block text-sm font-medium text-indigo-700">Scanner ou Saisir le Code EAN/UPC</label>
<input v-model="form.code_ean" type="text" @keyup.enter.prevent="fetchEanDetails"
class="mt-1 block w-full rounded-lg border-indigo-200 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm font-mono" placeholder="ex: 0884116301292" />
</div>
<button type="button" @click="fetchEanDetails" :disabled="isSearchingEan || !form.code_ean"
class="rounded-lg bg-indigo-600 px-4 py-2 mt-1 text-sm font-medium text-white shadow hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 disabled:bg-indigo-300 transition-colors flex items-center gap-2">
<svg v-if="isSearchingEan" class="animate-spin h-4 w-4 text-white" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
</svg>
Rechercher
</button>
</div>
<p v-if="eanError" class="mt-2 text-xs font-semibold text-red-600">{{ eanError }}</p>
<p v-if="eanSuccess" class="mt-2 text-xs font-semibold text-green-600">{{ eanSuccess }}</p>
</div>
<!-- Informations de base -->
<div class="rounded-xl bg-white p-6 shadow-sm border border-gray-100">
<h2 class="mb-5 text-sm font-semibold uppercase tracking-wide text-gray-500 font-bold">Identification de l'asset</h2>
<div class="grid gap-6 sm:grid-cols-2">
<div class="sm:col-span-1">
<label class="block text-sm font-medium text-gray-700 font-bold">Nom / Hostname</label>
<input v-model="form.nom" type="text" required class="mt-1 block w-full rounded-lg border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm" placeholder="ex: SRV-SQL-01" />
</div>
<div>
<label class="block text-sm font-medium text-gray-700 font-bold">Type de matériel</label>
<input v-model="form.type" list="asset-types" required class="mt-1 block w-full rounded-lg border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm" placeholder="ex: Serveur" />
<datalist id="asset-types">
<option value="Serveur" />
<option value="Switch" />
<option value="NAS" />
<option value="Baie de stockage" />
<option value="Onduleur" />
<option value="Firewall" />
<option value="Cœur de réseau" />
</datalist>
</div>
<div>
<label class="block text-sm font-medium text-gray-700">Marque</label>
<input v-model="form.marque" type="text" class="mt-1 block w-full rounded-lg border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm" placeholder="ex: Dell" />
</div>
<div>
<label class="block text-sm font-medium text-gray-700">Modèle</label>
<input v-model="form.modele" type="text" class="mt-1 block w-full rounded-lg border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm" placeholder="ex: PowerEdge R640" />
</div>
<div>
<label class="block text-sm font-medium text-gray-700">Numéro de série / SN / Tag</label>
<input v-model="form.numero_serie" type="text" class="mt-1 block w-full rounded-lg border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm font-mono" placeholder="ex: ABC123D" />
</div>
<div>
<label class="block text-sm font-medium text-gray-700">Statut actuel</label>
<select v-model="form.statut" required class="mt-1 block w-full rounded-lg border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm">
<option value="en_service">En service</option>
<option value="hors_service">Hors service</option>
<option value="en_reparation">En réparation</option>
<option value="stock">En stock / Spare</option>
</select>
</div>
</div>
</div>
<!-- Emplacement et Commune -->
<div class="rounded-xl bg-white p-6 shadow-sm border border-gray-100">
<h2 class="mb-5 text-sm font-semibold uppercase tracking-wide text-gray-500 font-bold">Localisation et Affectation</h2>
<div class="grid gap-6 sm:grid-cols-2">
<div>
<label class="block text-sm font-medium text-gray-700">Ville / Commune</label>
<select v-model="form.commune_id" class="mt-1 block w-full rounded-lg border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm">
<option value="">Infrastructure Globale (Agglo)</option>
<option v-for="c in communes" :key="c.id" :value="c.id">{{ c.nom }}</option>
</select>
</div>
<div>
<label class="block text-sm font-medium text-gray-700">Emplacement précis / Site</label>
<input v-model="form.emplacement" type="text" class="mt-1 block w-full rounded-lg border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm" placeholder="ex: Datacenter Local Lyon - Rack A2 - 12U" />
</div>
</div>
</div>
<!-- Dates et Garanties -->
<div class="rounded-xl bg-white p-6 shadow-sm border border-gray-100">
<h2 class="mb-5 text-sm font-semibold uppercase tracking-wide text-gray-500 font-bold">Cycle de vie & Garanties</h2>
<div class="grid gap-6 sm:grid-cols-2">
<div>
<label class="block text-sm font-medium text-gray-700">Date d'achat / mise en service</label>
<input v-model="form.date_achat" type="date" class="mt-1 block w-full rounded-lg border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm" />
</div>
<div>
<label class="block text-sm font-medium text-gray-700 font-bold">Fin de garantie constructeur</label>
<input v-model="form.date_fin_garantie" type="date" required class="mt-1 block w-full rounded-lg border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm" />
<p class="mt-1 text-xs text-gray-500">Cette date sera affichée dans le calendrier global.</p>
</div>
</div>
</div>
<!-- Lien Commande -->
<div class="rounded-xl bg-white p-6 shadow-sm border border-gray-100">
<h2 class="mb-5 text-sm font-semibold uppercase tracking-wide text-gray-500 font-bold">Achat & Commande</h2>
<div>
<label class="block text-sm font-medium text-gray-700">Commande associée (optionnel)</label>
<select v-model="form.commande_id" class="mt-1 block w-full rounded-lg border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm">
<option value="">Aucune commande liée</option>
<option v-for="cmd in commandes" :key="cmd.id" :value="cmd.id">
N° {{ cmd.numero_commande ?? 'Sans-N' }} - {{ cmd.objet }}
</option>
</select>
<p class="mt-1 text-xs text-gray-500">Permet de retrouver l'origine de l'achat et les justificatifs.</p>
</div>
</div>
<!-- Notes -->
<div class="rounded-xl bg-white p-6 shadow-sm border border-gray-100">
<label class="block text-sm font-medium text-gray-700 font-bold mb-2">Notes techniques / Configuration</label>
<textarea v-model="form.notes" rows="4" class="block w-full rounded-lg border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm" placeholder="IP, VLANs, rôles du serveur..."></textarea>
</div>
<div class="flex items-center justify-end gap-3">
<Link :href="route('assets.index')" class="text-sm font-medium text-gray-600 hover:text-gray-900 transition-colors">Annuler</Link>
<button type="submit" :disabled="form.processing"
class="rounded-lg bg-indigo-600 px-6 py-2.5 text-sm font-semibold text-white shadow-sm hover:bg-indigo-700 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600 disabled:opacity-50 transition-colors">
{{ isEdit ? 'Enregistrer les modifications' : 'Ajouter l\'équipement' }}
</button>
<button v-if="isEdit" type="button" @click="confirmDelete"
class="ml-4 rounded-lg bg-red-50 px-4 py-2 text-sm font-medium text-red-600 hover:bg-red-100 transition-colors">
Supprimer
</button>
</div>
</form>
</div>
</AuthenticatedLayout>
</template>
<script>
import { router } from '@inertiajs/vue3'
export default {
methods: {
confirmDelete() {
if (confirm('Êtes-vous sûr de vouloir supprimer cet équipement ?')) {
router.delete(route('assets.destroy', this.asset.id))
}
}
}
}
</script>

View File

@@ -0,0 +1,158 @@
<script setup>
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout.vue'
import Pagination from '@/Components/Pagination.vue'
import { Head, Link, router } from '@inertiajs/vue3'
import { ref, reactive } from 'vue'
const props = defineProps({
assets: Object,
communes: Array,
types: Array,
filters: Object,
})
const filters = reactive({
search: props.filters.search || '',
type: props.filters.type || '',
commune_id: props.filters.commune_id || '',
})
function applyFilters() {
router.get(route('assets.index'), filters, { preserveState: true, replace: true })
}
function formatDate(d) {
if (!d) return '—'
return new Intl.DateTimeFormat('fr-FR').format(new Date(d))
}
const statutLabels = {
en_service: 'En service',
hors_service: 'Hors service',
en_reparation: 'En réparation',
stock: 'En stock',
}
const statutColors = {
en_service: 'bg-green-100 text-green-800',
hors_service: 'bg-red-100 text-red-800',
en_reparation: 'bg-orange-100 text-orange-800',
stock: 'bg-blue-100 text-blue-800',
}
function checkWarranty(date) {
if (!date) return 'text-gray-400'
const today = new Date()
const exp = new Date(date)
if (exp < today) return 'text-red-600 font-bold'
const diff = (exp - today) / (1000 * 60 * 60 * 24)
if (diff <= 30) return 'text-orange-600 font-bold'
return 'text-gray-600'
}
</script>
<template>
<Head title="Inventaire Infrastructure (Assets)" />
<AuthenticatedLayout>
<template #header>
<div class="flex items-center justify-between">
<h1 class="text-xl font-semibold text-gray-900">Assets (Hardware & Infra)</h1>
<Link :href="route('assets.create')"
class="rounded-lg bg-indigo-600 px-4 py-2 text-sm font-medium text-white hover:bg-indigo-700 transition-colors">
+ Nouvel Asset
</Link>
</div>
</template>
<div class="space-y-4">
<!-- Filtres -->
<div class="rounded-xl bg-white p-4 shadow-sm border border-gray-100">
<div class="grid gap-3 sm:grid-cols-2 lg:grid-cols-4">
<input v-model="filters.search" @input="applyFilters" type="text" placeholder="Recherche (SN, Nom, Modèle)..."
class="rounded-lg border border-gray-300 px-3 py-2 text-sm focus:border-indigo-500 focus:outline-none placeholder-gray-400" />
<select v-model="filters.type" @change="applyFilters"
class="rounded-lg border border-gray-300 px-3 py-2 text-sm focus:border-indigo-500 focus:outline-none">
<option value="">Tous les types</option>
<option v-for="t in types" :key="t" :value="t">{{ t }}</option>
<option value="Serveur">Serveur</option>
<option value="Switch">Switch</option>
<option value="NAS">NAS</option>
<option value="Baie de stockage">Baie de stockage</option>
<option value="Onduleur">Onduleur</option>
</select>
<select v-model="filters.commune_id" @change="applyFilters"
class="rounded-lg border border-gray-300 px-3 py-2 text-sm focus:border-indigo-500 focus:outline-none">
<option value="">Partout (Agglo)</option>
<option v-for="c in communes" :key="c.id" :value="c.id">{{ c.nom }}</option>
</select>
</div>
</div>
<!-- Table -->
<div class="rounded-xl bg-white shadow-sm border border-gray-100 overflow-hidden">
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-100 text-sm">
<thead class="bg-gray-50">
<tr>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Matériel</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Type</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">S/N</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Ville / Site</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Fin Garantie</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Statut</th>
<th class="px-4 py-3 text-center text-xs font-medium text-gray-500 uppercase">Actions</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-50">
<tr v-for="asset in assets.data" :key="asset.id" class="hover:bg-gray-50 transition-colors">
<td class="px-4 py-3">
<div class="font-medium text-gray-900">{{ asset.nom }}</div>
<div class="text-xs text-gray-500">{{ asset.marque }} {{ asset.modele }}</div>
</td>
<td class="px-4 py-3 whitespace-nowrap text-gray-600">
<span class="px-2 py-0.5 rounded border border-gray-200 bg-gray-50 text-[10px] uppercase font-bold text-gray-500">
{{ asset.type }}
</span>
</td>
<td class="px-4 py-3 whitespace-nowrap font-mono text-xs text-gray-600">{{ asset.numero_serie ?? '—' }}</td>
<td class="px-4 py-3">
<div class="text-gray-900">{{ asset.commune?.nom ?? 'Agglo' }}</div>
<div class="text-xs text-gray-500">{{ asset.emplacement ?? '—' }}</div>
</td>
<td class="px-4 py-3 whitespace-nowrap" :class="checkWarranty(asset.date_fin_garantie)">
{{ formatDate(asset.date_fin_garantie) }}
<span v-if="checkWarranty(asset.date_fin_garantie).includes('red')" class="ml-1" title="Expirée"></span>
<span v-else-if="checkWarranty(asset.date_fin_garantie).includes('orange')" class="ml-1" title="Proche échéance"></span>
</td>
<td class="px-4 py-3 whitespace-nowrap">
<span :class="['px-2 py-0.5 rounded-full text-xs font-medium', statutColors[asset.statut]]">
{{ statutLabels[asset.statut] }}
</span>
</td>
<td class="px-4 py-3 text-center">
<div class="flex items-center justify-center gap-2">
<Link :href="route('assets.show', asset.id)"
class="text-gray-400 hover:text-blue-600 transition-colors" title="Afficher les détails">
<svg class="h-5 w-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z" />
</svg>
</Link>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div v-if="!assets.data.length" class="py-12 text-center text-gray-400">
Aucun matériel trouvé.
</div>
<div class="px-4 py-3 border-t border-gray-100">
<Pagination :links="assets.links" />
</div>
</div>
</div>
</AuthenticatedLayout>
</template>

View File

@@ -0,0 +1,151 @@
<script setup>
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout.vue'
import { Head, Link } from '@inertiajs/vue3'
const props = defineProps({
asset: Object,
})
function formatDate(d) {
if (!d) return '—'
return new Intl.DateTimeFormat('fr-FR').format(new Date(d))
}
const statutLabels = {
en_service: 'En service',
hors_service: 'Hors service',
en_reparation: 'En réparation',
stock: 'En stock',
}
const statutColors = {
en_service: 'bg-green-100 text-green-800',
hors_service: 'bg-red-100 text-red-800',
en_reparation: 'bg-orange-100 text-orange-800',
stock: 'bg-blue-100 text-blue-800',
}
function checkWarranty(date) {
if (!date) return 'text-gray-400'
const today = new Date()
const exp = new Date(date)
if (exp < today) return 'text-red-600 font-bold'
const diff = (exp - today) / (1000 * 60 * 60 * 24)
if (diff <= 30) return 'text-orange-600 font-bold'
return 'text-gray-600'
}
</script>
<template>
<Head :title="asset.nom" />
<AuthenticatedLayout>
<template #header>
<div class="flex items-center justify-between">
<div class="flex items-center gap-3">
<Link :href="route('assets.index')" class="text-gray-400 hover:text-gray-600 transition-colors">
<svg class="h-5 w-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7" />
</svg>
</Link>
<div>
<h1 class="text-xl font-semibold text-gray-900">{{ asset.nom }}</h1>
<p class="text-sm text-gray-500">{{ asset.type }} - {{ asset.marque }} {{ asset.modele }}</p>
</div>
</div>
<!-- Action Buttons: Edit -->
<Link :href="route('assets.edit', asset.id)"
class="rounded-lg bg-indigo-600 px-4 py-2 text-sm font-medium text-white hover:bg-indigo-700 transition-colors">
Modifier
</Link>
</div>
</template>
<div class="grid gap-6 lg:grid-cols-3">
<div class="space-y-6 lg:col-span-2">
<!-- Informations de base -->
<div class="rounded-xl bg-white p-6 shadow-sm border border-gray-100">
<h2 class="mb-5 text-sm font-semibold uppercase tracking-wide text-gray-500">Détails du matériel</h2>
<div class="grid gap-4 sm:grid-cols-2">
<div>
<p class="text-xs text-gray-500">Nom / Hostname</p>
<p class="mt-0.5 font-medium text-gray-900">{{ asset.nom }}</p>
</div>
<div>
<p class="text-xs text-gray-500">Type de matériel</p>
<p class="mt-0.5 font-medium text-gray-900">{{ asset.type }}</p>
</div>
<div>
<p class="text-xs text-gray-500">Marque & Modèle</p>
<p class="mt-0.5 font-medium text-gray-900">{{ asset.marque || '—' }} {{ asset.modele || '' }}</p>
</div>
<div>
<p class="text-xs text-gray-500">Code EAN/UPC</p>
<p class="mt-0.5 font-mono text-sm text-gray-900">{{ asset.code_ean || '—' }}</p>
</div>
<div>
<p class="text-xs text-gray-500 font-bold">Numéro de série / SN</p>
<p class="mt-0.5 font-mono text-sm text-gray-900">{{ asset.numero_serie || '—' }}</p>
</div>
<div>
<p class="text-xs text-gray-500 border-t pt-4 mt-2">Statut actuel</p>
<span :class="['mt-2 inline-block px-2 py-0.5 rounded-full text-xs font-medium', statutColors[asset.statut]]">
{{ statutLabels[asset.statut] }}
</span>
</div>
</div>
</div>
<!-- Notes / Config -->
<div v-if="asset.notes" class="rounded-xl bg-white p-6 shadow-sm border border-gray-100">
<h2 class="mb-4 text-sm font-semibold uppercase tracking-wide text-gray-500">Notes & Configuration</h2>
<div class="whitespace-pre-wrap text-sm text-gray-700">{{ asset.notes }}</div>
</div>
</div>
<div class="space-y-6 lg:col-span-1">
<!-- Localisation -->
<div class="rounded-xl bg-white p-6 shadow-sm border border-gray-100">
<h2 class="mb-4 text-sm font-semibold uppercase tracking-wide text-gray-500">Localisation</h2>
<div class="space-y-4">
<div>
<p class="text-xs text-gray-500">Ville / Commune</p>
<p class="mt-0.5 font-medium text-gray-900">{{ asset.commune?.nom || 'Infrastructure Globale (Agglo)' }}</p>
</div>
<div>
<p class="text-xs text-gray-500">Emplacement précis</p>
<p class="mt-0.5 font-medium text-gray-900">{{ asset.emplacement || '—' }}</p>
</div>
</div>
</div>
<!-- Cycle de vie & Garantie -->
<div class="rounded-xl bg-white p-6 shadow-sm border border-gray-100">
<h2 class="mb-4 text-sm font-semibold uppercase tracking-wide text-gray-500">Cycle de vie</h2>
<div class="space-y-4">
<div>
<p class="text-xs text-gray-500">Date d'achat</p>
<p class="mt-0.5 font-medium text-gray-900">{{ formatDate(asset.date_achat) }}</p>
</div>
<div>
<p class="text-xs text-gray-500">Fin de garantie (constructeur)</p>
<p class="mt-0.5 font-medium" :class="checkWarranty(asset.date_fin_garantie)">
{{ formatDate(asset.date_fin_garantie) }}
<span v-if="checkWarranty(asset.date_fin_garantie).includes('red')" class="ml-1" title="Expirée">⚠️ Expirée</span>
<span v-else-if="checkWarranty(asset.date_fin_garantie).includes('orange')" class="ml-1" title="Proche échéance">⏳ À renouveler</span>
</p>
</div>
</div>
</div>
<!-- Commande associée -->
<div v-if="asset.commande" class="rounded-xl bg-white p-6 shadow-sm border border-gray-100">
<h2 class="mb-4 text-sm font-semibold uppercase tracking-wide text-gray-500">Commande associée</h2>
<Link :href="route('commandes.show', asset.commande.id)" class="block rounded-lg border border-gray-100 bg-gray-50 p-4 hover:bg-gray-100 transition-colors">
<div class="font-medium text-indigo-600">{{ asset.commande.numero_commande }}</div>
<div class="mt-1 text-xs text-gray-600">{{ asset.commande.objet }}</div>
</Link>
</div>
</div>
</div>
</AuthenticatedLayout>
</template>

View File

@@ -0,0 +1,110 @@
<script setup>
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout.vue'
import { Head } from '@inertiajs/vue3'
import FullCalendar from '@fullcalendar/vue3'
import dayGridPlugin from '@fullcalendar/daygrid'
import interactionPlugin from '@fullcalendar/interaction'
import frLocale from '@fullcalendar/core/locales/fr'
import { ref, onMounted } from 'vue'
const calendarOptions = ref({
plugins: [dayGridPlugin, interactionPlugin],
initialView: 'dayGridMonth',
locale: frLocale,
headerToolbar: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,dayGridWeek'
},
events: route('calendar.events'),
eventClick: (info) => {
if (info.event.url) {
info.jsEvent.preventDefault()
window.location.href = info.event.url
}
},
eventDidMount: (info) => {
// Simple tooltip-like title on hover
info.el.title = info.event.title + (info.event.extendedProps.service ? ' - ' + info.event.extendedProps.service : '')
},
height: 'auto',
firstDay: 1, // Start on Monday
})
</script>
<template>
<Head title="Calendrier des écheances" />
<AuthenticatedLayout>
<template #header>
<h1 class="text-xl font-semibold text-gray-900">Calendrier des échéances</h1>
</template>
<div class="rounded-xl bg-white p-6 shadow-sm border border-gray-100">
<div class="calendar-container">
<FullCalendar :options="calendarOptions" />
</div>
<div class="mt-8 grid gap-4 sm:grid-cols-3">
<div class="flex items-center gap-2">
<span class="w-3 h-3 rounded-full bg-[#27ae60]"></span>
<span class="text-xs text-gray-600">Contrats Actifs</span>
</div>
<div class="flex items-center gap-2">
<span class="w-3 h-3 rounded-full bg-[#f39c12]"></span>
<span class="text-xs text-gray-600">Contrats à Renouveler / Proche écheance</span>
</div>
<div class="flex items-center gap-2">
<span class="w-3 h-3 rounded-full bg-[#3498db]"></span>
<span class="text-xs text-gray-600">Licences / SaaS</span>
</div>
<div class="flex items-center gap-2">
<span class="w-3 h-3 rounded-full bg-[#9b59b6]"></span>
<span class="text-xs text-gray-600">Noms de Domaine</span>
</div>
<div class="flex items-center gap-2">
<span class="w-3 h-3 rounded-full bg-[#e74c3c]"></span>
<span class="text-xs text-gray-600">Contrats Expirés</span>
</div>
</div>
</div>
</AuthenticatedLayout>
</template>
<style>
.fc {
font-family: inherit;
--fc-border-color: #f1f5f9;
--fc-button-bg-color: #4f46e5;
--fc-button-border-color: #4f46e5;
--fc-button-hover-bg-color: #4338ca;
--fc-button-active-bg-color: #4338ca;
--fc-today-bg-color: #f8fafc;
}
.fc .fc-toolbar-title {
font-size: 1.25rem;
font-weight: 700;
color: #1e293b;
}
.fc .fc-col-header-cell {
padding: 12px 0;
background: #f8fafc;
font-weight: 600;
font-size: 0.75rem;
text-transform: uppercase;
color: #64748b;
}
.fc-event {
cursor: pointer;
border: none !important;
padding: 2px 4px !important;
font-size: 0.75rem !important;
}
.fc-daygrid-event {
white-space: normal !important;
align-items: center;
}
</style>

View File

@@ -6,6 +6,7 @@ import { Head, Link, useForm } from '@inertiajs/vue3'
const props = defineProps({
services: Array,
fournisseurs: Array,
communes: Array,
categories: Array,
articles: Array,
})
@@ -13,6 +14,7 @@ const props = defineProps({
const form = useForm({
service_id: '',
fournisseur_id: '',
commune_id: '',
objet: '',
description: '',
justification: '',
@@ -77,6 +79,15 @@ function submit() {
</select>
</div>
<div>
<label class="block text-sm font-medium text-gray-700">Ville / Commune</label>
<select v-model="form.commune_id"
class="mt-1 block w-full rounded-lg border border-gray-300 px-3 py-2 text-sm shadow-sm focus:border-blue-500 focus:outline-none">
<option value=""> Non défini </option>
<option v-for="c in communes" :key="c.id" :value="c.id">{{ c.nom }}</option>
</select>
</div>
<div>
<label class="block text-sm font-medium text-gray-700">Priorité</label>
<select v-model="form.priorite"

View File

@@ -8,6 +8,7 @@ const props = defineProps({
commande: Object,
services: Array,
fournisseurs: Array,
communes: Array,
categories: Array,
articles: Array,
})
@@ -15,6 +16,7 @@ const props = defineProps({
const form = useForm({
service_id: props.commande.service_id,
fournisseur_id: props.commande.fournisseur_id ?? '',
commune_id: props.commande.commune_id ?? '',
objet: props.commande.objet,
description: props.commande.description ?? '',
justification: props.commande.justification ?? '',
@@ -76,6 +78,14 @@ const showReceived = ['commandee','partiellement_recue','recue_complete'].includ
<option v-for="f in fournisseurs" :key="f.id" :value="f.id">{{ f.nom }}</option>
</select>
</div>
<div>
<label class="block text-sm font-medium text-gray-700">Ville / Commune</label>
<select v-model="form.commune_id"
class="mt-1 block w-full rounded-lg border border-gray-300 px-3 py-2 text-sm shadow-sm focus:border-blue-500 focus:outline-none">
<option value=""> Non défini </option>
<option v-for="c in communes" :key="c.id" :value="c.id">{{ c.nom }}</option>
</select>
</div>
<div>
<label class="block text-sm font-medium text-gray-700">Priorité</label>
<select v-model="form.priorite"

View File

@@ -11,13 +11,24 @@ const props = defineProps({
commandes: Object,
services: Array,
fournisseurs: Array,
communes: Array,
filters: Object,
})
const page = usePage()
const statuts = page.props.config?.statuts ?? {}
const filters = reactive({ ...props.filters })
const filters = reactive({
search: '',
service_id: '',
fournisseur_id: '',
commune_id: '',
statut: '',
priorite: '',
date_from: '',
date_to: '',
...props.filters
})
const deleteTarget = ref(null)
function applyFilters() {
@@ -97,6 +108,12 @@ function formatCurrency(v) {
<option value="haute">Haute</option>
<option value="normale">Normale</option>
</select>
<select v-model="filters.commune_id" @change="applyFilters"
class="rounded-lg border border-gray-300 px-3 py-2 text-sm focus:border-blue-500 focus:outline-none">
<option value="">Toutes communes</option>
<option v-for="c in communes" :key="c.id" :value="c.id">{{ c.nom }}</option>
</select>
</div>
<div class="mt-3 grid gap-3 sm:grid-cols-3">
@@ -120,6 +137,7 @@ function formatCurrency(v) {
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">N°</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Objet</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Service</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Ville</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Fournisseur</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Statut</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Priorité</th>
@@ -141,6 +159,7 @@ function formatCurrency(v) {
<p class="truncate text-gray-800">{{ cmd.objet }}</p>
</td>
<td class="px-4 py-3 whitespace-nowrap text-gray-600">{{ cmd.service?.nom }}</td>
<td class="px-4 py-3 whitespace-nowrap text-gray-600">{{ cmd.commune?.nom ?? '—' }}</td>
<td class="px-4 py-3 whitespace-nowrap text-gray-600">{{ cmd.fournisseur?.nom ?? '—' }}</td>
<td class="px-4 py-3"><StatutBadge :statut="cmd.statut" /></td>
<td class="px-4 py-3"><PrioriteBadge :priorite="cmd.priorite" /></td>

View File

@@ -96,6 +96,10 @@ const transitionColors = {
<p class="text-xs text-gray-500">Service demandeur</p>
<p class="mt-0.5 font-medium text-gray-900">{{ commande.service?.nom ?? '—' }}</p>
</div>
<div>
<p class="text-xs text-gray-500">Ville / Commune</p>
<p class="mt-0.5 font-medium text-gray-900">{{ commande.commune?.nom ?? '—' }}</p>
</div>
<div>
<p class="text-xs text-gray-500">Fournisseur</p>
<p class="mt-0.5 font-medium text-gray-900">{{ commande.fournisseur?.nom ?? '—' }}</p>
@@ -160,6 +164,35 @@ const transitionColors = {
:show-received="['commandee','partiellement_recue','recue_complete','cloturee'].includes(commande.statut)" />
</div>
<!-- Matériels associés (Assets) -->
<div v-if="commande.assets?.length" class="rounded-xl bg-white p-5 shadow-sm border border-gray-100">
<div class="flex items-center justify-between mb-4">
<h2 class="text-sm font-semibold uppercase tracking-wide text-gray-500">Matériels livrés (Assets)</h2>
<span class="px-2 py-0.5 rounded-full bg-blue-100 text-blue-700 text-[10px] font-bold uppercase">{{ commande.assets.length }} équipements</span>
</div>
<div class="divide-y divide-gray-100">
<div v-for="asset in commande.assets" :key="asset.id" class="flex items-center justify-between py-3 first:pt-0 last:pb-0">
<div class="flex items-start gap-3">
<div class="mt-1 rounded bg-gray-100 p-2 text-gray-400">
<svg class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 3v2m6-2v2M9 19v2m6-2v2M5 9H3m2 6H3m18-6h-2m2 6h-2M7 19h10a2 2 0 002-2V7a2 2 0 00-2-2H7a2 2 0 00-2 2v10a2 2 0 002 2zM9 9h6v6H9V9z" />
</svg>
</div>
<div>
<Link :href="route('assets.show', asset.id)" class="font-medium text-gray-900 hover:text-blue-600 transition-colors">
{{ asset.nom }}
</Link>
<div class="text-xs text-gray-500 font-mono">{{ asset.numero_serie ?? 'Sans S/N' }} {{ asset.marque }} {{ asset.modele }}</div>
</div>
</div>
<div class="text-right">
<span class="block text-xs font-medium text-gray-900">{{ asset.type }}</span>
<span v-if="asset.date_fin_garantie" class="text-[10px] text-gray-500">Garantie jusqu'au {{ formatDate(asset.date_fin_garantie) }}</span>
</div>
</div>
</div>
</div>
<!-- Notes -->
<div v-if="commande.description || commande.justification || commande.notes || commande.notes_fournisseur"
class="rounded-xl bg-white p-5 shadow-sm border border-gray-100">

View File

@@ -0,0 +1,82 @@
<script setup>
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout.vue'
import { Head, useForm, router } from '@inertiajs/vue3'
import { ref } from 'vue'
defineProps({ communes: Array })
const showForm = ref(false)
const editTarget = ref(null)
const form = useForm({ nom: '', code_postal: '' })
const editForm = useForm({ nom: '', code_postal: '' })
function openEdit(c) {
editTarget.value = c
editForm.nom = c.nom; editForm.code_postal = c.code_postal ?? ''
}
function submitCreate() { form.post(route('communes.store'), { onSuccess: () => { showForm.value = false; form.reset() } }) }
function submitEdit() { editForm.put(route('communes.update', editTarget.value.id), { onSuccess: () => editTarget.value = null }) }
function deleteCommune(c) {
if (confirm(`Supprimer "${c.nom}" ?`)) router.delete(route('communes.destroy', c.id))
}
</script>
<template>
<Head title="Communes" />
<AuthenticatedLayout>
<template #header>
<div class="flex items-center justify-between">
<h1 class="text-xl font-semibold text-gray-900">Gestion des Communes</h1>
<button @click="showForm = !showForm" class="rounded-lg bg-indigo-600 px-4 py-2 text-sm font-medium text-white hover:bg-indigo-700 transition-colors">+ Ajouter</button>
</div>
</template>
<div v-if="showForm" class="mb-6 rounded-xl bg-white p-5 shadow-sm border border-indigo-200">
<form @submit.prevent="submitCreate" class="grid gap-3 sm:grid-cols-2">
<div>
<label class="block text-xs font-medium text-gray-600 mb-1">Nom de la commune *</label>
<input v-model="form.nom" type="text" required placeholder="ex: Béziers" class="block w-full rounded-lg border border-gray-300 px-3 py-2 text-sm focus:border-indigo-500 focus:outline-none" />
</div>
<div>
<label class="block text-xs font-medium text-gray-600 mb-1">Code Postal</label>
<input v-model="form.code_postal" type="text" placeholder="ex: 34500" class="block w-full rounded-lg border border-gray-300 px-3 py-2 text-sm focus:border-indigo-500 focus:outline-none" />
</div>
<div class="sm:col-span-2 flex gap-2">
<button type="submit" :disabled="form.processing" class="rounded-lg bg-indigo-600 px-4 py-2 text-sm font-medium text-white hover:bg-indigo-700 disabled:opacity-50 transition-colors">Créer</button>
<button type="button" @click="showForm = false" class="rounded-lg border border-gray-300 px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50 transition-colors">Annuler</button>
</div>
</form>
</div>
<div class="grid gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
<div v-for="c in communes" :key="c.id" class="rounded-xl bg-white p-5 shadow-sm border border-gray-100 hover:border-indigo-100 transition-all">
<template v-if="editTarget?.id !== c.id">
<div class="flex items-start justify-between">
<div>
<h3 class="font-semibold text-gray-900">{{ c.nom }}</h3>
<p v-if="c.code_postal" class="text-xs text-gray-400 mt-0.5">{{ c.code_postal }}</p>
</div>
<div class="flex gap-1">
<button @click="openEdit(c)" class="text-gray-400 hover:text-indigo-600 transition-colors p-1"><svg class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z" /></svg></button>
<button @click="deleteCommune(c)" class="text-gray-400 hover:text-red-600 transition-colors p-1"><svg class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" /></svg></button>
</div>
</div>
<div class="mt-3 flex gap-4 text-xs text-gray-500 pt-3 border-t border-gray-50">
<span>{{ c.commandes_count }} commandes</span>
<span>{{ c.contrats_count }} contrats</span>
</div>
</template>
<form v-else @submit.prevent="submitEdit" class="space-y-3">
<div><label class="block text-xs font-medium text-gray-600 mb-1">Nom *</label><input v-model="editForm.nom" type="text" required class="block w-full rounded-lg border border-gray-300 px-3 py-2 text-sm focus:border-indigo-500 focus:outline-none" /></div>
<div><label class="block text-xs font-medium text-gray-600 mb-1">CP</label><input v-model="editForm.code_postal" type="text" class="block w-full rounded-lg border border-gray-300 px-3 py-2 text-sm focus:border-indigo-500 focus:outline-none" /></div>
<div class="flex gap-2">
<button type="submit" :disabled="editForm.processing" class="flex-1 rounded-lg bg-indigo-600 px-3 py-2 text-sm font-medium text-white hover:bg-indigo-700 disabled:opacity-50 transition-colors">OK</button>
<button type="button" @click="editTarget = null" class="rounded-lg border border-gray-300 px-3 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50 transition-colors">X</button>
</div>
</form>
</div>
</div>
</AuthenticatedLayout>
</template>

View File

@@ -5,6 +5,7 @@ import { Head, Link, useForm } from '@inertiajs/vue3'
const props = defineProps({
services: Array,
fournisseurs: Array,
communes: Array,
statuts: Object,
})
@@ -12,6 +13,7 @@ const form = useForm({
titre: '',
description: '',
fournisseur_id: '',
commune_id: '',
service_id: props.services.length === 1 ? props.services[0].id : '',
date_debut: '',
date_echeance: '',
@@ -79,6 +81,15 @@ function submit() {
class="w-full rounded-lg border border-gray-200 bg-gray-50 px-3 py-2 text-sm text-gray-500" />
</div>
<div>
<label class="mb-1 block text-sm font-medium text-gray-700">Ville / Commune</label>
<select v-model="form.commune_id"
class="w-full rounded-lg border border-gray-300 px-3 py-2 text-sm focus:border-blue-500 focus:outline-none">
<option value=""> Non défini </option>
<option v-for="c in communes" :key="c.id" :value="c.id">{{ c.nom }}</option>
</select>
</div>
<div class="sm:col-span-2">
<label class="mb-1 block text-sm font-medium text-gray-700">Description</label>
<textarea v-model="form.description" rows="3"

View File

@@ -6,6 +6,7 @@ const props = defineProps({
contrat: Object,
services: Array,
fournisseurs: Array,
communes: Array,
statuts: Object,
})
@@ -13,6 +14,7 @@ const form = useForm({
titre: props.contrat.titre ?? '',
description: props.contrat.description ?? '',
fournisseur_id: props.contrat.fournisseur_id ?? '',
commune_id: props.contrat.commune_id ?? '',
service_id: props.contrat.service_id ?? (props.services.length === 1 ? props.services[0].id : ''),
date_debut: props.contrat.date_debut ?? '',
date_echeance: props.contrat.date_echeance ?? '',
@@ -80,6 +82,15 @@ function submit() {
class="w-full rounded-lg border border-gray-200 bg-gray-50 px-3 py-2 text-sm text-gray-500" />
</div>
<div>
<label class="mb-1 block text-sm font-medium text-gray-700">Ville / Commune</label>
<select v-model="form.commune_id"
class="w-full rounded-lg border border-gray-300 px-3 py-2 text-sm focus:border-blue-500 focus:outline-none">
<option value=""> Non défini </option>
<option v-for="c in communes" :key="c.id" :value="c.id">{{ c.nom }}</option>
</select>
</div>
<div class="sm:col-span-2">
<label class="mb-1 block text-sm font-medium text-gray-700">Description</label>
<textarea v-model="form.description" rows="3"

View File

@@ -9,13 +9,21 @@ const props = defineProps({
contrats: Object,
services: Array,
fournisseurs: Array,
communes: Array,
filters: Object,
statuts: Object,
})
const page = usePage()
const filters = reactive({ ...props.filters })
const filters = reactive({
search: '',
service_id: '',
fournisseur_id: '',
commune_id: '',
statut: '',
...props.filters
})
const deleteTarget = ref(null)
function applyFilters() {
@@ -93,6 +101,12 @@ const statutColors = {
<option value="">Tous les statuts</option>
<option v-for="(label, key) in statuts" :key="key" :value="key">{{ label }}</option>
</select>
<select v-model="filters.commune_id" @change="applyFilters"
class="rounded-lg border border-gray-300 px-3 py-2 text-sm focus:border-indigo-500 focus:outline-none">
<option value="">Toutes communes</option>
<option v-for="c in communes" :key="c.id" :value="c.id">{{ c.nom }}</option>
</select>
</div>
<div class="mt-3 flex justify-end">
@@ -111,6 +125,7 @@ const statutColors = {
<tr>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Titre</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Service</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Ville</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Fournisseur</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Statut</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Date début</th>
@@ -128,6 +143,7 @@ const statutColors = {
</Link>
</td>
<td class="px-4 py-3 whitespace-nowrap text-gray-600">{{ cnt.service?.nom }}</td>
<td class="px-4 py-3 whitespace-nowrap text-gray-600">{{ cnt.commune?.nom ?? '—' }}</td>
<td class="px-4 py-3 whitespace-nowrap text-gray-600">{{ cnt.fournisseur?.nom ?? '—' }}</td>
<td class="px-4 py-3">
<span :class="['inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium', statutColors[cnt.statut]]">

View File

@@ -71,6 +71,10 @@ const statutColors = {
<p class="text-xs text-gray-500">Service concerné</p>
<p class="mt-0.5 font-medium text-gray-900">{{ contrat.service?.nom ?? '—' }}</p>
</div>
<div>
<p class="text-xs text-gray-500">Ville / Commune</p>
<p class="mt-0.5 font-medium text-gray-900">{{ contrat.commune?.nom ?? '—' }}</p>
</div>
<div>
<p class="text-xs text-gray-500">Fournisseur</p>
<p class="mt-0.5 font-medium text-gray-900">{{ contrat.fournisseur?.nom ?? '—' }}</p>
@@ -101,6 +105,20 @@ const statutColors = {
</div>
</div>
</div>
<!-- Licences associées -->
<div v-if="contrat.licences?.length" class="mt-6 rounded-xl bg-white p-5 shadow-sm border border-gray-100">
<h2 class="mb-4 text-sm font-semibold uppercase tracking-wide text-gray-500">Licences & Abonnements liés</h2>
<div class="space-y-3">
<div v-for="lic in contrat.licences" :key="lic.id" class="flex items-center justify-between p-3 rounded-lg border border-gray-50 hover:bg-gray-50 transition-colors">
<div>
<div class="font-medium text-gray-900">{{ lic.nom }}</div>
<div class="text-xs text-gray-500">{{ lic.nombre_sieges_utilises }} / {{ lic.nombre_sieges_total }} sièges utilisés</div>
</div>
<Link :href="route('licences.edit', lic.id)" class="text-xs font-semibold text-indigo-600 hover:text-indigo-800">Afficher</Link>
</div>
</div>
</div>
</div>
<!-- Colonne droite (Pièces jointes) -->

View File

@@ -0,0 +1,152 @@
<script setup>
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout.vue'
import { Head, Link, useForm } from '@inertiajs/vue3'
const props = defineProps({
licence: Object,
contrats: Array,
fournisseurs: Array,
communes: Array,
})
const isEdit = !!props.licence
const form = useForm({
nom: props.licence?.nom || '',
contrat_id: props.licence?.contrat_id || '',
fournisseur_id: props.licence?.fournisseur_id || '',
commune_id: props.licence?.commune_id || '',
cle_licence: props.licence?.cle_licence || '',
nombre_sieges_total: props.licence?.nombre_sieges_total || 1,
nombre_sieges_utilises: props.licence?.nombre_sieges_utilises || 0,
date_acquisition: props.licence?.date_acquisition ? props.licence.date_acquisition.substring(0, 10) : '',
date_expiration: props.licence?.date_expiration ? props.licence.date_expiration.substring(0, 10) : '',
type_licence: props.licence?.type_licence || 'abonnement',
statut: props.licence?.statut || 'active',
notes: props.licence?.notes || '',
})
function submit() {
if (isEdit) {
form.put(route('licences.update', props.licence.id))
} else {
form.post(route('licences.store'))
}
}
</script>
<template>
<Head :title="isEdit ? 'Modifier Licence' : 'Nouvelle Licence'" />
<AuthenticatedLayout>
<template #header>
<div class="flex items-center gap-3">
<Link :href="route('licences.index')" class="text-gray-400 hover:text-gray-600 transition-colors">
<svg class="h-5 w-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7" />
</svg>
</Link>
<h1 class="text-xl font-semibold text-gray-900">{{ isEdit ? 'Modifier la licence' : 'Ajouter une licence' }}</h1>
</div>
</template>
<div class="max-w-4xl">
<form @submit.prevent="submit" class="space-y-6">
<!-- Section Informations Générales -->
<div class="rounded-xl bg-white p-6 shadow-sm border border-gray-100">
<h2 class="mb-5 text-sm font-semibold uppercase tracking-wide text-gray-500">Informations logicielles</h2>
<div class="grid gap-6 sm:grid-cols-2">
<div class="sm:col-span-2">
<label class="block text-sm font-medium text-gray-700">Nom du produit / logiciel</label>
<input v-model="form.nom" type="text" required class="mt-1 block w-full rounded-lg border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm" placeholder="ex: Microsoft 365 Business Standard" />
<div v-if="form.errors.nom" class="mt-1 text-xs text-red-600">{{ form.errors.nom }}</div>
</div>
<div>
<label class="block text-sm font-medium text-gray-700">Type de licence</label>
<select v-model="form.type_licence" required class="mt-1 block w-full rounded-lg border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm">
<option value="perpétuelle">Perpétuelle (achat unique)</option>
<option value="abonnement">Abonnement (annuel/mensuel)</option>
</select>
</div>
<div>
<label class="block text-sm font-medium text-gray-700">Statut</label>
<select v-model="form.statut" required class="mt-1 block w-full rounded-lg border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm">
<option value="active">Active</option>
<option value="expirée">Expirée</option>
<option value="résiliée">Résiliée</option>
</select>
</div>
</div>
</div>
<!-- Section Clé et Sièges -->
<div class="rounded-xl bg-white p-6 shadow-sm border border-gray-100">
<h2 class="mb-5 text-sm font-semibold uppercase tracking-wide text-gray-500">Clés et Utilisation</h2>
<div class="grid gap-6 sm:grid-cols-2">
<div class="sm:col-span-2">
<label class="block text-sm font-medium text-gray-700">Clé de licence (stockage sécurisé)</label>
<textarea v-model="form.cle_licence" rows="2" class="mt-1 block w-full rounded-lg border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm" placeholder="Saisissez la clé ou le code d'activation..."></textarea>
</div>
<div>
<label class="block text-sm font-medium text-gray-700">Nombre de sièges (Total)</label>
<input v-model.number="form.nombre_sieges_total" type="number" min="1" required class="mt-1 block w-full rounded-lg border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm" />
</div>
<div>
<label class="block text-sm font-medium text-gray-700">Nombre de sièges (Utilisés)</label>
<input v-model.number="form.nombre_sieges_utilises" type="number" min="0" required class="mt-1 block w-full rounded-lg border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm" />
</div>
</div>
</div>
<!-- Section Dates et Liens -->
<div class="rounded-xl bg-white p-6 shadow-sm border border-gray-100">
<h2 class="mb-5 text-sm font-semibold uppercase tracking-wide text-gray-500">Établissement & Dates</h2>
<div class="grid gap-6 sm:grid-cols-2">
<div>
<label class="block text-sm font-medium text-gray-700">Affectation Commune</label>
<select v-model="form.commune_id" class="mt-1 block w-full rounded-lg border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm">
<option value="">Non affectée (Agglo)</option>
<option v-for="c in communes" :key="c.id" :value="c.id">{{ c.nom }}</option>
</select>
</div>
<div>
<label class="block text-sm font-medium text-gray-700">Fournisseur</label>
<select v-model="form.fournisseur_id" required class="mt-1 block w-full rounded-lg border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm">
<option value="">Choisir un fournisseur</option>
<option v-for="f in fournisseurs" :key="f.id" :value="f.id">{{ f.nom }}</option>
</select>
</div>
<div>
<label class="block text-sm font-medium text-gray-700">Contrat lié (optionnel)</label>
<select v-model="form.contrat_id" class="mt-1 block w-full rounded-lg border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm">
<option value="">Aucun contrat spécifique</option>
<option v-for="cnt in contrats" :key="cnt.id" :value="cnt.id">{{ cnt.titre }}</option>
</select>
</div>
<div>
<label class="block text-sm font-medium text-gray-700">Date d'échéance / Expiration</label>
<input v-model="form.date_expiration" type="date" class="mt-1 block w-full rounded-lg border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm" />
</div>
</div>
</div>
<div class="flex items-center justify-end gap-3">
<Link :href="route('licences.index')" class="text-sm font-medium text-gray-600 hover:text-gray-900 transition-colors">Annuler</Link>
<button type="submit" :disabled="form.processing"
class="rounded-lg bg-indigo-600 px-6 py-2.5 text-sm font-semibold text-white shadow-sm hover:bg-indigo-700 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600 disabled:opacity-50 transition-colors">
{{ isEdit ? 'Enregistrer les modifications' : 'Créer la licence' }}
</button>
</div>
</form>
</div>
</AuthenticatedLayout>
</template>

View File

@@ -0,0 +1,141 @@
<script setup>
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout.vue'
import Pagination from '@/Components/Pagination.vue'
import { Head, Link, router } from '@inertiajs/vue3'
import { ref, reactive } from 'vue'
const props = defineProps({
licences: Object,
communes: Array,
fournisseurs: Array,
filters: Object,
})
const filters = reactive({
search: props.filters.search || '',
commune_id: props.filters.commune_id || '',
fournisseur_id: props.filters.fournisseur_id || '',
})
function applyFilters() {
router.get(route('licences.index'), filters, { preserveState: true, replace: true })
}
function formatDate(d) {
if (!d) return '—'
return new Intl.DateTimeFormat('fr-FR').format(new Date(d))
}
const statutColors = {
active: 'bg-green-100 text-green-800',
'expirée': 'bg-red-100 text-red-800',
'résiliée': 'bg-gray-100 text-gray-800',
}
function getUsageColor(rate) {
if (rate >= 90) return 'bg-red-500'
if (rate >= 75) return 'bg-orange-500'
return 'bg-blue-500'
}
</script>
<template>
<Head title="Gestion des Licences" />
<AuthenticatedLayout>
<template #header>
<div class="flex items-center justify-between">
<h1 class="text-xl font-semibold text-gray-900">Licences & Abonnements</h1>
<Link :href="route('licences.create')"
class="rounded-lg bg-indigo-600 px-4 py-2 text-sm font-medium text-white hover:bg-indigo-700 transition-colors">
+ Nouvelle licence
</Link>
</div>
</template>
<div class="space-y-4">
<!-- Filtres -->
<div class="rounded-xl bg-white p-4 shadow-sm border border-gray-100">
<div class="grid gap-3 sm:grid-cols-2 lg:grid-cols-4">
<input v-model="filters.search" @input="applyFilters" type="text" placeholder="Recherche produit..."
class="rounded-lg border border-gray-300 px-3 py-2 text-sm focus:border-indigo-500 focus:outline-none" />
<select v-model="filters.commune_id" @change="applyFilters"
class="rounded-lg border border-gray-300 px-3 py-2 text-sm focus:border-indigo-500 focus:outline-none">
<option value="">Toutes les communes</option>
<option v-for="c in communes" :key="c.id" :value="c.id">{{ c.nom }}</option>
</select>
<select v-model="filters.fournisseur_id" @change="applyFilters"
class="rounded-lg border border-gray-300 px-3 py-2 text-sm focus:border-indigo-500 focus:outline-none">
<option value="">Tous les fournisseurs</option>
<option v-for="f in fournisseurs" :key="f.id" :value="f.id">{{ f.nom }}</option>
</select>
</div>
</div>
<!-- Table -->
<div class="rounded-xl bg-white shadow-sm border border-gray-100 overflow-hidden">
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-100 text-sm">
<thead class="bg-gray-50">
<tr>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Produit / Logiciel</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Commune</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Fournisseur / Contrat</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Utilisation Sièges</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Expiration</th>
<th class="px-4 py-3 text-center text-xs font-medium text-gray-500 uppercase">Actions</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-50 text-gray-600">
<tr v-for="lic in licences.data" :key="lic.id" class="hover:bg-gray-50 transition-colors">
<td class="px-4 py-3">
<div class="font-medium text-gray-900">{{ lic.nom }}</div>
<div class="text-xs text-xs">{{ lic.type_licence }}</div>
</td>
<td class="px-4 py-3">{{ lic.commune?.nom ?? '—' }}</td>
<td class="px-4 py-3">
<div>{{ lic.fournisseur?.nom }}</div>
<div class="text-xs text-indigo-500" v-if="lic.contrat">
{{ lic.contrat.titre }}
</div>
</td>
<td class="px-4 py-3">
<div class="flex items-center gap-2">
<div class="w-24 h-2 bg-gray-100 rounded-full overflow-hidden">
<div :class="['h-full transition-all', getUsageColor((lic.nombre_sieges_utilises / lic.nombre_sieges_total) * 100)]"
:style="{ width: Math.min((lic.nombre_sieges_utilises / lic.nombre_sieges_total) * 100, 100) + '%' }">
</div>
</div>
<span class="text-xs font-bold">{{ lic.nombre_sieges_utilises }} / {{ lic.nombre_sieges_total }}</span>
</div>
</td>
<td class="px-4 py-3">
<span :class="['px-2 py-0.5 rounded-full text-xs font-medium', statutColors[lic.statut]]">
{{ lic.statut }}
</span>
<div class="mt-1 text-xs" v-if="lic.date_expiration">
Éxpire le {{ formatDate(lic.date_expiration) }}
</div>
</td>
<td class="px-4 py-3 text-center">
<div class="flex items-center justify-center gap-2">
<Link :href="route('licences.edit', lic.id)"
class="p-1 text-gray-400 hover:text-blue-600 transition-colors">
<svg class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z" />
</svg>
</Link>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="px-4 py-3 border-t border-gray-100">
<Pagination :links="licences.links" />
</div>
</div>
</div>
</AuthenticatedLayout>
</template>