Fix some charts.

This commit is contained in:
James Cole
2019-08-17 08:00:27 +02:00
parent 6f78735bc5
commit 7f887e294a
8 changed files with 22 additions and 16 deletions

View File

@@ -81,7 +81,7 @@ class CategoryController extends Controller
$cache->addProperty('chart.category.all'); $cache->addProperty('chart.category.all');
$cache->addProperty($category->id); $cache->addProperty($category->id);
if ($cache->has()) { if ($cache->has()) {
//return response()->json($cache->get()); // @codeCoverageIgnore return response()->json($cache->get()); // @codeCoverageIgnore
} }
$start = $repository->firstUseDate($category) ?? $this->getDate(); $start = $repository->firstUseDate($category) ?? $this->getDate();
$range = app('preferences')->get('viewRange', '1M')->data; $range = app('preferences')->get('viewRange', '1M')->data;
@@ -216,7 +216,7 @@ class CategoryController extends Controller
$cache->addProperty($accounts->pluck('id')->toArray()); $cache->addProperty($accounts->pluck('id')->toArray());
$cache->addProperty($category); $cache->addProperty($category);
if ($cache->has()) { if ($cache->has()) {
return response()->json($cache->get());// @codeCoverageIgnore return response()->json($cache->get());// @codeCoverageIgnore
} }
$repository = app(CategoryRepositoryInterface::class); $repository = app(CategoryRepositoryInterface::class);
$expenses = $repository->periodExpenses(new Collection([$category]), $accounts, $start, $end); $expenses = $repository->periodExpenses(new Collection([$category]), $accounts, $start, $end);
@@ -248,7 +248,7 @@ class CategoryController extends Controller
$spent = $expenses[$category->id]['entries'][$period] ?? '0'; $spent = $expenses[$category->id]['entries'][$period] ?? '0';
$earned = $income[$category->id]['entries'][$period] ?? '0'; $earned = $income[$category->id]['entries'][$period] ?? '0';
$sum = bcadd($spent, $earned); $sum = bcadd($spent, $earned);
$chartData[0]['entries'][$label] = round(bcmul($spent, '-1'), 12); $chartData[0]['entries'][$label] = round($spent, 12);
$chartData[1]['entries'][$label] = round($earned, 12); $chartData[1]['entries'][$label] = round($earned, 12);
$chartData[2]['entries'][$label] = round($sum, 12); $chartData[2]['entries'][$label] = round($sum, 12);
} }

View File

@@ -208,7 +208,7 @@ class CategoryReportController extends Controller
$cache->addProperty($start); $cache->addProperty($start);
$cache->addProperty($end); $cache->addProperty($end);
if ($cache->has()) { if ($cache->has()) {
//return response()->json($cache->get()); // @codeCoverageIgnore return response()->json($cache->get()); // @codeCoverageIgnore
} }
$format = app('navigation')->preferredCarbonLocalizedFormat($start, $end); $format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
@@ -262,7 +262,7 @@ class CategoryReportController extends Controller
$labelOut = $category->id . '-out'; $labelOut = $category->id . '-out';
$labelSumIn = $category->id . '-total-in'; $labelSumIn = $category->id . '-total-in';
$labelSumOut = $category->id . '-total-out'; $labelSumOut = $category->id . '-total-out';
$currentIncome = bcmul($income[$category->id] ?? '0','-1'); $currentIncome = $income[$category->id] ?? '0';
$currentExpense = $expenses[$category->id] ?? '0'; $currentExpense = $expenses[$category->id] ?? '0';
// add to sum: // add to sum:

View File

