Skip to content

Firefly III: a personal finances manager

All new stufs!

Sander Dorigo2f9c3830041b
diff --git a/app/config/app.php b/app/config/app.php
index 66190ce4e2..b997979dd7 100644
--- a/app/config/app.php
+++ b/app/config/app.php
@@ -43,7 +43,7 @@ return [
'Firefly\Helper\HelperServiceProvider',
'Firefly\Validation\ValidationServiceProvider',
'DaveJamesMiller\Breadcrumbs\ServiceProvider',
- 'TwigBridge\ServiceProvider'
+ 'Grumpydictator\Gchart\GchartServiceProvider',
],
'manifest' => storage_path() . '/meta',
'aliases' => [
diff --git a/app/controllers/GoogleChartController.php b/app/controllers/GoogleChartController.php
index ce36712823..c4e5ab89d8 100644
--- a/app/controllers/GoogleChartController.php
+++ b/app/controllers/GoogleChartController.php
@@ -1,8 +1,263 @@
<?php
+use Carbon\Carbon;
/**
* Class GoogleChartController
*/
-class GoogleChartController extends BaseController {
+class GoogleChartController extends BaseController
+{
+ /**
+ * This method renders the b
+ */
+ public function allAccountsBalanceChart()
+ {
+ /** @var \Grumpydictator\Gchart\GChart $chart */
+ $chart = App::make('gchart');
+ $chart->addColumn('Day of the month', 'date');
+
+ /** @var \FireflyIII\Shared\Preferences\Preferences $preferences */
+ $preferences = App::make('FireflyIII\Shared\Preferences\Preferences');
+ $pref = $preferences->get('frontpageAccounts');
+
+ /** @var \FireflyIII\Database\Account $acct */
+ $acct = App::make('FireflyIII\Database\Account');
+ $accounts = $acct->getByIds($pref->data);
+
+
+ /*
+ * Add a column for each account.
+ */
+ /** @var Account $account */
+ foreach ($accounts as $account) {
+ $chart->addColumn('Balance for ' . $account->name, 'number');
+ }
+ /*
+ * Loop the date, then loop the accounts, then add balance.
+ */
+ $start = Session::get('start');
+ $end = Session::get('end');
+ $current = clone $start;
+
+ while ($end >= $current) {
+ $row = [clone $current];
+
+ foreach ($accounts as $account) {
+ if ($current > Carbon::now()) {
+ $row[] = null;
+ } else {
+ $row[] = $account->balance($current);
+ }
+
+ }
+
+ $chart->addRowArray($row);
+ $current->addDay();
+ }
+
+ $chart->generate();
+ return Response::json($chart->getData());
+
+ }
+
+ /**
+ * @return \Illuminate\Http\JsonResponse
+ */
+ public function allBudgetsHomeChart()
+ {
+ /** @var \Grumpydictator\Gchart\GChart $chart */
+ $chart = App::make('gchart');
+ $chart->addColumn('Budget', 'string');
+ $chart->addColumn('Budgeted', 'number');
+ $chart->addColumn('Spent', 'number');
+
+ /** @var \FireflyIII\Database\Budget $bdt */
+ $bdt = App::make('FireflyIII\Database\Budget');
+ $budgets = $bdt->get();
+
+ /*
+ * Loop budgets:
+ */
+ /** @var Budget $budget */
+ foreach ($budgets as $budget) {
+
+ /*
+ * Is there a repetition starting on this particular date? We can use that.
+ */
+ /** @var \LimitRepetition $repetition */
+ $repetition = $bdt->repetitionOnStartingOnDate($budget, Session::get('start'));
+
+ /*
+ * If there is, use it. Otherwise, forget it.
+ */
+ if (is_null($repetition)) {
+ // use the session start and end for our search query
+ $searchStart = Session::get('start');
+ $searchEnd = Session::get('end');
+ // the limit is zero:
+ $limit = 0;
+
+ } else {
+ // use the limit's start and end for our search query
+ $searchStart = $repetition->startdate;
+ $searchEnd = $repetition->enddate;
+ // the limit is the repetitions limit:
+ $limit = floatval($repetition->amount);
+ }
+
+ /*
+ * No matter the result of the search for the repetition, get all the transactions associated
+ * with the budget, and sum up the expenses made.
+ */
+ $expenses = floatval($budget->transactionjournals()->before($searchEnd)->after($searchStart)->lessThan(0)->sum('amount')) * -1;
+ if ($expenses > 0) {
+ $chart->addRow($budget->name, $limit, $expenses);
+ }
+ }
+
+ /*
+ * Finally, get all transactions WITHOUT a budget and add those as well.
+ * (yes this method is oddly specific).
+ */
+ $noBudgetSet = $bdt->transactionsWithoutBudgetInDateRange(Session::get('start'), Session::get('end'));
+ $sum = $noBudgetSet->sum('amount') * -1;
+ $chart->addRow('No budget', 0, $sum);
+
+
+ $chart->generate();
+ return Response::json($chart->getData());
+ }
+
+ /**
+ * @return \Illuminate\Http\JsonResponse
+ */
+ public function allCategoriesHomeChart()
+ {
+ $data = [];
+
+ /** @var \Grumpydictator\Gchart\GChart $chart */
+ $chart = App::make('gchart');
+ $chart->addColumn('Category', 'string');
+ $chart->addColumn('Spent', 'number');
+
+ /** @var \FireflyIII\Database\TransactionJournal $tj */
+ $tj = App::make('FireflyIII\Database\TransactionJournal');
+
+ /*
+ * Get the journals:
+ */
+ $journals = $tj->getInDateRange(Session::get('start'), Session::get('end'));
+
+ /** @var \TransactionJournal $journal */
+ foreach ($journals as $journal) {
+ if ($journal->transactionType->type == 'Withdrawal') {
+ $amount = floatval($journal->transactions[1]->amount);
+ $amount = $amount < 0 ? $amount * -1 : $amount;
+ $category = $journal->categories()->first();
+ if (!is_null($category)) {
+ if (isset($data[$category->name])) {
+ $data[$category->name] += $amount;
+ } else {
+ $data[$category->name] = $amount;
+ }
+ }
+ }
+ }
+ arsort($data);
+ foreach ($data as $key => $entry) {
+ $chart->addRow($key, $entry);
+ }
+
+
+ $chart->generate();
+ return Response::json($chart->getData());
+
+ }
+
+ public function recurringTransactionsOverview()
+ {
+
+ /*
+ * Set of paid transaction journals.
+ * Set of unpaid recurring transactions.
+ */
+ $paid = [
+ 'items' => [],
+ 'amount' => 0
+ ];
+ $unpaid = [
+ 'items' => [],
+ 'amount' => 0
+ ];
+
+ /** @var \Grumpydictator\Gchart\GChart $chart */
+ $chart = App::make('gchart');
+ $chart->addColumn('Name', 'string');
+ $chart->addColumn('Amount', 'number');
+
+ /** @var \FireflyIII\Database\Recurring $rcr */
+ $rcr = App::make('FireflyIII\Database\Recurring');
+
+ /** @var \FireflyIII\Shared\Toolkit\Date $dateKit */
+ $dateKit = App::make('FireflyIII\Shared\Toolkit\Date');
+
+ $recurring = $rcr->get();
+
+ /** @var \RecurringTransaction $entry */
+ foreach ($recurring as $entry) {
+ /*
+ * Start another loop starting at the $date.
+ */
+ $start = clone $entry->date;
+ $end = Carbon::now();
+
+ /*
+ * The jump we make depends on the $repeat_freq
+ */
+ $current = clone $start;
+
+ while ($current <= $end) {
+ /*
+ * Get end of period for $current:
+ */
+ $currentEnd = clone $current;
+ $dateKit->endOfPeriod($currentEnd, $entry->repeat_freq);
+
+ /*
+ * In the current session range?
+ */
+ if (\Session::get('end') >= $current and $currentEnd >= \Session::get('start')) {
+ /*
+ * Lets see if we've already spent money on this recurring transaction (it hath recurred).
+ */
+ /** @var TransactionJournal $set */
+ $journal = $rcr->getJournalForRecurringInRange($entry, $current, $currentEnd);
+
+ if (is_null($journal)) {
+ $unpaid['items'][] = $entry->name;
+ $unpaid['amount'] += (($entry->amount_max + $entry->amount_min) / 2);
+ } else {
+ $amount = floatval($journal->transactions[0]->amount);
+ $amount = $amount < 0 ? $amount * -1 : $amount;
+ $paid['items'][] = $journal->description;
+ $paid['amount'] += $amount;
+ }
+ }
+
+ /*
+ * Add some time for the next loop!
+ */
+ $dateKit->addPeriod($current, $entry->repeat_freq, intval($entry->skip));
+
+ }
+
+ }
+ /** @var \RecurringTransaction $entry */
+ $chart->addRow('Unpaid: ' . join(', ', $unpaid['items']), $unpaid['amount']);
+ $chart->addRow('Paid: ' . join(', ', $paid['items']), $paid['amount']);
+
+ $chart->generate();
+ return Response::json($chart->getData());
+
+ }
}
\ No newline at end of file
diff --git a/app/lib/FireflyIII/Database/Account.php b/app/lib/FireflyIII/Database/Account.php
index 70eac86228..09bfa73dc0 100644
--- a/app/lib/FireflyIII/Database/Account.php
+++ b/app/lib/FireflyIII/Database/Account.php
@@ -16,6 +16,9 @@ class Account implements CUD, CommonDatabaseCalls, AccountInterface
{
use SwitchUser;
+ /**
+ *
+ */
public function __construct()
{
$this->setUser(\Auth::user());
@@ -423,4 +426,14 @@ class Account implements CUD, CommonDatabaseCalls, AccountInterface
{
// TODO: Implement findByWhat() method.
}
+
+ /**
+ * @param array $ids
+ *
+ * @return Collection
+ */
+ public function getByIds(array $ids)
+ {
+ return $this->getUser()->accounts()->whereIn('id', $ids)->get();
+ }
}
\ No newline at end of file
diff --git a/app/lib/FireflyIII/Database/Budget.php b/app/lib/FireflyIII/Database/Budget.php
new file mode 100644
index 0000000000..aa7ef4c94c
--- /dev/null
+++ b/app/lib/FireflyIII/Database/Budget.php
@@ -0,0 +1,155 @@
+<?php
+namespace FireflyIII\Database;
+
+use Carbon\Carbon;
+use Illuminate\Support\MessageBag;
+use LaravelBook\Ardent\Ardent;
+use Illuminate\Support\Collection;
+
+/**
+ * Class Budget
+ *
+ * @package FireflyIII\Database
+ */
+class Budget implements CUD, CommonDatabaseCalls, BudgetInterface
+{
+ use SwitchUser;
+
+ /**
+ *
+ */
+ public function __construct()
+ {
+ $this->setUser(\Auth::user());
+ }
+
+ /**
+ * @param \Budget $budget
+ * @param Carbon $date
+ *
+ * @return \LimitRepetition|null
+ */
+ public function repetitionOnStartingOnDate(\Budget $budget, Carbon $date)
+ {
+ return \LimitRepetition::
+ leftJoin('limits', 'limit_repetitions.limit_id', '=', 'limits.id')->leftJoin(
+ 'components', 'limits.component_id', '=', 'components.id'
+ )->where('limit_repetitions.startdate', $date->format('Y-m-d'))->where(
+ 'components.id', $budget->id
+ )->first(['limit_repetitions.*']);
+ }
+
+ /**
+ * @param Ardent $model
+ *
+ * @return bool
+ */
+ public function destroy(Ardent $model)
+ {
+ // TODO: Implement destroy() method.
+ }
+
+ /**
+ * Validates a model. Returns an array containing MessageBags
+ * errors/warnings/successes.
+ *
+ * @param Ardent $model
+ *
+ * @return array
+ */
+ public function validateObject(Ardent $model)
+ {
+ // TODO: Implement validateObject() method.
+ }
+
+ /**
+ * Validates an array. Returns an array containing MessageBags
+ * errors/warnings/successes.
+ *
+ * @param array $model
+ *
+ * @return array
+ */
+ public function validate(array $model)
+ {
+ // TODO: Implement validate() method.
+ }
+
+ /**
+ * @param array $data
+ *
+ * @return Ardent
+ */
+ public function store(array $data)
+ {
+ // TODO: Implement store() method.
+ }
+
+ /**
+ * Returns an object with id $id.
+ *
+ * @param int $id
+ *
+ * @return Ardent
+ */
+ public function find($id)
+ {
+ // TODO: Implement find() method.
+ }
+
+ /**
+ * Returns all objects.
+ *
+ * @return Collection
+ */
+ public function get()
+ {
+ return $this->getUser()->budgets()->get();
+ }
+
+ /**
+ * @param array $ids
+ *
+ * @return Collection
+ */
+ public function getByIds(array $ids)
+ {
+ // TODO: Implement getByIds() method.
+ }
+
+ /**
+ * Finds an account type using one of the "$what"'s: expense, asset, revenue, opening, etc.
+ *
+ * @param $what
+ *
+ * @return \AccountType|null
+ */
+ public function findByWhat($what)
+ {
+ // TODO: Implement findByWhat() method.
+ }
+
+ /**
+ * @param Carbon $start
+ * @param Carbon $end
+ *
+ * @return Collection
+ */
+ public function transactionsWithoutBudgetInDateRange(Carbon $start, Carbon $end)
+ {
+ // Add expenses that have no budget:
+ return \Auth::user()->transactionjournals()->whereNotIn(
+ 'transaction_journals.id', function ($query) use ($start, $end) {
+ $query->select('transaction_journals.id')->from('transaction_journals')
+ ->leftJoin(
+ 'component_transaction_journal', 'component_transaction_journal.transaction_journal_id', '=',
+ 'transaction_journals.id'
+ )
+ ->leftJoin('components', 'components.id', '=', 'component_transaction_journal.component_id')
+ ->where('transaction_journals.date', '>=', $start->format('Y-m-d'))
+ ->where('transaction_journals.date', '<=', $end->format('Y-m-d'))
+ ->where('components.class', 'Budget');
+ }
+ )->before($end)->after($start)->lessThan(0)->transactionTypes(['Withdrawal'])->get();
+ }
+}
\ No newline at end of file
diff --git a/app/lib/FireflyIII/Database/BudgetInterface.php b/app/lib/FireflyIII/Database/BudgetInterface.php
new file mode 100644
index 0000000000..ac38f77e7b
--- /dev/null
+++ b/app/lib/FireflyIII/Database/BudgetInterface.php
@@ -0,0 +1,31 @@
+<?php
+
+namespace FireflyIII\Database;
+
+use Carbon\Carbon;
+use Illuminate\Support\Collection;
+
+/**
+ * Interface BudgetInterface
+ *
+ * @package FireflyIII\Database
+ */
+interface BudgetInterface
+{
+ /**
+ * @param \Budget $budget
+ * @param Carbon $date
+ *
+ * @return \LimitRepetition|null
+ */
+ public function repetitionOnStartingOnDate(\Budget $budget, Carbon $date);
+
+ /**
+ * @param Carbon $start
+ * @param Carbon $end
+ *
+ * @return Collection
+ */
+ public function transactionsWithoutBudgetInDateRange(Carbon $start, Carbon $end);
+
+}
\ No newline at end of file
diff --git a/app/lib/FireflyIII/Database/Category.php b/app/lib/FireflyIII/Database/Category.php
new file mode 100644
index 0000000000..55031c4662
--- /dev/null
+++ b/app/lib/FireflyIII/Database/Category.php
@@ -0,0 +1,115 @@
+<?php
+namespace FireflyIII\Database;
+
+use Carbon\Carbon;
+use Illuminate\Support\MessageBag;
+use LaravelBook\Ardent\Ardent;
+use Illuminate\Support\Collection;
+
+/**
+ * Class Category
+ *
+ * @package FireflyIII\Database
+ */
+class Category implements CUD, CommonDatabaseCalls, CategoryInterface
+{
+ use SwitchUser;
+
+ /**
+ *
+ */
+ public function __construct()
+ {
+ $this->setUser(\Auth::user());
+ }
+
+ /**
+ * @param Ardent $model
+ *
+ * @return bool
+ */
+ public function destroy(Ardent $model)
+ {
+ // TODO: Implement destroy() method.
+ }
+
+ /**
+ * Validates a model. Returns an array containing MessageBags
+ * errors/warnings/successes.
+ *
+ * @param Ardent $model
+ *
+ * @return array
+ */
+ public function validateObject(Ardent $model)
+ {
+ // TODO: Implement validateObject() method.
+ }
+
+ /**
+ * Validates an array. Returns an array containing MessageBags
+ * errors/warnings/successes.
+ *
+ * @param array $model
+ *
+ * @return array
+ */
+ public function validate(array $model)
+ {
+ // TODO: Implement validate() method.
+ }
+
+ /**
+ * @param array $data
+ *
+ * @return Ardent
+ */
+ public function store(array $data)
+ {
+ // TODO: Implement store() method.
+ }
+
+ /**
+ * Returns an object with id $id.
+ *
+ * @param int $id
+ *
+ * @return Ardent
+ */
+ public function find($id)
+ {
+ // TODO: Implement find() method.
+ }
+
+ /**
+ * Returns all objects.
+ *
+ * @return Collection
+ */
+ public function get()
+ {
+ // TODO: Implement get() method.
+ }
+
+ /**
+ * @param array $ids
+ *
+ * @return Collection
+ */
+ public function getByIds(array $ids)
+ {
+ // TODO: Implement getByIds() method.
+ }
+
+ /**
+ * Finds an account type using one of the "$what"'s: expense, asset, revenue, opening, etc.
+ *
+ * @param $what
+ *
+ * @return \AccountType|null
+ */
+ public function findByWhat($what)
+ {
+ // TODO: Implement findByWhat() method.
+ }
+}
\ No newline at end of file
diff --git a/app/lib/FireflyIII/Database/CategoryInterface.php b/app/lib/FireflyIII/Database/CategoryInterface.php
new file mode 100644
index 0000000000..79dfcf343e
--- /dev/null
+++ b/app/lib/FireflyIII/Database/CategoryInterface.php
@@ -0,0 +1,16 @@
+<?php
+
+namespace FireflyIII\Database;
+
+use Carbon\Carbon;
+use Illuminate\Support\Collection;
+
+/**
+ * Interface CategoryInterface
+ *
+ * @package FireflyIII\Database
+ */
+interface CategoryInterface
+{
+
+}
\ No newline at end of file
diff --git a/app/lib/FireflyIII/Database/CommonDatabaseCalls.php b/app/lib/FireflyIII/Database/CommonDatabaseCalls.php
index 555feabdda..3ed907493b 100644
--- a/app/lib/FireflyIII/Database/CommonDatabaseCalls.php
+++ b/app/lib/FireflyIII/Database/CommonDatabaseCalls.php
@@ -35,6 +35,14 @@ interface CommonDatabaseCalls
*/
public function get();
+
+ /**
+ * @param array $ids
+ *
+ * @return Collection
+ */
+ public function getByIds(array $ids);
+
/**
* Finds an account type using one of the "$what"'s: expense, asset, revenue, opening, etc.
*
diff --git a/app/lib/FireflyIII/Database/Recurring.php b/app/lib/FireflyIII/Database/Recurring.php
new file mode 100644
index 0000000000..a87b094ba4
--- /dev/null
+++ b/app/lib/FireflyIII/Database/Recurring.php
@@ -0,0 +1,129 @@
+<?php
+
+namespace FireflyIII\Database;
+
+
+use Carbon\Carbon;
+use Illuminate\Support\Collection;
+use LaravelBook\Ardent\Ardent;
+
+/**
+ * Class Recurring
+ *
+ * @package FireflyIII\Database
+ */
+class Recurring implements CUD, CommonDatabaseCalls, RecurringInterface
+{
+ use SwitchUser;
+
+ /**
+ *
+ */
+ public function __construct()
+ {
+ $this->setUser(\Auth::user());
+ }
+
+ /**
+ * @param \RecurringTransaction $recurring
+ * @param Carbon $current
+ * @param Carbon $currentEnd
+ *
+ * @return \TransactionJournal|null
+ */
+ public function getJournalForRecurringInRange(\RecurringTransaction $recurring, Carbon $start, Carbon $end)
+ {
+ return $this->getUser()->transactionjournals()->where('recurring_transaction_id', $recurring->id)->after($start)->before($end)->first();
+
+ }
+
+ /**
+ * @param Ardent $model
+ *
+ * @return bool
+ */
+ public function destroy(Ardent $model)
+ {
+ // TODO: Implement destroy() method.
+ }
+
+ /**
+ * Validates a model. Returns an array containing MessageBags
+ * errors/warnings/successes.
+ *
+ * @param Ardent $model
+ *
+ * @return array
+ */
+ public function validateObject(Ardent $model)
+ {
+ // TODO: Implement validateObject() method.
+ }
+
+ /**
+ * Validates an array. Returns an array containing MessageBags
+ * errors/warnings/successes.
+ *
+ * @param array $model
+ *
+ * @return array
+ */
+ public function validate(array $model)
+ {
+ // TODO: Implement validate() method.
+ }
+
+ /**
+ * @param array $data
+ *
+ * @return Ardent
+ */
+ public function store(array $data)
+ {
+ // TODO: Implement store() method.
+ }
+
+ /**
+ * Returns an object with id $id.
+ *
+ * @param int $id
+ *
+ * @return Ardent
+ */
+ public function find($id)
+ {
+ // TODO: Implement find() method.
+ }
+
+ /**
+ * Returns all objects.
+ *
+ * @return Collection
+ */
+ public function get()
+ {
+ return $this->getUser()->recurringtransactions()->get();
+ }
+
+ /**
+ * @param array $ids
+ *
+ * @return Collection
+ */
+ public function getByIds(array $ids)
+ {
+ // TODO: Implement getByIds() method.
+ }
+
+ /**
+ * Finds an account type using one of the "$what"'s: expense, asset, revenue, opening, etc.
+ *
+ * @param $what
+ *
+ * @return \AccountType|null
+ */
+ public function findByWhat($what)
+ {
+ // TODO: Implement findByWhat() method.
+ }
+}
\ No newline at end of file
diff --git a/app/lib/FireflyIII/Database/RecurringInterface.php b/app/lib/FireflyIII/Database/RecurringInterface.php
new file mode 100644
index 0000000000..ed728ac9a0
--- /dev/null
+++ b/app/lib/FireflyIII/Database/RecurringInterface.php
@@ -0,0 +1,22 @@
+<?php
+
+namespace FireflyIII\Database;
+use Carbon\Carbon;
+
+/**
+ * Interface RecurringInterface
+ *
+ * @package FireflyIII\Database
+ */
+interface RecurringInterface
+{
+ /**
+ * @param \RecurringTransaction $recurring
+ * @param Carbon $current
+ * @param Carbon $currentEnd
+ *
+ * @return \TransactionJournal|null
+ */
+ public function getJournalForRecurringInRange(\RecurringTransaction $recurring, Carbon $start, Carbon $end);
+
+}
\ No newline at end of file
diff --git a/app/lib/FireflyIII/Database/TransactionJournal.php b/app/lib/FireflyIII/Database/TransactionJournal.php
index daa122ccde..690ddf5697 100644
--- a/app/lib/FireflyIII/Database/TransactionJournal.php
+++ b/app/lib/FireflyIII/Database/TransactionJournal.php
@@ -33,6 +33,17 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData
$this->setUser(\Auth::user());
}
+ /**
+ * @param Carbon $start
+ * @param Carbon $end
+ *
+ * @return Collection
+ */
+ public function getInDateRange(Carbon $start, Carbon $end)
+ {
+ return $this->getuser()->transactionjournals()->withRelevantData()->before($end)->after($start)->get();
+ }
+
/**
* @param Ardent $model
@@ -250,4 +261,14 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData
{
// TODO: Implement findByWhat() method.
}
+
+ /**
+ * @param array $ids
+ *
+ * @return Collection
+ */
+ public function getByIds(array $ids)
+ {
+ // TODO: Implement getByIds() method.
+ }
}
\ No newline at end of file
diff --git a/app/lib/FireflyIII/Database/TransactionJournalInterface.php b/app/lib/FireflyIII/Database/TransactionJournalInterface.php
index b791c06ad6..f08ed11891 100644
--- a/app/lib/FireflyIII/Database/TransactionJournalInterface.php
+++ b/app/lib/FireflyIII/Database/TransactionJournalInterface.php
@@ -7,6 +7,8 @@
*/
namespace FireflyIII\Database;
+use Carbon\Carbon;
+use Illuminate\Support\Collection;
/**
* Interface TransactionJournalInterface
@@ -15,5 +17,12 @@ namespace FireflyIII\Database;
*/
interface TransactionJournalInterface
{
+ /**
+ * @param Carbon $start
+ * @param Carbon $end
+ *
+ * @return Collection
+ */
+ public function getInDateRange(Carbon $start, Carbon $end);
}
\ No newline at end of file
diff --git a/app/lib/FireflyIII/Shared/Preferences/Preferences.php b/app/lib/FireflyIII/Shared/Preferences/Preferences.php
new file mode 100644
index 0000000000..0fa5bfda7a
--- /dev/null
+++ b/app/lib/FireflyIII/Shared/Preferences/Preferences.php
@@ -0,0 +1,58 @@
+<?php
+namespace FireflyIII\Shared\Preferences;
+/**
+ * Class PreferencesHelper
+ *
+ * @package Firefly\Helper\Preferences
+ */
+class Preferences implements PreferencesInterface
+{
+
+ /**
+ * @param $name
+ * @param null $default
+ *
+ * @return null|\Preference
+ */
+ public function get($name, $default = null)
+ {
+ $pref = \Preference::where('user_id', \Auth::user()->id)->where('name', $name)->first();
+ if (is_null($default) && is_null($pref)) {
+ // return NULL
+ return null;
+ }
+ if (!is_null($pref)) {
+ return $pref;
+ }
+ if (!is_null($default) && is_null($pref)) {
+ // create preference, return that:
+ return $this->set($name, $default);
+ }
+
+ return null;
+
+ }
+
+ /**
+ * @param $name
+ * @param $value
+ *
+ * @return \Preference
+ */
+ public function set($name, $value)
+ {
+ $pref = \Preference::where('user_id', \Auth::user()->id)->where('name', $name)->first();
+ if (is_null($pref)) {
+ $pref = new \Preference;
+ $pref->name = $name;
+ $pref->user()->associate(\Auth::user());
+
+ }
+ $pref->data = $value;
+ $pref->save();
+
+
+ return $pref;
+
+ }
+}
\ No newline at end of file
diff --git a/app/lib/FireflyIII/Shared/Preferences/PreferencesInterface.php b/app/lib/FireflyIII/Shared/Preferences/PreferencesInterface.php
new file mode 100644
index 0000000000..4e7389695f
--- /dev/null
+++ b/app/lib/FireflyIII/Shared/Preferences/PreferencesInterface.php
@@ -0,0 +1,29 @@
+<?php
+namespace FireflyIII\Shared\Preferences;
+
+/**
+ * Interface PreferencesHelperInterface
+ *
+ * @package Firefly\Helper\Preferences
+ */
+interface PreferencesInterface
+{
+
+
+ /**
+ * @param $name
+ * @param $value
+ *
+ * @return null|\Preference
+ */
+ public function set($name, $value);
+
+ /**
+ * @param $name
+ * @param null $default
+ *
+ * @return \Preference
+ */
+ public function get($name, $default = null);
+
+}
\ No newline at end of file
diff --git a/app/lib/FireflyIII/Shared/Toolkit/Date.php b/app/lib/FireflyIII/Shared/Toolkit/Date.php
new file mode 100644
index 0000000000..1abf90e321
--- /dev/null
+++ b/app/lib/FireflyIII/Shared/Toolkit/Date.php
@@ -0,0 +1,86 @@
+<?php
+
+namespace FireflyIII\Shared\Toolkit;
+
+use Carbon\Carbon;
+use Firefly\Exception\FireflyException;
+
+/**
+ * Class Date
+ *
+ * @package FireflyIII\Shared\Toolkit
+ */
+class Date
+{
+ /**
+ * @param Carbon $currentEnd
+ * @param $repeatFreq
+ *
+ * @throws FireflyException
+ */
+ public function endOfPeriod(Carbon $currentEnd, $repeatFreq)
+ {
+ switch ($repeatFreq) {
+ default:
+ throw new FireflyException('Cannot do endOfPeriod for $repeat_freq ' . $repeatFreq);
+ break;
+ case 'daily':
+ $currentEnd->addDay();
+ break;
+ case 'weekly':
+ $currentEnd->addWeek()->subDay();
+ break;
+ case 'monthly':
+ $currentEnd->addMonth()->subDay();
+ break;
+ case 'quarterly':
+ $currentEnd->addMonths(3)->subDay();
+ break;
+ case 'half-year':
+ $currentEnd->addMonths(6)->subDay();
+ break;
+ case 'yearly':
+ $currentEnd->addYear()->subDay();
+ break;
+ }
+ }
+
+ /**
+ * @param Carbon $date
+ * @param $repeatFreq
+ * @param $skip
+ *
+ * @return Carbon
+ * @throws FireflyException
+ */
+ public function addPeriod(Carbon $date, $repeatFreq, $skip)
+ {
+ $add = ($skip + 1);
+ switch ($repeatFreq) {
+ default:
+ throw new FireflyException('Cannot do addPeriod for $repeat_freq ' . $repeatFreq);
+ break;
+ case 'daily':
+ $date->addDays($add);
+ break;
+ case 'weekly':
+ $date->addWeeks($add);
+ break;
+ case 'monthly':
+ $date->addMonths($add);
+ break;
+ case 'quarterly':
+ $months = $add * 3;
+ $date->addMonths($months);
+ break;
+ case 'half-year':
+ $months = $add * 6;
+ $date->addMonths($months);
+ break;
+ case 'yearly':
+ $date->addYears($add);
+ break;
+ }
+ return $date;
+ }
+}
\ No newline at end of file
diff --git a/app/routes.php b/app/routes.php
index 22d86fa854..9eced9703c 100644
--- a/app/routes.php
+++ b/app/routes.php
@@ -162,12 +162,15 @@ Route::group(['before' => 'auth'], function () {
Route::get('/categories/delete/{category}',['uses' => 'CategoryController@delete','as' => 'categories.delete']);
// chart controller
- Route::get('/chart/home/account/{account?}', ['uses' => 'ChartController@homeAccount', 'as' => 'chart.home']);
- Route::get('/chart/home/categories', ['uses' => 'ChartController@homeCategories', 'as' => 'chart.categories']);
- Route::get('/chart/home/budgets', ['uses' => 'ChartController@homeBudgets', 'as' => 'chart.budgets']);
+ Route::get('/chart/home/account', ['uses' => 'GoogleChartController@allAccountsBalanceChart']);
+ Route::get('/chart/home/budgets', ['uses' => 'GoogleChartController@allBudgetsHomeChart']);
+ Route::get('/chart/home/categories', ['uses' => 'GoogleChartController@allCategoriesHomeChart']);
+ Route::get('/chart/home/recurring', ['uses' => 'GoogleChartController@recurringTransactionsOverview']);
+
+
Route::get('/chart/home/info/{accountnameA}/{day}/{month}/{year}', ['uses' => 'ChartController@homeAccountInfo', 'as' => 'chart.info']);
Route::get('/chart/categories/show/{category}', ['uses' => 'ChartController@categoryShowChart','as' => 'chart.showcategory']);
- Route::get('/chart/home/recurring', ['uses' => 'ChartController@homeRecurring', 'as' => 'chart.recurring']);
+
// (new charts for budgets)
Route::get('/chart/budget/{budget}/default', ['uses' => 'ChartController@budgetDefault', 'as' => 'chart.budget.default']);
Route::get('chart/budget/{budget}/no_envelope', ['uses' => 'ChartController@budgetNoLimits', 'as' => 'chart.budget.nolimit']);
diff --git a/public/assets/javascript/firefly/gcharts.js b/public/assets/javascript/firefly/gcharts.js
index f99b5e0620..998514d0f1 100644
--- a/public/assets/javascript/firefly/gcharts.js
+++ b/public/assets/javascript/firefly/gcharts.js
@@ -1,8 +1,5 @@
google.load('visualization', '1.0', {'packages': ['corechart']});
-/*
- If this method has not been defined (yet) it will error out.
- */
function googleLineChart(URL, container) {
$.getJSON(URL).success(function (data) {
/*
@@ -10,16 +7,114 @@ function googleLineChart(URL, container) {
*/
gdata = new google.visualization.DataTable(data);
+ /*
+ Format as money
+ */
+ var money = new google.visualization.NumberFormat({decimalSymbol: ',', groupingSymbol: '.', prefix: '\u20AC '});
+ for (i = 1; i < gdata.getNumberOfColumns(); i++) {
+ money.format(gdata, i);
+ }
+
/*
Create a new google charts object.
*/
var chart = new google.visualization.LineChart(document.getElementById(container));
/*
- Draw it:
+ Draw it:
*/
chart.draw(gdata, defaultLineChartOptions);
+ }).fail(function () {
+ $('#' + container).addClass('google-chart-error');
+ });
+}
+
+function googleBarChart(URL, container) {
+ $.getJSON(URL).success(function (data) {
+ /*
+ Get the data from the JSON
+ */
+ gdata = new google.visualization.DataTable(data);
+
+ /*
+ Format as money
+ */
+ var money = new google.visualization.NumberFormat({decimalSymbol: ',', groupingSymbol: '.', prefix: '\u20AC '});
+ for (i = 1; i < gdata.getNumberOfColumns(); i++) {
+ money.format(gdata, i);
+ }
+
+ /*
+ Create a new google charts object.
+ */
+ var chart = new google.visualization.BarChart(document.getElementById(container));
+
+ /*
+ Draw it:
+ */
+ chart.draw(gdata, defaultBarChartOptions);
+
+ }).fail(function () {
+ $('#' + container).addClass('google-chart-error');
+ });
+}
+
+function googleColumnChart(URL, container) {
+ $.getJSON(URL).success(function (data) {
+ /*
+ Get the data from the JSON
+ */
+ gdata = new google.visualization.DataTable(data);
+
+ /*
+ Format as money
+ */
+ var money = new google.visualization.NumberFormat({decimalSymbol: ',', groupingSymbol: '.', prefix: '\u20AC '});
+ for (i = 1; i < gdata.getNumberOfColumns(); i++) {
+ money.format(gdata, i);
+ }
+
+ /*
+ Create a new google charts object.
+ */
+ var chart = new google.visualization.ColumnChart(document.getElementById(container));
+
+ /*
+ Draw it:
+ */
+ chart.draw(gdata, defaultColumnChartOptions);
+
+ }).fail(function () {
+ $('#' + container).addClass('google-chart-error');
+ });
+}
+
+function googlePieChart(URL, container) {
+ $.getJSON(URL).success(function (data) {
+ /*
+ Get the data from the JSON
+ */
+ gdata = new google.visualization.DataTable(data);
+
+ /*
+ Format as money
+ */
+ var money = new google.visualization.NumberFormat({decimalSymbol: ',', groupingSymbol: '.', prefix: '\u20AC '});
+ for (i = 1; i < gdata.getNumberOfColumns(); i++) {
+ money.format(gdata, i);
+ }
+
+ /*
+ Create a new google charts object.
+ */
+ var chart = new google.visualization.PieChart(document.getElementById(container));
+
+ /*
+ Draw it:
+ */
+ chart.draw(gdata, defaultPieChartOptions);
+
}).fail(function () {
$('#' + container).addClass('google-chart-error');
});
diff --git a/public/assets/javascript/firefly/gcharts.options.js b/public/assets/javascript/firefly/gcharts.options.js
index 594d1e26ad..a038b286a8 100644
--- a/public/assets/javascript/firefly/gcharts.options.js
+++ b/public/assets/javascript/firefly/gcharts.options.js
@@ -1,3 +1,59 @@
var defaultLineChartOptions = {
+ curveType: 'function',
+ legend: {
+ position: 'none'
+ },
+ lineWidth: 1,
+ chartArea: {
+ left: 50,
+ top: 10,
+ width: '85%',
+ height: '80%'
+ },
+ height: 400,
+ vAxis: {format: '\u20AC #'}
+
+};
+
+var defaultBarChartOptions = {
+ height: 400,
+ hAxis: {format: '\u20AC #'},
+ chartArea: {
+ left: 75,
+ top: 10,
+ width: '100%',
+ height: '90%'
+ },
+
+ legend: {
+ position: 'none'
+ }
+};
+
+var defaultColumnChartOptions = {
+ height: 400,
+ chartArea: {
+ left: 50,
+ top: 10,
+ width: '85%',
+ height: '80%'
+ },
+ vAxis: {format: '\u20AC #'},
+ legend: {
+ position: 'none'
+ }
+};
+
+var defaultPieChartOptions = {
+ chartArea: {
+ left: 0,
+ top: 0,
+ width: '100%',
+ height: '100%'
+ },
+ height:200,
+ legend: {
+ position: 'none'
+ }
};
\ No newline at end of file
diff --git a/public/assets/javascript/firefly/index.js b/public/assets/javascript/firefly/index.js
index 834dc8db66..49e6508c67 100644
--- a/public/assets/javascript/firefly/index.js
+++ b/public/assets/javascript/firefly/index.js
@@ -7,6 +7,9 @@ google.setOnLoadCallback(drawChart);
function drawChart() {
console.log(1);
googleLineChart('chart/home/account', 'accounts-chart');
+ googleBarChart('chart/home/budgets','budgets-chart');
+ googleColumnChart('chart/home/categories','categories-chart');
+ googlePieChart('chart/home/recurring','recurring-chart')
}