From ec5b4f5fa758e80cd2aa5daeca60672e2111cbfd Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 15 Jan 2013 15:36:04 +0100 Subject: [PATCH] Fix: Start to fix some bug (pgsql compatibility), try to optimize request. Added FIXME tags. --- htdocs/core/boxes/box_activity.php | 58 ++++++++++++++++++------------ 1 file changed, 35 insertions(+), 23 deletions(-) diff --git a/htdocs/core/boxes/box_activity.php b/htdocs/core/boxes/box_activity.php index 7839f4c30aa..adbc2c7090a 100644 --- a/htdocs/core/boxes/box_activity.php +++ b/htdocs/core/boxes/box_activity.php @@ -1,5 +1,7 @@ +/* Copyright (C) 2012 Charles-François BENKE + * Copyright (C) 2005-2013 Laurent Destailleur + * * 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 2 of the License, or @@ -31,10 +33,11 @@ class box_activity extends ModeleBoxes var $boximg="object_bill"; var $boxlabel; var $depends = array("facture"); - + var $db; var $param; - + var $enabled = 1; + var $info_box_head = array(); var $info_box_contents = array(); @@ -43,7 +46,7 @@ class box_activity extends ModeleBoxes */ function __construct() { - global $langs; + global $langs,$conf; $langs->load("boxes"); $langs->load("bills"); @@ -51,6 +54,12 @@ class box_activity extends ModeleBoxes $langs->load("orders"); $this->boxlabel = $langs->transnoentitiesnoconv("BoxGlobalActivity"); + + // Disabled by default because, still has some bug (pgsl support, filters) and slow down seriously Dolibarr + $this->enabled = (! empty($conf->global->MAIN_FEATURES_LEVEL) || ! empty($conf->global->MAIN_BOX_ACTIVITY_ENABLED)); + // FIXME: Use a cache to save data because this slow down too much main home page. This box slow down too seriously software. + // FIXME: Removed number_format (not compatible with all languages) + // FIXME: Pb into some status } /** @@ -66,13 +75,7 @@ class box_activity extends ModeleBoxes $totalMnt = 0; $totalnb = 0; - include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; - include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; - include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; - $facturestatic=new Facture($db); - $propalstatic=new Propal($db); - $commandestatic=new Commande($db); $nbofyears=2; if (! empty($conf->global->MAIN_BOX_ACTIVITY_DURATION)) $nbofyears=$conf->global->MAIN_BOX_ACTIVITY_DURATION; @@ -80,12 +83,15 @@ class box_activity extends ModeleBoxes $this->info_box_head = array('text' => $textHead, 'limit'=> dol_strlen($textHead)); // compute the year limit to show - $tmpdate= dol_time_plus_duree(time(), -1*$nbofyears, "y"); + $tmpdate= dol_time_plus_duree(dol_now(), -1*$nbofyears, "y"); // list the summary of the bills if (! empty($conf->facture->enabled) && $user->rights->facture->lire) { - $sql = "SELECT f.paye, f.fk_statut, SUM(f.total_ttc) as Mnttot, COUNT(*) as nb"; + include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; + $facturestatic=new Facture($db); + + $sql = "SELECT f.fk_statut, SUM(f.total_ttc) as Mnttot, COUNT(*) as nb"; $sql.= " FROM (".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= ")"; @@ -94,7 +100,7 @@ class box_activity extends ModeleBoxes if($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id; $sql.= " AND f.fk_soc = s.rowid"; $sql.= " AND f.datef >= '".$db->idate($tmpdate)."' AND paye=1"; - $sql.= " GROUP BY f.paye, f.fk_statut "; + $sql.= " GROUP BY f.fk_statut"; $sql.= " ORDER BY f.fk_statut DESC"; $result = $db->query($sql); @@ -107,7 +113,7 @@ class box_activity extends ModeleBoxes $this->info_box_contents[$i][0] = array('td' => 'align="left" width="16"', 'logo' => 'bill'); $objp = $db->fetch_object($result); - $this->info_box_contents[$i][1] = array('td' => 'align="left"', 'text' => $langs->trans("Bills")." ".$facturestatic->LibStatut($objp->paye,$objp->fk_statut,0)." ".$objp->annee); + $this->info_box_contents[$i][1] = array('td' => 'align="left"', 'text' => $langs->trans("Bills")." ".$facturestatic->LibStatut(1,$objp->fk_statut,0)." ".$objp->annee); $billurl="viewstatut=2&paye=1&year=".$objp->annee; $this->info_box_contents[$i][2] = array('td' => 'align="right"', @@ -123,19 +129,19 @@ class box_activity extends ModeleBoxes $totalnb += $objp->nb; $totalMnt += $objp->Mnttot; } - $this->info_box_contents[$i][4] = array('td' => 'align="right" width="18"', 'text' => $facturestatic->LibStatut($objp->paye,$objp->fk_statut,3) ); + $this->info_box_contents[$i][4] = array('td' => 'align="right" width="18"', 'text' => $facturestatic->LibStatut(1,$objp->fk_statut,3) ); $i++; } if ($num==0) $this->info_box_contents[$i][0] = array('td' => 'align="center"','text'=>$langs->trans("NoRecordedInvoices")); } else dol_print_error($db); - $sql = "SELECT f.paye, f.fk_statut, SUM(f.total_ttc) as Mnttot, COUNT(*) as nb"; + $sql = "SELECT f.fk_statut, SUM(f.total_ttc) as Mnttot, COUNT(*) as nb"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f"; $sql.= " WHERE f.entity = ".$conf->entity; $sql.= " AND f.fk_soc = s.rowid"; $sql.= " AND paye=0"; - $sql.= " GROUP BY f.paye, f.fk_statut "; + $sql.= " GROUP BY f.fk_statut"; $sql.= " ORDER BY f.fk_statut DESC"; $result = $db->query($sql); @@ -151,7 +157,7 @@ class box_activity extends ModeleBoxes $objp = $db->fetch_object($result); $this->info_box_contents[$i][1] = array('td' => 'align="left"', - 'text' => $langs->trans("Bills")." ".$facturestatic->LibStatut($objp->paye,$objp->fk_statut,0)); + 'text' => $langs->trans("Bills")." ".$facturestatic->LibStatut(0,$objp->fk_statut,0)); $billurl="viewstatut=".$objp->fk_statut."&paye=0"; $this->info_box_contents[$i][2] = array('td' => 'align="right"', @@ -163,7 +169,7 @@ class box_activity extends ModeleBoxes ); $totalMnt += $objp->Mnttot; $this->info_box_contents[$i][4] = array('td' => 'align="right" width="18"', - 'text' => $facturestatic->LibStatut($objp->paye,$objp->fk_statut,3) + 'text' => $facturestatic->LibStatut(0,$objp->fk_statut,3) ); $i++; } @@ -176,7 +182,10 @@ class box_activity extends ModeleBoxes // list the summary of the orders if (! empty($conf->commande->enabled) && $user->rights->commande->lire) { - $sql = "SELECT c.fk_statut,c.facture, sum(c.total_ttc) as Mnttot, count(*) as nb"; + include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; + $commandestatic=new Commande($db); + + $sql = "SELECT c.fk_statut, sum(c.total_ttc) as Mnttot, count(*) as nb"; $sql.= " FROM (".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as c"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= ")"; @@ -200,7 +209,7 @@ class box_activity extends ModeleBoxes $objp = $db->fetch_object($result); $this->info_box_contents[$i][1] = array('td' => 'align="left"', - 'text' =>$langs->trans("Orders")." ".$commandestatic->LibStatut($objp->fk_statut,$objp->facture,0) + 'text' =>$langs->trans("Orders")." ".$commandestatic->LibStatut($objp->fk_statut,0,0) ); $this->info_box_contents[$i][2] = array('td' => 'align="right"', @@ -213,7 +222,7 @@ class box_activity extends ModeleBoxes 'text' => dol_trunc(number_format($objp->Mnttot, 0, ',', ' '),40)." ".getCurrencySymbol($conf->currency) ); $totalMnt += $objp->Mnttot; - $this->info_box_contents[$i][4] = array('td' => 'align="right" width="18"', 'text' => $commandestatic->LibStatut($objp->fk_statut,$objp->facture,3)); + $this->info_box_contents[$i][4] = array('td' => 'align="right" width="18"', 'text' => $commandestatic->LibStatut($objp->fk_statut,0,3)); $i++; } @@ -224,7 +233,10 @@ class box_activity extends ModeleBoxes // list the summary of the propals if (! empty($conf->propal->enabled) && $user->rights->propal->lire) { - $sql = "SELECT p.fk_statut, sum(p.total) as Mnttot, count(*) as nb"; + include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; + $propalstatic=new Propal($db); + + $sql = "SELECT p.fk_statut, SUM(p.total) as Mnttot, COUNT(*) as nb"; $sql.= " FROM (".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= ")";