diff --git a/app/Http/Controllers/CreateProjectController.php b/app/Http/Controllers/CreateProjectController.php
index ba476c60..b776311b 100755
--- a/app/Http/Controllers/CreateProjectController.php
+++ b/app/Http/Controllers/CreateProjectController.php
@@ -122,7 +122,7 @@ public function addFurtherTasks(Request $request)
$newOrderEquipmentTask->further_tasks_id = $request->selectedFurtherTaskExisting;
}
- $newOrderEquipmentTask->inspection = 'Nao';
+ $newOrderEquipmentTask->inspection = 2;
$newOrderEquipmentTask->save();
@@ -192,187 +192,78 @@ function () use ($writer) {
public function finishCreatingProject($numberProject)
{
+ // recebe atraves de sessao toda a vez quem entra no componente 'SelectElementalTasksInWonkstation' para selecionar as tarefas de cada Workstation
+ $receiveAllFurtherTasks = session('receiveAllFurtherTasks');
+ $receiveElementalTasks = session('receiveElementalTasks');
+
+ // Inicializar a matriz de IDs faltantes
+ $missingElementalTasks = [];
+ $missingFurtherTasksDetails = [];
+ $missingWorkstations = [];
+
+ // Recebe todos os dados dos postos de Trabalho
$receiveWorkstaions = ConstructionWorkstation::where('company_projects_id', $numberProject)->get();
+
+ foreach ($receiveWorkstaions as $workstation) {
+ // Verifica se o ID da workstation está presente na tabela WorkstationsAssociationTasks
+ $exists = WorkstationsAssociationTasks::where('id_workstations', $workstation->id_workstations)->exists();
+
+ // Se não existe na tabela, adiciona à lista das workstations onde nao tem tarefas atribuidas ainda.
+ if (!$exists) {
+ $missingWorkstations[$workstation->id_workstations] = [
+ 'name_workstations' => $workstation->name_workstations,
+ 'nomenclature_workstation' => $workstation->nomenclature_workstation
+ ];
+ }
+ }
+
// Extrai apena o id_workstations de cada um
$workstationIds = $receiveWorkstaions->pluck('id_workstations')->toArray();
- $workstationOccurrences = WorkstationsAssociationTasks::whereIn('id_workstations', $workstationIds)
- ->get()
- ->countBy('id_workstations')
- ->toArray();
-
- // Guarda as WorkStations que não tem nenhuma tarefa associada
- $missingWorkstations = array_filter($workstationIds, function ($workstationId) use ($workstationOccurrences) {
- return !isset($workstationOccurrences[$workstationId]) || $workstationOccurrences[$workstationId] == 0;
- });
-
- foreach ($missingWorkstations as $dataWs => $idWs) {
- $checkDataWsMissing = ConstructionWorkstation::where('id_workstations', $idWs)->get();
- $receiveDataWsMissing[$idWs] = $checkDataWsMissing;
- }
-
- // Recebe todos os equipamentos relacionados na Obra indicada
- $receiveEquipments = Equipment::where('company_projects_id', $numberProject)->get();
-
- // Recebe a quantidade de equipamentos de acordo com seu tipo de Equipamento
- $equipmentCounts = $receiveEquipments->countBy('equipment_type_id');
-
-
- // CV
- $countType1 = $equipmentCounts[1] ?? 0;
- // ISV
- $countType2 = $equipmentCounts[2] ?? 0;
- // PSV
- $countType3 = $equipmentCounts[3] ?? 0;
-
- $valuesTypeCV = [];
- $valuesTypeISV = [];
- $valuesTypePSV = [];
- $GeneralValues = [1, 2, 8, 14, 17];
-
- if ($countType1 > 0) {
- $valuesTypeCV = [18, 4, 6, 11, 19, 16];
- }
- if ($countType2 > 0) {
- $valuesTypeISV = [7, 12, 20, 15, 21];
- }
- if ($countType3 > 0) {
- $valuesTypePSV = [3, 9, 10, 13, 15];
- }
- $missingTasks = [];
-
- // Recebe cada id de workstations
- foreach ($workstationIds as $id) {
-
- // Verificar se há pelo menos uma entrada para cada valor em $GeneralValues
- foreach ($GeneralValues as $value) {
- $exists = WorkstationsAssociationTasks::where('id_workstations', $id)
- ->where('elemental_tasks_id', $value)
+ // Iterar sobre cada tarefa em $receiveElementalTasks
+ foreach ($receiveElementalTasks as $taskGroup) {
+ foreach ($taskGroup as $taskId => $taskDetails) {
+ // Verificar se a tarefa está associada a algum id_workstations
+ $exists = WorkstationsAssociationTasks::whereIn('id_workstations', $workstationIds)
+ ->where('elemental_tasks_id', $taskId)
->exists();
+ // Se não existe, adicionar à lista de tarefas faltantes
if (!$exists) {
- $missingTasks[$id][] = $value;
- }
- }
- // Verificar se há pelo menos uma entrada para cada valor em $valuesTypeCV
- if ($countType1 > 0) {
- foreach ($valuesTypeCV as $value) {
- $exists = WorkstationsAssociationTasks::where('id_workstations', $id)
- ->where('elemental_tasks_id', $value)
- ->exists();
-
- if (!$exists) {
- $missingTasks[$id][] = $value;
- }
- }
- }
-
- // Verificar se há pelo menos uma entrada para cada valor em $valuesTypeISV
- if ($countType2 > 0) {
- foreach ($valuesTypeISV as $value) {
- $exists = WorkstationsAssociationTasks::where('id_workstations', $id)
- ->where('elemental_tasks_id', $value)
- ->exists();
-
- if (!$exists) {
- $missingTasks[$id][] = $value;
- }
- }
- }
-
- // Verificar se há pelo menos uma entrada para cada valor em $valuesTypePSV
- if ($countType3 > 0) {
- foreach ($valuesTypePSV as $value) {
- $exists = WorkstationsAssociationTasks::where('id_workstations', $id)
- ->where('elemental_tasks_id', $value)
- ->exists();
-
- if (!$exists) {
- $missingTasks[$id][] = $value;
- }
+ $missingElementalTasks[$taskId] = $taskDetails;
}
}
}
- // Todas as tarefas que não estao em cada posto
- $allMissingTasks = [];
+ // Iterar sobre cada tarefa em $receiveAllFurtherTasks
+ foreach ($receiveAllFurtherTasks as $furtherTask) {
+ // Obter o ID da tarefa
+ $taskId = $furtherTask->further_tasks_id;
- // Aqui nós contamos quantas workstations existem
- $numberOfWorkstations = count($workstationIds);
+ // Verificar se a tarefa está associada a algum id_workstations
+ $exists = WorkstationsAssociationTasks::whereIn('id_workstations', $workstationIds)
+ ->where('further_tasks_id', $taskId)
+ ->exists();
- // Junta todas as tarefas ausentes em um único array
- foreach ($missingTasks as $tasks) {
- $allMissingTasks = array_merge($allMissingTasks, $tasks);
+ // Se não existe, adicionar à lista de tarefas faltantes
+ if (!$exists) {
+ $missingFurtherTasksDetails[$taskId] = [
+ 'name' => $furtherTask->further_tasks_name,
+ 'description' => $furtherTask->further_tasks_description
+ ];
+ }
}
- // Conta o número de ocorrências de cada tarefa no array
- $counts = array_count_values($allMissingTasks);
+ // A Partir daqui ja temos as 2 variaveis a receberem array com as tarefas que faltam ser associadas.
+ $allMissingTasks = [
+ 'elemental' => $missingElementalTasks,
+ 'further' => $missingFurtherTasksDetails,
+ 'workstation' => $missingWorkstations
+ ];
- // Mantém apenas as tarefas que aparecem no array o mesmo número de vezes que o número de workstations
- $allMissingTasks = array_filter($counts, function ($count) use ($numberOfWorkstations) {
- return $count === $numberOfWorkstations;
- });
- // Recebe as tarefas, não existentes em nenhum do postos
- $receveDataTasksMissing = [];
-
- foreach ($allMissingTasks as $IdElementalTask => $ElementalTask) {
- // dd($IdElementalTask);
- $checkDataTask = ElementalTasks::where('elemental_tasks_id', $IdElementalTask)->first();
-
- $receiveDataTasksMissing[$IdElementalTask] = $checkDataTask;
- }
-
- // // Se receber zero(0) quer dizer que todas as tarefas foram atribuidas pelo menos uma vez em cada posto de Trabalho.
- // if (sizeof($allMissingTasks) != 0) {
- // $missingTasksList = collect($receiveDataTasksMissing)
- // ->map(function ($task) {
- // return $task->elemental_tasks_code . ' => ' . $task->elemental_tasks_description;
- // })
- // ->implode('
');
-
- // return redirect()->back()->with('error', 'As seguintes tarefas não foram atribuídas a nenhum posto de trabalho:
' . $missingTasksList);
- // } elseif (sizeof($missingWorkstations) != 0) {
- // $receveMissingWorkstations = collect($receiveDataWsMissing)
- // ->map(function ($DataWorkstation) {
- // // Aqui iteramos sobre a Collection de ConstructionWorkstation
- // return $DataWorkstation->map(function ($constructionWorkstation) {
- // return $constructionWorkstation->name_workstations ;
- // });
- // })
- // ->flatten() // Achata a coleção multi-dimensional para um único nível
- // ->implode('
');
-
- // return redirect()->back()->with('error', 'O seguintes postos não tem nenhuma tarefa atribuida!!
' . $receveMissingWorkstations.);
-
- $errors = [];
-
- // Se receber zero(0) quer dizer que todas as tarefas foram atribuídas pelo menos uma vez em cada posto de Trabalho.
- if (sizeof($allMissingTasks) != 0) {
- $missingTasksList = collect($receiveDataTasksMissing)
- ->map(function ($task) {
- return $task->elemental_tasks_code . ' => ' . $task->elemental_tasks_description;
- })
- ->implode('
');
-
- $errors[] = 'As seguintes tarefas não foram atribuídas a nenhum posto de trabalho:
' . $missingTasksList;
- }
-
- if (sizeof($missingWorkstations) != 0) {
- $receveMissingWorkstations = collect($receiveDataWsMissing)
- ->map(function ($DataWorkstation) {
- // Aqui iteramos sobre a Collection de ConstructionWorkstation
- return $DataWorkstation->map(function ($constructionWorkstation) {
- return $constructionWorkstation->name_workstations;
- });
- })
- ->flatten() // Achata a coleção multi-dimensional para um único nível
- ->implode('
');
-
- $errors[] = 'O seguintes postos não tem nenhuma tarefa atribuida!!
' . $receveMissingWorkstations;
- } // Verificar se existem erros e retornar, se houver
- if (!empty($errors)) {
- return redirect()->back()->with('errors', $errors);
+ if (!empty($allMissingTasks)) {
+ return redirect()->back()->with('errors', $allMissingTasks);
} else {
$project = CompanyProject::find($numberProject);
$project->order_project = 2;
@@ -427,24 +318,6 @@ public function deleteWorkstation($name)
return back()->with('danger', 'Posto de Trabalho não encontrado!');
}
- public function AddNomenclatureWorkstation(Request $request)
- {
- foreach ($request->nameWorkstations as $key => $value) {
- // Procurar a Workstation pelo ID
- $workstation = ConstructionWorkstation::where('name_workstations', $key)
- ->first();
- if ($workstation) {
- // Atualizar o valor do campo nomenclature_workstation
- $workstation->nomenclature_workstation = $value;
- $workstation->save();
- }
- }
-
- // Redirecionar de volta com uma mensagem de sucesso
- return back()->with('success', 'Nome da estação de trabalho atualizado com sucesso!');
- }
-
-
public function removeProjectEquipment(Request $request)
{
@@ -936,7 +809,7 @@ public function createEquipmentManual(Request $request)
$JoinsEquipmentsWithTasks->execution_order = $execution_order++;
$JoinsEquipmentsWithTasks->elemental_tasks_id = $TasksAssociationAmbit->elemental_tasks_id;
$JoinsEquipmentsWithTasks->further_tasks_id = null;
- $JoinsEquipmentsWithTasks->inspection = 'Nao';
+ $JoinsEquipmentsWithTasks->inspection = 2;
$JoinsEquipmentsWithTasks->save();
}
@@ -1151,24 +1024,36 @@ public function workstationsAssociationTasks(Request $request)
$workStation->save();
}
- // então, iteramos sobre as três listas de tarefas e as associamos à estação de trabalho
- $taskTypes = ['generalTasks', 'PsvTasks', 'CvTasks', 'IsvTasks'];
+ // Atualizar a lista de tipos de tarefas para incluir os novos grupos
+ $taskTypes = ['generalTasks', '1', '2', '3', 'FurtherTasks'];
foreach ($taskTypes as $groupTasks) {
if (isset($request[$groupTasks])) { // Checar se esse grupo de tarefas existe no request
foreach ($request[$groupTasks] as $taskID => $check) {
- // Encontra a tarefa existente, se houver
- $taskAssociation = WorkstationsAssociationTasks::where('id_workstations', $workStation->id_workstations)
- ->where('elemental_tasks_id', $taskID)
- ->where('company_projects_id', $workStation->company_projects_id)
- ->first();
+ if ($groupTasks == 'FurtherTasks') {
+ // Encontra a tarefa existente, se houver, para FurtherTasks
+ $taskAssociation = WorkstationsAssociationTasks::where('id_workstations', $workStation->id_workstations)
+ ->where('further_tasks_id', $taskID)
+ ->where('company_projects_id', $workStation->company_projects_id)
+ ->first();
+ } else {
+ // Encontra a tarefa existente, se houver, para os outros grupos
+ $taskAssociation = WorkstationsAssociationTasks::where('id_workstations', $workStation->id_workstations)
+ ->where('elemental_tasks_id', $taskID)
+ ->where('company_projects_id', $workStation->company_projects_id)
+ ->first();
+ }
if ($check == 'on') {
if (!$taskAssociation) {
$taskAssociation = new WorkstationsAssociationTasks;
$taskAssociation->id_workstations = $workStation->id_workstations;
- $taskAssociation->elemental_tasks_id = $taskID; // Usando $taskID, que é a key
+ if ($groupTasks == 'FurtherTasks') {
+ $taskAssociation->further_tasks_id = $taskID; // Usando $taskID, que é a key
+ } else {
+ $taskAssociation->elemental_tasks_id = $taskID; // Usando $taskID, que é a key
+ }
$taskAssociation->company_projects_id = $workStation->company_projects_id;
}
$taskAssociation->save();
@@ -1179,6 +1064,7 @@ public function workstationsAssociationTasks(Request $request)
}
}
+
// Redirecionar de volta com uma mensagem de sucesso
return back()->with('success', 'Posto de trabalho : ' . $workStation->name_workstations . ' atualizado com sucesso!');
}
diff --git a/app/Livewire/Articulado/AdditonalTask.php b/app/Livewire/Articulado/AdditonalTask.php
index 9e9e1ea2..f902d5ac 100644
--- a/app/Livewire/Articulado/AdditonalTask.php
+++ b/app/Livewire/Articulado/AdditonalTask.php
@@ -17,7 +17,7 @@ class AdditonalTask extends Component
public $selectedFurtherTask = 'null';
public $showAdditionalTask = false;
-
+
public function mount($equipment)
{
$this->equipment = $equipment;
diff --git a/app/Livewire/Articulado/SelectElementalTasksInWonkstation.php b/app/Livewire/Articulado/SelectElementalTasksInWonkstation.php
new file mode 100644
index 00000000..fa884af0
--- /dev/null
+++ b/app/Livewire/Articulado/SelectElementalTasksInWonkstation.php
@@ -0,0 +1,113 @@
+workstation = $workstation;
+
+ $this->receiveAllEquipments = Equipment::where('company_projects_id', $this->workstation->company_projects_id)
+ ->join('equipment_association_ambits', 'equipments.equipment_id', '=', 'equipment_association_ambits.equipment_id')
+ ->select('equipments.equipment_id', 'equipments.equipment_type_id', 'equipment_association_ambits.ambits_id')
+ ->get()
+ ->toArray();
+
+ $this->receiveAllFurtherTasks = FurtherTasks::where('company_projects_id', $this->workstation->company_projects_id)
+ ->get();
+
+ // Inicializar a matriz
+ $this->receiveElementalTasks = [
+ 'geral' => [],
+ '1' => [],
+ '2' => [],
+ '3' => []
+ ];
+
+ // Coletar todos os elemental_tasks_id para cada equipment_type_id
+ foreach ($this->receiveAllEquipments as $equipment) {
+ $elementalTasksIds = TasksAssociationAmbits::where('ambits_equipment_id', $equipment['ambits_id'])
+ ->pluck('elemental_tasks_id')
+ ->toArray();
+
+ // Inicializar cada ID como uma chave com um array vazio como valor
+ foreach ($elementalTasksIds as $id) {
+ $this->receiveElementalTasks[$equipment['equipment_type_id']][$id] = [];
+ }
+ }
+
+ // Mover elemental_tasks_id que aparecem em mais de um equipment_type_id para 'geral'
+ foreach ($this->receiveElementalTasks as $key1 => $values1) {
+ foreach ($this->receiveElementalTasks as $key2 => $values2) {
+ if ($key1 !== $key2 && $key1 !== 'geral' && $key2 !== 'geral') {
+ $commonValues = array_intersect_key($values1, $values2);
+ if (!empty($commonValues)) {
+ foreach ($commonValues as $value => $emptyArray) {
+ $this->receiveElementalTasks['geral'][$value] = [];
+ unset($this->receiveElementalTasks[$key1][$value]);
+ unset($this->receiveElementalTasks[$key2][$value]);
+ }
+ }
+ }
+ }
+ }
+
+ // Iterar sobre $receiveElementalTasks
+ foreach ($this->receiveElementalTasks as $key => $ids) {
+ // Para cada ID em uma chave específica, buscar os detalhes na tabela ElementalTasks
+ $details = ElementalTasks::whereIn('elemental_tasks_id', array_keys($ids))
+ ->select(['elemental_tasks_id', 'elemental_tasks_code', 'elemental_tasks_description'])
+ ->get()
+ ->toArray();
+
+ // Atualizar o array $receiveElementalTasks com os detalhes
+ foreach ($details as $detail) {
+ $this->receiveElementalTasks[$key][$detail['elemental_tasks_id']] = [
+ 'code' => $detail['elemental_tasks_code'],
+ 'description' => $detail['elemental_tasks_description']
+ ];
+ }
+ }
+
+ // Armazenar os dados na sessão
+ session([
+ 'receiveAllFurtherTasks' => $this->receiveAllFurtherTasks,
+ 'receiveElementalTasks' => $this->receiveElementalTasks,
+ ]);
+ }
+
+ public function render()
+ {
+ return view('livewire.articulado.select-elemental-tasks-in-wonkstation');
+ }
+}
diff --git a/resources/views/email/pendingUsers.blade.php b/resources/views/email/pendingUsers.blade.php
index e0c7ce87..f2dfd92f 100755
--- a/resources/views/email/pendingUsers.blade.php
+++ b/resources/views/email/pendingUsers.blade.php
@@ -46,7 +46,7 @@
-
+ {{-- --}}
diff --git a/resources/views/livewire/articulado/select-elemental-tasks-in-wonkstation.blade.php b/resources/views/livewire/articulado/select-elemental-tasks-in-wonkstation.blade.php
new file mode 100644
index 00000000..6a47cebc
--- /dev/null
+++ b/resources/views/livewire/articulado/select-elemental-tasks-in-wonkstation.blade.php
@@ -0,0 +1,219 @@
+