Merge pull request 'ranjith-dev' (#983) from ranjith-dev into master
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 17s

Reviewed-on: #983
This commit was merged in pull request #983.
This commit is contained in:
2026-09-05 10:47:17 +00:00
16 changed files with 1046 additions and 15 deletions

View File

@@ -4,6 +4,7 @@ namespace App\Console\Commands;
use App\Mail\PanelBoxReportMail;
use App\Models\Machine;
use App\Models\PanelBoxValidation;
use App\Models\Plant;
use App\Models\ProductionCharacteristic;
use Illuminate\Console\Command;
@@ -94,6 +95,15 @@ class SendPanelBoxReport extends Command
->distinct()
->get();
foreach ($records as $record) {
$supplierNumber = PanelBoxValidation::where('plant_id', $plantId)
->where('serial_number', $record->serial_number)
->first()?->panel_box_supplier;
$record->panel_box_supplier = $supplierNumber;
}
if ($records->isEmpty()) {
$this->info('No panel box records found.');
return;

View File

@@ -0,0 +1,79 @@
<?php
namespace App\Filament\Exports;
use App\Models\ModelMaster;
use Filament\Actions\Exports\ExportColumn;
use Filament\Actions\Exports\Exporter;
use Filament\Actions\Exports\Models\Export;
class ModelMasterExporter extends Exporter
{
protected static ?string $model = ModelMaster::class;
public static function getColumns(): array
{
return [
ExportColumn::make('no')
->label('NO')
->state(function ($record) use (&$rowNumber) {
// Increment and return the row number
return ++$rowNumber;
}),
ExportColumn::make('plant.code')
->label('PLANT CODE'),
ExportColumn::make('machine.work_center')
->label('WORK CENTER'),
ExportColumn::make('heading_name')
->label('HEADING NAME'),
ExportColumn::make('heading_value')
->label('HEADING VALUE'),
ExportColumn::make('type_name')
->label('TYPE NAME'),
ExportColumn::make('type_value')
->label('TYPE VALUE'),
ExportColumn::make('has_motor')
->label('HAS MOTOR'),
ExportColumn::make('has_m_part')
->label('HAS MOTOR PART'),
ExportColumn::make('has_m_count')
->label('HAS MOTOR COUNT'),
ExportColumn::make('has_pump')
->label('HAS PUMP'),
ExportColumn::make('has_p_part')
->label('HAS PUMP PART'),
ExportColumn::make('has_p_count')
->label('HAS PUMP COUNT'),
ExportColumn::make('has_name_plate')
->label('HAS NAME PLATE'),
ExportColumn::make('has_np_part')
->label('HAS NAME PLATE PART'),
ExportColumn::make('has_np_count')
->label('HAS NAME PLATE COUNT'),
ExportColumn::make('created_at')
->label('CREATED AT'),
ExportColumn::make('created_by')
->label('CREATED BY'),
ExportColumn::make('updated_at')
->label('UPDATED AT')
->enabledByDefault(true),
ExportColumn::make('updated_by')
->label('UPDATED BY')
->enabledByDefault(true),
ExportColumn::make('deleted_at')
->label('DELETED AT')
->enabledByDefault(false),
];
}
public static function getCompletedNotificationBody(Export $export): string
{
$body = 'Your model master export has completed and '.number_format($export->successful_rows).' '.str('row')->plural($export->successful_rows).' exported.';
if ($failedRowsCount = $export->getFailedRowsCount()) {
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to export.';
}
return $body;
}
}

View File

@@ -0,0 +1,249 @@
<?php
namespace App\Filament\Imports;
use App\Models\Machine;
use App\Models\ModelMaster;
use App\Models\Plant;
use Filament\Actions\Imports\Exceptions\RowImportFailedException;
use Filament\Actions\Imports\ImportColumn;
use Filament\Actions\Imports\Importer;
use Filament\Actions\Imports\Models\Import;
use Filament\Facades\Filament;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Str;
class ModelMasterImporter extends Importer
{
protected static ?string $model = ModelMaster::class;
public static function getColumns(): array
{
return [
ImportColumn::make('plant')
->label('PLANT CODE')
->requiredMapping()
->exampleHeader('PLANT CODE')
->example('1000')
->relationship(resolveUsing: 'code')
->rules(['required']),
ImportColumn::make('machine')
->label('WORK CENTER')
->requiredMapping()
->exampleHeader('WORK CENTER')
->example('RMGLAS01')
->relationship(resolveUsing: 'work_center')
->rules(['required']),
ImportColumn::make('heading_name')
->label('HEADING NAME')
->exampleHeader('HEADING NAME')
->example('ZMM_HEADING'),
ImportColumn::make('heading_value')
->label('HEADING VALUE')
->exampleHeader('HEADING VALUE')
->example('PUMPS'),
ImportColumn::make('type_name')
->label('TYPE NAME')
->exampleHeader('TYPE NAME')
->example(''),
ImportColumn::make('type_value')
->label('TYPE VALUE')
->exampleHeader('TYPE VALUE')
->example(''),
ImportColumn::make('has_motor')
->label('HAS MOTOR')
->exampleHeader('HAS MOTOR')
->example('1'),
ImportColumn::make('has_m_part')
->label('HAS MOTOR PART')
->exampleHeader('HAS MOTOR PART')
->example('1'),
ImportColumn::make('has_m_count')
->label('HAS MOTOR COUNT')
->exampleHeader('HAS MOTOR COUNT')
->example('1'),
ImportColumn::make('has_pump')
->label('HAS PUMP')
->exampleHeader('HAS PUMP')
->example('1'),
ImportColumn::make('has_p_part')
->label('HAS PUMP PART')
->exampleHeader('HAS PUMP PART')
->example('1'),
ImportColumn::make('has_p_count')
->label('HAS PUMP COUNT')
->exampleHeader('HAS PUMP COUNT')
->example('1'),
ImportColumn::make('has_name_plate')
->label('HAS NAME PLATE')
->exampleHeader('HAS NAME PLATE')
->example(''),
ImportColumn::make('has_np_part')
->label('HAS NAME PLATE PART')
->exampleHeader('HAS NAME PLATE PART')
->example(''),
ImportColumn::make('has_np_count')
->label('HAS NAME PLATE COUNT')
->exampleHeader('HAS NAME PLATE COUNT')
->example(''),
];
}
public function resolveRecord(): ?ModelMaster
{
$warnMsg = [];
$plantCod = trim($this->data['plant']);
$plant = null;
$plantId = null;
$workCent = trim($this->data['machine']);
$machine = null;
$machineId = null;
$headingName = strtoupper(trim($this->data['heading_name']));
$headingValue = strtoupper(trim($this->data['heading_value']));
$typeName = strtoupper(trim($this->data['type_name']));
$typeValue = (Str::length($typeName) <= 0) ? '' : strtoupper(trim($this->data['type_value']));
$hasMotor = (trim($this->data['has_motor']) == '1') ? '1' : '0';
$hasMPart = (trim($this->data['has_m_part']) == '1') ? '1' : '0';
$hasMCount = ($hasMotor == '1') ? trim($this->data['has_m_count']) : '0';
$hasPump = (trim($this->data['has_pump']) == '1') ? '1' : '0';
$hasPPart = (trim($this->data['has_p_part']) == '1') ? '1' : '0';
$hasPCount = ($hasPump == '1') ? trim($this->data['has_p_count']) : '0';
$hasNamePlate = (trim($this->data['has_name_plate']) == '1') ? '1' : '0';
$hasNpPart = (trim($this->data['has_np_part']) == '1') ? '1' : '0';
$hasNpCount = ($hasNamePlate == '1') ? trim($this->data['has_np_count']) : '0';
$createdBy = Filament::auth()->user()->name;
$updatedBy = Filament::auth()->user()->name;
if ($plantCod == null || $plantCod == '' || ! $plantCod) {
$warnMsg[] = "Plant code can't be empty!";
} elseif (! is_numeric($plantCod)) {
$warnMsg[] = "Plant code '{$plantCod}' should contain only numeric values!";
} elseif (Str::length($plantCod) < 4 || Str::length($plantCod) > 7) {
$warnMsg[] = "Plant code '{$plantCod}' must be between 4 and 7 digits only!";
} elseif (! preg_match('/^[1-9]\d{3,6}$/', $plantCod)) {
$warnMsg[] = "Invalid plant code '{$plantCod}' found!";
}
if ($workCent == null || $workCent == '' || ! $workCent) {
$warnMsg[] = "Work center can't be empty!";
} elseif (Str::length($workCent) < 6) {
$warnMsg[] = "Work center '{$workCent}' should contain minimum 6 characters!";
} elseif (! ctype_alnum($workCent)) {
$warnMsg[] = "Work center '{$workCent}' should contain only alpha-numeric values!";
} elseif (! preg_match('/^[a-zA-Z0-9]{6,}$/', $workCent)) {
$warnMsg[] = "Invalid work center '{$workCent}' found!";
}
$columns = Schema::getColumnListing('class_characteristics');
if ($headingName == null || $headingName == '' || ! $headingName) {
$warnMsg[] = "Heading name can't be empty!";
} elseif (Str::length($headingName) < 5) {
$warnMsg[] = "Heading name '{$headingName}' should contain minimum 5 characters!";
} else {
if (! in_array($headingName, $columns, true)) {
$warnMsg[] = 'Unknown heading name found!';
}
}
if ($typeName != null && $typeName != '' && $typeName) {
if (Str::length($typeName) < 5) {
$warnMsg[] = "Type name '{$typeName}' should contain minimum 5 characters!";
} else {
if (! in_array($typeName, $columns, true)) {
$warnMsg[] = 'Unknown type name found!';
}
}
}
if ($hasMotor != '1') {
$hasMPart = '0';
$hasMCount = '0';
} else {
$hasMPart = ($hasMPart != '1') ? '0' : '1';
$hasMCount = ($hasMCount == '0' || empty($hasMCount) || ! is_numeric($hasMCount) || ! preg_match('/^([1-9]|[1-9][0-9])$/', $hasMCount)) ? '1' : $hasMCount;
}
if ($hasPump != '1') {
$hasPPart = '0';
$hasPCount = '0';
} else {
$hasPPart = ($hasPPart != '1') ? '0' : '1';
$hasPCount = ($hasPCount == '0' || empty($hasPCount) || ! is_numeric($hasPCount) || ! preg_match('/^([1-9]|[1-9][0-9])$/', $hasPCount)) ? '1' : $hasPCount;
}
if ($hasNamePlate != '1') {
$hasNpPart = '0';
$hasNpCount = '0';
} else {
$hasNpPart = ($hasNpPart != '1') ? '0' : '1';
$hasNpCount = ($hasNpCount == '0' || empty($hasNpCount) || ! is_numeric($hasNpCount) || ! preg_match('/^([1-9]|[1-9][0-9])$/', $hasNpCount)) ? '1' : $hasNpCount;
}
$plant = Plant::where('code', $plantCod)->first();
if (! $plant) {
$warnMsg[] = 'Plant code not found!';
} else {
$plantId = $plant->id;
$machine = Machine::where('work_center', $workCent)->first();
if (! $machine) {
$warnMsg[] = 'Work center not found!';
} else {
$machine = Machine::where('work_center', $workCent)->where('plant_id', $plantId)->first();
if (! $machine) {
$warnMsg[] = 'Work center not found for the plant!';
} else {
$machineId = $machine->id;
if (empty($warnMsg)) {
$recExist = ModelMaster::where('plant_id', $plantId)->where('machine_id', $machineId)->where('heading_name', $headingName)->where('heading_value', $headingValue)->where('type_name', $typeName)->where('type_value', $typeValue)->first()?->created_by;
if ($recExist) {
$createdBy = $recExist;
}
}
}
}
}
if (! empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg));
}
return ModelMaster::updateOrCreate([
'plant_id' => $plantId,
'machine_id' => $machineId,
'heading_name' => $headingName,
'heading_value' => $headingValue,
'type_name' => $typeName,
'type_value' => $typeValue,
],
[
'has_motor' => $hasMotor,
'has_m_part' => $hasMPart,
'has_m_count' => $hasMCount,
'has_pump' => $hasPump,
'has_p_part' => $hasPPart,
'has_p_count' => $hasPCount,
'has_name_plate' => $hasNamePlate,
'has_np_part' => $hasNpPart,
'has_np_count' => $hasNpCount,
'created_by' => $createdBy,
'updated_by' => $updatedBy,
]
);
// return new ModelMaster;
}
public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your model master import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
if ($failedRowsCount = $import->getFailedRowsCount()) {
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
}
return $body;
}
}

View File

@@ -36,7 +36,7 @@ class ClassCharacteristicResource extends Resource
protected static ?string $navigationGroup = 'Laser Marking';
protected static ?int $navigationSort = 5;
protected static ?int $navigationSort = 7;
public static function form(Form $form): Form
{

View File

@@ -0,0 +1,394 @@
<?php
namespace App\Filament\Resources;
use App\Filament\Exports\ModelMasterExporter;
use App\Filament\Imports\ModelMasterImporter;
use App\Filament\Resources\ModelMasterResource\Pages;
use App\Models\Machine;
use App\Models\ModelMaster;
use App\Models\Plant;
use Filament\Facades\Filament;
use Filament\Forms;
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;
class ModelMasterResource extends Resource
{
protected static ?string $model = ModelMaster::class;
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $navigationGroup = 'Laser Marking';
protected static ?int $navigationSort = 1;
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Select::make('plant_id')
->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();
})
->disabled(fn (Get $get) => ! empty($get('id')))
->default(function () {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? $userHas : optional(ModelMaster::latest()->first())->plant_id;
})
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('machine_id', null);
$set('updated_by', Filament::auth()->user()?->name);
})
->required(),
Forms\Components\Select::make('machine_id')
->label('WORK CENTER')
->reactive()
->searchable()
->options(function (callable $get) {
$plantId = $get('plant_id');
if (empty($plantId)) {
return [];
}
return Machine::where('plant_id', $plantId)->orderBy('work_center')->pluck('work_center', 'id')->toArray();
})
->disabled(fn (Get $get) => ! empty($get('id')))
->default(function (callable $get) {
$plantId = $get('plant_id');
if (empty($plantId)) {
return null;
}
return ModelMaster::where('plant_id', $plantId)->latest()->first()->machine_id ?? null;
})
->afterStateUpdated(function (callable $set) {
$set('updated_by', Filament::auth()->user()?->name);
})
->required(),
Forms\Components\TextInput::make('heading_name')
->label('HEADING NAME')
->reactive()
->readOnly(fn (callable $get) => (! $get('plant_id') || ! $get('machine_id')))
->afterStateUpdated(function (callable $set) {
$set('updated_by', Filament::auth()->user()?->name);
})
->required(),
Forms\Components\TextInput::make('heading_value')
->label('HEADING VALUE')
->reactive()
->readOnly(fn (callable $get) => (! $get('plant_id') || ! $get('machine_id')))
->afterStateUpdated(function (callable $set) {
$set('updated_by', Filament::auth()->user()?->name);
})
->required(),
Forms\Components\TextInput::make('type_name')
->label('TYPE NAME')
->reactive()
->readOnly(fn (callable $get) => (! $get('plant_id') || ! $get('machine_id')))
->afterStateUpdated(function (callable $set) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('type_value')
->label('TYPE VALUE')
->reactive()
->readOnly(fn (callable $get) => (! $get('plant_id') || ! $get('machine_id')))
->afterStateUpdated(function (callable $set) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('has_motor')
->label('HAS MOTOR')
->reactive()
->minValue(0)
->integer()
->maxValue(1)
->readOnly(fn (callable $get) => (! $get('plant_id') || ! $get('machine_id')))
->afterStateUpdated(function (callable $set) {
$set('updated_by', Filament::auth()->user()?->name);
})
->required(),
Forms\Components\TextInput::make('has_m_part')
->label('HAS MOTOR PART')
->reactive()
->minValue(0)
->integer()
->maxValue(1)
->readOnly(fn (callable $get) => (! $get('plant_id') || ! $get('machine_id')))
->afterStateUpdated(function (callable $set) {
$set('updated_by', Filament::auth()->user()?->name);
})
->required(),
Forms\Components\TextInput::make('has_m_count')
->label('HAS MOTOR COUNT')
->reactive()
->minValue(0)
->integer()
->maxValue(99)
->readOnly(fn (callable $get) => (! $get('plant_id') || ! $get('machine_id')))
->afterStateUpdated(function (callable $set) {
$set('updated_by', Filament::auth()->user()?->name);
})
->required(),
Forms\Components\TextInput::make('has_pump')
->label('HAS PUMP')
->reactive()
->minValue(0)
->integer()
->maxValue(1)
->readOnly(fn (callable $get) => (! $get('plant_id') || ! $get('machine_id')))
->afterStateUpdated(function (callable $set) {
$set('updated_by', Filament::auth()->user()?->name);
})
->required(),
Forms\Components\TextInput::make('has_p_part')
->label('HAS PUMP PART')
->reactive()
->minValue(0)
->integer()
->maxValue(1)
->readOnly(fn (callable $get) => (! $get('plant_id') || ! $get('machine_id')))
->afterStateUpdated(function (callable $set) {
$set('updated_by', Filament::auth()->user()?->name);
})
->required(),
Forms\Components\TextInput::make('has_p_count')
->label('HAS PUMP COUNT')
->reactive()
->minValue(0)
->integer()
->maxValue(99)
->readOnly(fn (callable $get) => (! $get('plant_id') || ! $get('machine_id')))
->afterStateUpdated(function (callable $set) {
$set('updated_by', Filament::auth()->user()?->name);
})
->required(),
Forms\Components\TextInput::make('has_name_plate')
->label('HAS NAME PLATE')
->reactive()
->minValue(0)
->integer()
->maxValue(1)
->readOnly(fn (callable $get) => (! $get('plant_id') || ! $get('machine_id')))
->afterStateUpdated(function (callable $set) {
$set('updated_by', Filament::auth()->user()?->name);
})
->required(),
Forms\Components\TextInput::make('has_np_part')
->label('HAS NAME PLATE PART')
->reactive()
->minValue(0)
->integer()
->maxValue(1)
->readOnly(fn (callable $get) => (! $get('plant_id') || ! $get('machine_id')))
->afterStateUpdated(function (callable $set) {
$set('updated_by', Filament::auth()->user()?->name);
})
->required(),
Forms\Components\TextInput::make('has_np_count')
->label('HAS NAME PLATE COUNT')
->reactive()
->minValue(0)
->integer()
->maxValue(99)
->readOnly(fn (callable $get) => (! $get('plant_id') || ! $get('machine_id')))
->afterStateUpdated(function (callable $set) {
$set('updated_by', Filament::auth()->user()?->name);
})
->required(),
Forms\Components\Hidden::make('created_by')
->label('Created By')
->default(Filament::auth()->user()?->name),
Forms\Components\Hidden::make('updated_by')
->label('Updated By')
->default(Filament::auth()->user()?->name),
Forms\Components\TextInput::make('id')
->hidden()
->readOnly(),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('No.')
->label('NO')
->alignCenter()
->getStateUsing(function ($record, $livewire, $column, $rowLoop) {
$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')
->label('PLANT NAME')
->alignCenter()
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('machine.work_center')
->label('WORK CENTER')
->alignCenter()
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('heading_name')
->label('HEADING NAME')
->alignCenter()
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('heading_value')
->label('HEADING VALUE')
->alignCenter()
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('type_name')
->label('TYPE NAME')
->alignCenter()
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('type_value')
->label('TYPE VALUE')
->alignCenter()
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('has_motor')
->label('HAS MOTOR')
->alignCenter()
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('has_m_part')
->label('HAS MOTOR PART')
->alignCenter()
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('has_m_count')
->label('HAS MOTOR COUNT')
->alignCenter()
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('has_pump')
->label('HAS PUMP')
->alignCenter()
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('has_p_part')
->label('HAS PUMP PART')
->alignCenter()
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('has_p_count')
->label('HAS PUMP COUNT')
->alignCenter()
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('has_name_plate')
->label('HAS NAME PLATE')
->alignCenter()
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('has_np_part')
->label('HAS NAME PLATE PART')
->alignCenter()
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('has_np_count')
->label('HAS NAME PLATE COUNT')
->alignCenter()
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('created_at')
->label('CREATED AT')
->alignCenter()
->dateTime()
->sortable(),
Tables\Columns\TextColumn::make('created_by')
->label('CREATED BY')
->alignCenter(),
Tables\Columns\TextColumn::make('updated_at')
->label('UPDATED AT')
->alignCenter()
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: false),
Tables\Columns\TextColumn::make('updated_by')
->label('UPDATED BY')
->alignCenter()
->toggleable(isToggledHiddenByDefault: false),
Tables\Columns\TextColumn::make('deleted_at')
->label('DELETED AT')
->alignCenter()
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([
Tables\Filters\TrashedFilter::make(),
])
->actions([
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
Tables\Actions\ForceDeleteBulkAction::make(),
Tables\Actions\RestoreBulkAction::make(),
]),
])
->headerActions([
ImportAction::make()
->label('Import Model Masters')
->color('warning')
->importer(ModelMasterImporter::class)
->visible(function () {
return Filament::auth()->user()->can('view import model master');
}),
ExportAction::make()
->label('Export Model Masters')
->color('warning')
->exporter(ModelMasterExporter::class)
->visible(function () {
return Filament::auth()->user()->can('view export model master');
}),
]);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListModelMasters::route('/'),
'create' => Pages\CreateModelMaster::route('/create'),
'view' => Pages\ViewModelMaster::route('/{record}'),
'edit' => Pages\EditModelMaster::route('/{record}/edit'),
];
}
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()
->withoutGlobalScopes([
SoftDeletingScope::class,
]);
}
}

