Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Some new code + GA
James Colee11e53913a17
diff --git a/.env.example b/.env.exampleindex 07b13be62b..fdf834d3ef 100644--- a/.env.example+++ b/.env.example@@ -14,3 +14,4 @@ SESSION_DRIVER=fileEMAIL_SMTP=EMAIL_USERNAME=EMAIL_PASSWORD=+ANALYTICS_ID=\ No newline at end of filediff --git a/README.md b/README.mdindex 2d54514d55..294aa07bd1 100644--- a/README.md+++ b/README.md@@ -5,7 +5,8 @@ Firefly III (v3.3.5)[](http://stillmaintained.com/JC5/firefly-iii)[](https://insight.sensiolabs.com/projects/d44c7012-5f50-41ad-add8-8445330e4102)[](https://codeclimate.com/github/JC5/firefly-iii)-[](https://codeclimate.com/github/JC5/firefly-iii)+[](https://coveralls.io/r/JC5/firefly-iii?branch=master)+[](https://coveralls.io/r/JC5/firefly-iii?branch=develop)[](https://packagist.org/packages/grumpydictator/firefly-iii)[](https://packagist.org/packages/grumpydictator/firefly-iii)diff --git a/app/Http/Middleware/PiggyBanks.php b/app/Http/Middleware/PiggyBanks.phpindex 35b90281a0..0854d338a8 100644--- a/app/Http/Middleware/PiggyBanks.php+++ b/app/Http/Middleware/PiggyBanks.php@@ -13,7 +13,7 @@ use Illuminate\Http\Request;use Illuminate\Support\Collection;use Navigation;use Session;-+use App;/*** Class PiggyBanks@@ -50,7 +50,7 @@ class PiggyBanks*/public function handle(Request $request, Closure $next){- if ($this->auth->check() && !$request->isXmlHttpRequest()) {+ if ($this->auth->check() && !$request->isXmlHttpRequest() && App::environment() != 'testing') {// get piggy banks without a repetition:/** @var Collection $set */$set = $this->auth->user()->piggybanks()diff --git a/app/Http/Middleware/Range.php b/app/Http/Middleware/Range.phpindex 7a5f212bc5..b26daf51b2 100644--- a/app/Http/Middleware/Range.php+++ b/app/Http/Middleware/Range.php@@ -3,6 +3,7 @@namespace FireflyIII\Http\Middleware;+use App;use Carbon\Carbon;use Closure;use Illuminate\Contracts\Auth\Guard;@@ -47,14 +48,14 @@ class Range*/public function handle(Request $request, Closure $theNext){- if ($this->auth->check()) {+ if ($this->auth->check() && App::environment() != 'testing') {// ignore preference. set the range to be the current month:if (!Session::has('start') && !Session::has('end')) {/** @var \FireflyIII\Models\Preference $viewRange */$viewRange = Preferences::get('viewRange', '1M');- $start = Session::has('start') ? Session::get('start') : new Carbon;+ $start = new Carbon;$start = Navigation::updateStartDate($viewRange->data, $start);$end = Navigation::updateEndDate($viewRange->data, $start);@@ -62,7 +63,12 @@ class RangeSession::put('end', $end);}if (!Session::has('first')) {- $journal = $this->auth->user()->transactionjournals()->orderBy('date', 'ASC')->first(['transaction_journals.*']);+ /**+ * Get helper thing.+ */+ /** @var \FireflyIII\Repositories\Journal\JournalRepositoryInterface $repository */+ $repository = App::make('FireflyIII\Repositories\Journal\JournalRepositoryInterface');+ $journal = $repository->first();if ($journal) {Session::put('first', $journal->date);} else {diff --git a/app/Http/Middleware/Reminders.php b/app/Http/Middleware/Reminders.phpindex 55c555aec0..457e4e2543 100644--- a/app/Http/Middleware/Reminders.php+++ b/app/Http/Middleware/Reminders.php@@ -46,7 +46,7 @@ class Reminders*/public function handle(Request $request, Closure $next){- if ($this->auth->check() && !$request->isXmlHttpRequest()) {+ if ($this->auth->check() && !$request->isXmlHttpRequest() && App::environment() != 'testing') {// do reminders stuff.$piggyBanks = $this->auth->user()->piggyBanks()->where('remind_me', 1)->get();$today = new Carbon;diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.phpindex 92215550dd..9fc94b9bdf 100644--- a/app/Repositories/Account/AccountRepository.php+++ b/app/Repositories/Account/AccountRepository.php@@ -133,8 +133,8 @@ class AccountRepository implements AccountRepositoryInterface->where('account_meta.name', 'accountRole')->where('account_meta.data', '"savingAsset"')->get(['accounts.*']);- $start = clone Session::get('start');- $end = clone Session::get('end');+ $start = clone Session::get('start', new Carbon);+ $end = clone Session::get('end', new Carbon);$accounts->each(function (Account $account) use ($start, $end) {diff --git a/app/Repositories/Journal/JournalRepository.php b/app/Repositories/Journal/JournalRepository.phpindex e89e631406..1c726ae6dc 100644--- a/app/Repositories/Journal/JournalRepository.php+++ b/app/Repositories/Journal/JournalRepository.php@@ -264,4 +264,12 @@ class JournalRepository implements JournalRepositoryInterfacereturn [$from, $to];}-}+ /**+ * Get users first transaction journal+ *+ * @return TransactionJournal+ */+ public function first()+ {+ return Auth::user()->transactionjournals()->orderBy('date', 'ASC')->first(['transaction_journals.*']);+ }}diff --git a/app/Repositories/Journal/JournalRepositoryInterface.php b/app/Repositories/Journal/JournalRepositoryInterface.phpindex cf10d0e557..5e89501790 100644--- a/app/Repositories/Journal/JournalRepositoryInterface.php+++ b/app/Repositories/Journal/JournalRepositoryInterface.php@@ -44,4 +44,10 @@ interface JournalRepositoryInterface* @return mixed*/public function update(TransactionJournal $journal, array $data);++ /**+ * Get users first transaction journal+ * @return TransactionJournal+ */+ public function first();}diff --git a/database/migrations/2014_12_13_190730_changes_for_v321.php b/database/migrations/2014_12_13_190730_changes_for_v321.phpindex 9b4c82db98..b381e774ab 100644--- a/database/migrations/2014_12_13_190730_changes_for_v321.php+++ b/database/migrations/2014_12_13_190730_changes_for_v321.php@@ -7,7 +7,6 @@ use FireflyIII\Models\Component;use Illuminate\Database\Migrations\Migration;use Illuminate\Database\Schema\Blueprint;use Illuminate\Support\Facades\Schema;-/*** @SuppressWarnings(PHPMD.ShortMethodName) // method names are mandated by laravel.* @SuppressWarnings("TooManyMethods") // I'm fine with this@@ -427,28 +426,28 @@ class ChangesForV321 extends Migrationpublic function moveComponentIdToBudgetId(){- \Log::debug('Now in moveComponentIdToBudgetId()');+ //Log::debug('Now in moveComponentIdToBudgetId()');BudgetLimit::get()->each(function (BudgetLimit $bl) {- \Log::debug('Now at budgetLimit #' . $bl->id . ' with component_id: ' . $bl->component_id);+ Log::debug('Now at budgetLimit #' . $bl->id . ' with component_id: ' . $bl->component_id);$component = Component::find($bl->component_id);if ($component) {- \Log::debug('Found component with id #' . $component->id . ' and name ' . $component->name);+ Log::debug('Found component with id #' . $component->id . ' and name ' . $component->name);$budget = Budget::whereName($component->name)->whereUserId($component->user_id)->first();if ($budget) {- \Log::debug('Found a budget with ID #' . $budget->id . ' and name ' . $budget->name);+ Log::debug('Found a budget with ID #' . $budget->id . ' and name ' . $budget->name);$bl->budget_id = $budget->id;$bl->save();- \Log::debug('Connected budgetLimit #' . $bl->id . ' to budget_id' . $budget->id);+ Log::debug('Connected budgetLimit #' . $bl->id . ' to budget_id' . $budget->id);} else {- \Log::debug('Could not find a matching budget with name ' . $component->name);+ Log::debug('Could not find a matching budget with name ' . $component->name);}} else {- \Log::debug('Could not find a component with id ' . $bl->component_id);+ Log::debug('Could not find a component with id ' . $bl->component_id);}});- \Log::debug('Done with moveComponentIdToBudgetId()');+ //Log::debug('Done with moveComponentIdToBudgetId()');}diff --git a/resources/views/layouts/default.blade.php b/resources/views/layouts/default.blade.phpindex 685112e0ae..e0c8eea327 100644--- a/resources/views/layouts/default.blade.php+++ b/resources/views/layouts/default.blade.php@@ -121,19 +121,31 @@<script type="text/javascript" src="js/daterangepicker.js"></script><script type="text/javascript">- var start = "{{Session::get('start')->format('d-m-Y')}}";- var end = "{{Session::get('end')->format('d-m-Y')}}";- var titleString = "{{Session::get('start')->format('j M Y')}} - {{Session::get('end')->format('j M Y')}}";+ var start = "{{Session::get('start', new Carbon\Carbon)->format('d-m-Y')}}";+ var end = "{{Session::get('end', new Carbon\Carbon)->format('d-m-Y')}}";+ var titleString = "{{Session::get('start', new Carbon\Carbon)->format('j M Y')}} - {{Session::get('end', new Carbon\Carbon)->format('j M Y')}}";var dateRangeURL = "{{route('daterange')}}";var token = "{{csrf_token()}}";- var firstDate = moment("{{Session::get('first')->format('Y-m-d')}}");- var currentMonthName = "{{$currentMonthName}}";- var previousMonthName = "{{$previousMonthName}}";- var nextMonthName = "{{$nextMonthName}}";+ var firstDate = moment("{{Session::get('first', new Carbon\Carbon)->format('Y-m-d')}}");+ var currentMonthName = "{{isset($currentMonthName) ? $currentMonthName : 'Month'}}";+ var previousMonthName = "{{isset($previousMonthName) ? $previousMonthName : 'Month'}}";+ var nextMonthName = "{{isset($nextMonthName) ? $nextMonthName : 'Month'}}";$('#daterange span').text(titleString);</script><script type="text/javascript" src="js/firefly.js"></script>@yield('scripts')+++<script>+ (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){+ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),+ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)+ })(window,document,'script','//www.google-analytics.com/analytics.js','ga');++ ga('create', '<?php echo env('ANALYTICS_ID', 'XXX-XX-X'); ?>', 'auto');+ ga('send', 'pageview');++</script></body></html>diff --git a/resources/views/partials/menu.blade.php b/resources/views/partials/menu.blade.phpindex 740dab2346..29a371045d 100644--- a/resources/views/partials/menu.blade.php+++ b/resources/views/partials/menu.blade.php@@ -18,7 +18,7 @@<ul class="nav navbar-top-links navbar-right"><!-- reminders -->- @if($reminders->count() > 0)+ @if(isset($reminders) && $reminders->count() > 0)<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#" aria-expanded="false"><i class="fa fa-envelope fa-fw"></i> <i class="fa fa-caret-down"></i>diff --git a/tests/TestCase.php b/tests/TestCase.phpindex 971e451ea7..00a3c124e7 100644--- a/tests/TestCase.php+++ b/tests/TestCase.php@@ -1,5 +1,4 @@<?php-/*** Class TestCase*/@@ -20,4 +19,18 @@ class TestCase extends Illuminate\Foundation\Testing\TestCasereturn $app;}+ /**+ * @param string $class+ *+ * @return mixed+ */+ public function mock($class)+ {+ $mock = Mockery::mock($class);++ $this->app->instance($class, $mock);++ return $mock;+ }+}diff --git a/tests/controllers/AccountControllerTest.php b/tests/controllers/AccountControllerTest.phpindex 02b96a43a6..f16fb238ec 100644--- a/tests/controllers/AccountControllerTest.php+++ b/tests/controllers/AccountControllerTest.php@@ -1,4 +1,5 @@<?php+use FireflyIII\Models\Preference;/*** Generated by PHPUnit_SkeletonGenerator on 2015-03-08 at 20:05:14.@@ -30,8 +31,17 @@ class AccountControllerTest extends TestCasepublic function testCreate(){$this->be(new FireflyIII\User);++ $pref = new Preference;+ $pref->data = '1M';++ Preferences::shouldReceive('get', 'viewRange')->andReturn($pref);+ Amount::shouldReceive('getDefaultCurrency')->andReturn(null);+$response = $this->call('GET', '/accounts/create/asset');$this->assertResponseOk();++$this->assertViewHas('subTitle', 'Create a new asset account');$this->assertViewHas('subTitleIcon', 'fa-money');$this->assertViewHas('what', 'asset');