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';
89 $listofoppstatus = array();
90 $listofopplabel = array();
91 $listofoppcode = array();
92 $colorseriesstat = array();
93 $sql =
"SELECT cls.rowid, cls.code, cls.percent, cls.label";
94 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_lead_status as cls";
95 $sql .=
" WHERE active = 1";
96 $sql .=
" AND cls.code <> 'LOST'";
97 $sql .=
" AND cls.code <> 'WON'";
98 $sql .= $this->db->order(
'cls.rowid',
'ASC');
99 $resql = $this->db->query($sql);
101 $num = $this->db->num_rows($resql);
105 $objp = $this->db->fetch_object($resql);
106 $listofoppstatus[$objp->rowid] = $objp->percent;
107 $listofopplabel[$objp->rowid] = $objp->label;
108 $listofoppcode[$objp->rowid] = $objp->code;
109 switch ($objp->code) {
111 $colorseriesstat[$objp->rowid] =
'-'.$badgeStatus0;
114 $colorseriesstat[$objp->rowid] =
'-'.$badgeStatus1;
117 $colorseriesstat[$objp->rowid] = $badgeStatus1;
120 $colorseriesstat[$objp->rowid] = $badgeStatus4;
131 global $conf, $user, $langs;
134 $this->info_box_head = array(
135 'text' => $langs->trans(
"Statistics").
' - '.$langs->trans(
"BoxTitleFunnelOfProspection"),
140 if ($user->hasRight(
'projet',
'lire') ||
getDolGlobalString(
'PROJECT_USE_OPPORTUNITIES')) {
141 $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";
142 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p, ".MAIN_DB_PREFIX.
"c_lead_status as cls";
143 $sql .=
" WHERE p.entity IN (".getEntity(
'project').
")";
144 $sql .=
" AND p.fk_opp_status = cls.rowid";
145 $sql .=
" AND p.fk_statut = 1";
146 $sql .=
" AND cls.code NOT IN ('LOST', 'WON')";
147 $sql .=
" GROUP BY p.fk_opp_status, cls.code";
148 $resql = $this->db->query($sql);
150 $form =
new Form($this->db);
152 $num = $this->db->num_rows($resql);
158 $ponderated_opp_amount = 0;
160 $valsamount = array();
161 $dataseries = array();
164 $obj = $this->db->fetch_object($resql);
166 $valsnb[$obj->opp_status] = $obj->nb;
167 $valsamount[$obj->opp_status] = $obj->opp_amount;
168 $totalnb += $obj->nb;
169 if ($obj->opp_status) {
170 $totaloppnb += $obj->nb;
172 if (!in_array($obj->code, array(
'WON',
'LOST'))) {
173 $totalamount += $obj->opp_amount;
174 $ponderated_opp_amount += $obj->ponderated_opp_amount;
179 $this->db->free($resql);
180 $ponderated_opp_amount = $ponderated_opp_amount / 100;
183 $stringtoprint .=
'<div class="div-table-responsive-no-min ">';
184 $listofstatus = array_keys($listofoppstatus);
185 $liststatus = array();
187 $customlabels = array();
190 foreach ($listofstatus as $status) {
196 $labelStatus = $langs->transnoentitiesnoconv(
"OppStatus".$code);
198 if (empty($labelStatus)) {
199 $labelStatus = $listofopplabel[$status];
201 $amount = (isset($valsamount[$status]) ? (float) $valsamount[$status] : 0);
202 $customlabel = $amount.
"€";
205 $liststatus[] = $labelStatus;
206 if (!$conf->use_javascript_ajax) {
207 $stringtoprint .=
'<tr class="oddeven">';
208 $stringtoprint .=
'<td>'.$labelStatus.
'</td>';
209 $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>';
210 $stringtoprint .=
"</tr>\n";
212 $customlabels[] = $customlabel;
213 if ($maxamount < $amount) {
214 $maxamount = $amount;
220 $valuetoaddtomindata = $maxamount / 100;
221 foreach ($data as $key => $value) {
223 $data[$key] = $valuetoaddtomindata + $value;
227 $dataseries[] = $data;
228 if ($conf->use_javascript_ajax) {
229 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
231 $dolgraph->SetMinValue(0);
232 $dolgraph->SetData($dataseries);
233 $dolgraph->SetLegend($liststatus);
234 $dolgraph->setHideXValues(
true);
235 $dolgraph->SetDataColor(array_values($colorseriesstat));
237 $dolgraph->setShowLegend(2);
238 if (!empty($conf->dol_optimize_smallscreen)) {
239 $dolgraph->SetWidth(320);
241 $dolgraph->setShowPercent(1);
242 $dolgraph->setMirrorGraphValues(
true);
243 $dolgraph->setBorderWidth(2);
244 $dolgraph->setBorderSkip(
'false');
245 $dolgraph->SetType(array(
'horizontalbars'));
246 $dolgraph->SetHeight(
'200');
247 $dolgraph->SetWidth(
'600');
248 $dolgraph->setTooltipsTitles($liststatus);
249 $dolgraph->setTooltipsLabels($customlabels);
250 $dolgraph->mode =
'depth';
251 $dolgraph->draw(
'idgraphleadfunnel');
252 $stringtoprint .= $dolgraph->show($totaloppnb ? 0 : 1);
254 $stringtoprint .=
'</div>';
266 $this->info_box_contents[$line][] = array(
268 'td' =>
'class="center nopaddingleftimp nopaddingrightimp" colspan="2"',
269 'text' => $stringtoprint
272 $this->info_box_contents[$line][] = array(
273 'tr' =>
'class="oddeven"',
274 'td' =>
'class="left "',
276 'text' => $langs->trans(
"OpportunityTotalAmount").
' ('.$langs->trans(
"WonLostExcluded").
')'
278 $this->info_box_contents[$line][] = array(
279 'tr' =>
'class="oddeven"',
280 'td' =>
'class="nowraponall right amount"',
282 'text' =>
price($totalamount, 0,
'', 1, -1, -1, $conf->currency)
285 $this->info_box_contents[$line][] = array(
286 'tr' =>
'class="oddeven"',
287 'td' =>
'class="left "',
289 'text' => $form->textwithpicto($langs->trans(
"OpportunityPonderatedAmount").
' ('.$langs->trans(
"WonLostExcluded").
')', $langs->trans(
"OpportunityPonderatedAmountDesc"), 1)
292 $this->info_box_contents[$line][] = array(
293 'td' =>
'class="nowraponall right amount"',
295 'text' =>
price(
price2num($ponderated_opp_amount,
'MT'), 0,
'', 1, -1, -1, $conf->currency)
298 $this->info_box_contents[0][0] = array(
299 'td' =>
'class="center"',
300 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"NoRecordedCustomers").
'</span>'
304 $this->info_box_contents[0][0] = array(
306 'text' => $langs->trans(
"ReadPermissionNotAllowed")