All kinds of code cleanup, mostly to get some mess detection fixed.

This commit is contained in:
James Cole
2014-12-19 20:47:33 +01:00
parent 8ab294e90b
commit 30ac62ffb7
15 changed files with 131 additions and 297 deletions

View File

@@ -175,7 +175,7 @@ class BudgetController extends BaseController
Session::flash('successes', $messages['successes']); Session::flash('successes', $messages['successes']);
Session::flash('errors', $messages['errors']); Session::flash('errors', $messages['errors']);
if ($messages['errors']->count() > 0) { if ($messages['errors']->count() > 0) {
Session::flash('error', 'Could not store budget: ' . $messages['errors']->first()); Session::flash('error', 'Could not validate budget: ' . $messages['errors']->first());
} }
// return to create screen: // return to create screen:

View File

@@ -299,64 +299,6 @@ class GoogleChartController extends BaseController
} }
/**
* @param $year
*
* @return \Illuminate\Http\JsonResponse
*/
public function budgetsReportChart($year)
{
try {
$start = new Carbon('01-01-' . $year);
} catch (Exception $e) {
App::abort(500);
}
/** @var \Grumpydictator\Gchart\GChart $chart */
$chart = App::make('gchart');
/** @var \FireflyIII\Database\Budget\Budget $bdt */
$bdt = App::make('FireflyIII\Database\Budget\Budget');
$budgets = $bdt->get();
$chart->addColumn('Month', 'date');
/** @var \Budget $budget */
foreach ($budgets as $budget) {
$chart->addColumn($budget->name, 'number');
}
$chart->addColumn('No budget', 'number');
/*
* Loop budgets this year.
*/
$end = clone $start;
$end->endOfYear();
while ($start <= $end) {
$row = [clone $start];
foreach ($budgets as $budget) {
$row[] = $bdt->spentInMonth($budget, $start);
}
/*
* Without a budget:
*/
$endOfMonth = clone $start;
$endOfMonth->endOfMonth();
$set = $bdt->transactionsWithoutBudgetInDateRange($start, $endOfMonth);
$row[] = floatval($set->sum('amount')) * -1;
$chart->addRowArray($row);
$start->addMonth();
}
$chart->generate();
return Response::json($chart->getData());
}
/** /**
* @param Category $component * @param Category $component
* @param $year * @param $year

View File

@@ -80,22 +80,6 @@ class HomeController extends BaseController
return Redirect::back(); return Redirect::back();
} }
public function repair()
{
BudgetLimit::get()->each(
function (BudgetLimit $bl) {
$component = Component::find($bl->component_id);
if ($component) {
$budget = Budget::whereName($component->name)->whereUserId($component->user_id)->first();
if ($budget) {
$bl->budget_id = $budget->id;
$bl->save();
}
}
}
);
}
/** /**
* @return \Illuminate\Http\RedirectResponse * @return \Illuminate\Http\RedirectResponse
*/ */

View File

