Simplified some code.

This commit is contained in:
James Cole 2016-04-29 08:56:56 +02:00
parent ea014a6504
commit 14b94a5bd2
13 changed files with 104 additions and 83 deletions

View File

@ -95,11 +95,10 @@ class AbnAmroDescription extends Specifix implements SpecifixInterface
// description and opposing account will be the same.
$this->data['opposing-account-name'] = $matches[4];
$this->data['description'] = $matches[4];
if ($matches[1] == 'GEA') {
$this->data['description'] = 'GEA ' . $matches[4];
} else {
$this->data['description'] = $matches[4];
}
return true;
@ -154,9 +153,8 @@ class AbnAmroDescription extends Specifix implements SpecifixInterface
// Set a new description for the current transaction. If none was given
// set the description to type, name and reference
if ($newDescription) {
$this->data['description'] = $newDescription;
} else {
$this->data['description'] = $newDescription;
if (strlen($newDescription) === 0) {
$this->data['description'] = sprintf('%s - %s (%s)', $type, $name, $reference);
}
@ -212,9 +210,8 @@ class AbnAmroDescription extends Specifix implements SpecifixInterface
// Set a new description for the current transaction. If none was given
// set the description to type, name and reference
if ($newDescription) {
$this->data['description'] = $newDescription;
} else {
$this->data['description'] = $newDescription;
if (strlen($newDescription) === 0) {
$this->data['description'] = sprintf('%s - %s (%s)', $type, $name, $reference);
}
}

View File

@ -55,9 +55,8 @@ class ConfirmationController extends Controller
Session::flash('success', strval(trans('firefly.account_is_confirmed')));
return redirect(route('home'));
} else {
throw new FireflyException(trans('firefly.invalid_activation_code'));
}
throw new FireflyException(trans('firefly.invalid_activation_code'));
}
/**

View File

@ -251,34 +251,19 @@ class BudgetController extends Controller
/**
* @param BudgetRepositoryInterface $repository
* @param Budget $budget
* @param LimitRepetition|null $repetition
*
* @return View
* @throws FireflyException
*/
public function show(BudgetRepositoryInterface $repository, Budget $budget, LimitRepetition $repetition = null)
public function show(BudgetRepositoryInterface $repository, Budget $budget)
{
if (!is_null($repetition->id) && $repetition->budgetLimit->budget->id != $budget->id) {
throw new FireflyException('This budget limit is not part of this budget.');
}
$pageSize = Preferences::get('transactionPageSize', 50)->data;
$journals = $repository->getJournals($budget, $repetition, $pageSize);
if (is_null($repetition->id)) {
$start = $repository->firstActivity($budget);
$end = new Carbon;
$set = $budget->limitrepetitions()->orderBy('startdate', 'DESC')->get();
$subTitle = e($budget->name);
$journals->setPath('/budgets/show/' . $budget->id);
} else {
$start = $repetition->startdate;
$end = $repetition->enddate;
$set = new Collection([$repetition]);
$subTitle = trans('firefly.budget_in_month', ['name' => $budget->name, 'month' => $repetition->startdate->formatLocalized($this->monthFormat)]);
$journals->setPath('/budgets/show/' . $budget->id . '/' . $repetition->id);
}
$journals = $repository->getJournals($budget, new LimitRepetition, $pageSize);
$start = $repository->firstActivity($budget);
$end = new Carbon;
$set = $budget->limitrepetitions()->orderBy('startdate', 'DESC')->get();
$subTitle = e($budget->name);
$journals->setPath('/budgets/show/' . $budget->id);
$spentArray = $repository->spentPerDay($budget, $start, $end);
$limits = new Collection();
@ -292,6 +277,41 @@ class BudgetController extends Controller
return view('budgets.show', compact('limits', 'budget', 'repetition', 'journals', 'subTitle'));
}
/**
* @param BudgetRepositoryInterface $repository
* @param Budget $budget
* @param LimitRepetition $repetition
*
* @return View
* @throws FireflyException
*/
public function showWithRepetition(BudgetRepositoryInterface $repository, Budget $budget, LimitRepetition $repetition)
{
if ($repetition->budgetLimit->budget->id != $budget->id) {
throw new FireflyException('This budget limit is not part of this budget.');
}
$pageSize = Preferences::get('transactionPageSize', 50)->data;
$journals = $repository->getJournals($budget, $repetition, $pageSize);
$start = $repetition->startdate;
$end = $repetition->enddate;
$set = new Collection([$repetition]);
$subTitle = trans('firefly.budget_in_month', ['name' => $budget->name, 'month' => $repetition->startdate->formatLocalized($this->monthFormat)]);
$journals->setPath('/budgets/show/' . $budget->id . '/' . $repetition->id);
$spentArray = $repository->spentPerDay($budget, $start, $end);
$limits = new Collection();
/** @var LimitRepetition $entry */
foreach ($set as $entry) {
$entry->spent = $this->getSumOfRange($entry->startdate, $entry->enddate, $spentArray);
$limits->push($entry);
}
return view('budgets.show', compact('limits', 'budget', 'repetition', 'journals', 'subTitle'));
}
/**
* @param BudgetFormRequest $request
* @param BudgetRepositoryInterface $repository

View File

@ -186,25 +186,26 @@ class CategoryController extends Controller
if ($cache->has()) {
$entries = $cache->get();
} else {
while ($end >= $start) {
$end = Navigation::startOfPeriod($end, $range);
$currentEnd = Navigation::endOfPeriod($end, $range);
// get data from spentArray:
$spent = $this->getSumOfRange($end, $currentEnd, $spentArray);
$earned = $this->getSumOfRange($end, $currentEnd, $earnedArray);
$dateStr = $end->format('Y-m-d');
$dateName = Navigation::periodShow($end, $range);
$entries->push([$dateStr, $dateName, $spent, $earned]);
$end = Navigation::subtractPeriod($end, $range, 1);
}
$cache->store($entries);
return view('categories.show', compact('category', 'journals', 'entries', 'hideCategory', 'subTitle'));
}
while ($end >= $start) {
$end = Navigation::startOfPeriod($end, $range);
$currentEnd = Navigation::endOfPeriod($end, $range);
// get data from spentArray:
$spent = $this->getSumOfRange($end, $currentEnd, $spentArray);
$earned = $this->getSumOfRange($end, $currentEnd, $earnedArray);
$dateStr = $end->format('Y-m-d');
$dateName = Navigation::periodShow($end, $range);
$entries->push([$dateStr, $dateName, $spent, $earned]);
$end = Navigation::subtractPeriod($end, $range, 1);
}
$cache->store($entries);
return view('categories.show', compact('category', 'journals', 'entries', 'hideCategory', 'subTitle'));
}

View File

@ -51,9 +51,11 @@ class BillController extends Controller
// expenses are negative (bill not yet paid),
$creditCardDue = bcmul($creditCardDue, '-1');
$unpaid = bcadd($unpaid, $creditCardDue);
} else {
// if more than zero, the bill has been paid: (transfer = positive).
// amount must be negative to be added to $paid:
}
// if $creditCardDue more than zero, the bill has been paid: (transfer = positive).
// amount must be negative to be added to $paid:
if ($creditCardDue >= 0) {
$paid = bcadd($paid, $creditCardDue);
}

View File

@ -168,14 +168,16 @@ class CurrencyController extends Controller
*/
public function store(CurrencyFormRequest $request, CurrencyRepositoryInterface $repository)
{
$data = $request->getCurrencyData();
if (Auth::user()->hasRole('owner')) {
$currency = $repository->store($data);
Session::flash('success', trans('firefly.created_currency', ['name' => $currency->name]));
} else {
if (!Auth::user()->hasRole('owner')) {
Log::error('User ' . Auth::user()->id . ' is not admin, but tried to store a currency.');
return redirect(session('currency.create.url'));
}
$data = $request->getCurrencyData();
$currency = $repository->store($data);
Session::flash('success', trans('firefly.created_currency', ['name' => $currency->name]));
if (intval(Input::get('create_another')) === 1) {
Session::put('currency.create.fromStore', true);

View File

@ -32,16 +32,15 @@ class HomeController extends Controller
public function dateRange()
{
$start = new Carbon(Input::get('start'));
$end = new Carbon(Input::get('end'));
$label = Input::get('label');
$start = new Carbon(Input::get('start'));
$end = new Carbon(Input::get('end'));
$label = Input::get('label');
$isCustomRange = false;
// check if the label is "everything" or "Custom range" which will betray
// a possible problem with the budgets.
if ($label === strval(trans('firefly.everything')) || $label === strval(trans('firefly.customRange'))) {
Session::put('is_custom_range', true);
} else {
Session::put('is_custom_range', false);
$isCustomRange = true;
}
$diff = $start->diffInDays($end);
@ -50,6 +49,7 @@ class HomeController extends Controller
Session::flash('warning', strval(trans('firefly.warning_much_data', ['days' => $diff])));
}
Session::put('is_custom_range', $isCustomRange);
Session::put('start', $start);
Session::put('end', $end);
}

View File

@ -111,12 +111,12 @@ class NewUserController extends Controller
$repository->storeMeta($creditCard, 'ccMonthlyPaymentDate', Carbon::now()->year . '-01-01');
$count++;
}
$message = strval(trans('firefly.stored_new_accounts_new_user'));
if ($count == 1) {
Session::flash('success', strval(trans('firefly.stored_new_account_new_user')));
} else {
Session::flash('success', strval(trans('firefly.stored_new_accounts_new_user')));
$message = strval(trans('firefly.stored_new_account_new_user'));
}
Session::flash('success', $message);
Preferences::mark();
return redirect(route('index'));

View File

@ -127,16 +127,15 @@ class PiggyBankController extends Controller
$accounts = ExpandedForm::makeSelectList($repository->getAccounts(['Default account', 'Asset account']));
$subTitle = trans('firefly.update_piggy_title', ['name' => $piggyBank->name]);
$subTitleIcon = 'fa-pencil';
$targetDate = null;
/*
* Flash some data to fill the form.
*/
if (is_null($piggyBank->targetdate) || $piggyBank->targetdate == '') {
$targetDate = null;
} else {
if (!is_null($piggyBank->targetdate) || !$piggyBank->targetdate == '') {
$targetDate = new Carbon($piggyBank->targetdate);
$targetDate = $targetDate->format('Y-m-d');
}
$preFilled = ['name' => $piggyBank->name,
'account_id' => $piggyBank->account_id,
'targetamount' => $piggyBank->targetamount,
@ -246,13 +245,13 @@ class PiggyBankController extends Controller
'success', strval(trans('firefly.added_amount_to_piggy', ['amount' => Amount::format($amount, false), 'name' => e($piggyBank->name)]))
);
Preferences::mark();
} else {
Log::error('Cannot add ' . $amount . ' because max amount is ' . $maxAmount . ' (left on account is ' . $leftOnAccount . ')');
Session::flash(
'error', strval(trans('firefly.cannot_add_amount_piggy', ['amount' => Amount::format($amount, false), 'name' => e($piggyBank->name)]))
);
return redirect(route('piggy-banks.index'));
}
Log::error('Cannot add ' . $amount . ' because max amount is ' . $maxAmount . ' (left on account is ' . $leftOnAccount . ')');
Session::flash('error', strval(trans('firefly.cannot_add_amount_piggy', ['amount' => Amount::format($amount, false), 'name' => e($piggyBank->name)])));
return redirect(route('piggy-banks.index'));
}
@ -280,12 +279,12 @@ class PiggyBankController extends Controller
'success', strval(trans('firefly.removed_amount_from_piggy', ['amount' => Amount::format($amount, false), 'name' => e($piggyBank->name)]))
);
Preferences::mark();
} else {
Session::flash(
'error', strval(trans('firefly.cannot_remove_from_piggy', ['amount' => Amount::format($amount, false), 'name' => e($piggyBank->name)]))
);
return redirect(route('piggy-banks.index'));
}
Session::flash('error', strval(trans('firefly.cannot_remove_from_piggy', ['amount' => Amount::format($amount, false), 'name' => e($piggyBank->name)])));
return redirect(route('piggy-banks.index'));
}

