mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-22 12:11:19 +00:00
PHPStorm can order methods by alphabet, who knew.
This commit is contained in:
@@ -58,7 +58,7 @@ class CreateController extends Controller
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
app('view')->share('mainTitleIcon', 'fa-credit-card');
|
||||
app('view')->share('title', (string) trans('firefly.accounts'));
|
||||
app('view')->share('title', (string)trans('firefly.accounts'));
|
||||
|
||||
$this->repository = app(AccountRepositoryInterface::class);
|
||||
$this->attachments = app(AttachmentHelperInterface::class);
|
||||
@@ -77,7 +77,7 @@ class CreateController extends Controller
|
||||
{
|
||||
$defaultCurrency = app('amount')->getDefaultCurrency();
|
||||
$subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType));
|
||||
$subTitle = (string) trans(sprintf('firefly.make_new_%s_account', $objectType));
|
||||
$subTitle = (string)trans(sprintf('firefly.make_new_%s_account', $objectType));
|
||||
$roles = $this->getRoles();
|
||||
$liabilityTypes = $this->getLiabilityTypes();
|
||||
$hasOldInput = null !== $request->old('_token');
|
||||
@@ -96,9 +96,9 @@ class CreateController extends Controller
|
||||
|
||||
// interest calculation periods:
|
||||
$interestPeriods = [
|
||||
'daily' => (string) trans('firefly.interest_calc_daily'),
|
||||
'monthly' => (string) trans('firefly.interest_calc_monthly'),
|
||||
'yearly' => (string) trans('firefly.interest_calc_yearly'),
|
||||
'daily' => (string)trans('firefly.interest_calc_daily'),
|
||||
'monthly' => (string)trans('firefly.interest_calc_monthly'),
|
||||
'yearly' => (string)trans('firefly.interest_calc_yearly'),
|
||||
];
|
||||
|
||||
// pre fill some data
|
||||
@@ -106,7 +106,7 @@ class CreateController extends Controller
|
||||
'preFilled',
|
||||
[
|
||||
'currency_id' => $defaultCurrency->id,
|
||||
'include_net_worth' => $hasOldInput ? (bool) $request->old('include_net_worth') : true,
|
||||
'include_net_worth' => $hasOldInput ? (bool)$request->old('include_net_worth') : true,
|
||||
]
|
||||
);
|
||||
// issue #8321
|
||||
@@ -139,7 +139,7 @@ class CreateController extends Controller
|
||||
{
|
||||
$data = $request->getAccountData();
|
||||
$account = $this->repository->store($data);
|
||||
$request->session()->flash('success', (string) trans('firefly.stored_new_account', ['name' => $account->name]));
|
||||
$request->session()->flash('success', (string)trans('firefly.stored_new_account', ['name' => $account->name]));
|
||||
app('preferences')->mark();
|
||||
|
||||
Log::channel('audit')->info('Stored new account.', $data);
|
||||
@@ -162,7 +162,7 @@ class CreateController extends Controller
|
||||
}
|
||||
if (null !== $files && auth()->user()->hasRole('demo')) {
|
||||
Log::channel('audit')->warning(sprintf('The demo user is trying to upload attachments in %s.', __METHOD__));
|
||||
session()->flash('info', (string) trans('firefly.no_att_demo_user'));
|
||||
session()->flash('info', (string)trans('firefly.no_att_demo_user'));
|
||||
}
|
||||
|
||||
if (count($this->attachments->getMessages()->get('attachments')) > 0) {
|
||||
@@ -171,7 +171,7 @@ class CreateController extends Controller
|
||||
|
||||
// redirect to previous URL.
|
||||
$redirect = redirect($this->getPreviousUrl('accounts.create.url'));
|
||||
if (1 === (int) $request->get('create_another')) {
|
||||
if (1 === (int)$request->get('create_another')) {
|
||||
// set value so create routine will not overwrite URL:
|
||||
$request->session()->put('accounts.create.fromStore', true);
|
||||
|
||||
|
@@ -57,7 +57,7 @@ class EditController extends Controller
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
app('view')->share('mainTitleIcon', 'fa-credit-card');
|
||||
app('view')->share('title', (string) trans('firefly.accounts'));
|
||||
app('view')->share('title', (string)trans('firefly.accounts'));
|
||||
|
||||
$this->repository = app(AccountRepositoryInterface::class);
|
||||
$this->attachments = app(AttachmentHelperInterface::class);
|
||||
@@ -81,7 +81,7 @@ class EditController extends Controller
|
||||
}
|
||||
|
||||
$objectType = config('firefly.shortNamesByFullName')[$account->accountType->type];
|
||||
$subTitle = (string) trans(sprintf('firefly.edit_%s_account', $objectType), ['name' => $account->name]);
|
||||
$subTitle = (string)trans(sprintf('firefly.edit_%s_account', $objectType), ['name' => $account->name]);
|
||||
$subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType));
|
||||
$roles = $this->getRoles();
|
||||
$liabilityTypes = $this->getLiabilityTypes();
|
||||
@@ -106,9 +106,9 @@ class EditController extends Controller
|
||||
|
||||
// interest calculation periods:
|
||||
$interestPeriods = [
|
||||
'daily' => (string) trans('firefly.interest_calc_daily'),
|
||||
'monthly' => (string) trans('firefly.interest_calc_monthly'),
|
||||
'yearly' => (string) trans('firefly.interest_calc_yearly'),
|
||||
'daily' => (string)trans('firefly.interest_calc_daily'),
|
||||
'monthly' => (string)trans('firefly.interest_calc_monthly'),
|
||||
'yearly' => (string)trans('firefly.interest_calc_yearly'),
|
||||
];
|
||||
|
||||
// put previous url in session if not redirect from store (not "return_to_edit").
|
||||
@@ -117,7 +117,7 @@ class EditController extends Controller
|
||||
}
|
||||
$request->session()->forget('accounts.edit.fromUpdate');
|
||||
|
||||
$openingBalanceAmount = (string) $repository->getOpeningBalanceAmount($account);
|
||||
$openingBalanceAmount = (string)$repository->getOpeningBalanceAmount($account);
|
||||
if ('0' === $openingBalanceAmount) {
|
||||
$openingBalanceAmount = '';
|
||||
}
|
||||
@@ -143,17 +143,17 @@ class EditController extends Controller
|
||||
'cc_type' => $repository->getMetaValue($account, 'cc_type'),
|
||||
'cc_monthly_payment_date' => $repository->getMetaValue($account, 'cc_monthly_payment_date'),
|
||||
'BIC' => $repository->getMetaValue($account, 'BIC'),
|
||||
'opening_balance_date' => substr((string) $openingBalanceDate, 0, 10),
|
||||
'opening_balance_date' => substr((string)$openingBalanceDate, 0, 10),
|
||||
'liability_type_id' => $account->account_type_id,
|
||||
'opening_balance' => app('steam')->bcround($openingBalanceAmount, $currency->decimal_places),
|
||||
'liability_direction' => $this->repository->getMetaValue($account, 'liability_direction'),
|
||||
'virtual_balance' => app('steam')->bcround($virtualBalance, $currency->decimal_places),
|
||||
'currency_id' => $currency->id,
|
||||
'include_net_worth' => $hasOldInput ? (bool) $request->old('include_net_worth') : $includeNetWorth,
|
||||
'include_net_worth' => $hasOldInput ? (bool)$request->old('include_net_worth') : $includeNetWorth,
|
||||
'interest' => $repository->getMetaValue($account, 'interest'),
|
||||
'interest_period' => $repository->getMetaValue($account, 'interest_period'),
|
||||
'notes' => $this->repository->getNoteText($account),
|
||||
'active' => $hasOldInput ? (bool) $request->old('active') : $account->active,
|
||||
'active' => $hasOldInput ? (bool)$request->old('active') : $account->active,
|
||||
];
|
||||
if ('' === $openingBalanceAmount) {
|
||||
$preFilled['opening_balance'] = '';
|
||||
@@ -178,7 +178,7 @@ class EditController extends Controller
|
||||
$data = $request->getAccountData();
|
||||
$this->repository->update($account, $data);
|
||||
Log::channel('audit')->info(sprintf('Updated account #%d.', $account->id), $data);
|
||||
$request->session()->flash('success', (string) trans('firefly.updated_account', ['name' => $account->name]));
|
||||
$request->session()->flash('success', (string)trans('firefly.updated_account', ['name' => $account->name]));
|
||||
|
||||
// store new attachment(s):
|
||||
/** @var null|array $files */
|
||||
@@ -188,7 +188,7 @@ class EditController extends Controller
|
||||
}
|
||||
if (null !== $files && auth()->user()->hasRole('demo')) {
|
||||
Log::channel('audit')->warning(sprintf('The demo user is trying to upload attachments in %s.', __METHOD__));
|
||||
session()->flash('info', (string) trans('firefly.no_att_demo_user'));
|
||||
session()->flash('info', (string)trans('firefly.no_att_demo_user'));
|
||||
}
|
||||
|
||||
if (count($this->attachments->getMessages()->get('attachments')) > 0) {
|
||||
@@ -197,7 +197,7 @@ class EditController extends Controller
|
||||
|
||||
// redirect
|
||||
$redirect = redirect($this->getPreviousUrl('accounts.edit.url'));
|
||||
if (1 === (int) $request->get('return_to_edit')) {
|
||||
if (1 === (int)$request->get('return_to_edit')) {
|
||||
// set value so edit routine will not overwrite URL:
|
||||
$request->session()->put('accounts.edit.fromUpdate', true);
|
||||
|
||||
|
@@ -95,6 +95,21 @@ class ForgotPasswordController extends Controller
|
||||
return back()->with('status', trans($response));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function validateHost(): void
|
||||
{
|
||||
$configuredHost = parse_url((string)config('app.url'), PHP_URL_HOST);
|
||||
if (false === $configuredHost || null === $configuredHost) {
|
||||
throw new FireflyException('Please set a valid and correct Firefly III URL in the APP_URL environment variable.');
|
||||
}
|
||||
$host = request()->host();
|
||||
if ($configuredHost !== $host) {
|
||||
throw new FireflyException('The Host-header does not match the host in the APP_URL environment variable. Please make sure these match. See also: https://bit.ly/FF3-host-header');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show form for email recovery.
|
||||
*
|
||||
@@ -121,19 +136,4 @@ class ForgotPasswordController extends Controller
|
||||
|
||||
return view('auth.passwords.email')->with(compact('allowRegistration', 'pageTitle'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function validateHost(): void
|
||||
{
|
||||
$configuredHost = parse_url((string)config('app.url'), PHP_URL_HOST);
|
||||
if (false === $configuredHost || null === $configuredHost) {
|
||||
throw new FireflyException('Please set a valid and correct Firefly III URL in the APP_URL environment variable.');
|
||||
}
|
||||
$host = request()->host();
|
||||
if ($configuredHost !== $host) {
|
||||
throw new FireflyException('The Host-header does not match the host in the APP_URL environment variable. Please make sure these match. See also: https://bit.ly/FF3-host-header');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -132,6 +132,25 @@ class LoginController extends Controller
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the failed login response instance.
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*
|
||||
* @throws ValidationException
|
||||
*/
|
||||
protected function sendFailedLoginResponse(Request $request): void
|
||||
{
|
||||
$exception = ValidationException::withMessages(
|
||||
[
|
||||
$this->username() => [trans('auth.failed')],
|
||||
]
|
||||
);
|
||||
$exception->redirectTo = route('login');
|
||||
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log the user out of the application.
|
||||
*
|
||||
@@ -210,23 +229,4 @@ class LoginController extends Controller
|
||||
|
||||
return view('auth.login', compact('allowRegistration', 'email', 'remember', 'allowReset', 'title', 'usernameField'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the failed login response instance.
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*
|
||||
* @throws ValidationException
|
||||
*/
|
||||
protected function sendFailedLoginResponse(Request $request): void
|
||||
{
|
||||
$exception = ValidationException::withMessages(
|
||||
[
|
||||
$this->username() => [trans('auth.failed')],
|
||||
]
|
||||
);
|
||||
$exception->redirectTo = route('login');
|
||||
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
@@ -109,6 +109,31 @@ class RegisterController extends Controller
|
||||
return redirect($this->redirectPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
*/
|
||||
protected function allowedToRegister(): bool
|
||||
{
|
||||
// is allowed to register?
|
||||
$allowRegistration = true;
|
||||
|
||||
try {
|
||||
$singleUserMode = app('fireflyconfig')->get('single_user_mode', config('firefly.configuration.single_user_mode'))->data;
|
||||
} catch (ContainerExceptionInterface|NotFoundExceptionInterface $e) {
|
||||
$singleUserMode = true;
|
||||
}
|
||||
$userCount = User::count();
|
||||
$guard = config('auth.defaults.guard');
|
||||
if (true === $singleUserMode && $userCount > 0 && 'web' === $guard) {
|
||||
$allowRegistration = false;
|
||||
}
|
||||
if ('web' !== $guard) {
|
||||
$allowRegistration = false;
|
||||
}
|
||||
|
||||
return $allowRegistration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the application registration form if the invitation code is valid.
|
||||
*
|
||||
@@ -164,29 +189,4 @@ class RegisterController extends Controller
|
||||
|
||||
return view('auth.register', compact('isDemoSite', 'email', 'pageTitle'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
*/
|
||||
protected function allowedToRegister(): bool
|
||||
{
|
||||
// is allowed to register?
|
||||
$allowRegistration = true;
|
||||
|
||||
try {
|
||||
$singleUserMode = app('fireflyconfig')->get('single_user_mode', config('firefly.configuration.single_user_mode'))->data;
|
||||
} catch (ContainerExceptionInterface|NotFoundExceptionInterface $e) {
|
||||
$singleUserMode = true;
|
||||
}
|
||||
$userCount = User::count();
|
||||
$guard = config('auth.defaults.guard');
|
||||
if (true === $singleUserMode && $userCount > 0 && 'web' === $guard) {
|
||||
$allowRegistration = false;
|
||||
}
|
||||
if ('web' !== $guard) {
|
||||
$allowRegistration = false;
|
||||
}
|
||||
|
||||
return $allowRegistration;
|
||||
}
|
||||
}
|
||||
|
@@ -31,7 +31,6 @@ use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Redirector;
|
||||
use PragmaRX\Google2FALaravel\Support\Authenticator;
|
||||
use Preferences;
|
||||
|
||||
/**
|
||||
* Class TwoFactorController.
|
||||
|
@@ -52,7 +52,7 @@ class EditController extends Controller
|
||||
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
app('view')->share('title', (string) trans('firefly.bills'));
|
||||
app('view')->share('title', (string)trans('firefly.bills'));
|
||||
app('view')->share('mainTitleIcon', 'fa-calendar-o');
|
||||
$this->attachments = app(AttachmentHelperInterface::class);
|
||||
$this->repository = app(BillRepositoryInterface::class);
|
||||
@@ -75,10 +75,10 @@ class EditController extends Controller
|
||||
$billPeriods = config('firefly.bill_periods');
|
||||
|
||||
foreach ($billPeriods as $current) {
|
||||
$periods[$current] = (string) trans('firefly.'.$current);
|
||||
$periods[$current] = (string)trans('firefly.'.$current);
|
||||
}
|
||||
|
||||
$subTitle = (string) trans('firefly.edit_bill', ['name' => $bill->name]);
|
||||
$subTitle = (string)trans('firefly.edit_bill', ['name' => $bill->name]);
|
||||
|
||||
// put previous url in session if not redirect from store (not "return_to_edit").
|
||||
if (true !== session('bills.edit.fromUpdate')) {
|
||||
@@ -99,7 +99,7 @@ class EditController extends Controller
|
||||
'extension_date' => $bill->extension_date,
|
||||
'notes' => $this->repository->getNoteText($bill),
|
||||
'transaction_currency_id' => $bill->transaction_currency_id,
|
||||
'active' => $hasOldInput ? (bool) $request->old('active') : $bill->active,
|
||||
'active' => $hasOldInput ? (bool)$request->old('active') : $bill->active,
|
||||
'object_group' => null !== $bill->objectGroups->first() ? $bill->objectGroups->first()->title : '',
|
||||
];
|
||||
|
||||
@@ -119,7 +119,7 @@ class EditController extends Controller
|
||||
|
||||
Log::channel('audit')->info(sprintf('Updated bill #%d.', $bill->id), $billData);
|
||||
|
||||
$request->session()->flash('success', (string) trans('firefly.updated_bill', ['name' => $bill->name]));
|
||||
$request->session()->flash('success', (string)trans('firefly.updated_bill', ['name' => $bill->name]));
|
||||
app('preferences')->mark();
|
||||
|
||||
/** @var null|array $files */
|
||||
@@ -129,7 +129,7 @@ class EditController extends Controller
|
||||
}
|
||||
if (null !== $files && auth()->user()->hasRole('demo')) {
|
||||
Log::channel('audit')->warning(sprintf('The demo user is trying to upload attachments in %s.', __METHOD__));
|
||||
session()->flash('info', (string) trans('firefly.no_att_demo_user'));
|
||||
session()->flash('info', (string)trans('firefly.no_att_demo_user'));
|
||||
}
|
||||
|
||||
// flash messages
|
||||
@@ -138,7 +138,7 @@ class EditController extends Controller
|
||||
}
|
||||
$redirect = redirect($this->getPreviousUrl('bills.edit.url'));
|
||||
|
||||
if (1 === (int) $request->get('return_to_edit')) {
|
||||
if (1 === (int)$request->get('return_to_edit')) {
|
||||
$request->session()->put('bills.edit.fromUpdate', true);
|
||||
|
||||
$redirect = redirect(route('bills.edit', [$bill->id]))->withInput(['return_to_edit' => 1]);
|
||||
|
@@ -134,24 +134,6 @@ class IndexController extends Controller
|
||||
return view('bills.index', compact('bills', 'sums', 'total', 'totals', 'today'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the order of a bill.
|
||||
*/
|
||||
public function setOrder(Request $request, Bill $bill): JsonResponse
|
||||
{
|
||||
$objectGroupTitle = (string)$request->get('objectGroupTitle');
|
||||
$newOrder = (int)$request->get('order');
|
||||
$this->repository->setOrder($bill, $newOrder);
|
||||
if ('' !== $objectGroupTitle) {
|
||||
$this->repository->setObjectGroup($bill, $objectGroupTitle);
|
||||
}
|
||||
if ('' === $objectGroupTitle) {
|
||||
$this->repository->removeObjectGroup($bill);
|
||||
}
|
||||
|
||||
return response()->json(['data' => 'OK']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
*/
|
||||
@@ -268,4 +250,22 @@ class IndexController extends Controller
|
||||
|
||||
return $totals;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the order of a bill.
|
||||
*/
|
||||
public function setOrder(Request $request, Bill $bill): JsonResponse
|
||||
{
|
||||
$objectGroupTitle = (string)$request->get('objectGroupTitle');
|
||||
$newOrder = (int)$request->get('order');
|
||||
$this->repository->setOrder($bill, $newOrder);
|
||||
if ('' !== $objectGroupTitle) {
|
||||
$this->repository->setObjectGroup($bill, $objectGroupTitle);
|
||||
}
|
||||
if ('' === $objectGroupTitle) {
|
||||
$this->repository->removeObjectGroup($bill);
|
||||
}
|
||||
|
||||
return response()->json(['data' => 'OK']);
|
||||
}
|
||||
}
|
||||
|
@@ -159,24 +159,6 @@ class IndexController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
public function reorder(Request $request, BudgetRepositoryInterface $repository): JsonResponse
|
||||
{
|
||||
$this->abRepository->cleanup();
|
||||
$budgetIds = $request->get('budgetIds');
|
||||
|
||||
foreach ($budgetIds as $index => $budgetId) {
|
||||
$budgetId = (int)$budgetId;
|
||||
$budget = $repository->find($budgetId);
|
||||
if (null !== $budget) {
|
||||
app('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']);
|
||||
}
|
||||
|
||||
private function getAllAvailableBudgets(Carbon $start, Carbon $end): array
|
||||
{
|
||||
// get all available budgets.
|
||||
@@ -296,11 +278,11 @@ class IndexController extends Controller
|
||||
// also calculate how much left from budgeted:
|
||||
$sums['left'][$currencyId]
|
||||
??= [
|
||||
'amount' => '0',
|
||||
'currency_id' => $budgeted['currency_id'],
|
||||
'currency_symbol' => $budgeted['currency_symbol'],
|
||||
'currency_decimal_places' => $budgeted['currency_decimal_places'],
|
||||
];
|
||||
'amount' => '0',
|
||||
'currency_id' => $budgeted['currency_id'],
|
||||
'currency_symbol' => $budgeted['currency_symbol'],
|
||||
'currency_decimal_places' => $budgeted['currency_decimal_places'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -316,4 +298,22 @@ class IndexController extends Controller
|
||||
|
||||
return $sums;
|
||||
}
|
||||
|
||||
public function reorder(Request $request, BudgetRepositoryInterface $repository): JsonResponse
|
||||
{
|
||||
$this->abRepository->cleanup();
|
||||
$budgetIds = $request->get('budgetIds');
|
||||
|
||||
foreach ($budgetIds as $index => $budgetId) {
|
||||
$budgetId = (int)$budgetId;
|
||||
$budget = $repository->find($budgetId);
|
||||
if (null !== $budget) {
|
||||
app('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']);
|
||||
}
|
||||
}
|
||||
|
@@ -409,6 +409,58 @@ class AccountController extends Controller
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function periodByCurrency(Carbon $start, Carbon $end, Account $account, TransactionCurrency $currency): array
|
||||
{
|
||||
app('log')->debug(sprintf('Now in periodByCurrency("%s", "%s", %s, "%s")', $start->format('Y-m-d'), $end->format('Y-m-d'), $account->id, $currency->code));
|
||||
$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 = [];
|
||||
$current = clone $start;
|
||||
app('log')->debug(sprintf('Step is %s', $step));
|
||||
|
||||
// fix for issue https://github.com/firefly-iii/firefly-iii/issues/8041
|
||||
// have to make sure this chart is always based on the balance at the END of the period.
|
||||
// This period depends on the size of the chart
|
||||
$current = app('navigation')->endOfX($current, $step, null);
|
||||
app('log')->debug(sprintf('$current date is %s', $current->format('Y-m-d')));
|
||||
if ('1D' === $step) {
|
||||
// per day the entire period, balance for every day.
|
||||
$format = (string)trans('config.month_and_day_js', [], $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->isoFormat($format);
|
||||
$entries[$label] = (float)$balance;
|
||||
$previous = $balance;
|
||||
$current->addDay();
|
||||
}
|
||||
}
|
||||
if ('1W' === $step || '1M' === $step || '1Y' === $step) {
|
||||
while ($end >= $current) {
|
||||
app('log')->debug(sprintf('Current is: %s', $current->format('Y-m-d')));
|
||||
$balance = (float)app('steam')->balance($account, $current, $currency);
|
||||
$label = app('navigation')->periodShow($current, $step);
|
||||
$entries[$label] = $balance;
|
||||
$current = app('navigation')->addPeriod($current, $step, 0);
|
||||
// here too, to fix #8041, the data is corrected to the end of the period.
|
||||
$current = app('navigation')->endOfX($current, $step, null);
|
||||
}
|
||||
}
|
||||
$result['entries'] = $entries;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the balances for a given set of dates and accounts.
|
||||
*
|
||||
@@ -512,56 +564,4 @@ class AccountController extends Controller
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function periodByCurrency(Carbon $start, Carbon $end, Account $account, TransactionCurrency $currency): array
|
||||
{
|
||||
app('log')->debug(sprintf('Now in periodByCurrency("%s", "%s", %s, "%s")', $start->format('Y-m-d'), $end->format('Y-m-d'), $account->id, $currency->code));
|
||||
$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 = [];
|
||||
$current = clone $start;
|
||||
app('log')->debug(sprintf('Step is %s', $step));
|
||||
|
||||
// fix for issue https://github.com/firefly-iii/firefly-iii/issues/8041
|
||||
// have to make sure this chart is always based on the balance at the END of the period.
|
||||
// This period depends on the size of the chart
|
||||
$current = app('navigation')->endOfX($current, $step, null);
|
||||
app('log')->debug(sprintf('$current date is %s', $current->format('Y-m-d')));
|
||||
if ('1D' === $step) {
|
||||
// per day the entire period, balance for every day.
|
||||
$format = (string)trans('config.month_and_day_js', [], $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->isoFormat($format);
|
||||
$entries[$label] = (float)$balance;
|
||||
$previous = $balance;
|
||||
$current->addDay();
|
||||
}
|
||||
}
|
||||
if ('1W' === $step || '1M' === $step || '1Y' === $step) {
|
||||
while ($end >= $current) {
|
||||
app('log')->debug(sprintf('Current is: %s', $current->format('Y-m-d')));
|
||||
$balance = (float)app('steam')->balance($account, $current, $currency);
|
||||
$label = app('navigation')->periodShow($current, $step);
|
||||
$entries[$label] = $balance;
|
||||
$current = app('navigation')->addPeriod($current, $step, 0);
|
||||
// here too, to fix #8041, the data is corrected to the end of the period.
|
||||
$current = app('navigation')->endOfX($current, $step, null);
|
||||
}
|
||||
}
|
||||
$result['entries'] = $entries;
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
@@ -195,6 +195,23 @@ class BudgetReportController extends Controller
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
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->isoFormat($format);
|
||||
$return[$key] = '0';
|
||||
$currentStart = clone $currentEnd;
|
||||
$currentStart->addDay()->startOfDay();
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Chart that groups expenses by the account.
|
||||
*/
|
||||
@@ -224,21 +241,4 @@ class BudgetReportController extends Controller
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
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->isoFormat($format);
|
||||
$return[$key] = '0';
|
||||
$currentStart = clone $currentEnd;
|
||||
$currentStart->addDay()->startOfDay();
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
@@ -94,6 +94,11 @@ class CategoryController extends Controller
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
private function getDate(): Carbon
|
||||
{
|
||||
return today(config('app.timezone'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the category chart on the front page.
|
||||
* TODO test method for category refactor.
|
||||
@@ -141,6 +146,85 @@ class CategoryController extends Controller
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate report chart for either with or without category.
|
||||
*/
|
||||
private function reportPeriodChart(Collection $accounts, Carbon $start, Carbon $end, ?Category $category): array
|
||||
{
|
||||
$income = [];
|
||||
$expenses = [];
|
||||
$categoryId = 0;
|
||||
if (null === $category) {
|
||||
/** @var NoCategoryRepositoryInterface $noCatRepository */
|
||||
$noCatRepository = app(NoCategoryRepositoryInterface::class);
|
||||
|
||||
// this gives us all currencies
|
||||
$expenses = $noCatRepository->listExpenses($start, $end, $accounts);
|
||||
$income = $noCatRepository->listIncome($start, $end, $accounts);
|
||||
}
|
||||
|
||||
if (null !== $category) {
|
||||
/** @var OperationsRepositoryInterface $opsRepository */
|
||||
$opsRepository = app(OperationsRepositoryInterface::class);
|
||||
$categoryId = $category->id;
|
||||
// this gives us all currencies
|
||||
$collection = new Collection([$category]);
|
||||
$expenses = $opsRepository->listExpenses($start, $end, null, $collection);
|
||||
$income = $opsRepository->listIncome($start, $end, null, $collection);
|
||||
}
|
||||
$currencies = array_unique(array_merge(array_keys($income), array_keys($expenses)));
|
||||
$periods = app('navigation')->listOfPeriods($start, $end);
|
||||
$format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
|
||||
$chartData = [];
|
||||
// make empty data array:
|
||||
// double foreach (bad) to make empty array:
|
||||
foreach ($currencies as $currencyId) {
|
||||
$currencyInfo = $expenses[$currencyId] ?? $income[$currencyId];
|
||||
$outKey = sprintf('%d-out', $currencyId);
|
||||
$inKey = sprintf('%d-in', $currencyId);
|
||||
$chartData[$outKey]
|
||||
= [
|
||||
'label' => sprintf('%s (%s)', (string)trans('firefly.spent'), $currencyInfo['currency_name']),
|
||||
'entries' => [],
|
||||
'type' => 'bar',
|
||||
'backgroundColor' => 'rgba(219, 68, 55, 0.5)', // red
|
||||
];
|
||||
|
||||
$chartData[$inKey]
|
||||
= [
|
||||
'label' => sprintf('%s (%s)', (string)trans('firefly.earned'), $currencyInfo['currency_name']),
|
||||
'entries' => [],
|
||||
'type' => 'bar',
|
||||
'backgroundColor' => 'rgba(0, 141, 76, 0.5)', // green
|
||||
];
|
||||
// loop empty periods:
|
||||
foreach (array_keys($periods) as $period) {
|
||||
$label = $periods[$period];
|
||||
$chartData[$outKey]['entries'][$label] = '0';
|
||||
$chartData[$inKey]['entries'][$label] = '0';
|
||||
}
|
||||
// loop income and expenses for this category.:
|
||||
$outSet = $expenses[$currencyId]['categories'][$categoryId] ?? ['transaction_journals' => []];
|
||||
foreach ($outSet['transaction_journals'] as $journal) {
|
||||
$amount = app('steam')->positive($journal['amount']);
|
||||
$date = $journal['date']->isoFormat($format);
|
||||
$chartData[$outKey]['entries'][$date] ??= '0';
|
||||
|
||||
$chartData[$outKey]['entries'][$date] = bcadd($amount, $chartData[$outKey]['entries'][$date]);
|
||||
}
|
||||
|
||||
$inSet = $income[$currencyId]['categories'][$categoryId] ?? ['transaction_journals' => []];
|
||||
foreach ($inSet['transaction_journals'] as $journal) {
|
||||
$amount = app('steam')->positive($journal['amount']);
|
||||
$date = $journal['date']->isoFormat($format);
|
||||
$chartData[$inKey]['entries'][$date] ??= '0';
|
||||
$chartData[$inKey]['entries'][$date] = bcadd($amount, $chartData[$inKey]['entries'][$date]);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->generator->multiSet($chartData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Chart for period for transactions without a category.
|
||||
* TODO test me.
|
||||
@@ -195,88 +279,4 @@ class CategoryController extends Controller
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
private function getDate(): Carbon
|
||||
{
|
||||
return today(config('app.timezone'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate report chart for either with or without category.
|
||||
*/
|
||||
private function reportPeriodChart(Collection $accounts, Carbon $start, Carbon $end, ?Category $category): array
|
||||
{
|
||||
$income = [];
|
||||
$expenses = [];
|
||||
$categoryId = 0;
|
||||
if (null === $category) {
|
||||
/** @var NoCategoryRepositoryInterface $noCatRepository */
|
||||
$noCatRepository = app(NoCategoryRepositoryInterface::class);
|
||||
|
||||
// this gives us all currencies
|
||||
$expenses = $noCatRepository->listExpenses($start, $end, $accounts);
|
||||
$income = $noCatRepository->listIncome($start, $end, $accounts);
|
||||
}
|
||||
|
||||
if (null !== $category) {
|
||||
/** @var OperationsRepositoryInterface $opsRepository */
|
||||
$opsRepository = app(OperationsRepositoryInterface::class);
|
||||
$categoryId = $category->id;
|
||||
// this gives us all currencies
|
||||
$collection = new Collection([$category]);
|
||||
$expenses = $opsRepository->listExpenses($start, $end, null, $collection);
|
||||
$income = $opsRepository->listIncome($start, $end, null, $collection);
|
||||
}
|
||||
$currencies = array_unique(array_merge(array_keys($income), array_keys($expenses)));
|
||||
$periods = app('navigation')->listOfPeriods($start, $end);
|
||||
$format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
|
||||
$chartData = [];
|
||||
// make empty data array:
|
||||
// double foreach (bad) to make empty array:
|
||||
foreach ($currencies as $currencyId) {
|
||||
$currencyInfo = $expenses[$currencyId] ?? $income[$currencyId];
|
||||
$outKey = sprintf('%d-out', $currencyId);
|
||||
$inKey = sprintf('%d-in', $currencyId);
|
||||
$chartData[$outKey]
|
||||
= [
|
||||
'label' => sprintf('%s (%s)', (string)trans('firefly.spent'), $currencyInfo['currency_name']),
|
||||
'entries' => [],
|
||||
'type' => 'bar',
|
||||
'backgroundColor' => 'rgba(219, 68, 55, 0.5)', // red
|
||||
];
|
||||
|
||||
$chartData[$inKey]
|
||||
= [
|
||||
'label' => sprintf('%s (%s)', (string)trans('firefly.earned'), $currencyInfo['currency_name']),
|
||||
'entries' => [],
|
||||
'type' => 'bar',
|
||||
'backgroundColor' => 'rgba(0, 141, 76, 0.5)', // green
|
||||
];
|
||||
// loop empty periods:
|
||||
foreach (array_keys($periods) as $period) {
|
||||
$label = $periods[$period];
|
||||
$chartData[$outKey]['entries'][$label] = '0';
|
||||
$chartData[$inKey]['entries'][$label] = '0';
|
||||
}
|
||||
// loop income and expenses for this category.:
|
||||
$outSet = $expenses[$currencyId]['categories'][$categoryId] ?? ['transaction_journals' => []];
|
||||
foreach ($outSet['transaction_journals'] as $journal) {
|
||||
$amount = app('steam')->positive($journal['amount']);
|
||||
$date = $journal['date']->isoFormat($format);
|
||||
$chartData[$outKey]['entries'][$date] ??= '0';
|
||||
|
||||
$chartData[$outKey]['entries'][$date] = bcadd($amount, $chartData[$outKey]['entries'][$date]);
|
||||
}
|
||||
|
||||
$inSet = $income[$currencyId]['categories'][$categoryId] ?? ['transaction_journals' => []];
|
||||
foreach ($inSet['transaction_journals'] as $journal) {
|
||||
$amount = app('steam')->positive($journal['amount']);
|
||||
$date = $journal['date']->isoFormat($format);
|
||||
$chartData[$inKey]['entries'][$date] ??= '0';
|
||||
$chartData[$inKey]['entries'][$date] = bcadd($amount, $chartData[$inKey]['entries'][$date]);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->generator->multiSet($chartData);
|
||||
}
|
||||
}
|
||||
|
@@ -269,6 +269,26 @@ class CategoryReportController extends Controller
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO duplicate function
|
||||
*/
|
||||
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->isoFormat($format);
|
||||
$return[$key] = '0';
|
||||
$currentStart = clone $currentEnd;
|
||||
$currentStart->addDay()->startOfDay();
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function sourceExpense(Collection $accounts, Collection $categories, Carbon $start, Carbon $end): JsonResponse
|
||||
{
|
||||
$result = [];
|
||||
@@ -324,24 +344,4 @@ class CategoryReportController extends Controller
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO duplicate function
|
||||
*/
|
||||
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->isoFormat($format);
|
||||
$return[$key] = '0';
|
||||
$currentStart = clone $currentEnd;
|
||||
$currentStart->addDay()->startOfDay();
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
@@ -212,6 +212,44 @@ class DoubleReportController extends Controller
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO duplicate function
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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->isoFormat($format);
|
||||
$return[$key] = '0';
|
||||
$currentStart = clone $currentEnd;
|
||||
$currentStart->addDay()->startOfDay();
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function tagExpense(Collection $accounts, Collection $others, Carbon $start, Carbon $end): JsonResponse
|
||||
{
|
||||
$result = [];
|
||||
@@ -317,42 +355,4 @@ class DoubleReportController extends Controller
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO duplicate function
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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->isoFormat($format);
|
||||
$return[$key] = '0';
|
||||
$currentStart = clone $currentEnd;
|
||||
$currentStart->addDay()->startOfDay();
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
@@ -102,27 +102,27 @@ class ExpenseReportController extends Controller
|
||||
/** @var Account $exp */
|
||||
$exp = $combination->first();
|
||||
$chartData[$exp->id.'-in'] = [
|
||||
'label' => sprintf('%s (%s)', $name, (string) trans('firefly.income')),
|
||||
'label' => sprintf('%s (%s)', $name, (string)trans('firefly.income')),
|
||||
'type' => 'bar',
|
||||
'yAxisID' => 'y-axis-0',
|
||||
'entries' => [],
|
||||
];
|
||||
$chartData[$exp->id.'-out'] = [
|
||||
'label' => sprintf('%s (%s)', $name, (string) trans('firefly.expenses')),
|
||||
'label' => sprintf('%s (%s)', $name, (string)trans('firefly.expenses')),
|
||||
'type' => 'bar',
|
||||
'yAxisID' => 'y-axis-0',
|
||||
'entries' => [],
|
||||
];
|
||||
// total in, total out:
|
||||
$chartData[$exp->id.'-total-in'] = [
|
||||
'label' => sprintf('%s (%s)', $name, (string) trans('firefly.sum_of_income')),
|
||||
'label' => sprintf('%s (%s)', $name, (string)trans('firefly.sum_of_income')),
|
||||
'type' => 'line',
|
||||
'fill' => false,
|
||||
'yAxisID' => 'y-axis-1',
|
||||
'entries' => [],
|
||||
];
|
||||
$chartData[$exp->id.'-total-out'] = [
|
||||
'label' => sprintf('%s (%s)', $name, (string) trans('firefly.sum_of_expenses')),
|
||||
'label' => sprintf('%s (%s)', $name, (string)trans('firefly.sum_of_expenses')),
|
||||
'type' => 'line',
|
||||
'fill' => false,
|
||||
'yAxisID' => 'y-axis-1',
|
||||
|
@@ -274,6 +274,26 @@ class TagReportController extends Controller
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO duplicate function
|
||||
*/
|
||||
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->isoFormat($format);
|
||||
$return[$key] = '0';
|
||||
$currentStart = clone $currentEnd;
|
||||
$currentStart->addDay()->startOfDay();
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function sourceExpense(Collection $accounts, Collection $tags, Carbon $start, Carbon $end): JsonResponse
|
||||
{
|
||||
$result = [];
|
||||
@@ -381,24 +401,4 @@ class TagReportController extends Controller
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO duplicate function
|
||||
*/
|
||||
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->isoFormat($format);
|
||||
$return[$key] = '0';
|
||||
$currentStart = clone $currentEnd;
|
||||
$currentStart->addDay()->startOfDay();
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Http\Middleware\IsDemoUser;
|
||||
use FireflyIII\Models\AccountType;
|
||||
@@ -140,21 +141,6 @@ class DebugController extends Controller
|
||||
return view('debug', compact('table', 'now', 'logContent'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Flash all types of messages.
|
||||
*
|
||||
* @return Redirector|RedirectResponse
|
||||
*/
|
||||
public function testFlash(Request $request)
|
||||
{
|
||||
$request->session()->flash('success', 'This is a success message.');
|
||||
$request->session()->flash('info', 'This is an info message.');
|
||||
$request->session()->flash('warning', 'This is a warning.');
|
||||
$request->session()->flash('error', 'This is an error!');
|
||||
|
||||
return redirect(route('home'));
|
||||
}
|
||||
|
||||
private function generateTable(): string
|
||||
{
|
||||
// system information:
|
||||
@@ -336,4 +322,19 @@ class DebugController extends Controller
|
||||
|
||||
return implode(' ', $flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flash all types of messages.
|
||||
*
|
||||
* @return Redirector|RedirectResponse
|
||||
*/
|
||||
public function testFlash(Request $request)
|
||||
{
|
||||
$request->session()->flash('success', 'This is a success message.');
|
||||
$request->session()->flash('info', 'This is an info message.');
|
||||
$request->session()->flash('warning', 'This is a warning.');
|
||||
$request->session()->flash('error', 'This is an error!');
|
||||
|
||||
return redirect(route('home'));
|
||||
}
|
||||
}
|
||||
|
@@ -67,7 +67,7 @@ class IndexController extends Controller
|
||||
public function export(): LaravelResponse|RedirectResponse
|
||||
{
|
||||
if (auth()->user()->hasRole('demo')) {
|
||||
session()->flash('info', (string) trans('firefly.demo_user_export'));
|
||||
session()->flash('info', (string)trans('firefly.demo_user_export'));
|
||||
|
||||
return redirect(route('export.index'));
|
||||
}
|
||||
|
@@ -144,7 +144,6 @@ class JavascriptController extends Controller
|
||||
|
||||
return response()
|
||||
->view('v2.javascript.variables', $data)
|
||||
->header('Content-Type', 'text/javascript')
|
||||
;
|
||||
->header('Content-Type', 'text/javascript');
|
||||
}
|
||||
}
|
||||
|
@@ -129,7 +129,7 @@ class BoxController extends Controller
|
||||
app('log')->debug('Left to spend is positive or zero!');
|
||||
$boxTitle = (string)trans('firefly.left_to_spend');
|
||||
$activeDaysLeft = $this->activeDaysLeft($start, $end); // see method description.
|
||||
$display = 1; // not overspent
|
||||
$display = 1; // not overspent
|
||||
$leftPerDayAmount = bcdiv($leftToSpendAmount, (string)$activeDaysLeft);
|
||||
app('log')->debug(sprintf('Left to spend per day is %s', $leftPerDayAmount));
|
||||
}
|
||||
|
@@ -71,13 +71,13 @@ class RecurrenceController extends Controller
|
||||
$start = Carbon::createFromFormat('Y-m-d', $request->get('start'));
|
||||
$end = Carbon::createFromFormat('Y-m-d', $request->get('end'));
|
||||
$firstDate = Carbon::createFromFormat('Y-m-d', $request->get('first_date'));
|
||||
$endDate = '' !== (string) $request->get('end_date') ? Carbon::createFromFormat('Y-m-d', $request->get('end_date')) : null;
|
||||
$endsAt = (string) $request->get('ends');
|
||||
$endDate = '' !== (string)$request->get('end_date') ? Carbon::createFromFormat('Y-m-d', $request->get('end_date')) : null;
|
||||
$endsAt = (string)$request->get('ends');
|
||||
$repetitionType = explode(',', $request->get('type'))[0];
|
||||
$repetitions = (int) $request->get('reps');
|
||||
$weekend = (int) $request->get('weekend');
|
||||
$repetitions = (int)$request->get('reps');
|
||||
$weekend = (int)$request->get('weekend');
|
||||
$repetitionMoment = '';
|
||||
$skip = (int) $request->get('skip');
|
||||
$skip = (int)$request->get('skip');
|
||||
$skip = $skip < 0 || $skip > 31 ? 0 : $skip;
|
||||
$weekend = $weekend < 1 || $weekend > 4 ? 1 : $weekend;
|
||||
|
||||
@@ -147,7 +147,7 @@ class RecurrenceController extends Controller
|
||||
*/
|
||||
public function suggest(Request $request): JsonResponse
|
||||
{
|
||||
$string = '' === (string) $request->get('date') ? date('Y-m-d') : (string) $request->get('date');
|
||||
$string = '' === (string)$request->get('date') ? date('Y-m-d') : (string)$request->get('date');
|
||||
$today = today(config('app.timezone'))->startOfDay();
|
||||
|
||||
try {
|
||||
@@ -159,37 +159,37 @@ class RecurrenceController extends Controller
|
||||
return response()->json();
|
||||
}
|
||||
$date->startOfDay();
|
||||
$preSelected = (string) $request->get('pre_select');
|
||||
$preSelected = (string)$request->get('pre_select');
|
||||
$locale = app('steam')->getLocale();
|
||||
|
||||
app('log')->debug(sprintf('date = %s, today = %s. date > today? %s', $date->toAtomString(), $today->toAtomString(), var_export($date > $today, true)));
|
||||
app('log')->debug(sprintf('past = true? %s', var_export('true' === (string) $request->get('past'), true)));
|
||||
app('log')->debug(sprintf('past = true? %s', var_export('true' === (string)$request->get('past'), true)));
|
||||
|
||||
$result = [];
|
||||
if ($date > $today || 'true' === (string) $request->get('past')) {
|
||||
if ($date > $today || 'true' === (string)$request->get('past')) {
|
||||
app('log')->debug('Will fill dropdown.');
|
||||
$weekly = sprintf('weekly,%s', $date->dayOfWeekIso);
|
||||
$monthly = sprintf('monthly,%s', $date->day);
|
||||
$dayOfWeek = (string) trans(sprintf('config.dow_%s', $date->dayOfWeekIso));
|
||||
$dayOfWeek = (string)trans(sprintf('config.dow_%s', $date->dayOfWeekIso));
|
||||
$ndom = sprintf('ndom,%s,%s', $date->weekOfMonth, $date->dayOfWeekIso);
|
||||
$yearly = sprintf('yearly,%s', $date->format('Y-m-d'));
|
||||
$yearlyDate = $date->isoFormat((string) trans('config.month_and_day_no_year_js', [], $locale));
|
||||
$yearlyDate = $date->isoFormat((string)trans('config.month_and_day_no_year_js', [], $locale));
|
||||
$result = [
|
||||
'daily' => ['label' => (string) trans('firefly.recurring_daily'), 'selected' => str_starts_with($preSelected, 'daily')],
|
||||
'daily' => ['label' => (string)trans('firefly.recurring_daily'), 'selected' => str_starts_with($preSelected, 'daily')],
|
||||
$weekly => [
|
||||
'label' => (string) trans('firefly.recurring_weekly', ['weekday' => $dayOfWeek]),
|
||||
'label' => (string)trans('firefly.recurring_weekly', ['weekday' => $dayOfWeek]),
|
||||
'selected' => str_starts_with($preSelected, 'weekly'),
|
||||
],
|
||||
$monthly => [
|
||||
'label' => (string) trans('firefly.recurring_monthly', ['dayOfMonth' => $date->day]),
|
||||
'label' => (string)trans('firefly.recurring_monthly', ['dayOfMonth' => $date->day]),
|
||||
'selected' => str_starts_with($preSelected, 'monthly'),
|
||||
],
|
||||
$ndom => [
|
||||
'label' => (string) trans('firefly.recurring_ndom', ['weekday' => $dayOfWeek, 'dayOfMonth' => $date->weekOfMonth]),
|
||||
'label' => (string)trans('firefly.recurring_ndom', ['weekday' => $dayOfWeek, 'dayOfMonth' => $date->weekOfMonth]),
|
||||
'selected' => str_starts_with($preSelected, 'ndom'),
|
||||
],
|
||||
$yearly => [
|
||||
'label' => (string) trans('firefly.recurring_yearly', ['date' => $yearlyDate]),
|
||||
'label' => (string)trans('firefly.recurring_yearly', ['date' => $yearlyDate]),
|
||||
'selected' => str_starts_with($preSelected, 'yearly'),
|
||||
],
|
||||
];
|
||||
|
@@ -141,24 +141,6 @@ class IndexController extends Controller
|
||||
return view('piggy-banks.index', compact('piggyBanks', 'accounts'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the order of a piggy bank.
|
||||
*/
|
||||
public function setOrder(Request $request, PiggyBank $piggyBank): JsonResponse
|
||||
{
|
||||
$objectGroupTitle = (string)$request->get('objectGroupTitle');
|
||||
$newOrder = (int)$request->get('order');
|
||||
$this->piggyRepos->setOrder($piggyBank, $newOrder);
|
||||
if ('' !== $objectGroupTitle) {
|
||||
$this->piggyRepos->setObjectGroup($piggyBank, $objectGroupTitle);
|
||||
}
|
||||
if ('' === $objectGroupTitle) {
|
||||
$this->piggyRepos->removeObjectGroup($piggyBank);
|
||||
}
|
||||
|
||||
return response()->json(['data' => 'OK']);
|
||||
}
|
||||
|
||||
private function makeSums(array $piggyBanks): array
|
||||
{
|
||||
$sums = [];
|
||||
@@ -193,4 +175,22 @@ class IndexController extends Controller
|
||||
|
||||
return $piggyBanks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the order of a piggy bank.
|
||||
*/
|
||||
public function setOrder(Request $request, PiggyBank $piggyBank): JsonResponse
|
||||
{
|
||||
$objectGroupTitle = (string)$request->get('objectGroupTitle');
|
||||
$newOrder = (int)$request->get('order');
|
||||
$this->piggyRepos->setOrder($piggyBank, $newOrder);
|
||||
if ('' !== $objectGroupTitle) {
|
||||
$this->piggyRepos->setObjectGroup($piggyBank, $objectGroupTitle);
|
||||
}
|
||||
if ('' === $objectGroupTitle) {
|
||||
$this->piggyRepos->removeObjectGroup($piggyBank);
|
||||
}
|
||||
|
||||
return response()->json(['data' => 'OK']);
|
||||
}
|
||||
}
|
||||
|
@@ -49,7 +49,7 @@ class PreferencesController extends Controller
|
||||
|
||||
$this->middleware(
|
||||
static function ($request, $next) {
|
||||
app('view')->share('title', (string) trans('firefly.preferences'));
|
||||
app('view')->share('title', (string)trans('firefly.preferences'));
|
||||
app('view')->share('mainTitleIcon', 'fa-gear');
|
||||
|
||||
return $next($request);
|
||||
@@ -72,8 +72,8 @@ class PreferencesController extends Controller
|
||||
|
||||
/** @var Account $account */
|
||||
foreach ($accounts as $account) {
|
||||
$type = $account->accountType->type;
|
||||
$role = sprintf('opt_group_%s', $repository->getMetaValue($account, 'account_role'));
|
||||
$type = $account->accountType->type;
|
||||
$role = sprintf('opt_group_%s', $repository->getMetaValue($account, 'account_role'));
|
||||
|
||||
if (in_array($type, [AccountType::MORTGAGE, AccountType::DEBT, AccountType::LOAN], true)) {
|
||||
$role = sprintf('opt_group_l_%s', $type);
|
||||
@@ -82,7 +82,7 @@ class PreferencesController extends Controller
|
||||
if ('opt_group_' === $role) {
|
||||
$role = 'opt_group_defaultAsset';
|
||||
}
|
||||
$groupedAccounts[(string) trans(sprintf('firefly.%s', $role))][$account->id] = $account->name;
|
||||
$groupedAccounts[(string)trans(sprintf('firefly.%s', $role))][$account->id] = $account->name;
|
||||
}
|
||||
ksort($groupedAccounts);
|
||||
|
||||
@@ -105,7 +105,7 @@ class PreferencesController extends Controller
|
||||
if (is_array($fiscalYearStartStr)) {
|
||||
$fiscalYearStartStr = '01-01';
|
||||
}
|
||||
$fiscalYearStart = sprintf('%s-%s', date('Y'), (string) $fiscalYearStartStr);
|
||||
$fiscalYearStart = sprintf('%s-%s', date('Y'), (string)$fiscalYearStartStr);
|
||||
$tjOptionalFields = app('preferences')->get('transaction_journal_optional_fields', [])->data;
|
||||
$availableDarkModes = config('firefly.available_dark_modes');
|
||||
|
||||
@@ -120,12 +120,12 @@ class PreferencesController extends Controller
|
||||
// list of locales also has "equal" which makes it equal to whatever the language is.
|
||||
|
||||
try {
|
||||
$locales = json_decode((string) file_get_contents(resource_path(sprintf('lang/%s/locales.json', $language))), true, 512, JSON_THROW_ON_ERROR);
|
||||
$locales = json_decode((string)file_get_contents(resource_path(sprintf('lang/%s/locales.json', $language))), true, 512, JSON_THROW_ON_ERROR);
|
||||
} catch (\JsonException $e) {
|
||||
app('log')->error($e->getMessage());
|
||||
$locales = [];
|
||||
}
|
||||
$locales = ['equal' => (string) trans('firefly.equal_to_language')] + $locales;
|
||||
$locales = ['equal' => (string)trans('firefly.equal_to_language')] + $locales;
|
||||
// an important fallback is that the frontPageAccount array gets refilled automatically
|
||||
// when it turns up empty.
|
||||
if (0 === count($frontPageAccounts)) {
|
||||
@@ -158,7 +158,7 @@ class PreferencesController extends Controller
|
||||
$frontPageAccounts = [];
|
||||
if (is_array($request->get('frontPageAccounts')) && count($request->get('frontPageAccounts')) > 0) {
|
||||
foreach ($request->get('frontPageAccounts') as $id) {
|
||||
$frontPageAccounts[] = (int) $id;
|
||||
$frontPageAccounts[] = (int)$id;
|
||||
}
|
||||
app('preferences')->set('frontPageAccounts', $frontPageAccounts);
|
||||
}
|
||||
@@ -184,7 +184,7 @@ class PreferencesController extends Controller
|
||||
|
||||
// slack URL:
|
||||
if (!auth()->user()->hasRole('demo')) {
|
||||
$url = (string) $request->get('slackUrl');
|
||||
$url = (string)$request->get('slackUrl');
|
||||
if (UrlValidator::isValidWebhookURL($url)) {
|
||||
app('preferences')->set('slack_webhook_url', $url);
|
||||
}
|
||||
@@ -194,8 +194,8 @@ class PreferencesController extends Controller
|
||||
}
|
||||
|
||||
// custom fiscal year
|
||||
$customFiscalYear = 1 === (int) $request->get('customFiscalYear');
|
||||
$string = strtotime((string) $request->get('fiscalYearStart'));
|
||||
$customFiscalYear = 1 === (int)$request->get('customFiscalYear');
|
||||
$string = strtotime((string)$request->get('fiscalYearStart'));
|
||||
if (false !== $string) {
|
||||
$fiscalYearStart = date('m-d', $string);
|
||||
app('preferences')->set('customFiscalYear', $customFiscalYear);
|
||||
@@ -204,7 +204,7 @@ class PreferencesController extends Controller
|
||||
|
||||
// save page size:
|
||||
app('preferences')->set('listPageSize', 50);
|
||||
$listPageSize = (int) $request->get('listPageSize');
|
||||
$listPageSize = (int)$request->get('listPageSize');
|
||||
if ($listPageSize > 0 && $listPageSize < 1337) {
|
||||
app('preferences')->set('listPageSize', $listPageSize);
|
||||
}
|
||||
@@ -252,7 +252,7 @@ class PreferencesController extends Controller
|
||||
app('preferences')->set('darkMode', $darkMode);
|
||||
}
|
||||
|
||||
session()->flash('success', (string) trans('firefly.saved_preferences'));
|
||||
session()->flash('success', (string)trans('firefly.saved_preferences'));
|
||||
app('preferences')->mark();
|
||||
|
||||
return redirect(route('preferences.index'));
|
||||
|
@@ -497,6 +497,47 @@ class ProfileController extends Controller
|
||||
return redirect(route('profile.index'));
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO duplicate code.
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function addToMFAHistory(string $mfaCode): void
|
||||
{
|
||||
/** @var array $mfaHistory */
|
||||
$mfaHistory = app('preferences')->get('mfa_history', [])->data;
|
||||
$entry = [
|
||||
'time' => time(),
|
||||
'code' => $mfaCode,
|
||||
];
|
||||
$mfaHistory[] = $entry;
|
||||
|
||||
app('preferences')->set('mfa_history', $mfaHistory);
|
||||
$this->filterMFAHistory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove old entries from the preferences array.
|
||||
*/
|
||||
private function filterMFAHistory(): void
|
||||
{
|
||||
/** @var array $mfaHistory */
|
||||
$mfaHistory = app('preferences')->get('mfa_history', [])->data;
|
||||
$newHistory = [];
|
||||
$now = time();
|
||||
foreach ($mfaHistory as $entry) {
|
||||
$time = $entry['time'];
|
||||
$code = $entry['code'];
|
||||
if ($now - $time <= 300) {
|
||||
$newHistory[] = [
|
||||
'time' => $time,
|
||||
'code' => $code,
|
||||
];
|
||||
}
|
||||
}
|
||||
app('preferences')->set('mfa_history', $newHistory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit delete account.
|
||||
*
|
||||
@@ -631,45 +672,4 @@ class ProfileController extends Controller
|
||||
|
||||
return redirect(route('login'));
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO duplicate code.
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function addToMFAHistory(string $mfaCode): void
|
||||
{
|
||||
/** @var array $mfaHistory */
|
||||
$mfaHistory = app('preferences')->get('mfa_history', [])->data;
|
||||
$entry = [
|
||||
'time' => time(),
|
||||
'code' => $mfaCode,
|
||||
];
|
||||
$mfaHistory[] = $entry;
|
||||
|
||||
app('preferences')->set('mfa_history', $mfaHistory);
|
||||
$this->filterMFAHistory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove old entries from the preferences array.
|
||||
*/
|
||||
private function filterMFAHistory(): void
|
||||
{
|
||||
/** @var array $mfaHistory */
|
||||
$mfaHistory = app('preferences')->get('mfa_history', [])->data;
|
||||
$newHistory = [];
|
||||
$now = time();
|
||||
foreach ($mfaHistory as $entry) {
|
||||
$time = $entry['time'];
|
||||
$code = $entry['code'];
|
||||
if ($now - $time <= 300) {
|
||||
$newHistory[] = [
|
||||
'time' => $time,
|
||||
'code' => $code,
|
||||
];
|
||||
}
|
||||
}
|
||||
app('preferences')->set('mfa_history', $newHistory);
|
||||
}
|
||||
}
|
||||
|
@@ -283,8 +283,8 @@ class CategoryController extends Controller
|
||||
];
|
||||
++$result[$key]['transactions'];
|
||||
$result[$key]['sum'] = bcadd($journal['amount'], $result[$key]['sum']);
|
||||
$result[$key]['avg'] = bcdiv($result[$key]['sum'], (string) $result[$key]['transactions']);
|
||||
$result[$key]['avg_float'] = (float) $result[$key]['avg']; // intentional float
|
||||
$result[$key]['avg'] = bcdiv($result[$key]['sum'], (string)$result[$key]['transactions']);
|
||||
$result[$key]['avg_float'] = (float)$result[$key]['avg']; // intentional float
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -333,8 +333,8 @@ class CategoryController extends Controller
|
||||
];
|
||||
++$result[$key]['transactions'];
|
||||
$result[$key]['sum'] = bcadd($journal['amount'], $result[$key]['sum']);
|
||||
$result[$key]['avg'] = bcdiv($result[$key]['sum'], (string) $result[$key]['transactions']);
|
||||
$result[$key]['avg_float'] = (float) $result[$key]['avg'];
|
||||
$result[$key]['avg'] = bcdiv($result[$key]['sum'], (string)$result[$key]['transactions']);
|
||||
$result[$key]['avg_float'] = (float)$result[$key]['avg'];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -664,7 +664,7 @@ class CategoryController extends Controller
|
||||
$result[] = [
|
||||
'description' => $journal['description'],
|
||||
'transaction_group_id' => $journal['transaction_group_id'],
|
||||
'amount_float' => (float) $journal['amount'],
|
||||
'amount_float' => (float)$journal['amount'],
|
||||
'amount' => $journal['amount'],
|
||||
'date' => $journal['date']->isoFormat($this->monthAndDayFormat),
|
||||
'date_sort' => $journal['date']->format('Y-m-d'),
|
||||
@@ -712,7 +712,7 @@ class CategoryController extends Controller
|
||||
$result[] = [
|
||||
'description' => $journal['description'],
|
||||
'transaction_group_id' => $journal['transaction_group_id'],
|
||||
'amount_float' => (float) $journal['amount'],
|
||||
'amount_float' => (float)$journal['amount'],
|
||||
'amount' => $journal['amount'],
|
||||
'date' => $journal['date']->isoFormat($this->monthAndDayFormat),
|
||||
'date_sort' => $journal['date']->format('Y-m-d'),
|
||||
|
@@ -41,7 +41,7 @@ class DoubleController extends Controller
|
||||
{
|
||||
use AugumentData;
|
||||
|
||||
protected AccountRepositoryInterface $accountRepository;
|
||||
protected AccountRepositoryInterface $accountRepository;
|
||||
private OperationsRepositoryInterface $opsRepository;
|
||||
|
||||
/**
|
||||
@@ -278,6 +278,24 @@ class DoubleController extends Controller
|
||||
return view('reports.double.partials.accounts', compact('sums', 'report'));
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO this method is duplicated.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Factory|View
|
||||
*/
|
||||
@@ -468,22 +486,4 @@ class DoubleController extends Controller
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO this method is duplicated.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@@ -279,8 +279,8 @@ class TagController extends Controller
|
||||
];
|
||||
++$result[$key]['transactions'];
|
||||
$result[$key]['sum'] = bcadd($journal['amount'], $result[$key]['sum']);
|
||||
$result[$key]['avg'] = bcdiv($result[$key]['sum'], (string) $result[$key]['transactions']);
|
||||
$result[$key]['avg_float'] = (float) $result[$key]['avg'];
|
||||
$result[$key]['avg'] = bcdiv($result[$key]['sum'], (string)$result[$key]['transactions']);
|
||||
$result[$key]['avg_float'] = (float)$result[$key]['avg'];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -329,8 +329,8 @@ class TagController extends Controller
|
||||
];
|
||||
++$result[$key]['transactions'];
|
||||
$result[$key]['sum'] = bcadd($journal['amount'], $result[$key]['sum']);
|
||||
$result[$key]['avg'] = bcdiv($result[$key]['sum'], (string) $result[$key]['transactions']);
|
||||
$result[$key]['avg_float'] = (float) $result[$key]['avg'];
|
||||
$result[$key]['avg'] = bcdiv($result[$key]['sum'], (string)$result[$key]['transactions']);
|
||||
$result[$key]['avg_float'] = (float)$result[$key]['avg'];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -466,7 +466,7 @@ class TagController extends Controller
|
||||
$result[] = [
|
||||
'description' => $journal['description'],
|
||||
'transaction_group_id' => $journal['transaction_group_id'],
|
||||
'amount_float' => (float) $journal['amount'],
|
||||
'amount_float' => (float)$journal['amount'],
|
||||
'amount' => $journal['amount'],
|
||||
'date' => $journal['date']->isoFormat($this->monthAndDayFormat),
|
||||
'date_sort' => $journal['date']->format('Y-m-d'),
|
||||
@@ -514,7 +514,7 @@ class TagController extends Controller
|
||||
$result[] = [
|
||||
'description' => $journal['description'],
|
||||
'transaction_group_id' => $journal['transaction_group_id'],
|
||||
'amount_float' => (float) $journal['amount'], // intentional float.
|
||||
'amount_float' => (float)$journal['amount'], // intentional float.
|
||||
'amount' => $journal['amount'],
|
||||
'date' => $journal['date']->isoFormat($this->monthAndDayFormat),
|
||||
'date_sort' => $journal['date']->format('Y-m-d'),
|
||||
|
@@ -132,29 +132,6 @@ class EditController extends Controller
|
||||
return view('rules.rule.edit', compact('rule', 'subTitle', 'primaryTrigger', 'oldTriggers', 'oldActions', 'triggerCount', 'actionCount'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the rule.
|
||||
*
|
||||
* @return Redirector|RedirectResponse
|
||||
*/
|
||||
public function update(RuleFormRequest $request, Rule $rule)
|
||||
{
|
||||
$data = $request->getRuleData();
|
||||
|
||||
$this->ruleRepos->update($rule, $data);
|
||||
|
||||
session()->flash('success', (string)trans('firefly.updated_rule', ['title' => $rule->title]));
|
||||
app('preferences')->mark();
|
||||
$redirect = redirect($this->getPreviousUrl('rules.edit.url'));
|
||||
if (1 === (int)$request->get('return_to_edit')) {
|
||||
session()->put('rules.edit.fromUpdate', true);
|
||||
|
||||
$redirect = redirect(route('rules.edit', [$rule->id]))->withInput(['return_to_edit' => 1]);
|
||||
}
|
||||
|
||||
return $redirect;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
*/
|
||||
@@ -196,4 +173,27 @@ class EditController extends Controller
|
||||
|
||||
return $renderedEntries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the rule.
|
||||
*
|
||||
* @return Redirector|RedirectResponse
|
||||
*/
|
||||
public function update(RuleFormRequest $request, Rule $rule)
|
||||
{
|
||||
$data = $request->getRuleData();
|
||||
|
||||
$this->ruleRepos->update($rule, $data);
|
||||
|
||||
session()->flash('success', (string)trans('firefly.updated_rule', ['title' => $rule->title]));
|
||||
app('preferences')->mark();
|
||||
$redirect = redirect($this->getPreviousUrl('rules.edit.url'));
|
||||
if (1 === (int)$request->get('return_to_edit')) {
|
||||
session()->put('rules.edit.fromUpdate', true);
|
||||
|
||||
$redirect = redirect(route('rules.edit', [$rule->id]))->withInput(['return_to_edit' => 1]);
|
||||
}
|
||||
|
||||
return $redirect;
|
||||
}
|
||||
}
|
||||
|
@@ -129,26 +129,6 @@ class InstallController extends Controller
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create specific RSA keys.
|
||||
*/
|
||||
public function keys(): void
|
||||
{
|
||||
$key = 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, (string)$key->getPublicKey());
|
||||
file_put_contents($privateKey, $key->toString('PKCS1'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
*/
|
||||
@@ -173,4 +153,24 @@ class InstallController extends Controller
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create specific RSA keys.
|
||||
*/
|
||||
public function keys(): void
|
||||
{
|
||||
$key = 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, (string)$key->getPublicKey());
|
||||
file_put_contents($privateKey, $key->toString('PKCS1'));
|
||||
}
|
||||
}
|
||||
|
@@ -135,38 +135,6 @@ class ConvertController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Do the conversion.
|
||||
*
|
||||
* @return Redirector|RedirectResponse
|
||||
*/
|
||||
public function postIndex(Request $request, TransactionType $destinationType, TransactionGroup $group)
|
||||
{
|
||||
if (!$this->isEditableGroup($group)) {
|
||||
return $this->redirectGroupToAccount($group);
|
||||
}
|
||||
|
||||
/** @var TransactionJournal $journal */
|
||||
foreach ($group->transactionJournals as $journal) {
|
||||
// catch FF exception.
|
||||
try {
|
||||
$this->convertJournal($journal, $destinationType, $request->all());
|
||||
} catch (FireflyException $e) {
|
||||
session()->flash('error', $e->getMessage());
|
||||
|
||||
return redirect()->route('transactions.convert.index', [strtolower($destinationType->type), $group->id])->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
// correct transfers:
|
||||
$group->refresh();
|
||||
|
||||
session()->flash('success', (string)trans('firefly.converted_to_'.$destinationType->type));
|
||||
event(new UpdatedTransactionGroup($group, true, true));
|
||||
|
||||
return redirect(route('transactions.show', [$group->id]));
|
||||
}
|
||||
|
||||
private function getValidDepositSources(): array
|
||||
{
|
||||
// make repositories
|
||||
@@ -291,6 +259,38 @@ class ConvertController extends Controller
|
||||
return $grouped;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do the conversion.
|
||||
*
|
||||
* @return Redirector|RedirectResponse
|
||||
*/
|
||||
public function postIndex(Request $request, TransactionType $destinationType, TransactionGroup $group)
|
||||
{
|
||||
if (!$this->isEditableGroup($group)) {
|
||||
return $this->redirectGroupToAccount($group);
|
||||
}
|
||||
|
||||
/** @var TransactionJournal $journal */
|
||||
foreach ($group->transactionJournals as $journal) {
|
||||
// catch FF exception.
|
||||
try {
|
||||
$this->convertJournal($journal, $destinationType, $request->all());
|
||||
} catch (FireflyException $e) {
|
||||
session()->flash('error', $e->getMessage());
|
||||
|
||||
return redirect()->route('transactions.convert.index', [strtolower($destinationType->type), $group->id])->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
// correct transfers:
|
||||
$group->refresh();
|
||||
|
||||
session()->flash('success', (string)trans('firefly.converted_to_'.$destinationType->type));
|
||||
event(new UpdatedTransactionGroup($group, true, true));
|
||||
|
||||
return redirect(route('transactions.show', [$group->id]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
*/
|
||||
|
@@ -50,7 +50,7 @@ class CreateController extends Controller
|
||||
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
app('view')->share('title', (string) trans('firefly.transactions'));
|
||||
app('view')->share('title', (string)trans('firefly.transactions'));
|
||||
app('view')->share('mainTitleIcon', 'fa-exchange');
|
||||
$this->repository = app(TransactionGroupRepositoryInterface::class);
|
||||
|
||||
@@ -61,7 +61,7 @@ class CreateController extends Controller
|
||||
|
||||
public function cloneGroup(Request $request): JsonResponse
|
||||
{
|
||||
$groupId = (int) $request->get('id');
|
||||
$groupId = (int)$request->get('id');
|
||||
if (0 !== $groupId) {
|
||||
$group = $this->repository->find($groupId);
|
||||
if (null !== $group) {
|
||||
@@ -101,14 +101,14 @@ class CreateController extends Controller
|
||||
{
|
||||
app('preferences')->mark();
|
||||
|
||||
$sourceId = (int) request()->get('source');
|
||||
$destinationId = (int) request()->get('destination');
|
||||
$sourceId = (int)request()->get('source');
|
||||
$destinationId = (int)request()->get('destination');
|
||||
|
||||
/** @var AccountRepositoryInterface $accountRepository */
|
||||
$accountRepository = app(AccountRepositoryInterface::class);
|
||||
$cash = $accountRepository->getCashAccount();
|
||||
$preFilled = session()->has('preFilled') ? session('preFilled') : [];
|
||||
$subTitle = (string) trans(sprintf('breadcrumbs.create_%s', strtolower((string) $objectType)));
|
||||
$subTitle = (string)trans(sprintf('breadcrumbs.create_%s', strtolower((string)$objectType)));
|
||||
$subTitleIcon = 'fa-plus';
|
||||
$optionalFields = app('preferences')->get('transaction_journal_optional_fields', [])->data;
|
||||
$allowedOpposingTypes = config('firefly.allowed_opposing_types');
|
||||
|
@@ -51,7 +51,7 @@ class EditController extends Controller
|
||||
// translations:
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
app('view')->share('title', (string) trans('firefly.transactions'));
|
||||
app('view')->share('title', (string)trans('firefly.transactions'));
|
||||
app('view')->share('mainTitleIcon', 'fa-exchange');
|
||||
|
||||
$this->repository = app(JournalRepositoryInterface::class);
|
||||
@@ -79,7 +79,7 @@ class EditController extends Controller
|
||||
$expectedSourceTypes = config('firefly.expected_source_types');
|
||||
$allowedSourceDests = config('firefly.source_dests');
|
||||
$title = $transactionGroup->transactionJournals()->count() > 1 ? $transactionGroup->title : $transactionGroup->transactionJournals()->first()->description;
|
||||
$subTitle = (string) trans('firefly.edit_transaction_title', ['description' => $title]);
|
||||
$subTitle = (string)trans('firefly.edit_transaction_title', ['description' => $title]);
|
||||
$subTitleIcon = 'fa-plus';
|
||||
$defaultCurrency = app('amount')->getDefaultCurrency();
|
||||
$cash = $repository->getCashAccount();
|
||||
|
@@ -73,22 +73,6 @@ class Installer
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is access denied error.
|
||||
*/
|
||||
protected function isAccessDenied(string $message): bool
|
||||
{
|
||||
return false !== stripos($message, 'Access denied');
|
||||
}
|
||||
|
||||
/**
|
||||
* Is no tables exist error.
|
||||
*/
|
||||
protected function noTablesExist(string $message): bool
|
||||
{
|
||||
return false !== stripos($message, 'Base table or view not found');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the tables are created and accounted for.
|
||||
*
|
||||
@@ -125,6 +109,22 @@ class Installer
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is access denied error.
|
||||
*/
|
||||
protected function isAccessDenied(string $message): bool
|
||||
{
|
||||
return false !== stripos($message, 'Access denied');
|
||||
}
|
||||
|
||||
/**
|
||||
* Is no tables exist error.
|
||||
*/
|
||||
protected function noTablesExist(string $message): bool
|
||||
{
|
||||
return false !== stripos($message, 'Base table or view not found');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the "db_version" variable is correct.
|
||||
*/
|
||||
|
@@ -46,7 +46,7 @@ class JournalLinkRequest extends FormRequest
|
||||
$return = [];
|
||||
$linkType = $this->get('link_type');
|
||||
$parts = explode('_', $linkType);
|
||||
$return['link_type_id'] = (int) $parts[0];
|
||||
$return['link_type_id'] = (int)$parts[0];
|
||||
$return['transaction_journal_id'] = $this->convertInteger('opposing');
|
||||
$return['notes'] = $this->convertString('notes');
|
||||
$return['direction'] = $parts[1];
|
||||
|
@@ -150,6 +150,38 @@ class RecurrenceFormRequest extends FormRequest
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses repetition data.
|
||||
*/
|
||||
private function parseRepetitionData(): array
|
||||
{
|
||||
$value = $this->convertString('repetition_type');
|
||||
$return = [
|
||||
'type' => '',
|
||||
'moment' => '',
|
||||
];
|
||||
|
||||
if ('daily' === $value) {
|
||||
$return['type'] = $value;
|
||||
}
|
||||
// monthly,17
|
||||
// ndom,3,7
|
||||
if (in_array(substr($value, 0, 6), ['yearly', 'weekly'], true)) {
|
||||
$return['type'] = substr($value, 0, 6);
|
||||
$return['moment'] = substr($value, 7);
|
||||
}
|
||||
if (str_starts_with($value, 'monthly')) {
|
||||
$return['type'] = substr($value, 0, 7);
|
||||
$return['moment'] = substr($value, 8);
|
||||
}
|
||||
if (str_starts_with($value, 'ndom')) {
|
||||
$return['type'] = substr($value, 0, 4);
|
||||
$return['moment'] = substr($value, 5);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* The rules for this request.
|
||||
*/
|
||||
@@ -278,18 +310,18 @@ class RecurrenceFormRequest extends FormRequest
|
||||
$throwError = true;
|
||||
if ('withdrawal' === $type) {
|
||||
$throwError = false;
|
||||
$sourceId = (int) $data['source_id'];
|
||||
$destinationId = (int) $data['withdrawal_destination_id'];
|
||||
$sourceId = (int)$data['source_id'];
|
||||
$destinationId = (int)$data['withdrawal_destination_id'];
|
||||
}
|
||||
if ('deposit' === $type) {
|
||||
$throwError = false;
|
||||
$sourceId = (int) $data['deposit_source_id'];
|
||||
$destinationId = (int) ($data['destination_id'] ?? 0);
|
||||
$sourceId = (int)$data['deposit_source_id'];
|
||||
$destinationId = (int)($data['destination_id'] ?? 0);
|
||||
}
|
||||
if ('transfer' === $type) {
|
||||
$throwError = false;
|
||||
$sourceId = (int) $data['source_id'];
|
||||
$destinationId = (int) ($data['destination_id'] ?? 0);
|
||||
$sourceId = (int)$data['source_id'];
|
||||
$destinationId = (int)($data['destination_id'] ?? 0);
|
||||
}
|
||||
if (true === $throwError) {
|
||||
throw new FireflyException(sprintf('Cannot handle transaction type "%s"', $this->convertString('transaction_type')));
|
||||
@@ -300,7 +332,7 @@ class RecurrenceFormRequest extends FormRequest
|
||||
|
||||
// do something with result:
|
||||
if (false === $validSource) {
|
||||
$message = (string) trans('validation.generic_invalid_source');
|
||||
$message = (string)trans('validation.generic_invalid_source');
|
||||
$validator->errors()->add('source_id', $message);
|
||||
$validator->errors()->add('deposit_source_id', $message);
|
||||
|
||||
@@ -311,41 +343,9 @@ class RecurrenceFormRequest extends FormRequest
|
||||
$validDestination = $accountValidator->validateDestination(['id' => $destinationId]);
|
||||
// do something with result:
|
||||
if (false === $validDestination) {
|
||||
$message = (string) trans('validation.generic_invalid_destination');
|
||||
$message = (string)trans('validation.generic_invalid_destination');
|
||||
$validator->errors()->add('destination_id', $message);
|
||||
$validator->errors()->add('withdrawal_destination_id', $message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses repetition data.
|
||||
*/
|
||||
private function parseRepetitionData(): array
|
||||
{
|
||||
$value = $this->convertString('repetition_type');
|
||||
$return = [
|
||||
'type' => '',
|
||||
'moment' => '',
|
||||
];
|
||||
|
||||
if ('daily' === $value) {
|
||||
$return['type'] = $value;
|
||||
}
|
||||
// monthly,17
|
||||
// ndom,3,7
|
||||
if (in_array(substr($value, 0, 6), ['yearly', 'weekly'], true)) {
|
||||
$return['type'] = substr($value, 0, 6);
|
||||
$return['moment'] = substr($value, 7);
|
||||
}
|
||||
if (str_starts_with($value, 'monthly')) {
|
||||
$return['type'] = substr($value, 0, 7);
|
||||
$return['moment'] = substr($value, 8);
|
||||
}
|
||||
if (str_starts_with($value, 'ndom')) {
|
||||
$return['type'] = substr($value, 0, 4);
|
||||
$return['moment'] = substr($value, 5);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
@@ -55,7 +55,7 @@ class ReportFormRequest extends FormRequest
|
||||
$collection = new Collection();
|
||||
if (is_array($set)) {
|
||||
foreach ($set as $accountId) {
|
||||
$account = $repository->find((int) $accountId);
|
||||
$account = $repository->find((int)$accountId);
|
||||
if (null !== $account) {
|
||||
$collection->push($account);
|
||||
}
|
||||
@@ -76,7 +76,7 @@ class ReportFormRequest extends FormRequest
|
||||
$collection = new Collection();
|
||||
if (is_array($set)) {
|
||||
foreach ($set as $budgetId) {
|
||||
$budget = $repository->find((int) $budgetId);
|
||||
$budget = $repository->find((int)$budgetId);
|
||||
if (null !== $budget) {
|
||||
$collection->push($budget);
|
||||
}
|
||||
@@ -97,7 +97,7 @@ class ReportFormRequest extends FormRequest
|
||||
$collection = new Collection();
|
||||
if (is_array($set)) {
|
||||
foreach ($set as $categoryId) {
|
||||
$category = $repository->find((int) $categoryId);
|
||||
$category = $repository->find((int)$categoryId);
|
||||
if (null !== $category) {
|
||||
$collection->push($category);
|
||||
}
|
||||
@@ -118,7 +118,7 @@ class ReportFormRequest extends FormRequest
|
||||
$collection = new Collection();
|
||||
if (is_array($set)) {
|
||||
foreach ($set as $accountId) {
|
||||
$account = $repository->find((int) $accountId);
|
||||
$account = $repository->find((int)$accountId);
|
||||
if (null !== $account) {
|
||||
$collection->push($account);
|
||||
}
|
||||
@@ -137,7 +137,7 @@ class ReportFormRequest extends FormRequest
|
||||
{
|
||||
$date = today(config('app.timezone'));
|
||||
$range = $this->get('daterange');
|
||||
$parts = explode(' - ', (string) $range);
|
||||
$parts = explode(' - ', (string)$range);
|
||||
if (2 === count($parts)) {
|
||||
$string = $parts[1];
|
||||
// validate as date
|
||||
@@ -175,7 +175,7 @@ class ReportFormRequest extends FormRequest
|
||||
{
|
||||
$date = today(config('app.timezone'));
|
||||
$range = $this->get('daterange');
|
||||
$parts = explode(' - ', (string) $range);
|
||||
$parts = explode(' - ', (string)$range);
|
||||
if (2 === count($parts)) {
|
||||
$string = $parts[0];
|
||||
// validate as date
|
||||
@@ -229,7 +229,7 @@ class ReportFormRequest extends FormRequest
|
||||
|
||||
continue;
|
||||
}
|
||||
$tag = $repository->find((int) $tagTag);
|
||||
$tag = $repository->find((int)$tagTag);
|
||||
if (null !== $tag) {
|
||||
$collection->push($tag);
|
||||
}
|
||||
|
@@ -58,6 +58,28 @@ class RuleFormRequest extends FormRequest
|
||||
];
|
||||
}
|
||||
|
||||
private function getRuleTriggerData(): array
|
||||
{
|
||||
$return = [];
|
||||
$triggerData = $this->get('triggers');
|
||||
if (is_array($triggerData)) {
|
||||
foreach ($triggerData as $trigger) {
|
||||
$stopProcessing = $trigger['stop_processing'] ?? '0';
|
||||
$prohibited = $trigger['prohibited'] ?? '0';
|
||||
$set = [
|
||||
'type' => $trigger['type'] ?? 'invalid',
|
||||
'value' => $trigger['value'] ?? '',
|
||||
'stop_processing' => 1 === (int)$stopProcessing,
|
||||
'prohibited' => 1 === (int)$prohibited,
|
||||
];
|
||||
$set = self::replaceAmountTrigger($set);
|
||||
$return[] = $set;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
public static function replaceAmountTrigger(array $array): array
|
||||
{
|
||||
// do some sneaky search and replace.
|
||||
@@ -83,6 +105,24 @@ class RuleFormRequest extends FormRequest
|
||||
return $array;
|
||||
}
|
||||
|
||||
private function getRuleActionData(): array
|
||||
{
|
||||
$return = [];
|
||||
$actionData = $this->get('actions');
|
||||
if (is_array($actionData)) {
|
||||
foreach ($actionData as $action) {
|
||||
$stopProcessing = $action['stop_processing'] ?? '0';
|
||||
$return[] = [
|
||||
'type' => $action['type'] ?? 'invalid',
|
||||
'value' => $action['value'] ?? '',
|
||||
'stop_processing' => 1 === (int)$stopProcessing,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rules for this request.
|
||||
*/
|
||||
@@ -127,44 +167,4 @@ class RuleFormRequest extends FormRequest
|
||||
Log::channel('audit')->error(sprintf('Validation errors in %s', __CLASS__), $validator->errors()->toArray());
|
||||
}
|
||||
}
|
||||
|
||||
private function getRuleTriggerData(): array
|
||||
{
|
||||
$return = [];
|
||||
$triggerData = $this->get('triggers');
|
||||
if (is_array($triggerData)) {
|
||||
foreach ($triggerData as $trigger) {
|
||||
$stopProcessing = $trigger['stop_processing'] ?? '0';
|
||||
$prohibited = $trigger['prohibited'] ?? '0';
|
||||
$set = [
|
||||
'type' => $trigger['type'] ?? 'invalid',
|
||||
'value' => $trigger['value'] ?? '',
|
||||
'stop_processing' => 1 === (int) $stopProcessing,
|
||||
'prohibited' => 1 === (int) $prohibited,
|
||||
];
|
||||
$set = self::replaceAmountTrigger($set);
|
||||
$return[] = $set;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
private function getRuleActionData(): array
|
||||
{
|
||||
$return = [];
|
||||
$actionData = $this->get('actions');
|
||||
if (is_array($actionData)) {
|
||||
foreach ($actionData as $action) {
|
||||
$stopProcessing = $action['stop_processing'] ?? '0';
|
||||
$return[] = [
|
||||
'type' => $action['type'] ?? 'invalid',
|
||||
'value' => $action['value'] ?? '',
|
||||
'stop_processing' => 1 === (int) $stopProcessing,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user