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') +
| + | ID | +Datum | +Positionen | +Person / Firma | +Ausgang (S) | +Eingang (H) | +Konto | +Projekt | +
|---|---|---|---|---|---|---|---|---|
| + | + | {{ $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']) }} | ++ | + |
| + @endfor + |