Added view rights against plant on import and export
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 9s
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 9s
This commit is contained in:
@@ -24,8 +24,8 @@ class GuardPatrolEntryExporter extends Exporter
|
|||||||
}),
|
}),
|
||||||
// ExportColumn::make('id')
|
// ExportColumn::make('id')
|
||||||
// ->label('ID'),
|
// ->label('ID'),
|
||||||
ExportColumn::make('plant.name')
|
ExportColumn::make('plant.code')
|
||||||
->label('PLANT'),
|
->label('PLANT CODE'),
|
||||||
ExportColumn::make('guardNames.name')
|
ExportColumn::make('guardNames.name')
|
||||||
->label('GUARD NAME'),
|
->label('GUARD NAME'),
|
||||||
ExportColumn::make('checkPointNames.name')
|
ExportColumn::make('checkPointNames.name')
|
||||||
@@ -54,10 +54,10 @@ class GuardPatrolEntryExporter extends Exporter
|
|||||||
|
|
||||||
public static function getCompletedNotificationBody(Export $export): string
|
public static function getCompletedNotificationBody(Export $export): string
|
||||||
{
|
{
|
||||||
$body = 'Your guard patrol entry export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
|
$body = 'Your guard patrol entry export has completed and '.number_format($export->successful_rows).' '.str('row')->plural($export->successful_rows).' exported.';
|
||||||
|
|
||||||
if ($failedRowsCount = $export->getFailedRowsCount()) {
|
if ($failedRowsCount = $export->getFailedRowsCount()) {
|
||||||
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
|
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to export.';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $body;
|
return $body;
|
||||||
|
|||||||
@@ -23,10 +23,10 @@ class GuardPatrolEntryImporter extends Importer
|
|||||||
return [
|
return [
|
||||||
ImportColumn::make('plant')
|
ImportColumn::make('plant')
|
||||||
->requiredMapping()
|
->requiredMapping()
|
||||||
->exampleHeader('Plant Name')
|
->exampleHeader('Plant Code')
|
||||||
->example('Ransar Industries-I')
|
->example('1000')
|
||||||
->label('Plant Name')
|
->label('Plant Code')
|
||||||
->relationship(resolveUsing: 'name')
|
->relationship(resolveUsing: 'code')
|
||||||
->rules(['required']),
|
->rules(['required']),
|
||||||
ImportColumn::make('guardNames')
|
ImportColumn::make('guardNames')
|
||||||
->requiredMapping()
|
->requiredMapping()
|
||||||
@@ -68,61 +68,60 @@ class GuardPatrolEntryImporter extends Importer
|
|||||||
public function resolveRecord(): ?GuardPatrolEntry
|
public function resolveRecord(): ?GuardPatrolEntry
|
||||||
{
|
{
|
||||||
$warnMsg = [];
|
$warnMsg = [];
|
||||||
$plant = Plant::where('name', $this->data['plant'])->first();
|
$plantCod = $this->data['plant'];
|
||||||
|
$plant = null;
|
||||||
$guardNames = null;
|
$guardNames = null;
|
||||||
$checkPointNames = null;
|
$checkPointNames = null;
|
||||||
$patrolDateTime = null; //$fdateTime = null;
|
$patrolDateTime = null; // $fdateTime = null;
|
||||||
if (!$plant) {
|
|
||||||
$warnMsg[] = "Plant not found"; // '" . $this->data['plant'] . "'
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$guardNames = GuardName::where('plant_id', $plant->id)->where('name', $this->data['guardNames'])->first();
|
|
||||||
if (!$guardNames) {
|
|
||||||
$warnMsg[] = "Guard name not found";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$checkPointNames = CheckPointName::where('plant_id', $plant->id)->where('name', $this->data['checkPointNames'])->first();
|
|
||||||
if (!$checkPointNames) {
|
|
||||||
$warnMsg[] = "Check point name not found";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$patrolTime = $this->data['patrol_time'];//$fromDate = $this->data['from_datetime'];
|
|
||||||
$formats = ['d-m-Y H:i', 'd-m-Y H:i:s']; //'07-05-2025 08:00' or '07-05-2025 08:00:00'
|
|
||||||
|
|
||||||
foreach ($formats as $format) {
|
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
|
||||||
try {
|
$warnMsg[] = 'Invalid plant code found';
|
||||||
$patrolDateTime = Carbon::createFromFormat($format, $patrolTime);
|
} else {
|
||||||
break;
|
$plant = Plant::where('code', $plantCod)->first();
|
||||||
} catch (\Exception $e) {
|
if (! $plant) {
|
||||||
// Optionally collect warning messages
|
$warnMsg[] = 'Plant not found'; // '" . $plantCod . "'
|
||||||
// $warnMsg[] = "Date format mismatch with format: $format";
|
} else {
|
||||||
|
$guardNames = GuardName::where('plant_id', $plant->id)->where('name', $this->data['guardNames'])->first();
|
||||||
|
if (! $guardNames) {
|
||||||
|
$warnMsg[] = 'Guard name not found';
|
||||||
|
} else {
|
||||||
|
$checkPointNames = CheckPointName::where('plant_id', $plant->id)->where('name', $this->data['checkPointNames'])->first();
|
||||||
|
if (! $checkPointNames) {
|
||||||
|
$warnMsg[] = 'Check point name not found';
|
||||||
|
} else {
|
||||||
|
$patrolTime = $this->data['patrol_time']; // $fromDate = $this->data['from_datetime'];
|
||||||
|
$formats = ['d-m-Y H:i', 'd-m-Y H:i:s']; // '07-05-2025 08:00' or '07-05-2025 08:00:00'
|
||||||
|
|
||||||
|
foreach ($formats as $format) {
|
||||||
|
try {
|
||||||
|
$patrolDateTime = Carbon::createFromFormat($format, $patrolTime);
|
||||||
|
break;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
// Optionally collect warning messages
|
||||||
|
// $warnMsg[] = "Date format mismatch with format: $format";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset($patrolDateTime)) {
|
if (! isset($patrolDateTime)) {
|
||||||
// throw new \Exception('Invalid date time format');
|
// throw new \Exception('Invalid date time format');
|
||||||
$warnMsg[] = "Invalid 'Patrol DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
|
$warnMsg[] = "Invalid 'Patrol DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
|
||||||
}
|
} else {
|
||||||
else
|
$guardEntryFound = GuardPatrolEntry::where('plant_id', $plant->id)->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) {
|
||||||
$guardEntryFound = GuardPatrolEntry::where('plant_id', $plant->id)->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();
|
$warnMsg[] = 'Duplicate guard patrol entry found';
|
||||||
if ($guardEntryFound) {
|
}
|
||||||
$warnMsg[] = "Duplicate guard patrol entry found";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$createdBy = Filament::auth()->user()->name;// ?? 'Admin'
|
$createdBy = Filament::auth()->user()->name; // ?? 'Admin'
|
||||||
if (!$createdBy) {
|
if (! $createdBy) {
|
||||||
$warnMsg[] = "Invalid created by name found";
|
$warnMsg[] = 'Invalid created by name found';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($warnMsg)) {
|
if (! empty($warnMsg)) {
|
||||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,14 +129,15 @@ class GuardPatrolEntryImporter extends Importer
|
|||||||
'plant_id' => $plant->id,
|
'plant_id' => $plant->id,
|
||||||
'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' => null,
|
'reader_code' => null,
|
||||||
'created_by' => $createdBy,
|
'created_by' => $createdBy,
|
||||||
'updated_by' => $createdBy
|
'updated_by' => $createdBy,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
// // return GuardPatrolEntry::firstOrNew([
|
// // return GuardPatrolEntry::firstOrNew([
|
||||||
// // // Update existing records, matching them by `$this->data['column_name']`
|
// // // Update existing records, matching them by `$this->data['column_name']`
|
||||||
@@ -149,10 +149,10 @@ class GuardPatrolEntryImporter extends Importer
|
|||||||
|
|
||||||
public static function getCompletedNotificationBody(Import $import): string
|
public static function getCompletedNotificationBody(Import $import): string
|
||||||
{
|
{
|
||||||
$body = 'Your guard patrol entry import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
|
$body = 'Your guard patrol entry import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
|
||||||
|
|
||||||
if ($failedRowsCount = $import->getFailedRowsCount()) {
|
if ($failedRowsCount = $import->getFailedRowsCount()) {
|
||||||
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
|
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $body;
|
return $body;
|
||||||
|
|||||||
Reference in New Issue
Block a user