diff --git a/htdocs/core/boxes/box_activity.php b/htdocs/core/boxes/box_activity.php index 5e4267bd12c..ae10ddbdfe2 100644 --- a/htdocs/core/boxes/box_activity.php +++ b/htdocs/core/boxes/box_activity.php @@ -73,17 +73,21 @@ class box_activity extends ModeleBoxes $propalstatic=new Propal($db); $commandestatic=new Commande($db); - $textHead = $langs->trans("Activity")." ".date("Y"); + $textHead = $langs->trans("Activity"); $this->info_box_head = array('text' => $textHead, 'limit'=> dol_strlen($textHead)); // 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"; - $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 (DATE_FORMAT(f.datef,'%Y') = ".date("Y")." or paye=0)"; + // compute the year limit to show + $tmpdate= dol_time_plus_duree(time(), -2, "y"); + + // we select only the payed bill grouped by years + $sql = "SELECT DATE_FORMAT(f.datef,'%Y') as annee, f.paye, 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.fk_soc = s.rowid"; + $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND DATE_FORMAT(f.datef,'%Y') >= ".date('Y',$tmpdate)." and paye=1"; $sql.= " GROUP BY f.paye, f.fk_statut "; $sql.= " ORDER BY f.fk_statut DESC"; @@ -91,8 +95,47 @@ class box_activity extends ModeleBoxes if ($result) { $num = $db->num_rows($result); - $now=dol_now(); $i = 0; + while ($i < $num) + { + $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); + $billurl="viewstatut=2&paye=1&year=".$objp->annee; + + $this->info_box_contents[$i][2] = array('td' => 'align="right"', + 'text' => $objp->nb, 'url' => DOL_URL_ROOT."/compta/facture/liste.php?".$billurl."&mainmenu=accountancy&leftmenu=customers_bills" + ); + + $this->info_box_contents[$i][3] = array('td' => 'align="right"', + 'text' => dol_trunc(number_format($objp->Mnttot, 0, ',', ' '),40)." ".$langs->trans("Currency".$conf->currency) + ); + // We add only for the current year + if ($objp->annee == date("Y")) + { + $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) ); + $i++; + } + if ($num==0) $this->info_box_contents[$i][0] = array('td' => 'align="center"','text'=>$langs->trans("NoRecordedInvoices")); + } + + $sql = "SELECT f.paye, 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.= " ORDER BY f.fk_statut DESC"; + + $result = $db->query($sql); + if ($result) + { + $num = $db->num_rows($result)+$i; + $now=dol_now(); while ($i < $num) { @@ -103,16 +146,7 @@ class box_activity extends ModeleBoxes $this->info_box_contents[$i][1] = array('td' => 'align="left"', 'text' => $langs->trans("Bills")." ".$facturestatic->LibStatut($objp->paye,$objp->fk_statut,0)); - if($objp->fk_statut==0) - { // draft - $billurl="viewstatut=0&paye=0"; - } elseif($objp->fk_statut==1) - { // unpaid - $billurl="viewstatut=1&paye=0"; - } else - { // paid for current year - $billurl="viewstatut=2&paye=1"; - } + $billurl="viewstatut=".$objp->fk_statut."&paye=0"; $this->info_box_contents[$i][2] = array('td' => 'align="right"', 'text' => $objp->nb, 'url' => DOL_URL_ROOT."/compta/facture/list.php?".$billurl."&mainmenu=accountancy&leftmenu=customers_bills" ); @@ -135,6 +169,7 @@ 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"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as c"; $sql.= " WHERE c.entity = ".$conf->entity; @@ -181,7 +216,6 @@ class box_activity extends ModeleBoxes $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p"; $sql.= " WHERE p.entity = ".$conf->entity; $sql.= " AND p.fk_soc = s.rowid"; - $sql.= " AND DATE_FORMAT(p.datep,'%Y') = ".date("Y"); $sql.= " AND p.date_cloture IS NULL "; // just unclosed $sql.= " GROUP BY p.fk_statut"; $sql.= " ORDER BY p.fk_statut DESC";