164 lines
6.0 KiB
PHP
Executable File
164 lines
6.0 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Livewire\Execução;
|
|
|
|
use App\Models\EquipmentWorkHistory;
|
|
use Livewire\Component;
|
|
use Livewire\Exceptions\PublicPropertyNotFoundException;
|
|
use App\Models\Equipment;
|
|
use App\Models\GeneralAttributesEquipment;
|
|
use App\Models\OrderEquipmentTasks;
|
|
use App\Models\ControlEquipmentWorkstation;
|
|
|
|
use Spatie\LaravelIgnition\Recorders\DumpRecorder\Dump;
|
|
|
|
class EquipmentsDashboard extends Component
|
|
{
|
|
public $totalEquipmentsCount;
|
|
public $unstarted;
|
|
public $inProgress;
|
|
public $toApprove;
|
|
public $completed;
|
|
public $completed1;
|
|
public $totalEquivalentEquipment;
|
|
public $equivalentUnstarted;
|
|
public $equivalentInProgress;
|
|
public $equivalentCompleted;
|
|
|
|
public $datasProject;
|
|
public $lastUpdated;
|
|
|
|
|
|
public function mount($datasProject)
|
|
{
|
|
$this->datasProject = $datasProject;
|
|
|
|
$this->lastUpdated = now()->format('Y-m-d H:i');
|
|
|
|
// chama a funcao e envia a variavel datasProject recebido da view principal
|
|
$this->refreshDataEquipments($datasProject);
|
|
}
|
|
|
|
public function updateTimeGrafics()
|
|
{
|
|
// $this->lastUpdated = now()->toDateTimeString();
|
|
$this->lastUpdated = now()->format('Y-m-d H:i');
|
|
|
|
|
|
// Chame o método para atualizar os dados dos gráficos
|
|
$this->refreshDataEquipments($this->datasProject);
|
|
|
|
// Disparar um evento com os dados atualizados
|
|
$this->dispatch('refreshData', [
|
|
'totalEquipmentsCount' => $this->totalEquipmentsCount,
|
|
'unstarted' => $this->unstarted,
|
|
'inProgress' => $this->inProgress,
|
|
'toApprove' => $this->toApprove,
|
|
'completed' => $this->completed,
|
|
'totalEquivalentEquipment' => $this->totalEquivalentEquipment,
|
|
'equivalentUnstarted' => $this->equivalentUnstarted,
|
|
'equivalentInProgress' => $this->equivalentInProgress,
|
|
'equivalentCompleted' => $this->equivalentCompleted,
|
|
]);
|
|
}
|
|
|
|
// Por tipo de equipamento,
|
|
|
|
// Por Fabrica
|
|
|
|
//Porcentagem
|
|
public function showPercentageEquipments()
|
|
{
|
|
// Disparar um evento com os dados atualizados
|
|
$this->dispatch('refreshPercentageEquipments', [
|
|
'totalEquipmentsCount' => $this->totalEquipmentsCount,
|
|
'unstarted' => $this->unstarted,
|
|
'inProgress' => $this->inProgress,
|
|
'toApprove' => $this->toApprove,
|
|
'completed' => $this->completed,
|
|
'totalEquivalentEquipment' => $this->totalEquivalentEquipment,
|
|
'equivalentUnstarted' => $this->equivalentUnstarted,
|
|
'equivalentInProgress' => $this->equivalentInProgress,
|
|
'equivalentCompleted' => $this->equivalentCompleted,
|
|
]);
|
|
}
|
|
|
|
public function refreshDataEquipments($datasProject)
|
|
{
|
|
// Inicializa a zero o contador para toda a vez que atualizar.
|
|
$this->completed = 0;
|
|
$this->inProgress = 0;
|
|
$this->toApprove = 0;
|
|
$this->unstarted = 0;
|
|
$this->equivalentCompleted = 0;
|
|
$this->equivalentInProgress = 0;
|
|
$this->equivalentUnstarted = 0;
|
|
|
|
// Recebe o total de equipamentos da Obra.
|
|
$totalEquipments = EquipmentWorkHistory::where('company_projects_id', $datasProject->company_projects_id)->get();
|
|
|
|
// Busca o valor total de todos os equipamentos encontrados
|
|
$this->totalEquipmentsCount = $totalEquipments->count();
|
|
|
|
$equipmentCounts = [];
|
|
|
|
foreach ($totalEquipments as $equipment) {
|
|
// Conta quantas vezes o equipamento aparece em OrderEquipmentTasks
|
|
$tasksCount = OrderEquipmentTasks::where('equipmentWorkHistorys_id', $equipment->equipmentWorkHistorys_id)->count();
|
|
|
|
$equipmentCounts[$equipment->equipment_id] = $tasksCount;
|
|
|
|
// Verifica se o equipamento está concluído
|
|
if (
|
|
ControlEquipmentWorkstation::where('equipmentWorkHistorys_id', $equipment->equipmentWorkHistorys_id)
|
|
->whereNotNull('id_workstations')
|
|
->whereNotNull('entry_date')
|
|
->whereNotNull('departure_date')
|
|
->count() >= $tasksCount
|
|
&& EquipmentWorkHistory::where('equipmentWorkHistorys_id', $equipment->equipmentWorkHistorys_id)
|
|
->where('equipment_status_project', 2)
|
|
->exists()
|
|
) {
|
|
$this->completed++;
|
|
$this->equivalentCompleted += $equipmentCounts[$equipment->equipment_id];
|
|
}
|
|
// Verifica se o equipamento está para aprovar
|
|
elseif (
|
|
EquipmentWorkHistory::where('equipmentWorkHistorys_id', $equipment->equipmentWorkHistorys_id)
|
|
->where('equipment_status_project', 1)
|
|
->exists()
|
|
) {
|
|
$this->toApprove++;
|
|
}
|
|
// Verifica se o equipamento está em progresso
|
|
elseif (
|
|
ControlEquipmentWorkstation::where('equipmentWorkHistorys_id', $equipment->equipmentWorkHistorys_id)
|
|
->exists()
|
|
) {
|
|
$this->inProgress++;
|
|
$this->equivalentInProgress += $equipmentCounts[$equipment->equipment_id];
|
|
}
|
|
// Verifica se o equipamento está por iniciar
|
|
elseif (
|
|
EquipmentWorkHistory::where('equipmentWorkHistorys_id', $equipment->equipmentWorkHistorys_id)
|
|
->where('equipment_status_project', 0)
|
|
->exists()
|
|
&& !ControlEquipmentWorkstation::where('equipmentWorkHistorys_id', $equipment->equipmentWorkHistorys_id)
|
|
->exists()
|
|
) {
|
|
$this->unstarted++;
|
|
$this->equivalentUnstarted += $equipmentCounts[$equipment->equipment_id];
|
|
}
|
|
}
|
|
|
|
// Busca o valor total de todas as ocorrências criadas na variável equipmentCounts
|
|
$this->totalEquivalentEquipment = array_sum($equipmentCounts);
|
|
}
|
|
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.execução.equipments-dashboard');
|
|
}
|
|
}
|