@@ -1,21 +1,25 @@
<?php <?php
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Database\PiggyBank\RepeatedExpense as Repository;
use FireflyIII\Exception\FireflyException; use FireflyIII\Exception\FireflyException;
use Illuminate\Support\MessageBag;
/** /**
* Class RepeatedExpenseController * Class RepeatedExpenseController
*/ */
class RepeatedExpenseController extends BaseController class RepeatedExpenseController extends BaseController
{ {
/** @var Repository */
protected $_repository;
/** /**
* * @param Repository $repository
*/ */
public function __construct() public function __construct(Repository $repository)
{ {
View::share('title', 'Repeated expenses'); View::share('title', 'Repeated expenses');
View::share('mainTitleIcon', 'fa-rotate-left'); View::share('mainTitleIcon', 'fa-rotate-left');
$this->_repository = $repository;
} }
/** /**
@@ -86,50 +90,36 @@ class RepeatedExpenseController extends BaseController
*/ */
public function store() public function store()
{ {
$data = Input::all(); $data = Input::except('_token');
$data['repeats'] = 1; $data['repeats'] = 1;
/** @var \FireflyIII\Database\PiggyBank\RepeatedExpense $repository */
$repository = App::make('FireflyIII\Database\PiggyBank\RepeatedExpense');
switch ($data['post_submit_action']) { // always validate:
default: $messages = $this->_repository->validate($data);
throw new FireflyException('Cannot handle post_submit_action "' . e($data['post_submit_action']) . '"');
break;
case 'create_another':
case 'store':
$messages = $repository->validate($data);
/** @var MessageBag $messages ['errors'] */
if ($messages['errors']->count() > 0) {
Session::flash('warnings', $messages['warnings']);
Session::flash('successes', $messages['successes']);
Session::flash('error', 'Could not save repeated expense: ' . $messages['errors']->first());
return Redirect::route('repeated.create')->withInput()->withErrors($messages['errors']); // flash messages:
} Session::flash('warnings', $messages['warnings']);
// store! Session::flash('successes', $messages['successes']);
$repeated = $repository->store($data); Session::flash('errors', $messages['errors']);
if ($messages['errors']->count() > 0) {
/* Session::flash('error', 'Could not validate repeated expense: ' . $messages['errors']->first());
* Create the relevant repetition per Event.
*/
Event::fire('piggybank.store', [$repeated]); // new and used.
Session::flash('success', 'New repeated expense stored!');
if ($data['post_submit_action'] == 'create_another') {
return Redirect::route('repeated.create')->withInput();
} else {
return Redirect::route('repeated.index');
}
break;
case 'validate_only':
$messageBags = $repository->validate($data);
Session::flash('warnings', $messageBags['warnings']);
Session::flash('successes', $messageBags['successes']);
Session::flash('errors', $messageBags['errors']);
return Redirect::route('repeated.create')->withInput();
break;
} }
// return to create screen:
if ($data['post_submit_action'] == 'validate_only' || $messages['errors']->count() > 0) {
return Redirect::route('repeated.create')->withInput();
}
// store:
$this->_repository->store($data);
Session::flash('success', 'Budget "' . e($data['name']) . '" stored.');
if ($data['post_submit_action'] == 'store') {
return Redirect::route('repeated.index');
}
// create another.
if ($data['post_submit_action'] == 'create_another') {
return Redirect::route('repeated.create')->withInput();
}
return Redirect::route('repeated.index');
} }
} }

View File

@@ -55,8 +55,8 @@ class ChangesForV321 extends Migration
$this->moveCategoriesBack(); // 2. $this->moveCategoriesBack(); // 2.
$this->updateComponentInBudgetLimits(); // 3. $this->updateComponentInBudgetLimits(); // 3.
$this->dropBudgetIdColumnInBudgetLimits(); // 4. $this->dropBudgetIdColumnInBudgetLimits(); // 4.
$createJournalComponents = new CreateComponentTransactionJournalTable; // 5. $createComponents = new CreateComponentTransactionJournalTable; // 5.
$createJournalComponents->up(); $createComponents->up();
$this->moveBackEntriesForBudgetsInJoinedTable(); // 6. $this->moveBackEntriesForBudgetsInJoinedTable(); // 6.
$this->moveBackEntriesForCategoriesInJoinedTable(); // 7. $this->moveBackEntriesForCategoriesInJoinedTable(); // 7.
$this->dropBudgetJournalTable(); // 8. $this->dropBudgetJournalTable(); // 8.

View File

