Import Fun Completed and Sticker Master

This commit is contained in:
dhanabalan
2025-03-28 16:52:40 +05:30
parent ef4504155a
commit e46f290fd1
47 changed files with 1317 additions and 335 deletions

View File

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

View File

@@ -27,11 +27,12 @@ class BlockResource extends Resource
return $form
->schema([
Forms\Components\TextInput::make('name')
->required()
->unique(ignoreRecord: true),
->required(),
// ->unique(ignoreRecord: true),
// ->columnSpanFull(),
Forms\Components\Select::make('plant_id')
->relationship('plant', 'name')
// ->unique(ignoreRecord: true)
->required(),
]);
}

View File

@@ -31,7 +31,7 @@ class CompanyResource extends Resource
Forms\Components\TextInput::make('name')
->required()
//->citext('name')
->unique()
->unique(ignoreRecord: true)
->columnSpanFull(),
]);
}

View File

@@ -28,6 +28,10 @@ class ItemResource extends Resource
{
return $form
->schema([
Forms\Components\Select::make('plant_id')
->relationship('plant', 'name')
->required(),
// ->nullable(),
Forms\Components\TextInput::make('code')
->required()
->unique(ignoreRecord: true)
@@ -38,38 +42,8 @@ class ItemResource extends Resource
->numeric()
->minValue(1),
Forms\Components\Textarea::make('description')
->required()
->columnSpanFull(),
Forms\Components\Select::make('plant_id')
->relationship('plant', 'name')
->required()
->reactive()
->afterStateUpdated(fn ($set) => $set('block_id', null)), // Reset block_id when plant changes
Forms\Components\Select::make('block_id')
->relationship('block', 'name')
->required()
->options(fn (callable $get) =>
\App\Models\Block::where('plant_id', $get('plant_id'))
->pluck('name', 'id')
->toArray() // Convert collection to array
)
->reactive(), // Ensures the dropdown updates when plant_id changes
// Forms\Components\Select::make('plant_id')
// ->relationship('plant', 'name')
// ->required()
// ->reactive(),
// Forms\Components\Select::make('block_id')
// ->relationship('block', 'name')
// ->required()
// ->options(fn (callable $get) =>
// \App\Models\Block::where('plant_id', $get('plant_id'))->pluck('name', 'id')
// )
// ->reactive() // Updates dynamically when plant_id changes
// ->afterStateUpdated(fn ($set) => $set('block_id', null)), // Reset block_id when plant_id changes
Forms\Components\Select::make('line_id')
->relationship('line', 'name')
->required(),
// ->columnSpanFull(),
]);
}
@@ -88,10 +62,6 @@ class ItemResource extends Resource
->sortable(),
Tables\Columns\TextColumn::make('description')
->sortable(),
Tables\Columns\TextColumn::make('line.name')
->sortable(),
Tables\Columns\TextColumn::make('block.name')
->sortable(),
Tables\Columns\TextColumn::make('plant.name')
->sortable(),
Tables\Columns\TextColumn::make('created_at')

View File

@@ -27,21 +27,16 @@ class LineResource extends Resource
{
return $form
->schema([
Forms\Components\Select::make('plant_id')
->relationship('plant', 'name')
->required(),
// ->nullable(),
Forms\Components\Textarea::make('name')
->required(),
// ->columnSpanFull(),
Forms\Components\Textarea::make('type')
->required(),
//->columnSpanFull(),
Forms\Components\Select::make('plant_id')
->relationship('plant', 'name')
->required(),
Forms\Components\Select::make('block_id')
->relationship('block', 'name')
->required(),
Forms\Components\Select::make('shift_id')
->relationship('shift', 'name')
->required(),
]);
}
@@ -57,10 +52,6 @@ class LineResource extends Resource
->sortable(),
Tables\Columns\TextColumn::make('type')
->sortable(),
Tables\Columns\TextColumn::make('shift.name')
->sortable(),
Tables\Columns\TextColumn::make('block.name')
->sortable(),
Tables\Columns\TextColumn::make('plant.name')
->sortable(),
Tables\Columns\TextColumn::make('created_at')

View File

@@ -33,15 +33,6 @@ class LineStopResource extends Resource
Forms\Components\Textarea::make('reason')
->required(),
//->columnSpanFull(),
Forms\Components\Select::make('plant_id')
->relationship('plant', 'name')
->required(),
Forms\Components\Select::make('block_id')
->relationship('block', 'name')
->required(),
Forms\Components\Select::make('shift_id')
->relationship('shift', 'name')
->required(),
]);
}
@@ -57,12 +48,6 @@ class LineStopResource extends Resource
->sortable(),
Tables\Columns\TextColumn::make('reason')
->sortable(),
Tables\Columns\TextColumn::make('shift.name')
->sortable(),
Tables\Columns\TextColumn::make('block.name')
->sortable(),
Tables\Columns\TextColumn::make('plant.name')
->sortable(),
Tables\Columns\TextColumn::make('created_at')
->dateTime()
->sortable()

View File

@@ -14,6 +14,8 @@ use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Carbon\Carbon;
class ProductionLineStopResource extends Resource
{
@@ -21,43 +23,154 @@ class ProductionLineStopResource extends Resource
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $navigationGroup = 'Master Entries';
// protected static ?string $navigationParentItem = 'Display Transactions';
protected static ?string $navigationGroup = 'Production';
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Select::make('lineStop_id')
->relationship('linestop', 'code')
->required(),
Forms\Components\Select::make('lineStop_id')
->relationship('linestop', 'reason')
->required(),
Forms\Components\Select::make('plant_id')
->relationship('plant', 'name')
->required()
->nullable()
->reactive(),
Forms\Components\Select::make('block_name')
->required()
->nullable()
->reactive()
->afterStateUpdated(fn ($set) => $set('shift_id', null)),
Forms\Components\Select::make('shift_id')
->relationship('shift', 'name')
->required()
->nullable()
// ->options(fn (callable $get) =>
// \App\Models\Shift::where('plant_id', $get('plant_id'))
// ->pluck('name', 'id')
// ->toArray() // Convert collection to array
// )
->options(function (callable $get) {
if (!$get('plant_id')) {
return [];
}
return \App\Models\Shift::where('plant_id', $get('plant_id'))
->pluck('name', 'id')
->toArray();
})
->reactive()
->afterStateUpdated(fn ($set) => $set('line_id', null)),
Forms\Components\Select::make('line_id')
->relationship('line', 'name')
->required()
->nullable()
// ->options(fn (callable $get) =>
// \App\Models\Line::where('plant_id', $get('plant_id'))
// ->pluck('name', 'id')
// ->toArray() // Convert collection to array
// )
->options(function (callable $get) {
if (!$get('plant_id')) {
return [];
}
return \App\Models\Line::where('plant_id', $get('plant_id'))
->pluck('name', 'id')
->toArray();
})
->reactive(),
// Forms\Components\Select::make('linestop_id')
// ->label('Line Stop Code')
// ->relationship('linestop', 'code')
// ->searchable()
// ->required()
// ->nullable()
// ->reactive(),
Forms\Components\Select::make('linestop_id')
->label('Line Stop Code')
// ->options(fn (callable $get) =>
// \App\Models\LineStop::where('id', $get('linestop_id'))
// ->pluck('code', 'id')
// )
->options(fn () => \App\Models\LineStop::pluck('code', 'id'))
->required()
->nullable()
// ->reactive()
->searchable()
->live(debounce: 500) // Enable live updates
->afterStateUpdated(function ($state, callable $set, callable $get) {
$lineStopId = $get('linestop_id'); // Get entered linestop_id
// Ensure `linestop_id` is not cleared
if (!$lineStopId) {
$set('lineStop_reason', null);
return;
}
// Check if item exists for the selected plant
$lineStop = \App\Models\LineStop::where('id', $lineStopId)
->where('id', $lineStopId)
->first();
$set('lineStop_reason', $lineStop?->reason ?? null);
}),
Forms\Components\TextInput::make('lineStop_reason')
->label('Line Stop Reason')
->required()
->reactive()
->readOnly(true),
Forms\Components\DateTimePicker::make('from_datetime')
->required(),
->label('From DateTime')
->required()
->reactive()
->afterStateUpdated(fn ($state, callable $set, callable $get) =>
self::updateStopDuration($get, $set)
),
Forms\Components\DateTimePicker::make('to_datetime')
->required(),
->label('To DateTime')
->required()
->reactive()
->afterStateUpdated(fn ($state, callable $set, callable $get) =>
self::updateStopDuration($get, $set) //self means it calling the function within the class
),
Forms\Components\TextInput::make('stop_hour')
->required()
// ->dehydrated(false) // Don't send to backend
->readOnly(true)
->numeric(),
Forms\Components\TextInput::make('stop_min')
->required()
// ->dehydrated(false)
->readOnly(true)
->numeric(),
Forms\Components\Select::make('plant_id')
->relationship('plant', 'name')
->required(),
Forms\Components\Select::make('block_id')
->relationship('block', 'name')
->required(),
Forms\Components\Select::make('shift_id')
->relationship('shift', 'name')
->required(),
Forms\Components\Select::make('line_id')
->relationship('line', 'name')
->required(),
]);
}
public static function updateStopDuration(callable $get, callable $set)
{
$from = $get('from_datetime');
$to = $get('to_datetime');
// Carbon is a PHP date and time library.
if ($from && $to) {
$fromTime = Carbon::parse($from); //Carbon::parse($from) converts the from datetime string into a Carbon objec
$toTime = Carbon::parse($to);
if ($fromTime->lt($toTime)) {
$diffInMinutes = $fromTime->diffInMinutes($toTime);
$set('stop_hour', floor($diffInMinutes / 60));
$set('stop_min', $diffInMinutes % 60);
} else {
$set('stop_hour', 0);
$set('stop_min', 0);
}
}
}
public static function table(Table $table): Table
{
return $table
@@ -86,8 +199,6 @@ class ProductionLineStopResource extends Resource
->sortable(),
Tables\Columns\TextColumn::make('shift.name')
->sortable(),
Tables\Columns\TextColumn::make('block.name')
->sortable(),
Tables\Columns\TextColumn::make('plant.name')
->sortable(),
Tables\Columns\TextColumn::make('created_at')

View File

@@ -21,12 +21,63 @@ class ProductionPlanResource extends Resource
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $navigationGroup = 'Master Entries';
// protected static ?string $navigationParentItem = 'Production Line Stops';
protected static ?string $navigationGroup = 'Production';
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Select::make('plant_id')
->relationship('plant', 'name')
->required()
->nullable()
->reactive(),
Forms\Components\Select::make('block_name')
->required()
->nullable()
->reactive()
->afterStateUpdated(fn ($set) => $set('shift_id', null)),
Forms\Components\Select::make('shift_id')
->relationship('shift', 'name')
->required()
->nullable()
// ->options(fn (callable $get) =>
// \App\Models\Shift::where('plant_id', $get('plant_id'))
// ->pluck('name', 'id')
// ->toArray() // Convert collection to array
// )
->options(function (callable $get) {
if (!$get('plant_id')) {
return [];
}
return \App\Models\Shift::where('plant_id', $get('plant_id'))
->pluck('name', 'id')
->toArray();
})
->reactive()
->afterStateUpdated(fn ($set) => $set('line_id', null)),
Forms\Components\Select::make('line_id')
->relationship('line', 'name')
->required()
->nullable()
// ->options(fn (callable $get) =>
// \App\Models\Line::where('plant_id', $get('plant_id'))
// ->pluck('name', 'id')
// ->toArray() // Convert collection to array
// )
->options(function (callable $get) {
if (!$get('plant_id')) {
return [];
}
return \App\Models\Line::where('plant_id', $get('plant_id'))
->pluck('name', 'id')
->toArray();
})
->reactive(),
Forms\Components\TextInput::make('plan_quantity')
->required()
->numeric()
@@ -36,15 +87,7 @@ class ProductionPlanResource extends Resource
->numeric()
->readOnly()
->default(0),
Forms\Components\Select::make('plant_id')
->relationship('plant', 'name')
->required(),
Forms\Components\Select::make('shift_id')
->relationship('shift', 'name')
->required(),
Forms\Components\Select::make('line_id')
->relationship('line', 'name')
->required(),
]);
}

