From e7479d6a4156fa5762b3e231ee750b0a90d52d3d Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 2 Sep 2024 10:35:20 +1000 Subject: [PATCH] Updates for template service properties --- app/Filters/InvoiceFilters.php | 52 --------------------- app/Filters/QueryFilters.php | 57 +++++++++++++++++++++++ app/Models/Project.php | 6 +++ app/Services/Template/TemplateService.php | 2 + app/Utils/HtmlEngine.php | 6 +++ 5 files changed, 71 insertions(+), 52 deletions(-) diff --git a/app/Filters/InvoiceFilters.php b/app/Filters/InvoiceFilters.php index e31cfd0dec..9f3a935146 100644 --- a/app/Filters/InvoiceFilters.php +++ b/app/Filters/InvoiceFilters.php @@ -266,58 +266,6 @@ class InvoiceFilters extends QueryFilters return $this->builder->where('due_date', '>=', $date); } - /** - * Filter by date range - * - * @param string $date_range - * @return Builder - */ - public function date_range(string $date_range = ''): Builder - { - $parts = explode(",", $date_range); - - if (count($parts) != 2) { - return $this->builder; - } - - try { - - $start_date = Carbon::parse($parts[0]); - $end_date = Carbon::parse($parts[1]); - - return $this->builder->whereBetween('date', [$start_date, $end_date]); - } catch(\Exception $e) { - return $this->builder; - } - - } - - /** - * Filter by due date range - * - * @param string $date_range - * @return Builder - */ - public function due_date_range(string $date_range = ''): Builder - { - $parts = explode(",", $date_range); - - if (count($parts) != 2) { - return $this->builder; - } - try { - - $start_date = Carbon::parse($parts[0]); - $end_date = Carbon::parse($parts[1]); - - return $this->builder->whereBetween('due_date', [$start_date, $end_date]); - } catch(\Exception $e) { - return $this->builder; - } - - } - - /** * Sorts the list based on $sort. * diff --git a/app/Filters/QueryFilters.php b/app/Filters/QueryFilters.php index 7f98a1d14e..c4ace3e0c6 100644 --- a/app/Filters/QueryFilters.php +++ b/app/Filters/QueryFilters.php @@ -331,4 +331,61 @@ abstract class QueryFilters ->orderByRaw("{$this->with_property} = ? DESC", [$value]) ->company(); } + + + /** + * Filter by date range + * + * @param string $date_range + * @return Builder + */ + public function date_range(string $date_range = ''): Builder + { + $parts = explode(",", $date_range); + + if (count($parts) != 2 || !in_array('date', \Illuminate\Support\Facades\Schema::getColumnListing($this->builder->getModel()->getTable()))) { + return $this->builder; + } + + try { + + $start_date = Carbon::parse($parts[0]); + $end_date = Carbon::parse($parts[1]); + + return $this->builder->whereBetween('date', [$start_date, $end_date]); + } catch(\Exception $e) { + return $this->builder; + } + + } + + /** + * Filter by due date range + * + * @param string $date_range + * @return Builder + */ + public function due_date_range(string $date_range = ''): Builder + { + + $parts = explode(",", $date_range); + + if (count($parts) != 2 || !in_array('due_date', \Illuminate\Support\Facades\Schema::getColumnListing($this->builder->getModel()->getTable()))) { + return $this->builder; + } + + try { + + $start_date = Carbon::parse($parts[0]); + $end_date = Carbon::parse($parts[1]); + + return $this->builder->whereBetween('due_date', [$start_date, $end_date]); + } catch(\Exception $e) { + return $this->builder; + } + + } + + + } diff --git a/app/Models/Project.php b/app/Models/Project.php index c786dcec08..32a5ffabd2 100644 --- a/app/Models/Project.php +++ b/app/Models/Project.php @@ -37,6 +37,7 @@ use Laracasts\Presenter\PresentableTrait; * @property-read Project|null $project * @property-read int|null $tasks_count * @property-read \App\Models\User $user + * @property-read \App\Models\User $assigned_user * @property-read \App\Models\Vendor|null $vendor * @method static \Illuminate\Database\Eloquent\Builder|BaseModel company() * @method static \Illuminate\Database\Eloquent\Builder|BaseModel exclude($columns) @@ -117,6 +118,11 @@ class Project extends BaseModel return $this->belongsTo(User::class)->withTrashed(); } + public function assigned_user(): \Illuminate\Database\Eloquent\Relations\BelongsTo + { + return $this->belongsTo(User::class, 'assigned_user_id', 'id')->withTrashed(); + } + public function tasks(): \Illuminate\Database\Eloquent\Relations\HasMany { return $this->hasMany(Task::class); diff --git a/app/Services/Template/TemplateService.php b/app/Services/Template/TemplateService.php index c4894b674d..4810c42dfa 100644 --- a/app/Services/Template/TemplateService.php +++ b/app/Services/Template/TemplateService.php @@ -949,6 +949,7 @@ class TemplateService 'custom_value4' => $task->custom_value4 ?: '', 'status' => $task->status ? $task->status->name : '', 'user' => $this->userInfo($task->user), + 'assigned_user' => $task->assigned_user ? $this->userInfo($task->assigned_user) : [], 'client' => $this->getClient($task), ]; @@ -1007,6 +1008,7 @@ class TemplateService 'tasks' => ($project->tasks && !$nested) ? $this->processTasks($project->tasks, true) : [], //@phpstan-ignore-line 'client' => $this->getClient($project), 'user' => $this->userInfo($project->user), + 'assigned_user' => $project->assigned_user ? $this->userInfo($project->assigned_user) : [], 'invoices' => $this->processInvoices($project->invoices) ]; diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index 53b0cc3495..b2cf9f9176 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -401,11 +401,17 @@ class HtmlEngine $data['$user.name'] = ['value' => $this->entity->user->present()->name(), 'label' => ctrans('texts.name')]; + $data['$user.signature'] = ['value' => $this->entity->user->signature ?? '', 'label' => ctrans('texts.signature')]; $data['$user.first_name'] = ['value' => $this->entity->user->first_name, 'label' => ctrans('texts.first_name')]; $data['$user.last_name'] = ['value' => $this->entity->user->last_name, 'label' => ctrans('texts.last_name')]; $data['$created_by_user'] = &$data['$user.name']; + $data['$assigned_to_user'] = ['value' => $this->entity->assigned_user ? $this->entity->assigned_user->present()->name() : '', 'label' => ctrans('texts.name')]; + $data['$assigned_user.signature'] = ['value' => $this->entity->assigned_user ? $this->entity->assigned_user->signature : '', 'label' => ctrans('texts.signature')]; + + $data['$assigned_user.first_name'] = ['value' => $this->entity->assigned_user ? $this->entity->assigned_user->first_name : '', 'label' => ctrans('texts.first_name')]; + $data['$assigned_user.last_name'] = ['value' => $this->entity->assigned_user ? $this->entity->assigned_user->last_name : '', 'label' => ctrans('texts.last_name')]; $data['$user_iban'] = ['value' => $this->helpers->formatCustomFieldValue($this->company->custom_fields, 'company1', $this->settings->custom_value1, $this->client) ?: ' ', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'company1')];