Expanded new report a bit. Mainly copy/paste work. Will have to see how it pans out.

This commit is contained in:
James Cole 2015-12-11 09:39:17 +01:00
parent 0a54caf202
commit 7f19b6957a
5 changed files with 126 additions and 5 deletions

View File

@ -452,4 +452,25 @@ class ReportHelper implements ReportHelperInterface
return $object;
}
/**
* Get a full report on the users incomes during the period for the given accounts.
*
* @param Carbon $start
* @param Carbon $end
* @param Collection $accounts
*
* @return Income
*/
public function getIncomeReportForList($start, $end, Collection $accounts)
{
$object = new Income;
$set = $this->query->incomeInPeriodCorrectedForList($start, $end, $accounts);
foreach ($set as $entry) {
$object->addToTotal($entry->amount_positive);
$object->addOrCreateIncome($entry);
}
return $object;
}
}

View File

@ -36,8 +36,8 @@ interface ReportHelperInterface
* This method generates a full report for the given period on all
* given accounts
*
* @param Carbon $start
* @param Carbon $end
* @param Carbon $start
* @param Carbon $end
* @param Collection $accounts
*
* @return AccountCollection
@ -104,6 +104,17 @@ interface ReportHelperInterface
*/
public function getIncomeReport($start, $end, $shared);
/**
* Get a full report on the users incomes during the period for the given accounts.
*
* @param Carbon $start
* @param Carbon $end
* @param Collection $accounts
*
* @return Income
*/
public function getIncomeReportForList($start, $end, Collection $accounts);
/**
* @param Carbon $date
*

View File

@ -104,6 +104,7 @@ class ReportQuery implements ReportQueryInterface
);
}
$set = $query->get(['accounts.*']);
return $set;
}
@ -141,7 +142,7 @@ class ReportQuery implements ReportQueryInterface
function (Builder $q) {
$q->where('transaction_types.type', TransactionType::TRANSFER);
$q->where('acm_from.data', '=', '"sharedAsset"');
$q->where('acm_to.data','!=','"sharedAsset"');
$q->where('acm_to.data', '!=', '"sharedAsset"');
}
);
}
@ -261,4 +262,79 @@ class ReportQuery implements ReportQueryInterface
return $query;
}
/**
* This method works the same way as ReportQueryInterface::incomeInPeriod does, but instead of returning results
* will simply list the transaction journals only. This should allow any follow up counting to be accurate with
* regards to tags. It will only get the incomes to the specified accounts.
*
* @param Carbon $start
* @param Carbon $end
* @param Collection $accounts
*
* @return Collection
*/
public function incomeInPeriodCorrectedForList(Carbon $start, Carbon $end, Collection $accounts)
{
$query = $this->queryJournalsWithTransactions($start, $end);
$ids = [];
/** @var Account $account */
foreach ($accounts as $account) {
$ids[] = $account->id;
}
// only get deposits not to a shared account
// and transfers to a shared account.
// OR is a deposit
// OR is a transfer FROM a shared account to NOT a shared account.
//
$query->where(
function (Builder $query) {
$query->where(
function (Builder $q) {
$q->where('transaction_types.type', TransactionType::DEPOSIT);
}
);
$query->orWhere(
function (Builder $q) {
$q->where('transaction_types.type', TransactionType::TRANSFER);
$q->where('acm_from.data', '=', '"sharedAsset"');
$q->where('acm_to.data', '!=', '"sharedAsset"');
}
);
}
);
// only include selected accounts.
$query->whereIn('acm_to.id', $ids);
$query->orderBy('transaction_journals.date');
// get everything
$data = $query->get(
['transaction_journals.*', 'transaction_types.type', 'ac_from.name as name', 'ac_from.id as account_id', 'ac_from.encrypted as account_encrypted']
);
$data->each(
function (TransactionJournal $journal) {
if (intval($journal->account_encrypted) == 1) {
$journal->name = Crypt::decrypt($journal->name);
}
}
);
$data = $data->filter(
function (TransactionJournal $journal) {
if ($journal->amount != 0) {
return $journal;
}
return null;
}
);
return $data;
}
}

View File

@ -55,6 +55,19 @@ interface ReportQueryInterface
*/
public function incomeInPeriodCorrected(Carbon $start, Carbon $end, $includeShared = false);
/**
* This method works the same way as ReportQueryInterface::incomeInPeriod does, but instead of returning results
* will simply list the transaction journals only. This should allow any follow up counting to be accurate with
* regards to tags. It will only get the incomes to the specified accounts.
*
* @param Carbon $start
* @param Carbon $end
* @param Collection $accounts
*
* @return Collection
*/
public function incomeInPeriodCorrectedForList(Carbon $start, Carbon $end, Collection $accounts);
/**
* Covers tags as well.
*

View File

@ -241,8 +241,8 @@ class ReportController extends Controller
$expenseTopLength = 8;
// get report stuff!
$accounts = $this->helper->getAccountReportForList($start, $end, $list);
// $incomes = $this->helper->getIncomeReportForList($start, $end, $list);
$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);