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

114 lines
3.2 KiB
PHP
Raw Normal View History

2015-06-27 17:32:52 +02:00
<?php
namespace FireflyIII\Generator\Chart\Bill;
2015-06-28 12:41:58 +02:00
use Config;
2015-06-27 17:32:52 +02:00
use FireflyIII\Models\Bill;
use FireflyIII\Models\TransactionJournal;
use Illuminate\Support\Collection;
2015-06-28 12:41:58 +02:00
use Preferences;
2015-06-27 17:32:52 +02:00
/**
* Class ChartJsBillChartGenerator
*
* @package FireflyIII\Generator\Chart\Bill
*/
class ChartJsBillChartGenerator implements BillChartGenerator
{
/**
* @param Collection $paid
* @param Collection $unpaid
*
* @return array
*/
public function frontpage(Collection $paid, Collection $unpaid)
{
$paidDescriptions = [];
$paidAmount = 0;
$unpaidDescriptions = [];
$unpaidAmount = 0;
2015-07-06 17:45:59 +02:00
bcscale(2);
2015-06-27 17:32:52 +02:00
/** @var TransactionJournal $entry */
2015-07-06 22:23:34 +02:00
foreach ($paid as $entry) { // loop paid and create single entry:
2015-06-27 17:32:52 +02:00
$paidDescriptions[] = $entry->description;
2015-09-30 19:43:02 +02:00
$paidAmount = bcadd($paidAmount, $entry->amount_positive);
2015-06-27 17:32:52 +02:00
}
/** @var Bill $entry */
2015-07-06 22:23:34 +02:00
foreach ($unpaid as $entry) { // loop unpaid:
2015-06-27 17:32:52 +02:00
$description = $entry[0]->name . ' (' . $entry[1]->format('jS M Y') . ')';
2015-07-26 19:42:28 +02:00
$amount = bcdiv(bcadd($entry[0]->amount_max, $entry[0]->amount_min), 2);
2015-06-27 17:32:52 +02:00
$unpaidDescriptions[] = $description;
2015-07-06 17:45:59 +02:00
$unpaidAmount = bcadd($unpaidAmount, $amount);
2015-06-27 17:32:52 +02:00
unset($amount, $description);
}
$data = [
[
'value' => $unpaidAmount,
'color' => 'rgba(53, 124, 165,0.7)',
'highlight' => 'rgba(53, 124, 165,0.9)',
'label' => trans('firefly.unpaid'),
],
[
'value' => $paidAmount,
'color' => 'rgba(0, 141, 76, 0.7)',
'highlight' => 'rgba(0, 141, 76, 0.9)',
'label' => trans('firefly.paid'),
]
];
return $data;
}
/**
* @param Bill $bill
* @param Collection $entries
*
* @return array
*/
public function single(Bill $bill, Collection $entries)
{
2015-06-28 12:41:58 +02:00
// language:
2015-12-24 08:35:08 +01:00
$format = trans('config.month');
2015-06-28 12:41:58 +02:00
$data = [
'count' => 3,
'labels' => [],
'datasets' => [],
];
// dataset: max amount
// dataset: min amount
// dataset: actual amount
$minAmount = [];
$maxAmount = [];
$actualAmount = [];
foreach ($entries as $entry) {
$data['labels'][] = $entry->date->formatLocalized($format);
$minAmount[] = round($bill->amount_min, 2);
$maxAmount[] = round($bill->amount_max, 2);
2015-10-01 07:46:47 +02:00
$actualAmount[] = round(($entry->amount * -1), 2);
2015-06-28 12:41:58 +02: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 17:32:52 +02:00
}
2015-06-28 08:24:12 +02:00
}