mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-10 07:25:50 -06:00
Expand the chart.
This commit is contained in:
parent
36d8dee853
commit
733b6d7eb7
@ -495,17 +495,23 @@ class ChartController extends BaseController
|
||||
public function homeRecurring()
|
||||
{
|
||||
/** @var \Firefly\Helper\Toolkit\ToolkitInterface $toolkit */
|
||||
$toolkit = App::make('Firefly\Helper\Toolkit\ToolkitInterface');
|
||||
$recurringTransactions = \Auth::user()->recurringtransactions()->get();
|
||||
$sessionStart = \Session::get('start');
|
||||
$sessionEnd = \Session::get('end');
|
||||
$paid = [];
|
||||
$unpaid = [];
|
||||
$toolkit = App::make('Firefly\Helper\Toolkit\ToolkitInterface');
|
||||
|
||||
/*
|
||||
* Set of paid transaction journals.
|
||||
* Set of unpaid recurring transactions.
|
||||
*/
|
||||
$paid = [];
|
||||
$unpaid = [];
|
||||
|
||||
/*
|
||||
* Loop the recurring transactions.
|
||||
*/
|
||||
|
||||
/** @var \RecurringTransaction $recurring */
|
||||
foreach ($recurringTransactions as $recurring) {
|
||||
foreach (\Auth::user()->recurringtransactions()->get() as $recurring) {
|
||||
/*
|
||||
* Start a loop starting at the $date.
|
||||
* Start another loop starting at the $date.
|
||||
*/
|
||||
$start = clone $recurring->date;
|
||||
$end = Carbon::now();
|
||||
@ -515,38 +521,30 @@ class ChartController extends BaseController
|
||||
*/
|
||||
$current = clone $start;
|
||||
|
||||
\Log::debug('Now looping recurring transaction #' . $recurring->id . ': ' . $recurring->name);
|
||||
|
||||
while ($current <= $end) {
|
||||
/*
|
||||
* Get end of period for $current:
|
||||
*/
|
||||
$currentEnd = clone $current;
|
||||
$toolkit->endOfPeriod($currentEnd, $recurring->repeat_freq);
|
||||
\Log::debug('Now at $current: ' . $current->format('D d F Y') . ' - ' . $currentEnd->format('D d F Y'));
|
||||
|
||||
/*
|
||||
* In the current session range?
|
||||
*/
|
||||
if ($sessionEnd >= $current and $currentEnd >= $sessionStart) {
|
||||
if (\Session::get('end') >= $current and $currentEnd >= \Session::get('start')) {
|
||||
/*
|
||||
* Lets see if we've already spent money on this recurring transaction (it hath recurred).
|
||||
*/
|
||||
/** @var Collection $set */
|
||||
$set = \Auth::user()->transactionjournals()->where('recurring_transaction_id', $recurring->id)
|
||||
->after($current)->before($currentEnd)->get();
|
||||
if (count($set) > 1) {
|
||||
\Log::error('Recurring #' . $recurring->id . ', dates [' . $current . ',' . $currentEnd . ']. Found multiple hits. Cannot handle this!');
|
||||
throw new FireflyException('Cannot handle multiple transactions. See logs.');
|
||||
} else if (count($set) == 0) {
|
||||
/** @var TransactionJournal $set */
|
||||
$transaction = \Auth::user()->transactionjournals()->where('recurring_transaction_id', $recurring->id)->after($current)->before($currentEnd)->first();
|
||||
|
||||
if(is_null($transaction)) {
|
||||
$unpaid[] = $recurring;
|
||||
} else {
|
||||
$paid[] = $set->get(0);
|
||||
$paid[] = $transaction;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Add some time for the next loop!
|
||||
*/
|
||||
@ -556,23 +554,32 @@ class ChartController extends BaseController
|
||||
|
||||
}
|
||||
/*
|
||||
* Loop paid and unpaid to make two haves for a pie chart.
|
||||
* Get some colors going.
|
||||
*/
|
||||
$unPaidColours = $toolkit->colorRange('AA4643', 'FFFFFF', count($unpaid) == 0 ? 1 : count($unpaid));
|
||||
$paidColours = $toolkit->colorRange('4572A7', 'FFFFFF', count($paid) == 0 ? 1 : count($paid));
|
||||
|
||||
/*
|
||||
* The chart serie:
|
||||
*/
|
||||
$serie = [
|
||||
'type' => 'pie',
|
||||
'name' => 'Amount',
|
||||
'data' => []
|
||||
];
|
||||
|
||||
/*
|
||||
* Loop paid and unpaid to make two haves for a pie chart.
|
||||
*/
|
||||
/** @var TransactionJournal $entry */
|
||||
foreach ($paid as $index => $entry) {
|
||||
$transactions = $entry->transactions()->get();
|
||||
$amount = max(floatval($transactions[0]->amount), floatval($transactions[1]->amount));
|
||||
$serie['data'][] = [
|
||||
'name' => $entry->description,
|
||||
'name' => 'Already paid "'.$entry->description.'"',
|
||||
'y' => $amount,
|
||||
'url' => route('transactions.show',$entry->id),
|
||||
'objType' => 'paid',
|
||||
'color' => $paidColours[$index]
|
||||
];
|
||||
}
|
||||
@ -582,8 +589,10 @@ class ChartController extends BaseController
|
||||
foreach ($unpaid as $index => $entry) {
|
||||
$amount = (floatval($entry->amount_max) + floatval($entry->amount_min)) / 2;
|
||||
$serie['data'][] = [
|
||||
'name' => $entry->name,
|
||||
'name' => 'Still due: '.$entry->name,
|
||||
'y' => $amount,
|
||||
'url' => route('recurring.show',$entry->id),
|
||||
'objType' => 'unpaid',
|
||||
'color' => $unPaidColours[$index]
|
||||
];
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace Firefly\Helper\Toolkit;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
@ -40,4 +41,12 @@ interface ToolkitInterface
|
||||
*/
|
||||
public function colorRange($start, $end, $steps = 5);
|
||||
|
||||
/**
|
||||
* @param Carbon $date
|
||||
* @param $repeatFreq
|
||||
* @param $skip
|
||||
* @return Carbon
|
||||
*/
|
||||
public function addPeriod(Carbon $date, $repeatFreq, $skip);
|
||||
|
||||
}
|
@ -219,8 +219,25 @@ $(function () {
|
||||
credits: {
|
||||
enabled: false
|
||||
},
|
||||
tooltip: {
|
||||
formatter: function () {
|
||||
if (this.point.objType == 'paid') {
|
||||
return this.key + ': \u20AC ' + Highcharts.numberFormat(this.y, 2);
|
||||
} else {
|
||||
return this.key + ': ~\u20AC ' + Highcharts.numberFormat(this.y, 2);
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
plotOptions: {
|
||||
pie: {
|
||||
events: {
|
||||
click: function (e) {
|
||||
if (e.point.url != null) {
|
||||
window.location = e.point.url;
|
||||
}
|
||||
}
|
||||
},
|
||||
allowPointSelect: true,
|
||||
cursor: 'pointer',
|
||||
dataLabels: {
|
||||
|
Loading…
Reference in New Issue
Block a user