User Order step1

This commit is contained in:
Kevin Adametz 2020-08-07 16:02:03 +02:00
parent eb55b01b0d
commit a5db985ae8
90 changed files with 6439 additions and 421 deletions

View file

@ -103,6 +103,8 @@ use Illuminate\Database\Eloquent\SoftDeletes;
* @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)
*/
class Product extends Model
{
@ -124,7 +126,9 @@ class Product extends Model
'trans_usage' => 'array',
'trans_ingredients' => 'array',
'action' => 'array',
'wp_number' => 'int'
'wp_number' => 'int',
'shipping_addon' => 'bool',
'active' => 'bool'
];
use Sluggable;
@ -155,6 +159,7 @@ class Product extends Model
'amount',
'active',
'show_at',
'shipping_addon',
'identifier',
'action',
'upgrade_to_id'
@ -235,20 +240,20 @@ class Product extends Model
}
public function setPriceAttribute( $value ) {
$value = $this->_format_number($value);
$this->attributes['price'] = floatval(str_replace(',', '.', $value));
$this->attributes['price'] = $value ? Util::reFormatNumber($value) : null;
}
public function setPriceEkAttribute( $value ) {
$value = $this->_format_number($value);
$this->attributes['price_ek'] = floatval(str_replace(',', '.', $value));
$this->attributes['price_ek'] = $value ? Util::reFormatNumber($value) : null;
}
public function setTaxAttribute( $value ) {
$value = $this->_format_number($value);
$this->attributes['tax'] = floatval(str_replace(',', '.', $value));
$this->attributes['tax'] = $value ? Util::reFormatNumber($value) : null;
}
public function setPriceOldAttribute( $value ) {
$value = $this->_format_number($value);
$this->attributes['price_old'] = floatval(str_replace(',', '.', $value));
$this->attributes['price_old'] = $value ? Util::reFormatNumber($value) : null;
}
public function getFormattedPrice()
@ -271,6 +276,34 @@ class Product extends Model
return isset($this->attributes['price_old']) ? Util::formatNumber($this->attributes['price_old']) : "";
}
/*price by user Factor*/
private function calcPriceUserFactor($price){
if(\Auth::user() && \Auth::user()->user_level){
$margin = ((\Auth::user()->user_level->margin -100)*-1) / 100;
$price = $price * $margin;
}
return $price;
}
/*price net*/
private function calcPriceNet($price){
$tax_rate = ($this->attributes['tax'] + 100) / 100;
return $price / $tax_rate;
}
//price calu with
public function getPriceWith(Bool $net = true, Bool $ufactor = true){
$price = $this->attributes['price'];
$price = $net ? $this->calcPriceNet($price) : $price;
$price = $ufactor ? $this->calcPriceUserFactor($price) : $price;
return $price;
}
/*out*/
public function getFormattedPriceWith(Bool $net = true, Bool $ufactor = true)
{
return isset($this->attributes['price']) ? Util::formatNumber($this->getPriceWith($net, $ufactor)) : "";
}
public function getBasePriceFormattedFull(){
if($price = $this->getBasePrice()){
$unit = $this->attributes['unit'];
@ -310,6 +343,10 @@ class Product extends Model
public function getUnitType(){
return isset($this->unitTypes[$this->unit]) ? $this->unitTypes[$this->unit] : '-';
}
public function getShowAtType(){
return isset($this->showATs[$this->show_at]) ? $this->showATs[$this->show_at] : '-';
}
public function setPosAttribute($value){
$this->attributes['pos'] = is_numeric($value) ? $value : null;