prestation/Controleur/ControleurAjaximporterlisteassure.php
2025-12-01 18:54:33 +00:00

298 lines
8.7 KiB
PHP

<?php
require_once 'vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
require_once 'Framework/Controleurrequete.php'; // OK
require_once 'Modele/Beneficiaire.php';
require_once 'Modele/Avenant.php';
class ControleurAjaximporterlisteassure extends Controleurrequete
{
private $beneficiaire;
private $avenant;
public function __construct()
{
$this->beneficiaire = new Beneficiaire();
$this->avenant = new Avenant();
}
public function index()
{
}
public function initimportermodele()
{
$idPolice = $_SESSION['idPolice_C'];
$avenants = $this->avenant->getAvenant($idPolice);
$this->genererVueAjax(array('avenants' => $avenants));
}
public function exportermodele()
{
$beneficiaires = $this->beneficiaire->getModeleAssures();
// Excel
$headerXLS = array
(
_('Catégorie'),
_('No Adhérent'),
_('No Famille'),
_('Nom'),
_('Prénoms'),
_('Lien Parenté'),
_('Nature Pièce'),
_('No Pièce'),
_('Genre'),
_('Groupe Sang'),
_('Naissance'),
_('Tél Portable')
);
$dataXLS = array();
foreach ($beneficiaires as $beneficiaire)
{
$dataXLS[]=$beneficiaire;
}
$classeur = new Spreadsheet();
$classeur->getProperties()->setCreator("INTER-SANTE");
$classeur->setActiveSheetIndex(0);
$feuille=$classeur->getActiveSheet();
$feuille->setTitle(_('MODELE ASSURES'));
$feuille->fromArray($headerXLS, NULL, 'A1', true);
$feuille->fromArray($dataXLS, NULL, 'A2', true);
//Forcer le téléchargement vers le navigateur;
$fichier = 'Temp/TEMPLATE_LISTE_ASSURE'."_".uniqid().".xlsx";
$writer = new Xlsx($classeur);
$writer->save($fichier);
$t_html =' <div class="alert alert-success"> ';
$t_html .=' <a style="font-size:15pt;" href="'.$fichier.'" target="_blank" > '._("TELECHARGER").' </a> ';
$t_html .=' </div ';
echo $t_html;
exit();
}
public function importermodele()
{
$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"));
exit();
}
$docXLS = new PHPExcel_Reader_Excel2007();
$Excel = $docXLS->load($fichier);
$Excel->setActiveSheetIndex(0);
$feuille=$Excel->getActiveSheet();
$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<=" ")
{
$noFamille = "0";
}
$nom = trim($tableauExcel[$i]['D']);
$prenoms = trim($tableauExcel[$i]['E']);
$codeLienParente = trim($tableauExcel[$i]['F']);
$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']);
$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();
}
$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();
}
// Penser à gérer les erreurs de date
$this->beneficiaire->insererLigneModeleAssure($idAvenant, $categorie, $numeroAdherent,
$noFamille, $nom, $prenoms, $codeLienParente, $codeNaturePiece, $numeroPiece, $sexe,
$codeGroupeSanguin, $dateNaissance, $telephonePortable);
/*
echo "Ligne ". $i . " => OK";
echo "<BR>";
*/
}
$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();
}
//
public function traiterlignesimportees()
{
$idPolice = $_SESSION['idPolice_C'];
$avenants = $this->avenant->getAvenant($idPolice);
$this->genererVueAjax(array('avenants' => $avenants));
}
public function exclureligneimportee()
{
$idBeneficiairemodel = $this->requete->getParametreFormulaire("idBeneficiairemodel");
$exclure = $this->requete->getParametreFormulaire("exclure");
$this->beneficiaire->exclureligneimportee($idBeneficiairemodel, $exclure);
// $this->genererVueAjax();
}
public function calculerprimeimportee()
{
$this->beneficiaire->calculerprimeimportee();
}
public function afficheradherentimportee()
{
$idCollege = $this->requete->getParametreFormulaire("idCollege");
$adherents = $this->beneficiaire->getListeAdherentImportes($idCollege);
$adherents_college = $this->beneficiaire->getListeAdherentImportesCollege($idCollege);
$this->genererVueAjax(array('adherents' => $adherents, 'adherents_college' => $adherents_college));
}
public function ajouterunadherentaucollege()
{
$idBeneficiairemodel = $this->requete->getParametreFormulaire("idBeneficiairemodel");
$idCollege = $this->requete->getParametreFormulaire("idCollege");
$this->beneficiaire->ajouterunadherentaucollege($idBeneficiairemodel, $idCollege);
// $this->genererVueAjax();
}
public function retirerunadherentaucollege()
{
$idBeneficiairemodel = $this->requete->getParametreFormulaire("idBeneficiairemodel");
$this->beneficiaire->retirerunadherentaucollege($idBeneficiairemodel);
// $this->genererVueAjax();
}
public function incorpoerassuresimportes()
{
$this->beneficiaire->incorpoerassuresimportes();
// $this->genererVueAjax();
}
public function ajoutertousadherentaucollege()
{
$idCollege = $this->requete->getParametreFormulaire("idCollege");
$this->beneficiaire->ajoutertousadherentaucollege($idCollege);
// $this->genererVueAjax();
}
public function ajoutersanscollegeadherentaucollege()
{
$idCollege = $this->requete->getParametreFormulaire("idCollege");
$this->beneficiaire->ajoutersanscollegeadherentaucollege($idCollege);
// $this->genererVueAjax();
}
public function retirertousadherentaucollege()
{
$idCollege = $this->requete->getParametreFormulaire("idCollege");
$this->beneficiaire->retirertousadherentaucollege($idCollege);
// $this->genererVueAjax();
}
public function majetape()
{
$this->beneficiaire->majetape();
}
}