Fixed reports to properly handle paid status dropdown.
[timetracker.git] / WEB-INF / lib / ttReportHelper.class.php
index ae90374..ba8c9c9 100644 (file)
@@ -53,6 +53,8 @@ class ttReportHelper {
     if ($bean->getAttribute('include_records')=='2') $dropdown_parts .= ' and l.billable = 0';
     if ($bean->getAttribute('invoice')=='1') $dropdown_parts .= ' and l.invoice_id is not NULL';
     if ($bean->getAttribute('invoice')=='2') $dropdown_parts .= ' and l.invoice_id is NULL';
+    if ($bean->getAttribute('paid_status')=='1') $dropdown_parts .= ' and l.paid = 1';
+    if ($bean->getAttribute('paid_status')=='2') $dropdown_parts .= ' and l.paid = 0';
 
     // Prepare user list part.
     $userlist = -1;
@@ -74,7 +76,7 @@ class ttReportHelper {
         new DateAndTime($user->date_format, $bean->getAttribute('start_date')),
         new DateAndTime($user->date_format, $bean->getAttribute('end_date')));
     }
-    $where = " where l.status = 1 and l.date >= '".$period->getBeginDate(DB_DATEFORMAT)."' and l.date <= '".$period->getEndDate(DB_DATEFORMAT)."'".
+    $where = " where l.status = 1 and l.date >= '".$period->getStartDate(DB_DATEFORMAT)."' and l.date <= '".$period->getEndDate(DB_DATEFORMAT)."'".
       " $user_list_part $dropdown_parts";
     return $where;
   }
@@ -125,7 +127,7 @@ class ttReportHelper {
         new DateAndTime($user->date_format, $report['period_start']),
         new DateAndTime($user->date_format, $report['period_end']));
     }
-    $where = " where l.status = 1 and l.date >= '".$period->getBeginDate(DB_DATEFORMAT)."' and l.date <= '".$period->getEndDate(DB_DATEFORMAT)."'".
+    $where = " where l.status = 1 and l.date >= '".$period->getStartDate(DB_DATEFORMAT)."' and l.date <= '".$period->getEndDate(DB_DATEFORMAT)."'".
       " $user_list_part $dropdown_parts";
     return $where;
   }
@@ -164,7 +166,7 @@ class ttReportHelper {
         new DateAndTime($user->date_format, $bean->getAttribute('start_date')),
         new DateAndTime($user->date_format, $bean->getAttribute('end_date')));
     }
-    $where = " where ei.status = 1 and ei.date >= '".$period->getBeginDate(DB_DATEFORMAT)."' and ei.date <= '".$period->getEndDate(DB_DATEFORMAT)."'".
+    $where = " where ei.status = 1 and ei.date >= '".$period->getStartDate(DB_DATEFORMAT)."' and ei.date <= '".$period->getEndDate(DB_DATEFORMAT)."'".
       " $user_list_part $dropdown_parts";
     return $where;
   }
@@ -211,7 +213,7 @@ class ttReportHelper {
         new DateAndTime($user->date_format, $report['period_start']),
         new DateAndTime($user->date_format, $report['period_end']));
     }
-    $where = " where ei.status = 1 and ei.date >= '".$period->getBeginDate(DB_DATEFORMAT)."' and ei.date <= '".$period->getEndDate(DB_DATEFORMAT)."'".
+    $where = " where ei.status = 1 and ei.date >= '".$period->getStartDate(DB_DATEFORMAT)."' and ei.date <= '".$period->getEndDate(DB_DATEFORMAT)."'".
       " $user_list_part $dropdown_parts";
     return $where;
   }
@@ -276,6 +278,10 @@ class ttReportHelper {
         array_push($fields, "cast(l.billable * coalesce(upb.rate, 0) * time_to_sec(l.duration)/3600 as decimal(10,2)) as cost"); // Use project rate for user.
       array_push($fields, "null as expense"); 
     }
+    // Add paid status.
+    if ($user->canManageTeam() && $bean->getAttribute('chpaid'))
+      array_push($fields, 'l.paid as paid');
+
     // Add invoice name if it is selected.
     if (($user->canManageTeam() || $user->isClient()) && $bean->getAttribute('chinvoice'))
       array_push($fields, 'i.name as invoice');
