Skip to content

Commit

Permalink
salary components relationships with salary slip
Browse files Browse the repository at this point in the history
  • Loading branch information
dhanuSama committed Apr 4, 2023
1 parent c13fca7 commit b647540
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
16 changes: 16 additions & 0 deletions src/Models/SalaryComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Visanduma\LaravelHrm\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphToMany;

class SalaryComponent extends Model
{
Expand All @@ -14,4 +15,19 @@ public function salStructures()
{
return $this->belongsToMany(SalaryStructure::class, 'hrm_salary_structure_components', 'sal_comp_id', 'sal_struct_id');
}

public function slips(): MorphToMany
{
return $this->morphToMany(SalarySlip::class,
'itemable',
'hrm_salary_slip_items',
'itemable_id',
'sal_slip_id'
);
}

public function isEarning()
{
return $this->type == 'earning' ? true : false;
}
}
11 changes: 2 additions & 9 deletions src/Models/SalarySlip.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public function claims(): MorphToMany
);
}

public function structures(): MorphToMany
public function components(): MorphToMany
{
return $this->morphedByMany(SalaryStructure::class,
return $this->morphedByMany(SalaryComponent::class,
'itemable',
'hrm_salary_slip_items',
'sal_slip_id'
Expand All @@ -38,11 +38,4 @@ public function employee()
{
return $this->belongsTo(Employee::class, 'emp_id');
}

// methods

public function totalSalary(SalaryStructure $obj): float
{
return $this->claims->sum('claimed_amount') + $obj->salComponents->sum('pivot.amount');
}
}
10 changes: 0 additions & 10 deletions src/Models/SalaryStructure.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,4 @@ public function assignors()
{
return $this->hasMany(SalaryStructurable::class, 'sal_struct_id', 'id');
}

public function slips(): MorphToMany
{
return $this->morphToMany(SalarySlip::class,
'itemable',
'hrm_salary_slip_items',
'itemable_id',
'sal_slip_id'
);
}
}

0 comments on commit b647540

Please sign in to comment.