@@ -86,7 +86,7 @@ class ReportController extends Controller
/** @var AccountRepositoryInterface $accountRepository */ /** @var AccountRepositoryInterface $accountRepository */
$accountRepository = app(AccountRepositoryInterface::class); $accountRepository = app(AccountRepositoryInterface::class);
$filtered = $accounts->filter( $filtered = $accounts->filter(
function (Account $account) use ($accountRepository) { static function (Account $account) use ($accountRepository) {
$includeNetWorth = $accountRepository->getMetaValue($account, 'include_net_worth'); $includeNetWorth = $accountRepository->getMetaValue($account, 'include_net_worth');
$result = null === $includeNetWorth ? true : '1' === $includeNetWorth; $result = null === $includeNetWorth ? true : '1' === $includeNetWorth;
if (false === $result) { if (false === $result) {
@@ -97,6 +97,7 @@ class ReportController extends Controller
} }
); );
// TODO get liabilities and include those as well?
while ($current < $end) { while ($current < $end) {
// get balances by date, grouped by currency. // get balances by date, grouped by currency.

View File

@@ -201,7 +201,7 @@ class TagReportController extends Controller
$cache->addProperty($start); $cache->addProperty($start);
$cache->addProperty($end); $cache->addProperty($end);
if ($cache->has()) { if ($cache->has()) {
//return response()->json($cache->get()); // @codeCoverageIgnore return response()->json($cache->get()); // @codeCoverageIgnore
} }
$format = app('navigation')->preferredCarbonLocalizedFormat($start, $end); $format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);

View File

@@ -48,7 +48,7 @@ class BillController extends Controller
$cache->addProperty('bill-report'); $cache->addProperty('bill-report');
$cache->addProperty($accounts->pluck('id')->toArray()); $cache->addProperty($accounts->pluck('id')->toArray());
if ($cache->has()) { if ($cache->has()) {
//return $cache->get(); // @codeCoverageIgnore return $cache->get(); // @codeCoverageIgnore
} }
@@ -57,13 +57,13 @@ class BillController extends Controller
$report = $helper->getBillReport($accounts, $start, $end); $report = $helper->getBillReport($accounts, $start, $end);
// try { try {
$result = view('reports.partials.bills', compact('report'))->render(); $result = view('reports.partials.bills', compact('report'))->render();
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
// } catch (Throwable $e) { } catch (Throwable $e) {
// Log::debug(sprintf('Could not render reports.partials.budgets: %s', $e->getMessage())); Log::debug(sprintf('Could not render reports.partials.budgets: %s', $e->getMessage()));
// $result = 'Could not render view.'; $result = 'Could not render view.';
// } }
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
$cache->store($result); $cache->store($result);

View File

@@ -475,6 +475,7 @@ class CategoryRepository implements CategoryRepositoryInterface
/** /**
* TODO not multi currency aware.
* @param Collection $categories * @param Collection $categories
* @param Collection $accounts * @param Collection $accounts
* @param Carbon $start * @param Carbon $start
@@ -510,7 +511,7 @@ class CategoryRepository implements CategoryRepositoryInterface
foreach ($journals as $journal) { foreach ($journals as $journal) {
$categoryId = (int)$journal['category_id']; $categoryId = (int)$journal['category_id'];
$date = $journal['date']->format($carbonFormat); $date = $journal['date']->format($carbonFormat);
$data[$categoryId]['entries'][$date] = bcadd($data[$categoryId]['entries'][$date] ?? '0', $journal['amount']); $data[$categoryId]['entries'][$date] = bcadd($data[$categoryId]['entries'][$date] ?? '0', bcmul($journal['amount'],'-1'));
} }
return $data; return $data;
@@ -548,7 +549,7 @@ class CategoryRepository implements CategoryRepositoryInterface
if (!isset($result['entries'][$date])) { if (!isset($result['entries'][$date])) {
$result['entries'][$date] = '0'; $result['entries'][$date] = '0';
} }
$result['entries'][$date] = bcadd($result['entries'][$date], $journal['amount']); $result['entries'][$date] = bcadd($result['entries'][$date], bcmul($journal['amount'],'-1'));
} }
Log::debug('Done looping transactions..'); Log::debug('Done looping transactions..');
Log::debug('Finished periodIncomeNoCategory()'); Log::debug('Finished periodIncomeNoCategory()');

View File

@@ -137,6 +137,7 @@ interface CategoryRepositoryInterface
public function lastUseDate(Category $category, Collection $accounts): ?Carbon; public function lastUseDate(Category $category, Collection $accounts): ?Carbon;
/** /**
* TODO not multi-currency
* @param Collection $categories * @param Collection $categories
* @param Collection $accounts * @param Collection $accounts
* @param Carbon $start * @param Carbon $start
@@ -149,6 +150,7 @@ interface CategoryRepositoryInterface
/** /**
* TODO not multi-currency
* @param Collection $accounts * @param Collection $accounts
* @param Carbon $start * @param Carbon $start
* @param Carbon $end * @param Carbon $end
@@ -158,6 +160,7 @@ interface CategoryRepositoryInterface
public function periodExpensesNoCategory(Collection $accounts, Carbon $start, Carbon $end): array; public function periodExpensesNoCategory(Collection $accounts, Carbon $start, Carbon $end): array;
/** /**
* TODO not multi-currency
* @param Collection $categories * @param Collection $categories
* @param Collection $accounts * @param Collection $accounts
* @param Carbon $start * @param Carbon $start
@@ -168,6 +171,7 @@ interface CategoryRepositoryInterface
public function periodIncome(Collection $categories, Collection $accounts, Carbon $start, Carbon $end): array; public function periodIncome(Collection $categories, Collection $accounts, Carbon $start, Carbon $end): array;
/** /**
* TODO not multi-currency
* @param Collection $accounts * @param Collection $accounts
* @param Carbon $start * @param Carbon $start
* @param Carbon $end * @param Carbon $end

View File

@@ -375,7 +375,7 @@ trait PeriodOverview
$cache->addProperty('tag-period-entries'); $cache->addProperty('tag-period-entries');
$cache->addProperty($tag->id); $cache->addProperty($tag->id);
if ($cache->has()) { if ($cache->has()) {
// return $cache->get(); // @codeCoverageIgnore return $cache->get(); // @codeCoverageIgnore
} }
/** @var array $dates */ /** @var array $dates */
$dates = app('navigation')->blockPeriods($start, $end, $range); $dates = app('navigation')->blockPeriods($start, $end, $range);