Abo Einmalprodukte und Bestätigung abschließen

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Kevin 2026-06-05 15:28:08 +00:00
parent 2bdc9ada3c
commit 2269ce031f
57 changed files with 3647 additions and 371 deletions

View file

@ -19,6 +19,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
* @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()
@ -31,32 +32,43 @@ use Illuminate\Database\Eloquent\SoftDeletes;
* @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
@ -64,6 +76,7 @@ class ShoppingOrderItem extends Model
protected $table = 'shopping_order_items';
use SoftDeletes;
protected $dates = ['deleted_at'];
protected $fillable = [
@ -73,6 +86,7 @@ class ShoppingOrderItem extends Model
'homeparty_id',
'shopping_collect_order_id',
'comp',
'is_abo_addon',
'qty',
'price',
'price_net',
@ -83,6 +97,7 @@ class ShoppingOrderItem extends Model
'points',
'slug',
];
protected $casts = [
'qty' => 'int',
'price' => 'float',
@ -92,21 +107,38 @@ class ShoppingOrderItem extends Model
'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');
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');
return $this->belongsTo('App\Models\Product', 'product_id');
}
public function homeparty()
{
return $this->belongsTo('App\Models\Homeparty','homeparty_id');
return $this->belongsTo('App\Models\Homeparty', 'homeparty_id');
}
public function getFormattedPrice()
@ -139,7 +171,6 @@ class ShoppingOrderItem extends Model
return formatNumber($this->attributes['tax']);
}
public function getFormattedDiscount()
{
return cleanNumberFormat($this->attributes['discount']);
@ -147,7 +178,7 @@ class ShoppingOrderItem extends Model
public function getFormattedTotalPriceNet()
{
return formatNumber($this->attributes['price_net'] * $this->attributes['qty']);
return formatNumber($this->attributes['price_net'] * $this->attributes['qty']);
}
public function setPointsAttribute($value)
@ -157,6 +188,6 @@ class ShoppingOrderItem extends Model
public function getFormattedPoints()
{
return isset($this->attributes['points']) ? formatNumber($this->attributes['points']) : "";
return isset($this->attributes['points']) ? formatNumber($this->attributes['points']) : '';
}
}
}

View file

@ -45,6 +45,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
* @property-read User|null $member
* @property-read \App\Models\ShoppingUser $shopping_user
* @property-read Collection<int, \App\Models\UserAboItem> $user_abo_items
* @property-read Collection<int, \App\Models\UserAboOneTimeItem> $one_time_items
* @property-read int|null $user_abo_items_count
* @property-read int|null $user_abo_orders_count
*
@ -173,6 +174,11 @@ class UserAbo extends Model
return $this->hasMany(UserAboItem::class);
}
public function one_time_items()
{
return $this->hasMany(UserAboOneTimeItem::class);
}
public function user_abo_item_histories()
{
return $this->hasMany(UserAboItemHistory::class);

View file

@ -24,7 +24,7 @@ use Yard;
* @property Carbon|null $updated_at
* @property Product $product
* @property UserAbo $user_abo
* @package App\Models
*
* @method static \Illuminate\Database\Eloquent\Builder|UserAboItem newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|UserAboItem newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|UserAboItem query()
@ -36,55 +36,57 @@ use Yard;
* @method static \Illuminate\Database\Eloquent\Builder|UserAboItem whereStatus($value)
* @method static \Illuminate\Database\Eloquent\Builder|UserAboItem whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|UserAboItem whereUserAboId($value)
*
* @mixin \Eloquent
*/
class UserAboItem extends Model
{
protected $table = 'user_abo_items';
protected $table = 'user_abo_items';
protected $casts = [
'user_abo_id' => 'int',
'product_id' => 'int',
'comp' => 'int',
'qty' => 'int',
'status' => 'int'
];
protected $casts = [
'user_abo_id' => 'int',
'product_id' => 'int',
'comp' => 'int',
'qty' => 'int',
'status' => 'int',
];
protected $fillable = [
'user_abo_id',
'product_id',
'comp',
'qty',
'status'
];
protected $fillable = [
'user_abo_id',
'product_id',
'comp',
'qty',
'status',
];
public function product()
{
return $this->belongsTo(Product::class);
}
public function product()
{
return $this->belongsTo(Product::class);
}
public function user_abo()
{
return $this->belongsTo(UserAbo::class);
}
public function user_abo()
{
return $this->belongsTo(UserAbo::class);
}
public function getPrice()
{
$ufactor = $this->user_abo->is_for === 'me' ? true : false;
$tax_free = $ufactor ? true : Yard::instance('shopping')->getUserTaxFree();
$userCountry = Yard::instance('shopping')->getUserCountry();
return $this->product->getPriceWith($tax_free, $ufactor, $userCountry);
}
public function getPrice()
{
$ufactor = $this->user_abo->is_for === 'me' ? true : false;
$tax_free = $ufactor ? true : Yard::instance(\App\Services\AboOrderCart::INSTANCE)->getUserTaxFree();
$userCountry = Yard::instance(\App\Services\AboOrderCart::INSTANCE)->getUserCountry();
return $this->product->getPriceWith($tax_free, $ufactor, $userCountry);
}
public function getFormattedPrice(){
/** der Preis wird für den User berechnet */
return Util::formatNumber($this->getPrice());
}
public function getFormattedPrice()
{
/** der Preis wird für den User berechnet */
return Util::formatNumber($this->getPrice());
}
public function getFormattedTotalPrice(){
/** der Preis wird für den User berechnet */
return Util::formatNumber($this->getPrice() * $this->qty);
}
public function getFormattedTotalPrice()
{
/** der Preis wird für den User berechnet */
return Util::formatNumber($this->getPrice() * $this->qty);
}
}

View file

@ -0,0 +1,101 @@
<?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);
}
}