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:
@@ -7,9 +7,11 @@ use App\Http\Controllers\Pos\Concerns\ScopesToAccount;
|
|||||||
use App\Models\PosLocation;
|
use App\Models\PosLocation;
|
||||||
use App\Models\PosProduct;
|
use App\Models\PosProduct;
|
||||||
use App\Models\PosSale;
|
use App\Models\PosSale;
|
||||||
|
use App\Services\Pos\PosBarcodeLookupService;
|
||||||
use App\Services\Pos\PosLocationService;
|
use App\Services\Pos\PosLocationService;
|
||||||
use App\Services\Pos\PosSaleService;
|
use App\Services\Pos\PosSaleService;
|
||||||
use App\Services\Crm\CrmClient;
|
use App\Services\Crm\CrmClient;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\RedirectResponse;
|
use Illuminate\Http\RedirectResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\View\View;
|
use Illuminate\View\View;
|
||||||
@@ -19,7 +21,11 @@ class RegisterController extends Controller
|
|||||||
{
|
{
|
||||||
use ScopesToAccount;
|
use ScopesToAccount;
|
||||||
|
|
||||||
public function __construct(private PosSaleService $sales, private PosLocationService $locations) {}
|
public function __construct(
|
||||||
|
private PosSaleService $sales,
|
||||||
|
private PosLocationService $locations,
|
||||||
|
private PosBarcodeLookupService $barcodes,
|
||||||
|
) {}
|
||||||
|
|
||||||
public function index(Request $request): View
|
public function index(Request $request): View
|
||||||
{
|
{
|
||||||
@@ -30,20 +36,43 @@ class RegisterController extends Controller
|
|||||||
'products' => $this->registerProducts($owner, $location),
|
'products' => $this->registerProducts($owner, $location),
|
||||||
'location' => $location,
|
'location' => $location,
|
||||||
'crmCustomers' => $this->crmCustomers($owner),
|
'crmCustomers' => $this->crmCustomers($owner),
|
||||||
|
'barcodeLookupUrl' => route('pos.register.lookup'),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function lookup(Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
$data = $request->validate([
|
||||||
|
'code' => ['required', 'string', 'max:80'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$owner = $this->ownerRef($request);
|
||||||
|
$location = $this->locations->ensureDefault($owner);
|
||||||
|
$product = $this->barcodes->lookup($owner, $location, $data['code']);
|
||||||
|
|
||||||
|
if (! $product || $product['price_minor'] <= 0 || $product['name'] === '') {
|
||||||
|
return response()->json(['message' => 'No product found for that barcode.'], 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->json(['product' => $product]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register catalog: local pos_products in restaurant mode, live CRM products
|
* Register catalog: local pos_products in restaurant mode, live CRM products
|
||||||
* in retail mode (resilient — empty if CRM is unreachable).
|
* in retail mode (resilient — empty if CRM is unreachable).
|
||||||
*
|
*
|
||||||
* @return list<array{id: int|string|null, name: string, price_minor: int}>
|
* @return list<array{id: int|string|null, name: string, price_minor: int, sku: string|null}>
|
||||||
*/
|
*/
|
||||||
private function registerProducts(string $owner, PosLocation $location): array
|
private function registerProducts(string $owner, PosLocation $location): array
|
||||||
{
|
{
|
||||||
if ($location->isRestaurant()) {
|
if ($location->isRestaurant()) {
|
||||||
return PosProduct::owned($owner)->active()->orderBy('name')->get()
|
return PosProduct::owned($owner)->active()->orderBy('name')->get()
|
||||||
->map(fn (PosProduct $p) => ['id' => $p->id, 'name' => $p->name, 'price_minor' => $p->price_minor])
|
->map(fn (PosProduct $p) => [
|
||||||
|
'id' => $p->id,
|
||||||
|
'name' => $p->name,
|
||||||
|
'price_minor' => $p->price_minor,
|
||||||
|
'sku' => $p->sku,
|
||||||
|
])
|
||||||
->all();
|
->all();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,6 +87,7 @@ class RegisterController extends Controller
|
|||||||
'id' => $r['id'] ?? null,
|
'id' => $r['id'] ?? null,
|
||||||
'name' => (string) ($r['name'] ?? ''),
|
'name' => (string) ($r['name'] ?? ''),
|
||||||
'price_minor' => (int) ($r['unit_price_minor'] ?? 0),
|
'price_minor' => (int) ($r['unit_price_minor'] ?? 0),
|
||||||
|
'sku' => isset($r['sku']) && $r['sku'] !== '' ? (string) $r['sku'] : null,
|
||||||
])
|
])
|
||||||
->filter(fn ($r) => $r['name'] !== '' && $r['price_minor'] > 0)
|
->filter(fn ($r) => $r['name'] !== '' && $r['price_minor'] > 0)
|
||||||
->values()
|
->values()
|
||||||
@@ -126,6 +156,12 @@ class RegisterController extends Controller
|
|||||||
if ($data['payment_method'] === 'cash') {
|
if ($data['payment_method'] === 'cash') {
|
||||||
$this->sales->recordCashPayment($sale);
|
$this->sales->recordCashPayment($sale);
|
||||||
|
|
||||||
|
if ($location->printer_auto_print) {
|
||||||
|
return redirect()
|
||||||
|
->route('pos.sales.receipt', ['sale' => $sale, 'autoprint' => 1])
|
||||||
|
->with('success', 'Cash sale recorded.');
|
||||||
|
}
|
||||||
|
|
||||||
return redirect()
|
return redirect()
|
||||||
->route('pos.sales.show', $sale)
|
->route('pos.sales.show', $sale)
|
||||||
->with('success', 'Cash sale recorded.');
|
->with('success', 'Cash sale recorded.');
|
||||||
|
|||||||
@@ -44,6 +44,18 @@ class SaleController extends Controller
|
|||||||
return view('pos.sales.show', compact('sale', 'invoiceUrl'));
|
return view('pos.sales.show', compact('sale', 'invoiceUrl'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function receipt(Request $request, PosSale $sale): View
|
||||||
|
{
|
||||||
|
$this->authorizeOwner($request, $sale);
|
||||||
|
$sale->load('lines', 'location');
|
||||||
|
|
||||||
|
return view('pos.receipts.print', [
|
||||||
|
'sale' => $sale,
|
||||||
|
'location' => $sale->location,
|
||||||
|
'autoprint' => $request->boolean('autoprint'),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
public function cancel(Request $request, PosSale $sale): RedirectResponse
|
public function cancel(Request $request, PosSale $sale): RedirectResponse
|
||||||
{
|
{
|
||||||
$this->authorizeOwner($request, $sale);
|
$this->authorizeOwner($request, $sale);
|
||||||
|
|||||||
@@ -42,6 +42,9 @@ class SettingsController extends Controller
|
|||||||
'currency' => ['required', 'string', 'size:3'],
|
'currency' => ['required', 'string', 'size:3'],
|
||||||
'service_style' => ['required', 'in:retail,restaurant'],
|
'service_style' => ['required', 'in:retail,restaurant'],
|
||||||
'receipt_footer' => ['nullable', 'string', 'max:1000'],
|
'receipt_footer' => ['nullable', 'string', 'max:1000'],
|
||||||
|
'receipt_header' => ['nullable', 'string', 'max:500'],
|
||||||
|
'printer_paper_mm' => ['required', 'in:58,80'],
|
||||||
|
'printer_auto_print' => ['sometimes', 'boolean'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$user = ladill_account() ?? $request->user();
|
$user = ladill_account() ?? $request->user();
|
||||||
@@ -56,6 +59,9 @@ class SettingsController extends Controller
|
|||||||
'currency' => strtoupper($data['currency']),
|
'currency' => strtoupper($data['currency']),
|
||||||
'service_style' => $data['service_style'],
|
'service_style' => $data['service_style'],
|
||||||
'receipt_footer' => $data['receipt_footer'] ?? null,
|
'receipt_footer' => $data['receipt_footer'] ?? null,
|
||||||
|
'receipt_header' => $data['receipt_header'] ?? null,
|
||||||
|
'printer_paper_mm' => (int) $data['printer_paper_mm'],
|
||||||
|
'printer_auto_print' => $request->boolean('printer_auto_print'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return back()->with('success', 'Settings saved.');
|
return back()->with('success', 'Settings saved.');
|
||||||
|
|||||||
@@ -18,8 +18,19 @@ class PosLocation extends Model
|
|||||||
'currency',
|
'currency',
|
||||||
'service_style',
|
'service_style',
|
||||||
'receipt_footer',
|
'receipt_footer',
|
||||||
|
'receipt_header',
|
||||||
|
'printer_paper_mm',
|
||||||
|
'printer_auto_print',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
protected function casts(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'printer_paper_mm' => 'integer',
|
||||||
|
'printer_auto_print' => 'boolean',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
public function isRestaurant(): bool
|
public function isRestaurant(): bool
|
||||||
{
|
{
|
||||||
return $this->service_style === self::STYLE_RESTAURANT;
|
return $this->service_style === self::STYLE_RESTAURANT;
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\Pos;
|
||||||
|
|
||||||
|
use App\Models\PosLocation;
|
||||||
|
use App\Models\PosProduct;
|
||||||
|
use App\Services\Crm\CrmClient;
|
||||||
|
|
||||||
|
class PosBarcodeLookupService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Resolve a scanned barcode/SKU to a register line item.
|
||||||
|
*
|
||||||
|
* @return array{id: int|string|null, name: string, price_minor: int, sku: string|null}|null
|
||||||
|
*/
|
||||||
|
public function lookup(string $ownerRef, PosLocation $location, string $code): ?array
|
||||||
|
{
|
||||||
|
$code = trim($code);
|
||||||
|
if ($code === '') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($location->isRestaurant()) {
|
||||||
|
return $this->lookupLocal($ownerRef, $code);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->lookupRetail($ownerRef, $code) ?? $this->lookupLocal($ownerRef, $code);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return array{id: int|string|null, name: string, price_minor: int, sku: string|null}|null */
|
||||||
|
private function lookupLocal(string $ownerRef, string $code): ?array
|
||||||
|
{
|
||||||
|
$product = PosProduct::owned($ownerRef)
|
||||||
|
->active()
|
||||||
|
->where('sku', $code)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (! $product) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'id' => $product->id,
|
||||||
|
'name' => $product->name,
|
||||||
|
'price_minor' => $product->price_minor,
|
||||||
|
'sku' => $product->sku,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return array{id: int|string|null, name: string, price_minor: int, sku: string|null}|null */
|
||||||
|
private function lookupRetail(string $ownerRef, string $code): ?array
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$rows = (array) (CrmClient::for($ownerRef)->products([
|
||||||
|
'search' => $code,
|
||||||
|
'type' => 'product',
|
||||||
|
'active' => 1,
|
||||||
|
'per_page' => 25,
|
||||||
|
])['data'] ?? []);
|
||||||
|
} catch (\Throwable) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
$sku = isset($row['sku']) ? (string) $row['sku'] : '';
|
||||||
|
if ($sku !== '' && strcasecmp($sku, $code) === 0) {
|
||||||
|
return [
|
||||||
|
'id' => $row['id'] ?? null,
|
||||||
|
'name' => (string) ($row['name'] ?? ''),
|
||||||
|
'price_minor' => (int) ($row['unit_price_minor'] ?? 0),
|
||||||
|
'sku' => $sku,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('pos_locations', function (Blueprint $table) {
|
||||||
|
$table->string('receipt_header', 500)->nullable()->after('receipt_footer');
|
||||||
|
$table->unsignedTinyInteger('printer_paper_mm')->default(80)->after('receipt_header');
|
||||||
|
$table->boolean('printer_auto_print')->default(false)->after('printer_paper_mm');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('pos_locations', function (Blueprint $table) {
|
||||||
|
$table->dropColumn(['receipt_header', 'printer_paper_mm', 'printer_auto_print']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,126 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<title>Receipt {{ $sale->reference }}</title>
|
||||||
|
@include('partials.favicon')
|
||||||
|
@php
|
||||||
|
$paper = in_array((int) ($location?->printer_paper_mm ?? 80), [58, 80], true)
|
||||||
|
? (int) $location->printer_paper_mm
|
||||||
|
: 80;
|
||||||
|
@endphp
|
||||||
|
<style>
|
||||||
|
* { box-sizing: border-box; }
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
padding: 16px;
|
||||||
|
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 1.4;
|
||||||
|
color: #111;
|
||||||
|
background: #fff;
|
||||||
|
}
|
||||||
|
.receipt {
|
||||||
|
width: {{ $paper }}mm;
|
||||||
|
max-width: 100%;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
.center { text-align: center; }
|
||||||
|
.muted { color: #555; }
|
||||||
|
.divider {
|
||||||
|
border: 0;
|
||||||
|
border-top: 1px dashed #999;
|
||||||
|
margin: 10px 0;
|
||||||
|
}
|
||||||
|
table { width: 100%; border-collapse: collapse; }
|
||||||
|
td { padding: 2px 0; vertical-align: top; }
|
||||||
|
.qty { width: 2.5rem; }
|
||||||
|
.amt { text-align: right; white-space: nowrap; }
|
||||||
|
.total-row td { font-weight: 700; padding-top: 6px; }
|
||||||
|
.actions {
|
||||||
|
margin: 20px auto 0;
|
||||||
|
max-width: {{ $paper }}mm;
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
button, a.btn {
|
||||||
|
font: inherit;
|
||||||
|
padding: 8px 14px;
|
||||||
|
border-radius: 8px;
|
||||||
|
border: 1px solid #cbd5e1;
|
||||||
|
background: #fff;
|
||||||
|
color: #0f172a;
|
||||||
|
text-decoration: none;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
button.primary, a.btn.primary {
|
||||||
|
background: #4f46e5;
|
||||||
|
border-color: #4f46e5;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
@media print {
|
||||||
|
body { padding: 0; }
|
||||||
|
.actions { display: none !important; }
|
||||||
|
@page { margin: 4mm; size: {{ $paper }}mm auto; }
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="receipt">
|
||||||
|
@if ($location?->receipt_header)
|
||||||
|
<p class="center">{{ $location->receipt_header }}</p>
|
||||||
|
@endif
|
||||||
|
<p class="center" style="font-size:14px;font-weight:700;">{{ $location?->name ?? 'Ladill POS' }}</p>
|
||||||
|
<p class="center muted">{{ $sale->reference }}</p>
|
||||||
|
<p class="center muted">{{ $sale->created_at->format('M j, Y g:i A') }}</p>
|
||||||
|
|
||||||
|
<hr class="divider">
|
||||||
|
|
||||||
|
<table>
|
||||||
|
@foreach ($sale->lines as $line)
|
||||||
|
<tr>
|
||||||
|
<td class="qty">{{ $line->quantity }}×</td>
|
||||||
|
<td>{{ $line->name }}</td>
|
||||||
|
<td class="amt">{{ pos_money($line->line_total_minor, $sale->currency) }}</td>
|
||||||
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<hr class="divider">
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr class="total-row">
|
||||||
|
<td colspan="2">Total</td>
|
||||||
|
<td class="amt">{{ pos_money($sale->total_minor, $sale->currency) }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2" class="muted">Payment</td>
|
||||||
|
<td class="amt muted">{{ ucfirst($sale->payment_method) }}</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
@if ($sale->customer_name)
|
||||||
|
<p class="center muted" style="margin-top:10px;">Customer: {{ $sale->customer_name }}</p>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
@if ($location?->receipt_footer)
|
||||||
|
<hr class="divider">
|
||||||
|
<p class="center muted">{{ $location->receipt_footer }}</p>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
<p class="center muted" style="margin-top:12px;">Thank you</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="actions">
|
||||||
|
<button type="button" class="primary" onclick="window.print()">Print receipt</button>
|
||||||
|
<a class="btn" href="{{ route('pos.sales.show', $sale) }}">Back to sale</a>
|
||||||
|
<a class="btn" href="{{ route('pos.register') }}">Register</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@if ($autoprint)
|
||||||
|
<script>window.addEventListener('load', () => window.print());</script>
|
||||||
|
@endif
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
<x-app-layout title="Register">
|
<x-app-layout title="Register">
|
||||||
<div class="mx-auto max-w-6xl" x-data="posRegister(@js([
|
<div class="mx-auto max-w-6xl" x-data="posRegister(@js([
|
||||||
'products' => $products,
|
'products' => $products,
|
||||||
|
'lookupUrl' => $barcodeLookupUrl,
|
||||||
|
'csrf' => csrf_token(),
|
||||||
]))">
|
]))">
|
||||||
<div class="flex flex-wrap items-center justify-between gap-3">
|
<div class="flex flex-wrap items-center justify-between gap-3">
|
||||||
<div>
|
<div>
|
||||||
@@ -32,11 +34,27 @@
|
|||||||
|
|
||||||
<div class="mt-6 grid gap-6 lg:grid-cols-5">
|
<div class="mt-6 grid gap-6 lg:grid-cols-5">
|
||||||
<div class="lg:col-span-3 space-y-4">
|
<div class="lg:col-span-3 space-y-4">
|
||||||
|
<div class="rounded-2xl border border-slate-200 bg-white p-4">
|
||||||
|
<label for="barcode-scan" class="text-sm font-medium text-slate-700">Barcode scanner</label>
|
||||||
|
<p class="mt-0.5 text-xs text-slate-400">Scan with a USB scanner or type a SKU/barcode and press Enter.</p>
|
||||||
|
<div class="mt-2 flex gap-2">
|
||||||
|
<input type="text" id="barcode-scan" x-ref="scanInput" x-model="scanCode"
|
||||||
|
@keydown.enter.prevent="submitScan()"
|
||||||
|
placeholder="Scan barcode…" autocomplete="off"
|
||||||
|
class="block w-full rounded-xl border-slate-300 text-sm shadow-sm focus:border-indigo-500 focus:ring-indigo-500">
|
||||||
|
<button type="button" @click="submitScan()"
|
||||||
|
class="shrink-0 rounded-xl bg-slate-900 px-4 py-2 text-sm font-medium text-white hover:bg-slate-800">Add</button>
|
||||||
|
</div>
|
||||||
|
<p x-show="scanError" x-cloak class="mt-2 text-xs text-red-600" x-text="scanError"></p>
|
||||||
|
<p x-show="scanOk" x-cloak class="mt-2 text-xs text-green-700" x-text="scanOk"></p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div x-show="tab === 'catalog'" class="grid gap-3 sm:grid-cols-2 xl:grid-cols-3">
|
<div x-show="tab === 'catalog'" class="grid gap-3 sm:grid-cols-2 xl:grid-cols-3">
|
||||||
<template x-for="product in products" :key="product.id">
|
<template x-for="product in products" :key="product.id">
|
||||||
<button type="button" @click="addProduct(product)"
|
<button type="button" @click="addProduct(product)"
|
||||||
class="rounded-2xl border border-slate-200 bg-white p-4 text-left hover:border-indigo-200 hover:shadow-sm">
|
class="rounded-2xl border border-slate-200 bg-white p-4 text-left hover:border-indigo-200 hover:shadow-sm">
|
||||||
<p class="font-medium text-slate-900" x-text="product.name"></p>
|
<p class="font-medium text-slate-900" x-text="product.name"></p>
|
||||||
|
<p class="mt-0.5 text-xs text-slate-400" x-show="product.sku" x-text="product.sku"></p>
|
||||||
<p class="mt-1 text-sm text-indigo-600" x-text="formatMoney(product.price_minor)"></p>
|
<p class="mt-1 text-sm text-indigo-600" x-text="formatMoney(product.price_minor)"></p>
|
||||||
</button>
|
</button>
|
||||||
</template>
|
</template>
|
||||||
@@ -108,9 +126,44 @@
|
|||||||
return {
|
return {
|
||||||
tab: 'catalog',
|
tab: 'catalog',
|
||||||
products: config.products || [],
|
products: config.products || [],
|
||||||
|
lookupUrl: config.lookupUrl || '',
|
||||||
|
csrf: config.csrf || '',
|
||||||
cart: [],
|
cart: [],
|
||||||
quickAmount: '',
|
quickAmount: '',
|
||||||
quickLabel: 'Sale',
|
quickLabel: 'Sale',
|
||||||
|
scanCode: '',
|
||||||
|
scanError: '',
|
||||||
|
scanOk: '',
|
||||||
|
scanBuffer: '',
|
||||||
|
scanTimer: null,
|
||||||
|
init() {
|
||||||
|
document.addEventListener('keydown', (e) => this.onGlobalKeydown(e));
|
||||||
|
},
|
||||||
|
onGlobalKeydown(e) {
|
||||||
|
if (this.shouldIgnoreScan(e)) return;
|
||||||
|
if (e.key === 'Enter') {
|
||||||
|
const code = (this.scanBuffer || '').trim();
|
||||||
|
this.scanBuffer = '';
|
||||||
|
if (code.length >= 3) {
|
||||||
|
e.preventDefault();
|
||||||
|
this.scanCode = code;
|
||||||
|
this.submitScan();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey) {
|
||||||
|
this.scanBuffer += e.key;
|
||||||
|
clearTimeout(this.scanTimer);
|
||||||
|
this.scanTimer = setTimeout(() => { this.scanBuffer = ''; }, 120);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
shouldIgnoreScan(e) {
|
||||||
|
const tag = (e.target?.tagName || '').toLowerCase();
|
||||||
|
if (tag === 'textarea') return true;
|
||||||
|
if (tag === 'input' && e.target?.id !== 'barcode-scan') return true;
|
||||||
|
if (e.target?.isContentEditable) return true;
|
||||||
|
return false;
|
||||||
|
},
|
||||||
addProduct(product) {
|
addProduct(product) {
|
||||||
const existing = this.cart.find(l => l.product_id === product.id);
|
const existing = this.cart.find(l => l.product_id === product.id);
|
||||||
if (existing) {
|
if (existing) {
|
||||||
@@ -123,6 +176,46 @@
|
|||||||
quantity: 1,
|
quantity: 1,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
this.scanError = '';
|
||||||
|
this.scanOk = product.name + ' added';
|
||||||
|
setTimeout(() => { this.scanOk = ''; }, 1500);
|
||||||
|
},
|
||||||
|
async submitScan() {
|
||||||
|
const code = (this.scanCode || '').trim();
|
||||||
|
this.scanError = '';
|
||||||
|
this.scanOk = '';
|
||||||
|
if (!code) return;
|
||||||
|
|
||||||
|
const local = this.products.find(p => p.sku && String(p.sku).toLowerCase() === code.toLowerCase());
|
||||||
|
if (local) {
|
||||||
|
this.addProduct(local);
|
||||||
|
this.scanCode = '';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.lookupUrl) {
|
||||||
|
this.scanError = 'No product found for that barcode.';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await fetch(this.lookupUrl + '?' + new URLSearchParams({ code }), {
|
||||||
|
headers: {
|
||||||
|
Accept: 'application/json',
|
||||||
|
'X-Requested-With': 'XMLHttpRequest',
|
||||||
|
'X-CSRF-TOKEN': this.csrf,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const data = await res.json().catch(() => ({}));
|
||||||
|
if (!res.ok) {
|
||||||
|
this.scanError = data.message || 'No product found for that barcode.';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.addProduct(data.product);
|
||||||
|
this.scanCode = '';
|
||||||
|
} catch (err) {
|
||||||
|
this.scanError = 'Barcode lookup failed. Try again.';
|
||||||
|
}
|
||||||
},
|
},
|
||||||
addQuick() {
|
addQuick() {
|
||||||
const amount = Math.round(parseFloat(this.quickAmount || 0) * 100);
|
const amount = Math.round(parseFloat(this.quickAmount || 0) * 100);
|
||||||
|
|||||||
@@ -48,6 +48,13 @@
|
|||||||
<p class="mt-6 border-t border-slate-100 pt-4 text-center text-xs text-slate-500">{{ $sale->location->receipt_footer }}</p>
|
<p class="mt-6 border-t border-slate-100 pt-4 text-center text-xs text-slate-500">{{ $sale->location->receipt_footer }}</p>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
|
<div class="mt-6 flex flex-wrap gap-2 border-t border-slate-100 pt-4">
|
||||||
|
<a href="{{ route('pos.sales.receipt', $sale) }}" target="_blank" rel="noopener"
|
||||||
|
class="inline-flex items-center justify-center rounded-xl bg-slate-900 px-4 py-2.5 text-sm font-semibold text-white hover:bg-slate-800">
|
||||||
|
Print receipt
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
@if ($sale->isPaid() && !empty($invoiceUrl))
|
@if ($sale->isPaid() && !empty($invoiceUrl))
|
||||||
<div class="mt-6 border-t border-slate-100 pt-4">
|
<div class="mt-6 border-t border-slate-100 pt-4">
|
||||||
<a href="{{ $invoiceUrl }}" class="btn-primary inline-flex w-full justify-center">Create invoice</a>
|
<a href="{{ $invoiceUrl }}" class="btn-primary inline-flex w-full justify-center">Create invoice</a>
|
||||||
|
|||||||
@@ -28,6 +28,34 @@
|
|||||||
<textarea id="receipt_footer" name="receipt_footer" rows="3"
|
<textarea id="receipt_footer" name="receipt_footer" rows="3"
|
||||||
class="mt-1.5 block w-full rounded-xl border-slate-300 text-sm shadow-sm focus:border-indigo-500 focus:ring-indigo-500">{{ old('receipt_footer', $location->receipt_footer) }}</textarea>
|
class="mt-1.5 block w-full rounded-xl border-slate-300 text-sm shadow-sm focus:border-indigo-500 focus:ring-indigo-500">{{ old('receipt_footer', $location->receipt_footer) }}</textarea>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="border-t border-slate-100 pt-4">
|
||||||
|
<p class="text-sm font-semibold text-slate-900">Receipt & printer</p>
|
||||||
|
<p class="mt-1 text-xs text-slate-400">Thermal receipt layout for browser print (58mm or 80mm paper). USB barcode scanners work as keyboard wedges on the register.</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label for="receipt_header" class="text-sm font-medium text-slate-700">Receipt header</label>
|
||||||
|
<input type="text" id="receipt_header" name="receipt_header" maxlength="500"
|
||||||
|
value="{{ old('receipt_header', $location->receipt_header) }}"
|
||||||
|
placeholder="Your business name or tagline"
|
||||||
|
class="mt-1.5 block w-full rounded-xl border-slate-300 text-sm shadow-sm focus:border-indigo-500 focus:ring-indigo-500">
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label for="printer_paper_mm" class="text-sm font-medium text-slate-700">Receipt paper width</label>
|
||||||
|
<select id="printer_paper_mm" name="printer_paper_mm"
|
||||||
|
class="mt-1.5 block w-full rounded-xl border-slate-300 text-sm shadow-sm focus:border-indigo-500 focus:ring-indigo-500">
|
||||||
|
<option value="80" @selected((int) old('printer_paper_mm', $location->printer_paper_mm ?? 80) === 80)>80 mm (standard thermal)</option>
|
||||||
|
<option value="58" @selected((int) old('printer_paper_mm', $location->printer_paper_mm ?? 80) === 58)>58 mm (compact thermal)</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<label class="flex items-start gap-3 rounded-xl border border-slate-200 bg-slate-50 px-4 py-3">
|
||||||
|
<input type="checkbox" name="printer_auto_print" value="1"
|
||||||
|
@checked(old('printer_auto_print', $location->printer_auto_print))
|
||||||
|
class="mt-0.5 rounded border-slate-300 text-indigo-600 focus:ring-indigo-500">
|
||||||
|
<span>
|
||||||
|
<span class="block text-sm font-medium text-slate-800">Auto-print after cash sales</span>
|
||||||
|
<span class="mt-0.5 block text-xs text-slate-500">Opens the receipt print dialog when you record a cash payment.</span>
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
<div class="flex justify-end">
|
<div class="flex justify-end">
|
||||||
<button type="submit" class="btn-primary">Save settings</button>
|
<button type="submit" class="btn-primary">Save settings</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -51,10 +51,12 @@ Route::middleware(['auth', 'platform.session'])->group(function () {
|
|||||||
Route::get('/dashboard', [DashboardController::class, 'index'])->name('pos.dashboard');
|
Route::get('/dashboard', [DashboardController::class, 'index'])->name('pos.dashboard');
|
||||||
|
|
||||||
Route::get('/register', [RegisterController::class, 'index'])->name('pos.register');
|
Route::get('/register', [RegisterController::class, 'index'])->name('pos.register');
|
||||||
|
Route::get('/register/lookup', [RegisterController::class, 'lookup'])->name('pos.register.lookup');
|
||||||
Route::post('/register/charge', [RegisterController::class, 'charge'])->name('pos.register.charge');
|
Route::post('/register/charge', [RegisterController::class, 'charge'])->name('pos.register.charge');
|
||||||
Route::post('/register/mode', [RegisterController::class, 'setMode'])->name('pos.mode.set');
|
Route::post('/register/mode', [RegisterController::class, 'setMode'])->name('pos.mode.set');
|
||||||
|
|
||||||
Route::get('/sales', [SaleController::class, 'index'])->name('pos.sales.index');
|
Route::get('/sales', [SaleController::class, 'index'])->name('pos.sales.index');
|
||||||
|
Route::get('/sales/{sale}/receipt', [SaleController::class, 'receipt'])->name('pos.sales.receipt');
|
||||||
Route::get('/sales/{sale}', [SaleController::class, 'show'])->name('pos.sales.show');
|
Route::get('/sales/{sale}', [SaleController::class, 'show'])->name('pos.sales.show');
|
||||||
Route::post('/sales/{sale}/cancel', [SaleController::class, 'cancel'])->name('pos.sales.cancel');
|
Route::post('/sales/{sale}/cancel', [SaleController::class, 'cancel'])->name('pos.sales.cancel');
|
||||||
Route::delete('/sales/{sale}', [SaleController::class, 'destroy'])->name('pos.sales.destroy');
|
Route::delete('/sales/{sale}', [SaleController::class, 'destroy'])->name('pos.sales.destroy');
|
||||||
|
|||||||
@@ -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']);
|
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]);
|
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
|
public function test_retail_register_reads_crm_products_and_snapshots_lines(): void
|
||||||
|
|||||||
Reference in New Issue
Block a user