firefly-iii/app/Generator/Chart/Bill/ChartJsBillChartGenerator.php

99 lines
2.7 KiB
PHP
Raw Normal View History

2015-06-27 10:32:52 -05:00
<?php
2016-02-05 05:08:25 -06:00
declare(strict_types = 1);
/**
* ChartJsBillChartGenerator.php
* Copyright (C) 2016 Sander Dorigo
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
2015-06-27 10:32:52 -05:00
namespace FireflyIII\Generator\Chart\Bill;
use FireflyIII\Models\Bill;
2015-12-27 13:07:49 -06:00
use FireflyIII\Models\TransactionJournal;
2015-06-27 10:32:52 -05:00
use Illuminate\Support\Collection;
/**
* Class ChartJsBillChartGenerator
*
* @package FireflyIII\Generator\Chart\Bill
*/
class ChartJsBillChartGenerator implements BillChartGeneratorInterface
2015-06-27 10:32:52 -05:00
{
/**
* @param string $paid
* @param string $unpaid
2015-06-27 10:32:52 -05:00
*
* @return array
*/
2016-02-05 02:25:15 -06:00
public function frontpage(string $paid, string $unpaid)
2015-06-27 10:32:52 -05:00
{
2015-07-06 10:45:59 -05:00
bcscale(2);
2015-06-27 10:32:52 -05:00
$data = [
[
2015-12-28 00:12:47 -06:00
'value' => round($unpaid, 2),
2015-06-27 10:32:52 -05:00
'color' => 'rgba(53, 124, 165,0.7)',
'highlight' => 'rgba(53, 124, 165,0.9)',
'label' => trans('firefly.unpaid'),
],
[
'value' => round(bcmul($paid, '-1'), 2), // paid is negative, must be positive.
2015-06-27 10:32:52 -05:00
'color' => 'rgba(0, 141, 76, 0.7)',
'highlight' => 'rgba(0, 141, 76, 0.9)',
'label' => trans('firefly.paid'),
2016-01-15 16:12:52 -06:00
],
2015-06-27 10:32:52 -05:00
];
return $data;
}
/**
* @param Bill $bill
* @param Collection $entries
*
* @return array
*/
public function single(Bill $bill, Collection $entries)
{
bcscale(2);
$format = (string)trans('config.month');
2016-01-02 09:57:31 -06:00
$data = [
2015-06-28 05:41:58 -05:00
'count' => 3,
'labels' => [],
'datasets' => [],
];
$minAmount = [];
$maxAmount = [];
$actualAmount = [];
2015-12-27 13:07:49 -06:00
/** @var TransactionJournal $entry */
2015-06-28 05:41:58 -05:00
foreach ($entries as $entry) {
$data['labels'][] = $entry->date->formatLocalized($format);
$minAmount[] = round($bill->amount_min, 2);
$maxAmount[] = round($bill->amount_max, 2);
2015-12-27 13:07:49 -06:00
/*
* journalAmount has been collected in BillRepository::getJournals
*/
$actualAmount[] = round(bcmul($entry->journalAmount, '-1'), 2);
2015-06-28 05:41:58 -05:00
}
$data['datasets'][] = [
'label' => trans('firefly.minAmount'),
'data' => $minAmount,
];
$data['datasets'][] = [
'label' => trans('firefly.billEntry'),
'data' => $actualAmount,
];
$data['datasets'][] = [
'label' => trans('firefly.maxAmount'),
'data' => $maxAmount,
];
$data['count'] = count($data['datasets']);
return $data;
2015-06-27 10:32:52 -05:00
}
2015-06-28 01:24:12 -05:00
}