From c23fab267c2bbe2a738e53cf22208875abb59eee Mon Sep 17 00:00:00 2001 From: Cubexed Date: Fri, 12 Sep 2014 05:30:17 +0200 Subject: [PATCH 1/5] This commit adds a way to filter projects by checking if selected year is in creation/ending range. The year input is shown after the list, outside the table. It's hidden by default and must be enabled with PROJECT_LIMIT_YEAR_RANGE --- htdocs/core/lib/project.lib.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/htdocs/core/lib/project.lib.php b/htdocs/core/lib/project.lib.php index e44b0dd413c..cad5880beab 100644 --- a/htdocs/core/lib/project.lib.php +++ b/htdocs/core/lib/project.lib.php @@ -642,6 +642,7 @@ function print_projecttasks_array($db, $socid, $projectsListId, $mytasks=0, $sta $sortfield=''; $sortorder=''; + $project_year_filter=0; $title=$langs->trans("Project"); if ($statut == 0) $title=$langs->trans("ProjectDraft"); @@ -681,6 +682,16 @@ function print_projecttasks_array($db, $socid, $projectsListId, $mytasks=0, $sta { $sql.= " AND p.fk_statut = ".$statut; } + if (!empty($conf->global->PROJECT_LIMIT_YEAR_RANGE)) { + $project_year_filter = GETPOST("project_year_filter"); + //Check if empty or invalid year. Wildcard ignores the sql check + if ($project_year_filter != "*") { + if (empty($project_year_filter) || !ctype_digit($project_year_filter)) { // + $project_year_filter = date("Y"); + } + $sql.= " AND (YEAR(p.datec) <= ".$project_year_filter." AND YEAR(p.datee) >= ".$project_year_filter.")"; + } + } $sql.= " GROUP BY p.rowid, p.ref, p.title, p.fk_user_creat, p.public, p.fk_statut"; $sql.= " ORDER BY p.title, p.ref"; @@ -724,6 +735,19 @@ function print_projecttasks_array($db, $socid, $projectsListId, $mytasks=0, $sta { dol_print_error($db); } + print ""; + + if (!empty($conf->global->PROJECT_LIMIT_YEAR_RANGE)) { + //Add the year filter input + print ''; + print ''; + print ''; + print ''; + print '\n"; + print '
'.$langs->trans("Year").'
'; + print ''; + print "
'; + } } From 71a1857b49b9c8d675207c90aeb008e2274381fe Mon Sep 17 00:00:00 2001 From: Cubexed Date: Fri, 12 Sep 2014 16:46:19 +0200 Subject: [PATCH 2/5] Ignore dateo/datee if is a null column --- htdocs/core/lib/project.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/project.lib.php b/htdocs/core/lib/project.lib.php index cad5880beab..f62d06c6af6 100644 --- a/htdocs/core/lib/project.lib.php +++ b/htdocs/core/lib/project.lib.php @@ -689,7 +689,7 @@ function print_projecttasks_array($db, $socid, $projectsListId, $mytasks=0, $sta if (empty($project_year_filter) || !ctype_digit($project_year_filter)) { // $project_year_filter = date("Y"); } - $sql.= " AND (YEAR(p.datec) <= ".$project_year_filter." AND YEAR(p.datee) >= ".$project_year_filter.")"; + $sql.= " AND (p.datee IS NULL OR YEAR(p.dateo) <= ".$project_year_filter.") AND (p.datee IS NULL OR YEAR(p.datee) >= ".$project_year_filter.")"; } } $sql.= " GROUP BY p.rowid, p.ref, p.title, p.fk_user_creat, p.public, p.fk_statut"; From 68994823dd7738735f848ca9b607f9174b68f8bd Mon Sep 17 00:00:00 2001 From: Cubexed Date: Fri, 12 Sep 2014 18:00:55 +0200 Subject: [PATCH 3/5] Closed projects are greyed out in project selector --- htdocs/core/class/html.formprojet.class.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/htdocs/core/class/html.formprojet.class.php b/htdocs/core/class/html.formprojet.class.php index 4042bb16e31..eafe9d9f166 100644 --- a/htdocs/core/class/html.formprojet.class.php +++ b/htdocs/core/class/html.formprojet.class.php @@ -115,12 +115,17 @@ class FormProjets { $disabled=0; $labeltoshow.=' '.dol_trunc($obj->title,$maxlength); - if (! $obj->fk_statut > 0) + if ($obj->fk_statut == 0) { $disabled=1; $labeltoshow.=' - '.$langs->trans("Draft"); } - if ($socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid)) + else if ($obj->fk_statut == 2) + { + $disabled=1; + $labeltoshow.=' - '.$langs->trans("Closed"); + } + else if ($socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid)) { $disabled=1; $labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany"); From c3b255bce999935b84b922cd62ef98aeaf697d21 Mon Sep 17 00:00:00 2001 From: Cubexed Date: Tue, 16 Sep 2014 15:27:04 +0200 Subject: [PATCH 4/5] Changed sql to be portable --- htdocs/core/lib/project.lib.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/core/lib/project.lib.php b/htdocs/core/lib/project.lib.php index f62d06c6af6..7a8f2302c12 100644 --- a/htdocs/core/lib/project.lib.php +++ b/htdocs/core/lib/project.lib.php @@ -689,7 +689,8 @@ function print_projecttasks_array($db, $socid, $projectsListId, $mytasks=0, $sta if (empty($project_year_filter) || !ctype_digit($project_year_filter)) { // $project_year_filter = date("Y"); } - $sql.= " AND (p.datee IS NULL OR YEAR(p.dateo) <= ".$project_year_filter.") AND (p.datee IS NULL OR YEAR(p.datee) >= ".$project_year_filter.")"; + $sql.= " AND (p.dateo IS NULL OR p.dateo <= ".$db->idate(dol_get_last_day($project_year_filter,12,false)).")"; + $sql.= " AND (p.datee IS NULL OR p.datee >= ".$db->idate(dol_get_first_day($project_year_filter,1,false)).")"; } } $sql.= " GROUP BY p.rowid, p.ref, p.title, p.fk_user_creat, p.public, p.fk_statut"; From fe9e7a0fa951e1ba2945af6728101aa2d5266d97 Mon Sep 17 00:00:00 2001 From: Cubexed Date: Fri, 12 Sep 2014 18:00:55 +0200 Subject: [PATCH 5/5] Revert "Closed projects are greyed out in project selector" This reverts commit 68994823dd7738735f848ca9b607f9174b68f8bd. --- htdocs/core/class/html.formprojet.class.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/htdocs/core/class/html.formprojet.class.php b/htdocs/core/class/html.formprojet.class.php index eafe9d9f166..4042bb16e31 100644 --- a/htdocs/core/class/html.formprojet.class.php +++ b/htdocs/core/class/html.formprojet.class.php @@ -115,17 +115,12 @@ class FormProjets { $disabled=0; $labeltoshow.=' '.dol_trunc($obj->title,$maxlength); - if ($obj->fk_statut == 0) + if (! $obj->fk_statut > 0) { $disabled=1; $labeltoshow.=' - '.$langs->trans("Draft"); } - else if ($obj->fk_statut == 2) - { - $disabled=1; - $labeltoshow.=' - '.$langs->trans("Closed"); - } - else if ($socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid)) + if ($socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid)) { $disabled=1; $labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany");