레거시 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>
140 lines
3.3 KiB
PHP
140 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Sales;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class SalesProspect extends Model
|
|
{
|
|
use SoftDeletes;
|
|
|
|
protected $table = 'sales_prospects';
|
|
|
|
protected $fillable = [
|
|
'manager_id',
|
|
'sales_manager_id',
|
|
'company_name',
|
|
'representative',
|
|
'business_no',
|
|
'contact_phone',
|
|
'email',
|
|
'address',
|
|
'status',
|
|
];
|
|
|
|
protected $casts = [
|
|
'created_at' => 'datetime',
|
|
'updated_at' => 'datetime',
|
|
'deleted_at' => 'datetime',
|
|
];
|
|
|
|
/**
|
|
* 등록한 영업 담당자
|
|
*/
|
|
public function manager(): BelongsTo
|
|
{
|
|
return $this->belongsTo(SalesManager::class, 'manager_id');
|
|
}
|
|
|
|
/**
|
|
* 담당 매니저
|
|
*/
|
|
public function salesManager(): BelongsTo
|
|
{
|
|
return $this->belongsTo(SalesManager::class, 'sales_manager_id');
|
|
}
|
|
|
|
/**
|
|
* 계약 상품 목록
|
|
*/
|
|
public function products(): HasMany
|
|
{
|
|
return $this->hasMany(SalesProspectProduct::class, 'prospect_id');
|
|
}
|
|
|
|
/**
|
|
* 시나리오 체크리스트
|
|
*/
|
|
public function scenarios(): HasMany
|
|
{
|
|
return $this->hasMany(SalesProspectScenario::class, 'prospect_id');
|
|
}
|
|
|
|
/**
|
|
* 상담 기록
|
|
*/
|
|
public function consultations(): HasMany
|
|
{
|
|
return $this->hasMany(SalesProspectConsultation::class, 'prospect_id');
|
|
}
|
|
|
|
/**
|
|
* 영업 실적
|
|
*/
|
|
public function records(): HasMany
|
|
{
|
|
return $this->hasMany(SalesRecord::class, 'prospect_id');
|
|
}
|
|
|
|
/**
|
|
* 상태 라벨
|
|
*/
|
|
public function getStatusLabelAttribute(): string
|
|
{
|
|
return match ($this->status) {
|
|
'lead' => '리드',
|
|
'prospect' => '가망',
|
|
'negotiation' => '협상중',
|
|
'contracted' => '계약완료',
|
|
'lost' => '실패',
|
|
default => $this->status,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* 상태별 색상 클래스
|
|
*/
|
|
public function getStatusColorAttribute(): string
|
|
{
|
|
return match ($this->status) {
|
|
'lead' => 'bg-gray-100 text-gray-800',
|
|
'prospect' => 'bg-blue-100 text-blue-800',
|
|
'negotiation' => 'bg-yellow-100 text-yellow-800',
|
|
'contracted' => 'bg-green-100 text-green-800',
|
|
'lost' => 'bg-red-100 text-red-800',
|
|
default => 'bg-gray-100 text-gray-800',
|
|
};
|
|
}
|
|
|
|
/**
|
|
* 사업자번호 포맷팅 (XXX-XX-XXXXX)
|
|
*/
|
|
public function getFormattedBusinessNoAttribute(): string
|
|
{
|
|
$bizNo = preg_replace('/[^0-9]/', '', $this->business_no);
|
|
if (strlen($bizNo) === 10) {
|
|
return substr($bizNo, 0, 3) . '-' . substr($bizNo, 3, 2) . '-' . substr($bizNo, 5);
|
|
}
|
|
return $this->business_no ?? '';
|
|
}
|
|
|
|
/**
|
|
* 총 계약금액
|
|
*/
|
|
public function getTotalContractAmountAttribute(): float
|
|
{
|
|
return $this->products()->sum('contract_amount');
|
|
}
|
|
|
|
/**
|
|
* 총 수수료
|
|
*/
|
|
public function getTotalCommissionAttribute(): float
|
|
{
|
|
return $this->products()->sum('commission_amount');
|
|
}
|
|
}
|