X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=WEB-INF%2Flib%2FttReportHelper.class.php;h=e58241e05e731358282939763356cf4d3ea317ca;hb=ae00c14ac2999773e17a761542932cb95420430a;hp=fe81a5758a7f963f245e4d6102687782bc69d1ab;hpb=5fd6816a0567b31414492712d5002d3ecc9f52a2;p=timetracker.git diff --git a/WEB-INF/lib/ttReportHelper.class.php b/WEB-INF/lib/ttReportHelper.class.php index fe81a575..e58241e0 100644 --- a/WEB-INF/lib/ttReportHelper.class.php +++ b/WEB-INF/lib/ttReportHelper.class.php @@ -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; @@ -96,6 +98,8 @@ class ttReportHelper { 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; @@ -143,6 +147,8 @@ class ttReportHelper { 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; @@ -182,6 +188,8 @@ class ttReportHelper { 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; @@ -346,6 +354,9 @@ class ttReportHelper { 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'); @@ -426,6 +437,39 @@ class ttReportHelper { 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. @@ -1046,6 +1090,23 @@ class ttReportHelper { } } + // 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) { @@ -1164,6 +1225,8 @@ class ttReportHelper { $body .= ''.$i18n->getKey('label.note').''; if ($bean->getAttribute('chcost')) $body .= ''.$i18n->getKey('label.cost').''; + if ($bean->getAttribute('chpaid')) + $body .= ''.$i18n->getKey('label.paid').''; if ($bean->getAttribute('chinvoice')) $body .= ''.$i18n->getKey('label.invoice').''; $body .= ''; @@ -1205,6 +1268,7 @@ class ttReportHelper { $body .= ($user->canManageTeam() || $user->isClient()) ? $subtotals[$prev_grouped_by]['cost'] : $subtotals[$prev_grouped_by]['expenses']; $body .= ''; } + if ($bean->getAttribute('chpaid')) $body .= ''; if ($bean->getAttribute('chinvoice')) $body .= ''; $body .= ''; $body .= ' '; @@ -1237,6 +1301,11 @@ class ttReportHelper { $body .= ''.htmlspecialchars($record['note']).''; if ($bean->getAttribute('chcost')) $body .= ''.$record['cost'].''; + if ($bean->getAttribute('chpaid')) { + $body .= ''; + $body .= $record['paid'] == 1 ? $i18n->getKey('label.yes') : $i18n->getKey('label.no'); + $body .= ''; + } if ($bean->getAttribute('chinvoice')) $body .= ''.htmlspecialchars($record['invoice']).''; $body .= ''; @@ -1266,6 +1335,7 @@ class ttReportHelper { $body .= ($user->canManageTeam() || $user->isClient()) ? $subtotals[$cur_grouped_by]['cost'] : $subtotals[$cur_grouped_by]['expenses']; $body .= ''; } + if ($bean->getAttribute('chpaid')) $body .= ''; if ($bean->getAttribute('chinvoice')) $body .= ''; $body .= ''; } @@ -1288,6 +1358,7 @@ class ttReportHelper { $body .= ($user->canManageTeam() || $user->isClient()) ? $totals['cost'] : $totals['expenses']; $body .= ''; } + if ($bean->getAttribute('chpaid')) $body .= ''; if ($bean->getAttribute('chinvoice')) $body .= ''; $body .= ''; @@ -1310,7 +1381,7 @@ class ttReportHelper { $items = ttReportHelper::getFavItems($report); $condition = str_replace('count', '', $condition); - $count_required = intval(trim(str_replace('>', '', $condition))); + $count_required = (int) trim(str_replace('>', '', $condition)); if (count($items) > $count_required) return true; // Condition ok. @@ -1436,6 +1507,8 @@ class ttReportHelper { $body .= ''.$i18n->getKey('label.note').''; if ($report['show_cost']) $body .= ''.$i18n->getKey('label.cost').''; + if ($report['show_paid']) + $body .= ''.$i18n->getKey('label.paid').''; if ($report['show_invoice']) $body .= ''.$i18n->getKey('label.invoice').''; $body .= ''; @@ -1477,6 +1550,7 @@ class ttReportHelper { $body .= ($user->canManageTeam() || $user->isClient()) ? $subtotals[$prev_grouped_by]['cost'] : $subtotals[$prev_grouped_by]['expenses']; $body .= ''; } + if ($report['show_paid']) $body .= ''; if ($report['show_invoice']) $body .= ''; $body .= ''; $body .= ' '; @@ -1509,6 +1583,11 @@ class ttReportHelper { $body .= ''.htmlspecialchars($record['note']).''; if ($report['show_cost']) $body .= ''.$record['cost'].''; + if ($report['show_paid']) { + $body .= ''; + $body .= $record['paid'] == 1 ? $i18n->getKey('label.yes') : $i18n->getKey('label.no'); + $body .= ''; + } if ($report['show_invoice']) $body .= ''.htmlspecialchars($record['invoice']).''; $body .= ''; @@ -1538,6 +1617,7 @@ class ttReportHelper { $body .= ($user->canManageTeam() || $user->isClient()) ? $subtotals[$cur_grouped_by]['cost'] : $subtotals[$cur_grouped_by]['expenses']; $body .= ''; } + if ($report['show_paid']) $body .= ''; if ($report['show_invoice']) $body .= ''; $body .= ''; } @@ -1560,6 +1640,7 @@ class ttReportHelper { $body .= ($user->canManageTeam() || $user->isClient()) ? $totals['cost'] : $totals['expenses']; $body .= ''; } + if ($report['show_paid']) $body .= ''; if ($report['show_invoice']) $body .= ''; $body .= '';