99 lines
2.4 KiB
PHP
99 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class FinancialReport extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
public const TYPE_REVENUE_EXPENDITURE = 'revenue_expenditure';
|
|
public const TYPE_BALANCE_SHEET = 'balance_sheet';
|
|
public const TYPE_PROPERTY_INVENTORY = 'property_inventory';
|
|
public const TYPE_INTERNAL_MANAGEMENT = 'internal_management';
|
|
|
|
public const STATUS_DRAFT = 'draft';
|
|
public const STATUS_FINALIZED = 'finalized';
|
|
public const STATUS_APPROVED = 'approved';
|
|
public const STATUS_SUBMITTED = 'submitted';
|
|
|
|
protected $fillable = [
|
|
'report_type',
|
|
'fiscal_year',
|
|
'period_start',
|
|
'period_end',
|
|
'status',
|
|
'budget_id',
|
|
'generated_by_user_id',
|
|
'approved_by_user_id',
|
|
'approved_at',
|
|
'file_path',
|
|
'notes',
|
|
];
|
|
|
|
protected $casts = [
|
|
'fiscal_year' => 'integer',
|
|
'period_start' => 'date',
|
|
'period_end' => 'date',
|
|
'approved_at' => 'datetime',
|
|
];
|
|
|
|
// Relationships
|
|
|
|
public function budget(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Budget::class);
|
|
}
|
|
|
|
public function generatedBy(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'generated_by_user_id');
|
|
}
|
|
|
|
public function approvedBy(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'approved_by_user_id');
|
|
}
|
|
|
|
// Helper methods
|
|
|
|
public function isDraft(): bool
|
|
{
|
|
return $this->status === self::STATUS_DRAFT;
|
|
}
|
|
|
|
public function isFinalized(): bool
|
|
{
|
|
return $this->status === self::STATUS_FINALIZED;
|
|
}
|
|
|
|
public function isApproved(): bool
|
|
{
|
|
return $this->status === self::STATUS_APPROVED;
|
|
}
|
|
|
|
public function isSubmitted(): bool
|
|
{
|
|
return $this->status === self::STATUS_SUBMITTED;
|
|
}
|
|
|
|
public function canBeEdited(): bool
|
|
{
|
|
return $this->status === self::STATUS_DRAFT;
|
|
}
|
|
|
|
public function getReportTypeNameAttribute(): string
|
|
{
|
|
return match($this->report_type) {
|
|
self::TYPE_REVENUE_EXPENDITURE => '收支決算表',
|
|
self::TYPE_BALANCE_SHEET => '資產負債表',
|
|
self::TYPE_PROPERTY_INVENTORY => '財產目錄',
|
|
self::TYPE_INTERNAL_MANAGEMENT => '內部管理報表',
|
|
default => $this->report_type,
|
|
};
|
|
}
|
|
}
|