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';
87 if ($theme_vars_file) {
88 include $theme_vars_file;
91 $listofoppstatus = array();
92 $listofopplabel = array();
93 $listofoppposition = array();
95 $colorseriesstat = array();
97 $sql =
"SELECT cls.rowid, cls.code, cls.percent, cls.label, cls.position";
98 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_lead_status as cls";
99 $sql .=
" WHERE active = 1";
100 $sql .=
" AND cls.code NOT IN ('LOST', 'WON')";
101 $sql .= $this->db->order(
'cls.position,cls.rowid',
'ASC,ASC');
103 $resql = $this->db->query($sql);
105 $num = $this->db->num_rows($resql);
109 $objp = $this->db->fetch_object($resql);
111 $listofoppstatus[$objp->rowid] = $objp->percent;
112 $listofopplabel[$objp->rowid] = $objp->label;
113 $listofoppposition[$objp->rowid] = $objp->position;
115 switch ($objp->code) {
117 $colorseriesstat[$objp->rowid] =
'-'.$badgeStatus0;
120 $colorseriesstat[$objp->rowid] =
'-'.$badgeStatus1;
123 $colorseriesstat[$objp->rowid] = $badgeStatus1;
126 $colorseriesstat[$objp->rowid] = $badgeStatus4;
134 dol_print_error($this->db);
137 global
$conf, $user, $langs;
140 $this->info_box_head = array(
141 'text' => $langs->trans(
"Opportunities").
' - '.$langs->trans(
"BoxTitleFunnelOfProspection"),
146 if ($user->hasRight(
'projet',
'lire') ||
getDolGlobalString(
'PROJECT_USE_OPPORTUNITIES')) {
147 $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";
148 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p, ".MAIN_DB_PREFIX.
"c_lead_status as cls";
149 $sql .=
" WHERE p.entity IN (".getEntity(
'project').
")";
150 $sql .=
" AND p.fk_opp_status = cls.rowid";
151 $sql .=
" AND p.fk_statut = 1";
152 $sql .=
" AND cls.active = 1";
153 $sql .=
" AND cls.code NOT IN ('LOST', 'WON')";
154 $sql .=
" GROUP BY p.fk_opp_status, cls.code, cls.position";
155 $sql .=
" ORDER BY cls.position, 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);
176 $valsamount[$obj->opp_status] = $obj->opp_amount;
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);
190 $ponderated_opp_amount /= 100;
193 $stringtoprint .=
'<div class="div-table-responsive-no-min ">';
194 $listofstatus = array_keys($listofoppstatus);
195 $liststatus = array();
197 $customlabels = array();
202 foreach ($listofstatus as $status) {
205 $customlabelmore =
'';
209 $labelStatus = $langs->transnoentitiesnoconv(
"OppStatus".$code);
211 if (empty($labelStatus)) {
212 $labelStatus = $listofopplabel[$status];
214 $amount = (isset($valsamount[$status]) ? (float) $valsamount[$status] : 0);
215 $customlabel =
price($amount, 0, $langs, 1, -1,
'MT',
$conf->currency);
217 $amountforgraph = $amount;
221 foreach ($listofstatus as $status2) {
222 if ($listofoppposition[$status2] > $listofoppposition[$status]) {
223 $amountafter += $valsamount[$status2];
226 $amountforgraph += $amountafter;
228 $customlabelmore =
price($amountafter, 0, $langs, 1, -1,
'MT',
$conf->currency);
231 $data[] = $amountforgraph;
232 $liststatus[] = $labelStatus;
233 if (!
$conf->use_javascript_ajax) {
234 $stringtoprint .=
'<tr class="oddeven">';
235 $stringtoprint .=
'<td>'.$labelStatus.
'</td>';
236 $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>';
237 $stringtoprint .=
"</tr>\n";
241 $customlabels[] = $customlabel.
' + '.$customlabelmore;
243 $customlabels[] = $customlabel;
246 if ($maxamount < $amountforgraph) {
247 $maxamount = $amountforgraph;
252 $valuetoaddtomindata = $maxamount / 100;
253 foreach ($data as $key => $value) {
255 $data[$key] = $valuetoaddtomindata + $value;
258 foreach ($data as $key => $value) {
259 if ($data[$key] == 0) {
260 $data[$key] = $valuetoaddtomindata;
265 $dataseries[] = $data;
266 if (
$conf->use_javascript_ajax) {
267 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
269 $dolgraph->SetMinValue(0);
270 $dolgraph->SetData($dataseries);
271 $dolgraph->SetLegend($liststatus);
272 $dolgraph->setHideXValues(
false);
273 $dolgraph->setHideYValues(
true);
274 $dolgraph->SetDataColor(array_values($colorseriesstat));
275 $dolgraph->setShowLegend(2);
276 $dolgraph->setShowPercent(1);
277 $dolgraph->setMirrorGraphValues(
true);
278 $dolgraph->setBorderWidth(2);
279 $dolgraph->setBorderSkip(
'false');
280 $dolgraph->SetType(array(
'horizontalbars'));
281 $dolgraph->SetHeight(
'150');
282 $dolgraph->SetWidth(
$conf->dol_optimize_smallscreen ?
'300' : ((empty($_SESSION[
"dol_screenwidth"]) || $_SESSION[
"dol_screenwidth"] > 1600) ?
'600' :
'500'));
283 $dolgraph->setTooltipsTitles($liststatus);
284 $dolgraph->setTooltipsLabels($customlabels);
285 $dolgraph->mode =
'depth';
286 $dolgraph->draw(
'idgraphleadfunnel');
288 $stringtoprint .= $dolgraph->show($totaloppnb ? 0 : 1);
290 $stringtoprint .=
'</div>';
294 $this->info_box_contents[$line][] = array(
296 'td' =>
'class="center nopaddingleftimp nopaddingrightimp" colspan="2"',
297 'text' => $stringtoprint
300 $this->info_box_contents[$line][] = array(
301 'tr' =>
'class="oddeven"',
302 'td' =>
'class="left "',
305 'text' => $langs->trans(
"OpportunityTotalAmount").
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"WonLostExcluded").
')</span>'
307 $this->info_box_contents[$line][] = array(
308 'tr' =>
'class="oddeven"',
309 'td' =>
'class="nowraponall right amount"',
311 'text' =>
price($totalamount, 0,
'', 1, -1, -1,
$conf->currency)
314 $this->info_box_contents[$line][] = array(
315 'tr' =>
'class="oddeven"',
316 'td' =>
'class="left "',
319 'text' => $form->textwithpicto($langs->trans(
"OpportunityPonderatedAmount").
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"WonLostExcluded").
')</span>', $langs->trans(
"OpportunityPonderatedAmountDesc"), 1)
322 $this->info_box_contents[$line][] = array(
323 'td' =>
'class="nowraponall right amount"',
325 'text' =>
price(
price2num($ponderated_opp_amount,
'MT'), 0,
'', 1, -1, -1,
$conf->currency)
328 $this->info_box_contents[0][0] = array(
329 'td' =>
'class="center"',
330 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"NoRecordedCustomers").
'</span>'
334 $this->info_box_contents[0][0] = array(
336 'text' => $langs->trans(
"ReadPermissionNotAllowed")