2004-10-19 22:43:23 +02:00
< ? php
2003-11-17 10:53:28 +01:00
/* Copyright ( C ) 2001 - 2003 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2016-10-25 02:56:46 +02:00
* Copyright ( C ) 2004 - 2016 Laurent Destailleur < eldy @ users . sourceforge . net >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2009 Regis Houssin < regis . houssin @ inodbox . com >
2003-11-17 10:53:28 +01:00
*
* 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
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2003-11-17 10:53:28 +01:00
* ( 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
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2003-11-17 10:53:28 +01:00
*/
2004-12-04 20:07:24 +01:00
/**
2010-03-01 18:38:35 +01:00
* \file htdocs / expedition / stats / index . php
* \ingroup expedition
2013-07-25 15:02:40 +02:00
* \brief Page with shipment statistics
2010-03-01 18:38:35 +01:00
*/
2004-12-04 20:07:24 +01:00
2012-08-22 23:24:21 +02:00
require '../../main.inc.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/expedition/class/expedition.class.php' ;
2013-07-25 15:02:40 +02:00
require_once DOL_DOCUMENT_ROOT . '/expedition/class/expeditionstats.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/dolgraph.class.php' ;
2020-04-10 10:59:32 +02:00
$WIDTH = DolGraph :: getDefaultGraphSizeForStats ( 'width' );
$HEIGHT = DolGraph :: getDefaultGraphSizeForStats ( 'height' );
2013-07-25 15:02:40 +02:00
2020-04-10 10:59:32 +02:00
$userid = GETPOST ( 'userid' , 'int' );
$socid = GETPOST ( 'socid' , 'int' );
2013-07-25 15:02:40 +02:00
// Security check
2021-02-25 22:38:35 +01:00
if ( $user -> socid > 0 ) {
2020-10-31 14:32:18 +01:00
$action = '' ;
$socid = $user -> socid ;
2013-07-25 15:02:40 +02:00
}
2021-03-21 18:01:43 +01:00
$nowyear = dol_print_date ( dol_now (), " %Y " );
2020-04-10 10:59:32 +02:00
$year = GETPOST ( 'year' ) > 0 ? GETPOST ( 'year' ) : $nowyear ;
2021-06-14 01:11:39 +02:00
$startyear = $year - ( empty ( $conf -> global -> MAIN_STATS_GRAPHS_SHOW_N_YEARS ) ? 2 : max ( 1 , min ( 10 , $conf -> global -> MAIN_STATS_GRAPHS_SHOW_N_YEARS )));
2020-04-10 10:59:32 +02:00
$endyear = $year ;
2003-11-17 10:53:28 +01:00
2018-05-26 20:51:17 +02:00
// Load translation files required by the page
$langs -> loadLangs ( array ( 'sendings' , 'other' , 'companies' ));
2005-04-04 21:38:17 +02:00
2021-03-21 18:01:43 +01:00
// Security check
if ( $user -> socid ) {
$socid = $user -> socid ;
}
restrictedArea ( $user , 'expedition' );
2005-04-04 21:38:17 +02:00
2011-12-17 15:55:49 +01:00
/*
* View
*/
2020-04-10 10:59:32 +02:00
$form = new Form ( $db );
2013-07-25 15:02:40 +02:00
2003-11-17 10:53:28 +01:00
llxHeader ();
2020-04-20 15:57:15 +02:00
print load_fiche_titre ( $langs -> trans ( " StatisticsOfSendings " ), '' , 'dolly' );
2010-08-14 04:44:07 +02:00
2013-07-25 15:02:40 +02:00
dol_mkdir ( $dir );
2020-04-10 10:59:32 +02:00
$stats = new ExpeditionStats ( $db , $socid , '' , ( $userid > 0 ? $userid : 0 ));
2013-07-25 15:02:40 +02:00
// Build graphic number of object
2019-01-27 11:55:16 +01:00
$data = $stats -> getNbByMonthWithPrevYear ( $endyear , $startyear );
2013-07-25 15:02:40 +02:00
//var_dump($data);exit;
// $data = array(array('Lib',val1,val2,val3),...)
2021-10-22 22:15:59 +02:00
if ( empty ( $user -> rights -> societe -> client -> voir ) || $user -> socid ) {
2020-10-31 14:32:18 +01:00
$filenamenb = $dir . '/shipmentsnbinyear-' . $user -> id . '-' . $year . '.png' ;
2020-05-21 15:05:19 +02:00
} else {
2020-10-31 14:32:18 +01:00
$filenamenb = $dir . '/shipmentsnbinyear-' . $year . '.png' ;
2013-07-25 15:02:40 +02:00
}
$px1 = new DolGraph ();
$mesg = $px1 -> isGraphKo ();
2021-02-25 22:38:35 +01:00
if ( ! $mesg ) {
2020-10-31 14:32:18 +01:00
$px1 -> SetData ( $data );
$i = $startyear ; $legend = array ();
2021-02-25 22:38:35 +01:00
while ( $i <= $endyear ) {
2020-10-31 14:32:18 +01:00
$legend [] = $i ;
$i ++ ;
}
$px1 -> SetLegend ( $legend );
$px1 -> SetMaxValue ( $px1 -> GetCeilMaxValue ());
$px1 -> SetMinValue ( min ( 0 , $px1 -> GetFloorMinValue ()));
$px1 -> SetWidth ( $WIDTH );
$px1 -> SetHeight ( $HEIGHT );
$px1 -> SetYLabel ( $langs -> trans ( " NbOfSendings " ));
$px1 -> SetShading ( 3 );
$px1 -> SetHorizTickIncrement ( 1 );
$px1 -> mode = 'depth' ;
$px1 -> SetTitle ( $langs -> trans ( " NumberOfShipmentsByMonth " ));
$px1 -> draw ( $filenamenb , $fileurlnb );
2013-07-25 15:02:40 +02:00
}
// Build graphic amount of object
/*
$data = $stats -> getAmountByMonthWithPrevYear ( $endyear , $startyear );
//var_dump($data);
// $data = array(array('Lib',val1,val2,val3),...)
2021-10-22 22:15:59 +02:00
if ( empty ( $user -> rights -> societe -> client -> voir ) || $user -> socid )
2013-07-25 15:02:40 +02:00
{
2021-02-25 22:38:35 +01:00
$filenameamount = $dir . '/shipmentsamountinyear-' . $user -> id . '-' . $year . '.png' ;
2013-07-25 15:02:40 +02:00
}
else
{
2021-02-25 22:38:35 +01:00
$filenameamount = $dir . '/shipmentsamountinyear-' . $year . '.png' ;
2013-07-25 15:02:40 +02:00
}
$px2 = new DolGraph ();
$mesg = $px2 -> isGraphKo ();
if ( ! $mesg )
{
2021-02-25 22:38:35 +01:00
$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 ( " AmountOfShipments " ));
$px2 -> SetShading ( 3 );
$px2 -> SetHorizTickIncrement ( 1 );
$px2 -> mode = 'depth' ;
$px2 -> SetTitle ( $langs -> trans ( " AmountOfShipmentsByMonthHT " ));
$px2 -> draw ( $filenameamount , $fileurlamount );
2013-07-25 15:02:40 +02:00
}
*/
/*
$data = $stats -> getAverageByMonthWithPrevYear ( $endyear , $startyear );
2021-10-22 22:15:59 +02:00
if ( empty ( $user -> rights -> societe -> client -> voir ) || $user -> socid )
2013-07-25 15:02:40 +02:00
{
2021-02-25 22:38:35 +01:00
$filename_avg = $dir . '/shipmentsaverage-' . $user -> id . '-' . $year . '.png' ;
2013-07-25 15:02:40 +02:00
}
else
{
2021-02-25 22:38:35 +01:00
$filename_avg = $dir . '/shipmentsaverage-' . $year . '.png' ;
2013-07-25 15:02:40 +02:00
}
$px3 = new DolGraph ();
$mesg = $px3 -> isGraphKo ();
if ( ! $mesg )
{
2021-02-25 22:38:35 +01:00
$px3 -> SetData ( $data );
$i = $startyear ; $legend = array ();
while ( $i <= $endyear )
{
$legend [] = $i ;
$i ++ ;
}
$px3 -> SetLegend ( $legend );
$px3 -> SetYLabel ( $langs -> trans ( " AmountAverage " ));
$px3 -> SetMaxValue ( $px3 -> GetCeilMaxValue ());
$px3 -> SetMinValue ( $px3 -> GetFloorMinValue ());
$px3 -> SetWidth ( $WIDTH );
$px3 -> SetHeight ( $HEIGHT );
$px3 -> SetShading ( 3 );
$px3 -> SetHorizTickIncrement ( 1 );
$px3 -> mode = 'depth' ;
$px3 -> SetTitle ( $langs -> trans ( " AmountAverage " ));
$px3 -> draw ( $filename_avg , $fileurl_avg );
2013-07-25 15:02:40 +02:00
}
*/
// Show array
$data = $stats -> getAllByYear ();
2020-04-10 10:59:32 +02:00
$arrayyears = array ();
foreach ( $data as $val ) {
if ( ! empty ( $val [ 'year' ])) {
$arrayyears [ $val [ 'year' ]] = $val [ 'year' ];
2013-07-25 15:02:40 +02:00
}
}
2021-02-25 22:38:35 +01:00
if ( ! count ( $arrayyears )) {
$arrayyears [ $nowyear ] = $nowyear ;
}
2013-07-25 15:02:40 +02:00
2020-04-10 10:59:32 +02:00
$h = 0 ;
2013-07-25 15:02:40 +02:00
$head = array ();
2020-04-10 10:59:32 +02:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/expedition/stats/index.php' ;
2013-07-25 15:02:40 +02:00
$head [ $h ][ 1 ] = $langs -> trans ( " ByMonthYear " );
$head [ $h ][ 2 ] = 'byyear' ;
$h ++ ;
2020-04-10 10:59:32 +02:00
$type = 'shipment_stats' ;
2013-07-25 15:02:40 +02:00
2019-01-27 11:55:16 +01:00
complete_head_from_modules ( $conf , $langs , null , $head , $h , $type );
2013-07-25 15:02:40 +02:00
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , 'byyear' , $langs -> trans ( " Statistics " ), - 1 );
2013-07-25 15:02:40 +02:00
print '<div class="fichecenter"><div class="fichethirdleft">' ;
2021-06-14 01:11:39 +02:00
// Show filter box
print '<form name="stats" method="POST" action="' . $_SERVER [ " PHP_SELF " ] . '">' ;
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
print '<table class="noborder centpercent">' ;
print '<tr class="liste_titre"><td class="liste_titre" colspan="2">' . $langs -> trans ( " Filter " ) . '</td></tr>' ;
// Company
print '<tr><td class="left">' . $langs -> trans ( " ThirdParty " ) . '</td><td class="left">' ;
print img_picto ( '' , 'company' , 'class="pictofixedwidth"' );
print $form -> select_company ( $socid , 'socid' , '' , 1 , 0 , 0 , array (), 0 , 'widthcentpercentminusx maxwidth300' , '' );
print '</td></tr>' ;
// User
print '<tr><td class="left">' . $langs -> trans ( " CreatedBy " ) . '</td><td class="left">' ;
print img_picto ( '' , 'user' , 'class="pictofixedwidth"' );
print $form -> select_dolusers ( $userid , 'userid' , 1 , '' , 0 , '' , '' , 0 , 0 , 0 , '' , 0 , '' , 'widthcentpercentminusx maxwidth300' );
print '</td></tr>' ;
// Year
print '<tr><td class="left">' . $langs -> trans ( " Year " ) . '</td><td class="left">' ;
2021-02-25 22:38:35 +01:00
if ( ! in_array ( $year , $arrayyears )) {
$arrayyears [ $year ] = $year ;
}
if ( ! in_array ( $nowyear , $arrayyears )) {
$arrayyears [ $nowyear ] = $nowyear ;
}
2021-06-14 01:11:39 +02:00
arsort ( $arrayyears );
2021-12-07 02:35:46 +01:00
print $form -> selectarray ( 'year' , $arrayyears , $year , 0 , 0 , 0 , '' , 0 , 0 , 0 , '' , 'width75' );
2021-06-14 01:11:39 +02:00
print '</td></tr>' ;
print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="' . $langs -> trans ( " Refresh " ) . '"></td></tr>' ;
print '</table>' ;
print '</form>' ;
print '<br><br>' ;
2012-02-12 23:29:31 +01:00
2018-10-26 15:46:17 +02:00
print '<div class="div-table-responsive-no-min">' ;
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">' ;
2016-10-25 02:56:46 +02:00
print '<tr class="liste_titre" height="24">' ;
2019-03-10 09:13:13 +01:00
print '<td class="center">' . $langs -> trans ( " Year " ) . '</td>' ;
print '<td class="right">' . $langs -> trans ( " NbOfSendings " ) . '</td>' ;
/* print '<td class="center">' . $langs -> trans ( " AmountTotal " ) . '</td>' ;
print '<td class="center">' . $langs -> trans ( " AmountAverage " ) . '</td>' ; */
2013-07-25 15:02:40 +02:00
print '</tr>' ;
2020-04-10 10:59:32 +02:00
$oldyear = 0 ;
2021-02-25 22:38:35 +01:00
foreach ( $data as $val ) {
2013-07-25 15:02:40 +02:00
$year = $val [ 'year' ];
2021-02-25 22:38:35 +01:00
while ( ! empty ( $year ) && $oldyear > $year + 1 ) { // If we have empty year
2013-07-25 15:02:40 +02:00
$oldyear -- ;
2018-05-01 10:42:09 +02:00
2017-05-15 16:25:51 +02:00
print '<tr class="oddeven" height="24">' ;
2019-05-21 17:22:38 +02:00
print '<td class="center"><a href="' . $_SERVER [ " PHP_SELF " ] . '?year=' . $oldyear . '">' . $oldyear . '</a></td>' ;
2018-05-01 10:42:09 +02:00
2019-03-10 09:13:13 +01:00
print '<td class="right">0</td>' ;
/* print '<td class="right">0</td>' ;
print '<td class="right">0</td>' ; */
2013-07-25 15:02:40 +02:00
print '</tr>' ;
}
2018-05-01 10:42:09 +02:00
2017-05-15 16:25:51 +02:00
print '<tr class="oddeven" height="24">' ;
2019-03-10 09:13:13 +01:00
print '<td class="center">' ;
2020-10-02 19:54:06 +02:00
if ( $year ) {
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?year=' . $year . '">' . $year . '</a>' ;
} else {
// Technical error that should not happen
print 'Error: validation date of shipment is not defined. This looks strange because shipment is validated. Try to run /install/repair.php?standard=confirmed' ;
}
2016-10-29 17:16:14 +02:00
print '</td>' ;
2019-03-10 09:13:13 +01:00
print '<td class="right">' . $val [ 'nb' ] . '</td>' ;
/* print '<td class="right">' . price ( price2num ( $val [ 'total' ], 'MT' ), 1 ) . '</td>' ;
print '<td class="right">' . price ( price2num ( $val [ 'avg' ], 'MT' ), 1 ) . '</td>' ; */
2013-07-25 15:02:40 +02:00
print '</tr>' ;
2020-04-10 10:59:32 +02:00
$oldyear = $year ;
2013-07-25 15:02:40 +02:00
}
print '</table>' ;
2018-10-26 15:46:17 +02:00
print '</div>' ;
2013-07-25 15:02:40 +02:00
2021-10-24 00:37:37 +02:00
print '</div><div class="fichetwothirdright">' ;
2013-07-25 15:02:40 +02:00
// Show graphs
2019-11-05 21:24:41 +01:00
print '<table class="border centpercent"><tr class="pair nohover"><td class="center">' ;
2021-02-25 22:38:35 +01:00
if ( $mesg ) {
print $mesg ;
} else {
2020-10-31 14:32:18 +01:00
print $px1 -> show ();
print " <br> \n " ;
/* print $px2 -> show ();
2021-02-25 22:38:35 +01:00
print " <br> \n " ;
print $px3 -> show (); */
2013-07-25 15:02:40 +02:00
}
print '</td></tr></table>' ;
2021-10-24 00:37:37 +02:00
print '</div></div>' ;
2013-07-25 15:02:40 +02:00
print '<div style="clear:both"></div>' ;
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2013-07-25 15:02:40 +02:00
// TODO USe code similar to commande/stats/index.php instead of this one.
/*
2019-11-05 21:24:41 +01:00
print '<table class="border centpercent">' ;
2019-03-10 09:13:13 +01:00
print '<tr><td class="center">' . $langs -> trans ( " Year " ) . '</td>' ;
print '<td width="40%" class="center">' . $langs -> trans ( " NbOfSendings " ) . '</td></tr>' ;
2003-11-17 10:53:28 +01:00
2012-02-12 23:29:31 +01:00
$sql = " SELECT count(*) as nb, date_format(date_expedition,'%Y') as dm " ;
2009-12-11 19:30:14 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " expedition " ;
$sql .= " WHERE fk_statut > 0 " ;
$sql .= " AND entity = " . $conf -> entity ;
2012-02-12 23:29:31 +01:00
$sql .= " GROUP BY dm DESC " ;
2009-04-27 22:37:50 +02:00
2010-08-14 04:44:07 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
2003-11-17 10:53:28 +01:00
{
2021-02-25 22:38:35 +01:00
$num = $db -> num_rows ( $resql );
$i = 0 ;
while ( $i < $num )
{
$row = $db -> fetch_row ( $resql );
$nbproduct = $row [ 0 ];
$year = $row [ 1 ];
print " <tr> " ;
print '<td class="center"><a href="month.php?year=' . $year . '">' . $year . '</a></td><td class="center">' . $nbproduct . '</td></tr>' ;
$i ++ ;
}
2003-11-17 10:53:28 +01:00
}
2012-02-12 23:29:31 +01:00
$db -> free ( $resql );
2003-11-17 10:53:28 +01:00
2009-04-27 22:37:50 +02:00
print '</table>' ;
2013-07-25 15:02:40 +02:00
*/
2009-04-27 22:37:50 +02:00
print '<br>' ;
2020-03-23 19:35:14 +01:00
print '<i class="opacitymedium">' . $langs -> trans ( " StatsOnShipmentsOnlyValidated " ) . '</i>' ;
2003-11-17 10:53:28 +01:00
2018-08-02 14:03:50 +02:00
// End of page
2011-08-27 16:24:16 +02:00
llxFooter ();
2011-12-17 15:55:49 +01:00
$db -> close ();