Initial commit
This commit is contained in:
563
app/(main)/chantiers/[id]/execution-granulaire/page.tsx
Normal file
563
app/(main)/chantiers/[id]/execution-granulaire/page.tsx
Normal file
@@ -0,0 +1,563 @@
|
||||
'use client';
|
||||
|
||||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import { useParams } from 'next/navigation';
|
||||
import { Card } from 'primereact/card';
|
||||
import { Checkbox } from 'primereact/checkbox';
|
||||
import { Button } from 'primereact/button';
|
||||
import { ProgressBar } from 'primereact/progressbar';
|
||||
import { Badge } from 'primereact/badge';
|
||||
import { Toast } from 'primereact/toast';
|
||||
import { Accordion, AccordionTab } from 'primereact/accordion';
|
||||
import { TreeTable } from 'primereact/treetable';
|
||||
import { Column } from 'primereact/column';
|
||||
import { Dialog } from 'primereact/dialog';
|
||||
import { InputTextarea } from 'primereact/inputtextarea';
|
||||
import { Avatar } from 'primereact/avatar';
|
||||
import { apiClient } from '../../../../../services/api-client';
|
||||
|
||||
/**
|
||||
* Interface pour les tâches d'exécution avec état de completion
|
||||
*/
|
||||
interface TacheExecution {
|
||||
id: string;
|
||||
nom: string;
|
||||
description?: string;
|
||||
ordreExecution: number;
|
||||
dureeEstimeeMinutes?: number;
|
||||
critique: boolean;
|
||||
bloquante: boolean;
|
||||
priorite: 'BASSE' | 'NORMALE' | 'HAUTE';
|
||||
niveauQualification?: string;
|
||||
nombreOperateursRequis: number;
|
||||
conditionsMeteo: string;
|
||||
outilsRequis?: string[];
|
||||
materiauxRequis?: string[];
|
||||
|
||||
// État d'exécution
|
||||
terminee: boolean;
|
||||
dateCompletion?: Date;
|
||||
completeepar?: string;
|
||||
commentaires?: string;
|
||||
tempsRealise?: number; // en minutes
|
||||
difficulteRencontree?: 'AUCUNE' | 'FAIBLE' | 'MOYENNE' | 'ELEVEE';
|
||||
}
|
||||
|
||||
interface SousPhaseExecution {
|
||||
id: string;
|
||||
nom: string;
|
||||
description?: string;
|
||||
ordreExecution: number;
|
||||
taches: TacheExecution[];
|
||||
|
||||
// Calculé automatiquement
|
||||
avancement: number; // % basé sur les tâches terminées
|
||||
tachesTerminees: number;
|
||||
totalTaches: number;
|
||||
dureeRealisee: number; // en minutes
|
||||
dureeEstimee: number; // en minutes
|
||||
}
|
||||
|
||||
interface PhaseExecution {
|
||||
id: string;
|
||||
nom: string;
|
||||
description?: string;
|
||||
ordreExecution: number;
|
||||
sousPhases: SousPhaseExecution[];
|
||||
|
||||
// Calculé automatiquement
|
||||
avancement: number; // % basé sur les sous-phases
|
||||
sousPhasesTerminees: number;
|
||||
totalSousPhases: number;
|
||||
}
|
||||
|
||||
interface ChantierExecution {
|
||||
id: string;
|
||||
nom: string;
|
||||
client: string;
|
||||
dateDebut: Date;
|
||||
dateFinPrevue: Date;
|
||||
phases: PhaseExecution[];
|
||||
|
||||
// Avancement global calculé
|
||||
avancementGlobal: number; // % basé sur toutes les tâches
|
||||
totalTachesTerminees: number;
|
||||
totalTaches: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Page d'exécution granulaire d'un chantier
|
||||
* Permet de cocher les tâches terminées pour un suivi précis de l'avancement
|
||||
*/
|
||||
const ExecutionGranulaireChantier = () => {
|
||||
const { id } = useParams();
|
||||
const toast = useRef<Toast>(null);
|
||||
|
||||
// États principaux
|
||||
const [chantier, setChantier] = useState<ChantierExecution | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [saving, setSaving] = useState(false);
|
||||
|
||||
// États pour les modals
|
||||
const [showCommentDialog, setShowCommentDialog] = useState(false);
|
||||
const [selectedTache, setSelectedTache] = useState<TacheExecution | null>(null);
|
||||
const [commentaires, setCommentaires] = useState('');
|
||||
const [tempsRealise, setTempsRealise] = useState<number>(0);
|
||||
const [difficulte, setDifficulte] = useState<'AUCUNE' | 'FAIBLE' | 'MOYENNE' | 'ELEVEE'>('AUCUNE');
|
||||
|
||||
// États pour la vue
|
||||
const [activeIndex, setActiveIndex] = useState<number>(0);
|
||||
const [expandedKeys, setExpandedKeys] = useState<any>({});
|
||||
|
||||
useEffect(() => {
|
||||
if (id) {
|
||||
loadChantierExecution(id as string);
|
||||
}
|
||||
}, [id]);
|
||||
|
||||
/**
|
||||
* Charge les données d'exécution du chantier
|
||||
*/
|
||||
const loadChantierExecution = async (chantierId: string) => {
|
||||
try {
|
||||
setLoading(true);
|
||||
|
||||
// Charger les informations de base du chantier
|
||||
const chantierResponse = await apiClient.get(`/chantiers/${chantierId}`);
|
||||
const chantierData = chantierResponse.data;
|
||||
|
||||
// Charger les phases avec leurs sous-phases et tâches
|
||||
const phasesResponse = await apiClient.get(`/chantiers/${chantierId}/phases`);
|
||||
const phasesData = phasesResponse.data;
|
||||
|
||||
// Pour chaque phase, charger les tâches d'exécution
|
||||
const phasesWithExecution = await Promise.all(
|
||||
phasesData.map(async (phase: any) => {
|
||||
const sousPhasesWithTaches = await Promise.all(
|
||||
phase.sousPhases?.map(async (sousPhase: any) => {
|
||||
// Charger les tâches et leur état d'exécution
|
||||
const tachesExecution = await loadTachesExecution(chantierId, sousPhase.id);
|
||||
|
||||
// Calculer l'avancement de la sous-phase
|
||||
const tachesTerminees = tachesExecution.filter(t => t.terminee).length;
|
||||
const avancement = tachesExecution.length > 0 ?
|
||||
(tachesTerminees / tachesExecution.length) * 100 : 0;
|
||||
|
||||
const dureeRealisee = tachesExecution
|
||||
.filter(t => t.terminee && t.tempsRealise)
|
||||
.reduce((sum, t) => sum + (t.tempsRealise || 0), 0);
|
||||
|
||||
const dureeEstimee = tachesExecution
|
||||
.reduce((sum, t) => sum + (t.dureeEstimeeMinutes || 0), 0);
|
||||
|
||||
return {
|
||||
...sousPhase,
|
||||
taches: tachesExecution,
|
||||
avancement: Math.round(avancement),
|
||||
tachesTerminees,
|
||||
totalTaches: tachesExecution.length,
|
||||
dureeRealisee,
|
||||
dureeEstimee
|
||||
};
|
||||
}) || []
|
||||
);
|
||||
|
||||
// Calculer l'avancement de la phase
|
||||
const totalTaches = sousPhasesWithTaches.reduce((sum, sp) => sum + sp.totalTaches, 0);
|
||||
const totalTachesTerminees = sousPhasesWithTaches.reduce((sum, sp) => sum + sp.tachesTerminees, 0);
|
||||
const avancement = totalTaches > 0 ? (totalTachesTerminees / totalTaches) * 100 : 0;
|
||||
|
||||
return {
|
||||
...phase,
|
||||
sousPhases: sousPhasesWithTaches,
|
||||
avancement: Math.round(avancement),
|
||||
totalSousPhases: sousPhasesWithTaches.length,
|
||||
sousPhasesTerminees: sousPhasesWithTaches.filter(sp => sp.avancement === 100).length
|
||||
};
|
||||
})
|
||||
);
|
||||
|
||||
// Calculer l'avancement global du chantier
|
||||
const totalTaches = phasesWithExecution.reduce((sum, phase) =>
|
||||
sum + phase.sousPhases.reduce((spSum, sp) => spSum + sp.totalTaches, 0), 0
|
||||
);
|
||||
const totalTachesTerminees = phasesWithExecution.reduce((sum, phase) =>
|
||||
sum + phase.sousPhases.reduce((spSum, sp) => spSum + sp.tachesTerminees, 0), 0
|
||||
);
|
||||
const avancementGlobal = totalTaches > 0 ? (totalTachesTerminees / totalTaches) * 100 : 0;
|
||||
|
||||
setChantier({
|
||||
id: chantierData.id,
|
||||
nom: chantierData.nom,
|
||||
client: chantierData.client?.nom || chantierData.client,
|
||||
dateDebut: new Date(chantierData.dateDebut),
|
||||
dateFinPrevue: new Date(chantierData.dateFinPrevue),
|
||||
phases: phasesWithExecution,
|
||||
avancementGlobal: Math.round(avancementGlobal),
|
||||
totalTaches,
|
||||
totalTachesTerminees
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error('Erreur lors du chargement:', error);
|
||||
showToast('error', 'Erreur', 'Impossible de charger les données d\'exécution');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Charge les tâches d'exécution pour une sous-phase
|
||||
*/
|
||||
const loadTachesExecution = async (chantierId: string, sousPhaseId: string): Promise<TacheExecution[]> => {
|
||||
try {
|
||||
// Charger les templates de tâches
|
||||
const templatesResponse = await apiClient.get(`/tache-templates/by-sous-phase/${sousPhaseId}`);
|
||||
const templates = templatesResponse.data;
|
||||
|
||||
// Charger les états d'exécution (s'ils existent)
|
||||
let etatsExecution = [];
|
||||
try {
|
||||
const etatsResponse = await apiClient.get(`/chantiers/${chantierId}/taches-execution/${sousPhaseId}`);
|
||||
etatsExecution = etatsResponse.data;
|
||||
} catch (error) {
|
||||
// Pas encore d'états d'exécution, on démarre avec toutes les tâches non terminées
|
||||
console.log('Aucun état d\'exécution trouvé, initialisation...');
|
||||
}
|
||||
|
||||
// Combiner templates avec états d'exécution
|
||||
return templates.map((template: any) => {
|
||||
const etat = etatsExecution.find((e: any) => e.tacheTemplateId === template.id);
|
||||
return {
|
||||
...template,
|
||||
terminee: etat?.terminee || false,
|
||||
dateCompletion: etat?.dateCompletion ? new Date(etat.dateCompletion) : undefined,
|
||||
completeepar: etat?.completeepar,
|
||||
commentaires: etat?.commentaires,
|
||||
tempsRealise: etat?.tempsRealise,
|
||||
difficulteRencontree: etat?.difficulteRencontree || 'AUCUNE'
|
||||
};
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Erreur lors du chargement des tâches:', error);
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Marque une tâche comme terminée ou non terminée
|
||||
*/
|
||||
const toggleTacheTerminee = async (tache: TacheExecution) => {
|
||||
if (!tache.terminee) {
|
||||
// Marquer comme terminée - ouvrir le dialog pour les détails
|
||||
setSelectedTache(tache);
|
||||
setCommentaires(tache.commentaires || '');
|
||||
setTempsRealise(tache.tempsRealise || tache.dureeEstimeeMinutes || 0);
|
||||
setDifficulte(tache.difficulteRencontree || 'AUCUNE');
|
||||
setShowCommentDialog(true);
|
||||
} else {
|
||||
// Marquer comme non terminée
|
||||
await saveTacheExecution(tache, false);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Sauvegarde l'état d'exécution d'une tâche
|
||||
*/
|
||||
const saveTacheExecution = async (tache: TacheExecution, terminee: boolean, details?: any) => {
|
||||
try {
|
||||
setSaving(true);
|
||||
|
||||
const executionData = {
|
||||
chantierID: id,
|
||||
tacheTemplateId: tache.id,
|
||||
terminee,
|
||||
dateCompletion: terminee ? new Date().toISOString() : null,
|
||||
completeepar: terminee ? 'CURRENT_USER' : null, // À remplacer par l'utilisateur connecté
|
||||
commentaires: details?.commentaires || '',
|
||||
tempsRealise: details?.tempsRealise || null,
|
||||
difficulteRencontree: details?.difficulte || 'AUCUNE'
|
||||
};
|
||||
|
||||
await apiClient.post(`/chantiers/${id}/taches-execution`, executionData);
|
||||
|
||||
showToast('success', 'Succès',
|
||||
terminee ? 'Tâche marquée comme terminée' : 'Tâche marquée comme non terminée'
|
||||
);
|
||||
|
||||
// Recharger les données pour mettre à jour l'avancement
|
||||
await loadChantierExecution(id as string);
|
||||
|
||||
} catch (error) {
|
||||
console.error('Erreur lors de la sauvegarde:', error);
|
||||
showToast('error', 'Erreur', 'Impossible de sauvegarder l\'état de la tâche');
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Confirme la completion d'une tâche avec les détails
|
||||
*/
|
||||
const confirmerCompletion = async () => {
|
||||
if (!selectedTache) return;
|
||||
|
||||
await saveTacheExecution(selectedTache, true, {
|
||||
commentaires,
|
||||
tempsRealise,
|
||||
difficulte
|
||||
});
|
||||
|
||||
setShowCommentDialog(false);
|
||||
setSelectedTache(null);
|
||||
};
|
||||
|
||||
/**
|
||||
* Affiche un toast message
|
||||
*/
|
||||
const showToast = (severity: 'success' | 'info' | 'warn' | 'error', summary: string, detail: string) => {
|
||||
toast.current?.show({ severity, summary, detail, life: 3000 });
|
||||
};
|
||||
|
||||
/**
|
||||
* Template pour l'affichage d'une tâche avec checkbox
|
||||
*/
|
||||
const renderTacheCheckbox = (tache: TacheExecution) => {
|
||||
const isDisabled = saving;
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`flex align-items-center gap-3 p-3 border-round transition-colors ${
|
||||
tache.terminee ? 'bg-green-50 border-green-200' : 'bg-white border-gray-200'
|
||||
} border-1 hover:bg-gray-50`}
|
||||
>
|
||||
<Checkbox
|
||||
checked={tache.terminee}
|
||||
onChange={() => toggleTacheTerminee(tache)}
|
||||
disabled={isDisabled}
|
||||
/>
|
||||
|
||||
<div className="flex-1">
|
||||
<div className={`font-medium ${tache.terminee ? 'line-through text-600' : ''}`}>
|
||||
{tache.nom}
|
||||
</div>
|
||||
{tache.description && (
|
||||
<div className="text-sm text-600 mt-1">{tache.description}</div>
|
||||
)}
|
||||
|
||||
<div className="flex gap-2 mt-2">
|
||||
{tache.critique && <Badge value="Critique" severity="danger" className="p-badge-sm" />}
|
||||
{tache.bloquante && <Badge value="Bloquante" severity="warning" className="p-badge-sm" />}
|
||||
{tache.priorite === 'HAUTE' && <Badge value="Haute priorité" severity="info" className="p-badge-sm" />}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="text-right text-sm">
|
||||
{tache.dureeEstimeeMinutes && (
|
||||
<div className="text-600">
|
||||
Estimé: {Math.floor(tache.dureeEstimeeMinutes / 60)}h{tache.dureeEstimeeMinutes % 60}min
|
||||
</div>
|
||||
)}
|
||||
{tache.terminee && tache.tempsRealise && (
|
||||
<div className="text-green-600 font-medium">
|
||||
Réalisé: {Math.floor(tache.tempsRealise / 60)}h{tache.tempsRealise % 60}min
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="flex justify-content-center align-items-center h-20rem">
|
||||
<i className="pi pi-spin pi-spinner" style={{ fontSize: '2rem' }}></i>
|
||||
<span className="ml-2">Chargement de l'exécution du chantier...</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!chantier) {
|
||||
return (
|
||||
<div className="text-center">
|
||||
<h5>Chantier non trouvé</h5>
|
||||
<p>Impossible de charger les données d'exécution du chantier.</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="grid">
|
||||
<Toast ref={toast} />
|
||||
|
||||
{/* En-tête avec avancement global */}
|
||||
<div className="col-12">
|
||||
<Card>
|
||||
<div className="flex justify-content-between align-items-start">
|
||||
<div className="flex-1">
|
||||
<h4 className="mt-0 mb-2">{chantier.nom}</h4>
|
||||
<div className="text-600 mb-3">
|
||||
Client: {chantier.client} •
|
||||
Début: {chantier.dateDebut.toLocaleDateString('fr-FR')} •
|
||||
Fin prévue: {chantier.dateFinPrevue.toLocaleDateString('fr-FR')}
|
||||
</div>
|
||||
|
||||
<div className="flex align-items-center gap-4">
|
||||
<div className="flex-1">
|
||||
<div className="flex justify-content-between mb-2">
|
||||
<span className="font-medium">Avancement Global</span>
|
||||
<span className="font-bold text-lg">{chantier.avancementGlobal}%</span>
|
||||
</div>
|
||||
<ProgressBar
|
||||
value={chantier.avancementGlobal}
|
||||
className="mb-2"
|
||||
style={{ height: '12px' }}
|
||||
/>
|
||||
<div className="text-sm text-600">
|
||||
{chantier.totalTachesTerminees} / {chantier.totalTaches} tâches terminées
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="text-right">
|
||||
<Avatar
|
||||
icon="pi pi-chart-line"
|
||||
size="xlarge"
|
||||
className="bg-blue-100 text-blue-800"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
{/* Phases avec sous-phases et tâches */}
|
||||
<div className="col-12">
|
||||
<Accordion activeIndex={activeIndex} onTabChange={(e) => setActiveIndex(e.index)}>
|
||||
{chantier.phases.map((phase, phaseIndex) => (
|
||||
<AccordionTab
|
||||
key={phase.id}
|
||||
header={
|
||||
<div className="flex justify-content-between align-items-center w-full pr-4">
|
||||
<div className="flex align-items-center gap-3">
|
||||
<Badge value={phase.ordreExecution} />
|
||||
<span className="font-medium">{phase.nom}</span>
|
||||
</div>
|
||||
<div className="flex align-items-center gap-2">
|
||||
<span className="text-sm">{phase.avancement}%</span>
|
||||
<ProgressBar
|
||||
value={phase.avancement}
|
||||
style={{ width: '100px', height: '8px' }}
|
||||
showValue={false}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<div className="grid">
|
||||
{phase.sousPhases.map((sousPhase) => (
|
||||
<div key={sousPhase.id} className="col-12">
|
||||
<Card className="mb-3">
|
||||
<div className="flex justify-content-between align-items-center mb-3">
|
||||
<div>
|
||||
<h6 className="mt-0 mb-1">{sousPhase.nom}</h6>
|
||||
{sousPhase.description && (
|
||||
<p className="text-600 mt-0 mb-2">{sousPhase.description}</p>
|
||||
)}
|
||||
<div className="text-sm text-500">
|
||||
{sousPhase.tachesTerminees} / {sousPhase.totalTaches} tâches terminées
|
||||
</div>
|
||||
</div>
|
||||
<div className="text-right">
|
||||
<div className="text-lg font-bold mb-1">{sousPhase.avancement}%</div>
|
||||
<ProgressBar
|
||||
value={sousPhase.avancement}
|
||||
style={{ width: '120px', height: '8px' }}
|
||||
showValue={false}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-column gap-2">
|
||||
{sousPhase.taches.map((tache) => (
|
||||
<div key={tache.id}>
|
||||
{renderTacheCheckbox(tache)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</AccordionTab>
|
||||
))}
|
||||
</Accordion>
|
||||
</div>
|
||||
|
||||
{/* Dialog de completion de tâche */}
|
||||
<Dialog
|
||||
header="Finaliser la tâche"
|
||||
visible={showCommentDialog}
|
||||
onHide={() => setShowCommentDialog(false)}
|
||||
style={{ width: '50vw' }}
|
||||
breakpoints={{ '960px': '75vw', '641px': '90vw' }}
|
||||
modal
|
||||
>
|
||||
{selectedTache && (
|
||||
<div className="p-fluid">
|
||||
<div className="mb-4">
|
||||
<h6 className="text-primary">{selectedTache.nom}</h6>
|
||||
{selectedTache.description && (
|
||||
<p className="text-600 mt-1">{selectedTache.description}</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="field">
|
||||
<label htmlFor="commentaires">Commentaires (optionnel)</label>
|
||||
<InputTextarea
|
||||
id="commentaires"
|
||||
value={commentaires}
|
||||
onChange={(e) => setCommentaires(e.target.value)}
|
||||
rows={3}
|
||||
placeholder="Commentaires sur la réalisation de cette tâche..."
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="field">
|
||||
<label>Temps réalisé (minutes)</label>
|
||||
<input
|
||||
type="number"
|
||||
className="p-inputtext p-component"
|
||||
value={tempsRealise}
|
||||
onChange={(e) => setTempsRealise(parseInt(e.target.value) || 0)}
|
||||
min={0}
|
||||
/>
|
||||
{selectedTache.dureeEstimeeMinutes && (
|
||||
<small className="text-600">
|
||||
Temps estimé: {selectedTache.dureeEstimeeMinutes} minutes
|
||||
</small>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex justify-content-end gap-2 mt-4">
|
||||
<Button
|
||||
label="Annuler"
|
||||
icon="pi pi-times"
|
||||
className="p-button-text"
|
||||
onClick={() => setShowCommentDialog(false)}
|
||||
/>
|
||||
<Button
|
||||
label="Marquer comme terminée"
|
||||
icon="pi pi-check"
|
||||
onClick={confirmerCompletion}
|
||||
loading={saving}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</Dialog>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ExecutionGranulaireChantier;
|
||||
324
app/(main)/chantiers/[id]/phases-clean/page.tsx
Normal file
324
app/(main)/chantiers/[id]/phases-clean/page.tsx
Normal file
@@ -0,0 +1,324 @@
|
||||
'use client';
|
||||
|
||||
import React, { useState, useRef, useEffect } from 'react';
|
||||
import { useParams } from 'next/navigation';
|
||||
import { Card } from 'primereact/card';
|
||||
import { Button } from 'primereact/button';
|
||||
import { Dialog } from 'primereact/dialog';
|
||||
import { InputText } from 'primereact/inputtext';
|
||||
import { InputTextarea } from 'primereact/inputtextarea';
|
||||
import { Calendar } from 'primereact/calendar';
|
||||
import { InputNumber } from 'primereact/inputnumber';
|
||||
import { Dropdown } from 'primereact/dropdown';
|
||||
import { Checkbox } from 'primereact/checkbox';
|
||||
import { Toast } from 'primereact/toast';
|
||||
import { Toolbar } from 'primereact/toolbar';
|
||||
import { Badge } from 'primereact/badge';
|
||||
|
||||
import PhasesTable from '../../../../../components/phases/PhasesTable';
|
||||
import usePhasesManager from '../../../../../hooks/usePhasesManager';
|
||||
import type { PhaseChantier, PhaseFormData } from '../../../../../types/btp-extended';
|
||||
|
||||
const PhasesCleanPage: React.FC = () => {
|
||||
const params = useParams();
|
||||
const chantierId = params?.id as string;
|
||||
const toast = useRef<Toast>(null);
|
||||
|
||||
// Hook de gestion des phases
|
||||
const {
|
||||
phases,
|
||||
loading,
|
||||
selectedPhase,
|
||||
setSelectedPhase,
|
||||
loadPhases,
|
||||
createPhase,
|
||||
updatePhase,
|
||||
deletePhase,
|
||||
startPhase,
|
||||
setToastRef
|
||||
} = usePhasesManager({ chantierId });
|
||||
|
||||
const [globalFilter, setGlobalFilter] = useState('');
|
||||
|
||||
// États pour les dialogues
|
||||
const [showPhaseDialog, setShowPhaseDialog] = useState(false);
|
||||
const [editingPhase, setEditingPhase] = useState(false);
|
||||
|
||||
// États pour les formulaires
|
||||
const [phaseForm, setPhaseForm] = useState<PhaseFormData>({
|
||||
nom: '',
|
||||
description: '',
|
||||
dateDebutPrevue: '',
|
||||
dateFinPrevue: '',
|
||||
dureeEstimeeHeures: 8,
|
||||
priorite: 'MOYENNE',
|
||||
critique: false,
|
||||
ordreExecution: 1,
|
||||
budgetPrevu: 0,
|
||||
coutReel: 0,
|
||||
prerequisPhases: [],
|
||||
competencesRequises: [],
|
||||
materielsNecessaires: [],
|
||||
fournisseursRecommandes: []
|
||||
});
|
||||
|
||||
// Initialisation
|
||||
useEffect(() => {
|
||||
setToastRef(toast.current);
|
||||
if (chantierId) {
|
||||
loadPhases();
|
||||
}
|
||||
}, [chantierId, setToastRef, loadPhases]);
|
||||
|
||||
// Gestionnaires d'événements
|
||||
const handleEditPhase = (phase: PhaseChantier) => {
|
||||
setSelectedPhase(phase);
|
||||
setEditingPhase(true);
|
||||
setPhaseForm({
|
||||
nom: phase.nom,
|
||||
description: phase.description || '',
|
||||
dateDebutPrevue: phase.dateDebutPrevue || '',
|
||||
dateFinPrevue: phase.dateFinPrevue || '',
|
||||
dureeEstimeeHeures: phase.dureeEstimeeHeures || 8,
|
||||
priorite: phase.priorite || 'MOYENNE',
|
||||
critique: phase.critique || false,
|
||||
ordreExecution: phase.ordreExecution || 1,
|
||||
budgetPrevu: phase.budgetPrevu || 0,
|
||||
coutReel: phase.coutReel || 0,
|
||||
prerequisPhases: phase.prerequisPhases || [],
|
||||
competencesRequises: phase.competencesRequises || [],
|
||||
materielsNecessaires: phase.materielsNecessaires || [],
|
||||
fournisseursRecommandes: phase.fournisseursRecommandes || []
|
||||
});
|
||||
setShowPhaseDialog(true);
|
||||
};
|
||||
|
||||
const handleSavePhase = async () => {
|
||||
if (!phaseForm.nom.trim()) {
|
||||
toast.current?.show({
|
||||
severity: 'warn',
|
||||
summary: 'Données manquantes',
|
||||
detail: 'Veuillez remplir le nom de la phase',
|
||||
life: 3000
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const phaseData = {
|
||||
...phaseForm,
|
||||
chantierId: chantierId
|
||||
};
|
||||
|
||||
if (editingPhase && selectedPhase) {
|
||||
await updatePhase(selectedPhase.id!, phaseData);
|
||||
} else {
|
||||
await createPhase(phaseData);
|
||||
}
|
||||
|
||||
setShowPhaseDialog(false);
|
||||
setEditingPhase(false);
|
||||
setSelectedPhase(null);
|
||||
resetPhaseForm();
|
||||
|
||||
} catch (error) {
|
||||
console.error('Erreur lors de la sauvegarde de la phase:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const resetPhaseForm = () => {
|
||||
setPhaseForm({
|
||||
nom: '',
|
||||
description: '',
|
||||
dateDebutPrevue: '',
|
||||
dateFinPrevue: '',
|
||||
dureeEstimeeHeures: 8,
|
||||
priorite: 'MOYENNE',
|
||||
critique: false,
|
||||
ordreExecution: 1,
|
||||
budgetPrevu: 0,
|
||||
coutReel: 0,
|
||||
prerequisPhases: [],
|
||||
competencesRequises: [],
|
||||
materielsNecessaires: [],
|
||||
fournisseursRecommandes: []
|
||||
});
|
||||
};
|
||||
|
||||
// Templates de la toolbar
|
||||
const toolbarStartTemplate = (
|
||||
<div className="flex align-items-center gap-2">
|
||||
<h5 className="m-0 text-color">Phases - Version Clean</h5>
|
||||
<Badge value={phases.length} />
|
||||
</div>
|
||||
);
|
||||
|
||||
const toolbarEndTemplate = (
|
||||
<div className="flex gap-2">
|
||||
<span className="p-input-icon-left">
|
||||
<i className="pi pi-search" />
|
||||
<InputText
|
||||
value={globalFilter}
|
||||
onChange={(e) => setGlobalFilter(e.target.value)}
|
||||
placeholder="Rechercher..."
|
||||
/>
|
||||
</span>
|
||||
<Button
|
||||
label="Nouvelle phase"
|
||||
icon="pi pi-plus"
|
||||
className="p-button-success"
|
||||
onClick={() => {
|
||||
resetPhaseForm();
|
||||
setEditingPhase(false);
|
||||
setShowPhaseDialog(true);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="grid">
|
||||
<Toast ref={toast} />
|
||||
|
||||
<div className="col-12">
|
||||
<Card>
|
||||
<Toolbar
|
||||
start={toolbarStartTemplate}
|
||||
end={toolbarEndTemplate}
|
||||
className="mb-4"
|
||||
/>
|
||||
|
||||
<PhasesTable
|
||||
phases={phases}
|
||||
loading={loading}
|
||||
chantierId={chantierId}
|
||||
showStats={false}
|
||||
showChantierColumn={false}
|
||||
showSubPhases={true}
|
||||
showBudget={true}
|
||||
showExpansion={true}
|
||||
actions={['view', 'edit', 'delete', 'start']}
|
||||
onRefresh={loadPhases}
|
||||
onPhaseEdit={handleEditPhase}
|
||||
onPhaseDelete={deletePhase}
|
||||
onPhaseStart={startPhase}
|
||||
rows={15}
|
||||
globalFilter={globalFilter}
|
||||
showGlobalFilter={true}
|
||||
/>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
{/* Dialog pour créer/modifier une phase */}
|
||||
<Dialog
|
||||
header={editingPhase ? "Modifier la phase" : "Nouvelle phase"}
|
||||
visible={showPhaseDialog}
|
||||
onHide={() => {
|
||||
setShowPhaseDialog(false);
|
||||
setEditingPhase(false);
|
||||
resetPhaseForm();
|
||||
}}
|
||||
footer={
|
||||
<div>
|
||||
<Button
|
||||
label="Annuler"
|
||||
icon="pi pi-times"
|
||||
className="p-button-text"
|
||||
onClick={() => {
|
||||
setShowPhaseDialog(false);
|
||||
setEditingPhase(false);
|
||||
resetPhaseForm();
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
label={editingPhase ? "Modifier" : "Créer"}
|
||||
icon="pi pi-check"
|
||||
className="p-button-success"
|
||||
onClick={handleSavePhase}
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
style={{ width: '50vw', maxWidth: '600px' }}
|
||||
modal
|
||||
>
|
||||
<div className="grid">
|
||||
<div className="col-12">
|
||||
<div className="field">
|
||||
<label htmlFor="phaseNom" className="font-semibold">
|
||||
Nom de la phase <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<InputText
|
||||
id="phaseNom"
|
||||
value={phaseForm.nom}
|
||||
onChange={(e) => setPhaseForm(prev => ({ ...prev, nom: e.target.value }))}
|
||||
className="w-full"
|
||||
placeholder="Ex: Fondations, Gros œuvre..."
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="col-12">
|
||||
<div className="field">
|
||||
<label htmlFor="phaseDescription" className="font-semibold">Description</label>
|
||||
<InputTextarea
|
||||
id="phaseDescription"
|
||||
value={phaseForm.description}
|
||||
onChange={(e) => setPhaseForm(prev => ({ ...prev, description: e.target.value }))}
|
||||
className="w-full"
|
||||
rows={3}
|
||||
placeholder="Description détaillée de la phase..."
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="col-12 md:col-6">
|
||||
<div className="field">
|
||||
<label htmlFor="phaseDuree" className="font-semibold">Durée estimée (heures)</label>
|
||||
<InputNumber
|
||||
id="phaseDuree"
|
||||
value={phaseForm.dureeEstimeeHeures}
|
||||
onChange={(e) => setPhaseForm(prev => ({ ...prev, dureeEstimeeHeures: e.value || 0 }))}
|
||||
className="w-full"
|
||||
min={1}
|
||||
suffix=" h"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="col-12 md:col-6">
|
||||
<div className="field">
|
||||
<label htmlFor="phasePriorite" className="font-semibold">Priorité</label>
|
||||
<Dropdown
|
||||
id="phasePriorite"
|
||||
value={phaseForm.priorite}
|
||||
options={[
|
||||
{ label: 'Faible', value: 'FAIBLE' },
|
||||
{ label: 'Moyenne', value: 'MOYENNE' },
|
||||
{ label: 'Élevée', value: 'ELEVEE' },
|
||||
{ label: 'Critique', value: 'CRITIQUE' }
|
||||
]}
|
||||
onChange={(e) => setPhaseForm(prev => ({ ...prev, priorite: e.value }))}
|
||||
className="w-full"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="col-12">
|
||||
<div className="field-checkbox">
|
||||
<Checkbox
|
||||
id="phaseCritique"
|
||||
checked={phaseForm.critique}
|
||||
onChange={(e) => setPhaseForm(prev => ({ ...prev, critique: e.checked }))}
|
||||
/>
|
||||
<label htmlFor="phaseCritique" className="ml-2 font-semibold">
|
||||
Phase critique
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default PhasesCleanPage;
|
||||
269
app/(main)/chantiers/[id]/phases-responsive/page.tsx
Normal file
269
app/(main)/chantiers/[id]/phases-responsive/page.tsx
Normal file
@@ -0,0 +1,269 @@
|
||||
'use client';
|
||||
|
||||
import React, { useState, useContext } from 'react';
|
||||
import { Panel } from 'primereact/panel';
|
||||
import { Button } from 'primereact/button';
|
||||
import { Toast } from 'primereact/toast';
|
||||
import { useRef } from 'react';
|
||||
import { LayoutContext } from '../../../../../layout/context/layoutcontext';
|
||||
import AtlantisResponsivePhasesTable from '../../../../../components/phases/AtlantisResponsivePhasesTable';
|
||||
import AtlantisAccessibilityControls from '../../../../../components/phases/AtlantisAccessibilityControls';
|
||||
import PhasesQuickPreview from '../../../../../components/phases/PhasesQuickPreview';
|
||||
import PhaseValidationPanel from '../../../../../components/phases/PhaseValidationPanel';
|
||||
import { Dialog } from 'primereact/dialog';
|
||||
import testDataService from '../../../../../services/testDataService';
|
||||
import type { PhaseChantier } from '../../../../../types/btp';
|
||||
|
||||
const ResponsivePhasesPage: React.FC = () => {
|
||||
const [phases, setPhases] = useState<PhaseChantier[]>([]);
|
||||
const [selectedPhase, setSelectedPhase] = useState<PhaseChantier | null>(null);
|
||||
const [validationDialogVisible, setValidationDialogVisible] = useState(false);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const { isDesktop } = useContext(LayoutContext);
|
||||
const toast = useRef<Toast>(null);
|
||||
|
||||
// Générer des données de test au chargement
|
||||
React.useEffect(() => {
|
||||
const client = testDataService.generateTestClient(1);
|
||||
const chantier = testDataService.generateTestChantier(1, 'MAISON_INDIVIDUELLE', client);
|
||||
const generatedPhases = testDataService.generatePhasesWithPrerequisites(chantier);
|
||||
setPhases(generatedPhases);
|
||||
}, []);
|
||||
|
||||
const handlePhaseSelect = (phase: PhaseChantier) => {
|
||||
setSelectedPhase(phase);
|
||||
|
||||
toast.current?.show({
|
||||
severity: 'info',
|
||||
summary: 'Phase sélectionnée',
|
||||
detail: `${phase.nom} - ${phase.statut}`,
|
||||
life: 3000
|
||||
});
|
||||
};
|
||||
|
||||
const handlePhaseStart = (phaseId: string) => {
|
||||
setPhases(prev => prev.map(p =>
|
||||
p.id === phaseId
|
||||
? { ...p, statut: 'EN_COURS' as const, dateDebutReelle: new Date().toISOString().split('T')[0] }
|
||||
: p
|
||||
));
|
||||
|
||||
toast.current?.show({
|
||||
severity: 'success',
|
||||
summary: 'Phase démarrée',
|
||||
detail: 'La phase a été mise en cours',
|
||||
life: 3000
|
||||
});
|
||||
};
|
||||
|
||||
const handlePhaseValidation = (phase: PhaseChantier) => {
|
||||
setSelectedPhase(phase);
|
||||
setValidationDialogVisible(true);
|
||||
};
|
||||
|
||||
const headerTemplate = (
|
||||
<div className="flex align-items-center justify-content-between">
|
||||
<div className="flex align-items-center gap-3">
|
||||
<i className="pi pi-building text-2xl text-primary" />
|
||||
<div>
|
||||
<h2 className="m-0 text-color">Gestion des phases - Vue responsive</h2>
|
||||
<p className="m-0 text-color-secondary text-sm">
|
||||
Interface adaptative utilisant le template Atlantis React
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{isDesktop() && (
|
||||
<div className="flex align-items-center gap-2">
|
||||
<Button
|
||||
label="Actualiser"
|
||||
icon="pi pi-refresh"
|
||||
className="p-button-outlined"
|
||||
onClick={() => window.location.reload()}
|
||||
/>
|
||||
<Button
|
||||
label="Paramètres"
|
||||
icon="pi pi-cog"
|
||||
className="p-button-text"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="grid">
|
||||
<Toast ref={toast} />
|
||||
|
||||
{/* En-tête de page avec style Atlantis */}
|
||||
<div className="col-12">
|
||||
<div className="card">
|
||||
{headerTemplate}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Contrôles d'accessibilité */}
|
||||
<div className="col-12">
|
||||
<AtlantisAccessibilityControls />
|
||||
</div>
|
||||
|
||||
{/* Vue d'ensemble rapide */}
|
||||
{phases.length > 0 && (
|
||||
<div className="col-12 lg:col-4">
|
||||
<PhasesQuickPreview
|
||||
phases={phases}
|
||||
className="h-full"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Tableau principal responsive */}
|
||||
<div className={`col-12 ${phases.length > 0 ? 'lg:col-8' : ''}`}>
|
||||
<AtlantisResponsivePhasesTable
|
||||
phases={phases}
|
||||
onPhaseSelect={handlePhaseSelect}
|
||||
onPhaseStart={handlePhaseStart}
|
||||
onPhaseValidate={handlePhaseValidation}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Informations complémentaires sur mobile */}
|
||||
{!isDesktop() && selectedPhase && (
|
||||
<div className="col-12">
|
||||
<div className="card">
|
||||
<h6 className="mt-0 mb-3 text-color">Phase sélectionnée</h6>
|
||||
<div className="grid">
|
||||
<div className="col-12 sm:col-6">
|
||||
<div className="field">
|
||||
<label className="font-semibold text-color-secondary">Nom</label>
|
||||
<p className="m-0 text-color">{selectedPhase.nom}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="col-12 sm:col-6">
|
||||
<div className="field">
|
||||
<label className="font-semibold text-color-secondary">Statut</label>
|
||||
<p className="m-0 text-color">{selectedPhase.statut}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="col-12 sm:col-6">
|
||||
<div className="field">
|
||||
<label className="font-semibold text-color-secondary">Avancement</label>
|
||||
<p className="m-0 text-color">{selectedPhase.pourcentageAvancement || 0}%</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="col-12 sm:col-6">
|
||||
<div className="field">
|
||||
<label className="font-semibold text-color-secondary">Date début prévue</label>
|
||||
<p className="m-0 text-color">
|
||||
{selectedPhase.dateDebutPrevue ?
|
||||
new Date(selectedPhase.dateDebutPrevue).toLocaleDateString('fr-FR') :
|
||||
'-'
|
||||
}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
{selectedPhase.description && (
|
||||
<div className="col-12">
|
||||
<div className="field">
|
||||
<label className="font-semibold text-color-secondary">Description</label>
|
||||
<p className="m-0 text-color-secondary">{selectedPhase.description}</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Actions rapides pour mobile */}
|
||||
{!isDesktop() && (
|
||||
<div className="col-12">
|
||||
<div className="card">
|
||||
<h6 className="mt-0 mb-3 text-color">Actions rapides</h6>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Button
|
||||
label="Nouvelle phase"
|
||||
icon="pi pi-plus"
|
||||
className="p-button-success flex-1 sm:flex-none"
|
||||
/>
|
||||
<Button
|
||||
label="Filtrer"
|
||||
icon="pi pi-filter"
|
||||
className="p-button-outlined flex-1 sm:flex-none"
|
||||
/>
|
||||
<Button
|
||||
label="Exporter"
|
||||
icon="pi pi-download"
|
||||
className="p-button-outlined flex-1 sm:flex-none"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Statistiques rapides */}
|
||||
<div className="col-12">
|
||||
<div className="grid">
|
||||
<div className="col-6 md:col-3">
|
||||
<div className="card text-center">
|
||||
<div className="text-2xl font-bold text-primary">
|
||||
{phases.length}
|
||||
</div>
|
||||
<div className="text-color-secondary text-sm">Total phases</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="col-6 md:col-3">
|
||||
<div className="card text-center">
|
||||
<div className="text-2xl font-bold text-green-500">
|
||||
{phases.filter(p => p.statut === 'TERMINEE').length}
|
||||
</div>
|
||||
<div className="text-color-secondary text-sm">Terminées</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="col-6 md:col-3">
|
||||
<div className="card text-center">
|
||||
<div className="text-2xl font-bold text-blue-500">
|
||||
{phases.filter(p => p.statut === 'EN_COURS').length}
|
||||
</div>
|
||||
<div className="text-color-secondary text-sm">En cours</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="col-6 md:col-3">
|
||||
<div className="card text-center">
|
||||
<div className="text-2xl font-bold text-orange-500">
|
||||
{phases.filter(p => p.critique).length}
|
||||
</div>
|
||||
<div className="text-color-secondary text-sm">Critiques</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Dialog de validation */}
|
||||
<Dialog
|
||||
header="Validation des prérequis"
|
||||
visible={validationDialogVisible}
|
||||
onHide={() => setValidationDialogVisible(false)}
|
||||
style={{ width: isDesktop() ? '800px' : '95vw' }}
|
||||
modal
|
||||
className="p-fluid"
|
||||
>
|
||||
{selectedPhase && (
|
||||
<PhaseValidationPanel
|
||||
phase={selectedPhase}
|
||||
allPhases={phases}
|
||||
onStartPhase={handlePhaseStart}
|
||||
onViewPrerequisite={(prereqId) => {
|
||||
const prereq = phases.find(p => p.id === prereqId);
|
||||
if (prereq) {
|
||||
setSelectedPhase(prereq);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</Dialog>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ResponsivePhasesPage;
|
||||
1124
app/(main)/chantiers/[id]/phases/page.tsx
Normal file
1124
app/(main)/chantiers/[id]/phases/page.tsx
Normal file
File diff suppressed because it is too large
Load Diff
337
app/(main)/chantiers/en-cours/page.tsx
Normal file
337
app/(main)/chantiers/en-cours/page.tsx
Normal file
@@ -0,0 +1,337 @@
|
||||
'use client';
|
||||
|
||||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import { DataTable } from 'primereact/datatable';
|
||||
import { Column } from 'primereact/column';
|
||||
import { Button } from 'primereact/button';
|
||||
import { InputText } from 'primereact/inputtext';
|
||||
import { Card } from 'primereact/card';
|
||||
import { Toast } from 'primereact/toast';
|
||||
import { Toolbar } from 'primereact/toolbar';
|
||||
import { Tag } from 'primereact/tag';
|
||||
import { ProgressBar } from 'primereact/progressbar';
|
||||
import { Dialog } from 'primereact/dialog';
|
||||
import { Calendar } from 'primereact/calendar';
|
||||
import { InputNumber } from 'primereact/inputnumber';
|
||||
import { chantierService } from '../../../../services/api';
|
||||
import { formatDate, formatCurrency } from '../../../../utils/formatters';
|
||||
import type { Chantier } from '../../../../types/btp';
|
||||
|
||||
const ChantiersEnCoursPage = () => {
|
||||
const [chantiers, setChantiers] = useState<Chantier[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [globalFilter, setGlobalFilter] = useState('');
|
||||
const [selectedChantiers, setSelectedChantiers] = useState<Chantier[]>([]);
|
||||
const [updateDialog, setUpdateDialog] = useState(false);
|
||||
const [selectedChantier, setSelectedChantier] = useState<Chantier | null>(null);
|
||||
const [updateData, setUpdateData] = useState({ dateFinReelle: null, montantReel: 0 });
|
||||
const toast = useRef<Toast>(null);
|
||||
const dt = useRef<DataTable<Chantier[]>>(null);
|
||||
|
||||
useEffect(() => {
|
||||
loadChantiers();
|
||||
}, []);
|
||||
|
||||
const loadChantiers = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const data = await chantierService.getAll();
|
||||
// Filtrer seulement les chantiers en cours
|
||||
const chantiersEnCours = data.filter(chantier => chantier.statut === 'EN_COURS');
|
||||
setChantiers(chantiersEnCours);
|
||||
} catch (error) {
|
||||
console.error('Erreur lors du chargement des chantiers:', error);
|
||||
toast.current?.show({
|
||||
severity: 'error',
|
||||
summary: 'Erreur',
|
||||
detail: 'Impossible de charger les chantiers en cours',
|
||||
life: 3000
|
||||
});
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const calculateProgress = (chantier: Chantier) => {
|
||||
if (!chantier.dateDebut || !chantier.dateFinPrevue) return 0;
|
||||
|
||||
const now = new Date();
|
||||
const start = new Date(chantier.dateDebut);
|
||||
const end = new Date(chantier.dateFinPrevue);
|
||||
const totalDays = (end.getTime() - start.getTime()) / (1000 * 60 * 60 * 24);
|
||||
const elapsedDays = (now.getTime() - start.getTime()) / (1000 * 60 * 60 * 24);
|
||||
|
||||
return Math.min(Math.max((elapsedDays / totalDays) * 100, 0), 100);
|
||||
};
|
||||
|
||||
const isLate = (chantier: Chantier) => {
|
||||
if (!chantier.dateFinPrevue) return false;
|
||||
const today = new Date();
|
||||
const endDate = new Date(chantier.dateFinPrevue);
|
||||
return today > endDate;
|
||||
};
|
||||
|
||||
const markAsCompleted = (chantier: Chantier) => {
|
||||
setSelectedChantier(chantier);
|
||||
setUpdateData({
|
||||
dateFinReelle: new Date(),
|
||||
montantReel: chantier.montantReel || chantier.montantPrevu || 0
|
||||
});
|
||||
setUpdateDialog(true);
|
||||
};
|
||||
|
||||
const handleCompleteChantier = async () => {
|
||||
if (!selectedChantier) return;
|
||||
|
||||
try {
|
||||
const updatedChantier = {
|
||||
...selectedChantier,
|
||||
statut: 'TERMINE',
|
||||
dateFinReelle: updateData.dateFinReelle,
|
||||
montantReel: updateData.montantReel
|
||||
};
|
||||
|
||||
await chantierService.update(selectedChantier.id, updatedChantier);
|
||||
|
||||
// Retirer le chantier de la liste car il n'est plus "en cours"
|
||||
setChantiers(prev => prev.filter(c => c.id !== selectedChantier.id));
|
||||
setUpdateDialog(false);
|
||||
|
||||
toast.current?.show({
|
||||
severity: 'success',
|
||||
summary: 'Succès',
|
||||
detail: 'Chantier marqué comme terminé',
|
||||
life: 3000
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Erreur lors de la mise à jour:', error);
|
||||
toast.current?.show({
|
||||
severity: 'error',
|
||||
summary: 'Erreur',
|
||||
detail: 'Impossible de mettre à jour le chantier',
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const exportCSV = () => {
|
||||
dt.current?.exportCSV();
|
||||
};
|
||||
|
||||
const leftToolbarTemplate = () => {
|
||||
return (
|
||||
<div className="my-2">
|
||||
<h5 className="m-0">Chantiers en cours ({chantiers.length})</h5>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const rightToolbarTemplate = () => {
|
||||
return (
|
||||
<Button
|
||||
label="Exporter"
|
||||
icon="pi pi-upload"
|
||||
severity="help"
|
||||
onClick={exportCSV}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
const actionBodyTemplate = (rowData: Chantier) => {
|
||||
return (
|
||||
<div className="flex gap-2">
|
||||
<Button
|
||||
icon="pi pi-check"
|
||||
rounded
|
||||
severity="success"
|
||||
size="small"
|
||||
tooltip="Marquer comme terminé"
|
||||
onClick={() => markAsCompleted(rowData)}
|
||||
/>
|
||||
<Button
|
||||
icon="pi pi-eye"
|
||||
rounded
|
||||
severity="info"
|
||||
size="small"
|
||||
tooltip="Voir détails"
|
||||
onClick={() => {
|
||||
toast.current?.show({
|
||||
severity: 'info',
|
||||
summary: 'Info',
|
||||
detail: `Détails du chantier ${rowData.nom}`,
|
||||
life: 3000
|
||||
});
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const statusBodyTemplate = (rowData: Chantier) => {
|
||||
const late = isLate(rowData);
|
||||
return (
|
||||
<div className="flex align-items-center gap-2">
|
||||
<Tag value="En cours" severity="success" />
|
||||
{late && <Tag value="En retard" severity="danger" />}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const progressBodyTemplate = (rowData: Chantier) => {
|
||||
const progress = calculateProgress(rowData);
|
||||
const late = isLate(rowData);
|
||||
|
||||
return (
|
||||
<div className="flex align-items-center gap-2">
|
||||
<ProgressBar
|
||||
value={progress}
|
||||
style={{ height: '6px', width: '100px' }}
|
||||
color={late ? '#ef4444' : undefined}
|
||||
/>
|
||||
<span className={`text-sm ${late ? 'text-red-500' : ''}`}>
|
||||
{Math.round(progress)}%
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const clientBodyTemplate = (rowData: Chantier) => {
|
||||
if (!rowData.client) return '';
|
||||
return `${rowData.client.prenom} ${rowData.client.nom}`;
|
||||
};
|
||||
|
||||
const dateBodyTemplate = (rowData: Chantier, field: string) => {
|
||||
const date = (rowData as any)[field];
|
||||
const late = field === 'dateFinPrevue' && isLate(rowData);
|
||||
|
||||
return (
|
||||
<span className={late ? 'text-red-500 font-bold' : ''}>
|
||||
{date ? formatDate(date) : ''}
|
||||
{late && <i className="pi pi-exclamation-triangle ml-1"></i>}
|
||||
</span>
|
||||
);
|
||||
};
|
||||
|
||||
const budgetBodyTemplate = (rowData: Chantier) => {
|
||||
const prevu = rowData.montantPrevu || 0;
|
||||
const reel = rowData.montantReel || 0;
|
||||
const progress = calculateProgress(rowData);
|
||||
const estimated = prevu * (progress / 100);
|
||||
|
||||
return (
|
||||
<div className="text-sm">
|
||||
<div>Prévu: {formatCurrency(prevu)}</div>
|
||||
<div className="text-600">Estimé: {formatCurrency(estimated)}</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const header = (
|
||||
<div className="flex flex-column md:flex-row md:justify-content-between md:align-items-center">
|
||||
<h5 className="m-0">Chantiers en cours de réalisation</h5>
|
||||
<span className="block mt-2 md:mt-0 p-input-icon-left">
|
||||
<i className="pi pi-search" />
|
||||
<InputText
|
||||
type="search"
|
||||
placeholder="Rechercher..."
|
||||
onInput={(e) => setGlobalFilter(e.currentTarget.value)}
|
||||
/>
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
|
||||
const completeDialogFooter = (
|
||||
<>
|
||||
<Button
|
||||
label="Annuler"
|
||||
icon="pi pi-times"
|
||||
text
|
||||
onClick={() => setUpdateDialog(false)}
|
||||
/>
|
||||
<Button
|
||||
label="Marquer comme terminé"
|
||||
icon="pi pi-check"
|
||||
text
|
||||
onClick={handleCompleteChantier}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="grid">
|
||||
<div className="col-12">
|
||||
<Card>
|
||||
<Toast ref={toast} />
|
||||
<Toolbar className="mb-4" left={leftToolbarTemplate} right={rightToolbarTemplate} />
|
||||
|
||||
<DataTable
|
||||
ref={dt}
|
||||
value={chantiers}
|
||||
selection={selectedChantiers}
|
||||
onSelectionChange={(e) => setSelectedChantiers(e.value)}
|
||||
dataKey="id"
|
||||
paginator
|
||||
rows={10}
|
||||
rowsPerPageOptions={[5, 10, 25]}
|
||||
className="datatable-responsive"
|
||||
paginatorTemplate="FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink CurrentPageReport RowsPerPageDropdown"
|
||||
currentPageReportTemplate="Affichage de {first} à {last} sur {totalRecords} chantiers"
|
||||
globalFilter={globalFilter}
|
||||
emptyMessage="Aucun chantier en cours trouvé."
|
||||
header={header}
|
||||
responsiveLayout="scroll"
|
||||
loading={loading}
|
||||
>
|
||||
<Column selectionMode="multiple" headerStyle={{ width: '4rem' }} />
|
||||
<Column field="nom" header="Nom" sortable headerStyle={{ minWidth: '12rem' }} />
|
||||
<Column field="client" header="Client" body={clientBodyTemplate} sortable headerStyle={{ minWidth: '12rem' }} />
|
||||
<Column field="adresse" header="Adresse" sortable headerStyle={{ minWidth: '12rem' }} />
|
||||
<Column field="dateDebut" header="Date début" body={(rowData) => dateBodyTemplate(rowData, 'dateDebut')} sortable headerStyle={{ minWidth: '10rem' }} />
|
||||
<Column field="dateFinPrevue" header="Date fin prévue" body={(rowData) => dateBodyTemplate(rowData, 'dateFinPrevue')} sortable headerStyle={{ minWidth: '10rem' }} />
|
||||
<Column field="statut" header="Statut" body={statusBodyTemplate} headerStyle={{ minWidth: '10rem' }} />
|
||||
<Column field="progress" header="Progression" body={progressBodyTemplate} headerStyle={{ minWidth: '12rem' }} />
|
||||
<Column field="budget" header="Budget" body={budgetBodyTemplate} headerStyle={{ minWidth: '12rem' }} />
|
||||
<Column body={actionBodyTemplate} headerStyle={{ minWidth: '8rem' }} />
|
||||
</DataTable>
|
||||
|
||||
<Dialog
|
||||
visible={updateDialog}
|
||||
style={{ width: '450px' }}
|
||||
header="Finaliser le chantier"
|
||||
modal
|
||||
className="p-fluid"
|
||||
footer={completeDialogFooter}
|
||||
onHide={() => setUpdateDialog(false)}
|
||||
>
|
||||
<div className="formgrid grid">
|
||||
<div className="field col-12">
|
||||
<label htmlFor="dateFinReelle">Date de fin réelle</label>
|
||||
<Calendar
|
||||
id="dateFinReelle"
|
||||
value={updateData.dateFinReelle}
|
||||
onChange={(e) => setUpdateData(prev => ({ ...prev, dateFinReelle: e.value }))}
|
||||
dateFormat="dd/mm/yy"
|
||||
showIcon
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="field col-12">
|
||||
<label htmlFor="montantReel">Montant réel (€)</label>
|
||||
<InputNumber
|
||||
id="montantReel"
|
||||
value={updateData.montantReel}
|
||||
onValueChange={(e) => setUpdateData(prev => ({ ...prev, montantReel: e.value || 0 }))}
|
||||
mode="currency"
|
||||
currency="EUR"
|
||||
locale="fr-FR"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ChantiersEnCoursPage;
|
||||
377
app/(main)/chantiers/execution-granulaire/page.tsx
Normal file
377
app/(main)/chantiers/execution-granulaire/page.tsx
Normal file
@@ -0,0 +1,377 @@
|
||||
'use client';
|
||||
|
||||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { DataTable } from 'primereact/datatable';
|
||||
import { Column } from 'primereact/column';
|
||||
import { Button } from 'primereact/button';
|
||||
import { Card } from 'primereact/card';
|
||||
import { ProgressBar } from 'primereact/progressbar';
|
||||
import { Badge } from 'primereact/badge';
|
||||
import { Toast } from 'primereact/toast';
|
||||
import { InputText } from 'primereact/inputtext';
|
||||
import { FilterMatchMode } from 'primereact/api';
|
||||
import { apiClient } from '../../../../services/api-client';
|
||||
import { executionGranulaireService } from '../../../../services/executionGranulaireService';
|
||||
|
||||
/**
|
||||
* Interface pour les chantiers avec avancement granulaire
|
||||
*/
|
||||
interface ChantierExecutionGranulaire {
|
||||
id: string;
|
||||
nom: string;
|
||||
client: string | { nom: string; prenom?: string };
|
||||
statut: 'EN_COURS' | 'PLANIFIE' | 'TERMINE' | 'EN_RETARD';
|
||||
dateDebut: Date;
|
||||
dateFinPrevue: Date;
|
||||
avancementGranulaire?: number;
|
||||
totalTaches: number;
|
||||
tachesTerminees: number;
|
||||
avancementCalcule: boolean; // Si l'avancement est basé sur les tâches ou les dates
|
||||
derniereMAJ?: Date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Page listant tous les chantiers avec possibilité d'accès à l'exécution granulaire
|
||||
*/
|
||||
const ChantiersExecutionGranulaire = () => {
|
||||
const router = useRouter();
|
||||
const toast = useRef<Toast>(null);
|
||||
|
||||
// États principaux
|
||||
const [chantiers, setChantiers] = useState<ChantierExecutionGranulaire[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [globalFilterValue, setGlobalFilterValue] = useState('');
|
||||
const [filters, setFilters] = useState({
|
||||
global: { value: null, matchMode: FilterMatchMode.CONTAINS }
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
loadChantiersWithAvancement();
|
||||
}, []);
|
||||
|
||||
/**
|
||||
* Charge tous les chantiers avec leur avancement granulaire
|
||||
*/
|
||||
const loadChantiersWithAvancement = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
|
||||
// Charger tous les chantiers actifs
|
||||
const chantiersResponse = await apiClient.get('/chantiers');
|
||||
const allChantiers = chantiersResponse.data.filter((c: any) =>
|
||||
c.actif && (c.statut === 'EN_COURS' || c.statut === 'PLANIFIE')
|
||||
);
|
||||
|
||||
// Pour chaque chantier, essayer d'obtenir l'avancement granulaire
|
||||
const chantiersWithAvancement = await Promise.all(
|
||||
allChantiers.map(async (chantier: any) => {
|
||||
let avancementData = null;
|
||||
let avancementCalcule = false;
|
||||
|
||||
try {
|
||||
// Essayer d'obtenir l'avancement granulaire
|
||||
avancementData = await executionGranulaireService.getAvancementGranulaire(chantier.id);
|
||||
avancementCalcule = true;
|
||||
} catch (error) {
|
||||
// Pas encore d'avancement granulaire, on utilisera un calcul basé sur les dates
|
||||
console.log(`Avancement granulaire non disponible pour ${chantier.nom}`);
|
||||
}
|
||||
|
||||
return {
|
||||
id: chantier.id,
|
||||
nom: chantier.nom,
|
||||
client: chantier.client?.nom || chantier.client || 'Client non défini',
|
||||
statut: chantier.statut,
|
||||
dateDebut: new Date(chantier.dateDebut),
|
||||
dateFinPrevue: new Date(chantier.dateFinPrevue || Date.now()),
|
||||
avancementGranulaire: avancementData?.pourcentage || calculateDateBasedProgress(chantier),
|
||||
totalTaches: avancementData?.totalTaches || 0,
|
||||
tachesTerminees: avancementData?.tachesTerminees || 0,
|
||||
avancementCalcule,
|
||||
derniereMAJ: avancementData?.derniereMAJ
|
||||
};
|
||||
})
|
||||
);
|
||||
|
||||
setChantiers(chantiersWithAvancement);
|
||||
} catch (error) {
|
||||
console.error('Erreur lors du chargement des chantiers:', error);
|
||||
showToast('error', 'Erreur', 'Impossible de charger la liste des chantiers');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Calcule l'avancement basé sur les dates si pas d'avancement granulaire
|
||||
*/
|
||||
const calculateDateBasedProgress = (chantier: any): number => {
|
||||
if (chantier.statut === 'TERMINE') return 100;
|
||||
if (chantier.statut === 'PLANIFIE') return 0;
|
||||
|
||||
if (!chantier.dateDebut || !chantier.dateFinPrevue) return 10;
|
||||
|
||||
const now = new Date();
|
||||
const start = new Date(chantier.dateDebut);
|
||||
const end = new Date(chantier.dateFinPrevue);
|
||||
|
||||
if (now < start) return 0;
|
||||
if (now > end) return 100;
|
||||
|
||||
const totalDays = (end.getTime() - start.getTime()) / (1000 * 60 * 60 * 24);
|
||||
const elapsedDays = (now.getTime() - start.getTime()) / (1000 * 60 * 60 * 24);
|
||||
|
||||
return Math.min(Math.max((elapsedDays / totalDays) * 100, 0), 100);
|
||||
};
|
||||
|
||||
/**
|
||||
* Affiche un toast message
|
||||
*/
|
||||
const showToast = (severity: 'success' | 'info' | 'warn' | 'error', summary: string, detail: string) => {
|
||||
toast.current?.show({ severity, summary, detail, life: 3000 });
|
||||
};
|
||||
|
||||
/**
|
||||
* Navigue vers la page d'exécution granulaire d'un chantier
|
||||
*/
|
||||
const navigateToExecution = (chantier: ChantierExecutionGranulaire) => {
|
||||
router.push(`/chantiers/${chantier.id}/execution-granulaire`);
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialise l'exécution granulaire pour un chantier
|
||||
*/
|
||||
const initialiserExecution = async (chantier: ChantierExecutionGranulaire) => {
|
||||
try {
|
||||
await executionGranulaireService.initialiserExecutionGranulaire(chantier.id);
|
||||
showToast('success', 'Succès', `Exécution granulaire initialisée pour ${chantier.nom}`);
|
||||
await loadChantiersWithAvancement(); // Recharger pour mettre à jour l'état
|
||||
} catch (error) {
|
||||
console.error('Erreur lors de l\'initialisation:', error);
|
||||
showToast('error', 'Erreur', 'Impossible d\'initialiser l\'exécution granulaire');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Gestion du filtre global
|
||||
*/
|
||||
const onGlobalFilterChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const value = e.target.value;
|
||||
let _filters = { ...filters };
|
||||
_filters['global'].value = value;
|
||||
|
||||
setFilters(_filters);
|
||||
setGlobalFilterValue(value);
|
||||
};
|
||||
|
||||
/**
|
||||
* Template pour l'affichage du nom du client
|
||||
*/
|
||||
const clientBodyTemplate = (rowData: ChantierExecutionGranulaire) => {
|
||||
if (typeof rowData.client === 'string') {
|
||||
return rowData.client;
|
||||
}
|
||||
return rowData.client?.nom || 'Client inconnu';
|
||||
};
|
||||
|
||||
/**
|
||||
* Template pour l'affichage du statut
|
||||
*/
|
||||
const statutBodyTemplate = (rowData: ChantierExecutionGranulaire) => {
|
||||
const severityMap: Record<string, "success" | "info" | "warning" | "danger"> = {
|
||||
'EN_COURS': 'info',
|
||||
'PLANIFIE': 'warning',
|
||||
'TERMINE': 'success',
|
||||
'EN_RETARD': 'danger'
|
||||
};
|
||||
return <Badge value={rowData.statut} severity={severityMap[rowData.statut]} />;
|
||||
};
|
||||
|
||||
/**
|
||||
* Template pour l'affichage de l'avancement
|
||||
*/
|
||||
const avancementBodyTemplate = (rowData: ChantierExecutionGranulaire) => {
|
||||
const progress = Math.round(rowData.avancementGranulaire || 0);
|
||||
|
||||
return (
|
||||
<div className="flex align-items-center gap-2">
|
||||
<ProgressBar
|
||||
value={progress}
|
||||
style={{ width: '100px', height: '8px' }}
|
||||
showValue={false}
|
||||
/>
|
||||
<span className="font-medium">{progress}%</span>
|
||||
{!rowData.avancementCalcule && (
|
||||
<i className="pi pi-calendar text-orange-500" title="Avancement basé sur les dates" />
|
||||
)}
|
||||
{rowData.avancementCalcule && (
|
||||
<i className="pi pi-check-circle text-green-500" title="Avancement granulaire disponible" />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Template pour l'affichage des tâches
|
||||
*/
|
||||
const tachesBodyTemplate = (rowData: ChantierExecutionGranulaire) => {
|
||||
if (!rowData.avancementCalcule) {
|
||||
return <span className="text-500">-</span>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="text-sm">
|
||||
<div>{rowData.tachesTerminees} / {rowData.totalTaches}</div>
|
||||
<div className="text-500">tâches terminées</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Template pour les actions
|
||||
*/
|
||||
const actionsBodyTemplate = (rowData: ChantierExecutionGranulaire) => {
|
||||
return (
|
||||
<div className="flex gap-2">
|
||||
{rowData.avancementCalcule ? (
|
||||
<Button
|
||||
icon="pi pi-play"
|
||||
label="Exécuter"
|
||||
size="small"
|
||||
onClick={() => navigateToExecution(rowData)}
|
||||
tooltip="Accéder à l'exécution granulaire"
|
||||
/>
|
||||
) : (
|
||||
<Button
|
||||
icon="pi pi-cog"
|
||||
label="Initialiser"
|
||||
size="small"
|
||||
severity="secondary"
|
||||
onClick={() => initialiserExecution(rowData)}
|
||||
tooltip="Initialiser l'exécution granulaire"
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* En-tête du tableau avec filtre de recherche
|
||||
*/
|
||||
const renderHeader = () => {
|
||||
return (
|
||||
<div className="flex justify-content-between align-items-center">
|
||||
<h6 className="m-0">Chantiers - Exécution Granulaire</h6>
|
||||
<span className="p-input-icon-left">
|
||||
<i className="pi pi-search" />
|
||||
<InputText
|
||||
value={globalFilterValue}
|
||||
onChange={onGlobalFilterChange}
|
||||
placeholder="Rechercher..."
|
||||
/>
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="grid">
|
||||
<Toast ref={toast} />
|
||||
|
||||
{/* En-tête de la page */}
|
||||
<div className="col-12">
|
||||
<Card>
|
||||
<div className="flex justify-content-between align-items-center">
|
||||
<div>
|
||||
<h4 className="mt-0 mb-2">Exécution Granulaire des Chantiers</h4>
|
||||
<p className="text-600 mt-0">
|
||||
Gérez l'avancement détaillé de vos chantiers avec un suivi granulaire par tâche
|
||||
</p>
|
||||
</div>
|
||||
<Button
|
||||
icon="pi pi-refresh"
|
||||
label="Actualiser"
|
||||
onClick={loadChantiersWithAvancement}
|
||||
loading={loading}
|
||||
/>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
{/* Tableau des chantiers */}
|
||||
<div className="col-12">
|
||||
<Card>
|
||||
<DataTable
|
||||
value={chantiers}
|
||||
loading={loading}
|
||||
header={renderHeader()}
|
||||
filters={filters}
|
||||
globalFilterFields={['nom', 'client']}
|
||||
emptyMessage="Aucun chantier trouvé"
|
||||
paginator
|
||||
rows={10}
|
||||
className="p-datatable-gridlines"
|
||||
responsiveLayout="scroll"
|
||||
sortField="nom"
|
||||
sortOrder={1}
|
||||
>
|
||||
<Column
|
||||
field="nom"
|
||||
header="Nom du chantier"
|
||||
sortable
|
||||
style={{ minWidth: '200px' }}
|
||||
/>
|
||||
<Column
|
||||
field="client"
|
||||
header="Client"
|
||||
body={clientBodyTemplate}
|
||||
sortable
|
||||
style={{ width: '150px' }}
|
||||
/>
|
||||
<Column
|
||||
field="statut"
|
||||
header="Statut"
|
||||
body={statutBodyTemplate}
|
||||
sortable
|
||||
style={{ width: '120px' }}
|
||||
/>
|
||||
<Column
|
||||
field="dateDebut"
|
||||
header="Date de début"
|
||||
sortable
|
||||
body={(rowData) => rowData.dateDebut.toLocaleDateString('fr-FR')}
|
||||
style={{ width: '120px' }}
|
||||
/>
|
||||
<Column
|
||||
field="dateFinPrevue"
|
||||
header="Fin prévue"
|
||||
sortable
|
||||
body={(rowData) => rowData.dateFinPrevue.toLocaleDateString('fr-FR')}
|
||||
style={{ width: '120px' }}
|
||||
/>
|
||||
<Column
|
||||
field="avancementGranulaire"
|
||||
header="Avancement"
|
||||
body={avancementBodyTemplate}
|
||||
sortable
|
||||
style={{ width: '160px' }}
|
||||
/>
|
||||
<Column
|
||||
header="Tâches"
|
||||
body={tachesBodyTemplate}
|
||||
style={{ width: '120px' }}
|
||||
/>
|
||||
<Column
|
||||
header="Actions"
|
||||
body={actionsBodyTemplate}
|
||||
style={{ width: '140px' }}
|
||||
/>
|
||||
</DataTable>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ChantiersExecutionGranulaire;
|
||||
1242
app/(main)/chantiers/nouveau/page.tsx
Normal file
1242
app/(main)/chantiers/nouveau/page.tsx
Normal file
File diff suppressed because it is too large
Load Diff
871
app/(main)/chantiers/page.tsx
Normal file
871
app/(main)/chantiers/page.tsx
Normal file
@@ -0,0 +1,871 @@
|
||||
'use client';
|
||||
|
||||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import { DataTable } from 'primereact/datatable';
|
||||
import { Column } from 'primereact/column';
|
||||
import { Button } from 'primereact/button';
|
||||
import { InputText } from 'primereact/inputtext';
|
||||
import { Card } from 'primereact/card';
|
||||
import { Dialog } from 'primereact/dialog';
|
||||
import { Toast } from 'primereact/toast';
|
||||
import { Toolbar } from 'primereact/toolbar';
|
||||
import { Tag } from 'primereact/tag';
|
||||
import { ProgressBar } from 'primereact/progressbar';
|
||||
import { Dropdown } from 'primereact/dropdown';
|
||||
import { Calendar } from 'primereact/calendar';
|
||||
import { InputTextarea } from 'primereact/inputtextarea';
|
||||
import { InputNumber } from 'primereact/inputnumber';
|
||||
import phaseService from '../../../services/phaseService';
|
||||
import chantierService from '../../../services/chantierService';
|
||||
import clientService from '../../../services/clientService';
|
||||
import { PhaseChantier } from '../../../types/btp-extended';
|
||||
import type { Chantier } from '../../../types/btp';
|
||||
import {
|
||||
ActionButtonGroup,
|
||||
ViewButton,
|
||||
EditButton,
|
||||
DeleteButton,
|
||||
ActionButton
|
||||
} from '../../../components/ui/ActionButton';
|
||||
import RoleProtectedPage from '@/components/RoleProtectedPage';
|
||||
|
||||
const ChantiersPageContent = () => {
|
||||
const [chantiers, setChantiers] = useState<Chantier[]>([]);
|
||||
const [clients, setClients] = useState<any[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [globalFilter, setGlobalFilter] = useState('');
|
||||
const [selectedChantiers, setSelectedChantiers] = useState<Chantier[]>([]);
|
||||
const [chantierDialog, setChantierDialog] = useState(false);
|
||||
const [deleteChantierDialog, setDeleteChantierDialog] = useState(false);
|
||||
const [permanentDelete, setPermanentDelete] = useState(false);
|
||||
const [deleteChantierssDialog, setDeleteChantierssDialog] = useState(false);
|
||||
const [phasesDialog, setPhasesDialog] = useState(false);
|
||||
const [selectedChantierPhases, setSelectedChantierPhases] = useState<PhaseChantier[]>([]);
|
||||
const [currentChantier, setCurrentChantier] = useState<Chantier | null>(null);
|
||||
const [chantier, setChantier] = useState<Chantier>({
|
||||
id: '',
|
||||
nom: '',
|
||||
description: '',
|
||||
adresse: '',
|
||||
dateDebut: new Date(),
|
||||
dateFinPrevue: new Date(),
|
||||
dateFinReelle: null,
|
||||
statut: 'PLANIFIE',
|
||||
montantPrevu: 0,
|
||||
montantReel: 0,
|
||||
actif: true,
|
||||
client: null
|
||||
});
|
||||
const [submitted, setSubmitted] = useState(false);
|
||||
const toast = useRef<Toast>(null);
|
||||
const dt = useRef<DataTable<Chantier[]>>(null);
|
||||
|
||||
const statuts = [
|
||||
{ label: 'Planifié', value: 'PLANIFIE' },
|
||||
{ label: 'En cours', value: 'EN_COURS' },
|
||||
{ label: 'Terminé', value: 'TERMINE' },
|
||||
{ label: 'Annulé', value: 'ANNULE' },
|
||||
{ label: 'Suspendu', value: 'SUSPENDU' }
|
||||
];
|
||||
|
||||
// États workflow BTP
|
||||
const workflowTransitions = {
|
||||
'PLANIFIE': ['EN_COURS', 'ANNULE'],
|
||||
'EN_COURS': ['TERMINE', 'SUSPENDU', 'ANNULE'],
|
||||
'SUSPENDU': ['EN_COURS', 'ANNULE'],
|
||||
'TERMINE': [], // Statut final
|
||||
'ANNULE': [] // Statut final
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
loadChantiers();
|
||||
loadClients();
|
||||
}, []);
|
||||
|
||||
const loadChantiers = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const data = await chantierService.getAll();
|
||||
setChantiers(data);
|
||||
} catch (error: any) {
|
||||
const errorMessage = error?.userMessage || error?.message || 'Impossible de charger les chantiers';
|
||||
toast.current?.show({
|
||||
severity: 'error',
|
||||
summary: 'Erreur de chargement',
|
||||
detail: errorMessage,
|
||||
life: 5000
|
||||
});
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const loadClients = async () => {
|
||||
try {
|
||||
const data = await clientService.getAll();
|
||||
setClients(data.map(client => ({
|
||||
label: `${client.prenom} ${client.nom}${client.entreprise ? ' - ' + client.entreprise : ''}`,
|
||||
value: client.id,
|
||||
client: client
|
||||
})));
|
||||
} catch (error) {
|
||||
console.warn('Erreur lors du chargement des clients:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const openNew = () => {
|
||||
setChantier({
|
||||
id: '',
|
||||
nom: '',
|
||||
description: '',
|
||||
adresse: '',
|
||||
dateDebut: new Date(),
|
||||
dateFinPrevue: new Date(),
|
||||
dateFinReelle: null,
|
||||
statut: 'PLANIFIE',
|
||||
montantPrevu: 0,
|
||||
montantReel: 0,
|
||||
actif: true,
|
||||
client: null
|
||||
});
|
||||
setSubmitted(false);
|
||||
setChantierDialog(true);
|
||||
};
|
||||
|
||||
const hideDialog = () => {
|
||||
setSubmitted(false);
|
||||
setChantierDialog(false);
|
||||
};
|
||||
|
||||
const hideDeleteChantierDialog = () => {
|
||||
setDeleteChantierDialog(false);
|
||||
};
|
||||
|
||||
const hideDeleteChantierssDialog = () => {
|
||||
setDeleteChantierssDialog(false);
|
||||
};
|
||||
|
||||
const saveChantier = async () => {
|
||||
setSubmitted(true);
|
||||
|
||||
if (chantier.nom.trim() && chantier.client && chantier.adresse.trim()) {
|
||||
try {
|
||||
let updatedChantiers = [...chantiers];
|
||||
|
||||
// Préparer les données pour l'envoi
|
||||
const chantierToSave: any = {
|
||||
nom: chantier.nom.trim(),
|
||||
description: chantier.description || '',
|
||||
adresse: chantier.adresse.trim(),
|
||||
dateDebut: chantier.dateDebut instanceof Date ? chantier.dateDebut.toISOString().split('T')[0] : chantier.dateDebut,
|
||||
dateFinPrevue: chantier.dateFinPrevue instanceof Date ? chantier.dateFinPrevue.toISOString().split('T')[0] : chantier.dateFinPrevue,
|
||||
statut: chantier.statut,
|
||||
montantPrevu: Number(chantier.montantPrevu) || 0,
|
||||
montantReel: Number(chantier.montantReel) || 0,
|
||||
actif: chantier.actif !== undefined ? chantier.actif : true,
|
||||
clientId: chantier.client // Envoyer l'ID du client directement
|
||||
};
|
||||
|
||||
// Ajouter dateFinReelle seulement si elle existe
|
||||
if (chantier.dateFinReelle) {
|
||||
chantierToSave.dateFinReelle = chantier.dateFinReelle instanceof Date ? chantier.dateFinReelle.toISOString().split('T')[0] : chantier.dateFinReelle;
|
||||
}
|
||||
|
||||
// Ne pas envoyer l'id lors de la création
|
||||
if (chantier.id) {
|
||||
chantierToSave.id = chantier.id;
|
||||
}
|
||||
|
||||
console.log('Données à envoyer:', chantierToSave);
|
||||
|
||||
if (chantier.id) {
|
||||
// Mise à jour
|
||||
const updatedChantier = await chantierService.update(chantier.id, chantierToSave);
|
||||
const index = chantiers.findIndex(c => c.id === chantier.id);
|
||||
updatedChantiers[index] = updatedChantier;
|
||||
|
||||
toast.current?.show({
|
||||
severity: 'success',
|
||||
summary: 'Succès',
|
||||
detail: 'Chantier mis à jour',
|
||||
life: 3000
|
||||
});
|
||||
} else {
|
||||
// Créer le nouveau chantier
|
||||
const newChantier = await chantierService.create(chantierToSave);
|
||||
updatedChantiers.push(newChantier);
|
||||
|
||||
toast.current?.show({
|
||||
severity: 'success',
|
||||
summary: 'Succès',
|
||||
detail: 'Chantier créé',
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
|
||||
setChantiers(updatedChantiers);
|
||||
setChantierDialog(false);
|
||||
setChantier({
|
||||
id: '',
|
||||
nom: '',
|
||||
description: '',
|
||||
adresse: '',
|
||||
dateDebut: new Date(),
|
||||
dateFinPrevue: new Date(),
|
||||
dateFinReelle: null,
|
||||
statut: 'PLANIFIE',
|
||||
montantPrevu: 0,
|
||||
montantReel: 0,
|
||||
actif: true,
|
||||
client: null
|
||||
});
|
||||
} catch (error: any) {
|
||||
// Utiliser le message enrichi par l'intercepteur
|
||||
const errorMessage = error?.userMessage || error?.message || 'Impossible de sauvegarder le chantier';
|
||||
|
||||
toast.current?.show({
|
||||
severity: 'error',
|
||||
summary: 'Erreur de sauvegarde',
|
||||
detail: errorMessage,
|
||||
life: 5000
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const editChantier = (chantier: Chantier) => {
|
||||
setChantier({
|
||||
...chantier,
|
||||
client: chantier.client?.id || null
|
||||
});
|
||||
setChantierDialog(true);
|
||||
};
|
||||
|
||||
const confirmDeleteChantier = (chantier: Chantier, permanent: boolean = false) => {
|
||||
setChantier(chantier);
|
||||
setPermanentDelete(permanent);
|
||||
setDeleteChantierDialog(true);
|
||||
};
|
||||
|
||||
const deleteChantier = async () => {
|
||||
try {
|
||||
await chantierService.delete(chantier.id, permanentDelete);
|
||||
let updatedChantiers = chantiers.filter(c => c.id !== chantier.id);
|
||||
setChantiers(updatedChantiers);
|
||||
setDeleteChantierDialog(false);
|
||||
setPermanentDelete(false);
|
||||
toast.current?.show({
|
||||
severity: 'success',
|
||||
summary: 'Succès',
|
||||
detail: 'Chantier supprimé',
|
||||
life: 3000
|
||||
});
|
||||
} catch (error: any) {
|
||||
const errorMessage = error?.userMessage || error?.message || 'Impossible de supprimer le chantier';
|
||||
const statusCode = error?.statusCode;
|
||||
|
||||
// Message d'erreur plus détaillé selon le code de statut
|
||||
let detail = errorMessage;
|
||||
if (statusCode === 409) {
|
||||
detail = 'Ce chantier ne peut pas être supprimé (peut-être en cours ou terminé)';
|
||||
} else if (statusCode === 404) {
|
||||
detail = 'Ce chantier n\'existe plus';
|
||||
} else if (statusCode === 403) {
|
||||
detail = 'Vous n\'avez pas les droits pour supprimer ce chantier';
|
||||
}
|
||||
|
||||
toast.current?.show({
|
||||
severity: 'error',
|
||||
summary: 'Erreur de suppression',
|
||||
detail: detail,
|
||||
life: 5000
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const exportCSV = () => {
|
||||
dt.current?.exportCSV();
|
||||
};
|
||||
|
||||
const onInputChange = (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>, name: string) => {
|
||||
const val = (e.target && e.target.value) || '';
|
||||
let _chantier = { ...chantier };
|
||||
(_chantier as any)[name] = val;
|
||||
setChantier(_chantier);
|
||||
};
|
||||
|
||||
const onDateChange = (e: any, name: string) => {
|
||||
let _chantier = { ...chantier };
|
||||
(_chantier as any)[name] = e.value;
|
||||
setChantier(_chantier);
|
||||
};
|
||||
|
||||
const onNumberChange = (e: any, name: string) => {
|
||||
let _chantier = { ...chantier };
|
||||
(_chantier as any)[name] = e.value;
|
||||
setChantier(_chantier);
|
||||
};
|
||||
|
||||
const onDropdownChange = (e: any, name: string) => {
|
||||
let _chantier = { ...chantier };
|
||||
(_chantier as any)[name] = e.value;
|
||||
setChantier(_chantier);
|
||||
};
|
||||
|
||||
const leftToolbarTemplate = () => {
|
||||
return (
|
||||
<div className="my-2">
|
||||
<Button
|
||||
label="Nouveau"
|
||||
icon="pi pi-plus"
|
||||
severity="success"
|
||||
className="mr-2 p-button-text p-button-rounded"
|
||||
onClick={openNew}
|
||||
/>
|
||||
<Button
|
||||
label="Supprimer"
|
||||
icon="pi pi-trash"
|
||||
severity="danger"
|
||||
className="p-button-text p-button-rounded"
|
||||
onClick={() => setDeleteChantierssDialog(true)}
|
||||
disabled={!selectedChantiers || selectedChantiers.length === 0}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const rightToolbarTemplate = () => {
|
||||
return (
|
||||
<Button
|
||||
label="Exporter"
|
||||
icon="pi pi-upload"
|
||||
severity="help"
|
||||
className="p-button-text p-button-rounded"
|
||||
onClick={exportCSV}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
const voirPhasesChantier = async (chantier: Chantier) => {
|
||||
try {
|
||||
setCurrentChantier(chantier);
|
||||
const phases = await phaseService.getByChantier(chantier.id);
|
||||
setSelectedChantierPhases(phases || []);
|
||||
setPhasesDialog(true);
|
||||
} catch (error) {
|
||||
console.warn('Erreur lors du chargement des phases:', error);
|
||||
toast.current?.show({
|
||||
severity: 'error',
|
||||
summary: 'Erreur',
|
||||
detail: 'Impossible de charger les phases du chantier',
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const actionBodyTemplate = (rowData: Chantier) => {
|
||||
return (
|
||||
<ActionButtonGroup>
|
||||
<ActionButton
|
||||
icon="pi pi-sitemap"
|
||||
tooltip="Gérer les phases"
|
||||
onClick={() => window.location.href = `/chantiers/${rowData.id}/phases`}
|
||||
color="blue"
|
||||
/>
|
||||
<EditButton
|
||||
tooltip="Modifier"
|
||||
onClick={() => editChantier(rowData)}
|
||||
/>
|
||||
<DeleteButton
|
||||
tooltip="Supprimer"
|
||||
onClick={() => confirmDeleteChantier(rowData, true)}
|
||||
/>
|
||||
</ActionButtonGroup>
|
||||
);
|
||||
};
|
||||
|
||||
const statusBodyTemplate = (rowData: Chantier) => {
|
||||
const getSeverity = (status: string) => {
|
||||
switch (status) {
|
||||
case 'PLANIFIE': return 'info';
|
||||
case 'EN_COURS': return 'success';
|
||||
case 'TERMINE': return 'secondary';
|
||||
case 'ANNULE': return 'danger';
|
||||
case 'SUSPENDU': return 'warning';
|
||||
default: return 'info';
|
||||
}
|
||||
};
|
||||
|
||||
const getLabel = (status: string) => {
|
||||
switch (status) {
|
||||
case 'PLANIFIE': return 'Planifié';
|
||||
case 'EN_COURS': return 'En cours';
|
||||
case 'TERMINE': return 'Terminé';
|
||||
case 'ANNULE': return 'Annulé';
|
||||
case 'SUSPENDU': return 'Suspendu';
|
||||
default: return status;
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Tag
|
||||
value={getLabel(rowData.statut)}
|
||||
severity={getSeverity(rowData.statut)}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
const actifBodyTemplate = (rowData: Chantier) => {
|
||||
return (
|
||||
<Tag
|
||||
value={rowData.actif ? 'Actif' : 'Inactif'}
|
||||
severity={rowData.actif ? 'success' : 'danger'}
|
||||
icon={rowData.actif ? 'pi pi-check' : 'pi pi-times'}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
const progressBodyTemplate = (rowData: Chantier) => {
|
||||
if (rowData.statut === 'TERMINE') {
|
||||
return <ProgressBar value={100} style={{ height: '6px' }} />;
|
||||
}
|
||||
|
||||
if (rowData.statut === 'ANNULE') {
|
||||
return <ProgressBar value={0} style={{ height: '6px' }} color="#ef4444" />;
|
||||
}
|
||||
|
||||
// Calcul approximatif basé sur les dates
|
||||
const now = new Date();
|
||||
const start = new Date(rowData.dateDebut);
|
||||
const end = new Date(rowData.dateFinPrevue);
|
||||
const totalDays = (end.getTime() - start.getTime()) / (1000 * 60 * 60 * 24);
|
||||
const elapsedDays = (now.getTime() - start.getTime()) / (1000 * 60 * 60 * 24);
|
||||
const progress = Math.min(Math.max((elapsedDays / totalDays) * 100, 0), 100);
|
||||
|
||||
return <ProgressBar value={progress} style={{ height: '6px' }} />;
|
||||
};
|
||||
|
||||
const clientBodyTemplate = (rowData: Chantier) => {
|
||||
if (!rowData.client) return '';
|
||||
return `${rowData.client.prenom} ${rowData.client.nom}`;
|
||||
};
|
||||
|
||||
const dateBodyTemplate = (rowData: Chantier, field: string) => {
|
||||
const date = (rowData as any)[field];
|
||||
return date ? formatDate(date) : '';
|
||||
};
|
||||
|
||||
const header = (
|
||||
<div className="flex flex-column md:flex-row md:justify-content-between md:align-items-center">
|
||||
<h5 className="m-0">Gestion des Chantiers</h5>
|
||||
<span className="block mt-2 md:mt-0 p-input-icon-left">
|
||||
<i className="pi pi-search" />
|
||||
<InputText
|
||||
type="search"
|
||||
placeholder="Rechercher..."
|
||||
onInput={(e) => setGlobalFilter(e.currentTarget.value)}
|
||||
/>
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
|
||||
const chantierDialogFooter = (
|
||||
<>
|
||||
<Button label="Annuler" icon="pi pi-times" text onClick={hideDialog} />
|
||||
<Button label="Sauvegarder" icon="pi pi-check" text onClick={saveChantier} />
|
||||
</>
|
||||
);
|
||||
|
||||
const deleteChantierDialogFooter = (
|
||||
<>
|
||||
<Button label="Non" icon="pi pi-times" text onClick={hideDeleteChantierDialog} />
|
||||
<Button label="Oui" icon="pi pi-check" text onClick={deleteChantier} />
|
||||
</>
|
||||
);
|
||||
|
||||
const phaseDialogFooter = (
|
||||
<div className="flex justify-content-between">
|
||||
<div className="flex gap-2">
|
||||
<Button
|
||||
label="Nouvelle Phase"
|
||||
icon="pi pi-plus"
|
||||
onClick={() => {
|
||||
if (currentChantier) {
|
||||
window.location.href = `/chantiers/${currentChantier.id}/phases`;
|
||||
}
|
||||
}}
|
||||
className="p-button-text p-button-rounded p-button-success"
|
||||
tooltip="Aller à la page de gestion des phases"
|
||||
/>
|
||||
<Button
|
||||
label="Gérer les Phases"
|
||||
icon="pi pi-sitemap"
|
||||
onClick={() => {
|
||||
if (currentChantier) {
|
||||
window.location.href = `/chantiers/${currentChantier.id}/phases`;
|
||||
}
|
||||
}}
|
||||
className="p-button-text p-button-rounded p-button-info"
|
||||
tooltip="Interface complète de gestion des phases"
|
||||
/>
|
||||
</div>
|
||||
<Button label="Fermer" icon="pi pi-times" onClick={() => setPhasesDialog(false)} />
|
||||
</div>
|
||||
);
|
||||
|
||||
const phaseAvancementTemplate = (phase: PhaseChantier) => {
|
||||
const avancement = phase.pourcentageAvancement || 0;
|
||||
return (
|
||||
<div className="flex align-items-center gap-2">
|
||||
<ProgressBar
|
||||
value={avancement}
|
||||
className="w-6rem"
|
||||
style={{ height: '0.5rem' }}
|
||||
/>
|
||||
<span className="text-sm font-medium">{avancement}%</span>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const phaseStatutTemplate = (phase: PhaseChantier) => {
|
||||
return (
|
||||
<Tag
|
||||
value={phaseService.getStatutLabel(phase.statut)}
|
||||
style={{
|
||||
backgroundColor: phaseService.getStatutColor(phase.statut),
|
||||
color: 'white'
|
||||
}}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
const phaseBudgetTemplate = (phase: PhaseChantier) => {
|
||||
return new Intl.NumberFormat('fr-FR', {
|
||||
style: 'currency',
|
||||
currency: 'EUR',
|
||||
notation: 'compact'
|
||||
}).format(phase.budgetPrevu || 0);
|
||||
};
|
||||
|
||||
const formatDate = (dateString: string | Date | null) => {
|
||||
if (!dateString) return '';
|
||||
const date = new Date(dateString);
|
||||
return date.toLocaleDateString('fr-FR');
|
||||
};
|
||||
|
||||
const formatCurrency = (amount: number) => {
|
||||
return new Intl.NumberFormat('fr-FR', {
|
||||
style: 'currency',
|
||||
currency: 'EUR'
|
||||
}).format(amount);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="grid">
|
||||
<div className="col-12">
|
||||
<Card>
|
||||
<Toast ref={toast} />
|
||||
<Toolbar className="mb-4" left={leftToolbarTemplate} right={rightToolbarTemplate} />
|
||||
|
||||
<DataTable
|
||||
ref={dt}
|
||||
value={chantiers}
|
||||
selection={selectedChantiers}
|
||||
onSelectionChange={(e) => setSelectedChantiers(e.value)}
|
||||
dataKey="id"
|
||||
paginator
|
||||
rows={10}
|
||||
rowsPerPageOptions={[5, 10, 25]}
|
||||
className="datatable-responsive"
|
||||
paginatorTemplate="FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink CurrentPageReport RowsPerPageDropdown"
|
||||
currentPageReportTemplate="Affichage de {first} à {last} sur {totalRecords} chantiers"
|
||||
globalFilter={globalFilter}
|
||||
emptyMessage="Aucun chantier trouvé."
|
||||
header={header}
|
||||
responsiveLayout="scroll"
|
||||
loading={loading}
|
||||
>
|
||||
<Column selectionMode="multiple" headerStyle={{ width: '4rem' }} />
|
||||
<Column field="nom" header="Nom" sortable headerStyle={{ minWidth: '12rem' }} />
|
||||
<Column field="client" header="Client" body={clientBodyTemplate} sortable headerStyle={{ minWidth: '12rem' }} />
|
||||
<Column field="adresse" header="Adresse" sortable headerStyle={{ minWidth: '12rem' }} />
|
||||
<Column field="dateDebut" header="Date début" body={(rowData) => dateBodyTemplate(rowData, 'dateDebut')} sortable headerStyle={{ minWidth: '10rem' }} />
|
||||
<Column field="dateFinPrevue" header="Date fin prévue" body={(rowData) => dateBodyTemplate(rowData, 'dateFinPrevue')} sortable headerStyle={{ minWidth: '10rem' }} />
|
||||
<Column field="statut" header="Statut" body={statusBodyTemplate} sortable headerStyle={{ minWidth: '8rem' }} />
|
||||
<Column field="actif" header="État" body={actifBodyTemplate} sortable headerStyle={{ minWidth: '7rem' }} />
|
||||
<Column field="progress" header="Progression" body={progressBodyTemplate} headerStyle={{ minWidth: '10rem' }} />
|
||||
<Column field="montantPrevu" header="Montant prévu" body={(rowData) => formatCurrency(rowData.montantPrevu)} sortable headerStyle={{ minWidth: '10rem' }} />
|
||||
<Column body={actionBodyTemplate} headerStyle={{ minWidth: '10rem' }} />
|
||||
</DataTable>
|
||||
|
||||
<Dialog
|
||||
visible={chantierDialog}
|
||||
style={{ width: '600px' }}
|
||||
header="Détails du Chantier"
|
||||
modal
|
||||
className="p-fluid"
|
||||
footer={chantierDialogFooter}
|
||||
onHide={hideDialog}
|
||||
>
|
||||
<div className="formgrid grid">
|
||||
<div className="field col-12">
|
||||
<label htmlFor="nom">Nom du chantier</label>
|
||||
<InputText
|
||||
id="nom"
|
||||
value={chantier.nom}
|
||||
onChange={(e) => onInputChange(e, 'nom')}
|
||||
required
|
||||
className={submitted && !chantier.nom ? 'p-invalid' : ''}
|
||||
/>
|
||||
{submitted && !chantier.nom && <small className="p-invalid">Le nom est requis.</small>}
|
||||
</div>
|
||||
|
||||
<div className="field col-12">
|
||||
<label htmlFor="client">Client</label>
|
||||
<Dropdown
|
||||
id="client"
|
||||
value={chantier.client}
|
||||
options={clients}
|
||||
onChange={(e) => onDropdownChange(e, 'client')}
|
||||
placeholder="Sélectionnez un client"
|
||||
required
|
||||
className={submitted && !chantier.client ? 'p-invalid' : ''}
|
||||
/>
|
||||
{submitted && !chantier.client && <small className="p-invalid">Le client est requis.</small>}
|
||||
</div>
|
||||
|
||||
<div className="field col-12">
|
||||
<label htmlFor="description">Description</label>
|
||||
<InputTextarea
|
||||
id="description"
|
||||
value={chantier.description}
|
||||
onChange={(e) => onInputChange(e, 'description')}
|
||||
rows={3}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="field col-12">
|
||||
<label htmlFor="adresse">Adresse</label>
|
||||
<InputTextarea
|
||||
id="adresse"
|
||||
value={chantier.adresse}
|
||||
onChange={(e) => onInputChange(e, 'adresse')}
|
||||
rows={2}
|
||||
required
|
||||
className={submitted && !chantier.adresse ? 'p-invalid' : ''}
|
||||
/>
|
||||
{submitted && !chantier.adresse && <small className="p-invalid">L'adresse est requise.</small>}
|
||||
</div>
|
||||
|
||||
<div className="field col-12 md:col-6">
|
||||
<label htmlFor="dateDebut">Date de début</label>
|
||||
<Calendar
|
||||
id="dateDebut"
|
||||
value={chantier.dateDebut}
|
||||
onChange={(e) => onDateChange(e, 'dateDebut')}
|
||||
dateFormat="dd/mm/yy"
|
||||
showIcon
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="field col-12 md:col-6">
|
||||
<label htmlFor="dateFinPrevue">Date de fin prévue</label>
|
||||
<Calendar
|
||||
id="dateFinPrevue"
|
||||
value={chantier.dateFinPrevue}
|
||||
onChange={(e) => onDateChange(e, 'dateFinPrevue')}
|
||||
dateFormat="dd/mm/yy"
|
||||
showIcon
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="field col-12 md:col-6">
|
||||
<label htmlFor="statut">Statut</label>
|
||||
<Dropdown
|
||||
id="statut"
|
||||
value={chantier.statut}
|
||||
options={statuts}
|
||||
onChange={(e) => onDropdownChange(e, 'statut')}
|
||||
placeholder="Sélectionnez un statut"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="field col-12 md:col-6">
|
||||
<label htmlFor="montantPrevu">Montant prévu (€)</label>
|
||||
<InputNumber
|
||||
id="montantPrevu"
|
||||
value={chantier.montantPrevu}
|
||||
onValueChange={(e) => onNumberChange(e, 'montantPrevu')}
|
||||
mode="currency"
|
||||
currency="EUR"
|
||||
locale="fr-FR"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{chantier.statut === 'TERMINE' && (
|
||||
<>
|
||||
<div className="field col-12 md:col-6">
|
||||
<label htmlFor="dateFinReelle">Date de fin réelle</label>
|
||||
<Calendar
|
||||
id="dateFinReelle"
|
||||
value={chantier.dateFinReelle}
|
||||
onChange={(e) => onDateChange(e, 'dateFinReelle')}
|
||||
dateFormat="dd/mm/yy"
|
||||
showIcon
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="field col-12 md:col-6">
|
||||
<label htmlFor="montantReel">Montant réel (€)</label>
|
||||
<InputNumber
|
||||
id="montantReel"
|
||||
value={chantier.montantReel}
|
||||
onValueChange={(e) => onNumberChange(e, 'montantReel')}
|
||||
mode="currency"
|
||||
currency="EUR"
|
||||
locale="fr-FR"
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</Dialog>
|
||||
|
||||
<Dialog
|
||||
visible={deleteChantierDialog}
|
||||
style={{ width: '450px' }}
|
||||
header="Confirmer la suppression"
|
||||
modal
|
||||
footer={deleteChantierDialogFooter}
|
||||
onHide={hideDeleteChantierDialog}
|
||||
>
|
||||
<div className="flex align-items-center justify-content-center">
|
||||
<i className="pi pi-exclamation-triangle mr-3" style={{ fontSize: '2rem' }} />
|
||||
{chantier && (
|
||||
<span>
|
||||
Êtes-vous sûr de vouloir supprimer le chantier <b>{chantier.nom}</b> ?
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</Dialog>
|
||||
|
||||
{/* Dialog des phases du chantier */}
|
||||
<Dialog
|
||||
visible={phasesDialog}
|
||||
style={{ width: '90vw', height: '80vh' }}
|
||||
header={`Phases du chantier: ${currentChantier?.nom}`}
|
||||
modal
|
||||
className="p-fluid"
|
||||
footer={phaseDialogFooter}
|
||||
onHide={() => setPhasesDialog(false)}
|
||||
maximizable
|
||||
>
|
||||
<div className="grid mb-3">
|
||||
<div className="col-12 md:col-3">
|
||||
<Card>
|
||||
<div className="text-center">
|
||||
<div className="text-2xl font-bold text-blue-500">{selectedChantierPhases.length}</div>
|
||||
<div className="text-color-secondary">Total phases</div>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
<div className="col-12 md:col-3">
|
||||
<Card>
|
||||
<div className="text-center">
|
||||
<div className="text-2xl font-bold text-green-500">
|
||||
{selectedChantierPhases.filter(p => p.statut === 'EN_COURS').length}
|
||||
</div>
|
||||
<div className="text-color-secondary">En cours</div>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
<div className="col-12 md:col-3">
|
||||
<Card>
|
||||
<div className="text-center">
|
||||
<div className="text-2xl font-bold text-purple-500">
|
||||
{selectedChantierPhases.filter(p => p.statut === 'TERMINEE').length}
|
||||
</div>
|
||||
<div className="text-color-secondary">Terminées</div>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
<div className="col-12 md:col-3">
|
||||
<Card>
|
||||
<div className="text-center">
|
||||
<div className="text-2xl font-bold text-red-500">
|
||||
{selectedChantierPhases.filter(p => phaseService.isEnRetard(p)).length}
|
||||
</div>
|
||||
<div className="text-color-secondary">En retard</div>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<DataTable
|
||||
value={selectedChantierPhases}
|
||||
paginator
|
||||
rows={10}
|
||||
dataKey="id"
|
||||
className="datatable-responsive"
|
||||
emptyMessage="Aucune phase définie pour ce chantier"
|
||||
responsiveLayout="scroll"
|
||||
>
|
||||
<Column field="nom" header="Phase" sortable style={{ minWidth: '12rem' }} />
|
||||
<Column
|
||||
header="Statut"
|
||||
body={phaseStatutTemplate}
|
||||
sortable
|
||||
style={{ minWidth: '8rem' }}
|
||||
/>
|
||||
<Column
|
||||
header="Avancement"
|
||||
body={phaseAvancementTemplate}
|
||||
style={{ minWidth: '10rem' }}
|
||||
/>
|
||||
<Column
|
||||
field="dateDebutPrevue"
|
||||
header="Début prévu"
|
||||
body={(rowData) => formatDate(rowData.dateDebutPrevue)}
|
||||
sortable
|
||||
style={{ minWidth: '10rem' }}
|
||||
/>
|
||||
<Column
|
||||
field="dateFinPrevue"
|
||||
header="Fin prévue"
|
||||
body={(rowData) => formatDate(rowData.dateFinPrevue)}
|
||||
sortable
|
||||
style={{ minWidth: '10rem' }}
|
||||
/>
|
||||
<Column
|
||||
header="Budget"
|
||||
body={phaseBudgetTemplate}
|
||||
style={{ minWidth: '8rem' }}
|
||||
/>
|
||||
<Column
|
||||
header="Critique"
|
||||
body={(rowData) => rowData.critique ?
|
||||
<Tag value="Oui" severity="danger" /> :
|
||||
<Tag value="Non" severity="success" />
|
||||
}
|
||||
style={{ minWidth: '6rem' }}
|
||||
/>
|
||||
</DataTable>
|
||||
</Dialog>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const ChantiersPage = () => {
|
||||
return (
|
||||
<RoleProtectedPage
|
||||
requiredPage="CHANTIERS"
|
||||
fallbackMessage="Vous devez avoir accès aux chantiers pour consulter cette page."
|
||||
>
|
||||
<ChantiersPageContent />
|
||||
</RoleProtectedPage>
|
||||
);
|
||||
};
|
||||
|
||||
export default ChantiersPage;
|
||||
376
app/(main)/chantiers/planifies/page.tsx
Normal file
376
app/(main)/chantiers/planifies/page.tsx
Normal file
@@ -0,0 +1,376 @@
|
||||
'use client';
|
||||
|
||||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import { DataTable } from 'primereact/datatable';
|
||||
import { Column } from 'primereact/column';
|
||||
import { Button } from 'primereact/button';
|
||||
import { InputText } from 'primereact/inputtext';
|
||||
import { Card } from 'primereact/card';
|
||||
import { Toast } from 'primereact/toast';
|
||||
import { Toolbar } from 'primereact/toolbar';
|
||||
import { Tag } from 'primereact/tag';
|
||||
import { Dialog } from 'primereact/dialog';
|
||||
import { Calendar } from 'primereact/calendar';
|
||||
import { chantierService } from '../../../../services/api';
|
||||
import { formatDate, formatCurrency } from '../../../../utils/formatters';
|
||||
import type { Chantier } from '../../../../types/btp';
|
||||
|
||||
const ChantiersPlanifiesPage = () => {
|
||||
const [chantiers, setChantiers] = useState<Chantier[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [globalFilter, setGlobalFilter] = useState('');
|
||||
const [selectedChantiers, setSelectedChantiers] = useState<Chantier[]>([]);
|
||||
const [startDialog, setStartDialog] = useState(false);
|
||||
const [selectedChantier, setSelectedChantier] = useState<Chantier | null>(null);
|
||||
const [startDate, setStartDate] = useState<Date>(new Date());
|
||||
const toast = useRef<Toast>(null);
|
||||
const dt = useRef<DataTable<Chantier[]>>(null);
|
||||
|
||||
useEffect(() => {
|
||||
loadChantiers();
|
||||
}, []);
|
||||
|
||||
const loadChantiers = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const data = await chantierService.getAll();
|
||||
// Filtrer seulement les chantiers planifiés
|
||||
const chantiersPlanifies = data.filter(chantier => chantier.statut === 'PLANIFIE');
|
||||
setChantiers(chantiersPlanifies);
|
||||
} catch (error) {
|
||||
console.error('Erreur lors du chargement des chantiers:', error);
|
||||
toast.current?.show({
|
||||
severity: 'error',
|
||||
summary: 'Erreur',
|
||||
detail: 'Impossible de charger les chantiers planifiés',
|
||||
life: 3000
|
||||
});
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const getDaysUntilStart = (dateDebut: string | Date) => {
|
||||
const today = new Date();
|
||||
const start = new Date(dateDebut);
|
||||
const diffTime = start.getTime() - today.getTime();
|
||||
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
|
||||
return diffDays;
|
||||
};
|
||||
|
||||
const isStartingSoon = (dateDebut: string | Date) => {
|
||||
const days = getDaysUntilStart(dateDebut);
|
||||
return days >= 0 && days <= 7; // Dans les 7 prochains jours
|
||||
};
|
||||
|
||||
const isOverdue = (dateDebut: string | Date) => {
|
||||
const days = getDaysUntilStart(dateDebut);
|
||||
return days < 0; // Date de début dépassée
|
||||
};
|
||||
|
||||
const startChantier = (chantier: Chantier) => {
|
||||
setSelectedChantier(chantier);
|
||||
setStartDate(new Date());
|
||||
setStartDialog(true);
|
||||
};
|
||||
|
||||
const handleStartChantier = async () => {
|
||||
if (!selectedChantier) return;
|
||||
|
||||
try {
|
||||
const updatedChantier = {
|
||||
...selectedChantier,
|
||||
statut: 'EN_COURS',
|
||||
dateDebut: startDate
|
||||
};
|
||||
|
||||
await chantierService.update(selectedChantier.id, updatedChantier);
|
||||
|
||||
// Retirer le chantier de la liste car il n'est plus "planifié"
|
||||
setChantiers(prev => prev.filter(c => c.id !== selectedChantier.id));
|
||||
setStartDialog(false);
|
||||
|
||||
toast.current?.show({
|
||||
severity: 'success',
|
||||
summary: 'Succès',
|
||||
detail: 'Chantier démarré avec succès',
|
||||
life: 3000
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Erreur lors du démarrage:', error);
|
||||
toast.current?.show({
|
||||
severity: 'error',
|
||||
summary: 'Erreur',
|
||||
detail: 'Impossible de démarrer le chantier',
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const exportCSV = () => {
|
||||
dt.current?.exportCSV();
|
||||
};
|
||||
|
||||
const bulkStart = async () => {
|
||||
if (selectedChantiers.length === 0) {
|
||||
toast.current?.show({
|
||||
severity: 'warn',
|
||||
summary: 'Attention',
|
||||
detail: 'Veuillez sélectionner au moins un chantier',
|
||||
life: 3000
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await Promise.all(
|
||||
selectedChantiers.map(chantier =>
|
||||
chantierService.update(chantier.id, {
|
||||
...chantier,
|
||||
statut: 'EN_COURS',
|
||||
dateDebut: new Date()
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
setChantiers(prev => prev.filter(c => !selectedChantiers.includes(c)));
|
||||
setSelectedChantiers([]);
|
||||
|
||||
toast.current?.show({
|
||||
severity: 'success',
|
||||
summary: 'Succès',
|
||||
detail: `${selectedChantiers.length} chantier(s) démarré(s)`,
|
||||
life: 3000
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Erreur lors du démarrage en lot:', error);
|
||||
toast.current?.show({
|
||||
severity: 'error',
|
||||
summary: 'Erreur',
|
||||
detail: 'Impossible de démarrer les chantiers sélectionnés',
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const leftToolbarTemplate = () => {
|
||||
return (
|
||||
<div className="my-2 flex gap-2">
|
||||
<h5 className="m-0 flex align-items-center">Chantiers planifiés ({chantiers.length})</h5>
|
||||
<Button
|
||||
label="Démarrer sélection"
|
||||
icon="pi pi-play"
|
||||
severity="success"
|
||||
size="small"
|
||||
onClick={bulkStart}
|
||||
disabled={selectedChantiers.length === 0}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const rightToolbarTemplate = () => {
|
||||
return (
|
||||
<Button
|
||||
label="Exporter"
|
||||
icon="pi pi-upload"
|
||||
severity="help"
|
||||
onClick={exportCSV}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
const actionBodyTemplate = (rowData: Chantier) => {
|
||||
return (
|
||||
<div className="flex gap-2">
|
||||
<Button
|
||||
icon="pi pi-play"
|
||||
rounded
|
||||
severity="success"
|
||||
size="small"
|
||||
tooltip="Démarrer le chantier"
|
||||
onClick={() => startChantier(rowData)}
|
||||
/>
|
||||
<Button
|
||||
icon="pi pi-eye"
|
||||
rounded
|
||||
severity="info"
|
||||
size="small"
|
||||
tooltip="Voir détails"
|
||||
onClick={() => {
|
||||
toast.current?.show({
|
||||
severity: 'info',
|
||||
summary: 'Info',
|
||||
detail: `Détails du chantier ${rowData.nom}`,
|
||||
life: 3000
|
||||
});
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const statusBodyTemplate = (rowData: Chantier) => {
|
||||
const overdue = isOverdue(rowData.dateDebut);
|
||||
const startingSoon = isStartingSoon(rowData.dateDebut);
|
||||
|
||||
return (
|
||||
<div className="flex align-items-center gap-2">
|
||||
<Tag value="Planifié" severity="info" />
|
||||
{overdue && <Tag value="En retard" severity="danger" />}
|
||||
{startingSoon && !overdue && <Tag value="Bientôt" severity="warning" />}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const dateDebutBodyTemplate = (rowData: Chantier) => {
|
||||
const overdue = isOverdue(rowData.dateDebut);
|
||||
const startingSoon = isStartingSoon(rowData.dateDebut);
|
||||
const days = getDaysUntilStart(rowData.dateDebut);
|
||||
|
||||
let className = '';
|
||||
let icon = '';
|
||||
let suffix = '';
|
||||
|
||||
if (overdue) {
|
||||
className = 'text-red-500 font-bold';
|
||||
icon = 'pi pi-exclamation-triangle';
|
||||
suffix = ` (${Math.abs(days)} jour${Math.abs(days) > 1 ? 's' : ''} de retard)`;
|
||||
} else if (startingSoon) {
|
||||
className = 'text-orange-500 font-bold';
|
||||
icon = 'pi pi-clock';
|
||||
suffix = ` (dans ${days} jour${days > 1 ? 's' : ''})`;
|
||||
} else if (days > 0) {
|
||||
suffix = ` (dans ${days} jour${days > 1 ? 's' : ''})`;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
{icon && <i className={`${icon} mr-1`}></i>}
|
||||
{formatDate(rowData.dateDebut)}
|
||||
<small className="block text-600">{suffix}</small>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const clientBodyTemplate = (rowData: Chantier) => {
|
||||
if (!rowData.client) return '';
|
||||
return `${rowData.client.prenom} ${rowData.client.nom}`;
|
||||
};
|
||||
|
||||
const durationBodyTemplate = (rowData: Chantier) => {
|
||||
if (!rowData.dateDebut || !rowData.dateFinPrevue) return '';
|
||||
|
||||
const start = new Date(rowData.dateDebut);
|
||||
const end = new Date(rowData.dateFinPrevue);
|
||||
const diffTime = end.getTime() - start.getTime();
|
||||
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
|
||||
|
||||
return `${diffDays} jour${diffDays > 1 ? 's' : ''}`;
|
||||
};
|
||||
|
||||
const header = (
|
||||
<div className="flex flex-column md:flex-row md:justify-content-between md:align-items-center">
|
||||
<h5 className="m-0">Chantiers en attente de démarrage</h5>
|
||||
<span className="block mt-2 md:mt-0 p-input-icon-left">
|
||||
<i className="pi pi-search" />
|
||||
<InputText
|
||||
type="search"
|
||||
placeholder="Rechercher..."
|
||||
onInput={(e) => setGlobalFilter(e.currentTarget.value)}
|
||||
/>
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
|
||||
const startDialogFooter = (
|
||||
<>
|
||||
<Button
|
||||
label="Annuler"
|
||||
icon="pi pi-times"
|
||||
text
|
||||
onClick={() => setStartDialog(false)}
|
||||
/>
|
||||
<Button
|
||||
label="Démarrer"
|
||||
icon="pi pi-play"
|
||||
text
|
||||
onClick={handleStartChantier}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="grid">
|
||||
<div className="col-12">
|
||||
<Card>
|
||||
<Toast ref={toast} />
|
||||
<Toolbar className="mb-4" left={leftToolbarTemplate} right={rightToolbarTemplate} />
|
||||
|
||||
<DataTable
|
||||
ref={dt}
|
||||
value={chantiers}
|
||||
selection={selectedChantiers}
|
||||
onSelectionChange={(e) => setSelectedChantiers(e.value)}
|
||||
dataKey="id"
|
||||
paginator
|
||||
rows={10}
|
||||
rowsPerPageOptions={[5, 10, 25]}
|
||||
className="datatable-responsive"
|
||||
paginatorTemplate="FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink CurrentPageReport RowsPerPageDropdown"
|
||||
currentPageReportTemplate="Affichage de {first} à {last} sur {totalRecords} chantiers"
|
||||
globalFilter={globalFilter}
|
||||
emptyMessage="Aucun chantier planifié trouvé."
|
||||
header={header}
|
||||
responsiveLayout="scroll"
|
||||
loading={loading}
|
||||
sortField="dateDebut"
|
||||
sortOrder={1}
|
||||
>
|
||||
<Column selectionMode="multiple" headerStyle={{ width: '4rem' }} />
|
||||
<Column field="nom" header="Nom" sortable headerStyle={{ minWidth: '12rem' }} />
|
||||
<Column field="client" header="Client" body={clientBodyTemplate} sortable headerStyle={{ minWidth: '12rem' }} />
|
||||
<Column field="adresse" header="Adresse" sortable headerStyle={{ minWidth: '12rem' }} />
|
||||
<Column field="dateDebut" header="Date de début prévue" body={dateDebutBodyTemplate} sortable headerStyle={{ minWidth: '14rem' }} />
|
||||
<Column field="dateFinPrevue" header="Date de fin prévue" body={(rowData) => formatDate(rowData.dateFinPrevue)} sortable headerStyle={{ minWidth: '10rem' }} />
|
||||
<Column field="duration" header="Durée" body={durationBodyTemplate} headerStyle={{ minWidth: '8rem' }} />
|
||||
<Column field="statut" header="Statut" body={statusBodyTemplate} headerStyle={{ minWidth: '12rem' }} />
|
||||
<Column field="montantPrevu" header="Budget prévu" body={(rowData) => formatCurrency(rowData.montantPrevu)} sortable headerStyle={{ minWidth: '10rem' }} />
|
||||
<Column body={actionBodyTemplate} headerStyle={{ minWidth: '8rem' }} />
|
||||
</DataTable>
|
||||
|
||||
<Dialog
|
||||
visible={startDialog}
|
||||
style={{ width: '450px' }}
|
||||
header="Démarrer le chantier"
|
||||
modal
|
||||
className="p-fluid"
|
||||
footer={startDialogFooter}
|
||||
onHide={() => setStartDialog(false)}
|
||||
>
|
||||
<div className="formgrid grid">
|
||||
<div className="field col-12">
|
||||
<p>
|
||||
Confirmer le démarrage du chantier <strong>{selectedChantier?.nom}</strong> ?
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="field col-12">
|
||||
<label htmlFor="startDate">Date de démarrage effectif</label>
|
||||
<Calendar
|
||||
id="startDate"
|
||||
value={startDate}
|
||||
onChange={(e) => setStartDate(e.value || new Date())}
|
||||
dateFormat="dd/mm/yy"
|
||||
showIcon
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ChantiersPlanifiesPage;
|
||||
474
app/(main)/chantiers/retard/page.tsx
Normal file
474
app/(main)/chantiers/retard/page.tsx
Normal file
@@ -0,0 +1,474 @@
|
||||
'use client';
|
||||
|
||||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import { DataTable } from 'primereact/datatable';
|
||||
import { Column } from 'primereact/column';
|
||||
import { Button } from 'primereact/button';
|
||||
import { InputText } from 'primereact/inputtext';
|
||||
import { Card } from 'primereact/card';
|
||||
import { Toast } from 'primereact/toast';
|
||||
import { Toolbar } from 'primereact/toolbar';
|
||||
import { Tag } from 'primereact/tag';
|
||||
import { Dialog } from 'primereact/dialog';
|
||||
import { Calendar } from 'primereact/calendar';
|
||||
import { InputTextarea } from 'primereact/inputtextarea';
|
||||
import { ProgressBar } from 'primereact/progressbar';
|
||||
import { Chip } from 'primereact/chip';
|
||||
import { chantierService } from '../../../../services/api';
|
||||
import { formatDate, formatCurrency } from '../../../../utils/formatters';
|
||||
import type { Chantier } from '../../../../types/btp';
|
||||
import {
|
||||
ActionButtonGroup,
|
||||
ViewButton,
|
||||
ActionButton
|
||||
} from '../../../../components/ui/ActionButton';
|
||||
|
||||
const ChantiersRetardPage = () => {
|
||||
const [chantiers, setChantiers] = useState<Chantier[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [globalFilter, setGlobalFilter] = useState('');
|
||||
const [selectedChantiers, setSelectedChantiers] = useState<Chantier[]>([]);
|
||||
const [actionDialog, setActionDialog] = useState(false);
|
||||
const [selectedChantier, setSelectedChantier] = useState<Chantier | null>(null);
|
||||
const [actionType, setActionType] = useState<'extend' | 'status'>('extend');
|
||||
const [newEndDate, setNewEndDate] = useState<Date | null>(null);
|
||||
const [actionNotes, setActionNotes] = useState('');
|
||||
const toast = useRef<Toast>(null);
|
||||
const dt = useRef<DataTable<Chantier[]>>(null);
|
||||
|
||||
useEffect(() => {
|
||||
loadChantiers();
|
||||
}, []);
|
||||
|
||||
const loadChantiers = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const data = await chantierService.getAll();
|
||||
// Filtrer les chantiers en retard (planifiés avec date dépassée OU en cours avec date fin prévue dépassée)
|
||||
const chantiersEnRetard = data.filter(chantier => {
|
||||
const today = new Date();
|
||||
|
||||
// Chantiers planifiés dont la date de début est dépassée
|
||||
if (chantier.statut === 'PLANIFIE') {
|
||||
const startDate = new Date(chantier.dateDebut);
|
||||
return startDate < today;
|
||||
}
|
||||
|
||||
// Chantiers en cours dont la date de fin prévue est dépassée
|
||||
if (chantier.statut === 'EN_COURS') {
|
||||
const endDate = new Date(chantier.dateFinPrevue);
|
||||
return endDate < today;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
setChantiers(chantiersEnRetard);
|
||||
} catch (error) {
|
||||
console.error('Erreur lors du chargement des chantiers:', error);
|
||||
toast.current?.show({
|
||||
severity: 'error',
|
||||
summary: 'Erreur',
|
||||
detail: 'Impossible de charger les chantiers en retard',
|
||||
life: 3000
|
||||
});
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const getDelayDays = (chantier: Chantier) => {
|
||||
const today = new Date();
|
||||
let referenceDate: Date;
|
||||
|
||||
if (chantier.statut === 'PLANIFIE') {
|
||||
referenceDate = new Date(chantier.dateDebut);
|
||||
} else {
|
||||
referenceDate = new Date(chantier.dateFinPrevue);
|
||||
}
|
||||
|
||||
const diffTime = today.getTime() - referenceDate.getTime();
|
||||
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
|
||||
return diffDays;
|
||||
};
|
||||
|
||||
const getDelaySeverity = (days: number) => {
|
||||
if (days <= 7) return 'warning';
|
||||
if (days <= 30) return 'danger';
|
||||
return 'danger';
|
||||
};
|
||||
|
||||
const getPriorityLevel = (days: number) => {
|
||||
if (days <= 3) return { level: 'FAIBLE', color: 'orange' };
|
||||
if (days <= 15) return { level: 'MOYEN', color: 'red' };
|
||||
return { level: 'URGENT', color: 'red' };
|
||||
};
|
||||
|
||||
const calculateProgress = (chantier: Chantier) => {
|
||||
if (chantier.statut !== 'EN_COURS' || !chantier.dateDebut || !chantier.dateFinPrevue) return 0;
|
||||
|
||||
const now = new Date();
|
||||
const start = new Date(chantier.dateDebut);
|
||||
const end = new Date(chantier.dateFinPrevue);
|
||||
const totalDays = (end.getTime() - start.getTime()) / (1000 * 60 * 60 * 24);
|
||||
const elapsedDays = (now.getTime() - start.getTime()) / (1000 * 60 * 60 * 24);
|
||||
|
||||
return Math.min(Math.max((elapsedDays / totalDays) * 100, 0), 120); // Peut dépasser 100% si en retard
|
||||
};
|
||||
|
||||
const extendDeadline = (chantier: Chantier) => {
|
||||
setSelectedChantier(chantier);
|
||||
setActionType('extend');
|
||||
setNewEndDate(new Date(chantier.dateFinPrevue));
|
||||
setActionNotes('');
|
||||
setActionDialog(true);
|
||||
};
|
||||
|
||||
const changeStatus = (chantier: Chantier) => {
|
||||
setSelectedChantier(chantier);
|
||||
setActionType('status');
|
||||
setActionNotes('');
|
||||
setActionDialog(true);
|
||||
};
|
||||
|
||||
const handleAction = async () => {
|
||||
if (!selectedChantier) return;
|
||||
|
||||
try {
|
||||
let updatedChantier = { ...selectedChantier };
|
||||
|
||||
if (actionType === 'extend' && newEndDate) {
|
||||
updatedChantier.dateFinPrevue = newEndDate;
|
||||
} else if (actionType === 'status') {
|
||||
updatedChantier.statut = 'SUSPENDU';
|
||||
}
|
||||
|
||||
await chantierService.update(selectedChantier.id, updatedChantier);
|
||||
|
||||
// Recharger la liste si le statut a changé
|
||||
if (actionType === 'status') {
|
||||
setChantiers(prev => prev.filter(c => c.id !== selectedChantier.id));
|
||||
} else {
|
||||
// Mettre à jour le chantier dans la liste
|
||||
setChantiers(prev => prev.map(c =>
|
||||
c.id === selectedChantier.id ? updatedChantier : c
|
||||
));
|
||||
}
|
||||
|
||||
setActionDialog(false);
|
||||
|
||||
toast.current?.show({
|
||||
severity: 'success',
|
||||
summary: 'Succès',
|
||||
detail: actionType === 'extend' ? 'Échéance reportée' : 'Chantier suspendu',
|
||||
life: 3000
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Erreur lors de l\'action:', error);
|
||||
toast.current?.show({
|
||||
severity: 'error',
|
||||
summary: 'Erreur',
|
||||
detail: 'Impossible d\'effectuer l\'action',
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const exportCSV = () => {
|
||||
dt.current?.exportCSV();
|
||||
};
|
||||
|
||||
const generateAlertReport = () => {
|
||||
const urgentChantiers = chantiers.filter(c => getPriorityLevel(getDelayDays(c)).level === 'URGENT');
|
||||
const report = `
|
||||
=== ALERTE CHANTIERS EN RETARD ===
|
||||
Date du rapport: ${new Date().toLocaleDateString('fr-FR')}
|
||||
|
||||
CHANTIERS URGENTS (${urgentChantiers.length}):
|
||||
${urgentChantiers.map(c => `
|
||||
- ${c.nom}
|
||||
Client: ${c.client ? `${c.client.prenom} ${c.client.nom}` : 'N/A'}
|
||||
Retard: ${getDelayDays(c)} jours
|
||||
Statut: ${c.statut}
|
||||
Budget: ${formatCurrency(c.montantPrevu || 0)}
|
||||
`).join('')}
|
||||
|
||||
STATISTIQUES:
|
||||
- Total chantiers en retard: ${chantiers.length}
|
||||
- Retard moyen: ${Math.round(chantiers.reduce((sum, c) => sum + getDelayDays(c), 0) / chantiers.length)} jours
|
||||
- Impact budgétaire: ${formatCurrency(chantiers.reduce((sum, c) => sum + (c.montantPrevu || 0), 0))}
|
||||
`;
|
||||
|
||||
const blob = new Blob([report], { type: 'text/plain;charset=utf-8;' });
|
||||
const link = document.createElement('a');
|
||||
link.href = URL.createObjectURL(blob);
|
||||
link.download = `alerte_retards_${new Date().toISOString().split('T')[0]}.txt`;
|
||||
link.click();
|
||||
|
||||
toast.current?.show({
|
||||
severity: 'success',
|
||||
summary: 'Rapport généré',
|
||||
detail: 'Le rapport d\'alerte a été téléchargé',
|
||||
life: 3000
|
||||
});
|
||||
};
|
||||
|
||||
const leftToolbarTemplate = () => {
|
||||
return (
|
||||
<div className="my-2 flex gap-2">
|
||||
<h5 className="m-0 flex align-items-center text-red-500">
|
||||
<i className="pi pi-exclamation-triangle mr-2"></i>
|
||||
Chantiers en retard ({chantiers.length})
|
||||
</h5>
|
||||
<Button
|
||||
label="Rapport d'alerte"
|
||||
icon="pi pi-file-export"
|
||||
severity="danger"
|
||||
size="small"
|
||||
onClick={generateAlertReport}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const rightToolbarTemplate = () => {
|
||||
return (
|
||||
<Button
|
||||
label="Exporter"
|
||||
icon="pi pi-upload"
|
||||
severity="help"
|
||||
onClick={exportCSV}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
const actionBodyTemplate = (rowData: Chantier) => {
|
||||
return (
|
||||
<ActionButtonGroup>
|
||||
<ActionButton
|
||||
icon="pi pi-calendar-plus"
|
||||
tooltip="Reporter l'échéance"
|
||||
onClick={() => extendDeadline(rowData)}
|
||||
color="orange"
|
||||
/>
|
||||
<ActionButton
|
||||
icon="pi pi-pause"
|
||||
tooltip="Suspendre le chantier"
|
||||
onClick={() => changeStatus(rowData)}
|
||||
color="red"
|
||||
/>
|
||||
<ViewButton
|
||||
tooltip="Voir détails"
|
||||
onClick={() => {
|
||||
toast.current?.show({
|
||||
severity: 'info',
|
||||
summary: 'Info',
|
||||
detail: `Détails du chantier ${rowData.nom}`,
|
||||
life: 3000
|
||||
});
|
||||
}}
|
||||
/>
|
||||
</ActionButtonGroup>
|
||||
);
|
||||
};
|
||||
|
||||
const statusBodyTemplate = (rowData: Chantier) => {
|
||||
const delayDays = getDelayDays(rowData);
|
||||
const priority = getPriorityLevel(delayDays);
|
||||
|
||||
return (
|
||||
<div className="flex align-items-center gap-2">
|
||||
<Tag
|
||||
value={rowData.statut === 'PLANIFIE' ? 'Non démarré' : 'En cours'}
|
||||
severity={rowData.statut === 'PLANIFIE' ? 'info' : 'success'}
|
||||
/>
|
||||
<Chip
|
||||
label={priority.level}
|
||||
style={{ backgroundColor: priority.color, color: 'white' }}
|
||||
className="text-xs"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const delayBodyTemplate = (rowData: Chantier) => {
|
||||
const delayDays = getDelayDays(rowData);
|
||||
const severity = getDelaySeverity(delayDays);
|
||||
|
||||
return (
|
||||
<div className="flex align-items-center gap-2">
|
||||
<Tag
|
||||
value={`${delayDays} jour${delayDays > 1 ? 's' : ''}`}
|
||||
severity={severity}
|
||||
icon="pi pi-clock"
|
||||
/>
|
||||
{rowData.statut === 'PLANIFIE' && (
|
||||
<small className="text-600">de retard au démarrage</small>
|
||||
)}
|
||||
{rowData.statut === 'EN_COURS' && (
|
||||
<small className="text-600">après l'échéance</small>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const progressBodyTemplate = (rowData: Chantier) => {
|
||||
if (rowData.statut === 'PLANIFIE') {
|
||||
return <span className="text-600">Non démarré</span>;
|
||||
}
|
||||
|
||||
const progress = calculateProgress(rowData);
|
||||
return (
|
||||
<div className="flex align-items-center gap-2">
|
||||
<ProgressBar
|
||||
value={Math.min(progress, 100)}
|
||||
style={{ height: '6px', width: '100px' }}
|
||||
color={progress > 100 ? '#ef4444' : undefined}
|
||||
/>
|
||||
<span className={`text-sm ${progress > 100 ? 'text-red-500 font-bold' : ''}`}>
|
||||
{Math.round(progress)}%
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const clientBodyTemplate = (rowData: Chantier) => {
|
||||
if (!rowData.client) return '';
|
||||
return `${rowData.client.prenom} ${rowData.client.nom}`;
|
||||
};
|
||||
|
||||
const referenceeDateBodyTemplate = (rowData: Chantier) => {
|
||||
const date = rowData.statut === 'PLANIFIE' ? rowData.dateDebut : rowData.dateFinPrevue;
|
||||
const label = rowData.statut === 'PLANIFIE' ? 'Début prévu' : 'Fin prévue';
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="font-bold text-red-500">{formatDate(date)}</div>
|
||||
<small className="text-600">{label}</small>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const header = (
|
||||
<div className="flex flex-column md:flex-row md:justify-content-between md:align-items-center">
|
||||
<h5 className="m-0">Chantiers nécessitant une attention immédiate</h5>
|
||||
<span className="block mt-2 md:mt-0 p-input-icon-left">
|
||||
<i className="pi pi-search" />
|
||||
<InputText
|
||||
type="search"
|
||||
placeholder="Rechercher..."
|
||||
onInput={(e) => setGlobalFilter(e.currentTarget.value)}
|
||||
/>
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
|
||||
const actionDialogFooter = (
|
||||
<>
|
||||
<Button
|
||||
label="Annuler"
|
||||
icon="pi pi-times"
|
||||
text
|
||||
onClick={() => setActionDialog(false)}
|
||||
/>
|
||||
<Button
|
||||
label={actionType === 'extend' ? 'Reporter' : 'Suspendre'}
|
||||
icon={actionType === 'extend' ? 'pi pi-calendar-plus' : 'pi pi-pause'}
|
||||
text
|
||||
onClick={handleAction}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="grid">
|
||||
<div className="col-12">
|
||||
<Card>
|
||||
<Toast ref={toast} />
|
||||
<Toolbar className="mb-4" left={leftToolbarTemplate} right={rightToolbarTemplate} />
|
||||
|
||||
<DataTable
|
||||
ref={dt}
|
||||
value={chantiers}
|
||||
selection={selectedChantiers}
|
||||
onSelectionChange={(e) => setSelectedChantiers(e.value)}
|
||||
dataKey="id"
|
||||
paginator
|
||||
rows={10}
|
||||
rowsPerPageOptions={[5, 10, 25]}
|
||||
className="datatable-responsive"
|
||||
paginatorTemplate="FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink CurrentPageReport RowsPerPageDropdown"
|
||||
currentPageReportTemplate="Affichage de {first} à {last} sur {totalRecords} chantiers"
|
||||
globalFilter={globalFilter}
|
||||
emptyMessage="Aucun chantier en retard trouvé."
|
||||
header={header}
|
||||
responsiveLayout="scroll"
|
||||
loading={loading}
|
||||
sortField="dateDebut"
|
||||
sortOrder={1}
|
||||
>
|
||||
<Column selectionMode="multiple" headerStyle={{ width: '4rem' }} />
|
||||
<Column field="nom" header="Nom" sortable headerStyle={{ minWidth: '12rem' }} />
|
||||
<Column field="client" header="Client" body={clientBodyTemplate} sortable headerStyle={{ minWidth: '12rem' }} />
|
||||
<Column field="referenceDate" header="Date de référence" body={referenceeDateBodyTemplate} sortable headerStyle={{ minWidth: '12rem' }} />
|
||||
<Column field="delay" header="Retard" body={delayBodyTemplate} headerStyle={{ minWidth: '12rem' }} />
|
||||
<Column field="statut" header="Statut/Priorité" body={statusBodyTemplate} headerStyle={{ minWidth: '12rem' }} />
|
||||
<Column field="progress" header="Progression" body={progressBodyTemplate} headerStyle={{ minWidth: '12rem' }} />
|
||||
<Column field="montantPrevu" header="Budget" body={(rowData) => formatCurrency(rowData.montantPrevu)} sortable headerStyle={{ minWidth: '10rem' }} />
|
||||
<Column body={actionBodyTemplate} headerStyle={{ minWidth: '12rem' }} />
|
||||
</DataTable>
|
||||
|
||||
<Dialog
|
||||
visible={actionDialog}
|
||||
style={{ width: '500px' }}
|
||||
header={actionType === 'extend' ? 'Reporter l\'échéance' : 'Suspendre le chantier'}
|
||||
modal
|
||||
className="p-fluid"
|
||||
footer={actionDialogFooter}
|
||||
onHide={() => setActionDialog(false)}
|
||||
>
|
||||
<div className="formgrid grid">
|
||||
<div className="field col-12">
|
||||
<p>
|
||||
Chantier: <strong>{selectedChantier?.nom}</strong>
|
||||
</p>
|
||||
<p>
|
||||
Retard actuel: <strong>{selectedChantier ? getDelayDays(selectedChantier) : 0} jour(s)</strong>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{actionType === 'extend' && (
|
||||
<div className="field col-12">
|
||||
<label htmlFor="newEndDate">Nouvelle date de fin prévue</label>
|
||||
<Calendar
|
||||
id="newEndDate"
|
||||
value={newEndDate}
|
||||
onChange={(e) => setNewEndDate(e.value)}
|
||||
dateFormat="dd/mm/yy"
|
||||
showIcon
|
||||
minDate={new Date()}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="field col-12">
|
||||
<label htmlFor="actionNotes">
|
||||
{actionType === 'extend' ? 'Raison du report' : 'Raison de la suspension'}
|
||||
</label>
|
||||
<InputTextarea
|
||||
id="actionNotes"
|
||||
value={actionNotes}
|
||||
onChange={(e) => setActionNotes(e.target.value)}
|
||||
rows={3}
|
||||
placeholder="Expliquez la raison de cette action..."
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ChantiersRetardPage;
|
||||
404
app/(main)/chantiers/termines/page.tsx
Normal file
404
app/(main)/chantiers/termines/page.tsx
Normal file
@@ -0,0 +1,404 @@
|
||||
'use client';
|
||||
|
||||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import { DataTable } from 'primereact/datatable';
|
||||
import { Column } from 'primereact/column';
|
||||
import { Button } from 'primereact/button';
|
||||
import { InputText } from 'primereact/inputtext';
|
||||
import { Card } from 'primereact/card';
|
||||
import { Toast } from 'primereact/toast';
|
||||
import { Toolbar } from 'primereact/toolbar';
|
||||
import { Tag } from 'primereact/tag';
|
||||
import { Dialog } from 'primereact/dialog';
|
||||
import { Rating } from 'primereact/rating';
|
||||
import { InputTextarea } from 'primereact/inputtextarea';
|
||||
import { chantierService } from '../../../../services/api';
|
||||
import { formatDate, formatCurrency } from '../../../../utils/formatters';
|
||||
import type { Chantier } from '../../../../types/btp';
|
||||
|
||||
const ChantiersTerminesPage = () => {
|
||||
const [chantiers, setChantiers] = useState<Chantier[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [globalFilter, setGlobalFilter] = useState('');
|
||||
const [selectedChantiers, setSelectedChantiers] = useState<Chantier[]>([]);
|
||||
const [detailDialog, setDetailDialog] = useState(false);
|
||||
const [selectedChantier, setSelectedChantier] = useState<Chantier | null>(null);
|
||||
const [satisfaction, setSatisfaction] = useState(5);
|
||||
const [notes, setNotes] = useState('');
|
||||
const toast = useRef<Toast>(null);
|
||||
const dt = useRef<DataTable<Chantier[]>>(null);
|
||||
|
||||
useEffect(() => {
|
||||
loadChantiers();
|
||||
}, []);
|
||||
|
||||
const loadChantiers = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const data = await chantierService.getAll();
|
||||
// Filtrer seulement les chantiers terminés
|
||||
const chantiersTermines = data.filter(chantier => chantier.statut === 'TERMINE');
|
||||
setChantiers(chantiersTermines);
|
||||
} catch (error) {
|
||||
console.error('Erreur lors du chargement des chantiers:', error);
|
||||
toast.current?.show({
|
||||
severity: 'error',
|
||||
summary: 'Erreur',
|
||||
detail: 'Impossible de charger les chantiers terminés',
|
||||
life: 3000
|
||||
});
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const calculateDuration = (dateDebut: string | Date, dateFinReelle: string | Date) => {
|
||||
const start = new Date(dateDebut);
|
||||
const end = new Date(dateFinReelle);
|
||||
const diffTime = end.getTime() - start.getTime();
|
||||
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
|
||||
return diffDays;
|
||||
};
|
||||
|
||||
const calculateDelay = (dateFinPrevue: string | Date, dateFinReelle: string | Date) => {
|
||||
const planned = new Date(dateFinPrevue);
|
||||
const actual = new Date(dateFinReelle);
|
||||
const diffTime = actual.getTime() - planned.getTime();
|
||||
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
|
||||
return diffDays;
|
||||
};
|
||||
|
||||
const isOnTime = (dateFinPrevue: string | Date, dateFinReelle: string | Date) => {
|
||||
const delay = calculateDelay(dateFinPrevue, dateFinReelle);
|
||||
return delay <= 0;
|
||||
};
|
||||
|
||||
const isOnBudget = (montantPrevu: number, montantReel: number) => {
|
||||
return montantReel <= montantPrevu;
|
||||
};
|
||||
|
||||
const getBudgetVariance = (montantPrevu: number, montantReel: number) => {
|
||||
return ((montantReel - montantPrevu) / montantPrevu) * 100;
|
||||
};
|
||||
|
||||
const viewDetails = (chantier: Chantier) => {
|
||||
setSelectedChantier(chantier);
|
||||
setSatisfaction(5);
|
||||
setNotes('');
|
||||
setDetailDialog(true);
|
||||
};
|
||||
|
||||
const exportCSV = () => {
|
||||
dt.current?.exportCSV();
|
||||
};
|
||||
|
||||
const generateReport = () => {
|
||||
const totalProjects = chantiers.length;
|
||||
const onTimeProjects = chantiers.filter(c =>
|
||||
c.dateFinReelle && isOnTime(c.dateFinPrevue, c.dateFinReelle)
|
||||
).length;
|
||||
const onBudgetProjects = chantiers.filter(c =>
|
||||
isOnBudget(c.montantPrevu || 0, c.montantReel || 0)
|
||||
).length;
|
||||
|
||||
const totalBudget = chantiers.reduce((sum, c) => sum + (c.montantPrevu || 0), 0);
|
||||
const totalCost = chantiers.reduce((sum, c) => sum + (c.montantReel || 0), 0);
|
||||
|
||||
const report = `
|
||||
=== RAPPORT CHANTIERS TERMINÉS ===
|
||||
Nombre total de chantiers: ${totalProjects}
|
||||
Chantiers dans les délais: ${onTimeProjects} (${Math.round(onTimeProjects/totalProjects*100)}%)
|
||||
Chantiers dans le budget: ${onBudgetProjects} (${Math.round(onBudgetProjects/totalProjects*100)}%)
|
||||
Budget total prévu: ${formatCurrency(totalBudget)}
|
||||
Coût total réel: ${formatCurrency(totalCost)}
|
||||
Variance budgétaire: ${formatCurrency(totalCost - totalBudget)} (${Math.round(((totalCost - totalBudget)/totalBudget)*100)}%)
|
||||
`;
|
||||
|
||||
const blob = new Blob([report], { type: 'text/plain;charset=utf-8;' });
|
||||
const link = document.createElement('a');
|
||||
link.href = URL.createObjectURL(blob);
|
||||
link.download = `rapport_chantiers_termines_${new Date().toISOString().split('T')[0]}.txt`;
|
||||
link.click();
|
||||
|
||||
toast.current?.show({
|
||||
severity: 'success',
|
||||
summary: 'Rapport généré',
|
||||
detail: 'Le rapport a été téléchargé',
|
||||
life: 3000
|
||||
});
|
||||
};
|
||||
|
||||
const leftToolbarTemplate = () => {
|
||||
return (
|
||||
<div className="my-2 flex gap-2">
|
||||
<h5 className="m-0 flex align-items-center">Chantiers terminés ({chantiers.length})</h5>
|
||||
<Button
|
||||
label="Générer rapport"
|
||||
icon="pi pi-file-excel"
|
||||
severity="help"
|
||||
size="small"
|
||||
onClick={generateReport}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const rightToolbarTemplate = () => {
|
||||
return (
|
||||
<Button
|
||||
label="Exporter"
|
||||
icon="pi pi-upload"
|
||||
severity="help"
|
||||
onClick={exportCSV}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
const actionBodyTemplate = (rowData: Chantier) => {
|
||||
return (
|
||||
<div className="flex gap-2">
|
||||
<Button
|
||||
icon="pi pi-eye"
|
||||
rounded
|
||||
severity="info"
|
||||
size="small"
|
||||
tooltip="Voir détails"
|
||||
onClick={() => viewDetails(rowData)}
|
||||
/>
|
||||
<Button
|
||||
icon="pi pi-file-pdf"
|
||||
rounded
|
||||
severity="help"
|
||||
size="small"
|
||||
tooltip="Générer facture"
|
||||
onClick={() => {
|
||||
toast.current?.show({
|
||||
severity: 'info',
|
||||
summary: 'Info',
|
||||
detail: `Génération de facture pour ${rowData.nom}`,
|
||||
life: 3000
|
||||
});
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const statusBodyTemplate = (rowData: Chantier) => {
|
||||
const onTime = rowData.dateFinReelle && isOnTime(rowData.dateFinPrevue, rowData.dateFinReelle);
|
||||
const onBudget = isOnBudget(rowData.montantPrevu || 0, rowData.montantReel || 0);
|
||||
|
||||
return (
|
||||
<div className="flex align-items-center gap-2">
|
||||
<Tag value="Terminé" severity="secondary" />
|
||||
{onTime && <Tag value="Dans les délais" severity="success" />}
|
||||
{!onTime && <Tag value="En retard" severity="warning" />}
|
||||
{onBudget && <Tag value="Budget respecté" severity="success" />}
|
||||
{!onBudget && <Tag value="Dépassement" severity="danger" />}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const clientBodyTemplate = (rowData: Chantier) => {
|
||||
if (!rowData.client) return '';
|
||||
return `${rowData.client.prenom} ${rowData.client.nom}`;
|
||||
};
|
||||
|
||||
const durationBodyTemplate = (rowData: Chantier) => {
|
||||
if (!rowData.dateDebut || !rowData.dateFinReelle) return '';
|
||||
|
||||
const duration = calculateDuration(rowData.dateDebut, rowData.dateFinReelle);
|
||||
const delay = calculateDelay(rowData.dateFinPrevue, rowData.dateFinReelle);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div>{duration} jour{duration > 1 ? 's' : ''}</div>
|
||||
{delay > 0 && (
|
||||
<small className="text-orange-500">
|
||||
+{delay} jour{delay > 1 ? 's' : ''} de retard
|
||||
</small>
|
||||
)}
|
||||
{delay < 0 && (
|
||||
<small className="text-green-500">
|
||||
{Math.abs(delay)} jour{Math.abs(delay) > 1 ? 's' : ''} d'avance
|
||||
</small>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const budgetBodyTemplate = (rowData: Chantier) => {
|
||||
const prevu = rowData.montantPrevu || 0;
|
||||
const reel = rowData.montantReel || 0;
|
||||
const variance = getBudgetVariance(prevu, reel);
|
||||
const onBudget = isOnBudget(prevu, reel);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div>Prévu: {formatCurrency(prevu)}</div>
|
||||
<div>Réel: {formatCurrency(reel)}</div>
|
||||
<small className={onBudget ? 'text-green-500' : 'text-red-500'}>
|
||||
{variance > 0 ? '+' : ''}{variance.toFixed(1)}%
|
||||
</small>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const header = (
|
||||
<div className="flex flex-column md:flex-row md:justify-content-between md:align-items-center">
|
||||
<h5 className="m-0">Chantiers terminés - Historique</h5>
|
||||
<span className="block mt-2 md:mt-0 p-input-icon-left">
|
||||
<i className="pi pi-search" />
|
||||
<InputText
|
||||
type="search"
|
||||
placeholder="Rechercher..."
|
||||
onInput={(e) => setGlobalFilter(e.currentTarget.value)}
|
||||
/>
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
|
||||
const detailDialogFooter = (
|
||||
<>
|
||||
<Button
|
||||
label="Fermer"
|
||||
icon="pi pi-times"
|
||||
text
|
||||
onClick={() => setDetailDialog(false)}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="grid">
|
||||
<div className="col-12">
|
||||
<Card>
|
||||
<Toast ref={toast} />
|
||||
<Toolbar className="mb-4" left={leftToolbarTemplate} right={rightToolbarTemplate} />
|
||||
|
||||
<DataTable
|
||||
ref={dt}
|
||||
value={chantiers}
|
||||
selection={selectedChantiers}
|
||||
onSelectionChange={(e) => setSelectedChantiers(e.value)}
|
||||
dataKey="id"
|
||||
paginator
|
||||
rows={10}
|
||||
rowsPerPageOptions={[5, 10, 25]}
|
||||
className="datatable-responsive"
|
||||
paginatorTemplate="FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink CurrentPageReport RowsPerPageDropdown"
|
||||
currentPageReportTemplate="Affichage de {first} à {last} sur {totalRecords} chantiers"
|
||||
globalFilter={globalFilter}
|
||||
emptyMessage="Aucun chantier terminé trouvé."
|
||||
header={header}
|
||||
responsiveLayout="scroll"
|
||||
loading={loading}
|
||||
sortField="dateFinReelle"
|
||||
sortOrder={-1}
|
||||
>
|
||||
<Column selectionMode="multiple" headerStyle={{ width: '4rem' }} />
|
||||
<Column field="nom" header="Nom" sortable headerStyle={{ minWidth: '12rem' }} />
|
||||
<Column field="client" header="Client" body={clientBodyTemplate} sortable headerStyle={{ minWidth: '12rem' }} />
|
||||
<Column field="dateFinReelle" header="Date de fin" body={(rowData) => formatDate(rowData.dateFinReelle)} sortable headerStyle={{ minWidth: '10rem' }} />
|
||||
<Column field="duration" header="Durée réelle" body={durationBodyTemplate} headerStyle={{ minWidth: '10rem' }} />
|
||||
<Column field="statut" header="Statut" body={statusBodyTemplate} headerStyle={{ minWidth: '15rem' }} />
|
||||
<Column field="budget" header="Budget" body={budgetBodyTemplate} headerStyle={{ minWidth: '12rem' }} />
|
||||
<Column body={actionBodyTemplate} headerStyle={{ minWidth: '8rem' }} />
|
||||
</DataTable>
|
||||
|
||||
<Dialog
|
||||
visible={detailDialog}
|
||||
style={{ width: '600px' }}
|
||||
header={`Détails - ${selectedChantier?.nom}`}
|
||||
modal
|
||||
className="p-fluid"
|
||||
footer={detailDialogFooter}
|
||||
onHide={() => setDetailDialog(false)}
|
||||
>
|
||||
{selectedChantier && (
|
||||
<div className="formgrid grid">
|
||||
<div className="field col-12">
|
||||
<h3 className="text-primary">Informations générales</h3>
|
||||
</div>
|
||||
|
||||
<div className="field col-12 md:col-6">
|
||||
<label className="font-bold">Client:</label>
|
||||
<p>{selectedChantier.client ? `${selectedChantier.client.prenom} ${selectedChantier.client.nom}` : ''}</p>
|
||||
</div>
|
||||
|
||||
<div className="field col-12 md:col-6">
|
||||
<label className="font-bold">Adresse:</label>
|
||||
<p>{selectedChantier.adresse}</p>
|
||||
</div>
|
||||
|
||||
<div className="field col-12">
|
||||
<label className="font-bold">Description:</label>
|
||||
<p>{selectedChantier.description || 'Aucune description'}</p>
|
||||
</div>
|
||||
|
||||
<div className="field col-12">
|
||||
<h3 className="text-primary">Planning</h3>
|
||||
</div>
|
||||
|
||||
<div className="field col-12 md:col-4">
|
||||
<label className="font-bold">Date début:</label>
|
||||
<p>{formatDate(selectedChantier.dateDebut)}</p>
|
||||
</div>
|
||||
|
||||
<div className="field col-12 md:col-4">
|
||||
<label className="font-bold">Date fin prévue:</label>
|
||||
<p>{formatDate(selectedChantier.dateFinPrevue)}</p>
|
||||
</div>
|
||||
|
||||
<div className="field col-12 md:col-4">
|
||||
<label className="font-bold">Date fin réelle:</label>
|
||||
<p>{selectedChantier.dateFinReelle ? formatDate(selectedChantier.dateFinReelle) : 'Non définie'}</p>
|
||||
</div>
|
||||
|
||||
<div className="field col-12">
|
||||
<h3 className="text-primary">Budget</h3>
|
||||
</div>
|
||||
|
||||
<div className="field col-12 md:col-6">
|
||||
<label className="font-bold">Budget prévu:</label>
|
||||
<p>{formatCurrency(selectedChantier.montantPrevu || 0)}</p>
|
||||
</div>
|
||||
|
||||
<div className="field col-12 md:col-6">
|
||||
<label className="font-bold">Coût réel:</label>
|
||||
<p>{formatCurrency(selectedChantier.montantReel || 0)}</p>
|
||||
</div>
|
||||
|
||||
<div className="field col-12">
|
||||
<h3 className="text-primary">Évaluation</h3>
|
||||
</div>
|
||||
|
||||
<div className="field col-12">
|
||||
<label className="font-bold">Satisfaction client:</label>
|
||||
<Rating
|
||||
value={satisfaction}
|
||||
onChange={(e) => setSatisfaction(e.value || 0)}
|
||||
stars={5}
|
||||
className="mt-2"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="field col-12">
|
||||
<label className="font-bold">Notes:</label>
|
||||
<InputTextarea
|
||||
value={notes}
|
||||
onChange={(e) => setNotes(e.target.value)}
|
||||
rows={3}
|
||||
placeholder="Notes sur le chantier..."
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</Dialog>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ChantiersTerminesPage;
|
||||
583
app/(main)/chantiers/workflow/page.tsx
Normal file
583
app/(main)/chantiers/workflow/page.tsx
Normal file
@@ -0,0 +1,583 @@
|
||||
'use client';
|
||||
|
||||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import { Card } from 'primereact/card';
|
||||
import { DataTable } from 'primereact/datatable';
|
||||
import { Column } from 'primereact/column';
|
||||
import { Button } from 'primereact/button';
|
||||
import { Tag } from 'primereact/tag';
|
||||
import { ProgressBar } from 'primereact/progressbar';
|
||||
import { Dialog } from 'primereact/dialog';
|
||||
import { InputTextarea } from 'primereact/inputtextarea';
|
||||
import { Dropdown } from 'primereact/dropdown';
|
||||
import { Timeline } from 'primereact/timeline';
|
||||
import { Toast } from 'primereact/toast';
|
||||
import { Divider } from 'primereact/divider';
|
||||
import { Badge } from 'primereact/badge';
|
||||
import { Knob } from 'primereact/knob';
|
||||
import chantierService from '../../../../services/chantierService';
|
||||
|
||||
/**
|
||||
* Page Workflow Chantiers BTP Express
|
||||
* Gestion complète du cycle de vie des chantiers avec transitions d'état
|
||||
*/
|
||||
const WorkflowChantiers = () => {
|
||||
const [chantiers, setChantiers] = useState<any[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [workflowDialog, setWorkflowDialog] = useState(false);
|
||||
const [selectedChantier, setSelectedChantier] = useState<any>(null);
|
||||
const [nouveauStatut, setNouveauStatut] = useState('');
|
||||
const [commentaire, setCommentaire] = useState('');
|
||||
const [historique, setHistorique] = useState<any[]>([]);
|
||||
const [metriques, setMetriques] = useState<any>({});
|
||||
const toast = useRef<Toast>(null);
|
||||
|
||||
// Définition des transitions workflow BTP
|
||||
const workflowTransitions = {
|
||||
'PLANIFIE': [
|
||||
{ label: 'Démarrer le chantier', value: 'EN_COURS', icon: 'pi-play', color: 'success' },
|
||||
{ label: 'Annuler', value: 'ANNULE', icon: 'pi-times', color: 'danger' }
|
||||
],
|
||||
'EN_COURS': [
|
||||
{ label: 'Terminer le chantier', value: 'TERMINE', icon: 'pi-check', color: 'success' },
|
||||
{ label: 'Suspendre', value: 'SUSPENDU', icon: 'pi-pause', color: 'warning' },
|
||||
{ label: 'Annuler', value: 'ANNULE', icon: 'pi-times', color: 'danger' }
|
||||
],
|
||||
'SUSPENDU': [
|
||||
{ label: 'Reprendre', value: 'EN_COURS', icon: 'pi-play', color: 'info' },
|
||||
{ label: 'Annuler définitivement', value: 'ANNULE', icon: 'pi-times', color: 'danger' }
|
||||
],
|
||||
'TERMINE': [], // Statut final
|
||||
'ANNULE': [] // Statut final
|
||||
};
|
||||
|
||||
const statutsConfig = {
|
||||
'PLANIFIE': { color: 'info', icon: 'pi-calendar', label: 'Planifié' },
|
||||
'EN_COURS': { color: 'success', icon: 'pi-cog', label: 'En cours' },
|
||||
'SUSPENDU': { color: 'warning', icon: 'pi-pause', label: 'Suspendu' },
|
||||
'TERMINE': { color: 'success', icon: 'pi-check-circle', label: 'Terminé' },
|
||||
'ANNULE': { color: 'danger', icon: 'pi-times-circle', label: 'Annulé' }
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
loadChantiers();
|
||||
loadMetriques();
|
||||
}, []);
|
||||
|
||||
const loadChantiers = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
|
||||
// Simulation données chantiers avec workflow
|
||||
const mockChantiers = [
|
||||
{
|
||||
id: '1',
|
||||
nom: 'Rénovation Villa Rousseau',
|
||||
client: 'Claire Rousseau',
|
||||
statut: 'EN_COURS',
|
||||
avancement: 65,
|
||||
dateDebut: '2025-01-15',
|
||||
dateFinPrevue: '2025-03-20',
|
||||
montantPrevu: 85000,
|
||||
montantReel: 72500,
|
||||
equipe: 'Équipe Rénovation A',
|
||||
phases: [
|
||||
{ nom: 'Démolition', statut: 'TERMINE', avancement: 100 },
|
||||
{ nom: 'Gros œuvre', statut: 'EN_COURS', avancement: 80 },
|
||||
{ nom: 'Second œuvre', statut: 'PLANIFIE', avancement: 0 },
|
||||
{ nom: 'Finitions', statut: 'PLANIFIE', avancement: 0 }
|
||||
],
|
||||
alertes: ['Retard de 3 jours sur livraison matériaux'],
|
||||
derniereMiseAJour: new Date()
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
nom: 'Extension Maison Martin',
|
||||
client: 'Sophie Martin',
|
||||
statut: 'PLANIFIE',
|
||||
avancement: 0,
|
||||
dateDebut: '2025-02-10',
|
||||
dateFinPrevue: '2025-05-15',
|
||||
montantPrevu: 45000,
|
||||
montantReel: 0,
|
||||
equipe: 'Équipe Extension B',
|
||||
phases: [
|
||||
{ nom: 'Fondations', statut: 'PLANIFIE', avancement: 0 },
|
||||
{ nom: 'Élévation', statut: 'PLANIFIE', avancement: 0 },
|
||||
{ nom: 'Couverture', statut: 'PLANIFIE', avancement: 0 },
|
||||
{ nom: 'Aménagement', statut: 'PLANIFIE', avancement: 0 }
|
||||
],
|
||||
alertes: [],
|
||||
derniereMiseAJour: new Date()
|
||||
},
|
||||
{
|
||||
id: '3',
|
||||
nom: 'Réfection Toiture Dupont',
|
||||
client: 'Jean Dupont',
|
||||
statut: 'SUSPENDU',
|
||||
avancement: 30,
|
||||
dateDebut: '2025-01-08',
|
||||
dateFinPrevue: '2025-02-28',
|
||||
montantPrevu: 28000,
|
||||
montantReel: 12000,
|
||||
equipe: 'Équipe Couverture C',
|
||||
phases: [
|
||||
{ nom: 'Dépose ancienne toiture', statut: 'TERMINE', avancement: 100 },
|
||||
{ nom: 'Charpente', statut: 'SUSPENDU', avancement: 60 },
|
||||
{ nom: 'Couverture neuve', statut: 'PLANIFIE', avancement: 0 },
|
||||
{ nom: 'Isolation', statut: 'PLANIFIE', avancement: 0 }
|
||||
],
|
||||
alertes: ['Chantier suspendu - Problème météorologique', 'Attente validation assurance'],
|
||||
derniereMiseAJour: new Date()
|
||||
}
|
||||
];
|
||||
|
||||
setChantiers(mockChantiers);
|
||||
} catch (error) {
|
||||
console.error('Erreur chargement chantiers:', error);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const loadMetriques = () => {
|
||||
setMetriques({
|
||||
totalChantiers: 12,
|
||||
enCours: 5,
|
||||
planifies: 4,
|
||||
terminesRecemment: 2,
|
||||
suspendus: 1,
|
||||
tauxReussite: 92,
|
||||
delaiMoyen: -2 // Négatif = en avance
|
||||
});
|
||||
};
|
||||
|
||||
const ouvrirWorkflow = (chantier: any) => {
|
||||
setSelectedChantier(chantier);
|
||||
setNouveauStatut('');
|
||||
setCommentaire('');
|
||||
|
||||
// Charger historique du chantier
|
||||
const mockHistorique = [
|
||||
{
|
||||
date: new Date('2025-01-15T08:00:00'),
|
||||
statut: 'EN_COURS',
|
||||
utilisateur: 'M. Laurent',
|
||||
commentaire: 'Démarrage chantier - Équipe mobilisée',
|
||||
automatique: false
|
||||
},
|
||||
{
|
||||
date: new Date('2025-01-20T14:30:00'),
|
||||
statut: 'EN_COURS',
|
||||
utilisateur: 'Système',
|
||||
commentaire: 'Phase démolition terminée automatiquement',
|
||||
automatique: true
|
||||
},
|
||||
{
|
||||
date: new Date('2025-01-25T10:15:00'),
|
||||
statut: 'EN_COURS',
|
||||
utilisateur: 'Mme Petit',
|
||||
commentaire: 'Avancement gros œuvre - 50% réalisé',
|
||||
automatique: false
|
||||
}
|
||||
];
|
||||
|
||||
setHistorique(mockHistorique);
|
||||
setWorkflowDialog(true);
|
||||
};
|
||||
|
||||
const executerTransition = async () => {
|
||||
if (!selectedChantier || !nouveauStatut) return;
|
||||
|
||||
try {
|
||||
// Simuler appel API pour changer le statut
|
||||
const chantierMisAJour = {
|
||||
...selectedChantier,
|
||||
statut: nouveauStatut,
|
||||
derniereMiseAJour: new Date()
|
||||
};
|
||||
|
||||
// Logique métier spécifique selon le statut
|
||||
if (nouveauStatut === 'EN_COURS') {
|
||||
chantierMisAJour.dateDebutReel = new Date();
|
||||
} else if (nouveauStatut === 'TERMINE') {
|
||||
chantierMisAJour.dateFinReelle = new Date();
|
||||
chantierMisAJour.avancement = 100;
|
||||
}
|
||||
|
||||
// Mettre à jour la liste
|
||||
const chantiersUpdated = chantiers.map(c =>
|
||||
c.id === selectedChantier.id ? chantierMisAJour : c
|
||||
);
|
||||
setChantiers(chantiersUpdated);
|
||||
|
||||
// Ajouter à l'historique
|
||||
const nouvelleEntree = {
|
||||
date: new Date(),
|
||||
statut: nouveauStatut,
|
||||
utilisateur: 'Utilisateur actuel',
|
||||
commentaire: commentaire || `Changement vers ${statutsConfig[nouveauStatut as keyof typeof statutsConfig]?.label}`,
|
||||
automatique: false
|
||||
};
|
||||
|
||||
setHistorique([nouvelleEntree, ...historique]);
|
||||
|
||||
toast.current?.show({
|
||||
severity: 'success',
|
||||
summary: 'Transition réussie',
|
||||
detail: `Chantier "${selectedChantier.nom}" passé en statut ${statutsConfig[nouveauStatut as keyof typeof statutsConfig]?.label}`,
|
||||
life: 4000
|
||||
});
|
||||
|
||||
setWorkflowDialog(false);
|
||||
loadMetriques(); // Recalculer les métriques
|
||||
|
||||
} catch (error) {
|
||||
console.error('Erreur transition:', error);
|
||||
toast.current?.show({
|
||||
severity: 'error',
|
||||
summary: 'Erreur',
|
||||
detail: 'Impossible d\'effectuer la transition',
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const statutBodyTemplate = (rowData: any) => {
|
||||
const config = statutsConfig[rowData.statut as keyof typeof statutsConfig];
|
||||
return (
|
||||
<div className="flex align-items-center gap-2">
|
||||
<i className={`pi ${config.icon} text-${config.color}`} />
|
||||
<Tag value={config.label} severity={config.color} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const avancementBodyTemplate = (rowData: any) => {
|
||||
return (
|
||||
<div className="flex align-items-center gap-2">
|
||||
<ProgressBar
|
||||
value={rowData.avancement}
|
||||
style={{ width: '100px', height: '8px' }}
|
||||
color={rowData.avancement >= 100 ? '#10B981' : rowData.avancement >= 50 ? '#F59E0B' : '#3B82F6'}
|
||||
/>
|
||||
<span className="text-sm font-medium">{rowData.avancement}%</span>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const alertesBodyTemplate = (rowData: any) => {
|
||||
if (!rowData.alertes || rowData.alertes.length === 0) {
|
||||
return <span className="text-color-secondary">-</span>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex align-items-center gap-2">
|
||||
<Badge value={rowData.alertes.length} severity="danger" />
|
||||
<Button
|
||||
icon="pi pi-exclamation-triangle"
|
||||
text
|
||||
size="small"
|
||||
severity="danger"
|
||||
tooltip={rowData.alertes.join(', ')}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const actionsBodyTemplate = (rowData: any) => {
|
||||
const transitionsPossibles = workflowTransitions[rowData.statut as keyof typeof workflowTransitions] || [];
|
||||
|
||||
return (
|
||||
<div className="flex gap-2">
|
||||
<Button
|
||||
icon="pi pi-cog"
|
||||
size="small"
|
||||
severity="info"
|
||||
tooltip="Gérer workflow"
|
||||
onClick={() => ouvrirWorkflow(rowData)}
|
||||
/>
|
||||
|
||||
{transitionsPossibles.length > 0 && (
|
||||
<Button
|
||||
icon="pi pi-arrow-right"
|
||||
size="small"
|
||||
severity="success"
|
||||
tooltip="Transitions disponibles"
|
||||
onClick={() => ouvrirWorkflow(rowData)}
|
||||
/>
|
||||
)}
|
||||
|
||||
<Button
|
||||
icon="pi pi-eye"
|
||||
size="small"
|
||||
severity="help"
|
||||
tooltip="Voir détails"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const phasesBodyTemplate = (rowData: any) => {
|
||||
const phasesTerminees = rowData.phases?.filter((p: any) => p.statut === 'TERMINE').length || 0;
|
||||
const totalPhases = rowData.phases?.length || 0;
|
||||
|
||||
return (
|
||||
<div className="flex align-items-center gap-2">
|
||||
<span className="text-sm">{phasesTerminees}/{totalPhases}</span>
|
||||
<ProgressBar
|
||||
value={totalPhases > 0 ? (phasesTerminees / totalPhases) * 100 : 0}
|
||||
style={{ width: '60px', height: '6px' }}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="grid">
|
||||
<Toast ref={toast} />
|
||||
|
||||
{/* Métriques Workflow */}
|
||||
<div className="col-12">
|
||||
<div className="grid">
|
||||
<div className="col-12 md:col-2">
|
||||
<Card>
|
||||
<div className="text-center">
|
||||
<div className="text-2xl font-bold text-blue-500">{metriques.totalChantiers}</div>
|
||||
<div className="text-color-secondary">Total chantiers</div>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
<div className="col-12 md:col-2">
|
||||
<Card>
|
||||
<div className="text-center">
|
||||
<div className="text-2xl font-bold text-green-500">{metriques.enCours}</div>
|
||||
<div className="text-color-secondary">En cours</div>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
<div className="col-12 md:col-2">
|
||||
<Card>
|
||||
<div className="text-center">
|
||||
<div className="text-2xl font-bold text-cyan-500">{metriques.planifies}</div>
|
||||
<div className="text-color-secondary">Planifiés</div>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
<div className="col-12 md:col-2">
|
||||
<Card>
|
||||
<div className="text-center">
|
||||
<div className="text-2xl font-bold text-orange-500">{metriques.suspendus}</div>
|
||||
<div className="text-color-secondary">Suspendus</div>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
<div className="col-12 md:col-2">
|
||||
<Card>
|
||||
<div className="text-center">
|
||||
<Knob
|
||||
value={metriques.tauxReussite}
|
||||
size={60}
|
||||
strokeWidth={8}
|
||||
valueColor="#10B981"
|
||||
/>
|
||||
<div className="text-color-secondary mt-2">Taux réussite</div>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
<div className="col-12 md:col-2">
|
||||
<Card>
|
||||
<div className="text-center">
|
||||
<div className={`text-2xl font-bold ${metriques.delaiMoyen < 0 ? 'text-green-500' : 'text-red-500'}`}>
|
||||
{metriques.delaiMoyen > 0 ? `+${metriques.delaiMoyen}` : metriques.delaiMoyen}j
|
||||
</div>
|
||||
<div className="text-color-secondary">Délai moyen</div>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="col-12">
|
||||
<Divider />
|
||||
</div>
|
||||
|
||||
{/* Tableau chantiers avec workflow */}
|
||||
<div className="col-12">
|
||||
<Card title="Gestion Workflow Chantiers">
|
||||
<DataTable
|
||||
value={chantiers}
|
||||
loading={loading}
|
||||
paginator
|
||||
rows={10}
|
||||
dataKey="id"
|
||||
emptyMessage="Aucun chantier trouvé"
|
||||
responsiveLayout="scroll"
|
||||
>
|
||||
<Column field="nom" header="Chantier" sortable style={{ minWidth: '200px' }} />
|
||||
<Column field="client" header="Client" sortable style={{ minWidth: '150px' }} />
|
||||
<Column header="Statut" body={statutBodyTemplate} sortable style={{ minWidth: '120px' }} />
|
||||
<Column header="Avancement" body={avancementBodyTemplate} style={{ minWidth: '150px' }} />
|
||||
<Column header="Phases" body={phasesBodyTemplate} style={{ minWidth: '100px' }} />
|
||||
<Column field="equipe" header="Équipe" style={{ minWidth: '150px' }} />
|
||||
<Column header="Alertes" body={alertesBodyTemplate} style={{ minWidth: '80px' }} />
|
||||
<Column
|
||||
field="montantPrevu"
|
||||
header="Budget"
|
||||
body={(rowData) => new Intl.NumberFormat('fr-FR', {
|
||||
style: 'currency',
|
||||
currency: 'EUR',
|
||||
notation: 'compact'
|
||||
}).format(rowData.montantPrevu)}
|
||||
style={{ minWidth: '100px' }}
|
||||
/>
|
||||
<Column body={actionsBodyTemplate} style={{ minWidth: '150px' }} />
|
||||
</DataTable>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
{/* Dialog Workflow */}
|
||||
<Dialog
|
||||
visible={workflowDialog}
|
||||
style={{ width: '90vw', height: '90vh' }}
|
||||
header={`Workflow - ${selectedChantier?.nom}`}
|
||||
modal
|
||||
onHide={() => setWorkflowDialog(false)}
|
||||
maximizable
|
||||
>
|
||||
{selectedChantier && (
|
||||
<div className="grid">
|
||||
{/* Informations chantier */}
|
||||
<div className="col-12 md:col-4">
|
||||
<Card title="Informations Chantier">
|
||||
<div className="flex flex-column gap-3">
|
||||
<div>
|
||||
<strong>Client:</strong> {selectedChantier.client}
|
||||
</div>
|
||||
<div>
|
||||
<strong>Statut actuel:</strong>
|
||||
<Tag
|
||||
value={statutsConfig[selectedChantier.statut as keyof typeof statutsConfig]?.label}
|
||||
severity={statutsConfig[selectedChantier.statut as keyof typeof statutsConfig]?.color}
|
||||
className="ml-2"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<strong>Avancement:</strong>
|
||||
<ProgressBar value={selectedChantier.avancement} className="mt-2" />
|
||||
</div>
|
||||
<div>
|
||||
<strong>Équipe:</strong> {selectedChantier.equipe}
|
||||
</div>
|
||||
<div>
|
||||
<strong>Budget:</strong> {new Intl.NumberFormat('fr-FR', {
|
||||
style: 'currency',
|
||||
currency: 'EUR'
|
||||
}).format(selectedChantier.montantPrevu)}
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
{/* Transitions disponibles */}
|
||||
<div className="col-12 md:col-4">
|
||||
<Card title="Actions Disponibles">
|
||||
<div className="flex flex-column gap-3">
|
||||
{workflowTransitions[selectedChantier.statut as keyof typeof workflowTransitions]?.map((transition) => (
|
||||
<Button
|
||||
key={transition.value}
|
||||
label={transition.label}
|
||||
icon={`pi ${transition.icon}`}
|
||||
severity={transition.color}
|
||||
className="justify-content-start"
|
||||
onClick={() => setNouveauStatut(transition.value)}
|
||||
outlined={nouveauStatut !== transition.value}
|
||||
/>
|
||||
))}
|
||||
|
||||
{workflowTransitions[selectedChantier.statut as keyof typeof workflowTransitions]?.length === 0 && (
|
||||
<div className="text-center text-color-secondary p-4">
|
||||
<i className="pi pi-lock text-3xl mb-3" />
|
||||
<div>Aucune transition disponible</div>
|
||||
<div className="text-sm">Statut final atteint</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{nouveauStatut && (
|
||||
<div className="mt-4">
|
||||
<label className="block text-sm font-medium mb-2">
|
||||
Commentaire (optionnel)
|
||||
</label>
|
||||
<InputTextarea
|
||||
value={commentaire}
|
||||
onChange={(e) => setCommentaire(e.target.value)}
|
||||
rows={3}
|
||||
placeholder="Ajoutez un commentaire sur cette transition..."
|
||||
/>
|
||||
|
||||
<div className="flex gap-2 mt-3">
|
||||
<Button
|
||||
label="Confirmer la transition"
|
||||
icon="pi pi-check"
|
||||
severity="success"
|
||||
onClick={executerTransition}
|
||||
/>
|
||||
<Button
|
||||
label="Annuler"
|
||||
icon="pi pi-times"
|
||||
severity="secondary"
|
||||
outlined
|
||||
onClick={() => {
|
||||
setNouveauStatut('');
|
||||
setCommentaire('');
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
{/* Historique */}
|
||||
<div className="col-12 md:col-4">
|
||||
<Card title="Historique des Changements">
|
||||
<Timeline
|
||||
value={historique}
|
||||
align="left"
|
||||
content={(item) => (
|
||||
<div className="p-2">
|
||||
<div className="flex align-items-center gap-2 mb-1">
|
||||
<Tag
|
||||
value={statutsConfig[item.statut as keyof typeof statutsConfig]?.label}
|
||||
severity={statutsConfig[item.statut as keyof typeof statutsConfig]?.color}
|
||||
/>
|
||||
{item.automatique && <Badge value="Auto" severity="info" />}
|
||||
</div>
|
||||
<div className="text-sm text-color-secondary mb-1">
|
||||
{item.date.toLocaleString('fr-FR')}
|
||||
</div>
|
||||
<div className="text-sm font-medium mb-1">
|
||||
{item.utilisateur}
|
||||
</div>
|
||||
<div className="text-sm">
|
||||
{item.commentaire}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
/>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</Dialog>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default WorkflowChantiers;
|
||||
Reference in New Issue
Block a user