1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-09 20:52:56 +01:00

Improve task descriptions when invoiced

This commit is contained in:
Hillel Coren 2017-01-15 22:11:04 +02:00
parent 1337b8130a
commit 21795b683d
2 changed files with 17 additions and 5 deletions

View File

@ -253,10 +253,11 @@ class TaskController extends BaseController
Session::flash('message', trans('texts.stopped_task'));
return Redirect::to('tasks');
} else if ($action == 'invoice' || $action == 'add_to_invoice') {
$tasks = Task::scope($ids)->with('client')->get();
$tasks = Task::scope($ids)->with('client')->orderBy('project_id', 'id')->get();
$clientPublicId = false;
$data = [];
$lastProjectId = false;
foreach ($tasks as $task) {
if ($task->client) {
if (!$clientPublicId) {
@ -276,11 +277,13 @@ class TaskController extends BaseController
}
$account = Auth::user()->account;
$showProject = $lastProjectId != $task->project_id;
$data[] = [
'publicId' => $task->public_id,
'description' => $task->description . "\n\n" . $task->present()->times($account),
'description' => $task->present()->invoiceDescription($account, $showProject),
'duration' => $task->getHours(),
];
$lastProjectId = $task->project_id;
}
if ($action == 'invoice') {

View File

@ -35,8 +35,18 @@ class TaskPresenter extends EntityPresenter
* @param $account
* @return mixed
*/
public function times($account)
public function invoiceDescription($account, $showProject)
{
$str = '';
if ($showProject && $project = $this->project()) {
$str .= "##{$project}\n\n";
}
if ($description = trim($this->entity->description)) {
$str .= $description . "\n\n";
}
$parts = json_decode($this->entity->time_log) ?: [];
$times = [];
@ -54,7 +64,6 @@ class TaskPresenter extends EntityPresenter
$times[] = "### {$start} - {$end}";
}
return implode("\n", $times);
return $str . implode("\n", $times);
}
}