Add restaurant/café mode: floor, open tabs, and kitchen display (Phase 1)
Deploy Ladill POS / deploy (push) Successful in 30s
Deploy Ladill POS / deploy (push) Successful in 30s
Gated by a per-location service_style (retail | restaurant). Restaurant mode adds: - Floor screen with tables (areas, seats, status) — tap a free table to open a dine-in tab; takeaway/counter orders open from the same screen. - Open tickets (tabs): a sale stays pending while items are added; lines persist as you go (posTicket Alpine component posts each change to the server). - Send-to-kitchen fires un-sent lines; a polling Kitchen Display (KDS) shows active tickets and bumps items queued → preparing → ready → served. - Settlement reuses the existing cash / Ladill Pay flow; paying closes the tab and frees the table (PosSaleService::closeTicket, wired into both pay paths). - Settings gains the mode toggle and a tables manager. Schema is additive (new pos_tables; service_style on locations; order/kitchen columns on sales + lines). Retail flow is untouched. Sidebar surfaces Floor + Kitchen only in restaurant mode. New PosRestaurantTest covers the dine-in lifecycle end to end; suite green (10 passed). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
e9a0c92308
commit
d9e4b6e06e
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Http\Middleware\EnsurePlatformSession;
|
||||
use App\Models\PosLocation;
|
||||
use App\Models\PosProduct;
|
||||
use App\Models\PosSale;
|
||||
use App\Models\PosSaleLine;
|
||||
use App\Models\PosTable;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PosRestaurantTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->withoutMiddleware(EnsurePlatformSession::class);
|
||||
$this->withoutVite();
|
||||
}
|
||||
|
||||
private function user(): User
|
||||
{
|
||||
return User::create([
|
||||
'public_id' => 'u-'.uniqid(),
|
||||
'name' => 'Server',
|
||||
'email' => uniqid().'@example.com',
|
||||
]);
|
||||
}
|
||||
|
||||
private function restaurant(User $user): array
|
||||
{
|
||||
$location = PosLocation::create([
|
||||
'owner_ref' => $user->public_id,
|
||||
'name' => 'Café',
|
||||
'currency' => 'GHS',
|
||||
'service_style' => PosLocation::STYLE_RESTAURANT,
|
||||
]);
|
||||
$table = PosTable::create([
|
||||
'owner_ref' => $user->public_id,
|
||||
'location_id' => $location->id,
|
||||
'label' => 'T1',
|
||||
'seats' => 4,
|
||||
'status' => PosTable::STATUS_FREE,
|
||||
]);
|
||||
$product = PosProduct::create([
|
||||
'owner_ref' => $user->public_id,
|
||||
'name' => 'Latte',
|
||||
'price_minor' => 2500,
|
||||
'currency' => 'GHS',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
return [$location, $table, $product];
|
||||
}
|
||||
|
||||
public function test_dine_in_ticket_lifecycle(): void
|
||||
{
|
||||
$user = $this->user();
|
||||
[, $table, $product] = $this->restaurant($user);
|
||||
|
||||
// Open a dine-in tab on the table.
|
||||
$this->actingAs($user)->post(route('pos.tickets.open'), [
|
||||
'order_type' => 'dine_in',
|
||||
'table_id' => $table->id,
|
||||
])->assertRedirect();
|
||||
|
||||
$sale = PosSale::where('owner_ref', $user->public_id)->firstOrFail();
|
||||
$this->assertSame(PosSale::ORDER_DINE_IN, $sale->order_type);
|
||||
$this->assertSame(PosSale::STATUS_PENDING, $sale->status);
|
||||
$this->assertTrue($sale->table_id === $table->id);
|
||||
$this->assertSame(PosTable::STATUS_OCCUPIED, $table->fresh()->status);
|
||||
|
||||
// Add an item to the tab.
|
||||
$this->actingAs($user)->postJson(route('pos.tickets.lines.add', $sale), [
|
||||
'product_id' => $product->id,
|
||||
'name' => $product->name,
|
||||
'unit_price_minor' => $product->price_minor,
|
||||
'quantity' => 2,
|
||||
])->assertOk()->assertJsonPath('total_minor', 5000);
|
||||
|
||||
// Fire it to the kitchen.
|
||||
$this->actingAs($user)->postJson(route('pos.tickets.send', $sale))
|
||||
->assertOk()->assertJsonPath('fired', 1);
|
||||
|
||||
$line = $sale->lines()->firstOrFail();
|
||||
$this->assertSame(PosSaleLine::KITCHEN_QUEUED, $line->fresh()->kitchen_state);
|
||||
$this->assertSame(PosSale::KITCHEN_ACTIVE, $sale->fresh()->kitchen_status);
|
||||
|
||||
// Kitchen feed shows the active ticket.
|
||||
$this->actingAs($user)->getJson(route('pos.kitchen.feed'))
|
||||
->assertOk()->assertJsonCount(1, 'tickets');
|
||||
|
||||
// Bump the line through to served.
|
||||
foreach (['preparing', 'ready', 'served'] as $expected) {
|
||||
$this->actingAs($user)->postJson(route('pos.kitchen.bump', $line))
|
||||
->assertOk()->assertJsonPath('state', $expected);
|
||||
}
|
||||
$this->assertSame(PosSale::KITCHEN_SERVED, $sale->fresh()->kitchen_status);
|
||||
|
||||
// Settle in cash — ticket paid, table freed.
|
||||
$this->actingAs($user)->post(route('pos.tickets.settle', $sale), [
|
||||
'payment_method' => 'cash',
|
||||
])->assertRedirect(route('pos.sales.show', $sale));
|
||||
|
||||
$this->assertSame(PosSale::STATUS_PAID, $sale->fresh()->status);
|
||||
$this->assertNotNull($sale->fresh()->closed_at);
|
||||
$this->assertSame(PosTable::STATUS_FREE, $table->fresh()->status);
|
||||
$this->assertNull($table->fresh()->current_sale_id);
|
||||
}
|
||||
|
||||
public function test_cannot_open_two_tabs_on_one_table(): void
|
||||
{
|
||||
$user = $this->user();
|
||||
[, $table] = $this->restaurant($user);
|
||||
|
||||
$this->actingAs($user)->post(route('pos.tickets.open'), [
|
||||
'order_type' => 'dine_in', 'table_id' => $table->id,
|
||||
])->assertRedirect();
|
||||
|
||||
$this->actingAs($user)->post(route('pos.tickets.open'), [
|
||||
'order_type' => 'dine_in', 'table_id' => $table->id,
|
||||
])->assertRedirect();
|
||||
|
||||
$this->assertSame(1, PosSale::where('owner_ref', $user->public_id)->count());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user