Skip to content

Commit

Permalink
Merge pull request #29 from SolidCharity/TP-202006-delete-service
Browse files Browse the repository at this point in the history
delete all participants when deleting the service.
delete all participants of only one specific service.
display report for only one specific service.
fixes #28
  • Loading branch information
tpokorra authored Jun 3, 2020
2 parents 1e77228 + d303570 commit 4ecadb2
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 12 deletions.
29 changes: 24 additions & 5 deletions app/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
8 changes: 6 additions & 2 deletions app/Http/Controllers/ServiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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::
Expand Down
1 change: 1 addition & 0 deletions resources/lang/de/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions resources/lang/en/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
17 changes: 15 additions & 2 deletions resources/views/admin.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,31 @@
</div>
</div>
</div>
</div>

<div class="btn-group">
<form method="post" action="{{ route('dropAllParticipants', $service->id) }}">
@method('DELETE')
@csrf
<button type="submit" class="btn btn-danger" onclick="return confirm('@lang('messages.confirm_delete')')">@lang('messages.delete_all_participants')</button>
</form>

<a href="/report/{{$service->id}}" target="_blank"><button class="btn btn-primary">@lang('messages.print_report')</button></a>
</div>
</div>
@endforeach

<br/>
@lang('messages.for_all_services'):
<div class="btn-group">
<form method="post" action="{{ route('dropAllParticipants') }}">
@method('DELETE')
@csrf
<button type="submit" class="btn btn-danger" onclick="return confirm('@lang('messages.confirm_delete')')">@lang('messages.delete_all_participants')</button>
</form>

<a href="/report" target="_blank"><button class="btn btn-primary">@lang('messages.print_report')</button></a>
</div>
</div>
</div>
</div>
<div class="card">
<div class="card-header">@lang('messages.settings')</div>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/report.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<div class="row">
<div class="col-md-4"></div>
<div class="col-md-4">
@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])
</div>
</div>
</div>
Expand Down
12 changes: 10 additions & 2 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Illuminate\Support\Facades\Route;
use Illuminate\Http\Request;
use App\Http\Controllers\AdminController;

/*
|--------------------------------------------------------------------------
Expand All @@ -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');

Expand All @@ -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');

0 comments on commit 4ecadb2

Please sign in to comment.