_accounts = $accounts; $this->_journals = $journals; $this->_repository = $repository; View::share('title', 'Reports'); View::share('mainTitleIcon', 'fa-line-chart'); } /** * */ public function index() { $start = $this->_journals->firstDate(); $months = $this->_repository->listOfMonths(clone $start); $years = $this->_repository->listOfYears(clone $start); $title = 'Reports'; $mainTitleIcon = 'fa-line-chart'; return View::make('reports.index', compact('years', 'months', 'title', 'mainTitleIcon')); } /** * @param string $year * @param string $month * * @return \Illuminate\View\View */ public function month($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'); $subTitle = 'Report for ' . $date->format('F Y'); $subTitleIcon = 'fa-calendar'; $displaySum = true; // to show sums in report. $income = $this->_repository->getIncomeForMonth($date); $expenses = $this->_repository->getExpenseGroupedForMonth($date, 10); $budgets = $this->_repository->getBudgetsForMonth($date); $categories = $this->_repository->getCategoriesForMonth($date, 10); $accounts = $this->_repository->getAccountsForMonth($date); return View::make( 'reports.month', compact('accounts', 'categories', 'budgets', 'expenses', 'subTitle', 'displaySum', 'subTitleIcon', 'income') ); } /** * @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 * * @return $this */ public function year($year) { try { new Carbon('01-01-' . $year); } catch (Exception $e) { App::abort(500); } $date = new Carbon('01-01-' . $year); $end = clone $date; $end->endOfYear(); $title = 'Reports'; $subTitle = $year; $subTitleIcon = 'fa-bar-chart'; $mainTitleIcon = 'fa-line-chart'; $balances = $this->_repository->yearBalanceReport($date); $groupedIncomes = $this->_repository->revenueGroupedByAccount($date, $end, 15); $groupedExpenses = $this->_repository->expensesGroupedByAccount($date, $end, 15); return View::make( 'reports.year', compact('date', 'groupedIncomes', 'groupedExpenses', 'year', 'balances', 'title', 'subTitle', 'subTitleIcon', 'mainTitleIcon') ); } }