Files
sam-manage/app/Models/Sales/SalesProspectScenario.php
pro d39028d92a feat:영업관리 모듈 (salesmanagement) Laravel 마이그레이션
레거시 sales 시스템에서 MNG로 마이그레이션:
- 마이그레이션: sales_managers, sales_prospects, sales_records 등 6개 테이블
- 모델: SalesManager, SalesProspect, SalesRecord 등 6개 모델
- 컨트롤러: SalesManagerController, SalesProspectController, SalesRecordController
- 뷰: managers, prospects, records CRUD 화면
- 라우트: /sales/* 경로 추가

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-26 11:09:42 +09:00

69 lines
1.6 KiB
PHP

<?php
namespace App\Models\Sales;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class SalesProspectScenario extends Model
{
protected $table = 'sales_prospect_scenarios';
protected $fillable = [
'prospect_id',
'scenario_type',
'step_id',
'checkpoint_index',
'is_checked',
];
protected $casts = [
'step_id' => 'integer',
'checkpoint_index' => 'integer',
'is_checked' => 'boolean',
'created_at' => 'datetime',
'updated_at' => 'datetime',
];
/**
* 가망고객
*/
public function prospect(): BelongsTo
{
return $this->belongsTo(SalesProspect::class, 'prospect_id');
}
/**
* 시나리오 유형 라벨
*/
public function getScenarioTypeLabelAttribute(): string
{
return match ($this->scenario_type) {
'sales' => '영업 시나리오',
'manager' => '매니저 시나리오',
default => $this->scenario_type,
};
}
/**
* 특정 가망고객의 시나리오 진행률 계산
*/
public static function getProgressRate(int $prospectId, string $scenarioType): float
{
$total = self::where('prospect_id', $prospectId)
->where('scenario_type', $scenarioType)
->count();
if ($total === 0) {
return 0;
}
$checked = self::where('prospect_id', $prospectId)
->where('scenario_type', $scenarioType)
->where('is_checked', true)
->count();
return round(($checked / $total) * 100, 1);
}
}