Added bookings controller and index view.
This commit is contained in:
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Booking;
|
||||
use App\SubBooking;
|
||||
use Illuminate\Http\Request;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class BookingsController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index($year)
|
||||
{
|
||||
$bookings = Booking::whereYear('date', '=', $year)
|
||||
->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)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
@extends('layout.master')
|
||||
|
||||
@section('title', 'Kassenbuch')
|
||||
|
||||
@section('subnav')
|
||||
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
<h4>
|
||||
<a href='/bookings/year-{{ $year - 1 }}'>{{ $year - 1 }}</a>
|
||||
1. Januar {{ $year }} - 31. Dezember {{ $year }}
|
||||
<a href='/bookings/year-{{ $year + 1 }}'>{{ $year + 1 }}</a>
|
||||
</h4>
|
||||
<table border='1'>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th>ID</th>
|
||||
<th>Datum</th>
|
||||
<th>Positionen</th>
|
||||
<th>Person / Firma</th>
|
||||
<th>Ausgang (S)</th>
|
||||
<th>Eingang (H)</th>
|
||||
<th>Konto</th>
|
||||
<th>Projekt</th>
|
||||
</tr>
|
||||
@for ($month = 1; $month <= 12; $month++)
|
||||
@if (isset($bookings[$month]))
|
||||
<tr style='color: red; font-weight: bold'>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td>{{ $year . '-' . sprintf('%02d', $month) . '-01'}}</td>
|
||||
<td>Saldo</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td>{{ formatAmount($sums[$month - 1]['balance']) }}</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
@foreach($bookings[$month] as $booking)
|
||||
<tr>
|
||||
<td>
|
||||
@if (!$booking->isSimple())
|
||||
v
|
||||
@endif
|
||||
</td>
|
||||
<td>{{ $booking->id }}</td>
|
||||
<td>{{ $booking->date }}</td>
|
||||
<td>{{ $booking->reference }}</td>
|
||||
<td>{{ $booking->person_or_company }}</td>
|
||||
<td align='right'>
|
||||
@if ($booking->signedAmount() < 0)
|
||||
{{ formatAmount($booking->signedAmount()) }}
|
||||
@endif
|
||||
</td>
|
||||
<td align='right'>
|
||||
@if ($booking->signedAmount() >= 0)
|
||||
{{ formatAmount($booking->signedAmount()) }}
|
||||
@endif
|
||||
</td>
|
||||
<td>
|
||||
@if ($booking->isSimple())
|
||||
{{ $booking->accountType->name }}
|
||||
@endif
|
||||
</td>
|
||||
<td>
|
||||
@if ($booking->isSimple())
|
||||
{{ $booking->project->name }}
|
||||
@endif
|
||||
</td>
|
||||
</tr>
|
||||
@if (!$booking->isSimple())
|
||||
@foreach ($booking->subBookings()->withSignedAmount()->get() as $subBooking)
|
||||
<tr>
|
||||
<td>+</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td>{{ $subBooking->reference }}</td>
|
||||
<td></td>
|
||||
<td align='right'>
|
||||
@if ($subBooking->signedAmount < 0)
|
||||
{{ formatAmount($subBooking->signedAmount) }}
|
||||
@endif
|
||||
</td>
|
||||
<td align='right'>
|
||||
@if ($subBooking->signedAmount >= 0)
|
||||
{{ formatAmount($subBooking->signedAmount) }}
|
||||
@endif
|
||||
</td>
|
||||
<td>
|
||||
{{ $subBooking->accountType->name }}
|
||||
</td>
|
||||
<td>
|
||||
{{ $subBooking->project->name }}
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
@endif
|
||||
@endforeach
|
||||
<tr style='color: #000080; font-weight: bold'>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td>
|
||||
{{ $year . '-' . sprintf('%02d', $month) . '-' .
|
||||
cal_days_in_month(CAL_GREGORIAN, $month, $year) }}
|
||||
</td>
|
||||
<td>Monatsabschluss</td>
|
||||
<td></td>
|
||||
<td>{{ formatAmount($sums[$month]['expeditures']) }}</td>
|
||||
<td>{{ formatAmount($sums[$month]['incomes']) }}</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr style='color: red; font-weight: bold'>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td>
|
||||
{{ $year . '-' . sprintf('%02d', $month) . '-' .
|
||||
cal_days_in_month(CAL_GREGORIAN, $month, $year) }}
|
||||
</td>
|
||||
<td>Saldo</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td>{{ formatAmount($sums[$month]['balance']) }}</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
@for ($i = 0; $i < 9; $i++)
|
||||
<td> </td>
|
||||
@endfor
|
||||
</tr>
|
||||
@endif
|
||||
@endfor
|
||||
</table>
|
||||
@endsection
|
||||
Reference in New Issue
Block a user