Files
ladill-pos/app/Http/Controllers/Pos/SettingsController.php
T
isaaccladandCursor 9a2d196d84
Deploy Ladill POS / deploy (push) Successful in 1m42s
Add barcode scanner, thermal receipt printing, and printer settings.
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>
2026-07-08 05:40:14 +00:00

129 lines
4.6 KiB
PHP

<?php
namespace App\Http\Controllers\Pos;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Pos\Concerns\ScopesToAccount;
use App\Models\PosLocation;
use App\Models\PosTable;
use App\Services\Import\CrmProductImportService;
use App\Services\Import\MerchantCatalogImportService;
use App\Services\Pos\PosLocationService;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
use RuntimeException;
class SettingsController extends Controller
{
use ScopesToAccount;
public function __construct(
private PosLocationService $locations,
private \App\Services\Pos\SubscriptionService $subscriptions,
) {}
public function index(Request $request): View
{
$owner = $this->ownerRef($request);
$location = $this->locations->ensureDefault($owner);
return view('pos.settings', [
'location' => $location,
'merchantImportEnabled' => (bool) config('pos.merchant_import_enabled', true),
'tables' => PosTable::owned($owner)->orderBy('area')->orderBy('position')->orderBy('label')->get(),
]);
}
public function update(Request $request): RedirectResponse
{
$data = $request->validate([
'name' => ['required', 'string', 'max:120'],
'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();
if ($data['service_style'] === 'restaurant' && ! $this->subscriptions->canUseRestaurantMode($user)) {
return redirect()->route('pos.pro.index')
->with('upsell', 'Restaurant mode is part of Ladill POS Pro.');
}
$location = $this->locations->ensureDefault($this->ownerRef($request));
$location->update([
'name' => $data['name'],
'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.');
}
public function storeTable(Request $request): RedirectResponse
{
$data = $request->validate([
'area' => ['nullable', 'string', 'max:60'],
'label' => ['required', 'string', 'max:60'],
'seats' => ['nullable', 'integer', 'min:1', 'max:99'],
]);
$owner = $this->ownerRef($request);
$location = $this->locations->ensureDefault($owner);
PosTable::create([
'owner_ref' => $owner,
'location_id' => $location->id,
'area' => $data['area'] ?? null,
'label' => $data['label'],
'seats' => $data['seats'] ?? 2,
'status' => PosTable::STATUS_FREE,
'position' => (int) PosTable::owned($owner)->max('position') + 1,
]);
return back()->with('success', 'Table added.');
}
public function destroyTable(Request $request, PosTable $table): RedirectResponse
{
$this->authorizeOwner($request, $table);
if (! $table->isFree()) {
return back()->with('error', 'Settle the open ticket before removing this table.');
}
$table->delete();
return back()->with('success', 'Table removed.');
}
public function importCrm(Request $request, CrmProductImportService $import): RedirectResponse
{
try {
$result = $import->import($this->ownerRef($request));
return back()->with('success', "Imported {$result['imported']} product(s), updated {$result['updated']}.");
} catch (RuntimeException $e) {
return back()->with('error', $e->getMessage());
}
}
public function importMerchant(Request $request, MerchantCatalogImportService $import): RedirectResponse
{
try {
$result = $import->import($this->ownerRef($request));
return back()->with('success', "Imported {$result['imported']} item(s) from {$result['storefronts']} storefront(s), updated {$result['updated']}.");
} catch (RuntimeException $e) {
return back()->with('error', $e->getMessage());
}
}
}