164 lines
5.5 KiB
PHP
164 lines
5.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
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)
|
|
* @mixin \Eloquent
|
|
*/
|
|
class ShippingPrice extends Model
|
|
{
|
|
protected $table = 'shipping_prices';
|
|
|
|
protected $fillable = [
|
|
'shipping_id', 'price', 'tax_rate', 'factor', 'total_from', 'total_to', 'weight_from', 'weight_to',
|
|
];
|
|
|
|
public function shipping()
|
|
{
|
|
return $this->belongsTo('App\Models\Shipping', 'shipping_id');
|
|
}
|
|
|
|
|
|
public function _format_number($value)
|
|
{
|
|
return preg_replace("/[^0-9,]/", "", $value);
|
|
}
|
|
|
|
public function setPriceAttribute($value)
|
|
{
|
|
$value = $this->_format_number($value);
|
|
$this->attributes['price'] = floatval(str_replace(',', '.', $value));
|
|
|
|
}
|
|
|
|
public function setFactorAttribute($value)
|
|
{
|
|
$value = $this->_format_number($value);
|
|
if ($value == "") {
|
|
$this->attributes['factor'] = null;
|
|
} else {
|
|
$this->attributes['factor'] = floatval(str_replace(',', '.', $value));
|
|
}
|
|
}
|
|
|
|
public function setTaxAttribute($value)
|
|
{
|
|
$value = $this->_format_number($value);
|
|
if ($value == "") {
|
|
$this->attributes['tax_rate'] = null;
|
|
} else {
|
|
$this->attributes['tax_rate'] = floatval(str_replace(',', '.', $value));
|
|
}
|
|
}
|
|
|
|
|
|
public function setTotalFromAttribute($value)
|
|
{
|
|
$value = $this->_format_number($value);
|
|
if ($value == "") {
|
|
$this->attributes['total_from'] = null;
|
|
} else {
|
|
$this->attributes['total_from'] = floatval(str_replace(',', '.', $value));
|
|
}
|
|
}
|
|
|
|
public function setTotalToAttribute($value)
|
|
{
|
|
$value = $this->_format_number($value);
|
|
if ($value == "") {
|
|
$this->attributes['total_to'] = null;
|
|
} else {
|
|
|
|
$this->attributes['total_to'] = floatval(str_replace(',', '.', $value));
|
|
}
|
|
}
|
|
|
|
|
|
public function getFormattedPrice()
|
|
{
|
|
if ($this->attributes['price'] === NULL) {
|
|
return $this->attributes['price'];
|
|
}
|
|
if (\App::getLocale() == "en") {
|
|
return number_format($this->attributes['price'], 2, '.', ',');
|
|
}
|
|
return number_format($this->attributes['price'], 2, ',', '.');
|
|
}
|
|
|
|
public function getFormattedTaxRate()
|
|
{
|
|
if ($this->attributes['tax_rate'] === NULL) {
|
|
return $this->attributes['tax_rate'];
|
|
}
|
|
if (\App::getLocale() == "en") {
|
|
return number_format($this->attributes['tax_rate'], 2, '.', ',');
|
|
}
|
|
return number_format($this->attributes['tax_rate'], 2, ',', '.');
|
|
}
|
|
|
|
public function getFormattedFactor()
|
|
{
|
|
if ($this->attributes['factor'] === NULL) {
|
|
return $this->attributes['factor'];
|
|
}
|
|
if (\App::getLocale() == "en") {
|
|
return number_format($this->attributes['factor'], 2, '.', ',');
|
|
}
|
|
return number_format($this->attributes['factor'], 2, ',', '.');
|
|
}
|
|
|
|
|
|
public function getFormatTotalFrom()
|
|
{
|
|
if ($this->attributes['total_from'] === NULL) {
|
|
return $this->attributes['total_from'];
|
|
}
|
|
if (\App::getLocale() == "en") {
|
|
return number_format($this->attributes['total_from'], 2, '.', ',');
|
|
}
|
|
return number_format($this->attributes['total_from'], 2, ',', '.');
|
|
}
|
|
|
|
public function getFormattedTotalTo()
|
|
{
|
|
if ($this->attributes['total_to'] === NULL) {
|
|
return $this->attributes['total_to'];
|
|
}
|
|
if (\App::getLocale() == "en") {
|
|
return number_format($this->attributes['total_to'], 2, '.', ',');
|
|
}
|
|
return number_format($this->attributes['total_to'], 2, ',', '.');
|
|
}
|
|
|
|
|
|
}
|