mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-08-17 03:14:34 +00:00
Compare commits
199 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
aaa186be5e | ||
|
98ae5b0ca0 | ||
|
36c8171d0f | ||
|
3603eb94cc | ||
|
0e068d4ccf | ||
|
199f348ff4 | ||
|
b22655fb7c | ||
|
06cc9618ba | ||
|
b9019c8c7f | ||
|
77e133e67c | ||
|
571e7df807 | ||
|
22f4d2979a | ||
|
e46e366694 | ||
|
7b4bc23815 | ||
|
9ca79f767c | ||
|
274dba7408 | ||
|
31708ca29e | ||
|
671b025588 | ||
|
a7956e4856 | ||
|
355862025a | ||
|
a2a39ee0f8 | ||
|
ec8e39c16f | ||
|
88f714999e | ||
|
c0c2aa3be0 | ||
|
822044820e | ||
|
6ffc182142 | ||
|
3d54a78573 | ||
|
8ddf7d953a | ||
|
8b9e9ad103 | ||
|
5737224c40 | ||
|
ec9aacbcae | ||
|
9395454997 | ||
|
66198a8d98 | ||
|
96ed9a4256 | ||
|
10e54b2263 | ||
|
cf00922ad2 | ||
|
84e8e007a5 | ||
|
d07b2e773b | ||
|
506ef7b0b9 | ||
|
2cd5dae8e2 | ||
|
a1cd49c111 | ||
|
aca2973aef | ||
|
0a7a691c95 | ||
|
72906a7afd | ||
|
d1a4a83570 | ||
|
e0396b29e8 | ||
|
536833cfe0 | ||
|
317b02d1b9 | ||
|
75e279ea0d | ||
|
dc2ad21f4c | ||
|
484d49aae1 | ||
|
ca39438ad4 | ||
|
49a65ebff4 | ||
|
befdc05084 | ||
|
1fbffe761b | ||
|
36aad379ff | ||
|
540cfa072e | ||
|
3b049c15cc | ||
|
3e93ed0a17 | ||
|
d7d9358136 | ||
|
5cf0939ff9 | ||
|
8dc6f91d3c | ||
|
a3a25db230 | ||
|
c06f18c815 | ||
|
6802f04036 | ||
|
beeccdf345 | ||
|
58241ed39d | ||
|
31128020f0 | ||
|
6c48afc37b | ||
|
7a2f169dfc | ||
|
ed910b99a7 | ||
|
54195c0826 | ||
|
cefbbcd1df | ||
|
cc01592085 | ||
|
5a98a5252d | ||
|
184e8b1132 | ||
|
2b6b896c2e | ||
|
96d06b7a93 | ||
|
f54f1611b5 | ||
|
69ad757e8b | ||
|
e0beb796ad | ||
|
f331e7d820 | ||
|
cbb62d3d78 | ||
|
c85bc59c1d | ||
|
8081eeb007 | ||
|
56f91bd10d | ||
|
8e20b78731 | ||
|
23a09b7081 | ||
|
67fdd27499 | ||
|
e1941daedd | ||
|
f28bc568a4 | ||
|
f24cfe39aa | ||
|
59d2bf3f79 | ||
|
3176e54614 | ||
|
eb090f7265 | ||
|
6d3a9bfd18 | ||
|
76f08b7acb | ||
|
1ff99346aa | ||
|
369695ab32 | ||
|
7e23dd1d66 | ||
|
0205d3fc5c | ||
|
4660cf2ad5 | ||
|
e26d08d674 | ||
|
0932bf2797 | ||
|
f560fc6d76 | ||
|
aa6209af00 | ||
|
4a51176193 | ||
|
bb84f7a434 | ||
|
48168b1ef0 | ||
|
8281c7c83e | ||
|
a07c1e3c71 | ||
|
0766bb31fe | ||
|
ff4472c1a5 | ||
|
17424740e5 | ||
|
dad0b2fcd3 | ||
|
c48dbf030f | ||
|
617808d603 | ||
|
845149deee | ||
|
1a9e009327 | ||
|
ae90815708 | ||
|
1c460343b7 | ||
|
26079622f9 | ||
|
06c6d6096f | ||
|
c8183aea51 | ||
|
7531134ad2 | ||
|
cd0c6439c2 | ||
|
c918c93f51 | ||
|
97d3bd68ed | ||
|
75f1e034ae | ||
|
8e72f218f1 | ||
|
d643e05c5a | ||
|
fea44834d0 | ||
|
195a2d7523 | ||
|
b2fd346ef8 | ||
|
1ff8b62cb7 | ||
|
c7ae15a41a | ||
|
efe6f59f79 | ||
|
8e31d0491d | ||
|
73d4a10351 | ||
|
81d9d4dbc7 | ||
|
184ec13f99 | ||
|
dee0422eff | ||
|
81a2975f1a | ||
|
5cd2ef4a5e | ||
|
466c2a68c2 | ||
|
0fb9fba531 | ||
|
356dd2c6cd | ||
|
32c4661233 | ||
|
a245b504ec | ||
|
a2f5fbdfd3 | ||
|
04be26adc5 | ||
|
be0adb7cf2 | ||
|
84fd92bf5a | ||
|
ee4e061739 | ||
|
4a2b01cd9a | ||
|
efdd6460fb | ||
|
803827e05c | ||
|
a41d5e9ab3 | ||
|
e94333f877 | ||
|
6dbb80d687 | ||
|
31a1031624 | ||
|
f8e9ce0d52 | ||
|
11baa968cd | ||
|
3e5e5b376f | ||
|
bda18f296d | ||
|
287d110c84 | ||
|
c98275e73a | ||
|
aa573cc951 | ||
|
883d3d86e3 | ||
|
fb047bd5f4 | ||
|
66a04d8365 | ||
|
a0e501f9fd | ||
|
8b40d3346d | ||
|
eddf5cd250 | ||
|
ee5c534ca3 | ||
|
fd4e77ae0f | ||
|
b747c50aa3 | ||
|
deebdd86a6 | ||
|
b2db79cc10 | ||
|
bbab370b1e | ||
|
db4adf399d | ||
|
0683c87e52 | ||
|
3f62b647fc | ||
|
2562a5b30d | ||
|
e232f2e223 | ||
|
21644ff4dd | ||
|
be96a4fce5 | ||
|
a1cabcbed3 | ||
|
ce933b1f06 | ||
|
51ae130922 | ||
|
da1bc18a47 | ||
|
e7165a526b | ||
|
6081cc399f | ||
|
7c5c24e15d | ||
|
e3e55b4347 | ||
|
40d8e7d1ad | ||
|
59e23b89f2 | ||
|
cc33af8193 | ||
|
52a28a7758 |
@@ -15,4 +15,5 @@ EMAIL_SMTP=
|
||||
EMAIL_DRIVER=smtp
|
||||
EMAIL_USERNAME=
|
||||
EMAIL_PASSWORD=
|
||||
ANALYTICS_ID=
|
||||
ANALYTICS_ID=
|
||||
EMAIL_PRETEND=false
|
@@ -8,10 +8,11 @@ DB_DATABASE=homestead
|
||||
DB_USERNAME=homestead
|
||||
DB_PASSWORD=secret
|
||||
|
||||
CACHE_DRIVER=file
|
||||
SESSION_DRIVER=file
|
||||
CACHE_DRIVER=array
|
||||
SESSION_DRIVER=array
|
||||
|
||||
EMAIL_SMTP=
|
||||
EMAIL_USERNAME=
|
||||
EMAIL_PASSWORD=
|
||||
ANALYTICS_ID=ABC
|
||||
ANALYTICS_ID=ABC
|
||||
EMAIL_PRETEND=true
|
3
.gitignore
vendored
3
.gitignore
vendored
@@ -28,3 +28,6 @@ tests/_output/*
|
||||
clover.xml
|
||||
node_modules/
|
||||
addNewLines.php
|
||||
.phpstorm.meta.php
|
||||
.env.backup
|
||||
.env.local
|
||||
|
@@ -16,7 +16,7 @@ install:
|
||||
- mv -v .env.testing .env
|
||||
|
||||
script:
|
||||
- phpunit --debug
|
||||
- phpunit
|
||||
|
||||
after_script:
|
||||
- php vendor/bin/coveralls
|
||||
|
108
README.md
108
README.md
@@ -1,46 +1,64 @@
|
||||
Firefly III (v3.3.9)
|
||||
===========
|
||||
# Firefly III
|
||||
#### v3.4.0.6
|
||||
|
||||
[](https://travis-ci.org/JC5/firefly-iii)
|
||||
[](http://stillmaintained.com/JC5/firefly-iii)
|
||||
[](https://insight.sensiolabs.com/projects/d44c7012-5f50-41ad-add8-8445330e4102)
|
||||
[](https://codeclimate.com/github/JC5/firefly-iii)
|
||||
[](https://coveralls.io/r/JC5/firefly-iii?branch=master)
|
||||
[](https://coveralls.io/r/JC5/firefly-iii?branch=develop)
|
||||
|
||||
[](https://packagist.org/packages/grumpydictator/firefly-iii)
|
||||
[](https://packagist.org/packages/grumpydictator/firefly-iii)
|
||||
[](https://packagist.org/packages/grumpydictator/firefly-iii)
|
||||
[](https://packagist.org/packages/grumpydictator/firefly-iii)
|
||||

|
||||
## About
|
||||
|
||||
Firefly III is a tool to help you manage your finances. Please read the full description [in the wiki](https://github.com/JC5/firefly-iii/wiki/full-description).
|
||||
|
||||
Firefly Mark III is a new version of Firefly built upon best practices and lessons learned
|
||||
from building [Firefly](https://github.com/JC5/Firefly). It's Mark III since the original Firefly never made it outside of my
|
||||
laptop and [Firefly II](https://github.com/JC5/Firefly) is live.
|
||||
|
||||
If you're not sure if this tool is for you, please read the [full description](https://github.com/JC5/firefly-iii/wiki/full-description).
|
||||
|
||||
To install and use Firefly III, please read [the installation guide](https://github.com/JC5/firefly-iii/wiki/Installation),
|
||||
[the upgrade guide](https://github.com/JC5/firefly-iii/wiki/Upgrade-instructions) (if applicable) and the **[first use guide](https://github.com/JC5/firefly-iii/wiki/First-use)**.
|
||||
"Firefly III" is a financial manager. It can help you keep track of expenses, income, budgets and everything in between. It even supports credit cards, shared
|
||||
household accounts and savings accounts! It's pretty fancy. You should use it to save and organise money.
|
||||
|
||||
If you want to try out Firefly III, you can do so on [this dedicated website](https://geld.nder.be/). This site always runs the latest version of Firefly III. If you want to use it, please read the [privacy considerations](https://github.com/JC5/firefly-iii/wiki/Privacy-on-demo-site) for this demo-site.
|
||||
_Firefly is a system you'll have install yourself on webhosting of your choosing._
|
||||
|
||||
Personal financial management is pretty difficult, and everybody has their own approach to it. Some people
|
||||
make budgets, other people limit their cashflow by throwing away their credit cards, others try to increase
|
||||
their current cashflow. There are tons of ways to save and earn money.
|
||||
|
||||
Firefly works on the principle that if you know where you're money is going, you can stop it from going there.
|
||||
|
||||
|
||||
To get to know Firefly, and to see if it fits you, check out these resources:
|
||||
|
||||
- The screenshots below on this very page.
|
||||
- The featurelist below, also on this very page.
|
||||
- The [full description](https://github.com/JC5/firefly-iii/wiki/full-description), which will tell you how Firefly works,
|
||||
and the philosophy behind it.
|
||||
|
||||
|
||||
#### About the name (if you care)
|
||||
|
||||
It's III, or 3, because [version 2](https://github.com/JC5/Firefly) and version 1 (not online) preceded it. It has been growing steadily ever since.
|
||||
|
||||
## Running and installing
|
||||
|
||||
If you're still interested please read [the installation guide](https://github.com/JC5/firefly-iii/wiki/Installation),
|
||||
[the upgrade guide](https://github.com/JC5/firefly-iii/wiki/Upgrade-instructions) (if applicable)
|
||||
and the **[first use guide](https://github.com/JC5/firefly-iii/wiki/First-use)**.
|
||||
|
||||
If you want to try out Firefly III, you can do so on [this dedicated website](https://geld.nder.be/).
|
||||
This site always runs the latest version of Firefly III. If you want to use it, please read the [privacy considerations](https://github.com/JC5/firefly-iii/wiki/Privacy-on-demo-site) for this demo-site.
|
||||
|
||||
## Current features
|
||||
|
||||
- [A double-entry bookkeeping system](https://en.wikipedia.org/wiki/Double-entry_bookkeeping_system);
|
||||
- You can store, edit and remove withdrawals, deposits and transfers. This allows you full financial management;
|
||||
- You can store, edit and remove [withdrawals, deposits and transfers](https://en.wikipedia.org/wiki/Financial_transaction). This allows you full financial management;
|
||||
- You can manage different types of accounts
|
||||
- Asset accounts
|
||||
- Shared asset accounts (household accounts)
|
||||
- [Asset](https://en.wikipedia.org/wiki/Asset) accounts
|
||||
- Shared [asset accounts](https://en.wikipedia.org/wiki/Asset) ([household accounts](https://en.wikipedia.org/wiki/Household))
|
||||
- Saving accounts
|
||||
- Credit cards
|
||||
- It's possible to create, change and manage money using _[budgets](https://en.wikipedia.org/wiki/Envelope_system)_;
|
||||
- Organize transactions using categories;
|
||||
- Save towards a goal using piggy banks;
|
||||
- Predict and anticipate bills;
|
||||
- View income / expense reports;
|
||||
- Lots of help text in case you don't get it;
|
||||
- Save towards a goal using [piggy banks](https://en.wikipedia.org/wiki/Piggy_bank);
|
||||
- Predict and anticipate [bills](https://en.wikipedia.org/wiki/Invoice);
|
||||
- View income / expense [reports](https://en.wikipedia.org/wiki/Financial_statement);
|
||||
- Organize expenses using tags;
|
||||
- Lots of help text in case you don't get it.
|
||||
|
||||
Everything is organised:
|
||||
|
||||
@@ -50,33 +68,29 @@ Everything is organised:
|
||||
- Lots of charts because we all love them.
|
||||
- Financial reporting showing you how well you are doing;
|
||||
|
||||
## Changes
|
||||
|
||||
Firefly III will feature, but does not feature yet:
|
||||
|
||||
|
||||
- More control over other resources outside of personal finance
|
||||
- Debts
|
||||
- More test-coverage;
|
||||
- Firefly will be able to split transactions; a single purchase can be split in multiple entries, for more fine-grained control.
|
||||
- Firefly will be able to join transactions.
|
||||
- Any other features I might not have thought of.
|
||||
|
||||
Some stuff has been removed:
|
||||
|
||||
- The nesting of budgets, categories and beneficiaries is removed because it was pretty pointless.
|
||||
|
||||
## Screenshots
|
||||
|
||||

|
||||
_Please note that everything in these screenshots is fictional and may not be realistic._
|
||||
|
||||

|
||||

|
||||
|
||||

|
||||

|
||||
|
||||

|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
## Current state
|
||||
I have the basics up and running. Test coverage is currently coming, slowly.
|
||||
|
||||
Questions, ideas or other things to contribute? [Let me know](https://github.com/JC5/firefly-iii/issues/new)!
|
||||
Firefly III is pretty much all grown up. Full test coverage (nerd alert!) is coming. One of the things on the todo-list
|
||||
is adding translations.
|
||||
|
||||
Questions, ideas, bugs or other things to contribute? [Let me know](https://github.com/JC5/firefly-iii/issues/new)!
|
||||
|
||||
If you like this tool, feel free to [donate me some beer money](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=2ZMV952UUSCLU&lc=NL&item_name=Development%20of%20Firefly¤cy_code=EUR&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHosted).
|
||||
|
@@ -2,6 +2,7 @@
|
||||
/**
|
||||
* Class Command
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Commands
|
||||
*/
|
||||
abstract class Command
|
||||
|
@@ -6,6 +6,7 @@ use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
/**
|
||||
* Class Kernel
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Console
|
||||
*/
|
||||
class Kernel extends ConsoleKernel
|
||||
|
@@ -3,6 +3,7 @@
|
||||
/**
|
||||
* Class Event
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Events
|
||||
*/
|
||||
abstract class Event
|
||||
|
@@ -6,6 +6,7 @@ use Illuminate\Queue\SerializesModels;
|
||||
/**
|
||||
* Class JournalCreated
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Events
|
||||
*/
|
||||
class JournalCreated extends Event
|
||||
@@ -19,7 +20,8 @@ class JournalCreated extends Event
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
* @param TransactionJournal $journal
|
||||
* @param $piggyBankId
|
||||
*/
|
||||
public function __construct(TransactionJournal $journal, $piggyBankId)
|
||||
{
|
||||
|
@@ -2,6 +2,12 @@
|
||||
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Class JournalDeleted
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Events
|
||||
*/
|
||||
class JournalDeleted extends Event
|
||||
{
|
||||
|
||||
@@ -10,7 +16,6 @@ class JournalDeleted extends Event
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
@@ -3,6 +3,12 @@
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Class JournalSaved
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Events
|
||||
*/
|
||||
class JournalSaved extends Event
|
||||
{
|
||||
|
||||
@@ -13,7 +19,7 @@ class JournalSaved extends Event
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
* @param TransactionJournal $journal
|
||||
*/
|
||||
public function __construct(TransactionJournal $journal)
|
||||
{
|
||||
|
@@ -6,6 +6,7 @@ namespace FireflyIII\Exceptions;
|
||||
/**
|
||||
* Class FireflyException
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Exceptions
|
||||
*/
|
||||
class FireflyException extends \Exception
|
||||
|
@@ -6,6 +6,7 @@ use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
/**
|
||||
* Class Handler
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Exceptions
|
||||
*/
|
||||
class Handler extends ExceptionHandler
|
||||
@@ -49,8 +50,7 @@ class Handler extends ExceptionHandler
|
||||
*/
|
||||
public function report(Exception $e)
|
||||
{
|
||||
/** @noinspection PhpInconsistentReturnPointsInspection */
|
||||
return parent::report($e);
|
||||
parent::report($e);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@ namespace FireflyIII\Exceptions;
|
||||
/**
|
||||
* Class NotImplementedException
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Exceptions
|
||||
*/
|
||||
class NotImplementedException extends \Exception
|
||||
|
@@ -4,6 +4,7 @@ namespace FireflyIII\Exceptions;
|
||||
/**
|
||||
* Class ValidationExceptions
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Exception
|
||||
*/
|
||||
class ValidationException extends \Exception
|
||||
|
@@ -19,7 +19,6 @@ class ConnectJournalToPiggyBank
|
||||
/**
|
||||
* Create the event handler.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
@@ -31,7 +30,7 @@ class ConnectJournalToPiggyBank
|
||||
*
|
||||
* @param JournalCreated $event
|
||||
*
|
||||
* @return void
|
||||
* @return boolean
|
||||
*/
|
||||
public function handle(JournalCreated $event)
|
||||
{
|
||||
@@ -39,7 +38,7 @@ class ConnectJournalToPiggyBank
|
||||
$journal = $event->journal;
|
||||
$piggyBankId = $event->piggyBankId;
|
||||
if (intval($piggyBankId) < 1) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
Log::debug('JournalCreated event: ' . $journal->id . ', ' . $piggyBankId);
|
||||
@@ -48,23 +47,39 @@ class ConnectJournalToPiggyBank
|
||||
$piggyBank = Auth::user()->piggybanks()->where('piggy_banks.id', $piggyBankId)->first(['piggy_banks.*']);
|
||||
|
||||
if (is_null($piggyBank) || $journal->transactionType->type != 'Transfer') {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
Log::debug('Found a piggy bank');
|
||||
$amount = $journal->amount;
|
||||
Log::debug('Amount: ' . $amount);
|
||||
if ($amount == 0) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
// update piggy bank rep for date of transaction journal.
|
||||
$repetition = $piggyBank->piggyBankRepetitions()->relevantOnDate($journal->date)->first();
|
||||
if (is_null($repetition)) {
|
||||
Log::debug('Found no repetition for piggy bank for date ' . $journal->date->format('Y M d'));
|
||||
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
Log::debug('Found rep! ' . $repetition->id);
|
||||
|
||||
/*
|
||||
* Add amount when
|
||||
*/
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($journal->transactions()->get() as $transaction) {
|
||||
if ($transaction->account_id == $piggyBank->account_id) {
|
||||
if ($transaction->amount < 0) {
|
||||
$amount = $amount * -1;
|
||||
Log::debug('Transaction is away from piggy, so amount becomes ' . $amount);
|
||||
} else {
|
||||
Log::debug('Transaction is to from piggy, so amount stays ' . $amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$repetition->currentamount += $amount;
|
||||
$repetition->save();
|
||||
|
||||
@@ -76,6 +91,7 @@ class ConnectJournalToPiggyBank
|
||||
'amount' => $amount
|
||||
]
|
||||
);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
@@ -5,6 +5,7 @@ use FireflyIII\Events\JournalDeleted;
|
||||
/**
|
||||
* Class JournalDeletedHandler
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Handlers\Events
|
||||
*/
|
||||
class JournalDeletedHandler
|
||||
|
@@ -7,6 +7,7 @@ use Log;
|
||||
/**
|
||||
* Class RescanJournal
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Handlers\Events
|
||||
*/
|
||||
class RescanJournal
|
||||
@@ -15,7 +16,6 @@ class RescanJournal
|
||||
/**
|
||||
* Create the event handler.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
@@ -41,7 +41,7 @@ class RescanJournal
|
||||
|
||||
Log::debug('Found ' . $list->count() . ' bills to check.');
|
||||
|
||||
/** @var Bill $bill */
|
||||
/** @var \FireflyIII\Models\Bill $bill */
|
||||
foreach ($list as $bill) {
|
||||
Log::debug('Now calling bill #' . $bill->id . ' (' . $bill->name . ')');
|
||||
$repository->scan($bill, $journal);
|
||||
|
@@ -2,11 +2,11 @@
|
||||
|
||||
use FireflyIII\Events\JournalSaved;
|
||||
use FireflyIII\Models\PiggyBankEvent;
|
||||
use FireflyIII\Models\Transaction;
|
||||
|
||||
/**
|
||||
* Class UpdateJournalConnection
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Handlers\Events
|
||||
*/
|
||||
class UpdateJournalConnection
|
||||
@@ -15,7 +15,6 @@ class UpdateJournalConnection
|
||||
/**
|
||||
* Create the event handler.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
@@ -17,6 +17,7 @@ class Help implements HelpInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @param $key
|
||||
*
|
||||
* @return string
|
||||
@@ -27,6 +28,7 @@ class Help implements HelpInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @param $route
|
||||
*
|
||||
* @return array
|
||||
@@ -54,7 +56,10 @@ class Help implements HelpInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
* @codeCoverageIgnore
|
||||
* @param $route
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasRoute($route)
|
||||
{
|
||||
@@ -62,10 +67,11 @@ class Help implements HelpInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $title
|
||||
* @codeCoverageIgnore
|
||||
* @param $route
|
||||
* @param array $content
|
||||
*
|
||||
* @return void
|
||||
* @internal param $title
|
||||
*/
|
||||
public function putInCache($route, array $content)
|
||||
{
|
||||
@@ -74,6 +80,7 @@ class Help implements HelpInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @param $route
|
||||
*
|
||||
* @return bool
|
||||
@@ -82,4 +89,4 @@ class Help implements HelpInterface
|
||||
{
|
||||
return Cache::has('help.' . $route . '.title') && Cache::has('help.' . $route . '.text');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -18,16 +18,25 @@ interface HelpInterface
|
||||
public function getFromCache($key);
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
* @param $route
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getFromGithub($route);
|
||||
|
||||
/**
|
||||
* @param $route
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasRoute($route);
|
||||
|
||||
/**
|
||||
* @param $route
|
||||
*
|
||||
* @return array
|
||||
* @return bool
|
||||
*/
|
||||
public function getFromGithub($route);
|
||||
public function inCache($route);
|
||||
|
||||
/**
|
||||
* @param $route
|
||||
@@ -36,11 +45,4 @@ interface HelpInterface
|
||||
* @return void
|
||||
*/
|
||||
public function putInCache($route, array $content);
|
||||
|
||||
/**
|
||||
* @param $route
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function inCache($route);
|
||||
}
|
||||
}
|
||||
|
@@ -33,7 +33,7 @@ class ReminderHelper implements ReminderHelperInterface
|
||||
$ranges = $this->getReminderRanges($piggyBank, $start);
|
||||
$currentRep = $piggyBank->currentRelevantRep();
|
||||
$left = $piggyBank->targetamount - $currentRep->currentamount;
|
||||
$perReminder = $left / count($ranges);
|
||||
$perReminder = count($ranges) == 0 ? $left : $left / count($ranges);
|
||||
} else {
|
||||
$perReminder = null;
|
||||
$ranges = [];
|
||||
@@ -46,8 +46,6 @@ class ReminderHelper implements ReminderHelperInterface
|
||||
'leftToSave' => $left,
|
||||
];
|
||||
|
||||
|
||||
// create one:
|
||||
$reminder = new Reminder;
|
||||
$reminder->user()->associate(Auth::user());
|
||||
$reminder->startdate = $start;
|
||||
|
@@ -18,25 +18,6 @@ use Steam;
|
||||
class ReportHelper implements ReportHelperInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* This methods fails to take in account transfers FROM shared accounts.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function expensesGroupedByAccount(Carbon $start, Carbon $end, $limit = 15)
|
||||
{
|
||||
$result = $this->_queries->journalsByExpenseAccount($start, $end);
|
||||
$array = $this->_helper->makeArray($result);
|
||||
$limited = $this->_helper->limitArray($array, $limit);
|
||||
|
||||
return $limited;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets some kind of list for a monthly overview.
|
||||
*
|
||||
@@ -91,11 +72,11 @@ class ReportHelper implements ReportHelperInterface
|
||||
$end = Carbon::now();
|
||||
$months = [];
|
||||
while ($start <= $end) {
|
||||
$year = $start->format('Y');
|
||||
$year = $start->year;
|
||||
$months[$year][] = [
|
||||
'formatted' => $start->format('F Y'),
|
||||
'month' => intval($start->format('m')),
|
||||
'year' => intval($start->format('Y')),
|
||||
'month' => $start->month,
|
||||
'year' => $year,
|
||||
];
|
||||
$start->addMonth();
|
||||
}
|
||||
@@ -114,10 +95,10 @@ class ReportHelper implements ReportHelperInterface
|
||||
$end = Carbon::now();
|
||||
$years = [];
|
||||
while ($start <= $end) {
|
||||
$years[] = $start->format('Y');
|
||||
$years[] = $start->year;
|
||||
$start->addYear();
|
||||
}
|
||||
$years[] = Carbon::now()->format('Y');
|
||||
$years[] = Carbon::now()->year;
|
||||
// force the current year.
|
||||
$years = array_unique($years);
|
||||
|
||||
@@ -136,7 +117,7 @@ class ReportHelper implements ReportHelperInterface
|
||||
$end = clone $date;
|
||||
$sharedAccounts = [];
|
||||
if ($showSharedReports === false) {
|
||||
$sharedCollection = \Auth::user()->accounts()
|
||||
$sharedCollection = Auth::user()->accounts()
|
||||
->leftJoin('account_meta', 'account_meta.account_id', '=', 'accounts.id')
|
||||
->where('account_meta.name', '=', 'accountRole')
|
||||
->where('account_meta.data', '=', json_encode('sharedAsset'))
|
||||
|
@@ -13,18 +13,6 @@ use Illuminate\Support\Collection;
|
||||
interface ReportHelperInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* This methods fails to take in account transfers FROM shared accounts.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function expensesGroupedByAccount(Carbon $start, Carbon $end, $limit = 15);
|
||||
|
||||
/**
|
||||
* This method gets some kind of list for a monthly overview.
|
||||
*
|
||||
|
@@ -150,8 +150,16 @@ class ReportQuery implements ReportQueryInterface
|
||||
$set = $query->get(['accounts.*']);
|
||||
$set->each(
|
||||
function (Account $account) use ($start, $end) {
|
||||
/**
|
||||
* The balance for today always incorporates transactions
|
||||
* made on today. So to get todays "start" balance, we sub one
|
||||
* day.
|
||||
*/
|
||||
$yesterday = clone $start;
|
||||
$yesterday->subDay();
|
||||
|
||||
/** @noinspection PhpParamsInspection */
|
||||
$account->startBalance = Steam::balance($account, $start);
|
||||
$account->startBalance = Steam::balance($account, $yesterday);
|
||||
$account->endBalance = Steam::balance($account, $end);
|
||||
}
|
||||
);
|
||||
|
@@ -11,6 +11,7 @@ use Input;
|
||||
use Redirect;
|
||||
use Session;
|
||||
use Steam;
|
||||
use URL;
|
||||
use View;
|
||||
|
||||
/**
|
||||
@@ -25,6 +26,7 @@ class AccountController extends Controller
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
View::share('mainTitleIcon', 'fa-credit-card');
|
||||
View::share('title', 'Accounts');
|
||||
}
|
||||
@@ -39,6 +41,12 @@ class AccountController extends Controller
|
||||
$subTitleIcon = Config::get('firefly.subIconsByIdentifier.' . $what);
|
||||
$subTitle = 'Create a new ' . e($what) . ' account';
|
||||
|
||||
// put previous url in session if not redirect from store (not "create another").
|
||||
if (Session::get('accounts.create.fromStore') !== true) {
|
||||
Session::put('accounts.create.url', URL::previous());
|
||||
}
|
||||
Session::forget('accounts.create.fromStore');
|
||||
|
||||
return view('accounts.create', compact('subTitleIcon', 'what', 'subTitle'));
|
||||
|
||||
}
|
||||
@@ -52,15 +60,19 @@ class AccountController extends Controller
|
||||
{
|
||||
$subTitle = 'Delete ' . strtolower(e($account->accountType->type)) . ' "' . e($account->name) . '"';
|
||||
|
||||
// put previous url in session
|
||||
Session::put('accounts.delete.url', URL::previous());
|
||||
|
||||
return view('accounts.delete', compact('account', 'subTitle'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param AccountRepositoryInterface $repository
|
||||
* @param Account $account
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(Account $account, AccountRepositoryInterface $repository)
|
||||
public function destroy(AccountRepositoryInterface $repository, Account $account)
|
||||
{
|
||||
|
||||
$type = $account->accountType->type;
|
||||
@@ -71,16 +83,16 @@ class AccountController extends Controller
|
||||
|
||||
Session::flash('success', 'The ' . e($typeName) . ' account "' . e($name) . '" was deleted.');
|
||||
|
||||
return Redirect::route('accounts.index', $typeName);
|
||||
return Redirect::to(Session::get('accounts.delete.url'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param AccountRepositoryInterface $repository
|
||||
* @param Account $account
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
public function edit(Account $account, AccountRepositoryInterface $repository)
|
||||
public function edit(AccountRepositoryInterface $repository, Account $account)
|
||||
{
|
||||
|
||||
$what = Config::get('firefly.shortNamesByFullName')[$account->accountType->type];
|
||||
@@ -88,6 +100,12 @@ class AccountController extends Controller
|
||||
$subTitleIcon = Config::get('firefly.subIconsByIdentifier.' . $what);
|
||||
$openingBalance = $repository->openingBalanceTransaction($account);
|
||||
|
||||
// put previous url in session if not redirect from store (not "return_to_edit").
|
||||
if (Session::get('accounts.edit.fromUpdate') !== true) {
|
||||
Session::put('accounts.edit.url', URL::previous());
|
||||
}
|
||||
Session::forget('accounts.edit.fromUpdate');
|
||||
|
||||
// pre fill some useful values.
|
||||
|
||||
// the opening balance is tricky:
|
||||
@@ -112,12 +130,12 @@ class AccountController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $what
|
||||
* @param AccountRepositoryInterface $repository
|
||||
* @param $what
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
public function index($what, AccountRepositoryInterface $repository)
|
||||
public function index(AccountRepositoryInterface $repository, $what)
|
||||
{
|
||||
$subTitle = Config::get('firefly.subTitlesByIdentifier.' . $what);
|
||||
$subTitleIcon = Config::get('firefly.subIconsByIdentifier.' . $what);
|
||||
@@ -141,12 +159,12 @@ class AccountController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param AccountRepositoryInterface $repository
|
||||
* @param Account $account
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
public function show(Account $account, AccountRepositoryInterface $repository)
|
||||
public function show(AccountRepositoryInterface $repository, Account $account)
|
||||
{
|
||||
$page = intval(Input::get('page')) == 0 ? 1 : intval(Input::get('page'));
|
||||
$subTitleIcon = Config::get('firefly.subTitlesByIdentifier.' . $account->accountType->type);
|
||||
@@ -184,23 +202,28 @@ class AccountController extends Controller
|
||||
Session::flash('success', 'New account "' . $account->name . '" stored!');
|
||||
|
||||
if (intval(Input::get('create_another')) === 1) {
|
||||
return Redirect::route('accounts.create', $request->input('what'))->withInput();
|
||||
// set value so create routine will not overwrite URL:
|
||||
Session::put('accounts.create.fromStore', true);
|
||||
|
||||
return Redirect::route('accounts.create')->withInput();
|
||||
}
|
||||
|
||||
return Redirect::route('accounts.index', $request->input('what'));
|
||||
// redirect to previous URL.
|
||||
return Redirect::to(Session::get('accounts.create.url'));
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param AccountFormRequest $request
|
||||
* @param AccountRepositoryInterface $repository
|
||||
* @param Account $account
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @return $this|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(Account $account, AccountFormRequest $request, AccountRepositoryInterface $repository)
|
||||
public function update(AccountFormRequest $request, AccountRepositoryInterface $repository, Account $account)
|
||||
{
|
||||
$what = Config::get('firefly.shortNamesByFullName.' . $account->accountType->type);
|
||||
|
||||
$accountData = [
|
||||
'name' => $request->input('name'),
|
||||
'active' => $request->input('active'),
|
||||
@@ -219,10 +242,14 @@ class AccountController extends Controller
|
||||
Session::flash('success', 'Account "' . $account->name . '" updated.');
|
||||
|
||||
if (intval(Input::get('return_to_edit')) === 1) {
|
||||
return Redirect::route('accounts.edit', $account->id);
|
||||
// set value so edit routine will not overwrite URL:
|
||||
Session::put('accounts.edit.fromUpdate', true);
|
||||
|
||||
return Redirect::route('accounts.edit', $account->id)->withInput(['return_to_edit' => 1]);
|
||||
}
|
||||
|
||||
return Redirect::route('accounts.index', $what);
|
||||
// redirect to previous URL.
|
||||
return Redirect::to(Session::get('accounts.edit.url'));
|
||||
|
||||
}
|
||||
|
||||
|
@@ -8,6 +8,7 @@ use Illuminate\Http\Request;
|
||||
use Illuminate\Mail\Message;
|
||||
use Mail;
|
||||
use Session;
|
||||
use Twig;
|
||||
|
||||
/**
|
||||
* Class AuthController
|
||||
@@ -37,6 +38,7 @@ class AuthController extends Controller
|
||||
*
|
||||
* @param \Illuminate\Contracts\Auth\Guard $auth
|
||||
* @param \Illuminate\Contracts\Auth\Registrar $registrar
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
*/
|
||||
public function __construct(Guard $auth, Registrar $registrar)
|
||||
@@ -47,6 +49,18 @@ class AuthController extends Controller
|
||||
$this->middleware('guest', ['except' => 'getLogout']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the application login form.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @return \Illuminate\Http\Response
|
||||
*
|
||||
*/
|
||||
public function getLogin()
|
||||
{
|
||||
return Twig::render('auth.login');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a registration request for the application.
|
||||
*
|
||||
@@ -62,7 +76,9 @@ class AuthController extends Controller
|
||||
$this->throwValidationException(
|
||||
$request, $validator
|
||||
);
|
||||
// @codeCoverageIgnoreStart
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
$data = $request->all();
|
||||
$data['password'] = bcrypt($data['password']);
|
||||
|
@@ -7,7 +7,7 @@ use Illuminate\Foundation\Auth\ResetsPasswords;
|
||||
|
||||
/**
|
||||
* Class PasswordController
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Http\Controllers\Auth
|
||||
*/
|
||||
class PasswordController extends Controller
|
||||
|
@@ -4,7 +4,6 @@ use Config;
|
||||
use FireflyIII\Http\Requests;
|
||||
use FireflyIII\Http\Requests\BillFormRequest;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
@@ -29,16 +28,18 @@ class BillController extends Controller
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
View::share('title', 'Bills');
|
||||
View::share('mainTitleIcon', 'fa-calendar-o');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
* @param AccountRepositoryInterface $repository
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function add(Bill $bill, AccountRepositoryInterface $repository)
|
||||
public function add(AccountRepositoryInterface $repository, Bill $bill)
|
||||
{
|
||||
$matches = explode(',', $bill->match);
|
||||
$description = [];
|
||||
@@ -83,7 +84,14 @@ class BillController extends Controller
|
||||
{
|
||||
$periods = Config::get('firefly.periods_to_text');
|
||||
|
||||
return view('bills.create')->with('periods', $periods)->with('subTitle', 'Create new');
|
||||
// put previous url in session if not redirect from store (not "create another").
|
||||
if (Session::get('bills.create.fromStore') !== true) {
|
||||
Session::put('bills.create.url', URL::previous());
|
||||
}
|
||||
Session::forget('bills.create.fromStore');
|
||||
$subTitle = 'Create new bill';
|
||||
|
||||
return view('bills.create', compact('periods', 'subTitle'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,21 +101,26 @@ class BillController extends Controller
|
||||
*/
|
||||
public function delete(Bill $bill)
|
||||
{
|
||||
return view('bills.delete')->with('bill', $bill)->with('subTitle', 'Delete "' . e($bill->name) . '"');
|
||||
// put previous url in session
|
||||
Session::put('bills.delete.url', URL::previous());
|
||||
$subTitle = 'Delete "' . e($bill->name) . '"';
|
||||
|
||||
return view('bills.delete', compact('bill', 'subTitle'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
* @param BillRepositoryInterface $repository
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(Bill $bill, BillRepositoryInterface $repository)
|
||||
public function destroy(BillRepositoryInterface $repository, Bill $bill)
|
||||
{
|
||||
$repository->destroy($bill);
|
||||
|
||||
Session::flash('success', 'The bill was deleted.');
|
||||
|
||||
return Redirect::route('bills.index');
|
||||
return Redirect::to(Session::get('bills.delete.url'));
|
||||
|
||||
}
|
||||
|
||||
@@ -118,9 +131,16 @@ class BillController extends Controller
|
||||
*/
|
||||
public function edit(Bill $bill)
|
||||
{
|
||||
$periods = Config::get('firefly.periods_to_text');
|
||||
$periods = Config::get('firefly.periods_to_text');
|
||||
$subTitle = 'Edit "' . e($bill->name) . '"';
|
||||
|
||||
return view('bills.edit')->with('periods', $periods)->with('bill', $bill)->with('subTitle', 'Edit "' . e($bill->name) . '"');
|
||||
// put previous url in session if not redirect from store (not "return_to_edit").
|
||||
if (Session::get('bills.edit.fromUpdate') !== true) {
|
||||
Session::put('bills.edit.url', URL::previous());
|
||||
}
|
||||
Session::forget('bills.edit.fromUpdate');
|
||||
|
||||
return view('bills.edit', compact('subTitle', 'periods', 'bill'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -142,11 +162,12 @@ class BillController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
* @param BillRepositoryInterface $repository
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return mixed
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function rescan(Bill $bill, BillRepositoryInterface $repository)
|
||||
public function rescan(BillRepositoryInterface $repository, Bill $bill)
|
||||
{
|
||||
if (intval($bill->active) == 0) {
|
||||
Session::flash('warning', 'Inactive bills cannot be scanned.');
|
||||
@@ -167,21 +188,26 @@ class BillController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
* @param BillRepositoryInterface $repository
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function show(Bill $bill, BillRepositoryInterface $repository)
|
||||
public function show(BillRepositoryInterface $repository, Bill $bill)
|
||||
{
|
||||
$journals = $repository->getJournals($bill);
|
||||
$bill->nextExpectedMatch = $repository->nextExpectedMatch($bill);
|
||||
$hideBill = true;
|
||||
$subTitle = e($bill->name);
|
||||
|
||||
return view('bills.show', compact('journals', 'hideBill', 'bill'))->with('subTitle', e($bill->name));
|
||||
return view('bills.show', compact('journals', 'hideBill', 'bill', 'subTitle'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
* @param BillFormRequest $request
|
||||
* @param BillRepositoryInterface $repository
|
||||
*
|
||||
* @return $this|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(BillFormRequest $request, BillRepositoryInterface $repository)
|
||||
{
|
||||
@@ -190,30 +216,40 @@ class BillController extends Controller
|
||||
Session::flash('success', 'Bill "' . e($bill->name) . '" stored.');
|
||||
|
||||
if (intval(Input::get('create_another')) === 1) {
|
||||
// set value so create routine will not overwrite URL:
|
||||
Session::put('bills.create.fromStore', true);
|
||||
|
||||
return Redirect::route('bills.create')->withInput();
|
||||
}
|
||||
|
||||
return Redirect::route('bills.index');
|
||||
// redirect to previous URL.
|
||||
return Redirect::to(Session::get('bills.create.url'));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
* @param BillFormRequest $request
|
||||
* @param BillRepositoryInterface $repository
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return $this
|
||||
* @return $this|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(Bill $bill, BillFormRequest $request, BillRepositoryInterface $repository)
|
||||
public function update(BillFormRequest $request, BillRepositoryInterface $repository, Bill $bill)
|
||||
{
|
||||
$billData = $request->getBillData();
|
||||
$bill = $repository->update($bill, $billData);
|
||||
|
||||
if (intval(Input::get('return_to_edit')) === 1) {
|
||||
return Redirect::route('bills.edit', $bill->id);
|
||||
}
|
||||
|
||||
Session::flash('success', 'Bill "' . e($bill->name) . '" updated.');
|
||||
|
||||
return Redirect::route('bills.index');
|
||||
if (intval(Input::get('return_to_edit')) === 1) {
|
||||
// set value so edit routine will not overwrite URL:
|
||||
Session::put('bills.edit.fromUpdate', true);
|
||||
|
||||
return Redirect::route('bills.edit', $bill->id)->withInput(['return_to_edit' => 1]);
|
||||
}
|
||||
|
||||
// redirect to previous URL.
|
||||
return Redirect::to(Session::get('bills.edit.url'));
|
||||
|
||||
}
|
||||
|
||||
|
@@ -5,7 +5,6 @@ use Carbon\Carbon;
|
||||
use FireflyIII\Http\Requests;
|
||||
use FireflyIII\Http\Requests\BudgetFormRequest;
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Models\BudgetLimit;
|
||||
use FireflyIII\Models\LimitRepetition;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use Input;
|
||||
@@ -29,16 +28,19 @@ class BudgetController extends Controller
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
View::share('title', 'Budgets');
|
||||
View::share('mainTitleIcon', 'fa-tasks');
|
||||
View::share('hideBudgets', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
* @param BudgetRepositoryInterface $repository
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function amount(Budget $budget, BudgetRepositoryInterface $repository)
|
||||
public function amount(BudgetRepositoryInterface $repository, Budget $budget)
|
||||
{
|
||||
$amount = intval(Input::get('amount'));
|
||||
$date = Session::get('start', Carbon::now()->startOfMonth());
|
||||
@@ -58,8 +60,9 @@ class BudgetController extends Controller
|
||||
Session::put('budgets.create.url', URL::previous());
|
||||
}
|
||||
Session::forget('budgets.create.fromStore');
|
||||
$subTitle = 'Create a new budget';
|
||||
|
||||
return view('budgets.create')->with('subTitle', 'Create a new budget');
|
||||
return view('budgets.create', compact('subTitle'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,7 +81,8 @@ class BudgetController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
* @param Budget $budget
|
||||
* @param BudgetRepositoryInterface $repository
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
@@ -114,7 +118,9 @@ class BudgetController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
* @param BudgetRepositoryInterface $repository
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
public function index(BudgetRepositoryInterface $repository)
|
||||
{
|
||||
@@ -148,7 +154,9 @@ class BudgetController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\View\View
|
||||
* @param BudgetRepositoryInterface $repository
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
public function noBudget(BudgetRepositoryInterface $repository)
|
||||
{
|
||||
@@ -161,7 +169,7 @@ class BudgetController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function postUpdateIncome()
|
||||
{
|
||||
@@ -173,24 +181,26 @@ class BudgetController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BudgetRepositoryInterface $repository
|
||||
* @param Budget $budget
|
||||
* @param LimitRepetition $repetition
|
||||
*
|
||||
* @param Budget $budget
|
||||
* @param LimitRepetition $repetition
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
* @return View
|
||||
*/
|
||||
public function show(Budget $budget, LimitRepetition $repetition = null, BudgetRepositoryInterface $repository)
|
||||
public function show(BudgetRepositoryInterface $repository, Budget $budget, LimitRepetition $repetition = null)
|
||||
{
|
||||
if (!is_null($repetition->id) && $repetition->budgetLimit->budget->id != $budget->id) {
|
||||
return view('error')->with('message', 'Invalid selection.');
|
||||
$message = 'Invalid selection.';
|
||||
|
||||
return view('error', compact('message'));
|
||||
}
|
||||
|
||||
$hideBudget = true; // used in transaction list.
|
||||
$journals = $repository->getJournals($budget, $repetition);
|
||||
$limits = !is_null($repetition->id) ? [$repetition->budgetLimit] : $repository->getBudgetLimits($budget);
|
||||
$subTitle = !is_null($repetition->id) ? e($budget->name) . ' in ' . $repetition->startdate->format('F Y') : e($budget->name);
|
||||
$journals = $repository->getJournals($budget, $repetition);
|
||||
$limits = !is_null($repetition->id) ? [$repetition->budgetLimit] : $repository->getBudgetLimits($budget);
|
||||
$subTitle = !is_null($repetition->id) ? e($budget->name) . ' in ' . $repetition->startdate->format('F Y') : e($budget->name);
|
||||
$journals->setPath('/budgets/show/' . $budget->id);
|
||||
|
||||
return view('budgets.show', compact('limits', 'budget', 'repetition', 'journals', 'subTitle', 'hideBudget'));
|
||||
return view('budgets.show', compact('limits', 'budget', 'repetition', 'journals', 'subTitle'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -222,13 +232,13 @@ class BudgetController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
* @param BudgetFormRequest $request
|
||||
* @param BudgetRepositoryInterface $repository
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @return $this|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(Budget $budget, BudgetFormRequest $request, BudgetRepositoryInterface $repository)
|
||||
public function update(BudgetFormRequest $request, BudgetRepositoryInterface $repository, Budget $budget)
|
||||
{
|
||||
$budgetData = [
|
||||
'name' => $request->input('name'),
|
||||
@@ -252,14 +262,14 @@ class BudgetController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
* @return View
|
||||
*/
|
||||
public function updateIncome()
|
||||
{
|
||||
$date = Session::get('start', Carbon::now()->startOfMonth())->format('FY');
|
||||
$budgetAmount = Preferences::get('budgetIncomeTotal' . $date, 1000);
|
||||
$date = Session::get('start', Carbon::now()->startOfMonth())->format('FY');
|
||||
$amount = Preferences::get('budgetIncomeTotal' . $date, 1000);
|
||||
|
||||
return view('budgets.income')->with('amount', $budgetAmount);
|
||||
return view('budgets.income', compact('amount'));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -2,7 +2,6 @@
|
||||
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Http\Requests;
|
||||
use FireflyIII\Http\Requests\CategoryFormRequest;
|
||||
use FireflyIII\Models\Category;
|
||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||
@@ -26,6 +25,7 @@ class CategoryController extends Controller
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
View::share('title', 'Categories');
|
||||
View::share('mainTitleIcon', 'fa-bar-chart');
|
||||
}
|
||||
@@ -40,8 +40,9 @@ class CategoryController extends Controller
|
||||
Session::put('categories.create.url', URL::previous());
|
||||
}
|
||||
Session::forget('categories.create.fromStore');
|
||||
$subTitle = 'Create a new category';
|
||||
|
||||
return view('categories.create')->with('subTitle', 'Create a new category');
|
||||
return view('categories.create', compact('subTitle'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,7 +52,7 @@ class CategoryController extends Controller
|
||||
*/
|
||||
public function delete(Category $category)
|
||||
{
|
||||
$subTitle = 'Delete category' . e($category->name) . '"';
|
||||
$subTitle = 'Delete category "' . e($category->name) . '"';
|
||||
|
||||
// put previous url in session
|
||||
Session::put('categories.delete.url', URL::previous());
|
||||
@@ -60,11 +61,12 @@ class CategoryController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
* @param CategoryRepositoryInterface $repository
|
||||
* @param Category $category
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(Category $category, CategoryRepositoryInterface $repository)
|
||||
public function destroy(CategoryRepositoryInterface $repository, Category $category)
|
||||
{
|
||||
|
||||
$name = $category->name;
|
||||
@@ -95,8 +97,9 @@ class CategoryController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
* @param CategoryRepositoryInterface $repository
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function index(CategoryRepositoryInterface $repository)
|
||||
{
|
||||
@@ -112,6 +115,8 @@ class CategoryController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CategoryRepositoryInterface $repository
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function noCategory(CategoryRepositoryInterface $repository)
|
||||
@@ -125,11 +130,12 @@ class CategoryController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
* @param CategoryRepositoryInterface $repository
|
||||
* @param Category $category
|
||||
*
|
||||
* @return $this
|
||||
* @return View
|
||||
*/
|
||||
public function show(Category $category, CategoryRepositoryInterface $repository)
|
||||
public function show(CategoryRepositoryInterface $repository, Category $category)
|
||||
{
|
||||
$hideCategory = true; // used in list.
|
||||
$page = intval(Input::get('page'));
|
||||
@@ -168,13 +174,13 @@ class CategoryController extends Controller
|
||||
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
* @param CategoryFormRequest $request
|
||||
* @param CategoryRepositoryInterface $repository
|
||||
* @param Category $category
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(Category $category, CategoryFormRequest $request, CategoryRepositoryInterface $repository)
|
||||
public function update(CategoryFormRequest $request, CategoryRepositoryInterface $repository, Category $category)
|
||||
{
|
||||
$categoryData = [
|
||||
'name' => $request->input('name'),
|
||||
|
@@ -3,6 +3,7 @@
|
||||
use Illuminate\Foundation\Bus\DispatchesCommands;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
use View;
|
||||
|
||||
/**
|
||||
* Class Controller
|
||||
@@ -14,4 +15,14 @@ abstract class Controller extends BaseController
|
||||
|
||||
use DispatchesCommands, ValidatesRequests;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
View::share('hideBudgets', false);
|
||||
View::share('hideCategories', false);
|
||||
View::share('hideBills', false);
|
||||
View::share('hideTags', false);
|
||||
}
|
||||
}
|
||||
|
@@ -27,7 +27,7 @@ class CurrencyController extends Controller
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
parent::__construct();
|
||||
View::share('title', 'Currencies');
|
||||
View::share('mainTitleIcon', 'fa-usd');
|
||||
}
|
||||
@@ -68,11 +68,12 @@ class CurrencyController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $currency
|
||||
* @param CurrencyRepositoryInterface $repository
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View
|
||||
* @return \Illuminate\Http\RedirectResponse|View
|
||||
*/
|
||||
public function delete(TransactionCurrency $currency, CurrencyRepositoryInterface $repository)
|
||||
public function delete(CurrencyRepositoryInterface $repository, TransactionCurrency $currency)
|
||||
{
|
||||
|
||||
if ($repository->countJournals($currency) > 0) {
|
||||
@@ -89,11 +90,13 @@ class CurrencyController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $currency
|
||||
* @param CurrencyRepositoryInterface $repository
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function destroy(TransactionCurrency $currency, CurrencyRepositoryInterface $repository)
|
||||
public function destroy(CurrencyRepositoryInterface $repository, TransactionCurrency $currency)
|
||||
{
|
||||
if ($repository->countJournals($currency) > 0) {
|
||||
Session::flash('error', 'Cannot destroy ' . e($currency->name) . ' because there are still transactions attached to it.');
|
||||
@@ -130,6 +133,8 @@ class CurrencyController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CurrencyRepositoryInterface $repository
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function index(CurrencyRepositoryInterface $repository)
|
||||
@@ -141,7 +146,9 @@ class CurrencyController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
|
||||
*
|
||||
* @param CurrencyFormRequest $request
|
||||
* @param CurrencyRepositoryInterface $repository
|
||||
*
|
||||
* @return $this|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
@@ -166,11 +173,13 @@ class CurrencyController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $currency
|
||||
* @param CurrencyFormRequest $request
|
||||
* @param CurrencyRepositoryInterface $repository
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return $this|\Illuminate\Http\RedirectResponse
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(TransactionCurrency $currency, CurrencyFormRequest $request, CurrencyRepositoryInterface $repository)
|
||||
public function update(CurrencyFormRequest $request, CurrencyRepositoryInterface $repository, TransactionCurrency $currency)
|
||||
{
|
||||
$data = $request->getCurrencyData();
|
||||
$currency = $repository->update($currency, $data);
|
||||
|
@@ -35,12 +35,12 @@ class GoogleChartController extends Controller
|
||||
|
||||
|
||||
/**
|
||||
* @param GChart $chart
|
||||
* @param Account $account
|
||||
* @param string $view
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function accountBalanceChart(Account $account, GChart $chart)
|
||||
public function accountBalanceChart(GChart $chart, Account $account)
|
||||
{
|
||||
$chart->addColumn('Day of month', 'date');
|
||||
$chart->addColumn('Balance for ' . $account->name, 'number');
|
||||
@@ -64,7 +64,8 @@ class GoogleChartController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param GChart $chart
|
||||
* @param GChart $chart
|
||||
* @param AccountRepositoryInterface $repository
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
@@ -104,11 +105,13 @@ class GoogleChartController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $year
|
||||
* @param GChart $chart
|
||||
* @param BudgetRepositoryInterface $repository
|
||||
* @param $year
|
||||
*
|
||||
* @return $this|\Illuminate\Http\JsonResponse
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function allBudgetsAndSpending($year, GChart $chart, BudgetRepositoryInterface $repository)
|
||||
public function allBudgetsAndSpending(GChart $chart, BudgetRepositoryInterface $repository, $year)
|
||||
{
|
||||
$budgets = $repository->getBudgets();
|
||||
$chart->addColumn('Month', 'date');
|
||||
@@ -137,15 +140,17 @@ class GoogleChartController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param GChart $chart
|
||||
* @param GChart $chart
|
||||
* @param BudgetRepositoryInterface $repository
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function allBudgetsHomeChart(GChart $chart, BudgetRepositoryInterface $repository)
|
||||
{
|
||||
$chart->addColumn('Budget', 'string');
|
||||
$chart->addColumn('Budgeted', 'number');
|
||||
$chart->addColumn('Left', 'number');
|
||||
$chart->addColumn('Spent', 'number');
|
||||
$chart->addColumn('Overspent', 'number');
|
||||
|
||||
$budgets = $repository->getBudgets();
|
||||
$start = Session::get('start', Carbon::now()->startOfMonth());
|
||||
@@ -156,22 +161,31 @@ class GoogleChartController extends Controller
|
||||
$repetitions = $repository->getBudgetLimitRepetitions($budget, $start, $end);
|
||||
if ($repetitions->count() == 0) {
|
||||
$expenses = $repository->sumBudgetExpensesInPeriod($budget, $start, $end);
|
||||
$allEntries->push([$budget->name, 0, $expenses]);
|
||||
$allEntries->push([$budget->name, 0, 0, $expenses]);
|
||||
continue;
|
||||
}
|
||||
/** @var LimitRepetition $repetition */
|
||||
foreach ($repetitions as $repetition) {
|
||||
$expenses = $repository->sumBudgetExpensesInPeriod($budget, $repetition->startdate, $repetition->enddate);
|
||||
$allEntries->push([$budget->name . ' (' . $repetition->startdate->format('j M Y') . ')', floatval($repetition->amount), $expenses]);
|
||||
$expenses = $repository->sumBudgetExpensesInPeriod($budget, $repetition->startdate, $repetition->enddate);
|
||||
$left = $expenses < floatval($repetition->amount) ? floatval($repetition->amount) - $expenses : 0;
|
||||
$spent = $expenses > floatval($repetition->amount) ? 0 : $expenses;
|
||||
$overspent = $expenses > floatval($repetition->amount) ? $expenses - floatval($repetition->amount) : 0;
|
||||
$allEntries->push(
|
||||
[$budget->name . ' (' . $repetition->startdate->format('j M Y') . ')',
|
||||
$left,
|
||||
$spent,
|
||||
$overspent
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$noBudgetExpenses = $repository->getWithoutBudgetSum($start, $end);
|
||||
$allEntries->push(['(no budget)', 0, $noBudgetExpenses]);
|
||||
$allEntries->push(['(no budget)', 0, 0, $noBudgetExpenses]);
|
||||
|
||||
foreach ($allEntries as $entry) {
|
||||
if ($entry[2] > 0) {
|
||||
$chart->addRow($entry[0], $entry[1], $entry[2]);
|
||||
if ($entry[1] != 0 || $entry[2] != 0 || $entry[3] != 0) {
|
||||
$chart->addRow($entry[0], $entry[1], $entry[2], $entry[3]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,7 +196,8 @@ class GoogleChartController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param GChart $chart
|
||||
* @param GChart $chart
|
||||
* @param CategoryRepositoryInterface $repository
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
@@ -209,12 +224,13 @@ class GoogleChartController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
* @param GChart $chart
|
||||
* @param GChart $chart
|
||||
* @param BillRepositoryInterface $repository
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function billOverview(Bill $bill, GChart $chart, BillRepositoryInterface $repository)
|
||||
public function billOverview(GChart $chart, BillRepositoryInterface $repository, Bill $bill)
|
||||
{
|
||||
|
||||
$chart->addColumn('Date', 'date');
|
||||
@@ -236,7 +252,10 @@ class GoogleChartController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param GChart $chart
|
||||
* @param GChart $chart
|
||||
*
|
||||
* @param BillRepositoryInterface $repository
|
||||
* @param AccountRepositoryInterface $accounts
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
@@ -318,13 +337,14 @@ class GoogleChartController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param GChart $chart
|
||||
* @param BudgetRepositoryInterface $repository
|
||||
* @param Budget $budget
|
||||
* @param LimitRepetition $repetition
|
||||
*
|
||||
* @param Budget $budget
|
||||
* @param LimitRepetition $repetition
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function budgetLimitSpending(Budget $budget, LimitRepetition $repetition, GChart $chart, BudgetRepositoryInterface $repository)
|
||||
public function budgetLimitSpending(GChart $chart, BudgetRepositoryInterface $repository, Budget $budget, LimitRepetition $repetition)
|
||||
{
|
||||
$start = clone $repetition->startdate;
|
||||
$end = $repetition->enddate;
|
||||
@@ -351,14 +371,14 @@ class GoogleChartController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
* @param int $year
|
||||
* @param GChart $chart
|
||||
* @param BudgetRepositoryInterface $repository
|
||||
* @param Budget $budget
|
||||
* @param int $year
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function budgetsAndSpending(Budget $budget, $year = 0, GChart $chart, BudgetRepositoryInterface $repository)
|
||||
public function budgetsAndSpending(GChart $chart, BudgetRepositoryInterface $repository, Budget $budget, $year = 0)
|
||||
{
|
||||
$chart->addColumn('Month', 'date');
|
||||
$chart->addColumn('Budgeted', 'number');
|
||||
@@ -388,12 +408,13 @@ class GoogleChartController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param GChart $chart
|
||||
* @param CategoryRepositoryInterface $repository
|
||||
* @param Category $category
|
||||
*
|
||||
* @param Category $category
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function categoryOverviewChart(Category $category, GChart $chart, CategoryRepositoryInterface $repository)
|
||||
public function categoryOverviewChart(GChart $chart, CategoryRepositoryInterface $repository, Category $category)
|
||||
{
|
||||
// oldest transaction in category:
|
||||
$start = $repository->getFirstActivityDate($category);
|
||||
@@ -424,12 +445,13 @@ class GoogleChartController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param GChart $chart
|
||||
* @param CategoryRepositoryInterface $repository
|
||||
* @param Category $category
|
||||
*
|
||||
* @param Category $category
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function categoryPeriodChart(Category $category, GChart $chart, CategoryRepositoryInterface $repository)
|
||||
public function categoryPeriodChart(GChart $chart, CategoryRepositoryInterface $repository, Category $category)
|
||||
{
|
||||
$start = clone Session::get('start', Carbon::now()->startOfMonth());
|
||||
$chart->addColumn('Period', 'date');
|
||||
@@ -451,11 +473,13 @@ class GoogleChartController extends Controller
|
||||
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param GChart $chart
|
||||
* @param PiggyBankRepositoryInterface $repository
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function piggyBankHistory(PiggyBank $piggyBank, GChart $chart, PiggyBankRepositoryInterface $repository)
|
||||
public function piggyBankHistory(GChart $chart, PiggyBankRepositoryInterface $repository, PiggyBank $piggyBank)
|
||||
{
|
||||
$chart->addColumn('Date', 'date');
|
||||
$chart->addColumn('Balance', 'number');
|
||||
@@ -476,12 +500,13 @@ class GoogleChartController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param GChart $chart
|
||||
* @param ReportQueryInterface $query
|
||||
* @param $year
|
||||
*
|
||||
* @param $year
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function yearInExp($year, GChart $chart, ReportQueryInterface $query)
|
||||
public function yearInExp(GChart $chart, ReportQueryInterface $query, $year)
|
||||
{
|
||||
$start = new Carbon('01-01-' . $year);
|
||||
$chart->addColumn('Month', 'date');
|
||||
@@ -514,12 +539,13 @@ class GoogleChartController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param GChart $chart
|
||||
* @param ReportQueryInterface $query
|
||||
* @param $year
|
||||
*
|
||||
* @param $year
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function yearInExpSum($year, GChart $chart, ReportQueryInterface $query)
|
||||
public function yearInExpSum(GChart $chart, ReportQueryInterface $query, $year)
|
||||
{
|
||||
$start = new Carbon('01-01-' . $year);
|
||||
$chart->addColumn('Summary', 'string');
|
||||
|
@@ -1,12 +1,8 @@
|
||||
<?php namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use Cache;
|
||||
use ErrorException;
|
||||
use FireflyIII\Helpers\Help\HelpInterface;
|
||||
use League\CommonMark\CommonMarkConverter;
|
||||
use Log;
|
||||
use Response;
|
||||
use Route;
|
||||
|
||||
/**
|
||||
* Class HelpController
|
||||
@@ -17,11 +13,12 @@ class HelpController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* @param $route
|
||||
* @param HelpInterface $help
|
||||
* @param $route
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function show($route, HelpInterface $help)
|
||||
public function show(HelpInterface $help, $route)
|
||||
{
|
||||
$content = [
|
||||
'text' => '<p>There is no help for this route!</p>',
|
||||
|
@@ -86,7 +86,7 @@ class HomeController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
return view('index', compact('count', 'title', 'savings', 'subTitle', 'mainTitleIcon', 'transactions', 'savingsTotal','piggyBankAccounts'));
|
||||
return view('index', compact('count', 'title', 'savings', 'subTitle', 'mainTitleIcon', 'transactions', 'savingsTotal', 'piggyBankAccounts'));
|
||||
}
|
||||
|
||||
|
||||
|
@@ -1,17 +1,16 @@
|
||||
<?php namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use Amount;
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Report\ReportQueryInterface;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Models\Preference;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Preferences;
|
||||
use Response;
|
||||
@@ -28,7 +27,9 @@ class JsonController extends Controller
|
||||
|
||||
|
||||
/**
|
||||
* @param BillRepositoryInterface $repository
|
||||
* @param BillRepositoryInterface $repository
|
||||
*
|
||||
* @param AccountRepositoryInterface $accountRepository
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
@@ -149,6 +150,8 @@ class JsonController extends Controller
|
||||
/**
|
||||
* Returns a list of categories.
|
||||
*
|
||||
* @param CategoryRepositoryInterface $repository
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function categories(CategoryRepositoryInterface $repository)
|
||||
@@ -166,6 +169,8 @@ class JsonController extends Controller
|
||||
/**
|
||||
* Returns a JSON list of all beneficiaries.
|
||||
*
|
||||
* @param AccountRepositoryInterface $accountRepository
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function expenseAccounts(AccountRepositoryInterface $accountRepository)
|
||||
@@ -181,6 +186,8 @@ class JsonController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AccountRepositoryInterface $accountRepository
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function revenueAccounts(AccountRepositoryInterface $accountRepository)
|
||||
@@ -200,6 +207,7 @@ class JsonController extends Controller
|
||||
*/
|
||||
public function setSharedReports()
|
||||
{
|
||||
/** @var Preference $pref */
|
||||
$pref = Preferences::get('showSharedReports', false);
|
||||
$new = !$pref->data;
|
||||
Preferences::set('showSharedReports', $new);
|
||||
@@ -219,11 +227,31 @@ class JsonController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $what
|
||||
* Returns a JSON list of all beneficiaries.
|
||||
*
|
||||
* @param TagRepositoryInterface $tagRepository
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function tags(TagRepositoryInterface $tagRepository)
|
||||
{
|
||||
$list = $tagRepository->get();
|
||||
$return = [];
|
||||
foreach ($list as $entry) {
|
||||
$return[] = $entry->tag;
|
||||
}
|
||||
|
||||
return Response::json($return);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param JournalRepositoryInterface $repository
|
||||
* @param $what
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function transactionJournals($what, JournalRepositoryInterface $repository)
|
||||
public function transactionJournals(JournalRepositoryInterface $repository, $what)
|
||||
{
|
||||
$descriptions = [];
|
||||
$dbType = $repository->getTransactionType($what);
|
||||
|
@@ -6,9 +6,7 @@ use Config;
|
||||
use ExpandedForm;
|
||||
use FireflyIII\Http\Requests;
|
||||
use FireflyIII\Http\Requests\PiggyBankFormRequest;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\PiggyBank;
|
||||
use FireflyIII\Models\PiggyBankEvent;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
@@ -32,6 +30,7 @@ class PiggyBankController extends Controller
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
View::share('title', 'Piggy banks');
|
||||
View::share('mainTitleIcon', 'fa-sort-amount-asc');
|
||||
}
|
||||
@@ -39,11 +38,12 @@ class PiggyBankController extends Controller
|
||||
/**
|
||||
* Add money to piggy bank
|
||||
*
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param AccountRepositoryInterface $repository
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function add(PiggyBank $piggyBank, AccountRepositoryInterface $repository)
|
||||
public function add(AccountRepositoryInterface $repository, PiggyBank $piggyBank)
|
||||
{
|
||||
$leftOnAccount = $repository->leftOnAccount($piggyBank->account);
|
||||
$savedSoFar = $piggyBank->currentRelevantRep()->currentamount;
|
||||
@@ -54,15 +54,15 @@ class PiggyBankController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AccountRepositoryInterface $repository
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function create(AccountRepositoryInterface $repository)
|
||||
{
|
||||
|
||||
$periods = Config::get('firefly.piggy_bank_periods');
|
||||
$accounts = ExpandedForm::makeSelectList($repository->getAccounts(['Default account', 'Asset account']));
|
||||
//Auth::user()->accounts()->orderBy('accounts.name', 'ASC')->accountTypeIn(['Default account', 'Asset account'])->get(['accounts.*'])
|
||||
// );
|
||||
$periods = Config::get('firefly.piggy_bank_periods');
|
||||
$accounts = ExpandedForm::makeSelectList($repository->getAccounts(['Default account', 'Asset account']));
|
||||
$subTitle = 'Create new piggy bank';
|
||||
$subTitleIcon = 'fa-plus';
|
||||
|
||||
@@ -91,11 +91,12 @@ class PiggyBankController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param PiggyBankRepositoryInterface $repository
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(PiggyBank $piggyBank, PiggyBankRepositoryInterface $repository)
|
||||
public function destroy(PiggyBankRepositoryInterface $repository, PiggyBank $piggyBank)
|
||||
{
|
||||
|
||||
|
||||
@@ -106,13 +107,12 @@ class PiggyBankController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
|
||||
* @param AccountRepositoryInterface $repository
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return $this
|
||||
* @return View
|
||||
*/
|
||||
public function edit(PiggyBank $piggyBank, AccountRepositoryInterface $repository)
|
||||
public function edit(AccountRepositoryInterface $repository, PiggyBank $piggyBank)
|
||||
{
|
||||
|
||||
$periods = Config::get('firefly.piggy_bank_periods');
|
||||
@@ -148,7 +148,10 @@ class PiggyBankController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
* @param AccountRepositoryInterface $repository
|
||||
* @param PiggyBankRepositoryInterface $piggyRepository
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
public function index(AccountRepositoryInterface $repository, PiggyBankRepositoryInterface $piggyRepository)
|
||||
{
|
||||
@@ -186,7 +189,7 @@ class PiggyBankController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow user to order piggy banks.
|
||||
* @param PiggyBankRepositoryInterface $repository
|
||||
*/
|
||||
public function order(PiggyBankRepositoryInterface $repository)
|
||||
{
|
||||
@@ -203,13 +206,13 @@ class PiggyBankController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* POST add money to piggy bank
|
||||
*
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param PiggyBankRepositoryInterface $repository
|
||||
* @param AccountRepositoryInterface $accounts
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function postAdd(PiggyBank $piggyBank, PiggyBankRepositoryInterface $repository, AccountRepositoryInterface $accounts)
|
||||
public function postAdd(PiggyBankRepositoryInterface $repository, AccountRepositoryInterface $accounts, PiggyBank $piggyBank)
|
||||
{
|
||||
$amount = round(floatval(Input::get('amount')), 2);
|
||||
$leftOnAccount = $accounts->leftOnAccount($piggyBank->account);
|
||||
@@ -239,11 +242,12 @@ class PiggyBankController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param PiggyBankRepositoryInterface $repository
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function postRemove(PiggyBank $piggyBank, PiggyBankRepositoryInterface $repository)
|
||||
public function postRemove(PiggyBankRepositoryInterface $repository, PiggyBank $piggyBank)
|
||||
{
|
||||
$amount = floatval(Input::get('amount'));
|
||||
|
||||
@@ -268,7 +272,6 @@ class PiggyBankController extends Controller
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @SuppressWarnings("Unused")
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
@@ -278,11 +281,12 @@ class PiggyBankController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param PiggyBankRepositoryInterface $repository
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return $this
|
||||
* @return View
|
||||
*/
|
||||
public function show(PiggyBank $piggyBank, PiggyBankRepositoryInterface $repository)
|
||||
public function show(PiggyBankRepositoryInterface $repository, PiggyBank $piggyBank)
|
||||
{
|
||||
$events = $repository->getEvents($piggyBank);
|
||||
|
||||
@@ -331,13 +335,13 @@ class PiggyBankController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
|
||||
* @param PiggyBankRepositoryInterface $repository
|
||||
* @param PiggyBankFormRequest $request
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function update(PiggyBank $piggyBank, PiggyBankRepositoryInterface $repository, PiggyBankFormRequest $request)
|
||||
public function update(PiggyBankRepositoryInterface $repository, PiggyBankFormRequest $request, PiggyBank $piggyBank)
|
||||
{
|
||||
$piggyBankData = [
|
||||
'name' => $request->get('name'),
|
||||
|
@@ -20,26 +20,26 @@ class PreferencesController extends Controller
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
parent::__construct();
|
||||
View::share('title', 'Preferences');
|
||||
View::share('mainTitleIcon', 'fa-gear');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AccountRepositoryInterface $repository
|
||||
*
|
||||
* @return $this|\Illuminate\View\View
|
||||
*/
|
||||
public function index(AccountRepositoryInterface $repository)
|
||||
{
|
||||
$accounts = $repository->getAccounts(['Default account', 'Asset account']);
|
||||
$viewRange = Preferences::get('viewRange', '1M');
|
||||
$viewRangeValue = $viewRange->data;
|
||||
$frontPage = Preferences::get('frontPageAccounts', []);
|
||||
$budgetMax = Preferences::get('budgetMaximum', 1000);
|
||||
$budgetMaximum = $budgetMax->data;
|
||||
$accounts = $repository->getAccounts(['Default account', 'Asset account']);
|
||||
$viewRangePref = Preferences::get('viewRange', '1M');
|
||||
$viewRange = $viewRangePref->data;
|
||||
$frontPageAccounts = Preferences::get('frontPageAccounts', []);
|
||||
$budgetMax = Preferences::get('budgetMaximum', 1000);
|
||||
$budgetMaximum = $budgetMax->data;
|
||||
|
||||
return view('preferences.index', compact('budgetMaximum'))->with('accounts', $accounts)->with('frontPageAccounts', $frontPage)->with(
|
||||
'viewRange', $viewRangeValue
|
||||
);
|
||||
return view('preferences.index', compact('budgetMaximum', 'accounts', 'frontPageAccounts', 'viewRange'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -26,16 +26,6 @@ class ProfileController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\View\View
|
||||
*
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('profile.index')->with('title', 'Profile')->with('subTitle', Auth::user()->email)->with('mainTitleIcon', 'fa-user');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
@@ -47,25 +37,17 @@ class ProfileController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\View\View
|
||||
*
|
||||
*/
|
||||
public function postDeleteAccount(DeleteAccountFormRequest $request) {
|
||||
// old, new1, new2
|
||||
if (!Hash::check($request->get('password'), Auth::user()->password)) {
|
||||
Session::flash('error', 'Invalid password!');
|
||||
|
||||
return Redirect::route('delete-account');
|
||||
}
|
||||
|
||||
// DELETE!
|
||||
Auth::user()->delete();
|
||||
Session::flush();
|
||||
return Redirect::route('index');
|
||||
public function index()
|
||||
{
|
||||
return view('profile.index')->with('title', 'Profile')->with('subTitle', Auth::user()->email)->with('mainTitleIcon', 'fa-user');
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param ProfileFormRequest $request
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View
|
||||
*/
|
||||
public function postChangePassword(ProfileFormRequest $request)
|
||||
@@ -76,7 +58,7 @@ class ProfileController extends Controller
|
||||
|
||||
return Redirect::route('change-password');
|
||||
}
|
||||
$result = $this->validatePassword($request->get('current_password'), $request->get('new_password'), $request->get('new_password_confirmation'));
|
||||
$result = $this->validatePassword($request->get('current_password'), $request->get('new_password'));
|
||||
if (!($result === true)) {
|
||||
Session::flash('error', $result);
|
||||
|
||||
@@ -93,29 +75,43 @@ class ProfileController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
|
||||
*
|
||||
* @param string $old
|
||||
* @param string $new1
|
||||
* @param string $new2
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
protected function validatePassword($old, $new1, $new2)
|
||||
protected function validatePassword($old, $new1)
|
||||
{
|
||||
if (strlen($new1) == 0 || strlen($new2) == 0) {
|
||||
return 'Do fill in a password!';
|
||||
|
||||
}
|
||||
if ($new1 == $old) {
|
||||
return 'The idea is to change your password.';
|
||||
}
|
||||
|
||||
if ($new1 !== $new2) {
|
||||
return 'New passwords do not match!';
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DeleteAccountFormRequest $request
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function postDeleteAccount(DeleteAccountFormRequest $request)
|
||||
{
|
||||
// old, new1, new2
|
||||
if (!Hash::check($request->get('password'), Auth::user()->password)) {
|
||||
Session::flash('error', 'Invalid password!');
|
||||
|
||||
return Redirect::route('delete-account');
|
||||
}
|
||||
|
||||
// DELETE!
|
||||
Auth::user()->delete();
|
||||
Session::flush();
|
||||
|
||||
return Redirect::route('index');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -1,164 +0,0 @@
|
||||
<?php namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use Auth;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionGroup;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Input;
|
||||
use Redirect;
|
||||
use Response;
|
||||
use URL;
|
||||
|
||||
/**
|
||||
* Class RelatedController
|
||||
*
|
||||
* @package FireflyIII\Http\Controllers
|
||||
*/
|
||||
class RelatedController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function alreadyRelated(TransactionJournal $journal)
|
||||
{
|
||||
$ids = [];
|
||||
/** @var TransactionGroup $group */
|
||||
foreach ($journal->transactiongroups()->get() as $group) {
|
||||
/** @var TransactionJournal $loopJournal */
|
||||
foreach ($group->transactionjournals()->get() as $loopJournal) {
|
||||
if ($loopJournal->id != $journal->id) {
|
||||
$ids[] = $loopJournal->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
$unique = array_unique($ids);
|
||||
$journals = new Collection;
|
||||
if (count($unique) > 0) {
|
||||
$journals = Auth::user()->transactionjournals()->whereIn('id', $unique)->get();
|
||||
}
|
||||
$parent = $journal;
|
||||
|
||||
return view('related.alreadyRelated', compact('parent', 'journals'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
|
||||
*
|
||||
* @param TransactionJournal $parentJournal
|
||||
* @param TransactionJournal $childJournal
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getRemoveRelation(TransactionJournal $parentJournal, TransactionJournal $childJournal)
|
||||
{
|
||||
$groups = $parentJournal->transactiongroups()->get();
|
||||
/** @var TransactionGroup $group */
|
||||
foreach ($groups as $group) {
|
||||
foreach ($group->transactionjournals()->get() as $loopJournal) {
|
||||
if ($loopJournal->id == $childJournal->id) {
|
||||
// remove from group:
|
||||
$group->transactionjournals()->detach($childJournal);
|
||||
}
|
||||
}
|
||||
if ($group->transactionjournals()->count() == 1) {
|
||||
$group->delete();
|
||||
}
|
||||
}
|
||||
|
||||
return Redirect::to(URL::previous());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $parentJournal
|
||||
* @param TransactionJournal $childJournal
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function relate(TransactionJournal $parentJournal, TransactionJournal $childJournal)
|
||||
{
|
||||
$group = new TransactionGroup;
|
||||
$group->relation = 'balance';
|
||||
$group->user_id = Auth::user()->id;
|
||||
$group->save();
|
||||
$group->transactionjournals()->save($parentJournal);
|
||||
$group->transactionjournals()->save($childJournal);
|
||||
|
||||
return Response::json(true);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function related(TransactionJournal $journal)
|
||||
{
|
||||
$groups = $journal->transactiongroups()->get();
|
||||
$members = new Collection;
|
||||
/** @var TransactionGroup $group */
|
||||
foreach ($groups as $group) {
|
||||
/** @var TransactionJournal $loopJournal */
|
||||
foreach ($group->transactionjournals()->get() as $loopJournal) {
|
||||
if ($loopJournal->id != $journal->id) {
|
||||
$members->push($loopJournal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return view('related.relate', compact('journal', 'members'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
|
||||
*
|
||||
* @param TransactionJournal $parentJournal
|
||||
* @param TransactionJournal $childJournal
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @throws Exception
|
||||
*/
|
||||
public function removeRelation(TransactionJournal $parentJournal, TransactionJournal $childJournal)
|
||||
{
|
||||
$groups = $parentJournal->transactiongroups()->get();
|
||||
/** @var TransactionGroup $group */
|
||||
foreach ($groups as $group) {
|
||||
foreach ($group->transactionjournals()->get() as $loopJournal) {
|
||||
if ($loopJournal->id == $childJournal->id) {
|
||||
// remove from group:
|
||||
$group->transactionjournals()->detach($childJournal);
|
||||
}
|
||||
}
|
||||
if ($group->transactionjournals()->count() == 1) {
|
||||
$group->delete();
|
||||
}
|
||||
}
|
||||
|
||||
return Response::json(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function search(TransactionJournal $journal, JournalRepositoryInterface $repository)
|
||||
{
|
||||
|
||||
$search = e(trim(Input::get('searchValue')));
|
||||
$parent = $journal;
|
||||
|
||||
$journals = $repository->searchRelated($search, $journal);
|
||||
|
||||
return view('related.searchResult', compact('journals', 'search', 'parent'));
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -1,9 +1,7 @@
|
||||
<?php namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Reminders\ReminderHelperInterface;
|
||||
use FireflyIII\Models\Reminder;
|
||||
use FireflyIII\Repositories\Reminder\ReminderRepositoryInterface;
|
||||
use Redirect;
|
||||
use Session;
|
||||
use URL;
|
||||
@@ -19,6 +17,8 @@ class ReminderController extends Controller
|
||||
|
||||
/**
|
||||
* @param Reminder $reminder
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function act(Reminder $reminder)
|
||||
{
|
||||
@@ -36,6 +36,8 @@ class ReminderController extends Controller
|
||||
|
||||
/**
|
||||
* @param Reminder $reminder
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function dismiss(Reminder $reminder)
|
||||
{
|
||||
@@ -48,55 +50,18 @@ class ReminderController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ReminderRepositoryInterface $repository
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function index(ReminderHelperInterface $helper)
|
||||
public function index(ReminderRepositoryInterface $repository)
|
||||
{
|
||||
|
||||
$reminders = Auth::user()->reminders()->get();
|
||||
|
||||
$reminders->each(
|
||||
function (Reminder $reminder) use ($helper) {
|
||||
$reminder->description = $helper->getReminderText($reminder);
|
||||
}
|
||||
);
|
||||
|
||||
$today = new Carbon;
|
||||
// active reminders:
|
||||
$active = $reminders->filter(
|
||||
function (Reminder $reminder) use ($today) {
|
||||
if ($reminder->notnow === false && $reminder->active === true && $reminder->startdate <= $today && $reminder->enddate >= $today) {
|
||||
return $reminder;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// expired reminders:
|
||||
$expired = $reminders->filter(
|
||||
function (Reminder $reminder) use ($today) {
|
||||
if ($reminder->notnow === false && $reminder->active === true && $reminder->startdate > $today || $reminder->enddate < $today) {
|
||||
return $reminder;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// inactive reminders
|
||||
$inactive = $reminders->filter(
|
||||
function (Reminder $reminder) {
|
||||
if ($reminder->active === false) {
|
||||
return $reminder;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// dismissed reminders
|
||||
$dismissed = $reminders->filter(
|
||||
function (Reminder $reminder) {
|
||||
if ($reminder->notnow === true) {
|
||||
return $reminder;
|
||||
}
|
||||
}
|
||||
);
|
||||
$active = $repository->getActiveReminders();
|
||||
$expired = $repository->getExpiredReminders();
|
||||
$inactive = $repository->getInactiveReminders();
|
||||
$dismissed = $repository->getDismissedReminders();
|
||||
|
||||
$title = 'Reminders';
|
||||
$mainTitleIcon = 'fa-clock-o';
|
||||
@@ -106,6 +71,8 @@ class ReminderController extends Controller
|
||||
|
||||
/**
|
||||
* @param Reminder $reminder
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function show(Reminder $reminder)
|
||||
{
|
||||
|
@@ -1,7 +1,6 @@
|
||||
<?php namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use FireflyIII\Helpers\Report\ReportHelperInterface;
|
||||
use FireflyIII\Helpers\Report\ReportQueryInterface;
|
||||
use FireflyIII\Models\Account;
|
||||
@@ -47,50 +46,52 @@ class ReportController extends Controller
|
||||
*/
|
||||
public function budget($year = '2014', $month = '1')
|
||||
{
|
||||
try {
|
||||
new Carbon($year . '-' . $month . '-01');
|
||||
} catch (Exception $e) {
|
||||
return view('error')->with('message', 'Invalid date');
|
||||
}
|
||||
$date = new Carbon($year . '-' . $month . '-01');
|
||||
$start = clone $date;
|
||||
$date = new Carbon($year . '-' . $month . '-01');
|
||||
$subTitle = 'Budget report for ' . $date->format('F Y');
|
||||
$subTitleIcon = 'fa-calendar';
|
||||
$start = clone $date;
|
||||
|
||||
|
||||
$start->startOfMonth();
|
||||
$end = clone $date;
|
||||
$end->endOfMonth();
|
||||
$start->subDay();
|
||||
|
||||
// should show shared reports?
|
||||
/** @var Preference $pref */
|
||||
$pref = Preferences::get('showSharedReports', false);
|
||||
$showSharedReports = $pref->data;
|
||||
$accountAmounts = []; // array with sums of spent amounts on each account.
|
||||
$accounts = $this->query->getAllAccounts($start, $end, $showSharedReports); // all accounts and some data.
|
||||
|
||||
foreach ($accounts as $account) {
|
||||
|
||||
$dayEarly = clone $date;
|
||||
$subTitle = 'Budget report for ' . $date->format('F Y');
|
||||
$subTitleIcon = 'fa-calendar';
|
||||
$dayEarly = $dayEarly->subDay();
|
||||
$accounts = $this->query->getAllAccounts($start, $end, $showSharedReports);
|
||||
$start->addDay();
|
||||
$budgets = $this->query->getBudgetSummary($account, $start, $end);// get budget summary for this account:
|
||||
$balancedAmount = $this->query->balancedTransactionsSum($account, $start, $end);
|
||||
$accountAmounts[$account->id] = $balancedAmount;
|
||||
// balance out the transactions (see transaction groups & tags) ^^
|
||||
|
||||
$accounts->each(
|
||||
function (Account $account) use ($start, $end) {
|
||||
$budgets = $this->query->getBudgetSummary($account, $start, $end);
|
||||
$balancedAmount = $this->query->balancedTransactionsSum($account, $start, $end);
|
||||
$array = [];
|
||||
$hide = true;
|
||||
foreach ($budgets as $budget) {
|
||||
$id = intval($budget->id);
|
||||
$data = $budget->toArray();
|
||||
$array[$id] = $data;
|
||||
if (floatval($data['queryAmount']) != 0) {
|
||||
$hide = false;
|
||||
}
|
||||
// array with budget information for each account:
|
||||
$array = [];
|
||||
// should always hide account
|
||||
$hide = true;
|
||||
// loop all budgets
|
||||
/** @var \FireflyIII\Models\Budget $budget */
|
||||
foreach ($budgets as $budget) {
|
||||
$id = intval($budget->id);
|
||||
$data = $budget->toArray();
|
||||
$array[$id] = $data;
|
||||
|
||||
// no longer hide account if any budget has money in it.
|
||||
if (floatval($data['queryAmount']) != 0) {
|
||||
$hide = false;
|
||||
}
|
||||
$account->hide = $hide;
|
||||
$account->budgetInformation = $array;
|
||||
$account->balancedAmount = $balancedAmount;
|
||||
|
||||
$accountAmounts[$account->id] += $data['queryAmount'];
|
||||
}
|
||||
);
|
||||
$account->hide = $hide;
|
||||
$account->budgetInformation = $array;
|
||||
$account->balancedAmount = $balancedAmount;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Start getBudgetsForMonth DONE
|
||||
@@ -101,14 +102,14 @@ class ReportController extends Controller
|
||||
* End getBudgetsForMonth DONE
|
||||
*/
|
||||
|
||||
return view('reports.budget', compact('subTitle', 'year', 'month', 'subTitleIcon', 'date', 'accounts', 'budgets', 'dayEarly'));
|
||||
return view('reports.budget', compact('subTitle', 'accountAmounts', 'year', 'month', 'subTitleIcon', 'date', 'accounts', 'budgets'));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ReportHelperInterface $helper
|
||||
*
|
||||
* @return View
|
||||
* @internal param ReportHelperInterface $helper
|
||||
*
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
@@ -131,11 +132,6 @@ class ReportController extends Controller
|
||||
public function modalBalancedTransfers(Account $account, $year = '2014', $month = '1')
|
||||
{
|
||||
|
||||
try {
|
||||
new Carbon($year . '-' . $month . '-01');
|
||||
} catch (Exception $e) {
|
||||
return view('error')->with('message', 'Invalid date');
|
||||
}
|
||||
$start = new Carbon($year . '-' . $month . '-01');
|
||||
$end = clone $start;
|
||||
$end->endOfMonth();
|
||||
@@ -148,20 +144,16 @@ class ReportController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param string $year
|
||||
* @param string $month
|
||||
* @param ReportQueryInterface $query
|
||||
* @param Account $account
|
||||
* @param string $year
|
||||
* @param string $month
|
||||
*
|
||||
* @return View
|
||||
* @internal param ReportQueryInterface $query
|
||||
*
|
||||
*/
|
||||
public function modalLeftUnbalanced(Account $account, $year = '2014', $month = '1')
|
||||
{
|
||||
try {
|
||||
new Carbon($year . '-' . $month . '-01');
|
||||
} catch (Exception $e) {
|
||||
return view('error')->with('message', 'Invalid date');
|
||||
}
|
||||
$start = new Carbon($year . '-' . $month . '-01');
|
||||
$end = clone $start;
|
||||
$end->endOfMonth();
|
||||
@@ -173,6 +165,8 @@ class ReportController extends Controller
|
||||
if ($count == 0) {
|
||||
return $journal;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
);
|
||||
|
||||
@@ -188,11 +182,6 @@ class ReportController extends Controller
|
||||
*/
|
||||
public function modalNoBudget(Account $account, $year = '2014', $month = '1')
|
||||
{
|
||||
try {
|
||||
new Carbon($year . '-' . $month . '-01');
|
||||
} catch (Exception $e) {
|
||||
return view('error')->with('message', 'Invalid date');
|
||||
}
|
||||
$start = new Carbon($year . '-' . $month . '-01');
|
||||
$end = clone $start;
|
||||
$end->endOfMonth();
|
||||
@@ -210,11 +199,6 @@ class ReportController extends Controller
|
||||
*/
|
||||
public function month($year = '2014', $month = '1')
|
||||
{
|
||||
try {
|
||||
new Carbon($year . '-' . $month . '-01');
|
||||
} catch (Exception $e) {
|
||||
return view('error')->with('message', 'Invalid date.');
|
||||
}
|
||||
$date = new Carbon($year . '-' . $month . '-01');
|
||||
$subTitle = 'Report for ' . $date->format('F Y');
|
||||
$subTitleIcon = 'fa-calendar';
|
||||
@@ -326,11 +310,6 @@ class ReportController extends Controller
|
||||
*/
|
||||
public function year($year)
|
||||
{
|
||||
try {
|
||||
new Carbon('01-01-' . $year);
|
||||
} catch (Exception $e) {
|
||||
return view('error')->with('message', 'Invalid date.');
|
||||
}
|
||||
/** @var Preference $pref */
|
||||
$pref = Preferences::get('showSharedReports', false);
|
||||
$showSharedReports = $pref->data;
|
||||
|
@@ -12,6 +12,10 @@ class SearchController extends Controller
|
||||
{
|
||||
/**
|
||||
* Results always come in the form of an array [results, count, fullCount]
|
||||
*
|
||||
* @param SearchInterface $searcher
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function index(SearchInterface $searcher)
|
||||
{
|
||||
|
325
app/Http/Controllers/TagController.php
Normal file
325
app/Http/Controllers/TagController.php
Normal file
@@ -0,0 +1,325 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Http\Requests\TagFormRequest;
|
||||
use FireflyIII\Models\Preference;
|
||||
use FireflyIII\Models\Tag;
|
||||
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
||||
use Input;
|
||||
use Preferences;
|
||||
use Redirect;
|
||||
use Response;
|
||||
use Session;
|
||||
use URL;
|
||||
use View;
|
||||
|
||||
/**
|
||||
* Class TagController
|
||||
*
|
||||
* Remember: a balancingAct takes at most one expense and one transfer.
|
||||
* an advancePayment takes at most one expense, infinite deposits and NO transfers.
|
||||
*
|
||||
* transaction can only have one advancePayment OR balancingAct.
|
||||
* Other attempts to put in such a tag are blocked.
|
||||
* also show an error when editing a tag and it becomes either
|
||||
* of these two types. Or rather, block editing of the tag.
|
||||
*
|
||||
* @package FireflyIII\Http\Controllers
|
||||
*/
|
||||
class TagController extends Controller
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
View::share('title', 'Tags');
|
||||
View::share('mainTitleIcon', 'fa-tags');
|
||||
View::share('hideTags', true);
|
||||
$tagOptions = [
|
||||
'nothing' => 'Just a regular tag.',
|
||||
'balancingAct' => 'The tag takes at most two transactions; an expense and a transfer. They\'ll balance each other out.',
|
||||
'advancePayment' => 'The tag accepts one expense and any number of deposits aimed to repay the original expense.',
|
||||
];
|
||||
View::share('tagOptions', $tagOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$subTitle = 'New tag';
|
||||
$subTitleIcon = 'fa-tag';
|
||||
|
||||
$preFilled = [
|
||||
'tagMode' => 'nothing'
|
||||
];
|
||||
if (!Input::old('tagMode')) {
|
||||
Session::flash('preFilled', $preFilled);
|
||||
}
|
||||
// put previous url in session if not redirect from store (not "create another").
|
||||
if (Session::get('tags.create.fromStore') !== true) {
|
||||
Session::put('tags.create.url', URL::previous());
|
||||
}
|
||||
Session::forget('tags.create.fromStore');
|
||||
|
||||
return view('tags.create', compact('subTitle', 'subTitleIcon'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function delete(Tag $tag)
|
||||
{
|
||||
$subTitle = 'Delete "' . e($tag->tag) . '"';
|
||||
|
||||
// put previous url in session
|
||||
Session::put('tags.delete.url', URL::previous());
|
||||
|
||||
return view('tags.delete', compact('tag', 'subTitle'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TagRepositoryInterface $repository
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(TagRepositoryInterface $repository, Tag $tag)
|
||||
{
|
||||
|
||||
$tagName = $tag->tag;
|
||||
$repository->destroy($tag);
|
||||
|
||||
Session::flash('success', 'Tag "' . e($tagName) . '" was deleted.');
|
||||
|
||||
return Redirect::to(route('tags.index'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
public function edit(Tag $tag)
|
||||
{
|
||||
$subTitle = 'Edit tag "' . e($tag->tag) . '"';
|
||||
$subTitleIcon = 'fa-tag';
|
||||
|
||||
/*
|
||||
* Default tag options (again)
|
||||
*/
|
||||
$tagOptions = [
|
||||
'nothing' => 'Just a regular tag.',
|
||||
'balancingAct' => 'The tag takes at most two transactions; an expense and a transfer. They\'ll balance each other out.',
|
||||
'advancePayment' => 'The tag accepts one expense and any number of deposits aimed to repay the original expense.',
|
||||
];
|
||||
|
||||
/*
|
||||
* Can this tag become another type?
|
||||
*/
|
||||
$allowToAdvancePayment = true;
|
||||
$allowToBalancingAct = true;
|
||||
|
||||
/*
|
||||
* If this tag is a balancing act, and it contains transfers, it cannot be
|
||||
* changes to an advancePayment.
|
||||
*/
|
||||
|
||||
if ($tag->tagMode == 'balancingAct') {
|
||||
foreach ($tag->transactionjournals as $journal) {
|
||||
if ($journal->transactionType->type == 'Transfer') {
|
||||
$allowToAdvancePayment = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If this tag contains more than one expenses, it cannot become an advance payment.
|
||||
*/
|
||||
$count = 0;
|
||||
foreach ($tag->transactionjournals as $journal) {
|
||||
if ($journal->transactionType->type == 'Withdrawal') {
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
if ($count > 1) {
|
||||
$allowToAdvancePayment = false;
|
||||
}
|
||||
|
||||
/*
|
||||
* If has more than two transactions already, cannot become a balancing act:
|
||||
*/
|
||||
if ($tag->transactionjournals->count() > 2) {
|
||||
$allowToBalancingAct = false;
|
||||
}
|
||||
|
||||
/*
|
||||
* If any transaction is a deposit, cannot become a balancing act.
|
||||
*/
|
||||
$count = 0;
|
||||
foreach ($tag->transactionjournals as $journal) {
|
||||
if ($journal->transactionType->type == 'Deposit') {
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
if ($count > 0) {
|
||||
$allowToBalancingAct = false;
|
||||
}
|
||||
|
||||
|
||||
// edit tag options:
|
||||
if ($allowToAdvancePayment === false) {
|
||||
unset($tagOptions['advancePayment']);
|
||||
}
|
||||
if ($allowToBalancingAct === false) {
|
||||
unset($tagOptions['balancingAct']);
|
||||
}
|
||||
|
||||
|
||||
// put previous url in session if not redirect from store (not "return_to_edit").
|
||||
if (Session::get('tags.edit.fromUpdate') !== true) {
|
||||
Session::put('tags.edit.url', URL::previous());
|
||||
}
|
||||
Session::forget('tags.edit.fromUpdate');
|
||||
|
||||
return view('tags.edit', compact('tag', 'subTitle', 'subTitleIcon', 'tagOptions'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $state
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function hideTagHelp($state)
|
||||
{
|
||||
|
||||
$state = $state == 'true' ? true : false;
|
||||
Preferences::set('hideTagHelp', $state);
|
||||
|
||||
return Response::json(true);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
/** @var Preference $helpHiddenPref */
|
||||
$helpHiddenPref = Preferences::get('hideTagHelp', false);
|
||||
$title = 'Tags';
|
||||
$mainTitleIcon = 'fa-tags';
|
||||
$helpHidden = $helpHiddenPref->data;
|
||||
$tags = Auth::user()->tags()->get();
|
||||
|
||||
return view('tags.index', compact('title', 'mainTitleIcon', 'helpHidden', 'tags'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function show(Tag $tag)
|
||||
{
|
||||
$subTitle = $tag->tag;
|
||||
$subTitleIcon = 'fa-tag';
|
||||
|
||||
return view('tags.show', compact('tag', 'subTitle', 'subTitleIcon'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TagFormRequest $request
|
||||
*
|
||||
* @param TagRepositoryInterface $repository
|
||||
*
|
||||
* @return $this|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(TagFormRequest $request, TagRepositoryInterface $repository)
|
||||
{
|
||||
if (Input::get('setTag') == 'true') {
|
||||
$latitude = strlen($request->get('latitude')) > 0 ? $request->get('latitude') : null;
|
||||
$longitude = strlen($request->get('longitude')) > 0 ? $request->get('longitude') : null;
|
||||
$zoomLevel = strlen($request->get('zoomLevel')) > 0 ? $request->get('zoomLevel') : null;
|
||||
} else {
|
||||
$latitude = null;
|
||||
$longitude = null;
|
||||
$zoomLevel = null;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'tag' => $request->get('tag'),
|
||||
'date' => strlen($request->get('date')) > 0 ? new Carbon($request->get('date')) : null,
|
||||
'description' => strlen($request->get('description')) > 0 ? $request->get('description') : '',
|
||||
'latitude' => $latitude,
|
||||
'longitude' => $longitude,
|
||||
'zoomLevel' => $zoomLevel,
|
||||
'tagMode' => $request->get('tagMode'),
|
||||
];
|
||||
$repository->store($data);
|
||||
|
||||
Session::flash('success', 'The tag has been created!');
|
||||
|
||||
if (intval(Input::get('create_another')) === 1) {
|
||||
// set value so create routine will not overwrite URL:
|
||||
Session::put('tags.create.fromStore', true);
|
||||
|
||||
return Redirect::route('tags.create')->withInput();
|
||||
}
|
||||
|
||||
// redirect to previous URL.
|
||||
return Redirect::to(Session::get('tags.create.url'));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TagFormRequest $request
|
||||
* @param TagRepositoryInterface $repository
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return $this|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(TagFormRequest $request, TagRepositoryInterface $repository, Tag $tag)
|
||||
{
|
||||
if (Input::get('setTag') == 'true') {
|
||||
$latitude = strlen($request->get('latitude')) > 0 ? $request->get('latitude') : null;
|
||||
$longitude = strlen($request->get('longitude')) > 0 ? $request->get('longitude') : null;
|
||||
$zoomLevel = strlen($request->get('zoomLevel')) > 0 ? $request->get('zoomLevel') : null;
|
||||
} else {
|
||||
$latitude = null;
|
||||
$longitude = null;
|
||||
$zoomLevel = null;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'tag' => $request->get('tag'),
|
||||
'date' => strlen($request->get('date')) > 0 ? new Carbon($request->get('date')) : null,
|
||||
'description' => strlen($request->get('description')) > 0 ? $request->get('description') : '',
|
||||
'latitude' => $latitude,
|
||||
'longitude' => $longitude,
|
||||
'zoomLevel' => $zoomLevel,
|
||||
'tagMode' => $request->get('tagMode'),
|
||||
];
|
||||
|
||||
$repository->update($tag, $data);
|
||||
|
||||
Session::flash('success', 'Tag "' . e($data['tag']) . '" updated.');
|
||||
|
||||
if (intval(Input::get('return_to_edit')) === 1) {
|
||||
// set value so edit routine will not overwrite URL:
|
||||
Session::put('tags.edit.fromUpdate', true);
|
||||
|
||||
return Redirect::route('tags.edit', $tag->id)->withInput(['return_to_edit' => 1]);
|
||||
}
|
||||
|
||||
// redirect to previous URL.
|
||||
return Redirect::to(Session::get('tags.edit.url'));
|
||||
}
|
||||
}
|
@@ -1,6 +1,7 @@
|
||||
<?php namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use ExpandedForm;
|
||||
use FireflyIII\Events\JournalCreated;
|
||||
use FireflyIII\Events\JournalSaved;
|
||||
@@ -8,8 +9,8 @@ use FireflyIII\Http\Requests;
|
||||
use FireflyIII\Http\Requests\JournalFormRequest;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Input;
|
||||
use Redirect;
|
||||
use Response;
|
||||
@@ -28,24 +29,20 @@ class TransactionController extends Controller
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
View::share('title', 'Transactions');
|
||||
View::share('mainTitleIcon', 'fa-repeat');
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the view helping the user to create a new transaction journal.
|
||||
* @param AccountRepositoryInterface $repository
|
||||
* @param string $what
|
||||
*
|
||||
* @param string $what
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
* @return View
|
||||
*/
|
||||
public function create($what = 'deposit')
|
||||
public function create(AccountRepositoryInterface $repository, $what = 'deposit')
|
||||
{
|
||||
$accounts = ExpandedForm::makeSelectList(
|
||||
Auth::user()->accounts()->accountTypeIn(['Default account', 'Asset account'])->orderBy('accounts.name', 'ASC')->orderBy('name', 'ASC')->where(
|
||||
'active', 1
|
||||
)->orderBy('name', 'DESC')->get(['accounts.*'])
|
||||
);
|
||||
$accounts = ExpandedForm::makeSelectList($repository->getAccounts(['Default account', 'Asset account']));
|
||||
$budgets = ExpandedForm::makeSelectList(Auth::user()->budgets()->get());
|
||||
$budgets[0] = '(no budget)';
|
||||
$piggies = ExpandedForm::makeSelectList(Auth::user()->piggyBanks()->get());
|
||||
@@ -94,15 +91,16 @@ class TransactionController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $transactionJournal
|
||||
* @param JournalRepositoryInterface $repository
|
||||
* @param TransactionJournal $transactionJournal
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(TransactionJournal $transactionJournal)
|
||||
public function destroy(JournalRepositoryInterface $repository, TransactionJournal $transactionJournal)
|
||||
{
|
||||
Session::flash('success', 'Transaction "' . e($transactionJournal->description) . '" destroyed.');
|
||||
|
||||
$transactionJournal->delete();
|
||||
$repository->delete($transactionJournal);
|
||||
|
||||
// redirect to previous URL:
|
||||
return Redirect::to(Session::get('transactions.delete.url'));
|
||||
@@ -111,18 +109,15 @@ class TransactionController extends Controller
|
||||
/**
|
||||
* Shows the view to edit a transaction.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param AccountRepositoryInterface $repository
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function edit(TransactionJournal $journal, JournalRepositoryInterface $repository)
|
||||
public function edit(AccountRepositoryInterface $repository, TransactionJournal $journal)
|
||||
{
|
||||
$what = strtolower($journal->transactiontype->type);
|
||||
$accounts = ExpandedForm::makeSelectList(
|
||||
Auth::user()->accounts()->accountTypeIn(['Default account', 'Asset account'])->orderBy('accounts.name', 'ASC')->where('active', 1)->orderBy(
|
||||
'name', 'DESC'
|
||||
)->get(['accounts.*'])
|
||||
);
|
||||
$accounts = ExpandedForm::makeSelectList($repository->getAccounts(['Default account', 'Asset account']));
|
||||
$budgets = ExpandedForm::makeSelectList(Auth::user()->budgets()->get());
|
||||
$budgets[0] = '(no budget)';
|
||||
$transactions = $journal->transactions()->orderBy('amount', 'DESC')->get();
|
||||
@@ -134,6 +129,12 @@ class TransactionController extends Controller
|
||||
'budget_id' => 0,
|
||||
'piggy_bank_id' => 0
|
||||
];
|
||||
// get tags:
|
||||
$tags = [];
|
||||
foreach ($journal->tags as $tag) {
|
||||
$tags[] = $tag->tag;
|
||||
}
|
||||
$preFilled['tags'] = join(',', $tags);
|
||||
|
||||
$category = $journal->categories()->first();
|
||||
if (!is_null($category)) {
|
||||
@@ -150,12 +151,14 @@ class TransactionController extends Controller
|
||||
}
|
||||
|
||||
$preFilled['amount'] = $journal->amount;
|
||||
$preFilled['account_id'] = $repository->getAssetAccount($journal);
|
||||
$preFilled['account_id'] = $journal->assetAccount->id;
|
||||
$preFilled['expense_account'] = $transactions[0]->account->name;
|
||||
$preFilled['revenue_account'] = $transactions[1]->account->name;
|
||||
$preFilled['account_from_id'] = $transactions[1]->account->id;
|
||||
$preFilled['account_to_id'] = $transactions[0]->account->id;
|
||||
|
||||
Session::flash('preFilled', $preFilled);
|
||||
|
||||
// put previous url in session if not redirect from store (not "return_to_edit").
|
||||
if (Session::get('transactions.edit.fromUpdate') !== true) {
|
||||
Session::put('transactions.edit.url', URL::previous());
|
||||
@@ -167,12 +170,14 @@ class TransactionController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $what
|
||||
* @param JournalRepositoryInterface $repository
|
||||
* @param $what
|
||||
*
|
||||
* @return $this
|
||||
* @return View
|
||||
*/
|
||||
public function index($what)
|
||||
public function index(JournalRepositoryInterface $repository, $what)
|
||||
{
|
||||
$types = [];
|
||||
switch ($what) {
|
||||
case 'expenses':
|
||||
case 'withdrawal':
|
||||
@@ -194,18 +199,10 @@ class TransactionController extends Controller
|
||||
break;
|
||||
}
|
||||
|
||||
$page = intval(\Input::get('page'));
|
||||
$offset = $page > 0 ? ($page - 1) * 50 : 0;
|
||||
$page = intval(Input::get('page'));
|
||||
$offset = $page > 0 ? ($page - 1) * 50 : 0;
|
||||
$journals = $repository->getJournalsOfTypes($types, $offset, $page);
|
||||
|
||||
$set = Auth::user()->transactionJournals()->transactionTypes($types)->withRelevantData()->take(50)->offset($offset)
|
||||
->orderBy('date', 'DESC')
|
||||
->orderBy('order', 'ASC')
|
||||
->orderBy('id', 'DESC')
|
||||
->get(
|
||||
['transaction_journals.*']
|
||||
);
|
||||
$count = Auth::user()->transactionJournals()->transactionTypes($types)->count();
|
||||
$journals = new LengthAwarePaginator($set, $count, 50, $page);
|
||||
$journals->setPath('transactions/' . $what);
|
||||
|
||||
return view('transactions.index', compact('subTitle', 'what', 'subTitleIcon', 'journals'));
|
||||
@@ -213,15 +210,19 @@ class TransactionController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Reorder transactions (which all must have the same date)
|
||||
* @param JournalRepositoryInterface $repository
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function reorder()
|
||||
public function reorder(JournalRepositoryInterface $repository)
|
||||
{
|
||||
$ids = Input::get('items');
|
||||
$ids = Input::get('items');
|
||||
$date = new Carbon(Input::get('date'));
|
||||
if (count($ids) > 0) {
|
||||
$order = 0;
|
||||
foreach ($ids as $id) {
|
||||
$journal = Auth::user()->transactionjournals()->where('id', $id)->where('date', Input::get('date'))->first();
|
||||
|
||||
$journal = $repository->getWithDate($id, $date);
|
||||
if ($journal) {
|
||||
$journal->order = $order;
|
||||
$order++;
|
||||
@@ -235,31 +236,22 @@ class TransactionController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
* @param JournalRepositoryInterface $repository
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function show(TransactionJournal $journal)
|
||||
public function show(JournalRepositoryInterface $repository, TransactionJournal $journal)
|
||||
{
|
||||
$journal->transactions->each(
|
||||
function (Transaction $t) use ($journal) {
|
||||
$t->before = floatval(
|
||||
$t->account->transactions()->leftJoin(
|
||||
'transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id'
|
||||
)
|
||||
->where('transaction_journals.date', '<=', $journal->date->format('Y-m-d'))
|
||||
->where('transaction_journals.order', '>=', $journal->order)
|
||||
->where('transaction_journals.id', '!=', $journal->id)
|
||||
->sum('transactions.amount')
|
||||
);
|
||||
function (Transaction $t) use ($journal, $repository) {
|
||||
$t->before = $repository->getAmountBefore($journal, $t);
|
||||
$t->after = $t->before + $t->amount;
|
||||
}
|
||||
);
|
||||
$subTitle = e($journal->transactiontype->type) . ' "' . e($journal->description) . '"';
|
||||
|
||||
|
||||
return view('transactions.show', compact('journal'))->with(
|
||||
'subTitle', e($journal->transactiontype->type) . ' "' . e($journal->description) . '"'
|
||||
);
|
||||
return view('transactions.show', compact('journal', 'subTitle'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -279,11 +271,7 @@ class TransactionController extends Controller
|
||||
// ConnectJournalToPiggyBank
|
||||
event(new JournalCreated($journal, intval($request->get('piggy_bank_id'))));
|
||||
|
||||
if (intval($request->get('reminder_id')) > 0) {
|
||||
$reminder = Auth::user()->reminders()->find($request->get('reminder_id'));
|
||||
$reminder->active = 0;
|
||||
$reminder->save();
|
||||
}
|
||||
$repository->deactivateReminder($request->get('reminder_id'));
|
||||
|
||||
Session::flash('success', 'New transaction "' . $journal->description . '" stored!');
|
||||
|
||||
@@ -299,14 +287,15 @@ class TransactionController extends Controller
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
* @param JournalFormRequest $request
|
||||
* @param JournalRepositoryInterface $repository
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
|
||||
*
|
||||
* @return $this
|
||||
* @return $this|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(TransactionJournal $journal, JournalFormRequest $request, JournalRepositoryInterface $repository)
|
||||
public function update(JournalFormRequest $request, JournalRepositoryInterface $repository, TransactionJournal $journal)
|
||||
{
|
||||
|
||||
$journalData = $request->getJournalData();
|
||||
|
@@ -7,6 +7,7 @@ use Illuminate\Http\Request;
|
||||
/**
|
||||
* Class Authenticate
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Http\Middleware
|
||||
*/
|
||||
class Authenticate
|
||||
|
@@ -46,7 +46,7 @@ class PiggyBanks
|
||||
*/
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
if ($this->auth->check() && !$request->isXmlHttpRequest() && App::environment() != 'testing') {
|
||||
if ($this->auth->check() && !$request->isXmlHttpRequest()) {
|
||||
// get piggy banks without a repetition:
|
||||
/** @var Collection $set */
|
||||
$set = $this->auth->user()->piggybanks()
|
||||
|
@@ -48,7 +48,7 @@ class Range
|
||||
*/
|
||||
public function handle(Request $request, Closure $theNext)
|
||||
{
|
||||
if ($this->auth->check() && App::environment() != 'testing') {
|
||||
if ($this->auth->check()) {
|
||||
|
||||
// ignore preference. set the range to be the current month:
|
||||
if (!Session::has('start') && !Session::has('end')) {
|
||||
|
@@ -8,6 +8,7 @@ use Illuminate\Http\Request;
|
||||
/**
|
||||
* Class RedirectIfAuthenticated
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Http\Middleware
|
||||
*/
|
||||
class RedirectIfAuthenticated
|
||||
|
@@ -46,7 +46,7 @@ class Reminders
|
||||
*/
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
if ($this->auth->check() && !$request->isXmlHttpRequest() && App::environment() != 'testing') {
|
||||
if ($this->auth->check() && !$request->isXmlHttpRequest()) {
|
||||
// do reminders stuff.
|
||||
$piggyBanks = $this->auth->user()->piggyBanks()->where('remind_me', 1)->get();
|
||||
$today = new Carbon;
|
||||
|
@@ -10,6 +10,7 @@ use Log;
|
||||
/**
|
||||
* Class ReplaceTestVars
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Http\Middleware
|
||||
*/
|
||||
class ReplaceTestVars
|
||||
|
@@ -6,6 +6,7 @@ use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;
|
||||
/**
|
||||
* Class VerifyCsrfToken
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Http\Middleware
|
||||
*/
|
||||
class VerifyCsrfToken extends BaseVerifier
|
||||
|
@@ -10,6 +10,7 @@ use Input;
|
||||
/**
|
||||
* Class AccountFormRequest
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Http\Requests
|
||||
*/
|
||||
class AccountFormRequest extends Request
|
||||
|
@@ -9,6 +9,7 @@ use Input;
|
||||
/**
|
||||
* Class BillFormRequest
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Http\Requests
|
||||
*/
|
||||
class BillFormRequest extends Request
|
||||
|
@@ -9,6 +9,7 @@ use Input;
|
||||
/**
|
||||
* Class BudgetFormRequest
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Http\Requests
|
||||
*/
|
||||
class BudgetFormRequest extends Request
|
||||
|
@@ -9,6 +9,7 @@ use Input;
|
||||
/**
|
||||
* Class CategoryFormRequest
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Http\Requests
|
||||
*/
|
||||
class CategoryFormRequest extends Request
|
||||
|
@@ -8,6 +8,7 @@ use Input;
|
||||
/**
|
||||
* Class BillFormRequest
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Http\Requests
|
||||
*/
|
||||
class CurrencyFormRequest extends Request
|
||||
|
@@ -7,6 +7,7 @@ use Auth;
|
||||
/**
|
||||
* Class DeleteAccountFormRequest
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Http\Requests
|
||||
*/
|
||||
class DeleteAccountFormRequest extends Request
|
||||
@@ -26,7 +27,7 @@ class DeleteAccountFormRequest extends Request
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'password' => 'required',
|
||||
'password' => 'required',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@@ -10,6 +10,7 @@ use Input;
|
||||
/**
|
||||
* Class JournalFormRequest
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Http\Requests
|
||||
*/
|
||||
class JournalFormRequest extends Request
|
||||
@@ -42,6 +43,7 @@ class JournalFormRequest extends Request
|
||||
'date' => new Carbon($this->get('date')),
|
||||
'budget_id' => intval($this->get('budget_id')),
|
||||
'category' => $this->get('category'),
|
||||
'tags' => explode(',', $this->get('tags')),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -56,7 +58,7 @@ class JournalFormRequest extends Request
|
||||
|
||||
$rules = [
|
||||
'description' => 'required|min:1,max:255',
|
||||
'what' => 'required|in:withdrawal,deposit,transfer|exists:transaction_types,type',
|
||||
'what' => 'required|in:withdrawal,deposit,transfer',
|
||||
'amount' => 'numeric|required|min:0.01',
|
||||
'date' => 'required|date',
|
||||
'reminder_id' => 'numeric|exists:reminders,id',
|
||||
|
@@ -8,6 +8,7 @@ use Input;
|
||||
/**
|
||||
* Class PiggyBankFormRequest
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Http\Requests
|
||||
*/
|
||||
class PiggyBankFormRequest extends Request
|
||||
|
@@ -7,6 +7,7 @@ use Auth;
|
||||
/**
|
||||
* Class ProfileFormRequest
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Http\Requests
|
||||
*/
|
||||
class ProfileFormRequest extends Request
|
||||
|
@@ -5,6 +5,7 @@ use Illuminate\Foundation\Http\FormRequest;
|
||||
/**
|
||||
* Class Request
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Http\Requests
|
||||
*/
|
||||
abstract class Request extends FormRequest
|
||||
|
54
app/Http/Requests/TagFormRequest.php
Normal file
54
app/Http/Requests/TagFormRequest.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: sander
|
||||
* Date: 27/04/15
|
||||
* Time: 12:50
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use Auth;
|
||||
use FireflyIII\Models\Tag;
|
||||
use Input;
|
||||
|
||||
/**
|
||||
* Class TagFormRequest
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Http\Requests
|
||||
*/
|
||||
class TagFormRequest extends Request
|
||||
{
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
// Only allow logged in users
|
||||
return Auth::check();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
$idRule = '';
|
||||
$tagRule = 'required|min:1|uniqueObjectForUser:tags,tag,TRUE';
|
||||
if (Tag::find(Input::get('id'))) {
|
||||
$idRule = 'belongsToUser:tags';
|
||||
$tagRule = 'required|min:1|uniqueObjectForUser:tags,tag,TRUE,' . Input::get('id');
|
||||
}
|
||||
|
||||
return [
|
||||
'tag' => $tagRule,
|
||||
'id' => $idRule,
|
||||
'description' => 'min:1',
|
||||
'date' => 'date',
|
||||
'latitude' => 'numeric|min:-90|max:90',
|
||||
'longitude' => 'numeric|min:-90|max:90',
|
||||
'tagMode' => 'required|in:nothing,balancingAct,advancePayment'
|
||||
];
|
||||
}
|
||||
}
|
@@ -9,6 +9,8 @@ use FireflyIII\Models\Category;
|
||||
use FireflyIII\Models\LimitRepetition;
|
||||
use FireflyIII\Models\PiggyBank;
|
||||
use FireflyIII\Models\Reminder;
|
||||
use FireflyIII\Models\Tag;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
|
||||
/*
|
||||
@@ -22,6 +24,14 @@ Breadcrumbs::register(
|
||||
}
|
||||
);
|
||||
|
||||
Breadcrumbs::register(
|
||||
'index',
|
||||
function (Generator $breadcrumbs) {
|
||||
|
||||
$breadcrumbs->push('Home', route('index'));
|
||||
}
|
||||
);
|
||||
|
||||
// accounts
|
||||
Breadcrumbs::register(
|
||||
'accounts.index', function (Generator $breadcrumbs, $what) {
|
||||
@@ -95,6 +105,13 @@ Breadcrumbs::register(
|
||||
}
|
||||
);
|
||||
|
||||
Breadcrumbs::register(
|
||||
'budgets.noBudget', function (Generator $breadcrumbs, $subTitle) {
|
||||
$breadcrumbs->parent('budgets.index');
|
||||
$breadcrumbs->push($subTitle, route('budgets.noBudget'));
|
||||
}
|
||||
);
|
||||
|
||||
Breadcrumbs::register(
|
||||
'budgets.show', function (Generator $breadcrumbs, Budget $budget, LimitRepetition $repetition = null) {
|
||||
$breadcrumbs->parent('budgets.index');
|
||||
@@ -142,6 +159,34 @@ Breadcrumbs::register(
|
||||
}
|
||||
);
|
||||
|
||||
Breadcrumbs::register(
|
||||
'categories.noCategory', function (Generator $breadcrumbs, $subTitle) {
|
||||
$breadcrumbs->parent('categories.index');
|
||||
$breadcrumbs->push($subTitle, route('categories.noCategory'));
|
||||
}
|
||||
);
|
||||
|
||||
// currencies.
|
||||
Breadcrumbs::register(
|
||||
'currency.index', function (Generator $breadcrumbs) {
|
||||
$breadcrumbs->parent('home');
|
||||
$breadcrumbs->push('Currencies', route('currency.index'));
|
||||
}
|
||||
);
|
||||
|
||||
Breadcrumbs::register(
|
||||
'currency.edit', function (Generator $breadcrumbs, TransactionCurrency $currency) {
|
||||
$breadcrumbs->parent('currency.index');
|
||||
$breadcrumbs->push('Edit ' . $currency->name, route('currency.edit', $currency->id));
|
||||
}
|
||||
);
|
||||
Breadcrumbs::register(
|
||||
'currency.delete', function (Generator $breadcrumbs, TransactionCurrency $currency) {
|
||||
$breadcrumbs->parent('currency.index');
|
||||
$breadcrumbs->push('Delete ' . $currency->name, route('currency.delete', $currency->id));
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
// piggy banks
|
||||
Breadcrumbs::register(
|
||||
@@ -268,21 +313,21 @@ Breadcrumbs::register(
|
||||
Breadcrumbs::register(
|
||||
'reports.year', function (Generator $breadcrumbs, Carbon $date) {
|
||||
$breadcrumbs->parent('reports.index');
|
||||
$breadcrumbs->push($date->format('Y'), route('reports.year', $date->format('Y')));
|
||||
$breadcrumbs->push($date->year, route('reports.year', $date->year));
|
||||
}
|
||||
);
|
||||
|
||||
Breadcrumbs::register(
|
||||
'reports.month', function (Generator $breadcrumbs, Carbon $date) {
|
||||
$breadcrumbs->parent('reports.index');
|
||||
$breadcrumbs->push('Monthly report for ' . $date->format('F Y'), route('reports.month', $date));
|
||||
$breadcrumbs->parent('reports.year', $date);
|
||||
$breadcrumbs->push('Monthly report for ' . $date->format('F Y'), route('reports.month', [$date->year, $date->month]));
|
||||
}
|
||||
);
|
||||
|
||||
Breadcrumbs::register(
|
||||
'reports.budget', function (Generator $breadcrumbs, Carbon $date) {
|
||||
$breadcrumbs->parent('reports.index');
|
||||
$breadcrumbs->push('Budget report for ' . $date->format('F Y'), route('reports.budget', $date));
|
||||
$breadcrumbs->push('Budget report for ' . $date->format('F Y'), route('reports.budget', [$date->year, $date->month]));
|
||||
}
|
||||
);
|
||||
|
||||
@@ -350,3 +395,24 @@ Breadcrumbs::register(
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
// tags
|
||||
Breadcrumbs::register(
|
||||
'tags.index', function (Generator $breadcrumbs) {
|
||||
$breadcrumbs->parent('home');
|
||||
$breadcrumbs->push('Tags', route('tags.index'));
|
||||
}
|
||||
);
|
||||
|
||||
Breadcrumbs::register(
|
||||
'tags.create', function (Generator $breadcrumbs) {
|
||||
$breadcrumbs->parent('tags.index');
|
||||
$breadcrumbs->push('Create tag', route('tags.create'));
|
||||
}
|
||||
);
|
||||
Breadcrumbs::register(
|
||||
'tags.show', function (Generator $breadcrumbs, Tag $tag) {
|
||||
$breadcrumbs->parent('tags.index');
|
||||
$breadcrumbs->push(e($tag->tag), route('tags.show', $tag->id));
|
||||
}
|
||||
);
|
||||
|
@@ -6,121 +6,177 @@ use FireflyIII\Models\Category;
|
||||
use FireflyIII\Models\LimitRepetition;
|
||||
use FireflyIII\Models\PiggyBank;
|
||||
use FireflyIII\Models\Reminder;
|
||||
use FireflyIII\Models\Tag;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
|
||||
// models
|
||||
/** @noinspection PhpUnusedParameterInspection */
|
||||
Route::bind(
|
||||
'account',
|
||||
function ($value, $route) {
|
||||
if (Auth::check()) {
|
||||
$account = Account::leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||
->where('account_types.editable', 1)
|
||||
->where('accounts.id', $value)
|
||||
->where('user_id', Auth::user()->id)
|
||||
->first(['accounts.*']);
|
||||
if ($account) {
|
||||
return $account;
|
||||
$object = Account::leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||
->where('account_types.editable', 1)
|
||||
->where('accounts.id', $value)
|
||||
->where('user_id', Auth::user()->id)
|
||||
->first(['accounts.*']);
|
||||
if ($object) {
|
||||
return $object;
|
||||
}
|
||||
}
|
||||
App::abort(404);
|
||||
throw new NotFoundHttpException;
|
||||
}
|
||||
);
|
||||
|
||||
Route::bind(
|
||||
'tjSecond', function ($value, $route) {
|
||||
if (Auth::check()) {
|
||||
return TransactionJournal::
|
||||
where('id', $value)->where('user_id', Auth::user()->id)->first();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
);
|
||||
|
||||
/** @noinspection PhpUnusedParameterInspection */
|
||||
Route::bind(
|
||||
'tj', function ($value, $route) {
|
||||
if (Auth::check()) {
|
||||
return TransactionJournal::
|
||||
where('id', $value)->where('user_id', Auth::user()->id)->first();
|
||||
$object = TransactionJournal::where('id', $value)->where('user_id', Auth::user()->id)->first();
|
||||
if ($object) {
|
||||
return $object;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
throw new NotFoundHttpException;
|
||||
}
|
||||
);
|
||||
|
||||
/** @noinspection PhpUnusedParameterInspection */
|
||||
Route::bind(
|
||||
'currency', function ($value, $route) {
|
||||
return TransactionCurrency::find($value);
|
||||
if (Auth::check()) {
|
||||
$object = TransactionCurrency::find($value);
|
||||
if ($object) {
|
||||
return $object;
|
||||
}
|
||||
}
|
||||
throw new NotFoundHttpException;
|
||||
}
|
||||
);
|
||||
|
||||
/** @noinspection PhpUnusedParameterInspection */
|
||||
Route::bind(
|
||||
'bill', function ($value, $route) {
|
||||
if (Auth::check()) {
|
||||
return Bill::where('id', $value)->where('user_id', Auth::user()->id)->first();
|
||||
$object = Bill::where('id', $value)->where('user_id', Auth::user()->id)->first();
|
||||
if ($object) {
|
||||
return $object;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
throw new NotFoundHttpException;
|
||||
}
|
||||
);
|
||||
|
||||
/** @noinspection PhpUnusedParameterInspection */
|
||||
Route::bind(
|
||||
'budget', function ($value, $route) {
|
||||
if (Auth::check()) {
|
||||
return Budget::where('id', $value)->where('user_id', Auth::user()->id)->first();
|
||||
$object = Budget::where('id', $value)->where('user_id', Auth::user()->id)->first();
|
||||
if ($object) {
|
||||
return $object;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
throw new NotFoundHttpException;
|
||||
}
|
||||
);
|
||||
|
||||
/** @noinspection PhpUnusedParameterInspection */
|
||||
Route::bind(
|
||||
'reminder', function ($value, $route) {
|
||||
if (Auth::check()) {
|
||||
return Reminder::where('id', $value)->where('user_id', Auth::user()->id)->first();
|
||||
$object = Reminder::where('id', $value)->where('user_id', Auth::user()->id)->first();
|
||||
if ($object) {
|
||||
return $object;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
throw new NotFoundHttpException;
|
||||
}
|
||||
);
|
||||
|
||||
/** @noinspection PhpUnusedParameterInspection */
|
||||
Route::bind(
|
||||
'limitrepetition', function ($value, $route) {
|
||||
if (Auth::check()) {
|
||||
return LimitRepetition::where('limit_repetitions.id', $value)
|
||||
->leftjoin('budget_limits', 'budget_limits.id', '=', 'limit_repetitions.budget_limit_id')
|
||||
->leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id')
|
||||
->where('budgets.user_id', Auth::user()->id)
|
||||
->first(['limit_repetitions.*']);
|
||||
$object = LimitRepetition::where('limit_repetitions.id', $value)
|
||||
->leftjoin('budget_limits', 'budget_limits.id', '=', 'limit_repetitions.budget_limit_id')
|
||||
->leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id')
|
||||
->where('budgets.user_id', Auth::user()->id)
|
||||
->first(['limit_repetitions.*']);
|
||||
if ($object) {
|
||||
return $object;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
throw new NotFoundHttpException;
|
||||
}
|
||||
);
|
||||
|
||||
/** @noinspection PhpUnusedParameterInspection */
|
||||
Route::bind(
|
||||
'piggyBank', function ($value, $route) {
|
||||
if (Auth::check()) {
|
||||
return PiggyBank::
|
||||
where('piggy_banks.id', $value)
|
||||
->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')
|
||||
->where('accounts.user_id', Auth::user()->id)
|
||||
->first(['piggy_banks.*']);
|
||||
$object = PiggyBank::where('piggy_banks.id', $value)
|
||||
->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')
|
||||
->where('accounts.user_id', Auth::user()->id)
|
||||
->first(['piggy_banks.*']);
|
||||
if ($object) {
|
||||
return $object;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
throw new NotFoundHttpException;
|
||||
}
|
||||
);
|
||||
|
||||
/** @noinspection PhpUnusedParameterInspection */
|
||||
Route::bind(
|
||||
'category', function ($value, $route) {
|
||||
if (Auth::check()) {
|
||||
return Category::where('id', $value)->where('user_id', Auth::user()->id)->first();
|
||||
$object = Category::where('id', $value)->where('user_id', Auth::user()->id)->first();
|
||||
if ($object) {
|
||||
return $object;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
throw new NotFoundHttpException;
|
||||
}
|
||||
);
|
||||
|
||||
/** @noinspection PhpUnusedParameterInspection */
|
||||
Route::bind(
|
||||
'reminder', function ($value, $route) {
|
||||
if (Auth::check()) {
|
||||
/** @var \FireflyIII\Models\Reminder $object */
|
||||
$object = Reminder::find($value);
|
||||
if ($object) {
|
||||
if ($object->remindersable->account->user_id == Auth::user()->id) {
|
||||
return $object;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new NotFoundHttpException;
|
||||
}
|
||||
);
|
||||
|
||||
/** @noinspection PhpUnusedParameterInspection */
|
||||
Route::bind(
|
||||
'tag', function ($value, $route) {
|
||||
if (Auth::check()) {
|
||||
$object = Tag::where('id', $value)->where('user_id', Auth::user()->id)->first();
|
||||
if ($object) {
|
||||
return $object;
|
||||
}
|
||||
}
|
||||
|
||||
throw new NotFoundHttpException;
|
||||
}
|
||||
);
|
||||
|
||||
@@ -245,6 +301,7 @@ Route::group(
|
||||
Route::get('/json/expense-accounts', ['uses' => 'JsonController@expenseAccounts', 'as' => 'json.expense-accounts']);
|
||||
Route::get('/json/revenue-accounts', ['uses' => 'JsonController@revenueAccounts', 'as' => 'json.revenue-accounts']);
|
||||
Route::get('/json/categories', ['uses' => 'JsonController@categories', 'as' => 'json.categories']);
|
||||
Route::get('/json/tags', ['uses' => 'JsonController@tags', 'as' => 'json.tags']);
|
||||
Route::get('/json/box/in', ['uses' => 'JsonController@boxIn', 'as' => 'json.box.in']);
|
||||
Route::get('/json/box/out', ['uses' => 'JsonController@boxOut', 'as' => 'json.box.out']);
|
||||
Route::get('/json/box/bills-unpaid', ['uses' => 'JsonController@boxBillsUnpaid', 'as' => 'json.box.paid']);
|
||||
@@ -286,16 +343,6 @@ Route::group(
|
||||
Route::post('/profile/delete-account', ['uses' => 'ProfileController@postDeleteAccount', 'as' => 'delete-account-post']);
|
||||
Route::post('/profile/change-password', ['uses' => 'ProfileController@postChangePassword', 'as' => 'change-password-post']);
|
||||
|
||||
/**
|
||||
* Related transactions controller
|
||||
*/
|
||||
Route::get('/related/alreadyRelated/{tj}', ['uses' => 'RelatedController@alreadyRelated', 'as' => 'related.alreadyRelated']);
|
||||
Route::post('/related/relate/{tj}/{tjSecond}', ['uses' => 'RelatedController@relate', 'as' => 'related.relate']);
|
||||
Route::post('/related/removeRelation/{tj}/{tjSecond}', ['uses' => 'RelatedController@removeRelation', 'as' => 'related.removeRelation']);
|
||||
Route::get('/related/remove/{tj}/{tjSecond}', ['uses' => 'RelatedController@getRemoveRelation', 'as' => 'related.getRemoveRelation']);
|
||||
Route::get('/related/related/{tj}', ['uses' => 'RelatedController@related', 'as' => 'related.related']);
|
||||
Route::post('/related/search/{tj}', ['uses' => 'RelatedController@search', 'as' => 'related.search']);
|
||||
|
||||
/**
|
||||
* Reminder Controller
|
||||
*/
|
||||
@@ -327,6 +374,22 @@ Route::group(
|
||||
*/
|
||||
Route::get('/search', ['uses' => 'SearchController@index', 'as' => 'search']);
|
||||
|
||||
/**
|
||||
* Tag Controller
|
||||
*/
|
||||
Route::get('/tags', ['uses' => 'TagController@index', 'as' => 'tags.index']);
|
||||
Route::get('/tags/create', ['uses' => 'TagController@create', 'as' => 'tags.create']);
|
||||
Route::get('/tags/show/{tag}', ['uses' => 'TagController@show', 'as' => 'tags.show']);
|
||||
Route::get('/tags/edit/{tag}', ['uses' => 'TagController@edit', 'as' => 'tags.edit']);
|
||||
Route::get('/tags/delete/{tag}', ['uses' => 'TagController@delete', 'as' => 'tags.delete']);
|
||||
|
||||
Route::post('/tags/store', ['uses' => 'TagController@store', 'as' => 'tags.store']);
|
||||
Route::post('/tags/update/{tag}', ['uses' => 'TagController@update', 'as' => 'tags.update']);
|
||||
Route::post('/tags/destroy/{tag}', ['uses' => 'TagController@destroy', 'as' => 'tags.destroy']);
|
||||
|
||||
Route::post('/tags/hideTagHelp/{state}', ['uses' => 'TagController@hideTagHelp', 'as' => 'tags.hideTagHelp']);
|
||||
|
||||
|
||||
/**
|
||||
* Transaction Controller
|
||||
*/
|
||||
|
@@ -29,6 +29,7 @@ class Account extends Model
|
||||
/**
|
||||
* @param array $fields
|
||||
*
|
||||
*
|
||||
* @return Account|null
|
||||
*/
|
||||
public static function firstOrCreateEncrypted(array $fields)
|
||||
@@ -51,7 +52,7 @@ class Account extends Model
|
||||
$account = Account::create($fields);
|
||||
if (is_null($account->id)) {
|
||||
// could not create account:
|
||||
App::abort(500, 'Could not create new account with data: ' . json_encode($fields).' because ' . json_encode($account->getErrors()));
|
||||
App::abort(500, 'Could not create new account with data: ' . json_encode($fields) . ' because ' . json_encode($account->getErrors()));
|
||||
|
||||
|
||||
}
|
||||
@@ -61,6 +62,32 @@ class Account extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $fields
|
||||
*
|
||||
* @return Account|null
|
||||
*/
|
||||
public static function firstOrNullEncrypted(array $fields)
|
||||
{
|
||||
// everything but the name:
|
||||
$query = Account::orderBy('id');
|
||||
foreach ($fields as $name => $value) {
|
||||
if ($name != 'name') {
|
||||
$query->where($name, $value);
|
||||
}
|
||||
}
|
||||
$set = $query->get(['accounts.*']);
|
||||
/** @var Account $account */
|
||||
foreach ($set as $account) {
|
||||
if ($account->name == $fields['name']) {
|
||||
return $account;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function accountMeta()
|
||||
@@ -69,6 +96,7 @@ class Account extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function accountType()
|
||||
@@ -77,6 +105,7 @@ class Account extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return array
|
||||
*/
|
||||
public function getDates()
|
||||
@@ -85,6 +114,7 @@ class Account extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param $fieldName
|
||||
*
|
||||
* @return string|null
|
||||
@@ -102,6 +132,7 @@ class Account extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @param $value
|
||||
*
|
||||
* @return string
|
||||
@@ -119,6 +150,7 @@ class Account extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function piggyBanks()
|
||||
@@ -127,6 +159,7 @@ class Account extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @param EloquentBuilder $query
|
||||
* @param array $types
|
||||
*/
|
||||
@@ -140,6 +173,7 @@ class Account extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @param EloquentBuilder $query
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
@@ -156,6 +190,7 @@ class Account extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @param $value
|
||||
*/
|
||||
public function setNameAttribute($value)
|
||||
@@ -165,6 +200,7 @@ class Account extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function transactions()
|
||||
@@ -173,6 +209,7 @@ class Account extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function user()
|
||||
|
@@ -6,6 +6,7 @@ use Watson\Validating\ValidatingTrait;
|
||||
/**
|
||||
* Class AccountMeta
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Models
|
||||
*/
|
||||
class AccountMeta extends Model
|
||||
@@ -22,6 +23,7 @@ class AccountMeta extends Model
|
||||
protected $table = 'account_meta';
|
||||
|
||||
/**
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function account()
|
||||
|
@@ -5,6 +5,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
/**
|
||||
* Class AccountType
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Models
|
||||
*/
|
||||
class AccountType extends Model
|
||||
|
@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
/**
|
||||
* Class Budget
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Models
|
||||
*/
|
||||
class Budget extends Model
|
||||
@@ -17,6 +18,7 @@ class Budget extends Model
|
||||
protected $fillable = ['user_id', 'name'];
|
||||
|
||||
/**
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function budgetlimits()
|
||||
|
@@ -5,6 +5,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
/**
|
||||
* Class BudgetLimit
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Models
|
||||
*/
|
||||
class BudgetLimit extends Model
|
||||
|
@@ -1,12 +1,14 @@
|
||||
<?php namespace FireflyIII\Models;
|
||||
|
||||
use App;
|
||||
use Crypt;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use App;
|
||||
|
||||
/**
|
||||
* Class Category
|
||||
*
|
||||
*
|
||||
* @package FireflyIII\Models
|
||||
*/
|
||||
class Category extends Model
|
||||
@@ -16,6 +18,7 @@ class Category extends Model
|
||||
protected $fillable = ['user_id', 'name'];
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return array
|
||||
*/
|
||||
public function getDates()
|
||||
@@ -24,6 +27,7 @@ class Category extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function transactionjournals()
|
||||
@@ -65,6 +69,7 @@ class Category extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function user()
|
||||
@@ -73,6 +78,7 @@ class Category extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @param $value
|
||||
*/
|
||||
public function setNameAttribute($value)
|
||||
@@ -82,6 +88,7 @@ class Category extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @param $value
|
||||
*
|
||||
* @return string
|
||||
@@ -93,9 +100,7 @@ class Category extends Model
|
||||
return Crypt::decrypt($value);
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
return $value;
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
/**
|
||||
* Class Component
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Models
|
||||
*/
|
||||
class Component extends Model
|
||||
|
@@ -13,6 +13,7 @@ class LimitRepetition extends Model
|
||||
{
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function budgetLimit()
|
||||
@@ -21,6 +22,7 @@ class LimitRepetition extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return array
|
||||
*/
|
||||
public function getDates()
|
||||
|
@@ -14,9 +14,10 @@ class PiggyBank extends Model
|
||||
use SoftDeletes;
|
||||
|
||||
protected $fillable
|
||||
= ['name', 'account_id', 'reminder_skip', 'targetamount', 'startdate', 'targetdate', 'reminder', 'remind_me'];
|
||||
= ['name', 'account_id', 'order', 'reminder_skip', 'targetamount', 'startdate', 'targetdate', 'reminder', 'remind_me'];
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function account()
|
||||
@@ -44,6 +45,7 @@ class PiggyBank extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function piggyBankRepetitions()
|
||||
@@ -52,6 +54,7 @@ class PiggyBank extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return array
|
||||
*/
|
||||
public function getDates()
|
||||
@@ -60,6 +63,7 @@ class PiggyBank extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @param $value
|
||||
*
|
||||
* @return int
|
||||
@@ -70,6 +74,7 @@ class PiggyBank extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function piggyBankEvents()
|
||||
@@ -78,6 +83,7 @@ class PiggyBank extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
|
||||
*/
|
||||
public function reminders()
|
||||
@@ -86,6 +92,7 @@ class PiggyBank extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @param $value
|
||||
*/
|
||||
public function setNameAttribute($value)
|
||||
@@ -95,6 +102,7 @@ class PiggyBank extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @param $value
|
||||
*
|
||||
* @return string
|
||||
|
@@ -5,6 +5,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
/**
|
||||
* Class PiggyBankEvent
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Models
|
||||
*/
|
||||
class PiggyBankEvent extends Model
|
||||
|
@@ -7,11 +7,14 @@ use Illuminate\Database\Eloquent\Model;
|
||||
/**
|
||||
* Class PiggyBankRepetition
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Models
|
||||
*/
|
||||
class PiggyBankRepetition extends Model
|
||||
{
|
||||
|
||||
protected $fillable = ['piggy_bank_id', 'startdate', 'targetdate', 'currentamount'];
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
|
@@ -5,6 +5,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
/**
|
||||
* Class Preference
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Models
|
||||
*/
|
||||
class Preference extends Model
|
||||
|
@@ -17,6 +17,7 @@ class Reminder extends Model
|
||||
protected $fillable = ['user_id', 'startdate', 'metadata', 'enddate', 'active', 'notnow', 'remindersable_id', 'remindersable_type',];
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @param $value
|
||||
*
|
||||
* @return int
|
||||
@@ -27,6 +28,7 @@ class Reminder extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return array
|
||||
*/
|
||||
public function getDates()
|
||||
@@ -35,6 +37,7 @@ class Reminder extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @param $value
|
||||
*
|
||||
* @return mixed
|
||||
@@ -49,6 +52,7 @@ class Reminder extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @param $value
|
||||
*
|
||||
* @return bool
|
||||
@@ -59,6 +63,7 @@ class Reminder extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
|
||||
*/
|
||||
public function remindersable()
|
||||
@@ -67,6 +72,7 @@ class Reminder extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @param EloquentBuilder $query
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
@@ -78,6 +84,12 @@ class Reminder extends Model
|
||||
return $query->where('reminders.startdate', '=', $start->format('Y-m-d 00:00:00'))->where('reminders.enddate', '=', $end->format('Y-m-d 00:00:00'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @param EloquentBuilder $query
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function scopeToday(EloquentBuilder $query)
|
||||
{
|
||||
$today = new Carbon;
|
||||
@@ -87,6 +99,7 @@ class Reminder extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @param $value
|
||||
*/
|
||||
public function setMetadataAttribute($value)
|
||||
@@ -96,6 +109,7 @@ class Reminder extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function user()
|
||||
|
135
app/Models/Tag.php
Normal file
135
app/Models/Tag.php
Normal file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Models;
|
||||
|
||||
use App;
|
||||
use Crypt;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
|
||||
/**
|
||||
* Class Tag
|
||||
*
|
||||
* @package FireflyIII\Models
|
||||
*/
|
||||
class Tag extends Model
|
||||
{
|
||||
use ValidatingTrait;
|
||||
|
||||
protected $fillable = ['user_id', 'tag', 'date', 'description', 'longitude', 'latitude', 'zoomLevel', 'tagMode'];
|
||||
protected $rules
|
||||
= [
|
||||
'tag' => 'required|min:1|uniqueObjectForUser:tags,tag,TRUE',
|
||||
'description' => 'min:1',
|
||||
'date' => 'date',
|
||||
'latitude' => 'numeric|min:-90|max:90',
|
||||
'longitude' => 'numeric|min:-90|max:90',
|
||||
'tagMode' => 'required|in:nothing,balancingAct,advancePayment'
|
||||
];
|
||||
|
||||
/**
|
||||
* @param array $fields
|
||||
*
|
||||
* @return Tag|null
|
||||
*/
|
||||
public static function firstOrCreateEncrypted(array $fields)
|
||||
{
|
||||
// everything but the tag:
|
||||
if (isset($fields['tagMode'])) {
|
||||
unset($fields['tagMode']);
|
||||
}
|
||||
$query = Tag::orderBy('id');
|
||||
foreach ($fields as $name => $value) {
|
||||
if ($name != 'tag') {
|
||||
$query->where($name, $value);
|
||||
}
|
||||
}
|
||||
$set = $query->get(['tags.*']);
|
||||
/** @var Tag $tag */
|
||||
foreach ($set as $tag) {
|
||||
if ($tag->tag == $fields['tag']) {
|
||||
return $tag;
|
||||
}
|
||||
}
|
||||
// create it!
|
||||
$fields['tagMode'] = 'nothing';
|
||||
$fields['description'] = isset($fields['description']) && !is_null($fields['description']) ? $fields['description'] : '';
|
||||
$tag = Tag::create($fields);
|
||||
if (is_null($tag->id)) {
|
||||
// could not create account:
|
||||
App::abort(500, 'Could not create new tag with data: ' . json_encode($fields) . ' because ' . json_encode($tag->getErrors()));
|
||||
|
||||
|
||||
}
|
||||
|
||||
return $tag;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return array
|
||||
*/
|
||||
public function getDates()
|
||||
{
|
||||
return ['created_at', 'updated_at', 'date'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @param $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescriptionAttribute($value)
|
||||
{
|
||||
return Crypt::decrypt($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @param $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTagAttribute($value)
|
||||
{
|
||||
return Crypt::decrypt($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @param $value
|
||||
*/
|
||||
public function setDescriptionAttribute($value)
|
||||
{
|
||||
$this->attributes['description'] = Crypt::encrypt($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @param $value
|
||||
*/
|
||||
public function setTagAttribute($value)
|
||||
{
|
||||
$this->attributes['tag'] = Crypt::encrypt($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function transactionjournals()
|
||||
{
|
||||
return $this->belongsToMany('FireflyIII\Models\TransactionJournal');
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo('FireflyIII\User');
|
||||
}
|
||||
}
|
@@ -9,6 +9,7 @@ use Watson\Validating\ValidatingTrait;
|
||||
/**
|
||||
* Class Transaction
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Models
|
||||
*/
|
||||
class Transaction extends Model
|
||||
|
@@ -4,8 +4,10 @@ use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class TransactionCurrency
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Models
|
||||
*/
|
||||
class TransactionCurrency extends Model
|
||||
|
@@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
/**
|
||||
* Class TransactionGroup
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Models
|
||||
*/
|
||||
class TransactionGroup extends Model
|
||||
|
@@ -32,6 +32,7 @@ class TransactionJournal extends Model
|
||||
];
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function bill()
|
||||
@@ -40,6 +41,7 @@ class TransactionJournal extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function budgets()
|
||||
@@ -48,6 +50,7 @@ class TransactionJournal extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function categories()
|
||||
@@ -66,9 +69,44 @@ class TransactionJournal extends Model
|
||||
return floatval($t->amount);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Account|mixed
|
||||
*/
|
||||
public function getAssetAccountAttribute()
|
||||
{
|
||||
$positive = true; // the asset account is in the transaction with the positive amount.
|
||||
if ($this->transactionType->type === 'Withdrawal') {
|
||||
$positive = false;
|
||||
}
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($this->transactions()->get() as $transaction) {
|
||||
if (floatval($transaction->amount) > 0 && $positive === true) {
|
||||
return $transaction->account;
|
||||
}
|
||||
if (floatval($transaction->amount) < 0 && $positive === false) {
|
||||
return $transaction->account;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $this->transactions()->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function transactions()
|
||||
{
|
||||
return $this->hasMany('FireflyIII\Models\Transaction');
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return array
|
||||
*/
|
||||
public function getDates()
|
||||
@@ -77,6 +115,7 @@ class TransactionJournal extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @param $value
|
||||
*
|
||||
* @return string
|
||||
@@ -87,12 +126,11 @@ class TransactionJournal extends Model
|
||||
return Crypt::decrypt($value);
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
return $value;
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function piggyBankEvents()
|
||||
@@ -101,6 +139,7 @@ class TransactionJournal extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @param EloquentBuilder $query
|
||||
* @param Account $account
|
||||
*/
|
||||
@@ -114,6 +153,7 @@ class TransactionJournal extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @param EloquentBuilder $query
|
||||
* @param Carbon $date
|
||||
*
|
||||
@@ -125,6 +165,7 @@ class TransactionJournal extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @param EloquentBuilder $query
|
||||
* @param Carbon $date
|
||||
*
|
||||
@@ -136,6 +177,7 @@ class TransactionJournal extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @param EloquentBuilder $query
|
||||
* @param $amount
|
||||
*/
|
||||
@@ -152,6 +194,7 @@ class TransactionJournal extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @param EloquentBuilder $query
|
||||
* @param Carbon $date
|
||||
*
|
||||
@@ -163,6 +206,7 @@ class TransactionJournal extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @param EloquentBuilder $query
|
||||
* @param array $types
|
||||
*/
|
||||
@@ -178,6 +222,7 @@ class TransactionJournal extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* Automatically includes the 'with' parameters to get relevant related
|
||||
* objects.
|
||||
*
|
||||
@@ -193,15 +238,26 @@ class TransactionJournal extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @param $value
|
||||
*/
|
||||
public function setDescriptionAttribute($value)
|
||||
{
|
||||
$this->attributes['description'] = \Crypt::encrypt($value);
|
||||
$this->attributes['description'] = Crypt::encrypt($value);
|
||||
$this->attributes['encrypted'] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function tags()
|
||||
{
|
||||
return $this->belongsToMany('FireflyIII\Models\Tag');
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function transactionCurrency()
|
||||
@@ -210,6 +266,7 @@ class TransactionJournal extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function transactionType()
|
||||
@@ -218,6 +275,7 @@ class TransactionJournal extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function transactiongroups()
|
||||
@@ -226,14 +284,7 @@ class TransactionJournal extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function transactions()
|
||||
{
|
||||
return $this->hasMany('FireflyIII\Models\Transaction');
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function user()
|
||||
|
@@ -5,6 +5,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
/**
|
||||
* Class TransactionRelation
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Models
|
||||
*/
|
||||
class TransactionRelation extends Model
|
||||
|
@@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
/**
|
||||
* Class TransactionType
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Models
|
||||
*/
|
||||
class TransactionType extends Model
|
||||
|
@@ -35,6 +35,7 @@ class AppServiceProvider extends ServiceProvider
|
||||
'Illuminate\Contracts\Auth\Registrar',
|
||||
'FireflyIII\Services\Registrar'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -23,7 +23,227 @@ class ConfigServiceProvider extends ServiceProvider
|
||||
{
|
||||
config(
|
||||
[
|
||||
//
|
||||
'twigbridge' => [
|
||||
|
||||
'twig' => [
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Extension
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| File extension for Twig view files.
|
||||
|
|
||||
*/
|
||||
'extension' => 'twig',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Accepts all Twig environment configuration options
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| http://twig.sensiolabs.org/doc/api.html#environment-options
|
||||
|
|
||||
*/
|
||||
'environment' => [
|
||||
|
||||
// When set to true, the generated templates have a __toString() method
|
||||
// that you can use to display the generated nodes.
|
||||
// default: false
|
||||
'debug' => config('app.debug', false),
|
||||
|
||||
// The charset used by the templates.
|
||||
// default: utf-8
|
||||
'charset' => 'utf-8',
|
||||
|
||||
// The base template class to use for generated templates.
|
||||
// default: TwigBridge\Twig\Template
|
||||
'base_template_class' => 'TwigBridge\Twig\Template',
|
||||
|
||||
// An absolute path where to store the compiled templates, or false to disable caching. If null
|
||||
// then the cache file path is used.
|
||||
// default: cache file storage path
|
||||
'cache' => null,
|
||||
|
||||
// When developing with Twig, it's useful to recompile the template
|
||||
// whenever the source code changes. If you don't provide a value
|
||||
// for the auto_reload option, it will be determined automatically based on the debug value.
|
||||
'auto_reload' => true,
|
||||
|
||||
// If set to false, Twig will silently ignore invalid variables
|
||||
// (variables and or attributes/methods that do not exist) and
|
||||
// replace them with a null value. When set to true, Twig throws an exception instead.
|
||||
// default: false
|
||||
'strict_variables' => false,
|
||||
|
||||
// If set to true, auto-escaping will be enabled by default for all templates.
|
||||
// default: true
|
||||
'autoescape' => true,
|
||||
|
||||
// A flag that indicates which optimizations to apply
|
||||
// (default to -1 -- all optimizations are enabled; set it to 0 to disable)
|
||||
'optimizations' => -1,
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Global variables
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| These will always be passed in and can be accessed as Twig variables.
|
||||
| NOTE: these will be overwritten if you pass data into the view with the same key.
|
||||
|
|
||||
*/
|
||||
'globals' => [],
|
||||
],
|
||||
|
||||
'extensions' => [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Extensions
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Enabled extensions.
|
||||
|
|
||||
| `Twig_Extension_Debug` is enabled automatically if twig.debug is TRUE.
|
||||
|
|
||||
*/
|
||||
'enabled' => [
|
||||
'TwigBridge\Extension\Loader\Facades',
|
||||
'TwigBridge\Extension\Loader\Filters',
|
||||
'TwigBridge\Extension\Loader\Functions',
|
||||
|
||||
'TwigBridge\Extension\Laravel\Auth',
|
||||
'TwigBridge\Extension\Laravel\Config',
|
||||
'TwigBridge\Extension\Laravel\Dump',
|
||||
'TwigBridge\Extension\Laravel\Input',
|
||||
'TwigBridge\Extension\Laravel\Session',
|
||||
'TwigBridge\Extension\Laravel\String',
|
||||
'TwigBridge\Extension\Laravel\Translator',
|
||||
'TwigBridge\Extension\Laravel\Url',
|
||||
|
||||
// 'TwigBridge\Extension\Laravel\Form',
|
||||
// 'TwigBridge\Extension\Laravel\Html',
|
||||
// 'TwigBridge\Extension\Laravel\Legacy\Facades',
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Facades
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Available facades. Access like `{{ Config.get('foo.bar') }}`.
|
||||
|
|
||||
| Each facade can take an optional array of options. To mark the whole facade
|
||||
| as safe you can set the option `'is_safe' => true`. Setting the facade as
|
||||
| safe means that any HTML returned will not be escaped.
|
||||
|
|
||||
| It is advisable to not set the whole facade as safe and instead mark the
|
||||
| each appropriate method as safe for security reasons. You can do that with
|
||||
| the following syntax:
|
||||
|
|
||||
| <code>
|
||||
| 'Form' => [
|
||||
| 'is_safe' => [
|
||||
| 'open'
|
||||
| ]
|
||||
| ]
|
||||
| </code>
|
||||
|
|
||||
| The values of the `is_safe` array must match the called method on the facade
|
||||
| in order to be marked as safe.
|
||||
|
|
||||
*/
|
||||
'facades' => [
|
||||
'Breadcrumbs' => [
|
||||
'is_safe' => [
|
||||
'renderIfExists'
|
||||
]
|
||||
],
|
||||
'Session',
|
||||
'Route',
|
||||
'Auth',
|
||||
'URL',
|
||||
'Config',
|
||||
'ExpandedForm' => [
|
||||
'is_safe' => [
|
||||
'date', 'text', 'select', 'balance', 'optionsList', 'checkbox', 'amount', 'tags', 'integer', 'textarea', 'location',
|
||||
'multiRadio'
|
||||
]
|
||||
],
|
||||
'Form' => [
|
||||
'is_safe' => [
|
||||
'input', 'select', 'checkbox', 'model', 'open', 'radio', 'textarea'
|
||||
]
|
||||
],
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Functions
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Available functions. Access like `{{ secure_url(...) }}`.
|
||||
|
|
||||
| Each function can take an optional array of options. These options are
|
||||
| passed directly to `Twig_SimpleFunction`.
|
||||
|
|
||||
| So for example, to mark a function as safe you can do the following:
|
||||
|
|
||||
| <code>
|
||||
| 'link_to' => [
|
||||
| 'is_safe' => ['html']
|
||||
| ]
|
||||
| </code>
|
||||
|
|
||||
| The options array also takes a `callback` that allows you to name the
|
||||
| function differently in your Twig templates than what it's actually called.
|
||||
|
|
||||
| <code>
|
||||
| 'link' => [
|
||||
| 'callback' => 'link_to'
|
||||
| ]
|
||||
| </code>
|
||||
|
|
||||
*/
|
||||
'functions' => [
|
||||
'elixir',
|
||||
'head',
|
||||
'last',
|
||||
'old'
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Filters
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Available filters. Access like `{{ variable|filter }}`.
|
||||
|
|
||||
| Each filter can take an optional array of options. These options are
|
||||
| passed directly to `Twig_SimpleFilter`.
|
||||
|
|
||||
| So for example, to mark a filter as safe you can do the following:
|
||||
|
|
||||
| <code>
|
||||
| 'studly_case' => [
|
||||
| 'is_safe' => ['html']
|
||||
| ]
|
||||
| </code>
|
||||
|
|
||||
| The options array also takes a `callback` that allows you to name the
|
||||
| filter differently in your Twig templates than what is actually called.
|
||||
|
|
||||
| <code>
|
||||
| 'snake' => [
|
||||
| 'callback' => 'snake_case'
|
||||
| ]
|
||||
| </code>
|
||||
|
|
||||
*/
|
||||
'filters' => [],
|
||||
],
|
||||
]
|
||||
]
|
||||
);
|
||||
}
|
||||
|
@@ -1,11 +1,11 @@
|
||||
<?php namespace FireflyIII\Providers;
|
||||
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Models\BudgetLimit;
|
||||
use FireflyIII\Models\LimitRepetition;
|
||||
use FireflyIII\Models\PiggyBank;
|
||||
use FireflyIII\Models\PiggyBankRepetition;
|
||||
use FireflyIII\Models\Reminder;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Support\Facades\Navigation;
|
||||
@@ -13,7 +13,6 @@ use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
use Log;
|
||||
use FireflyIII\Models\Reminder;
|
||||
|
||||
/**
|
||||
* Class EventServiceProvider
|
||||
@@ -118,8 +117,8 @@ class EventServiceProvider extends ServiceProvider
|
||||
try {
|
||||
$repetition->save();
|
||||
} catch (QueryException $e) {
|
||||
\Log::error('Trying to save new LimitRepetition failed!');
|
||||
\Log::error($e->getMessage());
|
||||
Log::error('Trying to save new LimitRepetition failed!');
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
} else {
|
||||
if ($set->count() == 1) {
|
||||
|
@@ -2,13 +2,21 @@
|
||||
|
||||
namespace FireflyIII\Providers;
|
||||
|
||||
use App;
|
||||
use FireflyIII\Support\Amount;
|
||||
use FireflyIII\Support\ExpandedForm;
|
||||
use FireflyIII\Support\Navigation;
|
||||
use FireflyIII\Support\Preferences;
|
||||
use FireflyIII\Support\Steam;
|
||||
use FireflyIII\Support\Twig\Budget;
|
||||
use FireflyIII\Support\Twig\General;
|
||||
use FireflyIII\Support\Twig\Translation;
|
||||
use FireflyIII\Support\Twig\Journal;
|
||||
use FireflyIII\Support\Twig\PiggyBank;
|
||||
use FireflyIII\Validation\FireflyValidator;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Twig;
|
||||
use TwigBridge\Extension\Loader\Functions;
|
||||
use Validator;
|
||||
|
||||
/**
|
||||
@@ -25,10 +33,23 @@ class FireflyServiceProvider extends ServiceProvider
|
||||
return new FireflyValidator($translator, $data, $rules, $messages);
|
||||
}
|
||||
);
|
||||
/*
|
||||
* Default Twig configuration:
|
||||
*/
|
||||
|
||||
$config = App::make('config');
|
||||
Twig::addExtension(new Functions($config));
|
||||
Twig::addExtension(new PiggyBank);
|
||||
Twig::addExtension(new General);
|
||||
Twig::addExtension(new Journal);
|
||||
Twig::addExtension(new Budget);
|
||||
Twig::addExtension(new Translation);
|
||||
}
|
||||
|
||||
public function register()
|
||||
{
|
||||
|
||||
|
||||
$this->app->bind(
|
||||
'preferences', function () {
|
||||
return new Preferences;
|
||||
@@ -63,6 +84,8 @@ class FireflyServiceProvider extends ServiceProvider
|
||||
$this->app->bind('FireflyIII\Repositories\Bill\BillRepositoryInterface', 'FireflyIII\Repositories\Bill\BillRepository');
|
||||
$this->app->bind('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface', 'FireflyIII\Repositories\PiggyBank\PiggyBankRepository');
|
||||
$this->app->bind('FireflyIII\Repositories\Currency\CurrencyRepositoryInterface', 'FireflyIII\Repositories\Currency\CurrencyRepository');
|
||||
$this->app->bind('FireflyIII\Repositories\Tag\TagRepositoryInterface', 'FireflyIII\Repositories\Tag\TagRepository');
|
||||
$this->app->bind('FireflyIII\Repositories\Reminder\ReminderRepositoryInterface', 'FireflyIII\Repositories\Reminder\ReminderRepository');
|
||||
$this->app->bind('FireflyIII\Support\Search\SearchInterface', 'FireflyIII\Support\Search\Search');
|
||||
|
||||
|
||||
@@ -71,6 +94,7 @@ class FireflyServiceProvider extends ServiceProvider
|
||||
$this->app->bind('FireflyIII\Helpers\Report\ReportHelperInterface', 'FireflyIII\Helpers\Report\ReportHelper');
|
||||
$this->app->bind('FireflyIII\Helpers\Report\ReportQueryInterface', 'FireflyIII\Helpers\Report\ReportQuery');
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -16,12 +16,14 @@ use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Session;
|
||||
use Steam;
|
||||
|
||||
|
||||
/**
|
||||
* Class AccountRepository
|
||||
*
|
||||
@@ -224,7 +226,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
// then, percentage.
|
||||
$difference = $account->endBalance - $account->piggyBalance;
|
||||
$account->difference = $difference;
|
||||
$account->percentage = $difference != 0 ? round((($difference / $account->endBalance) * 100)) : 100;
|
||||
$account->percentage = $difference != 0 && $account->endBalance != 0 ? round((($difference / $account->endBalance) * 100)) : 100;
|
||||
|
||||
}
|
||||
);
|
||||
@@ -269,6 +271,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
$pct = $pct > 100 ? 100 : $pct;
|
||||
$account->difference = $diff;
|
||||
$account->percentage = round($pct);
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
@@ -287,7 +290,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
public function getTransfersInRange(Account $account, Carbon $start, Carbon $end)
|
||||
{
|
||||
return TransactionJournal::whereIn(
|
||||
'id', function ($q) use ($account, $start, $end) {
|
||||
'id', function (Builder $q) use ($account, $start, $end) {
|
||||
$q->select('transaction_journals.id')
|
||||
->from('transactions')
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
@@ -310,7 +313,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
*/
|
||||
public function leftOnAccount(Account $account)
|
||||
{
|
||||
$balance = \Steam::balance($account, null, true);
|
||||
$balance = Steam::balance($account, null, true);
|
||||
/** @var PiggyBank $p */
|
||||
foreach ($account->piggybanks()->get() as $p) {
|
||||
$balance -= $p->currentRelevantRep()->currentamount;
|
||||
@@ -374,6 +377,8 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param array $data
|
||||
*
|
||||
* @return Account
|
||||
*/
|
||||
public function update(Account $account, array $data)
|
||||
{
|
||||
@@ -438,13 +443,20 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
|
||||
if (!$newAccount->isValid()) {
|
||||
// does the account already exist?
|
||||
$existingAccount = Account::where('user_id', $data['user'])->where('account_type_id', $accountType->id)->where('name', $data['name'])->first();
|
||||
$searchData = [
|
||||
'user_id' => $data['user'],
|
||||
'account_type_id' => $accountType->id,
|
||||
'name' => $data['name']
|
||||
];
|
||||
$existingAccount = Account::firstOrNullEncrypted($searchData);
|
||||
if (!$existingAccount) {
|
||||
Log::error('Account create error: ' . $newAccount->getErrors()->toJson());
|
||||
App::abort(500);
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
$newAccount = $existingAccount;
|
||||
|
||||
}
|
||||
$newAccount->save();
|
||||
|
||||
@@ -498,9 +510,6 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
'encrypted' => true
|
||||
]
|
||||
);
|
||||
if (!$journal->isValid()) {
|
||||
App::abort(500);
|
||||
}
|
||||
$journal->save();
|
||||
|
||||
|
||||
@@ -524,9 +533,6 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
'amount' => $firstAmount
|
||||
]
|
||||
);
|
||||
if (!$one->isValid()) {
|
||||
App::abort(500);
|
||||
}
|
||||
$one->save();
|
||||
|
||||
// second transaction: to
|
||||
@@ -537,9 +543,6 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
'amount' => $secondAmount
|
||||
]
|
||||
);
|
||||
if (!$two->isValid()) {
|
||||
App::abort(500);
|
||||
}
|
||||
$two->save();
|
||||
|
||||
return $journal;
|
||||
|
@@ -88,7 +88,7 @@ interface AccountRepositoryInterface
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param string $range
|
||||
* @param $page
|
||||
*
|
||||
* @return LengthAwarePaginator
|
||||
*/
|
||||
|
@@ -4,6 +4,7 @@ namespace FireflyIII\Repositories\Bill;
|
||||
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use DB;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Bill;
|
||||
@@ -119,7 +120,7 @@ class BillRepository implements BillRepositoryInterface
|
||||
*/
|
||||
public function getPossiblyRelatedJournals(Bill $bill)
|
||||
{
|
||||
$set = \DB::table('transactions')->where('amount', '>', 0)->where('amount', '>=', $bill->amount_min)->where('amount', '<=', $bill->amount_max)->get(
|
||||
$set = DB::table('transactions')->where('amount', '>', 0)->where('amount', '>=', $bill->amount_min)->where('amount', '<=', $bill->amount_max)->get(
|
||||
['transaction_journal_id']
|
||||
);
|
||||
$ids = [];
|
||||
@@ -211,10 +212,12 @@ class BillRepository implements BillRepositoryInterface
|
||||
* $today is the start of the next period, to make sure FF3 won't miss anything
|
||||
* when the current period has a transaction journal.
|
||||
*/
|
||||
$today = Navigation::addPeriod(new Carbon, $bill->repeat_freq, 0);
|
||||
/** @var \Carbon\Carbon $obj */
|
||||
$obj = new Carbon;
|
||||
$today = Navigation::addPeriod($obj, $bill->repeat_freq, 0);
|
||||
|
||||
$skip = $bill->skip + 1;
|
||||
$start = Navigation::startOfPeriod(new Carbon, $bill->repeat_freq);
|
||||
$start = Navigation::startOfPeriod($obj, $bill->repeat_freq);
|
||||
/*
|
||||
* go back exactly one month/week/etc because FF3 does not care about 'next'
|
||||
* bills if they're too far into the past.
|
||||
@@ -259,11 +262,8 @@ class BillRepository implements BillRepositoryInterface
|
||||
/*
|
||||
* Attach expense account to description for more narrow matching.
|
||||
*/
|
||||
if (count($journal->transactions) < 2) {
|
||||
$transactions = $journal->transactions()->get();
|
||||
} else {
|
||||
$transactions = $journal->transactions;
|
||||
}
|
||||
$transactions = $journal->transactions()->get();
|
||||
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($transactions as $transaction) {
|
||||
/** @var Account $account */
|
||||
|
@@ -10,6 +10,7 @@ use FireflyIII\Models\LimitRepetition;
|
||||
use Illuminate\Database\Query\Builder as QueryBuilder;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Collection;
|
||||
use Input;
|
||||
|
||||
/**
|
||||
* Class BudgetRepository
|
||||
@@ -24,21 +25,6 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
*/
|
||||
public function cleanupBudgets()
|
||||
{
|
||||
$limits = BudgetLimit::leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id')->get(['budget_limits.*']);
|
||||
|
||||
// loop budget limits:
|
||||
$found = [];
|
||||
/** @var BudgetLimit $limit */
|
||||
foreach ($limits as $limit) {
|
||||
$key = $limit->budget_id . '-' . $limit->startdate;
|
||||
if (isset($found[$key])) {
|
||||
$limit->delete();
|
||||
} else {
|
||||
$found[$key] = true;
|
||||
}
|
||||
unset($key);
|
||||
}
|
||||
|
||||
// delete limits with amount 0:
|
||||
BudgetLimit::where('amount', 0)->delete();
|
||||
|
||||
@@ -162,7 +148,7 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
*/
|
||||
public function getJournals(Budget $budget, LimitRepetition $repetition = null, $take = 50)
|
||||
{
|
||||
$offset = intval(\Input::get('page')) > 0 ? intval(\Input::get('page')) * $take : 0;
|
||||
$offset = intval(Input::get('page')) > 0 ? intval(Input::get('page')) * $take : 0;
|
||||
|
||||
|
||||
$setQuery = $budget->transactionJournals()->withRelevantData()->take($take)->offset($offset)
|
||||
@@ -260,13 +246,12 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
->whereNotNull('budget_transaction_journal.budget_id');
|
||||
}
|
||||
)
|
||||
->before($end)
|
||||
->after($start)
|
||||
->before($end)
|
||||
->lessThan(0)
|
||||
->transactionTypes(['Withdrawal'])
|
||||
->get();
|
||||
|
||||
return floatval($noBudgetSet->sum('amount')) * -1;
|
||||
->sum('transactions.amount');
|
||||
return floatval($noBudgetSet) * -1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -71,9 +71,9 @@ interface CategoryRepositoryInterface
|
||||
public function getWithoutCategory(Carbon $start, Carbon $end);
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Category $category
|
||||
* @param \Carbon\Carbon $start
|
||||
* @param \Carbon\Carbon $end
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
|
@@ -4,13 +4,17 @@ namespace FireflyIII\Repositories\Journal;
|
||||
|
||||
use App;
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use DB;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
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 Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
|
||||
@@ -22,6 +26,38 @@ use Log;
|
||||
class JournalRepository implements JournalRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param int $reminderId
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function deactivateReminder($reminderId)
|
||||
{
|
||||
$reminder = Auth::user()->reminders()->find($reminderId);
|
||||
if ($reminder) {
|
||||
$reminder->active = 0;
|
||||
$reminder->save();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function delete(TransactionJournal $journal)
|
||||
{
|
||||
// delete transactions first:
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($journal->transactions()->get() as $transaction) {
|
||||
$transaction->delete();
|
||||
}
|
||||
$journal->delete();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get users first transaction journal
|
||||
*
|
||||
@@ -33,33 +69,22 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Get the account_id, which is the asset account that paid for the transaction.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param Transaction $transaction
|
||||
*
|
||||
* @return mixed
|
||||
* @return float
|
||||
*/
|
||||
public function getAssetAccount(TransactionJournal $journal)
|
||||
public function getAmountBefore(TransactionJournal $journal, Transaction $transaction)
|
||||
{
|
||||
$positive = true; // the asset account is in the transaction with the positive amount.
|
||||
switch ($journal->transactionType->type) {
|
||||
case 'Withdrawal':
|
||||
$positive = false;
|
||||
break;
|
||||
}
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($journal->transactions()->get() as $transaction) {
|
||||
if (floatval($transaction->amount) > 0 && $positive === true) {
|
||||
return $transaction->account_id;
|
||||
}
|
||||
if (floatval($transaction->amount) < 0 && $positive === false) {
|
||||
return $transaction->account_id;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $journal->transactions()->first()->account_id;
|
||||
return floatval(
|
||||
$transaction->account->transactions()->leftJoin(
|
||||
'transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id'
|
||||
)
|
||||
->where('transaction_journals.date', '<=', $journal->date->format('Y-m-d'))
|
||||
->where('transaction_journals.order', '>=', $journal->order)
|
||||
->where('transaction_journals.id', '!=', $journal->id)
|
||||
->sum('transactions.amount')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,6 +97,28 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
return Auth::user()->transactionjournals()->where('transaction_type_id', $dbType->id)->orderBy('id', 'DESC')->take(50)->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $types
|
||||
* @param int $offset
|
||||
* @param int $page
|
||||
*
|
||||
* @return LengthAwarePaginator
|
||||
*/
|
||||
public function getJournalsOfTypes(array $types, $offset, $page)
|
||||
{
|
||||
$set = Auth::user()->transactionJournals()->transactionTypes($types)->withRelevantData()->take(50)->offset($offset)
|
||||
->orderBy('date', 'DESC')
|
||||
->orderBy('order', 'ASC')
|
||||
->orderBy('id', 'DESC')
|
||||
->get(
|
||||
['transaction_journals.*']
|
||||
);
|
||||
$count = Auth::user()->transactionJournals()->transactionTypes($types)->count();
|
||||
$journals = new LengthAwarePaginator($set, $count, 50, $page);
|
||||
|
||||
return $journals;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $type
|
||||
*
|
||||
@@ -83,55 +130,37 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param TransactionJournal $journal
|
||||
* @param $id
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return Collection
|
||||
* @return TransactionJournal
|
||||
*/
|
||||
public function searchRelated($query, TransactionJournal $journal)
|
||||
public function getWithDate($id, Carbon $date)
|
||||
{
|
||||
$start = clone $journal->date;
|
||||
$end = clone $journal->date;
|
||||
$start->startOfMonth();
|
||||
$end->endOfMonth();
|
||||
return Auth::user()->transactionjournals()->where('id', $id)->where('date', $date->format('Y-m-d 00:00:00'))->first();
|
||||
}
|
||||
|
||||
// get already related transactions:
|
||||
$exclude = [$journal->id];
|
||||
foreach ($journal->transactiongroups()->get() as $group) {
|
||||
foreach ($group->transactionjournals()->get() as $current) {
|
||||
$exclude[] = $current->id;
|
||||
/**
|
||||
*
|
||||
* * Remember: a balancingAct takes at most one expense and one transfer.
|
||||
* an advancePayment takes at most one expense, infinite deposits and NO transfers.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param array $array
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function saveTags(TransactionJournal $journal, array $array)
|
||||
{
|
||||
/** @var \FireflyIII\Repositories\Tag\TagRepositoryInterface $tagRepository */
|
||||
$tagRepository = App::make('FireflyIII\Repositories\Tag\TagRepositoryInterface');
|
||||
|
||||
foreach ($array as $name) {
|
||||
if (strlen(trim($name)) > 0) {
|
||||
$tag = Tag::firstOrCreateEncrypted(['tag' => $name, 'user_id' => $journal->user_id]);
|
||||
$tagRepository->connect($journal, $tag);
|
||||
}
|
||||
}
|
||||
$exclude = array_unique($exclude);
|
||||
|
||||
/** @var Collection $collection */
|
||||
$collection = Auth::user()->transactionjournals()
|
||||
->withRelevantData()
|
||||
->before($end)->after($start)->where('encrypted', 0)
|
||||
->whereNotIn('id', $exclude)
|
||||
->where('description', 'LIKE', '%' . $query . '%')
|
||||
->get();
|
||||
|
||||
// manually search encrypted entries:
|
||||
/** @var Collection $encryptedCollection */
|
||||
$encryptedCollection = Auth::user()->transactionjournals()
|
||||
->withRelevantData()
|
||||
->before($end)->after($start)
|
||||
->where('encrypted', 1)
|
||||
->whereNotIn('id', $exclude)
|
||||
->get();
|
||||
$encrypted = $encryptedCollection->filter(
|
||||
function (TransactionJournal $journal) use ($query) {
|
||||
$strPos = strpos(strtolower($journal->description), strtolower($query));
|
||||
if ($strPos !== false) {
|
||||
return $journal;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
);
|
||||
|
||||
return $collection->merge($encrypted);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -166,6 +195,7 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
|
||||
// store or get budget
|
||||
if (intval($data['budget_id']) > 0) {
|
||||
/** @var \FireflyIII\Models\Budget $budget */
|
||||
$budget = Budget::find($data['budget_id']);
|
||||
$journal->budgets()->save($budget);
|
||||
}
|
||||
@@ -191,6 +221,11 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
$journal->completed = 1;
|
||||
$journal->save();
|
||||
|
||||
// store tags
|
||||
if (isset($data['tags']) && is_array($data['tags'])) {
|
||||
$this->saveTags($journal, $data['tags']);
|
||||
}
|
||||
|
||||
return $journal;
|
||||
|
||||
|
||||
@@ -220,6 +255,7 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
// unlink all budgets and recreate them:
|
||||
$journal->budgets()->detach();
|
||||
if (intval($data['budget_id']) > 0) {
|
||||
/** @var \FireflyIII\Models\Budget $budget */
|
||||
$budget = Budget::find($data['budget_id']);
|
||||
$journal->budgets()->save($budget);
|
||||
}
|
||||
@@ -246,9 +282,54 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
|
||||
$journal->save();
|
||||
|
||||
// update tags:
|
||||
if (isset($data['tags']) && is_array($data['tags'])) {
|
||||
$this->updateTags($journal, $data['tags']);
|
||||
}
|
||||
|
||||
return $journal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
* @param array $array
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function updateTags(TransactionJournal $journal, array $array)
|
||||
{
|
||||
// create tag repository
|
||||
/** @var \FireflyIII\Repositories\Tag\TagRepositoryInterface $tagRepository */
|
||||
$tagRepository = App::make('FireflyIII\Repositories\Tag\TagRepositoryInterface');
|
||||
|
||||
|
||||
// find or create all tags:
|
||||
$tags = [];
|
||||
$ids = [];
|
||||
foreach ($array as $name) {
|
||||
if (strlen(trim($name)) > 0) {
|
||||
$tag = Tag::firstOrCreateEncrypted(['tag' => $name, 'user_id' => $journal->user_id]);
|
||||
$tags[] = $tag;
|
||||
$ids[] = $tag->id;
|
||||
}
|
||||
}
|
||||
|
||||
// delete all tags connected to journal not in this array:
|
||||
if (count($ids) > 0) {
|
||||
DB::table('tag_transaction_journal')->where('transaction_journal_id', $journal->id)->whereNotIn('tag_id', $ids)->delete();
|
||||
}
|
||||
// if count is zero, delete them all:
|
||||
if (count($ids) == 0) {
|
||||
DB::table('tag_transaction_journal')->where('transaction_journal_id', $journal->id)->delete();
|
||||
}
|
||||
|
||||
// connect each tag to journal (if not yet connected):
|
||||
/** @var Tag $tag */
|
||||
foreach ($tags as $tag) {
|
||||
$tagRepository->connect($journal, $tag);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionType $type
|
||||
* @param array $data
|
||||
@@ -298,14 +379,19 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
$to = Account::find($data['account_to_id']);
|
||||
break;
|
||||
}
|
||||
if (is_null($to->id)) {
|
||||
if (is_null($to) || (!is_null($to) && is_null($to->id))) {
|
||||
Log::error('"to"-account is null, so we cannot continue!');
|
||||
App::abort(500, '"to"-account is null, so we cannot continue!');
|
||||
// @codeCoverageIgnoreStart
|
||||
}
|
||||
if (is_null($from->id)) {
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
if (is_null($from) || (!is_null($from) && is_null($from->id))) {
|
||||
Log::error('"from"-account is null, so we cannot continue!');
|
||||
App::abort(500, '"from"-account is null, so we cannot continue!');
|
||||
// @codeCoverageIgnoreStart
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
return [$from, $to];
|
||||
}
|
||||
|
@@ -2,9 +2,11 @@
|
||||
|
||||
namespace FireflyIII\Repositories\Journal;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
@@ -14,6 +16,20 @@ use Illuminate\Support\Collection;
|
||||
*/
|
||||
interface JournalRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @param int $reminderId
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function deactivateReminder($reminderId);
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function delete(TransactionJournal $journal);
|
||||
|
||||
/**
|
||||
* Get users first transaction journal
|
||||
*
|
||||
@@ -22,14 +38,12 @@ interface JournalRepositoryInterface
|
||||
public function first();
|
||||
|
||||
/**
|
||||
*
|
||||
* Get the account_id, which is the asset account that paid for the transaction.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param Transaction $transaction
|
||||
*
|
||||
* @return int
|
||||
* @return float
|
||||
*/
|
||||
public function getAssetAccount(TransactionJournal $journal);
|
||||
public function getAmountBefore(TransactionJournal $journal, Transaction $transaction);
|
||||
|
||||
/**
|
||||
* @param TransactionType $dbType
|
||||
@@ -39,13 +53,13 @@ interface JournalRepositoryInterface
|
||||
public function getJournalsOfType(TransactionType $dbType);
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param TransactionJournal $journal
|
||||
* @param array $types
|
||||
* @param int $offset
|
||||
* @param int $page
|
||||
*
|
||||
* @return Collection
|
||||
* @return LengthAwarePaginator
|
||||
*/
|
||||
public function searchRelated($query, TransactionJournal $journal);
|
||||
|
||||
public function getJournalsOfTypes(array $types, $offset, $page);
|
||||
|
||||
/**
|
||||
* @param $type
|
||||
@@ -53,6 +67,30 @@ interface JournalRepositoryInterface
|
||||
* @return TransactionType
|
||||
*/
|
||||
public function getTransactionType($type);
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return TransactionJournal
|
||||
*/
|
||||
public function getWithDate($id, Carbon $date);
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
* @param array $array
|
||||
*
|
||||
* @return void
|
||||
|
||||
/**
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param array $array
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function saveTags(TransactionJournal $journal, array $array);
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
@@ -67,4 +105,12 @@ interface JournalRepositoryInterface
|
||||
* @return mixed
|
||||
*/
|
||||
public function update(TransactionJournal $journal, array $data);
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
* @param array $array
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function updateTags(TransactionJournal $journal, array $array);
|
||||
}
|
||||
|
@@ -21,7 +21,6 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
|
||||
|
||||
/**
|
||||
* @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
|
||||
*
|
||||
* Based on the piggy bank, the reminder-setting and
|
||||
* other variables this method tries to divide the piggy bank into equal parts. Each is
|
||||
@@ -140,26 +139,26 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
/** @var Collection $set */
|
||||
$set = Auth::user()->piggyBanks()->orderBy('order', 'ASC')->get();
|
||||
|
||||
$set->sortBy(
|
||||
function (PiggyBank $piggyBank) {
|
||||
return $piggyBank->name;
|
||||
}
|
||||
);
|
||||
|
||||
return $set;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set all piggy banks to order 0.
|
||||
*
|
||||
* @return void
|
||||
* @return boolean
|
||||
*/
|
||||
public function reset()
|
||||
{
|
||||
DB::table('piggy_banks')
|
||||
->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.id')
|
||||
->where('accounts.user_id', Auth::user()->id)
|
||||
->update(['order' => 0, 'piggy_banks.updated_at' => DB::Raw('NOW()')]);
|
||||
// split query to make it work in sqlite:
|
||||
$set = PiggyBank::
|
||||
leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.id')
|
||||
->where('accounts.user_id', Auth::user()->id)->get(['piggy_banks.*']);
|
||||
foreach ($set as $e) {
|
||||
$e->order = 0;
|
||||
$e->save();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -195,10 +194,11 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PiggyBank $account
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param array $data
|
||||
*
|
||||
* @return PiggyBank
|
||||
* @internal param PiggyBank $account
|
||||
*/
|
||||
public function update(PiggyBank $piggyBank, array $data)
|
||||
{
|
||||
|
@@ -15,7 +15,6 @@ interface PiggyBankRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
|
||||
*
|
||||
* Based on the piggy bank, the reminder-setting and
|
||||
* other variables this method tries to divide the piggy bank into equal parts. Each is
|
||||
@@ -95,7 +94,7 @@ interface PiggyBankRepositoryInterface
|
||||
public function store(array $data);
|
||||
|
||||
/**
|
||||
* @param PiggyBank $account
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param array $data
|
||||
*
|
||||
* @return PiggyBank
|
||||
|
@@ -9,6 +9,7 @@ use FireflyIII\Models\Reminder;
|
||||
/**
|
||||
* Class PiggyBankPart
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Collection
|
||||
*/
|
||||
class PiggyBankPart
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user