diff --git a/htdocs/compta/facture/stats/facturestats.class.php b/htdocs/compta/facture/stats/facturestats.class.php index b0c56f0697a..3d5b23b2e6c 100644 --- a/htdocs/compta/facture/stats/facturestats.class.php +++ b/htdocs/compta/facture/stats/facturestats.class.php @@ -82,8 +82,9 @@ class FactureStats extends Stats */ function getNbByYear() { - $sql = "SELECT date_format(datef,'%Y') as dm, count(*)"; - $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." GROUP BY dm DESC"; + $sql = "SELECT YEAR(datef) as dm, count(*)"; + $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql.= " GROUP BY dm DESC"; $sql.= " WHERE ".$this->where; return $this->_getNbByYear($sql); @@ -97,9 +98,9 @@ class FactureStats extends Stats */ function getNbByMonth($year) { - $sql = "SELECT date_format(datef,'%m') as dm, count(*)"; + $sql = "SELECT MONTH(datef) as dm, count(*)"; $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element; - $sql.= " WHERE date_format(datef,'%Y') = ".$year; + $sql.= " WHERE YEAR(datef) = ".$year; $sql.= " AND ".$this->where; $sql.= " GROUP BY dm DESC"; diff --git a/htdocs/compta/facture/stats/index.php b/htdocs/compta/facture/stats/index.php index 773bfbae112..7b3e4926ca5 100644 --- a/htdocs/compta/facture/stats/index.php +++ b/htdocs/compta/facture/stats/index.php @@ -70,9 +70,9 @@ $stats = new FactureStats($db, $socid, $mode); // Build graphic number of object +// $data = array(array('Lib',val1,val2,val3),...) $data = $stats->getNbByMonthWithPrevYear($endyear,$startyear); //var_dump($data); -// $data = array(array('Lib',val1,val2,val3),...) $filenamenb = $dir."/invoicesnbinyear-".$year.".png"; if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=invoicesnbinyear-'.$year.'.png'; diff --git a/htdocs/includes/boxes/box_services_vendus.php b/htdocs/includes/boxes/box_services_vendus.php index 34ccf2c8d11..c0d1e53d3fd 100644 --- a/htdocs/includes/boxes/box_services_vendus.php +++ b/htdocs/includes/boxes/box_services_vendus.php @@ -16,148 +16,145 @@ * 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$ - * $Source$ */ /** - \file htdocs/includes/boxes/box_services_vendus.php - \ingroup produits,services - \brief Module de génération de l'affichage de la box services_vendus -*/ + * \file htdocs/includes/boxes/box_services_vendus.php + * \ingroup produits,services + * \brief Module de génération de l'affichage de la box services_vendus + * \version $Id$ + */ include_once(DOL_DOCUMENT_ROOT."/includes/boxes/modules_boxes.php"); class box_services_vendus extends ModeleBoxes { - var $boxcode="lastproductsincontract"; - var $boximg="object_product"; - var $boxlabel; - var $depends = array("produit","service"); + var $boxcode="lastproductsincontract"; + var $boximg="object_product"; + var $boxlabel; + var $depends = array("produit","service"); var $db; var $param; - var $info_box_head = array(); - var $info_box_contents = array(); + var $info_box_head = array(); + var $info_box_contents = array(); - /** - * \brief Constructeur de la classe - */ - function box_services_vendus() - { - global $langs; - $langs->load("boxes"); + /** + * \brief Constructeur de la classe + */ + function box_services_vendus() + { + global $langs; + $langs->load("boxes"); - $this->boxlabel=$langs->trans("BoxLastProductsInContract"); - } + $this->boxlabel=$langs->trans("BoxLastProductsInContract"); + } - /** - * \brief Charge les données en mémoire pour affichage ultérieur - * \param $max Nombre maximum d'enregistrements à charger - */ - function loadBox($max=5) - { - global $user, $langs, $db, $conf; + /** + * \brief Charge les données en mémoire pour affichage ultérieur + * \param $max Nombre maximum d'enregistrements à charger + */ + function loadBox($max=5) + { + global $user, $langs, $db, $conf; include_once(DOL_DOCUMENT_ROOT."/contrat/contrat.class.php"); - $contratlignestatic=new ContratLigne($db); + $contratlignestatic=new ContratLigne($db); - $this->info_box_head = array('text' => $langs->trans("BoxLastProductsInContract",$max)); + $this->info_box_head = array('text' => $langs->trans("BoxLastProductsInContract",$max)); - if ($user->rights->produit->lire && $user->rights->contrat->lire) - { - $sql = "SELECT s.nom, s.rowid as socid,"; + if ($user->rights->produit->lire && $user->rights->contrat->lire) + { + $sql = "SELECT s.nom, s.rowid as socid,"; $sql.= " c.rowid,"; $sql.= " cd.rowid as cdid, cd.tms as datem, cd.statut,"; $sql.= " p.rowid as pid, p.label, p.fk_product_type"; - if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user"; - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."product as p"; - if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - if ($conf->categorie->enabled && !$user->rights->categorie->voir) - { - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON cp.fk_product = p.rowid"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as ca ON cp.fk_categorie = ca.rowid"; - } - $sql.= " WHERE s.rowid = c.fk_soc AND c.rowid = cd.fk_contrat AND cd.fk_product = p.rowid"; - if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; - if ($conf->categorie->enabled && !$user->rights->categorie->voir) - { + if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user"; + $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."product as p"; + if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + if ($conf->categorie->enabled && !$user->rights->categorie->voir) + { + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON cp.fk_product = p.rowid"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as ca ON cp.fk_categorie = ca.rowid"; + } + $sql.= " WHERE s.rowid = c.fk_soc AND c.rowid = cd.fk_contrat AND cd.fk_product = p.rowid"; + if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; + if ($conf->categorie->enabled && !$user->rights->categorie->voir) + { $sql.= ' AND IFNULL(ca.visible,1)=1'; - } - if($user->societe_id) - { - $sql.= " AND s.rowid = ".$user->societe_id; - } - $sql.= " ORDER BY c.tms DESC "; - $sql.= $db->plimit($max, 0); - - $result = $db->query($sql); - - if ($result) - { - $num = $db->num_rows($result); - - $i = 0; - - while ($i < $num) - { - $objp = $db->fetch_object($result); - - // Multilangs - if ($conf->global->MAIN_MULTILANGS) // si l'option est active - { - $sqld = "SELECT label FROM ".MAIN_DB_PREFIX."product_det"; - $sqld.= " WHERE fk_product=".$objp->pid." AND lang='". $langs->getDefaultLang() ."'"; - $sqld.= " LIMIT 1"; + } + if($user->societe_id) + { + $sql.= " AND s.rowid = ".$user->societe_id; + } + $sql.= " ORDER BY c.tms DESC "; + $sql.= $db->plimit($max, 0); - $resultd = $db->query($sqld); - if ($resultd) - { - $objtp = $db->fetch_object($resultd); - if ($objtp->label != '') $objp->label = $objtp->label; - } - } - - $this->info_box_contents[$i][0] = array('align' => 'left', + $result = $db->query($sql); + if ($result) + { + $num = $db->num_rows($result); + + $i = 0; + + while ($i < $num) + { + $objp = $db->fetch_object($result); + + // Multilangs + if ($conf->global->MAIN_MULTILANGS) // si l'option est active + { + $sqld = "SELECT label FROM ".MAIN_DB_PREFIX."product_det"; + $sqld.= " WHERE fk_product=".$objp->pid." AND lang='". $langs->getDefaultLang() ."'"; + $sqld.= " LIMIT 1"; + + $resultd = $db->query($sqld); + if ($resultd) + { + $objtp = $db->fetch_object($resultd); + if ($objtp->label != '') $objp->label = $objtp->label; + } + } + + $this->info_box_contents[$i][0] = array('align' => 'left', 'logo' => ($objp->fk_product_type==1?'object_service':'object_product'), 'text' => $objp->label, 'maxlength' => 16, 'url' => DOL_URL_ROOT."/contrat/fiche.php?id=".$objp->rowid); - - $this->info_box_contents[$i][1] = array('align' => 'left', + + $this->info_box_contents[$i][1] = array('align' => 'left', 'text' => $objp->nom, 'maxlength' => 40, 'url' => DOL_URL_ROOT."/comm/fiche.php?socid=".$objp->socid); - $this->info_box_contents[$i][2] = array('align' => 'right', + $this->info_box_contents[$i][2] = array('align' => 'right', 'text' => dolibarr_print_date($objp->datem,'day')); - $this->info_box_contents[$i][3] = array('align' => 'right', + $this->info_box_contents[$i][3] = array('align' => 'right', 'text' => $contratlignestatic->LibStatut($objp->statut,3), 'width' => 18 - ); - - $i++; - } - } - else { - dolibarr_print_error($db); - } - } - else { - $this->info_box_contents[0][0] = array('align' => 'left', + ); + + $i++; + } + } + else { + dolibarr_print_error($db); + } + } + else { + $this->info_box_contents[0][0] = array('align' => 'left', 'text' => $langs->trans("ReadPermissionNotAllowed")); - } - - } + } - function showBox() - { - parent::showBox($this->info_box_head, $this->info_box_contents); - } + } + + function showBox() + { + parent::showBox($this->info_box_head, $this->info_box_contents); + } } diff --git a/htdocs/includes/boxes/modules_boxes.php b/htdocs/includes/boxes/modules_boxes.php index 54a29d9140c..64e75b866a0 100644 --- a/htdocs/includes/boxes/modules_boxes.php +++ b/htdocs/includes/boxes/modules_boxes.php @@ -209,17 +209,12 @@ class ModeleBoxes $maxlength=$this->MAXLENGTHBOX; if (isset($contents[$i][$j]['maxlength'])) $maxlength=$contents[$i][$j]['maxlength']; - if ($maxlength && strlen($textewithnotags) > $maxlength) - { - $texte=substr($texte,0,$maxlength)."..."; - } - if ($maxlength && strlen($texte2withnotags) > $maxlength) - { - $texte2=substr($texte2,0,$maxlength)."..."; - } - print $texte; + if ($maxlength) $textewithnotags=dolibarr_trunc($textewithnotags,$maxlength); + print $textewithnotags; + + //print $texte; if (isset($contents[$i][$j]['url'])) print ''; - print $texte2; + print $texte2withnotags; print ""; } diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php index ef018e8d6a8..f4f06fb895f 100644 --- a/htdocs/lib/functions.lib.php +++ b/htdocs/lib/functions.lib.php @@ -844,6 +844,60 @@ function dol_print_phone_link($phone,$option=0) return $link; } + +/** + * Make a strlen call. Works even in mbstring module not enabled + * + * @param unknown_type $string + * @param unknown_type $stringencoding + * @return unknown + */ +function dol_strlen($string,$stringencoding='') +{ + global $langs; + + if (empty($stringencoding)) $stringencoding=$langs->charset_output; + + $ret=''; + if (function_exists('mb_strlen')) + { + $ret=mb_strlen($string,$stringencoding); + } + else + { + $ret=strlen($string); + } + return $ret; +} + +/** + * Make a substring. Works even in mbstring module not enabled + * + * @param unknown_type $string + * @param unknown_type $start + * @param unknown_type $length + * @param unknown_type $stringencoding + * @return unknown + */ +function dol_substr($string,$start,$length,$stringencoding='') +{ + global $langs; + + if (empty($stringencoding)) $stringencoding=$langs->charset_output; + + $ret=''; + if (function_exists('mb_substr')) + { + $ret=mb_substr($string,$start,$length,$stringencoding); + } + else + { + $ret=substr($string,$start,$length); + } + return $ret; +} + + /** * \brief Truncate a string to a particular length adding '...' if string larger than length * \param string String to truncate @@ -852,7 +906,7 @@ function dol_print_phone_link($phone,$option=0) * \return string Truncated string * \remarks USE_SHORT_TITLE=0 can disable all truncings */ -function dolibarr_trunc($string,$size=40,$trunc='right') +function dolibarr_trunc($string,$size=40,$trunc='right',$stringencoding='') { global $conf; @@ -862,29 +916,26 @@ function dolibarr_trunc($string,$size=40,$trunc='right') // We go always here if ($trunc == 'right') { - //mb_internal_encoding("UTF-8"); - //print $conf->character_set_client.'-'.mb_strlen($string).'-'.strlen($string); - //print 'ee'.$string.$size.mb_strcut($string,0,$size,'UTF-8').'rr'; - if (strlen($string) > $size) - return substr($string,0,$size).'...'; + if (dol_strlen($string,$stringencoding) > $size) + return dol_substr($string,0,$size,$stringencoding).'...'; else return $string; } if ($trunc == 'middle') { - if (strlen($string) > 2 && strlen($string) > $size) + if (dol_strlen($string,$stringencoding) > 2 && dol_strlen($string,$stringencoding) > $size) { $size1=round($size/2); $size2=round($size/2); - return substr($string,0,$size1).'...'.substr($string,strlen($string) - $size2,$size2); + return dol_substr($string,0,$size1,$stringencoding).'...'.dol_substr($string,dol_strlen($string,$stringencoding) - $size2,$size2,$stringencoding); } else return $string; } if ($trunc == 'left') { - if (strlen($string) > $size) - return '...'.substr($string,strlen($string) - $size,$size); + if (dol_strlen($string,$stringencoding) > $size) + return '...'.dol_substr($string,dol_strlen($string,$stringencoding) - $size,$size,$stringencoding); else return $string; } @@ -896,12 +947,12 @@ function dolibarr_trunc($string,$size=40,$trunc='right') } /** - \brief Compl�te une chaine a une taille donn�e par des espaces - \param string Chaine a compl�ter - \param size Longueur de la chaine. - \param side 0=Compl�tion a droite, 1=Compl�tion a gauche - \param char Chaine de compl�tion - \return string Chaine compl�t�e + * \brief Complete une chaine a une taille donnee par des espaces + * \param string Chaine a completer + * \param size Longueur de la chaine. + * \param side 0=Completion a droite, 1=Completion a gauche + * \param char Chaine de completion + * \return string Chaine complete */ function dolibarr_pad($string,$size,$side,$char=' ') { @@ -917,10 +968,10 @@ function dolibarr_pad($string,$size,$side,$char=' ') } /** - \brief Affiche picto propre a une notion/module (fonction g�n�rique) - \param alt Texte sur le alt de l'image - \param object Objet pour lequel il faut afficher le logo (exemple: user, group, action, bill, contract, propal, product, ...) - \return string Retourne tag img + * \brief Affiche picto propre a une notion/module (fonction g�n�rique) + * \param alt Texte sur le alt de l'image + * \param object Objet pour lequel il faut afficher le logo (exemple: user, group, action, bill, contract, propal, product, ...) + * \return string Retourne tag img */ function img_object($alt, $object) { diff --git a/htdocs/stats.class.php b/htdocs/stats.class.php index f3c66afcdc4..f9b43a5a092 100644 --- a/htdocs/stats.class.php +++ b/htdocs/stats.class.php @@ -191,7 +191,11 @@ class Stats } $this->db->free($resql); } - + else + { + dolibarr_print_error($this->db); + } + for ($i = 1 ; $i < 13 ; $i++) { $res[$i] = $result[$i] + 0; @@ -201,7 +205,9 @@ class Stats for ($i = 1 ; $i < 13 ; $i++) { - $data[$i-1] = array(ucfirst(substr(dolibarr_print_date(dolibarr_mktime(12,0,0,$i,1,$year),"%b"),0,3)), $res[$i]); + $month=dolibarr_print_date(dolibarr_mktime(12,0,0,$i,1,$year),"%b"); + $month=dol_substr($month,0,3); + $data[$i-1] = array(ucfirst($month), $res[$i]); } return $data; @@ -241,14 +247,16 @@ class Stats for ($i = 1 ; $i < 13 ; $i++) { - $data[$i-1] = array(ucfirst(substr(dolibarr_print_date(dolibarr_mktime(12,0,0,$i,1,$year),"%b"),0,3)), $res[$i]); + $month=dolibarr_print_date(dolibarr_mktime(12,0,0,$i,1,$year),"%b"); + $month=dol_substr($month,0,3); + $data[$i-1] = array(ucfirst($month), $res[$i]); } return $data; } /** - * + * \brief Renvoie le montant moyen par mois pour une annee donnee * */ function _getAverageByMonth($year, $sql)