mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-30 10:33:30 +00:00
Moved charts to separate generators.
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace FireflyIII\Generator\Chart\Account;
|
namespace FireflyIII\Generator\Chart\Account;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Carbon\Carbon;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface AccountChartGenerator
|
* Interface AccountChartGenerator
|
||||||
|
32
app/Generator/Chart/Bill/BillChartGenerator.php
Normal file
32
app/Generator/Chart/Bill/BillChartGenerator.php
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
namespace FireflyIII\Generator\Chart\Bill;
|
||||||
|
|
||||||
|
|
||||||
|
use FireflyIII\Models\Bill;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface BillChartGenerator
|
||||||
|
*
|
||||||
|
* @package FireflyIII\Generator\Chart\Bill
|
||||||
|
*/
|
||||||
|
interface BillChartGenerator
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Bill $bill
|
||||||
|
* @param Collection $entries
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function single(Bill $bill, Collection $entries);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $paid
|
||||||
|
* @param Collection $unpaid
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function frontpage(Collection $paid, Collection $unpaid);
|
||||||
|
|
||||||
|
}
|
87
app/Generator/Chart/Bill/GoogleBillChartGenerator.php
Normal file
87
app/Generator/Chart/Bill/GoogleBillChartGenerator.php
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace FireflyIII\Generator\Chart\Bill;
|
||||||
|
|
||||||
|
use FireflyIII\Models\Bill;
|
||||||
|
use FireflyIII\Models\TransactionJournal;
|
||||||
|
use Grumpydictator\Gchart\GChart;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class GoogleBillChartGenerator
|
||||||
|
*
|
||||||
|
* @package FireflyIII\Generator\Chart\Bill
|
||||||
|
*/
|
||||||
|
class GoogleBillChartGenerator implements BillChartGenerator
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $paid
|
||||||
|
* @param Collection $unpaid
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function frontpage(Collection $paid, Collection $unpaid)
|
||||||
|
{
|
||||||
|
// loop paid and create single entry:
|
||||||
|
$paidDescriptions = [];
|
||||||
|
$paidAmount = 0;
|
||||||
|
$unpaidDescriptions = [];
|
||||||
|
$unpaidAmount = 0;
|
||||||
|
|
||||||
|
|
||||||
|
/** @var TransactionJournal $entry */
|
||||||
|
foreach ($paid as $entry) {
|
||||||
|
|
||||||
|
$paidDescriptions[] = $entry->description;
|
||||||
|
$paidAmount += floatval($entry->amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
// loop unpaid:
|
||||||
|
/** @var Bill $entry */
|
||||||
|
foreach ($unpaid as $entry) {
|
||||||
|
$description = $entry[0]->name . ' (' . $entry[1]->format('jS M Y') . ')';
|
||||||
|
$amount = ($entry[0]->amount_max + $entry[0]->amount_min) / 2;
|
||||||
|
$unpaidDescriptions[] = $description;
|
||||||
|
$unpaidAmount += $amount;
|
||||||
|
unset($amount, $description);
|
||||||
|
}
|
||||||
|
|
||||||
|
$chart = new GChart;
|
||||||
|
$chart->addColumn(trans('firefly.name'), 'string');
|
||||||
|
$chart->addColumn(trans('firefly.amount'), 'number');
|
||||||
|
|
||||||
|
$chart->addRow(trans('firefly.unpaid') . ': ' . join(', ', $unpaidDescriptions), $unpaidAmount);
|
||||||
|
$chart->addRow(trans('firefly.paid') . ': ' . join(', ', $paidDescriptions), $paidAmount);
|
||||||
|
|
||||||
|
$chart->generate();
|
||||||
|
|
||||||
|
return $chart->getData();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Bill $bill
|
||||||
|
* @param Collection $entries
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function single(Bill $bill, Collection $entries)
|
||||||
|
{
|
||||||
|
// make chart:
|
||||||
|
$chart = new GChart;
|
||||||
|
$chart->addColumn(trans('firefly.date'), 'date');
|
||||||
|
$chart->addColumn(trans('firefly.maxAmount'), 'number');
|
||||||
|
$chart->addColumn(trans('firefly.minAmount'), 'number');
|
||||||
|
$chart->addColumn(trans('firefly.billEntry'), 'number');
|
||||||
|
|
||||||
|
/** @var TransactionJournal $result */
|
||||||
|
foreach ($entries as $result) {
|
||||||
|
$chart->addRow(clone $result->date, floatval($bill->amount_max), floatval($bill->amount_min), floatval($result->amount));
|
||||||
|
}
|
||||||
|
|
||||||
|
$chart->generate();
|
||||||
|
|
||||||
|
return $chart->getData();
|
||||||
|
}
|
||||||
|
}
|
43
app/Generator/Chart/Budget/BudgetChartGenerator.php
Normal file
43
app/Generator/Chart/Budget/BudgetChartGenerator.php
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace FireflyIII\Generator\Chart\Budget;
|
||||||
|
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface BudgetChartGenerator
|
||||||
|
*
|
||||||
|
* @package FireflyIII\Generator\Chart\Budget
|
||||||
|
*/
|
||||||
|
interface BudgetChartGenerator
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param Collection $entries
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function budget(Collection $entries);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $entries
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function budgetLimit(Collection $entries);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $entries
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function frontpage(Collection $entries);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $budgets
|
||||||
|
* @param Collection $entries
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function year(Collection $budgets, Collection $entries);
|
||||||
|
|
||||||
|
}
|
110
app/Generator/Chart/Budget/GoogleBudgetChartGenerator.php
Normal file
110
app/Generator/Chart/Budget/GoogleBudgetChartGenerator.php
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace FireflyIII\Generator\Chart\Budget;
|
||||||
|
|
||||||
|
use Grumpydictator\Gchart\GChart;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class GoogleBudgetChartGenerator
|
||||||
|
*
|
||||||
|
* @package FireflyIII\Generator\Chart\Budget
|
||||||
|
*/
|
||||||
|
class GoogleBudgetChartGenerator implements BudgetChartGenerator
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $entries
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function budget(Collection $entries)
|
||||||
|
{
|
||||||
|
|
||||||
|
$chart = new GChart;
|
||||||
|
$chart->addColumn(trans('firefly.period'), 'date');
|
||||||
|
$chart->addColumn(trans('firefly.spent'), 'number');
|
||||||
|
|
||||||
|
/** @var array $entry */
|
||||||
|
foreach ($entries as $entry) {
|
||||||
|
$chart->addRow($entry[0], $entry[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$chart->generate();
|
||||||
|
|
||||||
|
return $chart->getData();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $entries
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function budgetLimit(Collection $entries)
|
||||||
|
{
|
||||||
|
$chart = new GChart;
|
||||||
|
$chart->addColumn(trans('firefly.day'), 'date');
|
||||||
|
$chart->addColumn(trans('firefly.left'), 'number');
|
||||||
|
|
||||||
|
foreach ($entries as $entry) {
|
||||||
|
|
||||||
|
$chart->addRow($entry[0], $entry[1]);
|
||||||
|
}
|
||||||
|
$chart->generate();
|
||||||
|
|
||||||
|
return $chart->getData();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $entries
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function frontpage(Collection $entries)
|
||||||
|
{
|
||||||
|
$chart = new GChart;
|
||||||
|
$chart->addColumn(trans('firefly.budget'), 'string');
|
||||||
|
$chart->addColumn(trans('firefly.left'), 'number');
|
||||||
|
$chart->addColumn(trans('firefly.spent'), 'number');
|
||||||
|
$chart->addColumn(trans('firefly.overspent'), 'number');
|
||||||
|
|
||||||
|
/** @var array $entry */
|
||||||
|
foreach ($entries as $entry) {
|
||||||
|
if ($entry[1] != 0 || $entry[2] != 0 || $entry[3] != 0) {
|
||||||
|
$chart->addRow($entry[0], $entry[1], $entry[2], $entry[3]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$chart->generate();
|
||||||
|
|
||||||
|
return $chart->getData();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $budgets
|
||||||
|
* @param Collection $entries
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function year(Collection $budgets, Collection $entries)
|
||||||
|
{
|
||||||
|
$chart = new GChart;
|
||||||
|
// add columns:
|
||||||
|
$chart->addColumn(trans('firefly.month'), 'date');
|
||||||
|
foreach ($budgets as $budget) {
|
||||||
|
$chart->addColumn($budget->name, 'number');
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var array $entry */
|
||||||
|
foreach ($entries as $entry) {
|
||||||
|
|
||||||
|
$chart->addRowArray($entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
$chart->generate();
|
||||||
|
|
||||||
|
return $chart->getData();
|
||||||
|
}
|
||||||
|
}
|
44
app/Generator/Chart/Category/CategoryChartGenerator.php
Normal file
44
app/Generator/Chart/Category/CategoryChartGenerator.php
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace FireflyIII\Generator\Chart\Category;
|
||||||
|
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface CategoryChartGenerator
|
||||||
|
*
|
||||||
|
* @package FireflyIII\Generator\Chart\Category
|
||||||
|
*/
|
||||||
|
interface CategoryChartGenerator
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $entries
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function all(Collection $entries);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $entries
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function frontpage(Collection $entries);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $entries
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function month(Collection $entries);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $categories
|
||||||
|
* @param Collection $entries
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function year(Collection $categories, Collection $entries);
|
||||||
|
}
|
102
app/Generator/Chart/Category/GoogleCategoryChartGenerator.php
Normal file
102
app/Generator/Chart/Category/GoogleCategoryChartGenerator.php
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace FireflyIII\Generator\Chart\Category;
|
||||||
|
|
||||||
|
use Grumpydictator\Gchart\GChart;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class GoogleCategoryChartGenerator
|
||||||
|
*
|
||||||
|
* @package FireflyIII\Generator\Chart\Category
|
||||||
|
*/
|
||||||
|
class GoogleCategoryChartGenerator implements CategoryChartGenerator
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $entries
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function all(Collection $entries)
|
||||||
|
{
|
||||||
|
$chart = new GChart;
|
||||||
|
$chart->addColumn(trans('firefly.period'), 'date');
|
||||||
|
$chart->addColumn(trans('firefly.spent'), 'number');
|
||||||
|
|
||||||
|
/** @var array $entry */
|
||||||
|
foreach ($entries as $entry) {
|
||||||
|
$chart->addRow($entry[0], $entry[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$chart->generate();
|
||||||
|
|
||||||
|
return $chart->getData();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $entries
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function frontpage(Collection $entries)
|
||||||
|
{
|
||||||
|
$chart = new GChart;
|
||||||
|
$chart->addColumn(trans('firefly.category'), 'string');
|
||||||
|
$chart->addColumn(trans('firefly.spent'), 'number');
|
||||||
|
|
||||||
|
|
||||||
|
/** @var array $entry */
|
||||||
|
foreach ($entries as $entry) {
|
||||||
|
$sum = $entry['sum'];
|
||||||
|
if ($sum != 0) {
|
||||||
|
$chart->addRow($entry['name'], $sum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$chart->generate();
|
||||||
|
|
||||||
|
return $chart->getData();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $entries
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function month(Collection $entries)
|
||||||
|
{
|
||||||
|
$chart = new GChart;
|
||||||
|
|
||||||
|
$chart->addColumn(trans('firefly.period'), 'date');
|
||||||
|
$chart->addColumn(trans('firefly.spent'), 'number');
|
||||||
|
|
||||||
|
/** @var array $entry */
|
||||||
|
foreach ($entries as $entry) {
|
||||||
|
$chart->addRow($entry[0], $entry[1]);
|
||||||
|
}
|
||||||
|
$chart->generate();
|
||||||
|
|
||||||
|
return $chart->getData();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $entries
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function year(Collection $categories, Collection $entries)
|
||||||
|
{
|
||||||
|
$chart = new GChart;
|
||||||
|
|
||||||
|
$chart->addColumn(trans('firefly.month'), 'date');
|
||||||
|
foreach ($categories as $category) {
|
||||||
|
$chart->addColumn($category->name, 'number');
|
||||||
|
}
|
||||||
|
/** @var array $entry */
|
||||||
|
foreach ($entries as $entry) {
|
||||||
|
$chart->addRowArray($entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace FireflyIII\Generator\Chart\PiggyBank;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Grumpydictator\Gchart\GChart;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class GooglePiggyBankChartGenerator
|
||||||
|
*
|
||||||
|
* @package FireflyIII\Generator\Chart\PiggyBank
|
||||||
|
*/
|
||||||
|
class GooglePiggyBankChartGenerator implements PiggyBankChartGenerator
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $set
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function history(Collection $set)
|
||||||
|
{
|
||||||
|
$chart = new GChart;
|
||||||
|
$chart->addColumn(trans('firefly.date'), 'date');
|
||||||
|
$chart->addColumn(trans('firefly.balance'), 'number');
|
||||||
|
|
||||||
|
$sum = '0';
|
||||||
|
bcscale(2);
|
||||||
|
|
||||||
|
foreach ($set as $entry) {
|
||||||
|
$sum = bcadd($sum, $entry->sum);
|
||||||
|
$chart->addRow(new Carbon($entry->date), $sum);
|
||||||
|
}
|
||||||
|
|
||||||
|
$chart->generate();
|
||||||
|
|
||||||
|
return $chart->getData();
|
||||||
|
}
|
||||||
|
}
|
20
app/Generator/Chart/PiggyBank/PiggyBankChartGenerator.php
Normal file
20
app/Generator/Chart/PiggyBank/PiggyBankChartGenerator.php
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace FireflyIII\Generator\Chart\PiggyBank;
|
||||||
|
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface PiggyBankChartGenerator
|
||||||
|
*
|
||||||
|
* @package FireflyIII\Generator\Chart\PiggyBank
|
||||||
|
*/
|
||||||
|
interface PiggyBankChartGenerator
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param Collection $set
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function history(Collection $set);
|
||||||
|
}
|
58
app/Generator/Chart/Report/GoogleReportChartGenerator.php
Normal file
58
app/Generator/Chart/Report/GoogleReportChartGenerator.php
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace FireflyIII\Generator\Chart\Report;
|
||||||
|
|
||||||
|
use Grumpydictator\Gchart\GChart;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class GoogleReportChartGenerator
|
||||||
|
*
|
||||||
|
* @package FireflyIII\Generator\Chart\Report
|
||||||
|
*/
|
||||||
|
class GoogleReportChartGenerator implements ReportChartGenerator
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $entries
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function yearInOut(Collection $entries)
|
||||||
|
{
|
||||||
|
$chart = new GChart;
|
||||||
|
$chart->addColumn(trans('firefly.month'), 'date');
|
||||||
|
$chart->addColumn(trans('firefly.income'), 'number');
|
||||||
|
$chart->addColumn(trans('firefly.expenses'), 'number');
|
||||||
|
|
||||||
|
/** @var array $entry */
|
||||||
|
foreach ($entries as $entry) {
|
||||||
|
$chart->addRowArray($entry);
|
||||||
|
}
|
||||||
|
$chart->generate();
|
||||||
|
|
||||||
|
return $chart->getData();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $income
|
||||||
|
* @param string $expense
|
||||||
|
* @param int $count
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function yearInOutSummarized($income, $expense, $count)
|
||||||
|
{
|
||||||
|
$chart = new GChart;
|
||||||
|
|
||||||
|
$chart->addColumn(trans('firefly.summary'), 'string');
|
||||||
|
$chart->addColumn(trans('firefly.income'), 'number');
|
||||||
|
$chart->addColumn(trans('firefly.expenses'), 'number');
|
||||||
|
$chart->addRow(trans('firefly.sum'), $income, $expense);
|
||||||
|
$chart->addRow(trans('firefly.average'), ($income / $count), ($expense / $count));
|
||||||
|
|
||||||
|
$chart->generate();
|
||||||
|
|
||||||
|
return $chart->getData();
|
||||||
|
}
|
||||||
|
}
|
31
app/Generator/Chart/Report/ReportChartGenerator.php
Normal file
31
app/Generator/Chart/Report/ReportChartGenerator.php
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace FireflyIII\Generator\Chart\Report;
|
||||||
|
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface ReportChartGenerator
|
||||||
|
*
|
||||||
|
* @package FireflyIII\Generator\Chart\Report
|
||||||
|
*/
|
||||||
|
interface ReportChartGenerator
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $entries
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function yearInOut(Collection $entries);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $income
|
||||||
|
* @param string $expense
|
||||||
|
* @param int $count
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function yearInOutSummarized($income, $expense, $count);
|
||||||
|
|
||||||
|
}
|
@@ -8,12 +8,10 @@ use FireflyIII\Http\Controllers\Controller;
|
|||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\Support\CacheProperties;
|
use FireflyIII\Support\CacheProperties;
|
||||||
use Grumpydictator\Gchart\GChart;
|
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Preferences;
|
use Preferences;
|
||||||
use Response;
|
use Response;
|
||||||
use Session;
|
use Session;
|
||||||
use Steam;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class AccountController
|
* Class AccountController
|
||||||
|
@@ -2,14 +2,13 @@
|
|||||||
|
|
||||||
namespace FireflyIII\Http\Controllers\Chart;
|
namespace FireflyIII\Http\Controllers\Chart;
|
||||||
|
|
||||||
|
use App;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Http\Controllers\Controller;
|
use FireflyIII\Http\Controllers\Controller;
|
||||||
use FireflyIII\Models\Bill;
|
use FireflyIII\Models\Bill;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||||
use FireflyIII\Support\CacheProperties;
|
use FireflyIII\Support\CacheProperties;
|
||||||
use Grumpydictator\Gchart\GChart;
|
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Response;
|
use Response;
|
||||||
use Session;
|
use Session;
|
||||||
@@ -22,60 +21,30 @@ use Steam;
|
|||||||
*/
|
*/
|
||||||
class BillController extends Controller
|
class BillController extends Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/** @var \FireflyIII\Generator\Chart\Bill\BillChartGenerator */
|
||||||
|
protected $generator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows the overview for a bill. The min/max amount and matched journals.
|
|
||||||
*
|
*
|
||||||
* @param GChart $chart
|
|
||||||
* @param BillRepositoryInterface $repository
|
|
||||||
* @param Bill $bill
|
|
||||||
*
|
|
||||||
* @return \Symfony\Component\HttpFoundation\Response
|
|
||||||
*/
|
*/
|
||||||
public function single(GChart $chart, BillRepositoryInterface $repository, Bill $bill)
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
parent::__construct();
|
||||||
$chart->addColumn(trans('firefly.date'), 'date');
|
// create chart generator:
|
||||||
$chart->addColumn(trans('firefly.maxAmount'), 'number');
|
$this->generator = App::make('FireflyIII\Generator\Chart\Bill\BillChartGenerator');
|
||||||
$chart->addColumn(trans('firefly.minAmount'), 'number');
|
|
||||||
$chart->addColumn(trans('firefly.billEntry'), 'number');
|
|
||||||
|
|
||||||
$cache = new CacheProperties;
|
|
||||||
$cache->addProperty('single');
|
|
||||||
$cache->addProperty('bill');
|
|
||||||
$cache->addProperty($bill->id);
|
|
||||||
if ($cache->has()) {
|
|
||||||
return Response::json($cache->get()); // @codeCoverageIgnore
|
|
||||||
}
|
|
||||||
|
|
||||||
// get first transaction or today for start:
|
|
||||||
$results = $repository->getJournals($bill);
|
|
||||||
/** @var TransactionJournal $result */
|
|
||||||
foreach ($results as $result) {
|
|
||||||
$chart->addRow(clone $result->date, floatval($bill->amount_max), floatval($bill->amount_min), floatval($result->amount));
|
|
||||||
}
|
|
||||||
|
|
||||||
$chart->generate();
|
|
||||||
|
|
||||||
$data = $chart->getData();
|
|
||||||
$cache->store($data);
|
|
||||||
|
|
||||||
return Response::json($data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows all bills and whether or not theyve been paid this month (pie chart).
|
* Shows all bills and whether or not theyve been paid this month (pie chart).
|
||||||
*
|
*
|
||||||
* @param GChart $chart
|
|
||||||
*
|
|
||||||
* @param BillRepositoryInterface $repository
|
* @param BillRepositoryInterface $repository
|
||||||
* @param AccountRepositoryInterface $accounts
|
* @param AccountRepositoryInterface $accounts
|
||||||
*
|
*
|
||||||
* @return \Symfony\Component\HttpFoundation\Response
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
*/
|
*/
|
||||||
public function frontpage(GChart $chart, BillRepositoryInterface $repository, AccountRepositoryInterface $accounts)
|
public function frontpage(BillRepositoryInterface $repository, AccountRepositoryInterface $accounts)
|
||||||
{
|
{
|
||||||
$chart->addColumn(trans('firefly.name'), 'string');
|
|
||||||
$chart->addColumn(trans('firefly.amount'), 'number');
|
|
||||||
|
|
||||||
$start = Session::get('start', Carbon::now()->startOfMonth());
|
$start = Session::get('start', Carbon::now()->startOfMonth());
|
||||||
$end = Session::get('end', Carbon::now()->endOfMonth());
|
$end = Session::get('end', Carbon::now()->endOfMonth());
|
||||||
@@ -94,11 +63,7 @@ class BillController extends Controller
|
|||||||
$bills = $repository->getActiveBills();
|
$bills = $repository->getActiveBills();
|
||||||
$paid = new Collection; // journals.
|
$paid = new Collection; // journals.
|
||||||
$unpaid = new Collection; // bills
|
$unpaid = new Collection; // bills
|
||||||
// loop paid and create single entry:
|
|
||||||
$paidDescriptions = [];
|
|
||||||
$paidAmount = 0;
|
|
||||||
$unpaidDescriptions = [];
|
|
||||||
$unpaidAmount = 0;
|
|
||||||
|
|
||||||
/** @var Bill $bill */
|
/** @var Bill $bill */
|
||||||
foreach ($bills as $bill) {
|
foreach ($bills as $bill) {
|
||||||
@@ -136,30 +101,35 @@ class BillController extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// build chart:
|
||||||
|
$data = $this->generator->frontpage($paid, $unpaid);
|
||||||
|
$cache->store($data);
|
||||||
|
|
||||||
/** @var TransactionJournal $entry */
|
return Response::json($data);
|
||||||
foreach ($paid as $entry) {
|
|
||||||
|
|
||||||
$paidDescriptions[] = $entry->description;
|
|
||||||
$paidAmount += floatval($entry->amount);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// loop unpaid:
|
/**
|
||||||
/** @var Bill $entry */
|
* Shows the overview for a bill. The min/max amount and matched journals.
|
||||||
foreach ($unpaid as $entry) {
|
*
|
||||||
$description = $entry[0]->name . ' (' . $entry[1]->format('jS M Y') . ')';
|
* @param BillRepositoryInterface $repository
|
||||||
$amount = ($entry[0]->amount_max + $entry[0]->amount_min) / 2;
|
* @param Bill $bill
|
||||||
$unpaidDescriptions[] = $description;
|
*
|
||||||
$unpaidAmount += $amount;
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
unset($amount, $description);
|
*/
|
||||||
|
public function single(BillRepositoryInterface $repository, Bill $bill)
|
||||||
|
{
|
||||||
|
$cache = new CacheProperties;
|
||||||
|
$cache->addProperty('single');
|
||||||
|
$cache->addProperty('bill');
|
||||||
|
$cache->addProperty($bill->id);
|
||||||
|
if ($cache->has()) {
|
||||||
|
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
$chart->addRow(trans('firefly.unpaid') . ': ' . join(', ', $unpaidDescriptions), $unpaidAmount);
|
// get first transaction or today for start:
|
||||||
$chart->addRow(trans('firefly.paid') . ': ' . join(', ', $paidDescriptions), $paidAmount);
|
$results = $repository->getJournals($bill);
|
||||||
|
|
||||||
$chart->generate();
|
$data = $this->generator->single($bill, $results);
|
||||||
|
|
||||||
$data = $chart->getData();
|
|
||||||
$cache->store($data);
|
$cache->store($data);
|
||||||
|
|
||||||
return Response::json($data);
|
return Response::json($data);
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace FireflyIII\Http\Controllers\Chart;
|
namespace FireflyIII\Http\Controllers\Chart;
|
||||||
|
|
||||||
|
use App;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Http\Controllers\Controller;
|
use FireflyIII\Http\Controllers\Controller;
|
||||||
use FireflyIII\Models\Budget;
|
use FireflyIII\Models\Budget;
|
||||||
@@ -22,19 +23,30 @@ use Session;
|
|||||||
*/
|
*/
|
||||||
class BudgetController extends Controller
|
class BudgetController extends Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/** @var \FireflyIII\Generator\Chart\Budget\BudgetChartGenerator */
|
||||||
|
protected $generator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
// create chart generator:
|
||||||
|
$this->generator = App::make('FireflyIII\Generator\Chart\Budget\BudgetChartGenerator');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param GChart $chart
|
|
||||||
* @param BudgetRepositoryInterface $repository
|
* @param BudgetRepositoryInterface $repository
|
||||||
* @param Budget $budget
|
* @param Budget $budget
|
||||||
*
|
*
|
||||||
* @return \Symfony\Component\HttpFoundation\Response
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
*/
|
*/
|
||||||
public function budget(GChart $chart, BudgetRepositoryInterface $repository, Budget $budget)
|
public function budget(BudgetRepositoryInterface $repository, Budget $budget)
|
||||||
{
|
{
|
||||||
$chart->addColumn(trans('firefly.period'), 'date');
|
|
||||||
$chart->addColumn(trans('firefly.spent'), 'number');
|
|
||||||
|
|
||||||
|
|
||||||
|
// dates and times
|
||||||
$first = $repository->getFirstBudgetLimitDate($budget);
|
$first = $repository->getFirstBudgetLimitDate($budget);
|
||||||
$range = Preferences::get('viewRange', '1M')->data;
|
$range = Preferences::get('viewRange', '1M')->data;
|
||||||
$last = Session::get('end', new Carbon);
|
$last = Session::get('end', new Carbon);
|
||||||
@@ -47,33 +59,23 @@ class BudgetController extends Controller
|
|||||||
$cache->addProperty($first);
|
$cache->addProperty($first);
|
||||||
$cache->addProperty($last);
|
$cache->addProperty($last);
|
||||||
$cache->addProperty('budget');
|
$cache->addProperty('budget');
|
||||||
$cache->addProperty('budget');
|
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
return Response::json($cache->get()); // @codeCoverageIgnore
|
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$entries = new Collection;
|
||||||
|
|
||||||
while ($first < $last) {
|
while ($first < $last) {
|
||||||
$end = Navigation::addPeriod($first, $range, 0);
|
$end = Navigation::addPeriod($first, $range, 0);
|
||||||
$end->subDay();
|
$end->subDay();
|
||||||
|
|
||||||
// start date for chart.
|
|
||||||
$chartDate = clone $end;
|
$chartDate = clone $end;
|
||||||
$chartDate->startOfMonth();
|
$chartDate->startOfMonth();
|
||||||
|
|
||||||
$spent = $repository->spentInPeriodCorrected($budget, $first, $end);
|
$spent = $repository->spentInPeriodCorrected($budget, $first, $end);
|
||||||
$chart->addRow($chartDate, $spent);
|
$entries->push([$chartDate, $spent]);
|
||||||
|
|
||||||
$first = Navigation::addPeriod($first, $range, 0);
|
$first = Navigation::addPeriod($first, $range, 0);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$chart->generate();
|
$data = $this->generator->budget($entries);
|
||||||
|
|
||||||
$data = $chart->getData();
|
|
||||||
|
|
||||||
|
|
||||||
$cache->store($data);
|
$cache->store($data);
|
||||||
|
|
||||||
return Response::json($data);
|
return Response::json($data);
|
||||||
@@ -89,7 +91,7 @@ class BudgetController extends Controller
|
|||||||
*
|
*
|
||||||
* @return \Symfony\Component\HttpFoundation\Response
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
*/
|
*/
|
||||||
public function budgetLimit(GChart $chart, BudgetRepositoryInterface $repository, Budget $budget, LimitRepetition $repetition)
|
public function budgetLimit(BudgetRepositoryInterface $repository, Budget $budget, LimitRepetition $repetition)
|
||||||
{
|
{
|
||||||
$start = clone $repetition->startdate;
|
$start = clone $repetition->startdate;
|
||||||
$end = $repetition->enddate;
|
$end = $repetition->enddate;
|
||||||
@@ -106,10 +108,7 @@ class BudgetController extends Controller
|
|||||||
return Response::json($cache->get()); // @codeCoverageIgnore
|
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
$chart->addColumn(trans('firefly.day'), 'date');
|
$entries = new Collection;
|
||||||
$chart->addColumn(trans('firefly.left'), 'number');
|
|
||||||
|
|
||||||
|
|
||||||
$amount = $repetition->amount;
|
$amount = $repetition->amount;
|
||||||
|
|
||||||
while ($start <= $end) {
|
while ($start <= $end) {
|
||||||
@@ -118,12 +117,11 @@ class BudgetController extends Controller
|
|||||||
*/
|
*/
|
||||||
$sum = $repository->expensesOnDayCorrected($budget, $start);
|
$sum = $repository->expensesOnDayCorrected($budget, $start);
|
||||||
$amount += $sum;
|
$amount += $sum;
|
||||||
$chart->addRow(clone $start, $amount);
|
$entries->push([clone $start, $amount]);
|
||||||
$start->addDay();
|
$start->addDay();
|
||||||
}
|
}
|
||||||
$chart->generate();
|
|
||||||
|
|
||||||
$data = $chart->getData();
|
$data = $this->generator->budgetLimit($entries);
|
||||||
$cache->store($data);
|
$cache->store($data);
|
||||||
|
|
||||||
return Response::json($data);
|
return Response::json($data);
|
||||||
@@ -133,18 +131,12 @@ class BudgetController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Shows a budget list with spent/left/overspent.
|
* Shows a budget list with spent/left/overspent.
|
||||||
*
|
*
|
||||||
* @param GChart $chart
|
|
||||||
* @param BudgetRepositoryInterface $repository
|
* @param BudgetRepositoryInterface $repository
|
||||||
*
|
*
|
||||||
* @return \Symfony\Component\HttpFoundation\Response
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
*/
|
*/
|
||||||
public function frontpage(GChart $chart, BudgetRepositoryInterface $repository)
|
public function frontpage(BudgetRepositoryInterface $repository)
|
||||||
{
|
{
|
||||||
$chart->addColumn(trans('firefly.budget'), 'string');
|
|
||||||
$chart->addColumn(trans('firefly.left'), 'number');
|
|
||||||
$chart->addColumn(trans('firefly.spent'), 'number');
|
|
||||||
$chart->addColumn(trans('firefly.overspent'), 'number');
|
|
||||||
|
|
||||||
$budgets = $repository->getBudgets();
|
$budgets = $repository->getBudgets();
|
||||||
$start = Session::get('start', Carbon::now()->startOfMonth());
|
$start = Session::get('start', Carbon::now()->startOfMonth());
|
||||||
$end = Session::get('end', Carbon::now()->endOfMonth());
|
$end = Session::get('end', Carbon::now()->endOfMonth());
|
||||||
@@ -160,6 +152,7 @@ class BudgetController extends Controller
|
|||||||
return Response::json($cache->get()); // @codeCoverageIgnore
|
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bcscale(2);
|
||||||
|
|
||||||
/** @var Budget $budget */
|
/** @var Budget $budget */
|
||||||
foreach ($budgets as $budget) {
|
foreach ($budgets as $budget) {
|
||||||
@@ -172,31 +165,26 @@ class BudgetController extends Controller
|
|||||||
/** @var LimitRepetition $repetition */
|
/** @var LimitRepetition $repetition */
|
||||||
foreach ($repetitions as $repetition) {
|
foreach ($repetitions as $repetition) {
|
||||||
$expenses = $repository->spentInPeriodCorrected($budget, $repetition->startdate, $repetition->enddate, true);
|
$expenses = $repository->spentInPeriodCorrected($budget, $repetition->startdate, $repetition->enddate, true);
|
||||||
$left = $expenses < floatval($repetition->amount) ? floatval($repetition->amount) - $expenses : 0;
|
// $left can be less than zero.
|
||||||
$spent = $expenses > floatval($repetition->amount) ? floatval($repetition->amount) : $expenses;
|
// $overspent can be more than zero ( = overspending)
|
||||||
$overspent = $expenses > floatval($repetition->amount) ? $expenses - floatval($repetition->amount) : 0;
|
|
||||||
$allEntries->push(
|
$left = max(bcsub($repetition->amount, $expenses), 0); // limited at zero.
|
||||||
[$budget->name . ' (' . $repetition->startdate->formatLocalized($this->monthAndDayFormat) . ')',
|
$overspent = max(bcsub($expenses, $repetition->amount), 0); // limited at zero.
|
||||||
$left,
|
$date = $repetition->startdate->formatLocalized($this->monthAndDayFormat);
|
||||||
$spent,
|
$name = $budget->name . ' (' . $date . ')';
|
||||||
$overspent
|
|
||||||
]
|
// $spent is maxed to the repetition amount:
|
||||||
);
|
$spent = $expenses > $repetition->amount ? $repetition->amount : $expenses;
|
||||||
|
|
||||||
|
|
||||||
|
$allEntries->push([$name, $left, $spent, $overspent]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$noBudgetExpenses = $repository->getWithoutBudgetSum($start, $end) * -1;
|
$noBudgetExpenses = $repository->getWithoutBudgetSum($start, $end) * -1;
|
||||||
$allEntries->push([trans('firefly.noBudget'), 0, 0, $noBudgetExpenses]);
|
$allEntries->push([trans('firefly.noBudget'), 0, 0, $noBudgetExpenses]);
|
||||||
|
|
||||||
foreach ($allEntries as $entry) {
|
$data = $this->generator->frontpage($allEntries);
|
||||||
if ($entry[1] != 0 || $entry[2] != 0 || $entry[3] != 0) {
|
|
||||||
$chart->addRow($entry[0], $entry[1], $entry[2], $entry[3]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$chart->generate();
|
|
||||||
|
|
||||||
$data = $chart->getData();
|
|
||||||
$cache->store($data);
|
$cache->store($data);
|
||||||
|
|
||||||
return Response::json($data);
|
return Response::json($data);
|
||||||
@@ -206,14 +194,13 @@ class BudgetController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Show a yearly overview for a budget.
|
* Show a yearly overview for a budget.
|
||||||
*
|
*
|
||||||
* @param GChart $chart
|
|
||||||
* @param BudgetRepositoryInterface $repository
|
* @param BudgetRepositoryInterface $repository
|
||||||
* @param $year
|
* @param $year
|
||||||
* @param bool $shared
|
* @param bool $shared
|
||||||
*
|
*
|
||||||
* @return \Symfony\Component\HttpFoundation\Response
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
*/
|
*/
|
||||||
public function year(GChart $chart, BudgetRepositoryInterface $repository, $year, $shared = false)
|
public function year(BudgetRepositoryInterface $repository, $year, $shared = false)
|
||||||
{
|
{
|
||||||
$start = new Carbon($year . '-01-01');
|
$start = new Carbon($year . '-01-01');
|
||||||
$end = new Carbon($year . '-12-31');
|
$end = new Carbon($year . '-12-31');
|
||||||
@@ -230,17 +217,12 @@ class BudgetController extends Controller
|
|||||||
return Response::json($cache->get()); // @codeCoverageIgnore
|
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
// add columns:
|
$entries = new Collection;
|
||||||
$chart->addColumn(trans('firefly.month'), 'date');
|
|
||||||
foreach ($budgets as $budget) {
|
|
||||||
$chart->addColumn($budget->name, 'number');
|
|
||||||
}
|
|
||||||
|
|
||||||
while ($start < $end) {
|
while ($start < $end) {
|
||||||
// month is the current end of the period:
|
// month is the current end of the period:
|
||||||
$month = clone $start;
|
$month = clone $start;
|
||||||
$month->endOfMonth();
|
$month->endOfMonth();
|
||||||
// make a row:
|
|
||||||
$row = [clone $start];
|
$row = [clone $start];
|
||||||
|
|
||||||
// each budget, fill the row:
|
// each budget, fill the row:
|
||||||
@@ -248,14 +230,11 @@ class BudgetController extends Controller
|
|||||||
$spent = $repository->spentInPeriodCorrected($budget, $start, $month, $shared);
|
$spent = $repository->spentInPeriodCorrected($budget, $start, $month, $shared);
|
||||||
$row[] = $spent;
|
$row[] = $spent;
|
||||||
}
|
}
|
||||||
$chart->addRowArray($row);
|
$entries->push($row);
|
||||||
|
|
||||||
$start->endOfMonth()->addDay();
|
$start->endOfMonth()->addDay();
|
||||||
}
|
}
|
||||||
|
|
||||||
$chart->generate();
|
$data = $this->generator->year($budgets, $entries);
|
||||||
|
|
||||||
$data = $chart->getData();
|
|
||||||
$cache->store($data);
|
$cache->store($data);
|
||||||
|
|
||||||
return Response::json($data);
|
return Response::json($data);
|
||||||
|
@@ -3,12 +3,13 @@
|
|||||||
namespace FireflyIII\Http\Controllers\Chart;
|
namespace FireflyIII\Http\Controllers\Chart;
|
||||||
|
|
||||||
|
|
||||||
|
use App;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Http\Controllers\Controller;
|
use FireflyIII\Http\Controllers\Controller;
|
||||||
use FireflyIII\Models\Category;
|
use FireflyIII\Models\Category;
|
||||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||||
use FireflyIII\Support\CacheProperties;
|
use FireflyIII\Support\CacheProperties;
|
||||||
use Grumpydictator\Gchart\GChart;
|
use Illuminate\Support\Collection;
|
||||||
use Navigation;
|
use Navigation;
|
||||||
use Preferences;
|
use Preferences;
|
||||||
use Response;
|
use Response;
|
||||||
@@ -21,42 +22,61 @@ use Session;
|
|||||||
*/
|
*/
|
||||||
class CategoryController extends Controller
|
class CategoryController extends Controller
|
||||||
{
|
{
|
||||||
|
/** @var \FireflyIII\Generator\Chart\Category\CategoryChartGenerator */
|
||||||
|
protected $generator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
// create chart generator:
|
||||||
|
$this->generator = App::make('FireflyIII\Generator\Chart\Category\CategoryChartGenerator');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show an overview for a category for all time, per month/week/year.
|
* Show an overview for a category for all time, per month/week/year.
|
||||||
*
|
*
|
||||||
* @param GChart $chart
|
|
||||||
* @param CategoryRepositoryInterface $repository
|
* @param CategoryRepositoryInterface $repository
|
||||||
* @param Category $category
|
* @param Category $category
|
||||||
*
|
*
|
||||||
* @return \Symfony\Component\HttpFoundation\Response
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
*/
|
*/
|
||||||
public function all(GChart $chart, CategoryRepositoryInterface $repository, Category $category)
|
public function all(CategoryRepositoryInterface $repository, Category $category)
|
||||||
{
|
{
|
||||||
// oldest transaction in category:
|
// oldest transaction in category:
|
||||||
$start = $repository->getFirstActivityDate($category);
|
$start = $repository->getFirstActivityDate($category);
|
||||||
$range = Preferences::get('viewRange', '1M')->data;
|
$range = Preferences::get('viewRange', '1M')->data;
|
||||||
// jump to start of week / month / year / etc
|
|
||||||
$start = Navigation::startOfPeriod($start, $range);
|
$start = Navigation::startOfPeriod($start, $range);
|
||||||
|
|
||||||
$chart->addColumn(trans('firefly.period'), 'date');
|
|
||||||
$chart->addColumn(trans('firefly.spent'), 'number');
|
|
||||||
|
|
||||||
|
|
||||||
$end = new Carbon;
|
$end = new Carbon;
|
||||||
while ($start <= $end) {
|
|
||||||
|
|
||||||
$currentEnd = Navigation::endOfPeriod($start, $range);
|
$entries = new Collection;
|
||||||
$spent = $repository->spentInPeriodCorrected($category, $start, $currentEnd);
|
|
||||||
$chart->addRow(clone $start, $spent);
|
|
||||||
|
|
||||||
$start = Navigation::addPeriod($start, $range, 0);
|
|
||||||
|
// chart properties for cache:
|
||||||
|
$cache = new CacheProperties();
|
||||||
|
$cache->addProperty($start);
|
||||||
|
$cache->addProperty($end);
|
||||||
|
$cache->addProperty('all');
|
||||||
|
$cache->addProperty('categories');
|
||||||
|
if ($cache->has()) {
|
||||||
|
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
$chart->generate();
|
while ($start <= $end) {
|
||||||
|
$currentEnd = Navigation::endOfPeriod($start, $range);
|
||||||
|
$spent = $repository->spentInPeriodCorrected($category, $start, $currentEnd);
|
||||||
|
$entries->push([clone $start, $spent]);
|
||||||
|
$start = Navigation::addPeriod($start, $range, 0);
|
||||||
|
|
||||||
return Response::json($chart->getData());
|
}
|
||||||
|
|
||||||
|
$data = $this->generator->all($entries);
|
||||||
|
$cache->store($data);
|
||||||
|
|
||||||
|
return Response::json($data);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -64,15 +84,12 @@ class CategoryController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Show this month's category overview.
|
* Show this month's category overview.
|
||||||
*
|
*
|
||||||
* @param GChart $chart
|
|
||||||
* @param CategoryRepositoryInterface $repository
|
* @param CategoryRepositoryInterface $repository
|
||||||
*
|
*
|
||||||
* @return \Symfony\Component\HttpFoundation\Response
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
*/
|
*/
|
||||||
public function frontpage(GChart $chart, CategoryRepositoryInterface $repository)
|
public function frontpage(CategoryRepositoryInterface $repository)
|
||||||
{
|
{
|
||||||
$chart->addColumn(trans('firefly.category'), 'string');
|
|
||||||
$chart->addColumn(trans('firefly.spent'), 'number');
|
|
||||||
|
|
||||||
$start = Session::get('start', Carbon::now()->startOfMonth());
|
$start = Session::get('start', Carbon::now()->startOfMonth());
|
||||||
$end = Session::get('end', Carbon::now()->endOfMonth());
|
$end = Session::get('end', Carbon::now()->endOfMonth());
|
||||||
@@ -87,11 +104,10 @@ class CategoryController extends Controller
|
|||||||
return Response::json($cache->get()); // @codeCoverageIgnore
|
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
$set = $repository->getCategoriesAndExpensesCorrected($start, $end);
|
$array = $repository->getCategoriesAndExpensesCorrected($start, $end);
|
||||||
|
|
||||||
// sort by callback:
|
// sort by callback:
|
||||||
uasort(
|
uasort(
|
||||||
$set,
|
$array,
|
||||||
function ($left, $right) {
|
function ($left, $right) {
|
||||||
if ($left['sum'] == $right['sum']) {
|
if ($left['sum'] == $right['sum']) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -100,48 +116,48 @@ class CategoryController extends Controller
|
|||||||
return ($left['sum'] < $right['sum']) ? 1 : -1;
|
return ($left['sum'] < $right['sum']) ? 1 : -1;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
$set = new Collection($array);
|
||||||
|
$data = $this->generator->frontpage($set);
|
||||||
foreach ($set as $entry) {
|
|
||||||
$sum = floatval($entry['sum']);
|
|
||||||
if ($sum != 0) {
|
|
||||||
$chart->addRow($entry['name'], $sum);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$chart->generate();
|
|
||||||
|
|
||||||
$data = $chart->getData();
|
|
||||||
$cache->store($data);
|
|
||||||
|
|
||||||
return Response::json($data);
|
return Response::json($data);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param GChart $chart
|
|
||||||
* @param CategoryRepositoryInterface $repository
|
* @param CategoryRepositoryInterface $repository
|
||||||
* @param Category $category
|
* @param Category $category
|
||||||
*
|
*
|
||||||
* @return \Symfony\Component\HttpFoundation\Response
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
*/
|
*/
|
||||||
public function month(GChart $chart, CategoryRepositoryInterface $repository, Category $category)
|
public function month(CategoryRepositoryInterface $repository, Category $category)
|
||||||
{
|
{
|
||||||
$start = clone Session::get('start', Carbon::now()->startOfMonth());
|
$start = clone Session::get('start', Carbon::now()->startOfMonth());
|
||||||
$end = Session::get('end', Carbon::now()->endOfMonth());
|
$end = Session::get('end', Carbon::now()->endOfMonth());
|
||||||
|
|
||||||
$chart->addColumn(trans('firefly.period'), 'date');
|
// chart properties for cache:
|
||||||
$chart->addColumn(trans('firefly.spent'), 'number');
|
$cache = new CacheProperties;
|
||||||
|
$cache->addProperty($start);
|
||||||
|
$cache->addProperty($end);
|
||||||
|
$cache->addProperty($category->id);
|
||||||
|
$cache->addProperty('category');
|
||||||
|
$cache->addProperty('month');
|
||||||
|
if ($cache->has()) {
|
||||||
|
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||||
|
}
|
||||||
|
$entries = new Collection;
|
||||||
|
|
||||||
|
|
||||||
while ($start <= $end) {
|
while ($start <= $end) {
|
||||||
$spent = $repository->spentOnDaySumCorrected($category, $start);
|
$spent = $repository->spentOnDaySumCorrected($category, $start);
|
||||||
$chart->addRow(clone $start, $spent);
|
|
||||||
|
$entries->push([clone $start, $spent]);
|
||||||
$start->addDay();
|
$start->addDay();
|
||||||
}
|
}
|
||||||
|
|
||||||
$chart->generate();
|
$data = $this->generator->month($entries);
|
||||||
|
$cache->store($data);
|
||||||
|
|
||||||
return Response::json($chart->getData());
|
return Response::json($data);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -149,25 +165,31 @@ class CategoryController extends Controller
|
|||||||
/**
|
/**
|
||||||
* This chart will only show expenses.
|
* This chart will only show expenses.
|
||||||
*
|
*
|
||||||
* @param GChart $chart
|
|
||||||
* @param CategoryRepositoryInterface $repository
|
* @param CategoryRepositoryInterface $repository
|
||||||
* @param $year
|
* @param $year
|
||||||
* @param bool $shared
|
* @param bool $shared
|
||||||
*
|
*
|
||||||
* @return \Symfony\Component\HttpFoundation\Response
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
*/
|
*/
|
||||||
public function year(GChart $chart, CategoryRepositoryInterface $repository, $year, $shared = false)
|
public function year(CategoryRepositoryInterface $repository, $year, $shared = false)
|
||||||
{
|
{
|
||||||
$start = new Carbon($year . '-01-01');
|
$start = new Carbon($year . '-01-01');
|
||||||
$end = new Carbon($year . '-12-31');
|
$end = new Carbon($year . '-12-31');
|
||||||
|
|
||||||
|
|
||||||
|
// chart properties for cache:
|
||||||
|
$cache = new CacheProperties;
|
||||||
|
$cache->addProperty($start);
|
||||||
|
$cache->addProperty($end);
|
||||||
|
$cache->addProperty('category');
|
||||||
|
$cache->addProperty('year');
|
||||||
|
if ($cache->has()) {
|
||||||
|
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||||
|
}
|
||||||
|
|
||||||
$shared = $shared == 'shared' ? true : false;
|
$shared = $shared == 'shared' ? true : false;
|
||||||
$categories = $repository->getCategories();
|
$categories = $repository->getCategories();
|
||||||
|
$entries = new Collection;
|
||||||
// add columns:
|
|
||||||
$chart->addColumn(trans('firefly.month'), 'date');
|
|
||||||
foreach ($categories as $category) {
|
|
||||||
$chart->addColumn($category->name, 'number');
|
|
||||||
}
|
|
||||||
|
|
||||||
while ($start < $end) {
|
while ($start < $end) {
|
||||||
// month is the current end of the period:
|
// month is the current end of the period:
|
||||||
@@ -181,13 +203,14 @@ class CategoryController extends Controller
|
|||||||
$spent = $repository->spentInPeriodCorrected($category, $start, $month, $shared);
|
$spent = $repository->spentInPeriodCorrected($category, $start, $month, $shared);
|
||||||
$row[] = $spent;
|
$row[] = $spent;
|
||||||
}
|
}
|
||||||
$chart->addRowArray($row);
|
$entries->push($row);
|
||||||
|
|
||||||
$start->addMonth();
|
$start->addMonth();
|
||||||
}
|
}
|
||||||
|
|
||||||
$chart->generate();
|
$data = $this->generator->year($categories, $entries);
|
||||||
|
$cache->store($data);
|
||||||
|
|
||||||
return Response::json($chart->getData());
|
return Response::json($data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
namespace FireflyIII\Http\Controllers\Chart;
|
namespace FireflyIII\Http\Controllers\Chart;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use App;
|
||||||
use FireflyIII\Http\Controllers\Controller;
|
use FireflyIII\Http\Controllers\Controller;
|
||||||
use FireflyIII\Models\PiggyBank;
|
use FireflyIII\Models\PiggyBank;
|
||||||
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
||||||
use Grumpydictator\Gchart\GChart;
|
use FireflyIII\Support\CacheProperties;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Response;
|
use Response;
|
||||||
|
|
||||||
@@ -18,32 +18,44 @@ use Response;
|
|||||||
*/
|
*/
|
||||||
class PiggyBankController extends Controller
|
class PiggyBankController extends Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/** @var \FireflyIII\Generator\Chart\PiggyBank\PiggyBankChartGenerator */
|
||||||
|
protected $generator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
// create chart generator:
|
||||||
|
$this->generator = App::make('FireflyIII\Generator\Chart\PiggyBank\PiggyBankChartGenerator');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows the piggy bank history.
|
* Shows the piggy bank history.
|
||||||
*
|
*
|
||||||
* @param GChart $chart
|
|
||||||
* @param PiggyBankRepositoryInterface $repository
|
* @param PiggyBankRepositoryInterface $repository
|
||||||
* @param PiggyBank $piggyBank
|
* @param PiggyBank $piggyBank
|
||||||
*
|
*
|
||||||
* @return \Symfony\Component\HttpFoundation\Response
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
*/
|
*/
|
||||||
public function history(GChart $chart, PiggyBankRepositoryInterface $repository, PiggyBank $piggyBank)
|
public function history(PiggyBankRepositoryInterface $repository, PiggyBank $piggyBank)
|
||||||
{
|
{
|
||||||
$chart->addColumn(trans('firefly.date'), 'date');
|
// chart properties for cache:
|
||||||
$chart->addColumn(trans('firefly.balance'), 'number');
|
$cache = new CacheProperties;
|
||||||
|
$cache->addProperty('piggy-history');
|
||||||
/** @var Collection $set */
|
$cache->addProperty($piggyBank->id);
|
||||||
$set = $repository->getEventSummarySet($piggyBank);
|
if ($cache->has()) {
|
||||||
$sum = 0;
|
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||||
|
|
||||||
foreach ($set as $entry) {
|
|
||||||
$sum += floatval($entry->sum);
|
|
||||||
$chart->addRow(new Carbon($entry->date), $sum);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$chart->generate();
|
/** @var Collection $set */
|
||||||
|
$set = new Collection($repository->getEventSummarySet($piggyBank));
|
||||||
|
$data = $this->generator->history($set);
|
||||||
|
$cache->store($data);
|
||||||
|
|
||||||
return Response::json($chart->getData());
|
return Response::json($data);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,10 +3,12 @@
|
|||||||
namespace FireflyIII\Http\Controllers\Chart;
|
namespace FireflyIII\Http\Controllers\Chart;
|
||||||
|
|
||||||
|
|
||||||
|
use App;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Helpers\Report\ReportQueryInterface;
|
use FireflyIII\Helpers\Report\ReportQueryInterface;
|
||||||
use FireflyIII\Http\Controllers\Controller;
|
use FireflyIII\Http\Controllers\Controller;
|
||||||
use Grumpydictator\Gchart\GChart;
|
use FireflyIII\Support\CacheProperties;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
use Response;
|
use Response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -17,85 +19,108 @@ use Response;
|
|||||||
class ReportController extends Controller
|
class ReportController extends Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/** @var \FireflyIII\Generator\Chart\Report\ReportChartGenerator */
|
||||||
|
protected $generator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
// create chart generator:
|
||||||
|
$this->generator = App::make('FireflyIII\Generator\Chart\Report\ReportChartGenerator');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Summarizes all income and expenses, per month, for a given year.
|
* Summarizes all income and expenses, per month, for a given year.
|
||||||
*
|
*
|
||||||
* @param GChart $chart
|
|
||||||
* @param ReportQueryInterface $query
|
* @param ReportQueryInterface $query
|
||||||
* @param $year
|
* @param $year
|
||||||
* @param bool $shared
|
* @param bool $shared
|
||||||
*
|
*
|
||||||
* @return \Symfony\Component\HttpFoundation\Response
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
*/
|
*/
|
||||||
public function yearInOut(GChart $chart, ReportQueryInterface $query, $year, $shared = false)
|
public function yearInOut(ReportQueryInterface $query, $year, $shared = false)
|
||||||
{
|
{
|
||||||
// get start and end of year
|
// get start and end of year
|
||||||
$start = new Carbon($year . '-01-01');
|
$start = new Carbon($year . '-01-01');
|
||||||
$end = new Carbon($year . '-12-31');
|
$end = new Carbon($year . '-12-31');
|
||||||
$shared = $shared == 'shared' ? true : false;
|
$shared = $shared == 'shared' ? true : false;
|
||||||
|
|
||||||
$chart->addColumn(trans('firefly.month'), 'date');
|
// chart properties for cache:
|
||||||
$chart->addColumn(trans('firefly.income'), 'number');
|
$cache = new CacheProperties;
|
||||||
$chart->addColumn(trans('firefly.expenses'), 'number');
|
$cache->addProperty('yearInOut');
|
||||||
|
$cache->addProperty($year);
|
||||||
|
$cache->addProperty($shared);
|
||||||
|
if ($cache->has()) {
|
||||||
|
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||||
|
}
|
||||||
|
|
||||||
|
$entries = new Collection;
|
||||||
while ($start < $end) {
|
while ($start < $end) {
|
||||||
$month = clone $start;
|
$month = clone $start;
|
||||||
$month->endOfMonth();
|
$month->endOfMonth();
|
||||||
// total income and total expenses:
|
// total income and total expenses:
|
||||||
$incomeSum = floatval($query->incomeInPeriodCorrected($start, $month, $shared)->sum('amount'));
|
$incomeSum = $query->incomeInPeriodCorrected($start, $month, $shared)->sum('amount');
|
||||||
$expenseSum = floatval($query->expenseInPeriodCorrected($start, $month, $shared)->sum('amount'));
|
$expenseSum = $query->expenseInPeriodCorrected($start, $month, $shared)->sum('amount');
|
||||||
|
|
||||||
$chart->addRow(clone $start, $incomeSum, $expenseSum);
|
$entries->push([clone $start, $incomeSum, $expenseSum]);
|
||||||
$start->addMonth();
|
$start->addMonth();
|
||||||
}
|
}
|
||||||
$chart->generate();
|
|
||||||
|
|
||||||
return Response::json($chart->getData());
|
$data = $this->generator->yearInOut($entries);
|
||||||
|
$cache->store($data);
|
||||||
|
|
||||||
|
return Response::json($data);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Summarizes all income and expenses for a given year. Gives a total and an average.
|
* Summarizes all income and expenses for a given year. Gives a total and an average.
|
||||||
*
|
*
|
||||||
* @param GChart $chart
|
|
||||||
* @param ReportQueryInterface $query
|
* @param ReportQueryInterface $query
|
||||||
* @param $year
|
* @param $year
|
||||||
* @param bool $shared
|
* @param bool $shared
|
||||||
*
|
*
|
||||||
* @return \Symfony\Component\HttpFoundation\Response
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
*/
|
*/
|
||||||
public function yearInOutSummarized(GChart $chart, ReportQueryInterface $query, $year, $shared = false)
|
public function yearInOutSummarized(ReportQueryInterface $query, $year, $shared = false)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// chart properties for cache:
|
||||||
|
$cache = new CacheProperties;
|
||||||
|
$cache->addProperty('yearInOutSummarized');
|
||||||
|
$cache->addProperty($year);
|
||||||
|
$cache->addProperty($shared);
|
||||||
|
if ($cache->has()) {
|
||||||
|
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||||
|
}
|
||||||
|
|
||||||
$start = new Carbon($year . '-01-01');
|
$start = new Carbon($year . '-01-01');
|
||||||
$end = new Carbon($year . '-12-31');
|
$end = new Carbon($year . '-12-31');
|
||||||
$shared = $shared == 'shared' ? true : false;
|
$shared = $shared == 'shared' ? true : false;
|
||||||
$income = 0;
|
$income = '0';
|
||||||
$expense = 0;
|
$expense = '0';
|
||||||
$count = 0;
|
$count = 0;
|
||||||
|
|
||||||
$chart->addColumn(trans('firefly.summary'), 'string');
|
bcscale(2);
|
||||||
$chart->addColumn(trans('firefly.income'), 'number');
|
|
||||||
$chart->addColumn(trans('firefly.expenses'), 'number');
|
|
||||||
|
|
||||||
while ($start < $end) {
|
while ($start < $end) {
|
||||||
$month = clone $start;
|
$month = clone $start;
|
||||||
$month->endOfMonth();
|
$month->endOfMonth();
|
||||||
// total income and total expenses:
|
// total income and total expenses:
|
||||||
$income += floatval($query->incomeInPeriodCorrected($start, $month, $shared)->sum('amount'));
|
$income = bcadd($income, $query->incomeInPeriodCorrected($start, $month, $shared)->sum('amount'));
|
||||||
$expense += floatval($query->expenseInPeriodCorrected($start, $month, $shared)->sum('amount'));
|
$expense = bcadd($expense, $query->expenseInPeriodCorrected($start, $month, $shared)->sum('amount'));
|
||||||
$count++;
|
$count++;
|
||||||
$start->addMonth();
|
$start->addMonth();
|
||||||
}
|
}
|
||||||
|
|
||||||
// add total + average:
|
$data = $this->generator->yearInOutSummarized($income, $expense, $count);
|
||||||
$chart->addRow(trans('firefly.sum'), $income, $expense);
|
$cache->store($data);
|
||||||
$count = $count > 0 ? $count : 1;
|
|
||||||
$chart->addRow(trans('firefly.average'), ($income / $count), ($expense / $count));
|
|
||||||
|
|
||||||
$chart->generate();
|
return Response::json($data);
|
||||||
|
|
||||||
return Response::json($chart->getData());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -93,6 +93,11 @@ class FireflyServiceProvider extends ServiceProvider
|
|||||||
|
|
||||||
// make Google charts:
|
// make Google charts:
|
||||||
$this->app->bind('FireflyIII\Generator\Chart\Account\AccountChartGenerator', 'FireflyIII\Generator\Chart\Account\GoogleAccountChartGenerator');
|
$this->app->bind('FireflyIII\Generator\Chart\Account\AccountChartGenerator', 'FireflyIII\Generator\Chart\Account\GoogleAccountChartGenerator');
|
||||||
|
$this->app->bind('FireflyIII\Generator\Chart\Bill\BillChartGenerator', 'FireflyIII\Generator\Chart\Bill\GoogleBillChartGenerator');
|
||||||
|
$this->app->bind('FireflyIII\Generator\Chart\Budget\BudgetChartGenerator', 'FireflyIII\Generator\Chart\Budget\GoogleBudgetChartGenerator');
|
||||||
|
$this->app->bind('FireflyIII\Generator\Chart\Category\CategoryChartGenerator', 'FireflyIII\Generator\Chart\Category\GoogleCategoryChartGenerator');
|
||||||
|
$this->app->bind('FireflyIII\Generator\Chart\PiggyBank\PiggyBankChartGenerator', 'FireflyIII\Generator\Chart\PiggyBank\GooglePiggyBankChartGenerator');
|
||||||
|
$this->app->bind('FireflyIII\Generator\Chart\Report\ReportChartGenerator', 'FireflyIII\Generator\Chart\Report\GoogleReportChartGenerator');
|
||||||
|
|
||||||
|
|
||||||
$this->app->bind('FireflyIII\Helpers\Help\HelpInterface', 'FireflyIII\Helpers\Help\Help');
|
$this->app->bind('FireflyIII\Helpers\Help\HelpInterface', 'FireflyIII\Helpers\Help\Help');
|
||||||
|
Reference in New Issue
Block a user