Features: - Implement two fee types: entrance fee and annual fee (both NT$1,000) - Add 50% discount for disability certificate holders - Add disability certificate upload in member profile - Integrate disability verification into cashier approval workflow - Add membership fee settings in system admin Document permissions: - Fix hard-coded role logic in Document model - Use permission-based authorization instead of role checks Additional features: - Add announcements, general ledger, and trial balance modules - Add income management and accounting entries - Add comprehensive test suite with factories - Update UI translations to Traditional Chinese 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
102 lines
2.1 KiB
PHP
102 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class AccountingEntry extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
const ENTRY_TYPE_DEBIT = 'debit';
|
|
const ENTRY_TYPE_CREDIT = 'credit';
|
|
|
|
protected $fillable = [
|
|
'finance_document_id',
|
|
'income_id',
|
|
'chart_of_account_id',
|
|
'entry_type',
|
|
'amount',
|
|
'entry_date',
|
|
'description',
|
|
];
|
|
|
|
protected $casts = [
|
|
'entry_date' => 'date',
|
|
'amount' => 'decimal:2',
|
|
];
|
|
|
|
/**
|
|
* Get the finance document that owns this entry
|
|
*/
|
|
public function financeDocument()
|
|
{
|
|
return $this->belongsTo(FinanceDocument::class);
|
|
}
|
|
|
|
/**
|
|
* Get the income that owns this entry
|
|
*/
|
|
public function income()
|
|
{
|
|
return $this->belongsTo(Income::class);
|
|
}
|
|
|
|
/**
|
|
* Get the chart of account for this entry
|
|
*/
|
|
public function chartOfAccount()
|
|
{
|
|
return $this->belongsTo(ChartOfAccount::class);
|
|
}
|
|
|
|
/**
|
|
* Check if this is a debit entry
|
|
*/
|
|
public function isDebit(): bool
|
|
{
|
|
return $this->entry_type === self::ENTRY_TYPE_DEBIT;
|
|
}
|
|
|
|
/**
|
|
* Check if this is a credit entry
|
|
*/
|
|
public function isCredit(): bool
|
|
{
|
|
return $this->entry_type === self::ENTRY_TYPE_CREDIT;
|
|
}
|
|
|
|
/**
|
|
* Scope to filter debit entries
|
|
*/
|
|
public function scopeDebits($query)
|
|
{
|
|
return $query->where('entry_type', self::ENTRY_TYPE_DEBIT);
|
|
}
|
|
|
|
/**
|
|
* Scope to filter credit entries
|
|
*/
|
|
public function scopeCredits($query)
|
|
{
|
|
return $query->where('entry_type', self::ENTRY_TYPE_CREDIT);
|
|
}
|
|
|
|
/**
|
|
* Scope to filter by account
|
|
*/
|
|
public function scopeForAccount($query, $accountId)
|
|
{
|
|
return $query->where('chart_of_account_id', $accountId);
|
|
}
|
|
|
|
/**
|
|
* Scope to filter by date range
|
|
*/
|
|
public function scopeDateRange($query, $startDate, $endDate)
|
|
{
|
|
return $query->whereBetween('entry_date', [$startDate, $endDate]);
|
|
}
|
|
}
|