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:
@@ -10,6 +10,7 @@ interface AccountRepositoryInterface
|
||||
public function count();
|
||||
|
||||
public function get();
|
||||
public function find($id);
|
||||
public function getByIds($ids);
|
||||
public function getDefault();
|
||||
public function getActiveDefault();
|
||||
|
||||
@@ -16,6 +16,11 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
return \Auth::user()->accounts()->with('accounttype')->get();
|
||||
}
|
||||
|
||||
public function find($id)
|
||||
{
|
||||
return \Auth::user()->accounts()->where('id', $id)->first();
|
||||
}
|
||||
|
||||
public function getByIds($ids)
|
||||
{
|
||||
return \Auth::user()->accounts()->with('accounttype')->whereIn('id', $ids)->get();
|
||||
|
||||
@@ -10,11 +10,16 @@ class StorageServiceProvider extends ServiceProvider
|
||||
// Triggered automatically by Laravel
|
||||
public function register()
|
||||
{
|
||||
// storage:
|
||||
$this->app->bind(
|
||||
'Firefly\Storage\User\UserRepositoryInterface',
|
||||
'Firefly\Storage\User\EloquentUserRepository'
|
||||
);
|
||||
$this->app->bind(
|
||||
'Firefly\Storage\Transaction\TransactionRepositoryInterface',
|
||||
'Firefly\Storage\Transaction\EloquentTransactionRepository'
|
||||
);
|
||||
|
||||
|
||||
|
||||
$this->app->bind(
|
||||
'Firefly\Storage\Account\AccountRepositoryInterface',
|
||||
@@ -24,6 +29,7 @@ class StorageServiceProvider extends ServiceProvider
|
||||
'Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface',
|
||||
'Firefly\Storage\TransactionJournal\EloquentTransactionJournalRepository'
|
||||
);
|
||||
|
||||
$this->app->bind(
|
||||
'Firefly\Storage\Component\ComponentRepositoryInterface',
|
||||
'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;
|
||||
|
||||
switch (true) {
|
||||
// is withdrawal from one of your own accounts:
|
||||
case ($fromAT == 'Default account'):
|
||||
$journalType = \TransactionType::where('type', 'Withdrawal')->first();
|
||||
case ($from->transactions()->count() == 0 && $to->transactions()->count() == 0):
|
||||
$journalType = \TransactionType::where('type', 'Opening balance')->first();
|
||||
break;
|
||||
|
||||
// both are yours:
|
||||
case ($fromAT == 'Default account' && $toAT == 'Default account'):
|
||||
// determin transaction type. If both accounts are new, it's an initial
|
||||
// balance transfer.
|
||||
$journalType = \TransactionType::where('type', 'Transfer')->first();
|
||||
break;
|
||||
case ($from->transactions()->count() == 0 && $to->transactions()->count() == 0):
|
||||
$journalType = \TransactionType::where('type', 'Opening balance')->first();
|
||||
case ($amount < 0):
|
||||
$journalType = \TransactionType::where('type', 'Deposit')->first();
|
||||
break;
|
||||
default:
|
||||
// is deposit into one of your own accounts:
|
||||
// is deposit into one of your own accounts:
|
||||
case ($toAT == 'Default account'):
|
||||
$journalType = \TransactionType::where('type', 'Deposit')->first();
|
||||
break;
|
||||
// is withdrawal from one of your own accounts:
|
||||
case ($fromAT == 'Default account'):
|
||||
$journalType = \TransactionType::where('type', 'Withdrawal')->first();
|
||||
break;
|
||||
}
|
||||
|
||||
// some debug information:
|
||||
@@ -126,4 +129,33 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
$journal->save();
|
||||
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
|
||||
{
|
||||
|
||||
public function createSimpleJournal(\Account $from, \Account $to, $description, $amount, \Carbon\Carbon $date);
|
||||
|
||||
}
|
||||
public function get();
|
||||
|
||||
public function getByAccount(\Account $account, $count = 25);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user