Add barcode scanner, thermal receipt printing, and printer settings.
Deploy Ladill POS / deploy (push) Successful in 1m42s
Deploy Ladill POS / deploy (push) Successful in 1m42s
Register supports USB keyboard-wedge scanners with SKU lookup (local catalog and CRM in retail mode). Sales get a thermal receipt print template (58/80mm) with configurable header/footer, plus optional auto-print after cash sales. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Http\Middleware\EnsurePlatformSession;
|
||||
use App\Models\PosLocation;
|
||||
use App\Models\PosProduct;
|
||||
use App\Models\PosSale;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PosHardwareTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private function user(): User
|
||||
{
|
||||
return User::create([
|
||||
'public_id' => 'u-'.uniqid(),
|
||||
'name' => 'Cashier',
|
||||
'email' => uniqid().'@example.com',
|
||||
]);
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->withoutMiddleware(EnsurePlatformSession::class);
|
||||
$this->withoutVite();
|
||||
|
||||
config([
|
||||
'crm.url' => 'https://crm.test/api',
|
||||
'crm.key' => 'test-crm-key',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_barcode_lookup_finds_local_product_in_restaurant_mode(): void
|
||||
{
|
||||
$user = $this->user();
|
||||
PosLocation::create([
|
||||
'owner_ref' => $user->public_id,
|
||||
'name' => 'Main register',
|
||||
'currency' => 'GHS',
|
||||
'service_style' => 'restaurant',
|
||||
]);
|
||||
PosProduct::create([
|
||||
'owner_ref' => $user->public_id,
|
||||
'name' => 'Water',
|
||||
'sku' => 'H2O-001',
|
||||
'price_minor' => 500,
|
||||
'currency' => 'GHS',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$this->actingAs($user)
|
||||
->getJson(route('pos.register.lookup', ['code' => 'H2O-001']))
|
||||
->assertOk()
|
||||
->assertJsonPath('product.name', 'Water')
|
||||
->assertJsonPath('product.price_minor', 500);
|
||||
}
|
||||
|
||||
public function test_barcode_lookup_returns_404_for_unknown_code(): void
|
||||
{
|
||||
$user = $this->user();
|
||||
PosLocation::create([
|
||||
'owner_ref' => $user->public_id,
|
||||
'name' => 'Main register',
|
||||
'currency' => 'GHS',
|
||||
'service_style' => 'restaurant',
|
||||
]);
|
||||
|
||||
$this->actingAs($user)
|
||||
->getJson(route('pos.register.lookup', ['code' => 'MISSING']))
|
||||
->assertNotFound();
|
||||
}
|
||||
|
||||
public function test_receipt_page_renders_thermal_layout(): void
|
||||
{
|
||||
$user = $this->user();
|
||||
$location = PosLocation::create([
|
||||
'owner_ref' => $user->public_id,
|
||||
'name' => 'Main register',
|
||||
'currency' => 'GHS',
|
||||
'receipt_header' => 'Acme Shop',
|
||||
'printer_paper_mm' => 58,
|
||||
]);
|
||||
$sale = PosSale::create([
|
||||
'owner_ref' => $user->public_id,
|
||||
'location_id' => $location->id,
|
||||
'reference' => 'POS-TEST',
|
||||
'currency' => 'GHS',
|
||||
'status' => 'paid',
|
||||
'payment_method' => 'cash',
|
||||
'total_minor' => 1000,
|
||||
]);
|
||||
$sale->lines()->create([
|
||||
'name' => 'Tea',
|
||||
'unit_price_minor' => 1000,
|
||||
'quantity' => 1,
|
||||
'line_total_minor' => 1000,
|
||||
]);
|
||||
|
||||
$this->actingAs($user)
|
||||
->get(route('pos.sales.receipt', $sale))
|
||||
->assertOk()
|
||||
->assertSee('Acme Shop')
|
||||
->assertSee('POS-TEST')
|
||||
->assertSee('Tea')
|
||||
->assertSee('Print receipt');
|
||||
}
|
||||
|
||||
public function test_cash_sale_redirects_to_receipt_when_auto_print_enabled(): void
|
||||
{
|
||||
Http::fake([
|
||||
'crm.test/api/customers*' => Http::response(['data' => []], 200),
|
||||
]);
|
||||
|
||||
$user = $this->user();
|
||||
PosLocation::create([
|
||||
'owner_ref' => $user->public_id,
|
||||
'name' => 'Main register',
|
||||
'currency' => 'GHS',
|
||||
'printer_auto_print' => true,
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($user)->post(route('pos.register.charge'), [
|
||||
'payment_method' => 'cash',
|
||||
'lines' => [
|
||||
['name' => 'Snack', 'unit_price_minor' => 500, 'quantity' => 1],
|
||||
],
|
||||
]);
|
||||
|
||||
$sale = PosSale::where('owner_ref', $user->public_id)->firstOrFail();
|
||||
$response->assertRedirect(route('pos.sales.receipt', ['sale' => $sale, 'autoprint' => 1]));
|
||||
}
|
||||
}
|
||||
@@ -65,7 +65,7 @@ class PosRegisterTest extends TestCase
|
||||
PosLocation::create(['owner_ref' => $user->public_id, 'name' => 'Main register', 'currency' => 'GHS', 'service_style' => 'restaurant']);
|
||||
PosProduct::create(['owner_ref' => $user->public_id, 'name' => 'Coffee', 'price_minor' => 1500, 'currency' => 'GHS', 'is_active' => true]);
|
||||
|
||||
$this->actingAs($user)->get(route('pos.register'))->assertOk()->assertSee('Coffee');
|
||||
$this->actingAs($user)->get(route('pos.register'))->assertOk()->assertSee('Coffee')->assertSee('Barcode scanner');
|
||||
}
|
||||
|
||||
public function test_retail_register_reads_crm_products_and_snapshots_lines(): void
|
||||
|
||||
Reference in New Issue
Block a user