Made big headway in preference management, accounts, importing stuff, etc. etc.

This commit is contained in:
James Cole
2014-07-06 15:18:11 +02:00
parent 188105492c
commit 4192f2bc8f
46 changed files with 672 additions and 187 deletions

View File

@@ -1,10 +1,4 @@
<?php
/**
* Created by PhpStorm.
* User: sander
* Date: 04/07/14
* Time: 13:58
*/
namespace Firefly\Exception;

View File

@@ -1,10 +1,4 @@
<?php
/**
* Created by PhpStorm.
* User: sander
* Date: 04/07/14
* Time: 13:55
*/
namespace Firefly\Helper;

View File

@@ -21,6 +21,12 @@ class HelperServiceProvider extends ServiceProvider
'Firefly\Helper\Migration\MigrationHelperInterface',
'Firefly\Helper\Migration\MigrationHelper'
);
// settings:
$this->app->bind(
'Firefly\Helper\Preferences\PreferencesHelperInterface',
'Firefly\Helper\Preferences\PreferencesHelper'
);
}
}

View File

@@ -1,10 +1,4 @@
<?php
/**
* Created by PhpStorm.
* User: sander
* Date: 03/07/14
* Time: 21:34
*/
namespace Firefly\Helper\Migration;

View File

@@ -1,10 +1,4 @@
<?php
/**
* Created by PhpStorm.
* User: sander
* Date: 03/07/14
* Time: 21:33
*/
namespace Firefly\Helper\Migration;

View File

@@ -0,0 +1,39 @@
<?php
namespace Firefly\Helper\Preferences;
class PreferencesHelper implements PreferencesHelperInterface
{
public function get($name, $default = null)
{
$pref = \Preference::where('user_id', \Auth::user()->id)->where('name', $name)->first();
if (is_null($default) && is_null($pref)) {
// return NULL
return null;
}
if (!is_null($pref)) {
return $pref;
}
if (!is_null($default) && is_null($pref)) {
// create preference, return that:
return $this->set($name, $default);
}
}
public function set($name, $value)
{
$pref = \Preference::where('user_id', \Auth::user()->id)->where('name', $name)->first();
if (is_null($pref)) {
$pref = new \Preference;
$pref->name = $name;
$pref->user()->associate(\Auth::user());
}
$pref->data = $value;
$pref->save();
return $pref;
}
}

View File

@@ -0,0 +1,9 @@
<?php
namespace Firefly\Helper\Preferences;
interface PreferencesHelperInterface
{
public function set($name,$value);
public function get($name,$default = null);
}

View File

@@ -10,6 +10,9 @@ interface AccountRepositoryInterface
public function count();
public function get();
public function getByIds($ids);
public function getDefault();
public function getActiveDefault();
public function store($data);
public function storeWithInitialBalance($data,\Carbon\Carbon $date, $amount = 0);

View File

@@ -3,8 +3,6 @@
namespace Firefly\Storage\Account;
use Firefly\Helper\MigrationException;
class EloquentAccountRepository implements AccountRepositoryInterface
{
public $validator;
@@ -13,8 +11,30 @@ class EloquentAccountRepository implements AccountRepositoryInterface
{
}
public function get() {
return \Auth::user()->accounts()->get();
public function get()
{
return \Auth::user()->accounts()->with('accounttype')->get();
}
public function getByIds($ids)
{
return \Auth::user()->accounts()->with('accounttype')->whereIn('id', $ids)->get();
}
public function getDefault()
{
return \Auth::user()->accounts()->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
->where('account_types.description', 'Default account')
->get(['accounts.*']);
}
public function getActiveDefault()
{
return \Auth::user()->accounts()->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
->where('account_types.description', 'Default account')->where('accounts.active', 1)
->get(['accounts.*']);
}
public function count()

View File

@@ -1,10 +1,5 @@
<?php
/**
* Created by PhpStorm.
* User: sander
* Date: 03/07/14
* Time: 15:24
*/
namespace Firefly\Storage\TransactionJournal;
@@ -15,7 +10,7 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
public function createSimpleJournal(\Account $from, \Account $to, $description, $amount, \Carbon\Carbon $date)
{
\Log::debug('Creating tranaction "'.$description.'".');
\Log::debug('Creating tranaction "' . $description . '".');
/*
* We're building this thinking the money goes from A to B.
* If the amount is negative however, the money still goes
@@ -69,7 +64,10 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
}
// some debug information:
\Log::debug($journalType->type.': AccountFrom "'.$from->name.'" will gain/lose '.$amountFrom.' and AccountTo "'.$to->name.'" will gain/lose '.$amountTo);
\Log::debug(
$journalType->type . ': AccountFrom "' . $from->name . '" will gain/lose ' . $amountFrom
. ' and AccountTo "' . $to->name . '" will gain/lose ' . $amountTo
);
if (is_null($journalType)) {
\Log::error('Could not figure out transacion type!');

View File

@@ -1,15 +1,10 @@
<?php
/**
* Created by PhpStorm.
* User: sander
* Date: 03/07/14
* Time: 15:22
*/
namespace Firefly\Storage\TransactionJournal;
interface TransactionJournalRepositoryInterface {
interface TransactionJournalRepositoryInterface
{
public function createSimpleJournal(\Account $from, \Account $to, $description, $amount, \Carbon\Carbon $date);