Reformatted and checked everything. [skip ci]

This commit is contained in:
James Cole
2014-07-25 13:02:01 +02:00
parent bcd48f2e49
commit 30d5b88769
45 changed files with 980 additions and 330 deletions

View File

@@ -94,7 +94,7 @@ class AccountController extends \BaseController
*/ */
public function show($accountId) public function show($accountId)
{ {
return $accountId;
} }
// //
// //

View File

@@ -2,17 +2,27 @@
use Firefly\Storage\Budget\BudgetRepositoryInterface as BRI; use Firefly\Storage\Budget\BudgetRepositoryInterface as BRI;
/**
* Class BudgetController
*/
class BudgetController extends BaseController class BudgetController extends BaseController
{ {
protected $_budgets; protected $_budgets;
/**
* @param BRI $budgets
*/
public function __construct(BRI $budgets) public function __construct(BRI $budgets)
{ {
$this->_budgets = $budgets; $this->_budgets = $budgets;
View::share('menu', 'budgets'); View::share('menu', 'budgets');
} }
/**
* @return $this|\Illuminate\View\View
* @throws Firefly\Exception\FireflyException
*/
public function indexByDate() public function indexByDate()
{ {
// get a list of dates by getting all repetitions: // get a list of dates by getting all repetitions:
@@ -21,8 +31,8 @@ class BudgetController extends BaseController
foreach ($budgets as $budget) { foreach ($budgets as $budget) {
foreach ($budget->limits as $limit) { foreach ($budget->limits as $limit) {
$dateFormats = \Config::get('firefly.date_formats_by_period.' . $limit->repeat_freq); $dateFormats = \Config::get('firefly.date_formats_by_period.' . $limit->repeat_freq);
if(is_null($dateFormats)) { if (is_null($dateFormats)) {
die('No date formats for ' . $limit->repeat_freq); throw new \Firefly\Exception\FireflyException('No date formats for ' . $limit->repeat_freq);
} }
foreach ($limit->limitrepetitions as $rep) { foreach ($limit->limitrepetitions as $rep) {
@@ -37,9 +47,6 @@ class BudgetController extends BaseController
foreach ($budgets as $budget) { foreach ($budgets as $budget) {
foreach ($budget->limits as $limit) { foreach ($budget->limits as $limit) {
$dateFormats = \Config::get('firefly.date_formats_by_period.' . $limit->repeat_freq); $dateFormats = \Config::get('firefly.date_formats_by_period.' . $limit->repeat_freq);
if(is_null($dateFormats)) {
die('No date formats for ' . $limit->repeat_freq);
}
foreach ($limit->limitrepetitions as $rep) { foreach ($limit->limitrepetitions as $rep) {
$month = $rep->startdate->format($dateFormats['group_date']); $month = $rep->startdate->format($dateFormats['group_date']);
@@ -53,6 +60,9 @@ class BudgetController extends BaseController
} }
/**
* @return $this|\Illuminate\View\View
*/
public function indexByBudget() public function indexByBudget()
{ {
$budgets = $this->_budgets->get(); $budgets = $this->_budgets->get();
@@ -61,12 +71,18 @@ class BudgetController extends BaseController
} }
/**
* @return $this|\Illuminate\View\View
*/
public function create() public function create()
{ {
$periods = \Config::get('firefly.periods_to_text'); $periods = \Config::get('firefly.periods_to_text');
return View::make('budgets.create')->with('periods', $periods); return View::make('budgets.create')->with('periods', $periods);
} }
/**
* @return \Illuminate\Http\RedirectResponse
*/
public function store() public function store()
{ {
@@ -84,6 +100,7 @@ class BudgetController extends BaseController
/** /**
* TODO actual view, actual content. * TODO actual view, actual content.
*
* @param $budgetId * @param $budgetId
* *
* @return string * @return string

View File

@@ -19,9 +19,13 @@ class ChartController extends BaseController
protected $_preferences; protected $_preferences;
protected $_budgets; protected $_budgets;
/** /**
* @param ARI $accounts * @param ARI $accounts
* @param TJRI $journals * @param TJRI $journals
* @param PHI $preferences
* @param tk $toolkit
* @param BRI $budgets
*/ */
public function __construct(ARI $accounts, TJRI $journals, PHI $preferences, tk $toolkit, BRI $budgets) public function __construct(ARI $accounts, TJRI $journals, PHI $preferences, tk $toolkit, BRI $budgets)
{ {
@@ -42,13 +46,9 @@ class ChartController extends BaseController
list($start, $end) = $this->_tk->getDateRangeDates(); list($start, $end) = $this->_tk->getDateRangeDates();
$current = clone $start; $current = clone $start;
$return = []; $return = [];
$account = null;
$today = new Carbon\Carbon;
if (!is_null($accountId)) { $account = !is_null($accountId) ? $this->_accounts->find($accountId) : null;
/** @var \Account $account */ $today = new Carbon\Carbon;
$account = $this->_accounts->find($accountId);
}
if (is_null($account)) { if (is_null($account)) {
@@ -65,8 +65,6 @@ class ChartController extends BaseController
while ($current <= $end) { while ($current <= $end) {
// loop accounts: // loop accounts:
foreach ($accounts as $index => $account) { foreach ($accounts as $index => $account) {
if ($current > $today) { if ($current > $today) {
$return[$index]['data'][] = [$current->timestamp * 1000, $account->predict(clone $current)]; $return[$index]['data'][] = [$current->timestamp * 1000, $account->predict(clone $current)];
} else { } else {
@@ -97,6 +95,8 @@ class ChartController extends BaseController
* @param $day * @param $day
* @param $month * @param $month
* @param $year * @param $year
*
* @return $this|\Illuminate\View\View
*/ */
public function homeAccountInfo($name, $day, $month, $year) public function homeAccountInfo($name, $day, $month, $year)
{ {
@@ -122,15 +122,17 @@ class ChartController extends BaseController
return View::make('charts.info')->with('rows', $result)->with('sum', $sum); return View::make('charts.info')->with('rows', $result)->with('sum', $sum);
} }
/**
* @return \Illuminate\Http\JsonResponse
* @throws Firefly\Exception\FireflyException
*/
public function homeCategories() public function homeCategories()
{ {
list($start, $end) = $this->_tk->getDateRangeDates(); list($start, $end) = $this->_tk->getDateRangeDates();
$account = null;
$result = []; $result = [];
// grab all transaction journals in this period: // grab all transaction journals in this period:
$journals = $this->_journals->getByDateRange($start, $end); $journals = $this->_journals->getByDateRange($start, $end);
$result = [];
foreach ($journals as $journal) { foreach ($journals as $journal) {
// has to be one: // has to be one:
@@ -163,16 +165,20 @@ class ChartController extends BaseController
} }
/**
* @return \Illuminate\Http\JsonResponse
* @throws Firefly\Exception\FireflyException
*/
public function homeBudgets() public function homeBudgets()
{ {
// grab all budgets in the time period, like the index does: // grab all budgets in the time period, like the index does:
// get the budgets for this period: // get the budgets for this period:
$data = []; $data = [];
list($start, $end) = $this->_tk->getDateRangeDates(); list($start) = $this->_tk->getDateRangeDates();
$budgets = $this->_budgets->getWithRepetitionsInPeriod($start, \Session::get('range')); $budgets = $this->_budgets->getWithRepetitionsInPeriod($start, \Session::get('range'));
$repeatFreq = Config::get('firefly.range_to_repeat_freq.'.Session::get('range')); $repeatFreq = Config::get('firefly.range_to_repeat_freq.' . Session::get('range'));
$dateFormats = Config::get('firefly.date_formats_by_period.' . $repeatFreq); $dateFormats = Config::get('firefly.date_formats_by_period.' . $repeatFreq);
if (is_null($dateFormats)) { if (is_null($dateFormats)) {
@@ -210,8 +216,5 @@ class ChartController extends BaseController
} }
return Response::json($data); return Response::json($data);
echo '<pre>';
print_r($data);
} }
} }

View File

@@ -20,6 +20,8 @@ class HomeController extends BaseController
* @param ARI $accounts * @param ARI $accounts
* @param PHI $preferences * @param PHI $preferences
* @param TJRI $journal * @param TJRI $journal
* @param Toolkit $toolkit
* @param BRI $budgets
*/ */
public function __construct(ARI $accounts, PHI $preferences, TJRI $journal, Toolkit $toolkit, BRI $budgets) public function __construct(ARI $accounts, PHI $preferences, TJRI $journal, Toolkit $toolkit, BRI $budgets)
{ {
@@ -76,6 +78,9 @@ class HomeController extends BaseController
); );
} }
/**
* @return \Illuminate\Http\RedirectResponse
*/
public function flush() public function flush()
{ {
Cache::flush(); Cache::flush();

View File

@@ -3,12 +3,19 @@
use Firefly\Storage\Budget\BudgetRepositoryInterface as BRI; use Firefly\Storage\Budget\BudgetRepositoryInterface as BRI;
use Firefly\Storage\Limit\LimitRepositoryInterface as LRI; use Firefly\Storage\Limit\LimitRepositoryInterface as LRI;
/**
* Class LimitController
*/
class LimitController extends BaseController class LimitController extends BaseController
{ {
protected $_budgets; protected $_budgets;
protected $_limits; protected $_limits;
/**
* @param BRI $budgets
* @param LRI $limits
*/
public function __construct(BRI $budgets, LRI $limits) public function __construct(BRI $budgets, LRI $limits)
{ {
$this->_budgets = $budgets; $this->_budgets = $budgets;
@@ -17,6 +24,11 @@ class LimitController extends BaseController
} }
/**
* @param null $budgetId
*
* @return $this|\Illuminate\View\View
*/
public function create($budgetId = null) public function create($budgetId = null)
{ {
$periods = \Config::get('firefly.periods_to_text'); $periods = \Config::get('firefly.periods_to_text');
@@ -31,6 +43,11 @@ class LimitController extends BaseController
)->with('prefilled', $prefilled); )->with('prefilled', $prefilled);
} }
/**
* @param null $limitId
*
* @return $this|\Illuminate\View\View
*/
public function edit($limitId = null) public function edit($limitId = null)
{ {
$limit = $this->_limits->find($limitId); $limit = $this->_limits->find($limitId);
@@ -50,9 +67,15 @@ class LimitController extends BaseController
'periods', $periods 'periods', $periods
); );
} }
return View::make('error')->with('message', 'No such limit.');
} }
/**
* @param null $limitId
*
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
*/
public function update($limitId = null) public function update($limitId = null)
{ {
/** @var \Limit $limit */ /** @var \Limit $limit */
@@ -77,6 +100,9 @@ class LimitController extends BaseController
} }
/**
* @return \Illuminate\Http\RedirectResponse
*/
public function store() public function store()
{ {
// find a limit with these properties, as we might already have one: // find a limit with these properties, as we might already have one:
@@ -88,6 +114,11 @@ class LimitController extends BaseController
} }
} }
/**
* @param $limitId
*
* @return $this|\Illuminate\View\View
*/
public function delete($limitId) public function delete($limitId)
{ {
$limit = $this->_limits->find($limitId); $limit = $this->_limits->find($limitId);
@@ -100,6 +131,11 @@ class LimitController extends BaseController
} }
} }
/**
* @param $limitId
*
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
*/
public function destroy($limitId) public function destroy($limitId)
{ {
$limit = $this->_limits->find($limitId); $limit = $this->_limits->find($limitId);

View File

@@ -1,6 +1,5 @@
<?php <?php
use Carbon\Carbon as Carbon;
use Firefly\Helper\Migration\MigrationHelperInterface as MHI; use Firefly\Helper\Migration\MigrationHelperInterface as MHI;
/** /**
@@ -37,125 +36,10 @@ class MigrationController extends BaseController
if ($migration->validFile()) { if ($migration->validFile()) {
$migration->migrate(); $migration->migrate();
} else { } else {
echo 'Invalid file.'; throw new \Firefly\Exception\FireflyException('Invalid file.');
exit();
} }
} }
echo '<a href="' . route('index') . '">home</a>'; return '<a href="' . route('index') . '">home</a>';
exit();
}
public function limit()
{
$user = User::find(1);
$budgets = [];
// new budget
for ($i = 0; $i < 7; $i++) {
$budget = new Budget();
$budget->user()->associate($user);
$budget->name = 'Some budget #' . rand(1, 2000);
$budget->save();
$budgets[] = $budget;
}
// create a non-repeating limit for this week:
$today = new Carbon('01-07-2014');
$limit = new Limit;
$limit->budget()->associate($budgets[0]);
$limit->amount = 100;
$limit->startdate = $today;
$limit->amount = 100;
$limit->repeats = 0;
$limit->repeat_freq = 'weekly';
var_dump($limit->save());
var_dump($limit->errors()->all());
// create a repeating daily limit:
$day = new Limit;
$day->budget()->associate($budgets[1]);
$day->amount = 100;
$day->startdate = $today;
$day->amount = 100;
$day->repeats = 1;
$day->repeat_freq = 'daily';
$day->save();
// repeating weekly limit.
$week = new Limit;
$week->budget()->associate($budgets[2]);
$week->amount = 100;
$week->startdate = $today;
$week->amount = 100;
$week->repeats = 1;
$week->repeat_freq = 'weekly';
$week->save();
// repeating monthly limit
$month = new Limit;
$month->budget()->associate($budgets[3]);
$month->amount = 100;
$month->startdate = $today;
$month->amount = 100;
$month->repeats = 1;
$month->repeat_freq = 'monthly';
$month->save();
// quarter
$quarter = new Limit;
$quarter->budget()->associate($budgets[4]);
$quarter->amount = 100;
$quarter->startdate = $today;
$quarter->amount = 100;
$quarter->repeats = 1;
$quarter->repeat_freq = 'quarterly';
$quarter->save();
// six months
$six = new Limit;
$six->budget()->associate($budgets[5]);
$six->amount = 100;
$six->startdate = $today;
$six->amount = 100;
$six->repeats = 1;
$six->repeat_freq = 'half-year';
$six->save();
// year
$yearly = new Limit;
$yearly->budget()->associate($budgets[6]);
$yearly->amount = 100;
$yearly->startdate = $today;
$yearly->amount = 100;
$yearly->repeats = 1;
$yearly->repeat_freq = 'yearly';
$yearly->save();
// create a repeating weekly limit:
// create a repeating monthly limit:
foreach ($budgets as $budget) {
echo '#' . $budget->id . ': ' . $budget->name . ':<br />';
foreach ($budget->limits()->get() as $limit) {
echo '&nbsp;&nbsp;Limit #' . $limit->id . ', amount: ' . $limit->amount . ', start: '
. $limit->startdate->format('D d-m-Y') . ', repeats: '
. $limit->repeats . ', repeat_freq: ' . $limit->repeat_freq . '<br />';
foreach ($limit->limitrepetitions()->get() as $rep) {
echo '&nbsp;&nbsp;&nbsp;&nbsp;rep: #' . $rep->id . ', from ' . $rep->startdate->format('D d-m-Y')
. ' to '
. $rep->enddate->format('D d-m-Y') . '<br>';
}
}
}
return '';
} }
/** /**

View File

@@ -34,6 +34,11 @@ class TransactionController extends BaseController
View::share('menu', 'home'); View::share('menu', 'home');
} }
/**
* @param $what
*
* @return $this|\Illuminate\View\View
*/
public function create($what) public function create($what)
{ {
// get accounts with names and id's. // get accounts with names and id's.
@@ -44,12 +49,16 @@ class TransactionController extends BaseController
$budgets[0] = '(no budget)'; $budgets[0] = '(no budget)';
return View::make('transactions.create')->with('accounts', $accounts)->with('budgets', $budgets)->with( return View::make('transactions.create')->with('accounts', $accounts)->with('budgets', $budgets)->with(
'what', $what 'what', $what
); );
} }
/**
* @param $what
*
* @return \Illuminate\Http\RedirectResponse
*/
public function store($what) public function store($what)
{ {
// $fromAccount and $toAccount are found // $fromAccount and $toAccount are found
@@ -73,12 +82,8 @@ class TransactionController extends BaseController
break; break;
} }
// fall back to cash if necessary: // fall back to cash if necessary:
if (is_null($fromAccount)) { $fromAccount = is_null($fromAccount) ? $fromAccount = $this->_accounts->getCashAccount() : $fromAccount;
$fromAccount = $this->_accounts->getCashAccount(); $toAccount = is_null($toAccount) ? $toAccount = $this->_accounts->getCashAccount() : $toAccount;
}
if (is_null($toAccount)) {
$toAccount = $this->_accounts->getCashAccount();
}
// create or find category: // create or find category:
$category = $this->_categories->createOrFind(Input::get('category')); $category = $this->_categories->createOrFind(Input::get('category'));
@@ -109,24 +114,29 @@ class TransactionController extends BaseController
Session::flash('success', 'Transaction saved'); Session::flash('success', 'Transaction saved');
if(Input::get('create') == '1') { if (Input::get('create') == '1') {
return Redirect::route('transactions.create',$what)->withInput(); return Redirect::route('transactions.create', $what)->withInput();
} else { } else {
return Redirect::route('index'); return Redirect::route('index');
} }
} }
/**
* @return $this|\Illuminate\View\View
*/
public function index() public function index()
{ {
$transactions = $this->_journal->paginate(25); $transactions = $this->_journal->paginate(25);
return View::make('transactions.index')->with('transactions', $transactions); return View::make('transactions.index')->with('transactions', $transactions);
} }
/**
* @param $journalId
*
* @return $this|\Illuminate\View\View
*/
public function show($journalId) public function show($journalId)
{ {
$journal = $this->_journal->find($journalId); $journal = $this->_journal->find($journalId);
@@ -136,6 +146,11 @@ class TransactionController extends BaseController
return View::make('error')->with('message', 'Invalid journal'); return View::make('error')->with('message', 'Invalid journal');
} }
/**
* @param $journalId
*
* @return $this|\Illuminate\View\View
*/
public function edit($journalId) public function edit($journalId)
{ {
$journal = $this->_journal->find($journalId); $journal = $this->_journal->find($journalId);

View File

@@ -4,8 +4,14 @@
namespace Firefly\Database; namespace Firefly\Database;
use LaravelBook\Ardent\Ardent;
abstract class SingleTableInheritanceEntity extends \LaravelBook\Ardent\Ardent /**
* Class SingleTableInheritanceEntity
*
* @package Firefly\Database
*/
abstract class SingleTableInheritanceEntity extends Ardent
{ {
/** /**
* The field that stores the subclass * The field that stores the subclass
@@ -20,15 +26,26 @@ abstract class SingleTableInheritanceEntity extends \LaravelBook\Ardent\Ardent
*/ */
protected $isSubclass = false; protected $isSubclass = false;
public function newFromBuilder($attributes = array()) /**
* @param array $attributes
*
* @return \Illuminate\Database\Eloquent\Model|static
*/
public function newFromBuilder($attributes = [])
{ {
$instance = $this->mapData((array)$attributes)->newInstance(array(), true); $instance = $this->mapData((array)$attributes)->newInstance([], true);
$instance->setRawAttributes((array)$attributes, true); $instance->setRawAttributes((array)$attributes, true);
return $instance; return $instance;
} }
// if no subclass is defined, function as normal
/**
* if no subclass is defined, function as normal
*
* @param array $attributes
*
* @return \Illuminate\Database\Eloquent\Model|static
*/
public function mapData(array $attributes) public function mapData(array $attributes)
{ {
if (!$this->subclassField) { if (!$this->subclassField) {
@@ -38,9 +55,16 @@ abstract class SingleTableInheritanceEntity extends \LaravelBook\Ardent\Ardent
return new $attributes[$this->subclassField]; return new $attributes[$this->subclassField];
} }
// instead of using $this->newInstance(), call
// newInstance() on the object from mapData
/**
*
* instead of using $this->newInstance(), call
* newInstance() on the object from mapData
*
* @param bool $excludeDeleted
*
* @return \Illuminate\Database\Eloquent\Builder|static
*/
public function newQuery($excludeDeleted = true) public function newQuery($excludeDeleted = true)
{ {
// If using Laravel 4.0.x then use the following commented version of this command // If using Laravel 4.0.x then use the following commented version of this command
@@ -64,16 +88,29 @@ abstract class SingleTableInheritanceEntity extends \LaravelBook\Ardent\Ardent
return $builder; return $builder;
} }
/**
* @return bool
*/
public function isSubclass() public function isSubclass()
{ {
return $this->isSubclass; return $this->isSubclass;
} }
// ensure that the subclass field is assigned on save /**
* ensure that the subclass field is assigned on save
*
* @param array $rules
* @param array $customMessages
* @param array $options
* @param callable $beforeSave
* @param callable $afterSave
*
* @return bool
*/
public function save( public function save(
array $rules = array(), array $rules = [],
array $customMessages = array(), array $customMessages = [],
array $options = array(), array $options = [],
\Closure $beforeSave = null, \Closure $beforeSave = null,
\Closure $afterSave = null \Closure $afterSave = null
) { ) {

View File

@@ -3,6 +3,11 @@
namespace Firefly\Exception; namespace Firefly\Exception;
/**
* Class FireflyException
*
* @package Firefly\Exception
*/
class FireflyException extends \Exception class FireflyException extends \Exception
{ {

View File

@@ -3,6 +3,11 @@
namespace Firefly\Helper; namespace Firefly\Helper;
/**
* Class MigrationException
*
* @package Firefly\Helper
*/
class MigrationException extends \Exception class MigrationException extends \Exception
{ {

View File

@@ -1,8 +1,18 @@
<?php <?php
namespace Firefly\Helper\Email; namespace Firefly\Helper\Email;
/**
* Class EmailHelper
*
* @package Firefly\Helper\Email
*/
class EmailHelper implements EmailHelperInterface class EmailHelper implements EmailHelperInterface
{ {
/**
* @param \User $user
*
* @return mixed|void
*/
public function sendVerificationMail(\User $user) public function sendVerificationMail(\User $user)
{ {
@@ -19,6 +29,11 @@ class EmailHelper implements EmailHelperInterface
); );
} }
/**
* @param \User $user
*
* @return mixed|void
*/
public function sendPasswordMail(\User $user) public function sendPasswordMail(\User $user)
{ {
@@ -37,6 +52,11 @@ class EmailHelper implements EmailHelperInterface
); );
} }
/**
* @param \User $user
*
* @return mixed|void
*/
public function sendResetVerification(\User $user) public function sendResetVerification(\User $user)
{ {
$reset = \Str::random(32); $reset = \Str::random(32);

View File

@@ -2,13 +2,33 @@
namespace Firefly\Helper\Email; namespace Firefly\Helper\Email;
/**
* Interface EmailHelperInterface
*
* @package Firefly\Helper\Email
*/
interface EmailHelperInterface interface EmailHelperInterface
{ {
/**
* @param \User $user
*
* @return mixed
*/
public function sendVerificationMail(\User $user); public function sendVerificationMail(\User $user);
/**
* @param \User $user
*
* @return mixed
*/
public function sendPasswordMail(\User $user); public function sendPasswordMail(\User $user);
/**
* @param \User $user
*
* @return mixed
*/
public function sendResetVerification(\User $user); public function sendResetVerification(\User $user);
} }

View File

@@ -3,11 +3,18 @@ namespace Firefly\Helper;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
/**
* Class HelperServiceProvider
*
* @package Firefly\Helper
*/
class HelperServiceProvider extends ServiceProvider class HelperServiceProvider extends ServiceProvider
{ {
// Triggered automatically by Laravel /**
* Triggered automatically by Laravel
*/
public function register() public function register()
{ {
// mail: // mail:

View File

@@ -3,19 +3,33 @@
namespace Firefly\Helper\Migration; namespace Firefly\Helper\Migration;
use Firefly\Helper\MigrationException; use Carbon\Carbon;
use Firefly\Exception\FireflyException;
/**
* Class MigrationHelper
*
* @package Firefly\Helper\Migration
*/
class MigrationHelper implements MigrationHelperInterface class MigrationHelper implements MigrationHelperInterface
{ {
protected $path; protected $path;
protected $JSON; protected $JSON;
protected $map = []; protected $map = [];
/**
* @param $path
*
* @return mixed|void
*/
public function loadFile($path) public function loadFile($path)
{ {
$this->path = $path; $this->path = $path;
} }
/**
* @return bool
*/
public function validFile() public function validFile()
{ {
// file does not exist: // file does not exist:
@@ -39,6 +53,9 @@ class MigrationHelper implements MigrationHelperInterface
return true; return true;
} }
/**
* @return bool
*/
public function migrate() public function migrate()
{ {
\Log::info('Start of migration.'); \Log::info('Start of migration.');
@@ -62,7 +79,7 @@ class MigrationHelper implements MigrationHelperInterface
$this->_importLimits(); $this->_importLimits();
} catch (\Firefly\Exception\FireflyException $e) { } catch (FireflyException $e) {
\DB::rollBack(); \DB::rollBack();
\Log::error('Rollback because of error!'); \Log::error('Rollback because of error!');
\Log::error($e->getMessage()); \Log::error($e->getMessage());
@@ -74,6 +91,9 @@ class MigrationHelper implements MigrationHelperInterface
return true; return true;
} }
/**
*
*/
protected function _createCashAccount() protected function _createCashAccount()
{ {
$cashAT = \AccountType::where('description', 'Cash account')->first(); $cashAT = \AccountType::where('description', 'Cash account')->first();
@@ -84,6 +104,9 @@ class MigrationHelper implements MigrationHelperInterface
$this->map['cash'] = $cash; $this->map['cash'] = $cash;
} }
/**
*
*/
protected function _importAccounts() protected function _importAccounts()
{ {
@@ -97,7 +120,7 @@ class MigrationHelper implements MigrationHelperInterface
} else { } else {
$account = $accounts->storeWithInitialBalance( $account = $accounts->storeWithInitialBalance(
['name' => $entry->name], ['name' => $entry->name],
new \Carbon\Carbon($entry->openingbalancedate), new Carbon($entry->openingbalancedate),
floatval($entry->openingbalance) floatval($entry->openingbalance)
); );
} }
@@ -106,6 +129,9 @@ class MigrationHelper implements MigrationHelperInterface
} }
} }
/**
*
*/
protected function _importComponents() protected function _importComponents()
{ {
$beneficiaryAT = \AccountType::where('description', 'Beneficiary account')->first(); $beneficiaryAT = \AccountType::where('description', 'Beneficiary account')->first();
@@ -128,6 +154,12 @@ class MigrationHelper implements MigrationHelperInterface
} }
} }
/**
* @param $component
* @param \AccountType $beneficiaryAT
*
* @return mixed
*/
protected function _importBeneficiary($component, \AccountType $beneficiaryAT) protected function _importBeneficiary($component, \AccountType $beneficiaryAT)
{ {
/** @var \Firefly\Storage\Account\AccountRepositoryInterface $accounts */ /** @var \Firefly\Storage\Account\AccountRepositoryInterface $accounts */
@@ -140,6 +172,11 @@ class MigrationHelper implements MigrationHelperInterface
); );
} }
/**
* @param $component
*
* @return mixed
*/
protected function _importCategory($component) protected function _importCategory($component)
{ {
/** @var \Firefly\Storage\Component\ComponentRepositoryInterface $components */ /** @var \Firefly\Storage\Component\ComponentRepositoryInterface $components */
@@ -147,6 +184,11 @@ class MigrationHelper implements MigrationHelperInterface
return $components->store(['name' => $component->name, 'class' => 'Category']); return $components->store(['name' => $component->name, 'class' => 'Category']);
} }
/**
* @param $component
*
* @return mixed
*/
protected function _importBudget($component) protected function _importBudget($component)
{ {
/** @var \Firefly\Storage\Component\ComponentRepositoryInterface $components */ /** @var \Firefly\Storage\Component\ComponentRepositoryInterface $components */
@@ -154,39 +196,9 @@ class MigrationHelper implements MigrationHelperInterface
return $components->store(['name' => $component->name, 'class' => 'Budget']); return $components->store(['name' => $component->name, 'class' => 'Budget']);
} }
protected function _importLimits() /**
{ *
\Log::info('Importing limits'); */
foreach ($this->JSON->limits as $entry) {
\Log::debug(
'Now at #' . $entry->id . ': EUR ' . $entry->amount . ' for month ' . $entry->date
. ' and componentID: ' . $entry->component_id
);
$budget = isset($this->map['budgets'][$entry->component_id]) ? $this->map['budgets'][$entry->component_id]
: null;
if (!is_null($budget)) {
\Log::debug('Found budget for this limit: #' . $budget->id . ', ' . $budget->name);
$limit = new \Limit;
$limit->budget()->associate($budget);
$limit->startdate = new \Carbon\Carbon($entry->date);
$limit->amount = floatval($entry->amount);
$limit->repeats = 0;
$limit->repeat_freq = 'monthly';
try {
$limit->save();
} catch (\Exception $e) {
}
} else {
\Log::warning('No budget for this limit!');
}
// create repeat thing should not be necessary.
}
}
protected function _importTransactions() protected function _importTransactions()
{ {
@@ -215,7 +227,6 @@ class MigrationHelper implements MigrationHelperInterface
} }
foreach ($this->JSON->transactions as $entry) { foreach ($this->JSON->transactions as $entry) {
$id = $entry->id;
// to properly save the amount, do it times -1: // to properly save the amount, do it times -1:
$amount = $entry->amount * -1; $amount = $entry->amount * -1;
@@ -227,7 +238,7 @@ class MigrationHelper implements MigrationHelperInterface
/** @var \Account $toAccount */ /** @var \Account $toAccount */
$toAccount = isset($beneficiaries[$entry->id]) ? $beneficiaries[$entry->id] : $this->map['cash']; $toAccount = isset($beneficiaries[$entry->id]) ? $beneficiaries[$entry->id] : $this->map['cash'];
$date = new \Carbon\Carbon($entry->date); $date = new Carbon($entry->date);
$journal = $journals->createSimpleJournal($fromAccount, $toAccount, $entry->description, $amount, $date); $journal = $journals->createSimpleJournal($fromAccount, $toAccount, $entry->description, $amount, $date);
// save budgets and categories, on the journal // save budgets and categories, on the journal
@@ -243,13 +254,15 @@ class MigrationHelper implements MigrationHelperInterface
} }
} }
/**
*
*/
protected function _importTransfers() protected function _importTransfers()
{ {
/** @var \Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface $journals */ /** @var \Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface $journals */
$journals = \App::make('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface'); $journals = \App::make('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
foreach ($this->JSON->transfers as $entry) { foreach ($this->JSON->transfers as $entry) {
$id = $entry->id;
// to properly save the amount, do it times 1 (?): // to properly save the amount, do it times 1 (?):
$amount = $entry->amount * -1; $amount = $entry->amount * -1;
@@ -262,9 +275,45 @@ class MigrationHelper implements MigrationHelperInterface
$toAccount = isset($this->map['accounts'][$entry->accountto_id]) $toAccount = isset($this->map['accounts'][$entry->accountto_id])
? $this->map['accounts'][$entry->accountfrom_id] : false; ? $this->map['accounts'][$entry->accountfrom_id] : false;
$date = new \Carbon\Carbon($entry->date); $date = new Carbon($entry->date);
$journals->createSimpleJournal($fromAccount, $toAccount, $entry->description, $amount, $date); $journals->createSimpleJournal($fromAccount, $toAccount, $entry->description, $amount, $date);
} }
} }
/**
*
*/
protected function _importLimits()
{
\Log::info('Importing limits');
foreach ($this->JSON->limits as $entry) {
\Log::debug(
'Now at #' . $entry->id . ': EUR ' . $entry->amount . ' for month ' . $entry->date
. ' and componentID: ' . $entry->component_id
);
$budget = isset($this->map['budgets'][$entry->component_id]) ? $this->map['budgets'][$entry->component_id]
: null;
if (!is_null($budget)) {
\Log::debug('Found budget for this limit: #' . $budget->id . ', ' . $budget->name);
$limit = new \Limit;
$limit->budget()->associate($budget);
$limit->startdate = new Carbon($entry->date);
$limit->amount = floatval($entry->amount);
$limit->repeats = 0;
$limit->repeat_freq = 'monthly';
try {
$limit->save();
} catch (\Exception $e) {
}
} else {
\Log::warning('No budget for this limit!');
}
// create repeat thing should not be necessary.
}
}
} }

View File

@@ -2,13 +2,28 @@
namespace Firefly\Helper\Migration; namespace Firefly\Helper\Migration;
/**
* Interface MigrationHelperInterface
*
* @package Firefly\Helper\Migration
*/
interface MigrationHelperInterface interface MigrationHelperInterface
{ {
/**
* @param $path
*
* @return mixed
*/
public function loadFile($path); public function loadFile($path);
/**
* @return mixed
*/
public function validFile(); public function validFile();
/**
* @return mixed
*/
public function migrate(); public function migrate();
} }

View File

@@ -1,8 +1,19 @@
<?php <?php
namespace Firefly\Helper\Preferences; namespace Firefly\Helper\Preferences;
/**
* Class PreferencesHelper
*
* @package Firefly\Helper\Preferences
*/
class PreferencesHelper implements PreferencesHelperInterface class PreferencesHelper implements PreferencesHelperInterface
{ {
/**
* @param $name
* @param null $default
*
* @return mixed|null|\Preference
*/
public function get($name, $default = null) public function get($name, $default = null)
{ {
$pref = \Preference::where('user_id', \Auth::user()->id)->where('name', $name)->first(); $pref = \Preference::where('user_id', \Auth::user()->id)->where('name', $name)->first();
@@ -17,9 +28,16 @@ class PreferencesHelper implements PreferencesHelperInterface
// create preference, return that: // create preference, return that:
return $this->set($name, $default); return $this->set($name, $default);
} }
return null;
} }
/**
* @param $name
* @param $value
*
* @return mixed|\Preference
*/
public function set($name, $value) public function set($name, $value)
{ {
$pref = \Preference::where('user_id', \Auth::user()->id)->where('name', $name)->first(); $pref = \Preference::where('user_id', \Auth::user()->id)->where('name', $name)->first();

View File

@@ -1,10 +1,29 @@
<?php <?php
namespace Firefly\Helper\Preferences; namespace Firefly\Helper\Preferences;
/**
* Interface PreferencesHelperInterface
*
* @package Firefly\Helper\Preferences
*/
interface PreferencesHelperInterface interface PreferencesHelperInterface
{ {
/**
* @param $name
* @param $value
*
* @return mixed
*/
public function set($name, $value); public function set($name, $value);
/**
* @param $name
* @param null $default
*
* @return mixed
*/
public function get($name, $default = null); public function get($name, $default = null);
} }

View File

@@ -2,6 +2,8 @@
namespace Firefly\Helper\Toolkit; namespace Firefly\Helper\Toolkit;
use Carbon\Carbon;
/** /**
* Class Toolkit * Class Toolkit
* *
@@ -37,10 +39,10 @@ class Toolkit implements ToolkitInterface
} }
// switch $range, update range or something: // switch $range, update range or something:
$start = \Session::has('start') ? \Session::get('start') : new \Carbon\Carbon(); $start = \Session::has('start') ? \Session::get('start') : new Carbon;
$end = \Session::has('end') ? \Session::get('end') : new \Carbon\Carbon(); $end = \Session::has('end') ? \Session::get('end') : new Carbon;
$today = new \Carbon\Carbon; $today = new Carbon;
\Log::debug('Start: ' . $start.' ('.\Session::has('start').')'); \Log::debug('Start: ' . $start . ' (' . \Session::has('start') . ')');
\Log::debug('End: ' . $end); \Log::debug('End: ' . $end);
// see if we have to do a prev / next thing: // see if we have to do a prev / next thing:
@@ -58,8 +60,8 @@ class Toolkit implements ToolkitInterface
case 'custom': case 'custom':
// when range is custom AND input, we ignore $today // when range is custom AND input, we ignore $today
if (\Input::get('start') && \Input::get('end')) { if (\Input::get('start') && \Input::get('end')) {
$start = new \Carbon\Carbon(\Input::get('start')); $start = new Carbon(\Input::get('start'));
$end = new \Carbon\Carbon(\Input::get('end')); $end = new Carbon(\Input::get('end'));
} else { } else {
$start = \Session::get('start'); $start = \Session::get('start');
$end = \Session::get('end'); $end = \Session::get('end');
@@ -147,11 +149,14 @@ class Toolkit implements ToolkitInterface
return \Redirect::route('index'); return \Redirect::route('index');
} }
return; return null;
} }
/**
* @return array
*/
public function getDateRangeDates() public function getDateRangeDates()
{ {
return [\Session::get('start'), \Session::get('end')]; return [\Session::get('start'), \Session::get('end')];

View File

@@ -2,11 +2,21 @@
namespace Firefly\Helper\Toolkit; namespace Firefly\Helper\Toolkit;
/**
* Interface ToolkitInterface
*
* @package Firefly\Helper\Toolkit
*/
interface ToolkitInterface interface ToolkitInterface
{ {
/**
* @return mixed
*/
public function getDateRange(); public function getDateRange();
/**
* @return mixed
*/
public function getDateRangeDates(); public function getDateRangeDates();
} }

View File

@@ -3,36 +3,101 @@
namespace Firefly\Storage\Account; namespace Firefly\Storage\Account;
use Carbon\Carbon;
/**
* Interface AccountRepositoryInterface
*
* @package Firefly\Storage\Account
*/
interface AccountRepositoryInterface interface AccountRepositoryInterface
{ {
/**
* @return mixed
*/
public function count(); public function count();
/**
* @return mixed
*/
public function get(); public function get();
/**
* @return mixed
*/
public function getBeneficiaries(); public function getBeneficiaries();
public function find($id); /**
* @param $accountId
*
* @return mixed
*/
public function find($accountId);
/**
* @param $name
*
* @return mixed
*/
public function findByName($name); public function findByName($name);
/**
* @return mixed
*/
public function getCashAccount(); public function getCashAccount();
/**
* @param $ids
*
* @return mixed
*/
public function getByIds($ids); public function getByIds($ids);
/**
* @return mixed
*/
public function getDefault(); public function getDefault();
/**
* @return mixed
*/
public function getActiveDefault(); public function getActiveDefault();
/**
* @return mixed
*/
public function getActiveDefaultAsSelectList(); public function getActiveDefaultAsSelectList();
/**
* @param $data
*
* @return mixed
*/
public function store($data); public function store($data);
public function storeWithInitialBalance($data, \Carbon\Carbon $date, $amount = 0); /**
* @param $data
* @param Carbon $date
* @param int $amount
*
* @return mixed
*/
public function storeWithInitialBalance($data, Carbon $date, $amount = 0);
/**
* @param $name
*
* @return mixed
*/
public function createOrFindBeneficiary($name); public function createOrFindBeneficiary($name);
/**
* @param $name
* @param \AccountType $type
*
* @return mixed
*/
public function createOrFind($name, \AccountType $type); public function createOrFind($name, \AccountType $type);
} }

View File

@@ -3,19 +3,37 @@
namespace Firefly\Storage\Account; namespace Firefly\Storage\Account;
use Carbon\Carbon;
use Firefly\Exception\FireflyException;
use Illuminate\Database\QueryException;
/**
* Class EloquentAccountRepository
*
* @package Firefly\Storage\Account
*/
class EloquentAccountRepository implements AccountRepositoryInterface class EloquentAccountRepository implements AccountRepositoryInterface
{ {
public $validator; public $validator;
/**
*
*/
public function __construct() public function __construct()
{ {
} }
/**
* @return mixed
*/
public function get() public function get()
{ {
return \Auth::user()->accounts()->with('accounttype')->orderBy('name', 'ASC')->get(); return \Auth::user()->accounts()->with('accounttype')->orderBy('name', 'ASC')->get();
} }
/**
* @return mixed
*/
public function getBeneficiaries() public function getBeneficiaries()
{ {
$list = \Auth::user()->accounts()->leftJoin( $list = \Auth::user()->accounts()->leftJoin(
@@ -27,11 +45,21 @@ class EloquentAccountRepository implements AccountRepositoryInterface
return $list; return $list;
} }
public function find($id) /**
* @param $accountId
*
* @return mixed
*/
public function find($accountId)
{ {
return \Auth::user()->accounts()->where('id', $id)->first(); return \Auth::user()->accounts()->where('id', $accountId)->first();
} }
/**
* @param $ids
*
* @return array|mixed
*/
public function getByIds($ids) public function getByIds($ids)
{ {
if (count($ids) > 0) { if (count($ids) > 0) {
@@ -41,6 +69,9 @@ class EloquentAccountRepository implements AccountRepositoryInterface
} }
} }
/**
* @return mixed
*/
public function getDefault() public function getDefault()
{ {
return \Auth::user()->accounts()->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id') return \Auth::user()->accounts()->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
@@ -49,6 +80,9 @@ class EloquentAccountRepository implements AccountRepositoryInterface
->orderBy('accounts.name', 'ASC')->get(['accounts.*']); ->orderBy('accounts.name', 'ASC')->get(['accounts.*']);
} }
/**
* @return mixed
*/
public function getActiveDefault() public function getActiveDefault()
{ {
return \Auth::user()->accounts()->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id') return \Auth::user()->accounts()->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
@@ -57,6 +91,9 @@ class EloquentAccountRepository implements AccountRepositoryInterface
->get(['accounts.*']); ->get(['accounts.*']);
} }
/**
* @return array|mixed
*/
public function getActiveDefaultAsSelectList() public function getActiveDefaultAsSelectList()
{ {
$list = \Auth::user()->accounts()->leftJoin( $list = \Auth::user()->accounts()->leftJoin(
@@ -72,13 +109,24 @@ class EloquentAccountRepository implements AccountRepositoryInterface
return $return; return $return;
} }
/**
* @return mixed
*/
public function count() public function count()
{ {
return \Auth::user()->accounts()->count(); return \Auth::user()->accounts()->count();
} }
public function storeWithInitialBalance($data, \Carbon\Carbon $date, $amount = 0) /**
* @param $data
* @param Carbon $date
* @param int $amount
*
* @return \Account|mixed
* @throws \Firefly\Exception\FireflyException
*/
public function storeWithInitialBalance($data, Carbon $date, $amount = 0)
{ {
$account = $this->store($data); $account = $this->store($data);
@@ -91,7 +139,7 @@ class EloquentAccountRepository implements AccountRepositoryInterface
$initial->active = 0; $initial->active = 0;
try { try {
$initial->save(); $initial->save();
} catch (\Illuminate\Database\QueryException $e) { } catch (QueryException $e) {
\Log::error('DB ERROR: ' . $e->getMessage()); \Log::error('DB ERROR: ' . $e->getMessage());
throw new FireflyException('Could not save counterbalance account for ' . $data['name']); throw new FireflyException('Could not save counterbalance account for ' . $data['name']);
} }
@@ -110,6 +158,12 @@ class EloquentAccountRepository implements AccountRepositoryInterface
} }
/**
* @param $data
*
* @return \Account|mixed
* @throws \Firefly\Exception\FireflyException
*/
public function store($data) public function store($data)
{ {
$defaultAT = \AccountType::where('description', 'Default account')->first(); $defaultAT = \AccountType::where('description', 'Default account')->first();
@@ -123,14 +177,19 @@ class EloquentAccountRepository implements AccountRepositoryInterface
$account->active = isset($data['active']) ? $data['active'] : 1; $account->active = isset($data['active']) ? $data['active'] : 1;
try { try {
$account->save(); $account->save();
} catch (\Illuminate\Database\QueryException $e) { } catch (QueryException $e) {
\Log::error('DB ERROR: ' . $e->getMessage()); \Log::error('DB ERROR: ' . $e->getMessage());
throw new \Firefly\Exception\FireflyException('Could not save account ' . $data['name']); throw new FireflyException('Could not save account ' . $data['name']);
} }
return $account; return $account;
} }
/**
* @param $name
*
* @return \Account|mixed|null
*/
public function createOrFindBeneficiary($name) public function createOrFindBeneficiary($name)
{ {
if (is_null($name) || strlen($name) == 0) { if (is_null($name) || strlen($name) == 0) {
@@ -140,6 +199,12 @@ class EloquentAccountRepository implements AccountRepositoryInterface
return $this->createOrFind($name, $type); return $this->createOrFind($name, $type);
} }
/**
* @param $name
* @param \AccountType $type
*
* @return \Account|mixed
*/
public function createOrFind($name, \AccountType $type) public function createOrFind($name, \AccountType $type)
{ {
$beneficiary = $this->findByName($name); $beneficiary = $this->findByName($name);
@@ -153,11 +218,19 @@ class EloquentAccountRepository implements AccountRepositoryInterface
return $beneficiary; return $beneficiary;
} }
/**
* @param $name
*
* @return mixed
*/
public function findByName($name) public function findByName($name)
{ {
return \Auth::user()->accounts()->where('name', 'like', '%' . $name . '%')->first(); return \Auth::user()->accounts()->where('name', 'like', '%' . $name . '%')->first();
} }
/**
* @return mixed
*/
public function getCashAccount() public function getCashAccount()
{ {
$type = \AccountType::where('description', 'Cash account')->first(); $type = \AccountType::where('description', 'Cash account')->first();

View File

@@ -2,16 +2,45 @@
namespace Firefly\Storage\Budget; namespace Firefly\Storage\Budget;
use Carbon\Carbon;
/**
* Interface BudgetRepositoryInterface
*
* @package Firefly\Storage\Budget
*/
interface BudgetRepositoryInterface interface BudgetRepositoryInterface
{ {
/**
* @return mixed
*/
public function getAsSelectList(); public function getAsSelectList();
/**
* @return mixed
*/
public function get(); public function get();
/**
* @param $data
*
* @return mixed
*/
public function store($data); public function store($data);
public function find($id); /**
* @param $budgetId
*
* @return mixed
*/
public function find($budgetId);
public function getWithRepetitionsInPeriod(\Carbon\Carbon $date, $range); /**
* @param Carbon $date
* @param $range
*
* @return mixed
*/
public function getWithRepetitionsInPeriod(Carbon $date, $range);
} }

View File

@@ -2,10 +2,19 @@
namespace Firefly\Storage\Budget; namespace Firefly\Storage\Budget;
use Carbon\Carbon;
/**
* Class EloquentBudgetRepository
*
* @package Firefly\Storage\Budget
*/
class EloquentBudgetRepository implements BudgetRepositoryInterface class EloquentBudgetRepository implements BudgetRepositoryInterface
{ {
/**
* @return array|mixed
*/
public function getAsSelectList() public function getAsSelectList()
{ {
$list = \Auth::user()->budgets()->with( $list = \Auth::user()->budgets()->with(
@@ -18,20 +27,18 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
return $return; return $return;
} }
public function getWithRepetitionsInPeriod(\Carbon\Carbon $date, $range) /**
* @param Carbon $date
* @param $range
*
* @return mixed
*/
public function getWithRepetitionsInPeriod(Carbon $date, $range)
{ {
/** @var \Firefly\Helper\Toolkit\ToolkitInterface $toolkit */
$toolkit = \App::make('Firefly\Helper\Toolkit\ToolkitInterface');
$dates = $toolkit->getDateRangeDates();
$start = $dates[0];
$result = [];
$set = \Auth::user()->budgets()->with( $set = \Auth::user()->budgets()->with(
['limits' => function ($q) use ($date) { ['limits' => function ($q) use ($date) {
$q->orderBy('limits.startdate', 'ASC'); $q->orderBy('limits.startdate', 'ASC');
// $q->where('startdate',$date->format('Y-m-d'));
}, 'limits.limitrepetitions' => function ($q) use ($date) { }, 'limits.limitrepetitions' => function ($q) use ($date) {
$q->orderBy('limit_repetitions.startdate', 'ASC'); $q->orderBy('limit_repetitions.startdate', 'ASC');
$q->where('startdate', $date->format('Y-m-d')); $q->where('startdate', $date->format('Y-m-d'));
@@ -65,6 +72,11 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
return $set; return $set;
} }
/**
* @param $data
*
* @return \Budget|mixed
*/
public function store($data) public function store($data)
{ {
$budget = new \Budget; $budget = new \Budget;
@@ -76,7 +88,7 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
if ($data['amount'] > 0) { if ($data['amount'] > 0) {
$limit = new \Limit; $limit = new \Limit;
$limit->budget()->associate($budget); $limit->budget()->associate($budget);
$startDate = new \Carbon\Carbon; $startDate = new Carbon;
switch ($data['repeat_freq']) { switch ($data['repeat_freq']) {
case 'daily': case 'daily':
$startDate->startOfDay(); $startDate->startOfDay();
@@ -111,6 +123,10 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
return $budget; return $budget;
} }
/**
* @return mixed
*/
public function get() public function get()
{ {
return \Auth::user()->budgets()->with( return \Auth::user()->budgets()->with(
@@ -122,10 +138,15 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
)->orderBy('name', 'ASC')->get(); )->orderBy('name', 'ASC')->get();
} }
public function find($id) /**
* @param $budgetId
*
* @return mixed
*/
public function find($budgetId)
{ {
return \Auth::user()->budgets()->find($id); return \Auth::user()->budgets()->find($budgetId);
} }
} }

View File

@@ -2,16 +2,38 @@
namespace Firefly\Storage\Category; namespace Firefly\Storage\Category;
/**
* Interface CategoryRepositoryInterface
*
* @package Firefly\Storage\Category
*/
interface CategoryRepositoryInterface interface CategoryRepositoryInterface
{ {
/**
* @return mixed
*/
public function get(); public function get();
/**
* @param $name
*
* @return mixed
*/
public function createOrFind($name); public function createOrFind($name);
/**
* @param $name
*
* @return mixed
*/
public function findByName($name); public function findByName($name);
/**
* @param $name
*
* @return mixed
*/
public function store($name); public function store($name);
} }

View File

@@ -2,14 +2,26 @@
namespace Firefly\Storage\Category; namespace Firefly\Storage\Category;
/**
* Class EloquentCategoryRepository
*
* @package Firefly\Storage\Category
*/
class EloquentCategoryRepository implements CategoryRepositoryInterface class EloquentCategoryRepository implements CategoryRepositoryInterface
{ {
/**
* @return mixed
*/
public function get() public function get()
{ {
return \Auth::user()->categories()->get(); return \Auth::user()->categories()->get();
} }
/**
* @param $name
*
* @return \Category|mixed
*/
public function createOrFind($name) public function createOrFind($name)
{ {
$category = $this->findByName($name); $category = $this->findByName($name);
@@ -21,12 +33,22 @@ class EloquentCategoryRepository implements CategoryRepositoryInterface
} }
/**
* @param $name
*
* @return mixed
*/
public function findByName($name) public function findByName($name)
{ {
return \Auth::user()->categories()->where('name', 'LIKE', '%' . $name . '%')->first(); return \Auth::user()->categories()->where('name', 'LIKE', '%' . $name . '%')->first();
} }
/**
* @param $name
*
* @return \Category|mixed
*/
public function store($name) public function store($name)
{ {
$category = new \Category(); $category = new \Category();

View File

@@ -3,14 +3,29 @@
namespace Firefly\Storage\Component; namespace Firefly\Storage\Component;
/**
* Interface ComponentRepositoryInterface
*
* @package Firefly\Storage\Component
*/
interface ComponentRepositoryInterface interface ComponentRepositoryInterface
{ {
/**
* @return mixed
*/
public function count(); public function count();
/**
* @return mixed
*/
public function get(); public function get();
/**
* @param $data
*
* @return mixed
*/
public function store($data); public function store($data);
} }

View File

@@ -3,32 +3,56 @@
namespace Firefly\Storage\Component; namespace Firefly\Storage\Component;
use Firefly\Exception\FireflyException;
use Illuminate\Database\QueryException;
/**
* Class EloquentComponentRepository
*
* @package Firefly\Storage\Component
*/
class EloquentComponentRepository implements ComponentRepositoryInterface class EloquentComponentRepository implements ComponentRepositoryInterface
{ {
public $validator; public $validator;
/**
*
*/
public function __construct() public function __construct()
{ {
} }
/**
* @return mixed
*/
public function count() public function count()
{ {
return \Auth::user()->components()->count(); return \Auth::user()->components()->count();
} }
/**
* @return mixed|void
* @throws \Firefly\Exception\FireflyException
*/
public function get() public function get()
{ {
die('no impl'); throw new FireflyException('No implementation.');
} }
/**
* @param $data
*
* @return \Budget|\Category|mixed
* @throws \Firefly\Exception\FireflyException
*/
public function store($data) public function store($data)
{ {
if (!isset($data['class'])) { if (!isset($data['class'])) {
throw new \Firefly\Exception\FireflyException('No class type present.'); throw new FireflyException('No class type present.');
} }
switch ($data['class']) { switch ($data['class']) {
default:
case 'Budget': case 'Budget':
$component = new \Budget; $component = new \Budget;
break; break;
@@ -41,9 +65,9 @@ class EloquentComponentRepository implements ComponentRepositoryInterface
$component->user()->associate(\Auth::user()); $component->user()->associate(\Auth::user());
try { try {
$component->save(); $component->save();
} catch (\Illuminate\Database\QueryException $e) { } catch (QueryException $e) {
\Log::error('DB ERROR: ' . $e->getMessage()); \Log::error('DB ERROR: ' . $e->getMessage());
throw new \Firefly\Exception\FireflyException('Could not save component ' . $data['name'] . ' of type' throw new FireflyException('Could not save component ' . $data['name'] . ' of type'
. $data['class']); . $data['class']);
} }

View File

@@ -1,17 +1,24 @@
<?php <?php
/**
* Created by PhpStorm.
* User: sander
* Date: 20/07/14
* Time: 13:43
*/
namespace Firefly\Storage\Limit; namespace Firefly\Storage\Limit;
use Carbon\Carbon;
/**
* Class EloquentLimitRepository
*
* @package Firefly\Storage\Limit
*/
class EloquentLimitRepository implements LimitRepositoryInterface class EloquentLimitRepository implements LimitRepositoryInterface
{ {
/**
* @param $limitId
*
* @return mixed
*/
public function find($limitId) public function find($limitId)
{ {
return \Limit::with('limitrepetitions')->where('limits.id', $limitId)->leftJoin( return \Limit::with('limitrepetitions')->where('limits.id', $limitId)->leftJoin(
@@ -20,6 +27,11 @@ class EloquentLimitRepository implements LimitRepositoryInterface
->where('components.user_id', \Auth::user()->id)->first(['limits.*']); ->where('components.user_id', \Auth::user()->id)->first(['limits.*']);
} }
/**
* @param $data
*
* @return \Limit
*/
public function store($data) public function store($data)
{ {
$budget = \Budget::find($data['budget_id']); $budget = \Budget::find($data['budget_id']);
@@ -28,7 +40,7 @@ class EloquentLimitRepository implements LimitRepositoryInterface
return new \Limit; return new \Limit;
} }
// set the date to the correct start period: // set the date to the correct start period:
$date = new \Carbon\Carbon($data['startdate']); $date = new Carbon($data['startdate']);
switch ($data['period']) { switch ($data['period']) {
case 'daily': case 'daily':
$date->startOfDay(); $date->startOfDay();
@@ -79,10 +91,15 @@ class EloquentLimitRepository implements LimitRepositoryInterface
return $limit; return $limit;
} }
public function getTJByBudgetAndDateRange(\Budget $budget, \Carbon\Carbon $start, \Carbon\Carbon $end) /**
* @param \Budget $budget
* @param Carbon $start
* @param Carbon $end
*
* @return mixed
*/
public function getTJByBudgetAndDateRange(\Budget $budget, Carbon $start, Carbon $end)
{ {
$type = \TransactionType::where('type', 'Withdrawal')->first();
$result = $budget->transactionjournals()->after($start)->before($end)->get(); $result = $budget->transactionjournals()->after($start)->before($end)->get();
return $result; return $result;

View File

@@ -2,13 +2,36 @@
namespace Firefly\Storage\Limit; namespace Firefly\Storage\Limit;
use Carbon\Carbon;
/**
* Interface LimitRepositoryInterface
*
* @package Firefly\Storage\Limit
*/
interface LimitRepositoryInterface interface LimitRepositoryInterface
{ {
/**
* @param $data
*
* @return mixed
*/
public function store($data); public function store($data);
public function getTJByBudgetAndDateRange(\Budget $budget, \Carbon\Carbon $start, \Carbon\Carbon $end); /**
* @param \Budget $budget
* @param Carbon $start
* @param Carbon $end
*
* @return mixed
*/
public function getTJByBudgetAndDateRange(\Budget $budget, Carbon $start, Carbon $end);
/**
* @param $limitId
*
* @return mixed
*/
public function find($limitId); public function find($limitId);
} }

View File

@@ -3,11 +3,18 @@ namespace Firefly\Storage;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
/**
* Class StorageServiceProvider
*
* @package Firefly\Storage
*/
class StorageServiceProvider extends ServiceProvider class StorageServiceProvider extends ServiceProvider
{ {
// Triggered automatically by Laravel /**
* Triggered automatically by Laravel
*/
public function register() public function register()
{ {
$this->app->bind( $this->app->bind(

View File

@@ -2,7 +2,11 @@
namespace Firefly\Storage\Transaction; namespace Firefly\Storage\Transaction;
/**
* Class EloquentTransactionRepository
*
* @package Firefly\Storage\Transaction
*/
class EloquentTransactionRepository implements TransactionRepositoryInterface class EloquentTransactionRepository implements TransactionRepositoryInterface
{ {

View File

@@ -2,7 +2,11 @@
namespace Firefly\Storage\Transaction; namespace Firefly\Storage\Transaction;
/**
* Interface TransactionRepositoryInterface
*
* @package Firefly\Storage\Transaction
*/
interface TransactionRepositoryInterface interface TransactionRepositoryInterface
{ {

View File

@@ -3,10 +3,22 @@
namespace Firefly\Storage\TransactionJournal; namespace Firefly\Storage\TransactionJournal;
use Carbon\Carbon;
use Firefly\Exception\FireflyException;
/**
* Class EloquentTransactionJournalRepository
*
* @package Firefly\Storage\TransactionJournal
*/
class EloquentTransactionJournalRepository implements TransactionJournalRepositoryInterface class EloquentTransactionJournalRepository implements TransactionJournalRepositoryInterface
{ {
/**
* @param $journalId
*
* @return mixed
*/
public function find($journalId) public function find($journalId)
{ {
return \Auth::user()->transactionjournals()->with( return \Auth::user()->transactionjournals()->with(
@@ -41,7 +53,7 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
* B loses 200 (-200). * 1 * B loses 200 (-200). * 1
* *
* @param \Account $from * @param \Account $from
* @param \Account $to * @param \Account $toAccount
* @param $description * @param $description
* @param $amount * @param $amount
* @param \Carbon\Carbon $date * @param \Carbon\Carbon $date
@@ -49,7 +61,7 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
* @return \TransactionJournal * @return \TransactionJournal
* @throws \Firefly\Exception\FireflyException * @throws \Firefly\Exception\FireflyException
*/ */
public function createSimpleJournal(\Account $from, \Account $to, $description, $amount, \Carbon\Carbon $date) public function createSimpleJournal(\Account $from, \Account $toAccount, $description, $amount, Carbon $date)
{ {
\Log::debug('Creating tranaction "' . $description . '".'); \Log::debug('Creating tranaction "' . $description . '".');
@@ -59,23 +71,23 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
if (round(floatval($amount), 2) == 0.00) { if (round(floatval($amount), 2) == 0.00) {
\Log::error('Transaction will never save: amount = 0'); \Log::error('Transaction will never save: amount = 0');
\Session::flash('error', 'The amount should not be empty or zero.'); \Session::flash('error', 'The amount should not be empty or zero.');
throw new \Firefly\Exception\FireflyException('Could not figure out transaction type.'); throw new FireflyException('Could not figure out transaction type.');
} }
// same account: // same account:
if ($from->id == $to->id) { if ($from->id == $toAccount->id) {
\Log::error('Accounts cannot be equal'); \Log::error('Accounts cannot be equal');
\Session::flash('error', 'Select two different accounts.'); \Session::flash('error', 'Select two different accounts.');
throw new \Firefly\Exception\FireflyException('Select two different accounts.'); throw new FireflyException('Select two different accounts.');
} }
// account types for both: // account types for both:
$toAT = $to->accountType->description; $toAT = $toAccount->accountType->description;
$fromAT = $from->accountType->description; $fromAT = $from->accountType->description;
$journalType = null; $journalType = null;
switch (true) { switch (true) {
case ($from->transactions()->count() == 0 && $to->transactions()->count() == 0): case ($from->transactions()->count() == 0 && $toAccount->transactions()->count() == 0):
$journalType = \TransactionType::where('type', 'Opening balance')->first(); $journalType = \TransactionType::where('type', 'Opening balance')->first();
break; break;
@@ -99,19 +111,19 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
// some debug information: // some debug information:
\Log::debug( \Log::debug(
$journalType->type . ': AccountFrom "' . $from->name . '" will gain/lose ' . $amountFrom $journalType->type . ': AccountFrom "' . $from->name . '" will gain/lose ' . $amountFrom
. ' and AccountTo "' . $to->name . '" will gain/lose ' . $amountTo . ' and AccountTo "' . $toAccount->name . '" will gain/lose ' . $amountTo
); );
if (is_null($journalType)) { if (is_null($journalType)) {
\Log::error('Could not figure out transacion type!'); \Log::error('Could not figure out transacion type!');
throw new \Firefly\Exception\FireflyException('Could not figure out transaction type.'); throw new FireflyException('Could not figure out transaction type.');
} }
// always the same currency: // always the same currency:
$currency = \TransactionCurrency::where('code', 'EUR')->first(); $currency = \TransactionCurrency::where('code', 'EUR')->first();
if (is_null($currency)) { if (is_null($currency)) {
\Log::error('No currency for journal!'); \Log::error('No currency for journal!');
throw new \Firefly\Exception\FireflyException('No currency for journal!'); throw new FireflyException('No currency for journal!');
} }
// new journal: // new journal:
@@ -126,7 +138,7 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
\Log::error('Cannot create valid journal.'); \Log::error('Cannot create valid journal.');
\Log::error('Errors: ' . print_r($journal->errors()->all(), true)); \Log::error('Errors: ' . print_r($journal->errors()->all(), true));
\Session::flash('error', 'Could not create journal: ' . $journal->errors()->first()); \Session::flash('error', 'Could not create journal: ' . $journal->errors()->first());
throw new \Firefly\Exception\FireflyException('Cannot create valid journal.'); throw new FireflyException('Cannot create valid journal.');
} }
$journal->save(); $journal->save();
@@ -139,19 +151,19 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
if (!$fromTransaction->save()) { if (!$fromTransaction->save()) {
\Log::error('Cannot create valid transaction (from) for journal #' . $journal->id); \Log::error('Cannot create valid transaction (from) for journal #' . $journal->id);
\Log::error('Errors: ' . print_r($fromTransaction->errors()->all(), true)); \Log::error('Errors: ' . print_r($fromTransaction->errors()->all(), true));
throw new \Firefly\Exception\FireflyException('Cannot create valid transaction (from).'); throw new FireflyException('Cannot create valid transaction (from).');
} }
$fromTransaction->save(); $fromTransaction->save();
$toTransaction = new \Transaction; $toTransaction = new \Transaction;
$toTransaction->account()->associate($to); $toTransaction->account()->associate($toAccount);
$toTransaction->transactionJournal()->associate($journal); $toTransaction->transactionJournal()->associate($journal);
$toTransaction->description = null; $toTransaction->description = null;
$toTransaction->amount = $amountTo; $toTransaction->amount = $amountTo;
if (!$toTransaction->save()) { if (!$toTransaction->save()) {
\Log::error('Cannot create valid transaction (to) for journal #' . $journal->id); \Log::error('Cannot create valid transaction (to) for journal #' . $journal->id);
\Log::error('Errors: ' . print_r($toTransaction->errors()->all(), true)); \Log::error('Errors: ' . print_r($toTransaction->errors()->all(), true));
throw new \Firefly\Exception\FireflyException('Cannot create valid transaction (to).'); throw new FireflyException('Cannot create valid transaction (to).');
} }
$toTransaction->save(); $toTransaction->save();
@@ -160,12 +172,23 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
return $journal; return $journal;
} }
/**
*
*/
public function get() public function get()
{ {
} }
public function getByAccountInDateRange(\Account $account, $count = 25, \Carbon\Carbon $start, \Carbon\Carbon $end) /**
* @param \Account $account
* @param int $count
* @param Carbon $start
* @param Carbon $end
*
* @return mixed
*/
public function getByAccountInDateRange(\Account $account, $count = 25, Carbon $start, Carbon $end)
{ {
$accountID = $account->id; $accountID = $account->id;
$query = \Auth::user()->transactionjournals()->with( $query = \Auth::user()->transactionjournals()->with(
@@ -187,6 +210,11 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
return $query; return $query;
} }
/**
* @param int $count
*
* @return mixed
*/
public function paginate($count = 25) public function paginate($count = 25)
{ {
$query = \Auth::user()->transactionjournals()->with( $query = \Auth::user()->transactionjournals()->with(
@@ -207,7 +235,13 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
return $query; return $query;
} }
public function getByDateRange(\Carbon\Carbon $start, \Carbon\Carbon $end) /**
* @param Carbon $start
* @param Carbon $end
*
* @return mixed
*/
public function getByDateRange(Carbon $start, Carbon $end)
{ {
// lets make this simple. // lets make this simple.
$types = []; $types = [];
@@ -231,7 +265,13 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
return $journals; return $journals;
} }
public function getByAccountAndDate(\Account $account, \Carbon\Carbon $date) /**
* @param \Account $account
* @param Carbon $date
*
* @return mixed
*/
public function getByAccountAndDate(\Account $account, Carbon $date)
{ {
$accountID = $account->id; $accountID = $account->id;
$query = \Auth::user()->transactionjournals()->with( $query = \Auth::user()->transactionjournals()->with(

View File

@@ -2,21 +2,69 @@
namespace Firefly\Storage\TransactionJournal; namespace Firefly\Storage\TransactionJournal;
use Carbon\Carbon;
/**
* Interface TransactionJournalRepositoryInterface
*
* @package Firefly\Storage\TransactionJournal
*/
interface TransactionJournalRepositoryInterface interface TransactionJournalRepositoryInterface
{ {
public function createSimpleJournal(\Account $from, \Account $to, $description, $amount, \Carbon\Carbon $date); /**
* @param \Account $from
* @param \Account $toAccount
* @param $description
* @param $amount
* @param Carbon $date
*
* @return mixed
*/
public function createSimpleJournal(\Account $from, \Account $toAccount, $description, $amount, Carbon $date);
/**
* @return mixed
*/
public function get(); public function get();
/**
* @param $journalId
*
* @return mixed
*/
public function find($journalId); public function find($journalId);
public function getByAccountInDateRange(\Account $account, $count = 25, \Carbon\Carbon $start, \Carbon\Carbon $end); /**
* @param \Account $account
* @param int $count
* @param Carbon $start
* @param Carbon $end
*
* @return mixed
*/
public function getByAccountInDateRange(\Account $account, $count = 25, Carbon $start, Carbon $end);
public function getByAccountAndDate(\Account $account, \Carbon\Carbon $date); /**
* @param \Account $account
* @param Carbon $date
*
* @return mixed
*/
public function getByAccountAndDate(\Account $account, Carbon $date);
public function getByDateRange(\Carbon\Carbon $start, \Carbon\Carbon $end); /**
* @param Carbon $start
* @param Carbon $end
*
* @return mixed
*/
public function getByDateRange(Carbon $start, Carbon $end);
/**
* @param int $count
*
* @return mixed
*/
public function paginate($count = 25); public function paginate($count = 25);
} }

View File

@@ -3,12 +3,25 @@
namespace Firefly\Storage\User; namespace Firefly\Storage\User;
/**
* Class EloquentUserRepository
*
* @package Firefly\Storage\User
*/
class EloquentUserRepository implements UserRepositoryInterface class EloquentUserRepository implements UserRepositoryInterface
{ {
/**
*
*/
public function __construct() public function __construct()
{ {
} }
/**
* @param $array
*
* @return bool|\User
*/
public function register($array) public function register($array)
{ {
$user = new \User; $user = new \User;
@@ -26,6 +39,11 @@ class EloquentUserRepository implements UserRepositoryInterface
return $user; return $user;
} }
/**
* @param $array
*
* @return bool
*/
public function auth($array) public function auth($array)
{ {
$user = \User::where('email', $array['email'])->first(); $user = \User::where('email', $array['email'])->first();
@@ -36,16 +54,32 @@ class EloquentUserRepository implements UserRepositoryInterface
return false; return false;
} }
/**
* @param $reset
*
* @return mixed
*/
public function findByReset($reset) public function findByReset($reset)
{ {
return \User::where('reset', $reset)->first(); return \User::where('reset', $reset)->first();
} }
/**
* @param $email
*
* @return mixed
*/
public function findByEmail($email) public function findByEmail($email)
{ {
return \User::where('email', $email)->first(); return \User::where('email', $email)->first();
} }
/**
* @param \User $user
* @param $password
*
* @return bool
*/
public function updatePassword(\User $user, $password) public function updatePassword(\User $user, $password)
{ {
$password = \Hash::make($password); $password = \Hash::make($password);

View File

@@ -3,17 +3,47 @@
namespace Firefly\Storage\User; namespace Firefly\Storage\User;
/**
* Interface UserRepositoryInterface
*
* @package Firefly\Storage\User
*/
interface UserRepositoryInterface interface UserRepositoryInterface
{ {
/**
* @param $array
*
* @return mixed
*/
public function register($array); public function register($array);
/**
* @param $array
*
* @return mixed
*/
public function auth($array); public function auth($array);
/**
* @param $reset
*
* @return mixed
*/
public function findByReset($reset); public function findByReset($reset);
/**
* @param $email
*
* @return mixed
*/
public function findByEmail($email); public function findByEmail($email);
/**
* @param \User $user
* @param $password
*
* @return mixed
*/
public function updatePassword(\User $user, $password); public function updatePassword(\User $user, $password);

View File

@@ -2,6 +2,10 @@
namespace Firefly\Trigger\Limits; namespace Firefly\Trigger\Limits;
use Carbon\Carbon;
use Illuminate\Database\QueryException;
use Illuminate\Events\Dispatcher;
/** /**
* Class EloquentLimitTrigger * Class EloquentLimitTrigger
* *
@@ -64,14 +68,14 @@ class EloquentLimitTrigger
try { try {
$repetition->save(); $repetition->save();
} catch (\Illuminate\Database\QueryException $e) { } catch (QueryException $e) {
// do nothing // do nothing
\Log::error($e->getMessage()); \Log::error($e->getMessage());
} }
} else { } else {
// there are limits already, do they // there are limits already, do they
// fall into the range surrounding today? // fall into the range surrounding today?
$today = new \Carbon\Carbon; $today = new Carbon;
$today->addMonths(2); $today->addMonths(2);
if ($limit->repeats == 1 && $today >= $limit->startdate) { if ($limit->repeats == 1 && $today >= $limit->startdate) {
@@ -141,7 +145,7 @@ class EloquentLimitTrigger
$repetition->limit()->associate($limit); $repetition->limit()->associate($limit);
try { try {
$repetition->save(); $repetition->save();
} catch (\Illuminate\Database\QueryException $e) { } catch (QueryException $e) {
// do nothing // do nothing
\Log::error($e->getMessage()); \Log::error($e->getMessage());
} }
@@ -153,7 +157,10 @@ class EloquentLimitTrigger
} }
} }
public function subscribe(\Illuminate\Events\Dispatcher $events) /**
* @param Dispatcher $events
*/
public function subscribe(Dispatcher $events)
{ {
$events->listen('app.before', 'Firefly\Trigger\Limits\EloquentLimitTrigger@updateLimitRepetitions'); $events->listen('app.before', 'Firefly\Trigger\Limits\EloquentLimitTrigger@updateLimitRepetitions');

View File

@@ -15,17 +15,16 @@ class AccountControllerTest extends TestCase
{ {
// mock account type(s): // mock account type(s):
$personal = $this->mock('AccountType'); $personal = $this->mock('AccountType');
$personal->shouldReceive('getAttribute','description')->andReturn('Default account'); $personal->shouldReceive('getAttribute', 'description')->andReturn('Default account');
$bene = $this->mock('AccountType'); $bene = $this->mock('AccountType');
$bene->shouldReceive('getAttribute','description')->andReturn('Beneficiary account'); $bene->shouldReceive('getAttribute', 'description')->andReturn('Beneficiary account');
$initial = $this->mock('AccountType'); $initial = $this->mock('AccountType');
$initial->shouldReceive('getAttribute','description')->andReturn('Initial balance account'); $initial->shouldReceive('getAttribute', 'description')->andReturn('Initial balance account');
$cash = $this->mock('AccountType'); $cash = $this->mock('AccountType');
$cash->shouldReceive('getAttribute','description')->andReturn('Cash account'); $cash->shouldReceive('getAttribute', 'description')->andReturn('Cash account');
// mock account(s) // mock account(s)
@@ -40,16 +39,13 @@ class AccountControllerTest extends TestCase
$four = $this->mock('Account'); $four = $this->mock('Account');
$four->shouldReceive('getAttribute')->andReturn($cash); $four->shouldReceive('getAttribute')->andReturn($cash);
$c = new \Illuminate\Database\Eloquent\Collection([$one,$two,$three,$four]); $c = new \Illuminate\Database\Eloquent\Collection([$one, $two, $three, $four]);
// mock account repository: // mock account repository:
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface'); $accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
$accounts->shouldReceive('get')->andReturn($c); $accounts->shouldReceive('get')->andReturn($c);
$list = [ $list = [
'personal' => [$one], 'personal' => [$one],
'beneficiaries' => [$two], 'beneficiaries' => [$two],
@@ -60,11 +56,10 @@ class AccountControllerTest extends TestCase
// mock: // mock:
View::shouldReceive('share'); View::shouldReceive('share');
View::shouldReceive('make')->with('accounts.index')->once()->andReturn(\Mockery::self()) View::shouldReceive('make')->with('accounts.index')->once()->andReturn(\Mockery::self())
->shouldReceive('with')->once()->with('accounts',$list)->andReturn(\Mockery::self()) ->shouldReceive('with')->once()->with('accounts', $list)->andReturn(\Mockery::self())
->shouldReceive('with')->once()->with('total', 4)->andReturn(\Mockery::self()); ->shouldReceive('with')->once()->with('total', 4)->andReturn(\Mockery::self());
// call // call
$this->call('GET', '/accounts'); $this->call('GET', '/accounts');

View File

@@ -1,7 +1,8 @@
<?php <?php
use \League\FactoryMuffin\Facade\FactoryMuffin; use League\FactoryMuffin\Facade\FactoryMuffin;
/** /**
* Class BudgetControllerTest * Class BudgetControllerTest
*/ */
@@ -24,7 +25,6 @@ class BudgetControllerTest extends TestCase
$budget->limits()->save($limit); $budget->limits()->save($limit);
// mock budget repository: // mock budget repository:
$budgets = $this->mock('Firefly\Storage\Budget\BudgetRepositoryInterface'); $budgets = $this->mock('Firefly\Storage\Budget\BudgetRepositoryInterface');
$budgets->shouldReceive('get')->once()->andReturn([$budget]); $budgets->shouldReceive('get')->once()->andReturn([$budget]);
@@ -46,7 +46,6 @@ class BudgetControllerTest extends TestCase
$budget->limits()->save($limit); $budget->limits()->save($limit);
// mock budget repository: // mock budget repository:
$budgets = $this->mock('Firefly\Storage\Budget\BudgetRepositoryInterface'); $budgets = $this->mock('Firefly\Storage\Budget\BudgetRepositoryInterface');
$budgets->shouldReceive('get')->once()->andReturn([$budget]); $budgets->shouldReceive('get')->once()->andReturn([$budget]);
@@ -84,7 +83,7 @@ class BudgetControllerTest extends TestCase
$budgets->shouldReceive('store')->with($return)->once()->andReturn(true); $budgets->shouldReceive('store')->with($return)->once()->andReturn(true);
// call // call
$this->call('POST', '/budget/store',$data); $this->call('POST', '/budget/store', $data);
// test // test
$this->assertResponseStatus(302); $this->assertResponseStatus(302);
@@ -106,7 +105,7 @@ class BudgetControllerTest extends TestCase
// call // call
$this->call('GET', '/budget/show/'.$budget->id); $this->call('GET', '/budget/show/' . $budget->id);
// test // test
$this->assertResponseOk(); $this->assertResponseOk();

View File

@@ -181,7 +181,7 @@ class ChartControllerTest extends TestCase
{ {
$account = FactoryMuffin::create('Account'); $account = FactoryMuffin::create('Account');
$second = FactoryMuffin::create('Account'); $second = FactoryMuffin::create('Account');
$date = \Carbon\Carbon::createFromDate('2012','01','01'); $date = \Carbon\Carbon::createFromDate('2012', '01', '01');
$transaction = FactoryMuffin::create('Transaction'); $transaction = FactoryMuffin::create('Transaction');
$transaction->account()->associate($second); $transaction->account()->associate($second);
$journal = FactoryMuffin::create('TransactionJournal'); $journal = FactoryMuffin::create('TransactionJournal');
@@ -196,13 +196,8 @@ class ChartControllerTest extends TestCase
$tj->shouldReceive('getByAccountAndDate')->once()->andReturn([$journal]); $tj->shouldReceive('getByAccountAndDate')->once()->andReturn([$journal]);
// call // call
$this->call('GET', '/chart/home/info/'.$account->name.'/'.$date->format('d/m/Y')); $this->call('GET', '/chart/home/info/' . $account->name . '/' . $date->format('d/m/Y'));
// test // test
$this->assertResponseOk(); $this->assertResponseOk();

View File

@@ -71,7 +71,7 @@ class HomeControllerTest extends TestCase
// mock transaction journal repository: // mock transaction journal repository:
$tj = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface'); $tj = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
$tj->shouldReceive('getByAccount')->with($account,15)->andReturn([]); $tj->shouldReceive('getByAccount')->with($account, 15)->andReturn([]);
// mock preferences & pref: // mock preferences & pref:
$pref = $this->mock('Preference'); $pref = $this->mock('Preference');

View File

@@ -1,12 +1,14 @@
<?php <?php
class JsonControllerTest extends TestCase { class JsonControllerTest extends TestCase
{
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();
} }
public function testBeneficiaries() { public function testBeneficiaries()
{
$obj = new stdClass; $obj = new stdClass;
$obj->name = 'Bla bla'; $obj->name = 'Bla bla';
@@ -22,7 +24,8 @@ class JsonControllerTest extends TestCase {
} }
public function testCategories() { public function testCategories()
{
$obj = new stdClass; $obj = new stdClass;
$obj->name = 'Bla bla'; $obj->name = 'Bla bla';
@@ -35,6 +38,7 @@ class JsonControllerTest extends TestCase {
// test // test
$this->assertResponseOk(); $this->assertResponseOk();
} }
public function tearDown() public function tearDown()
{ {
Mockery::close(); Mockery::close();

View File

@@ -57,6 +57,7 @@ class PreferencesControllerTest extends TestCase
$this->assertSessionHas('success'); $this->assertSessionHas('success');
$this->assertRedirectedToRoute('preferences'); $this->assertRedirectedToRoute('preferences');
} }
public function tearDown() public function tearDown()
{ {
Mockery::close(); Mockery::close();

View File

@@ -30,7 +30,7 @@ class TransactionControllerTest extends TestCase
View::shouldReceive('share'); View::shouldReceive('share');
View::shouldReceive('make')->with('transactions.create')->andReturn(\Mockery::self()) View::shouldReceive('make')->with('transactions.create')->andReturn(\Mockery::self())
->shouldReceive('with')->once() ->shouldReceive('with')->once()
->with('what','withdrawal') ->with('what', 'withdrawal')
->andReturn(Mockery::self()) ->andReturn(Mockery::self())
->shouldReceive('with')->once() ->shouldReceive('with')->once()
->with('accounts', []) ->with('accounts', [])
@@ -61,7 +61,7 @@ class TransactionControllerTest extends TestCase
View::shouldReceive('share'); View::shouldReceive('share');
View::shouldReceive('make')->with('transactions.create')->andReturn(\Mockery::self()) View::shouldReceive('make')->with('transactions.create')->andReturn(\Mockery::self())
->shouldReceive('with')->once() ->shouldReceive('with')->once()
->with('what','deposit') ->with('what', 'deposit')
->andReturn(Mockery::self()) ->andReturn(Mockery::self())
->shouldReceive('with')->once() ->shouldReceive('with')->once()
@@ -393,7 +393,7 @@ class TransactionControllerTest extends TestCase
$this->call('POST', '/transactions/store/withdrawal', $data); $this->call('POST', '/transactions/store/withdrawal', $data);
// test // test
$this->assertRedirectedToRoute('transactions.create',['what' => 'withdrawal']); $this->assertRedirectedToRoute('transactions.create', ['what' => 'withdrawal']);
} }
/** /**
@@ -443,7 +443,7 @@ class TransactionControllerTest extends TestCase
$this->call('POST', '/transactions/store/deposit', $data); $this->call('POST', '/transactions/store/deposit', $data);
// test // test
$this->assertRedirectedToRoute('transactions.create',['what' => 'deposit']); $this->assertRedirectedToRoute('transactions.create', ['what' => 'deposit']);
} }
/** /**
@@ -488,10 +488,11 @@ class TransactionControllerTest extends TestCase
$this->call('POST', '/transactions/store/transfer', $data); $this->call('POST', '/transactions/store/transfer', $data);
// test // test
$this->assertRedirectedToRoute('transactions.create',['what' => 'transfer']); $this->assertRedirectedToRoute('transactions.create', ['what' => 'transfer']);
} }
public function testShow() { public function testShow()
{
$journal = FactoryMuffin::create('TransactionJournal'); $journal = FactoryMuffin::create('TransactionJournal');
// mock transaction journal: // mock transaction journal:
@@ -499,7 +500,6 @@ class TransactionControllerTest extends TestCase
$tj->shouldReceive('find')->with($journal->id)->andReturn($journal); $tj->shouldReceive('find')->with($journal->id)->andReturn($journal);
// call // call
$this->call('GET', '/transaction/show/' . $journal->id); $this->call('GET', '/transaction/show/' . $journal->id);
@@ -507,7 +507,8 @@ class TransactionControllerTest extends TestCase
$this->assertResponseOk(); $this->assertResponseOk();
} }
public function testShowError() { public function testShowError()
{
// mock transaction journal: // mock transaction journal:
$tj = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface'); $tj = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
@@ -521,7 +522,8 @@ class TransactionControllerTest extends TestCase
$this->assertViewHas('message'); $this->assertViewHas('message');
} }
public function testEdit() { public function testEdit()
{
$journal = FactoryMuffin::create('TransactionJournal'); $journal = FactoryMuffin::create('TransactionJournal');
// mock transaction journal: // mock transaction journal:
@@ -533,7 +535,6 @@ class TransactionControllerTest extends TestCase
$accounts->shouldReceive('getActiveDefaultAsSelectList')->andReturn([]); $accounts->shouldReceive('getActiveDefaultAsSelectList')->andReturn([]);
// call // call
$this->call('GET', '/transaction/edit/' . $journal->id); $this->call('GET', '/transaction/edit/' . $journal->id);
@@ -541,7 +542,8 @@ class TransactionControllerTest extends TestCase
$this->assertResponseOk(); $this->assertResponseOk();
} }
public function testEditError() { public function testEditError()
{
// mock transaction journal: // mock transaction journal:
$tj = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface'); $tj = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
$tj->shouldReceive('find')->with(1)->andReturn(null); $tj->shouldReceive('find')->with(1)->andReturn(null);

View File

@@ -64,7 +64,7 @@ class UserControllerTest extends TestCase
// test // test
$this->call('GET', '/register'); $this->call('GET', '/register');
$this->assertResponseStatus(200); $this->assertResponseStatus(200);
$this->assertViewHas('message','Not possible'); $this->assertViewHas('message', 'Not possible');
} }
/** /**
@@ -94,7 +94,6 @@ class UserControllerTest extends TestCase
} }
/** /**
* Register and verify FAILED: * Register and verify FAILED:
*/ */
@@ -189,7 +188,7 @@ class UserControllerTest extends TestCase
$this->call('POST', '/remindme'); $this->call('POST', '/remindme');
$this->assertResponseOk(); $this->assertResponseOk();
$this->assertSessionHas('error','No good!'); $this->assertSessionHas('error', 'No good!');
} }
public function testPostRegisterNotAllowed() public function testPostRegisterNotAllowed()
@@ -207,7 +206,7 @@ class UserControllerTest extends TestCase
// test // test
$this->call('POST', '/register', $data); $this->call('POST', '/register', $data);
$this->assertResponseStatus(200); $this->assertResponseStatus(200);
$this->assertViewHas('message','Not possible'); $this->assertViewHas('message', 'Not possible');
} }