ranjith-dev #325

Merged
jothi merged 8 commits from ranjith-dev into master 2026-02-10 08:49:35 +00:00
41 changed files with 1891 additions and 1648 deletions

View File

@@ -30,6 +30,8 @@ class CharacteristicApproverMasterExporter extends Exporter
->label('WORK CENTER'), ->label('WORK CENTER'),
ExportColumn::make('machine_name') ExportColumn::make('machine_name')
->label('MACHINE NAME'), ->label('MACHINE NAME'),
ExportColumn::make('approver_type')
->label('APPROVER TYPE'),
ExportColumn::make('characteristic_field') ExportColumn::make('characteristic_field')
->label('MASTER CHARACTERISTIC FIELD'), ->label('MASTER CHARACTERISTIC FIELD'),
ExportColumn::make('name1') ExportColumn::make('name1')

View File

@@ -30,12 +30,14 @@ class RequestCharacteristicExporter extends Exporter
->label('WORK CENTER'), ->label('WORK CENTER'),
ExportColumn::make('work_flow_id') ExportColumn::make('work_flow_id')
->label('WORK FLOW ID'), ->label('WORK FLOW ID'),
ExportColumn::make('characteristicApproverMaster.machine_name')
->label('MACHINE NAME'),
ExportColumn::make('item.code') ExportColumn::make('item.code')
->label('ITEM CODE'), ->label('ITEM CODE'),
ExportColumn::make('aufnr') ExportColumn::make('aufnr')
->label('AUFNR'), ->label('JOB NUMBER'),
ExportColumn::make('characteristicApproverMaster.machine_name') ExportColumn::make('characteristicApproverMaster.approver_type')
->label('MACHINE NAME'), ->label('APPROVER TYPE'),
ExportColumn::make('characteristicApproverMaster.characteristic_field') ExportColumn::make('characteristicApproverMaster.characteristic_field')
->label('MASTER CHARACTERISTIC FIELD'), ->label('MASTER CHARACTERISTIC FIELD'),
ExportColumn::make('characteristic_name') ExportColumn::make('characteristic_name')

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

