From 9834adc0a51b490d47c467061cfe178ed45e1ac9 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Wed, 4 Apr 2018 22:21:15 +0300 Subject: [PATCH] Added more custom fields --- app/Ninja/Reports/ExpenseReport.php | 17 +++++++++++++++++ app/Ninja/Reports/TaskReport.php | 27 +++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/app/Ninja/Reports/ExpenseReport.php b/app/Ninja/Reports/ExpenseReport.php index b852dcc64f5f..a7ba91544a34 100644 --- a/app/Ninja/Reports/ExpenseReport.php +++ b/app/Ninja/Reports/ExpenseReport.php @@ -23,6 +23,16 @@ class ExpenseReport extends AbstractReport 'user' => ['columnSelector-false'], ]; + $user = auth()->user(); + $account = $user->account; + + if ($account->customLabel('expense1')) { + $columns[$account->present()->customLabel('expense1')] = ['columnSelector-false', 'custom']; + } + if ($account->customLabel('expense2')) { + $columns[$account->present()->customLabel('expense2')] = ['columnSelector-false', 'custom']; + } + if (TaxRate::scope()->count()) { $columns['tax'] = ['columnSelector-false']; } @@ -85,6 +95,13 @@ class ExpenseReport extends AbstractReport $expense->user->getDisplayName(), ]; + if ($account->customLabel('expense1')) { + $row[] = $expense->custom_value1; + } + if ($account->customLabel('expense2')) { + $row[] = $expense->custom_value2; + } + if ($hasTaxRates) { $row[] = $expense->present()->taxAmount; } diff --git a/app/Ninja/Reports/TaskReport.php b/app/Ninja/Reports/TaskReport.php index d6a2398a4760..f69c9f4b4299 100644 --- a/app/Ninja/Reports/TaskReport.php +++ b/app/Ninja/Reports/TaskReport.php @@ -4,12 +4,13 @@ namespace App\Ninja\Reports; use App\Models\Task; use Utils; +use Auth; class TaskReport extends AbstractReport { public function getColumns() { - return [ + $columns = [ 'client' => [], 'start_date' => [], 'project' => [], @@ -18,10 +19,23 @@ class TaskReport extends AbstractReport 'amount' => [], 'user' => ['columnSelector-false'], ]; + + $user = auth()->user(); + $account = $user->account; + + if ($account->customLabel('task1')) { + $columns[$account->present()->customLabel('task1')] = ['columnSelector-false', 'custom']; + } + if ($account->customLabel('task2')) { + $columns[$account->present()->customLabel('task2')] = ['columnSelector-false', 'custom']; + } + + return $columns; } public function run() { + $account = Auth::user()->account; $startDate = date_create($this->startDate); $endDate = date_create($this->endDate); $subgroup = $this->options['subgroup']; @@ -41,7 +55,7 @@ class TaskReport extends AbstractReport $currencyId = auth()->user()->account->getCurrencyId(); } - $this->data[] = [ + $row = [ $task->client ? ($this->isExport ? $task->client->getDisplayName() : $task->client->present()->link) : trans('texts.unassigned'), $this->isExport ? $task->getStartTime() : link_to($task->present()->url, $task->getStartTime()), $task->present()->project, @@ -51,6 +65,15 @@ class TaskReport extends AbstractReport $task->user->getDisplayName(), ]; + if ($account->customLabel('task1')) { + $row[] = $task->custom_value1; + } + if ($account->customLabel('task2')) { + $row[] = $task->custom_value2; + } + + $this->data[] = $row; + $this->addToTotals($currencyId, 'duration', $duration); $this->addToTotals($currencyId, 'amount', $amount);