array('title' => 'CHIFFRE D\'AFFAIRES', 'div' => 1000, 'unit' => ' K€', 'evolution' => 'r6' ), 'r7' => array('title' => 'RESULTAT COURANT AVANT IMPOTS', 'div' => 1000, 'unit' => ' K€', 'evolution' => 'r8' ), 'r10' => array('title' => 'RESULTAT NET', 'div' => 1000, 'unit' => ' K€', 'evolution' => 'r11' ), 'r18' => array('title' => 'FONDS PROPRES', 'div' => 1000, 'unit' => ' K€', 'evolution' => 'r19' ), 'r22' => array('title' => 'TOTAL BILAN', 'div' => 1000, 'unit' => ' K€', 'evolution' => 'r23' ), 'r231' => array('title' => 'FONDS DE ROULEMENT', 'div' => 1000, 'unit' => ' K€', 'evolution' => 'r235'), 'r232' => array('title' => 'BESOIN EN FONDS DE ROULEMENT', 'div' => 1000, 'unit' => ' K€', 'evolution' => 'r236'), 'r249' => array('title' => 'TRESORERIE', 'div' => 1000, 'unit' => ' K€', 'evolution' => 'r254'), 'r24' => array('title' => 'EFFECTIF', 'div' => 1, 'unit' => ' Pers.', 'evolution' => 'r24' ) ); protected $datas = array(); protected $structure = array(); private $resultats; private $evolutionsArray; /** * Merci de passer l'objet a ce niveau : BilansInfos->item * * @param unknown_type $resultats */ public function __construct($resultats, $evolutions) { $this->resultats = $resultats; $this->evolutionsArray = $evolutions; } /** * A utiliser avec précaution ! * * format : 'id' => array(title => '', div => '', unit => '', evolution => '') * @param Array $element */ public function addInRatioTab($id, $element) { $tab = array($id => $element); $copy = $this->tabRatio; $this->tabRatio = array_merge($copy, $tab); } public function constructStructure() { self::constructBaseLibele(); foreach ($this->datas as $libele => $title) { foreach ($this->resultats as $item) foreach ($item as $row) { foreach($row as $champ => $valeur) { if ($champ == 'dateCloture'){ $date = $valeur; self::constructBaseDate($libele, $valeur); } if ($champ == 'typeBilan') { self::constructBaseType($libele, $date, $valeur); } } } } print_r($this->datas); } /** * Construction du premier etage Libeler */ private function constructBaseLibele() { foreach ($this->tabRatio as $libel => $valeur) { $this->datas[$valeur['title']] = array(); } } /** * Construction du deuxieme etage Dates * * @param $libeler precedent $libele * @param date courente $date */ private function constructBaseDate($libel, $date) { if(!array_key_exists($date, $this->datas)) { $this->datas[$libel][$date] = array(); } } /** * Construction du troisieme etage Type * * @param libele precedent $libele * @param date precedente $date * @param type en cours $type */ private function constructBaseType($libele, $date, $type) { foreach ($this->resultats as $row) { foreach($row as $champ => $valeur) { if ($champ == 'dateCloture') { if ($valeur == $date) { $this->datas[$libele][$valeur][$type] = array(); } } } } } /** * Construction du quatrieme etage Items * * @param libele precedent $libele * @param date precedente $date * @param type precedent $type * @param item precedent $item * @param id de l'item dans le tabRatio $id * @param id evolution dans tabRatio $idEvol */ private function constructBaseItem($libele, $date, $type, $item, $id, $idEvol) { if ($item->id == $id) { $var = new stdClass(); $var->val = $item->val; foreach ($this->evolutionsArray as $evol) { if ($evol->id == $idEvol) $var->evolution = $item->val; } $this->datas[$libele][$date][$type] = $var; } } } Class Synthese { /** * Type du bilan N, C, A, S, B * * N : Normal * C : Consolidé * A : Assurance * B : Banque * S : Simplifié * * Ont garde une priorité sur les bilan de type S donc les type N deviennent type S ! * Donc il n'y a pas de type N dans la vue. * * @var unknown_type */ protected $typeBilan = array( 'N', 'C', 'A', 'B' ); /** * Les données correctement formaté par FormatData * * @var unknown_type */ protected $datas; /** * Les parametres courrant de l'objet * * @var unknown_type */ protected $currentTypeBilan; protected $currentDate; public function __construct($resultats, $evolutions) { $this->data = new FormatDatas($resultats, $evolutions); $this->data->constructStructure(); } /** * Permet de retourner des elements du tableau * peut egalement savoir si l'element existe dans le tableau * * @param unknown_type $id * @param unknown_type (existe, title, div, unit, evolution) */ public function getElementInSynthese($id, $action) { foreach ($this->tabRatio as $name => $element) { if ($name == $id) { switch ($action){ case 'exist': return (true); case 'title': return($element['title']); case 'div': return ($element['div']); case 'unit': return ($element['unit']); case 'evolution': return ($element['evolution']); default: return ($element); } } } return (false); } /** * Permet de switcher entre les bilans * * @param unknown_type $type */ protected function selectTypeBilan($type) { foreach($this->typeBilan as $typeBilan) { if ($typeBilan == $type) $this->currentTypeBilan = $type; } } /** * Permet de selectionnez d'autre dates. * * @param unknown_type $date */ protected function selectDateBilan($date) { $this->currentDate = $date; } }