From 70e051a1bf01c953e6e474f85719376e5a8aee1b Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Thu, 4 Feb 2016 18:05:35 +0100 Subject: [PATCH 1/7] Add goods customers boxes --- htdocs/core/boxes/box_bonsclients.php | 168 ++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 htdocs/core/boxes/box_bonsclients.php diff --git a/htdocs/core/boxes/box_bonsclients.php b/htdocs/core/boxes/box_bonsclients.php new file mode 100644 index 00000000000..0f650e6775c --- /dev/null +++ b/htdocs/core/boxes/box_bonsclients.php @@ -0,0 +1,168 @@ + + * Copyright (C) 2004-2010 Laurent Destailleur + * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2015 Frederic France + * Copyright (C) 2016 Charlie Benke + * + * 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 3 of the License, or + * (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 + * along with this program. If not, see . + */ + +/** + * \file htdocs/core/boxes/box_clients.php + * \ingroup societes + * \brief Module de generation de l'affichage de la box clients + */ + +include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php'; + + +/** + * Class to manage the box to show last thirdparties + */ +class box_bonsclients extends ModeleBoxes +{ + var $boxcode="goodcustomers"; + var $boximg="object_company"; + var $boxlabel="BoxGoodCustomers"; + var $depends = array("societe"); + + var $db; + var $enabled = 1; + + var $info_box_head = array(); + var $info_box_contents = array(); + + + /** + * Constructor + * + * @param DoliDB $db Database handler + * @param string $param More parameters + */ + function __construct($db,$param='') + { + global $conf, $user; + + $this->db = $db; + + // disable box for such cases + if (! empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) $this->enabled=0; // disabled by this option + } + + /** + * Load data for box to show them later + * + * @param int $max Maximum number of records to load + * @return void + */ + function loadBox($max=5) + { + global $user, $langs, $db, $conf; + $langs->load("boxes"); + + $this->max=$max; + + include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; + $thirdpartystatic=new Societe($db); + + $this->info_box_head = array('text' => $langs->trans("BoxTitleGoodCustomers",$max)); + + if ($user->rights->societe->lire) + { + + $sql = "SELECT s.rowid, s.nom as name, s.logo, s.code_client, s.code_fournisseur, s.client, s.fournisseur, s.tms as datem, s.status as status,"; + $sql.= " count(*) as nbfact, sum(if (f.paye=1,1,0)) as nbfactpaye"; + $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture as f"; + $sql.= ' WHERE s.entity IN ('.getEntity('societe', 1).')'; + $sql.= ' AND s.rowid = f.fk_soc'; + $sql.= " GROUP BY s.rowid, s.nom, s.logo, s.code_client, s.code_fournisseur, s.client, s.fournisseur, s.tms, s.status"; + $sql.= $db->order("nbfact","DESC"); + $sql.= $db->plimit($max,0); + + dol_syslog(get_class($this)."::loadBox", LOG_DEBUG); + $result = $db->query($sql); + if ($result) + { + $num = $db->num_rows($result); + + $line = 0; + while ($line < $num) + { + $objp = $db->fetch_object($result); + $datem=$db->jdate($objp->tms); + $thirdpartystatic->id = $objp->rowid; + $thirdpartystatic->name = $objp->name; + $thirdpartystatic->code_client = $objp->code_client; + $thirdpartystatic->code_fournisseur = $objp->code_fournisseur; + $thirdpartystatic->client = $objp->client; + $thirdpartystatic->fournisseur = $objp->fournisseur; + $thirdpartystatic->logo = $objp->logo; + $nbfact = $objp->nbfact; + $nbimpaye = $objp->nbfact - $objp->nbfactpaye; + + $this->info_box_contents[$line][] = array( + 'td' => 'align="left"', + 'text' => $thirdpartystatic->getNomUrl(1), + 'asis' => 1, + ); + + $this->info_box_contents[$line][] = array( + 'td' => 'align="right"', + 'text' => dol_print_date($datem, "day") + ); + + $this->info_box_contents[$line][] = array( + 'td' => 'align="right"', + 'text' => $nbfact.( $nbimpaye != 0 ? ' ('.$nbimpaye.')':'') + ); + + $this->info_box_contents[$line][] = array( + 'td' => 'align="right" width="18"', + 'text' => $thirdpartystatic->LibStatut($objp->status,3) + ); + + $line++; + } + + if ($num==0) $this->info_box_contents[$line][0] = array('td' => 'align="center"','text'=>$langs->trans("NoRecordedCustomers")); + + $db->free($result); + } + else { + $this->info_box_contents[0][0] = array( 'td' => 'align="left"', + 'maxlength'=>500, + 'text' => ($db->error().' sql='.$sql)); + } + } + else { + $this->info_box_contents[0][0] = array('align' => 'left', + 'text' => $langs->trans("ReadPermissionNotAllowed")); + } + + } + + /** + * Method to show box + * + * @param array $head Array with properties of box title + * @param array $contents Array with properties of box lines + * @return void + */ + function showBox($head = null, $contents = null) + { + parent::showBox($this->info_box_head, $this->info_box_contents); + } +} + From 5498b1cd5a9362b61e0950c5006db874af235d5b Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Thu, 4 Feb 2016 18:06:43 +0100 Subject: [PATCH 2/7] Update modSociete.class.php --- htdocs/core/modules/modSociete.class.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/htdocs/core/modules/modSociete.class.php b/htdocs/core/modules/modSociete.class.php index 41fd00e5463..b8032cca13e 100644 --- a/htdocs/core/modules/modSociete.class.php +++ b/htdocs/core/modules/modSociete.class.php @@ -131,7 +131,9 @@ class modSociete extends DolibarrModules $this->boxes[$r][1] = "box_activity.php"; $this->boxes[$r][2] = '(WarningUsingThisBoxSlowDown)'; $r++; - + $this->boxes[$r][1] = "box_bonsclients.php"; + $this->boxes[$r][2] = '(WarningUsingThisBoxSlowDown)'; + $r++; // Permissions $this->rights = array(); $this->rights_class = 'societe'; From 9c896b18699834f331dbccb1bf404b042e8e41b1 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Thu, 4 Feb 2016 18:10:28 +0100 Subject: [PATCH 3/7] translations too --- htdocs/langs/en_US/boxes.lang | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/htdocs/langs/en_US/boxes.lang b/htdocs/langs/en_US/boxes.lang index 796c058e3b5..6afc6d7b7b2 100644 --- a/htdocs/langs/en_US/boxes.lang +++ b/htdocs/langs/en_US/boxes.lang @@ -60,6 +60,8 @@ BoxTitleLastContracts=Last %s contracts BoxTitleLastModifiedDonations=Last %s modified donations BoxTitleLastModifiedExpenses=Last %s modified expense reports BoxGlobalActivity=Global activity (invoices, proposals, orders) +BoxGoodCustomers=Good Customers +BoxTitleGoodCustomers= %s Good Customers FailedToRefreshDataInfoNotUpToDate=Failed to refresh RSS flux. Last successfull refresh date: %s LastRefreshDate=Last refresh date NoRecordedBookmarks=No bookmarks defined. @@ -95,4 +97,4 @@ ForCustomersInvoices=Customers invoices ForCustomersOrders=Customers orders ForProposals=Proposals LastXMonthRolling=The last %s month rolling -ChooseBoxToAdd=Add a box to your dashboard... \ No newline at end of file +ChooseBoxToAdd=Add a box to your dashboard... From eb48e84b34217167d18d84534d2c3d353b148d17 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Fri, 5 Feb 2016 23:37:04 +0100 Subject: [PATCH 4/7] name of boxe file changed --- .../core/boxes/{box_bonsclients.php => box_goodcustomers.php} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename htdocs/core/boxes/{box_bonsclients.php => box_goodcustomers.php} (99%) diff --git a/htdocs/core/boxes/box_bonsclients.php b/htdocs/core/boxes/box_goodcustomers.php similarity index 99% rename from htdocs/core/boxes/box_bonsclients.php rename to htdocs/core/boxes/box_goodcustomers.php index 0f650e6775c..734d1885824 100644 --- a/htdocs/core/boxes/box_bonsclients.php +++ b/htdocs/core/boxes/box_goodcustomers.php @@ -31,7 +31,7 @@ include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php'; /** * Class to manage the box to show last thirdparties */ -class box_bonsclients extends ModeleBoxes +class box_goodcustomers extends ModeleBoxes { var $boxcode="goodcustomers"; var $boximg="object_company"; From e2afe5460e1fb6210b7ae6bad8a566da88d00aa1 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Fri, 5 Feb 2016 23:37:31 +0100 Subject: [PATCH 5/7] Update modSociete.class.php --- htdocs/core/modules/modSociete.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/modules/modSociete.class.php b/htdocs/core/modules/modSociete.class.php index b8032cca13e..f0d04d30990 100644 --- a/htdocs/core/modules/modSociete.class.php +++ b/htdocs/core/modules/modSociete.class.php @@ -131,7 +131,7 @@ class modSociete extends DolibarrModules $this->boxes[$r][1] = "box_activity.php"; $this->boxes[$r][2] = '(WarningUsingThisBoxSlowDown)'; $r++; - $this->boxes[$r][1] = "box_bonsclients.php"; + $this->boxes[$r][1] = "box_goodcustomers.php"; $this->boxes[$r][2] = '(WarningUsingThisBoxSlowDown)'; $r++; // Permissions From 59c9d8527509cb2141118d9ac509a60826d48951 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Fri, 5 Feb 2016 23:38:04 +0100 Subject: [PATCH 6/7] Update boxes.lang --- htdocs/langs/en_US/boxes.lang | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/langs/en_US/boxes.lang b/htdocs/langs/en_US/boxes.lang index 6afc6d7b7b2..57bfc174ec5 100644 --- a/htdocs/langs/en_US/boxes.lang +++ b/htdocs/langs/en_US/boxes.lang @@ -61,7 +61,7 @@ BoxTitleLastModifiedDonations=Last %s modified donations BoxTitleLastModifiedExpenses=Last %s modified expense reports BoxGlobalActivity=Global activity (invoices, proposals, orders) BoxGoodCustomers=Good Customers -BoxTitleGoodCustomers= %s Good Customers +BoxTitleGoodCustomers=%s Good Customers FailedToRefreshDataInfoNotUpToDate=Failed to refresh RSS flux. Last successfull refresh date: %s LastRefreshDate=Last refresh date NoRecordedBookmarks=No bookmarks defined. From c672ad9fed2cff80b4d501ff366db636b0b05a17 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Mon, 8 Feb 2016 15:00:49 +0100 Subject: [PATCH 7/7] Update box_goodcustomers.php --- htdocs/core/boxes/box_goodcustomers.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/boxes/box_goodcustomers.php b/htdocs/core/boxes/box_goodcustomers.php index 734d1885824..609eabdbc7a 100644 --- a/htdocs/core/boxes/box_goodcustomers.php +++ b/htdocs/core/boxes/box_goodcustomers.php @@ -83,7 +83,7 @@ class box_goodcustomers extends ModeleBoxes { $sql = "SELECT s.rowid, s.nom as name, s.logo, s.code_client, s.code_fournisseur, s.client, s.fournisseur, s.tms as datem, s.status as status,"; - $sql.= " count(*) as nbfact, sum(if (f.paye=1,1,0)) as nbfactpaye"; + $sql.= " count(*) as nbfact, sum(". $db->if('f.paye=1','1','0').") as nbfactpaye"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture as f"; $sql.= ' WHERE s.entity IN ('.getEntity('societe', 1).')'; $sql.= ' AND s.rowid = f.fk_soc';