ranjith-dev #325

Merged
jothi merged 8 commits from ranjith-dev into master 2026-02-10 08:49:35 +00:00
36 changed files with 1592 additions and 1574 deletions
Showing only changes of commit aaa9c17e66 - Show all commits

View File

@@ -5,34 +5,30 @@ namespace App\Filament\Resources;
use App\Filament\Exports\AlertMailRuleExporter; use App\Filament\Exports\AlertMailRuleExporter;
use App\Filament\Imports\AlertMailRuleImporter; use App\Filament\Imports\AlertMailRuleImporter;
use App\Filament\Resources\AlertMailRuleResource\Pages; use App\Filament\Resources\AlertMailRuleResource\Pages;
use App\Filament\Resources\AlertMailRuleResource\RelationManagers;
use App\Models\AlertMailRule; use App\Models\AlertMailRule;
use App\Models\InvoiceMaster; use App\Models\InvoiceMaster;
use App\Models\Plant; use App\Models\Plant;
use Dotenv\Exception\ValidationException;
use Filament\Facades\Filament; use Filament\Facades\Filament;
use Filament\Forms; use Filament\Forms;
use Filament\Forms\Components\Actions\Action;
use Filament\Forms\Components\Checkbox; use Filament\Forms\Components\Checkbox;
use Filament\Forms\Components\Section;
use Filament\Forms\Form; use Filament\Forms\Form;
use Filament\Notifications\Notification;
use Filament\Resources\Resource; use Filament\Resources\Resource;
use Filament\Tables; use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Table; use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope; use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Actions\Action;
use Filament\Notifications\Notification;
use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\DB;
use Illuminate\Validation\ValidationException as ValidationValidationException;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Actions\ExportAction;
class AlertMailRuleResource extends Resource class AlertMailRuleResource extends Resource
{ {
protected static ?string $model = AlertMailRule::class; protected static ?string $model = AlertMailRule::class;
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack'; protected static ?string $navigationIcon = 'heroicon-m-bell-alert';
protected static ?string $navigationGroup = 'Alert Mail'; protected static ?string $navigationGroup = 'Alert Mail';
@@ -47,7 +43,8 @@ class AlertMailRuleResource 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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->required(fn ($get) => ! $get('is_active')) ->required(fn ($get) => ! $get('is_active'))
->afterStateUpdated(fn ($state, callable $set) => $state ? $set('is_active', false) : null), ->afterStateUpdated(fn ($state, callable $set) => $state ? $set('is_active', false) : null),
@@ -166,6 +163,7 @@ class AlertMailRuleResource 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('plant') Tables\Columns\TextColumn::make('plant')
@@ -178,6 +176,7 @@ class AlertMailRuleResource extends Resource
if (! $plants) { if (! $plants) {
$plants = Plant::pluck('name', 'id')->toArray(); $plants = Plant::pluck('name', 'id')->toArray();
} }
return $plants[$state] ?? 'All Plants'; return $plants[$state] ?? 'All Plants';
}), }),
Tables\Columns\TextColumn::make('module') Tables\Columns\TextColumn::make('module')
@@ -260,14 +259,14 @@ class AlertMailRuleResource extends Resource
->label('Import Alert Mail Rule') ->label('Import Alert Mail Rule')
->color('warning') ->color('warning')
->importer(AlertMailRuleImporter::class) ->importer(AlertMailRuleImporter::class)
->visible(function() { ->visible(function () {
return Filament::auth()->user()->can('view import alert mail rule'); return Filament::auth()->user()->can('view import alert mail rule');
}), }),
ExportAction::make() ExportAction::make()
->label('Export Alert Mail Rule') ->label('Export Alert Mail Rule')
->color('warning') ->color('warning')
->exporter(AlertMailRuleExporter::class) ->exporter(AlertMailRuleExporter::class)
->visible(function() { ->visible(function () {
return Filament::auth()->user()->can('view export alert mail rule'); return Filament::auth()->user()->can('view export alert mail rule');
}), }),
]); ]);

View File

@@ -9,16 +9,16 @@ use App\Models\Block;
use App\Models\Plant; use App\Models\Plant;
use Filament\Facades\Filament; use Filament\Facades\Filament;
use Filament\Forms; use Filament\Forms;
use Filament\Forms\Components\Section;
use Filament\Forms\Form; use Filament\Forms\Form;
use Filament\Forms\Get; use Filament\Forms\Get;
use Filament\Resources\Resource; use Filament\Resources\Resource;
use Filament\Tables; use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction; use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Table; use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope; use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Forms\Components\Section;
use Filament\Tables\Actions\ExportAction;
use Illuminate\Validation\Rule; use Illuminate\Validation\Rule;
class BlockResource extends Resource class BlockResource extends Resource
@@ -46,12 +46,11 @@ class BlockResource extends Resource
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$nameId = $get('name'); $nameId = $get('name');
// Ensure `linestop_id` is not cleared // Ensure `linestop_id` is not cleared
if (!$nameId) { if (! $nameId) {
$set('bNameError', 'Scan the valid name.'); $set('bNameError', 'Scan the valid name.');
return; return;
} } else {
else
{
$set('bNameError', null); $set('bNameError', null);
} }
}) })
@@ -72,21 +71,21 @@ class BlockResource 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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->default(function () { ->default(function () {
return optional(Block::latest()->first())->plant_id; return optional(Block::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) {
$nameId = $get('plant_id'); $nameId = $get('plant_id');
// Ensure `linestop_id` is not cleared // Ensure `linestop_id` is not cleared
if (!$nameId) { if (! $nameId) {
$set('bPlantError', 'Please select a plant first.'); $set('bPlantError', 'Please select a plant first.');
return; return;
} } else {
else
{
$set('bPlantError', null); $set('bPlantError', null);
} }
}) })
@@ -117,10 +116,11 @@ class BlockResource 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('name') Tables\Columns\TextColumn::make('name')
//->unique(ignoreRecord: true) // ->unique(ignoreRecord: true)
->label('Block') ->label('Block')
->alignCenter() ->alignCenter()
->sortable() ->sortable()
@@ -167,14 +167,14 @@ class BlockResource extends Resource
->label('Import Blocks') ->label('Import Blocks')
->color('warning') ->color('warning')
->importer(BlockImporter::class) ->importer(BlockImporter::class)
->visible(function() { ->visible(function () {
return Filament::auth()->user()->can('view import block'); return Filament::auth()->user()->can('view import block');
}), }),
ExportAction::make() ExportAction::make()
->label('Export Blocks') ->label('Export Blocks')
->color('warning') ->color('warning')
->exporter(BlockExporter::class) ->exporter(BlockExporter::class)
->visible(function() { ->visible(function () {
return Filament::auth()->user()->can('view export block'); return Filament::auth()->user()->can('view export block');
}), }),
]); ]);

View File

