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 @@ - +
+
+ @method('DELETE') + @csrf + +
+ + +
+ @endforeach +
+@lang('messages.for_all_services'): +
@method('DELETE') @csrf @@ -69,7 +81,8 @@
-
+ +
@lang('messages.settings')
diff --git a/resources/views/report.blade.php b/resources/views/report.blade.php index 6f9e96a..e82e945 100644 --- a/resources/views/report.blade.php +++ b/resources/views/report.blade.php @@ -29,7 +29,7 @@
- @lang('messages.currently_visitors', ['value' => $service->count_adults + $service->count_children]) + @lang('messages.currently_visitors', ['value' => $service->count_adults + $service->count_children, 'max' => $service->max_visitors])
diff --git a/routes/web.php b/routes/web.php index 74124e7..a1e7dde 100644 --- a/routes/web.php +++ b/routes/web.php @@ -2,6 +2,7 @@ use Illuminate\Support\Facades\Route; use Illuminate\Http\Request; +use App\Http\Controllers\AdminController; /* |-------------------------------------------------------------------------- @@ -19,7 +20,15 @@ Route::apiResource('services', 'ServiceController'); Route::apiResource('participants', 'ParticipantController'); -Route::delete('participants', 'AdminController@dropAllParticipants')->name('dropAllParticipants'); +Route::delete('participants1/{service_id?}', + function ($service_id = null) { + return AdminController::dropAllParticipants($service_id); + })->name('dropAllParticipants'); +Route::get('/report/{service_id?}', + function ($service_id=null) { + return AdminController::report($service_id); + })->name('report'); + Route::patch('tenants', 'AdminController@updateChurchName')->name('updateChurchName'); Route::delete('participants2', 'FrontendController@cancelregistration')->name('cancelregistration'); @@ -39,4 +48,3 @@ Route::get('/', 'FrontendController@index')->name('frontend'); Route::get('/home', 'AdminController@index')->name('home'); Route::get('/admin', 'AdminController@index')->name('admin'); -Route::get('/report', 'AdminController@report')->name('report');