Implemented person target creating and editing.
This commit is contained in:
@@ -3,7 +3,9 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\PersonTarget;
|
||||
use Illuminate\Http\Request;
|
||||
use App\IOType;
|
||||
use App\Person;
|
||||
use App\Http\Requests\PersonTargetCreateOrUpdate;
|
||||
|
||||
class PersonTargetsController extends Controller
|
||||
{
|
||||
@@ -36,18 +38,32 @@ class PersonTargetsController extends Controller
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
$personTarget = new PersonTarget();
|
||||
|
||||
$formArrays = PersonTargetsController::loadFormArrays();
|
||||
|
||||
return view('personTargets.create', array_merge(compact('personTarget'), $formArrays));
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Http\Requests\PersonTargetCreateOrUpdate $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
public function store(PersonTargetCreateOrUpdate $request)
|
||||
{
|
||||
//
|
||||
$personTarget = new PersonTarget();
|
||||
|
||||
$personTarget->reference = request('reference');
|
||||
$personTarget->amount = request('amount');
|
||||
$personTarget->date = request('date');
|
||||
$personTarget->io_type_id = request('io_type_id');
|
||||
$personTarget->person_id = request('person_id');
|
||||
|
||||
$personTarget->save();
|
||||
|
||||
return redirect('/targets');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,7 +85,9 @@ class PersonTargetsController extends Controller
|
||||
*/
|
||||
public function edit(PersonTarget $personTarget)
|
||||
{
|
||||
//
|
||||
$formArrays = PersonTargetsController::loadFormArrays();
|
||||
|
||||
return view('personTargets.edit', array_merge(compact('personTarget'), $formArrays));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,9 +97,18 @@ class PersonTargetsController extends Controller
|
||||
* @param \App\PersonTarget $personTarget
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, PersonTarget $personTarget)
|
||||
public function update(PersonTargetCreateOrUpdate $request,
|
||||
PersonTarget $personTarget)
|
||||
{
|
||||
//
|
||||
$personTarget->reference = request('reference');
|
||||
$personTarget->amount = request('amount');
|
||||
$personTarget->date = request('date');
|
||||
$personTarget->io_type_id = request('io_type_id');
|
||||
$personTarget->person_id = request('person_id');
|
||||
|
||||
$personTarget->save();
|
||||
|
||||
return redirect('/targets');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,4 +134,29 @@ class PersonTargetsController extends Controller
|
||||
|
||||
return redirect('/targets');
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the data about people and IO types and return them as an array, such
|
||||
* that the data can be used as input for a form dropdowndown field.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function loadFormArrays()
|
||||
{
|
||||
$ioTypes = IOType::all();
|
||||
|
||||
$ioTypesArray = [];
|
||||
foreach ($ioTypes as $ioType) {
|
||||
$ioTypesArray[$ioType->id] = $ioType->name;
|
||||
}
|
||||
|
||||
$people = Person::all('id', 'name_or_company', 'surname')->sortBy('name_or_company');
|
||||
|
||||
$peopleArray = [];
|
||||
foreach ($people as $person) {
|
||||
$peopleArray[$person->id] = $person->fullName(true);
|
||||
}
|
||||
|
||||
return compact('ioTypesArray', 'peopleArray');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class PersonTargetCreateOrUpdate extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'date' => 'required',
|
||||
'reference' => 'required',
|
||||
'amount' => 'required|numeric|min:0',
|
||||
'io_type_id' => 'required',
|
||||
'person_id' => 'required'
|
||||
];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'date.required' =>
|
||||
'Die Zahlungsverpflichtung muss ein Datum haben.',
|
||||
|
||||
'reference.required' =>
|
||||
'Die Zahlungsverpflichtung muss eine Position haben.',
|
||||
|
||||
'amount.required' =>
|
||||
'Die Zahlungsverpflichtung muss einen Betrag haben.',
|
||||
'amount.numeric' =>
|
||||
'Der Betrag muss eine Zahl sein.',
|
||||
'amount.min' =>
|
||||
'Der Betrag darf kein Vorzeichen haben. Das Vorzeichen der
|
||||
Zahlungsverpflichtung wird durch den Typ bestimmt.',
|
||||
|
||||
'io_type_id.required' =>
|
||||
'Die Zahlungsverpflichtung muss einen Typ haben.',
|
||||
|
||||
'person_id.required' =>
|
||||
'Die Zahlungsverpflichtung muss einer Person zugeordnet werden.'
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
@extends('layout.master')
|
||||
|
||||
@section('subnav')
|
||||
<li class='nav-item'>
|
||||
<a href='{{ url()->previous() }}' class='btn btn-outline-primary'>Zurück</a>
|
||||
</li>
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
<h1>@yield('title')</h1>
|
||||
<form action="/targets/@if (!is_null($personTarget->id)) {{ $personTarget->id }} @endif" method='post'>
|
||||
@if (!is_null($personTarget->id))
|
||||
{{ method_field('patch') }}
|
||||
@endif
|
||||
{{ csrf_field() }}
|
||||
<div class='form-group row'>
|
||||
{{ Form::label('date', 'Datum', ['class' => 'col-sm-2 col-form-label']) }}
|
||||
<div class='col-sm-10'>
|
||||
{{ Form::date('date', $personTarget->date, ['class' => 'form-control']) }}
|
||||
</div>
|
||||
</div>
|
||||
<div class='form-group row'>
|
||||
{{ Form::label('reference', 'Position', ['class' => 'col-sm-2 col-form-label']) }}
|
||||
<div class='col-sm-10'>
|
||||
{{ Form::text('reference', $personTarget->reference, ['class' => 'form-control']) }}
|
||||
</div>
|
||||
</div>
|
||||
<div class='form-group row'>
|
||||
{{ Form::label('amount', 'Betrag', ['class' => 'col-sm-2 col-form-label']) }}
|
||||
<div class='col-sm-10'>
|
||||
{{ Form::text('amount', $personTarget->amount, ['class' => 'form-control']) }}
|
||||
</div>
|
||||
</div>
|
||||
<div class='form-group row'>
|
||||
{{ Form::label('io_type_id', 'Typ', ['class' => 'col-sm-2 col-form-label']) }}
|
||||
<div class='col-sm-10'>
|
||||
{{
|
||||
Form::select(
|
||||
'io_type_id',
|
||||
$ioTypesArray,
|
||||
$personTarget->io_type_id,
|
||||
[
|
||||
'placeholder' => 'Hier auswählen ...',
|
||||
'class' => 'form-control'
|
||||
]
|
||||
)
|
||||
}}
|
||||
</div>
|
||||
</div>
|
||||
<div class='form-group row'>
|
||||
{{ Form::label('person_id', 'Person / Firma', ['class' => 'col-sm-2 col-form-label']) }}
|
||||
<div class='col-sm-10'>
|
||||
{{
|
||||
Form::select(
|
||||
'person_id',
|
||||
$peopleArray,
|
||||
$personTarget->person_id,
|
||||
[
|
||||
'placeholder' => 'Hier auswählen ...',
|
||||
'class' => 'form-control'
|
||||
]
|
||||
)
|
||||
}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ul>
|
||||
@foreach ($errors->all() as $error)
|
||||
<li>{{ $error }}</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
|
||||
<div class="form-group row">
|
||||
<div class="col-sm-10">
|
||||
<button class="btn btn-primary" type="submit" id="submit">Speichern</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
@endsection
|
||||
@@ -0,0 +1,4 @@
|
||||
@extends('layout.forms.personTarget')
|
||||
|
||||
@section('title', 'Neue Zahlungsverpflichtung')
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
@extends('layout.forms.personTarget')
|
||||
|
||||
@section('title', 'Zahlungsverpflichtung bearbeiten')
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
<td>{!! formatAmount($personTarget->difference()) !!}</td>
|
||||
<td>
|
||||
<div class="btn-group" role="group" aria-label="Basic example">
|
||||
<a href='/targets/{{ $personTarget->id }}' class="btn btn-primary"><i class="fas fa-eye"></i></a>
|
||||
<a href='/targets/{{ $personTarget->id }}/edit' class="btn btn-success"><i class="fas fa-edit"></i></a>
|
||||
<a href='/targets/{{ $personTarget->id }}/delete' class="btn btn-danger"><i class="fas fa-trash"></i></a>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user