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

Reviewed-on: #506
This commit was merged in pull request #506.
This commit is contained in:
2026-04-07 12:01:24 +00:00
10 changed files with 784 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
<?php
namespace App\Filament\Exports;
use App\Models\ProductionCharacteristic;
use Filament\Actions\Exports\ExportColumn;
use Filament\Actions\Exports\Exporter;
use Filament\Actions\Exports\Models\Export;
class ProductionCharacteristicExporter extends Exporter
{
protected static ?string $model = ProductionCharacteristic::class;
public static function getColumns(): array
{
static $rowNumber = 0;
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('line.name')
->label('LINE NAME'),
ExportColumn::make('item.code')
->label('ITEM CODE'),
ExportColumn::make('machine.work_center')
->label('WORK CENTER'),
ExportColumn::make('production_order')
->label('PRODUCTION ORDER'),
ExportColumn::make('serial_number')
->label('SERIAL NUMBER'),
ExportColumn::make('characteristic_name')
->label('CHARACTERISTIC NAME'),
ExportColumn::make('observed_value')
->label('OBSERVED VALUE'),
ExportColumn::make('status')
->label('STATUS'),
ExportColumn::make('inspection_status')
->label('INSPECTION STATUS'),
ExportColumn::make('remark')
->label('REMARK'),
ExportColumn::make('created_at')
->label('CREATED AT'),
ExportColumn::make('updated_at')
->label('UPDATED AT'),
ExportColumn::make('created_by')
->label('CREATED BY'),
ExportColumn::make('updated_by')
->label('UPDATED BY'),
ExportColumn::make('deleted_at')
->label('DELETED AT'),
];
}
public static function getCompletedNotificationBody(Export $export): string
{
$body = 'Your production characteristic 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,65 @@
<?php
namespace App\Filament\Imports;
use App\Models\ProductionCharacteristic;
use Filament\Actions\Imports\ImportColumn;
use Filament\Actions\Imports\Importer;
use Filament\Actions\Imports\Models\Import;
class ProductionCharacteristicImporter extends Importer
{
protected static ?string $model = ProductionCharacteristic::class;
public static function getColumns(): array
{
return [
ImportColumn::make('plant')
->requiredMapping()
->relationship()
->rules(['required']),
ImportColumn::make('line')
->requiredMapping()
->relationship()
->rules(['required']),
ImportColumn::make('item')
->requiredMapping()
->relationship()
->rules(['required']),
ImportColumn::make('machine')
->requiredMapping()
->relationship()
->rules(['required']),
ImportColumn::make('production_order'),
ImportColumn::make('serial_number'),
ImportColumn::make('characteristic_name'),
ImportColumn::make('observed_value'),
ImportColumn::make('status'),
ImportColumn::make('inspection_status'),
ImportColumn::make('remark'),
ImportColumn::make('created_by'),
ImportColumn::make('updated_by'),
];
}
public function resolveRecord(): ?ProductionCharacteristic
{
// return ProductionCharacteristic::firstOrNew([
// // Update existing records, matching them by `$this->data['column_name']`
// 'email' => $this->data['email'],
// ]);
return new ProductionCharacteristic();
}
public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your production characteristic 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

@@ -0,0 +1,369 @@
<?php
namespace App\Filament\Resources;
use App\Filament\Exports\ProductionCharacteristicExporter;
use App\Filament\Imports\ProductionCharacteristicImporter;
use App\Filament\Resources\ProductionCharacteristicResource\Pages;
use App\Filament\Resources\ProductionCharacteristicResource\RelationManagers;
use App\Models\Item;
use App\Models\Line;
use App\Models\Machine;
use App\Models\Plant;
use App\Models\ProductCharacteristicsMaster;
use App\Models\ProductionCharacteristic;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Forms\Get;
class ProductionCharacteristicResource extends Resource
{
protected static ?string $model = ProductionCharacteristic::class;
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $navigationGroup = 'Production';
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Select::make('plant_id')
->label('Plant Name')
->nullable()
->searchable()
->reactive()
->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();
})
->disabled(fn (Get $get) => ! empty($get('id')))
->default(function () {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? $userHas : optional(ProductionCharacteristic::latest()->first())->plant_id;
})
->afterStateUpdated(function ($state, $set, callable $get) {
$plantId = $get('plant_id');
$set('line_id', null);
$set('item_id', null);
$set('machine_id', null);
$set('production_order', null);
$set('serial_number', null);
$set('observed_value', null);
$set('status', 'NotOk');
$set('updated_by', Filament::auth()->user()?->name);
if (! $plantId) {
$set('poPlantError', 'Please select a plant first.');
}
})
->extraAttributes(fn ($get) => [
'class' => $get('poPlantError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('poPlantError') ? $get('poPlantError') : null)
->hintColor('danger')
->required(),
Forms\Components\Select::make('line_id')
->label('Line Name')
->nullable()
->searchable()
->reactive()
->options(function (callable $get) {
if (! $get('plant_id')) {
return [];
}
return Line::where('plant_id', $get('plant_id'))
->pluck('name', 'id')
->toArray();
})
->disabled(fn (Get $get) => ! empty($get('id')))
->afterStateUpdated(function ($state, $set, callable $get) {
$plantId = $get('plant_id');
$set('item_id', null);
$set('machine_id', null);
$set('production_order', null);
$set('serial_number', null);
$set('observed_value', null);
$set('status', 'NotOk');
$set('updated_by', Filament::auth()->user()?->name);
if (! $plantId) {
$set('line_id', null);
$set('poPlantError', 'Please select a plant first.');
}
})
->required(),
Forms\Components\Select::make('item_id')
->label('Item Code')
->nullable()
->searchable()
->reactive()
->options(function (callable $get) {
if (! $get('plant_id') || ! $get('line_id')) {
return [];
}
return Item::where('plant_id', $get('plant_id'))
->pluck('code', 'id')
->toArray();
})
->disabled(fn (Get $get) => ! empty($get('id')))
->afterStateUpdated(function ($state, $set, callable $get) {
$plantId = $get('plant_id');
$set('machine_id', null);
$set('production_order', null);
$set('serial_number', null);
$set('observed_value', null);
$set('status', 'NotOk');
$set('updated_by', Filament::auth()->user()?->name);
if (! $plantId) {
$set('item_id', null);
$set('poPlantError', 'Please select a plant first.');
}
})
->required(),
Forms\Components\Select::make('machine_id')
->label('Work Center')
->nullable()
->searchable()
->reactive()
->options(function (callable $get) {
if (! $get('plant_id') || ! $get('line_id') || ! $get('item_id')) {
return [];
}
return Machine::where('plant_id', $get('plant_id'))
->where('line_id', $get('line_id'))
->pluck('work_center', 'id')
->toArray();
})
->disabled(fn (Get $get) => ! empty($get('id')))
->afterStateUpdated(function ($state, $set, callable $get) {
$plantId = $get('plant_id');
$set('production_order', null);
$set('serial_number', null);
$set('observed_value', null);
$set('status', 'NotOk');
$set('updated_by', Filament::auth()->user()?->name);
if (! $plantId) {
$set('machine_id', null);
$set('poPlantError', 'Please select a plant first.');
}
})
->required(),
Forms\Components\TextInput::make('production_order')
->label('Production Order'),
Forms\Components\TextInput::make('serial_number')
->label('Serial Number'),
Forms\Components\TextInput::make('characteristic_name')
->label('Characteristic Name'),
Forms\Components\TextInput::make('observed_value')
->label('Observed Value'),
Forms\Components\Select::make('status')
->label('Status')
->options([
'Ok' => 'Ok',
'NotOk' => 'Not Ok',
'ConditionallyAccepted' => 'Conditionally Accepted',
])
->reactive(),
Forms\Components\TextInput::make('inspection_status')
->label('Inspection Status'),
Forms\Components\TextInput::make('remark')
->label('Remark')
->reactive()
->required(fn ($get) => $get('status') == 'ConditionallyAccepted')
->visible(fn ($get) => $get('status') == 'ConditionallyAccepted'),
Forms\Components\Hidden::make('created_by')
->label('Created By'),
Forms\Components\Hidden::make('updated_by')
->label('Updated By'),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('No.')
->label('No.')
->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')
->searchable()
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('line.name')
->label('Line Name')
->searchable()
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('item.code')
->label('Item Code')
->searchable()
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('item.description')
->label('Item Description')
->searchable()
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('machine.work_center')
->label('Work Center')
->searchable()
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('production_order')
->label('Production Order')
->searchable()
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('serial_number')
->label('Serial Number')
->searchable()
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('characteristic_name')
->label('Characteristic Name')
->searchable()
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('machine.name')
->label('Spec. Value')
// ->searchable()
->formatStateUsing(function ($record) {
$specVal = ProductCharacteristicsMaster::where('plant_id', $record->plant_id)->where('item_id', $record->item_id)->where('line_id', $record->line_id)->where('machine_id', $record->machine_id)->first();
// return $record?->plant_id.'-'.$record?->item_id.'-'.$record->line_id.'-'.$record?->machine_id;
return $specVal?->lower.' - '.$specVal?->upper;
})
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('observed_value')
->label('Observed Value')
->searchable()
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('status')
->label('Status')
->searchable()
// ->formatStateUsing(function ($record) {
// return empty($record->status == 'Ok') ? 'Ok' : 'Not Ok';
// })
->color(fn (string $state): string => match ($state) {
'Ok' => 'success',
'Not Ok' => 'danger',
'NotOk' => 'danger',
'ConditionallyAccepted' => 'success',
default => 'gray',
})
->alignCenter()
->sortable(),
// Tables\Columns\TextColumn::make('inspection_status')
// ->label('Inspection Status')
// ->searchable()
// ->color(fn (string $state): string => match ($state) {
// 'Ok' => 'success',
// 'Not Ok' => 'danger',
// 'NotOk' => 'danger',
// default => 'gray',
// })
// ->alignCenter()
// ->sortable(),
Tables\Columns\TextColumn::make('remark')
->label('Remark')
->searchable()
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('created_at')
->label('Created At')
->alignCenter()
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('updated_at')
->label('Updated At')
->alignCenter()
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
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 Production Characteristics')
->color('warning')
->importer(ProductionCharacteristicImporter::class)
->visible(function () {
return Filament::auth()->user()->can('view import production characteristics');
}),
ExportAction::make()
->label('Export Production Characteristics')
->color('warning')
->exporter(ProductionCharacteristicExporter::class)
->visible(function () {
return Filament::auth()->user()->can('view export production characteristics');
}),
]);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListProductionCharacteristics::route('/'),
'create' => Pages\CreateProductionCharacteristic::route('/create'),
'view' => Pages\ViewProductionCharacteristic::route('/{record}'),
'edit' => Pages\EditProductionCharacteristic::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\ProductionCharacteristicResource\Pages;
use App\Filament\Resources\ProductionCharacteristicResource;
use Filament\Actions;
use Filament\Resources\Pages\CreateRecord;
class CreateProductionCharacteristic extends CreateRecord
{
protected static string $resource = ProductionCharacteristicResource::class;
}

View File

@@ -0,0 +1,22 @@
<?php
namespace App\Filament\Resources\ProductionCharacteristicResource\Pages;
use App\Filament\Resources\ProductionCharacteristicResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
class EditProductionCharacteristic extends EditRecord
{
protected static string $resource = ProductionCharacteristicResource::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\ProductionCharacteristicResource\Pages;
use App\Filament\Resources\ProductionCharacteristicResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;
class ListProductionCharacteristics extends ListRecords
{
protected static string $resource = ProductionCharacteristicResource::class;
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}

View File

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

View File

@@ -0,0 +1,50 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
class ProductionCharacteristic extends Model
{
use SoftDeletes;
protected $fillable = [
'plant_id',
'line_id',
'item_id',
'machine_id',
'production_order',
'serial_number',
'observed_value',
'characteristic_name',
'status',
'inspection_status',
'remark',
'created_at',
'updated_at',
'created_by',
'updated_by',
];
public function plant(): BelongsTo
{
return $this->belongsTo(Plant::class);
}
public function line(): BelongsTo
{
return $this->belongsTo(Line::class);
}
public function item(): BelongsTo
{
return $this->belongsTo(Item::class);
}
public function machine(): BelongsTo
{
return $this->belongsTo(Machine::class);
}
}

View File

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

View File

@@ -0,0 +1,53 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
$sql = <<<'SQL'
CREATE TABLE production_characteristics (
id BIGINT GENERATED always AS IDENTITY PRIMARY KEY,
plant_id BIGINT NOT NULL,
line_id BIGINT NOT NULL,
item_id BIGINT NOT NULL,
machine_id BIGINT NOT NULL,
production_order TEXT DEFAULT NULL,
serial_number TEXT DEFAULT NULL,
characteristic_name TEXT DEFAULT NULL,
observed_value TEXT DEFAULT NULL,
status TEXT DEFAULT NULL,
inspection_status TEXT DEFAULT NULL,
remark TEXT DEFAULT NULL,
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,
FOREIGN KEY (plant_id) REFERENCES plants (id),
FOREIGN KEY (line_id) REFERENCES lines (id),
FOREIGN KEY (item_id) REFERENCES items (id),
FOREIGN KEY (machine_id) REFERENCES machines (id)
);
SQL;
DB::statement($sql);
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('production_characteristics');
}
};