diff --git a/app/Http/Controllers/BookingsController.php b/app/Http/Controllers/BookingsController.php
index 48cebf2..098faf1 100644
--- a/app/Http/Controllers/BookingsController.php
+++ b/app/Http/Controllers/BookingsController.php
@@ -24,48 +24,15 @@ class BookingsController extends Controller
*/
public function index($year)
{
- $bookings = Booking::with('subBookings.accountType.accountClass.ioType',
- 'subBookings.project')
- ->whereYear('date', '=', $year)
- ->orderBy('date')
- ->get()
- ->groupBy( function ($item) {
- return Carbon::parse($item->date)->format('n');
- });
+ $cashbook = $this->getCashbook($year);
- $sums = array();
-
- $startBalance = SubBooking::balanceAt($year - 1 . '-12-31');
- $sums[0]['balance'] = $startBalance;
+ return view('bookings.index', $cashbook);
+ }
- $expeditures = SubBooking::expedituresInInterval($year . '-01-01', $year . '-12-31', true);
-
- $incomes = SubBooking::incomesInInterval($year . '-01-01', $year . '-12-31', true);
+ public function report($year) {
+ $cashbook = $this->getCashbook($year);
- // 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++) {
- $currExpeditures = $expeditures->where('month', '=', $month)->first()->expeditures;
-
- $currIncomes = $expeditures->where('month', '<', $month)->sum('expeditures')
- + $incomes->where('month', '<=', $month)->sum('incomes')
- + $startBalance;
-
- $currBalance = $currExpeditures + $currIncomes;
-
- $sums[$month]['expeditures'] = $currExpeditures;
- $sums[$month]['incomes'] = $currIncomes;
- $sums[$month]['balance'] = $currBalance;
- }
-
- $firstDateString = Carbon::parse(Booking::firstDate());
- $firstDate['Y'] = $firstDateString->format('Y');
- $firstDate['m'] = $firstDateString->format('m');
-
- return view('bookings.index', compact('bookings', 'year', 'sums', 'firstDate'));
+ return view('bookings.print', $cashbook);
}
/**
@@ -285,7 +252,7 @@ class BookingsController extends Controller
// ... and create a list of the open targets to show it in the form as
// dropdown menu.
$openTargetsArray = [];
-
+
foreach ($openTargets as $personTargets) {
foreach ($personTargets as $personTarget) {
$person = $personTarget->person;
@@ -306,7 +273,7 @@ class BookingsController extends Controller
foreach ($projects as $project) {
$timeOfProject = '';
-
+
if ($project->start_date <= today() and $project->end_date >= today()) {
$timeOfProject = 'Laufende Projekte';
} elseif ($project->start_date > today()) {
@@ -314,7 +281,7 @@ class BookingsController extends Controller
} else {
$timeOfProject = 'Vergangene Projekte';
}
-
+
$projectsArray['Vergangene Projekte'][$project->id] = $project->name;
}
@@ -346,4 +313,49 @@ class BookingsController extends Controller
return compact('openTargetsArray', 'projectsArray', 'accountTypeArray');
}
+
+ private function getCashbook($year) {
+ $bookings = Booking::with('subBookings.accountType.accountClass.ioType',
+ 'subBookings.project')
+ ->whereYear('date', '=', $year)
+ ->orderBy('date')
+ ->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++) {
+ $currExpeditures = $expeditures->where('month', '=', $month)->first()->expeditures;
+
+ $currIncomes = $expeditures->where('month', '<', $month)->sum('expeditures')
+ + $incomes->where('month', '<=', $month)->sum('incomes')
+ + $startBalance;
+
+ $currBalance = $currExpeditures + $currIncomes;
+
+ $sums[$month]['expeditures'] = $currExpeditures;
+ $sums[$month]['incomes'] = $currIncomes;
+ $sums[$month]['balance'] = $currBalance;
+ }
+
+ $firstDateString = Carbon::parse(Booking::firstDate());
+ $firstDate['Y'] = $firstDateString->format('Y');
+ $firstDate['m'] = $firstDateString->format('m');
+
+ return compact('bookings', 'year', 'sums', 'firstDate');
+ }
}
diff --git a/resources/views/bookings/print.blade.php b/resources/views/bookings/print.blade.php
new file mode 100644
index 0000000..bb07d72
--- /dev/null
+++ b/resources/views/bookings/print.blade.php
@@ -0,0 +1,115 @@
+@extends('layout.print')
+
+@section('title', 'Kassenbuch ' . $year)
+
+@section('content')
+@for ($month = 1; $month <= 12; $month++)
+
+
+
+ | Datum |
+ Positionen |
+ Person / Firma |
+ Ausgang |
+ Eingang |
+ Konto |
+
+
+ @if ((
+ date('Y') > $year
+ or (date('Y') == $year
+ and date('m') >= $month)
+ ) and (
+ $firstDate['Y'] < $year
+ or $firstDate['Y'] == $year
+ and $firstDate['m'] <= $month
+ ))
+
+ | {{ startOfMonth($year, $month) }} |
+ Saldo |
+ |
+ |
+ {!! formatAmount($sums[$month - 1]['balance']) !!} |
+ |
+
+ @endif
+ @if (isset($bookings[$month]))
+ @foreach($bookings[$month] as $booking)
+
+ | {{ formatDate($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()->number }}
+ @endif
+ |
+
+ @if (!$booking->isSimple())
+ @foreach ($booking->subBookings as $subBooking)
+
+ |
+ {{ $subBooking->reference }} |
+ |
+
+ @if ($subBooking->signedAmount() < 0)
+ {!! formatAmount($subBooking->signedAmount()) !!}
+ @endif
+ |
+
+ @if ($subBooking->signedAmount() >= 0)
+ {!! formatAmount($subBooking->signedAmount()) !!}
+ @endif
+ |
+
+ {{ $subBooking->accountType->number }}
+ |
+
+ @endforeach
+ @endif
+ @endforeach
+ @endif
+ @if ((
+ date('Y') > $year
+ or (date('Y') == $year
+ and date('m') >= $month)
+ ) and (
+ $firstDate['Y'] < $year
+ or $firstDate['Y'] == $year
+ and $firstDate['m'] <= $month
+ ))
+
+ |
+ {{ endOfMonth($year, $month) }}
+ |
+ Monatsabschluss |
+ |
+ {!! formatAmount($sums[$month]['expeditures']) !!} |
+ {!! formatAmount($sums[$month]['incomes']) !!} |
+ |
+
+
+ |
+ {{ endOfMonth($year, $month) }}
+ |
+ Saldo |
+ |
+ {!! formatAmount($sums[$month]['balance']) !!} |
+ |
+ |
+
+ @endif
+
+@endfor
+@endsection
diff --git a/resources/views/layout/print.blade.php b/resources/views/layout/print.blade.php
index 13ba7fc..89b4a85 100644
--- a/resources/views/layout/print.blade.php
+++ b/resources/views/layout/print.blade.php
@@ -1,6 +1,6 @@
- Pollux - @yield('title')
+ Twäng! e. V. - @yield('title')
{{ $accountClass->name }}
-
+
| Datum |
Position |
Person / Firma |
diff --git a/routes/web.php b/routes/web.php
index 2ec9b6c..3f47ffc 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -19,52 +19,53 @@ Route::middleware(['auth'])->group(function() {
**************************************************************************/
Route::get('/people', 'PeopleController@index');
Route::post('/people', 'PeopleController@store');
-
+
Route::get('/people/create', 'PeopleController@create');
Route::get('/people/{person}', 'PeopleController@show');
Route::patch('/people/{person}', 'PeopleController@update');
Route::delete('/people/{person}', 'PeopleController@destroy');
-
+
Route::get('/people/{person}/edit', 'PeopleController@edit');
Route::get('/people/{person}/delete', 'PeopleController@delete');
-
+
/**************************************************************************
* BOOKINGS *
**************************************************************************/
Route::redirect('/bookings', 'bookings/year-' . date('Y'));
Route::get('/bookings/year-{year}', 'BookingsController@index');
+ Route::get('/bookings/year-{year}/print', 'BookingsController@report');
Route::post('/bookings', 'BookingsController@store');
-
+
Route::get('/bookings/create', 'BookingsController@create');
Route::patch('/bookings/{booking}', 'BookingsController@update');
Route::delete('/bookings/{booking}', 'BookingsController@destroy');
-
+
Route::get('/bookings/{booking}/edit', 'BookingsController@edit');
Route::get('/bookings/{booking}/delete', 'BookingsController@delete');
-
+
/**************************************************************************
* PROJECTS *
**************************************************************************/
Route::get('/projects', 'ProjectsController@index');
Route::post('/projects', 'ProjectsController@store');
-
+
Route::get('/projects/create', 'ProjectsController@create');
Route::patch('/projects/{project}', 'ProjectsController@update');
Route::delete('/projects/{project}', 'ProjectsController@destroy');
-
+
Route::get('/projects/{project}/edit', 'ProjectsController@edit');
Route::get('/projects/{project}/delete', 'ProjectsController@delete');
-
+
/**************************************************************************
* PERSON TARGETS *
**************************************************************************/
Route::get('/targets', 'PersonTargetsController@index');
Route::post('/targets', 'PersonTargetsController@store');
-
+
Route::get('/targets/create', 'PersonTargetsController@create');
Route::patch('/targets/{personTarget}', 'PersonTargetsController@update');
Route::delete('/targets/{personTarget}', 'PersonTargetsController@destroy');
-
+
Route::get('/targets/{personTarget}/edit', 'PersonTargetsController@edit');
Route::get('/targets/{personTarget}/delete', 'PersonTargetsController@delete');