diff --git a/app/Livewire/GuardPatrolEntryDataTable.php b/app/Livewire/GuardPatrolEntryDataTable.php index ed6f022..c766499 100644 --- a/app/Livewire/GuardPatrolEntryDataTable.php +++ b/app/Livewire/GuardPatrolEntryDataTable.php @@ -13,23 +13,41 @@ class GuardPatrolEntryDataTable extends Component // public $date; public $newNameFound; + public $guardName; + public $checkPointName; + public $startTime; + public $endTime; + public $start; + public $finish; + public $begin; + public $end; + public $labTime; + public $minDiff; + public $seqNoCnt = 0; + public $seqNo = 0; + public $isSequenced = true; + public $sequences = []; + public $seqTime; + public $seqTimes = []; + public $startSeqCheckPoints = []; + public $records = []; protected $listeners = [ @@ -61,9 +79,9 @@ class GuardPatrolEntryDataTable extends Component $this->seqTimes = []; $this->startSeqCheckPoints = []; - if (!$plantId || !$date) - { + if (! $plantId || ! $date) { $this->records = []; + return; } @@ -73,20 +91,19 @@ class GuardPatrolEntryDataTable extends Component $this->startSeqCheckPoints[$i] = CheckPointTime::with('checkPointNames1')->with('checkPointNames2')->where('sequence_number', $i)->where('plant_id', $plantId)->first(); } - $this->sequences = array_fill(1, $this->seqNoCnt, "X"); + $this->sequences = array_fill(1, $this->seqNoCnt, 'X'); $this->seqTimes = array_fill(1, $this->seqNoCnt, null); $hasSingleGuard = GuardPatrolEntry::whereDate('patrol_time', $date)->where('plant_id', $plantId)->orderBy('patrol_time', 'asc')->get(); $checking = 0; - $records = GuardPatrolEntry::with('guardNames')->with('checkPointNames')->whereDate('patrol_time', $date)->where('plant_id', $plantId)->orderBy('patrol_time', 'asc')->get(); //desc Carbon::parse($record->patrol_time)->toTimeString() - foreach ($records as $index => $record) { //foreach ($startSeqCheckPoints as $seq => $checkpoint) + $records = GuardPatrolEntry::with('guardNames')->with('checkPointNames')->whereDate('patrol_time', $date)->where('plant_id', $plantId)->orderBy('patrol_time', 'asc')->get(); // desc Carbon::parse($record->patrol_time)->toTimeString() + foreach ($records as $index => $record) { // foreach ($startSeqCheckPoints as $seq => $checkpoint) $checking++; $guardName = $record->guardNames ? $record->guardNames->name : null; $checkPointName = $record->checkPointNames ? $record->checkPointNames->name : null; - if ($this->guardName != $guardName || $this->newNameFound) {//if ($this->newNameFound) { - if ($this->guardName) - { + if ($this->guardName != $guardName || $this->newNameFound) {// if ($this->newNameFound) { + if ($this->guardName) { $recordData = [ 'guard_name' => $this->guardName, 'start_time' => $this->startTime, @@ -105,27 +122,25 @@ class GuardPatrolEntryDataTable extends Component $this->seqTimes = array_fill(1, $this->seqNoCnt, null); $this->guardName = $guardName; - $this->startTime = Carbon::parse($record->patrol_time)->toTimeString(); //"2025-06-01 00:07:12" + $this->startTime = Carbon::parse($record->patrol_time)->toTimeString(); // "2025-06-01 00:07:12" $this->start = Carbon::parse($record->patrol_time); - $this->endTime = Carbon::parse($record->patrol_time)->toTimeString(); //"2025-06-01 00:07:12" + $this->endTime = Carbon::parse($record->patrol_time)->toTimeString(); // "2025-06-01 00:07:12" $this->finish = Carbon::parse($record->patrol_time); $this->begin = Carbon::parse($record->patrol_time); $this->end = Carbon::parse($record->patrol_time); - $this->labTime = (int)$this->start->diffInMinutes($this->finish); - $this->minDiff = (int)$this->begin->diffInMinutes($this->end); - $this->seqTime = $this->begin->toTimeString(). " - " . $this->end->toTimeString(); + $this->labTime = (int) $this->start->diffInMinutes($this->finish); + $this->minDiff = (int) $this->begin->diffInMinutes($this->end); + $this->seqTime = $this->begin->toTimeString().' - '.$this->end->toTimeString(); $this->seqNo = 0; $this->newNameFound = false; $this->isSequenced = true; - } - else if ($this->guardName == $guardName && $this->start && $this->begin) - { - $this->endTime = Carbon::parse($record->patrol_time)->toTimeString(); //"2025-06-01 00:07:12" + } elseif ($this->guardName == $guardName && $this->start && $this->begin) { + $this->endTime = Carbon::parse($record->patrol_time)->toTimeString(); // "2025-06-01 00:07:12" $this->finish = Carbon::parse($record->patrol_time); $this->end = Carbon::parse($record->patrol_time); - $this->labTime = (int)$this->start->diffInMinutes($this->finish); - $this->minDiff = (int)$this->begin->diffInMinutes($this->end); - $this->seqTime = $this->begin->toTimeString(). " - " . $this->end->toTimeString(); + $this->labTime = (int) $this->start->diffInMinutes($this->finish); + $this->minDiff = (int) $this->begin->diffInMinutes($this->end); + $this->seqTime = $this->begin->toTimeString().' - '.$this->end->toTimeString(); $this->begin = Carbon::parse($record->patrol_time); // $this->seqNo = 0; } @@ -133,19 +148,16 @@ class GuardPatrolEntryDataTable extends Component $this->seqNo++; if ($this->seqNo == 1) { - if ($checkPointName == $this->startSeqCheckPoints[$this->seqNo]->checkPointNames1->name) {//"STP BACKSIDE" + if ($checkPointName == $this->startSeqCheckPoints[$this->seqNo]->checkPointNames1->name) {// "STP BACKSIDE" $this->isSequenced = true; - $this->sequences = array_fill(1, $this->seqNoCnt, "X"); - } - else { + $this->sequences = array_fill(1, $this->seqNoCnt, 'X'); + } else { $this->isSequenced = false; - $this->sequences = array_fill(1, $this->seqNoCnt, "X"); + $this->sequences = array_fill(1, $this->seqNoCnt, 'X'); } - if (($index+1) == count($hasSingleGuard)) - { - if ($this->guardName) - { + if (($index + 1) == count($hasSingleGuard)) { + if ($this->guardName) { $recordData = [ 'guard_name' => $this->guardName, 'start_time' => $this->startTime, @@ -161,26 +173,37 @@ class GuardPatrolEntryDataTable extends Component $this->records[] = $recordData; } } - } - else if ($this->seqNo >= ($this->seqNoCnt+1)) { - $this->seqTimes[$this->seqNo-1] = $this->seqTime; - if ($checkPointName == $this->startSeqCheckPoints[$this->seqNo-1]->checkPointNames2->name) {//"D 72 END" + } elseif ($this->seqNo >= ($this->seqNoCnt + 1)) { + $this->seqTimes[$this->seqNo - 1] = $this->seqTime; + if ($checkPointName == $this->startSeqCheckPoints[$this->seqNo - 1]->checkPointNames2->name) {// "D 72 END" if ($this->isSequenced) { - $this->sequences[$this->seqNo-1] = $this->minDiff; + $this->sequences[$this->seqNo - 1] = $this->minDiff; } - } - else { + } else { $this->isSequenced = false; } $this->newNameFound = true; - if ($hasSingleGuard->unique('guard_name_id')->count() == 1) - { - if (($this->seqNoCnt+1) == count($hasSingleGuard)) - { - //dd("Has 1 Guard and single patrol round (".($this->seqNoCnt+1).") is present"); - if ($this->guardName) - { + if ($hasSingleGuard->unique('guard_name_id')->count() == 1) { + if (($this->seqNoCnt + 1) == count($hasSingleGuard)) { + // dd("Has 1 Guard and single patrol round (".($this->seqNoCnt+1).") is present"); + if ($this->guardName) { + $recordData = [ + 'guard_name' => $this->guardName, + 'start_time' => $this->startTime, + 'end_time' => $this->endTime, + 'lap_time' => $this->labTime, + ]; + + for ($i = 1; $i <= $this->seqNoCnt; $i++) { + $recordData["Sequence_$i"] = $this->sequences[$i]; + $recordData["Sequence_Time_$i"] = $this->seqTimes[$i]; + } + + $this->records[] = $recordData; + } + } elseif (($index + 1) == count($hasSingleGuard)) { + if ($this->guardName) { $recordData = [ 'guard_name' => $this->guardName, 'start_time' => $this->startTime, @@ -196,30 +219,8 @@ class GuardPatrolEntryDataTable extends Component $this->records[] = $recordData; } } - else if (($index+1) == count($hasSingleGuard)) - { - if ($this->guardName) - { - $recordData = [ - 'guard_name' => $this->guardName, - 'start_time' => $this->startTime, - 'end_time' => $this->endTime, - 'lap_time' => $this->labTime, - ]; - - for ($i = 1; $i <= $this->seqNoCnt; $i++) { - $recordData["Sequence_$i"] = $this->sequences[$i]; - $recordData["Sequence_Time_$i"] = $this->seqTimes[$i]; - } - - $this->records[] = $recordData; - } - } - } - else if (($index+1) == count($hasSingleGuard)) - { - if ($this->guardName) - { + } elseif (($index + 1) == count($hasSingleGuard)) { + if ($this->guardName) { $recordData = [ 'guard_name' => $this->guardName, 'start_time' => $this->startTime, @@ -235,26 +236,36 @@ class GuardPatrolEntryDataTable extends Component $this->records[] = $recordData; } } - } - else // if ($this->seqNo >= 2) { - { - $this->seqTimes[$this->seqNo-1] = $this->seqTime; - if ($checkPointName == $this->startSeqCheckPoints[$this->seqNo]->checkPointNames1->name) {//"CANTEEN" + } else { // if ($this->seqNo >= 2) { + $this->seqTimes[$this->seqNo - 1] = $this->seqTime; + if ($checkPointName == $this->startSeqCheckPoints[$this->seqNo]->checkPointNames1->name) {// "CANTEEN" if ($this->isSequenced) { - $this->sequences[$this->seqNo-1] = $this->minDiff; + $this->sequences[$this->seqNo - 1] = $this->minDiff; } - } - else { + } else { $this->isSequenced = false; } - if ($hasSingleGuard->unique('guard_name_id')->count() == 1) - { - if ($this->seqNo == count($hasSingleGuard)) - { - //dd("Has 1 Guard and single patrol round (".($this->seqNoCnt+1).") is present"); - if ($this->guardName) - { + if ($hasSingleGuard->unique('guard_name_id')->count() == 1) { + if ($this->seqNo == count($hasSingleGuard)) { + // dd("Has 1 Guard and single patrol round (".($this->seqNoCnt+1).") is present"); + if ($this->guardName) { + $recordData = [ + 'guard_name' => $this->guardName, + 'start_time' => $this->startTime, + 'end_time' => $this->endTime, + 'lap_time' => $this->labTime, + ]; + + for ($i = 1; $i <= $this->seqNoCnt; $i++) { + $recordData["Sequence_$i"] = $this->sequences[$i]; + $recordData["Sequence_Time_$i"] = $this->seqTimes[$i]; + } + + $this->records[] = $recordData; + } + } elseif (($index + 1) == count($hasSingleGuard)) { + if ($this->guardName) { $recordData = [ 'guard_name' => $this->guardName, 'start_time' => $this->startTime, @@ -270,30 +281,8 @@ class GuardPatrolEntryDataTable extends Component $this->records[] = $recordData; } } - else if (($index+1) == count($hasSingleGuard)) - { - if ($this->guardName) - { - $recordData = [ - 'guard_name' => $this->guardName, - 'start_time' => $this->startTime, - 'end_time' => $this->endTime, - 'lap_time' => $this->labTime, - ]; - - for ($i = 1; $i <= $this->seqNoCnt; $i++) { - $recordData["Sequence_$i"] = $this->sequences[$i]; - $recordData["Sequence_Time_$i"] = $this->seqTimes[$i]; - } - - $this->records[] = $recordData; - } - } - } - else if (($index+1) == count($hasSingleGuard)) - { - if ($this->guardName) - { + } elseif (($index + 1) == count($hasSingleGuard)) { + if ($this->guardName) { $recordData = [ 'guard_name' => $this->guardName, 'start_time' => $this->startTime,