Small bugfixes for issues in beta 2

This commit is contained in:
James Cole 2021-03-15 07:45:46 +01:00
parent b9bf5c9856
commit 8d84dfb3aa
No known key found for this signature in database
GPG Key ID: B5669F9493CDE38D
16 changed files with 99 additions and 192 deletions

View File

@ -44,11 +44,8 @@ class CreateController extends Controller
{ {
use ModelInformation; use ModelInformation;
/** @var AttachmentHelperInterface Helper for attachments. */ private AttachmentHelperInterface $attachments;
private $attachments; private AccountRepositoryInterface $repository;
/** @var AccountRepositoryInterface The account repository */
private $repository;
/** /**
* CreateController constructor. * CreateController constructor.

View File

@ -58,7 +58,7 @@ class AvailableBudgetController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('title', (string) trans('firefly.budgets')); app('view')->share('title', (string)trans('firefly.budgets'));
app('view')->share('mainTitleIcon', 'fa-pie-chart'); app('view')->share('mainTitleIcon', 'fa-pie-chart');
$this->abRepository = app(AvailableBudgetRepositoryInterface::class); $this->abRepository = app(AvailableBudgetRepositoryInterface::class);
$this->currencyRepos = app(CurrencyRepositoryInterface::class); $this->currencyRepos = app(CurrencyRepositoryInterface::class);
@ -95,7 +95,7 @@ class AvailableBudgetController extends Controller
return redirect(route('available-budgets.edit', [$first->id])); return redirect(route('available-budgets.edit', [$first->id]));
} }
$page = (int) ($request->get('page') ?? 1); $page = (int)($request->get('page') ?? 1);
return prefixView('budgets.available-budgets.create', compact('start', 'end', 'page', 'currency')); return prefixView('budgets.available-budgets.create', compact('start', 'end', 'page', 'currency'));
} }
@ -129,7 +129,7 @@ class AvailableBudgetController extends Controller
); );
$page = (int) ($request->get('page') ?? 1); $page = (int)($request->get('page') ?? 1);
return prefixView('budgets.available-budgets.create-alternative', compact('start', 'end', 'page', 'currencies')); return prefixView('budgets.available-budgets.create-alternative', compact('start', 'end', 'page', 'currencies'));
} }
@ -157,7 +157,8 @@ class AvailableBudgetController extends Controller
*/ */
public function edit(AvailableBudget $availableBudget, Carbon $start, Carbon $end) public function edit(AvailableBudget $availableBudget, Carbon $start, Carbon $end)
{ {
$availableBudget->amount = number_format((float) $availableBudget->amount, $availableBudget->transactionCurrency->decimal_places, '.', ''); $availableBudget->amount = number_format((float)$availableBudget->amount, $availableBudget->transactionCurrency->decimal_places, '.', '');
return prefixView('budgets.available-budgets.edit', compact('availableBudget', 'start', 'end')); return prefixView('budgets.available-budgets.edit', compact('availableBudget', 'start', 'end'));
} }
@ -179,7 +180,7 @@ class AvailableBudgetController extends Controller
} }
// validate amount // validate amount
$amount = (string) $request->get('amount'); $amount = (string)$request->get('amount');
if ('' === $amount) { if ('' === $amount) {
session()->flash('error', trans('firefly.invalid_amount')); session()->flash('error', trans('firefly.invalid_amount'));
@ -192,7 +193,7 @@ class AvailableBudgetController extends Controller
} }
// find currency // find currency
$currency = $this->currencyRepos->find((int) $request->get('currency_id')); $currency = $this->currencyRepos->find((int)$request->get('currency_id'));
if (null === $currency) { if (null === $currency) {
session()->flash('error', trans('firefly.invalid_currency')); session()->flash('error', trans('firefly.invalid_currency'));
@ -205,10 +206,10 @@ class AvailableBudgetController extends Controller
if (null === $existing) { if (null === $existing) {
$this->abRepository->store( $this->abRepository->store(
[ [
'amount' => $amount, 'amount' => $amount,
'currency' => $currency, 'currency_id' => $currency->id,
'start' => $start, 'start' => $start,
'end' => $end, 'end' => $end,
] ]
); );
} }
@ -233,7 +234,7 @@ class AvailableBudgetController extends Controller
public function update(Request $request, AvailableBudget $availableBudget, Carbon $start, Carbon $end) public function update(Request $request, AvailableBudget $availableBudget, Carbon $start, Carbon $end)
{ {
// validate amount // validate amount
$amount = (string) $request->get('amount'); $amount = (string)$request->get('amount');
if ('' === $amount) { if ('' === $amount) {
session()->flash('error', trans('firefly.invalid_amount')); session()->flash('error', trans('firefly.invalid_amount'));

View File

@ -41,17 +41,17 @@ class BillStoreRequest extends FormRequest
public function getBillData(): array public function getBillData(): array
{ {
return [ return [
'name' => $this->string('name'), 'name' => $this->string('name'),
'amount_min' => $this->string('amount_min'), 'amount_min' => $this->string('amount_min'),
'currency_id' => $this->integer('transaction_currency_id'), 'currency_id' => $this->integer('transaction_currency_id'),
'currency_code' => '', 'currency_code' => '',
'amount_max' => $this->string('amount_max'), 'amount_max' => $this->string('amount_max'),
'date' => $this->date('date'), 'date' => $this->date('date'),
'repeat_freq' => $this->string('repeat_freq'), 'repeat_freq' => $this->string('repeat_freq'),
'skip' => $this->integer('skip'), 'skip' => $this->integer('skip'),
'notes' => $this->nlString('notes'), 'notes' => $this->nlString('notes'),
'active' => $this->boolean('active'), 'active' => $this->boolean('active'),
'object_group' => $this->string('object_group'), 'object_group_title' => $this->string('object_group'),
]; ];
} }

View File

@ -42,17 +42,17 @@ class BillUpdateRequest extends FormRequest
public function getBillData(): array public function getBillData(): array
{ {
return [ return [
'name' => $this->string('name'), 'name' => $this->string('name'),
'amount_min' => $this->string('amount_min'), 'amount_min' => $this->string('amount_min'),
'currency_id' => $this->integer('transaction_currency_id'), 'currency_id' => $this->integer('transaction_currency_id'),
'currency_code' => '', 'currency_code' => '',
'amount_max' => $this->string('amount_max'), 'amount_max' => $this->string('amount_max'),
'date' => $this->date('date'), 'date' => $this->date('date'),
'repeat_freq' => $this->string('repeat_freq'), 'repeat_freq' => $this->string('repeat_freq'),
'skip' => $this->integer('skip'), 'skip' => $this->integer('skip'),
'notes' => $this->nlString('notes'), 'notes' => $this->nlString('notes'),
'active' => $this->boolean('active'), 'active' => $this->boolean('active'),
'object_group' => $this->string('object_group'), 'object_group_title' => $this->string('object_group'),
]; ];
} }

View File

@ -44,12 +44,12 @@ class BudgetFormStoreRequest extends FormRequest
public function getBudgetData(): array public function getBudgetData(): array
{ {
return [ return [
'name' => $this->string('name'), 'name' => $this->string('name'),
'active' => $this->boolean('active'), 'active' => $this->boolean('active'),
'auto_budget_type' => $this->integer('auto_budget_type'), 'auto_budget_type' => $this->integer('auto_budget_type'),
'transaction_currency_id' => $this->integer('auto_budget_currency_id'), 'currency_id' => $this->integer('auto_budget_currency_id'),
'auto_budget_amount' => $this->string('auto_budget_amount'), 'auto_budget_amount' => $this->string('auto_budget_amount'),
'auto_budget_period' => $this->string('auto_budget_period'), 'auto_budget_period' => $this->string('auto_budget_period'),
]; ];
} }

View File

@ -45,12 +45,12 @@ class BudgetFormUpdateRequest extends FormRequest
public function getBudgetData(): array public function getBudgetData(): array
{ {
return [ return [
'name' => $this->string('name'), 'name' => $this->string('name'),
'active' => $this->boolean('active'), 'active' => $this->boolean('active'),
'auto_budget_type' => $this->integer('auto_budget_type'), 'auto_budget_type' => $this->integer('auto_budget_type'),
'transaction_currency_id' => $this->integer('auto_budget_currency_id'), 'currency_id' => $this->integer('auto_budget_currency_id'),
'auto_budget_amount' => $this->string('auto_budget_amount'), 'auto_budget_amount' => $this->string('auto_budget_amount'),
'auto_budget_period' => $this->string('auto_budget_period'), 'auto_budget_period' => $this->string('auto_budget_period'),
]; ];
} }

View File

@ -47,7 +47,7 @@ class PiggyBankStoreRequest extends FormRequest
'targetamount' => $this->string('targetamount'), 'targetamount' => $this->string('targetamount'),
'targetdate' => $this->date('targetdate'), 'targetdate' => $this->date('targetdate'),
'notes' => $this->nlString('notes'), 'notes' => $this->nlString('notes'),
'object_group' => $this->string('object_group'), 'object_group_title' => $this->string('object_group'),
]; ];
} }

View File

@ -42,13 +42,13 @@ class PiggyBankUpdateRequest extends FormRequest
public function getPiggyBankData(): array public function getPiggyBankData(): array
{ {
return [ return [
'name' => $this->string('name'), 'name' => $this->string('name'),
'startdate' => $this->date('startdate'), 'startdate' => $this->date('startdate'),
'account_id' => $this->integer('account_id'), 'account_id' => $this->integer('account_id'),
'targetamount' => $this->string('targetamount'), 'targetamount' => $this->string('targetamount'),
'targetdate' => $this->date('targetdate'), 'targetdate' => $this->date('targetdate'),
'notes' => $this->nlString('notes'), 'notes' => $this->nlString('notes'),
'object_group' => $this->string('object_group'), 'object_group_title' => $this->string('object_group'),
]; ];
} }

View File

@ -335,6 +335,9 @@ class BudgetRepository implements BudgetRepositoryInterface
if ('none' === $type) { if ('none' === $type) {
return $newBudget; return $newBudget;
} }
if (0 === $type) {
return $newBudget;
}
if ('reset' === $type) { if ('reset' === $type) {
$type = AutoBudget::AUTO_BUDGET_RESET; $type = AutoBudget::AUTO_BUDGET_RESET;
@ -343,7 +346,8 @@ class BudgetRepository implements BudgetRepositoryInterface
$type = AutoBudget::AUTO_BUDGET_ROLLOVER; $type = AutoBudget::AUTO_BUDGET_ROLLOVER;
} }
$repos = app(CurrencyRepositoryInterface::class); $repos = app(CurrencyRepositoryInterface::class);
$currency = null;
if (array_key_exists('currency_id', $data)) { if (array_key_exists('currency_id', $data)) {
$currency = $repos->findNull((int)$data['currency_id']); $currency = $repos->findNull((int)$data['currency_id']);
} }
@ -420,6 +424,7 @@ class BudgetRepository implements BudgetRepositoryInterface
if (null === $autoBudget if (null === $autoBudget
&& array_key_exists('auto_budget_type', $data) && array_key_exists('auto_budget_type', $data)
&& array_key_exists('auto_budget_amount', $data) && array_key_exists('auto_budget_amount', $data)
&& 0 !== $data['auto_budget_type']
) { ) {
// only create if all are here: // only create if all are here:
$autoBudget = new AutoBudget; $autoBudget = new AutoBudget;
@ -428,7 +433,7 @@ class BudgetRepository implements BudgetRepositoryInterface
} }
// update existing type // update existing type
if (array_key_exists('auto_budget_type', $data)) { if (array_key_exists('auto_budget_type', $data) && 0 !== $data['auto_budget_type']) {
$autoBudgetType = $data['auto_budget_type']; $autoBudgetType = $data['auto_budget_type'];
if ('reset' === $autoBudgetType) { if ('reset' === $autoBudgetType) {
$autoBudget->auto_budget_type = AutoBudget::AUTO_BUDGET_RESET; $autoBudget->auto_budget_type = AutoBudget::AUTO_BUDGET_RESET;
@ -442,10 +447,10 @@ class BudgetRepository implements BudgetRepositoryInterface
return $budget; return $budget;
} }
} }
if (array_key_exists('auto_budget_amount', $data)) { if (array_key_exists('auto_budget_amount', $data) && null !== $autoBudget) {
$autoBudget->amount = $data['auto_budget_amount']; $autoBudget->amount = $data['auto_budget_amount'];
} }
if (array_key_exists('auto_budget_period', $data)) { if (array_key_exists('auto_budget_period', $data) && null !== $autoBudget) {
$autoBudget->period = $data['auto_budget_period']; $autoBudget->period = $data['auto_budget_period'];
} }
if (null !== $autoBudget) { if (null !== $autoBudget) {

View File

@ -258,29 +258,6 @@ class RuleRepository implements RuleRepositoryInterface
return $filtered; return $filtered;
} }
/**
* @param Rule $rule
*
* @return bool
*/
public function moveDown(Rule $rule): bool
{
$order = $rule->order;
// find the rule with order+1 and give it order-1
$other = $rule->ruleGroup->rules()->where('order', $order + 1)->first();
if ($other) {
--$other->order;
$other->save();
}
++$rule->order;
$rule->save();
$this->resetRuleOrder($rule->ruleGroup);
return true;
}
/** /**
* @inheritDoc * @inheritDoc
*/ */
@ -295,29 +272,6 @@ class RuleRepository implements RuleRepositoryInterface
return $rule; return $rule;
} }
/**
* @param Rule $rule
*
* @return bool
*/
public function moveUp(Rule $rule): bool
{
$order = $rule->order;
// find the rule with order-1 and give it order+1
$other = $rule->ruleGroup->rules()->where('order', $order - 1)->first();
if ($other) {
++$other->order;
$other->save();
}
--$rule->order;
$rule->save();
$this->resetRuleOrder($rule->ruleGroup);
return true;
}
/** /**
* @param Rule $rule * @param Rule $rule
* @param array $ids * @param array $ids

View File

@ -123,13 +123,6 @@ interface RuleRepositoryInterface
*/ */
public function getUpdateRules(): Collection; public function getUpdateRules(): Collection;
/**
* @param Rule $rule
*
* @return bool
*/
public function moveDown(Rule $rule): bool;
/** /**
* @param Rule $rule * @param Rule $rule
* @param RuleGroup $ruleGroup * @param RuleGroup $ruleGroup
@ -139,13 +132,6 @@ interface RuleRepositoryInterface
*/ */
public function moveRule(Rule $rule, RuleGroup $ruleGroup, int $order): Rule; public function moveRule(Rule $rule, RuleGroup $ruleGroup, int $order): Rule;
/**
* @param Rule $rule
*
* @return bool
*/
public function moveUp(Rule $rule): bool;
/** /**
* @param Rule $rule * @param Rule $rule
* @param array $ids * @param array $ids

View File

@ -277,52 +277,6 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
return (int)$this->user->ruleGroups()->max('order'); return (int)$this->user->ruleGroups()->max('order');
} }
/**
* @param RuleGroup $ruleGroup
*
* @return bool
*/
public function moveDown(RuleGroup $ruleGroup): bool
{
$order = $ruleGroup->order;
// find the rule with order+1 and give it order-1
$other = $this->user->ruleGroups()->where('order', $order + 1)->first();
if ($other) {
--$other->order;
$other->save();
}
++$ruleGroup->order;
$ruleGroup->save();
$this->resetRuleGroupOrder();
return true;
}
/**
* @param RuleGroup $ruleGroup
*
* @return bool
*/
public function moveUp(RuleGroup $ruleGroup): bool
{
$order = $ruleGroup->order;
// find the rule with order-1 and give it order+1
$other = $this->user->ruleGroups()->where('order', $order - 1)->first();
if ($other) {
++$other->order;
$other->save();
}
--$ruleGroup->order;
$ruleGroup->save();
$this->resetRuleGroupOrder();
return true;
}
/** /**
* @return bool * @return bool
*/ */

