parent
582ca8299d
commit
263cf93a1e
41 changed files with 812 additions and 288 deletions
166
app/Services/BusinessPlan/SalesPointsVolume.php
Normal file
166
app/Services/BusinessPlan/SalesPointsVolume.php
Normal file
|
|
@ -0,0 +1,166 @@
|
|||
<?php
|
||||
namespace App\Services\BusinessPlan;
|
||||
|
||||
use App\User;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Models\UserSalesVolume;
|
||||
|
||||
class SalesPointsVolume
|
||||
{
|
||||
|
||||
public static function changeSalesPointsVolumeUser(ShoppingOrder $shoppingOrder, $to_user_id){
|
||||
|
||||
if($shoppingOrder->user_sales_volume){
|
||||
$to_user_id = intval($to_user_id);
|
||||
if($shoppingOrder->user_sales_volume->user_id === $to_user_id){
|
||||
\Session()->flash('alert-error', 'Keine Änderung: selber Berater');
|
||||
return;
|
||||
}
|
||||
if(!$shoppingOrder->user_sales_volume->isCurrentMonthYear()){
|
||||
\Session()->flash('alert-error', 'Änderung muss im selben Monat sein');
|
||||
return;
|
||||
}
|
||||
|
||||
$month = $shoppingOrder->user_sales_volume->month;
|
||||
$year = $shoppingOrder->user_sales_volume->year;
|
||||
$form_user_id = $shoppingOrder->user_sales_volume->user_id;
|
||||
|
||||
$to_user = User::find($to_user_id);
|
||||
$form_user = User::find($form_user_id);
|
||||
|
||||
$shoppingOrder->user_sales_volume->user_id = $to_user_id;
|
||||
$shoppingOrder->user_sales_volume->message = 'Punkte zugewiesen am: '.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;
|
||||
$shoppingOrder->user_sales_volume->syslog = $syslog;
|
||||
|
||||
$shoppingOrder->user_sales_volume->save();
|
||||
|
||||
//recalculate
|
||||
self::reCalculateSalesPointsVolume($to_user_id, $month, $year);
|
||||
self::reCalculateSalesPointsVolume($form_user_id, $month, $year);
|
||||
\Session()->flash('alert-save', true);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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_total_net = 0;
|
||||
$month_shop_points = 0;
|
||||
$month_shop_total_net = 0;
|
||||
//TDOO Status === 3???
|
||||
|
||||
foreach($userSalesVolumes as $userSalesVolume){
|
||||
switch ($userSalesVolume->status) {
|
||||
case 1: //Bestellung
|
||||
$month_points += $userSalesVolume->points;
|
||||
$month_total_net += $userSalesVolume->total_net;
|
||||
break;
|
||||
case 2: //Shop
|
||||
$month_shop_points += $userSalesVolume->points;
|
||||
$month_shop_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_total_net = $month_total_net;
|
||||
$userSalesVolume->save();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function addSalesPointsVolumeUser(ShoppingOrder $shoppingOrder){
|
||||
|
||||
/*
|
||||
status
|
||||
1 => 'hinzugefügt aus Bestellung',
|
||||
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.
|
||||
$month = date('m');
|
||||
$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([
|
||||
'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,
|
||||
'message' => '',
|
||||
'status' => $status,
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
public static function setToUserAndReCalculate(UserSalesVolume $user_sales_volume, $user_id){
|
||||
|
||||
//set month year date new, calculate it in the currently month!
|
||||
//If the month has changed, it can no longer be added to the month before
|
||||
$month = date('m');
|
||||
$year = date('Y');
|
||||
$date = date('d.m.Y');
|
||||
|
||||
$user_sales_volume->user_id = $user_id;
|
||||
$user_sales_volume->month = $month;
|
||||
$user_sales_volume->year = $year;
|
||||
$user_sales_volume->date = $date;
|
||||
$user_sales_volume->status = 2; //hinzugefügt aus Shop can only Pending
|
||||
$user_sales_volume->save();
|
||||
|
||||
self::reCalculateSalesPointsVolume($user_id, $month, $year);
|
||||
}
|
||||
|
||||
public static function getStatusByOrderPaymentFor(ShoppingOrder $shoppingOrder){
|
||||
if($shoppingOrder->payment_for){
|
||||
if($shoppingOrder->payment_for === 6){ //Kunde-Shop
|
||||
if($shoppingOrder->shopping_user && $shoppingOrder->shopping_user->is_like){
|
||||
return 3; //shop Kunden, berater zuordnen <- need?
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ namespace App\Services;
|
|||
use App\Mail\MailCheckout;
|
||||
use App\Mail\MailInfo;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Services\BusinessPlan\SalesPointsVolume;
|
||||
use App\Services\Shop;
|
||||
use App\User;
|
||||
use Auth;
|
||||
|
|
@ -79,7 +80,7 @@ class CustomerPriority
|
|||
}
|
||||
//set Points and Volume
|
||||
if ($shopping_user->shopping_order && $user_sales_volume = $shopping_user->shopping_order->user_sales_volume_no_userid()) {
|
||||
$user_sales_volume->setToUserAndCalculate($shopping_user->member_id);
|
||||
SalesPointsVolume::setToUserAndReCalculate($user_sales_volume, $shopping_user->member_id);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -325,7 +325,7 @@ class HTMLHelper
|
|||
if($value->account){
|
||||
$to = $value->account->first_name." ".$value->account->last_name." | ";
|
||||
}
|
||||
$ret .= '<option value="'.$value->id.'" '.$attr.'>'.$to.$value->email.' #'.$value->number.'</option>\n';
|
||||
$ret .= '<option value="'.$value->id.'" '.$attr.'>'.$to.$value->email.' #'.$value->account->m_account.'</option>\n';
|
||||
|
||||
}
|
||||
return $ret;
|
||||
|
|
|
|||
|
|
@ -17,7 +17,8 @@ class Payment
|
|||
'paid' => "bezahlt",
|
||||
'appointed' => "offen",
|
||||
'failed' => "abbruch",
|
||||
'extern' => "extern",
|
||||
'extern' => "offen", //offen
|
||||
'extern_paid' => "bezahlt",
|
||||
'invoice_open' => "offen",
|
||||
'invoice_paid' => "bezahlt",
|
||||
'invoice_non' => "keine Zahlung",
|
||||
|
|
@ -34,7 +35,8 @@ class Payment
|
|||
'paid' => "success",
|
||||
'appointed' => "warning",
|
||||
'failed' => "danger",
|
||||
'extern' => "success",
|
||||
'extern' => "warning",
|
||||
'extern_paid' => "success",
|
||||
'invoice_open' => "warning",
|
||||
'invoice_paid' => "success",
|
||||
'invoice_non' => "failed",
|
||||
|
|
|
|||
|
|
@ -36,7 +36,10 @@ class Shop
|
|||
$shopping_users = ShoppingUser::where('number', '=', $number)->get();
|
||||
$orders = 1;
|
||||
foreach ($shopping_users as $shopping_user) {
|
||||
if($shopping_user->shopping_order && ($shopping_user->shopping_order->txaction === 'paid' || $shopping_user->shopping_order->txaction === 'appointed' || $shopping_user->shopping_order->txaction === 'extern')){
|
||||
if($shopping_user->shopping_order && ($shopping_user->shopping_order->txaction === 'paid' ||
|
||||
$shopping_user->shopping_order->txaction === 'appointed' ||
|
||||
$shopping_user->shopping_order->txaction === 'extern' ||
|
||||
$shopping_user->shopping_order->txaction === 'extern_paid' )){
|
||||
$shopping_user->orders = $orders++;
|
||||
|
||||
}else{
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ class ShopApiOrderCart
|
|||
//price brutto calu with
|
||||
private function calcuPriceWith($price, $tax_rate = null, $discount = null){
|
||||
$tax_dec = ($tax_rate + 100) / 100;
|
||||
$price / $tax_dec;
|
||||
$price = $price / $tax_dec;
|
||||
$margin = (($discount -100)*-1) / 100;
|
||||
$price = $price * $margin;
|
||||
return round($price, 2);
|
||||
|
|
@ -199,6 +199,7 @@ class ShopApiOrderCart
|
|||
$api_notice = $ShoppingOrder->api_notice;
|
||||
$api_notice['shopping_order_id'] = $shoppingCollectOrder->shopping_order_id;
|
||||
$ShoppingOrder->api_notice = $api_notice;
|
||||
$ShoppingOrder->txaction = 'extern_paid';
|
||||
$ShoppingOrder->save();
|
||||
}
|
||||
$shoppingCollectOrder->status = 2; //order
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ use App\Models\ShoppingOrder;
|
|||
use App\Models\UserSalesVolume;
|
||||
use App\Models\ShoppingOrderItem;
|
||||
use App\Repositories\ImportRepository;
|
||||
use App\Services\BusinessPlan\SalesPointsVolume;
|
||||
|
||||
class Correction
|
||||
{
|
||||
|
|
@ -23,7 +24,7 @@ class Correction
|
|||
3 => 'hinzugefügt aus Shop / pending',
|
||||
|
||||
*/
|
||||
$status = UserSalesVolume::getStatusByOrder($order);
|
||||
$status = SalesPointsVolume::getStatusByOrderPaymentFor($order);
|
||||
$user_id = $order->auth_user_id ? $order->auth_user_id : $order->member_id;
|
||||
//akuteller tag / Monat.
|
||||
$month = $order->created_at->format('m');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue