mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-04 11:48:05 +00:00
Moar updates.
This commit is contained in:
@@ -38,10 +38,10 @@ class HomeController extends BaseController
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
Queue::push(function($job)
|
||||
{
|
||||
Log::debug('This is a job!');
|
||||
});
|
||||
// Queue::push(function($job)
|
||||
// {
|
||||
// Log::debug('This is a job!');
|
||||
// });
|
||||
|
||||
\Event::fire('limits.check');
|
||||
\Event::fire('piggybanks.check');
|
||||
|
@@ -28,8 +28,10 @@ class MigrateController extends BaseController
|
||||
if (is_writable($path)) {
|
||||
Input::file('file')->move($path, $fileName);
|
||||
// so now we push something in a queue and do something with it! Yay!
|
||||
Queue::push('Firefly\Queue\Import@start', ['file' => $fullName,'user' => \Auth::user()->id]);
|
||||
exit;
|
||||
\Log::debug('Pushed a job to start the import.');
|
||||
Queue::push('Firefly\Queue\Import@start', ['file' => $fullName, 'user' => \Auth::user()->id]);
|
||||
Session::flash('success', 'The import job has been queued. Please be patient. Data will appear');
|
||||
return Redirect::route('index');
|
||||
}
|
||||
Session::flash('error', 'Could not save file to storage.');
|
||||
return Redirect::route('migrate.index');
|
||||
|
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
class CreateFailedJobsTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('failed_jobs');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('failed_jobs', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->text('connection');
|
||||
$table->text('queue');
|
||||
$table->text('payload');
|
||||
$table->timestamp('failed_at');
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@@ -3,8 +3,7 @@
|
||||
namespace Firefly\Queue;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Firefly\Exception\FireflyException;
|
||||
use Illuminate\Queue\Jobs\SyncJob;
|
||||
use Illuminate\Queue\Jobs\Job;
|
||||
|
||||
/**
|
||||
* Class Import
|
||||
@@ -24,6 +23,18 @@ class Import
|
||||
/** @var \Firefly\Storage\Category\CategoryRepositoryInterface */
|
||||
protected $_categories;
|
||||
|
||||
/** @var \Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface */
|
||||
protected $_journals;
|
||||
|
||||
/** @var \Firefly\Storage\Limit\LimitRepositoryInterface */
|
||||
protected $_limits;
|
||||
|
||||
/** @var \Firefly\Storage\Piggybank\PiggybankRepositoryInterface */
|
||||
protected $_piggybanks;
|
||||
|
||||
/** @var \Firefly\Storage\RecurringTransaction\RecurringTransactionRepositoryInterface */
|
||||
protected $_recurring;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@@ -33,19 +44,59 @@ class Import
|
||||
$this->_repository = \App::make('Firefly\Storage\Import\ImportRepositoryInterface');
|
||||
$this->_budgets = \App::make('Firefly\Storage\Budget\BudgetRepositoryInterface');
|
||||
$this->_categories = \App::make('Firefly\Storage\Category\CategoryRepositoryInterface');
|
||||
$this->_journals = \App::make('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
|
||||
$this->_limits = \App::make('Firefly\Storage\Limit\LimitRepositoryInterface');
|
||||
$this->_piggybanks = \App::make('Firefly\Storage\Piggybank\PiggybankRepositoryInterface');
|
||||
$this->_recurring = \App::make('Firefly\Storage\RecurringTransaction\RecurringTransactionRepositoryInterface');
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Job $job
|
||||
* @param array $payload
|
||||
* @throws \Firefly\Exception\FireflyException
|
||||
*/
|
||||
public function importComponent(Job $job, array $payload)
|
||||
{
|
||||
|
||||
\Log::debug('Going to import component "' . $payload['data']['name'] . '".');
|
||||
switch ($payload['data']['type']['type']) {
|
||||
case 'beneficiary':
|
||||
$payload['class'] = 'Account';
|
||||
$payload['data']['account_type'] = 'Beneficiary account';
|
||||
$this->importAccount($job, $payload);
|
||||
break;
|
||||
case 'budget':
|
||||
$this->importBudget($job, $payload);
|
||||
break;
|
||||
case 'category':
|
||||
$this->importCategory($job, $payload);
|
||||
break;
|
||||
case 'payer':
|
||||
$job->delete();
|
||||
break;
|
||||
default:
|
||||
$job->delete();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Import a personal account or beneficiary as a new account.
|
||||
*
|
||||
* @param SyncJob $job
|
||||
* @param Job $job
|
||||
* @param array $payload
|
||||
*/
|
||||
public function importAccount(SyncJob $job, array $payload)
|
||||
public function importAccount(Job $job, array $payload)
|
||||
{
|
||||
|
||||
/** @var \Importmap $importMap */
|
||||
$importMap = $this->_repository->findImportmap($payload['mapID']);
|
||||
$user = $importMap->user;
|
||||
$this->overruleUser($user);
|
||||
|
||||
|
||||
// maybe we've already imported this account:
|
||||
$importEntry = $this->_repository->findImportEntry($importMap, 'Account', intval($payload['data']['id']));
|
||||
@@ -85,16 +136,33 @@ class Import
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
*/
|
||||
protected function overruleUser(\User $user)
|
||||
{
|
||||
$this->_accounts->overruleUser($user);
|
||||
$this->_budgets->overruleUser($user);
|
||||
$this->_categories->overruleUser($user);
|
||||
$this->_journals->overruleUser($user);
|
||||
$this->_limits->overruleUser($user);
|
||||
$this->_repository->overruleUser($user);
|
||||
$this->_piggybanks->overruleUser($user);
|
||||
$this->_recurring->overruleUser($user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Import a budget into Firefly.
|
||||
*
|
||||
* @param SyncJob $job
|
||||
* @param Job $job
|
||||
* @param array $payload
|
||||
*/
|
||||
public function importBudget(SyncJob $job, array $payload)
|
||||
public function importBudget(Job $job, array $payload)
|
||||
{
|
||||
/** @var \Importmap $importMap */
|
||||
$importMap = $this->_repository->findImportmap($payload['mapID']);
|
||||
$user = $importMap->user;
|
||||
$this->overruleUser($user);
|
||||
|
||||
// maybe we've already imported this budget:
|
||||
$bdg = $this->_budgets->findByName($payload['data']['name']);
|
||||
@@ -117,14 +185,16 @@ class Import
|
||||
/**
|
||||
* Import a category into Firefly.
|
||||
*
|
||||
* @param SyncJob $job
|
||||
* @param Job $job
|
||||
* @param array $payload
|
||||
*/
|
||||
public function importCategory(SyncJob $job, array $payload)
|
||||
public function importCategory(Job $job, array $payload)
|
||||
{
|
||||
|
||||
/** @var \Importmap $importMap */
|
||||
$importMap = $this->_repository->findImportmap($payload['mapID']);
|
||||
$user = $importMap->user;
|
||||
$this->overruleUser($user);
|
||||
|
||||
// try to find budget:
|
||||
$current = $this->_categories->findByName($payload['data']['name']);
|
||||
@@ -141,85 +211,42 @@ class Import
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SyncJob $job
|
||||
* @param array $payload
|
||||
* @throws \Firefly\Exception\FireflyException
|
||||
*/
|
||||
public function importComponent(SyncJob $job, array $payload)
|
||||
{
|
||||
|
||||
\Log::debug('Going to import component "' . $payload['data']['name'] . '".');
|
||||
switch ($payload['data']['type']['type']) {
|
||||
case 'beneficiary':
|
||||
$jobFunction = 'Firefly\Queue\Import@importAccount';
|
||||
$payload['class'] = 'Account';
|
||||
$payload['data']['account_type'] = 'Beneficiary account';
|
||||
\Log::debug('It is a beneficiary.');
|
||||
break;
|
||||
case 'budget':
|
||||
$jobFunction = 'Firefly\Queue\Import@importBudget';
|
||||
\Log::debug('It is a budget.');
|
||||
break;
|
||||
case 'category':
|
||||
$jobFunction = 'Firefly\Queue\Import@importCategory';
|
||||
\Log::debug('It is a category.');
|
||||
break;
|
||||
case 'payer':
|
||||
// ignored!
|
||||
break;
|
||||
default:
|
||||
throw new FireflyException('No import case for "' . $payload['data']['type']['type'] . '"!');
|
||||
}
|
||||
if (isset($jobFunction)) {
|
||||
\Queue::push($jobFunction, $payload);
|
||||
}
|
||||
$job->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SyncJob $job
|
||||
* @param Job $job
|
||||
* @param array $payload
|
||||
*/
|
||||
public function importComponentTransaction(SyncJob $job, array $payload)
|
||||
public function importComponentTransaction(Job $job, array $payload)
|
||||
{
|
||||
if ($job->attempts() > 1) {
|
||||
\Log::info('Job running for ' . $job->attempts() . 'th time!');
|
||||
\Log::info('importComponentTransaction Job running for ' . $job->attempts() . 'th time!');
|
||||
}
|
||||
if ($job->attempts() > 30) {
|
||||
\Log::error('importComponentTransaction Job running for ' . $job->attempts() . 'th time, so KILL!');
|
||||
$job->delete();
|
||||
return;
|
||||
}
|
||||
|
||||
$oldComponentId = intval($payload['data']['component_id']);
|
||||
$oldTransactionId = intval($payload['data']['transaction_id']);
|
||||
|
||||
/** @var \Firefly\Storage\Import\ImportRepositoryInterface $repository */
|
||||
$repository = \App::make('Firefly\Storage\Import\ImportRepositoryInterface');
|
||||
|
||||
|
||||
/** @var \Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface $journals */
|
||||
$journals = \App::make('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
|
||||
|
||||
/** @var \Firefly\Storage\Category\CategoryRepositoryInterface $categories */
|
||||
$categories = \App::make('Firefly\Storage\Category\CategoryRepositoryInterface');
|
||||
|
||||
/** @var \Firefly\Storage\Account\AccountRepositoryInterface $accounts */
|
||||
$accounts = \App::make('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
|
||||
|
||||
/** @var \Importmap $importMap */
|
||||
$importMap = $repository->findImportmap($payload['mapID']);
|
||||
$importMap = $this->_repository->findImportmap($payload['mapID']);
|
||||
$user = $importMap->user;
|
||||
$this->overruleUser($user);
|
||||
|
||||
$oldTransactionMap = $repository->findImportEntry($importMap, 'Transaction', $oldTransactionId);
|
||||
$oldTransactionMap = $this->_repository->findImportEntry($importMap, 'Transaction', $oldTransactionId);
|
||||
|
||||
// we don't know what the component is, so we need to search for it in a set
|
||||
// of possible types (Account / Beneficiary, Budget, Category)
|
||||
/** @var \Importentry $oldComponentMap */
|
||||
$oldComponentMap = $repository->findImportComponentMap($importMap, $oldComponentId);
|
||||
$oldComponentMap = $this->_repository->findImportComponentMap($importMap, $oldComponentId);
|
||||
|
||||
if (is_null($oldComponentMap)) {
|
||||
\Log::debug('Could not run this one, waiting for five seconds...');
|
||||
$job->release(5);
|
||||
\Log::debug('importComponentTransaction Could not run this one, waiting for five minutes...');
|
||||
$job->release(300);
|
||||
return;
|
||||
}
|
||||
|
||||
$journal = $journals->find($oldTransactionMap->new);
|
||||
$journal = $this->_journals->find($oldTransactionMap->new);
|
||||
\Log::debug('Going to update ' . $journal->description);
|
||||
|
||||
// find the cash account:
|
||||
@@ -237,8 +264,8 @@ class Import
|
||||
|
||||
break;
|
||||
case 'Category':
|
||||
$category = $categories->find($oldComponentMap->new);
|
||||
$journal = $journals->find($oldTransactionMap->new);
|
||||
$category = $this->_categories->find($oldComponentMap->new);
|
||||
$journal = $this->_journals->find($oldTransactionMap->new);
|
||||
\Log::info('Updating transactions Category.');
|
||||
$journal->categories()->save($category);
|
||||
$journal->save();
|
||||
@@ -246,11 +273,11 @@ class Import
|
||||
break;
|
||||
case 'Account':
|
||||
\Log::info('Updating transactions Account.');
|
||||
$account = $accounts->find($oldComponentMap->new);
|
||||
$journal = $journals->find($oldTransactionMap->new);
|
||||
$account = $this->_accounts->find($oldComponentMap->new);
|
||||
$journal = $this->_journals->find($oldTransactionMap->new);
|
||||
if (is_null($account)) {
|
||||
\Log::debug('Cash account is needed.');
|
||||
$account = $accounts->getCashAccount();
|
||||
$account = $this->_accounts->getCashAccount();
|
||||
\Log::info($account);
|
||||
}
|
||||
|
||||
@@ -269,51 +296,51 @@ class Import
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SyncJob $job
|
||||
* @param Job $job
|
||||
* @param array $payload
|
||||
*/
|
||||
public function importLimit(SyncJob $job, array $payload)
|
||||
public function importLimit(Job $job, array $payload)
|
||||
{
|
||||
|
||||
/** @var \Firefly\Storage\Limit\LimitRepositoryInterface $limits */
|
||||
$limits = \App::make('Firefly\Storage\Limit\LimitRepositoryInterface');
|
||||
|
||||
/** @var \Firefly\Storage\Import\ImportRepositoryInterface $repository */
|
||||
$repository = \App::make('Firefly\Storage\Import\ImportRepositoryInterface');
|
||||
|
||||
/** @var \Firefly\Storage\Budget\BudgetRepositoryInterface $budgets */
|
||||
$budgets = \App::make('Firefly\Storage\Budget\BudgetRepositoryInterface');
|
||||
if ($job->attempts() > 30) {
|
||||
\Log::error('importLimit Job running for ' . $job->attempts() . 'th time, so KILL!');
|
||||
$job->delete();
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var \Importmap $importMap */
|
||||
$importMap = $repository->findImportmap($payload['mapID']);
|
||||
$importMap = $this->_repository->findImportmap($payload['mapID']);
|
||||
$user = $importMap->user;
|
||||
$this->overruleUser($user);
|
||||
|
||||
|
||||
// find the budget this limit is part of:
|
||||
$importEntry = $repository->findImportEntry($importMap, 'Budget', intval($payload['data']['component_id']));
|
||||
$importEntry = $this->_repository->findImportEntry($importMap, 'Budget',
|
||||
intval($payload['data']['component_id']));
|
||||
|
||||
// budget is not yet imported:
|
||||
if (is_null($importEntry)) {
|
||||
\Log::debug('Released job for work in five seconds...');
|
||||
$job->release(5);
|
||||
\Log::debug('importLimit Cannot import limit #' . $payload['data']['id'] .
|
||||
' because the budget is not here yet. #' . $job->attempts());
|
||||
$job->release(300);
|
||||
return;
|
||||
}
|
||||
// find similar limit:
|
||||
\Log::debug('Trying to find budget with ID #' . $importEntry->new . ', based on entry #' . $importEntry->id);
|
||||
$budget = $budgets->find($importEntry->new);
|
||||
$budget = $this->_budgets->find($importEntry->new);
|
||||
if (!is_null($budget)) {
|
||||
$current = $limits->findByBudgetAndDate($budget, new Carbon($payload['data']['date']));
|
||||
$current = $this->_limits->findByBudgetAndDate($budget, new Carbon($payload['data']['date']));
|
||||
if (is_null($current)) {
|
||||
// create it!
|
||||
$payload['data']['budget_id'] = $budget->id;
|
||||
$payload['data']['startdate'] = $payload['data']['date'];
|
||||
$payload['data']['period'] = 'monthly';
|
||||
$lim = $limits->store((array)$payload['data']);
|
||||
$repository->store($importMap, 'Limit', $payload['data']['id'], $lim->id);
|
||||
$lim = $this->_limits->store((array)$payload['data']);
|
||||
$this->_repository->store($importMap, 'Limit', $payload['data']['id'], $lim->id);
|
||||
\Event::fire('limits.store', [$lim]);
|
||||
\Log::debug('Imported ' . $payload['class'] . ', for ' . $budget->name . ' (' . $lim->startdate . ').');
|
||||
} else {
|
||||
// already has!
|
||||
$repository->store($importMap, 'Budget', $payload['data']['id'], $current->id);
|
||||
$this->_repository->store($importMap, 'Budget', $payload['data']['id'], $current->id);
|
||||
\Log::debug('Already had ' . $payload['class'] . ', for ' . $budget->name . ' (' . $current->startdate . ').');
|
||||
}
|
||||
} else {
|
||||
@@ -324,34 +351,27 @@ class Import
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SyncJob $job
|
||||
* @param Job $job
|
||||
* @param array $payload
|
||||
*/
|
||||
public function importPiggybank(SyncJob $job, array $payload)
|
||||
public function importPiggybank(Job $job, array $payload)
|
||||
{
|
||||
/** @var \Firefly\Storage\Piggybank\PiggybankRepositoryInterface $piggybanks */
|
||||
$piggybanks = \App::make('Firefly\Storage\Piggybank\PiggybankRepositoryInterface');
|
||||
|
||||
/** @var \Firefly\Storage\Import\ImportRepositoryInterface $repository */
|
||||
$repository = \App::make('Firefly\Storage\Import\ImportRepositoryInterface');
|
||||
|
||||
/** @var \Importmap $importMap */
|
||||
$importMap = $repository->findImportmap($payload['mapID']);
|
||||
$importMap = $this->_repository->findImportmap($payload['mapID']);
|
||||
$user = $importMap->user;
|
||||
$this->overruleUser($user);
|
||||
|
||||
/** @var \Firefly\Storage\Account\AccountRepositoryInterface $accounts */
|
||||
$accounts = \App::make('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
|
||||
// try to find related piggybank:
|
||||
$current = $piggybanks->findByName($payload['data']['name']);
|
||||
// try to find related piggybank:
|
||||
$current = $this->_piggybanks->findByName($payload['data']['name']);
|
||||
|
||||
// we need an account to go with this piggy bank:
|
||||
$set = $accounts->getActiveDefault();
|
||||
$set = $this->_accounts->getActiveDefault();
|
||||
if (count($set) > 0) {
|
||||
$account = $set[0];
|
||||
$payload['data']['account_id'] = $account->id;
|
||||
} else {
|
||||
\Log::debug('Released job for work in five seconds...');
|
||||
$job->release(5);
|
||||
\Log::debug('Released job for work in five minutes...');
|
||||
$job->release(300);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -361,35 +381,31 @@ class Import
|
||||
$payload['data']['rep_every'] = 1;
|
||||
$payload['data']['reminder_skip'] = 1;
|
||||
$payload['data']['rep_times'] = 1;
|
||||
$piggy = $piggybanks->store((array)$payload['data']);
|
||||
$repository->store($importMap, 'Piggybank', $payload['data']['id'], $piggy->id);
|
||||
$piggy = $this->_piggybanks->store((array)$payload['data']);
|
||||
$this->_repository->store($importMap, 'Piggybank', $payload['data']['id'], $piggy->id);
|
||||
\Log::debug('Imported ' . $payload['class'] . ' "' . $payload['data']['name'] . '".');
|
||||
\Event::fire('piggybanks.store', [$piggy]);
|
||||
} else {
|
||||
$repository->store($importMap, 'Piggybank', $payload['data']['id'], $current->id);
|
||||
$this->_repository->store($importMap, 'Piggybank', $payload['data']['id'], $current->id);
|
||||
\Log::debug('Already had ' . $payload['class'] . ' "' . $payload['data']['name'] . '".');
|
||||
}
|
||||
$job->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SyncJob $job
|
||||
* @param Job $job
|
||||
* @param array $payload
|
||||
*/
|
||||
public function importPredictable(SyncJob $job, array $payload)
|
||||
public function importPredictable(Job $job, array $payload)
|
||||
{
|
||||
/** @var \Firefly\Storage\RecurringTransaction\RecurringTransactionRepositoryInterface $piggybanks */
|
||||
$recurring = \App::make('Firefly\Storage\RecurringTransaction\RecurringTransactionRepositoryInterface');
|
||||
|
||||
/** @var \Firefly\Storage\Import\ImportRepositoryInterface $repository */
|
||||
$repository = \App::make('Firefly\Storage\Import\ImportRepositoryInterface');
|
||||
|
||||
/** @var \Importmap $importMap */
|
||||
$importMap = $repository->findImportmap($payload['mapID']);
|
||||
$importMap = $this->_repository->findImportmap($payload['mapID']);
|
||||
$user = $importMap->user;
|
||||
$this->overruleUser($user);
|
||||
|
||||
|
||||
// try to find related recurring transaction:
|
||||
$current = $recurring->findByName($payload['data']['description']);
|
||||
$current = $this->_recurring->findByName($payload['data']['description']);
|
||||
if (is_null($current)) {
|
||||
|
||||
$payload['data']['name'] = $payload['data']['description'];
|
||||
@@ -402,12 +418,12 @@ class Import
|
||||
$payload['data']['active'] = intval($payload['data']['inactive']) == 1 ? 0 : 1;
|
||||
$payload['data']['automatch'] = 1;
|
||||
|
||||
$recur = $recurring->store((array)$payload['data']);
|
||||
$recur = $this->_recurring->store((array)$payload['data']);
|
||||
|
||||
$repository->store($importMap, 'RecurringTransaction', $payload['data']['id'], $recur->id);
|
||||
$this->_repository->store($importMap, 'RecurringTransaction', $payload['data']['id'], $recur->id);
|
||||
\Log::debug('Imported ' . $payload['class'] . ' "' . $payload['data']['name'] . '".');
|
||||
} else {
|
||||
$repository->store($importMap, 'RecurringTransaction', $payload['data']['id'], $current->id);
|
||||
$this->_repository->store($importMap, 'RecurringTransaction', $payload['data']['id'], $current->id);
|
||||
\Log::debug('Already had ' . $payload['class'] . ' "' . $payload['data']['description'] . '".');
|
||||
}
|
||||
$job->delete();
|
||||
@@ -415,10 +431,10 @@ class Import
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SyncJob $job
|
||||
* @param Job $job
|
||||
* @param array $payload
|
||||
*/
|
||||
public function importSetting(SyncJob $job, array $payload)
|
||||
public function importSetting(Job $job, array $payload)
|
||||
{
|
||||
switch ($payload['data']['name']) {
|
||||
default:
|
||||
@@ -429,23 +445,17 @@ class Import
|
||||
// if we have this account, update all piggy banks:
|
||||
$accountID = intval($payload['data']['value']);
|
||||
|
||||
/** @var \Firefly\Storage\Import\ImportRepositoryInterface $repository */
|
||||
$repository = \App::make('Firefly\Storage\Import\ImportRepositoryInterface');
|
||||
|
||||
/** @var \Importmap $importMap */
|
||||
$importMap = $repository->findImportmap($payload['mapID']);
|
||||
$importMap = $this->_repository->findImportmap($payload['mapID']);
|
||||
$user = $importMap->user;
|
||||
$this->overruleUser($user);
|
||||
|
||||
|
||||
$importEntry = $repository->findImportEntry($importMap, 'Account', $accountID);
|
||||
$importEntry = $this->_repository->findImportEntry($importMap, 'Account', $accountID);
|
||||
if ($importEntry) {
|
||||
/** @var \Firefly\Storage\Account\AccountRepositoryInterface $accounts */
|
||||
$accounts = \App::make('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
|
||||
/** @var \Firefly\Storage\Piggybank\PiggybankRepositoryInterface $piggybanks */
|
||||
$piggybanks = \App::make('Firefly\Storage\Piggybank\PiggybankRepositoryInterface');
|
||||
|
||||
$all = $piggybanks->get();
|
||||
$account = $accounts->find($importEntry->new);
|
||||
$all = $this->_piggybanks->get();
|
||||
$account = $this->_accounts->find($importEntry->new);
|
||||
|
||||
\Log::debug('Updating all piggybanks, found the right setting.');
|
||||
foreach ($all as $piggy) {
|
||||
@@ -454,7 +464,8 @@ class Import
|
||||
$piggy->save();
|
||||
}
|
||||
} else {
|
||||
$job->release(5);
|
||||
\Log::debug('importSetting wait five minutes and try again...');
|
||||
$job->release(300);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -463,35 +474,29 @@ class Import
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SyncJob $job
|
||||
* @param Job $job
|
||||
* @param array $payload
|
||||
*/
|
||||
public function importTransaction(SyncJob $job, array $payload)
|
||||
public function importTransaction(Job $job, array $payload)
|
||||
{
|
||||
/** @var \Firefly\Storage\Import\ImportRepositoryInterface $repository */
|
||||
$repository = \App::make('Firefly\Storage\Import\ImportRepositoryInterface');
|
||||
|
||||
/** @var \Firefly\Storage\Account\AccountRepositoryInterface $accounts */
|
||||
$accounts = \App::make('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
|
||||
/** @var \Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface $journals */
|
||||
$journals = \App::make('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
|
||||
|
||||
|
||||
/** @var \Importmap $importMap */
|
||||
$importMap = $repository->findImportmap($payload['mapID']);
|
||||
$importMap = $this->_repository->findImportmap($payload['mapID']);
|
||||
$user = $importMap->user;
|
||||
$this->overruleUser($user);
|
||||
|
||||
// find or create the account type for the import account.
|
||||
// find or create the account for the import account.
|
||||
$accountType = $accounts->findAccountType('Import account');
|
||||
$importAccount = $accounts->createOrFind('Import account', $accountType);
|
||||
$accountType = $this->_accounts->findAccountType('Import account');
|
||||
$importAccount = $this->_accounts->createOrFind('Import account', $accountType);
|
||||
|
||||
|
||||
// if amount is more than zero, move from $importAccount
|
||||
$amount = floatval($payload['data']['amount']);
|
||||
|
||||
$accountEntry = $repository->findImportEntry($importMap, 'Account', intval($payload['data']['account_id']));
|
||||
$personalAccount = $accounts->find($accountEntry->new);
|
||||
$accountEntry = $this->_repository->findImportEntry($importMap, 'Account',
|
||||
intval($payload['data']['account_id']));
|
||||
$personalAccount = $this->_accounts->find($accountEntry->new);
|
||||
|
||||
if ($amount < 0) {
|
||||
// if amount is less than zero, move to $importAccount
|
||||
@@ -505,54 +510,49 @@ class Import
|
||||
$date = new Carbon($payload['data']['date']);
|
||||
|
||||
// find a journal?
|
||||
$current = $repository->findImportEntry($importMap, 'Transaction', intval($payload['data']['id']));
|
||||
$current = $this->_repository->findImportEntry($importMap, 'Transaction', intval($payload['data']['id']));
|
||||
|
||||
|
||||
if (is_null($current)) {
|
||||
$journal = $journals->createSimpleJournal($accountFrom, $accountTo,
|
||||
$journal = $this->_journals->createSimpleJournal($accountFrom, $accountTo,
|
||||
$payload['data']['description'], $amount, $date);
|
||||
$repository->store($importMap, 'Transaction', $payload['data']['id'], $journal->id);
|
||||
$this->_repository->store($importMap, 'Transaction', $payload['data']['id'], $journal->id);
|
||||
\Log::debug('Imported transaction "' . $payload['data']['description'] . '" (' . $journal->date->format('Y-m-d') . ').');
|
||||
} else {
|
||||
// do nothing.
|
||||
\Log::debug('ALREADY imported transaction "' . $payload['data']['description'] . '".');
|
||||
}
|
||||
|
||||
$job->delete();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SyncJob $job
|
||||
* @param Job $job
|
||||
* @param array $payload
|
||||
*/
|
||||
public function importTransfer(SyncJob $job, array $payload)
|
||||
public function importTransfer(Job $job, array $payload)
|
||||
{
|
||||
/** @var \Firefly\Storage\Import\ImportRepositoryInterface $repository */
|
||||
$repository = \App::make('Firefly\Storage\Import\ImportRepositoryInterface');
|
||||
|
||||
/** @var \Firefly\Storage\Account\AccountRepositoryInterface $accounts */
|
||||
$accounts = \App::make('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
|
||||
/** @var \Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface $journals */
|
||||
$journals = \App::make('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
|
||||
|
||||
|
||||
/** @var \Importmap $importMap */
|
||||
$importMap = $repository->findImportmap($payload['mapID']);
|
||||
$importMap = $this->_repository->findImportmap($payload['mapID']);
|
||||
$user = $importMap->user;
|
||||
$this->overruleUser($user);
|
||||
|
||||
// from account:
|
||||
$oldFromAccountID = intval($payload['data']['accountfrom_id']);
|
||||
$oldFromAccountEntry = $repository->findImportEntry($importMap, 'Account', $oldFromAccountID);
|
||||
$accountFrom = $accounts->find($oldFromAccountEntry->new);
|
||||
$oldFromAccountEntry = $this->_repository->findImportEntry($importMap, 'Account', $oldFromAccountID);
|
||||
$accountFrom = $this->_accounts->find($oldFromAccountEntry->new);
|
||||
|
||||
// to account:
|
||||
$oldToAccountID = intval($payload['data']['accountto_id']);
|
||||
$oldToAccountEntry = $repository->findImportEntry($importMap, 'Account', $oldToAccountID);
|
||||
$accountTo = $accounts->find($oldToAccountEntry->new);
|
||||
$oldToAccountEntry = $this->_repository->findImportEntry($importMap, 'Account', $oldToAccountID);
|
||||
$accountTo = $this->_accounts->find($oldToAccountEntry->new);
|
||||
if (!is_null($accountFrom) && !is_null($accountTo)) {
|
||||
$amount = floatval($payload['data']['amount']);
|
||||
$date = new Carbon($payload['data']['date']);
|
||||
$journal = $journals->createSimpleJournal($accountFrom, $accountTo, $payload['data']['description'],
|
||||
$journal = $this->_journals->createSimpleJournal($accountFrom, $accountTo, $payload['data']['description'],
|
||||
$amount, $date);
|
||||
\Log::debug('Imported transfer "' . $payload['data']['description'] . '".');
|
||||
$job->delete();
|
||||
@@ -563,10 +563,10 @@ class Import
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SyncJob $job
|
||||
* @param Job $job
|
||||
* @param $payload
|
||||
*/
|
||||
public function start(SyncJob $job, array $payload)
|
||||
public function start(Job $job, array $payload)
|
||||
{
|
||||
\Log::debug('Start with job "start"');
|
||||
$user = \User::find($payload['user']);
|
||||
@@ -591,19 +591,20 @@ class Import
|
||||
$class = ucfirst(\Str::singular($classes_plural));
|
||||
\Log::debug('Create job to import all ' . $classes_plural);
|
||||
foreach ($JSON->$classes_plural as $entry) {
|
||||
//\Log::debug('Create job to import single ' . $class);
|
||||
\Log::debug('Create job to import single ' . $class);
|
||||
$fn = 'import' . $class;
|
||||
$jobFunction = 'Firefly\Queue\Import@' . $fn;
|
||||
\Queue::push($jobFunction, ['data' => $entry, 'class' => $class, 'mapID' => $importMap->id]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// accounts, components, limits, piggybanks, predictables, settings, transactions, transfers
|
||||
// , components, limits, piggybanks, predictables, settings, transactions, transfers
|
||||
// component_predictables, component_transactions, component_transfers
|
||||
|
||||
$count = count($JSON->component_transaction);
|
||||
foreach ($JSON->component_transaction as $index => $entry) {
|
||||
//\Log::debug('Create job to import components_transaction! Yay! (' . $index . '/' . $count . ') ');
|
||||
\Log::debug('Create job to import components_transaction! Yay! (' . $index . '/' . $count . ') ');
|
||||
$fn = 'importComponentTransaction';
|
||||
$jobFunction = 'Firefly\Queue\Import@' . $fn;
|
||||
\Queue::push($jobFunction, ['data' => $entry, 'mapID' => $importMap->id]);
|
||||
@@ -611,12 +612,7 @@ class Import
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
echo 'Done';
|
||||
\Log::debug('Done with job "start"');
|
||||
exit;
|
||||
|
||||
// this is it, close the job:
|
||||
$job->delete();
|
||||
}
|
||||
|
@@ -101,6 +101,12 @@ interface AccountRepositoryInterface
|
||||
*/
|
||||
public function getDefault();
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
* @return mixed
|
||||
*/
|
||||
public function overruleUser(\User $user);
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
*
|
||||
|
@@ -12,11 +12,15 @@ use Carbon\Carbon;
|
||||
*/
|
||||
class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
{
|
||||
|
||||
protected $_user = null;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->_user = \Auth::user();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -24,7 +28,7 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return \Auth::user()->accounts()->count();
|
||||
return $this->_user->accounts()->count();
|
||||
|
||||
}
|
||||
|
||||
@@ -86,8 +90,8 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
$accountIDs = array_unique($accountIDs);
|
||||
if (count($accountIDs) > 0) {
|
||||
// find the "initial balance" type accounts in this list. Should be just 1.
|
||||
$query = \Auth::user()->accounts()->accountTypeIn(['Initial balance account'])
|
||||
->whereIn('accounts.id', $accountIDs);
|
||||
$query = $this->_user->accounts()->accountTypeIn(['Initial balance account'])
|
||||
->whereIn('accounts.id', $accountIDs);
|
||||
if ($query->count() == 1) {
|
||||
$iba = $query->first(['accounts.*']);
|
||||
$iba->delete();
|
||||
@@ -111,7 +115,16 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
*/
|
||||
public function find($accountId)
|
||||
{
|
||||
return \Auth::user()->accounts()->where('id', $accountId)->first();
|
||||
return $this->_user->accounts()->where('id', $accountId)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $type
|
||||
* @return mixed
|
||||
*/
|
||||
public function findAccountType($type)
|
||||
{
|
||||
return \AccountType::where('type', $type)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -124,9 +137,23 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
{
|
||||
$type = is_null($type) ? \AccountType::where('type', 'Default account')->first() : $type;
|
||||
|
||||
return \Auth::user()->accounts()->where('account_type_id', $type->id)
|
||||
->where('name', 'like', '%' . $name . '%')
|
||||
->first();
|
||||
return $this->_user->accounts()->where('account_type_id', $type->id)
|
||||
->where('name', 'like', '%' . $name . '%')
|
||||
->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Used for import
|
||||
*
|
||||
* @param $name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function findByNameAny($name)
|
||||
{
|
||||
return $this->_user->accounts()
|
||||
->where('name', 'like', '%' . $name . '%')
|
||||
->first();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,7 +161,7 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
return \Auth::user()->accounts()->with('accounttype')->orderBy('name', 'ASC')->get();
|
||||
return $this->_user->accounts()->with('accounttype')->orderBy('name', 'ASC')->get();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -142,18 +169,10 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
*/
|
||||
public function getActiveDefault()
|
||||
{
|
||||
return \Auth::user()->accounts()->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||
->where('account_types.type', 'Default account')->where('accounts.active', 1)
|
||||
return $this->_user->accounts()->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||
->where('account_types.type', 'Default account')->where('accounts.active', 1)
|
||||
|
||||
->get(['accounts.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $type
|
||||
* @return mixed
|
||||
*/
|
||||
public function findAccountType($type) {
|
||||
return \AccountType::where('type',$type)->first();
|
||||
->get(['accounts.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -161,12 +180,12 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
*/
|
||||
public function getActiveDefaultAsSelectList()
|
||||
{
|
||||
$list = \Auth::user()->accounts()->leftJoin(
|
||||
'account_types', 'account_types.id', '=', 'accounts.account_type_id'
|
||||
$list = $this->_user->accounts()->leftJoin(
|
||||
'account_types', 'account_types.id', '=', 'accounts.account_type_id'
|
||||
)
|
||||
->where('account_types.type', 'Default account')->where('accounts.active', 1)
|
||||
->where('account_types.type', 'Default account')->where('accounts.active', 1)
|
||||
|
||||
->orderBy('accounts.name', 'ASC')->get(['accounts.*']);
|
||||
->orderBy('accounts.name', 'ASC')->get(['accounts.*']);
|
||||
$return = [];
|
||||
foreach ($list as $entry) {
|
||||
$return[intval($entry->id)] = $entry->name;
|
||||
@@ -180,12 +199,12 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
*/
|
||||
public function getBeneficiaries()
|
||||
{
|
||||
$list = \Auth::user()->accounts()->leftJoin(
|
||||
'account_types', 'account_types.id', '=', 'accounts.account_type_id'
|
||||
$list = $this->_user->accounts()->leftJoin(
|
||||
'account_types', 'account_types.id', '=', 'accounts.account_type_id'
|
||||
)
|
||||
->where('account_types.type', 'Beneficiary account')->where('accounts.active', 1)
|
||||
->where('account_types.type', 'Beneficiary account')->where('accounts.active', 1)
|
||||
|
||||
->orderBy('accounts.name', 'ASC')->get(['accounts.*']);
|
||||
->orderBy('accounts.name', 'ASC')->get(['accounts.*']);
|
||||
|
||||
return $list;
|
||||
}
|
||||
@@ -198,7 +217,7 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
public function getByIds(array $ids)
|
||||
{
|
||||
if (count($ids) > 0) {
|
||||
return \Auth::user()->accounts()->with('accounttype')->whereIn('id', $ids)->orderBy('name', 'ASC')->get();
|
||||
return $this->_user->accounts()->with('accounttype')->whereIn('id', $ids)->orderBy('name', 'ASC')->get();
|
||||
} else {
|
||||
return $this->getActiveDefault();
|
||||
}
|
||||
@@ -210,12 +229,12 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
public function getCashAccount()
|
||||
{
|
||||
$type = \AccountType::where('type', 'Cash account')->first();
|
||||
$cash = \Auth::user()->accounts()->where('account_type_id', $type->id)->first();
|
||||
if(is_null($cash)) {
|
||||
$cash = $this->_user->accounts()->where('account_type_id', $type->id)->first();
|
||||
if (is_null($cash)) {
|
||||
$cash = new \Account;
|
||||
$cash->accountType()->associate($type);
|
||||
$cash->user()->associate(\Auth::user());
|
||||
$cash->name = 'Cash account';
|
||||
$cash->user()->associate($this->_user);
|
||||
$cash->name = 'Cash account';
|
||||
$cash->active = 1;
|
||||
$cash->save();
|
||||
}
|
||||
@@ -229,10 +248,20 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
*/
|
||||
public function getDefault()
|
||||
{
|
||||
return \Auth::user()->accounts()->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||
->where('account_types.type', 'Default account')
|
||||
return $this->_user->accounts()->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||
->where('account_types.type', 'Default account')
|
||||
|
||||
->orderBy('accounts.name', 'ASC')->get(['accounts.*']);
|
||||
->orderBy('accounts.name', 'ASC')->get(['accounts.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function overruleUser(\User $user)
|
||||
{
|
||||
$this->_user = $user;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -262,11 +291,7 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
*/
|
||||
$account = new \Account;
|
||||
$account->accountType()->associate($accountType);
|
||||
if (\Auth::check()) {
|
||||
$account->user()->associate(\Auth::user());
|
||||
} else {
|
||||
$account->user_id = $data['user_id'];
|
||||
}
|
||||
$account->user()->associate($this->_user);
|
||||
|
||||
$account->name = $data['name'];
|
||||
$account->active
|
||||
@@ -328,20 +353,6 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
return $account;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used for import
|
||||
*
|
||||
* @param $name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function findByNameAny($name)
|
||||
{
|
||||
return \Auth::user()->accounts()
|
||||
->where('name', 'like', '%' . $name . '%')
|
||||
->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Account $account
|
||||
* @param int $amount
|
||||
@@ -358,7 +369,7 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
// create new account:
|
||||
$initial = new \Account;
|
||||
$initial->accountType()->associate($initialBalanceAT);
|
||||
$initial->user()->associate(\Auth::user());
|
||||
$initial->user()->associate($this->_user);
|
||||
$initial->name = $account->name . ' initial balance';
|
||||
$initial->active = 0;
|
||||
if ($initial->validate()) {
|
||||
|
@@ -30,6 +30,12 @@ interface BudgetRepositoryInterface
|
||||
*/
|
||||
public function findByName($budgetName);
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
* @return mixed
|
||||
*/
|
||||
public function overruleUser(\User $user);
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
|
@@ -11,6 +11,15 @@ use Carbon\Carbon;
|
||||
*/
|
||||
class EloquentBudgetRepository implements BudgetRepositoryInterface
|
||||
{
|
||||
protected $_user = null;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->_user = \Auth::user();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Budget $budget
|
||||
@@ -32,13 +41,13 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
|
||||
public function find($budgetId)
|
||||
{
|
||||
|
||||
return \Auth::user()->budgets()->find($budgetId);
|
||||
return $this->_user->budgets()->find($budgetId);
|
||||
}
|
||||
|
||||
public function findByName($budgetName)
|
||||
{
|
||||
|
||||
return \Auth::user()->budgets()->whereName($budgetName)->first();
|
||||
return $this->_user->budgets()->whereName($budgetName)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,12 +55,12 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
$set = \Auth::user()->budgets()->with(
|
||||
['limits' => function ($q) {
|
||||
$q->orderBy('limits.startdate', 'DESC');
|
||||
}, 'limits.limitrepetitions' => function ($q) {
|
||||
$q->orderBy('limit_repetitions.startdate', 'ASC');
|
||||
}]
|
||||
$set = $this->_user->budgets()->with(
|
||||
['limits' => function ($q) {
|
||||
$q->orderBy('limits.startdate', 'DESC');
|
||||
}, 'limits.limitrepetitions' => function ($q) {
|
||||
$q->orderBy('limit_repetitions.startdate', 'ASC');
|
||||
}]
|
||||
)->orderBy('name', 'ASC')->get();
|
||||
foreach ($set as $budget) {
|
||||
foreach ($budget->limits as $limit) {
|
||||
@@ -69,8 +78,8 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
|
||||
*/
|
||||
public function getAsSelectList()
|
||||
{
|
||||
$list = \Auth::user()->budgets()->with(
|
||||
['limits', 'limits.limitrepetitions']
|
||||
$list = $this->_user->budgets()->with(
|
||||
['limits', 'limits.limitrepetitions']
|
||||
)->orderBy('name', 'ASC')->get();
|
||||
$return = [];
|
||||
foreach ($list as $entry) {
|
||||
@@ -88,9 +97,9 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
|
||||
*/
|
||||
public function store($data)
|
||||
{
|
||||
$budget = new \Budget;
|
||||
$budget = new \Budget;
|
||||
$budget->name = $data['name'];
|
||||
$budget->user()->associate(\Auth::user());
|
||||
$budget->user()->associate($this->_user);
|
||||
$budget->save();
|
||||
|
||||
// if limit, create limit (repetition itself will be picked up elsewhere).
|
||||
@@ -121,9 +130,9 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
|
||||
$startDate->startOfYear();
|
||||
break;
|
||||
}
|
||||
$limit->startdate = $startDate;
|
||||
$limit->amount = $data['amount'];
|
||||
$limit->repeats = isset($data['repeats']) ? $data['repeats'] : 0;
|
||||
$limit->startdate = $startDate;
|
||||
$limit->amount = $data['amount'];
|
||||
$limit->repeats = isset($data['repeats']) ? $data['repeats'] : 0;
|
||||
$limit->repeat_freq = $data['repeat_freq'];
|
||||
if ($limit->validate()) {
|
||||
$limit->save();
|
||||
@@ -154,4 +163,14 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
|
||||
return $budget;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function overruleUser(\User $user)
|
||||
{
|
||||
$this->_user = $user;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@@ -29,6 +29,12 @@ interface CategoryRepositoryInterface
|
||||
*/
|
||||
public function createOrFind($name);
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
* @return mixed
|
||||
*/
|
||||
public function overruleUser(\User $user);
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
|
@@ -9,6 +9,16 @@ namespace Firefly\Storage\Category;
|
||||
*/
|
||||
class EloquentCategoryRepository implements CategoryRepositoryInterface
|
||||
{
|
||||
protected $_user = null;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->_user = \Auth::user();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
@@ -48,7 +58,7 @@ class EloquentCategoryRepository implements CategoryRepositoryInterface
|
||||
*/
|
||||
public function find($categoryId)
|
||||
{
|
||||
return \Auth::user()->categories()->find($categoryId);
|
||||
return $this->_user->categories()->find($categoryId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,7 +72,7 @@ class EloquentCategoryRepository implements CategoryRepositoryInterface
|
||||
return null;
|
||||
}
|
||||
|
||||
return \Auth::user()->categories()->where('name', 'LIKE', '%' . $name . '%')->first();
|
||||
return $this->_user->categories()->where('name', 'LIKE', '%' . $name . '%')->first();
|
||||
|
||||
}
|
||||
|
||||
@@ -71,7 +81,7 @@ class EloquentCategoryRepository implements CategoryRepositoryInterface
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
return \Auth::user()->categories()->orderBy('name', 'ASC')->get();
|
||||
return $this->_user->categories()->orderBy('name', 'ASC')->get();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,10 +91,10 @@ class EloquentCategoryRepository implements CategoryRepositoryInterface
|
||||
*/
|
||||
public function store($data)
|
||||
{
|
||||
$category = new \Category;
|
||||
$category = new \Category;
|
||||
$category->name = $data['name'];
|
||||
|
||||
$category->user()->associate(\Auth::user());
|
||||
$category->user()->associate($this->_user);
|
||||
$category->save();
|
||||
|
||||
return $category;
|
||||
@@ -106,4 +116,14 @@ class EloquentCategoryRepository implements CategoryRepositoryInterface
|
||||
|
||||
return $category;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function overruleUser(\User $user)
|
||||
{
|
||||
$this->_user = $user;
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -28,4 +28,10 @@ interface ComponentRepositoryInterface
|
||||
*/
|
||||
public function store($data);
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
* @return mixed
|
||||
*/
|
||||
public function overruleUser(\User $user);
|
||||
|
||||
}
|
@@ -14,12 +14,14 @@ use Illuminate\Database\QueryException;
|
||||
class EloquentComponentRepository implements ComponentRepositoryInterface
|
||||
{
|
||||
public $validator;
|
||||
protected $_user = null;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->_user = \Auth::user();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -27,7 +29,7 @@ class EloquentComponentRepository implements ComponentRepositoryInterface
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return \Auth::user()->components()->count();
|
||||
return $this->_user->components()->count();
|
||||
|
||||
}
|
||||
|
||||
@@ -40,6 +42,16 @@ class EloquentComponentRepository implements ComponentRepositoryInterface
|
||||
throw new FireflyException('No implementation.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function overruleUser(\User $user)
|
||||
{
|
||||
$this->_user = $user;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
*
|
||||
@@ -62,7 +74,7 @@ class EloquentComponentRepository implements ComponentRepositoryInterface
|
||||
|
||||
}
|
||||
$component->name = $data['name'];
|
||||
$component->user()->associate(\Auth::user());
|
||||
$component->user()->associate($this->_user);
|
||||
try {
|
||||
$component->save();
|
||||
} catch (QueryException $e) {
|
||||
|
@@ -5,6 +5,15 @@ namespace Firefly\Storage\Import;
|
||||
|
||||
class EloquentImportRepository implements ImportRepositoryInterface
|
||||
{
|
||||
protected $_user = null;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->_user = \Auth::user();
|
||||
}
|
||||
|
||||
public function findImportComponentMap(\Importmap $map, $oldComponentId)
|
||||
{
|
||||
@@ -26,6 +35,16 @@ class EloquentImportRepository implements ImportRepositoryInterface
|
||||
return \Importmap::find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function overruleUser(\User $user)
|
||||
{
|
||||
$this->_user = $user;
|
||||
return true;
|
||||
}
|
||||
|
||||
public function store(\Importmap $map, $class, $oldID, $newID)
|
||||
{
|
||||
$entry = new \Importentry;
|
||||
|
@@ -24,4 +24,10 @@ interface ImportRepositoryInterface
|
||||
public function findImportEntry(\Importmap $map, $class, $oldID);
|
||||
|
||||
public function findImportComponentMap(\Importmap $map, $oldComponentId);
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
* @return mixed
|
||||
*/
|
||||
public function overruleUser(\User $user);
|
||||
}
|
@@ -12,9 +12,14 @@ use Carbon\Carbon;
|
||||
*/
|
||||
class EloquentLimitRepository implements LimitRepositoryInterface
|
||||
{
|
||||
protected $_user = null;
|
||||
|
||||
public function findByBudgetAndDate(\Budget $budget, Carbon $date) {
|
||||
return \Limit::whereComponentId($budget->id)->where('startdate',$date->format('Y-m-d'))->first();
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->_user = \Auth::user();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -29,24 +34,6 @@ class EloquentLimitRepository implements LimitRepositoryInterface
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Limit $limit
|
||||
* @param $data
|
||||
*
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function update(\Limit $limit, $data)
|
||||
{
|
||||
$limit->startdate = new Carbon($data['startdate']);
|
||||
$limit->repeat_freq = $data['period'];
|
||||
$limit->repeats = isset($data['repeats']) && $data['repeats'] == '1' ? 1 : 0;
|
||||
$limit->amount = floatval($data['amount']);
|
||||
|
||||
$limit->save();
|
||||
|
||||
return $limit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $limitId
|
||||
*
|
||||
@@ -55,15 +42,20 @@ class EloquentLimitRepository implements LimitRepositoryInterface
|
||||
public function find($limitId)
|
||||
{
|
||||
return \Limit::with('limitrepetitions')->where('limits.id', $limitId)->leftJoin(
|
||||
'components', 'components.id', '=', 'limits.component_id'
|
||||
'components', 'components.id', '=', 'limits.component_id'
|
||||
)
|
||||
->where('components.user_id', \Auth::user()->id)->first(['limits.*']);
|
||||
->where('components.user_id', $this->_user->id)->first(['limits.*']);
|
||||
}
|
||||
|
||||
public function findByBudgetAndDate(\Budget $budget, Carbon $date)
|
||||
{
|
||||
return \Limit::whereComponentId($budget->id)->where('startdate', $date->format('Y-m-d'))->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Budget $budget
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
@@ -75,6 +67,16 @@ class EloquentLimitRepository implements LimitRepositoryInterface
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function overruleUser(\User $user)
|
||||
{
|
||||
$this->_user = $user;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
*
|
||||
@@ -119,9 +121,9 @@ class EloquentLimitRepository implements LimitRepositoryInterface
|
||||
// find existing:
|
||||
$count = \Limit::
|
||||
leftJoin('components', 'components.id', '=', 'limits.component_id')->where(
|
||||
'components.user_id', \Auth::user()->id
|
||||
'components.user_id', $this->_user->id
|
||||
)->where('startdate', $date->format('Y-m-d'))->where('component_id', $data['budget_id'])->where(
|
||||
'repeat_freq', $data['period']
|
||||
'repeat_freq', $data['period']
|
||||
)->count();
|
||||
if ($count > 0) {
|
||||
\Session::flash('error', 'There already is an entry for these parameters.');
|
||||
@@ -131,9 +133,9 @@ class EloquentLimitRepository implements LimitRepositoryInterface
|
||||
// create new limit:
|
||||
$limit = new \Limit;
|
||||
$limit->budget()->associate($budget);
|
||||
$limit->startdate = $date;
|
||||
$limit->amount = floatval($data['amount']);
|
||||
$limit->repeats = isset($data['repeats']) ? intval($data['repeats']) : 0;
|
||||
$limit->startdate = $date;
|
||||
$limit->amount = floatval($data['amount']);
|
||||
$limit->repeats = isset($data['repeats']) ? intval($data['repeats']) : 0;
|
||||
$limit->repeat_freq = $data['period'];
|
||||
if (!$limit->save()) {
|
||||
\Session::flash('error', 'Could not save: ' . $limit->errors()->first());
|
||||
@@ -142,4 +144,22 @@ class EloquentLimitRepository implements LimitRepositoryInterface
|
||||
return $limit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Limit $limit
|
||||
* @param $data
|
||||
*
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function update(\Limit $limit, $data)
|
||||
{
|
||||
$limit->startdate = new Carbon($data['startdate']);
|
||||
$limit->repeat_freq = $data['period'];
|
||||
$limit->repeats = isset($data['repeats']) && $data['repeats'] == '1' ? 1 : 0;
|
||||
$limit->amount = floatval($data['amount']);
|
||||
|
||||
$limit->save();
|
||||
|
||||
return $limit;
|
||||
}
|
||||
|
||||
}
|
@@ -56,4 +56,10 @@ interface LimitRepositoryInterface
|
||||
* @return mixed
|
||||
*/
|
||||
public function update(\Limit $limit, $data);
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
* @return mixed
|
||||
*/
|
||||
public function overruleUser(\User $user);
|
||||
}
|
@@ -14,6 +14,15 @@ use Firefly\Exception\FireflyException;
|
||||
class EloquentPiggybankRepository implements PiggybankRepositoryInterface
|
||||
{
|
||||
|
||||
protected $_user = null;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->_user = \Auth::user();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
@@ -21,14 +30,14 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface
|
||||
public function count()
|
||||
{
|
||||
return \Piggybank::leftJoin('accounts', 'accounts.id', '=', 'piggybanks.account_id')->where(
|
||||
'accounts.user_id', \Auth::user()->id
|
||||
'accounts.user_id', $this->_user->id
|
||||
)->count();
|
||||
}
|
||||
|
||||
public function countNonrepeating()
|
||||
{
|
||||
return \Piggybank::leftJoin('accounts', 'accounts.id', '=', 'piggybanks.account_id')->where(
|
||||
'accounts.user_id', \Auth::user()->id
|
||||
'accounts.user_id', $this->_user->id
|
||||
)->where('repeats', 0)->count();
|
||||
|
||||
}
|
||||
@@ -36,7 +45,7 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface
|
||||
public function countRepeating()
|
||||
{
|
||||
return \Piggybank::leftJoin('accounts', 'accounts.id', '=', 'piggybanks.account_id')->where(
|
||||
'accounts.user_id', \Auth::user()->id
|
||||
'accounts.user_id', $this->_user->id
|
||||
)->where('repeats', 1)->count();
|
||||
}
|
||||
|
||||
@@ -60,14 +69,14 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface
|
||||
public function find($piggyBankId)
|
||||
{
|
||||
return \Piggybank::leftJoin('accounts', 'accounts.id', '=', 'piggybanks.account_id')->where(
|
||||
'accounts.user_id', \Auth::user()->id
|
||||
'accounts.user_id', $this->_user->id
|
||||
)->where('piggybanks.id', $piggyBankId)->first(['piggybanks.*']);
|
||||
}
|
||||
|
||||
public function findByName($piggyBankName)
|
||||
{
|
||||
return \Piggybank::leftJoin('accounts', 'accounts.id', '=', 'piggybanks.account_id')->where(
|
||||
'accounts.user_id', \Auth::user()->id
|
||||
'accounts.user_id', $this->_user->id
|
||||
)->where('piggybanks.name', $piggyBankName)->first(['piggybanks.*']);
|
||||
}
|
||||
|
||||
@@ -76,7 +85,7 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
$piggies = \Auth::user()->piggybanks()->with(['account', 'piggybankrepetitions'])->get();
|
||||
$piggies = $this->_user->piggybanks()->with(['account', 'piggybankrepetitions'])->get();
|
||||
|
||||
foreach ($piggies as $pig) {
|
||||
$pig->leftInAccount = $this->leftOnAccount($pig->account);
|
||||
@@ -102,7 +111,6 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param \Piggybank $piggyBank
|
||||
* @param $amount
|
||||
@@ -122,6 +130,16 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function overruleUser(\User $user)
|
||||
{
|
||||
$this->_user = $user;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
*
|
||||
@@ -141,6 +159,7 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface
|
||||
|
||||
/** @var \Firefly\Storage\Account\AccountRepositoryInterface $accounts */
|
||||
$accounts = \App::make('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
$accounts->overruleUser($this->_user);
|
||||
$account = isset($data['account_id']) ? $accounts->find($data['account_id']) : null;
|
||||
|
||||
|
||||
@@ -221,6 +240,7 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface
|
||||
{
|
||||
/** @var \Firefly\Storage\Account\AccountRepositoryInterface $accounts */
|
||||
$accounts = \App::make('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
$accounts->overruleUser($this->_user);
|
||||
$account = isset($data['account_id']) ? $accounts->find($data['account_id']) : null;
|
||||
|
||||
if (!is_null($account)) {
|
||||
|
@@ -39,7 +39,9 @@ interface PiggybankRepositoryInterface
|
||||
* @return mixed
|
||||
*/
|
||||
public function find($piggyBankId);
|
||||
|
||||
public function findByName($piggyBankName);
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
@@ -77,5 +79,11 @@ interface PiggybankRepositoryInterface
|
||||
*/
|
||||
public function update(\Piggybank $piggy, $data);
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
* @return mixed
|
||||
*/
|
||||
public function overruleUser(\User $user);
|
||||
|
||||
|
||||
}
|
@@ -12,6 +12,27 @@ use Carbon\Carbon;
|
||||
*/
|
||||
class EloquentRecurringTransactionRepository implements RecurringTransactionRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function overruleUser(\User $user)
|
||||
{
|
||||
$this->_user = $user;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected $_user = null;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->_user = \Auth::user();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \RecurringTransaction $recurringTransaction
|
||||
*
|
||||
@@ -26,7 +47,7 @@ class EloquentRecurringTransactionRepository implements RecurringTransactionRepo
|
||||
|
||||
public function findByName($name)
|
||||
{
|
||||
return \Auth::user()->recurringtransactions()->where('name', 'LIKE', '%' . $name . '%')->first();
|
||||
return $this->_user->recurringtransactions()->where('name', 'LIKE', '%' . $name . '%')->first();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -34,7 +55,7 @@ class EloquentRecurringTransactionRepository implements RecurringTransactionRepo
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
return \Auth::user()->recurringtransactions()->get();
|
||||
return $this->_user->recurringtransactions()->get();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -45,7 +66,7 @@ class EloquentRecurringTransactionRepository implements RecurringTransactionRepo
|
||||
public function store($data)
|
||||
{
|
||||
$recurringTransaction = new \RecurringTransaction;
|
||||
$recurringTransaction->user()->associate(\Auth::user());
|
||||
$recurringTransaction->user()->associate($this->_user);
|
||||
$recurringTransaction->name = $data['name'];
|
||||
$recurringTransaction->match = join(' ', explode(',', $data['match']));
|
||||
$recurringTransaction->amount_max = floatval($data['amount_max']);
|
||||
|
@@ -44,5 +44,11 @@ interface RecurringTransactionRepositoryInterface
|
||||
*/
|
||||
public function update(\RecurringTransaction $recurringTransaction, $data);
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
* @return mixed
|
||||
*/
|
||||
public function overruleUser(\User $user);
|
||||
|
||||
|
||||
}
|
@@ -12,6 +12,26 @@ use Carbon\Carbon;
|
||||
*/
|
||||
class EloquentReminderRepository implements ReminderRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @param \User $user
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function overruleUser(\User $user)
|
||||
{
|
||||
$this->_user = $user;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected $_user = null;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->_user = \Auth::user();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Reminder $reminder
|
||||
*
|
||||
@@ -42,7 +62,7 @@ class EloquentReminderRepository implements ReminderRepositoryInterface
|
||||
{
|
||||
$today = new Carbon;
|
||||
|
||||
return \Auth::user()->reminders()->validOn($today)->get();
|
||||
return $this->_user->reminders()->validOn($today)->get();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -52,8 +72,8 @@ class EloquentReminderRepository implements ReminderRepositoryInterface
|
||||
{
|
||||
$today = new Carbon;
|
||||
|
||||
return \Auth::user()->reminders()->with('recurringtransaction')->validOn($today)->where(
|
||||
'class', 'RecurringTransactionReminder'
|
||||
return $this->_user->reminders()->with('recurringtransaction')->validOn($today)->where(
|
||||
'class', 'RecurringTransactionReminder'
|
||||
)->get();
|
||||
|
||||
}
|
||||
|
@@ -39,4 +39,10 @@ interface ReminderRepositoryInterface
|
||||
|
||||
public function getCurrentRecurringReminders();
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
* @return mixed
|
||||
*/
|
||||
public function overruleUser(\User $user);
|
||||
|
||||
}
|
@@ -9,5 +9,24 @@ namespace Firefly\Storage\Transaction;
|
||||
*/
|
||||
class EloquentTransactionRepository implements TransactionRepositoryInterface
|
||||
{
|
||||
protected $_user = null;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->_user = \Auth::user();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function overruleUser(\User $user)
|
||||
{
|
||||
$this->_user = $user;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@@ -9,6 +9,11 @@ namespace Firefly\Storage\Transaction;
|
||||
*/
|
||||
interface TransactionRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @param \User $user
|
||||
* @return mixed
|
||||
*/
|
||||
public function overruleUser(\User $user);
|
||||
|
||||
|
||||
}
|
@@ -14,6 +14,16 @@ use Firefly\Exception\FireflyException;
|
||||
class EloquentTransactionJournalRepository implements TransactionJournalRepositoryInterface
|
||||
{
|
||||
|
||||
protected $_user = null;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->_user = \Auth::user();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* We're building this thinking the money goes from A to B.
|
||||
@@ -34,8 +44,8 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
* A gains 200 (200). * -1
|
||||
* B loses 200 (-200). * 1
|
||||
*
|
||||
* @param \Account $from
|
||||
* @param \Account $toAccount
|
||||
* @param \Account $from
|
||||
* @param \Account $toAccount
|
||||
* @param $description
|
||||
* @param $amount
|
||||
* @param \Carbon\Carbon $date
|
||||
@@ -48,7 +58,7 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
$journal = new \TransactionJournal;
|
||||
|
||||
$amountFrom = $amount * -1;
|
||||
$amountTo = $amount;
|
||||
$amountTo = $amount;
|
||||
|
||||
if (round(floatval($amount), 2) == 0.00) {
|
||||
$journal->errors()->add('amount', 'Amount must not be zero.');
|
||||
@@ -64,7 +74,7 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
}
|
||||
|
||||
// account types for both:
|
||||
$toAT = $toAccount->accountType->type;
|
||||
$toAT = $toAccount->accountType->type;
|
||||
$fromAT = $from->accountType->type;
|
||||
|
||||
$journalType = null;
|
||||
@@ -105,10 +115,10 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
|
||||
$journal->transactionType()->associate($journalType);
|
||||
$journal->transactionCurrency()->associate($currency);
|
||||
$journal->user()->associate(\Auth::user());
|
||||
$journal->completed = false;
|
||||
$journal->user()->associate($this->_user);
|
||||
$journal->completed = false;
|
||||
$journal->description = $description;
|
||||
$journal->date = $date;
|
||||
$journal->date = $date;
|
||||
if (!$journal->validate()) {
|
||||
return $journal;
|
||||
}
|
||||
@@ -119,10 +129,10 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
$fromTransaction->account()->associate($from);
|
||||
$fromTransaction->transactionJournal()->associate($journal);
|
||||
$fromTransaction->description = null;
|
||||
$fromTransaction->amount = $amountFrom;
|
||||
$fromTransaction->amount = $amountFrom;
|
||||
if (!$fromTransaction->validate()) {
|
||||
throw new FireflyException('Cannot create valid transaction (from): ' . $fromTransaction->errors()->first(
|
||||
));
|
||||
throw new FireflyException('Cannot create valid transaction (from): ' . $fromTransaction->errors()
|
||||
->first());
|
||||
}
|
||||
$fromTransaction->save();
|
||||
|
||||
@@ -130,7 +140,7 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
$toTransaction->account()->associate($toAccount);
|
||||
$toTransaction->transactionJournal()->associate($journal);
|
||||
$toTransaction->description = null;
|
||||
$toTransaction->amount = $amountTo;
|
||||
$toTransaction->amount = $amountTo;
|
||||
if (!$toTransaction->validate()) {
|
||||
throw new FireflyException('Cannot create valid transaction (to): ' . $toTransaction->errors()->first());
|
||||
}
|
||||
@@ -149,13 +159,13 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
*/
|
||||
public function find($journalId)
|
||||
{
|
||||
return \Auth::user()->transactionjournals()->with(
|
||||
['transactions' => function ($q) {
|
||||
return $q->orderBy('amount', 'ASC');
|
||||
}, 'transactioncurrency', 'transactiontype', 'components', 'transactions.account',
|
||||
'transactions.account.accounttype']
|
||||
return $this->_user->transactionjournals()->with(
|
||||
['transactions' => function ($q) {
|
||||
return $q->orderBy('amount', 'ASC');
|
||||
}, 'transactioncurrency', 'transactiontype', 'components', 'transactions.account',
|
||||
'transactions.account.accounttype']
|
||||
)
|
||||
->where('id', $journalId)->first();
|
||||
->where('id', $journalId)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -168,64 +178,76 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
|
||||
/**
|
||||
* @param \Account $account
|
||||
* @param Carbon $date
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getByAccountAndDate(\Account $account, Carbon $date)
|
||||
{
|
||||
$accountID = $account->id;
|
||||
$query = \Auth::user()->transactionjournals()->with(
|
||||
[
|
||||
'transactions',
|
||||
'transactions.account',
|
||||
'transactioncurrency',
|
||||
'transactiontype'
|
||||
]
|
||||
$query = $this->_user->transactionjournals()->with(
|
||||
[
|
||||
'transactions',
|
||||
'transactions.account',
|
||||
'transactioncurrency',
|
||||
'transactiontype'
|
||||
]
|
||||
)
|
||||
->distinct()
|
||||
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
|
||||
->where('transactions.account_id', $accountID)
|
||||
->where('transaction_journals.date', $date->format('Y-m-d'))
|
||||
->orderBy('transaction_journals.date', 'DESC')
|
||||
->orderBy('transaction_journals.id', 'DESC')
|
||||
->get(['transaction_journals.*']);
|
||||
->distinct()
|
||||
->leftJoin('transactions', 'transactions.transaction_journal_id', '=',
|
||||
'transaction_journals.id')
|
||||
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
|
||||
->where('transactions.account_id', $accountID)
|
||||
->where('transaction_journals.date', $date->format('Y-m-d'))
|
||||
->orderBy('transaction_journals.date', 'DESC')
|
||||
->orderBy('transaction_journals.id', 'DESC')
|
||||
->get(['transaction_journals.*']);
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Account $account
|
||||
* @param int $count
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @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(
|
||||
[
|
||||
'transactions',
|
||||
'transactioncurrency',
|
||||
'transactiontype'
|
||||
]
|
||||
$query = $this->_user->transactionjournals()->with(
|
||||
[
|
||||
'transactions',
|
||||
'transactioncurrency',
|
||||
'transactiontype'
|
||||
]
|
||||
)
|
||||
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
|
||||
->where('accounts.id', $accountID)
|
||||
->where('date', '>=', $start->format('Y-m-d'))
|
||||
->where('date', '<=', $end->format('Y-m-d'))
|
||||
->orderBy('transaction_journals.date', 'DESC')
|
||||
->orderBy('transaction_journals.id', 'DESC')
|
||||
->take($count)
|
||||
->get(['transaction_journals.*']);
|
||||
->leftJoin('transactions', 'transactions.transaction_journal_id', '=',
|
||||
'transaction_journals.id')
|
||||
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
|
||||
->where('accounts.id', $accountID)
|
||||
->where('date', '>=', $start->format('Y-m-d'))
|
||||
->where('date', '<=', $end->format('Y-m-d'))
|
||||
->orderBy('transaction_journals.date', 'DESC')
|
||||
->orderBy('transaction_journals.id', 'DESC')
|
||||
->take($count)
|
||||
->get(['transaction_journals.*']);
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function overruleUser(\User $user)
|
||||
{
|
||||
$this->_user = $user;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $count
|
||||
*
|
||||
@@ -233,19 +255,19 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
*/
|
||||
public function paginate($count = 25, Carbon $start = null, Carbon $end = null)
|
||||
{
|
||||
$query = \Auth::user()->transactionjournals()->with(
|
||||
[
|
||||
'transactions' => function ($q) {
|
||||
return $q->orderBy('amount', 'ASC');
|
||||
},
|
||||
'transactions.account',
|
||||
'transactions.account.accounttype',
|
||||
'transactioncurrency',
|
||||
'transactiontype'
|
||||
]
|
||||
$query = $this->_user->transactionjournals()->with(
|
||||
[
|
||||
'transactions' => function ($q) {
|
||||
return $q->orderBy('amount', 'ASC');
|
||||
},
|
||||
'transactions.account',
|
||||
'transactions.account.accounttype',
|
||||
'transactioncurrency',
|
||||
'transactiontype'
|
||||
]
|
||||
)
|
||||
->orderBy('transaction_journals.date', 'DESC')
|
||||
->orderBy('transaction_journals.id', 'DESC');
|
||||
->orderBy('transaction_journals.date', 'DESC')
|
||||
->orderBy('transaction_journals.id', 'DESC');
|
||||
if (!is_null($start)) {
|
||||
$query->where('transaction_journals.date', '>=', $start->format('Y-m-d'));
|
||||
}
|
||||
@@ -270,37 +292,40 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
// depending on the $what
|
||||
|
||||
$fromAccount = null;
|
||||
$toAccount = null;
|
||||
$toAccount = null;
|
||||
|
||||
/** @var \Firefly\Storage\Account\AccountRepositoryInterface $accountRepository */
|
||||
$accountRepository = \App::make('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
$accountRepository->overruleUser($this->_user);
|
||||
|
||||
/** @var \Firefly\Storage\Category\CategoryRepositoryInterface $catRepository */
|
||||
$catRepository = \App::make('Firefly\Storage\Category\CategoryRepositoryInterface');
|
||||
$catRepository->overruleUser($this->_user);
|
||||
|
||||
/** @var \Firefly\Storage\Budget\BudgetRepositoryInterface $budRepository */
|
||||
$budRepository = \App::make('Firefly\Storage\Budget\BudgetRepositoryInterface');
|
||||
$budRepository->overruleUser($this->_user);
|
||||
|
||||
|
||||
switch ($what) {
|
||||
case 'withdrawal':
|
||||
$fromAccount = $accountRepository->find(intval($data['account_id']));
|
||||
$toAccount = $accountRepository->createOrFindBeneficiary($data['beneficiary']);
|
||||
$toAccount = $accountRepository->createOrFindBeneficiary($data['beneficiary']);
|
||||
break;
|
||||
|
||||
case 'deposit':
|
||||
$fromAccount = $accountRepository->createOrFindBeneficiary($data['beneficiary']);
|
||||
$toAccount = $accountRepository->find(intval($data['account_id']));
|
||||
$toAccount = $accountRepository->find(intval($data['account_id']));
|
||||
break;
|
||||
case 'transfer':
|
||||
$fromAccount = $accountRepository->find(intval($data['account_from_id']));
|
||||
$toAccount = $accountRepository->find(intval($data['account_to_id']));
|
||||
$toAccount = $accountRepository->find(intval($data['account_to_id']));
|
||||
|
||||
break;
|
||||
}
|
||||
// fall back to cash if necessary:
|
||||
$fromAccount = is_null($fromAccount) ? $fromAccount = $accountRepository->getCashAccount() : $fromAccount;
|
||||
$toAccount = is_null($toAccount) ? $toAccount = $accountRepository->getCashAccount() : $toAccount;
|
||||
$toAccount = is_null($toAccount) ? $toAccount = $accountRepository->getCashAccount() : $toAccount;
|
||||
|
||||
// create or find category:
|
||||
$category = isset($data['category']) ? $catRepository->createOrFind($data['category']) : null;
|
||||
@@ -309,8 +334,8 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
$budget = isset($data['budget_id']) ? $budRepository->find(intval($data['budget_id'])) : null;
|
||||
// find amount & description:
|
||||
$description = trim($data['description']);
|
||||
$amount = floatval($data['amount']);
|
||||
$date = new Carbon($data['date']);
|
||||
$amount = floatval($data['amount']);
|
||||
$date = new Carbon($data['date']);
|
||||
|
||||
// try to create a journal:
|
||||
$transactionJournal = $this->createSimpleJournal($fromAccount, $toAccount, $description, $amount, $date);
|
||||
@@ -323,6 +348,7 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
if ($what == 'transfer') {
|
||||
/** @var \Firefly\Storage\Piggybank\PiggybankRepositoryInterface $piggyRepository */
|
||||
$piggyRepository = \App::make('Firefly\Storage\Piggybank\PiggybankRepositoryInterface');
|
||||
$piggyRepository->overruleUser($this->_user);
|
||||
|
||||
if (isset($data['piggybank_id'])) {
|
||||
/** @var \Piggybank $piggyBank */
|
||||
@@ -337,15 +363,15 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
$transaction->piggybank()->associate($piggyBank);
|
||||
$transaction->save();
|
||||
\Event::fire(
|
||||
'piggybanks.createRelatedTransfer', [$piggyBank, $transactionJournal, $transaction]
|
||||
'piggybanks.createRelatedTransfer', [$piggyBank, $transactionJournal, $transaction]
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($connected === false) {
|
||||
\Session::flash(
|
||||
'warning', 'Piggy bank "' . e($piggyBank->name)
|
||||
. '" is not set to draw money from any of the accounts in this transfer'
|
||||
'warning', 'Piggy bank "' . e($piggyBank->name)
|
||||
. '" is not set to draw money from any of the accounts in this transfer'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -375,18 +401,21 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
{
|
||||
/** @var \Firefly\Storage\Category\CategoryRepositoryInterface $catRepository */
|
||||
$catRepository = \App::make('Firefly\Storage\Category\CategoryRepositoryInterface');
|
||||
$catRepository->overruleUser($this->_user);
|
||||
|
||||
/** @var \Firefly\Storage\Budget\BudgetRepositoryInterface $budgetRepository */
|
||||
$budRepository = \App::make('Firefly\Storage\Budget\BudgetRepositoryInterface');
|
||||
$budRepository->overruleUser($this->_user);
|
||||
|
||||
/** @var \Firefly\Storage\Account\AccountRepositoryInterface $accountRepository */
|
||||
$accountRepository = \App::make('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
$accountRepository->overruleUser($this->_user);
|
||||
|
||||
|
||||
// update basics first:
|
||||
$journal->description = $data['description'];
|
||||
$journal->date = $data['date'];
|
||||
$amount = floatval($data['amount']);
|
||||
$journal->date = $data['date'];
|
||||
$amount = floatval($data['amount']);
|
||||
|
||||
// remove previous category, if any:
|
||||
if (!is_null($journal->categories()->first())) {
|
||||
@@ -424,7 +453,7 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
switch ($journal->transactiontype->type) {
|
||||
case 'Withdrawal':
|
||||
// means transaction[0] is the users account.
|
||||
$account = $accountRepository->find($data['account_id']);
|
||||
$account = $accountRepository->find($data['account_id']);
|
||||
$beneficiary = $accountRepository->createOrFindBeneficiary($data['beneficiary']);
|
||||
$transactions[0]->account()->associate($account);
|
||||
$transactions[1]->account()->associate($beneficiary);
|
||||
@@ -438,7 +467,7 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
break;
|
||||
case 'Deposit':
|
||||
// means transaction[0] is the beneficiary.
|
||||
$account = $accountRepository->find($data['account_id']);
|
||||
$account = $accountRepository->find($data['account_id']);
|
||||
$beneficiary = $accountRepository->createOrFindBeneficiary($data['beneficiary']);
|
||||
$journal->transactions[0]->account()->associate($beneficiary);
|
||||
$journal->transactions[1]->account()->associate($account);
|
||||
@@ -455,6 +484,7 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
// attach the new piggy bank, if valid:
|
||||
/** @var \Firefly\Storage\Piggybank\PiggybankRepositoryInterface $piggyRepository */
|
||||
$piggyRepository = \App::make('Firefly\Storage\Piggybank\PiggybankRepositoryInterface');
|
||||
$piggyRepository->overruleUser($this->_user);
|
||||
|
||||
if (isset($data['piggybank_id'])) {
|
||||
/** @var \Piggybank $piggyBank */
|
||||
@@ -476,8 +506,8 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
}
|
||||
if ($connected === false) {
|
||||
\Session::flash(
|
||||
'warning', 'Piggy bank "' . e($piggyBank->name)
|
||||
. '" is not set to draw money from any of the accounts in this transfer'
|
||||
'warning', 'Piggy bank "' . e($piggyBank->name)
|
||||
. '" is not set to draw money from any of the accounts in this transfer'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -16,7 +16,7 @@ interface TransactionJournalRepositoryInterface
|
||||
* @param \Account $toAccount
|
||||
* @param $description
|
||||
* @param $amount
|
||||
* @param Carbon $date
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
@@ -27,6 +27,12 @@ interface TransactionJournalRepositoryInterface
|
||||
*/
|
||||
public function get();
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
* @return mixed
|
||||
*/
|
||||
public function overruleUser(\User $user);
|
||||
|
||||
/**
|
||||
* @param $what
|
||||
* @param $data
|
||||
@@ -52,9 +58,9 @@ interface TransactionJournalRepositoryInterface
|
||||
|
||||
/**
|
||||
* @param \Account $account
|
||||
* @param int $count
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param int $count
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
@@ -62,7 +68,7 @@ interface TransactionJournalRepositoryInterface
|
||||
|
||||
/**
|
||||
* @param \Account $account
|
||||
* @param Carbon $date
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
|
@@ -60,10 +60,10 @@ class EloquentUserRepository implements UserRepositoryInterface
|
||||
*/
|
||||
public function register($array)
|
||||
{
|
||||
$user = new \User;
|
||||
$user->email = isset($array['email']) ? $array['email'] : null;
|
||||
$user = new \User;
|
||||
$user->email = isset($array['email']) ? $array['email'] : null;
|
||||
$user->migrated = 0;
|
||||
$user->reset = \Str::random(32);
|
||||
$user->reset = \Str::random(32);
|
||||
$user->password = \Hash::make(\Str::random(12));
|
||||
|
||||
if (!$user->save()) {
|
||||
|
@@ -1,5 +1,24 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Importentry
|
||||
*
|
||||
* @property-read \Importmap $importmap
|
||||
* @property integer $id
|
||||
* @property \Carbon\Carbon $created_at
|
||||
* @property \Carbon\Carbon $updated_at
|
||||
* @property string $class
|
||||
* @property integer $importmap_id
|
||||
* @property integer $old
|
||||
* @property integer $new
|
||||
* @method static \Illuminate\Database\Query\Builder|\Importentry whereId($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Importentry whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Importentry whereUpdatedAt($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Importentry whereClass($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Importentry whereImportmapId($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Importentry whereOld($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Importentry whereNew($value)
|
||||
*/
|
||||
class Importentry extends Eloquent {
|
||||
public function importmap()
|
||||
{
|
||||
|
@@ -2,6 +2,18 @@
|
||||
|
||||
/**
|
||||
* Class Importmap
|
||||
*
|
||||
* @property-read \User $user
|
||||
* @property integer $id
|
||||
* @property \Carbon\Carbon $created_at
|
||||
* @property \Carbon\Carbon $updated_at
|
||||
* @property integer $user_id
|
||||
* @property string $file
|
||||
* @method static \Illuminate\Database\Query\Builder|\Importmap whereId($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Importmap whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Importmap whereUpdatedAt($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Importmap whereUserId($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Importmap whereFile($value)
|
||||
*/
|
||||
class Importmap extends Eloquent
|
||||
{
|
||||
|
@@ -47,6 +47,22 @@ use LaravelBook\Ardent\Builder;
|
||||
* 'Budget[] $budgets
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\
|
||||
* 'Category[] $categories
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\
|
||||
* 'Budget[] $budgets
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\
|
||||
* 'Category[] $categories
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\
|
||||
* 'Budget[] $budgets
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\
|
||||
* 'Category[] $categories
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\
|
||||
* 'Budget[] $budgets
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\
|
||||
* 'Category[] $categories
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\
|
||||
* 'Budget[] $budgets
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\
|
||||
* 'Category[] $categories
|
||||
*/
|
||||
class TransactionJournal extends Ardent
|
||||
{
|
||||
|
Reference in New Issue
Block a user