Skip to content

Commit b34fbd4

Browse files
committed
First Final Version
1 parent fd60b77 commit b34fbd4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+25137
-66413
lines changed

app/Action.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Action extends Model
88
{
99
//
1010
protected $fillable = [
11-
'name', 'group_id', 'year', 'action_status_id', 'address_id'
11+
'name', 'group_id', 'year', 'action_status_id', 'address_id', 'APIKey', 'SmartsuppToken'
1212
];
1313

1414
public function group(){

app/Http/Controllers/AdminActionsController.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ public function store(Request $request)
8484
$group = Auth::user()->group;
8585
$input['group_id'] = $group['id'];
8686
}
87+
$user = Auth::user();
88+
$action = $user->getAction();
89+
GeoCoder::setApiKey($action['APIKey']);
90+
GeoCoder::setCountry('CH');
8791
$geocode = Geocoder::getCoordinatesForAddress($input['street'] . ', ' .$input['plz'] . ' '.$input['city']);
8892
$input['lat'] = $geocode['lat'];
8993
$input['lng'] = $geocode['lng'];
@@ -145,6 +149,8 @@ public function update(Request $request, $id)
145149
$address=$action->center;
146150
if($address){
147151
$input = $request->all();
152+
GeoCoder::setApiKey($action['APIKey']);
153+
GeoCoder::setCountry('CH');
148154
$geocode = Geocoder::getCoordinatesForAddress($input['street'] . ', ' .$input['plz'] . ' '.$input['city']);
149155
$input['lat'] = $geocode['lat'];
150156
$input['lng'] = $geocode['lng'];
@@ -191,7 +197,7 @@ public function complete(Request $request, $id)
191197
{
192198
//
193199
$action = Action::findOrFail($id);
194-
$action->action_status_id = 10;
200+
$action->action_status_id = config('status.action_aktiv');
195201
$action->update($request->all());
196202
return redirect('/admin/actions');
197203
}

app/Http/Controllers/AdminAddressesController.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ public function searchResponseCity(Request $request)
6969
public function store(Request $request)
7070
{
7171
//
72+
$user = Auth::user();
73+
$action = $user->getAction();
7274
$city=City::Where('id',$request->city_id)->first();
7375
if(!$city){
7476
return back()->withInput()->withErrors(['errors' => ['Ortschaft nicht gefunden.']]);
@@ -81,7 +83,9 @@ public function store(Request $request)
8183
$group = Auth::user()->group;
8284
$input['group_id'] = $group['id'];
8385
}
84-
$geocode = Geocoder::getCoordinatesForAddress($input['street'] . ', ' . $city->plz . ' '.$city->name);
86+
GeoCoder::setApiKey($action['APIKey']);
87+
GeoCoder::setCountry('CH');
88+
$geocode = GeoCoder::getCoordinatesForAddress($input['street'] . ', ' . $city->plz . ' '.$city->name);
8589
$input['lat'] = $geocode['lat'];
8690
$input['lng'] = $geocode['lng'];
8791

@@ -141,6 +145,10 @@ public function update(Request $request, $id)
141145
$input = $request->all();
142146
$input['city_id'] = $city->id;
143147
}
148+
$user = Auth::user();
149+
$action = $user->getAction();
150+
GeoCoder::setApiKey($action['APIKey']);
151+
GeoCoder::setCountry('CH');
144152

145153
$geocode = Geocoder::getCoordinatesForAddress($input['street'] . ', ' . $city->plz . ' '.$city->name);
146154
$input['lat'] = $geocode['lat'];

app/Http/Controllers/AdminController.php

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,31 @@ public function index(){
4040
// array_push($graphs_sum, $graph->sum);
4141
// }
4242
$graphs = $graphs->where('quantity', '>',0)->get()->sortBy('wann');
43-
$graphs_time_min = $graphs->first()->wann;
44-
$graphs_time_max = $graphs->last()->wann;
45-
$graphs_time_max = date('H:i:s', (ceil(strtotime($graphs_time_max)/1800)*1800));
43+
if(count($graphs)>0){
44+
$graphs_time_min = $graphs->first()->wann;
45+
$graphs_time_max = $graphs->last()->wann;
46+
$graphs_time_max = date('H:i:s', (ceil(strtotime($graphs_time_max)/1800)*1800));
4647

47-
$diff = ceil((strtotime($graphs_time_max)-strtotime($graphs_time_min))/1800);
48-
49-
$graphs_time = array();
50-
$graphs_sum = array();
48+
$diff = ceil((strtotime($graphs_time_max)-strtotime($graphs_time_min))/1800);
49+
50+
$graphs_time = array();
51+
$graphs_sum = array();
5152

52-
array_push($graphs_time, date('H:i:s', (floor(strtotime($graphs_time_min)/1800)*1800)));
53+
array_push($graphs_time, date('H:i:s', (floor(strtotime($graphs_time_min)/1800)*1800)));
5354

54-
for($i = 0;$i <= $diff; $i++){
55-
if($i > 0){
56-
array_push($graphs_time, date('H:i:s', strtotime($graphs_time[$i - 1])+1800));
55+
for($i = 0;$i <= $diff; $i++){
56+
if($i > 0){
57+
array_push($graphs_time, date('H:i:s', strtotime($graphs_time[$i - 1])+1800));
58+
}
59+
$graph_sum = Logbook::where('action_id', $action['id'])->whereTime('wann', '>', date('H:i:s', strtotime($graphs_time[$i])-900))
60+
->whereTime('wann', '<', date('H:i:s', strtotime($graphs_time[$i])+900));
61+
array_push($graphs_sum, $graph_sum->sum('quantity'));
5762
}
58-
$graph_sum = Logbook::where('action_id', $action['id'])->whereTime('wann', '>', date('H:i:s', strtotime($graphs_time[$i])-900))
59-
->whereTime('wann', '<', date('H:i:s', strtotime($graphs_time[$i])+900));
60-
array_push($graphs_sum, $graph_sum->sum('quantity'));
6163
}
62-
64+
else{
65+
$graphs_time = 0;
66+
$graphs_sum = 0;
67+
}
6368
$total = $action->orders->sum('quantity') + $cut;
6469

6570
$routes = Route::where('action_id', $action['id'])->get();
@@ -74,15 +79,17 @@ public function index(){
7479
else{
7580
$total = 0;
7681
$orders_count = 0;
77-
$orders_open_delivery = 0;
78-
$orders_on_route = 0;
82+
$routes_count = 0;
83+
$orders_open = 0;
84+
$orders_delivery = 0;
7985
$orders_open_pickup = 0;
8086
$orders_finished = 0;
8187
$cut = 0;
8288
$logbooks = 0;
83-
$routes_count = 0;
8489
$open_routes = 0;
8590
$users = 0;
91+
$graphs_time = 0;
92+
$graphs_sum = 0;
8693
}
8794

8895
return view('admin/index', compact('total', 'orders_count', 'routes_count', 'orders_open', 'orders_delivery','orders_open_pickup',

app/Http/Controllers/AdminOrdersController.php

Lines changed: 57 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)