Stage 7+14 — Mechanic Board + Scan Center
Mechanic Workflow (Stage 7): - /app/mechanic Filament page filtered to master_id = auth user - Kanban 4 columns (in_work / awaiting_parts / ready / recent), each card shows WO#, plate, client, complaint summary, photo presence - 2 KPI tiles (active now / closed today) - Mobile-responsive grid (auto-fit, minmax 260px) WarehouseService: - issueNow(WorkOrderPart) — consume reservations immediately scoped to one line, without closing the WO (mechanic physically takes part now) - returnPart(WorkOrderPart, qty?, notes?) — refund to stock as new batch at original buy_price, writes `return` event, capped at consumed total WO PartsRelationManager: - "Eliberează" action — visible when active reservation exists - "Restituire" action — visible when consumed reservation exists, with qty modal + notes Scan Center (Stage 14): - PartResource "QR" action — per-part SVG QR with payload PART:<article|id> - BulkAction "Tipărește etichete QR" → /parts/labels?ids=N,M (HTML A4 sheet, 3-col grid, print CSS hides toolbar) - /app/scan Filament page using html5-qrcode 2.3.8 (CDN), auto-picks back camera, decodes → Livewire dispatches scanner-decoded → resolveAndRedirect - Lookup matches PART:N prefix, parts.article, parts.barcode, or numeric id - Manual input fallback for browsers without camera Tests (6 new): - WarehouseIssueReturnTest (3): issueNow consumes immediately; returnPart creates positive batch + return event; over-return is capped - ScannerLookupTest (3): PART: prefix lookup, raw barcode lookup, unknown miss Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -262,6 +262,95 @@ class WarehouseService
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Issue parts NOW for a single WO line — used when the mechanic physically
|
||||
* takes the part from the shelf before the WO is closed. Same logic as
|
||||
* consume() but scoped to one work_order_part_id.
|
||||
*/
|
||||
public function issueNow(WorkOrderPart $wop): int
|
||||
{
|
||||
return DB::transaction(function () use ($wop) {
|
||||
$active = PartReservation::with(['batch', 'part'])
|
||||
->where('work_order_part_id', $wop->id)
|
||||
->where('status', PartReservation::STATUS_ACTIVE)
|
||||
->lockForUpdate()
|
||||
->get();
|
||||
|
||||
foreach ($active as $r) {
|
||||
$batch = $r->batch;
|
||||
if (! $batch) continue;
|
||||
$take = min((float) $r->qty, (float) $batch->qty_remaining);
|
||||
if ($take <= 0) continue;
|
||||
|
||||
$batch->qty_remaining = (float) $batch->qty_remaining - $take;
|
||||
$batch->save();
|
||||
|
||||
$this->logEvent(
|
||||
$r->part, $batch, $batch->warehouse,
|
||||
'issue', -$take, (float) $batch->buy_price,
|
||||
$wop->workOrder, "WO part #{$wop->id} (issue now)"
|
||||
);
|
||||
|
||||
$r->status = PartReservation::STATUS_CONSUMED;
|
||||
$r->consumed_at = now();
|
||||
$r->save();
|
||||
|
||||
if ($r->part) {
|
||||
$r->part->qty_reserved = max(0.0, (float) $r->part->qty_reserved - (float) $r->qty);
|
||||
$r->part->saveQuietly();
|
||||
}
|
||||
}
|
||||
|
||||
if ($wop->part) $this->syncPartCachedQty($wop->part);
|
||||
return $active->count();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Return parts physically taken back to stock. Creates a NEW batch with
|
||||
* the same buy_price as the original (FIFO-correct re-entry) and writes
|
||||
* a `return` event referencing the WO part.
|
||||
*/
|
||||
public function returnPart(WorkOrderPart $wop, ?float $qty = null, ?string $notes = null): ?PartBatch
|
||||
{
|
||||
if (! $wop->part_id) return null;
|
||||
|
||||
return DB::transaction(function () use ($wop, $qty, $notes) {
|
||||
$consumed = PartReservation::where('work_order_part_id', $wop->id)
|
||||
->where('status', PartReservation::STATUS_CONSUMED)
|
||||
->orderBy('consumed_at', 'desc')
|
||||
->get();
|
||||
|
||||
$totalConsumed = (float) $consumed->sum('qty');
|
||||
$qtyReturn = $qty !== null ? min((float) $qty, $totalConsumed) : $totalConsumed;
|
||||
if ($qtyReturn <= 0) return null;
|
||||
|
||||
$unitCost = (float) ($consumed->first()?->batch?->buy_price ?? $wop->buy_price);
|
||||
$warehouse = $consumed->first()?->batch?->warehouse
|
||||
?? $this->defaultWarehouse($wop->company_id);
|
||||
|
||||
$batch = PartBatch::create([
|
||||
'company_id' => $wop->company_id,
|
||||
'part_id' => $wop->part_id,
|
||||
'warehouse_id' => $warehouse->id,
|
||||
'qty_in' => $qtyReturn,
|
||||
'qty_remaining' => $qtyReturn,
|
||||
'buy_price' => $unitCost,
|
||||
'received_at' => now(),
|
||||
'notes' => $notes ?? "Retur de la WO part #{$wop->id}",
|
||||
]);
|
||||
|
||||
$this->logEvent(
|
||||
$wop->part, $batch, $warehouse,
|
||||
'return', $qtyReturn, $unitCost,
|
||||
$wop->workOrder, $notes ?? "Retur WO #{$wop->workOrder?->number}"
|
||||
);
|
||||
|
||||
$this->syncPartCachedQty($wop->part);
|
||||
return $batch;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Move stock between warehouses (FIFO from source). Creates one transfer_out
|
||||
* + one transfer_in batch in the destination warehouse.
|
||||
|
||||
Reference in New Issue
Block a user