diff --git a/htdocs/projet/graph_opportunities.inc.php b/htdocs/projet/graph_opportunities.inc.php new file mode 100644 index 00000000000..6cae34bddfa --- /dev/null +++ b/htdocs/projet/graph_opportunities.inc.php @@ -0,0 +1,85 @@ +global->PROJECT_USE_OPPORTUNITIES)) +{ + $sql = "SELECT COUNT(p.rowid) as nb, SUM(p.opp_amount) as opp_amount, p.fk_opp_status as opp_status"; + $sql.= " FROM ".MAIN_DB_PREFIX."projet as p"; + $sql.= " WHERE p.entity = ".$conf->entity; + $sql.= " AND p.fk_statut = 1"; + if ($mine || empty($user->rights->projet->all->lire)) $sql.= " AND p.rowid IN (".$projectsListId.")"; + if ($socid) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")"; + $sql.= " GROUP BY p.fk_opp_status"; + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; + + $totalnb=0; + $totalamount=0; + $ponderated_opp_amount=0; + $valsnb=array(); + $valsamount=array(); + $dataseries=array(); + // -1=Canceled, 0=Draft, 1=Validated, (2=Accepted/On process not managed for customer orders), 3=Closed (Sent/Received, billed or not) + while ($i < $num) + { + $obj = $db->fetch_object($resql); + if ($obj) + { + //if ($row[1]!=-1 && ($row[1]!=3 || $row[2]!=1)) + { + $valsnb[$obj->opp_status]=$obj->nb; + $valsamount[$obj->opp_status]=$obj->opp_amount; + $totalnb+=$obj->nb; + $totalamount+=$obj->opp_amount; + $ponderated_opp_amount = $ponderated_opp_amount + price2num($listofoppstatus[$obj->opp_status] * $obj->opp_amount / 100); + } + $total+=$row[0]; + } + $i++; + } + $db->free($resql); + + print ''; + print ''."\n"; + $var=true; + $listofstatus=array_keys($listofoppstatus); + foreach ($listofstatus as $status) + { + $labelstatus = ''; + + $code = dol_getIdFromCode($db, $status, 'c_lead_status', 'rowid', 'code'); + if ($code) $labelstatus = $langs->trans("OppStatus".$code); + if (empty($labelstatus)) $labelstatus=$listofopplabel[$status]; + + //$labelstatus .= ' ('.$langs->trans("Coeff").': '.price2num($listofoppstatus[$status]).')'; + $labelstatus .= ' - '.price2num($listofoppstatus[$status]).'%'; + + $dataseries[]=array('label'=>$labelstatus,'data'=>(isset($valsamount[$status])?(float) $valsamount[$status]:0)); + if (! $conf->use_javascript_ajax) + { + $var=!$var; + print ""; + print ''; + print ''; + print "\n"; + } + } + if ($conf->use_javascript_ajax) + { + print ''; + } + //if ($totalinprocess != $total) + //print ''; + print ''; + print ''; + print "
'.$langs->trans("Statistics").' - '.$langs->trans("OpportunitiesStatusForOpenedProjects").'
'.$labelstatus.''.price((isset($valsamount[$status])?(float) $valsamount[$status]:0), 0, '', 1, -1, -1, $conf->currency).'
'; + $data=array('series'=>$dataseries); + dol_print_graph('stats',400,180,$data,1,'pie',0,'',0); + print '
'.$langs->trans("Total").' ('.$langs->trans("CustomersOrdersRunning").')'.$totalinprocess.'
'.$langs->trans("OpportunityTotalAmount").''.price($totalamount, 0, '', 1, -1, -1, $conf->currency).'
'.$langs->trans("OpportunityPonderatedAmount").''.price($ponderated_opp_amount, 0, '', 1, -1, -1, $conf->currency).'

"; + } + else + { + dol_print_error($db); + } +} diff --git a/htdocs/projet/index.php b/htdocs/projet/index.php index 11ae9e78906..b91b8763611 100644 --- a/htdocs/projet/index.php +++ b/htdocs/projet/index.php @@ -128,91 +128,7 @@ if (count($listofsearchfields)) /* * Statistics */ - -if (! empty($conf->global->PROJECT_USE_OPPORTUNITIES)) -{ - $sql = "SELECT COUNT(p.rowid) as nb, SUM(p.opp_amount) as opp_amount, p.fk_opp_status as opp_status"; - $sql.= " FROM ".MAIN_DB_PREFIX."projet as p"; - $sql.= " WHERE p.entity = ".$conf->entity; - $sql.= " AND p.fk_statut = 1"; - if ($mine || empty($user->rights->projet->all->lire)) $sql.= " AND p.rowid IN (".$projectsListId.")"; - if ($socid) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")"; - $sql.= " GROUP BY p.fk_opp_status"; - $resql = $db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - $i = 0; - - $totalnb=0; - $totalamount=0; - $ponderated_opp_amount=0; - $valsnb=array(); - $valsamount=array(); - $dataseries=array(); - // -1=Canceled, 0=Draft, 1=Validated, (2=Accepted/On process not managed for customer orders), 3=Closed (Sent/Received, billed or not) - while ($i < $num) - { - $obj = $db->fetch_object($resql); - if ($obj) - { - //if ($row[1]!=-1 && ($row[1]!=3 || $row[2]!=1)) - { - $valsnb[$obj->opp_status]=$obj->nb; - $valsamount[$obj->opp_status]=$obj->opp_amount; - $totalnb+=$obj->nb; - $totalamount+=$obj->opp_amount; - $ponderated_opp_amount = $ponderated_opp_amount + price2num($listofoppstatus[$obj->opp_status] * $obj->opp_amount / 100); - } - $total+=$row[0]; - } - $i++; - } - $db->free($resql); - - print ''; - print ''."\n"; - $var=true; - $listofstatus=array_keys($listofoppstatus); - foreach ($listofstatus as $status) - { - $labelstatus = ''; - - $code = dol_getIdFromCode($db, $status, 'c_lead_status', 'rowid', 'code'); - if ($code) $labelstatus = $langs->trans("OppStatus".$code); - if (empty($labelstatus)) $labelstatus=$listofopplabel[$status]; - - //$labelstatus .= ' ('.$langs->trans("Coeff").': '.price2num($listofoppstatus[$status]).')'; - $labelstatus .= ' - '.price2num($listofoppstatus[$status]).'%'; - - $dataseries[]=array('label'=>$labelstatus,'data'=>(isset($valsamount[$status])?(float) $valsamount[$status]:0)); - if (! $conf->use_javascript_ajax) - { - $var=!$var; - print ""; - print ''; - print ''; - print "\n"; - } - } - if ($conf->use_javascript_ajax) - { - print ''; - } - //if ($totalinprocess != $total) - //print ''; - print ''; - print ''; - print "
'.$langs->trans("Statistics").' - '.$langs->trans("OpportunitiesStatusForOpenedProjects").'
'.$labelstatus.''.price((isset($valsamount[$status])?(float) $valsamount[$status]:0), 0, '', 1, -1, -1, $conf->currency).'
'; - $data=array('series'=>$dataseries); - dol_print_graph('stats',400,180,$data,1,'pie',0,''); - print '
'.$langs->trans("Total").' ('.$langs->trans("CustomersOrdersRunning").')'.$totalinprocess.'
'.$langs->trans("OpportunityTotalAmount").''.price($totalamount, 0, '', 1, -1, -1, $conf->currency).'
'.$langs->trans("OpportunityPonderatedAmount").''.price($ponderated_opp_amount, 0, '', 1, -1, -1, $conf->currency).'

