Files
sam-api/app/Models/Tenants/ExpenseAccount.php
유병철 0044779eb4 feat: [finance] 계정과목 확장 및 전표 연동 시스템 구현
- AccountCode 모델/서비스 확장 (업데이트, 기본 계정과목 시딩)
- JournalSyncService 추가 (전표 자동 연동)
- SyncsExpenseAccounts 트레이트 추가
- CardTransactionController, TaxInvoiceController 기능 확장
- expense_accounts 테이블에 전표 연결 컬럼 마이그레이션
- account_codes 테이블 확장 마이그레이션
- 전체 테넌트 기본 계정과목 시딩 마이그레이션

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 10:32:20 +09:00

108 lines
2.5 KiB
PHP

<?php
namespace App\Models\Tenants;
use App\Models\Orders\Client;
use App\Traits\Auditable;
use App\Traits\BelongsToTenant;
use App\Traits\ModelTrait;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* 비용 계정 모델
*
* CEO 대시보드용 비용 데이터 (복리후생비, 접대비 등)
*/
class ExpenseAccount extends Model
{
use Auditable, BelongsToTenant, HasFactory, ModelTrait, SoftDeletes;
protected $table = 'expense_accounts';
protected $fillable = [
'tenant_id',
'account_type',
'sub_type',
'expense_date',
'amount',
'description',
'receipt_no',
'vendor_id',
'vendor_name',
'payment_method',
'card_no',
'loan_id',
'journal_entry_id',
'journal_entry_line_id',
'created_by',
'updated_by',
'deleted_by',
];
protected $casts = [
'expense_date' => 'date',
'amount' => 'decimal:2',
];
// 계정 유형 상수
public const TYPE_WELFARE = 'welfare';
public const TYPE_ENTERTAINMENT = 'entertainment';
public const TYPE_TRAVEL = 'travel';
public const TYPE_OFFICE = 'office';
// 세부 유형 상수 (접대비)
public const SUB_TYPE_GIFT_CERTIFICATE = 'gift_certificate';
// 세부 유형 상수 (복리후생)
public const SUB_TYPE_MEAL = 'meal';
public const SUB_TYPE_HEALTH = 'health';
public const SUB_TYPE_EDUCATION = 'education';
// 결제 수단 상수
public const PAYMENT_CARD = 'card';
public const PAYMENT_CASH = 'cash';
public const PAYMENT_TRANSFER = 'transfer';
/**
* 거래처 관계
*/
public function vendor(): BelongsTo
{
return $this->belongsTo(Client::class, 'vendor_id');
}
/**
* 복리후생비 스코프
*/
public function scopeWelfare($query)
{
return $query->where('account_type', self::TYPE_WELFARE);
}
/**
* 접대비 스코프
*/
public function scopeEntertainment($query)
{
return $query->where('account_type', self::TYPE_ENTERTAINMENT);
}
/**
* 기간 필터 스코프
*/
public function scopeInPeriod($query, string $startDate, string $endDate)
{
return $query->whereBetween('expense_date', [$startDate, $endDate]);
}
}