invoiceninja/app/Ninja/Reports/TaskReport.php

52 lines
1.6 KiB
PHP
Raw Normal View History

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