View File

@@ -21,35 +21,121 @@ class ProductionQuantityResource extends Resource
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $navigationGroup = 'Master Entries';
// protected static ?string $navigationParentItem = 'Display Transactions';
protected static ?string $navigationGroup = 'Production';
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Select::make('item_id')
->relationship('item', 'code')
Forms\Components\Select::make('plant_id')
->relationship('plant', 'name')
->required()
->nullable()
->reactive(),
Forms\Components\Select::make('block_name')
->required()
->nullable()
->reactive()
->afterStateUpdated(fn ($set) => $set('shift_id', null)),
Forms\Components\Select::make('shift_id')
->relationship('shift', 'name')
->required()
->nullable()
// ->options(fn (callable $get) =>
// \App\Models\Shift::where('plant_id', $get('plant_id'))
// ->pluck('name', 'id')
// ->toArray() // Convert collection to array
// )
->options(function (callable $get) {
if (!$get('plant_id')) {
return [];
}
return \App\Models\Shift::where('plant_id', $get('plant_id'))
->pluck('name', 'id')
->toArray();
})
->reactive()
->afterStateUpdated(fn ($set) => $set('line_id', null)),
Forms\Components\Select::make('line_id')
->relationship('line', 'name')
->required()
->nullable()
// ->options(fn (callable $get) =>
// \App\Models\Line::where('plant_id', $get('plant_id'))
// ->pluck('name', 'id')
// ->toArray() // Convert collection to array
// )
->options(function (callable $get) {
if (!$get('plant_id')) {
return [];
}
return \App\Models\Line::where('plant_id', $get('plant_id'))
->pluck('name', 'id')
->toArray();
})
->reactive(),
// Forms\Components\Select::make('item_id')
// ->label('Item Code')
// ->relationship('item', 'code')
// ->required(),
// // Forms\Components\TextInput::make('item_code')
// // ->required()
// // ->autocapitalize('item_code'),
// // //->columnSpanFull(),
// Virtual field for code input (not stored in DB)
Forms\Components\TextInput::make('item_code')
->label('Item Code')
->required()
->reactive()
->afterStateUpdated(function ($state, callable $get, callable $set) {
// Only search when all parent IDs are selected
if ($get('plant_id') && $get('line_id')) {
$item = \App\Models\Item::where('code', $state)
->where('plant_id', $get('plant_id'))
->where('line_id', $get('line_id'))
->first();
if ($item) {
$set('item_id', $item->id); // Set actual foreign key
} else {
$set('item_id', null); // Clear item_id if not found
}
}
})
->rules([
function ($get) {
return function ($attribute, $value, $fail) use ($get) {
// Check if item exists with the given code and foreign keys
$exists = \App\Models\Item::where('code', $value)
->where('plant_id', $get('plant_id'))
->where('line_id', $get('line_id'))
->exists();
if (!$exists) {
// Custom error message
$fail("The item code '{$value}' does not exist for the selected Plant/Block/Line.");
}
};
},
]),
Forms\Components\Hidden::make('item_id')
->required(),
// Forms\Components\TextInput::make('item_code')
// ->required()
// ->autocapitalize('item_code'),
// //->columnSpanFull(),
Forms\Components\TextInput::make('item_description')
->label('Description')
->required(),
// Forms\Components\Select::make('item_id')
// ->label('Description')
// ->relationship('item', 'description')
// ->required(),
Forms\Components\TextInput::make('serial_number')
->required()
->autocapitalize('serial_number'),
//->columnSpanFull(),
Forms\Components\Select::make('plant_id')
->relationship('plant', 'name')
->required(),
Forms\Components\Select::make('block_id')
->relationship('block', 'name')
->required(),
Forms\Components\Select::make('shift_id')
->relationship('shift', 'name')
->required(),
Forms\Components\Select::make('line_id')
->relationship('line', 'name')
->required(),
]);
}
@@ -61,13 +147,7 @@ class ProductionQuantityResource extends Resource
->label('ID')
->numeric()
->sortable(),
Tables\Columns\TextColumn::make('plan_quantity')
->numeric()
->sortable(),
Tables\Columns\TextColumn::make('hourly_quantity')
->numeric()
->sortable(),
Tables\Columns\TextColumn::make('item_code')
Tables\Columns\TextColumn::make('item.code')
->sortable(),
Tables\Columns\TextColumn::make('serial_number')
->sortable(),
@@ -75,8 +155,6 @@ class ProductionQuantityResource extends Resource
->sortable(),
Tables\Columns\TextColumn::make('shift.name')
->sortable(),
Tables\Columns\TextColumn::make('block.name')
->sortable(),
Tables\Columns\TextColumn::make('plant.name')
->sortable(),
Tables\Columns\TextColumn::make('created_at')

