More code for #159 [skip ci]

This commit is contained in:
James Cole 2016-04-03 11:14:36 +02:00
parent 885b56c465
commit 03691c81c2
4 changed files with 88 additions and 13 deletions

View File

@ -48,6 +48,9 @@ class ReportController extends Controller
case 'expense-entry':
$html = $this->expenseEntry($attributes);
break;
case 'income-entry':
$html = $this->incomeEntry($attributes);
break;
}
return Response::json(['html' => $html]);
@ -83,6 +86,25 @@ class ReportController extends Controller
return $view;
}
/**
* Returns all the incomes that went to the given asset account.
*
* @param $attributes
*
* @return string
* @throws FireflyException
*/
private function incomeEntry($attributes)
{
/** @var AccountRepositoryInterface $repository */
$repository = app('FireflyIII\Repositories\Account\AccountRepositoryInterface');
$account = $repository->find(intval($attributes['accountId']));
$journals = $repository->getIncomeByDestination($account, $attributes['accounts'], $attributes['startDate'], $attributes['endDate']);
$view = view('popup.report.income-entry', compact('journals'))->render();
return $view;
}
/**
* Returns all the expenses that went to the given expense account.
*

View File

@ -676,4 +676,29 @@ class AccountRepository implements AccountRepositoryInterface
}
}
/**
* Returns a list of transactions TO the given (asset) $account, but none from the
* given list of accounts
*
* @param Account $account
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
* @return Collection
*/
public function getIncomeByDestination(Account $account, Collection $accounts, Carbon $start, Carbon $end)
{
$ids = $accounts->pluck('id')->toArray();
$journals = $this->user->transactionjournals()
->expanded()
->before($end)
->where('source_account.id', $account->id)
->whereIn('destination_account.id', $ids)
->after($start)
->get(TransactionJournal::QUERYFIELDS);
return $journals;
}
}

View File

@ -20,19 +20,6 @@ use Illuminate\Support\Collection;
interface AccountRepositoryInterface
{
/**
* Returns a list of transactions TO the $account, not including transfers
* and/or expenses in the $accounts list.
*
* @param Account $account
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
* @return Collection
*/
public function getExpensesByDestination(Account $account, Collection $accounts, Carbon $start, Carbon $end);
/**
* @param array $types
*
@ -84,6 +71,19 @@ interface AccountRepositoryInterface
*/
public function getCreditCards(Carbon $date): Collection;
/**
* Returns a list of transactions TO the given (expense) $account, all from the
* given list of accounts
*
* @param Account $account
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
* @return Collection
*/
public function getExpensesByDestination(Account $account, Collection $accounts, Carbon $start, Carbon $end);
/**
* @param TransactionJournal $journal
* @param Account $account
@ -108,6 +108,19 @@ interface AccountRepositoryInterface
*/
public function getFrontpageTransactions(Account $account, Carbon $start, Carbon $end): Collection;
/**
* Returns a list of transactions TO the given (asset) $account, but none from the
* given list of accounts
*
* @param Account $account
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
* @return Collection
*/
public function getIncomeByDestination(Account $account, Collection $accounts, Carbon $start, Carbon $end);
/**
* @param Account $account
* @param $page

View File

@ -0,0 +1,15 @@
<!-- Modal dialog to show budget expenses -->
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="{{ 'close'|_ }}"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="incomeEntryTitle">{{ 'income_entry'|_ }}</h4>
</div>
<div class="modal-body">
{% include 'popup/list/journals.twig' %}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">{{ 'close'|_ }}</button>
</div>
</div>
</div>