extranet/includes/liasse/liassexls.php
2010-11-26 15:33:00 +00:00

115 lines
3.3 KiB
PHP

<?php
set_time_limit(120);
$writerMode = array('Excel5', 'Excel2007');
if (!isset($writerType) || !in_array($writerType, $writerMode))
{
$writerType = 'Excel5';
}
switch($writerType)
{
case 'Excel5':
$extension = '.xls';
break;
case 'Excel2007':
$extension = '.xlsx';
break;
}
$xlsWriteFile = PATH_SITE . '/cache/liasse/' . $fileName . $extension;
if( !file_exists($xlsWriteFile) )
{
$values = $tabBilan;
if (!isset($element) || empty($element)){
$element = 'bdf_liasse_template';
}
switch($element)
{
case 'bdf_liasse_template':
//Ajout champs spéciaux
$values['TEXTE_SIRET'] = 'Siret : '.$tabBilan['SIREN'];
$values['TEXTE_RS'] = 'Société : '.$_SESSION['tabInfo']['entrep']['raisonSociale'];
$values['TEXTE_DATEN'] = 'Date de clôture : le ' .
substr($tabBilan['DATE_CLOTURE'],6,2) . '/' .
substr($tabBilan['DATE_CLOTURE'],4,2) . '/' .
substr($tabBilan['DATE_CLOTURE'],0,4) .
' sur ' . $tabBilan['DUREE_MOIS'] . ' mois';
break;
//Bilan Normal Cerfa
case 'liasse_2050':
$values['TEXTE_SIRET'] = $tabBilan['SIREN'];
$values['TEXTE_RS'] = $_SESSION['tabInfo']['entrep']['raisonSociale'];
$values['TEXTE_DATEN'] =
substr($tabBilan['DATE_CLOTURE'],6,2) . '/' .
substr($tabBilan['DATE_CLOTURE'],4,2) . '/' .
substr($tabBilan['DATE_CLOTURE'],0,4);
$values['TEXTE_DUREEN'] = $tabBilan['DUREE_MOIS'];
$values['TEXTE_DUREEN1'] = $tabBilan['DUREE_MOIS_PRE'];
break;
//Bilan Simplifié Cerfa
case 'liasse_2033':
$values['TEXTE_SIRET'] = $tabBilan['SIREN'];
$values['TEXTE_RS'] = $_SESSION['tabInfo']['entrep']['raisonSociale'];
$values['TEXTE_DATEN'] =
substr($tabBilan['DATE_CLOTURE'],6,2) . '/' .
substr($tabBilan['DATE_CLOTURE'],4,2) . '/' .
substr($tabBilan['DATE_CLOTURE'],0,4);
$values['TEXTE_DATEN1'] =
substr($tabBilan['DATE_CLOTURE_PRE'],6,2) . '/' .
substr($tabBilan['DATE_CLOTURE_PRE'],4,2) . '/' .
substr($tabBilan['DATE_CLOTURE_PRE'],0,4);
$values['TEXTE_DUREEN'] = $tabBilan['DUREE_MOIS'];
$values['TEXTE_DUREEN1'] = $tabBilan['DUREE_MOIS_PRE'];
break;
}
$iniFile = $element.'.ini';
$xlsFile = $element.'.xls';
//Association
$dataAssoc = parse_ini_file(realpath(dirname(__FILE__)).'/'.$iniFile, true);
$assoc = array();
foreach($dataAssoc as $sheet => $dataCell)
{
foreach($dataCell as $key => $cell)
{
$assoc[$key] = array($sheet, $cell);
}
}
//Ecriture dans modèles
require_once 'lib/phpexcel/PHPExcel.php';
$objPHPexcel = PHPExcel_IOFactory::load(realpath(dirname(__FILE__)).'/'.$xlsFile);
foreach( $assoc as $key => $position )
{
$sheet = $position[0];
$cell = $position[1];
if (array_key_exists($key, $values))
{
$objWorksheet = $objPHPexcel->getSheet($sheet);
$objWorksheet->getCell($cell)->setValue($values[$key]);
}
/*
else
{
$objWorksheet = $objPHPexcel->getSheet($sheet);
$objWorksheet->getCell($cell)->setValue('_');
//echo "La clé $key n'a pas de valeur!<br/>";
}
*/
}
$objPHPexcel->setActiveSheetIndex(0);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPexcel, $writerType);
$objWriter->save($xlsWriteFile);
}
if( file_exists($xlsWriteFile) )
{
$client->setLog('liassexls', $siren, 0, '');
echo '<a href="fichier/liasse/'.basename($xlsWriteFile).
'" target="_blank">Télécharger le fichier excel.</a>';
}
else
{
echo "Erreur lors de la construction du fichier.";
}
?>