2017-01-22 11:09:29 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Ninja\Reports;
|
|
|
|
|
|
|
|
use App\Models\Task;
|
2017-01-30 20:40:43 +01:00
|
|
|
use Utils;
|
2017-01-22 11:09:29 +01:00
|
|
|
|
|
|
|
class TaskReport extends AbstractReport
|
|
|
|
{
|
2018-01-21 14:53:43 +01:00
|
|
|
public function getColumns()
|
|
|
|
{
|
|
|
|
return [
|
2018-01-23 19:32:11 +01:00
|
|
|
'client' => [],
|
|
|
|
'date' => [],
|
|
|
|
'project' => [],
|
|
|
|
'description' => [],
|
|
|
|
'duration' => [],
|
|
|
|
'amount' => [],
|
2018-01-26 13:11:23 +01:00
|
|
|
'user' => ['columnSelector-false'],
|
2018-01-21 14:53:43 +01:00
|
|
|
];
|
|
|
|
}
|
2017-01-22 11:09:29 +01:00
|
|
|
|
|
|
|
public function run()
|
|
|
|
{
|
2017-12-31 22:24:57 +01:00
|
|
|
$startDate = date_create($this->startDate);
|
|
|
|
$endDate = date_create($this->endDate);
|
|
|
|
|
2017-01-22 11:09:29 +01:00
|
|
|
$tasks = Task::scope()
|
2017-03-31 08:01:07 +02:00
|
|
|
->orderBy('created_at', 'desc')
|
2018-01-26 13:11:23 +01:00
|
|
|
->with('client.contacts', 'project', 'account', 'user')
|
2017-01-22 11:09:29 +01:00
|
|
|
->withArchived()
|
2017-12-31 22:24:57 +01:00
|
|
|
->dateRange($startDate, $endDate);
|
2017-01-22 11:09:29 +01:00
|
|
|
|
|
|
|
foreach ($tasks->get() as $task) {
|
2017-12-31 22:24:57 +01:00
|
|
|
$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();
|
|
|
|
}
|
|
|
|
|
2017-01-22 11:09:29 +01:00
|
|
|
$this->data[] = [
|
|
|
|
$task->client ? ($this->isExport ? $task->client->getDisplayName() : $task->client->present()->link) : trans('texts.unassigned'),
|
2017-08-27 22:18:10 +02:00
|
|
|
$this->isExport ? $task->getStartTime() : link_to($task->present()->url, $task->getStartTime()),
|
2017-01-22 11:09:29 +01:00
|
|
|
$task->present()->project,
|
2017-08-27 22:16:41 +02:00
|
|
|
$task->description,
|
2017-01-22 11:09:29 +01:00
|
|
|
Utils::formatTime($task->getDuration()),
|
2017-12-31 22:24:57 +01:00
|
|
|
Utils::formatMoney($amount, $currencyId),
|
2018-01-26 13:11:23 +01:00
|
|
|
$task->user->getDisplayName(),
|
2017-01-22 11:09:29 +01:00
|
|
|
];
|
2017-12-31 22:24:57 +01:00
|
|
|
|
|
|
|
$this->addToTotals($currencyId, 'duration', $task->getDuration());
|
|
|
|
$this->addToTotals($currencyId, 'amount', $amount);
|
2017-01-22 11:09:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|