NEW Add filter "opportunity status" on statistics of projects.

This commit is contained in:
Laurent Destailleur 2022-05-16 10:45:42 +02:00
parent 508cbee1a5
commit ac60aa4711
5 changed files with 53 additions and 76 deletions

View File

@ -236,14 +236,14 @@ class Project extends CommonObject
'datee' =>array('type'=>'date', 'label'=>'DateEnd', 'enabled'=>1, 'visible'=>1, 'position'=>35),
'description' =>array('type'=>'text', 'label'=>'Description', 'enabled'=>1, 'visible'=>3, 'position'=>55, 'searchall'=>1),
'public' =>array('type'=>'integer', 'label'=>'Visibility', 'enabled'=>1, 'visible'=>1, 'position'=>65),
'fk_opp_status' =>array('type'=>'integer', 'label'=>'OpportunityStatusShort', 'enabled'=>1, 'visible'=>1, 'position'=>75),
'opp_percent' =>array('type'=>'double(5,2)', 'label'=>'OpportunityProbabilityShort', 'enabled'=>1, 'visible'=>1, 'position'=>80),
'fk_opp_status' =>array('type'=>'integer', 'label'=>'OpportunityStatusShort', 'enabled'=>'!empty($conf->global->PROJECT_USE_OPPORTUNITIES)', 'visible'=>1, 'position'=>75),
'opp_percent' =>array('type'=>'double(5,2)', 'label'=>'OpportunityProbabilityShort', 'enabled'=>'!empty($conf->global->PROJECT_USE_OPPORTUNITIES)', 'visible'=>1, 'position'=>80),
'note_private' =>array('type'=>'text', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>0, 'position'=>85, 'searchall'=>1),
'note_public' =>array('type'=>'text', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>90, 'searchall'=>1),
'model_pdf' =>array('type'=>'varchar(255)', 'label'=>'ModelPdf', 'enabled'=>1, 'visible'=>0, 'position'=>95),
'date_close' =>array('type'=>'datetime', 'label'=>'DateClosing', 'enabled'=>1, 'visible'=>0, 'position'=>105),
'fk_user_close' =>array('type'=>'integer', 'label'=>'UserClosing', 'enabled'=>1, 'visible'=>0, 'position'=>110),
'opp_amount' =>array('type'=>'double(24,8)', 'label'=>'OpportunityAmountShort', 'enabled'=>1, 'visible'=>1, 'position'=>115),
'opp_amount' =>array('type'=>'double(24,8)', 'label'=>'OpportunityAmountShort', 'enabled'=>1, 'visible'=>'!empty($conf->global->PROJECT_USE_OPPORTUNITIES)', 'position'=>115),
'budget_amount' =>array('type'=>'double(24,8)', 'label'=>'Budget', 'enabled'=>1, 'visible'=>1, 'position'=>119),
'usage_bill_time' =>array('type'=>'integer', 'label'=>'UsageBillTimeShort', 'enabled'=>1, 'visible'=>-1, 'position'=>130),
'usage_opportunity' =>array('type'=>'integer', 'label'=>'UsageOpportunity', 'enabled'=>1, 'visible'=>-1, 'position'=>135),

View File

