mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
See if we can easily generate reports with shared accounts.
This commit is contained in:
parent
0b028a8923
commit
17ae4b7d2a
@ -23,26 +23,33 @@ class ReportQuery implements ReportQueryInterface
|
|||||||
/**
|
/**
|
||||||
* This query retrieves a list of accounts that are active and not shared.
|
* This query retrieves a list of accounts that are active and not shared.
|
||||||
*
|
*
|
||||||
|
* @param bool $showSharedReports
|
||||||
|
*
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
public function accountList()
|
public function accountList($showSharedReports = false)
|
||||||
{
|
{
|
||||||
return Auth::user()->accounts()
|
$query = Auth::user()->accounts();
|
||||||
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
if ($showSharedReports === false) {
|
||||||
->leftJoin(
|
|
||||||
'account_meta', function (JoinClause $join) {
|
$query->leftJoin(
|
||||||
$join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', "accountRole");
|
'account_meta', function (JoinClause $join) {
|
||||||
}
|
$join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', "accountRole");
|
||||||
)
|
}
|
||||||
->whereIn('account_types.type', ['Default account', 'Cash account', 'Asset account'])
|
)->where(
|
||||||
->where('active', 1)
|
function (Builder $query) {
|
||||||
->where(
|
$query->where('account_meta.data', '!=', '"sharedAsset"');
|
||||||
function (Builder $query) {
|
$query->orWhereNull('account_meta.data');
|
||||||
$query->where('account_meta.data', '!=', '"sharedAsset"');
|
}
|
||||||
$query->orWhereNull('account_meta.data');
|
);
|
||||||
}
|
|
||||||
)
|
}
|
||||||
->get(['accounts.*']);
|
$query->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||||
|
->whereIn('account_types.type', ['Default account', 'Cash account', 'Asset account'])
|
||||||
|
->where('active', 1)
|
||||||
|
->orderBy('accounts.name', 'ASC');
|
||||||
|
|
||||||
|
return $query->get(['accounts.*']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -105,7 +112,7 @@ class ReportQuery implements ReportQueryInterface
|
|||||||
{
|
{
|
||||||
$set = $this->balancedTransactionsList($account, $start, $end);
|
$set = $this->balancedTransactionsList($account, $start, $end);
|
||||||
$sum = 0;
|
$sum = 0;
|
||||||
foreach($set as $entry) {
|
foreach ($set as $entry) {
|
||||||
$sum += floatval($entry->amount);
|
$sum += floatval($entry->amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,26 +124,31 @@ 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 getAllAccounts(Carbon $start, Carbon $end)
|
public function getAllAccounts(Carbon $start, Carbon $end, $showSharedReports = false)
|
||||||
{
|
{
|
||||||
$set = Auth::user()->accounts()->orderBy('accounts.name', 'ASC')
|
$query = Auth::user()->accounts()->orderBy('accounts.name', 'ASC')
|
||||||
->accountTypeIn(['Default account', 'Asset account', 'Cash account'])
|
->accountTypeIn(['Default account', 'Asset account', 'Cash account']);
|
||||||
->leftJoin(
|
if ($showSharedReports === false) {
|
||||||
'account_meta', function (JoinClause $join) {
|
$query->leftJoin(
|
||||||
$join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole');
|
'account_meta', function (JoinClause $join) {
|
||||||
}
|
$join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole');
|
||||||
)
|
}
|
||||||
->orderBy('accounts.name','ASC')
|
)
|
||||||
->where(
|
->orderBy('accounts.name', 'ASC')
|
||||||
function (Builder $query) {
|
->where(
|
||||||
$query->where('account_meta.data', '!=', '"sharedAsset"');
|
function (Builder $query) use ($showSharedReports) {
|
||||||
$query->orWhereNull('account_meta.data');
|
|
||||||
}
|
$query->where('account_meta.data', '!=', '"sharedAsset"');
|
||||||
)
|
$query->orWhereNull('account_meta.data');
|
||||||
->get(['accounts.*']);
|
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$set = $query->get(['accounts.*']);
|
||||||
$set->each(
|
$set->each(
|
||||||
function (Account $account) use ($start, $end) {
|
function (Account $account) use ($start, $end) {
|
||||||
/** @noinspection PhpParamsInspection */
|
/** @noinspection PhpParamsInspection */
|
||||||
@ -223,64 +235,68 @@ 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 incomeByPeriod(Carbon $start, Carbon $end)
|
public function incomeByPeriod(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 ($query) {
|
||||||
function ($q) {
|
$query->where(
|
||||||
$q->where('transaction_types.type', 'Deposit');
|
function ($q) {
|
||||||
$q->where('acm_to.data', '!=', '"sharedAsset"');
|
$q->where('transaction_types.type', 'Deposit');
|
||||||
}
|
$q->where('acm_to.data', '!=', '"sharedAsset"');
|
||||||
);
|
}
|
||||||
$query->orWhere(
|
);
|
||||||
function ($q) {
|
$query->orWhere(
|
||||||
$q->where('transaction_types.type', 'Transfer');
|
function ($q) {
|
||||||
$q->where('acm_from.data', '=', '"sharedAsset"');
|
$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('transaction_journals.date')
|
$query->before($end)->after($start)
|
||||||
->get(
|
->where('transaction_journals.user_id', Auth::user()->id)
|
||||||
['transaction_journals.id',
|
->groupBy('t_from.account_id')->orderBy('transaction_journals.date');
|
||||||
'transaction_journals.description',
|
|
||||||
'transaction_journals.encrypted',
|
return $query->get(
|
||||||
'transaction_types.type',
|
['transaction_journals.id',
|
||||||
DB::Raw('SUM(`t_to`.`amount`) as `amount`'),
|
'transaction_journals.description',
|
||||||
'transaction_journals.date',
|
'transaction_journals.encrypted',
|
||||||
't_from.account_id as account_id',
|
'transaction_types.type',
|
||||||
'ac_from.name as name']
|
DB::Raw('SUM(`t_to`.`amount`) as `amount`'),
|
||||||
);
|
'transaction_journals.date',
|
||||||
|
't_from.account_id as account_id',
|
||||||
|
'ac_from.name as name']
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -288,33 +304,37 @@ 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 journalsByBudget(Carbon $start, Carbon $end)
|
public function journalsByBudget(Carbon $start, Carbon $end, $showSharedReports = false)
|
||||||
{
|
{
|
||||||
return Auth::user()->transactionjournals()
|
$query = Auth::user()->transactionjournals()
|
||||||
->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
|
->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
|
||||||
->leftJoin('budgets', 'budget_transaction_journal.budget_id', '=', 'budgets.id')
|
->leftJoin('budgets', 'budget_transaction_journal.budget_id', '=', 'budgets.id')
|
||||||
->leftJoin(
|
->leftJoin(
|
||||||
'transactions', function (JoinClause $join) {
|
'transactions', function (JoinClause $join) {
|
||||||
$join->on('transaction_journals.id', '=', 'transactions.transaction_journal_id')->where('transactions.amount', '<', 0);
|
$join->on('transaction_journals.id', '=', 'transactions.transaction_journal_id')->where('transactions.amount', '<', 0);
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
|
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id');
|
||||||
->leftJoin(
|
if ($showSharedReports === false) {
|
||||||
'account_meta', function (JoinClause $join) {
|
|
||||||
$join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole');
|
$query->leftJoin(
|
||||||
}
|
'account_meta', function (JoinClause $join) {
|
||||||
)
|
$join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole');
|
||||||
->leftJoin('transaction_types', 'transaction_journals.transaction_type_id', '=', 'transaction_types.id')
|
}
|
||||||
->where('transaction_journals.date', '>=', $start->format('Y-m-d'))
|
)->where('account_meta.data', '!=', '"sharedAsset"');
|
||||||
->where('transaction_journals.date', '<=', $end->format('Y-m-d'))
|
}
|
||||||
->where('account_meta.data', '!=', '"sharedAsset"')
|
$query->leftJoin('transaction_types', 'transaction_journals.transaction_type_id', '=', 'transaction_types.id')
|
||||||
->where('transaction_types.type', 'Withdrawal')
|
->where('transaction_journals.date', '>=', $start->format('Y-m-d'))
|
||||||
->groupBy('budgets.id')
|
->where('transaction_journals.date', '<=', $end->format('Y-m-d'))
|
||||||
->orderBy('budgets.name', 'ASC')
|
->where('transaction_types.type', 'Withdrawal')
|
||||||
->get(['budgets.id', 'budgets.name', DB::Raw('SUM(`transactions`.`amount`) AS `spent`')]);
|
->groupBy('budgets.id')
|
||||||
|
->orderBy('budgets.name', 'ASC');
|
||||||
|
|
||||||
|
return $query->get(['budgets.id', 'budgets.name', DB::Raw('SUM(`transactions`.`amount`) AS `spent`')]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -323,35 +343,38 @@ 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 journalsByCategory(Carbon $start, Carbon $end)
|
public function journalsByCategory(Carbon $start, Carbon $end, $showSharedReports = false)
|
||||||
{
|
{
|
||||||
return Auth::user()->transactionjournals()
|
$query = Auth::user()->transactionjournals()
|
||||||
->leftJoin(
|
->leftJoin(
|
||||||
'category_transaction_journal', 'category_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id'
|
'category_transaction_journal', 'category_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id'
|
||||||
)
|
)
|
||||||
->leftJoin('categories', 'category_transaction_journal.category_id', '=', 'categories.id')
|
->leftJoin('categories', 'category_transaction_journal.category_id', '=', 'categories.id')
|
||||||
->leftJoin(
|
->leftJoin(
|
||||||
'transactions', function (JoinClause $join) {
|
'transactions', function (JoinClause $join) {
|
||||||
$join->on('transaction_journals.id', '=', 'transactions.transaction_journal_id')->where('transactions.amount', '<', 0);
|
$join->on('transaction_journals.id', '=', 'transactions.transaction_journal_id')->where('transactions.amount', '<', 0);
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
|
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id');
|
||||||
->leftJoin(
|
if ($showSharedReports === false) {
|
||||||
'account_meta', function (JoinClause $join) {
|
$query->leftJoin(
|
||||||
$join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole');
|
'account_meta', function (JoinClause $join) {
|
||||||
}
|
$join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole');
|
||||||
)
|
}
|
||||||
->leftJoin('transaction_types', 'transaction_journals.transaction_type_id', '=', 'transaction_types.id')
|
)->where('account_meta.data', '!=', '"sharedAsset"');
|
||||||
->where('transaction_journals.date', '>=', $start->format('Y-m-d'))
|
}
|
||||||
->where('transaction_journals.date', '<=', $end->format('Y-m-d'))
|
$query->leftJoin('transaction_types', 'transaction_journals.transaction_type_id', '=', 'transaction_types.id')
|
||||||
->where('account_meta.data', '!=', '"sharedAsset"')
|
->where('transaction_journals.date', '>=', $start->format('Y-m-d'))
|
||||||
->where('transaction_types.type', 'Withdrawal')
|
->where('transaction_journals.date', '<=', $end->format('Y-m-d'))
|
||||||
->groupBy('categories.id')
|
->where('transaction_types.type', 'Withdrawal')
|
||||||
->orderBy('amount')
|
->groupBy('categories.id')
|
||||||
->get(['categories.id', 'categories.name', DB::Raw('SUM(`transactions`.`amount`) AS `amount`')]);
|
->orderBy('amount');
|
||||||
|
|
||||||
|
return $query->get(['categories.id', 'categories.name', DB::Raw('SUM(`transactions`.`amount`) AS `amount`')]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -363,57 +386,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 journalsByExpenseAccount(Carbon $start, Carbon $end)
|
public function journalsByExpenseAccount(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 ($query) {
|
||||||
function ($q) {
|
$query->where(
|
||||||
$q->where('transaction_types.type', 'Withdrawal');
|
function ($q) {
|
||||||
$q->where('acm_from.data', '!=', '"sharedAsset"');
|
$q->where('transaction_types.type', 'Withdrawal');
|
||||||
}
|
$q->where('acm_from.data', '!=', '"sharedAsset"');
|
||||||
);
|
}
|
||||||
$query->orWhere(
|
);
|
||||||
function ($q) {
|
$query->orWhere(
|
||||||
$q->where('transaction_types.type', 'Transfer');
|
function ($q) {
|
||||||
$q->where('acm_to.data', '=', '"sharedAsset"');
|
$q->where('transaction_types.type', 'Transfer');
|
||||||
}
|
$q->where('acm_to.data', '=', '"sharedAsset"');
|
||||||
);
|
}
|
||||||
}
|
);
|
||||||
)
|
}
|
||||||
->before($end)
|
);
|
||||||
->after($start)
|
}
|
||||||
->where('transaction_journals.user_id', Auth::user()->id)
|
$query->before($end)
|
||||||
->groupBy('t_to.account_id')
|
->after($start)
|
||||||
->orderBy('amount', 'DESC')
|
->where('transaction_journals.user_id', Auth::user()->id)
|
||||||
->get(['t_to.account_id as id', 'ac_to.name as name', DB::Raw('SUM(t_to.amount) as `amount`')]);
|
->groupBy('t_to.account_id')
|
||||||
|
->orderBy('amount', 'DESC');
|
||||||
|
|
||||||
|
return $query->get(['t_to.account_id as id', 'ac_to.name as name', DB::Raw('SUM(t_to.amount) as `amount`')]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -17,19 +17,69 @@ interface ReportQueryInterface
|
|||||||
/**
|
/**
|
||||||
* This query retrieves a list of accounts that are active and not shared.
|
* This query retrieves a list of accounts that are active and not shared.
|
||||||
*
|
*
|
||||||
|
* @param bool $showSharedReports
|
||||||
|
*
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
public function accountList();
|
public function accountList($showSharedReports = false);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method will get a list of all expenses in a certain time period that have no budget
|
||||||
|
* and are balanced by a transfer to make up for it.
|
||||||
|
*
|
||||||
|
* @param Account $account
|
||||||
|
* @param Carbon $start
|
||||||
|
* @param Carbon $end
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function balancedTransactionsList(Account $account, Carbon $start, Carbon $end);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method will get the sum of all expenses in a certain time period that have no budget
|
||||||
|
* and are balanced by a transfer to make up for it.
|
||||||
|
*
|
||||||
|
* @param Account $account
|
||||||
|
* @param Carbon $start
|
||||||
|
* @param Carbon $end
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function balancedTransactionsSum(Account $account, Carbon $start, Carbon $end);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a users accounts combined with various meta-data related to the start and end date.
|
* Get a users accounts combined with various meta-data related to the start and end date.
|
||||||
*
|
*
|
||||||
* @param Carbon $start
|
* @param Carbon $start
|
||||||
* @param Carbon $end
|
* @param Carbon $end
|
||||||
|
* @param bool $showSharedReports
|
||||||
*
|
*
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
public function getAllAccounts(Carbon $start, Carbon $end);
|
public function getAllAccounts(Carbon $start, Carbon $end, $showSharedReports = false);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Grabs a summary of all expenses grouped by budget, related to the account.
|
||||||
|
*
|
||||||
|
* @param Account $account
|
||||||
|
* @param Carbon $start
|
||||||
|
* @param Carbon $end
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getBudgetSummary(Account $account, Carbon $start, Carbon $end);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of transaction journals that have no budget, filtered for the specified account
|
||||||
|
* and the specified date range.
|
||||||
|
*
|
||||||
|
* @param Account $account
|
||||||
|
* @param Carbon $start
|
||||||
|
* @param Carbon $end
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function getTransactionsWithoutBudget(Account $account, Carbon $start, Carbon $end);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method returns all "income" journals in a certain period, which are both transfers from a shared account
|
* This method returns all "income" journals in a certain period, which are both transfers from a shared account
|
||||||
@ -38,20 +88,22 @@ interface ReportQueryInterface
|
|||||||
*
|
*
|
||||||
* @param Carbon $start
|
* @param Carbon $start
|
||||||
* @param Carbon $end
|
* @param Carbon $end
|
||||||
|
* @param bool $showSharedReports
|
||||||
*
|
*
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
public function incomeByPeriod(Carbon $start, Carbon $end);
|
public function incomeByPeriod(Carbon $start, Carbon $end, $showSharedReports = false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a list of expenses grouped by the budget they were filed under.
|
* Gets a list of expenses grouped by the budget they were filed under.
|
||||||
*
|
*
|
||||||
* @param Carbon $start
|
* @param Carbon $start
|
||||||
* @param Carbon $end
|
* @param Carbon $end
|
||||||
|
* @param bool $showSharedReports
|
||||||
*
|
*
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
public function journalsByBudget(Carbon $start, Carbon $end);
|
public function journalsByBudget(Carbon $start, Carbon $end, $showSharedReports = false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a list of categories and the expenses therein, grouped by the relevant category.
|
* Gets a list of categories and the expenses therein, grouped by the relevant category.
|
||||||
@ -59,10 +111,11 @@ interface ReportQueryInterface
|
|||||||
*
|
*
|
||||||
* @param Carbon $start
|
* @param Carbon $start
|
||||||
* @param Carbon $end
|
* @param Carbon $end
|
||||||
|
* @param bool $showSharedReports
|
||||||
*
|
*
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
public function journalsByCategory(Carbon $start, Carbon $end);
|
public function journalsByCategory(Carbon $start, Carbon $end, $showSharedReports = false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a list of expense accounts and the expenses therein, grouped by that expense account.
|
* Gets a list of expense accounts and the expenses therein, grouped by that expense account.
|
||||||
@ -72,10 +125,11 @@ interface ReportQueryInterface
|
|||||||
*
|
*
|
||||||
* @param Carbon $start
|
* @param Carbon $start
|
||||||
* @param Carbon $end
|
* @param Carbon $end
|
||||||
|
* @param bool $showSharedReports
|
||||||
*
|
*
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
public function journalsByExpenseAccount(Carbon $start, Carbon $end);
|
public function journalsByExpenseAccount(Carbon $start, Carbon $end, $showSharedReports = false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method returns all deposits into asset accounts, grouped by the revenue account,
|
* This method returns all deposits into asset accounts, grouped by the revenue account,
|
||||||
@ -108,51 +162,4 @@ interface ReportQueryInterface
|
|||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
public function sharedExpensesByCategory(Carbon $start, Carbon $end);
|
public function sharedExpensesByCategory(Carbon $start, Carbon $end);
|
||||||
|
|
||||||
/**
|
|
||||||
* Grabs a summary of all expenses grouped by budget, related to the account.
|
|
||||||
*
|
|
||||||
* @param Account $account
|
|
||||||
* @param Carbon $start
|
|
||||||
* @param Carbon $end
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function getBudgetSummary(Account $account, Carbon $start, Carbon $end);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a list of transaction journals that have no budget, filtered for the specified account
|
|
||||||
* and the specified date range.
|
|
||||||
*
|
|
||||||
* @param Account $account
|
|
||||||
* @param Carbon $start
|
|
||||||
* @param Carbon $end
|
|
||||||
*
|
|
||||||
* @return Collection
|
|
||||||
*/
|
|
||||||
public function getTransactionsWithoutBudget(Account $account, Carbon $start, Carbon $end);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method will get a list of all expenses in a certain time period that have no budget
|
|
||||||
* and are balanced by a transfer to make up for it.
|
|
||||||
*
|
|
||||||
* @param Account $account
|
|
||||||
* @param Carbon $start
|
|
||||||
* @param Carbon $end
|
|
||||||
*
|
|
||||||
* @return Collection
|
|
||||||
*/
|
|
||||||
public function balancedTransactionsList(Account $account, Carbon $start, Carbon $end);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method will get the sum of all expenses in a certain time period that have no budget
|
|
||||||
* and are balanced by a transfer to make up for it.
|
|
||||||
*
|
|
||||||
* @param Account $account
|
|
||||||
* @param Carbon $start
|
|
||||||
* @param Carbon $end
|
|
||||||
*
|
|
||||||
* @return Collection
|
|
||||||
*/
|
|
||||||
public function balancedTransactionsSum(Account $account, Carbon $start, Carbon $end);
|
|
||||||
}
|
}
|
@ -9,6 +9,7 @@ use FireflyIII\Http\Requests;
|
|||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use Illuminate\Database\Query\JoinClause;
|
use Illuminate\Database\Query\JoinClause;
|
||||||
|
use Preferences;
|
||||||
use Session;
|
use Session;
|
||||||
use Steam;
|
use Steam;
|
||||||
use View;
|
use View;
|
||||||
@ -51,11 +52,16 @@ class ReportController extends Controller
|
|||||||
$end->endOfMonth();
|
$end->endOfMonth();
|
||||||
$start->subDay();
|
$start->subDay();
|
||||||
|
|
||||||
|
// shared accounts preference:
|
||||||
|
$pref = Preferences::get('showSharedReports', false);
|
||||||
|
$showSharedReports = $pref->data;
|
||||||
|
|
||||||
|
|
||||||
$dayEarly = clone $date;
|
$dayEarly = clone $date;
|
||||||
$subTitle = 'Budget report for ' . $date->format('F Y');
|
$subTitle = 'Budget report for ' . $date->format('F Y');
|
||||||
$subTitleIcon = 'fa-calendar';
|
$subTitleIcon = 'fa-calendar';
|
||||||
$dayEarly = $dayEarly->subDay();
|
$dayEarly = $dayEarly->subDay();
|
||||||
$accounts = $query->getAllAccounts($start, $end);
|
$accounts = $query->getAllAccounts($start, $end, $showSharedReports);
|
||||||
$start->addDay();
|
$start->addDay();
|
||||||
|
|
||||||
$accounts->each(
|
$accounts->each(
|
||||||
@ -89,17 +95,20 @@ class ReportController extends Controller
|
|||||||
)
|
)
|
||||||
->get(['budgets.*', 'budget_limits.amount as amount']);
|
->get(['budgets.*', 'budget_limits.amount as amount']);
|
||||||
$budgets = Steam::makeArray($set);
|
$budgets = Steam::makeArray($set);
|
||||||
$amountSet = $query->journalsByBudget($start, $end);
|
$amountSet = $query->journalsByBudget($start, $end, $showSharedReports);
|
||||||
$amounts = Steam::makeArray($amountSet);
|
$amounts = Steam::makeArray($amountSet);
|
||||||
$budgets = Steam::mergeArrays($budgets, $amounts);
|
$budgets = Steam::mergeArrays($budgets, $amounts);
|
||||||
$budgets[0]['spent'] = isset($budgets[0]['spent']) ? $budgets[0]['spent'] : 0.0;
|
$budgets[0]['spent'] = isset($budgets[0]['spent']) ? $budgets[0]['spent'] : 0.0;
|
||||||
$budgets[0]['amount'] = isset($budgets[0]['amount']) ? $budgets[0]['amount'] : 0.0;
|
$budgets[0]['amount'] = isset($budgets[0]['amount']) ? $budgets[0]['amount'] : 0.0;
|
||||||
$budgets[0]['name'] = 'No budget';
|
$budgets[0]['name'] = 'No budget';
|
||||||
|
|
||||||
// find transactions to shared expense accounts, which are without a budget by default:
|
// find transactions to shared asset accounts, which are without a budget by default:
|
||||||
$transfers = $query->sharedExpenses($start, $end);
|
// which is only relevant when shared asset accounts are hidden.
|
||||||
foreach ($transfers as $transfer) {
|
if ($showSharedReports === false) {
|
||||||
$budgets[0]['spent'] += floatval($transfer->amount) * -1;
|
$transfers = $query->sharedExpenses($start, $end);
|
||||||
|
foreach ($transfers as $transfer) {
|
||||||
|
$budgets[0]['spent'] += floatval($transfer->amount) * -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -152,6 +161,14 @@ class ReportController extends Controller
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Account $account
|
||||||
|
* @param string $year
|
||||||
|
* @param string $month
|
||||||
|
* @param ReportQueryInterface $query
|
||||||
|
*
|
||||||
|
* @return View
|
||||||
|
*/
|
||||||
public function modalLeftUnbalanced(Account $account, $year = '2014', $month = '1', ReportQueryInterface $query)
|
public function modalLeftUnbalanced(Account $account, $year = '2014', $month = '1', ReportQueryInterface $query)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
@ -217,6 +234,9 @@ class ReportController extends Controller
|
|||||||
$subTitleIcon = 'fa-calendar';
|
$subTitleIcon = 'fa-calendar';
|
||||||
$displaySum = true; // to show sums in report.
|
$displaySum = true; // to show sums in report.
|
||||||
|
|
||||||
|
$pref = Preferences::get('showSharedReports', false);
|
||||||
|
$showSharedReports = $pref->data;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -232,14 +252,14 @@ class ReportController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Start getIncomeForMonth DONE
|
* Start getIncomeForMonth DONE
|
||||||
*/
|
*/
|
||||||
$income = $query->incomeByPeriod($start, $end);
|
$income = $query->incomeByPeriod($start, $end, $showSharedReports);
|
||||||
/**
|
/**
|
||||||
* End getIncomeForMonth DONE
|
* End getIncomeForMonth DONE
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* Start getExpenseGroupedForMonth DONE
|
* Start getExpenseGroupedForMonth DONE
|
||||||
*/
|
*/
|
||||||
$set = $query->journalsByExpenseAccount($start, $end);
|
$set = $query->journalsByExpenseAccount($start, $end, $showSharedReports);
|
||||||
$expenses = Steam::makeArray($set);
|
$expenses = Steam::makeArray($set);
|
||||||
$expenses = Steam::sortArray($expenses);
|
$expenses = Steam::sortArray($expenses);
|
||||||
$expenses = Steam::limitArray($expenses, 10);
|
$expenses = Steam::limitArray($expenses, 10);
|
||||||
@ -257,7 +277,7 @@ class ReportController extends Controller
|
|||||||
)
|
)
|
||||||
->get(['budgets.*', 'budget_limits.amount as amount']);
|
->get(['budgets.*', 'budget_limits.amount as amount']);
|
||||||
$budgets = Steam::makeArray($set);
|
$budgets = Steam::makeArray($set);
|
||||||
$amountSet = $query->journalsByBudget($start, $end);
|
$amountSet = $query->journalsByBudget($start, $end, $showSharedReports);
|
||||||
$amounts = Steam::makeArray($amountSet);
|
$amounts = Steam::makeArray($amountSet);
|
||||||
$budgets = Steam::mergeArrays($budgets, $amounts);
|
$budgets = Steam::mergeArrays($budgets, $amounts);
|
||||||
$budgets[0]['spent'] = isset($budgets[0]['spent']) ? $budgets[0]['spent'] : 0.0;
|
$budgets[0]['spent'] = isset($budgets[0]['spent']) ? $budgets[0]['spent'] : 0.0;
|
||||||
@ -265,9 +285,11 @@ class ReportController extends Controller
|
|||||||
$budgets[0]['name'] = 'No budget';
|
$budgets[0]['name'] = 'No budget';
|
||||||
|
|
||||||
// find transactions to shared expense accounts, which are without a budget by default:
|
// find transactions to shared expense accounts, which are without a budget by default:
|
||||||
$transfers = $query->sharedExpenses($start, $end);
|
if ($showSharedReports === false) {
|
||||||
foreach ($transfers as $transfer) {
|
$transfers = $query->sharedExpenses($start, $end);
|
||||||
$budgets[0]['spent'] += floatval($transfer->amount) * -1;
|
foreach ($transfers as $transfer) {
|
||||||
|
$budgets[0]['spent'] += floatval($transfer->amount) * -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -281,9 +303,13 @@ class ReportController extends Controller
|
|||||||
$categories = Steam::makeArray($result);
|
$categories = Steam::makeArray($result);
|
||||||
|
|
||||||
// all transfers
|
// all transfers
|
||||||
$result = $query->sharedExpensesByCategory($start, $end);
|
if ($showSharedReports === false) {
|
||||||
$transfers = Steam::makeArray($result);
|
$result = $query->sharedExpensesByCategory($start, $end);
|
||||||
$merged = Steam::mergeArrays($categories, $transfers);
|
$transfers = Steam::makeArray($result);
|
||||||
|
$merged = Steam::mergeArrays($categories, $transfers);
|
||||||
|
} else {
|
||||||
|
$merged = $categories;
|
||||||
|
}
|
||||||
|
|
||||||
// sort.
|
// sort.
|
||||||
$sorted = Steam::sortNegativeArray($merged);
|
$sorted = Steam::sortNegativeArray($merged);
|
||||||
|
@ -138,9 +138,9 @@ class TestDataSeeder extends Seeder
|
|||||||
$acc_c = Account::create(['user_id' => $user->id, 'account_type_id' => $assetType->id, 'name' => 'Delete me', 'active' => 1]);
|
$acc_c = Account::create(['user_id' => $user->id, 'account_type_id' => $assetType->id, 'name' => 'Delete me', 'active' => 1]);
|
||||||
|
|
||||||
// create account meta:
|
// create account meta:
|
||||||
$meta_a = AccountMeta::create(['account_id' => $acc_a->id, 'name' => 'accountRole', 'data' => 'defaultExpense']);
|
$meta_a = AccountMeta::create(['account_id' => $acc_a->id, 'name' => 'accountRole', 'data' => 'defaultAsset']);
|
||||||
$meta_b = AccountMeta::create(['account_id' => $acc_b->id, 'name' => 'accountRole', 'data' => 'defaultExpense']);
|
$meta_b = AccountMeta::create(['account_id' => $acc_b->id, 'name' => 'accountRole', 'data' => 'defaultAsset']);
|
||||||
$meta_c = AccountMeta::create(['account_id' => $acc_c->id, 'name' => 'accountRole', 'data' => 'defaultExpense']);
|
$meta_c = AccountMeta::create(['account_id' => $acc_c->id, 'name' => 'accountRole', 'data' => 'defaultAsset']);
|
||||||
// var_dump($meta_a->toArray());
|
// var_dump($meta_a->toArray());
|
||||||
// var_dump($meta_b->toArray());
|
// var_dump($meta_b->toArray());
|
||||||
// var_dump($meta_c->toArray());
|
// var_dump($meta_c->toArray());
|
||||||
|
Loading…
Reference in New Issue
Block a user