Files
ladill-pos/app/Models/PosLocation.php
T
isaacclad 600aedb59d
Deploy Ladill POS / deploy (push) Successful in 31s
Email digital receipts, add promo settings, and apply tips at charge.
Send real receipt emails from the customer display and sale page, store
branch promo content for the idle screen, and fold selected tips into totals.
2026-07-15 16:10:20 +00:00

94 lines
2.3 KiB
PHP

<?php
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
{
public const STYLE_RETAIL = 'retail';
public const STYLE_RESTAURANT = 'restaurant';
protected $fillable = [
'owner_ref',
'name',
'currency',
'is_default',
'service_style',
'receipt_footer',
'receipt_header',
'receipt_logo_path',
'printer_paper_mm',
'printer_auto_print',
'customer_promo_headline',
'customer_promo_body',
'customer_promo_image_path',
];
protected function casts(): array
{
return [
'is_default' => 'boolean',
'printer_paper_mm' => 'integer',
'printer_auto_print' => 'boolean',
];
}
public function isRestaurant(): bool
{
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 customerPromoImageUrl(): ?string
{
if ($this->customer_promo_image_path) {
return Storage::disk('public')->url($this->customer_promo_image_path);
}
return $this->receiptLogoUrl();
}
/** Default idle-screen promo for the customer-facing display. */
public function customerPromo(): array
{
return [
'headline' => $this->customer_promo_headline ?: $this->name,
'body' => $this->customer_promo_body ?: 'Thank you for shopping with us.',
'image_url' => $this->customerPromoImageUrl(),
];
}
public function products(): HasMany
{
return $this->hasMany(PosProduct::class, 'location_id');
}
public function tables(): HasMany
{
return $this->hasMany(PosTable::class, 'location_id');
}
public function sales(): HasMany
{
return $this->hasMany(PosSale::class, 'location_id');
}
public function scopeOwned(Builder $query, string $ownerRef): Builder
{
return $query->where('owner_ref', $ownerRef);
}
}