View File

@@ -0,0 +1,12 @@
<?php
namespace App\Filament\Resources\ModelMasterResource\Pages;
use App\Filament\Resources\ModelMasterResource;
use Filament\Actions;
use Filament\Resources\Pages\CreateRecord;
class CreateModelMaster extends CreateRecord
{
protected static string $resource = ModelMasterResource::class;
}

View File

@@ -0,0 +1,22 @@
<?php
namespace App\Filament\Resources\ModelMasterResource\Pages;
use App\Filament\Resources\ModelMasterResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
class EditModelMaster extends EditRecord
{
protected static string $resource = ModelMasterResource::class;
protected function getHeaderActions(): array
{
return [
Actions\ViewAction::make(),
Actions\DeleteAction::make(),
Actions\ForceDeleteAction::make(),
Actions\RestoreAction::make(),
];
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Resources\ModelMasterResource\Pages;
use App\Filament\Resources\ModelMasterResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;
class ListModelMasters extends ListRecords
{
protected static string $resource = ModelMasterResource::class;
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Resources\ModelMasterResource\Pages;
use App\Filament\Resources\ModelMasterResource;
use Filament\Actions;
use Filament\Resources\Pages\ViewRecord;
class ViewModelMaster extends ViewRecord
{
protected static string $resource = ModelMasterResource::class;
protected function getHeaderActions(): array
{
return [
Actions\EditAction::make(),
];
}
}

View File

@@ -104,7 +104,8 @@ class RequestCharacteristicResource extends Resource
}
$set('updated_by', Filament::auth()->user()?->name);
})
->disabled(fn ($get) => self::isFieldDisabled($get)),
// ->disabled(fn ($get) => self::isFieldDisabled($get))
->disabled(fn (Get $get) => ! empty($get('id'))),
Forms\Components\Select::make('machine_id')
->label('Work Center')
// ->relationship('machine', 'name')
@@ -133,7 +134,7 @@ class RequestCharacteristicResource extends Resource
$set('approver_type', null);
$set('updated_by', Filament::auth()->user()?->name);
})
->disabled(fn ($get) => self::isFieldDisabled($get)),
->disabled(fn (Get $get) => ! empty($get('id'))),
Forms\Components\Hidden::make('show_validation_image')
->reactive()
->default(false),
@@ -224,7 +225,7 @@ class RequestCharacteristicResource extends Resource
return ($userHas && strlen($userHas) > 0) ? null : optional(RequestCharacteristic::latest()->first())->item_id ?? null;
})
->disabled(fn ($get) => self::isFieldDisabled($get)),
->disabled(fn (Get $get) => ! empty($get('id'))),
Forms\Components\TextInput::make('aufnr')
->label('Job Number')
->reactive()
@@ -251,7 +252,7 @@ class RequestCharacteristicResource extends Resource
return ($userHas && strlen($userHas) > 0) ? null : optional(RequestCharacteristic::latest()->first())->aufnr ?? null;
})
->readOnly(fn ($get) => ($get('item_id') == null))
->disabled(fn ($get) => self::isFieldDisabled($get)),
->disabled(fn (Get $get) => ! empty($get('id'))),
Forms\Components\TextInput::make('gernr')
->label('Serial Number')
->reactive()
@@ -281,7 +282,8 @@ class RequestCharacteristicResource extends Resource
}
return false;
}),
})
->disabled(fn (Get $get) => ! empty($get('id'))),
Forms\Components\Select::make('machine_name')
->label('Machine Name')
->reactive()
@@ -334,7 +336,8 @@ class RequestCharacteristicResource extends Resource
}
}
})
->required(),
->required()
->disabled(fn (Get $get) => ! empty($get('id'))),
Forms\Components\Select::make('approver_type')
->label('Request Type')
// ->columnSpan(1)
@@ -400,7 +403,8 @@ class RequestCharacteristicResource extends Resource
$set('approver_type', null);
}
}
}),
})
->disabled(fn (Get $get) => ! empty($get('id'))),
Forms\Components\Select::make('characteristic_approver_master_id')
->label('Master Characteristic Field')
// ->relationship('characteristicApproverMaster', 'characteristic_field')
@@ -431,7 +435,8 @@ class RequestCharacteristicResource extends Resource
$set('update_value', null);
$set('updated_by', Filament::auth()->user()?->name);
})
->required(),
->required()
->disabled(fn (Get $get) => ! empty($get('id'))),
Forms\Components\TextInput::make('model_type')
->label('Model Type')
->reactive()
@@ -442,8 +447,8 @@ class RequestCharacteristicResource extends Resource
$set('update_value', null);
$set('updated_by', Filament::auth()->user()?->name);
})
->required(),
// ->disabled(fn ($get) => self::isFieldDisabled($get))
->required()
->disabled(fn (Get $get) => ! empty($get('id'))),
Section::make('Request Characteristic Details')
// ->columnSpan(['default' => 2, 'sm' => 4])
->reactive()

