qr_code_batches + qr_codes tables. State machine via
spatie/laravel-model-states (unassigned → allocated → active → used,
plus expired/voided). Serial format PH-{area}-{YYMM}-{batch}-{code}-
{checksum} with 2-char SHA-256-derived checksum. BatchGenerator
bulk-inserts in chunks. QrAllocator allocates free codes to verified
households (prefers area-targeted batch, falls back to any). Real
HouseholdVerified listener replaces the placeholder. QrBalanceLow
event for Module 11.
Admin: batch CRUD, mark-printed, void code, lifecycle search, PDF
print sheet (24/A4 via dompdf + endroid/qr-code + picqer/barcode).
Resident: list own codes, balance with low_balance flag, activate
allocated codes.
Removed explicit Event::listen for HouseholdVerified — Laravel 11
auto-discovers it via handle() type-hint, and double-registering was
causing double-dispatch.
130 feature tests passing.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
34 lines
1.2 KiB
PHP
34 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use App\Models\QrCode;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class QrCodeBatchResource extends JsonResource
|
|
{
|
|
public function toArray(Request $request): array
|
|
{
|
|
$statusCounts = $this->whenLoaded('codes', function () {
|
|
return $this->codes->groupBy(fn (QrCode $c) => (string) $c->status)
|
|
->map(fn ($group) => $group->count())
|
|
->all();
|
|
});
|
|
|
|
return [
|
|
'batch_number' => $this->batch_number,
|
|
'quantity' => $this->quantity,
|
|
'purpose' => $this->purpose,
|
|
'target_area' => $this->whenLoaded('targetArea', fn () => $this->targetArea?->code),
|
|
'target_store_id' => $this->target_store_id,
|
|
'created_by' => $this->whenLoaded('createdBy', fn () => $this->createdBy?->full_name),
|
|
'printed_at' => $this->printed_at?->toIso8601String(),
|
|
'expires_at' => $this->expires_at?->toIso8601String(),
|
|
'notes' => $this->notes,
|
|
'status_counts' => $statusCounts,
|
|
'created_at' => $this->created_at?->toIso8601String(),
|
|
];
|
|
}
|
|
}
|