Skip to content

Commit

Permalink
First Final Version
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromesigg committed Nov 6, 2020
1 parent fd60b77 commit b34fbd4
Show file tree
Hide file tree
Showing 47 changed files with 25,137 additions and 66,413 deletions.
2 changes: 1 addition & 1 deletion app/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Action extends Model
{
//
protected $fillable = [
'name', 'group_id', 'year', 'action_status_id', 'address_id'
'name', 'group_id', 'year', 'action_status_id', 'address_id', 'APIKey', 'SmartsuppToken'
];

public function group(){
Expand Down
8 changes: 7 additions & 1 deletion app/Http/Controllers/AdminActionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ public function store(Request $request)
$group = Auth::user()->group;
$input['group_id'] = $group['id'];
}
$user = Auth::user();
$action = $user->getAction();
GeoCoder::setApiKey($action['APIKey']);
GeoCoder::setCountry('CH');
$geocode = Geocoder::getCoordinatesForAddress($input['street'] . ', ' .$input['plz'] . ' '.$input['city']);
$input['lat'] = $geocode['lat'];
$input['lng'] = $geocode['lng'];
Expand Down Expand Up @@ -145,6 +149,8 @@ public function update(Request $request, $id)
$address=$action->center;
if($address){
$input = $request->all();
GeoCoder::setApiKey($action['APIKey']);
GeoCoder::setCountry('CH');
$geocode = Geocoder::getCoordinatesForAddress($input['street'] . ', ' .$input['plz'] . ' '.$input['city']);
$input['lat'] = $geocode['lat'];
$input['lng'] = $geocode['lng'];
Expand Down Expand Up @@ -191,7 +197,7 @@ public function complete(Request $request, $id)
{
//
$action = Action::findOrFail($id);
$action->action_status_id = 10;
$action->action_status_id = config('status.action_aktiv');
$action->update($request->all());
return redirect('/admin/actions');
}
Expand Down
10 changes: 9 additions & 1 deletion app/Http/Controllers/AdminAddressesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public function searchResponseCity(Request $request)
public function store(Request $request)
{
//
$user = Auth::user();
$action = $user->getAction();
$city=City::Where('id',$request->city_id)->first();
if(!$city){
return back()->withInput()->withErrors(['errors' => ['Ortschaft nicht gefunden.']]);
Expand All @@ -81,7 +83,9 @@ public function store(Request $request)
$group = Auth::user()->group;
$input['group_id'] = $group['id'];
}
$geocode = Geocoder::getCoordinatesForAddress($input['street'] . ', ' . $city->plz . ' '.$city->name);
GeoCoder::setApiKey($action['APIKey']);
GeoCoder::setCountry('CH');
$geocode = GeoCoder::getCoordinatesForAddress($input['street'] . ', ' . $city->plz . ' '.$city->name);
$input['lat'] = $geocode['lat'];
$input['lng'] = $geocode['lng'];

Expand Down Expand Up @@ -141,6 +145,10 @@ public function update(Request $request, $id)
$input = $request->all();
$input['city_id'] = $city->id;
}
$user = Auth::user();
$action = $user->getAction();
GeoCoder::setApiKey($action['APIKey']);
GeoCoder::setCountry('CH');

$geocode = Geocoder::getCoordinatesForAddress($input['street'] . ', ' . $city->plz . ' '.$city->name);
$input['lat'] = $geocode['lat'];
Expand Down
43 changes: 25 additions & 18 deletions app/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,31 @@ public function index(){
// array_push($graphs_sum, $graph->sum);
// }
$graphs = $graphs->where('quantity', '>',0)->get()->sortBy('wann');
$graphs_time_min = $graphs->first()->wann;
$graphs_time_max = $graphs->last()->wann;
$graphs_time_max = date('H:i:s', (ceil(strtotime($graphs_time_max)/1800)*1800));
if(count($graphs)>0){
$graphs_time_min = $graphs->first()->wann;
$graphs_time_max = $graphs->last()->wann;
$graphs_time_max = date('H:i:s', (ceil(strtotime($graphs_time_max)/1800)*1800));

$diff = ceil((strtotime($graphs_time_max)-strtotime($graphs_time_min))/1800);

$graphs_time = array();
$graphs_sum = array();
$diff = ceil((strtotime($graphs_time_max)-strtotime($graphs_time_min))/1800);
$graphs_time = array();
$graphs_sum = array();

array_push($graphs_time, date('H:i:s', (floor(strtotime($graphs_time_min)/1800)*1800)));
array_push($graphs_time, date('H:i:s', (floor(strtotime($graphs_time_min)/1800)*1800)));

for($i = 0;$i <= $diff; $i++){
if($i > 0){
array_push($graphs_time, date('H:i:s', strtotime($graphs_time[$i - 1])+1800));
for($i = 0;$i <= $diff; $i++){
if($i > 0){
array_push($graphs_time, date('H:i:s', strtotime($graphs_time[$i - 1])+1800));
}
$graph_sum = Logbook::where('action_id', $action['id'])->whereTime('wann', '>', date('H:i:s', strtotime($graphs_time[$i])-900))
->whereTime('wann', '<', date('H:i:s', strtotime($graphs_time[$i])+900));
array_push($graphs_sum, $graph_sum->sum('quantity'));
}
$graph_sum = Logbook::where('action_id', $action['id'])->whereTime('wann', '>', date('H:i:s', strtotime($graphs_time[$i])-900))
->whereTime('wann', '<', date('H:i:s', strtotime($graphs_time[$i])+900));
array_push($graphs_sum, $graph_sum->sum('quantity'));
}

else{
$graphs_time = 0;
$graphs_sum = 0;
}
$total = $action->orders->sum('quantity') + $cut;

$routes = Route::where('action_id', $action['id'])->get();
Expand All @@ -74,15 +79,17 @@ public function index(){
else{
$total = 0;
$orders_count = 0;
$orders_open_delivery = 0;
$orders_on_route = 0;
$routes_count = 0;
$orders_open = 0;
$orders_delivery = 0;
$orders_open_pickup = 0;
$orders_finished = 0;
$cut = 0;
$logbooks = 0;
$routes_count = 0;
$open_routes = 0;
$users = 0;
$graphs_time = 0;
$graphs_sum = 0;
}

return view('admin/index', compact('total', 'orders_count', 'routes_count', 'orders_open', 'orders_delivery','orders_open_pickup',
Expand Down
96 changes: 57 additions & 39 deletions app/Http/Controllers/AdminOrdersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ public function createRoute(Request $request)
{
$input['name'] = $request->name;
$input['action_id'] = $action['id'];
$input['route_status_id'] = 5;
$input['route_status_id'] = config('status.route_geplant');
$input['user_id'] = Auth::user()->id;
$route = Route::create($input);


}
Order::WhereIn('id',$request->id)->update(['route_id' => $route['id']]);

$routes = Route::where('action_id', $action['id'])->where('route_status_id',5)->get();
$routes = Route::where('action_id', $action['id'])->where('route_status_id', config('status.route_geplant'))->get();
return view('admin.orders.index', compact('routes'));
}

Expand All @@ -115,20 +115,22 @@ public function createRoute(Request $request)
public function create()
{
//
$routes = Route::where('route_status_id',5)->get();
$routes = Route::where('route_status_id', config('status.route_geplant'))->get();
$routes = $routes->pluck('name','id')->all();
return view('admin.orders.create', compact('routes'));
}

public function map()
{
$action= Auth::user()->getaction();
$orders = Order::where('action_id', $action['id'])->get();
$orders = Order::where('action_id', $action['id']);
$orders = $orders->with('address')->get();
$cities = $action->addresses->unique('city')->pluck('city');
$statuses = OrderStatus::pluck('name')->all();
$center = $action->center;
$key = $action['APIKey'];

return view('admin.orders.map', compact('orders', 'cities', 'statuses', 'center'));
return view('admin.orders.map', compact('orders', 'cities', 'statuses', 'center', 'key'));
}

public function mapfilter(Request $request)
Expand All @@ -145,7 +147,7 @@ public function mapfilter(Request $request)

if(isset($status) and $status!="Alle"){
$order_status = OrderStatus::where('name',$status)->first();
$orders->where('order_status_id',$order_status['id'])->get();
$orders->where('order_status_id',$order_status['id']);
}

$orders = $orders->with('address')->get();
Expand All @@ -164,6 +166,10 @@ public function uploadFile(Request $request){
$user = Auth::user();
$action = $user->getAction();
$center = $action->center;
$user = Auth::user();
$action = $user->getAction();
GeoCoder::setApiKey($action['APIKey']);
GeoCoder::setCountry('CH');
foreach($importData_arr as $importData){
// return $importData;
$importData['abholung'] = $importData['abholung'] === "x" ? 1 : 0;
Expand All @@ -175,7 +181,9 @@ public function uploadFile(Request $request){
"street" => $center['street'],
"group_id"=> $user->group['id'],
"city" => $center['city'],
"plz" => $center['plz']);
"plz" => $center['plz'],
"lat" => $center['lat'],
"lng" => $center['lng']);
}
else{
$insertAddress = array(
Expand All @@ -190,38 +198,40 @@ public function uploadFile(Request $request){
$address = Address::firstOrCreate(['name' => $importData['name'], 'firstname' => $importData['vorname']], $insertAddress);

if($address){
$geocode = Geocoder::getCoordinatesForAddress($address['street'] . ', ' .$address['plz'] . ' '.$address['city']);
$lat = $geocode['lat'];
$lng = $geocode['lng'];

$address->update(['lat' => $lat, 'lng' => $lng]);

if($importData['route']){
$insertRoute = array(
"name"=> $importData['route'],
"action_id" => $user->getAction,
"route_status_id" => config('status.route_geplant'));

$route = Route::firstOrCreate(['name' => $importData['route'],], $insertRoute);
$route_id = $route['id'];
}
else
{
$route_id = null;
}

if(!$importData['abholung']){
$geocode = Geocoder::getCoordinatesForAddress($address['street'] . ', ' .$address['plz'] . ' '.$address['city']);
$lat = $geocode['lat'];
$lng = $geocode['lng'];

$address->update(['lat' => $lat, 'lng' => $lng]);
}

if($importData['route']){
$insertRoute = array(
"name"=> $importData['route'],
"action_id" => $user->getAction,
"route_status_id" => config('status.route_geplant'));

$route = Route::firstOrCreate(['name' => $importData['route'],], $insertRoute);
$route_id = $route['id'];
}
else
{
$route_id = null;
}


$insertOrder = array(

"quantity"=> $importData['anzahl'],
"route_id" => $route_id,
"action_id" => $action['id'],
"address_id"=> $address['id'],
"order_status_id" => config('status.order_offen'),
"pick_up" => $importData['abholung'],
"comments" => $importData['bemerkung']);
$insertOrder = array(
"quantity"=> $importData['anzahl'],
"route_id" => $route_id,
"action_id" => $action['id'],
"address_id"=> $address['id'],
"order_status_id" => config('status.order_offen'),
"pick_up" => $importData['abholung'],
"comments" => $importData['bemerkung']);
}
Order::firstOrCreate(['action_id' => $action['id'], 'address_id' => $address['id']], $insertOrder);
Order::firstOrCreate(['action_id' => $action['id'], 'address_id' => $address['id'], 'quantity' => $importData['anzahl'], 'comments' => $importData['bemerkung']], $insertOrder);


}
Expand Down Expand Up @@ -262,6 +272,10 @@ public function store(Request $request)
$group = Auth::user()->group;
$input['group_id'] = $group['id'];
}
$user = Auth::user();
$action = $user->getAction();
GeoCoder::setApiKey($action['APIKey']);
GeoCoder::setCountry('CH');
$geocode = Geocoder::getCoordinatesForAddress($input['street'] . ', ' .$input['plz'] . ' '.$input['city']);
$input['lat'] = $geocode['lat'];
$input['lng'] = $geocode['lng'];
Expand All @@ -276,7 +290,7 @@ public function store(Request $request)
$input['address_id'] = $address->id;
$action = Auth::user()->getAction();
$input['action_id'] = $action['id'];
$input['order_status_id'] = 5;
$input['order_status_id'] = config('status.order_offen');

Order::create($input);

Expand Down Expand Up @@ -305,7 +319,7 @@ public function edit($id)
{
//
$action = Auth::user()->getAction();
$routes = Route::where('action_id', $action['id'])->where('route_status_id',5)->get();
$routes = Route::where('action_id', $action['id'])->where('route_status_id', config('status.route_unterwegs'))->get();
$routes = $routes->pluck('name','id')->all();
$order = Order::findOrFail($id);

Expand All @@ -324,6 +338,10 @@ public function update(Request $request, $id)
//
$order = Order::findOrFail($id);
$address=$order->address;
$user = Auth::user();
$action = $user->getAction();
GeoCoder::setApiKey($action['APIKey']);
GeoCoder::setCountry('CH');
if($address){
$input = $request->all();
$geocode = Geocoder::getCoordinatesForAddress($input['street'] . ', ' .$input['plz'] . ' '.$input['city']);
Expand Down
Loading

0 comments on commit b34fbd4

Please sign in to comment.