last changes since 6-2023
This commit is contained in:
parent
0341c9c189
commit
04d677d37a
142 changed files with 7895 additions and 2855 deletions
|
|
@ -2,6 +2,7 @@
|
|||
namespace App\Services\BusinessPlan;
|
||||
|
||||
use App\User;
|
||||
use stdClass;
|
||||
use App\Services\Util;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Models\UserSalesVolume;
|
||||
|
|
@ -33,7 +34,9 @@ class SalesPointsVolume
|
|||
$shoppingOrder->user_sales_volume->message = 'zugewiesen: '.date('d.m.Y');
|
||||
|
||||
$syslog = $shoppingOrder->user_sales_volume->syslog;
|
||||
$syslog[date('d.m.Y-h:i:s')] = 'change form: #'.$form_user_id.' '.$form_user->email.' to: #'.$to_user_id.' '.$to_user->email;
|
||||
$from_email = $form_user ? $form_user->email : '';
|
||||
$to_email = $to_user ? $to_user->email : '';
|
||||
$syslog[date('d.m.Y-h:i:s')] = 'change form: #'.$form_user_id.' '.$from_email.' to: #'.$to_user_id.' '.$to_email;
|
||||
$shoppingOrder->user_sales_volume->syslog = $syslog;
|
||||
|
||||
$shoppingOrder->user_sales_volume->save();
|
||||
|
|
@ -47,10 +50,23 @@ class SalesPointsVolume
|
|||
|
||||
}
|
||||
|
||||
private static function add_KP_TP_Points($userSalesVolume, $month_points){
|
||||
if($userSalesVolume->status_points === 2) { //KP
|
||||
$month_points->KP += $userSalesVolume->points;
|
||||
}else{
|
||||
// === 1 //TP + KP
|
||||
$month_points->KP += $userSalesVolume->points;
|
||||
$month_points->TP += $userSalesVolume->points;
|
||||
}
|
||||
return $month_points;
|
||||
}
|
||||
|
||||
public static function reCalculateSalesPointsVolume($user_id, $month, $year){
|
||||
|
||||
$userSalesVolumes = UserSalesVolume::where('user_id', $user_id)->where('month', $month)->where('year', $year)->orderBy('id', 'ASC')->get();
|
||||
$month_points = 0;
|
||||
$month_points = new stdClass();
|
||||
$month_points->KP = 0;
|
||||
$month_points->TP = 0;
|
||||
$month_total_net = 0;
|
||||
$month_shop_points = 0;
|
||||
$month_shop_total_net = 0;
|
||||
|
|
@ -59,21 +75,26 @@ class SalesPointsVolume
|
|||
foreach($userSalesVolumes as $userSalesVolume){
|
||||
switch ($userSalesVolume->status) {
|
||||
case 1: //Bestellung Berater
|
||||
$month_points += $userSalesVolume->points;
|
||||
$month_points = self::add_KP_TP_Points($userSalesVolume, $month_points);
|
||||
$month_total_net += $userSalesVolume->total_net;
|
||||
break;
|
||||
case 2: //Shop
|
||||
$month_shop_points += $userSalesVolume->points;
|
||||
$month_shop_total_net += $userSalesVolume->total_net;
|
||||
break;
|
||||
case 4: //add Berater
|
||||
$month_points += $userSalesVolume->points;
|
||||
case 4: //Gutschrift
|
||||
$month_points = self::add_KP_TP_Points($userSalesVolume, $month_points);
|
||||
$month_total_net += $userSalesVolume->total_net;
|
||||
break;
|
||||
case 4: //Registrierung
|
||||
$month_points = self::add_KP_TP_Points($userSalesVolume, $month_points);
|
||||
$month_total_net += $userSalesVolume->total_net;
|
||||
break;
|
||||
}
|
||||
$userSalesVolume->month_shop_points = $month_shop_points;
|
||||
$userSalesVolume->month_shop_total_net = $month_shop_total_net;
|
||||
$userSalesVolume->month_points = $month_points;
|
||||
$userSalesVolume->month_KP_points = $month_points->KP;
|
||||
$userSalesVolume->month_TP_points = $month_points->TP;
|
||||
$userSalesVolume->month_total_net = $month_total_net;
|
||||
$userSalesVolume->save();
|
||||
}
|
||||
|
|
@ -88,6 +109,7 @@ class SalesPointsVolume
|
|||
2 => 'hinzugefügt aus Shop',
|
||||
3 => 'hinzugefügt aus Shop / pending',
|
||||
*/
|
||||
|
||||
$status = self::getStatusByOrderPaymentFor($shoppingOrder);
|
||||
$user_id = $shoppingOrder->auth_user_id ? $shoppingOrder->auth_user_id : $shoppingOrder->member_id;
|
||||
//akuteller tag / Monat.
|
||||
|
|
@ -95,45 +117,27 @@ class SalesPointsVolume
|
|||
$year = date('Y');
|
||||
$date = date('d.m.Y');
|
||||
|
||||
if($status === 3){ //shop bestellung User pending if is_like
|
||||
$user_id = NULL;//$shoppingOrder->auth_user_id ? $shoppingOrder->auth_user_id : $shoppingOrder->member_id;
|
||||
$month_points = 0;
|
||||
$month_total_net = 0;
|
||||
$month_shop_points = 0;
|
||||
$month_shop_total_net = 0;
|
||||
}else{
|
||||
$month_points = UserSalesVolume::where('user_id', $user_id)->where('status', 1)->where('month', $month)->where('year', $year)->sum('points');
|
||||
$month_total_net = UserSalesVolume::where('user_id', $user_id)->where('status', 1)->where('month', $month)->where('year', $year)->sum('total_net');
|
||||
$month_shop_points = UserSalesVolume::where('user_id', $user_id)->where('status', 2)->where('month', $month)->where('year', $year)->sum('points');
|
||||
$month_shop_total_net = UserSalesVolume::where('user_id', $user_id)->where('status', 2)->where('month', $month)->where('year', $year)->sum('total_net');
|
||||
}
|
||||
switch ($status) {
|
||||
case 1: //Bestellung
|
||||
$month_points += $shoppingOrder->points;
|
||||
$month_total_net += $shoppingOrder->subtotal;
|
||||
break;
|
||||
case 2: //Shop
|
||||
$month_shop_points += $shoppingOrder->points;
|
||||
$month_shop_total_net += $shoppingOrder->subtotal;
|
||||
break;
|
||||
}
|
||||
|
||||
return UserSalesVolume::create([
|
||||
if($status === 3){ //shop bestellung User pending if is_like
|
||||
$user_id = NULL;
|
||||
}
|
||||
$user_sales_volume = UserSalesVolume::create([
|
||||
'user_id' => $user_id,
|
||||
'shopping_order_id' => $shoppingOrder->id,
|
||||
'month' => $month,
|
||||
'year' => $year,
|
||||
'date' => $date,
|
||||
'points' => $shoppingOrder->points,
|
||||
'month_points' => $month_points,
|
||||
'month_shop_points' => $month_shop_points,
|
||||
'total_net' => $shoppingOrder->subtotal,
|
||||
'month_total_net' => $month_total_net,
|
||||
'month_shop_total_net' => $month_shop_total_net,
|
||||
'total_net' => $shoppingOrder->subtotal,
|
||||
'status_points' => 1, //KP + TP
|
||||
'message' => '',
|
||||
'status' => $status,
|
||||
]);
|
||||
|
||||
if($status !== 3){
|
||||
self::reCalculateSalesPointsVolume($user_sales_volume->user_id, $user_sales_volume->month, $user_sales_volume->year);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static function setToUserAndReCalculate(UserSalesVolume $user_sales_volume, $user_id){
|
||||
|
|
@ -181,6 +185,7 @@ class SalesPointsVolume
|
|||
|
||||
$user_sales_volume->message = 'geändert: '.date('d.m.Y');
|
||||
$user_sales_volume->info = $data['info'];
|
||||
$user_sales_volume->status_points = $data['status_points'];
|
||||
|
||||
$syslog = $user_sales_volume->syslog;
|
||||
$syslog[date('d.m.Y-h:i:s')] = 'edit points: #'.$old_points.' '.$user_sales_volume->points .' total: #'.$old_total_net.' '.$user_sales_volume->total_ne;
|
||||
|
|
@ -198,7 +203,6 @@ class SalesPointsVolume
|
|||
|
||||
public static function addSalesPointsVolume($data){
|
||||
|
||||
|
||||
if(!isset($data['user_id'])){
|
||||
\Session()->flash('alert-error', 'Kein Berater ausgewählt');
|
||||
return;
|
||||
|
|
@ -211,7 +215,7 @@ class SalesPointsVolume
|
|||
$total_net = isset($data['total_net']) ? Util::reFormatNumber($data['total_net']) : 0;
|
||||
$points = isset($data['points']) ? intval($data['points']) : 0;
|
||||
$syslog[date('d.m.Y-h:i:s')] = 'add points: #'.$points.' total: #'.$total_net;
|
||||
|
||||
$status = isset($data['status']) ? intval($data['status']) : 4;
|
||||
|
||||
$user_sales_volume = UserSalesVolume::create([
|
||||
'user_id' => $user->id,
|
||||
|
|
@ -220,11 +224,12 @@ class SalesPointsVolume
|
|||
'year' => $year,
|
||||
'date' => $date,
|
||||
'points' => $points,
|
||||
'status_points' => $data['status_points'],
|
||||
'total_net' => $total_net,
|
||||
'message' => 'hinzugefügt: '.date('d.m.Y'),
|
||||
'info' => $data['info'],
|
||||
'syslog' => $syslog,
|
||||
'status' => 4,
|
||||
'status' => $status,
|
||||
]);
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue