405 lines
17 KiB
PHP
405 lines
17 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire;
|
|
|
|
use App\Models\CheckPointTime;
|
|
use App\Models\GuardPatrolEntry;
|
|
use Carbon\Carbon;
|
|
use Livewire\Component;
|
|
|
|
class GuardPatrolEntryDataTable extends Component
|
|
{
|
|
// public $plantId;
|
|
// 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 $seqNo;
|
|
public $isSequenced = true;
|
|
public $sequence1;
|
|
public $sequence2;
|
|
public $sequence3;
|
|
public $sequence4;
|
|
public $sequence5;
|
|
public $sequence6;
|
|
public $sequence7;
|
|
public $sequence8;
|
|
public $sequence9;
|
|
public $seqTime;
|
|
public $seqTime1;
|
|
public $seqTime2;
|
|
public $seqTime3;
|
|
public $seqTime4;
|
|
public $seqTime5;
|
|
public $seqTime6;
|
|
public $seqTime7;
|
|
public $seqTime8;
|
|
public $seqTime9;
|
|
public $startSeqCheckPoint1;
|
|
public $startSeqCheckPoint2;
|
|
public $startSeqCheckPoint3;
|
|
public $startSeqCheckPoint4;
|
|
public $startSeqCheckPoint5;
|
|
public $startSeqCheckPoint6;
|
|
public $startSeqCheckPoint7;
|
|
public $startSeqCheckPoint8;
|
|
public $startSeqCheckPoint9;
|
|
public $records = [];
|
|
|
|
protected $listeners = [
|
|
'loadGuardData' => 'loadGuardPatrolData',
|
|
];
|
|
|
|
public function loadGuardPatrolData($plantId, $date)
|
|
{
|
|
// $this->plantId = $plantId;
|
|
// $this->date = $date;
|
|
|
|
$this->records = [];
|
|
$this->newNameFound = true;
|
|
$this->guardName = null;
|
|
// $this->checkPointName = null;
|
|
$this->startTime = null;
|
|
$this->endTime = null;
|
|
$this->start = null;
|
|
$this->finish = null;
|
|
$this->begin = null;
|
|
$this->end = null;
|
|
$this->labTime = null;
|
|
$this->minDiff = 0;
|
|
$this->seqNo = 0;
|
|
$this->isSequenced = true;
|
|
$this->sequence1 = null;
|
|
$this->sequence2 = null;
|
|
$this->sequence3 = null;
|
|
$this->sequence4 = null;
|
|
$this->sequence5 = null;
|
|
$this->sequence6 = null;
|
|
$this->sequence7 = null;
|
|
$this->sequence8 = null;
|
|
$this->sequence9 = null;
|
|
$this->seqTime = null;
|
|
$this->seqTime1 = null;
|
|
$this->seqTime2 = null;
|
|
$this->seqTime3 = null;
|
|
$this->seqTime4 = null;
|
|
$this->seqTime5 = null;
|
|
$this->seqTime6 = null;
|
|
$this->seqTime7 = null;
|
|
$this->seqTime8 = null;
|
|
$this->seqTime9 = null;
|
|
|
|
if(!$plantId || !$date)
|
|
{
|
|
$this->records = [];
|
|
return;
|
|
}
|
|
|
|
$this->startSeqCheckPoint1 = CheckPointTime::with('checkPointNames1')->with('checkPointNames2')->where('sequence_number', 1)->where('plant_id', $plantId)->first();
|
|
$this->startSeqCheckPoint2 = CheckPointTime::with('checkPointNames1')->with('checkPointNames2')->where('sequence_number', 2)->where('plant_id', $plantId)->first();
|
|
$this->startSeqCheckPoint3 = CheckPointTime::with('checkPointNames1')->with('checkPointNames2')->where('sequence_number', 3)->where('plant_id', $plantId)->first();
|
|
$this->startSeqCheckPoint4 = CheckPointTime::with('checkPointNames1')->with('checkPointNames2')->where('sequence_number', 4)->where('plant_id', $plantId)->first();
|
|
$this->startSeqCheckPoint5 = CheckPointTime::with('checkPointNames1')->with('checkPointNames2')->where('sequence_number', 5)->where('plant_id', $plantId)->first();
|
|
$this->startSeqCheckPoint6 = CheckPointTime::with('checkPointNames1')->with('checkPointNames2')->where('sequence_number', 6)->where('plant_id', $plantId)->first();
|
|
$this->startSeqCheckPoint7 = CheckPointTime::with('checkPointNames1')->with('checkPointNames2')->where('sequence_number', 7)->where('plant_id', $plantId)->first();
|
|
$this->startSeqCheckPoint8 = CheckPointTime::with('checkPointNames1')->with('checkPointNames2')->where('sequence_number', 8)->where('plant_id', $plantId)->first();
|
|
$this->startSeqCheckPoint9 = CheckPointTime::with('checkPointNames1')->with('checkPointNames2')->where('sequence_number', 9)->where('plant_id', $plantId)->first();
|
|
|
|
$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 $record) {
|
|
$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)
|
|
{
|
|
$this->records[] = [
|
|
'guard_name' => $this->guardName,
|
|
// 'check_point_name' => $record->checkPointNames ? $record->checkPointNames->name : "",
|
|
'start_time' => $this->startTime,
|
|
'end_time' => $this->endTime,
|
|
'lap_time' => $this->labTime,
|
|
'Sequence_1' => $this->sequence1,
|
|
'Sequence_2' => $this->sequence2,
|
|
'Sequence_3' => $this->sequence3,
|
|
'Sequence_4' => $this->sequence4,
|
|
'Sequence_5' => $this->sequence5,
|
|
'Sequence_6' => $this->sequence6,
|
|
'Sequence_7' => $this->sequence7,
|
|
'Sequence_8' => $this->sequence8,
|
|
'Sequence_9' => $this->sequence9,
|
|
'Sequence_Time_1' => $this->seqTime1,
|
|
'Sequence_Time_2' => $this->seqTime2,
|
|
'Sequence_Time_3' => $this->seqTime3,
|
|
'Sequence_Time_4' => $this->seqTime4,
|
|
'Sequence_Time_5' => $this->seqTime5,
|
|
'Sequence_Time_6' => $this->seqTime6,
|
|
'Sequence_Time_7' => $this->seqTime7,
|
|
'Sequence_Time_8' => $this->seqTime8,
|
|
'Sequence_Time_9' => $this->seqTime9
|
|
//'created_at' => $record->created_at,
|
|
];
|
|
}
|
|
|
|
$this->seqTime1 = null;
|
|
$this->seqTime2 = null;
|
|
$this->seqTime3 = null;
|
|
$this->seqTime4 = null;
|
|
$this->seqTime5 = null;
|
|
$this->seqTime6 = null;
|
|
$this->seqTime7 = null;
|
|
$this->seqTime8 = null;
|
|
$this->seqTime9 = null;
|
|
|
|
$this->guardName = $guardName;
|
|
$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->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->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"
|
|
$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->begin = Carbon::parse($record->patrol_time);
|
|
// $this->seqNo = 0;
|
|
}
|
|
|
|
$this->seqNo++;
|
|
|
|
if ($this->seqNo == 1) {
|
|
if ($checkPointName == $this->startSeqCheckPoint1->checkPointNames1->name) {//"STP BACKSIDE"
|
|
$this->isSequenced = true;
|
|
$this->sequence1 = "X";
|
|
$this->sequence2 = "X";
|
|
$this->sequence3 = "X";
|
|
$this->sequence4 = "X";
|
|
$this->sequence5 = "X";
|
|
$this->sequence6 = "X";
|
|
$this->sequence7 = "X";
|
|
$this->sequence8 = "X";
|
|
$this->sequence9 = "X";
|
|
}
|
|
else {
|
|
$this->isSequenced = false;
|
|
$this->sequence1 = "X";
|
|
$this->sequence2 = "X";
|
|
$this->sequence3 = "X";
|
|
$this->sequence4 = "X";
|
|
$this->sequence5 = "X";
|
|
$this->sequence6 = "X";
|
|
$this->sequence7 = "X";
|
|
$this->sequence8 = "X";
|
|
$this->sequence9 = "X";
|
|
}
|
|
}
|
|
else if ($this->seqNo == 2) {
|
|
$this->seqTime1 = $this->seqTime;
|
|
if ($checkPointName == $this->startSeqCheckPoint2->checkPointNames1->name) {//"CANTEEN"
|
|
if ($this->isSequenced) {
|
|
$this->sequence1 = $this->minDiff;
|
|
$this->sequence2 = "X";
|
|
$this->sequence3 = "X";
|
|
$this->sequence4 = "X";
|
|
$this->sequence5 = "X";
|
|
$this->sequence6 = "X";
|
|
$this->sequence7 = "X";
|
|
$this->sequence8 = "X";
|
|
$this->sequence9 = "X";
|
|
}
|
|
}
|
|
else {
|
|
$this->isSequenced = false;
|
|
$this->sequence1 = "X";
|
|
$this->sequence2 = "X";
|
|
$this->sequence3 = "X";
|
|
$this->sequence4 = "X";
|
|
$this->sequence5 = "X";
|
|
$this->sequence6 = "X";
|
|
$this->sequence7 = "X";
|
|
$this->sequence8 = "X";
|
|
$this->sequence9 = "X";
|
|
}
|
|
}
|
|
else if ($this->seqNo == 3) {
|
|
$this->seqTime2 = $this->seqTime;
|
|
if ($checkPointName == $this->startSeqCheckPoint3->checkPointNames1->name) {//"D BLOCK BACK GATE"
|
|
if ($this->isSequenced) {
|
|
$this->sequence2 = $this->minDiff;
|
|
$this->sequence3 = "X";
|
|
$this->sequence4 = "X";
|
|
$this->sequence5 = "X";
|
|
$this->sequence6 = "X";
|
|
$this->sequence7 = "X";
|
|
$this->sequence8 = "X";
|
|
$this->sequence9 = "X";
|
|
}
|
|
}
|
|
else {
|
|
$this->isSequenced = false;
|
|
$this->sequence2 = "X";
|
|
$this->sequence3 = "X";
|
|
$this->sequence4 = "X";
|
|
$this->sequence5 = "X";
|
|
$this->sequence6 = "X";
|
|
$this->sequence7 = "X";
|
|
$this->sequence8 = "X";
|
|
$this->sequence9 = "X";
|
|
}
|
|
}
|
|
else if ($this->seqNo == 4) {
|
|
$this->seqTime3 = $this->seqTime;
|
|
if ($checkPointName == $this->startSeqCheckPoint4->checkPointNames1->name) {//"C BLOCK PACKING END"
|
|
if ($this->isSequenced) {
|
|
$this->sequence3 = $this->minDiff;
|
|
$this->sequence4 = "X";
|
|
$this->sequence5 = "X";
|
|
$this->sequence6 = "X";
|
|
$this->sequence7 = "X";
|
|
$this->sequence8 = "X";
|
|
$this->sequence9 = "X";
|
|
}
|
|
}
|
|
else {
|
|
$this->isSequenced = false;
|
|
$this->sequence3 = "X";
|
|
$this->sequence4 = "X";
|
|
$this->sequence5 = "X";
|
|
$this->sequence6 = "X";
|
|
$this->sequence7 = "X";
|
|
$this->sequence8 = "X";
|
|
$this->sequence9 = "X";
|
|
}
|
|
}
|
|
else if ($this->seqNo == 5) {
|
|
$this->seqTime4 = $this->seqTime;
|
|
if ($checkPointName == $this->startSeqCheckPoint5->checkPointNames1->name) {//"EXPORT WINDING FRONT"
|
|
if ($this->isSequenced) {
|
|
$this->sequence4 = $this->minDiff;
|
|
$this->sequence5 = "X";
|
|
$this->sequence6 = "X";
|
|
$this->sequence7 = "X";
|
|
$this->sequence8 = "X";
|
|
$this->sequence9 = "X";
|
|
}
|
|
}
|
|
else {
|
|
$this->isSequenced = false;
|
|
$this->sequence4 = "X";
|
|
$this->sequence5 = "X";
|
|
$this->sequence6 = "X";
|
|
$this->sequence7 = "X";
|
|
$this->sequence8 = "X";
|
|
$this->sequence9 = "X";
|
|
}
|
|
}
|
|
else if ($this->seqNo == 6) {
|
|
$this->seqTime5 = $this->seqTime;
|
|
if ($checkPointName == $this->startSeqCheckPoint6->checkPointNames1->name) {//"DOMESTIC WINDING FRONT"
|
|
if ($this->isSequenced) {
|
|
$this->sequence5 = $this->minDiff;
|
|
$this->sequence6 = "X";
|
|
$this->sequence7 = "X";
|
|
$this->sequence8 = "X";
|
|
$this->sequence9 = "X";
|
|
}
|
|
}
|
|
else {
|
|
$this->isSequenced = false;
|
|
$this->sequence5 = "X";
|
|
$this->sequence6 = "X";
|
|
$this->sequence7 = "X";
|
|
$this->sequence8 = "X";
|
|
$this->sequence9 = "X";
|
|
}
|
|
}
|
|
else if ($this->seqNo == 7) {
|
|
$this->seqTime6 = $this->seqTime;
|
|
if ($checkPointName == $this->startSeqCheckPoint7->checkPointNames1->name) {//"POWER HOUSE FRONT"
|
|
if ($this->isSequenced) {
|
|
$this->sequence6 = $this->minDiff;
|
|
$this->sequence7 = "X";
|
|
$this->sequence8 = "X";
|
|
$this->sequence9 = "X";
|
|
}
|
|
}
|
|
else {
|
|
$this->isSequenced = false;
|
|
$this->sequence6 = "X";
|
|
$this->sequence7 = "X";
|
|
$this->sequence8 = "X";
|
|
$this->sequence9 = "X";
|
|
}
|
|
}
|
|
else if ($this->seqNo == 8) {
|
|
$this->seqTime7 = $this->seqTime;
|
|
if ($checkPointName == $this->startSeqCheckPoint8->checkPointNames1->name) {//"B BLOCK BUFFING FRONT"
|
|
if ($this->isSequenced) {
|
|
$this->sequence7 = $this->minDiff;
|
|
$this->sequence8 = "X";
|
|
$this->sequence9 = "X";
|
|
}
|
|
}
|
|
else {
|
|
$this->isSequenced = false;
|
|
$this->sequence7 = "X";
|
|
$this->sequence8 = "X";
|
|
$this->sequence9 = "X";
|
|
}
|
|
}
|
|
else if ($this->seqNo == 9) {
|
|
$this->seqTime8 = $this->seqTime;
|
|
if ($checkPointName == $this->startSeqCheckPoint9->checkPointNames1->name) {//"D BLOCK DESPATCH FRONT"
|
|
if ($this->isSequenced) {
|
|
$this->sequence8 = $this->minDiff;
|
|
$this->sequence9 = "X";
|
|
}
|
|
}
|
|
else {
|
|
$this->isSequenced = false;
|
|
$this->sequence8 = "X";
|
|
$this->sequence9 = "X";
|
|
}
|
|
}
|
|
else if ($this->seqNo == 10) {
|
|
$this->seqTime9 = $this->seqTime;
|
|
if ($checkPointName == $this->startSeqCheckPoint9->checkPointNames2->name) {//"D 72 END"
|
|
if ($this->isSequenced) {
|
|
$this->sequence9 = $this->minDiff;
|
|
}
|
|
}
|
|
else {
|
|
$this->isSequenced = false;
|
|
$this->sequence9 = "X";
|
|
}
|
|
$this->newNameFound = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.guard-patrol-entry-data-table');
|
|
}
|
|
}
|