216 lines
6.6 KiB
PHP
216 lines
6.6 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Created by Reliese Model.
|
|
*/
|
|
|
|
namespace App\Models;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* Class HomepartyUserOrderItem
|
|
*
|
|
* @property int $id
|
|
* @property int $homeparty_id
|
|
* @property int $homeparty_user_id
|
|
* @property int $product_id
|
|
* @property int $qty
|
|
* @property float $price
|
|
* @property float $price_net
|
|
* @property float $tax_rate
|
|
* @property int $points
|
|
* @property float $margin
|
|
* @property float $ek-price
|
|
* @property string $slug
|
|
* @property Carbon $created_at
|
|
* @property Carbon $updated_at
|
|
* @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()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUserOrderItem whereCreatedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUserOrderItem whereEkPrice($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUserOrderItem whereHomepartyId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUserOrderItem whereHomepartyUserId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUserOrderItem whereId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUserOrderItem whereMargin($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUserOrderItem wherePoints($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUserOrderItem wherePrice($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUserOrderItem wherePriceNet($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUserOrderItem whereProductId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUserOrderItem whereQty($value)
|
|
* @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)
|
|
* @mixin \Eloquent
|
|
*/
|
|
class HomepartyUserOrderItem extends Model
|
|
{
|
|
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 $fillable = [
|
|
'homeparty_id',
|
|
'homeparty_user_id',
|
|
'product_id',
|
|
'qty',
|
|
'price',
|
|
'price_net',
|
|
'tax_rate',
|
|
'points',
|
|
'margin',
|
|
'ek-price',
|
|
'ek-price_net',
|
|
'slug'
|
|
];
|
|
|
|
public function homeparty()
|
|
{
|
|
return $this->belongsTo(Homeparty::class);
|
|
}
|
|
|
|
public function homeparty_user()
|
|
{
|
|
return $this->belongsTo(HomepartyUser::class);
|
|
}
|
|
|
|
public function product()
|
|
{
|
|
return $this->belongsTo(Product::class);
|
|
}
|
|
|
|
public function getFormattedPrice()
|
|
{
|
|
return formatNumber($this->attributes['price']);
|
|
}
|
|
|
|
public function getFormattedTotalPrice()
|
|
{
|
|
return formatNumber($this->attributes['price'] * $this->attributes['qty']);
|
|
}
|
|
|
|
public function getFormattedPriceNet()
|
|
{
|
|
return formatNumber($this->attributes['price_net']);
|
|
}
|
|
|
|
public function getFormattedTotalPriceNet()
|
|
{
|
|
return formatNumber($this->attributes['price_net'] * $this->attributes['qty']);
|
|
}
|
|
|
|
public function getFormattedEKPrice()
|
|
{
|
|
return formatNumber($this->attributes['ek-price']);
|
|
}
|
|
|
|
public function getFormattedTotalEKPrice()
|
|
{
|
|
return formatNumber($this->attributes['ek-price'] * $this->attributes['qty']);
|
|
}
|
|
|
|
public function getFormattedEKPriceNet()
|
|
{
|
|
return formatNumber($this->attributes['ek-price_net']);
|
|
}
|
|
|
|
public function getFormattedTotalEKPriceNet()
|
|
{
|
|
return formatNumber($this->attributes['ek-price_net'] * $this->attributes['qty']);
|
|
}
|
|
|
|
public function getFormattedIncomePrice()
|
|
{
|
|
return formatNumber($this->attributes['price'] - $this->attributes['ek-price']);
|
|
}
|
|
|
|
public function getFormattedTotalIncomePrice()
|
|
{
|
|
return formatNumber(($this->attributes['price'] - $this->attributes['ek-price']) * $this->attributes['qty']);
|
|
}
|
|
|
|
public function getFormattedTotalPoints()
|
|
{
|
|
return formatNumber($this->attributes['points'] * $this->attributes['qty'], 0);
|
|
}
|
|
|
|
public function getTotalPrice()
|
|
{
|
|
return (float) ($this->attributes['price'] * $this->attributes['qty']);
|
|
}
|
|
|
|
|
|
public function getTotalPoints()
|
|
{
|
|
return ($this->attributes['points'] * $this->attributes['qty']);
|
|
}
|
|
|
|
public function geTotalPriceNet()
|
|
{
|
|
return (float) ($this->attributes['price_net'] * $this->attributes['qty']);
|
|
}
|
|
|
|
public function geTotalEKPrice()
|
|
{
|
|
return (float) ($this->attributes['ek-price'] * $this->attributes['qty']);
|
|
}
|
|
|
|
public function geTotalEKPriceNet()
|
|
{
|
|
return (float) ($this->attributes['ek-price_net'] * $this->attributes['qty']);
|
|
}
|
|
|
|
public function getIncomePrice()
|
|
{
|
|
return (float) ($this->attributes['price'] - $this->attributes['ek-price']);
|
|
}
|
|
|
|
public function geTotalIncomePrice()
|
|
{
|
|
return (float) (($this->attributes['price'] - $this->attributes['ek-price']) * $this->attributes['qty']);
|
|
}
|
|
|
|
|
|
public function getCurrencyByKey($key)
|
|
{
|
|
$rNumber = 0;
|
|
if($this->homeparty && $this->homeparty->isPriceCurrency()){
|
|
$user_country = $this->homeparty->getUserCountry();
|
|
$faktor = isset($user_country->currency_faktor) ? $user_country->currency_faktor : 1;
|
|
switch ($key) {
|
|
case 'TotalIncomePrice':
|
|
$rNumber = $this->geTotalIncomePrice() * $faktor;
|
|
break;
|
|
case 'TotalPrice':
|
|
$rNumber = $this->getTotalPrice() * $faktor;
|
|
break;
|
|
case 'TotalEKPrice':
|
|
$rNumber = $this->geTotalEKPrice() * $faktor;
|
|
break;
|
|
|
|
}
|
|
}
|
|
|
|
return formatNumber($rNumber);
|
|
}
|
|
}
|
|
|