20if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
21 $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";
22 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p LEFT JOIN ".MAIN_DB_PREFIX.
"c_lead_status as cls ON p.fk_opp_status = cls.rowid";
23 $sql .=
" WHERE p.entity IN (".getEntity(
'project').
")";
24 $sql .=
" AND p.fk_statut = 1";
25 if ($mine || empty($user->rights->projet->all->lire)) {
26 $sql .=
" AND p.rowid IN (".$db->sanitize($projectsListId).
")";
29 $sql .=
" AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".((int) $socid).
")";
31 $sql .=
" GROUP BY p.fk_opp_status, cls.code";
32 $resql = $db->query($sql);
35 $num = $db->num_rows($resql);
42 $ponderated_opp_amount = 0;
44 $valsamount = array();
45 $dataseries = array();
48 $obj = $db->fetch_object($resql);
50 $valsnb[$obj->opp_status] = $obj->nb;
51 $valsamount[$obj->opp_status] = $obj->opp_amount;
53 if ($obj->opp_status) {
54 $totaloppnb += $obj->nb;
56 if (!in_array($obj->code, array(
'WON',
'LOST'))) {
57 $totalamount += $obj->opp_amount;
58 $ponderated_opp_amount += $obj->ponderated_opp_amount;
66 $ponderated_opp_amount = $ponderated_opp_amount / 100;
68 print
'<div class="div-table-responsive-no-min">';
69 print
'<table class="noborder nohover centpercent">';
70 print
'<tr class="liste_titre"><th colspan="2">'.$langs->trans(
"Statistics").
' - '.$langs->trans(
"OpportunitiesStatusForOpenedProjects").
'</th></tr>'.
"\n";
72 $listofstatus = array_keys($listofoppstatus);
74 foreach ($valsamount as $key => $val) {
75 if (!in_array($key, $listofstatus) && $key) {
76 $listofstatus[] = $key;
80 foreach ($listofstatus as $status) {
85 $labelStatus = $langs->transnoentitiesnoconv(
"OppStatus".$code);
86 if ($code ==
'WON' || $code ==
'LOST') {
87 $labelStatus = $langs->transnoentitiesnoconv(
"OppStatus".$code).
' ('.$langs->transnoentitiesnoconv(
"NotClosedYet").
")";
90 if (empty($labelStatus) && isset($listofopplabel[$status])) {
91 $labelStatus = $listofopplabel[$status];
93 if (empty($labelStatus)) {
94 $labelStatus = $langs->transnoentitiesnoconv(
'OldValue', $status);
100 $dataseries[] = array($labelStatus, (isset($valsamount[$status]) ? (
float) $valsamount[$status] : 0));
101 if (!$conf->use_javascript_ajax) {
102 print
'<tr class="oddeven">';
103 print
'<td>'.$labelStatus.
'</td>';
104 print
'<td class="right"><a href="list.php?statut='.$status.
'">'.
price((isset($valsamount[$status]) ? (
float) $valsamount[$status] : 0), 0,
'', 1, -1, -1, $conf->currency).
'</a></td>';
108 if ($conf->use_javascript_ajax) {
109 print
'<tr><td class="center nopaddingleftimp nopaddingrightimp" colspan="2">';
111 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
113 $dolgraph->SetData($dataseries);
114 $dolgraph->SetDataColor(array_values($colorseries));
115 $dolgraph->setShowLegend(2);
116 $dolgraph->setShowPercent(1);
117 $dolgraph->SetType(array(
'pie'));
119 $dolgraph->SetHeight(
'200');
120 $dolgraph->draw(
'idgraphstatus');
121 print $dolgraph->show($totaloppnb ? 0 : 1);
127 print
'<tr class="liste_total"><td class="maxwidth200 tdoverflow">'.$langs->trans(
"OpportunityTotalAmount").
' ('.$langs->trans(
"WonLostExcluded").
')</td><td class="right">'.
price($totalamount, 0,
'', 1, -1, -1, $conf->currency).
'</td></tr>';
128 print
'<tr class="liste_total"><td class="minwidth200 tdoverflow">';
130 print $form->textwithpicto($langs->trans(
"OpportunityPonderatedAmount").
' ('.$langs->trans(
"WonLostExcluded").
')', $langs->trans(
"OpportunityPonderatedAmountDesc"), 1);
131 print
'</td><td class="right">'.price(
price2num($ponderated_opp_amount,
'MT'), 0,
'', 1, -1, -1, $conf->currency).
'</td></tr>';
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.