commit 08-2025

This commit is contained in:
Kevin Adametz 2025-08-12 18:01:59 +02:00
parent 9ae662f63e
commit 480fdc65ed
404 changed files with 65310 additions and 2600431 deletions

74
app/Models/Customer.php Normal file
View file

@ -0,0 +1,74 @@
<?php
namespace App\Models;
use App\User;
use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable; // Wichtig!
/**
*
*
* @property int $id
* @property string|null $name
* @property string $email
* @property int|null $shopping_user_id
* @property int|null $member_id
* @property int|null $number
* @property string|null $language
* @property string|null $mode
* @property string|null $remember_token
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read User|null $member
* @property-read \Illuminate\Notifications\DatabaseNotificationCollection<int, \Illuminate\Notifications\DatabaseNotification> $notifications
* @property-read int|null $notifications_count
* @property-read \App\Models\ShoppingUser|null $shoppingUser
* @method static \Illuminate\Database\Eloquent\Builder<static>|Customer newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder<static>|Customer newQuery()
* @method static \Illuminate\Database\Eloquent\Builder<static>|Customer query()
* @method static \Illuminate\Database\Eloquent\Builder<static>|Customer whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Customer whereEmail($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Customer whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Customer whereLanguage($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Customer whereMemberId($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Customer whereMode($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Customer whereName($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Customer whereNumber($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Customer whereRememberToken($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Customer whereShoppingUserId($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Customer whereUpdatedAt($value)
* @mixin \Eloquent
*/
class Customer extends Authenticatable // Erbt von Authenticatable
{
use HasFactory, Notifiable;
protected $table = 'customers';
protected $fillable = [
'name',
'email',
'shopping_user_id',
'member_id',
'number',
'language',
'mode',
];
// Wichtig: Laravel Auth benötigt dies, auch wenn kein Passwort verwendet wird
protected $hidden = [
'remember_token',
];
public function shoppingUser()
{
return $this->belongsTo(ShoppingUser::class, 'shopping_user_id');
}
public function member()
{
return $this->belongsTo(User::class, 'member_id');
}
}

View file

@ -51,6 +51,11 @@ class ShippingCountry extends Model
return $this->hasMany('App\Models\ShoppingOrder', 'country_id');
}
public function hasShoppingOrders()
{
return $this->shopping_orders()->exists();
}
public static function getActiveShippingCountries(){
$ret = [];

View file

@ -119,11 +119,9 @@ class ShoppingCollectOrder extends Model
{
$tax_split = $this->tax_split;
$add_tax = round($add_tax, 2);
$tax_split[$tax_rate] = isset($tax_split[$tax_rate]) ? round($tax_split[$tax_rate] += $add_tax, 2) : $add_tax;
foreach((array)$tax_split as $key=>$value){
$tax_split[$key] = number_format($value, 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,14 +129,43 @@ class ShoppingCollectOrder extends Model
{
$net_split = $this->net_split;
$add_net = round($add_net, 2);
$net_split[$tax_rate] = isset($net_split[$tax_rate]) ? round($net_split[$tax_rate] += $add_net, 2) : $add_net;
foreach($net_split as $key=>$value){
$net_split[$key] = number_format($value, 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;
}
/**
* Parst verschiedene Zahlenformate zu einem float-Wert
* Unterstützt: 19.50, 1234.56, 1.234,56, 1,234.56
*/
private function parseNumericValue($value)
{
// Bereits eine Zahl? Direkt zurückgeben
if (is_numeric($value)) {
return (float)$value;
}
// String zu String konvertieren für weitere Verarbeitung
$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));
} 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);
} else {
// Einfaches Format: 19.50, 123.45, etc.
// Nur Kommas durch Punkte ersetzen
return (float)str_replace(',', '.', $value);
}
}
public function addShopItem($shop_item_id, $shop_item)
{
$numberFields = [

View file

@ -46,6 +46,8 @@ use Illuminate\Database\Eloquent\Model;
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingPayment whereAboInterval($value)
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingPayment whereCarddata($value)
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingPayment whereIsAbo($value)
* @property string|null $identifier
* @method static \Illuminate\Database\Eloquent\Builder<static>|ShoppingPayment whereIdentifier($value)
* @mixin \Eloquent
*/
class ShoppingPayment extends Model
@ -108,6 +110,7 @@ class ShoppingPayment extends Model
return __('payment.purchase_on_account');
}
}
return __('payment.unknown');
}
public function getPaymentAmount(){

View file

@ -317,4 +317,23 @@ class ShoppingUser extends Model
public function getAllOrdersByMember(){
return ShoppingUserService::getAllOrdersByMember($this);
}
public function getDeliveryCountry($get_country = false){
if($this->same_as_billing == 1){
if($this->billing_country_id){
if($get_country){
return $this->billing_country;
}
return $this->billing_country->getLocated();
}
}else{
if($this->shipping_country_id){
if($get_country){
return $this->shipping_country;
}
return $this->shipping_country->getLocated();
}
}
return 'not set';
}
}

View file

@ -86,7 +86,7 @@ class UserLevel extends Model
public function getNextUserLevels(){
//$ret = [0=>'Keinen'];
$ret = UserLevel::where('active', true)->where('id', '!=', $this->id)->orderBy('pos', 'asc')->get()->pluck('name', 'id')->toArray();
return array_add($ret, 0, '-> Keinen Karriere Level');
return [0 => '-> Keinen Karriere Level'] + $ret;
}
public function setPosAttribute($value){