make app database
This commit is contained in:
12
app/Domain/Loan/Enums/LoanStage.php
Normal file
12
app/Domain/Loan/Enums/LoanStage.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Loan\Enums;
|
||||
|
||||
enum LoanStage: string
|
||||
{
|
||||
case Validation = 'VALIDATION';
|
||||
case FraudCheck = 'FRAUD_CHECK';
|
||||
case GuarantorCheck = 'GUARANTOR_CHECK';
|
||||
case CreditCheck = 'CREDIT_CHECK';
|
||||
case ManagerApproval = 'MANAGER_APPROVAL';
|
||||
}
|
||||
20
app/Domain/Loan/Enums/LoanStatus.php
Normal file
20
app/Domain/Loan/Enums/LoanStatus.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Loan\Enums;
|
||||
|
||||
enum LoanStatus: string
|
||||
{
|
||||
case Submitted = 'SUBMITTED';
|
||||
case InProgress = 'IN_PROGRESS';
|
||||
case ManualReview = 'MANUAL_REVIEW';
|
||||
case Approved = 'APPROVED';
|
||||
case Rejected = 'REJECTED';
|
||||
|
||||
public function isTerminal(): bool
|
||||
{
|
||||
return match ($this) {
|
||||
self::ManualReview, self::Approved, self::Rejected => true,
|
||||
self::Submitted, self::InProgress => false,
|
||||
};
|
||||
}
|
||||
}
|
||||
10
app/Domain/Loan/Enums/StageResultType.php
Normal file
10
app/Domain/Loan/Enums/StageResultType.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Loan\Enums;
|
||||
|
||||
enum StageResultType: string
|
||||
{
|
||||
case Pass = 'PASS';
|
||||
case Fail = 'FAIL';
|
||||
case ManualReview = 'MANUAL_REVIEW';
|
||||
}
|
||||
10
app/Domain/Loan/Enums/WorkflowConfigurationStatus.php
Normal file
10
app/Domain/Loan/Enums/WorkflowConfigurationStatus.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Loan\Enums;
|
||||
|
||||
enum WorkflowConfigurationStatus: string
|
||||
{
|
||||
case Draft = 'DRAFT';
|
||||
case Published = 'PUBLISHED';
|
||||
case Archived = 'ARCHIVED';
|
||||
}
|
||||
73
app/Models/Loan.php
Normal file
73
app/Models/Loan.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Domain\Loan\Enums\LoanStatus;
|
||||
use Database\Factories\LoanFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
#[Fillable([
|
||||
'public_id',
|
||||
'customer_id',
|
||||
'loan_type_id',
|
||||
'workflow_configuration_id',
|
||||
'current_workflow_configuration_step_id',
|
||||
'amount',
|
||||
'phone',
|
||||
'monthly_income',
|
||||
'credit_score',
|
||||
'has_guarantor',
|
||||
'status',
|
||||
])]
|
||||
class Loan extends Model
|
||||
{
|
||||
/** @use HasFactory<LoanFactory> */
|
||||
use HasFactory;
|
||||
|
||||
protected $attributes = [
|
||||
'status' => LoanStatus::Submitted->value,
|
||||
];
|
||||
|
||||
public function getRouteKeyName(): string
|
||||
{
|
||||
return 'public_id';
|
||||
}
|
||||
|
||||
public function loanType(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(LoanType::class);
|
||||
}
|
||||
|
||||
public function workflowConfiguration(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(WorkflowConfiguration::class);
|
||||
}
|
||||
|
||||
public function currentStep(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(WorkflowConfigurationStep::class, 'current_workflow_configuration_step_id');
|
||||
}
|
||||
|
||||
public function histories(): HasMany
|
||||
{
|
||||
return $this->hasMany(LoanHistory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'amount' => 'integer',
|
||||
'monthly_income' => 'integer',
|
||||
'credit_score' => 'integer',
|
||||
'has_guarantor' => 'boolean',
|
||||
'status' => LoanStatus::class,
|
||||
];
|
||||
}
|
||||
}
|
||||
49
app/Models/LoanHistory.php
Normal file
49
app/Models/LoanHistory.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Domain\Loan\Enums\LoanStage;
|
||||
use App\Domain\Loan\Enums\StageResultType;
|
||||
use Database\Factories\LoanHistoryFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
#[Fillable([
|
||||
'loan_id',
|
||||
'workflow_configuration_step_id',
|
||||
'stage_code',
|
||||
'rules_snapshot',
|
||||
'result',
|
||||
'reason',
|
||||
'executed_at',
|
||||
])]
|
||||
class LoanHistory extends Model
|
||||
{
|
||||
/** @use HasFactory<LoanHistoryFactory> */
|
||||
use HasFactory;
|
||||
|
||||
public function loan(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Loan::class);
|
||||
}
|
||||
|
||||
public function workflowConfigurationStep(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(WorkflowConfigurationStep::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'stage_code' => LoanStage::class,
|
||||
'rules_snapshot' => 'array',
|
||||
'result' => StageResultType::class,
|
||||
'executed_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
}
|
||||
36
app/Models/LoanType.php
Normal file
36
app/Models/LoanType.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Database\Factories\LoanTypeFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
#[Fillable(['code', 'name', 'is_active'])]
|
||||
class LoanType extends Model
|
||||
{
|
||||
/** @use HasFactory<LoanTypeFactory> */
|
||||
use HasFactory;
|
||||
|
||||
public function workflowConfigurations(): HasMany
|
||||
{
|
||||
return $this->hasMany(WorkflowConfiguration::class);
|
||||
}
|
||||
|
||||
public function loans(): HasMany
|
||||
{
|
||||
return $this->hasMany(Loan::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
}
|
||||
}
|
||||
31
app/Models/StageDefinition.php
Normal file
31
app/Models/StageDefinition.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Database\Factories\StageDefinitionFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
#[Fillable(['code', 'name', 'is_active'])]
|
||||
class StageDefinition extends Model
|
||||
{
|
||||
/** @use HasFactory<StageDefinitionFactory> */
|
||||
use HasFactory;
|
||||
|
||||
public function workflowConfigurationSteps(): HasMany
|
||||
{
|
||||
return $this->hasMany(WorkflowConfigurationStep::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
}
|
||||
}
|
||||
58
app/Models/WorkflowConfiguration.php
Normal file
58
app/Models/WorkflowConfiguration.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Domain\Loan\Enums\WorkflowConfigurationStatus;
|
||||
use Database\Factories\WorkflowConfigurationFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
#[Fillable(['loan_type_id', 'name', 'version', 'status', 'published_at', 'created_by'])]
|
||||
class WorkflowConfiguration extends Model
|
||||
{
|
||||
/** @use HasFactory<WorkflowConfigurationFactory> */
|
||||
use HasFactory;
|
||||
|
||||
protected $attributes = [
|
||||
'status' => WorkflowConfigurationStatus::Draft->value,
|
||||
];
|
||||
|
||||
public function loanType(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(LoanType::class);
|
||||
}
|
||||
|
||||
public function steps(): HasMany
|
||||
{
|
||||
return $this->hasMany(WorkflowConfigurationStep::class)->orderBy('position');
|
||||
}
|
||||
|
||||
public function loans(): HasMany
|
||||
{
|
||||
return $this->hasMany(Loan::class);
|
||||
}
|
||||
|
||||
public function creator(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'created_by');
|
||||
}
|
||||
|
||||
public function isEditable(): bool
|
||||
{
|
||||
return $this->status === WorkflowConfigurationStatus::Draft;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'status' => WorkflowConfigurationStatus::class,
|
||||
'published_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
}
|
||||
43
app/Models/WorkflowConfigurationStep.php
Normal file
43
app/Models/WorkflowConfigurationStep.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Database\Factories\WorkflowConfigurationStepFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
#[Fillable(['workflow_configuration_id', 'stage_definition_id', 'position', 'rules', 'is_enabled'])]
|
||||
class WorkflowConfigurationStep extends Model
|
||||
{
|
||||
/** @use HasFactory<WorkflowConfigurationStepFactory> */
|
||||
use HasFactory;
|
||||
|
||||
public function workflowConfiguration(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(WorkflowConfiguration::class);
|
||||
}
|
||||
|
||||
public function stageDefinition(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(StageDefinition::class);
|
||||
}
|
||||
|
||||
public function loanHistories(): HasMany
|
||||
{
|
||||
return $this->hasMany(LoanHistory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'rules' => 'array',
|
||||
'is_enabled' => 'boolean',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user