$extension = File::extension($request->file('import_file')->getClientOriginalName()); //$newfilename= basename($_FILES["import_file"]["name"]); $newfilename= date('dmYHis').str_replace("- ", "", basename($_FILES["import_file"]["name"])); $import = request()->file('import_file'); $path = request()->file('import_file')->getRealPath(); $extension = request()->file('import_file')->guessExtension(); $file = request()->file('import_file')->storeAs('plugins/fichiers', $newfilename ,'public'); if ($extension=="xlsx" || $extension == "xls" || $extension == "csv") { $feuille=Excel::toArray([],$import); $derniereLigne = count($feuille[0]) -1; $tableauexcel = $feuille['0']; //pas neccessaire $init = DB::select("call sp_init_inserer_ligne_modele_assure_tempon(?,?);",[$codeSociete,$code_utilisateur]); for ($i = 1; $i <= $derniereLigne; $i++) { $categorie = trim($tableauexcel[$i]['0']); $noFamille = trim($tableauexcel[$i]['1']); if ($noFamille<=" ") { $noFamille = "0"; } $numeroAdherent = trim($tableauexcel[$i]['2']); $nom = trim($tableauexcel[$i]['3']); $prenoms = trim($tableauexcel[$i]['4']); $codeLienParente = trim($tableauexcel[$i]['5']); $codeNaturePiece = trim($tableauexcel[$i]['6']); $numeroPiece = trim($tableauexcel[$i]['7']); $sexe = trim($tableauexcel[$i]['8']); $codeGroupeSanguin = trim($tableauexcel[$i]['9']); $dateNaissance = trim($tableauexcel[$i]['10']); $telephonePortable = trim($tableauexcel[$i]['11']); // $numeroMatricule = trim($feuille[$i]['M']); $numeroCmu = trim($tableauexcel[$i]['12']); $nomComplet = $nom . " " . $prenoms; // ON VERIFIE LES DONNEES DU TABLEAU EXCEL if ( ($categorie<=" ") && ($codeLienParente=="A")) { return back()->withStatus(__($nomComplet . " => Pas de catégorie!")); } $liste_liens = array("A", "C", "E", "O", "F", "D"); if (!in_array($codeLienParente, $liste_liens)) { return back()->withStatus(__($nomComplet . " => => Revoir lien de parenté!")); } $liste_sexes = array("M", "F"); if (!in_array($sexe, $liste_sexes)) { return back()->withStatus(__($nomComplet . " => => Revoir le sexe!")); } DB::select("call sp_inserer_ligne_modele_assure_tempon(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?);",[ $categorie, $numeroAdherent, $noFamille, $nom, $prenoms, $codeLienParente, $codeNaturePiece, $numeroPiece, $sexe, $codeGroupeSanguin, $dateNaissance, $telephonePortable, $numeroCmu, $code_utilisateur ]); // Penser à gérer les erreurs de date // dd($nomComplet); } // Vérification de certaines erreurs : // 1 => Si nouvelle famille sans Adhérent $noFamilleSansAdherents = DB::select("call sp_adh_imp_famille_sans_adherent_tempon(?);",[$codeSociete ]); foreach ($noFamilleSansAdherents as $noFamilleSansAdherent){ } $noFamilleSansAdherent = $noFamilleSansAdherent->noFamille; if ($noFamilleSansAdherent>"0") { return back()->withStatus(__(" => => Famille ".$noFamilleSansAdherent. " => => Adherent Principal manquant !")); } // 2 => Si plus d'1 Adhérent dans une même famille $noFamillePlusieursAdherents = DB::select("call sp_adh_imp_famille_plusieurs_adherent_tempon(?);",[$codeSociete ]); foreach ($noFamillePlusieursAdherents as $noFamillePlusieursAdherent){ } $noFamillePlusieursAdherent = $noFamillePlusieursAdherent->noFamille; if ($noFamillePlusieursAdherent>"0") { return back()->withStatus(__(" => => Famille ".$noFamillePlusieursAdherent . " => => Plusieurs Adherents Principaux !")); } dd($code_utilisateur); // a ne pas excecuter //DB::select("call sp_incorporer_assures_importes();"); return back()->withStatus(__('Import effectué')); }else{ return back()->withStatus(__("Veuillez Choisir un fichier au format XLSX ou XLS ou CSV")); }