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\Imports\GuardPatrolEntryImporter;
|
||||
use App\Filament\Resources\GuardPatrolEntryResource\Pages;
|
||||
use App\Filament\Resources\GuardPatrolEntryResource\RelationManagers;
|
||||
use App\Models\CheckPointName;
|
||||
use App\Models\Configuration;
|
||||
use App\Models\GuardName;
|
||||
@@ -17,7 +16,6 @@ use Filament\Forms;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Tabs\Tab;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Forms\Get;
|
||||
@@ -54,6 +52,7 @@ class GuardPatrolEntryResource extends Resource
|
||||
->reactive()
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->default(function () {
|
||||
@@ -65,10 +64,9 @@ class GuardPatrolEntryResource extends Resource
|
||||
if (! $plantId) {
|
||||
// $set('gPePlantError', 'Please select a plant first.');
|
||||
$set('gPePlantError', 'Please select a plant first.');
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('patrol_time', now()->format('Y-m-d H:i:s'));
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
$set('gPePlantError', null);
|
||||
@@ -102,10 +100,9 @@ class GuardPatrolEntryResource extends Resource
|
||||
$guardName = $get('guard_name_id');
|
||||
if (! $guardName) {
|
||||
$set('gPeGuardNameError', 'Please select a guard name first.');
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('patrol_time', now()->format('Y-m-d H:i:s'));
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
$set('gPeGuardNameError', null);
|
||||
@@ -150,10 +147,9 @@ class GuardPatrolEntryResource extends Resource
|
||||
if (! $checkPointName) {
|
||||
$set('check_point_name_id', null);
|
||||
$set('gPeCheckPointNameError', 'Please select a check point name first.');
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('patrol_time', now()->format('Y-m-d H:i:s'));
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
$set('gPeCheckPointNameError', null);
|
||||
@@ -176,8 +172,7 @@ class GuardPatrolEntryResource extends Resource
|
||||
->hidden(fn (Get $get) => ! $get('id'))
|
||||
->reactive()
|
||||
->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('updated_by', Filament::auth()->user()?->name);
|
||||
@@ -225,6 +220,7 @@ class GuardPatrolEntryResource extends Resource
|
||||
$paginator = $livewire->getTableRecords();
|
||||
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
|
||||
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
|
||||
|
||||
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
|
||||
}),
|
||||
// Tables\Columns\TextColumn::make('id')
|
||||
@@ -288,6 +284,7 @@ class GuardPatrolEntryResource extends Resource
|
||||
// })
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->reactive(),
|
||||
@@ -350,6 +347,12 @@ class GuardPatrolEntryResource extends Resource
|
||||
|
||||
if (! empty($data['Plant'])) {
|
||||
$query->where('plant_id', $data['Plant']);
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return $query->whereRaw('1 = 0');
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($data['Guard Name'])) {
|
||||
@@ -377,6 +380,12 @@ class GuardPatrolEntryResource extends Resource
|
||||
|
||||
if (! empty($data['Plant'])) {
|
||||
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return 'Plant: Choose plant to filter records.';
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($data['Guard Name'])) {
|
||||
@@ -400,7 +409,7 @@ class GuardPatrolEntryResource extends Resource
|
||||
}
|
||||
|
||||
return $indicators;
|
||||
})
|
||||
}),
|
||||
])
|
||||
->filtersFormMaxHeight('280px')
|
||||
->actions([
|
||||
@@ -422,6 +431,7 @@ class GuardPatrolEntryResource extends Resource
|
||||
// ->options(Plant::pluck('name', 'id')->toArray())
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->label('Select Plant')
|
||||
@@ -435,10 +445,9 @@ class GuardPatrolEntryResource extends Resource
|
||||
$set('guard_patrol_entry', null);
|
||||
if (! $plantId) {
|
||||
$set('gPeSelectPlantError', 'Please select a plant first.');
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('gPeSelectPlantError', null);
|
||||
}
|
||||
})
|
||||
@@ -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');
|
||||
|
||||
if(!$folderPath)
|
||||
{
|
||||
if (! $folderPath) {
|
||||
Notification::make()
|
||||
->title('Upload Folder Path Not Found!')
|
||||
->body('Please set the folder path in configuration for Guard Patrol Entry.')
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$fullFolderPath = "uploads/$folderPath";
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
@@ -504,12 +512,10 @@ class GuardPatrolEntryResource extends Resource
|
||||
|
||||
$fullPath = Storage::disk('local')->path($path);
|
||||
|
||||
if ($fullPath && file_exists($fullPath))
|
||||
{
|
||||
if ($fullPath && file_exists($fullPath)) {
|
||||
$rows = Excel::toArray(null, $fullPath)[0];
|
||||
|
||||
if((count($rows) - 1) <= 0)
|
||||
{
|
||||
if ((count($rows) - 1) <= 0) {
|
||||
Notification::make()
|
||||
->title('Invalid Guard Patrol Entry Found')
|
||||
->body('Uploaded excel sheet is empty or<br>contains no valid data.')
|
||||
@@ -519,6 +525,7 @@ class GuardPatrolEntryResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -529,9 +536,10 @@ class GuardPatrolEntryResource extends Resource
|
||||
$invalidPatrolTimes = [];
|
||||
$validRowsFound = false;
|
||||
|
||||
foreach ($rows as $index => $row)
|
||||
{
|
||||
if ($index === 0) continue; // Skip header
|
||||
foreach ($rows as $index => $row) {
|
||||
if ($index === 0) {
|
||||
continue;
|
||||
} // Skip header
|
||||
|
||||
$rowNumber = trim($row[0]);
|
||||
$guardName = trim($row[1]);
|
||||
@@ -539,21 +547,20 @@ class GuardPatrolEntryResource extends Resource
|
||||
$readerCode = trim($row[3]);
|
||||
$patrolTime = trim($row[4]);
|
||||
|
||||
if (empty($rowNumber)) { continue; }
|
||||
if (empty($rowNumber)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (empty($guardName) || empty($checkPointName) || empty($readerCode) || empty($patrolTime)) {
|
||||
$invalidRows[] = $rowNumber;
|
||||
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(Str::length($guardName) < 3 || Str::length($checkPointName) < 3 || Str::length($readerCode) < 3 || Str::length($patrolTime) < 3)
|
||||
{
|
||||
} else {
|
||||
if (Str::length($guardName) < 3 || Str::length($checkPointName) < 3 || Str::length($readerCode) < 3 || Str::length($patrolTime) < 3) {
|
||||
$invalidGuardCheckPoints[] = $rowNumber;
|
||||
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$isValidRow = true;
|
||||
$guardNames = GuardName::where('plant_id', $plantId)->where('name', $guardName)->first();
|
||||
if (! $guardNames) {
|
||||
@@ -602,6 +609,7 @@ class GuardPatrolEntryResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -616,6 +624,7 @@ class GuardPatrolEntryResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -672,15 +681,17 @@ class GuardPatrolEntryResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$validCnt = 0;
|
||||
$dupCnt = 0;
|
||||
$validRowsFound = false;
|
||||
foreach ($rows as $index => $row)
|
||||
{
|
||||
if ($index === 0) continue; // Skip header
|
||||
foreach ($rows as $index => $row) {
|
||||
if ($index === 0) {
|
||||
continue;
|
||||
} // Skip header
|
||||
|
||||
$rowNumber = trim($row[0]);
|
||||
$guardName = trim($row[1]);
|
||||
@@ -688,7 +699,9 @@ class GuardPatrolEntryResource extends Resource
|
||||
$readerCode = trim($row[3]);
|
||||
$patrolTime = trim($row[4]);
|
||||
|
||||
if (empty($rowNumber)) { continue; }
|
||||
if (empty($rowNumber)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (empty($guardName) || empty($checkPointName) || empty($readerCode) || empty($patrolTime)) {
|
||||
continue;
|
||||
@@ -720,21 +733,20 @@ class GuardPatrolEntryResource extends Resource
|
||||
if ($guardEntryFound) {
|
||||
// $warnMsg[] = "Duplicate guard patrol entry found";
|
||||
$dupCnt++;
|
||||
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$validCnt++;
|
||||
GuardPatrolEntry::updateOrCreate([
|
||||
'plant_id' => $plantId,
|
||||
'guard_name_id' => $guardNames->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,
|
||||
'created_by' => $user,
|
||||
'updated_by' => $user
|
||||
'updated_by' => $user,
|
||||
]
|
||||
);
|
||||
$validRowsFound = true;
|
||||
@@ -748,25 +760,19 @@ class GuardPatrolEntryResource extends Resource
|
||||
->body("Uploaded excel sheet contains '{$dupCnt}' duplicate entries!<br>Please check the uploaded file and try again.")
|
||||
->danger()
|
||||
->send();
|
||||
if ($disk->exists($path))
|
||||
{
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
}
|
||||
else if ($validRowsFound && $validCnt > 0)
|
||||
{
|
||||
} elseif ($validRowsFound && $validCnt > 0) {
|
||||
// session(['guard_patrol_entry_path' => $fullPath]);
|
||||
Notification::make()
|
||||
->title("Success: '{$validCnt}' guard patrol entries imported successfully.")
|
||||
->success()
|
||||
->send();
|
||||
if ($disk->exists($path))
|
||||
{
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Notification::make()
|
||||
->title('Failed: Something went wrong while uploading guard patrol entries!')
|
||||
->danger()
|
||||
|
||||
Reference in New Issue
Block a user