mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-10 12:24:50 +00:00
Refactor some views for double account report.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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.';
|
||||
|
||||
Reference in New Issue
Block a user