mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-13 16:00:13 +00:00
Fixed a small bug in the account frontpage chart.
This commit is contained in:
@@ -234,10 +234,18 @@ 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());
|
||||||
$frontPage = Preferences::get('frontPageAccounts', $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])->pluck('id')->toArray());
|
$defaultSet = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])->pluck('id')->toArray();
|
||||||
$accounts = $repository->getAccountsById($frontPage->data);
|
Log::debug('Default set is ', $defaultSet);
|
||||||
|
$frontPage = Preferences::get('frontPageAccounts', $defaultSet);
|
||||||
|
Log::debug('Frontpage preference set is ', $frontPage->data);
|
||||||
|
if (count($frontPage->data) === 0) {
|
||||||
|
$frontPage->data = $defaultSet;
|
||||||
|
Log::debug('frontpage set is empty!');
|
||||||
|
$frontPage->save();
|
||||||
|
}
|
||||||
|
$accounts = $repository->getAccountsById($frontPage->data);
|
||||||
|
|
||||||
return Response::json($this->accountBalanceChart($accounts, $start, $end));
|
return Response::json($this->accountBalanceChart($accounts, $start, $end));
|
||||||
}
|
}
|
||||||
|
@@ -14,6 +14,7 @@ declare(strict_types = 1);
|
|||||||
namespace FireflyIII\Http\Controllers\Chart;
|
namespace FireflyIII\Http\Controllers\Chart;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
|
||||||
use FireflyIII\Generator\Chart\Bill\BillChartGeneratorInterface;
|
use FireflyIII\Generator\Chart\Bill\BillChartGeneratorInterface;
|
||||||
use FireflyIII\Helpers\Collector\JournalCollector;
|
use FireflyIII\Helpers\Collector\JournalCollector;
|
||||||
use FireflyIII\Http\Controllers\Controller;
|
use FireflyIII\Http\Controllers\Controller;
|
||||||
@@ -54,11 +55,26 @@ class BillController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function frontpage(BillRepositoryInterface $repository)
|
public function frontpage(BillRepositoryInterface $repository)
|
||||||
{
|
{
|
||||||
$start = session('start', Carbon::now()->startOfMonth());
|
$start = session('start', Carbon::now()->startOfMonth());
|
||||||
$end = session('end', Carbon::now()->endOfMonth());
|
$end = session('end', Carbon::now()->endOfMonth());
|
||||||
$paid = $repository->getBillsPaidInRange($start, $end); // will be a negative amount.
|
$cache = new CacheProperties;
|
||||||
$unpaid = $repository->getBillsUnpaidInRange($start, $end); // will be a positive amount.
|
$cache->addProperty($start);
|
||||||
$data = $this->generator->frontpage($paid, $unpaid);
|
$cache->addProperty($end);
|
||||||
|
$cache->addProperty('chart.bill.frontpage');
|
||||||
|
if ($cache->has()) {
|
||||||
|
return Response::json($cache->get());
|
||||||
|
}
|
||||||
|
|
||||||
|
$paid = $repository->getBillsPaidInRange($start, $end); // will be a negative amount.
|
||||||
|
$unpaid = $repository->getBillsUnpaidInRange($start, $end); // will be a positive amount.
|
||||||
|
$chartData = [
|
||||||
|
strval(trans('firefly.unpaid')) => $unpaid,
|
||||||
|
strval(trans('firefly.paid')) => $paid,
|
||||||
|
];
|
||||||
|
|
||||||
|
/** @var GeneratorInterface $generator */
|
||||||
|
$generator = app(GeneratorInterface::class);
|
||||||
|
$data = $generator->pieChart($chartData);
|
||||||
|
|
||||||
return Response::json($data);
|
return Response::json($data);
|
||||||
}
|
}
|
||||||
|
@@ -48,7 +48,7 @@ class Preference extends Model
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return json_decode($data);
|
return json_decode($data, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user