Added view rights against plant
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
This commit is contained in:
@@ -5,7 +5,6 @@ namespace App\Filament\Resources;
|
|||||||
use App\Filament\Exports\GuardPatrolEntryExporter;
|
use App\Filament\Exports\GuardPatrolEntryExporter;
|
||||||
use App\Filament\Imports\GuardPatrolEntryImporter;
|
use App\Filament\Imports\GuardPatrolEntryImporter;
|
||||||
use App\Filament\Resources\GuardPatrolEntryResource\Pages;
|
use App\Filament\Resources\GuardPatrolEntryResource\Pages;
|
||||||
use App\Filament\Resources\GuardPatrolEntryResource\RelationManagers;
|
|
||||||
use App\Models\CheckPointName;
|
use App\Models\CheckPointName;
|
||||||
use App\Models\Configuration;
|
use App\Models\Configuration;
|
||||||
use App\Models\GuardName;
|
use App\Models\GuardName;
|
||||||
@@ -17,7 +16,6 @@ use Filament\Forms;
|
|||||||
use Filament\Forms\Components\DateTimePicker;
|
use Filament\Forms\Components\DateTimePicker;
|
||||||
use Filament\Forms\Components\FileUpload;
|
use Filament\Forms\Components\FileUpload;
|
||||||
use Filament\Forms\Components\Select;
|
use Filament\Forms\Components\Select;
|
||||||
use Filament\Forms\Components\Tabs\Tab;
|
|
||||||
use Filament\Forms\Components\TextInput;
|
use Filament\Forms\Components\TextInput;
|
||||||
use Filament\Forms\Form;
|
use Filament\Forms\Form;
|
||||||
use Filament\Forms\Get;
|
use Filament\Forms\Get;
|
||||||
@@ -54,21 +52,21 @@ class GuardPatrolEntryResource extends Resource
|
|||||||
->reactive()
|
->reactive()
|
||||||
->options(function (callable $get) {
|
->options(function (callable $get) {
|
||||||
$userHas = Filament::auth()->user()->plant_id;
|
$userHas = Filament::auth()->user()->plant_id;
|
||||||
|
|
||||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||||
})
|
})
|
||||||
->default(function () {
|
->default(function () {
|
||||||
return optional(GuardPatrolEntry::where('created_by', Filament::auth()->user()?->name)->latest()->first())->plant_id;
|
return optional(GuardPatrolEntry::where('created_by', Filament::auth()->user()?->name)->latest()->first())->plant_id;
|
||||||
})
|
})
|
||||||
->disabled(fn (Get $get) => !empty($get('id')))
|
->disabled(fn (Get $get) => ! empty($get('id')))
|
||||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
$plantId = $get('plant_id');
|
$plantId = $get('plant_id');
|
||||||
if (!$plantId) {
|
if (! $plantId) {
|
||||||
// $set('gPePlantError', 'Please select a plant first.');
|
// $set('gPePlantError', 'Please select a plant first.');
|
||||||
$set('gPePlantError', 'Please select a plant first.');
|
$set('gPePlantError', 'Please select a plant first.');
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$set('patrol_time', now()->format('Y-m-d H:i:s'));
|
$set('patrol_time', now()->format('Y-m-d H:i:s'));
|
||||||
$set('updated_by', Filament::auth()->user()?->name);
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
$set('gPePlantError', null);
|
$set('gPePlantError', null);
|
||||||
@@ -84,7 +82,7 @@ class GuardPatrolEntryResource extends Resource
|
|||||||
// ->relationship('guardNames', 'name')
|
// ->relationship('guardNames', 'name')
|
||||||
->options(function (callable $get) {
|
->options(function (callable $get) {
|
||||||
$plantId = $get('plant_id');
|
$plantId = $get('plant_id');
|
||||||
if (!$plantId) {
|
if (! $plantId) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,15 +95,14 @@ class GuardPatrolEntryResource extends Resource
|
|||||||
->default(function () {
|
->default(function () {
|
||||||
return optional(GuardPatrolEntry::where('created_by', Filament::auth()->user()?->name)->latest()->first())->guard_name_id;
|
return optional(GuardPatrolEntry::where('created_by', Filament::auth()->user()?->name)->latest()->first())->guard_name_id;
|
||||||
})
|
})
|
||||||
->disabled(fn (Get $get) => !empty($get('id')))
|
->disabled(fn (Get $get) => ! empty($get('id')))
|
||||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
$guardName = $get('guard_name_id');
|
$guardName = $get('guard_name_id');
|
||||||
if (!$guardName) {
|
if (! $guardName) {
|
||||||
$set('gPeGuardNameError', 'Please select a guard name first.');
|
$set('gPeGuardNameError', 'Please select a guard name first.');
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$set('patrol_time', now()->format('Y-m-d H:i:s'));
|
$set('patrol_time', now()->format('Y-m-d H:i:s'));
|
||||||
$set('updated_by', Filament::auth()->user()?->name);
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
$set('gPeGuardNameError', null);
|
$set('gPeGuardNameError', null);
|
||||||
@@ -116,7 +113,7 @@ class GuardPatrolEntryResource extends Resource
|
|||||||
])
|
])
|
||||||
->hint(fn ($get) => $get('gPeGuardNameError') ? $get('gPeGuardNameError') : null)
|
->hint(fn ($get) => $get('gPeGuardNameError') ? $get('gPeGuardNameError') : null)
|
||||||
->hintColor('danger'),
|
->hintColor('danger'),
|
||||||
Forms\Components\Hidden::make('check_point_name')//TextInput
|
Forms\Components\Hidden::make('check_point_name')// TextInput
|
||||||
->label('Check Point Name')
|
->label('Check Point Name')
|
||||||
->reactive()
|
->reactive()
|
||||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
@@ -131,7 +128,7 @@ class GuardPatrolEntryResource extends Resource
|
|||||||
// ->relationship('checkPointNames', 'name')
|
// ->relationship('checkPointNames', 'name')
|
||||||
->options(function (callable $get) {
|
->options(function (callable $get) {
|
||||||
$plantId = $get('plant_id');
|
$plantId = $get('plant_id');
|
||||||
if (!$plantId) {
|
if (! $plantId) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,16 +141,15 @@ class GuardPatrolEntryResource extends Resource
|
|||||||
// ->default(function () {
|
// ->default(function () {
|
||||||
// return optional(GuardPatrolEntry::where('created_by', Filament::auth()->user()?->name)->latest()->first())->check_point_name_id;
|
// return optional(GuardPatrolEntry::where('created_by', Filament::auth()->user()?->name)->latest()->first())->check_point_name_id;
|
||||||
// })
|
// })
|
||||||
->disabled(fn (Get $get) => !empty($get('id')))
|
->disabled(fn (Get $get) => ! empty($get('id')))
|
||||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
$checkPointName = $get('check_point_name_id');
|
$checkPointName = $get('check_point_name_id');
|
||||||
if (!$checkPointName) {
|
if (! $checkPointName) {
|
||||||
$set('check_point_name_id', null);
|
$set('check_point_name_id', null);
|
||||||
$set('gPeCheckPointNameError', 'Please select a check point name first.');
|
$set('gPeCheckPointNameError', 'Please select a check point name first.');
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$set('patrol_time', now()->format('Y-m-d H:i:s'));
|
$set('patrol_time', now()->format('Y-m-d H:i:s'));
|
||||||
$set('updated_by', Filament::auth()->user()?->name);
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
$set('gPeCheckPointNameError', null);
|
$set('gPeCheckPointNameError', null);
|
||||||
@@ -173,11 +169,10 @@ class GuardPatrolEntryResource extends Resource
|
|||||||
}),
|
}),
|
||||||
Forms\Components\TextInput::make('reader_code')
|
Forms\Components\TextInput::make('reader_code')
|
||||||
->label('Reader Code')
|
->label('Reader Code')
|
||||||
->hidden(fn (Get $get) => !$get('id'))
|
->hidden(fn (Get $get) => ! $get('id'))
|
||||||
->reactive()
|
->reactive()
|
||||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
if(!$get('id'))
|
if (! $get('id')) {
|
||||||
{
|
|
||||||
$set('patrol_time', now()->format('Y-m-d H:i:s'));
|
$set('patrol_time', now()->format('Y-m-d H:i:s'));
|
||||||
}
|
}
|
||||||
$set('updated_by', Filament::auth()->user()?->name);
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
@@ -186,7 +181,7 @@ class GuardPatrolEntryResource extends Resource
|
|||||||
->label('Patrol Time')
|
->label('Patrol Time')
|
||||||
->reactive()
|
->reactive()
|
||||||
->default(fn () => now())
|
->default(fn () => now())
|
||||||
->readOnly(fn (Get $get) => !$get('id'))
|
->readOnly(fn (Get $get) => ! $get('id'))
|
||||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
$set('updated_by', Filament::auth()->user()?->name);
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
})
|
})
|
||||||
@@ -225,6 +220,7 @@ class GuardPatrolEntryResource extends Resource
|
|||||||
$paginator = $livewire->getTableRecords();
|
$paginator = $livewire->getTableRecords();
|
||||||
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
|
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
|
||||||
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
|
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
|
||||||
|
|
||||||
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
|
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
|
||||||
}),
|
}),
|
||||||
// Tables\Columns\TextColumn::make('id')
|
// Tables\Columns\TextColumn::make('id')
|
||||||
@@ -235,11 +231,11 @@ class GuardPatrolEntryResource extends Resource
|
|||||||
->label('Plant')
|
->label('Plant')
|
||||||
->alignCenter()
|
->alignCenter()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
Tables\Columns\TextColumn::make('guardNames.name') //guard_name_id
|
Tables\Columns\TextColumn::make('guardNames.name') // guard_name_id
|
||||||
->label('Guard Name')
|
->label('Guard Name')
|
||||||
->alignCenter()
|
->alignCenter()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
Tables\Columns\TextColumn::make('checkPointNames.name') //check_point_name_id
|
Tables\Columns\TextColumn::make('checkPointNames.name') // check_point_name_id
|
||||||
->label('Check Point Name')
|
->label('Check Point Name')
|
||||||
->alignCenter()
|
->alignCenter()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
@@ -288,18 +284,19 @@ class GuardPatrolEntryResource extends Resource
|
|||||||
// })
|
// })
|
||||||
->options(function (callable $get) {
|
->options(function (callable $get) {
|
||||||
$userHas = Filament::auth()->user()->plant_id;
|
$userHas = Filament::auth()->user()->plant_id;
|
||||||
|
|
||||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||||
})
|
})
|
||||||
->reactive(),
|
->reactive(),
|
||||||
// ->afterStateUpdated(function ($state, callable $set, callable $get) {
|
// ->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
// $set('sticker_master_id', null);
|
// $set('sticker_master_id', null);
|
||||||
// $set('sap_msg_status', null);
|
// $set('sap_msg_status', null);
|
||||||
// }),
|
// }),
|
||||||
Select::make('Guard Name')
|
Select::make('Guard Name')
|
||||||
->label('Select Guard Name')
|
->label('Select Guard Name')
|
||||||
->options(function (callable $get) {
|
->options(function (callable $get) {
|
||||||
$plantId = $get('Plant');
|
$plantId = $get('Plant');
|
||||||
if (!$plantId) {
|
if (! $plantId) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -310,7 +307,7 @@ class GuardPatrolEntryResource extends Resource
|
|||||||
->label('Select Check Point Name')
|
->label('Select Check Point Name')
|
||||||
->options(function (callable $get) {
|
->options(function (callable $get) {
|
||||||
$plantId = $get('Plant');
|
$plantId = $get('Plant');
|
||||||
if (!$plantId) {
|
if (! $plantId) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -322,11 +319,11 @@ class GuardPatrolEntryResource extends Resource
|
|||||||
->placeholder('Select Created By')
|
->placeholder('Select Created By')
|
||||||
->options(function (callable $get) {
|
->options(function (callable $get) {
|
||||||
$plantId = $get('Plant');
|
$plantId = $get('Plant');
|
||||||
if (!$plantId) {
|
if (! $plantId) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return GuardPatrolEntry::where('plant_id', $plantId)->orderBy('patrol_time', 'asc')->get()->unique('created_by')->pluck('created_by', 'created_by')->toArray();//, 'id'
|
return GuardPatrolEntry::where('plant_id', $plantId)->orderBy('patrol_time', 'asc')->get()->unique('created_by')->pluck('created_by', 'created_by')->toArray(); // , 'id'
|
||||||
})
|
})
|
||||||
->reactive(),
|
->reactive(),
|
||||||
DateTimePicker::make(name: 'From Patrol Time')
|
DateTimePicker::make(name: 'From Patrol Time')
|
||||||
@@ -341,66 +338,78 @@ class GuardPatrolEntryResource extends Resource
|
|||||||
->placeholder(placeholder: 'Select To Patrol Time')
|
->placeholder(placeholder: 'Select To Patrol Time')
|
||||||
->reactive()
|
->reactive()
|
||||||
->native(false),
|
->native(false),
|
||||||
])
|
])
|
||||||
->query(function ($query, array $data) {
|
->query(function ($query, array $data) {
|
||||||
//Hide all records initially if no filters are applied
|
// Hide all records initially if no filters are applied
|
||||||
if (empty($data['Plant']) && empty($data['Guard Name']) && empty($data['Check Point Name']) && empty($data['Created By']) && empty($data['From Patrol Time']) && empty($data['To Patrol Time'])) {
|
if (empty($data['Plant']) && empty($data['Guard Name']) && empty($data['Check Point Name']) && empty($data['Created By']) && empty($data['From Patrol Time']) && empty($data['To Patrol Time'])) {
|
||||||
return $query->whereRaw('1 = 0');
|
return $query->whereRaw('1 = 0');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($data['Plant'])) {
|
if (! empty($data['Plant'])) {
|
||||||
$query->where('plant_id', $data['Plant']);
|
$query->where('plant_id', $data['Plant']);
|
||||||
}
|
} else {
|
||||||
|
$userHas = Filament::auth()->user()->plant_id;
|
||||||
|
|
||||||
if (!empty($data['Guard Name'])) {
|
if ($userHas && strlen($userHas) > 0) {
|
||||||
$query->where('guard_name_id', $data['Guard Name']);
|
return $query->whereRaw('1 = 0');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty($data['Check Point Name'])) {
|
if (! empty($data['Guard Name'])) {
|
||||||
$query->where('check_point_name_id', $data['Check Point Name']);
|
$query->where('guard_name_id', $data['Guard Name']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($data['Created By'])) {
|
if (! empty($data['Check Point Name'])) {
|
||||||
$query->where('created_by', $data['Created By']);
|
$query->where('check_point_name_id', $data['Check Point Name']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($data['From Patrol Time'])) {
|
if (! empty($data['Created By'])) {
|
||||||
$query->where('patrol_time', '>=', $data['From Patrol Time']);
|
$query->where('created_by', $data['Created By']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($data['To Patrol Time'])) {
|
if (! empty($data['From Patrol Time'])) {
|
||||||
$query->where('patrol_time', '<=', $data['To Patrol Time']);
|
$query->where('patrol_time', '>=', $data['From Patrol Time']);
|
||||||
}
|
}
|
||||||
})
|
|
||||||
->indicateUsing(function (array $data) {
|
|
||||||
$indicators = [];
|
|
||||||
|
|
||||||
if (!empty($data['Plant'])) {
|
if (! empty($data['To Patrol Time'])) {
|
||||||
$indicators[] = 'Plant: ' . Plant::where('id', $data['Plant'])->value('name');
|
$query->where('patrol_time', '<=', $data['To Patrol Time']);
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
->indicateUsing(function (array $data) {
|
||||||
|
$indicators = [];
|
||||||
|
|
||||||
if (!empty($data['Guard Name'])) {
|
if (! empty($data['Plant'])) {
|
||||||
$indicators[] = 'Guard Name: ' . GuardName::where('plant_id', $data['Plant'])->where('id', $data['Guard Name'])->value('name');
|
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
|
||||||
}
|
} else {
|
||||||
|
$userHas = Filament::auth()->user()->plant_id;
|
||||||
|
|
||||||
if (!empty($data['Check Point Name'])) {
|
if ($userHas && strlen($userHas) > 0) {
|
||||||
$indicators[] = 'Check Point Name: ' . CheckPointName::where('plant_id', $data['Plant'])->where('id', $data['Check Point Name'])->value('name');
|
return 'Plant: Choose plant to filter records.';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty($data['Created By'])) {
|
if (! empty($data['Guard Name'])) {
|
||||||
$indicators[] = 'Created By: ' . $data['Created By'];
|
$indicators[] = 'Guard Name: '.GuardName::where('plant_id', $data['Plant'])->where('id', $data['Guard Name'])->value('name');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($data['From Patrol Time'])) {
|
if (! empty($data['Check Point Name'])) {
|
||||||
$indicators[] = 'From: ' . $data['From Patrol Time'];
|
$indicators[] = 'Check Point Name: '.CheckPointName::where('plant_id', $data['Plant'])->where('id', $data['Check Point Name'])->value('name');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($data['To Patrol Time'])) {
|
if (! empty($data['Created By'])) {
|
||||||
$indicators[] = 'To: ' . $data['To Patrol Time'];
|
$indicators[] = 'Created By: '.$data['Created By'];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $indicators;
|
if (! empty($data['From Patrol Time'])) {
|
||||||
})
|
$indicators[] = 'From: '.$data['From Patrol Time'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! empty($data['To Patrol Time'])) {
|
||||||
|
$indicators[] = 'To: '.$data['To Patrol Time'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $indicators;
|
||||||
|
}),
|
||||||
])
|
])
|
||||||
->filtersFormMaxHeight('280px')
|
->filtersFormMaxHeight('280px')
|
||||||
->actions([
|
->actions([
|
||||||
@@ -422,6 +431,7 @@ class GuardPatrolEntryResource extends Resource
|
|||||||
// ->options(Plant::pluck('name', 'id')->toArray())
|
// ->options(Plant::pluck('name', 'id')->toArray())
|
||||||
->options(function (callable $get) {
|
->options(function (callable $get) {
|
||||||
$userHas = Filament::auth()->user()->plant_id;
|
$userHas = Filament::auth()->user()->plant_id;
|
||||||
|
|
||||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||||
})
|
})
|
||||||
->label('Select Plant')
|
->label('Select Plant')
|
||||||
@@ -433,12 +443,11 @@ class GuardPatrolEntryResource extends Resource
|
|||||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
$plantId = $get('plant_id');
|
$plantId = $get('plant_id');
|
||||||
$set('guard_patrol_entry', null);
|
$set('guard_patrol_entry', null);
|
||||||
if (!$plantId) {
|
if (! $plantId) {
|
||||||
$set('gPeSelectPlantError', 'Please select a plant first.');
|
$set('gPeSelectPlantError', 'Please select a plant first.');
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$set('gPeSelectPlantError', null);
|
$set('gPeSelectPlantError', null);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -455,7 +464,7 @@ class GuardPatrolEntryResource extends Resource
|
|||||||
->reactive()
|
->reactive()
|
||||||
->required()
|
->required()
|
||||||
->disk('local')
|
->disk('local')
|
||||||
->visible(fn (Get $get) => !empty($get('plant_id')))
|
->visible(fn (Get $get) => ! empty($get('plant_id')))
|
||||||
->directory('uploads/temp')
|
->directory('uploads/temp')
|
||||||
// Allow only .xlsx and .xls
|
// Allow only .xlsx and .xls
|
||||||
->acceptedFileTypes(['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.ms-excel'])
|
->acceptedFileTypes(['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.ms-excel'])
|
||||||
@@ -465,7 +474,7 @@ class GuardPatrolEntryResource extends Resource
|
|||||||
])
|
])
|
||||||
// Server-side validation for extra safety
|
// Server-side validation for extra safety
|
||||||
->rules(['mimes:xlsx,xls']),
|
->rules(['mimes:xlsx,xls']),
|
||||||
])
|
])
|
||||||
->action(function (array $data) {
|
->action(function (array $data) {
|
||||||
$uploadedFile = $data['guard_patrol_entry'];
|
$uploadedFile = $data['guard_patrol_entry'];
|
||||||
|
|
||||||
@@ -482,21 +491,20 @@ class GuardPatrolEntryResource extends Resource
|
|||||||
|
|
||||||
$folderPath = Configuration::where('c_name', 'GUARD_PATROL_ENTRY_FOLDER_PATH')->where('plant_id', $plantId)->value('c_value');
|
$folderPath = Configuration::where('c_name', 'GUARD_PATROL_ENTRY_FOLDER_PATH')->where('plant_id', $plantId)->value('c_value');
|
||||||
|
|
||||||
if(!$folderPath)
|
if (! $folderPath) {
|
||||||
{
|
|
||||||
Notification::make()
|
Notification::make()
|
||||||
->title('Upload Folder Path Not Found!')
|
->title('Upload Folder Path Not Found!')
|
||||||
->body('Please set the folder path in configuration for Guard Patrol Entry.')
|
->body('Please set the folder path in configuration for Guard Patrol Entry.')
|
||||||
->danger()
|
->danger()
|
||||||
->send();
|
->send();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$fullFolderPath = "uploads/$folderPath";
|
$fullFolderPath = "uploads/$folderPath";
|
||||||
|
|
||||||
// Check if the folder exists, if not, create it
|
// Check if the folder exists, if not, create it
|
||||||
if (!Storage::disk('local')->exists($fullFolderPath))
|
if (! Storage::disk('local')->exists($fullFolderPath)) {
|
||||||
{
|
|
||||||
Storage::disk('local')->makeDirectory($fullFolderPath);
|
Storage::disk('local')->makeDirectory($fullFolderPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -504,12 +512,10 @@ class GuardPatrolEntryResource extends Resource
|
|||||||
|
|
||||||
$fullPath = Storage::disk('local')->path($path);
|
$fullPath = Storage::disk('local')->path($path);
|
||||||
|
|
||||||
if ($fullPath && file_exists($fullPath))
|
if ($fullPath && file_exists($fullPath)) {
|
||||||
{
|
|
||||||
$rows = Excel::toArray(null, $fullPath)[0];
|
$rows = Excel::toArray(null, $fullPath)[0];
|
||||||
|
|
||||||
if((count($rows) - 1) <= 0)
|
if ((count($rows) - 1) <= 0) {
|
||||||
{
|
|
||||||
Notification::make()
|
Notification::make()
|
||||||
->title('Invalid Guard Patrol Entry Found')
|
->title('Invalid Guard Patrol Entry Found')
|
||||||
->body('Uploaded excel sheet is empty or<br>contains no valid data.')
|
->body('Uploaded excel sheet is empty or<br>contains no valid data.')
|
||||||
@@ -519,19 +525,21 @@ class GuardPatrolEntryResource extends Resource
|
|||||||
if ($disk->exists($path)) {
|
if ($disk->exists($path)) {
|
||||||
$disk->delete($path);
|
$disk->delete($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$invalidRows=[];
|
$invalidRows = [];
|
||||||
$invalidGuardCheckPoints=[];
|
$invalidGuardCheckPoints = [];
|
||||||
$unknownGuards=[];
|
$unknownGuards = [];
|
||||||
$unknownCheckPoints=[];
|
$unknownCheckPoints = [];
|
||||||
$invalidPatrolTimes=[];
|
$invalidPatrolTimes = [];
|
||||||
$validRowsFound = false;
|
$validRowsFound = false;
|
||||||
|
|
||||||
foreach ($rows as $index => $row)
|
foreach ($rows as $index => $row) {
|
||||||
{
|
if ($index === 0) {
|
||||||
if ($index === 0) continue; // Skip header
|
continue;
|
||||||
|
} // Skip header
|
||||||
|
|
||||||
$rowNumber = trim($row[0]);
|
$rowNumber = trim($row[0]);
|
||||||
$guardName = trim($row[1]);
|
$guardName = trim($row[1]);
|
||||||
@@ -539,35 +547,34 @@ class GuardPatrolEntryResource extends Resource
|
|||||||
$readerCode = trim($row[3]);
|
$readerCode = trim($row[3]);
|
||||||
$patrolTime = trim($row[4]);
|
$patrolTime = trim($row[4]);
|
||||||
|
|
||||||
if (empty($rowNumber)) { continue; }
|
if (empty($rowNumber)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (empty($guardName) || empty($checkPointName) || empty($readerCode) || empty($patrolTime)) {
|
if (empty($guardName) || empty($checkPointName) || empty($readerCode) || empty($patrolTime)) {
|
||||||
$invalidRows[] = $rowNumber;
|
$invalidRows[] = $rowNumber;
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
} else {
|
||||||
else
|
if (Str::length($guardName) < 3 || Str::length($checkPointName) < 3 || Str::length($readerCode) < 3 || Str::length($patrolTime) < 3) {
|
||||||
{
|
|
||||||
if(Str::length($guardName) < 3 || Str::length($checkPointName) < 3 || Str::length($readerCode) < 3 || Str::length($patrolTime) < 3)
|
|
||||||
{
|
|
||||||
$invalidGuardCheckPoints[] = $rowNumber;
|
$invalidGuardCheckPoints[] = $rowNumber;
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$isValidRow = true;
|
$isValidRow = true;
|
||||||
$guardNames = GuardName::where('plant_id', $plantId)->where('name', $guardName)->first();
|
$guardNames = GuardName::where('plant_id', $plantId)->where('name', $guardName)->first();
|
||||||
if (!$guardNames) {
|
if (! $guardNames) {
|
||||||
$unknownGuards[] = $guardName;
|
$unknownGuards[] = $guardName;
|
||||||
$isValidRow = false;
|
$isValidRow = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$checkPointNames = CheckPointName::where('plant_id', $plantId)->where('name', $checkPointName)->first();
|
$checkPointNames = CheckPointName::where('plant_id', $plantId)->where('name', $checkPointName)->first();
|
||||||
if (!$checkPointNames) {
|
if (! $checkPointNames) {
|
||||||
$unknownCheckPoints[] = $checkPointName;
|
$unknownCheckPoints[] = $checkPointName;
|
||||||
$isValidRow = false;
|
$isValidRow = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$formats = ['d-m-Y H:i:s', 'd-m-Y H:i']; //'07-05-2025 08:00' or '07-05-2025 08:00:00'
|
$formats = ['d-m-Y H:i:s', 'd-m-Y H:i']; // '07-05-2025 08:00' or '07-05-2025 08:00:00'
|
||||||
$patrolDateTime = null;
|
$patrolDateTime = null;
|
||||||
foreach ($formats as $format) {
|
foreach ($formats as $format) {
|
||||||
try {
|
try {
|
||||||
@@ -579,13 +586,13 @@ class GuardPatrolEntryResource extends Resource
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($patrolDateTime)) {
|
if (! isset($patrolDateTime)) {
|
||||||
$invalidPatrolTimes[] = $rowNumber;
|
$invalidPatrolTimes[] = $rowNumber;
|
||||||
$isValidRow = false;
|
$isValidRow = false;
|
||||||
//$warnMsg[] = "Invalid 'Patrol DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
|
// $warnMsg[] = "Invalid 'Patrol DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($isValidRow && !$validRowsFound) {
|
if ($isValidRow && ! $validRowsFound) {
|
||||||
$validRowsFound = true;
|
$validRowsFound = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -593,38 +600,40 @@ class GuardPatrolEntryResource extends Resource
|
|||||||
}
|
}
|
||||||
|
|
||||||
$uniqueInvalidRows = array_unique($invalidRows);
|
$uniqueInvalidRows = array_unique($invalidRows);
|
||||||
if (!empty($uniqueInvalidRows)) {
|
if (! empty($uniqueInvalidRows)) {
|
||||||
Notification::make()
|
Notification::make()
|
||||||
->title('Invalid Guard Patrol Entry Found')
|
->title('Invalid Guard Patrol Entry Found')
|
||||||
->body('The following rows contain empty values (Guard name or Check point name or Reader code or Patrol time):<br>' . implode(', ', $uniqueInvalidRows))
|
->body('The following rows contain empty values (Guard name or Check point name or Reader code or Patrol time):<br>'.implode(', ', $uniqueInvalidRows))
|
||||||
->danger()
|
->danger()
|
||||||
->send();
|
->send();
|
||||||
if ($disk->exists($path)) {
|
if ($disk->exists($path)) {
|
||||||
$disk->delete($path);
|
$disk->delete($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//should contain minimum 13 digit alpha numeric values
|
// should contain minimum 13 digit alpha numeric values
|
||||||
$uniqueInvalidGuardCheckPoints = array_unique($invalidGuardCheckPoints);
|
$uniqueInvalidGuardCheckPoints = array_unique($invalidGuardCheckPoints);
|
||||||
if (!empty($uniqueInvalidGuardCheckPoints)) {
|
if (! empty($uniqueInvalidGuardCheckPoints)) {
|
||||||
Notification::make()
|
Notification::make()
|
||||||
->title('Invalid Guard Patrol Entry Found')
|
->title('Invalid Guard Patrol Entry Found')
|
||||||
->body('The following rows contain invalid values (Guard name or Check point name or Reader code or Patrol time):<br>' . implode(', ', $uniqueInvalidGuardCheckPoints))
|
->body('The following rows contain invalid values (Guard name or Check point name or Reader code or Patrol time):<br>'.implode(', ', $uniqueInvalidGuardCheckPoints))
|
||||||
->danger()
|
->danger()
|
||||||
->send();
|
->send();
|
||||||
if ($disk->exists($path)) {
|
if ($disk->exists($path)) {
|
||||||
$disk->delete($path);
|
$disk->delete($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$invalidDataFound = false;
|
$invalidDataFound = false;
|
||||||
$uniqueUnknownGuards = array_unique($unknownGuards);
|
$uniqueUnknownGuards = array_unique($unknownGuards);
|
||||||
if (!empty($uniqueUnknownGuards)) {
|
if (! empty($uniqueUnknownGuards)) {
|
||||||
Notification::make()
|
Notification::make()
|
||||||
->title('Unknown Guard Names Found')
|
->title('Unknown Guard Names Found')
|
||||||
->body("The following guard names aren't exist in master data:<br>" . implode(', ', $uniqueUnknownGuards))
|
->body("The following guard names aren't exist in master data:<br>".implode(', ', $uniqueUnknownGuards))
|
||||||
->danger()
|
->danger()
|
||||||
->send();
|
->send();
|
||||||
if ($disk->exists($path)) {
|
if ($disk->exists($path)) {
|
||||||
@@ -634,10 +643,10 @@ class GuardPatrolEntryResource extends Resource
|
|||||||
}
|
}
|
||||||
|
|
||||||
$uniqueUnknownCheckPoints = array_unique($unknownCheckPoints);
|
$uniqueUnknownCheckPoints = array_unique($unknownCheckPoints);
|
||||||
if (!empty($uniqueUnknownCheckPoints)) {
|
if (! empty($uniqueUnknownCheckPoints)) {
|
||||||
Notification::make()
|
Notification::make()
|
||||||
->title('Unknown Check Point Names Found')
|
->title('Unknown Check Point Names Found')
|
||||||
->body("The following check point names aren't exist in master data:<br>" . implode(', ', $uniqueUnknownCheckPoints))
|
->body("The following check point names aren't exist in master data:<br>".implode(', ', $uniqueUnknownCheckPoints))
|
||||||
->danger()
|
->danger()
|
||||||
->send();
|
->send();
|
||||||
if ($disk->exists($path)) {
|
if ($disk->exists($path)) {
|
||||||
@@ -647,10 +656,10 @@ class GuardPatrolEntryResource extends Resource
|
|||||||
}
|
}
|
||||||
|
|
||||||
$uniqueInvalidPatrolTimes = array_unique($invalidPatrolTimes);
|
$uniqueInvalidPatrolTimes = array_unique($invalidPatrolTimes);
|
||||||
if (!empty($uniqueInvalidPatrolTimes)) {
|
if (! empty($uniqueInvalidPatrolTimes)) {
|
||||||
Notification::make()
|
Notification::make()
|
||||||
->title('Invalid Patrol Time Format Found')
|
->title('Invalid Patrol Time Format Found')
|
||||||
->body("The following rows contains invalid patrol time format (Expected 'DD-MM-YYYY HH:MM:SS'):<br>" . implode(', ', $uniqueInvalidPatrolTimes))
|
->body("The following rows contains invalid patrol time format (Expected 'DD-MM-YYYY HH:MM:SS'):<br>".implode(', ', $uniqueInvalidPatrolTimes))
|
||||||
->danger()
|
->danger()
|
||||||
->send();
|
->send();
|
||||||
if ($disk->exists($path)) {
|
if ($disk->exists($path)) {
|
||||||
@@ -663,24 +672,26 @@ class GuardPatrolEntryResource extends Resource
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$validRowsFound) {
|
if (! $validRowsFound) {
|
||||||
Notification::make()
|
Notification::make()
|
||||||
->title('Invalid Guard Patrol Entry Found')
|
->title('Invalid Guard Patrol Entry Found')
|
||||||
->body('Uploaded excel sheet is empty or<br>contains no valid data.')
|
->body('Uploaded excel sheet is empty or<br>contains no valid data.')
|
||||||
->danger()
|
->danger()
|
||||||
->send();
|
->send();
|
||||||
if ($disk->exists($path)) {
|
if ($disk->exists($path)) {
|
||||||
$disk->delete($path);
|
$disk->delete($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$validCnt = 0;
|
$validCnt = 0;
|
||||||
$dupCnt = 0;
|
$dupCnt = 0;
|
||||||
$validRowsFound = false;
|
$validRowsFound = false;
|
||||||
foreach ($rows as $index => $row)
|
foreach ($rows as $index => $row) {
|
||||||
{
|
if ($index === 0) {
|
||||||
if ($index === 0) continue; // Skip header
|
continue;
|
||||||
|
} // Skip header
|
||||||
|
|
||||||
$rowNumber = trim($row[0]);
|
$rowNumber = trim($row[0]);
|
||||||
$guardName = trim($row[1]);
|
$guardName = trim($row[1]);
|
||||||
@@ -688,7 +699,9 @@ class GuardPatrolEntryResource extends Resource
|
|||||||
$readerCode = trim($row[3]);
|
$readerCode = trim($row[3]);
|
||||||
$patrolTime = trim($row[4]);
|
$patrolTime = trim($row[4]);
|
||||||
|
|
||||||
if (empty($rowNumber)) { continue; }
|
if (empty($rowNumber)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (empty($guardName) || empty($checkPointName) || empty($readerCode) || empty($patrolTime)) {
|
if (empty($guardName) || empty($checkPointName) || empty($readerCode) || empty($patrolTime)) {
|
||||||
continue;
|
continue;
|
||||||
@@ -696,7 +709,7 @@ class GuardPatrolEntryResource extends Resource
|
|||||||
|
|
||||||
$isValidRow = true;
|
$isValidRow = true;
|
||||||
|
|
||||||
$formats = ['d-m-Y H:i:s', 'd-m-Y H:i']; //'07-05-2025 08:00' or '07-05-2025 08:00:00'
|
$formats = ['d-m-Y H:i:s', 'd-m-Y H:i']; // '07-05-2025 08:00' or '07-05-2025 08:00:00'
|
||||||
$patrolDateTime = null;
|
$patrolDateTime = null;
|
||||||
foreach ($formats as $format) {
|
foreach ($formats as $format) {
|
||||||
try {
|
try {
|
||||||
@@ -707,7 +720,7 @@ class GuardPatrolEntryResource extends Resource
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($patrolDateTime)) {
|
if (! isset($patrolDateTime)) {
|
||||||
$isValidRow = false;
|
$isValidRow = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -718,23 +731,22 @@ class GuardPatrolEntryResource extends Resource
|
|||||||
$guardEntryFound = GuardPatrolEntry::where('plant_id', $plantId)->where('guard_name_id', $guardNames->id)->where('check_point_name_id', $checkPointNames->id)->where('patrol_time', $patrolDateTime->format('Y-m-d H:i:s'))->first();
|
$guardEntryFound = GuardPatrolEntry::where('plant_id', $plantId)->where('guard_name_id', $guardNames->id)->where('check_point_name_id', $checkPointNames->id)->where('patrol_time', $patrolDateTime->format('Y-m-d H:i:s'))->first();
|
||||||
|
|
||||||
if ($guardEntryFound) {
|
if ($guardEntryFound) {
|
||||||
//$warnMsg[] = "Duplicate guard patrol entry found";
|
// $warnMsg[] = "Duplicate guard patrol entry found";
|
||||||
$dupCnt++;
|
$dupCnt++;
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$validCnt++;
|
$validCnt++;
|
||||||
GuardPatrolEntry::updateOrCreate([
|
GuardPatrolEntry::updateOrCreate([
|
||||||
'plant_id' => $plantId,
|
'plant_id' => $plantId,
|
||||||
'guard_name_id' => $guardNames->id,
|
'guard_name_id' => $guardNames->id,
|
||||||
'check_point_name_id' => $checkPointNames->id,
|
'check_point_name_id' => $checkPointNames->id,
|
||||||
'patrol_time' => $patrolDateTime->format('Y-m-d H:i:s')
|
'patrol_time' => $patrolDateTime->format('Y-m-d H:i:s'),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'reader_code' => $readerCode,
|
'reader_code' => $readerCode,
|
||||||
'created_by' => $user,
|
'created_by' => $user,
|
||||||
'updated_by' => $user
|
'updated_by' => $user,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
$validRowsFound = true;
|
$validRowsFound = true;
|
||||||
@@ -742,31 +754,25 @@ class GuardPatrolEntryResource extends Resource
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$validRowsFound && $dupCnt > 0) {
|
if (! $validRowsFound && $dupCnt > 0) {
|
||||||
Notification::make()
|
Notification::make()
|
||||||
->title('Duplicate Guard Patrol Entry Found')
|
->title('Duplicate Guard Patrol Entry Found')
|
||||||
->body("Uploaded excel sheet contains '{$dupCnt}' duplicate entries!<br>Please check the uploaded file and try again.")
|
->body("Uploaded excel sheet contains '{$dupCnt}' duplicate entries!<br>Please check the uploaded file and try again.")
|
||||||
->danger()
|
->danger()
|
||||||
->send();
|
->send();
|
||||||
if ($disk->exists($path))
|
if ($disk->exists($path)) {
|
||||||
{
|
|
||||||
$disk->delete($path);
|
$disk->delete($path);
|
||||||
}
|
}
|
||||||
}
|
} elseif ($validRowsFound && $validCnt > 0) {
|
||||||
else if ($validRowsFound && $validCnt > 0)
|
// session(['guard_patrol_entry_path' => $fullPath]);
|
||||||
{
|
|
||||||
//session(['guard_patrol_entry_path' => $fullPath]);
|
|
||||||
Notification::make()
|
Notification::make()
|
||||||
->title("Success: '{$validCnt}' guard patrol entries imported successfully.")
|
->title("Success: '{$validCnt}' guard patrol entries imported successfully.")
|
||||||
->success()
|
->success()
|
||||||
->send();
|
->send();
|
||||||
if ($disk->exists($path))
|
if ($disk->exists($path)) {
|
||||||
{
|
|
||||||
$disk->delete($path);
|
$disk->delete($path);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
Notification::make()
|
Notification::make()
|
||||||
->title('Failed: Something went wrong while uploading guard patrol entries!')
|
->title('Failed: Something went wrong while uploading guard patrol entries!')
|
||||||
->danger()
|
->danger()
|
||||||
@@ -777,7 +783,7 @@ class GuardPatrolEntryResource extends Resource
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
->visible(function() {
|
->visible(function () {
|
||||||
return Filament::auth()->user()->can('view import guard patrol entries');
|
return Filament::auth()->user()->can('view import guard patrol entries');
|
||||||
}),
|
}),
|
||||||
ImportAction::make()
|
ImportAction::make()
|
||||||
@@ -785,14 +791,14 @@ class GuardPatrolEntryResource extends Resource
|
|||||||
// ->hidden()
|
// ->hidden()
|
||||||
->color('warning')
|
->color('warning')
|
||||||
->importer(GuardPatrolEntryImporter::class)
|
->importer(GuardPatrolEntryImporter::class)
|
||||||
->visible(function() {
|
->visible(function () {
|
||||||
return Filament::auth()->user()->can('view import guard patrol entry');
|
return Filament::auth()->user()->can('view import guard patrol entry');
|
||||||
}),
|
}),
|
||||||
ExportAction::make()
|
ExportAction::make()
|
||||||
->label('Export Guard Patrol Entry')
|
->label('Export Guard Patrol Entry')
|
||||||
->color('warning')
|
->color('warning')
|
||||||
->exporter(GuardPatrolEntryExporter::class)
|
->exporter(GuardPatrolEntryExporter::class)
|
||||||
->visible(function() {
|
->visible(function () {
|
||||||
return Filament::auth()->user()->can('view export guard patrol entry');
|
return Filament::auth()->user()->can('view export guard patrol entry');
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
|||||||
Reference in New Issue
Block a user