199 lines
5.4 KiB
PHP
199 lines
5.4 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/Tarifsmedicaments.php';
|
|
|
|
class ControleurAjaximportertarifmedicament extends Controleurrequete
|
|
{
|
|
private $tarif;
|
|
|
|
public function __construct() {
|
|
$this->tarif = new Tarifsmedicaments();
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
}
|
|
|
|
public function exportermodele()
|
|
{
|
|
$modeles = $this->tarif->getModeleTarif();
|
|
|
|
// Excel
|
|
$headerXLS = array(
|
|
"codeMedicament",
|
|
"libelle",
|
|
"unite",
|
|
"substituable",
|
|
"nomSubstitut",
|
|
"instructions",
|
|
"ententePrealable",
|
|
"exclu",
|
|
"actif",
|
|
"prix");
|
|
|
|
$dataXLS = array();
|
|
|
|
foreach ($modeles as $modele)
|
|
{
|
|
$dataXLS[]=$modele;
|
|
}
|
|
|
|
$classeur = new Spreadsheet();
|
|
$classeur->getProperties()->setCreator("INTER-SANTE");
|
|
$classeur->setActiveSheetIndex(0);
|
|
$feuille=$classeur->getActiveSheet();
|
|
$feuille->setTitle(_('MODELE TARIF MEDICAMENT'));
|
|
$feuille->fromArray($headerXLS, NULL, 'A1', true);
|
|
$feuille->fromArray($dataXLS, NULL, 'A2', true);
|
|
|
|
$fichier = 'Temp/TEMPLATE_MEDICAMENTS'."_".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()
|
|
{
|
|
$idTarif = $this->requete->getParametreFormulaire("idTarif");
|
|
$codeTarifMedicament = $this->requete->getParametreFormulaire("codeTarifMedicament");
|
|
$cheminFichier = $this->requete->getParametreFormulaire("cheminFichier");
|
|
|
|
$this->tarif->initIinsererLigneModeleTarif($idTarif);
|
|
|
|
$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++)
|
|
{
|
|
$codeMedicament = trim($tableauExcel[$i]['A']);
|
|
$libelle = trim($tableauExcel[$i]['B']);
|
|
$unite = trim($tableauExcel[$i]['C']);
|
|
|
|
$substituable = trim($tableauExcel[$i]['D']);
|
|
if ($substituable>"0")
|
|
{
|
|
$substituable = "1";
|
|
}
|
|
|
|
$nomSubstitut = trim($tableauExcel[$i]['E']);
|
|
$instructions = trim($tableauExcel[$i]['F']);
|
|
|
|
$ententePrealable = trim($tableauExcel[$i]['G']);
|
|
if ($ententePrealable>"0")
|
|
{
|
|
$ententePrealable = "1";
|
|
}
|
|
|
|
$exclu = trim($tableauExcel[$i]['H']);
|
|
if ($exclu>"0")
|
|
{
|
|
$exclu = "1";
|
|
}
|
|
|
|
$actif = trim($tableauExcel[$i]['I']);
|
|
if ($actif>"0")
|
|
{
|
|
$actif = "1";
|
|
}
|
|
|
|
$prix = trim($tableauExcel[$i]['J']);
|
|
if ($prix<="0")
|
|
{
|
|
$prix = "0";
|
|
}
|
|
|
|
if ($codeMedicament<=" ")
|
|
{
|
|
$this->genererVueAjax(array('message_erreur_excel' => "Ligne " . $i ." => codeMedicament ne peut être vide !", 'succes_impot_execl' => "0"));
|
|
exit();
|
|
}
|
|
|
|
if ($libelle<=" ")
|
|
{
|
|
$this->genererVueAjax(array('message_erreur_excel' => "Ligne " . $i ." => Le libellé ne peut être vide !", 'succes_impot_execl' => "0"));
|
|
exit();
|
|
}
|
|
|
|
if ($prix<="0")
|
|
{
|
|
$this->genererVueAjax(array('message_erreur_excel' => "Ligne " . $i ." => Revoir le prix !", 'succes_impot_execl' => "0"));
|
|
exit();
|
|
}
|
|
|
|
// codeMedicament inexistant dans p_medicamentmodel et donc p_medicament
|
|
$codeMedicamentManquant = $this->tarif->getcodemedicamentmanquant($codeMedicament);
|
|
if ($codeMedicamentManquant=="0")
|
|
{
|
|
$this->genererVueAjax(array('message_erreur_excel' => "codeMedicament " . $codeMedicament . " => manquant dans la liste des medicaments !", 'succes_impot_execl' => "0"));
|
|
exit();
|
|
}
|
|
|
|
$this->tarif->insererLigneModeleTarif($idTarif, $codeTarifMedicament, $codeMedicament, $libelle, $unite, $substituable,
|
|
$nomSubstitut, $instructions, $ententePrealable, $exclu, $actif, $prix);
|
|
}
|
|
|
|
// $this->genererVueAjax(array('message_erreur_excel' => "Tout est OK !", 'succes_impot_execl' => "0"));
|
|
// exit();
|
|
|
|
// Vérification de certaines erreurs :
|
|
|
|
// 1 => doublons codeMedicament
|
|
$codeMedicamentDoublon = $this->tarif->getdoubloncodemedicament($idTarif);
|
|
if ($codeMedicamentDoublon>"0")
|
|
{
|
|
$this->genererVueAjax(array('message_erreur_excel' => "codeMedicament " . $codeMedicamentDoublon . " => Doublon !", '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 incorporermedicamentsimportes()
|
|
{
|
|
$this->tarif->incorporermedicamentsimportes();
|
|
|
|
// $this->genererVueAjax();
|
|
}
|
|
|
|
public function majetape()
|
|
{
|
|
$idTarif = $this->requete->getParametreFormulaire("idTarif");
|
|
$this->tarif->majetape($idTarif);
|
|
}
|
|
} |