@ -28,6 +28,10 @@ class ProjectStats extends Stats
public $userid;
public $socid;
public $year;
public $yearmonth;
public $status;
public $opp_status;
/**
* Constructor
@ -180,7 +184,25 @@ class ProjectStats extends Stats
}
if (!empty($this->status)) {
$sqlwhere[] = " t.fk_opp_status IN (".$this->db->sanitize($this->status).")";
$sqlwhere[] = " t.fk_statut IN (".$this->db->sanitize($this->status).")";
}
if (!empty($this->opp_status)) {
if (is_numeric($this->opp_status) && $this->opp_status > 0) {
$sqlwhere[] = " t.fk_opp_status = ".((int) $this->opp_status);
}
if ($this->opp_status == 'all') {
$sqlwhere[] = " (t.fk_opp_status IS NOT NULL AND t.fk_opp_status <> -1)";
}
if ($this->opp_status == 'openedopp') {
$sqlwhere[] = " (t.fk_opp_status IS NOT NULL AND t.fk_opp_status <> -1 AND t.fk_opp_status NOT IN (SELECT rowid FROM ".MAIN_DB_PREFIX."c_lead_status WHERE code IN ('WON','LOST')))";
}
if ($this->opp_status == 'notopenedopp') {
$sqlwhere[] = " (t.fk_opp_status IS NULL OR t.fk_opp_status = -1 OR t.fk_opp_status IN (SELECT rowid FROM ".MAIN_DB_PREFIX."c_lead_status WHERE code = 'WON'))";
}
if ($this->opp_status == 'none') {
$sqlwhere[] = " (t.fk_opp_status IS NULL OR t.fk_opp_status = -1)";
}
}
if (empty($user->rights->projet->all->lire)) {

View File

@ -1174,8 +1174,8 @@ while ($i < min($num, $limit)) {
}
// Title
if (!empty($arrayfields['p.title']['checked'])) {
print '<td class="tdoverflowmax200">';
print dol_trunc($obj->title, 80);
print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->title).'">';
print $obj->title;
print '</td>';
if (!$i) {
$totalarray['nbfield']++;

View File

@ -24,18 +24,15 @@
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
require_once DOL_DOCUMENT_ROOT.'/projet/class/projectstats.class.php';
// Security check
if (!$user->rights->projet->lire) {
accessforbidden();
}
$WIDTH = DolGraph::getDefaultGraphSizeForStats('width');
$HEIGHT = DolGraph::getDefaultGraphSizeForStats('height');
$search_opp_status = GETPOST("search_opp_status", 'alpha');
$userid = GETPOST('userid', 'int');
$socid = GETPOST('socid', 'int');
// Security check
@ -44,19 +41,25 @@ if ($user->socid > 0) {
$socid = $user->socid;
}
$nowyear = strftime("%Y", dol_now());
$year = GETPOST('year') > 0 ?GETPOST('year') : $nowyear;
$year = GETPOST('year', 'int') > 0 ? GETPOST('year', 'int') : $nowyear;
$startyear = $year - (empty($conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS) ? 2 : max(1, min(10, $conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS)));
$endyear = $year;
// Load translation files required by the page
$langs->loadLangs(array('companies', 'projects'));
// Security check
if (!$user->rights->projet->lire) {
accessforbidden();
}
/*
* View
*/
$form = new Form($db);
$formproject = new FormProjets($db);
$includeuserlist = array();
@ -82,66 +85,11 @@ if (!empty($year)) {
$stats_project->year = $year;
}
/*
if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES))
{
// Current stats of project amount per status
$data1 = $stats_project->getAllProjectByStatus();
if (!is_array($data1) && $data1 < 0) {
setEventMessages($stats_project->error, null, 'errors');
if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
if ($search_opp_status) {
$stats_project->opp_status = $search_opp_status;
}
if (empty($data1))
{
$showpointvalue = 0;
$nocolor = 1;
$data1 = array(array(0=>$langs->trans("None"), 1=>1));
}
$filenamenb = $conf->project->dir_output."/stats/projectbystatus.png";
$fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=projectstats&amp;file=projectbystatus.png';
$px = new DolGraph();
$mesg = $px->isGraphKo();
if (empty($mesg)) {
$i = 0; $tot = count($data1); $legend = array();
while ($i <= $tot)
{
$legend[] = $data1[$i][0];
$i++;
}
$px->SetData($data1);
unset($data1);
if ($nocolor)
$px->SetDataColor(array(
array(
220,
220,
220
)
));
$px->SetLegend($legend);
$px->setShowLegend(0);
$px->setShowPointValue($showpointvalue);
$px->setShowPercent(1);
$px->SetMaxValue($px->GetCeilMaxValue());
$px->SetWidth($WIDTH);
$px->SetHeight($HEIGHT);
$px->SetShading(3);
$px->SetHorizTickIncrement(1);
$px->SetCssPrefix("cssboxes");
$px->SetType(array('pie'));
$px->SetTitle($langs->trans('OpportunitiesStatusForProjects'));
$result = $px->draw($filenamenb, $fileurlnb);
if ($result < 0) {
setEventMessages($px->error, null, 'errors');
}
} else {
setEventMessages(null, $mesg, 'errors');
}
}*/
}
// Build graphic number of object
@ -285,12 +233,19 @@ print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
print img_picto('', 'company', 'class="pictofixedwidth"');
print $form->select_company($socid, 'socid', '', 1, 0, 0, array(), 0, 'widthcentpercentminusx maxwidth300', '');
print '</td></tr>';
// Opportunity status
if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
print '<tr><td>'.$langs->trans("OpportunityStatusShort").'</td><td>';
print $formproject->selectOpportunityStatus('search_opp_status', $search_opp_status, 1, 0, 1, 0, 'maxwidth300', 1);
print '</td></tr>';
}
// User
/*print '<tr><td>'.$langs->trans("ProjectCommercial").'</td><td>';
print $form->select_dolusers($userid, 'userid', 1, array(),0,$includeuserlist);
print '</td></tr>';*/
// Year
print '<tr><td>'.$langs->trans("Year").'</td><td>';
print '<tr><td>'.$langs->trans("Year").' <span class="opacitymedium">('.$langs->trans("DateCreation").')</span></td><td>';
if (!in_array($year, $arrayyears)) {
$arrayyears[$year] = $year;
}

View File

@ -101,12 +101,12 @@ class Workstation extends CommonObject
public $fields=array(
'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'css'=>'left', 'comment'=>"Id"),
'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>'1', 'position'=>10, 'notnull'=>1, 'visible'=>1, 'noteditable'=>'0', 'default'=>'', 'index'=>1, 'searchall'=>1, 'showoncombobox'=>'1', 'comment'=>"Reference of object"),
'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>'1', 'position'=>30, 'notnull'=>1, 'visible'=>1, 'searchall'=>1, 'css'=>'minwidth300', 'showoncombobox'=>'2',),
'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>'1', 'position'=>30, 'notnull'=>1, 'visible'=>1, 'searchall'=>1, 'css'=>'minwidth300', 'csslist'=>'tdoverflowmax125', 'showoncombobox'=>'2',),
'type' => array('type'=>'varchar(8)', 'label'=>'Type', 'enabled'=>'1', 'position'=>32, 'default'=>1, 'notnull'=>1, 'visible'=>1, 'arrayofkeyval'=>array('HUMAN'=>'Human', 'MACHINE'=>'Machine', 'BOTH'=>'HumanMachine'),),
'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>'1', 'position'=>61, 'notnull'=>0, 'visible'=>0,),
'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>'1', 'position'=>62, 'notnull'=>0, 'visible'=>0,),
'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>500, 'notnull'=>1, 'visible'=>-2,),
'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>501, 'notnull'=>0, 'visible'=>-2,),
'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>500, 'notnull'=>1, 'visible'=>-2, 'csslist'=>'nowraponall'),
'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>501, 'notnull'=>0, 'visible'=>-2, 'csslist'=>'nowraponall'),
'fk_user_creat' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserAuthor', 'enabled'=>'1', 'position'=>510, 'notnull'=>1, 'visible'=>-2, 'foreignkey'=>'user.rowid',),
'fk_user_modif' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>'1', 'position'=>511, 'notnull'=>-1, 'visible'=>-2,),
'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>'1', 'position'=>512, 'notnull'=>-1, 'visible'=>-2,),