"; - } - else - { - dol_print_error($db); - } -} +include DOL_DOCUMENT_ROOT.'/projet/graph_opportunities.inc.php'; // List of draft projects diff --git a/htdocs/projet/list.php b/htdocs/projet/list.php index 7481a6bf05c..c4e8b8f5783 100644 --- a/htdocs/projet/list.php +++ b/htdocs/projet/list.php @@ -276,15 +276,16 @@ if ($resql) $moreforfilter.=$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, 1, 'maxwidth300'); $moreforfilter.=''; } - // If the user can view prospects other than his' - if (($user->rights->societe->client->voir || $socid) && !$mine) - { - $moreforfilter.='
'; - $moreforfilter.=$langs->trans('ProjectsWithThisUserAsContact'). ': '; - $moreforfilter.=$form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300'); - $moreforfilter.='
'; - } + // If the user can view prospects other than his' + if ($mine) $search_user=$user->id; + $moreforfilter.='
'; + $moreforfilter.=$langs->trans('ProjectsWithThisUserAsContact'). ': '; + $includeonly=''; + if (empty($user->rights->user->user->lire)) $includeonly=array($user->id); + $moreforfilter.=$form->select_dolusers($search_user, 'search_user', 1, '', 0, $includeonly, '', 0, 0, 0, '', 0, '', 'maxwidth300'); + $moreforfilter.='
'; + if (! empty($moreforfilter)) { print '
';