This commit is contained in:
KONE SOREL 2026-01-05 19:40:23 +00:00
parent b63f1055b9
commit c7d856275d
5 changed files with 153 additions and 146 deletions

View File

@ -87,133 +87,102 @@ class ControleurAjaximporterlisteassure extends Controleurrequete
public function importermodele()
{
$idAvenant = $this->requete->getParametreFormulaire("idAvenant");
$cheminFichier = $this->requete->getParametreFormulaire("cheminFichier");
$idAvenant = $this->requete->getParametreFormulaire("idAvenant");
$cheminFichier = $this->requete->getParametreFormulaire("cheminFichier");
$_SESSION['idAvenant_C'] = $idAvenant;
$this->beneficiaire->initIinsererLigneModeleAssure();
$dataXLS = array();
$fichier = "Temp/import/".$cheminFichier;
if (!file_exists($fichier))
{
$this->genererVueAjax(array('message_erreur_excel' => "Fichier introubable sur le serveur !", 'succes_impot_execl' => "0"));
// 1. Vérification du fichier
if (!file_exists($fichier)) {
$this->genererVueAjax(array(
'message_erreur_excel' => "Erreur : Fichier introuvable sur le serveur !",
'succes_impot_execl' => "0"
));
exit();
}
/*
$docXLS = new PHPExcel_Reader_Excel2007();
$Excel = $docXLS->load($fichier);
$Excel->setActiveSheetIndex(0);
$feuille=$Excel->getActiveSheet();
*/
$docXLS = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
$Excel = $docXLS->load($fichier);
$feuille = $Excel->getSheet($Excel->getFirstSheetIndex());
$derniereLigne = $feuille->getHighestRow();
$derniereColonne = $feuille->getHighestColumn();
$tableauExcel = $feuille->toArray(null, true, true, true);
for ($i = 2; $i <= $derniereLigne; $i++)
{
$categorie = trim($tableauExcel[$i]['A']);
$numeroAdherent = trim($tableauExcel[$i]['B']);
$noFamille = trim($tableauExcel[$i]['C']);
if ($noFamille<=" ")
try {
$docXLS = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
$Excel = $docXLS->load($fichier);
$feuille = $Excel->getSheet($Excel->getFirstSheetIndex());
$derniereLigne = $feuille->getHighestRow();
$tableauExcel = $feuille->toArray(null, true, true, true);
// 2. Boucle de validation et insertion
for ($i = 2; $i <= $derniereLigne; $i++)
{
$noFamille = "0";
// ... (vos extractions trim() restent identiques)
$nom = trim($tableauExcel[$i]['D']);
$prenoms = trim($tableauExcel[$i]['E']);
$nomComplet = $nom . " " . $prenoms;
$codeLienParente = trim($tableauExcel[$i]['F']);
$sexe = trim($tableauExcel[$i]['I']);
// Validation Catégorie
if ( (trim($tableauExcel[$i]['A']) <= " ") && ($codeLienParente == "A")) {
$this->renvoyerErreurImport("Ligne $i : $nomComplet => Pas de catégorie !");
}
// Validation Lien de parenté
if (!in_array($codeLienParente, array("A", "C", "E", "O"))) {
$this->renvoyerErreurImport("Ligne $i : $nomComplet => Lien de parenté '$codeLienParente' invalide !");
}
// Validation Sexe
if (!in_array($sexe, array("M", "F"))) {
$this->renvoyerErreurImport("Ligne $i : $nomComplet => Genre '$sexe' invalide !");
}
// Insertion en base temporaire
$this->beneficiaire->insererLigneModeleAssure($idAvenant, ...$params);
}
$nom = trim($tableauExcel[$i]['D']);
$prenoms = trim($tableauExcel[$i]['E']);
$codeLienParente = trim($tableauExcel[$i]['F']);
$this->beneficiaire->gererIncorporationSurFamExistante();
$codeNaturePiece = trim($tableauExcel[$i]['G']);
$numeroPiece = trim($tableauExcel[$i]['H']);
$sexe = trim($tableauExcel[$i]['I']);
$codeGroupeSanguin = trim($tableauExcel[$i]['J']);
$dateNaissance = trim($tableauExcel[$i]['K']);
$telephonePortable = trim($tableauExcel[$i]['L']);
$email = trim($tableauExcel[$i]['M']);
$nomComplet = $nom . " " . $prenoms;
if ( ($categorie<=" ") && ($codeLienParente=="A"))
{
$this->genererVueAjax(array('message_erreur_excel' => $nomComplet . " => Pas de catégorie!", 'succes_impot_execl' => "0"));
exit();
}
$liste_liens = array("A", "C", "E", "O");
if (!in_array($codeLienParente, $liste_liens))
{
$this->genererVueAjax(array('message_erreur_excel' => $nomComplet . " => Revoir lien de parenté!", 'succes_impot_execl' => "0"));
exit();
}
// 3. Vérifications métier post-import
$this->verifierContraintesMetier();
$liste_sexes = array("M", "F");
if (!in_array($sexe, $liste_sexes))
{
$this->genererVueAjax(array('message_erreur_excel' => $nomComplet . " => Revoir le sexe!", 'succes_impot_execl' => "0"));
exit();
}
// 4. SUCCÈS FINAL
$this->genererVueAjax(array(
'message_erreur_excel' => "Fichier analysé avec succès ! Préparation de l'incorporation...",
'succes_impot_execl' => "1"
));
// Penser à gérer les erreurs de date
$this->beneficiaire->insererLigneModeleAssure($idAvenant, $categorie, $numeroAdherent,
$noFamille, $nom, $prenoms, $codeLienParente, $codeNaturePiece, $numeroPiece, $sexe,
$codeGroupeSanguin, $dateNaissance, $telephonePortable, $email);
/*
echo "Ligne ". $i . " => OK";
echo "<BR>";
*/
} catch (Exception $e) {
$this->renvoyerErreurImport("Erreur lors de la lecture du fichier : " . $e->getMessage());
}
$this->beneficiaire->gererIncorporationSurFamExistante();
// Vérification de certaines erreurs :
// 1 => Si nouvelle famille sans Adhérent
$noFamilleSansAdherent = $this->beneficiaire->getadhimpfamillesansadherent();
if ($noFamilleSansAdherent>"0")
{
$this->genererVueAjax(array('message_erreur_excel' => "Famille " . $noFamilleSansAdherent . " => Adherent Principal manquant !", 'succes_impot_execl' => "0"));
exit();
}
// 2 => Si plus d'1 Adhérent dans une même famille
$noFamillePlusieursAdherent = $this->beneficiaire->getadhimpfamilleplusieursadherent();
if ($noFamillePlusieursAdherent>"0")
{
$this->genererVueAjax(array('message_erreur_excel' => "Famille " . $noFamillePlusieursAdherent . " => Plusieurs Adherents Principaux !", 'succes_impot_execl' => "0"));
exit();
}
// 3 => Incorporation sur une ancienne famille introuvable dans la police
$noFamilleExistantSansAdherent = $this->beneficiaire->getadhimpfamilleexistantsansadherent();
if ($noFamilleExistantSansAdherent>"0")
{
$this->genererVueAjax(array('message_erreur_excel' => "Famille " . $noFamilleExistantSansAdherent . " => Ancienne famille introuvable !", 'succes_impot_execl' => "0"));
exit();
}
$this->genererVueAjax(array('message_erreur_excel' => "Fichier temporaire extrait du serveur avec succes!", 'succes_impot_execl' => "1"));
exit();
}
/**
* Helper pour uniformiser les sorties d'erreur
*/
private function renvoyerErreurImport($message) {
$this->genererVueAjax(array(
'message_erreur_excel' => $message,
'succes_impot_execl' => "0"
));
exit();
}
/**
* Regroupe vos vérifications de cohérence famille
*/
private function verifierContraintesMetier() {
$err1 = $this->beneficiaire->getadhimpfamillesansadherent();
if ($err1 > "0") $this->renvoyerErreurImport("Famille $err1 => Adhérent Principal (A) manquant !");
$err2 = $this->beneficiaire->getadhimpfamilleplusieursadherent();
if ($err2 > "0") $this->renvoyerErreurImport("Famille $err2 => Plusieurs Adhérents Principaux détectés !");
$err3 = $this->beneficiaire->getadhimpfamilleexistantsansadherent();
if ($err3 > "0") $this->renvoyerErreurImport("Famille $err3 => Ancienne famille introuvable dans cette police !");
}
//
public function traiterlignesimportees()
{

View File

@ -2580,8 +2580,7 @@ function importer_modele_assure(idAvenant) {
var isSuccess = $("#succes_impot_execl").val();
maj_etape_3_import_assures();
/*
if (isSuccess === "1") {
alert_ebene("Liaison réussie ! Passage au traitement...", "Link successful! Moving to processing...");
maj_etape_3_import_assures();
@ -2589,7 +2588,7 @@ function importer_modele_assure(idAvenant) {
div_export.empty(); // On vide le spinner pour laisser voir l'erreur
alert_ebene("Le fichier contient des erreurs de format.", "The file contains formatting errors.");
}
*/
},
error: function() {
alert_ebene("Erreur technique lors de l'importation.", "Technical error during import.");

View File

@ -1,4 +1,9 @@
<div id="div_erreur_excel" class="alert alert-danger" >
<H4> <?= $message_erreur_excel ?> </H4>
<input class="sr-only" type="text" id="succes_impot_execl" name="succes_impot_execl" value="<?= $succes_impot_execl ?>">
<div class="alert <?= ($succes_impot_execl == '1') ? 'alert-success' : 'alert-danger' ?> shadow-sm border-0 d-flex align-items-center">
<i class="fas <?= ($succes_impot_execl == '1') ? 'fa-check-circle' : 'fa-exclamation-triangle' ?> fa-2x me-3"></i>
<div>
<h6 class="alert-heading mb-1 fw-bold"><?= ($succes_impot_execl == '1') ? _("Analyse réussie") : _("Erreur d'analyse") ?></h6>
<span><?= $message_erreur_excel ?></span>
</div>
</div>
<input type="hidden" id="succes_impot_execl" value="<?= $succes_impot_execl ?>">

View File

@ -1,32 +1,66 @@
<legend> <?= _("Sélectionner un avenant pour importation OLD") ?> </legend>
<div class="mt-4 animate__animated animate__fadeIn">
<div class="alert alert-primary d-flex align-items-center mb-3 shadow-sm border-0">
<i class="fas fa-info-circle fa-lg me-3"></i>
<div>
<strong><?= _("Étape 3 :") ?></strong> <?= _("Veuillez sélectionner l'avenant auquel ces nouveaux assurés seront rattachés.") ?>
</div>
</div>
<table class="table table-striped table-bordered table-hover table-condensed table-responsive" style="font-size:10pt;">
<thead>
<tr>
<th style='text-align:center' > <?= _("Numéro") ?> </th>
<th style='text-align:center'> <?= _("Effet") ?> </th>
<th> <?= _("Libellé") ?> </th>
<th> <?= _("Commentaires") ?> </th>
<th> <?= _("Producteur") ?> </th>
<th style='text-align:center'> <?= _("Saisie") ?> </th>
<th style='text-align:center'> <?= _("Importer...") ?> </th>
</tr>
</thead>
<div class="table-responsive rounded shadow-sm border">
<table class="table table-hover align-middle mb-0" style="font-size: 0.9rem;">
<thead class="table-light text-muted">
<tr>
<th class="text-center py-3" width="10%"><?= _("N° Avenant") ?></th>
<th class="text-center" width="12%"><?= _("Date Effet") ?></th>
<th width="20%"><?= _("Mouvement") ?></th>
<th width="25%"><?= _("Motif / Commentaires") ?></th>
<th width="15%"><?= _("Auteur") ?></th>
<th class="text-center" width="18%"><?= _("Action") ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($avenants as $avenant):
$idAvenant = $avenant['idAvenant'];
?>
<tr class="transition-row">
<td class="text-center fw-bold text-primary">
<?= $this->nettoyer($avenant['numeroAvenant']) ?>
</td>
<td class="text-center">
<span class="badge bg-light text-dark border fw-bold px-2 py-1">
<?= dateLang($this->nettoyer($avenant['dateEffet'])) ?>
</span>
</td>
<td>
<div class="fw-bold"><?= $this->nettoyer($avenant['libelleAvenant']) ?></div>
<div class="text-muted x-small" style="font-size: 0.75rem;">
<i class="far fa-clock me-1"></i>Saisie le <?= dateheureLang($this->nettoyer($avenant['dateSysteme'])) ?>
</div>
</td>
<td>
<div class="text-muted small italic text-truncate" style="max-width: 250px;" title="<?= $this->nettoyer($avenant['motifavenant']) ?>">
<?= $this->nettoyer($avenant['motifavenant']) ?: '-' ?>
</div>
</td>
<td class="small">
<i class="fas fa-user-edit me-1 text-secondary"></i> <?= $this->nettoyer($avenant['utilisateur']) ?>
</td>
<td class="text-center">
<button type="button"
class="btn btn-info btn-sm px-3 shadow-sm text-white fw-bold w-100"
onclick="importer_modele_assure(<?= $idAvenant ?>);">
<i class="fas fa-file-import me-1"></i> <?= _("Lancer l'import") ?>
</button>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
<tbody>
<?php
foreach ($avenants as $avenant):
$idAvenant = $avenant['idAvenant'];
?>
<tr valign="top">
<td align='center'><?= $this->nettoyer($avenant['numeroAvenant']) ?></td>
<td align='center'><?= dateLang($this->nettoyer($avenant['dateEffet'])) ?></td>
<td><?= $this->nettoyer($avenant['libelleAvenant']) ?></td>
<td><?= $this->nettoyer($avenant['motifavenant']) ?></td>
<td><?= $this->nettoyer($avenant['utilisateur']) ?></td>
<td align='center'><?= dateheureLang($this->nettoyer($avenant['dateSysteme'])) ?></td>
<td> <button style='font-size:10pt;' type="button" class="form-control btn btn-info" onclick="javascript:importer_modele_assure(<?= $idAvenant ?>);"> <?= _("Importer...") ?> </button> </td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<style>
.transition-row { transition: all 0.2s ease; }
.transition-row:hover { background-color: rgba(13, 202, 240, 0.05) !important; }
.italic { font-style: italic; }
</style>

View File

@ -638,7 +638,7 @@ $photoAssureCrypte = $_SESSION['photoAssureCrypte'];
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<!-- Application Scripts -->
<script src="/Js/fonctions.js?ver=2026.01.05.28"></script>
<script src="/Js/fonctions.js?ver=2026.01.05.29"></script>
<script type="text/javascript">
raffraichier_gabarit();