mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
More extensions and views. First home view is semi-complete, time to write some tests again.
This commit is contained in:
parent
4192f2bc8f
commit
2f5afc80a3
@ -5,11 +5,13 @@ use Firefly\Storage\Account\AccountRepositoryInterface as ARI;
|
|||||||
class AccountController extends \BaseController
|
class AccountController extends \BaseController
|
||||||
{
|
{
|
||||||
|
|
||||||
public function __construct(ARI $accounts) {
|
public function __construct(ARI $accounts)
|
||||||
|
{
|
||||||
$this->accounts = $accounts;
|
$this->accounts = $accounts;
|
||||||
|
|
||||||
View::share('menu', 'accounts');
|
View::share('menu', 'accounts');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display a listing of the resource.
|
* Display a listing of the resource.
|
||||||
*
|
*
|
||||||
@ -26,6 +28,7 @@ class AccountController extends \BaseController
|
|||||||
];
|
];
|
||||||
|
|
||||||
foreach ($all as $account) {
|
foreach ($all as $account) {
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
switch ($account->accounttype->description) {
|
switch ($account->accounttype->description) {
|
||||||
case 'Default account':
|
case 'Default account':
|
||||||
$list['personal'][] = $account;
|
$list['personal'][] = $account;
|
||||||
@ -41,6 +44,7 @@ class AccountController extends \BaseController
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
}
|
}
|
||||||
|
|
||||||
return View::make('accounts.index')->with('accounts', $list);
|
return View::make('accounts.index')->with('accounts', $list);
|
||||||
@ -76,10 +80,11 @@ class AccountController extends \BaseController
|
|||||||
/**
|
/**
|
||||||
* Display the specified resource.
|
* Display the specified resource.
|
||||||
*
|
*
|
||||||
* @param Account $account
|
* @param int $id
|
||||||
|
*
|
||||||
* @return Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
public function show(Account $account)
|
public function show($id)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,8 @@ use Firefly\Storage\Account\AccountRepositoryInterface as ARI;
|
|||||||
class ChartController extends BaseController
|
class ChartController extends BaseController
|
||||||
{
|
{
|
||||||
|
|
||||||
|
protected $accounts;
|
||||||
|
|
||||||
public function __construct(ARI $accounts)
|
public function __construct(ARI $accounts)
|
||||||
{
|
{
|
||||||
$this->accounts = $accounts;
|
$this->accounts = $accounts;
|
||||||
@ -14,7 +16,7 @@ class ChartController extends BaseController
|
|||||||
/**
|
/**
|
||||||
* Show home charts.
|
* Show home charts.
|
||||||
*/
|
*/
|
||||||
public function home(Account $account = null)
|
public function home($account = null)
|
||||||
{
|
{
|
||||||
// chart
|
// chart
|
||||||
$chart = App::make('gchart');
|
$chart = App::make('gchart');
|
||||||
@ -45,6 +47,10 @@ class ChartController extends BaseController
|
|||||||
$chart->addRowArray($row);
|
$chart->addRowArray($row);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
$account = $this->accounts->find($account);
|
||||||
|
if (is_null($account)) {
|
||||||
|
return View::make('error')->with('message', 'No account found.');
|
||||||
|
}
|
||||||
$chart->addColumn($account->name, 'number');
|
$chart->addColumn($account->name, 'number');
|
||||||
while ($current <= $today) {
|
while ($current <= $today) {
|
||||||
$row = [clone $current, $account->balance(clone $current)];
|
$row = [clone $current, $account->balance(clone $current)];
|
||||||
|
@ -1,17 +1,20 @@
|
|||||||
<?php
|
<?php
|
||||||
use Firefly\Helper\Preferences\PreferencesHelperInterface as PHI;
|
use Firefly\Helper\Preferences\PreferencesHelperInterface as PHI;
|
||||||
use Firefly\Storage\Account\AccountRepositoryInterface as ARI;
|
use Firefly\Storage\Account\AccountRepositoryInterface as ARI;
|
||||||
|
use Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface as TJRI;
|
||||||
|
|
||||||
|
|
||||||
class HomeController extends BaseController
|
class HomeController extends BaseController
|
||||||
{
|
{
|
||||||
protected $accounts;
|
protected $accounts;
|
||||||
protected $preferences;
|
protected $preferences;
|
||||||
|
protected $tj;
|
||||||
|
|
||||||
public function __construct(ARI $accounts, PHI $preferences)
|
public function __construct(ARI $accounts, PHI $preferences, TJRI $tj)
|
||||||
{
|
{
|
||||||
$this->accounts = $accounts;
|
$this->accounts = $accounts;
|
||||||
$this->preferences = $preferences;
|
$this->preferences = $preferences;
|
||||||
|
$this->tj = $tj;
|
||||||
View::share('menu', 'home');
|
View::share('menu', 'home');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,6 +31,11 @@ class HomeController extends BaseController
|
|||||||
$list = $this->accounts->getByIds($pref->data);
|
$list = $this->accounts->getByIds($pref->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get transactions for each account:
|
||||||
|
foreach ($list as $account) {
|
||||||
|
$account->transactionList = $this->tj->getByAccount($account,10);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// build the home screen:
|
// build the home screen:
|
||||||
return View::make('index')->with('count', $count)->with('accounts', $list);
|
return View::make('index')->with('count', $count)->with('accounts', $list);
|
||||||
|
@ -10,6 +10,7 @@ interface AccountRepositoryInterface
|
|||||||
public function count();
|
public function count();
|
||||||
|
|
||||||
public function get();
|
public function get();
|
||||||
|
public function find($id);
|
||||||
public function getByIds($ids);
|
public function getByIds($ids);
|
||||||
public function getDefault();
|
public function getDefault();
|
||||||
public function getActiveDefault();
|
public function getActiveDefault();
|
||||||
|
@ -16,6 +16,11 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
|||||||
return \Auth::user()->accounts()->with('accounttype')->get();
|
return \Auth::user()->accounts()->with('accounttype')->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function find($id)
|
||||||
|
{
|
||||||
|
return \Auth::user()->accounts()->where('id', $id)->first();
|
||||||
|
}
|
||||||
|
|
||||||
public function getByIds($ids)
|
public function getByIds($ids)
|
||||||
{
|
{
|
||||||
return \Auth::user()->accounts()->with('accounttype')->whereIn('id', $ids)->get();
|
return \Auth::user()->accounts()->with('accounttype')->whereIn('id', $ids)->get();
|
||||||
|
@ -10,11 +10,16 @@ class StorageServiceProvider extends ServiceProvider
|
|||||||
// Triggered automatically by Laravel
|
// Triggered automatically by Laravel
|
||||||
public function register()
|
public function register()
|
||||||
{
|
{
|
||||||
// storage:
|
|
||||||
$this->app->bind(
|
$this->app->bind(
|
||||||
'Firefly\Storage\User\UserRepositoryInterface',
|
'Firefly\Storage\User\UserRepositoryInterface',
|
||||||
'Firefly\Storage\User\EloquentUserRepository'
|
'Firefly\Storage\User\EloquentUserRepository'
|
||||||
);
|
);
|
||||||
|
$this->app->bind(
|
||||||
|
'Firefly\Storage\Transaction\TransactionRepositoryInterface',
|
||||||
|
'Firefly\Storage\Transaction\EloquentTransactionRepository'
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$this->app->bind(
|
$this->app->bind(
|
||||||
'Firefly\Storage\Account\AccountRepositoryInterface',
|
'Firefly\Storage\Account\AccountRepositoryInterface',
|
||||||
@ -24,6 +29,7 @@ class StorageServiceProvider extends ServiceProvider
|
|||||||
'Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface',
|
'Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface',
|
||||||
'Firefly\Storage\TransactionJournal\EloquentTransactionJournalRepository'
|
'Firefly\Storage\TransactionJournal\EloquentTransactionJournalRepository'
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->app->bind(
|
$this->app->bind(
|
||||||
'Firefly\Storage\Component\ComponentRepositoryInterface',
|
'Firefly\Storage\Component\ComponentRepositoryInterface',
|
||||||
'Firefly\Storage\Component\EloquentComponentRepository'
|
'Firefly\Storage\Component\EloquentComponentRepository'
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Firefly\Storage\Transaction;
|
||||||
|
|
||||||
|
|
||||||
|
class EloquentTransactionRepository implements TransactionRepositoryInterface {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Firefly\Storage\Transaction;
|
||||||
|
|
||||||
|
|
||||||
|
interface TransactionRepositoryInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -43,24 +43,27 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
|||||||
$journalType = null;
|
$journalType = null;
|
||||||
|
|
||||||
switch (true) {
|
switch (true) {
|
||||||
// is withdrawal from one of your own accounts:
|
case ($from->transactions()->count() == 0 && $to->transactions()->count() == 0):
|
||||||
case ($fromAT == 'Default account'):
|
$journalType = \TransactionType::where('type', 'Opening balance')->first();
|
||||||
$journalType = \TransactionType::where('type', 'Withdrawal')->first();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// both are yours:
|
// both are yours:
|
||||||
case ($fromAT == 'Default account' && $toAT == 'Default account'):
|
case ($fromAT == 'Default account' && $toAT == 'Default account'):
|
||||||
// determin transaction type. If both accounts are new, it's an initial
|
// determin transaction type. If both accounts are new, it's an initial
|
||||||
// balance transfer.
|
// balance transfer.
|
||||||
$journalType = \TransactionType::where('type', 'Transfer')->first();
|
$journalType = \TransactionType::where('type', 'Transfer')->first();
|
||||||
break;
|
break;
|
||||||
case ($from->transactions()->count() == 0 && $to->transactions()->count() == 0):
|
case ($amount < 0):
|
||||||
$journalType = \TransactionType::where('type', 'Opening balance')->first();
|
$journalType = \TransactionType::where('type', 'Deposit')->first();
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
// is deposit into one of your own accounts:
|
// is deposit into one of your own accounts:
|
||||||
case ($toAT == 'Default account'):
|
case ($toAT == 'Default account'):
|
||||||
$journalType = \TransactionType::where('type', 'Deposit')->first();
|
$journalType = \TransactionType::where('type', 'Deposit')->first();
|
||||||
break;
|
break;
|
||||||
|
// is withdrawal from one of your own accounts:
|
||||||
|
case ($fromAT == 'Default account'):
|
||||||
|
$journalType = \TransactionType::where('type', 'Withdrawal')->first();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// some debug information:
|
// some debug information:
|
||||||
@ -126,4 +129,33 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
|||||||
$journal->save();
|
$journal->save();
|
||||||
return $journal;
|
return $journal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function get()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getByAccount(\Account $account, $count = 25)
|
||||||
|
{
|
||||||
|
$accountID = $account->id;
|
||||||
|
$query = \TransactionJournal::
|
||||||
|
with(
|
||||||
|
[
|
||||||
|
'transactions',
|
||||||
|
'transactioncurrency',
|
||||||
|
'transactiontype'
|
||||||
|
]
|
||||||
|
)
|
||||||
|
->take($count)
|
||||||
|
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||||
|
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
|
||||||
|
->where('accounts.id', $accountID)
|
||||||
|
->orderBy('transaction_journals.date', 'DESC')
|
||||||
|
->orderBy('transaction_journals.id', 'DESC')
|
||||||
|
->take($count)
|
||||||
|
->get(['transaction_journals.*']);
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -5,7 +5,10 @@ namespace Firefly\Storage\TransactionJournal;
|
|||||||
|
|
||||||
interface TransactionJournalRepositoryInterface
|
interface TransactionJournalRepositoryInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
public function createSimpleJournal(\Account $from, \Account $to, $description, $amount, \Carbon\Carbon $date);
|
public function createSimpleJournal(\Account $from, \Account $to, $description, $amount, \Carbon\Carbon $date);
|
||||||
|
|
||||||
|
public function get();
|
||||||
|
|
||||||
|
public function getByAccount(\Account $account, $count = 25);
|
||||||
|
|
||||||
}
|
}
|
@ -1,14 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
Route::bind('account', function ($value, $route) {
|
|
||||||
if(Auth::user()) {
|
|
||||||
return Auth::user()->accounts()->find($value);
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// protected routes:
|
// protected routes:
|
||||||
Route::group(['before' => 'auth'], function () {
|
Route::group(['before' => 'auth'], function () {
|
||||||
|
|
||||||
|
@ -7,6 +7,33 @@ class AccountControllerTest extends TestCase
|
|||||||
parent::setUp();
|
parent::setUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testIndex() {
|
||||||
|
|
||||||
|
$list = [
|
||||||
|
'personal' => [],
|
||||||
|
'beneficiaries' => [],
|
||||||
|
'initial' => [],
|
||||||
|
'cash' => []
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
// mock:
|
||||||
|
View::shouldReceive('share');
|
||||||
|
View::shouldReceive('make')->with('accounts.index')->once()->andReturn(\Mockery::self())
|
||||||
|
->shouldReceive('with')->once()->with('accounts',$list);
|
||||||
|
|
||||||
|
// mock account repository:
|
||||||
|
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||||
|
$accounts->shouldReceive('get')->andReturn([]);
|
||||||
|
|
||||||
|
// call
|
||||||
|
$this->call('GET', '/accounts');
|
||||||
|
|
||||||
|
// test
|
||||||
|
$this->assertResponseOk();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public function testCreate()
|
public function testCreate()
|
||||||
{
|
{
|
||||||
// mock:
|
// mock:
|
||||||
@ -22,8 +49,14 @@ class AccountControllerTest extends TestCase
|
|||||||
|
|
||||||
public function testShow()
|
public function testShow()
|
||||||
{
|
{
|
||||||
|
// mock account repository:
|
||||||
|
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||||
|
$accounts->shouldReceive('get')->with(1)->andReturn([]);
|
||||||
|
|
||||||
// the route filters on accounts using Eloquent, maybe fix that instead?
|
// call
|
||||||
$this->assertTrue(true);
|
$this->call('GET', '/accounts/1');
|
||||||
|
|
||||||
|
// test
|
||||||
|
$this->assertResponseOk();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -32,9 +32,11 @@
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
@else
|
@else
|
||||||
|
<!-- ACCOUNTS -->
|
||||||
<div class="row" style="border-top:1px #eee solid;">
|
<div class="row" style="border-top:1px #eee solid;">
|
||||||
@foreach($accounts as $index => $account)
|
@foreach($accounts as $index => $account)
|
||||||
<div class="col-lg-6">
|
<div class="col-lg-6">
|
||||||
|
<h4>{{{$account->name}}} chart</h4>
|
||||||
<div id="chart_{{{$account->id}}}" data-id="{{{$account->id}}}" class="homeChart" data-title="{{{$account->name}}}"></div>
|
<div id="chart_{{{$account->id}}}" data-id="{{{$account->id}}}" class="homeChart" data-title="{{{$account->name}}}"></div>
|
||||||
<p>
|
<p>
|
||||||
Go to <a href="#" title="Overview for {{{$account->name}}}">{{{$account->name}}}</a>
|
Go to <a href="#" title="Overview for {{{$account->name}}}">{{{$account->name}}}</a>
|
||||||
@ -42,11 +44,23 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
@if($index % 2 == 1)
|
@if($index % 2 == 1)
|
||||||
</div><div class="row" style="border-top:1px #eee solid;">
|
</div><div class="row">
|
||||||
@endif
|
@endif
|
||||||
@endforeach
|
@endforeach
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- TRANSACTIONS -->
|
||||||
|
<div class="row">
|
||||||
|
@foreach($accounts as $index => $account)
|
||||||
|
<div class="col-lg-6">
|
||||||
|
<h4>{{$account->name}}</h4>
|
||||||
|
@include('transactions.journals',['journals' => $account->transactionList])
|
||||||
|
</div>
|
||||||
|
@if($index % 2 == 1)
|
||||||
|
</div><div class="row" style="border-top:1px #eee solid;">
|
||||||
|
@endif
|
||||||
|
@endforeach
|
||||||
|
</div>
|
||||||
|
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
|
34
app/views/transactions/journals.blade.php
Normal file
34
app/views/transactions/journals.blade.php
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<table class="table table-bordered table-striped table-condensed">
|
||||||
|
<tr>
|
||||||
|
<th> </th>
|
||||||
|
<th>Description</th>
|
||||||
|
<th>Date</th>
|
||||||
|
<th>Amount</th>
|
||||||
|
</tr>
|
||||||
|
@foreach($account->transactionList as $journal)
|
||||||
|
<tr>
|
||||||
|
|
||||||
|
<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
|
||||||
|
|
||||||
|
</td>
|
||||||
|
<td><a href="#">{{{$journal->description}}}</a></td>
|
||||||
|
<td>{{$journal->date->format('jS M Y')}}</td>
|
||||||
|
<td>
|
||||||
|
@foreach($journal->transactions as $t)
|
||||||
|
@if($t->account_id == $account->id)
|
||||||
|
{{mf($t->amount)}}
|
||||||
|
@endif
|
||||||
|
@endforeach
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
</table>
|
Loading…
Reference in New Issue
Block a user