@@ -95,15 +95,15 @@ public function createRoute(Request $request)
9595 {
9696 $ input ['name ' ] = $ request ->name ;
9797 $ input ['action_id ' ] = $ action ['id ' ];
98- $ input ['route_status_id ' ] = 5 ;
98+ $ input ['route_status_id ' ] = config ( ' status.route_geplant ' ) ;
9999 $ input ['user_id ' ] = Auth::user ()->id ;
100100 $ route = Route::create ($ input );
101101
102102
103103 }
104104 Order::WhereIn ('id ' ,$ request ->id )->update (['route_id ' => $ route ['id ' ]]);
105105
106- $ routes = Route::where ('action_id ' , $ action ['id ' ])->where ('route_status_id ' ,5 )->get ();
106+ $ routes = Route::where ('action_id ' , $ action ['id ' ])->where ('route_status_id ' , config ( ' status.route_geplant ' ) )->get ();
107107 return view ('admin.orders.index ' , compact ('routes ' ));
108108 }
109109
@@ -115,20 +115,22 @@ public function createRoute(Request $request)
115115 public function create ()
116116 {
117117 //
118- $ routes = Route::where ('route_status_id ' ,5 )->get ();
118+ $ routes = Route::where ('route_status_id ' , config ( ' status.route_geplant ' ) )->get ();
119119 $ routes = $ routes ->pluck ('name ' ,'id ' )->all ();
120120 return view ('admin.orders.create ' , compact ('routes ' ));
121121 }
122122
123123 public function map ()
124124 {
125125 $ action = Auth::user ()->getaction ();
126- $ orders = Order::where ('action_id ' , $ action ['id ' ])->get ();
126+ $ orders = Order::where ('action_id ' , $ action ['id ' ]);
127+ $ orders = $ orders ->with ('address ' )->get ();
127128 $ cities = $ action ->addresses ->unique ('city ' )->pluck ('city ' );
128129 $ statuses = OrderStatus::pluck ('name ' )->all ();
129130 $ center = $ action ->center ;
131+ $ key = $ action ['APIKey ' ];
130132
131- return view ('admin.orders.map ' , compact ('orders ' , 'cities ' , 'statuses ' , 'center ' ));
133+ return view ('admin.orders.map ' , compact ('orders ' , 'cities ' , 'statuses ' , 'center ' , ' key ' ));
132134 }
133135
134136 public function mapfilter (Request $ request )
@@ -145,7 +147,7 @@ public function mapfilter(Request $request)
145147
146148 if (isset ($ status ) and $ status !="Alle " ){
147149 $ order_status = OrderStatus::where ('name ' ,$ status )->first ();
148- $ orders ->where ('order_status_id ' ,$ order_status ['id ' ])-> get () ;
150+ $ orders ->where ('order_status_id ' ,$ order_status ['id ' ]);
149151 }
150152
151153 $ orders = $ orders ->with ('address ' )->get ();
@@ -164,6 +166,10 @@ public function uploadFile(Request $request){
164166 $ user = Auth::user ();
165167 $ action = $ user ->getAction ();
166168 $ center = $ action ->center ;
169+ $ user = Auth::user ();
170+ $ action = $ user ->getAction ();
171+ GeoCoder::setApiKey ($ action ['APIKey ' ]);
172+ GeoCoder::setCountry ('CH ' );
167173 foreach ($ importData_arr as $ importData ){
168174 // return $importData;
169175 $ importData ['abholung ' ] = $ importData ['abholung ' ] === "x " ? 1 : 0 ;
@@ -175,7 +181,9 @@ public function uploadFile(Request $request){
175181 "street " => $ center ['street ' ],
176182 "group_id " => $ user ->group ['id ' ],
177183 "city " => $ center ['city ' ],
178- "plz " => $ center ['plz ' ]);
184+ "plz " => $ center ['plz ' ],
185+ "lat " => $ center ['lat ' ],
186+ "lng " => $ center ['lng ' ]);
179187 }
180188 else {
181189 $ insertAddress = array (
@@ -190,38 +198,40 @@ public function uploadFile(Request $request){
190198 $ address = Address::firstOrCreate (['name ' => $ importData ['name ' ], 'firstname ' => $ importData ['vorname ' ]], $ insertAddress );
191199
192200 if ($ address ){
193- $ geocode = Geocoder::getCoordinatesForAddress ($ address ['street ' ] . ', ' .$ address ['plz ' ] . ' ' .$ address ['city ' ]);
194- $ lat = $ geocode ['lat ' ];
195- $ lng = $ geocode ['lng ' ];
196-
197- $ address ->update (['lat ' => $ lat , 'lng ' => $ lng ]);
198-
199- if ($ importData ['route ' ]){
200- $ insertRoute = array (
201- "name " => $ importData ['route ' ],
202- "action_id " => $ user ->getAction ,
203- "route_status_id " => config ('status.route_geplant ' ));
204-
205- $ route = Route::firstOrCreate (['name ' => $ importData ['route ' ],], $ insertRoute );
206- $ route_id = $ route ['id ' ];
207- }
208- else
209- {
210- $ route_id = null ;
211- }
212-
201+ if (!$ importData ['abholung ' ]){
202+ $ geocode = Geocoder::getCoordinatesForAddress ($ address ['street ' ] . ', ' .$ address ['plz ' ] . ' ' .$ address ['city ' ]);
203+ $ lat = $ geocode ['lat ' ];
204+ $ lng = $ geocode ['lng ' ];
205+
206+ $ address ->update (['lat ' => $ lat , 'lng ' => $ lng ]);
207+ }
208+
209+ if ($ importData ['route ' ]){
210+ $ insertRoute = array (
211+ "name " => $ importData ['route ' ],
212+ "action_id " => $ user ->getAction ,
213+ "route_status_id " => config ('status.route_geplant ' ));
214+
215+ $ route = Route::firstOrCreate (['name ' => $ importData ['route ' ],], $ insertRoute );
216+ $ route_id = $ route ['id ' ];
217+ }
218+ else
219+ {
220+ $ route_id = null ;
221+ }
222+
213223
214- $ insertOrder = array (
215-
216- "quantity " => $ importData ['anzahl ' ],
217- "route_id " => $ route_id ,
218- "action_id " => $ action ['id ' ],
219- "address_id " => $ address ['id ' ],
220- "order_status_id " => config ('status.order_offen ' ),
221- "pick_up " => $ importData ['abholung ' ],
222- "comments " => $ importData ['bemerkung ' ]);
224+ $ insertOrder = array (
225+
226+ "quantity " => $ importData ['anzahl ' ],
227+ "route_id " => $ route_id ,
228+ "action_id " => $ action ['id ' ],
229+ "address_id " => $ address ['id ' ],
230+ "order_status_id " => config ('status.order_offen ' ),
231+ "pick_up " => $ importData ['abholung ' ],
232+ "comments " => $ importData ['bemerkung ' ]);
223233 }
224- Order::firstOrCreate (['action_id ' => $ action ['id ' ], 'address_id ' => $ address ['id ' ]], $ insertOrder );
234+ Order::firstOrCreate (['action_id ' => $ action ['id ' ], 'address_id ' => $ address ['id ' ], ' quantity ' => $ importData [ ' anzahl ' ], ' comments ' => $ importData [ ' bemerkung ' ] ], $ insertOrder );
225235
226236
227237 }
@@ -262,6 +272,10 @@ public function store(Request $request)
262272 $ group = Auth::user ()->group ;
263273 $ input ['group_id ' ] = $ group ['id ' ];
264274 }
275+ $ user = Auth::user ();
276+ $ action = $ user ->getAction ();
277+ GeoCoder::setApiKey ($ action ['APIKey ' ]);
278+ GeoCoder::setCountry ('CH ' );
265279 $ geocode = Geocoder::getCoordinatesForAddress ($ input ['street ' ] . ', ' .$ input ['plz ' ] . ' ' .$ input ['city ' ]);
266280 $ input ['lat ' ] = $ geocode ['lat ' ];
267281 $ input ['lng ' ] = $ geocode ['lng ' ];
@@ -276,7 +290,7 @@ public function store(Request $request)
276290 $ input ['address_id ' ] = $ address ->id ;
277291 $ action = Auth::user ()->getAction ();
278292 $ input ['action_id ' ] = $ action ['id ' ];
279- $ input ['order_status_id ' ] = 5 ;
293+ $ input ['order_status_id ' ] = config ( ' status.order_offen ' ) ;
280294
281295 Order::create ($ input );
282296
@@ -305,7 +319,7 @@ public function edit($id)
305319 {
306320 //
307321 $ action = Auth::user ()->getAction ();
308- $ routes = Route::where ('action_id ' , $ action ['id ' ])->where ('route_status_id ' ,5 )->get ();
322+ $ routes = Route::where ('action_id ' , $ action ['id ' ])->where ('route_status_id ' , config ( ' status.route_unterwegs ' ) )->get ();
309323 $ routes = $ routes ->pluck ('name ' ,'id ' )->all ();
310324 $ order = Order::findOrFail ($ id );
311325
@@ -324,6 +338,10 @@ public function update(Request $request, $id)
324338 //
325339 $ order = Order::findOrFail ($ id );
326340 $ address =$ order ->address ;
341+ $ user = Auth::user ();
342+ $ action = $ user ->getAction ();
343+ GeoCoder::setApiKey ($ action ['APIKey ' ]);
344+ GeoCoder::setCountry ('CH ' );
327345 if ($ address ){
328346 $ input = $ request ->all ();
329347 $ geocode = Geocoder::getCoordinatesForAddress ($ input ['street ' ] . ', ' .$ input ['plz ' ] . ' ' .$ input ['city ' ]);
0 commit comments