mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-10 15:35:53 -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()
|
public function homeRecurring()
|
||||||
{
|
{
|
||||||
/** @var \Firefly\Helper\Toolkit\ToolkitInterface $toolkit */
|
/** @var \Firefly\Helper\Toolkit\ToolkitInterface $toolkit */
|
||||||
$toolkit = App::make('Firefly\Helper\Toolkit\ToolkitInterface');
|
$toolkit = App::make('Firefly\Helper\Toolkit\ToolkitInterface');
|
||||||
$recurringTransactions = \Auth::user()->recurringtransactions()->get();
|
|
||||||
$sessionStart = \Session::get('start');
|
/*
|
||||||
$sessionEnd = \Session::get('end');
|
* Set of paid transaction journals.
|
||||||
$paid = [];
|
* Set of unpaid recurring transactions.
|
||||||
$unpaid = [];
|
*/
|
||||||
|
$paid = [];
|
||||||
|
$unpaid = [];
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Loop the recurring transactions.
|
||||||
|
*/
|
||||||
|
|
||||||
/** @var \RecurringTransaction $recurring */
|
/** @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;
|
$start = clone $recurring->date;
|
||||||
$end = Carbon::now();
|
$end = Carbon::now();
|
||||||
@ -515,38 +521,30 @@ class ChartController extends BaseController
|
|||||||
*/
|
*/
|
||||||
$current = clone $start;
|
$current = clone $start;
|
||||||
|
|
||||||
\Log::debug('Now looping recurring transaction #' . $recurring->id . ': ' . $recurring->name);
|
|
||||||
|
|
||||||
while ($current <= $end) {
|
while ($current <= $end) {
|
||||||
/*
|
/*
|
||||||
* Get end of period for $current:
|
* Get end of period for $current:
|
||||||
*/
|
*/
|
||||||
$currentEnd = clone $current;
|
$currentEnd = clone $current;
|
||||||
$toolkit->endOfPeriod($currentEnd, $recurring->repeat_freq);
|
$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?
|
* 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).
|
* Lets see if we've already spent money on this recurring transaction (it hath recurred).
|
||||||
*/
|
*/
|
||||||
/** @var Collection $set */
|
/** @var TransactionJournal $set */
|
||||||
$set = \Auth::user()->transactionjournals()->where('recurring_transaction_id', $recurring->id)
|
$transaction = \Auth::user()->transactionjournals()->where('recurring_transaction_id', $recurring->id)->after($current)->before($currentEnd)->first();
|
||||||
->after($current)->before($currentEnd)->get();
|
|
||||||
if (count($set) > 1) {
|
if(is_null($transaction)) {
|
||||||
\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) {
|
|
||||||
$unpaid[] = $recurring;
|
$unpaid[] = $recurring;
|
||||||
} else {
|
} else {
|
||||||
$paid[] = $set->get(0);
|
$paid[] = $transaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add some time for the next loop!
|
* 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));
|
$unPaidColours = $toolkit->colorRange('AA4643', 'FFFFFF', count($unpaid) == 0 ? 1 : count($unpaid));
|
||||||
$paidColours = $toolkit->colorRange('4572A7', 'FFFFFF', count($paid) == 0 ? 1 : count($paid));
|
$paidColours = $toolkit->colorRange('4572A7', 'FFFFFF', count($paid) == 0 ? 1 : count($paid));
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The chart serie:
|
||||||
|
*/
|
||||||
$serie = [
|
$serie = [
|
||||||
'type' => 'pie',
|
'type' => 'pie',
|
||||||
'name' => 'Amount',
|
'name' => 'Amount',
|
||||||
'data' => []
|
'data' => []
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Loop paid and unpaid to make two haves for a pie chart.
|
||||||
|
*/
|
||||||
/** @var TransactionJournal $entry */
|
/** @var TransactionJournal $entry */
|
||||||
foreach ($paid as $index => $entry) {
|
foreach ($paid as $index => $entry) {
|
||||||
$transactions = $entry->transactions()->get();
|
$transactions = $entry->transactions()->get();
|
||||||
$amount = max(floatval($transactions[0]->amount), floatval($transactions[1]->amount));
|
$amount = max(floatval($transactions[0]->amount), floatval($transactions[1]->amount));
|
||||||
$serie['data'][] = [
|
$serie['data'][] = [
|
||||||
'name' => $entry->description,
|
'name' => 'Already paid "'.$entry->description.'"',
|
||||||
'y' => $amount,
|
'y' => $amount,
|
||||||
|
'url' => route('transactions.show',$entry->id),
|
||||||
|
'objType' => 'paid',
|
||||||
'color' => $paidColours[$index]
|
'color' => $paidColours[$index]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@ -582,8 +589,10 @@ class ChartController extends BaseController
|
|||||||
foreach ($unpaid as $index => $entry) {
|
foreach ($unpaid as $index => $entry) {
|
||||||
$amount = (floatval($entry->amount_max) + floatval($entry->amount_min)) / 2;
|
$amount = (floatval($entry->amount_max) + floatval($entry->amount_min)) / 2;
|
||||||
$serie['data'][] = [
|
$serie['data'][] = [
|
||||||
'name' => $entry->name,
|
'name' => 'Still due: '.$entry->name,
|
||||||
'y' => $amount,
|
'y' => $amount,
|
||||||
|
'url' => route('recurring.show',$entry->id),
|
||||||
|
'objType' => 'unpaid',
|
||||||
'color' => $unPaidColours[$index]
|
'color' => $unPaidColours[$index]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Firefly\Helper\Toolkit;
|
namespace Firefly\Helper\Toolkit;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -40,4 +41,12 @@ interface ToolkitInterface
|
|||||||
*/
|
*/
|
||||||
public function colorRange($start, $end, $steps = 5);
|
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: {
|
credits: {
|
||||||
enabled: false
|
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: {
|
plotOptions: {
|
||||||
pie: {
|
pie: {
|
||||||
|
events: {
|
||||||
|
click: function (e) {
|
||||||
|
if (e.point.url != null) {
|
||||||
|
window.location = e.point.url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
allowPointSelect: true,
|
allowPointSelect: true,
|
||||||
cursor: 'pointer',
|
cursor: 'pointer',
|
||||||
dataLabels: {
|
dataLabels: {
|
||||||
|
Loading…
Reference in New Issue
Block a user