mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Basic tutorial for new users.
This commit is contained in:
@@ -53,6 +53,11 @@ class HomeController extends Controller
|
||||
|
||||
$types = Config::get('firefly.accountTypesByIdentifier.asset');
|
||||
$count = $repository->countAccounts($types);
|
||||
|
||||
if($count == 0) {
|
||||
return Redirect::route('new-user.index');
|
||||
}
|
||||
|
||||
$title = 'Firefly';
|
||||
$subTitle = trans('firefly.welcomeBack');
|
||||
$mainTitleIcon = 'fa-fire';
|
||||
|
119
app/Http/Controllers/NewUserController.php
Normal file
119
app/Http/Controllers/NewUserController.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use Config;
|
||||
use FireflyIII\Http\Requests\NewUserFormRequest;
|
||||
use FireflyIII\Models\AccountMeta;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use Redirect;
|
||||
use Session;
|
||||
use View;
|
||||
|
||||
/**
|
||||
* Class NewUserController
|
||||
*
|
||||
* @package FireflyIII\Http\Controllers
|
||||
*/
|
||||
class NewUserController extends Controller
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param AccountRepositoryInterface $repository
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function index(AccountRepositoryInterface $repository)
|
||||
{
|
||||
View::share('title', 'Welcome to Firefly!');
|
||||
View::share('mainTitleIcon', 'fa-fire');
|
||||
|
||||
|
||||
$types = Config::get('firefly.accountTypesByIdentifier.asset');
|
||||
$count = $repository->countAccounts($types);
|
||||
|
||||
if ($count > 0) {
|
||||
return Redirect::route('index');
|
||||
|
||||
}
|
||||
|
||||
return view('new-user.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param NewUserFormRequest $request
|
||||
* @param AccountRepositoryInterface $repository
|
||||
*/
|
||||
public function submit(NewUserFormRequest $request, AccountRepositoryInterface $repository)
|
||||
{
|
||||
|
||||
// create normal asset account:
|
||||
$assetAccount = [
|
||||
'name' => $request->get('bank_name'),
|
||||
'accountType' => 'asset',
|
||||
'virtualBalance' => 0,
|
||||
'active' => true,
|
||||
'user' => Auth::user()->id,
|
||||
'accountRole' => 'defaultAsset',
|
||||
'openingBalance' => floatval($request->input('bank_balance')),
|
||||
'openingBalanceDate' => new Carbon,
|
||||
'openingBalanceCurrency' => intval($request->input('balance_currency_id')),
|
||||
];
|
||||
|
||||
$repository->store($assetAccount);
|
||||
|
||||
// create savings account
|
||||
if (strlen($request->get('savings_balance') > 0)) {
|
||||
$savingsAccount = [
|
||||
'name' => $request->get('bank_name') . ' savings account',
|
||||
'accountType' => 'asset',
|
||||
'virtualBalance' => 0,
|
||||
'active' => true,
|
||||
'user' => Auth::user()->id,
|
||||
'accountRole' => 'savingAsset',
|
||||
'openingBalance' => floatval($request->input('savings_balance')),
|
||||
'openingBalanceDate' => new Carbon,
|
||||
'openingBalanceCurrency' => intval($request->input('balance_currency_id')),
|
||||
];
|
||||
$repository->store($savingsAccount);
|
||||
}
|
||||
|
||||
|
||||
// create credit card.
|
||||
if (strlen($request->get('credit_card_limit') > 0)) {
|
||||
$creditAccount = [
|
||||
'name' => 'Credit card',
|
||||
'accountType' => 'asset',
|
||||
'virtualBalance' => floatval($request->get('credit_card_limit')),
|
||||
'active' => true,
|
||||
'user' => Auth::user()->id,
|
||||
'accountRole' => 'ccAsset',
|
||||
'openingBalance' => null,
|
||||
'openingBalanceDate' => null,
|
||||
'openingBalanceCurrency' => intval($request->input('balance_currency_id')),
|
||||
];
|
||||
$creditCard = $repository->store($creditAccount);
|
||||
|
||||
// store meta for CC:
|
||||
AccountMeta::create(
|
||||
[
|
||||
'name' => 'ccType',
|
||||
'data' => 'monthlyFull',
|
||||
'account_id' => $creditCard->id,
|
||||
]
|
||||
);
|
||||
AccountMeta::create(
|
||||
[
|
||||
'name' => 'ccMonthlyPaymentDate',
|
||||
'data' => Carbon::now()->year.'-01-01',
|
||||
'account_id' => $creditCard->id,
|
||||
]
|
||||
);
|
||||
|
||||
}
|
||||
Session::flash('success', 'New account(s) created!');
|
||||
|
||||
return Redirect::route('home');
|
||||
}
|
||||
}
|
37
app/Http/Requests/NewUserFormRequest.php
Normal file
37
app/Http/Requests/NewUserFormRequest.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use Auth;
|
||||
|
||||
/**
|
||||
* Class NewUserFormRequest
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Http\Requests
|
||||
*/
|
||||
class NewUserFormRequest extends Request
|
||||
{
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
// Only allow logged in users
|
||||
return Auth::check();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'bank_name' => 'required|between:1,200',
|
||||
'bank_balance' => 'required|numeric',
|
||||
'savings_balance' => 'numeric',
|
||||
'credit_card_limit' => 'numeric',
|
||||
'balance_currency_id' => 'exists:transaction_currencies,id',
|
||||
];
|
||||
}
|
||||
}
|
@@ -317,6 +317,12 @@ Route::group(
|
||||
Route::get('/json/box/bills-paid', ['uses' => 'JsonController@boxBillsPaid', 'as' => 'json.box.unpaid']);
|
||||
Route::get('/json/transaction-journals/{what}', 'JsonController@transactionJournals');
|
||||
|
||||
/**
|
||||
* New user Controller
|
||||
*/
|
||||
Route::get('/new-user', ['uses' => 'NewUserController@index', 'as' => 'new-user.index']);
|
||||
Route::post('/new-user/submit', ['uses' => 'NewUserController@submit', 'as' => 'new-user.submit']);
|
||||
|
||||
/**
|
||||
* Piggy Bank Controller
|
||||
*/
|
||||
|
@@ -308,6 +308,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
if ($journal->destination_account->id == $account->id) {
|
||||
return $journal;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
);
|
||||
@@ -364,7 +365,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
$opposingData = [
|
||||
'user' => $data['user'],
|
||||
'accountType' => $type,
|
||||
'virtual_balance' => $data['virtualBalance'],
|
||||
'virtualBalance' => 0,
|
||||
'name' => $data['name'] . ' initial balance',
|
||||
'active' => false,
|
||||
];
|
||||
@@ -445,6 +446,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
'user_id' => $data['user'],
|
||||
'account_type_id' => $accountType->id,
|
||||
'name' => $data['name'],
|
||||
'virtual_balance' => $data['virtualBalance'],
|
||||
'active' => $data['active'] === true ? true : false,
|
||||
]
|
||||
);
|
||||
@@ -454,6 +456,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
$searchData = [
|
||||
'user_id' => $data['user'],
|
||||
'account_type_id' => $accountType->id,
|
||||
'virtual_balance' => $data['virtualBalance'],
|
||||
'name' => $data['name']
|
||||
];
|
||||
$existingAccount = Account::firstOrNullEncrypted($searchData);
|
||||
|
@@ -18,6 +18,13 @@ return [
|
||||
'showEverything' => 'Show everything',
|
||||
'never' => 'Never',
|
||||
|
||||
// new user:
|
||||
'submit' => 'Submit',
|
||||
'getting_started' => 'Getting started',
|
||||
'to_get_started' => 'To get started with Firefly, please enter your current bank\'s name, and the balance of your checking account:',
|
||||
'savings_balance_text' => 'If you have a savings account, please enter the current balance of your savings account:',
|
||||
'cc_balance_text' => 'If you have a credit card, please enter your credit card\'s limit.',
|
||||
|
||||
// forms:
|
||||
'mandatoryFields' => 'Mandatory fields',
|
||||
'optionalFields' => 'Optional fields',
|
||||
|
@@ -1,5 +1,12 @@
|
||||
<?php
|
||||
return [
|
||||
|
||||
// new user:
|
||||
'bank_name' => 'Bank name',
|
||||
'bank_balance' => 'Balance',
|
||||
'savings_balance' => 'Savings balance',
|
||||
'credit_card_limit' => 'Credit card limit',
|
||||
|
||||
'name' => 'Name',
|
||||
'active' => 'Active',
|
||||
'amount_min' => 'Minimum amount',
|
||||
|
@@ -18,6 +18,13 @@ return [
|
||||
'showEverything' => 'Laat alles zien',
|
||||
'never' => 'Nooit',
|
||||
|
||||
// new user:
|
||||
'submit' => 'Invoeren',
|
||||
'getting_started' => 'Aan de start!',
|
||||
'to_get_started' => 'Begin met de naam van de bank waar je je betaalrekening hebt, en het saldo van die rekening.',
|
||||
'savings_balance_text' => 'Voer ook het saldo van je spaarrekening in, als je die hebt.',
|
||||
'cc_balance_text' => 'Als je een credit card hebt, vul dan hier je credit cardlimiet in.',
|
||||
|
||||
// forms:
|
||||
'mandatoryFields' => 'Verplichte velden',
|
||||
'optionalFields' => 'Optionele velden',
|
||||
|
@@ -1,5 +1,12 @@
|
||||
<?php
|
||||
return [
|
||||
|
||||
// new user:
|
||||
'bank_name' => 'Banknaam',
|
||||
'bank_balance' => 'Saldo',
|
||||
'savings_balance' => 'Saldo van spaarrekening',
|
||||
'credit_card_limit' => 'Credit card limiet',
|
||||
|
||||
'name' => 'Naam',
|
||||
'active' => 'Actief',
|
||||
'amount_min' => 'Minimumbedrag',
|
||||
|
@@ -2,24 +2,6 @@
|
||||
{% block content %}
|
||||
{{ Breadcrumbs.renderIfExists }}
|
||||
|
||||
{% if count == 0 %}
|
||||
<div class="row">
|
||||
<div class="col-lg-12 col-md-12 col-sm-12">
|
||||
<p class="lead">{{ 'welcome'|_ }}</p>
|
||||
|
||||
<p>
|
||||
{{ 'createNewAsset'|_ }}
|
||||
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-lg-6 col-md-6 col-sm-12">
|
||||
<h2><a href="{{route('accounts.create','asset')}}">{{ 'createNewAssetButton'|_ }}</a></h2>
|
||||
</div>
|
||||
{% else %}
|
||||
<!-- Language test: {{ 'test'|_ }} -->
|
||||
<!-- fancy new boxes -->
|
||||
{% include 'partials/boxes.twig' %}
|
||||
|
||||
<div class="row">
|
||||
@@ -200,8 +182,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endif %}
|
||||
|
||||
|
||||
{% endblock %}
|
||||
{% block scripts %}
|
||||
|
45
resources/twig/new-user/index.twig
Normal file
45
resources/twig/new-user/index.twig
Normal file
@@ -0,0 +1,45 @@
|
||||
{% extends "./layout/default.twig" %}
|
||||
{% block content %}
|
||||
{{ Breadcrumbs.renderIfExists }}
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-6 col-sm-8 col-xs-12">
|
||||
<h3>{{ 'getting_started'|_ }}</h3>
|
||||
<p>
|
||||
{{ 'to_get_started'|_ }}
|
||||
</p>
|
||||
<form action="{{ route('new-user.submit') }}" method="post" id="store" class="form-horizontal">
|
||||
<input type="hidden" name="_token" value="{{ csrf_token() }}" />
|
||||
|
||||
{{ ExpandedForm.text('bank_name')}}
|
||||
{{ ExpandedForm.balance('bank_balance')}}
|
||||
|
||||
<p>
|
||||
{{ 'savings_balance_text'|_ }}
|
||||
</p>
|
||||
|
||||
{{ ExpandedForm.balance('savings_balance') }}
|
||||
|
||||
<p>
|
||||
{{ 'cc_balance_text'|_ }}
|
||||
|
||||
</p>
|
||||
|
||||
{{ ExpandedForm.balance('credit_card_limit') }}
|
||||
|
||||
<p>
|
||||
<input type="submit" name="submit" value="{{ 'submit'|_ }}" class="bt btn-success btn-lg" />
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
{% block scripts %}
|
||||
<!-- load the libraries and scripts necessary for Google Charts: -->
|
||||
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
|
||||
<script type="text/javascript" src="js/gcharts.options.js"></script>
|
||||
<script type="text/javascript" src="js/gcharts.js"></script>
|
||||
<script type="text/javascript" src="js/index.js"></script>
|
||||
{% endblock %}
|
Reference in New Issue
Block a user