@@ -43,7 +43,7 @@ class CharacteristicValueResource 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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->reactive() ->reactive()
->afterStateUpdated(function ($state, $set, callable $get) { ->afterStateUpdated(function ($state, $set, callable $get) {
@@ -296,7 +296,7 @@ class CharacteristicValueResource 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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->reactive() ->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {

View File

@@ -5,7 +5,6 @@ namespace App\Filament\Resources;
use App\Filament\Exports\CheckPointNameExporter; use App\Filament\Exports\CheckPointNameExporter;
use App\Filament\Imports\CheckPointNameImporter; use App\Filament\Imports\CheckPointNameImporter;
use App\Filament\Resources\CheckPointNameResource\Pages; use App\Filament\Resources\CheckPointNameResource\Pages;
use App\Filament\Resources\CheckPointNameResource\RelationManagers;
use App\Models\CheckPointName; use App\Models\CheckPointName;
use App\Models\Plant; use App\Models\Plant;
use Filament\Facades\Filament; use Filament\Facades\Filament;
@@ -42,20 +41,20 @@ class CheckPointNameResource 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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->default(function () { ->default(function () {
return optional(CheckPointName::where('created_by', Filament::auth()->user()?->name)->latest()->first())->plant_id; return optional(CheckPointName::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('cPnPlantError', 'Please select a plant first.'); $set('cPnPlantError', 'Please select a plant first.');
return; return;
} } else {
else
{
$set('cPnPlantError', null); $set('cPnPlantError', null);
$set('created_by', Filament::auth()->user()?->name); $set('created_by', Filament::auth()->user()?->name);
} }
@@ -100,6 +99,7 @@ class CheckPointNameResource 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')
@@ -156,14 +156,14 @@ class CheckPointNameResource extends Resource
->label('Import Check Point Names') ->label('Import Check Point Names')
->color('warning') ->color('warning')
->importer(CheckPointNameImporter::class) ->importer(CheckPointNameImporter::class)
->visible(function() { ->visible(function () {
return Filament::auth()->user()->can('view import check point name'); return Filament::auth()->user()->can('view import check point name');
}), }),
ExportAction::make() ExportAction::make()
->label('Export Check Point Names') ->label('Export Check Point Names')
->color('warning') ->color('warning')
->exporter(CheckPointNameExporter::class) ->exporter(CheckPointNameExporter::class)
->visible(function() { ->visible(function () {
return Filament::auth()->user()->can('view export check point name'); return Filament::auth()->user()->can('view export check point name');
}), }),
]); ]);

View File

@@ -5,7 +5,6 @@ namespace App\Filament\Resources;
use App\Filament\Exports\CheckPointTimeExporter; use App\Filament\Exports\CheckPointTimeExporter;
use App\Filament\Imports\CheckPointTimeImporter; use App\Filament\Imports\CheckPointTimeImporter;
use App\Filament\Resources\CheckPointTimeResource\Pages; use App\Filament\Resources\CheckPointTimeResource\Pages;
use App\Filament\Resources\CheckPointTimeResource\RelationManagers;
use App\Models\CheckPointName; use App\Models\CheckPointName;
use App\Models\CheckPointTime; use App\Models\CheckPointTime;
use App\Models\Plant; use App\Models\Plant;
@@ -43,20 +42,20 @@ class CheckPointTimeResource 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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->default(function () { ->default(function () {
return optional(CheckPointTime::where('created_by', Filament::auth()->user()?->name)->latest()->first())->plant_id; return optional(CheckPointTime::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('cPtPlantError', 'Please select a plant first.'); $set('cPtPlantError', 'Please select a plant first.');
return; return;
} } else {
else
{
$set('cPtPlantError', null); $set('cPtPlantError', null);
$set('created_by', Filament::auth()->user()?->name); $set('created_by', Filament::auth()->user()?->name);
} }
@@ -80,15 +79,15 @@ class CheckPointTimeResource extends Resource
return Rule::unique('check_point_times', 'sequence_number') return Rule::unique('check_point_times', 'sequence_number')
->where('plant_id', $get('plant_id')) ->where('plant_id', $get('plant_id'))
->ignore($get('id')); ->ignore($get('id'));
//->where('check_point1_id', $get('check_point1_id')) // ->where('check_point1_id', $get('check_point1_id'))
//->where('check_point2_id', $get('check_point2_id')) // ->where('check_point2_id', $get('check_point2_id'))
}), }),
Forms\Components\Select::make('check_point1_id') Forms\Components\Select::make('check_point1_id')
->label('Check Point Name 1') ->label('Check Point Name 1')
// ->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 [];
} }
@@ -101,19 +100,19 @@ class CheckPointTimeResource extends Resource
->default(function () { ->default(function () {
return optional(CheckPointTime::where('created_by', Filament::auth()->user()?->name)->latest()->first())->check_point1_id; return optional(CheckPointTime::where('created_by', Filament::auth()->user()?->name)->latest()->first())->check_point1_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) {
$checkPoint1 = $get('check_point1_id'); $checkPoint1 = $get('check_point1_id');
$checkPoint2 = $get('check_point2_id'); $checkPoint2 = $get('check_point2_id');
if (!$checkPoint1) { if (! $checkPoint1) {
$set('cPtCheckPoint1Error', 'Please select a check point 1 first.'); $set('cPtCheckPoint1Error', 'Please select a check point 1 first.');
return; return;
} } else {
else
{
if ($checkPoint2 && $checkPoint1 == $checkPoint2) { if ($checkPoint2 && $checkPoint1 == $checkPoint2) {
$set('cPtCheckPoint1Error', 'Duplicate check point 2 found.'); $set('cPtCheckPoint1Error', 'Duplicate check point 2 found.');
$set('check_point2_id', null); $set('check_point2_id', null);
return; return;
} }
$set('cPtCheckPoint1Error', null); $set('cPtCheckPoint1Error', null);
@@ -131,7 +130,7 @@ class CheckPointTimeResource 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,19 +143,19 @@ class CheckPointTimeResource extends Resource
->default(function () { ->default(function () {
return optional(CheckPointTime::where('created_by', Filament::auth()->user()?->name)->latest()->first())->check_point2_id; return optional(CheckPointTime::where('created_by', Filament::auth()->user()?->name)->latest()->first())->check_point2_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) {
$checkPoint1 = $get('check_point1_id'); $checkPoint1 = $get('check_point1_id');
$checkPoint2 = $get('check_point2_id'); $checkPoint2 = $get('check_point2_id');
if (!$checkPoint2) { if (! $checkPoint2) {
$set('cPtCheckPoint2Error', 'Please select a check point 2 first.'); $set('cPtCheckPoint2Error', 'Please select a check point 2 first.');
return; return;
} } else {
else
{
if ($checkPoint1 && $checkPoint1 == $checkPoint2) { if ($checkPoint1 && $checkPoint1 == $checkPoint2) {
$set('cPtCheckPoint2Error', 'Duplicate check point 2 found.'); $set('cPtCheckPoint2Error', 'Duplicate check point 2 found.');
$set('check_point2_id', null); $set('check_point2_id', null);
return; return;
} }
$set('cPtCheckPoint1Error', null); $set('cPtCheckPoint1Error', null);
@@ -185,32 +184,30 @@ class CheckPointTimeResource extends Resource
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$timeLapse = $state; $timeLapse = $state;
$timeLapseCushioning = $get('time_lapse_cushioning'); $timeLapseCushioning = $get('time_lapse_cushioning');
if (!$timeLapse) { if (! $timeLapse) {
$set('cPtTimeLapseError', 'Please enter a valid time lapse!'); $set('cPtTimeLapseError', 'Please enter a valid time lapse!');
$set('time_lapse_cushioning', null); $set('time_lapse_cushioning', null);
$set('min_cushioning', null); $set('min_cushioning', null);
$set('max_cushioning', null); $set('max_cushioning', null);
return; return;
} } elseif (! $timeLapseCushioning) {
elseif(!$timeLapseCushioning)
{
// $set('cPtTimeLapseError', 'Please enter a valid time lapse cushioning!'); // $set('cPtTimeLapseError', 'Please enter a valid time lapse cushioning!');
$set('time_lapse_cushioning', 1); $set('time_lapse_cushioning', 1);
$set('cPtTimeLapseError', null); $set('cPtTimeLapseError', null);
$set('min_cushioning', $timeLapse - 1); $set('min_cushioning', $timeLapse - 1);
$set('max_cushioning', $timeLapse + 1); $set('max_cushioning', $timeLapse + 1);
$set('created_by', Filament::auth()->user()?->name); $set('created_by', Filament::auth()->user()?->name);
return; return;
} } elseif ($timeLapseCushioning > $timeLapse) {
elseif ($timeLapseCushioning > $timeLapse) {
$set('cPtTimeLapseError', 'Must be greater than or equal to time lapse cushioning!'); $set('cPtTimeLapseError', 'Must be greater than or equal to time lapse cushioning!');
$set('time_lapse_cushioning', null); $set('time_lapse_cushioning', null);
$set('min_cushioning', null); $set('min_cushioning', null);
$set('max_cushioning', null); $set('max_cushioning', null);
return; return;
} } else {
else
{
$set('cPtTimeLapseError', null); $set('cPtTimeLapseError', null);
$set('cPtTimeLapseCushError', null); $set('cPtTimeLapseCushError', null);
$set('min_cushioning', $timeLapse - $timeLapseCushioning); $set('min_cushioning', $timeLapse - $timeLapseCushioning);
@@ -233,32 +230,30 @@ class CheckPointTimeResource extends Resource
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$timeLapse = $get('time_lapse'); $timeLapse = $get('time_lapse');
$timeLapseCushioning = $state; $timeLapseCushioning = $state;
if (!$timeLapse) { if (! $timeLapse) {
$set('cPtTimeLapseCushError', 'Please enter a valid time lapse first.'); $set('cPtTimeLapseCushError', 'Please enter a valid time lapse first.');
$set('time_lapse_cushioning', null); $set('time_lapse_cushioning', null);
$set('min_cushioning', null); $set('min_cushioning', null);
$set('max_cushioning', null); $set('max_cushioning', null);
return; return;
} } elseif (! $timeLapseCushioning) {
elseif(!$timeLapseCushioning)
{
// $set('cPtTimeLapseCushError', 'Please enter a valid time lapse cushioning!'); // $set('cPtTimeLapseCushError', 'Please enter a valid time lapse cushioning!');
$set('time_lapse_cushioning', 1); $set('time_lapse_cushioning', 1);
$set('cPtTimeLapseCushError', null); $set('cPtTimeLapseCushError', null);
$set('min_cushioning', $timeLapse - 1); $set('min_cushioning', $timeLapse - 1);
$set('max_cushioning', $timeLapse + 1); $set('max_cushioning', $timeLapse + 1);
$set('created_by', Filament::auth()->user()?->name); $set('created_by', Filament::auth()->user()?->name);
return; return;
} } elseif ($timeLapseCushioning > $timeLapse) {
elseif ($timeLapseCushioning > $timeLapse) {
$set('cPtTimeLapseCushError', 'Must be less than or equal to time lapse!'); $set('cPtTimeLapseCushError', 'Must be less than or equal to time lapse!');
$set('time_lapse_cushioning', null); $set('time_lapse_cushioning', null);
$set('min_cushioning', null); $set('min_cushioning', null);
$set('max_cushioning', null); $set('max_cushioning', null);
return; return;
} } else {
else
{
$set('cPtTimeLapseError', null); $set('cPtTimeLapseError', null);
$set('cPtTimeLapseCushError', null); $set('cPtTimeLapseCushError', null);
$set('min_cushioning', $timeLapse - $timeLapseCushioning); $set('min_cushioning', $timeLapse - $timeLapseCushioning);
@@ -308,6 +303,7 @@ class CheckPointTimeResource 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')
@@ -387,14 +383,14 @@ class CheckPointTimeResource extends Resource
->label('Import Check Point Times') ->label('Import Check Point Times')
->color('warning') ->color('warning')
->importer(CheckPointTimeImporter::class) ->importer(CheckPointTimeImporter::class)
->visible(function() { ->visible(function () {
return Filament::auth()->user()->can('view import check point time'); return Filament::auth()->user()->can('view import check point time');
}), }),
ExportAction::make() ExportAction::make()
->label('Export Check Point Times') ->label('Export Check Point Times')
->color('warning') ->color('warning')
->exporter(CheckPointTimeExporter::class) ->exporter(CheckPointTimeExporter::class)
->visible(function() { ->visible(function () {
return Filament::auth()->user()->can('view export check point time'); return Filament::auth()->user()->can('view export check point time');
}), }),
]); ]);

View File

@@ -37,7 +37,7 @@ class ClassCharacteristicResource 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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->required(), ->required(),
Forms\Components\Select::make('item_id') Forms\Components\Select::make('item_id')

View File

@@ -5,7 +5,6 @@ namespace App\Filament\Resources;
use App\Filament\Exports\ConfigurationExporter; use App\Filament\Exports\ConfigurationExporter;
use App\Filament\Imports\ConfigurationImporter; use App\Filament\Imports\ConfigurationImporter;
use App\Filament\Resources\ConfigurationResource\Pages; use App\Filament\Resources\ConfigurationResource\Pages;
use App\Filament\Resources\ConfigurationResource\RelationManagers;
use App\Models\Configuration; use App\Models\Configuration;
use App\Models\Line; use App\Models\Line;
use App\Models\Plant; use App\Models\Plant;
@@ -15,18 +14,20 @@ use Filament\Forms\Form;
use Filament\Forms\Get; use Filament\Forms\Get;
use Filament\Resources\Resource; use Filament\Resources\Resource;
use Filament\Tables; use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Table; use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope; use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Actions\ExportAction;
class ConfigurationResource extends Resource class ConfigurationResource extends Resource
{ {
protected static ?string $model = Configuration::class; protected static ?string $model = Configuration::class;
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack'; protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $navigationGroup = 'Master Entries'; protected static ?string $navigationGroup = 'Master Entries';
protected static ?int $navigationSort = 10; protected static ?int $navigationSort = 10;
public static function form(Form $form): Form public static function form(Form $form): Form
@@ -40,20 +41,20 @@ class ConfigurationResource 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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->default(function () { ->default(function () {
return optional(Configuration::latest()->first())->plant_id; return optional(Configuration::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('cPlantError', 'Please select a plant first.'); $set('cPlantError', 'Please select a plant first.');
return; return;
} } else {
else
{
$set('cPlantError', null); $set('cPlantError', null);
} }
}) })
@@ -68,7 +69,7 @@ class ConfigurationResource extends Resource
->required() ->required()
->reactive() ->reactive()
->options(function (callable $get) { ->options(function (callable $get) {
if (!$get('plant_id')) { if (! $get('plant_id')) {
return []; return [];
} }
@@ -79,15 +80,14 @@ class ConfigurationResource extends Resource
->default(function () { ->default(function () {
return optional(Configuration::latest()->first())->line_id; return optional(Configuration::latest()->first())->line_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) {
$lineId = $get('line_id'); $lineId = $get('line_id');
if (!$lineId) { if (! $lineId) {
$set('cLineError', 'Please select a line first.'); $set('cLineError', 'Please select a line first.');
return; return;
} } else {
else
{
$set('cLineError', null); $set('cLineError', null);
} }
}) })
@@ -124,6 +124,7 @@ class ConfigurationResource 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('plant.name') Tables\Columns\TextColumn::make('plant.name')
@@ -186,14 +187,14 @@ class ConfigurationResource extends Resource
->label('Import Configurations') ->label('Import Configurations')
->color('warning') ->color('warning')
->importer(ConfigurationImporter::class) ->importer(ConfigurationImporter::class)
->visible(function() { ->visible(function () {
return Filament::auth()->user()->can('view import configuration'); return Filament::auth()->user()->can('view import configuration');
}), }),
ExportAction::make() ExportAction::make()
->label('Export Configurations') ->label('Export Configurations')
->color('warning') ->color('warning')
->exporter(ConfigurationExporter::class) ->exporter(ConfigurationExporter::class)
->visible(function() { ->visible(function () {
return Filament::auth()->user()->can('view export configuration'); return Filament::auth()->user()->can('view export configuration');
}), }),
]); ]);

View File

@@ -5,26 +5,26 @@ namespace App\Filament\Resources;
use App\Filament\Exports\DeviceMasterExporter; use App\Filament\Exports\DeviceMasterExporter;
use App\Filament\Imports\DeviceMasterImporter; use App\Filament\Imports\DeviceMasterImporter;
use App\Filament\Resources\DeviceMasterResource\Pages; use App\Filament\Resources\DeviceMasterResource\Pages;
use App\Filament\Resources\DeviceMasterResource\RelationManagers;
use App\Models\DeviceMaster; use App\Models\DeviceMaster;
use App\Models\Plant; use App\Models\Plant;
use Filament\Facades\Filament; use Filament\Facades\Filament;
use Filament\Forms; use Filament\Forms;
use Filament\Forms\Components\Section;
use Filament\Forms\Form; use Filament\Forms\Form;
use Filament\Resources\Resource; use Filament\Resources\Resource;
use Filament\Tables; use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Table; use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope; use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Forms\Components\Section;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Actions\ExportAction;
class DeviceMasterResource extends Resource class DeviceMasterResource extends Resource
{ {
protected static ?string $model = DeviceMaster::class; protected static ?string $model = DeviceMaster::class;
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack'; protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $navigationGroup = 'Power House'; protected static ?string $navigationGroup = 'Power House';
public static function form(Form $form): Form public static function form(Form $form): Form
@@ -38,7 +38,8 @@ class DeviceMasterResource extends Resource
->relationship('plant', 'name') ->relationship('plant', 'name')
->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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->required(), ->required(),
Forms\Components\TextInput::make('name') Forms\Components\TextInput::make('name')
@@ -65,6 +66,7 @@ class DeviceMasterResource 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('plant.name') Tables\Columns\TextColumn::make('plant.name')
@@ -120,14 +122,14 @@ class DeviceMasterResource extends Resource
->label('Import Device Masters') ->label('Import Device Masters')
->color('warning') ->color('warning')
->importer(DeviceMasterImporter::class) ->importer(DeviceMasterImporter::class)
->visible(function() { ->visible(function () {
return Filament::auth()->user()->can('view import device master'); return Filament::auth()->user()->can('view import device master');
}), }),
ExportAction::make() ExportAction::make()
->label('Export Device Masters') ->label('Export Device Masters')
->color('warning') ->color('warning')
->exporter(DeviceMasterExporter::class) ->exporter(DeviceMasterExporter::class)
->visible(function() { ->visible(function () {
return Filament::auth()->user()->can('view export device master'); return Filament::auth()->user()->can('view export device master');
}), }),
]); ]);

View File

@@ -39,7 +39,7 @@ class EbReadingResource 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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->required(), ->required(),
Forms\Components\TextInput::make('lcd_segment_check') Forms\Components\TextInput::make('lcd_segment_check')
@@ -336,7 +336,7 @@ class EbReadingResource 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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->reactive() ->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {

View File

@@ -5,25 +5,24 @@ namespace App\Filament\Resources;
use App\Filament\Exports\EquipmentMasterExporter; use App\Filament\Exports\EquipmentMasterExporter;
use App\Filament\Imports\EquipmentMasterImporter; use App\Filament\Imports\EquipmentMasterImporter;
use App\Filament\Resources\EquipmentMasterResource\Pages; use App\Filament\Resources\EquipmentMasterResource\Pages;
use App\Filament\Resources\EquipmentMasterResource\RelationManagers;
use App\Models\EquipmentMaster; use App\Models\EquipmentMaster;
use App\Models\Plant; use App\Models\Plant;
use Carbon\Carbon; use Carbon\Carbon;
use Filament\Forms\Components\Actions\Action; use Filament\Facades\Filament;
use Filament\Forms; use Filament\Forms;
use Filament\Forms\Components\Actions\Action;
use Filament\Forms\Form; use Filament\Forms\Form;
use Filament\Notifications\Notification;
use Filament\Resources\Resource; use Filament\Resources\Resource;
use Filament\Tables; use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Table; use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope; use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Facades\Filament; use Illuminate\Validation\Rule;
use Filament\Notifications\Notification;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Actions\ExportAction;
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile; use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
use Storage; use Storage;
use Illuminate\Validation\Rule;
class EquipmentMasterResource extends Resource class EquipmentMasterResource extends Resource
{ {
@@ -45,11 +44,12 @@ class EquipmentMasterResource extends Resource
->relationship('plant', 'name') ->relationship('plant', 'name')
->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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->required(), ->required(),
Forms\Components\Select::make('machine_id') Forms\Components\Select::make('machine_id')
//->relationship('machine', 'name') // ->relationship('machine', 'name')
->label('Work Center') ->label('Work Center')
->reactive() ->reactive()
->options(function (callable $get) { ->options(function (callable $get) {
@@ -57,6 +57,7 @@ class EquipmentMasterResource extends Resource
if (empty($plantId)) { if (empty($plantId)) {
return []; return [];
} }
return \App\Models\Machine::where('plant_id', $plantId)->pluck('work_center', 'id'); return \App\Models\Machine::where('plant_id', $plantId)->pluck('work_center', 'id');
}) })
->required(), ->required(),
@@ -93,7 +94,7 @@ class EquipmentMasterResource extends Resource
$set('attachment', null); $set('attachment', null);
} }
}), }),
//->afterStateUpdated(function ($state, callable $set) { // ->afterStateUpdated(function ($state, callable $set) {
// if (! $state) { // if (! $state) {
// return; // return;
// } // }
@@ -285,15 +286,15 @@ class EquipmentMasterResource extends Resource
->title('PDF uploaded successfully') ->title('PDF uploaded successfully')
->success() ->success()
->send(); ->send();
return; return;
} }
} } else {
else
{
Notification::make() Notification::make()
->title('No file selected to upload') ->title('No file selected to upload')
->warning() ->warning()
->send(); ->send();
return; return;
} }
}), }),
@@ -303,11 +304,12 @@ class EquipmentMasterResource extends Resource
->action(function ($get) { ->action(function ($get) {
$equipmentNumber = $get('equipment_number'); $equipmentNumber = $get('equipment_number');
if (!$equipmentNumber) { if (! $equipmentNumber) {
Notification::make() Notification::make()
->title('No equipment number entered') ->title('No equipment number entered')
->danger() ->danger()
->send(); ->send();
return; return;
} }
@@ -321,11 +323,12 @@ class EquipmentMasterResource extends Resource
} }
} }
if (!$fileToDownload) { if (! $fileToDownload) {
Notification::make() Notification::make()
->title('PDF not found for this equipment') ->title('PDF not found for this equipment')
->danger() ->danger()
->send(); ->send();
return; return;
} }
@@ -342,7 +345,6 @@ class EquipmentMasterResource extends Resource
]); ]);
} }
public static function table(Table $table): Table public static function table(Table $table): Table
{ {
return $table return $table
@@ -353,6 +355,7 @@ class EquipmentMasterResource 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('plant.name') Tables\Columns\TextColumn::make('plant.name')
@@ -449,14 +452,14 @@ class EquipmentMasterResource extends Resource
->label('Import Equipment Masters') ->label('Import Equipment Masters')
->color('warning') ->color('warning')
->importer(EquipmentMasterImporter::class) ->importer(EquipmentMasterImporter::class)
->visible(function() { ->visible(function () {
return Filament::auth()->user()->can('view import equipment master'); return Filament::auth()->user()->can('view import equipment master');
}), }),
ExportAction::make() ExportAction::make()
->label('Export Equipment Masters') ->label('Export Equipment Masters')
->color('warning') ->color('warning')
->exporter(EquipmentMasterExporter::class) ->exporter(EquipmentMasterExporter::class)
->visible(function() { ->visible(function () {
return Filament::auth()->user()->can('view export equipment master'); return Filament::auth()->user()->can('view export equipment master');
}), }),
]); ]);
@@ -489,25 +492,22 @@ class EquipmentMasterResource extends Resource
protected static function calculateNextCalibrationDate(?string $startDateTime, ?string $durationDays): ?string protected static function calculateNextCalibrationDate(?string $startDateTime, ?string $durationDays): ?string
{ {
if (!$startDateTime || !$durationDays) { if (! $startDateTime || ! $durationDays) {
return null; return null;
} }
try try {
{
$startDateTimeCarbon = Carbon::parse($startDateTime); $startDateTimeCarbon = Carbon::parse($startDateTime);
$durationDays = str_replace(',', '.', $durationDays); $durationDays = str_replace(',', '.', $durationDays);
if(!is_numeric($durationDays)) if (! is_numeric($durationDays)) {
{
return null; return null;
} }
$nextCalibrationDate = $startDateTimeCarbon->addDays(floatval($durationDays)); $nextCalibrationDate = $startDateTimeCarbon->addDays(floatval($durationDays));
return $nextCalibrationDate->format('Y-m-d H:i:s'); return $nextCalibrationDate->format('Y-m-d H:i:s');
} } catch (\Exception $e) {
catch (\Exception $e)
{
return null; return null;
} }
} }

