First attempt at new month report.

This commit is contained in:
James Cole 2014-12-25 09:50:01 +01:00
parent 1659904f81
commit 290f25f1a0
9 changed files with 221 additions and 57 deletions

View File

@ -30,6 +30,9 @@ class ReportController extends BaseController
$this->_journals = $journals;
$this->_repository = $repository;
View::share('title', 'Reports');
View::share('mainTitleIcon', 'fa-line-chart');
}
/**
@ -46,6 +49,33 @@ class ReportController extends BaseController
return View::make('reports.index', compact('years', 'months', 'title', 'mainTitleIcon'));
}
/**
* @param string $year
* @param string $month
*
* @return \Illuminate\View\View
*/
public function month($year = '2014', $month = '1')
{
try {
new Carbon($year . '-' . $month . '-01');
} catch (Exception $e) {
View::make('error')->with('message', 'Invalid date');
}
$date = new Carbon($year . '-' . $month . '-01');
$subTitle = 'Report for ' . $date->format('F Y');
$subTitleIcon = 'fa-calendar';
$income = $this->_repository->getIncomeForMonth($date,false);
// var_dump($income->toArray());
// exit;
return View::make('reports.month', compact('date', 'subTitle', 'subTitleIcon','income'));
}
/**
* @param $year
* @param $month

View File

@ -13,7 +13,7 @@ class ChangesForV322 extends Migration
*/
public function down()
{
// TODO
}
@ -27,6 +27,8 @@ class ChangesForV322 extends Migration
// rename tables:
Schema::rename('piggybank_repetitions', 'piggy_bank_repetitions');
Schema::rename('piggybanks', 'piggy_banks');
// rename fields
Schema::table(
'piggy_bank_events', function (Blueprint $table) {
$table->renameColumn('piggybank_id', 'piggy_bank_id');
@ -38,6 +40,13 @@ class ChangesForV322 extends Migration
$table->renameColumn('piggybank_id', 'piggy_bank_id');
}
);
// add soft delete to piggy banks
Schema::table(
'piggy_banks', function (Blueprint $table) {
$table->softDeletes();
}
);
}
}

View File

@ -5,6 +5,7 @@ namespace FireflyIII\Report;
use Carbon\Carbon;
use FireflyIII\Database\Account\Account as AccountRepository;
use FireflyIII\Database\SwitchUser;
use FireflyIII\Database\TransactionJournal\TransactionJournal as JournalRepository;
use Illuminate\Support\Collection;
// todo add methods to itnerface
@ -23,12 +24,16 @@ class Report implements ReportInterface
/** @var AccountRepository */
protected $_accounts;
/** @var JournalRepository */
protected $_journals;
/**
* @param AccountRepository $accounts
*/
public function __construct(AccountRepository $accounts)
public function __construct(AccountRepository $accounts, JournalRepository $journals)
{
$this->_accounts = $accounts;
$this->_journals = $journals;
}
@ -75,6 +80,30 @@ class Report implements ReportInterface
}
/**
* @param Carbon $date
* @param bool $shared
*
* @return Collection
*/
public function getIncomeForMonth(Carbon $date, $shared = false)
{
$start = clone $date;
$start->startOfMonth();
$end = clone $date;
$end->endOfMonth();
$userId = $this->_accounts->getUser()->id;
$list = \TransactionJournal::withRelevantData()
->transactionTypes(['Deposit'])
->where('user_id', $userId)
->orderBy('date','DESC')
->before($end)->after($start)->get(['transaction_journals.*']);
return $list;
}
/**
* @param Carbon $start
*

View File

@ -50,4 +50,12 @@ interface ReportInterface
* @return array
*/
public function yearBalanceReport(Carbon $date);
/**
* @param Carbon $date
* @param bool $shared
*
* @return Collection
*/
public function getIncomeForMonth(Carbon $date, $shared = false);
}

View File

