mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-03 12:10:42 -06:00
First attempt at including expense report.
This commit is contained in:
parent
67fe35d564
commit
ad01891a67
@ -473,4 +473,25 @@ class ReportHelper implements ReportHelperInterface
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -83,15 +83,26 @@ interface ReportHelperInterface
|
||||
public function getCategoryReport(Carbon $start, Carbon $end, $shared);
|
||||
|
||||
/**
|
||||
* Get a full report on the users expenses during the period.
|
||||
* Get a full report on the users expenses during the period.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param boolean $shared
|
||||
*
|
||||
* @return Expense
|
||||
*/
|
||||
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 boolean $shared
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return Expense
|
||||
*/
|
||||
public function getExpenseReport($start, $end, $shared);
|
||||
public function getExpenseReportForList($start, $end, Collection $accounts);
|
||||
|
||||
/**
|
||||
* 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\Query\JoinClause;
|
||||
use Illuminate\Support\Collection;
|
||||
use Steam;
|
||||
|
||||
/**
|
||||
* Class ReportQuery
|
||||
@ -301,7 +300,7 @@ class ReportQuery implements ReportQueryInterface
|
||||
$query->orWhere(
|
||||
function (Builder $q) {
|
||||
$q->where('transaction_types.type', TransactionType::TRANSFER);
|
||||
$q->where('acm_from.data', '=', '"sharedAsset"');
|
||||
$q->where('acm_from.data', '=', '"sharedAsset"');
|
||||
$q->where('acm_to.data', '!=', '"sharedAsset"');
|
||||
}
|
||||
);
|
||||
@ -336,4 +335,65 @@ class ReportQuery implements ReportQueryInterface
|
||||
|
||||
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);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
@ -243,11 +243,11 @@ class ReportController extends Controller
|
||||
// get report stuff!
|
||||
$accounts = $this->helper->getAccountReportForList($start, $end, $list);
|
||||
$incomes = $this->helper->getIncomeReportForList($start, $end, $list);
|
||||
// $expenses = $this->helper->getExpenseReportForList($start, $end, $list);
|
||||
// $budgets = $this->helper->getBudgetReportForList($start, $end, $list);
|
||||
// $categories = $this->helper->getCategoryReportForList($start, $end, $list);
|
||||
// $balance = $this->helper->getBalanceReportForList($start, $end, $list);
|
||||
// $bills = $this->helper->getBillReportForList($start, $end);
|
||||
$expenses = $this->helper->getExpenseReportForList($start, $end, $list);
|
||||
// $budgets = $this->helper->getBudgetReportForList($start, $end, $list);
|
||||
// $categories = $this->helper->getCategoryReportForList($start, $end, $list);
|
||||
// $balance = $this->helper->getBalanceReportForList($start, $end, $list);
|
||||
// $bills = $this->helper->getBillReportForList($start, $end);
|
||||
|
||||
// continue!
|
||||
return view(
|
||||
|
Loading…
Reference in New Issue
Block a user