|ShoppingOrder whereUserWhiteLabel($value) * * @property array|null $cancellation_invoice * * @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrder whereCancellationInvoice($value) * * @mixin \Eloquent */ class ShoppingOrder extends Model { protected $table = 'shopping_orders'; use SoftDeletes; protected $dates = ['deleted_at']; protected $fillable = [ 'shopping_user_id', 'auth_user_id', 'promotion_user_id', 'user_shop_id', 'member_id', 'payment_for', 'country_id', 'total', 'subtotal_full', 'discount', 'subtotal', 'shipping', 'shipping_net', 'subtotal_shipping', 'tax', 'total_without_credit', 'payment_credit', 'total_shipping', 'points', 'weight', 'paid', 'invoice', 'cancellation_invoice', 'delivery', 'user_white_label', 'invoice_number', 'txaction', 'wp_invoice_path', 'wp_notice', 'mode', 'shipped', 'shipped_at', 'shipping_option', 'tracking', ]; protected $casts = [ 'wp_notice' => 'array', 'invoice' => 'array', 'cancellation_invoice' => 'array', 'delivery' => 'array', 'shipped_at' => 'datetime', 'user_white_label' => 'boolean', ]; public static $shippedTypes = [ 0 => 'offen', 1 => 'in Bearbeitung', 2 => 'versendet', 3 => 'abgeschlossen', 5 => 'Wartestellung', 4 => 'Abholung', 10 => 'storniert', ]; public static $paymentForTypes = [ 0 => '', 1 => 'Registrierung', 2 => 'Mitgliedschaft', 3 => 'Guthabenaufladung', // guthaben 4 => 'VP.Bestellung Abholung', 5 => 'VP.Bestellung Lieferung', 6 => 'VP.Kundenbestellung', 7 => 'Promotion', 8 => 'Shop', 9 => '-', 10 => 'extern', 11 => '', ]; public static $paymentForColors = [ 0 => 'default', 1 => 'warning', 2 => 'warning', 3 => 'secondary', 4 => 'secondary', 5 => 'secondary', 6 => 'info', 7 => 'dark', 8 => 'info', 9 => 'default', 10 => 'info', 11 => 'default', ]; public static $apiShippedTypes = [ 0 => 'open', // (Fullfilment durch Händler)', 1 => 'process', // (Fullfilment: nicht Versand) 2 => 'sent', // (Fullfilment: Versand erfolgt)' 3 => 'close', // (Fullfilment: Versand erfolgt)', 4 => 'pick_up', // (Fullfilment: Versand erfolgt)', 10 => 'cancel', ]; public static $shippedColors = [ 0 => 'warning', 1 => 'info', 2 => 'success', 3 => 'secondary', 4 => 'success', 5 => 'warning-dark', 10 => 'danger', ]; public function shopping_user() { return $this->belongsTo('App\Models\ShoppingUser', 'shopping_user_id'); } public function country() { return $this->belongsTo('App\Models\ShippingCountry', 'country_id'); } public function shipping_country() { return $this->belongsTo('App\Models\ShippingCountry', 'country_id'); } public function promotion_user() { return $this->belongsTo('App\Models\PromotionUser', 'promotion_user_id'); } public function user_shop() { return $this->belongsTo('App\Models\UserShop', 'user_shop_id'); } // can null public function member() { return $this->belongsTo('App\User', 'member_id'); } // can null public function auth_user() { return $this->belongsTo('App\User', 'auth_user_id'); } public function user_history() { return $this->hasOne('App\Models\UserHistory', 'shopping_order_id')->latest(); } public function shopping_order_margin() { return $this->hasOne('App\Models\ShoppingOrderMargin', 'shopping_order_id')->latest(); } public function shopping_order_items() { return $this->hasMany('App\Models\ShoppingOrderItem', 'shopping_order_id'); } /** * Mindestens eine Bestellzeile mit White-Label-Produkt (Lieferschein mit Etikett-Infos). */ public function hasWhitelabelProducts(): bool { return $this->shopping_order_items() ->whereHas('product', function ($query): void { $query->where('whitelabel', true); }) ->exists(); } public function shopping_payments() { return $this->hasMany('App\Models\ShoppingPayment', 'shopping_order_id'); } public function shopping_payment_last() { return $this->hasOne('App\Models\ShoppingPayment', 'shopping_order_id')->latest(); } public function setUserHistoryValue($values = []) { if ($user_history = $this->user_history) { foreach ($values as $key => $val) { $user_history->{$key} = $val; } $user_history->save(); } } public function getLastShoppingPayment($key = false) { $shopping_payment = $this->shopping_payments->last(); if ($shopping_payment) { if ($key === 'getPaymentType') { return $shopping_payment->getPaymentType(); } if ($key === 'reference') { return $shopping_payment->reference; } } return ''; } public function getShippedType() { return isset(self::$shippedTypes[$this->shipped]) ? self::$shippedTypes[$this->shipped] : ''; } public function getAPIShippedType() { return isset(self::$apiShippedTypes[$this->shipped]) ? self::$apiShippedTypes[$this->shipped] : 'free'; } public function getShippedColor() { return isset(self::$shippedColors[$this->shipped]) ? self::$shippedColors[$this->shipped] : 'default'; } public function getPaymentForType() { return isset(self::$paymentForTypes[$this->payment_for]) ? self::$paymentForTypes[$this->payment_for] : ''; } public function getPaymentForColor() { return isset(self::$paymentForColors[$this->payment_for]) ? self::$paymentForColors[$this->payment_for] : ''; } public function getFormattedTotal() { return formatNumber($this->attributes['total']); } public function getFormattedSubtotalFull() { return formatNumber($this->attributes['subtotal_full']); } public function getFormattedSubtotal() { return formatNumber($this->attributes['subtotal']); } public function getFormattedDiscount() { return formatNumber($this->attributes['discount']); } public function getFormattedShipping() { return formatNumber($this->attributes['shipping']); } public function getFormattedShippingNet() { return formatNumber($this->attributes['shipping_net']); } public function getFormattedSubtotalShipping() { return formatNumber($this->attributes['subtotal_shipping']); } public function getFormattedTax() { return formatNumber($this->attributes['tax']); } public function getFormattedTotalWithoutCredit() { return formatNumber($this->attributes['total_without_credit']); } public function getFormattedPaymentCredit() { return formatNumber($this->attributes['payment_credit']); } public function getFormattedTotalShipping() { return formatNumber($this->attributes['total_shipping']); } public function getItemsCount() { $count = 0; if ($this->shopping_order_items) { foreach ($this->shopping_order_items as $shopping_order_item) { $count += $shopping_order_item->qty; } } return $count; } public function isInvoice() { return $this->user_invoice ? true : false; } public function isPickUp() { return $this->shipping_option === 'pick_up' ? true : false; } public function isTax() { return $this->tax > 0 ? true : false; } }