From 290f25f1a07c28a78ae933a59553f6aa994c1089 Mon Sep 17 00:00:00 2001 From: James Cole Date: Thu, 25 Dec 2014 09:50:01 +0100 Subject: [PATCH] First attempt at new month report. --- app/controllers/ReportController.php | 32 ++++++++- .../2014_12_24_191544_changes_for_v322.php | 11 ++- app/lib/FireflyIII/Report/Report.php | 31 +++++++- app/lib/FireflyIII/Report/ReportInterface.php | 8 +++ app/lib/FireflyIII/Shared/Toolkit/Date.php | 53 +++++++------- app/routes.php | 3 +- app/views/list/journals-small.blade.php | 31 ++++++++ app/views/reports/index.blade.php | 39 ++++------- app/views/reports/month.blade.php | 70 +++++++++++++++++++ 9 files changed, 221 insertions(+), 57 deletions(-) create mode 100644 app/views/list/journals-small.blade.php create mode 100644 app/views/reports/month.blade.php 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 @@ + + @foreach($journals as $journal) + + + + + + + + @endforeach +
+ {{{$journal->description}}} + + @if($journal->transactiontype->type == 'Withdrawal') + {{mf($journal->transactions[1]->amount,false)}} + @endif + @if($journal->transactiontype->type == 'Deposit') + {{mf($journal->transactions[1]->amount,false)}} + @endif + @if($journal->transactiontype->type == 'Transfer') + {{mf($journal->transactions[1]->amount,false)}} + @endif + + {{$journal->date->format('j F Y')}} + + @if($journal->transactions[1]->account->accounttype->description == 'Cash account') + (cash) + @else + {{{$journal->transactions[1]->account->name}}} + @endif +
\ 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 @@ -
-
-
- Budget reports -
-
- + +
+
+
+ Monthly reports +
+
+ +
-
-
-
-
- Unbalanced transactions -
-
- -
-
-
@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()) }} +
+
+
+
Income
+ @include('list.journals-small',['journals' => $income]) +
+
+
+
+
Expenses (top 10)
+
Body
+
+
+
+
+
+
+
Budgets
+
Body
+
+
+
+
+
Categories
+
Body
+
+
+
+
+
+
+
Accounts
+
Body
+
+
+
+
+
+
+
Piggy banks
+
Body
+
+
+
+
+
Repeated expenses
+
Body
+
+
+
+
+
+
+
Recurring transactions
+
Body
+
+
+
+
+
+
+
Outside of budgets
+
Body
+
+
+
+@stop \ No newline at end of file