Transferred the loading of the arrays for the booking forms into a own separate

method.
Impemented the booking.edit view and controller method.
This commit is contained in:
Lukas Halbritter
2018-10-04 22:59:41 +02:00
parent e5386fe7e7
commit 20859fe4a9
+120 -96
View File
@@ -20,18 +20,14 @@ class BookingsController extends Controller
*/ */
public function index($year) public function index($year)
{ {
$bookings = Booking::with( $bookings = Booking::with('subBookings.accountType.accountClass.ioType',
'subBookings.accountType.accountClass.ioType', 'subBookings.project')
'subBookings.project'
)
->whereYear('date', '=', $year) ->whereYear('date', '=', $year)
->orderBy('date') ->orderBy('date')
->get() ->get()
->groupBy( ->groupBy( function ($item) {
function ($item) { return Carbon::parse($item->date)->format('n');
return Carbon::parse($item->date)->format('n'); });
}
);
$sums = array(); $sums = array();
@@ -65,6 +61,120 @@ class BookingsController extends Controller
* @return \Illuminate\Http\Response * @return \Illuminate\Http\Response
*/ */
public function create() public function create()
{
return view('bookings.create', BookingsController::loadFormArrays());
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$booking = new Booking;
$booking->date = request('date');
$booking->reference = request('reference');
$booking->person_or_company = request('person_or_company');
$booking->note = request('note');
$booking->save();
$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');
$booking->subBookings()->save($subBooking);
return redirect('/bookings/year-' . Carbon::parse(request('date'))->format('Y'));
}
/**
* Display the specified resource.
*
* @param \App\Booking $booking
* @return \Illuminate\Http\Response
*/
public function show(Booking $booking)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Booking $booking
* @return \Illuminate\Http\Response
*/
public function edit(Booking $booking)
{
$booking->load('subBookings',
'subBookings.personTarget:id,reference,person_id',
'subBookings.personTarget.person:id,name_or_company,surname');
$formArrays = BookingsController::loadFormArrays();
// Add the person targets of the booking to the personTargetsArray,
// since it is possible that the person target of the sub-booking is no
// longer open and therefor not loaded into the list of open targets.
foreach ($booking->subBookings as $subBooking) {
$personTarget = $subBooking->personTarget;
$person = $personTarget->person;
$formArrays['openTargetsArray'][$person->fullName(true)][$personTarget->id]
= $personTarget->reference;
}
return view('bookings.edit', array_merge(compact('booking'), $formArrays));
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Booking $booking
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Booking $booking)
{
return redirect('/bookings/year-' . Carbon::parse(request('date'))->format('Y'));
}
/**
* Show the dialog for deleting the specified resource.
*
* @param \App\Booking $booking
* @return \Illuminate\Http\Response
*/
public function delete(Booking $booking)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param \App\Booking $booking
* @return \Illuminate\Http\Response
*/
public function destroy(Booking $booking)
{
//
}
/**
* Load the data about person targets, projects and account types from the
* database to show tis data in a form as dropdown menu.
*
* @return array
*/
private function loadFormArrays()
{ {
// Get all open targets from the database ... // Get all open targets from the database ...
$openTargets = PersonTarget::open() $openTargets = PersonTarget::open()
@@ -135,92 +245,6 @@ class BookingsController extends Controller
[$accountType->id] = $accountType->numberAndName(); [$accountType->id] = $accountType->numberAndName();
} }
return view('bookings.create', compact('projectsArray', 'openTargetsArray', 'accountTypeArray')); return compact('openTargetsArray', 'projectsArray', 'accountTypeArray');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$booking = new Booking;
$booking->date = request('date');
$booking->reference = request('reference');
$booking->person_or_company = request('person_or_company');
$booking->note = request('note');
$booking->save();
$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');
$booking->subBookings()->save($subBooking);
return redirect('/bookings/year-' . Carbon::parse(request('date'))->format('Y'));
}
/**
* Display the specified resource.
*
* @param \App\Booking $booking
* @return \Illuminate\Http\Response
*/
public function show(Booking $booking)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Booking $booking
* @return \Illuminate\Http\Response
*/
public function edit(Booking $booking)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Booking $booking
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Booking $booking)
{
//
}
/**
* Show the dialog for deleting the specified resource.
*
* @param \App\Booking $booking
* @return \Illuminate\Http\Response
*/
public function delete(Booking $booking)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param \App\Booking $booking
* @return \Illuminate\Http\Response
*/
public function destroy(Booking $booking)
{
//
} }
} }