1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-15 07:33:04 +01:00
invoiceninja/app/Jobs/Task/TaskAssigned.php

73 lines
2.5 KiB
PHP
Raw Normal View History

2024-06-19 05:57:50 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Jobs\Task;
use App\Models\Task;
use App\Libraries\MultiDB;
2024-07-10 12:51:36 +02:00
use App\Models\CompanyUser;
2024-06-19 05:57:50 +02:00
use App\Services\Email\Email;
use Illuminate\Bus\Queueable;
use App\Services\Email\EmailObject;
use Illuminate\Mail\Mailables\Address;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
2024-07-10 12:51:36 +02:00
use Illuminate\Contracts\Queue\ShouldQueue;
2024-06-19 05:57:50 +02:00
use Illuminate\Foundation\Bus\Dispatchable;
use App\Utils\Traits\Notifications\UserNotifies;
class TaskAssigned implements ShouldQueue
{
use Dispatchable;
use InteractsWithQueue;
use Queueable;
use SerializesModels;
use UserNotifies;
/**
* Create a new job instance.
*
*/
public function __construct(private Task $task, private string $db)
{
}
public function handle(): void
{
MultiDB::setDb($this->db);
$company_user = $this->task->assignedCompanyUser();
2024-07-10 12:51:36 +02:00
if(($company_user instanceof CompanyUser) && $this->findEntityAssignedNotification($company_user, 'task'))
2024-06-19 05:57:50 +02:00
{
$mo = new EmailObject();
$mo->subject = ctrans('texts.task_assigned_subject', ['task' => $this->task->number, 'date' => now()->setTimeZone($this->task->company->timezone()->name)->format($this->task->company->date_format()) ]);
$mo->body = ctrans('texts.task_assigned_body',['task' => $this->task->number, 'description' => $this->task->description ?? '', 'client' => $this->task->client ? $this->task->client->present()->name() : ' ']);
$mo->text_body = ctrans('texts.task_assigned_body',['task' => $this->task->number, 'description' => $this->task->description ?? '', 'client' => $this->task->client ? $this->task->client->present()->name() : ' ']);
$mo->company_key = $this->task->company->company_key;
$mo->html_template = 'email.template.generic';
$mo->to = [new Address($this->task->assigned_user->email, $this->task->assigned_user->present()->name())];
$mo->email_template_body = 'task_assigned_body';
$mo->email_template_subject = 'task_assigned_subject';
(new Email($mo, $this->task->company))->handle();
}
}
public function failed($exception = null)
{
}
}