feat: 견적 시스템 API

- 5130의 71개 하드코딩 컬럼을 동적 카테고리 필드 시스템으로 전환
- 모터 브라켓 계산 등 핵심 비즈니스 로직 FormulaParser에 통합
- 파라미터 기반 동적 견적 폼 시스템 구축
- 견적 상태 워크플로 (DRAFT → SENT → APPROVED/REJECTED/EXPIRED)
- 모델셋 관리 API: 카테고리+제품+BOM 통합 관리
- 견적 관리 API: 생성/수정/복제/상태변경/미리보기 기능

주요 구현 사항:
- EstimateController/EstimateService: 견적 비즈니스 로직
- ModelSetController/ModelSetService: 모델셋 관리 로직
- Estimate/EstimateItem 모델: 견적 데이터 구조
- 동적 견적 필드 마이그레이션: 스크린/철재 제품 구조
- API 라우트 17개 엔드포인트 추가
- 다국어 메시지 지원 (성공/에러 메시지)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-09-24 17:41:26 +09:00
parent eb42d11f5e
commit 2d9217c9b4
14 changed files with 2021 additions and 0 deletions

View File

@@ -0,0 +1,108 @@
<?php
namespace App\Models\Estimate;
use App\Models\Commons\Category;
use App\Models\Contracts\BelongsToTenant;
use App\Traits\BelongsToTenantTrait;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
class Estimate extends Model implements BelongsToTenant
{
use HasFactory, SoftDeletes, BelongsToTenantTrait;
protected $fillable = [
'tenant_id',
'model_set_id',
'estimate_no',
'estimate_name',
'customer_name',
'project_name',
'parameters',
'calculated_results',
'bom_data',
'total_amount',
'status',
'notes',
'valid_until',
'created_by',
'updated_by',
'deleted_by',
];
protected $casts = [
'parameters' => 'array',
'calculated_results' => 'array',
'bom_data' => 'array',
'total_amount' => 'decimal:2',
'valid_until' => 'date',
'created_at' => 'datetime',
'updated_at' => 'datetime',
'deleted_at' => 'datetime',
];
/**
* 모델셋 관계 (카테고리)
*/
public function modelSet(): BelongsTo
{
return $this->belongsTo(Category::class, 'model_set_id');
}
/**
* 견적 항목들
*/
public function items(): HasMany
{
return $this->hasMany(EstimateItem::class);
}
/**
* 견적 번호 자동 생성
*/
public static function generateEstimateNo(int $tenantId): string
{
$prefix = 'EST';
$date = now()->format('Ymd');
$lastEstimate = self::where('tenant_id', $tenantId)
->whereDate('created_at', today())
->orderBy('id', 'desc')
->first();
$sequence = $lastEstimate ? (int) substr($lastEstimate->estimate_no, -3) + 1 : 1;
return $prefix . $date . str_pad($sequence, 3, '0', STR_PAD_LEFT);
}
/**
* 견적 상태별 스코프
*/
public function scopeDraft($query)
{
return $query->where('status', 'DRAFT');
}
public function scopeSent($query)
{
return $query->where('status', 'SENT');
}
public function scopeApproved($query)
{
return $query->where('status', 'APPROVED');
}
/**
* 만료된 견적 스코프
*/
public function scopeExpired($query)
{
return $query->whereNotNull('valid_until')
->where('valid_until', '<', now());
}
}

View File

@@ -0,0 +1,81 @@
<?php
namespace App\Models\Estimate;
use App\Models\Contracts\BelongsToTenant;
use App\Traits\BelongsToTenantTrait;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
class EstimateItem extends Model implements BelongsToTenant
{
use HasFactory, SoftDeletes, BelongsToTenantTrait;
protected $fillable = [
'tenant_id',
'estimate_id',
'sequence',
'item_name',
'item_description',
'parameters',
'calculated_values',
'unit_price',
'quantity',
'total_price',
'bom_components',
'notes',
'created_by',
'updated_by',
'deleted_by',
];
protected $casts = [
'parameters' => 'array',
'calculated_values' => 'array',
'unit_price' => 'decimal:2',
'quantity' => 'decimal:2',
'total_price' => 'decimal:2',
'bom_components' => 'array',
'created_at' => 'datetime',
'updated_at' => 'datetime',
'deleted_at' => 'datetime',
];
/**
* 견적 관계
*/
public function estimate(): BelongsTo
{
return $this->belongsTo(Estimate::class);
}
/**
* 순번별 정렬
*/
public function scopeOrdered($query)
{
return $query->orderBy('sequence');
}
/**
* 총 금액 계산
*/
public function calculateTotalPrice(): float
{
return $this->unit_price * $this->quantity;
}
/**
* 저장 시 총 금액 자동 계산
*/
protected static function boot()
{
parent::boot();
static::saving(function ($item) {
$item->total_price = $item->calculateTotalPrice();
});
}
}