From abf218fc2133ae3a16e7b22bfddfc0885f095cbc Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 17 Jun 2018 07:45:10 +0200 Subject: [PATCH] Prevent empty box. --- app/Http/Controllers/Json/BoxController.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/Http/Controllers/Json/BoxController.php b/app/Http/Controllers/Json/BoxController.php index 27c857d97b..e61c522daf 100644 --- a/app/Http/Controllers/Json/BoxController.php +++ b/app/Http/Controllers/Json/BoxController.php @@ -153,6 +153,12 @@ class BoxController extends Controller $incomes[$currencyId] = Amount::formatAnything($currency, $incomes[$currencyId] ?? '0', false); $expenses[$currencyId] = Amount::formatAnything($currency, $expenses[$currencyId] ?? '0', false); } + if (\count($sums) === 0) { + $currency = app('amount')->getDefaultCurrency(); + $sums[$currency->id] = Amount::formatAnything($currency, '0', false); + $incomes[$currency->id] = Amount::formatAnything($currency, '0', false); + $expenses[$currency->id] = Amount::formatAnything($currency, '0', false); + } $response = [ 'incomes' => $incomes, @@ -161,6 +167,7 @@ class BoxController extends Controller 'size' => \count($sums), ]; + $cache->store($response); return response()->json($response);