From cc95c4b595e8c5e34bd9a113db3bf81d28b916c7 Mon Sep 17 00:00:00 2001 From: Lukas Halbritter Date: Fri, 28 Sep 2018 22:47:35 +0200 Subject: [PATCH] Added bookings controller and index view. --- app/Http/Controllers/BookingsController.php | 131 +++++++++++++++++++ resources/views/bookings/index.blade.php | 136 ++++++++++++++++++++ 2 files changed, 267 insertions(+) create mode 100644 app/Http/Controllers/BookingsController.php create mode 100644 resources/views/bookings/index.blade.php diff --git a/app/Http/Controllers/BookingsController.php b/app/Http/Controllers/BookingsController.php new file mode 100644 index 0000000..74fd685 --- /dev/null +++ b/app/Http/Controllers/BookingsController.php @@ -0,0 +1,131 @@ +orderBy('date') + ->withCount('subBookings') + ->get() + ->groupBy(function($item) { + return Carbon::parse($item->date)->format('n'); + }); + + $sums = array(); + + $startBalance = SubBooking::balanceAt($year - 1 . '-12-31'); + $sums[0]['balance'] = $startBalance; + + $expeditures = SubBooking::expedituresInInterval( + $year . '-01-01', $year . '-12-31', true); + + $incomes = SubBooking::incomesInInterval( + $year . '-01-01', $year . '-12-31', true); + + // Create an array with the following properties: + // 'balance' - The account balance at the last day of a month + // 'expeditures' - the sum of all expeditures in this month + // 'incomes' - the sum of all incomes in this month plus the account + // balance of the previous month + for ($month = 1; $month <= 12; $month++) { + $sums[$month]['expeditures'] = $expeditures->where('month', '=', $month)->first()->expeditures; + $sums[$month]['incomes'] = $expeditures->where('month', '<', $month)->sum('expeditures') + + $incomes->where('month', '<=', $month)->sum('incomes') + + $startBalance; + $sums[$month]['balance'] = $sums[$month]['expeditures'] + + $sums[$month]['incomes']; + } + + return view('bookings.index', compact('bookings', 'year', 'sums')); + } + + /** + * Show the form for creating a new resource. + * + * @return \Illuminate\Http\Response + */ + public function create() + { + // + } + + /** + * Store a newly created resource in storage. + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Http\Response + */ + public function store(Request $request) + { + // + } + + /** + * 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) + { + // + } +} diff --git a/resources/views/bookings/index.blade.php b/resources/views/bookings/index.blade.php new file mode 100644 index 0000000..8d4c7e6 --- /dev/null +++ b/resources/views/bookings/index.blade.php @@ -0,0 +1,136 @@ +@extends('layout.master') + +@section('title', 'Kassenbuch') + +@section('subnav') + +@endsection + +@section('content') +

+ {{ $year - 1 }} + 1. Januar {{ $year }} - 31. Dezember {{ $year }} + {{ $year + 1 }} +

+ + + + + + + + + + + + + @for ($month = 1; $month <= 12; $month++) + @if (isset($bookings[$month])) + + + + + + + + + + + + @foreach($bookings[$month] as $booking) + + + + + + + + + + + + @if (!$booking->isSimple()) + @foreach ($booking->subBookings()->withSignedAmount()->get() as $subBooking) + + + + + + + + + + + + @endforeach + @endif + @endforeach + + + + + + + + + + + + + + + + + + + + + + + + @for ($i = 0; $i < 9; $i++) + + @endfor + + @endif + @endfor +
IDDatumPositionenPerson / FirmaAusgang (S)Eingang (H)KontoProjekt
{{ $year . '-' . sprintf('%02d', $month) . '-01'}}Saldo{{ formatAmount($sums[$month - 1]['balance']) }}
+ @if (!$booking->isSimple()) + v + @endif + {{ $booking->id }}{{ $booking->date }}{{ $booking->reference }}{{ $booking->person_or_company }} + @if ($booking->signedAmount() < 0) + {{ formatAmount($booking->signedAmount()) }} + @endif + + @if ($booking->signedAmount() >= 0) + {{ formatAmount($booking->signedAmount()) }} + @endif + + @if ($booking->isSimple()) + {{ $booking->accountType->name }} + @endif + + @if ($booking->isSimple()) + {{ $booking->project->name }} + @endif +
+{{ $subBooking->reference }} + @if ($subBooking->signedAmount < 0) + {{ formatAmount($subBooking->signedAmount) }} + @endif + + @if ($subBooking->signedAmount >= 0) + {{ formatAmount($subBooking->signedAmount) }} + @endif + + {{ $subBooking->accountType->name }} + + {{ $subBooking->project->name }} +
+ {{ $year . '-' . sprintf('%02d', $month) . '-' . + cal_days_in_month(CAL_GREGORIAN, $month, $year) }} + Monatsabschluss{{ formatAmount($sums[$month]['expeditures']) }}{{ formatAmount($sums[$month]['incomes']) }}
+ {{ $year . '-' . sprintf('%02d', $month) . '-' . + cal_days_in_month(CAL_GREGORIAN, $month, $year) }} + Saldo{{ formatAmount($sums[$month]['balance']) }}
 
+@endsection