mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 00:27:30 +00:00
Removed references to sankey.
This commit is contained in:
@@ -110,113 +110,6 @@ class AccountController extends BaseController
|
|||||||
|
|
||||||
return Response::jsoN($return);
|
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
|
* @return \Illuminate\View\View
|
||||||
|
@@ -142,7 +142,6 @@ Route::group(['before' => 'auth'], function () {
|
|||||||
Route::get('/accounts/edit/{account}',['uses' => 'AccountController@edit','as' => 'accounts.edit']);
|
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/delete/{account}',['uses' => 'AccountController@delete','as' => 'accounts.delete']);
|
||||||
Route::get('/accounts/show/{account}',['uses' => 'AccountController@show','as' => 'accounts.show']);
|
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:
|
// budget controller:
|
||||||
Route::get('/budgets/date',['uses' => 'BudgetController@indexByDate','as' => 'budgets.index.date']);
|
Route::get('/budgets/date',['uses' => 'BudgetController@indexByDate','as' => 'budgets.index.date']);
|
||||||
|
Reference in New Issue
Block a user