Updates to 03-2025

This commit is contained in:
Kevin Adametz 2025-04-01 10:36:47 +02:00
parent bfa3bb1df4
commit 9ae662f63e
243 changed files with 12580 additions and 12018 deletions

View file

@ -0,0 +1,322 @@
<?php
namespace App\Http\Controllers\User;
use App\Http\Controllers\Controller;
use App\Models\Product;
use App\Models\ShoppingUser;
use App\Models\UserAbo;
use App\Models\UserAboItem;
use App\Repositories\AboRepository;
use App\Services\AboHelper;
use App\Services\AboOrderCart;
use App\Services\Shop;
use App\Services\UserService;
use App\User;
use Request;
use Yard;
class AboController extends Controller
{
protected $aboRepository;
public function __construct(AboRepository $aboRepository)
{
$this->middleware('active.account');
$this->aboRepository = $aboRepository;
}
public function index($view)
{
if ($view === 'me') {
// Nur Abos des aktuellen Benutzers
$user_abos = UserAbo::where('user_id', \Auth::user()->id)
->where('status', '>', 1);
if ($user_abos->count() > 0) {
return redirect(route('user_abos_detail', ['me', $user_abos->first()->id]));
}
return view('user.abo.index', [
'user_abos' => [],
'view' => 'me',
'isAdmin' => false
]);
}
if ($view === 'ot') {
$user_abos = UserAbo::where('member_id', \Auth::user()->id)
->where('status', '>', 1)
->where('is_for', 'ot')
->orderBy('id', 'desc')
->get();
return view('user.abo.index', [
'user_abos' => $user_abos,
'view' => 'ot',
'isAdmin' => false
]);
}
// Standardfall, wenn weder 'me' noch 'ot'
return view('user.abo.index', [
'user_abos' => [],
'view' => 'me',
'isAdmin' => false
]);
}
public function detail($view, $id)
{
$data = Request::all();
$user_abo = UserAbo::findOrFail($id);
$this->checkPermissions($view, $user_abo);
//init Yard
AboOrderCart::initYard($user_abo);
//holt die aktuellen UserAccount Daten oder die Userdaten des Abo
$customer_detail = AboOrderCart::getCustomerDetail();
AboOrderCart::makeOrderYard($user_abo);
$comp_products = [];
if ($user_abo->is_for === 'me') {
$comp_products = Shop::getCompProducts('abo-me');
}
$data = [
'user_abo' => $user_abo,
'isAdmin' => false,
'customer_detail' => $customer_detail,
'view' => $view,
'comp_products' => $comp_products,
];
return view('user.abo.detail', $data);
}
public function update($view, $id)
{
$data = Request::all();
$user_abo = UserAbo::findOrFail($id);
$this->checkPermissions($view, $user_abo);
if (isset($data['action'])) {
if ($data['action'] === 'abo_update_settings') {
$user_abo = UserAbo::findOrFail($data['id']);
$this->aboRepository->setModel($user_abo);
$this->aboRepository->update($data);
return redirect(route('user_abos_detail', [$view, $id]));
}
if (Request::ajax()) {
$message = false;
//addProduct
if ($data['action'] === 'addProduct') {
if ($product = Product::find($data['product_id'])) {
if ($UserAboItem = UserAboItem::where('user_abo_id', $user_abo->id)->where('product_id', $product->id)->where('comp', 0)->first()) {
$UserAboItem->qty = $UserAboItem->qty + 1;
$UserAboItem->save();
} else {
UserAboItem::create([
'user_abo_id' => $user_abo->id,
'product_id' => $product->id,
'comp' => 0,
'qty' => 1,
'status' => 1,
]);
}
}
}
//updateCart
if ($data['action'] === 'updateCart') {
//product_id | order_item_id | cart_order_id | qty
if (isset($data['product_id']) && $product = Product::find($data['product_id'])) {
if (isset($data['order_item_id']) && $UserAboItem = UserAboItem::find($data['order_item_id'])) {
if (isset($data['qty'])) {
$qty = (int) $data['qty'];
$qty = $qty < 1 ? 1 : $qty;
$qty = $qty > 100 ? 100 : $qty;
$UserAboItem->qty = $qty;
$UserAboItem->save();
}
}
}
}
//removeFromCart
if ($data['action'] === 'removeFromCart') {
if (!isset($data['product_id']) || !($product = Product::find($data['product_id']))) {
$message = __('abo.product_not_found');
}
if (!isset($data['order_item_id']) || !($userAboItem = UserAboItem::find($data['order_item_id']))) {
$message = __('abo.abo_item_not_found');
}
$has_basis_product = $this->check_need_basis_product($user_abo, $product, $data['order_item_id']);
if (!$has_basis_product) {
$message = __('abo.need_basis_product');
}
if (!$message) {
$userAboItem->delete();
$user_abo->refresh(); // Abo neu laden um die aktualisierten Items zu erhalten
}
}
//updateCompProduct
if ($data['action'] === 'updateCompProduct') {
if ($UserAboItem = UserAboItem::where('user_abo_id', $user_abo->id)->where('comp', $data['comp_num'])->first()) {
$UserAboItem->product_id = $data['comp_product_id'];
$UserAboItem->save();
} else {
UserAboItem::create([
'user_abo_id' => $user_abo->id,
'product_id' => $data['comp_product_id'],
'comp' => $data['comp_num'],
'qty' => 1,
'status' => 1,
]);
}
}
AboOrderCart::initYard($user_abo);
AboOrderCart::makeOrderYard($user_abo); //reCalculateShippingPrice
AboOrderCart::checkNumOfCompProducts($user_abo); //after reCalculateShippingPrice check it and remove or add comp product
if ($user_abo->is_for === 'me') {
$data['comp_products'] = Shop::getCompProducts('abo-me');
}
$error_message = $message ? $message : false;
$html_cart = view("admin.abo._order_abo_show", ['user_abo' => $user_abo, 'error_message' => $error_message])->render();
$html_comp = view("user.order.comp_product", $data)->render();
$amount = $user_abo->getFormattedAmount();
// $html_total = view("user.homeparty.show_total_order", ['homeparty' => $homeparty])->render();
return response()->json(['response' => true, 'data' => $data, 'html_cart' => $html_cart, 'html_comp' => $html_comp, 'amount' => $amount]);
}
}
}
public function check_need_basis_product($user_abo, $product, $order_item_id)
{
// Wenn das zu entfernende Produkt kein Basis-Produkt ist, keine weitere Prüfung nötig
if (AboHelper::getAboShowOn($product) !== 'base') {
return true;
}
// Prüfe ob noch ein anderes Basis-Produkt vorhanden ist
foreach ($user_abo->user_abo_items as $user_abo_item) {
if ($user_abo_item->id == $order_item_id) {
continue;
}
if (AboHelper::getAboShowOn($user_abo_item->product) === 'base') {
return true;
}
}
return false;
}
public function datatable($user_abo_id)
{
$user_abo = UserAbo::findOrFail($user_abo_id);
if (!$user_abo) {
abort(404);
}
//$user_abo->is_for === 'me'
$show_on_ids = ['12', '13'];
$query = Product::select('products.*')
->where('active', true)
->where(function ($q) use ($show_on_ids) {
foreach ($show_on_ids as $id) {
$q->orWhereJsonContains('show_on', $id);
}
})
->orderByRaw(
"CASE
WHEN JSON_CONTAINS(show_on, ?, '$') THEN 1
WHEN JSON_CONTAINS(show_on, ?, '$') THEN 2
ELSE 3 END",
[$show_on_ids[0], isset($show_on_ids[1]) ? $show_on_ids[1] : $show_on_ids[0]]
);
return \DataTables::eloquent($query)
->addColumn('add_card', function (Product $product) use ($user_abo) {
$ufactor = $user_abo->is_for === 'me' ? true : false;
$tax_free = $user_abo->is_for === 'me' ? true : Yard::instance('shopping')->getUserTaxFree();
return '<button type="button" class="btn btn-sm btn-md-extra btn-secondary add-product-basket" data-product-id="' . $product->id . '">
<strong>&euro; ' . $product->getFormattedPriceWith($tax_free, $ufactor, Yard::instance('shopping')->getUserCountry()) . '</strong>&nbsp; +<span class="ion ion-md-cart"></span>
</button>';
})
->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]) . '">';
}
return "";
})
->addColumn('name', function (Product $product) use ($user_abo) {
return '<strong>' . $product->getLang('name') . '</strong><br>' . get_abo_type_badge_by_product($product);
})
->addColumn('price_net', function (Product $product) use ($user_abo) {
$ufactor = $user_abo->is_for === 'me' ? true : false;
return '<span class="no-line-break">' . $product->getFormattedPriceWith(true, $ufactor, Yard::instance('shopping')->getUserCountry()) . " €</span>" . '<span class="no-line-break">' . $product->getFormattedPriceCurrencyWith(true, true, Yard::instance('shopping')->getUserCountry()) . '</span>';
})
->addColumn('price_gross', function (Product $product) use ($user_abo) {
$ufactor = $user_abo->is_for === 'me' ? true : false;
return '<span class="no-line-break">' . $product->getFormattedPriceWith(false, $ufactor, Yard::instance('shopping')->getUserCountry()) . " €</span>" . '<span class="no-line-break">' . $product->getFormattedPriceCurrencyWith(true, true, Yard::instance('shopping')->getUserCountry()) . '</span>';
})
->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"
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>';
})
->filterColumn('product', function ($query, $keyword) {
if ($keyword != "") {
$query->where('name', 'LIKE', '%' . $keyword . '%');
}
})
->orderColumn('name', 'name $1')
->orderColumn('product', 'name $1')
->orderColumn('number', 'number $1')
->orderColumn('points', 'points $1')
->orderColumn('price_net', 'price_net $1')
->orderColumn('price_gross', 'price_gross $1')
->orderColumn('contents_total', 'contents_total $1')
->orderColumn('weight', 'weight $1')
->rawColumns(['add_card', 'product', 'name', 'quantity', 'picture', 'price_net', 'price_gross', 'action'])
->make(true);
}
private function checkPermissions($view, $user_abo)
{
if ($view === 'me' && $user_abo->is_for !== 'me') {
abort(403, 'Unauthorized action. Is not for me');
}
if ($view === 'ot' && $user_abo->is_for !== 'ot') {
abort(403, 'Unauthorized action. Is not your customer');
}
if ($view === 'me' && $user_abo->user_id !== \Auth::user()->id) {
abort(403, 'Unauthorized action. Is not my abo');
}
if ($view === 'ot' && $user_abo->member_id !== \Auth::user()->id) {
abort(403, 'Unauthorized action. Is not my customer abo');
}
}
}

