65 lines
1.8 KiB
PHP
65 lines
1.8 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Models\Tenants;
|
||
|
|
|
||
|
|
use Illuminate\Database\Eloquent\Builder;
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
|
||
|
|
class IncomeTaxBracket extends Model
|
||
|
|
{
|
||
|
|
protected $table = 'income_tax_brackets';
|
||
|
|
|
||
|
|
protected $fillable = [
|
||
|
|
'tax_year',
|
||
|
|
'salary_from',
|
||
|
|
'salary_to',
|
||
|
|
'family_count',
|
||
|
|
'tax_amount',
|
||
|
|
];
|
||
|
|
|
||
|
|
protected $casts = [
|
||
|
|
'tax_year' => 'integer',
|
||
|
|
'salary_from' => 'integer',
|
||
|
|
'salary_to' => 'integer',
|
||
|
|
'family_count' => 'integer',
|
||
|
|
'tax_amount' => 'integer',
|
||
|
|
];
|
||
|
|
|
||
|
|
public function scopeForYear(Builder $query, int $year): Builder
|
||
|
|
{
|
||
|
|
return $query->where('tax_year', $year);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function scopeForSalaryRange(Builder $query, int $salaryThousand): Builder
|
||
|
|
{
|
||
|
|
return $query->where('salary_from', '<=', $salaryThousand)
|
||
|
|
->where(function ($q) use ($salaryThousand) {
|
||
|
|
$q->where('salary_to', '>', $salaryThousand)
|
||
|
|
->orWhere(function ($q2) use ($salaryThousand) {
|
||
|
|
$q2->whereColumn('salary_from', 'salary_to')
|
||
|
|
->where('salary_from', $salaryThousand);
|
||
|
|
});
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
public function scopeForFamilyCount(Builder $query, int $count): Builder
|
||
|
|
{
|
||
|
|
return $query->where('family_count', $count);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 간이세액표에서 세액 조회
|
||
|
|
*/
|
||
|
|
public static function lookupTax(int $year, int $salaryThousand, int $familyCount): int
|
||
|
|
{
|
||
|
|
$familyCount = max(1, min(11, $familyCount));
|
||
|
|
|
||
|
|
$bracket = static::forYear($year)
|
||
|
|
->forSalaryRange($salaryThousand)
|
||
|
|
->forFamilyCount($familyCount)
|
||
|
|
->first();
|
||
|
|
|
||
|
|
return $bracket ? $bracket->tax_amount : 0;
|
||
|
|
}
|
||
|
|
}
|