mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Refactor references to static facades. Improve budget controller code.
This commit is contained in:
parent
b8699422c8
commit
89834baf01
@ -29,7 +29,6 @@ use FireflyIII\Http\Requests\AccountFormRequest;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use Illuminate\Http\Request;
|
||||
use Preferences;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -103,11 +102,11 @@ class CreateController extends Controller
|
||||
app('preferences')->mark();
|
||||
|
||||
// update preferences if necessary:
|
||||
$frontPage = Preferences::get('frontPageAccounts', [])->data;
|
||||
$frontPage = app('preferences')->get('frontPageAccounts', [])->data;
|
||||
if (AccountType::ASSET === $account->accountType->type && \count($frontPage) > 0) {
|
||||
// @codeCoverageIgnoreStart
|
||||
$frontPage[] = $account->id;
|
||||
Preferences::set('frontPageAccounts', $frontPage);
|
||||
app('preferences')->set('frontPageAccounts', $frontPage);
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
// redirect to previous URL.
|
||||
|
@ -29,7 +29,6 @@ use FireflyIII\Models\Account;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Preferences;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -75,7 +74,7 @@ class IndexController extends Controller
|
||||
$collection = $this->repository->getAccountsByType($types);
|
||||
$total = $collection->count();
|
||||
$page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page');
|
||||
$pageSize = (int)Preferences::get('listPageSize', 50)->data;
|
||||
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
|
||||
$accounts = $collection->slice(($page - 1) * $pageSize, $pageSize);
|
||||
unset($collection);
|
||||
/** @var Carbon $start */
|
||||
|
@ -38,7 +38,6 @@ use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Services\Internal\Update\CurrencyUpdateService;
|
||||
use Log;
|
||||
use Preferences;
|
||||
|
||||
/**
|
||||
* Class ReconcileController.
|
||||
@ -138,7 +137,7 @@ class ReconcileController extends Controller
|
||||
}
|
||||
|
||||
// no start or end:
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
$range = app('preferences')->get('viewRange', '1M')->data;
|
||||
|
||||
// get start and end
|
||||
if (null === $start && null === $end) {
|
||||
|
@ -36,7 +36,6 @@ use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Collection;
|
||||
use Preferences;
|
||||
use View;
|
||||
|
||||
/**
|
||||
@ -100,7 +99,7 @@ class ShowController extends Controller
|
||||
$today = new Carbon;
|
||||
$subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $account->accountType->type));
|
||||
$page = (int)$request->get('page');
|
||||
$pageSize = (int)Preferences::get('listPageSize', 50)->data;
|
||||
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
|
||||
$currencyId = (int)$this->repository->getMetaValue($account, 'currency_id');
|
||||
$currency = $this->currencyRepos->findNull($currencyId);
|
||||
if (0 === $currencyId) {
|
||||
@ -146,7 +145,7 @@ class ShowController extends Controller
|
||||
$start = $this->repository->oldestJournalDate($account);
|
||||
$subTitleIcon = config('firefly.subIconsByIdentifier.' . $account->accountType->type);
|
||||
$page = (int)$request->get('page');
|
||||
$pageSize = (int)Preferences::get('listPageSize', 50)->data;
|
||||
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
|
||||
$currencyId = (int)$this->repository->getMetaValue($account, 'currency_id');
|
||||
$currency = $this->currencyRepos->findNull($currencyId);
|
||||
if (0 === $currencyId) {
|
||||
@ -187,7 +186,7 @@ class ShowController extends Controller
|
||||
*/
|
||||
private function getPeriodOverview(Account $account, ?Carbon $date): Collection
|
||||
{
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
$range = app('preferences')->get('viewRange', '1M')->data;
|
||||
$start = $this->repository->oldestJournalDate($account);
|
||||
$end = $date ?? new Carbon;
|
||||
if ($end < $start) {
|
||||
|
@ -29,7 +29,6 @@ use FireflyIII\Http\Requests\UserFormRequest;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\User;
|
||||
use Log;
|
||||
use Preferences;
|
||||
|
||||
/**
|
||||
* Class UserController.
|
||||
@ -121,7 +120,7 @@ class UserController extends Controller
|
||||
$users->each(
|
||||
function (User $user) use ($repository) {
|
||||
$list = ['twoFactorAuthEnabled', 'twoFactorAuthSecret'];
|
||||
$preferences = Preferences::getArrayForUser($user, $list);
|
||||
$preferences = app('preferences')->getArrayForUser($user, $list);
|
||||
$user->isAdmin = $repository->hasRole($user, 'owner');
|
||||
$is2faEnabled = 1 === $preferences['twoFactorAuthEnabled'];
|
||||
$has2faSecret = null !== $preferences['twoFactorAuthSecret'];
|
||||
|
@ -29,7 +29,6 @@ use FireflyIII\User;
|
||||
use Illuminate\Cookie\CookieJar;
|
||||
use Illuminate\Http\Request;
|
||||
use Log;
|
||||
use Preferences;
|
||||
|
||||
/**
|
||||
* Class TwoFactorController.
|
||||
@ -49,12 +48,12 @@ class TwoFactorController extends Controller
|
||||
$user = auth()->user();
|
||||
|
||||
// to make sure the validator in the next step gets the secret, we push it in session
|
||||
$secretPreference = Preferences::get('twoFactorAuthSecret', null);
|
||||
$secretPreference = app('preferences')->get('twoFactorAuthSecret', null);
|
||||
$secret = null === $secretPreference ? null : $secretPreference->data;
|
||||
$title = (string)trans('firefly.two_factor_title');
|
||||
|
||||
// make sure the user has two factor configured:
|
||||
$has2FA = Preferences::get('twoFactorAuthEnabled', false)->data;
|
||||
$has2FA = app('preferences')->get('twoFactorAuthEnabled', false)->data;
|
||||
if (null === $has2FA || false === $has2FA) {
|
||||
return redirect(route('index'));
|
||||
}
|
||||
|
@ -36,10 +36,8 @@ use Illuminate\Support\Collection;
|
||||
use League\Fractal\Manager;
|
||||
use League\Fractal\Resource\Item;
|
||||
use League\Fractal\Serializer\DataArraySerializer;
|
||||
use Preferences;
|
||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
use URL;
|
||||
use View;
|
||||
|
||||
/**
|
||||
* Class BillController.
|
||||
@ -65,7 +63,7 @@ class BillController extends Controller
|
||||
$maxFileSize = app('steam')->phpBytes(ini_get('upload_max_filesize'));
|
||||
$maxPostSize = app('steam')->phpBytes(ini_get('post_max_size'));
|
||||
$uploadSize = min($maxFileSize, $maxPostSize);
|
||||
View::share('uploadSize', $uploadSize);
|
||||
app('view')->share('uploadSize', $uploadSize);
|
||||
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
@ -186,7 +184,7 @@ class BillController extends Controller
|
||||
{
|
||||
$start = session('start');
|
||||
$end = session('end');
|
||||
$pageSize = (int)Preferences::get('listPageSize', 50)->data;
|
||||
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
|
||||
$paginator = $this->billRepository->getPaginator($pageSize);
|
||||
$parameters = new ParameterBag();
|
||||
$parameters->set('start', $start);
|
||||
@ -269,7 +267,7 @@ class BillController extends Controller
|
||||
$end = session('end');
|
||||
$year = $start->year;
|
||||
$page = (int)$request->get('page');
|
||||
$pageSize = (int)Preferences::get('listPageSize', 50)->data;
|
||||
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
|
||||
$yearAverage = $this->billRepository->getYearAverage($bill, $start);
|
||||
$overallAverage = $this->billRepository->getOverallAverage($bill);
|
||||
$manager = new Manager();
|
||||
|
@ -32,13 +32,12 @@ use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
use FireflyIII\Support\Http\Controllers\DateCalculation;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Preferences;
|
||||
use View;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -46,6 +45,7 @@ use View;
|
||||
*/
|
||||
class AmountController extends Controller
|
||||
{
|
||||
use DateCalculation;
|
||||
/** @var BudgetRepositoryInterface */
|
||||
private $repository;
|
||||
|
||||
@ -56,7 +56,7 @@ class AmountController extends Controller
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
View::share('hideBudgets', true);
|
||||
app('view')->share('hideBudgets', true);
|
||||
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
@ -79,53 +79,36 @@ class AmountController extends Controller
|
||||
*/
|
||||
public function amount(Request $request, BudgetRepositoryInterface $repository, Budget $budget): JsonResponse
|
||||
{
|
||||
$amount = (string)$request->get('amount');
|
||||
$start = Carbon::createFromFormat('Y-m-d', $request->get('start'));
|
||||
$end = Carbon::createFromFormat('Y-m-d', $request->get('end'));
|
||||
$budgetLimit = $this->repository->updateLimitAmount($budget, $start, $end, $amount);
|
||||
$largeDiff = false;
|
||||
$warnText = '';
|
||||
$days = 0;
|
||||
$daysInMonth = 0;
|
||||
if (0 === bccomp($amount, '0')) {
|
||||
$budgetLimit = null;
|
||||
}
|
||||
$amount = (string)$request->get('amount');
|
||||
$start = Carbon::createFromFormat('Y-m-d', $request->get('start'));
|
||||
$end = Carbon::createFromFormat('Y-m-d', $request->get('end'));
|
||||
$budgetLimit = $this->repository->updateLimitAmount($budget, $start, $end, $amount);
|
||||
$spent = $repository->spentInPeriod(new Collection([$budget]), new Collection, $start, $end);
|
||||
$currency = app('amount')->getDefaultCurrency();
|
||||
$left = app('amount')->formatAnything($currency, bcadd($amount, $spent), true);
|
||||
$largeDiff = false;
|
||||
$warnText = '';
|
||||
$leftPerDay = null;
|
||||
$periodLength = $start->diffInDays($end);
|
||||
$dayDifference = $this->getDayDifference($start, $end);
|
||||
|
||||
// if today is between start and end, use the diff in days between end and today (days left)
|
||||
// otherwise, use diff between start and end.
|
||||
$today = new Carbon;
|
||||
Log::debug(sprintf('Start is %s, end is %s, today is %s', $start->format('Y-m-d'), $end->format('Y-m-d'), $today->format('Y-m-d')));
|
||||
if ($today->gte($start) && $today->lte($end)) {
|
||||
$days = $end->diffInDays($today);
|
||||
$daysInMonth = $start->diffInDays($today);
|
||||
}
|
||||
if ($today->lte($start) || $today->gte($end)) {
|
||||
$days = $start->diffInDays($end);
|
||||
$daysInMonth = $start->diffInDays($end);
|
||||
}
|
||||
$days = 0 === $days ? 1 : $days;
|
||||
$daysInMonth = 0 === $daysInMonth ? 1 : $daysInMonth;
|
||||
|
||||
// calculate left in budget:
|
||||
$spent = $repository->spentInPeriod(new Collection([$budget]), new Collection, $start, $end);
|
||||
$currency = app('amount')->getDefaultCurrency();
|
||||
$left = app('amount')->formatAnything($currency, bcadd($amount, $spent), true);
|
||||
$leftPerDay = 'none';
|
||||
|
||||
// is user has money left, calculate.
|
||||
/*
|
||||
* If the user budgets ANY amount per day for this budget (anything but zero)
|
||||
* Firefly III calculates how much he could spend per day.
|
||||
*/
|
||||
if (1 === bccomp(bcadd($amount, $spent), '0')) {
|
||||
$leftPerDay = app('amount')->formatAnything($currency, bcdiv(bcadd($amount, $spent), (string)$days), true);
|
||||
$leftPerDay = app('amount')->formatAnything($currency, bcdiv(bcadd($amount, $spent), (string)$dayDifference), true);
|
||||
}
|
||||
|
||||
|
||||
// over or under budgeting, compared to previous budgets?
|
||||
/*
|
||||
* Get the average amount of money the user budgets for this budget.
|
||||
* And calculate the same for the current amount.
|
||||
*
|
||||
* If the difference is very large, give the user a notification.
|
||||
*/
|
||||
$average = $this->repository->budgetedPerDay($budget);
|
||||
// current average per day:
|
||||
$diff = $start->diffInDays($end);
|
||||
$current = $amount;
|
||||
if ($diff > 0) {
|
||||
$current = bcdiv($amount, (string)$diff);
|
||||
}
|
||||
$current = bcdiv($amount, (string)$periodLength);
|
||||
if (bccomp(bcmul('1.1', $average), $current) === -1) {
|
||||
$largeDiff = true;
|
||||
$warnText = (string)trans(
|
||||
@ -150,8 +133,6 @@ class AmountController extends Controller
|
||||
'large_diff' => $largeDiff,
|
||||
'left_per_day' => $leftPerDay,
|
||||
'warn_text' => $warnText,
|
||||
'daysInMonth' => $daysInMonth,
|
||||
|
||||
]
|
||||
);
|
||||
}
|
||||
@ -187,7 +168,7 @@ class AmountController extends Controller
|
||||
'suggested' => '0',
|
||||
];
|
||||
$currency = app('amount')->getDefaultCurrency();
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
$range = app('preferences')->get('viewRange', '1M')->data;
|
||||
/** @var Carbon $begin */
|
||||
$begin = app('navigation')->subtractPeriod($start, $range, 3);
|
||||
|
||||
@ -272,5 +253,4 @@ class AmountController extends Controller
|
||||
|
||||
return view('budgets.income', compact('available', 'start', 'end', 'page'));
|
||||
}
|
||||
|
||||
}
|
@ -29,7 +29,6 @@ use FireflyIII\Http\Requests\BudgetFormRequest;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use View;
|
||||
|
||||
/**
|
||||
* Class CreateController
|
||||
@ -46,7 +45,7 @@ class CreateController extends Controller
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
View::share('hideBudgets', true);
|
||||
app('view')->share('hideBudgets', true);
|
||||
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
|
@ -28,7 +28,6 @@ use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use Illuminate\Http\Request;
|
||||
use View;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -46,7 +45,7 @@ class DeleteController extends Controller
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
View::share('hideBudgets', true);
|
||||
app('view')->share('hideBudgets', true);
|
||||
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
|
@ -30,7 +30,6 @@ use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use View;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -48,7 +47,7 @@ class EditController extends Controller
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
View::share('hideBudgets', true);
|
||||
app('view')->share('hideBudgets', true);
|
||||
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
|
@ -28,11 +28,10 @@ use Carbon\Carbon;
|
||||
use Exception;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Support\Http\Controllers\DateCalculation;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Log;
|
||||
use Preferences;
|
||||
use View;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -41,6 +40,7 @@ use View;
|
||||
class IndexController extends Controller
|
||||
{
|
||||
|
||||
use DateCalculation;
|
||||
/** @var BudgetRepositoryInterface */
|
||||
private $repository;
|
||||
|
||||
@ -51,7 +51,7 @@ class IndexController extends Controller
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
View::share('hideBudgets', true);
|
||||
app('view')->share('hideBudgets', true);
|
||||
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
@ -73,13 +73,13 @@ class IndexController extends Controller
|
||||
*/
|
||||
public function index(Request $request, string $moment = null)
|
||||
{
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
$start = session('start', new Carbon);
|
||||
$end = session('end', new Carbon);
|
||||
$page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page');
|
||||
$pageSize = (int)Preferences::get('listPageSize', 50)->data;
|
||||
$days = 0;
|
||||
$daysInMonth = 0;
|
||||
$range = app('preferences')->get('viewRange', '1M')->data;
|
||||
$start = session('start', new Carbon);
|
||||
$end = session('end', new Carbon);
|
||||
$page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page');
|
||||
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
|
||||
$days = 0;
|
||||
|
||||
|
||||
// make date if present:
|
||||
if (null !== $moment || '' !== (string)$moment) {
|
||||
@ -96,15 +96,12 @@ class IndexController extends Controller
|
||||
// otherwise, use diff between start and end.
|
||||
$today = new Carbon;
|
||||
if ($today->gte($start) && $today->lte($end)) {
|
||||
$days = $end->diffInDays($today);
|
||||
$daysInMonth = $start->diffInDays($today);
|
||||
$days = $end->diffInDays($today);
|
||||
}
|
||||
if ($today->lte($start) || $today->gte($end)) {
|
||||
$days = $start->diffInDays($end);
|
||||
$daysInMonth = $start->diffInDays($end);
|
||||
$days = $start->diffInDays($end);
|
||||
}
|
||||
$days = 0 === $days ? 1 : $days;
|
||||
$daysInMonth = 0 === $daysInMonth ? 1 : $daysInMonth;
|
||||
$days = 0 === $days ? 1 : $days;
|
||||
|
||||
|
||||
$next = clone $end;
|
||||
@ -113,6 +110,7 @@ class IndexController extends Controller
|
||||
$prev->subDay();
|
||||
$prev = app('navigation')->startOfPeriod($prev, $range);
|
||||
$this->repository->cleanupBudgets();
|
||||
$daysPassed = $this->getDaysPassedInPeriod($start, $end);
|
||||
$allBudgets = $this->repository->getActiveBudgets();
|
||||
$total = $allBudgets->count();
|
||||
$budgets = $allBudgets->slice(($page - 1) * $pageSize, $pageSize);
|
||||
@ -165,10 +163,14 @@ class IndexController extends Controller
|
||||
return view(
|
||||
'budgets.index', compact(
|
||||
'available', 'currentMonth', 'next', 'nextText', 'prev', 'allBudgets', 'prevText', 'periodStart', 'periodEnd', 'days', 'page',
|
||||
'budgetInformation', 'daysInMonth',
|
||||
'budgetInformation', 'daysPassed',
|
||||
'inactive', 'budgets', 'spent', 'budgeted', 'previousLoop', 'nextLoop', 'start', 'end'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -36,8 +36,6 @@ use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Collection;
|
||||
use Preferences;
|
||||
use View;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -56,7 +54,7 @@ class ShowController extends Controller
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
View::share('hideBudgets', true);
|
||||
app('view')->share('hideBudgets', true);
|
||||
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
@ -80,7 +78,7 @@ class ShowController extends Controller
|
||||
{
|
||||
// default values:
|
||||
$moment = $moment ?? '';
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
$range = app('preferences')->get('viewRange', '1M')->data;
|
||||
$start = null;
|
||||
$end = null;
|
||||
$periods = new Collection;
|
||||
@ -117,7 +115,7 @@ class ShowController extends Controller
|
||||
}
|
||||
|
||||
$page = (int)$request->get('page');
|
||||
$pageSize = (int)Preferences::get('listPageSize', 50)->data;
|
||||
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
|
||||
|
||||
/** @var JournalCollectorInterface $collector */
|
||||
$collector = app(JournalCollectorInterface::class);
|
||||
@ -141,7 +139,7 @@ class ShowController extends Controller
|
||||
$start = session('first', Carbon::create()->startOfYear());
|
||||
$end = new Carbon;
|
||||
$page = (int)$request->get('page');
|
||||
$pageSize = (int)Preferences::get('listPageSize', 50)->data;
|
||||
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
|
||||
$limits = $this->getLimits($budget, $start, $end);
|
||||
$repetition = null;
|
||||
|
||||
@ -172,7 +170,7 @@ class ShowController extends Controller
|
||||
}
|
||||
|
||||
$page = (int)$request->get('page');
|
||||
$pageSize = (int)Preferences::get('listPageSize', 50)->data;
|
||||
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
|
||||
$subTitle = trans(
|
||||
'firefly.budget_in_period',
|
||||
[
|
||||
@ -239,7 +237,7 @@ class ShowController extends Controller
|
||||
$repository = app(JournalRepositoryInterface::class);
|
||||
$first = $repository->firstNull();
|
||||
$start = null === $first ? new Carbon : $first->date;
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
$range = app('preferences')->get('viewRange', '1M')->data;
|
||||
$start = app('navigation')->startOfPeriod($start, $range);
|
||||
$end = app('navigation')->endOfX(new Carbon, $range, null);
|
||||
$entries = new Collection;
|
||||
|
@ -37,7 +37,6 @@ use Illuminate\Http\Request;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Preferences;
|
||||
|
||||
/**
|
||||
* Class CategoryController.
|
||||
@ -146,7 +145,7 @@ class CategoryController extends Controller
|
||||
public function index(Request $request)
|
||||
{
|
||||
$page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page');
|
||||
$pageSize = (int)Preferences::get('listPageSize', 50)->data;
|
||||
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
|
||||
$collection = $this->repository->getCategories();
|
||||
$total = $collection->count();
|
||||
$collection = $collection->slice(($page - 1) * $pageSize, $pageSize);
|
||||
@ -174,12 +173,12 @@ class CategoryController extends Controller
|
||||
{
|
||||
// default values:
|
||||
$moment = $moment ?? '';
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
$range = app('preferences')->get('viewRange', '1M')->data;
|
||||
$start = null;
|
||||
$end = null;
|
||||
$periods = new Collection;
|
||||
$page = (int)$request->get('page');
|
||||
$pageSize = (int)Preferences::get('listPageSize', 50)->data;
|
||||
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
|
||||
Log::debug('Start of noCategory()');
|
||||
// prep for "all" view.
|
||||
if ('all' === $moment) {
|
||||
@ -242,8 +241,8 @@ class CategoryController extends Controller
|
||||
$subTitle = $category->name;
|
||||
$subTitleIcon = 'fa-bar-chart';
|
||||
$page = (int)$request->get('page');
|
||||
$pageSize = (int)Preferences::get('listPageSize', 50)->data;
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
|
||||
$range = app('preferences')->get('viewRange', '1M')->data;
|
||||
$start = null;
|
||||
$end = null;
|
||||
$periods = new Collection;
|
||||
@ -362,7 +361,7 @@ class CategoryController extends Controller
|
||||
private function getNoCategoryPeriodOverview(Carbon $theDate): Collection
|
||||
{
|
||||
Log::debug(sprintf('Now in getNoCategoryPeriodOverview(%s)', $theDate->format('Y-m-d')));
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
$range = app('preferences')->get('viewRange', '1M')->data;
|
||||
$first = $this->journalRepos->firstNull();
|
||||
$start = null === $first ? new Carbon : $first->date;
|
||||
$end = $theDate ?? new Carbon;
|
||||
@ -447,7 +446,7 @@ class CategoryController extends Controller
|
||||
*/
|
||||
private function getPeriodOverview(Category $category, Carbon $date): Collection
|
||||
{
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
$range = app('preferences')->get('viewRange', '1M')->data;
|
||||
$first = $this->journalRepos->firstNull();
|
||||
$start = null === $first ? new Carbon : $first->date;
|
||||
$end = $date ?? new Carbon;
|
||||
|
@ -39,7 +39,6 @@ use FireflyIII\Support\CacheProperties;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Preferences;
|
||||
|
||||
/** checked
|
||||
* Class AccountController.
|
||||
@ -231,7 +230,7 @@ class AccountController extends Controller
|
||||
$end = clone session('end', Carbon::now()->endOfMonth());
|
||||
$defaultSet = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])->pluck('id')->toArray();
|
||||
Log::debug('Default set is ', $defaultSet);
|
||||
$frontPage = Preferences::get('frontPageAccounts', $defaultSet);
|
||||
$frontPage = app('preferences')->get('frontPageAccounts', $defaultSet);
|
||||
|
||||
|
||||
Log::debug('Frontpage preference set is ', $frontPage->data);
|
||||
|
@ -32,7 +32,6 @@ use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Collection;
|
||||
use Preferences;
|
||||
|
||||
/**
|
||||
* Class CategoryController.
|
||||
@ -77,7 +76,7 @@ class CategoryController extends Controller
|
||||
$start = new Carbon; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
$range = app('preferences')->get('viewRange', '1M')->data;
|
||||
$start = app('navigation')->startOfPeriod($start, $range);
|
||||
$end = new Carbon;
|
||||
$accounts = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
|
||||
@ -283,7 +282,7 @@ class CategoryController extends Controller
|
||||
*/
|
||||
public function specificPeriod(Category $category, Carbon $date): JsonResponse
|
||||
{
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
$range = app('preferences')->get('viewRange', '1M')->data;
|
||||
$start = app('navigation')->startOfPeriod($date, $range);
|
||||
$end = app('navigation')->endOfPeriod($date, $range);
|
||||
$data = $this->makePeriodChart($category, $start, $end);
|
||||
|
@ -27,7 +27,6 @@ use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Support\Facades\Preferences;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
@ -35,7 +34,6 @@ use Illuminate\Routing\Controller as BaseController;
|
||||
use Log;
|
||||
use Route;
|
||||
use URL;
|
||||
use View;
|
||||
|
||||
/**
|
||||
* Class Controller.
|
||||
@ -59,17 +57,17 @@ class Controller extends BaseController
|
||||
public function __construct()
|
||||
{
|
||||
// for transaction lists:
|
||||
View::share('hideBudgets', false);
|
||||
View::share('hideCategories', false);
|
||||
View::share('hideBills', false);
|
||||
View::share('hideTags', false);
|
||||
app('view')->share('hideBudgets', false);
|
||||
app('view')->share('hideCategories', false);
|
||||
app('view')->share('hideBills', false);
|
||||
app('view')->share('hideTags', false);
|
||||
|
||||
// is site a demo site?
|
||||
$isDemoSite = FireflyConfig::get('is_demo_site', config('firefly.configuration.is_demo_site'))->data;
|
||||
View::share('IS_DEMO_SITE', $isDemoSite);
|
||||
View::share('DEMO_USERNAME', env('DEMO_USERNAME', ''));
|
||||
View::share('DEMO_PASSWORD', env('DEMO_PASSWORD', ''));
|
||||
View::share('FF_VERSION', config('firefly.version'));
|
||||
app('view')->share('IS_DEMO_SITE', $isDemoSite);
|
||||
app('view')->share('DEMO_USERNAME', env('DEMO_USERNAME', ''));
|
||||
app('view')->share('DEMO_PASSWORD', env('DEMO_PASSWORD', ''));
|
||||
app('view')->share('FF_VERSION', config('firefly.version'));
|
||||
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
@ -93,17 +91,17 @@ class Controller extends BaseController
|
||||
|
||||
// either must be array and either must be > 0
|
||||
if ((\is_array($intro) || \is_array($specialIntro)) && (\count($intro) > 0 || \count($specialIntro) > 0)) {
|
||||
$shownDemo = Preferences::get($key, false)->data;
|
||||
$shownDemo = app('preferences')->get($key, false)->data;
|
||||
Log::debug(sprintf('Check if user has already seen intro with key "%s". Result is %d', $key, $shownDemo));
|
||||
}
|
||||
|
||||
// share language
|
||||
$language = Preferences::get('language', config('firefly.default_language', 'en_US'))->data;
|
||||
$language = app('preferences')->get('language', config('firefly.default_language', 'en_US'))->data;
|
||||
|
||||
View::share('language', $language);
|
||||
View::share('shownDemo', $shownDemo);
|
||||
View::share('current_route_name', $page);
|
||||
View::share('original_route_name', Route::currentRouteName());
|
||||
app('view')->share('language', $language);
|
||||
app('view')->share('shownDemo', $shownDemo);
|
||||
app('view')->share('current_route_name', $page);
|
||||
app('view')->share('original_route_name', Route::currentRouteName());
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
|
@ -31,7 +31,6 @@ use FireflyIII\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Log;
|
||||
use Preferences;
|
||||
use View;
|
||||
|
||||
/**
|
||||
@ -100,7 +99,7 @@ class CurrencyController extends Controller
|
||||
*/
|
||||
public function defaultCurrency(Request $request, TransactionCurrency $currency)
|
||||
{
|
||||
Preferences::set('currencyPreference', $currency->code);
|
||||
app('preferences')->set('currencyPreference', $currency->code);
|
||||
app('preferences')->mark();
|
||||
|
||||
$request->session()->flash('success', trans('firefly.new_default_currency', ['name' => $currency->name]));
|
||||
@ -215,7 +214,7 @@ class CurrencyController extends Controller
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
$page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page');
|
||||
$pageSize = (int)Preferences::get('listPageSize', 50)->data;
|
||||
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
|
||||
$collection = $this->repository->get();
|
||||
$total = $collection->count();
|
||||
$collection = $collection->sortBy(
|
||||
@ -227,7 +226,7 @@ class CurrencyController extends Controller
|
||||
$currencies = new LengthAwarePaginator($collection, $total, $pageSize, $page);
|
||||
$currencies->setPath(route('currencies.index'));
|
||||
|
||||
$defaultCurrency = $this->repository->getCurrencyByPreference(Preferences::get('currencyPreference', config('firefly.default_currency', 'EUR')));
|
||||
$defaultCurrency = $this->repository->getCurrencyByPreference(app('preferences')->get('currencyPreference', config('firefly.default_currency', 'EUR')));
|
||||
$isOwner = true;
|
||||
if (!$this->userRepository->hasRole($user, 'owner')) {
|
||||
$request->session()->flash('info', trans('firefly.ask_site_owner', ['owner' => env('SITE_OWNER')]));
|
||||
|
@ -32,7 +32,6 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\ExportJob\ExportJobRepositoryInterface;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Response as LaravelResponse;
|
||||
use Preferences;
|
||||
|
||||
/**
|
||||
* Class ExportController.
|
||||
@ -118,7 +117,7 @@ class ExportController extends Controller
|
||||
|
||||
// does the user have shared accounts?
|
||||
$formats = array_keys(config('firefly.export_formats'));
|
||||
$defaultFormat = Preferences::get('export_format', config('firefly.default_export_format'))->data;
|
||||
$defaultFormat = app('preferences')->get('export_format', config('firefly.default_export_format'))->data;
|
||||
$first = session('first')->format('Y-m-d');
|
||||
$today = Carbon::create()->format('Y-m-d');
|
||||
|
||||
|
@ -25,7 +25,6 @@ namespace FireflyIII\Http\Controllers;
|
||||
use FireflyIII\Helpers\Help\HelpInterface;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Log;
|
||||
use Preferences;
|
||||
|
||||
/**
|
||||
* Class HelpController.
|
||||
@ -58,7 +57,7 @@ class HelpController extends Controller
|
||||
*/
|
||||
public function show(string $route): JsonResponse
|
||||
{
|
||||
$language = Preferences::get('language', config('firefly.default_language', 'en_US'))->data;
|
||||
$language = app('preferences')->get('language', config('firefly.default_language', 'en_US'))->data;
|
||||
$html = $this->getHelpText($route, $language);
|
||||
|
||||
return response()->json(['html' => $html]);
|
||||
|
@ -36,7 +36,6 @@ use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Preferences;
|
||||
use View;
|
||||
|
||||
/**
|
||||
@ -111,7 +110,7 @@ class HomeController extends Controller
|
||||
}
|
||||
$subTitle = trans('firefly.welcomeBack');
|
||||
$transactions = [];
|
||||
$frontPage = Preferences::get(
|
||||
$frontPage = app('preferences')->get(
|
||||
'frontPageAccounts',
|
||||
$repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])->pluck('id')->toArray()
|
||||
);
|
||||
|
@ -31,7 +31,6 @@ use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Log;
|
||||
use Preferences;
|
||||
|
||||
/**
|
||||
* Class JavascriptController.
|
||||
@ -47,7 +46,7 @@ class JavascriptController extends Controller
|
||||
public function accounts(AccountRepositoryInterface $repository, CurrencyRepositoryInterface $currencyRepository): Response
|
||||
{
|
||||
$accounts = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
|
||||
$preference = Preferences::get('currencyPreference', config('firefly.default_currency', 'EUR'));
|
||||
$preference = app('preferences')->get('currencyPreference', config('firefly.default_currency', 'EUR'));
|
||||
/** @noinspection NullPointerExceptionInspection */
|
||||
$default = $currencyRepository->findByCodeNull($preference->data);
|
||||
|
||||
@ -114,7 +113,7 @@ class JavascriptController extends Controller
|
||||
$accounting = app('amount')->getJsConfig($localeconv);
|
||||
$localeconv = localeconv();
|
||||
$localeconv['frac_digits'] = $currency->decimal_places;
|
||||
$pref = Preferences::get('language', config('firefly.default_language', 'en_US'));
|
||||
$pref = app('preferences')->get('language', config('firefly.default_language', 'en_US'));
|
||||
/** @noinspection NullPointerExceptionInspection */
|
||||
$lang = $pref->data;
|
||||
$dateRange = $this->getDateRangeConfig();
|
||||
@ -140,7 +139,7 @@ class JavascriptController extends Controller
|
||||
*/
|
||||
private function getDateRangeConfig(): array
|
||||
{
|
||||
$viewRange = Preferences::get('viewRange', '1M')->data;
|
||||
$viewRange = app('preferences')->get('viewRange', '1M')->data;
|
||||
$start = session('start');
|
||||
$end = session('end');
|
||||
$first = session('first');
|
||||
|
@ -22,7 +22,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers\Json;
|
||||
|
||||
use FireflyIII\Support\Facades\Preferences;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Log;
|
||||
|
||||
@ -104,7 +103,7 @@ class IntroController
|
||||
$key .= '_' . $specialPage;
|
||||
}
|
||||
Log::debug(sprintf('Going to mark the following route as NOT done: %s with special "%s" (%s)', $route, $specialPage, $key));
|
||||
Preferences::set($key, false);
|
||||
app('preferences')->set($key, false);
|
||||
|
||||
return response()->json(['message' => trans('firefly.intro_boxes_after_refresh')]);
|
||||
}
|
||||
@ -123,7 +122,7 @@ class IntroController
|
||||
$key .= '_' . $specialPage;
|
||||
}
|
||||
Log::debug(sprintf('Going to mark the following route as done: %s with special "%s" (%s)', $route, $specialPage, $key));
|
||||
Preferences::set($key, true);
|
||||
app('preferences')->set($key, true);
|
||||
|
||||
return response()->json(['result' => sprintf('Reported demo watched for route "%s".', $route)]);
|
||||
}
|
||||
|
@ -27,7 +27,6 @@ use FireflyIII\Http\Requests\NewUserFormRequest;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use Preferences;
|
||||
use View;
|
||||
|
||||
/**
|
||||
@ -89,7 +88,7 @@ class NewUserController extends Controller
|
||||
}
|
||||
|
||||
// set language preference:
|
||||
Preferences::set('language', $language);
|
||||
app('preferences')->set('language', $language);
|
||||
// Store currency preference from input:
|
||||
$currency = $currencyRepository->findNull((int)$request->input('amount_currency_id_bank_balance'));
|
||||
|
||||
@ -108,7 +107,7 @@ class NewUserController extends Controller
|
||||
$this->createCashWalletAccount($currency, $language);
|
||||
|
||||
// store currency preference:
|
||||
Preferences::set('currencyPreference', $currency->code);
|
||||
app('preferences')->set('currencyPreference', $currency->code);
|
||||
app('preferences')->mark();
|
||||
|
||||
// set default optional fields:
|
||||
@ -123,7 +122,7 @@ class NewUserController extends Controller
|
||||
'notes' => true,
|
||||
'attachments' => true,
|
||||
];
|
||||
Preferences::set('transaction_journal_optional_fields', $visibleFields);
|
||||
app('preferences')->set('transaction_journal_optional_fields', $visibleFields);
|
||||
|
||||
session()->flash('success', (string)trans('firefly.stored_new_accounts_new_user'));
|
||||
app('preferences')->mark();
|
||||
|
@ -36,7 +36,6 @@ use Illuminate\Http\Request;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Preferences;
|
||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
|
||||
/**
|
||||
@ -220,7 +219,7 @@ class PiggyBankController extends Controller
|
||||
$collection = $this->piggyRepos->getPiggyBanks();
|
||||
$total = $collection->count();
|
||||
$page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page');
|
||||
$pageSize = (int)Preferences::get('listPageSize', 50)->data;
|
||||
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
|
||||
$accounts = [];
|
||||
/** @var Carbon $end */
|
||||
$end = session('end', Carbon::now()->endOfMonth());
|
||||
|
@ -35,7 +35,6 @@ use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Route;
|
||||
use InvalidArgumentException;
|
||||
use View;
|
||||
|
||||
/**
|
||||
* Class ReportController.
|
||||
@ -89,8 +88,8 @@ class ReportController extends Controller
|
||||
$attributes = $request->get('attributes') ?? [];
|
||||
$attributes = $this->parseAttributes($attributes);
|
||||
|
||||
View::share('start', $attributes['startDate']);
|
||||
View::share('end', $attributes['endDate']);
|
||||
app('view')->share('start', $attributes['startDate']);
|
||||
app('view')->share('end', $attributes['endDate']);
|
||||
|
||||
switch ($attributes['location']) {
|
||||
default:
|
||||
|
@ -25,7 +25,6 @@ namespace FireflyIII\Http\Controllers;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use Illuminate\Http\Request;
|
||||
use Preferences;
|
||||
|
||||
/**
|
||||
* Class PreferencesController.
|
||||
@ -57,16 +56,16 @@ class PreferencesController extends Controller
|
||||
public function index(AccountRepositoryInterface $repository)
|
||||
{
|
||||
$accounts = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
|
||||
$viewRangePref = Preferences::get('viewRange', '1M');
|
||||
$viewRangePref = app('preferences')->get('viewRange', '1M');
|
||||
/** @noinspection NullPointerExceptionInspection */
|
||||
$viewRange = $viewRangePref->data;
|
||||
$frontPageAccounts = Preferences::get('frontPageAccounts', []);
|
||||
$language = Preferences::get('language', config('firefly.default_language', 'en_US'))->data;
|
||||
$listPageSize = Preferences::get('listPageSize', 50)->data;
|
||||
$customFiscalYear = Preferences::get('customFiscalYear', 0)->data;
|
||||
$fiscalYearStartStr = Preferences::get('fiscalYearStart', '01-01')->data;
|
||||
$frontPageAccounts = app('preferences')->get('frontPageAccounts', []);
|
||||
$language = app('preferences')->get('language', config('firefly.default_language', 'en_US'))->data;
|
||||
$listPageSize = app('preferences')->get('listPageSize', 50)->data;
|
||||
$customFiscalYear = app('preferences')->get('customFiscalYear', 0)->data;
|
||||
$fiscalYearStartStr = app('preferences')->get('fiscalYearStart', '01-01')->data;
|
||||
$fiscalYearStart = date('Y') . '-' . $fiscalYearStartStr;
|
||||
$tjOptionalFields = Preferences::get('transaction_journal_optional_fields', [])->data;
|
||||
$tjOptionalFields = app('preferences')->get('transaction_journal_optional_fields', [])->data;
|
||||
|
||||
return view(
|
||||
'preferences.index',
|
||||
@ -96,11 +95,11 @@ class PreferencesController extends Controller
|
||||
foreach ($request->get('frontPageAccounts') as $id) {
|
||||
$frontPageAccounts[] = (int)$id;
|
||||
}
|
||||
Preferences::set('frontPageAccounts', $frontPageAccounts);
|
||||
app('preferences')->set('frontPageAccounts', $frontPageAccounts);
|
||||
}
|
||||
|
||||
// view range:
|
||||
Preferences::set('viewRange', $request->get('viewRange'));
|
||||
app('preferences')->set('viewRange', $request->get('viewRange'));
|
||||
// forget session values:
|
||||
session()->forget('start');
|
||||
session()->forget('end');
|
||||
@ -109,20 +108,20 @@ class PreferencesController extends Controller
|
||||
// custom fiscal year
|
||||
$customFiscalYear = 1 === (int)$request->get('customFiscalYear');
|
||||
$fiscalYearStart = date('m-d', strtotime((string)$request->get('fiscalYearStart')));
|
||||
Preferences::set('customFiscalYear', $customFiscalYear);
|
||||
Preferences::set('fiscalYearStart', $fiscalYearStart);
|
||||
app('preferences')->set('customFiscalYear', $customFiscalYear);
|
||||
app('preferences')->set('fiscalYearStart', $fiscalYearStart);
|
||||
|
||||
// save page size:
|
||||
Preferences::set('listPageSize', 50);
|
||||
app('preferences')->set('listPageSize', 50);
|
||||
$listPageSize = (int)$request->get('listPageSize');
|
||||
if ($listPageSize > 0 && $listPageSize < 1337) {
|
||||
Preferences::set('listPageSize', $listPageSize);
|
||||
app('preferences')->set('listPageSize', $listPageSize);
|
||||
}
|
||||
|
||||
// language:
|
||||
$lang = $request->get('language');
|
||||
if (array_key_exists($lang, config('firefly.languages'))) {
|
||||
Preferences::set('language', $lang);
|
||||
app('preferences')->set('language', $lang);
|
||||
}
|
||||
|
||||
// optional fields for transactions:
|
||||
@ -138,7 +137,7 @@ class PreferencesController extends Controller
|
||||
'notes' => isset($setOptions['notes']),
|
||||
'attachments' => isset($setOptions['attachments']),
|
||||
];
|
||||
Preferences::set('transaction_journal_optional_fields', $optionalTj);
|
||||
app('preferences')->set('transaction_journal_optional_fields', $optionalTj);
|
||||
|
||||
session()->flash('success', (string)trans('firefly.saved_preferences'));
|
||||
app('preferences')->mark();
|
||||
|
@ -44,7 +44,6 @@ use Laravel\Passport\ClientRepository;
|
||||
use Laravel\Passport\Passport;
|
||||
use Log;
|
||||
use phpseclib\Crypt\RSA;
|
||||
use Preferences;
|
||||
|
||||
/**
|
||||
* Class ProfileController.
|
||||
@ -125,7 +124,7 @@ class ProfileController extends Controller
|
||||
{
|
||||
// find preference with this token value.
|
||||
/** @var Collection $set */
|
||||
$set = Preferences::findByName('email_change_confirm_token');
|
||||
$set = app('preferences')->findByName('email_change_confirm_token');
|
||||
$user = null;
|
||||
Log::debug(sprintf('Found %d preferences', $set->count()));
|
||||
/** @var Preference $preference */
|
||||
@ -166,8 +165,8 @@ class ProfileController extends Controller
|
||||
*/
|
||||
public function deleteCode()
|
||||
{
|
||||
Preferences::delete('twoFactorAuthEnabled');
|
||||
Preferences::delete('twoFactorAuthSecret');
|
||||
app('preferences')->delete('twoFactorAuthEnabled');
|
||||
app('preferences')->delete('twoFactorAuthSecret');
|
||||
session()->flash('success', (string)trans('firefly.pref_two_factor_auth_disabled'));
|
||||
session()->flash('info', (string)trans('firefly.pref_two_factor_auth_remove_it'));
|
||||
|
||||
@ -186,7 +185,7 @@ class ProfileController extends Controller
|
||||
if ($repository->hasRole($user, 'demo')) {
|
||||
return redirect(route('profile.index'));
|
||||
}
|
||||
$hasTwoFactorAuthSecret = (null !== Preferences::get('twoFactorAuthSecret'));
|
||||
$hasTwoFactorAuthSecret = (null !== app('preferences')->get('twoFactorAuthSecret'));
|
||||
|
||||
// if we don't have a valid secret yet, redirect to the code page to get one.
|
||||
if (!$hasTwoFactorAuthSecret) {
|
||||
@ -196,7 +195,7 @@ class ProfileController extends Controller
|
||||
// If FF3 already has a secret, just set the two factor auth enabled to 1,
|
||||
// and let the user continue with the existing secret.
|
||||
|
||||
Preferences::set('twoFactorAuthEnabled', 1);
|
||||
app('preferences')->set('twoFactorAuthEnabled', 1);
|
||||
|
||||
return redirect(route('profile.index'));
|
||||
}
|
||||
@ -220,15 +219,15 @@ class ProfileController extends Controller
|
||||
}
|
||||
$subTitle = auth()->user()->email;
|
||||
$userId = auth()->user()->id;
|
||||
$enabled2FA = 1 === (int)Preferences::get('twoFactorAuthEnabled', 0)->data;
|
||||
$enabled2FA = 1 === (int)app('preferences')->get('twoFactorAuthEnabled', 0)->data;
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
// get access token or create one.
|
||||
$accessToken = Preferences::get('access_token', null);
|
||||
$accessToken = app('preferences')->get('access_token', null);
|
||||
if (null === $accessToken) {
|
||||
$token = $user->generateAccessToken();
|
||||
$accessToken = Preferences::set('access_token', $token);
|
||||
$accessToken = app('preferences')->set('access_token', $token);
|
||||
}
|
||||
|
||||
return view('profile.index', compact('subTitle', 'userId', 'accessToken', 'enabled2FA'));
|
||||
@ -312,8 +311,8 @@ class ProfileController extends Controller
|
||||
*/
|
||||
public function postCode(TokenFormRequest $request)
|
||||
{
|
||||
Preferences::set('twoFactorAuthEnabled', 1);
|
||||
Preferences::set('twoFactorAuthSecret', session()->get('two-factor-secret'));
|
||||
app('preferences')->set('twoFactorAuthEnabled', 1);
|
||||
app('preferences')->set('twoFactorAuthSecret', session()->get('two-factor-secret'));
|
||||
|
||||
session()->flash('success', (string)trans('firefly.saved_preferences'));
|
||||
app('preferences')->mark();
|
||||
@ -353,7 +352,7 @@ class ProfileController extends Controller
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
$token = $user->generateAccessToken();
|
||||
Preferences::set('access_token', $token);
|
||||
app('preferences')->set('access_token', $token);
|
||||
session()->flash('success', (string)trans('firefly.token_regenerated'));
|
||||
|
||||
return redirect(route('profile.index'));
|
||||
@ -371,7 +370,7 @@ class ProfileController extends Controller
|
||||
public function undoEmailChange(UserRepositoryInterface $repository, string $token, string $hash)
|
||||
{
|
||||
// find preference with this token value.
|
||||
$set = Preferences::findByName('email_change_undo_token');
|
||||
$set = app('preferences')->findByName('email_change_undo_token');
|
||||
$user = null;
|
||||
/** @var Preference $preference */
|
||||
foreach ($set as $preference) {
|
||||
@ -385,7 +384,7 @@ class ProfileController extends Controller
|
||||
|
||||
// found user.
|
||||
// which email address to return to?
|
||||
$set = Preferences::beginsWith($user, 'previous_email_');
|
||||
$set = app('preferences')->beginsWith($user, 'previous_email_');
|
||||
/** @var string $match */
|
||||
$match = null;
|
||||
foreach ($set as $entry) {
|
||||
|
@ -37,8 +37,6 @@ use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Preferences;
|
||||
use View;
|
||||
|
||||
/**
|
||||
* Class ReportController.
|
||||
@ -62,7 +60,7 @@ class ReportController extends Controller
|
||||
function ($request, $next) {
|
||||
app('view')->share('title', trans('firefly.reports'));
|
||||
app('view')->share('mainTitleIcon', 'fa-line-chart');
|
||||
View::share('subTitleIcon', 'fa-calendar');
|
||||
app('view')->share('subTitleIcon', 'fa-calendar');
|
||||
$this->helper = app(ReportHelperInterface::class);
|
||||
$this->repository = app(BudgetRepositoryInterface::class);
|
||||
|
||||
@ -91,7 +89,7 @@ class ReportController extends Controller
|
||||
}
|
||||
$this->repository->cleanupBudgets();
|
||||
|
||||
View::share(
|
||||
app('view')->share(
|
||||
'subTitle', trans(
|
||||
'firefly.report_account',
|
||||
['start' => $start->formatLocalized($this->monthFormat), 'end' => $end->formatLocalized($this->monthFormat)]
|
||||
@ -124,7 +122,7 @@ class ReportController extends Controller
|
||||
}
|
||||
$this->repository->cleanupBudgets();
|
||||
|
||||
View::share(
|
||||
app('view')->share(
|
||||
'subTitle',
|
||||
trans(
|
||||
'firefly.report_audit',
|
||||
@ -161,7 +159,7 @@ class ReportController extends Controller
|
||||
}
|
||||
$this->repository->cleanupBudgets();
|
||||
|
||||
View::share(
|
||||
app('view')->share(
|
||||
'subTitle',
|
||||
trans(
|
||||
'firefly.report_budget',
|
||||
@ -199,7 +197,7 @@ class ReportController extends Controller
|
||||
}
|
||||
$this->repository->cleanupBudgets();
|
||||
|
||||
View::share(
|
||||
app('view')->share(
|
||||
'subTitle',
|
||||
trans(
|
||||
'firefly.report_category',
|
||||
@ -237,7 +235,7 @@ class ReportController extends Controller
|
||||
}
|
||||
$this->repository->cleanupBudgets();
|
||||
|
||||
View::share(
|
||||
app('view')->share(
|
||||
'subTitle',
|
||||
trans(
|
||||
'firefly.report_default',
|
||||
@ -264,7 +262,7 @@ class ReportController extends Controller
|
||||
/** @var Carbon $start */
|
||||
$start = clone session('first');
|
||||
$months = $this->helper->listOfMonths($start);
|
||||
$customFiscalYear = Preferences::get('customFiscalYear', 0)->data;
|
||||
$customFiscalYear = app('preferences')->get('customFiscalYear', 0)->data;
|
||||
$accounts = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
|
||||
$accountList = implode(',', $accounts->pluck('id')->toArray());
|
||||
$this->repository->cleanupBudgets();
|
||||
@ -395,7 +393,7 @@ class ReportController extends Controller
|
||||
}
|
||||
$this->repository->cleanupBudgets();
|
||||
|
||||
View::share(
|
||||
app('view')->share(
|
||||
'subTitle',
|
||||
trans(
|
||||
'firefly.report_tag',
|
||||
|
@ -33,7 +33,6 @@ use FireflyIII\Support\CacheProperties;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Collection;
|
||||
use View;
|
||||
|
||||
/**
|
||||
* Class TagController.
|
||||
@ -49,7 +48,7 @@ class TagController extends Controller
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
View::share('hideTags', true);
|
||||
app('view')->share('hideTags', true);
|
||||
$this->redirectUri = route('tags.index');
|
||||
|
||||
$this->middleware(
|
||||
|
@ -38,7 +38,6 @@ use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Log;
|
||||
use Preferences;
|
||||
use View;
|
||||
|
||||
/**
|
||||
@ -63,7 +62,7 @@ class SingleController extends Controller
|
||||
$maxFileSize = app('steam')->phpBytes(ini_get('upload_max_filesize'));
|
||||
$maxPostSize = app('steam')->phpBytes(ini_get('post_max_size'));
|
||||
$uploadSize = min($maxFileSize, $maxPostSize);
|
||||
View::share('uploadSize', $uploadSize);
|
||||
app('view')->share('uploadSize', $uploadSize);
|
||||
|
||||
// some useful repositories:
|
||||
$this->middleware(
|
||||
@ -148,7 +147,7 @@ class SingleController extends Controller
|
||||
$preFilled = session()->has('preFilled') ? session('preFilled') : [];
|
||||
$subTitle = trans('form.add_new_' . $what);
|
||||
$subTitleIcon = 'fa-plus';
|
||||
$optionalFields = Preferences::get('transaction_journal_optional_fields', [])->data;
|
||||
$optionalFields = app('preferences')->get('transaction_journal_optional_fields', [])->data;
|
||||
$source = (int)$request->get('source');
|
||||
|
||||
// grab old currency ID from old data:
|
||||
@ -259,7 +258,7 @@ class SingleController extends Controller
|
||||
// journal related code
|
||||
$sourceAccounts = $repository->getJournalSourceAccounts($journal);
|
||||
$destinationAccounts = $repository->getJournalDestinationAccounts($journal);
|
||||
$optionalFields = Preferences::get('transaction_journal_optional_fields', [])->data;
|
||||
$optionalFields = app('preferences')->get('transaction_journal_optional_fields', [])->data;
|
||||
$pTransaction = $repository->getFirstPosTransaction($journal);
|
||||
$foreignCurrency = $pTransaction->foreignCurrency ?? $pTransaction->transactionCurrency;
|
||||
$preFilled = [
|
||||
|
@ -38,7 +38,6 @@ use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Transformers\TransactionTransformer;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Collection;
|
||||
use Preferences;
|
||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
use View;
|
||||
|
||||
@ -102,7 +101,7 @@ class SplitController extends Controller
|
||||
$budgets = ExpandedForm::makeSelectListWithEmpty($this->budgets->getActiveBudgets());
|
||||
|
||||
// other fields
|
||||
$optionalFields = Preferences::get('transaction_journal_optional_fields', [])->data;
|
||||
$optionalFields = app('preferences')->get('transaction_journal_optional_fields', [])->data;
|
||||
$preFilled = $this->arrayFromJournal($request, $journal);
|
||||
|
||||
// put previous url in session if not redirect from store (not "return_to_edit").
|
||||
|
@ -40,7 +40,6 @@ use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Preferences;
|
||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
use View;
|
||||
|
||||
@ -85,7 +84,7 @@ class TransactionController extends Controller
|
||||
$subTitleIcon = config('firefly.transactionIconsByWhat.' . $what);
|
||||
$types = config('firefly.transactionTypesByWhat.' . $what);
|
||||
$page = (int)$request->get('page');
|
||||
$pageSize = (int)Preferences::get('listPageSize', 50)->data;
|
||||
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
|
||||
if (null === $start) {
|
||||
$start = session('start');
|
||||
$end = session('end');
|
||||
@ -130,7 +129,7 @@ class TransactionController extends Controller
|
||||
$subTitleIcon = config('firefly.transactionIconsByWhat.' . $what);
|
||||
$types = config('firefly.transactionTypesByWhat.' . $what);
|
||||
$page = (int)$request->get('page');
|
||||
$pageSize = (int)Preferences::get('listPageSize', 50)->data;
|
||||
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
|
||||
$path = route('transactions.index.all', [$what]);
|
||||
$first = $this->repository->firstNull();
|
||||
$start = null === $first ? new Carbon : $first->date;
|
||||
@ -245,7 +244,7 @@ class TransactionController extends Controller
|
||||
*/
|
||||
private function getPeriodOverview(string $what, Carbon $date): Collection
|
||||
{
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
$range = app('preferences')->get('viewRange', '1M')->data;
|
||||
$first = $this->repository->firstNull();
|
||||
$start = new Carbon;
|
||||
$start->subYear();
|
||||
|
@ -27,9 +27,7 @@ use Carbon\Carbon;
|
||||
use Closure;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use Illuminate\Http\Request;
|
||||
use Preferences;
|
||||
use Session;
|
||||
use View;
|
||||
|
||||
/**
|
||||
* Class SessionFilter.
|
||||
@ -68,8 +66,8 @@ class Range
|
||||
*/
|
||||
private function configureList(): void
|
||||
{
|
||||
$pref = Preferences::get('list-length', config('firefly.list_length', 10))->data;
|
||||
View::share('listLength', $pref);
|
||||
$pref = app('preferences')->get('list-length', config('firefly.list_length', 10))->data;
|
||||
app('view')->share('listLength', $pref);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -77,7 +75,7 @@ class Range
|
||||
*/
|
||||
private function configureView(): void
|
||||
{
|
||||
$pref = Preferences::get('language', config('firefly.default_language', 'en_US'));
|
||||
$pref = app('preferences')->get('language', config('firefly.default_language', 'en_US'));
|
||||
/** @noinspection NullPointerExceptionInspection */
|
||||
$lang = $pref->data;
|
||||
App::setLocale($lang);
|
||||
@ -90,7 +88,7 @@ class Range
|
||||
|
||||
// send error to view if could not set money format
|
||||
if (false === $moneyResult) {
|
||||
View::share('invalidMonetaryLocale', true); // @codeCoverageIgnore
|
||||
app('view')->share('invalidMonetaryLocale', true); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
// save some formats:
|
||||
@ -98,9 +96,9 @@ class Range
|
||||
$dateTimeFormat = (string)trans('config.date_time');
|
||||
$defaultCurrency = app('amount')->getDefaultCurrency();
|
||||
|
||||
View::share('monthAndDayFormat', $monthAndDayFormat);
|
||||
View::share('dateTimeFormat', $dateTimeFormat);
|
||||
View::share('defaultCurrency', $defaultCurrency);
|
||||
app('view')->share('monthAndDayFormat', $monthAndDayFormat);
|
||||
app('view')->share('dateTimeFormat', $dateTimeFormat);
|
||||
app('view')->share('defaultCurrency', $defaultCurrency);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -122,10 +120,10 @@ class Range
|
||||
{
|
||||
// ignore preference. set the range to be the current month:
|
||||
if (!Session::has('start') && !Session::has('end')) {
|
||||
$viewRange = Preferences::get('viewRange', '1M')->data;
|
||||
$viewRange = app('preferences')->get('viewRange', '1M')->data;
|
||||
if (null === $viewRange) {
|
||||
$viewRange = '1M';
|
||||
Preferences::set('viewRange', '1M');
|
||||
app('preferences')->set('viewRange', '1M');
|
||||
}
|
||||
$start = new Carbon;
|
||||
$start = app('navigation')->updateStartDate($viewRange, $start);
|
||||
|
@ -24,7 +24,6 @@ namespace FireflyIII\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Preferences;
|
||||
|
||||
/**
|
||||
* Class RedirectIfTwoFactorAuthenticated.
|
||||
@ -43,9 +42,9 @@ class RedirectIfTwoFactorAuthenticated
|
||||
public function handle($request, Closure $next, $guard = null)
|
||||
{
|
||||
if (Auth::guard($guard)->check()) {
|
||||
$is2faEnabled = Preferences::get('twoFactorAuthEnabled', false)->data;
|
||||
$is2faEnabled = app('preferences')->get('twoFactorAuthEnabled', false)->data;
|
||||
|
||||
$has2faSecret = null !== Preferences::get('twoFactorAuthSecret');
|
||||
$has2faSecret = null !== app('preferences')->get('twoFactorAuthSecret');
|
||||
|
||||
// grab 2auth information from cookie.
|
||||
$is2faAuthed = 'true' === $request->cookie('twoFactorAuthenticated');
|
||||
|
@ -30,7 +30,6 @@ use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Log;
|
||||
use View;
|
||||
|
||||
/**
|
||||
* Class Sandstorm.
|
||||
@ -53,7 +52,7 @@ class Sandstorm
|
||||
{
|
||||
// is in Sandstorm environment?
|
||||
$sandstorm = 1 === (int)getenv('SANDSTORM');
|
||||
View::share('SANDSTORM', $sandstorm);
|
||||
app('view')->share('SANDSTORM', $sandstorm);
|
||||
if (!$sandstorm) {
|
||||
return $next($request);
|
||||
}
|
||||
@ -76,7 +75,7 @@ class Sandstorm
|
||||
$user = $repository->first();
|
||||
/** @noinspection NullPointerExceptionInspection */
|
||||
Auth::guard($guard)->login($user);
|
||||
View::share('SANDSTORM_ANON', false);
|
||||
app('view')->share('SANDSTORM_ANON', false);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
@ -86,7 +85,7 @@ class Sandstorm
|
||||
$user = User::first();
|
||||
/** @noinspection NullPointerExceptionInspection */
|
||||
Auth::guard($guard)->login($user);
|
||||
View::share('SANDSTORM_ANON', true);
|
||||
app('view')->share('SANDSTORM_ANON', true);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
@ -108,7 +107,7 @@ class Sandstorm
|
||||
$repository->attachRole($user, 'owner');
|
||||
|
||||
// share value.
|
||||
View::share('SANDSTORM_ANON', false);
|
||||
app('view')->share('SANDSTORM_ANON', false);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
@ -124,11 +123,11 @@ class Sandstorm
|
||||
// if in Sandstorm, user logged in, still must check if user is anon.
|
||||
$userId = (string)$request->header('X-Sandstorm-User-Id');
|
||||
if ('' === $userId) {
|
||||
View::share('SANDSTORM_ANON', true);
|
||||
app('view')->share('SANDSTORM_ANON', true);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
View::share('SANDSTORM_ANON', false);
|
||||
app('view')->share('SANDSTORM_ANON', false);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
@ -60,31 +60,29 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
*/
|
||||
public function budgetedPerDay(Budget $budget): string
|
||||
{
|
||||
Log::debug(sprintf('Now with budget #%d "%s"', $budget->id, $budget->name));
|
||||
$total = '0';
|
||||
$count = 0;
|
||||
foreach ($budget->budgetlimits as $limit) {
|
||||
$diff = (string)$limit->start_date->diffInDays($limit->end_date);
|
||||
if (bccomp('0', $diff) === 0) {
|
||||
$diff = '1';
|
||||
}
|
||||
$diff = $limit->start_date->diffInDays($limit->end_date);
|
||||
$diff = 0 === $diff ? 1 : $diff;
|
||||
$amount = (string)$limit->amount;
|
||||
$perDay = bcdiv($amount, $diff);
|
||||
$perDay = bcdiv($amount, (string)$diff);
|
||||
$total = bcadd($total, $perDay);
|
||||
$count++;
|
||||
Log::debug(sprintf('Found %d budget limits. Per day is %s, total is %s', $count, $perDay, $total));
|
||||
}
|
||||
$avg = $total;
|
||||
if ($count > 0) {
|
||||
$avg = bcdiv($total, (string)$count);
|
||||
}
|
||||
Log::debug(sprintf('%s / %d = %s = average.', $total, $count, $avg));
|
||||
|
||||
return $avg;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*
|
||||
|
||||
|
||||
*/
|
||||
public function cleanupBudgets(): bool
|
||||
{
|
||||
@ -852,10 +850,9 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
* @param Carbon $end
|
||||
* @param string $amount
|
||||
*
|
||||
* @return BudgetLimit
|
||||
* @throws \Exception
|
||||
* @return BudgetLimit|null
|
||||
*/
|
||||
public function updateLimitAmount(Budget $budget, Carbon $start, Carbon $end, string $amount): BudgetLimit
|
||||
public function updateLimitAmount(Budget $budget, Carbon $start, Carbon $end, string $amount): ?BudgetLimit
|
||||
{
|
||||
$this->cleanupBudgets();
|
||||
// count the limits:
|
||||
@ -885,9 +882,14 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
// 1 if the left_operand is larger than the right_operand, -1 otherwise.
|
||||
if (null !== $limit && bccomp($amount, '0') <= 0) {
|
||||
Log::debug(sprintf('%s is zero, delete budget limit #%d', $amount, $limit->id));
|
||||
$limit->delete();
|
||||
try {
|
||||
$limit->delete();
|
||||
} catch (Exception $e) {
|
||||
Log::debug(sprintf('Could not delete limit: %s', $e->getMessage()));
|
||||
}
|
||||
|
||||
return new BudgetLimit;
|
||||
|
||||
return null;
|
||||
}
|
||||
// update if exists:
|
||||
if (null !== $limit) {
|
||||
|
@ -292,7 +292,7 @@ interface BudgetRepositoryInterface
|
||||
* @param Carbon $end
|
||||
* @param string $amount
|
||||
*
|
||||
* @return BudgetLimit
|
||||
* @return BudgetLimit|null
|
||||
*/
|
||||
public function updateLimitAmount(Budget $budget, Carbon $start, Carbon $end, string $amount): BudgetLimit;
|
||||
public function updateLimitAmount(Budget $budget, Carbon $start, Carbon $end, string $amount): ?BudgetLimit;
|
||||
}
|
||||
|
93
app/Support/Http/Controllers/DateCalculation.php
Normal file
93
app/Support/Http/Controllers/DateCalculation.php
Normal file
@ -0,0 +1,93 @@
|
||||
<?php
|
||||
/**
|
||||
* DateCalculation.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Support\Http\Controllers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Trait DateCalculation
|
||||
*
|
||||
* @package FireflyIII\Support\Http\Controllers
|
||||
*/
|
||||
trait DateCalculation
|
||||
{
|
||||
/**
|
||||
* Returns the number of days between the two given dates.
|
||||
* - If today is within the two dates, give the number of days between today and the end date.
|
||||
* - If they are the same, return 1.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function getDayDifference(Carbon $start, Carbon $end): int
|
||||
{
|
||||
$dayDifference = 0;
|
||||
|
||||
// if today is between start and end, use the diff in days between end and today (days left)
|
||||
// otherwise, use diff between start and end.
|
||||
$today = new Carbon;
|
||||
Log::debug(sprintf('Start is %s, end is %s, today is %s', $start->format('Y-m-d'), $end->format('Y-m-d'), $today->format('Y-m-d')));
|
||||
if ($today->gte($start) && $today->lte($end)) {
|
||||
$dayDifference = $end->diffInDays($today);
|
||||
}
|
||||
if ($today->lte($start) || $today->gte($end)) {
|
||||
$dayDifference = $start->diffInDays($end);
|
||||
}
|
||||
$dayDifference = 0 === $dayDifference ? 1 : $dayDifference;
|
||||
|
||||
return $dayDifference;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of days that have passed in this period. If it is zero (start of period)
|
||||
* then return 1.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function getDaysPassedInPeriod(Carbon $start, Carbon $end): int
|
||||
{
|
||||
// if today is between start and end, use the diff in days between end and today (days left)
|
||||
// otherwise, use diff between start and end.
|
||||
$today = new Carbon;
|
||||
$daysPassed = 0;
|
||||
Log::debug(sprintf('Start is %s, end is %s, today is %s', $start->format('Y-m-d'), $end->format('Y-m-d'), $today->format('Y-m-d')));
|
||||
if ($today->gte($start) && $today->lte($end)) {
|
||||
$daysPassed = $start->diffInDays($today);
|
||||
}
|
||||
if ($today->lte($start) || $today->gte($end)) {
|
||||
$daysPassed = $start->diffInDays($end);
|
||||
}
|
||||
$daysPassed = 0 === $daysPassed ? 1 : $daysPassed;
|
||||
|
||||
return $daysPassed;
|
||||
|
||||
}
|
||||
|
||||
}
|
4
public/js/ff/budgets/index.js
vendored
4
public/js/ff/budgets/index.js
vendored
@ -131,8 +131,8 @@ function updateBudgetedAmounts(e) {
|
||||
// fill in "left" value:
|
||||
|
||||
|
||||
if (data.left_per_day !== 'none') {
|
||||
leftCell.html(data.left + '(' + data.left_per_day + ')');
|
||||
if (data.left_per_day !== null) {
|
||||
leftCell.html(data.left + ' (' + data.left_per_day + ')');
|
||||
} else {
|
||||
leftCell.html(data.left);
|
||||
}
|
||||
|
@ -188,7 +188,7 @@
|
||||
<td class="hidden-sm hidden-xs spent" data-id="{{ budget.id }}" data-spent="{{ budgetInformation[budget.id]['spent'] }}"
|
||||
data-value="{{ budgetInformation[budget.id]['spent'] }}">
|
||||
{{ budgetInformation[budget.id]['spent']|formatAmount }}
|
||||
({{ (budgetInformation[budget.id]['spent'] / daysInMonth)|formatAmount }})
|
||||
({{ (budgetInformation[budget.id]['spent'] / daysPassed)|formatAmount }})
|
||||
</td>
|
||||
<td class="left" data-id="{{ budget.id }}"
|
||||
data-value="{{ (repAmount + budgetInformation[budget.id]['spent']) }}">
|
||||
|
Loading…
Reference in New Issue
Block a user