View File

@ -128,20 +128,6 @@ interface RuleGroupRepositoryInterface
*/ */
public function maxOrder(): int; public function maxOrder(): int;
/**
* @param RuleGroup $ruleGroup
*
* @return bool
*/
public function moveDown(RuleGroup $ruleGroup): bool;
/**
* @param RuleGroup $ruleGroup
*
* @return bool
*/
public function moveUp(RuleGroup $ruleGroup): bool;
/** /**
* @return bool * @return bool
*/ */

View File

@ -155,16 +155,39 @@ trait AppendsLocationData
*/ */
private function isValidPOST(?string $prefix): bool private function isValidPOST(?string $prefix): bool
{ {
$longitudeKey = $this->getLocationKey($prefix, 'longitude'); Log::debug('Now in isValidPOST()');
$latitudeKey = $this->getLocationKey($prefix, 'latitude'); $longitudeKey = $this->getLocationKey($prefix, 'longitude');
$zoomLevelKey = $this->getLocationKey($prefix, 'zoom_level'); $latitudeKey = $this->getLocationKey($prefix, 'latitude');
$zoomLevelKey = $this->getLocationKey($prefix, 'zoom_level');
$hasLocationKey = $this->getLocationKey($prefix, 'has_location');
// fields must not be null:
if (null !== $this->get($longitudeKey) && null !== $this->get($latitudeKey) && null !== $this->get($zoomLevelKey)) {
Log::debug('All fields present');
// if is POST and route contains API, this is enough:
if ('POST' === $this->method() && $this->routeIs('*.store') && $this->routeIs('api.v1.*')) {
Log::debug('Is API location');
return ('POST' === $this->method() && $this->routeIs('*.store')) return true;
&& ( }
null !== $this->get($longitudeKey) // if is POST and route does not contain API, must also have "store_location" = true
&& null !== $this->get($latitudeKey) if ('POST' === $this->method() && $this->routeIs('*.store') && !$this->routeIs('api.v1.*') && $hasLocationKey) {
&& null !== $this->get($zoomLevelKey) $hasLocation = $this->boolean($hasLocationKey);
); if (true === $hasLocation) {
Log::debug('Is form location');
return true;
}
Log::debug('Is not form location');
return false;
}
Log::debug('Is not POST API or POST form');
return false;
}
Log::debug('Fields not present');
return false;
} }
/** /**

View File

@ -44,7 +44,6 @@
{% if piggy.attachments.count() > 0 %} {% if piggy.attachments.count() > 0 %}
<i class="fa fa-fw fa-paperclip"></i> <i class="fa fa-fw fa-paperclip"></i>
{% endif %} {% endif %}
</td> </td>
<td style="text-align: right;" class="piggySaved"> <td style="text-align: right;" class="piggySaved">
<span title="Saved so far" <span title="Saved so far"

View File

@ -130,7 +130,9 @@
<ul> <ul>
{% for rep in rt.repetitions %} {% for rep in rt.repetitions %}
{% for occ in rep.occurrences %} {% for occ in rep.occurrences %}
{% if loop.index0 < 2 %}
<li>{{ occ.formatLocalized(monthAndDayFormat) }}</li> <li>{{ occ.formatLocalized(monthAndDayFormat) }}</li>
{% endif %}
{% endfor %} {% endfor %}
{% endfor %} {% endfor %}
</ul> </ul>