23-01-2026

This commit is contained in:
Kevin Adametz 2026-01-23 17:35:23 +01:00
parent a939cd51ef
commit a8b395e20d
248 changed files with 29342 additions and 4805 deletions

View file

@ -6,10 +6,10 @@
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Casts\AsArrayObject;
use App\User;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Casts\AsArrayObject;
use Illuminate\Database\Eloquent\Model;
/**
* Class ShoppingCollectOrder
@ -33,7 +33,7 @@ use App\User;
* @property Carbon|null $updated_at
* @property ShoppingOrder|null $shopping_order
* @property User $user
* @package App\Models
*
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder query()
@ -54,8 +54,11 @@ use App\User;
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder whereTaxTotal($value)
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder whereUserId($value)
*
* @property array|null $net_split
*
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder whereNetSplit($value)
*
* @mixin \Eloquent
*/
class ShoppingCollectOrder extends Model
@ -72,7 +75,7 @@ class ShoppingCollectOrder extends Model
'price_total' => 'float',
'tax_total' => 'float',
'qty_total' => 'int',
'points' => 'int',
'points' => 'float',
'status' => 'int',
'tax_split' => 'array',
'net_split' => 'array',
@ -83,7 +86,7 @@ class ShoppingCollectOrder extends Model
protected $fillable = [
'user_id',
'shopping_order_id',
//'identifier',
// 'identifier',
'shipping',
'shipping_net',
'shipping_tax',
@ -96,14 +99,14 @@ class ShoppingCollectOrder extends Model
'net_split',
'orders',
'shop_items',
'status'
'status',
];
public static $statusTypes = [
0 => '',
1 => 'store / pre',
2 => 'order',
];
0 => '',
1 => 'store / pre',
2 => 'order',
];
public function shopping_order()
{
@ -115,13 +118,23 @@ class ShoppingCollectOrder extends Model
return $this->belongsTo(User::class);
}
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']) : '';
}
public function addTaxToSplit($tax_rate, $add_tax)
{
$tax_split = $this->tax_split;
$add_tax = round($add_tax, 2);
$existing_value = isset($tax_split[$tax_rate]) ? $this->parseNumericValue($tax_split[$tax_rate]) : 0;
$tax_split[$tax_rate] = round($existing_value + $add_tax, 2);
$this->tax_split = $tax_split;
}
@ -131,7 +144,7 @@ class ShoppingCollectOrder extends Model
$add_net = round($add_net, 2);
$existing_value = isset($net_split[$tax_rate]) ? $this->parseNumericValue($net_split[$tax_rate]) : 0;
$net_split[$tax_rate] = round($existing_value + $add_net, 2);
$this->net_split = $net_split;
}
@ -143,26 +156,26 @@ class ShoppingCollectOrder extends Model
{
// Bereits eine Zahl? Direkt zurückgeben
if (is_numeric($value)) {
return (float)$value;
return (float) $value;
}
// String zu String konvertieren für weitere Verarbeitung
$value = (string)$value;
$value = (string) $value;
// Entferne Leerzeichen
$value = trim($value);
// Prüfe verschiedene Formate
if (preg_match('/^-?\d{1,3}(\.\d{3})*,\d{2}$/', $value)) {
// Deutsches Format: 1.234,56 oder 1.234.567,89
return (float)str_replace(',', '.', str_replace('.', '', $value));
return (float) str_replace(',', '.', str_replace('.', '', $value));
} elseif (preg_match('/^-?\d{1,3}(,\d{3})*\.\d{2}$/', $value)) {
// Amerikanisches Format: 1,234.56 oder 1,234,567.89
return (float)str_replace(',', '', $value);
return (float) str_replace(',', '', $value);
} else {
// Einfaches Format: 19.50, 123.45, etc.
// Nur Kommas durch Punkte ersetzen
return (float)str_replace(',', '.', $value);
return (float) str_replace(',', '.', $value);
}
}
@ -170,25 +183,26 @@ class ShoppingCollectOrder extends Model
{
$numberFields = [
'user_price_net',
'user_price_total_net',
'user_price_total_net',
'user_tax',
'user_tax_total'
'user_tax_total',
];
$intFields = [
// Points werden jetzt auch als Dezimalzahlen behandelt
$decimalFields = [
'points_total',
'points'
'points',
];
foreach ($numberFields as $field) {
if (isset($shop_item->$field)) {
$shop_item->$field = number_format($shop_item->$field, 2);
$shop_item->$field = number_format($shop_item->$field, 2, '.', '');
}
}
foreach ($intFields as $field) {
foreach ($decimalFields as $field) {
if (isset($shop_item->$field)) {
$shop_item->$field = intval($shop_item->$field);
$shop_item->$field = round((float) $shop_item->$field, 2);
}
}
@ -203,6 +217,7 @@ class ShoppingCollectOrder extends Model
public function initShoppingOrder($order)
{
$order['shopping_order'] = ShoppingOrder::findOrFail($order['order_id']);
return $order;
}
}