View File

@@ -5,33 +5,28 @@ namespace App\Filament\Resources;
use App\Filament\Exports\GrMasterExporter; use App\Filament\Exports\GrMasterExporter;
use App\Filament\Imports\GrMasterImporter; use App\Filament\Imports\GrMasterImporter;
use App\Filament\Resources\GrMasterResource\Pages; use App\Filament\Resources\GrMasterResource\Pages;
use App\Filament\Resources\GrMasterResource\RelationManagers;
use App\Models\GrMaster; use App\Models\GrMaster;
use App\Models\Item; use App\Models\Item;
use App\Models\Plant; use App\Models\Plant;
use Filament\Facades\Filament; use Filament\Facades\Filament;
use Filament\Forms; use Filament\Forms;
use Filament\Forms\Components\Actions\Action;
use Filament\Forms\Form; use Filament\Forms\Form;
use Filament\Notifications\Notification;
use Filament\Resources\Resource; use Filament\Resources\Resource;
use Filament\Tables; use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Table; use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope; use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Notifications\Notification;
use Filament\Forms\Components\Actions\Action;
use Storage;
use Smalot\PdfParser\Parser;
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Actions\ExportAction;
use Illuminate\Validation\Rule; use Illuminate\Validation\Rule;
use thiagoalessio\TesseractOCR\TesseractOCR; use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
use setasign\Fpdi\Fpdi; use setasign\Fpdi\Fpdi;
use setasign\Fpdi\PdfReader;
use SimpleSoftwareIO\QrCode\Facades\QrCode; use SimpleSoftwareIO\QrCode\Facades\QrCode;
use Smalot\PdfParser\Parser;
use Storage;
use thiagoalessio\TesseractOCR\TesseractOCR;
class GrMasterResource extends Resource class GrMasterResource extends Resource
{ {
@@ -39,6 +34,8 @@ class GrMasterResource extends Resource
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack'; protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $navigationGroup = 'Process Order';
public static function form(Form $form): Form public static function form(Form $form): Form
{ {
return $form return $form
@@ -49,12 +46,13 @@ class GrMasterResource extends Resource
->relationship('plant', 'name') ->relationship('plant', 'name')
->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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->required(), ->required(),
Forms\Components\Select::make('item_id') Forms\Components\Select::make('item_id')
->label('Item Code') ->label('Item Code')
//->relationship('item', 'id') // ->relationship('item', 'id')
->reactive() ->reactive()
->searchable() ->searchable()
->options(function (callable $get) { ->options(function (callable $get) {
@@ -62,6 +60,7 @@ class GrMasterResource extends Resource
if (empty($plantId)) { if (empty($plantId)) {
return []; return [];
} }
return Item::where('plant_id', $plantId)->pluck('code', 'id'); return Item::where('plant_id', $plantId)->pluck('code', 'id');
}) })
->required(), ->required(),
@@ -91,8 +90,7 @@ class GrMasterResource extends Resource
->action(function ($get, callable $set) { ->action(function ($get, callable $set) {
$uploadedFiles = $get('attachment'); $uploadedFiles = $get('attachment');
if (is_array($uploadedFiles) && count($uploadedFiles) > 0) if (is_array($uploadedFiles) && count($uploadedFiles) > 0) {
{
$uploaded = reset($uploadedFiles); $uploaded = reset($uploadedFiles);
if ($uploaded instanceof TemporaryUploadedFile) { if ($uploaded instanceof TemporaryUploadedFile) {
@@ -100,8 +98,8 @@ class GrMasterResource extends Resource
$safeName = preg_replace('/[^A-Za-z0-9_\-]/', '_', $grNumber); $safeName = preg_replace('/[^A-Za-z0-9_\-]/', '_', $grNumber);
// $originalName = $uploaded->getClientOriginalName(); // $originalName = $uploaded->getClientOriginalName();
// $path = 'uploads/GRNumber/' . $originalName; // $path = 'uploads/GRNumber/' . $originalName;
$finalFileName = $safeName . '.pdf'; $finalFileName = $safeName.'.pdf';
$finalPath = 'uploads/GRNumber/' . $finalFileName; $finalPath = 'uploads/GRNumber/'.$finalFileName;
if (Storage::disk('local')->exists($finalPath)) { if (Storage::disk('local')->exists($finalPath)) {
Notification::make() Notification::make()
@@ -109,6 +107,7 @@ class GrMasterResource extends Resource
->body("The file '{$finalFileName}' already exists in uploads/GRNumber.") ->body("The file '{$finalFileName}' already exists in uploads/GRNumber.")
->warning() ->warning()
->send(); ->send();
return; // Stop here return; // Stop here
} }
@@ -118,15 +117,14 @@ class GrMasterResource extends Resource
'local' 'local'
); );
// $fullPath = storage_path('app/' . $storedPath); // $fullPath = storage_path('app/' . $storedPath);
$fullPath = storage_path('app/private/' . $storedPath); $fullPath = storage_path('app/private/'.$storedPath);
$parser = new Parser(); $parser = new Parser;
//$pdf = $parser->parseContent(file_get_contents($uploaded->getRealPath())); // $pdf = $parser->parseContent(file_get_contents($uploaded->getRealPath()));
$pdf = $parser->parseFile($fullPath); $pdf = $parser->parseFile($fullPath);
$text = $pdf->getText(); $text = $pdf->getText();
//dd($text); // dd($text);
if (preg_match('/Item code\s*:\s*(\S+)/i', $text, $matches)) { if (preg_match('/Item code\s*:\s*(\S+)/i', $text, $matches)) {
$item1 = $matches[1]; $item1 = $matches[1];
@@ -136,8 +134,7 @@ class GrMasterResource extends Resource
// $item2 = $matches[1]; // $item2 = $matches[1];
// dd($item2); // dd($item2);
// } // }
else else {
{
Notification::make() Notification::make()
->title('Item Code Not Found') ->title('Item Code Not Found')
->body('Could not find Item code in uploaded PDF.') ->body('Could not find Item code in uploaded PDF.')
@@ -147,6 +144,7 @@ class GrMasterResource extends Resource
if (Storage::disk('local')->exists($storedPath)) { if (Storage::disk('local')->exists($storedPath)) {
Storage::disk('local')->delete($storedPath); Storage::disk('local')->delete($storedPath);
} }
return; return;
} }
@@ -160,21 +158,19 @@ class GrMasterResource extends Resource
$plant = Plant::find($plant); $plant = Plant::find($plant);
if ($item) if ($item) {
{
$itemCode = $item->code; $itemCode = $item->code;
} } else {
else
{
$itemCode = null; $itemCode = null;
Notification::make() Notification::make()
->title('Item Not Found') ->title('Item Not Found')
->body("Item not found in uploaded pdf.") ->body('Item not found in uploaded pdf.')
->warning() ->warning()
->send(); ->send();
if (Storage::disk('local')->exists($storedPath)) { if (Storage::disk('local')->exists($storedPath)) {
Storage::disk('local')->delete($storedPath); Storage::disk('local')->delete($storedPath);
} }
return; return;
} }
@@ -184,17 +180,15 @@ class GrMasterResource extends Resource
'local' 'local'
); );
if($itemCode == $item1) if ($itemCode == $item1) {
{
Notification::make() Notification::make()
->title('Success') ->title('Success')
->body("Gr Number '$processOrder' PDF uploaded successfully.") ->body("Gr Number '$processOrder' PDF uploaded successfully.")
->success() ->success()
->send(); ->send();
return; return;
} } else {
else
{
Notification::make() Notification::make()
->title('Item Code not matched') ->title('Item Code not matched')
->body("Item Code: {$item->code} not matched with the uploaded pdf code $item1.") ->body("Item Code: {$item->code} not matched with the uploaded pdf code $item1.")
@@ -204,16 +198,16 @@ class GrMasterResource extends Resource
if (Storage::disk('local')->exists($storedPath)) { if (Storage::disk('local')->exists($storedPath)) {
Storage::disk('local')->delete($storedPath); Storage::disk('local')->delete($storedPath);
} }
return; return;
} }
} }
} } else {
else
{
Notification::make() Notification::make()
->title('No file selected to upload') ->title('No file selected to upload')
->warning() ->warning()
->send(); ->send();
return; return;
} }
}), }),
@@ -393,11 +387,12 @@ class GrMasterResource extends Resource
->action(function ($get) { ->action(function ($get) {
$equipmentNumber = $get('gr_number'); $equipmentNumber = $get('gr_number');
if (!$equipmentNumber) { if (! $equipmentNumber) {
Notification::make() Notification::make()
->title('No GR Number entered') ->title('No GR Number entered')
->danger() ->danger()
->send(); ->send();
return; return;
} }
@@ -411,11 +406,12 @@ class GrMasterResource extends Resource
} }
} }
if (!$fileToDownload) { if (! $fileToDownload) {
Notification::make() Notification::make()
->title('PDF not found for this process order') ->title('PDF not found for this process order')
->danger() ->danger()
->send(); ->send();
return; return;
} }
@@ -440,6 +436,7 @@ class GrMasterResource 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('plant.name') Tables\Columns\TextColumn::make('plant.name')
@@ -506,14 +503,14 @@ class GrMasterResource extends Resource
->label('Import GR Masters') ->label('Import GR Masters')
->color('warning') ->color('warning')
->importer(GrMasterImporter::class) ->importer(GrMasterImporter::class)
->visible(function() { ->visible(function () {
return Filament::auth()->user()->can('view import gr master'); return Filament::auth()->user()->can('view import gr master');
}), }),
ExportAction::make() ExportAction::make()
->label('Export GR Masters') ->label('Export GR Masters')
->color('warning') ->color('warning')
->exporter(GrMasterExporter::class) ->exporter(GrMasterExporter::class)
->visible(function() { ->visible(function () {
return Filament::auth()->user()->can('view export gr master'); return Filament::auth()->user()->can('view export gr master');
}), }),
]); ]);

View File

@@ -5,7 +5,6 @@ namespace App\Filament\Resources;
use App\Filament\Exports\GuardNameExporter; use App\Filament\Exports\GuardNameExporter;
use App\Filament\Imports\GuardNameImporter; use App\Filament\Imports\GuardNameImporter;
use App\Filament\Resources\GuardNameResource\Pages; use App\Filament\Resources\GuardNameResource\Pages;
use App\Filament\Resources\GuardNameResource\RelationManagers;
use App\Models\GuardName; use App\Models\GuardName;
use App\Models\Plant; use App\Models\Plant;
use Filament\Facades\Filament; use Filament\Facades\Filament;
@@ -42,20 +41,20 @@ class GuardNameResource 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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->default(function () { ->default(function () {
return optional(GuardName::latest()->first())->plant_id; return optional(GuardName::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('GnError', 'Please select a plant first.'); $set('GnError', 'Please select a plant first.');
return; return;
} } else {
else
{
$set('GnError', null); $set('GnError', null);
$set('created_by', Filament::auth()->user()?->name); $set('created_by', Filament::auth()->user()?->name);
} }
@@ -113,6 +112,7 @@ class GuardNameResource 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')
@@ -169,14 +169,14 @@ class GuardNameResource extends Resource
->label('Import Guard Names') ->label('Import Guard Names')
->color('warning') ->color('warning')
->importer(GuardNameImporter::class) ->importer(GuardNameImporter::class)
->visible(function() { ->visible(function () {
return Filament::auth()->user()->can('view import guard name'); return Filament::auth()->user()->can('view import guard name');
}), }),
ExportAction::make() ExportAction::make()
->label('Export Guard Names') ->label('Export Guard Names')
->color('warning') ->color('warning')
->exporter(GuardNameExporter::class) ->exporter(GuardNameExporter::class)
->visible(function() { ->visible(function () {
return Filament::auth()->user()->can('view export guard name'); return Filament::auth()->user()->can('view export guard name');
}), }),
]); ]);

