diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index 8670d12..32584df 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -45,21 +45,40 @@ public function index(Request $request) } /// print a report with the visitors for each service - public function report() + static public function report($service_id) { + if (empty(Auth::user())) { + return redirect('/login'); + } + $tenant_id = Auth::user()->tenant_id; - $services = \App\Service::where('tenant_id', $tenant_id)->get(); - $participants = \App\Participant::where('tenant_id', $tenant_id)->get(); + + if (empty($service_id)) { + $participants = \App\Participant::where('tenant_id', $tenant_id)->get(); + $services = \App\Service::where('tenant_id', $tenant_id)->get(); + } else { + $participants = \App\Participant::where([['tenant_id', $tenant_id],['service_id',$service_id]])->get(); + $services = \App\Service::where([['tenant_id', $tenant_id],['id',$service_id]])->get(); + } return view('report', ['services' => $services, 'participants' => $participants]); } /// drop all participants, as preparation for next week's Sunday! - public function dropAllParticipants() + static public function dropAllParticipants($service_id) { + if (empty(Auth::user())) { + return redirect('/login'); + } + $tenant_id = Auth::user()->tenant_id; - $participants = \App\Participant::where('tenant_id', $tenant_id)->get(); + + if (empty($service_id)) { + $participants = \App\Participant::where('tenant_id', $tenant_id)->get(); + } else { + $participants = \App\Participant::where([['tenant_id', $tenant_id],['service_id',$service_id]])->get(); + } foreach ($participants as $participant) { diff --git a/app/Http/Controllers/ServiceController.php b/app/Http/Controllers/ServiceController.php index 4539829..b8f4986 100644 --- a/app/Http/Controllers/ServiceController.php +++ b/app/Http/Controllers/ServiceController.php @@ -117,9 +117,13 @@ public function destroy($id) ->where([['tenant_id', $tenant_id], ['service_id', $id]]) ->sum('count_adults'); + if ($count > 0) { - return redirect('/admin') - ->withAlert(__('messages.error_service_delete_failed')); + $participants = \App\Participant::where([['tenant_id', $tenant_id],['service_id', $id]])->get(); + foreach ($participants as $participant) + { + $participant->delete(); + } } $service = \App\Service:: diff --git a/resources/lang/de/messages.php b/resources/lang/de/messages.php index 508de0c..d299aeb 100644 --- a/resources/lang/de/messages.php +++ b/resources/lang/de/messages.php @@ -17,6 +17,7 @@ 'addservice' => 'Weiterer Gottesdienst', 'delete' => 'Löschen', 'delete_all_participants' => 'Alle Besucher löschen', + 'for_all_services' => 'Für alle Gottesdienste', 'confirm_delete' => 'Wollen Sie wirklich löschen?', 'save' => 'Ändern', 'error_service_delete_failed' => 'Gottesdienst kann nicht gelöscht werden, weil es noch Besucher gibt', diff --git a/resources/lang/en/messages.php b/resources/lang/en/messages.php index 1676950..dc15f76 100644 --- a/resources/lang/en/messages.php +++ b/resources/lang/en/messages.php @@ -17,6 +17,7 @@ 'addservice' => 'Add Service', 'delete' => 'Delete', 'delete_all_participants' => 'Delete all participants', + 'for_all_services' => 'For all services', 'confirm_delete' => 'Do you really want to delete?', 'save' => 'Save', 'error_service_delete_failed' => 'Service cannot be deleted because there are still visitors assigned', diff --git a/resources/views/admin.blade.php b/resources/views/admin.blade.php index 5da6201..46ca881 100644 --- a/resources/views/admin.blade.php +++ b/resources/views/admin.blade.php @@ -58,10 +58,22 @@ - +
+ @endforeach +