View File

@@ -0,0 +1,126 @@
<?php
namespace App\Filament\Resources;
use App\Filament\Resources\QualityValidationResource\Pages;
use App\Filament\Resources\QualityValidationResource\RelationManagers;
use App\Models\QualityValidation;
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;
class QualityValidationResource extends Resource
{
protected static ?string $model = QualityValidation::class;
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $navigationGroup = 'Display';
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Select::make('plant_id')
->relationship('plant', 'name')
->required(),
Forms\Components\Select::make('item_id')
->relationship('item', 'code')
->searchable()
->required(),
Forms\Components\Select::make('stickermaster_id')
->relationship('stickermaster', 'id')
->required(),
Forms\Components\TextInput::make('scan_qr')
->label('Scan QR Code')
->required(),
Forms\Components\TextInput::make('production_order')
->required(),
Forms\Components\TextInput::make('part_validation1'),
Forms\Components\TextInput::make('part_validation2'),
Forms\Components\TextInput::make('part_validation3'),
Forms\Components\TextInput::make('part_validation4'),
Forms\Components\TextInput::make('part_validation5'),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('id')
->label('ID')
->numeric()
->sortable(),
Tables\Columns\TextColumn::make('item.id')
->numeric()
->sortable(),
Tables\Columns\TextColumn::make('plant.name')
->numeric()
->sortable(),
Tables\Columns\TextColumn::make('stickermaster.id')
->numeric()
->sortable(),
Tables\Columns\TextColumn::make('created_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('updated_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('deleted_at')
->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(),
]),
]);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListQualityValidations::route('/'),
'create' => Pages\CreateQualityValidation::route('/create'),
'view' => Pages\ViewQualityValidation::route('/{record}'),
'edit' => Pages\EditQualityValidation::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\QualityValidationResource\Pages;
use App\Filament\Resources\QualityValidationResource;
use Filament\Actions;
use Filament\Resources\Pages\CreateRecord;
class CreateQualityValidation extends CreateRecord
{
protected static string $resource = QualityValidationResource::class;
}

