Skip to content

Firefly III: a personal finances manager

First attempt at new month report.

James Cole290f25f1a07c
diff --git a/app/controllers/ReportController.php b/app/controllers/ReportController.php
index 96e806fa0b..81e7de76b8 100644
--- a/app/controllers/ReportController.php
+++ b/app/controllers/ReportController.php
@@ -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
@@ -83,7 +113,7 @@ class ReportController extends BaseController
return null;
}
);
- $deposits = $journals->filter(
+ $deposits = $journals->filter(
function (TransactionJournal $journal) {
$relations = $journal->transactiongroups()->where('relation', 'balance')->count();
$budgets = $journal->budgets()->count();
diff --git a/app/database/migrations/2014_12_24_191544_changes_for_v322.php b/app/database/migrations/2014_12_24_191544_changes_for_v322.php
index 49a66708c8..143c4fe376 100644
--- a/app/database/migrations/2014_12_24_191544_changes_for_v322.php
+++ b/app/database/migrations/2014_12_24_191544_changes_for_v322.php
@@ -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();
+ }
+ );
}
}
diff --git a/app/lib/FireflyIII/Report/Report.php b/app/lib/FireflyIII/Report/Report.php
index 8638ae20b0..0b59efcc4c 100644
--- a/app/lib/FireflyIII/Report/Report.php
+++ b/app/lib/FireflyIII/Report/Report.php
@@ -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
*
diff --git a/app/lib/FireflyIII/Report/ReportInterface.php b/app/lib/FireflyIII/Report/ReportInterface.php
index 4605beb75d..7cef787cb4 100644
--- a/app/lib/FireflyIII/Report/ReportInterface.php
+++ b/app/lib/FireflyIII/Report/ReportInterface.php
@@ -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);
}
\ No newline at end of file
diff --git a/app/lib/FireflyIII/Shared/Toolkit/Date.php b/app/lib/FireflyIII/Shared/Toolkit/Date.php
index 347a9b3c85..5ec5af4148 100644
--- a/app/lib/FireflyIII/Shared/Toolkit/Date.php
+++ b/app/lib/FireflyIII/Shared/Toolkit/Date.php
@@ -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 $repeatFreq
- * @param $skip
+ * @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 $repeatFreq
+ * @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 $repeatFreq
- * @param Carbon $maxDate
+ * @param \Carbon\Carbon $theCurrentEnd
+ * @param $repeatFreq
+ * @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 $repeatFrequency
+ * @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 $repeatFreq
+ * @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 $repeatFreq
- * @param int $subtract
+ * @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) {
diff --git a/app/routes.php b/app/routes.php
index 7288405638..b12d653354 100644
--- a/app/routes.php
+++ b/app/routes.php
@@ -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']);
diff --git a/app/views/list/journals-small.blade.php b/app/views/list/journals-small.blade.php
new file mode 100644
index 0000000000..31af0154ff
--- /dev/null
+++ b/app/views/list/journals-small.blade.php
@@ -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>
\ No newline at end of file
diff --git a/app/views/reports/index.blade.php b/app/views/reports/index.blade.php
index bf37aa61e3..8a0e83fe81 100644
--- a/app/views/reports/index.blade.php
+++ b/app/views/reports/index.blade.php
@@ -16,33 +16,20 @@
</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
- </div>
- <div class="panel-body">
- <ul>
- @foreach($months as $month)
- <li><a href="#{{$month['year']}}-{{$month['month']}}">{{$month['formatted']}}</a></li>
- @endforeach
- </ul>
+
+ <div class="col-lg-4 col-md-4 col-sm-4">
+ <div class="panel panel-default">
+ <div class="panel-heading">
+ Monthly reports
+ </div>
+ <div class="panel-body">
+ <ul>
+ @foreach($months as $month)
+ <li><a href="{{route('reports.month',[$month['year'],$month['month']])}}">{{$month['formatted']}}</a></li>
+ @endforeach
+ </ul>
+ </div>
</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>
- @endforeach
- </ul>
- </div>
- </div>
- </div>
</div>
@stop
\ No newline at end of file
diff --git a/app/views/reports/month.blade.php b/app/views/reports/month.blade.php
new file mode 100644
index 0000000000..44ff3e529a
--- /dev/null
+++ b/app/views/reports/month.blade.php
@@ -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
\ No newline at end of file