Skip to content

Firefly III: a personal finances manager

Fix nullpointers.

James Cole2f9724e7ca51
diff --cc app/Http/Controllers/Budget/BudgetLimitController.php
index c281774a4b,c281774a4b..eaa1ec3c93
--- a/app/Http/Controllers/Budget/BudgetLimitController.php
+++ b/app/Http/Controllers/Budget/BudgetLimitController.php
@@@ -135,16 -135,16 +135,21 @@@ class BudgetLimitController extends Con
if (null === $currency || null === $budget) {
throw new FireflyException('No valid currency or budget.');
}
-- $start = Carbon::createFromFormat('Y-m-d', $request->get('start'));
-- $end = Carbon::createFromFormat('Y-m-d', $request->get('end'));
++ $start = Carbon::createFromFormat('Y-m-d', $request->get('start'));
++ $end = Carbon::createFromFormat('Y-m-d', $request->get('end'));
++ $amount = (string)$request->get('amount');
$start->startOfDay();
$end->startOfDay();
++ if ('' === $amount) {
++ return response()->json([]);
++ }
++
Log::debug(sprintf('Start: %s, end: %s', $start->format('Y-m-d'), $end->format('Y-m-d')));
$limit = $this->blRepository->find($budget, $currency, $start, $end);
if (null !== $limit) {
-- $limit->amount = $request->get('amount');
++ $limit->amount = $amount;
$limit->save();
}
if (null === $limit) {
@@@ -154,7 -154,7 +159,7 @@@
'currency_id' => (int)$request->get('transaction_currency_id'),
'start_date' => $start,
'end_date' => $end,
-- 'amount' => $request->get('amount'),
++ 'amount' => $amount,
]
);
}
@@@ -176,7 -176,7 +181,7 @@@
return response()->json($array);
}
-- return redirect(route('budgets.index', [$start->format('Y-m-d'), $end->format('Y-m-d')]));
++ return response()->json([]);
}
/**
@@@ -187,7 -187,7 +192,10 @@@
*/
public function update(Request $request, BudgetLimit $budgetLimit): JsonResponse
{
-- $amount = $request->get('amount');
++ $amount = (string)$request->get('amount');
++ if ('' === $amount) {
++ $amount = '0';
++ }
$limit = $this->blRepository->update($budgetLimit, ['amount' => $amount]);
$array = $limit->toArray();
diff --cc app/Http/Requests/BudgetFormStoreRequest.php
index 60555fa624,60555fa624..f4a18f21ed
--- a/app/Http/Requests/BudgetFormStoreRequest.php
+++ b/app/Http/Requests/BudgetFormStoreRequest.php
@@@ -65,7 -65,7 +65,7 @@@ class BudgetFormStoreRequest extends Fo
'active' => 'numeric|between:0,1',
'auto_budget_type' => 'numeric|between:0,2',
'auto_budget_currency_id' => 'exists:transaction_currencies,id',
-- 'auto_budget_amount' => 'min:0|max:1000000000',
++ 'auto_budget_amount' => 'min:0|max:1000000000|required_if:auto_budget_type,1|required_if:auto_budget_type,2',
'auto_budget_period' => 'in:daily,weekly,monthly,quarterly,half_year,yearly',
];
}
diff --cc app/Http/Requests/BudgetFormUpdateRequest.php
index a907df9db4,a907df9db4..0e4f63d7fe
--- a/app/Http/Requests/BudgetFormUpdateRequest.php
+++ b/app/Http/Requests/BudgetFormUpdateRequest.php
@@@ -75,7 -75,7 +75,7 @@@ class BudgetFormUpdateRequest extends F
'active' => 'numeric|between:0,1',
'auto_budget_type' => 'numeric|between:0,2',
'auto_budget_currency_id' => 'exists:transaction_currencies,id',
-- 'auto_budget_amount' => 'min:0|max:1000000000',
++ 'auto_budget_amount' => 'min:0|max:1000000000|required_if:auto_budget_type,1|required_if:auto_budget_type,2',
'auto_budget_period' => 'in:daily,weekly,monthly,quarterly,half_year,yearly',
];
}