
PK 
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class SalaryComponent extends Model
{
protected $table = 'salary_components';
public $timestamps = false;
protected $fillable = [
'code',
'name',
'type',
'calculation_type',
'percentage_of',
'is_statutory',
'is_taxable',
'is_part_of_ctc',
'is_active',
'pf_applicable',
'esi_applicable',
'pt_applicable',
'display_order'
];
protected $casts = [
'is_statutory' => 'boolean',
'is_taxable' => 'boolean',
'is_part_of_ctc' => 'boolean',
'is_active' => 'boolean',
'pf_applicable' => 'boolean',
'esi_applicable' => 'boolean',
'pt_applicable' => 'boolean',
];
/**
* Employee component values
*/
public function employeeComponents()
{
return $this->hasMany(
EmployeeSalaryComponent::class,
'salary_component_id'
);
}
/**
* Payroll details relation
*/
public function payrollDetails()
{
return $this->hasMany(PayrollDetail::class);
}
/**
* Scopes
*/
public function scopeEarnings($query)
{
return $query->whereRaw('LOWER(type) = ?', ['earning']);
}
public function scopeDeductions($query)
{
return $query->whereRaw('LOWER(type) = ?', ['deduction']);
}
/**
* Helpers
*/
public function isEarning(): bool
{
return strtolower($this->type) === 'earning';
}
public function isDeduction(): bool
{
return strtolower($this->type) === 'deduction';
}
public function isEmployerContribution(): bool
{
return strtolower($this->type) === 'employercontribution';
}
}


PK 99