middleware('admin'); } public function users() { if (Request::get('reset') === 'filter') { return redirect(route('admin_sales_users')); } $data = []; return view('admin.sales.users', $data); } public function usersDetail($id) { $ShoppingOrder = ShoppingOrder::find($id); if ($ShoppingOrder->payment_for === 6 || $ShoppingOrder->payment_for === 7) { return redirect(route('admin_sales_customers_detail', [$ShoppingOrder->id])); abort(403, 'Kundenbestellung'); } /*if($ShoppingOrder->shipped === 0){ $ShoppingOrder->shipped = 1; $ShoppingOrder->save(); }*/ $data = [ 'shopping_order' => $ShoppingOrder, 'isAdmin' => true, 'isView' => 'sales_user', ]; return view('admin.sales.user_detail', $data); } public function usersStore($id) { exit('keine funktion'); $data = [ 'shopping_order' => ShoppingOrder::find($id), 'isAdmin' => true, ]; return view('admin.sales.user_detail', $data); } public function usersDatatable() { $query = ShoppingOrder::with('shopping_user', 'user_shop', 'shopping_payments')->select('shopping_orders.*')->where('shopping_orders.auth_user_id', '!=', null); return \DataTables::eloquent($query) ->addColumn('id', function (ShoppingOrder $ShoppingOrder) { return ''; }) ->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 ''.$ShoppingOrder->getFormattedTotalShipping().' €'; }) ->addColumn('payment', function (ShoppingOrder $ShoppingOrder) { return $ShoppingOrder->getLastShoppingPayment('getPaymentType'); }) ->addColumn('shipped', function (ShoppingOrder $ShoppingOrder) { if ($ShoppingOrder->payment_for === 8) { return ''; } return ''.$ShoppingOrder->getShippedType().''; }) ->addColumn('dhl_button', function (ShoppingOrder $ShoppingOrder) { return ''; }) ->addColumn('payment_for', function (ShoppingOrder $ShoppingOrder) { return Payment::getPaymentForBadge($ShoppingOrder); }) ->addColumn('invoice', function (ShoppingOrder $ShoppingOrder) { return $ShoppingOrder->isInvoice() ? ' ' : '-'; }) ->addColumn('reference', function (ShoppingOrder $ShoppingOrder) { return $ShoppingOrder->getLastShoppingPayment('reference'); }) ->addColumn('orders', function (ShoppingOrder $ShoppingOrder) { return $ShoppingOrder->shopping_user ? $ShoppingOrder->shopping_user->orders : ''; }) ->addColumn('user_shop_id', function (ShoppingOrder $ShoppingOrder) { return $ShoppingOrder->user_shop ? ''.$ShoppingOrder->user_shop->getSubdomain(false).'' : ''; }) ->addColumn('auth_user_shop', function (ShoppingOrder $ShoppingOrder) { $auth_user_shop = UserShop::whereUserId($ShoppingOrder->auth_user_id)->first(); return $auth_user_shop ? ''.$auth_user_shop->getSubdomain(false).'' : '-'; }) ->orderColumn('id', 'id $1') ->orderColumn('txaction', 'txaction $1') ->orderColumn('user_shop_id', 'user_shop_id $1') ->orderColumn('shipped', 'shipped $1') ->orderColumn('total_shipping', 'total_shipping $1') ->orderColumn('payment_for', 'payment_for $1') ->rawColumns(['id', 'dhl_button', 'txaction', 'user_shop_id', 'auth_user_shop', 'payment_for', 'total_shipping', 'invoice', 'shipped']) ->make(true); } public function customers() { if (Request::get('reset') === 'filter') { set_user_attr('filter_user_shop_id', null); set_user_attr('filter_txaction', null); set_user_attr('filter_member_id', null); return redirect(route('admin_sales_customers')); } $filter_user_shops = ShoppingOrder::select('user_shops.id', 'user_shops.slug') ->join('user_shops', 'shopping_orders.user_shop_id', '=', 'user_shops.id') ->orderBy('user_shops.slug') ->distinct() ->pluck('slug', 'id') ->toArray(); $filter_members = ShoppingOrder::join('users', 'member_id', '=', 'users.id')->groupBy('member_id')->join('user_accounts', 'account_id', '=', 'user_accounts.id')->select('users.id', 'users.email', 'user_accounts.first_name', 'user_accounts.last_name')->get(); // ->pluck('email', 'id')->unique()->toArray(); $data = [ 'filter_user_shops' => $filter_user_shops, 'filter_members' => $filter_members, ]; return view('admin.sales.customers', $data); } public function customersDetail($id) { $ShoppingOrder = ShoppingOrder::find($id); if (! $ShoppingOrder) { abort(404); } if ($ShoppingOrder->payment_for !== 6 && $ShoppingOrder->payment_for !== 7) { return redirect(route('admin_sales_users_detail', [$ShoppingOrder->id])); abort(403, 'Beraterbestellung'); } /* if($ShoppingOrder->shipped === 0){ $ShoppingOrder->shipped = 1; $ShoppingOrder->save(); } */ $data = [ 'shopping_order' => $ShoppingOrder, 'isAdmin' => true, 'isView' => 'sales_customer', ]; return view('admin.sales.customer_detail', $data); } public function customersStore($id) { $data = Request::all(); $change_member_error = false; if ($data['action'] === 'shopping-order-change-member') { if (! isset($data['change_member_key']) || $data['change_member_key'] !== config('mivita.edit_data_pass')) { $change_member_error = 'Das Passwort ist falsch.'; } else { // change $shopping_order = ShoppingOrder::findOrFail($data['id']); CustomerPriority::newMemberForOrder($shopping_order, $data['change_member_id'], $data['customer_set_member_for']); \Session()->flash('alert-save', true); return redirect(route('admin_sales_customers_detail', [$shopping_order->id])); } } if ($data['action'] === 'shopping-user-is-like-member') { if (! isset($data['change_member_key']) || $data['change_member_key'] !== config('mivita.edit_data_pass')) { \Session()->flash('alert-error', 'Das Passwort ist falsch.'); return redirect($data['back']); } else { if (! isset($data['is_like_shopping_user_id'])) { \Session()->flash('alert-error', 'Keine Änderung ausgewählt'); return redirect($data['back']); } $shopping_user = ShoppingUser::findOrFail($data['id']); $set_like_shopping_user = ShoppingUser::findOrFail($data['is_like_shopping_user_id']); $send_member_mail = isset($data['send_member_mail']) ? true : false; $change_shopping_user = isset($data['change_shopping_user']) ? true : false; // Mail send in setIsLike CustomerPriority::setIsLike($shopping_user, $set_like_shopping_user, $send_member_mail, $change_shopping_user); \Session()->flash('alert-save', true); return redirect($data['back']); } } if ($data['action'] === 'shopping-order-change-points') { if (! isset($data['change_member_key']) || $data['change_member_key'] !== config('mivita.edit_data_pass')) { \Session()->flash('alert-error', 'Das Passwort ist falsch.'); return back(); } else { if (! isset($data['change_points'])) { \Session()->flash('alert-error', 'Keine Änderung ausgewählt'); return back(); } $shopping_order = ShoppingOrder::findOrFail($data['id']); SalesPointsVolume::changeSalesPointsVolumeUser($shopping_order, $data['change_member_id']); return redirect(route('admin_sales_customers_detail', [$shopping_order->id])); } } $data = [ 'change_member_error' => $change_member_error, 'shopping_order' => ShoppingOrder::find($id), 'isAdmin' => true, 'isView' => 'sales_customer', ]; return view('admin.sales.customer_detail', $data); } public function customersDatatable() { $query = ShoppingOrder::with('shopping_user')->select('shopping_orders.*')->where('shopping_orders.auth_user_id', null); set_user_attr('filter_user_shop_id', Request::get('filter_user_shop_id')); if (Request::get('filter_user_shop_id') != '') { $query->where('user_shop_id', '=', Request::get('filter_user_shop_id')); } set_user_attr('filter_txaction', Request::get('filter_txaction')); if (Request::get('filter_txaction') != '') { if (Request::get('filter_txaction') === 'NULL') { $query->where('txaction', '=', null); } else { $query->where('txaction', '=', Request::get('filter_txaction')); } } 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')); } return \DataTables::eloquent($query) ->addColumn('id', function (ShoppingOrder $ShoppingOrder) { return ''; }) ->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 ''.$ShoppingOrder->getFormattedTotalShipping().' €'; }) ->addColumn('payment', function (ShoppingOrder $ShoppingOrder) { if ($ShoppingOrder->txaction === 'extern_paid') { $shopping_oder_id = isset($ShoppingOrder->api_notice['shopping_order_id']) ? $ShoppingOrder->api_notice['shopping_order_id'] : null; if ($shopping_oder_id) { return ' '.$shopping_oder_id.''; } } return $ShoppingOrder->getLastShoppingPayment('getPaymentType'); }) ->addColumn('shipped', function (ShoppingOrder $ShoppingOrder) { return ''.$ShoppingOrder->getShippedType().''; }) ->addColumn('dhl_button', function (ShoppingOrder $ShoppingOrder) { return ''; }) ->addColumn('payment_for', function (ShoppingOrder $ShoppingOrder) { return Payment::getPaymentForBadge($ShoppingOrder); }) ->addColumn('invoice', function (ShoppingOrder $ShoppingOrder) { if (($ShoppingOrder->txaction === 'extern' || $ShoppingOrder->txaction === 'extern_paid') && $ShoppingOrder->wp_invoice_path) { return ' '; } return $ShoppingOrder->isInvoice() ? ' ' : '-'; }) ->addColumn('reference', function (ShoppingOrder $ShoppingOrder) { return $ShoppingOrder->getLastShoppingPayment('reference'); }) ->addColumn('member_id', function (ShoppingOrder $ShoppingOrder) { if ($ShoppingOrder->member_id && $ShoppingOrder->member) { return $ShoppingOrder->member ? ''.$ShoppingOrder->member->getFullName().'' : 'gelöscht'; } if ($ShoppingOrder->shopping_user && $ShoppingOrder->shopping_user->is_like) { return ''; } return ''; }) ->addColumn('user_shop_id', function (ShoppingOrder $ShoppingOrder) { return $ShoppingOrder->user_shop ? ''.$ShoppingOrder->user_shop->getSubdomain(false).'' : ''; }) ->orderColumn('id', 'id $1') ->orderColumn('txaction', 'txaction $1') ->orderColumn('user_shop_id', 'user_shop_id $1') ->orderColumn('member_id', 'member_id $1') ->orderColumn('shipped', 'shipped $1') ->orderColumn('payment_for', 'payment_for $1') ->orderColumn('total_shipping', 'total_shipping $1') ->rawColumns(['id', 'dhl_button', 'member_id', 'txaction', 'user_shop_id', 'payment_for', 'payment', 'total_shipping', 'invoice', 'shipped']) ->make(true); } public function store() { $data = Request::all(); if (! isset($data['id'])) { abort(404); } if (isset($data['action'])) { if ($data['action'] === 'store_shipped' && isset($data['shipped'])) { $shopping_order = ShoppingOrder::findOrFail($data['id']); $shopping_order->shipped = $data['shipped']; $shopping_order->save(); } if ($data['action'] === 'store_txaction' && isset($data['txaction']) && isset($data['payment_id'])) { $shopping_order = ShoppingOrder::findOrFail($data['id']); $shopping_payment = ShoppingPayment::findOrFail($data['payment_id']); PaymentTransaction::create([ 'shopping_payment_id' => $shopping_payment->id, 'request' => 'transaction', 'txid' => 0, 'userid' => 0, 'status' => 'FNCMIV', 'transmitted_data' => null, 'txaction' => $data['txaction'], 'mode' => $shopping_payment->mode, ]); $shopping_order->txaction = $data['txaction']; $shopping_order->paid = true; $shopping_order->save(); $shopping_payment->txaction = $data['txaction']; $shopping_payment->save(); // TODO can send MAIL // Bei Zahlung auf Rechnung wurde die Rechnung schon erstellt, // wenn muss hier die Storno erstellt werden // Payment::paymentStatusSendMail($shopping_order, $shopping_payment, $data); } } if (isset($data['back'])) { return redirect($data['back']); } } /* Manuelle Rechnung erstellen.*/ public function invoice() { $data = Request::all(); if (! isset($data['id'])) { abort(404); } if (isset($data['action'])) { if ($data['action'] === 'create_invoice') { $shopping_order = ShoppingOrder::findOrFail($data['id']); $invoice_repo = new InvoiceRepository($shopping_order); if ($shopping_order->isInvoice()) { $invoice_repo->update($data); } else { $invoice_repo->createAndSalesVolume($data); } if (isset($data['view']) && $data['view'] === 'sales_customer') { return redirect(route('admin_sales_customers_detail', [$shopping_order->id])); } return redirect(route('admin_sales_users_detail', [$shopping_order->id])); } } } /** * Stornorechnung erstellen mit Punktekorrektur */ public function invoiceCancellation() { $data = Request::all(); if (! isset($data['id'])) { abort(404); } if (isset($data['action']) && $data['action'] === 'create_cancellation_invoice') { $shopping_order = ShoppingOrder::findOrFail($data['id']); // Prüfen ob Rechnung existiert if (! $shopping_order->isInvoice()) { \Session()->flash('alert-error', 'Es existiert keine Rechnung für diese Bestellung.'); return redirect($data['back'] ?? route('admin_sales_users_detail', [$shopping_order->id])); } // Prüfen ob bereits storniert if ($shopping_order->isCancellationInvoice()) { \Session()->flash('alert-error', 'Diese Rechnung wurde bereits storniert.'); return redirect($data['back'] ?? route('admin_sales_users_detail', [$shopping_order->id])); } try { $invoice_repo = new InvoiceRepository($shopping_order); $cancellation_invoice = $invoice_repo->createCancellation($data); \Session()->flash('alert-success', 'Stornorechnung wurde erfolgreich erstellt und Punkte wurden korrigiert.'); } catch (\Exception $e) { \Log::error('Fehler beim Erstellen der Stornorechnung: '.$e->getMessage(), [ 'order_id' => $shopping_order->id, 'exception' => $e, ]); \Session()->flash('alert-error', 'Fehler beim Erstellen der Stornorechnung: '.$e->getMessage()); } return redirect($data['back'] ?? route('admin_sales_users_detail', [$shopping_order->id])); } abort(404); } }