View File

@@ -53,7 +53,7 @@ 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::orderBy('code')->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;

View File

@@ -4,24 +4,21 @@ namespace App\Filament\Resources;
use App\Filament\Exports\InvoiceInTransitExporter; use App\Filament\Exports\InvoiceInTransitExporter;
use App\Filament\Resources\InvoiceInTransitResource\Pages; use App\Filament\Resources\InvoiceInTransitResource\Pages;
use App\Filament\Resources\InvoiceInTransitResource\RelationManagers;
use App\Models\InvoiceInTransit; use App\Models\InvoiceInTransit;
use App\Models\Plant; use App\Models\Plant;
use Filament\Facades\Filament; use Filament\Facades\Filament;
use Filament\Forms; use Filament\Forms;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Form; use Filament\Forms\Form;
use Filament\Notifications\Notification; use Filament\Notifications\Notification;
use Filament\Resources\Resource; use Filament\Resources\Resource;
use Filament\Tables; use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Table; use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope; use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Forms\Components\FileUpload;
use Storage;
use Maatwebsite\Excel\Facades\Excel; use Maatwebsite\Excel\Facades\Excel;
use Filament\Tables\Actions\ExportAction; use Storage;
use Carbon\Carbon;
use PhpOffice\PhpSpreadsheet\Shared\Date as ExcelDate;
class InvoiceInTransitResource extends Resource class InvoiceInTransitResource extends Resource
{ {
@@ -37,6 +34,11 @@ class InvoiceInTransitResource extends Resource
->schema([ ->schema([
Forms\Components\Select::make('plant_id') Forms\Components\Select::make('plant_id')
->relationship('plant', 'name') ->relationship('plant', 'name')
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->required(), ->required(),
Forms\Components\TextInput::make('receiving_plant') Forms\Components\TextInput::make('receiving_plant')
->label('Receiving Plant'), ->label('Receiving Plant'),
@@ -272,8 +274,7 @@ class InvoiceInTransitResource 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) {
@@ -305,7 +306,6 @@ class InvoiceInTransitResource extends Resource
$invalidLRBLAWDt = []; $invalidLRBLAWDt = [];
$invalidPenDay = []; $invalidPenDay = [];
foreach ($rows as $index => $row) { foreach ($rows as $index => $row) {
if ($index == 0) { if ($index == 0) {
continue; continue;
@@ -369,7 +369,7 @@ class InvoiceInTransitResource extends Resource
$plant = Plant::where('code', $plantCode)->first(); $plant = Plant::where('code', $plantCode)->first();
//$plantId = $plant->id; // $plantId = $plant->id;
} }
@@ -470,8 +470,7 @@ class InvoiceInTransitResource extends Resource
return; return;
} }
foreach ($rows as $index => $row) foreach ($rows as $index => $row) {
{
if ($index == 0) { if ($index == 0) {
continue; continue;
} }
@@ -504,8 +503,7 @@ class InvoiceInTransitResource extends Resource
throw new \Exception("Invalid plant code : '{$plantCode}'"); throw new \Exception("Invalid plant code : '{$plantCode}'");
} }
if (! empty($invoiceDt)) if (! empty($invoiceDt)) {
{
if (preg_match('/^\d{2}[-\/]\d{2}[-\/]\d{4}$/', $invoiceDt)) { if (preg_match('/^\d{2}[-\/]\d{2}[-\/]\d{4}$/', $invoiceDt)) {
[$day, $month, $year] = preg_split('/[-\/]/', $invoiceDt); [$day, $month, $year] = preg_split('/[-\/]/', $invoiceDt);
$formattedDate = "{$year}-{$month}-{$day}"; $formattedDate = "{$year}-{$month}-{$day}";
@@ -517,8 +515,7 @@ class InvoiceInTransitResource extends Resource
} else { } else {
$formattedDate = null; $formattedDate = null;
} }
if (! empty($LRBAWDt)) if (! empty($LRBAWDt)) {
{
if (preg_match('/^\d{2}[-\/]\d{2}[-\/]\d{4}$/', $LRBAWDt)) { if (preg_match('/^\d{2}[-\/]\d{2}[-\/]\d{4}$/', $LRBAWDt)) {
[$day, $month, $year] = preg_split('/[-\/]/', $LRBAWDt); [$day, $month, $year] = preg_split('/[-\/]/', $LRBAWDt);
$formattedDt = "{$year}-{$month}-{$day}"; $formattedDt = "{$year}-{$month}-{$day}";
@@ -530,8 +527,7 @@ class InvoiceInTransitResource extends Resource
} else { } else {
$formattedDt = null; $formattedDt = null;
} }
if (! empty($OBDDate)) if (! empty($OBDDate)) {
{
if (preg_match('/^\d{2}[-\/]\d{2}[-\/]\d{4}$/', $OBDDate)) { if (preg_match('/^\d{2}[-\/]\d{2}[-\/]\d{4}$/', $OBDDate)) {
[$day, $month, $year] = preg_split('/[-\/]/', $OBDDate); [$day, $month, $year] = preg_split('/[-\/]/', $OBDDate);
$formattedDate = "{$year}-{$month}-{$day}"; $formattedDate = "{$year}-{$month}-{$day}";
@@ -577,15 +573,15 @@ class InvoiceInTransitResource extends Resource
->body('Invoice in transit uploaded successfully!') ->body('Invoice in transit uploaded successfully!')
->success() ->success()
->send(); ->send();
return; return;
} } else {
else
{
Notification::make() Notification::make()
->title('Insertion Failed') ->title('Insertion Failed')
->body('Invoice in transit upload failed!') ->body('Invoice in transit upload failed!')
->success() ->success()
->send(); ->send();
return; return;
} }
} }

View File

@@ -56,7 +56,7 @@ class ItemResource 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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->default(function () { ->default(function () {
return optional(Item::latest()->first())->plant_id; return optional(Item::latest()->first())->plant_id;
@@ -251,7 +251,7 @@ class ItemResource 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)->orderBy('code')->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray(); return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->reactive() ->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get): void { ->afterStateUpdated(function ($state, callable $set, callable $get): void {
@@ -394,7 +394,7 @@ class ItemResource extends Resource
// // ->options(Plant::pluck('name', 'id')->toArray()) // Fetch plant names and IDs // // ->options(Plant::pluck('name', 'id')->toArray()) // Fetch plant names and IDs
// ->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::orderBy('code')->pluck('name', 'id')->toArray();
// }) // })
// ->label('Select Plant') // ->label('Select Plant')
// ->required() // ->required()

View File

@@ -5,23 +5,22 @@ namespace App\Filament\Resources;
use App\Filament\Exports\LineExporter; use App\Filament\Exports\LineExporter;
use App\Filament\Imports\LineImporter; use App\Filament\Imports\LineImporter;
use App\Filament\Resources\LineResource\Pages; use App\Filament\Resources\LineResource\Pages;
use App\Filament\Resources\LineResource\RelationManagers;
use App\Models\Line; use App\Models\Line;
use App\Models\Plant; use App\Models\Plant;
use App\Models\WorkGroupMaster; use App\Models\WorkGroupMaster;
use Filament\Facades\Filament; use Filament\Facades\Filament;
use Filament\Forms; use Filament\Forms;
use Filament\Forms\Components\Section;
use Filament\Forms\Form; use Filament\Forms\Form;
use Filament\Forms\Get; use Filament\Forms\Get;
use Filament\Forms\Set;
use Filament\Resources\Resource; use Filament\Resources\Resource;
use Filament\Tables; use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction; use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Table; use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope; use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Forms\Components\Section;
use Filament\Forms\Set;
use Filament\Tables\Actions\ExportAction;
use Illuminate\Validation\Rule; use Illuminate\Validation\Rule;
use Illuminate\Validation\Rules\Unique; use Illuminate\Validation\Rules\Unique;
@@ -48,22 +47,22 @@ class LineResource 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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->default(function () { ->default(function () {
return optional(Line::latest()->first())->plant_id; return optional(Line::latest()->first())->plant_id;
}) })
->disabled(fn (Get $get) => !empty($get('id'))) ->disabled(fn (Get $get) => ! empty($get('id')))
// ->afterStateUpdated(fn ($set) => $set('block_id', null) & $set('name', null) & $set('start_time', null) & $set('duration', null) & $set('end_time', null)) // ->afterStateUpdated(fn ($set) => $set('block_id', null) & $set('name', null) & $set('start_time', null) & $set('duration', null) & $set('end_time', null))
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id'); $plantId = $get('plant_id');
// Ensure `linestop_id` is not cleared // Ensure `linestop_id` is not cleared
if (!$plantId) { if (! $plantId) {
$set('lPlantError', 'Please select a plant first.'); $set('lPlantError', 'Please select a plant first.');
return; return;
} } else {
else
{
$set('lPlantError', null); $set('lPlantError', null);
} }
}) })
@@ -97,12 +96,11 @@ class LineResource extends Resource
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$lineNam = $get('name'); $lineNam = $get('name');
// Ensure `linestop_id` is not cleared // Ensure `linestop_id` is not cleared
if (!$lineNam) { if (! $lineNam) {
$set('lNameError', 'Scan the valid name.'); $set('lNameError', 'Scan the valid name.');
return; return;
} } else {
else
{
// $exists = Line::where('name', $lineNam) // $exists = Line::where('name', $lineNam)
// ->where('plant_id', $get('plant_id')) // ->where('plant_id', $get('plant_id'))
// ->exists(); // ->exists();
@@ -171,12 +169,11 @@ class LineResource extends Resource
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$lineTyp = $get('type'); $lineTyp = $get('type');
// Ensure `linestop_id` is not cleared // Ensure `linestop_id` is not cleared
if (!$lineTyp) { if (! $lineTyp) {
$set('lTypeError', 'Scan the valid type.'); $set('lTypeError', 'Scan the valid type.');
return; return;
} } else {
else
{
$set('lTypeError', null); $set('lTypeError', null);
} }
}) })
@@ -201,13 +198,13 @@ class LineResource extends Resource
]; ];
foreach ($partValidationColumns as $column) { foreach ($partValidationColumns as $column) {
$set($column . '_visible', false); $set($column.'_visible', false);
$set($column, null); $set($column, null);
} }
$partValidDispColumns = [ $partValidDispColumns = [
'work_group1_actual_id', 'work_group2_actual_id', 'work_group3_actual_id', 'work_group4_actual_id', 'work_group5_actual_id', 'work_group1_actual_id', 'work_group2_actual_id', 'work_group3_actual_id', 'work_group4_actual_id', 'work_group5_actual_id',
'work_group6_actual_id', 'work_group7_actual_id', 'work_group8_actual_id', 'work_group9_actual_id', 'work_group10_actual_id' 'work_group6_actual_id', 'work_group7_actual_id', 'work_group8_actual_id', 'work_group9_actual_id', 'work_group10_actual_id',
]; ];
foreach ($partValidDispColumns as $column) { foreach ($partValidDispColumns as $column) {
@@ -237,11 +234,11 @@ class LineResource extends Resource
// } // }
// } // }
// }), // }),
//->required(fn (callable $get) => $get('no_of_operation') >= 1), // ->required(fn (callable $get) => $get('no_of_operation') >= 1),
Forms\Components\TextInput::make('work_group1_actual_id') Forms\Components\TextInput::make('work_group1_actual_id')
->label('Work Group Center 1') ->label('Work Group Center 1')
->hidden(fn (callable $get) => !$get('work_group1_id_visible')) ->hidden(fn (callable $get) => ! $get('work_group1_id_visible'))
->default('') ->default('')
->reactive() ->reactive()
->required() ->required()
@@ -258,14 +255,16 @@ class LineResource extends Resource
if ($state == null || trim($state) == '') { if ($state == null || trim($state) == '') {
$set('work_group1_id_error', null); $set('work_group1_id_error', null);
$set('work_group1_id', null); $set('work_group1_id', null);
return; return;
} }
$set('work_group1_id_error', null); $set('work_group1_id_error', null);
$set('work_group1_id', null); $set('work_group1_id', null);
if (!$plantId) { if (! $plantId) {
$set('work_group1_id_error', 'Invalid plant name.'); $set('work_group1_id_error', 'Invalid plant name.');
return; return;
} }
@@ -273,8 +272,9 @@ class LineResource extends Resource
->where('name', $state) ->where('name', $state)
->first(); ->first();
if (!$workGroupRecord) { if (! $workGroupRecord) {
$set('work_group1_id_error', 'Work group does not exist for this plant in master.'); $set('work_group1_id_error', 'Work group does not exist for this plant in master.');
return; return;
} }
@@ -300,10 +300,9 @@ class LineResource extends Resource
->send(); ->send();
$set('work_group1_actual_id', ''); $set('work_group1_actual_id', '');
$set('work_group1_id', null); $set('work_group1_id', null);
return; return;
} } else {
else
{
$set('work_group1_id_error', null); $set('work_group1_id_error', null);
$set('work_group1_id', $workGroupRecord->id); $set('work_group1_id', $workGroupRecord->id);
} }
@@ -318,7 +317,7 @@ class LineResource extends Resource
Forms\Components\TextInput::make('work_group2_actual_id') Forms\Components\TextInput::make('work_group2_actual_id')
->label('Work Group Center 2') ->label('Work Group Center 2')
->hidden(fn (callable $get) => !$get('work_group2_id_visible')) ->hidden(fn (callable $get) => ! $get('work_group2_id_visible'))
->default('') ->default('')
->required() ->required()
->reactive() ->reactive()
@@ -335,14 +334,16 @@ class LineResource extends Resource
if ($state == null || trim($state) == '') { if ($state == null || trim($state) == '') {
$set('work_group2_id_error', null); $set('work_group2_id_error', null);
$set('work_group2_id', null); $set('work_group2_id', null);
return; return;
} }
$set('work_group2_id_error', null); $set('work_group2_id_error', null);
$set('work_group2_id', null); $set('work_group2_id', null);
if (!$plantId) { if (! $plantId) {
$set('work_group2_id_error', 'Invalid plant name.'); $set('work_group2_id_error', 'Invalid plant name.');
return; return;
} }
@@ -350,8 +351,9 @@ class LineResource extends Resource
->where('name', $state) ->where('name', $state)
->first(); ->first();
if (!$workGroupRecord) { if (! $workGroupRecord) {
$set('work_group2_id_error', 'Work group does not exist for this plant in master.'); $set('work_group2_id_error', 'Work group does not exist for this plant in master.');
return; return;
} }
@@ -372,10 +374,9 @@ class LineResource extends Resource
->send(); ->send();
$set('work_group2_actual_id', ''); $set('work_group2_actual_id', '');
$set('work_group2_id', null); $set('work_group2_id', null);
return; return;
} } else {
else
{
$set('work_group2_id_error', null); $set('work_group2_id_error', null);
$set('work_group2_id', $workGroupRecord->id); $set('work_group2_id', $workGroupRecord->id);
} }
@@ -390,7 +391,7 @@ class LineResource extends Resource
Forms\Components\TextInput::make('work_group3_actual_id') Forms\Components\TextInput::make('work_group3_actual_id')
->label('Work Group Center 3') ->label('Work Group Center 3')
->hidden(fn (callable $get) => !$get('work_group3_id_visible')) ->hidden(fn (callable $get) => ! $get('work_group3_id_visible'))
->default('') ->default('')
->required() ->required()
->reactive() ->reactive()
@@ -407,14 +408,16 @@ class LineResource extends Resource
if ($state == null || trim($state) == '') { if ($state == null || trim($state) == '') {
$set('work_group3_id_error', null); $set('work_group3_id_error', null);
$set('work_group3_id', null); $set('work_group3_id', null);
return; return;
} }
$set('work_group3_id_error', null); $set('work_group3_id_error', null);
$set('work_group3_id', null); $set('work_group3_id', null);
if (!$plantId) { if (! $plantId) {
$set('work_group3_id_error', 'Invalid plant name.'); $set('work_group3_id_error', 'Invalid plant name.');
return; return;
} }
@@ -422,8 +425,9 @@ class LineResource extends Resource
->where('name', $state) ->where('name', $state)
->first(); ->first();
if (!$workGroupRecord) { if (! $workGroupRecord) {
$set('work_group3_id_error', 'Work group does not exist for this plant in master.'); $set('work_group3_id_error', 'Work group does not exist for this plant in master.');
return; return;
} }
@@ -444,10 +448,9 @@ class LineResource extends Resource
->send(); ->send();
$set('work_group3_actual_id', ''); $set('work_group3_actual_id', '');
$set('work_group3_id', null); $set('work_group3_id', null);
return; return;
} } else {
else
{
$set('work_group3_id_error', null); $set('work_group3_id_error', null);
$set('work_group3_id', $workGroupRecord->id); $set('work_group3_id', $workGroupRecord->id);
} }
@@ -462,7 +465,7 @@ class LineResource extends Resource
Forms\Components\TextInput::make('work_group4_actual_id') Forms\Components\TextInput::make('work_group4_actual_id')
->label('Work Group Center 4') ->label('Work Group Center 4')
->hidden(fn (callable $get) => !$get('work_group4_id_visible')) ->hidden(fn (callable $get) => ! $get('work_group4_id_visible'))
->default('') ->default('')
->required() ->required()
->reactive() ->reactive()
@@ -479,14 +482,16 @@ class LineResource extends Resource
if ($state == null || trim($state) == '') { if ($state == null || trim($state) == '') {
$set('work_group4_id_error', null); $set('work_group4_id_error', null);
$set('work_group4_id', null); $set('work_group4_id', null);
return; return;
} }
$set('work_group4_id_error', null); $set('work_group4_id_error', null);
$set('work_group4_id', null); $set('work_group4_id', null);
if (!$plantId) { if (! $plantId) {
$set('work_group4_id_error', 'Invalid plant name.'); $set('work_group4_id_error', 'Invalid plant name.');
return; return;
} }
@@ -494,8 +499,9 @@ class LineResource extends Resource
->where('name', $state) ->where('name', $state)
->first(); ->first();
if (!$workGroupRecord) { if (! $workGroupRecord) {
$set('work_group4_id_error', 'Work group does not exist for this plant in master.'); $set('work_group4_id_error', 'Work group does not exist for this plant in master.');
return; return;
} }
@@ -516,10 +522,9 @@ class LineResource extends Resource
->send(); ->send();
$set('work_group4_actual_id', ''); $set('work_group4_actual_id', '');
$set('work_group4_id', null); $set('work_group4_id', null);
return; return;
} } else {
else
{
$set('work_group4_id_error', null); $set('work_group4_id_error', null);
$set('work_group4_id', $workGroupRecord->id); $set('work_group4_id', $workGroupRecord->id);
} }
@@ -534,7 +539,7 @@ class LineResource extends Resource
Forms\Components\TextInput::make('work_group5_actual_id') Forms\Components\TextInput::make('work_group5_actual_id')
->label('Work Group Center 5') ->label('Work Group Center 5')
->hidden(fn (callable $get) => !$get('work_group5_id_visible')) ->hidden(fn (callable $get) => ! $get('work_group5_id_visible'))
->default('') ->default('')
->required() ->required()
->reactive() ->reactive()
@@ -551,14 +556,16 @@ class LineResource extends Resource
if ($state == null || trim($state) == '') { if ($state == null || trim($state) == '') {
$set('work_group5_id_error', null); $set('work_group5_id_error', null);
$set('work_group5_id', null); $set('work_group5_id', null);
return; return;
} }
$set('work_group5_id_error', null); $set('work_group5_id_error', null);
$set('work_group5_id', null); $set('work_group5_id', null);
if (!$plantId) { if (! $plantId) {
$set('work_group5_id_error', 'Invalid plant name.'); $set('work_group5_id_error', 'Invalid plant name.');
return; return;
} }
@@ -566,8 +573,9 @@ class LineResource extends Resource
->where('name', $state) ->where('name', $state)
->first(); ->first();
if (!$workGroupRecord) { if (! $workGroupRecord) {
$set('work_group5_id_error', 'Work group does not exist for this plant in master.'); $set('work_group5_id_error', 'Work group does not exist for this plant in master.');
return; return;
} }
@@ -588,10 +596,9 @@ class LineResource extends Resource
->send(); ->send();
$set('work_group5_actual_id', ''); $set('work_group5_actual_id', '');
$set('work_group5_id', null); $set('work_group5_id', null);
return; return;
} } else {
else
{
$set('work_group5_id_error', null); $set('work_group5_id_error', null);
$set('work_group5_id', $workGroupRecord->id); $set('work_group5_id', $workGroupRecord->id);
} }
@@ -606,7 +613,7 @@ class LineResource extends Resource
Forms\Components\TextInput::make('work_group6_actual_id') Forms\Components\TextInput::make('work_group6_actual_id')
->label('Work Group Center 6') ->label('Work Group Center 6')
->hidden(fn (callable $get) => !$get('work_group6_id_visible')) ->hidden(fn (callable $get) => ! $get('work_group6_id_visible'))
->default('') ->default('')
->required() ->required()
->reactive() ->reactive()
@@ -623,14 +630,16 @@ class LineResource extends Resource
if ($state == null || trim($state) == '') { if ($state == null || trim($state) == '') {
$set('work_group6_id_error', null); $set('work_group6_id_error', null);
$set('work_group6_id', null); $set('work_group6_id', null);
return; return;
} }
$set('work_group6_id_error', null); $set('work_group6_id_error', null);
$set('work_group6_id', null); $set('work_group6_id', null);
if (!$plantId) { if (! $plantId) {
$set('work_group6_id_error', 'Invalid plant name.'); $set('work_group6_id_error', 'Invalid plant name.');
return; return;
} }
@@ -638,8 +647,9 @@ class LineResource extends Resource
->where('name', $state) ->where('name', $state)
->first(); ->first();
if (!$workGroupRecord) { if (! $workGroupRecord) {
$set('work_group6_id_error', 'Work group does not exist for this plant in master.'); $set('work_group6_id_error', 'Work group does not exist for this plant in master.');
return; return;
} }
@@ -660,10 +670,9 @@ class LineResource extends Resource
->send(); ->send();
$set('work_group6_actual_id', ''); $set('work_group6_actual_id', '');
$set('work_group6_id', null); $set('work_group6_id', null);
return; return;
} } else {
else
{
$set('work_group6_id_error', null); $set('work_group6_id_error', null);
$set('work_group6_id', $workGroupRecord->id); $set('work_group6_id', $workGroupRecord->id);
} }
@@ -678,7 +687,7 @@ class LineResource extends Resource
Forms\Components\TextInput::make('work_group7_actual_id') Forms\Components\TextInput::make('work_group7_actual_id')
->label('Work Group Center 7') ->label('Work Group Center 7')
->hidden(fn (callable $get) => !$get('work_group7_id_visible')) ->hidden(fn (callable $get) => ! $get('work_group7_id_visible'))
->default('') ->default('')
->required() ->required()
->reactive() ->reactive()
@@ -695,14 +704,16 @@ class LineResource extends Resource
if ($state == null || trim($state) == '') { if ($state == null || trim($state) == '') {
$set('work_group7_id_error', null); $set('work_group7_id_error', null);
$set('work_group7_id', null); $set('work_group7_id', null);
return; return;
} }
$set('work_group7_id_error', null); $set('work_group7_id_error', null);
$set('work_group7_id', null); $set('work_group7_id', null);
if (!$plantId) { if (! $plantId) {
$set('work_group7_id_error', 'Invalid plant name.'); $set('work_group7_id_error', 'Invalid plant name.');
return; return;
} }
@@ -710,8 +721,9 @@ class LineResource extends Resource
->where('name', $state) ->where('name', $state)
->first(); ->first();
if (!$workGroupRecord) { if (! $workGroupRecord) {
$set('work_group7_id_error', 'Work group does not exist for this plant in master.'); $set('work_group7_id_error', 'Work group does not exist for this plant in master.');
return; return;
} }
@@ -732,10 +744,9 @@ class LineResource extends Resource
->send(); ->send();
$set('work_group7_actual_id', ''); $set('work_group7_actual_id', '');
$set('work_group7_id', null); $set('work_group7_id', null);
return; return;
} } else {
else
{
$set('work_group7_id_error', null); $set('work_group7_id_error', null);
$set('work_group7_id', $workGroupRecord->id); $set('work_group7_id', $workGroupRecord->id);
} }
@@ -750,7 +761,7 @@ class LineResource extends Resource
Forms\Components\TextInput::make('work_group8_actual_id') Forms\Components\TextInput::make('work_group8_actual_id')
->label('Work Group Center 8') ->label('Work Group Center 8')
->hidden(fn (callable $get) => !$get('work_group8_id_visible')) ->hidden(fn (callable $get) => ! $get('work_group8_id_visible'))
->default('') ->default('')
->required() ->required()
->reactive() ->reactive()
@@ -767,14 +778,16 @@ class LineResource extends Resource
if ($state == null || trim($state) == '') { if ($state == null || trim($state) == '') {
$set('work_group8_id_error', null); $set('work_group8_id_error', null);
$set('work_group8_id', null); $set('work_group8_id', null);
return; return;
} }
$set('work_group8_id_error', null); $set('work_group8_id_error', null);
$set('work_group8_id', null); $set('work_group8_id', null);
if (!$plantId) { if (! $plantId) {
$set('work_group8_id_error', 'Invalid plant name.'); $set('work_group8_id_error', 'Invalid plant name.');
return; return;
} }
@@ -782,8 +795,9 @@ class LineResource extends Resource
->where('name', $state) ->where('name', $state)
->first(); ->first();
if (!$workGroupRecord) { if (! $workGroupRecord) {
$set('work_group8_id_error', 'Work group does not exist for this plant in master.'); $set('work_group8_id_error', 'Work group does not exist for this plant in master.');
return; return;
} }
@@ -804,10 +818,9 @@ class LineResource extends Resource
->send(); ->send();
$set('work_group8_actual_id', ''); $set('work_group8_actual_id', '');
$set('work_group8_id', null); $set('work_group8_id', null);
return; return;
} } else {
else
{
$set('work_group8_id_error', null); $set('work_group8_id_error', null);
$set('work_group8_id', $workGroupRecord->id); $set('work_group8_id', $workGroupRecord->id);
} }
@@ -822,7 +835,7 @@ class LineResource extends Resource
Forms\Components\TextInput::make('work_group9_actual_id') Forms\Components\TextInput::make('work_group9_actual_id')
->label('Work Group Center 9') ->label('Work Group Center 9')
->hidden(fn (callable $get) => !$get('work_group9_id_visible')) ->hidden(fn (callable $get) => ! $get('work_group9_id_visible'))
->default('') ->default('')
->required() ->required()
->reactive() ->reactive()
@@ -839,14 +852,16 @@ class LineResource extends Resource
if ($state == null || trim($state) == '') { if ($state == null || trim($state) == '') {
$set('work_group9_id_error', null); $set('work_group9_id_error', null);
$set('work_group9_id', null); $set('work_group9_id', null);
return; return;
} }
$set('work_group9_id_error', null); $set('work_group9_id_error', null);
$set('work_group9_id', null); $set('work_group9_id', null);
if (!$plantId) { if (! $plantId) {
$set('work_group9_id_error', 'Invalid plant name.'); $set('work_group9_id_error', 'Invalid plant name.');
return; return;
} }
@@ -854,8 +869,9 @@ class LineResource extends Resource
->where('name', $state) ->where('name', $state)
->first(); ->first();
if (!$workGroupRecord) { if (! $workGroupRecord) {
$set('work_group9_id_error', 'Work group does not exist for this plant in master.'); $set('work_group9_id_error', 'Work group does not exist for this plant in master.');
return; return;
} }
@@ -876,10 +892,9 @@ class LineResource extends Resource
->send(); ->send();
$set('work_group9_actual_id', ''); $set('work_group9_actual_id', '');
$set('work_group9_id', null); $set('work_group9_id', null);
return; return;
} } else {
else
{
$set('work_group9_id_error', null); $set('work_group9_id_error', null);
$set('work_group9_id', $workGroupRecord->id); $set('work_group9_id', $workGroupRecord->id);
} }
@@ -894,7 +909,7 @@ class LineResource extends Resource
Forms\Components\TextInput::make('work_group10_actual_id') Forms\Components\TextInput::make('work_group10_actual_id')
->label('Work Group Center 10') ->label('Work Group Center 10')
->hidden(fn (callable $get) => !$get('work_group10_id_visible')) ->hidden(fn (callable $get) => ! $get('work_group10_id_visible'))
->default('') ->default('')
->required() ->required()
->reactive() ->reactive()
@@ -911,14 +926,16 @@ class LineResource extends Resource
if ($state == null || trim($state) == '') { if ($state == null || trim($state) == '') {
$set('work_group10_id_error', null); $set('work_group10_id_error', null);
$set('work_group10_id', null); $set('work_group10_id', null);
return; return;
} }
$set('work_group10_id_error', null); $set('work_group10_id_error', null);
$set('work_group10_id', null); $set('work_group10_id', null);
if (!$plantId) { if (! $plantId) {
$set('work_group10_id_error', 'Invalid plant name.'); $set('work_group10_id_error', 'Invalid plant name.');
return; return;
} }
@@ -926,8 +943,9 @@ class LineResource extends Resource
->where('name', $state) ->where('name', $state)
->first(); ->first();
if (!$workGroupRecord) { if (! $workGroupRecord) {
$set('work_group10_id_error', 'Work group does not exist for this plant in master.'); $set('work_group10_id_error', 'Work group does not exist for this plant in master.');
return; return;
} }
@@ -948,10 +966,9 @@ class LineResource extends Resource
->send(); ->send();
$set('work_group10_actual_id', ''); $set('work_group10_actual_id', '');
$set('work_group10_id', null); $set('work_group10_id', null);
return; return;
} } else {
else
{
$set('work_group10_id_error', null); $set('work_group10_id_error', null);
$set('work_group10_id', $workGroupRecord->id); $set('work_group10_id', $workGroupRecord->id);
} }
@@ -987,6 +1004,7 @@ class LineResource 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('plant.name') Tables\Columns\TextColumn::make('plant.name')
@@ -1145,14 +1163,14 @@ class LineResource extends Resource
->label('Import Lines') ->label('Import Lines')
->color('warning') ->color('warning')
->importer(LineImporter::class) ->importer(LineImporter::class)
->visible(function() { ->visible(function () {
return Filament::auth()->user()->can('view import line'); return Filament::auth()->user()->can('view import line');
}), }),
ExportAction::make() ExportAction::make()
->label('Export Lines') ->label('Export Lines')
->color('warning') ->color('warning')
->exporter(LineExporter::class) ->exporter(LineExporter::class)
->visible(function() { ->visible(function () {
return Filament::auth()->user()->can('view export line'); return Filament::auth()->user()->can('view export line');
}), }),
]); ]);

