74 $badgeStatus0 =
'#cbd3d3';
75 $badgeStatus1 =
'#bc9526';
76 $badgeStatus1b =
'#bc9526';
77 $badgeStatus2 =
'#9c9c26';
78 $badgeStatus3 =
'#bca52b';
79 $badgeStatus4 =
'#25a580';
80 $badgeStatus4b =
'#25a580';
81 $badgeStatus5 =
'#cad2d2';
82 $badgeStatus6 =
'#cad2d2';
83 $badgeStatus7 =
'#baa32b';
84 $badgeStatus8 =
'#993013';
85 $badgeStatus9 =
'#e7f0f0';
86 if (file_exists(DOL_DOCUMENT_ROOT.
'/theme/'.$conf->theme.
'/theme_vars.inc.php')) {
87 include DOL_DOCUMENT_ROOT.
'/theme/'.$conf->theme.
'/theme_vars.inc.php';
90 $listofoppstatus = array();
91 $listofopplabel = array();
92 $listofoppposition = array();
94 $colorseriesstat = array();
96 $sql =
"SELECT cls.rowid, cls.code, cls.percent, cls.label, cls.position";
97 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_lead_status as cls";
98 $sql .=
" WHERE active = 1";
99 $sql .=
" AND cls.code NOT IN ('LOST', 'WON')";
100 $sql .= $this->db->order(
'cls.position,cls.rowid',
'ASC,ASC');
102 $resql = $this->db->query($sql);
104 $num = $this->db->num_rows($resql);
108 $objp = $this->db->fetch_object($resql);
110 $listofoppstatus[$objp->rowid] = $objp->percent;
111 $listofopplabel[$objp->rowid] = $objp->label;
112 $listofoppposition[$objp->rowid] = $objp->position;
114 switch ($objp->code) {
116 $colorseriesstat[$objp->rowid] =
'-'.$badgeStatus0;
119 $colorseriesstat[$objp->rowid] =
'-'.$badgeStatus1;
122 $colorseriesstat[$objp->rowid] = $badgeStatus1;
125 $colorseriesstat[$objp->rowid] = $badgeStatus4;
136 global $conf, $user, $langs;
139 $this->info_box_head = array(
140 'text' => $langs->trans(
"Opportunities").
' - '.$langs->trans(
"BoxTitleFunnelOfProspection"),
145 if ($user->hasRight(
'projet',
'lire') ||
getDolGlobalString(
'PROJECT_USE_OPPORTUNITIES')) {
146 $sql =
"SELECT p.fk_opp_status as opp_status, cls.code, cls.position, COUNT(p.rowid) as nb, SUM(p.opp_amount) as opp_amount, SUM(p.opp_amount * p.opp_percent) as ponderated_opp_amount";
147 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p, ".MAIN_DB_PREFIX.
"c_lead_status as cls";
148 $sql .=
" WHERE p.entity IN (".getEntity(
'project').
")";
149 $sql .=
" AND p.fk_opp_status = cls.rowid";
150 $sql .=
" AND p.fk_statut = 1";
151 $sql .=
" AND cls.active = 1";
152 $sql .=
" AND cls.code NOT IN ('LOST', 'WON')";
153 $sql .=
" GROUP BY p.fk_opp_status, cls.code, cls.position";
154 $sql .=
" ORDER BY cls.position, p.fk_opp_status, cls.code";
156 $resql = $this->db->query($sql);
158 $form =
new Form($this->db);
160 $num = $this->db->num_rows($resql);
166 $ponderated_opp_amount = 0;
168 $valsamount = array();
169 $dataseries = array();
172 $obj = $this->db->fetch_object($resql);
175 $valsamount[$obj->opp_status] = $obj->opp_amount;
177 if ($obj->opp_status) {
178 $totaloppnb += $obj->nb;
180 if (!in_array($obj->code, array(
'WON',
'LOST'))) {
181 $totalamount += $obj->opp_amount;
182 $ponderated_opp_amount += $obj->ponderated_opp_amount;
187 $this->db->free($resql);
189 $ponderated_opp_amount /= 100;
192 $stringtoprint .=
'<div class="div-table-responsive-no-min ">';
193 $listofstatus = array_keys($listofoppstatus);
194 $liststatus = array();
196 $customlabels = array();
201 foreach ($listofstatus as $status) {
204 $customlabelmore =
'';
208 $labelStatus = $langs->transnoentitiesnoconv(
"OppStatus".$code);
210 if (empty($labelStatus)) {
211 $labelStatus = $listofopplabel[$status];
213 $amount = (isset($valsamount[$status]) ? (float) $valsamount[$status] : 0);
214 $customlabel =
price($amount, 0, $langs, 1, -1,
'MT', $conf->currency);
216 $amountforgraph = $amount;
220 foreach ($listofstatus as $status2) {
221 if ($listofoppposition[$status2] > $listofoppposition[$status]) {
222 $amountafter += $valsamount[$status2];
225 $amountforgraph += $amountafter;
227 $customlabelmore =
price($amountafter, 0, $langs, 1, -1,
'MT', $conf->currency);
230 $data[] = $amountforgraph;
231 $liststatus[] = $labelStatus;
232 if (!$conf->use_javascript_ajax) {
233 $stringtoprint .=
'<tr class="oddeven">';
234 $stringtoprint .=
'<td>'.$labelStatus.
'</td>';
235 $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>';
236 $stringtoprint .=
"</tr>\n";
240 $customlabels[] = $customlabel.
' + '.$customlabelmore;
242 $customlabels[] = $customlabel;
245 if ($maxamount < $amountforgraph) {
246 $maxamount = $amountforgraph;
251 $valuetoaddtomindata = $maxamount / 100;
252 foreach ($data as $key => $value) {
254 $data[$key] = $valuetoaddtomindata + $value;
257 foreach ($data as $key => $value) {
258 if ($data[$key] == 0) {
259 $data[$key] = $valuetoaddtomindata;
264 $dataseries[] = $data;
265 if ($conf->use_javascript_ajax) {
266 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
268 $dolgraph->SetMinValue(0);
269 $dolgraph->SetData($dataseries);
270 $dolgraph->SetLegend($liststatus);
271 $dolgraph->setHideXValues(
false);
272 $dolgraph->setHideYValues(
true);
273 $dolgraph->SetDataColor(array_values($colorseriesstat));
274 $dolgraph->setShowLegend(2);
275 $dolgraph->setShowPercent(1);
276 $dolgraph->setMirrorGraphValues(
true);
277 $dolgraph->setBorderWidth(2);
278 $dolgraph->setBorderSkip(
'false');
279 $dolgraph->SetType(array(
'horizontalbars'));
280 $dolgraph->SetHeight(
'150');
281 $dolgraph->SetWidth($conf->dol_optimize_smallscreen ?
'300' : ((empty($_SESSION[
"dol_screenwidth"]) || $_SESSION[
"dol_screenwidth"] > 1600) ?
'600' :
'500'));
282 $dolgraph->setTooltipsTitles($liststatus);
283 $dolgraph->setTooltipsLabels($customlabels);
284 $dolgraph->mode =
'depth';
285 $dolgraph->draw(
'idgraphleadfunnel');
287 $stringtoprint .= $dolgraph->show($totaloppnb ? 0 : 1);
289 $stringtoprint .=
'</div>';
293 $this->info_box_contents[$line][] = array(
295 'td' =>
'class="center nopaddingleftimp nopaddingrightimp" colspan="2"',
296 'text' => $stringtoprint
299 $this->info_box_contents[$line][] = array(
300 'tr' =>
'class="oddeven"',
301 'td' =>
'class="left "',
304 'text' => $langs->trans(
"OpportunityTotalAmount").
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"WonLostExcluded").
')</span>'
306 $this->info_box_contents[$line][] = array(
307 'tr' =>
'class="oddeven"',
308 'td' =>
'class="nowraponall right amount"',
310 'text' =>
price($totalamount, 0,
'', 1, -1, -1, $conf->currency)
313 $this->info_box_contents[$line][] = array(
314 'tr' =>
'class="oddeven"',
315 'td' =>
'class="left "',
318 'text' => $form->textwithpicto($langs->trans(
"OpportunityPonderatedAmount").
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"WonLostExcluded").
')</span>', $langs->trans(
"OpportunityPonderatedAmountDesc"), 1)
321 $this->info_box_contents[$line][] = array(
322 'td' =>
'class="nowraponall right amount"',
324 'text' =>
price(
price2num($ponderated_opp_amount,
'MT'), 0,
'', 1, -1, -1, $conf->currency)
327 $this->info_box_contents[0][0] = array(
328 'td' =>
'class="center"',
329 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"NoRecordedCustomers").
'</span>'
333 $this->info_box_contents[0][0] = array(
335 'text' => $langs->trans(
"ReadPermissionNotAllowed")