mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-18 12:28:46 +00:00
Reformatted and checked everything. [skip ci]
This commit is contained in:
@@ -4,8 +4,14 @@
|
||||
|
||||
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
|
||||
@@ -20,15 +26,26 @@ abstract class SingleTableInheritanceEntity extends \LaravelBook\Ardent\Ardent
|
||||
*/
|
||||
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);
|
||||
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)
|
||||
{
|
||||
if (!$this->subclassField) {
|
||||
@@ -38,9 +55,16 @@ abstract class SingleTableInheritanceEntity extends \LaravelBook\Ardent\Ardent
|
||||
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)
|
||||
{
|
||||
// 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 bool
|
||||
*/
|
||||
public function 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(
|
||||
array $rules = array(),
|
||||
array $customMessages = array(),
|
||||
array $options = array(),
|
||||
array $rules = [],
|
||||
array $customMessages = [],
|
||||
array $options = [],
|
||||
\Closure $beforeSave = null,
|
||||
\Closure $afterSave = null
|
||||
) {
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
namespace Firefly\Exception;
|
||||
|
||||
|
||||
/**
|
||||
* Class FireflyException
|
||||
*
|
||||
* @package Firefly\Exception
|
||||
*/
|
||||
class FireflyException extends \Exception
|
||||
{
|
||||
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
namespace Firefly\Helper;
|
||||
|
||||
|
||||
/**
|
||||
* Class MigrationException
|
||||
*
|
||||
* @package Firefly\Helper
|
||||
*/
|
||||
class MigrationException extends \Exception
|
||||
{
|
||||
|
||||
|
||||
@@ -1,8 +1,18 @@
|
||||
<?php
|
||||
namespace Firefly\Helper\Email;
|
||||
|
||||
/**
|
||||
* Class EmailHelper
|
||||
*
|
||||
* @package Firefly\Helper\Email
|
||||
*/
|
||||
class EmailHelper implements EmailHelperInterface
|
||||
{
|
||||
/**
|
||||
* @param \User $user
|
||||
*
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function sendVerificationMail(\User $user)
|
||||
{
|
||||
|
||||
@@ -19,6 +29,11 @@ class EmailHelper implements EmailHelperInterface
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
*
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function sendPasswordMail(\User $user)
|
||||
{
|
||||
|
||||
@@ -37,6 +52,11 @@ class EmailHelper implements EmailHelperInterface
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
*
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function sendResetVerification(\User $user)
|
||||
{
|
||||
$reset = \Str::random(32);
|
||||
|
||||
@@ -2,13 +2,33 @@
|
||||
|
||||
namespace Firefly\Helper\Email;
|
||||
|
||||
/**
|
||||
* Interface EmailHelperInterface
|
||||
*
|
||||
* @package Firefly\Helper\Email
|
||||
*/
|
||||
interface EmailHelperInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function sendVerificationMail(\User $user);
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function sendPasswordMail(\User $user);
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function sendResetVerification(\User $user);
|
||||
|
||||
}
|
||||
@@ -3,11 +3,18 @@ namespace Firefly\Helper;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
/**
|
||||
* Class HelperServiceProvider
|
||||
*
|
||||
* @package Firefly\Helper
|
||||
*/
|
||||
class HelperServiceProvider extends ServiceProvider
|
||||
{
|
||||
|
||||
|
||||
// Triggered automatically by Laravel
|
||||
/**
|
||||
* Triggered automatically by Laravel
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
// mail:
|
||||
|
||||
@@ -3,19 +3,33 @@
|
||||
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
|
||||
{
|
||||
protected $path;
|
||||
protected $JSON;
|
||||
protected $map = [];
|
||||
|
||||
/**
|
||||
* @param $path
|
||||
*
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function loadFile($path)
|
||||
{
|
||||
$this->path = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function validFile()
|
||||
{
|
||||
// file does not exist:
|
||||
@@ -39,6 +53,9 @@ class MigrationHelper implements MigrationHelperInterface
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function migrate()
|
||||
{
|
||||
\Log::info('Start of migration.');
|
||||
@@ -62,7 +79,7 @@ class MigrationHelper implements MigrationHelperInterface
|
||||
$this->_importLimits();
|
||||
|
||||
|
||||
} catch (\Firefly\Exception\FireflyException $e) {
|
||||
} catch (FireflyException $e) {
|
||||
\DB::rollBack();
|
||||
\Log::error('Rollback because of error!');
|
||||
\Log::error($e->getMessage());
|
||||
@@ -74,6 +91,9 @@ class MigrationHelper implements MigrationHelperInterface
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function _createCashAccount()
|
||||
{
|
||||
$cashAT = \AccountType::where('description', 'Cash account')->first();
|
||||
@@ -84,6 +104,9 @@ class MigrationHelper implements MigrationHelperInterface
|
||||
$this->map['cash'] = $cash;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function _importAccounts()
|
||||
{
|
||||
|
||||
@@ -97,7 +120,7 @@ class MigrationHelper implements MigrationHelperInterface
|
||||
} else {
|
||||
$account = $accounts->storeWithInitialBalance(
|
||||
['name' => $entry->name],
|
||||
new \Carbon\Carbon($entry->openingbalancedate),
|
||||
new Carbon($entry->openingbalancedate),
|
||||
floatval($entry->openingbalance)
|
||||
);
|
||||
}
|
||||
@@ -106,6 +129,9 @@ class MigrationHelper implements MigrationHelperInterface
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function _importComponents()
|
||||
{
|
||||
$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)
|
||||
{
|
||||
/** @var \Firefly\Storage\Account\AccountRepositoryInterface $accounts */
|
||||
@@ -140,6 +172,11 @@ class MigrationHelper implements MigrationHelperInterface
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $component
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function _importCategory($component)
|
||||
{
|
||||
/** @var \Firefly\Storage\Component\ComponentRepositoryInterface $components */
|
||||
@@ -147,6 +184,11 @@ class MigrationHelper implements MigrationHelperInterface
|
||||
return $components->store(['name' => $component->name, 'class' => 'Category']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $component
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function _importBudget($component)
|
||||
{
|
||||
/** @var \Firefly\Storage\Component\ComponentRepositoryInterface $components */
|
||||
@@ -154,39 +196,9 @@ class MigrationHelper implements MigrationHelperInterface
|
||||
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()
|
||||
{
|
||||
|
||||
@@ -215,7 +227,6 @@ class MigrationHelper implements MigrationHelperInterface
|
||||
}
|
||||
|
||||
foreach ($this->JSON->transactions as $entry) {
|
||||
$id = $entry->id;
|
||||
|
||||
// to properly save the amount, do it times -1:
|
||||
$amount = $entry->amount * -1;
|
||||
@@ -227,7 +238,7 @@ class MigrationHelper implements MigrationHelperInterface
|
||||
/** @var \Account $toAccount */
|
||||
$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);
|
||||
|
||||
// save budgets and categories, on the journal
|
||||
@@ -243,13 +254,15 @@ class MigrationHelper implements MigrationHelperInterface
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function _importTransfers()
|
||||
{
|
||||
/** @var \Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface $journals */
|
||||
$journals = \App::make('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
|
||||
|
||||
foreach ($this->JSON->transfers as $entry) {
|
||||
$id = $entry->id;
|
||||
|
||||
// to properly save the amount, do it times 1 (?):
|
||||
$amount = $entry->amount * -1;
|
||||
@@ -262,9 +275,45 @@ class MigrationHelper implements MigrationHelperInterface
|
||||
$toAccount = isset($this->map['accounts'][$entry->accountto_id])
|
||||
? $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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
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.
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,28 @@
|
||||
|
||||
namespace Firefly\Helper\Migration;
|
||||
|
||||
|
||||
/**
|
||||
* Interface MigrationHelperInterface
|
||||
*
|
||||
* @package Firefly\Helper\Migration
|
||||
*/
|
||||
interface MigrationHelperInterface
|
||||
{
|
||||
/**
|
||||
* @param $path
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function loadFile($path);
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function validFile();
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function migrate();
|
||||
|
||||
}
|
||||
@@ -1,8 +1,19 @@
|
||||
<?php
|
||||
namespace Firefly\Helper\Preferences;
|
||||
/**
|
||||
* Class PreferencesHelper
|
||||
*
|
||||
* @package Firefly\Helper\Preferences
|
||||
*/
|
||||
class PreferencesHelper implements PreferencesHelperInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param null $default
|
||||
*
|
||||
* @return mixed|null|\Preference
|
||||
*/
|
||||
public function get($name, $default = null)
|
||||
{
|
||||
$pref = \Preference::where('user_id', \Auth::user()->id)->where('name', $name)->first();
|
||||
@@ -17,9 +28,16 @@ class PreferencesHelper implements PreferencesHelperInterface
|
||||
// create preference, return that:
|
||||
return $this->set($name, $default);
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param $value
|
||||
*
|
||||
* @return mixed|\Preference
|
||||
*/
|
||||
public function set($name, $value)
|
||||
{
|
||||
$pref = \Preference::where('user_id', \Auth::user()->id)->where('name', $name)->first();
|
||||
|
||||
@@ -1,10 +1,29 @@
|
||||
<?php
|
||||
namespace Firefly\Helper\Preferences;
|
||||
|
||||
/**
|
||||
* Interface PreferencesHelperInterface
|
||||
*
|
||||
* @package Firefly\Helper\Preferences
|
||||
*/
|
||||
interface PreferencesHelperInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param $value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function set($name, $value);
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param null $default
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($name, $default = null);
|
||||
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Firefly\Helper\Toolkit;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* Class Toolkit
|
||||
*
|
||||
@@ -37,10 +39,10 @@ class Toolkit implements ToolkitInterface
|
||||
}
|
||||
|
||||
// switch $range, update range or something:
|
||||
$start = \Session::has('start') ? \Session::get('start') : new \Carbon\Carbon();
|
||||
$end = \Session::has('end') ? \Session::get('end') : new \Carbon\Carbon();
|
||||
$today = new \Carbon\Carbon;
|
||||
\Log::debug('Start: ' . $start.' ('.\Session::has('start').')');
|
||||
$start = \Session::has('start') ? \Session::get('start') : new Carbon;
|
||||
$end = \Session::has('end') ? \Session::get('end') : new Carbon;
|
||||
$today = new Carbon;
|
||||
\Log::debug('Start: ' . $start . ' (' . \Session::has('start') . ')');
|
||||
\Log::debug('End: ' . $end);
|
||||
|
||||
// see if we have to do a prev / next thing:
|
||||
@@ -58,8 +60,8 @@ class Toolkit implements ToolkitInterface
|
||||
case 'custom':
|
||||
// when range is custom AND input, we ignore $today
|
||||
if (\Input::get('start') && \Input::get('end')) {
|
||||
$start = new \Carbon\Carbon(\Input::get('start'));
|
||||
$end = new \Carbon\Carbon(\Input::get('end'));
|
||||
$start = new Carbon(\Input::get('start'));
|
||||
$end = new Carbon(\Input::get('end'));
|
||||
} else {
|
||||
$start = \Session::get('start');
|
||||
$end = \Session::get('end');
|
||||
@@ -147,11 +149,14 @@ class Toolkit implements ToolkitInterface
|
||||
return \Redirect::route('index');
|
||||
|
||||
}
|
||||
return;
|
||||
return null;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getDateRangeDates()
|
||||
{
|
||||
return [\Session::get('start'), \Session::get('end')];
|
||||
|
||||
@@ -2,11 +2,21 @@
|
||||
|
||||
namespace Firefly\Helper\Toolkit;
|
||||
|
||||
|
||||
/**
|
||||
* Interface ToolkitInterface
|
||||
*
|
||||
* @package Firefly\Helper\Toolkit
|
||||
*/
|
||||
interface ToolkitInterface
|
||||
{
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getDateRange();
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getDateRangeDates();
|
||||
|
||||
}
|
||||
@@ -3,36 +3,101 @@
|
||||
|
||||
namespace Firefly\Storage\Account;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* Interface AccountRepositoryInterface
|
||||
*
|
||||
* @package Firefly\Storage\Account
|
||||
*/
|
||||
interface AccountRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function count();
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function get();
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getBeneficiaries();
|
||||
|
||||
public function find($id);
|
||||
/**
|
||||
* @param $accountId
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function find($accountId);
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function findByName($name);
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCashAccount();
|
||||
|
||||
/**
|
||||
* @param $ids
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getByIds($ids);
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getDefault();
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getActiveDefault();
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getActiveDefaultAsSelectList();
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param \AccountType $type
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function createOrFind($name, \AccountType $type);
|
||||
|
||||
}
|
||||
@@ -3,19 +3,37 @@
|
||||
|
||||
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
|
||||
{
|
||||
public $validator;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
return \Auth::user()->accounts()->with('accounttype')->orderBy('name', 'ASC')->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getBeneficiaries()
|
||||
{
|
||||
$list = \Auth::user()->accounts()->leftJoin(
|
||||
@@ -27,11 +45,21 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
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)
|
||||
{
|
||||
if (count($ids) > 0) {
|
||||
@@ -41,6 +69,9 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getDefault()
|
||||
{
|
||||
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.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getActiveDefault()
|
||||
{
|
||||
return \Auth::user()->accounts()->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||
@@ -57,6 +91,9 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
->get(['accounts.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function getActiveDefaultAsSelectList()
|
||||
{
|
||||
$list = \Auth::user()->accounts()->leftJoin(
|
||||
@@ -72,13 +109,24 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function 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);
|
||||
@@ -91,7 +139,7 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
$initial->active = 0;
|
||||
try {
|
||||
$initial->save();
|
||||
} catch (\Illuminate\Database\QueryException $e) {
|
||||
} catch (QueryException $e) {
|
||||
\Log::error('DB ERROR: ' . $e->getMessage());
|
||||
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)
|
||||
{
|
||||
$defaultAT = \AccountType::where('description', 'Default account')->first();
|
||||
@@ -123,14 +177,19 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
$account->active = isset($data['active']) ? $data['active'] : 1;
|
||||
try {
|
||||
$account->save();
|
||||
} catch (\Illuminate\Database\QueryException $e) {
|
||||
} catch (QueryException $e) {
|
||||
\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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @return \Account|mixed|null
|
||||
*/
|
||||
public function createOrFindBeneficiary($name)
|
||||
{
|
||||
if (is_null($name) || strlen($name) == 0) {
|
||||
@@ -140,6 +199,12 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
return $this->createOrFind($name, $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param \AccountType $type
|
||||
*
|
||||
* @return \Account|mixed
|
||||
*/
|
||||
public function createOrFind($name, \AccountType $type)
|
||||
{
|
||||
$beneficiary = $this->findByName($name);
|
||||
@@ -153,11 +218,19 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
return $beneficiary;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function findByName($name)
|
||||
{
|
||||
return \Auth::user()->accounts()->where('name', 'like', '%' . $name . '%')->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCashAccount()
|
||||
{
|
||||
$type = \AccountType::where('description', 'Cash account')->first();
|
||||
|
||||
@@ -2,16 +2,45 @@
|
||||
|
||||
namespace Firefly\Storage\Budget;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* Interface BudgetRepositoryInterface
|
||||
*
|
||||
* @package Firefly\Storage\Budget
|
||||
*/
|
||||
interface BudgetRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getAsSelectList();
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function get();
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
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);
|
||||
|
||||
}
|
||||
@@ -2,10 +2,19 @@
|
||||
|
||||
namespace Firefly\Storage\Budget;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* Class EloquentBudgetRepository
|
||||
*
|
||||
* @package Firefly\Storage\Budget
|
||||
*/
|
||||
class EloquentBudgetRepository implements BudgetRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function getAsSelectList()
|
||||
{
|
||||
$list = \Auth::user()->budgets()->with(
|
||||
@@ -18,20 +27,18 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
|
||||
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(
|
||||
['limits' => function ($q) use ($date) {
|
||||
$q->orderBy('limits.startdate', 'ASC');
|
||||
// $q->where('startdate',$date->format('Y-m-d'));
|
||||
}, 'limits.limitrepetitions' => function ($q) use ($date) {
|
||||
$q->orderBy('limit_repetitions.startdate', 'ASC');
|
||||
$q->where('startdate', $date->format('Y-m-d'));
|
||||
@@ -65,6 +72,11 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
|
||||
return $set;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
*
|
||||
* @return \Budget|mixed
|
||||
*/
|
||||
public function store($data)
|
||||
{
|
||||
$budget = new \Budget;
|
||||
@@ -76,7 +88,7 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
|
||||
if ($data['amount'] > 0) {
|
||||
$limit = new \Limit;
|
||||
$limit->budget()->associate($budget);
|
||||
$startDate = new \Carbon\Carbon;
|
||||
$startDate = new Carbon;
|
||||
switch ($data['repeat_freq']) {
|
||||
case 'daily':
|
||||
$startDate->startOfDay();
|
||||
@@ -111,6 +123,10 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
|
||||
return $budget;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
return \Auth::user()->budgets()->with(
|
||||
@@ -122,10 +138,15 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
|
||||
)->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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,16 +2,38 @@
|
||||
|
||||
namespace Firefly\Storage\Category;
|
||||
|
||||
|
||||
/**
|
||||
* Interface CategoryRepositoryInterface
|
||||
*
|
||||
* @package Firefly\Storage\Category
|
||||
*/
|
||||
interface CategoryRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function get();
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function createOrFind($name);
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function findByName($name);
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function store($name);
|
||||
|
||||
}
|
||||
@@ -2,14 +2,26 @@
|
||||
|
||||
namespace Firefly\Storage\Category;
|
||||
|
||||
|
||||
/**
|
||||
* Class EloquentCategoryRepository
|
||||
*
|
||||
* @package Firefly\Storage\Category
|
||||
*/
|
||||
class EloquentCategoryRepository implements CategoryRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
return \Auth::user()->categories()->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @return \Category|mixed
|
||||
*/
|
||||
public function createOrFind($name)
|
||||
{
|
||||
$category = $this->findByName($name);
|
||||
@@ -21,12 +33,22 @@ class EloquentCategoryRepository implements CategoryRepositoryInterface
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function findByName($name)
|
||||
{
|
||||
return \Auth::user()->categories()->where('name', 'LIKE', '%' . $name . '%')->first();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @return \Category|mixed
|
||||
*/
|
||||
public function store($name)
|
||||
{
|
||||
$category = new \Category();
|
||||
|
||||
@@ -3,14 +3,29 @@
|
||||
|
||||
namespace Firefly\Storage\Component;
|
||||
|
||||
|
||||
/**
|
||||
* Interface ComponentRepositoryInterface
|
||||
*
|
||||
* @package Firefly\Storage\Component
|
||||
*/
|
||||
interface ComponentRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function count();
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function get();
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function store($data);
|
||||
|
||||
}
|
||||
@@ -3,32 +3,56 @@
|
||||
|
||||
namespace Firefly\Storage\Component;
|
||||
|
||||
use Firefly\Exception\FireflyException;
|
||||
use Illuminate\Database\QueryException;
|
||||
|
||||
/**
|
||||
* Class EloquentComponentRepository
|
||||
*
|
||||
* @package Firefly\Storage\Component
|
||||
*/
|
||||
class EloquentComponentRepository implements ComponentRepositoryInterface
|
||||
{
|
||||
public $validator;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return \Auth::user()->components()->count();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed|void
|
||||
* @throws \Firefly\Exception\FireflyException
|
||||
*/
|
||||
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)
|
||||
{
|
||||
if (!isset($data['class'])) {
|
||||
throw new \Firefly\Exception\FireflyException('No class type present.');
|
||||
throw new FireflyException('No class type present.');
|
||||
}
|
||||
switch ($data['class']) {
|
||||
default:
|
||||
case 'Budget':
|
||||
$component = new \Budget;
|
||||
break;
|
||||
@@ -41,9 +65,9 @@ class EloquentComponentRepository implements ComponentRepositoryInterface
|
||||
$component->user()->associate(\Auth::user());
|
||||
try {
|
||||
$component->save();
|
||||
} catch (\Illuminate\Database\QueryException $e) {
|
||||
} catch (QueryException $e) {
|
||||
\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']);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: sander
|
||||
* Date: 20/07/14
|
||||
* Time: 13:43
|
||||
*/
|
||||
|
||||
namespace Firefly\Storage\Limit;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* Class EloquentLimitRepository
|
||||
*
|
||||
* @package Firefly\Storage\Limit
|
||||
*/
|
||||
class EloquentLimitRepository implements LimitRepositoryInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param $limitId
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function find($limitId)
|
||||
{
|
||||
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.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
*
|
||||
* @return \Limit
|
||||
*/
|
||||
public function store($data)
|
||||
{
|
||||
$budget = \Budget::find($data['budget_id']);
|
||||
@@ -28,7 +40,7 @@ class EloquentLimitRepository implements LimitRepositoryInterface
|
||||
return new \Limit;
|
||||
}
|
||||
// set the date to the correct start period:
|
||||
$date = new \Carbon\Carbon($data['startdate']);
|
||||
$date = new Carbon($data['startdate']);
|
||||
switch ($data['period']) {
|
||||
case 'daily':
|
||||
$date->startOfDay();
|
||||
@@ -79,10 +91,15 @@ class EloquentLimitRepository implements LimitRepositoryInterface
|
||||
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();
|
||||
|
||||
return $result;
|
||||
|
||||
@@ -2,13 +2,36 @@
|
||||
|
||||
namespace Firefly\Storage\Limit;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* Interface LimitRepositoryInterface
|
||||
*
|
||||
* @package Firefly\Storage\Limit
|
||||
*/
|
||||
interface LimitRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
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);
|
||||
}
|
||||
@@ -3,11 +3,18 @@ namespace Firefly\Storage;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
/**
|
||||
* Class StorageServiceProvider
|
||||
*
|
||||
* @package Firefly\Storage
|
||||
*/
|
||||
class StorageServiceProvider extends ServiceProvider
|
||||
{
|
||||
|
||||
|
||||
// Triggered automatically by Laravel
|
||||
/**
|
||||
* Triggered automatically by Laravel
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->bind(
|
||||
|
||||
@@ -2,7 +2,11 @@
|
||||
|
||||
namespace Firefly\Storage\Transaction;
|
||||
|
||||
|
||||
/**
|
||||
* Class EloquentTransactionRepository
|
||||
*
|
||||
* @package Firefly\Storage\Transaction
|
||||
*/
|
||||
class EloquentTransactionRepository implements TransactionRepositoryInterface
|
||||
{
|
||||
|
||||
|
||||
@@ -2,7 +2,11 @@
|
||||
|
||||
namespace Firefly\Storage\Transaction;
|
||||
|
||||
|
||||
/**
|
||||
* Interface TransactionRepositoryInterface
|
||||
*
|
||||
* @package Firefly\Storage\Transaction
|
||||
*/
|
||||
interface TransactionRepositoryInterface
|
||||
{
|
||||
|
||||
|
||||
@@ -3,10 +3,22 @@
|
||||
|
||||
namespace Firefly\Storage\TransactionJournal;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Firefly\Exception\FireflyException;
|
||||
|
||||
/**
|
||||
* Class EloquentTransactionJournalRepository
|
||||
*
|
||||
* @package Firefly\Storage\TransactionJournal
|
||||
*/
|
||||
class EloquentTransactionJournalRepository implements TransactionJournalRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param $journalId
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function find($journalId)
|
||||
{
|
||||
return \Auth::user()->transactionjournals()->with(
|
||||
@@ -41,7 +53,7 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
* B loses 200 (-200). * 1
|
||||
*
|
||||
* @param \Account $from
|
||||
* @param \Account $to
|
||||
* @param \Account $toAccount
|
||||
* @param $description
|
||||
* @param $amount
|
||||
* @param \Carbon\Carbon $date
|
||||
@@ -49,7 +61,7 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
* @return \TransactionJournal
|
||||
* @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 . '".');
|
||||
|
||||
@@ -59,23 +71,23 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
if (round(floatval($amount), 2) == 0.00) {
|
||||
\Log::error('Transaction will never save: amount = 0');
|
||||
\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:
|
||||
if ($from->id == $to->id) {
|
||||
if ($from->id == $toAccount->id) {
|
||||
\Log::error('Accounts cannot be equal');
|
||||
\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:
|
||||
$toAT = $to->accountType->description;
|
||||
$toAT = $toAccount->accountType->description;
|
||||
$fromAT = $from->accountType->description;
|
||||
|
||||
$journalType = null;
|
||||
|
||||
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();
|
||||
break;
|
||||
|
||||
@@ -99,19 +111,19 @@ 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
|
||||
. ' and AccountTo "' . $toAccount->name . '" will gain/lose ' . $amountTo
|
||||
);
|
||||
|
||||
if (is_null($journalType)) {
|
||||
\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:
|
||||
$currency = \TransactionCurrency::where('code', 'EUR')->first();
|
||||
if (is_null($currency)) {
|
||||
\Log::error('No currency for journal!');
|
||||
throw new \Firefly\Exception\FireflyException('No currency for journal!');
|
||||
throw new FireflyException('No currency for journal!');
|
||||
}
|
||||
|
||||
// new journal:
|
||||
@@ -126,7 +138,7 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
\Log::error('Cannot create valid journal.');
|
||||
\Log::error('Errors: ' . print_r($journal->errors()->all(), true));
|
||||
\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();
|
||||
|
||||
@@ -139,19 +151,19 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
if (!$fromTransaction->save()) {
|
||||
\Log::error('Cannot create valid transaction (from) for journal #' . $journal->id);
|
||||
\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();
|
||||
|
||||
$toTransaction = new \Transaction;
|
||||
$toTransaction->account()->associate($to);
|
||||
$toTransaction->account()->associate($toAccount);
|
||||
$toTransaction->transactionJournal()->associate($journal);
|
||||
$toTransaction->description = null;
|
||||
$toTransaction->amount = $amountTo;
|
||||
if (!$toTransaction->save()) {
|
||||
\Log::error('Cannot create valid transaction (to) for journal #' . $journal->id);
|
||||
\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();
|
||||
|
||||
@@ -160,12 +172,23 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
return $journal;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
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;
|
||||
$query = \Auth::user()->transactionjournals()->with(
|
||||
@@ -187,6 +210,11 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $count
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function paginate($count = 25)
|
||||
{
|
||||
$query = \Auth::user()->transactionjournals()->with(
|
||||
@@ -207,7 +235,13 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
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.
|
||||
$types = [];
|
||||
@@ -231,7 +265,13 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
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;
|
||||
$query = \Auth::user()->transactionjournals()->with(
|
||||
|
||||
@@ -2,21 +2,69 @@
|
||||
|
||||
namespace Firefly\Storage\TransactionJournal;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* Interface TransactionJournalRepositoryInterface
|
||||
*
|
||||
* @package Firefly\Storage\TransactionJournal
|
||||
*/
|
||||
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();
|
||||
|
||||
/**
|
||||
* @param $journalId
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
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);
|
||||
|
||||
}
|
||||
@@ -3,12 +3,25 @@
|
||||
|
||||
namespace Firefly\Storage\User;
|
||||
|
||||
/**
|
||||
* Class EloquentUserRepository
|
||||
*
|
||||
* @package Firefly\Storage\User
|
||||
*/
|
||||
class EloquentUserRepository implements UserRepositoryInterface
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $array
|
||||
*
|
||||
* @return bool|\User
|
||||
*/
|
||||
public function register($array)
|
||||
{
|
||||
$user = new \User;
|
||||
@@ -26,6 +39,11 @@ class EloquentUserRepository implements UserRepositoryInterface
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $array
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function auth($array)
|
||||
{
|
||||
$user = \User::where('email', $array['email'])->first();
|
||||
@@ -36,16 +54,32 @@ class EloquentUserRepository implements UserRepositoryInterface
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $reset
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function findByReset($reset)
|
||||
{
|
||||
return \User::where('reset', $reset)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $email
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function findByEmail($email)
|
||||
{
|
||||
return \User::where('email', $email)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
* @param $password
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function updatePassword(\User $user, $password)
|
||||
{
|
||||
$password = \Hash::make($password);
|
||||
|
||||
@@ -3,17 +3,47 @@
|
||||
|
||||
namespace Firefly\Storage\User;
|
||||
|
||||
|
||||
/**
|
||||
* Interface UserRepositoryInterface
|
||||
*
|
||||
* @package Firefly\Storage\User
|
||||
*/
|
||||
interface UserRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @param $array
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function register($array);
|
||||
|
||||
/**
|
||||
* @param $array
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function auth($array);
|
||||
|
||||
/**
|
||||
* @param $reset
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function findByReset($reset);
|
||||
|
||||
/**
|
||||
* @param $email
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function findByEmail($email);
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
* @param $password
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function updatePassword(\User $user, $password);
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
|
||||
namespace Firefly\Trigger\Limits;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Events\Dispatcher;
|
||||
|
||||
/**
|
||||
* Class EloquentLimitTrigger
|
||||
*
|
||||
@@ -64,14 +68,14 @@ class EloquentLimitTrigger
|
||||
|
||||
try {
|
||||
$repetition->save();
|
||||
} catch (\Illuminate\Database\QueryException $e) {
|
||||
} catch (QueryException $e) {
|
||||
// do nothing
|
||||
\Log::error($e->getMessage());
|
||||
}
|
||||
} else {
|
||||
// there are limits already, do they
|
||||
// fall into the range surrounding today?
|
||||
$today = new \Carbon\Carbon;
|
||||
$today = new Carbon;
|
||||
$today->addMonths(2);
|
||||
if ($limit->repeats == 1 && $today >= $limit->startdate) {
|
||||
|
||||
@@ -141,7 +145,7 @@ class EloquentLimitTrigger
|
||||
$repetition->limit()->associate($limit);
|
||||
try {
|
||||
$repetition->save();
|
||||
} catch (\Illuminate\Database\QueryException $e) {
|
||||
} catch (QueryException $e) {
|
||||
// do nothing
|
||||
\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');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user