View File

@@ -48,7 +48,7 @@ class LocatorResource 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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->default(function () { ->default(function () {
return optional(Locator::latest()->first())->plant_id; return optional(Locator::latest()->first())->plant_id;
@@ -194,7 +194,7 @@ class LocatorResource 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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->reactive() ->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get): void { ->afterStateUpdated(function ($state, callable $set, callable $get): void {

View File

@@ -45,7 +45,7 @@ class MachineResource 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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->default(function () { ->default(function () {
return optional(Machine::latest()->first())->plant_id; return optional(Machine::latest()->first())->plant_id;

View File

@@ -5,21 +5,20 @@ namespace App\Filament\Resources;
use App\Filament\Exports\MfmMeterExporter; use App\Filament\Exports\MfmMeterExporter;
use App\Filament\Imports\MfmMeterImporter; use App\Filament\Imports\MfmMeterImporter;
use App\Filament\Resources\MfmMeterResource\Pages; use App\Filament\Resources\MfmMeterResource\Pages;
use App\Filament\Resources\MfmMeterResource\RelationManagers;
use App\Models\DeviceMaster; use App\Models\DeviceMaster;
use App\Models\MfmMeter; use App\Models\MfmMeter;
use App\Models\Plant; use App\Models\Plant;
use Filament\Facades\Filament; use Filament\Facades\Filament;
use Filament\Forms; use Filament\Forms;
use Filament\Forms\Components\Section;
use Filament\Forms\Form; use Filament\Forms\Form;
use Filament\Resources\Resource; use Filament\Resources\Resource;
use Filament\Tables; use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Table; use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope; use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Forms\Components\Section;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Actions\ExportAction;
class MfmMeterResource extends Resource class MfmMeterResource extends Resource
{ {
@@ -42,15 +41,17 @@ class MfmMeterResource extends Resource
->required() ->required()
->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::orderBy('code')->pluck('name', 'id')->toArray();
}), }),
Forms\Components\Select::make('device_master_id') Forms\Components\Select::make('device_master_id')
//->relationship('device', 'name') // ->relationship('device', 'name')
->options(function ($get) { ->options(function ($get) {
$plantId = $get('plant_id'); $plantId = $get('plant_id');
if (!$plantId) { if (! $plantId) {
return []; return [];
} }
return DeviceMaster::where('plant_id', $plantId)->pluck('name', 'id'); return DeviceMaster::where('plant_id', $plantId)->pluck('name', 'id');
}) })
->label('Device Name') ->label('Device Name')
@@ -77,6 +78,7 @@ class MfmMeterResource 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('plant.name') Tables\Columns\TextColumn::make('plant.name')
@@ -126,14 +128,14 @@ class MfmMeterResource extends Resource
->label('Import MFM Meters') ->label('Import MFM Meters')
->color('warning') ->color('warning')
->importer(MfmMeterImporter::class) ->importer(MfmMeterImporter::class)
->visible(function() { ->visible(function () {
return Filament::auth()->user()->can('view import mfm meter'); return Filament::auth()->user()->can('view import mfm meter');
}), }),
ExportAction::make() ExportAction::make()
->label('Export MFM Meters') ->label('Export MFM Meters')
->color('warning') ->color('warning')
->exporter(MfmMeterExporter::class) ->exporter(MfmMeterExporter::class)
->visible(function() { ->visible(function () {
return Filament::auth()->user()->can('view export mfm meter'); return Filament::auth()->user()->can('view export mfm meter');
}), }),
]); ]);

View File

@@ -5,26 +5,26 @@ namespace App\Filament\Resources;
use App\Filament\Exports\MfmParameterExporter; use App\Filament\Exports\MfmParameterExporter;
use App\Filament\Imports\MfmParameterImporter; use App\Filament\Imports\MfmParameterImporter;
use App\Filament\Resources\MfmParameterResource\Pages; use App\Filament\Resources\MfmParameterResource\Pages;
use App\Filament\Resources\MfmParameterResource\RelationManagers;
use App\Models\MfmParameter; use App\Models\MfmParameter;
use App\Models\Plant; use App\Models\Plant;
use Filament\Facades\Filament; use Filament\Facades\Filament;
use Filament\Forms; use Filament\Forms;
use Filament\Forms\Components\Section;
use Filament\Forms\Form; use Filament\Forms\Form;
use Filament\Resources\Resource; use Filament\Resources\Resource;
use Filament\Tables; use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Table; use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope; use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Forms\Components\Section;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Actions\ExportAction;
class MfmParameterResource extends Resource class MfmParameterResource extends Resource
{ {
protected static ?string $model = MfmParameter::class; protected static ?string $model = MfmParameter::class;
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack'; protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $navigationGroup = 'Power House'; protected static ?string $navigationGroup = 'Power House';
public static function form(Form $form): Form public static function form(Form $form): Form
@@ -39,7 +39,8 @@ class MfmParameterResource 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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->afterStateUpdated(function (callable $set) { ->afterStateUpdated(function (callable $set) {
$set('device_master_id', null); $set('device_master_id', null);
@@ -54,11 +55,11 @@ class MfmParameterResource extends Resource
->required(), ->required(),
Forms\Components\Select::make('device_master_id') Forms\Components\Select::make('device_master_id')
->label('Device Master') ->label('Device Master')
//->relationship('deviceName', 'name') // ->relationship('deviceName', 'name')
->options(function (callable $get) { ->options(function (callable $get) {
$plantId = $get('plant_id'); $plantId = $get('plant_id');
if (!$plantId) { if (! $plantId) {
return []; return [];
} }
@@ -82,7 +83,7 @@ class MfmParameterResource extends Resource
->options(function (callable $get) { ->options(function (callable $get) {
$plantId = $get('plant_id'); $plantId = $get('plant_id');
if (!$plantId) { if (! $plantId) {
return []; return [];
} }
@@ -139,6 +140,7 @@ class MfmParameterResource 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('plant.name') Tables\Columns\TextColumn::make('plant.name')
@@ -212,14 +214,14 @@ class MfmParameterResource extends Resource
->label('Import MFM Parameters') ->label('Import MFM Parameters')
->color('warning') ->color('warning')
->importer(MfmParameterImporter::class) ->importer(MfmParameterImporter::class)
->visible(function() { ->visible(function () {
return Filament::auth()->user()->can('view import mfm parameter'); return Filament::auth()->user()->can('view import mfm parameter');
}), }),
ExportAction::make() ExportAction::make()
->label('Export MFM Parameters') ->label('Export MFM Parameters')
->color('warning') ->color('warning')
->exporter(MfmParameterExporter::class) ->exporter(MfmParameterExporter::class)
->visible(function() { ->visible(function () {
return Filament::auth()->user()->can('view export mfm parameter'); return Filament::auth()->user()->can('view export mfm parameter');
}), }),
]); ]);

View File

@@ -3,7 +3,6 @@
namespace App\Filament\Resources; namespace App\Filament\Resources;
use App\Filament\Resources\MfmReadingResource\Pages; use App\Filament\Resources\MfmReadingResource\Pages;
use App\Filament\Resources\MfmReadingResource\RelationManagers;
use App\Models\MfmReading; use App\Models\MfmReading;
use App\Models\Plant; use App\Models\Plant;
use Filament\Facades\Filament; use Filament\Facades\Filament;
@@ -31,7 +30,8 @@ class MfmReadingResource extends Resource
->relationship('plant', 'name') ->relationship('plant', 'name')
->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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->required(), ->required(),
Forms\Components\Select::make('mfm_meter_id') Forms\Components\Select::make('mfm_meter_id')
@@ -72,6 +72,7 @@ class MfmReadingResource 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('plant.name') Tables\Columns\TextColumn::make('plant.name')

View File

@@ -49,7 +49,7 @@ class MotorTestingMasterResource 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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->default(function () { ->default(function () {
return optional(MotorTestingMaster::latest()->first())->plant_id; return optional(MotorTestingMaster::latest()->first())->plant_id;
@@ -466,7 +466,7 @@ class MotorTestingMasterResource 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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->reactive() ->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {

View File

@@ -3,36 +3,36 @@
namespace App\Filament\Resources; namespace App\Filament\Resources;
use App\Filament\Resources\OcrValidationResource\Pages; use App\Filament\Resources\OcrValidationResource\Pages;
use App\Filament\Resources\OcrValidationResource\RelationManagers;
use App\Models\Item; use App\Models\Item;
use App\Models\OcrValidation; use App\Models\OcrValidation;
use App\Models\Plant; use App\Models\Plant;
use Filament\Facades\Filament;
use Filament\Forms; use Filament\Forms;
use Filament\Forms\Components\Actions\Action;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Form; use Filament\Forms\Form;
use Filament\Notifications\Notification;
use Filament\Resources\Resource; use Filament\Resources\Resource;
use Filament\Tables; use Filament\Tables;
use Filament\Tables\Table; use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope; use Illuminate\Database\Eloquent\SoftDeletingScope;
use thiagoalessio\TesseractOCR\TesseractOCR;
use setasign\Fpdi\Fpdi;
use Filament\Facades\Filament;
use Filament\Forms\Components\Actions\Action;
use Filament\Notifications\Notification;
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile; use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
use setasign\Fpdi\PdfReader; use setasign\Fpdi\Fpdi;
use SimpleSoftwareIO\QrCode\Facades\QrCode; use SimpleSoftwareIO\QrCode\Facades\QrCode;
use Storage;
use Filament\Forms\Concerns\InteractsWithForms;
use Smalot\PdfParser\Parser; use Smalot\PdfParser\Parser;
use Storage;
class OcrValidationResource extends Resource class OcrValidationResource extends Resource
{ {
protected static ?string $model = OcrValidation::class; protected static ?string $model = OcrValidation::class;
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack'; protected static ?string $navigationIcon = 'heroicon-s-qr-code';
protected static ?string $navigationGroup = 'OCR';
public $camera_capture; public $camera_capture;
public $serialNumbers = []; public $serialNumbers = [];
use InteractsWithForms; use InteractsWithForms;
@@ -47,12 +47,13 @@ class OcrValidationResource extends Resource
->relationship('plant', 'name') ->relationship('plant', 'name')
->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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->required(), ->required(),
Forms\Components\Select::make('item_id') Forms\Components\Select::make('item_id')
->label('Item Code') ->label('Item Code')
//->relationship('item', 'id') // ->relationship('item', 'id')
->reactive() ->reactive()
->searchable() ->searchable()
->options(function (callable $get) { ->options(function (callable $get) {
@@ -60,6 +61,7 @@ class OcrValidationResource extends Resource
if (empty($plantId)) { if (empty($plantId)) {
return []; return [];
} }
return Item::where('plant_id', $plantId)->pluck('code', 'id'); return Item::where('plant_id', $plantId)->pluck('code', 'id');
}) })
->required(), ->required(),
@@ -114,8 +116,7 @@ class OcrValidationResource extends Resource
->action(function ($get, callable $set) { ->action(function ($get, callable $set) {
$uploadedFiles = $get('attachment'); $uploadedFiles = $get('attachment');
if (is_array($uploadedFiles) && count($uploadedFiles) > 0) if (is_array($uploadedFiles) && count($uploadedFiles) > 0) {
{
$uploaded = reset($uploadedFiles); $uploaded = reset($uploadedFiles);
if ($uploaded instanceof TemporaryUploadedFile) { if ($uploaded instanceof TemporaryUploadedFile) {
@@ -123,8 +124,8 @@ class OcrValidationResource extends Resource
$safeName = preg_replace('/[^A-Za-z0-9_\-]/', '_', $grNumber); $safeName = preg_replace('/[^A-Za-z0-9_\-]/', '_', $grNumber);
// $originalName = $uploaded->getClientOriginalName(); // $originalName = $uploaded->getClientOriginalName();
// $path = 'uploads/GRNumber/' . $originalName; // $path = 'uploads/GRNumber/' . $originalName;
$finalFileName = $safeName . '.pdf'; $finalFileName = $safeName.'.pdf';
$finalPath = 'uploads/OcrGrNumber/' . $finalFileName; $finalPath = 'uploads/OcrGrNumber/'.$finalFileName;
if (Storage::disk('local')->exists($finalPath)) { if (Storage::disk('local')->exists($finalPath)) {
Notification::make() Notification::make()
@@ -132,6 +133,7 @@ class OcrValidationResource extends Resource
->body("The file '{$finalFileName}' already exists in uploads/GRNumber.") ->body("The file '{$finalFileName}' already exists in uploads/GRNumber.")
->warning() ->warning()
->send(); ->send();
return; return;
} }
@@ -141,26 +143,22 @@ class OcrValidationResource extends Resource
'local' 'local'
); );
// $fullPath = storage_path('app/' . $storedPath); // $fullPath = storage_path('app/' . $storedPath);
$fullPath = storage_path('app/private/' . $storedPath); $fullPath = storage_path('app/private/'.$storedPath);
$parser = new Parser(); $parser = new Parser;
//$pdf = $parser->parseContent(file_get_contents($uploaded->getRealPath())); // $pdf = $parser->parseContent(file_get_contents($uploaded->getRealPath()));
$pdf = $parser->parseFile($fullPath); $pdf = $parser->parseFile($fullPath);
$text = $pdf->getText(); $text = $pdf->getText();
// dd($text); // dd($text);
//dd($text); // dd($text);
$item1 = null; $item1 = null;
$item2 = null; $item2 = null;
if (preg_match('/Item code\s*:\s*(\S+)/i', $text, $matches)) if (preg_match('/Item code\s*:\s*(\S+)/i', $text, $matches)) {
{
$item1 = $matches[1]; $item1 = $matches[1];
} } elseif (preg_match('/E CODE\s*:\s*(\S+)/i', $text, $matches)) {
else if (preg_match('/E CODE\s*:\s*(\S+)/i', $text, $matches))
{
$item2 = $matches[1]; $item2 = $matches[1];
} }
@@ -174,21 +172,19 @@ class OcrValidationResource extends Resource
$plant = Plant::find($plant); $plant = Plant::find($plant);
if ($item) if ($item) {
{
$itemCode = $item->code; $itemCode = $item->code;
} } else {
else
{
$itemCode = null; $itemCode = null;
Notification::make() Notification::make()
->title('Item Not Found') ->title('Item Not Found')
->body("Item not found in uploaded pdf.") ->body('Item not found in uploaded pdf.')
->warning() ->warning()
->send(); ->send();
if (Storage::disk('local')->exists($storedPath)) { if (Storage::disk('local')->exists($storedPath)) {
Storage::disk('local')->delete($storedPath); Storage::disk('local')->delete($storedPath);
} }
return; return;
} }
@@ -198,26 +194,24 @@ class OcrValidationResource extends Resource
'local' 'local'
); );
if($itemCode == $item1) if ($itemCode == $item1) {
{
Notification::make() Notification::make()
->title('Success') ->title('Success')
->body("Gr Number '$processOrder' PDF uploaded successfully.") ->body("Gr Number '$processOrder' PDF uploaded successfully.")
->success() ->success()
->send(); ->send();
return; return;
} }
if($itemCode == $item2) if ($itemCode == $item2) {
{
Notification::make() Notification::make()
->title('Success') ->title('Success')
->body("Gr Number '$processOrder' PDF uploaded successfully.") ->body("Gr Number '$processOrder' PDF uploaded successfully.")
->success() ->success()
->send(); ->send();
return; return;
} } else {
else
{
Notification::make() Notification::make()
->title('Item Code not matched') ->title('Item Code not matched')
->body("Item Code: {$item->code} not matched with the uploaded pdf code $item1.") ->body("Item Code: {$item->code} not matched with the uploaded pdf code $item1.")
@@ -227,16 +221,16 @@ class OcrValidationResource extends Resource
if (Storage::disk('local')->exists($storedPath)) { if (Storage::disk('local')->exists($storedPath)) {
Storage::disk('local')->delete($storedPath); Storage::disk('local')->delete($storedPath);
} }
return; return;
} }
} }
} } else {
else
{
Notification::make() Notification::make()
->title('No file selected to upload') ->title('No file selected to upload')
->warning() ->warning()
->send(); ->send();
return; return;
} }
}), }),
@@ -256,25 +250,25 @@ class OcrValidationResource extends Resource
->title('Serial numbers cannot be empty!') ->title('Serial numbers cannot be empty!')
->danger() ->danger()
->send(); ->send();
return; return;
} }
//$serialNumbers = array_slice($serialNumbers, 0, 4); // $serialNumbers = array_slice($serialNumbers, 0, 4);
if (count($serials) == 1) if (count($serials) == 1) {
{
$serialNumbers = $serials; $serialNumbers = $serials;
$grNumber = trim($grNumber); $grNumber = trim($grNumber);
//$templatePath = storage_path('app/private/uploads/StickerTemplateOcr/Single.pdf'); // $templatePath = storage_path('app/private/uploads/StickerTemplateOcr/Single.pdf');
$templatePath = storage_path("app/private/uploads/OcrGrNumber/{$grNumber}.pdf"); $templatePath = storage_path("app/private/uploads/OcrGrNumber/{$grNumber}.pdf");
if(!file_exists($templatePath)) if (! file_exists($templatePath)) {
{
Notification::make() Notification::make()
->title("Template PDF not found for the Gr Number $grNumber.") ->title("Template PDF not found for the Gr Number $grNumber.")
->danger() ->danger()
->send(); ->send();
return; return;
} }
@@ -300,17 +294,21 @@ class OcrValidationResource extends Resource
]; ];
foreach ($serialNumbers as $i => $serial) { foreach ($serialNumbers as $i => $serial) {
if (!isset($slots[$i]) || !isset($qrSlots[$i])) continue; if (! isset($slots[$i]) || ! isset($qrSlots[$i])) {
continue;
}
// Erase old QR completely (slightly larger) // Erase old QR completely (slightly larger)
$pdf->SetFillColor(255, 255, 255); $pdf->SetFillColor(255, 255, 255);
$pdf->Rect($qrSlots[$i]['x']-1, $qrSlots[$i]['y']-1, $qrSlots[$i]['size']+2, $qrSlots[$i]['size']+2, 'F'); $pdf->Rect($qrSlots[$i]['x'] - 1, $qrSlots[$i]['y'] - 1, $qrSlots[$i]['size'] + 2, $qrSlots[$i]['size'] + 2, 'F');
// Generate new QR code // Generate new QR code
$qrPath = storage_path("app/private/uploads/QR/qr_$serial.png"); $qrPath = storage_path("app/private/uploads/QR/qr_$serial.png");
$qrDir = storage_path('app/private/uploads/QR'); $qrDir = storage_path('app/private/uploads/QR');
if (!file_exists($qrDir)) mkdir($qrDir, 0777, true); if (! file_exists($qrDir)) {
//QrCode::format('svg')->size(100)->generate($serial, $qrPath); mkdir($qrDir, 0777, true);
}
// QrCode::format('svg')->size(100)->generate($serial, $qrPath);
QrCode::format('png')->size(300)->errorCorrection('H')->generate($serial, $qrPath); QrCode::format('png')->size(300)->errorCorrection('H')->generate($serial, $qrPath);
// Place QR code // Place QR code
@@ -331,12 +329,11 @@ class OcrValidationResource extends Resource
// Download // Download
return response()->download($outputPath); return response()->download($outputPath);
} }
if(count($serials) == 4) if (count($serials) == 4) {
{
$serialNumbers = array_slice($serials, 0, 4); $serialNumbers = array_slice($serials, 0, 4);
//dd($serialNumbers); // dd($serialNumbers);
$itemId = $get('item_id'); $itemId = $get('item_id');
@@ -348,19 +345,19 @@ class OcrValidationResource extends Resource
$grNumber = trim($grNumber); $grNumber = trim($grNumber);
//$templatePath = storage_path('app/private/uploads/StickerTemplateOcr/Single.pdf'); // $templatePath = storage_path('app/private/uploads/StickerTemplateOcr/Single.pdf');
$templatePath = storage_path("app/private/uploads/OcrGrNumber/{$grNumber}.pdf"); $templatePath = storage_path("app/private/uploads/OcrGrNumber/{$grNumber}.pdf");
// $templatePath = storage_path('app/private/uploads/StickerTemplateOcr/multi.pdf'); // $templatePath = storage_path('app/private/uploads/StickerTemplateOcr/multi.pdf');
//$templatePath = storage_path("app/private/uploads/OcrGrNumber/'$grNumber'.pdf"); // $templatePath = storage_path("app/private/uploads/OcrGrNumber/'$grNumber'.pdf");
if(!file_exists($templatePath)) if (! file_exists($templatePath)) {
{
Notification::make() Notification::make()
->title("Template PDF not found for the Gr Number $grNumber.") ->title("Template PDF not found for the Gr Number $grNumber.")
->danger() ->danger()
->send(); ->send();
return; return;
} }
@@ -398,17 +395,21 @@ class OcrValidationResource extends Resource
]; ];
foreach ($serialNumbers as $i => $serial) { foreach ($serialNumbers as $i => $serial) {
if (!isset($slots[$i]) || !isset($qrSlots[$i])) continue; if (! isset($slots[$i]) || ! isset($qrSlots[$i])) {
continue;
}
// Erase old QR completely (slightly larger) // Erase old QR completely (slightly larger)
$pdf->SetFillColor(255, 255, 255); $pdf->SetFillColor(255, 255, 255);
$pdf->Rect($qrSlots[$i]['x']-1, $qrSlots[$i]['y']-1, $qrSlots[$i]['size']+2, $qrSlots[$i]['size']+2, 'F'); $pdf->Rect($qrSlots[$i]['x'] - 1, $qrSlots[$i]['y'] - 1, $qrSlots[$i]['size'] + 2, $qrSlots[$i]['size'] + 2, 'F');
// Generate new QR code // Generate new QR code
$qrPath = storage_path("app/private/uploads/QR/qr_$serial.png"); $qrPath = storage_path("app/private/uploads/QR/qr_$serial.png");
$qrDir = storage_path('app/private/uploads/QR'); $qrDir = storage_path('app/private/uploads/QR');
if (!file_exists($qrDir)) mkdir($qrDir, 0777, true); if (! file_exists($qrDir)) {
//QrCode::format('svg')->size(100)->generate($serial, $qrPath); mkdir($qrDir, 0777, true);
}
// QrCode::format('svg')->size(100)->generate($serial, $qrPath);
QrCode::format('png')->size(300)->errorCorrection('H')->generate($serial, $qrPath); QrCode::format('png')->size(300)->errorCorrection('H')->generate($serial, $qrPath);
// Place QR code // Place QR code
@@ -428,13 +429,12 @@ class OcrValidationResource extends Resource
// Download // Download
return response()->download($outputPath); return response()->download($outputPath);
} } else {
else
{
Notification::make() Notification::make()
->title('Please capture either 1 or 4 serial numbers.') ->title('Please capture either 1 or 4 serial numbers.')
->danger() ->danger()
->send(); ->send();
return; return;
} }
}), }),
@@ -443,11 +443,12 @@ class OcrValidationResource extends Resource
->action(function ($get) { ->action(function ($get) {
$equipmentNumber = $get('gr_number'); $equipmentNumber = $get('gr_number');
if (!$equipmentNumber) { if (! $equipmentNumber) {
Notification::make() Notification::make()
->title('No GR Number entered') ->title('No GR Number entered')
->danger() ->danger()
->send(); ->send();
return; return;
} }
@@ -461,13 +462,15 @@ class OcrValidationResource extends Resource
} }
} }
if (!$fileToDownload) { if (! $fileToDownload) {
Notification::make() Notification::make()
->title('PDF not found for this process order') ->title('PDF not found for this process order')
->danger() ->danger()
->send(); ->send();
return; return;
} }
return response()->download(Storage::disk('local')->path($fileToDownload)); return response()->download(Storage::disk('local')->path($fileToDownload));
}), }),
]), ]),
@@ -481,7 +484,6 @@ class OcrValidationResource extends Resource
]); ]);
} }
public static function table(Table $table): Table public static function table(Table $table): Table
{ {
return $table return $table

View File

@@ -49,7 +49,7 @@ class PalletValidationResource 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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->afterStateUpdated(function ($state, callable $set) { ->afterStateUpdated(function ($state, callable $set) {
$set('pallet_number', null); $set('pallet_number', null);
@@ -279,7 +279,7 @@ class PalletValidationResource 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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->reactive() ->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get): void { ->afterStateUpdated(function ($state, callable $set, callable $get): void {
@@ -529,7 +529,7 @@ class PalletValidationResource 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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->required() ->required()
->reactive() ->reactive()

View File

@@ -55,7 +55,7 @@ class ProductionLineStopResource 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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->default(function () { ->default(function () {
return optional(ProductionLineStop::latest()->first())->plant_id; return optional(ProductionLineStop::latest()->first())->plant_id;
@@ -430,7 +430,7 @@ class ProductionLineStopResource 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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->reactive() ->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {

View File

@@ -54,7 +54,7 @@ class ProductionPlanResource 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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->default(function () { ->default(function () {
return optional(ProductionPlan::latest()->first())->plant_id; return optional(ProductionPlan::latest()->first())->plant_id;
@@ -576,7 +576,7 @@ class ProductionPlanResource 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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->reactive() ->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {

View File

@@ -63,7 +63,7 @@ class ProductionQuantityResource 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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
// ->default(fn () => optional(ProductionQuantity::latest()->first())->plant_id) // ->default(fn () => optional(ProductionQuantity::latest()->first())->plant_id)
->default(function () { ->default(function () {
@@ -1035,7 +1035,7 @@ class ProductionQuantityResource 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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->reactive() ->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {

View File

@@ -56,7 +56,7 @@ class QualityValidationResource 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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->afterStateUpdated(function (callable $set, callable $get, $state) { ->afterStateUpdated(function (callable $set, callable $get, $state) {
$set('item_id', null); $set('item_id', null);
@@ -3015,7 +3015,7 @@ class QualityValidationResource 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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->reactive() ->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {

View File

@@ -53,7 +53,7 @@ class ReworkLocatorInvoiceValidationResource 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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id'); $plantId = $get('plant_id');
@@ -456,7 +456,7 @@ class ReworkLocatorInvoiceValidationResource 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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->reactive() ->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get): void { ->afterStateUpdated(function ($state, callable $set, callable $get): void {

View File

@@ -55,7 +55,7 @@ class SerialValidationResource 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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->default(function () { ->default(function () {
return optional(SerialValidation::latest()->first())->plant_id; return optional(SerialValidation::latest()->first())->plant_id;
@@ -332,7 +332,7 @@ class SerialValidationResource 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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->label('Select Plant') ->label('Select Plant')
->required() ->required()
@@ -1038,7 +1038,7 @@ class SerialValidationResource 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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->reactive() ->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get): void { ->afterStateUpdated(function ($state, callable $set, callable $get): void {

View File

@@ -10,16 +10,16 @@ use App\Models\Shift;
use Carbon\Carbon; use Carbon\Carbon;
use Filament\Facades\Filament; use Filament\Facades\Filament;
use Filament\Forms; use Filament\Forms;
use Filament\Forms\Components\Section;
use Filament\Forms\Form; use Filament\Forms\Form;
use Filament\Forms\Get; use Filament\Forms\Get;
use Filament\Resources\Resource; use Filament\Resources\Resource;
use Filament\Tables; use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction; use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Table; use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope; use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Forms\Components\Section;
use Filament\Tables\Actions\ExportAction;
use Illuminate\Validation\Rule; use Illuminate\Validation\Rule;
class ShiftResource extends Resource class ShiftResource extends Resource
@@ -45,22 +45,22 @@ class ShiftResource 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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->default(function () { ->default(function () {
return optional(Shift::latest()->first())->plant_id; return optional(Shift::latest()->first())->plant_id;
}) })
->disabled(fn (Get $get) => !empty($get('id'))) ->disabled(fn (Get $get) => ! empty($get('id')))
// ->afterStateUpdated(fn ($set) => $set('block_id', null) & $set('name', null) & $set('start_time', null) & $set('duration', null) & $set('end_time', null)) // ->afterStateUpdated(fn ($set) => $set('block_id', null) & $set('name', null) & $set('start_time', null) & $set('duration', null) & $set('end_time', null))
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id'); $plantId = $get('plant_id');
$set('block_id', null); $set('block_id', null);
if (!$plantId) { if (! $plantId) {
$set('sPlantError', 'Please select a plant first.'); $set('sPlantError', 'Please select a plant first.');
return; return;
} } else {
else
{
$set('sPlantError', null); $set('sPlantError', null);
} }
}) })
@@ -84,7 +84,7 @@ class ShiftResource extends Resource
// ->toArray() // Convert collection to array // ->toArray() // Convert collection to array
// ) // )
->options(function (callable $get) { ->options(function (callable $get) {
if (!$get('plant_id')) { if (! $get('plant_id')) {
return []; return [];
} }
@@ -96,12 +96,11 @@ class ShiftResource extends Resource
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$blockId = $get('block_id'); $blockId = $get('block_id');
$set('name', null); $set('name', null);
if (!$blockId) { if (! $blockId) {
$set('sBlockError', 'Please select a block first.'); $set('sBlockError', 'Please select a block first.');
return; return;
} } else {
else
{
$set('sBlockError', null); $set('sBlockError', null);
} }
}) })
@@ -118,12 +117,11 @@ class ShiftResource extends Resource
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$nameId = $get('name'); $nameId = $get('name');
$set('start_time', null); $set('start_time', null);
if (!$nameId) { if (! $nameId) {
$set('sNameError', 'Scan the valid name.'); $set('sNameError', 'Scan the valid name.');
return; return;
} } else {
else
{
// $exists = Shift::where('plant_id', $get('plant_id')) // $exists = Shift::where('plant_id', $get('plant_id'))
// ->where('block_id', $get('block_id')) // ->where('block_id', $get('block_id'))
// ->where('name', $nameId) // ->where('name', $nameId)
@@ -161,12 +159,11 @@ class ShiftResource extends Resource
$startTime = $get('start_time'); $startTime = $get('start_time');
$set('duration', null); $set('duration', null);
$set('end_time', self::calculateEndTime($state, $get('duration'))); $set('end_time', self::calculateEndTime($state, $get('duration')));
if (!$startTime) { if (! $startTime) {
$set('sStartTimeError', 'Choose the valid start time.'); $set('sStartTimeError', 'Choose the valid start time.');
return; return;
} } else {
else
{
// $exists = Shift::where('plant_id', $get('plant_id')) // $exists = Shift::where('plant_id', $get('plant_id'))
// ->where('block_id', $get('block_id')) // ->where('block_id', $get('block_id'))
// ->where('name', $get('name')) // ->where('name', $get('name'))
@@ -202,12 +199,11 @@ class ShiftResource extends Resource
$duration = $get('duration'); $duration = $get('duration');
// $set('end_time', null); // $set('end_time', null);
$set('end_time', self::calculateEndTime($get('start_time'), $state)); $set('end_time', self::calculateEndTime($get('start_time'), $state));
if (!$duration) { if (! $duration) {
$set('sDurationError', 'Scan the valid duration.'); $set('sDurationError', 'Scan the valid duration.');
return; return;
} } else {
else
{
[$hRs, $miNs] = explode('.', $duration) + [0, 0]; // Ensure two parts [$hRs, $miNs] = explode('.', $duration) + [0, 0]; // Ensure two parts
$hRs = (int) $hRs; $hRs = (int) $hRs;
$miNs = (int) $miNs; $miNs = (int) $miNs;
@@ -218,6 +214,7 @@ class ShiftResource extends Resource
$set('sDurationError', 'Minutes exceeds 1 hour.'); $set('sDurationError', 'Minutes exceeds 1 hour.');
$set('duration', null); $set('duration', null);
$set('end_time', null); $set('end_time', null);
return; return;
} }
@@ -227,6 +224,7 @@ class ShiftResource extends Resource
$set('sDurationError', 'Duration exceeds 24 hours.'); $set('sDurationError', 'Duration exceeds 24 hours.');
$set('duration', null); $set('duration', null);
$set('end_time', null); $set('end_time', null);
return; return;
} }
$set('sDurationError', null); $set('sDurationError', null);
@@ -246,12 +244,11 @@ class ShiftResource extends Resource
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$endTime = $get('end_time'); $endTime = $get('end_time');
$set('end_time', self::calculateEndTime($get('start_time'), $state)); $set('end_time', self::calculateEndTime($get('start_time'), $state));
if (!$endTime) { if (! $endTime) {
$set('sEndTimeError', 'Choose the valid start time & duration.'); $set('sEndTimeError', 'Choose the valid start time & duration.');
return; return;
} } else {
else
{
$set('sEndTimeError', null); $set('sEndTimeError', null);
} }
}) })
@@ -282,6 +279,7 @@ class ShiftResource 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('name') Tables\Columns\TextColumn::make('name')
@@ -347,14 +345,14 @@ class ShiftResource extends Resource
->label('Import Shifts') ->label('Import Shifts')
->color('warning') ->color('warning')
->importer(ShiftImporter::class) ->importer(ShiftImporter::class)
->visible(function() { ->visible(function () {
return Filament::auth()->user()->can('view import shift'); return Filament::auth()->user()->can('view import shift');
}), }),
ExportAction::make() ExportAction::make()
->label('Export Shifts') ->label('Export Shifts')
->color('warning') ->color('warning')
->exporter(ShiftExporter::class) ->exporter(ShiftExporter::class)
->visible(function() { ->visible(function () {
return Filament::auth()->user()->can('view export shift'); return Filament::auth()->user()->can('view export shift');
}), }),
]); ]);
@@ -387,7 +385,7 @@ class ShiftResource extends Resource
protected static function calculateEndTime(?string $startTime, ?string $duration): ?string protected static function calculateEndTime(?string $startTime, ?string $duration): ?string
{ {
if (!$startTime || !$duration) { if (! $startTime || ! $duration) {
return null; return null;
} }
@@ -397,7 +395,7 @@ class ShiftResource extends Resource
// Ensure duration is in a valid numeric format // Ensure duration is in a valid numeric format
$duration = str_replace(',', '.', $duration); // Handle decimal formats $duration = str_replace(',', '.', $duration); // Handle decimal formats
if (!is_numeric($duration)) { if (! is_numeric($duration)) {
return null; // Invalid duration format return null; // Invalid duration format
} }

View File

@@ -2,6 +2,8 @@
namespace App\Filament\Resources; namespace App\Filament\Resources;
use App\Filament\Exports\StickerPrintingExporter;
use App\Filament\Imports\StickerPrintingImporter;
use App\Filament\Resources\StickerPrintingResource\Pages; use App\Filament\Resources\StickerPrintingResource\Pages;
use App\Models\Plant; use App\Models\Plant;
use App\Models\StickerPrinting; use App\Models\StickerPrinting;
@@ -11,14 +13,11 @@ use Filament\Forms\Components\Section;
use Filament\Forms\Form; use Filament\Forms\Form;
use Filament\Resources\Resource; use Filament\Resources\Resource;
use Filament\Tables; use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Table; use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope; use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use App\Filament\Exports\StickerPrintingExporter;
use App\Filament\Imports\StickerPrintingImporter;
use Filament\Forms\Components\Actions\Action;
class StickerPrintingResource extends Resource class StickerPrintingResource extends Resource
{ {
@@ -40,13 +39,14 @@ class StickerPrintingResource extends Resource
->relationship('plant', 'name') ->relationship('plant', 'name')
->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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->required() ->required()
->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('reference_number', null); $set('reference_number', null);
$set('serial_number', null); $set('serial_number', null);
$set('ivPlantError', 'Please select a plant first.'); $set('ivPlantError', 'Please select a plant first.');
@@ -64,7 +64,7 @@ class StickerPrintingResource extends Resource
Forms\Components\TextInput::make('reference_number') Forms\Components\TextInput::make('reference_number')
->label('Reference Number') ->label('Reference Number')
->reactive() ->reactive()
->readOnly(fn (callable $get) => !empty($get('serial_number'))) ->readOnly(fn (callable $get) => ! empty($get('serial_number')))
->extraAttributes([ ->extraAttributes([
'id' => 'invoice_number_input', 'id' => 'invoice_number_input',
'x-data' => '{ value: "" }', 'x-data' => '{ value: "" }',
@@ -82,9 +82,9 @@ class StickerPrintingResource extends Resource
'x-data' => '{ value: "" }', 'x-data' => '{ value: "" }',
'x-model' => 'value', 'x-model' => 'value',
'wire:keydown.enter.prevent' => 'processSno(value)', 'wire:keydown.enter.prevent' => 'processSno(value)',
//'x-on:keydown.enter.prevent' => '$wire.processInvoice(value)', // 'x-on:keydown.enter.prevent' => '$wire.processInvoice(value)',
]), ]),
//->required(), // ->required(),
Forms\Components\View::make('forms.components.print-button'), Forms\Components\View::make('forms.components.print-button'),
Forms\Components\Hidden::make('created_by') Forms\Components\Hidden::make('created_by')

View File

@@ -5,28 +5,27 @@ namespace App\Filament\Resources;
use App\Filament\Exports\TempLiveReadingExporter; use App\Filament\Exports\TempLiveReadingExporter;
use App\Filament\Imports\TempLiveReadingImporter; use App\Filament\Imports\TempLiveReadingImporter;
use App\Filament\Resources\TempLiveReadingResource\Pages; use App\Filament\Resources\TempLiveReadingResource\Pages;
use App\Filament\Resources\TempLiveReadingResource\RelationManagers;
use App\Models\MfmMeter; use App\Models\MfmMeter;
use App\Models\Plant; use App\Models\Plant;
use App\Models\TempLiveReading; use App\Models\TempLiveReading;
use Filament\Facades\Filament; use Filament\Facades\Filament;
use Filament\Forms; use Filament\Forms;
use Filament\Forms\Components\Section;
use Filament\Forms\Form; use Filament\Forms\Form;
use Filament\Resources\Resource; use Filament\Resources\Resource;
use Filament\Tables; use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Table; use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope; use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Forms\Components\Section;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Actions\ExportAction;
class TempLiveReadingResource extends Resource class TempLiveReadingResource extends Resource
{ {
protected static ?string $model = TempLiveReading::class; protected static ?string $model = TempLiveReading::class;
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack'; protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $navigationGroup = 'Power House'; protected static ?string $navigationGroup = 'Power House';
public static function form(Form $form): Form public static function form(Form $form): Form
@@ -42,7 +41,8 @@ class TempLiveReadingResource extends Resource
->required() ->required()
->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::orderBy('code')->pluck('name', 'id')->toArray();
}), }),
Forms\Components\Select::make('mfm_meter_id') Forms\Components\Select::make('mfm_meter_id')
->label('MFM Meter ID') ->label('MFM Meter ID')
@@ -50,7 +50,7 @@ class TempLiveReadingResource extends Resource
->reactive() ->reactive()
->options(function (callable $get) { ->options(function (callable $get) {
$plantId = $get('plant_id'); $plantId = $get('plant_id');
if (!$plantId) { if (! $plantId) {
return []; return [];
} }
@@ -78,6 +78,7 @@ class TempLiveReadingResource 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('plant.name') Tables\Columns\TextColumn::make('plant.name')
@@ -139,6 +140,7 @@ class TempLiveReadingResource extends Resource
// //
]; ];
} }
public static function getNavigationLabel(): string public static function getNavigationLabel(): string
{ {
return 'Live Readings'; return 'Live Readings';
@@ -149,7 +151,6 @@ class TempLiveReadingResource extends Resource
return 'Live Readings'; return 'Live Readings';
} }
public static function getPages(): array public static function getPages(): array
{ {
return [ return [

View File

@@ -63,7 +63,7 @@ class TestingPanelReadingResource 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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->default(function () { ->default(function () {
return optional(TestingPanelReading::latest()->first())->plant_id; return optional(TestingPanelReading::latest()->first())->plant_id;
@@ -480,7 +480,10 @@ class TestingPanelReadingResource extends Resource
->label('Select Plant') ->label('Select Plant')
->nullable() ->nullable()
->options(function () { ->options(function () {
return Plant::pluck('name', 'id'); // return Plant::pluck('name', 'id');
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->reactive() ->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {

View File

@@ -47,7 +47,7 @@ class WeightValidationResource 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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->required(), ->required(),
Forms\Components\Select::make('item_id') Forms\Components\Select::make('item_id')
@@ -168,7 +168,7 @@ class WeightValidationResource 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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->reactive(), ->reactive(),
// ->afterStateUpdated(function ($state, callable $set, callable $get) { // ->afterStateUpdated(function ($state, callable $set, callable $get) {
@@ -406,7 +406,7 @@ class WeightValidationResource 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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->label('Select Plant') ->label('Select Plant')
->required() ->required()

View File

@@ -45,7 +45,7 @@ class WorkGroupMasterResource 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::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->afterStateUpdated(function ($state, $set, callable $get) { ->afterStateUpdated(function ($state, $set, callable $get) {
$plantId = $get('plant_id'); $plantId = $get('plant_id');