mivita/app/Models/ShoppingOrderItem.php
Kevin 2269ce031f Abo Einmalprodukte und Bestätigung abschließen
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-05 15:28:08 +00:00

193 lines
6.5 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* App\Models\ShoppingOrderItem
*
* @property int $id
* @property int $shopping_order_id
* @property string|null $row_id
* @property int $product_id
* @property int|null $qty
* @property float|null $price
* @property string|null $slug
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \App\Models\Product $product
* @property-read \App\Models\ShoppingOrder $shopping_order
*
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingOrderItem newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingOrderItem newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingOrderItem query()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingOrderItem whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingOrderItem whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingOrderItem wherePrice($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingOrderItem whereProductId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingOrderItem whereQty($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingOrderItem whereRowId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingOrderItem whereShoppingOrderId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingOrderItem whereSlug($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingOrderItem whereUpdatedAt($value)
*
* @property float|null $tax_rate
* @property \Illuminate\Support\Carbon|null $deleted_at
* @property string|null $user_deleted_at
*
* @method static \Illuminate\Database\Query\Builder|\App\Models\ShoppingOrderItem onlyTrashed()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingOrderItem whereDeletedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingOrderItem whereTaxRate($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingOrderItem whereUserDeletedAt($value)
* @method static \Illuminate\Database\Query\Builder|\App\Models\ShoppingOrderItem withTrashed()
* @method static \Illuminate\Database\Query\Builder|\App\Models\ShoppingOrderItem withoutTrashed()
*
* @property int|null $comp
* @property float|null $price_net
*
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingOrderItem whereComp($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingOrderItem wherePriceNet($value)
*
* @property int|null $homeparty_id
* @property-read \App\Models\Homeparty|null $homeparty
*
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrderItem whereHomepartyId($value)
*
* @property string|null $tax
* @property string|null $price_vk_net
* @property string|null $discount
* @property int|null $points
*
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrderItem whereDiscount($value)
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrderItem wherePoints($value)
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrderItem wherePriceVkNet($value)
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrderItem whereTax($value)
*
* @property int|null $shopping_collect_order_id
*
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrderItem whereShoppingCollectOrderId($value)
*
* @mixin \Eloquent
*/
class ShoppingOrderItem extends Model
{
protected $table = 'shopping_order_items';
use SoftDeletes;
protected $dates = ['deleted_at'];
protected $fillable = [
'shopping_order_id',
'row_id',
'product_id',
'homeparty_id',
'shopping_collect_order_id',
'comp',
'is_abo_addon',
'qty',
'price',
'price_net',
'tax_rate',
'tax',
'price_vk_net',
'discount',
'points',
'slug',
];
protected $casts = [
'qty' => 'int',
'price' => 'float',
'price_net' => 'float',
'tax_rate' => 'float',
'tax' => 'float',
'price_vk_net' => 'float',
'discount' => 'float',
'points' => 'float',
'is_abo_addon' => 'bool',
];
public function shopping_order()
{
return $this->belongsTo('App\Models\ShoppingOrder', 'shopping_order_id');
}
/**
* Reine Abo-Positionen (keine einmalig hinzugefügten Artikel).
*/
public function scopeAboItems($query)
{
return $query->where('is_abo_addon', false);
}
/**
* Einmalig zum Abo-Versand hinzugefügte Artikel aus dem normalen Bestellsortiment.
*/
public function scopeAddonItems($query)
{
return $query->where('is_abo_addon', true);
}
public function product()
{
return $this->belongsTo('App\Models\Product', 'product_id');
}
public function homeparty()
{
return $this->belongsTo('App\Models\Homeparty', 'homeparty_id');
}
public function getFormattedPrice()
{
return formatNumber($this->attributes['price']);
}
public function getFormattedTotalPrice()
{
return formatNumber($this->attributes['price'] * $this->attributes['qty']);
}
public function getFormattedPriceNet()
{
return formatNumber($this->attributes['price_net']);
}
public function getFormattedPriceVkNet()
{
return formatNumber($this->attributes['price_vk_net']);
}
public function getFormattedTaxRate()
{
return cleanNumberFormat($this->attributes['tax_rate']);
}
public function getTaxRate()
{
return formatNumber($this->attributes['tax']);
}
public function getFormattedDiscount()
{
return cleanNumberFormat($this->attributes['discount']);
}
public function getFormattedTotalPriceNet()
{
return formatNumber($this->attributes['price_net'] * $this->attributes['qty']);
}
public function setPointsAttribute($value)
{
$this->attributes['points'] = $value !== null ? \Util::reFormatNumber($value) : null;
}
public function getFormattedPoints()
{
return isset($this->attributes['points']) ? formatNumber($this->attributes['points']) : '';
}
}