Implemented compact scopre report.
This commit is contained in:
@@ -25,4 +25,9 @@ class AccountClass extends Model
|
||||
{
|
||||
return $this->belongsTo('App\Scope');
|
||||
}
|
||||
|
||||
public function accountTypes()
|
||||
{
|
||||
return $this->hasMany('App\AccountType');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,11 @@ class AccountType extends Model
|
||||
return $this->belongsTo('App\AccountClass');
|
||||
}
|
||||
|
||||
public function subBookings()
|
||||
{
|
||||
return $this->hasMany('App\SubBooking');
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
* INDIRECT RELATIONS *
|
||||
**************************************************************************/
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Http\Controllers;
|
||||
|
||||
use App\Project;
|
||||
use App\SubBooking;
|
||||
use App\Scope;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
@@ -116,7 +117,47 @@ class ReportsController extends Controller
|
||||
*/
|
||||
public function scopes($type, $year)
|
||||
{
|
||||
//
|
||||
if ($type == 'compact') {
|
||||
$yearFilter = function($query) use ($year) {
|
||||
$query->whereHas('booking', function($query) use ($year) {
|
||||
$query->whereYear('date', $year);
|
||||
});
|
||||
};
|
||||
|
||||
$scopes = Scope::select('id', 'name')
|
||||
->with([
|
||||
'accountClasses:id,io_type_id,scope_id,name',
|
||||
'accountClasses.ioType:id,factor',
|
||||
'accountClasses.accountTypes' => function($query) use ($year, $yearFilter) {
|
||||
return $query->select('id', 'account_class_id', 'name', 'number')
|
||||
->whereHas('subBookings', $yearFilter)
|
||||
->with(['subBookings' => $yearFilter]);
|
||||
}
|
||||
])->get();
|
||||
|
||||
foreach ($scopes as $scope) {
|
||||
foreach ($scope->accountClasses as $accountClass) {
|
||||
$accountClass->amount =
|
||||
$accountClass->accountTypes->sum(function ($accountType) {
|
||||
return $accountType->subBookings->sum('amount');
|
||||
});
|
||||
}
|
||||
|
||||
$scope->balance = $scope->accountClasses->sum(function ($accountClass) {
|
||||
return $accountClass->amount * $accountClass->ioType->factor;
|
||||
});
|
||||
}
|
||||
|
||||
$startBalance = SubBooking::balanceAt(lastDayOfYear($year - 1));
|
||||
$endBalance = $startBalance + $scopes->sum('balance');
|
||||
|
||||
return view('reports.scopes.compact', compact('scopes', 'year',
|
||||
'startBalance', 'endBalance'));
|
||||
} elseif ($type == 'detailed') {
|
||||
return view('reports.scopes.detailed');
|
||||
} else {
|
||||
abort(404);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+3
-1
@@ -6,5 +6,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Scope extends Model
|
||||
{
|
||||
//
|
||||
public function accountClasses() {
|
||||
return $this->hasMany('App\AccountClass');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
<li class="nav-item ml-auto">
|
||||
<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>
|
||||
<a href='/reports/scopes/compact/{{ $year }}' class="btn
|
||||
btn-outline-warning">Abrechnung</a>
|
||||
</li>
|
||||
@endsection
|
||||
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
@extends('layout.master')
|
||||
|
||||
@section('title', 'Abrechnung ' . $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'>
|
||||
<tr>
|
||||
<td>
|
||||
<b>Kontostand am 1. 1. {{ $year }}</b>
|
||||
</td>
|
||||
<td>
|
||||
<b>{!! formatAmount($startBalance) !!}</b>
|
||||
</td>
|
||||
</tr>
|
||||
<tr><td colspan='2'></td></tr>
|
||||
@foreach($scopes as $scope)
|
||||
<tr>
|
||||
<td colspan='2'><b>{{ $scope->name }}</b></td>
|
||||
</tr>
|
||||
@foreach($scope->accountClasses as $accountClass)
|
||||
<tr>
|
||||
<td colspan='2' style='text-indent: 2em;'>
|
||||
<u>{{ $accountClass->name }}</u>
|
||||
</td>
|
||||
</tr>
|
||||
@foreach($accountClass->accountTypes as $accountType)
|
||||
<tr>
|
||||
<td style='text-indent: 4em;'>
|
||||
{{$accountType->number}} - {{$accountType->name}}
|
||||
</td>
|
||||
<td>
|
||||
{!! formatAmount($accountType->subBookings->sum('amount')) !!}
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
<tr><td colspan='2'></td></tr>
|
||||
@endforeach
|
||||
<tr>
|
||||
<td colspan='2' style='text-indent: 2em;'>
|
||||
<u>GESAMT</u>
|
||||
</td>
|
||||
<tr>
|
||||
@foreach($scope->accountClasses as $accountClass)
|
||||
<tr>
|
||||
<td style='text-indent: 4em;'>
|
||||
{{ $accountClass->name }}
|
||||
</td>
|
||||
<td>
|
||||
{!! formatAmount($accountClass->amount) !!}
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
<tr>
|
||||
<td style='text-indent: 4em;'>
|
||||
Saldo {{ $scope->name }}
|
||||
</td>
|
||||
<td>{!! formatAmount($scope->balance) !!}</td>
|
||||
</tr>
|
||||
<tr><td colspan='2'></td></tr>
|
||||
@endforeach
|
||||
<tr>
|
||||
<td colspan='2'>
|
||||
<b>Übersicht</b>
|
||||
</td>
|
||||
<tr>
|
||||
@foreach($scopes as $scope)
|
||||
<tr>
|
||||
<td style='text-indent: 4em;'>
|
||||
Saldo {{ $scope->name }}
|
||||
</td>
|
||||
<td>{!! formatAmount($scope->balance) !!}</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
<tr>
|
||||
<td style='text-indent: 4em;'>Gesamtsaldo</td>
|
||||
<td>{!! formatAmount($scopes->sum('balance')) !!}</td>
|
||||
</tr>
|
||||
<tr><td colspan='2'></td></tr>
|
||||
<tr>
|
||||
<td>
|
||||
<b>Kontostand am 31. 12. {{ $year }}</b>
|
||||
</td>
|
||||
<td>
|
||||
<b>{!! formatAmount($endBalance) !!}</b>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
@endsection
|
||||
Reference in New Issue
Block a user