2016-05-20 08:57:45 +02:00
|
|
|
<?php
|
2022-12-29 19:41:57 +01:00
|
|
|
|
2016-05-20 12:27:31 +02:00
|
|
|
/**
|
|
|
|
* NewUserController.php
|
2020-01-31 07:32:04 +01:00
|
|
|
* Copyright (c) 2019 james@firefly-iii.org
|
2016-05-20 12:27:31 +02:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
2016-10-05 06:52:15 +02:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
2017-10-21 08:40:00 +02:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2017-10-21 08:40:00 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2019-10-02 06:37:26 +02:00
|
|
|
* GNU Affero General Public License for more details.
|
2017-10-21 08:40:00 +02:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2016-05-20 12:27:31 +02:00
|
|
|
*/
|
2017-04-09 07:44:22 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2016-05-20 08:57:45 +02:00
|
|
|
namespace FireflyIII\Http\Controllers;
|
2015-06-01 18:13:54 +02:00
|
|
|
|
2025-01-03 09:15:52 +01:00
|
|
|
use FireflyIII\Enums\AccountTypeEnum;
|
2021-09-18 10:26:12 +02:00
|
|
|
use FireflyIII\Exceptions\FireflyException;
|
2015-06-01 18:13:54 +02:00
|
|
|
use FireflyIII\Http\Requests\NewUserFormRequest;
|
2020-04-14 17:23:58 +02:00
|
|
|
use FireflyIII\Models\AccountType;
|
2016-10-09 08:18:47 +02:00
|
|
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
2023-10-28 06:58:33 +02:00
|
|
|
use FireflyIII\Repositories\UserGroups\Currency\CurrencyRepositoryInterface;
|
2018-08-10 17:05:37 +02:00
|
|
|
use FireflyIII\Support\Http\Controllers\CreateStuff;
|
2021-05-24 08:54:58 +02:00
|
|
|
use Illuminate\Contracts\View\Factory;
|
2020-03-17 15:01:00 +01:00
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
use Illuminate\Routing\Redirector;
|
2021-05-24 08:54:58 +02:00
|
|
|
use Illuminate\View\View;
|
2015-06-01 18:13:54 +02:00
|
|
|
|
|
|
|
/**
|
2017-11-15 12:25:49 +01:00
|
|
|
* Class NewUserController.
|
2015-06-01 18:13:54 +02:00
|
|
|
*/
|
|
|
|
class NewUserController extends Controller
|
|
|
|
{
|
2018-08-10 17:05:37 +02:00
|
|
|
use CreateStuff;
|
2021-09-18 10:26:12 +02:00
|
|
|
|
2023-10-28 06:58:33 +02:00
|
|
|
private AccountRepositoryInterface $repository;
|
2018-04-15 08:52:58 +02:00
|
|
|
|
2016-01-09 08:20:55 +01:00
|
|
|
/**
|
|
|
|
* NewUserController constructor.
|
|
|
|
*/
|
2016-01-08 18:29:47 +01:00
|
|
|
public function __construct()
|
|
|
|
{
|
2016-01-08 20:40:48 +01:00
|
|
|
parent::__construct();
|
2016-10-29 07:44:46 +02:00
|
|
|
|
|
|
|
$this->middleware(
|
|
|
|
function ($request, $next) {
|
2018-04-15 08:52:58 +02:00
|
|
|
$this->repository = app(AccountRepositoryInterface::class);
|
|
|
|
|
2016-10-29 07:44:46 +02:00
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
);
|
2016-01-08 18:29:47 +01:00
|
|
|
}
|
2015-06-01 18:13:54 +02:00
|
|
|
|
|
|
|
/**
|
2018-07-22 08:10:16 +02:00
|
|
|
* Form the user gets when he has no data in the system.
|
|
|
|
*
|
2023-12-20 19:35:52 +01:00
|
|
|
* @return Factory|Redirector|RedirectResponse|View
|
2015-06-01 18:13:54 +02:00
|
|
|
*/
|
2018-04-15 08:52:58 +02:00
|
|
|
public function index()
|
2015-06-01 18:13:54 +02:00
|
|
|
{
|
2024-12-22 08:43:12 +01:00
|
|
|
app('view')->share('title', (string) trans('firefly.welcome'));
|
2017-12-16 19:46:36 +01:00
|
|
|
app('view')->share('mainTitleIcon', 'fa-fire');
|
2015-06-01 18:13:54 +02:00
|
|
|
|
2024-01-01 14:43:56 +01:00
|
|
|
$types = config('firefly.accountTypesByIdentifier.asset');
|
|
|
|
$count = $this->repository->count($types);
|
2018-04-15 08:52:58 +02:00
|
|
|
|
|
|
|
$languages = [];
|
2015-06-01 18:13:54 +02:00
|
|
|
|
|
|
|
if ($count > 0) {
|
2015-07-06 16:27:21 +02:00
|
|
|
return redirect(route('index'));
|
2015-06-01 18:13:54 +02:00
|
|
|
}
|
|
|
|
|
2022-01-29 14:11:12 +01:00
|
|
|
return view('new-user.index', compact('languages'));
|
2015-06-01 18:13:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-22 08:10:16 +02:00
|
|
|
* Store his new settings.
|
|
|
|
*
|
2023-12-20 19:35:52 +01:00
|
|
|
* @return Redirector|RedirectResponse
|
2015-06-05 07:10:51 +02:00
|
|
|
*
|
2021-09-18 10:26:12 +02:00
|
|
|
* @throws FireflyException
|
2015-06-01 18:13:54 +02:00
|
|
|
*/
|
2018-04-15 08:52:58 +02:00
|
|
|
public function submit(NewUserFormRequest $request, CurrencyRepositoryInterface $currencyRepository)
|
2015-06-01 18:13:54 +02:00
|
|
|
{
|
2024-01-01 14:43:56 +01:00
|
|
|
$language = $request->convertString('language');
|
2018-04-15 08:52:58 +02:00
|
|
|
if (!array_key_exists($language, config('firefly.languages'))) {
|
|
|
|
$language = 'en_US';
|
|
|
|
}
|
2015-06-01 18:13:54 +02:00
|
|
|
|
2018-04-15 08:52:58 +02:00
|
|
|
// set language preference:
|
2018-07-14 16:08:34 +02:00
|
|
|
app('preferences')->set('language', $language);
|
2018-04-15 08:52:58 +02:00
|
|
|
// Store currency preference from input:
|
2024-12-22 08:43:12 +01:00
|
|
|
$currency = $currencyRepository->find((int) $request->input('amount_currency_id_bank_balance'));
|
2017-11-03 06:58:39 +01:00
|
|
|
|
2018-04-15 08:52:58 +02:00
|
|
|
// if is null, set to EUR:
|
|
|
|
if (null === $currency) {
|
2023-10-28 18:18:12 +02:00
|
|
|
$currency = $currencyRepository->findByCode('EUR');
|
2017-11-03 06:58:39 +01:00
|
|
|
}
|
2018-11-10 10:04:46 +01:00
|
|
|
$currencyRepository->enable($currency);
|
2017-11-03 06:58:39 +01:00
|
|
|
|
2022-03-29 14:58:06 +02:00
|
|
|
$this->createAssetAccount($request, $currency); // create normal asset account
|
2018-07-20 14:34:56 +02:00
|
|
|
$this->createSavingsAccount($request, $currency, $language); // create savings account
|
2022-03-29 14:58:06 +02:00
|
|
|
$this->createCashWalletAccount($currency, $language); // create cash wallet account
|
2018-04-15 08:52:58 +02:00
|
|
|
|
|
|
|
// store currency preference:
|
2023-10-22 07:55:36 +02:00
|
|
|
$currencyRepository->makeDefault($currency);
|
2020-04-14 17:23:58 +02:00
|
|
|
|
|
|
|
// store frontpage preferences:
|
2025-01-03 09:15:52 +01:00
|
|
|
$accounts = $this->repository->getAccountsByType([AccountTypeEnum::ASSET->value])->pluck('id')->toArray();
|
2024-04-01 20:26:02 +02:00
|
|
|
app('preferences')->set('frontpageAccounts', $accounts);
|
2020-04-14 17:23:58 +02:00
|
|
|
|
|
|
|
// mark.
|
2018-07-08 12:08:53 +02:00
|
|
|
app('preferences')->mark();
|
2018-04-15 08:52:58 +02:00
|
|
|
|
2018-02-10 08:21:35 +01:00
|
|
|
// set default optional fields:
|
2022-12-29 19:41:57 +01:00
|
|
|
$visibleFields = [
|
|
|
|
'interest_date' => true,
|
|
|
|
'book_date' => false,
|
|
|
|
'process_date' => false,
|
|
|
|
'due_date' => false,
|
|
|
|
'payment_date' => false,
|
|
|
|
'invoice_date' => false,
|
|
|
|
'internal_reference' => false,
|
|
|
|
'notes' => true,
|
|
|
|
'attachments' => true,
|
|
|
|
];
|
2018-07-14 16:08:34 +02:00
|
|
|
app('preferences')->set('transaction_journal_optional_fields', $visibleFields);
|
2018-02-10 08:21:35 +01:00
|
|
|
|
2024-12-22 08:43:12 +01:00
|
|
|
session()->flash('success', (string) trans('firefly.stored_new_accounts_new_user'));
|
2018-07-08 12:08:53 +02:00
|
|
|
app('preferences')->mark();
|
2015-06-01 18:13:54 +02:00
|
|
|
|
2015-07-06 16:27:21 +02:00
|
|
|
return redirect(route('index'));
|
2015-06-01 18:13:54 +02:00
|
|
|
}
|
2015-06-05 13:39:24 +02:00
|
|
|
}
|