feat: Initialize core application structure including authentication, role-based dashboards, service task management, and integration workflows.
This commit is contained in:
76
app/Services/ServiceTaskManager.php
Normal file
76
app/Services/ServiceTaskManager.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\ServiceTask;
|
||||
use App\Models\TaskItem;
|
||||
use App\Enums\ServiceTaskStatus;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ServiceTaskManager
|
||||
{
|
||||
public function startTask(ServiceTask $task): void
|
||||
{
|
||||
$task->update([
|
||||
'status' => ServiceTaskStatus::InProgress,
|
||||
'started_at' => now(),
|
||||
]);
|
||||
|
||||
// Log activity
|
||||
}
|
||||
|
||||
public function completeTaskItem(TaskItem $item, array $data = []): void
|
||||
{
|
||||
$item->update([
|
||||
'is_completed' => true,
|
||||
'completed_at' => now(),
|
||||
'completed_by' => auth()->id(),
|
||||
'data' => $data,
|
||||
]);
|
||||
|
||||
$this->checkIfTaskCanBeValidated($item->serviceTask);
|
||||
}
|
||||
|
||||
protected function checkIfTaskCanBeValidated(ServiceTask $task): void
|
||||
{
|
||||
$allMandatoryCompleted = $task->taskItems()
|
||||
->where('is_mandatory', true)
|
||||
->where('is_completed', false)
|
||||
->count() === 0;
|
||||
|
||||
if ($allMandatoryCompleted && $task->status !== ServiceTaskStatus::WaitingValidation && $task->status !== ServiceTaskStatus::Completed) {
|
||||
$task->update(['status' => ServiceTaskStatus::WaitingValidation]);
|
||||
|
||||
// Notify service manager
|
||||
$users = \App\Models\User::role($task->service->name)->get();
|
||||
\Illuminate\Support\Facades\Notification::send($users, new \App\Notifications\ServiceTaskReadyForValidationNotification($task));
|
||||
}
|
||||
}
|
||||
|
||||
public function validateTask(ServiceTask $task): void
|
||||
{
|
||||
$task->update([
|
||||
'status' => ServiceTaskStatus::Completed,
|
||||
'completed_at' => now(),
|
||||
'validated_by' => auth()->id(),
|
||||
]);
|
||||
|
||||
// Notify RH that a service has completed their task
|
||||
$rhUsers = \App\Models\User::role('RH')->get();
|
||||
\Illuminate\Support\Facades\Notification::send($rhUsers, new \App\Notifications\ServiceTaskValidatedNotification($task));
|
||||
|
||||
// Trigger check on the parent integration request
|
||||
app(IntegrationService::class)->checkCompletion($task->integrationRequest);
|
||||
}
|
||||
|
||||
public function rejectTask(ServiceTask $task, string $reason): void
|
||||
{
|
||||
$task->update([
|
||||
'status' => ServiceTaskStatus::Rejected,
|
||||
]);
|
||||
|
||||
// Notify service users
|
||||
$users = \App\Models\User::role($task->service->name)->get();
|
||||
\Illuminate\Support\Facades\Notification::send($users, new \App\Notifications\ServiceTaskRejectedNotification($task, $reason));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user