@ -2,7 +2,6 @@
namespace FireflyIII\Shared\Toolkit;
use Carbon\Carbon;
use FireflyIII\Exception\FireflyException;
/**
@ -13,14 +12,14 @@ use FireflyIII\Exception\FireflyException;
class Date
{
/**
* @param Carbon $theDate
* @param \Carbon\Carbon $theDate
* @param $repeatFreq
* @param $skip
*
* @return Carbon
* @return \Carbon\Carbon
* @throws FireflyException
*/
public function addPeriod(Carbon $theDate, $repeatFreq, $skip)
public function addPeriod(\Carbon\Carbon $theDate, $repeatFreq, $skip)
{
$date = clone $theDate;
$add = ($skip + 1);
@ -59,13 +58,13 @@ class Date
}
/**
* @param Carbon $theCurrentEnd
* @param \Carbon\Carbon $theCurrentEnd
* @param $repeatFreq
*
* @return mixed
* @return \Carbon\Carbon
* @throws FireflyException
*/
public function endOfPeriod(Carbon $theCurrentEnd, $repeatFreq)
public function endOfPeriod(\Carbon\Carbon $theCurrentEnd, $repeatFreq)
{
$currentEnd = clone $theCurrentEnd;
switch ($repeatFreq) {
@ -100,14 +99,14 @@ class Date
}
/**
* @param Carbon $theCurrentEnd
* @param \Carbon\Carbon $theCurrentEnd
* @param $repeatFreq
* @param Carbon $maxDate
* @param \Carbon\Carbon $maxDate
*
* @return mixed
* @return \Carbon\Carbon
* @throws FireflyException
*/
public function endOfX(Carbon $theCurrentEnd, $repeatFreq, Carbon $maxDate)
public function endOfX(\Carbon\Carbon $theCurrentEnd, $repeatFreq, \Carbon\Carbon $maxDate)
{
$currentEnd = clone $theCurrentEnd;
switch ($repeatFreq) {
@ -149,13 +148,13 @@ class Date
}
/**
* @param Carbon $date
* @param \Carbon\Carbon $date
* @param $repeatFrequency
*
* @return string
* @throws FireflyException
*/
public function periodShow(Carbon $date, $repeatFrequency)
public function periodShow(\Carbon\Carbon $date, $repeatFrequency)
{
switch ($repeatFrequency) {
default:
@ -183,13 +182,13 @@ class Date
}
/**
* @param Carbon $theDate
* @param \Carbon\Carbon $theDate
* @param $repeatFreq
*
* @return Carbon
* @return \Carbon\Carbon
* @throws FireflyException
*/
public function startOfPeriod(Carbon $theDate, $repeatFreq)
public function startOfPeriod(\Carbon\Carbon $theDate, $repeatFreq)
{
$date = clone $theDate;
switch ($repeatFreq) {
@ -228,14 +227,14 @@ class Date
}
/**
* @param Carbon $theDate
* @param \Carbon\Carbon $theDate
* @param $repeatFreq
* @param int $subtract
*
* @return Carbon
* @return \Carbon\Carbon
* @throws FireflyException
*/
public function subtractPeriod(Carbon $theDate, $repeatFreq, $subtract = 1)
public function subtractPeriod(\Carbon\Carbon $theDate, $repeatFreq, $subtract = 1)
{
$date = clone $theDate;
switch ($repeatFreq) {

View File

@ -247,7 +247,8 @@ Route::group(
// report controller:
Route::get('/reports', ['uses' => 'ReportController@index', 'as' => 'reports.index']);
Route::get('/reports/{year}', ['uses' => 'ReportController@year', 'as' => 'reports.year']);
Route::get('/reports/unbalanced/{year}/{month}', ['uses' => 'ReportController@unbalanced', 'as' => 'reports.unbalanced']);
Route::get('/reports/{year}/{month}', ['uses' => 'ReportController@month', 'as' => 'reports.month']);
#Route::get('/reports/unbalanced/{year}/{month}', ['uses' => 'ReportController@unbalanced', 'as' => 'reports.unbalanced']);
// reminder controller
Route::get('/reminders/{reminder}', ['uses' => 'ReminderController@show', 'as' => 'reminders.show']);

View File

@ -0,0 +1,31 @@
<table class="table table-bordered">
@foreach($journals as $journal)
<tr>
<td>
<a href="{{route('transactions.show',$journal->id)}}" title="{{{$journal->description}}}">{{{$journal->description}}}</a>
</td>
<td>
@if($journal->transactiontype->type == 'Withdrawal')
<span class="text-danger">{{mf($journal->transactions[1]->amount,false)}}</span>
@endif
@if($journal->transactiontype->type == 'Deposit')
<span class="text-success">{{mf($journal->transactions[1]->amount,false)}}</span>
@endif
@if($journal->transactiontype->type == 'Transfer')
<span class="text-info">{{mf($journal->transactions[1]->amount,false)}}</span>
@endif
</td>
<td>
{{$journal->date->format('j F Y')}}
</td>
<td>
@if($journal->transactions[1]->account->accounttype->description == 'Cash account')
<span class="text-success">(cash)</span>
@else
<a href="{{route('accounts.show',$journal->transactions[1]->account_id)}}">{{{$journal->transactions[1]->account->name}}}</a>
@endif
</td>
</tr>
@endforeach
</table>

View File

@ -16,29 +16,16 @@
</div>
</div>
</div>
<div class="col-lg-4 col-md-4 col-sm-4">
<div class="panel panel-default">
<div class="panel-heading">
Budget reports
Monthly reports
</div>
<div class="panel-body">
<ul>
@foreach($months as $month)
<li><a href="#{{$month['year']}}-{{$month['month']}}">{{$month['formatted']}}</a></li>
@endforeach
</ul>
</div>
</div>
</div>
<div class="col-lg-4 col-md-4 col-sm-4">
<div class="panel panel-default">
<div class="panel-heading">
Unbalanced transactions
</div>
<div class="panel-body">
<ul>
@foreach($months as $month)
<li><a href="{{route('reports.unbalanced',[$month['year'],$month['month']])}}">{{$month['formatted']}}</a></li>
<li><a href="{{route('reports.month',[$month['year'],$month['month']])}}">{{$month['formatted']}}</a></li>
@endforeach
</ul>
</div>

View File

@ -0,0 +1,70 @@
@extends('layouts.default')
@section('content')
{{ Breadcrumbs::renderIfExists(Route::getCurrentRoute()->getName()) }}
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-12">
<div class="panel panel-default">
<div class="panel-heading">Income</div>
@include('list.journals-small',['journals' => $income])
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-12">
<div class="panel panel-default">
<div class="panel-heading">Expenses (top 10)</div>
<div class="panel-body">Body</div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-12">
<div class="panel panel-default">
<div class="panel-heading">Budgets</div>
<div class="panel-body">Body</div>
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-12">
<div class="panel panel-default">
<div class="panel-heading">Categories</div>
<div class="panel-body">Body</div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
<div class="panel panel-default">
<div class="panel-heading">Accounts</div>
<div class="panel-body">Body</div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-12">
<div class="panel panel-default">
<div class="panel-heading">Piggy banks</div>
<div class="panel-body">Body</div>
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-12">
<div class="panel panel-default">
<div class="panel-heading">Repeated expenses</div>
<div class="panel-body">Body</div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
<div class="panel panel-default">
<div class="panel-heading">Recurring transactions</div>
<div class="panel-body">Body</div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
<div class="panel panel-default">
<div class="panel-heading">Outside of budgets</div>
<div class="panel-body">Body</div>
</div>
</div>
</div>
@stop