View File

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

View File

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

View File

@@ -2,12 +2,15 @@
namespace App\Filament\Resources;
use App\Filament\Imports\ShiftImporter;
use App\Filament\Resources\ShiftResource\Pages;
use App\Models\Shift;
use Carbon\Carbon;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
@@ -26,23 +29,53 @@ class ShiftResource extends Resource
->schema([
Forms\Components\Select::make('plant_id')
->relationship('plant', 'name')
->required(),
->required()
->nullable()
->reactive()
->afterStateUpdated(fn ($set) => $set('block_id', null)), // Reset block_id when plant changes
Forms\Components\Select::make('block_id')
->relationship('block', 'name')
->required(),
->required()
->nullable()
// ->options(fn (callable $get) =>
// \App\Models\Block::where('plant_id', $get('plant_id'))
// ->pluck('name', 'id')
// ->toArray() // Convert collection to array
// )
->options(function (callable $get) {
if (!$get('plant_id')) {
return [];
}
return \App\Models\Block::where('plant_id', $get('plant_id'))
->pluck('name', 'id')
->toArray();
})
->reactive(),
Forms\Components\TextInput::make('name')
->required(),
Forms\Components\TimePicker::make('start_time')
->required(),
// ->native(false),
->required()
->live()
->afterStateUpdated(fn (callable $set, callable $get, $state) =>
$set('end_time', self::calculateEndTime($state, $get('duration')))
),
Forms\Components\TextInput::make('duration')
->required()
->inputMode('decimal')
->minValue(1),
->minValue(0.01) // Minimum valid duration
->lazy()
->afterStateUpdated(fn (callable $set, callable $get, $state) =>
$set('end_time', self::calculateEndTime($get('start_time'), $state))
),
Forms\Components\TimePicker::make('end_time')
->required(),
// ->native(false),
]);
}
public static function table(Table $table): Table
@@ -90,6 +123,10 @@ class ShiftResource extends Resource
Tables\Actions\ForceDeleteBulkAction::make(),
Tables\Actions\RestoreBulkAction::make(),
]),
])
->headerActions([
ImportAction::make()
->importer(ShiftImporter::class),
]);
}
@@ -117,4 +154,36 @@ class ShiftResource extends Resource
SoftDeletingScope::class,
]);
}
protected static function calculateEndTime(?string $startTime, ?string $duration): ?string
{
if (!$startTime || !$duration) {
return null;
}
try {
// Convert start_time to Carbon instance
$startTimeCarbon = Carbon::createFromFormat('H:i:s', $startTime);
// Ensure duration is in a valid numeric format
$duration = str_replace(',', '.', $duration); // Handle decimal formats
if (!is_numeric($duration)) {
return null; // Invalid duration format
}
// Extract hours and minutes correctly
[$hours, $decimalMinutes] = explode('.', $duration) + [0, 0]; // Ensure two parts
$hours = (int) $hours; // Convert to integer hours
$minutes = (int) $decimalMinutes; // Directly use decimal part as minutes
// Calculate end time
$endTimeCarbon = $startTimeCarbon->addHours($hours)->addMinutes($minutes);
return $endTimeCarbon->format('H:i:s'); // Return formatted end time
} catch (\Exception $e) {
return null;
}
}
}

