lan_kiosk/app/Models/Customer.php
Anna-Sara Sélea df9f1cf17e Swish feature
2026-08-22 16:13:42 +02:00

63 lines
1.3 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use App\Models\Puchase;
use App\Models\Deposit;
class Customer extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'lan_id',
'name',
'guardian_name',
'amount_left',
'deposit',
'give_leftover',
'comment',
'customer_group_id',
'is_in_group'
];
/**
* Make this customer a member of a group and hand over the balance they have
* left to spend. Returns the amount that was moved, for the caller to add to
* the group's own row.
*
* Membership and money move together — a member keeps no balance of their own.
*/
public function joinGroup(int $groupId): int
{
$moved = (int) $this->amount_left;
$this->customer_group_id = $groupId;
$this->is_in_group = 1;
$this->deposit = 0;
$this->amount_left = 0;
$this->save();
return $moved;
}
/**
* Get the purchases for the customer.
*/
public function purchases()
{
return $this->hasMany(Purchase::class);
}
/**
* Get the deposit for the customer.
*/
public function deposits()
{
return $this->hasMany(Deposit::class);
}
}