84 $badgeStatus0 =
'#cbd3d3';
85 $badgeStatus1 =
'#bc9526';
86 $badgeStatus1b =
'#bc9526';
87 $badgeStatus2 =
'#9c9c26';
88 $badgeStatus3 =
'#bca52b';
89 $badgeStatus4 =
'#25a580';
90 $badgeStatus4b =
'#25a580';
91 $badgeStatus5 =
'#cad2d2';
92 $badgeStatus6 =
'#cad2d2';
93 $badgeStatus7 =
'#baa32b';
94 $badgeStatus8 =
'#993013';
95 $badgeStatus9 =
'#e7f0f0';
96 if (file_exists(DOL_DOCUMENT_ROOT.
'/theme/'.$conf->theme.
'/theme_vars.inc.php')) {
97 include DOL_DOCUMENT_ROOT.
'/theme/'.$conf->theme.
'/theme_vars.inc.php';
99 $listofoppstatus = array();
100 $listofopplabel = array();
101 $listofoppcode = array();
102 $colorseriesstat = array();
103 $sql =
"SELECT cls.rowid, cls.code, cls.percent, cls.label";
104 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_lead_status as cls";
105 $sql .=
" WHERE active=1";
106 $sql .=
" AND cls.code <> 'LOST'";
107 $sql .=
" AND cls.code <> 'WON'";
108 $sql .= $this->db->order(
'cls.rowid',
'ASC');
109 $resql = $this->db->query($sql);
111 $num = $this->db->num_rows($resql);
115 $objp = $this->db->fetch_object($resql);
116 $listofoppstatus[$objp->rowid] = $objp->percent;
117 $listofopplabel[$objp->rowid] = $objp->label;
118 $listofoppcode[$objp->rowid] = $objp->code;
119 switch ($objp->code) {
121 $colorseriesstat[$objp->rowid] =
'-'.$badgeStatus0;
124 $colorseriesstat[$objp->rowid] =
'-'.$badgeStatus1;
127 $colorseriesstat[$objp->rowid] = $badgeStatus1;
130 $colorseriesstat[$objp->rowid] = $badgeStatus4;
141 global $conf, $user, $langs;
144 $this->info_box_head = array(
145 'text' => $langs->trans(
"Statistics").
' - '.$langs->trans(
"BoxTitleFunnelOfProspection"),
150 if ($user->hasRight(
'projet',
'lire') ||
getDolGlobalString(
'PROJECT_USE_OPPORTUNITIES')) {
151 $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";
152 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p, ".MAIN_DB_PREFIX.
"c_lead_status as cls";
153 $sql .=
" WHERE p.entity IN (".getEntity(
'project').
")";
154 $sql .=
" AND p.fk_opp_status = cls.rowid";
155 $sql .=
" AND p.fk_statut = 1";
156 $sql .=
" AND cls.code NOT IN ('LOST', 'WON')";
157 $sql .=
" GROUP BY p.fk_opp_status, cls.code";
158 $resql = $this->db->query($sql);
160 $form =
new Form($this->db);
162 $num = $this->db->num_rows($resql);
168 $ponderated_opp_amount = 0;
170 $valsamount = array();
171 $dataseries = array();
174 $obj = $this->db->fetch_object($resql);
176 $valsnb[$obj->opp_status] = $obj->nb;
177 $valsamount[$obj->opp_status] = $obj->opp_amount;
178 $totalnb += $obj->nb;
179 if ($obj->opp_status) {
180 $totaloppnb += $obj->nb;
182 if (!in_array($obj->code, array(
'WON',
'LOST'))) {
183 $totalamount += $obj->opp_amount;
184 $ponderated_opp_amount += $obj->ponderated_opp_amount;
189 $this->db->free($resql);
190 $ponderated_opp_amount = $ponderated_opp_amount / 100;
193 $stringtoprint .=
'<div class="div-table-responsive-no-min ">';
194 $listofstatus = array_keys($listofoppstatus);
195 $liststatus = array();
197 $customlabels = array();
199 foreach ($listofstatus as $status) {
205 $labelStatus = $langs->transnoentitiesnoconv(
"OppStatus".$code);
207 if (empty($labelStatus)) {
208 $labelStatus = $listofopplabel[$status];
210 $amount = (isset($valsamount[$status]) ? (float) $valsamount[$status] : 0);
212 $customlabel = $amount;
213 $liststatus[] = $labelStatus;
214 if (!$conf->use_javascript_ajax) {
215 $stringtoprint .=
'<tr class="oddeven">';
216 $stringtoprint .=
'<td>'.$labelStatus.
'</td>';
217 $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>';
218 $stringtoprint .=
"</tr>\n";
221 $customlabels[] = $customlabel;
223 $dataseries[] = $data;
224 if ($conf->use_javascript_ajax) {
225 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
227 $dolgraph->SetMinValue(0);
228 $dolgraph->SetData($dataseries);
229 $dolgraph->SetLegend($liststatus);
230 $dolgraph->setHideXValues(
true);
231 $dolgraph->SetDataColor(array_values($colorseriesstat));
233 $dolgraph->setShowLegend(2);
234 if (!empty($conf->dol_optimize_smallscreen)) {
235 $dolgraph->SetWidth(320);
237 $dolgraph->setShowPercent(1);
238 $dolgraph->setMirrorGraphValues(
true);
239 $dolgraph->setBorderWidth(2);
240 $dolgraph->setBorderSkip(
'false');
241 $dolgraph->SetType(array(
'horizontalbars'));
242 $dolgraph->SetHeight(
'200');
243 $dolgraph->SetWidth(
'600');
244 $dolgraph->setTooltipsTitles($liststatus);
245 $dolgraph->setTooltipsLabels($customlabels);
246 $dolgraph->mode =
'depth';
247 $dolgraph->draw(
'idgraphleadfunnel');
248 $stringtoprint .= $dolgraph->show($totaloppnb ? 0 : 1);
250 $stringtoprint .=
'</div>';
262 $this->info_box_contents[$line][] = array(
264 'td' =>
'class="center nopaddingleftimp nopaddingrightimp" colspan="2"',
265 'text' => $stringtoprint
268 $this->info_box_contents[$line][] = array(
269 'tr' =>
'class="oddeven"',
270 'td' =>
'class="left "',
272 'text' => $langs->trans(
"OpportunityTotalAmount").
' ('.$langs->trans(
"WonLostExcluded").
')'
274 $this->info_box_contents[$line][] = array(
275 'tr' =>
'class="oddeven"',
276 'td' =>
'class="nowraponall right amount"',
278 'text' =>
price($totalamount, 0,
'', 1, -1, -1, $conf->currency)
281 $this->info_box_contents[$line][] = array(
282 'tr' =>
'class="oddeven"',
283 'td' =>
'class="left "',
285 'text' => $form->textwithpicto($langs->trans(
"OpportunityPonderatedAmount").
' ('.$langs->trans(
"WonLostExcluded").
')', $langs->trans(
"OpportunityPonderatedAmountDesc"), 1)
288 $this->info_box_contents[$line][] = array(
289 'td' =>
'class="nowraponall right amount"',
291 'text' =>
price(
price2num($ponderated_opp_amount,
'MT'), 0,
'', 1, -1, -1, $conf->currency)
294 $this->info_box_contents[0][0] = array(
295 'td' =>
'class="center"',
296 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"NoRecordedCustomers").
'</span>'
300 $this->info_box_contents[0][0] = array(
302 'text' => $langs->trans(
"ReadPermissionNotAllowed")