Subversion-Projekte lars-tiefland.webanos.marine-sales.de

Revision

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

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