2015-02-06 04:52:16 +01:00
|
|
|
<?php namespace FireflyIII\Http\Controllers;
|
2015-02-06 04:39:52 +01:00
|
|
|
|
2015-02-07 06:49:24 +01:00
|
|
|
use Carbon\Carbon;
|
2015-04-07 18:26:14 +02:00
|
|
|
use Config;
|
2015-03-13 08:44:07 +01:00
|
|
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
2015-03-02 13:19:13 +01:00
|
|
|
use Input;
|
2015-02-07 06:49:24 +01:00
|
|
|
use Preferences;
|
2015-03-31 20:46:37 +02:00
|
|
|
use Redirect;
|
2015-05-23 17:11:16 +02:00
|
|
|
use Route;
|
2015-04-07 18:26:14 +02:00
|
|
|
use Session;
|
2015-04-09 11:52:35 +02:00
|
|
|
use Steam;
|
2015-04-07 18:26:14 +02:00
|
|
|
|
2015-02-06 21:23:14 +01:00
|
|
|
/**
|
|
|
|
* Class HomeController
|
|
|
|
*
|
|
|
|
* @package FireflyIII\Http\Controllers
|
|
|
|
*/
|
2015-02-06 07:23:26 +01:00
|
|
|
class HomeController extends Controller
|
|
|
|
{
|
2015-02-06 04:39:52 +01:00
|
|
|
|
2015-03-02 13:19:13 +01:00
|
|
|
public function dateRange()
|
|
|
|
{
|
2015-03-02 12:35:14 +01:00
|
|
|
$start = new Carbon(Input::get('start'));
|
2015-03-02 13:19:13 +01:00
|
|
|
$end = new Carbon(Input::get('end'));
|
|
|
|
|
|
|
|
$diff = $start->diffInDays($end);
|
|
|
|
|
|
|
|
if ($diff > 50) {
|
|
|
|
Session::flash('warning', $diff . ' days of data may take a while to load.');
|
|
|
|
}
|
2015-03-02 12:35:14 +01:00
|
|
|
|
2015-03-02 13:19:13 +01:00
|
|
|
Session::put('start', $start);
|
|
|
|
Session::put('end', $end);
|
2015-03-02 12:35:14 +01:00
|
|
|
}
|
|
|
|
|
2015-04-07 20:54:43 +02:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2015-04-07 18:26:14 +02:00
|
|
|
public function flush()
|
|
|
|
{
|
2015-03-31 20:46:37 +02:00
|
|
|
Session::clear();
|
2015-04-07 18:26:14 +02:00
|
|
|
|
2015-03-31 20:46:37 +02:00
|
|
|
return Redirect::route('index');
|
|
|
|
}
|
|
|
|
|
2015-02-06 07:23:26 +01:00
|
|
|
/**
|
2015-04-13 20:43:58 +02:00
|
|
|
* @param AccountRepositoryInterface $repository
|
|
|
|
*
|
2015-02-06 21:23:14 +01:00
|
|
|
* @return \Illuminate\View\View
|
2015-02-06 07:23:26 +01:00
|
|
|
*/
|
2015-03-13 08:44:07 +01:00
|
|
|
public function index(AccountRepositoryInterface $repository)
|
2015-02-06 07:23:26 +01:00
|
|
|
{
|
2015-03-13 08:44:07 +01:00
|
|
|
|
2015-04-13 20:43:58 +02:00
|
|
|
$types = Config::get('firefly.accountTypesByIdentifier.asset');
|
|
|
|
$count = $repository->countAccounts($types);
|
2015-06-01 18:13:54 +02:00
|
|
|
|
|
|
|
if($count == 0) {
|
|
|
|
return Redirect::route('new-user.index');
|
|
|
|
}
|
|
|
|
|
2015-04-13 20:43:58 +02:00
|
|
|
$title = 'Firefly';
|
2015-05-14 13:17:53 +02:00
|
|
|
$subTitle = trans('firefly.welcomeBack');
|
2015-04-13 20:43:58 +02:00
|
|
|
$mainTitleIcon = 'fa-fire';
|
|
|
|
$transactions = [];
|
|
|
|
$frontPage = Preferences::get('frontPageAccounts', []);
|
|
|
|
$start = Session::get('start', Carbon::now()->startOfMonth());
|
|
|
|
$end = Session::get('end', Carbon::now()->endOfMonth());
|
|
|
|
$accounts = $repository->getFrontpageAccounts($frontPage);
|
|
|
|
$savings = $repository->getSavingsAccounts();
|
|
|
|
$piggyBankAccounts = $repository->getPiggyBankAccounts();
|
|
|
|
|
|
|
|
$savingsTotal = 0;
|
2015-04-09 11:52:35 +02:00
|
|
|
foreach ($savings as $savingAccount) {
|
2015-04-09 19:10:24 +02:00
|
|
|
$savingsTotal += Steam::balance($savingAccount, $end);
|
2015-04-09 11:52:35 +02:00
|
|
|
}
|
|
|
|
|
2015-04-07 20:54:43 +02:00
|
|
|
$sum = $repository->sumOfEverything();
|
2015-03-29 19:44:59 +02:00
|
|
|
if ($sum != 0) {
|
2015-03-29 18:28:49 +02:00
|
|
|
Session::flash(
|
|
|
|
'error', 'Your transactions are unbalanced. This means a'
|
2015-05-26 18:57:31 +00:00
|
|
|
. ' withdrawal, deposit or transfer was not stored properly. '
|
|
|
|
. 'Please check your accounts and transactions for errors.'
|
2015-03-29 18:28:49 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-02-07 06:49:24 +01:00
|
|
|
foreach ($accounts as $account) {
|
2015-03-13 08:44:07 +01:00
|
|
|
$set = $repository->getFrontpageTransactions($account, $start, $end);
|
2015-02-07 06:49:24 +01:00
|
|
|
if (count($set) > 0) {
|
|
|
|
$transactions[] = [$set, $account];
|
|
|
|
}
|
|
|
|
}
|
2015-02-07 13:15:40 +01:00
|
|
|
|
2015-04-28 15:26:30 +02:00
|
|
|
return view('index', compact('count', 'title', 'savings', 'subTitle', 'mainTitleIcon', 'transactions', 'savingsTotal', 'piggyBankAccounts'));
|
2015-02-06 07:23:26 +01:00
|
|
|
}
|
2015-02-06 04:39:52 +01:00
|
|
|
|
2015-05-23 17:11:16 +02:00
|
|
|
/**
|
|
|
|
* @codeCoverageIgnore
|
|
|
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
|
|
|
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
|
|
|
*/
|
|
|
|
public function routes()
|
|
|
|
{
|
|
|
|
$directory = '/vagrant_data/Sites/firefly-iii-help';
|
|
|
|
$languages = array_keys(Config::get('firefly.lang'));
|
|
|
|
$routes = [];
|
|
|
|
$ignored = [
|
|
|
|
'debugbar.openhandler', 'debugbar.assets.css', 'debugbar.assets.js', 'register', 'routes', 'daterange',
|
|
|
|
'flush', 'delete-account-post', 'change-password-post', 'logout', 'login', 'tags.hideTagHelp',
|
|
|
|
'budgets.postIncome', 'flush'
|
|
|
|
];
|
|
|
|
|
|
|
|
$ignoreMatch = ['.store', '.update', '.destroy', 'json.'];
|
|
|
|
|
|
|
|
$routeCollection = Route::getRoutes();
|
|
|
|
/** @var \Illuminate\Routing\Route $object */
|
|
|
|
foreach ($routeCollection as $object) {
|
|
|
|
// get name:
|
|
|
|
$name = $object->getName();
|
|
|
|
// has name and not in ignore list?
|
|
|
|
if (strlen($name) > 0 && !in_array($name, $ignored)) {
|
|
|
|
|
|
|
|
// not in ignoreMatch?
|
|
|
|
$continue = true;
|
|
|
|
foreach ($ignoreMatch as $ignore) {
|
|
|
|
$match = strpos($name, $ignore);
|
|
|
|
if (!($match === false)) {
|
|
|
|
$continue = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unset($ignore, $match);
|
|
|
|
|
|
|
|
if ($continue) {
|
|
|
|
|
|
|
|
$routes[] = $name;
|
|
|
|
|
|
|
|
// check all languages:
|
|
|
|
foreach ($languages as $lang) {
|
|
|
|
$file = $directory . '/' . $lang . '/' . $name . '.md';
|
|
|
|
if (!file_exists($file)) {
|
|
|
|
touch($file);
|
|
|
|
echo $name . '<br />';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// loop directories with language file.
|
|
|
|
// tag the ones not in the list of approved routes.
|
|
|
|
foreach ($languages as $lang) {
|
|
|
|
$dir = $directory . '/' . $lang;
|
|
|
|
$set = scandir($dir);
|
|
|
|
foreach ($set as $entry) {
|
|
|
|
if ($entry != '.' && $entry != '..') {
|
|
|
|
$name = str_replace('.md', '', $entry);
|
|
|
|
if (!in_array($name, $routes)) {
|
|
|
|
$file = $dir . '/' . $entry;
|
|
|
|
unlink($file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
echo 'Done!';
|
|
|
|
}
|
|
|
|
|
2015-02-06 21:23:14 +01:00
|
|
|
|
2015-02-06 04:39:52 +01:00
|
|
|
}
|