From 21795b683d0b0500f759bd8f162fda04c3f7b517 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 15 Jan 2017 22:11:04 +0200 Subject: [PATCH] Improve task descriptions when invoiced --- app/Http/Controllers/TaskController.php | 7 +++++-- app/Ninja/Presenters/TaskPresenter.php | 15 ++++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/TaskController.php b/app/Http/Controllers/TaskController.php index 9de256c989..452ce50eba 100644 --- a/app/Http/Controllers/TaskController.php +++ b/app/Http/Controllers/TaskController.php @@ -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') { diff --git a/app/Ninja/Presenters/TaskPresenter.php b/app/Ninja/Presenters/TaskPresenter.php index 7f985d3280..bec387f065 100644 --- a/app/Ninja/Presenters/TaskPresenter.php +++ b/app/Ninja/Presenters/TaskPresenter.php @@ -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); } - }