@@ -49,7 +49,7 @@ class TestContentSeeder extends Seeder
Component::create(['user_id' => $user->id, 'name' => 'Some Component 7', 'class' => 'Category']); Component::create(['user_id' => $user->id, 'name' => 'Some Component 7', 'class' => 'Category']);
// create some expense accounts. // create some expense accounts.
$ah = Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Albert Heijn', 'active' => 1]); $albert = Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Albert Heijn', 'active' => 1]);
$plus = Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'PLUS', 'active' => 1]); $plus = Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'PLUS', 'active' => 1]);
$vitens = Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Vitens', 'active' => 1]); $vitens = Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Vitens', 'active' => 1]);
$greenchoice = Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Greenchoice', 'active' => 1]); $greenchoice = Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Greenchoice', 'active' => 1]);
@@ -59,7 +59,7 @@ class TestContentSeeder extends Seeder
// create three revenue accounts. // create three revenue accounts.
$employer = Account::create(['user_id' => $user->id, 'account_type_id' => $revenueType->id, 'name' => 'Employer', 'active' => 1]); $employer = Account::create(['user_id' => $user->id, 'account_type_id' => $revenueType->id, 'name' => 'Employer', 'active' => 1]);
$taxes = Account::create(['user_id' => $user->id, 'account_type_id' => $revenueType->id, 'name' => 'IRS', 'active' => 1]); $taxes = Account::create(['user_id' => $user->id, 'account_type_id' => $revenueType->id, 'name' => 'IRS', 'active' => 1]);
$job = Account::create(['user_id' => $user->id, 'account_type_id' => $revenueType->id, 'name' => 'Job', 'active' => 1]); Account::create(['user_id' => $user->id, 'account_type_id' => $revenueType->id, 'name' => 'Job', 'active' => 1]);
// put money in the two accounts (initial balance) // put money in the two accounts (initial balance)
$ibChecking = Account::create( $ibChecking = Account::create(
@@ -98,7 +98,7 @@ class TestContentSeeder extends Seeder
$groceriesStart->addDay(); $groceriesStart->addDay();
if (intval($groceriesStart->format('d')) % 2 == 0) { if (intval($groceriesStart->format('d')) % 2 == 0) {
$this->createTransaction( $this->createTransaction(
$checking, $ah, $amt, $withdrawal, 'Groceries', $groceriesStart->format('Y-m-d'), $groceriesBudget, $dailyGroceries $checking, $albert, $amt, $withdrawal, 'Groceries', $groceriesStart->format('Y-m-d'), $groceriesBudget, $dailyGroceries
); );
} }
$groceriesStart->addDay(); $groceriesStart->addDay();

View File

@@ -235,11 +235,10 @@ class Budget implements CUD, CommonDatabaseCalls, BudgetInterface
public function repetitionOnStartingOnDate(\Budget $budget, Carbon $date) public function repetitionOnStartingOnDate(\Budget $budget, Carbon $date)
{ {
return \LimitRepetition:: return \LimitRepetition::
leftJoin('budget_limits', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id')->leftJoin( leftJoin('budget_limits', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id')
'budgets', 'budget_limits.budget_id', '=', 'budgets.id' ->where('limit_repetitions.startdate', $date->format('Y-m-d'))
)->where('limit_repetitions.startdate', $date->format('Y-m-d'))->where( ->where('budget_limits.budget_id', $budget->id)
'budgets.id', $budget->id ->first(['limit_repetitions.*']);
)->first(['limit_repetitions.*']);
} }
/** /**
@@ -251,15 +250,22 @@ class Budget implements CUD, CommonDatabaseCalls, BudgetInterface
public function transactionsWithoutBudgetInDateRange(Carbon $start, Carbon $end) public function transactionsWithoutBudgetInDateRange(Carbon $start, Carbon $end)
{ {
// Add expenses that have no budget: // Add expenses that have no budget:
return $this->getUser()->transactionjournals()->whereNotIn( return $this->getUser()
'transaction_journals.id', function ($query) use ($start, $end) { ->transactionjournals()
$query->select('transaction_journals.id')->from('transaction_journals')->leftJoin( ->whereNotIn('transaction_journals.id', function ($query) use ($start, $end) {
'budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id' $query
)->leftJoin('budgets', 'budgets.id', '=', 'budget_transaction_journal.budget_id')->where( ->select('transaction_journals.id')
'transaction_journals.date', '>=', $start->format('Y-m-d') ->from('transaction_journals')
)->where('transaction_journals.date', '<=', $end->format('Y-m-d')); ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
->where('transaction_journals.date', '>=', $start->format('Y-m-d'))
->where('transaction_journals.date', '<=', $end->format('Y-m-d'));
} }
)->before($end)->after($start)->lessThan(0)->transactionTypes(['Withdrawal'])->get(); )
->before($end)
->after($start)
->lessThan(0)
->transactionTypes(['Withdrawal'])
->get();
} }
/** /**

View File

@@ -232,6 +232,7 @@ class PiggyBank implements CUD, CommonDatabaseCalls, PiggyBankInterface
*/ */
public function findRepetitionByDate(\Piggybank $piggybank, Carbon $date) public function findRepetitionByDate(\Piggybank $piggybank, Carbon $date)
{ {
/** @var Collection $reps */
$reps = $piggybank->piggybankrepetitions()->get(); $reps = $piggybank->piggybankrepetitions()->get();
if ($reps->count() == 1) { if ($reps->count() == 1) {
return $reps->first(); return $reps->first();
@@ -239,7 +240,19 @@ class PiggyBank implements CUD, CommonDatabaseCalls, PiggyBankInterface
if ($reps->count() == 0) { if ($reps->count() == 0) {
throw new FireflyException('Should always find a piggy bank repetition.'); throw new FireflyException('Should always find a piggy bank repetition.');
} }
throw new NotImplementedException; // should filter the one we need:
$repetitions = $reps->filter(
function (\PiggybankRepetition $rep) use ($date) {
if ($date >= $rep->startdate && $date <= $rep->targetdate) {
return $rep;
}
}
);
if ($repetitions->count() == 0) {
return null;
}
return $repetitions->first();
} }
/** /**

View File

@@ -117,12 +117,10 @@ class RepeatedExpense implements CUD, CommonDatabaseCalls, PiggyBankInterface
public function store(array $data) public function store(array $data)
{ {
$data['rep_every'] = isset($data['rep_every']) ? $data['rep_every'] : 0; $data['rep_every'] = intval($data['rep_every']);
$data['reminder_skip'] = isset($data['reminder_skip']) ? $data['reminder_skip'] : 0; $data['reminder_skip'] = intval($data['reminder_skip']);
$data['order'] = isset($data['order']) ? $data['order'] : 0; $data['order'] = intval($data['order']);
$data['remind_me'] = isset($data['remind_me']) ? intval($data['remind_me']) : 0; $data['remind_me'] = intval($data['remind_me']);
$data['startdate'] = isset($data['startdate']) ? $data['startdate'] : Carbon::now()->format('Y-m-d');
$data['targetdate'] = isset($data['targetdate']) && $data['targetdate'] != '' ? $data['targetdate'] : null;
$data['account_id'] = intval($data['account_id']); $data['account_id'] = intval($data['account_id']);
@@ -130,12 +128,7 @@ class RepeatedExpense implements CUD, CommonDatabaseCalls, PiggyBankInterface
$data['reminder'] = null; $data['reminder'] = null;
} }
$repeated = new \Piggybank($data); $repeated = new \Piggybank($data);
if (!$repeated->isValid()) {
var_dump($repeated->getErrors()->all());
exit;
}
$repeated->save(); $repeated->save();
return $repeated; return $repeated;

View File

@@ -92,78 +92,20 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData
*/ */
public function update(\Eloquent $model, array $data) public function update(\Eloquent $model, array $data)
{ {
/** @var \FireflyIII\Database\TransactionType\TransactionType $typeRepository */ $journalType = $this->getJournalType($data['what']);
$typeRepository = \App::make('FireflyIII\Database\TransactionType\TransactionType'); $currency = $this->getJournalCurrency($data['currency']);
$model->description = $data['description'];
/** @var \FireflyIII\Database\Account\Account $accountRepository */ $model->date = $data['date'];
$accountRepository = \App::make('FireflyIII\Database\Account\Account');
/** @var \FireflyIII\Database\TransactionCurrency\TransactionCurrency $currencyRepository */
$currencyRepository = \App::make('FireflyIII\Database\TransactionCurrency\TransactionCurrency');
$journalType = $typeRepository->findByWhat($data['what']);
$currency = $currencyRepository->findByCode($data['currency']);
$model->transactionType()->associate($journalType); $model->transactionType()->associate($journalType);
$model->transactionCurrency()->associate($currency); $model->transactionCurrency()->associate($currency);
$model->user()->associate($this->getUser()); $model->user()->associate($this->getUser());
$model->description = $data['description'];
$model->date = $data['date'];
/*
* This must be enough to store the journal:
*/
if (!$model->isValid()) {
\Log::error($model->getErrors()->all());
throw new FireflyException('store() transaction journal failed, but it should not!');
}
$model->save(); $model->save();
/* list($fromAccount, $toAccount) = $this->storeAccounts($data);
* Still need to find the accounts related to the transactions.
* This depends on the type of transaction.
*/
switch ($data['what']) {
case 'withdrawal':
$data['from'] = $accountRepository->find($data['account_id']);
$data['to'] = $accountRepository->firstExpenseAccountOrCreate($data['expense_account']);
break;
case 'opening':
break;
case 'deposit':
$data['to'] = $accountRepository->find($data['account_id']);
$data['from'] = $accountRepository->firstRevenueAccountOrCreate($data['revenue_account']);
break;
case 'transfer':
$data['from'] = $accountRepository->find($data['account_from_id']);
$data['to'] = $accountRepository->find($data['account_to_id']);
break;
default: $this->storeBudget($data, $model);
throw new FireflyException('Cannot save transaction journal with accounts based on $what "' . $data['what'] . '".'); $this->storeCategory($data, $model);
break;
}
/*
* Update the budget and the category.
*/
if (isset($data['budget_id']) && intval($data['budget_id']) > 0) {
/** @var \FireflyIII\Database\Budget\Budget $budgetRepository */
$budgetRepository = \App::make('FireflyIII\Database\Budget\Budget');
$budget = $budgetRepository->find(intval($data['budget_id']));
if ($budget) {
$model->budgets()->sync([$budget->id]);
}
}
if (strlen($data['category']) > 0) {
/** @var \FireflyIII\Database\Category\Category $categoryRepository */
$categoryRepository = \App::make('FireflyIII\Database\Category\Category');
$category = $categoryRepository->firstOrCreate($data['category']);
if ($category) {
$model->categories()->sync([$category->id]);
}
}
/* /*
* TODO move to transaction thing. * TODO move to transaction thing.
@@ -174,10 +116,10 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData
foreach ($model->transactions()->get() as $transaction) { foreach ($model->transactions()->get() as $transaction) {
if (floatval($transaction->amount) > 0) { if (floatval($transaction->amount) > 0) {
// the TO transaction. // the TO transaction.
$transaction->account()->associate($data['to']); $transaction->account()->associate($toAccount);
$transaction->amount = $amount; $transaction->amount = $amount;
} else { } else {
$transaction->account()->associate($data['from']); $transaction->account()->associate($fromAccount);
$transaction->amount = $amount * -1; $transaction->amount = $amount * -1;
} }
if (!$transaction->isValid()) { if (!$transaction->isValid()) {
@@ -443,8 +385,8 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData
} }
/** /**
* @param array $data * @param array $data
* @param \TransactionJournal $journal * @param \TransactionJournal|\Eloquent $journal
*/ */
public function storeBudget($data, \TransactionJournal $journal) public function storeBudget($data, \TransactionJournal $journal)
{ {
@@ -453,14 +395,14 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData
$budgetRepository = \App::make('FireflyIII\Database\Budget\Budget'); $budgetRepository = \App::make('FireflyIII\Database\Budget\Budget');
$budget = $budgetRepository->find(intval($data['budget_id'])); $budget = $budgetRepository->find(intval($data['budget_id']));
if ($budget) { if ($budget) {
$journal->budgets()->save($budget); $journal->budgets()->sync([$budget->id]);
} }
} }
} }
/** /**
* @param array $data * @param array $data
* @param \TransactionJournal $journal * @param \TransactionJournal|\Eloquent $journal
*/ */
public function storeCategory(array $data, \TransactionJournal $journal) public function storeCategory(array $data, \TransactionJournal $journal)
{ {

View File

@@ -87,10 +87,6 @@ class Piggybank
$event->piggybank()->associate($piggybank); $event->piggybank()->associate($piggybank);
$event->amount = floatval($amount); $event->amount = floatval($amount);
$event->date = new Carbon; $event->date = new Carbon;
if (!$event->isValid()) {
var_dump($event->getErrors());
exit();
}
$event->save(); $event->save();
} }
} }
@@ -120,7 +116,7 @@ class Piggybank
*/ */
public function storeTransfer(\TransactionJournal $journal, $piggybankId = 0) public function storeTransfer(\TransactionJournal $journal, $piggybankId = 0)
{ {
if ($piggybankId == 0 || is_null($piggybankId)) { if (intval($piggybankId) == 0) {
return; return;
} }
/** @var \FireflyIII\Database\PiggyBank\PiggyBank $repository */ /** @var \FireflyIII\Database\PiggyBank\PiggyBank $repository */
@@ -129,58 +125,32 @@ class Piggybank
/** @var \Piggybank $piggyBank */ /** @var \Piggybank $piggyBank */
$piggyBank = $repository->find($piggybankId); $piggyBank = $repository->find($piggybankId);
/** @var \PiggybankRepetition $repetition */ if ($journal->transactions()->where('account_id', $piggyBank->account_id)->count() == 0) {
$repetition = $repository->findRepetitionByDate($piggyBank, $journal->date);
\Log::debug(
'Connecting transfer "' . $journal->description . '" (#' . $journal->id . ') to piggy bank "' . $piggyBank->name . '" (#' . $piggyBank->id . ').'
);
// some variables to double check the connection.
$start = $piggyBank->startdate;
$end = $piggyBank->targetdate;
$amount = floatval($piggyBank->targetamount);
$leftToSave = $amount - floatval($repetition->currentamount);
$relevantTransaction = null;
/** @var \Transaction $transaction */
foreach ($journal->transactions as $transaction) {
if ($transaction->account_id == $piggyBank->account_id) {
$relevantTransaction = $transaction;
}
}
if (is_null($relevantTransaction)) {
return; return;
} }
\Log::debug('Relevant transaction is #' . $relevantTransaction->id . ' with amount ' . $relevantTransaction->amount); /** @var \PiggybankRepetition $repetition */
$repetition = $repository->findRepetitionByDate($piggyBank, $journal->date);
// if FF3 should save this connection depends on some variables: $amount = floatval($piggyBank->targetamount);
if ($start && $end && $journal->date >= $start && $journal->date <= $end) { $leftToSave = $amount - floatval($repetition->currentamount);
if ($relevantTransaction->amount < 0) { // amount removed from account, so removed from piggy bank. $transaction = $journal->transactions()->where('account_id', $piggyBank->account_id)->first();
\Log::debug('Remove from piggy bank.'); // must be in range of journal. Continue determines if we can move it.
$continue = ($relevantTransaction->amount * -1 <= floatval($repetition->currentamount)); if (floatval($transaction->amount < 0)) {
\Log::debug( // amount removed from account, so removed from piggy bank.
'relevantTransaction.amount *-1 = ' . ($relevantTransaction->amount * -1) . ' >= current = ' . floatval($repetition->currentamount) $continue = ($transaction->amount * -1 <= floatval($repetition->currentamount));
); } else {
} else { // amount added // amount added
\Log::debug('Add from piggy bank.'); $continue = $transaction->amount <= $leftToSave;
$continue = $relevantTransaction->amount <= $leftToSave; }
} if ($continue) {
if ($continue) { \Log::debug('Update repetition.');
\Log::debug('Update repetition.'); $repetition->currentamount += floatval($transaction->amount);
$repetition->currentamount += floatval($relevantTransaction->amount); $repetition->save();
$repetition->save(); $event = new \PiggyBankEvent;
$event->piggybank()->associate($piggyBank);
$event = new \PiggyBankEvent; $event->transactionjournal()->associate($journal);
$event->piggybank()->associate($piggyBank); $event->amount = floatval($transaction->amount);
$event->transactionjournal()->associate($journal); $event->date = new Carbon;
$event->amount = floatval($relevantTransaction->amount); $event->save();
$event->date = new Carbon;
if (!$event->isValid()) {
var_dump($event->getErrors());
exit();
}
$event->save();
}
} }
} }

View File

@@ -71,15 +71,9 @@ class Reminders
$today = Carbon::now(); $today = Carbon::now();
//$today = new Carbon('14-12-2014');
/** @var \Piggybank $piggybank */ /** @var \Piggybank $piggybank */
foreach ($set as $piggyBank) { foreach ($set as $piggyBank) {
/*
* Try to find a reminder that is valid in the current [period]
* aka between [start of period] and [end of period] as denoted
* by the piggy's repeat_freq.
*/
/** @var \PiggybankRepetition $repetition */ /** @var \PiggybankRepetition $repetition */
$repetition = $piggyBank->currentRelevantRep(); $repetition = $piggyBank->currentRelevantRep();
$start = \DateKit::startOfPeriod($today, $piggyBank->reminder); $start = \DateKit::startOfPeriod($today, $piggyBank->reminder);

View File

@@ -51,15 +51,16 @@ class LimitRepetition extends Eloquent
*/ */
public function spentInRepetition() public function spentInRepetition()
{ {
$sum = \DB::table('transactions')->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')->leftJoin( $sum = \DB::table('transactions')
'component_transaction_journal', 'component_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id' ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
)->leftJoin('components', 'components.id', '=', 'component_transaction_journal.component_id')->leftJoin( ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
'budget_limits', 'budget_limits.component_id', '=', 'components.id' ->leftJoin('budget_limits', 'budget_limits.budget_id', '=', 'budget_transaction_journal.budget_id')
)->leftJoin('limit_repetitions', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id')->where( ->leftJoin('limit_repetitions', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id')
'transaction_journals.date', '>=', $this->startdate->format('Y-m-d') ->where('transaction_journals.date', '>=', $this->startdate->format('Y-m-d'))
)->where('transaction_journals.date', '<=', $this->enddate->format('Y-m-d'))->where('transactions.amount', '>', 0)->where( ->where('transaction_journals.date', '<=', $this->enddate->format('Y-m-d'))
'limit_repetitions.id', '=', $this->id ->where('transactions.amount', '>', 0)
)->sum('transactions.amount'); ->where('limit_repetitions.id', '=', $this->id)
->sum('transactions.amount');
return floatval($sum); return floatval($sum);
} }

View File

@@ -98,10 +98,11 @@ Route::bind(
Route::bind( Route::bind(
'limitrepetition', function ($value, $route) { 'limitrepetition', function ($value, $route) {
if (Auth::check()) { if (Auth::check()) {
return LimitRepetition:: return LimitRepetition::where('limit_repetitions.id', $value)
where('limit_repetitions.id', $value)->leftjoin('budget_limits', 'budget_limits.id', '=', 'limit_repetitions.budget_limit_id')->leftJoin( ->leftjoin('budget_limits', 'budget_limits.id', '=', 'limit_repetitions.budget_limit_id')
'budgets', 'budgets.id', '=', 'budget_limits.budget_id' ->leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id')
)->where('budgets.user_id', Auth::user()->id)->first(['limit_repetitions.*']); ->where('budgets.user_id', Auth::user()->id)
->first(['limit_repetitions.*']);
} }
return null; return null;
@@ -180,7 +181,6 @@ Route::group(
Route::get('/chart/reports/income-expenses/{year}', ['uses' => 'GoogleChartController@yearInExp']); Route::get('/chart/reports/income-expenses/{year}', ['uses' => 'GoogleChartController@yearInExp']);
Route::get('/chart/reports/income-expenses-sum/{year}', ['uses' => 'GoogleChartController@yearInExpSum']); Route::get('/chart/reports/income-expenses-sum/{year}', ['uses' => 'GoogleChartController@yearInExpSum']);
Route::get('/chart/recurring/{recurring}', ['uses' => 'GoogleChartController@recurringOverview']); Route::get('/chart/recurring/{recurring}', ['uses' => 'GoogleChartController@recurringOverview']);
Route::get('/chart/reports/budgets/{year}', ['uses' => 'GoogleChartController@budgetsReportChart']);
Route::get('/chart/budget/{budget}/{limitrepetition}', ['uses' => 'GoogleChartController@budgetLimitSpending']); Route::get('/chart/budget/{budget}/{limitrepetition}', ['uses' => 'GoogleChartController@budgetLimitSpending']);
Route::get('/chart/piggyhistory/{piggybank}', ['uses' => 'GoogleChartController@piggyBankHistory']); Route::get('/chart/piggyhistory/{piggybank}', ['uses' => 'GoogleChartController@piggyBankHistory']);

View File

@@ -3,6 +3,5 @@ if (typeof(google) != 'undefined') {
function drawChart() { function drawChart() {
googleColumnChart('chart/reports/income-expenses/' + year, 'income-expenses-chart'); googleColumnChart('chart/reports/income-expenses/' + year, 'income-expenses-chart');
googleColumnChart('chart/reports/income-expenses-sum/' + year, 'income-expenses-sum-chart') googleColumnChart('chart/reports/income-expenses-sum/' + year, 'income-expenses-sum-chart')
googleStackedColumnChart('chart/reports/budgets/' + year, 'budgets');
} }
} }