extranet/library/Scores/Finance/Liasse/XLS.php
2017-03-07 14:50:28 +01:00

125 lines
3.5 KiB
PHP

<?php
class Scores_Finance_Liasse_XLS
{
protected $path;
protected $mode;
protected $modele;
protected $writerMode = array(
'Excel5' => '.xls',
'Excel2007' => '.xlsx',
);
protected $assoc = array();
protected $values = array();
/**
*
* Enter description here ...
* @param string $modele
* Nom du modèle
* @param string $mode
* Type de fichier excel pour l'ecriture (Excel5 | Excel2007)
*/
public function __construct($modele = '', $mode = 'Excel5')
{
$c = Zend_Registry::get('config');
$this->path = $c->profil->path->shared . '/files/';
if (!is_dir($this->path)){
mkdir($this->path);
}
$this->modele = $modele;
if (empty($this->modele)){
$this->modele = 'bdf_liasse_template';
}
$this->mode = $mode;
}
public function dataModel($siren, $raisonSociale, $values)
{
switch($this->modele)
{
case 'bdf_liasse_template':
//Ajout champs spéciaux
$values['TEXTE_SIRET'] = 'Siret : '.$siren;
$values['TEXTE_RS'] = 'Société : '.$raisonSociale;
$values['TEXTE_DATEN'] = 'Date de clôture : le ' .
substr($values['DATE_CLOTURE'],6,2) . '/' .
substr($values['DATE_CLOTURE'],4,2) . '/' .
substr($values['DATE_CLOTURE'],0,4) .
' sur ' . $values['DUREE_MOIS'] . ' mois';
break;
//Bilan Normal Cerfa
case 'liasse_2050':
$values['TEXTE_SIRET'] = $siren;
$values['TEXTE_RS'] = $raisonSociale;
$values['TEXTE_DATEN'] =
substr($values['DATE_CLOTURE'],6,2) . '/' .
substr($values['DATE_CLOTURE'],4,2) . '/' .
substr($values['DATE_CLOTURE'],0,4);
$values['TEXTE_DATEN1'] =
substr($values['DATE_CLOTURE_PRE'],6,2) . '/' .
substr($values['DATE_CLOTURE_PRE'],4,2) . '/' .
substr($values['DATE_CLOTURE_PRE'],0,4);
$values['TEXTE_DUREEN'] = $values['DUREE_MOIS'];
$values['TEXTE_DUREEN1'] = $values['DUREE_MOIS_PRE'];
break;
//Bilan Simplifié Cerfa
case 'liasse_2033':
$values['TEXTE_SIRET'] = $siren;
$values['TEXTE_RS'] = $raisonSociale;
$values['TEXTE_DATEN'] =
substr($values['DATE_CLOTURE'],6,2) . '/' .
substr($values['DATE_CLOTURE'],4,2) . '/' .
substr($values['DATE_CLOTURE'],0,4);
$values['TEXTE_DATEN1'] =
substr($values['DATE_CLOTURE_PRE'],6,2) . '/' .
substr($values['DATE_CLOTURE_PRE'],4,2) . '/' .
substr($values['DATE_CLOTURE_PRE'],0,4);
$values['TEXTE_DUREEN'] = $values['DUREE_MOIS'];
$values['TEXTE_DUREEN1'] = $values['DUREE_MOIS_PRE'];
break;
}
//Association
$dataAssoc = parse_ini_file(realpath(dirname(__FILE__)).'/models/'.$this->modele.'.ini', true);
$assoc = array();
foreach($dataAssoc as $sheet => $dataCell)
{
foreach($dataCell as $key => $cell)
{
$assoc[$key] = array($sheet, $cell);
}
}
$this->assoc = $assoc;
$this->values = $values;
}
public function dataFile($file)
{
$objPHPexcel = PHPExcel_IOFactory::load(realpath(dirname(__FILE__)).'/models/'.$this->modele.'.xls');
foreach( $this->assoc as $key => $position )
{
$sheet = $position[0];
$cell = $position[1];
if (array_key_exists($key, $this->values))
{
$objWorksheet = $objPHPexcel->getSheet($sheet);
$objWorksheet->getCell($cell)->setValue($this->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, $this->mode);
$objWriter->save($this->path.'/'.$file);
}
}
?>