mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
More code for previous.
This commit is contained in:
parent
17ae4b7d2a
commit
114788567d
@ -7,7 +7,6 @@ use Carbon\Carbon;
|
|||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use Illuminate\Database\Query\JoinClause;
|
use Illuminate\Database\Query\JoinClause;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Session;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ReportHelper
|
* Class ReportHelper
|
||||||
@ -87,7 +86,7 @@ class ReportHelper implements ReportHelperInterface
|
|||||||
$end = Carbon::now();
|
$end = Carbon::now();
|
||||||
$months = [];
|
$months = [];
|
||||||
while ($start <= $end) {
|
while ($start <= $end) {
|
||||||
$year = $start->format('Y');
|
$year = $start->format('Y');
|
||||||
$months[$year][] = [
|
$months[$year][] = [
|
||||||
'formatted' => $start->format('F Y'),
|
'formatted' => $start->format('F Y'),
|
||||||
'month' => intval($start->format('m')),
|
'month' => intval($start->format('m')),
|
||||||
@ -119,33 +118,37 @@ class ReportHelper implements ReportHelperInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Carbon $date
|
* @param Carbon $date
|
||||||
|
* @param bool $showSharedReports
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function yearBalanceReport(Carbon $date)
|
public function yearBalanceReport(Carbon $date, $showSharedReports = false)
|
||||||
{
|
{
|
||||||
$start = clone $date;
|
$start = clone $date;
|
||||||
$end = clone $date;
|
$end = clone $date;
|
||||||
$sharedAccounts = [];
|
$sharedAccounts = [];
|
||||||
$sharedCollection = \Auth::user()->accounts()
|
if ($showSharedReports === false) {
|
||||||
->leftJoin('account_meta', 'account_meta.account_id', '=', 'accounts.id')
|
$sharedCollection = \Auth::user()->accounts()
|
||||||
->where('account_meta.name', '=', 'accountRole')
|
->leftJoin('account_meta', 'account_meta.account_id', '=', 'accounts.id')
|
||||||
->where('account_meta.data', '=', json_encode('sharedAsset'))
|
->where('account_meta.name', '=', 'accountRole')
|
||||||
->get(['accounts.id']);
|
->where('account_meta.data', '=', json_encode('sharedAsset'))
|
||||||
|
->get(['accounts.id']);
|
||||||
|
|
||||||
foreach ($sharedCollection as $account) {
|
foreach ($sharedCollection as $account) {
|
||||||
$sharedAccounts[] = $account->id;
|
$sharedAccounts[] = $account->id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$accounts = \Auth::user()->accounts()->accountTypeIn(['Default account', 'Asset account'])->orderBy('accounts.name','ASC')->get(['accounts.*'])->filter(
|
$accounts = \Auth::user()->accounts()->accountTypeIn(['Default account', 'Asset account'])->orderBy('accounts.name', 'ASC')->get(['accounts.*'])
|
||||||
function (Account $account) use ($sharedAccounts) {
|
->filter(
|
||||||
if (!in_array($account->id, $sharedAccounts)) {
|
function (Account $account) use ($sharedAccounts) {
|
||||||
return $account;
|
if (!in_array($account->id, $sharedAccounts)) {
|
||||||
}
|
return $account;
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
$report = [];
|
$report = [];
|
||||||
$start->startOfYear()->subDay();
|
$start->startOfYear()->subDay();
|
||||||
$end->endOfYear();
|
$end->endOfYear();
|
||||||
|
@ -14,27 +14,6 @@ interface ReportHelperInterface
|
|||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Carbon $date
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function listOfMonths(Carbon $date);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Carbon $date
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function listOfYears(Carbon $date);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Carbon $date
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function yearBalanceReport(Carbon $date);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This methods fails to take in account transfers FROM shared accounts.
|
* This methods fails to take in account transfers FROM shared accounts.
|
||||||
*
|
*
|
||||||
@ -54,4 +33,26 @@ interface ReportHelperInterface
|
|||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
public function getBudgetsForMonth(Carbon $date);
|
public function getBudgetsForMonth(Carbon $date);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Carbon $date
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function listOfMonths(Carbon $date);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Carbon $date
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function listOfYears(Carbon $date);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Carbon $date
|
||||||
|
* @param bool $showSharedReports
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function yearBalanceReport(Carbon $date, $showSharedReports = false);
|
||||||
}
|
}
|
@ -447,55 +447,60 @@ class ReportQuery implements ReportQueryInterface
|
|||||||
*
|
*
|
||||||
* @param Carbon $start
|
* @param Carbon $start
|
||||||
* @param Carbon $end
|
* @param Carbon $end
|
||||||
|
* @param bool $showSharedReports
|
||||||
*
|
*
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
public function journalsByRevenueAccount(Carbon $start, Carbon $end)
|
public function journalsByRevenueAccount(Carbon $start, Carbon $end, $showSharedReports = false)
|
||||||
{
|
{
|
||||||
return TransactionJournal::
|
$query = TransactionJournal::
|
||||||
leftJoin(
|
leftJoin(
|
||||||
'transactions as t_from', function (JoinClause $join) {
|
'transactions as t_from', function (JoinClause $join) {
|
||||||
$join->on('t_from.transaction_journal_id', '=', 'transaction_journals.id')->where('t_from.amount', '<', 0);
|
$join->on('t_from.transaction_journal_id', '=', 'transaction_journals.id')->where('t_from.amount', '<', 0);
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
->leftJoin('accounts as ac_from', 't_from.account_id', '=', 'ac_from.id')
|
->leftJoin('accounts as ac_from', 't_from.account_id', '=', 'ac_from.id')
|
||||||
->leftJoin(
|
->leftJoin(
|
||||||
'account_meta as acm_from', function (JoinClause $join) {
|
'account_meta as acm_from', function (JoinClause $join) {
|
||||||
$join->on('ac_from.id', '=', 'acm_from.account_id')->where('acm_from.name', '=', 'accountRole');
|
$join->on('ac_from.id', '=', 'acm_from.account_id')->where('acm_from.name', '=', 'accountRole');
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
->leftJoin(
|
->leftJoin(
|
||||||
'transactions as t_to', function (JoinClause $join) {
|
'transactions as t_to', function (JoinClause $join) {
|
||||||
$join->on('t_to.transaction_journal_id', '=', 'transaction_journals.id')->where('t_to.amount', '>', 0);
|
$join->on('t_to.transaction_journal_id', '=', 'transaction_journals.id')->where('t_to.amount', '>', 0);
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
->leftJoin('accounts as ac_to', 't_to.account_id', '=', 'ac_to.id')
|
->leftJoin('accounts as ac_to', 't_to.account_id', '=', 'ac_to.id')
|
||||||
->leftJoin(
|
->leftJoin(
|
||||||
'account_meta as acm_to', function (JoinClause $join) {
|
'account_meta as acm_to', function (JoinClause $join) {
|
||||||
$join->on('ac_to.id', '=', 'acm_to.account_id')->where('acm_to.name', '=', 'accountRole');
|
$join->on('ac_to.id', '=', 'acm_to.account_id')->where('acm_to.name', '=', 'accountRole');
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
|
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id');
|
||||||
->where(
|
if ($showSharedReports === false) {
|
||||||
function ($query) {
|
|
||||||
$query->where(
|
$query->where(
|
||||||
function ($q) {
|
function ($query) {
|
||||||
$q->where('transaction_types.type', 'Deposit');
|
$query->where(
|
||||||
$q->where('acm_to.data', '!=', '"sharedAsset"');
|
function ($q) {
|
||||||
}
|
$q->where('transaction_types.type', 'Deposit');
|
||||||
);
|
$q->where('acm_to.data', '!=', '"sharedAsset"');
|
||||||
$query->orWhere(
|
}
|
||||||
function ($q) {
|
);
|
||||||
$q->where('transaction_types.type', 'Transfer');
|
$query->orWhere(
|
||||||
$q->where('acm_from.data', '=', '"sharedAsset"');
|
function ($q) {
|
||||||
}
|
$q->where('transaction_types.type', 'Transfer');
|
||||||
);
|
$q->where('acm_from.data', '=', '"sharedAsset"');
|
||||||
}
|
}
|
||||||
)
|
);
|
||||||
->before($end)->after($start)
|
}
|
||||||
->where('transaction_journals.user_id', Auth::user()->id)
|
);
|
||||||
->groupBy('t_from.account_id')->orderBy('amount')
|
}
|
||||||
->get(['t_from.account_id as account_id', 'ac_from.name as name', DB::Raw('SUM(t_from.amount) as `amount`')]);
|
$query->before($end)->after($start)
|
||||||
|
->where('transaction_journals.user_id', Auth::user()->id)
|
||||||
|
->groupBy('t_from.account_id')->orderBy('amount');
|
||||||
|
|
||||||
|
return $query->get(['t_from.account_id as account_id', 'ac_from.name as name', DB::Raw('SUM(t_from.amount) as `amount`')]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -136,10 +136,11 @@ interface ReportQueryInterface
|
|||||||
*
|
*
|
||||||
* @param Carbon $start
|
* @param Carbon $start
|
||||||
* @param Carbon $end
|
* @param Carbon $end
|
||||||
|
* @param bool $showSharedReports
|
||||||
*
|
*
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
public function journalsByRevenueAccount(Carbon $start, Carbon $end);
|
public function journalsByRevenueAccount(Carbon $start, Carbon $end, $showSharedReports = false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* With an equally misleading name, this query returns are transfers to shared accounts. These are considered
|
* With an equally misleading name, this query returns are transfers to shared accounts. These are considered
|
||||||
|
@ -363,16 +363,19 @@ class ReportController extends Controller
|
|||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return view('error')->with('message', 'Invalid date.');
|
return view('error')->with('message', 'Invalid date.');
|
||||||
}
|
}
|
||||||
$date = new Carbon('01-01-' . $year);
|
|
||||||
$end = clone $date;
|
$pref = Preferences::get('showSharedReports', false);
|
||||||
|
$showSharedReports = $pref->data;
|
||||||
|
$date = new Carbon('01-01-' . $year);
|
||||||
|
$end = clone $date;
|
||||||
$end->endOfYear();
|
$end->endOfYear();
|
||||||
$title = 'Reports';
|
$title = 'Reports';
|
||||||
$subTitle = $year;
|
$subTitle = $year;
|
||||||
$subTitleIcon = 'fa-bar-chart';
|
$subTitleIcon = 'fa-bar-chart';
|
||||||
$mainTitleIcon = 'fa-line-chart';
|
$mainTitleIcon = 'fa-line-chart';
|
||||||
$balances = $helper->yearBalanceReport($date);
|
$balances = $helper->yearBalanceReport($date, $showSharedReports);
|
||||||
$groupedIncomes = $query->journalsByRevenueAccount($date, $end);
|
$groupedIncomes = $query->journalsByRevenueAccount($date, $end, $showSharedReports);
|
||||||
$groupedExpenses = $query->journalsByExpenseAccount($date, $end);
|
$groupedExpenses = $query->journalsByExpenseAccount($date, $end, $showSharedReports);
|
||||||
|
|
||||||
//$groupedExpenses = $helper-> expensesGroupedByAccount($date, $end, 15);
|
//$groupedExpenses = $helper-> expensesGroupedByAccount($date, $end, 15);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user