Files
firefly-iii/app/Http/Controllers/Report/OperationsController.php

134 lines
3.9 KiB
PHP
Raw Normal View History

2016-10-25 18:53:54 +02:00
<?php
/**
2016-12-06 08:59:08 +01:00
* OperationsController.php
2016-10-25 18:53:54 +02:00
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
2016-10-25 18:53:54 +02:00
namespace FireflyIII\Http\Controllers\Report;
use Carbon\Carbon;
use FireflyIII\Http\Controllers\Controller;
2017-04-17 08:31:42 +02:00
use FireflyIII\Repositories\Account\AccountTaskerInterface;
use FireflyIII\Support\CacheProperties;
2016-10-25 18:53:54 +02:00
use Illuminate\Support\Collection;
/**
2016-12-06 08:59:08 +01:00
* Class OperationsController
2016-10-25 18:53:54 +02:00
*
* @package FireflyIII\Http\Controllers\Report
*/
2016-12-06 08:59:08 +01:00
class OperationsController extends Controller
2016-10-25 18:53:54 +02:00
{
/**
2017-04-17 08:31:42 +02:00
* @param AccountTaskerInterface $tasker
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
2016-12-06 08:59:08 +01:00
* @return mixed|string
*/
2017-04-17 08:31:42 +02:00
public function expenses(AccountTaskerInterface $tasker, Collection $accounts, Carbon $start, Carbon $end)
2016-10-25 18:53:54 +02:00
{
// chart properties for cache:
$cache = new CacheProperties;
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty('expense-report');
$cache->addProperty($accounts->pluck('id')->toArray());
if ($cache->has()) {
2017-03-04 11:19:44 +01:00
return $cache->get(); // @codeCoverageIgnore
}
2017-04-17 08:31:42 +02:00
$entries = $tasker->getExpenseReport($start, $end, $accounts);
2016-12-27 15:31:17 +01:00
$type = 'expense-entry';
$result = view('reports.partials.income-expenses', compact('entries', 'type'))->render();
$cache->store($result);
return $result;
}
2016-12-14 18:59:12 +01:00
/**
2017-04-17 08:31:42 +02:00
* @param AccountTaskerInterface $tasker
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
2016-12-14 18:59:12 +01:00
*
* @return string
*/
2017-04-17 08:31:42 +02:00
public function income(AccountTaskerInterface $tasker, Collection $accounts, Carbon $start, Carbon $end)
2016-12-14 18:59:12 +01:00
{
// chart properties for cache:
$cache = new CacheProperties;
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty('income-report');
$cache->addProperty($accounts->pluck('id')->toArray());
if ($cache->has()) {
2017-03-04 11:19:44 +01:00
return $cache->get(); // @codeCoverageIgnore
2016-12-14 18:59:12 +01:00
}
2017-04-17 08:31:42 +02:00
$entries = $tasker->getIncomeReport($start, $end, $accounts);
2016-12-27 15:31:17 +01:00
$type = 'income-entry';
$result = view('reports.partials.income-expenses', compact('entries', 'type'))->render();
2016-12-14 18:59:12 +01:00
$cache->store($result);
return $result;
}
/**
2017-04-17 08:31:42 +02:00
* @param AccountTaskerInterface $tasker
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
2016-12-06 08:59:08 +01:00
* @return mixed|string
*/
2017-04-17 08:31:42 +02:00
public function operations(AccountTaskerInterface $tasker, Collection $accounts, Carbon $start, Carbon $end)
{
// chart properties for cache:
$cache = new CacheProperties;
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty('inc-exp-report');
$cache->addProperty($accounts->pluck('id')->toArray());
if ($cache->has()) {
2017-03-04 11:19:44 +01:00
return $cache->get(); // @codeCoverageIgnore
}
2017-04-17 08:31:42 +02:00
$incomes = $tasker->getIncomeReport($start, $end, $accounts);
$expenses = $tasker->getExpenseReport($start, $end, $accounts);
2016-12-05 20:35:13 +01:00
$incomeSum = array_sum(
array_map(
function ($item) {
return $item['sum'];
}, $incomes
)
);
$expensesSum = array_sum(
array_map(
function ($item) {
return $item['sum'];
}, $expenses
)
);
2016-12-06 08:59:08 +01:00
$result = view('reports.partials.operations', compact('incomeSum', 'expensesSum'))->render();
$cache->store($result);
return $result;
}
}