Some cleanup.

This commit is contained in:
James Cole
2014-08-10 15:01:46 +02:00
parent fbd056104a
commit d0a30f71cd
35 changed files with 752 additions and 407 deletions

View File

@@ -65,6 +65,11 @@ class EloquentAccountRepository implements AccountRepositoryInterface
return $this->createOrFind($name, $type);
}
/**
* @param \Account $account
*
* @return bool|mixed
*/
public function destroy(\Account $account)
{
$account->delete();
@@ -89,7 +94,8 @@ class EloquentAccountRepository implements AccountRepositoryInterface
}
/**
* @param $name
* @param $name
* @param \AccountType $type
*
* @return mixed
*/
@@ -228,9 +234,10 @@ class EloquentAccountRepository implements AccountRepositoryInterface
}
/**
* @param $data
* @param \Account $account
* @param $data
*
* @return \Account|void
* @return \Account|mixed
*/
public function update(\Account $account, $data)
{

View File

@@ -2,8 +2,6 @@
namespace Firefly\Storage\Budget;
use Carbon\Carbon;
/**
* Interface BudgetRepositoryInterface
*
@@ -12,7 +10,7 @@ use Carbon\Carbon;
interface BudgetRepositoryInterface
{
/**
* @param $data
* @param \Budget $budget
*
* @return mixed
*/
@@ -35,14 +33,6 @@ interface BudgetRepositoryInterface
*/
public function getAsSelectList();
/**
* @param Carbon $date
* @param $range
*
* @return mixed
*/
public function getWithRepetitionsInPeriod(Carbon $date, $range);
/**
* @param $data
*
@@ -51,7 +41,8 @@ interface BudgetRepositoryInterface
public function store($data);
/**
* @param $data
* @param \Budget $budget
* @param $data
*
* @return mixed
*/

View File

@@ -12,6 +12,11 @@ use Carbon\Carbon;
class EloquentBudgetRepository implements BudgetRepositoryInterface
{
/**
* @param \Budget $budget
*
* @return bool|mixed
*/
public function destroy(\Budget $budget)
{
$budget->delete();
@@ -69,18 +74,6 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
return $return;
}
/**
* @param Carbon $date
* @param $range
*
* @return mixed
*/
public function getWithRepetitionsInPeriod(Carbon $date, $range)
{
//return $set;
}
/**
* @param $data
@@ -138,9 +131,10 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
}
/**
* @param $data
* @param \Budget $budget
* @param $data
*
* @return mixed
* @return \Budget|mixed
*/
public function update(\Budget $budget, $data)
{

View File

@@ -15,6 +15,11 @@ interface CategoryRepositoryInterface
*/
public function get();
/**
* @param $categoryId
*
* @return mixed
*/
public function find($categoryId);
/**
@@ -38,10 +43,16 @@ interface CategoryRepositoryInterface
*/
public function store($data);
/**
* @param $category
* @param $data
*
* @return mixed
*/
public function update($category, $data);
/**
* @param $data
* @param $category
*
* @return mixed
*/

View File

@@ -26,6 +26,11 @@ class EloquentCategoryRepository implements CategoryRepositoryInterface
}
/**
* @param $category
*
* @return bool|mixed
*/
public function destroy($category)
{
$category->delete();
@@ -33,6 +38,11 @@ class EloquentCategoryRepository implements CategoryRepositoryInterface
return true;
}
/**
* @param $categoryId
*
* @return mixed
*/
public function find($categoryId)
{
return \Auth::user()->categories()->find($categoryId);
@@ -62,7 +72,7 @@ class EloquentCategoryRepository implements CategoryRepositoryInterface
}
/**
* @param $name
* @param $data
*
* @return \Category|mixed
*/
@@ -77,6 +87,12 @@ class EloquentCategoryRepository implements CategoryRepositoryInterface
return $category;
}
/**
* @param $category
* @param $data
*
* @return mixed
*/
public function update($category, $data)
{
// update account accordingly:

View File

@@ -14,6 +14,11 @@ class EloquentLimitRepository implements LimitRepositoryInterface
{
/**
* @param \Limit $limit
*
* @return bool
*/
public function destroy(\Limit $limit)
{
$limit->delete();

View File

@@ -35,5 +35,10 @@ interface LimitRepositoryInterface
*/
public function find($limitId);
/**
* @param \Limit $limit
*
* @return mixed
*/
public function destroy(\Limit $limit);
}

View File

@@ -12,6 +12,9 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface
{
/**
* @return mixed
*/
public function count()
{
return \Piggybank::leftJoin('accounts', 'accounts.id', '=', 'piggybanks.account_id')->where(
@@ -19,6 +22,11 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface
)->count();
}
/**
* @param $piggyBankId
*
* @return mixed
*/
public function find($piggyBankId)
{
return \Piggybank::leftJoin('accounts', 'accounts.id', '=', 'piggybanks.account_id')->where(
@@ -26,6 +34,9 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface
)->where('piggybanks.id', $piggyBankId)->first(['piggybanks.*']);
}
/**
* @return mixed
*/
public function get()
{
return \Piggybank::with('account')->leftJoin('accounts', 'accounts.id', '=', 'piggybanks.account_id')->where(
@@ -33,6 +44,11 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface
)->get(['piggybanks.*']);
}
/**
* @param $data
*
* @return \Piggybank
*/
public function store($data)
{
var_dump($data);
@@ -56,6 +72,11 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface
return $piggyBank;
}
/**
* @param $data
*
* @return mixed
*/
public function update($data)
{
$piggyBank = $this->find($data['id']);
@@ -74,6 +95,12 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface
return $piggyBank;
}
/**
* @param \Piggybank $piggyBank
* @param $amount
*
* @return mixed|void
*/
public function updateAmount(\Piggybank $piggyBank, $amount)
{
$piggyBank->amount = floatval($amount);

View File

@@ -11,16 +11,43 @@ namespace Firefly\Storage\Piggybank;
interface PiggybankRepositoryInterface
{
/**
* @param $piggyBankId
*
* @return mixed
*/
public function find($piggyBankId);
/**
* @return mixed
*/
public function count();
/**
* @param $data
*
* @return mixed
*/
public function store($data);
/**
* @return mixed
*/
public function get();
/**
* @param \Piggybank $piggyBank
* @param $amount
*
* @return mixed
*/
public function updateAmount(\Piggybank $piggyBank, $amount);
/**
* @param $data
*
* @return mixed
*/
public function update($data);
}

View File

@@ -5,8 +5,18 @@ namespace Firefly\Storage\RecurringTransaction;
use Carbon\Carbon;
/**
* Class EloquentRecurringTransactionRepository
*
* @package Firefly\Storage\RecurringTransaction
*/
class EloquentRecurringTransactionRepository implements RecurringTransactionRepositoryInterface
{
/**
* @param \RecurringTransaction $recurringTransaction
*
* @return bool|mixed
*/
public function destroy(\RecurringTransaction $recurringTransaction)
{
$recurringTransaction->delete();
@@ -14,11 +24,19 @@ class EloquentRecurringTransactionRepository implements RecurringTransactionRepo
return true;
}
/**
* @return mixed
*/
public function get()
{
return \Auth::user()->recurringtransactions()->get();
}
/**
* @param $data
*
* @return mixed|\RecurringTransaction
*/
public function store($data)
{
$recurringTransaction = new \RecurringTransaction;

View File

@@ -3,14 +3,31 @@
namespace Firefly\Storage\RecurringTransaction;
/**
* Interface RecurringTransactionRepositoryInterface
*
* @package Firefly\Storage\RecurringTransaction
*/
interface RecurringTransactionRepositoryInterface
{
/**
* @return mixed
*/
public function get();
/**
* @param $data
*
* @return mixed
*/
public function store($data);
/**
* @param \RecurringTransaction $recurringTransaction
*
* @return mixed
*/
public function destroy(\RecurringTransaction $recurringTransaction);

View File

@@ -45,21 +45,18 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
*/
public function createSimpleJournal(\Account $from, \Account $toAccount, $description, $amount, Carbon $date)
{
\Log::debug('Creating tranaction "' . $description . '".');
$journal = new \TransactionJournal;
$amountFrom = $amount * -1;
$amountTo = $amount;
if (round(floatval($amount), 2) == 0.00) {
\Log::error('Transaction will never save: amount = 0');
$journal->errors()->add('amount', 'Amount must not be zero.');
return $journal;
}
// same account:
if ($from->id == $toAccount->id) {
\Log::error('Accounts cannot be equal');
$journal->errors()->add('account_id', 'Must be different accounts.');
$journal->errors()->add('account_from_id', 'Must be different accounts.');
@@ -94,21 +91,13 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
break;
}
// some debug information:
\Log::debug(
$journalType->type . ': AccountFrom "' . $from->name . '" will gain/lose ' . $amountFrom
. ' and AccountTo "' . $toAccount->name . '" will gain/lose ' . $amountTo
);
if (is_null($journalType)) {
\Log::error('Could not figure out transacion type!');
throw new FireflyException('Could not figure out transaction type.');
}
// always the same currency:
$currency = \TransactionCurrency::where('code', 'EUR')->first();
if (is_null($currency)) {
\Log::error('No currency for journal!');
throw new FireflyException('No currency for journal!');
}
@@ -132,9 +121,8 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
$fromTransaction->description = null;
$fromTransaction->amount = $amountFrom;
if (!$fromTransaction->validate()) {
\Log::error('Cannot create valid transaction (from) for journal #' . $journal->id);
\Log::error('Errors: ' . print_r($fromTransaction->errors()->all(), true));
throw new FireflyException('Cannot create valid transaction (from).');
throw new FireflyException('Cannot create valid transaction (from): ' . $fromTransaction->errors()->first(
));
}
$fromTransaction->save();
@@ -144,9 +132,7 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
$toTransaction->description = null;
$toTransaction->amount = $amountTo;
if (!$toTransaction->validate()) {
\Log::error('Cannot create valid transaction (to) for journal #' . $journal->id);
\Log::error('Errors: ' . print_r($toTransaction->errors()->all(), true));
throw new FireflyException('Cannot create valid transaction (to).');
throw new FireflyException('Cannot create valid transaction (to): ' . $toTransaction->errors()->first());
}
$toTransaction->save();
@@ -155,11 +141,6 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
return $journal;
}
/*
*
*/
/**
* @param $journalId
*
@@ -244,17 +225,6 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
return $query;
}
/**
* @param Carbon $start
* @param Carbon $end
*
* @return mixed
*/
public function getByDateRange(Carbon $start, Carbon $end)
{
die('no impl');
}
/**
* @param int $count
*
@@ -280,6 +250,12 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
return $query;
}
/**
* @param $what
* @param $data
*
* @return mixed|\TransactionJournal
*/
public function store($what, $data)
{
// $fromAccount and $toAccount are found
@@ -325,7 +301,7 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
// // find amount & description:
$description = trim($data['description']);
$amount = floatval($data['amount']);
$date = new \Carbon\Carbon($data['date']);
$date = new Carbon($data['date']);
// try to create a journal:
$transactionJournal = $this->createSimpleJournal($fromAccount, $toAccount, $description, $amount, $date);
@@ -344,6 +320,13 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
return $transactionJournal;
}
/**
* @param \TransactionJournal $journal
* @param $data
*
* @return mixed|\TransactionJournal
* @throws \Firefly\Exception\FireflyException
*/
public function update(\TransactionJournal $journal, $data)
{
/** @var \Firefly\Storage\Category\CategoryRepositoryInterface $catRepository */
@@ -412,7 +395,7 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
$journal->transactions[1]->account()->associate($toAccount);
break;
default:
throw new \Firefly\Exception\FireflyException('Cannot edit this!');
throw new FireflyException('Cannot edit this!');
break;
}

View File

@@ -27,8 +27,20 @@ interface TransactionJournalRepositoryInterface
*/
public function get();
/**
* @param $what
* @param $data
*
* @return mixed
*/
public function store($what, $data);
/**
* @param \TransactionJournal $journal
* @param $data
*
* @return mixed
*/
public function update(\TransactionJournal $journal, $data);
/**
@@ -56,14 +68,6 @@ interface TransactionJournalRepositoryInterface
*/
public function getByAccountAndDate(\Account $account, Carbon $date);
/**
* @param Carbon $start
* @param Carbon $end
*
* @return mixed
*/
public function getByDateRange(Carbon $start, Carbon $end);
/**
* @param int $count
*