Custom Price / Land / User Order Homeparty
This commit is contained in:
parent
d46824a4ac
commit
51d81d8ec6
55 changed files with 1951 additions and 681 deletions
|
|
@ -128,10 +128,12 @@ class Product extends Model
|
|||
'trans_description' => 'array',
|
||||
'trans_usage' => 'array',
|
||||
'trans_ingredients' => 'array',
|
||||
'show_on' => 'array',
|
||||
'action' => 'array',
|
||||
'wp_number' => 'int',
|
||||
'shipping_addon' => 'bool',
|
||||
'active' => 'bool'
|
||||
'active' => 'bool',
|
||||
'no_commission' => 'bool',
|
||||
];
|
||||
use Sluggable;
|
||||
|
||||
|
|
@ -149,6 +151,7 @@ class Product extends Model
|
|||
'price_old',
|
||||
'points',
|
||||
'weight',
|
||||
'no_commission',
|
||||
'contents',
|
||||
'contents_total',
|
||||
'unit',
|
||||
|
|
@ -162,6 +165,7 @@ class Product extends Model
|
|||
'amount',
|
||||
'active',
|
||||
'show_at',
|
||||
'show_on',
|
||||
'shipping_addon',
|
||||
'identifier',
|
||||
'action',
|
||||
|
|
@ -175,8 +179,6 @@ class Product extends Model
|
|||
'upgrade' => 'Produktupgrade zur Produkt ID',
|
||||
'upgrade_member' => 'Beraterupgrade zur Karriere ID',
|
||||
'proportional_voucher' => 'Anteiliger Gutschein Berater',
|
||||
|
||||
|
||||
];
|
||||
public $unitTypes = [
|
||||
0 => '',
|
||||
|
|
@ -195,7 +197,16 @@ class Product extends Model
|
|||
5 => 'Onboarding Berater',
|
||||
6 => 'Onboarding Berater + Berater Shop',
|
||||
7 => 'zur internen Berechnung',
|
||||
];
|
||||
|
||||
public $showONs = [
|
||||
1 => 'KundenShop',
|
||||
2 => 'BeraterShop',
|
||||
3 => 'Auszeitparty',
|
||||
4 => 'Registrierung Berater',
|
||||
5 => 'Mitgliedschaft Berater',
|
||||
6 => 'Onboarding Berater',
|
||||
10 => 'zur internen Berechnung',
|
||||
];
|
||||
|
||||
public $actions = [
|
||||
|
|
@ -262,19 +273,19 @@ class Product extends Model
|
|||
|
||||
public function setPriceAttribute( $value ) {
|
||||
|
||||
$this->attributes['price'] = $value ? Util::reFormatNumber($value) : null;
|
||||
$this->attributes['price'] = $value !== null ? Util::reFormatNumber($value) : null;
|
||||
}
|
||||
public function setPriceEkAttribute( $value ) {
|
||||
|
||||
$this->attributes['price_ek'] = $value ? Util::reFormatNumber($value) : null;
|
||||
$this->attributes['price_ek'] = $value !== null ? Util::reFormatNumber($value) : null;
|
||||
}
|
||||
public function setTaxAttribute( $value ) {
|
||||
|
||||
$this->attributes['tax'] = $value ? Util::reFormatNumber($value) : null;
|
||||
$this->attributes['tax'] = $value !== null ? Util::reFormatNumber($value) : null;
|
||||
}
|
||||
public function setPriceOldAttribute( $value ) {
|
||||
|
||||
$this->attributes['price_old'] = $value ? Util::reFormatNumber($value) : null;
|
||||
$this->attributes['price_old'] = $value !== null ? Util::reFormatNumber($value) : null;
|
||||
}
|
||||
|
||||
public function getFormattedPrice()
|
||||
|
|
@ -287,10 +298,6 @@ class Product extends Model
|
|||
return isset($this->attributes['price_ek']) ? Util::formatNumber($this->attributes['price_ek']) : "";
|
||||
}
|
||||
|
||||
public function getFormattedTax()
|
||||
{
|
||||
return isset($this->attributes['tax']) ? Util::formatNumber($this->attributes['tax'], 0) : "";
|
||||
}
|
||||
|
||||
public function getFormattedPriceOld()
|
||||
{
|
||||
|
|
@ -299,6 +306,9 @@ class Product extends Model
|
|||
|
||||
/*price by user Factor*/
|
||||
private function calcPriceUserFactor($price){
|
||||
if($this->no_commission){
|
||||
return $price;
|
||||
}
|
||||
if(\Auth::user() && \Auth::user()->user_level){
|
||||
$margin = ((\Auth::user()->user_level->margin -100)*-1) / 100;
|
||||
$price = $price * $margin;
|
||||
|
|
@ -306,24 +316,36 @@ class Product extends Model
|
|||
return $price;
|
||||
}
|
||||
/*price net*/
|
||||
private function calcPriceNet($price){
|
||||
$tax_rate = ($this->attributes['tax'] + 100) / 100;
|
||||
|
||||
private function calcPriceNet($price, $country=null){
|
||||
$tax = $this->getTaxWith($country);
|
||||
$tax_rate = ($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;
|
||||
public function getPriceWith(Bool $net = true, Bool $ufactor = true, $country = null){
|
||||
$price = isset($this->attributes['price']) ? $this->attributes['price'] : null;
|
||||
$cprice = $country ? $this->getCPrice($country) : null;
|
||||
$price = $cprice ? $cprice : $price;
|
||||
$price = $net ? $this->calcPriceNet($price, $country) : $price;
|
||||
$price = $ufactor ? $this->calcPriceUserFactor($price) : $price;
|
||||
return round($price, 2);
|
||||
}
|
||||
/*out*/
|
||||
public function getFormattedPriceWith(Bool $net = true, Bool $ufactor = true)
|
||||
{
|
||||
return isset($this->attributes['price']) ? Util::formatNumber($this->getPriceWith($net, $ufactor)) : "";
|
||||
public function getFormattedPriceWith(Bool $net = true, Bool $ufactor = true, $country = null)
|
||||
{
|
||||
return isset($this->attributes['price']) ? Util::formatNumber($this->getPriceWith($net, $ufactor, $country)) : "";
|
||||
}
|
||||
|
||||
public function getTaxWith($country = null){
|
||||
$tax = isset($this->attributes['tax']) ? $this->attributes['tax'] : null;
|
||||
$ctax = $country ? $this->getCTax($country) : null;
|
||||
return $ctax !== null ? $ctax : $tax;
|
||||
}
|
||||
|
||||
public function getFormattedTax($country = null)
|
||||
{
|
||||
return isset($this->attributes['tax']) ? Util::formatNumber($this->getTaxWith($country), 0) : "";
|
||||
}
|
||||
|
||||
public function getBasePriceFormattedFull(){
|
||||
if($price = $this->getBasePrice()){
|
||||
|
|
@ -368,6 +390,14 @@ class Product extends Model
|
|||
return isset($this->showATs[$this->show_at]) ? $this->showATs[$this->show_at] : '-';
|
||||
}
|
||||
|
||||
public function getShowOnTypes(){
|
||||
$ret = [];
|
||||
foreach($this->show_on as $show){
|
||||
$ret[] = isset($this->showONs[$show]) ? $this->showONs[$show] : '-';
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
public function setPosAttribute($value){
|
||||
$this->attributes['pos'] = is_numeric($value) ? $value : null;
|
||||
|
|
@ -403,29 +433,40 @@ class Product extends Model
|
|||
return rtrim($ret, ', ');
|
||||
}
|
||||
|
||||
public function getCountryPrice($country_id){
|
||||
return $this->country_prices->where('country_id', '=', $country_id)->first() ?: new CountryPrice();
|
||||
public function getCountryPrice(Country $country){
|
||||
if($country->own_eur){
|
||||
return $this->country_prices->where('country_id', '=', $country->id)->first() ?: new CountryPrice();
|
||||
}
|
||||
return new CountryPrice();
|
||||
}
|
||||
|
||||
public function getCPrice($country_id){
|
||||
return $this->getCountryPrice($country_id)->c_price;
|
||||
public function getCPrice(Country $country){
|
||||
return $this->getCountryPrice($country)->c_price;
|
||||
}
|
||||
public function getCTax($country_id){
|
||||
return $this->getCountryPrice($country_id)->c_tax;
|
||||
public function getCTax(Country $country){
|
||||
return $this->getCountryPrice($country)->c_tax;
|
||||
}
|
||||
public function getCPriceOld($country_id){
|
||||
return $this->getCountryPrice($country_id)->c_price_old;
|
||||
public function getCPriceOld(Country $country){
|
||||
return $this->getCountryPrice($country)->c_price_old;
|
||||
}
|
||||
public function getCCurrency($country_id){
|
||||
return $this->getCountryPrice($country_id)->c_currency;
|
||||
public function getCCurrency(Country $country){
|
||||
return $this->getCountryPrice($country)->c_currency;
|
||||
}
|
||||
|
||||
public function getRealPrice(Country $country){
|
||||
if($country->own_eur && $this->getCPrice($country->id)){
|
||||
return $this->getCPrice($country->id);
|
||||
if($country->own_eur && $this->getCPrice($country)){
|
||||
return $this->getCPrice($country);
|
||||
}
|
||||
return $this->price;
|
||||
}
|
||||
|
||||
|
||||
public function getFormattedPriceCurrencyWith(Bool $net = true, Bool $ufactor = true, Country $country = null){
|
||||
$ret = "";
|
||||
if($country->currency){
|
||||
$price = $this->getPriceWith($net, $ufactor, $country);
|
||||
$ret = formatNumber($price * $country->currency_faktor)." ".$country->currency_unit;
|
||||
return '<br><span class="small">~'.$ret.'<span>';
|
||||
}
|
||||
return "" ;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue