diff --git a/app/Http/Controllers/Json/BoxController.php b/app/Http/Controllers/Json/BoxController.php index 6fcd63bab4..20b45bee97 100644 --- a/app/Http/Controllers/Json/BoxController.php +++ b/app/Http/Controllers/Json/BoxController.php @@ -215,47 +215,6 @@ class BoxController extends Controller return response()->json($response); } - - /** - * Bills to pay and paid. - * - * @param BillRepositoryInterface $repository - * - * @return JsonResponse - */ - public function bills(BillRepositoryInterface $repository): JsonResponse - { - /** @var Carbon $start */ - $start = session('start', Carbon::now()->startOfMonth()); - /** @var Carbon $end */ - $end = session('end', Carbon::now()->endOfMonth()); - - $cache = new CacheProperties; - $cache->addProperty($start); - $cache->addProperty($end); - $cache->addProperty('box-bills'); - if ($cache->has()) { - return response()->json($cache->get()); // @codeCoverageIgnore - } - - /* - * Since both this method and the chart use the exact same data, we can suffice - * with calling the one method in the bill repository that will get this amount. - */ - $paidAmount = bcmul($repository->getBillsPaidInRange($start, $end), '-1'); - $unpaidAmount = $repository->getBillsUnpaidInRange($start, $end); // will be a positive amount. - $currency = app('amount')->getDefaultCurrency(); - - $return = [ - 'paid' => app('amount')->formatAnything($currency, $paidAmount, false), - 'unpaid' => app('amount')->formatAnything($currency, $unpaidAmount, false), - ]; - $cache->store($return); - - return response()->json($return); - } - - /** * Total user net worth. * diff --git a/public/v1/js/ff/index.js b/public/v1/js/ff/index.js index d2d2b5e68f..ae25ffe5f3 100644 --- a/public/v1/js/ff/index.js +++ b/public/v1/js/ff/index.js @@ -83,11 +83,11 @@ function getAvailableBox() { $('#box-left-to-spend').html(data.left_to_spend); $('#box-left-per-day').html(data.left_per_day); } - if(1=== data.display) { + if (1 === data.display) { $('#box-left-to-spend').html(data.left_to_spend); $('#box-left-per-day').html(data.left_per_day); } - if(2=== data.display) { + if (2 === data.display) { $('#box-left-to-spend').html(data.spent_total); $('#box-left-per-day').html(data.spent_per_day); } @@ -100,9 +100,31 @@ function getAvailableBox() { function getBillsBox() { // box-bills-unpaid // box-bills-paid - $.getJSON('json/box/bills').done(function (data) { - $('#box-bills-paid').html(data.paid); - $('#box-bills-unpaid').html(data.unpaid); + + // get summary. + + $.getJSON('api/v1/summary/basic?start=' + sessionStart + '&end=' + sessionEnd).done(function (data) { + var key; + var unpaid = []; + var paid = []; + for (key in data) { + var row = data[key]; + //console.log(key); + if (key.substr(0, 16) === 'bills-unpaid-in-') { + // only when less than 3. + if (unpaid.length < 3) { + unpaid.push(data[key].value_parsed); + } + } + if (key.substr(0, 14) === 'bills-paid-in-') { + // only when less than 5. + if (paid.length < 3) { + paid.push(data[key].value_parsed); + } + } + } + $('#box-bills-unpaid').html(unpaid.join(', ')); + $('#box-bills-paid').html(paid.join(', ')); }); } diff --git a/routes/web.php b/routes/web.php index 2187bc2a54..1b43fd4337 100644 --- a/routes/web.php +++ b/routes/web.php @@ -617,7 +617,6 @@ Route::group( // boxes Route::get('box/balance', ['uses' => 'Json\BoxController@balance', 'as' => 'box.balance']); - Route::get('box/bills', ['uses' => 'Json\BoxController@bills', 'as' => 'box.bills']); Route::get('box/available', ['uses' => 'Json\BoxController@available', 'as' => 'box.available']); Route::get('box/net-worth', ['uses' => 'Json\BoxController@netWorth', 'as' => 'box.net-worth']);