View File

@@ -0,0 +1,291 @@
<?php
namespace App\Filament\Resources;
use App\Filament\Resources\StickerMasterResource\Pages;
use App\Filament\Resources\StickerMasterResource\RelationManagers;
use App\Models\StickerMaster;
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;
class StickerMasterResource extends Resource
{
protected static ?string $model = StickerMaster::class;
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $navigationGroup = 'Master Entries';
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Select::make('plant_id')
->relationship('plant', 'name')
->reactive()
->afterStateUpdated(fn (callable $set) => $set('item_id', null))
->required(),
Forms\Components\Select::make('item_id')
->label('Item Code')
->options(fn (callable $get) =>
\App\Models\Item::where('plant_id', $get('plant_id'))
->pluck('code', 'id')
)
->required()
->searchable()
->live(debounce: 500) // Enable live updates
->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id'); // Get selected plant_id
$itemId = $get('item_id'); // Get entered item_id
// Ensure `item_id` is not cleared
if (!$plantId || !$itemId) {
$set('item_description', null);
return;
}
// Check if item exists for the selected plant
$item = \App\Models\Item::where('plant_id', $plantId)
->where('id', $itemId)
->first();
if ($item) {
$set('item_description', $item->description);
} else {
$set('item_description', null);
}
}),
// ->validationAttribute('Item Code')
// ->rule('required')
// ->extraAttributes(fn ($get) => [
// 'class' => $get('validationError') ? 'border-red-500' : '',
// ])
// ->hint(fn ($get) => $get('validationError') ? $get('validationError') : null)
// ->hintColor('danger'), // Show error in red under the input field
Forms\Components\TextInput::make('item_description')
->label('Description')
->required()
->reactive()
->readOnly(true),
//Forms\Components\Textarea::make('serial_number_motor'),
Forms\Components\TextInput::make('part_validation1')
->nullable(),
Forms\Components\TextInput::make('part_validation2')
->nullable(),
Forms\Components\TextInput::make('part_validation3')
->nullable(),
Forms\Components\TextInput::make('part_validation4')
->nullable(),
Forms\Components\TextInput::make('part_validation5')
->nullable(),
Forms\Components\Checkbox::make('serial_number_motor')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
//Forms\Components\Textarea::make('serial_number_pump')
Forms\Components\Checkbox::make('serial_number_pump')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
//Forms\Components\TextInput::make('serial_number_pumpset'),
Forms\Components\Checkbox::make('serial_number_pumpset')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
//Forms\Components\TextInput::make('pack_slip_motor'),
Forms\Components\Checkbox::make('pack_slip_motor')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
//Forms\Components\TextInput::make('pack_slip_pump'),
Forms\Components\Checkbox::make('pack_slip_pump')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
//Forms\Components\TextInput::make('pack_slip_pumpset'),
Forms\Components\Checkbox::make('pack_slip_pumpset')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
//Forms\Components\TextInput::make('name_plate_motor'),
Forms\Components\Checkbox::make('name_plate_motor')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
//Forms\Components\TextInput::make('name_plate_pump'),
Forms\Components\Checkbox::make('name_plate_pump')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
//Forms\Components\TextInput::make('name_plate_pumpset'),
Forms\Components\Checkbox::make('name_plate_pumpset')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
//Forms\Components\TextInput::make('tube_sticker_motor'),
Forms\Components\Checkbox::make('tube_sticker_motor')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
//Forms\Components\TextInput::make('tube_sticker_pump'),
Forms\Components\Checkbox::make('tube_sticker_pump')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
//Forms\Components\TextInput::make('tube_sticker_pumpset'),
Forms\Components\Checkbox::make('tube_sticker_pumpset')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
//Forms\Components\TextInput::make('warranty_card'),
Forms\Components\Checkbox::make('warranty_card')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('id')
->label('ID')
->numeric()
->sortable(),
Tables\Columns\TextColumn::make('item.id')
->numeric()
->sortable(),
Tables\Columns\TextColumn::make('plant.name')
->numeric()
->sortable(),
Tables\Columns\CheckboxColumn::make('serial_number_motor')
->disabled(true)
->sortable(),
Tables\Columns\CheckboxColumn::make('serial_number_pump')
->disabled(true)
->sortable(),
Tables\Columns\CheckboxColumn::make('serial_number_pumpset')
->disabled(true)
->sortable(),
Tables\Columns\CheckboxColumn::make('pack_slip_motor')
->disabled(true)
->sortable(),
Tables\Columns\CheckboxColumn::make('pack_slip_pump')
->disabled(true)
->sortable(),
Tables\Columns\CheckboxColumn::make('pack_slip_pumpset')
->disabled(true)
->sortable(),
Tables\Columns\CheckboxColumn::make('name_plate_motor')
->disabled(true)
->sortable(),
Tables\Columns\CheckboxColumn::make('name_plate_pump')
->disabled(true)
->sortable(),
Tables\Columns\CheckboxColumn::make('name_plate_pumpset')
->disabled(true)
->sortable(),
Tables\Columns\CheckboxColumn::make('tube_sticker_motor')
->disabled(true)
->sortable(),
Tables\Columns\CheckboxColumn::make('tube_sticker_pump')
->disabled(true)
->sortable(),
Tables\Columns\CheckboxColumn::make('tube_sticker_pumpset')
->disabled(true)
->sortable(),
Tables\Columns\CheckboxColumn::make('warranty_card')
->disabled(true)
->sortable(),
Tables\Columns\TextColumn::make('part_validation1')
->sortable(),
Tables\Columns\TextColumn::make('part_validation2')
->sortable(),
Tables\Columns\TextColumn::make('part_validation3')
->sortable(),
Tables\Columns\TextColumn::make('part_validation4')
->sortable(),
Tables\Columns\TextColumn::make('part_validation5')
->sortable(),
Tables\Columns\TextColumn::make('created_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('updated_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('deleted_at')
->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(),
]),
]);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListStickerMasters::route('/'),
'create' => Pages\CreateStickerMaster::route('/create'),
'view' => Pages\ViewStickerMaster::route('/{record}'),
'edit' => Pages\EditStickerMaster::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\StickerMasterResource\Pages;
use App\Filament\Resources\StickerMasterResource;
use Filament\Actions;
use Filament\Resources\Pages\CreateRecord;
class CreateStickerMaster extends CreateRecord
{
protected static string $resource = StickerMasterResource::class;
}

View File

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

View File

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