c90c35d930
Contextual multipliers layered on top of base MarkupRule pricing, applied
per work-order line based on vehicle, client and urgency.
Schema:
- pricing_coefficients (multiplier, conditions JSON, priority, stackable)
- vehicles.vehicle_class (sedan/suv/commercial/hybrid/ev/premium)
- clients.is_vip
- work_orders.urgency (normal/urgent/express)
PricingEngine::quote(Part, Vehicle?, Client?, urgency):
- base = MarkupRule on buy_price (fallback sell_price or buy×1.30)
- context: class (explicit or inferred hybrid/ev from fuel), age, vip, urgency
- stackable coefficients all multiply; non-stackable take only the highest
- returns {base, final, applied[]} breakdown
PricingCoefficient::matches(ctx) — classes/age range/vip/urgency conditions
(empty = always applies).
Filament:
- PricingCoefficientResource with condition builder (classes, age, vip, urgency)
- vehicle_class select, client is_vip toggle, WO urgency select
- "Preț inteligent" action on WO parts shows breakdown + applies sell_price
Tests (6 new):
- base-only without coefficients; age coefficient gating; VIP; express urgency;
stackable multiply vs non-stackable highest-wins; hybrid inferred from fuel
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
62 lines
1.6 KiB
PHP
62 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Tenant;
|
|
|
|
use App\Models\Concerns\BelongsToTenant;
|
|
use App\Models\Concerns\Auditable;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class Client extends Model
|
|
{
|
|
use Auditable, BelongsToTenant, SoftDeletes;
|
|
|
|
protected $fillable = [
|
|
'company_id', 'type', 'name', 'company_name',
|
|
'phone', 'phone_alt', 'email',
|
|
'telegram', 'telegram_chat_id', 'whatsapp', 'viber',
|
|
'notify_prefs',
|
|
'source', 'marketing_channel', 'status', 'is_vip',
|
|
'balance', 'discount_pct', 'notes',
|
|
'assigned_to', 'last_contact_at',
|
|
];
|
|
|
|
protected $casts = [
|
|
'balance' => 'decimal:2',
|
|
'discount_pct' => 'decimal:2',
|
|
'last_contact_at' => 'datetime',
|
|
'notify_prefs' => 'array',
|
|
'is_vip' => 'boolean',
|
|
];
|
|
|
|
/** Normalize a phone number to E.164-ish digits for matching. */
|
|
public static function normalizePhone(?string $phone): ?string
|
|
{
|
|
if (! $phone) return null;
|
|
$digits = preg_replace('/[^0-9]/', '', $phone);
|
|
return $digits ?: null;
|
|
}
|
|
|
|
public function vehicles(): HasMany
|
|
{
|
|
return $this->hasMany(Vehicle::class);
|
|
}
|
|
|
|
public function workOrders(): HasMany
|
|
{
|
|
return $this->hasMany(WorkOrder::class);
|
|
}
|
|
|
|
public function payments(): HasMany
|
|
{
|
|
return $this->hasMany(Payment::class);
|
|
}
|
|
|
|
public function assignedTo(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'assigned_to');
|
|
}
|
|
}
|