Merge pull request 'ranjith-dev' (#325) from ranjith-dev into master
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled

Reviewed-on: #325
This commit was merged in pull request #325.
This commit is contained in:
2026-02-10 08:49:34 +00:00
41 changed files with 1891 additions and 1648 deletions

View File

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

View File

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

View File

@@ -5,34 +5,30 @@ namespace App\Filament\Resources;
use App\Filament\Exports\AlertMailRuleExporter;
use App\Filament\Imports\AlertMailRuleImporter;
use App\Filament\Resources\AlertMailRuleResource\Pages;
use App\Filament\Resources\AlertMailRuleResource\RelationManagers;
use App\Models\AlertMailRule;
use App\Models\InvoiceMaster;
use App\Models\Plant;
use Dotenv\Exception\ValidationException;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Components\Actions\Action;
use Filament\Forms\Components\Checkbox;
use Filament\Forms\Components\Section;
use Filament\Forms\Form;
use Filament\Notifications\Notification;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
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\DB;
use Illuminate\Validation\ValidationException as ValidationValidationException;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Actions\ExportAction;
class AlertMailRuleResource extends Resource
{
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';
@@ -47,7 +43,8 @@ class AlertMailRuleResource extends Resource
->reactive()
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
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'))
->afterStateUpdated(fn ($state, callable $set) => $state ? $set('is_active', false) : null),
@@ -166,6 +163,7 @@ class AlertMailRuleResource extends Resource
$paginator = $livewire->getTableRecords();
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}),
Tables\Columns\TextColumn::make('plant')
@@ -178,6 +176,7 @@ class AlertMailRuleResource extends Resource
if (! $plants) {
$plants = Plant::pluck('name', 'id')->toArray();
}
return $plants[$state] ?? 'All Plants';
}),
Tables\Columns\TextColumn::make('module')
@@ -260,14 +259,14 @@ class AlertMailRuleResource extends Resource
->label('Import Alert Mail Rule')
->color('warning')
->importer(AlertMailRuleImporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view import alert mail rule');
}),
ExportAction::make()
->label('Export Alert Mail Rule')
->color('warning')
->exporter(AlertMailRuleExporter::class)
->visible(function() {
->visible(function () {
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 Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Components\Section;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Forms\Components\Section;
use Filament\Tables\Actions\ExportAction;
use Illuminate\Validation\Rule;
class BlockResource extends Resource
@@ -46,12 +46,11 @@ class BlockResource extends Resource
->afterStateUpdated(function ($state, callable $set, callable $get) {
$nameId = $get('name');
// Ensure `linestop_id` is not cleared
if (!$nameId) {
if (! $nameId) {
$set('bNameError', 'Scan the valid name.');
return;
}
else
{
} else {
$set('bNameError', null);
}
})
@@ -72,21 +71,21 @@ class BlockResource extends Resource
->reactive()
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->default(function () {
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) {
$nameId = $get('plant_id');
// Ensure `linestop_id` is not cleared
if (!$nameId) {
if (! $nameId) {
$set('bPlantError', 'Please select a plant first.');
return;
}
else
{
} else {
$set('bPlantError', null);
}
})
@@ -117,10 +116,11 @@ class BlockResource extends Resource
$paginator = $livewire->getTableRecords();
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}),
Tables\Columns\TextColumn::make('name')
//->unique(ignoreRecord: true)
// ->unique(ignoreRecord: true)
->label('Block')
->alignCenter()
->sortable()
@@ -167,14 +167,14 @@ class BlockResource extends Resource
->label('Import Blocks')
->color('warning')
->importer(BlockImporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view import block');
}),
ExportAction::make()
->label('Export Blocks')
->color('warning')
->exporter(BlockExporter::class)
->visible(function() {
->visible(function () {
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\Models\CharacteristicApproverMaster;
use App\Models\Machine;
use App\Models\Plant;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Components\Section;
@@ -33,26 +34,38 @@ class CharacteristicApproverMasterResource extends Resource
Section::make('')
->schema([
Forms\Components\Select::make('plant_id')
->label('Plant')
->columnSpan(2)
->reactive()
->label('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()
->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) {
$set('machine_id', null);
$set('machine_name', null);
$set('approver_type', null);
$set('characteristic_field', null);
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\Select::make('machine_id')
->label('Work Center')
->columnSpan(2)
->columnSpan(1)
// ->relationship('machine', 'name')
->reactive()
->searchable()
->options(function (callable $get) {
$plantId = $get('plant_id');
if (empty($plantId)) {
if (! $plantId) {
return [];
}
@@ -60,30 +73,76 @@ class CharacteristicApproverMasterResource extends Resource
})
->required()
->default(function () {
return optional(CharacteristicApproverMaster::latest()->first())->machine_id ?? [];
return optional(CharacteristicApproverMaster::latest()->first())->machine_id ?? null;
})
->afterStateUpdated(function ($state, callable $set) {
$set('machine_name', null);
$set('approver_type', null);
$set('characteristic_field', null);
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('machine_name')
->label('Machine')
->columnSpan(2)
->columnSpan(1)
->reactive()
->required()
->minLength(5)
->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) {
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);
}),
Forms\Components\TextInput::make('characteristic_field')
->label('Master Characteristic Field')
->columnSpan(2)
->columnSpan(4)
->reactive()
->required()
->minLength(1)
->default('NIL')
->default(function () {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? null : 'NIL';
})
->afterStateUpdated(function ($state, callable $set) {
if (strtolower($state) == 'nil' || $state == '' || $state == null) {
$set('characteristic_field', 'NIL');
@@ -233,6 +292,11 @@ class CharacteristicApproverMasterResource extends Resource
->alignCenter()
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('approver_type')
->label('Approver Type')
->alignCenter()
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('characteristic_field')
->label('Master Characteristic Field')
->alignCenter()

View File

@@ -43,7 +43,7 @@ class CharacteristicValueResource extends Resource
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->reactive()
->afterStateUpdated(function ($state, $set, callable $get) {
@@ -296,7 +296,7 @@ class CharacteristicValueResource extends Resource
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->reactive()
->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\Imports\CheckPointNameImporter;
use App\Filament\Resources\CheckPointNameResource\Pages;
use App\Filament\Resources\CheckPointNameResource\RelationManagers;
use App\Models\CheckPointName;
use App\Models\Plant;
use Filament\Facades\Filament;
@@ -42,20 +41,20 @@ class CheckPointNameResource extends Resource
->reactive()
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->default(function () {
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) {
$plantId = $get('plant_id');
if (!$plantId) {
if (! $plantId) {
$set('cPnPlantError', 'Please select a plant first.');
return;
}
else
{
} else {
$set('cPnPlantError', null);
$set('created_by', Filament::auth()->user()?->name);
}
@@ -100,6 +99,7 @@ class CheckPointNameResource extends Resource
$paginator = $livewire->getTableRecords();
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}),
// Tables\Columns\TextColumn::make('id')
@@ -156,14 +156,14 @@ class CheckPointNameResource extends Resource
->label('Import Check Point Names')
->color('warning')
->importer(CheckPointNameImporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view import check point name');
}),
ExportAction::make()
->label('Export Check Point Names')
->color('warning')
->exporter(CheckPointNameExporter::class)
->visible(function() {
->visible(function () {
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\Imports\CheckPointTimeImporter;
use App\Filament\Resources\CheckPointTimeResource\Pages;
use App\Filament\Resources\CheckPointTimeResource\RelationManagers;
use App\Models\CheckPointName;
use App\Models\CheckPointTime;
use App\Models\Plant;
@@ -43,20 +42,20 @@ class CheckPointTimeResource extends Resource
->reactive()
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->default(function () {
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) {
$plantId = $get('plant_id');
if (!$plantId) {
if (! $plantId) {
$set('cPtPlantError', 'Please select a plant first.');
return;
}
else
{
} else {
$set('cPtPlantError', null);
$set('created_by', Filament::auth()->user()?->name);
}
@@ -80,15 +79,15 @@ class CheckPointTimeResource extends Resource
return Rule::unique('check_point_times', 'sequence_number')
->where('plant_id', $get('plant_id'))
->ignore($get('id'));
//->where('check_point1_id', $get('check_point1_id'))
//->where('check_point2_id', $get('check_point2_id'))
// ->where('check_point1_id', $get('check_point1_id'))
// ->where('check_point2_id', $get('check_point2_id'))
}),
Forms\Components\Select::make('check_point1_id')
->label('Check Point Name 1')
// ->relationship('checkPointNames', 'name')
->options(function (callable $get) {
$plantId = $get('plant_id');
if (!$plantId) {
if (! $plantId) {
return [];
}
@@ -101,19 +100,19 @@ class CheckPointTimeResource extends Resource
->default(function () {
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) {
$checkPoint1 = $get('check_point1_id');
$checkPoint2 = $get('check_point2_id');
if (!$checkPoint1) {
if (! $checkPoint1) {
$set('cPtCheckPoint1Error', 'Please select a check point 1 first.');
return;
}
else
{
} else {
if ($checkPoint2 && $checkPoint1 == $checkPoint2) {
$set('cPtCheckPoint1Error', 'Duplicate check point 2 found.');
$set('check_point2_id', null);
return;
}
$set('cPtCheckPoint1Error', null);
@@ -131,7 +130,7 @@ class CheckPointTimeResource extends Resource
// ->relationship('checkPointNames', 'name')
->options(function (callable $get) {
$plantId = $get('plant_id');
if (!$plantId) {
if (! $plantId) {
return [];
}
@@ -144,19 +143,19 @@ class CheckPointTimeResource extends Resource
->default(function () {
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) {
$checkPoint1 = $get('check_point1_id');
$checkPoint2 = $get('check_point2_id');
if (!$checkPoint2) {
if (! $checkPoint2) {
$set('cPtCheckPoint2Error', 'Please select a check point 2 first.');
return;
}
else
{
} else {
if ($checkPoint1 && $checkPoint1 == $checkPoint2) {
$set('cPtCheckPoint2Error', 'Duplicate check point 2 found.');
$set('check_point2_id', null);
return;
}
$set('cPtCheckPoint1Error', null);
@@ -185,32 +184,30 @@ class CheckPointTimeResource extends Resource
->afterStateUpdated(function ($state, callable $set, callable $get) {
$timeLapse = $state;
$timeLapseCushioning = $get('time_lapse_cushioning');
if (!$timeLapse) {
if (! $timeLapse) {
$set('cPtTimeLapseError', 'Please enter a valid time lapse!');
$set('time_lapse_cushioning', null);
$set('min_cushioning', null);
$set('max_cushioning', null);
return;
}
elseif(!$timeLapseCushioning)
{
} elseif (! $timeLapseCushioning) {
// $set('cPtTimeLapseError', 'Please enter a valid time lapse cushioning!');
$set('time_lapse_cushioning', 1);
$set('cPtTimeLapseError', null);
$set('min_cushioning', $timeLapse - 1);
$set('max_cushioning', $timeLapse + 1);
$set('created_by', Filament::auth()->user()?->name);
return;
}
elseif ($timeLapseCushioning > $timeLapse) {
} elseif ($timeLapseCushioning > $timeLapse) {
$set('cPtTimeLapseError', 'Must be greater than or equal to time lapse cushioning!');
$set('time_lapse_cushioning', null);
$set('min_cushioning', null);
$set('max_cushioning', null);
return;
}
else
{
} else {
$set('cPtTimeLapseError', null);
$set('cPtTimeLapseCushError', null);
$set('min_cushioning', $timeLapse - $timeLapseCushioning);
@@ -233,32 +230,30 @@ class CheckPointTimeResource extends Resource
->afterStateUpdated(function ($state, callable $set, callable $get) {
$timeLapse = $get('time_lapse');
$timeLapseCushioning = $state;
if (!$timeLapse) {
if (! $timeLapse) {
$set('cPtTimeLapseCushError', 'Please enter a valid time lapse first.');
$set('time_lapse_cushioning', null);
$set('min_cushioning', null);
$set('max_cushioning', null);
return;
}
elseif(!$timeLapseCushioning)
{
} elseif (! $timeLapseCushioning) {
// $set('cPtTimeLapseCushError', 'Please enter a valid time lapse cushioning!');
$set('time_lapse_cushioning', 1);
$set('cPtTimeLapseCushError', null);
$set('min_cushioning', $timeLapse - 1);
$set('max_cushioning', $timeLapse + 1);
$set('created_by', Filament::auth()->user()?->name);
return;
}
elseif ($timeLapseCushioning > $timeLapse) {
} elseif ($timeLapseCushioning > $timeLapse) {
$set('cPtTimeLapseCushError', 'Must be less than or equal to time lapse!');
$set('time_lapse_cushioning', null);
$set('min_cushioning', null);
$set('max_cushioning', null);
return;
}
else
{
} else {
$set('cPtTimeLapseError', null);
$set('cPtTimeLapseCushError', null);
$set('min_cushioning', $timeLapse - $timeLapseCushioning);
@@ -308,6 +303,7 @@ class CheckPointTimeResource extends Resource
$paginator = $livewire->getTableRecords();
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}),
// Tables\Columns\TextColumn::make('id')
@@ -387,14 +383,14 @@ class CheckPointTimeResource extends Resource
->label('Import Check Point Times')
->color('warning')
->importer(CheckPointTimeImporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view import check point time');
}),
ExportAction::make()
->label('Export Check Point Times')
->color('warning')
->exporter(CheckPointTimeExporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view export check point time');
}),
]);

View File

@@ -37,7 +37,7 @@ class ClassCharacteristicResource extends Resource
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->required(),
Forms\Components\Select::make('item_id')

View File

@@ -5,7 +5,6 @@ namespace App\Filament\Resources;
use App\Filament\Exports\ConfigurationExporter;
use App\Filament\Imports\ConfigurationImporter;
use App\Filament\Resources\ConfigurationResource\Pages;
use App\Filament\Resources\ConfigurationResource\RelationManagers;
use App\Models\Configuration;
use App\Models\Line;
use App\Models\Plant;
@@ -15,18 +14,20 @@ use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Actions\ExportAction;
class ConfigurationResource extends Resource
{
protected static ?string $model = Configuration::class;
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $navigationGroup = 'Master Entries';
protected static ?int $navigationSort = 10;
public static function form(Form $form): Form
@@ -40,20 +41,20 @@ class ConfigurationResource extends Resource
->reactive()
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->default(function () {
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) {
$plantId = $get('plant_id');
if (!$plantId) {
if (! $plantId) {
$set('cPlantError', 'Please select a plant first.');
return;
}
else
{
} else {
$set('cPlantError', null);
}
})
@@ -68,7 +69,7 @@ class ConfigurationResource extends Resource
->required()
->reactive()
->options(function (callable $get) {
if (!$get('plant_id')) {
if (! $get('plant_id')) {
return [];
}
@@ -79,15 +80,14 @@ class ConfigurationResource extends Resource
->default(function () {
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) {
$lineId = $get('line_id');
if (!$lineId) {
if (! $lineId) {
$set('cLineError', 'Please select a line first.');
return;
}
else
{
} else {
$set('cLineError', null);
}
})
@@ -124,6 +124,7 @@ class ConfigurationResource extends Resource
$paginator = $livewire->getTableRecords();
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}),
Tables\Columns\TextColumn::make('plant.name')
@@ -186,14 +187,14 @@ class ConfigurationResource extends Resource
->label('Import Configurations')
->color('warning')
->importer(ConfigurationImporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view import configuration');
}),
ExportAction::make()
->label('Export Configurations')
->color('warning')
->exporter(ConfigurationExporter::class)
->visible(function() {
->visible(function () {
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\Imports\DeviceMasterImporter;
use App\Filament\Resources\DeviceMasterResource\Pages;
use App\Filament\Resources\DeviceMasterResource\RelationManagers;
use App\Models\DeviceMaster;
use App\Models\Plant;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Components\Section;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Forms\Components\Section;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Actions\ExportAction;
class DeviceMasterResource extends Resource
{
protected static ?string $model = DeviceMaster::class;
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $navigationGroup = 'Power House';
public static function form(Form $form): Form
@@ -38,7 +38,8 @@ class DeviceMasterResource extends Resource
->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::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(),
Forms\Components\TextInput::make('name')
@@ -65,6 +66,7 @@ class DeviceMasterResource extends Resource
$paginator = $livewire->getTableRecords();
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}),
Tables\Columns\TextColumn::make('plant.name')
@@ -120,14 +122,14 @@ class DeviceMasterResource extends Resource
->label('Import Device Masters')
->color('warning')
->importer(DeviceMasterImporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view import device master');
}),
ExportAction::make()
->label('Export Device Masters')
->color('warning')
->exporter(DeviceMasterExporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view export device master');
}),
]);

View File

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

View File

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

View File

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

View File

@@ -56,7 +56,7 @@ class ItemResource extends Resource
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->default(function () {
return optional(Item::latest()->first())->plant_id;
@@ -251,7 +251,7 @@ class ItemResource extends Resource
->options(function (callable $get) {
$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()
->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(function (callable $get) {
// $userHas = Filament::auth()->user()->plant_id;
// return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
// return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
// })
// ->label('Select Plant')
// ->required()

View File

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

View File

@@ -48,7 +48,7 @@ class LocatorResource extends Resource
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->default(function () {
return optional(Locator::latest()->first())->plant_id;
@@ -194,7 +194,7 @@ class LocatorResource extends Resource
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get): void {

View File

@@ -45,7 +45,7 @@ class MachineResource extends Resource
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->default(function () {
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\Imports\MfmMeterImporter;
use App\Filament\Resources\MfmMeterResource\Pages;
use App\Filament\Resources\MfmMeterResource\RelationManagers;
use App\Models\DeviceMaster;
use App\Models\MfmMeter;
use App\Models\Plant;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Components\Section;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Forms\Components\Section;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Actions\ExportAction;
class MfmMeterResource extends Resource
{
@@ -42,15 +41,17 @@ class MfmMeterResource extends Resource
->required()
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
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')
//->relationship('device', 'name')
// ->relationship('device', 'name')
->options(function ($get) {
$plantId = $get('plant_id');
if (!$plantId) {
if (! $plantId) {
return [];
}
return DeviceMaster::where('plant_id', $plantId)->pluck('name', 'id');
})
->label('Device Name')
@@ -77,6 +78,7 @@ class MfmMeterResource extends Resource
$paginator = $livewire->getTableRecords();
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}),
Tables\Columns\TextColumn::make('plant.name')
@@ -126,14 +128,14 @@ class MfmMeterResource extends Resource
->label('Import MFM Meters')
->color('warning')
->importer(MfmMeterImporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view import mfm meter');
}),
ExportAction::make()
->label('Export MFM Meters')
->color('warning')
->exporter(MfmMeterExporter::class)
->visible(function() {
->visible(function () {
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\Imports\MfmParameterImporter;
use App\Filament\Resources\MfmParameterResource\Pages;
use App\Filament\Resources\MfmParameterResource\RelationManagers;
use App\Models\MfmParameter;
use App\Models\Plant;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Components\Section;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Forms\Components\Section;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Actions\ExportAction;
class MfmParameterResource extends Resource
{
protected static ?string $model = MfmParameter::class;
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $navigationGroup = 'Power House';
public static function form(Form $form): Form
@@ -39,7 +39,8 @@ class MfmParameterResource extends Resource
->reactive()
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->afterStateUpdated(function (callable $set) {
$set('device_master_id', null);
@@ -54,11 +55,11 @@ class MfmParameterResource extends Resource
->required(),
Forms\Components\Select::make('device_master_id')
->label('Device Master')
//->relationship('deviceName', 'name')
// ->relationship('deviceName', 'name')
->options(function (callable $get) {
$plantId = $get('plant_id');
if (!$plantId) {
if (! $plantId) {
return [];
}
@@ -82,7 +83,7 @@ class MfmParameterResource extends Resource
->options(function (callable $get) {
$plantId = $get('plant_id');
if (!$plantId) {
if (! $plantId) {
return [];
}
@@ -139,6 +140,7 @@ class MfmParameterResource extends Resource
$paginator = $livewire->getTableRecords();
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}),
Tables\Columns\TextColumn::make('plant.name')
@@ -212,14 +214,14 @@ class MfmParameterResource extends Resource
->label('Import MFM Parameters')
->color('warning')
->importer(MfmParameterImporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view import mfm parameter');
}),
ExportAction::make()
->label('Export MFM Parameters')
->color('warning')
->exporter(MfmParameterExporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view export mfm parameter');
}),
]);

View File

@@ -3,7 +3,6 @@
namespace App\Filament\Resources;
use App\Filament\Resources\MfmReadingResource\Pages;
use App\Filament\Resources\MfmReadingResource\RelationManagers;
use App\Models\MfmReading;
use App\Models\Plant;
use Filament\Facades\Filament;
@@ -31,7 +30,8 @@ class MfmReadingResource extends Resource
->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::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(),
Forms\Components\Select::make('mfm_meter_id')
@@ -72,6 +72,7 @@ class MfmReadingResource extends Resource
$paginator = $livewire->getTableRecords();
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}),
Tables\Columns\TextColumn::make('plant.name')

View File

@@ -49,7 +49,7 @@ class MotorTestingMasterResource extends Resource
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->default(function () {
return optional(MotorTestingMaster::latest()->first())->plant_id;
@@ -466,7 +466,7 @@ class MotorTestingMasterResource extends Resource
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {

View File

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

View File

@@ -49,7 +49,7 @@ class PalletValidationResource extends Resource
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
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) {
$set('pallet_number', null);
@@ -279,7 +279,7 @@ class PalletValidationResource extends Resource
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get): void {
@@ -529,7 +529,7 @@ class PalletValidationResource extends Resource
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->required()
->reactive()

View File

@@ -55,7 +55,7 @@ class ProductionLineStopResource extends Resource
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->default(function () {
return optional(ProductionLineStop::latest()->first())->plant_id;
@@ -430,7 +430,7 @@ class ProductionLineStopResource extends Resource
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {

View File

@@ -54,7 +54,7 @@ class ProductionPlanResource extends Resource
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->default(function () {
return optional(ProductionPlan::latest()->first())->plant_id;
@@ -576,7 +576,7 @@ class ProductionPlanResource extends Resource
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {

View File

@@ -63,7 +63,7 @@ class ProductionQuantityResource extends Resource
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
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(function () {
@@ -1035,7 +1035,7 @@ class ProductionQuantityResource extends Resource
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {

View File

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

View File

@@ -53,7 +53,7 @@ class ReworkLocatorInvoiceValidationResource extends Resource
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
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) {
$plantId = $get('plant_id');
@@ -456,7 +456,7 @@ class ReworkLocatorInvoiceValidationResource extends Resource
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get): void {

View File

@@ -55,7 +55,7 @@ class SerialValidationResource extends Resource
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->default(function () {
return optional(SerialValidation::latest()->first())->plant_id;
@@ -332,7 +332,7 @@ class SerialValidationResource extends Resource
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->label('Select Plant')
->required()
@@ -1038,7 +1038,7 @@ class SerialValidationResource extends Resource
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get): void {

View File

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

View File

@@ -2,6 +2,8 @@
namespace App\Filament\Resources;
use App\Filament\Exports\StickerPrintingExporter;
use App\Filament\Imports\StickerPrintingImporter;
use App\Filament\Resources\StickerPrintingResource\Pages;
use App\Models\Plant;
use App\Models\StickerPrinting;
@@ -11,14 +13,11 @@ use Filament\Forms\Components\Section;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
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
{
@@ -40,13 +39,14 @@ class StickerPrintingResource extends Resource
->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::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()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id');
if (!$plantId) {
if (! $plantId) {
$set('reference_number', null);
$set('serial_number', null);
$set('ivPlantError', 'Please select a plant first.');
@@ -64,7 +64,7 @@ class StickerPrintingResource extends Resource
Forms\Components\TextInput::make('reference_number')
->label('Reference Number')
->reactive()
->readOnly(fn (callable $get) => !empty($get('serial_number')))
->readOnly(fn (callable $get) => ! empty($get('serial_number')))
->extraAttributes([
'id' => 'invoice_number_input',
'x-data' => '{ value: "" }',
@@ -82,9 +82,9 @@ class StickerPrintingResource extends Resource
'x-data' => '{ value: "" }',
'x-model' => '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\Hidden::make('created_by')

View File

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

View File

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

View File

@@ -47,7 +47,7 @@ class WeightValidationResource extends Resource
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->required(),
Forms\Components\Select::make('item_id')
@@ -168,7 +168,7 @@ class WeightValidationResource extends Resource
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->reactive(),
// ->afterStateUpdated(function ($state, callable $set, callable $get) {
@@ -406,7 +406,7 @@ class WeightValidationResource extends Resource
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->label('Select Plant')
->required()

View File

@@ -45,7 +45,7 @@ class WorkGroupMasterResource extends Resource
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
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) {
$plantId = $get('plant_id');

View File

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