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;
/** @var AttachmentHelperInterface Helper for attachments. */
private $attachments;
/** @var AccountRepositoryInterface The account repository */
private $repository;
private AttachmentHelperInterface $attachments;
private AccountRepositoryInterface $repository;
/**
* CreateController constructor.

View File

@ -58,7 +58,7 @@ class AvailableBudgetController extends Controller
$this->middleware(
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');
$this->abRepository = app(AvailableBudgetRepositoryInterface::class);
$this->currencyRepos = app(CurrencyRepositoryInterface::class);
@ -95,7 +95,7 @@ class AvailableBudgetController extends Controller
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'));
}
@ -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'));
}
@ -157,7 +157,8 @@ class AvailableBudgetController extends Controller
*/
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'));
}
@ -179,7 +180,7 @@ class AvailableBudgetController extends Controller
}
// validate amount
$amount = (string) $request->get('amount');
$amount = (string)$request->get('amount');
if ('' === $amount) {
session()->flash('error', trans('firefly.invalid_amount'));
@ -192,7 +193,7 @@ class AvailableBudgetController extends Controller
}
// find currency
$currency = $this->currencyRepos->find((int) $request->get('currency_id'));
$currency = $this->currencyRepos->find((int)$request->get('currency_id'));
if (null === $currency) {
session()->flash('error', trans('firefly.invalid_currency'));
@ -205,10 +206,10 @@ class AvailableBudgetController extends Controller
if (null === $existing) {
$this->abRepository->store(
[
'amount' => $amount,
'currency' => $currency,
'start' => $start,
'end' => $end,
'amount' => $amount,
'currency_id' => $currency->id,
'start' => $start,
'end' => $end,
]
);
}
@ -233,7 +234,7 @@ class AvailableBudgetController extends Controller
public function update(Request $request, AvailableBudget $availableBudget, Carbon $start, Carbon $end)
{
// validate amount
$amount = (string) $request->get('amount');
$amount = (string)$request->get('amount');
if ('' === $amount) {
session()->flash('error', trans('firefly.invalid_amount'));

View File

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

View File

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

View File

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

View File

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

View File

@ -47,7 +47,7 @@ class PiggyBankStoreRequest extends FormRequest
'targetamount' => $this->string('targetamount'),
'targetdate' => $this->date('targetdate'),
'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
{
return [
'name' => $this->string('name'),
'startdate' => $this->date('startdate'),
'account_id' => $this->integer('account_id'),
'targetamount' => $this->string('targetamount'),
'targetdate' => $this->date('targetdate'),
'notes' => $this->nlString('notes'),
'object_group' => $this->string('object_group'),
'name' => $this->string('name'),
'startdate' => $this->date('startdate'),
'account_id' => $this->integer('account_id'),
'targetamount' => $this->string('targetamount'),
'targetdate' => $this->date('targetdate'),
'notes' => $this->nlString('notes'),
'object_group_title' => $this->string('object_group'),
];
}

View File

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

View File

@ -258,29 +258,6 @@ class RuleRepository implements RuleRepositoryInterface
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
*/
@ -295,29 +272,6 @@ class RuleRepository implements RuleRepositoryInterface
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 array $ids

View File

@ -123,13 +123,6 @@ interface RuleRepositoryInterface
*/
public function getUpdateRules(): Collection;
/**
* @param Rule $rule
*
* @return bool
*/
public function moveDown(Rule $rule): bool;
/**
* @param Rule $rule
* @param RuleGroup $ruleGroup
@ -139,13 +132,6 @@ interface RuleRepositoryInterface
*/
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 array $ids

View File

@ -277,52 +277,6 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
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
*/

View File

@ -128,20 +128,6 @@ interface RuleGroupRepositoryInterface
*/
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
*/

View File

@ -155,16 +155,39 @@ trait AppendsLocationData
*/
private function isValidPOST(?string $prefix): bool
{
$longitudeKey = $this->getLocationKey($prefix, 'longitude');
$latitudeKey = $this->getLocationKey($prefix, 'latitude');
$zoomLevelKey = $this->getLocationKey($prefix, 'zoom_level');
Log::debug('Now in isValidPOST()');
$longitudeKey = $this->getLocationKey($prefix, 'longitude');
$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'))
&& (
null !== $this->get($longitudeKey)
&& null !== $this->get($latitudeKey)
&& null !== $this->get($zoomLevelKey)
);
return true;
}
// if is POST and route does not contain API, must also have "store_location" = true
if ('POST' === $this->method() && $this->routeIs('*.store') && !$this->routeIs('api.v1.*') && $hasLocationKey) {
$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 %}
<i class="fa fa-fw fa-paperclip"></i>
{% endif %}
</td>
<td style="text-align: right;" class="piggySaved">
<span title="Saved so far"

View File

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