Added option to create a new person target together with a new booking
This commit is contained in:
@@ -7,6 +7,8 @@ use App\SubBooking;
|
||||
use App\PersonTarget;
|
||||
use App\Project;
|
||||
use App\AccountType;
|
||||
use App\Person;
|
||||
|
||||
use App\Http\Requests\StoreBooking;
|
||||
use App\Http\Requests\UpdateBooking;
|
||||
|
||||
@@ -69,7 +71,18 @@ class BookingsController extends Controller
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('bookings.create', BookingsController::loadFormArrays());
|
||||
$formArrays = BookingsController::loadFormArrays();
|
||||
|
||||
$persons = Person::select('id', 'name_or_company', 'surname')
|
||||
->orderBy('name_or_company')->get();
|
||||
|
||||
$personsArray = [];
|
||||
|
||||
foreach ($persons as $person) {
|
||||
$personsArray[$person->id] = $person->fullName(true);
|
||||
}
|
||||
|
||||
return view('bookings.create', array_merge(compact('personsArray'), $formArrays));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,6 +93,7 @@ class BookingsController extends Controller
|
||||
*/
|
||||
public function store(StoreBooking $request)
|
||||
{
|
||||
// Booking
|
||||
$booking = new Booking;
|
||||
|
||||
$booking->date = request('date');
|
||||
@@ -89,14 +103,32 @@ class BookingsController extends Controller
|
||||
|
||||
$booking->save();
|
||||
|
||||
// SubBooking
|
||||
$subBooking = new SubBooking;
|
||||
|
||||
$subBooking->reference = request('reference');
|
||||
$subBooking->amount = swapComma(request('amount'));
|
||||
$subBooking->account_type_id = request('account_type_id');
|
||||
$subBooking->person_target_id = request('person_target_id');
|
||||
$subBooking->project_id = request('project_id');
|
||||
|
||||
if (is_null(request('personTarget'))) {
|
||||
$subBooking->person_target_id = request('person_target_id');
|
||||
} else {
|
||||
$personTarget = new personTarget();
|
||||
|
||||
$personTarget->io_type_id = $subBooking->ioType()->id;
|
||||
$personTarget->amount = request('amount');
|
||||
$personTarget->reference = request('reference');
|
||||
$personTarget->person_id = request('personTarget')['person_id'];
|
||||
$personTarget->date = is_null(request('personTarget')['date']) ?
|
||||
request('date') :
|
||||
request('personTarget')['date'];
|
||||
|
||||
$personTarget->save();
|
||||
|
||||
$subBooking->person_target_id = $personTarget->id;
|
||||
}
|
||||
|
||||
$booking->subBookings()->save($subBooking);
|
||||
|
||||
return redirect('/bookings/year-' . Carbon::parse(request('date'))->format('Y'));
|
||||
|
||||
@@ -29,6 +29,13 @@ class StoreBooking extends FormRequest
|
||||
'person_or_company' => 'required',
|
||||
'amount' => 'sometimes|required|numeric|min:0',
|
||||
'account_type_id' => 'required',
|
||||
'person_target_id' => 'empty_if:personTarget.person_id'
|
||||
. '|empty_if:personTarget.date',
|
||||
'personTarget.person_id' => 'empty_if:person_target_id'
|
||||
. '|required_with:personTarget.date',
|
||||
'personTarget.date' => 'sometimes'
|
||||
. '|empty_if:person_target_id'
|
||||
. '|before_or_equal:date'
|
||||
];
|
||||
}
|
||||
|
||||
@@ -53,7 +60,22 @@ class StoreBooking extends FormRequest
|
||||
Buchung wird durch das zugeordnete Konto bestimmt.',
|
||||
|
||||
'account_type_id.required' =>
|
||||
'Der Buchung muss ein Konto zugewiesen werden.'
|
||||
'Der Buchung muss ein Konto zugewiesen werden.',
|
||||
|
||||
'person_target_id.empty_if' =>
|
||||
'Wenn ein Personenkonto angewählt ist kann keine neue '
|
||||
. 'Soll-Buchung angelegt werden.',
|
||||
'personTarget.person_id.empty_if' =>
|
||||
'Wenn eine neue Soll-Buchung angelegt werden soll kann kein '
|
||||
. 'Personenkonto gewählt werden.',
|
||||
'personTarget.person_id.required_with' =>
|
||||
'Die neue Soll-Buchung muss einer Person zugeordnet werden.',
|
||||
'personTarget.date.empty_if' =>
|
||||
'Wenn eine neue Soll-Buchung angelegt werden soll kann kein '
|
||||
. 'Personenkonto gewählt werden.',
|
||||
'personTarget.date.before_or_equal' =>
|
||||
'Das Datum der neuen Soll-Buchung muss vor dem Datum der '
|
||||
. 'Buchung liegen.'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,24 @@
|
||||
<td>{{ Form::select('person_target_id', $openTargetsArray, 'placeholder',
|
||||
['placeholder' => 'Hier auswählen ...']) }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><b>oder:</b></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ Form::label('personTarget[person_id]', 'neue Soll-Buchung') }}</td>
|
||||
<td>
|
||||
{{
|
||||
Form::select(
|
||||
'personTarget[person_id]',
|
||||
$personsArray,
|
||||
'placeholder',
|
||||
['placeholder' => 'Hier auswählen ...']
|
||||
)
|
||||
}}
|
||||
{{ Form::date('personTarget[date]') }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ Form::label('project_id', 'Projekt') }}</td>
|
||||
<td>{{ Form::select('project_id', $projectsArray, 'placeholder',
|
||||
|
||||
Reference in New Issue
Block a user