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' => [],
|
2018-02-15 19:47:51 +01:00
|
|
|
'start_date' => [],
|
2018-01-23 19:32:11 +01:00
|
|
|
'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);
|
2018-02-28 15:57:10 +01:00
|
|
|
$subgroup = $this->options['subgroup'];
|
2017-12-31 22:24:57 +01:00
|
|
|
|
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) {
|
2018-02-15 19:47:51 +01:00
|
|
|
$duration = $task->getDuration($startDate->format('U'), $endDate->modify('+1 day')->format('U'));
|
|
|
|
$amount = $task->getRate() * ($duration / 60 / 60);
|
2017-12-31 22:24:57 +01:00
|
|
|
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,
|
2018-02-15 19:47:51 +01:00
|
|
|
Utils::formatTime($duration),
|
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
|
|
|
|
2018-02-15 19:47:51 +01:00
|
|
|
$this->addToTotals($currencyId, 'duration', $duration);
|
2017-12-31 22:24:57 +01:00
|
|
|
$this->addToTotals($currencyId, 'amount', $amount);
|
2018-02-28 15:57:10 +01:00
|
|
|
|
|
|
|
if ($subgroup == 'project') {
|
|
|
|
$dimension = $task->present()->project;
|
|
|
|
} else {
|
|
|
|
$dimension = $this->getDimension($task);
|
|
|
|
}
|
|
|
|
$this->addChartData($dimension, $task->created_at, round($duration / 60 / 60, 2));
|
2017-01-22 11:09:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|