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

@ -2,8 +2,9 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Cviebrock\EloquentSluggable\Sluggable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
/**
* App\Models\Category
@ -49,26 +50,21 @@ use Cviebrock\EloquentSluggable\Sluggable;
* @property-read int|null $translations_count
* @mixin \Eloquent
*/
class Category extends Model
{
use Sluggable;
protected $table = 'categories';
protected $fillable = [
'parent_id', 'name', 'headline', 'pos', 'active',
'parent_id',
'name',
'headline',
'pos',
'active',
'slug',
];
public function sluggable() : array
{
return [
'slug' => [
'source' => 'name'
]
];
}
public function parent()
{
return $this->belongsTo('App\Models\Category', 'parent_id');
@ -82,48 +78,50 @@ class Category extends Model
public function product_categories()
{
return $this->hasMany('App\Models\ProductCategory', 'category_id', 'id')->orderBy('pos', 'DESC');
}
public function productCategoriesCountActive()
{
$category_id = $this->id;
return Product::where('active', true)->whereHas('product_categories', function ($query) use ($category_id) {
$query->where('category_id', $category_id); //
})->orderBy('pos', 'ASC')->count();
$query->where('category_id', $category_id); //
})->orderBy('pos', 'ASC')->count();
}
public function productCategoriesCountActiveOn($show_on = ['1'])
{
$category_id = $this->id;
return Product::where('active', true)->whereJsonContains('show_on', $show_on)
->whereHas('product_categories', function ($query) use ($category_id) {
$query->where('category_id', $category_id); //
})->orderBy('pos', 'ASC')->count();
->whereHas('product_categories', function ($query) use ($category_id) {
$query->where('category_id', $category_id); //
})->orderBy('pos', 'ASC')->count();
}
public function setSlugAttribute($value)
{
$slug = Str::slug($value);
if (self::where('slug', $slug)->exists()) {
$slug = $slug . '-' . self::where('slug', $slug)->count();
}
$this->attributes['slug'] = $slug;
}
public function iq_image()
{
return $this->belongsTo('App\Models\IqImage', 'headline_image_id');
}
public function setPosAttribute($value){
public function setPosAttribute($value)
{
$this->attributes['pos'] = is_numeric($value) ? $value : null;
}
public function translations()
{
return $this->hasMany(TransCategory::class, 'categorie_id');
}
public function getLang($key)
public function getLang($key)
{
$lang = \App::getLocale();
if ($lang == 'de') {
@ -135,9 +133,7 @@ class Category extends Model
public function getTrans($key, $lang)
{
$trans = $this->translations->where('language','=', $lang)->where('key', $key)->first();
$trans = $this->translations->where('language', '=', $lang)->where('key', $key)->first();
return $trans ? $trans->value : '';
}
}

View file

@ -0,0 +1,129 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
/**
* App\Models\DashboardNews
*
* @property int $id
* @property string|null $title
* @property string|null $teaser
* @property string|null $content
* @property array|null $trans_title
* @property array|null $trans_teaser
* @property array|null $trans_content
* @property bool $active
* @property \Illuminate\Support\Carbon|null $display_date
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @mixin \Eloquent
*/
class DashboardNews extends Model
{
protected $table = 'dashboard_news';
protected $casts = [
'trans_title' => 'array',
'trans_teaser' => 'array',
'trans_content' => 'array',
'file_links' => 'array',
'active' => 'boolean',
'display_date' => 'date',
];
protected $fillable = [
'title',
'teaser',
'content',
'trans_title',
'trans_teaser',
'trans_content',
'file_links',
'active',
'display_date',
];
/**
* Get translated value or fallback to default (German)
*/
public function getLang($key)
{
$lang = \App::getLocale();
if ($lang == 'de') {
return $this->{$key};
}
$trans = $this->getTrans($key, $lang);
if (!$trans || $trans == '') {
return $this->{$key};
}
return $trans;
}
/**
* Get specific translation
*/
public function getTrans($key, $lang)
{
$transKey = 'trans_' . $key;
if (!empty($this->{$transKey}[$lang])) {
return $this->{$transKey}[$lang];
}
return "";
}
/**
* Get active news
*/
public static function getActiveNews()
{
return self::where('active', true)
->orderBy('created_at', 'DESC')
->first();
}
/**
* Get formatted display date or created_at as fallback
*/
public function getDisplayDateFormatted()
{
$date = $this->display_date ?: $this->created_at;
return $date ? $date->format('d.m.Y') : '';
}
/**
* Get file links for current language
*/
public function getFileLinks($lang = null)
{
if (!$lang) {
$lang = \App::getLocale();
}
if (!$this->file_links || !isset($this->file_links[$lang])) {
return [];
}
return collect($this->file_links[$lang])->map(function ($link) {
if (isset($link['file_id'])) {
$file = \App\Models\DcFile::find($link['file_id']);
if ($file && $file->active) {
return [
'file' => $file,
'label' => $link['label'] ?? $file->original_name,
];
}
}
return null;
})->filter()->values();
}
/**
* Check if news has file links for current language
*/
public function hasFileLinks($lang = null)
{
return count($this->getFileLinks($lang)) > 0;
}
}

View file

@ -6,6 +6,7 @@
namespace App\Models;
use App\Services\Util;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
@ -29,7 +30,7 @@ use Illuminate\Database\Eloquent\Model;
* @property Homeparty $homeparty
* @property HomepartyUser $homeparty_user
* @property Product $product
* @package App\Models
*
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUserOrderItem newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUserOrderItem newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUserOrderItem query()
@ -47,58 +48,66 @@ use Illuminate\Database\Eloquent\Model;
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUserOrderItem whereSlug($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUserOrderItem whereTaxRate($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUserOrderItem whereUpdatedAt($value)
*
* @property float|null $ek_price_net
*
* @method static \Illuminate\Database\Eloquent\Builder|HomepartyUserOrderItem whereEkPriceNet($value)
*
* @mixin \Eloquent
*/
class HomepartyUserOrderItem extends Model
{
protected $table = 'homeparty_user_order_items';
protected $table = 'homeparty_user_order_items';
protected $casts = [
'homeparty_id' => 'int',
'homeparty_user_id' => 'int',
'product_id' => 'int',
'qty' => 'int',
'price' => 'float',
'price_net' => 'float',
'tax_rate' => 'float',
'points' => 'int',
'margin' => 'float',
'ek_price' => 'float',
'ek_price_net' => 'float'
protected $casts = [
'homeparty_id' => 'int',
'homeparty_user_id' => 'int',
'product_id' => 'int',
'qty' => 'int',
'price' => 'float',
'price_net' => 'float',
'tax_rate' => 'float',
'points' => 'float',
'margin' => 'float',
'ek_price' => 'float',
'ek_price_net' => 'float',
];
];
protected $fillable = [
'homeparty_id',
'homeparty_user_id',
'product_id',
'qty',
'price',
'price_net',
'tax_rate',
'points',
'margin',
'ek_price',
protected $fillable = [
'homeparty_id',
'homeparty_user_id',
'product_id',
'qty',
'price',
'price_net',
'tax_rate',
'points',
'margin',
'ek_price',
'ek_price_net',
'slug'
];
'slug',
];
public function homeparty()
{
return $this->belongsTo(Homeparty::class);
}
public function homeparty()
{
return $this->belongsTo(Homeparty::class);
}
public function homeparty_user()
{
return $this->belongsTo(HomepartyUser::class);
}
public function homeparty_user()
{
return $this->belongsTo(HomepartyUser::class);
}
public function product()
{
return $this->belongsTo(Product::class);
}
public function product()
{
return $this->belongsTo(Product::class);
}
public function setPointsAttribute($value)
{
$this->attributes['points'] = $value !== null ? Util::reFormatNumber($value) : null;
}
public function getFormattedPrice()
{
@ -117,7 +126,7 @@ class HomepartyUserOrderItem 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 getFormattedEKPrice()
@ -127,7 +136,7 @@ class HomepartyUserOrderItem extends Model
public function getFormattedTotalEKPrice()
{
return formatNumber($this->attributes['ek_price'] * $this->attributes['qty']);
return formatNumber($this->attributes['ek_price'] * $this->attributes['qty']);
}
public function getFormattedEKPriceNet()
@ -137,7 +146,7 @@ class HomepartyUserOrderItem extends Model
public function getFormattedTotalEKPriceNet()
{
return formatNumber($this->attributes['ek_price_net'] * $this->attributes['qty']);
return formatNumber($this->attributes['ek_price_net'] * $this->attributes['qty']);
}
public function getFormattedIncomePrice()
@ -147,12 +156,12 @@ class HomepartyUserOrderItem extends Model
public function getFormattedTotalIncomePrice()
{
return formatNumber(($this->attributes['price'] - $this->attributes['ek_price']) * $this->attributes['qty']);
return formatNumber(($this->attributes['price'] - $this->attributes['ek_price']) * $this->attributes['qty']);
}
public function getFormattedTotalPoints()
{
return formatNumber($this->attributes['points'] * $this->attributes['qty'], 0);
return formatNumber($this->attributes['points'] * $this->attributes['qty'], 2);
}
public function getTotalPrice()
@ -160,25 +169,24 @@ class HomepartyUserOrderItem extends Model
return (float) ($this->attributes['price'] * $this->attributes['qty']);
}
public function getTotalPoints()
{
return ($this->attributes['points'] * $this->attributes['qty']);
return $this->attributes['points'] * $this->attributes['qty'];
}
public function geTotalPriceNet()
{
return (float) ($this->attributes['price_net'] * $this->attributes['qty']);
return (float) ($this->attributes['price_net'] * $this->attributes['qty']);
}
public function geTotalEKPrice()
{
return (float) ($this->attributes['ek_price'] * $this->attributes['qty']);
return (float) ($this->attributes['ek_price'] * $this->attributes['qty']);
}
public function geTotalEKPriceNet()
{
return (float) ($this->attributes['ek_price_net'] * $this->attributes['qty']);
return (float) ($this->attributes['ek_price_net'] * $this->attributes['qty']);
}
public function getIncomePrice()
@ -188,14 +196,13 @@ class HomepartyUserOrderItem extends Model
public function geTotalIncomePrice()
{
return (float) (($this->attributes['price'] - $this->attributes['ek_price']) * $this->attributes['qty']);
return (float) (($this->attributes['price'] - $this->attributes['ek_price']) * $this->attributes['qty']);
}
public function getCurrencyByKey($key)
{
$rNumber = 0;
if($this->homeparty && $this->homeparty->isPriceCurrency()){
if ($this->homeparty && $this->homeparty->isPriceCurrency()) {
$user_country = $this->homeparty->getUserCountry();
$faktor = isset($user_country->currency_faktor) ? $user_country->currency_faktor : 1;
switch ($key) {
@ -204,15 +211,13 @@ class HomepartyUserOrderItem extends Model
break;
case 'TotalPrice':
$rNumber = $this->getTotalPrice() * $faktor;
break;
break;
case 'TotalEKPrice':
$rNumber = $this->geTotalEKPrice() * $faktor;
break;
break;
}
}
return formatNumber($rNumber);
}
}

View file

@ -40,6 +40,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\ProductCategory[] $categories
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\ProductImage[] $images
* @property-write mixed $price_vk
*
* @method static bool|null forceDelete()
* @method static \Illuminate\Database\Query\Builder|\App\Models\Product onlyTrashed()
* @method static bool|null restore()
@ -71,39 +72,56 @@ use Illuminate\Database\Eloquent\SoftDeletes;
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereUsage($value)
* @method static \Illuminate\Database\Query\Builder|\App\Models\Product withTrashed()
* @method static \Illuminate\Database\Query\Builder|\App\Models\Product withoutTrashed()
*
* @property string|null $slug
*
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product findSimilarSlugs($attribute, $config, $slug)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereSlug($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product query()
*
* @property int|null $weight
* @property int|null $show_at
* @property array|null $action
* @property-read int|null $attributes_count
* @property-read int|null $categories_count
* @property-read int|null $images_count
*
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereAction($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereShowAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereWeight($value)
*
* @property int|null $points
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\ProductImage[] $imagesActive
* @property-read int|null $images_active_count
*
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product wherePoints($value)
*
* @property string|null $identifier
*
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereIdentifier($value)
*
* @property int|null $upgrade_to_id
*
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereUpgradeToId($value)
*
* @property int|null $contents_total
* @property int|null $unit
*
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereContentsTotal($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereUnit($value)
*
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\CountryPrice[] $country_prices
* @property-read int|null $country_prices_count
* @property int|null $wp_number
*
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereWpNumber($value)
*
* @property bool|null $shipping_addon
*
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereShippingAddon($value)
*
* @property-read int|null $ingredients_count
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\ProductIngredient[] $product_ingredients
* @property-read int|null $product_ingredients_count
@ -111,35 +129,43 @@ use Illuminate\Database\Eloquent\SoftDeletes;
* @property array|null $show_on
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Ingredient[] $p_ingredients
* @property-read int|null $p_ingredients_count
*
* @method static \Illuminate\Database\Eloquent\Builder|Product whereNoCommission($value)
* @method static \Illuminate\Database\Eloquent\Builder|Product whereShowOn($value)
* @method static \Illuminate\Database\Eloquent\Builder|Product withUniqueSlugConstraints(\Illuminate\Database\Eloquent\Model $model, string $attribute, array $config, string $slug)
*
* @property string|null $ean
*
* @method static \Illuminate\Database\Eloquent\Builder|Product whereEan($value)
*
* @property bool|null $no_free_shipping
* @property bool|null $buying_restriction
* @property int|null $buying_restriction_amount
*
* @method static \Illuminate\Database\Eloquent\Builder|Product whereBuyingRestriction($value)
* @method static \Illuminate\Database\Eloquent\Builder|Product whereBuyingRestrictionAmount($value)
* @method static \Illuminate\Database\Eloquent\Builder|Product whereNoFreeShipping($value)
*
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\ProductBuying> $product_buyings
* @property-read int|null $product_buyings_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\ProductBuying> $product_buyings
* @property bool|null $sponsor_buying_points
* @property int|null $sponsor_buying_points_amount
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\ProductBuying> $product_buyings
*
* @method static \Illuminate\Database\Eloquent\Builder|Product whereSponsorBuyingPoints($value)
* @method static \Illuminate\Database\Eloquent\Builder|Product whereSponsorBuyingPointsAmount($value)
*
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\ProductBuying> $product_buyings
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\TransProduct> $translations
* @property-read int|null $translations_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\ProductCategory> $product_categories
* @property-read int|null $product_categories_count
*
* @mixin \Eloquent
*/
class Product extends Model
{
/*identifiers
show_upgrade # in membership payment can upgrade this package to show order
show_order # in membership payment show always
@ -167,11 +193,9 @@ class Product extends Model
'buying_restriction_amount' => 'int',
'sponsor_buying_points' => 'bool',
'sponsor_buying_points_amount' => 'int',
];
use Sluggable;
use Sluggable;
use SoftDeletes;
protected $dates = ['deleted_at'];
@ -210,7 +234,7 @@ class Product extends Model
'sponsor_buying_points_amount',
'identifier',
'action',
'upgrade_to_id'
'upgrade_to_id',
];
public $identifiers_types = [
@ -221,6 +245,7 @@ class Product extends Model
'upgrade_member' => 'Berater upgrade zur Karriere ID',
'proportional_voucher' => 'Anteiliger Gutschein Berater',
];
public $unitTypes = [
0 => '',
1 => 'ml',
@ -269,7 +294,7 @@ class Product extends Model
];
/************* ✨ Codeium Command ⭐ *************/
/************* ✨ Codeium Command ⭐ *************/
/**
* Configure the model for auto-generating a slug.
*
@ -280,48 +305,58 @@ class Product extends Model
* @return array Configuration for slug generation.
*/
/****** e935bd41-f49b-4736-9603-2da86dc27f25 *******/ public function sluggable() : array
/****** e935bd41-f49b-4736-9603-2da86dc27f25 *******/
public function sluggable(): array
{
return [
'slug' => [
'source' => 'name'
]
'source' => 'name',
],
];
}
public function product_buyings(){
public function product_buyings()
{
return $this->hasMany('App\Models\ProductBuying', 'product_id', 'id');
}
public function attributes(){
public function attributes()
{
return $this->hasMany('App\Models\ProductAttribute', 'product_id', 'id');
}
public function categories(){
public function categories()
{
return $this->hasMany('App\Models\ProductCategory', 'product_id', 'id')->orderBy('pos', 'DESC');
}
public function product_categories(){
public function product_categories()
{
return $this->hasMany('App\Models\ProductCategory', 'product_id', 'id')->orderBy('pos', 'DESC');
}
public function images(){
public function images()
{
return $this->hasMany('App\Models\ProductImage', 'product_id', 'id')->orderBy('pos');
}
public function imagesActive(){
public function imagesActive()
{
return $this->hasMany('App\Models\ProductImage', 'product_id', 'id')->where('active', true)->orderBy('pos');
}
public function getImageUrl(){
if(count($this->imagesActive)){
public function getImageUrl()
{
if (count($this->imagesActive)) {
return route('product_image', [$this->imagesActive->first()->slug]);
}
return "";
return '';
}
public function getProductUrl(){
return 'https://mivita.shop/produkte/alle-produkte/'.$this->slug;
public function getProductUrl()
{
return 'https://mivita.shop/produkte/alle-produkte/'.$this->slug;
}
public function country_prices()
@ -346,96 +381,160 @@ class Product extends Model
return $this->hasMany(ProductIngredient::class, 'product_ingredients', 'id');
}
public function getActionName($id = 0){
if(isset($this->actions[$id])){
/**
* Bundle-Items: Enthaltene Produkte in diesem Set/Kit
*/
public function bundleItems()
{
return $this->belongsToMany(Product::class, 'product_bundles', 'product_id', 'bundle_product_id')
->withPivot('quantity', 'pos')
->orderBy('product_bundles.pos');
}
/**
* Bundle-Parents: Sets/Kits, die dieses Produkt enthalten
*/
public function bundleParents()
{
return $this->belongsToMany(Product::class, 'product_bundles', 'bundle_product_id', 'product_id')
->withPivot('quantity', 'pos');
}
/**
* Prüft ob dieses Produkt ein Set/Kit ist (enthält andere Produkte)
*/
public function isBundle(): bool
{
return $this->bundleItems()->count() > 0;
}
/**
* Holt Bundle-Items mit eager loading
*/
public function product_bundles()
{
return $this->hasMany(ProductBundle::class, 'product_id', 'id')->orderBy('pos');
}
public function getActionName($id = 0)
{
if (isset($this->actions[$id])) {
return $this->actions[$id];
}
return false;
}
public function getUpgradeToIdName($from){
if($from === 'payment_for_shop_upgrade'){
public function getUpgradeToIdName($from)
{
if ($from === 'payment_for_shop_upgrade') {
$value = Product::find($this->upgrade_to_id);
}
if($from === 'payment_for_lead_upgrade'){
if ($from === 'payment_for_lead_upgrade') {
$value = UserLevel::find($this->upgrade_to_id);
}
if($value){
if ($value) {
return $value->name;
}
return "not found";
return 'not found';
}
public function _format_number($value){
return preg_replace("/[^0-9,]/", "", $value);
public function _format_number($value)
{
return preg_replace('/[^0-9,]/', '', $value);
}
public function setPriceAttribute( $value ) {
public function setPriceAttribute($value)
{
$this->attributes['price'] = $value !== null ? Util::reFormatNumber($value) : null;
$this->attributes['price'] = $value !== null ? Util::reFormatNumber($value) : null;
}
public function setPriceEkAttribute( $value ) {
$this->attributes['price_ek'] = $value !== null ? Util::reFormatNumber($value) : null;
public function setPriceEkAttribute($value)
{
$this->attributes['price_ek'] = $value !== null ? Util::reFormatNumber($value) : null;
}
public function setTaxAttribute( $value ) {
public function setTaxAttribute($value)
{
$this->attributes['tax'] = $value !== null ? Util::reFormatNumber($value) : null;
}
public function setPriceOldAttribute( $value ) {
$this->attributes['price_old'] = $value !== null ? Util::reFormatNumber($value) : null;
public function setPriceOldAttribute($value)
{
$this->attributes['price_old'] = $value !== null ? Util::reFormatNumber($value) : null;
}
public function setPointsAttribute($value)
{
$this->attributes['points'] = $value !== null ? Util::reFormatNumber($value) : null;
}
public function getFormattedPoints()
{
return isset($this->attributes['points']) ? Util::formatNumber($this->attributes['points']) : '';
}
public function getFormattedPrice()
{
return isset($this->attributes['price']) ? Util::formatNumber($this->attributes['price']) : "";
return isset($this->attributes['price']) ? Util::formatNumber($this->attributes['price']) : '';
}
public function getFormattedPriceEk()
{
return isset($this->attributes['price_ek']) ? Util::formatNumber($this->attributes['price_ek']) : "";
return isset($this->attributes['price_ek']) ? Util::formatNumber($this->attributes['price_ek']) : '';
}
public function getFormattedPriceOld()
{
return isset($this->attributes['price_old']) ? Util::formatNumber($this->attributes['price_old']) : "";
return isset($this->attributes['price_old']) ? Util::formatNumber($this->attributes['price_old']) : '';
}
/*price by user Factor*/
private function calcPriceUserFactor($price, $user=null){
if($this->no_commission){
/* price by user Factor */
private function calcPriceUserFactor($price, $user = null)
{
if ($this->no_commission) {
return $price;
}
$user = $user ? $user : \Auth::user();
if($user && $user->user_level){
$margin = (($user->user_level->margin -100)*-1) / 100;
if ($user && $user->user_level) {
$margin = (($user->user_level->margin - 100) * -1) / 100;
$price = $price * $margin;
}
return $price;
}
private function calcPriceUserCommission($price, $user){
if($this->no_commission){
private function calcPriceUserCommission($price, $user)
{
if ($this->no_commission) {
return $price;
}
$user = $user ? $user : \Auth::user();
if($user && $user->user_level){
if ($user && $user->user_level) {
$margin = $user->user_level->margin;
$price = $price / 100 * $margin;
$price = $price / 100 * $margin;
}
return $price;
}
/*price net*/
private function calcPriceNet($price, $country=null){
/* price net */
private function calcPriceNet($price, $country = null)
{
$tax = $this->getTaxWith($country);
$tax_rate = ($tax + 100) / 100;
$tax_rate = ($tax + 100) / 100;
return $price / $tax_rate;
}
//price calu with
public function getPriceWith(Bool $net = true, Bool $ufactor = true, $country = null, $commission=false, $user = null){
// price calu with
public function getPriceWith(bool $net = true, bool $ufactor = true, $country = null, $commission = false, $user = null)
{
$price = isset($this->attributes['price']) ? $this->attributes['price'] : null;
$cprice = $country ? $this->getCPrice($country) : null;
$price = $cprice ? $cprice : $price;
@ -446,19 +545,21 @@ class Product extends Model
return round($price, 2);
}
/*out*/
public function getFormattedPriceWith(Bool $net = true, Bool $ufactor = true, $country = null, $commission=false)
{
return isset($this->attributes['price']) ? Util::formatNumber($this->getPriceWith($net, $ufactor, $country, $commission)) : "";
/* out */
public function getFormattedPriceWith(bool $net = true, bool $ufactor = true, $country = null, $commission = false)
{
return isset($this->attributes['price']) ? Util::formatNumber($this->getPriceWith($net, $ufactor, $country, $commission)) : '';
}
public function getTaxWith($country = null){
public function getTaxWith($country = null)
{
$tax = isset($this->attributes['tax']) ? $this->attributes['tax'] : null;
$ctax = $country ? $this->getCTax($country) : null;
return $ctax !== null ? $ctax : $tax;
}
public function getFormattedPriceOldWith(Bool $net = true, Bool $ufactor = true, $country = null)
public function getFormattedPriceOldWith(bool $net = true, bool $ufactor = true, $country = null)
{
$price = isset($this->attributes['price_old']) ? $this->attributes['price_old'] : null;
$cprice = $country ? $this->getCPriceOld($country) : null;
@ -466,105 +567,120 @@ class Product extends Model
$price = $net ? $this->calcPriceNet($price, $country) : $price;
$price = $ufactor ? $this->calcPriceUserFactor($price) : $price;
$price = round($price, 2);
return isset($price) ? Util::formatNumber($price) : "";
}
return isset($price) ? Util::formatNumber($price) : '';
}
public function getFormattedTax($country = null)
{
return isset($this->attributes['tax']) ? Util::formatNumber($this->getTaxWith($country), 0) : "";
return isset($this->attributes['tax']) ? Util::formatNumber($this->getTaxWith($country), 0) : '';
}
public function getBasePriceFormattedFullWith(Bool $net = true, Bool $ufactor = true, $country = null){
public function getBasePriceFormattedFullWith(bool $net = true, bool $ufactor = true, $country = null)
{
$price = $this->getPriceWith($net, $ufactor, $country);
if($price = $this->getBasePriceWith($price)){
if ($price = $this->getBasePriceWith($price)) {
$unit = $this->attributes['unit'];
//ml g
if($unit === 1 || $unit === 2){
return Util::formatNumber($price) . ' € / 100 '.$this->getUnitType();
// ml g
if ($unit === 1 || $unit === 2) {
return Util::formatNumber($price).' € / 100 '.$this->getUnitType();
}
//l kg
if($unit === 3 || $unit === 4){
return Util::formatNumber($price) . ' € / 1 '.$this->getUnitType();
// l kg
if ($unit === 3 || $unit === 4) {
return Util::formatNumber($price).' € / 1 '.$this->getUnitType();
}
}
return "";
return '';
}
public function getBasePriceWith($price){
if(isset($this->attributes['unit']) && isset($this->attributes['contents_total']) && $this->attributes['contents_total'] != 0){
public function getBasePriceWith($price)
{
if (isset($this->attributes['unit']) && isset($this->attributes['contents_total']) && $this->attributes['contents_total'] != 0) {
$unit = $this->attributes['unit'];
//ml g
if($unit === 1 || $unit === 2){
// ml g
if ($unit === 1 || $unit === 2) {
return $price * 100 / $this->attributes['contents_total'];
}
//l kg
if($unit === 3 || $unit === 4){
return $price * 1000 / $this->attributes['contents_total'];
// l kg
if ($unit === 3 || $unit === 4) {
return $price * 1000 / $this->attributes['contents_total'];
}
}
return "";
return '';
}
public function getBasePriceFormattedFull(){
if($price = $this->getBasePrice()){
public function getBasePriceFormattedFull()
{
if ($price = $this->getBasePrice()) {
$unit = $this->attributes['unit'];
//ml g
if($unit === 1 || $unit === 2){
return Util::formatNumber($price) . ' € / 100 '.$this->getUnitType();
// ml g
if ($unit === 1 || $unit === 2) {
return Util::formatNumber($price).' € / 100 '.$this->getUnitType();
}
//l kg
if($unit === 3 || $unit === 4){
return Util::formatNumber($price) . ' € / 1 '.$this->getUnitType();
// l kg
if ($unit === 3 || $unit === 4) {
return Util::formatNumber($price).' € / 1 '.$this->getUnitType();
}
}
return "";
return '';
}
public function getBasePriceFormatted(){
if($price = $this->getBasePrice()){
public function getBasePriceFormatted()
{
if ($price = $this->getBasePrice()) {
return Util::formatNumber($price);
}
return "";
return '';
}
public function getBasePrice(){
if(isset($this->attributes['unit']) && isset($this->attributes['contents_total']) && $this->attributes['contents_total'] != 0){
public function getBasePrice()
{
if (isset($this->attributes['unit']) && isset($this->attributes['contents_total']) && $this->attributes['contents_total'] != 0) {
$unit = $this->attributes['unit'];
//ml g
if($unit === 1 || $unit === 2){
// ml g
if ($unit === 1 || $unit === 2) {
return $this->attributes['price'] * 100 / $this->attributes['contents_total'];
}
//l kg
if($unit === 3 || $unit === 4){
return $this->attributes['price'] * 1000 / $this->attributes['contents_total'];
// l kg
if ($unit === 3 || $unit === 4) {
return $this->attributes['price'] * 1000 / $this->attributes['contents_total'];
}
}
return "";
}
public function getUnitType(){
return '';
}
public function getUnitType()
{
return isset($this->unitTypes[$this->unit]) ? __($this->unitTypes[$this->unit]) : '-';
}
public function getShowAtType(){
public function getShowAtType()
{
return isset($this->showATs[$this->show_at]) ? $this->showATs[$this->show_at] : '-';
}
public function getShowOnTypes(){
public function getShowOnTypes()
{
$ret = [];
if($this->show_on && is_array($this->show_on)){
foreach($this->show_on as $show){
if ($this->show_on && is_array($this->show_on)) {
foreach ($this->show_on as $show) {
$ret[] = isset($this->showONs[$show]) ? $this->showONs[$show] : '-';
}
}
return $ret;
}
public function setPosAttribute($value){
public function setPosAttribute($value)
{
$this->attributes['pos'] = is_numeric($value) ? $value : null;
}
public function getLang($key)
{
$lang = \App::getLocale();
@ -572,58 +688,75 @@ class Product extends Model
return $this->{$key};
}
$trans = $this->getTrans($key, $lang);
return $trans != '' ? $trans : $this->{$key};
return $trans != '' ? $trans : $this->{$key};
}
public function getTrans($key, $lang)
{
$trans = $this->translations->where('language','=', $lang)->where('key', $key)->first();
$trans = $this->translations->where('language', '=', $lang)->where('key', $key)->first();
return $trans ? $trans->value : '';
}
public function getTranNames()
{
$ret = "";
foreach ((array) $this->trans_name as $value){
$ret = '';
foreach ((array) $this->trans_name as $value) {
$ret .= $value.', ';
}
return rtrim($ret, ', ');
}
public function getCountryPrice(Country $country){
if($country->own_eur){
return $this->country_prices->where('country_id', '=', $country->id)->first() ?: new CountryPrice();
public function getCountryPrice(Country $country)
{
if ($country->own_eur) {
return $this->country_prices->where('country_id', '=', $country->id)->first() ?: new CountryPrice;
}
return new CountryPrice();
return new CountryPrice;
}
public function getCPrice(Country $country){
public function getCPrice(Country $country)
{
return $this->getCountryPrice($country)->c_price;
}
public function getCTax(Country $country){
public function getCTax(Country $country)
{
return $this->getCountryPrice($country)->c_tax;
}
public function getCPriceOld(Country $country){
public function getCPriceOld(Country $country)
{
return $this->getCountryPrice($country)->c_price_old;
}
public function getCCurrency(Country $country){
public function getCCurrency(Country $country)
{
return $this->getCountryPrice($country)->c_currency;
}
public function getRealPrice(Country $country){
if($country->own_eur && $this->getCPrice($country)){
public function getRealPrice(Country $country)
{
if ($country->own_eur && $this->getCPrice($country)) {
return $this->getCPrice($country);
}
return $this->price;
}
public function getFormattedPriceCurrencyWith(Bool $net = true, Bool $ufactor = true, Country $country = null, $commission = false){
$ret = "";
if($country && isset($country->currency) && $country->currency){
$price = $this->getPriceWith($net, $ufactor, $country, $commission);
$ret = formatNumber($price * $country->currency_faktor)." ".$country->currency_unit;
public function getFormattedPriceCurrencyWith(bool $net = true, bool $ufactor = true, ?Country $country = null, $commission = false)
{
$ret = '';
if ($country && isset($country->currency) && $country->currency) {
$price = $this->getPriceWith($net, $ufactor, $country, $commission);
$ret = formatNumber($price * $country->currency_faktor).' '.$country->currency_unit;
return '<br><span class="small">~'.$ret.'<span>';
}
return "" ;
return '';
}
}

View file

@ -0,0 +1,71 @@
<?php
/**
* ProductBundle Model - Verwaltet Set/Kit Produkt-Beziehungen
*/
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
/**
* Class ProductBundle
*
* @property int $id
* @property int $product_id
* @property int $bundle_product_id
* @property int $quantity
* @property int $pos
* @property Carbon $created_at
* @property Carbon $updated_at
* @property Product $product
* @property Product $bundleProduct
*
* @method static \Illuminate\Database\Eloquent\Builder|ProductBundle newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|ProductBundle newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|ProductBundle query()
* @method static \Illuminate\Database\Eloquent\Builder|ProductBundle whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|ProductBundle whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|ProductBundle whereProductId($value)
* @method static \Illuminate\Database\Eloquent\Builder|ProductBundle whereBundleProductId($value)
* @method static \Illuminate\Database\Eloquent\Builder|ProductBundle whereQuantity($value)
* @method static \Illuminate\Database\Eloquent\Builder|ProductBundle wherePos($value)
* @method static \Illuminate\Database\Eloquent\Builder|ProductBundle whereUpdatedAt($value)
*
* @mixin \Eloquent
*/
class ProductBundle extends Model
{
protected $table = 'product_bundles';
protected $casts = [
'product_id' => 'int',
'bundle_product_id' => 'int',
'quantity' => 'int',
'pos' => 'int',
];
protected $fillable = [
'product_id',
'bundle_product_id',
'quantity',
'pos',
];
/**
* Das Set/Kit-Produkt (Parent)
*/
public function product()
{
return $this->belongsTo(Product::class, 'product_id');
}
/**
* Das enthaltene Produkt (Child)
*/
public function bundleProduct()
{
return $this->belongsTo(Product::class, 'bundle_product_id');
}
}

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;
}
}

View file

@ -154,6 +154,7 @@ class ShoppingOrder extends Model
'net_split' => 'array',
'abo_interval' => 'int',
'is_abo' => 'bool',
'points' => 'float',
];
public static $shippedTypes = [
@ -421,6 +422,16 @@ class ShoppingOrder extends Model
return formatNumber($this->attributes['total_shipping']);
}
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 getPriceVkNetBy($product_id)
{
if ($product = Product::find($product_id)) {

View file

@ -91,7 +91,7 @@ class ShoppingOrderItem extends Model
'tax' => 'float',
'price_vk_net' => 'float',
'discount' => 'float',
'points' => 'int',
'points' => 'float',
];
public function shopping_order()
@ -149,4 +149,14 @@ class ShoppingOrderItem extends Model
{
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']) : "";
}
}

View file

@ -40,6 +40,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
* @property-read int|null $shopping_orders_count
* @property-read \App\Models\Country $billing_country
* @property-read \App\Models\Country $shipping_country
*
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingUser newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingUser newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingUser query()
@ -70,57 +71,80 @@ use Illuminate\Database\Eloquent\SoftDeletes;
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingUser whereShippingSalutation($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingUser whereShippingZipcode($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingUser whereUpdatedAt($value)
*
* @property int|null $orders
* @property-read \App\Models\ShoppingOrder $shopping_order
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\ShoppingOrder[] $shopping_orders
*
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingUser whereOrders($value)
*
* @property int|null $abo_options
*
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingUser whereAboOptions($value)
*
* @property int|null $member_id
* @property int|null $number
* @property bool $is_like
* @property array|null $notice
* @property-read \App\User|null $auth_user
* @property-read \App\User|null $member
*
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingUser whereIsLike($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingUser whereMemberId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingUser whereNotice($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingUser whereNumber($value)
*
* @property bool|null $has_buyed
* @property bool|null $subscribed
* @property int|null $wp_order_number
* @property string|null $wp_order_date
*
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingUser whereHasBuyed($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingUser whereSubscribed($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingUser whereWpOrderDate($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingUser whereWpOrderNumber($value)
*
* @property \Illuminate\Support\Carbon|null $deleted_at
* @property string|null $user_deleted_at
*
* @method static \Illuminate\Database\Query\Builder|\App\Models\ShoppingUser onlyTrashed()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingUser whereDeletedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingUser whereUserDeletedAt($value)
* @method static \Illuminate\Database\Query\Builder|\App\Models\ShoppingUser withTrashed()
* @method static \Illuminate\Database\Query\Builder|\App\Models\ShoppingUser withoutTrashed()
*
* @property string|null $mode
*
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingUser whereMode($value)
*
* @property bool|null $faker_mail
* @property string|null $shipping_email
* @property string|null $is_for
* @property string|null $is_from
* @property int|null $shopping_user_id
*
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingUser whereFakerMail($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingUser whereIsFor($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingUser whereIsFrom($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingUser whereShippingEmail($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingUser whereShoppingUserId($value)
*
* @property int|null $homeparty_id
*
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingUser whereHomepartyId($value)
*
* @property int|null $shopping_collect_order_id
*
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingUser whereShoppingCollectOrderId($value)
*
* @property string|null $remarks
*
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingUser whereRemarks($value)
*
* @property string|null $language
*
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingUser whereLanguage($value)
*
* @mixin \Eloquent
*/
class ShoppingUser extends Model
@ -128,10 +152,9 @@ class ShoppingUser extends Model
protected $table = 'shopping_users';
use SoftDeletes;
protected $dates = ['deleted_at'];
protected $fillable = [
'auth_user_id',
'member_id',
@ -163,6 +186,7 @@ class ShoppingUser extends Model
'shipping_city',
'shipping_country_id',
'shipping_phone',
'shipping_postnumber',
'has_buyed',
'subscribed',
'notice',
@ -188,83 +212,93 @@ class ShoppingUser extends Model
'wp_order_number' => 'int',
];
//can null
// can null
public function member()
{
return $this->belongsTo('App\User','member_id');
return $this->belongsTo('App\User', 'member_id');
}
public function auth_user()
{
return $this->belongsTo('App\User','auth_user_id');
}
public function auth_user()
{
return $this->belongsTo('App\User', 'auth_user_id');
}
public function billing_country()
{
return $this->belongsTo('App\Models\Country','billing_country_id');
return $this->belongsTo('App\Models\Country', 'billing_country_id');
}
public function shipping_country()
{
return $this->belongsTo('App\Models\Country','shipping_country_id');
return $this->belongsTo('App\Models\Country', 'shipping_country_id');
}
public function shopping_orders()
{
return $this->hasMany('App\Models\ShoppingOrder','shopping_user_id');
return $this->hasMany('App\Models\ShoppingOrder', 'shopping_user_id');
}
public function shopping_order()
{
return $this->hasOne('App\Models\ShoppingOrder','shopping_user_id');
return $this->hasOne('App\Models\ShoppingOrder', 'shopping_user_id');
}
public function getLocale(){
public function getLocale()
{
return $this->language ? $this->language : \App::getLocale();
}
public function setNotice($key, $value){
public function setNotice($key, $value)
{
$notice = $this->notice;
$notice[$key] = $value;
$this->notice = $notice;
$this->save();
}
public function getNotice($key){
public function getNotice($key)
{
return isset($this->notice[$key]) ? $this->notice[$key] : false;
}
public function removeNotice($key){
public function removeNotice($key)
{
$notice = $this->notice;
if(isset($notice[$key])){
if (isset($notice[$key])) {
unset($notice[$key]);
}
$this->notice = $notice;
$this->save();
}
public function firstEntryByNumber(){
public function firstEntryByNumber()
{
if($this->number>0){
if($shopping_user = ShoppingUser::where('number', $this->number)->orderBy('created_at', 'ASC')->first()){
if ($this->number > 0) {
if ($shopping_user = ShoppingUser::where('number', $this->number)->orderBy('created_at', 'ASC')->first()) {
return $shopping_user;
}
}
return $this;
}
public function lastEntryByNumber(){
if($this->number>0){
if($shopping_user = ShoppingUser::where('number', $this->number)->orderBy('created_at', 'DESC')->first()){
public function lastEntryByNumber()
{
if ($this->number > 0) {
if ($shopping_user = ShoppingUser::where('number', $this->number)->orderBy('created_at', 'DESC')->first()) {
return $shopping_user;
}
}
return $this;
}
public function getOrderPaymentFor() {
public function getOrderPaymentFor()
{
switch($this->is_from){
switch ($this->is_from) {
case 'wizard':
return 1;
case 'membership':
@ -276,34 +310,40 @@ class ShoppingUser extends Model
case 'shopping':
return 6;
case 'extern':
return 7;
return 7;
case 'collection':
return 8;
return 8;
}
return 0;
}
public function setIsForAttribute($value){
if($value === 'abo-me' || $value === 'me'){
public function setIsForAttribute($value)
{
if ($value === 'abo-me' || $value === 'me') {
$this->attributes['is_for'] = 'me';
return;
}
if($value === 'ot-member' || $value === 'ot-customer' || $value === 'abo-ot-member' || $value === 'abo-ot-customer'){
if ($value === 'ot-member' || $value === 'ot-customer' || $value === 'abo-ot-member' || $value === 'abo-ot-customer') {
$this->attributes['is_for'] = 'ot';
return;
}
$this->attributes['is_for'] = $value;
}
public function getAPIShippedType() {
if($this->shopping_order){
public function getAPIShippedType()
{
if ($this->shopping_order) {
return $this->shopping_order->getAPIShippedType();
}
return "free";
return 'free';
}
public function getFullNameAsArray() {
public function getFullNameAsArray()
{
return [
'company' => $this->billing_company,
'salutation' => $this->billing_salutation,
@ -314,26 +354,75 @@ class ShoppingUser extends Model
];
}
public function getAllOrdersByMember(){
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){
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){
} else {
if ($this->shipping_country_id) {
if ($get_country) {
return $this->shipping_country;
}
return $this->shipping_country->getLocated();
}
}
return 'not set';
}
/**
* Prüft ob es sich um eine Packstation/Paketbox-Lieferung handelt
*/
public function isPackstationDelivery(): bool
{
return ! empty($this->shipping_postnumber);
}
/**
* Liefert die effektive Lieferadresse (berücksichtigt same_as_billing)
*/
public function getEffectiveShippingAddress(): array
{
if ($this->same_as_billing) {
return [
'salutation' => $this->billing_salutation,
'company' => $this->billing_company,
'firstname' => $this->billing_firstname,
'lastname' => $this->billing_lastname,
'address' => $this->billing_address,
'address_2' => $this->billing_address_2,
'zipcode' => $this->billing_zipcode,
'city' => $this->billing_city,
'country_id' => $this->billing_country_id,
'phone' => $this->billing_phone,
'postnumber' => null, // Bei same_as_billing keine Packstation
];
}
return [
'salutation' => $this->shipping_salutation,
'company' => $this->shipping_company,
'firstname' => $this->shipping_firstname,
'lastname' => $this->shipping_lastname,
'address' => $this->shipping_address,
'address_2' => $this->shipping_address_2,
'zipcode' => $this->shipping_zipcode,
'city' => $this->shipping_city,
'country_id' => $this->shipping_country_id,
'phone' => $this->shipping_phone,
'postnumber' => $this->shipping_postnumber,
];
}
}

View file

@ -123,17 +123,17 @@ class UserAbo extends Model
];
public static $aboDeliveryDays = [5, 10, 20, 25];
public static $statusTypes = [
0 => 'abo_new',
1 => 'abo_new',
1 => 'abo_new',
2 => 'abo_okay',
3 => 'abo_hold',
4 => 'abo_cancel',
5 => 'abo_finish',
6 => 'abo_inactive',
7 => 'abo_grace'
];
];
public static $statusColors = [
0 => 'success',
@ -144,9 +144,9 @@ class UserAbo extends Model
5 => 'info',
6 => 'warning',
7 => 'danger'
];
];
public function user()
{
@ -159,9 +159,9 @@ class UserAbo extends Model
}
public function shopping_user()
{
return $this->belongsTo('App\Models\ShoppingUser','shopping_user_id');
}
{
return $this->belongsTo('App\Models\ShoppingUser', 'shopping_user_id');
}
public function user_abo_orders()
{
@ -173,66 +173,80 @@ class UserAbo extends Model
return $this->hasMany(UserAboItem::class);
}
public function getCountOrders(){
public function getCountOrders()
{
//sind bezahlte Bestellungen
return $this->user_abo_orders->where('status', '>=', 2)->count();
}
public function setStartDateAttribute( $value ) {
$this->attributes['start_date'] = isset($value) ? (new Carbon($value))->format('Y-m-d') : NULL;
}
public function getCountPaidOrders()
{
//sind bezahlte Bestellungen
return $this->user_abo_orders->where('status', '>=', 2)->where('paid', true)->count();
}
public function setStartDateAttribute($value)
{
$this->attributes['start_date'] = isset($value) ? (new Carbon($value))->format('Y-m-d') : NULL;
}
public function getStartDateAttribute()
{
{
return $this->attributes['start_date'] ? Carbon::parse($this->attributes['start_date'])->format(\Util::formatDateDB()) : '';
}
}
public function setLastDateAttribute( $value ) {
$this->attributes['last_date'] = isset($value) ? (new Carbon($value))->format('Y-m-d') : NULL;
}
public function setLastDateAttribute($value)
{
$this->attributes['last_date'] = isset($value) ? (new Carbon($value))->format('Y-m-d') : NULL;
}
public function getLastDateAttribute()
{
{
return $this->attributes['last_date'] ? Carbon::parse($this->attributes['last_date'])->format(\Util::formatDateDB()) : '';
}
}
public function setNextDateAttribute( $value ) {
$this->attributes['next_date'] = isset($value) ? (new Carbon($value))->format('Y-m-d') : NULL;
}
public function setNextDateAttribute($value)
{
$this->attributes['next_date'] = isset($value) ? (new Carbon($value))->format('Y-m-d') : NULL;
}
public function getNextDateAttribute()
{
{
return $this->attributes['next_date'] ? Carbon::parse($this->attributes['next_date'])->format(\Util::formatDateDB()) : '';
}
}
public function setCancelDateAttribute( $value ) {
$this->attributes['cancel_date'] = isset($value) ? (new Carbon($value))->format('Y-m-d') : NULL;
}
public function setCancelDateAttribute($value)
{
$this->attributes['cancel_date'] = isset($value) ? (new Carbon($value))->format('Y-m-d') : NULL;
}
public function getCancelDateAttribute()
{
{
return $this->attributes['cancel_date'] ? Carbon::parse($this->attributes['cancel_date'])->format(\Util::formatDateDB()) : '';
}
}
public function getFormattedAmount()
{
return isset($this->attributes['amount']) ? Util::formatNumber($this->attributes['amount']/100) : "";
}
{
return isset($this->attributes['amount']) ? Util::formatNumber($this->attributes['amount'] / 100) : "";
}
public function getIsForFormated()
{
return $this->attributes['is_for'] === 'me' ? '<span class="badge badge-outline-warning-dark">'.__('tables.adviser').'</span>' : '<span class="badge badge-outline-info">'.__('tables.customer').'</span>';
return $this->attributes['is_for'] === 'me' ? '<span class="badge badge-outline-warning-dark">' . __('tables.adviser') . '</span>' : '<span class="badge badge-outline-info">' . __('tables.customer') . '</span>';
}
public function getStatusFormated(){
return '<span class="badge badge-pill badge-'.$this->getStatusColor().'">'.$this->getStatusType().'</span>';
public function getStatusFormated()
{
return '<span class="badge badge-pill badge-' . $this->getStatusColor() . '">' . $this->getStatusType() . '</span>';
}
public function getStatusType(){
return isset(self::$statusTypes[$this->status]) ? __('abo.'.self::$statusTypes[$this->status]) : "";
}
public function getStatusType()
{
return isset(self::$statusTypes[$this->status]) ? __('abo.' . self::$statusTypes[$this->status]) : "";
}
public function getStatusColor(){
return isset(self::$statusColors[$this->status]) ? self::$statusColors[$this->status] : "default";
}
public function getStatusColor()
{
return isset(self::$statusColors[$this->status]) ? self::$statusColors[$this->status] : "default";
}
public function getPaymentType(){
public function getPaymentType()
{
return $this->clearingtype === 'wlt' ? __('payment.paypal') : __('payment.credit_card');
}
}

View file

@ -40,26 +40,28 @@ class UserAboOrder extends Model
protected $casts = [
'user_abo_id' => 'int',
'shopping_order_id' => 'int',
'status' => 'int'
'status' => 'int',
'paid' => 'bool'
];
protected $fillable = [
'user_abo_id',
'user_id',
'shopping_order_id',
'status'
'status',
'paid'
];
public static $statusTypes = [
0 => 'abo_new',
1 => 'abo_new',
1 => 'abo_new',
2 => 'abo_okay',
3 => 'abo_hold',
4 => 'abo_cancel',
5 => 'abo_finish',
6 => 'abo_inactive',
7 => 'abo_grace'
];
];
public static $statusColors = [
0 => 'success',
@ -70,7 +72,7 @@ class UserAboOrder extends Model
5 => 'info',
6 => 'warning',
7 => 'danger'
];
];
@ -84,16 +86,18 @@ class UserAboOrder extends Model
return $this->belongsTo(UserAbo::class);
}
public function getStatusFormated(){
return '<span class="badge badge-pill badge-'.$this->getStatusColor().'">'.$this->getStatusType().'</span>';
public function getStatusFormated()
{
return '<span class="badge badge-pill badge-' . $this->getStatusColor() . '">' . $this->getStatusType() . '</span>';
}
public function getStatusType(){
return isset(self::$statusTypes[$this->status]) ? __('abo.'.self::$statusTypes[$this->status]) : "";
}
public function getStatusColor(){
return isset(self::$statusColors[$this->status]) ? self::$statusColors[$this->status] : "default";
}
public function getStatusType()
{
return isset(self::$statusTypes[$this->status]) ? __('abo.' . self::$statusTypes[$this->status]) : "";
}
public function getStatusColor()
{
return isset(self::$statusColors[$this->status]) ? self::$statusColors[$this->status] : "default";
}
}

View file

@ -136,10 +136,49 @@ class UserAccount extends Model
{
protected $table = 'user_accounts';
protected $fillable = [
'm_account', 'm_salutation', 'm_first_name', 'm_last_name', 'm_notes', 'company', 'salutation', 'first_name', 'last_name', 'address', 'address_2', 'zipcode', 'city', 'country_id', 'pre_phone_id', 'phone', 'pre_mobil_id', 'mobil',
'tax_number', 'tax_identification_number', 'taxable_sales', 'same_as_billing',
'shipping_salutation', 'shipping_company', 'shipping_firstname', 'shipping_lastname', 'shipping_address', 'shipping_address_2', 'shipping_zipcode', 'shipping_city', 'shipping_country_id', 'shipping_pre_phone_id', 'shipping_phone',
'birthday', 'website', 'facebook', 'facebook_fanpage', 'instagram', 'bank_owner', 'bank_iban', 'bank_bic', 'notice'
'm_account',
'm_salutation',
'm_first_name',
'm_last_name',
'm_notes',
'company',
'salutation',
'first_name',
'last_name',
'address',
'address_2',
'zipcode',
'city',
'country_id',
'pre_phone_id',
'phone',
'pre_mobil_id',
'mobil',
'tax_number',
'tax_identification_number',
'taxable_sales',
'same_as_billing',
'shipping_salutation',
'shipping_company',
'shipping_firstname',
'shipping_lastname',
'shipping_address',
'shipping_address_2',
'shipping_zipcode',
'shipping_city',
'shipping_country_id',
'shipping_pre_phone_id',
'shipping_phone',
'shipping_postnumber',
'birthday',
'website',
'facebook',
'facebook_fanpage',
'instagram',
'bank_owner',
'bank_iban',
'bank_bic',
'notice'
];
//'reverse_charge', 'reverse_charge_valid'
@ -185,85 +224,100 @@ class UserAccount extends Model
public function getBirthdayAttribute($value)
{
if(!$value){
if (!$value) {
return "";
}
return Carbon::parse($value)->format(\Util::formatDateDB());
}
public function setBirthdayAttribute( $value ) {
public function setBirthdayAttribute($value)
{
$this->attributes['birthday'] = isset($value) ? (new Carbon($value))->format('Y-m-d') : NULL;
}
public function getDataProtectionFormat(){
if(!$this->attributes['data_protection']){ return ""; }
public function getDataProtectionFormat()
{
if (!$this->attributes['data_protection']) {
return "";
}
return Carbon::parse($this->attributes['data_protection'])->format(\Util::formatDateTimeDB());
}
public function getAcceptContractFormat(){
if(!$this->attributes['accept_contract']){ return ""; }
public function getAcceptContractFormat()
{
if (!$this->attributes['accept_contract']) {
return "";
}
return Carbon::parse($this->attributes['accept_contract'])->format(\Util::formatDateTimeDB());
}
public function getReverseChargeValidFormat(){
if(!$this->attributes['reverse_charge_valid']){ return ""; }
public function getReverseChargeValidFormat()
{
if (!$this->attributes['reverse_charge_valid']) {
return "";
}
return Carbon::parse($this->attributes['reverse_charge_valid'])->format(\Util::formatDateTimeDB());
}
public function getCountryAttrAs($attr, $as = false){
if($this->country){
public function getCountryAttrAs($attr, $as = false)
{
if ($this->country) {
$val = $this->country->getAttrByKey($attr);
if($val){
if($as){
if ($val) {
if ($as) {
return $as;
}
return true;
}
}
return "";
}
public function setNotice($key, $value){
public function setNotice($key, $value)
{
$notice = $this->notice;
$notice[$key] = $value;
$this->notice = $notice;
$this->save();
}
public function getNotice($key){
public function getNotice($key)
{
return isset($this->notice[$key]) ? $this->notice[$key] : false;
}
public function getPhoneNumber(){
if($this->mobil && $this->mobil !== ""){
return ($this->pre_mobil ? $this->pre_mobil->phone : '')." ".$this->mobil;
public function getPhoneNumber()
{
if ($this->mobil && $this->mobil !== "") {
return ($this->pre_mobil ? $this->pre_mobil->phone : '') . " " . $this->mobil;
}
if($this->phone && $this->phone !== ""){
return ($this->pre_phone ? $this->pre_phone->phone : '')." ".$this->phone;
if ($this->phone && $this->phone !== "") {
return ($this->pre_phone ? $this->pre_phone->phone : '') . " " . $this->phone;
}
}
}
public function getPhoneFull(){
if($this->phone && $this->phone !== ""){
return ($this->pre_phone ? $this->pre_phone->phone : '')." ".$this->phone;
public function getPhoneFull()
{
if ($this->phone && $this->phone !== "") {
return ($this->pre_phone ? $this->pre_phone->phone : '') . " " . $this->phone;
}
return "";
}
}
public function getMobilFull(){
if($this->mobil && $this->mobil !== ""){
return ($this->pre_mobil ? $this->pre_mobil->phone : '')." ".$this->mobil;
public function getMobilFull()
{
if ($this->mobil && $this->mobil !== "") {
return ($this->pre_mobil ? $this->pre_mobil->phone : '') . " " . $this->mobil;
}
return "";
}
}
public function getShippingPhoneFull(){
if($this->shipping_phone && $this->shipping_phone !== ""){
return ($this->shipping_pre_phone ? $this->shipping_pre_phone->phone : '')." ".$this->shipping_phone;
public function getShippingPhoneFull()
{
if ($this->shipping_phone && $this->shipping_phone !== "") {
return ($this->shipping_pre_phone ? $this->shipping_pre_phone->phone : '') . " " . $this->shipping_phone;
}
return "";
}
}
}

View file

@ -137,25 +137,29 @@ class UserBusiness extends Model
'm_level_id' => 'int',
'active_account' => 'bool',
'm_account' => 'int',
'sales_volume_KP_points' => 'int',
'sales_volume_TP_points' => 'int',
'sales_volume_points_shop' => 'int',
'sales_volume_points_KP_sum' => 'int',
'sales_volume_points_TP_sum' => 'int',
'sales_volume_KP_points' => 'float',
'sales_volume_TP_points' => 'float',
'sales_volume_points_shop' => 'float',
'sales_volume_points_KP_sum' => 'float',
'sales_volume_points_TP_sum' => 'float',
'sales_volume_total' => 'float',
'sales_volume_total_shop' => 'float',
'sales_volume_total_sum' => 'float',
'payline_points' => 'int',
'payline_points_qual_kp' => 'int',
'active_growth_bonus' => 'float',
'payline_points' => 'float',
'payline_points_qual_kp' => 'float',
'margin' => 'float',
'margin_shop' => 'float',
'qual_kp' => 'int',
'qual_pp' => 'int',
'calc_qual_kp' => 'int',
'total_pp' => 'int',
'total_qual_pp' => 'int',
'commission_pp_total' => 'float',
'commission_growth_total' => 'float',
'growth_bonus_details' => 'array',
'commission_shop_sales' => 'float',
'active_growth_bonus' => 'float',
'qual_user_level' => 'array',
'qual_user_level_next' => 'array',
'next_qual_user_level' => 'array',
@ -202,15 +206,18 @@ class UserBusiness extends Model
'margin_shop',
'qual_kp',
'qual_pp',
'calc_qual_kp',
'qual_user_level',
'qual_user_level_next',
'next_qual_user_level',
'next_can_user_level',
'total_pp',
'total_qual_pp',
'active_growth_bonus',
'commission_shop_sales',
'commission_pp_total',
'commission_growth_total',
'growth_bonus_details',
'business_lines',
'user_items',
'version',
@ -220,29 +227,66 @@ class UserBusiness extends Model
{
return $this->belongsTo(User::class);
}
public function user_business_structure()
{
return $this->belongsTo(UserBusinessStructure::class, 'b_structure_id');
}
public function isSave(){
public function isSave()
{
return $this->id !== null ? true : false;
}
public function setPaymentAccountDateAttribute( $value ) {
$this->attributes['payment_account_date'] = isset($value) ? (new Carbon($value))->format('Y-m-d') : NULL;
}
public function setPaymentAccountDateAttribute($value)
{
$this->attributes['payment_account_date'] = isset($value) ? (new Carbon($value))->format('Y-m-d') : NULL;
}
public function setActiveDateAttribute( $value ) {
$this->attributes['active_date'] = isset($value) ? (new Carbon($value))->format('Y-m-d') : NULL;
}
public function setActiveDateAttribute($value)
{
$this->attributes['active_date'] = isset($value) ? (new Carbon($value))->format('Y-m-d') : NULL;
}
public function getSalesVolumeTotalMargin(){
public function getSalesVolumeTotalMargin()
{
return $this->sales_volume_total / 100 * $this->margin;
}
// Formatted Points Getter
public function getFormattedSalesVolumeKPPoints()
{
return isset($this->attributes['sales_volume_KP_points']) ? formatNumber($this->attributes['sales_volume_KP_points']) : "";
}
public function getFormattedSalesVolumeTPPoints()
{
return isset($this->attributes['sales_volume_TP_points']) ? formatNumber($this->attributes['sales_volume_TP_points']) : "";
}
public function getFormattedSalesVolumePointsShop()
{
return isset($this->attributes['sales_volume_points_shop']) ? formatNumber($this->attributes['sales_volume_points_shop']) : "";
}
public function getFormattedSalesVolumePointsKPSum()
{
return isset($this->attributes['sales_volume_points_KP_sum']) ? formatNumber($this->attributes['sales_volume_points_KP_sum']) : "";
}
public function getFormattedSalesVolumePointsTPSum()
{
return isset($this->attributes['sales_volume_points_TP_sum']) ? formatNumber($this->attributes['sales_volume_points_TP_sum']) : "";
}
public function getFormattedPaylinePoints()
{
return isset($this->attributes['payline_points']) ? formatNumber($this->attributes['payline_points']) : "";
}
public function getFormattedPaylinePointsQualKp()
{
return isset($this->attributes['payline_points_qual_kp']) ? formatNumber($this->attributes['payline_points_qual_kp']) : "";
}
}

View file

@ -69,7 +69,25 @@ class UserLevel extends Model
protected $table = 'user_levels';
protected $fillable = [
'next_id', 'name', 'margin', 'margin_shop', 'qual_kp', 'qual_pp', 'growth_bonus', 'pr_line_1', 'pr_line_2', 'pr_line_3', 'pr_line_4', 'pr_line_5', 'pr_line_6', 'pr_line_7', 'pr_line_8', 'paylines', 'pos', 'active', 'default',
'next_id',
'name',
'margin',
'margin_shop',
'qual_kp',
'qual_pp',
'growth_bonus',
'pr_line_1',
'pr_line_2',
'pr_line_3',
'pr_line_4',
'pr_line_5',
'pr_line_6',
'pr_line_7',
'pr_line_8',
'paylines',
'pos',
'active',
'default',
];
@ -83,15 +101,16 @@ class UserLevel extends Model
return $this->hasMany(TransUserLevel::class, 'user_level_id');
}
public function getNextUserLevels(){
public function getNextUserLevels()
{
//$ret = [0=>'Keinen'];
$ret = UserLevel::where('active', true)->where('id', '!=', $this->id)->orderBy('pos', 'asc')->get()->pluck('name', 'id')->toArray();
return [0 => '-> Keinen Karriere Level'] + $ret;
}
public function setPosAttribute($value){
public function setPosAttribute($value)
{
$this->attributes['pos'] = is_numeric($value) ? $value : null;
}
public function setGrowthBonusAttribute($value)
@ -100,7 +119,7 @@ class UserLevel extends Model
}
public function getFormattedGrowthBonus()
{
return isset($this->attributes['growth_bonus']) ? Util::formatNumber($this->attributes['growth_bonus'],1) : "";
return isset($this->attributes['growth_bonus']) ? Util::formatNumber($this->attributes['growth_bonus'], 2) : "";
}
public function getFormattedMargin()
@ -112,7 +131,7 @@ class UserLevel extends Model
{
return isset($this->attributes['margin_shop']) ? Util::formatNumber($this->attributes['margin_shop'], 1) : "";
}
public function getLang($key)
{
$lang = \App::getLocale();
@ -125,9 +144,7 @@ class UserLevel extends Model
public function getTrans($key, $lang)
{
$trans = $this->translations->where('language','=', $lang)->where('key', $key)->first();
$trans = $this->translations->where('language', '=', $lang)->where('key', $key)->first();
return $trans ? $trans->value : '';
}
}

View file

@ -79,10 +79,10 @@ class UserSalesVolume extends Model
'user_invoice_id' => 'int',
'month' => 'int',
'year' => 'int',
'points' => 'int',
'month_KP_points' => 'int',
'month_TP_points' => 'int',
'month_shop_points' => 'int',
'points' => 'float',
'month_KP_points' => 'float',
'month_TP_points' => 'float',
'month_shop_points' => 'float',
'status_points' => 'int',
'status_turnover' => 'int',
'total_net' => 'float',
@ -120,34 +120,34 @@ class UserSalesVolume extends Model
public static $statusPointsTypes = [
1 => 'KU + TP', //Eigene + Team
2 => 'KU', //nur Eigene nicht Team
];
1 => 'KU + TP', //Eigene + Team
2 => 'KU', //nur Eigene nicht Team
];
public static $statusTurnoverTypes = [
1 => 'advisor_order', //hinzugefügt aus
2 => 'shoporder', //hinzugefügt aus
];
1 => 'advisor_order', //hinzugefügt aus
2 => 'shoporder', //hinzugefügt aus
];
public static $statusTypes = [
0 => 'not_assigned',
1 => 'advisor_order', //hinzugefügt aus
2 => 'shoporder', //hinzugefügt aus
3 => 'shoporder_pending', //hinzugefügt aus
0 => 'not_assigned',
1 => 'advisor_order', //hinzugefügt aus
2 => 'shoporder', //hinzugefügt aus
3 => 'shoporder_pending', //hinzugefügt aus
4 => 'credit', //hinzugefügt aus
5 => 'registration', //hinzugefügt aus
// 10 => ''
];
// 10 => ''
];
public static $statusColors = [
0 => 'warning',
0 => 'warning',
1 => 'success',
2 => 'secondary',
2 => 'secondary',
3 => 'warning',
4 => 'info',
5 => 'info',
10 => 'danger',
];
];
public function shopping_order()
{
@ -164,110 +164,168 @@ class UserSalesVolume extends Model
return $this->belongsTo(UserInvoice::class);
}
public function getDateAttribute(){
return $this->attributes['date'] ? Carbon::parse($this->attributes['date'])->format(\Util::formatDateDB()) : '';
}
public function setDateAttribute( $value ) {
$this->attributes['date'] = isset($value) ? (new Carbon($value))->format('Y-m-d') : NULL;
}
public function getDateRaw(){
return isset($this->attributes['date']) ? $this->attributes['date'] : NULL;
}
public function getDateAttribute()
{
return $this->attributes['date'] ? Carbon::parse($this->attributes['date'])->format(\Util::formatDateDB()) : '';
}
public function setDateAttribute($value)
{
$this->attributes['date'] = isset($value) ? (new Carbon($value))->format('Y-m-d') : NULL;
}
public function getDateRaw()
{
return isset($this->attributes['date']) ? $this->attributes['date'] : NULL;
}
public function getPointsKPSum(){
// Points Setter/Getter für deutsches Zahlenformat
public function setPointsAttribute($value)
{
$this->attributes['points'] = $value !== null ? \Util::reFormatNumber($value) : null;
}
public function setMonthKPPointsAttribute($value)
{
$this->attributes['month_KP_points'] = $value !== null ? \Util::reFormatNumber($value) : null;
}
public function setMonthTPPointsAttribute($value)
{
$this->attributes['month_TP_points'] = $value !== null ? \Util::reFormatNumber($value) : null;
}
public function setMonthShopPointsAttribute($value)
{
$this->attributes['month_shop_points'] = $value !== null ? \Util::reFormatNumber($value) : null;
}
public function getFormattedPoints()
{
return isset($this->attributes['points']) ? \Util::formatNumber($this->attributes['points']) : "";
}
public function getFormattedMonthKPPoints()
{
return isset($this->attributes['month_KP_points']) ? \Util::formatNumber($this->attributes['month_KP_points']) : 0;
}
public function getFormattedMonthTPPoints()
{
return isset($this->attributes['month_TP_points']) ? \Util::formatNumber($this->attributes['month_TP_points']) : 0;
}
public function getFormattedMonthShopPoints()
{
return isset($this->attributes['month_shop_points']) ? \Util::formatNumber($this->attributes['month_shop_points']) : 0;
}
public function getPointsKPSum()
{
return $this->month_KP_points + $this->month_shop_points; //only KP für SUM - KP is for User
}
public function getPointsTPSum(){
public function getPointsTPSum()
{
return $this->month_TP_points + $this->month_shop_points; //only TP für SUM - TP is only for Payline
}
public function getTotalNetSum(){
public function getTotalNetSum()
{
return $this->month_total_net + $this->month_shop_total_net;
}
public function getStatusType(){
return isset(self::$statusTypes[$this->status]) ? __('payment.'.self::$statusTypes[$this->status]) : "";
}
public static function getTransStatusType(){
public function getStatusType()
{
return isset(self::$statusTypes[$this->status]) ? __('payment.' . self::$statusTypes[$this->status]) : "";
}
public static function getTransStatusType()
{
$ret = [];
foreach(self::$statusTypes as $key=>$val){
$ret[$key] = trans('payment.'.$val);
foreach (self::$statusTypes as $key => $val) {
$ret[$key] = trans('payment.' . $val);
}
return $ret;
}
}
public static function getTransTurnoverTypes(){
public static function getTransTurnoverTypes()
{
$ret = [];
foreach(self::$statusTurnoverTypes as $key=>$val){
$ret[$key] = trans('payment.'.$val);
foreach (self::$statusTurnoverTypes as $key => $val) {
$ret[$key] = trans('payment.' . $val);
}
return $ret;
}
}
public function getStatusColor(){
return isset(self::$statusColors[$this->status]) ? self::$statusColors[$this->status] : "default";
}
public function getStatusColor()
{
return isset(self::$statusColors[$this->status]) ? self::$statusColors[$this->status] : "default";
}
public function getStatusPointsType(){
return isset(self::$statusPointsTypes[$this->status_points]) ? self::$statusPointsTypes[$this->status_points] : "";
}
public function getStatusPointsColor(){
return isset(self::$statusColors[$this->status_points]) ? self::$statusColors[$this->status_points] : "default";
}
public function getStatusPointsType()
{
return isset(self::$statusPointsTypes[$this->status_points]) ? self::$statusPointsTypes[$this->status_points] : "";
}
public function getStatusPointsColor()
{
return isset(self::$statusColors[$this->status_points]) ? self::$statusColors[$this->status_points] : "default";
}
public function getStatusTurnoverType(){
public function getStatusTurnoverType()
{
switch ($this->status) {
case 1: //Bestellung Berater
return 'E';
return 'E';
case 2: //Shop
return 'S';
case 4: //Gutschrift
if($this->status_turnover === 2){
return 'S';
}else{
if ($this->status_turnover === 2) {
return 'S';
} else {
return 'E';
}
}
case 5: //Registrierung
return 'E';
return 'E';
}
return "";
}
public function getStatusTurnoverColor(){
return "";
}
public function getStatusTurnoverColor()
{
switch ($this->status) {
case 1: //Bestellung Berater
return 'success';
return 'success';
case 2: //Shop
return 'secondary';
case 4: //Gutschrift
if($this->status_turnover === 2){
return 'secondary';
}else{
if ($this->status_turnover === 2) {
return 'secondary';
} else {
return 'success';
}
}
case 5: //Registrierung
return 'success';
return 'success';
}
return "default";
}
public function getFormatedMonthYear(){
return str_pad($this->month, 2, "0", STR_PAD_LEFT)."/".$this->year;
return "default";
}
public function isCurrentMonthYear(){
if($this->month === intval(date('m')) && $this->year === intval(date('Y'))){
public function getFormatedMonthYear()
{
return str_pad($this->month, 2, "0", STR_PAD_LEFT) . "/" . $this->year;
}
public function isCurrentMonthYear()
{
if ($this->month === intval(date('m')) && $this->year === intval(date('Y'))) {
return true;
}
return false;
}
public function caluCommissonTotalNet($margin){
if($this->total_net > 0 && $margin > 0){
public function caluCommissonTotalNet($margin)
{
if ($this->total_net > 0 && $margin > 0) {
return $this->total_net / 100 * $margin;
}
return 0;
}
}
}