Skip to content

Commit

Permalink
provide history of services #112
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil committed Dec 12, 2022
1 parent 3fabe05 commit c24ebeb
Show file tree
Hide file tree
Showing 7 changed files with 307 additions and 1 deletion.
59 changes: 59 additions & 0 deletions app/Http/Controllers/ServiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -381,4 +381,63 @@ public function delete($id)

return $this->destroy($id);
}

/**
* Display a listing of services from the past.
*
* @return \Illuminate\Http\Response
*/
public function history()
{
if(!Auth::user()->isAdmin()) {
abort(402, "Nope.");
}

$services = Service::whereDate('date', '<=', Carbon::now())->where('client_id', '=', Auth::user()->currentclient_id)
->orderBy('date', 'desc')->with('openpositions')
->with('positions.qualification')
->with('positions.user')
->paginate(30);

$user = User::where(['id' => Auth::user()->id])->with('qualifications')->first();
$isAdmin = $user->isAdmin();
$servicesHoliday = $user->services_inHolidayList();

return view('service.history', compact('services', 'user', 'servicesHoliday', 'isAdmin'));
}

/**
* Finalize a service.
*
* @return
*/
public function finalize($id)
{
//only allowed if user is admin
if(!Auth::user()->isAdmin() || Service::where(['id' => $id, 'client_id' => Auth::user()->currentclient_id])->count() <= 0) {
abort(402, "Nope.");
}

$service = Service::findOrFail($id);

//if Service dateEnd do NOT exsist and date is today or in history
//OR dateEnd exsist and is today or in history
if(
(empty($service->dateEnd) && Carbon::now()->endOfDay()->gte($service->date))
||
(!empty($service->dateEnd) && Carbon::now()->endOfDay()->gte($service->dateEnd))
)
{
$service->finalized_at = Carbon::now();
$service->finalized_by = Auth::user()->id;
$service->save();
Session::flash('successmessage', 'Dienst erfolgreich abgeschlossen');
}
else
{
Session::flash('errormessage', 'Dienste aus der Zukunf können nicht abgeschlossen werden.');
}

return redirect()->back();
}
}
2 changes: 1 addition & 1 deletion app/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Service extends Model
];

protected $dates = [
'date', 'dateEnd',
'date', 'dateEnd', 'finalized_at'
];

