2016-10-25 11:53:54 -05:00
|
|
|
<?php
|
|
|
|
/**
|
2016-12-06 01:59:08 -06:00
|
|
|
* OperationsController.php
|
2017-10-21 01:40:00 -05:00
|
|
|
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
2016-10-25 11:53:54 -05:00
|
|
|
*
|
2017-10-21 01:40:00 -05:00
|
|
|
* This file is part of Firefly III.
|
2016-10-25 11:53:54 -05:00
|
|
|
*
|
2017-10-21 01:40:00 -05:00
|
|
|
* Firefly III is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Firefly III is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2017-12-17 07:41:58 -06:00
|
|
|
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
2016-10-25 11:53:54 -05:00
|
|
|
*/
|
2017-04-09 00:44:22 -05:00
|
|
|
declare(strict_types=1);
|
2016-10-25 11:53:54 -05:00
|
|
|
|
|
|
|
namespace FireflyIII\Http\Controllers\Report;
|
|
|
|
|
|
|
|
use Carbon\Carbon;
|
|
|
|
use FireflyIII\Http\Controllers\Controller;
|
2017-04-17 01:31:42 -05:00
|
|
|
use FireflyIII\Repositories\Account\AccountTaskerInterface;
|
2016-10-26 09:46:43 -05:00
|
|
|
use FireflyIII\Support\CacheProperties;
|
2016-10-25 11:53:54 -05:00
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
|
|
|
|
/**
|
2017-11-15 05:25:49 -06:00
|
|
|
* Class OperationsController.
|
2016-10-25 11:53:54 -05:00
|
|
|
*/
|
2016-12-06 01:59:08 -06:00
|
|
|
class OperationsController extends Controller
|
2016-10-25 11:53:54 -05:00
|
|
|
{
|
2016-10-26 09:46:43 -05:00
|
|
|
/**
|
2017-04-17 01:31:42 -05:00
|
|
|
* @param AccountTaskerInterface $tasker
|
|
|
|
* @param Collection $accounts
|
|
|
|
* @param Carbon $start
|
|
|
|
* @param Carbon $end
|
2016-10-26 09:46:43 -05:00
|
|
|
*
|
2016-12-06 01:59:08 -06:00
|
|
|
* @return mixed|string
|
2018-04-27 23:23:13 -05:00
|
|
|
* @throws \Throwable
|
2016-10-26 09:46:43 -05:00
|
|
|
*/
|
2017-04-17 01:31:42 -05:00
|
|
|
public function expenses(AccountTaskerInterface $tasker, Collection $accounts, Carbon $start, Carbon $end)
|
2016-10-25 11:53:54 -05:00
|
|
|
{
|
2016-10-26 09:46:43 -05:00
|
|
|
// chart properties for cache:
|
|
|
|
$cache = new CacheProperties;
|
|
|
|
$cache->addProperty($start);
|
|
|
|
$cache->addProperty($end);
|
2016-11-02 14:45:11 -05:00
|
|
|
$cache->addProperty('expense-report');
|
2016-10-26 09:46:43 -05:00
|
|
|
$cache->addProperty($accounts->pluck('id')->toArray());
|
|
|
|
if ($cache->has()) {
|
2017-03-04 04:19:44 -06:00
|
|
|
return $cache->get(); // @codeCoverageIgnore
|
2016-11-02 14:45:11 -05:00
|
|
|
}
|
2017-04-17 01:31:42 -05:00
|
|
|
$entries = $tasker->getExpenseReport($start, $end, $accounts);
|
2016-12-27 08:31:17 -06:00
|
|
|
$type = 'expense-entry';
|
|
|
|
$result = view('reports.partials.income-expenses', compact('entries', 'type'))->render();
|
2016-11-02 14:45:11 -05:00
|
|
|
$cache->store($result);
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2016-12-14 11:59:12 -06:00
|
|
|
/**
|
2017-04-17 01:31:42 -05:00
|
|
|
* @param AccountTaskerInterface $tasker
|
|
|
|
* @param Collection $accounts
|
|
|
|
* @param Carbon $start
|
|
|
|
* @param Carbon $end
|
2016-12-14 11:59:12 -06:00
|
|
|
*
|
|
|
|
* @return string
|
2018-04-27 23:23:13 -05:00
|
|
|
* @throws \Throwable
|
2016-12-14 11:59:12 -06:00
|
|
|
*/
|
2017-04-17 01:31:42 -05:00
|
|
|
public function income(AccountTaskerInterface $tasker, Collection $accounts, Carbon $start, Carbon $end)
|
2016-12-14 11:59:12 -06: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 04:19:44 -06:00
|
|
|
return $cache->get(); // @codeCoverageIgnore
|
2016-12-14 11:59:12 -06:00
|
|
|
}
|
2017-04-17 01:31:42 -05:00
|
|
|
$entries = $tasker->getIncomeReport($start, $end, $accounts);
|
2016-12-27 08:31:17 -06:00
|
|
|
$type = 'income-entry';
|
|
|
|
$result = view('reports.partials.income-expenses', compact('entries', 'type'))->render();
|
2016-12-14 11:59:12 -06:00
|
|
|
|
|
|
|
$cache->store($result);
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2016-11-02 14:45:11 -05:00
|
|
|
/**
|
2017-04-17 01:31:42 -05:00
|
|
|
* @param AccountTaskerInterface $tasker
|
|
|
|
* @param Collection $accounts
|
|
|
|
* @param Carbon $start
|
|
|
|
* @param Carbon $end
|
2016-11-02 14:45:11 -05:00
|
|
|
*
|
2016-12-06 01:59:08 -06:00
|
|
|
* @return mixed|string
|
2018-04-27 23:23:13 -05:00
|
|
|
* @throws \Throwable
|
2016-11-02 14:45:11 -05:00
|
|
|
*/
|
2017-04-17 01:31:42 -05:00
|
|
|
public function operations(AccountTaskerInterface $tasker, Collection $accounts, Carbon $start, Carbon $end)
|
2016-11-02 14:45:11 -05:00
|
|
|
{
|
|
|
|
// 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 04:19:44 -06:00
|
|
|
return $cache->get(); // @codeCoverageIgnore
|
2016-10-26 09:46:43 -05:00
|
|
|
}
|
|
|
|
|
2017-04-17 01:31:42 -05:00
|
|
|
$incomes = $tasker->getIncomeReport($start, $end, $accounts);
|
|
|
|
$expenses = $tasker->getExpenseReport($start, $end, $accounts);
|
2016-12-05 13:35:13 -06:00
|
|
|
$incomeSum = array_sum(
|
|
|
|
array_map(
|
|
|
|
function ($item) {
|
|
|
|
return $item['sum'];
|
2017-11-15 03:52:29 -06:00
|
|
|
},
|
|
|
|
$incomes
|
2016-12-05 13:35:13 -06:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$expensesSum = array_sum(
|
|
|
|
array_map(
|
|
|
|
function ($item) {
|
|
|
|
return $item['sum'];
|
2017-11-15 03:52:29 -06:00
|
|
|
},
|
|
|
|
$expenses
|
2016-12-05 13:35:13 -06:00
|
|
|
)
|
|
|
|
);
|
2016-10-26 09:46:43 -05:00
|
|
|
|
2016-12-06 01:59:08 -06:00
|
|
|
$result = view('reports.partials.operations', compact('incomeSum', 'expensesSum'))->render();
|
2016-11-02 14:45:11 -05:00
|
|
|
$cache->store($result);
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
2016-12-22 12:42:45 -06:00
|
|
|
}
|