@@ -945,7 +951,7 @@ class ttReportHelper {
         new DateAndTime($user->date_format, $bean->getAttribute('end_date')));
     }
 
-    $totals['start_date'] = $period->getBeginDate();
+    $totals['start_date'] = $period->getStartDate();
     $totals['end_date'] = $period->getEndDate();
     $totals['time'] = $total_time;
     $totals['cost'] = $total_cost;
@@ -1015,7 +1021,7 @@ class ttReportHelper {
         new DateAndTime($user->date_format, $report['period_end']));
     }
 
-    $totals['start_date'] = $period->getBeginDate();
+    $totals['start_date'] = $period->getStartDate();
     $totals['end_date'] = $period->getEndDate();
     $totals['time'] = $total_time;
     $totals['cost'] = $total_cost;
@@ -1062,7 +1068,7 @@ class ttReportHelper {
     $style_title = 'text-align: center; font-size: 15pt; font-family: Arial, Helvetica, sans-serif;';
     $tableHeader = 'font-weight: bold; background-color: #a6ccf7; text-align: left;';
     $tableHeaderCentered = 'font-weight: bold; background-color: #a6ccf7; text-align: center;';
-    $rowItem = 'background-color: #ccccce;';
+    $rowItem = 'background-color: #ffffff;';
     $rowItemAlt = 'background-color: #f5f5f5;';
     $rowSubtotal = 'background-color: #e0e0e0;';
     $cellLeftAligned = 'text-align: left; vertical-align: top;';
@@ -1300,6 +1306,20 @@ class ttReportHelper {
     return $body;
   }
 
+  // checkFavReportCondition - checks whether it is okay to send fav report.
+  static function checkFavReportCondition($report, $condition)
+  {
+    $items = ttReportHelper::getFavItems($report);
+
+    $condition = str_replace('count', '', $condition);
+    $count_required = intval(trim(str_replace('>', '', $condition)));
+
+    if (count($items) > $count_required)
+      return true; // Condition ok.
+
+    return false;
+  }
+
   // prepareFavReportBody - prepares an email body for a favorite report.
   static function prepareFavReportBody($report)
   {
@@ -1320,7 +1340,7 @@ class ttReportHelper {
     $style_title = 'text-align: center; font-size: 15pt; font-family: Arial, Helvetica, sans-serif;';
     $tableHeader = 'font-weight: bold; background-color: #a6ccf7; text-align: left;';
     $tableHeaderCentered = 'font-weight: bold; background-color: #a6ccf7; text-align: center;';
-    $rowItem = 'background-color: #ccccce;';
+    $rowItem = 'background-color: #ffffff;';
     $rowItemAlt = 'background-color: #f5f5f5;';
     $rowSubtotal = 'background-color: #e0e0e0;';
     $cellLeftAligned = 'text-align: left; vertical-align: top;';
@@ -1559,9 +1579,9 @@ class ttReportHelper {
   }
 
   // sendFavReport - sends a favorite report to a specified email, called from cron.php
-  static function sendFavReport($report, $email) {
+  static function sendFavReport($report, $subject, $email, $cc) {
     // We are called from cron.php, we have no $bean in session.
-    // cron.php set global $user and $i18n objects to match our favorite report user.
+    // cron.php sets global $user and $i18n objects to match our favorite report user.
     global $user;
     global $i18n;
 
@@ -1573,9 +1593,14 @@ class ttReportHelper {
     $mailer->setCharSet(CHARSET);
     $mailer->setContentType('text/html');
     $mailer->setSender(SENDER);
+    if (!empty($cc))
+      $mailer->setReceiverCC($cc);
+    if (!empty($user->bcc_email))
+      $mailer->setReceiverBCC($user->bcc_email);
     $mailer->setReceiver($email);
-    $mailer->setSendType(MAIL_MODE);
-    if (!$mailer->send($report['name'], $body))
+    $mailer->setMailMode(MAIL_MODE);
+    if (empty($subject)) $subject = $report['name'];
+    if (!$mailer->send($subject, $body))
       return false;
 
     return true;