From cb2cf69e4e216ea5bc3a5be480653b1339b37057 Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Mon, 11 Mar 2013 17:53:02 +0000 Subject: [PATCH] --- inc/commons/class.common.core.php | 6 +- .../class.extranet.page.chiffres.php | 174 +++++++++++++----- 2 files changed, 133 insertions(+), 47 deletions(-) diff --git a/inc/commons/class.common.core.php b/inc/commons/class.common.core.php index 2fad698ed..79cd427bc 100644 --- a/inc/commons/class.common.core.php +++ b/inc/commons/class.common.core.php @@ -547,7 +547,9 @@ class commonCore extends cubeCore { . 'WHERE factures.projet=projets.projet_id AND clients.utilisateur_id=projets.client AND factures.createur=equipiers.utilisateur_id AND (factures.facture_id>=0 OR factures.status=1) '); $this->views->createView('projets_timereport', 'SELECT * FROM projets_vue WHERE status=0'); $this->views->createView('order_timereport', 'SELECT utilisateur_id,projet AS projet_id,MAX(date) AS derniere_activite FROM timereport,taches,projets WHERE taches.tache_id=timereport.tache_id AND taches.projet=projets.projet_id AND projets.status=0 GROUP BY utilisateur_id,taches.projet ORDER BY utilisateur_id ASC,MAX(date) DESC'); - $this->views->createView('ca', 'SELECT SUM(total_ht) AS ca, YEAR(FROM_UNIXTIME(date_creation)) annee FROM factures WHERE status IN(1,2) GROUP BY annee'); + $this->views->createView('ca', 'SELECT SUM(total_ht) AS ca, YEAR(FROM_UNIXTIME(date_creation)) annee FROM factures WHERE status>0 GROUP BY annee'); + $this->views->createView('cam', 'SELECT SUM(total_ht) AS ca, DATE_FORMAT(FROM_UNIXTIME(date_creation),\'%Y-%m\') mois FROM factures WHERE status>0 GROUP BY mois'); + $this->views->createView('cat', 'SELECT SUM(total_ht) AS ca, CONCAT_WS(\'-\',YEAR(FROM_UNIXTIME(date_creation)),QUARTER(FROM_UNIXTIME(date_creation))) trimestre FROM factures WHERE status>0 GROUP BY trimestre'); $this->views->createView('ftpaccess', 'SELECT email AS userid,password AS passwd,utilisateur_id AS uid,' . '\'1000\' AS gid,CONCAT(\'' . FTPROOT . '\',utilisateur_id) AS homedir, \'/bin/false\' AS shell ' . 'FROM utilisateurs WHERE grade=0 ' @@ -590,7 +592,7 @@ class commonCore extends cubeCore { . 'LEFT JOIN utilisateurs_entreprise r ON d.revendeur=r.utilisateur_id ' . 'LEFT JOIN utilisateurs_entreprise c ON d.utilisateur=c.utilisateur_id ' . 'LEFT JOIN utilisateurs a ON d.administrateur=a.utilisateur_id'); - cubeDb::mysqlConvert($this->con, 'UTF8', 'utf8_general_ci', 'MYISAM'); + //cubeDb::mysqlConvert($this->con, 'UTF8', 'utf8_general_ci', 'MYISAM'); touch($cache); } diff --git a/inc/extranet/Controlleur/class.extranet.page.chiffres.php b/inc/extranet/Controlleur/class.extranet.page.chiffres.php index 7fe2b4883..a63c20add 100644 --- a/inc/extranet/Controlleur/class.extranet.page.chiffres.php +++ b/inc/extranet/Controlleur/class.extranet.page.chiffres.php @@ -1,7 +1,8 @@ getEvents(array($y['start'], $m['end']), '', 0); $e = array(); - foreach($events as $event) { - foreach($event->when as $when) { + foreach ($events as $event) { + foreach ($event->when as $when) { $date = new DateTime($when->starttime); break; } @@ -28,47 +29,45 @@ class extranetPageChiffres { return $e; } - public static function getCharges() - { + public static function getCharges() { $events = self::listeCharges(); $total = 0; - foreach($events as $event) { + foreach ($events as $event) { $total += floatval($event['montant']); } return $total; } - public static function chargesDetails() - { + public static function chargesDetails() { global $core; $events = self::listeCharges(); $i = 0; $total = 0; $res = ''; - foreach($events as $event) { + foreach ($events as $event) { $total += $event['montant']; - $odd = cubeMath::isOdd($i)?' class="odd"':''; + $odd = cubeMath::isOdd($i) ? ' class="odd"' : ''; $res .= '' . $event['title'] . '' . $event['date'] . '' . self::format($event['montant']) . ''; $i++; } - $odd = cubeMath::isOdd($i)?' class="odd"':''; + $odd = cubeMath::isOdd($i) ? ' class="odd"' : ''; $res .= '' . __('Total') . '' . date('Y') . '' . self::format($total) . ''; return $res; } - public static function listeChiffres() - { + public static function listeChiffres() { global $core; commonDroits::min(2); $res = self::chiffresAnnee($encours); $res .= self::caGlobal($chiffres, $total, $encours); + $res.=self::caTrimestre(); + $res.=self::caMensuel(); $res .= self::caCategorie($chiffres, $total); $res .= self::caWorkRate($chiffres, $total); return $res; } - public static function chiffresAnnee(&$encours) - { + public static function chiffresAnnee(&$encours) { global $core; // $charges_payees = self::getCharges(); $r = $core->con->select('SELECT SUM(montant_facture) AS total_factures FROM projets_vue'); @@ -106,8 +105,7 @@ class extranetPageChiffres { return $res; } - public static function caGlobal(&$chiffres, &$total, $encours) - { + public static function caGlobal(&$chiffres, &$total, $encours) { global $core; // Chiffres globaux $r = $core->con->select('SELECT * FROM ca ORDER BY annee ASC'); @@ -121,7 +119,7 @@ class extranetPageChiffres { $res .= self::caChart($chiffres, $encours); $res .= ''; $res .= '' . __("Chiffre d'affaire annuel") . ''; - foreach($chiffres as $annee => $ca) { + foreach ($chiffres as $annee => $ca) { $res .= '' . $annee . ''; } $res .= '' . __('Total') . ''; @@ -129,7 +127,7 @@ class extranetPageChiffres { $res .= ''; $total = 0; - foreach($chiffres as $annee => $ca) { + foreach ($chiffres as $annee => $ca) { $res .= '' . self::format($ca) . ''; $total += $ca; } @@ -141,8 +139,94 @@ class extranetPageChiffres { return $res; } - public static function caCategorie($chiffres, $total) - { + public static function caTrimestre() { + global $core; + // Chiffres globaux + $r = $core->con->select('SELECT * FROM cat ORDER BY trimestre DESC'); + $chiffres = array(); + while ($r->fetch()) { + list($annee, $trimestre) = explode('-', $r->trimestre); + if ($annee < 2009) { + continue; + } + if (!isset($chiffres[$annee])) { + $chiffres[$annee] = array(1 => 0, 2 => 0, 3 => 0, 4 => 0); + } + $chiffres[$annee][$trimestre] = $r->ca; + } + + + $res = commonPage::bh(); + $res .= ''; + $res .= ''; + for ($i = 1; $i <= 4; $i++) { + $res .= ''; + } + $res.=''; + $res .= ''; + + foreach ($chiffres as $annee => $trimestres) { + $res .= ''; + $total = 0; + $res.=''; + foreach ($trimestres as $trimestre => $ca) { + $res .= ''; + $total += $ca; + } + $res.=''; + $res .= ''; + } + + $res .= '
' . __("Chiffre d'affaire trimestriel") . 'T' . $i . '' . __('Total') . '
' . $annee . '' . self::format($ca) . '' . self::format($total) . '
'; + $res .= commonPage::bf(); + return $res; + } + + public static function caMensuel() { + global $core; + // Chiffres globaux + $r = $core->con->select('SELECT * FROM cam ORDER BY mois DESC'); + $chiffres = array(); + while ($r->fetch()) { + list($annee, $mois) = explode('-', $r->mois); + $mois = intval($mois); + if ($annee < 2009) { + continue; + } + if (!isset($chiffres[$annee])) { + $chiffres[$annee] = array(1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 0, 10 => 0, 11 => 0, 12 => 0); + } + $chiffres[$annee][$mois] = $r->ca; + } + + + $res = commonPage::bh(); + $res .= ''; + $res .= ''; + for ($i = 1; $i <= 12; $i++) { + $res .= ''; + } + $res.=''; + $res .= ''; + + foreach ($chiffres as $annee => $moiss) { + $res .= ''; + $total = 0; + $res.=''; + foreach ($moiss as $mois => $ca) { + $res .= ''; + $total += $ca; + } + $res.=''; + $res .= ''; + } + + $res .= '
' . __("Chiffre d'affaire mensuel") . '' . cubeDate::getMonth($i) . '' . __('Total') . '
' . $annee . '' . self::format($ca) . '' . self::format($total) . '
'; + $res .= commonPage::bf(); + return $res; + } + + public static function caCategorie($chiffres, $total) { global $core; // Chiffres par catégorie $chiffresc = array(); @@ -164,26 +248,26 @@ class extranetPageChiffres { $res .= ''; $res .= ''; $res .= ''; - foreach($annees as $annee) { + foreach ($annees as $annee) { $res .= ''; } $res .= ''; $res .= ''; $i = 0; - foreach($chiffresc as $categorie => $tab) { - $odd = (cubeMath::isOdd($i))?' class="odd"':''; + foreach ($chiffresc as $categorie => $tab) { + $odd = (cubeMath::isOdd($i)) ? ' class="odd"' : ''; $res .= ''; $res .= ''; - foreach($annees as $annee) { + foreach ($annees as $annee) { if (isset($tab[$annee])) { $ca = self::format($tab[$annee]); $part = round(($tab[$annee] / $totaux_ca_prev[$annee]) * 100) . '%'; @@ -205,8 +289,7 @@ class extranetPageChiffres { return $res; } - public static function caCategoriesChart($a, $datas, $type, $width, $height, $max = 7) - { + public static function caCategoriesChart($a, $datas, $type, $width, $height, $max = 7) { global $core; $title = sprintf(__('Répartition du CA pour %d'), $a); $chart = new cubeGoogleCharts($type, $width, $height); @@ -215,7 +298,7 @@ class extranetPageChiffres { $total = array_sum($datas); $i = 1; $others = 0; - foreach($datas as $c => $ca) { + foreach ($datas as $c => $ca) { if ($i <= $max) { $chart->addData($ca, null, $core->categories[$c]); $i++; @@ -230,15 +313,14 @@ class extranetPageChiffres { return $chart->display($title); } - public static function caChart($chiffres, $encours) - { + public static function caChart($chiffres, $encours) { global $core; $title = __("*Evolution du chiffre d'affaire"); $chart = new cubeGoogleCharts('bvs', 940, 200); $chart->setTitle($title); $max = 0; - foreach($chiffres as $annee => $ca) { + foreach ($chiffres as $annee => $ca) { if (date('Y') == $annee) { $ca += $encours; } @@ -248,7 +330,7 @@ class extranetPageChiffres { $cac = array(); $cae = array(); - foreach($chiffres as $annee => $ca) { + foreach ($chiffres as $annee => $ca) { $cac[] = round($ca / $ratio); if (date('Y') == $annee) { $cae[] = ($encours / $ratio); @@ -261,8 +343,7 @@ class extranetPageChiffres { return $chart->display($title); } - public static function caWorkRate($chiffres, $total) - { + public static function caWorkRate($chiffres, $total) { global $core; // Temps travaillé / Temps prévu $chiffresc = array(); @@ -280,7 +361,7 @@ class extranetPageChiffres { $res = commonPage::bh(); $res .= '
'; - $a = date('Y')-1; - $res .= self::caCategoriesChart($a, $chiffresa[$a], 'p3' , 440 , 150); + $a = date('Y') - 1; + $res .= self::caCategoriesChart($a, $chiffresa[$a], 'p3', 440, 150); $a++; - $res .= self::caCategoriesChart($a, $chiffresa[$a], 'p3' , 500 , 200); + $res .= self::caCategoriesChart($a, $chiffresa[$a], 'p3', 500, 200); $res .= '
' . __("Chiffre d'affaire par catégorie") . '' . $annee . '' . __('Total') . '
' . $core->categories[$categorie] . '
'; $res .= ''; - foreach($annees as $annee) { + foreach ($annees as $annee) { $total_consomme_annee[$annee] = 0; $total_prevu_annee[$annee] = 0; $res .= ''; @@ -288,14 +369,14 @@ class extranetPageChiffres { $res .= ''; $res .= ''; $i = 0; - foreach($chiffresc as $categorie => $tab) { - $odd = (cubeMath::isOdd($i))?' class="odd"':''; + foreach ($chiffresc as $categorie => $tab) { + $odd = (cubeMath::isOdd($i)) ? ' class="odd"' : ''; $res .= ''; $res .= ''; $total_consomme = 0; $total_prevu = 0; - foreach($annees as $annee) { + foreach ($annees as $annee) { if (isset($tab[$annee])) { $tc = self::format($tab[$annee]['jours_consommes'], false); $tp = self::format($tab[$annee]['jours_prevus'], false); @@ -317,7 +398,7 @@ class extranetPageChiffres { $i++; } $res .= ''; - foreach($annees as $annee) { + foreach ($annees as $annee) { if (isset($total_prevu_annee[$annee]) && isset($total_consomme_annee[$annee])) { $c = $total_consomme_annee[$annee]; $p = $total_prevu_annee[$annee]; @@ -333,18 +414,21 @@ class extranetPageChiffres { return $res; } - public static function format($nb, $euro = true) - { + public static function format($nb, $euro = true, $ifzero = '-') { if ($euro) { $nb = $nb / 1000; } $nb = round($nb); + if ($nb == 0) { + return $ifzero; + } $res = number_format($nb, 0, '.', ' '); if ($euro) { $res .= ' K€'; } return $res; } + } ?> \ No newline at end of file -- 2.39.5
' . __("Rapport Temps travaillé / Temps payé") . '' . $annee . '' . __('Total') . '
' . $core->categories[$categorie] . '
' . __('Total') . '