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,21 +52,21 @@ 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 () {
|
||||
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) {
|
||||
$plantId = $get('plant_id');
|
||||
if (!$plantId) {
|
||||
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);
|
||||
@@ -84,7 +82,7 @@ class GuardPatrolEntryResource extends Resource
|
||||
// ->relationship('guardNames', 'name')
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
if (!$plantId) {
|
||||
if (! $plantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -97,15 +95,14 @@ class GuardPatrolEntryResource extends Resource
|
||||
->default(function () {
|
||||
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) {
|
||||
$guardName = $get('guard_name_id');
|
||||
if (!$guardName) {
|
||||
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);
|
||||
@@ -116,7 +113,7 @@ class GuardPatrolEntryResource extends Resource
|
||||
])
|
||||
->hint(fn ($get) => $get('gPeGuardNameError') ? $get('gPeGuardNameError') : null)
|
||||
->hintColor('danger'),
|
||||
Forms\Components\Hidden::make('check_point_name')//TextInput
|
||||
Forms\Components\Hidden::make('check_point_name')// TextInput
|
||||
->label('Check Point Name')
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
@@ -131,7 +128,7 @@ class GuardPatrolEntryResource extends Resource
|
||||
// ->relationship('checkPointNames', 'name')
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
if (!$plantId) {
|
||||
if (! $plantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -144,16 +141,15 @@ class GuardPatrolEntryResource extends Resource
|
||||
// ->default(function () {
|
||||
// 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) {
|
||||
$checkPointName = $get('check_point_name_id');
|
||||
if (!$checkPointName) {
|
||||
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);
|
||||
@@ -173,11 +169,10 @@ class GuardPatrolEntryResource extends Resource
|
||||
}),
|
||||
Forms\Components\TextInput::make('reader_code')
|
||||
->label('Reader Code')
|
||||
->hidden(fn (Get $get) => !$get('id'))
|
||||
->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);
|
||||
@@ -186,7 +181,7 @@ class GuardPatrolEntryResource extends Resource
|
||||
->label('Patrol Time')
|
||||
->reactive()
|
||||
->default(fn () => now())
|
||||
->readOnly(fn (Get $get) => !$get('id'))
|
||||
->readOnly(fn (Get $get) => ! $get('id'))
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$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')
|
||||
@@ -235,11 +231,11 @@ class GuardPatrolEntryResource extends Resource
|
||||
->label('Plant')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('guardNames.name') //guard_name_id
|
||||
Tables\Columns\TextColumn::make('guardNames.name') // guard_name_id
|
||||
->label('Guard Name')
|
||||
->alignCenter()
|
||||
->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')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
@@ -288,18 +284,19 @@ 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(),
|
||||
// ->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
// $set('sticker_master_id', null);
|
||||
// $set('sap_msg_status', null);
|
||||
// }),
|
||||
// ->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
// $set('sticker_master_id', null);
|
||||
// $set('sap_msg_status', null);
|
||||
// }),
|
||||
Select::make('Guard Name')
|
||||
->label('Select Guard Name')
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('Plant');
|
||||
if (!$plantId) {
|
||||
if (! $plantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -310,7 +307,7 @@ class GuardPatrolEntryResource extends Resource
|
||||
->label('Select Check Point Name')
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('Plant');
|
||||
if (!$plantId) {
|
||||
if (! $plantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -322,11 +319,11 @@ class GuardPatrolEntryResource extends Resource
|
||||
->placeholder('Select Created By')
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('Plant');
|
||||
if (!$plantId) {
|
||||
if (! $plantId) {
|
||||
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(),
|
||||
DateTimePicker::make(name: 'From Patrol Time')
|
||||
@@ -341,66 +338,78 @@ class GuardPatrolEntryResource extends Resource
|
||||
->placeholder(placeholder: 'Select To Patrol Time')
|
||||
->reactive()
|
||||
->native(false),
|
||||
])
|
||||
->query(function ($query, array $data) {
|
||||
//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'])) {
|
||||
return $query->whereRaw('1 = 0');
|
||||
}
|
||||
])
|
||||
->query(function ($query, array $data) {
|
||||
// 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'])) {
|
||||
return $query->whereRaw('1 = 0');
|
||||
}
|
||||
|
||||
if (!empty($data['Plant'])) {
|
||||
$query->where('plant_id', $data['Plant']);
|
||||
}
|
||||
if (! empty($data['Plant'])) {
|
||||
$query->where('plant_id', $data['Plant']);
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if (!empty($data['Guard Name'])) {
|
||||
$query->where('guard_name_id', $data['Guard Name']);
|
||||
}
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return $query->whereRaw('1 = 0');
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($data['Check Point Name'])) {
|
||||
$query->where('check_point_name_id', $data['Check Point Name']);
|
||||
}
|
||||
if (! empty($data['Guard Name'])) {
|
||||
$query->where('guard_name_id', $data['Guard Name']);
|
||||
}
|
||||
|
||||
if (!empty($data['Created By'])) {
|
||||
$query->where('created_by', $data['Created By']);
|
||||
}
|
||||
if (! empty($data['Check Point Name'])) {
|
||||
$query->where('check_point_name_id', $data['Check Point Name']);
|
||||
}
|
||||
|
||||
if (!empty($data['From Patrol Time'])) {
|
||||
$query->where('patrol_time', '>=', $data['From Patrol Time']);
|
||||
}
|
||||
if (! empty($data['Created By'])) {
|
||||
$query->where('created_by', $data['Created By']);
|
||||
}
|
||||
|
||||
if (!empty($data['To Patrol Time'])) {
|
||||
$query->where('patrol_time', '<=', $data['To Patrol Time']);
|
||||
}
|
||||
})
|
||||
->indicateUsing(function (array $data) {
|
||||
$indicators = [];
|
||||
if (! empty($data['From Patrol Time'])) {
|
||||
$query->where('patrol_time', '>=', $data['From Patrol Time']);
|
||||
}
|
||||
|
||||
if (!empty($data['Plant'])) {
|
||||
$indicators[] = 'Plant: ' . Plant::where('id', $data['Plant'])->value('name');
|
||||
}
|
||||
if (! empty($data['To Patrol Time'])) {
|
||||
$query->where('patrol_time', '<=', $data['To Patrol Time']);
|
||||
}
|
||||
})
|
||||
->indicateUsing(function (array $data) {
|
||||
$indicators = [];
|
||||
|
||||
if (!empty($data['Guard Name'])) {
|
||||
$indicators[] = 'Guard Name: ' . GuardName::where('plant_id', $data['Plant'])->where('id', $data['Guard Name'])->value('name');
|
||||
}
|
||||
if (! empty($data['Plant'])) {
|
||||
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if (!empty($data['Check Point Name'])) {
|
||||
$indicators[] = 'Check Point Name: ' . CheckPointName::where('plant_id', $data['Plant'])->where('id', $data['Check Point Name'])->value('name');
|
||||
}
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return 'Plant: Choose plant to filter records.';
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($data['Created By'])) {
|
||||
$indicators[] = 'Created By: ' . $data['Created By'];
|
||||
}
|
||||
if (! empty($data['Guard Name'])) {
|
||||
$indicators[] = 'Guard Name: '.GuardName::where('plant_id', $data['Plant'])->where('id', $data['Guard Name'])->value('name');
|
||||
}
|
||||
|
||||
if (!empty($data['From Patrol Time'])) {
|
||||
$indicators[] = 'From: ' . $data['From Patrol Time'];
|
||||
}
|
||||
if (! empty($data['Check Point Name'])) {
|
||||
$indicators[] = 'Check Point Name: '.CheckPointName::where('plant_id', $data['Plant'])->where('id', $data['Check Point Name'])->value('name');
|
||||
}
|
||||
|
||||
if (!empty($data['To Patrol Time'])) {
|
||||
$indicators[] = 'To: ' . $data['To Patrol Time'];
|
||||
}
|
||||
if (! empty($data['Created By'])) {
|
||||
$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')
|
||||
->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')
|
||||
@@ -433,12 +443,11 @@ class GuardPatrolEntryResource extends Resource
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
$set('guard_patrol_entry', null);
|
||||
if (!$plantId) {
|
||||
if (! $plantId) {
|
||||
$set('gPeSelectPlantError', 'Please select a plant first.');
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('gPeSelectPlantError', null);
|
||||
}
|
||||
})
|
||||
@@ -455,7 +464,7 @@ class GuardPatrolEntryResource extends Resource
|
||||
->reactive()
|
||||
->required()
|
||||
->disk('local')
|
||||
->visible(fn (Get $get) => !empty($get('plant_id')))
|
||||
->visible(fn (Get $get) => ! empty($get('plant_id')))
|
||||
->directory('uploads/temp')
|
||||
// Allow only .xlsx and .xls
|
||||
->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
|
||||
->rules(['mimes:xlsx,xls']),
|
||||
])
|
||||
])
|
||||
->action(function (array $data) {
|
||||
$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');
|
||||
|
||||
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,19 +525,21 @@ class GuardPatrolEntryResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$invalidRows=[];
|
||||
$invalidGuardCheckPoints=[];
|
||||
$unknownGuards=[];
|
||||
$unknownCheckPoints=[];
|
||||
$invalidPatrolTimes=[];
|
||||
$invalidRows = [];
|
||||
$invalidGuardCheckPoints = [];
|
||||
$unknownGuards = [];
|
||||
$unknownCheckPoints = [];
|
||||
$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,35 +547,34 @@ 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) {
|
||||
if (! $guardNames) {
|
||||
$unknownGuards[] = $guardName;
|
||||
$isValidRow = false;
|
||||
}
|
||||
|
||||
$checkPointNames = CheckPointName::where('plant_id', $plantId)->where('name', $checkPointName)->first();
|
||||
if (!$checkPointNames) {
|
||||
if (! $checkPointNames) {
|
||||
$unknownCheckPoints[] = $checkPointName;
|
||||
$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;
|
||||
foreach ($formats as $format) {
|
||||
try {
|
||||
@@ -579,13 +586,13 @@ class GuardPatrolEntryResource extends Resource
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($patrolDateTime)) {
|
||||
if (! isset($patrolDateTime)) {
|
||||
$invalidPatrolTimes[] = $rowNumber;
|
||||
$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;
|
||||
}
|
||||
}
|
||||
@@ -593,38 +600,40 @@ class GuardPatrolEntryResource extends Resource
|
||||
}
|
||||
|
||||
$uniqueInvalidRows = array_unique($invalidRows);
|
||||
if (!empty($uniqueInvalidRows)) {
|
||||
if (! empty($uniqueInvalidRows)) {
|
||||
Notification::make()
|
||||
->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()
|
||||
->send();
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//should contain minimum 13 digit alpha numeric values
|
||||
// should contain minimum 13 digit alpha numeric values
|
||||
$uniqueInvalidGuardCheckPoints = array_unique($invalidGuardCheckPoints);
|
||||
if (!empty($uniqueInvalidGuardCheckPoints)) {
|
||||
if (! empty($uniqueInvalidGuardCheckPoints)) {
|
||||
Notification::make()
|
||||
->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()
|
||||
->send();
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$invalidDataFound = false;
|
||||
$uniqueUnknownGuards = array_unique($unknownGuards);
|
||||
if (!empty($uniqueUnknownGuards)) {
|
||||
if (! empty($uniqueUnknownGuards)) {
|
||||
Notification::make()
|
||||
->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()
|
||||
->send();
|
||||
if ($disk->exists($path)) {
|
||||
@@ -634,10 +643,10 @@ class GuardPatrolEntryResource extends Resource
|
||||
}
|
||||
|
||||
$uniqueUnknownCheckPoints = array_unique($unknownCheckPoints);
|
||||
if (!empty($uniqueUnknownCheckPoints)) {
|
||||
if (! empty($uniqueUnknownCheckPoints)) {
|
||||
Notification::make()
|
||||
->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()
|
||||
->send();
|
||||
if ($disk->exists($path)) {
|
||||
@@ -647,10 +656,10 @@ class GuardPatrolEntryResource extends Resource
|
||||
}
|
||||
|
||||
$uniqueInvalidPatrolTimes = array_unique($invalidPatrolTimes);
|
||||
if (!empty($uniqueInvalidPatrolTimes)) {
|
||||
if (! empty($uniqueInvalidPatrolTimes)) {
|
||||
Notification::make()
|
||||
->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()
|
||||
->send();
|
||||
if ($disk->exists($path)) {
|
||||
@@ -663,24 +672,26 @@ class GuardPatrolEntryResource extends Resource
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$validRowsFound) {
|
||||
if (! $validRowsFound) {
|
||||
Notification::make()
|
||||
->title('Invalid Guard Patrol Entry Found')
|
||||
->body('Uploaded excel sheet is empty or<br>contains no valid data.')
|
||||
->danger()
|
||||
->send();
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
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;
|
||||
@@ -696,7 +709,7 @@ class GuardPatrolEntryResource extends Resource
|
||||
|
||||
$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;
|
||||
foreach ($formats as $format) {
|
||||
try {
|
||||
@@ -707,7 +720,7 @@ class GuardPatrolEntryResource extends Resource
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($patrolDateTime)) {
|
||||
if (! isset($patrolDateTime)) {
|
||||
$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();
|
||||
|
||||
if ($guardEntryFound) {
|
||||
//$warnMsg[] = "Duplicate guard patrol entry found";
|
||||
// $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
|
||||
[
|
||||
'reader_code' => $readerCode,
|
||||
'created_by' => $user,
|
||||
'updated_by' => $user,
|
||||
]
|
||||
);
|
||||
$validRowsFound = true;
|
||||
@@ -742,31 +754,25 @@ class GuardPatrolEntryResource extends Resource
|
||||
}
|
||||
}
|
||||
|
||||
if (!$validRowsFound && $dupCnt > 0) {
|
||||
if (! $validRowsFound && $dupCnt > 0) {
|
||||
Notification::make()
|
||||
->title('Duplicate Guard Patrol Entry Found')
|
||||
->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)
|
||||
{
|
||||
//session(['guard_patrol_entry_path' => $fullPath]);
|
||||
} 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()
|
||||
@@ -777,7 +783,7 @@ class GuardPatrolEntryResource extends Resource
|
||||
}
|
||||
}
|
||||
})
|
||||
->visible(function() {
|
||||
->visible(function () {
|
||||
return Filament::auth()->user()->can('view import guard patrol entries');
|
||||
}),
|
||||
ImportAction::make()
|
||||
@@ -785,14 +791,14 @@ class GuardPatrolEntryResource extends Resource
|
||||
// ->hidden()
|
||||
->color('warning')
|
||||
->importer(GuardPatrolEntryImporter::class)
|
||||
->visible(function() {
|
||||
->visible(function () {
|
||||
return Filament::auth()->user()->can('view import guard patrol entry');
|
||||
}),
|
||||
ExportAction::make()
|
||||
->label('Export Guard Patrol Entry')
|
||||
->color('warning')
|
||||
->exporter(GuardPatrolEntryExporter::class)
|
||||
->visible(function() {
|
||||
->visible(function () {
|
||||
return Filament::auth()->user()->can('view export guard patrol entry');
|
||||
}),
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user