View File

@@ -48,6 +48,11 @@ class Machine extends Model
return $this->hasMany(ClassCharacteristic::class, 'machine_id', 'id');
}
public function ModelMasters()
{
return $this->hasMany(ModelMaster::class, 'machine_id', 'id');
}
public function windedSerialValidationErrors()
{
return $this->hasMany(WindedSerialValidationError::class, 'machine_id', 'id');

View File

@@ -0,0 +1,46 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
// use Illuminate\Database\Eloquent\Prunable;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
class ModelMaster extends Model
{
// use Prunable;
use SoftDeletes;
protected $fillable = [
'plant_id',
'machine_id',
'heading_name',
'heading_value',
'type_name',
'type_value',
'has_motor',
'has_m_part',
'has_m_count',
'has_pump',
'has_p_part',
'has_p_count',
'has_name_plate',
'has_np_part',
'has_np_count',
'created_at',
'updated_at',
'created_by',
'updated_by',
];
public function plant(): BelongsTo
{
return $this->belongsTo(Plant::class);
}
public function machine(): BelongsTo
{
return $this->belongsTo(Machine::class);
}
}

View File

@@ -164,10 +164,10 @@ class Plant extends Model
return $this->hasMany(ClassCharacteristic::class, 'plant_id', 'id');
}
// public function ModelMasters()
// {
// return $this->hasMany(ModelMaster::class, 'plant_id', 'id');
// }
public function ModelMasters()
{
return $this->hasMany(ModelMaster::class, 'plant_id', 'id');
}
public function windedSerialValidationErrors()
{

View File

@@ -0,0 +1,106 @@
<?php
namespace App\Policies;
use Illuminate\Auth\Access\Response;
use App\Models\ModelMaster;
use App\Models\User;
class ModelMasterPolicy
{
/**
* Determine whether the user can view any models.
*/
public function viewAny(User $user): bool
{
return $user->checkPermissionTo('view-any ModelMaster');
}
/**
* Determine whether the user can view the model.
*/
public function view(User $user, ModelMaster $modelmaster): bool
{
return $user->checkPermissionTo('view ModelMaster');
}
/**
* Determine whether the user can create models.
*/
public function create(User $user): bool
{
return $user->checkPermissionTo('create ModelMaster');
}
/**
* Determine whether the user can update the model.
*/
public function update(User $user, ModelMaster $modelmaster): bool
{
return $user->checkPermissionTo('update ModelMaster');
}
/**
* Determine whether the user can delete the model.
*/
public function delete(User $user, ModelMaster $modelmaster): bool
{
return $user->checkPermissionTo('delete ModelMaster');
}
/**
* Determine whether the user can delete any models.
*/
public function deleteAny(User $user): bool
{
return $user->checkPermissionTo('delete-any ModelMaster');
}
/**
* Determine whether the user can restore the model.
*/
public function restore(User $user, ModelMaster $modelmaster): bool
{
return $user->checkPermissionTo('restore ModelMaster');
}
/**
* Determine whether the user can restore any models.
*/
public function restoreAny(User $user): bool
{
return $user->checkPermissionTo('restore-any ModelMaster');
}
/**
* Determine whether the user can replicate the model.
*/
public function replicate(User $user, ModelMaster $modelmaster): bool
{
return $user->checkPermissionTo('replicate ModelMaster');
}
/**
* Determine whether the user can reorder the models.
*/
public function reorder(User $user): bool
{
return $user->checkPermissionTo('reorder ModelMaster');
}
/**
* Determine whether the user can permanently delete the model.
*/
public function forceDelete(User $user, ModelMaster $modelmaster): bool
{
return $user->checkPermissionTo('force-delete ModelMaster');
}
/**
* Determine whether the user can permanently delete any models.
*/
public function forceDeleteAny(User $user): bool
{
return $user->checkPermissionTo('force-delete-any ModelMaster');
}
}

View File

@@ -0,0 +1,58 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
// Schema::create('model_masters', function (Blueprint $table) {
// $table->id();
// $table->timestamps();
// });
$sql = <<<'SQL'
CREATE TABLE model_masters (
id BIGINT GENERATED always AS IDENTITY PRIMARY KEY,
plant_id BIGINT NOT NULL,
machine_id BIGINT NOT NULL,
heading_name TEXT DEFAULT NULL,
heading_value TEXT DEFAULT NULL,
type_name TEXT DEFAULT NULL,
type_value TEXT DEFAULT NULL,
has_motor TEXT DEFAULT '0',
has_m_part TEXT DEFAULT '0',
has_m_count TEXT DEFAULT '0',
has_pump TEXT DEFAULT '0',
has_p_part TEXT DEFAULT '0',
has_p_count TEXT DEFAULT '0',
has_name_plate TEXT DEFAULT '0',
has_np_part TEXT DEFAULT '0',
has_np_count TEXT DEFAULT '0',
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP NOT NULL DEFAULT NOW(),
created_by TEXT DEFAULT NULL,
updated_by TEXT DEFAULT NULL,
deleted_at TIMESTAMP,
UNIQUE (plant_id, machine_id, heading_name, heading_value, type_name, type_value),
FOREIGN KEY (plant_id) REFERENCES plants (id),
FOREIGN KEY (machine_id) REFERENCES machines (id)
);
SQL;
DB::statement($sql);
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('model_masters');
}
};

View File

@@ -264,6 +264,7 @@
<thead>
<tr>
<th width="12%">S.No</th>
<th>Supplier Number</th>
<th>Serial Number</th>
<th width="20%">Status</th>
</tr>
@@ -279,6 +280,12 @@
{{ $index + 1 }}
</td>
<td>
<span class="supplier-number">
{{ $record->panel_box_supplier }}
</span>
</td>
<td>
<span class="serial-number">
{{ $record->serial_number }}