gruene-seele/app/Models/ShippingPrice.php
2025-04-01 10:39:21 +02:00

132 lines
5 KiB
PHP

<?php
namespace App\Models;
use App\Services\Util;
use Illuminate\Database\Eloquent\Model;
/**
* App\Models\ShippingPrice
*
* @property int $id
* @property int $shipping_id
* @property float|null $price
* @property float|null $tax_rate
* @property float|null $factor
* @property float|null $total_from
* @property float|null $total_to
* @property int|null $weight_from
* @property int|null $weight_to
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \App\Models\Shipping $shipping
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShippingPrice newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShippingPrice newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShippingPrice query()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShippingPrice whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShippingPrice whereFactor($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShippingPrice whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShippingPrice wherePrice($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShippingPrice whereShippingId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShippingPrice whereTax($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShippingPrice whereTotalFrom($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShippingPrice whereTotalTo($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShippingPrice whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShippingPrice whereWeightFrom($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShippingPrice whereWeightTo($value)
* @property-write mixed $tax
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShippingPrice whereTaxRate($value)
* @property float|null $price_comp
* @property int|null $num_comp
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShippingPrice whereNumComp($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShippingPrice wherePriceComp($value)
* @property int|null $shipping_for
* @method static \Illuminate\Database\Eloquent\Builder|ShippingPrice whereShippingFor($value)
* @mixin \Eloquent
*/
class ShippingPrice extends Model
{
protected $table = 'shipping_prices';
protected $fillable = [
'shipping_id', 'price', 'price_comp', 'num_comp', 'tax_rate', 'factor', 'total_from', 'total_to', 'weight_from', 'weight_to', 'shipping_for',
];
public static $shippingForTypes = [
1 => 'Berater Bestellungen',
2 => 'Promotion Bestellungen',
3 => 'Shop Bestellungen',
];
public function shipping()
{
return $this->belongsTo('App\Models\Shipping', 'shipping_id');
}
public function getShippingForType(){
return isset(self::$shippingForTypes[$this->shipping_for]) ? self::$shippingForTypes[$this->shipping_for] : "";
}
public function setPriceAttribute($value)
{
$this->attributes['price'] = $value ? Util::reFormatNumber($value) : null;
}
public function setPriceCompAttribute($value)
{
$this->attributes['price_comp'] = $value ? Util::reFormatNumber($value) : null;
}
public function setFactorAttribute($value)
{
$this->attributes['factor'] = $value ? Util::reFormatNumber($value) : null;
}
public function setTaxRateAttribute($value)
{
$this->attributes['tax_rate'] = $value ? Util::reFormatNumber($value) : null;
}
public function setTotalFromAttribute($value)
{
$this->attributes['total_from'] = $value ? Util::reFormatNumber($value) : null;
}
public function setTotalToAttribute($value)
{
$this->attributes['total_to'] = $value ? Util::reFormatNumber($value) : null;
}
public function getFormattedPrice()
{
return isset($this->attributes['price']) ? Util::formatNumber($this->attributes['price']) : "";
}
public function getFormattedPriceComp()
{
return isset($this->attributes['price_comp']) ? Util::formatNumber($this->attributes['price_comp']) : "";
}
public function getFormattedTaxRate()
{
return isset($this->attributes['tax_rate']) ? Util::formatNumber($this->attributes['tax_rate']) : "";
}
public function getFormattedFactor()
{
return isset($this->attributes['factor']) ? Util::formatNumber($this->attributes['factor']) : "";
}
public function getFormatTotalFrom()
{
return isset($this->attributes['total_from']) ? Util::formatNumber($this->attributes['total_from']) : "";
}
public function getFormattedTotalTo()
{
return isset($this->attributes['total_to']) ? Util::formatNumber($this->attributes['total_to']) : "";
}
}