diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index af6397f60e..6823688027 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -186,7 +186,7 @@ class AccountController extends Controller $repository->update($account, $accountData); - Session::flash('success', 'New account "' . $account->name . '" updated.'); + Session::flash('success', 'Account "' . $account->name . '" updated.'); return Redirect::route('accounts.index', $what); diff --git a/app/Http/Controllers/BudgetController.php b/app/Http/Controllers/BudgetController.php index 36c788973e..0022d4bdf3 100644 --- a/app/Http/Controllers/BudgetController.php +++ b/app/Http/Controllers/BudgetController.php @@ -3,14 +3,16 @@ use Auth; use Carbon\Carbon; use FireflyIII\Http\Requests; +use FireflyIII\Http\Requests\BudgetFormRequest; use FireflyIII\Models\Budget; +use FireflyIII\Models\LimitRepetition; use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; use Input; use Preferences; +use Redirect; +use Response; use Session; use View; -use Response; -use Log; /** * Class BudgetController @@ -36,16 +38,61 @@ class BudgetController extends Controller { $amount = intval(Input::get('amount')); $date = Session::get('start', Carbon::now()->startOfMonth()); - Log::debug('Budget: '. $budget->id); - Log::debug('Budget (full) ' . print_r($budget->toArray(),true)); - Log::debug('Amount:' . $amount); - Log::debug('Date: ' . $date); $limitRepetition = $repository->updateLimitAmount($budget, $date, $amount); return Response::json(['name' => $budget->name, 'repetition' => $limitRepetition ? $limitRepetition->id : 0]); } + /** + * @return $this + */ + public function create() + { + return View::make('budgets.create')->with('subTitle', 'Create a new budget'); + } + + /** + * @param Budget $budget + * + * @return \Illuminate\View\View + */ + public function delete(Budget $budget) + { + $subTitle = 'Delete budget' . e($budget->name) . '"'; + + return View::make('budgets.delete', compact('budget', 'subTitle')); + } + + /** + * @param Budget $budget + * + * @return \Illuminate\Http\RedirectResponse + */ + public function destroy(Budget $budget, BudgetRepositoryInterface $repository) + { + + $name = $budget->name; + $repository->destroy($budget); + + Session::flash('success', 'The budget "' . e($name) . '" was deleted.'); + + return Redirect::route('budgets.index'); + } + + /** + * @param Budget $budget + * + * @return $this + */ + public function edit(Budget $budget) + { + $subTitle = 'Edit budget "' . e($budget->name) . '"'; + + return View::make('budgets.edit', compact('budget', 'subTitle')); + + } + /** * @return mixed */ @@ -73,4 +120,103 @@ class BudgetController extends Controller return View::make('budgets.index', compact('budgetMaximum', 'budgets', 'spent', 'spentPCT', 'overspent', 'amount')); } + /** + * @return \Illuminate\View\View + */ + public function noBudget() + { + $start = \Session::get('start', Carbon::now()->startOfMonth()); + $end = \Session::get('end', Carbon::now()->startOfMonth()); + $list = Auth::user() + ->transactionjournals() + ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') + ->whereNull('budget_transaction_journal.id') + ->before($end) + ->after($start) + ->orderBy('transaction_journals.date') + ->get(['transaction_journals.*']); + $subTitle = 'Transactions without a budget in ' . $start->format('F Y'); + + return View::make('budgets.noBudget', compact('list', 'subTitle')); + } + + /** + * @return mixed + */ + public function postUpdateIncome() + { + + $date = Session::get('start', Carbon::now()->startOfMonth())->format('FY'); + Preferences::set('budgetIncomeTotal' . $date, intval(Input::get('amount'))); + + return Redirect::route('budgets.index'); + } + + public function store(BudgetFormRequest $request, BudgetRepositoryInterface $repository) + { + $budgetData = [ + 'name' => $request->input('name'), + 'user' => Auth::user()->id, + ]; + $budget = $repository->store($budgetData); + + Session::flash('success', 'New budget "' . $budget->name . '" stored!'); + + return Redirect::route('budgets.index'); + + } + + /** + * + * @param Budget $budget + * @param LimitRepetition $repetition + * + * @return \Illuminate\View\View + */ + public function show(Budget $budget, LimitRepetition $repetition = null, BudgetRepositoryInterface $repository) + { + if (!is_null($repetition->id) && $repetition->budgetLimit->budget->id != $budget->id) { + return View::make('error')->with('message', 'Invalid selection.'); + } + + $hideBudget = true; // used in transaction list. + $journals = $repository->getJournals($budget, $repetition); + $limits = !is_null($repetition->id) ? [$repetition->budgetLimit] : $budget->budgetLimits()->orderBy('startdate', 'DESC')->get(); + $subTitle = !is_null($repetition->id) ? e($budget->name) . ' in ' . $repetition->startdate->format('F Y') : e($budget->name); + + return View::make('budgets.show', compact('limits', 'budget', 'repetition', 'journals', 'subTitle', 'hideBudget')); + } + + /** + * @param Budget $budget + * @param BudgetFormRequest $request + * @param BudgetRepositoryInterface $repository + * + * @return \Illuminate\Http\RedirectResponse + */ + public function update(Budget $budget, BudgetFormRequest $request, BudgetRepositoryInterface $repository) + { + $budgetData = [ + 'name' => $request->input('name'), + ]; + + $repository->update($budget, $budgetData); + + Session::flash('success', 'Budget "' . $budget->name . '" updated.'); + + return Redirect::route('budgets.index'); + + } + + /** + * @return $this + */ + public function updateIncome() + { + $date = Session::get('start', Carbon::now()->startOfMonth())->format('FY'); + $budgetAmount = Preferences::get('budgetIncomeTotal' . $date, 1000); + + return View::make('budgets.income')->with('amount', $budgetAmount); + } + } diff --git a/app/Http/Controllers/GoogleChartController.php b/app/Http/Controllers/GoogleChartController.php index 3391af442c..828f6aaa9d 100644 --- a/app/Http/Controllers/GoogleChartController.php +++ b/app/Http/Controllers/GoogleChartController.php @@ -1,5 +1,6 @@ addColumn('Day of month', 'date'); + $chart->addColumn('Balance for ' . $account->name, 'number'); + $chart->addCertainty(1); + + $start = Session::get('start', Carbon::now()->startOfMonth()); + $end = Session::get('end', Carbon::now()->endOfMonth()); + $count = $account->transactions()->count(); + + if ($view == 'all' && $count > 0) { + $first = $account->transactions()->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')->orderBy( + 'date', 'ASC' + )->first(['transaction_journals.date']); + $last = $account->transactions()->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')->orderBy( + 'date', 'DESC' + )->first(['transaction_journals.date']); + $start = new Carbon($first->date); + $end = new Carbon($last->date); + } + + $current = clone $start; + + while ($end >= $current) { + $chart->addRow(clone $current, Steam::balance($account, $current), false); + $current->addDay(); + } + + + $chart->generate(); + + return Response::json($chart->getData()); + } + /** * @param GChart $chart * @@ -234,43 +275,99 @@ class GoogleChartController extends Controller } /** - * @param Account $account - * @param string $view + * + * @param Budget $budget + * @param LimitRepetition $repetition * * @return \Illuminate\Http\JsonResponse */ - public function accountBalanceChart(Account $account, $view = 'session', GChart $chart) + public function budgetLimitSpending(Budget $budget, LimitRepetition $repetition, GChart $chart) { - $chart->addColumn('Day of month', 'date'); - $chart->addColumn('Balance for ' . $account->name, 'number'); - $chart->addCertainty(1); + $start = clone $repetition->startdate; + $end = $repetition->enddate; - $start = Session::get('start', Carbon::now()->startOfMonth()); - $end = Session::get('end', Carbon::now()->endOfMonth()); - $count = $account->transactions()->count(); + $chart->addColumn('Day', 'date'); + $chart->addColumn('Left', 'number'); - if ($view == 'all' && $count > 0) { - $first = $account->transactions()->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')->orderBy( - 'date', 'ASC' - )->first(['transaction_journals.date']); - $last = $account->transactions()->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')->orderBy( - 'date', 'DESC' - )->first(['transaction_journals.date']); - $start = new Carbon($first->date); - $end = new Carbon($last->date); + + $amount = $repetition->amount; + + while ($start <= $end) { + /* + * Sum of expenses on this day: + */ + $sum = floatval($budget->transactionjournals()->lessThan(0)->transactionTypes(['Withdrawal'])->onDate($start)->sum('amount')); + $amount += $sum; + $chart->addRow(clone $start, $amount); + $start->addDay(); + } + $chart->generate(); + + return Response::json($chart->getData()); + + } + + /** + * + * @param Budget $budget + * + * @param int $year + * + * @return \Illuminate\Http\JsonResponse + */ + public function budgetsAndSpending(Budget $budget, $year = 0) + { + + $chart = App::make('Grumpydictator\Gchart\GChart'); + $repository = App::make('FireflyIII\Repositories\Budget\BudgetRepository'); + $chart->addColumn('Month', 'date'); + $chart->addColumn('Budgeted', 'number'); + $chart->addColumn('Spent', 'number'); + if ($year == 0) { + // grab the first budgetlimit ever: + $firstLimit = $budget->budgetlimits()->orderBy('startdate', 'ASC')->first(); + if ($firstLimit) { + $start = new Carbon($firstLimit->startdate); + } else { + $start = Carbon::now()->startOfYear(); + } + + // grab the last budget limit ever: + $lastLimit = $budget->budgetlimits()->orderBy('startdate', 'DESC')->first(); + if ($lastLimit) { + $end = new Carbon($lastLimit->startdate); + } else { + $end = Carbon::now()->endOfYear(); + } + } else { + $start = Carbon::createFromDate(intval($year), 1, 1); + $end = clone $start; + $end->endOfYear(); } - $current = clone $start; + while ($start <= $end) { + $spent = $repository->spentInMonth($budget, $start); + $repetition = LimitRepetition::leftJoin('budget_limits', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id') + ->where('limit_repetitions.startdate', $start->format('Y-m-d 00:00:00')) + ->where('budget_limits.budget_id', $budget->id) + ->first(['limit_repetitions.*']); - while ($end >= $current) { - $chart->addRow(clone $current, Steam::balance($account, $current), false); - $current->addDay(); + if ($repetition) { + $budgeted = floatval($repetition->amount); + \Log::debug('Found a repetition on ' . $start->format('Y-m-d') . ' for budget ' . $budget->name . '!'); + } else { + \Log::debug('No repetition on ' . $start->format('Y-m-d') . ' for budget ' . $budget->name); + $budgeted = null; + } + $chart->addRow(clone $start, $budgeted, $spent); + $start->addMonth(); } - $chart->generate(); return Response::json($chart->getData()); + + } diff --git a/app/Http/Requests/BudgetFormRequest.php b/app/Http/Requests/BudgetFormRequest.php new file mode 100644 index 0000000000..591926a969 --- /dev/null +++ b/app/Http/Requests/BudgetFormRequest.php @@ -0,0 +1,40 @@ + $nameRule, + ]; + } +} \ No newline at end of file diff --git a/app/Http/breadcrumbs.php b/app/Http/breadcrumbs.php index 126c478c30..c465fd3f79 100644 --- a/app/Http/breadcrumbs.php +++ b/app/Http/breadcrumbs.php @@ -1,8 +1,10 @@ accountType->type) { default: throw new FireflyException('Cannot handle account type "' . e($account->accountType->type) . '"'); @@ -47,14 +49,14 @@ Breadcrumbs::register( } ); Breadcrumbs::register( - 'accounts.delete', function (Generator $breadcrumbs, \Account $account) { + 'accounts.delete', function (Generator $breadcrumbs, Account $account) { $breadcrumbs->parent('accounts.show', $account); $breadcrumbs->push('Delete ' . e($account->name), route('accounts.delete', $account->id)); } ); Breadcrumbs::register( - 'accounts.edit', function (Generator $breadcrumbs, \Account $account) { + 'accounts.edit', function (Generator $breadcrumbs, Account $account) { $breadcrumbs->parent('accounts.show', $account); $breadcrumbs->push('Edit ' . e($account->name), route('accounts.edit', $account->id)); } @@ -91,9 +93,9 @@ Breadcrumbs::register( 'budgets.show', function (Generator $breadcrumbs, Budget $budget, LimitRepetition $repetition = null) { $breadcrumbs->parent('budgets.index'); $breadcrumbs->push(e($budget->name), route('budgets.show', $budget->id)); - if (!is_null($repetition)) { + if (!is_null($repetition) && !is_null($repetition->id)) { $breadcrumbs->push( - DateKit::periodShow($repetition->startdate, $repetition->budgetlimit->repeat_freq), route('budgets.show', $budget->id, $repetition->id) + Navigation::periodShow($repetition->startdate, $repetition->budgetlimit->repeat_freq), route('budgets.show', $budget->id, $repetition->id) ); } } diff --git a/app/Http/routes.php b/app/Http/routes.php index f9c83d1a45..e6f6ab2311 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -2,6 +2,9 @@ use FireflyIII\Models\Account; use FireflyIII\Models\Budget; use FireflyIII\Models\Bill; +use FireflyIII\Models\LimitRepetition; + + // models Route::bind( 'account', @@ -43,6 +46,19 @@ Route::bind( } ); +Route::bind( + 'limitrepetition', function ($value, $route) { + if (Auth::check()) { + return LimitRepetition::where('limit_repetitions.id', $value) + ->leftjoin('budget_limits', 'budget_limits.id', '=', 'limit_repetitions.budget_limit_id') + ->leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id') + ->where('budgets.user_id', Auth::user()->id) + ->first(['limit_repetitions.*']); + } + + return null; +} +); /** * Home Controller @@ -120,6 +136,9 @@ 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/budget/{budget}/{limitrepetition}', ['uses' => 'GoogleChartController@budgetLimitSpending']); //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']); diff --git a/app/Models/Budget.php b/app/Models/Budget.php index f915f41f04..b07c11b830 100644 --- a/app/Models/Budget.php +++ b/app/Models/Budget.php @@ -13,6 +13,8 @@ class Budget extends Model use SoftDeletes; + protected $fillable = ['user_id', 'name']; + /** * @return \Illuminate\Database\Eloquent\Relations\HasMany */ diff --git a/app/Models/LimitRepetition.php b/app/Models/LimitRepetition.php index fe837e9d14..927d33b1f9 100644 --- a/app/Models/LimitRepetition.php +++ b/app/Models/LimitRepetition.php @@ -26,4 +26,20 @@ class LimitRepetition extends Model return ['created_at', 'updated_at', 'startdate', 'enddate']; } + public function spentInRepetition() + { + $sum = \DB::table('transactions') + ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') + ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') + ->leftJoin('budget_limits', 'budget_limits.budget_id', '=', 'budget_transaction_journal.budget_id') + ->leftJoin('limit_repetitions', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id') + ->where('transaction_journals.date', '>=', $this->startdate->format('Y-m-d')) + ->where('transaction_journals.date', '<=', $this->enddate->format('Y-m-d')) + ->where('transactions.amount', '>', 0) + ->where('limit_repetitions.id', '=', $this->id) + ->sum('transactions.amount'); + + return floatval($sum); + } + } diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.php index 6895328107..2745f8379f 100644 --- a/app/Models/TransactionJournal.php +++ b/app/Models/TransactionJournal.php @@ -87,6 +87,19 @@ class TransactionJournal extends Model return $this->hasMany('FireflyIII\Models\PiggyBankEvent'); } + /** + * @param EloquentBuilder $query + * @param Account $account + */ + public function scopeAccountIs(EloquentBuilder $query, Account $account) + { + if (!isset($this->joinedTransactions)) { + $query->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id'); + $this->joinedTransactions = true; + } + $query->where('transactions.account_id', $account->id); + } + /** * @param EloquentBuilder $query * @param Carbon $date @@ -125,6 +138,17 @@ class TransactionJournal extends Model $query->where('transactions.amount', '<=', $amount); } + /** + * @param EloquentBuilder $query + * @param Carbon $date + * + * @return mixed + */ + public function scopeOnDate(EloquentBuilder $query, Carbon $date) + { + return $query->where('date', '=', $date->format('Y-m-d')); + } + /** * @param EloquentBuilder $query * @param array $types @@ -140,6 +164,21 @@ class TransactionJournal extends Model $query->whereIn('transaction_types.type', $types); } + /** + * Automatically includes the 'with' parameters to get relevant related + * objects. + * + * @param EloquentBuilder $query + */ + public function scopeWithRelevantData(EloquentBuilder $query) + { + $query->with( + ['transactions' => function (HasMany $q) { + $q->orderBy('amount', 'ASC'); + }, 'transactiontype', 'transactioncurrency', 'budgets', 'categories', 'transactions.account.accounttype', 'bill', 'budgets', 'categories'] + ); + } + /** * @param $value */ @@ -173,21 +212,6 @@ class TransactionJournal extends Model return $this->belongsToMany('FireflyIII\Models\TransactionGroup'); } - /** - * Automatically includes the 'with' parameters to get relevant related - * objects. - * - * @param EloquentBuilder $query - */ - public function scopeWithRelevantData(EloquentBuilder $query) - { - $query->with( - ['transactions' => function (HasMany $q) { - $q->orderBy('amount', 'ASC'); - }, 'transactiontype', 'transactioncurrency','budgets', 'categories', 'transactions.account.accounttype', 'bill', 'budgets', 'categories'] - ); - } - /** * @return \Illuminate\Database\Eloquent\Relations\HasMany */ @@ -204,17 +228,4 @@ class TransactionJournal extends Model return $this->belongsTo('FireflyIII\User'); } - /** - * @param EloquentBuilder $query - * @param Account $account - */ - public function scopeAccountIs(EloquentBuilder $query, Account $account) - { - if (!isset($this->joinedTransactions)) { - $query->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id'); - $this->joinedTransactions = true; - } - $query->where('transactions.account_id', $account->id); - } - } diff --git a/app/Providers/TestingServiceProvider.php b/app/Providers/TestingServiceProvider.php new file mode 100644 index 0000000000..314f1f936d --- /dev/null +++ b/app/Providers/TestingServiceProvider.php @@ -0,0 +1,28 @@ +app->environment() == 'testing') + { + $this->app['config']['session.driver'] = 'native'; + } + } + +} \ No newline at end of file diff --git a/app/Repositories/Budget/BudgetRepository.php b/app/Repositories/Budget/BudgetRepository.php index 135417e2bd..9488d28a2e 100644 --- a/app/Repositories/Budget/BudgetRepository.php +++ b/app/Repositories/Budget/BudgetRepository.php @@ -6,6 +6,7 @@ use Carbon\Carbon; use FireflyIII\Models\Budget; use FireflyIII\Models\BudgetLimit; use FireflyIII\Models\LimitRepetition; +use Illuminate\Pagination\LengthAwarePaginator; /** * Class BudgetRepository @@ -15,6 +16,51 @@ use FireflyIII\Models\LimitRepetition; class BudgetRepository implements BudgetRepositoryInterface { + /** + * @param Budget $budget + * + * @return boolean + */ + public function destroy(Budget $budget) + { + $budget->delete(); + + return true; + } + + /** + * Returns all the transaction journals for a limit, possibly limited by a limit repetition. + * + * @param Budget $budget + * @param LimitRepetition $repetition + * @param int $take + * + * @return \Illuminate\Pagination\Paginator + */ + public function getJournals(Budget $budget, LimitRepetition $repetition = null, $take = 50) + { + $offset = intval(\Input::get('page')) > 0 ? intval(\Input::get('page')) * $take : 0; + + + $setQuery = $budget->transactionJournals()->withRelevantData()->take($take)->offset($offset)->orderBy('date', 'DESC'); + $countQuery = $budget->transactionJournals(); + + + if (!is_null($repetition->id)) { + $setQuery->after($repetition->startdate)->before($repetition->enddate); + $countQuery->after($repetition->startdate)->before($repetition->enddate); + } + + + $set = $setQuery->get(['transaction_journals.*']); + $count = $countQuery->count(); + $items = []; + foreach ($set as $entry) { + $items[] = $entry; + } + return new LengthAwarePaginator($items, $count, $take, $offset); + } + /** * @param Budget $budget * @param Carbon $date @@ -31,6 +77,39 @@ class BudgetRepository implements BudgetRepositoryInterface return $sum; } + /** + * @param array $data + * + * @return Budget + */ + public function store(array $data) + { + $newBudget = new Budget( + [ + 'user_id' => $data['user'], + 'name' => $data['name'], + ] + ); + $newBudget->save(); + + return $newBudget; + } + + /** + * @param Budget $budget + * @param array $data + * + * @return Budget + */ + public function update(Budget $budget, array $data) + { + // update the account: + $budget->name = $data['name']; + $budget->save(); + + return $budget; + } + /** * @param Budget $budget * @param Carbon $date @@ -59,6 +138,7 @@ class BudgetRepository implements BudgetRepositoryInterface $limit->delete(); } } + return $limit; diff --git a/app/Repositories/Budget/BudgetRepositoryInterface.php b/app/Repositories/Budget/BudgetRepositoryInterface.php index 9314d4a22f..771c01ccd8 100644 --- a/app/Repositories/Budget/BudgetRepositoryInterface.php +++ b/app/Repositories/Budget/BudgetRepositoryInterface.php @@ -2,6 +2,7 @@ namespace FireflyIII\Repositories\Budget; use FireflyIII\Models\Budget; +use FireflyIII\Models\LimitRepetition; use Carbon\Carbon; /** * Interface BudgetRepositoryInterface @@ -10,6 +11,12 @@ use Carbon\Carbon; */ interface BudgetRepositoryInterface { + /** + * @param Budget $budget + * + * @return boolean + */ + public function destroy(Budget $budget); /** * @param Budget $budget @@ -28,4 +35,30 @@ interface BudgetRepositoryInterface */ public function updateLimitAmount(Budget $budget, Carbon $date, $amount); + /** + * @param array $data + * + * @return Budget + */ + public function store(array $data); + + /** + * @param Budget $budget + * @param array $data + * + * @return Budget + */ + public function update(Budget $budget, array $data); + + /** + * Returns all the transaction journals for a limit, possibly limited by a limit repetition. + * + * @param Budget $budget + * @param LimitRepetition $repetition + * @param int $take + * + * @return \Illuminate\Pagination\Paginator + */ + public function getJournals(Budget $budget, LimitRepetition $repetition = null, $take = 50); + } \ No newline at end of file diff --git a/app/Support/ExpandedForm.php b/app/Support/ExpandedForm.php index 3494c9fc2c..a7a148b2cf 100644 --- a/app/Support/ExpandedForm.php +++ b/app/Support/ExpandedForm.php @@ -2,7 +2,6 @@ namespace FireflyIII\Support; -use Amount; use FireflyIII\Models\TransactionCurrency; use Illuminate\Support\MessageBag; use Input; diff --git a/app/Support/Navigation.php b/app/Support/Navigation.php index 4b41b1b8f0..6c1bd66329 100644 --- a/app/Support/Navigation.php +++ b/app/Support/Navigation.php @@ -14,6 +14,33 @@ class Navigation { + /** + * @param Carbon $date + * @param $repeatFrequency + * + * @return string + * @throws FireflyException + */ + public function periodShow(Carbon $date, $repeatFrequency) + { + $formatMap = [ + 'daily' => 'j F Y', + 'week' => '\W\e\e\k W, Y', + 'weekly' => '\W\e\e\k W, Y', + 'quarter' => 'F Y', + 'month' => 'F Y', + 'monthly' => 'F Y', + 'year' => 'Y', + 'yearly' => 'Y', + + ]; + if (isset($formatMap[$repeatFrequency])) { + return $date->format($formatMap[$repeatFrequency]); + } + throw new FireflyException('No date formats for frequency "' . $repeatFrequency . '"!'); + } + + /** * @param $range * @param Carbon $date diff --git a/composer.lock b/composer.lock index bc29b0d420..af8bd1e0e1 100644 --- a/composer.lock +++ b/composer.lock @@ -131,16 +131,16 @@ }, { "name": "danielstjules/stringy", - "version": "1.8.1", + "version": "1.9.0", "source": { "type": "git", "url": "https://github.com/danielstjules/Stringy.git", - "reference": "6a7b0391b2baf0bfdca3ec0c8d33ff379c2835ad" + "reference": "3cf18e9e424a6dedc38b7eb7ef580edb0929461b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/danielstjules/Stringy/zipball/6a7b0391b2baf0bfdca3ec0c8d33ff379c2835ad", - "reference": "6a7b0391b2baf0bfdca3ec0c8d33ff379c2835ad", + "url": "https://api.github.com/repos/danielstjules/Stringy/zipball/3cf18e9e424a6dedc38b7eb7ef580edb0929461b", + "reference": "3cf18e9e424a6dedc38b7eb7ef580edb0929461b", "shasum": "" }, "require": { @@ -183,7 +183,7 @@ "utility", "utils" ], - "time": "2015-01-08 15:21:43" + "time": "2015-02-10 06:19:18" }, { "name": "davejamesmiller/laravel-breadcrumbs", @@ -749,12 +749,12 @@ "source": { "type": "git", "url": "https://github.com/JC5/gchart.git", - "reference": "0cbefaf7ea75f4ce23791d9764787f3b617208dd" + "reference": "24d06101cfda7ff336ecb10f7f0cb0d6004cb83c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/JC5/gchart/zipball/0cbefaf7ea75f4ce23791d9764787f3b617208dd", - "reference": "0cbefaf7ea75f4ce23791d9764787f3b617208dd", + "url": "https://api.github.com/repos/JC5/gchart/zipball/24d06101cfda7ff336ecb10f7f0cb0d6004cb83c", + "reference": "24d06101cfda7ff336ecb10f7f0cb0d6004cb83c", "shasum": "" }, "require": { @@ -777,7 +777,7 @@ } ], "description": "GChart is a small package that allows you to easily generate data for the Google Charts API.", - "time": "2015-02-08 00:18:35" + "time": "2015-02-20 20:07:26" }, { "name": "illuminate/html", @@ -1013,16 +1013,16 @@ }, { "name": "laravel/framework", - "version": "v5.0.2", + "version": "v5.0.6", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "30391aa20874c30725f653bea1ea5b895a5217cf" + "reference": "43637b796f1ac0b1a960984231251ff04b438006" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/30391aa20874c30725f653bea1ea5b895a5217cf", - "reference": "30391aa20874c30725f653bea1ea5b895a5217cf", + "url": "https://api.github.com/repos/laravel/framework/zipball/43637b796f1ac0b1a960984231251ff04b438006", + "reference": "43637b796f1ac0b1a960984231251ff04b438006", "shasum": "" }, "require": { @@ -1134,7 +1134,7 @@ "framework", "laravel" ], - "time": "2015-02-06 23:14:12" + "time": "2015-02-20 16:22:21" }, { "name": "league/flysystem", @@ -1566,16 +1566,16 @@ }, { "name": "psy/psysh", - "version": "v0.3.3", + "version": "v0.3.5", "source": { "type": "git", "url": "https://github.com/bobthecow/psysh.git", - "reference": "0355cecab0591c83fed019a9572c510b0da29174" + "reference": "2ce0e8f3020fd292c2ad2a496c5d83939823f642" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/bobthecow/psysh/zipball/0355cecab0591c83fed019a9572c510b0da29174", - "reference": "0355cecab0591c83fed019a9572c510b0da29174", + "url": "https://api.github.com/repos/bobthecow/psysh/zipball/2ce0e8f3020fd292c2ad2a496c5d83939823f642", + "reference": "2ce0e8f3020fd292c2ad2a496c5d83939823f642", "shasum": "" }, "require": { @@ -1625,14 +1625,14 @@ } ], "description": "An interactive shell for modern PHP.", - "homepage": "https://github.com/bobthecow/psysh", + "homepage": "http://psysh.org", "keywords": [ "REPL", "console", "interactive", "shell" ], - "time": "2015-01-20 21:18:03" + "time": "2015-02-12 19:35:52" }, { "name": "swiftmailer/swiftmailer", @@ -2537,20 +2537,20 @@ "packages-dev": [ { "name": "barryvdh/laravel-debugbar", - "version": "v2.0.0", + "version": "v2.0.1", "source": { "type": "git", "url": "https://github.com/barryvdh/laravel-debugbar.git", - "reference": "343dbc07007272511727c9272e568d707682fc24" + "reference": "77b9cc071f4bbd839923269668b14d308778d8b0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/barryvdh/laravel-debugbar/zipball/343dbc07007272511727c9272e568d707682fc24", - "reference": "343dbc07007272511727c9272e568d707682fc24", + "url": "https://api.github.com/repos/barryvdh/laravel-debugbar/zipball/77b9cc071f4bbd839923269668b14d308778d8b0", + "reference": "77b9cc071f4bbd839923269668b14d308778d8b0", "shasum": "" }, "require": { - "illuminate/support": "5.0.*", + "illuminate/support": "5.0.x", "maximebf/debugbar": "~1.10.2", "php": ">=5.4.0", "symfony/finder": "~2.6" @@ -2587,7 +2587,7 @@ "profiler", "webprofiler" ], - "time": "2015-02-03 19:52:06" + "time": "2015-02-15 14:11:42" }, { "name": "codeception/c3", @@ -2830,12 +2830,12 @@ "source": { "type": "git", "url": "https://github.com/codeclimate/php-test-reporter.git", - "reference": "2dd8395f81874333d15de3a598f722997ba42fb5" + "reference": "2a67d5d940e175fddba15f29c81a646ace26dc38" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/codeclimate/php-test-reporter/zipball/2dd8395f81874333d15de3a598f722997ba42fb5", - "reference": "2dd8395f81874333d15de3a598f722997ba42fb5", + "url": "https://api.github.com/repos/codeclimate/php-test-reporter/zipball/2a67d5d940e175fddba15f29c81a646ace26dc38", + "reference": "2a67d5d940e175fddba15f29c81a646ace26dc38", "shasum": "" }, "require": { @@ -2845,6 +2845,7 @@ "symfony/console": ">=2.0" }, "require-dev": { + "ext-xdebug": "*", "phpunit/phpunit": "3.7.*@stable" }, "bin": [ @@ -2879,7 +2880,7 @@ "codeclimate", "coverage" ], - "time": "2014-12-29 16:17:04" + "time": "2015-02-20 22:40:35" }, { "name": "doctrine/instantiator", @@ -3276,16 +3277,16 @@ }, { "name": "janhenkgerritsen/codeception-laravel5", - "version": "1.0.10", + "version": "1.0.11", "source": { "type": "git", "url": "https://github.com/janhenkgerritsen/codeception-laravel5.git", - "reference": "6308e72a73dfb015164689646676cda6827409d5" + "reference": "b4aef07d548b6becfd54ebf909e1f49de1ca5392" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/janhenkgerritsen/codeception-laravel5/zipball/6308e72a73dfb015164689646676cda6827409d5", - "reference": "6308e72a73dfb015164689646676cda6827409d5", + "url": "https://api.github.com/repos/janhenkgerritsen/codeception-laravel5/zipball/b4aef07d548b6becfd54ebf909e1f49de1ca5392", + "reference": "b4aef07d548b6becfd54ebf909e1f49de1ca5392", "shasum": "" }, "require": { @@ -3314,7 +3315,7 @@ "laravel", "laravel5" ], - "time": "2015-02-07 10:02:06" + "time": "2015-02-14 11:20:37" }, { "name": "league/factory-muffin", diff --git a/config/app.php b/config/app.php index 686a08138c..23d8fa9af1 100644 --- a/config/app.php +++ b/config/app.php @@ -149,6 +149,7 @@ return [ 'FireflyIII\Providers\EventServiceProvider', 'FireflyIII\Providers\RouteServiceProvider', 'FireflyIII\Providers\FireflyServiceProvider', + 'FireflyIII\Providers\TestingServiceProvider', ], diff --git a/database/migrations/2014_12_13_190730_changes_for_v321.php b/database/migrations/2014_12_13_190730_changes_for_v321.php index 3d184e8e6f..c5a2be3f0c 100644 --- a/database/migrations/2014_12_13_190730_changes_for_v321.php +++ b/database/migrations/2014_12_13_190730_changes_for_v321.php @@ -236,7 +236,9 @@ class ChangesForV321 extends Migration { Schema::table( 'limit_repetitions', function (Blueprint $table) { + $table->dropForeign('limit_repetitions_budget_limit_id_foreign'); $table->renameColumn('budget_limit_id', 'limit_id'); + $table->foreign('limit_id')->references('id')->on('limits')->onDelete('cascade'); } ); } @@ -404,7 +406,9 @@ class ChangesForV321 extends Migration { Schema::table( 'limit_repetitions', function (Blueprint $table) { + $table->dropForeign('limit_repetitions_limit_id_foreign'); $table->renameColumn('limit_id', 'budget_limit_id'); + $table->foreign('budget_limit_id')->references('id')->on('budget_limits')->onDelete('cascade'); } ); } diff --git a/database/migrations/2014_12_24_191544_changes_for_v322.php b/database/migrations/2014_12_24_191544_changes_for_v322.php index f1ec4036b3..fc78f7b173 100644 --- a/database/migrations/2014_12_24_191544_changes_for_v322.php +++ b/database/migrations/2014_12_24_191544_changes_for_v322.php @@ -108,13 +108,17 @@ class ChangesForV322 extends Migration // rename fields Schema::table( 'piggy_bank_events', function (Blueprint $table) { + $table->dropForeign('piggybank_events_piggybank_id_foreign'); $table->renameColumn('piggybank_id', 'piggy_bank_id'); + $table->foreign('piggy_bank_id')->references('id')->on('piggy_banks')->onDelete('cascade'); } ); Schema::table( 'piggy_bank_repetitions', function (Blueprint $table) { + $table->dropForeign('piggybank_repetitions_piggybank_id_foreign'); $table->renameColumn('piggybank_id', 'piggy_bank_id'); + $table->foreign('piggy_bank_id')->references('id')->on('piggy_banks')->onDelete('cascade'); } ); diff --git a/database/seeds/TestDataSeeder.php b/database/seeds/TestDataSeeder.php index 8e5bb51ddc..34a6acfd61 100644 --- a/database/seeds/TestDataSeeder.php +++ b/database/seeds/TestDataSeeder.php @@ -215,9 +215,9 @@ class TestDataSeeder extends Seeder ); // and because we have no filters, some repetitions: - LimitRepetition::create(['budget_limit_id' => $groceriesLimit->id, 'startdate' => $this->som, 'enddate' => $this->eom, 'amount' => 201]); - LimitRepetition::create(['budget_limit_id' => $billsLimit->id, 'startdate' => $this->som, 'enddate' => $this->eom, 'amount' => 202]); - LimitRepetition::create(['budget_limit_id' => $deleteMeLimit->id, 'startdate' => $this->som, 'enddate' => $this->eom, 'amount' => 203]); +// LimitRepetition::create(['budget_limit_id' => $groceriesLimit->id, 'startdate' => $this->som, 'enddate' => $this->eom, 'amount' => 201]); +// LimitRepetition::create(['budget_limit_id' => $billsLimit->id, 'startdate' => $this->som, 'enddate' => $this->eom, 'amount' => 202]); +// LimitRepetition::create(['budget_limit_id' => $deleteMeLimit->id, 'startdate' => $this->som, 'enddate' => $this->eom, 'amount' => 203]); } /** diff --git a/resources/views/budgets/create.blade.php b/resources/views/budgets/create.blade.php index 6ba3bcf297..a9722f5ac0 100644 --- a/resources/views/budgets/create.blade.php +++ b/resources/views/budgets/create.blade.php @@ -1,7 +1,7 @@ @extends('layouts.default') @section('content') {!! Breadcrumbs::renderIfExists(Route::getCurrentRoute()->getName()) !!} -{{Form::open(['class' => 'form-horizontal','id' => 'store','url' => route('budgets.store')])}} +{!! Form::open(['class' => 'form-horizontal','id' => 'store','url' => route('budgets.store')]) !!}
@@ -9,7 +9,7 @@ Mandatory fields
- {{Form::ffText('name')}} + {!! ExpandedForm::text('name') !!}

@@ -26,7 +26,7 @@ Options

- {{Form::ffOptionsList('create','budget')}} + {!! ExpandedForm::optionsList('create','budget') !!}
@@ -36,7 +36,7 @@ -{{Form::close()}} +{!! Form::close() !!} @stop diff --git a/resources/views/budgets/delete.blade.php b/resources/views/budgets/delete.blade.php index 7b85429f1a..d4acb2d795 100644 --- a/resources/views/budgets/delete.blade.php +++ b/resources/views/budgets/delete.blade.php @@ -1,7 +1,7 @@ @extends('layouts.default') @section('content') {!! Breadcrumbs::renderIfExists(Route::getCurrentRoute()->getName(), $budget) !!} -{{Form::open(['class' => 'form-horizontal','id' => 'destroy','url' => route('budgets.destroy',$budget->id)])}} +{!! Form::open(['class' => 'form-horizontal','id' => 'destroy','url' => route('budgets.destroy',$budget->id)]) !!}
@@ -33,5 +33,5 @@
-{{Form::close()}} +{!! Form::close() !!} @stop diff --git a/resources/views/budgets/edit.blade.php b/resources/views/budgets/edit.blade.php index 0a124bad78..a2860bc391 100644 --- a/resources/views/budgets/edit.blade.php +++ b/resources/views/budgets/edit.blade.php @@ -1,42 +1,43 @@ @extends('layouts.default') @section('content') -{!! Breadcrumbs::renderIfExists(Route::getCurrentRoute()->getName(), $budget) !!} -
-
-

Use budgets to organize and limit your expenses.

+ {!! Breadcrumbs::renderIfExists(Route::getCurrentRoute()->getName(), $budget) !!} +
+
+

Use budgets to organize and limit your expenses.

+
-
-{{Form::model($budget, ['class' => 'form-horizontal','id' => 'update','url' => route('budgets.update',$budget->id)])}} -
-
-
-
- Mandatory fields -
-
- {{Form::ffText('name')}} + {!! Form::model($budget, ['class' => 'form-horizontal','id' => 'update','url' => route('budgets.update',$budget->id)]) !!} + +
+
+
+
+ Mandatory fields +
+
+ {!! ExpandedForm::text('name') !!} +
+

+ +

-

- -

-
-
- -
-
- Options -
-
- {{Form::ffOptionsList('update','budget')}} +
+ +
+
+ Options +
+
+ {!! ExpandedForm::optionsList('update','budget') !!} +
-
-{{Form::close()}} + {!! Form::close() !!} @stop diff --git a/resources/views/budgets/income.blade.php b/resources/views/budgets/income.blade.php index 713c61a20c..d01fea7eea 100644 --- a/resources/views/budgets/income.blade.php +++ b/resources/views/budgets/income.blade.php @@ -1,5 +1,6 @@
-{{Form::token()}} + +{!! Form::token() !!}