View file

@ -5,10 +5,13 @@ namespace App\Http\Controllers\User;
use App\Http\Controllers\Controller;
use App\Models\ShoppingUser;
use App\Repositories\CustomerRepository;
use App\Services\AboHelper;
use App\Services\CustomerPriority;
use App\Services\HTMLHelper;
use App\Services\ShoppingUserService;
use App\User;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use Request;
use Validator;
@ -227,23 +230,51 @@ class CustomerController extends Controller
return redirect(route('user_customer_detail', [$shopping_user->id]));
}
private function checkShoppingUsersByEmail(){
//ist an dieser stelle nicht machbar, zu viele Datenbankzugriffe
//siehe App\Console\Commands\SyncShoppingUserData
/* $user = User::find(\Auth::user()->id);
ShoppingUserService::setFakerMail($user);
ShoppingUserService::syncNumbersByEmail($user);
ShoppingUserService::syncOrdersByEmail($user); */
}
public function getCustomers()
{
//$this->checkShoppingUsersByEmail();
$user = User::find(\Auth::user()->id);
//\Log::info('Current user ID: ' . $user->id);
$query = ShoppingUser::select(['id', 'billing_company', 'billing_salutation', 'billing_firstname', 'billing_lastname', 'billing_email', 'faker_mail', 'billing_zipcode', 'billing_city', 'billing_country_id', 'orders', 'subscribed', 'created_at', 'number', 'mode', 'is_like', 'wp_order_number'])
->where('shopping_users.member_id', '=', $user->id);
//->groupBy('shopping_users.number');
->with('billing_country')
->whereIn('id', function($query) {
$query->select(DB::raw('MAX(id)'))
->from('shopping_users')
->groupBy('billing_email');
})->where('shopping_users.member_id', '=', $user->id)->where('shopping_users.auth_user_id', '=', NULL);
/*set_user_attr('filter_member_id', Request::get('filter_member_id'));
if(Request::get('filter_member_id') != ""){
$query->where('member_id', '=', Request::get('filter_member_id'));
}*/
if(Request::get('isfor') === 'ot-member'){ //Bestellung für Kunden
}
if(Request::get('isfor') === 'ot-customer' || Request::get('isfor') === 'abo-ot-customer'){ //Bestellung für Kunden Zahlungslink
$query->where(function($q) {
$q->where('shopping_users.faker_mail', '!=', 1)
->orWhereNull('shopping_users.faker_mail');
});
}
//\Log::info('SQL Query: ' . $query->toSql());
//\Log::info('Query Bindings: ' . print_r($query->getBindings(), true));
return \DataTables::eloquent($query)
->addColumn('send_to', function (ShoppingUser $ShoppingUser) {
$ot = Request::get('isfor') ? Request::get('isfor') : 'ot-member';
if(Request::get('isfor') === 'abo-ot-customer' && AboHelper::memberHasAbo($ShoppingUser)){
return '<span class="badge badge-pill badge-success"><i class="fa fa-check-circle"></i> '.__('abo.abo_assigned').'</span>';
}
return $ShoppingUser->is_like ? '<span class="badge badge-pill badge-warning"><i class="fa fa-clock"></i> '.__('customer.under_review').'</span>' : '<a href="' . route('user_order_my_delivery', [$ot, $ShoppingUser->id]) . '" class="btn btn-sm btn-secondary"><span class="fa fa-shopping-cart"></span> '.__('customer.select').'</a>';
})
->addColumn('billing_email', function (ShoppingUser $ShoppingUser) {
@ -262,7 +293,7 @@ class CustomerController extends Controller
return $ShoppingUser->firstEntryByNumber()->created_at->format('d.m.Y');
})
->addColumn('orders', function (ShoppingUser $ShoppingUser) {
return $ShoppingUser->lastEntryByNumber()->orders;
return $ShoppingUser->orders;
})
->addColumn('subscribed', function (ShoppingUser $ShoppingUser) {
return get_active_badge($ShoppingUser->subscribed);

View file

@ -10,12 +10,14 @@ use Request;
use App\User;
use App\Mail\MailInfo;
use App\Models\Product;
use App\Services\Payment;
use App\Models\UserHistory;
use App\Models\ShoppingOrder;
use App\Services\UserService;
use App\Models\ShippingCountry;
use App\Models\ShoppingInstance;
use Illuminate\Support\Facades\Mail;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Mail;
class MembershipController extends Controller
@ -39,11 +41,35 @@ class MembershipController extends Controller
if($user->payment_account){
$diff_months = Carbon::now()->diffInMonths(Carbon::parse($user->payment_account)) +1;
}
$userShoppingOrders = ShoppingOrder::with('shopping_user', 'shopping_payments')->select('shopping_orders.*')
->where('auth_user_id', '=', $user->id)
->where('txaction', '!=', NULL)
->whereIn('payment_for', [1, 2])
->orderBy('created_at', 'DESC')
->get();
$userHistoryPaymentOrder = UserHistory::whereUserId($user->id)->whereAction('payment_order')->get()->last();
$userHistoryUpgradeOrder = UserHistory::whereUserId($user->id)->whereAction('upgrade_order')->get()->last();
$userHistoryPaymentOrder = null;
$userHistoryUpgradeOrder = null;
/* Bezhalung ist nur 29 Tage vor ablauf möglich */
/* isRenewalAccount payment_account date - config('mivita.renewal_days') Vertragsverlängerung */
if($user->isRenewalAccount()){
//Acount ist noch nicht verlängert / bezahlt
if ($user->payment_account) {
//Die Order muss größer als das Datum sein.
$payment_greaterThan = Carbon::parse($user->payment_account)->modify('-'.(config('mivita.renewal_days')+1).' days');
$userHistoryPaymentOrder = UserHistory::whereUserId($user->id)->whereAction('payment_order')->where('created_at', '>=', $payment_greaterThan)->get()->last();
}
}
if($user->isActiveAccount() && !$user->isActiveShop()){
$payment_greaterThan = Carbon::parse($user->payment_account)->modify('-'.(config('mivita.renewal_days')+1).' days');
$userHistoryUpgradeOrder = UserHistory::whereUserId($user->id)->whereAction('upgrade_order')->where('created_at', '>=', $payment_greaterThan)->get()->last();
}
$userHistoryDeleteMembership = UserHistory::whereUserId($user->id)->whereAction('delete_membership')->whereStatus(50)->get()->last();
$shipping_country_id = $this->checkShoppingCountry($user);
if(!$shipping_country_id){
abort(403, __('validation.custom.shipping_not_found'));
@ -60,6 +86,7 @@ class MembershipController extends Controller
'userHistoryUpgradeOrder' => $userHistoryUpgradeOrder,
'userHistoryDeleteMembership' => $userHistoryDeleteMembership,
'yard_info' => UserService::getYardInfo(),
'userShoppingOrders' => $userShoppingOrders,
];
return view('user.membership.index', $data);
@ -131,7 +158,7 @@ class MembershipController extends Controller
$image = $product->images->first()->slug;
}
$qty = Request::get('qty') ? Request::get('qty') : 1;
$cartItem = Yard::instance('shopping')->add($product->id, $product->getLang('name'), $qty, $product->getPriceWith(\App\Services\UserService::getTaxFree(), false, \App\Services\UserService::$user_country), false, false, ['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points, 'no_commission' => $product->no_commission]);
$cartItem = Yard::instance('shopping')->add($product->id, $product->getLang('name'), $qty, $product->getPriceWith(\App\Services\UserService::getTaxFree(), false, \App\Services\UserService::$user_country), false, false, ['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points, 'no_commission' => $product->no_commission, 'show_on' => $product->show_on]);
if(\App\Services\UserService::getTaxFree()){
Yard::setTax($cartItem->rowId, 0);
}else{

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,674 @@
<?php
namespace App\Http\Controllers\User;
use App\Http\Controllers\Controller;
use App\Mail\MailCustomPaymet;
use App\Models\Product;
use App\Models\ShippingCountry;
use App\Models\ShoppingInstance;
use App\Models\ShoppingOrder;
use App\Models\ShoppingUser;
use App\Models\UserHistory;
use App\Services\AboHelper;
use App\Services\OrderPaymentService;
use App\Services\Payment;
use App\Services\Shop;
use App\Services\UserService;
use App\Services\Util;
use App\User;
use Auth;
use Illuminate\Support\Facades\Mail;
use Request;
use Validator;
use Yard;
class OrderController extends Controller
{
public function __construct()
{
$this->middleware('active.account');
}
public function index()
{
$data = [
];
return view('user.order.index', $data);
}
public function detail($id)
{
$user = User::find(\Auth::user()->id);
$shopping_order = ShoppingOrder::findOrFail($id);
if($shopping_order->auth_user_id !== $user->id){
abort(404);
}
if( $shopping_order->payment_for === 6 || $shopping_order->payment_for === 7){
return redirect(route('user_shop_order_detail', [$shopping_order->id]));
abort(403, 'Kundenbestellung');
}
$shopping_order->getLastShoppingPayment();
$data = [
'shopping_order' => $shopping_order,
'isAdmin' => false,
];
return view('user.order.detail', $data);
}
public function ordersDatatable(){
$user = User::find(\Auth::user()->id);
$query = ShoppingOrder::with('shopping_user', 'shopping_payments')->select('shopping_orders.*')->where('auth_user_id', '=', $user->id)->where('txaction', '!=', NULL);
return \DataTables::eloquent($query)
->addColumn('id', function (ShoppingOrder $ShoppingOrder) {
return '<a href="'.route('user_order_detail', [$ShoppingOrder->id]).'" class="btn icon-btn btn-sm btn-primary"><span class="fa fa-edit"></span></a>';
})
->addColumn('created_at', function (ShoppingOrder $ShoppingOrder) {
return $ShoppingOrder->created_at->format("d.m.Y");
})
->addColumn('txaction', function (ShoppingOrder $ShoppingOrder) {
return Payment::getShoppingOrderBadge($ShoppingOrder);
})
->addColumn('total_shipping', function (ShoppingOrder $ShoppingOrder) {
return '<span class="no-line-break">'.$ShoppingOrder->getFormattedTotalShipping()." €</span>";
})
->addColumn('payment', function (ShoppingOrder $ShoppingOrder) {
return $ShoppingOrder->getLastShoppingPayment('getPaymentType');
})
->addColumn('shipped', function (ShoppingOrder $ShoppingOrder) {
if($ShoppingOrder->payment_for === 8){
return '<button type="button" class="btn btn-xs btn-info btn-round" data-toggle="modal" data-target="#modals-load-content"
data-id="'.$ShoppingOrder->id.'"
data-action="shop-user-order-shipping-detail"
data-back=""
data-modal="modal-xl"
data-init_from="user"
data-route="'.route('modal_load').'"><span class="fa fa-eye"></span></button>';
}
return '<span class="badge badge-pill badge-'.$ShoppingOrder->getShippedColor().'">'.$ShoppingOrder->getShippedType().'</span>';
})
->addColumn('payment_for', function (ShoppingOrder $ShoppingOrder) {
return Payment::getPaymentForBadge($ShoppingOrder);
})
->addColumn('invoice', function (ShoppingOrder $ShoppingOrder) {
return $ShoppingOrder->isInvoice() ? '<span class="no-line-break"><a href="'.route('storage_file', [$ShoppingOrder->id, 'invoice', 'download']).'" class="btn btn-primary btn-xs"><i class="fa fa-download"></i></a>
<a href="'.route('storage_file', [$ShoppingOrder->id, 'invoice', 'stream']).'" target="_blank" class="btn btn-warning btn-xs"><i class="fa fa-eye"></i></a></span>' : '-';
})
->addColumn('reference', function (ShoppingOrder $ShoppingOrder) {
return $ShoppingOrder->getLastShoppingPayment('reference');
})
->orderColumn('id', 'id $1')
->orderColumn('txaction', 'txaction $1')
->orderColumn('shipped', 'shipped $1')
->orderColumn('total_shipping', 'total_shipping $1')
->orderColumn('payment_for', 'payment_for $1')
->rawColumns(['id', 'txaction', 'payment_for', 'total_shipping', 'invoice', 'shipped'])
->make(true);
}
/*
$for = me, ot-member, ot-customer, abo-ot-member, abo-ot-customer, abo-me
*/
public function delivery($for, $id=null)
{
$user = User::find(\Auth::user()->id);
$shopping_user = null;
$delivery_id = null;
if(strpos($for, 'ot') !== false){ //ot-member, ot-customer abo-ot-member, abo-ot-customer,
$shopping_user = Shop::checkShoppingUser($id, $user);
$delivery_id = $shopping_user->id;
if(!Shop::checkShoppingCountry($for, $delivery_id) && !\Session()->has('custom-error')){
$country = Shop::getDeliveryCountry($for, $delivery_id);
\Session()->flash('custom-error', $country.": ".__('validation.custom.shipping_not_found'));
return redirect(route('user_order_my_delivery', [$for, $delivery_id]));
}
if($for === 'abo-ot-customer'){
//check if user has an Abo
if(AboHelper::hasAboByEmail($shopping_user->billing_email) && !\Session()->has('custom-error')){
\Session()->flash('custom-error', __('abo.error_email_has_abo', ['email' => $shopping_user->billing_email]));
return redirect(route('user_order_my_delivery', [$for, $delivery_id]));
}
}
}
if(Request::get('action') === 'next'){
Yard::instance('shopping')->destroy();
if(strpos(Request::get('switchers-radio-is-for'), 'ot') !== false){
$delivery_id = $id;
}
return redirect(route('user_order_my_list', [Request::get('switchers-radio-is-for'), $delivery_id]));
}
$data = [
'shopping_user' => $shopping_user,
'isAdmin' => false,
'isView' => 'customer',
'for' => $for,
'delivery_id' => $delivery_id,
];
return view('user.order.delivery', $data);
}
public function list($for, $id=null)
{
$user = User::find(\Auth::user()->id);
if($for === 'abo-me' && AboHelper::userHasAbo($user)){
abort(403, 'User has an Abo. Cannot order.');
}
$shopping_user = null;
$delivery_id = null;
if(strpos($for, 'ot') !== false){ //ot-member, ot-customer abo-ot-member, abo-ot-customer,
$shopping_user = Shop::checkShoppingUser($id, $user);
$delivery_id = $shopping_user->id;
}
if($for === 'ot-customer' || $for === 'abo-ot-customer'){
//Liederung an (abo-) ot-customer (Kunden) Zahlung und Rechnung geht an Kunden
UserService::initCustomerYard($shopping_user, $for);
}else{
//Lieferung an user oder (abo-) ot-member (Kunden) rechnung geht an User
//lieferland und rechnungsland prüfen
$shipping_country_id = Shop::checkShoppingCountry($for, $id);
if(!$shipping_country_id){
$country = Shop::getDeliveryCountry($for, $id);
\Session()->flash('custom-error', $country.": ".__('validation.custom.shipping_not_found'));
return redirect(route('user_order_my_delivery', [$for, $delivery_id]));
}
UserService::initUserYard($user, $shipping_country_id, $for);
}
$data = [
'shopping_user' => $shopping_user,
'user' => $user,
'isAdmin' => false,
'isView' => 'customer',
'for' => $for,
'template' => str_replace('abo-', '', $for),
'delivery_id' => $delivery_id,
'is_abo' => strpos($for, 'abo') !== false,
'comp_products' => Shop::getCompProducts($for),
];
return view('user.order.list', $data);
}
public function payment($for, $id=null){
$data = Request::all();
$user = User::find(Auth::user()->id);
$rules = array(
'shipping_salutation' => 'required',
'shipping_firstname'=>'required',
'shipping_lastname'=>'required',
'shipping_address'=>'required',
'shipping_zipcode'=>'required',
'shipping_city' => 'required',
'shipping_state' => 'required',
);
$validator = Validator::make(Request::all(), $rules);
if ($validator->fails()) {
return back()->withErrors($validator)->withInput(Request::all());
}
//hier prüfen, ob versand etc richtig berechnet wurde
$this->checkSendYardForPayment($data, $id);
if(Yard::instance('shopping')->getNumComp() > 0){
if(!isset($data['switchers-comp-product'])){
$validator->errors()->add('switchers-comp-product', __('msg.please_select_compensation_product'));
}else{
if(!is_array($data['switchers-comp-product'])){
$validator->errors()->add('switchers-comp-product', __('msg.please_select_compensation_product'));
}else{
if(count($data['switchers-comp-product']) !== Yard::instance('shopping')->getNumComp()){
$validator->errors()->add('switchers-comp-product', __('mdg.please_select_count_compensation_products', ['count'=>Yard::instance('shopping')->getNumComp()]));
}
}
}
if ($validator->errors()->count()) {
return back()->withErrors($validator)->withInput(Request::all());
}
}
do {
$identifier = Util::getToken();
} while( ShoppingInstance::where('identifier', $identifier)->count() );
$data['is_from'] = 'user_order';
$data['is_for'] = $for;
$data['is_abo'] = $data['is_abo'] ?? 0;
$data['abo_interval'] = $data['abo_interval'] ?? 0;
$data['shopping_user_id'] = $id;
$data['user_price_infos'] = Yard::instance('shopping')->getUserPriceInfos();
unset($data['quantity']);
unset($data['_token']);
$data['mode'] = config('app.mode') === 'test' ? 'test' : 'live';
if($for === 'ot-customer' || $for === 'abo-ot-customer'){
$shopping_instance = ShoppingInstance::create([
'identifier' => $identifier,
'user_shop_id' => $user->shop->id,
'payment' => 6, //Berater Shop to Customer Shop
'subdomain' => $user->shop->getSubdomain(),
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
'language' => \App::getLocale(),
'amount' => Yard::instance('shopping')->totalWithShipping(2, '.', ''),
'status' => 0,
'shopping_user_id' => $id,
'shopping_data' => $data,
'back' => url()->previous(),
]);
Yard::instance('shopping')->store($identifier);
$yard_shopping_items = OrderPaymentService::getRestoredYardShoppingItems($shopping_instance);
// send Mail to Customer
$this->customPaymentSendMail($user, $identifier, $yard_shopping_items, $data);
UserHistory::create(['user_id' => $user->id, 'action'=>'user_order_customer', 'status'=>1, 'product_id'=>null, 'identifier'=>$identifier, 'is_abo'=>$data['is_abo']]);
//eine Abschließen bestellseite für den User + Link zum Kunden Shop + Mail an den Kunden / Berater
return redirect(route('user_order_my_custom_payment', ['identifier'=>$identifier]));
}else{
ShoppingInstance::create([
'identifier' => $identifier,
'user_shop_id' => 1, //is first faker shop for buy intern
'auth_user_id' => Auth::user()->id,
'payment' => 2, //Berater Shop
'subdomain' => url('/'),
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
'language' => \App::getLocale(),
'amount' => Yard::instance('shopping')->totalWithShipping(2, '.', ''),
'status' => 0,
'shopping_user_id' => $id,
'shopping_data' => $data,
'back' => url()->previous(),
]);
Yard::instance('shopping')->store($identifier);
$path = route('checkout.checkout_card', ['identifier'=>$identifier]);
UserHistory::create(['user_id' => $user->id, 'action'=>'user_order_payment', 'status'=>1, 'product_id'=>null, 'identifier'=>$identifier, 'is_abo'=>$data['is_abo']]);
//$path = str_replace('http', 'https', $path);
return redirect()->secure($path);
}
}
private function checkSendYardForPayment($data, $id){
$user = User::find(\Auth::user()->id);
$shopping_user = null;
if(strpos($data['shipping_is_for'], 'ot') !== false){
$shopping_user = Shop::checkShoppingUser($id, $user);
}
$shipping_country_id = Shop::checkShoppingCountry($data['shipping_is_for'], $id);
if(!$shipping_country_id){
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
Yard::instance('shopping')->store($identifier);
$data['user_id'] = Auth::user()->id;
$data['shopping_user_id'] = $id;
\App\Services\MyLog::writeLog('payment', 'error', 'no shipping_country_id found | Yard identifier: '.$identifier, $data);
abort(403, __('msg.shipping_country_was_not_found'));
}
//must be the same shipping country
if($shipping_country_id != Yard::instance('shopping')->getShippingCountryId()){
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
Yard::instance('shopping')->store($identifier);
$data['user_id'] = Auth::user()->id;
$data['shopping_user_id'] = $id;
\App\Services\MyLog::writeLog('payment', 'error', 'shipping_country_id is not the same from Yard | Yard identifier: '.$identifier, $data);
abort(403, __('msg.shipping_country_was_not_correctly'));
}
if($data['shipping_is_for'] !== 'ot-customer'){
if(Yard::instance('shopping')->shipping_free){
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
Yard::instance('shopping')->store($identifier);
$data['user_id'] = Auth::user()->id;
$data['shopping_user_id'] = $id;
\App\Services\MyLog::writeLog('payment', 'error', 'Yard can by not shipping_free | Yard identifier: '.$identifier, $data);
abort(403, __('msg.shopping_cart_was_shipping_free'));
}
}
if($data['shipping_is_for'] === 'ot-customer'){
if(!$user->shop){
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
Yard::instance('shopping')->store($identifier);
$data['user_id'] = Auth::user()->id;
$data['shopping_user_id'] = $id;
\App\Services\MyLog::writeLog('payment', 'error', 'User has no Shop for an User to Customer order| Yard identifier: '.$identifier, $data);
abort(403, __('msg.shopping_cart_was_not_user_shop'));
}
}
$shipping_price = Shop::getShippingPriceByShippingCountryId($shipping_country_id, Yard::instance('shopping')->weight());
dump($shipping_price);
//for other and has weight - check
if(strpos($data['shipping_is_for'], 'ot') !== false && $data['shipping_is_for'] !== 'ot-customer' && Yard::instance('shopping')->weight() > 0){
if(!Yard::instance('shopping')->getShippingPrice() || Yard::instance('shopping')->getShippingPrice() == 0){
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
Yard::instance('shopping')->store($identifier);
$data['user_id'] = Auth::user()->id;
$data['shopping_user_id'] = $id;
\App\Services\MyLog::writeLog('payment', 'error', 'Yard OT shipping_price is 0 or | Yard identifier: '.$identifier, $data);
abort(403, __('msg.shipping_cost_cannot_be_0'));
}
if(Yard::instance('shopping')->getShippingPrice() != $shipping_price->price){
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
Yard::instance('shopping')->store($identifier);
$data['user_id'] = Auth::user()->id;
$data['shopping_user_id'] = $id;
\App\Services\MyLog::writeLog('payment', 'error', 'Yard OT shipping_price is not the same from shipping_price | Yard identifier: '.$identifier, $data);
abort(403, __('msg.shipping_costs_were_not_calculated_correctly'));
}
}
if(($data['shipping_is_for'] == 'me' || $data['shipping_is_for'] == 'abo-me') && Yard::instance('shopping')->weight() > 0){
if(!Yard::instance('shopping')->getShippingPrice() || Yard::instance('shopping')->getShippingPrice() == 0){
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
Yard::instance('shopping')->store($identifier);
$data['user_id'] = Auth::user()->id;
$data['shopping_user_id'] = $id;
\App\Services\MyLog::writeLog('payment', 'error', 'Yard ME shipping_price is 0 or | Yard identifier: '.$identifier, $data);
abort(403, __('msg.shipping_cost_cannot_be_0'));
}
dump(Yard::instance('shopping')->getShippingPrice());
dump($shipping_price->price_comp);
dump(Yard::instance('shopping')->getNumComp());
dump($shipping_price->num_comp);
dd($data) ;
if(Yard::instance('shopping')->getShippingPrice() != $shipping_price->price_comp){
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
Yard::instance('shopping')->store($identifier);
$data['user_id'] = Auth::user()->id;
$data['shopping_user_id'] = $id;
\App\Services\MyLog::writeLog('payment', 'error', 'Yard ME shipping_price is not the same from shipping_price | Yard identifier: '.$identifier, $data);
abort(403, __('msg.shipping_costs_were_not_calculated_correctly'));
}
if(Yard::instance('shopping')->getNumComp() != $shipping_price->num_comp){
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
Yard::instance('shopping')->store($identifier);
$data['user_id'] = Auth::user()->id;
$data['shopping_user_id'] = $id;
\App\Services\MyLog::writeLog('payment', 'error', 'Yard num_comp is 0 | Yard identifier: '.$identifier, $data);
abort(403, __('msg.compensation_products_cannot_be_0'));
}
}
}
public function datatable(){
if(Request::get('shipping_is_for') === 'me' || Request::get('shipping_is_for') === 'abo-me'){
$show_on_ids = Request::get('is_abo') ? ['12', '13'] : ['2'];
$query = Product::with('product_buyings')
->select('products.*')->where('products.active', true)
->where(function($q) use ($show_on_ids) {
foreach($show_on_ids as $id) {
$q->orWhereJsonContains('show_on', $id);
}
})
->orderByRaw("CASE
WHEN JSON_CONTAINS(show_on, ?, '$') THEN 1
WHEN JSON_CONTAINS(show_on, ?, '$') THEN 2
ELSE 3 END",
[$show_on_ids[0], isset($show_on_ids[1]) ? $show_on_ids[1] : $show_on_ids[0]]);
}else{
$show_on_ids = Request::get('is_abo') ? ['12', '13'] : ['3'];
$query = Product::select('products.*')
->where('active', true)
->where(function($q) use ($show_on_ids) {
foreach($show_on_ids as $id) {
$q->orWhereJsonContains('show_on', $id);
}
})
->orderByRaw("CASE
WHEN JSON_CONTAINS(show_on, ?, '$') THEN 1
WHEN JSON_CONTAINS(show_on, ?, '$') THEN 2
ELSE 3 END",
[$show_on_ids[0], isset($show_on_ids[1]) ? $show_on_ids[1] : $show_on_ids[0]]);
}
return \DataTables::eloquent($query)
->addColumn('product', function (Product $product) {
$cartItem = Yard::instance('shopping')->getCartItemByProduct($product->id);
$qty = isset($cartItem->qty) ? $cartItem->qty : 0;
$rowId = isset($cartItem->rowId) ? $cartItem->rowId : '';
return '<strong>'.$product->getLang('name').'</strong><br>
<div class="no-line-break input-group-min-w">
<div class="input-group d-inline-flex w-auto">
<span class="input-group-prepend">
<button type="button" class="btn btn-secondary icon-btn md-btn-extra remove-product-basket" data-row-id="'.$rowId.'" data-product-id="'.$product->id.'">-</button>
</span>
<input type="text" class="form-control text-center input-extra table-input-event-onchange" name="product_qty_'.$product->id.'" data-row-id="'.$rowId.'" data-product-id="'.$product->id.'" value="'.$qty.'">
<span class="input-group-append">
<button type="button" class="btn btn-secondary icon-btn md-btn-extra add-product-basket" data-row-id="'.$rowId.'" data-product-id="'.$product->id.'">+</button>
</span>
</div>
</div>';
})
->addColumn('abo', function (Product $product) {
return AboHelper::getAboTypeBadge(AboHelper::getAboShowOn($product));
})
/*
->addColumn('add_card', function (Product $product) {
return '<button type="button" class="btn btn-sm btn-md-extra btn-secondary add-product-basket" data-product-id="'.$product->id.'">
<strong>&euro; '.$product->getFormattedPriceWith().'</strong>&nbsp; +<span class="ion ion-md-cart"></span>
</button>';
})
->addColumn('quantity', function (Product $product) {
$cartItem = Yard::instance('shopping')->getCartItemByProduct($product->id);
$qty = isset($cartItem->qty) ? $cartItem->qty : 0;
$rowId = isset($cartItem->rowId) ? $cartItem->rowId : '';
return '<div class="no-line-break input-group-min-w">
<div class="input-group d-inline-flex w-auto">
<span class="input-group-prepend">
<button type="button" class="btn btn-secondary icon-btn md-btn-extra remove-product-basket" data-row-id="'.$rowId.'" data-product-id="'.$product->id.'">-</button>
</span>
<input type="text" class="form-control text-center input-extra table-input-event-onchange" name="product_qty_'.$product->id.'" data-row-id="'.$rowId.'" data-product-id="'.$product->id.'" value="'.$qty.'">
<span class="input-group-append">
<button type="button" class="btn btn-secondary icon-btn md-btn-extra add-product-basket" data-row-id="'.$rowId.'" data-product-id="'.$product->id.'">+</button>
</span>
</div>
</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]).'">';
}
return "";
})
->addColumn('price_net', function (Product $product) {
return '<span class="no-line-break">'.$product->getFormattedPriceWith(true, true, Yard::instance('shopping')->getUserCountry()). " €</span>".'<span class="no-line-break">'.$product->getFormattedPriceCurrencyWith(true, true, Yard::instance('shopping')->getUserCountry()).'</span>';
})
->addColumn('price_gross', function (Product $product) {
return '<span class="no-line-break">'.$product->getFormattedPriceWith(false, true, Yard::instance('shopping')->getUserCountry()). " €</span>".'<span class="no-line-break">'.$product->getFormattedPriceCurrencyWith(false, true, Yard::instance('shopping')->getUserCountry()).'</span>';
})
->addColumn('price_vk_gross', function (Product $product) {
return '<span class="no-line-break">'.$product->getFormattedPriceWith(false, false, Yard::instance('shopping')->getUserCountry()). " €</span>".'<span class="no-line-break">'.$product->getFormattedPriceCurrencyWith(false, false, Yard::instance('shopping')->getUserCountry()).'</span>';
})
->addColumn('customer_price_net', function (Product $product) {
return '<span class="no-line-break">'.$product->getFormattedPriceWith(true, false, Yard::instance('shopping')->getUserCountry()). " €</span>".'<span class="no-line-break">'.$product->getFormattedPriceCurrencyWith(true, false, Yard::instance('shopping')->getUserCountry()).'</span>';
})
->addColumn('customer_price_gross', function (Product $product) {
return '<span class="no-line-break">'.$product->getFormattedPriceWith(false, false, Yard::instance('shopping')->getUserCountry()). " €</span>".'<span class="no-line-break">'.$product->getFormattedPriceCurrencyWith(false, false, Yard::instance('shopping')->getUserCountry()).'</span>';
})
->addColumn('my_commission_net', function (Product $product) {
return '<span class="no-line-break">'.$product->getFormattedPriceWith(true, false, Yard::instance('shopping')->getUserCountry(), true). " €</span>".'<span class="no-line-break">'.$product->getFormattedPriceCurrencyWith(true, false, Yard::instance('shopping')->getUserCountry(), true).'</span>';
})
->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"
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>';
})
->filterColumn('product', function($query, $keyword) {
if($keyword != ""){
$query->where('name', 'LIKE', '%'.$keyword.'%');
}
})
->orderColumn('name', 'name $1')
->orderColumn('product', 'name $1')
->orderColumn('number', 'number $1')
->orderColumn('points', 'points $1')
->orderColumn('price_net', 'price_net $1')
->orderColumn('price_gross', 'price_gross $1')
->orderColumn('price_vk_gross', 'price $1')
->orderColumn('customer_price_net', 'price $1')
->orderColumn('customer_price_gross', 'price $1')
->orderColumn('my_commission_net', 'price $1')
->orderColumn('contents_total', 'contents_total $1')
->orderColumn('weight', 'weight $1')
->orderColumn('abo', 'show_on $1')
->rawColumns(['add_card', 'price_net', 'price_gross', 'price_vk_gross', 'customer_price_net', 'customer_price_gross', 'my_commission_net', 'product', 'quantity', 'picture', 'abo', 'action'])
->make(true);
}
public function performRequest(){
if(Request::ajax()) {
$data = Request::all();
$is_for = isset($data['shipping_is_for']) ? $data['shipping_is_for'] : 'ot-member';
$data['for'] = $is_for;
$data['comp_products'] = Shop::getCompProducts($is_for);
if($data['action'] === 'updateCart' && isset($data['product_id'])){
if($product = Product::find($data['product_id'])){
$image = "";
if($product->images->count()){
$image = $product->images->first()->slug;
}
//get the card item
if($is_for === 'ot-customer' || $is_for === 'abo-ot-customer'){
$cartItem = Yard::instance('shopping')
->add($product->id, $product->getLang('name'), 1,
round($product->getPriceWith(Yard::instance('shopping')->getUserTaxFree(), false, Yard::instance('shopping')->getUserCountry()), 1), false, false,
['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points, 'no_commission' => $product->no_commission, 'show_on' => $product->show_on]);
}else{
$cartItem = Yard::instance('shopping')
->add($product->id, $product->getLang('name'), 1,
$product->getPriceWith(Yard::instance('shopping')->getUserTaxFree(), true, Yard::instance('shopping')->getUserCountry()), false, false,
['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points, 'no_commission' => $product->no_commission, 'show_on' => $product->show_on]);
}
if(Yard::instance('shopping')->getUserTaxFree()){
Yard::setTax($cartItem->rowId, 0);
}else{
Yard::setTax($cartItem->rowId, $product->getTaxWith(Yard::instance('shopping')->getUserCountry()));
}
if(isset($data['qty']) && $data['qty'] > 0){
Yard::instance('shopping')->update($cartItem->rowId, $data['qty']);
}else{
//if 0 get the item by qty:1 and remove it
Yard::instance('shopping')->remove($cartItem->rowId);
}
Yard::instance('shopping')->reCalculateShippingPrice();
$this->checkCompProduct(Yard::instance('shopping')->getNumComp());
$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]);
}
}
if($data['action'] === 'clearCart') {
Yard::instance('shopping')->destroy();
return response()->json(['response' => true, 'data'=>Yard::instance('shopping')->count(), 'html_card'=>'', 'html_comp'=>'']);
}
if($data['action'] === 'updateShippingCountry') {
if(isset($data['shipping_country_id'])){
if($shipping_country = ShippingCountry::find($data['shipping_country_id'])){
Yard::instance('shopping')->setShippingCountryWithPrice($shipping_country->id, $is_for);
$this->checkCompProduct(Yard::instance('shopping')->getNumComp());
}
}
$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]);
}
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]);
}
}
private function checkCompProduct($count_comp_products){
foreach (Yard::instance('shopping')->content() as $row) {
//wenn gleich löschen, da neue Versandkosten
if($row->options->comp > $count_comp_products) {
Yard::instance('shopping')->remove($row->rowId);
}
}
}
private function updateCompProduct($data){
//clear old
foreach (Yard::instance('shopping')->content() as $row) {
//wenn kleiner wurde ein produkt entfernt aufgrund der Anzahl
//wenn gleich löschen, da neue Versandkosten
if($row->options->comp === $data['comp_num'] || $row->options->comp > $data['count_comp_products']) {
Yard::instance('shopping')->remove($row->rowId);
}
}
if(isset($data['comp_product_id'])) {
if ($product = Product::find($data['comp_product_id'])) {
$image = "";
if ($product->images->count()) {
$image = $product->images->first()->slug;
}
$cartItem = Yard::instance('shopping')->add($product->id, $product->getLang('name'), 1, 0, false, false,
['image' => $image, 'slug' => $product->slug, 'weight' => 0, 'points' => 0,
'comp' => $data['comp_num'], 'product_id' => $product->id]);
Yard::setTax($cartItem->rowId, 0);
}
}
}
public function customPayment($identifier){
$data = OrderPaymentService::getCustomPayment($identifier);
return view('user.order.payment.custom_payment', $data);
}
private static function customPaymentSendMail($user, $identifier, $yard_shopping_items, $data){
$bcc = [];
$shopping_instance = ShoppingInstance::where('identifier', $identifier)->first();
if(!$shopping_instance){
abort(403, __('msg.shopping_instance_not_found'));
}
$shopping_user = $data['shopping_user_id'] ? ShoppingUser::find($data['shopping_user_id']) : null;
if(!$shopping_user){
abort(403, __('msg.shopping_user_not_found'));
}
$route = route('checkout.checkout_card', ['identifier'=>$identifier]);
$billing_email = $shopping_user->billing_email;
if(!$billing_email){
$billing_email = $data['mode'] === 'test' ? config('app.checkout_test_mail') : config('app.checkout_mail');
}
$bcc[] = $data['mode'] === 'test' ? config('app.checkout_test_mail') : config('app.checkout_mail');
$bcc[] = $shopping_user->member ? $shopping_user->member->email : $user->email;
Mail::to($billing_email)->bcc($bcc)->locale(\App::getLocale())
->send(new MailCustomPaymet($route, $shopping_user, $shopping_instance, $yard_shopping_items, $data['mode']));
}
}

View file

@ -0,0 +1,97 @@
<?php
namespace App\Http\Controllers\User;
use Request;
use App\User;
use App\Models\ShoppingInstance;
use App\Http\Controllers\Controller;
use App\Services\OrderPaymentService;
class OrderPaymentController extends Controller
{
public function __construct()
{
$this->middleware('active.account');
}
public function index()
{
$data = [
];
return view('user.order.payment.index', $data);
}
public function detail($identifier)
{
$data = OrderPaymentService::getCustomPayment($identifier);
$data['backlink'] = route('user_order_payment_links');
return view('user.order.payment.custom_payment', $data);
}
public function delete($identifier){
OrderPaymentService::deleteInstance($identifier);
return redirect(route('user_order_payment_links'));
}
public function datatable(){
$user = User::find(\Auth::user()->id);
$user_shop_id = $user->shop ? $user->shop->id : null;
$query = ShoppingInstance::select('*')
->where('user_shop_id', '=', $user_shop_id)
->where('payment', 6);
return \DataTables::eloquent($query)
->addColumn('id', function (ShoppingInstance $shoppingInstance) {
return '<a href="'.route('user_order_payment_links_detail', [$shoppingInstance->identifier]).'" class="btn icon-btn btn-sm btn-primary"><span class="fa fa-edit"></span></a>';
})
->addColumn('created_at', function (ShoppingInstance $shoppingInstance) {
return $shoppingInstance->created_at->format("d.m.Y");
})
->addColumn('status', function (ShoppingInstance $shoppingInstance) {
return OrderPaymentService::getStatusBadge($shoppingInstance);
})
->addColumn('payment_method', function (ShoppingInstance $shoppingInstance) {
return $shoppingInstance->payment_method ? $shoppingInstance->payment_method->name : '-';
})
->addColumn('total', function (ShoppingInstance $shoppingInstance) {
if($shoppingInstance->amount > 0){
return '<span class="no-line-break">'.$shoppingInstance->getAmountFormatted()." €</span>";
}else{
return '-';
}
})
->addColumn('type', function (ShoppingInstance $shoppingInstance) {
return OrderPaymentService::getTypeBadge($shoppingInstance);
})
->addColumn('billing_firstname', function (ShoppingInstance $shoppingInstance) {
return $shoppingInstance->shopping_data['billing_firstname'] ?? '-';
})
->addColumn('billing_lastname', function (ShoppingInstance $shoppingInstance) {
return $shoppingInstance->shopping_data['billing_lastname'] ?? '-';
})
->addColumn('billing_email', function (ShoppingInstance $shoppingInstance) {
return $shoppingInstance->shopping_data['billing_email'] ?? '-';
})
->addColumn('delete', function (ShoppingInstance $shoppingInstance) {
return '<a onclick="return confirm(\''.__('confirm_delete').'\');" href="'.route('user_order_payment_links_delete', [$shoppingInstance->identifier]).'" class="btn icon-btn btn-sm btn-danger"><span class="fa fa-trash"></span></a>';
})
->orderColumn('id', 'identifier $1')
->orderColumn('created_at', 'created_at $1')
->orderColumn('status', 'status $1')
->orderColumn('total', 'total $1')
->orderColumn('type', 'type $1')
->orderColumn('billing_firstname', 'billing_firstname $1')
->orderColumn('billing_lastname', 'billing_lastname $1')
->orderColumn('billing_email', 'billing_email $1')
->rawColumns(['id', 'status', 'type', 'total', 'invoice', 'delete'])
->make(true);
}
}

View file

@ -50,10 +50,9 @@ class PaymentController extends Controller
if(Credit::isCredit($UserCredit)){
$ret .= '<a href="'.route('storage_file', [$UserCredit->id, 'credit', 'download']).'" class="btn btn-primary btn-xs"><i class="fa fa-download"></i></a> ';
$ret .= '<a href="'.route('storage_file', [$UserCredit->id, 'credit', 'stream']).'" target="_blank" class="btn btn-warning btn-xs"><i class="fa fa-eye"></i></a><br>';
if(Auth::user()->isVIP()){
$ret .= '<a href="'.route('storage_file', [$UserCredit->id, 'credit_detail', 'html']).'" target="_blank" class="btn btn-secondary btn-xs mt-2"><i class="fa fa-eye"></i></a> ';
$ret .= '<a href="'.route('storage_file', [$UserCredit->id, 'credit_detail', 'pdf']).'" target="_blank" class="btn btn-secondary btn-xs mt-2"><i class="fa fa-file-pdf" style="min-width:13.5px"></i></a> ';
}
$ret .= '<a href="'.route('storage_file', [$UserCredit->id, 'credit_detail', 'html']).'" target="_blank" class="btn btn-secondary btn-xs mt-2"><i class="fa fa-eye"></i></a> ';
$ret .= '<a href="'.route('storage_file', [$UserCredit->id, 'credit_detail', 'pdf']).'" target="_blank" class="btn btn-secondary btn-xs mt-2"><i class="fa fa-file-pdf" style="min-width:13.5px"></i></a> ';
}else{
$ret = "-";
}

View file

@ -146,7 +146,7 @@ class ShopApiController extends Controller
return $ShoppingOrder->user_shop ? '<a href="'.$ShoppingOrder->user_shop->getSubdomain(false).'" target="_blank">'.$ShoppingOrder->user_shop->getSubdomain(false).'</span>' : '';
})
->addColumn('payment_for', function (ShoppingOrder $ShoppingOrder) {
return '<span class="badge badge-pill badge-'.$ShoppingOrder->getPaymentForColor().'">'.$ShoppingOrder->getPaymentForType().'</span>';
return Payment::getPaymentForBadge($ShoppingOrder);
})
->addColumn('shipped', function (ShoppingOrder $ShoppingOrder) {
return '<span class="badge badge-pill badge-'.$ShoppingOrder->getShippedColor().'">'.$ShoppingOrder->getShippedType().'</span>

View file

@ -28,7 +28,7 @@ class ShopSalesController extends Controller
$user = User::find(\Auth::user()->id);
$shopping_order = ShoppingOrder::findOrFail($id);
if($shopping_order->member_id !== $user->id){
abort(404);
abort(403, 'Unauthorized action. User ID does not match.');
}
if( $shopping_order->payment_for !== 6 && $shopping_order->payment_for !== 7){
return redirect(route('user_order_detail', [$shopping_order->id]));
@ -67,7 +67,7 @@ class ShopSalesController extends Controller
return $ShoppingOrder->user_shop ? '<a href="'.$ShoppingOrder->user_shop->getSubdomain(false).'" target="_blank">'.$ShoppingOrder->user_shop->getSubdomain(false).'</span>' : '';
})
->addColumn('payment_for', function (ShoppingOrder $ShoppingOrder) {
return '<span class="badge badge-pill badge-'.$ShoppingOrder->getPaymentForColor().'">'.$ShoppingOrder->getPaymentForType().'</span>';
return Payment::getPaymentForBadge($ShoppingOrder);
})
->addColumn('shipped', function (ShoppingOrder $ShoppingOrder) {
return '<span class="badge badge-pill badge-'.$ShoppingOrder->getShippedColor().'">'.$ShoppingOrder->getShippedType().'</span>

View file

@ -2,6 +2,7 @@
namespace App\Http\Controllers\User;
use Auth;
use Request;
use App\User;
@ -26,11 +27,11 @@ class TeamController extends Controller
public function members()
{
$user = User::find(\Auth::user()->id);
if($user->isActiveShop() && $user->shop){
$shop_register_link = $user->shop->getSubdomain(false)."/reg";
}else{
$member_id = 'm'.($user->id + config('mivita.add_number_id'));
$shop_register_link = config('app.protocol').config('app.domain').config('app.tld_care').'/reg/'.$member_id;
if ($user->isActiveShop() && $user->shop) {
$shop_register_link = $user->shop->getSubdomain(false) . "/reg";
} else {
$member_id = 'm' . ($user->id + config('mivita.add_number_id'));
$shop_register_link = config('app.protocol') . config('app.domain') . config('app.tld_care') . '/reg/' . $member_id;
}
$data = [
'shop_register_link' => $shop_register_link
@ -71,7 +72,7 @@ class TeamController extends Controller
{
$user = User::find(\Auth::user()->id);
if(!$user->isVIP()){
if (!$user->isVIP()) {
abort(404);
}
$ExportBot = new ExportBot('member');
@ -82,14 +83,15 @@ class TeamController extends Controller
return view('user.team.export', $data);
}
public function userTeamExport(){
public function userTeamExport()
{
if(Request::get('action') === "export"){
if (Request::get('action') === "export") {
$user = User::find(\Auth::user()->id);
$ExportBot = new ExportBot('member');
$ExportBot->initStructureUser($user, 'list'); //tree or list
$columns = [];
$filename = __('team.filename_export').date('Y-m-d-H-i-s');
$filename = __('team.filename_export') . date('Y-m-d-H-i-s');
$headers = array(
__('tables.line'),
__('tables.level'),
@ -104,12 +106,13 @@ class TeamController extends Controller
__('tables.phone'),
__('tables.mobil'),
__('tables.birthday'),
__('tables.partner_since'),
__('tables.account'),
__('tables.account_to'),
__('tables.sponsor'),
);
if(isset($ExportBot->user_list->childs)){
foreach ($ExportBot->user_list->childs as $child){
if (isset($ExportBot->user_list->childs)) {
foreach ($ExportBot->user_list->childs as $child) {
$columns[] = array(
__('tables.line') => $child->line,
__('tables.level') => $child->level_name,
@ -124,42 +127,44 @@ class TeamController extends Controller
__('tables.phone') => $child->phone,
__('tables.mobil') => $child->mobil,
__('tables.birthday') => $child->birthday,
__('tables.partner_since') => $child->partner_since,
__('tables.account') => ($child->active_account == 1 ? __('yes') : __('no')),
__('tables.account_to') => $child->payment_account_date,
__('tables.sponsor') => $child->sponsor_name,
);
}
}
return Excel::download(new UserTeamExport($columns, $headers), $filename.'.xls');
return Excel::download(new UserTeamExport($columns, $headers), $filename . '.xls');
}
}
private function setFilterVars(){
private function setFilterVars()
{
if(!session('team_user_filter_month')){
if (!session('team_user_filter_month')) {
session(['team_user_filter_month' => intval(date('m'))]);
}
if(!session('team_user_filter_year')){
if (!session('team_user_filter_year')) {
session(['team_user_filter_year' => intval(date('Y'))]);
}
if(!session('team_user_points_filter_month')){
if (!session('team_user_points_filter_month')) {
session(['team_user_points_filter_month' => intval(date('m'))]);
}
if(!session('team_user_points_filter_year')){
if (!session('team_user_points_filter_year')) {
session(['team_user_points_filter_year' => intval(date('Y'))]);
}
if(Request::get('team_user_filter_month')){
if (Request::get('team_user_filter_month')) {
session(['team_user_filter_month' => Request::get('team_user_filter_month')]);
}
if(Request::get('team_user_filter_year')){
if (Request::get('team_user_filter_year')) {
session(['team_user_filter_year' => Request::get('team_user_filter_year')]);
}
if(Request::get('team_user_points_filter_month')){
if (Request::get('team_user_points_filter_month')) {
session(['team_user_points_filter_month' => Request::get('team_user_points_filter_month')]);
}
if(Request::get('team_user_points_filter_year')){
if (Request::get('team_user_points_filter_year')) {
session(['team_user_points_filter_year' => Request::get('team_user_points_filter_year')]);
}
}
@ -170,46 +175,47 @@ class TeamController extends Controller
$user_id = \Auth::user()->id;
$query = UserSalesVolume::with('user', 'user.account')->with('shopping_order')->select('user_sales_volumes.*')
->where('user_sales_volumes.user_id', '=', $user_id)
->where('user_sales_volumes.month', '=', Request::get('team_user_points_filter_month'))
->where('user_sales_volumes.year', '=', Request::get('team_user_points_filter_year'));
->where('user_sales_volumes.user_id', '=', $user_id)
->where('user_sales_volumes.month', '=', Request::get('team_user_points_filter_month'))
->where('user_sales_volumes.year', '=', Request::get('team_user_points_filter_year'));
return $query;
}
public function datatablePoints(){
public function datatablePoints()
{
$query = $this->initSearchPoints();
return \DataTables::eloquent($query)
->addColumn('order', function (UserSalesVolume $UserSalesVolume) {
if($UserSalesVolume->shopping_order){
if($UserSalesVolume->status === 1 && $UserSalesVolume->shopping_order->auth_user_id === $UserSalesVolume->user_id){
return '<a href="' . route('user_order_detail', [$UserSalesVolume->shopping_order->id]) . '" class="btn btn-xs btn-primary">'.$UserSalesVolume->shopping_order->id.'</a>';
if ($UserSalesVolume->shopping_order) {
if ($UserSalesVolume->status === 1 && $UserSalesVolume->shopping_order->auth_user_id === $UserSalesVolume->user_id) {
return '<a href="' . route('user_order_detail', [$UserSalesVolume->shopping_order->id]) . '" class="btn btn-xs btn-primary">' . $UserSalesVolume->shopping_order->id . '</a>';
}
if(($UserSalesVolume->status === 2 || $UserSalesVolume->status === 3) && $UserSalesVolume->shopping_order->member_id === $UserSalesVolume->user_id){
return '<a href="' . route('user_shop_order_detail', [$UserSalesVolume->shopping_order->id]) . '" class="btn btn-xs btn-secondary">'.$UserSalesVolume->shopping_order->id.'</a>';
if (($UserSalesVolume->status === 2 || $UserSalesVolume->status === 3) && $UserSalesVolume->shopping_order->member_id === $UserSalesVolume->user_id) {
return '<a href="' . route('user_shop_order_detail', [$UserSalesVolume->shopping_order->id]) . '" class="btn btn-xs btn-secondary">' . $UserSalesVolume->shopping_order->id . '</a>';
}
}
return '';
})
->addColumn('total_net', function (UserSalesVolume $UserSalesVolume) {
return formatNumber($UserSalesVolume->total_net).' &euro;';
return formatNumber($UserSalesVolume->total_net) . ' &euro;';
})
->addColumn('status_turnover', function (UserSalesVolume $UserSalesVolume) {
return '<span class="badge badge-pill badge-'.$UserSalesVolume->getStatusTurnoverColor().'">'.$UserSalesVolume->getStatusTurnoverType().'</span>';
return '<span class="badge badge-pill badge-' . $UserSalesVolume->getStatusTurnoverColor() . '">' . $UserSalesVolume->getStatusTurnoverType() . '</span>';
})
->addColumn('status', function (UserSalesVolume $UserSalesVolume) {
return '<span class="badge badge-pill badge-'.$UserSalesVolume->getStatusColor().'">'.$UserSalesVolume->getStatusType().'</span>';
return '<span class="badge badge-pill badge-' . $UserSalesVolume->getStatusColor() . '">' . $UserSalesVolume->getStatusType() . '</span>';
})
->addColumn('message', function (UserSalesVolume $UserSalesVolume) {
return '<span class="no-line-break">'.$UserSalesVolume->message.'</span>';
return '<span class="no-line-break">' . $UserSalesVolume->message . '</span>';
})
->addColumn('info', function (UserSalesVolume $UserSalesVolume) {
return '<span class="no-line-break">'.$UserSalesVolume->info.'</span>';
return '<span class="no-line-break">' . $UserSalesVolume->info . '</span>';
})
->orderColumn('id', 'id $1')
->orderColumn('order', 'order $1')
->orderColumn('status', 'status $1')
@ -220,7 +226,8 @@ class TeamController extends Controller
->make(true);
}
public function load(){
public function load()
{
$user = User::find(\Auth::user()->id);
$userSalesVolume = $user->getUserSalesVolume(intval(session('team_user_points_filter_month')), intval(session('team_user_points_filter_year')), 'first');
@ -229,9 +236,6 @@ class TeamController extends Controller
'userSalesVolume' => $userSalesVolume,
];
$html = view('user.team._points_sum', $data)->render();
return response()->json(['response' => true, 'data'=>$data, 'html'=>$html]);
return response()->json(['response' => true, 'data' => $data, 'html' => $html]);
}
}
}