Add receipt logo upload and redesign thermal receipt header.
Deploy Ladill POS / deploy (push) Successful in 1m32s
Deploy Ladill POS / deploy (push) Successful in 1m32s
Per-location logo in settings with remove/replace support; receipt template reserves space at the top when a logo is set. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -11,6 +11,7 @@ use App\Services\Import\MerchantCatalogImportService;
|
||||
use App\Services\Pos\PosLocationService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\View\View;
|
||||
use RuntimeException;
|
||||
|
||||
@@ -43,6 +44,8 @@ class SettingsController extends Controller
|
||||
'service_style' => ['required', 'in:retail,restaurant'],
|
||||
'receipt_footer' => ['nullable', 'string', 'max:1000'],
|
||||
'receipt_header' => ['nullable', 'string', 'max:500'],
|
||||
'receipt_logo' => ['nullable', 'image', 'mimes:jpeg,jpg,png,gif,webp', 'max:2048'],
|
||||
'remove_receipt_logo' => ['sometimes', 'boolean'],
|
||||
'printer_paper_mm' => ['required', 'in:58,80'],
|
||||
'printer_auto_print' => ['sometimes', 'boolean'],
|
||||
]);
|
||||
@@ -54,6 +57,22 @@ class SettingsController extends Controller
|
||||
}
|
||||
|
||||
$location = $this->locations->ensureDefault($this->ownerRef($request));
|
||||
|
||||
if ($request->boolean('remove_receipt_logo') && $location->receipt_logo_path) {
|
||||
Storage::disk('public')->delete($location->receipt_logo_path);
|
||||
$location->receipt_logo_path = null;
|
||||
}
|
||||
|
||||
if ($request->hasFile('receipt_logo')) {
|
||||
if ($location->receipt_logo_path) {
|
||||
Storage::disk('public')->delete($location->receipt_logo_path);
|
||||
}
|
||||
$location->receipt_logo_path = $request->file('receipt_logo')->store(
|
||||
'pos/receipt-logos/'.$this->ownerRef($request),
|
||||
'public'
|
||||
);
|
||||
}
|
||||
|
||||
$location->update([
|
||||
'name' => $data['name'],
|
||||
'currency' => strtoupper($data['currency']),
|
||||
@@ -62,6 +81,7 @@ class SettingsController extends Controller
|
||||
'receipt_header' => $data['receipt_header'] ?? null,
|
||||
'printer_paper_mm' => (int) $data['printer_paper_mm'],
|
||||
'printer_auto_print' => $request->boolean('printer_auto_print'),
|
||||
'receipt_logo_path' => $location->receipt_logo_path,
|
||||
]);
|
||||
|
||||
return back()->with('success', 'Settings saved.');
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class PosLocation extends Model
|
||||
{
|
||||
@@ -19,6 +20,7 @@ class PosLocation extends Model
|
||||
'service_style',
|
||||
'receipt_footer',
|
||||
'receipt_header',
|
||||
'receipt_logo_path',
|
||||
'printer_paper_mm',
|
||||
'printer_auto_print',
|
||||
];
|
||||
@@ -36,6 +38,15 @@ class PosLocation extends Model
|
||||
return $this->service_style === self::STYLE_RESTAURANT;
|
||||
}
|
||||
|
||||
public function receiptLogoUrl(): ?string
|
||||
{
|
||||
if (! $this->receipt_logo_path) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Storage::disk('public')->url($this->receipt_logo_path);
|
||||
}
|
||||
|
||||
public function products(): HasMany
|
||||
{
|
||||
return $this->hasMany(PosProduct::class, 'location_id');
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<?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_logo_path', 500)->nullable()->after('receipt_header');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('pos_locations', function (Blueprint $table) {
|
||||
$table->dropColumn('receipt_logo_path');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -9,6 +9,8 @@
|
||||
$paper = in_array((int) ($location?->printer_paper_mm ?? 80), [58, 80], true)
|
||||
? (int) $location->printer_paper_mm
|
||||
: 80;
|
||||
$logoUrl = $location?->receiptLogoUrl();
|
||||
$hasLogo = filled($logoUrl);
|
||||
@endphp
|
||||
<style>
|
||||
* { box-sizing: border-box; }
|
||||
@@ -28,6 +30,34 @@
|
||||
}
|
||||
.center { text-align: center; }
|
||||
.muted { color: #555; }
|
||||
.brand {
|
||||
padding-bottom: {{ $hasLogo ? '8px' : '0' }};
|
||||
margin-bottom: {{ $hasLogo ? '10px' : '0' }};
|
||||
}
|
||||
.brand-logo {
|
||||
display: block;
|
||||
width: auto;
|
||||
max-width: {{ $paper === 58 ? '42mm' : '52mm' }};
|
||||
max-height: {{ $paper === 58 ? '14mm' : '18mm' }};
|
||||
margin: 0 auto 8px;
|
||||
object-fit: contain;
|
||||
}
|
||||
.brand-title {
|
||||
margin: 0;
|
||||
font-size: {{ $hasLogo ? '13px' : '14px' }};
|
||||
font-weight: 700;
|
||||
line-height: 1.3;
|
||||
}
|
||||
.brand-subtitle {
|
||||
margin: 4px 0 0;
|
||||
font-size: 11px;
|
||||
line-height: 1.35;
|
||||
}
|
||||
.meta {
|
||||
margin: 0;
|
||||
font-size: 11px;
|
||||
line-height: 1.35;
|
||||
}
|
||||
.divider {
|
||||
border: 0;
|
||||
border-top: 1px dashed #999;
|
||||
@@ -69,12 +99,24 @@
|
||||
</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>
|
||||
<header class="brand center">
|
||||
@if ($hasLogo)
|
||||
<img src="{{ $logoUrl }}?v={{ $location->updated_at?->timestamp }}" alt="" class="brand-logo">
|
||||
@endif
|
||||
|
||||
@if ($location?->receipt_header)
|
||||
<p class="brand-title">{{ $location->receipt_header }}</p>
|
||||
@elseif (! $hasLogo)
|
||||
<p class="brand-title">{{ $location?->name ?? 'Ladill POS' }}</p>
|
||||
@endif
|
||||
|
||||
@if ($hasLogo || $location?->receipt_header)
|
||||
<p class="brand-subtitle muted">{{ $location?->name ?? 'Ladill POS' }}</p>
|
||||
@endif
|
||||
</header>
|
||||
|
||||
<p class="center meta muted">{{ $sale->reference }}</p>
|
||||
<p class="center meta muted">{{ $sale->created_at->format('M j, Y g:i A') }}</p>
|
||||
|
||||
<hr class="divider">
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<x-app-layout title="Settings">
|
||||
<x-settings.page description="Register location, receipt footer, and catalog imports.">
|
||||
<x-settings.card title="Location" description="Register name, currency, service style, and receipt footer.">
|
||||
<form method="POST" action="{{ route('pos.settings.update') }}" class="space-y-4">
|
||||
<form method="POST" action="{{ route('pos.settings.update') }}" enctype="multipart/form-data" class="space-y-4">
|
||||
@csrf
|
||||
@method('PUT')
|
||||
<div>
|
||||
@@ -39,6 +39,29 @@
|
||||
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 class="text-sm font-medium text-slate-700">Receipt logo</label>
|
||||
<p class="mt-0.5 text-xs text-slate-400">Optional. Shown at the top of printed receipts. A square PNG or JPG works best on thermal paper.</p>
|
||||
<div class="mt-3 flex items-center gap-4">
|
||||
@if ($location->receipt_logo_path)
|
||||
<img src="{{ $location->receiptLogoUrl() }}?v={{ $location->updated_at?->timestamp }}"
|
||||
alt="Current receipt logo"
|
||||
class="h-16 w-16 rounded-xl border border-slate-200 bg-white object-contain p-1">
|
||||
@else
|
||||
<div class="flex h-16 w-16 items-center justify-center rounded-xl border border-dashed border-slate-300 text-[10px] text-slate-400">No logo</div>
|
||||
@endif
|
||||
<div class="min-w-0 flex-1 space-y-2">
|
||||
<input type="file" name="receipt_logo" accept="image/png,image/jpeg,image/gif,image/webp"
|
||||
class="block w-full text-sm text-slate-600 file:mr-3 file:rounded-lg file:border-0 file:bg-indigo-50 file:px-3 file:py-1.5 file:text-sm file:font-medium file:text-indigo-700 hover:file:bg-indigo-100">
|
||||
@if ($location->receipt_logo_path)
|
||||
<label class="inline-flex items-center gap-2 text-xs text-slate-500">
|
||||
<input type="checkbox" name="remove_receipt_logo" value="1" class="rounded border-slate-300 text-indigo-600">
|
||||
Remove current logo
|
||||
</label>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
</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"
|
||||
|
||||
@@ -8,7 +8,9 @@ use App\Models\PosProduct;
|
||||
use App\Models\PosSale;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PosHardwareTest extends TestCase
|
||||
@@ -135,4 +137,70 @@ class PosHardwareTest extends TestCase
|
||||
$sale = PosSale::where('owner_ref', $user->public_id)->firstOrFail();
|
||||
$response->assertRedirect(route('pos.sales.receipt', ['sale' => $sale, 'autoprint' => 1]));
|
||||
}
|
||||
|
||||
public function test_settings_accepts_receipt_logo_upload(): void
|
||||
{
|
||||
Storage::fake('public');
|
||||
|
||||
$user = $this->user();
|
||||
PosLocation::create([
|
||||
'owner_ref' => $user->public_id,
|
||||
'name' => 'Main register',
|
||||
'currency' => 'GHS',
|
||||
]);
|
||||
|
||||
$this->actingAs($user)
|
||||
->put(route('pos.settings.update'), [
|
||||
'name' => 'Main register',
|
||||
'currency' => 'GHS',
|
||||
'service_style' => 'retail',
|
||||
'printer_paper_mm' => 80,
|
||||
'receipt_logo' => UploadedFile::fake()->image('logo.png', 120, 120),
|
||||
])
|
||||
->assertRedirect();
|
||||
|
||||
$location = PosLocation::where('owner_ref', $user->public_id)->firstOrFail();
|
||||
$this->assertNotNull($location->receipt_logo_path);
|
||||
Storage::disk('public')->assertExists($location->receipt_logo_path);
|
||||
}
|
||||
|
||||
public function test_receipt_page_shows_uploaded_logo(): void
|
||||
{
|
||||
Storage::fake('public');
|
||||
|
||||
$user = $this->user();
|
||||
$logoPath = 'pos/receipt-logos/'.$user->public_id.'/logo.png';
|
||||
Storage::disk('public')->put($logoPath, UploadedFile::fake()->image('logo.png', 120, 120)->getContent());
|
||||
|
||||
$location = PosLocation::create([
|
||||
'owner_ref' => $user->public_id,
|
||||
'name' => 'Main register',
|
||||
'currency' => 'GHS',
|
||||
'receipt_header' => 'Acme Shop',
|
||||
'receipt_logo_path' => $logoPath,
|
||||
'printer_paper_mm' => 80,
|
||||
]);
|
||||
$sale = PosSale::create([
|
||||
'owner_ref' => $user->public_id,
|
||||
'location_id' => $location->id,
|
||||
'reference' => 'POS-LOGO',
|
||||
'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('brand-logo', false)
|
||||
->assertSee('Acme Shop')
|
||||
->assertSee('POS-LOGO');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user