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

Reviewed-on: #196
This commit was merged in pull request #196.
This commit is contained in:
2026-05-25 10:11:42 +00:00
9 changed files with 463 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
<?php
namespace App\Filament\Exports;
use App\Models\EmployeeMaster;
use Filament\Actions\Exports\ExportColumn;
use Filament\Actions\Exports\Exporter;
use Filament\Actions\Exports\Models\Export;
class EmployeeMasterExporter extends Exporter
{
protected static ?string $model = EmployeeMaster::class;
public static function getColumns(): array
{
return [
ExportColumn::make('id')
->label('ID'),
ExportColumn::make('plant.name'),
ExportColumn::make('name'),
ExportColumn::make('code'),
ExportColumn::make('department'),
ExportColumn::make('designation'),
ExportColumn::make('email'),
ExportColumn::make('mobile_number'),
ExportColumn::make('created_at'),
ExportColumn::make('updated_at'),
ExportColumn::make('created_by'),
ExportColumn::make('updated_by'),
ExportColumn::make('deleted_at'),
];
}
public static function getCompletedNotificationBody(Export $export): string
{
$body = 'Your employee 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,53 @@
<?php
namespace App\Filament\Imports;
use App\Models\EmployeeMaster;
use Filament\Actions\Imports\ImportColumn;
use Filament\Actions\Imports\Importer;
use Filament\Actions\Imports\Models\Import;
class EmployeeMasterImporter extends Importer
{
protected static ?string $model = EmployeeMaster::class;
public static function getColumns(): array
{
return [
ImportColumn::make('plant')
->requiredMapping()
->relationship()
->rules(['required']),
ImportColumn::make('name'),
ImportColumn::make('code'),
ImportColumn::make('department'),
ImportColumn::make('designation'),
ImportColumn::make('email')
->rules(['email']),
ImportColumn::make('mobile_number'),
ImportColumn::make('created_by'),
ImportColumn::make('updated_by'),
];
}
public function resolveRecord(): ?EmployeeMaster
{
// return EmployeeMaster::firstOrNew([
// // Update existing records, matching them by `$this->data['column_name']`
// 'email' => $this->data['email'],
// ]);
return new EmployeeMaster();
}
public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your employee 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

@@ -0,0 +1,217 @@
<?php
namespace App\Filament\Resources;
use App\Filament\Exports\EmployeeMasterExporter;
use App\Filament\Imports\EmployeeMasterImporter;
use App\Filament\Resources\EmployeeMasterResource\Pages;
use App\Filament\Resources\EmployeeMasterResource\RelationManagers;
use App\Models\EmployeeMaster;
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\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Illuminate\Validation\Rule;
class EmployeeMasterResource extends Resource
{
protected static ?string $model = EmployeeMaster::class;
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Select::make('plant_id')
->label('Plant')
->relationship('plant', 'name')
->required(),
Forms\Components\TextInput::make('name')
->label('Name')
->required()
->reactive()
->extraInputAttributes([
'oninput' => 'this.value = this.value.replace(/[^a-zA-Z\s]/g, "")',
]),
Forms\Components\TextInput::make('code')
->label('ID')
->extraInputAttributes([
'oninput' => 'this.value = this.value.replace(/[^a-zA-Z0-9]/g, "")',])
->required()
->unique(
table: 'employee_masters',
column: 'code',
ignoreRecord: true
)
->validationMessages([
'unique' => 'Duplicate employee code already exists.',
]),
Forms\Components\TextInput::make('department')
->label('Department')
->required(),
Forms\Components\TextInput::make('designation')
->label('Designation')
->extraInputAttributes([
'oninput' => 'this.value = this.value.replace(/[^a-zA-Z\s]/g, "")',])
->required(),
Forms\Components\TextInput::make('email')
->label('Email')
->email()
->required(),
Forms\Components\TextInput::make('mobile_number')
->label('Mobile Number')
->length(10)
->reactive()
->extraInputAttributes([
'oninput' => 'this.value = this.value.replace(/[^0-9]/g, "").slice(0, 10)', // blocks non-numbers + limits to 10 chars
'maxlength' => 10,
])
->required()
->unique(
table: 'employee_masters',
column: 'mobile_number',
ignoreRecord: true
)
->validationMessages([
'unique' => 'Duplicate mobile number already exists.',
]),
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 ?? ''),
]);
}
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;
})
->alignCenter(),
Tables\Columns\TextColumn::make('plant.name')
->numeric()
->sortable()
->alignCenter(),
Tables\Columns\TextColumn::make('name')
->label('Name')
->sortable()
->alignCenter()
->searchable(),
Tables\Columns\TextColumn::make('code')
->label('Employee ID')
->sortable()
->alignCenter()
->searchable(),
Tables\Columns\TextColumn::make('department')
->label('Department')
->sortable()
->alignCenter()
->searchable(),
Tables\Columns\TextColumn::make('designation')
->label('Designation')
->sortable()
->alignCenter()
->searchable(),
Tables\Columns\TextColumn::make('email')
->label('Email')
->sortable()
->alignCenter()
->searchable(),
Tables\Columns\TextColumn::make('mobile_number')
->label('Mobile Number')
->sortable()
->alignCenter()
->searchable(),
Tables\Columns\TextColumn::make('created_at')
->dateTime()
->sortable()
->alignCenter(),
Tables\Columns\TextColumn::make('updated_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true)
->alignCenter(),
Tables\Columns\TextColumn::make('created_by')
->label('Created by')
->sortable()
->alignCenter(),
Tables\Columns\TextColumn::make('updated_by')
->label('Updated by')
->sortable()
->toggleable(isToggledHiddenByDefault: true)
->alignCenter(),
Tables\Columns\TextColumn::make('deleted_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true)
->alignCenter(),
])
->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()
->importer(EmployeeMasterImporter::class)
->visible(function() {
return Filament::auth()->user()->can('view import employee master');
}),
ExportAction::make()
->exporter(EmployeeMasterExporter::class)
->visible(function() {
return Filament::auth()->user()->can('view export employee master');
}),
]);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListEmployeeMasters::route('/'),
'create' => Pages\CreateEmployeeMaster::route('/create'),
'view' => Pages\ViewEmployeeMaster::route('/{record}'),
'edit' => Pages\EditEmployeeMaster::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\EmployeeMasterResource\Pages;
use App\Filament\Resources\EmployeeMasterResource;
use Filament\Actions;
use Filament\Resources\Pages\CreateRecord;
class CreateEmployeeMaster extends CreateRecord
{
protected static string $resource = EmployeeMasterResource::class;
}

View File

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

View File

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

View File

@@ -0,0 +1,32 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
class EmployeeMaster extends Model
{
use SoftDeletes;
protected $fillable = [
'plant_id',
'name',
'code',
'department',
'designation',
'email',
'mobile_number',
'created_at',
'updated_at',
'created_by',
'updated_by',
];
public function plant(): BelongsTo
{
return $this->belongsTo(Plant::class);
}
}

View File

@@ -0,0 +1,45 @@
<?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 employee_masters (
id BIGINT GENERATED always AS IDENTITY PRIMARY KEY,
plant_id BIGINT NOT NULL,
name TEXT DEFAULT NULL,
code TEXT DEFAULT NULL,
department TEXT DEFAULT NULL,
designation TEXT DEFAULT NULL,
email TEXT DEFAULT NULL,
mobile_number 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)
);
SQL;
DB::statement($sql);
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('employee_masters');
}
};