';
- print '';
- print '';
- print ' ';
if (empty($mode))
{
if ($conf->use_javascript_ajax) print ''.$langs->trans("All").' / '.$langs->trans("None").'';
diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php
index fe32541a0fc..aaebcf697f3 100644
--- a/htdocs/compta/paiement.php
+++ b/htdocs/compta/paiement.php
@@ -705,7 +705,7 @@ if (! GETPOST('action'))
print_liste_field_titre($langs->trans('Date'),$_SERVER["PHP_SELF"],'dp','','','',$sortfield,$sortorder);
print_liste_field_titre($langs->trans('Type'),$_SERVER["PHP_SELF"],'libelle','','','',$sortfield,$sortorder);
print_liste_field_titre($langs->trans('Amount'),$_SERVER["PHP_SELF"],'fa_amount','','','align="right"',$sortfield,$sortorder);
- print_liste_field_titre('');
+ print_liste_field_titre('',$_SERVER["PHP_SELF"],"",'','','',$sortfield,$sortorder,'maxwidthsearch ');
print "\n";
while ($i < min($num,$limit))
@@ -728,6 +728,6 @@ if (! GETPOST('action'))
}
}
-$db->close();
-
llxFooter();
+
+$db->close();
diff --git a/htdocs/compta/paiement/list.php b/htdocs/compta/paiement/list.php
index f2b6bcf1490..d284a128631 100644
--- a/htdocs/compta/paiement/list.php
+++ b/htdocs/compta/paiement/list.php
@@ -68,6 +68,12 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both
$search_company="";
}
+// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
+$hookmanager->initHooks(array('paymentlist'));
+$extrafields = new ExtraFields($db);
+
+
+
/*
* View
*/
@@ -81,24 +87,37 @@ if (GETPOST("orphelins"))
// Paiements lies a aucune facture (pour aide au diagnostic)
$sql = "SELECT p.rowid, p.datep as dp, p.amount,";
$sql.= " p.statut, p.num_paiement,";
- //$sql.= " c.libelle as paiement_type";
$sql.= " c.code as paiement_code";
+ // Add fields for extrafields
+ foreach ($extrafields->attribute_list as $key => $val) $sql.=",ef.".$key.' as options_'.$key;
+ // Add fields from hooks
+ $parameters=array();
+ $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook
+ $sql.=$hookmanager->resPrint;
$sql.= " FROM (".MAIN_DB_PREFIX."paiement as p,";
$sql.= " ".MAIN_DB_PREFIX."c_paiement as c)";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement";
$sql.= " WHERE p.fk_paiement = c.id";
$sql.= " AND p.entity = ".$conf->entity;
$sql.= " AND pf.fk_facture IS NULL";
+ // Add where from hooks
+ $parameters=array();
+ $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook
+ $sql.=$hookmanager->resPrint;
}
else
{
$sql = "SELECT DISTINCT p.rowid, p.datep as dp, p.amount,"; // DISTINCT is to avoid duplicate when there is a link to sales representatives
$sql.= " p.statut, p.num_paiement,";
- //$sql.= " c.libelle as paiement_type,";
$sql.= " c.code as paiement_code,";
$sql.= " ba.rowid as bid, ba.label,";
$sql.= " s.rowid as socid, s.nom as name";
- //$sql.= " f.facnumber";
+ // Add fields for extrafields
+ foreach ($extrafields->attribute_list as $key => $val) $sql.=",ef.".$key.' as options_'.$key;
+ // Add fields from hooks
+ $parameters=array();
+ $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook
+ $sql.=$hookmanager->resPrint;
$sql.= " FROM (".MAIN_DB_PREFIX."c_paiement as c, ".MAIN_DB_PREFIX."paiement as p)";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON p.fk_bank = b.rowid";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid";
@@ -127,6 +146,10 @@ else
if ($search_paymenttype != "") $sql .=" AND c.code='".$db->escape($search_paymenttype)."'";
if ($search_amount) $sql .=" AND p.amount='".$db->escape(price2num($search_amount))."'";
if ($search_company) $sql .= natural_search('s.nom', $search_company);
+ // Add where from hooks
+ $parameters=array();
+ $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook
+ $sql.=$hookmanager->resPrint;
}
$sql.= $db->order($sortfield,$sortorder);
$sql.= $db->plimit($limit+1, $offset);
@@ -157,11 +180,13 @@ if ($resql)
print_liste_field_titre($langs->trans("Account"),$_SERVER["PHP_SELF"],"ba.label","",$paramlist,"",$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Amount"),$_SERVER["PHP_SELF"],"p.amount","",$paramlist,'align="right"',$sortfield,$sortorder);
//print_liste_field_titre($langs->trans("Invoices"),"","","",$paramlist,'align="left"',$sortfield,$sortorder);
- if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION))
- {
- print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"p.statut","",$paramlist,'align="right"',$sortfield,$sortorder);
- }
- print_liste_field_titre('');
+
+ $parameters=array();
+ $reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook
+ print $hookmanager->resPrint;
+
+ if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION)) print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"p.statut","",$paramlist,'align="right"',$sortfield,$sortorder);
+ print_liste_field_titre('',$_SERVER["PHP_SELF"],"",'','','',$sortfield,$sortorder,'maxwidthsearch ');
print "\n";
// Lines for filters fields
@@ -199,7 +224,7 @@ if ($resql)
$var=!$var;
print "
";
- print '
';
+ print '
';
$paymentstatic->id=$objp->rowid;
$paymentstatic->ref=$objp->rowid;
print $paymentstatic->getNomUrl(1);
diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php
index b2e1992f0f9..7f2640fad4a 100644
--- a/htdocs/core/menus/standard/eldy.lib.php
+++ b/htdocs/core/menus/standard/eldy.lib.php
@@ -1194,6 +1194,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu
$newmenu->add("/projet/index.php?leftmenu=projects", $langs->trans("Projects"), 0, $user->rights->projet->lire && $user->rights->projet->lire, '', $mainmenu, 'projects');
$newmenu->add("/projet/card.php?leftmenu=projects&action=create", $langs->trans("NewProject"), 1, $user->rights->projet->creer && $user->rights->projet->creer);
$newmenu->add("/projet/list.php?leftmenu=projects", $langs->trans("List"), 1, $user->rights->projet->lire && $user->rights->projet->lire);
+ $newmenu->add("/projet/stats/index.php?leftmenu=projects", $langs->trans("Statistics"), 1, $user->rights->projet->lire && $user->rights->projet->lire);
if (empty($conf->global->PROJECT_HIDE_TASKS))
{
diff --git a/htdocs/langs/en_US/projects.lang b/htdocs/langs/en_US/projects.lang
index aadd6603853..de6f0fe0576 100644
--- a/htdocs/langs/en_US/projects.lang
+++ b/htdocs/langs/en_US/projects.lang
@@ -158,3 +158,5 @@ AssignTask=Assign
ProjectOverview=Overview
ManageTasks=Use projects to follow tasks and time
ManageOpportunitiesStatus=Use projects to follow leads/opportinuties
+ProjectNbProjectByMonth=Nb of created projects by month
+ProjectsStatistics=Statistics on projects/leads
\ No newline at end of file
diff --git a/htdocs/projet/class/projectstats.class.php b/htdocs/projet/class/projectstats.class.php
new file mode 100644
index 00000000000..27335777db1
--- /dev/null
+++ b/htdocs/projet/class/projectstats.class.php
@@ -0,0 +1,327 @@
+
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+include_once DOL_DOCUMENT_ROOT . '/core/class/stats.class.php';
+include_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
+
+
+class ProjectStats extends Stats
+{
+ protected $db;
+ private $project;
+ public $userid;
+ public $socid;
+ public $year;
+ function __construct($db) {
+ global $conf, $user;
+
+ $this->db = $db;
+
+ require_once 'project.class.php';
+
+ $this->project = new Project($this->db);
+ }
+
+
+ /**
+ * Return all leads grouped by status
+ *
+ * @param int $limit Limit results
+ * @return array|int
+ * @throws Exception
+ */
+ function getAllProjectByStatus($limit = 5)
+ {
+ global $conf, $user, $langs;
+
+ $datay = array ();
+
+ $sql = "SELECT";
+ $sql .= " count(DISTINCT t.rowid), t.fk_opp_status";
+ $sql .= " FROM " . MAIN_DB_PREFIX . "projet as t";
+ $sql .= $this->buildWhere();
+ $sql .= " GROUP BY t.fk_opp_status";
+
+ $result = array ();
+ $res = array ();
+
+ dol_syslog(get_class($this) . '::' . __METHOD__ . "", LOG_DEBUG);
+ $resql = $this->db->query($sql);
+ if ($resql) {
+ $num = $this->db->num_rows($resql);
+ $i = 0;
+ $other = 0;
+ while ( $i < $num ) {
+ $row = $this->db->fetch_row($resql);
+ if ($i < $limit || $num == $limit)
+ $result[$i] = array (
+ $this->projet->status[$row[1]] . '(' . $row[0] . ')',
+ $row[0]
+ );
+ else
+ $other += $row[1];
+ $i ++;
+ }
+ if ($num > $limit)
+ $result[$i] = array (
+ $langs->transnoentitiesnoconv("Other"),
+ $other
+ );
+ $this->db->free($resql);
+ } else {
+ $this->error = "Error " . $this->db->lasterror();
+ dol_syslog(get_class($this) . '::' . __METHOD__ . ' ' . $this->error, LOG_ERR);
+ return - 1;
+ }
+
+ return $result;
+ }
+
+ /**
+ * Return count, and sum of products
+ *
+ * @return array of values
+ */
+ function getAllByYear()
+ {
+ global $conf, $user, $langs;
+
+ $datay = array ();
+
+ $sql = "SELECT date_format(t.datec,'%Y') as year, COUNT(t.rowid) as nb, SUM(t.opp_amount) as total, AVG(t.opp_amount) as avg";
+ $sql .= " FROM " . MAIN_DB_PREFIX . "projet as t";
+ if (! $user->rights->societe->client->voir && ! $user->societe_id)
+ $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON sc.fk_soc=t.fk_soc AND sc.fk_user=" . $user->id;
+ $sql .= $this->buildWhere();
+ $sql .= " GROUP BY year";
+ $sql .= $this->db->order('year', 'DESC');
+
+ return $this->_getAllByYear($sql);
+ }
+ /**
+ *
+ * @return string
+ */
+ public function buildWhere() {
+ $sqlwhere_str = '';
+ $sqlwhere = array ();
+
+ $sqlwhere[] = ' t.entity IN (' . getEntity('project') . ')';
+
+ if (! empty($this->userid))
+ $sqlwhere[] = ' t.fk_user_resp=' . $this->userid;
+ if (! empty($this->socid))
+ $sqlwhere[] = ' t.fk_soc=' . $this->socid;
+ if (! empty($this->year) && empty($this->yearmonth))
+ $sqlwhere[] = " date_format(t.datec,'%Y')='" . $this->year . "'";
+ if (! empty($this->yearmonth))
+ $sqlwhere[] = " t.datec BETWEEN '" . $this->db->idate(dol_get_first_day($this->yearmonth)) . "' AND '" . $this->db->idate(dol_get_last_day($this->yearmonth)) . "'";
+
+ if (! empty($this->status))
+ $sqlwhere[] = " t.fk_opp_status IN (" . $this->status . ")";
+
+ if (count($sqlwhere) > 0) {
+ $sqlwhere_str = ' WHERE ' . implode(' AND ', $sqlwhere);
+ }
+
+ return $sqlwhere_str;
+ }
+
+ /**
+ * Return Project number by month for a year
+ *
+ * @param int $year scan
+ * @return array of values
+ */
+ function getNbByMonth($year) {
+ global $user;
+
+ $this->yearmonth = $year;
+
+ $sql = "SELECT date_format(t.datec,'%m') as dm, COUNT(*) as nb";
+ $sql .= " FROM " . MAIN_DB_PREFIX . "projet as t";
+ if (! $user->rights->societe->client->voir && ! $user->societe_id)
+ $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON sc.fk_soc=t.fk_soc AND sc.fk_user=" . $user->id;
+ $sql .= $this->buildWhere();
+ $sql .= " GROUP BY dm";
+ $sql .= $this->db->order('dm', 'DESC');
+
+ $this->yearmonth=0;
+
+ $res = $this->_getNbByMonth($year, $sql);
+ // var_dump($res);print ' ';
+ return $res;
+ }
+
+ /**
+ * Return the Project amount by month for a year
+ *
+ * @param int $year scan
+ * @return array with amount by month
+ */
+ function getAmountByMonth($year) {
+ global $user;
+
+ $this->yearmonth = $year;
+
+ $sql = "SELECT date_format(t.datec,'%m') as dm, SUM(t.opp_amount)";
+ $sql .= " FROM " . MAIN_DB_PREFIX . "projet as t";
+ if (! $user->rights->societe->client->voir && ! $user->societe_id)
+ $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON sc.fk_soc=t.fk_soc AND sc.fk_user=" . $user->id;
+ $sql .= $this->buildWhere();
+ $sql .= " GROUP BY dm";
+ $sql .= $this->db->order('dm', 'DESC');
+ $this->yearmonth=0;
+
+ $res = $this->_getAmountByMonth($year, $sql);
+ // var_dump($res);print ' ';
+ return $res;
+ }
+
+ /**
+ * Return amount of elements by month for several years
+ *
+ * @param int $endyear End year
+ * @param int $startyear Start year
+ * @param int $cachedelay accept for cache file (0=No read, no save of cache, -1=No read but save)
+ * @return array of values
+ */
+ function getTransformRateByMonthWithPrevYear($endyear, $startyear, $cachedelay = 0)
+ {
+ global $conf, $user, $langs;
+
+ if ($startyear > $endyear) return - 1;
+
+ $datay = array();
+
+ // Search into cache
+ if (! empty($cachedelay))
+ {
+ include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
+ include_once DOL_DOCUMENT_ROOT . '/core/lib/json.lib.php';
+ }
+
+ $newpathofdestfile = $conf->user->dir_temp . '/' . get_class($this) . '_' . __FUNCTION__ . '_' . (empty($this->cachefilesuffix) ? '' : $this->cachefilesuffix . '_') . $langs->defaultlang . '_user' . $user->id . '.cache';
+ $newmask = '0644';
+
+ $nowgmt = dol_now();
+
+ $foundintocache = 0;
+ if ($cachedelay > 0) {
+ $filedate = dol_filemtime($newpathofdestfile);
+ if ($filedate >= ($nowgmt - $cachedelay)) {
+ $foundintocache = 1;
+
+ $this->_lastfetchdate[get_class($this) . '_' . __FUNCTION__] = $filedate;
+ } else {
+ dol_syslog(get_class($this) . '::' . __FUNCTION__ . " cache file " . $newpathofdestfile . " is not found or older than now - cachedelay (" . $nowgmt . " - " . $cachedelay . ") so we can't use it.");
+ }
+ }
+
+ // Load file into $data
+ if ($foundintocache) // Cache file found and is not too old
+ {
+ dol_syslog(get_class($this) . '::' . __FUNCTION__ . " read data from cache file " . $newpathofdestfile . " " . $filedate . ".");
+ $data = dol_json_decode(file_get_contents($newpathofdestfile), true);
+ } else {
+ $year = $startyear;
+ while ( $year <= $endyear ) {
+ $datay[$year] = $this->getTransformRateByMonth($year);
+ $year ++;
+ }
+
+ $data = array ();
+ // $data = array('xval'=>array(0=>xlabel,1=>yval1,2=>yval2...),...)
+ for($i = 0; $i < 12; $i ++) {
+ $data[$i][] = $datay[$endyear][$i][0]; // set label
+ $year = $startyear;
+ while ( $year <= $endyear ) {
+ $data[$i][] = $datay[$year][$i][1]; // set yval for x=i
+ $year ++;
+ }
+ }
+ }
+
+ // Save cache file
+ if (empty($foundintocache) && ($cachedelay > 0 || $cachedelay == - 1)) {
+ dol_syslog(get_class($this) . '::' . __FUNCTION__ . " save cache file " . $newpathofdestfile . " onto disk.");
+ if (! dol_is_dir($conf->user->dir_temp))
+ dol_mkdir($conf->user->dir_temp);
+ $fp = fopen($newpathofdestfile, 'w');
+ fwrite($fp, dol_json_encode($data));
+ fclose($fp);
+ if (! empty($conf->global->MAIN_UMASK))
+ $newmask = $conf->global->MAIN_UMASK;
+ @chmod($newpathofdestfile, octdec($newmask));
+
+ $this->_lastfetchdate[get_class($this) . '_' . __FUNCTION__] = $nowgmt;
+ }
+
+ return $data;
+ }
+
+ /**
+ * Return the Project transformation rate by month for a year
+ *
+ * @param int $year scan
+ * @return array with amount by month
+ */
+ function getTransformRateByMonth($year) {
+ global $user;
+
+ $this->yearmonth = $year;
+
+ $sql = "SELECT date_format(t.datec,'%m') as dm, count(t.opp_amount)";
+ $sql .= " FROM " . MAIN_DB_PREFIX . "projet as t";
+ if (! $user->rights->societe->client->voir && ! $user->societe_id)
+ $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON sc.fk_soc=t.fk_soc AND sc.fk_user=" . $user->id;
+ $sql .= $this->buildWhere();
+ $sql .= " GROUP BY dm";
+ $sql .= $this->db->order('dm', 'DESC');
+
+ $res_total = $this->_getNbByMonth($year, $sql);
+
+ $this->status=6;
+
+ $sql = "SELECT date_format(t.datec,'%m') as dm, count(t.opp_amount)";
+ $sql .= " FROM " . MAIN_DB_PREFIX . "projet as t";
+ if (! $user->rights->societe->client->voir && ! $user->societe_id)
+ $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON sc.fk_soc=t.fk_soc AND sc.fk_user=" . $user->id;
+ $sql .= $this->buildWhere();
+ $sql .= " GROUP BY dm";
+ $sql .= $this->db->order('dm', 'DESC');
+
+ $this->status=0;
+ $this->yearmonth=0;
+
+ $res_only_wined = $this->_getNbByMonth($year, $sql);
+
+ $res=array();
+
+ foreach($res_total as $key=>$total_row) {
+ //var_dump($total_row);
+ if (!empty($total_row[1])) {
+ $res[$key]=array($total_row[0],(100*$res_only_wined[$key][1])/$total_row[1]);
+ } else {
+ $res[$key]=array($total_row[0],0);
+ }
+
+ }
+ // var_dump($res);print ' ';
+ return $res;
+ }
+}
\ No newline at end of file
diff --git a/htdocs/projet/stats/index.php b/htdocs/projet/stats/index.php
new file mode 100644
index 00000000000..fdb272ed70e
--- /dev/null
+++ b/htdocs/projet/stats/index.php
@@ -0,0 +1,367 @@
+
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+require '../../main.inc.php';
+require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/projet/class/projectstats.class.php';
+
+// Security check
+if (! $user->rights->projet->lire)
+ accessforbidden();
+
+
+$WIDTH=DolGraph::getDefaultGraphSizeForStats('width');
+$HEIGHT=DolGraph::getDefaultGraphSizeForStats('height');
+
+$userid=GETPOST('userid','int');
+$socid=GETPOST('socid','int');
+// Security check
+if ($user->societe_id > 0)
+{
+ $action = '';
+ $socid = $user->societe_id;
+}
+$nowyear=strftime("%Y", dol_now());
+$year = GETPOST('year')>0?GETPOST('year'):$nowyear;
+//$startyear=$year-2;
+$startyear=$year-1;
+$endyear=$year;
+
+$langs->load('projects');
+
+
+/*
+ * View
+ */
+
+$form=new Form($db);
+
+$includeuserlist=array();
+
+
+llxHeader('', $langs->trans('Projects'));
+
+$title=$langs->trans("ProjectsStatistics");
+$dir=$conf->projet->dir_output.'/temp';
+
+print_fiche_titre($title,'','title_project.png');
+
+dol_mkdir($dir);
+
+
+$stats_project= new ProjectStats($db);
+if (!empty($userid) && $userid!=-1) $stats_project->userid=$userid;
+if (!empty($socid) && $socid!=-1) $stats_project->socid=$socid;
+if (!empty($year)) $stats_project->year=$year;
+
+
+
+if (! empty($conf->global->PROJECT_USE_OPPORTUNITIES))
+{
+ $data1 = $stats_project->getAllProjectByStatus();
+ if (!is_array($data1) && $data1<0) {
+ setEventMessages($stats_project->error, null, 'errors');
+ }
+ if (empty($data1))
+ {
+ $showpointvalue=0;
+ $nocolor=1;
+ $data1=array(array(0=>$langs->trans("None"),1=>1));
+ }
+
+ $filenamenb = $conf->project->dir_output . "/stats/projectbystatus.png";
+ $fileurlnb = DOL_URL_ROOT . '/viewimage.php?modulepart=projectstats&file=projectbystatus.png';
+ $px = new DolGraph();
+ $mesg = $px->isGraphKo();
+ if (empty($mesg)) {
+ $i=0;$tot=count($data1);$legend=array();
+ while ($i <= $tot)
+ {
+ $data1[$i][0]=$data1[$i][0]; // Required to avoid error "Could not draw pie with labels contained inside canvas"
+ $legend[]=$data1[$i][0];
+ $i++;
+ }
+ $px->SetData($data1);
+ unset($data1);
+
+ if ($nocolor)
+ $px->SetDataColor(array (
+ array (
+ 220,
+ 220,
+ 220
+ )
+ ));
+ $px->SetPrecisionY(0);
+ $px->SetLegend($legend);
+ $px->setShowLegend(0);
+ $px->setShowPointValue($showpointvalue);
+ $px->setShowPercent(1);
+ $px->SetMaxValue($px->GetCeilMaxValue());
+ $px->SetWidth(300);
+ $px->SetHeight(300);
+ $px->SetShading(3);
+ $px->SetHorizTickIncrement(1);
+ $px->SetCssPrefix("cssboxes");
+ $px->SetType(array (
+ 'pie'
+ ));
+ $px->SetTitle($langs->trans('ProjectNbProjectByStatus'));
+ $result=$px->draw($filenamenb, $fileurlnb);
+ if ($result<0) {
+ setEventMessages($px->error, null, 'errors');
+ }
+ } else {
+ setEventMessages(null, $mesgs, 'errors');
+ }
+}
+
+
+// Build graphic number of object
+// $data = array(array('Lib',val1,val2,val3),...)
+$data = $stats_project->getNbByMonthWithPrevYear($endyear,$startyear);
+//var_dump($data);
+
+$filenamenb = $conf->project->dir_output . "/stats/projectnbprevyear-".$year.".png";
+$fileurlnb = DOL_URL_ROOT . '/viewimage.php?modulepart=projectstats&file=projectnbprevyear-'.$year.'.png';
+
+$px1 = new DolGraph();
+$mesg = $px1->isGraphKo();
+if (! $mesg)
+{
+ $px1->SetData($data);
+ $px1->SetPrecisionY(0);
+ $i=$startyear;$legend=array();
+ while ($i <= $endyear)
+ {
+ $legend[]=$i;
+ $i++;
+ }
+ $px1->SetLegend($legend);
+ $px1->SetMaxValue($px1->GetCeilMaxValue());
+ $px1->SetWidth($WIDTH);
+ $px1->SetHeight($HEIGHT);
+ $px1->SetYLabel($langs->trans("ProjectNbProject"));
+ $px1->SetShading(3);
+ $px1->SetHorizTickIncrement(1);
+ $px1->SetPrecisionY(0);
+ $px1->mode='depth';
+ $px1->SetTitle($langs->trans("ProjectNbProjectByMonth"));
+
+ $px1->draw($filenamenb,$fileurlnb);
+}
+
+
+if (! empty($conf->global->PROJECT_USE_OPPORTUNITIES))
+{
+ // Build graphic amount of object
+ $data = $stats_project->getAmountByMonthWithPrevYear($endyear,$startyear);
+ //var_dump($data);
+ // $data = array(array('Lib',val1,val2,val3),...)
+
+ $filenamenb = $conf->project->dir_output . "/stats/projectamountprevyear-".$year.".png";
+ $fileurlnb = DOL_URL_ROOT . '/viewimage.php?modulepart=projectstats&file=projectamountprevyear-'.$year.'.png';
+
+ $px2 = new DolGraph();
+ $mesg = $px2->isGraphKo();
+ if (! $mesg)
+ {
+ $px2->SetData($data);
+ $i=$startyear;$legend=array();
+ while ($i <= $endyear)
+ {
+ $legend[]=$i;
+ $i++;
+ }
+ $px2->SetLegend($legend);
+ $px2->SetMaxValue($px2->GetCeilMaxValue());
+ $px2->SetMinValue(min(0,$px2->GetFloorMinValue()));
+ $px2->SetWidth($WIDTH);
+ $px2->SetHeight($HEIGHT);
+ $px2->SetYLabel($langs->trans("ProjectAmountOfProject"));
+ $px2->SetShading(3);
+ $px2->SetHorizTickIncrement(1);
+ $px2->SetPrecisionY(0);
+ $px2->mode='depth';
+ $px2->SetTitle($langs->trans("ProjectAmountOfProjectsByMonth"));
+
+ $px2->draw($filenamenb,$fileurlnb);
+ }
+}
+
+if (! empty($conf->global->PROJECT_USE_OPPORTUNITIES))
+{
+ // Build graphic with transformation rate
+ $data = $stats_project->getTransformRateByMonthWithPrevYear($endyear,$startyear);
+ //var_dump($data);
+ // $data = array(array('Lib',val1,val2,val3),...)
+
+ $filenamenb = $conf->project->dir_output . "/stats/projecttransrateprevyear-".$year.".png";
+ $fileurlnb = DOL_URL_ROOT . '/viewimage.php?modulepart=projectstats&file=projecttransrateprevyear-'.$year.'.png';
+
+ $px3 = new DolGraph();
+ $mesg = $px3->isGraphKo();
+ if (! $mesg)
+ {
+ $px3->SetData($data);
+ $i=$startyear;$legend=array();
+ while ($i <= $endyear)
+ {
+ $legend[]=$i;
+ $i++;
+ }
+ $px3->SetLegend($legend);
+ $px3->SetMaxValue($px3->GetCeilMaxValue());
+ $px3->SetMinValue(min(0,$px3->GetFloorMinValue()));
+ $px3->SetWidth($WIDTH);
+ $px3->SetHeight($HEIGHT);
+ $px3->SetYLabel($langs->trans("ProjectTransRateOfProject"));
+ $px3->SetShading(3);
+ $px3->SetHorizTickIncrement(1);
+ $px3->SetPrecisionY(0);
+ $px3->mode='depth';
+ $px3->SetTitle($langs->trans("ProjectTransRateOfProjectsByMonth"));
+
+ $px3->draw($filenamenb,$fileurlnb);
+ }
+}
+
+
+// Show array
+$stats_project->year=0;
+$data_all_year = $stats_project->getAllByYear();
+if (!empty($year)) $stats_project->year=$year;
+$arrayyears=array();
+foreach($data_all_year as $val) {
+ $arrayyears[$val['year']]=$val['year'];
+}
+if (! count($arrayyears)) $arrayyears[$nowyear]=$nowyear;
+
+
+$h=0;
+$head = array();
+$head[$h][0] = DOL_URL_ROOT . '/projet/stats/index.php?mode='.$mode;
+$head[$h][1] = $langs->trans("ByMonthYear");
+$head[$h][2] = 'byyear';
+$h++;
+
+complete_head_from_modules($conf,$langs,null,$head,$h,$type);
+
+dol_fiche_head($head,'byyear',$langs->trans("Statistics"), 0, '');
+
+
+print '