Skip to content

Firefly III: a personal finances manager

Some new code.

James Cole460f14decadf
diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php
index 4bc3698507..36f5470003 100644
--- a/app/Http/Controllers/AccountController.php
+++ b/app/Http/Controllers/AccountController.php
@@ -1,5 +1,6 @@
<?php namespace FireflyIII\Http\Controllers;
+use App;
use Auth;
use Carbon\Carbon;
use Config;
@@ -10,6 +11,7 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Redirect;
use Session;
use View;
+use Input;
/**
* Class AccountController
@@ -115,6 +117,26 @@ class AccountController extends Controller
return view('accounts.index', compact('what', 'subTitleIcon', 'subTitle', 'accounts'));
}
+ /**
+ * @param Account $account
+ * @param string $range
+ * @param AccountRepositoryInterface $repository
+ *
+ * @return \Illuminate\View\View
+ */
+ public function show(Account $account, $range = 'session')
+ {
+ /** @var \FireflyIII\Repositories\Account\AccountRepositoryInterface $repository */
+ $repository = App::make('FireflyIII\Repositories\Account\AccountRepositoryInterface');
+ $page = intval(Input::get('page')) == 0 ? 1 : intval(Input::get('page'));
+ $subTitleIcon = Config::get('firefly.subTitlesByIdentifier.' . $account->accountType->type);
+ $what = Config::get('firefly.shortNamesByFullName.' . $account->accountType->type);
+ $journals = $repository->getJournals($account, $range);
+ $subTitle = 'Details for ' . strtolower(e($account->accountType->type)) . ' "' . e($account->name) . '"';
+
+ return View::make('accounts.show', compact('account', 'what', 'range', 'subTitleIcon', 'journals', 'subTitle'));
+ }
+
/**
* @param AccountFormRequest $request
* @param AccountRepositoryInterface $repository
diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php
index 976a7bf73b..1b89f3d8a9 100644
--- a/app/Repositories/Account/AccountRepository.php
+++ b/app/Repositories/Account/AccountRepository.php
@@ -3,6 +3,8 @@
namespace FireflyIII\Repositories\Account;
use App;
+use Auth;
+use Carbon\Carbon;
use Config;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountMeta;
@@ -10,7 +12,10 @@ use FireflyIII\Models\AccountType;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
+use Illuminate\Pagination\LengthAwarePaginator;
+use Illuminate\Pagination\Paginator;
use Log;
+use Session;
/**
* Class AccountRepository
@@ -32,6 +37,43 @@ class AccountRepository implements AccountRepositoryInterface
return true;
}
+ /**
+ * @param Account $account
+ * @param int $page
+ * @param string $range
+ *
+ * @return mixed
+ */
+ public function getJournals(Account $account, $page, $range = 'session')
+ {
+ $offset = $page * 50;
+ $items = [];
+ $query = Auth::user()
+ ->transactionJournals()
+ //->withRelevantData()
+ ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
+ ->where('transactions.account_id', $account->id)
+ ->orderBy('date', 'DESC');
+
+ if ($range == 'session') {
+ $query->before(Session::get('end', Carbon::now()->startOfMonth()));
+ $query->after(Session::get('start', Carbon::now()->startOfMonth()));
+ }
+ $count = $query->count();
+ $set = $query->take(50)->offset($offset)->get(['transaction_journals.*']);
+
+ foreach ($set as $entry) {
+ $items[] = $entry;
+ }
+
+ $paginator = new LengthAwarePaginator($items, $count, 50, $page);
+ return $paginator;
+
+ //return Paginator::make($items, $count, 50);
+
+
+ }
+
/**
* @param Account $account
*
diff --git a/app/Repositories/Account/AccountRepositoryInterface.php b/app/Repositories/Account/AccountRepositoryInterface.php
index 6e2e7897db..322a9f39af 100644
--- a/app/Repositories/Account/AccountRepositoryInterface.php
+++ b/app/Repositories/Account/AccountRepositoryInterface.php
@@ -4,6 +4,7 @@ namespace FireflyIII\Repositories\Account;
use FireflyIII\Models\Account;
use FireflyIII\Models\TransactionJournal;
+
/**
* Interface AccountRepositoryInterface
*
@@ -11,13 +12,6 @@ use FireflyIII\Models\TransactionJournal;
*/
interface AccountRepositoryInterface
{
- /**
- * @param array $data
- *
- * @return Account
- */
- public function store(array $data);
-
/**
* @param Account $account
*
@@ -27,11 +21,12 @@ interface AccountRepositoryInterface
/**
* @param Account $account
- * @param array $data
+ * @param int $page
+ * @param string $range
*
- * @return Account
+ * @return mixed
*/
- public function update(Account $account, array $data);
+ public function getJournals(Account $account, $page, $range = 'session');
/**
* @param Account $account
@@ -40,5 +35,18 @@ interface AccountRepositoryInterface
*/
public function openingBalanceTransaction(Account $account);
+ /**
+ * @param array $data
+ *
+ * @return Account
+ */
+ public function store(array $data);
+ /**
+ * @param Account $account
+ * @param array $data
+ *
+ * @return Account
+ */
+ public function update(Account $account, array $data);
}
\ No newline at end of file
diff --git a/public/js/accounts.js b/public/js/accounts.js
new file mode 100644
index 0000000000..d0830eecef
--- /dev/null
+++ b/public/js/accounts.js
@@ -0,0 +1,7 @@
+$(function () {
+
+ if (typeof(googleLineChart) === "function" && typeof accountID !== 'undefined' && typeof view !== 'undefined') {
+ googleLineChart('chart/account/' + accountID + '/' + view, 'overview-chart');
+ }
+
+});
\ No newline at end of file
diff --git a/resources/views/accounts/show.blade.php b/resources/views/accounts/show.blade.php
new file mode 100644
index 0000000000..0ace1f4916
--- /dev/null
+++ b/resources/views/accounts/show.blade.php
@@ -0,0 +1,77 @@
+@extends('layouts.default')
+@section('content')
+{{-- Breadcrumbs::renderIfExists(Route::getCurrentRoute()->getName(), $account) --}}
+<div class="row">
+ <div class="col-lg-8 col-md-6 col-sm-12">
+ <div class="panel panel-default">
+ <div class="panel-heading">
+ <i class="fa fa-fw {{$subTitleIcon}} fa-fw"></i> {{{$account->name}}}
+
+
+ <!-- ACTIONS MENU -->
+ <div class="pull-right">
+ <div class="btn-group">
+ <button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown">
+ Actions
+ <span class="caret"></span>
+ </button>
+ <ul class="dropdown-menu pull-right" role="menu">
+ <li><a href="{{route('accounts.edit',$account->id)}}"><i class="fa fa-pencil fa-fw"></i> Edit</a></li>
+ <li><a href="{{route('accounts.delete',$account->id)}}"><i class="fa fa-trash fa-fw"></i> Delete</a></li>
+ </ul>
+ </div>
+ </div>
+ </div>
+ <div class="panel-body">
+ <div id="overview-chart"></div>
+ </div>
+ </div>
+ </div>
+ <div class="col-lg-4 col-md-6 col-sm-12">
+ <!-- time based navigation -->
+ @include('partials.date_nav')
+ <div class="panel panel-default">
+ <div class="panel-heading">
+ <i class="fa fa-clock-o fa-fw"></i> View options for {{{$account->name}}}
+ </div>
+ <div class="panel-body">
+ <p>
+ @if($range == 'all')
+ <a href="{{route('accounts.show',$account->id)}}/session" class="btn btn-default">Stick to date-range</a>
+ @else
+ <a href="{{route('accounts.show',$account->id)}}/all" class="btn btn-default">Show all transactions</a>
+ @endif
+ </p>
+ </div>
+ </div>
+ </div>
+</div>
+
+
+<div class="row">
+ <div class="col-lg-12 col-md-12 col-sm-12">
+ <div class="panel panel-default">
+ <div class="panel-heading">
+ <i class="fa fa-repeat fa-fw"></i> Transactions
+ </div>
+ <div class="panel-body">
+ @include('list.journals-full')
+ </div>
+ </div>
+</div>
+
+
+
+@stop
+@section('scripts')
+<script type="text/javascript">
+ var accountID = {{{$account->id}}};
+ var view = '{{{$range}}}';
+ var currencyCode = '{{Amount::getCurrencyCode()}}';
+</script>
+<!-- load the libraries and scripts necessary for Google Charts: -->
+<script type="text/javascript" src="https://www.google.com/jsapi"></script>
+<script type="text/javascript" src="js/gcharts.options.js"></script>
+<script type="text/javascript" src="js/gcharts.js"></script>
+<script type="text/javascript" src="js/accounts.js"></script>
+@stop
diff --git a/resources/views/list/journals-full.blade.php b/resources/views/list/journals-full.blade.php
new file mode 100644
index 0000000000..4979b6a428
--- /dev/null
+++ b/resources/views/list/journals-full.blade.php
@@ -0,0 +1,120 @@
+@if(is_object($journals) && method_exists($journals, 'links'))
+{{$journals->links()}}
+@endif
+<table class="table table-striped table-bordered">
+ <tr>
+ <th colspan="2">&nbsp;</th>
+ <th>Description</th>
+ <th>Amount</th>
+ <th>Date</th>
+ <th>From</th>
+ <th>To</th>
+ @if(!isset($hideBudget) || (isset($hideBudget) && $hideBudget=== false))
+ <th><i class="fa fa-tasks fa-fw" title="Budget"></i></th>
+ @endif
+ @if(!isset($hideCategory) || (isset($hideCategory) && $hideCategory=== false))
+ <th><i class="fa fa-bar-chart fa-fw" title="Category"></i></th>
+ @endif
+ @if(!isset($hideBill) || (isset($hideBill) && $hideBill=== false))
+ <th><i class="fa fa-fw fa-rotate-right" title="Bill"></i></th>
+ @endif
+ </tr>
+ @foreach($journals as $journal)
+ @if(!isset($journal->transactions[1]) || !isset($journal->transactions[0]))
+ <tr>
+ <td>
+ <div class="btn-group btn-group-xs">
+ <a href="{{route('transactions.delete',$journal->id)}}" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span></a>
+ </div>
+ </td>
+ <td>&nbsp;</td>
+ <td>{{{$journal->description}}}</td>
+ <td colspan="7"><em>Invalid journal: Found {{$journal->transactions()->count()}} transaction(s)</td>
+ </tr>
+ @else
+ <tr>
+ <td>
+ <div class="btn-group btn-group-xs">
+ <a href="{{route('transactions.edit',$journal->id)}}" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span></a>
+ <a href="{{route('transactions.delete',$journal->id)}}" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span></a>
+ </div>
+ </td>
+ <td>
+ @if($journal->transactiontype->type == 'Withdrawal')
+ <span class="glyphicon glyphicon-arrow-left" title="Withdrawal"></span>
+ @endif
+ @if($journal->transactiontype->type == 'Deposit')
+ <span class="glyphicon glyphicon-arrow-right" title="Deposit"></span>
+ @endif
+ @if($journal->transactiontype->type == 'Transfer')
+ <span class="glyphicon glyphicon-resize-full" title="Transfer"></span>
+ @endif
+ @if($journal->transactiontype->type == 'Opening balance')
+ <span class="glyphicon glyphicon-ban-circle" title="Opening balance"></span>
+ @endif
+ </td>
+ <td>
+ <a href="{{route('transactions.show',$journal->id)}}" title="{{{$journal->description}}}">{{{$journal->description}}}</a>
+ </td>
+ <td>
+ @if($journal->transactiontype->type == 'Withdrawal')
+ <span class="text-danger">{{Amount::formatTransaction($journal->transactions[1],false)}}</span>
+ @endif
+ @if($journal->transactiontype->type == 'Deposit')
+ <span class="text-success">{{Amount::formatTransaction($journal->transactions[1],false)}}</span>
+ @endif
+ @if($journal->transactiontype->type == 'Transfer')
+ <span class="text-info">{{Amount::formatTransaction($journal->transactions[1],false)}}</span>
+ @endif
+ </td>
+ <td>
+ {{$journal->date->format('j F Y')}}
+ </td>
+ <td>
+ @if($journal->transactions[0]->account->accounttype->description == 'Cash account')
+ <span class="text-success">(cash)</span>
+ @else
+ <a href="{{route('accounts.show',$journal->transactions[0]->account_id)}}">{{{$journal->transactions[0]->account->name}}}</a>
+ @endif
+ </td>
+ <td>
+ @if($journal->transactions[1]->account->accounttype->description == 'Cash account')
+ <span class="text-success">(cash)</span>
+ @else
+ <a href="{{route('accounts.show',$journal->transactions[1]->account_id)}}">{{{$journal->transactions[1]->account->name}}}</a>
+ @endif
+ </td>
+ @if(!isset($hideBudget) || (isset($hideBudget) && $hideBudget=== false))
+ <td>
+ <?php $budget = isset($journal->budgets[0]) ? $journal->budgets[0] : null; ?>
+ @if($budget)
+ <a href="{{route('budgets.show',$budget->id)}}">{{{$budget->name}}}</a>
+ @endif
+ </td>
+ @endif
+ @if(!isset($hideCategory) || (isset($hideCategory) && $hideCategory=== false))
+ <td>
+ <?php $category = isset($journal->categories[0]) ? $journal->categories[0] : null; ?>
+ @if($category)
+ <a href="{{route('categories.show',$category->id)}}">{{{$category->name}}}</a>
+ @endif
+ </td>
+ @endif
+ @if(!isset($hideBill) || (isset($hideBill) && $hideBill=== false))
+ <td>
+ @if($journal->bill)
+ <a href="{{route('bills.show',$journal->bill_id)}}">{{{$journal->bill->name}}}</a>
+ @endif
+ </td>
+ @endif
+
+
+ </tr>
+ @endif
+
+ @endforeach
+</table>
+
+@if(is_object($journals) && method_exists($journals, 'links'))
+{{$journals->links()}}
+@endif