From 1b60d2ee8ac51a364b8f90ef17241179d4ade8e1 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Mon, 1 Jan 2018 11:10:59 +0200 Subject: [PATCH] Merge tax report changes --- app/Ninja/Reports/TaskReport.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/app/Ninja/Reports/TaskReport.php b/app/Ninja/Reports/TaskReport.php index fbc52b0591de..b19e871c8639 100644 --- a/app/Ninja/Reports/TaskReport.php +++ b/app/Ninja/Reports/TaskReport.php @@ -13,24 +13,39 @@ class TaskReport extends AbstractReport 'project', 'description', 'duration', + 'amount', ]; public function run() { + $startDate = date_create($this->startDate); + $endDate = date_create($this->endDate); + $tasks = Task::scope() ->orderBy('created_at', 'desc') - ->with('client.contacts') + ->with('client.contacts', 'project', 'account') ->withArchived() - ->dateRange($this->startDate, $this->endDate); + ->dateRange($startDate, $endDate); foreach ($tasks->get() as $task) { + $amount = $task->getRate() * ($task->getDuration() / 60 / 60); + if ($task->client && $task->client->currency_id) { + $currencyId = $task->client->currency_id; + } else { + $currencyId = auth()->user()->account->getCurrencyId(); + } + $this->data[] = [ $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, $task->description, Utils::formatTime($task->getDuration()), + Utils::formatMoney($amount, $currencyId), ]; + + $this->addToTotals($currencyId, 'duration', $task->getDuration()); + $this->addToTotals($currencyId, 'amount', $amount); } } }