Initial commit

This commit is contained in:
2025-11-20 23:21:05 +08:00
commit 13bc6db529
378 changed files with 54527 additions and 0 deletions

View File

@@ -0,0 +1,87 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Transaction extends Model
{
use HasFactory;
protected $fillable = [
'budget_item_id',
'chart_of_account_id',
'transaction_date',
'amount',
'transaction_type',
'description',
'reference_number',
'finance_document_id',
'membership_payment_id',
'created_by_user_id',
'notes',
];
protected $casts = [
'transaction_date' => 'date',
'amount' => 'decimal:2',
];
// Relationships
public function budgetItem(): BelongsTo
{
return $this->belongsTo(BudgetItem::class);
}
public function chartOfAccount(): BelongsTo
{
return $this->belongsTo(ChartOfAccount::class);
}
public function financeDocument(): BelongsTo
{
return $this->belongsTo(FinanceDocument::class);
}
public function membershipPayment(): BelongsTo
{
return $this->belongsTo(MembershipPayment::class);
}
public function createdBy(): BelongsTo
{
return $this->belongsTo(User::class, 'created_by_user_id');
}
// Helper methods
public function isIncome(): bool
{
return $this->transaction_type === 'income';
}
public function isExpense(): bool
{
return $this->transaction_type === 'expense';
}
// Scopes
public function scopeIncome($query)
{
return $query->where('transaction_type', 'income');
}
public function scopeExpense($query)
{
return $query->where('transaction_type', 'expense');
}
public function scopeForPeriod($query, $startDate, $endDate)
{
return $query->whereBetween('transaction_date', [$startDate, $endDate]);
}
}