diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 475051da56c9ddd746525d272683cc488e146c50..509e8792c8f258c5b0dceae43cff7f54d757834a 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -659,7 +659,11 @@ if ($_POST['action'] == "addligne" && $user->rights->propale->creer) if ($_POST['action'] == 'updateligne' && $user->rights->propale->creer && $_POST["save"] == $langs->trans("Save")) { $propal = new Propal($db); - if (! $propal->fetch($_POST['propalid']) > 0) dolibarr_print_error($db); + if (! $propal->fetch($_POST['propalid']) > 0) + { + dolibarr_print_error($db,$propal->error); + exit; + } // Define info_bits $info_bits=0; @@ -671,9 +675,12 @@ if ($_POST['action'] == 'updateligne' && $user->rights->propale->creer && $_POST // On v�rifie que le prix minimum est respect� $productid = $_POST['productid'] ; - $pruduct = new Product($db) ; - $pruduct->fetch($productid) ; - if ($pruduct->price_min && ($_POST['productid']!='')&&( price2num($_POST['subprice'])*(1-price2num($_POST['remise_percent'])/100) < price2num($pruduct->price_min))) + if ($productid) + { + $pruduct = new Product($db) ; + $res=$pruduct->fetch($productid) ; + } + if ($productid && $pruduct->price_min && ( price2num($_POST['subprice'])*(1-price2num($_POST['remise_percent'])/100) < price2num($pruduct->price_min))) { $mesg = '<div class="error">'.$langs->trans("CantBeLessThanMinPrice",price2num($pruduct->price_min,'MU').' '.$langs->trans("Currency".$conf->monnaie)).'</div>' ; } @@ -1913,18 +1920,24 @@ else if ($result) { - $num = $db->num_rows($result); $propalstatic=new Propal($db); - print_barre_liste($langs->trans('ListOfProposals'), $page,'propal.php','&socid='.$socid.'&viewstatut='.$viewstatut,$sortfield,$sortorder,'',$num); + + $num = $db->num_rows($result); + + $param='&socid='.$socid.'&viewstatut='.$viewstatut; + if ($month) $param.='&month='.$month; + if ($year) $param.='&year='.$year; + print_barre_liste($langs->trans('ListOfProposals'), $page,'propal.php',$param,$sortfield,$sortorder,'',$num); + $i = 0; print '<table class="liste" width="100%">'; print '<tr class="liste_titre">'; - print_liste_field_titre($langs->trans('Ref'),$_SERVER["PHP_SELF"],'p.ref','','&socid='.$socid.'&viewstatut='.$viewstatut,'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans('Company'),$_SERVER["PHP_SELF"],'s.nom','','&socid='.$socid.'&viewstatut='.$viewstatut,'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans('Date'),$_SERVER["PHP_SELF"],'p.datep','','&socid='.$socid.'&viewstatut='.$viewstatut, 'align="center"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans('DateEndPropalShort'),$_SERVER["PHP_SELF"],'dfv','','&socid='.$socid.'&viewstatut='.$viewstatut, 'align="center"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans('Price'),$_SERVER["PHP_SELF"],'p.total_ht','','&socid='.$socid.'&viewstatut='.$viewstatut, 'align="right"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans('Status'),$_SERVER["PHP_SELF"],'p.fk_statut','','&socid='.$socid.'&viewstatut='.$viewstatut,'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans('Ref'),$_SERVER["PHP_SELF"],'p.ref','',$param,'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans('Company'),$_SERVER["PHP_SELF"],'s.nom','',$param,'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans('Date'),$_SERVER["PHP_SELF"],'p.datep','',$param, 'align="center"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans('DateEndPropalShort'),$_SERVER["PHP_SELF"],'dfv','',$param, 'align="center"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans('Price'),$_SERVER["PHP_SELF"],'p.total_ht','',$param, 'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans('Status'),$_SERVER["PHP_SELF"],'p.fk_statut','',$param,'align="right"',$sortfield,$sortorder); print '<td class="liste_titre"> </td>'; print "</tr>\n"; // Lignes des champs de filtre @@ -1938,12 +1951,11 @@ else print '<input class="flat" type="text" size="40" name="search_societe" value="'.$_GET['search_societe'].'">'; print '</td>'; print '<td class="liste_titre" colspan="1" align="right">'; - print $langs->trans('Month').': <input class="flat" type="text" size="2" maxlength="2" name="month" value="'.$month.'">'; + print $langs->trans('Month').': <input class="flat" type="text" size="1" maxlength="2" name="month" value="'.$month.'">'; print ' '.$langs->trans('Year').': '; $max_year = date("Y"); $syear = $year; - if($syear == '') - $syear = date("Y"); + //if($syear == '') $syear = date("Y"); $html->select_year($syear,'year',1, '', $max_year); print '</td>'; print '<td class="liste_titre" colspan="1"> </td>'; @@ -2015,7 +2027,7 @@ else // Date fin validite if ($objp->dfv) { - print '<td align="center">'.dolibarr_print_date($objp->dfv); + print '<td align="center">'.dolibarr_print_date($objp->dfv,'day'); print '</td>'; } else diff --git a/htdocs/comm/propal/stats/index.php b/htdocs/comm/propal/stats/index.php index f9d9cc6da98b2dc44a926b13b48a350b901dd48d..1af520b1779ba7d1a723fd2a1fcbfcd3c747c7df 100644 --- a/htdocs/comm/propal/stats/index.php +++ b/htdocs/comm/propal/stats/index.php @@ -31,28 +31,46 @@ require_once(DOL_DOCUMENT_ROOT."/core/dolgraph.class.php"); $WIDTH=500; $HEIGHT=200; +// S�curit� acc�s client +if ($user->societe_id > 0) +{ + $action = ''; + $socid = $user->societe_id; +} + +$year = strftime("%Y", time()); +$startyear=$year-2; +$endyear=$year; +/* + * View + */ + llxHeader(); print_fiche_titre($langs->trans("ProposalsStatistics"), $mesg); -$stats = new PropaleStats($db); -$year = strftime("%Y", time()); -$startyear=$year-2; -$endyear=$year; +$dir=$conf->propal->dir_temp; + +create_exdir($dir); + +$stats = new PropaleStats($db, $socid); + +// Build graphic number of object $data = $stats->getNbByMonthWithPrevYear($endyear,$startyear); +//var_dump($data); +// $data = array(array('Lib',val1,val2,val3),...) -create_exdir($conf->propal->dir_temp); if (!$user->rights->societe->client->voir || $user->societe_id) { - $filename = $conf->propal->dir_temp.'/nbpropale2year-'.$user->id.'-'.$year.'.png'; - $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=nbpropale2year-'.$user->id.'-'.$year.'.png'; + $filenamenb = $conf->propal->dir_temp.'/proposalsnbinyear-'.$user->id.'-'.$year.'.png'; + $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsnbinyear-'.$user->id.'-'.$year.'.png'; } else { - $filename = $conf->propal->dir_temp.'/nbpropale2year-'.$year.'.png'; - $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=nbpropale2year-'.$year.'.png'; + $filenamenb = $conf->propal->dir_temp.'/proposalsnbinyear-'.$year.'.png'; + $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsnbinyear-'.$year.'.png'; } $px = new DolGraph(); @@ -69,6 +87,7 @@ if (! $mesg) } $px->SetLegend($legend); $px->SetMaxValue($px->GetCeilMaxValue()); + $px->SetMinValue(min(0,$px->GetFloorMinValue())); $px->SetWidth($WIDTH); $px->SetHeight($HEIGHT); $px->SetYLabel($langs->trans("NbOfProposals")); @@ -76,60 +95,109 @@ if (! $mesg) $px->SetHorizTickIncrement(1); $px->SetPrecisionY(0); $px->mode='depth'; - $px->draw($filename); + $px->SetTitle($langs->trans("NbOfProposals")); + + $px->draw($filenamenb); } -$sql = "SELECT count(*) as nb, date_format(p.datep,'%Y') as dm, sum(p.total) as total_ttc"; -if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user"; -$sql.= " FROM ".MAIN_DB_PREFIX."propal as p"; -if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; -$sql.= " WHERE fk_statut > 0"; -if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; -if($user->societe_id) +// Build graphic amount of object +$data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear); +//var_dump($data); +// $data = array(array('Lib',val1,val2,val3),...) + +if (!$user->rights->societe->client->voir || $user->societe_id) { - $sql .= " AND p.fk_soc = ".$user->societe_id; + $filenameamount = $conf->propal->dir_temp.'/proposalsamountinyear-'.$user->id.'-'.$year.'.png'; + $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsamountinyear-'.$user->id.'-'.$year.'.png'; } -$sql.= " GROUP BY dm DESC "; -$result=$db->query($sql); -if ($result) +else { - $num = $db->num_rows($result); + $filenameamount = $conf->propal->dir_temp.'/proposalsamountinyear-'.$year.'.png'; + $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsamountinyear-'.$year.'.png'; +} - print '<table class="border" width="100%" cellspacing="0" cellpadding="2">'; - print '<tr><td align="center">'.$langs->trans("Year").'</td><td width="10%" align="center">'.$langs->trans("NbOfProposals").'</td><td align="center">'.$langs->trans("AmountTotal").'</td>'; - print '<td align="center" valign="top" rowspan="'.($num + 1).'">'; - - if ($mesg) - { - print "$mesg"; - } - else - { - print '<img src="'.$fileurl.'" alt="Nombre de proposition par mois">'; - } - - print '</td></tr>'; - $i = 0; - while ($i < $num) - { - $obj = $db->fetch_object($result); - $nbproduct = $obj->nb; - $year = $obj->dm; - print "<tr>"; - print '<td align="center"><a href="month.php?year='.$year.'">'.$year.'</a></td>'; - print '<td align="center">'.$nbproduct.'</td>'; - print '<td align="center">'.price($obj->total_ttc).'</td></tr>'; - $i++; - } - - print '</table>'; - $db->free($result); +$px = new DolGraph(); +$mesg = $px->isGraphKo(); +if (! $mesg) +{ + $px->SetData($data); + $px->SetPrecisionY(0); + $i=$startyear; + while ($i <= $endyear) + { + $legend[]=$i; + $i++; + } + $px->SetLegend($legend); + $px->SetMaxValue($px->GetCeilMaxValue()); + $px->SetMinValue(min(0,$px->GetFloorMinValue())); + $px->SetWidth($WIDTH); + $px->SetHeight($HEIGHT); + $px->SetYLabel($langs->trans("AmountOfProposals")); + $px->SetShading(3); + $px->SetHorizTickIncrement(1); + $px->SetPrecisionY(0); + $px->mode='depth'; + $px->SetTitle($langs->trans("AmountOfProposalsByMonthHT")); + + $px->draw($filenameamount); } -else + +print '<table class="notopnoleftnopadd" width="100%"><tr>'; +print '<td align="center" valign="top">'; + +// Show array +$data = $stats->getAllByYear(); + +print '<table class="border" width="100%">'; +print '<tr height="24">'; +print '<td align="center">'.$langs->trans("Year").'</td>'; +print '<td align="center">'.$langs->trans("NbOfProposals").'</td>'; +print '<td align="center">'.$langs->trans("AmountTotal").'</td>'; +print '<td align="center">'.$langs->trans("AmountAverage").'</td>'; +print '</tr>'; + +$oldyear=0; +foreach ($data as $val) { - dolibarr_print_error($db); + $year = $val['year']; + print $avg; + while ($oldyear > $year+1) + { // If we have empty year + $oldyear--; + print '<tr height="24">'; + print '<td align="center"><a href="month.php?year='.$oldyear.'&mode='.$mode.'">'.$oldyear.'</a></td>'; + print '<td align="right">0</td>'; + print '<td align="right">0</td>'; + print '<td align="right">0</td>'; + print '</tr>'; + } + print '<tr height="24">'; + print '<td align="center"><a href="month.php?year='.$year.'">'.$year.'</a></td>'; + print '<td align="right">'.$val['nb'].'</td>'; + print '<td align="right">'.price(price2num($val['total'],'MT'),1).'</td>'; + print '<td align="right">'.price(price2num($val['avg'],'MT'),1).'</td>'; + print '</tr>'; + $oldyear=$year; +} + +print '</table>'; + + +print '</td>'; +print '<td align="center" valign="top">'; + +// Show graphs +print '<table class="border" width="100%"><tr valign="top"><td align="center">'; +if ($mesg) { print $mesg; } +else { + print '<img src="'.$fileurlnb.'" title="'.$langs->trans("NbOfProposals").'" alt="'.$langs->trans("NbOfProposals").'">'; + print "<br>\n"; + print '<img src="'.$fileurlamount.'" title="'.$langs->trans("AmountTotal").'" alt="'.$langs->trans("AmountTotal").'">'; } +print '</td></tr></table>'; +print '</td></tr></table>'; $db->close(); diff --git a/htdocs/comm/propal/stats/month.php b/htdocs/comm/propal/stats/month.php index e497330533ea1f93952e931a31e59da5015e64bf..bc4f1211479bb622dd7c90eda5d7613a8a088957 100644 --- a/htdocs/comm/propal/stats/month.php +++ b/htdocs/comm/propal/stats/month.php @@ -28,39 +28,48 @@ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/comm/propal/stats/propalestats.class.php"); require_once(DOL_DOCUMENT_ROOT."/core/dolgraph.class.php"); +$GRAPHWIDTH=500; +$GRAPHHEIGHT=200; -llxHeader(); +// Check security access +if ($user->societe_id > 0) +{ + $action = ''; + $socid = $user->societe_id; +} $year = isset($_GET["year"])?$_GET["year"]:date("Y",time()); + +/* + * View + */ + +llxHeader(); + +$dir=$conf->propal->dir_temp; + $mesg = '<a href="month.php?year='.($year - 1).'">'.img_previous().'</a> '; $mesg.= $langs->trans("Year")." $year"; $mesg.= ' <a href="month.php?year='.($year + 1).'">'.img_next().'</a>'; +print_fiche_titre($langs->trans("ProposalsStatistics"), $mesg); -$WIDTH=500; -$HEIGHT=200; +create_exdir($dir); -/* - * - * - */ +$stats = new PropaleStats($db, $socid); -print_fiche_titre($langs->trans("ProposalsStatistics"), $mesg); -$stats = new PropaleStats($db); $data = $stats->getNbByMonth($year); -create_exdir($conf->propal->dir_temp); - if (!$user->rights->societe->client->voir || $user->societe_id) { - $filename = $conf->propal->dir_temp.'/propale-'.$user->id.'-'.$year.'.png'; - $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=propale-'.$user->id.'-'.$year.'.png'; + $filename = $dir.'/proposalsnb-'.$user->id.'-'.$year.'.png'; + $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsnb-'.$user->id.'-'.$year.'.png'; } else { - $filename = $conf->propal->dir_temp.'/propale'.$year.'.png'; - $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=propale'.$year.'.png'; + $filename = $dir.'/proposalsnb-'.$year.'.png'; + $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsnb-'.$year.'.png'; } $px = new DolGraph(); @@ -68,34 +77,29 @@ $mesg = $px->isGraphKo(); if (! $mesg) { $px->SetData($data); - $px->SetPrecisionY(0); $px->SetMaxValue($px->GetCeilMaxValue()); - $px->SetWidth($WIDTH); - $px->SetHeight($HEIGHT); + $px->SetMinValue($px->GetFloorMinValue()); + $px->SetWidth($GRAPHWIDTH); + $px->SetHeight($GRAPHHEIGHT); $px->SetShading(3); $px->SetHorizTickIncrement(1); $px->SetPrecisionY(0); $px->draw($filename); } -$res = $stats->getAmountByMonth($year); -$data = array(); -for ($i = 1 ; $i < 13 ; $i++) -{ - $data[$i-1] = array(ucfirst(substr(strftime("%b",dolibarr_mktime(12,12,12,$i,1,$year)),0,3)), $res[$i]); -} +$data = $stats->getAmountByMonth($year); if (!$user->rights->societe->client->voir || $user->societe_id) { - $filename_amount = $conf->propal->dir_temp.'/propaleamount-'.$user->id.'-'.$year.'.png'; - $fileurl_amount = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=propaleamount-'.$user->id.'-'.$year.'.png'; + $filename_amount = $dir.'/proposalsamount-'.$user->id.'-'.$year.'.png'; + $fileurl_amount = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsamount-'.$user->id.'-'.$year.'.png'; } else { - $filename_amount = $conf->propal->dir_temp.'/propaleamount'.$year.'.png'; - $fileurl_amount = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=propaleamount'.$year.'.png'; + $filename_amount = $dir.'/proposalsamount-'.$year.'.png'; + $fileurl_amount = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsamount-'.$year.'.png'; } $px = new DolGraph(); @@ -103,16 +107,18 @@ $mesg = $px->isGraphKo(); if (! $mesg) { $px->SetData($data); - $px->SetPrecisionY(0); $px->SetYLabel($langs->trans("AmountTotal")); $px->SetMaxValue($px->GetCeilMaxValue()); - $px->SetWidth($WIDTH); - $px->SetHeight($HEIGHT); + $px->SetMinValue($px->GetFloorMinValue()); + $px->SetWidth($GRAPHWIDTH); + $px->SetHeight($GRAPHHEIGHT); $px->SetShading(3); $px->SetHorizTickIncrement(1); $px->SetPrecisionY(0); - $px->draw($filename_amount, $data, $year); + $px->draw($filename_amount); } + + $res = $stats->getAverageByMonth($year); $data = array(); @@ -124,13 +130,13 @@ for ($i = 1 ; $i < 13 ; $i++) if (!$user->rights->societe->client->voir || $user->societe_id) { - $filename_avg = $conf->propal->dir_temp.'/propaleaverage-'.$user->id.'-'.$year.'.png'; - $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=propaleaverage-'.$user->id.'-'.$year.'.png'; + $filename_avg = $dir.'/proposalsaverage-'.$user->id.'-'.$year.'.png'; + $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsaverage-'.$user->id.'-'.$year.'.png'; } else { - $filename_avg = $conf->propal->dir_temp.'/propaleaverage'.$year.'.png'; - $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=propaleaverage'.$year.'.png'; + $filename_avg = $dir.'/proposalsaverage-'.$year.'.png'; + $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsaverage-'.$year.'.png'; } $px = new DolGraph(); @@ -141,8 +147,9 @@ if (! $mesg) $px->SetPrecisionY(0); $px->SetYLabel($langs->trans("AmountAverage")); $px->SetMaxValue($px->GetCeilMaxValue()); - $px->SetWidth($WIDTH); - $px->SetHeight($HEIGHT); + $px->SetMinValue($px->GetFloorMinValue()); + $px->SetWidth($GRAPHWIDTH); + $px->SetHeight($GRAPHHEIGHT); $px->SetShading(3); $px->SetHorizTickIncrement(1); $px->SetPrecisionY(0); diff --git a/htdocs/comm/propal/stats/propalestats.class.php b/htdocs/comm/propal/stats/propalestats.class.php index cd7ccc2e32c614ffb4732a49fc5e12d045265361..717e8d5c3a6dffededda009f43d9590862052fff 100644 --- a/htdocs/comm/propal/stats/propalestats.class.php +++ b/htdocs/comm/propal/stats/propalestats.class.php @@ -15,124 +15,169 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Id$ */ /** - \file htdocs/comm/propal/stats/propalestats.class.php - \ingroup propales - \brief Fichier de la classe de gestion des stats des propales - \version $Revision$ -*/ + * \file htdocs/comm/propal/stats/propalestats.class.php + * \ingroup propales + * \brief Fichier de la classe de gestion des stats des propales + * \version $Id$ + */ include_once DOL_DOCUMENT_ROOT . "/stats.class.php"; +include_once DOL_DOCUMENT_ROOT . "/propal.class.php"; /** - \class PropaleStats - \brief Classe permettant la gestion des stats des propales -*/ - + * \class PropaleStats + * \brief Classe permettant la gestion des stats des propales + */ class PropaleStats extends Stats { - var $db ; - - function PropaleStats($DB) - { - $this->db = $DB; - } - - - /** - * Renvoie le nombre de proposition par mois pour une ann�e donn�e - * - */ - function getNbByMonth($year) - { - global $user; - - $sql = "SELECT date_format(p.datep,'%m') as dm, count(*)"; - if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user"; - $sql .= " FROM ".MAIN_DB_PREFIX."propal as p"; - if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql .= " WHERE date_format(p.datep,'%Y') = $year AND p.fk_statut > 0"; - if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; - if($user->societe_id) - { - $sql .= " AND p.fk_soc = ".$user->societe_id; - } - $sql .= " GROUP BY dm DESC"; - - return $this->_getNbByMonth($year, $sql); - } - - /** - * Renvoie le nombre de propale par ann�e - * - */ - function getNbByYear() - { - global $user; - - $sql = "SELECT date_format(p.datep,'%Y') as dm, count(*)"; - if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user"; - $sql .= " FROM ".MAIN_DB_PREFIX."propal as p"; - if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql .= " WHERE p.fk_statut > 0"; - if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; - if($user->societe_id) - { - $sql .= " AND p.fk_soc = ".$user->societe_id; - } - $sql .= " GROUP BY dm DESC"; - - return $this->_getNbByYear($sql); - } - /** - * Renvoie le nombre de propale par mois pour une ann�e donn�e - * - */ - function getAmountByMonth($year) - { - global $user; - - $sql = "SELECT date_format(p.datep,'%m') as dm, sum(p.total_ht)"; - if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user"; - $sql .= " FROM ".MAIN_DB_PREFIX."propal as p"; - if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql .= " WHERE date_format(p.datep,'%Y') = $year AND p.fk_statut > 0"; - if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; - if($user->societe_id) - { - $sql .= " AND p.fk_soc = ".$user->societe_id; - } - $sql .= " GROUP BY dm DESC"; - - return $this->_getAmountByMonth($year, $sql); - } - /** - * - * - */ - function getAverageByMonth($year) - { - global $user; - - $sql = "SELECT date_format(p.datep,'%m') as dm, avg(p.total_ht)"; - if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user"; - $sql .= " FROM ".MAIN_DB_PREFIX."propal as p"; - if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql .= " WHERE date_format(p.datep,'%Y') = $year AND p.fk_statut > 0"; - if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; - if($user->societe_id) - { - $sql .= " AND p.fk_soc = ".$user->societe_id; - } - $sql .= " GROUP BY dm DESC"; - - return $this->_getAverageByMonth($year, $sql); - } -} + var $db ; + + var $socid; + var $where; + + var $table_element; + var $field; + + + /** + * Constructor + * + * @param $DB Database handler + * @param $socid Id third party + * @return PropaleStats + */ + function PropaleStats($DB, $socid=0) + { + global $user; + + $this->db = $DB; + + $object=new Propal($this->db); + $this->table_element=$object->table_element; + $this->field='total'; + + $this->socid = $socid; + $this->where.= " fk_statut > 0"; + if (!$user->rights->societe->client->voir && !$user->societe_id) $this->where .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; + if($this->socid) + { + $this->where .= " AND p.fk_soc = ".$this->socid; + } + } + + /** + * Renvoie le nombre de proposition par mois pour une ann�e donn�e + * + */ + function getNbByMonth($year) + { + global $user; + + $sql = "SELECT date_format(p.datep,'%m') as dm, count(*)"; + if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user"; + $sql .= " FROM ".MAIN_DB_PREFIX."propal as p"; + if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= " WHERE date_format(p.datep,'%Y') = $year AND p.fk_statut > 0"; + if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; + if($user->societe_id) + { + $sql .= " AND p.fk_soc = ".$user->societe_id; + } + $sql .= " GROUP BY dm DESC"; + + return $this->_getNbByMonth($year, $sql); + } + + /** + * Renvoie le nombre de propale par ann�e + * + */ + function getNbByYear() + { + global $user; + + $sql = "SELECT date_format(p.datep,'%Y') as dm, count(*)"; + if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user"; + $sql .= " FROM ".MAIN_DB_PREFIX."propal as p"; + if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= " WHERE p.fk_statut > 0"; + if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; + if($user->societe_id) + { + $sql .= " AND p.fk_soc = ".$user->societe_id; + } + $sql .= " GROUP BY dm DESC"; + + return $this->_getNbByYear($sql); + } + /** + * Renvoie le nombre de propale par mois pour une ann�e donn�e + * + */ + function getAmountByMonth($year) + { + global $user; + + $sql = "SELECT date_format(p.datep,'%m') as dm, sum(p.total_ht)"; + if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user"; + $sql .= " FROM ".MAIN_DB_PREFIX."propal as p"; + if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= " WHERE date_format(p.datep,'%Y') = $year AND p.fk_statut > 0"; + if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; + if($user->societe_id) + { + $sql .= " AND p.fk_soc = ".$user->societe_id; + } + $sql .= " GROUP BY dm DESC"; + + return $this->_getAmountByMonth($year, $sql); + } + /** + * + * + */ + function getAverageByMonth($year) + { + global $user; + + $sql = "SELECT date_format(p.datep,'%m') as dm, avg(p.total_ht)"; + if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user"; + $sql .= " FROM ".MAIN_DB_PREFIX."propal as p"; + if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= " WHERE date_format(p.datep,'%Y') = $year AND p.fk_statut > 0"; + if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; + if($user->societe_id) + { + $sql .= " AND p.fk_soc = ".$user->societe_id; + } + $sql .= " GROUP BY dm DESC"; + + return $this->_getAverageByMonth($year, $sql); + } + + + /** + * \brief Return nb, total and average + * \return array Array of values + */ + function getAllByYear() + { + global $user; + + $sql = "SELECT date_format(p.datep,'%Y') as year, count(*) as nb, sum(".$this->field.") as total, avg(".$this->field.") as avg"; + if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user"; + $sql.= " FROM ".MAIN_DB_PREFIX."propal as p"; + if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql.= " WHERE ".$this->where; + $sql.= " GROUP BY year DESC"; + + return $this->_getAllByYear($sql); + } + +} ?> diff --git a/htdocs/compta/facture/stats/facturestats.class.php b/htdocs/compta/facture/stats/facturestats.class.php index 9360e74d1dd8f600ffc97d9a54f6b08bd4427058..b0c56f0697a5315c69bc9a35da80bc7edbd91ad0 100644 --- a/htdocs/compta/facture/stats/facturestats.class.php +++ b/htdocs/compta/facture/stats/facturestats.class.php @@ -41,6 +41,14 @@ class FactureStats extends Stats var $table_element; var $field; + /** + * Constructor + * + * @param $DB Database handler + * @param $socid Id third party + * @param $mode Option + * @return FactureStats + */ function FactureStats($DB, $socid=0, $mode) { $this->db = $DB; diff --git a/htdocs/compta/facture/stats/index.php b/htdocs/compta/facture/stats/index.php index dcc7381dd35bd58a36a3bd9447d36d8bcbe1591a..15c8d09c6c0612dd9ec9c2bd4ead54b35fd171b6 100644 --- a/htdocs/compta/facture/stats/index.php +++ b/htdocs/compta/facture/stats/index.php @@ -69,14 +69,14 @@ create_exdir($dir); $stats = new FactureStats($db, $socid, $mode); -// Build graphic number of invoices +// Build graphic number of object $data = $stats->getNbByMonthWithPrevYear($endyear,$startyear); //var_dump($data); // $data = array(array('Lib',val1,val2,val3),...) -$filenamenbinvoices = $dir."/invoicesnbinyear-".$year.".png"; -if ($mode == 'customer') $fileurlnbinvoices = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=invoicesnbinyear-'.$year.'.png'; -if ($mode == 'supplier') $fileurlnbinvoices = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&file=invoicesnbinyear-'.$year.'.png'; +$filenamenb = $dir."/invoicesnbinyear-".$year.".png"; +if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=invoicesnbinyear-'.$year.'.png'; +if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&file=invoicesnbinyear-'.$year.'.png'; $px = new DolGraph(); $mesg = $px->isGraphKo(); @@ -101,17 +101,17 @@ if (! $mesg) $px->mode='depth'; $px->SetTitle($langs->trans("NumberOfBillsByMonth")); - $px->draw($filenamenbinvoices); + $px->draw($filenamenb); } -// Build graphic amount of invoices +// Build graphic amount of object $data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear); //var_dump($data); // $data = array(array('Lib',val1,val2,val3),...) -$filenameamountinvoices = $dir."/invoicesamountinyear-".$year.".png"; -if ($mode == 'customer') $fileurlamountinvoices = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=invoicesamountinyear-'.$year.'.png'; -if ($mode == 'supplier') $fileurlamountinvoices = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&file=invoicesamountinyear-'.$year.'.png'; +$filenameamount = $dir."/invoicesamountinyear-".$year.".png"; +if ($mode == 'customer') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=invoicesamountinyear-'.$year.'.png'; +if ($mode == 'supplier') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&file=invoicesamountinyear-'.$year.'.png'; $px = new DolGraph(); $mesg = $px->isGraphKo(); @@ -137,7 +137,7 @@ if (! $mesg) $px->mode='depth'; $px->SetTitle($langs->trans("AmountOfBillsByMonthHT")); - $px->draw($filenameamountinvoices); + $px->draw($filenameamount); } @@ -192,9 +192,9 @@ print '<td align="center" valign="top">'; print '<table class="border" width="100%"><tr valign="top"><td align="center">'; if ($mesg) { print $mesg; } else { - print '<img src="'.$fileurlnbinvoices.'" title="'.$langs->trans("NumberOfBills").'" alt="'.$langs->trans("NumberOfBills").'">'; + print '<img src="'.$fileurlnb.'" title="'.$langs->trans("NumberOfBills").'" alt="'.$langs->trans("NumberOfBills").'">'; print "<br>\n"; - print '<img src="'.$fileurlamountinvoices.'" title="'.$langs->trans("AmountOfBills").'" alt="'.$langs->trans("AmountOfBills").'">'; + print '<img src="'.$fileurlamount.'" title="'.$langs->trans("AmountOfBills").'" alt="'.$langs->trans("AmountOfBills").'">'; } print '</td></tr></table>'; diff --git a/htdocs/compta/facture/stats/month.php b/htdocs/compta/facture/stats/month.php index 07256ab79698986b6fcc8e911f4fe612ffc376f2..dae0963bde00feaf5303ee87bacf4f427e3b8c9e 100644 --- a/htdocs/compta/facture/stats/month.php +++ b/htdocs/compta/facture/stats/month.php @@ -73,9 +73,9 @@ $stats = new FactureStats($db, $socid, $mode); $data = $stats->getNbByMonth($year); -$filename = $dir."/invoices-".$year.".png"; -if ($mode == 'customer') $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=invoices-'.$year.'.png'; -if ($mode == 'supplier') $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&file=invoices-'.$year.'.png'; +$filename = $dir."/invoicesnb-".$year.".png"; +if ($mode == 'customer') $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=invoicesnb-'.$year.'.png'; +if ($mode == 'supplier') $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&file=invoicesnb-'.$year.'.png'; $px = new DolGraph(); $mesg = $px->isGraphKo(); @@ -84,7 +84,6 @@ if (! $mesg) $px->SetData($data); $px->SetMaxValue($px->GetCeilMaxValue()); $px->SetMinValue($px->GetFloorMinValue()); - $px->SetPrecisionY(0); $px->SetWidth($GRAPHWIDTH); $px->SetHeight($GRAPHHEIGHT); $px->SetShading(3); @@ -109,7 +108,6 @@ if (! $mesg) $px->SetYLabel($langs->trans("AmountTotal")); $px->SetMaxValue($px->GetCeilMaxValue()); $px->SetMinValue($px->GetFloorMinValue()); - $px->SetPrecisionY(0); $px->SetWidth($GRAPHWIDTH); $px->SetHeight($GRAPHHEIGHT); $px->SetShading(3); @@ -144,7 +142,7 @@ if (! $mesg) $px->SetMinValue($px->GetFloorMinValue()); $px->SetWidth($GRAPHWIDTH); $px->SetHeight($GRAPHHEIGHT); - $px->SetShading(5); + $px->SetShading(3); $px->SetHorizTickIncrement(1); $px->SetPrecisionY(0); $px->draw($filename_avg); diff --git a/htdocs/propal.class.php b/htdocs/propal.class.php index 0ba06e78b96fa799f1789501e1cebbd2c7d333cd..7f19b7402104833dd99072a38e79f82098026535 100644 --- a/htdocs/propal.class.php +++ b/htdocs/propal.class.php @@ -37,10 +37,9 @@ require_once(DOL_DOCUMENT_ROOT ."/contact.class.php"); /** - \class Propal - \brief Classe permettant la gestion des propales + * \class Propal + * \brief Classe permettant la gestion des propales */ - class Propal extends CommonObject { var $db; @@ -95,9 +94,9 @@ class Propal extends CommonObject /** * \brief Constructeur - * \param DB Handler d'acc�s base - * \param socid Id de la soci�t� - * \param propalid Id de la propal + * \param DB Database handler + * \param socid Id third party + * \param propalid Id proposal */ function Propal($DB, $socid="", $propalid=0) { diff --git a/htdocs/stats.class.php b/htdocs/stats.class.php index 2baa45cd6e356ed05e9a0dc9348d3b8eff9d7a40..529d9ae51f8b4a9341c1b31c60155f169f02377b 100644 --- a/htdocs/stats.class.php +++ b/htdocs/stats.class.php @@ -111,6 +111,7 @@ class Stats { $result = array(); + dolibarr_syslog("Stats::_getNbByYear sql=".$sql); $resql=$this->db->query($sql); if ($resql) { @@ -139,6 +140,7 @@ class Stats { $result = array(); + dolibarr_syslog("Stats::_getAllByYear sql=".$sql); $resql=$this->db->query($sql); if ($resql) { @@ -169,8 +171,8 @@ class Stats { $result = array(); - $resql=$this->db->query($sql); dolibarr_syslog("Stats::_getNbByMonth sql=".$sql); + $resql=$this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); @@ -248,7 +250,7 @@ class Stats { $result = array(); - dolibarr_syslog("Stats::_getAmountByMonth sql=".$sql); + dolibarr_syslog("Stats::_getAverageByMonth sql=".$sql); $resql=$this->db->query($sql); if ($resql) {