mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-16 09:22:33 +00:00
Compare commits
142 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
9bdfecbfdc | ||
|
f85e4a24e5 | ||
|
0dda87c78e | ||
|
2fc09ff9d7 | ||
|
e4e0e21293 | ||
|
15089f0d7e | ||
|
7232c1d7bb | ||
|
9a53d8c21c | ||
|
0d198193db | ||
|
45bc23b8af | ||
|
3323c31765 | ||
|
bb7c26b77c | ||
|
9101d6a2c0 | ||
|
ad2b254be0 | ||
|
abc4f856ce | ||
|
b3b66a8f92 | ||
|
2f7cf9b916 | ||
|
b822e0c6e7 | ||
|
6fef9ee72b | ||
|
ab6dd0a1ec | ||
|
9deef5ac92 | ||
|
577187babe | ||
|
577290e813 | ||
|
f3b9798216 | ||
|
4dcaa96d16 | ||
|
0dcbf451d6 | ||
|
e87f6ca40e | ||
|
1f34e33d8c | ||
|
258e87e127 | ||
|
3ec8efcfc1 | ||
|
70ea227bd0 | ||
|
27c832ed58 | ||
|
a31b4ccf01 | ||
|
d221ea68d0 | ||
|
dc9fe58536 | ||
|
f871e29bdb | ||
|
1357352276 | ||
|
e169754693 | ||
|
1cfe4f40ba | ||
|
5545d1c1ba | ||
|
e5f7228fa9 | ||
|
11385494eb | ||
|
ae328de469 | ||
|
0574a706c8 | ||
|
70bb85a75b | ||
|
8cd901b57b | ||
|
8b9818c48e | ||
|
a95099fa46 | ||
|
221e4b7fc0 | ||
|
6cff3eb61e | ||
|
e4fd97ae77 | ||
|
5ca9099654 | ||
|
6e33e26ddf | ||
|
04461a4ab8 | ||
|
a4b9bbff54 | ||
|
4ad4252a77 | ||
|
aac0c9ab98 | ||
|
c123e1044a | ||
|
d25d0454fc | ||
|
f38984398d | ||
|
a07799cfa4 | ||
|
7c52f297ee | ||
|
50a3279b30 | ||
|
0ea14eb987 | ||
|
cf1b98e569 | ||
|
63fb435002 | ||
|
2f8263f53a | ||
|
fb649779d6 | ||
|
bb58f605f7 | ||
|
fccdf56c5d | ||
|
bd53410c71 | ||
|
7d63f124c4 | ||
|
9ffc5d857c | ||
|
2f93784acd | ||
|
d00fbe4eb3 | ||
|
51d9f041ae | ||
|
b872ab8b86 | ||
|
3d25fd79ca | ||
|
3aad78e6ef | ||
|
7d5bb72b0c | ||
|
46e5aae8bb | ||
|
b9e2ee7af3 | ||
|
c1a2892788 | ||
|
2078183e0d | ||
|
fab1d53714 | ||
|
3fe831c7d8 | ||
|
6958f71cfd | ||
|
a7351f348d | ||
|
5379e03447 | ||
|
539058e32d | ||
|
11b6b5a63c | ||
|
1155096226 | ||
|
2920dd356e | ||
|
9c3dac8170 | ||
|
49f9909b15 | ||
|
e4fef6dfc3 | ||
|
2da087401e | ||
|
629baf9de5 | ||
|
29a930dae5 | ||
|
d920537dd2 | ||
|
106b04a5da | ||
|
176752e219 | ||
|
8d19f60091 | ||
|
e937aa2f74 | ||
|
c3ccc4ccdf | ||
|
6c5cd705c0 | ||
|
ce003f217b | ||
|
8c7ef49eb6 | ||
|
29af4bd1b9 | ||
|
2ce5142b06 | ||
|
f3a8a25872 | ||
|
598e97d028 | ||
|
fa110279de | ||
|
8fdeaf73cc | ||
|
a7ffdf062a | ||
|
3bad92dd6d | ||
|
2e88024bca | ||
|
ca2301959c | ||
|
3285fae7f0 | ||
|
312079657b | ||
|
18c183afd6 | ||
|
f424d9cf20 | ||
|
5c3da9fd9e | ||
|
1f321fadd4 | ||
|
65f5d27b12 | ||
|
cdb591de7f | ||
|
a0ea3882e1 | ||
|
a9444ac702 | ||
|
d0c6afc3a9 | ||
|
e7a0a5937c | ||
|
08992b5298 | ||
|
6490a4240d | ||
|
43a7544dd7 | ||
|
0fe70dae17 | ||
|
7079e76886 | ||
|
0ec021c375 | ||
|
ff3396e286 | ||
|
78912903ce | ||
|
4c015e2d12 | ||
|
172634a55a | ||
|
58ca7d551a | ||
|
fd8ed4c9aa |
21
.env.example
21
.env.example
@@ -1,15 +1,19 @@
|
||||
APP_ENV=production
|
||||
APP_DEBUG=false
|
||||
APP_FORCE_SSL=false
|
||||
APP_FORCE_ROOT=
|
||||
APP_KEY=SomeRandomStringOf32CharsExactly
|
||||
LOG_LEVEL=warning
|
||||
APP_LOG_LEVEL=warning
|
||||
APP_URL=http://localhost
|
||||
|
||||
DB_CONNECTION=mysql
|
||||
DB_HOST=localhost
|
||||
DB_HOST=127.0.0.1
|
||||
DB_PORT=3306
|
||||
DB_DATABASE=homestead
|
||||
DB_USERNAME=homestead
|
||||
DB_PASSWORD=secret
|
||||
|
||||
BROADCAST_DRIVER=log
|
||||
CACHE_DRIVER=file
|
||||
SESSION_DRIVER=file
|
||||
QUEUE_DRIVER=sync
|
||||
@@ -18,17 +22,14 @@ COOKIE_PATH="/"
|
||||
COOKIE_DOMAIN=
|
||||
COOKIE_SECURE=false
|
||||
|
||||
DEFAULT_CURRENCY=EUR
|
||||
DEFAULT_LANGUAGE=en_US
|
||||
|
||||
REDIS_HOST=localhost
|
||||
REDIS_HOST=127.0.0.1
|
||||
REDIS_PASSWORD=null
|
||||
REDIS_PORT=6379
|
||||
|
||||
MAIL_DRIVER=smtp
|
||||
MAIL_HOST=mailtrap.io
|
||||
MAIL_PORT=2525
|
||||
MAIL_FROM=enter_your_email_here
|
||||
MAIL_FROM=changeme@example.com
|
||||
MAIL_USERNAME=null
|
||||
MAIL_PASSWORD=null
|
||||
MAIL_ENCRYPTION=null
|
||||
@@ -37,8 +38,10 @@ SEND_REGISTRATION_MAIL=true
|
||||
MUST_CONFIRM_ACCOUNT=false
|
||||
|
||||
SHOW_INCOMPLETE_TRANSLATIONS=false
|
||||
SHOW_DEMO_WARNING=false
|
||||
|
||||
ANALYTICS_ID=
|
||||
RUNCLEANUP=true
|
||||
SITE_OWNER=mail@example.com
|
||||
|
||||
PUSHER_KEY=
|
||||
PUSHER_SECRET=
|
||||
PUSHER_APP_ID=
|
||||
|
38
.env.testing
38
.env.testing
@@ -1,38 +0,0 @@
|
||||
APP_ENV=testing
|
||||
APP_DEBUG=true
|
||||
APP_FORCE_SSL=false
|
||||
APP_KEY=SomeRandomStringOf32CharsExactly
|
||||
LOG_LEVEL=debug
|
||||
|
||||
DB_CONNECTION=sqlite
|
||||
DB_HOST=localhost
|
||||
DB_DATABASE=homestead
|
||||
DB_USERNAME=homestead
|
||||
DB_PASSWORD=secret
|
||||
|
||||
CACHE_DRIVER=array
|
||||
SESSION_DRIVER=array
|
||||
QUEUE_DRIVER=array
|
||||
|
||||
DEFAULT_CURRENCY=EUR
|
||||
DEFAULT_LANGUAGE=en_US
|
||||
|
||||
REDIS_HOST=localhost
|
||||
REDIS_PASSWORD=null
|
||||
REDIS_PORT=6379
|
||||
|
||||
MAIL_DRIVER=log
|
||||
MAIL_HOST=mailtrap.io
|
||||
MAIL_PORT=2525
|
||||
MAIL_FROM=your_address_here@example.com
|
||||
MAIL_USERNAME=null
|
||||
MAIL_PASSWORD=null
|
||||
MAIL_ENCRYPTION=null
|
||||
|
||||
SHOW_INCOMPLETE_TRANSLATIONS=false
|
||||
|
||||
ANALYTICS_ID=abcde
|
||||
RUNCLEANUP=false
|
||||
SITE_OWNER=your_address_here@example.com
|
||||
|
||||
BLOCKED_DOMAINS=
|
2
.gitattributes
vendored
2
.gitattributes
vendored
@@ -1,3 +1,3 @@
|
||||
* text=auto
|
||||
*.css linguist-vendored
|
||||
*.less linguist-vendored
|
||||
*.scss linguist-vendored
|
||||
|
7
.gitignore
vendored
Normal file → Executable file
7
.gitignore
vendored
Normal file → Executable file
@@ -1,8 +1,13 @@
|
||||
/vendor
|
||||
/node_modules
|
||||
/public/storage
|
||||
/vendor
|
||||
/.idea
|
||||
Homestead.json
|
||||
Homestead.yaml
|
||||
.env
|
||||
_development
|
||||
.env.local
|
||||
result.html
|
||||
test-import.sh
|
||||
test-import-report.txt
|
||||
public/google*.html
|
||||
|
@@ -5,3 +5,4 @@ filter:
|
||||
excluded_paths:
|
||||
- app/Support/Migration/*
|
||||
- app/database/migrations/*
|
||||
- database/migrations/*
|
||||
|
71
CHANGELOG.md
71
CHANGELOG.md
@@ -2,8 +2,64 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## [Unreleased]
|
||||
- No unreleased changes yet.
|
||||
## [4.0.0] - 2015-05-25
|
||||
### Added
|
||||
- Upgraded to Laravel 5.3, most other libraries upgraded as well.
|
||||
- Added GBP as currency, thanks to @Mortalife
|
||||
|
||||
### Changed
|
||||
- Jump to version 4.0.0.
|
||||
- Firefly III is now subject to a [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/) license. Previous versions of this software are still MIT licensed.
|
||||
|
||||
### Fixed
|
||||
- Support for specific decimal places, thanks to @Mortalife
|
||||
- Various CSS fixes
|
||||
- Various bugs, thanks to @fuf, @sandermulders and @vissert
|
||||
- Various queries optimized for MySQL 5.7
|
||||
|
||||
## [3.10.4] - 2015-09-14
|
||||
### Fixed
|
||||
- Migration fix by @sandermulders
|
||||
- Tricky import bug fix thanks to @vissert
|
||||
- Currency preference will be correctly pulled from user settings, thanks to @fuf
|
||||
- Simplified code for upgrade instructions.
|
||||
|
||||
|
||||
## [3.10.3] - 2016-08-29
|
||||
### Added
|
||||
- More fields for mass-edit, thanks to @Vissert (#282)
|
||||
- First start of German translation
|
||||
|
||||
### Changed
|
||||
- More optional fields for transactions and the ability to filter them.
|
||||
|
||||
### Removed
|
||||
- Preference for budget maximum.
|
||||
|
||||
### Fixed
|
||||
- A bug in the translation routine broke the import.
|
||||
- It was possible to destroy your Firefly installation by removing all currencies. Thanks @mondjef
|
||||
- Translation bugs.
|
||||
- Import bug.
|
||||
|
||||
### Security
|
||||
- Firefly will not accept registrations beyond the first one, by default.
|
||||
|
||||
|
||||
## [3.10.2] - 2016-08-29
|
||||
### Added
|
||||
- New Chinese translations. Set Firefly III to show incomplete translations to follow the progress. Want to translate Firefly III in Chinese, or in any other language? Then check out [the Crowdin project](https://crowdin.com/project/firefly-iii).
|
||||
- Added more admin pages. They do nothing yet.
|
||||
|
||||
### Changed
|
||||
- Import routine will now also apply user rules.
|
||||
- Various code cleanup.
|
||||
- Some small HTML changes.
|
||||
|
||||
### Fixed
|
||||
- Bug in the mass edit routines.
|
||||
- Firefly III over a proxy will now work (see [issue #290](https://github.com/JC5/firefly-iii/issues/290)), thanks @dfiel for reporting.
|
||||
- Sneaky bug in the import routine, fixed by @Bonno
|
||||
|
||||
## [3.10.1] - 2016-08-25
|
||||
### Added
|
||||
@@ -38,13 +94,6 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
- The date picker now supports more ranges and periods.
|
||||
- Rewrote all migrations. #272
|
||||
|
||||
|
||||
### Deprecated
|
||||
- Initial release.
|
||||
|
||||
### Removed
|
||||
- Initial release.
|
||||
|
||||
### Fixed
|
||||
- Issue #264
|
||||
- Issue #265
|
||||
@@ -59,10 +108,6 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
- Bulk update problems, #280, thanks @stickgrinder
|
||||
- Fixed various problems with amount reporting of split transactions.
|
||||
|
||||
### Security
|
||||
- Initial release.
|
||||
|
||||
|
||||
[3.9.1]
|
||||
### Fixed
|
||||
- Fixed a bug where removing money from a piggy bank would not work. See issue #265 and #269
|
||||
|
4
LICENSE
4
LICENSE
@@ -1,7 +1,7 @@
|
||||
Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
https://creativecommons.org/licenses/by-sa/4.0/
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
@@ -22,24 +22,40 @@ use Illuminate\Log\Writer;
|
||||
*/
|
||||
class ConfigureLogging extends IlluminateConfigureLogging
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Application $app
|
||||
* @param Writer $log
|
||||
* Configure the Monolog handlers for the application.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Foundation\Application $app
|
||||
* @param \Illuminate\Log\Writer $log
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function configureDailyHandler(Application $app, Writer $log)
|
||||
{
|
||||
$config = $app->make('config');
|
||||
|
||||
$maxFiles = $config->get('app.log_max_files');
|
||||
|
||||
$log->useDailyFiles(
|
||||
$app->storagePath() . '/logs/firefly-iii.log',
|
||||
$app->make('config')->get('app.log_max_files', 5)
|
||||
$app->storagePath() . '/logs/firefly-iii.log', is_null($maxFiles) ? 5 : $maxFiles,
|
||||
$config->get('app.log_level', 'debug')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Application $app
|
||||
* @param Writer $log
|
||||
* Configure the Monolog handlers for the application.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Foundation\Application $app
|
||||
* @param \Illuminate\Log\Writer $log
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function configureSingleHandler(Application $app, Writer $log)
|
||||
{
|
||||
$log->useFiles($app->storagePath() . '/logs/firefly-iii.log');
|
||||
$log->useFiles(
|
||||
$app->storagePath() . '/logs/firefly-iii.log',
|
||||
$app->make('config')->get('app.log_level', 'debug')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -46,8 +46,6 @@ class EncryptFile extends Command
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
@@ -64,6 +62,5 @@ class EncryptFile extends Command
|
||||
$path = storage_path('upload') . '/' . $newName;
|
||||
file_put_contents($path, $content);
|
||||
$this->line(sprintf('Encrypted "%s" and put it in "%s"', $file, $path));
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -12,9 +12,9 @@ declare(strict_types = 1);
|
||||
namespace FireflyIII\Console\Commands;
|
||||
|
||||
use FireflyIII\Import\ImportProcedure;
|
||||
use FireflyIII\Import\ImportResult;
|
||||
use FireflyIII\Import\Logging\CommandHandler;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use Illuminate\Console\Command;
|
||||
use Log;
|
||||
|
||||
@@ -67,24 +67,33 @@ class Import extends Command
|
||||
$handler = new CommandHandler($this);
|
||||
$monolog->pushHandler($handler);
|
||||
|
||||
$result = ImportProcedure::run($job);
|
||||
$result = ImportProcedure::runImport($job);
|
||||
|
||||
|
||||
/**
|
||||
* @var int $index
|
||||
* @var ImportResult $entry
|
||||
* @var int $index
|
||||
* @var TransactionJournal $journal
|
||||
*/
|
||||
foreach ($result as $index => $entry) {
|
||||
if ($entry->isSuccess()) {
|
||||
$this->line(sprintf('Line #%d has been imported as transaction #%d.', $index, $entry->journal->id));
|
||||
foreach ($result as $index => $journal) {
|
||||
if (!is_null($journal->id)) {
|
||||
$this->line(sprintf('Line #%d has been imported as transaction #%d.', $index, $journal->id));
|
||||
continue;
|
||||
}
|
||||
$errors = join(', ', $entry->errors->all());
|
||||
$this->error(sprintf('Could not store line #%d, because: %s', $index, $errors));
|
||||
$this->error(sprintf('Could not store line #%d', $index));
|
||||
}
|
||||
|
||||
|
||||
$this->line('The import has completed.');
|
||||
|
||||
// get any errors from the importer:
|
||||
$extendedStatus = $job->extended_status;
|
||||
if (isset($extendedStatus['errors']) && count($extendedStatus['errors']) > 0) {
|
||||
$this->line(sprintf('The following %d error(s) occured during the import:', count($extendedStatus['errors'])));
|
||||
foreach ($extendedStatus['errors'] as $error) {
|
||||
$this->error($error);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
|
99
app/Console/Commands/ScanAttachments.php
Normal file
99
app/Console/Commands/ScanAttachments.php
Normal file
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
/**
|
||||
* ScanAttachments.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Console\Commands;
|
||||
|
||||
use Crypt;
|
||||
use FireflyIII\Models\Attachment;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Contracts\Encryption\DecryptException;
|
||||
use Illuminate\Contracts\Filesystem\FileNotFoundException;
|
||||
use Storage;
|
||||
|
||||
/**
|
||||
* Class ScanAttachments
|
||||
*
|
||||
* @package FireflyIII\Console\Commands
|
||||
*/
|
||||
class ScanAttachments extends Command
|
||||
{
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Rescan all attachments and re-set the MD5 hash and mime.';
|
||||
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'firefly:scan-attachments';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$attachments = Attachment::get();
|
||||
$disk = Storage::disk('upload');
|
||||
/** @var Attachment $attachment */
|
||||
foreach ($attachments as $attachment) {
|
||||
$fileName = $attachment->fileName();
|
||||
|
||||
// try to grab file content:
|
||||
try {
|
||||
$content = $disk->get($fileName);
|
||||
} catch (FileNotFoundException $e) {
|
||||
$this->error(sprintf('Could not find data for attachment #%d', $attachment->id));
|
||||
continue;
|
||||
}
|
||||
// try to decrypt content.
|
||||
try {
|
||||
$decrypted = Crypt::decrypt($content);
|
||||
} catch (DecryptException $e) {
|
||||
$this->error(sprintf('Could not decrypt data of attachment #%d', $attachment->id));
|
||||
continue;
|
||||
}
|
||||
|
||||
// make temp file:
|
||||
$tmpfname = tempnam(sys_get_temp_dir(), 'FireflyIII');
|
||||
|
||||
// store content in temp file:
|
||||
file_put_contents($tmpfname, $decrypted);
|
||||
|
||||
// get md5 and mime
|
||||
$md5 = md5_file($tmpfname);
|
||||
$mime = mime_content_type($tmpfname);
|
||||
|
||||
// update attachment:
|
||||
$attachment->md5 = $md5;
|
||||
$attachment->mime = $mime;
|
||||
$attachment->save();
|
||||
|
||||
|
||||
$this->line(sprintf('Fixed attachment #%d', $attachment->id));
|
||||
|
||||
// find file:
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@@ -44,8 +44,6 @@ class UpgradeFireflyInstructions extends Command
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
@@ -53,15 +51,22 @@ class UpgradeFireflyInstructions extends Command
|
||||
/** @var string $version */
|
||||
$version = config('firefly.version');
|
||||
$config = config('upgrade.text');
|
||||
$text = $config[$version] ?? null;
|
||||
$text = null;
|
||||
foreach (array_keys($config) as $compare) {
|
||||
// if string starts with:
|
||||
$len = strlen($compare);
|
||||
if (substr($version, 0, $len) === $compare) {
|
||||
$text = $config[$compare];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$this->line('+------------------------------------------------------------------------------+');
|
||||
$this->line('');
|
||||
|
||||
if (is_null($text)) {
|
||||
$this->line('Thank you for installing Firefly III, v' . $version);
|
||||
$this->line('If you are upgrading from a previous version,');
|
||||
$this->info('there are no extra upgrade instructions.');
|
||||
$this->info('There are no extra upgrade instructions.');
|
||||
$this->line('Firefly III should be ready for use.');
|
||||
} else {
|
||||
$this->line('Thank you for installing Firefly III, v' . $version);
|
||||
|
@@ -12,13 +12,13 @@ declare(strict_types = 1);
|
||||
namespace FireflyIII\Console\Commands;
|
||||
|
||||
use Crypt;
|
||||
use DB;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Models\Category;
|
||||
use FireflyIII\Models\Tag;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Console\Command;
|
||||
@@ -55,8 +55,6 @@ class VerifyDatabase extends Command
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
@@ -81,6 +79,9 @@ class VerifyDatabase extends Command
|
||||
|
||||
// report on journals with no transactions at all.
|
||||
$this->reportNoTransactions();
|
||||
|
||||
// transfers with budgets.
|
||||
$this->reportTransfersBudgets();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,11 +92,10 @@ class VerifyDatabase extends Command
|
||||
$set = Account
|
||||
::leftJoin('transactions', 'transactions.account_id', '=', 'accounts.id')
|
||||
->leftJoin('users', 'accounts.user_id', '=', 'users.id')
|
||||
->groupBy('accounts.id')
|
||||
->having('transaction_count', '=', 0)
|
||||
->groupBy(['accounts.id', 'accounts.encrypted', 'accounts.name', 'accounts.user_id', 'users.email'])
|
||||
->whereNull('transactions.account_id')
|
||||
->get(
|
||||
['accounts.id', 'accounts.encrypted', 'accounts.name', 'accounts.user_id', 'users.email',
|
||||
DB::raw('COUNT(`transactions`.`id`) AS `transaction_count`')]
|
||||
['accounts.id', 'accounts.encrypted', 'accounts.name', 'accounts.user_id', 'users.email']
|
||||
);
|
||||
|
||||
/** @var stdClass $entry */
|
||||
@@ -115,9 +115,9 @@ class VerifyDatabase extends Command
|
||||
$set = Budget
|
||||
::leftJoin('budget_limits', 'budget_limits.budget_id', '=', 'budgets.id')
|
||||
->leftJoin('users', 'budgets.user_id', '=', 'users.id')
|
||||
->groupBy('budgets.id')
|
||||
->having('budget_limit_count', '=', 0)
|
||||
->get(['budgets.id', 'budgets.name', 'budgets.user_id', 'users.email', DB::raw('COUNT(`budget_limits`.`id`) AS `budget_limit_count`')]);
|
||||
->groupBy(['budgets.id', 'budgets.name', 'budgets.user_id', 'users.email'])
|
||||
->whereNull('budget_limits.id')
|
||||
->get(['budgets.id', 'budgets.name', 'budgets.user_id', 'users.email']);
|
||||
|
||||
/** @var stdClass $entry */
|
||||
foreach ($set as $entry) {
|
||||
@@ -227,19 +227,16 @@ class VerifyDatabase extends Command
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function reportNoTransactions()
|
||||
{
|
||||
/*
|
||||
* select transaction_journals.id, count(transactions.id) as transaction_count from transaction_journals
|
||||
left join transactions ON transaction_journals.id = transactions.transaction_journal_id
|
||||
group by transaction_journals.id
|
||||
having transaction_count = 0
|
||||
*/
|
||||
$set = TransactionJournal
|
||||
::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->groupBy('transaction_journals.id')
|
||||
->having('transaction_count', '=', 0)
|
||||
->get(['transaction_journals.id', DB::raw('COUNT(`transactions`.`id`) as `transaction_count`')]);
|
||||
->whereNull('transactions.transaction_journal_id')
|
||||
->get(['transaction_journals.id']);
|
||||
|
||||
foreach ($set as $entry) {
|
||||
$this->error(
|
||||
@@ -308,4 +305,29 @@ having transaction_count = 0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function reportTransfersBudgets()
|
||||
{
|
||||
$set = TransactionJournal
|
||||
::distinct()
|
||||
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
|
||||
->leftJoin('budget_transaction_journal', 'transaction_journals.id', '=', 'budget_transaction_journal.transaction_journal_id')
|
||||
->where('transaction_types.type', TransactionType::TRANSFER)
|
||||
->whereNotNull('budget_transaction_journal.budget_id')->get(['transaction_journals.id']);
|
||||
|
||||
/** @var TransactionJournal $entry */
|
||||
foreach ($set as $entry) {
|
||||
$this->error(
|
||||
sprintf(
|
||||
'Error: Transaction journal #%d is a transfer, but has a budget. Edit it without changing anything, so the budget will be removed.',
|
||||
$entry->id
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
28
app/Console/Kernel.php
Normal file → Executable file
28
app/Console/Kernel.php
Normal file → Executable file
@@ -13,8 +13,10 @@ namespace FireflyIII\Console;
|
||||
|
||||
use FireflyIII\Console\Commands\EncryptFile;
|
||||
use FireflyIII\Console\Commands\Import;
|
||||
use FireflyIII\Console\Commands\ScanAttachments;
|
||||
use FireflyIII\Console\Commands\UpgradeFireflyInstructions;
|
||||
use FireflyIII\Console\Commands\VerifyDatabase;
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
|
||||
/**
|
||||
@@ -24,11 +26,10 @@ use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
*/
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
|
||||
/**
|
||||
* The bootstrap classes for the application.
|
||||
*
|
||||
* This needs to be for with the next upgrade.
|
||||
* Next upgrade verify these are the same.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
@@ -55,5 +56,28 @@ class Kernel extends ConsoleKernel
|
||||
VerifyDatabase::class,
|
||||
Import::class,
|
||||
EncryptFile::class,
|
||||
ScanAttachments::class,
|
||||
|
||||
];
|
||||
|
||||
/**
|
||||
* Register the Closure based commands for the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function commands()
|
||||
{
|
||||
require base_path('routes/console.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the application's command schedule.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@@ -148,16 +148,20 @@ class AccountCrud implements AccountCrudInterface
|
||||
if (count($types) > 0) {
|
||||
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
|
||||
$query->whereIn('account_types.type', $types);
|
||||
|
||||
}
|
||||
Log::debug(sprintf('Searching for account named %s of the following type(s)', $name), ['types' => $types]);
|
||||
|
||||
$accounts = $query->get(['accounts.*']);
|
||||
/** @var Account $account */
|
||||
foreach ($accounts as $account) {
|
||||
if ($account->name === $name) {
|
||||
Log::debug(sprintf('Found #%d (%s) with type id %d', $account->id, $account->name, $account->account_type_id));
|
||||
|
||||
return $account;
|
||||
}
|
||||
}
|
||||
Log::debug('Found nothing.');
|
||||
|
||||
return new Account;
|
||||
}
|
||||
|
33
app/Exceptions/Handler.php
Normal file → Executable file
33
app/Exceptions/Handler.php
Normal file → Executable file
@@ -10,14 +10,15 @@
|
||||
declare(strict_types = 1);
|
||||
namespace FireflyIII\Exceptions;
|
||||
|
||||
use Auth;
|
||||
use ErrorException;
|
||||
use Exception;
|
||||
use FireflyIII\Jobs\MailError;
|
||||
use Illuminate\Auth\Access\AuthorizationException;
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Request;
|
||||
use Illuminate\Session\TokenMismatchException;
|
||||
use Illuminate\Validation\ValidationException as ValException;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
|
||||
/**
|
||||
@@ -34,9 +35,12 @@ class Handler extends ExceptionHandler
|
||||
*/
|
||||
protected $dontReport
|
||||
= [
|
||||
AuthenticationException::class,
|
||||
AuthorizationException::class,
|
||||
HttpException::class,
|
||||
ModelNotFoundException::class,
|
||||
TokenMismatchException::class,
|
||||
ValException::class,
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -71,15 +75,14 @@ class Handler extends ExceptionHandler
|
||||
*/
|
||||
public function report(Exception $exception)
|
||||
{
|
||||
|
||||
if ($exception instanceof FireflyException || $exception instanceof ErrorException) {
|
||||
$userData = [
|
||||
'id' => 0,
|
||||
'email' => 'unknown@example.com',
|
||||
];
|
||||
if (Auth::check()) {
|
||||
$userData['id'] = Auth::user()->id;
|
||||
$userData['email'] = Auth::user()->email;
|
||||
if (auth()->check()) {
|
||||
$userData['id'] = auth()->user()->id;
|
||||
$userData['email'] = auth()->user()->email;
|
||||
}
|
||||
$data = [
|
||||
'class' => get_class($exception),
|
||||
@@ -92,10 +95,26 @@ class Handler extends ExceptionHandler
|
||||
];
|
||||
|
||||
// create job that will mail.
|
||||
$job = new MailError($userData, env('SITE_OWNER'), Request::ip(), $data);
|
||||
$ip = $_SERVER['REMOTE_ADDR'] ?? '0.0.0.0';
|
||||
$job = new MailError($userData, env('SITE_OWNER', ''), $ip, $data);
|
||||
dispatch($job);
|
||||
}
|
||||
|
||||
parent::report($exception);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an authentication exception into an unauthenticated response.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
protected function unauthenticated($request)
|
||||
{
|
||||
if ($request->expectsJson()) {
|
||||
return response()->json(['error' => 'Unauthenticated.'], 401);
|
||||
}
|
||||
|
||||
return redirect()->guest('login');
|
||||
}
|
||||
}
|
||||
|
@@ -92,6 +92,7 @@ class AttachmentCollector extends BasicCollector implements CollectorInterface
|
||||
'amount' => Amount::formatJournal($journal, false),
|
||||
];
|
||||
$string = trans('firefly.attachment_explanation', $args) . "\n";
|
||||
Log::debug('Appended explanation string', ['string' => $string]);
|
||||
$this->explanationString .= $string;
|
||||
|
||||
}
|
||||
|
@@ -11,7 +11,6 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Export\Collector;
|
||||
|
||||
use Auth;
|
||||
use Crypt;
|
||||
use FireflyIII\Models\ExportJob;
|
||||
use Illuminate\Contracts\Encryption\DecryptException;
|
||||
@@ -29,6 +28,7 @@ class UploadCollector extends BasicCollector implements CollectorInterface
|
||||
private $expected;
|
||||
/** @var \Illuminate\Contracts\Filesystem\Filesystem */
|
||||
private $exportDisk;
|
||||
private $importKeys = [];
|
||||
/** @var \Illuminate\Contracts\Filesystem\Filesystem */
|
||||
private $uploadDisk;
|
||||
|
||||
@@ -42,10 +42,17 @@ class UploadCollector extends BasicCollector implements CollectorInterface
|
||||
{
|
||||
parent::__construct($job);
|
||||
|
||||
Log::debug('Going to collect attachments', ['key' => $job->key]);
|
||||
|
||||
// make storage:
|
||||
$this->uploadDisk = Storage::disk('upload');
|
||||
$this->exportDisk = Storage::disk('export');
|
||||
$this->expected = 'csv-upload-' . Auth::user()->id . '-';
|
||||
|
||||
// file names associated with the old import routine.
|
||||
$this->expected = 'csv-upload-' . auth()->user()->id . '-';
|
||||
|
||||
// for the new import routine:
|
||||
$this->getImportKeys();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,12 +64,26 @@ class UploadCollector extends BasicCollector implements CollectorInterface
|
||||
$files = $this->uploadDisk->files();
|
||||
|
||||
foreach ($files as $entry) {
|
||||
$this->processOldUpload($entry);
|
||||
$this->processUpload($entry);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function getImportKeys()
|
||||
{
|
||||
$set = auth()->user()->importJobs()->where('status', 'import_complete')->get(['import_jobs.*']);
|
||||
if ($set->count() > 0) {
|
||||
$keys = $set->pluck('key')->toArray();
|
||||
$this->importKeys = $keys;
|
||||
|
||||
}
|
||||
Log::debug('Valid import keys are ', $this->importKeys);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $entry
|
||||
*
|
||||
@@ -83,9 +104,28 @@ class UploadCollector extends BasicCollector implements CollectorInterface
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isValidFile(string $entry): bool
|
||||
private function isImportFile(string $entry): bool
|
||||
{
|
||||
$name = str_replace('.upload', '', $entry);
|
||||
if (in_array($name, $this->importKeys)) {
|
||||
Log::debug(sprintf('Import file "%s" is in array', $name), $this->importKeys);
|
||||
|
||||
return true;
|
||||
}
|
||||
Log::debug(sprintf('Import file "%s" is NOT in array', $name), $this->importKeys);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $entry
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isOldImport(string $entry): bool
|
||||
{
|
||||
$len = strlen($this->expected);
|
||||
// file is part of the old import routine:
|
||||
if (substr($entry, 0, $len) === $this->expected) {
|
||||
|
||||
return true;
|
||||
@@ -97,23 +137,63 @@ class UploadCollector extends BasicCollector implements CollectorInterface
|
||||
/**
|
||||
* @param $entry
|
||||
*/
|
||||
private function processOldUpload(string $entry)
|
||||
private function processUpload(string $entry)
|
||||
{
|
||||
$content = '';
|
||||
|
||||
if ($this->isValidFile($entry)) {
|
||||
try {
|
||||
$content = Crypt::decrypt($this->uploadDisk->get($entry));
|
||||
} catch (DecryptException $e) {
|
||||
Log::error('Could not decrypt old CSV import file ' . $entry . '. Skipped because ' . $e->getMessage());
|
||||
}
|
||||
// file is old import:
|
||||
if ($this->isOldImport($entry)) {
|
||||
$this->saveOldImportFile($entry);
|
||||
}
|
||||
if (strlen($content) > 0) {
|
||||
// continue with file:
|
||||
$date = $this->getOriginalUploadDate($entry);
|
||||
$file = $this->job->key . '-Old CSV import dated ' . $date . '.csv';
|
||||
|
||||
// file is current import.
|
||||
if ($this->isImportFile($entry)) {
|
||||
$this->saveImportFile($entry);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $entry
|
||||
*/
|
||||
private function saveImportFile(string $entry)
|
||||
{
|
||||
// find job associated with import file:
|
||||
$name = str_replace('.upload', '', $entry);
|
||||
$job = auth()->user()->importJobs()->where('key', $name)->first();
|
||||
$content = '';
|
||||
try {
|
||||
$content = Crypt::decrypt($this->uploadDisk->get($entry));
|
||||
} catch (DecryptException $e) {
|
||||
Log::error('Could not decrypt old import file ' . $entry . '. Skipped because ' . $e->getMessage());
|
||||
}
|
||||
|
||||
if (!is_null($job) && strlen($content) > 0) {
|
||||
// add to export disk.
|
||||
$date = $job->created_at->format('Y-m-d');
|
||||
$file = sprintf('%s-Old %s import dated %s.%s', $this->job->key, strtoupper($job->file_type), $date, $job->file_type);
|
||||
$this->exportDisk->put($file, $content);
|
||||
$this->getFiles()->push($file);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $entry
|
||||
*/
|
||||
private function saveOldImportFile(string $entry)
|
||||
{
|
||||
$content = '';
|
||||
try {
|
||||
$content = Crypt::decrypt($this->uploadDisk->get($entry));
|
||||
} catch (DecryptException $e) {
|
||||
Log::error('Could not decrypt old CSV import file ' . $entry . '. Skipped because ' . $e->getMessage());
|
||||
}
|
||||
|
||||
if (strlen($content) > 0) {
|
||||
// add to export disk.
|
||||
$date = $this->getOriginalUploadDate($entry);
|
||||
$file = $this->job->key . '-Old import dated ' . $date . '.csv';
|
||||
$this->exportDisk->put($file, $content);
|
||||
$this->getFiles()->push($file);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -11,7 +11,6 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Handlers\Events;
|
||||
|
||||
use Auth;
|
||||
use FireflyIII\Events\TransactionJournalStored;
|
||||
use FireflyIII\Models\PiggyBank;
|
||||
use FireflyIII\Models\PiggyBankEvent;
|
||||
@@ -39,7 +38,7 @@ class ConnectJournalToPiggyBank
|
||||
$piggyBankId = $event->piggyBankId;
|
||||
|
||||
/** @var PiggyBank $piggyBank */
|
||||
$piggyBank = Auth::user()->piggybanks()->where('piggy_banks.id', $piggyBankId)->first(['piggy_banks.*']);
|
||||
$piggyBank = auth()->user()->piggyBanks()->where('piggy_banks.id', $piggyBankId)->first(['piggy_banks.*']);
|
||||
|
||||
if (is_null($piggyBank)) {
|
||||
return true;
|
||||
|
@@ -37,7 +37,7 @@ class ConnectTransactionToPiggyBank
|
||||
$repository = app(PiggyBankRepositoryInterface::class);
|
||||
$transaction = $event->transaction;
|
||||
|
||||
$piggyBank = $repository->find($transaction['piggy_bank_id']);
|
||||
$piggyBank = $repository->find($transaction['piggy_bank_id']);
|
||||
|
||||
// valid piggy:
|
||||
if (is_null($piggyBank->id)) {
|
||||
|
@@ -17,7 +17,6 @@ use FireflyIII\Models\Rule;
|
||||
use FireflyIII\Models\RuleGroup;
|
||||
use FireflyIII\Rules\Processor;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
/**
|
||||
* Class FireRulesForStore
|
||||
@@ -38,7 +37,7 @@ class FireRulesForStore
|
||||
{
|
||||
// get all the user's rule groups, with the rules, order by 'order'.
|
||||
/** @var User $user */
|
||||
$user = Auth::user();
|
||||
$user = auth()->user();
|
||||
$groups = $user->ruleGroups()->where('rule_groups.active', 1)->orderBy('order', 'ASC')->get();
|
||||
//
|
||||
/** @var RuleGroup $group */
|
||||
|
@@ -11,7 +11,6 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Handlers\Events;
|
||||
|
||||
use Auth;
|
||||
use FireflyIII\Events\TransactionJournalUpdated;
|
||||
use FireflyIII\Models\Rule;
|
||||
use FireflyIII\Models\RuleGroup;
|
||||
@@ -36,7 +35,7 @@ class FireRulesForUpdate
|
||||
{
|
||||
// get all the user's rule groups, with the rules, order by 'order'.
|
||||
/** @var User $user */
|
||||
$user = Auth::user();
|
||||
$user = auth()->user();
|
||||
$groups = $user->ruleGroups()->where('rule_groups.active', 1)->orderBy('order', 'ASC')->get();
|
||||
//
|
||||
/** @var RuleGroup $group */
|
||||
|
@@ -13,7 +13,6 @@ namespace FireflyIII\Handlers\Events;
|
||||
|
||||
use FireflyIII\Events\UserIsConfirmed;
|
||||
use FireflyIII\Events\UserRegistration;
|
||||
use FireflyIII\User;
|
||||
use Preferences;
|
||||
|
||||
/**
|
||||
@@ -32,20 +31,6 @@ class UserSaveIpAddress
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param UserRegistration $event
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function saveFromRegistration(UserRegistration $event): bool
|
||||
{
|
||||
Preferences::setForUser($event->user, 'registration_ip_address', $event->ipAddress);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
@@ -59,4 +44,18 @@ class UserSaveIpAddress
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param UserRegistration $event
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function saveFromRegistration(UserRegistration $event): bool
|
||||
{
|
||||
Preferences::setForUser($event->user, 'registration_ip_address', $event->ipAddress);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@@ -10,7 +10,6 @@
|
||||
declare(strict_types = 1);
|
||||
namespace FireflyIII\Helpers\Attachments;
|
||||
|
||||
use Auth;
|
||||
use Crypt;
|
||||
use FireflyIII\Models\Attachment;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
@@ -60,7 +59,7 @@ class AttachmentHelper implements AttachmentHelperInterface
|
||||
*/
|
||||
public function getAttachmentLocation(Attachment $attachment): string
|
||||
{
|
||||
$path = storage_path('upload') . DIRECTORY_SEPARATOR . 'at-' . $attachment->id . '.data';
|
||||
$path = sprintf('%s%sat-%d.data', storage_path('upload'), DIRECTORY_SEPARATOR, intval($attachment->id));
|
||||
|
||||
return $path;
|
||||
}
|
||||
@@ -112,7 +111,7 @@ class AttachmentHelper implements AttachmentHelperInterface
|
||||
$md5 = md5_file($file->getRealPath());
|
||||
$name = $file->getClientOriginalName();
|
||||
$class = get_class($model);
|
||||
$count = Auth::user()->attachments()->where('md5', $md5)->where('attachable_id', $model->id)->where('attachable_type', $class)->count();
|
||||
$count = auth()->user()->attachments()->where('md5', $md5)->where('attachable_id', $model->id)->where('attachable_type', $class)->count();
|
||||
|
||||
if ($count > 0) {
|
||||
$msg = (string)trans('validation.file_already_attached', ['name' => $name]);
|
||||
@@ -139,7 +138,7 @@ class AttachmentHelper implements AttachmentHelperInterface
|
||||
}
|
||||
|
||||
$attachment = new Attachment; // create Attachment object.
|
||||
$attachment->user()->associate(Auth::user());
|
||||
$attachment->user()->associate(auth()->user());
|
||||
$attachment->attachable()->associate($model);
|
||||
$attachment->md5 = md5_file($file->getRealPath());
|
||||
$attachment->filename = $file->getClientOriginalName();
|
||||
@@ -250,6 +249,8 @@ class AttachmentHelper implements AttachmentHelperInterface
|
||||
/**
|
||||
* @param array $files
|
||||
*
|
||||
* @param Model $model
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function processFiles(array $files, Model $model): bool
|
||||
|
@@ -32,14 +32,12 @@ class BalanceLine
|
||||
|
||||
/** @var BudgetModel */
|
||||
protected $budget;
|
||||
|
||||
/** @var Carbon */
|
||||
protected $startDate;
|
||||
/** @var Carbon */
|
||||
protected $endDate;
|
||||
|
||||
/** @var int */
|
||||
protected $role = self::ROLE_DEFAULTROLE;
|
||||
/** @var Carbon */
|
||||
protected $startDate;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -90,6 +88,22 @@ class BalanceLine
|
||||
$this->budget = $budget;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Carbon
|
||||
*/
|
||||
public function getEndDate()
|
||||
{
|
||||
return $this->endDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $endDate
|
||||
*/
|
||||
public function setEndDate($endDate)
|
||||
{
|
||||
$this->endDate = $endDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
@@ -106,6 +120,22 @@ class BalanceLine
|
||||
$this->role = $role;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Carbon
|
||||
*/
|
||||
public function getStartDate()
|
||||
{
|
||||
return $this->startDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $startDate
|
||||
*/
|
||||
public function setStartDate($startDate)
|
||||
{
|
||||
$this->startDate = $startDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
@@ -127,39 +157,6 @@ class BalanceLine
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Carbon
|
||||
*/
|
||||
public function getStartDate()
|
||||
{
|
||||
return $this->startDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $startDate
|
||||
*/
|
||||
public function setStartDate($startDate)
|
||||
{
|
||||
$this->startDate = $startDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Carbon
|
||||
*/
|
||||
public function getEndDate()
|
||||
{
|
||||
return $this->endDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $endDate
|
||||
*/
|
||||
public function setEndDate($endDate)
|
||||
{
|
||||
$this->endDate = $endDate;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* If a BalanceLine has a budget/repetition, each BalanceEntry in this BalanceLine
|
||||
* should have a "spent" value, which is the amount of money that has been spent
|
||||
|
@@ -47,6 +47,7 @@ class Budget
|
||||
public function addBudgetLine(BudgetLine $budgetLine): Budget
|
||||
{
|
||||
$this->budgetLines->push($budgetLine);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -59,6 +60,7 @@ class Budget
|
||||
{
|
||||
$add = strval(round($add, 2));
|
||||
$this->budgeted = bcadd($this->budgeted, $add);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -71,6 +73,7 @@ class Budget
|
||||
{
|
||||
$add = strval(round($add, 2));
|
||||
$this->left = bcadd($this->left, $add);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -83,6 +86,7 @@ class Budget
|
||||
{
|
||||
$add = strval(round($add, 2));
|
||||
$this->overspent = bcadd($this->overspent, $add);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -95,6 +99,7 @@ class Budget
|
||||
{
|
||||
$add = strval(round($add, 2));
|
||||
$this->spent = bcadd($this->spent, $add);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@@ -51,6 +51,7 @@ class BudgetLine
|
||||
public function setBudget(BudgetModel $budget): BudgetLine
|
||||
{
|
||||
$this->budget = $budget;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -70,6 +71,7 @@ class BudgetLine
|
||||
public function setBudgeted(string $budgeted): BudgetLine
|
||||
{
|
||||
$this->budgeted = $budgeted;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -89,6 +91,7 @@ class BudgetLine
|
||||
public function setLeft(string $left): BudgetLine
|
||||
{
|
||||
$this->left = $left;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -108,6 +111,7 @@ class BudgetLine
|
||||
public function setOverspent(string $overspent): BudgetLine
|
||||
{
|
||||
$this->overspent = $overspent;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -127,6 +131,7 @@ class BudgetLine
|
||||
public function setRepetition(LimitRepetition $repetition): BudgetLine
|
||||
{
|
||||
$this->repetition = $repetition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -146,6 +151,7 @@ class BudgetLine
|
||||
public function setSpent(string $spent): BudgetLine
|
||||
{
|
||||
$this->spent = $spent;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@@ -1,385 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Importer.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
namespace FireflyIII\Helpers\Csv;
|
||||
|
||||
use Auth;
|
||||
use FireflyIII\Events\TransactionJournalStored;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Helpers\Csv\Converter\ConverterInterface;
|
||||
use FireflyIII\Helpers\Csv\PostProcessing\PostProcessorInterface;
|
||||
use FireflyIII\Helpers\Csv\Specifix\SpecifixInterface;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class Importer
|
||||
*
|
||||
* @package FireflyIII\Helpers\Csv
|
||||
*/
|
||||
class Importer
|
||||
{
|
||||
|
||||
/** @var Data */
|
||||
protected $data;
|
||||
/** @var array */
|
||||
protected $errors = [];
|
||||
/** @var array */
|
||||
protected $importData;
|
||||
/** @var array */
|
||||
protected $importRow;
|
||||
/** @var int */
|
||||
protected $imported = 0;
|
||||
/** @var Collection */
|
||||
protected $journals;
|
||||
/** @var array */
|
||||
protected $map;
|
||||
/** @var array */
|
||||
protected $mapped;
|
||||
/** @var array */
|
||||
protected $roles;
|
||||
/** @var int */
|
||||
protected $rows = 0;
|
||||
/** @var array */
|
||||
protected $specifix = [];
|
||||
|
||||
/**
|
||||
* Used by CsvController.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getErrors(): array
|
||||
{
|
||||
return $this->errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by CsvController
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getImported(): int
|
||||
{
|
||||
return $this->imported;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function getJournals(): Collection
|
||||
{
|
||||
return $this->journals;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by CsvController
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getRows(): int
|
||||
{
|
||||
return $this->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getSpecifix(): array
|
||||
{
|
||||
return is_array($this->specifix) ? $this->specifix : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
set_time_limit(0);
|
||||
|
||||
$this->journals = new Collection;
|
||||
$this->map = $this->data->getMap();
|
||||
$this->roles = $this->data->getRoles();
|
||||
$this->mapped = $this->data->getMapped();
|
||||
$this->specifix = $this->data->getSpecifix();
|
||||
|
||||
foreach ($this->data->getReader() as $index => $row) {
|
||||
if ($this->parseRow($index)) {
|
||||
$this->rows++;
|
||||
$result = $this->importRow($row);
|
||||
if (!($result instanceof TransactionJournal)) {
|
||||
Log::error('Caught error at row #' . $index . ': ' . $result);
|
||||
$this->errors[$index] = $result;
|
||||
} else {
|
||||
$this->imported++;
|
||||
$this->journals->push($result);
|
||||
event(new TransactionJournalStored($result, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Data $data
|
||||
*/
|
||||
public function setData(Data $data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TransactionJournal|string
|
||||
*/
|
||||
protected function createTransactionJournal()
|
||||
{
|
||||
$date = $this->importData['date'];
|
||||
if (is_null($this->importData['date'])) {
|
||||
$date = $this->importData['date-rent'];
|
||||
}
|
||||
|
||||
|
||||
$transactionType = $this->getTransactionType(); // defaults to deposit
|
||||
$errors = new MessageBag;
|
||||
|
||||
$journal = TransactionJournal::create(
|
||||
[
|
||||
'user_id' => Auth::user()->id,
|
||||
'transaction_type_id' => $transactionType->id,
|
||||
'transaction_currency_id' => $this->importData['currency']->id,
|
||||
'description' => $this->importData['description'],
|
||||
'completed' => 0,
|
||||
'date' => $date,
|
||||
'bill_id' => $this->importData['bill-id'],
|
||||
]
|
||||
);
|
||||
if ($journal->getErrors()->count() == 0) {
|
||||
// first transaction
|
||||
$accountId = $this->importData['asset-account-object']->id; // create first transaction:
|
||||
$amount = $this->importData['amount'];
|
||||
$transaction = Transaction::create(['transaction_journal_id' => $journal->id, 'account_id' => $accountId, 'amount' => $amount]);
|
||||
$errors = $transaction->getErrors();
|
||||
|
||||
// second transaction
|
||||
$accountId = $this->importData['opposing-account-object']->id; // create second transaction:
|
||||
$amount = bcmul($this->importData['amount'], '-1');
|
||||
$transaction = Transaction::create(['transaction_journal_id' => $journal->id, 'account_id' => $accountId, 'amount' => $amount]);
|
||||
$errors = $transaction->getErrors()->merge($errors);
|
||||
}
|
||||
if ($errors->count() == 0) {
|
||||
$journal->completed = 1;
|
||||
$journal->save();
|
||||
} else {
|
||||
$text = join(',', $errors->all());
|
||||
|
||||
return $text;
|
||||
}
|
||||
$this->saveBudget($journal);
|
||||
$this->saveCategory($journal);
|
||||
$this->saveTags($journal);
|
||||
|
||||
// some debug info:
|
||||
$journalId = $journal->id;
|
||||
$type = $journal->transaction_type_type ?? $journal->transactionType->type;
|
||||
/** @var Account $asset */
|
||||
$asset = $this->importData['asset-account-object'];
|
||||
/** @var Account $opposing */
|
||||
$opposing = $this->importData['opposing-account-object'];
|
||||
|
||||
Log::info('Created journal #' . $journalId . ' of type ' . $type . '!');
|
||||
Log::info('Asset account #' . $asset->id . ' lost/gained: ' . $this->importData['amount']);
|
||||
Log::info($opposing->accountType->type . ' #' . $opposing->id . ' lost/gained: ' . bcmul($this->importData['amount'], '-1'));
|
||||
|
||||
return $journal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TransactionType
|
||||
*/
|
||||
protected function getTransactionType()
|
||||
{
|
||||
$transactionType = TransactionType::where('type', TransactionType::DEPOSIT)->first();
|
||||
if ($this->importData['amount'] < 0) {
|
||||
$transactionType = TransactionType::where('type', TransactionType::WITHDRAWAL)->first();
|
||||
}
|
||||
|
||||
if (in_array($this->importData['opposing-account-object']->accountType->type, ['Asset account', 'Default account'])) {
|
||||
$transactionType = TransactionType::where('type', TransactionType::TRANSFER)->first();
|
||||
}
|
||||
|
||||
return $transactionType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $row
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @return string|bool
|
||||
*/
|
||||
protected function importRow(array $row)
|
||||
{
|
||||
|
||||
$data = $this->getFiller(); // These fields are necessary to create a new transaction journal. Some are optional
|
||||
foreach ($row as $index => $value) {
|
||||
$role = $this->roles[$index] ?? '_ignore';
|
||||
$class = config('csv.roles.' . $role . '.converter');
|
||||
$field = config('csv.roles.' . $role . '.field');
|
||||
|
||||
|
||||
// here would be the place where preprocessors would fire.
|
||||
|
||||
/** @var ConverterInterface $converter */
|
||||
$converter = app('FireflyIII\Helpers\Csv\Converter\\' . $class);
|
||||
$converter->setData($data); // the complete array so far.
|
||||
$converter->setField($field);
|
||||
$converter->setIndex($index);
|
||||
$converter->setMapped($this->mapped);
|
||||
$converter->setValue($value);
|
||||
$data[$field] = $converter->convert();
|
||||
}
|
||||
// move to class vars.
|
||||
$this->importData = $data;
|
||||
$this->importRow = $row;
|
||||
unset($data, $row);
|
||||
// post processing and validating.
|
||||
$this->postProcess();
|
||||
$result = $this->validateData();
|
||||
|
||||
if (!($result === true)) {
|
||||
return $result; // return error.
|
||||
}
|
||||
$journal = $this->createTransactionJournal();
|
||||
|
||||
return $journal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $index
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function parseRow(int $index)
|
||||
{
|
||||
return (($this->data->hasHeaders() && $index >= 1) || !$this->data->hasHeaders());
|
||||
}
|
||||
|
||||
/**
|
||||
* Row denotes the original data.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function postProcess()
|
||||
{
|
||||
// do bank specific fixes (must be enabled but now all of them.
|
||||
|
||||
foreach ($this->getSpecifix() as $className) {
|
||||
/** @var SpecifixInterface $specifix */
|
||||
$specifix = app('FireflyIII\Helpers\Csv\Specifix\\' . $className);
|
||||
if ($specifix->getProcessorType() == SpecifixInterface::POST_PROCESSOR) {
|
||||
$specifix->setData($this->importData);
|
||||
$specifix->setRow($this->importRow);
|
||||
$this->importData = $specifix->fix();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$set = config('csv.post_processors');
|
||||
foreach ($set as $className) {
|
||||
/** @var PostProcessorInterface $postProcessor */
|
||||
$postProcessor = app('FireflyIII\Helpers\Csv\PostProcessing\\' . $className);
|
||||
$array = $this->importData ?? [];
|
||||
$postProcessor->setData($array);
|
||||
$this->importData = $postProcessor->process();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*/
|
||||
protected function saveBudget(TransactionJournal $journal)
|
||||
{
|
||||
// add budget:
|
||||
if (!is_null($this->importData['budget'])) {
|
||||
$journal->budgets()->save($this->importData['budget']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*/
|
||||
protected function saveCategory(TransactionJournal $journal)
|
||||
{
|
||||
// add category:
|
||||
if (!is_null($this->importData['category'])) {
|
||||
$journal->categories()->save($this->importData['category']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*/
|
||||
protected function saveTags(TransactionJournal $journal)
|
||||
{
|
||||
if (!is_null($this->importData['tags'])) {
|
||||
foreach ($this->importData['tags'] as $tag) {
|
||||
$journal->tags()->save($tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
protected function validateData()
|
||||
{
|
||||
$date = $this->importData['date'] ?? null;
|
||||
$rentDate = $this->importData['date-rent'] ?? null;
|
||||
if (is_null($date) && is_null($rentDate)) {
|
||||
return 'No date value for this row.';
|
||||
}
|
||||
if (is_null($this->importData['opposing-account-object'])) {
|
||||
return 'Opposing account is null';
|
||||
}
|
||||
|
||||
if (!($this->importData['asset-account-object'] instanceof Account)) {
|
||||
return 'No asset account to import into.';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function getFiller()
|
||||
{
|
||||
$filler = [];
|
||||
foreach (config('csv.roles') as $role) {
|
||||
if (isset($role['field'])) {
|
||||
$fieldName = $role['field'];
|
||||
$filler[$fieldName] = null;
|
||||
}
|
||||
}
|
||||
// some extra's:
|
||||
$filler['bill-id'] = null;
|
||||
$filler['opposing-account-object'] = null;
|
||||
$filler['asset-account-object'] = null;
|
||||
$filler['amount-modifier'] = '1';
|
||||
|
||||
return $filler;
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -11,7 +11,6 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Helpers\Report;
|
||||
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use DB;
|
||||
use FireflyIII\Helpers\Collection\Balance;
|
||||
@@ -102,34 +101,34 @@ class BalanceReportHelper implements BalanceReportHelperInterface
|
||||
private function allCoveredByBalancingActs(Collection $accounts, Carbon $start, Carbon $end): Collection
|
||||
{
|
||||
$ids = $accounts->pluck('id')->toArray();
|
||||
$set = Auth::user()->tags()
|
||||
->leftJoin('tag_transaction_journal', 'tag_transaction_journal.tag_id', '=', 'tags.id')
|
||||
->leftJoin('transaction_journals', 'tag_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->leftJoin('transaction_types', 'transaction_journals.transaction_type_id', '=', 'transaction_types.id')
|
||||
->leftJoin(
|
||||
'transactions AS t_source', function (JoinClause $join) {
|
||||
$join->on('transaction_journals.id', '=', 't_source.transaction_journal_id')->where('t_source.amount', '<', 0);
|
||||
}
|
||||
)
|
||||
->leftJoin(
|
||||
'transactions AS t_destination', function (JoinClause $join) {
|
||||
$join->on('transaction_journals.id', '=', 't_destination.transaction_journal_id')->where('t_destination.amount', '>', 0);
|
||||
}
|
||||
)
|
||||
->where('tags.tagMode', 'balancingAct')
|
||||
->where('transaction_types.type', TransactionType::TRANSFER)
|
||||
->where('transaction_journals.date', '>=', $start->format('Y-m-d'))
|
||||
->where('transaction_journals.date', '<=', $end->format('Y-m-d'))
|
||||
->whereNull('transaction_journals.deleted_at')
|
||||
->whereIn('t_source.account_id', $ids)
|
||||
->whereIn('t_destination.account_id', $ids)
|
||||
->groupBy('t_destination.account_id')
|
||||
->get(
|
||||
[
|
||||
't_destination.account_id',
|
||||
DB::raw('SUM(`t_destination`.`amount`) as `sum`'),
|
||||
]
|
||||
);
|
||||
$set = auth()->user()->tags()
|
||||
->leftJoin('tag_transaction_journal', 'tag_transaction_journal.tag_id', '=', 'tags.id')
|
||||
->leftJoin('transaction_journals', 'tag_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->leftJoin('transaction_types', 'transaction_journals.transaction_type_id', '=', 'transaction_types.id')
|
||||
->leftJoin(
|
||||
'transactions AS t_source', function (JoinClause $join) {
|
||||
$join->on('transaction_journals.id', '=', 't_source.transaction_journal_id')->where('t_source.amount', '<', 0);
|
||||
}
|
||||
)
|
||||
->leftJoin(
|
||||
'transactions AS t_destination', function (JoinClause $join) {
|
||||
$join->on('transaction_journals.id', '=', 't_destination.transaction_journal_id')->where('t_destination.amount', '>', 0);
|
||||
}
|
||||
)
|
||||
->where('tags.tagMode', 'balancingAct')
|
||||
->where('transaction_types.type', TransactionType::TRANSFER)
|
||||
->where('transaction_journals.date', '>=', $start->format('Y-m-d'))
|
||||
->where('transaction_journals.date', '<=', $end->format('Y-m-d'))
|
||||
->whereNull('transaction_journals.deleted_at')
|
||||
->whereIn('t_source.account_id', $ids)
|
||||
->whereIn('t_destination.account_id', $ids)
|
||||
->groupBy('t_destination.account_id')
|
||||
->get(
|
||||
[
|
||||
't_destination.account_id',
|
||||
DB::raw('SUM(`t_destination`.`amount`) as `sum`'),
|
||||
]
|
||||
);
|
||||
|
||||
return $set;
|
||||
}
|
||||
@@ -262,6 +261,7 @@ class BalanceReportHelper implements BalanceReportHelperInterface
|
||||
/**
|
||||
* @param Balance $balance
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's exactly 5.
|
||||
*
|
||||
* @return Balance
|
||||
*/
|
||||
private function removeUnusedBudgets(Balance $balance): Balance
|
||||
|
@@ -82,8 +82,8 @@ class ReportHelper implements ReportHelperInterface
|
||||
$billLine = new BillLine;
|
||||
$billLine->setBill($bill);
|
||||
$billLine->setActive(intval($bill->active) === 1);
|
||||
$billLine->setMin($bill->amount_min);
|
||||
$billLine->setMax($bill->amount_max);
|
||||
$billLine->setMin(strval($bill->amount_min));
|
||||
$billLine->setMax(strval($bill->amount_max));
|
||||
$billLine->setHit(false);
|
||||
// is hit in period?
|
||||
|
||||
|
@@ -11,7 +11,6 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use ExpandedForm;
|
||||
use FireflyIII\Crud\Account\AccountCrudInterface;
|
||||
@@ -50,7 +49,7 @@ class AccountController extends Controller
|
||||
/**
|
||||
* @param string $what
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
* @return View
|
||||
*/
|
||||
public function create(string $what = 'asset')
|
||||
{
|
||||
@@ -116,7 +115,7 @@ class AccountController extends Controller
|
||||
* @param ARI $repository
|
||||
* @param Account $account
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
* @return View
|
||||
*/
|
||||
public function edit(ARI $repository, Account $account)
|
||||
{
|
||||
@@ -172,8 +171,10 @@ class AccountController extends Controller
|
||||
$subTitleIcon = config('firefly.subIconsByIdentifier.' . $what);
|
||||
$types = config('firefly.accountTypesByIdentifier.' . $what);
|
||||
$accounts = $crud->getAccountsByType($types);
|
||||
$start = clone session('start', Carbon::now()->startOfMonth());
|
||||
$end = clone session('end', Carbon::now()->endOfMonth());
|
||||
/** @var Carbon $start */
|
||||
$start = clone session('start', Carbon::now()->startOfMonth());
|
||||
/** @var Carbon $end */
|
||||
$end = clone session('end', Carbon::now()->endOfMonth());
|
||||
$start->subDay();
|
||||
|
||||
$ids = $accounts->pluck('id')->toArray();
|
||||
@@ -196,7 +197,7 @@ class AccountController extends Controller
|
||||
* @param ARI $repository
|
||||
* @param Account $account
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
* @return View
|
||||
*/
|
||||
public function show(ARI $repository, Account $account)
|
||||
{
|
||||
@@ -204,15 +205,17 @@ class AccountController extends Controller
|
||||
$subTitleIcon = config('firefly.subIconsByIdentifier.' . $account->accountType->type);
|
||||
$subTitle = $account->name;
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
$start = session('start', Navigation::startOfPeriod(new Carbon, $range));
|
||||
$end = session('end', Navigation::endOfPeriod(new Carbon, $range));
|
||||
$page = intval(Input::get('page'));
|
||||
$pageSize = Preferences::get('transactionPageSize', 50)->data;
|
||||
$offset = ($page - 1) * $pageSize;
|
||||
$set = $repository->journalsInPeriod(new Collection([$account]), [], $start, $end);
|
||||
$count = $set->count();
|
||||
$subSet = $set->splice($offset, $pageSize);
|
||||
$journals = new LengthAwarePaginator($subSet, $count, $pageSize, $page);
|
||||
/** @var Carbon $start */
|
||||
$start = session('start', Navigation::startOfPeriod(new Carbon, $range));
|
||||
/** @var Carbon $end */
|
||||
$end = session('end', Navigation::endOfPeriod(new Carbon, $range));
|
||||
$page = intval(Input::get('page'));
|
||||
$pageSize = Preferences::get('transactionPageSize', 50)->data;
|
||||
$offset = ($page - 1) * $pageSize;
|
||||
$set = $repository->journalsInPeriod(new Collection([$account]), [], $start, $end);
|
||||
$count = $set->count();
|
||||
$subSet = $set->splice($offset, $pageSize);
|
||||
$journals = new LengthAwarePaginator($subSet, $count, $pageSize, $page);
|
||||
$journals->setPath('accounts/show/' . $account->id);
|
||||
|
||||
// grouped other months thing:
|
||||
@@ -287,7 +290,7 @@ class AccountController extends Controller
|
||||
* @param AccountFormRequest $request
|
||||
* @param AccountCrudInterface $crud
|
||||
*
|
||||
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function store(AccountFormRequest $request, AccountCrudInterface $crud)
|
||||
{
|
||||
@@ -297,7 +300,7 @@ class AccountController extends Controller
|
||||
'virtualBalance' => round($request->input('virtualBalance'), 2),
|
||||
'virtualBalanceCurrency' => intval($request->input('amount_currency_id_virtualBalance')),
|
||||
'active' => true,
|
||||
'user' => Auth::user()->id,
|
||||
'user' => auth()->user()->id,
|
||||
'iban' => $request->input('iban'),
|
||||
'accountNumber' => $request->input('accountNumber'),
|
||||
'accountRole' => $request->input('accountRole'),
|
||||
@@ -335,7 +338,7 @@ class AccountController extends Controller
|
||||
* @param AccountCrudInterface $crud
|
||||
* @param Account $account
|
||||
*
|
||||
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function update(AccountFormRequest $request, AccountCrudInterface $crud, Account $account)
|
||||
{
|
||||
@@ -343,7 +346,7 @@ class AccountController extends Controller
|
||||
$accountData = [
|
||||
'name' => $request->input('name'),
|
||||
'active' => $request->input('active'),
|
||||
'user' => Auth::user()->id,
|
||||
'user' => auth()->user()->id,
|
||||
'iban' => $request->input('iban'),
|
||||
'accountNumber' => $request->input('accountNumber'),
|
||||
'accountRole' => $request->input('accountRole'),
|
||||
|
77
app/Http/Controllers/Admin/ConfigurationController.php
Normal file
77
app/Http/Controllers/Admin/ConfigurationController.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/**
|
||||
* ConfigurationController.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers\Admin;
|
||||
|
||||
|
||||
use Config;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Http\Requests\ConfigurationRequest;
|
||||
use FireflyIII\Support\Facades\FireflyConfig;
|
||||
use Preferences;
|
||||
use Redirect;
|
||||
use Session;
|
||||
use View;
|
||||
|
||||
/**
|
||||
* Class ConfigurationController
|
||||
*
|
||||
* @package FireflyIII\Http\Controllers\Admin
|
||||
*/
|
||||
class ConfigurationController extends Controller
|
||||
{
|
||||
/**
|
||||
* ConfigurationController constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
View::share('title', strval(trans('firefly.administration')));
|
||||
View::share('mainTitleIcon', 'fa-hand-spock-o');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return View
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$subTitle = strval(trans('firefly.instance_configuration'));
|
||||
$subTitleIcon = 'fa-wrench';
|
||||
|
||||
// all available configuration and their default value in case
|
||||
// they don't exist yet.
|
||||
$singleUserMode = FireflyConfig::get('single_user_mode', Config::get('firefly.configuration.single_user_mode'))->data;
|
||||
|
||||
return view('admin.configuration.index', compact('subTitle', 'subTitleIcon', 'singleUserMode'));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ConfigurationRequest $request
|
||||
*/
|
||||
public function store(ConfigurationRequest $request)
|
||||
{
|
||||
// get config values:
|
||||
$singleUserMode = intval($request->get('single_user_mode')) === 1 ? true : false;
|
||||
|
||||
// store config values
|
||||
FireflyConfig::set('single_user_mode', $singleUserMode);
|
||||
|
||||
// flash message
|
||||
Session::flash('success', strval(trans('firefly.configuration_updated')));
|
||||
Preferences::mark();
|
||||
|
||||
return Redirect::route('admin.configuration.index');
|
||||
}
|
||||
|
||||
}
|
@@ -35,7 +35,7 @@ class DomainController extends Controller
|
||||
$title = strval(trans('firefly.administration'));
|
||||
$mainTitleIcon = 'fa-hand-spock-o';
|
||||
$subTitle = strval(trans('firefly.blocked_domains'));
|
||||
$subTitleIcon = 'fa-users';
|
||||
$subTitleIcon = 'fa-exclamation-circle';
|
||||
$domains = FireflyConfig::get('blocked-domains', [])->data;
|
||||
|
||||
// known domains
|
||||
@@ -58,7 +58,7 @@ class DomainController extends Controller
|
||||
return redirect(route('admin.users.domains'));
|
||||
}
|
||||
|
||||
$domain = $request->get('domain');
|
||||
$domain = strtolower($request->get('domain'));
|
||||
$blocked = FireflyConfig::get('blocked-domains', [])->data;
|
||||
|
||||
if (in_array($domain, $blocked)) {
|
||||
|
@@ -47,7 +47,7 @@ class AttachmentController extends Controller
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
* @return View
|
||||
*/
|
||||
public function delete(Attachment $attachment)
|
||||
{
|
||||
@@ -93,10 +93,10 @@ class AttachmentController extends Controller
|
||||
|
||||
if ($disk->exists($file)) {
|
||||
|
||||
$quoted = sprintf('"%s"', addcslashes(basename($attachment->filename), '"\\'));
|
||||
$quoted = sprintf('"%s"', addcslashes(basename($attachment->filename), '"\\'));
|
||||
$content = Crypt::decrypt($disk->get($file));
|
||||
|
||||
Log::debug('Send file to user', ['file' => $quoted, 'size' => strlen($content)]);
|
||||
Log::debug('Send file to user', ['file' => $quoted, 'size' => strlen($content)]);
|
||||
|
||||
return response($content, 200)
|
||||
->header('Content-Description', 'File Transfer')
|
||||
@@ -116,7 +116,7 @@ class AttachmentController extends Controller
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
* @return View
|
||||
*/
|
||||
public function edit(Attachment $attachment)
|
||||
{
|
||||
|
@@ -11,21 +11,10 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers\Auth;
|
||||
|
||||
use Auth;
|
||||
use FireflyIII\Events\UserRegistration;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Support\Facades\FireflyConfig;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
|
||||
use Illuminate\Foundation\Auth\ThrottlesLogins;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Mail\Message;
|
||||
use Illuminate\Support\Facades\Lang;
|
||||
use Log;
|
||||
use Mail;
|
||||
use Session;
|
||||
use Swift_TransportException;
|
||||
use Validator;
|
||||
|
||||
|
||||
@@ -55,107 +44,6 @@ class AuthController extends Controller
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a login request to the application.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function login(Request $request)
|
||||
{
|
||||
|
||||
$this->validate($request, [$this->loginUsername() => 'required', 'password' => 'required',]);
|
||||
$throttles = $this->isUsingThrottlesLoginsTrait();
|
||||
|
||||
if ($throttles && $this->hasTooManyLoginAttempts($request)) {
|
||||
return $this->sendLockoutResponse($request);
|
||||
}
|
||||
|
||||
$credentials = $this->getCredentials($request);
|
||||
$credentials['blocked'] = 0; // most not be blocked.
|
||||
|
||||
if (Auth::guard($this->getGuard())->attempt($credentials, $request->has('remember'))) {
|
||||
return $this->handleUserWasAuthenticated($request, $throttles);
|
||||
}
|
||||
|
||||
// check if user is blocked:
|
||||
$errorMessage = '';
|
||||
/** @var User $foundUser */
|
||||
$foundUser = User::where('email', $credentials['email'])->where('blocked', 1)->first();
|
||||
if (!is_null($foundUser)) {
|
||||
// if it exists, show message:
|
||||
$code = strlen(strval($foundUser->blocked_code)) > 0 ? $foundUser->blocked_code : 'general_blocked';
|
||||
$errorMessage = strval(trans('firefly.' . $code . '_error', ['email' => $credentials['email']]));
|
||||
$this->reportBlockedUserLoginAttempt($foundUser, $code, $request->ip());
|
||||
}
|
||||
|
||||
if ($throttles) {
|
||||
$this->incrementLoginAttempts($request);
|
||||
}
|
||||
|
||||
return $this->sendFailedLoginResponse($request, $errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a registration request for the application.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
* @throws FireflyException
|
||||
* @throws \Illuminate\Foundation\Validation\ValidationException
|
||||
*/
|
||||
public function register(Request $request)
|
||||
{
|
||||
$validator = $this->validator($request->all());
|
||||
|
||||
if ($validator->fails()) {
|
||||
$this->throwValidationException(
|
||||
$request, $validator
|
||||
);
|
||||
}
|
||||
|
||||
$data = $request->all();
|
||||
$data['password'] = bcrypt($data['password']);
|
||||
|
||||
// is user email domain blocked?
|
||||
if ($this->isBlockedDomain($data['email'])) {
|
||||
$validator->getMessageBag()->add('email', (string)trans('validation.invalid_domain'));
|
||||
|
||||
$this->reportBlockedDomainRegistrationAttempt($data['email'], $request->ip());
|
||||
|
||||
$this->throwValidationException(
|
||||
$request, $validator
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
$user = $this->create($request->all());
|
||||
|
||||
// trigger user registration event:
|
||||
event(new UserRegistration($user, $request->ip()));
|
||||
|
||||
Auth::login($user);
|
||||
|
||||
Session::flash('success', strval(trans('firefly.registered')));
|
||||
Session::flash('gaEventCategory', 'user');
|
||||
Session::flash('gaEventAction', 'new-registration');
|
||||
|
||||
return redirect($this->redirectPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the application registration form.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function showRegistrationForm()
|
||||
{
|
||||
$showDemoWarning = env('SHOW_DEMO_WARNING', false);
|
||||
|
||||
return view('auth.register', compact('showDemoWarning'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new user instance after a valid registration.
|
||||
@@ -174,67 +62,6 @@ class AuthController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getBlockedDomains()
|
||||
{
|
||||
return FireflyConfig::get('blocked-domains', [])->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the failed login message.
|
||||
*
|
||||
* @param string $message
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getFailedLoginMessage(string $message)
|
||||
{
|
||||
if (strlen($message) > 0) {
|
||||
return $message;
|
||||
}
|
||||
|
||||
return Lang::has('auth.failed')
|
||||
? Lang::get('auth.failed')
|
||||
: 'These credentials do not match our records.';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $email
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isBlockedDomain(string $email)
|
||||
{
|
||||
$parts = explode('@', $email);
|
||||
$blocked = $this->getBlockedDomains();
|
||||
|
||||
if (isset($parts[1]) && in_array($parts[1], $blocked)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the failed login response instance.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param string $message
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
protected function sendFailedLoginResponse(Request $request, string $message)
|
||||
{
|
||||
return redirect()->back()
|
||||
->withInput($request->only($this->loginUsername(), 'remember'))
|
||||
->withErrors(
|
||||
[
|
||||
$this->loginUsername() => $this->getFailedLoginMessage($message),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a validator for an incoming registration request.
|
||||
@@ -253,61 +80,5 @@ class AuthController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message home about a blocked domain and the address attempted to register.
|
||||
*
|
||||
* @param string $registrationMail
|
||||
* @param string $ipAddress
|
||||
*/
|
||||
private function reportBlockedDomainRegistrationAttempt(string $registrationMail, string $ipAddress)
|
||||
{
|
||||
try {
|
||||
$email = env('SITE_OWNER', false);
|
||||
$parts = explode('@', $registrationMail);
|
||||
$domain = $parts[1];
|
||||
$fields = [
|
||||
'email_address' => $registrationMail,
|
||||
'blocked_domain' => $domain,
|
||||
'ip' => $ipAddress,
|
||||
];
|
||||
|
||||
Mail::send(
|
||||
['emails.blocked-registration-html', 'emails.blocked-registration'], $fields, function (Message $message) use ($email, $domain) {
|
||||
$message->to($email, $email)->subject('Blocked a registration attempt with domain ' . $domain . '.');
|
||||
}
|
||||
);
|
||||
} catch (Swift_TransportException $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message home about the blocked attempt to login.
|
||||
* Perhaps in a later stage, simply log these messages.
|
||||
*
|
||||
* @param User $user
|
||||
* @param string $code
|
||||
* @param string $ipAddress
|
||||
*/
|
||||
private function reportBlockedUserLoginAttempt(User $user, string $code, string $ipAddress)
|
||||
{
|
||||
|
||||
try {
|
||||
$email = env('SITE_OWNER', false);
|
||||
$fields = [
|
||||
'user_id' => $user->id,
|
||||
'user_address' => $user->email,
|
||||
'code' => $code,
|
||||
'ip' => $ipAddress,
|
||||
];
|
||||
|
||||
Mail::send(
|
||||
['emails.blocked-login-html', 'emails.blocked-login'], $fields, function (Message $message) use ($email, $user) {
|
||||
$message->to($email, $email)->subject('Blocked a login attempt from ' . trim($user->email) . '.');
|
||||
}
|
||||
);
|
||||
} catch (Swift_TransportException $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -11,7 +11,6 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers\Auth;
|
||||
|
||||
use Auth;
|
||||
use FireflyIII\Events\ResendConfirmation;
|
||||
use FireflyIII\Events\UserIsConfirmed;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
@@ -55,10 +54,10 @@ class ConfirmationController extends Controller
|
||||
if ($database === $code && ($now - $time <= $maxDiff)) {
|
||||
|
||||
// trigger user registration event:
|
||||
event(new UserIsConfirmed(Auth::user(), $request->ip()));
|
||||
event(new UserIsConfirmed(auth()->user(), $request->ip()));
|
||||
|
||||
Preferences::setForUser(Auth::user(), 'user_confirmed', true);
|
||||
Preferences::setForUser(Auth::user(), 'user_confirmed_confirmed', time());
|
||||
Preferences::setForUser(auth()->user(), 'user_confirmed', true);
|
||||
Preferences::setForUser(auth()->user(), 'user_confirmed_confirmed', time());
|
||||
Session::flash('success', strval(trans('firefly.account_is_confirmed')));
|
||||
|
||||
return redirect(route('home'));
|
||||
@@ -68,6 +67,8 @@ class ConfirmationController extends Controller
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function resendConfirmation(Request $request)
|
||||
{
|
||||
@@ -77,7 +78,7 @@ class ConfirmationController extends Controller
|
||||
$owner = env('SITE_OWNER', 'mail@example.com');
|
||||
$view = 'auth.confirmation.no-resent';
|
||||
if ($now - $time > $maxDiff) {
|
||||
event(new ResendConfirmation(Auth::user(), $request->ip()));
|
||||
event(new ResendConfirmation(auth()->user(), $request->ip()));
|
||||
$view = 'auth.confirmation.resent';
|
||||
}
|
||||
|
||||
|
34
app/Http/Controllers/Auth/ForgotPasswordController.php
Executable file
34
app/Http/Controllers/Auth/ForgotPasswordController.php
Executable file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* ForgotPasswordController.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers\Auth;
|
||||
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
|
||||
|
||||
/**
|
||||
* Class ForgotPasswordController
|
||||
*
|
||||
* @package FireflyIII\Http\Controllers\Auth
|
||||
*/
|
||||
class ForgotPasswordController extends Controller
|
||||
{
|
||||
use SendsPasswordResetEmails;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->middleware('guest');
|
||||
}
|
||||
}
|
195
app/Http/Controllers/Auth/LoginController.php
Executable file
195
app/Http/Controllers/Auth/LoginController.php
Executable file
@@ -0,0 +1,195 @@
|
||||
<?php
|
||||
/**
|
||||
* LoginController.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers\Auth;
|
||||
|
||||
use Config;
|
||||
use FireflyConfig;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Mail\Message;
|
||||
use Lang;
|
||||
use Log;
|
||||
use Mail;
|
||||
use Swift_TransportException;
|
||||
|
||||
/**
|
||||
* Class LoginController
|
||||
*
|
||||
* @package FireflyIII\Http\Controllers\Auth
|
||||
*/
|
||||
class LoginController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Login Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller handles authenticating users for the application and
|
||||
| redirecting them to your home screen. The controller uses a trait
|
||||
| to conveniently provide its functionality to your applications.
|
||||
|
|
||||
*/
|
||||
|
||||
use AuthenticatesUsers;
|
||||
|
||||
/**
|
||||
* Where to redirect users after login / registration.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = '/home';
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->middleware('guest', ['except' => 'logout']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a login request to the application.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function login(Request $request)
|
||||
{
|
||||
$this->validateLogin($request);
|
||||
|
||||
// If the class is using the ThrottlesLogins trait, we can automatically throttle
|
||||
// the login attempts for this application. We'll key this by the username and
|
||||
// the IP address of the client making these requests into this application.
|
||||
if ($lockedOut = $this->hasTooManyLoginAttempts($request)) {
|
||||
$this->fireLockoutEvent($request);
|
||||
|
||||
return $this->sendLockoutResponse($request);
|
||||
}
|
||||
|
||||
$credentials = $this->credentials($request);
|
||||
$credentials['blocked'] = 0; // most not be blocked.
|
||||
|
||||
if ($this->guard()->attempt($credentials, $request->has('remember'))) {
|
||||
return $this->sendLoginResponse($request);
|
||||
}
|
||||
|
||||
// check if user is blocked:
|
||||
$errorMessage = '';
|
||||
/** @var User $foundUser */
|
||||
$foundUser = User::where('email', $credentials['email'])->where('blocked', 1)->first();
|
||||
if (!is_null($foundUser)) {
|
||||
// if it exists, show message:
|
||||
$code = strlen(strval($foundUser->blocked_code)) > 0 ? $foundUser->blocked_code : 'general_blocked';
|
||||
$errorMessage = strval(trans('firefly.' . $code . '_error', ['email' => $credentials['email']]));
|
||||
$this->reportBlockedUserLoginAttempt($foundUser, $code, $request->ip());
|
||||
}
|
||||
|
||||
// If the login attempt was unsuccessful we will increment the number of attempts
|
||||
// to login and redirect the user back to the login form. Of course, when this
|
||||
// user surpasses their maximum number of attempts they will get locked out.
|
||||
if (!$lockedOut) {
|
||||
$this->incrementLoginAttempts($request);
|
||||
}
|
||||
|
||||
return $this->sendFailedLoginResponse($request, $errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the application login form.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function showLoginForm(Request $request)
|
||||
{
|
||||
// is allowed to?
|
||||
$singleUserMode = FireflyConfig::get('single_user_mode', Config::get('firefly.configuration.single_user_mode'))->data;
|
||||
$userCount = User::count();
|
||||
$allowRegistration = true;
|
||||
if ($singleUserMode === true && $userCount > 0) {
|
||||
$allowRegistration = false;
|
||||
}
|
||||
|
||||
$email = $request->old('email');
|
||||
$remember = $request->old('remember');
|
||||
|
||||
return view('auth.login', compact('allowRegistration', 'email', 'remember'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the failed login message.
|
||||
*
|
||||
* @param string $message
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getFailedLoginMessage(string $message)
|
||||
{
|
||||
if (strlen($message) > 0) {
|
||||
return $message;
|
||||
}
|
||||
|
||||
return Lang::has('auth.failed') ? Lang::get('auth.failed') : 'These credentials do not match our records.';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the failed login response instance.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param string $message
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
protected function sendFailedLoginResponse(Request $request, string $message)
|
||||
{
|
||||
return redirect()->back()
|
||||
->withInput($request->only($this->username(), 'remember'))
|
||||
->withErrors(
|
||||
[
|
||||
$this->username() => $this->getFailedLoginMessage($message),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message home about the blocked attempt to login.
|
||||
* Perhaps in a later stage, simply log these messages.
|
||||
*
|
||||
* @param User $user
|
||||
* @param string $code
|
||||
* @param string $ipAddress
|
||||
*/
|
||||
private function reportBlockedUserLoginAttempt(User $user, string $code, string $ipAddress)
|
||||
{
|
||||
|
||||
try {
|
||||
$email = env('SITE_OWNER', false);
|
||||
$fields = [
|
||||
'user_id' => $user->id,
|
||||
'user_address' => $user->email,
|
||||
'code' => $code,
|
||||
'ip' => $ipAddress,
|
||||
];
|
||||
|
||||
Mail::send(
|
||||
['emails.blocked-login-html', 'emails.blocked-login'], $fields, function (Message $message) use ($email, $user) {
|
||||
$message->to($email, $email)->subject('Blocked a login attempt from ' . trim($user->email) . '.');
|
||||
}
|
||||
);
|
||||
} catch (Swift_TransportException $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
@@ -23,6 +23,7 @@ use Illuminate\Support\Facades\Password;
|
||||
* Class PasswordController
|
||||
*
|
||||
* @package FireflyIII\Http\Controllers\Auth
|
||||
* @method getEmailSubject
|
||||
*/
|
||||
class PasswordController extends Controller
|
||||
{
|
||||
@@ -55,7 +56,7 @@ class PasswordController extends Controller
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function sendResetLinkEmail(Request $request)
|
||||
{
|
||||
|
224
app/Http/Controllers/Auth/RegisterController.php
Executable file
224
app/Http/Controllers/Auth/RegisterController.php
Executable file
@@ -0,0 +1,224 @@
|
||||
<?php
|
||||
/**
|
||||
* RegisterController.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers\Auth;
|
||||
|
||||
use Auth;
|
||||
use Config;
|
||||
use FireflyIII\Events\UserRegistration;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Support\Facades\FireflyConfig;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Foundation\Auth\RegistersUsers;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Mail\Message;
|
||||
use Log;
|
||||
use Mail;
|
||||
use Session;
|
||||
use Swift_TransportException;
|
||||
use Validator;
|
||||
|
||||
/**
|
||||
* Class RegisterController
|
||||
*
|
||||
* @package FireflyIII\Http\Controllers\Auth
|
||||
*/
|
||||
class RegisterController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Register Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller handles the registration of new users as well as their
|
||||
| validation and creation. By default this controller uses a trait to
|
||||
| provide this functionality without requiring any additional code.
|
||||
|
|
||||
*/
|
||||
|
||||
use RegistersUsers;
|
||||
|
||||
/**
|
||||
* Where to redirect users after login / registration.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = '/home';
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->middleware('guest');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
|
||||
*/
|
||||
public function register(Request $request)
|
||||
{
|
||||
// is allowed to?
|
||||
$singleUserMode = FireflyConfig::get('single_user_mode', Config::get('firefly.configuration.single_user_mode'))->data;
|
||||
$userCount = User::count();
|
||||
if ($singleUserMode === true && $userCount > 0) {
|
||||
$message = 'Registration is currently not available.';
|
||||
|
||||
return view('error', compact('message'));
|
||||
}
|
||||
|
||||
|
||||
$validator = $this->validator($request->all());
|
||||
|
||||
if ($validator->fails()) {
|
||||
$this->throwValidationException($request, $validator);
|
||||
}
|
||||
|
||||
$data = $request->all();
|
||||
$data['password'] = bcrypt($data['password']);
|
||||
|
||||
// is user email domain blocked?
|
||||
if ($this->isBlockedDomain($data['email'])) {
|
||||
$validator->getMessageBag()->add('email', (string)trans('validation.invalid_domain'));
|
||||
|
||||
$this->reportBlockedDomainRegistrationAttempt($data['email'], $request->ip());
|
||||
|
||||
$this->throwValidationException($request, $validator);
|
||||
}
|
||||
|
||||
|
||||
$user = $this->create($request->all());
|
||||
|
||||
// trigger user registration event:
|
||||
event(new UserRegistration($user, $request->ip()));
|
||||
|
||||
Auth::login($user);
|
||||
|
||||
Session::flash('success', strval(trans('firefly.registered')));
|
||||
Session::flash('gaEventCategory', 'user');
|
||||
Session::flash('gaEventAction', 'new-registration');
|
||||
|
||||
return redirect($this->redirectPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* OLD
|
||||
* Show the application registration form.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function showRegistrationForm(Request $request)
|
||||
{
|
||||
$showDemoWarning = config('firefly.show-demo-warning', false);
|
||||
|
||||
// is allowed to?
|
||||
$singleUserMode = FireflyConfig::get('single_user_mode', Config::get('firefly.configuration.single_user_mode'))->data;
|
||||
$userCount = User::count();
|
||||
if ($singleUserMode === true && $userCount > 0) {
|
||||
$message = 'Registration is currently not available.';
|
||||
|
||||
return view('error', compact('message'));
|
||||
}
|
||||
|
||||
$email = $request->old('email');
|
||||
|
||||
return view('auth.register', compact('showDemoWarning', 'email'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new user instance after a valid registration.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
protected function create(array $data)
|
||||
{
|
||||
return User::create(
|
||||
[
|
||||
'email' => $data['email'],
|
||||
'password' => bcrypt($data['password']),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a validator for an incoming registration request.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return \Illuminate\Contracts\Validation\Validator
|
||||
*/
|
||||
protected function validator(array $data)
|
||||
{
|
||||
return Validator::make(
|
||||
$data, [
|
||||
'email' => 'required|email|max:255|unique:users',
|
||||
'password' => 'required|min:6|confirmed',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function getBlockedDomains()
|
||||
{
|
||||
return FireflyConfig::get('blocked-domains', [])->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $email
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isBlockedDomain(string $email)
|
||||
{
|
||||
$parts = explode('@', $email);
|
||||
$blocked = $this->getBlockedDomains();
|
||||
|
||||
if (isset($parts[1]) && in_array($parts[1], $blocked)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message home about a blocked domain and the address attempted to register.
|
||||
*
|
||||
* @param string $registrationMail
|
||||
* @param string $ipAddress
|
||||
*/
|
||||
private function reportBlockedDomainRegistrationAttempt(string $registrationMail, string $ipAddress)
|
||||
{
|
||||
try {
|
||||
$email = env('SITE_OWNER', false);
|
||||
$parts = explode('@', $registrationMail);
|
||||
$domain = $parts[1];
|
||||
$fields = [
|
||||
'email_address' => $registrationMail,
|
||||
'blocked_domain' => $domain,
|
||||
'ip' => $ipAddress,
|
||||
];
|
||||
|
||||
Mail::send(
|
||||
['emails.blocked-registration-html', 'emails.blocked-registration'], $fields, function (Message $message) use ($email, $domain) {
|
||||
$message->to($email, $email)->subject('Blocked a registration attempt with domain ' . $domain . '.');
|
||||
}
|
||||
);
|
||||
} catch (Swift_TransportException $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
44
app/Http/Controllers/Auth/ResetPasswordController.php
Executable file
44
app/Http/Controllers/Auth/ResetPasswordController.php
Executable file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* ResetPasswordController.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers\Auth;
|
||||
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use Illuminate\Foundation\Auth\ResetsPasswords;
|
||||
|
||||
/**
|
||||
* Class ResetPasswordController
|
||||
*
|
||||
* @package FireflyIII\Http\Controllers\Auth
|
||||
*/
|
||||
class ResetPasswordController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Password Reset Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller is responsible for handling password reset requests
|
||||
| and uses a simple trait to include this behavior. You're free to
|
||||
| explore this trait and override any methods you wish to tweak.
|
||||
|
|
||||
*/
|
||||
|
||||
use ResetsPasswords;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest');
|
||||
}
|
||||
}
|
@@ -11,7 +11,6 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers\Auth;
|
||||
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
@@ -34,7 +33,7 @@ class TwoFactorController extends Controller
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$user = Auth::user();
|
||||
$user = auth()->user();
|
||||
|
||||
// to make sure the validator in the next step gets the secret, we push it in session
|
||||
$secret = Preferences::get('twoFactorAuthSecret', '')->data;
|
||||
@@ -54,7 +53,7 @@ class TwoFactorController extends Controller
|
||||
*/
|
||||
public function lostTwoFactor()
|
||||
{
|
||||
$user = Auth::user();
|
||||
$user = auth()->user();
|
||||
$siteOwner = env('SITE_OWNER', '');
|
||||
$title = strval(trans('firefly.two_factor_forgot_title'));
|
||||
|
||||
|
@@ -41,7 +41,7 @@ class BillController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\View\View
|
||||
* @return View
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
@@ -66,7 +66,7 @@ class BillController extends Controller
|
||||
/**
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
* @return View
|
||||
*/
|
||||
public function delete(Bill $bill)
|
||||
{
|
||||
@@ -99,7 +99,7 @@ class BillController extends Controller
|
||||
/**
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
* @return View
|
||||
*/
|
||||
public function edit(Bill $bill)
|
||||
{
|
||||
@@ -123,12 +123,14 @@ class BillController extends Controller
|
||||
/**
|
||||
* @param BillRepositoryInterface $repository
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
* @return View
|
||||
*/
|
||||
public function index(BillRepositoryInterface $repository)
|
||||
{
|
||||
/** @var Carbon $start */
|
||||
$start = session('start');
|
||||
$end = session('end');
|
||||
/** @var Carbon $end */
|
||||
$end = session('end');
|
||||
|
||||
$bills = $repository->getBills();
|
||||
$bills->each(
|
||||
@@ -187,7 +189,7 @@ class BillController extends Controller
|
||||
* @param BillRepositoryInterface $repository
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
* @return View
|
||||
*/
|
||||
public function show(BillRepositoryInterface $repository, Bill $bill)
|
||||
{
|
||||
@@ -195,7 +197,7 @@ class BillController extends Controller
|
||||
$date = session('start');
|
||||
$year = $date->year;
|
||||
$page = intval(Input::get('page')) == 0 ? 1 : intval(Input::get('page'));
|
||||
$pageSize = Preferences::get('transactionPageSize', 50)->data;
|
||||
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
|
||||
$journals = $repository->getJournals($bill, $page, $pageSize);
|
||||
$yearAverage = $repository->getYearAverage($bill, $date);
|
||||
$overallAverage = $repository->getOverallAverage($bill);
|
||||
|
@@ -12,7 +12,6 @@ declare(strict_types = 1);
|
||||
namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use Amount;
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use Config;
|
||||
use FireflyIII\Crud\Account\AccountCrudInterface;
|
||||
@@ -82,7 +81,7 @@ class BudgetController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\View\View
|
||||
* @return View
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
@@ -101,7 +100,7 @@ class BudgetController extends Controller
|
||||
/**
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
* @return View
|
||||
*/
|
||||
public function delete(Budget $budget)
|
||||
{
|
||||
@@ -138,7 +137,7 @@ class BudgetController extends Controller
|
||||
/**
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
* @return View
|
||||
*/
|
||||
public function edit(Budget $budget)
|
||||
{
|
||||
@@ -221,12 +220,11 @@ class BudgetController extends Controller
|
||||
}
|
||||
|
||||
|
||||
$budgetMaximum = Preferences::get('budgetMaximum', 1000)->data;
|
||||
$defaultCurrency = Amount::getDefaultCurrency();
|
||||
|
||||
return view(
|
||||
'budgets.index', compact(
|
||||
'budgetMaximum', 'periodStart', 'periodEnd',
|
||||
'periodStart', 'periodEnd',
|
||||
'period', 'range', 'budgetIncomeTotal',
|
||||
'defaultCurrency', 'inactive', 'budgets',
|
||||
'spent', 'budgeted'
|
||||
@@ -237,7 +235,7 @@ class BudgetController extends Controller
|
||||
/**
|
||||
* @param BudgetRepositoryInterface $repository
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
* @return View
|
||||
*/
|
||||
public function noBudget(BudgetRepositoryInterface $repository)
|
||||
{
|
||||
@@ -360,7 +358,7 @@ class BudgetController extends Controller
|
||||
{
|
||||
$budgetData = [
|
||||
'name' => $request->input('name'),
|
||||
'user' => Auth::user()->id,
|
||||
'user' => auth()->user()->id,
|
||||
];
|
||||
$budget = $repository->store($budgetData);
|
||||
|
||||
@@ -411,7 +409,7 @@ class BudgetController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\View\View
|
||||
* @return View
|
||||
*/
|
||||
public function updateIncome()
|
||||
{
|
||||
|
@@ -11,7 +11,6 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Crud\Account\AccountCrudInterface;
|
||||
use FireflyIII\Http\Requests\CategoryFormRequest;
|
||||
@@ -47,7 +46,7 @@ class CategoryController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\View\View
|
||||
* @return View
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
@@ -66,7 +65,7 @@ class CategoryController extends Controller
|
||||
/**
|
||||
* @param Category $category
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
* @return View
|
||||
*/
|
||||
public function delete(Category $category)
|
||||
{
|
||||
@@ -101,7 +100,7 @@ class CategoryController extends Controller
|
||||
/**
|
||||
* @param Category $category
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
* @return View
|
||||
*/
|
||||
public function edit(Category $category)
|
||||
{
|
||||
@@ -122,7 +121,7 @@ class CategoryController extends Controller
|
||||
/**
|
||||
* @param CRI $repository
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
* @return View
|
||||
*/
|
||||
public function index(CRI $repository)
|
||||
{
|
||||
@@ -140,7 +139,7 @@ class CategoryController extends Controller
|
||||
/**
|
||||
* @param CRI $repository
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
* @return View
|
||||
*/
|
||||
public function noCategory(CRI $repository)
|
||||
{
|
||||
@@ -166,9 +165,10 @@ class CategoryController extends Controller
|
||||
*/
|
||||
public function show(CRI $repository, AccountCrudInterface $crud, Category $category)
|
||||
{
|
||||
/** @var Carbon $carbon */
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
$start = session('start', Navigation::startOfPeriod(new Carbon, $range));
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
/** @var Carbon $start */
|
||||
$start = session('start', Navigation::startOfPeriod(new Carbon, $range));
|
||||
/** @var Carbon $end */
|
||||
$end = session('end', Navigation::endOfPeriod(new Carbon, $range));
|
||||
$hideCategory = true; // used in list.
|
||||
$page = intval(Input::get('page'));
|
||||
@@ -183,7 +183,7 @@ class CategoryController extends Controller
|
||||
$journals->setPath('categories/show/' . $category->id);
|
||||
|
||||
// oldest transaction in category:
|
||||
$start = $repository->firstUseDate($category, new Collection);
|
||||
$start = $repository->firstUseDate($category);
|
||||
if ($start->year == 1900) {
|
||||
$start = new Carbon;
|
||||
}
|
||||
@@ -232,7 +232,7 @@ class CategoryController extends Controller
|
||||
*
|
||||
* @param $date
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
* @return View
|
||||
*/
|
||||
public function showWithDate(CRI $repository, Category $category, string $date)
|
||||
{
|
||||
@@ -264,7 +264,7 @@ class CategoryController extends Controller
|
||||
{
|
||||
$categoryData = [
|
||||
'name' => $request->input('name'),
|
||||
'user' => Auth::user()->id,
|
||||
'user' => auth()->user()->id,
|
||||
];
|
||||
$category = $repository->store($categoryData);
|
||||
|
||||
|
@@ -20,6 +20,7 @@ use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Navigation;
|
||||
use Preferences;
|
||||
use Response;
|
||||
@@ -35,19 +36,14 @@ class BudgetController extends Controller
|
||||
/** @var BudgetChartGeneratorInterface */
|
||||
protected $generator;
|
||||
|
||||
/** @var BudgetRepositoryInterface */
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
*
|
||||
* BudgetController constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
// create chart generator:
|
||||
$this->generator = app(BudgetChartGeneratorInterface::class);
|
||||
|
||||
$this->repository = app(BudgetRepositoryInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -143,8 +139,9 @@ class BudgetController extends Controller
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function frontpage()
|
||||
public function frontpage(BudgetRepositoryInterface $repository)
|
||||
{
|
||||
Log::debug('Hello');
|
||||
$start = session('start', Carbon::now()->startOfMonth());
|
||||
$end = session('end', Carbon::now()->endOfMonth());
|
||||
// chart properties for cache:
|
||||
@@ -156,8 +153,8 @@ class BudgetController extends Controller
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
$budgets = $this->repository->getActiveBudgets();
|
||||
$repetitions = $this->repository->getAllBudgetLimitRepetitions($start, $end);
|
||||
$budgets = $repository->getActiveBudgets();
|
||||
$repetitions = $repository->getAllBudgetLimitRepetitions($start, $end);
|
||||
$allEntries = new Collection;
|
||||
|
||||
/** @var Budget $budget */
|
||||
@@ -166,15 +163,15 @@ class BudgetController extends Controller
|
||||
$reps = $this->filterRepetitions($repetitions, $budget, $start, $end);
|
||||
|
||||
if ($reps->count() === 0) {
|
||||
$collection = $this->spentInPeriodSingle($budget, $start, $end);
|
||||
$collection = $this->spentInPeriodSingle($repository, $budget, $start, $end);
|
||||
$allEntries = $allEntries->merge($collection);
|
||||
continue;
|
||||
}
|
||||
$collection = $this->spentInPeriodMulti($budget, $reps);
|
||||
$collection = $this->spentInPeriodMulti($repository, $budget, $reps);
|
||||
$allEntries = $allEntries->merge($collection);
|
||||
|
||||
}
|
||||
$entry = $this->spentInPeriodWithout($start, $end);
|
||||
$entry = $this->spentInPeriodWithout($repository, $start, $end);
|
||||
$allEntries->push($entry);
|
||||
$data = $this->generator->frontpage($allEntries);
|
||||
$cache->store($data);
|
||||
@@ -214,8 +211,10 @@ class BudgetController extends Controller
|
||||
$repetitions = $repetitions->filter(
|
||||
function (LimitRepetition $repetition) use ($budgetIds) {
|
||||
if (in_array(strval($repetition->budget_id), $budgetIds)) {
|
||||
return $repetition;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
);
|
||||
/** @var LimitRepetition $repetition */
|
||||
@@ -289,8 +288,10 @@ class BudgetController extends Controller
|
||||
$reps = $repetitions->filter(
|
||||
function (LimitRepetition $repetition) use ($budget, $currentStart) {
|
||||
if ($repetition->budget_id === $budget->id && $repetition->startdate == $currentStart) {
|
||||
return $repetition;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
);
|
||||
$budgeted = $reps->sum('amount');
|
||||
@@ -325,26 +326,29 @@ class BudgetController extends Controller
|
||||
return $repetitions->filter(
|
||||
function (LimitRepetition $repetition) use ($budget, $start, $end) {
|
||||
if ($repetition->startdate < $end && $repetition->enddate > $start && $repetition->budget_id === $budget->id) {
|
||||
return $repetition;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
* @param Collection $repetitions
|
||||
* @param BudgetRepositoryInterface $repository
|
||||
* @param Budget $budget
|
||||
* @param Collection $repetitions
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
private function spentInPeriodMulti(Budget $budget, Collection $repetitions): Collection
|
||||
private function spentInPeriodMulti(BudgetRepositoryInterface $repository, Budget $budget, Collection $repetitions): Collection
|
||||
{
|
||||
$format = strval(trans('config.month_and_day'));
|
||||
$collection = new Collection;
|
||||
$name = $budget->name;
|
||||
/** @var LimitRepetition $repetition */
|
||||
foreach ($repetitions as $repetition) {
|
||||
$expenses = $this->repository->spentInPeriod(new Collection([$budget]), new Collection, $repetition->startdate, $repetition->enddate);
|
||||
$expenses = $repository->spentInPeriod(new Collection([$budget]), new Collection, $repetition->startdate, $repetition->enddate);
|
||||
|
||||
if ($repetitions->count() > 1) {
|
||||
$name = $budget->name . ' ' . trans(
|
||||
@@ -364,18 +368,19 @@ class BudgetController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param BudgetRepositoryInterface $repository
|
||||
* @param Budget $budget
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
private function spentInPeriodSingle(Budget $budget, Carbon $start, Carbon $end): Collection
|
||||
private function spentInPeriodSingle(BudgetRepositoryInterface $repository, Budget $budget, Carbon $start, Carbon $end): Collection
|
||||
{
|
||||
$collection = new Collection;
|
||||
$amount = '0';
|
||||
$left = '0';
|
||||
$spent = $this->repository->spentInPeriod(new Collection([$budget]), new Collection, $start, $end);
|
||||
$spent = $repository->spentInPeriod(new Collection([$budget]), new Collection, $start, $end);
|
||||
$overspent = '0';
|
||||
$array = [$budget->name, $left, $spent, $overspent, $amount, $spent];
|
||||
$collection->push($array);
|
||||
@@ -384,14 +389,15 @@ class BudgetController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param BudgetRepositoryInterface $repository
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function spentInPeriodWithout(Carbon $start, Carbon $end):array
|
||||
private function spentInPeriodWithout(BudgetRepositoryInterface $repository, Carbon $start, Carbon $end):array
|
||||
{
|
||||
$list = $this->repository->journalsInPeriodWithoutBudget(new Collection, $start, $end);
|
||||
$list = $repository->journalsInPeriodWithoutBudget(new Collection, $start, $end);
|
||||
$sum = '0';
|
||||
/** @var TransactionJournal $entry */
|
||||
foreach ($list as $entry) {
|
||||
|
@@ -58,7 +58,7 @@ class CategoryController extends Controller
|
||||
*/
|
||||
public function all(CRI $repository, AccountCrudInterface $crud, Category $category)
|
||||
{
|
||||
$start = $repository->firstUseDate($category, new Collection);
|
||||
$start = $repository->firstUseDate($category);
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
$start = Navigation::startOfPeriod($start, $range);
|
||||
$categoryCollection = new Collection([$category]);
|
||||
@@ -108,13 +108,12 @@ class CategoryController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Show this month's category overview.
|
||||
* @param CRI $repository
|
||||
* @param AccountCrudInterface $crud
|
||||
*
|
||||
* @param CRI $repository
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function frontpage(CRI $repository)
|
||||
public function frontpage(CRI $repository, AccountCrudInterface $crud)
|
||||
{
|
||||
$start = session('start', Carbon::now()->startOfMonth());
|
||||
$end = session('end', Carbon::now()->endOfMonth());
|
||||
@@ -128,10 +127,11 @@ class CategoryController extends Controller
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
$categories = $repository->getCategories();
|
||||
$accounts = $crud->getAccountsByType([AccountType::ASSET, AccountType::DEFAULT]);
|
||||
$set = new Collection;
|
||||
/** @var Category $category */
|
||||
foreach ($categories as $category) {
|
||||
$spent = $repository->spentInPeriod(new Collection([$category]), new Collection, $start, $end);
|
||||
$spent = $repository->spentInPeriod(new Collection([$category]), $accounts, $start, $end);
|
||||
if (bccomp($spent, '0') === -1) {
|
||||
$category->spent = $spent;
|
||||
$set->push($category);
|
||||
|
38
app/Http/Controllers/Controller.php
Normal file → Executable file
38
app/Http/Controllers/Controller.php
Normal file → Executable file
@@ -11,15 +11,11 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use App;
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
use NumberFormatter;
|
||||
use Preferences;
|
||||
use View;
|
||||
|
||||
/**
|
||||
@@ -48,36 +44,11 @@ class Controller extends BaseController
|
||||
View::share('hideBills', false);
|
||||
View::share('hideTags', false);
|
||||
|
||||
if (Auth::check()) {
|
||||
$pref = Preferences::get('language', env('DEFAULT_LANGUAGE', 'en_US'));
|
||||
$lang = $pref->data;
|
||||
// save some formats:
|
||||
$this->monthFormat = (string)trans('config.month');
|
||||
$this->monthAndDayFormat = (string)trans('config.month_and_day');
|
||||
$this->dateTimeFormat = (string)trans('config.date_time');
|
||||
|
||||
App::setLocale($lang);
|
||||
Carbon::setLocale(substr($lang, 0, 2));
|
||||
$locale = explode(',', trans('config.locale'));
|
||||
$locale = array_map('trim', $locale);
|
||||
|
||||
setlocale(LC_TIME, $locale);
|
||||
setlocale(LC_MONETARY, $locale);
|
||||
|
||||
// save some formats:
|
||||
$this->monthFormat = (string)trans('config.month');
|
||||
$this->monthAndDayFormat = (string)trans('config.month_and_day');
|
||||
$this->dateTimeFormat = (string)trans('config.date_time');
|
||||
|
||||
// change localeconv to a new array:
|
||||
$numberFormatter = numfmt_create($lang, NumberFormatter::CURRENCY);
|
||||
$localeconv = [
|
||||
'mon_decimal_point' => $numberFormatter->getSymbol($numberFormatter->getAttribute(NumberFormatter::DECIMAL_SEPARATOR_SYMBOL)),
|
||||
'mon_thousands_sep' => $numberFormatter->getSymbol($numberFormatter->getAttribute(NumberFormatter::MONETARY_GROUPING_SEPARATOR_SYMBOL)),
|
||||
'frac_digits' => $numberFormatter->getAttribute(NumberFormatter::MAX_FRACTION_DIGITS),
|
||||
];
|
||||
View::share('monthFormat', $this->monthFormat);
|
||||
View::share('monthAndDayFormat', $this->monthAndDayFormat);
|
||||
View::share('dateTimeFormat', $this->dateTimeFormat);
|
||||
View::share('language', $lang);
|
||||
View::share('localeconv', $localeconv);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,5 +78,4 @@ class Controller extends BaseController
|
||||
return $sum;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -11,7 +11,6 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use Auth;
|
||||
use Cache;
|
||||
use FireflyIII\Http\Requests\CurrencyFormRequest;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
@@ -43,7 +42,7 @@ class CurrencyController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\View\View
|
||||
* @return View
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
@@ -81,20 +80,19 @@ class CurrencyController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CurrencyRepositoryInterface $repository
|
||||
* @param TransactionCurrency $currency
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|View
|
||||
*/
|
||||
public function delete(CurrencyRepositoryInterface $repository, TransactionCurrency $currency)
|
||||
public function delete(TransactionCurrency $currency)
|
||||
{
|
||||
|
||||
if ($repository->countJournals($currency) > 0) {
|
||||
if (!$this->canDeleteCurrency($currency)) {
|
||||
Session::flash('error', trans('firefly.cannot_delete_currency', ['name' => $currency->name]));
|
||||
|
||||
return redirect(route('currency.index'));
|
||||
}
|
||||
|
||||
|
||||
// put previous url in session
|
||||
Session::put('currency.delete.url', URL::previous());
|
||||
Session::flash('gaEventCategory', 'currency');
|
||||
@@ -106,22 +104,21 @@ class CurrencyController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CurrencyRepositoryInterface $repository
|
||||
* @param TransactionCurrency $currency
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function destroy(CurrencyRepositoryInterface $repository, TransactionCurrency $currency)
|
||||
public function destroy(TransactionCurrency $currency)
|
||||
{
|
||||
if ($repository->countJournals($currency) > 0) {
|
||||
if (!$this->canDeleteCurrency($currency)) {
|
||||
Session::flash('error', trans('firefly.cannot_delete_currency', ['name' => $currency->name]));
|
||||
|
||||
return redirect(route('currency.index'));
|
||||
}
|
||||
|
||||
Session::flash('success', trans('firefly.deleted_currency', ['name' => $currency->name]));
|
||||
if (Auth::user()->hasRole('owner')) {
|
||||
if (auth()->user()->hasRole('owner')) {
|
||||
$currency->delete();
|
||||
}
|
||||
|
||||
@@ -131,12 +128,12 @@ class CurrencyController extends Controller
|
||||
/**
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
* @return View
|
||||
*/
|
||||
public function edit(TransactionCurrency $currency)
|
||||
{
|
||||
$subTitleIcon = 'fa-pencil';
|
||||
$subTitle = trans('firefly.edit_currency', ['name' => $currency->name]);
|
||||
$subTitle = trans('breadcrumbs.edit_currency', ['name' => $currency->name]);
|
||||
$currency->symbol = htmlentities($currency->symbol);
|
||||
|
||||
// put previous url in session if not redirect from store (not "return_to_edit").
|
||||
@@ -154,15 +151,15 @@ class CurrencyController extends Controller
|
||||
/**
|
||||
* @param CurrencyRepositoryInterface $repository
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
* @return View
|
||||
*/
|
||||
public function index(CurrencyRepositoryInterface $repository)
|
||||
{
|
||||
$currencies = $repository->get();
|
||||
$defaultCurrency = $repository->getCurrencyByPreference(Preferences::get('currencyPreference', env('DEFAULT_CURRENCY', 'EUR')));
|
||||
$defaultCurrency = $repository->getCurrencyByPreference(Preferences::get('currencyPreference', config('firefly.default_currency', 'EUR')));
|
||||
|
||||
|
||||
if (!Auth::user()->hasRole('owner')) {
|
||||
if (!auth()->user()->hasRole('owner')) {
|
||||
Session::flash('warning', trans('firefly.ask_site_owner', ['owner' => env('SITE_OWNER')]));
|
||||
}
|
||||
|
||||
@@ -175,12 +172,12 @@ class CurrencyController extends Controller
|
||||
* @param CurrencyFormRequest $request
|
||||
* @param CurrencyRepositoryInterface $repository
|
||||
*
|
||||
* @return $this|\Illuminate\Http\RedirectResponse
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function store(CurrencyFormRequest $request, CurrencyRepositoryInterface $repository)
|
||||
{
|
||||
if (!Auth::user()->hasRole('owner')) {
|
||||
Log::error('User ' . Auth::user()->id . ' is not admin, but tried to store a currency.');
|
||||
if (!auth()->user()->hasRole('owner')) {
|
||||
Log::error('User ' . auth()->user()->id . ' is not admin, but tried to store a currency.');
|
||||
|
||||
return redirect(session('currency.create.url'));
|
||||
}
|
||||
@@ -211,7 +208,7 @@ class CurrencyController extends Controller
|
||||
public function update(CurrencyFormRequest $request, CurrencyRepositoryInterface $repository, TransactionCurrency $currency)
|
||||
{
|
||||
$data = $request->getCurrencyData();
|
||||
if (Auth::user()->hasRole('owner')) {
|
||||
if (auth()->user()->hasRole('owner')) {
|
||||
$currency = $repository->update($currency, $data);
|
||||
}
|
||||
Session::flash('success', trans('firefly.updated_currency', ['name' => $currency->name]));
|
||||
@@ -229,4 +226,39 @@ class CurrencyController extends Controller
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function canDeleteCurrency(TransactionCurrency $currency): bool
|
||||
{
|
||||
$repository = app(CurrencyRepositoryInterface::class);
|
||||
|
||||
// has transactions still
|
||||
if ($repository->countJournals($currency) > 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// is the only currency left
|
||||
if ($repository->get()->count() === 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// is the default currency for the user or the system
|
||||
$defaultCode = Preferences::get('currencyPreference', config('firefly.default_currency', 'EUR'))->data;
|
||||
if ($currency->code === $defaultCode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// is the default currency for the system
|
||||
$defaultSystemCode = config('firefly.default_currency', 'EUR');
|
||||
if ($currency->code === $defaultSystemCode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// can be deleted
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -10,7 +10,6 @@
|
||||
declare(strict_types = 1);
|
||||
|
||||
|
||||
|
||||
namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
@@ -18,7 +17,6 @@ use ExpandedForm;
|
||||
use FireflyIII\Crud\Account\AccountCrudInterface;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Export\Processor;
|
||||
use FireflyIII\Http\Requests;
|
||||
use FireflyIII\Http\Requests\ExportFormRequest;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\ExportJob;
|
||||
@@ -94,7 +92,7 @@ class ExportController extends Controller
|
||||
* @param AccountCrudInterface $crud
|
||||
* @param EJRI $jobs
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
* @return View
|
||||
*/
|
||||
public function index(AccountCrudInterface $crud, EJRI $jobs)
|
||||
{
|
||||
|
@@ -39,7 +39,7 @@ class HelpController extends Controller
|
||||
*/
|
||||
public function show(HelpInterface $help, string $route)
|
||||
{
|
||||
$language = Preferences::get('language', env('DEFAULT_LANGUAGE', 'en_US'))->data;
|
||||
$language = Preferences::get('language', config('firefly.default_language', 'en_US'))->data;
|
||||
$content = [
|
||||
'text' => '<p>' . strval(trans('firefly.route_has_no_help')) . '</p>',
|
||||
'title' => 'Help',
|
||||
|
@@ -97,7 +97,7 @@ class HomeController extends Controller
|
||||
|
||||
/** @var Tag $tag */
|
||||
foreach ($tags as $tag) {
|
||||
foreach ($tag->transactionjournals()->get() as $journal) {
|
||||
foreach ($tag->transactionJournals()->get() as $journal) {
|
||||
$count = $journal->tags()->count();
|
||||
$journal->tag_count = $count;
|
||||
$journal->save();
|
||||
@@ -222,4 +222,5 @@ class HomeController extends Controller
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers;
|
||||
|
||||
@@ -263,7 +264,7 @@ class ImportController extends Controller
|
||||
*
|
||||
* @param ImportJob $job
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
* @return View
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function settings(ImportJob $job)
|
||||
@@ -305,8 +306,9 @@ class ImportController extends Controller
|
||||
*/
|
||||
public function start(ImportJob $job)
|
||||
{
|
||||
if ($job->status == "settings_complete") {
|
||||
ImportProcedure::run($job);
|
||||
set_time_limit(0);
|
||||
if ($job->status == 'settings_complete') {
|
||||
ImportProcedure::runImport($job);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -414,16 +416,25 @@ class ImportController extends Controller
|
||||
* @param ImportJob $job
|
||||
*
|
||||
* @return SetupInterface
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function makeImporter(ImportJob $job): SetupInterface
|
||||
{
|
||||
// create proper importer (depends on job)
|
||||
$type = $job->file_type;
|
||||
/** @var SetupInterface $importer */
|
||||
$importer = app('FireflyIII\Import\Setup\\' . ucfirst($type) . 'Setup');
|
||||
$importer->setJob($job);
|
||||
$type = strtolower($job->file_type);
|
||||
|
||||
return $importer;
|
||||
// validate type:
|
||||
$validTypes = array_keys(config('firefly.import_formats'));
|
||||
|
||||
|
||||
if (in_array($type, $validTypes)) {
|
||||
/** @var SetupInterface $importer */
|
||||
$importer = app('FireflyIII\Import\Setup\\' . ucfirst($type) . 'Setup');
|
||||
$importer->setJob($job);
|
||||
|
||||
return $importer;
|
||||
}
|
||||
throw new FireflyException(sprintf('"%s" is not a valid file type', $type));
|
||||
|
||||
}
|
||||
|
||||
@@ -449,8 +460,7 @@ class ImportController extends Controller
|
||||
Log::debug('Will redirect to complete()');
|
||||
|
||||
return redirect(route('import.complete', [$job->key]));
|
||||
case
|
||||
'import_complete':
|
||||
case 'import_complete':
|
||||
Log::debug('Will redirect to finished()');
|
||||
|
||||
return redirect(route('import.finished', [$job->key]));
|
||||
|
@@ -10,7 +10,6 @@
|
||||
declare(strict_types = 1);
|
||||
namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Crud\Account\AccountCrudInterface;
|
||||
use FireflyIII\Http\Requests\NewUserFormRequest;
|
||||
@@ -38,12 +37,12 @@ class NewUserController extends Controller
|
||||
/**
|
||||
* @param ARI $repository
|
||||
*
|
||||
* @@return \Illuminate\Http\RedirectResponse|\Illuminate\View\View
|
||||
* @@return View
|
||||
*/
|
||||
public function index(ARI $repository)
|
||||
{
|
||||
|
||||
View::share('title', 'Welcome to Firefly!');
|
||||
View::share('title', trans('firefly.welcome'));
|
||||
View::share('mainTitleIcon', 'fa-fire');
|
||||
|
||||
|
||||
@@ -107,7 +106,7 @@ class NewUserController extends Controller
|
||||
'accountType' => 'asset',
|
||||
'virtualBalance' => 0,
|
||||
'active' => true,
|
||||
'user' => Auth::user()->id,
|
||||
'user' => auth()->user()->id,
|
||||
'accountRole' => 'defaultAsset',
|
||||
'openingBalance' => round($request->input('bank_balance'), 2),
|
||||
'openingBalanceDate' => new Carbon,
|
||||
@@ -133,7 +132,7 @@ class NewUserController extends Controller
|
||||
'accountType' => 'asset',
|
||||
'virtualBalance' => 0,
|
||||
'active' => true,
|
||||
'user' => Auth::user()->id,
|
||||
'user' => auth()->user()->id,
|
||||
'accountRole' => 'savingAsset',
|
||||
'openingBalance' => round($request->input('savings_balance'), 2),
|
||||
'openingBalanceDate' => new Carbon,
|
||||
@@ -158,7 +157,7 @@ class NewUserController extends Controller
|
||||
'accountType' => 'asset',
|
||||
'virtualBalance' => round($request->get('credit_card_limit'), 2),
|
||||
'active' => true,
|
||||
'user' => Auth::user()->id,
|
||||
'user' => auth()->user()->id,
|
||||
'accountRole' => 'ccAsset',
|
||||
'openingBalance' => null,
|
||||
'openingBalanceDate' => null,
|
||||
|
@@ -54,7 +54,7 @@ class PiggyBankController extends Controller
|
||||
* @param ARI $repository
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return $this
|
||||
* @return View
|
||||
*/
|
||||
public function add(ARI $repository, PiggyBank $piggyBank)
|
||||
{
|
||||
@@ -74,7 +74,7 @@ class PiggyBankController extends Controller
|
||||
* @param ARI $repository
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return $this
|
||||
* @return View
|
||||
*/
|
||||
public function addMobile(ARI $repository, PiggyBank $piggyBank)
|
||||
{
|
||||
@@ -113,7 +113,7 @@ class PiggyBankController extends Controller
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return $this
|
||||
* @return View
|
||||
*/
|
||||
public function delete(PiggyBank $piggyBank)
|
||||
{
|
||||
@@ -253,7 +253,8 @@ class PiggyBankController extends Controller
|
||||
*/
|
||||
public function postAdd(PiggyBankRepositoryInterface $repository, ARI $accounts, PiggyBank $piggyBank)
|
||||
{
|
||||
$amount = strval(round(Input::get('amount'), 2));
|
||||
$amount = strval(round(Input::get('amount'), 2));
|
||||
/** @var Carbon $date */
|
||||
$date = session('end', Carbon::now()->endOfMonth());
|
||||
$leftOnAccount = $accounts->leftOnAccount($piggyBank->account, $date);
|
||||
$savedSoFar = strval($piggyBank->currentRelevantRep()->currentamount);
|
||||
@@ -320,7 +321,7 @@ class PiggyBankController extends Controller
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
* @return View
|
||||
*/
|
||||
public function remove(PiggyBank $piggyBank)
|
||||
{
|
||||
@@ -332,7 +333,7 @@ class PiggyBankController extends Controller
|
||||
*
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return $this
|
||||
* @return View
|
||||
*/
|
||||
public function removeMobile(PiggyBank $piggyBank)
|
||||
{
|
||||
@@ -358,7 +359,7 @@ class PiggyBankController extends Controller
|
||||
* @param PiggyBankFormRequest $request
|
||||
* @param PiggyBankRepositoryInterface $repository
|
||||
*
|
||||
* @return $this|\Illuminate\Http\RedirectResponse
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function store(PiggyBankFormRequest $request, PiggyBankRepositoryInterface $repository)
|
||||
{
|
||||
|
@@ -13,6 +13,7 @@ namespace FireflyIII\Http\Controllers\Popup;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Crud\Account\AccountCrudInterface;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Helpers\Collection\BalanceLine;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
@@ -110,8 +111,10 @@ class ReportController extends Controller
|
||||
function (TransactionJournal $journal) {
|
||||
$tags = $journal->tags()->where('tagMode', 'balancingAct')->count();
|
||||
if ($tags === 0) {
|
||||
return $journal;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
);
|
||||
break;
|
||||
@@ -182,7 +185,7 @@ class ReportController extends Controller
|
||||
{
|
||||
/** @var AccountRepositoryInterface $repository */
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$crud = app('FireflyIII\Crud\Account\AccountCrudInterface');
|
||||
$crud = app(AccountCrudInterface::class);
|
||||
$account = $crud->find(intval($attributes['accountId']));
|
||||
$types = [TransactionType::WITHDRAWAL, TransactionType::TRANSFER];
|
||||
$journals = $repository->journalsInPeriod($attributes['accounts'], $types, $attributes['startDate'], $attributes['endDate']);
|
||||
@@ -190,9 +193,12 @@ class ReportController extends Controller
|
||||
// filter for transfers and withdrawals TO the given $account
|
||||
$journals = $journals->filter(
|
||||
function (TransactionJournal $journal) use ($account) {
|
||||
if ($journal->destination_account_id === $account->id) {
|
||||
return $journal;
|
||||
$destinations = TransactionJournal::destinationAccountList($journal)->pluck('id')->toArray();
|
||||
if (in_array($account->id, $destinations)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
);
|
||||
|
||||
@@ -219,14 +225,19 @@ class ReportController extends Controller
|
||||
$journals = $repository->journalsInPeriod(new Collection([$account]), $types, $attributes['startDate'], $attributes['endDate']);
|
||||
$destinations = $attributes['accounts']->pluck('id')->toArray();
|
||||
// filter for transfers and withdrawals FROM the given $account
|
||||
|
||||
$journals = $journals->filter(
|
||||
function (TransactionJournal $journal) use ($account, $destinations) {
|
||||
$currentSources = TransactionJournal::sourceAccountList($journal)->pluck('id')->toArray();
|
||||
$currentDest = TransactionJournal::destinationAccountList($journal)->pluck('id')->toArray();
|
||||
if (
|
||||
$journal->source_account_id === $account->id
|
||||
&& in_array($journal->destination_account_id, $destinations)
|
||||
!empty(array_intersect([$account->id], $currentSources))
|
||||
&& !empty(array_intersect($destinations, $currentDest))
|
||||
) {
|
||||
return $journal;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
);
|
||||
|
||||
|
@@ -10,11 +10,10 @@
|
||||
declare(strict_types = 1);
|
||||
namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use Auth;
|
||||
use FireflyIII\Crud\Account\AccountCrudInterface;
|
||||
use FireflyIII\Http\Requests\TokenFormRequest;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use Input;
|
||||
use Illuminate\Http\Request;
|
||||
use PragmaRX\Google2FA\Contracts\Google2FA;
|
||||
use Preferences;
|
||||
use Session;
|
||||
@@ -46,7 +45,8 @@ class PreferencesController extends Controller
|
||||
public function code(Google2FA $google2fa)
|
||||
{
|
||||
$domain = $this->getDomain();
|
||||
$secret = $google2fa->generateSecretKey(16, Auth::user()->id);
|
||||
/** @noinspection PhpMethodParametersCountMismatchInspection */
|
||||
$secret = $google2fa->generateSecretKey(16, auth()->user()->id);
|
||||
Session::flash('two-factor-secret', $secret);
|
||||
$image = $google2fa->getQRCodeInline('Firefly III at ' . $domain, null, $secret, 150);
|
||||
|
||||
@@ -78,13 +78,12 @@ class PreferencesController extends Controller
|
||||
$viewRangePref = Preferences::get('viewRange', '1M');
|
||||
$viewRange = $viewRangePref->data;
|
||||
$frontPageAccounts = Preferences::get('frontPageAccounts', []);
|
||||
$budgetMax = Preferences::get('budgetMaximum', 1000);
|
||||
$language = Preferences::get('language', env('DEFAULT_LANGUAGE', 'en_US'))->data;
|
||||
$budgetMaximum = $budgetMax->data;
|
||||
$language = Preferences::get('language', config('firefly.default_language', 'en_US'))->data;
|
||||
$transactionPageSize = Preferences::get('transactionPageSize', 50)->data;
|
||||
$customFiscalYear = Preferences::get('customFiscalYear', 0)->data;
|
||||
$fiscalYearStartStr = Preferences::get('fiscalYearStart', '01-01')->data;
|
||||
$fiscalYearStart = date('Y') . '-' . $fiscalYearStartStr;
|
||||
$tjOptionalFields = Preferences::get('transaction_journal_optional_fields', [])->data;
|
||||
$is2faEnabled = Preferences::get('twoFactorAuthEnabled', 0)->data; // twoFactorAuthEnabled
|
||||
$has2faSecret = !is_null(Preferences::get('twoFactorAuthSecret')); // hasTwoFactorAuthSecret
|
||||
$showIncomplete = env('SHOW_INCOMPLETE_TRANSLATIONS', false) === true;
|
||||
@@ -92,7 +91,7 @@ class PreferencesController extends Controller
|
||||
return view(
|
||||
'preferences.index',
|
||||
compact(
|
||||
'budgetMaximum', 'language', 'accounts', 'frontPageAccounts',
|
||||
'language', 'accounts', 'frontPageAccounts', 'tjOptionalFields',
|
||||
'viewRange', 'customFiscalYear', 'transactionPageSize', 'fiscalYearStart', 'is2faEnabled',
|
||||
'has2faSecret', 'showIncomplete'
|
||||
)
|
||||
@@ -116,38 +115,36 @@ class PreferencesController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @param Request $request
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function postIndex()
|
||||
public function postIndex(Request $request)
|
||||
{
|
||||
// front page accounts
|
||||
$frontPageAccounts = [];
|
||||
if (is_array(Input::get('frontPageAccounts'))) {
|
||||
foreach (Input::get('frontPageAccounts') as $id) {
|
||||
if (is_array($request->get('frontPageAccounts'))) {
|
||||
foreach ($request->get('frontPageAccounts') as $id) {
|
||||
$frontPageAccounts[] = intval($id);
|
||||
}
|
||||
Preferences::set('frontPageAccounts', $frontPageAccounts);
|
||||
}
|
||||
|
||||
// view range:
|
||||
Preferences::set('viewRange', Input::get('viewRange'));
|
||||
Preferences::set('viewRange', $request->get('viewRange'));
|
||||
// forget session values:
|
||||
Session::forget('start');
|
||||
Session::forget('end');
|
||||
Session::forget('range');
|
||||
|
||||
// budget maximum:
|
||||
$budgetMaximum = intval(Input::get('budgetMaximum'));
|
||||
Preferences::set('budgetMaximum', $budgetMaximum);
|
||||
|
||||
// custom fiscal year
|
||||
$customFiscalYear = intval(Input::get('customFiscalYear')) === 1;
|
||||
$fiscalYearStart = date('m-d', strtotime(Input::get('fiscalYearStart')));
|
||||
$customFiscalYear = intval($request->get('customFiscalYear')) === 1;
|
||||
$fiscalYearStart = date('m-d', strtotime($request->get('fiscalYearStart')));
|
||||
Preferences::set('customFiscalYear', $customFiscalYear);
|
||||
Preferences::set('fiscalYearStart', $fiscalYearStart);
|
||||
|
||||
// save page size:
|
||||
$transactionPageSize = intval(Input::get('transactionPageSize'));
|
||||
$transactionPageSize = intval($request->get('transactionPageSize'));
|
||||
if ($transactionPageSize > 0 && $transactionPageSize < 1337) {
|
||||
Preferences::set('transactionPageSize', $transactionPageSize);
|
||||
} else {
|
||||
@@ -155,7 +152,7 @@ class PreferencesController extends Controller
|
||||
}
|
||||
|
||||
// two factor auth
|
||||
$twoFactorAuthEnabled = intval(Input::get('twoFactorAuthEnabled'));
|
||||
$twoFactorAuthEnabled = intval($request->get('twoFactorAuthEnabled'));
|
||||
$hasTwoFactorAuthSecret = !is_null(Preferences::get('twoFactorAuthSecret'));
|
||||
|
||||
// If we already have a secret, just set the two factor auth enabled to 1, and let the user continue with the existing secret.
|
||||
@@ -164,11 +161,26 @@ class PreferencesController extends Controller
|
||||
}
|
||||
|
||||
// language:
|
||||
$lang = Input::get('language');
|
||||
$lang = $request->get('language');
|
||||
if (in_array($lang, array_keys(config('firefly.languages')))) {
|
||||
Preferences::set('language', $lang);
|
||||
}
|
||||
|
||||
// optional fields for transactions:
|
||||
$setOptions = $request->get('tj');
|
||||
$optionalTj = [
|
||||
'interest_date' => isset($setOptions['interest_date']),
|
||||
'book_date' => isset($setOptions['book_date']),
|
||||
'process_date' => isset($setOptions['process_date']),
|
||||
'due_date' => isset($setOptions['due_date']),
|
||||
'payment_date' => isset($setOptions['payment_date']),
|
||||
'invoice_date' => isset($setOptions['invoice_date']),
|
||||
'internal_reference' => isset($setOptions['internal_reference']),
|
||||
'notes' => isset($setOptions['notes']),
|
||||
'attachments' => isset($setOptions['attachments']),
|
||||
];
|
||||
Preferences::set('transaction_journal_optional_fields', $optionalTj);
|
||||
|
||||
|
||||
Session::flash('success', strval(trans('firefly.saved_preferences')));
|
||||
Preferences::mark();
|
||||
|
@@ -11,7 +11,6 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use Auth;
|
||||
use FireflyIII\Events\UserIsDeleted;
|
||||
use FireflyIII\Http\Requests\DeleteAccountFormRequest;
|
||||
use FireflyIII\Http\Requests\ProfileFormRequest;
|
||||
@@ -19,6 +18,7 @@ use FireflyIII\User;
|
||||
use Hash;
|
||||
use Preferences;
|
||||
use Session;
|
||||
use View;
|
||||
|
||||
/**
|
||||
* Class ProfileController
|
||||
@@ -36,32 +36,32 @@ class ProfileController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\View\View
|
||||
* @return View
|
||||
*/
|
||||
public function changePassword()
|
||||
{
|
||||
return view('profile.change-password')->with('title', Auth::user()->email)->with('subTitle', trans('firefly.change_your_password'))->with(
|
||||
return view('profile.change-password')->with('title', auth()->user()->email)->with('subTitle', trans('firefly.change_your_password'))->with(
|
||||
'mainTitleIcon', 'fa-user'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\View\View
|
||||
* @return View
|
||||
*/
|
||||
public function deleteAccount()
|
||||
{
|
||||
return view('profile.delete-account')->with('title', Auth::user()->email)->with('subTitle', trans('firefly.delete_account'))->with(
|
||||
return view('profile.delete-account')->with('title', auth()->user()->email)->with('subTitle', trans('firefly.delete_account'))->with(
|
||||
'mainTitleIcon', 'fa-user'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\View\View
|
||||
* @return View
|
||||
*
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('profile.index')->with('title', trans('firefly.profile'))->with('subTitle', Auth::user()->email)->with('mainTitleIcon', 'fa-user');
|
||||
return view('profile.index')->with('title', trans('firefly.profile'))->with('subTitle', auth()->user()->email)->with('mainTitleIcon', 'fa-user');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,7 +72,7 @@ class ProfileController extends Controller
|
||||
public function postChangePassword(ProfileFormRequest $request)
|
||||
{
|
||||
// old, new1, new2
|
||||
if (!Hash::check($request->get('current_password'), Auth::user()->password)) {
|
||||
if (!Hash::check($request->get('current_password'), auth()->user()->password)) {
|
||||
Session::flash('error', strval(trans('firefly.invalid_current_password')));
|
||||
|
||||
return redirect(route('profile.change-password'));
|
||||
@@ -85,8 +85,8 @@ class ProfileController extends Controller
|
||||
}
|
||||
|
||||
// update the user with the new password.
|
||||
Auth::user()->password = bcrypt($request->get('new_password'));
|
||||
Auth::user()->save();
|
||||
auth()->user()->password = bcrypt($request->get('new_password'));
|
||||
auth()->user()->save();
|
||||
|
||||
Session::flash('success', strval(trans('firefly.password_changed')));
|
||||
|
||||
@@ -102,22 +102,22 @@ class ProfileController extends Controller
|
||||
public function postDeleteAccount(DeleteAccountFormRequest $request)
|
||||
{
|
||||
// old, new1, new2
|
||||
if (!Hash::check($request->get('password'), Auth::user()->password)) {
|
||||
if (!Hash::check($request->get('password'), auth()->user()->password)) {
|
||||
Session::flash('error', strval(trans('firefly.invalid_password')));
|
||||
|
||||
return redirect(route('profile.delete-account'));
|
||||
}
|
||||
|
||||
// respond to deletion:
|
||||
event(new UserIsDeleted(Auth::user(), $request->ip()));
|
||||
event(new UserIsDeleted(auth()->user(), $request->ip()));
|
||||
|
||||
// store some stuff for the future:
|
||||
$registration = Preferences::get('registration_ip_address')->data;
|
||||
$confirmation = Preferences::get('confirmation_ip_address')->data;
|
||||
|
||||
// DELETE!
|
||||
$email = Auth::user()->email;
|
||||
Auth::user()->delete();
|
||||
$email = auth()->user()->email;
|
||||
auth()->user()->delete();
|
||||
Session::flush();
|
||||
Session::flash('gaEventCategory', 'user');
|
||||
Session::flash('gaEventAction', 'delete-account');
|
||||
|
@@ -50,18 +50,11 @@ class ReportController extends Controller
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param ReportHelperInterface $helper
|
||||
*/
|
||||
public function __construct(ReportHelperInterface $helper)
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->helper = $helper;
|
||||
$this->accountHelper = app(AccountReportHelperInterface::class);
|
||||
$this->budgetHelper = app(BudgetReportHelperInterface::class);
|
||||
$this->balanceHelper = app(BalanceReportHelperInterface::class);
|
||||
|
||||
View::share('title', trans('firefly.reports'));
|
||||
View::share('mainTitleIcon', 'fa-line-chart');
|
||||
|
||||
@@ -74,6 +67,7 @@ class ReportController extends Controller
|
||||
*/
|
||||
public function index(AccountCrudInterface $crud)
|
||||
{
|
||||
$this->createRepositories();
|
||||
/** @var Carbon $start */
|
||||
$start = clone session('first');
|
||||
$months = $this->helper->listOfMonths($start);
|
||||
@@ -104,6 +98,7 @@ class ReportController extends Controller
|
||||
*/
|
||||
public function report(string $reportType, Carbon $start, Carbon $end, Collection $accounts)
|
||||
{
|
||||
$this->createRepositories();
|
||||
// throw an error if necessary.
|
||||
if ($end < $start) {
|
||||
throw new FireflyException('End date cannot be before start date, silly!');
|
||||
@@ -192,8 +187,9 @@ class ReportController extends Controller
|
||||
$transactionAmount = $journal->source_amount;
|
||||
|
||||
// get currently relevant transaction:
|
||||
if (intval($journal->destination_account_id) === $account->id) {
|
||||
$transactionAmount = $journal->destination_amount;
|
||||
$destinations = TransactionJournal::destinationAccountList($journal)->pluck('id')->toArray();
|
||||
if (in_array($account->id, $destinations)) {
|
||||
$transactionAmount = TransactionJournal::amountPositive($journal);
|
||||
}
|
||||
$newBalance = bcadd($startBalance, $transactionAmount);
|
||||
$journal->after = $newBalance;
|
||||
@@ -215,14 +211,32 @@ class ReportController extends Controller
|
||||
$reportType = 'audit';
|
||||
$accountIds = join(',', $accounts->pluck('id')->toArray());
|
||||
|
||||
$hideable = ['buttons', 'icon', 'description', 'balance_before', 'amount', 'balance_after', 'date', 'book_date', 'process_date', 'interest_date',
|
||||
'from', 'to', 'budget', 'category', 'bill', 'create_date', 'update_date',
|
||||
$hideable = ['buttons', 'icon', 'description', 'balance_before', 'amount', 'balance_after', 'date',
|
||||
'interest_date', 'book_date', 'process_date',
|
||||
// three new optional fields.
|
||||
'due_date', 'payment_date', 'invoice_date',
|
||||
'from', 'to', 'budget', 'category', 'bill',
|
||||
// more new optional fields
|
||||
'internal_reference', 'notes',
|
||||
|
||||
'create_date', 'update_date',
|
||||
];
|
||||
$defaultShow = ['icon', 'description', 'balance_before', 'amount', 'balance_after', 'date', 'to'];
|
||||
|
||||
return view('reports.audit.report', compact('start', 'end', 'reportType', 'accountIds', 'accounts', 'auditData', 'hideable', 'defaultShow'));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function createRepositories()
|
||||
{
|
||||
$this->helper = app(ReportHelperInterface::class);
|
||||
$this->accountHelper = app(AccountReportHelperInterface::class);
|
||||
$this->budgetHelper = app(BudgetReportHelperInterface::class);
|
||||
$this->balanceHelper = app(BalanceReportHelperInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $reportType
|
||||
* @param Carbon $start
|
||||
|
@@ -11,7 +11,6 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use Auth;
|
||||
use FireflyIII\Http\Requests\RuleFormRequest;
|
||||
use FireflyIII\Http\Requests\TestRuleFormRequest;
|
||||
use FireflyIII\Models\Rule;
|
||||
@@ -189,7 +188,7 @@ class RuleController extends Controller
|
||||
{
|
||||
$this->createDefaultRuleGroup();
|
||||
$this->createDefaultRule();
|
||||
$ruleGroups = $repository->getRuleGroupsWithRules(Auth::user());
|
||||
$ruleGroups = $repository->getRuleGroupsWithRules(auth()->user());
|
||||
|
||||
return view('rules.index', compact('ruleGroups'));
|
||||
}
|
||||
@@ -233,7 +232,7 @@ class RuleController extends Controller
|
||||
* @param RuleRepositoryInterface $repository
|
||||
* @param RuleGroup $ruleGroup
|
||||
*
|
||||
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function store(RuleFormRequest $request, RuleRepositoryInterface $repository, RuleGroup $ruleGroup)
|
||||
{
|
||||
@@ -243,7 +242,7 @@ class RuleController extends Controller
|
||||
$data = [
|
||||
'rule_group_id' => $ruleGroup->id,
|
||||
'title' => $request->get('title'),
|
||||
'user_id' => Auth::user()->id,
|
||||
'user_id' => auth()->user()->id,
|
||||
'trigger' => $request->get('trigger'),
|
||||
'description' => $request->get('description'),
|
||||
'rule-triggers' => $request->get('rule-trigger'),
|
||||
@@ -281,7 +280,7 @@ class RuleController extends Controller
|
||||
*
|
||||
* @param TestRuleFormRequest $request
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function testTriggers(TestRuleFormRequest $request)
|
||||
{
|
||||
@@ -336,7 +335,7 @@ class RuleController extends Controller
|
||||
* @param RuleFormRequest $request
|
||||
* @param Rule $rule
|
||||
*
|
||||
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function update(RuleRepositoryInterface $repository, RuleFormRequest $request, Rule $rule)
|
||||
{
|
||||
@@ -380,7 +379,7 @@ class RuleController extends Controller
|
||||
$data = [
|
||||
'rule_group_id' => $repository->getFirstRuleGroup()->id,
|
||||
'stop_processing' => 0,
|
||||
'user_id' => Auth::user()->id,
|
||||
'user_id' => auth()->user()->id,
|
||||
'title' => trans('firefly.default_rule_name'),
|
||||
'description' => trans('firefly.default_rule_description'),
|
||||
'trigger' => 'store-journal',
|
||||
@@ -413,7 +412,7 @@ class RuleController extends Controller
|
||||
|
||||
if ($repository->count() === 0) {
|
||||
$data = [
|
||||
'user_id' => Auth::user()->id,
|
||||
'user_id' => auth()->user()->id,
|
||||
'title' => trans('firefly.default_rule_group_name'),
|
||||
'description' => trans('firefly.default_rule_group_description'),
|
||||
];
|
||||
|
@@ -11,7 +11,6 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use ExpandedForm;
|
||||
use FireflyIII\Crud\Account\AccountCrudInterface;
|
||||
@@ -96,7 +95,7 @@ class RuleGroupController extends Controller
|
||||
{
|
||||
|
||||
$title = $ruleGroup->title;
|
||||
$moveTo = Auth::user()->ruleGroups()->find(intval(Input::get('move_rules_before_delete')));
|
||||
$moveTo = auth()->user()->ruleGroups()->find(intval(Input::get('move_rules_before_delete')));
|
||||
|
||||
$repository->destroy($ruleGroup, $moveTo);
|
||||
|
||||
@@ -163,7 +162,7 @@ class RuleGroupController extends Controller
|
||||
$job = new ExecuteRuleGroupOnExistingTransactions($ruleGroup);
|
||||
|
||||
// Apply parameters to the job
|
||||
$job->setUser(Auth::user());
|
||||
$job->setUser(auth()->user());
|
||||
$job->setAccounts($accounts);
|
||||
$job->setStartDate($startDate);
|
||||
$job->setEndDate($endDate);
|
||||
@@ -200,14 +199,14 @@ class RuleGroupController extends Controller
|
||||
* @param RuleGroupFormRequest $request
|
||||
* @param RuleGroupRepositoryInterface $repository
|
||||
*
|
||||
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function store(RuleGroupFormRequest $request, RuleGroupRepositoryInterface $repository)
|
||||
{
|
||||
$data = [
|
||||
'title' => $request->input('title'),
|
||||
'description' => $request->input('description'),
|
||||
'user_id' => Auth::user()->id,
|
||||
'user_id' => auth()->user()->id,
|
||||
];
|
||||
|
||||
$ruleGroup = $repository->store($data);
|
||||
@@ -245,7 +244,7 @@ class RuleGroupController extends Controller
|
||||
* @param RuleGroupRepositoryInterface $repository
|
||||
* @param RuleGroup $ruleGroup
|
||||
*
|
||||
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function update(RuleGroupFormRequest $request, RuleGroupRepositoryInterface $repository, RuleGroup $ruleGroup)
|
||||
{
|
||||
|
@@ -11,7 +11,6 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use Auth;
|
||||
use FireflyIII\Http\Requests\TagFormRequest;
|
||||
use FireflyIII\Models\Preference;
|
||||
use FireflyIII\Models\Tag;
|
||||
@@ -61,7 +60,7 @@ class TagController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\View\View
|
||||
* @return View
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
@@ -88,7 +87,7 @@ class TagController extends Controller
|
||||
/**
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
* @return View
|
||||
*/
|
||||
public function delete(Tag $tag)
|
||||
{
|
||||
@@ -123,7 +122,7 @@ class TagController extends Controller
|
||||
/**
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
* @return View
|
||||
*/
|
||||
public function edit(Tag $tag)
|
||||
{
|
||||
@@ -194,7 +193,7 @@ class TagController extends Controller
|
||||
foreach ($types as $type) {
|
||||
|
||||
/** @var Collection $tags */
|
||||
$tags = Auth::user()->tags()->where('tagMode', $type)->orderBy('date', 'ASC')->get();
|
||||
$tags = auth()->user()->tags()->where('tagMode', $type)->orderBy('date', 'ASC')->get();
|
||||
$tags = $tags->sortBy(
|
||||
function (Tag $tag) {
|
||||
$date = !is_null($tag->date) ? $tag->date->format('Ymd') : '000000';
|
||||
@@ -218,18 +217,17 @@ class TagController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @param Tag $tag
|
||||
* @param TagRepositoryInterface $repository
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
* @return View
|
||||
*/
|
||||
public function show(Tag $tag)
|
||||
public function show(Tag $tag, TagRepositoryInterface $repository)
|
||||
{
|
||||
$subTitle = $tag->tag;
|
||||
$subTitleIcon = 'fa-tag';
|
||||
/** @var Collection $journals */
|
||||
$journals = $tag->transactionjournals()->sortCorrectly()->expanded()->get(TransactionJournal::queryFields());
|
||||
|
||||
$sum = $journals->sum(
|
||||
$journals = $repository->getJournals($tag);
|
||||
$sum = $journals->sum(
|
||||
function (TransactionJournal $journal) {
|
||||
return TransactionJournal::amount($journal);
|
||||
}
|
||||
|
@@ -11,7 +11,6 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers\Transaction;
|
||||
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use ExpandedForm;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
@@ -75,7 +74,7 @@ class MassController extends Controller
|
||||
/** @var int $journalId */
|
||||
foreach ($ids as $journalId) {
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $repository->find($journalId);
|
||||
$journal = $repository->find(intval($journalId));
|
||||
if (!is_null($journal->id) && $journalId == $journal->id) {
|
||||
$set->push($journal);
|
||||
}
|
||||
@@ -192,7 +191,7 @@ class MassController extends Controller
|
||||
$destAccountName = $request->get('destination_account_name')[$journal->id] ?? '';
|
||||
|
||||
$budgetId = $journal->budgets->first() ? $journal->budgets->first()->id : 0;
|
||||
$category = $journal->categories->first() ? $journal->categories->first()->name : '';
|
||||
$category = $request->get('category')[$journal->id];
|
||||
$tags = $journal->tags->pluck('tag')->toArray();
|
||||
|
||||
// build data array
|
||||
@@ -201,11 +200,11 @@ class MassController extends Controller
|
||||
'what' => $what,
|
||||
'description' => $request->get('description')[$journal->id],
|
||||
'source_account_id' => intval($sourceAccountId),
|
||||
'source_account_name' => intval($destAccountId),
|
||||
'destination_account_id' => $sourceAccountName,
|
||||
'source_account_name' => $sourceAccountName,
|
||||
'destination_account_id' => intval($destAccountId),
|
||||
'destination_account_name' => $destAccountName,
|
||||
'amount' => round($request->get('amount')[$journal->id], 4),
|
||||
'user' => Auth::user()->id,
|
||||
'user' => auth()->user()->id,
|
||||
'amount_currency_id_amount' => intval($request->get('amount_currency_id_amount_' . $journal->id)),
|
||||
'date' => new Carbon($request->get('date')[$journal->id]),
|
||||
'interest_date' => $journal->interest_date,
|
||||
|
@@ -67,6 +67,7 @@ class SplitController extends Controller
|
||||
$budgets = ExpandedForm::makeSelectListWithEmpty($budgetRepository->getActiveBudgets());
|
||||
$piggyBanks = ExpandedForm::makeSelectListWithEmpty($piggyRepository->getPiggyBanksWithAmount());
|
||||
$subTitle = trans('form.add_new_' . $sessionData['what']);
|
||||
$optionalFields = Preferences::get('transaction_journal_optional_fields', [])->data;
|
||||
$subTitleIcon = 'fa-plus';
|
||||
$preFilled = [
|
||||
'what' => $sessionData['what'] ?? 'withdrawal',
|
||||
@@ -83,7 +84,7 @@ class SplitController extends Controller
|
||||
|
||||
return view(
|
||||
'split.journals.create',
|
||||
compact('journal', 'piggyBanks', 'subTitle', 'subTitleIcon', 'preFilled', 'assetAccounts', 'currencies', 'budgets', 'uploadSize')
|
||||
compact('journal', 'piggyBanks', 'subTitle', 'optionalFields', 'subTitleIcon', 'preFilled', 'assetAccounts', 'currencies', 'budgets', 'uploadSize')
|
||||
);
|
||||
}
|
||||
|
||||
@@ -101,6 +102,7 @@ class SplitController extends Controller
|
||||
$uploadSize = min(Steam::phpBytes(ini_get('upload_max_filesize')), Steam::phpBytes(ini_get('post_max_size')));
|
||||
$currencies = ExpandedForm::makeSelectList($currencyRepository->get());
|
||||
$assetAccounts = ExpandedForm::makeSelectList($crud->getAccountsByType(['Default account', 'Asset account']));
|
||||
$optionalFields = Preferences::get('transaction_journal_optional_fields', [])->data;
|
||||
$budgets = ExpandedForm::makeSelectListWithEmpty($budgetRepository->getActiveBudgets());
|
||||
$preFilled = $this->arrayFromJournal($request, $journal);
|
||||
$subTitle = trans('breadcrumbs.edit_journal', ['description' => $journal->description]);
|
||||
@@ -118,7 +120,8 @@ class SplitController extends Controller
|
||||
return view(
|
||||
'split.journals.edit',
|
||||
compact(
|
||||
'subTitleIcon', 'currencies', 'preFilled', 'subTitle', 'amount', 'sourceAccounts', 'uploadSize', 'destinationAccounts', 'assetAccounts',
|
||||
'subTitleIcon', 'currencies', 'optionalFields',
|
||||
'preFilled', 'subTitle', 'amount', 'sourceAccounts', 'uploadSize', 'destinationAccounts', 'assetAccounts',
|
||||
'budgets', 'journal'
|
||||
)
|
||||
);
|
||||
@@ -160,7 +163,7 @@ class SplitController extends Controller
|
||||
* @param JournalInterface $repository
|
||||
* @param AttachmentHelperInterface $att
|
||||
*
|
||||
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function update(TransactionJournal $journal, SplitJournalFormRequest $request, JournalInterface $repository, AttachmentHelperInterface $att)
|
||||
{
|
||||
|
@@ -44,12 +44,18 @@ class TransactionController extends Controller
|
||||
parent::__construct();
|
||||
View::share('title', trans('firefly.transactions'));
|
||||
View::share('mainTitleIcon', 'fa-repeat');
|
||||
|
||||
$maxFileSize = Steam::phpBytes(ini_get('upload_max_filesize'));
|
||||
$maxPostSize = Steam::phpBytes(ini_get('post_max_size'));
|
||||
$uploadSize = min($maxFileSize, $maxPostSize);
|
||||
|
||||
View::share('uploadSize', $uploadSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $what
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
* @return View
|
||||
*/
|
||||
public function create(string $what = TransactionType::DEPOSIT)
|
||||
{
|
||||
@@ -65,6 +71,7 @@ class TransactionController extends Controller
|
||||
$preFilled = Session::has('preFilled') ? session('preFilled') : [];
|
||||
$subTitle = trans('form.add_new_' . $what);
|
||||
$subTitleIcon = 'fa-plus';
|
||||
$optionalFields = Preferences::get('transaction_journal_optional_fields', [])->data;
|
||||
|
||||
Session::put('preFilled', $preFilled);
|
||||
|
||||
@@ -80,7 +87,7 @@ class TransactionController extends Controller
|
||||
asort($piggies);
|
||||
|
||||
|
||||
return view('transactions.create', compact('assetAccounts', 'subTitleIcon', 'uploadSize', 'budgets', 'what', 'piggies', 'subTitle'));
|
||||
return view('transactions.create', compact('assetAccounts', 'subTitleIcon', 'uploadSize', 'budgets', 'what', 'piggies', 'subTitle', 'optionalFields'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,7 +95,7 @@ class TransactionController extends Controller
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
* @return View
|
||||
*/
|
||||
public function delete(TransactionJournal $journal)
|
||||
{
|
||||
@@ -135,19 +142,23 @@ class TransactionController extends Controller
|
||||
if ($count > 2) {
|
||||
return redirect(route('split.journal.edit', [$journal->id]));
|
||||
}
|
||||
$budgetRepository = app('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
|
||||
$piggyRepository = app('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface');
|
||||
$crud = app('FireflyIII\Crud\Account\AccountCrudInterface');
|
||||
$assetAccounts = ExpandedForm::makeSelectList($crud->getAccountsByType(['Default account', 'Asset account']));
|
||||
$budgetList = ExpandedForm::makeSelectListWithEmpty($budgetRepository->getActiveBudgets());
|
||||
$piggyBankList = ExpandedForm::makeSelectListWithEmpty($piggyRepository->getPiggyBanks());
|
||||
$maxFileSize = Steam::phpBytes(ini_get('upload_max_filesize'));
|
||||
$maxPostSize = Steam::phpBytes(ini_get('post_max_size'));
|
||||
$uploadSize = min($maxFileSize, $maxPostSize);
|
||||
$what = strtolower(TransactionJournal::transactionTypeStr($journal));
|
||||
$subTitle = trans('breadcrumbs.edit_journal', ['description' => $journal->description]);
|
||||
|
||||
// code to get list data:
|
||||
$budgetRepository = app('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
|
||||
$piggyRepository = app('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface');
|
||||
$crud = app('FireflyIII\Crud\Account\AccountCrudInterface');
|
||||
$assetAccounts = ExpandedForm::makeSelectList($crud->getAccountsByType(['Default account', 'Asset account']));
|
||||
$budgetList = ExpandedForm::makeSelectListWithEmpty($budgetRepository->getActiveBudgets());
|
||||
$piggyBankList = ExpandedForm::makeSelectListWithEmpty($piggyRepository->getPiggyBanks());
|
||||
|
||||
// view related code
|
||||
$subTitle = trans('breadcrumbs.edit_journal', ['description' => $journal->description]);
|
||||
$what = strtolower(TransactionJournal::transactionTypeStr($journal));
|
||||
|
||||
// journal related code
|
||||
$sourceAccounts = TransactionJournal::sourceAccountList($journal);
|
||||
$destinationAccounts = TransactionJournal::destinationAccountList($journal);
|
||||
$optionalFields = Preferences::get('transaction_journal_optional_fields', [])->data;
|
||||
$preFilled = [
|
||||
'date' => TransactionJournal::dateAsString($journal),
|
||||
'interest_date' => TransactionJournal::dateAsString($journal, 'interest_date'),
|
||||
@@ -162,6 +173,13 @@ class TransactionController extends Controller
|
||||
'destination_account_id' => $destinationAccounts->first()->id,
|
||||
'destination_account_name' => $destinationAccounts->first()->name,
|
||||
'amount' => TransactionJournal::amountPositive($journal),
|
||||
|
||||
// new custom fields:
|
||||
'due_date' => TransactionJournal::dateAsString($journal, 'due_date'),
|
||||
'payment_date' => TransactionJournal::dateAsString($journal, 'payment_date'),
|
||||
'invoice_date' => TransactionJournal::dateAsString($journal, 'invoice_date'),
|
||||
'interal_reference' => $journal->getMeta('internal_reference'),
|
||||
'notes' => $journal->getMeta('notes'),
|
||||
];
|
||||
|
||||
if ($journal->isWithdrawal() && $destinationAccounts->first()->accountType->type == AccountType::CASH) {
|
||||
@@ -183,9 +201,10 @@ class TransactionController extends Controller
|
||||
}
|
||||
Session::forget('transactions.edit.fromUpdate');
|
||||
|
||||
return view('transactions.edit', compact('journal', 'uploadSize', 'assetAccounts', 'what', 'budgetList', 'piggyBankList', 'subTitle'))->with(
|
||||
'data', $preFilled
|
||||
);
|
||||
return view(
|
||||
'transactions.edit',
|
||||
compact('journal', 'optionalFields', 'assetAccounts', 'what', 'budgetList', 'piggyBankList', 'subTitle')
|
||||
)->with('data', $preFilled);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -273,7 +292,7 @@ class TransactionController extends Controller
|
||||
|
||||
// store the journal only, flash the rest.
|
||||
if ($doSplit) {
|
||||
$journal = $repository->storeJournal($journalData);
|
||||
$journal = $repository->storeJournal($journalData);
|
||||
$journal->completed = false;
|
||||
$journal->save();
|
||||
|
||||
@@ -336,7 +355,7 @@ class TransactionController extends Controller
|
||||
* @param AttachmentHelperInterface $att
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function update(JournalFormRequest $request, JournalRepositoryInterface $repository, AttachmentHelperInterface $att, TransactionJournal $journal)
|
||||
{
|
||||
|
18
app/Http/Kernel.php
Normal file → Executable file
18
app/Http/Kernel.php
Normal file → Executable file
@@ -6,7 +6,6 @@
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http;
|
||||
@@ -23,9 +22,11 @@ use FireflyIII\Http\Middleware\RedirectIfAuthenticated;
|
||||
use FireflyIII\Http\Middleware\RedirectIfTwoFactorAuthenticated;
|
||||
use FireflyIII\Http\Middleware\VerifyCsrfToken;
|
||||
use Illuminate\Auth\Middleware\AuthenticateWithBasicAuth;
|
||||
use Illuminate\Auth\Middleware\Authorize;
|
||||
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
|
||||
use Illuminate\Foundation\Http\Kernel as HttpKernel;
|
||||
use Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode;
|
||||
use Illuminate\Routing\Middleware\SubstituteBindings;
|
||||
use Illuminate\Routing\Middleware\ThrottleRequests;
|
||||
use Illuminate\Session\Middleware\StartSession;
|
||||
use Illuminate\View\Middleware\ShareErrorsFromSession;
|
||||
@@ -37,10 +38,11 @@ use Illuminate\View\Middleware\ShareErrorsFromSession;
|
||||
*/
|
||||
class Kernel extends HttpKernel
|
||||
{
|
||||
|
||||
/**
|
||||
* The bootstrap classes for the application.
|
||||
*
|
||||
* Next upgrade should verify these are all here.
|
||||
* Next upgrade verify these are the same.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
@@ -83,6 +85,7 @@ class Kernel extends HttpKernel
|
||||
StartSession::class,
|
||||
ShareErrorsFromSession::class,
|
||||
VerifyCsrfToken::class,
|
||||
SubstituteBindings::class,
|
||||
],
|
||||
// MUST NOT be logged in. Does not care about 2FA or confirmation.
|
||||
'user-not-logged-in' => [
|
||||
@@ -91,9 +94,9 @@ class Kernel extends HttpKernel
|
||||
StartSession::class,
|
||||
ShareErrorsFromSession::class,
|
||||
VerifyCsrfToken::class,
|
||||
SubstituteBindings::class,
|
||||
RedirectIfAuthenticated::class,
|
||||
],
|
||||
|
||||
// MUST be logged in.
|
||||
// MUST NOT have 2FA
|
||||
// don't care about confirmation:
|
||||
@@ -103,6 +106,7 @@ class Kernel extends HttpKernel
|
||||
StartSession::class,
|
||||
ShareErrorsFromSession::class,
|
||||
VerifyCsrfToken::class,
|
||||
SubstituteBindings::class,
|
||||
Authenticate::class,
|
||||
RedirectIfTwoFactorAuthenticated::class,
|
||||
],
|
||||
@@ -115,6 +119,7 @@ class Kernel extends HttpKernel
|
||||
StartSession::class,
|
||||
ShareErrorsFromSession::class,
|
||||
VerifyCsrfToken::class,
|
||||
SubstituteBindings::class,
|
||||
Authenticate::class,
|
||||
AuthenticateTwoFactor::class,
|
||||
IsNotConfirmed::class,
|
||||
@@ -129,6 +134,7 @@ class Kernel extends HttpKernel
|
||||
StartSession::class,
|
||||
ShareErrorsFromSession::class,
|
||||
VerifyCsrfToken::class,
|
||||
SubstituteBindings::class,
|
||||
Authenticate::class,
|
||||
],
|
||||
|
||||
@@ -142,6 +148,7 @@ class Kernel extends HttpKernel
|
||||
StartSession::class,
|
||||
ShareErrorsFromSession::class,
|
||||
VerifyCsrfToken::class,
|
||||
SubstituteBindings::class,
|
||||
Authenticate::class,
|
||||
AuthenticateTwoFactor::class,
|
||||
IsConfirmed::class,
|
||||
@@ -159,6 +166,7 @@ class Kernel extends HttpKernel
|
||||
StartSession::class,
|
||||
ShareErrorsFromSession::class,
|
||||
VerifyCsrfToken::class,
|
||||
SubstituteBindings::class,
|
||||
Authenticate::class,
|
||||
AuthenticateTwoFactor::class,
|
||||
IsConfirmed::class,
|
||||
@@ -168,8 +176,10 @@ class Kernel extends HttpKernel
|
||||
|
||||
],
|
||||
|
||||
|
||||
'api' => [
|
||||
'throttle:60,1',
|
||||
'bindings',
|
||||
],
|
||||
];
|
||||
|
||||
@@ -184,6 +194,8 @@ class Kernel extends HttpKernel
|
||||
= [
|
||||
'auth' => Authenticate::class,
|
||||
'auth.basic' => AuthenticateWithBasicAuth::class,
|
||||
'bindings' => SubstituteBindings::class,
|
||||
'can' => Authorize::class,
|
||||
'guest' => RedirectIfAuthenticated::class,
|
||||
'throttle' => ThrottleRequests::class,
|
||||
'range' => Range::class,
|
||||
|
@@ -41,7 +41,7 @@ class Authenticate
|
||||
|
||||
return redirect()->guest('login');
|
||||
}
|
||||
if (intval(Auth::user()->blocked) === 1) {
|
||||
if (intval(auth()->user()->blocked) === 1) {
|
||||
Auth::guard($guard)->logout();
|
||||
Session::flash('logoutMessage', trans('firefly.block_account_logout'));
|
||||
|
||||
|
@@ -45,7 +45,7 @@ class AuthenticateTwoFactor
|
||||
return redirect()->guest('login');
|
||||
}
|
||||
|
||||
if (intval(Auth::user()->blocked) === 1) {
|
||||
if (intval(auth()->user()->blocked) === 1) {
|
||||
Auth::guard($guard)->logout();
|
||||
Session::flash('logoutMessage', trans('firefly.block_account_logout'));
|
||||
|
||||
|
1
app/Http/Middleware/EncryptCookies.php
Normal file → Executable file
1
app/Http/Middleware/EncryptCookies.php
Normal file → Executable file
@@ -6,7 +6,6 @@
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Middleware;
|
||||
|
@@ -43,7 +43,7 @@ class IsAdmin
|
||||
return redirect()->guest('login');
|
||||
}
|
||||
/** @var User $user */
|
||||
$user = Auth::user();
|
||||
$user = auth()->user();
|
||||
if (!$user->hasRole('owner')) {
|
||||
return redirect(route('home'));
|
||||
}
|
||||
|
@@ -11,6 +11,7 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Middleware;
|
||||
|
||||
use App;
|
||||
use Carbon\Carbon;
|
||||
use Closure;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
@@ -19,6 +20,7 @@ use Illuminate\Contracts\Auth\Guard;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Navigation;
|
||||
use NumberFormatter;
|
||||
use Preferences;
|
||||
use Session;
|
||||
use View;
|
||||
@@ -62,36 +64,56 @@ class Range
|
||||
public function handle(Request $request, Closure $theNext, $guard = null)
|
||||
{
|
||||
if (!Auth::guard($guard)->guest()) {
|
||||
// ignore preference. set the range to be the current month:
|
||||
if (!Session::has('start') && !Session::has('end')) {
|
||||
|
||||
$viewRange = Preferences::get('viewRange', '1M')->data;
|
||||
$start = new Carbon;
|
||||
$start = Navigation::updateStartDate($viewRange, $start);
|
||||
$end = Navigation::updateEndDate($viewRange, $start);
|
||||
// set start, end and finish:
|
||||
$this->setRange();
|
||||
|
||||
Session::put('start', $start);
|
||||
Session::put('end', $end);
|
||||
}
|
||||
if (!Session::has('first')) {
|
||||
/** @var JournalRepositoryInterface $repository */
|
||||
$repository = app(JournalRepositoryInterface::class);
|
||||
$journal = $repository->first();
|
||||
$first = Carbon::now()->startOfYear();
|
||||
|
||||
if (!is_null($journal->id)) {
|
||||
$first = $journal->date;
|
||||
}
|
||||
Session::put('first', $first);
|
||||
}
|
||||
// get variables for date range:
|
||||
$this->datePicker();
|
||||
|
||||
// set view variables.
|
||||
$this->configureView();
|
||||
}
|
||||
$this->datePicker();
|
||||
|
||||
return $theNext($request);
|
||||
|
||||
}
|
||||
|
||||
private function configureView()
|
||||
{
|
||||
$pref = Preferences::get('language', config('firefly.default_language', 'en_US'));
|
||||
$lang = $pref->data;
|
||||
|
||||
App::setLocale($lang);
|
||||
Carbon::setLocale(substr($lang, 0, 2));
|
||||
$locale = explode(',', trans('config.locale'));
|
||||
$locale = array_map('trim', $locale);
|
||||
|
||||
setlocale(LC_TIME, $locale);
|
||||
setlocale(LC_MONETARY, $locale);
|
||||
|
||||
// save some formats:
|
||||
$monthFormat = (string)trans('config.month');
|
||||
$monthAndDayFormat = (string)trans('config.month_and_day');
|
||||
$dateTimeFormat = (string)trans('config.date_time');
|
||||
|
||||
// change localeconv to a new array:
|
||||
$numberFormatter = numfmt_create($lang, NumberFormatter::CURRENCY);
|
||||
$localeconv = [
|
||||
'mon_decimal_point' => $numberFormatter->getSymbol($numberFormatter->getAttribute(NumberFormatter::DECIMAL_SEPARATOR_SYMBOL)),
|
||||
'mon_thousands_sep' => $numberFormatter->getSymbol($numberFormatter->getAttribute(NumberFormatter::MONETARY_GROUPING_SEPARATOR_SYMBOL)),
|
||||
'frac_digits' => $numberFormatter->getAttribute(NumberFormatter::MAX_FRACTION_DIGITS),
|
||||
];
|
||||
View::share('monthFormat', $monthFormat);
|
||||
View::share('monthAndDayFormat', $monthAndDayFormat);
|
||||
View::share('dateTimeFormat', $dateTimeFormat);
|
||||
View::share('language', $lang);
|
||||
View::share('localeconv', $localeconv);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function datePicker()
|
||||
{
|
||||
$viewRange = Preferences::get('viewRange', '1M')->data;
|
||||
@@ -141,4 +163,33 @@ class Range
|
||||
View::share('dpRanges', $ranges);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function setRange()
|
||||
{
|
||||
// ignore preference. set the range to be the current month:
|
||||
if (!Session::has('start') && !Session::has('end')) {
|
||||
|
||||
$viewRange = Preferences::get('viewRange', '1M')->data;
|
||||
$start = new Carbon;
|
||||
$start = Navigation::updateStartDate($viewRange, $start);
|
||||
$end = Navigation::updateEndDate($viewRange, $start);
|
||||
|
||||
Session::put('start', $start);
|
||||
Session::put('end', $end);
|
||||
}
|
||||
if (!Session::has('first')) {
|
||||
/** @var JournalRepositoryInterface $repository */
|
||||
$repository = app(JournalRepositoryInterface::class);
|
||||
$journal = $repository->first();
|
||||
$first = Carbon::now()->startOfYear();
|
||||
|
||||
if (!is_null($journal->id)) {
|
||||
$first = $journal->date;
|
||||
}
|
||||
Session::put('first', $first);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
2
app/Http/Middleware/RedirectIfAuthenticated.php
Normal file → Executable file
2
app/Http/Middleware/RedirectIfAuthenticated.php
Normal file → Executable file
@@ -6,7 +6,6 @@
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Middleware;
|
||||
@@ -33,7 +32,6 @@ class RedirectIfAuthenticated
|
||||
public function handle($request, Closure $next, $guard = null)
|
||||
{
|
||||
if (Auth::guard($guard)->check()) {
|
||||
|
||||
return redirect('/');
|
||||
}
|
||||
|
||||
|
2
app/Http/Middleware/VerifyCsrfToken.php
Normal file → Executable file
2
app/Http/Middleware/VerifyCsrfToken.php
Normal file → Executable file
@@ -6,8 +6,8 @@
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;
|
||||
|
@@ -11,7 +11,6 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use Auth;
|
||||
use FireflyIII\Models\Account;
|
||||
use Input;
|
||||
|
||||
@@ -29,7 +28,7 @@ class AccountFormRequest extends Request
|
||||
public function authorize()
|
||||
{
|
||||
// Only allow logged in users
|
||||
return Auth::check();
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -11,8 +11,6 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use Auth;
|
||||
|
||||
/**
|
||||
* Class AttachmentFormRequest
|
||||
*
|
||||
@@ -27,7 +25,7 @@ class AttachmentFormRequest extends Request
|
||||
public function authorize()
|
||||
{
|
||||
// Only allow logged in users
|
||||
return Auth::check();
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -11,7 +11,6 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use Input;
|
||||
|
||||
@@ -29,7 +28,7 @@ class BillFormRequest extends Request
|
||||
public function authorize()
|
||||
{
|
||||
// Only allow logged in users
|
||||
return Auth::check();
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -45,7 +44,7 @@ class BillFormRequest extends Request
|
||||
'amount_currency_id_amount_max' => intval($this->get('amount_currency_id_amount_max')),
|
||||
'amount_max' => round($this->get('amount_max'), 2),
|
||||
'date' => new Carbon($this->get('date')),
|
||||
'user' => Auth::user()->id,
|
||||
'user' => auth()->user()->id,
|
||||
'repeat_freq' => $this->get('repeat_freq'),
|
||||
'skip' => intval($this->get('skip')),
|
||||
'automatch' => intval($this->get('automatch')) === 1,
|
||||
|
@@ -11,7 +11,6 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use Auth;
|
||||
use FireflyIII\Models\Budget;
|
||||
use Input;
|
||||
|
||||
@@ -29,7 +28,7 @@ class BudgetFormRequest extends Request
|
||||
public function authorize()
|
||||
{
|
||||
// Only allow logged in users
|
||||
return Auth::check();
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -11,7 +11,6 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use Auth;
|
||||
use FireflyIII\Models\Category;
|
||||
use Input;
|
||||
|
||||
@@ -29,7 +28,7 @@ class CategoryFormRequest extends Request
|
||||
public function authorize()
|
||||
{
|
||||
// Only allow logged in users
|
||||
return Auth::check();
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
/**
|
||||
|
42
app/Http/Requests/ConfigurationRequest.php
Normal file
42
app/Http/Requests/ConfigurationRequest.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* ConfigurationRequest.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
/**
|
||||
* Class ConfigurationRequest
|
||||
*
|
||||
*
|
||||
* @package FireflyIII\Http\Requests
|
||||
*/
|
||||
class ConfigurationRequest extends Request
|
||||
{
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
// Only allow logged in users and admins
|
||||
return auth()->check() && auth()->user()->hasRole('owner');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
$rules = [
|
||||
'single_user_mode' => 'between:0,1|numeric',
|
||||
];
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
@@ -11,7 +11,6 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use Auth;
|
||||
use Input;
|
||||
|
||||
/**
|
||||
@@ -28,7 +27,7 @@ class CurrencyFormRequest extends Request
|
||||
public function authorize()
|
||||
{
|
||||
// Only allow logged in users
|
||||
return Auth::check();
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -11,8 +11,6 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use Auth;
|
||||
|
||||
/**
|
||||
* Class DeleteAccountFormRequest
|
||||
*
|
||||
@@ -27,7 +25,7 @@ class DeleteAccountFormRequest extends Request
|
||||
public function authorize()
|
||||
{
|
||||
// Only allow logged in users
|
||||
return Auth::check();
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -11,7 +11,6 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
@@ -28,7 +27,7 @@ class ExportFormRequest extends Request
|
||||
public function authorize()
|
||||
{
|
||||
// Only allow logged in users
|
||||
return Auth::check();
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -11,8 +11,6 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use Auth;
|
||||
|
||||
/**
|
||||
* Class ImportUploadRequest
|
||||
*
|
||||
@@ -27,7 +25,7 @@ class ImportUploadRequest extends Request
|
||||
public function authorize()
|
||||
{
|
||||
// Only allow logged in users
|
||||
return Auth::check();
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -11,7 +11,6 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
@@ -32,7 +31,7 @@ class JournalFormRequest extends Request
|
||||
public function authorize()
|
||||
{
|
||||
// Only allow logged in users
|
||||
return Auth::check();
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,26 +39,34 @@ class JournalFormRequest extends Request
|
||||
*/
|
||||
public function getJournalData()
|
||||
{
|
||||
$tags = $this->get('tags') ?? '';
|
||||
$tags = $this->getFieldOrEmptyString('tags');
|
||||
|
||||
return [
|
||||
'what' => $this->get('what'),
|
||||
'description' => $this->get('description'),
|
||||
'source_account_id' => intval($this->get('source_account_id')),
|
||||
'source_account_name' => $this->get('source_account_name') ?? '',
|
||||
'source_account_name' => $this->getFieldOrEmptyString('source_account_name'),
|
||||
'destination_account_id' => intval($this->get('destination_account_id')),
|
||||
'destination_account_name' => $this->get('destination_account_name') ?? '',
|
||||
'destination_account_name' => $this->getFieldOrEmptyString('destination_account_name'),
|
||||
'amount' => round($this->get('amount'), 2),
|
||||
'user' => Auth::user()->id,
|
||||
'user' => auth()->user()->id,
|
||||
'amount_currency_id_amount' => intval($this->get('amount_currency_id_amount')),
|
||||
'date' => new Carbon($this->get('date')),
|
||||
'interest_date' => $this->get('interest_date') ? new Carbon($this->get('interest_date')) : null,
|
||||
'book_date' => $this->get('book_date') ? new Carbon($this->get('book_date')) : null,
|
||||
'process_date' => $this->get('process_date') ? new Carbon($this->get('process_date')) : null,
|
||||
'interest_date' => $this->getDateOrNull('interest_date'),
|
||||
'book_date' => $this->getDateOrNull('book_date'),
|
||||
'process_date' => $this->getDateOrNull('process_date'),
|
||||
'budget_id' => intval($this->get('budget_id')),
|
||||
'category' => $this->get('category') ?? '',
|
||||
'category' => $this->getFieldOrEmptyString('category'),
|
||||
'tags' => explode(',', $tags),
|
||||
'piggy_bank_id' => $this->get('piggy_bank_id') ? intval($this->get('piggy_bank_id')) : 0,
|
||||
'piggy_bank_id' => intval($this->get('piggy_bank_id')),
|
||||
|
||||
// new custom fields here:
|
||||
'due_date' => $this->getDateOrNull('due_date'),
|
||||
'payment_date' => $this->getDateOrNull('payment_date'),
|
||||
'invoice_date' => $this->getDateOrNull('invoice_date'),
|
||||
'internal_reference' => $this->get('internal_reference'),
|
||||
'notes' => $this->get('notes'),
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
@@ -81,6 +88,12 @@ class JournalFormRequest extends Request
|
||||
'category' => 'between:1,255',
|
||||
'amount_currency_id_amount' => 'required|exists:transaction_currencies,id',
|
||||
'piggy_bank_id' => 'numeric',
|
||||
|
||||
// new custom fields here:
|
||||
'due_date' => 'date',
|
||||
'payment_date' => 'date',
|
||||
'internal_reference' => 'min:1,max:255',
|
||||
'notes' => 'min:1,max:65536',
|
||||
];
|
||||
|
||||
switch ($what) {
|
||||
@@ -106,4 +119,24 @@ class JournalFormRequest extends Request
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
*
|
||||
* @return Carbon|null
|
||||
*/
|
||||
private function getDateOrNull(string $field)
|
||||
{
|
||||
return $this->get($field) ? new Carbon($this->get($field)) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getFieldOrEmptyString(string $field): string
|
||||
{
|
||||
return $this->get($field) ?? '';
|
||||
}
|
||||
}
|
||||
|
@@ -11,8 +11,6 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use Auth;
|
||||
|
||||
/**
|
||||
* Class MassDeleteJournalRequest
|
||||
*
|
||||
@@ -27,7 +25,7 @@ class MassDeleteJournalRequest extends Request
|
||||
public function authorize()
|
||||
{
|
||||
// Only allow logged in users
|
||||
return Auth::check();
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -11,8 +11,6 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use Auth;
|
||||
|
||||
/**
|
||||
* Class MassEditJournalRequest
|
||||
*
|
||||
@@ -27,7 +25,7 @@ class MassEditJournalRequest extends Request
|
||||
public function authorize()
|
||||
{
|
||||
// Only allow logged in users
|
||||
return Auth::check();
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -11,8 +11,6 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use Auth;
|
||||
|
||||
/**
|
||||
* Class NewUserFormRequest
|
||||
*
|
||||
@@ -27,7 +25,7 @@ class NewUserFormRequest extends Request
|
||||
public function authorize()
|
||||
{
|
||||
// Only allow logged in users
|
||||
return Auth::check();
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -11,7 +11,6 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use Auth;
|
||||
use Input;
|
||||
|
||||
/**
|
||||
@@ -28,7 +27,7 @@ class PiggyBankFormRequest extends Request
|
||||
public function authorize()
|
||||
{
|
||||
// Only allow logged in users
|
||||
return Auth::check();
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -11,8 +11,6 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use Auth;
|
||||
|
||||
/**
|
||||
* Class ProfileFormRequest
|
||||
*
|
||||
@@ -27,7 +25,7 @@ class ProfileFormRequest extends Request
|
||||
public function authorize()
|
||||
{
|
||||
// Only allow logged in users
|
||||
return Auth::check();
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -11,7 +11,6 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use Auth;
|
||||
use FireflyIII\Models\RuleGroup;
|
||||
use Input;
|
||||
|
||||
@@ -29,7 +28,7 @@ class RuleFormRequest extends Request
|
||||
public function authorize()
|
||||
{
|
||||
// Only allow logged in users
|
||||
return Auth::check();
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -18,7 +18,6 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use Auth;
|
||||
use FireflyIII\Models\RuleGroup;
|
||||
use Input;
|
||||
|
||||
@@ -36,7 +35,7 @@ class RuleGroupFormRequest extends Request
|
||||
public function authorize()
|
||||
{
|
||||
// Only allow logged in users
|
||||
return Auth::check();
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -11,7 +11,6 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
@@ -28,7 +27,7 @@ class SelectTransactionsRequest extends Request
|
||||
public function authorize()
|
||||
{
|
||||
// Only allow logged in users
|
||||
return Auth::check();
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -11,7 +11,6 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
|
||||
|
||||
@@ -28,7 +27,7 @@ class SplitJournalFormRequest extends Request
|
||||
public function authorize(): bool
|
||||
{
|
||||
// Only allow logged in users
|
||||
return Auth::check();
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -10,7 +10,6 @@
|
||||
declare(strict_types = 1);
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Models\Tag;
|
||||
use Input;
|
||||
@@ -29,7 +28,7 @@ class TagFormRequest extends Request
|
||||
public function authorize()
|
||||
{
|
||||
// Only allow logged in users
|
||||
return Auth::check();
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -11,8 +11,6 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use Auth;
|
||||
|
||||
/**
|
||||
* Class RuleFormRequest
|
||||
*
|
||||
@@ -27,7 +25,7 @@ class TestRuleFormRequest extends Request
|
||||
public function authorize()
|
||||
{
|
||||
// Only allow logged in users
|
||||
return Auth::check();
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -11,8 +11,6 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use Auth;
|
||||
|
||||
/**
|
||||
* Class TokenFormRequest
|
||||
*
|
||||
@@ -27,7 +25,7 @@ class TokenFormRequest extends Request
|
||||
public function authorize()
|
||||
{
|
||||
// Only allow logged in users
|
||||
return Auth::check();
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -120,6 +120,14 @@ Breadcrumbs::register(
|
||||
}
|
||||
);
|
||||
|
||||
Breadcrumbs::register(
|
||||
'admin.configuration.index', function (BreadCrumbGenerator $breadcrumbs) {
|
||||
$breadcrumbs->parent('admin.index');
|
||||
$breadcrumbs->push(trans('firefly.instance_configuration'), route('admin.configuration.index'));
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* ATTACHMENTS
|
||||
*/
|
||||
|
@@ -23,6 +23,7 @@ class Amount extends BasicConverter implements ConverterInterface
|
||||
* Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.
|
||||
* - Jamie Zawinski
|
||||
*
|
||||
*
|
||||
* @param $value
|
||||
*
|
||||
* @return float
|
||||
@@ -33,12 +34,12 @@ class Amount extends BasicConverter implements ConverterInterface
|
||||
$decimalPosition = $len - 3;
|
||||
$decimal = null;
|
||||
|
||||
if ($len > 2 && $value{$decimalPosition} == '.') {
|
||||
if (($len > 2 && $value{$decimalPosition} == '.') || ($len > 2 && strpos($value, '.') > $decimalPosition)) {
|
||||
$decimal = '.';
|
||||
}
|
||||
if ($len > 2 && $value{$decimalPosition} == ',') {
|
||||
$decimal = ',';
|
||||
}
|
||||
}
|
||||
|
||||
// if decimal is dot, replace all comma's and spaces with nothing. then parse as float (round to 4 pos)
|
||||
if ($decimal === '.') {
|
||||
|
@@ -27,6 +27,7 @@ class BillName extends BasicConverter implements ConverterInterface
|
||||
/**
|
||||
* @param $value
|
||||
*
|
||||
* @return Bill
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function convert($value)
|
||||
@@ -36,6 +37,7 @@ class BillName extends BasicConverter implements ConverterInterface
|
||||
|
||||
if (strlen($value) === 0) {
|
||||
$this->setCertainty(0);
|
||||
|
||||
return new Bill;
|
||||
}
|
||||
|
||||
@@ -48,6 +50,7 @@ class BillName extends BasicConverter implements ConverterInterface
|
||||
if (!is_null($bill->id)) {
|
||||
Log::debug('Found bill by ID', ['id' => $bill->id]);
|
||||
$this->setCertainty(100);
|
||||
|
||||
return $bill;
|
||||
}
|
||||
}
|
||||
@@ -57,6 +60,7 @@ class BillName extends BasicConverter implements ConverterInterface
|
||||
if (!is_null($bill->id)) {
|
||||
Log::debug('Found bill by name ', ['id' => $bill->id]);
|
||||
$this->setCertainty(100);
|
||||
|
||||
return $bill;
|
||||
}
|
||||
|
||||
@@ -66,7 +70,7 @@ class BillName extends BasicConverter implements ConverterInterface
|
||||
'name' => $value,
|
||||
'match' => $value,
|
||||
'amount_min' => 1,
|
||||
'user' => $this->user->id,
|
||||
'user' => $this->user->id,
|
||||
'amount_max' => 10,
|
||||
'date' => date('Ymd'),
|
||||
'repeat_freq' => 'monthly',
|
||||
|
@@ -11,7 +11,6 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Import\Converter;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use Log;
|
||||
@@ -36,6 +35,7 @@ class BudgetId extends BasicConverter implements ConverterInterface
|
||||
|
||||
if ($value === 0) {
|
||||
$this->setCertainty(0);
|
||||
|
||||
return new Budget;
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@ class BudgetId extends BasicConverter implements ConverterInterface
|
||||
if (!is_null($budget->id)) {
|
||||
Log::debug('Found budget by ID ', ['id' => $budget->id]);
|
||||
$this->setCertainty(100);
|
||||
|
||||
return $budget;
|
||||
}
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user