Resolves TRU-78 (DRIFT 17: License plate scan - show 'last washed' timestamp on landing page / DHL use case). The POS landing page already surfaces license plate scans via `GET /numberplatescans`, but it has no way to tell the operator **when a plate was last washed**. With DHL trailers going in and out several times a day, the front-desk needs that hint to decide whether a trailer needs another wash before pick-up. ## Changes - **`orders_o::getLastWashTimestampForPlate(string $reg_1): ?string`** — new helper that returns the `created_at` (MySQL DATETIME) of the most recent non-deleted order for the plate that has at least one non-deleted order item. Mirrors the contract used by `customer_vehicles_o::getLastOrderByPlate()` so the timestamp is always backed by a real wash. - **`GET /numberplatescans`** now enriches each scan row with a `last_wash` key (string or `null`). No breaking change to the existing payload; new field is additive. - **New Pest test** `services/nginx/app/tests/Unit/Orders/OrderLastWashTimestampForPlateTest.php` — static-analysis assertions for the helper definition and the route wiring (matches the style of `OrderBookingsCountsRouteWiringTest`). ## Frontend companion https://github.com/copenhagentruckwash/pleno-vue/pull/335 renders this `last_wash` in the inline details of each scan row on the POS landing page (`PosLastScannedLicensePlatesV2.vue`), with an "Aldrig vasket" / "Never washed" fallback when the API returns `null`. ## Risk - `getLastWashTimestampForPlate` does one extra indexed read per scan row (`SELECT id FROM orders WHERE reg_1 = ? AND deleted_at IS NULL`). The existing `isPlateSeenBefore` call already does the same, so the route's per-row query count is unchanged in shape. - The new field is additive and ignored by older clients, so this can roll forward without a coordinated client release. Co-authored-by: openclaw bugfix <openclaw@copenhagentruckwash.local>
42 lines
2.0 KiB
PHP
42 lines
2.0 KiB
PHP
<?php
|
|
|
|
it('orders_o exposes getLastWashTimestampForPlate that filters out orders without order items', function (): void {
|
|
$ordersFile = app_path('objects/orders_o.php');
|
|
expect(is_file($ordersFile))->toBeTrue();
|
|
|
|
$ordersCode = preg_replace('/\s+/', ' ', (string)file_get_contents($ordersFile));
|
|
|
|
expect($ordersCode)->toContain('public function getLastWashTimestampForPlate(string $reg_1): ?string');
|
|
|
|
// The helper must look at non-deleted orders with non-deleted order items,
|
|
// matching the contract used by customer_vehicles_o::getLastOrderByPlate().
|
|
expect($ordersCode)->toContain("'reg_1' => $normalized_reg_1");
|
|
expect($ordersCode)->toContain("'deleted_at' => null");
|
|
expect($ordersCode)->toContain("'order_id' => $order_id");
|
|
expect($ordersCode)->toContain('return $created_at;');
|
|
expect($ordersCode)->toContain('return null;');
|
|
});
|
|
|
|
it('plateScansRoute enriches GET /numberplatescans with last_wash per scan (TRU-78)', function (): void {
|
|
$routeFile = app_path('routes/plateScansRoute.php');
|
|
$ordersFile = app_path('objects/orders_o.php');
|
|
|
|
expect(is_file($routeFile))->toBeTrue();
|
|
expect(is_file($ordersFile))->toBeTrue();
|
|
|
|
$routeCode = preg_replace('/\s+/', ' ', (string)file_get_contents($routeFile));
|
|
$ordersCode = preg_replace('/\s+/', ' ', (string)file_get_contents($ordersFile));
|
|
|
|
// The route already loads orders_o and customer_vehicles_o; verify the
|
|
// new enrichment is wired in the GET /numberplatescans handler.
|
|
expect($routeCode)->toContain("\$this->get('/numberplatescans', function () {");
|
|
expect($routeCode)->toContain("'last_wash'");
|
|
expect($routeCode)->toContain('getLastWashTimestampForPlate');
|
|
expect($routeCode)->toContain("'last_wash' => (new orders_o())->getLastWashTimestampForPlate");
|
|
expect($routeCode)->toContain('$tmp_scan_last_wash');
|
|
|
|
// The helper definition must live in orders_o so the enrichment is real,
|
|
// not a stub.
|
|
expect($ordersCode)->toContain('public function getLastWashTimestampForPlate(string $reg_1): ?string');
|
|
});
|