Skip to content

Commit

Permalink
Merge pull request #374 from liberu-accounting/sweep/Implement-Employ…
Browse files Browse the repository at this point in the history
…ee-Payroll-Management-System

Implement Employee Payroll Management System
  • Loading branch information
curtisdelicata authored Dec 24, 2024
2 parents 2da2baf + b02ff04 commit 32063f2
Show file tree
Hide file tree
Showing 5 changed files with 255 additions and 0 deletions.
106 changes: 106 additions & 0 deletions app/Filament/Resources/PayrollResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@


<?php

namespace App\Filament\Resources;

use App\Filament\Resources\PayrollResource\Pages;
use App\Models\Payroll;
use Filament\Forms;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Forms\Form;
use Filament\Tables\Table;

class PayrollResource extends Resource
{
protected static ?string $model = Payroll::class;

protected static ?string $navigationIcon = 'heroicon-o-currency-dollar';
protected static ?string $navigationGroup = 'HR';

public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Select::make('employee_id')
->relationship('employee', 'name')
->required(),
Forms\Components\TextInput::make('base_salary')
->required()
->numeric()
->prefix('$'),
Forms\Components\TextInput::make('overtime_hours')
->numeric()
->default(0),
Forms\Components\TextInput::make('overtime_rate')
->numeric()
->prefix('$')
->default(0),
Forms\Components\TextInput::make('other_deductions')
->numeric()
->prefix('$')
->default(0),
Forms\Components\DatePicker::make('pay_period_start')
->required(),
Forms\Components\DatePicker::make('pay_period_end')
->required(),
Forms\Components\DatePicker::make('payment_date')
->required(),
Forms\Components\Select::make('payment_status')
->options([
'pending' => 'Pending',
'processed' => 'Processed',
'paid' => 'Paid',
])
->default('pending')
->required(),
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('employee.name')
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('base_salary')
->money('USD')
->sortable(),
Tables\Columns\TextColumn::make('net_salary')
->money('USD')
->sortable(),
Tables\Columns\TextColumn::make('payment_date')
->date()
->sortable(),
Tables\Columns\BadgeColumn::make('payment_status')
->colors([
'warning' => 'pending',
'primary' => 'processed',
'success' => 'paid',
]),
])
->filters([
Tables\Filters\SelectFilter::make('payment_status')
->options([
'pending' => 'Pending',
'processed' => 'Processed',
'paid' => 'Paid',
]),
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
]);
}

public static function getPages(): array
{
return [
'index' => Pages\ListPayrolls::route('/'),
'create' => Pages\CreatePayroll::route('/create'),
'edit' => Pages\EditPayroll::route('/{record}/edit'),
];
}
}
31 changes: 31 additions & 0 deletions app/Models/Employee.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@


<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Employee extends Model
{
use HasFactory;

protected $fillable = [
'name',
'email',
'position',
'hire_date',
'tax_id',
];

protected $casts = [
'hire_date' => 'date',
];

public function payrolls(): HasMany
{
return $this->hasMany(Payroll::class);
}
}
56 changes: 56 additions & 0 deletions app/Models/Payroll.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@


<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class Payroll extends Model
{
use HasFactory;

protected $fillable = [
'employee_id',
'base_salary',
'overtime_hours',
'overtime_rate',
'tax_deductions',
'other_deductions',
'net_salary',
'pay_period_start',
'pay_period_end',
'payment_date',
'payment_status',
];

protected $casts = [
'pay_period_start' => 'date',
'pay_period_end' => 'date',
'payment_date' => 'date',
'base_salary' => 'decimal:2',
'overtime_hours' => 'decimal:2',
'overtime_rate' => 'decimal:2',
'tax_deductions' => 'decimal:2',
'other_deductions' => 'decimal:2',
'net_salary' => 'decimal:2',
];

public function employee(): BelongsTo
{
return $this->belongsTo(Employee::class);
}

public function calculateNetSalary(): void
{
$overtimePay = $this->overtime_hours * $this->overtime_rate;
$grossSalary = $this->base_salary + $overtimePay;

// Calculate tax deductions (example rate of 20%)
$this->tax_deductions = $grossSalary * 0.20;

$this->net_salary = $grossSalary - $this->tax_deductions - $this->other_deductions;
}
}
28 changes: 28 additions & 0 deletions database/migrations/2024_02_24_000000_create_employees_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@


<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up(): void
{
Schema::create('employees', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->string('position');
$table->date('hire_date');
$table->string('tax_id')->unique();
$table->timestamps();
});
}

public function down(): void
{
Schema::dropIfExists('employees');
}
};
34 changes: 34 additions & 0 deletions database/migrations/2024_02_24_000001_create_payrolls_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@


<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up(): void
{
Schema::create('payrolls', function (Blueprint $table) {
$table->id();
$table->foreignId('employee_id')->constrained()->onDelete('cascade');
$table->decimal('base_salary', 10, 2);
$table->decimal('overtime_hours', 8, 2)->default(0);
$table->decimal('overtime_rate', 8, 2)->default(0);
$table->decimal('tax_deductions', 10, 2)->default(0);
$table->decimal('other_deductions', 10, 2)->default(0);
$table->decimal('net_salary', 10, 2);
$table->date('pay_period_start');
$table->date('pay_period_end');
$table->date('payment_date');
$table->string('payment_status')->default('pending');
$table->timestamps();
});
}

public function down(): void
{
Schema::dropIfExists('payrolls');
}
};

0 comments on commit 32063f2

Please sign in to comment.