9f295ce6f2
Optimisation du code a faire + le formulaire de gestion des type de bilan elle ne gere pour le moment que les bilan de type N...
498 lines
20 KiB
PHP
498 lines
20 KiB
PHP
<?php
|
|
require_once ('common/dates.php');
|
|
require_once ('Scores/SessionEntreprise.php');
|
|
require_once ('finance/synthese.lib.php');
|
|
require_once ('Scores/WsScores.php');
|
|
require_once ('ChartDirector/phpchartdir.php');
|
|
|
|
class FinanceController extends Zend_Controller_Action
|
|
{
|
|
private $ws;
|
|
private $entreprise;
|
|
private $dateFunction;
|
|
private $graphiqueRatio = array();
|
|
|
|
public function init()
|
|
{
|
|
$this->entreprise = new stdClass();
|
|
$this->dateFunction = new WDate();
|
|
$this->ws = new WsScores();
|
|
$entreprise = new SessionEntreprise($this->getRequest()->getParam('siret'), $this->getRequest()->getParam('id'));
|
|
$this->entreprise->nom = $entreprise->getRaisonSociale();
|
|
$this->entreprise->siret = $this->getRequest()->getParam('siret');
|
|
$this->entreprise->naf = $entreprise->getNaf();
|
|
|
|
$this->view->headLink()->appendStylesheet('/themes/default/styles/finance.css', 'all');
|
|
$this->view->headScript()
|
|
->appendFile('/themes/default/scripts/finance.js', 'text/javascript');
|
|
|
|
$this->view->assign('dateFunction', $this->dateFunction);
|
|
}
|
|
|
|
/* --------------------------------------------------------------------------------------------------- */
|
|
/* Gestion de la synthése avec le graphique */
|
|
/* ----------------------------------------------------------------------------------------------------*/
|
|
|
|
public function syntheseAction()
|
|
{
|
|
|
|
$bilanN = array();
|
|
$bilanC = array();
|
|
$bilanReference = array('r5' => array('evolution' => 'r6' , 'unite' => 'EUR', 'operateur' => 1000, 'name' => 'CHIFFRE D\'AFFAIRES'),
|
|
'r7' => array('evolution' => 'r8' , 'unite' => 'EUR', 'operateur' => 1000, 'name' => 'RESULTAT COURANT AVANT IMPOTS'),
|
|
'r10' => array('evolution' => 'r11' , 'unite' => 'EUR', 'operateur' => 1000, 'name' => 'RESULTAT NET'),
|
|
'r18' => array('evolution' => 'r19' , 'unite' => 'EUR', 'operateur' => 1000, 'name' => 'FONDS PROPRES'),
|
|
'r22' => array('evolution' => 'r23' , 'unite' => 'EUR', 'operateur' => 1000, 'name' => 'TOTAL BILAN'),
|
|
'r231' => array('evolution' => 'r235', 'unite' => 'EUR', 'operateur' => 1000, 'name' => 'FONDS DE ROULEMENT'),
|
|
'r232' => array('evolution' => 'r236', 'unite' => 'EUR', 'operateur' => 1000, 'name' => 'BESOIN EN FONDS DE ROULEMENT'),
|
|
'r249' => array('evolution' => 'r254', 'unite' => 'EUR', 'operateur' => 1000, 'name' => 'TRESORERIE'),
|
|
'r24' => array('evolution' => 'r24' , 'unite' => 'Pers.', 'operateur' => 1, 'name' => 'EFFECTIF')
|
|
);
|
|
$request = $this->getRequest();
|
|
$synthese = $this->ws->getRatios(substr($request->getParam('siret'), 0, 9), 'synthese');
|
|
|
|
foreach ($synthese->BilansInfos->item as $item) {
|
|
if ($item->typeBilan == 'N')
|
|
{
|
|
foreach ($item->RatiosEntrep->item as $RatiosEntrep) {
|
|
foreach ($bilanReference as $id => $params) {
|
|
if ($RatiosEntrep->id == $id)
|
|
{
|
|
$bilanN[$id]['name'] = $params['name'];
|
|
$bilanN[$id]['unite'] = $params['unite'];
|
|
if (count($bilanN[$id]['item']) <= 2) {
|
|
if (is_numeric($RatiosEntrep->val))
|
|
$valeur = number_format(($RatiosEntrep->val/$params['operateur']), 0, '', ' ');
|
|
$bilanN[$id]['item'][substr($item->dateCloture, 0, 4)]['ValEntrep'] = $valeur;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
foreach ($item->RatiosEntrepEvol->item as $RatiosEntrepEvol) {
|
|
foreach ($bilanReference as $id => $params) {
|
|
if ($RatiosEntrepEvol->id == $params['evolution']) {
|
|
if (array_key_exists(substr($item->dateCloture, 0, 4), $bilanN[$id]['item']))
|
|
$bilanN[$id]['item'][substr($item->dateCloture, 0, 4)]['ValEntrepEvol'] = $RatiosEntrepEvol->val;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
foreach ($bilanN as $id => $val)
|
|
ksort($bilanN[$id]['item']);
|
|
|
|
$this->view->assign('raisonSociale', $this->entreprise->nom);
|
|
$this->view->assign('siret', $request->getParam('siret'));
|
|
$this->view->assign('synthese', $bilanN);
|
|
}
|
|
|
|
public function bilansAction()
|
|
{
|
|
/*$bilan = $this->ws->getBilan(substr($this->entreprise->siret, 0, 9), $millesime, $typeBilan, $ref);
|
|
$this->view->assign('bilan', */
|
|
}
|
|
/* --------------------------------------------------------------------------------------------------- */
|
|
/* Gestion des ratios avec les graphiques */
|
|
/* ----------------------------------------------------------------------------------------------------*/
|
|
/**
|
|
* Permet de formater correctement les données.
|
|
*
|
|
* @param type d'unite $unite
|
|
* @param la valeur a transcrire $valeur
|
|
*/
|
|
protected function parseUnite($unite, $valeur)
|
|
{
|
|
switch ($unite)
|
|
{
|
|
case 'EUR':
|
|
return (number_format((round($valeur)/1000), 0, '', ' '));
|
|
case '%':
|
|
return (round($valeur));
|
|
case 'Jours':
|
|
return ($valeur);
|
|
default:
|
|
return ($valeur);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Permet de determiner si ont crée l'image ou s'il elle existe daja dans une periode de 8 heures MAX.
|
|
*
|
|
* @param nom de l'image $name
|
|
*/
|
|
protected function checkIfImageExist($name)
|
|
{
|
|
$path = APPLICATION_PATH.'/../cache/pages/imgcache/';
|
|
|
|
if (file_exists($path.$name.'.png')) {
|
|
$date = date('Ymdh', filemtime($path.$name.'.png'));
|
|
if($date + 8 > date('Ymdh'))
|
|
return (false);
|
|
else
|
|
return (true);
|
|
}
|
|
return (false);
|
|
}
|
|
|
|
/**
|
|
* Cette fonction permet de comparer les donnée entre elles pour determiner l'evolution
|
|
* positive ou négative, ( j'ai respecté les consigne apppliqué préalablement sur l'ancien Extranet.
|
|
*
|
|
* @param Objet $valeurEnt
|
|
* @param Objet $valeurSec
|
|
* @param string (le signe de comparaison) $compare
|
|
*/
|
|
protected function compareValeur($valeurEnt, $valeurSec, $compare)
|
|
{
|
|
$ecart = 1/100;
|
|
|
|
if( $valeurSec=='NS' || $valeurEnt == 'NS' || $valeurSec==NULL || $valeurEnt==NULL) {
|
|
return ('-');
|
|
} else if ($compare == '>') {
|
|
if (($valeurEnt + $ecart) > $valeurSec) {
|
|
$return = '<img src="/themes/default/images/finance/ratios_bon.png" />';
|
|
} elseif( ($valeurSec - ($valeurSec * $ecart)) < $valeurEnt && ($valeurSec + ($valeurSec * $ecart)) > $valeurEnt) {
|
|
$return = '-';
|
|
} else {
|
|
$return = '<img src="/themes/default/images/finance/ratios_mauvais.png" />';
|
|
}
|
|
} else if ($compare == '<') {
|
|
if (($valeurEnt + $ecart) > $valeurSec) {
|
|
$return = '<img src="/themes/default/images/finance/ratios_bon.png" />';
|
|
} elseif( ($valeurSec - ($valeurSec * $ecart)) < $valeurEnt && ($valeurSec + ($valeurSec * $ecart)) > $valeurEnt) {
|
|
$return = '-';
|
|
} else {
|
|
$return = '<img src="/themes/default/images/finance/ratios_mauvais.png" />';
|
|
}
|
|
}
|
|
return ($return);
|
|
}
|
|
|
|
/**
|
|
* Permet d'afficher les elements par block avec un titre.
|
|
*
|
|
* @param Le tableau de reference des ID a afficher $tableau
|
|
* @param Le nom du block en traitement $name
|
|
* @param Les elements de Ratios $element
|
|
* @param L'adresse de la variable $html
|
|
* @param l'object ratio $ratios
|
|
* @param la date du block $date
|
|
*/
|
|
protected function printElementRatio($tableau, $name, $element, &$html, $ratios, $date)
|
|
{
|
|
foreach($tableau[$name] as $row => $val) {
|
|
if ($row == $element->id) {
|
|
foreach ($ratios->RatiosInfos->item as $item) {
|
|
if ($item->id == $element->id) {
|
|
foreach ($ratios->RatiosSecteur->item as $Secteur) {
|
|
if (substr($date, 0, 4) == $Secteur->annee) {
|
|
foreach ($Secteur->liste->item as $liste) {
|
|
if ($item->id == $liste->id) {
|
|
if (self::checkIfImageExist($liste->id))
|
|
self::createGraphique($ratios, $liste->id, $item->unite, $liste->id);
|
|
$html .= '<tr>';
|
|
$html .= '<td>'.$item->libelle.'</td>';
|
|
$html .= '<td class="right">'.self::parseUnite($item->unite, $element->val).' '.$item->unite.'</td>';
|
|
$html .= '<td class="right">'.self::parseUnite($item->unite, $liste->val).' '.$item->unite.'</td>';
|
|
$html .= '<td align="center">';
|
|
$html .= '<a name="'.$item->libelle.'" class="rTip" rel="'.$this->view->url(array('controller' => 'finance',
|
|
'action' => 'printgraph',
|
|
'idGraph' => $liste->id.'.png')).'" href="">'.self::compareValeur($element->val, $liste->val, $val).'</a>';
|
|
$html .= '</td>';
|
|
$html .= '</tr>';
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Apelle la view avec la balise image, j'ai désactivé le layout pour un affichage spécial.
|
|
*/
|
|
public function printgraphAction()
|
|
{
|
|
$this->_helper->layout()->disableLayout();
|
|
$filename = $this->getRequest()->getParam('idGraph');
|
|
$this->view->assign('filename', $filename);
|
|
}
|
|
|
|
/**
|
|
* Permet de mettres les clefs du tableau sous forme indexé pour ChartDirector
|
|
* @param array $tableau
|
|
*/
|
|
protected function initTableau($tableau)
|
|
{
|
|
$i = 0;
|
|
|
|
foreach($tableau as $date => $valeur){
|
|
$tableau[$i] = $valeur;
|
|
unset($tableau[$date]);
|
|
$i++;
|
|
}
|
|
return ($tableau);
|
|
}
|
|
|
|
/**
|
|
* Permet de calculer avec les unité fournies ( exemple 1 000 000 = 1 000 000 / 1000 (EUR) )
|
|
*
|
|
* @param la valeur $valeur
|
|
* @param l'unité $unite
|
|
*/
|
|
protected function setUnite($valeur, $unite)
|
|
{
|
|
switch ($unite) {
|
|
case 'EUR':
|
|
return ($valeur = $valeur / 1000);
|
|
default:
|
|
return ($valeur);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Cette fonction permet de créer les abscisses pour les données, en l'ocurence elle gére Entreprise et Secteur
|
|
*
|
|
* @param le type de courbe $type
|
|
* @param l'unité de l'information $unite
|
|
* @param l'object ratio $ratio
|
|
* @param le tableau a formater $dataX
|
|
* @param id de l'element courant $id
|
|
* @param l'adresse du tableau de label $labelX
|
|
*/
|
|
protected function createAbscisse($type, $unite, $ratio, $dataX, $id, &$labelX = null)
|
|
{
|
|
$i = 0;
|
|
|
|
if ($type == 'RatiosEntrep') {
|
|
foreach ($ratio->BilansInfos->item as $element) {
|
|
if ($i >= 5)
|
|
break;
|
|
if (is_array($labelX))
|
|
$labelX[] = substr($element->dateCloture, 0, 4);
|
|
//$dataX[substr($element->dateCloture, 0, 4)] = array();
|
|
foreach ($element->RatiosEntrep->item as $ratioEntre) {
|
|
if ($ratioEntre->id == $id) {
|
|
$dataX[substr($element->dateCloture, 0, 4)] = self::setUnite($ratioEntre->val, $unite);$i++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if ($type == 'RatiosSecteur') {
|
|
foreach ($ratio->RatiosSecteur->item as $element) {
|
|
if($i >= 5)
|
|
break;
|
|
foreach($element->liste->item as $item) {
|
|
if ($item->id == $id) {
|
|
$dataX[$element->annee] = self::setUnite($item->val, $unite);$i++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (is_array($labelX))
|
|
sort($labelX);
|
|
ksort($dataX);
|
|
$dataX = self::initTableau($dataX);
|
|
|
|
return ($dataX);
|
|
}
|
|
|
|
/**
|
|
* Cette fonction crée le graphique et le stock dans cache/imgcache.
|
|
*
|
|
* @param l'objet ratio $ratio
|
|
* @param id de l'element courant $id
|
|
* @param l'unité courante $unite
|
|
* @param l'id qui servira de nom pour l'image $filename
|
|
*/
|
|
protected function createGraphique($ratio, $id, $unite, $filename)
|
|
{
|
|
$labelX = array();
|
|
$labelY = array();
|
|
$dataX1 = array();
|
|
$dataX2 = array();
|
|
$path = APPLICATION_PATH. '/../cache/pages/imgcache/';
|
|
$file = $filename.'.png';
|
|
$dataX1 = self::createAbscisse('RatiosEntrep', $unite, $ratio, $dataX1, $id, $labelX);
|
|
$dataX2 = self::createAbscisse('RatiosSecteur', $unite, $ratio, $dataX2, $id);
|
|
$c = new XYChart(350, 250);
|
|
|
|
$c->setPlotArea(55, 10, 280, 200);
|
|
$c->yAxis->setTitle($unite);
|
|
$c->xAxis->setTitle("Années");
|
|
$c->xAxis->setWidth(2);
|
|
$c->yAxis->setWidth(2);
|
|
$legendObj = $c->addLegend(50, 10, false, "times.ttf", 9);
|
|
$legendObj->setBackground(Transparent);
|
|
$c->addLineLayer($dataX1, 0x0000ff, "Entreprise");
|
|
$c->addLineLayer($dataX2, 0x008C00, "Secteur");
|
|
$c->yAxis->setLabels($labelY);
|
|
$c->yAxis->setLabelStep(10);
|
|
$c->xAxis->setLabels($labelX);
|
|
$c->makeChart($path.$file);
|
|
$return = '/fichier/imgcache/'.$file;
|
|
|
|
return ($return);
|
|
}
|
|
|
|
/**
|
|
* Gestion de l'affichage des ratios.
|
|
*/
|
|
public function ratiosAction()
|
|
{
|
|
/**
|
|
* Ont ajoute de nouveaux ratios a cette endroit
|
|
* @var unknown_type
|
|
*/
|
|
$tableau = array('EquilibreFinancier' => array('r233' => '>', 'r234' => '>', 'r237' => '>', 'r238' => '>', 'r239' => '>', 'r240' => '>'),
|
|
'Profitabilite' => array('r262' => '>', 'r263' => '>', 'r264' => '>', 'r265' => '>', 'r266' => '>'),
|
|
'Liquidite' => array('r250' => '>', 'r251' => '>', 'r252' => '>'),
|
|
'Endetement' => array('r241' => '<', 'r247' => '<', 'r248' => '<'),
|
|
'Productivite' => array('r271' => '>', 'r278' => '<', 'r279' => '<', 'r281' => '<', 'r261' => '>', 'r267' => '>')
|
|
);
|
|
|
|
$tab = array();
|
|
$siret = $this->getRequest()->getParam('siret');
|
|
$id = $this->getRequest()->getParam('id');
|
|
$i = 0;
|
|
$listeDate = array();
|
|
$request = $this->getRequest();
|
|
$date = $this->getRequest()->getParam('Date');
|
|
$type = $this->getRequest()->getParam('typeBilan');
|
|
$html = '';
|
|
|
|
$ratios = $this->ws->getRatios(substr($this->getRequest()->getParam('siret'), 0, 9), 'ratios');
|
|
|
|
//echo '<pre>';print_r($ratios);echo '</pre>';exit;
|
|
foreach($ratios->BilansInfos->item as $elements) {
|
|
//if ($i > 5)break;
|
|
$tab[$elements->dateCloture][$elements->typeBilan] = $elements;
|
|
$i++;
|
|
}
|
|
|
|
foreach ($tab as $champDate => $valeur)
|
|
$listeDate[] = $champDate;
|
|
|
|
if (isset($date)) {
|
|
if (!empty($date)) {
|
|
foreach ($tableau as $name => $valeur) {
|
|
$html .= '<tr class="subhead">
|
|
<td align="center">'.$name.'</td>
|
|
<td>Entreprise</td>
|
|
<td>Secteur</td>
|
|
<td>Position</td>
|
|
</tr>';
|
|
foreach ($tab[$date][$type]->RatiosEntrep->item as $element)
|
|
self::printElementRatio($tableau, $name, $element, $html, $ratios, $date);
|
|
}
|
|
}
|
|
}
|
|
$i = 0;
|
|
|
|
/** Gestion de la vue **/
|
|
$this->view->assign('i', $i);
|
|
$this->view->assign('html', $html);
|
|
$this->view->assign('raisonSociale', $this->entreprise->nom);
|
|
$this->view->assign('siret', $siret);
|
|
$this->view->assign('id', $id);
|
|
$this->view->assign('ratios', $tab);
|
|
$this->view->assign('naf', $this->entreprise->naf);
|
|
}
|
|
|
|
/* --------------------------------------------------------------------------------------------------- */
|
|
/* Gestion des liasses fiscales */
|
|
/* ----------------------------------------------------------------------------------------------------*/
|
|
|
|
private function selectInUnit($tab, $unite)
|
|
{
|
|
foreach($tab as $champ => $val) {
|
|
if($val == $unite)
|
|
return ($champ);
|
|
}
|
|
return (false);
|
|
}
|
|
|
|
public function liasseAction()
|
|
{
|
|
$ancres = array('C' => array('actif', 'passif', 'compteDeResultat'),
|
|
'N' => array('actif', 'passif', 'compteDeResultat', 'immobilisations',
|
|
'amortissements', 'provisions', 'creancesDettes',
|
|
'affectation'),
|
|
'A' => array('actif', 'passif', 'compteDeResultat'),
|
|
'B' => array('actif', 'passif', 'compteDeResultat')
|
|
);
|
|
|
|
/** La liste des type de bilan existant **/
|
|
$liste = array ('N' => array(), 'S' => array(),
|
|
'C' => array(), 'B' => array(),
|
|
'A' => array());
|
|
/** Le nom des type pour le select */
|
|
$type = array ('A' => 'Assurance', 'B' => 'Banque',
|
|
'C' => 'Consolidé', 'N' => '');
|
|
/** Liste des unités que l'ont proposent **/
|
|
$unit = array ('€' => 1, 'K€' => 1000,
|
|
'M€' => 1000000);
|
|
$liasse = array ();
|
|
$date = $this->getRequest()->getParam('date');
|
|
$siret = $this->getRequest()->getParam('siret');
|
|
$id = $this->getRequest()->getParam('id');
|
|
$listBilan = $this->ws->getListeBilans(substr($this->getRequest()->getParam('siret'), 0, 9));
|
|
$unite = $this->getRequest()->getParam('unit');
|
|
|
|
foreach ($listBilan->result->item as $item)
|
|
$liste[$item->typeBilan][] = $item->dateExercice;
|
|
|
|
/** ont transforme les bilan de type S en N **/
|
|
$NandS = array_merge($liste['N'], $liste['S']);
|
|
$liste['N'] = $NandS;unset($liste['S']);
|
|
|
|
if (!empty($date)) {
|
|
$dateAndType = explode(':', $date);
|
|
$liasses = $this->ws->getBilan(substr($this->getRequest()->getParam('siret'), 0, 9), $dateAndType[0], $dateAndType[1], true);
|
|
|
|
$this->view->assign('dateCloture', $liasses->DATE_CLOTURE);
|
|
$this->view->assign('dateCloturePre', $liasses->DATE_CLOTURE_PRE);
|
|
$this->view->assign('dureesMois', $liasses->DUREE_MOIS);
|
|
$this->view->assign('dureesMoisPre', $liasses->DUREE_MOIS_PRE);
|
|
|
|
foreach ($liasses->POSTES->item as $element) {
|
|
$liasse[$element->id] =
|
|
number_format(($element->val > 0)?$element->val / $unite:$element->val, 0, '', ' ') .' '.self::selectInUnit($unit, $unite);
|
|
}
|
|
$t = explode(':', $date);
|
|
$this->view->assign('champType', $t[1]);
|
|
$this->view->assign('liasse', $liasse);
|
|
}
|
|
|
|
/** Partie vue **/
|
|
$this->view->assign('ancres', $ancres);
|
|
$this->view->assign('typeFeuille', $typeFeuille);
|
|
$this->view->assign('liste', $liste);
|
|
$this->view->assign('nomSociete', $this->entreprise->nom);
|
|
$this->view->assign('siret', $siret);
|
|
$this->view->assign('id', $id);
|
|
$this->view->assign('type', $type);
|
|
$this->view->assign('unit', $unit);
|
|
}
|
|
|
|
/* --------------------------------------------------------------------------------------------------- */
|
|
/* Gestion des bourses */
|
|
/* ----------------------------------------------------------------------------------------------------*/
|
|
|
|
public function bourseAction()
|
|
{
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------------------------------------- */
|
|
/* Gestion des etablissements bancaires */
|
|
/* ----------------------------------------------------------------------------------------------------*/
|
|
public function banqueAction()
|
|
{
|
|
|
|
}
|
|
} |