Updated validation func. on import
This commit is contained in:
@@ -2,10 +2,14 @@
|
|||||||
|
|
||||||
namespace App\Filament\Imports;
|
namespace App\Filament\Imports;
|
||||||
|
|
||||||
|
use App\Models\Block;
|
||||||
|
use App\Models\Plant;
|
||||||
use App\Models\Shift;
|
use App\Models\Shift;
|
||||||
|
use Filament\Actions\Imports\Exceptions\RowImportFailedException;
|
||||||
use Filament\Actions\Imports\ImportColumn;
|
use Filament\Actions\Imports\ImportColumn;
|
||||||
use Filament\Actions\Imports\Importer;
|
use Filament\Actions\Imports\Importer;
|
||||||
use Filament\Actions\Imports\Models\Import;
|
use Filament\Actions\Imports\Models\Import;
|
||||||
|
use Str;
|
||||||
|
|
||||||
class ShiftImporter extends Importer
|
class ShiftImporter extends Importer
|
||||||
{
|
{
|
||||||
@@ -64,12 +68,30 @@ class ShiftImporter extends Importer
|
|||||||
|
|
||||||
public function resolveRecord(): ?Shift
|
public function resolveRecord(): ?Shift
|
||||||
{
|
{
|
||||||
$plant = \App\Models\Plant::where('name', $this->data['plant'])->first();
|
$warnMsg = [];
|
||||||
$block = \App\Models\Block::where('name', $this->data['block'])->where('plant_id', $plant->id)->first();
|
$plant = Plant::where('name', $this->data['plant'])->first();
|
||||||
|
if (!$plant) {
|
||||||
|
$warnMsg[] = "Plant not found";
|
||||||
|
}
|
||||||
|
$block = Block::where('name', $this->data['block'])->where('plant_id', $plant->id)->first();
|
||||||
|
if (!$block) {
|
||||||
|
$warnMsg[] = "Block not found";
|
||||||
|
}
|
||||||
|
if (Str::length($this->data['duration']) < 0 || !is_numeric($this->data['duration'])) {
|
||||||
|
$warnMsg[] = "Invalid duration found";
|
||||||
|
}
|
||||||
|
if (Str::length($this->data['start_time']) < 0) {
|
||||||
|
$warnMsg[] = "Invalid start time found";
|
||||||
|
}
|
||||||
|
if (Str::length($this->data['end_time']) < 0) {
|
||||||
|
$warnMsg[] = "Invalid end time found";
|
||||||
|
}
|
||||||
|
if (Str::length($this->data['status']) < 0 || $this->data['status'] != 'Active') {
|
||||||
|
$warnMsg[] = "Invalid shift status found";
|
||||||
|
}
|
||||||
|
|
||||||
if (!$plant || !$block) {
|
if (!empty($warnMsg)) {
|
||||||
// Optionally handle missing plant/block
|
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$shift = Shift::where('name', $this->data['name'])
|
$shift = Shift::where('name', $this->data['name'])
|
||||||
|
|||||||
Reference in New Issue
Block a user