User Order all Margins / Checkout
This commit is contained in:
parent
a96d7d5c77
commit
224bf9e951
92 changed files with 3551 additions and 561 deletions
|
|
@ -626,7 +626,7 @@ class ShoppingUserController extends Controller
|
|||
'subtotal' => Yard::instance('shopping')->subtotal(2, '.', ''),
|
||||
'shipping' => Yard::instance('shopping')->shipping(2, '.', ','),
|
||||
'shipping_net' => Yard::instance('shopping')->shippingNet(2, '.', ''),
|
||||
'subtotal_ws' => Yard::instance('shopping')->subtotalWithShipping(2, '.', ''),
|
||||
'subtotal_shipping' => Yard::instance('shopping')->subtotalWithShipping(2, '.', ''),
|
||||
'tax' => Yard::instance('shopping')->taxWithShipping(2, '.', ''),
|
||||
'total_shipping' => Yard::instance('shopping')->totalWithShipping(2, '.', ''),
|
||||
'points' => Yard::instance('shopping')->points(),
|
||||
|
|
|
|||
|
|
@ -172,7 +172,7 @@ class CustomerController extends Controller
|
|||
data-action="shopping-user-is-like-member"
|
||||
data-back="'.route('admin_customers').'"
|
||||
data-modal="modal-xl"
|
||||
data-route="'.route('modal_load').'"><span class="fa fa-edit"></span> Berater zuordnen</button>';
|
||||
data-route="'.route('modal_load').'"><span class="fa fa-edit"></span> Vertriebspartner zuordnen</button>';
|
||||
}
|
||||
if($ShoppingUser->member_id){
|
||||
return '<a href="'.route('admin_lead_edit', [$ShoppingUser->member_id]).'">'.$ShoppingUser->member->getFullName().'</a>';
|
||||
|
|
|
|||
|
|
@ -222,25 +222,27 @@ class LeadController extends Controller
|
|||
public function released($action, $id){
|
||||
|
||||
$user = User::findOrFail($id);
|
||||
|
||||
if($action === 'completed'){
|
||||
$validator = Validator::make(Request::all(), []);
|
||||
if(!$user->m_sponsor){
|
||||
$validator->errors()->add('m_sponsor', __('Berater hat keinen Sponsor.'));
|
||||
}
|
||||
/*if(!$user->m_sponsor){
|
||||
$validator->errors()->add('m_sponsor', __('Vertriebspartner hat keinen Sponsor.'));
|
||||
}*/
|
||||
if(!$user->account->m_first_name){
|
||||
$validator->errors()->add('m_first_name', __('Berater hat keinen Vornamen.'));
|
||||
$validator->errors()->add('m_first_name', __('Vertriebspartner hat keinen Vornamen.'));
|
||||
}
|
||||
if(!$user->account->m_first_name){
|
||||
$validator->errors()->add('m_last_name', __('Berater hat keinen Nachnamen.'));
|
||||
}
|
||||
if(!$user->account->m_account){
|
||||
$validator->errors()->add('m_account', __('Berater hat keine Account ID'));
|
||||
if(!$user->account->m_last_name){
|
||||
$validator->errors()->add('m_last_name', __('Vertriebspartner hat keinen Nachnamen.'));
|
||||
}
|
||||
|
||||
if ($validator->errors()->count()) {
|
||||
return back()->withErrors($validator)->withRequest(Request::all());
|
||||
}
|
||||
|
||||
if(!$user->account->m_account){
|
||||
$user->account->m_account = UserAccount::max('m_account') +1;
|
||||
$user->account->save();
|
||||
}
|
||||
|
||||
//create PDF
|
||||
$pdf = new ContractPDFRepository($user);
|
||||
$pdf->_set('disk', 'user');
|
||||
|
|
@ -271,7 +273,7 @@ class LeadController extends Controller
|
|||
}
|
||||
|
||||
UserHistory::create(['user_id' => $user->id, 'action'=>'released_completed', 'status'=>0]);
|
||||
\Session()->flash('alert-success', "Berater freigeschaltet!");
|
||||
\Session()->flash('alert-success', "Vertriebspartner freigeschaltet!");
|
||||
}
|
||||
|
||||
if($action === 'incomplete'){
|
||||
|
|
@ -303,7 +305,7 @@ class LeadController extends Controller
|
|||
->save();
|
||||
}
|
||||
UserHistory::create(['user_id' => $user->id, 'action'=>'released_incomplete', 'status'=>0]);
|
||||
\Session()->flash('alert-success', "E-Mail an Berater gesendet.");
|
||||
\Session()->flash('alert-success', "E-Mail an Vertriebspartner gesendet.");
|
||||
|
||||
}
|
||||
return redirect(route('admin_lead_edit', [$user->id]));
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ class MembershipController extends Controller
|
|||
'identifier' => $identifier,
|
||||
'user_shop_id' => 1, //is first faker shop for nuy intern
|
||||
'auth_user_id' => Auth::user()->id,
|
||||
'payment' => 3, //Berater Membership
|
||||
'payment' => 3, //Vertriebspartner Membership
|
||||
'subdomain' => url('/'),
|
||||
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
|
||||
'shopping_data' => $data,
|
||||
|
|
|
|||
|
|
@ -63,6 +63,12 @@ class ModalController extends Controller
|
|||
}
|
||||
|
||||
|
||||
if($data['action'] === 'user-order-show-user-level-margin'){
|
||||
$user = User::find($data['id']);
|
||||
$ret = view("admin.modal.user_level_margin", compact('user', 'data'))->render();
|
||||
}
|
||||
|
||||
|
||||
if($data['action'] === 'homeparty-add-product') {
|
||||
$homeparty = Homeparty::find($data['id']);
|
||||
$homeparty_user = HomepartyUser::find($data['user_id']);
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ class PaymentMethodController extends Controller
|
|||
'short' => $data['short'],
|
||||
'pos' => $data['pos'],
|
||||
'show_at' => $data['show_at'],
|
||||
'max_price' => $data['max_price'],
|
||||
'default' => isset($data['default']) ? true : false,
|
||||
'active' => isset($data['active']) ? true : false,
|
||||
]);
|
||||
|
|
@ -44,6 +45,7 @@ class PaymentMethodController extends Controller
|
|||
$model->name = $data['name'];
|
||||
$model->short = $data['short'];
|
||||
$model->pos = $data['pos'];
|
||||
$model->max_price = $data['max_price'];
|
||||
$model->show_at = $data['show_at'];
|
||||
$model->default = isset($data['default']) ? true : false;
|
||||
$model->active = isset($data['active']) ? true : false;
|
||||
|
|
|
|||
|
|
@ -65,7 +65,10 @@ class ProductController extends Controller
|
|||
$rules = array(
|
||||
'name' => 'required',
|
||||
);
|
||||
if($data['wp_number']){
|
||||
/*if(isset($data['number']) && $data['number'] != ""){
|
||||
$rules['number'] = 'int';
|
||||
}*/
|
||||
if(isset($data['wp_number'])){
|
||||
if($data['id'] !== "new"){
|
||||
$model = Product::findOrFail($data['id']);
|
||||
$rules['wp_number'] = 'unique:products,wp_number,'.$model->id;
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ class SalesController extends Controller
|
|||
})
|
||||
->addColumn('is_for', function (ShoppingOrder $ShoppingOrder) {
|
||||
if($ShoppingOrder->shopping_user->is_for === 'me'){
|
||||
return '<span class="badge badge-pill badge-secondary">Beraterbestellung</span>';
|
||||
return '<span class="badge badge-pill badge-secondary">Vertriebspartnerbestellung</span>';
|
||||
}
|
||||
if($ShoppingOrder->shopping_user->is_for === 'ot'){
|
||||
return '<span class="badge badge-pill badge-info">Kundenbestellung</span>';
|
||||
|
|
@ -216,7 +216,7 @@ class SalesController extends Controller
|
|||
})
|
||||
->addColumn('is_for', function (ShoppingOrder $ShoppingOrder) {
|
||||
if($ShoppingOrder->shopping_user->is_for === 'me'){
|
||||
return '<span class="badge badge-pill badge-secondary">Beraterbestellung</span>';
|
||||
return '<span class="badge badge-pill badge-secondary">Vertriebspartnerbestellung</span>';
|
||||
}
|
||||
if($ShoppingOrder->shopping_user->is_for === 'ot'){
|
||||
return '<span class="badge badge-pill badge-info">Kundenbestellung</span>';
|
||||
|
|
@ -239,7 +239,7 @@ class SalesController extends Controller
|
|||
data-action="shopping-user-is-like-member"
|
||||
data-back="'.route('admin_sales_customers').'"
|
||||
data-modal="modal-xl"
|
||||
data-route="'.route('modal_load').'"><span class="fa fa-edit"></span> Berater zuordnen</button>';
|
||||
data-route="'.route('modal_load').'"><span class="fa fa-edit"></span> Vertriebspartner zuordnen</button>';
|
||||
}
|
||||
return '';
|
||||
})
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ use App\Models\PaymentTransaction;
|
|||
use App\Models\ShippingCountry;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Models\ShoppingOrderItem;
|
||||
use App\Models\ShoppingOrderMargin;
|
||||
use App\Models\ShoppingPayment;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Services\CustomerPriority;
|
||||
|
|
@ -125,14 +126,13 @@ class CheckoutController extends Controller
|
|||
|
||||
if($is_from !== 'shopping' && Util::getAuthUser()){
|
||||
$user = Util::getAuthUser();
|
||||
$payment_methods = $user->payment_methods;
|
||||
$user_payment_methods = $user->payment_methods;
|
||||
$payment_data = $user->account->payment_data;
|
||||
}else{
|
||||
$payment_methods = PaymentMethod::getDefaultAsArray()->toArray();
|
||||
$user_payment_methods = PaymentMethod::getDefaultAsArray()->toArray();
|
||||
$payment_data = false;
|
||||
}
|
||||
|
||||
$payment_methods_active = \App\Models\PaymentMethod::where('active', true)->get()->pluck( 'id', 'short')->toArray();
|
||||
$data = [
|
||||
'is_from' => $is_from,
|
||||
'is_for' => $is_for,
|
||||
|
|
@ -140,8 +140,7 @@ class CheckoutController extends Controller
|
|||
'user_shop' => Util::getUserShop(),
|
||||
'shopping_user' => $shopping_user,
|
||||
'shopping_mode' => Util::getUserShoppingMode(),
|
||||
'payment_methods' => $payment_methods,
|
||||
'payment_methods_active' => $payment_methods_active,
|
||||
'user_payment_methods' => $user_payment_methods,
|
||||
'identifier' => $identifier,
|
||||
'payment_data' => $payment_data,
|
||||
'back' => url()->previous(),
|
||||
|
|
@ -402,18 +401,25 @@ class CheckoutController extends Controller
|
|||
private function makeShoppingOrder($shopping_user){
|
||||
|
||||
$user_shop = Util::getUserShop();
|
||||
|
||||
$discount = 0;
|
||||
if(Yard::instance('shopping')->getYardMargin()){
|
||||
$discount = Yard::instance('shopping')->getYardMargin()->net_discount;
|
||||
}
|
||||
$data = [
|
||||
'shopping_user_id' => $shopping_user->id,
|
||||
'auth_user_id' => $shopping_user->auth_user_id,
|
||||
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
|
||||
'payment_for' => Util::getUserPaymentFor(),
|
||||
'total' => Yard::instance('shopping')->total(2, '.', ''),
|
||||
'subtotal_full' => Yard::instance('shopping')->subtotal(2, '.', '', false),
|
||||
'discount' => $discount,
|
||||
'subtotal' => Yard::instance('shopping')->subtotal(2, '.', ''),
|
||||
'shipping' => Yard::instance('shopping')->shipping(2, '.', ','),
|
||||
'shipping_net' => Yard::instance('shopping')->shippingNet(2, '.', ''),
|
||||
'subtotal_ws' => Yard::instance('shopping')->subtotalWithShipping(2, '.', ''),
|
||||
'subtotal_shipping' => Yard::instance('shopping')->subtotalWithShipping(2, '.', ''),
|
||||
'tax' => Yard::instance('shopping')->taxWithShipping(2, '.', ''),
|
||||
'total_without_credit' => Yard::instance('shopping')->totalWithShippingWithoutCredit(2, '.', ''),
|
||||
'payment_credit' => Yard::instance('shopping')->totalfromCredit(2, '.', ''),
|
||||
'total_shipping' => Yard::instance('shopping')->totalWithShipping(2, '.', ''),
|
||||
'points' => Yard::instance('shopping')->points(),
|
||||
'weight' => Yard::instance('shopping')->weight(),
|
||||
|
|
@ -433,8 +439,9 @@ class CheckoutController extends Controller
|
|||
if(!$shopping_order){
|
||||
$shopping_order = ShoppingOrder::create($data);
|
||||
}
|
||||
$this->putPayments('shopping_order_id', $shopping_order->id);
|
||||
$this->makeOrderMargin($shopping_order);
|
||||
|
||||
$this->putPayments('shopping_order_id', $shopping_order->id);
|
||||
$items = Yard::instance('shopping')->getContentByOrder();
|
||||
$shopping_order->shopping_order_items()->each(function($model) use ($items, $shopping_order, $shopping_user) {
|
||||
foreach ($items as $item) {
|
||||
|
|
@ -477,6 +484,38 @@ class CheckoutController extends Controller
|
|||
return $shopping_order;
|
||||
}
|
||||
|
||||
private function makeOrderMargin(ShoppingOrder $shopping_order)
|
||||
{
|
||||
|
||||
if (Yard::instance('shopping')->getYardMargin()) {
|
||||
|
||||
$data = [
|
||||
'shopping_order_id' => $shopping_order->id,
|
||||
'user_id' => $shopping_order->auth_user_id,
|
||||
'net_price' => Yard::instance('shopping')->getYardMargin()->net_price,
|
||||
'net_discount' => Yard::instance('shopping')->getYardMargin()->net_discount,
|
||||
'net_amount' => Yard::instance('shopping')->getYardMargin()->net_amount,
|
||||
'from_payment_credit' => Yard::instance('shopping')->totalfromCredit(2, '.', ''),
|
||||
'from' => now(),
|
||||
'content' => serialize(Yard::instance('shopping')->getYardMargin()->toArray())
|
||||
];
|
||||
if(Yard::instance('shopping')->getYardMargin()->net_partner_commission > 0){
|
||||
$data['m_sponsor_id'] = $shopping_order->auth_user->m_sponsor;
|
||||
$data['net_partner_commission'] = Yard::instance('shopping')->getYardMargin()->net_partner_commission;
|
||||
}
|
||||
$shopping_order_margin = false;
|
||||
if ($this->getPayments('shopping_order_margin_id')) {
|
||||
$shopping_order_margin = ShoppingOrderMargin::find($this->getPayments('shopping_order_margin_id'));
|
||||
if ($shopping_order_margin) {
|
||||
$shopping_order_margin->fill($data);
|
||||
$shopping_order_margin->save();}
|
||||
}
|
||||
if (!$shopping_order_margin) {
|
||||
$shopping_order_margin = ShoppingOrderMargin::create($data);
|
||||
}
|
||||
$this->putPayments('shopping_order_margin_id', $shopping_order_margin->id);
|
||||
}
|
||||
}
|
||||
private function putPayments($key, $value){
|
||||
$content = $this->getContent();
|
||||
$content->put($key, $value);
|
||||
|
|
|
|||
|
|
@ -388,7 +388,7 @@ class HomepartyController extends Controller
|
|||
'identifier' => $identifier,
|
||||
'user_shop_id' => 1, //is first faker shop for nuy intern
|
||||
'auth_user_id' => Auth::user()->id,
|
||||
'payment' => 5, //Berater Membership
|
||||
'payment' => 5, //Vertriebspartner Membership
|
||||
'subdomain' => url('/'),
|
||||
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
|
||||
'shopping_data' => $data,
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ class OrderController extends Controller
|
|||
})
|
||||
->addColumn('is_for', function (ShoppingOrder $ShoppingOrder) {
|
||||
if($ShoppingOrder->shopping_user->is_for === 'me'){
|
||||
return '<span class="badge badge-pill badge-secondary">Beraterbestellung</span>';
|
||||
return '<span class="badge badge-pill badge-secondary">Vertriebspartnerbestellung</span>';
|
||||
}
|
||||
if($ShoppingOrder->shopping_user->is_for === 'ot'){
|
||||
return '<span class="badge badge-pill badge-info">Kundenbestellung</span>';
|
||||
|
|
@ -149,6 +149,8 @@ class OrderController extends Controller
|
|||
}
|
||||
|
||||
Yard::instance('shopping')->setShippingCountryWithPrice($shipping_country_id, $for);
|
||||
Yard::instance('shopping')->setShoppingUser($user, true);
|
||||
|
||||
|
||||
$data = [
|
||||
'shopping_user' => $shopping_user,
|
||||
|
|
@ -177,7 +179,6 @@ class OrderController extends Controller
|
|||
$validator = Validator::make(Request::all(), $rules);
|
||||
|
||||
if ($validator->fails()) {
|
||||
dd($validator);
|
||||
return back()->withErrors($validator)->withInput(Request::all());
|
||||
}
|
||||
|
||||
|
|
@ -214,7 +215,7 @@ class OrderController extends Controller
|
|||
'identifier' => $identifier,
|
||||
'user_shop_id' => 1, //is first faker shop for buy intern
|
||||
'auth_user_id' => Auth::user()->id,
|
||||
'payment' => 2, //Berater Shop
|
||||
'payment' => 2, //Vertriebspartner Shop
|
||||
'subdomain' => url('/'),
|
||||
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
|
||||
'shopping_data' => $data,
|
||||
|
|
@ -294,12 +295,12 @@ class OrderController extends Controller
|
|||
$q->where('show_at', '=', 0)
|
||||
->orWhere('show_at', '=', 1);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
//Kunden und Berater
|
||||
//->orWhere('show_at', '=', 2); // Nur Berater
|
||||
|
||||
//Kunden und Vertriebspartner
|
||||
//->orWhere('show_at', '=', 2); // Nur Vertriebspartner
|
||||
//->orderBy('pos', 'DESC')
|
||||
//->orderBy('id', 'DESC');
|
||||
|
||||
|
|
@ -346,6 +347,7 @@ class OrderController extends Controller
|
|||
</div>';
|
||||
|
||||
})*/
|
||||
|
||||
->addColumn('picture', function (Product $product) {
|
||||
if(count($product->images)){
|
||||
return '<img class="img-fluid img-extra" alt="" src="'.route('product_image', [$product->images->first()->slug]).'">';
|
||||
|
|
@ -361,8 +363,15 @@ class OrderController extends Controller
|
|||
->addColumn('price_vk_gross', function (Product $product) {
|
||||
return $product->getFormattedPriceWith(false, false). " €";
|
||||
})
|
||||
->addColumn('single_commission', function (Product $product) {
|
||||
return $product->single_commission ? '<span class="badge badge-warning">Handelspanne: '.$product->getFormattedValueCommission().' %</span>' : '<span class="badge badge-primary">Staffelprovision</span> <button class="btn btn-default btn-xs icon-btn md-btn-flat product-tooltip" title="details" data-modal="modal-lg"
|
||||
data-toggle="modal" data-target="#modals-load-content" data-id="'.Auth::user()->id.'" data-route="'.route('modal_load').'"
|
||||
data-action="user-order-show-user-level-margin" data-view="customer"><i class="ion ion-md-eye"></i></button>';
|
||||
})
|
||||
|
||||
|
||||
->addColumn('action', function (Product $product) {
|
||||
return '<button class="btn btn-default btn-sm icon-btn md-btn-flat product-tooltip" title="details" data-modal="modal-lg"
|
||||
return '<button class="btn btn-default btn-sm icon-btn md-btn-flat product-tooltip" title="details" data-modal="modal-lg"
|
||||
data-toggle="modal" data-target="#modals-load-content" data-id="'.$product->id.'" data-route="'.route('modal_load').'"
|
||||
data-action="user-order-show-product" data-view="customer"><i class="ion ion-md-eye"></i></button>';
|
||||
})
|
||||
|
|
@ -379,9 +388,10 @@ class OrderController extends Controller
|
|||
->orderColumn('price_gross', 'price_gross $1')
|
||||
->orderColumn('price_vk_gross', 'price $1')
|
||||
->orderColumn('contents_total', 'contents_total $1')
|
||||
->orderColumn('single_commission', 'single_commission $1')
|
||||
->orderColumn('weight', 'weight $1')
|
||||
|
||||
->rawColumns(['add_card', 'product', 'quantity', 'picture', 'action'])
|
||||
->rawColumns(['add_card', 'product', 'quantity', 'picture', 'action', 'single_commission'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
|
|
@ -401,7 +411,16 @@ class OrderController extends Controller
|
|||
}
|
||||
|
||||
//get the card item
|
||||
$cartItem = Yard::instance('shopping')->add($product->id, $product->getLang('name'), 1, $product->getPriceWith(false, true), $product->tax, ['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points]);
|
||||
$cartItem = Yard::instance('shopping')->add($product->id, $product->getLang('name'), 1, $product->getPriceWith(false, true), $product->tax,
|
||||
[
|
||||
'image' => $image,
|
||||
'slug' => $product->slug,
|
||||
'weight' => $product->weight,
|
||||
'single_commission' => $product->single_commission,
|
||||
'amount_commission' => $product->amount_commission,
|
||||
'value_commission' => $product->value_commission,
|
||||
'partner_commission' => $product->partner_commission,
|
||||
]);
|
||||
Yard::setTax($cartItem->rowId, $product->tax);
|
||||
|
||||
if(isset($data['qty']) && $data['qty'] > 0){
|
||||
|
|
@ -411,10 +430,8 @@ class OrderController extends Controller
|
|||
Yard::instance('shopping')->remove($cartItem->rowId);
|
||||
}
|
||||
//
|
||||
Yard::instance('shopping')->reCalculateShippingPrice();
|
||||
//$this->checkCompProduct(Yard::instance('shopping')->getNumComp());
|
||||
Yard::instance('shopping')->reCalculate();
|
||||
$html_card = view("user.order.yard_view_form", $data)->render();
|
||||
//$html_comp = view("user.order.comp_product", $data)->render();
|
||||
|
||||
return response()->json(['response' => true, 'data'=>$data, 'html_card'=>$html_card, 'html_comp'=>'']);
|
||||
}
|
||||
|
|
@ -435,19 +452,6 @@ class OrderController extends Controller
|
|||
//$html_comp = view("user.order.comp_product", $data)->render();
|
||||
return response()->json(['response' => true, 'data'=>$data, 'html_card'=>$html_card, 'html_comp'=>'']);
|
||||
}
|
||||
/* if($data['action'] === 'updateCompProduct'){
|
||||
// $data['comp_product_id']
|
||||
// $data['comp_num']
|
||||
//count_comp_products
|
||||
$this->updateCompProduct($data);
|
||||
Yard::instance('shopping')->reCalculateShippingPrice();
|
||||
$html_card = view("user.order.yard_view_form", $data)->render();
|
||||
$html_comp = view("user.order.comp_product", $data)->render();
|
||||
|
||||
return response()->json(['response' => true, 'data'=>$data, 'html_card'=>$html_card, 'html_comp'=>$html_comp]);
|
||||
|
||||
}
|
||||
*/
|
||||
return response()->json(['response' => false, 'data'=>$data]);
|
||||
}
|
||||
}
|
||||
|
|
@ -484,10 +488,5 @@ class OrderController extends Controller
|
|||
}
|
||||
}
|
||||
|
||||
private function getCompProducts($for){
|
||||
if($for === 'me'){
|
||||
return Product::whereActive(true)->where('show_at', '=', 1)->where('shipping_addon', true)->orderBy('pos', 'DESC')->get();
|
||||
}
|
||||
return null;
|
||||
}*/
|
||||
*/
|
||||
}
|
||||
|
|
@ -5,8 +5,11 @@ namespace App\Http\Controllers;
|
|||
|
||||
use App\Models\Attribute;
|
||||
use App\Models\ProductAttribute;
|
||||
use App\Models\Shipping;
|
||||
use App\Models\UserLevel;
|
||||
use App\Models\UserLevelMargin;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
|
||||
class UserLevelController extends Controller
|
||||
|
|
@ -27,42 +30,95 @@ class UserLevelController extends Controller
|
|||
return view('admin.level.index', $data);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
if($id === "new"){
|
||||
$user_level = new UserLevel();
|
||||
$user_level->active = 1;
|
||||
|
||||
}else{
|
||||
$user_level = UserLevel::findOrFail($id);
|
||||
|
||||
}
|
||||
$data = [
|
||||
'value' => $user_level,
|
||||
];
|
||||
return view('admin.level.edit', $data);
|
||||
|
||||
|
||||
}
|
||||
public function store()
|
||||
{
|
||||
|
||||
$data = Request::all();
|
||||
if($data['id'] == "new"){
|
||||
$model = UserLevel::create([
|
||||
'name' => $data['name'],
|
||||
'pos' => $data['pos'],
|
||||
'content' => $data['content'],
|
||||
'active' => isset($data['active']) ? true : false,
|
||||
]);
|
||||
}else{
|
||||
$model = UserLevel::find($data['id']);
|
||||
$model->name = $data['name'];
|
||||
$model->pos = $data['pos'];
|
||||
$model->content = $data['content'];
|
||||
$model->active = isset($data['active']) ? true : false;
|
||||
$model->save();
|
||||
}
|
||||
|
||||
if(!empty($data['trans'])){
|
||||
$trans = [];
|
||||
foreach ($data['trans'] as $lang => $value){
|
||||
if($value && $value != null){
|
||||
$trans[$lang] = $value;
|
||||
if($data['action'] === 'user_level') {
|
||||
if ($data['id'] === "new") {
|
||||
$user_level = UserLevel::create([
|
||||
'name' => $data['name'],
|
||||
'pos' => $data['pos'],
|
||||
'content' => $data['content'],
|
||||
'partner_provision' => isset($data['partner_provision']) ? true : false,
|
||||
'active' => isset($data['active']) ? true : false,
|
||||
]);
|
||||
} else {
|
||||
$user_level = UserLevel::find($data['id']);
|
||||
$user_level->name = $data['name'];
|
||||
$user_level->pos = $data['pos'];
|
||||
$user_level->content = $data['content'];
|
||||
$user_level->partner_provision = isset($data['partner_provision']) ? true : false;
|
||||
$user_level->active = isset($data['active']) ? true : false;
|
||||
$user_level->save();
|
||||
}
|
||||
|
||||
if (!empty($data['trans'])) {
|
||||
$trans = [];
|
||||
foreach ($data['trans'] as $lang => $value) {
|
||||
if ($value && $value != null) {
|
||||
$trans[$lang] = $value;
|
||||
}
|
||||
}
|
||||
if (count($trans)) {
|
||||
$user_level->trans_name = $trans;
|
||||
$user_level->save();
|
||||
}
|
||||
}
|
||||
if(count($trans)){
|
||||
$model->trans_name = $trans;
|
||||
$model->save();
|
||||
}
|
||||
|
||||
if($data['action'] === 'user_level_margin') {
|
||||
$user_level = UserLevel::findOrFail($data['user_level_id']);
|
||||
$rules = array('price_from' => 'required');
|
||||
$ret = ['value' => $user_level];
|
||||
$validator = Validator::make(Request::all(), $rules);
|
||||
if ($validator->fails()) {
|
||||
return view('admin.level.edit', $ret)->withErrors($validator);
|
||||
}
|
||||
if ($data['id'] === "new") {
|
||||
$user_level_margin = UserLevelMargin::create($data);
|
||||
} else {
|
||||
$user_level_margin = UserLevelMargin::findOrFail($data['id']);
|
||||
if($user_level_margin->user_level_id != $user_level->id){
|
||||
abort(404);
|
||||
}
|
||||
$user_level_margin->fill($data);
|
||||
$user_level_margin->save();
|
||||
}
|
||||
}
|
||||
|
||||
\Session()->flash('alert-save', '1');
|
||||
return redirect(route('admin_levels'));
|
||||
return redirect(route('admin_level_edit', [$user_level->id]));
|
||||
|
||||
}
|
||||
|
||||
public function delete($do, $id)
|
||||
{
|
||||
if($do === 'user_level_margin'){
|
||||
$model = UserLevelMargin::findOrFail($id);
|
||||
$id = $model->user_level->id;
|
||||
$model->delete();
|
||||
\Session()->flash('alert-success', "Eintrag gelöscht");
|
||||
return redirect(route('admin_level_edit', [$id]));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -480,7 +480,7 @@ class WizardController extends Controller
|
|||
'identifier' => $identifier,
|
||||
'user_shop_id' => 1, //is first faker shop for buy intern
|
||||
'auth_user_id' => Auth::user()->id,
|
||||
'payment' => 4, //Berater Wizard
|
||||
'payment' => 4, //Vertriebspartner Wizard
|
||||
'subdomain' => url('/'),
|
||||
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
|
||||
'shopping_data' => $data,
|
||||
|
|
|
|||
|
|
@ -58,16 +58,16 @@ class MailInfo extends Mailable
|
|||
}
|
||||
$content .= "E-Mail: ".$this->user->email;
|
||||
|
||||
$copy1line = "Infos zum Berater:"."\n";
|
||||
$button = "zum Berater";
|
||||
$title = "Ein Berater möchte seine Mitgliedschaft beenden.";
|
||||
$copy1line = "Infos zum Vertriebspartner:"."\n";
|
||||
$button = "zum Vertriebspartner";
|
||||
$title = "Ein Vertriebspartner möchte seine Mitgliedschaft beenden.";
|
||||
$url = route('admin_lead_edit', $this->user->id).'?show=check_lead';
|
||||
}
|
||||
|
||||
if($this->action === "check_is_like_customer") {
|
||||
$copy1line = "Hier geht es zum Kunden:"."\n";
|
||||
$button = "zum Kunden";
|
||||
$title = "Ein Kunden muss überprüft werden und einem Berater zugeordnet werden, da die Adresse nicht eindeutig ist.";
|
||||
$title = "Ein Kunden muss überprüft werden und einem Vertriebspartner zugeordnet werden, da die Adresse nicht eindeutig ist.";
|
||||
$url = route('admin_customer_detail', $this->user->id);
|
||||
$content .= $this->user ? 'Firma: '.$this->user->billing_company."\n" : '';
|
||||
$content .= \App\Services\HTMLHelper::getSalutationLang($this->user->billing_salutation)." ";
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ class MailReleaseAccount extends Mailable
|
|||
public function __construct(User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->subject = 'Neuer Berater Registrierung prüfen';
|
||||
$this->subject = 'Neuer Vertriebspartner Registrierung prüfen';
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -42,19 +42,19 @@ class MailReleaseAccount extends Mailable
|
|||
$content .= "E-Mail: ".$this->user->email;
|
||||
|
||||
|
||||
$copy1line = "Ein neuer Berater hat sich registriert und wartet auf die Überprüfung und Freigabe seiner Daten:"."\n";
|
||||
$copy1line = "Ein neuer Vertriebspartner hat sich registriert und wartet auf die Überprüfung und Freigabe seiner Daten:"."\n";
|
||||
$copy1line .= "+ Überprüfung der Ausweisdate"."\n";
|
||||
$copy1line .= "+ Überprüfung des Gewerbenachweises"."\n";
|
||||
$copy1line .= "+ Eintrag Account ID"."\n";
|
||||
$copy1line .= "+ Überprüfung / Kenntnisnahme Sponsor"."\n";
|
||||
$copy1line .= "+ Überprüfung der Rechnungsdaten"."\n";
|
||||
$copy1line .= 'Nach erfolgreicher Überprüfung mit dem Button „Daten vollständig => Berater freischalten“ den Berater freischalten.'."\n";
|
||||
$copy1line .= 'Der Berater erhält eine Mail, dass sein Account freigeschaltet wurde. Der Vertrag wird automatisch mit den Daten des Vertriebspartners erstellt.'."\n";
|
||||
$copy1line .= 'Nach erfolgreicher Überprüfung mit dem Button „Daten vollständig => Vertriebspartner freischalten“ den Vertriebspartner freischalten.'."\n";
|
||||
$copy1line .= 'Der Vertriebspartner erhält eine Mail, dass sein Account freigeschaltet wurde. Der Vertrag wird automatisch mit den Daten des Vertriebspartners erstellt.'."\n";
|
||||
|
||||
return $this->view('emails.info')->with([
|
||||
'url' => route('admin_lead_edit', $this->user->id).'?show=check_lead',
|
||||
'title' => 'Berater Registrierung prüfen',
|
||||
'button' => 'zur Berater Prüfung',
|
||||
'title' => 'Vertriebspartner Registrierung prüfen',
|
||||
'button' => 'zur Vertriebspartner Prüfung',
|
||||
'copy1line' => $copy1line,
|
||||
'copy2line' => __('email.copy2line'),
|
||||
'content' => $content,
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Services\Util;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
|
|
@ -35,6 +36,8 @@ use Illuminate\Database\Eloquent\Model;
|
|||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PaymentMethod whereShowAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PaymentMethod whereUpdatedAt($value)
|
||||
* @mixin \Eloquent
|
||||
* @property string|null $max_price
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PaymentMethod whereMaxPrice($value)
|
||||
*/
|
||||
class PaymentMethod extends Model
|
||||
{
|
||||
|
|
@ -52,6 +55,7 @@ class PaymentMethod extends Model
|
|||
'name',
|
||||
'short',
|
||||
'show_at',
|
||||
'max_price',
|
||||
'pos',
|
||||
'default',
|
||||
'active'
|
||||
|
|
@ -59,11 +63,11 @@ class PaymentMethod extends Model
|
|||
|
||||
public static $showATs = [
|
||||
0 => 'Nur Kunden Shop',
|
||||
1 => 'Nur Berater Shop',
|
||||
2 => 'Kunden + Berater Shop',
|
||||
3 => 'Nur Reg/Mitgliedschaft Berater',
|
||||
4 => 'Kunden + Berater Shop + Reg/Mitgliedschaft',
|
||||
5 => 'Berater Shop + Reg/Mitgliedschaft',
|
||||
1 => 'Nur Vertriebspartner Shop',
|
||||
2 => 'Kunden + Vertriebspartner Shop',
|
||||
3 => 'Nur Reg/Mitgliedschaft Vertriebspartner',
|
||||
4 => 'Kunden + Vertriebspartner Shop + Reg/Mitgliedschaft',
|
||||
5 => 'Vertriebspartner Shop + Reg/Mitgliedschaft',
|
||||
9 => 'überall',
|
||||
];
|
||||
|
||||
|
|
@ -74,4 +78,37 @@ class PaymentMethod extends Model
|
|||
public static function getDefaultAsArray($short=false){
|
||||
return PaymentMethod::where('active', true)->where('default', true)->pluck('id');
|
||||
}
|
||||
|
||||
public function setMaxPriceAttribute($value)
|
||||
{
|
||||
$this->attributes['max_price'] = $value ? Util::reFormatNumber($value) : null;
|
||||
}
|
||||
|
||||
public function getFormattedMaxPrice()
|
||||
{
|
||||
return isset($this->attributes['max_price']) ? Util::formatNumber($this->attributes['max_price']) : "";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $short //PP FNC VOR CC SB ...
|
||||
* @param $user_payment_methods //PaymentMethod [] IDs
|
||||
* @param $total //Full price
|
||||
*/
|
||||
public static function isShowPaymentMethod($short, $user_payment_methods, $total = 0){
|
||||
|
||||
$payment_method = PaymentMethod::whereShort($short)->first();
|
||||
|
||||
if($payment_method && $payment_method->active){
|
||||
if(in_array($payment_method->id, $user_payment_methods)){
|
||||
if($payment_method->max_price > 0){
|
||||
if($payment_method->max_price >= $total){
|
||||
return true;
|
||||
}
|
||||
}else{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -103,13 +103,20 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
|||
* @property-read int|null $country_prices_count
|
||||
* @property int|null $wp_number
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereWpNumber($value)
|
||||
* @property bool|null $shipping_addon
|
||||
* @property bool|null $single_commission
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereShippingAddon($value)
|
||||
* @property-read int|null $ingredients_count
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\ProductIngredient[] $product_ingredients
|
||||
* @property-read int|null $product_ingredients_count
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Ingredient[] $p_ingredients
|
||||
* @property-read int|null $p_ingredients_count
|
||||
* @property bool $amount_commission
|
||||
* @property string|null $value_commission
|
||||
* @property string|null $partner_commission
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Product whereAmountCommission($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Product wherePartnerCommission($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Product whereSingleCommission($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Product whereValueCommission($value)
|
||||
*/
|
||||
class Product extends Model
|
||||
{
|
||||
|
|
@ -132,7 +139,8 @@ class Product extends Model
|
|||
'trans_ingredients' => 'array',
|
||||
'action' => 'array',
|
||||
'wp_number' => 'int',
|
||||
'shipping_addon' => 'bool',
|
||||
'single_commission' => 'bool',
|
||||
'amount_commission' => 'bool',
|
||||
'active' => 'bool'
|
||||
];
|
||||
use Sluggable;
|
||||
|
|
@ -164,7 +172,10 @@ class Product extends Model
|
|||
'amount',
|
||||
'active',
|
||||
'show_at',
|
||||
'shipping_addon',
|
||||
'single_commission',
|
||||
'amount_commission',
|
||||
'value_commission',
|
||||
'partner_commission',
|
||||
'identifier',
|
||||
'action',
|
||||
'upgrade_to_id'
|
||||
|
|
@ -175,8 +186,8 @@ class Product extends Model
|
|||
'show_upgrade' => 'Kann geupdatet werden',
|
||||
'show_order' => 'Wird immer als Option angezeigt',
|
||||
'upgrade' => 'Produktupgrade zur Produkt ID',
|
||||
'upgrade_member' => 'Beraterupgrade zur Karriere ID',
|
||||
//'proportional_voucher' => 'Anteiliger Gutschein Berater',
|
||||
'upgrade_member' => 'Vertriebspartnerupgrade zur Karriere ID',
|
||||
//'proportional_voucher' => 'Anteiliger Gutschein Vertriebspartner',
|
||||
|
||||
|
||||
];
|
||||
|
|
@ -190,12 +201,12 @@ class Product extends Model
|
|||
|
||||
public $showATs = [
|
||||
0 => 'Nur Kunden Bestellungen',
|
||||
1 => 'Kunden + Berater Bestellungen',
|
||||
2 => 'Nur Berater Bestellungen',
|
||||
3 => 'Registrierung / Mitgliedschaft Berater',
|
||||
4 => 'Nur Mitgliedschaft Berater',
|
||||
//5 => 'Onboarding Berater',
|
||||
//6 => 'Onboarding Berater + Berater Shop',
|
||||
1 => 'Kunden + Vertriebspartner Bestellungen',
|
||||
2 => 'Nur Vertriebspartner Bestellungen',
|
||||
3 => 'Registrierung / Mitgliedschaft Vertriebspartner',
|
||||
4 => 'Nur Mitgliedschaft Vertriebspartner',
|
||||
//5 => 'Onboarding Vertriebspartner',
|
||||
//6 => 'Onboarding Vertriebspartner + Vertriebspartner Shop',
|
||||
7 => 'zur internen Berechnung',
|
||||
|
||||
];
|
||||
|
|
@ -279,6 +290,14 @@ class Product extends Model
|
|||
$this->attributes['price_old'] = $value ? Util::reFormatNumber($value) : null;
|
||||
}
|
||||
|
||||
public function setValueCommissionAttribute( $value ) {
|
||||
$this->attributes['value_commission'] = $value ? Util::reFormatNumber($value) : 0;
|
||||
}
|
||||
|
||||
public function setPartnerCommissionAttribute( $value ) {
|
||||
$this->attributes['partner_commission'] = $value ? Util::reFormatNumber($value) : 0;
|
||||
}
|
||||
|
||||
public function getFormattedPrice()
|
||||
{
|
||||
return isset($this->attributes['price']) ? Util::formatNumber($this->attributes['price']) : "";
|
||||
|
|
@ -298,6 +317,16 @@ class Product extends Model
|
|||
{
|
||||
return isset($this->attributes['price_old']) ? Util::formatNumber($this->attributes['price_old']) : "";
|
||||
}
|
||||
public function getFormattedValueCommission()
|
||||
{
|
||||
return isset($this->attributes['value_commission']) ? Util::formatNumber($this->attributes['value_commission']) : 0;
|
||||
}
|
||||
|
||||
public function getFormattedPartnerCommission()
|
||||
{
|
||||
return isset($this->attributes['partner_commission']) ? Util::formatNumber($this->attributes['partner_commission']) : 0;
|
||||
}
|
||||
|
||||
|
||||
/*price by user Factor*/
|
||||
private function calcPriceUserFactor($price){
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use Illuminate\Database\Eloquent\Model;
|
|||
|
||||
/**
|
||||
* Class Setting
|
||||
*
|
||||
*
|
||||
* @property int $id
|
||||
* @property string|null $identifier
|
||||
* @property string $slug
|
||||
|
|
@ -23,8 +23,27 @@ use Illuminate\Database\Eloquent\Model;
|
|||
* @property int $status
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
*
|
||||
* @package App\Models
|
||||
* @property string|null $full_text
|
||||
* @property string|null $text
|
||||
* @property string|null $type
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Setting findSimilarSlugs(string $attribute, array $config, string $slug)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Setting newModelQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Setting newQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Setting query()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Setting whereAction($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Setting whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Setting whereFullText($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Setting whereId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Setting whereIdentifier($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Setting whereObject($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Setting whereReferenz($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Setting whereSlug($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Setting whereStatus($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Setting whereText($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Setting whereType($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Setting whereUpdatedAt($value)
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class Setting extends Model
|
||||
{
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
|||
* @method static \Illuminate\Database\Query\Builder|\App\Models\ShoppingOrder withoutTrashed()
|
||||
* @property-read \App\Models\ShippingCountry $shipping_country
|
||||
* @property float|null $shipping_net
|
||||
* @property float|null $subtotal_ws
|
||||
* @property float|null $subtotal_shipping
|
||||
* @property int|null $points
|
||||
* @property int|null $shipped
|
||||
* @property string|null $tracking
|
||||
|
|
@ -82,6 +82,15 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
|||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingOrder whereWpInvoicePath($value)
|
||||
* @property array|null $wp_notice
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrder whereWpNotice($value)
|
||||
* @property string|null $subtotal_full
|
||||
* @property-read \App\Models\ShoppingOrderMargin|null $shopping_order_margin
|
||||
* @property-read \App\Models\ShoppingPayment|null $shopping_payment_last
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrder whereSubtotalFull($value)
|
||||
* @property string|null $discount
|
||||
* @property string|null $payment_credit
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrder whereDiscount($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrder wherePaymentCredit($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrder whereSubtotalShipping($value)
|
||||
*/
|
||||
class ShoppingOrder extends Model
|
||||
{
|
||||
|
|
@ -97,11 +106,15 @@ class ShoppingOrder extends Model
|
|||
'country_id',
|
||||
'user_shop_id',
|
||||
'total',
|
||||
'subtotal_full',
|
||||
'discount',
|
||||
'subtotal',
|
||||
'shipping',
|
||||
'shipping_net',
|
||||
'subtotal_ws',
|
||||
'subtotal_shipping',
|
||||
'tax',
|
||||
'total_without_credit',
|
||||
'payment_credit',
|
||||
'total_shipping',
|
||||
'points',
|
||||
'weight',
|
||||
|
|
@ -176,6 +189,10 @@ class ShoppingOrder extends Model
|
|||
return $this->hasOne('App\Models\UserHistory','shopping_order_id')->latest();
|
||||
}
|
||||
|
||||
public function shopping_order_margin()
|
||||
{
|
||||
return $this->hasOne('App\Models\ShoppingOrderMargin','shopping_order_id')->latest();
|
||||
}
|
||||
|
||||
public function shopping_order_items(){
|
||||
return $this->hasMany('App\Models\ShoppingOrderItem', 'shopping_order_id');
|
||||
|
|
@ -228,11 +245,21 @@ class ShoppingOrder extends Model
|
|||
return formatNumber($this->attributes['total']);
|
||||
}
|
||||
|
||||
public function getFormattedSubtotalFull()
|
||||
{
|
||||
return formatNumber($this->attributes['subtotal_full']);
|
||||
}
|
||||
|
||||
public function getFormattedSubtotal()
|
||||
{
|
||||
return formatNumber($this->attributes['subtotal']);
|
||||
}
|
||||
|
||||
public function getFormattedDiscount()
|
||||
{
|
||||
return formatNumber($this->attributes['discount']);
|
||||
}
|
||||
|
||||
public function getFormattedShipping()
|
||||
{
|
||||
return formatNumber($this->attributes['shipping']);
|
||||
|
|
@ -243,15 +270,24 @@ class ShoppingOrder extends Model
|
|||
return formatNumber($this->attributes['shipping_net']);
|
||||
}
|
||||
|
||||
public function getFormattedSubtotalWs()
|
||||
public function getFormattedSubtotalShipping()
|
||||
{
|
||||
return formatNumber($this->attributes['subtotal_ws']);
|
||||
return formatNumber($this->attributes['subtotal_shipping']);
|
||||
}
|
||||
|
||||
public function getFormattedTax()
|
||||
{
|
||||
return formatNumber($this->attributes['tax']);
|
||||
}
|
||||
public function getFormattedTotalWithoutCredit()
|
||||
{
|
||||
return formatNumber($this->attributes['total_without_credit']);
|
||||
}
|
||||
public function getFormattedPaymentCredit()
|
||||
{
|
||||
return formatNumber($this->attributes['payment_credit']);
|
||||
}
|
||||
|
||||
|
||||
public function getFormattedTotalShipping()
|
||||
{
|
||||
|
|
|
|||
108
app/Models/ShoppingOrderMargin.php
Normal file
108
app/Models/ShoppingOrderMargin.php
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Created by Reliese Model.
|
||||
*/
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Class ShoppingOrderMargin
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $shopping_order_id
|
||||
* @property int $user_id
|
||||
* @property float|null $net_price
|
||||
* @property float|null $net_discount
|
||||
* @property float|null $net_amount
|
||||
* @property int|null $m_sponsor_id
|
||||
* @property float|null $net_partner_commission
|
||||
* @property Carbon|null $from
|
||||
* @property bool $paid
|
||||
* @property bool $cancellation
|
||||
* @property int $status
|
||||
* @property string|null $content
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
* @property User $user
|
||||
* @property ShoppingOrder $shopping_order
|
||||
* @package App\Models
|
||||
* @property float|null $from_payment_credit
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrderMargin newModelQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrderMargin newQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrderMargin query()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrderMargin whereCancellation($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrderMargin whereContent($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrderMargin whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrderMargin whereFrom($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrderMargin whereFromPaymentCredit($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrderMargin whereId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrderMargin whereMSponsorId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrderMargin whereNetAmount($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrderMargin whereNetDiscount($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrderMargin whereNetPartnerCommission($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrderMargin whereNetPrice($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrderMargin wherePaid($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrderMargin whereShoppingOrderId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrderMargin whereStatus($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrderMargin whereUpdatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrderMargin whereUserId($value)
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class ShoppingOrderMargin extends Model
|
||||
{
|
||||
protected $table = 'shopping_order_margins';
|
||||
|
||||
protected $casts = [
|
||||
'shopping_order_id' => 'int',
|
||||
'user_id' => 'int',
|
||||
'net_price' => 'float',
|
||||
'net_discount' => 'float',
|
||||
'net_amount' => 'float',
|
||||
'from_payment_credit' => 'float',
|
||||
'm_sponsor_id' => 'int',
|
||||
'net_partner_commission' => 'float',
|
||||
'paid' => 'bool',
|
||||
'cancellation' => 'bool',
|
||||
'status' => 'int'
|
||||
];
|
||||
|
||||
protected $dates = [
|
||||
'from'
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'shopping_order_id',
|
||||
'user_id',
|
||||
'net_price',
|
||||
'net_discount',
|
||||
'net_amount',
|
||||
'from_payment_credit',
|
||||
'm_sponsor_id',
|
||||
'net_partner_commission',
|
||||
'from',
|
||||
'paid',
|
||||
'cancellation',
|
||||
'status',
|
||||
'content'
|
||||
];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
public function shopping_order()
|
||||
{
|
||||
return $this->belongsTo(ShoppingOrder::class, 'shopping_order_id');
|
||||
}
|
||||
|
||||
public function m_sponsor_id()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'm_sponsor_id');
|
||||
}
|
||||
}
|
||||
|
|
@ -31,15 +31,21 @@ use Illuminate\Database\Eloquent\Model;
|
|||
* @property array|null $trans_content
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserLevel whereContent($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserLevel whereTransContent($value)
|
||||
* @property bool $partner_provision
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\UserLevelMargin[] $user_level_margins
|
||||
* @property-read int|null $user_level_margins_count
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\UserLevelMargin[] $user_level_margins_re
|
||||
* @property-read int|null $user_level_margins_re_count
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserLevel wherePartnerProvision($value)
|
||||
*/
|
||||
class UserLevel extends Model
|
||||
{
|
||||
protected $table = 'user_levels';
|
||||
|
||||
protected $casts = ['trans_name' => 'array', 'trans_content' => 'array'];
|
||||
protected $casts = ['trans_name' => 'array', 'trans_content' => 'array', 'partner_provision'=>'bool'];
|
||||
|
||||
protected $fillable = [
|
||||
'name', 'content', 'pos', 'active',
|
||||
'name', 'content', 'pos', 'active', 'partner_provision',
|
||||
];
|
||||
|
||||
|
||||
|
|
@ -49,6 +55,17 @@ class UserLevel extends Model
|
|||
}
|
||||
*/
|
||||
|
||||
|
||||
public function user_level_margins()
|
||||
{
|
||||
return $this->hasMany('App\Models\UserLevelMargin', 'user_level_id', 'id');
|
||||
}
|
||||
|
||||
public function user_level_margins_re()
|
||||
{
|
||||
return $this->hasMany('App\Models\UserLevelMargin', 'user_level_id', 'id')->orderBy('price_from', 'DESC');
|
||||
}
|
||||
|
||||
public function setPosAttribute($value){
|
||||
$this->attributes['pos'] = is_numeric($value) ? $value : null;
|
||||
|
||||
|
|
|
|||
90
app/Models/UserLevelMargin.php
Normal file
90
app/Models/UserLevelMargin.php
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Created by Reliese Model.
|
||||
*/
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Services\Util;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Class UserLevelMargin
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $user_level_id
|
||||
* @property float|null $price_from
|
||||
* @property float|null $trading_margin
|
||||
* @property float|null $commission
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
* @property UserLevel $user_level
|
||||
* @package App\Models
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserLevelMargin newModelQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserLevelMargin newQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserLevelMargin query()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserLevelMargin whereCommission($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserLevelMargin whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserLevelMargin whereId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserLevelMargin wherePriceFrom($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserLevelMargin whereTradingMargin($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserLevelMargin whereUpdatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UserLevelMargin whereUserLevelId($value)
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class UserLevelMargin extends Model
|
||||
{
|
||||
protected $table = 'user_level_margins';
|
||||
|
||||
protected $casts = [
|
||||
'user_level_id' => 'int',
|
||||
'price_from' => 'float',
|
||||
'trading_margin' => 'float',
|
||||
'commission' => 'float'
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'user_level_id',
|
||||
'price_from',
|
||||
'trading_margin',
|
||||
'commission'
|
||||
];
|
||||
|
||||
public function user_level()
|
||||
{
|
||||
return $this->belongsTo(UserLevel::class);
|
||||
}
|
||||
|
||||
|
||||
public function setPriceFromAttribute($value)
|
||||
{
|
||||
$this->attributes['price_from'] = $value ? Util::reFormatNumber($value) : 0;
|
||||
}
|
||||
|
||||
public function getFormattedPriceFrom()
|
||||
{
|
||||
return isset($this->attributes['price_from']) ? Util::formatNumber($this->attributes['price_from']) : "";
|
||||
}
|
||||
|
||||
public function setTradingMarginAttribute($value)
|
||||
{
|
||||
$this->attributes['trading_margin'] = $value ? Util::reFormatNumber($value) : 0;
|
||||
}
|
||||
|
||||
public function getFormattedTradingMargin()
|
||||
{
|
||||
return isset($this->attributes['trading_margin']) ? Util::formatNumber($this->attributes['trading_margin']) : "";
|
||||
}
|
||||
|
||||
public function setCommissionAttribute($value)
|
||||
{
|
||||
$this->attributes['commission'] = $value ? Util::reFormatNumber($value) : 0;
|
||||
}
|
||||
|
||||
public function getFormattedCommission()
|
||||
{
|
||||
return isset($this->attributes['commission']) ? Util::formatNumber($this->attributes['commission']) : "";
|
||||
}
|
||||
}
|
||||
|
|
@ -128,7 +128,7 @@ class ContractPDFRepository extends BaseRepository {
|
|||
if(!Storage::disk($this->disk)->exists( $this->dir )){
|
||||
Storage::disk($this->disk)->makeDirectory($this->dir); //creates directory
|
||||
}
|
||||
$filename = "Beratervertrag.pdf";
|
||||
$filename = "Vertriebspartnervertrag.pdf";
|
||||
Storage::disk($this->disk)->put($this->dir.$filename, $pdf->Output('S'));
|
||||
$size = Storage::disk($this->disk)->size($this->dir.$filename);
|
||||
$mine = Storage::disk($this->disk)->getMimeType($this->dir.$filename);
|
||||
|
|
|
|||
|
|
@ -27,9 +27,8 @@ class ProductRepository extends BaseRepository {
|
|||
{
|
||||
|
||||
$data['active'] = isset($data['active']) ? 1 : 0;
|
||||
$data['shipping_addon'] = isset($data['shipping_addon']) ? 1 : 0;
|
||||
|
||||
|
||||
$data['single_commission'] = isset($data['single_commission']) ? 1 : 0;
|
||||
$data['amount_commission'] = isset($data['amount_commission']) ? 1 : 0;
|
||||
if($data['id'] === "new"){
|
||||
$this->model = Product::create($data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,6 +65,29 @@ class HTMLHelper
|
|||
|
||||
}
|
||||
|
||||
public static function setContentReadMore($content){
|
||||
|
||||
$sep = '##mehr lesen##';
|
||||
if(strpos($content, $sep) !== false){
|
||||
$name = 'collapse_'.random_int(1000, 10000);
|
||||
$split = explode($sep, $content);
|
||||
$first = isset($split[0]) ? $split[0] : "";
|
||||
$text = isset($split[1]) ? $split[1] : "";
|
||||
|
||||
$content = $first;
|
||||
$content .= '<br><a class="btn btn-primary btn-sm mt-2 collapsed" data-toggle="collapse" href="#'.$name.'" role="button" aria-expanded="false" aria-controls="'.$name.'">
|
||||
<span class="if-collapsed">'.__('mehr lesen').'</span>
|
||||
<span class="if-not-collapsed">'.__('weniger lesen').'</span>
|
||||
</a>';
|
||||
$content .= '<div class="collapse" id="'.$name.'">
|
||||
<div class="card card-body pt-0">
|
||||
'.$text.'
|
||||
</div>
|
||||
</div>';
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
|
||||
public static function getRolesOptions(){
|
||||
$ret = "";
|
||||
foreach (self::$roles as $role_id => $value){
|
||||
|
|
|
|||
|
|
@ -141,6 +141,21 @@ class Payment
|
|||
|
||||
}
|
||||
}
|
||||
//if the order has action
|
||||
if($shopping_order->shopping_user->is_from === 'user_order'){
|
||||
//is margin -> set paid
|
||||
$shopping_order->shopping_order_margin->paid = true;
|
||||
$shopping_order->shopping_order_margin->save();
|
||||
//is payment credit, reduce
|
||||
if($shopping_order->shopping_order_margin->from_payment_credit > 0){
|
||||
$new_credit = $shopping_order->auth_user->payment_credit - $shopping_order->shopping_order_margin->from_payment_credit;
|
||||
$new_credit = $new_credit < 0 ? 0 : $new_credit;
|
||||
$shopping_order->auth_user->payment_credit = $new_credit;
|
||||
$shopping_order->auth_user->save();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return $send_link;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,10 +43,10 @@ class Slim {
|
|||
if (empty($value)) {return null;}
|
||||
|
||||
// If magic quotes enabled
|
||||
if (get_magic_quotes_gpc()) {
|
||||
/* if (get_magic_quotes_gpc()) {
|
||||
$value = stripslashes($value);
|
||||
}
|
||||
|
||||
*/
|
||||
// The data is posted as a JSON String so to be used it needs to be deserialized first
|
||||
$data = json_decode($value);
|
||||
|
||||
|
|
|
|||
87
app/Services/UserMarign.php
Normal file
87
app/Services/UserMarign.php
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
namespace App\Services;
|
||||
|
||||
|
||||
use App\Models\ShoppingOrderMargin;
|
||||
use App\User;
|
||||
use Carbon;
|
||||
|
||||
class UserMarign
|
||||
{
|
||||
|
||||
|
||||
|
||||
public static function getMontlyPrice(User $user, $date = null, $format = false){
|
||||
|
||||
$now = $date ? Carbon::parse($date) : Carbon::now();
|
||||
$startDay = $now->startOfMonth()->toDateString();
|
||||
$endDay = $now->endOfMonth()->toDateString();
|
||||
|
||||
$sum_net_amount = ShoppingOrderMargin::whereUserId($user->id)
|
||||
->whereBetween('from', [$startDay, $endDay])
|
||||
->wherePaid(true)
|
||||
->whereCancellation(false)
|
||||
->sum('net_price');
|
||||
if($format){
|
||||
$sum_net_amount = Util::formatNumber($sum_net_amount);
|
||||
}
|
||||
return $sum_net_amount;
|
||||
}
|
||||
|
||||
public static function getMontlyPriceOpen(User $user, $date = null, $format = false){
|
||||
|
||||
$now = $date ? Carbon::parse($date) : Carbon::now();
|
||||
$startDay = $now->startOfMonth()->toDateString();
|
||||
$endDay = $now->endOfMonth()->toDateString();
|
||||
|
||||
$sum_net_amount = ShoppingOrderMargin::whereUserId($user->id)
|
||||
->whereBetween('from', [$startDay, $endDay])
|
||||
->wherePaid(false)
|
||||
->whereCancellation(false)
|
||||
->sum('net_price');
|
||||
if($format){
|
||||
$sum_net_amount = Util::formatNumber($sum_net_amount);
|
||||
}
|
||||
return $sum_net_amount;
|
||||
}
|
||||
|
||||
public static function getMontlyAmount(User $user, $date = null, $format = false){
|
||||
|
||||
$now = $date ? Carbon::parse($date) : Carbon::now();
|
||||
$startDay = $now->startOfMonth()->toDateString();
|
||||
$endDay = $now->endOfMonth()->toDateString();
|
||||
|
||||
$sum_net_amount = ShoppingOrderMargin::whereUserId($user->id)
|
||||
->whereBetween('from', [$startDay, $endDay])
|
||||
->wherePaid(true)
|
||||
->whereCancellation(false)
|
||||
->sum('net_amount');
|
||||
if($format){
|
||||
$sum_net_amount = Util::formatNumber($sum_net_amount);
|
||||
}
|
||||
|
||||
return $sum_net_amount;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function getMontlyPartnerCommission(User $user, $date = null, $format = false){
|
||||
|
||||
$now = $date ? Carbon::parse($date) : Carbon::now();
|
||||
$startDay = $now->startOfMonth()->toDateString();
|
||||
$endDay = $now->endOfMonth()->toDateString();
|
||||
|
||||
$sum_net_amount = ShoppingOrderMargin::whereMSponsorId($user->id)
|
||||
->whereBetween('from', [$startDay, $endDay])
|
||||
->wherePaid(true)
|
||||
->whereCancellation(false)
|
||||
->sum('net_partner_commission');
|
||||
if($format){
|
||||
$sum_net_amount = Util::formatNumber($sum_net_amount);
|
||||
}
|
||||
|
||||
return $sum_net_amount;
|
||||
}
|
||||
//monthy amount, sum
|
||||
|
||||
}
|
||||
|
|
@ -3,6 +3,9 @@ namespace App\Services;
|
|||
|
||||
use App\Models\Product;
|
||||
use App\Models\ShippingCountry;
|
||||
use App\Services\Yard\Commission;
|
||||
use App\Services\Yard\Margin;
|
||||
use App\Services\Yard\MarginItems;
|
||||
use Gloudemans\Shoppingcart\Cart;
|
||||
use Gloudemans\Shoppingcart\CartItem;
|
||||
use Gloudemans\Shoppingcart\Contracts\Buyable;
|
||||
|
|
@ -23,6 +26,13 @@ class Yard extends Cart
|
|||
private $ysession;
|
||||
private $yinstance;
|
||||
private $shopping_data = [];
|
||||
private $user;
|
||||
private $payment_credit;
|
||||
|
||||
private $yard_commission;
|
||||
private $yard_margin;
|
||||
|
||||
private $global_tax_rate = 19;
|
||||
|
||||
public function __construct(SessionManager $session, Dispatcher $events)
|
||||
{
|
||||
|
|
@ -52,6 +62,25 @@ class Yard extends Cart
|
|||
$this->shipping_is_for = $this->getYardExtra('shipping_is_for');
|
||||
}
|
||||
|
||||
if($this->getYardExtra('shopping_user')){
|
||||
$this->user = $this->getYardExtra('shopping_user');
|
||||
}
|
||||
|
||||
if($this->getYardExtra('user')){
|
||||
$this->user = $this->getYardExtra('user');
|
||||
}
|
||||
if($this->getYardExtra('payment_credit')){
|
||||
$this->payment_credit = $this->getYardExtra('payment_credit');
|
||||
}
|
||||
|
||||
if($this->getYardExtra('yard_commission')){
|
||||
$this->yard_commission = $this->getYardExtra('yard_commission');
|
||||
}
|
||||
|
||||
if($this->getYardExtra('yard_margin')){
|
||||
$this->yard_margin = $this->getYardExtra('yard_margin');
|
||||
}
|
||||
|
||||
/*if($this->getYardExtra('num_comp')){
|
||||
$this->num_comp = $this->getYardExtra('num_comp');
|
||||
}*/
|
||||
|
|
@ -123,10 +152,111 @@ class Yard extends Cart
|
|||
}
|
||||
|
||||
|
||||
public function reCalculateShippingPrice(){
|
||||
public function reCalculate(){
|
||||
$this->calculateShippingPrice();
|
||||
}
|
||||
/* * ***** */
|
||||
|
||||
public function calculateMargins(){
|
||||
//get user monthy amount
|
||||
$monthy_amount = UserMarign::getMontlyAmount($this->user);
|
||||
|
||||
$content = $this->getContent();
|
||||
|
||||
/*single + partner Commissions */
|
||||
//get price net commission, add amount, partner (total) from products is single_commission
|
||||
$yard_commission = new Commission();
|
||||
$yard_commission = $content->reduce(function ($yard_commission, CartItem $cartItem) {
|
||||
$price_net = $cartItem->price / ((100 + $cartItem->taxRate) / 100);
|
||||
if($cartItem->options->single_commission){
|
||||
$value_commission = $price_net / 100 * $cartItem->options->value_commission;
|
||||
$partner_commission = $price_net / 100 * $cartItem->options->partner_commission;
|
||||
|
||||
$price_net_commission = ($cartItem->qty * $price_net) - ($cartItem->qty * $value_commission);
|
||||
$yard_commission->single_price_net += ($cartItem->qty * $price_net);
|
||||
$yard_commission->single_value_commission += ($cartItem->qty * $value_commission);
|
||||
if($this->user->user_level->partner_provision){
|
||||
$yard_commission->single_partner_commission += ($cartItem->qty * $partner_commission);
|
||||
}
|
||||
$yard_commission->single_price_net_commission += $price_net_commission;
|
||||
//
|
||||
if($cartItem->options->amount_commission){
|
||||
$yard_commission->single_amount_commission += $price_net_commission;
|
||||
}
|
||||
}else{
|
||||
$yard_commission->price_net = $yard_commission->price_net + ($cartItem->qty * $price_net);
|
||||
}
|
||||
return $yard_commission;
|
||||
}, $yard_commission);
|
||||
|
||||
$this->yard_commission = $yard_commission;
|
||||
$this->putYardExtra('yard_commission', $this->yard_commission);
|
||||
|
||||
//dump($monthy_amount);
|
||||
//add to $monthy_amount für max level margins
|
||||
$start_monthy_amount = $monthy_amount + $yard_commission->single_amount_commission;
|
||||
$end_monthy_amount = $start_monthy_amount + $yard_commission->price_net;
|
||||
|
||||
//dump($start_monthy_amount);
|
||||
//dump($end_monthy_amount);
|
||||
|
||||
$margin = new Margin();
|
||||
$rest_amount = 0;
|
||||
$range = 0;
|
||||
$price_net = $yard_commission->price_net;
|
||||
if($yard_commission->price_net > 0 && $this->user && $this->user->user_level && $this->user->user_level->user_level_margins){
|
||||
foreach ($this->user->user_level->user_level_margins_re as $user_level_margin) {
|
||||
//total split?
|
||||
if ($end_monthy_amount >= $user_level_margin->price_from) {
|
||||
if(!isset($balance)){
|
||||
if($start_monthy_amount >= $user_level_margin->price_from){
|
||||
$balance = $yard_commission->price_net;
|
||||
$rest_amount = 0;
|
||||
}else{
|
||||
$balance = $end_monthy_amount - $user_level_margin->price_from;
|
||||
$rest_amount = $end_monthy_amount - ($start_monthy_amount + $balance);
|
||||
}
|
||||
}else{
|
||||
$range = $last_limit-$user_level_margin->price_from;
|
||||
if($rest_amount >= $range){
|
||||
$balance = $range;
|
||||
}else{
|
||||
$balance = $rest_amount;
|
||||
}
|
||||
$rest_amount = $rest_amount-$balance;
|
||||
}
|
||||
$last_limit = $user_level_margin->price_from;
|
||||
if($balance != 0){
|
||||
$margin->add($user_level_margin->price_from, [
|
||||
'price_net' => $price_net,
|
||||
'range' => $range,
|
||||
'rest_amount' => $rest_amount,
|
||||
'balance' => $balance,
|
||||
'trading_margin'=> $user_level_margin->trading_margin,
|
||||
'commission'=> $user_level_margin->commission,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$margin->setCommission($this->yard_commission);
|
||||
$margin->calculate();
|
||||
|
||||
$this->yard_margin = $margin;
|
||||
$this->putYardExtra('yard_margin', $this->yard_margin);
|
||||
|
||||
//dump($margin);
|
||||
}
|
||||
|
||||
public function getYardMargin(){
|
||||
return $this->yard_margin;
|
||||
}
|
||||
public function getYardCommission(){
|
||||
return $this->yard_commission;
|
||||
}
|
||||
/* * ***** */
|
||||
public function setShippingCountryWithPrice($shipping_country_id, $shipping_is_for = 'ot')
|
||||
{
|
||||
$this->shipping_country_id = $shipping_country_id;
|
||||
|
|
@ -139,6 +269,21 @@ class Yard extends Cart
|
|||
|
||||
}
|
||||
|
||||
public function setShoppingUser($user, $payment_credit = false){
|
||||
$this->user = $user;
|
||||
$this->payment_credit = $payment_credit;
|
||||
$this->putYardExtra('user', $user);
|
||||
$this->putYardExtra('payment_credit', $payment_credit);
|
||||
|
||||
}
|
||||
|
||||
public function getPaymentCredit(){
|
||||
if($this->payment_credit && $this->user->payment_credit > 0){
|
||||
return $this->user->payment_credit;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private function calculateShippingPrice(){
|
||||
|
||||
$shippingCountry = ShippingCountry::find($this->shipping_country_id);
|
||||
|
|
@ -151,10 +296,8 @@ class Yard extends Cart
|
|||
$shipping_price->price = 0;
|
||||
$shipping_price->price_comp = 0;
|
||||
}else{
|
||||
|
||||
|
||||
//first by price
|
||||
$shipping_price = $this->shippingPriceByTotal($shipping->shipping_prices, $this->total(2, '.', ''));
|
||||
$shipping_price = $this->shippingPriceBySubTotal($shipping->shipping_prices, $this->subtotal(2, '.', ''));
|
||||
//sec by weight
|
||||
if(!$shipping_price){
|
||||
$shipping_price = $this->shippingPriceByWeight($shipping->shipping_prices, $this->weight());
|
||||
|
|
@ -186,7 +329,7 @@ class Yard extends Cart
|
|||
}
|
||||
}
|
||||
|
||||
private function shippingPriceByTotal($prices, $total){
|
||||
private function shippingPriceBySubTotal($prices, $total){
|
||||
foreach ($prices as $price){
|
||||
if($price->total_from > 0 && $price->total_to > 0){
|
||||
if($total >= $price->total_from && $total <= $price->total_to){
|
||||
|
|
@ -243,19 +386,56 @@ class Yard extends Cart
|
|||
|
||||
public function taxWithShipping($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
||||
{
|
||||
$total = $this->totalWithShipping(2, '.', '');
|
||||
|
||||
// $total = $this->totalWithShipping(2, '.', '');
|
||||
// $totalTax = (float) $this->tax(2, '.', '') + $this->shipping_tax;
|
||||
$totalTax = $this->subtotalWithShipping(2, '.', '');
|
||||
return $this->numberFormat(($total - $totalTax), $decimals, $decimalPoint, $thousandSeperator);
|
||||
$subtotal_shipping = $this->subtotalWithShipping(2, '.', '');
|
||||
return $this->numberFormat(($subtotal_shipping / 100 * $this->global_tax_rate), $decimals, $decimalPoint, $thousandSeperator);
|
||||
}
|
||||
|
||||
|
||||
public function totalWithShipping($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
||||
{
|
||||
$total = (float) ($this->total(2, '.', '')) + $this->shipping_price;
|
||||
//$total = (float) ($this->total(2, '.', '')) + $this->shipping_price;
|
||||
$subtotal_shipping = $this->subtotalWithShipping(2, '.', '');
|
||||
$tax = $subtotal_shipping / 100 * $this->global_tax_rate;
|
||||
$total = ($subtotal_shipping + $tax);
|
||||
if($PaymentCredit = $this->getPaymentCredit()){
|
||||
$total = $total - $PaymentCredit;
|
||||
if($total < 0){
|
||||
$total = 0;
|
||||
}
|
||||
}
|
||||
return $this->numberFormat($total, $decimals, $decimalPoint, $thousandSeperator);
|
||||
}
|
||||
|
||||
|
||||
public function totalWithShippingWithoutCredit($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
||||
{
|
||||
//$total = (float) ($this->total(2, '.', '')) + $this->shipping_price;
|
||||
$subtotal_shipping = $this->subtotalWithShipping(2, '.', '');
|
||||
$tax = $subtotal_shipping / 100 * $this->global_tax_rate;
|
||||
$total = ($subtotal_shipping + $tax);
|
||||
return $this->numberFormat($total, $decimals, $decimalPoint, $thousandSeperator);
|
||||
}
|
||||
|
||||
public function totalfromCredit($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
||||
{
|
||||
$rest = 0;
|
||||
if ($PaymentCredit = $this->getPaymentCredit()) {
|
||||
$subtotal_shipping= $this->subtotalWithShipping(2, '.', '');
|
||||
$tax = $subtotal_shipping/ 100 * $this->global_tax_rate;
|
||||
$total = ($subtotal_shipping+ $tax);
|
||||
$rest = $PaymentCredit - $total;
|
||||
if($rest < 0){
|
||||
$rest = $PaymentCredit;
|
||||
}else{
|
||||
$rest = $PaymentCredit - $rest;
|
||||
}
|
||||
}
|
||||
return $this->numberFormat($rest, $decimals, $decimalPoint, $thousandSeperator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total price of the items in the cart.
|
||||
*
|
||||
|
|
@ -270,7 +450,6 @@ class Yard extends Cart
|
|||
$total = $content->reduce(function ($total, CartItem $cartItem) {
|
||||
return $total + ($cartItem->options->weight ? ($cartItem->options->weight*$cartItem->qty) : 0);
|
||||
}, 0);
|
||||
|
||||
return $total;
|
||||
}
|
||||
|
||||
|
|
@ -280,7 +459,6 @@ class Yard extends Cart
|
|||
$total = $content->reduce(function ($total, CartItem $cartItem) {
|
||||
return $total + ($cartItem->options->points ? ($cartItem->options->points * $cartItem->qty) : 0);
|
||||
}, 0);
|
||||
|
||||
return $total;
|
||||
}
|
||||
|
||||
|
|
@ -312,10 +490,8 @@ class Yard extends Cart
|
|||
|
||||
if ($withFees === true) {
|
||||
$fees = $this->feeTotal(null, null, null, true);
|
||||
|
||||
$total = $total + $fees;
|
||||
}
|
||||
|
||||
return $this->numberFormat($total, $decimals, $decimalPoint, $thousandSeperator);
|
||||
}
|
||||
|
||||
|
|
@ -340,7 +516,6 @@ class Yard extends Cart
|
|||
|
||||
if ($withFees === true) {
|
||||
$fees = $this->feeTax();
|
||||
|
||||
$tax = $tax + floatval($fees);
|
||||
}
|
||||
|
||||
|
|
@ -356,7 +531,7 @@ class Yard extends Cart
|
|||
* @param string $thousandSeperator
|
||||
* @return float
|
||||
*/
|
||||
public function subtotal($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
||||
public function subtotal($decimals = null, $decimalPoint = null, $thousandSeperator = null, $discount = true)
|
||||
{
|
||||
$content = $this->getContent();
|
||||
|
||||
|
|
@ -365,6 +540,9 @@ class Yard extends Cart
|
|||
return $subTotal + ($cartItem->qty * $price_net);
|
||||
}, 0);
|
||||
|
||||
if($discount && $this->yard_margin){
|
||||
$subTotal -= $this->yard_margin->net_discount;
|
||||
}
|
||||
return $this->numberFormat($subTotal, $decimals, $decimalPoint, $thousandSeperator);
|
||||
}
|
||||
|
||||
|
|
@ -379,7 +557,17 @@ class Yard extends Cart
|
|||
if($set_price === 'with'){
|
||||
$price = $product->getPriceWith(false, true);
|
||||
}
|
||||
$cartItem = $this->getCartItem($product->id, $product->getLang('name'), 1, $price, ['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points]);
|
||||
$cartItem = $this->getCartItem($product->id, $product->getLang('name'), 1, $price,
|
||||
[
|
||||
'image' => $image,
|
||||
'slug' => $product->slug,
|
||||
'weight' => $product->weight,
|
||||
'single_commission' => $product->single_commission,
|
||||
'amount_commission' => $product->amount_commission,
|
||||
'value_commission' => $product->value_commission,
|
||||
'partner_commission' => $product->partner_commission,
|
||||
]
|
||||
);
|
||||
$content = $this->getContent();
|
||||
|
||||
if ($content->has($cartItem->rowId)){
|
||||
|
|
|
|||
34
app/Services/Yard/Commission.php
Normal file
34
app/Services/Yard/Commission.php
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
namespace App\Services\Yard;
|
||||
|
||||
|
||||
use App\Services\Util;
|
||||
|
||||
class Commission
|
||||
{
|
||||
public $price_net;
|
||||
public $single_price_net;
|
||||
public $single_value_commission;
|
||||
public $single_partner_commission;
|
||||
public $single_amount_commission;
|
||||
public $single_price_net_commission;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->price_net = 0;
|
||||
$this->single_price_net = 0;
|
||||
$this->single_amount_commission = 0;
|
||||
$this->single_partner_commission = 0;
|
||||
$this->single_value_commission = 0;
|
||||
$this->single_price_net_commission = 0;
|
||||
}
|
||||
|
||||
public function isCommission(){
|
||||
return ($this->single_value_commission > 0) ? true : false;
|
||||
}
|
||||
|
||||
public function getFormatted($key)
|
||||
{
|
||||
return isset($this->{$key}) ? Util::formatNumber($this->{$key}) : "";
|
||||
}
|
||||
}
|
||||
104
app/Services/Yard/Margin.php
Normal file
104
app/Services/Yard/Margin.php
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
namespace App\Services\Yard;
|
||||
|
||||
use App\Services\Util;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class Margin
|
||||
{
|
||||
public $items;
|
||||
public $commission;
|
||||
public $net_discount;
|
||||
public $net_partner_commission;
|
||||
public $net_price;
|
||||
public $net_amount;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->items = new Collection;
|
||||
}
|
||||
|
||||
public function add($price_from, $values){
|
||||
$this->items->push(new MarginItems($price_from, $values));
|
||||
}
|
||||
|
||||
public function setCommission(Commission $commission){
|
||||
$this->commission = $commission;
|
||||
}
|
||||
public function isMargin(){
|
||||
return count($this->items) ? true : false;
|
||||
}
|
||||
|
||||
public function calculate(){
|
||||
|
||||
if($this->commission){
|
||||
$this->net_discount += $this->commission->single_value_commission;
|
||||
$this->net_partner_commission += $this->commission->single_partner_commission;
|
||||
$this->net_amount += $this->commission->single_amount_commission;
|
||||
$this->net_price += $this->commission->single_price_net_commission;
|
||||
|
||||
}
|
||||
|
||||
if($this->isMargin()){
|
||||
foreach ($this->items as $item){
|
||||
$this->net_discount += $item->value_margin;
|
||||
$this->net_partner_commission += $item->value_commission;
|
||||
$this->net_amount += $item->new_price_net;
|
||||
$this->net_price += $item->new_price_net;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public function getFormatted($key)
|
||||
{
|
||||
return isset($this->{$key}) ? Util::formatNumber($this->{$key}) : "";
|
||||
}
|
||||
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
return [
|
||||
'items' => $this->items,
|
||||
'commission' => $this->commission,
|
||||
'net_discount' => $this->net_discount,
|
||||
'net_partner_commission' => $this->net_partner_commission,
|
||||
'net_price' => $this->net_price,
|
||||
'net_amount' => $this->net_amount,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function restore($content)
|
||||
{
|
||||
|
||||
// Unserialize the content (either array if new, or collection if old)
|
||||
$storedContent = unserialize($content);
|
||||
|
||||
if (is_array($storedContent)) {
|
||||
$this->fromArray($storedContent);
|
||||
}
|
||||
//TODO - check this
|
||||
// If the old approach and is Collection, push into existing items
|
||||
/* if ($storedContent instanceof Collection) {
|
||||
foreach ($storedContent as $item) {
|
||||
$this->items->put($item);
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function fromArray($array)
|
||||
{
|
||||
$this->items = $array['items'];
|
||||
$this->commission = $array['commission'];
|
||||
$this->net_discount = $array['net_discount'];
|
||||
$this->net_partner_commission = $array['net_partner_commission'];
|
||||
$this->net_price = $array['net_price'];
|
||||
$this->net_amount = $array['net_amount'];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
46
app/Services/Yard/MarginItems.php
Normal file
46
app/Services/Yard/MarginItems.php
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
namespace App\Services\Yard;
|
||||
|
||||
use App\Services\Util;
|
||||
|
||||
class MarginItems
|
||||
{
|
||||
public $price_from;
|
||||
public $range;
|
||||
public $rest_amount;
|
||||
|
||||
public $balance;
|
||||
|
||||
public $value_margin;
|
||||
public $new_price_net;
|
||||
public $trading_margin;
|
||||
|
||||
public $value_commission;
|
||||
public $commission;
|
||||
|
||||
public function __construct($price_from, $values)
|
||||
{
|
||||
$this->price_from = $price_from;
|
||||
$this->range = $values['range'];
|
||||
$this->rest_amount = $values['rest_amount'];
|
||||
$this->balance = $values['balance'];
|
||||
$this->trading_margin = $values['trading_margin'];
|
||||
$this->commission = $values['commission'];
|
||||
$this->calculate();
|
||||
}
|
||||
|
||||
public function calculate(){
|
||||
$this->value_margin = $this->balance / 100 * $this->trading_margin;
|
||||
$this->new_price_net = $this->balance - $this->value_margin;
|
||||
if($this->commission > 0){
|
||||
$this->value_commission = $this->balance / 100 * $this->commission;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getFormatted($key)
|
||||
{
|
||||
return isset($this->{$key}) ? Util::formatNumber($this->{$key}) : "";
|
||||
}
|
||||
}
|
||||
|
|
@ -96,6 +96,8 @@ use Util;
|
|||
* @property string|null $payment_account
|
||||
* @property-read \App\Models\UserLevel|null $next_user_level
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|User wherePaymentAccount($value)
|
||||
* @property string|null $payment_credit
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|User wherePaymentCredit($value)
|
||||
*/
|
||||
class User extends Authenticatable
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue