feat: infrastructure assets management with warranty tracking and EAN lookup integration
This commit is contained in:
267
resources/js/Pages/Assets/Form.vue
Normal file
267
resources/js/Pages/Assets/Form.vue
Normal 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>
|
||||
158
resources/js/Pages/Assets/Index.vue
Normal file
158
resources/js/Pages/Assets/Index.vue
Normal 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>
|
||||
151
resources/js/Pages/Assets/Show.vue
Normal file
151
resources/js/Pages/Assets/Show.vue
Normal 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>
|
||||
Reference in New Issue
Block a user