Skip to content

Firefly III: a personal finances manager

Implemented the help.

James Colef2eae2fc9837
diff --git a/app/Http/Controllers/CurrencyController.php b/app/Http/Controllers/CurrencyController.php
index 6bb11e4d1e..53d4a6e0d5 100644
--- a/app/Http/Controllers/CurrencyController.php
+++ b/app/Http/Controllers/CurrencyController.php
@@ -8,6 +8,7 @@ use Preferences;
use Redirect;
use Session;
use View;
+use Cache;
/**
* Class CurrencyController
@@ -46,10 +47,8 @@ class CurrencyController extends Controller
*/
public function defaultCurrency(TransactionCurrency $currency)
{
- /** @var \FireflyIII\Shared\Preferences\Preferences $preferences */
- $preferences = App::make('FireflyIII\Shared\Preferences\Preferences');
- $currencyPreference = $preferences->get('currencyPreference', 'EUR');
+ $currencyPreference = Preferences::get('currencyPreference', 'EUR');
$currencyPreference->data = $currency->code;
$currencyPreference->save();
diff --git a/app/Http/Controllers/GoogleChartController.php b/app/Http/Controllers/GoogleChartController.php
index 8b2f389799..55e90b4979 100644
--- a/app/Http/Controllers/GoogleChartController.php
+++ b/app/Http/Controllers/GoogleChartController.php
@@ -10,19 +10,21 @@ use FireflyIII\Http\Requests;
use FireflyIII\Models\Account;
use FireflyIII\Models\Bill;
use FireflyIII\Models\Budget;
+use FireflyIII\Models\Category;
use FireflyIII\Models\LimitRepetition;
-use FireflyIII\Models\TransactionJournal;
+use FireflyIII\Models\PiggyBank;
use FireflyIII\Models\Transaction;
-use FireflyIII\Models\Category;
+use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use Grumpydictator\Gchart\GChart;
use Illuminate\Database\Query\Builder as QueryBuilder;
use Illuminate\Database\Query\JoinClause;
+use Navigation;
use Preferences;
use Response;
use Session;
+use DB;
use Steam;
-use Navigation;
/**
* Class GoogleChartController
@@ -33,93 +35,6 @@ class GoogleChartController extends Controller
{
- /**
- *
- * @param Category $category
- * @param $year
- *
- * @return \Illuminate\Http\JsonResponse
- */
- public function categoriesAndSpending(Category $category, $year, GChart $chart)
- {
- try {
- new Carbon('01-01-' . $year);
- } catch (Exception $e) {
- return view('error')->with('message', 'Invalid year.');
- }
-
- $chart->addColumn('Month', 'date');
- $chart->addColumn('Budgeted', 'number');
- $chart->addColumn('Spent', 'number');
-
- $start = new Carbon('01-01-' . $year);
- $end = clone $start;
- $end->endOfYear();
- while ($start <= $end) {
-
- $currentEnd = clone $start;
- $currentEnd->endOfMonth();
- $spent = floatval($category->transactionjournals()->before($end)->after($start)->lessThan(0)->sum('amount')) * -1;
- $budgeted = null;
-
- $chart->addRow(clone $start, $budgeted, $spent);
-
- $start->addMonth();
- }
-
-
- $chart->generate();
-
- return Response::json($chart->getData());
-
-
- }
-
- /**
- * @param Bill $bill
- *
- * @return \Illuminate\Http\JsonResponse
- */
- public function billOverview(Bill $bill, GChart $chart)
- {
-
- $chart->addColumn('Date', 'date');
- $chart->addColumn('Max amount', 'number');
- $chart->addColumn('Min amount', 'number');
- $chart->addColumn('Current entry', 'number');
-
- // get first transaction or today for start:
- $first = $bill->transactionjournals()->orderBy('date', 'ASC')->first();
- if ($first) {
- $start = $first->date;
- } else {
- $start = new Carbon;
- }
- $end = new Carbon;
- while ($start <= $end) {
- $result = $bill->transactionjournals()->before($end)->after($start)->first();
- if ($result) {
- /** @var Transaction $tr */
- foreach($result->transactions()->get() as $tr) {
- if(floatval($tr->amount) > 0) {
- $amount = floatval($tr->amount);
- }
- }
- } else {
- $amount = 0;
- }
- unset($result);
- $chart->addRow(clone $start, $bill->amount_max, $bill->amount_min, $amount);
- $start = Navigation::addPeriod($start, $bill->repeat_freq, 0);
- }
-
- $chart->generate();
-
- return Response::json($chart->getData());
-
- }
-
-
/**
* @param Account $account
* @param string $view
@@ -204,6 +119,45 @@ class GoogleChartController extends Controller
}
+ /**
+ * @param int $year
+ *
+ * @return $this|\Illuminate\Http\JsonResponse
+ */
+ public function allBudgetsAndSpending($year, GChart $chart, BudgetRepositoryInterface $repository)
+ {
+ try {
+ new Carbon('01-01-' . $year);
+ } catch (Exception $e) {
+ return view('error')->with('message', 'Invalid year.');
+ }
+ $budgets = Auth::user()->budgets()->get();
+ $budgets->sortBy('name');
+ $chart->addColumn('Month', 'date');
+ foreach ($budgets as $budget) {
+ $chart->addColumn($budget->name, 'number');
+ }
+ $start = Carbon::createFromDate(intval($year), 1, 1);
+ $end = clone $start;
+ $end->endOfYear();
+
+
+ while ($start <= $end) {
+ $row = [clone $start];
+ foreach ($budgets as $budget) {
+ $spent = $repository->spentInMonth($budget, $start);
+ $row[] = $spent;
+ }
+ $chart->addRowArray($row);
+ $start->addMonth();
+ }
+
+
+ $chart->generate();
+
+ return Response::json($chart->getData());
+
+ }
/**
* @param GChart $chart
@@ -312,6 +266,50 @@ class GoogleChartController extends Controller
}
+ /**
+ * @param Bill $bill
+ *
+ * @return \Illuminate\Http\JsonResponse
+ */
+ public function billOverview(Bill $bill, GChart $chart)
+ {
+
+ $chart->addColumn('Date', 'date');
+ $chart->addColumn('Max amount', 'number');
+ $chart->addColumn('Min amount', 'number');
+ $chart->addColumn('Current entry', 'number');
+
+ // get first transaction or today for start:
+ $first = $bill->transactionjournals()->orderBy('date', 'ASC')->first();
+ if ($first) {
+ $start = $first->date;
+ } else {
+ $start = new Carbon;
+ }
+ $end = new Carbon;
+ while ($start <= $end) {
+ $result = $bill->transactionjournals()->before($end)->after($start)->first();
+ if ($result) {
+ /** @var Transaction $tr */
+ foreach ($result->transactions()->get() as $tr) {
+ if (floatval($tr->amount) > 0) {
+ $amount = floatval($tr->amount);
+ }
+ }
+ } else {
+ $amount = 0;
+ }
+ unset($result);
+ $chart->addRow(clone $start, $bill->amount_max, $bill->amount_min, $amount);
+ $start = Navigation::addPeriod($start, $bill->repeat_freq, 0);
+ }
+
+ $chart->generate();
+
+ return Response::json($chart->getData());
+
+ }
+
/**
* @param GChart $chart
*
@@ -463,6 +461,70 @@ class GoogleChartController extends Controller
}
+ /**
+ *
+ * @param Category $category
+ * @param $year
+ *
+ * @return \Illuminate\Http\JsonResponse
+ */
+ public function categoriesAndSpending(Category $category, $year, GChart $chart)
+ {
+ try {
+ new Carbon('01-01-' . $year);
+ } catch (Exception $e) {
+ return view('error')->with('message', 'Invalid year.');
+ }
+
+ $chart->addColumn('Month', 'date');
+ $chart->addColumn('Budgeted', 'number');
+ $chart->addColumn('Spent', 'number');
+
+ $start = new Carbon('01-01-' . $year);
+ $end = clone $start;
+ $end->endOfYear();
+ while ($start <= $end) {
+
+ $currentEnd = clone $start;
+ $currentEnd->endOfMonth();
+ $spent = floatval($category->transactionjournals()->before($end)->after($start)->lessThan(0)->sum('amount')) * -1;
+ $budgeted = null;
+
+ $chart->addRow(clone $start, $budgeted, $spent);
+
+ $start->addMonth();
+ }
+
+
+ $chart->generate();
+
+ return Response::json($chart->getData());
+
+
+ }
+
+ /**
+ * @param PiggyBank $piggyBank
+ *
+ * @return \Illuminate\Http\JsonResponse
+ */
+ public function piggyBankHistory(PiggyBank $piggyBank, GChart $chart)
+ {
+ $chart->addColumn('Date', 'date');
+ $chart->addColumn('Balance', 'number');
+
+ $set = \DB::table('piggy_bank_events')->where('piggy_bank_id', $piggyBank->id)->groupBy('date')->get(['date', DB::Raw('SUM(`amount`) AS `sum`')]);
+
+ foreach ($set as $entry) {
+ $chart->addRow(new Carbon($entry->date), floatval($entry->sum));
+ }
+
+ $chart->generate();
+
+ return Response::json($chart->getData());
+
+ }
+
/**
*
* @param $year
@@ -570,45 +632,4 @@ class GoogleChartController extends Controller
}
- /**
- * @param int $year
- *
- * @return $this|\Illuminate\Http\JsonResponse
- */
- public function allBudgetsAndSpending($year, GChart $chart, BudgetRepositoryInterface $repository)
- {
- try {
- new Carbon('01-01-' . $year);
- } catch (Exception $e) {
- return view('error')->with('message', 'Invalid year.');
- }
- $budgets = Auth::user()->budgets()->get();
- $budgets->sortBy('name');
- $chart->addColumn('Month', 'date');
- foreach ($budgets as $budget) {
- $chart->addColumn($budget->name, 'number');
- }
- $start = Carbon::createFromDate(intval($year), 1, 1);
- $end = clone $start;
- $end->endOfYear();
-
-
- while ($start <= $end) {
- $row = [clone $start];
- foreach ($budgets as $budget) {
- $spent = $repository->spentInMonth($budget, $start);
- $row[] = $spent;
- }
- $chart->addRowArray($row);
- $start->addMonth();
- }
-
-
- $chart->generate();
-
- return Response::json($chart->getData());
-
- }
-
-
}
diff --git a/app/Http/Controllers/HelpController.php b/app/Http/Controllers/HelpController.php
new file mode 100644
index 0000000000..19457e4786
--- /dev/null
+++ b/app/Http/Controllers/HelpController.php
@@ -0,0 +1,94 @@
+<?php namespace FireflyIII\Http\Controllers;
+
+use ErrorException;
+use FireflyIII\Http\Requests;
+use FireflyIII\Http\Controllers\Controller;
+
+use Illuminate\Http\Request;
+use League\CommonMark\CommonMarkConverter;
+use Route;
+use Response;
+use Cache;
+
+/**
+ * Class HelpController
+ *
+ * @package FireflyIII\Http\Controllers
+ */
+class HelpController extends Controller {
+
+ /**
+ * @param $route
+ *
+ * @return \Illuminate\Http\JsonResponse
+ */
+ public function show($route)
+ {
+ $content = [
+ 'text' => '<p>There is no help for this route!</p>',
+ 'title' => 'Help',
+ ];
+
+ if (!Route::has($route)) {
+ \Log::error('No such route: ' . $route);
+
+ return Response::json($content);
+ }
+
+ if ($this->_inCache($route)) {
+ $content = [
+ 'text' => Cache::get('help.' . $route . '.text'),
+ 'title' => Cache::get('help.' . $route . '.title'),
+ ];
+
+ return Response::json($content);
+ }
+ $content = $this->_getFromGithub($route);
+
+
+ Cache::put('help.' . $route . '.text', $content['text'], 10080); // a week.
+ Cache::put('help.' . $route . '.title', $content['title'], 10080);
+
+ return Response::json($content);
+
+ }
+
+ /**
+ * @param $route
+ *
+ * @return bool
+ */
+ protected function _inCache($route)
+ {
+ return Cache::has('help.' . $route . '.title') && Cache::has('help.' . $route . '.text');
+ }
+
+ /**
+ * @param $route
+ *
+ * @return array
+ */
+ protected function _getFromGithub($route)
+ {
+ $uri = 'https://raw.githubusercontent.com/JC5/firefly-iii-help/master/' . e($route) . '.md';
+ $content = [
+ 'text' => '<p>There is no help for this route!</p>',
+ 'title' => $route,
+ ];
+ try {
+ $content['text'] = file_get_contents($uri);
+ } catch (ErrorException $e) {
+ \Log::error(trim($e->getMessage()));
+ }
+ if (strlen(trim($content['text'])) == 0) {
+ $content['text'] = '<p>There is no help for this route.</p>';
+ }
+ $converter = new CommonMarkConverter();
+ $content['text'] = $converter->convertToHtml($content['text']);
+
+ return $content;
+
+
+ }
+
+}
diff --git a/app/Http/routes.php b/app/Http/routes.php
index 1f3766d1cc..194cf1c7e3 100644
--- a/app/Http/routes.php
+++ b/app/Http/routes.php
@@ -162,17 +162,22 @@ Route::group(
Route::get('/chart/home/categories', ['uses' => 'GoogleChartController@allCategoriesHomeChart']);
Route::get('/chart/home/bills', ['uses' => 'GoogleChartController@billsOverview']);
Route::get('/chart/account/{account}/{view?}', ['uses' => 'GoogleChartController@accountBalanceChart']);
-
Route::get('/chart/budget/{budget}/spending/{year?}', ['uses' => 'GoogleChartController@budgetsAndSpending']);
Route::get('/chart/budgets/spending/{year?}', ['uses' => 'GoogleChartController@allBudgetsAndSpending']);
Route::get('/chart/budget/{budget}/{limitrepetition}', ['uses' => 'GoogleChartController@budgetLimitSpending']);
Route::get('/chart/category/{category}/spending/{year}', ['uses' => 'GoogleChartController@categoriesAndSpending']);
-
Route::get('/chart/reports/income-expenses/{year}', ['uses' => 'GoogleChartController@yearInExp']);
Route::get('/chart/reports/income-expenses-sum/{year}', ['uses' => 'GoogleChartController@yearInExpSum']);
Route::get('/chart/bills/{bill}', ['uses' => 'GoogleChartController@billOverview']);
- // JSON controller
+ /**
+ * Help Controller
+ */
+ Route::get('/help/{route}', ['uses' => 'HelpController@show', 'as' => 'help.show']);
+
+ /**
+ * JSON Controller
+ */
Route::get('/json/expense-accounts', ['uses' => 'JsonController@expenseAccounts', 'as' => 'json.expense-accounts']);
Route::get('/json/revenue-accounts', ['uses' => 'JsonController@revenueAccounts', 'as' => 'json.revenue-accounts']);
Route::get('/json/categories', ['uses' => 'JsonController@categories', 'as' => 'json.categories']);
@@ -181,7 +186,6 @@ Route::group(
/**
* Piggy Bank Controller
*/
- // piggy bank controller
Route::get('/piggy-banks', ['uses' => 'PiggyBankController@index', 'as' => 'piggy-banks.index']);
Route::get('/piggy-banks/add/{piggyBank}', ['uses' => 'PiggyBankController@add']); # add money
Route::get('/piggy-banks/remove/{piggyBank}', ['uses' => 'PiggyBankController@remove']); #remove money
diff --git a/composer.json b/composer.json
index ddf4b3c4db..59a4fbdd9c 100644
--- a/composer.json
+++ b/composer.json
@@ -23,11 +23,11 @@
"laravel/framework": "5.0.*",
"davejamesmiller/laravel-breadcrumbs": "~3.0",
"grumpydictator/gchart": "dev-master",
- "michelf/php-markdown": "@stable",
"watson/validating": "dev-master",
"doctrine/dbal": "~2.5",
"illuminate/html": "~5.0",
- "barryvdh/laravel-ide-helper": "~2.0"
+ "barryvdh/laravel-ide-helper": "~2.0",
+ "league/commonmark": "0.7.*"
},
"require-dev": {
diff --git a/composer.lock b/composer.lock
index af8bd1e0e1..1eba04d268 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
- "hash": "6399deca7bccfb38eaa5df996618bc4d",
+ "hash": "d78d46376975c1bfab9823b66a30ed5f",
"packages": [
{
"name": "barryvdh/laravel-ide-helper",
@@ -1136,6 +1136,65 @@
],
"time": "2015-02-20 16:22:21"
},
+ {
+ "name": "league/commonmark",
+ "version": "0.7.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/thephpleague/commonmark.git",
+ "reference": "5f5137889b2aec36f8a1009ebe8673dac45f004e"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/thephpleague/commonmark/zipball/5f5137889b2aec36f8a1009ebe8673dac45f004e",
+ "reference": "5f5137889b2aec36f8a1009ebe8673dac45f004e",
+ "shasum": ""
+ },
+ "require": {
+ "ext-mbstring": "*",
+ "php": ">=5.3.3"
+ },
+ "replace": {
+ "colinodell/commonmark-php": "*"
+ },
+ "require-dev": {
+ "erusev/parsedown": "~1.0",
+ "jgm/commonmark": "0.17",
+ "michelf/php-markdown": "~1.4",
+ "phpunit/phpunit": "~4.3"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "0.7-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "League\\CommonMark\\": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Colin O'Dell",
+ "email": "[email protected]",
+ "homepage": "http://www.colinodell.com",
+ "role": "Lead Developer"
+ }
+ ],
+ "description": "Markdown parser for PHP based on the CommonMark spec",
+ "homepage": "https://github.com/thephpleague/commonmark",
+ "keywords": [
+ "commonmark",
+ "markdown",
+ "parser"
+ ],
+ "time": "2015-02-16 23:59:27"
+ },
{
"name": "league/flysystem",
"version": "1.0.1",
@@ -1219,57 +1278,6 @@
],
"time": "2015-01-23 09:43:34"
},
- {
- "name": "michelf/php-markdown",
- "version": "1.4.1",
- "source": {
- "type": "git",
- "url": "https://github.com/michelf/php-markdown.git",
- "reference": "de9a19c7bf352d41cc99ed86c3c0ef17e87394b6"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/michelf/php-markdown/zipball/de9a19c7bf352d41cc99ed86c3c0ef17e87394b6",
- "reference": "de9a19c7bf352d41cc99ed86c3c0ef17e87394b6",
- "shasum": ""
- },
- "require": {
- "php": ">=5.3.0"
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-lib": "1.4.x-dev"
- }
- },
- "autoload": {
- "psr-0": {
- "Michelf": ""
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "BSD-3-Clause"
- ],
- "authors": [
- {
- "name": "Michel Fortin",
- "email": "[email protected]",
- "homepage": "http://michelf.ca/",
- "role": "Developer"
- },
- {
- "name": "John Gruber",
- "homepage": "http://daringfireball.net/"
- }
- ],
- "description": "PHP Markdown",
- "homepage": "http://michelf.ca/projects/php-markdown/",
- "keywords": [
- "markdown"
- ],
- "time": "2014-05-05 02:43:50"
- },
{
"name": "monolog/monolog",
"version": "1.12.0",
@@ -2633,25 +2641,25 @@
},
{
"name": "codeception/codeception",
- "version": "2.0.9",
+ "version": "2.0.11",
"source": {
"type": "git",
"url": "https://github.com/Codeception/Codeception.git",
- "reference": "0094191ac0d6e87821fba41de002103ebe79a279"
+ "reference": "9c7f23eff3e607225e9f43277c6d9cdb03d30b84"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/Codeception/Codeception/zipball/0094191ac0d6e87821fba41de002103ebe79a279",
- "reference": "0094191ac0d6e87821fba41de002103ebe79a279",
+ "url": "https://api.github.com/repos/Codeception/Codeception/zipball/9c7f23eff3e607225e9f43277c6d9cdb03d30b84",
+ "reference": "9c7f23eff3e607225e9f43277c6d9cdb03d30b84",
"shasum": ""
},
"require": {
"ext-json": "*",
"ext-mbstring": "*",
- "facebook/webdriver": "~0.4",
+ "facebook/webdriver": "~0.4|~0.5",
"guzzlehttp/guzzle": "~4.0|~5.0",
"php": ">=5.4.0",
- "phpunit/phpunit": "~4.0",
+ "phpunit/phpunit": "~4.5.0",
"symfony/browser-kit": "~2.4",
"symfony/console": "~2.4",
"symfony/css-selector": "~2.4",
@@ -2662,12 +2670,10 @@
},
"require-dev": {
"codeception/specify": "~0.3",
- "codegyre/robo-ci": "@dev",
"facebook/php-sdk": "~3.2",
- "flow/jsonpath": "~0.1",
+ "flow/jsonpath": "~0.2",
"monolog/monolog": "~1.8",
"pda/pheanstalk": "~2.0",
- "phpseclib/phpseclib": "~0.3.6",
"videlalvaro/php-amqplib": "~2.4"
},
"suggest": {
@@ -2711,7 +2717,7 @@
"functional testing",
"unit testing"
],
- "time": "2014-12-19 23:54:20"
+ "time": "2015-02-23 23:10:03"
},
{
"name": "codeception/phpbuiltinserver",
@@ -3275,48 +3281,6 @@
],
"time": "2014-10-12 19:18:40"
},
- {
- "name": "janhenkgerritsen/codeception-laravel5",
- "version": "1.0.11",
- "source": {
- "type": "git",
- "url": "https://github.com/janhenkgerritsen/codeception-laravel5.git",
- "reference": "b4aef07d548b6becfd54ebf909e1f49de1ca5392"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/janhenkgerritsen/codeception-laravel5/zipball/b4aef07d548b6becfd54ebf909e1f49de1ca5392",
- "reference": "b4aef07d548b6becfd54ebf909e1f49de1ca5392",
- "shasum": ""
- },
- "require": {
- "codeception/codeception": "~2.0",
- "php": ">=5.4.0"
- },
- "type": "library",
- "autoload": {
- "psr-0": {
- "Codeception": "src"
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Jan-Henk Gerritsen",
- "email": "[email protected]"
- }
- ],
- "description": "Laravel5 module for Codeception",
- "keywords": [
- "codeception",
- "laravel",
- "laravel5"
- ],
- "time": "2015-02-14 11:20:37"
- },
{
"name": "league/factory-muffin",
"version": "v2.1.1",
@@ -4805,7 +4769,6 @@
"minimum-stability": "stable",
"stability-flags": {
"grumpydictator/gchart": 20,
- "michelf/php-markdown": 0,
"watson/validating": 20,
"barryvdh/laravel-debugbar": 0,
"codeception/codeception": 0,