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\PosProduct;
|
||||
use App\Models\PosSale;
|
||||
use App\Services\Pos\PosBarcodeLookupService;
|
||||
use App\Services\Pos\PosLocationService;
|
||||
use App\Services\Pos\PosSaleService;
|
||||
use App\Services\Crm\CrmClient;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
@@ -19,7 +21,11 @@ class RegisterController extends Controller
|
||||
{
|
||||
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
|
||||
{
|
||||
@@ -30,20 +36,43 @@ class RegisterController extends Controller
|
||||
'products' => $this->registerProducts($owner, $location),
|
||||
'location' => $location,
|
||||
'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
|
||||
* 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
|
||||
{
|
||||
if ($location->isRestaurant()) {
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -58,6 +87,7 @@ class RegisterController extends Controller
|
||||
'id' => $r['id'] ?? null,
|
||||
'name' => (string) ($r['name'] ?? ''),
|
||||
'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)
|
||||
->values()
|
||||
@@ -126,6 +156,12 @@ class RegisterController extends Controller
|
||||
if ($data['payment_method'] === 'cash') {
|
||||
$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()
|
||||
->route('pos.sales.show', $sale)
|
||||
->with('success', 'Cash sale recorded.');
|
||||
|
||||
@@ -44,6 +44,18 @@ class SaleController extends Controller
|
||||
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
|
||||
{
|
||||
$this->authorizeOwner($request, $sale);
|
||||
|
||||
@@ -42,6 +42,9 @@ class SettingsController extends Controller
|
||||
'currency' => ['required', 'string', 'size:3'],
|
||||
'service_style' => ['required', 'in:retail,restaurant'],
|
||||
'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();
|
||||
@@ -56,6 +59,9 @@ class SettingsController extends Controller
|
||||
'currency' => strtoupper($data['currency']),
|
||||
'service_style' => $data['service_style'],
|
||||
'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.');
|
||||
|
||||
Reference in New Issue
Block a user