#51 Festschreiben der Points, Gutschriftenmodul

This commit is contained in:
Kevin Adametz 2022-07-29 18:18:05 +02:00
parent dfd049aaa9
commit 3f2fbd6d5b
63 changed files with 4610 additions and 971 deletions

View file

@ -48,7 +48,7 @@ class HomepartyCart
private static $voucher_price = 0;
public static $voucher_name = "";
private static $bonus_diff = 0;
private static $bonus_points_diff = 0;
private static $bonus_coupon_fault = 0;
@ -74,9 +74,12 @@ class HomepartyCart
self::addCart(self::$userCarts[$homeparty_user->id]);
}
self::caluclateShipping();
self::caluclateBonus();
self::calculateBonusHost();
self::caluclateShipping();
self::recalculate();
}
public static function addCart(HomepartyUserCart $homepartyUserCart){
@ -92,6 +95,22 @@ class HomepartyCart
return isset(self::$userCarts[$id]) ? self::$userCarts[$id] : null;
}
private static function recalculate(){
self::$points =0;
self::$price = 0;
self::$price_net = 0;
self::$ek_price = 0;
self::$ek_price_net = 0;
self::$income_price = 0;
foreach(self::$userCarts as $user_cart){
self::$points += $user_cart->points;
self::$price += $user_cart->price;
self::$price_net += $user_cart->price_net;
self::$ek_price += $user_cart->ek_price;
self::$ek_price_net += $user_cart->ek_price_net;
self::$income_price += $user_cart->income_price;
}
}
private static function caluclateBonus(){
@ -138,28 +157,52 @@ class HomepartyCart
$bonus_total = self::$bonus_value + self::$bonus_coupon;
$user_cart = self::getUserCart(self::$user_host_id);
//cart lower the bonus
if($user_cart->price <= $bonus_total){
self::$bonus_points_diff = $user_cart->points;
$user_cart->points = 0;
$user_cart->price = 0;
return;
$user_cart->price_net = 0;
//$price_bonus_total = $bonus_total - ($bonus_total - $user_cart->price);
/* self::$price -= $price_bonus_total;
self::$price_net -= ($price_bonus_total / config('app.main_tax'));
self::$ek_price -= $price_bonus_total;
self::$ek_price_net -= ($price_bonus_total / config('app.main_tax'));
self::$income_price -= $user_cart->income_price;*/
$user_cart->income_price = 0;
}else{
$bonus_percent = (100/$user_cart->price*$bonus_total);
self::$bonus_points_diff = round($user_cart->points/100*$bonus_percent);
$user_cart->points -= self::$bonus_points_diff;
//sub bonus on host
$user_cart->price -= $bonus_total;
$user_cart->price_net -= ($bonus_total / config('app.main_tax'));
/*self::$price -= $bonus_total;
self::$price_net -= ($bonus_total / config('app.main_tax'));
self::$ek_price -= $bonus_total;
self::$ek_price_net -= ($bonus_total / config('app.main_tax'));*/
}
$bonus_percent = (100/$user_cart->price*$bonus_total);
self::$bonus_points_diff = round($user_cart->points/100*$bonus_percent);
$user_cart->points -= self::$bonus_points_diff;
if($user_cart->ek_price <= $bonus_total){
$user_cart->ek_price = 0;
$user_cart->ek_price_net = 0;
$user_cart->income_price = $user_cart->price - $user_cart->ek_price;
//sub bonus on host
$user_cart->price -= $bonus_total;
$user_cart->price_net -= ($bonus_total / config('app.main_tax'));
$user_cart->ek_price -= $bonus_total;
$user_cart->ek_price_net -= ($bonus_total / config('app.main_tax'));
self::$price -= $bonus_total;
self::$price_net -= ($bonus_total / config('app.main_tax'));
self::$ek_price -= $bonus_total;
self::$ek_price_net -= ($bonus_total / config('app.main_tax'));
}else{
$user_cart->ek_price -= $bonus_total;
$user_cart->ek_price_net -= ($bonus_total / config('app.main_tax'));
}
}
}