Merge pull request #14942 from TobiasSekan/ShowProjectOverviewCount

Show count on project overview tab
This commit is contained in:
Laurent Destailleur 2020-10-06 23:34:43 +02:00 committed by GitHub
commit 47c80f0d14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 85 additions and 22 deletions

View File

@ -30,23 +30,23 @@ require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
/**
* Prepare array with list of tabs
*
* @param Object $object Object related to tabs
* @return array Array of tabs to show
* @param Project $project Object related to tabs
* @return array Array of tabs to show
*/
function project_prepare_head($object)
function project_prepare_head(Project $project)
{
global $db, $langs, $conf, $user;
$h = 0;
$head = array();
$head[$h][0] = DOL_URL_ROOT.'/projet/card.php?id='.$object->id;
$head[$h][0] = DOL_URL_ROOT.'/projet/card.php?id='.$project->id;
$head[$h][1] = $langs->trans("Project");
$head[$h][2] = 'project';
$h++;
$nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
$head[$h][0] = DOL_URL_ROOT.'/projet/contact.php?id='.$object->id;
$nbContact = count($project->liste_contact(-1, 'internal')) + count($project->liste_contact(-1, 'external'));
$head[$h][0] = DOL_URL_ROOT.'/projet/contact.php?id='.$project->id;
$head[$h][1] = $langs->trans("ProjectContact");
if ($nbContact > 0) $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
$head[$h][2] = 'contact';
@ -55,12 +55,12 @@ function project_prepare_head($object)
if (empty($conf->global->PROJECT_HIDE_TASKS))
{
// Then tab for sub level of projet, i mean tasks
$head[$h][0] = DOL_URL_ROOT.'/projet/tasks.php?id='.$object->id;
$head[$h][0] = DOL_URL_ROOT.'/projet/tasks.php?id='.$project->id;
$head[$h][1] = $langs->trans("Tasks");
require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
$taskstatic = new Task($db);
$nbTasks = count($taskstatic->getTasksArray(0, 0, $object->id, 0, 0));
$nbTasks = count($taskstatic->getTasksArray(0, 0, $project->id, 0, 0));
if ($nbTasks > 0) $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbTasks).'</span>';
$head[$h][2] = 'tasks';
$h++;
@ -71,7 +71,7 @@ function project_prepare_head($object)
//$sql .= " WHERE t.fk_user = u.rowid AND t.fk_task = pt.rowid";
$sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as t, ".MAIN_DB_PREFIX."projet_task as pt";
$sql .= " WHERE t.fk_task = pt.rowid";
$sql .= " AND pt.fk_projet =".$object->id;
$sql .= " AND pt.fk_projet =".$project->id;
$resql = $db->query($sql);
if ($resql)
{
@ -79,7 +79,7 @@ function project_prepare_head($object)
if ($obj) $nbTimeSpent = 1;
} else dol_print_error($db);
$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/time.php?withproject=1&projectid='.$object->id;
$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/time.php?withproject=1&projectid='.$project->id;
$head[$h][1] = $langs->trans("TimeSpent");
if ($nbTimeSpent > 0) $head[$h][1] .= '<span class="badge marginleftonlyshort">...</span>';
$head[$h][2] = 'timespent';
@ -91,8 +91,32 @@ function project_prepare_head($object)
|| !empty($conf->facture->enabled) || !empty($conf->contrat->enabled)
|| !empty($conf->ficheinter->enabled) || !empty($conf->agenda->enabled) || !empty($conf->deplacement->enabled))
{
$head[$h][0] = DOL_URL_ROOT.'/projet/element.php?id='.$object->id;
$count = 0;
if (!empty($conf->propal->enabled)) $count += $project->getElementCount('propal', 'propal');
if (!empty($conf->commande->enabled)) $count += $project->getElementCount('order', 'commande');
if (!empty($conf->facture->enabled)) $count += $project->getElementCount('invoice', 'facture');
if (!empty($conf->facture->enabled)) $count += $project->getElementCount('invoice_predefined', 'facture_rec');
if (!empty($conf->supplier_proposal->enabled)) $count += $project->getElementCount('proposal_supplier', 'supplier_proposal');
if (!empty($conf->supplier_order->enabled)) $count += $project->getElementCount('order_supplier', 'commande_fournisseur');
if (!empty($conf->supplier_invoice->enabled)) $count += $project->getElementCount('invoice_supplier', 'facture_fourn');
if (!empty($conf->contrat->enabled)) $count += $project->getElementCount('contract', 'contrat');
if (!empty($conf->ficheinter->enabled)) $count += $project->getElementCount('intervention', 'fichinter');
if (!empty($conf->expedition->enabled)) $count += $project->getElementCount('shipping', 'expedition');
if (!empty($conf->mrp->enabled)) $count += $project->getElementCount('mrp', 'mrp_mo', 'fk_project');
if (!empty($conf->deplacement->enabled)) $count += $project->getElementCount('trip', 'deplacement');
if (!empty($conf->expensereport->enabled)) $count += $project->getElementCount('expensereport', 'expensereport');
if (!empty($conf->don->enabled)) $count += $project->getElementCount('donation', 'don');
if (!empty($conf->loan->enabled)) $count += $project->getElementCount('loan', 'loan');
if (!empty($conf->tax->enabled)) $count += $project->getElementCount('chargesociales', 'chargesociales');
if (!empty($conf->projet->enabled)) $count += $project->getElementCount('project_task', 'projet_task');
if (!empty($conf->stock->enabled)) $count += $project->getElementCount('stock_mouvement', 'stock');
if (!empty($conf->salaries->enabled)) $count += $project->getElementCount('salaries', 'payment_salary');
if (!empty($conf->banque->enabled)) $count += $project->getElementCount('variouspayment', 'payment_various');
$head[$h][0] = DOL_URL_ROOT.'/projet/element.php?id='.$project->id;
$head[$h][1] = $langs->trans("ProjectOverview");
if ($count > 0) $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$count.'</span>';
$head[$h][2] = 'element';
$h++;
}
@ -101,15 +125,15 @@ function project_prepare_head($object)
// Entries must be declared in modules descriptor with line
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
// $this->tabs = array('entity:-tabname); to remove a tab
complete_head_from_modules($conf, $langs, $object, $head, $h, 'project');
complete_head_from_modules($conf, $langs, $project, $head, $h, 'project');
if (empty($conf->global->MAIN_DISABLE_NOTES_TAB))
{
$nbNote = 0;
if (!empty($object->note_private)) $nbNote++;
if (!empty($object->note_public)) $nbNote++;
$head[$h][0] = DOL_URL_ROOT.'/projet/note.php?id='.$object->id;
if (!empty($project->note_private)) $nbNote++;
if (!empty($project->note_public)) $nbNote++;
$head[$h][0] = DOL_URL_ROOT.'/projet/note.php?id='.$project->id;
$head[$h][1] = $langs->trans('Notes');
if ($nbNote > 0) $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
$head[$h][2] = 'notes';
@ -118,10 +142,10 @@ function project_prepare_head($object)
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
$upload_dir = $conf->projet->dir_output."/".dol_sanitizeFileName($object->ref);
$upload_dir = $conf->projet->dir_output."/".dol_sanitizeFileName($project->ref);
$nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
$nbLinks = Link::count($db, $object->element, $object->id);
$head[$h][0] = DOL_URL_ROOT.'/projet/document.php?id='.$object->id;
$nbLinks = Link::count($db, $project->element, $project->id);
$head[$h][0] = DOL_URL_ROOT.'/projet/document.php?id='.$project->id;
$head[$h][1] = $langs->trans('Documents');
if (($nbFiles + $nbLinks) > 0) $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
$head[$h][2] = 'document';
@ -130,15 +154,15 @@ function project_prepare_head($object)
// Manage discussion
if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_PROJECT))
{
$nbComments = $object->getNbComments();
$head[$h][0] = DOL_URL_ROOT.'/projet/comment.php?id='.$object->id;
$nbComments = $project->getNbComments();
$head[$h][0] = DOL_URL_ROOT.'/projet/comment.php?id='.$project->id;
$head[$h][1] = $langs->trans("CommentLink");
if ($nbComments > 0) $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbComments.'</span>';
$head[$h][2] = 'project_comment';
$h++;
}
$head[$h][0] = DOL_URL_ROOT.'/projet/info.php?id='.$object->id;
$head[$h][0] = DOL_URL_ROOT.'/projet/info.php?id='.$project->id;
$head[$h][1] .= $langs->trans("Events");
if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read)))
{
@ -148,7 +172,7 @@ function project_prepare_head($object)
$head[$h][2] = 'agenda';
$h++;
complete_head_from_modules($conf, $langs, $object, $head, $h, 'project', 'remove');
complete_head_from_modules($conf, $langs, $project, $head, $h, 'project', 'remove');
return $head;
}

View File

@ -848,6 +848,45 @@ class Project extends CommonObject
}
}
/**
* Return the count of a type of linked elements of this project
*
* @param string $type The type of the linked elements (e.g. 'propal', 'order', 'invoice', 'order_supplier', 'invoice_supplier')
* @param string $tablename The name of table associated of the type
* @param string $projectkey (optional) Equivalent key to fk_projet for actual type
* @return integer The count of the linked elements (the count is zero on request error too)
*/
public function getElementCount($type, $tablename, $projectkey = 'fk_projet')
{
if ($this->id <= 0) return 0;
if ($type == 'agenda') {
$sql = "SELECT COUNT(id) as nb FROM ".MAIN_DB_PREFIX."actioncomm WHERE fk_project = ".$this->id." AND entity IN (".getEntity('agenda').")";
} elseif ($type == 'expensereport') {
$sql = "SELECT COUNT(ed.rowid) as nb FROM ".MAIN_DB_PREFIX."expensereport as e, ".MAIN_DB_PREFIX."expensereport_det as ed WHERE e.rowid = ed.fk_expensereport AND e.entity IN (".getEntity('expensereport').") AND ed.fk_projet = ".$this->id;
} elseif ($type == 'project_task') {
$sql = "SELECT DISTINCT COUNT(pt.rowid) as nb FROM ".MAIN_DB_PREFIX."projet_task as pt WHERE pt.fk_projet = ".$this->id;
} elseif ($type == 'project_task_time') { // Case we want to duplicate line foreach user
$sql = "SELECT DISTINCT COUNT(pt.rowid) as nb FROM ".MAIN_DB_PREFIX."projet_task as pt, ".MAIN_DB_PREFIX."projet_task_time as ptt WHERE pt.rowid = ptt.fk_task AND pt.fk_projet = ".$this->id;
} elseif ($type == 'stock_mouvement') {
$sql = 'SELECT COUNT(ms.rowid) as nb FROM '.MAIN_DB_PREFIX."stock_mouvement as ms, ".MAIN_DB_PREFIX."entrepot as e WHERE e.rowid = ms.fk_entrepot AND e.entity IN (".getEntity('stock').") AND ms.origintype = 'project' AND ms.fk_origin = ".$this->id." AND ms.type_mouvement = 1";
} elseif ($type == 'loan') {
$sql = 'SELECT COUNT(l.rowid) as nb FROM '.MAIN_DB_PREFIX."loan as l WHERE l.entity IN (".getEntity('loan').") AND l.fk_projet = ".$this->id;
} else {
$sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.$tablename." WHERE ".$projectkey." = ".$this->id." AND entity IN (".getEntity($type).")";
}
$result = $this->db->query($sql);
if (!$result) return 0;
$obj = $this->db->fetch_object($result);
$this->db->free($result);
return $obj->nb;
}
/**
* Delete tasks with no children first, then task with children recursively
*