89 lines
2.2 KiB
PHP
89 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace Modules\Investment\Entities;
|
|
|
|
use App\Traits\HasDocuments;
|
|
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
|
use Modules\Auth\Entities\User;
|
|
use Modules\Investment\Enums\InvestmentSource;
|
|
use Modules\Investment\Enums\InvestmentStatus;
|
|
|
|
class Investment extends Model
|
|
{
|
|
use HasDocuments, HasUuids;
|
|
|
|
protected $table = 'investments';
|
|
|
|
protected $fillable = [
|
|
'reference_no',
|
|
'user_id',
|
|
'investment_account_id',
|
|
'investment_type_id',
|
|
'amount',
|
|
'source',
|
|
'status',
|
|
'remarks',
|
|
'created_by',
|
|
'approved_by',
|
|
'approved_at',
|
|
'completed_at',
|
|
'cancelled_at',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'amount' => 'decimal:2',
|
|
'source' => InvestmentSource::class,
|
|
'status' => InvestmentStatus::class,
|
|
'approved_at' => 'datetime',
|
|
'completed_at' => 'datetime',
|
|
'cancelled_at' => 'datetime',
|
|
];
|
|
}
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'user_id');
|
|
}
|
|
|
|
public function account(): BelongsTo
|
|
{
|
|
return $this->belongsTo(InvestmentAccount::class, 'investment_account_id');
|
|
}
|
|
|
|
public function investmentType(): BelongsTo
|
|
{
|
|
return $this->belongsTo(InvestmentType::class, 'investment_type_id');
|
|
}
|
|
|
|
public function createdBy(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'created_by');
|
|
}
|
|
|
|
public function approvedBy(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'approved_by');
|
|
}
|
|
|
|
public function ledgerEntries(): HasMany
|
|
{
|
|
return $this->hasMany(InvestmentLedger::class, 'investment_id');
|
|
}
|
|
|
|
public function payment(): HasOne
|
|
{
|
|
return $this->hasOne(InvestmentPayment::class, 'investment_id');
|
|
}
|
|
|
|
public function salaryDeductionDetail(): HasOne
|
|
{
|
|
return $this->hasOne(SalaryDeductionBatchDetail::class, 'investment_id');
|
|
}
|
|
}
|