mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Removed duplicate code.
This commit is contained in:
@@ -64,6 +64,7 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
|
|||||||
$categorySummary = $this->getCategorySummary();
|
$categorySummary = $this->getCategorySummary();
|
||||||
$averageExpenses = $this->getAverageExpenses();
|
$averageExpenses = $this->getAverageExpenses();
|
||||||
|
|
||||||
|
|
||||||
// render!
|
// render!
|
||||||
return view('reports.category.month', compact('accountIds', 'categoryIds', 'reportType', 'accountSummary', 'categorySummary','averageExpenses'))
|
return view('reports.category.month', compact('accountIds', 'categoryIds', 'reportType', 'accountSummary', 'categorySummary','averageExpenses'))
|
||||||
->with('start', $this->start)->with('end', $this->end)
|
->with('start', $this->start)->with('end', $this->end)
|
||||||
|
|||||||
@@ -108,41 +108,12 @@ class AccountController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function frontpage(AccountRepositoryInterface $repository)
|
public function frontpage(AccountRepositoryInterface $repository)
|
||||||
{
|
{
|
||||||
$start = clone session('start', Carbon::now()->startOfMonth());
|
$start = clone session('start', Carbon::now()->startOfMonth());
|
||||||
$end = clone session('end', Carbon::now()->endOfMonth());
|
$end = clone session('end', Carbon::now()->endOfMonth());
|
||||||
|
|
||||||
|
|
||||||
// chart properties for cache:
|
|
||||||
$cache = new CacheProperties;
|
|
||||||
$cache->addProperty($start);
|
|
||||||
$cache->addProperty($end);
|
|
||||||
$cache->addProperty('frontpage');
|
|
||||||
$cache->addProperty('accounts');
|
|
||||||
if ($cache->has()) {
|
|
||||||
return Response::json($cache->get());
|
|
||||||
}
|
|
||||||
|
|
||||||
$frontPage = Preferences::get('frontPageAccounts', $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])->pluck('id')->toArray());
|
$frontPage = Preferences::get('frontPageAccounts', $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])->pluck('id')->toArray());
|
||||||
$accounts = $repository->getAccountsById($frontPage->data);
|
$accounts = $repository->getAccountsById($frontPage->data);
|
||||||
|
|
||||||
foreach ($accounts as $account) {
|
return Response::json($this->accountBalanceChart($start, $end, $accounts));
|
||||||
$balances = [];
|
|
||||||
$current = clone $start;
|
|
||||||
$range = Steam::balanceInRange($account, $start, clone $end);
|
|
||||||
$previous = round(array_values($range)[0], 2);
|
|
||||||
while ($current <= $end) {
|
|
||||||
$format = $current->format('Y-m-d');
|
|
||||||
$balance = isset($range[$format]) ? round($range[$format], 2) : $previous;
|
|
||||||
$previous = $balance;
|
|
||||||
$balances[] = $balance;
|
|
||||||
$current->addDay();
|
|
||||||
}
|
|
||||||
$account->balances = $balances;
|
|
||||||
}
|
|
||||||
$data = $this->generator->frontpage($accounts, $start, $end);
|
|
||||||
$cache->store($data);
|
|
||||||
|
|
||||||
return Response::json($data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -156,38 +127,7 @@ class AccountController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function report(Carbon $start, Carbon $end, Collection $accounts)
|
public function report(Carbon $start, Carbon $end, Collection $accounts)
|
||||||
{
|
{
|
||||||
// chart properties for cache:
|
return Response::json($this->accountBalanceChart($start, $end, $accounts));
|
||||||
$cache = new CacheProperties();
|
|
||||||
$cache->addProperty($start);
|
|
||||||
$cache->addProperty($end);
|
|
||||||
$cache->addProperty('all');
|
|
||||||
$cache->addProperty('accounts');
|
|
||||||
$cache->addProperty('default');
|
|
||||||
$cache->addProperty($accounts);
|
|
||||||
if ($cache->has()) {
|
|
||||||
return Response::json($cache->get());
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($accounts as $account) {
|
|
||||||
$balances = [];
|
|
||||||
$current = clone $start;
|
|
||||||
$range = Steam::balanceInRange($account, $start, clone $end);
|
|
||||||
$previous = round(array_values($range)[0], 2);
|
|
||||||
while ($current <= $end) {
|
|
||||||
$format = $current->format('Y-m-d');
|
|
||||||
$balance = isset($range[$format]) ? round($range[$format], 2) : $previous;
|
|
||||||
$previous = $balance;
|
|
||||||
$balances[] = $balance;
|
|
||||||
$current->addDay();
|
|
||||||
}
|
|
||||||
$account->balances = $balances;
|
|
||||||
}
|
|
||||||
|
|
||||||
// make chart:
|
|
||||||
$data = $this->generator->frontpage($accounts, $start, $end);
|
|
||||||
$cache->store($data);
|
|
||||||
|
|
||||||
return Response::json($data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -340,4 +280,43 @@ class AccountController extends Controller
|
|||||||
return Response::json($data);
|
return Response::json($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Carbon $start
|
||||||
|
* @param Carbon $end
|
||||||
|
* @param Collection $accounts
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function accountBalanceChart(Carbon $start, Carbon $end, Collection $accounts): array
|
||||||
|
{
|
||||||
|
// chart properties for cache:
|
||||||
|
$cache = new CacheProperties();
|
||||||
|
$cache->addProperty($start);
|
||||||
|
$cache->addProperty($end);
|
||||||
|
$cache->addProperty('account-balance-chart');
|
||||||
|
$cache->addProperty($accounts);
|
||||||
|
if ($cache->has()) {
|
||||||
|
return $cache->get();
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($accounts as $account) {
|
||||||
|
$balances = [];
|
||||||
|
$current = clone $start;
|
||||||
|
$range = Steam::balanceInRange($account, $start, clone $end);
|
||||||
|
$previous = round(array_values($range)[0], 2);
|
||||||
|
while ($current <= $end) {
|
||||||
|
$format = $current->format('Y-m-d');
|
||||||
|
$balance = isset($range[$format]) ? round($range[$format], 2) : $previous;
|
||||||
|
$previous = $balance;
|
||||||
|
$balances[] = $balance;
|
||||||
|
$current->addDay();
|
||||||
|
}
|
||||||
|
$account->balances = $balances;
|
||||||
|
}
|
||||||
|
$data = $this->generator->frontpage($accounts, $start, $end);
|
||||||
|
$cache->store($data);
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user