Files
sam-api/app/Models/Tenants/IncomeTaxBracket.php
김보곤 82621a6045 feat: [payroll] MNG 급여관리 계산 엔진 및 일괄 처리 API 구현
- IncomeTaxBracket 모델 추가 (2024 간이세액표 DB 조회)
- PayrollService 전면 개편: 4대보험 + 소득세 자동 계산 엔진
- 10,000천원 초과 고소득 구간 공식 계산 지원
- 과세표준 = 총지급액 - 식대(비과세), 10원 단위 절삭
- 일괄 생성(bulkGenerate), 전월 복사(copyFromPrevious) 기능
- 확정취소(unconfirm), 지급취소(unpay) 상태 관리
- 계산 미리보기(calculatePreview) 엔드포인트 추가
- 공제항목 수동 오버라이드(deduction_overrides) 지원
- Payroll 모델에 long_term_care, options 필드 추가
2026-03-11 19:18:27 +09:00

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;
}
}