89 lines
2.9 KiB
PHP
Executable File
89 lines
2.9 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Livewire\Articulado;
|
|
|
|
use App\Models\ElementalTasks;
|
|
use App\Models\EquipmentWorkHistory;
|
|
use Livewire\Component;
|
|
|
|
use App\Models\OrderEquipmentTasks;
|
|
|
|
class AdditonalTask extends Component
|
|
{
|
|
public $equipment;
|
|
|
|
public $tasks = [];
|
|
|
|
public $elementalTasks = [];
|
|
public $furtherTaskRecords = [];
|
|
public $furtherTasks = [];
|
|
public $selectedFurtherTask = 'null';
|
|
public $furtherTaskDescription = '';
|
|
public $showAdditionalTask = false;
|
|
|
|
protected $listeners = ['furtherTaskSelected'];
|
|
|
|
|
|
public function mount($equipment)
|
|
{
|
|
// A variavel public recebe o valor de $equipment
|
|
$this->equipment = $equipment;
|
|
|
|
//recebe os dados de EquipmentWorkHistory
|
|
$receveEquipmentWorkHistory = EquipmentWorkHistory::where('equipment_id', $this->equipment->equipment_id)
|
|
->where('company_projects_id', $this->equipment->company_projects_id)
|
|
->first();
|
|
|
|
// A variavel de Array recebe os dados de OrderEquipmentTasks.
|
|
$this->tasks = OrderEquipmentTasks::where('equipmentWorkHistorys_id', $receveEquipmentWorkHistory->equipmentWorkHistorys_id)
|
|
->orderBy('execution_order', 'asc')
|
|
->get();
|
|
|
|
// Obtém os elemental_tasks_id de OrderEquipmentTasks que correspondem ao equipmentWorkHistorys_id
|
|
$elementalTaskIds = OrderEquipmentTasks::where('equipmentWorkHistorys_id', $receveEquipmentWorkHistory->equipmentWorkHistorys_id)
|
|
->pluck('elemental_tasks_id');
|
|
|
|
if ($receveEquipmentWorkHistory) {
|
|
|
|
// Agora, busca em ElementalTasks aqueles registros que correspondem aos IDs coletados
|
|
// e que também têm o company_projects_id desejado
|
|
$this->furtherTaskRecords = ElementalTasks::whereIn('elemental_tasks_id', $elementalTaskIds)
|
|
->where('company_projects_id', $this->equipment->company_projects_id)
|
|
->get();
|
|
} else {
|
|
$this->furtherTaskRecords = collect(); // Retorna uma coleção vazia se não encontrar nada
|
|
}
|
|
|
|
|
|
// Buscando furtherTasks que não estão presentes em $elementalTaskIds
|
|
$this->furtherTasks = ElementalTasks::where('company_projects_id', $this->equipment->company_projects_id)
|
|
->whereNotIn('elemental_tasks_id', $elementalTaskIds)
|
|
->get();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function updatedSelectedFurtherTask($value)
|
|
{
|
|
if ($value != 'null') {
|
|
$task = $this->furtherTasks->firstWhere('elemental_tasks_id', $value);
|
|
$this->furtherTaskDescription = $task ? $task->further_tasks_description : '';
|
|
} else {
|
|
$this->furtherTaskDescription = '';
|
|
}
|
|
}
|
|
|
|
|
|
public function toggle()
|
|
{
|
|
|
|
$this->showAdditionalTask = !$this->showAdditionalTask;
|
|
}
|
|
public function render()
|
|
{
|
|
return view('livewire.articulado.additonal-task');
|
|
}
|
|
}
|