- AccountCode 모델에 API와 동일한 필드 추가 (sub_category, parent_code, depth 등) - 카테고리 상수 정의 (CATEGORY_ASSET 등) - 블레이드 뷰에서 영문 카테고리 키 + 한글 라벨 매핑 적용
93 lines
2.1 KiB
PHP
93 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Barobill;
|
|
|
|
use App\Models\Tenants\Tenant;
|
|
use App\Traits\BelongsToTenant;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
/**
|
|
* 계정과목 모델
|
|
*
|
|
* API 프로젝트의 AccountCode 모델과 동일한 테이블 구조를 사용한다.
|
|
*/
|
|
class AccountCode extends Model
|
|
{
|
|
use BelongsToTenant;
|
|
|
|
protected $table = 'account_codes';
|
|
|
|
protected $fillable = [
|
|
'tenant_id',
|
|
'code',
|
|
'name',
|
|
'category',
|
|
'sub_category',
|
|
'parent_code',
|
|
'depth',
|
|
'department_type',
|
|
'description',
|
|
'sort_order',
|
|
'is_active',
|
|
];
|
|
|
|
protected $casts = [
|
|
'is_active' => 'boolean',
|
|
'sort_order' => 'integer',
|
|
'depth' => 'integer',
|
|
];
|
|
|
|
// Categories (대분류) — API 표준
|
|
public const CATEGORY_ASSET = 'asset';
|
|
public const CATEGORY_LIABILITY = 'liability';
|
|
public const CATEGORY_CAPITAL = 'capital';
|
|
public const CATEGORY_REVENUE = 'revenue';
|
|
public const CATEGORY_EXPENSE = 'expense';
|
|
|
|
public const CATEGORIES = [
|
|
self::CATEGORY_ASSET => '자산',
|
|
self::CATEGORY_LIABILITY => '부채',
|
|
self::CATEGORY_CAPITAL => '자본',
|
|
self::CATEGORY_REVENUE => '수익',
|
|
self::CATEGORY_EXPENSE => '비용',
|
|
];
|
|
|
|
/**
|
|
* 테넌트 관계
|
|
*/
|
|
public function tenant(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Tenant::class);
|
|
}
|
|
|
|
/**
|
|
* 테넌트별 활성 계정과목 조회 (하위 호환용)
|
|
*/
|
|
public static function getActiveByTenant(int $tenantId)
|
|
{
|
|
return self::getActive();
|
|
}
|
|
|
|
/**
|
|
* 전체 활성 계정과목 조회
|
|
*/
|
|
public static function getActive()
|
|
{
|
|
return self::where('is_active', true)
|
|
->orderBy('sort_order')
|
|
->orderBy('code')
|
|
->get();
|
|
}
|
|
|
|
/**
|
|
* 전체 계정과목 조회
|
|
*/
|
|
public static function getAll()
|
|
{
|
|
return self::orderBy('sort_order')
|
|
->orderBy('code')
|
|
->get();
|
|
}
|
|
}
|