View File

@ -124,7 +124,8 @@ Route::group(
Route::get('/budgets/create', ['uses' => 'BudgetController@create', 'as' => 'budgets.create']);
Route::get('/budgets/edit/{budget}', ['uses' => 'BudgetController@edit', 'as' => 'budgets.edit']);
Route::get('/budgets/delete/{budget}', ['uses' => 'BudgetController@delete', 'as' => 'budgets.delete']);
Route::get('/budgets/show/{budget}/{limitrepetition?}', ['uses' => 'BudgetController@show', 'as' => 'budgets.show']);
Route::get('/budgets/show/{budget}', ['uses' => 'BudgetController@show', 'as' => 'budgets.show']);
Route::get('/budgets/show/{budget}/{limitrepetition}', ['uses' => 'BudgetController@showWithRepetition', 'as' => 'budgets.showWithRepetition']);
Route::get('/budgets/list/noBudget', ['uses' => 'BudgetController@noBudget', 'as' => 'budgets.noBudget']);
Route::post('/budgets/income', ['uses' => 'BudgetController@postUpdateIncome', 'as' => 'budgets.postIncome']);
Route::post('/budgets/store', ['uses' => 'BudgetController@store', 'as' => 'budgets.store']);

View File

@ -107,7 +107,7 @@
<h3 class="box-title">
<!-- link in header -->
{% if budget.currentRep.id %}
<a href="{{ route('budgets.show', [budget.id, budget.currentRep.id]) }}" class="budget-link"
<a href="{{ route('budgets.showWithRepetition', [budget.id, budget.currentRep.id]) }}" class="budget-link"
data-id="{{ budget.id }}">{{ budget.name }}</a>
{% else %}
<a href="{{ route('budgets.show',budget.id) }}" class="budget-link" data-id="{{ budget.id }}">{{ budget.name }}</a>
@ -173,7 +173,7 @@
{% for other in budget.otherRepetitions %}
{% if other.id != budget.currentRep.id %}
<li>Budgeted
<a href="{{ route('budgets.show', [budget.id, other.id]) }}">{{ other.amount|formatAmountPlain }}</a>
<a href="{{ route('budgets.showWithRepetition', [budget.id, other.id]) }}">{{ other.amount|formatAmountPlain }}</a>
between
{{ other.startdate.formatLocalized(monthAndDayFormat) }}
and {{ other.enddate.formatLocalized(monthAndDayFormat) }}.

View File

@ -48,7 +48,7 @@
{% for limit in limits %}
<div class="box">
<div class="box-header with-border">
<h3 class="box-title"><a href="{{ route('budgets.show',[budget.id,limit.id]) }}">{{ limit.startdate.formatLocalized(monthFormat) }}</a>
<h3 class="box-title"><a href="{{ route('budgets.showWithRepetition',[budget.id,limit.id]) }}">{{ limit.startdate.formatLocalized(monthFormat) }}</a>
</h3>
</div>
<div class="box-body">

View File

@ -27,7 +27,7 @@
</td>
<td>
{% if budgetLine.getRepetition.id %}
<a href="{{ route('budgets.show', [budgetLine.getBudget.id, budgetLine.getRepetition.id]) }}">
<a href="{{ route('budgets.showWithRepetition', [budgetLine.getBudget.id, budgetLine.getRepetition.id]) }}">
{{ budgetLine.getRepetition.startdate.formatLocalized(monthAndDayFormat) }}
&mdash;
{{ budgetLine.getRepetition.enddate.formatLocalized(monthAndDayFormat) }}