51a0bab39e
Schema:
- users + specialization, color, hourly_rate (pentru maistri)
- labors: catalog manopere standard cu category/ore/preț (RO+RU)
- work_orders: nr unique per tenant, status workflow (9 stări),
pay_status (3 stări), client/vehicle/master/deal/appointment refs,
complaint/diagnosis/recommendations, total auto-calculat
- wo_works: manopere per fișă, recalc auto la save/delete
- wo_parts: piese per fișă (free-text deocamdată), discount/total auto
Filament resources (group Service):
- LaborResource: CRUD + grupare pe categorie + filter active
- WorkOrderResource: form complex în 4 secțiuni (antet, diagnostic, plată)
+ 2 RelationManagers (Works, Parts)
- MasterResource: vedere User filtrată role=mechanic, edit specializare/
culoare calendar/tarif oră
Conversie auto: la adaugare manoperă din catalog Labor,
form populează numele + ore + preț/oră derivat (price/hours).
Number generator pentru WO: format WO-{YY}-{NNNN} per tenant per an,
calculat în CreateWorkOrder via WorkOrder::generateNumber().
Seed extins:
- 3 mecanici (Vasile/Andrei/Nicolae) cu culori + specializări
- 10 manopere standard din prototipul AutoCRM.html
- 1 fișă demo (BMW X5 plăcuțe Brembo) cu 1 manoperă + 1 piesă, total auto
56 lines
1.4 KiB
PHP
56 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Tenant;
|
|
|
|
use App\Models\Concerns\BelongsToTenant;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class WorkOrderWork extends Model
|
|
{
|
|
use BelongsToTenant;
|
|
|
|
protected $table = 'wo_works';
|
|
|
|
public const STATUSES = [
|
|
'todo' => 'De făcut',
|
|
'in_progress' => 'În lucru',
|
|
'done' => 'Finalizat',
|
|
];
|
|
|
|
protected $fillable = [
|
|
'company_id', 'work_order_id', 'labor_id', 'master_id',
|
|
'name', 'hours', 'price_per_hour', 'total', 'status', 'notes',
|
|
];
|
|
|
|
protected $casts = [
|
|
'hours' => 'decimal:2',
|
|
'price_per_hour' => 'decimal:2',
|
|
'total' => 'decimal:2',
|
|
];
|
|
|
|
public function workOrder(): BelongsTo
|
|
{
|
|
return $this->belongsTo(WorkOrder::class);
|
|
}
|
|
|
|
public function labor(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Labor::class);
|
|
}
|
|
|
|
public function master(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'master_id');
|
|
}
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::saving(function (self $row) {
|
|
$row->total = round((float) $row->hours * (float) $row->price_per_hour, 2);
|
|
});
|
|
static::saved(fn (self $row) => $row->workOrder?->recalcTotal());
|
|
static::deleted(fn (self $row) => $row->workOrder?->recalcTotal());
|
|
}
|
|
}
|