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

Revision

Revision 27 | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
24 lars 1
<?php
2
 
3
    namespace App\Http\Controllers;
4
 
5
    use App\Http\Requests\ActionRequest;
6
    use App\Models\WebSetting;
7
    use Illuminate\Contracts\Foundation\Application;
8
    use Illuminate\Contracts\View\Factory;
9
    use Illuminate\Contracts\View\View;
10
    use Illuminate\Http\RedirectResponse;
11
    use Illuminate\Http\Request;
12
    use App\Models\OrderAddress;
13
    use App\Models\OrderItem;
14
    use App\Models\Order;
15
 
16
    class OrderController extends Controller
17
    {
18
        //
19
        private int       $shipAddrId;
20
        private int       $billAddrId;
21
        private Order     $order;
22
        private int       $orderId;
23
        private OrderItem $orderItem;
24
        private array     $orderItems;
25
 
26
        /**
27
         * Display a listing of the resource.
28
         *
29
         */
30
        public function index(): Factory|View|Application
31
        {
32
            //
33
            $orders = Order::with( [
34
                'shop',
35
                'orderType',
36
                'orderItem',
37
                'billAddr',
38
                'shipAddr'
39
            ] )->orderBy( "created_at", 'desc' )->paginate( 100 );
26 lars 40
            return view( 'orders', [ "orders" => $orders, ] );
24 lars 41
        }
42
 
43
        public function create()
44
        {
45
            $this->billAddr = new OrderAddress();
46
            if ( !( isset( $_SESSION["SHOP"]["buy"]["Persdata"]["ID"] ) && $_SESSION["SHOP"]["buy"]["Persdata"]["ID"] ) )
47
            {
48
                $_SESSION["SHOP"]["buy"]["Persdata"]["ID"] = 1;
49
            }
50
            $this->billAddr->user_id = $_SESSION["SHOP"]["buy"]["Persdata"]["ID"];
51
            $this->billAddr->name = $_SESSION["SHOP"]["buy"]["Persdata"]["Vorname"];
52
            $this->billAddr->lastname = $_SESSION["SHOP"]["buy"]["Persdata"]["Nachname"];
53
            if ( $_SESSION["SHOP"]["buy"]["Persdata"]["Firma"] )
54
            {
55
                $this->billAddr->company = $_SESSION["SHOP"]["buy"]["Persdata"]["Firma"];
56
            }
57
            $this->billAddr->street = $_SESSION["SHOP"]["buy"]["Persdata"]["Strasse"];
58
            $this->billAddr->houseno = $_SESSION["SHOP"]["buy"]["Persdata"]["Hausnummer"];
59
            $this->billAddr->zip = $_SESSION["SHOP"]["buy"]["Persdata"]["PLZ"];
60
            $this->billAddr->city = $_SESSION["SHOP"]["buy"]["Persdata"]["Ort"];
61
            $this->billAddr->country_id = $_SESSION["SHOP"]["buy"]["Persdata"]["Land"];
62
            $this->billAddr->phone = $_SESSION["SHOP"]["buy"]["Persdata"]["Telefon"];
63
            $this->billAddr->email = $_SESSION["SHOP"]["buy"]["Persdata"]["email"];
64
            $this->billAddr->save();
65
            $this->billAddrId = $this->billAddr->id;
66
 
67
            if ( $_SESSION["SHOP"]["Lieferadresse"] == "packstation" )
68
            {
69
                $this->shipAddr = new OrderAddress();
70
                $this->shipAddr->user_id = $_SESSION["SHOP"]["buy"]["Persdata"]["ID"];
71
                $this->shipAddr->name = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Vorname_pst"];
72
                $this->shipAddr->lastname = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Nachname_pst"];
73
                if ( $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Firma_pst"] )
74
                {
75
                    $this->shipAddr->company = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Firma_pst"];
76
                }
77
                $this->shipAddr->street = $_SESSION["SHOP"]["buy"]["Persdata"]["lieferStrasse_pst"];
78
                $this->shipAddr->houseno = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Hausnummer_pst"];
79
                $this->shipAddr->zip = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_PLZ_pst"];
80
                $this->shipAddr->city = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Ort_pst"];
81
                $this->shipAddr->country_id = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Land_pst"];
82
                $this->shipAddr->phone = $_SESSION["SHOP"]["buy"]["Persdata"]["Telefon"];
83
                $this->shipAddr->email = $_SESSION["SHOP"]["buy"]["Persdata"]["email"];
84
                $this->shipAddr->save();
85
                $this->shipAddrId = $this->billAddr->id;
86
            }
87
            else
88
            {
89
                $this->shipAddr = new OrderAddress();
90
                $this->shipAddr->user_id = $_SESSION["SHOP"]["buy"]["Persdata"]["ID"];
91
                $this->shipAddr->name = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Vorname"];
92
                if ( $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Firma"] )
93
                {
94
                    $this->shipAddr->company = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Firma"];
95
                }
96
                $this->shipAddr->lastname = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Nachname"];
97
                $this->shipAddr->street = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Strasse"];
98
                $this->shipAddr->houseno = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Hausnummer"];
99
                $this->shipAddr->zip = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_PLZ"];
100
                $this->shipAddr->city = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Ort"];
101
                $this->shipAddr->country_id = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Land"];
102
                $this->shipAddr->phone = $_SESSION["SHOP"]["buy"]["Persdata"]["Telefon"];
103
                $this->shipAddr->email = $_SESSION["SHOP"]["buy"]["Persdata"]["email"];
104
                $this->shipAddr->save();
105
                $this->shipAddrId = $this->billAddr->id;
106
            }
107
            $this->order = new Order();
108
            $this->order->shop_id = $GLOBALS["INI"]["shops_ID"];
109
            $this->order->user_id = $_SESSION["SHOP"]["buy"]["Persdata"]["ID"];
110
            $this->order->order_type_id = 1;
111
            $this->order->ship_addr_id = $this->shipAddrId;
112
            $this->order->bill_addr_id = $this->billAddrId;
113
            $this->order->created_by = "(Bestellung)";
114
            $this->order->save();
115
            $this->orderId = $this->order->id;
116
            $this->orderItems = array();
117
            foreach ( $_SESSION["SHOP"]["BASKET"]->items as $item )
118
            {
119
                $this->orderItem = new OrderItem();
120
                $this->orderItem->name = $item->name;
121
                $this->orderItem->item_id = $item->id;
122
                $this->orderItem->price = $item->price;
123
                $this->orderItem->amount = $item->menge;
124
                $this->orderItem->option_input = $item->addinfo;
125
                $this->orderItem->save();
126
                $this->orderItems[] = $this->orderItem;
127
            }
128
            return $this->orderId;
129
        }
130
 
131
        public function mail()
132
        {
133
            $webSettings = WebSetting::where( 'shop_id', '=', $this->order->shop_id )->where( 'order_type_id', '=', $this->order->order_type_id )->whereIn( 'id', [
134
                11,
135
                12,
136
                13,
137
                14,
138
                17,
139
                18,
140
                1000,
141
            ] )->get();
142
            foreach ( $webSettings as $webSetting )
143
            {
144
                switch ( $webSetting->id )
145
                {
146
                    case 11:
147
                        $fromEmail = $webSetting->content;
148
                        break;
149
                    case 12:
150
                        $customerSubject = $webSetting->content;
151
                        break;
152
                    case 13:
153
                        $customerBody = $webSetting->content;
154
                        break;
155
                    case 14:
156
                        $bccAddress = $webSetting->content;
157
                        break;
158
                    case 17:
159
                        $shopSubject = $webSetting->content;
160
                        break;
161
                    case 18:
162
                        $shopBody = $webSetting->content;
163
                        break;
164
                    case 1000:
165
                        $template = $webSetting->content;
166
                        break;
167
                }
168
            }
169
 
170
        }
171
 
172
        /**
173
         * Store a newly created resource in storage.
174
         *
175
         * @param Request $request
176
         * @return RedirectResponse
177
         */
178
        public function store( Request $request ): RedirectResponse
179
        {
180
            //
181
            $rules = [
182
                'name' => 'bail|max:255',
183
            ];
184
            $request->validate( $rules );
185
            $bu = new Order();
186
            $bu->update( $request->validated() );
28 lars 187
            return redirect( "/orders" );
24 lars 188
        }
189
 
190
        /**
191
         * Display the specified resource.
192
         *
193
         * @param int $id
194
         */
195
        public function show( int $id )
196
        {
197
            //
198
        }
199
 
200
        /**
201
         * Show the form for editing the specified resource.
202
         *
203
         * @param int $id
204
         * @return Factory|View|Application
205
         */
206
        public function edit( int $id ): Factory|View|Application
207
        {
208
            //
209
            $order = Order::with( [
210
                'shop',
211
                'orderType',
212
                'orderItem',
213
                'billAddr',
214
                'shipAddr',
215
                'orderItem.item',
216
                'orderItem.item.medium.medium',
217
            ] )->find( $id );
218
            $order->kk_info = unserialize( $order->kk_info );
219
            $preise_anzeigen = 1;
220
            if ( isset( $GLOBALS["web_rechte"]["Warenwirtschaft"]["bestellung"]["preise_anzeigen"] ) )
221
            {
222
                if ( !isset( $GLOBALS["user_rechte"]["Warenwirtschaft"]["bestellung"]["preise_anzeigen"] ) )
223
                {
224
                    // "<br/>für bestimmte user preis verbergen";
225
                    $preise_anzeigen = 0;
226
                }
227
            }
228
            \View::share( "preise_anzeigen", $preise_anzeigen );
26 lars 229
            return view( 'order', [ "order" => $order, ] );
24 lars 230
        }
231
 
232
 
233
        /**
234
         * Update the specified resource in storage.
235
         *
236
         * @param ActionRequest $request
237
         * @param int $id
238
         * @return RedirectResponse
239
         */
240
        public function update( ActionRequest $request, int $id ): RedirectResponse
241
        {
242
            //
243
            $rules = [
244
                'name' => 'bail|max:255',
245
            ];
246
            $request->validate( $rules );
247
            $bu = Order::find( $id );
248
            $data = $request->validated();
249
            $bu->update( $data );
28 lars 250
            return redirect( "/orders" );
24 lars 251
        }
252
 
253
        /**
254
         * Remove the specified resource from storage.
255
         *
256
         * @param int $id
257
         * @return RedirectResponse
258
         */
259
        public function destroy( int $id ): RedirectResponse
260
        {
261
            //
262
            $bu = Order::find( $id );
263
            $bu->update( [ "status" => "cancelled" ] );
28 lars 264
            return redirect( "/orders" );
24 lars 265
        }
266
    }