82 $badgeStatus0 =
'#cbd3d3';
83 $badgeStatus1 =
'#bc9526';
84 $badgeStatus1b =
'#bc9526';
85 $badgeStatus2 =
'#9c9c26';
86 $badgeStatus3 =
'#bca52b';
87 $badgeStatus4 =
'#25a580';
88 $badgeStatus4b =
'#25a580';
89 $badgeStatus5 =
'#cad2d2';
90 $badgeStatus6 =
'#cad2d2';
91 $badgeStatus7 =
'#baa32b';
92 $badgeStatus8 =
'#993013';
93 $badgeStatus9 =
'#e7f0f0';
94 if (file_exists(DOL_DOCUMENT_ROOT.
'/theme/'.$conf->theme.
'/theme_vars.inc.php')) {
95 include DOL_DOCUMENT_ROOT.
'/theme/'.$conf->theme.
'/theme_vars.inc.php';
97 $listofoppstatus = array();
98 $listofopplabel = array();
99 $listofoppcode = array();
100 $colorseriesstat = array();
101 $sql =
"SELECT cls.rowid, cls.code, cls.percent, cls.label";
102 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_lead_status as cls";
103 $sql .=
" WHERE active=1";
104 $sql .=
" AND cls.code <> 'LOST'";
105 $sql .= $this->db->order(
'cls.rowid',
'ASC');
106 $resql = $this->db->query($sql);
108 $num = $this->db->num_rows($resql);
112 $objp = $this->db->fetch_object($resql);
113 $listofoppstatus[$objp->rowid] = $objp->percent;
114 $listofopplabel[$objp->rowid] = $objp->label;
115 $listofoppcode[$objp->rowid] = $objp->code;
116 switch ($objp->code) {
118 $colorseriesstat[$objp->rowid] =
'-'.$badgeStatus0;
121 $colorseriesstat[$objp->rowid] =
'-'.$badgeStatus1;
124 $colorseriesstat[$objp->rowid] = $badgeStatus1;
127 $colorseriesstat[$objp->rowid] = $badgeStatus4;
130 $colorseriesstat[$objp->rowid] = $badgeStatus6;
141 global $conf, $user, $langs;
144 $this->info_box_head = array(
145 'text' => $langs->trans(
"Statistics").
' - '.$langs->trans(
"BoxTitleFunnelOfProspection"),
149 if ($user->hasRight(
'projet',
'lire') ||
getDolGlobalString(
'PROJECT_USE_OPPORTUNITIES')) {
150 $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";
151 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p, ".MAIN_DB_PREFIX.
"c_lead_status as cls";
152 $sql .=
" WHERE p.entity IN (".getEntity(
'project').
")";
153 $sql .=
" AND p.fk_opp_status = cls.rowid";
154 $sql .=
" AND p.fk_statut = 1";
155 $sql .=
" AND cls.code NOT IN ('LOST')";
156 $sql .=
" GROUP BY p.fk_opp_status, cls.code";
157 $resql = $this->db->query($sql);
159 $form =
new Form($this->db);
161 $num = $this->db->num_rows($resql);
167 $ponderated_opp_amount = 0;
169 $valsamount = array();
170 $dataseries = array();
173 $obj = $this->db->fetch_object($resql);
175 $valsnb[$obj->opp_status] = $obj->nb;
176 $valsamount[$obj->opp_status] = $obj->opp_amount;
177 $totalnb += $obj->nb;
178 if ($obj->opp_status) {
179 $totaloppnb += $obj->nb;
181 if (!in_array($obj->code, array(
'WON',
'LOST'))) {
182 $totalamount += $obj->opp_amount;
183 $ponderated_opp_amount += $obj->ponderated_opp_amount;
188 $this->db->free($resql);
189 $ponderated_opp_amount = $ponderated_opp_amount / 100;
192 $stringtoprint .=
'<div class="div-table-responsive-no-min ">';
193 $listofstatus = array_keys($listofoppstatus);
194 $liststatus = array();
196 $customlabels = array();
198 foreach ($listofstatus as $status) {
204 $labelStatus = $langs->transnoentitiesnoconv(
"OppStatus".$code);
206 if (empty($labelStatus)) {
207 $labelStatus = $listofopplabel[$status];
209 $amount = (isset($valsamount[$status]) ? (float) $valsamount[$status] : 0);
211 $customlabel = $amount;
212 $liststatus[] = $labelStatus;
213 if (!$conf->use_javascript_ajax) {
214 $stringtoprint .=
'<tr class="oddeven">';
215 $stringtoprint .=
'<td>'.$labelStatus.
'</td>';
216 $stringtoprint .=
'<td class="nowraponall right amount"><a href="list.php?statut='.$status.
'">'.
price((isset($valsamount[$status]) ? (
float) $valsamount[$status] : 0), 0,
'', 1, -1, -1, $conf->currency).
'</a></td>';
217 $stringtoprint .=
"</tr>\n";
220 $customlabels[] = $customlabel;
222 $dataseries[] = $data;
223 if ($conf->use_javascript_ajax) {
224 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
226 $dolgraph->SetMinValue(0);
227 $dolgraph->SetData($dataseries);
228 $dolgraph->SetLegend($liststatus);
229 $dolgraph->setHideXValues(
true);
230 $dolgraph->SetDataColor(array_values($colorseriesstat));
232 $dolgraph->setShowLegend(2);
233 if (!empty($conf->dol_optimize_smallscreen)) {
234 $dolgraph->SetWidth(320);
236 $dolgraph->setShowPercent(1);
237 $dolgraph->setMirrorGraphValues(
true);
238 $dolgraph->setBorderWidth(2);
239 $dolgraph->SetType(array(
'horizontalbars'));
240 $dolgraph->SetHeight(
'200');
241 $dolgraph->SetWidth(
'600');
242 $dolgraph->setTooltipsTitles($liststatus);
243 $dolgraph->setTooltipsLabels($customlabels);
244 $dolgraph->mode =
'depth';
245 $dolgraph->draw(
'idgraphleadfunnel');
246 $stringtoprint .= $dolgraph->show($totaloppnb ? 0 : 1);
248 $stringtoprint .=
'</div>';
251 $this->info_box_contents[$line][] = array(
252 'tr' =>
'class="nohover left "',
255 $this->info_box_contents[$line][] = array(
256 'tr' =>
'class="nohover left "',
260 $this->info_box_contents[$line][] = array(
262 'td' =>
'class="center nopaddingleftimp nopaddingrightimp" colspan="2"',
263 'text' => $stringtoprint
266 $this->info_box_contents[$line][] = array(
267 'tr' =>
'class="oddeven"',
268 'td' =>
'class="left "',
270 'text' => $langs->trans(
"OpportunityTotalAmount").
' ('.$langs->trans(
"WonLostExcluded").
')'
272 $this->info_box_contents[$line][] = array(
273 'tr' =>
'class="oddeven"',
274 'td' =>
'class="nowraponall right amount"',
276 'text' =>
price($totalamount, 0,
'', 1, -1, -1, $conf->currency)
279 $this->info_box_contents[$line][] = array(
280 'tr' =>
'class="oddeven"',
281 'td' =>
'class="left "',
283 'text' => $form->textwithpicto($langs->trans(
"OpportunityPonderatedAmount").
' ('.$langs->trans(
"WonLostExcluded").
')', $langs->trans(
"OpportunityPonderatedAmountDesc"), 1)
286 $this->info_box_contents[$line][] = array(
287 'td' =>
'class="nowraponall right amount"',
289 'text' =>
price(
price2num($ponderated_opp_amount,
'MT'), 0,
'', 1, -1, -1, $conf->currency)
292 $this->info_box_contents[0][0] = array(
293 'td' =>
'class="center opacitymedium"',
294 'text' => $langs->trans(
"NoRecordedCustomers")
298 $this->info_box_contents[0][0] = array(
300 'text' => $langs->trans(
"ReadPermissionNotAllowed")