101 lines
2.5 KiB
PHP
101 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Services\Util;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
/**
|
|
* Class UserAboOneTimeItem
|
|
*
|
|
* Einmalig dem Abo hinzugefügte Produkte aus dem normalen Bestellsortiment.
|
|
* Bewusst getrennt von {@see UserAboItem}, damit diese Positionen nie in die
|
|
* dauerhafte Abo-Logik geraten und nach erfolgreicher Ausführung gelöscht werden.
|
|
*
|
|
* @property int $id
|
|
* @property int $user_abo_id
|
|
* @property int $product_id
|
|
* @property int|null $comp
|
|
* @property int $qty
|
|
* @property int|null $confirmed_qty
|
|
* @property \Illuminate\Support\Carbon|null $confirmed_at
|
|
* @property float|null $price
|
|
* @property float|null $price_net
|
|
* @property float|null $tax_rate
|
|
* @property float|null $tax
|
|
* @property float|null $price_vk_net
|
|
* @property float|null $discount
|
|
* @property int|null $points
|
|
* @property int $status
|
|
* @property-read Product $product
|
|
* @property-read UserAbo $user_abo
|
|
*/
|
|
class UserAboOneTimeItem extends Model
|
|
{
|
|
use HasFactory;
|
|
use SoftDeletes;
|
|
|
|
protected $table = 'user_abo_one_time_items';
|
|
|
|
protected $casts = [
|
|
'user_abo_id' => 'int',
|
|
'product_id' => 'int',
|
|
'comp' => 'int',
|
|
'qty' => 'int',
|
|
'confirmed_qty' => 'int',
|
|
'confirmed_at' => 'datetime',
|
|
'price' => 'float',
|
|
'price_net' => 'float',
|
|
'tax_rate' => 'float',
|
|
'tax' => 'float',
|
|
'price_vk_net' => 'float',
|
|
'discount' => 'float',
|
|
'points' => 'int',
|
|
'status' => 'int',
|
|
];
|
|
|
|
protected $fillable = [
|
|
'user_abo_id',
|
|
'product_id',
|
|
'comp',
|
|
'qty',
|
|
'confirmed_qty',
|
|
'confirmed_at',
|
|
'price',
|
|
'price_net',
|
|
'tax_rate',
|
|
'tax',
|
|
'price_vk_net',
|
|
'discount',
|
|
'points',
|
|
'status',
|
|
];
|
|
|
|
public function product(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Product::class);
|
|
}
|
|
|
|
public function user_abo(): BelongsTo
|
|
{
|
|
return $this->belongsTo(UserAbo::class);
|
|
}
|
|
|
|
public function isConfirmed(): bool
|
|
{
|
|
return $this->confirmed_at !== null && $this->confirmed_qty === $this->qty;
|
|
}
|
|
|
|
public function getFormattedPrice(): string
|
|
{
|
|
return Util::formatNumber($this->price);
|
|
}
|
|
|
|
public function getFormattedTotalPrice(): string
|
|
{
|
|
return Util::formatNumber($this->price * $this->qty);
|
|
}
|
|
}
|