@@ -6,6 +6,7 @@ use App\Filament\Exports\CharacteristicApproverMasterExporter;
use App\Filament\Resources\CharacteristicApproverMasterResource\Pages; use App\Filament\Resources\CharacteristicApproverMasterResource\Pages;
use App\Models\CharacteristicApproverMaster; use App\Models\CharacteristicApproverMaster;
use App\Models\Machine; use App\Models\Machine;
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\Components\Section;
@@ -33,26 +34,38 @@ class CharacteristicApproverMasterResource extends Resource
Section::make('') Section::make('')
->schema([ ->schema([
Forms\Components\Select::make('plant_id') Forms\Components\Select::make('plant_id')
->label('Plant') ->label('Plant Name')
->columnSpan(2)
->reactive()
->relationship('plant', 'name') ->relationship('plant', 'name')
->columnSpan(1)
->reactive()
->searchable()
->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()
->default(function () { ->default(function () {
return optional(CharacteristicApproverMaster::latest()->first())->plant_id; $userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? null : optional(CharacteristicApproverMaster::latest()->first())->plant_id ?? null;
}) })
->afterStateUpdated(function ($state, callable $set) { ->afterStateUpdated(function ($state, callable $set) {
$set('machine_id', null);
$set('machine_name', null);
$set('approver_type', null);
$set('characteristic_field', null);
$set('updated_by', Filament::auth()->user()?->name); $set('updated_by', Filament::auth()->user()?->name);
}), }),
Forms\Components\Select::make('machine_id') Forms\Components\Select::make('machine_id')
->label('Work Center') ->label('Work Center')
->columnSpan(2) ->columnSpan(1)
// ->relationship('machine', 'name') // ->relationship('machine', 'name')
->reactive() ->reactive()
->searchable() ->searchable()
->options(function (callable $get) { ->options(function (callable $get) {
$plantId = $get('plant_id'); $plantId = $get('plant_id');
if (empty($plantId)) { if (! $plantId) {
return []; return [];
} }
@@ -60,30 +73,76 @@ class CharacteristicApproverMasterResource extends Resource
}) })
->required() ->required()
->default(function () { ->default(function () {
return optional(CharacteristicApproverMaster::latest()->first())->machine_id ?? []; return optional(CharacteristicApproverMaster::latest()->first())->machine_id ?? null;
}) })
->afterStateUpdated(function ($state, callable $set) { ->afterStateUpdated(function ($state, callable $set) {
$set('machine_name', null);
$set('approver_type', null);
$set('characteristic_field', null);
$set('updated_by', Filament::auth()->user()?->name); $set('updated_by', Filament::auth()->user()?->name);
}), }),
Forms\Components\TextInput::make('machine_name') Forms\Components\TextInput::make('machine_name')
->label('Machine') ->label('Machine')
->columnSpan(2) ->columnSpan(1)
->reactive() ->reactive()
->required() ->required()
->minLength(5) ->minLength(5)
->default(function () { ->default(function () {
return optional(CharacteristicApproverMaster::latest()->first())->machine_name ?? ''; $userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? null : optional(CharacteristicApproverMaster::latest()->first())->machine_name ?? null;
}) })
->afterStateUpdated(function ($state, callable $set) { ->afterStateUpdated(function ($state, callable $set) {
if (! $state) {
$set('approver_type', null);
$set('characteristic_field', null);
}
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\Select::make('approver_type')
->label('Request Type')
->columnSpan(1)
->reactive()
->nullable()
->searchable()
->required()
->options(function (callable $set, callable $get) {
$plantId = $get('plant_id');
$machineId = $get('machine_id');
$machineName = $get('machine_name');
if (! $plantId || ! $machineId || ! $machineName) {
$set('characteristic_field', null);
return [];
}
return [
'Characteristic' => 'Characteristic',
'Quality' => 'Quality',
];
})
->default(function () {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? null : 'Characteristic';
// return optional(CharacteristicApproverMaster::latest()->first())->approver_type ?? null;
})
->afterStateUpdated(function ($state, callable $set) {
$set('characteristic_field', null);
$set('updated_by', Filament::auth()->user()?->name); $set('updated_by', Filament::auth()->user()?->name);
}), }),
Forms\Components\TextInput::make('characteristic_field') Forms\Components\TextInput::make('characteristic_field')
->label('Master Characteristic Field') ->label('Master Characteristic Field')
->columnSpan(2) ->columnSpan(4)
->reactive() ->reactive()
->required() ->required()
->minLength(1) ->minLength(1)
->default('NIL') ->default(function () {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? null : 'NIL';
})
->afterStateUpdated(function ($state, callable $set) { ->afterStateUpdated(function ($state, callable $set) {
if (strtolower($state) == 'nil' || $state == '' || $state == null) { if (strtolower($state) == 'nil' || $state == '' || $state == null) {
$set('characteristic_field', 'NIL'); $set('characteristic_field', 'NIL');
@@ -233,6 +292,11 @@ class CharacteristicApproverMasterResource extends Resource
->alignCenter() ->alignCenter()
->searchable() ->searchable()
->sortable(), ->sortable(),
Tables\Columns\TextColumn::make('approver_type')
->label('Approver Type')
->alignCenter()
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('characteristic_field') Tables\Columns\TextColumn::make('characteristic_field')
->label('Master Characteristic Field') ->label('Master Characteristic Field')
->alignCenter() ->alignCenter()

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

@@ -7,6 +7,7 @@ use App\Filament\Resources\RequestCharacteristicResource\Pages;
use App\Models\CharacteristicApproverMaster; use App\Models\CharacteristicApproverMaster;
use App\Models\Item; use App\Models\Item;
use App\Models\Machine; use App\Models\Machine;
use App\Models\Plant;
use App\Models\RequestCharacteristic; use App\Models\RequestCharacteristic;
use Closure; use Closure;
use Filament\Facades\Filament; use Filament\Facades\Filament;
@@ -65,12 +66,20 @@ class RequestCharacteristicResource extends Resource
Section::make('') Section::make('')
->schema([ ->schema([
Forms\Components\Select::make('plant_id') Forms\Components\Select::make('plant_id')
->label('Plant') ->label('Plant Name')
->reactive()
->relationship('plant', 'name') ->relationship('plant', 'name')
->reactive()
->searchable()
->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()
->default(function () { ->default(function () {
return optional(RequestCharacteristic::latest()->first())->plant_id; $userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? null : optional(RequestCharacteristic::latest()->first())->plant_id ?? null;
}) })
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id'); $plantId = $get('plant_id');
@@ -80,8 +89,9 @@ class RequestCharacteristicResource extends Resource
$set('aufnr', null); $set('aufnr', null);
$set('machine_name', null); $set('machine_name', null);
$set('characteristic_approver_master_id', null); $set('characteristic_approver_master_id', null);
if (! $updRec && $plantId) { $set('approver_type', null);
$set('work_flow_id', self::isNewWorkFlow($get)); if (! $updRec) {
$set('work_flow_id', $plantId ? self::isNewWorkFlow($get) : null);
} }
$set('updated_by', Filament::auth()->user()?->name); $set('updated_by', Filament::auth()->user()?->name);
}) })
@@ -101,13 +111,16 @@ class RequestCharacteristicResource extends Resource
}) })
->required() ->required()
->default(function () { ->default(function () {
return optional(RequestCharacteristic::latest()->first())->machine_id ?? []; $userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? null : optional(RequestCharacteristic::latest()->first())->machine_id ?? null;
}) })
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('item_id', null); $set('item_id', null);
$set('aufnr', null); $set('aufnr', null);
$set('machine_name', null); $set('machine_name', null);
$set('characteristic_approver_master_id', null); $set('characteristic_approver_master_id', null);
$set('approver_type', null);
$set('updated_by', Filament::auth()->user()?->name); $set('updated_by', Filament::auth()->user()?->name);
}) })
->disabled(fn ($get) => self::isFieldDisabled($get)), ->disabled(fn ($get) => self::isFieldDisabled($get)),
@@ -115,6 +128,7 @@ class RequestCharacteristicResource extends Resource
->label('Work Flow ID') ->label('Work Flow ID')
->readOnly() ->readOnly()
->reactive() ->reactive()
->required()
->default(function ($state, callable $set, callable $get) { ->default(function ($state, callable $set, callable $get) {
$updRec = $get('id'); $updRec = $get('id');
if (! $updRec) { if (! $updRec) {
@@ -128,9 +142,10 @@ class RequestCharacteristicResource extends Resource
// ->ignore($get('id')); // ->ignore($get('id'));
// }), // }),
Forms\Components\Select::make('item_id') Forms\Components\Select::make('item_id')
->label('Item') ->label('Item Code')
// ->relationship('item', 'id') // ->relationship('item', 'id')
->reactive() ->reactive()
->required()
->searchable() ->searchable()
->options(function (callable $get) { ->options(function (callable $get) {
$plantId = $get('plant_id'); $plantId = $get('plant_id');
@@ -140,44 +155,64 @@ class RequestCharacteristicResource extends Resource
return Item::where('plant_id', $plantId)->pluck('code', 'id'); return Item::where('plant_id', $plantId)->pluck('code', 'id');
}) })
->required()
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
if (! $state) {
$set('aufnr', null); $set('aufnr', null);
}
$set('updated_by', Filament::auth()->user()?->name); $set('updated_by', Filament::auth()->user()?->name);
}) })
->default(function () { ->default(function () {
return optional(RequestCharacteristic::latest()->first())->item_id ?? []; $userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? null : optional(RequestCharacteristic::latest()->first())->item_id ?? null;
}) })
->disabled(fn ($get) => self::isFieldDisabled($get)), ->disabled(fn ($get) => self::isFieldDisabled($get)),
Forms\Components\TextInput::make('aufnr') Forms\Components\TextInput::make('aufnr')
->label('Aufnr') ->label('Job Number')
->reactive() ->reactive()
->required() ->required(function (callable $get) {
$item = $get('item_id');
if ($item) {
return true;
}
return false;
})
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('updated_by', Filament::auth()->user()?->name); $set('updated_by', Filament::auth()->user()?->name);
}) })
->default(function () { ->default(function () {
return optional(RequestCharacteristic::latest()->first())->aufnr ?? ''; $userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? null : optional(RequestCharacteristic::latest()->first())->aufnr ?? null;
}) })
->readOnly(fn ($get) => ($get('item_id') == null))
->disabled(fn ($get) => self::isFieldDisabled($get)), ->disabled(fn ($get) => self::isFieldDisabled($get)),
Forms\Components\Select::make('machine_name') Forms\Components\Select::make('machine_name')
->label('Machines') ->label('Machine Name')
->reactive() ->reactive()
->nullable() ->nullable()
->searchable() ->searchable()
->options(function (callable $get) { ->options(function (callable $set, callable $get) {
$plantId = $get('plant_id'); $plantId = $get('plant_id');
$machineId = $get('machine_id'); $machineId = $get('machine_id');
if (! $plantId || ! $machineId) { if (! $plantId || ! $machineId) {
$set('characteristic_name', null);
$set('current_value', null);
$set('update_value', null);
return []; return [];
} }
return CharacteristicApproverMaster::where('plant_id', $plantId)->where('machine_id', $machineId)->pluck('machine_name', 'machine_name')->unique(); return CharacteristicApproverMaster::where('plant_id', $plantId)->where('machine_id', $machineId)->pluck('machine_name', 'machine_name')->unique();
}) })
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('approver_type', null); // dd($get('characteristic_approver_master_id'));
$set('characteristic_approver_master_id', null); $set('characteristic_approver_master_id', null);
// dd($get('characteristic_approver_master_id')); $set('characteristic_name', null);
$set('current_value', null);
$set('update_value', null);
$set('updated_by', Filament::auth()->user()?->name); $set('updated_by', Filament::auth()->user()?->name);
}) })
->default(function () { ->default(function () {
@@ -185,60 +220,121 @@ class RequestCharacteristicResource extends Resource
$reqId = RequestCharacteristic::latest()->first()?->characteristic_approver_master_id; $reqId = RequestCharacteristic::latest()->first()?->characteristic_approver_master_id;
if ($reqId) { if ($reqId) {
$reqMac = CharacteristicApproverMaster::where('id', $reqId)->first()?->machine_name; $reqMac = CharacteristicApproverMaster::where('id', $reqId)->first()?->machine_name;
if ($reqMac) { $machineName = $reqMac ?? null;
$machineName = $reqMac;
} else {
$machineName = null;
}
} else { } else {
$machineName = null; $machineName = null;
} }
// return optional(RequestCharacteristic::latest()->first())->characteristic_approver_master_id ?? []; $userHas = Filament::auth()->user()->plant_id;
return $machineName ?? [];
return ($userHas && strlen($userHas) > 0) ? null : $machineName ?? null;
}) })
->afterStateHydrated(function ($component, $state, Get $get, Set $set) { ->afterStateHydrated(function ($component, $state, Get $get, Set $set) {
if ($get('id')) { if ($get('id')) {
$reqId = RequestCharacteristic::where('id', $get('id'))->first()?->characteristic_approver_master_id; $reqId = RequestCharacteristic::where('id', $get('id'))->first()?->characteristic_approver_master_id;
if ($reqId) { if ($reqId) {
$reqMac = CharacteristicApproverMaster::where('id', $reqId)->first()?->machine_name; $reqMac = CharacteristicApproverMaster::where('id', $reqId)->first()?->machine_name;
if ($reqMac) { $set('machine_name', $reqMac ?? null);
$set('machine_name', $reqMac);
} else {
$set('machine_name', null);
}
} else { } else {
$set('machine_name', null); $set('machine_name', null);
} }
} }
}) })
->required(), ->required(),
Forms\Components\Select::make('characteristic_approver_master_id') Forms\Components\Select::make('approver_type')
->label('Master Characteristic Field') ->label('Request Type')
// ->relationship('characteristicApproverMaster', 'characteristic_field') // ->columnSpan(1)
->reactive() ->reactive()
->nullable() ->nullable()
->searchable() ->searchable()
->options(function (callable $get) { ->required()
->options(function (callable $set, callable $get) {
$plantId = $get('plant_id'); $plantId = $get('plant_id');
$machineId = $get('machine_id'); $machineId = $get('machine_id');
$machineName = $get('machine_name'); $machineName = $get('machine_name');
if (! $plantId || ! $machineId || ! $machineName) { if (! $plantId || ! $machineId || ! $machineName) {
$set('characteristic_name', null);
$set('current_value', null);
$set('update_value', null);
return []; return [];
} }
return CharacteristicApproverMaster::where('plant_id', $plantId)->where('machine_id', $machineId)->where('machine_name', $machineName)->pluck('characteristic_field', 'id'); return [
}) 'Characteristic' => 'Characteristic',
->default(function () { 'Quality' => 'Quality',
return optional(RequestCharacteristic::latest()->first())->characteristic_approver_master_id ?? []; ];
}) })
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('characteristic_approver_master_id', null);
if ($get('approver_type') != 'Characteristic') {
$set('characteristic_name', null);
$set('current_value', null);
$set('update_value', null);
}
$set('updated_by', Filament::auth()->user()?->name);
})
->default(function () {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? null : 'Characteristic';
// $approverType = null;
// $reqId = RequestCharacteristic::latest()->first()?->characteristic_approver_master_id;
// if ($reqId) {
// $reqTyp = CharacteristicApproverMaster::where('id', $reqId)->first()?->approver_type;
// $approverType = $reqTyp ?? null;
// } else {
// $approverType = null;
// }
// // return optional(CharacteristicApproverMaster::latest()->first())->approver_type ?? null;
// return $approverType ?? null;
})
->afterStateHydrated(function ($component, $state, Get $get, Set $set) {
if ($get('id')) {
$reqId = RequestCharacteristic::where('id', $get('id'))->first()?->characteristic_approver_master_id;
if ($reqId) {
$reqTyp = CharacteristicApproverMaster::where('id', $reqId)->first()?->approver_type;
$set('approver_type', $reqTyp ?? null);
} else {
$set('approver_type', null);
}
}
}),
Forms\Components\Select::make('characteristic_approver_master_id')
->label('Master Characteristic Field')
// ->relationship('characteristicApproverMaster', 'characteristic_field')
->columnSpan(2)
->reactive()
->nullable()
->searchable()
->options(function (callable $set, callable $get) {
$plantId = $get('plant_id');
$machineId = $get('machine_id');
$machineName = $get('machine_name');
$reqTyp = $get('approver_type');
if (! $plantId || ! $machineId || ! $machineName || ! $reqTyp) {
return [];
}
return CharacteristicApproverMaster::where('plant_id', $plantId)->where('machine_id', $machineId)->where('machine_name', $machineName)->where('approver_type', $reqTyp)->pluck('characteristic_field', 'id');
})
->default(function () {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? null : optional(RequestCharacteristic::latest()->first())->characteristic_approver_master_id ?? null;
})
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('characteristic_name', null);
$set('current_value', null);
$set('update_value', null);
$set('updated_by', Filament::auth()->user()?->name); $set('updated_by', Filament::auth()->user()?->name);
}) })
->required(), ->required(),
// ->disabled(fn ($get) => self::isFieldDisabled($get)) // ->disabled(fn ($get) => self::isFieldDisabled($get))
Section::make('Request Characteristic Field') Section::make('Request Characteristic Details')
// ->columnSpan(['default' => 2, 'sm' => 4]) // ->columnSpan(['default' => 2, 'sm' => 4])
->reactive() ->reactive()
->schema([ ->schema([
@@ -249,7 +345,14 @@ class RequestCharacteristicResource extends Resource
$set('characteristic_name', strtoupper($state)); $set('characteristic_name', strtoupper($state));
$set('updated_by', Filament::auth()->user()?->name); $set('updated_by', Filament::auth()->user()?->name);
}) })
->required() ->required(function (callable $get) {
$reqTyp = $get('approver_type');
if ($reqTyp == 'Characteristic') {
return true;
}
return false;
})
->rules([ ->rules([
// function (callable $get) { // function (callable $get) {
// return Rule::unique('request_characteristics', 'characteristic_name') // return Rule::unique('request_characteristics', 'characteristic_name')
@@ -288,7 +391,7 @@ class RequestCharacteristicResource extends Resource
}; };
}, },
]) ])
->readOnly(fn ($get) => self::isFieldDisabled($get)), // disabled ->readOnly(fn ($get) => ($get('approver_type') != 'Characteristic') ?? self::isFieldDisabled($get)),
Forms\Components\TextInput::make('current_value') Forms\Components\TextInput::make('current_value')
->label('Current Value') ->label('Current Value')
->reactive() ->reactive()
@@ -296,14 +399,15 @@ class RequestCharacteristicResource extends Resource
$set('updated_by', Filament::auth()->user()?->name); $set('updated_by', Filament::auth()->user()?->name);
}) })
->required(function (callable $get) { ->required(function (callable $get) {
$reqTyp = $get('approver_type');
$updateVal = $get('update_value'); $updateVal = $get('update_value');
if ($updateVal == null || $updateVal == '') { if ($reqTyp == 'Characteristic' && ($updateVal == null || $updateVal == '')) {
return true; return true;
} }
return false; return false;
}) })
->readOnly(fn ($get) => self::isFieldDisabled($get)), ->readOnly(fn ($get) => ($get('approver_type') != 'Characteristic') ?? self::isFieldDisabled($get)),
Forms\Components\TextInput::make('update_value') Forms\Components\TextInput::make('update_value')
->label('Update Value') ->label('Update Value')
->reactive() ->reactive()
@@ -321,9 +425,17 @@ class RequestCharacteristicResource extends Resource
}; };
}, },
]) ])
->readOnly(fn ($get) => self::isFieldDisabled($get)), ->readOnly(fn ($get) => ($get('approver_type') != 'Characteristic') ?? self::isFieldDisabled($get)),
]) ])
->collapsible() // ->collapsed(function ($get): bool {
// $reqTyp = $get('approver_type');
// if ($reqTyp == 'Characteristic') {
// return true;
// }
// return false;
// })
->collapsed()
->columns(['default' => 1, 'sm' => 3]), ->columns(['default' => 1, 'sm' => 3]),
Section::make(function ($get): string { Section::make(function ($get): string {
$approverId = $get('characteristic_approver_master_id'); $approverId = $get('characteristic_approver_master_id');
@@ -338,16 +450,19 @@ class RequestCharacteristicResource extends Resource
Forms\Components\Select::make('approver_status1') Forms\Components\Select::make('approver_status1')
->label('Approver Status') ->label('Approver Status')
->reactive() ->reactive()
->live() // ->live()
->options([ ->options([
'Approved' => 'Approved', 'Approved' => 'Approved',
'Hold' => 'Hold', 'Hold' => 'Hold',
'Rejected' => 'Rejected', 'Rejected' => 'Rejected',
]) ])
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
if ($state && empty($get('approved1_at'))) { if ($state) {// && empty($get('approved1_at'))
$set('approved1_at', now()); $set('approved1_at', now()->toDateTimeString()); // now()->format('d-m-Y H:i:s')
} else {
$set('approved1_at', null);
} }
$set('approver_remark1', null);
$set('updated_by', Filament::auth()->user()?->name); $set('updated_by', Filament::auth()->user()?->name);
}) })
->disabled(function ($get) { ->disabled(function ($get) {
@@ -377,10 +492,17 @@ class RequestCharacteristicResource extends Resource
}), }),
Forms\Components\TextInput::make('approver_remark1') Forms\Components\TextInput::make('approver_remark1')
->label('Approver Remark') ->label('Approver Remark')
->reactive() ->live()
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$appStat = $get('approver_status1');
if ($appStat && $state) {
$set('approved1_at', now()->toDateTimeString()); // now()->format('d-m-Y H:i:s')
} else {
$set('approved1_at', null);
}
$set('updated_by', Filament::auth()->user()?->name); $set('updated_by', Filament::auth()->user()?->name);
}) })
->readOnly(fn ($get) => ($get('approver_status1') == null))
->disabled(function ($get) { ->disabled(function ($get) {
$currentUser = Filament::auth()->user(); $currentUser = Filament::auth()->user();
$updId = $get('id'); $updId = $get('id');
@@ -402,10 +524,12 @@ class RequestCharacteristicResource extends Resource
default => 'Updated At', default => 'Updated At',
}) })
->reactive() ->reactive()
->live() // ->live()
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('updated_by', Filament::auth()->user()?->name); $set('updated_by', Filament::auth()->user()?->name);
}) })
// ->format('d-m-Y H:i:s')
->readOnly(fn ($get) => ($get('approver_status1') == null))
->disabled(function ($get) { ->disabled(function ($get) {
$currentUser = Filament::auth()->user(); // logged-in user $currentUser = Filament::auth()->user(); // logged-in user
$approverId = $get('characteristic_approver_master_id'); $approverId = $get('characteristic_approver_master_id');
@@ -448,9 +572,12 @@ class RequestCharacteristicResource extends Resource
'Rejected' => 'Rejected', 'Rejected' => 'Rejected',
]) ])
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
if ($state && empty($get('approved2_at'))) { if ($state) {
$set('approved2_at', now()); $set('approved2_at', now()->toDateTimeString());
} else {
$set('approved2_at', null);
} }
$set('approver_remark2', null);
$set('updated_by', Filament::auth()->user()?->name); $set('updated_by', Filament::auth()->user()?->name);
}) })
->disabled(function ($get) { ->disabled(function ($get) {
@@ -480,10 +607,17 @@ class RequestCharacteristicResource extends Resource
}), }),
Forms\Components\TextInput::make('approver_remark2') Forms\Components\TextInput::make('approver_remark2')
->label('Approver Remark') ->label('Approver Remark')
->reactive() ->live()
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$appStat = $get('approver_status2');
if ($appStat && $state) {
$set('approved2_at', now()->toDateTimeString());
} else {
$set('approved2_at', null);
}
$set('updated_by', Filament::auth()->user()?->name); $set('updated_by', Filament::auth()->user()?->name);
}) })
->readOnly(fn ($get) => ($get('approver_status2') == null))
->disabled(function ($get) { ->disabled(function ($get) {
$currentUser = Filament::auth()->user(); $currentUser = Filament::auth()->user();
$updId = $get('id'); $updId = $get('id');
@@ -507,6 +641,7 @@ class RequestCharacteristicResource extends Resource
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('updated_by', Filament::auth()->user()?->name); $set('updated_by', Filament::auth()->user()?->name);
}) })
->readOnly(fn ($get) => ($get('approver_status2') == null))
->disabled(function ($get) { ->disabled(function ($get) {
$currentUser = Filament::auth()->user(); // logged-in user $currentUser = Filament::auth()->user(); // logged-in user
$approverId = $get('characteristic_approver_master_id'); $approverId = $get('characteristic_approver_master_id');
@@ -550,9 +685,12 @@ class RequestCharacteristicResource extends Resource
'Rejected' => 'Rejected', 'Rejected' => 'Rejected',
]) ])
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
if ($state && empty($get('approved3_at'))) { if ($state) {
$set('approved3_at', now()); $set('approved3_at', now()->toDateTimeString());
} else {
$set('approved3_at', null);
} }
$set('approver_remark3', null);
$set('updated_by', Filament::auth()->user()?->name); $set('updated_by', Filament::auth()->user()?->name);
}) })
->disabled(function ($get) { ->disabled(function ($get) {
@@ -581,10 +719,17 @@ class RequestCharacteristicResource extends Resource
}), }),
Forms\Components\TextInput::make('approver_remark3') Forms\Components\TextInput::make('approver_remark3')
->label('Approver Remark') ->label('Approver Remark')
->reactive() ->live()
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$appStat = $get('approver_status3');
if ($appStat && $state) {
$set('approved3_at', now()->toDateTimeString());
} else {
$set('approved3_at', null);
}
$set('updated_by', Filament::auth()->user()?->name); $set('updated_by', Filament::auth()->user()?->name);
}) })
->readOnly(fn ($get) => ($get('approver_status3') == null))
->disabled(function ($get) { ->disabled(function ($get) {
$currentUser = Filament::auth()->user(); $currentUser = Filament::auth()->user();
$updId = $get('id'); $updId = $get('id');
@@ -608,6 +753,7 @@ class RequestCharacteristicResource extends Resource
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('updated_by', Filament::auth()->user()?->name); $set('updated_by', Filament::auth()->user()?->name);
}) })
->readOnly(fn ($get) => ($get('approver_status3') == null))
->disabled(function ($get) { ->disabled(function ($get) {
$currentUser = Filament::auth()->user(); // logged-in user $currentUser = Filament::auth()->user(); // logged-in user
$approverId = $get('characteristic_approver_master_id'); $approverId = $get('characteristic_approver_master_id');
@@ -695,12 +841,12 @@ class RequestCharacteristicResource extends Resource
$lastSerial = substr($lastWorkflow->work_flow_id, strlen($prefix)); $lastSerial = substr($lastWorkflow->work_flow_id, strlen($prefix));
$nextSerial = str_pad( $nextSerial = str_pad(
intval($lastSerial) + 1, intval($lastSerial) + 1,
3, 4,
'0', '0',
STR_PAD_LEFT STR_PAD_LEFT
); );
} else { } else {
$nextSerial = '001'; $nextSerial = '0001';
} }
$workFlowId = "{$prefix}{$nextSerial}"; $workFlowId = "{$prefix}{$nextSerial}";
@@ -726,7 +872,7 @@ class RequestCharacteristicResource extends Resource
->alignCenter() ->alignCenter()
->searchable(), // isIndividual: true ->searchable(), // isIndividual: true
Tables\Columns\TextColumn::make('plant.name') Tables\Columns\TextColumn::make('plant.name')
->label('Plant') ->label('Plant Name')
->alignCenter() ->alignCenter()
->searchable() ->searchable()
->sortable(), ->sortable(),
@@ -741,17 +887,22 @@ class RequestCharacteristicResource extends Resource
->searchable() ->searchable()
->sortable(), ->sortable(),
Tables\Columns\TextColumn::make('aufnr') Tables\Columns\TextColumn::make('aufnr')
->label('Aufnr') ->label('Job Number')
->alignCenter() ->alignCenter()
->searchable() ->searchable()
->sortable(), ->sortable(),
Tables\Columns\TextColumn::make('characteristicApproverMaster.machine_name') Tables\Columns\TextColumn::make('characteristicApproverMaster.machine_name')
->label('Machine') ->label('Machine Name')
->alignCenter()
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('characteristicApproverMaster.approver_type')
->label('Request Type')
->alignCenter() ->alignCenter()
->searchable() ->searchable()
->sortable(), ->sortable(),
Tables\Columns\TextColumn::make('characteristicApproverMaster.characteristic_field') Tables\Columns\TextColumn::make('characteristicApproverMaster.characteristic_field')
->label('Master Characteristic') ->label('Master Characteristic Field')
->alignCenter() ->alignCenter()
->searchable() ->searchable()
->formatStateUsing(fn (string $state): string => strtoupper(__($state))) ->formatStateUsing(fn (string $state): string => strtoupper(__($state)))

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');

View File

@@ -15,6 +15,7 @@ class CharacteristicApproverMaster extends Model
'machine_id', 'machine_id',
'machine_name', 'machine_name',
'characteristic_field', 'characteristic_field',
'approver_type',
'name1', 'name1',
'mail1', 'mail1',
'name2', 'name2',
@@ -39,4 +40,9 @@ class CharacteristicApproverMaster extends Model
{ {
return $this->belongsTo(Machine::class); return $this->belongsTo(Machine::class);
} }
public function requestCharacteristics()
{
return $this->hasMany(RequestCharacteristic::class, 'characteristic_approver_master_id');
}
} }