mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-19 19:01:58 +00:00
First attempt at including expense report.
This commit is contained in:
@@ -473,4 +473,25 @@ class ReportHelper implements ReportHelperInterface
|
|||||||
|
|
||||||
return $object;
|
return $object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a full report on the users expenses during the period for a list of accounts.
|
||||||
|
*
|
||||||
|
* @param Carbon $start
|
||||||
|
* @param Carbon $end
|
||||||
|
* @param Collection $accounts
|
||||||
|
*
|
||||||
|
* @return Expense
|
||||||
|
*/
|
||||||
|
public function getExpenseReportForList($start, $end, Collection $accounts)
|
||||||
|
{
|
||||||
|
$object = new Expense;
|
||||||
|
$set = $this->query->expenseInPeriodCorrectedForList($start, $end, $accounts);
|
||||||
|
foreach ($set as $entry) {
|
||||||
|
$object->addToTotal($entry->amount_positive);
|
||||||
|
$object->addOrCreateExpense($entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $object;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -93,6 +93,17 @@ interface ReportHelperInterface
|
|||||||
*/
|
*/
|
||||||
public function getExpenseReport($start, $end, $shared);
|
public function getExpenseReport($start, $end, $shared);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a full report on the users expenses during the period for a list of accounts.
|
||||||
|
*
|
||||||
|
* @param Carbon $start
|
||||||
|
* @param Carbon $end
|
||||||
|
* @param Collection $accounts
|
||||||
|
*
|
||||||
|
* @return Expense
|
||||||
|
*/
|
||||||
|
public function getExpenseReportForList($start, $end, Collection $accounts);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a full report on the users incomes during the period.
|
* Get a full report on the users incomes during the period.
|
||||||
*
|
*
|
||||||
|
@@ -12,7 +12,6 @@ use FireflyIII\Models\TransactionType;
|
|||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Query\JoinClause;
|
use Illuminate\Database\Query\JoinClause;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Steam;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ReportQuery
|
* Class ReportQuery
|
||||||
@@ -336,4 +335,65 @@ class ReportQuery implements ReportQueryInterface
|
|||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* See ReportQueryInterface::incomeInPeriodCorrected
|
||||||
|
*
|
||||||
|
* This method returns all "expense" journals in a certain period, which are both transfers to a shared account
|
||||||
|
* and "ordinary" withdrawals. The query used is almost equal to ReportQueryInterface::journalsByRevenueAccount but it does
|
||||||
|
* not group and returns different fields.
|
||||||
|
*
|
||||||
|
* @param Carbon $start
|
||||||
|
* @param Carbon $end
|
||||||
|
* @param Collection $accounts
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function expenseInPeriodCorrectedForList(Carbon $start, Carbon $end, Collection $accounts)
|
||||||
|
{
|
||||||
|
$ids = [];
|
||||||
|
|
||||||
|
/** @var Account $account */
|
||||||
|
foreach ($accounts as $account) {
|
||||||
|
$ids[] = $account->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = $this->queryJournalsWithTransactions($start, $end);
|
||||||
|
$query->where(
|
||||||
|
function (Builder $query) {
|
||||||
|
$query->where(
|
||||||
|
function (Builder $q) { // only get withdrawals not from a shared account
|
||||||
|
$q->where('transaction_types.type', TransactionType::WITHDRAWAL);
|
||||||
|
$q->where('acm_from.data', '!=', '"sharedAsset"');
|
||||||
|
}
|
||||||
|
);
|
||||||
|
$query->orWhere(
|
||||||
|
function (Builder $q) { // and transfers from a shared account.
|
||||||
|
$q->where('transaction_types.type', TransactionType::TRANSFER);
|
||||||
|
$q->where('acm_to.data', '=', '"sharedAsset"');
|
||||||
|
$q->where('acm_from.data', '!=', '"sharedAsset"');
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// expense goes from the selected accounts:
|
||||||
|
$query->whereIn('ac_from.id', $ids);
|
||||||
|
|
||||||
|
$query->orderBy('transaction_journals.date');
|
||||||
|
$data = $query->get( // get everything
|
||||||
|
['transaction_journals.*', 'transaction_types.type', 'ac_to.name as name', 'ac_to.id as account_id', 'ac_to.encrypted as account_encrypted']
|
||||||
|
);
|
||||||
|
|
||||||
|
$data->each(
|
||||||
|
function (TransactionJournal $journal) {
|
||||||
|
if (intval($journal->account_encrypted) == 1) {
|
||||||
|
$journal->name = Crypt::decrypt($journal->name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -31,6 +31,22 @@ interface ReportQueryInterface
|
|||||||
*/
|
*/
|
||||||
public function expenseInPeriodCorrected(Carbon $start, Carbon $end, $includeShared = false);
|
public function expenseInPeriodCorrected(Carbon $start, Carbon $end, $includeShared = false);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* See ReportQueryInterface::incomeInPeriodCorrected
|
||||||
|
*
|
||||||
|
* This method returns all "expense" journals in a certain period, which are both transfers to a shared account
|
||||||
|
* and "ordinary" withdrawals. The query used is almost equal to ReportQueryInterface::journalsByRevenueAccount but it does
|
||||||
|
* not group and returns different fields.
|
||||||
|
*
|
||||||
|
* @param Carbon $start
|
||||||
|
* @param Carbon $end
|
||||||
|
* @param Collection $accounts
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function expenseInPeriodCorrectedForList(Carbon $start, Carbon $end, Collection $accounts);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
*
|
*
|
||||||
|
@@ -243,7 +243,7 @@ class ReportController extends Controller
|
|||||||
// get report stuff!
|
// get report stuff!
|
||||||
$accounts = $this->helper->getAccountReportForList($start, $end, $list);
|
$accounts = $this->helper->getAccountReportForList($start, $end, $list);
|
||||||
$incomes = $this->helper->getIncomeReportForList($start, $end, $list);
|
$incomes = $this->helper->getIncomeReportForList($start, $end, $list);
|
||||||
// $expenses = $this->helper->getExpenseReportForList($start, $end, $list);
|
$expenses = $this->helper->getExpenseReportForList($start, $end, $list);
|
||||||
// $budgets = $this->helper->getBudgetReportForList($start, $end, $list);
|
// $budgets = $this->helper->getBudgetReportForList($start, $end, $list);
|
||||||
// $categories = $this->helper->getCategoryReportForList($start, $end, $list);
|
// $categories = $this->helper->getCategoryReportForList($start, $end, $list);
|
||||||
// $balance = $this->helper->getBalanceReportForList($start, $end, $list);
|
// $balance = $this->helper->getBalanceReportForList($start, $end, $list);
|
||||||
|
Reference in New Issue
Block a user