Subversion-Projekte lars-tiefland.webanos.faltradxxs.de

Revision

Revision 26 | Zur aktuellen Revision | Blame | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

<?php

    namespace App\Http\Controllers;

    use App\Http\Requests\ActionRequest;
    use App\Models\WebSetting;
    use Illuminate\Contracts\Foundation\Application;
    use Illuminate\Contracts\View\Factory;
    use Illuminate\Contracts\View\View;
    use Illuminate\Http\RedirectResponse;
    use Illuminate\Http\Request;
    use App\Models\OrderAddress;
    use App\Models\OrderItem;
    use App\Models\Order;

    class OrderController extends Controller
    {
        //
        private int       $shipAddrId;
        private int       $billAddrId;
        private Order     $order;
        private int       $orderId;
        private OrderItem $orderItem;
        private array     $orderItems;

        /**
         * Display a listing of the resource.
         *
         */
        public function index(): Factory|View|Application
        {
            //
            $orders = Order::with( [
                'shop',
                'orderType',
                'orderItem',
                'billAddr',
                'shipAddr'
            ] )->orderBy( "created_at", 'desc' )->paginate( 100 );
            return view( 'admin/orders', [ "orders" => $orders, ] );
        }

        public function create()
        {
            $this->billAddr = new OrderAddress();
            if ( !( isset( $_SESSION["SHOP"]["buy"]["Persdata"]["ID"] ) && $_SESSION["SHOP"]["buy"]["Persdata"]["ID"] ) )
            {
                $_SESSION["SHOP"]["buy"]["Persdata"]["ID"] = 1;
            }
            $this->billAddr->user_id = $_SESSION["SHOP"]["buy"]["Persdata"]["ID"];
            $this->billAddr->name = $_SESSION["SHOP"]["buy"]["Persdata"]["Vorname"];
            $this->billAddr->lastname = $_SESSION["SHOP"]["buy"]["Persdata"]["Nachname"];
            if ( $_SESSION["SHOP"]["buy"]["Persdata"]["Firma"] )
            {
                $this->billAddr->company = $_SESSION["SHOP"]["buy"]["Persdata"]["Firma"];
            }
            $this->billAddr->street = $_SESSION["SHOP"]["buy"]["Persdata"]["Strasse"];
            $this->billAddr->houseno = $_SESSION["SHOP"]["buy"]["Persdata"]["Hausnummer"];
            $this->billAddr->zip = $_SESSION["SHOP"]["buy"]["Persdata"]["PLZ"];
            $this->billAddr->city = $_SESSION["SHOP"]["buy"]["Persdata"]["Ort"];
            $this->billAddr->country_id = $_SESSION["SHOP"]["buy"]["Persdata"]["Land"];
            $this->billAddr->phone = $_SESSION["SHOP"]["buy"]["Persdata"]["Telefon"];
            $this->billAddr->email = $_SESSION["SHOP"]["buy"]["Persdata"]["email"];
            $this->billAddr->save();
            $this->billAddrId = $this->billAddr->id;

            if ( $_SESSION["SHOP"]["Lieferadresse"] == "packstation" )
            {
                $this->shipAddr = new OrderAddress();
                $this->shipAddr->user_id = $_SESSION["SHOP"]["buy"]["Persdata"]["ID"];
                $this->shipAddr->name = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Vorname_pst"];
                $this->shipAddr->lastname = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Nachname_pst"];
                if ( $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Firma_pst"] )
                {
                    $this->shipAddr->company = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Firma_pst"];
                }
                $this->shipAddr->street = $_SESSION["SHOP"]["buy"]["Persdata"]["lieferStrasse_pst"];
                $this->shipAddr->houseno = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Hausnummer_pst"];
                $this->shipAddr->zip = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_PLZ_pst"];
                $this->shipAddr->city = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Ort_pst"];
                $this->shipAddr->country_id = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Land_pst"];
                $this->shipAddr->phone = $_SESSION["SHOP"]["buy"]["Persdata"]["Telefon"];
                $this->shipAddr->email = $_SESSION["SHOP"]["buy"]["Persdata"]["email"];
                $this->shipAddr->save();
                $this->shipAddrId = $this->billAddr->id;
            }
            else
            {
                $this->shipAddr = new OrderAddress();
                $this->shipAddr->user_id = $_SESSION["SHOP"]["buy"]["Persdata"]["ID"];
                $this->shipAddr->name = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Vorname"];
                if ( $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Firma"] )
                {
                    $this->shipAddr->company = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Firma"];
                }
                $this->shipAddr->lastname = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Nachname"];
                $this->shipAddr->street = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Strasse"];
                $this->shipAddr->houseno = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Hausnummer"];
                $this->shipAddr->zip = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_PLZ"];
                $this->shipAddr->city = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Ort"];
                $this->shipAddr->country_id = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Land"];
                $this->shipAddr->phone = $_SESSION["SHOP"]["buy"]["Persdata"]["Telefon"];
                $this->shipAddr->email = $_SESSION["SHOP"]["buy"]["Persdata"]["email"];
                $this->shipAddr->save();
                $this->shipAddrId = $this->billAddr->id;
            }
            $this->order = new Order();
            $this->order->shop_id = $GLOBALS["INI"]["shops_ID"];
            $this->order->user_id = $_SESSION["SHOP"]["buy"]["Persdata"]["ID"];
            $this->order->order_type_id = 1;
            $this->order->ship_addr_id = $this->shipAddrId;
            $this->order->bill_addr_id = $this->billAddrId;
            $this->order->created_by = "(Bestellung)";
            $this->order->save();
            $this->orderId = $this->order->id;
            $this->orderItems = array();
            foreach ( $_SESSION["SHOP"]["BASKET"]->items as $item )
            {
                $this->orderItem = new OrderItem();
                $this->orderItem->name = $item->name;
                $this->orderItem->item_id = $item->id;
                $this->orderItem->price = $item->price;
                $this->orderItem->amount = $item->menge;
                $this->orderItem->option_input = $item->addinfo;
                $this->orderItem->save();
                $this->orderItems[] = $this->orderItem;
            }
            return $this->orderId;
        }

        public function mail()
        {
            $webSettings = WebSetting::where( 'shop_id', '=', $this->order->shop_id )->where( 'order_type_id', '=', $this->order->order_type_id )->whereIn( 'id', [
                11,
                12,
                13,
                14,
                17,
                18,
                1000,
            ] )->get();
            foreach ( $webSettings as $webSetting )
            {
                switch ( $webSetting->id )
                {
                    case 11:
                        $fromEmail = $webSetting->content;
                        break;
                    case 12:
                        $customerSubject = $webSetting->content;
                        break;
                    case 13:
                        $customerBody = $webSetting->content;
                        break;
                    case 14:
                        $bccAddress = $webSetting->content;
                        break;
                    case 17:
                        $shopSubject = $webSetting->content;
                        break;
                    case 18:
                        $shopBody = $webSetting->content;
                        break;
                    case 1000:
                        $template = $webSetting->content;
                        break;
                }
            }

        }

        /**
         * Store a newly created resource in storage.
         *
         * @param Request $request
         * @return RedirectResponse
         */
        public function store( Request $request ): RedirectResponse
        {
            //
            $rules = [
                'name' => 'bail|max:255',
            ];
            $request->validate( $rules );
            $bu = new Order();
            $bu->update( $request->validated() );
            return redirect( "/backend/orders" );
        }

        /**
         * Display the specified resource.
         *
         * @param int $id
         */
        public function show( int $id )
        {
            //
        }

        /**
         * Show the form for editing the specified resource.
         *
         * @param int $id
         * @return Factory|View|Application
         */
        public function edit( int $id ): Factory|View|Application
        {
            //
            $order = Order::with( [
                'shop',
                'orderType',
                'orderItem',
                'billAddr',
                'shipAddr',
                'orderItem.item',
                'orderItem.item.medium.medium',
            ] )->find( $id );
            $order->kk_info = unserialize( $order->kk_info );
            $preise_anzeigen = 1;
            if ( isset( $GLOBALS["web_rechte"]["Warenwirtschaft"]["bestellung"]["preise_anzeigen"] ) )
            {
                if ( !isset( $GLOBALS["user_rechte"]["Warenwirtschaft"]["bestellung"]["preise_anzeigen"] ) )
                {
                    // "<br/>für bestimmte user preis verbergen";
                    $preise_anzeigen = 0;
                }
            }
            \View::share( "preise_anzeigen", $preise_anzeigen );
            return view( 'admin/order', [ "order" => $order, ] );
        }


        /**
         * Update the specified resource in storage.
         *
         * @param ActionRequest $request
         * @param int $id
         * @return RedirectResponse
         */
        public function update( ActionRequest $request, int $id ): RedirectResponse
        {
            //
            $rules = [
                'name' => 'bail|max:255',
            ];
            $request->validate( $rules );
            $bu = Order::find( $id );
            $data = $request->validated();
            $bu->update( $data );
            return redirect( "/backend/orders" );
        }

        /**
         * Remove the specified resource from storage.
         *
         * @param int $id
         * @return RedirectResponse
         */
        public function destroy( int $id ): RedirectResponse
        {
            //
            $bu = Order::find( $id );
            $bu->update( [ "status" => "cancelled" ] );
            return redirect( "/backend/orders" );
        }
    }