Refactor some views for double account report.

This commit is contained in:
James Cole 2019-09-03 17:30:45 +02:00
parent 7fb5c12a29
commit 4743230136
8 changed files with 43 additions and 34 deletions

View File

@ -57,12 +57,11 @@ class MonthReportGenerator implements ReportGeneratorInterface
$preferredPeriod = $this->preferredPeriod();
try {
$result = view(
'reports.account.report',
compact('accountIds', 'reportType', 'expenseIds', 'preferredPeriod')
'reports.double.report', compact('accountIds', 'reportType', 'expenseIds', 'preferredPeriod')
)->with('start', $this->start)->with('end', $this->end)->render();
} catch (Throwable $e) {
Log::error(sprintf('Cannot render reports.account.report: %s', $e->getMessage()));
$result = 'Could not render report view.';
Log::error(sprintf('Cannot render reports.double.report: %s', $e->getMessage()));
$result = sprintf('Could not render report view: %s', $e->getMessage());
}
return $result;

View File

@ -320,7 +320,7 @@ class ReportController extends Controller
$categories = implode(',', $request->getCategoryList()->pluck('id')->toArray());
$budgets = implode(',', $request->getBudgetList()->pluck('id')->toArray());
$tags = implode(',', $request->getTagList()->pluck('id')->toArray());
$expense = implode(',', $request->getExpenseList()->pluck('id')->toArray());
$double = implode(',', $request->getDoubleList()->pluck('id')->toArray());
$uri = route('reports.index');
if (0 === $request->getAccountList()->count()) {
@ -348,7 +348,7 @@ class ReportController extends Controller
return redirect(route('reports.index'));
}
if ('account' === $reportType && 0 === $request->getExpenseList()->count()) {
if ('account' === $reportType && 0 === $request->getDoubleList()->count()) {
session()->flash('error', (string)trans('firefly.select_at_least_one_expense'));
return redirect(route('reports.index'));
@ -375,7 +375,7 @@ class ReportController extends Controller
$uri = route('reports.report.tag', [$accounts, $tags, $start, $end]);
break;
case 'account':
$uri = route('reports.report.account', [$accounts, $expense, $start, $end]);
$uri = route('reports.report.account', [$accounts, $double, $start, $end]);
break;
}

View File

@ -147,11 +147,11 @@ class ReportFormRequest extends Request
}
/**
* Validate list of expense accounts.
* Validate list of accounts which exist twice in system.
*
* @return Collection
*/
public function getExpenseList(): Collection
public function getDoubleList(): Collection
{
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\Http\Controllers;
use FireflyIII\Helpers\Report\PopupReportInterface;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Budget;
use FireflyIII\Models\Rule;
@ -33,7 +34,6 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Throwable;
@ -53,15 +53,28 @@ trait RenderPartialViews
{
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
$expense = $repository->getActiveAccountsByType([AccountType::EXPENSE]);
$revenue = $repository->getActiveAccountsByType([AccountType::REVENUE]);
$set = new Collection;
$names = $revenue->pluck('name')->toArray();
foreach ($expense as $exp) {
if (in_array($exp->name, $names, true)) {
$set->push($exp);
$expense = $repository->getActiveAccountsByType([AccountType::EXPENSE, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]);
$revenue = $repository->getActiveAccountsByType([AccountType::REVENUE, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]);
$set = [];
/** @var Account $account */
foreach ($expense as $account) {
// loop revenue, find same account:
/** @var Account $otherAccount */
foreach ($revenue as $otherAccount) {
if (
(
($otherAccount->name === $account->name)
||
(null !== $account->iban && null !== $otherAccount->iban && $otherAccount->iban === $account->iban)
)
&& $otherAccount->id !== $account->id
) {
$set[] = $account;
}
}
}
// @codeCoverageIgnoreStart
try {
$result = view('reports.options.account', compact('set'))->render();
@ -97,7 +110,7 @@ trait RenderPartialViews
$journals = $popupHelper->balanceForBudget($budget, $account, $attributes);
// @codeCoverageIgnoreStart
try {
$view = view('popup.report.balance-amount', compact('journals', 'budget','account'))->render();
$view = view('popup.report.balance-amount', compact('journals', 'budget', 'account'))->render();
} catch (Throwable $e) {
Log::error(sprintf('Could not render: %s', $e->getMessage()));
$view = 'Firefly III could not render the view. Please see the log files.';

View File

@ -390,7 +390,7 @@ return [
// lists
'accountList' => AccountList::class,
'expenseList' => AccountList::class,
'doubleList' => AccountList::class,
'budgetList' => BudgetList::class,
'journalList' => JournalList::class,
'categoryList' => CategoryList::class,

View File

@ -1,7 +1,7 @@
{% extends "./layout/default" %}
{% block breadcrumbs %}
{{ Breadcrumbs.render(Route.getCurrentRoute.getName, accountIds, expenseIds, start, end) }}
{#{{ Breadcrumbs.render(Route.getCurrentRoute.getName, accountIds, expenseIds, start, end) }}#}
{% endblock %}
{% block content %}

View File

@ -3,7 +3,7 @@
<div class="col-sm-9">
<select id="inputExpRevAccounts" name="exp_rev[]" multiple="multiple" class="form-control">
{% for account in set %}
<option value="{{ account.id }}" label="{{ account.name }}">{{ account.name }}</option>
<option value="{{ account.id }}" label="{{ account.name }}{% if account.iban !='' %} ({{ account.iban }}){% endif %}">{{ account.name }}{% if account.iban !='' %} ({{ account.iban }}){% endif %}</option>
{% endfor %}
</select>
</div>

View File

@ -444,10 +444,8 @@ Route::group(
Route::group(
['middleware' => 'user-full-auth', 'namespace' => 'FireflyIII\Http\Controllers\Chart', 'prefix' => 'chart/expense', 'as' => 'chart.expense.'],
static function () {
Route::get(
'operations/{accountList}/{expenseList}/{start_date}/{end_date}',
['uses' => 'ExpenseReportController@mainChart', 'as' => 'main']
);
// TODO replace me.
//Route::get('operations/{accountList}/{expenseList}/{start_date}/{end_date}', ['uses' => 'ExpenseReportController@mainChart', 'as' => 'main']);
}
);
@ -689,7 +687,7 @@ Route::group(
Route::get('category/{accountList}/{categoryList}/{start_date}/{end_date}', ['uses' => 'ReportController@categoryReport', 'as' => 'report.category']);
Route::get('budget/{accountList}/{budgetList}/{start_date}/{end_date}', ['uses' => 'ReportController@budgetReport', 'as' => 'report.budget']);
Route::get('tag/{accountList}/{tagList}/{start_date}/{end_date}', ['uses' => 'ReportController@tagReport', 'as' => 'report.tag']);
Route::get('account/{accountList}/{expenseList}/{start_date}/{end_date}', ['uses' => 'ReportController@accountReport', 'as' => 'report.account']);
Route::get('account/{accountList}/{doubleList}/{start_date}/{end_date}', ['uses' => 'ReportController@accountReport', 'as' => 'report.account']);
Route::post('', ['uses' => 'ReportController@postIndex', 'as' => 'index.post']);
}
@ -720,18 +718,17 @@ Route::group(
*/
Route::group(
['middleware' => 'user-full-auth', 'namespace' => 'FireflyIII\Http\Controllers\Report', 'prefix' => 'report-data/expense', 'as' => 'report-data.expense.'],
function () {
static function () {
// TODO replace me.
// spent per period
Route::get('spent/{accountList}/{expenseList}/{start_date}/{end_date}', ['uses' => 'ExpenseController@spent', 'as' => 'spent']);
//Route::get('spent/{accountList}/{expenseList}/{start_date}/{end_date}', ['uses' => 'ExpenseController@spent', 'as' => 'spent']);
// per category && per budget
Route::get('category/{accountList}/{expenseList}/{start_date}/{end_date}', ['uses' => 'ExpenseController@category', 'as' => 'category']);
Route::get('budget/{accountList}/{expenseList}/{start_date}/{end_date}', ['uses' => 'ExpenseController@budget', 'as' => 'budget']);
//Route::get('category/{accountList}/{expenseList}/{start_date}/{end_date}', ['uses' => 'ExpenseController@category', 'as' => 'category']);
//Route::get('budget/{accountList}/{expenseList}/{start_date}/{end_date}', ['uses' => 'ExpenseController@budget', 'as' => 'budget']);
//expense earned top X
Route::get('expenses/{accountList}/{expenseList}/{start_date}/{end_date}', ['uses' => 'ExpenseController@topExpense', 'as' => 'expenses']);
Route::get('income/{accountList}/{expenseList}/{start_date}/{end_date}', ['uses' => 'ExpenseController@topIncome', 'as' => 'income']);
//Route::get('expenses/{accountList}/{expenseList}/{start_date}/{end_date}', ['uses' => 'ExpenseController@topExpense', 'as' => 'expenses']);
//Route::get('income/{accountList}/{expenseList}/{start_date}/{end_date}', ['uses' => 'ExpenseController@topIncome', 'as' => 'income']);
}
);