mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-19 16:10:00 +00:00
Greatly expanded report functionality.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
<?php
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Database\Account\Account as AccountRepository;
|
||||
use FireflyIII\Database\TransactionJournal\TransactionJournal as TransactionJournalRepository;
|
||||
use FireflyIII\Report\ReportInterface as Report;
|
||||
|
||||
@@ -10,31 +9,53 @@ use FireflyIII\Report\ReportInterface as Report;
|
||||
*/
|
||||
class ReportController extends BaseController
|
||||
{
|
||||
/** @var AccountRepository */
|
||||
protected $_accounts;
|
||||
|
||||
/** @var \FireflyIII\Database\Budget\Budget */
|
||||
protected $_budgets;
|
||||
/** @var TransactionJournalRepository */
|
||||
protected $_journals;
|
||||
|
||||
/** @var Report */
|
||||
protected $_repository;
|
||||
|
||||
/**
|
||||
* @param AccountRepository $accounts
|
||||
* @param TransactionJournalRepository $journals
|
||||
* @param Report $repository
|
||||
*/
|
||||
public function __construct(AccountRepository $accounts, TransactionJournalRepository $journals, Report $repository)
|
||||
public function __construct(TransactionJournalRepository $journals, Report $repository)
|
||||
{
|
||||
$this->_accounts = $accounts;
|
||||
$this->_journals = $journals;
|
||||
$this->_repository = $repository;
|
||||
/** @var \FireflyIII\Database\Budget\Budget _budgets */
|
||||
$this->_budgets = App::make('FireflyIII\Database\Budget\Budget');
|
||||
|
||||
|
||||
View::share('title', 'Reports');
|
||||
View::share('mainTitleIcon', 'fa-line-chart');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $year
|
||||
* @param string $month
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function budget($year = '2014', $month = '1')
|
||||
{
|
||||
try {
|
||||
new Carbon($year . '-' . $month . '-01');
|
||||
} catch (Exception $e) {
|
||||
View::make('error')->with('message', 'Invalid date');
|
||||
}
|
||||
$date = new Carbon($year . '-' . $month . '-01');
|
||||
$dayEarly = clone $date;
|
||||
$dayEarly = $dayEarly->subDay();
|
||||
$accounts = $this->_repository->getAccountListBudgetOverview($date);
|
||||
$budgets = $this->_repository->getBudgetsForMonth($date);
|
||||
|
||||
return View::make('reports.budget', compact('accounts', 'budgets', 'dayEarly'));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@@ -62,7 +83,7 @@ class ReportController extends BaseController
|
||||
} catch (Exception $e) {
|
||||
View::make('error')->with('message', 'Invalid date');
|
||||
}
|
||||
$date = new Carbon($year . '-' . $month . '-01');
|
||||
$date = new Carbon($year . '-' . $month . '-01');
|
||||
$subTitle = 'Report for ' . $date->format('F Y');
|
||||
$subTitleIcon = 'fa-calendar';
|
||||
$displaySum = true; // to show sums in report.
|
||||
@@ -79,61 +100,6 @@ class ReportController extends BaseController
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $year
|
||||
* @param $month
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function unbalanced($year, $month)
|
||||
{
|
||||
try {
|
||||
new Carbon($year . '-' . $month . '-01');
|
||||
} catch (Exception $e) {
|
||||
App::abort(500);
|
||||
}
|
||||
$start = new Carbon($year . '-' . $month . '-01');
|
||||
$end = clone $start;
|
||||
$title = 'Reports';
|
||||
$subTitle = 'Unbalanced transactions in ' . $start->format('F Y');
|
||||
$mainTitleIcon = 'fa-line-chart';
|
||||
$subTitleIcon = 'fa-bar-chart';
|
||||
$end->endOfMonth();
|
||||
|
||||
/** @var \FireflyIII\Database\TransactionJournal\TransactionJournal $journalRepository */
|
||||
$journalRepository = App::make('FireflyIII\Database\TransactionJournal\TransactionJournal');
|
||||
$journals = $journalRepository->getInDateRange($start, $end);
|
||||
|
||||
$withdrawals = $journals->filter(
|
||||
function (TransactionJournal $journal) {
|
||||
$relations = $journal->transactiongroups()->where('relation', 'balance')->count();
|
||||
$budgets = $journal->budgets()->count();
|
||||
$type = $journal->transactionType->type;
|
||||
if ($type == 'Withdrawal' && $budgets == 0 && $relations == 0) {
|
||||
return $journal;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
);
|
||||
$deposits = $journals->filter(
|
||||
function (TransactionJournal $journal) {
|
||||
$relations = $journal->transactiongroups()->where('relation', 'balance')->count();
|
||||
$budgets = $journal->budgets()->count();
|
||||
$type = $journal->transactionType->type;
|
||||
if ($type == 'Deposit' && $budgets == 0 && $relations == 0) {
|
||||
return $journal;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
);
|
||||
|
||||
$journals = $withdrawals->merge($deposits);
|
||||
|
||||
return View::make('reports.unbalanced', compact('start', 'end', 'title', 'subTitle', 'subTitleIcon', 'mainTitleIcon', 'journals'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $year
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user