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;
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;
}
if ($report['billable']=='2') $dropdown_parts .= ' and l.billable = 0';
if ($report['invoice']=='1') $dropdown_parts .= ' and l.invoice_id is not NULL';
if ($report['invoice']=='2') $dropdown_parts .= ' and l.invoice_id is NULL';
+ if ($report['paid_status']=='1') $dropdown_parts .= ' and l.paid = 1';
+ if ($report['paid_status']=='2') $dropdown_parts .= ' and l.paid = 0';
// Prepare user list part.
$userlist = -1;
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;
}
if ($bean->getAttribute('project')) $dropdown_parts .= ' and ei.project_id = '.$bean->getAttribute('project');
if ($bean->getAttribute('invoice')=='1') $dropdown_parts .= ' and ei.invoice_id is not NULL';
if ($bean->getAttribute('invoice')=='2') $dropdown_parts .= ' and ei.invoice_id is NULL';
+ if ($bean->getAttribute('paid_status')=='1') $dropdown_parts .= ' and ei.paid = 1';
+ if ($bean->getAttribute('paid_status')=='2') $dropdown_parts .= ' and ei.paid = 0';
// Prepare user list part.
$userlist = -1;
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;
}
if ($report['project_id']) $dropdown_parts .= ' and ei.project_id = '.$report['project_id'];
if ($report['invoice']=='1') $dropdown_parts .= ' and ei.invoice_id is not NULL';
if ($report['invoice']=='2') $dropdown_parts .= ' and ei.invoice_id is NULL';
+ if ($report['paid_status']=='1') $dropdown_parts .= ' and ei.paid = 1';
+ if ($report['paid_status']=='2') $dropdown_parts .= ' and ei.paid = 0';
// Prepare user list part.
$userlist = -1;
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;
}
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');
array_push($fields, 'ei.name as note');
array_push($fields, 'ei.cost as cost');
array_push($fields, 'ei.cost as expense');
+ // Add paid status.
+ if ($user->canManageTeam() && $bean->getAttribute('chpaid'))
+ array_push($fields, 'ei.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');
return $report_items;
}
+ // putInSession stores tt_log and tt_expense_items ids from a report in user session
+ // as 2 comma-separated lists.
+ static function putInSession($report_items) {
+ unset($_SESSION['report_item_ids']);
+ unset($_SESSION['report_item_expense_ids']);
+
+ // Iterate through records and build 2 comma-separated lists.
+ foreach($report_items as $item) {
+ if ($item['type'] == 1)
+ $report_item_ids .= ','.$item['id'];
+ else if ($item['type'] == 2)
+ $report_item_expense_ids .= ','.$item['id'];
+ }
+ $report_item_ids = trim($report_item_ids, ',');
+ $report_item_expense_ids = trim($report_item_expense_ids, ',');
+
+ // The lists are reqdy. Put them in session.
+ if ($report_item_ids) $_SESSION['report_item_ids'] = $report_item_ids;
+ if ($report_item_expense_ids) $_SESSION['report_item_expense_ids'] = $report_item_expense_ids;
+ }
+
+ // getFromSession obtains tt_log and tt_expense_items ids stored in user session.
+ static function getFromSession() {
+ $items = array();
+ $report_item_ids = $_SESSION['report_item_ids'];
+ if ($report_item_ids)
+ $items['report_item_ids'] = explode(',', $report_item_ids);
+ $report_item_expense_ids = $_SESSION['report_item_expense_ids'];
+ if ($report_item_expense_ids)
+ $items['report_item_expense_ids'] = explode(',', $report_item_expense_ids);
+ return $items;
+ }
+
// getFavItems retrieves all items associated with a favorite report.
// It combines tt_log and tt_expense_items in one array for presentation in one table using mysql union all.
// Expense items use the "note" field for item name.
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;
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;
}
}
+ // The markPaid marks a set of records as either paid or unpaid.
+ static function markPaid($time_log_ids, $expense_item_ids, $paid = true)
+ {
+ $mdb2 = getConnection();
+ $paid_val = (int) $paid;
+ if ($time_log_ids) {
+ $sql = "update tt_log set paid = $paid_val where id in(".join(', ', $time_log_ids).")";
+ $affected = $mdb2->exec($sql);
+ if (is_a($affected, 'PEAR_Error')) die($affected->getMessage());
+ }
+ if ($expense_item_ids) {
+ $sql = "update tt_expense_items set paid = $paid_val where id in(".join(', ', $expense_item_ids).")";
+ $affected = $mdb2->exec($sql);
+ if (is_a($affected, 'PEAR_Error')) die($affected->getMessage());
+ }
+ }
+
// prepareReportBody - prepares an email body for report.
static function prepareReportBody($bean, $comment)
{
$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;';
$body .= '<td style="'.$tableHeader.'">'.$i18n->getKey('label.note').'</td>';
if ($bean->getAttribute('chcost'))
$body .= '<td style="'.$tableHeaderCentered.'" width="5%">'.$i18n->getKey('label.cost').'</td>';
+ if ($bean->getAttribute('chpaid'))
+ $body .= '<td style="'.$tableHeaderCentered.'" width="5%">'.$i18n->getKey('label.paid').'</td>';
if ($bean->getAttribute('chinvoice'))
$body .= '<td style="'.$tableHeader.'">'.$i18n->getKey('label.invoice').'</td>';
$body .= '</tr>';
$body .= ($user->canManageTeam() || $user->isClient()) ? $subtotals[$prev_grouped_by]['cost'] : $subtotals[$prev_grouped_by]['expenses'];
$body .= '</td>';
}
+ if ($bean->getAttribute('chpaid')) $body .= '<td></td>';
if ($bean->getAttribute('chinvoice')) $body .= '<td></td>';
$body .= '</tr>';
$body .= '<tr><td> </td></tr>';
$body .= '<td style="'.$cellLeftAligned.'">'.htmlspecialchars($record['note']).'</td>';
if ($bean->getAttribute('chcost'))
$body .= '<td style="'.$cellRightAligned.'">'.$record['cost'].'</td>';
+ if ($bean->getAttribute('chpaid')) {
+ $body .= '<td style="'.$cellRightAligned.'">';
+ $body .= $record['paid'] == 1 ? $i18n->getKey('label.yes') : $i18n->getKey('label.no');
+ $body .= '</td>';
+ }
if ($bean->getAttribute('chinvoice'))
$body .= '<td style="'.$cellRightAligned.'">'.htmlspecialchars($record['invoice']).'</td>';
$body .= '</tr>';
$body .= ($user->canManageTeam() || $user->isClient()) ? $subtotals[$cur_grouped_by]['cost'] : $subtotals[$cur_grouped_by]['expenses'];
$body .= '</td>';
}
+ if ($bean->getAttribute('chpaid')) $body .= '<td></td>';
if ($bean->getAttribute('chinvoice')) $body .= '<td></td>';
$body .= '</tr>';
}
$body .= ($user->canManageTeam() || $user->isClient()) ? $totals['cost'] : $totals['expenses'];
$body .= '</td>';
}
+ if ($bean->getAttribute('chpaid')) $body .= '<td></td>';
if ($bean->getAttribute('chinvoice')) $body .= '<td></td>';
$body .= '</tr>';
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 = (int) 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)
{
$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;';
$body .= '<td style="'.$tableHeader.'">'.$i18n->getKey('label.note').'</td>';
if ($report['show_cost'])
$body .= '<td style="'.$tableHeaderCentered.'" width="5%">'.$i18n->getKey('label.cost').'</td>';
+ if ($report['show_paid'])
+ $body .= '<td style="'.$tableHeaderCentered.'" width="5%">'.$i18n->getKey('label.paid').'</td>';
if ($report['show_invoice'])
$body .= '<td style="'.$tableHeader.'">'.$i18n->getKey('label.invoice').'</td>';
$body .= '</tr>';
$body .= ($user->canManageTeam() || $user->isClient()) ? $subtotals[$prev_grouped_by]['cost'] : $subtotals[$prev_grouped_by]['expenses'];
$body .= '</td>';
}
+ if ($report['show_paid']) $body .= '<td></td>';
if ($report['show_invoice']) $body .= '<td></td>';
$body .= '</tr>';
$body .= '<tr><td> </td></tr>';
$body .= '<td style="'.$cellLeftAligned.'">'.htmlspecialchars($record['note']).'</td>';
if ($report['show_cost'])
$body .= '<td style="'.$cellRightAligned.'">'.$record['cost'].'</td>';
+ if ($report['show_paid']) {
+ $body .= '<td style="'.$cellRightAligned.'">';
+ $body .= $record['paid'] == 1 ? $i18n->getKey('label.yes') : $i18n->getKey('label.no');
+ $body .= '</td>';
+ }
if ($report['show_invoice'])
$body .= '<td style="'.$cellRightAligned.'">'.htmlspecialchars($record['invoice']).'</td>';
$body .= '</tr>';
$body .= ($user->canManageTeam() || $user->isClient()) ? $subtotals[$cur_grouped_by]['cost'] : $subtotals[$cur_grouped_by]['expenses'];
$body .= '</td>';
}
+ if ($report['show_paid']) $body .= '<td></td>';
if ($report['show_invoice']) $body .= '<td></td>';
$body .= '</tr>';
}
$body .= ($user->canManageTeam() || $user->isClient()) ? $totals['cost'] : $totals['expenses'];
$body .= '</td>';
}
+ if ($report['show_paid']) $body .= '<td></td>';
if ($report['show_invoice']) $body .= '<td></td>';
$body .= '</tr>';
}
// 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;
$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;