Added print version of the cashbook.
This commit is contained in:
@@ -24,48 +24,15 @@ class BookingsController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function index($year)
|
public function index($year)
|
||||||
{
|
{
|
||||||
$bookings = Booking::with('subBookings.accountType.accountClass.ioType',
|
$cashbook = $this->getCashbook($year);
|
||||||
'subBookings.project')
|
|
||||||
->whereYear('date', '=', $year)
|
|
||||||
->orderBy('date')
|
|
||||||
->get()
|
|
||||||
->groupBy( function ($item) {
|
|
||||||
return Carbon::parse($item->date)->format('n');
|
|
||||||
});
|
|
||||||
|
|
||||||
$sums = array();
|
return view('bookings.index', $cashbook);
|
||||||
|
}
|
||||||
|
|
||||||
$startBalance = SubBooking::balanceAt($year - 1 . '-12-31');
|
public function report($year) {
|
||||||
$sums[0]['balance'] = $startBalance;
|
$cashbook = $this->getCashbook($year);
|
||||||
|
|
||||||
$expeditures = SubBooking::expedituresInInterval($year . '-01-01', $year . '-12-31', true);
|
return view('bookings.print', $cashbook);
|
||||||
|
|
||||||
$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 view('bookings.index', compact('bookings', 'year', 'sums', 'firstDate'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -346,4 +313,49 @@ class BookingsController extends Controller
|
|||||||
|
|
||||||
return compact('openTargetsArray', 'projectsArray', 'accountTypeArray');
|
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');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,115 @@
|
|||||||
|
@extends('layout.print')
|
||||||
|
|
||||||
|
@section('title', 'Kassenbuch ' . $year)
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
@for ($month = 1; $month <= 12; $month++)
|
||||||
|
<table class='table table-striped table-sm table-borderless'
|
||||||
|
style='page-break-after: always'>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Datum</th>
|
||||||
|
<th>Positionen</th>
|
||||||
|
<th>Person / Firma</th>
|
||||||
|
<th>Ausgang</th>
|
||||||
|
<th>Eingang</th>
|
||||||
|
<th>Konto</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
@if ((
|
||||||
|
date('Y') > $year
|
||||||
|
or (date('Y') == $year
|
||||||
|
and date('m') >= $month)
|
||||||
|
) and (
|
||||||
|
$firstDate['Y'] < $year
|
||||||
|
or $firstDate['Y'] == $year
|
||||||
|
and $firstDate['m'] <= $month
|
||||||
|
))
|
||||||
|
<tr style='color:#ff0000'>
|
||||||
|
<th>{{ startOfMonth($year, $month) }}</th>
|
||||||
|
<th>Saldo</th>
|
||||||
|
<th></th>
|
||||||
|
<th></th>
|
||||||
|
<th>{!! formatAmount($sums[$month - 1]['balance']) !!}</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
@endif
|
||||||
|
@if (isset($bookings[$month]))
|
||||||
|
@foreach($bookings[$month] as $booking)
|
||||||
|
<tr>
|
||||||
|
<td>{{ formatDate($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()->number }}
|
||||||
|
@endif
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
@if (!$booking->isSimple())
|
||||||
|
@foreach ($booking->subBookings as $subBooking)
|
||||||
|
<tr style='font-style:italic'>
|
||||||
|
<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->number }}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
@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
|
||||||
|
))
|
||||||
|
<tr style='color:#000080'>
|
||||||
|
<th>
|
||||||
|
{{ endOfMonth($year, $month) }}
|
||||||
|
</th>
|
||||||
|
<th>Monatsabschluss</th>
|
||||||
|
<th></th>
|
||||||
|
<th>{!! formatAmount($sums[$month]['expeditures']) !!}</th>
|
||||||
|
<th>{!! formatAmount($sums[$month]['incomes']) !!}</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
<tr style='color:#ff0000'>
|
||||||
|
<th>
|
||||||
|
{{ endOfMonth($year, $month) }}
|
||||||
|
</th>
|
||||||
|
<th>Saldo</th>
|
||||||
|
<th></th>
|
||||||
|
<th>{!! formatAmount($sums[$month]['balance']) !!}</th>
|
||||||
|
<th></th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
@endif
|
||||||
|
</table>
|
||||||
|
@endfor
|
||||||
|
@endsection
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Pollux - @yield('title')</title>
|
<title>Twäng! e. V. - @yield('title')</title>
|
||||||
|
|
||||||
<link rel="stylesheet"
|
<link rel="stylesheet"
|
||||||
href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
|
href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
<b>{{ $accountClass->name }}</b>
|
<b>{{ $accountClass->name }}</b>
|
||||||
<table class='table table-sm table-borderless' style='page-break-after: always'>
|
<table class='table table-sm table-borderless' style='page-break-after: always'>
|
||||||
<thead>
|
<thead>
|
||||||
<tr style='color: #000080'>
|
<tr>
|
||||||
<th>Datum</th>
|
<th>Datum</th>
|
||||||
<th>Position</th>
|
<th>Position</th>
|
||||||
<th>Person / Firma</th>
|
<th>Person / Firma</th>
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ Route::middleware(['auth'])->group(function() {
|
|||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
Route::redirect('/bookings', 'bookings/year-' . date('Y'));
|
Route::redirect('/bookings', 'bookings/year-' . date('Y'));
|
||||||
Route::get('/bookings/year-{year}', 'BookingsController@index');
|
Route::get('/bookings/year-{year}', 'BookingsController@index');
|
||||||
|
Route::get('/bookings/year-{year}/print', 'BookingsController@report');
|
||||||
Route::post('/bookings', 'BookingsController@store');
|
Route::post('/bookings', 'BookingsController@store');
|
||||||
|
|
||||||
Route::get('/bookings/create', 'BookingsController@create');
|
Route::get('/bookings/create', 'BookingsController@create');
|
||||||
|
|||||||
Reference in New Issue
Block a user