diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.php index 37ecfaeee4..8b3b4d4795 100644 --- a/app/controllers/AccountController.php +++ b/app/controllers/AccountController.php @@ -110,113 +110,6 @@ class AccountController extends BaseController return Response::jsoN($return); } - /** - * @param $account - * - * @return \Illuminate\View\View - */ - public function sankeyOut($account) - { - - /* - * Get the stuff. - */ - $start = Session::get('start'); - $end = Session::get('end'); - $query = \TransactionJournal::withRelevantData() - ->defaultSorting() - ->accountIs($account) - ->after($start) - ->before($end); - $set = $query->get(['transaction_journals.*']); - /* - * Arrays we need: - */ - $collection = []; - $filtered = []; - $result = []; - /** @var \TransactionJournal $entry */ - foreach ($set as $entry) { - switch ($entry->transactionType->type) { - case 'Withdrawal': - /** @var Budget $budget */ - $budget = isset($entry->budgets[0]) ? $entry->budgets[0] : null; - $from = $entry->transactions[0]->account->name; - $amount = floatval($entry->transactions[1]->amount); - if ($budget) { - $to = $budget->name; - } else { - $to = '(no budget)'; - } - $collection[] = [$from, $to, $amount]; - - // also make one for the budget: - $from = $to; - $category = $entry->categories()->first(); - if ($category) { - $to = ' ' . $category->name; - } else { - $to = '(no category)'; - } - $collection[] = [$from, $to, $amount]; - break; - } - } - - /* - * To break "cycles", aka money going back AND forth Firefly searches for previously existing - * key sets (in reversed order) and if we find them, fix it. - * - * If the from-to amount found is larger than the amount going back, the amount going back - * is removed and substracted from the current amount. - * - * If the from-to amount found is less than the amount going back, the entry is ignored - * but substracted from the amount going back. - */ - foreach ($collection as $current) { - list($from, $to, $amount) = $current; - $key = $from . $to; - $reversed = $to . $from; - if (!isset($result[$reversed])) { - if (isset($result[$key])) { - $filtered[$key]['amount'] += $amount; - } else { - $filtered[$key] = ['from' => $from, 'to' => $to, 'amount' => $amount]; - } - } else { - /* - * If there is one, see which one will make it: - */ - $otherAmount = $result[$reversed]['amount']; - if ($amount >= $otherAmount) { - unset($result[$reversed]); - $amount = $amount - $otherAmount; - // set: - if (isset($result[$key])) { - $filtered[$key]['amount'] += $amount; - } else { - $filtered[$key] = ['from' => $from, 'to' => $to, 'amount' => $amount]; - } - } else { - $filtered[$reversed]['amount'] -= $amount; - } - } - - } - /* - * Take out the keys: - */ - foreach ($filtered as $key => $entry) { - $result[] = [$entry['from'],$entry['to'],$entry['amount']]; - } - - - /* - * Loop it again to add the amounts. - */ - return Response::json($result); - } - /** * @return \Illuminate\View\View diff --git a/app/routes.php b/app/routes.php index 52d8c728e9..22d86fa854 100644 --- a/app/routes.php +++ b/app/routes.php @@ -142,7 +142,6 @@ Route::group(['before' => 'auth'], function () { Route::get('/accounts/edit/{account}',['uses' => 'AccountController@edit','as' => 'accounts.edit']); Route::get('/accounts/delete/{account}',['uses' => 'AccountController@delete','as' => 'accounts.delete']); Route::get('/accounts/show/{account}',['uses' => 'AccountController@show','as' => 'accounts.show']); - Route::get('/accounts/sankey/{account}/out',['uses' => 'AccountController@sankeyOut','as' => 'accounts.sankey.out']); // budget controller: Route::get('/budgets/date',['uses' => 'BudgetController@indexByDate','as' => 'budgets.index.date']);