75 $badgeStatus0 =
'#cbd3d3';
76 $badgeStatus1 =
'#bc9526';
77 $badgeStatus1b =
'#bc9526';
78 $badgeStatus2 =
'#9c9c26';
79 $badgeStatus3 =
'#bca52b';
80 $badgeStatus4 =
'#25a580';
81 $badgeStatus4b =
'#25a580';
82 $badgeStatus5 =
'#cad2d2';
83 $badgeStatus6 =
'#cad2d2';
84 $badgeStatus7 =
'#baa32b';
85 $badgeStatus8 =
'#993013';
86 $badgeStatus9 =
'#e7f0f0';
87 if (file_exists(DOL_DOCUMENT_ROOT.
'/theme/'.$conf->theme.
'/theme_vars.inc.php')) {
88 include DOL_DOCUMENT_ROOT.
'/theme/'.$conf->theme.
'/theme_vars.inc.php';
90 $listofoppstatus = array();
91 $listofopplabel = array();
92 $listofoppcode = array();
93 $colorseriesstat = array();
94 $sql =
"SELECT cls.rowid, cls.code, cls.percent, cls.label";
95 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_lead_status as cls";
96 $sql .=
" WHERE active = 1";
97 $sql .=
" AND cls.code <> 'LOST'";
98 $sql .=
" AND cls.code <> 'WON'";
99 $sql .= $this->db->order(
'cls.rowid',
'ASC');
100 $resql = $this->db->query($sql);
102 $num = $this->db->num_rows($resql);
106 $objp = $this->db->fetch_object($resql);
107 $listofoppstatus[$objp->rowid] = $objp->percent;
108 $listofopplabel[$objp->rowid] = $objp->label;
109 $listofoppcode[$objp->rowid] = $objp->code;
110 switch ($objp->code) {
112 $colorseriesstat[$objp->rowid] =
'-'.$badgeStatus0;
115 $colorseriesstat[$objp->rowid] =
'-'.$badgeStatus1;
118 $colorseriesstat[$objp->rowid] = $badgeStatus1;
121 $colorseriesstat[$objp->rowid] = $badgeStatus4;
132 global $conf, $user, $langs;
135 $this->info_box_head = array(
136 'text' => $langs->trans(
"Statistics").
' - '.$langs->trans(
"BoxTitleFunnelOfProspection"),
141 if ($user->hasRight(
'projet',
'lire') ||
getDolGlobalString(
'PROJECT_USE_OPPORTUNITIES')) {
142 $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";
143 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p, ".MAIN_DB_PREFIX.
"c_lead_status as cls";
144 $sql .=
" WHERE p.entity IN (".getEntity(
'project').
")";
145 $sql .=
" AND p.fk_opp_status = cls.rowid";
146 $sql .=
" AND p.fk_statut = 1";
147 $sql .=
" AND cls.code NOT IN ('LOST', 'WON')";
148 $sql .=
" GROUP BY p.fk_opp_status, cls.code";
149 $resql = $this->db->query($sql);
151 $form =
new Form($this->db);
153 $num = $this->db->num_rows($resql);
159 $ponderated_opp_amount = 0;
161 $valsamount = array();
162 $dataseries = array();
165 $obj = $this->db->fetch_object($resql);
167 $valsnb[$obj->opp_status] = $obj->nb;
168 $valsamount[$obj->opp_status] = $obj->opp_amount;
169 $totalnb += $obj->nb;
170 if ($obj->opp_status) {
171 $totaloppnb += $obj->nb;
173 if (!in_array($obj->code, array(
'WON',
'LOST'))) {
174 $totalamount += $obj->opp_amount;
175 $ponderated_opp_amount += $obj->ponderated_opp_amount;
180 $this->db->free($resql);
181 $ponderated_opp_amount /= 100;
184 $stringtoprint .=
'<div class="div-table-responsive-no-min ">';
185 $listofstatus = array_keys($listofoppstatus);
186 $liststatus = array();
188 $customlabels = array();
191 foreach ($listofstatus as $status) {
197 $labelStatus = $langs->transnoentitiesnoconv(
"OppStatus".$code);
199 if (empty($labelStatus)) {
200 $labelStatus = $listofopplabel[$status];
202 $amount = (isset($valsamount[$status]) ? (float) $valsamount[$status] : 0);
203 $customlabel = $amount.
"€";
206 $liststatus[] = $labelStatus;
207 if (!$conf->use_javascript_ajax) {
208 $stringtoprint .=
'<tr class="oddeven">';
209 $stringtoprint .=
'<td>'.$labelStatus.
'</td>';
210 $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>';
211 $stringtoprint .=
"</tr>\n";
213 $customlabels[] = $customlabel;
214 if ($maxamount < $amount) {
215 $maxamount = $amount;
221 $valuetoaddtomindata = $maxamount / 100;
222 foreach ($data as $key => $value) {
224 $data[$key] = $valuetoaddtomindata + $value;
228 $dataseries[] = $data;
229 if ($conf->use_javascript_ajax) {
230 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
232 $dolgraph->SetMinValue(0);
233 $dolgraph->SetData($dataseries);
234 $dolgraph->SetLegend($liststatus);
235 $dolgraph->setHideXValues(
true);
236 $dolgraph->SetDataColor(array_values($colorseriesstat));
238 $dolgraph->setShowLegend(2);
239 if (!empty($conf->dol_optimize_smallscreen)) {
240 $dolgraph->SetWidth(320);
242 $dolgraph->setShowPercent(1);
243 $dolgraph->setMirrorGraphValues(
true);
244 $dolgraph->setBorderWidth(2);
245 $dolgraph->setBorderSkip(
'false');
246 $dolgraph->SetType(array(
'horizontalbars'));
247 $dolgraph->SetHeight(
'200');
248 $dolgraph->SetWidth(
'600');
249 $dolgraph->setTooltipsTitles($liststatus);
250 $dolgraph->setTooltipsLabels($customlabels);
251 $dolgraph->mode =
'depth';
252 $dolgraph->draw(
'idgraphleadfunnel');
253 $stringtoprint .= $dolgraph->show($totaloppnb ? 0 : 1);
255 $stringtoprint .=
'</div>';
267 $this->info_box_contents[$line][] = array(
269 'td' =>
'class="center nopaddingleftimp nopaddingrightimp" colspan="2"',
270 'text' => $stringtoprint
273 $this->info_box_contents[$line][] = array(
274 'tr' =>
'class="oddeven"',
275 'td' =>
'class="left "',
277 'text' => $langs->trans(
"OpportunityTotalAmount").
' ('.$langs->trans(
"WonLostExcluded").
')'
279 $this->info_box_contents[$line][] = array(
280 'tr' =>
'class="oddeven"',
281 'td' =>
'class="nowraponall right amount"',
283 'text' =>
price($totalamount, 0,
'', 1, -1, -1, $conf->currency)
286 $this->info_box_contents[$line][] = array(
287 'tr' =>
'class="oddeven"',
288 'td' =>
'class="left "',
290 'text' => $form->textwithpicto($langs->trans(
"OpportunityPonderatedAmount").
' ('.$langs->trans(
"WonLostExcluded").
')', $langs->trans(
"OpportunityPonderatedAmountDesc"), 1)
293 $this->info_box_contents[$line][] = array(
294 'td' =>
'class="nowraponall right amount"',
296 'text' =>
price(
price2num($ponderated_opp_amount,
'MT'), 0,
'', 1, -1, -1, $conf->currency)
299 $this->info_box_contents[0][0] = array(
300 'td' =>
'class="center"',
301 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"NoRecordedCustomers").
'</span>'
305 $this->info_box_contents[0][0] = array(
307 'text' => $langs->trans(
"ReadPermissionNotAllowed")