protected $attributes = array(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('services', function (Blueprint $table) {
$table->dateTime('finalized_at')->nullable();

$table->integer('finalized_by')->unsigned()->nullable();
$table->foreign('finalized_by')->references('id')->on('users')->onDelete('cascade');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('services', function (Blueprint $table) {
$table->dropColumn('finalized_at');
$table->dropColumn('finalized_by');
});
}
};
8 changes: 8 additions & 0 deletions resources/views/_layouts/menu.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@
<span>Dienste</span>
</a>
</li>
@can('administration')
<li class="{{active('service.history')}}">
<a href="{{ action('ServiceController@history') }}">
<i class="material-icons">assignment</i>
<span>Dienst Historie</span>
</a>
</li>
@endcan
@if(\Illuminate\Support\Facades\Auth::user()->currentclient()->module_training)
<li class="{{active('training.index')}}">
<a href="{{ action('TrainingController@index') }}">
Expand Down
193 changes: 193 additions & 0 deletions resources/views/service/history.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
@extends('_layouts.application')

@section('head')
@endsection

@section('content')
<h1>Dienst Historie</h1>
{{-- Pagination --}}
<div class="d-felx justify-content-center">
{{ $services->links() }}
</div>

@foreach($services as $service)
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<span class="anchor" id="service{{$service->id}}"></span>
<div class="card">
<div class="header @if(!empty($service->finalized_at)) bg-green @else bg-red @endif">
<h2 data-toggle="collapse" data-target="#card_{{$service->id}}">
<span class="glyphicon glyphicon-collapse-down float-left"></span>

{{$service->date->isoFormat('ddd DD.MM.YY H:mm')}} Uhr @if(!empty($service->dateEnd)) - {{$service->dateEnd->isoFormat('DD.MM.YY H:mm')}} Uhr @endif
<small>{{$service->comment}}</small>
@if(!empty($service->location)) <small>{{$service->location}}</small> @endif
</h2>

<ul class="header-dropdown m-r--5">

@if($isAdmin)
<li class="dropdown">
<a href="javascript:void(0);" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
<i class="material-icons">more_vert</i>
</a>
<ul class="dropdown-menu pull-right">
<li><a href="{{action('ServiceController@edit', $service->id) }}" class="waves-effect waves-block bg-orange"><i class="material-icons">mode_edit</i>Bearbeiten</a></li>
<li><a href="{{action('ServiceController@finalize', $service->id) }}" class="waves-effect waves-block bg-green"><i class="material-icons">done</i>Abschließen</a></li>
</ul>
</li>
@endif
</ul>

</div>
<div class="body collapse @if(Browser::isDesktop() && !in_array($service->id, $servicesHoliday)) in @endif" id="card_{{$service->id}}">

@if(Browser::isDesktop())
{{-- Start Desktop --}}
<div class="table-responsive table-bordered">
<table class="table">
<tr>
@foreach($service->positions as $position)
<th @if($position->requiredposition) class="font-underline"@endif>{{$position->qualification->name}}</th>
@endforeach
</tr>
<tr>

@foreach($service->positions as $position)
<td>
{{-- show candidates if nobody is approved --}}
@if(!isset($position->user))
@if($isAdmin)
@foreach($position->candidatures as $candidate)
<row>
<div class="col-md-12">
<span class="badge bg-orange">
{{substr ($candidate->user->first_name, 0, 1)}}. {{$candidate->user->name}}
<button type="button" class="btn btn-xs bg-green btn-authorize" positionid="{{$position->id}}" candidateid="{{$candidate->id}}"><i class="material-icons">check</i></button>
</span>
</div>
</row>
@endforeach
@endif
@endif
@if(isset($position->user))
<span class="badge @if($position->user->id == $user->id) bg-light-green @else bg-green @endif">
{{substr ($position->user->first_name, 0, 1)}}. {{$position->user->name}}
</span>
@endif
@if($position->comment)
<br>
<smal>({{$position->comment}})</smal>
@endif
</td>
@endforeach
</tr>
</table>
</div>
{{-- End Desktop--}}
@else
{{-- Start Mobile--}}
<div class="row display-flex container-fluid">

@foreach($service->positions as $position)
<div class="col-xs-12 col-sm-4 col-md-3 col-lg-2">
<div class="panel panel-default">

<b @if($position->requiredposition) class="font-underline"@endif>{{$position->qualification->name}}:</b>
<div class="panel-body">

{{-- show candidates if nobody is approved --}}
@if(!isset($position->user))
@if($isAdmin)
@foreach($position->candidatures as $candidate)
<row>
<div class="col-md-12">
<span class="badge bg-orange">
{{substr ($candidate->user->first_name, 0, 1)}}. {{$candidate->user->name}}
<button type="button" class="btn btn-xs bg-green btn-authorize" positionid="{{$position->id}}" candidateid="{{$candidate->id}}"><i class="material-icons">check</i></button>
</span>
</div>
</row>
@endforeach
@endif
@endif
@if(isset($position->user))
<span class="badge @if($position->user->id == $user->id) bg-light-green @else bg-green @endif">
{{substr ($position->user->first_name, 0, 1)}}. {{$position->user->name}}
</span>
@endif
@if($position->comment)
<br>
<smal>({{$position->comment}})</smal>
@endif
</div>
</div>
</div>

@endforeach

</div>
{{-- end mobile --}}
@endif
</div>
</div>
</div>
@endforeach

{{-- Pagination --}}
<div class="d-felx justify-content-center">
{{ $services->links() }}
</div>

@endsection

@section('post_body')
<script>
$( document ).ready(function() {
@if($isAdmin)
$('.btn-authorize').on('click', function () {
$(this).parent().attr("positionid", $(this).attr('positionid'));
$(this).remove();
$.ajax({
type: "POST",
url: '/position/'+$(this).attr('candidateid')+'/authorize',
headers: {
'X-CSRF-TOKEN': '{{ csrf_token() }}'
},
success : function(data){
if (data == "false") {
showNotification("alert-warning", "Fehler beim freigeben", "top", "center", "", "");
$("span[positionid="+data.id+"]").removeAttr('positionid')
} else {
showNotification("alert-success", "Zuordnung freigegeben", "top", "center", "", "");
//remove unsubscripe btn (if admin is a candidate)
$(".btn-unsubscribe[positionid="+data.id+"]").remove();
//remove all authorize
$($(".btn-authorize[positionid="+data.id+"]").closest('row')).remove();
//remove all btn-subscribe
$(".btn-subscribe[positionid="+data.id+"]").remove();
//set authorized green
if(data.user_id == {{\Illuminate\Support\Facades\Auth::user()->id}}) {
$("span[positionid="+data.id+"]").removeClass('bg-orange').addClass('bg-light-green');
} else {
$("span[positionid="+data.id+"]").removeClass('bg-orange').addClass('bg-green');
}
}
}
});
});
@endif
});
$('.collapse').on('shown.bs.collapse', function(){
$(this).parent().find(".glyphicon-collapse-down").removeClass("glyphicon-collapse-down").addClass("glyphicon-collapse-up");
}).on('hidden.bs.collapse', function(){
$(this).parent().find(".glyphicon-collapse-up").removeClass("glyphicon-collapse-up").addClass("glyphicon-collapse-down");
});
</script>
@endsection
2 changes: 2 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@

Route::resource('service', 'ServiceController');
Route::get('service/{service}/delete', 'ServiceController@delete')->name('service.delete');
Route::get('servicehistory', 'ServiceController@history')->name('service.history');
Route::get('service/finalize/{service}', 'ServiceController@finalize')->name('service.finalize');

Route::resource('training', 'TrainingController');
Route::get('training/{training}/delete', 'TrainingController@destroy')->name('training.delete');
Expand Down
8 changes: 8 additions & 0 deletions tests/Feature/RouteCredentialsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ public function test_AllRoutesNoAuthAvailable()

//service (resource)
$this->followingRedirects()->get('/service')->assertStatus(200)->assertViewIs('auth.login');
$this->followingRedirects()->get('/servicehistory')->assertStatus(200)->assertViewIs('auth.login');
$this->followingRedirects()->get('/service/finalize/1')->assertStatus(200)->assertViewIs('auth.login');

$this->post('/service', $session)->assertStatus(419);
$this->followingRedirects()->get('/service/1')->assertStatus(200)->assertViewIs('auth.login');
$this->put('/service/1', $session)->assertStatus(419);
Expand Down Expand Up @@ -661,6 +664,11 @@ public function test_AllRoutesAsUserAvailable()
->assertStatus(200)->assertViewIs('service.index')
->assertSee('Impressum')->assertSee('Datenschutz');

//GET|HEAD
$this->actingAs($user)->get('/servicehistory')->assertStatus(403); //only as admin
//GET|HEAD
$this->actingAs($user)->get('/service/finalize/1')->assertStatus(403); //only as admin

//POST | service
$this->actingAs($user)->post('/service', ['_token' => $token])->assertStatus(403); //only as admin

Expand Down

0 comments on commit c24ebeb

Please sign in to comment.