Initial attempt to implement quota percent for users.
[timetracker.git] / WEB-INF / lib / ttReportHelper.class.php
index 2265f0d..686283b 100644 (file)
@@ -191,8 +191,8 @@ class ttReportHelper {
       if ($user->getConfigOption('unit_totals_only'))
         array_push($fields, "null as units");
       else {
-        $firstUnitThreshold = $user->getConfigInt('1st_unit_threshold');
-        $minutesInUnit = $user->getConfigInt('minutes_in_unit');
+        $firstUnitThreshold = $user->getConfigInt('1st_unit_threshold', 0);
+        $minutesInUnit = $user->getConfigInt('minutes_in_unit', 15);
         array_push($fields, "if(l.billable = 0 or time_to_sec(l.duration)/60 < $firstUnitThreshold, 0, ceil(time_to_sec(l.duration)/60/$minutesInUnit)) as units");
       }
     }
@@ -463,18 +463,22 @@ class ttReportHelper {
   static function getTotals($options)
   {
     global $user;
-
     $mdb2 = getConnection();
 
+    $trackingMode = $user->getTrackingMode();
+    $decimalMark = $user->getDecimalMark();
     $where = ttReportHelper::getWhere($options);
 
     // Prepare parts.
     $time_part = "sum(time_to_sec(l.duration)) as time";
     if ($options['show_work_units']) {
-      $units_part = $user->unit_totals_only ? ", null as units" : ", sum(if(l.billable = 0 or time_to_sec(l.duration)/60 < $user->first_unit_threshold, 0, ceil(time_to_sec(l.duration)/60/$user->minutes_in_unit))) as units";
+      $unitTotalsOnly = $user->getConfigOption('unit_totals_only');
+      $firstUnitThreshold = $user->getConfigInt('1st_unit_threshold', 0);
+      $minutesInUnit = $user->getConfigInt('minutes_in_unit', 15);
+      $units_part = $unitTotalsOnly ? ", null as units" : ", sum(if(l.billable = 0 or time_to_sec(l.duration)/60 < $firstUnitThreshold, 0, ceil(time_to_sec(l.duration)/60/$minutesInUnit))) as units";
     }
     if ($options['show_cost']) {
-      if (MODE_TIME == $user->tracking_mode)
+      if (MODE_TIME == $trackingMode)
         $cost_part = ", sum(cast(l.billable * coalesce(u.rate, 0) * time_to_sec(l.duration)/3600 as decimal(10,2))) as cost, null as expenses";
       else
         $cost_part = ", sum(cast(l.billable * coalesce(upb.rate, 0) * time_to_sec(l.duration)/3600 as decimal(10,2))) as cost, null as expenses";
@@ -482,7 +486,7 @@ class ttReportHelper {
       $cost_part = ", null as cost, null as expenses";
     }
     if ($options['show_cost']) {
-      if (MODE_TIME == $user->tracking_mode) {
+      if (MODE_TIME == $trackingMode) {
         $left_joins = "left join tt_users u on (l.user_id = u.id)";
       } else {
         $left_joins = "left join tt_user_project_binds upb on (l.user_id = upb.user_id and l.project_id = upb.project_id)";
@@ -514,21 +518,22 @@ class ttReportHelper {
     if ($options['show_cost']) {
       $total_cost = $val['cost'];
       if (!$total_cost) $total_cost = '0.00';
-      if ('.' != $user->decimal_mark)
-        $total_cost = str_replace('.', $user->decimal_mark, $total_cost);
+      if ('.' != $decimalMark)
+        $total_cost = str_replace('.', $decimalMark, $total_cost);
       $total_expenses = $val['expenses'];
       if (!$total_expenses) $total_expenses = '0.00';
-      if ('.' != $user->decimal_mark)
-        $total_expenses = str_replace('.', $user->decimal_mark, $total_expenses);
+      if ('.' != $decimalMark)
+        $total_expenses = str_replace('.', $decimalMark, $total_expenses);
     }
 
+    $dateFormat = $user->getDateFormat();
     if ($options['period'])
-      $period = new Period($options['period'], new DateAndTime($user->date_format));
+      $period = new Period($options['period'], new DateAndTime($dateFormat));
     else {
       $period = new Period();
       $period->setPeriod(
-        new DateAndTime($user->date_format, $options['period_start']),
-        new DateAndTime($user->date_format, $options['period_end']));
+        new DateAndTime($dateFormat, $options['period_start']),
+        new DateAndTime($dateFormat, $options['period_end']));
     }
 
     $totals['start_date'] = $period->getStartDate();
@@ -1468,7 +1473,7 @@ class ttReportHelper {
     $workUnits = $options['show_work_units'];
     if ($workUnits) {
       $unitTotalsOnly = $user->getConfigOption('unit_totals_only');
-      $firstUnitThreshold = $user->getConfigInt('1st_unit_threshold');
+      $firstUnitThreshold = $user->getConfigInt('1st_unit_threshold', 0);
       $minutesInUnit = $user->getConfigInt('minutes_in_unit', 15);
       if ($unitTotalsOnly)
         $work_unit_part = ", if (sum(l.billable * time_to_sec(l.duration)/60) < $firstUnitThreshold, 0, ceil(sum(l.billable * time_to_sec(l.duration)/60/$minutesInUnit))) as units";
@@ -1593,7 +1598,7 @@ class ttReportHelper {
       return $key; // No need to format.
 
     global $user;
-    if ($user->date_format == DB_DATEFORMAT)
+    if ($user->getDateFormat() == DB_DATEFORMAT)
       return $key; // No need to format.
 
     $label = $key;