Implemented balances report.
This commit is contained in:
@@ -51,7 +51,62 @@ class ReportsController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function balances($year)
|
public function balances($year)
|
||||||
{
|
{
|
||||||
//
|
# Load monthly incomes, expeditures and the start account balance from
|
||||||
|
# the database.
|
||||||
|
$incomes = SubBooking::incomesInInterval(firstDayOfYear($year),
|
||||||
|
lastDayOfYear($year), true)->sortBy('month');
|
||||||
|
$expeditures = SubBooking::expedituresInInterval(firstDayOfYear($year),
|
||||||
|
lastDayOfYear($year), true)->sortBy('month');
|
||||||
|
$startBalance = SubBooking::balanceAt(lastDayOfYear($year - 1));
|
||||||
|
|
||||||
|
# If the data contains future months remove the data of all incomplete
|
||||||
|
# months.
|
||||||
|
if (date('Y') <= $year) {
|
||||||
|
foreach ([$incomes, $expeditures] as $cashflows) {
|
||||||
|
foreach ($cashflows as $key => $cashflow) {
|
||||||
|
if ($cashflow->month >= date('n')) {
|
||||||
|
$cashflows->forget($key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create a collection of balances, every entry holds information about
|
||||||
|
# one month.
|
||||||
|
$balances = collect();
|
||||||
|
|
||||||
|
for ($i = 0; $i < count($incomes); $i++) {
|
||||||
|
$balance = collect();
|
||||||
|
|
||||||
|
$balance->incomes = $incomes[$i]->incomes;
|
||||||
|
$balance->expeditures = $expeditures[$i]->expeditures;
|
||||||
|
$balance->monthBalance = $incomes[$i]->incomes
|
||||||
|
+ $expeditures[$i]->expeditures;
|
||||||
|
|
||||||
|
# Set date separately if the next month is in the new year.
|
||||||
|
if ($incomes[$i]->month == 12) {
|
||||||
|
$balance->date = firstDayOfYear($incomes[$i]->year + 1);
|
||||||
|
} else {
|
||||||
|
$balance->date = startOfMonth($incomes[$i]->year,
|
||||||
|
$incomes[$i]->month + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
# Set the balance of the first month separately since the value
|
||||||
|
# depends on the startBalance value and not on a value already
|
||||||
|
# existing in the balances collection.
|
||||||
|
if ($incomes[$i]->month == 1) {
|
||||||
|
$balance->accountBalance = $startBalance
|
||||||
|
+ $balance->monthBalance;
|
||||||
|
} else {
|
||||||
|
$balance->accountBalance = $balances[$i - 1]->accountBalance
|
||||||
|
+ $balance->monthBalance;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Add complete balance to the balances collection
|
||||||
|
$balances->push($balance);
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('reports.balances', compact('year', 'balances', 'startBalance'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+1
-1
@@ -213,7 +213,7 @@ class SubBooking extends Model
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result->sortBy('month')->sortBy('year')->values();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result->get();
|
return $result->get();
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
@section('subnav')
|
@section('subnav')
|
||||||
<li class="nav-item ml-auto">
|
<li class="nav-item ml-auto">
|
||||||
<a href='/bookings/create' class="btn btn-outline-success">Neue Buchung</a>
|
<a href='/bookings/create' class="btn btn-outline-success">Neue Buchung</a>
|
||||||
|
<a href='/reports/balances/{{ $year }}' class="btn btn-outline-warning">HS-Rechnung</a>
|
||||||
</li>
|
</li>
|
||||||
@endsection
|
@endsection
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
@extends('layout.master')
|
||||||
|
|
||||||
|
@section('title', 'HS-Rechnung für ' . $year)
|
||||||
|
|
||||||
|
@section('subnav')
|
||||||
|
<a class='btn btn-outline-secondary' href='/bookings/year-{{ $year }}'>Zurück</a>
|
||||||
|
@endsection
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<h2>@yield('title')</h2>
|
||||||
|
<table class='table table-striped table-bordered'>
|
||||||
|
<tr>
|
||||||
|
<th>Datum</th>
|
||||||
|
<th>Kontostand</th>
|
||||||
|
<th>Monatssaldo</th>
|
||||||
|
<th>Abgänge</th>
|
||||||
|
<th>Zugänge</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>{{ formatDate(firstDayOfYear($year)) }}</td>
|
||||||
|
<td>{!! formatAmount($startBalance) !!}</td>
|
||||||
|
<td></td>
|
||||||
|
<td></td>
|
||||||
|
<td></td>
|
||||||
|
</tr>
|
||||||
|
@foreach($balances as $balance)
|
||||||
|
<tr>
|
||||||
|
<td>{{ formatDate($balance->date) }}</td>
|
||||||
|
<td>{!! formatAmount($balance->accountBalance) !!}</td>
|
||||||
|
<td>{!! formatAmount($balance->monthBalance) !!}</td>
|
||||||
|
<td>{!! formatAmount($balance->expeditures) !!}</td>
|
||||||
|
<td>{!! formatAmount($balance->incomes) !!}</td>
|
||||||
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
</table>
|
||||||
|
@endsection
|
||||||
Reference in New Issue
Block a user