Files
sam-manage/app/Models/Rd/AiQuotation.php
김보곤 25795f8612 feat: [ai-quotation] 제조 견적서 자동 생성 기능 추가
- AI 2단계 분석: 고객 인터뷰 → 요구사항 추출 → 견적 산출
- 모델 확장: AiQuotation(모드/견적번호), AiQuotationItem(규격/단가/금액)
- AiQuotePriceTable 모델 신규 생성
- Create 페이지: 모듈/제조 모드 탭, 제품 카테고리, 고객 정보 입력
- Show 페이지: 제조 모드 분기 렌더링 (품목/금액/고객정보)
- Edit 페이지: 품목 인라인 편집, 할인/부가세/조건 입력
- Document: 한국 표준 제조업 견적서 양식 템플릿
- Controller/Route: update 엔드포인트, edit 라우트 추가
2026-03-03 15:58:16 +09:00

148 lines
3.6 KiB
PHP

<?php
namespace App\Models\Rd;
use App\Models\User;
use App\Traits\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
class AiQuotation extends Model
{
use BelongsToTenant, SoftDeletes;
protected $table = 'ai_quotations';
protected $fillable = [
'tenant_id',
'quote_mode',
'quote_number',
'product_category',
'title',
'input_type',
'input_text',
'input_file_path',
'ai_provider',
'ai_model',
'analysis_result',
'quotation_result',
'status',
'linked_quote_id',
'total_dev_cost',
'total_monthly_fee',
'created_by',
'options',
];
protected $casts = [
'analysis_result' => 'array',
'quotation_result' => 'array',
'options' => 'array',
'total_dev_cost' => 'decimal:0',
'total_monthly_fee' => 'decimal:0',
];
public const STATUS_PENDING = 'pending';
public const STATUS_PROCESSING = 'processing';
public const STATUS_COMPLETED = 'completed';
public const STATUS_FAILED = 'failed';
public const MODE_MODULE = 'module';
public const MODE_MANUFACTURE = 'manufacture';
public static function getStatuses(): array
{
return [
self::STATUS_PENDING => '대기',
self::STATUS_PROCESSING => '분석중',
self::STATUS_COMPLETED => '완료',
self::STATUS_FAILED => '실패',
];
}
public function getStatusLabelAttribute(): string
{
return match ($this->status) {
self::STATUS_PENDING => '대기',
self::STATUS_PROCESSING => '분석중',
self::STATUS_COMPLETED => '완료',
self::STATUS_FAILED => '실패',
default => $this->status,
};
}
public function getStatusColorAttribute(): string
{
return match ($this->status) {
self::STATUS_PENDING => 'badge-warning',
self::STATUS_PROCESSING => 'badge-info',
self::STATUS_COMPLETED => 'badge-success',
self::STATUS_FAILED => 'badge-error',
default => 'badge-ghost',
};
}
public function isCompleted(): bool
{
return $this->status === self::STATUS_COMPLETED;
}
public function isProcessing(): bool
{
return $this->status === self::STATUS_PROCESSING;
}
// Relations
public function items(): HasMany
{
return $this->hasMany(AiQuotationItem::class, 'ai_quotation_id')->orderBy('sort_order');
}
public function creator(): BelongsTo
{
return $this->belongsTo(User::class, 'created_by');
}
// Helpers
public function getOption(string $key, $default = null)
{
return data_get($this->options, $key, $default);
}
public function setOption(string $key, $value): void
{
$options = $this->options ?? [];
data_set($options, $key, $value);
$this->options = $options;
$this->save();
}
public function isManufacture(): bool
{
return $this->quote_mode === self::MODE_MANUFACTURE;
}
public function isModule(): bool
{
return $this->quote_mode === self::MODE_MODULE;
}
public function getFormattedDevCostAttribute(): string
{
return number_format((int) $this->total_dev_cost).'원';
}
public function getFormattedMonthlyFeeAttribute(): string
{
return number_format((int) $this->total_monthly_fee).'원';
}
}