Custom Price / Land / User Order Homeparty
This commit is contained in:
parent
d46824a4ac
commit
51d81d8ec6
55 changed files with 1951 additions and 681 deletions
|
|
@ -7,8 +7,10 @@
|
|||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use App\Models\Country;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use PHPUnit\Framework\Constraint\Count;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
/**
|
||||
* Class Homeparty
|
||||
|
|
@ -66,12 +68,15 @@ class Homeparty extends Model
|
|||
'pos' => 'int',
|
||||
'completed' => 'int',
|
||||
'status' => 'int',
|
||||
'step' => 'int',
|
||||
'country_id' => 'int',
|
||||
'order_to' => 'bool',
|
||||
'active' => 'bool',
|
||||
'default' => 'bool',
|
||||
'token_active' => 'bool',
|
||||
'settings' => 'array',
|
||||
'order' => 'array'
|
||||
'order' => 'array',
|
||||
'card_info' => 'array',
|
||||
];
|
||||
|
||||
protected $dates = [
|
||||
|
|
@ -87,24 +92,33 @@ class Homeparty extends Model
|
|||
'date',
|
||||
'name',
|
||||
'place',
|
||||
'country_id',
|
||||
'description',
|
||||
'pos',
|
||||
'completed',
|
||||
'status',
|
||||
'step',
|
||||
'order_to',
|
||||
'active',
|
||||
'default',
|
||||
'token',
|
||||
'token_active',
|
||||
'settings',
|
||||
'order'
|
||||
'order',
|
||||
'card_info'
|
||||
];
|
||||
private $user_country;
|
||||
|
||||
public function auth_user()
|
||||
{
|
||||
return $this->belongsTo('App\User', 'auth_user_id');
|
||||
}
|
||||
|
||||
public function country()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Country', 'country_id');
|
||||
}
|
||||
|
||||
public function homeparty_users()
|
||||
{
|
||||
return $this->hasMany('App\Models\HomepartyUser', 'homeparty_id');
|
||||
|
|
@ -141,5 +155,32 @@ class Homeparty extends Model
|
|||
public function getTokenLink(){
|
||||
return url('homeparty/'.$this->token);
|
||||
}
|
||||
|
||||
public function getCardInfo($key)
|
||||
{
|
||||
return isset($this->card_info[$key]) ? $this->card_info[$key] : null;
|
||||
}
|
||||
|
||||
public function getUserCountry(){
|
||||
if(!$this->user_country){
|
||||
if($user_country_id = $this->getCardInfo('user_country_id')){
|
||||
$this->user_country = Country::findOrFail($user_country_id);
|
||||
}
|
||||
}
|
||||
return $this->user_country;
|
||||
}
|
||||
|
||||
public function isPriceCurrency()
|
||||
{
|
||||
$user_country = $this->getUserCountry();
|
||||
return ($user_country && $user_country->currency) ? true : false;
|
||||
}
|
||||
|
||||
public function getPriceCurrencyUnit()
|
||||
{
|
||||
$user_country = $this->getUserCountry();
|
||||
return ($user_country && $user_country->currency) ? $user_country->currency_unit : false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -188,5 +188,29 @@ class HomepartyUserOrderItem extends Model
|
|||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,12 +46,14 @@ class PaymentMethod extends Model
|
|||
'pos' => 'int',
|
||||
'active' => 'bool',
|
||||
'default' => 'bool',
|
||||
'show_on' => 'array',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'short',
|
||||
'show_at',
|
||||
'show_on',
|
||||
'pos',
|
||||
'default',
|
||||
'active'
|
||||
|
|
@ -67,10 +69,30 @@ class PaymentMethod extends Model
|
|||
9 => 'überall',
|
||||
];
|
||||
|
||||
public static $showONs = [
|
||||
1 => 'KundenShop',
|
||||
2 => 'BeraterShop',
|
||||
3 => 'Auszeitparty',
|
||||
4 => 'Registrierung Berater',
|
||||
5 => 'Mitgliedschaft Berater',
|
||||
//6 => 'Onboarding Berater',
|
||||
10 => 'überall',
|
||||
];
|
||||
|
||||
public function getShowAtType(){
|
||||
return isset(self::$showATs[$this->show_at]) ? self::$showATs[$this->show_at] : '-';
|
||||
}
|
||||
|
||||
public function getShowOnTypes(){
|
||||
$ret = [];
|
||||
if($this->show_on){
|
||||
foreach($this->show_on as $show){
|
||||
$ret[] = isset(self::$showONs[$show]) ? self::$showONs[$show] : '-';
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public static function getDefaultAsArray($short=false){
|
||||
return PaymentMethod::where('active', true)->where('default', true)->pluck('id');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 "" ;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\ShippingCountry as ModelsShippingCountry;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
|
|
@ -50,4 +51,17 @@ class ShippingCountry extends Model
|
|||
return $this->hasMany('App\Models\ShoppingOrder', 'country_id');
|
||||
}
|
||||
|
||||
|
||||
public static function getActiveShippingCountries(){
|
||||
$ret = [];
|
||||
$ShippingCountries = ShippingCountry::all();
|
||||
foreach($ShippingCountries as $ShippingCountry){
|
||||
if($ShippingCountry->shipping->active){
|
||||
$ret[$ShippingCountry->country_id] = $ShippingCountry->country->getLocated();
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,32 +58,32 @@ class ShippingPrice 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 setPriceCompAttribute($value)
|
||||
{
|
||||
$this->attributes['price_comp'] = $value ? Util::reFormatNumber($value) : null;
|
||||
$this->attributes['price_comp'] = $value !== null ? Util::reFormatNumber($value) : null;
|
||||
}
|
||||
|
||||
public function setFactorAttribute($value)
|
||||
{
|
||||
$this->attributes['factor'] = $value ? Util::reFormatNumber($value) : null;
|
||||
$this->attributes['factor'] = $value !== null ? Util::reFormatNumber($value) : null;
|
||||
}
|
||||
|
||||
public function setTaxRateAttribute($value)
|
||||
{
|
||||
$this->attributes['tax_rate'] = $value ? Util::reFormatNumber($value) : null;
|
||||
$this->attributes['tax_rate'] = $value !== null ? Util::reFormatNumber($value) : null;
|
||||
}
|
||||
|
||||
public function setTotalFromAttribute($value)
|
||||
{
|
||||
$this->attributes['total_from'] = $value ? Util::reFormatNumber($value) : null;
|
||||
$this->attributes['total_from'] = $value !== null ? Util::reFormatNumber($value) : null;
|
||||
}
|
||||
|
||||
public function setTotalToAttribute($value)
|
||||
{
|
||||
$this->attributes['total_to'] = $value ? Util::reFormatNumber($value) : null;
|
||||
$this->attributes['total_to'] = $value !== null ? Util::reFormatNumber($value) : null;
|
||||
}
|
||||
|
||||
public function getFormattedPrice()
|
||||
|
|
|
|||
|
|
@ -101,5 +101,4 @@ class ShoppingOrderItem extends Model
|
|||
{
|
||||
return formatNumber($this->attributes['price_net'] * $this->attributes['qty']);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue