Code cleanup.

This commit is contained in:
James Cole
2021-03-28 11:46:23 +02:00
parent 2c575f3ca5
commit b5eeacc128
124 changed files with 1568 additions and 1384 deletions

View File

@@ -22,6 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Exceptions;
use Exception;
use FireflyIII\Models\Account;
use FireflyIII\Models\Attachment;

View File

@@ -207,6 +207,7 @@ class AccountFactory
if (null !== $result) {
Log::debug(sprintf('Found account type based on %d and "%s": "%s"', $accountTypeId, $accountType, $result->type));
}
return $result;
}

View File

@@ -22,6 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Factory;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Category;
use FireflyIII\User;

View File

@@ -22,6 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Factory;
use FireflyIII\Models\PiggyBank;
use FireflyIII\User;

View File

@@ -23,6 +23,7 @@
declare(strict_types=1);
namespace FireflyIII\Factory;
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Recurrence;
@@ -42,6 +43,7 @@ class RecurrenceFactory
private MessageBag $errors;
private User $user;
/**
* Constructor.
*

View File

@@ -44,6 +44,7 @@ class TransactionFactory
private TransactionJournal $journal;
private bool $reconciled;
private User $user;
/**
* Constructor.
*

View File

@@ -40,6 +40,7 @@ class TransactionGroupFactory
private $journalFactory;
/** @var User The user */
private $user;
/**
* TransactionGroupFactory constructor.
*/

View File

@@ -65,6 +65,7 @@ class YearReportGenerator implements ReportGeneratorInterface
return $result;
}
/**
* Set the accounts.
*

View File

@@ -22,6 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Handlers\Events;
use Exception;
use FireflyIII\Mail\AccessTokenCreatedMail;
use FireflyIII\Repositories\User\UserRepositoryInterface;

View File

@@ -22,6 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Handlers\Events;
use FireflyIII\Events\DestroyedTransactionGroup;
use FireflyIII\Events\RequestedSendWebhookMessages;
use FireflyIII\Generator\Webhook\MessageGeneratorInterface;

View File

@@ -23,12 +23,14 @@
declare(strict_types=1);
namespace FireflyIII\Handlers\Events;
use FireflyIII\Events\RequestedVersionCheckStatus;
use FireflyIII\Helpers\Update\UpdateTrait;
use FireflyIII\Models\Configuration;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\User;
use Log;
/**
* Class VersionCheckEventHandler
*/

View File

@@ -22,6 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Handlers\Events;
use FireflyIII\Jobs\SendWebhookMessage;
use FireflyIII\Models\WebhookMessage;
use Log;

View File

@@ -55,6 +55,7 @@ class AttachmentHelper implements AttachmentHelperInterface
/** @var Filesystem The disk where attachments are stored. */
protected $uploadDisk;
/**
* AttachmentHelper constructor.
*
@@ -69,6 +70,7 @@ class AttachmentHelper implements AttachmentHelperInterface
$this->attachments = new Collection;
$this->uploadDisk = Storage::disk('upload');
}
/**
* Returns the content of an attachment.
*

View File

@@ -52,6 +52,7 @@ trait AccountCollection
return $this;
}
/**
* These accounts must not be source accounts.
*
@@ -70,6 +71,7 @@ trait AccountCollection
return $this;
}
/**
* Define which accounts can be part of the source and destination transactions.
*
@@ -115,6 +117,7 @@ trait AccountCollection
return $this;
}
/**
* Define which accounts can be part of the source and destination transactions.
*
@@ -133,6 +136,7 @@ trait AccountCollection
return $this;
}
/**
* Define which accounts can be part of the source and destination transactions.
*
@@ -151,6 +155,7 @@ trait AccountCollection
return $this;
}
/**
* Either account can be set, but NOT both. This effectively excludes internal transfers.
*
@@ -187,6 +192,7 @@ trait AccountCollection
return $this;
}
/**
* Will include the source and destination account names and types.
*

View File

@@ -102,6 +102,7 @@ trait TimeCollection
return $this;
}
/**
* Collect transactions updated on a specific date.
*

View File

@@ -485,6 +485,25 @@ class GroupCollector implements GroupCollectorInterface
return $this;
}
/**
* Join table to get attachment information.
*/
private function joinAttachmentTables(): void
{
if (false === $this->hasJoinedAttTables) {
// join some extra tables:
$this->hasJoinedAttTables = true;
$this->query->leftJoin('attachments', 'attachments.attachable_id', '=', 'transaction_journals.id')
->where(
static function (EloquentBuilder $q1) {
$q1->where('attachments.attachable_type', TransactionJournal::class);
$q1->where('attachments.uploaded', 1);
$q1->orWhereNull('attachments.attachable_type');
}
);
}
}
/**
* Build the query.
*/
@@ -528,25 +547,6 @@ class GroupCollector implements GroupCollectorInterface
->orderBy('source.amount', 'DESC');
}
/**
* Join table to get attachment information.
*/
private function joinAttachmentTables(): void
{
if (false === $this->hasJoinedAttTables) {
// join some extra tables:
$this->hasJoinedAttTables = true;
$this->query->leftJoin('attachments', 'attachments.attachable_id', '=', 'transaction_journals.id')
->where(
static function (EloquentBuilder $q1) {
$q1->where('attachments.attachable_type', TransactionJournal::class);
$q1->where('attachments.uploaded', 1);
$q1->orWhereNull('attachments.attachable_type');
}
);
}
}
/**
*
*/

View File

@@ -22,6 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Account;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\Account;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;

View File

@@ -44,13 +44,13 @@ use Illuminate\View\View;
class EditController extends Controller
{
use ModelInformation, UserNavigation;
private AttachmentHelperInterface $attachments;
/** @var CurrencyRepositoryInterface The currency repository */
private $currencyRepos;
/** @var AccountRepositoryInterface The account repository */
private $repository;
private AttachmentHelperInterface $attachments;
/**
* EditController constructor.
*/
@@ -166,6 +166,7 @@ class EditController extends Controller
)
);
}
/**
* Update the account.
*

View File

@@ -50,6 +50,7 @@ use Log;
class ReconcileController extends Controller
{
use UserNavigation;
/** @var AccountRepositoryInterface The account repository */
private $accountRepos;
/** @var CurrencyRepositoryInterface The currency repository */
@@ -87,8 +88,8 @@ class ReconcileController extends Controller
* @param Carbon|null $start
* @param Carbon|null $end
*
* @throws Exception
* @return Factory|RedirectResponse|Redirector|View
* @throws Exception
*/
public function reconcile(Account $account, Carbon $start = null, Carbon $end = null)
{
@@ -212,9 +213,9 @@ class ReconcileController extends Controller
* @param Carbon $end
* @param string $difference
*
* @return RedirectResponse|Redirector|string
* @throws DuplicateTransactionException
*
* @return RedirectResponse|Redirector|string
*/
private function createReconciliation(Account $account, Carbon $start, Carbon $end, string $difference)
{

View File

@@ -32,10 +32,12 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Support\Http\Controllers\PeriodOverview;
use FireflyIII\Support\Http\Controllers\UserNavigation;
use Illuminate\Contracts\View\Factory;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Routing\Redirector;
use Illuminate\Support\Collection;
use Illuminate\View\View;
/**
* Class ShowController
@@ -72,6 +74,7 @@ class ShowController extends Controller
}
);
}
/**
* Show an account.
*
@@ -80,9 +83,9 @@ class ShowController extends Controller
* @param Carbon|null $start
* @param Carbon|null $end
*
* @return RedirectResponse|Redirector|Factory|View
* @throws Exception
*
* @return RedirectResponse|Redirector|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function show(Request $request, Account $account, Carbon $start = null, Carbon $end = null)
{
@@ -155,9 +158,9 @@ class ShowController extends Controller
* @param Request $request
* @param Account $account
*
* @return RedirectResponse|Redirector|Factory|View
* @throws Exception
*
* @return RedirectResponse|Redirector|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function showAll(Request $request, Account $account)
{

View File

@@ -28,6 +28,8 @@ use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Jobs\SubmitTelemetryData;
use FireflyIII\Repositories\Telemetry\TelemetryRepositoryInterface;
use Illuminate\Contracts\View\Factory;
use Illuminate\Http\RedirectResponse;
use Illuminate\Routing\Redirector;
use Illuminate\View\View;
/**
@@ -57,19 +59,7 @@ class TelemetryController extends Controller
}
/**
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function deleteSubmitted()
{
$this->repository->deleteSubmitted();
session()->flash('success', trans('firefly.telemetry_submitted_deleted'));
return redirect(url()->previous(route('admin.telemetry.index')));
}
/**
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
* @return RedirectResponse|Redirector
*/
public function deleteAll()
{
@@ -81,15 +71,13 @@ class TelemetryController extends Controller
}
/**
* Run job to submit telemetry.
* @return RedirectResponse|Redirector
*/
public function submit()
public function deleteSubmitted()
{
$job = app(SubmitTelemetryData::class);
$job->setDate(today(config('app.timezone')));
$job->setForce(true);
$job->handle();
session()->flash('info', trans('firefly.telemetry_submission_executed'));
$this->repository->deleteSubmitted();
session()->flash('success', trans('firefly.telemetry_submitted_deleted'));
return redirect(url()->previous(route('admin.telemetry.index')));
}
@@ -109,6 +97,20 @@ class TelemetryController extends Controller
return prefixView('admin.telemetry.index', compact('version', 'enabled', 'count'));
}
/**
* Run job to submit telemetry.
*/
public function submit()
{
$job = app(SubmitTelemetryData::class);
$job->setDate(today(config('app.timezone')));
$job->setForce(true);
$job->handle();
session()->flash('info', trans('firefly.telemetry_submission_executed'));
return redirect(url()->previous(route('admin.telemetry.index')));
}
/**
* View telemetry. Paginated because you never know how much will be collected.
*

View File

@@ -27,8 +27,11 @@ use FireflyIII\Http\Middleware\IsDemoUser;
use FireflyIII\Http\Requests\UserFormRequest;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\User;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
use Illuminate\Http\RedirectResponse;
use Illuminate\Routing\Redirector;
use Illuminate\View\View;
use Log;
/**
@@ -36,8 +39,8 @@ use Log;
*/
class UserController extends Controller
{
private UserRepositoryInterface $repository;
protected bool $externalIdentity;
private UserRepositoryInterface $repository;
/**
* UserController constructor.
@@ -64,7 +67,7 @@ class UserController extends Controller
/**
* @param User $user
*
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|RedirectResponse|Redirector|\Illuminate\View\View
* @return Application|Factory|RedirectResponse|Redirector|View
*/
public function delete(User $user)
{
@@ -104,7 +107,7 @@ class UserController extends Controller
*
* @param User $user
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
* @return Factory|View
*/
public function edit(User $user)
{
@@ -135,7 +138,7 @@ class UserController extends Controller
/**
* Show index of user manager.
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
* @return Factory|View
*/
public function index()
{
@@ -159,7 +162,7 @@ class UserController extends Controller
*
* @param User $user
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
* @return Factory|View
*/
public function show(User $user)
{

View File

@@ -26,9 +26,12 @@ use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Requests\AttachmentFormRequest;
use FireflyIII\Models\Attachment;
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
use Illuminate\Contracts\View\Factory;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response as LaravelResponse;
use Illuminate\Routing\Redirector;
use Illuminate\View\View;
/**
* Class AttachmentController.
@@ -65,7 +68,7 @@ class AttachmentController extends Controller
*
* @param Attachment $attachment
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
* @return Factory|View
*/
public function delete(Attachment $attachment)
{
@@ -83,7 +86,7 @@ class AttachmentController extends Controller
* @param Request $request
* @param Attachment $attachment
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
* @return RedirectResponse|Redirector
*/
public function destroy(Request $request, Attachment $attachment)
{
@@ -102,9 +105,9 @@ class AttachmentController extends Controller
*
* @param Attachment $attachment
*
* @throws FireflyException
* @return mixed
*
* @throws FireflyException
*/
public function download(Attachment $attachment)
{
@@ -136,7 +139,7 @@ class AttachmentController extends Controller
* @param Request $request
* @param Attachment $attachment
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
* @return Factory|View
*/
public function edit(Request $request, Attachment $attachment)
{
@@ -159,7 +162,7 @@ class AttachmentController extends Controller
/**
* Index of all attachments.
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
* @return Factory|View
*/
public function index()
{
@@ -171,6 +174,7 @@ class AttachmentController extends Controller
return $attachment;
}
);
return prefixView('attachments.index', compact('set'));
}
@@ -208,8 +212,8 @@ class AttachmentController extends Controller
*
* @param Attachment $attachment
*
* @throws FireflyException
* @return LaravelResponse
* @throws FireflyException
*/
public function view(Request $request, Attachment $attachment): LaravelResponse
{

View File

@@ -67,6 +67,7 @@ class LoginController extends Controller
parent::__construct();
$this->middleware('guest')->except('logout');
}
/**
* Handle a login request to the application.
*
@@ -214,6 +215,7 @@ class LoginController extends Controller
$cookieName = config('google2fa.cookie_name', 'google2fa_token');
request()->cookies->set($cookieName, 'invalid');
}
return prefixView('auth.login', compact('allowRegistration', 'email', 'remember', 'allowReset', 'title'));
}

View File

@@ -23,6 +23,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Bill;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
use FireflyIII\Http\Controllers\Controller;

View File

@@ -23,6 +23,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Bill;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\Bill;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;

View File

@@ -23,6 +23,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Bill;
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Http\Requests\BillUpdateRequest;
@@ -62,6 +63,7 @@ class EditController extends Controller
}
);
}
/**
* Edit a bill.
*
@@ -108,6 +110,7 @@ class EditController extends Controller
return prefixView('bills.edit', compact('subTitle', 'periods', 'rules', 'bill', 'defaultCurrency', 'preFilled'));
}
/**
* Update a bill.
*

View File

@@ -23,6 +23,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Bill;
use Carbon\Carbon;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\Bill;
@@ -139,6 +140,7 @@ class IndexController extends Controller
return prefixView('bills.index', compact('bills', 'sums', 'total', 'totals'));
}
/**
* @param array $bills
*

View File

@@ -22,6 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Bill;
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
@@ -116,6 +117,7 @@ class ShowController extends Controller
return redirect(route('bills.show', [$bill->id]));
}
/**
* Show a bill.
*

View File

@@ -22,6 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Budget;
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Http\Requests\BudgetFormStoreRequest;
@@ -37,8 +38,8 @@ use Illuminate\View\View;
*/
class CreateController extends Controller
{
private BudgetRepositoryInterface $repository;
private AttachmentHelperInterface $attachments;
private BudgetRepositoryInterface $repository;
/**
* CreateController constructor.
@@ -59,6 +60,7 @@ class CreateController extends Controller
}
);
}
/**
* Form to create a budget.
*
@@ -102,6 +104,7 @@ class CreateController extends Controller
return prefixView('budgets.create', compact('subTitle', 'autoBudgetTypes', 'autoBudgetPeriods'));
}
/**
* Stores a budget.
*

View File

@@ -22,6 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Budget;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\Budget;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
@@ -59,6 +60,7 @@ class DeleteController extends Controller
}
);
}
/**
* Deletes a budget.
*

View File

@@ -22,6 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Budget;
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Http\Requests\BudgetFormUpdateRequest;
@@ -39,11 +40,10 @@ use Illuminate\View\View;
*/
class EditController extends Controller
{
/** @var BudgetRepositoryInterface The budget repository */
private $repository;
/** @var AttachmentHelperInterface Helper for attachments. */
private $attachments;
/** @var BudgetRepositoryInterface The budget repository */
private $repository;
/**
* EditController constructor.

View File

@@ -49,6 +49,7 @@ use Log;
class IndexController extends Controller
{
use DateCalculation;
private AvailableBudgetRepositoryInterface $abRepository;
private BudgetLimitRepositoryInterface $blRepository;
private CurrencyRepositoryInterface $currencyRepository;
@@ -141,91 +142,6 @@ class IndexController extends Controller
);
}
/**
* @param Request $request
* @param BudgetRepositoryInterface $repository
*
* @return JsonResponse
*/
public function reorder(Request $request, BudgetRepositoryInterface $repository): JsonResponse
{
$budgetIds = $request->get('budgetIds');
foreach ($budgetIds as $index => $budgetId) {
$budgetId = (int) $budgetId;
$budget = $repository->findNull($budgetId);
if (null !== $budget) {
Log::debug(sprintf('Set budget #%d ("%s") to position %d', $budget->id, $budget->name, $index + 1));
$repository->setBudgetOrder($budget, $index + 1);
}
}
app('preferences')->mark();
return response()->json(['OK']);
}
/**
* @param array $budgets
*
* @return array
*/
private function getSums(array $budgets): array
{
$sums = [
'budgeted' => [],
'spent' => [],
'left' => [],
];
/** @var array $budget */
foreach ($budgets as $budget) {
/** @var array $spent */
foreach ($budget['spent'] as $spent) {
$currencyId = $spent['currency_id'];
$sums['spent'][$currencyId]
= $sums['spent'][$currencyId]
?? [
'amount' => '0',
'currency_id' => $spent['currency_id'],
'currency_symbol' => $spent['currency_symbol'],
'currency_decimal_places' => $spent['currency_decimal_places'],
];
$sums['spent'][$currencyId]['amount'] = bcadd($sums['spent'][$currencyId]['amount'], $spent['spent']);
}
/** @var array $budgeted */
foreach ($budget['budgeted'] as $budgeted) {
$currencyId = $budgeted['currency_id'];
$sums['budgeted'][$currencyId]
= $sums['budgeted'][$currencyId]
?? [
'amount' => '0',
'currency_id' => $budgeted['currency_id'],
'currency_symbol' => $budgeted['currency_symbol'],
'currency_decimal_places' => $budgeted['currency_decimal_places'],
];
$sums['budgeted'][$currencyId]['amount'] = bcadd($sums['budgeted'][$currencyId]['amount'], $budgeted['amount']);
// also calculate how much left from budgeted:
$sums['left'][$currencyId] = $sums['left'][$currencyId]
?? [
'amount' => '0',
'currency_id' => $budgeted['currency_id'],
'currency_symbol' => $budgeted['currency_symbol'],
'currency_decimal_places' => $budgeted['currency_decimal_places'],
];
}
}
// final calculation for 'left':
foreach ($sums['budgeted'] as $currencyId => $info) {
$spent = $sums['spent'][$currencyId]['amount'] ?? '0';
$budgeted = $sums['budgeted'][$currencyId]['amount'] ?? '0';
$sums['left'][$currencyId]['amount'] = bcadd($spent, $budgeted);
}
return $sums;
}
/**
* @param Carbon $start
* @param Carbon $end
@@ -312,6 +228,92 @@ class IndexController extends Controller
}
$budgets[] = $array;
}
return $budgets;
}
/**
* @param array $budgets
*
* @return array
*/
private function getSums(array $budgets): array
{
$sums = [
'budgeted' => [],
'spent' => [],
'left' => [],
];
/** @var array $budget */
foreach ($budgets as $budget) {
/** @var array $spent */
foreach ($budget['spent'] as $spent) {
$currencyId = $spent['currency_id'];
$sums['spent'][$currencyId]
= $sums['spent'][$currencyId]
?? [
'amount' => '0',
'currency_id' => $spent['currency_id'],
'currency_symbol' => $spent['currency_symbol'],
'currency_decimal_places' => $spent['currency_decimal_places'],
];
$sums['spent'][$currencyId]['amount'] = bcadd($sums['spent'][$currencyId]['amount'], $spent['spent']);
}
/** @var array $budgeted */
foreach ($budget['budgeted'] as $budgeted) {
$currencyId = $budgeted['currency_id'];
$sums['budgeted'][$currencyId]
= $sums['budgeted'][$currencyId]
?? [
'amount' => '0',
'currency_id' => $budgeted['currency_id'],
'currency_symbol' => $budgeted['currency_symbol'],
'currency_decimal_places' => $budgeted['currency_decimal_places'],
];
$sums['budgeted'][$currencyId]['amount'] = bcadd($sums['budgeted'][$currencyId]['amount'], $budgeted['amount']);
// also calculate how much left from budgeted:
$sums['left'][$currencyId] = $sums['left'][$currencyId]
?? [
'amount' => '0',
'currency_id' => $budgeted['currency_id'],
'currency_symbol' => $budgeted['currency_symbol'],
'currency_decimal_places' => $budgeted['currency_decimal_places'],
];
}
}
// final calculation for 'left':
foreach ($sums['budgeted'] as $currencyId => $info) {
$spent = $sums['spent'][$currencyId]['amount'] ?? '0';
$budgeted = $sums['budgeted'][$currencyId]['amount'] ?? '0';
$sums['left'][$currencyId]['amount'] = bcadd($spent, $budgeted);
}
return $sums;
}
/**
* @param Request $request
* @param BudgetRepositoryInterface $repository
*
* @return JsonResponse
*/
public function reorder(Request $request, BudgetRepositoryInterface $repository): JsonResponse
{
$budgetIds = $request->get('budgetIds');
foreach ($budgetIds as $index => $budgetId) {
$budgetId = (int)$budgetId;
$budget = $repository->findNull($budgetId);
if (null !== $budget) {
Log::debug(sprintf('Set budget #%d ("%s") to position %d', $budget->id, $budget->name, $index + 1));
$repository->setBudgetOrder($budget, $index + 1);
}
}
app('preferences')->mark();
return response()->json(['OK']);
}
}

View File

@@ -22,6 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Budget;
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
@@ -44,6 +45,7 @@ use Illuminate\View\View;
class ShowController extends Controller
{
use PeriodOverview, AugumentData;
private JournalRepositoryInterface $journalRepos;
private BudgetRepositoryInterface $repository;
@@ -131,6 +133,7 @@ class ShowController extends Controller
return prefixView('budgets.no-budget', compact('groups', 'subTitle', 'start', 'end'));
}
/**
* Show a single budget.
*
@@ -171,8 +174,8 @@ class ShowController extends Controller
* @param Budget $budget
* @param BudgetLimit $budgetLimit
*
* @throws FireflyException
* @return Factory|View
* @throws FireflyException
*/
public function showByBudgetLimit(Request $request, Budget $budget, BudgetLimit $budgetLimit)
{

View File

@@ -22,6 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Category;
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Http\Requests\CategoryFormRequest;
@@ -37,8 +38,8 @@ use Illuminate\View\View;
*/
class CreateController extends Controller
{
private CategoryRepositoryInterface $repository;
private AttachmentHelperInterface $attachments;
private CategoryRepositoryInterface $repository;
/**
* CategoryController constructor.
@@ -60,6 +61,7 @@ class CreateController extends Controller
}
);
}
/**
* Create category.
*
@@ -77,6 +79,7 @@ class CreateController extends Controller
return prefixView('categories.create', compact('subTitle'));
}
/**
* Store new category.
*

View File

@@ -22,6 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Category;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\Category;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;

View File

@@ -22,6 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Category;
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Http\Requests\CategoryFormRequest;
@@ -39,8 +40,8 @@ use Illuminate\View\View;
class EditController extends Controller
{
private CategoryRepositoryInterface $repository;
private AttachmentHelperInterface $attachments;
private CategoryRepositoryInterface $repository;
/**
* CategoryController constructor.
@@ -62,6 +63,7 @@ class EditController extends Controller
}
);
}
/**
* Edit a category.
*

View File

@@ -22,6 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Category;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\Category;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
@@ -58,6 +59,7 @@ class IndexController extends Controller
}
);
}
/**
* Show all categories.
*

View File

@@ -22,6 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Category;
use Carbon\Carbon;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Http\Controllers\Controller;
@@ -41,6 +42,7 @@ use Log;
class NoCategoryController extends Controller
{
use PeriodOverview;
/** @var JournalRepositoryInterface Journals and transactions overview */
private $journalRepos;
@@ -103,6 +105,7 @@ class NoCategoryController extends Controller
return prefixView('categories.no-category', compact('groups', 'subTitle', 'periods', 'start', 'end'));
}
/**
* Show all transactions without a category.
*

View File

@@ -42,6 +42,7 @@ use Illuminate\View\View;
class ShowController extends Controller
{
use PeriodOverview;
/** @var CategoryRepositoryInterface The category repository */
private $repository;
@@ -65,6 +66,7 @@ class ShowController extends Controller
}
);
}
/**
* Show a single category.
*

View File

@@ -76,6 +76,7 @@ class AccountController extends Controller
}
);
}
/**
* Shows the balances for all the user's expense accounts (on the front page).
*
@@ -169,6 +170,22 @@ class AccountController extends Controller
return response()->json($data);
}
/**
* Expenses per budget for all time, as shown on account overview.
*
* @param AccountRepositoryInterface $repository
* @param Account $account
*
* @return JsonResponse
*/
public function expenseBudgetAll(AccountRepositoryInterface $repository, Account $account): JsonResponse
{
$start = $repository->oldestJournalDate($account) ?? Carbon::now()->startOfMonth();
$end = Carbon::now();
return $this->expenseBudget($account, $start, $end);
}
/**
* Expenses per budget, as shown on account overview.
*
@@ -228,19 +245,19 @@ class AccountController extends Controller
}
/**
* Expenses per budget for all time, as shown on account overview.
* Expenses grouped by category for account.
*
* @param AccountRepositoryInterface $repository
* @param Account $account
*
* @return JsonResponse
*/
public function expenseBudgetAll(AccountRepositoryInterface $repository, Account $account): JsonResponse
public function expenseCategoryAll(AccountRepositoryInterface $repository, Account $account): JsonResponse
{
$start = $repository->oldestJournalDate($account) ?? Carbon::now()->startOfMonth();
$end = Carbon::now();
return $this->expenseBudget($account, $start, $end);
return $this->expenseCategory($account, $start, $end);
}
/**
@@ -299,22 +316,6 @@ class AccountController extends Controller
return response()->json($data);
}
/**
* Expenses grouped by category for account.
*
* @param AccountRepositoryInterface $repository
* @param Account $account
*
* @return JsonResponse
*/
public function expenseCategoryAll(AccountRepositoryInterface $repository, Account $account): JsonResponse
{
$start = $repository->oldestJournalDate($account) ?? Carbon::now()->startOfMonth();
$end = Carbon::now();
return $this->expenseCategory($account, $start, $end);
}
/**
* Shows the balances for all the user's frontpage accounts.
*
@@ -339,6 +340,22 @@ class AccountController extends Controller
return response()->json($this->accountBalanceChart($accounts, $start, $end));
}
/**
* Shows the income grouped by category for an account, in all time.
*
* @param AccountRepositoryInterface $repository
* @param Account $account
*
* @return JsonResponse
*/
public function incomeCategoryAll(AccountRepositoryInterface $repository, Account $account): JsonResponse
{
$start = $repository->oldestJournalDate($account) ?? Carbon::now()->startOfMonth();
$end = Carbon::now();
return $this->incomeCategory($account, $start, $end);
}
/**
* Shows all income per account for each category.
*
@@ -395,22 +412,6 @@ class AccountController extends Controller
return response()->json($data);
}
/**
* Shows the income grouped by category for an account, in all time.
*
* @param AccountRepositoryInterface $repository
* @param Account $account
*
* @return JsonResponse
*/
public function incomeCategoryAll(AccountRepositoryInterface $repository, Account $account): JsonResponse
{
$start = $repository->oldestJournalDate($account) ?? Carbon::now()->startOfMonth();
$end = Carbon::now();
return $this->incomeCategory($account, $start, $end);
}
/**
* Shows overview of account during a single period.
*
@@ -450,6 +451,61 @@ class AccountController extends Controller
return response()->json($data);
}
/**
* @param Carbon $start
* @param Carbon $end
* @param Account $account
* @param TransactionCurrency $currency
*
* @return array
*/
private function periodByCurrency(Carbon $start, Carbon $end, Account $account, TransactionCurrency $currency): array
{
$locale = app('steam')->getLocale();
$step = $this->calculateStep($start, $end);
$result = [
'label' => sprintf('%s (%s)', $account->name, $currency->symbol),
'currency_symbol' => $currency->symbol,
'currency_code' => $currency->code,
'entries' => [],
];
$entries = [];
$current = clone $start;
switch ($step) {
default:
break;
case '1D':
// per day the entire period, balance for every day.
$format = (string)trans('config.month_and_day', [], $locale);
$range = app('steam')->balanceInRange($account, $start, $end, $currency);
$previous = array_values($range)[0];
while ($end >= $current) {
$theDate = $current->format('Y-m-d');
$balance = $range[$theDate] ?? $previous;
$label = $current->formatLocalized($format);
$entries[$label] = (float)$balance;
$previous = $balance;
$current->addDay();
}
break;
// @codeCoverageIgnoreStart
case '1W':
case '1M':
case '1Y':
while ($end >= $current) {
$balance = (float)app('steam')->balance($account, $current, $currency);
$label = app('navigation')->periodShow($current, $step);
$entries[$label] = $balance;
$current = app('navigation')->addPeriod($current, $step, 0);
}
break;
// @codeCoverageIgnoreEnd
}
$result['entries'] = $entries;
return $result;
}
/**
* Shows the balances for a given set of dates and accounts.
*
@@ -465,6 +521,7 @@ class AccountController extends Controller
{
return response()->json($this->accountBalanceChart($accounts, $start, $end));
}
/**
* Shows the balances for all the user's revenue accounts.
*
@@ -557,59 +614,4 @@ class AccountController extends Controller
return response()->json($data);
}
/**
* @param Carbon $start
* @param Carbon $end
* @param Account $account
* @param TransactionCurrency $currency
*
* @return array
*/
private function periodByCurrency(Carbon $start, Carbon $end, Account $account, TransactionCurrency $currency): array
{
$locale = app('steam')->getLocale();
$step = $this->calculateStep($start, $end);
$result = [
'label' => sprintf('%s (%s)', $account->name, $currency->symbol),
'currency_symbol' => $currency->symbol,
'currency_code' => $currency->code,
'entries' => [],
];
$entries = [];
$current = clone $start;
switch ($step) {
default:
break;
case '1D':
// per day the entire period, balance for every day.
$format = (string) trans('config.month_and_day', [], $locale);
$range = app('steam')->balanceInRange($account, $start, $end, $currency);
$previous = array_values($range)[0];
while ($end >= $current) {
$theDate = $current->format('Y-m-d');
$balance = $range[$theDate] ?? $previous;
$label = $current->formatLocalized($format);
$entries[$label] = (float) $balance;
$previous = $balance;
$current->addDay();
}
break;
// @codeCoverageIgnoreStart
case '1W':
case '1M':
case '1Y':
while ($end >= $current) {
$balance = (float) app('steam')->balance($account, $current, $currency);
$label = app('navigation')->periodShow($current, $step);
$entries[$label] = $balance;
$current = app('navigation')->addPeriod($current, $step, 0);
}
break;
// @codeCoverageIgnoreEnd
}
$result['entries'] = $entries;
return $result;
}
}

View File

@@ -50,6 +50,7 @@ class BillController extends Controller
parent::__construct();
$this->generator = app(GeneratorInterface::class);
}
/**
* Shows all bills and whether or not they've been paid this month (pie chart).
*
@@ -79,12 +80,14 @@ class BillController extends Controller
foreach ($paid as $currencyId => $amount) {
$currencies[$currencyId] = $currencies[$currencyId] ?? $currencyRepository->findNull($currencyId);
$label = (string)trans('firefly.paid_in_currency', ['currency' => $currencies[$currencyId]->name]);
$chartData[$label] = ['amount' => $amount, 'currency_symbol' => $currencies[$currencyId]->symbol, 'currency_code' => $currencies[$currencyId]->code];
$chartData[$label] = ['amount' => $amount, 'currency_symbol' => $currencies[$currencyId]->symbol,
'currency_code' => $currencies[$currencyId]->code];
}
foreach ($unpaid as $currencyId => $amount) {
$currencies[$currencyId] = $currencies[$currencyId] ?? $currencyRepository->findNull($currencyId);
$label = (string)trans('firefly.unpaid_in_currency', ['currency' => $currencies[$currencyId]->name]);
$chartData[$label] = ['amount' => $amount, 'currency_symbol' => $currencies[$currencyId]->symbol, 'currency_code' => $currencies[$currencyId]->code];
$chartData[$label] = ['amount' => $amount, 'currency_symbol' => $currencies[$currencyId]->symbol,
'currency_code' => $currencies[$currencyId]->code];
}
$data = $this->generator->multiCurrencyPieChart($chartData);
@@ -92,6 +95,7 @@ class BillController extends Controller
return response()->json($data);
}
/**
* Shows overview for a single bill.
*
@@ -123,14 +127,18 @@ class BillController extends Controller
if ($left['date']->lt($right['date'])) {
return -1;
}
return 0;
}
);
$chartData = [
['type' => 'line', 'label' => (string) trans('firefly.min-amount'), 'currency_symbol' => $bill->transactionCurrency->symbol, 'currency_code' => $bill->transactionCurrency->code, 'entries' => []],
['type' => 'line', 'label' => (string) trans('firefly.max-amount'), 'currency_symbol' => $bill->transactionCurrency->symbol, 'currency_code' => $bill->transactionCurrency->code, 'entries' => []],
['type' => 'bar', 'label' => (string) trans('firefly.journal-amount'), 'currency_symbol' => $bill->transactionCurrency->symbol, 'currency_code' => $bill->transactionCurrency->code, 'entries' => []],
['type' => 'line', 'label' => (string)trans('firefly.min-amount'), 'currency_symbol' => $bill->transactionCurrency->symbol,
'currency_code' => $bill->transactionCurrency->code, 'entries' => []],
['type' => 'line', 'label' => (string)trans('firefly.max-amount'), 'currency_symbol' => $bill->transactionCurrency->symbol,
'currency_code' => $bill->transactionCurrency->code, 'entries' => []],
['type' => 'bar', 'label' => (string)trans('firefly.journal-amount'), 'currency_symbol' => $bill->transactionCurrency->symbol,
'currency_code' => $bill->transactionCurrency->code, 'entries' => []],
];
foreach ($journals as $journal) {

View File

@@ -77,6 +77,7 @@ class BudgetController extends Controller
}
);
}
/**
* Shows overview of a single budget.
*
@@ -141,6 +142,7 @@ class BudgetController extends Controller
return response()->json($data);
}
/**
* Shows the amount left in a specific budget limit.
*
@@ -192,6 +194,7 @@ class BudgetController extends Controller
return response()->json($data);
}
/**
* Shows how much is spent per asset account.
*
@@ -259,6 +262,7 @@ class BudgetController extends Controller
return response()->json($data);
}
/**
* Shows how much is spent per category.
*
@@ -322,6 +326,7 @@ class BudgetController extends Controller
return response()->json($data);
}
/**
* Shows how much is spent per expense account.
*
@@ -388,6 +393,7 @@ class BudgetController extends Controller
return response()->json($data);
}
/**
* Shows a budget list with spent/left/overspent.
*
@@ -419,6 +425,7 @@ class BudgetController extends Controller
return response()->json($data);
}
/**
* Shows a budget overview chart (spent and budgeted).
*
@@ -494,6 +501,7 @@ class BudgetController extends Controller
return response()->json($data);
}
/**
* Shows a chart for transactions without a budget.
*

View File

@@ -42,6 +42,7 @@ use Illuminate\Support\Collection;
class BudgetReportController extends Controller
{
use AugumentData, TransactionCalculation;
/** @var GeneratorInterface Chart generation methods. */
private $generator;
@@ -224,6 +225,29 @@ class BudgetReportController extends Controller
return response()->json($data);
}
/**
* @param Carbon $start
* @param Carbon $end
*
* @return array
*/
private function makeEntries(Carbon $start, Carbon $end): array
{
$return = [];
$format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
$preferredRange = app('navigation')->preferredRangeFormat($start, $end);
$currentStart = clone $start;
while ($currentStart <= $end) {
$currentEnd = app('navigation')->endOfPeriod($currentStart, $preferredRange);
$key = $currentStart->formatLocalized($format);
$return[$key] = '0';
$currentStart = clone $currentEnd;
$currentStart->addDay()->startOfDay();
}
return $return;
}
/**
* Chart that groups expenses by the account.
*
@@ -260,27 +284,4 @@ class BudgetReportController extends Controller
return response()->json($data);
}
/**
* @param Carbon $start
* @param Carbon $end
*
* @return array
*/
private function makeEntries(Carbon $start, Carbon $end): array
{
$return = [];
$format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
$preferredRange = app('navigation')->preferredRangeFormat($start, $end);
$currentStart = clone $start;
while ($currentStart <= $end) {
$currentEnd = app('navigation')->endOfPeriod($currentStart, $preferredRange);
$key = $currentStart->formatLocalized($format);
$return[$key] = '0';
$currentStart = clone $currentEnd;
$currentStart->addDay()->startOfDay();
}
return $return;
}
}

View File

@@ -60,6 +60,7 @@ class CategoryController extends Controller
// create chart generator:
$this->generator = app(GeneratorInterface::class);
}
/**
* Show an overview for a category for all time, per month/week/year.
* TODO test method, for category refactor.
@@ -92,6 +93,22 @@ class CategoryController extends Controller
return response()->json($data);
}
/**
* @return Carbon
*/
private function getDate(): Carbon
{
$carbon = null;
try {
$carbon = today(config('app.timezone'));
} catch (Exception $e) {
$e->getMessage();
}
return $carbon;
}
/**
* Shows the category chart on the front page.
* TODO test method, for category refactor.
@@ -147,84 +164,6 @@ class CategoryController extends Controller
return response()->json($data);
}
/**
* Chart for period for transactions without a category.
* TODO test me.
*
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
* @return JsonResponse
*/
public function reportPeriodNoCategory(Collection $accounts, Carbon $start, Carbon $end): JsonResponse
{
$cache = new CacheProperties;
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty('chart.category.period.no-cat');
$cache->addProperty($accounts->pluck('id')->toArray());
if ($cache->has()) {
return response()->json($cache->get()); // @codeCoverageIgnore
}
$data = $this->reportPeriodChart($accounts, $start, $end, null);
$cache->store($data);
return response()->json($data);
}
/**
* Chart for a specific period.
* TODO test method, for category refactor.
*
* @param Category $category
* @param $date
*
* @return JsonResponse
*/
public function specificPeriod(Category $category, Carbon $date): JsonResponse
{
$range = app('preferences')->get('viewRange', '1M')->data;
$start = app('navigation')->startOfPeriod($date, $range);
$end = session()->get('end');
if ($end < $start) {
[$end, $start] = [$start, $end]; // @codeCoverageIgnore
}
$cache = new CacheProperties;
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty($category->id);
$cache->addProperty('chart.category.period-chart');
if ($cache->has()) {
return response()->json($cache->get()); // @codeCoverageIgnore
}
/** @var WholePeriodChartGenerator $chartGenerator */
$chartGenerator = app(WholePeriodChartGenerator::class);
$chartData = $chartGenerator->generate($category, $start, $end);
$data = $this->generator->multiSet($chartData);
$cache->store($data);
return response()->json($data);
}
/**
* @return Carbon
*/
private function getDate(): Carbon
{
$carbon = null;
try {
$carbon = today(config('app.timezone'));
} catch (Exception $e) {
$e->getMessage();
}
return $carbon;
}
/**
* Generate report chart for either with or without category.
@@ -312,4 +251,68 @@ class CategoryController extends Controller
return $this->generator->multiSet($chartData);
}
/**
* Chart for period for transactions without a category.
* TODO test me.
*
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
* @return JsonResponse
*/
public function reportPeriodNoCategory(Collection $accounts, Carbon $start, Carbon $end): JsonResponse
{
$cache = new CacheProperties;
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty('chart.category.period.no-cat');
$cache->addProperty($accounts->pluck('id')->toArray());
if ($cache->has()) {
return response()->json($cache->get()); // @codeCoverageIgnore
}
$data = $this->reportPeriodChart($accounts, $start, $end, null);
$cache->store($data);
return response()->json($data);
}
/**
* Chart for a specific period.
* TODO test method, for category refactor.
*
* @param Category $category
* @param $date
*
* @return JsonResponse
*/
public function specificPeriod(Category $category, Carbon $date): JsonResponse
{
$range = app('preferences')->get('viewRange', '1M')->data;
$start = app('navigation')->startOfPeriod($date, $range);
$end = session()->get('end');
if ($end < $start) {
[$end, $start] = [$start, $end]; // @codeCoverageIgnore
}
$cache = new CacheProperties;
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty($category->id);
$cache->addProperty('chart.category.period-chart');
if ($cache->has()) {
return response()->json($cache->get()); // @codeCoverageIgnore
}
/** @var WholePeriodChartGenerator $chartGenerator */
$chartGenerator = app(WholePeriodChartGenerator::class);
$chartData = $chartGenerator->generate($category, $start, $end);
$data = $this->generator->multiSet($chartData);
$cache->store($data);
return response()->json($data);
}
}

View File

@@ -319,6 +319,31 @@ class CategoryReportController extends Controller
return response()->json($data);
}
/**
* TODO duplicate function
*
* @param Carbon $start
* @param Carbon $end
*
* @return array
*/
private function makeEntries(Carbon $start, Carbon $end): array
{
$return = [];
$format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
$preferredRange = app('navigation')->preferredRangeFormat($start, $end);
$currentStart = clone $start;
while ($currentStart <= $end) {
$currentEnd = app('navigation')->endOfPeriod($currentStart, $preferredRange);
$key = $currentStart->formatLocalized($format);
$return[$key] = '0';
$currentStart = clone $currentEnd;
$currentStart->addDay()->startOfDay();
}
return $return;
}
/**
* @param Collection $accounts
* @param Collection $categories
@@ -390,29 +415,4 @@ class CategoryReportController extends Controller
return response()->json($data);
}
/**
* TODO duplicate function
*
* @param Carbon $start
* @param Carbon $end
*
* @return array
*/
private function makeEntries(Carbon $start, Carbon $end): array
{
$return = [];
$format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
$preferredRange = app('navigation')->preferredRangeFormat($start, $end);
$currentStart = clone $start;
while ($currentStart <= $end) {
$currentEnd = app('navigation')->endOfPeriod($currentStart, $preferredRange);
$key = $currentStart->formatLocalized($format);
$return[$key] = '0';
$currentStart = clone $currentEnd;
$currentStart->addDay()->startOfDay();
}
return $return;
}
}

View File

@@ -247,6 +247,57 @@ class DoubleReportController extends Controller
return response()->json($data);
}
/**
* TODO this method is double.
*
* @param Collection $accounts
* @param int $id
* @param string $name
* @param null|string $iban
*
* @return string
*/
private function getCounterpartName(Collection $accounts, int $id, string $name, ?string $iban): string
{
/** @var Account $account */
foreach ($accounts as $account) {
if ($account->name === $name && $account->id !== $id) {
return $account->name;
}
if (null !== $account->iban && $account->iban === $iban && $account->id !== $id) {
return $account->iban;
}
}
return $name;
}
/**
* TODO duplicate function
*
* @param Carbon $start
* @param Carbon $end
*
* @return array
*/
private function makeEntries(Carbon $start, Carbon $end): array
{
$return = [];
$format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
$preferredRange = app('navigation')->preferredRangeFormat($start, $end);
$currentStart = clone $start;
while ($currentStart <= $end) {
$currentEnd = app('navigation')->endOfPeriod($currentStart, $preferredRange);
$key = $currentStart->formatLocalized($format);
$return[$key] = '0';
$currentStart = clone $currentEnd;
$currentStart->addDay()->startOfDay();
}
return $return;
}
/**
* @param Collection $accounts
* @param Collection $others
@@ -366,54 +417,4 @@ class DoubleReportController extends Controller
return response()->json($data);
}
/**
* TODO this method is double.
*
* @param Collection $accounts
* @param int $id
* @param string $name
* @param null|string $iban
*
* @return string
*/
private function getCounterpartName(Collection $accounts, int $id, string $name, ?string $iban): string
{
/** @var Account $account */
foreach ($accounts as $account) {
if ($account->name === $name && $account->id !== $id) {
return $account->name;
}
if (null !== $account->iban && $account->iban === $iban && $account->id !== $id) {
return $account->iban;
}
}
return $name;
}
/**
* TODO duplicate function
*
* @param Carbon $start
* @param Carbon $end
*
* @return array
*/
private function makeEntries(Carbon $start, Carbon $end): array
{
$return = [];
$format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
$preferredRange = app('navigation')->preferredRangeFormat($start, $end);
$currentStart = clone $start;
while ($currentStart <= $end) {
$currentEnd = app('navigation')->endOfPeriod($currentStart, $preferredRange);
$key = $currentStart->formatLocalized($format);
$return[$key] = '0';
$currentStart = clone $currentEnd;
$currentStart->addDay()->startOfDay();
}
return $return;
}
}

View File

@@ -42,6 +42,7 @@ use Illuminate\Support\Collection;
class ExpenseReportController extends Controller
{
use AugumentData, TransactionCalculation;
/** @var AccountRepositoryInterface The account repository */
protected $accountRepository;
/** @var GeneratorInterface Chart generation methods. */
@@ -64,6 +65,7 @@ class ExpenseReportController extends Controller
}
);
}
/**
* Main chart that shows income and expense for a combination of expense/revenue accounts.
*

View File

@@ -39,6 +39,7 @@ use Illuminate\Support\Collection;
class PiggyBankController extends Controller
{
use DateCalculation;
/** @var GeneratorInterface Chart generation methods. */
protected $generator;

View File

@@ -43,6 +43,7 @@ use Log;
class ReportController extends Controller
{
use BasicDataSupport, ChartGeneration;
/** @var GeneratorInterface Chart generation methods. */
protected $generator;

View File

@@ -38,6 +38,7 @@ use Illuminate\Support\Collection;
class TagReportController extends Controller
{
use AugumentData, TransactionCalculation;
/** @var GeneratorInterface Chart generation methods. */
protected $generator;
@@ -171,6 +172,7 @@ class TagReportController extends Controller
return response()->json($data);
}
/**
* @param Collection $accounts
* @param Collection $tags
@@ -320,6 +322,31 @@ class TagReportController extends Controller
return response()->json($data);
}
/**
* TODO duplicate function
*
* @param Carbon $start
* @param Carbon $end
*
* @return array
*/
private function makeEntries(Carbon $start, Carbon $end): array
{
$return = [];
$format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
$preferredRange = app('navigation')->preferredRangeFormat($start, $end);
$currentStart = clone $start;
while ($currentStart <= $end) {
$currentEnd = app('navigation')->endOfPeriod($currentStart, $preferredRange);
$key = $currentStart->formatLocalized($format);
$return[$key] = '0';
$currentStart = clone $currentEnd;
$currentStart->addDay()->startOfDay();
}
return $return;
}
/**
* @param Collection $accounts
* @param Collection $tags
@@ -425,6 +452,7 @@ class TagReportController extends Controller
return response()->json($data);
}
/**
* @param Collection $accounts
* @param Collection $tags
@@ -458,28 +486,4 @@ class TagReportController extends Controller
return response()->json($data);
}
/**
* TODO duplicate function
*
* @param Carbon $start
* @param Carbon $end
*
* @return array
*/
private function makeEntries(Carbon $start, Carbon $end): array
{
$return = [];
$format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
$preferredRange = app('navigation')->preferredRangeFormat($start, $end);
$currentStart = clone $start;
while ($currentStart <= $end) {
$currentEnd = app('navigation')->endOfPeriod($currentStart, $preferredRange);
$key = $currentStart->formatLocalized($format);
$return[$key] = '0';
$currentStart = clone $currentEnd;
$currentStart->addDay()->startOfDay();
}
return $return;
}
}

View File

@@ -56,8 +56,8 @@ class TransactionController extends Controller
* @param Carbon $start
* @param Carbon $end
*
* @throws FireflyException
* @return JsonResponse
* @throws FireflyException
*/
public function budgets(Carbon $start, Carbon $end)
{
@@ -100,8 +100,8 @@ class TransactionController extends Controller
* @param Carbon $start
* @param Carbon $end
*
* @throws FireflyException
* @return JsonResponse
* @throws FireflyException
*/
public function categories(string $objectType, Carbon $start, Carbon $end)
{
@@ -158,8 +158,8 @@ class TransactionController extends Controller
* @param Carbon $start
* @param Carbon $end
*
* @throws FireflyException
* @return JsonResponse
* @throws FireflyException
*/
public function destinationAccounts(string $objectType, Carbon $start, Carbon $end)
{
@@ -215,8 +215,8 @@ class TransactionController extends Controller
* @param Carbon $start
* @param Carbon $end
*
* @throws FireflyException
* @return JsonResponse
* @throws FireflyException
*/
public function sourceAccounts(string $objectType, Carbon $start, Carbon $end)
{

View File

@@ -27,13 +27,16 @@ use Artisan;
use Carbon\Carbon;
use DB;
use Exception;
use FireflyConfig;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Middleware\IsDemoUser;
use FireflyIII\Support\Http\Controllers\GetConfigurationData;
use Illuminate\Contracts\View\Factory;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Routing\Redirector;
use Illuminate\Routing\Route;
use Illuminate\View\View;
use Log;
use Monolog\Handler\RotatingFileHandler;
use Route as RouteFacade;
@@ -113,7 +116,7 @@ class DebugController extends Controller
*
* @param Request $request
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
* @return Factory|View
*
*/
public function index(Request $request)
@@ -144,7 +147,7 @@ class DebugController extends Controller
// expected + found DB version:
$expectedDBversion = config('firefly.db_version');
$foundDBversion = \FireflyConfig::get('db_version',1)->data;
$foundDBversion = FireflyConfig::get('db_version', 1)->data;
// some new vars.
$telemetry = true === config('firefly.send_telemetry') && true === config('firefly.feature_flags.telemetry');

View File

@@ -23,6 +23,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Export;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Http\Middleware\IsDemoUser;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
@@ -63,8 +64,8 @@ class IndexController extends Controller
}
/**
* @throws CannotInsertRecord
* @return LaravelResponse
* @throws CannotInsertRecord
*/
public function export(): LaravelResponse
{

View File

@@ -96,6 +96,7 @@ class HomeController extends Controller
return response()->json(['ok' => 'ok']);
}
/**
* Show index.
*

View File

@@ -76,6 +76,7 @@ class AutoCompleteController extends Controller
// give another key for consistency
$array[$index]['name'] = sprintf('#%d: %s', $item['transaction_group_id'], $item['description']);
}
return response()->json($array);
}

View File

@@ -125,6 +125,7 @@ class BoxController extends Controller
return response()->json($return);
}
/**
* Current total balance.
*

View File

@@ -23,6 +23,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Json;
use Carbon\Carbon;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\TransactionCurrency;

View File

@@ -177,6 +177,7 @@ class RecurrenceController extends Controller
];
}
Log::debug('Dropdown is', $result);
return response()->json($result);
}
}

View File

@@ -22,6 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Json;
use FireflyIII\Http\Controllers\Controller;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
@@ -87,6 +88,7 @@ class RuleController extends Controller
Log::error(sprintf('Cannot render rules.partials.trigger: %s', $e->getMessage()));
$view = 'Could not render view.';
}
return response()->json(['html' => $view]);
}

View File

@@ -23,6 +23,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\ObjectGroup;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\ObjectGroup;
use FireflyIII\Repositories\ObjectGroup\ObjectGroupRepositoryInterface;

View File

@@ -23,6 +23,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\ObjectGroup;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Http\Requests\ObjectGroupFormRequest;
use FireflyIII\Models\ObjectGroup;
@@ -73,6 +74,7 @@ class EditController extends Controller
return prefixView('object-groups.edit', compact('subTitle', 'subTitleIcon', 'objectGroup'));
}
/**
* Update a piggy bank.
*

View File

@@ -23,10 +23,14 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\ObjectGroup;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\ObjectGroup;
use FireflyIII\Repositories\ObjectGroup\ObjectGroupRepositoryInterface;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
use Illuminate\Http\Request;
use Illuminate\View\View;
use Log;
/**
@@ -58,7 +62,7 @@ class IndexController extends Controller
}
/**
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
* @return Application|Factory|View
*/
public function index()
{

View File

@@ -23,6 +23,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\PiggyBank;
use Carbon\Carbon;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\PiggyBank;

View File

@@ -23,6 +23,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\PiggyBank;
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Http\Requests\PiggyBankStoreRequest;
@@ -80,6 +81,7 @@ class CreateController extends Controller
return prefixView('piggy-banks.create', compact('subTitle', 'subTitleIcon'));
}
/**
* Store a new piggy bank.
*

View File

@@ -23,6 +23,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\PiggyBank;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;

View File

@@ -23,6 +23,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\PiggyBank;
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Http\Requests\PiggyBankUpdateRequest;
@@ -103,6 +104,7 @@ class EditController extends Controller
return prefixView('piggy-banks.edit', compact('subTitle', 'subTitleIcon', 'piggyBank', 'preFilled'));
}
/**
* Update a piggy bank.
*

View File

@@ -23,6 +23,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\PiggyBank;
use Carbon\Carbon;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\PiggyBank;
@@ -42,6 +43,7 @@ use Symfony\Component\HttpFoundation\ParameterBag;
class IndexController extends Controller
{
use OrganisesObjectGroups;
private PiggyBankRepositoryInterface $piggyRepos;
/**

View File

@@ -23,6 +23,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\PiggyBank;
use Carbon\Carbon;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\PiggyBank;

View File

@@ -44,9 +44,9 @@ use Illuminate\View\View;
*/
class CreateController extends Controller
{
private AttachmentHelperInterface $attachments;
private BudgetRepositoryInterface $budgetRepos;
private RecurringRepositoryInterface $recurring;
private AttachmentHelperInterface $attachments;
/**
* CreateController constructor.
@@ -73,6 +73,52 @@ class CreateController extends Controller
);
}
/**
* Create a new recurring transaction.
*
* @param Request $request
*
* @return Factory|View
*/
public function create(Request $request)
{
$budgets = app('expandedform')->makeSelectListWithEmpty($this->budgetRepos->getActiveBudgets());
$defaultCurrency = app('amount')->getDefaultCurrency();
$tomorrow = today(config('app.timezone'));
$oldRepetitionType = $request->old('repetition_type');
$tomorrow->addDay();
// put previous url in session if not redirect from store (not "create another").
if (true !== session('recurring.create.fromStore')) {
$this->rememberPreviousUri('recurring.create.uri');
}
$request->session()->forget('recurring.create.fromStore');
$repetitionEnds = [
'forever' => (string)trans('firefly.repeat_forever'),
'until_date' => (string)trans('firefly.repeat_until_date'),
'times' => (string)trans('firefly.repeat_times'),
];
$weekendResponses = [
RecurrenceRepetition::WEEKEND_DO_NOTHING => (string)trans('firefly.do_nothing'),
RecurrenceRepetition::WEEKEND_SKIP_CREATION => (string)trans('firefly.skip_transaction'),
RecurrenceRepetition::WEEKEND_TO_FRIDAY => (string)trans('firefly.jump_to_friday'),
RecurrenceRepetition::WEEKEND_TO_MONDAY => (string)trans('firefly.jump_to_monday'),
];
$hasOldInput = null !== $request->old('_token'); // flash some data
$preFilled = [
'first_date' => $tomorrow->format('Y-m-d'),
'transaction_type' => $hasOldInput ? $request->old('transaction_type') : 'withdrawal',
'active' => $hasOldInput ? (bool)$request->old('active') : true,
'apply_rules' => $hasOldInput ? (bool)$request->old('apply_rules') : true,
];
$request->session()->flash('preFilled', $preFilled);
return prefixView(
'recurring.create',
compact('tomorrow', 'oldRepetitionType', 'weekendResponses', 'preFilled', 'repetitionEnds', 'defaultCurrency', 'budgets')
);
}
/**
* @param Request $request
* @param TransactionJournal $journal
@@ -162,51 +208,6 @@ class CreateController extends Controller
);
}
/**
* Create a new recurring transaction.
*
* @param Request $request
*
* @return Factory|View
*/
public function create(Request $request)
{
$budgets = app('expandedform')->makeSelectListWithEmpty($this->budgetRepos->getActiveBudgets());
$defaultCurrency = app('amount')->getDefaultCurrency();
$tomorrow = today(config('app.timezone'));
$oldRepetitionType = $request->old('repetition_type');
$tomorrow->addDay();
// put previous url in session if not redirect from store (not "create another").
if (true !== session('recurring.create.fromStore')) {
$this->rememberPreviousUri('recurring.create.uri');
}
$request->session()->forget('recurring.create.fromStore');
$repetitionEnds = [
'forever' => (string) trans('firefly.repeat_forever'),
'until_date' => (string) trans('firefly.repeat_until_date'),
'times' => (string) trans('firefly.repeat_times'),
];
$weekendResponses = [
RecurrenceRepetition::WEEKEND_DO_NOTHING => (string) trans('firefly.do_nothing'),
RecurrenceRepetition::WEEKEND_SKIP_CREATION => (string) trans('firefly.skip_transaction'),
RecurrenceRepetition::WEEKEND_TO_FRIDAY => (string) trans('firefly.jump_to_friday'),
RecurrenceRepetition::WEEKEND_TO_MONDAY => (string) trans('firefly.jump_to_monday'),
];
$hasOldInput = null !== $request->old('_token'); // flash some data
$preFilled = [
'first_date' => $tomorrow->format('Y-m-d'),
'transaction_type' => $hasOldInput ? $request->old('transaction_type') : 'withdrawal',
'active' => $hasOldInput ? (bool) $request->old('active') : true,
'apply_rules' => $hasOldInput ? (bool) $request->old('apply_rules') : true,
];
$request->session()->flash('preFilled', $preFilled);
return prefixView(
'recurring.create',
compact('tomorrow', 'oldRepetitionType', 'weekendResponses', 'preFilled', 'repetitionEnds', 'defaultCurrency', 'budgets')
);
}
/**
* Store a recurring transaction.
*

View File

@@ -22,6 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Recurring;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\Recurrence;
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;

View File

@@ -22,6 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Recurring;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
use FireflyIII\Http\Controllers\Controller;
@@ -44,9 +45,9 @@ use Symfony\Component\HttpFoundation\ParameterBag;
*/
class EditController extends Controller
{
private AttachmentHelperInterface $attachments;
private BudgetRepositoryInterface $budgetRepos;
private RecurringRepositoryInterface $recurring;
private AttachmentHelperInterface $attachments;
/**
* EditController constructor.
@@ -67,6 +68,7 @@ class EditController extends Controller
$this->recurring = app(RecurringRepositoryInterface::class);
$this->budgetRepos = app(BudgetRepositoryInterface::class);
$this->attachments = app(AttachmentHelperInterface::class);
return $next($request);
}
);

View File

@@ -22,6 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Recurring;
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Controllers\Controller;
@@ -42,6 +43,7 @@ use Symfony\Component\HttpFoundation\ParameterBag;
class IndexController extends Controller
{
use GetConfigurationData;
private RecurringRepositoryInterface $recurringRepos;
/**
@@ -72,9 +74,9 @@ class IndexController extends Controller
*
* @param Request $request
*
* @return Factory|View
* @throws FireflyException
*
* @return Factory|View
*/
public function index(Request $request)
{

View File

@@ -41,6 +41,7 @@ use Symfony\Component\HttpFoundation\ParameterBag;
class ShowController extends Controller
{
use GetConfigurationData;
/** @var RecurringRepositoryInterface Recurring repository */
private $recurring;
@@ -66,13 +67,14 @@ class ShowController extends Controller
}
);
}
/**
* Show a single recurring transaction.
*
* @param Recurrence $recurrence
*
* @throws FireflyException
* @return Factory|View
* @throws FireflyException
*/
public function show(Recurrence $recurrence)
{

View File

@@ -56,6 +56,7 @@ class BalanceController extends Controller
}
);
}
/**
* Show overview of budget balances.
*

View File

@@ -22,6 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Report;
use Carbon\Carbon;
use FireflyIII\Helpers\Report\ReportHelperInterface;
use FireflyIII\Http\Controllers\Controller;

View File

@@ -44,8 +44,8 @@ class CategoryController extends Controller
{
use BasicDataSupport;
private OperationsRepositoryInterface $opsRepository;
private NoCategoryRepositoryInterface $noCatRepository;
private OperationsRepositoryInterface $opsRepository;
/**
* ExpenseReportController constructor.

View File

@@ -291,6 +291,31 @@ class DoubleController extends Controller
return prefixView('reports.double.partials.accounts', compact('sums', 'report'));
}
/**
* TODO this method is double.
*
* @param Collection $accounts
* @param int $id
* @param string $name
* @param string|null $iban
*
* @return string
*/
private function getCounterpartName(Collection $accounts, int $id, string $name, ?string $iban): string
{
/** @var Account $account */
foreach ($accounts as $account) {
if ($account->name === $name && $account->id !== $id) {
return $account->name;
}
if (null !== $account->iban && $account->iban === $iban && $account->id !== $id) {
return $account->iban;
}
}
return $name;
}
/**
* @param Collection $accounts
* @param Collection $double
@@ -490,29 +515,4 @@ class DoubleController extends Controller
return $result;
}
/**
* TODO this method is double.
*
* @param Collection $accounts
* @param int $id
* @param string $name
* @param string|null $iban
*
* @return string
*/
private function getCounterpartName(Collection $accounts, int $id, string $name, ?string $iban): string
{
/** @var Account $account */
foreach ($accounts as $account) {
if ($account->name === $name && $account->id !== $id) {
return $account->name;
}
if (null !== $account->iban && $account->iban === $iban && $account->id !== $id) {
return $account->iban;
}
}
return $name;
}
}

View File

@@ -57,6 +57,7 @@ class OperationsController extends Controller
}
);
}
/**
* View of income and expense.
*

View File

@@ -81,9 +81,9 @@ class ReportController extends Controller
* @param Carbon $start
* @param Carbon $end
*
* @throws FireflyException
* @return Factory|View|string
*
* @throws FireflyException
*/
public function auditReport(Collection $accounts, Carbon $start, Carbon $end)
{
@@ -117,9 +117,9 @@ class ReportController extends Controller
* @param Carbon $start
* @param Carbon $end
*
* @throws FireflyException
* @return Factory|View|string
*
* @throws FireflyException
*/
public function budgetReport(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end)
{
@@ -154,9 +154,9 @@ class ReportController extends Controller
* @param Carbon $start
* @param Carbon $end
*
* @throws FireflyException
* @return Factory|View|string
*
* @throws FireflyException
*/
public function categoryReport(Collection $accounts, Collection $categories, Carbon $start, Carbon $end)
{
@@ -190,9 +190,9 @@ class ReportController extends Controller
* @param Carbon $start
* @param Carbon $end
*
* @throws FireflyException
* @return Factory|View|string
*
* @throws FireflyException
*/
public function defaultReport(Collection $accounts, Carbon $start, Carbon $end)
{
@@ -227,8 +227,8 @@ class ReportController extends Controller
* @param Carbon $start
* @param Carbon $end
*
* @throws FireflyException
* @return Factory|View|string
* @throws FireflyException
*/
public function doubleReport(Collection $accounts, Collection $expense, Carbon $start, Carbon $end)
{
@@ -330,10 +330,10 @@ class ReportController extends Controller
*
* @param ReportFormRequest $request
*
* @throws FireflyException
*
* @return RedirectResponse|Redirector
*
* @throws FireflyException
*
*/
public function postIndex(ReportFormRequest $request)
{
@@ -406,6 +406,7 @@ class ReportController extends Controller
return redirect($uri);
}
/**
* Get a tag report.
*
@@ -414,8 +415,8 @@ class ReportController extends Controller
* @param Carbon $start
* @param Carbon $end
*
* @throws FireflyException
* @return Factory|View|string
* @throws FireflyException
*/
public function tagReport(Collection $accounts, Collection $tags, Carbon $start, Carbon $end)
{

View File

@@ -22,6 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Rule;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\Rule;
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;

View File

@@ -22,6 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Rule;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Http\Requests\RuleFormRequest;
use FireflyIII\Models\Rule;

View File

@@ -22,6 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Rule;
use Carbon\Carbon;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Http\Requests\SelectTransactionsRequest;
@@ -101,6 +102,7 @@ class SelectController extends Controller
return redirect()->route('rules.index');
}
/**
* View to select transactions by a rule.
*

View File

@@ -22,6 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\RuleGroup;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Http\Requests\RuleGroupFormRequest;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;

View File

@@ -22,6 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\RuleGroup;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\RuleGroup;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
@@ -59,6 +60,7 @@ class DeleteController extends Controller
}
);
}
/**
* Delete a rule group.
*

View File

@@ -79,6 +79,7 @@ class EditController extends Controller
return redirect(route('rules.index'));
}
/**
* Edit a rule group.
*

View File

@@ -22,6 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\RuleGroup;
use Carbon\Carbon;
use Exception;
use FireflyIII\Http\Controllers\Controller;
@@ -61,6 +62,7 @@ class ExecutionController extends Controller
}
);
}
/**
* Execute the given rulegroup on a set of existing transactions.
*

View File

@@ -22,6 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\System;
use Log;
/**
@@ -35,6 +36,7 @@ class CronController
public function cron()
{
Log::error('The cron endpoint has moved to GET /api/v1/cron/[token]');
return response('The cron endpoint has moved to GET /api/v1/cron/[token]', 500);
}
}

View File

@@ -22,17 +22,22 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\System;
use Artisan;
use Cache;
use Exception;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Support\Facades\Preferences;
use FireflyIII\Support\Http\Controllers\GetConfigurationData;
use Illuminate\Contracts\View\Factory;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Illuminate\View\View;
use Laravel\Passport\Passport;
use Log;
use phpseclib3\Crypt\RSA;
/**
* Class InstallController
*
@@ -45,10 +50,11 @@ class InstallController extends Controller
public const FORBIDDEN_ERROR = 'Internal PHP function "proc_close" is disabled for your installation. Auto-migration is not possible.';
public const BASEDIR_ERROR = 'Firefly III cannot execute the upgrade commands. It is not allowed to because of an open_basedir restriction.';
public const OTHER_ERROR = 'An unknown error prevented Firefly III from executing the upgrade commands. Sorry.';
private array $upgradeCommands;
private string $lastError;
private array $upgradeCommands;
/** @noinspection MagicMethodsValidityInspection */
/** @noinspection PhpMissingParentConstructorInspection */
/**
* InstallController constructor.
*/
@@ -110,7 +116,7 @@ class InstallController extends Controller
/**
* Show index.
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
* @return Factory|View
*/
public function index()
{
@@ -123,40 +129,6 @@ class InstallController extends Controller
return prefixView('install.index');
}
/**
* Create specific RSA keys.
*/
public function keys(): void
{
// switch on PHP version.
$result = version_compare(phpversion(), '8.0');
Log::info(sprintf('PHP version is %s', $result));
if (-1 === $result) {
Log::info('Will run PHP7 code.');
// PHP 7
$rsa = new \phpseclib\Crypt\RSA;
$keys = $rsa->createKey(4096);
}
if ($result >= 0) {
Log::info('Will run PHP8 code.');
// PHP 8
$keys = \phpseclib3\Crypt\RSA::createKey(4096);
}
[$publicKey, $privateKey] = [
Passport::keyPath('oauth-public.key'),
Passport::keyPath('oauth-private.key'),
];
if (file_exists($publicKey) || file_exists($privateKey)) {
return;
}
file_put_contents($publicKey, Arr::get($keys, 'publickey'));
file_put_contents($privateKey, Arr::get($keys, 'privatekey'));
}
/**
* @param Request $request
*
@@ -238,4 +210,38 @@ class InstallController extends Controller
return true;
}
/**
* Create specific RSA keys.
*/
public function keys(): void
{
// switch on PHP version.
$result = version_compare(phpversion(), '8.0');
Log::info(sprintf('PHP version is %s', $result));
if (-1 === $result) {
Log::info('Will run PHP7 code.');
// PHP 7
$rsa = new \phpseclib\Crypt\RSA;
$keys = $rsa->createKey(4096);
}
if ($result >= 0) {
Log::info('Will run PHP8 code.');
// PHP 8
$keys = RSA::createKey(4096);
}
[$publicKey, $privateKey] = [
Passport::keyPath('oauth-public.key'),
Passport::keyPath('oauth-private.key'),
];
if (file_exists($publicKey) || file_exists($privateKey)) {
return;
}
file_put_contents($publicKey, Arr::get($keys, 'publickey'));
file_put_contents($privateKey, Arr::get($keys, 'privatekey'));
}
}

View File

@@ -22,6 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Transaction;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Http\Requests\BulkEditJournalRequest;
use FireflyIII\Models\TransactionJournal;
@@ -38,6 +39,7 @@ class BulkController extends Controller
{
/** @var JournalRepositoryInterface Journals and transactions overview */
private $repository;
/**
* BulkController constructor.
*
@@ -82,6 +84,7 @@ class BulkController extends Controller
return prefixView('transactions.bulk.edit', compact('journals', 'subTitle', 'budgetList'));
}
/**
* Update all journals.
*
@@ -136,24 +139,6 @@ class BulkController extends Controller
return true;
}
/**
* @param TransactionJournal $journal
* @param bool $ignoreUpdate
* @param string $category
*
* @return bool
*/
private function updateJournalCategory(TransactionJournal $journal, bool $ignoreUpdate, string $category): bool
{
if (true === $ignoreUpdate) {
return false;
}
Log::debug(sprintf('Set budget to %s', $category));
$this->repository->updateCategory($journal, $category);
return true;
}
/**
* @param TransactionJournal $journal
* @param string $action
@@ -172,6 +157,25 @@ class BulkController extends Controller
$new = array_unique(array_merge($tags, $existing));
$this->repository->updateTags($journal, $new);
}
return true;
}
/**
* @param TransactionJournal $journal
* @param bool $ignoreUpdate
* @param string $category
*
* @return bool
*/
private function updateJournalCategory(TransactionJournal $journal, bool $ignoreUpdate, string $category): bool
{
if (true === $ignoreUpdate) {
return false;
}
Log::debug(sprintf('Set budget to %s', $category));
$this->repository->updateCategory($journal, $category);
return true;
}
}

View File

@@ -38,9 +38,11 @@ use FireflyIII\Support\Http\Controllers\ModelInformation;
use FireflyIII\Support\Http\Controllers\UserNavigation;
use FireflyIII\Transformers\TransactionGroupTransformer;
use FireflyIII\Validation\AccountValidator;
use Illuminate\Contracts\View\Factory;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Routing\Redirector;
use Illuminate\View\View;
use Log;
/**
@@ -52,8 +54,8 @@ class ConvertController extends Controller
{
use ModelInformation, UserNavigation;
private JournalRepositoryInterface $repository;
private AccountRepositoryInterface $accountRepository;
private JournalRepositoryInterface $repository;
/**
* ConvertController constructor.
@@ -76,13 +78,14 @@ class ConvertController extends Controller
}
);
}
/**
* Show overview of a to be converted transaction.
*
* @param TransactionType $destinationType
* @param TransactionGroup $group
*
* @return RedirectResponse|Redirector|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
* @return RedirectResponse|Redirector|Factory|View
* @throws Exception
*
*/
@@ -141,6 +144,137 @@ class ConvertController extends Controller
);
}
/**
* @return array
*/
private function getValidDepositSources(): array
{
// make repositories
$liabilityTypes = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN];
$accountList = $this->accountRepository
->getActiveAccountsByType([AccountType::REVENUE, AccountType::CASH, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]);
$grouped = [];
// group accounts:
/** @var Account $account */
foreach ($accountList as $account) {
$role = (string)$this->accountRepository->getMetaValue($account, 'account_role');
$name = $account->name;
if ('' === $role) {
$role = 'no_account_type'; // @codeCoverageIgnore
}
// maybe it's a liability thing:
if (in_array($account->accountType->type, $liabilityTypes, true)) {
$role = 'l_' . $account->accountType->type; // @codeCoverageIgnore
}
if (AccountType::CASH === $account->accountType->type) {
// @codeCoverageIgnoreStart
$role = 'cash_account';
$name = sprintf('(%s)', trans('firefly.cash'));
// @codeCoverageIgnoreEnd
}
if (AccountType::REVENUE === $account->accountType->type) {
$role = 'revenue_account'; // @codeCoverageIgnore
}
$key = (string)trans('firefly.opt_group_' . $role);
$grouped[$key][$account->id] = $name;
}
return $grouped;
}
/**
* @return array
*/
private function getValidWithdrawalDests(): array
{
// make repositories
$liabilityTypes = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN];
$accountList = $this->accountRepository->getActiveAccountsByType(
[AccountType::EXPENSE, AccountType::CASH, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]
);
$grouped = [];
// group accounts:
/** @var Account $account */
foreach ($accountList as $account) {
$role = (string)$this->accountRepository->getMetaValue($account, 'account_role');
$name = $account->name;
if ('' === $role) {
$role = 'no_account_type'; // @codeCoverageIgnore
}
// maybe it's a liability thing:
if (in_array($account->accountType->type, $liabilityTypes, true)) {
$role = 'l_' . $account->accountType->type; // @codeCoverageIgnore
}
if (AccountType::CASH === $account->accountType->type) {
// @codeCoverageIgnoreStart
$role = 'cash_account';
$name = sprintf('(%s)', trans('firefly.cash'));
// @codeCoverageIgnoreEnd
}
if (AccountType::EXPENSE === $account->accountType->type) {
$role = 'expense_account'; // @codeCoverageIgnore
}
$key = (string)trans('firefly.opt_group_' . $role);
$grouped[$key][$account->id] = $name;
}
return $grouped;
}
/**
* @return array
* @throws Exception
*/
private function getLiabilities(): array
{
// make repositories
$accountList = $this->accountRepository->getActiveAccountsByType([AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]);
$defaultCurrency = app('amount')->getDefaultCurrency();
$grouped = [];
// group accounts:
/** @var Account $account */
foreach ($accountList as $account) {
$balance = app('steam')->balance($account, today());
$currency = $this->accountRepository->getAccountCurrency($account) ?? $defaultCurrency;
$role = 'l_' . $account->accountType->type;
$key = (string)trans('firefly.opt_group_' . $role);
$grouped[$key][$account->id] = $account->name . ' (' . app('amount')->formatAnything($currency, $balance, false) . ')';
}
return $grouped;
}
/**
* @return array
* @throws Exception
*/
private function getAssetAccounts(): array
{
// make repositories
$accountList = $this->accountRepository->getActiveAccountsByType([AccountType::ASSET]);
$defaultCurrency = app('amount')->getDefaultCurrency();
$grouped = [];
// group accounts:
/** @var Account $account */
foreach ($accountList as $account) {
$balance = app('steam')->balance($account, today());
$currency = $this->accountRepository->getAccountCurrency($account) ?? $defaultCurrency;
$role = (string)$this->accountRepository->getMetaValue($account, 'account_role');
if ('' === $role) {
$role = 'no_account_type'; // @codeCoverageIgnore
}
$key = (string)trans('firefly.opt_group_' . $role);
$grouped[$key][$account->id] = $account->name . ' (' . app('amount')->formatAnything($currency, $balance, false) . ')';
}
return $grouped;
}
/**
* Do the conversion.
*
@@ -232,135 +366,4 @@ class ConvertController extends Controller
return $journal;
}
/**
* @return array
* @throws Exception
*/
private function getAssetAccounts(): array
{
// make repositories
$accountList = $this->accountRepository->getActiveAccountsByType([AccountType::ASSET]);
$defaultCurrency = app('amount')->getDefaultCurrency();
$grouped = [];
// group accounts:
/** @var Account $account */
foreach ($accountList as $account) {
$balance = app('steam')->balance($account, today());
$currency = $this->accountRepository->getAccountCurrency($account) ?? $defaultCurrency;
$role = (string)$this->accountRepository->getMetaValue($account, 'account_role');
if ('' === $role) {
$role = 'no_account_type'; // @codeCoverageIgnore
}
$key = (string)trans('firefly.opt_group_' . $role);
$grouped[$key][$account->id] = $account->name . ' (' . app('amount')->formatAnything($currency, $balance, false) . ')';
}
return $grouped;
}
/**
* @return array
* @throws Exception
*/
private function getLiabilities(): array
{
// make repositories
$accountList = $this->accountRepository->getActiveAccountsByType([AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]);
$defaultCurrency = app('amount')->getDefaultCurrency();
$grouped = [];
// group accounts:
/** @var Account $account */
foreach ($accountList as $account) {
$balance = app('steam')->balance($account, today());
$currency = $this->accountRepository->getAccountCurrency($account) ?? $defaultCurrency;
$role = 'l_' . $account->accountType->type;
$key = (string)trans('firefly.opt_group_' . $role);
$grouped[$key][$account->id] = $account->name . ' (' . app('amount')->formatAnything($currency, $balance, false) . ')';
}
return $grouped;
}
/**
* @return array
*/
private function getValidDepositSources(): array
{
// make repositories
$liabilityTypes = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN];
$accountList = $this->accountRepository
->getActiveAccountsByType([AccountType::REVENUE, AccountType::CASH, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]);
$grouped = [];
// group accounts:
/** @var Account $account */
foreach ($accountList as $account) {
$role = (string)$this->accountRepository->getMetaValue($account, 'account_role');
$name = $account->name;
if ('' === $role) {
$role = 'no_account_type'; // @codeCoverageIgnore
}
// maybe it's a liability thing:
if (in_array($account->accountType->type, $liabilityTypes, true)) {
$role = 'l_' . $account->accountType->type; // @codeCoverageIgnore
}
if (AccountType::CASH === $account->accountType->type) {
// @codeCoverageIgnoreStart
$role = 'cash_account';
$name = sprintf('(%s)', trans('firefly.cash'));
// @codeCoverageIgnoreEnd
}
if (AccountType::REVENUE === $account->accountType->type) {
$role = 'revenue_account'; // @codeCoverageIgnore
}
$key = (string)trans('firefly.opt_group_' . $role);
$grouped[$key][$account->id] = $name;
}
return $grouped;
}
/**
* @return array
*/
private function getValidWithdrawalDests(): array
{
// make repositories
$liabilityTypes = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN];
$accountList = $this->accountRepository->getActiveAccountsByType(
[AccountType::EXPENSE, AccountType::CASH, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]
);
$grouped = [];
// group accounts:
/** @var Account $account */
foreach ($accountList as $account) {
$role = (string)$this->accountRepository->getMetaValue($account, 'account_role');
$name = $account->name;
if ('' === $role) {
$role = 'no_account_type'; // @codeCoverageIgnore
}
// maybe it's a liability thing:
if (in_array($account->accountType->type, $liabilityTypes, true)) {
$role = 'l_' . $account->accountType->type; // @codeCoverageIgnore
}
if (AccountType::CASH === $account->accountType->type) {
// @codeCoverageIgnoreStart
$role = 'cash_account';
$name = sprintf('(%s)', trans('firefly.cash'));
// @codeCoverageIgnoreEnd
}
if (AccountType::EXPENSE === $account->accountType->type) {
$role = 'expense_account'; // @codeCoverageIgnore
}
$key = (string)trans('firefly.opt_group_' . $role);
$grouped[$key][$account->id] = $name;
}
return $grouped;
}
}

View File

@@ -112,6 +112,7 @@ class CreateController extends Controller
$previousUri = str_replace($search, '', $previousUri);
session()->put('preFilled', $preFilled);
return prefixView(
'transactions.create',
compact(

View File

@@ -22,6 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Transaction;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\TransactionGroup;
use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface;
@@ -38,6 +39,7 @@ use URL;
class DeleteController extends Controller
{
use UserNavigation;
/** @var TransactionGroupRepositoryInterface */
private $repository;

View File

@@ -22,11 +22,14 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Transaction;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\TransactionGroup;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Support\Http\Controllers\UserNavigation;
use Illuminate\Contracts\View\Factory;
use Illuminate\Http\RedirectResponse;
use Illuminate\Routing\Redirector;
use Illuminate\View\View;
/**
@@ -56,10 +59,11 @@ class EditController extends Controller
}
);
}
/**
* @param TransactionGroup $transactionGroup
*
* @return Factory|View|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
* @return Factory|View|RedirectResponse|Redirector
*/
public function edit(TransactionGroup $transactionGroup)
{
@@ -83,6 +87,7 @@ class EditController extends Controller
$parts = parse_url($previousUri);
$search = sprintf('?%s', $parts['query'] ?? '');
$previousUri = str_replace($search, '', $previousUri);
return prefixView(
'transactions.edit',
compact(

View File

@@ -22,6 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Transaction;
use Carbon\Carbon;
use Exception;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
@@ -71,8 +72,8 @@ class IndexController extends Controller
* @param Carbon|null $start
* @param Carbon|null $end
*
* @throws Exception
* @return Factory|View
* @throws Exception
*/
public function index(Request $request, string $objectType, Carbon $start = null, Carbon $end = null)
{
@@ -124,8 +125,8 @@ class IndexController extends Controller
* @param Request $request
* @param string $objectType
*
* @throws Exception
* @return Factory|View
* @throws Exception
*/
public function indexAll(Request $request, string $objectType)
{

View File

@@ -160,8 +160,8 @@ class MassController extends Controller
*
* @param MassEditJournalRequest $request
*
* @throws FireflyException
* @return RedirectResponse|Redirector
* @throws FireflyException
*/
public function update(MassEditJournalRequest $request)
{
@@ -189,76 +189,6 @@ class MassController extends Controller
return redirect($this->getPreviousUri('transactions.mass-edit.uri'));
}
/**
* @param MassEditJournalRequest $request
* @param int $journalId
* @param string $string
*
* @return Carbon|null
* @codeCoverageIgnore
*/
private function getDateFromRequest(MassEditJournalRequest $request, int $journalId, string $string): ?Carbon
{
$value = $request->get($string);
if (!is_array($value)) {
return null;
}
if (!isset($value[$journalId])) {
return null;
}
try {
$carbon = Carbon::parse($value[$journalId]);
} catch (InvalidArgumentException $e) {
$e->getMessage();
return null;
}
return $carbon;
}
/**
* @param MassEditJournalRequest $request
* @param int $journalId
* @param string $string
*
* @return int|null
* @codeCoverageIgnore
*/
private function getIntFromRequest(MassEditJournalRequest $request, int $journalId, string $string): ?int
{
$value = $request->get($string);
if (!is_array($value)) {
return null;
}
if (!isset($value[$journalId])) {
return null;
}
return (int) $value[$journalId];
}
/**
* @param MassEditJournalRequest $request
* @param int $journalId
* @param string $string
*
* @return string|null
* @codeCoverageIgnore
*/
private function getStringFromRequest(MassEditJournalRequest $request, int $journalId, string $string): ?string
{
$value = $request->get($string);
if (!is_array($value)) {
return null;
}
if (!isset($value[$journalId])) {
return null;
}
return (string) $value[$journalId];
}
/**
* @param int $journalId
* @param MassEditJournalRequest $request
@@ -295,4 +225,74 @@ class MassController extends Controller
// trigger rules
event(new UpdatedTransactionGroup($journal->transactionGroup));
}
/**
* @param MassEditJournalRequest $request
* @param int $journalId
* @param string $string
*
* @return Carbon|null
* @codeCoverageIgnore
*/
private function getDateFromRequest(MassEditJournalRequest $request, int $journalId, string $string): ?Carbon
{
$value = $request->get($string);
if (!is_array($value)) {
return null;
}
if (!isset($value[$journalId])) {
return null;
}
try {
$carbon = Carbon::parse($value[$journalId]);
} catch (InvalidArgumentException $e) {
$e->getMessage();
return null;
}
return $carbon;
}
/**
* @param MassEditJournalRequest $request
* @param int $journalId
* @param string $string
*
* @return string|null
* @codeCoverageIgnore
*/
private function getStringFromRequest(MassEditJournalRequest $request, int $journalId, string $string): ?string
{
$value = $request->get($string);
if (!is_array($value)) {
return null;
}
if (!isset($value[$journalId])) {
return null;
}
return (string)$value[$journalId];
}
/**
* @param MassEditJournalRequest $request
* @param int $journalId
* @param string $string
*
* @return int|null
* @codeCoverageIgnore
*/
private function getIntFromRequest(MassEditJournalRequest $request, int $journalId, string $string): ?int
{
$value = $request->get($string);
if (!is_array($value)) {
return null;
}
if (!isset($value[$journalId])) {
return null;
}
return (int)$value[$journalId];
}
}

View File

@@ -75,8 +75,8 @@ class ShowController extends Controller
/**
* @param TransactionGroup $transactionGroup
*
* @throws FireflyException
* @return Factory|View
* @throws FireflyException
*/
public function show(Request $request, TransactionGroup $transactionGroup)
{
@@ -186,6 +186,7 @@ class ShowController extends Controller
$accounts['source'] = array_unique($accounts['source'], SORT_REGULAR);
$accounts['destination'] = array_unique($accounts['destination'], SORT_REGULAR);
return $accounts;
}
}

View File

@@ -73,6 +73,7 @@ class Authenticate
return $next($request);
}
/**
* Determine if the user is logged in to any of the given guards.
*

View File

@@ -20,6 +20,7 @@
*/
declare(strict_types=1);
namespace FireflyIII\Http\Middleware;
use Closure;

View File

@@ -22,6 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Middleware;
use Closure;
use FireflyIII\Models\TransactionGroup;
use FireflyIII\Models\TransactionJournal;

Some files were not shown because too many files have changed in this diff Show More