diff --git a/htdocs/core/boxes/box_funnel_of_prospection.php b/htdocs/core/boxes/box_funnel_of_prospection.php new file mode 100644 index 00000000000..c4cebfcf68a --- /dev/null +++ b/htdocs/core/boxes/box_funnel_of_prospection.php @@ -0,0 +1,268 @@ + + * Copyright (C) 2014 Marcos García + * Copyright (C) 2015 Frederic France + * Copyright (C) 2016 Juan José Menent + * Copyright (C) 2020 Pierre Ardoin + * + * 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_funnel_of_prospection.php + * \ingroup projet + * \brief Module to show the funnel of prospection + */ +include_once DOL_DOCUMENT_ROOT . "/core/boxes/modules_boxes.php"; + +/** + * Class to manage the box to show last projet + */ +class box_funnel_of_prospection extends ModeleBoxes +{ + public $boxcode = "FunnelOfProspection"; + public $boximg = "object_projectpub"; + public $boxlabel = "BoxTitleFunnelOfProspection"; + public $depends = array("projet"); + + /** + * @var DoliDB Database handler. + */ + public $db; + + public $param; + + public $info_box_head = array(); + public $info_box_contents = array(); + + /** + * Constructor + * + * @param DoliDB $db Database handler + * @param string $param More parameters + */ + public function __construct($db, $param = '') + { + global $user, $langs, $conf; + + // Load translation files required by the page + $langs->loadLangs(array('boxes', 'projects')); + + $this->db = $db; + + $this->hidden = !($user->rights->projet->lire); + } + + /** + * Load data for box to show them later + * + * @param int $max Maximum number of records to load + * @return void + */ + public function loadBox($max = 5) + { + global $conf; + include DOL_DOCUMENT_ROOT . '/theme/' . $conf->theme . '/theme_vars.inc.php'; + $listofoppstatus = array(); + $listofopplabel = array(); + $listofoppcode = array(); + $colorseriesstat = array(); + $sql = "SELECT cls.rowid, cls.code, cls.percent, cls.label"; + $sql .= " FROM " . MAIN_DB_PREFIX . "c_lead_status as cls"; + $sql .= " WHERE active=1"; + $resql = $this->db->query($sql); + if ($resql) { + $num = $this->db->num_rows($resql); + $i = 0; + + while ($i < $num) { + $objp = $this->db->fetch_object($resql); + $listofoppstatus[$objp->rowid] = $objp->percent; + $listofopplabel[$objp->rowid] = $objp->label; + $listofoppcode[$objp->rowid] = $objp->code; + switch ($objp->code) { + case 'PROSP': + $colorseriesstat[$objp->rowid] = "-" . $badgeStatus0; + break; + case 'QUAL': + $colorseriesstat[$objp->rowid] = "-" . $badgeStatus1; + break; + case 'PROPO': + $colorseriesstat[$objp->rowid] = $badgeStatus1; + break; + case 'NEGO': + $colorseriesstat[$objp->rowid] = $badgeStatus4; + break; + case 'WON': + $colorseriesstat[$objp->rowid] = $badgeStatus6; + break; + default: + $colorseriesstat[$objp->rowid] = $badgeStatus2; + break; + } + $i++; + } + } else dol_print_error($this->db); + + global $conf, $user, $langs; + + $this->max = $max; + + $this->info_box_head = array( + 'text' => $langs->trans("Statistics") . ' - ' . $langs->trans("OpportunitiesStatusForOpenedProjects"), + $max + ); + + if ($user->rights->projet->lire || !empty($conf->global->PROJECT_USE_OPPORTUNITIES)) { + $sql = "SELECT p.fk_opp_status as opp_status, cls.code, COUNT(p.rowid) as nb, SUM(p.opp_amount) as opp_amount, SUM(p.opp_amount * p.opp_percent) as ponderated_opp_amount"; + $sql .= " FROM " . MAIN_DB_PREFIX . "projet as p, " . MAIN_DB_PREFIX . "c_lead_status as cls"; + $sql .= " WHERE p.entity IN (" . getEntity('project') . ")"; + $sql .= " AND p.fk_opp_status = cls.rowid"; + $sql .= " AND p.fk_statut = 1"; // Opend projects only + $sql .= " AND cls.code NOT IN ('LOST')"; + $sql .= " GROUP BY p.fk_opp_status, cls.code"; + $resql = $this->db->query($sql); + + $form = new Form($ths->db); + if ($resql) { + $num = $this->db->num_rows($resql); + $i = 0; + + $totalnb = 0; + $totaloppnb = 0; + $totalamount = 0; + $ponderated_opp_amount = 0; + $valsnb = array(); + $valsamount = array(); + $dataseries = array(); + + while ($i < $num) { + $obj = $this->db->fetch_object($resql); + if ($obj) { + $valsnb[$obj->opp_status] = $obj->nb; + $valsamount[$obj->opp_status] = $obj->opp_amount; + $totalnb += $obj->nb; + if ($obj->opp_status) $totaloppnb += $obj->nb; + if (!in_array($obj->code, array('WON', 'LOST'))) { + $totalamount += $obj->opp_amount; + $ponderated_opp_amount += $obj->ponderated_opp_amount; + } + } + $i++; + } + $this->db->free($resql); + $ponderated_opp_amount = $ponderated_opp_amount / 100; + + $stringtoprint = ''; + $stringtoprint .= '
'; + $listofstatus = array_keys($listofoppstatus); + foreach ($listofstatus as $status) { + $labelStatus = ''; + if ($status != 7) { + $code = dol_getIdFromCode($this->db, $status, 'c_lead_status', 'rowid', 'code'); + if ($code) $labelStatus = $langs->transnoentitiesnoconv("OppStatus" . $code); + if (empty($labelStatus)) $labelStatus = $listofopplabel[$status]; + + $dataseries[] = array($labelStatus,(isset($valsamount[$status]) ? (float) $valsamount[$status] : 0)); + if (!$conf->use_javascript_ajax) { + $stringtoprint .= ''; + $stringtoprint .= '' . $labelStatus . ''; + $stringtoprint .= '' . price((isset($valsamount[$status]) ? (float) $valsamount[$status] : 0), 0, '', 1, -1, -1, $conf->currency) . ''; + $stringtoprint .= "\n"; + } + } + } + if ($conf->use_javascript_ajax) { + include_once DOL_DOCUMENT_ROOT . '/core/class/dolgraph.class.php'; + $dolgraph = new DolGraph(); + $dolgraph->SetData($dataseries); + $dolgraph->SetDataColor(array_values($colorseriesstat)); + //$dolgraph->SetLegend(array('PROSP',$dataseries['PROSP'])); + $dolgraph->setShowLegend(2); + $dolgraph->setShowPercent(1); + $dolgraph->SetType(array('pie')); + $dolgraph->SetHeight('200'); + $dolgraph->draw('idgraphstatus'); + $stringtoprint .= $dolgraph->show($totaloppnb ? 0 : 1); + } + $stringtoprint .= '
'; + + $line = 0; + $this->info_box_contents[$line][] = array( + 'tr' => 'class="nohover left "', + 'text' => '' + ); + $this->info_box_contents[$line][] = array( + 'tr' => 'class="nohover left "', + 'text' => '' + ); + $line++; + $this->info_box_contents[$line][] = array( + 'tr' => '', + 'td' => 'class="center nopaddingleftimp nopaddingrightimp" colspan="2"', + 'text' => $stringtoprint + ); + $line++; + $this->info_box_contents[$line][] = array( + 'tr' => 'class="oddeven"', + 'td' => 'class="left "', + 'maxlength' => 500, + 'text' => $langs->trans("OpportunityTotalAmount") . ' (' . $langs->trans("WonLostExcluded") . ')' + ); + $this->info_box_contents[$line][] = array( + 'tr' => 'class="oddeven"', + 'td' => 'class="right "', + 'maxlength' => 500, + 'text' => price($totalamount, 0, '', 1, -1, -1, $conf->currency) + ); + $line++; + $this->info_box_contents[$line][] = array( + 'tr' => 'class="oddeven"', + 'td' => 'class="left "', + 'maxlength' => 500, + 'text' => $form->textwithpicto($langs->trans("OpportunityPonderatedAmount") . ' (' . $langs->trans("WonLostExcluded") . ')', $langs->trans("OpportunityPonderatedAmountDesc"), 1) + + ); + $this->info_box_contents[$line][] = array( + 'td' => 'class="right "', + 'maxlength' => 500, + 'text' => price(price2num($ponderated_opp_amount, 'MT'), 0, '', 1, -1, -1, $conf->currency) + ); + } else { + $this->info_box_contents[0][0] = array( + 'td' => 'class="center opacitymedium"', + 'text' => $langs->trans("NoRecordedCustomers") + ); + } + } else { + $this->info_box_contents[0][0] = array( + 'td' => '', + '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 + * @param int $nooutput No $stringtoprint .=, only return string + * @return string + */ + public function showBox($head = null, $contents = null, $nooutput = 0) + { + return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); + } +} diff --git a/htdocs/core/modules/modProjet.class.php b/htdocs/core/modules/modProjet.class.php index 42513a5b9f2..ff2edd3c787 100644 --- a/htdocs/core/modules/modProjet.class.php +++ b/htdocs/core/modules/modProjet.class.php @@ -142,6 +142,7 @@ class modProjet extends DolibarrModules 0=>array('file'=>'box_project.php', 'enabledbydefaulton'=>'Home'), 1=>array('file'=>'box_task.php', 'enabledbydefaulton'=>'Home'), 2=>array('file'=>'box_validated_projects.php', 'enabledbydefaulton'=>'Home'), + 3=>array('file'=>'box_funnel_of_prospection.php', 'enabledbydefaulton'=>'Home'), ); // Permissions diff --git a/htdocs/install/mysql/migration/12.0.0-13.0.0.sql b/htdocs/install/mysql/migration/12.0.0-13.0.0.sql index 2bfb4784206..9fcb3c4ef50 100644 --- a/htdocs/install/mysql/migration/12.0.0-13.0.0.sql +++ b/htdocs/install/mysql/migration/12.0.0-13.0.0.sql @@ -439,7 +439,6 @@ INSERT INTO llx_c_product_nature (code, label, active) VALUES (1, 'Finished', 1) ALTER TABLE llx_product MODIFY COLUMN finished tinyint DEFAULT NULL; ALTER TABLE llx_product ADD CONSTRAINT fk_product_finished FOREIGN KEY (finished) REFERENCES llx_c_product_nature (code); - -- MIGRATION TO DO AFTER RENAMING AN OBJECT -- drop constraint @@ -545,6 +544,10 @@ CREATE TABLE llx_session( user_agent varchar(128) NULL )ENGINE=innodb; + + +INSERT INTO llx_boxes_def(file,entity) VALUES ('box_funnel_of_prospection.php',1); + INSERT INTO llx_boxes_def(file, entity) VALUES ('box_customers_outstanding_bill_reached.php', 1); -ALTER TABLE llx_product_fournisseur_price ADD COLUMN packaging varchar(64); +ALTER TABLE llx_product_fournisseur_price ADD COLUMN packaging varchar(64); \ No newline at end of file diff --git a/htdocs/langs/en_US/boxes.lang b/htdocs/langs/en_US/boxes.lang index 502a3642afe..236d97da521 100644 --- a/htdocs/langs/en_US/boxes.lang +++ b/htdocs/langs/en_US/boxes.lang @@ -50,6 +50,7 @@ BoxTitleLastOutstandingBillReached=Customers with maximum outstanding exceeded BoxGlobalActivity=Global activity (invoices, proposals, orders) BoxGoodCustomers=Good customers BoxTitleGoodCustomers=%s Good customers +BoxTitleFunnelOfProspection=Amount of prospection by status FailedToRefreshDataInfoNotUpToDate=Failed to refresh RSS flux. Latest successful refresh date: %s LastRefreshDate=Latest refresh date NoRecordedBookmarks=No bookmarks defined.