+ switch ($group_by1) {
+ case 'date':
+ $group_by_parts .= ', l.date';
+ break;
+ case 'user':
+ $group_by_parts .= ', u.name';
+ break;
+ case 'client':
+ $group_by_parts .= ', c.name';
+ break;
+ case 'project':
+ $group_by_parts .= ', p.name';
+ break;
+ case 'task':
+ $group_by_parts .= ', t.name';
+ break;
+ case 'cf_1':
+ $group_by_parts .= ', cfo.value';
+ break;
+ }
+ switch ($group_by2) {
+ case 'date':
+ $group_by_parts .= ', l.date';
+ break;
+ case 'user':
+ $group_by_parts .= ', u.name';
+ break;
+ case 'client':
+ $group_by_parts .= ', c.name';
+ break;
+ case 'project':
+ $group_by_parts .= ', p.name';
+ break;
+ case 'task':
+ $group_by_parts .= ', t.name';
+ break;
+ case 'cf_1':
+ $group_by_parts .= ', cfo.value';
+ break;
+ }
+ switch ($group_by3) {
+ case 'date':
+ $group_by_parts .= ', l.date';
+ break;
+ case 'user':
+ $group_by_parts .= ', u.name';
+ break;
+ case 'client':
+ $group_by_parts .= ', c.name';
+ break;
+ case 'project':
+ $group_by_parts .= ', p.name';
+ break;
+ case 'task':
+ $group_by_parts .= ', t.name';
+ break;
+ case 'cf_1':
+ $group_by_parts .= ', cfo.value';
+ break;
+ }
+ // Remove garbage from the beginning.
+ $group_by_parts = ltrim($group_by_parts, ', ');
+ $group_by_part = "group by $group_by_parts";
+ return $group_by_part;
+ }
+
+ // makeGroupByExpensesPart builds a combined group by part for sql query for expense items using
+ // group_by1, group_by2, and group_by3 values passed in $options.
+ static function makeGroupByExpensesPart($options) {
+ $no_grouping = ($options['group_by1'] == null || $options['group_by1'] == 'no_grouping') &&
+ ($options['group_by2'] == null || $options['group_by2'] == 'no_grouping') &&
+ ($options['group_by3'] == null || $options['group_by3'] == 'no_grouping');
+ if ($no_grouping) return null;
+
+ $group_by1 = $options['group_by1'];
+ $group_by2 = $options['group_by2'];
+ $group_by3 = $options['group_by3'];
+
+ switch ($group_by1) {
+ case 'date':
+ $group_by_parts .= ', ei.date';
+ break;
+ case 'user':
+ $group_by_parts .= ', u.name';
+ break;
+ case 'client':
+ $group_by_parts .= ', c.name';
+ break;
+ case 'project':
+ $group_by_parts .= ', p.name';
+ break;
+ }
+ switch ($group_by2) {
+ case 'date':
+ $group_by_parts .= ', ei.date';
+ break;
+ case 'user':
+ $group_by_parts .= ', u.name';
+ break;
+ case 'client':
+ $group_by_parts .= ', c.name';
+ break;
+ case 'project':
+ $group_by_parts .= ', p.name';
+ break;
+ }
+ switch ($group_by3) {
+ case 'date':
+ $group_by_parts .= ', ei.date';
+ break;
+ case 'user':
+ $group_by_parts .= ', u.name';
+ break;
+ case 'client':
+ $group_by_parts .= ', c.name';
+ break;
+ case 'project':
+ $group_by_parts .= ', p.name';
+ break;
+ }
+ // Remove garbage from the beginning.
+ $group_by_parts = ltrim($group_by_parts, ', ');
+ if ($group_by_parts)
+ $group_by_part = "group by $group_by_parts";
+ return $group_by_part;
+ }
+
+ // makeConcatPart builds a concatenation part for getSubtotals query (for time items).
+ static function makeConcatPart($options) {
+ $group_by1 = $options['group_by1'];
+ $group_by2 = $options['group_by2'];
+ $group_by3 = $options['group_by3'];
+
+ switch ($group_by1) {
+ case 'date':
+ $what_to_concat .= ", ' - ', l.date";
+ break;
+ case 'user':
+ $what_to_concat .= ", ' - ', u.name";
+ $fields_part .= ', u.name as user';
+ break;
+ case 'client':
+ $what_to_concat .= ", ' - ', coalesce(c.name, 'Null')";
+ $fields_part .= ', c.name as client';
+ break;
+ case 'project':
+ $what_to_concat .= ", ' - ', coalesce(p.name, 'Null')";
+ $fields_part .= ', p.name as project';
+ break;
+ case 'task':
+ $what_to_concat .= ", ' - ', coalesce(t.name, 'Null')";
+ $fields_part .= ', t.name as task';
+ break;
+ case 'cf_1':
+ $what_to_concat .= ", ' - ', coalesce(cfo.value, 'Null')";
+ $fields_part .= ', cfo.value as cf_1';
+ break;
+ }
+ switch ($group_by2) {
+ case 'date':
+ $what_to_concat .= ", ' - ', l.date";
+ break;
+ case 'user':
+ $what_to_concat .= ", ' - ', u.name";
+ $fields_part .= ', u.name as user';
+ break;
+ case 'client':
+ $what_to_concat .= ", ' - ', coalesce(c.name, 'Null')";
+ $fields_part .= ', c.name as client';
+ break;
+ case 'project':
+ $what_to_concat .= ", ' - ', coalesce(p.name, 'Null')";
+ $fields_part .= ', p.name as project';
+ break;
+ case 'task':
+ $what_to_concat .= ", ' - ', coalesce(t.name, 'Null')";
+ $fields_part .= ', t.name as task';
+ break;
+ case 'cf_1':
+ $what_to_concat .= ", ' - ', coalesce(cfo.value, 'Null')";
+ $fields_part .= ', cfo.value as cf_1';
+ break;
+ }
+ switch ($group_by3) {
+ case 'date':
+ $what_to_concat .= ", ' - ', l.date";
+ break;
+ case 'user':
+ $what_to_concat .= ", ' - ', u.name";
+ $fields_part .= ', u.name as user';
+ break;
+ case 'client':
+ $what_to_concat .= ", ' - ', coalesce(c.name, 'Null')";
+ $fields_part .= ', c.name as client';
+ break;
+ case 'project':
+ $what_to_concat .= ", ' - ', coalesce(p.name, 'Null')";
+ $fields_part .= ', p.name as project';
+ break;
+ case 'task':
+ $what_to_concat .= ", ' - ', coalesce(t.name, 'Null')";
+ $fields_part .= ', t.name as task';
+ break;
+ case 'cf_1':
+ $what_to_concat .= ", ' - ', coalesce(cfo.value, 'Null')";
+ $fields_part .= ', cfo.value as cf_1';
+ break;
+ }
+ // Remove garbage from both ends.
+ $what_to_concat = trim($what_to_concat, "', -");
+ $concat_part = "concat($what_to_concat) as group_field";
+ $concat_part = trim($concat_part, ' -');
+ return "$concat_part $fields_part";
+ }
+
+ // makeConcatPart builds a concatenation part for getSubtotals query (for expense items).
+ static function makeConcatExpensesPart($options) {
+ $group_by1 = $options['group_by1'];
+ $group_by2 = $options['group_by2'];
+ $group_by3 = $options['group_by3'];
+
+ switch ($group_by1) {
+ case 'date':
+ $what_to_concat .= ", ' - ', ei.date";
+ break;
+ case 'user':
+ $what_to_concat .= ", ' - ', u.name";
+ $fields_part .= ', u.name as user';
+ break;
+ case 'client':
+ $what_to_concat .= ", ' - ', coalesce(c.name, 'Null')";
+ $fields_part .= ', c.name as client';
+ break;
+ case 'project':
+ $what_to_concat .= ", ' - ', coalesce(p.name, 'Null')";
+ $fields_part .= ', p.name as project';
+ break;
+
+ case 'task':
+ $what_to_concat .= ", ' - ', 'Null'";
+ $fields_part .= ', null as task';
+ break;
+
+ case 'cf_1':
+ $what_to_concat .= ", ' - ', 'Null'";
+ $fields_part .= ', null as cf_1';
+ break;
+ }
+ switch ($group_by2) {
+ case 'date':
+ $what_to_concat .= ", ' - ', ei.date";
+ break;
+ case 'user':
+ $what_to_concat .= ", ' - ', u.name";
+ $fields_part .= ', u.name as user';
+ break;
+ case 'client':
+ $what_to_concat .= ", ' - ', coalesce(c.name, 'Null')";
+ $fields_part .= ', c.name as client';
+ break;
+ case 'project':
+ $what_to_concat .= ", ' - ', coalesce(p.name, 'Null')";
+ $fields_part .= ', p.name as project';
+ break;
+
+ case 'task':
+ $what_to_concat .= ", ' - ', 'Null'";
+ $fields_part .= ', null as task';
+ break;
+
+ case 'cf_1':
+ $what_to_concat .= ", ' - ', 'Null'";
+ $fields_part .= ', null as cf_1';
+ break;
+ }
+ switch ($group_by3) {
+ case 'date':
+ $what_to_concat .= ", ' - ', ei.date";
+ break;
+ case 'user':
+ $what_to_concat .= ", ' - ', u.name";
+ $fields_part .= ', u.name as user';
+ break;
+ case 'client':
+ $what_to_concat .= ", ' - ', coalesce(c.name, 'Null')";
+ $fields_part .= ', c.name as client';
+ break;
+ case 'project':
+ $what_to_concat .= ", ' - ', coalesce(p.name, 'Null')";
+ $fields_part .= ', p.name as project';
+ break;