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.');
|
||||
|
||||
Reference in New Issue
Block a user