mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-26 21:43:53 +00:00 
			
		
		
		
	Compare commits
	
		
			255 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 50cf7f6a3b | ||
|  | eecb4db34c | ||
|  | 1f865d3ea4 | ||
|  | 623bb4b350 | ||
|  | dc8ad673a6 | ||
|  | 4914ad821e | ||
|  | f099cbadc3 | ||
|  | 42cda384c8 | ||
|  | 23c91b9990 | ||
|  | ff0379182e | ||
|  | e08a23948f | ||
|  | bd56de6d36 | ||
|  | 42970aea80 | ||
|  | 003a05ee8d | ||
|  | ffb11b01a6 | ||
|  | e426f5d5da | ||
|  | 6989f61e1b | ||
|  | 0e6677ccb3 | ||
|  | 8f104d555a | ||
|  | b1d3158db1 | ||
|  | 7645005d5a | ||
|  | 411f77fd29 | ||
|  | 568ab26db1 | ||
|  | 29652108f0 | ||
|  | f07e4dc711 | ||
|  | 8a2ac457c2 | ||
|  | 9e54eecfaa | ||
|  | 95ef691077 | ||
|  | 7a0ad5a587 | ||
|  | 42b49d0e4b | ||
|  | 9217c2f003 | ||
|  | fbdf66998d | ||
|  | deda9d3c54 | ||
|  | a5d78f20ae | ||
|  | 5ed09e3f38 | ||
|  | 3e9774cd66 | ||
|  | 54387c8fdf | ||
|  | 7eec949a13 | ||
|  | 4113c4ff40 | ||
|  | 1bf0968bfe | ||
|  | 374b90fb00 | ||
|  | 064e60e9d5 | ||
|  | b637455970 | ||
|  | 68158937d1 | ||
|  | adb1356b7a | ||
|  | d880ccb8e0 | ||
|  | 050fb1d1ef | ||
|  | 6580752bde | ||
|  | c9df265c9b | ||
|  | 098e5bc162 | ||
|  | 4b2dcc74d4 | ||
|  | a9254c5c9a | ||
|  | 7ce57e6ccb | ||
|  | 0fcb32a66f | ||
|  | 9946535f01 | ||
|  | 2b17396d6b | ||
|  | b01d5bc237 | ||
|  | b123860304 | ||
|  | 033f5b67db | ||
|  | 6280448dfb | ||
|  | 01cd3333e4 | ||
|  | 63050907b9 | ||
|  | beedf7d780 | ||
|  | 6b8194261f | ||
|  | dbb1c4d534 | ||
|  | e6263f9ff5 | ||
|  | 6ca119c4db | ||
|  | c483a1ab3a | ||
|  | 2e7edd033c | ||
|  | c576902501 | ||
|  | 66c2951594 | ||
|  | b812881cdb | ||
|  | cdeac2c6db | ||
|  | bca2ddd529 | ||
|  | e7285c6499 | ||
|  | bdff275672 | ||
|  | bec58a1ee6 | ||
|  | f64616748c | ||
|  | 512ce15973 | ||
|  | ed8b301574 | ||
|  | d22a6c019c | ||
|  | a0cb1b9d9e | ||
|  | a5294c62ea | ||
|  | e155d3311c | ||
|  | 0a372b0daf | ||
|  | 69143399d1 | ||
|  | 3270d3bf96 | ||
|  | 3896a66122 | ||
|  | b94781aef1 | ||
|  | bed1adc367 | ||
|  | ae54497efa | ||
|  | 06b747c221 | ||
|  | f159beee0d | ||
|  | 49d7dea086 | ||
|  | 3e65733dc5 | ||
|  | cc375d58bb | ||
|  | 911c7c662a | ||
|  | aae003be33 | ||
|  | aede03d8b2 | ||
|  | f0f5ada7de | ||
|  | 58365121a3 | ||
|  | d5a154d2e6 | ||
|  | b20f369aef | ||
|  | abb8aa0b29 | ||
|  | 5368a0f1d7 | ||
|  | d3897eece7 | ||
|  | a82b829da9 | ||
|  | 9f5058e81a | ||
|  | 5b19263720 | ||
|  | 9d5a0db0d9 | ||
|  | 4bd8a7014f | ||
|  | 353e96d951 | ||
|  | 149a6f92b0 | ||
|  | d66426c137 | ||
|  | 4fc9966392 | ||
|  | 417766f0db | ||
|  | de9ac97887 | ||
|  | 6be42f112a | ||
|  | 3895ae63c7 | ||
|  | 607d416d54 | ||
|  | 038693dc86 | ||
|  | cc9be13544 | ||
|  | 9c1474087f | ||
|  | 831de2bcf4 | ||
|  | eb687333bb | ||
|  | 5cc7966d54 | ||
|  | d1a34e7a6f | ||
|  | d63d791717 | ||
|  | 015570c741 | ||
|  | 8400ebc9c6 | ||
|  | 9f99e7c0af | ||
|  | 392c1fc399 | ||
|  | d3cea7a89c | ||
|  | 1dcf7407e6 | ||
|  | d543c033a3 | ||
|  | aaa186be5e | ||
|  | 2054b5b3dd | ||
|  | 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 | 
							
								
								
									
										18
									
								
								.env.backup
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								.env.backup
									
									
									
									
									
								
							| @@ -1,18 +0,0 @@ | |||||||
| APP_ENV=local |  | ||||||
| APP_DEBUG=true |  | ||||||
| APP_KEY=SomeRandomString |  | ||||||
|  |  | ||||||
| DB_CONNECTION=mysql |  | ||||||
| DB_HOST=localhost |  | ||||||
| DB_DATABASE=homestead |  | ||||||
| DB_USERNAME=homestead |  | ||||||
| DB_PASSWORD=secret |  | ||||||
|  |  | ||||||
| CACHE_DRIVER=file |  | ||||||
| SESSION_DRIVER=file |  | ||||||
|  |  | ||||||
| EMAIL_SMTP= |  | ||||||
| EMAIL_DRIVER=smtp |  | ||||||
| EMAIL_USERNAME= |  | ||||||
| EMAIL_PASSWORD= |  | ||||||
| ANALYTICS_ID= |  | ||||||
| @@ -15,4 +15,5 @@ EMAIL_SMTP= | |||||||
| EMAIL_DRIVER=smtp | EMAIL_DRIVER=smtp | ||||||
| EMAIL_USERNAME= | EMAIL_USERNAME= | ||||||
| EMAIL_PASSWORD= | EMAIL_PASSWORD= | ||||||
| ANALYTICS_ID= | ANALYTICS_ID= | ||||||
|  | EMAIL_PRETEND=false | ||||||
							
								
								
									
										18
									
								
								.env.local
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								.env.local
									
									
									
									
									
								
							| @@ -1,18 +0,0 @@ | |||||||
| APP_ENV=local |  | ||||||
| APP_DEBUG=true |  | ||||||
| APP_KEY=SomeRandomString |  | ||||||
|  |  | ||||||
| DB_CONNECTION=mysql |  | ||||||
| DB_HOST=localhost |  | ||||||
| DB_DATABASE=homestead |  | ||||||
| DB_USERNAME=homestead |  | ||||||
| DB_PASSWORD=secret |  | ||||||
|  |  | ||||||
| CACHE_DRIVER=file |  | ||||||
| SESSION_DRIVER=file |  | ||||||
|  |  | ||||||
| EMAIL_SMTP= |  | ||||||
| EMAIL_DRIVER=smtp |  | ||||||
| EMAIL_USERNAME= |  | ||||||
| EMAIL_PASSWORD= |  | ||||||
| ANALYTICS_ID= |  | ||||||
| @@ -8,10 +8,11 @@ DB_DATABASE=homestead | |||||||
| DB_USERNAME=homestead | DB_USERNAME=homestead | ||||||
| DB_PASSWORD=secret | DB_PASSWORD=secret | ||||||
|  |  | ||||||
| CACHE_DRIVER=file | CACHE_DRIVER=array | ||||||
| SESSION_DRIVER=file | SESSION_DRIVER=array | ||||||
|  |  | ||||||
| EMAIL_SMTP= | EMAIL_SMTP= | ||||||
| EMAIL_USERNAME= | EMAIL_USERNAME= | ||||||
| EMAIL_PASSWORD= | EMAIL_PASSWORD= | ||||||
| ANALYTICS_ID=ABC | ANALYTICS_ID=ABC | ||||||
|  | EMAIL_PRETEND=true | ||||||
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -29,3 +29,5 @@ clover.xml | |||||||
| node_modules/ | node_modules/ | ||||||
| addNewLines.php | addNewLines.php | ||||||
| .phpstorm.meta.php | .phpstorm.meta.php | ||||||
|  | .env.backup | ||||||
|  | .env.local | ||||||
|   | |||||||
| @@ -16,7 +16,7 @@ install: | |||||||
|   - mv -v .env.testing .env |   - mv -v .env.testing .env | ||||||
|  |  | ||||||
| script: | script: | ||||||
|   - phpunit --debug |   - phpunit | ||||||
|  |  | ||||||
| after_script: | after_script: | ||||||
|   - php vendor/bin/coveralls |   - php vendor/bin/coveralls | ||||||
|   | |||||||
							
								
								
									
										115
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										115
									
								
								README.md
									
									
									
									
									
								
							| @@ -1,82 +1,97 @@ | |||||||
| Firefly III (v3.4) | # Firefly III | ||||||
| =========== | #### v3.4.0.8 | ||||||
|  |  | ||||||
| [](https://travis-ci.org/JC5/firefly-iii) | [](https://travis-ci.org/JC5/firefly-iii) | ||||||
| [](http://stillmaintained.com/JC5/firefly-iii) | [](http://stillmaintained.com/JC5/firefly-iii) | ||||||
| [](https://insight.sensiolabs.com/projects/d44c7012-5f50-41ad-add8-8445330e4102) | [](https://insight.sensiolabs.com/projects/d44c7012-5f50-41ad-add8-8445330e4102) | ||||||
| [](https://codeclimate.com/github/JC5/firefly-iii) | [](https://codeclimate.com/github/JC5/firefly-iii) | ||||||
| [](https://coveralls.io/r/JC5/firefly-iii?branch=master) | [](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 | ||||||
| [](https://packagist.org/packages/grumpydictator/firefly-iii) |  | ||||||
|  |  | ||||||
| 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 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. | ||||||
| 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)**. |  | ||||||
|   |   | ||||||
| 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. | ||||||
|  |  | ||||||
| ## Current features | ## Current features | ||||||
|  |  | ||||||
| - [A double-entry bookkeeping system](https://en.wikipedia.org/wiki/Double-entry_bookkeeping_system); | - [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 | - You can manage different types of accounts; | ||||||
|   - Asset accounts |   - [Asset](https://en.wikipedia.org/wiki/Asset) accounts | ||||||
|   - Shared asset accounts (household accounts) |   - Shared [asset accounts](https://en.wikipedia.org/wiki/Asset) ([household accounts](https://en.wikipedia.org/wiki/Household)) | ||||||
|   - Saving accounts |   - Saving accounts | ||||||
|   - Credit cards |   - Credit cards | ||||||
| - It's possible to create, change and manage money using _[budgets](https://en.wikipedia.org/wiki/Envelope_system)_; | - It's possible to create, change and manage money using _[budgets](https://en.wikipedia.org/wiki/Envelope_system)_; | ||||||
| - Organize transactions using categories; | - Organize transactions using categories; | ||||||
| - Save towards a goal using piggy banks; | - Save towards a goal using [piggy banks](https://en.wikipedia.org/wiki/Piggy_bank); | ||||||
| - Predict and anticipate bills; | - Predict and anticipate [bills](https://en.wikipedia.org/wiki/Invoice); | ||||||
| - View income / expense reports; | - View income / expense [reports](https://en.wikipedia.org/wiki/Financial_statement); | ||||||
| - Lots of help text in case you don't get it; | - Organize expenses using tags; | ||||||
|  | - Lots of help text in case you don't get it. | ||||||
|  |  | ||||||
| Everything is organised: | Everything is organised: | ||||||
|  |  | ||||||
| - Clear views that should show you how you're doing; | - Clear views that should show you how you're doing; | ||||||
| - Easy navigation through your records; | - Easy navigation through your records; | ||||||
| - Browse back and forth to see previous months or even years; | - Browse back and forth to see previous months or even years; | ||||||
| - Lots of charts because we all love them. | - Lots of charts because we all love them; | ||||||
| - Financial reporting showing you how well you are doing; | - 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 | ## Screenshots | ||||||
|  |  | ||||||
|  | _Please note that everything in these screenshots is fictional and may not be realistic._ | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  | ## 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 state | ## 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 |  * Class Command | ||||||
|  * |  * | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  * @package FireflyIII\Commands |  * @package FireflyIII\Commands | ||||||
|  */ |  */ | ||||||
| abstract class Command | abstract class Command | ||||||
|   | |||||||
| @@ -6,6 +6,7 @@ use Illuminate\Foundation\Console\Kernel as ConsoleKernel; | |||||||
| /** | /** | ||||||
|  * Class Kernel |  * Class Kernel | ||||||
|  * |  * | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  * @package FireflyIII\Console |  * @package FireflyIII\Console | ||||||
|  */ |  */ | ||||||
| class Kernel extends ConsoleKernel | class Kernel extends ConsoleKernel | ||||||
| @@ -25,6 +26,8 @@ class Kernel extends ConsoleKernel | |||||||
|      * |      * | ||||||
|      * @param  \Illuminate\Console\Scheduling\Schedule $schedule |      * @param  \Illuminate\Console\Scheduling\Schedule $schedule | ||||||
|      * |      * | ||||||
|  |      * @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||||||
|  |      * | ||||||
|      * @return void |      * @return void | ||||||
|      */ |      */ | ||||||
|     protected function schedule(Schedule $schedule) |     protected function schedule(Schedule $schedule) | ||||||
|   | |||||||
| @@ -3,6 +3,7 @@ | |||||||
| /** | /** | ||||||
|  * Class Event |  * Class Event | ||||||
|  * |  * | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  * @package FireflyIII\Events |  * @package FireflyIII\Events | ||||||
|  */ |  */ | ||||||
| abstract class Event | abstract class Event | ||||||
|   | |||||||
| @@ -6,6 +6,7 @@ use Illuminate\Queue\SerializesModels; | |||||||
| /** | /** | ||||||
|  * Class JournalCreated |  * Class JournalCreated | ||||||
|  * |  * | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  * @package FireflyIII\Events |  * @package FireflyIII\Events | ||||||
|  */ |  */ | ||||||
| class JournalCreated extends Event | class JournalCreated extends Event | ||||||
| @@ -19,7 +20,8 @@ class JournalCreated extends Event | |||||||
|     /** |     /** | ||||||
|      * Create a new event instance. |      * Create a new event instance. | ||||||
|      * |      * | ||||||
|      * @return void |      * @param TransactionJournal $journal | ||||||
|  |      * @param                    $piggyBankId | ||||||
|      */ |      */ | ||||||
|     public function __construct(TransactionJournal $journal, $piggyBankId) |     public function __construct(TransactionJournal $journal, $piggyBankId) | ||||||
|     { |     { | ||||||
|   | |||||||
| @@ -2,6 +2,12 @@ | |||||||
|  |  | ||||||
| use Illuminate\Queue\SerializesModels; | use Illuminate\Queue\SerializesModels; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * Class JournalDeleted | ||||||
|  |  * | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  |  * @package FireflyIII\Events | ||||||
|  |  */ | ||||||
| class JournalDeleted extends Event | class JournalDeleted extends Event | ||||||
| { | { | ||||||
|  |  | ||||||
| @@ -10,7 +16,6 @@ class JournalDeleted extends Event | |||||||
|     /** |     /** | ||||||
|      * Create a new event instance. |      * Create a new event instance. | ||||||
|      * |      * | ||||||
|      * @return void |  | ||||||
|      */ |      */ | ||||||
|     public function __construct() |     public function __construct() | ||||||
|     { |     { | ||||||
|   | |||||||
| @@ -3,6 +3,12 @@ | |||||||
| use FireflyIII\Models\TransactionJournal; | use FireflyIII\Models\TransactionJournal; | ||||||
| use Illuminate\Queue\SerializesModels; | use Illuminate\Queue\SerializesModels; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * Class JournalSaved | ||||||
|  |  * | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  |  * @package FireflyIII\Events | ||||||
|  |  */ | ||||||
| class JournalSaved extends Event | class JournalSaved extends Event | ||||||
| { | { | ||||||
|  |  | ||||||
| @@ -13,7 +19,7 @@ class JournalSaved extends Event | |||||||
|     /** |     /** | ||||||
|      * Create a new event instance. |      * Create a new event instance. | ||||||
|      * |      * | ||||||
|      * @return void |      * @param TransactionJournal $journal | ||||||
|      */ |      */ | ||||||
|     public function __construct(TransactionJournal $journal) |     public function __construct(TransactionJournal $journal) | ||||||
|     { |     { | ||||||
|   | |||||||
| @@ -6,6 +6,7 @@ namespace FireflyIII\Exceptions; | |||||||
| /** | /** | ||||||
|  * Class FireflyException |  * Class FireflyException | ||||||
|  * |  * | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  * @package FireflyIII\Exceptions |  * @package FireflyIII\Exceptions | ||||||
|  */ |  */ | ||||||
| class FireflyException extends \Exception | class FireflyException extends \Exception | ||||||
|   | |||||||
| @@ -6,6 +6,7 @@ use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; | |||||||
| /** | /** | ||||||
|  * Class Handler |  * Class Handler | ||||||
|  * |  * | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  * @package FireflyIII\Exceptions |  * @package FireflyIII\Exceptions | ||||||
|  */ |  */ | ||||||
| class Handler extends ExceptionHandler | class Handler extends ExceptionHandler | ||||||
| @@ -26,6 +27,7 @@ class Handler extends ExceptionHandler | |||||||
|      * |      * | ||||||
|      * @param  \Illuminate\Http\Request $request |      * @param  \Illuminate\Http\Request $request | ||||||
|      * @param  \Exception               $e |      * @param  \Exception               $e | ||||||
|  |      * @SuppressWarnings(PHPMD.ShortVariable) | ||||||
|      * |      * | ||||||
|      * @return \Illuminate\Http\Response |      * @return \Illuminate\Http\Response | ||||||
|      */ |      */ | ||||||
| @@ -42,6 +44,7 @@ class Handler extends ExceptionHandler | |||||||
|      * Report or log an exception. |      * Report or log an exception. | ||||||
|      * |      * | ||||||
|      * This is a great spot to send exceptions to Sentry, Bugsnag, etc. |      * This is a great spot to send exceptions to Sentry, Bugsnag, etc. | ||||||
|  |      * @SuppressWarnings(PHPMD.ShortVariable) | ||||||
|      * |      * | ||||||
|      * @param  \Exception $e |      * @param  \Exception $e | ||||||
|      * |      * | ||||||
| @@ -49,8 +52,7 @@ class Handler extends ExceptionHandler | |||||||
|      */ |      */ | ||||||
|     public function report(Exception $e) |     public function report(Exception $e) | ||||||
|     { |     { | ||||||
|         /** @noinspection PhpInconsistentReturnPointsInspection */ |         parent::report($e); | ||||||
|         return parent::report($e); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -5,6 +5,7 @@ namespace FireflyIII\Exceptions; | |||||||
| /** | /** | ||||||
|  * Class NotImplementedException |  * Class NotImplementedException | ||||||
|  * |  * | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  * @package FireflyIII\Exceptions |  * @package FireflyIII\Exceptions | ||||||
|  */ |  */ | ||||||
| class NotImplementedException extends \Exception | class NotImplementedException extends \Exception | ||||||
|   | |||||||
| @@ -4,6 +4,7 @@ namespace FireflyIII\Exceptions; | |||||||
| /** | /** | ||||||
|  * Class ValidationExceptions |  * Class ValidationExceptions | ||||||
|  * |  * | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  * @package FireflyIII\Exception |  * @package FireflyIII\Exception | ||||||
|  */ |  */ | ||||||
| class ValidationException extends \Exception | class ValidationException extends \Exception | ||||||
|   | |||||||
| @@ -6,7 +6,6 @@ use FireflyIII\Models\PiggyBank; | |||||||
| use FireflyIII\Models\PiggyBankEvent; | use FireflyIII\Models\PiggyBankEvent; | ||||||
| use FireflyIII\Models\Transaction; | use FireflyIII\Models\Transaction; | ||||||
| use FireflyIII\Models\TransactionJournal; | use FireflyIII\Models\TransactionJournal; | ||||||
| use Log; |  | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Class ConnectJournalToPiggyBank |  * Class ConnectJournalToPiggyBank | ||||||
| @@ -19,7 +18,6 @@ class ConnectJournalToPiggyBank | |||||||
|     /** |     /** | ||||||
|      * Create the event handler. |      * Create the event handler. | ||||||
|      * |      * | ||||||
|      * @return void |  | ||||||
|      */ |      */ | ||||||
|     public function __construct() |     public function __construct() | ||||||
|     { |     { | ||||||
| @@ -29,54 +27,36 @@ class ConnectJournalToPiggyBank | |||||||
|     /** |     /** | ||||||
|      * Handle the event when journal is saved. |      * Handle the event when journal is saved. | ||||||
|      * |      * | ||||||
|  |      * @SuppressWarnings(PHPMD.CyclomaticComplexity) | ||||||
|  |      * | ||||||
|      * @param  JournalCreated $event |      * @param  JournalCreated $event | ||||||
|      * |      * | ||||||
|      * @return void |      * @return boolean | ||||||
|      */ |      */ | ||||||
|     public function handle(JournalCreated $event) |     public function handle(JournalCreated $event) | ||||||
|     { |     { | ||||||
|         /** @var TransactionJournal $journal */ |         /** @var TransactionJournal $journal */ | ||||||
|         $journal     = $event->journal; |         $journal     = $event->journal; | ||||||
|         $piggyBankId = $event->piggyBankId; |         $piggyBankId = $event->piggyBankId; | ||||||
|         if (intval($piggyBankId) < 1) { |  | ||||||
|             return; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         Log::debug('JournalCreated event: ' . $journal->id . ', ' . $piggyBankId); |  | ||||||
|  |  | ||||||
|         /** @var PiggyBank $piggyBank */ |         /** @var PiggyBank $piggyBank */ | ||||||
|         $piggyBank = Auth::user()->piggybanks()->where('piggy_banks.id', $piggyBankId)->first(['piggy_banks.*']); |         $piggyBank = Auth::user()->piggybanks()->where('piggy_banks.id', $piggyBankId)->first(['piggy_banks.*']); | ||||||
|  |  | ||||||
|         if (is_null($piggyBank) || $journal->transactionType->type != 'Transfer') { |         if (is_null($piggyBank)) { | ||||||
|             return; |             return false; | ||||||
|         } |  | ||||||
|         Log::debug('Found a piggy bank'); |  | ||||||
|         $amount = $journal->amount; |  | ||||||
|         Log::debug('Amount: ' . $amount); |  | ||||||
|         if ($amount == 0) { |  | ||||||
|             return; |  | ||||||
|         } |         } | ||||||
|         // update piggy bank rep for date of transaction journal. |         // update piggy bank rep for date of transaction journal. | ||||||
|         $repetition = $piggyBank->piggyBankRepetitions()->relevantOnDate($journal->date)->first(); |         $repetition = $piggyBank->piggyBankRepetitions()->relevantOnDate($journal->date)->first(); | ||||||
|         if (is_null($repetition)) { |         if (is_null($repetition)) { | ||||||
|             Log::debug('Found no repetition for piggy bank for date ' . $journal->date->format('Y M d')); |             return false; | ||||||
|  |  | ||||||
|             return; |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         Log::debug('Found rep! ' . $repetition->id); |         $amount = $journal->amount; | ||||||
|  |  | ||||||
|         /* |  | ||||||
|          * Add amount when |  | ||||||
|          */ |  | ||||||
|         /** @var Transaction $transaction */ |         /** @var Transaction $transaction */ | ||||||
|         foreach ($journal->transactions()->get() as $transaction) { |         foreach ($journal->transactions()->get() as $transaction) { | ||||||
|             if ($transaction->account_id == $piggyBank->account_id) { |             if ($transaction->account_id == $piggyBank->account_id) { | ||||||
|                 if ($transaction->amount < 0) { |                 if ($transaction->amount < 0) { | ||||||
|                     $amount = $amount * -1; |                     $amount = $transaction->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); |  | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| @@ -84,14 +64,9 @@ class ConnectJournalToPiggyBank | |||||||
|         $repetition->currentamount += $amount; |         $repetition->currentamount += $amount; | ||||||
|         $repetition->save(); |         $repetition->save(); | ||||||
|  |  | ||||||
|         PiggyBankEvent::create( |         PiggyBankEvent::create(['piggy_bank_id' => $piggyBank->id, 'transaction_journal_id' => $journal->id, 'date' => $journal->date, 'amount' => $amount]); | ||||||
|             [ |  | ||||||
|                 'piggy_bank_id'          => $piggyBank->id, |         return true; | ||||||
|                 'transaction_journal_id' => $journal->id, |  | ||||||
|                 'date'                   => $journal->date, |  | ||||||
|                 'amount'                 => $amount |  | ||||||
|             ] |  | ||||||
|         ); |  | ||||||
|  |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,35 +0,0 @@ | |||||||
| <?php namespace FireflyIII\Handlers\Events; |  | ||||||
|  |  | ||||||
| use FireflyIII\Events\JournalDeleted; |  | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * Class JournalDeletedHandler |  | ||||||
|  * |  | ||||||
|  * @package FireflyIII\Handlers\Events |  | ||||||
|  */ |  | ||||||
| class JournalDeletedHandler |  | ||||||
| { |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Create the event handler. |  | ||||||
|      * |  | ||||||
|      */ |  | ||||||
|     public function __construct() |  | ||||||
|     { |  | ||||||
|         // |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Handle the event. |  | ||||||
|      * |  | ||||||
|      * @param  JournalDeleted $event |  | ||||||
|      * |  | ||||||
|      * @return void |  | ||||||
|      */ |  | ||||||
|     public function handle(JournalDeleted $event) |  | ||||||
|     { |  | ||||||
|         // |  | ||||||
|  |  | ||||||
|     } |  | ||||||
|  |  | ||||||
| } |  | ||||||
| @@ -7,6 +7,7 @@ use Log; | |||||||
| /** | /** | ||||||
|  * Class RescanJournal |  * Class RescanJournal | ||||||
|  * |  * | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  * @package FireflyIII\Handlers\Events |  * @package FireflyIII\Handlers\Events | ||||||
|  */ |  */ | ||||||
| class RescanJournal | class RescanJournal | ||||||
| @@ -15,7 +16,6 @@ class RescanJournal | |||||||
|     /** |     /** | ||||||
|      * Create the event handler. |      * Create the event handler. | ||||||
|      * |      * | ||||||
|      * @return void |  | ||||||
|      */ |      */ | ||||||
|     public function __construct() |     public function __construct() | ||||||
|     { |     { | ||||||
| @@ -41,7 +41,7 @@ class RescanJournal | |||||||
|  |  | ||||||
|         Log::debug('Found ' . $list->count() . ' bills to check.'); |         Log::debug('Found ' . $list->count() . ' bills to check.'); | ||||||
|  |  | ||||||
|         /** @var Bill $bill */ |         /** @var \FireflyIII\Models\Bill $bill */ | ||||||
|         foreach ($list as $bill) { |         foreach ($list as $bill) { | ||||||
|             Log::debug('Now calling bill #' . $bill->id . ' (' . $bill->name . ')'); |             Log::debug('Now calling bill #' . $bill->id . ' (' . $bill->name . ')'); | ||||||
|             $repository->scan($bill, $journal); |             $repository->scan($bill, $journal); | ||||||
|   | |||||||
| @@ -2,11 +2,12 @@ | |||||||
|  |  | ||||||
| use FireflyIII\Events\JournalSaved; | use FireflyIII\Events\JournalSaved; | ||||||
| use FireflyIII\Models\PiggyBankEvent; | use FireflyIII\Models\PiggyBankEvent; | ||||||
| use FireflyIII\Models\Transaction; | use FireflyIII\Models\PiggyBankRepetition; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Class UpdateJournalConnection |  * Class UpdateJournalConnection | ||||||
|  * |  * | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  * @package FireflyIII\Handlers\Events |  * @package FireflyIII\Handlers\Events | ||||||
|  */ |  */ | ||||||
| class UpdateJournalConnection | class UpdateJournalConnection | ||||||
| @@ -15,7 +16,6 @@ class UpdateJournalConnection | |||||||
|     /** |     /** | ||||||
|      * Create the event handler. |      * Create the event handler. | ||||||
|      * |      * | ||||||
|      * @return void |  | ||||||
|      */ |      */ | ||||||
|     public function __construct() |     public function __construct() | ||||||
|     { |     { | ||||||
| @@ -40,7 +40,11 @@ class UpdateJournalConnection | |||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|         $piggyBank  = $event->piggyBank()->first(); |         $piggyBank  = $event->piggyBank()->first(); | ||||||
|         $repetition = $piggyBank->piggyBankRepetitions()->relevantOnDate($journal->date)->first(); |         $repetition = null; | ||||||
|  |         if ($piggyBank) { | ||||||
|  |             /** @var PiggyBankRepetition $repetition */ | ||||||
|  |             $repetition = $piggyBank->piggyBankRepetitions()->relevantOnDate($journal->date)->first(); | ||||||
|  |         } | ||||||
|  |  | ||||||
|         if (is_null($repetition)) { |         if (is_null($repetition)) { | ||||||
|             return; |             return; | ||||||
|   | |||||||
							
								
								
									
										90
									
								
								app/Helpers/Collection/Account.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										90
									
								
								app/Helpers/Collection/Account.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,90 @@ | |||||||
|  | <?php | ||||||
|  |  | ||||||
|  | namespace FireflyIII\Helpers\Collection; | ||||||
|  |  | ||||||
|  | use Illuminate\Support\Collection; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  |  * Class Account | ||||||
|  |  * | ||||||
|  |  * @package FireflyIII\Helpers\Collection | ||||||
|  |  */ | ||||||
|  | class Account | ||||||
|  | { | ||||||
|  |  | ||||||
|  |     /** @var Collection */ | ||||||
|  |     protected $accounts; | ||||||
|  |     /** @var float */ | ||||||
|  |     protected $difference; | ||||||
|  |     /** @var float */ | ||||||
|  |     protected $end; | ||||||
|  |     /** @var float */ | ||||||
|  |     protected $start; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @return \Illuminate\Support\Collection | ||||||
|  |      */ | ||||||
|  |     public function getAccounts() | ||||||
|  |     { | ||||||
|  |         return $this->accounts; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param \Illuminate\Support\Collection $accounts | ||||||
|  |      */ | ||||||
|  |     public function setAccounts($accounts) | ||||||
|  |     { | ||||||
|  |         $this->accounts = $accounts; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @return float | ||||||
|  |      */ | ||||||
|  |     public function getDifference() | ||||||
|  |     { | ||||||
|  |         return $this->difference; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param float $difference | ||||||
|  |      */ | ||||||
|  |     public function setDifference($difference) | ||||||
|  |     { | ||||||
|  |         $this->difference = $difference; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @return float | ||||||
|  |      */ | ||||||
|  |     public function getEnd() | ||||||
|  |     { | ||||||
|  |         return $this->end; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param float $end | ||||||
|  |      */ | ||||||
|  |     public function setEnd($end) | ||||||
|  |     { | ||||||
|  |         $this->end = $end; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @return float | ||||||
|  |      */ | ||||||
|  |     public function getStart() | ||||||
|  |     { | ||||||
|  |         return $this->start; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param float $start | ||||||
|  |      */ | ||||||
|  |     public function setStart($start) | ||||||
|  |     { | ||||||
|  |         $this->start = $start; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | } | ||||||
							
								
								
									
										64
									
								
								app/Helpers/Collection/Balance.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										64
									
								
								app/Helpers/Collection/Balance.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,64 @@ | |||||||
|  | <?php | ||||||
|  |  | ||||||
|  | namespace FireflyIII\Helpers\Collection; | ||||||
|  |  | ||||||
|  | use Illuminate\Support\Collection; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  |  * | ||||||
|  |  * Class Balance | ||||||
|  |  * | ||||||
|  |  * @package FireflyIII\Helpers\Collection | ||||||
|  |  */ | ||||||
|  | class Balance | ||||||
|  | { | ||||||
|  |  | ||||||
|  |     /** @var  BalanceHeader */ | ||||||
|  |     protected $balanceHeader; | ||||||
|  |  | ||||||
|  |     /** @var  Collection */ | ||||||
|  |     protected $balanceLines; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * | ||||||
|  |      */ | ||||||
|  |     public function __construct() | ||||||
|  |     { | ||||||
|  |         $this->balanceLines = new Collection; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param BalanceLine $line | ||||||
|  |      */ | ||||||
|  |     public function addBalanceLine(BalanceLine $line) | ||||||
|  |     { | ||||||
|  |         $this->balanceLines->push($line); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @return BalanceHeader | ||||||
|  |      */ | ||||||
|  |     public function getBalanceHeader() | ||||||
|  |     { | ||||||
|  |         return $this->balanceHeader; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param BalanceHeader $balanceHeader | ||||||
|  |      */ | ||||||
|  |     public function setBalanceHeader($balanceHeader) | ||||||
|  |     { | ||||||
|  |         $this->balanceHeader = $balanceHeader; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @return \Illuminate\Support\Collection | ||||||
|  |      */ | ||||||
|  |     public function getBalanceLines() | ||||||
|  |     { | ||||||
|  |         return $this->balanceLines; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | } | ||||||
							
								
								
									
										74
									
								
								app/Helpers/Collection/BalanceEntry.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										74
									
								
								app/Helpers/Collection/BalanceEntry.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,74 @@ | |||||||
|  | <?php | ||||||
|  |  | ||||||
|  | namespace FireflyIII\Helpers\Collection; | ||||||
|  |  | ||||||
|  | use FireflyIII\Models\Account as AccountModel; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  |  * | ||||||
|  |  * Class BalanceEntry | ||||||
|  |  * | ||||||
|  |  * @package FireflyIII\Helpers\Collection | ||||||
|  |  */ | ||||||
|  | class BalanceEntry | ||||||
|  | { | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     /** @var  AccountModel */ | ||||||
|  |     protected $account; | ||||||
|  |     /** @var float */ | ||||||
|  |     protected $left = 0.0; | ||||||
|  |     /** @var float */ | ||||||
|  |     protected $spent = 0.0; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @return AccountModel | ||||||
|  |      */ | ||||||
|  |     public function getAccount() | ||||||
|  |     { | ||||||
|  |         return $this->account; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param AccountModel $account | ||||||
|  |      */ | ||||||
|  |     public function setAccount($account) | ||||||
|  |     { | ||||||
|  |         $this->account = $account; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @return float | ||||||
|  |      */ | ||||||
|  |     public function getLeft() | ||||||
|  |     { | ||||||
|  |         return $this->left; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param float $left | ||||||
|  |      */ | ||||||
|  |     public function setLeft($left) | ||||||
|  |     { | ||||||
|  |         $this->left = $left; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @return float | ||||||
|  |      */ | ||||||
|  |     public function getSpent() | ||||||
|  |     { | ||||||
|  |         return $this->spent; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param float $spent | ||||||
|  |      */ | ||||||
|  |     public function setSpent($spent) | ||||||
|  |     { | ||||||
|  |         $this->spent = $spent; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | } | ||||||
							
								
								
									
										46
									
								
								app/Helpers/Collection/BalanceHeader.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								app/Helpers/Collection/BalanceHeader.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,46 @@ | |||||||
|  | <?php | ||||||
|  |  | ||||||
|  | namespace FireflyIII\Helpers\Collection; | ||||||
|  |  | ||||||
|  | use FireflyIII\Models\Account as AccountModel; | ||||||
|  | use Illuminate\Support\Collection; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  |  * | ||||||
|  |  * Class BalanceHeader | ||||||
|  |  * | ||||||
|  |  * @package FireflyIII\Helpers\Collection | ||||||
|  |  */ | ||||||
|  | class BalanceHeader | ||||||
|  | { | ||||||
|  |  | ||||||
|  |     /** @var  Collection */ | ||||||
|  |     protected $accounts; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * | ||||||
|  |      */ | ||||||
|  |     public function __construct() | ||||||
|  |     { | ||||||
|  |         $this->accounts = new Collection; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param AccountModel $account | ||||||
|  |      */ | ||||||
|  |     public function addAccount(AccountModel $account) | ||||||
|  |     { | ||||||
|  |         $this->accounts->push($account); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @return Collection | ||||||
|  |      */ | ||||||
|  |     public function getAccounts() | ||||||
|  |     { | ||||||
|  |         return $this->accounts; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | } | ||||||
							
								
								
									
										170
									
								
								app/Helpers/Collection/BalanceLine.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										170
									
								
								app/Helpers/Collection/BalanceLine.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,170 @@ | |||||||
|  | <?php | ||||||
|  |  | ||||||
|  | namespace FireflyIII\Helpers\Collection; | ||||||
|  |  | ||||||
|  | use FireflyIII\Models\Budget as BudgetModel; | ||||||
|  | use FireflyIII\Models\LimitRepetition; | ||||||
|  | use Illuminate\Support\Collection; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  |  * | ||||||
|  |  * Class BalanceLine | ||||||
|  |  * | ||||||
|  |  * @package FireflyIII\Helpers\Collection | ||||||
|  |  */ | ||||||
|  | class BalanceLine | ||||||
|  | { | ||||||
|  |  | ||||||
|  |     const ROLE_DEFAULTROLE = 1; | ||||||
|  |     const ROLE_TAGROLE     = 2; | ||||||
|  |     const ROLE_DIFFROLE    = 3; | ||||||
|  |  | ||||||
|  |     /** @var  Collection */ | ||||||
|  |     protected $balanceEntries; | ||||||
|  |  | ||||||
|  |     /** @var BudgetModel */ | ||||||
|  |     protected $budget; | ||||||
|  |  | ||||||
|  |     /** @var  LimitRepetition */ | ||||||
|  |     protected $repetition; | ||||||
|  |  | ||||||
|  |     protected $role = self::ROLE_DEFAULTROLE; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * | ||||||
|  |      */ | ||||||
|  |     public function __construct() | ||||||
|  |     { | ||||||
|  |         $this->balanceEntries = new Collection; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param BalanceEntry $balanceEntry | ||||||
|  |      */ | ||||||
|  |     public function addBalanceEntry(BalanceEntry $balanceEntry) | ||||||
|  |     { | ||||||
|  |         $this->balanceEntries->push($balanceEntry); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @return string | ||||||
|  |      */ | ||||||
|  |     public function getTitle() | ||||||
|  |     { | ||||||
|  |         if ($this->getBudget() instanceof BudgetModel) { | ||||||
|  |             return $this->getBudget()->name; | ||||||
|  |         } | ||||||
|  |         if ($this->getRole() == self::ROLE_DEFAULTROLE) { | ||||||
|  |             return trans('firefly.noBudget'); | ||||||
|  |         } | ||||||
|  |         if ($this->getRole() == self::ROLE_TAGROLE) { | ||||||
|  |             return trans('firefly.coveredWithTags'); | ||||||
|  |         } | ||||||
|  |         if ($this->getRole() == self::ROLE_DIFFROLE) { | ||||||
|  |             return trans('firefly.leftUnbalanced'); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @return BudgetModel | ||||||
|  |      */ | ||||||
|  |     public function getBudget() | ||||||
|  |     { | ||||||
|  |         return $this->budget; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param BudgetModel $budget | ||||||
|  |      */ | ||||||
|  |     public function setBudget($budget) | ||||||
|  |     { | ||||||
|  |         $this->budget = $budget; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @return int | ||||||
|  |      */ | ||||||
|  |     public function getRole() | ||||||
|  |     { | ||||||
|  |         return $this->role; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param int $role | ||||||
|  |      */ | ||||||
|  |     public function setRole($role) | ||||||
|  |     { | ||||||
|  |         $this->role = $role; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * If a BalanceLine has a budget/repetition, each BalanceEntry in this BalanceLine | ||||||
|  |      * should have a "spent" value, which is the amount of money that has been spent | ||||||
|  |      * on the given budget/repetition. If you subtract all those amounts from the budget/repetition's | ||||||
|  |      * total amount, this is returned: | ||||||
|  |      * | ||||||
|  |      * @return float | ||||||
|  |      */ | ||||||
|  |     public function leftOfRepetition() | ||||||
|  |     { | ||||||
|  |         $start = $this->getRepetition() ? $this->getRepetition()->amount : 0; | ||||||
|  |         /** @var BalanceEntry $balanceEntry */ | ||||||
|  |         foreach ($this->getBalanceEntries() as $balanceEntry) { | ||||||
|  |             $start += $balanceEntry->getSpent(); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return $start; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @return LimitRepetition | ||||||
|  |      */ | ||||||
|  |     public function getRepetition() | ||||||
|  |     { | ||||||
|  |         return $this->repetition; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param LimitRepetition $repetition | ||||||
|  |      */ | ||||||
|  |     public function setRepetition($repetition) | ||||||
|  |     { | ||||||
|  |         $this->repetition = $repetition; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @return Collection | ||||||
|  |      */ | ||||||
|  |     public function getBalanceEntries() | ||||||
|  |     { | ||||||
|  |         return $this->balanceEntries; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param Collection $balanceEntries | ||||||
|  |      */ | ||||||
|  |     public function setBalanceEntries($balanceEntries) | ||||||
|  |     { | ||||||
|  |         $this->balanceEntries = $balanceEntries; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * If the BalanceEntries for a BalanceLine have a "left" value, the amount | ||||||
|  |      * of money left in the entire BalanceLine is returned here: | ||||||
|  |      * | ||||||
|  |      * @return float | ||||||
|  |      */ | ||||||
|  |     public function sumOfLeft() | ||||||
|  |     { | ||||||
|  |         $sum = 0.0; | ||||||
|  |         /** @var BalanceEntry $balanceEntry */ | ||||||
|  |         foreach ($this->getBalanceEntries() as $balanceEntry) { | ||||||
|  |             $sum += $balanceEntry->getLeft(); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return $sum; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | } | ||||||
							
								
								
									
										57
									
								
								app/Helpers/Collection/Bill.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								app/Helpers/Collection/Bill.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,57 @@ | |||||||
|  | <?php | ||||||
|  |  | ||||||
|  | namespace FireflyIII\Helpers\Collection; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | use FireflyIII\Models\Bill as BillModel; | ||||||
|  | use Illuminate\Support\Collection; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  |  * Class Bill | ||||||
|  |  * | ||||||
|  |  * @package FireflyIII\Helpers\Collection | ||||||
|  |  */ | ||||||
|  | class Bill | ||||||
|  | { | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @var Collection | ||||||
|  |      */ | ||||||
|  |     protected $bills; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * | ||||||
|  |      */ | ||||||
|  |     public function __construct() | ||||||
|  |     { | ||||||
|  |         $this->bills = new Collection; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param BillLine $bill | ||||||
|  |      */ | ||||||
|  |     public function addBill(BillLine $bill) | ||||||
|  |     { | ||||||
|  |         $this->bills->push($bill); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @return Collection | ||||||
|  |      */ | ||||||
|  |     public function getBills() | ||||||
|  |     { | ||||||
|  |         $this->bills->sortBy( | ||||||
|  |             function (BillLine $bill) { | ||||||
|  |                 $active = intval($bill->getBill()->active) == 0 ? 1 : 0; | ||||||
|  |                 $name   = $bill->getBill()->name; | ||||||
|  |  | ||||||
|  |                 return $active . $name; | ||||||
|  |             } | ||||||
|  |         ); | ||||||
|  |  | ||||||
|  |  | ||||||
|  |         return $this->bills; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  | } | ||||||
							
								
								
									
										127
									
								
								app/Helpers/Collection/BillLine.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										127
									
								
								app/Helpers/Collection/BillLine.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,127 @@ | |||||||
|  | <?php | ||||||
|  |  | ||||||
|  | namespace FireflyIII\Helpers\Collection; | ||||||
|  |  | ||||||
|  | use FireflyIII\Models\Bill as BillModel; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  |  * | ||||||
|  |  * Class BillLine | ||||||
|  |  * | ||||||
|  |  * @package FireflyIII\Helpers\Collection | ||||||
|  |  */ | ||||||
|  | class BillLine | ||||||
|  | { | ||||||
|  |  | ||||||
|  |     /** @var  bool */ | ||||||
|  |     protected $active; | ||||||
|  |     /** @var  float */ | ||||||
|  |     protected $amount; | ||||||
|  |     /** @var  BillModel */ | ||||||
|  |     protected $bill; | ||||||
|  |     /** @var  bool */ | ||||||
|  |     protected $hit; | ||||||
|  |     /** @var  float */ | ||||||
|  |     protected $max; | ||||||
|  |     /** @var  float */ | ||||||
|  |     protected $min; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @return float | ||||||
|  |      */ | ||||||
|  |     public function getAmount() | ||||||
|  |     { | ||||||
|  |         return $this->amount; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param float $amount | ||||||
|  |      */ | ||||||
|  |     public function setAmount($amount) | ||||||
|  |     { | ||||||
|  |         $this->amount = $amount; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @return BillModel | ||||||
|  |      */ | ||||||
|  |     public function getBill() | ||||||
|  |     { | ||||||
|  |         return $this->bill; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param BillModel $bill | ||||||
|  |      */ | ||||||
|  |     public function setBill($bill) | ||||||
|  |     { | ||||||
|  |         $this->bill = $bill; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @return float | ||||||
|  |      */ | ||||||
|  |     public function getMax() | ||||||
|  |     { | ||||||
|  |         return $this->max; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param float $max | ||||||
|  |      */ | ||||||
|  |     public function setMax($max) | ||||||
|  |     { | ||||||
|  |         $this->max = $max; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @return float | ||||||
|  |      */ | ||||||
|  |     public function getMin() | ||||||
|  |     { | ||||||
|  |         return $this->min; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param float $min | ||||||
|  |      */ | ||||||
|  |     public function setMin($min) | ||||||
|  |     { | ||||||
|  |         $this->min = $min; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @return boolean | ||||||
|  |      */ | ||||||
|  |     public function isActive() | ||||||
|  |     { | ||||||
|  |         return $this->active; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param boolean $active | ||||||
|  |      */ | ||||||
|  |     public function setActive($active) | ||||||
|  |     { | ||||||
|  |         $this->active = $active; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @return boolean | ||||||
|  |      */ | ||||||
|  |     public function isHit() | ||||||
|  |     { | ||||||
|  |         return $this->hit; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param boolean $hit | ||||||
|  |      */ | ||||||
|  |     public function setHit($hit) | ||||||
|  |     { | ||||||
|  |         $this->hit = $hit; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | } | ||||||
							
								
								
									
										148
									
								
								app/Helpers/Collection/Budget.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										148
									
								
								app/Helpers/Collection/Budget.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,148 @@ | |||||||
|  | <?php | ||||||
|  |  | ||||||
|  | namespace FireflyIII\Helpers\Collection; | ||||||
|  |  | ||||||
|  | use Illuminate\Support\Collection; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  |  * | ||||||
|  |  * Class Budget | ||||||
|  |  * | ||||||
|  |  * @package FireflyIII\Helpers\Collection | ||||||
|  |  */ | ||||||
|  | class Budget | ||||||
|  | { | ||||||
|  |     /** @var  Collection */ | ||||||
|  |     protected $budgetLines; | ||||||
|  |     /** @var float */ | ||||||
|  |     protected $budgeted = 0; | ||||||
|  |     /** @var float */ | ||||||
|  |     protected $left = 0; | ||||||
|  |     /** @var float */ | ||||||
|  |     protected $overspent = 0; | ||||||
|  |     /** @var float */ | ||||||
|  |     protected $spent = 0; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * | ||||||
|  |      */ | ||||||
|  |     public function __construct() | ||||||
|  |     { | ||||||
|  |         $this->budgetLines = new Collection; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param BudgetLine $budgetLine | ||||||
|  |      */ | ||||||
|  |     public function addBudgetLine(BudgetLine $budgetLine) | ||||||
|  |     { | ||||||
|  |         $this->budgetLines->push($budgetLine); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param float $add | ||||||
|  |      */ | ||||||
|  |     public function addBudgeted($add) | ||||||
|  |     { | ||||||
|  |         $this->budgeted += floatval($add); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param float $add | ||||||
|  |      */ | ||||||
|  |     public function addLeft($add) | ||||||
|  |     { | ||||||
|  |         $this->left += floatval($add); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param float $add | ||||||
|  |      */ | ||||||
|  |     public function addOverspent($add) | ||||||
|  |     { | ||||||
|  |         $this->overspent += floatval($add); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param float $add | ||||||
|  |      */ | ||||||
|  |     public function addSpent($add) | ||||||
|  |     { | ||||||
|  |         $this->spent += floatval($add); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @return \Illuminate\Support\Collection | ||||||
|  |      */ | ||||||
|  |     public function getBudgetLines() | ||||||
|  |     { | ||||||
|  |         return $this->budgetLines; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @return float | ||||||
|  |      */ | ||||||
|  |     public function getBudgeted() | ||||||
|  |     { | ||||||
|  |         return $this->budgeted; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param float $budgeted | ||||||
|  |      */ | ||||||
|  |     public function setBudgeted($budgeted) | ||||||
|  |     { | ||||||
|  |         $this->budgeted = $budgeted; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @return float | ||||||
|  |      */ | ||||||
|  |     public function getLeft() | ||||||
|  |     { | ||||||
|  |         return $this->left; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param float $left | ||||||
|  |      */ | ||||||
|  |     public function setLeft($left) | ||||||
|  |     { | ||||||
|  |         $this->left = $left; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @return float | ||||||
|  |      */ | ||||||
|  |     public function getOverspent() | ||||||
|  |     { | ||||||
|  |         return $this->overspent; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param float $overspent | ||||||
|  |      */ | ||||||
|  |     public function setOverspent($overspent) | ||||||
|  |     { | ||||||
|  |         $this->overspent = $overspent; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @return float | ||||||
|  |      */ | ||||||
|  |     public function getSpent() | ||||||
|  |     { | ||||||
|  |         return $this->spent; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param float $spent | ||||||
|  |      */ | ||||||
|  |     public function setSpent($spent) | ||||||
|  |     { | ||||||
|  |         $this->spent = $spent; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | } | ||||||
							
								
								
									
										130
									
								
								app/Helpers/Collection/BudgetLine.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										130
									
								
								app/Helpers/Collection/BudgetLine.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,130 @@ | |||||||
|  | <?php | ||||||
|  |  | ||||||
|  | namespace FireflyIII\Helpers\Collection; | ||||||
|  |  | ||||||
|  | use FireflyIII\Models\Budget as BudgetModel; | ||||||
|  | use FireflyIII\Models\LimitRepetition; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  |  * | ||||||
|  |  * Class BudgetLine | ||||||
|  |  * | ||||||
|  |  * @package FireflyIII\Helpers\Collection | ||||||
|  |  */ | ||||||
|  | class BudgetLine | ||||||
|  | { | ||||||
|  |  | ||||||
|  |     /** @var  BudgetModel */ | ||||||
|  |     protected $budget; | ||||||
|  |  | ||||||
|  |     /** @var  LimitRepetition */ | ||||||
|  |     protected $repetition; | ||||||
|  |  | ||||||
|  |     /** @var float */ | ||||||
|  |     protected $budgeted = 0; | ||||||
|  |     /** @var float */ | ||||||
|  |     protected $left = 0; | ||||||
|  |     /** @var float */ | ||||||
|  |     protected $overspent = 0; | ||||||
|  |     /** @var float */ | ||||||
|  |     protected $spent = 0; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @return BudgetModel | ||||||
|  |      */ | ||||||
|  |     public function getBudget() | ||||||
|  |     { | ||||||
|  |         return $this->budget; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param BudgetModel $budget | ||||||
|  |      */ | ||||||
|  |     public function setBudget($budget) | ||||||
|  |     { | ||||||
|  |         $this->budget = $budget; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @return float | ||||||
|  |      */ | ||||||
|  |     public function getBudgeted() | ||||||
|  |     { | ||||||
|  |         return $this->budgeted; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param float $budgeted | ||||||
|  |      */ | ||||||
|  |     public function setBudgeted($budgeted) | ||||||
|  |     { | ||||||
|  |         $this->budgeted = $budgeted; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @return float | ||||||
|  |      */ | ||||||
|  |     public function getLeft() | ||||||
|  |     { | ||||||
|  |         return $this->left; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param float $left | ||||||
|  |      */ | ||||||
|  |     public function setLeft($left) | ||||||
|  |     { | ||||||
|  |         $this->left = $left; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @return float | ||||||
|  |      */ | ||||||
|  |     public function getOverspent() | ||||||
|  |     { | ||||||
|  |         return $this->overspent; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param float $overspent | ||||||
|  |      */ | ||||||
|  |     public function setOverspent($overspent) | ||||||
|  |     { | ||||||
|  |         $this->overspent = $overspent; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @return float | ||||||
|  |      */ | ||||||
|  |     public function getSpent() | ||||||
|  |     { | ||||||
|  |         return $this->spent; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param float $spent | ||||||
|  |      */ | ||||||
|  |     public function setSpent($spent) | ||||||
|  |     { | ||||||
|  |         $this->spent = $spent; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @return LimitRepetition | ||||||
|  |      */ | ||||||
|  |     public function getRepetition() | ||||||
|  |     { | ||||||
|  |         return $this->repetition; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param LimitRepetition $repetition | ||||||
|  |      */ | ||||||
|  |     public function setRepetition($repetition) | ||||||
|  |     { | ||||||
|  |         $this->repetition = $repetition; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | } | ||||||
							
								
								
									
										80
									
								
								app/Helpers/Collection/Category.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										80
									
								
								app/Helpers/Collection/Category.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,80 @@ | |||||||
|  | <?php | ||||||
|  | /** | ||||||
|  |  * Created by PhpStorm. | ||||||
|  |  * User: sander | ||||||
|  |  * Date: 16/05/15 | ||||||
|  |  * Time: 13:09 | ||||||
|  |  */ | ||||||
|  |  | ||||||
|  | namespace FireflyIII\Helpers\Collection; | ||||||
|  |  | ||||||
|  | use FireflyIII\Models\Category as CategoryModel; | ||||||
|  | use Illuminate\Support\Collection; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  |  * | ||||||
|  |  * Class Category | ||||||
|  |  * | ||||||
|  |  * @package FireflyIII\Helpers\Collection | ||||||
|  |  */ | ||||||
|  | class Category | ||||||
|  | { | ||||||
|  |  | ||||||
|  |     /** @var  Collection */ | ||||||
|  |     protected $categories; | ||||||
|  |     /** @var float */ | ||||||
|  |     protected $total = 0; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * | ||||||
|  |      */ | ||||||
|  |     public function __construct() | ||||||
|  |     { | ||||||
|  |         $this->categories = new Collection; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param CategoryModel $category | ||||||
|  |      */ | ||||||
|  |     public function addCategory(CategoryModel $category) | ||||||
|  |     { | ||||||
|  |         if ($category->spent > 0) { | ||||||
|  |             $this->categories->push($category); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param float $add | ||||||
|  |      */ | ||||||
|  |     public function addTotal($add) | ||||||
|  |     { | ||||||
|  |         $this->total += floatval($add); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @return Collection | ||||||
|  |      */ | ||||||
|  |     public function getCategories() | ||||||
|  |     { | ||||||
|  |         $this->categories->sortByDesc( | ||||||
|  |             function (CategoryModel $category) { | ||||||
|  |                 return $category->spent; | ||||||
|  |             } | ||||||
|  |         ); | ||||||
|  |  | ||||||
|  |  | ||||||
|  |         return $this->categories; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @return float | ||||||
|  |      */ | ||||||
|  |     public function getTotal() | ||||||
|  |     { | ||||||
|  |         return $this->total; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | } | ||||||
							
								
								
									
										82
									
								
								app/Helpers/Collection/Expense.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										82
									
								
								app/Helpers/Collection/Expense.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,82 @@ | |||||||
|  | <?php | ||||||
|  |  | ||||||
|  | namespace FireflyIII\Helpers\Collection; | ||||||
|  |  | ||||||
|  | use FireflyIII\Models\TransactionJournal; | ||||||
|  | use Illuminate\Support\Collection; | ||||||
|  | use stdClass; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  |  * | ||||||
|  |  * Class Expense | ||||||
|  |  * | ||||||
|  |  * @package FireflyIII\Helpers\Collection | ||||||
|  |  */ | ||||||
|  | class Expense | ||||||
|  | { | ||||||
|  |     /** @var Collection */ | ||||||
|  |     protected $expenses; | ||||||
|  |     /** @var float */ | ||||||
|  |     protected $total; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * | ||||||
|  |      */ | ||||||
|  |     public function __construct() | ||||||
|  |     { | ||||||
|  |         $this->expenses = new Collection; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param TransactionJournal $entry | ||||||
|  |      */ | ||||||
|  |     public function addOrCreateExpense(TransactionJournal $entry) | ||||||
|  |     { | ||||||
|  |  | ||||||
|  |         $accountId = $entry->account_id; | ||||||
|  |         if (!$this->expenses->has($accountId)) { | ||||||
|  |             $newObject         = new stdClass; | ||||||
|  |             $newObject->amount = floatval($entry->amount); | ||||||
|  |             $newObject->name   = $entry->name; | ||||||
|  |             $newObject->count  = 1; | ||||||
|  |             $newObject->id     = $accountId; | ||||||
|  |             $this->expenses->put($accountId, $newObject); | ||||||
|  |         } else { | ||||||
|  |             $existing = $this->expenses->get($accountId); | ||||||
|  |             $existing->amount += floatval($entry->amount); | ||||||
|  |             $existing->count++; | ||||||
|  |             $this->expenses->put($accountId, $existing); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param $add | ||||||
|  |      */ | ||||||
|  |     public function addToTotal($add) | ||||||
|  |     { | ||||||
|  |         $this->total += floatval($add); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @return Collection | ||||||
|  |      */ | ||||||
|  |     public function getExpenses() | ||||||
|  |     { | ||||||
|  |         $this->expenses->sortByDesc( | ||||||
|  |             function (stdClass $object) { | ||||||
|  |                 return $object->amount; | ||||||
|  |             } | ||||||
|  |         ); | ||||||
|  |  | ||||||
|  |         return $this->expenses; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @return float | ||||||
|  |      */ | ||||||
|  |     public function getTotal() | ||||||
|  |     { | ||||||
|  |         return $this->total; | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										85
									
								
								app/Helpers/Collection/Income.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										85
									
								
								app/Helpers/Collection/Income.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,85 @@ | |||||||
|  | <?php | ||||||
|  |  | ||||||
|  | namespace FireflyIII\Helpers\Collection; | ||||||
|  |  | ||||||
|  | use FireflyIII\Models\TransactionJournal; | ||||||
|  | use Illuminate\Support\Collection; | ||||||
|  | use stdClass; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  |  * | ||||||
|  |  * Class Income | ||||||
|  |  * | ||||||
|  |  * @package FireflyIII\Helpers\Collection | ||||||
|  |  */ | ||||||
|  | class Income | ||||||
|  | { | ||||||
|  |  | ||||||
|  |     /** @var Collection */ | ||||||
|  |     protected $incomes; | ||||||
|  |     /** @var float */ | ||||||
|  |     protected $total; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * | ||||||
|  |      */ | ||||||
|  |     public function __construct() | ||||||
|  |     { | ||||||
|  |         $this->incomes = new Collection; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param TransactionJournal $entry | ||||||
|  |      */ | ||||||
|  |     public function addOrCreateIncome(TransactionJournal $entry) | ||||||
|  |     { | ||||||
|  |  | ||||||
|  |         $accountId = $entry->account_id; | ||||||
|  |         if (!$this->incomes->has($accountId)) { | ||||||
|  |             $newObject         = new stdClass; | ||||||
|  |             $newObject->amount = floatval($entry->amount); | ||||||
|  |             $newObject->name   = $entry->name; | ||||||
|  |             $newObject->count  = 1; | ||||||
|  |             $newObject->id     = $accountId; | ||||||
|  |             $this->incomes->put($accountId, $newObject); | ||||||
|  |         } else { | ||||||
|  |             $existing = $this->incomes->get($accountId); | ||||||
|  |             $existing->amount += floatval($entry->amount); | ||||||
|  |             $existing->count++; | ||||||
|  |             $this->incomes->put($accountId, $existing); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param $add | ||||||
|  |      */ | ||||||
|  |     public function addToTotal($add) | ||||||
|  |     { | ||||||
|  |         $this->total += floatval($add); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @return Collection | ||||||
|  |      */ | ||||||
|  |     public function getIncomes() | ||||||
|  |     { | ||||||
|  |         $this->incomes->sortByDesc( | ||||||
|  |             function (stdClass $object) { | ||||||
|  |                 return $object->amount; | ||||||
|  |             } | ||||||
|  |         ); | ||||||
|  |  | ||||||
|  |         return $this->incomes; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @return float | ||||||
|  |      */ | ||||||
|  |     public function getTotal() | ||||||
|  |     { | ||||||
|  |         return $this->total; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | } | ||||||
| @@ -17,6 +17,8 @@ class Help implements HelpInterface | |||||||
| { | { | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * @codeCoverageIgnore | ||||||
|  |      * | ||||||
|      * @param $key |      * @param $key | ||||||
|      * |      * | ||||||
|      * @return string |      * @return string | ||||||
| @@ -27,13 +29,15 @@ class Help implements HelpInterface | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * @codeCoverageIgnore | ||||||
|  |      * | ||||||
|      * @param $route |      * @param $route | ||||||
|      * |      * | ||||||
|      * @return array |      * @return array | ||||||
|      */ |      */ | ||||||
|     public function getFromGithub($route) |     public function getFromGithub($route) | ||||||
|     { |     { | ||||||
|         $uri     = 'https://raw.githubusercontent.com/JC5/firefly-iii-help/master/' . e($route) . '.md'; |         $uri     = 'https://raw.githubusercontent.com/JC5/firefly-iii-help/master/en/' . e($route) . '.md'; | ||||||
|         $content = [ |         $content = [ | ||||||
|             'text'  => '<p>There is no help for this route!</p>', |             'text'  => '<p>There is no help for this route!</p>', | ||||||
|             'title' => $route, |             'title' => $route, | ||||||
| @@ -54,7 +58,11 @@ class Help implements HelpInterface | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @return boolean |      * @codeCoverageIgnore | ||||||
|  |      * | ||||||
|  |      * @param $route | ||||||
|  |      * | ||||||
|  |      * @return bool | ||||||
|      */ |      */ | ||||||
|     public function hasRoute($route) |     public function hasRoute($route) | ||||||
|     { |     { | ||||||
| @@ -62,10 +70,12 @@ class Help implements HelpInterface | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @param       $title |      * @codeCoverageIgnore | ||||||
|  |      * | ||||||
|  |      * @param       $route | ||||||
|      * @param array $content |      * @param array $content | ||||||
|      * |      * | ||||||
|      * @return void |      * @internal param $title | ||||||
|      */ |      */ | ||||||
|     public function putInCache($route, array $content) |     public function putInCache($route, array $content) | ||||||
|     { |     { | ||||||
| @@ -74,6 +84,8 @@ class Help implements HelpInterface | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * @codeCoverageIgnore | ||||||
|  |      * | ||||||
|      * @param $route |      * @param $route | ||||||
|      * |      * | ||||||
|      * @return bool |      * @return bool | ||||||
| @@ -82,4 +94,4 @@ class Help implements HelpInterface | |||||||
|     { |     { | ||||||
|         return Cache::has('help.' . $route . '.title') && Cache::has('help.' . $route . '.text'); |         return Cache::has('help.' . $route . '.title') && Cache::has('help.' . $route . '.text'); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -18,16 +18,25 @@ interface HelpInterface | |||||||
|     public function getFromCache($key); |     public function getFromCache($key); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @return boolean |      * @param $route | ||||||
|  |      * | ||||||
|  |      * @return array | ||||||
|  |      */ | ||||||
|  |     public function getFromGithub($route); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param $route | ||||||
|  |      * | ||||||
|  |      * @return bool | ||||||
|      */ |      */ | ||||||
|     public function hasRoute($route); |     public function hasRoute($route); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @param $route |      * @param $route | ||||||
|      * |      * | ||||||
|      * @return array |      * @return bool | ||||||
|      */ |      */ | ||||||
|     public function getFromGithub($route); |     public function inCache($route); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @param       $route |      * @param       $route | ||||||
| @@ -36,11 +45,4 @@ interface HelpInterface | |||||||
|      * @return void |      * @return void | ||||||
|      */ |      */ | ||||||
|     public function putInCache($route, array $content); |     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); |                 $ranges      = $this->getReminderRanges($piggyBank, $start); | ||||||
|                 $currentRep  = $piggyBank->currentRelevantRep(); |                 $currentRep  = $piggyBank->currentRelevantRep(); | ||||||
|                 $left        = $piggyBank->targetamount - $currentRep->currentamount; |                 $left        = $piggyBank->targetamount - $currentRep->currentamount; | ||||||
|                 $perReminder = $left / count($ranges); |                 $perReminder = count($ranges) == 0 ? $left : $left / count($ranges); | ||||||
|             } else { |             } else { | ||||||
|                 $perReminder = null; |                 $perReminder = null; | ||||||
|                 $ranges      = []; |                 $ranges      = []; | ||||||
| @@ -46,8 +46,6 @@ class ReminderHelper implements ReminderHelperInterface | |||||||
|                 'leftToSave'  => $left, |                 'leftToSave'  => $left, | ||||||
|             ]; |             ]; | ||||||
|  |  | ||||||
|  |  | ||||||
|             // create one: |  | ||||||
|             $reminder = new Reminder; |             $reminder = new Reminder; | ||||||
|             $reminder->user()->associate(Auth::user()); |             $reminder->user()->associate(Auth::user()); | ||||||
|             $reminder->startdate = $start; |             $reminder->startdate = $start; | ||||||
| @@ -65,6 +63,30 @@ class ReminderHelper implements ReminderHelperInterface | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Create all reminders for a piggy bank for a given date. | ||||||
|  |      * | ||||||
|  |      * @param PiggyBank $piggyBank | ||||||
|  |      * | ||||||
|  |      * @param Carbon    $date | ||||||
|  |      * | ||||||
|  |      * @return mixed | ||||||
|  |      */ | ||||||
|  |     public function createReminders(PiggyBank $piggyBank, Carbon $date) | ||||||
|  |     { | ||||||
|  |         $ranges = $this->getReminderRanges($piggyBank); | ||||||
|  |  | ||||||
|  |         foreach ($ranges as $range) { | ||||||
|  |             if ($date < $range['end'] && $date > $range['start']) { | ||||||
|  |                 // create a reminder here! | ||||||
|  |                 $this->createReminder($piggyBank, $range['start'], $range['end']); | ||||||
|  |                 // stop looping, we're done. | ||||||
|  |                 break; | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * This routine will return an array consisting of two dates which indicate the start |      * This routine will return an array consisting of two dates which indicate the start | ||||||
|      * and end date for each reminder that this piggy bank will have, if the piggy bank has |      * and end date for each reminder that this piggy bank will have, if the piggy bank has | ||||||
|   | |||||||
| @@ -4,6 +4,7 @@ namespace FireflyIII\Helpers\Reminders; | |||||||
|  |  | ||||||
| use Carbon\Carbon; | use Carbon\Carbon; | ||||||
| use FireflyIII\Models\PiggyBank; | use FireflyIII\Models\PiggyBank; | ||||||
|  | use FireflyIII\Models\PiggyBankRepetition; | ||||||
| use FireflyIII\Models\Reminder; | use FireflyIII\Models\Reminder; | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @@ -49,4 +50,15 @@ interface ReminderHelperInterface | |||||||
|      * @return Reminder |      * @return Reminder | ||||||
|      */ |      */ | ||||||
|     public function createReminder(PiggyBank $piggyBank, Carbon $start, Carbon $end); |     public function createReminder(PiggyBank $piggyBank, Carbon $start, Carbon $end); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Create all reminders for a piggy bank for a given date. | ||||||
|  |      * | ||||||
|  |      * @param PiggyBank $piggyBank | ||||||
|  |      * | ||||||
|  |      * @param Carbon    $date | ||||||
|  |      * | ||||||
|  |      * @return mixed | ||||||
|  |      */ | ||||||
|  |     public function createReminders(PiggyBank $piggyBank, Carbon $date); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -3,12 +3,23 @@ | |||||||
| namespace FireflyIII\Helpers\Report; | namespace FireflyIII\Helpers\Report; | ||||||
|  |  | ||||||
| use App; | use App; | ||||||
| use Auth; |  | ||||||
| use Carbon\Carbon; | use Carbon\Carbon; | ||||||
|  | use FireflyIII\Helpers\Collection\Account as AccountCollection; | ||||||
|  | use FireflyIII\Helpers\Collection\Balance; | ||||||
|  | use FireflyIII\Helpers\Collection\BalanceEntry; | ||||||
|  | use FireflyIII\Helpers\Collection\BalanceHeader; | ||||||
|  | use FireflyIII\Helpers\Collection\BalanceLine; | ||||||
|  | use FireflyIII\Helpers\Collection\Bill as BillCollection; | ||||||
|  | use FireflyIII\Helpers\Collection\BillLine; | ||||||
|  | use FireflyIII\Helpers\Collection\Budget as BudgetCollection; | ||||||
|  | use FireflyIII\Helpers\Collection\BudgetLine; | ||||||
|  | use FireflyIII\Helpers\Collection\Category as CategoryCollection; | ||||||
|  | use FireflyIII\Helpers\Collection\Expense; | ||||||
|  | use FireflyIII\Helpers\Collection\Income; | ||||||
| use FireflyIII\Models\Account; | use FireflyIII\Models\Account; | ||||||
| use Illuminate\Database\Query\JoinClause; | use FireflyIII\Models\Bill; | ||||||
| use Illuminate\Support\Collection; | use FireflyIII\Models\Budget as BudgetModel; | ||||||
| use Steam; | use FireflyIII\Models\LimitRepetition; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Class ReportHelper |  * Class ReportHelper | ||||||
| @@ -18,66 +29,345 @@ use Steam; | |||||||
| class ReportHelper implements ReportHelperInterface | class ReportHelper implements ReportHelperInterface | ||||||
| { | { | ||||||
|  |  | ||||||
|     /** |     /** @var ReportQueryInterface */ | ||||||
|      * This methods fails to take in account transfers FROM shared accounts. |     protected $query; | ||||||
|      * |  | ||||||
|      * @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; |     /** | ||||||
|  |      * @codeCoverageIgnore | ||||||
|  |      * @param ReportQueryInterface $query | ||||||
|  |      * | ||||||
|  |      */ | ||||||
|  |     public function __construct(ReportQueryInterface $query) | ||||||
|  |     { | ||||||
|  |         $this->query = $query; | ||||||
|  |  | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * This method generates a full report for the given period on all | ||||||
|  |      * the users asset and cash accounts. | ||||||
|  |      * | ||||||
|  |      * @param Carbon $date | ||||||
|  |      * @param Carbon $end | ||||||
|  |      * @param        $shared | ||||||
|  |      * | ||||||
|  |      * @return Account | ||||||
|  |      */ | ||||||
|  |     public function getAccountReport(Carbon $date, Carbon $end, $shared) | ||||||
|  |     { | ||||||
|  |  | ||||||
|  |  | ||||||
|  |         $accounts = $this->query->getAllAccounts($date, $end, $shared); | ||||||
|  |         $start    = 0; | ||||||
|  |         $end      = 0; | ||||||
|  |         $diff     = 0; | ||||||
|  |  | ||||||
|  |         // remove cash account, if any: | ||||||
|  |         $accounts  =$accounts->filter(function(Account $account) { | ||||||
|  |             if($account->accountType->type != 'Cash account') { | ||||||
|  |                 return $account; | ||||||
|  |             } | ||||||
|  |         }); | ||||||
|  |  | ||||||
|  |         // summarize: | ||||||
|  |         foreach ($accounts as $account) { | ||||||
|  |             $start += $account->startBalance; | ||||||
|  |             $end += $account->endBalance; | ||||||
|  |             $diff += ($account->endBalance - $account->startBalance); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         $object = new AccountCollection; | ||||||
|  |         $object->setStart($start); | ||||||
|  |         $object->setEnd($end); | ||||||
|  |         $object->setDifference($diff); | ||||||
|  |         $object->setAccounts($accounts); | ||||||
|  |  | ||||||
|  |         return $object; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * | ||||||
|  |      * The balance report contains a Balance object which in turn contains: | ||||||
|  |      * | ||||||
|  |      * A BalanceHeader object which contains all relevant user asset accounts for the report. | ||||||
|  |      * | ||||||
|  |      * A number of BalanceLine objects, which hold: | ||||||
|  |      * - A budget | ||||||
|  |      * - A number of BalanceEntry objects. | ||||||
|  |      * | ||||||
|  |      * The BalanceEntry object holds: | ||||||
|  |      *   - The same budget (again) | ||||||
|  |      *   - A user asset account as mentioned in the BalanceHeader | ||||||
|  |      *   - The amount of money spent on the budget by the user asset account | ||||||
|  |      * | ||||||
|  |      * @param Carbon  $start | ||||||
|  |      * @param Carbon  $end | ||||||
|  |      * @param boolean $shared | ||||||
|  |      * | ||||||
|  |      * @return Balance | ||||||
|  |      */ | ||||||
|  |     public function getBalanceReport(Carbon $start, Carbon $end, $shared) | ||||||
|  |     { | ||||||
|  |         $repository    = App::make('FireflyIII\Repositories\Budget\BudgetRepositoryInterface'); | ||||||
|  |         $tagRepository = App::make('FireflyIII\Repositories\Tag\TagRepositoryInterface'); | ||||||
|  |         $balance       = new Balance; | ||||||
|  |  | ||||||
|  |         // build a balance header: | ||||||
|  |         $header = new BalanceHeader; | ||||||
|  |  | ||||||
|  |         $accounts = $this->query->getAllAccounts($start, $end, $shared); | ||||||
|  |         $budgets  = $repository->getBudgets(); | ||||||
|  |         foreach ($accounts as $account) { | ||||||
|  |             $header->addAccount($account); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /** @var BudgetModel $budget */ | ||||||
|  |         foreach ($budgets as $budget) { | ||||||
|  |             $line = new BalanceLine; | ||||||
|  |             $line->setBudget($budget); | ||||||
|  |  | ||||||
|  |             // get budget amount for current period: | ||||||
|  |             $rep = $repository->getCurrentRepetition($budget, $start); | ||||||
|  |             $line->setRepetition($rep); | ||||||
|  |  | ||||||
|  |             // loop accounts: | ||||||
|  |             foreach ($accounts as $account) { | ||||||
|  |                 $balanceEntry = new BalanceEntry; | ||||||
|  |                 $balanceEntry->setAccount($account); | ||||||
|  |  | ||||||
|  |                 // get spent: | ||||||
|  |                 $spent = $this->query->spentInBudgetCorrected($account, $budget, $start, $end); // I think shared is irrelevant. | ||||||
|  |  | ||||||
|  |                 $balanceEntry->setSpent($spent); | ||||||
|  |                 $line->addBalanceEntry($balanceEntry); | ||||||
|  |             } | ||||||
|  |             // add line to balance: | ||||||
|  |             $balance->addBalanceLine($line); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         // then a new line for without budget. | ||||||
|  |         // and one for the tags: | ||||||
|  |         $empty    = new BalanceLine; | ||||||
|  |         $tags     = new BalanceLine; | ||||||
|  |         $diffLine = new BalanceLine; | ||||||
|  |  | ||||||
|  |         $tags->setRole(BalanceLine::ROLE_TAGROLE); | ||||||
|  |         $diffLine->setRole(BalanceLine::ROLE_DIFFROLE); | ||||||
|  |  | ||||||
|  |         foreach ($accounts as $account) { | ||||||
|  |             $spent = $this->query->spentNoBudget($account, $start, $end); | ||||||
|  |             $left  = $tagRepository->coveredByBalancingActs($account, $start, $end); | ||||||
|  |             $diff  = $spent + $left; | ||||||
|  |  | ||||||
|  |             // budget | ||||||
|  |             $budgetEntry = new BalanceEntry; | ||||||
|  |             $budgetEntry->setAccount($account); | ||||||
|  |             $budgetEntry->setSpent($spent); | ||||||
|  |             $empty->addBalanceEntry($budgetEntry); | ||||||
|  |  | ||||||
|  |             // balanced by tags | ||||||
|  |             $tagEntry = new BalanceEntry; | ||||||
|  |             $tagEntry->setAccount($account); | ||||||
|  |             $tagEntry->setLeft($left); | ||||||
|  |             $tags->addBalanceEntry($tagEntry); | ||||||
|  |  | ||||||
|  |             // difference: | ||||||
|  |             $diffEntry = new BalanceEntry; | ||||||
|  |             $diffEntry->setAccount($account); | ||||||
|  |             $diffEntry->setSpent($diff); | ||||||
|  |             $diffLine->addBalanceEntry($diffEntry); | ||||||
|  |  | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         $balance->addBalanceLine($empty); | ||||||
|  |         $balance->addBalanceLine($tags); | ||||||
|  |         $balance->addBalanceLine($diffLine); | ||||||
|  |  | ||||||
|  |         $balance->setBalanceHeader($header); | ||||||
|  |  | ||||||
|  |         return $balance; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * This method generates a full report for the given period on all | ||||||
|  |      * the users bills and their payments. | ||||||
|  |      * | ||||||
|  |      * @param Carbon  $start | ||||||
|  |      * @param Carbon  $end | ||||||
|  |      * @param boolean $shared | ||||||
|  |      * | ||||||
|  |      * @return BillCollection | ||||||
|  |      */ | ||||||
|  |     public function getBillReport(Carbon $start, Carbon $end, $shared) | ||||||
|  |     { | ||||||
|  |         /** @var \FireflyIII\Repositories\Bill\BillRepositoryInterface $repository */ | ||||||
|  |         $repository = App::make('FireflyIII\Repositories\Bill\BillRepositoryInterface'); | ||||||
|  |         $bills      = $repository->getBills(); | ||||||
|  |         $collection = new BillCollection; | ||||||
|  |  | ||||||
|  |         /** @var Bill $bill */ | ||||||
|  |         foreach ($bills as $bill) { | ||||||
|  |             $billLine = new BillLine; | ||||||
|  |             $billLine->setBill($bill); | ||||||
|  |             $billLine->setActive(intval($bill->active) == 1); | ||||||
|  |             $billLine->setMin(floatval($bill->amount_min)); | ||||||
|  |             $billLine->setMax(floatval($bill->amount_max)); | ||||||
|  |  | ||||||
|  |             // is hit in period? | ||||||
|  |             $set = $repository->getJournalsInRange($bill, $start, $end); | ||||||
|  |             if ($set->count() == 0) { | ||||||
|  |                 $billLine->setHit(false); | ||||||
|  |             } else { | ||||||
|  |                 $billLine->setHit(true); | ||||||
|  |                 $amount = 0; | ||||||
|  |                 foreach ($set as $entry) { | ||||||
|  |                     $amount += $entry->amount; | ||||||
|  |                 } | ||||||
|  |                 $billLine->setAmount($amount); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             $collection->addBill($billLine); | ||||||
|  |  | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return $collection; | ||||||
|  |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * This method gets some kind of list for a monthly overview. |      * @param Carbon  $start | ||||||
|  |      * @param Carbon  $end | ||||||
|  |      * @param boolean $shared | ||||||
|      * |      * | ||||||
|      * @param Carbon $date |      * @return BudgetCollection | ||||||
|      * @param bool   $showSharedReports |  | ||||||
|      * |  | ||||||
|      * @return Collection |  | ||||||
|      */ |      */ | ||||||
|     public function getBudgetsForMonth(Carbon $date, $showSharedReports = false) |     public function getBudgetReport(Carbon $start, Carbon $end, $shared) | ||||||
|     { |     { | ||||||
|         /** @var \FireflyIII\Helpers\Report\ReportQueryInterface $query */ |         $object = new BudgetCollection; | ||||||
|         $query = App::make('FireflyIII\Helpers\Report\ReportQueryInterface'); |         /** @var \FireflyIII\Repositories\Budget\BudgetRepositoryInterface $repository */ | ||||||
|  |         $repository = App::make('FireflyIII\Repositories\Budget\BudgetRepositoryInterface'); | ||||||
|  |         $set        = $repository->getBudgets(); | ||||||
|  |  | ||||||
|         $start = clone $date; |         foreach ($set as $budget) { | ||||||
|         $start->startOfMonth(); |  | ||||||
|         $end = clone $date; |  | ||||||
|         $end->endOfMonth(); |  | ||||||
|         $set = Auth::user()->budgets()->orderBy('budgets.name', 'ASC') |  | ||||||
|                    ->leftJoin( |  | ||||||
|                        'budget_limits', function (JoinClause $join) use ($date) { |  | ||||||
|                        $join->on('budget_limits.budget_id', '=', 'budgets.id')->where('budget_limits.startdate', '=', $date->format('Y-m-d')); |  | ||||||
|                    } |  | ||||||
|                    ) |  | ||||||
|                    ->get(['budgets.*', 'budget_limits.amount as queryAmount']); |  | ||||||
|  |  | ||||||
|         $budgets                   = Steam::makeArray($set); |             $repetitions = $repository->getBudgetLimitRepetitions($budget, $start, $end); | ||||||
|         $amountSet                 = $query->journalsByBudget($start, $end, $showSharedReports); |  | ||||||
|         $amounts                   = Steam::makeArray($amountSet); |             // no repetition(s) for this budget: | ||||||
|         $budgets                   = Steam::mergeArrays($budgets, $amounts); |             if ($repetitions->count() == 0) { | ||||||
|         $budgets[0]['spent']       = isset($budgets[0]['spent']) ? $budgets[0]['spent'] : 0.0; |                 $spent      = $repository->spentInPeriodCorrected($budget, $start, $end, $shared); | ||||||
|         $budgets[0]['queryAmount'] = isset($budgets[0]['queryAmount']) ? $budgets[0]['queryAmount'] : 0.0; |                 $budgetLine = new BudgetLine; | ||||||
|         $budgets[0]['name']        = 'No budget'; |                 $budgetLine->setBudget($budget); | ||||||
|  |                 $budgetLine->setOverspent($spent); | ||||||
|  |                 $object->addOverspent($spent); | ||||||
|  |                 $object->addBudgetLine($budgetLine); | ||||||
|  |                 continue; | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             // one or more repetitions for budget: | ||||||
|  |             /** @var LimitRepetition $repetition */ | ||||||
|  |             foreach ($repetitions as $repetition) { | ||||||
|  |                 $budgetLine = new BudgetLine; | ||||||
|  |                 $budgetLine->setBudget($budget); | ||||||
|  |                 $budgetLine->setRepetition($repetition); | ||||||
|  |                 $expenses  = $repository->spentInPeriodCorrected($budget, $repetition->startdate, $repetition->enddate, $shared); | ||||||
|  |                 $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; | ||||||
|  |  | ||||||
|  |                 $budgetLine->setLeft($left); | ||||||
|  |                 $budgetLine->setSpent($spent); | ||||||
|  |                 $budgetLine->setOverspent($overspent); | ||||||
|  |                 $budgetLine->setBudgeted($repetition->amount); | ||||||
|  |  | ||||||
|  |                 $object->addBudgeted($repetition->amount); | ||||||
|  |                 $object->addSpent($spent); | ||||||
|  |                 $object->addLeft($left); | ||||||
|  |                 $object->addOverspent($overspent); | ||||||
|  |                 $object->addBudgetLine($budgetLine); | ||||||
|  |  | ||||||
|  |             } | ||||||
|  |  | ||||||
|         // find transactions to shared asset accounts, which are without a budget by default: |  | ||||||
|         // which is only relevant when shared asset accounts are hidden. |  | ||||||
|         if ($showSharedReports === false) { |  | ||||||
|             $transfers = $query->sharedExpenses($start, $end)->sum('queryAmount'); |  | ||||||
|             $budgets[0]['spent'] += floatval($transfers) * -1; |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return $budgets; |         // stuff outside of budgets: | ||||||
|  |         $noBudget   = $repository->getWithoutBudgetSum($start, $end); | ||||||
|  |         $budgetLine = new BudgetLine; | ||||||
|  |         $budgetLine->setOverspent($noBudget); | ||||||
|  |         $object->addOverspent($noBudget); | ||||||
|  |         $object->addBudgetLine($budgetLine); | ||||||
|  |  | ||||||
|  |         return $object; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param Carbon  $start | ||||||
|  |      * @param Carbon  $end | ||||||
|  |      * @param boolean $shared | ||||||
|  |      * | ||||||
|  |      * @return CategoryCollection | ||||||
|  |      */ | ||||||
|  |     public function getCategoryReport(Carbon $start, Carbon $end, $shared) | ||||||
|  |     { | ||||||
|  |         $object = new CategoryCollection; | ||||||
|  |  | ||||||
|  |  | ||||||
|  |         /** | ||||||
|  |          * GET CATEGORIES: | ||||||
|  |          */ | ||||||
|  |         /** @var \FireflyIII\Repositories\Category\CategoryRepositoryInterface $repository */ | ||||||
|  |         $repository = App::make('FireflyIII\Repositories\Category\CategoryRepositoryInterface'); | ||||||
|  |         $set        = $repository->getCategories(); | ||||||
|  |         foreach ($set as $category) { | ||||||
|  |             $spent           = $repository->spentInPeriodCorrected($category, $start, $end, $shared); | ||||||
|  |             $category->spent = $spent; | ||||||
|  |             $object->addCategory($category); | ||||||
|  |             $object->addTotal($spent); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return $object; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Get a full report on the users expenses during the period. | ||||||
|  |      * | ||||||
|  |      * @param Carbon  $start | ||||||
|  |      * @param Carbon  $end | ||||||
|  |      * @param boolean $shared | ||||||
|  |      * | ||||||
|  |      * @return Expense | ||||||
|  |      */ | ||||||
|  |     public function getExpenseReport($start, $end, $shared) | ||||||
|  |     { | ||||||
|  |         $object = new Expense; | ||||||
|  |         $set    = $this->query->expenseInPeriodCorrected($start, $end, $shared); | ||||||
|  |         foreach ($set as $entry) { | ||||||
|  |             $object->addToTotal($entry->amount); | ||||||
|  |             $object->addOrCreateExpense($entry); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return $object; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Get a full report on the users incomes during the period. | ||||||
|  |      * | ||||||
|  |      * @param Carbon  $start | ||||||
|  |      * @param Carbon  $end | ||||||
|  |      * @param boolean $shared | ||||||
|  |      * | ||||||
|  |      * @return Income | ||||||
|  |      */ | ||||||
|  |     public function getIncomeReport($start, $end, $shared) | ||||||
|  |     { | ||||||
|  |         $object = new Income; | ||||||
|  |         $set    = $this->query->incomeInPeriodCorrected($start, $end, $shared); | ||||||
|  |         foreach ($set as $entry) { | ||||||
|  |             $object->addToTotal($entry->amount); | ||||||
|  |             $object->addOrCreateIncome($entry); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return $object; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -87,92 +377,20 @@ class ReportHelper implements ReportHelperInterface | |||||||
|      */ |      */ | ||||||
|     public function listOfMonths(Carbon $date) |     public function listOfMonths(Carbon $date) | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $start  = clone $date; |         $start  = clone $date; | ||||||
|         $end    = Carbon::now(); |         $end    = Carbon::now(); | ||||||
|         $months = []; |         $months = []; | ||||||
|         while ($start <= $end) { |         while ($start <= $end) { | ||||||
|             $year            = $start->format('Y'); |             $year            = $start->year; | ||||||
|             $months[$year][] = [ |             $months[$year][] = [ | ||||||
|                 'formatted' => $start->format('F Y'), |                 'formatted' => $start->formatLocalized('%B %Y'), | ||||||
|                 'month'     => intval($start->format('m')), |                 'month'     => $start->month, | ||||||
|                 'year'      => intval($start->format('Y')), |                 'year'      => $year, | ||||||
|             ]; |             ]; | ||||||
|             $start->addMonth(); |             $start->addMonth(); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return $months; |         return $months; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * @param Carbon $date |  | ||||||
|      * |  | ||||||
|      * @return array |  | ||||||
|      */ |  | ||||||
|     public function listOfYears(Carbon $date) |  | ||||||
|     { |  | ||||||
|         $start = clone $date; |  | ||||||
|         $end   = Carbon::now(); |  | ||||||
|         $years = []; |  | ||||||
|         while ($start <= $end) { |  | ||||||
|             $years[] = $start->format('Y'); |  | ||||||
|             $start->addYear(); |  | ||||||
|         } |  | ||||||
|         $years[] = Carbon::now()->format('Y'); |  | ||||||
|         // force the current year. |  | ||||||
|         $years = array_unique($years); |  | ||||||
|  |  | ||||||
|         return $years; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * @param Carbon $date |  | ||||||
|      * @param bool   $showSharedReports |  | ||||||
|      * |  | ||||||
|      * @return array |  | ||||||
|      */ |  | ||||||
|     public function yearBalanceReport(Carbon $date, $showSharedReports = false) |  | ||||||
|     { |  | ||||||
|         $start          = clone $date; |  | ||||||
|         $end            = clone $date; |  | ||||||
|         $sharedAccounts = []; |  | ||||||
|         if ($showSharedReports === false) { |  | ||||||
|             $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')) |  | ||||||
|                                      ->get(['accounts.id']); |  | ||||||
|  |  | ||||||
|             foreach ($sharedCollection as $account) { |  | ||||||
|                 $sharedAccounts[] = $account->id; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         $accounts = Auth::user()->accounts()->accountTypeIn(['Default account', 'Asset account'])->orderBy('accounts.name', 'ASC')->get(['accounts.*']) |  | ||||||
|                         ->filter( |  | ||||||
|                             function (Account $account) use ($sharedAccounts) { |  | ||||||
|                                 if (!in_array($account->id, $sharedAccounts)) { |  | ||||||
|                                     return $account; |  | ||||||
|                                 } |  | ||||||
|  |  | ||||||
|                                 return null; |  | ||||||
|                             } |  | ||||||
|                         ); |  | ||||||
|         $report   = []; |  | ||||||
|         $start->startOfYear()->subDay(); |  | ||||||
|         $end->endOfYear(); |  | ||||||
|  |  | ||||||
|         foreach ($accounts as $account) { |  | ||||||
|             $startBalance = Steam::balance($account, $start); |  | ||||||
|             $endBalance   = Steam::balance($account, $end); |  | ||||||
|             $report[]     = [ |  | ||||||
|                 'start'   => $startBalance, |  | ||||||
|                 'end'     => $endBalance, |  | ||||||
|                 'hide'    => ($startBalance == 0 && $endBalance == 0), |  | ||||||
|                 'account' => $account, |  | ||||||
|                 'shared'  => $account->accountRole == 'sharedAsset' |  | ||||||
|             ]; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         return $report; |  | ||||||
|     } |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -3,7 +3,12 @@ | |||||||
| namespace FireflyIII\Helpers\Report; | namespace FireflyIII\Helpers\Report; | ||||||
|  |  | ||||||
| use Carbon\Carbon; | use Carbon\Carbon; | ||||||
| use Illuminate\Support\Collection; | use FireflyIII\Helpers\Collection\Account; | ||||||
|  | use FireflyIII\Helpers\Collection\Balance; | ||||||
|  | use FireflyIII\Helpers\Collection\Budget as BudgetCollection; | ||||||
|  | use FireflyIII\Helpers\Collection\Category as CategoryCollection; | ||||||
|  | use FireflyIII\Helpers\Collection\Expense; | ||||||
|  | use FireflyIII\Helpers\Collection\Income; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Interface ReportHelperInterface |  * Interface ReportHelperInterface | ||||||
| @@ -13,26 +18,78 @@ use Illuminate\Support\Collection; | |||||||
| interface ReportHelperInterface | interface ReportHelperInterface | ||||||
| { | { | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * This method generates a full report for the given period on all | ||||||
|  |      * the users asset and cash accounts. | ||||||
|  |      * | ||||||
|  |      * @param Carbon  $date | ||||||
|  |      * @param Carbon  $end | ||||||
|  |      * @param boolean $shared | ||||||
|  |      * | ||||||
|  |      * @return Account | ||||||
|  |      */ | ||||||
|  |     public function getAccountReport(Carbon $date, Carbon $end, $shared); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * This methods fails to take in account transfers FROM shared accounts. |      * This method generates a full report for the given period on all | ||||||
|  |      * the users bills and their payments. | ||||||
|      * |      * | ||||||
|      * @param Carbon $start |      * @param Carbon  $start | ||||||
|      * @param Carbon $end |      * @param Carbon  $end | ||||||
|      * @param int    $limit |      * @param boolean $shared | ||||||
|      * |      * | ||||||
|      * @return Collection |      * @return Account | ||||||
|      */ |      */ | ||||||
|     public function expensesGroupedByAccount(Carbon $start, Carbon $end, $limit = 15); |     public function getBillReport(Carbon $start, Carbon $end, $shared); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * This method gets some kind of list for a monthly overview. |      * @param Carbon  $start | ||||||
|  |      * @param Carbon  $end | ||||||
|  |      * @param boolean $shared | ||||||
|      * |      * | ||||||
|      * @param Carbon $date |      * @return Balance | ||||||
|      * |  | ||||||
|      * @return Collection |  | ||||||
|      */ |      */ | ||||||
|     public function getBudgetsForMonth(Carbon $date); |     public function getBalanceReport(Carbon $start, Carbon $end, $shared); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param Carbon  $start | ||||||
|  |      * @param Carbon  $end | ||||||
|  |      * @param boolean $shared | ||||||
|  |      * | ||||||
|  |      * @return BudgetCollection | ||||||
|  |      */ | ||||||
|  |     public function getBudgetReport(Carbon $start, Carbon $end, $shared); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param Carbon  $start | ||||||
|  |      * @param Carbon  $end | ||||||
|  |      * @param boolean $shared | ||||||
|  |      * | ||||||
|  |      * @return CategoryCollection | ||||||
|  |      */ | ||||||
|  |     public function getCategoryReport(Carbon $start, Carbon $end, $shared); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Get a full report on the users expenses during the period. | ||||||
|  |      * | ||||||
|  |      * @param Carbon  $start | ||||||
|  |      * @param Carbon  $end | ||||||
|  |      * @param boolean $shared | ||||||
|  |      * | ||||||
|  |      * @return Expense | ||||||
|  |      */ | ||||||
|  |     public function getExpenseReport($start, $end, $shared); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Get a full report on the users incomes during the period. | ||||||
|  |      * | ||||||
|  |      * @param Carbon  $start | ||||||
|  |      * @param Carbon  $end | ||||||
|  |      * @param boolean $shared | ||||||
|  |      * | ||||||
|  |      * @return Income | ||||||
|  |      */ | ||||||
|  |     public function getIncomeReport($start, $end, $shared); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @param Carbon $date |      * @param Carbon $date | ||||||
| @@ -41,18 +98,4 @@ interface ReportHelperInterface | |||||||
|      */ |      */ | ||||||
|     public function listOfMonths(Carbon $date); |     public function listOfMonths(Carbon $date); | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * @param Carbon $date |  | ||||||
|      * |  | ||||||
|      * @return array |  | ||||||
|      */ |  | ||||||
|     public function listOfYears(Carbon $date); |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * @param Carbon $date |  | ||||||
|      * @param bool   $showSharedReports |  | ||||||
|      * |  | ||||||
|      * @return array |  | ||||||
|      */ |  | ||||||
|     public function yearBalanceReport(Carbon $date, $showSharedReports = false); |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -7,6 +7,7 @@ use Carbon\Carbon; | |||||||
| use Crypt; | use Crypt; | ||||||
| use DB; | use DB; | ||||||
| use FireflyIII\Models\Account; | use FireflyIII\Models\Account; | ||||||
|  | use FireflyIII\Models\Budget; | ||||||
| use FireflyIII\Models\TransactionJournal; | use FireflyIII\Models\TransactionJournal; | ||||||
| use Illuminate\Database\Eloquent\Builder; | use Illuminate\Database\Eloquent\Builder; | ||||||
| use Illuminate\Database\Eloquent\Model; | use Illuminate\Database\Eloquent\Model; | ||||||
| @@ -21,101 +22,62 @@ use Steam; | |||||||
|  */ |  */ | ||||||
| class ReportQuery implements ReportQueryInterface | class ReportQuery implements ReportQueryInterface | ||||||
| { | { | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * This query retrieves a list of accounts that are active and not shared. |      * See ReportQueryInterface::incomeInPeriodCorrected | ||||||
|      * |      * | ||||||
|      * @param bool $showSharedReports |      * @param Carbon $start | ||||||
|  |      * @param Carbon $end | ||||||
|  |      * @param bool   $includeShared | ||||||
|      * |      * | ||||||
|      * @return Collection |      * @return Collection | ||||||
|  |      * | ||||||
|      */ |      */ | ||||||
|     public function accountList($showSharedReports = false) |     public function expenseInPeriodCorrected(Carbon $start, Carbon $end, $includeShared = false) | ||||||
|     { |     { | ||||||
|         $query = Auth::user()->accounts(); |         $query = $this->queryJournalsWithTransactions($start, $end); | ||||||
|         if ($showSharedReports === false) { |         if ($includeShared === false) { | ||||||
|  |             $query->where( | ||||||
|             $query->leftJoin( |  | ||||||
|                 'account_meta', function (JoinClause $join) { |  | ||||||
|                 $join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', "accountRole"); |  | ||||||
|             } |  | ||||||
|             )->where( |  | ||||||
|                 function (Builder $query) { |                 function (Builder $query) { | ||||||
|                     $query->where('account_meta.data', '!=', '"sharedAsset"'); |                     $query->where( | ||||||
|                     $query->orWhereNull('account_meta.data'); |                         function (Builder $q) { // only get withdrawals not from a shared account | ||||||
|  |                             $q->where('transaction_types.type', 'Withdrawal'); | ||||||
|  |                             $q->where('acm_from.data', '!=', '"sharedAsset"'); | ||||||
|  |                         } | ||||||
|  |                     ); | ||||||
|  |                     $query->orWhere( | ||||||
|  |                         function (Builder $q) { // and transfers from a shared account. | ||||||
|  |                             $q->where('transaction_types.type', 'Transfer'); | ||||||
|  |                             $q->where('acm_to.data', '=', '"sharedAsset"'); | ||||||
|  |                         } | ||||||
|  |                     ); | ||||||
|                 } |                 } | ||||||
|             ); |             ); | ||||||
|  |         } else { | ||||||
|  |             $query->where('transaction_types.type', 'Withdrawal'); // any withdrawal is fine. | ||||||
|         } |         } | ||||||
|         $query->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id') |         $query->orderBy('transaction_journals.date'); | ||||||
|               ->whereIn('account_types.type', ['Default account', 'Cash account', 'Asset account']) |  | ||||||
|               ->where('active', 1) |  | ||||||
|               ->orderBy('accounts.name', 'ASC'); |  | ||||||
|  |  | ||||||
|         return $query->get(['accounts.*']); |         // get everything | ||||||
|     } |         $data = $query->get( | ||||||
|  |             ['transaction_journals.*', 'transaction_types.type', 'ac_to.name as name', 'ac_to.id as account_id', 'ac_to.encrypted as account_encrypted'] | ||||||
|  |         ); | ||||||
|  |  | ||||||
|     /** |         $data->each( | ||||||
|      * This method will get a list of all expenses in a certain time period that have no budget |             function (TransactionJournal $journal) { | ||||||
|      * and are balanced by a transfer to make up for it. |                 if (intval($journal->account_encrypted) == 1) { | ||||||
|      * |                     $journal->name = Crypt::decrypt($journal->name); | ||||||
|      * @param Account $account |                 } | ||||||
|      * @param Carbon  $start |             } | ||||||
|      * @param Carbon  $end |         ); | ||||||
|      * |         $data = $data->filter( | ||||||
|      * @return Collection |             function (TransactionJournal $journal) { | ||||||
|      */ |                 if ($journal->amount != 0) { | ||||||
|     public function balancedTransactionsList(Account $account, Carbon $start, Carbon $end) |                     return $journal; | ||||||
|     { |                 } | ||||||
|  |             } | ||||||
|  |         ); | ||||||
|  |  | ||||||
|         $set = TransactionJournal:: |         return $data; | ||||||
|         leftJoin('transaction_group_transaction_journal', 'transaction_group_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') |  | ||||||
|                                  ->leftJoin( |  | ||||||
|                                      'transaction_group_transaction_journal as otherFromGroup', function (JoinClause $join) { |  | ||||||
|                                      $join->on('otherFromGroup.transaction_group_id', '=', 'transaction_group_transaction_journal.transaction_group_id') |  | ||||||
|                                           ->on('otherFromGroup.transaction_journal_id', '!=', 'transaction_journals.id'); |  | ||||||
|                                  } |  | ||||||
|                                  ) |  | ||||||
|                                  ->leftJoin('transaction_journals as otherJournals', 'otherJournals.id', '=', 'otherFromGroup.transaction_journal_id') |  | ||||||
|                                  ->leftJoin('transaction_types', 'transaction_types.id', '=', 'otherJournals.transaction_type_id') |  | ||||||
|                                  ->leftJoin( |  | ||||||
|                                      'transactions', function (JoinClause $join) { |  | ||||||
|                                      $join->on('transaction_journals.id', '=', 'transactions.transaction_journal_id')->where('amount', '>', 0); |  | ||||||
|                                  } |  | ||||||
|                                  ) |  | ||||||
|                                  ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'otherJournals.id') |  | ||||||
|                                  ->before($end)->after($start) |  | ||||||
|                                  ->where('transaction_types.type', 'Withdrawal') |  | ||||||
|                                  ->where('transaction_journals.user_id', Auth::user()->id) |  | ||||||
|                                  ->whereNull('budget_transaction_journal.budget_id')->whereNull('transaction_journals.deleted_at') |  | ||||||
|                                  ->whereNull('otherJournals.deleted_at') |  | ||||||
|                                  ->where('transactions.account_id', $account->id) |  | ||||||
|                                  ->orderBy('transaction_journals.date', 'DESC') |  | ||||||
|                                  ->orderBy('transaction_journals.order', 'ASC') |  | ||||||
|                                  ->orderBy('transaction_journals.id', 'DESC') |  | ||||||
|                                  ->whereNotNull('transaction_group_transaction_journal.transaction_group_id') |  | ||||||
|                                  ->get( |  | ||||||
|                                      [ |  | ||||||
|                                          'transaction_journals.*', |  | ||||||
|                                          'transactions.amount as queryAmount' |  | ||||||
|                                      ] |  | ||||||
|                                  ); |  | ||||||
|  |  | ||||||
|         return $set; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * This method will get the sum of all expenses in a certain time period that have no budget |  | ||||||
|      * and are balanced by a transfer to make up for it. |  | ||||||
|      * |  | ||||||
|      * @param Account $account |  | ||||||
|      * @param Carbon  $start |  | ||||||
|      * @param Carbon  $end |  | ||||||
|      * |  | ||||||
|      * @return float |  | ||||||
|      */ |  | ||||||
|     public function balancedTransactionsSum(Account $account, Carbon $start, Carbon $end) |  | ||||||
|     { |  | ||||||
|         return floatval($this->balancedTransactionsList($account, $start, $end)->sum('queryAmount')); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -123,15 +85,15 @@ class ReportQuery implements ReportQueryInterface | |||||||
|      * |      * | ||||||
|      * @param Carbon $start |      * @param Carbon $start | ||||||
|      * @param Carbon $end |      * @param Carbon $end | ||||||
|      * @param bool   $showSharedReports |      * @param bool   $includeShared | ||||||
|      * |      * | ||||||
|      * @return Collection |      * @return Collection | ||||||
|      */ |      */ | ||||||
|     public function getAllAccounts(Carbon $start, Carbon $end, $showSharedReports = false) |     public function getAllAccounts(Carbon $start, Carbon $end, $includeShared = false) | ||||||
|     { |     { | ||||||
|         $query = Auth::user()->accounts()->orderBy('accounts.name', 'ASC') |         $query = Auth::user()->accounts()->orderBy('accounts.name', 'ASC') | ||||||
|                      ->accountTypeIn(['Default account', 'Asset account', 'Cash account']); |                      ->accountTypeIn(['Default account', 'Asset account', 'Cash account']); | ||||||
|         if ($showSharedReports === false) { |         if ($includeShared === false) { | ||||||
|             $query->leftJoin( |             $query->leftJoin( | ||||||
|                 'account_meta', function (JoinClause $join) { |                 'account_meta', function (JoinClause $join) { | ||||||
|                 $join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole'); |                 $join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole'); | ||||||
| @@ -150,8 +112,16 @@ class ReportQuery implements ReportQueryInterface | |||||||
|         $set = $query->get(['accounts.*']); |         $set = $query->get(['accounts.*']); | ||||||
|         $set->each( |         $set->each( | ||||||
|             function (Account $account) use ($start, $end) { |             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 */ |                 /** @noinspection PhpParamsInspection */ | ||||||
|                 $account->startBalance = Steam::balance($account, $start); |                 $account->startBalance = Steam::balance($account, $yesterday); | ||||||
|                 $account->endBalance   = Steam::balance($account, $end); |                 $account->endBalance   = Steam::balance($account, $end); | ||||||
|             } |             } | ||||||
|         ); |         ); | ||||||
| @@ -159,55 +129,27 @@ class ReportQuery implements ReportQueryInterface | |||||||
|         return $set; |         return $set; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Grabs a summary of all expenses grouped by budget, related to the account. |  | ||||||
|      * |  | ||||||
|      * @param Account $account |  | ||||||
|      * @param Carbon  $start |  | ||||||
|      * @param Carbon  $end |  | ||||||
|      * |  | ||||||
|      * @return mixed |  | ||||||
|      */ |  | ||||||
|     public function getBudgetSummary(Account $account, Carbon $start, Carbon $end) |  | ||||||
|     { |  | ||||||
|         $query = $this->queryJournalsNoBudget($account, $start, $end); |  | ||||||
|  |  | ||||||
|         return $query->get(['budgets.id', 'budgets.name', DB::Raw('SUM(`transactions`.`amount`) as `queryAmount`')]); |  | ||||||
|  |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Get a list of transaction journals that have no budget, filtered for the specified account |      * This method works the same way as ReportQueryInterface::incomeInPeriod does, but instead of returning results | ||||||
|      * and the specified date range. |      * will simply list the transaction journals only. This should allow any follow up counting to be accurate with | ||||||
|  |      * regards to tags. | ||||||
|      * |      * | ||||||
|      * @param Account $account |  | ||||||
|      * @param Carbon  $start |  | ||||||
|      * @param Carbon  $end |  | ||||||
|      * |  | ||||||
|      * @return Collection |  | ||||||
|      */ |  | ||||||
|     public function getTransactionsWithoutBudget(Account $account, Carbon $start, Carbon $end) |  | ||||||
|     { |  | ||||||
|         $query = $this->queryJournalsNoBudget($account, $start, $end); |  | ||||||
|  |  | ||||||
|         return $query->get(['budgets.name', 'transactions.amount as queryAmount', 'transaction_journals.*']); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * This method returns all "income" journals in a certain period, which are both transfers from a shared account |      * This method returns all "income" journals in a certain period, which are both transfers from a shared account | ||||||
|      * and "ordinary" deposits. The query used is almost equal to ReportQueryInterface::journalsByRevenueAccount but it does |      * and "ordinary" deposits. The query used is almost equal to ReportQueryInterface::journalsByRevenueAccount but it does | ||||||
|      * not group and returns different fields. |      * not group and returns different fields. | ||||||
|  |  | ||||||
|      * |      * | ||||||
|      * @param Carbon $start |      * @param Carbon $start | ||||||
|      * @param Carbon $end |      * @param Carbon $end | ||||||
|      * @param bool   $showSharedReports |      * @param bool   $includeShared | ||||||
|      * |      * | ||||||
|      * @return Collection |      * @return Collection | ||||||
|      */ |      */ | ||||||
|     public function incomeByPeriod(Carbon $start, Carbon $end, $showSharedReports = false) |     public function incomeInPeriodCorrected(Carbon $start, Carbon $end, $includeShared = false) | ||||||
|     { |     { | ||||||
|         $query = $this->queryJournalsWithTransactions($start, $end); |         $query = $this->queryJournalsWithTransactions($start, $end); | ||||||
|         if ($showSharedReports === false) { |         if ($includeShared === false) { | ||||||
|             // only get deposits not to a shared account |             // only get deposits not to a shared account | ||||||
|             // and transfers to a shared account. |             // and transfers to a shared account. | ||||||
|             $query->where( |             $query->where( | ||||||
| @@ -230,219 +172,25 @@ class ReportQuery implements ReportQueryInterface | |||||||
|             // any deposit is fine. |             // any deposit is fine. | ||||||
|             $query->where('transaction_types.type', 'Deposit'); |             $query->where('transaction_types.type', 'Deposit'); | ||||||
|         } |         } | ||||||
|         $query->groupBy('transaction_journals.id')->orderBy('transaction_journals.date'); |         $query->orderBy('transaction_journals.date'); | ||||||
|  |  | ||||||
|         // get everything, decrypt and return |         // get everything | ||||||
|         $data = $query->get( |         $data = $query->get( | ||||||
|             ['transaction_journals.id', |             ['transaction_journals.*', 'transaction_types.type', 'ac_from.name as name', 'ac_from.id as account_id', 'ac_from.encrypted as account_encrypted'] | ||||||
|              'transaction_journals.description', |  | ||||||
|              'transaction_journals.encrypted', |  | ||||||
|              'transaction_types.type', |  | ||||||
|              DB::Raw('SUM(`t_to`.`amount`) as `queryAmount`'), |  | ||||||
|              'transaction_journals.date', |  | ||||||
|              't_from.account_id as account_id', |  | ||||||
|              'ac_from.name as name', |  | ||||||
|              'ac_from.encrypted as account_encrypted' |  | ||||||
|             ] |  | ||||||
|         ); |         ); | ||||||
|  |  | ||||||
|         $data->each( |         $data->each( | ||||||
|             function (Model $object) { |             function (TransactionJournal $journal) { | ||||||
|                 $object->name = intval($object->account_encrypted) == 1 ? Crypt::decrypt($object->name) : $object->name; |                 if (intval($journal->account_encrypted) == 1) { | ||||||
|             } |                     $journal->name = Crypt::decrypt($journal->name); | ||||||
|         ); |  | ||||||
|  |  | ||||||
|         return $data; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Gets a list of expenses grouped by the budget they were filed under. |  | ||||||
|      * |  | ||||||
|      * @param Carbon $start |  | ||||||
|      * @param Carbon $end |  | ||||||
|      * @param bool   $showSharedReports |  | ||||||
|      * |  | ||||||
|      * @return Collection |  | ||||||
|      */ |  | ||||||
|     public function journalsByBudget(Carbon $start, Carbon $end, $showSharedReports = false) |  | ||||||
|     { |  | ||||||
|         $query = Auth::user()->transactionjournals() |  | ||||||
|                      ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') |  | ||||||
|                      ->leftJoin('budgets', 'budget_transaction_journal.budget_id', '=', 'budgets.id') |  | ||||||
|                      ->leftJoin( |  | ||||||
|                          'transactions', function (JoinClause $join) { |  | ||||||
|                          $join->on('transaction_journals.id', '=', 'transactions.transaction_journal_id')->where('transactions.amount', '<', 0); |  | ||||||
|                      } |  | ||||||
|                      ) |  | ||||||
|                      ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id'); |  | ||||||
|         if ($showSharedReports === false) { |  | ||||||
|  |  | ||||||
|             $query->leftJoin( |  | ||||||
|                 'account_meta', function (JoinClause $join) { |  | ||||||
|                 $join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole'); |  | ||||||
|             } |  | ||||||
|             )->where('account_meta.data', '!=', '"sharedAsset"'); |  | ||||||
|         } |  | ||||||
|         $query->leftJoin('transaction_types', 'transaction_journals.transaction_type_id', '=', 'transaction_types.id') |  | ||||||
|               ->where('transaction_journals.date', '>=', $start->format('Y-m-d')) |  | ||||||
|               ->where('transaction_journals.date', '<=', $end->format('Y-m-d')) |  | ||||||
|               ->where('transaction_types.type', 'Withdrawal') |  | ||||||
|               ->groupBy('budgets.id') |  | ||||||
|               ->orderBy('budgets.name', 'ASC'); |  | ||||||
|  |  | ||||||
|         return $query->get(['budgets.id', 'budgets.name', DB::Raw('SUM(`transactions`.`amount`) AS `spent`')]); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Gets a list of categories and the expenses therein, grouped by the relevant category. |  | ||||||
|      * This result excludes transfers to shared accounts which are expenses, technically. |  | ||||||
|      * |  | ||||||
|      * @param Carbon $start |  | ||||||
|      * @param Carbon $end |  | ||||||
|      * @param bool   $showSharedReports |  | ||||||
|      * |  | ||||||
|      * @return Collection |  | ||||||
|      */ |  | ||||||
|     public function journalsByCategory(Carbon $start, Carbon $end, $showSharedReports = false) |  | ||||||
|     { |  | ||||||
|         $query = Auth::user()->transactionjournals() |  | ||||||
|                      ->leftJoin( |  | ||||||
|                          'category_transaction_journal', 'category_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id' |  | ||||||
|                      ) |  | ||||||
|                      ->leftJoin('categories', 'category_transaction_journal.category_id', '=', 'categories.id') |  | ||||||
|                      ->leftJoin( |  | ||||||
|                          'transactions', function (JoinClause $join) { |  | ||||||
|                          $join->on('transaction_journals.id', '=', 'transactions.transaction_journal_id')->where('transactions.amount', '<', 0); |  | ||||||
|                      } |  | ||||||
|                      ) |  | ||||||
|                      ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id'); |  | ||||||
|         if ($showSharedReports === false) { |  | ||||||
|             $query->leftJoin( |  | ||||||
|                 'account_meta', function (JoinClause $join) { |  | ||||||
|                 $join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole'); |  | ||||||
|             } |  | ||||||
|             )->where('account_meta.data', '!=', '"sharedAsset"'); |  | ||||||
|         } |  | ||||||
|         $query->leftJoin('transaction_types', 'transaction_journals.transaction_type_id', '=', 'transaction_types.id') |  | ||||||
|               ->where('transaction_journals.date', '>=', $start->format('Y-m-d')) |  | ||||||
|               ->where('transaction_journals.date', '<=', $end->format('Y-m-d')) |  | ||||||
|               ->where('transaction_types.type', 'Withdrawal') |  | ||||||
|               ->groupBy('categories.id') |  | ||||||
|               ->orderBy('queryAmount'); |  | ||||||
|  |  | ||||||
|         $data = $query->get(['categories.id', 'categories.encrypted', 'categories.name', DB::Raw('SUM(`transactions`.`amount`) AS `queryAmount`')]); |  | ||||||
|         // decrypt data: |  | ||||||
|         $data->each( |  | ||||||
|             function (Model $object) { |  | ||||||
|                 $object->name = intval($object->encrypted) == 1 ? Crypt::decrypt($object->name) : $object->name; |  | ||||||
|             } |  | ||||||
|         ); |  | ||||||
|  |  | ||||||
|         return $data; |  | ||||||
|  |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Gets a list of expense accounts and the expenses therein, grouped by that expense account. |  | ||||||
|      * This result excludes transfers to shared accounts which are expenses, technically. |  | ||||||
|      * |  | ||||||
|      * So now it will include them! |  | ||||||
|      * |  | ||||||
|      * @param Carbon $start |  | ||||||
|      * @param Carbon $end |  | ||||||
|      * @param bool   $showSharedReports |  | ||||||
|      * |  | ||||||
|      * @return Collection |  | ||||||
|      */ |  | ||||||
|     public function journalsByExpenseAccount(Carbon $start, Carbon $end, $showSharedReports = false) |  | ||||||
|     { |  | ||||||
|         $query = $this->queryJournalsWithTransactions($start, $end); |  | ||||||
|         if ($showSharedReports === false) { |  | ||||||
|             // get all withdrawals not from a shared accounts |  | ||||||
|             // and all transfers to a shared account |  | ||||||
|             $query->where( |  | ||||||
|                 function (Builder $query) { |  | ||||||
|                     $query->where( |  | ||||||
|                         function (Builder $q) { |  | ||||||
|                             $q->where('transaction_types.type', 'Withdrawal'); |  | ||||||
|                             $q->where('acm_from.data', '!=', '"sharedAsset"'); |  | ||||||
|                         } |  | ||||||
|                     ); |  | ||||||
|                     $query->orWhere( |  | ||||||
|                         function (Builder $q) { |  | ||||||
|                             $q->where('transaction_types.type', 'Transfer'); |  | ||||||
|                             $q->where('acm_to.data', '=', '"sharedAsset"'); |  | ||||||
|                         } |  | ||||||
|                     ); |  | ||||||
|                 } |                 } | ||||||
|             ); |  | ||||||
|         } else { |  | ||||||
|             // any withdrawal goes: |  | ||||||
|             $query->where('transaction_types.type', 'Withdrawal'); |  | ||||||
|         } |  | ||||||
|         $query->before($end)->after($start) |  | ||||||
|               ->where('transaction_journals.user_id', Auth::user()->id) |  | ||||||
|               ->groupBy('t_to.account_id') |  | ||||||
|               ->orderBy('queryAmount', 'DESC'); |  | ||||||
|  |  | ||||||
|         $data = $query->get(['t_to.account_id as id', 'ac_to.name as name', 'ac_to.encrypted', DB::Raw('SUM(t_to.amount) as `queryAmount`')]); |  | ||||||
|  |  | ||||||
|         // decrypt |  | ||||||
|         $data->each( |  | ||||||
|             function (Model $object) { |  | ||||||
|                 $object->name = intval($object->encrypted) == 1 ? Crypt::decrypt($object->name) : $object->name; |  | ||||||
|             } |             } | ||||||
|         ); |         ); | ||||||
|  |         $data = $data->filter( | ||||||
|         return $data; |             function (TransactionJournal $journal) { | ||||||
|     } |                 if ($journal->amount != 0) { | ||||||
|  |                     return $journal; | ||||||
|     /** |  | ||||||
|      * This method returns all deposits into asset accounts, grouped by the revenue account, |  | ||||||
|      * |  | ||||||
|      * @param Carbon $start |  | ||||||
|      * @param Carbon $end |  | ||||||
|      * @param bool   $showSharedReports |  | ||||||
|      * |  | ||||||
|      * @return Collection |  | ||||||
|      */ |  | ||||||
|     public function journalsByRevenueAccount(Carbon $start, Carbon $end, $showSharedReports = false) |  | ||||||
|     { |  | ||||||
|         $query = $this->queryJournalsWithTransactions($start, $end); |  | ||||||
|         if ($showSharedReports === false) { |  | ||||||
|  |  | ||||||
|             // show queries where transfer type is deposit, and its not to a shared account |  | ||||||
|             // or where its a transfer and its from a shared account (both count as incomes) |  | ||||||
|             $query->where( |  | ||||||
|                 function (Builder $query) { |  | ||||||
|                     $query->where( |  | ||||||
|                         function (Builder $q) { |  | ||||||
|                             $q->where('transaction_types.type', 'Deposit'); |  | ||||||
|                             $q->where('acm_to.data', '!=', '"sharedAsset"'); |  | ||||||
|                         } |  | ||||||
|                     ); |  | ||||||
|                     $query->orWhere( |  | ||||||
|                         function (Builder $q) { |  | ||||||
|                             $q->where('transaction_types.type', 'Transfer'); |  | ||||||
|                             $q->where('acm_from.data', '=', '"sharedAsset"'); |  | ||||||
|                         } |  | ||||||
|                     ); |  | ||||||
|                 } |                 } | ||||||
|             ); |  | ||||||
|         } else { |  | ||||||
|             // any deposit goes: |  | ||||||
|             $query->where('transaction_types.type', 'Deposit'); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         $query->groupBy('t_from.account_id')->orderBy('queryAmount'); |  | ||||||
|  |  | ||||||
|         $data = $query->get( |  | ||||||
|             ['t_from.account_id as account_id', 'ac_from.name as name', 'ac_from.encrypted as encrypted', DB::Raw('SUM(t_from.amount) as `queryAmount`')] |  | ||||||
|         ); |  | ||||||
|         // decrypt |  | ||||||
|         $data->each( |  | ||||||
|             function (Model $object) { |  | ||||||
|                 $object->name = intval($object->encrypted) == 1 ? Crypt::decrypt($object->name) : $object->name; |  | ||||||
|             } |             } | ||||||
|         ); |         ); | ||||||
|  |  | ||||||
| @@ -450,119 +198,53 @@ class ReportQuery implements ReportQueryInterface | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * With an equally misleading name, this query returns are transfers to shared accounts. These are considered |      * Covers tags | ||||||
|      * expenses. |  | ||||||
|      * |  | ||||||
|      * @param Carbon $start |  | ||||||
|      * @param Carbon $end |  | ||||||
|      * |  | ||||||
|      * @return Collection |  | ||||||
|      */ |  | ||||||
|     public function sharedExpenses(Carbon $start, Carbon $end) |  | ||||||
|     { |  | ||||||
|         return TransactionJournal:: |  | ||||||
|         leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') |  | ||||||
|                                  ->leftJoin( |  | ||||||
|                                      'transactions', function (JoinClause $join) { |  | ||||||
|                                      $join->on('transactions.transaction_journal_id', '=', 'transaction_journals.id')->where( |  | ||||||
|                                          'transactions.amount', '>', 0 |  | ||||||
|                                      ); |  | ||||||
|                                  } |  | ||||||
|                                  ) |  | ||||||
|                                  ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id') |  | ||||||
|                                  ->leftJoin( |  | ||||||
|                                      'account_meta', function (JoinClause $join) { |  | ||||||
|                                      $join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole'); |  | ||||||
|                                  } |  | ||||||
|                                  ) |  | ||||||
|                                  ->where('account_meta.data', '"sharedAsset"') |  | ||||||
|                                  ->after($start) |  | ||||||
|                                  ->before($end) |  | ||||||
|                                  ->where('transaction_types.type', 'Transfer') |  | ||||||
|                                  ->where('transaction_journals.user_id', Auth::user()->id) |  | ||||||
|                                  ->get( |  | ||||||
|                                      ['transaction_journals.id', 'transaction_journals.description', 'transactions.account_id', 'accounts.name', |  | ||||||
|                                       'transactions.amount as queryAmount'] |  | ||||||
|                                  ); |  | ||||||
|  |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * With a slightly misleading name, this query returns all transfers to shared accounts |  | ||||||
|      * which are technically expenses, since it won't be just your money that gets spend. |  | ||||||
|      * |  | ||||||
|      * @param Carbon $start |  | ||||||
|      * @param Carbon $end |  | ||||||
|      * |  | ||||||
|      * @return Collection |  | ||||||
|      */ |  | ||||||
|     public function sharedExpensesByCategory(Carbon $start, Carbon $end) |  | ||||||
|     { |  | ||||||
|         return TransactionJournal:: |  | ||||||
|         leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') |  | ||||||
|                                  ->leftJoin( |  | ||||||
|                                      'transactions', function (JoinClause $join) { |  | ||||||
|                                      $join->on('transactions.transaction_journal_id', '=', 'transaction_journals.id')->where( |  | ||||||
|                                          'transactions.amount', '>', 0 |  | ||||||
|                                      ); |  | ||||||
|                                  } |  | ||||||
|                                  ) |  | ||||||
|                                  ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id') |  | ||||||
|                                  ->leftJoin( |  | ||||||
|                                      'account_meta', function (JoinClause $join) { |  | ||||||
|                                      $join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole'); |  | ||||||
|                                  } |  | ||||||
|                                  ) |  | ||||||
|                                  ->leftJoin( |  | ||||||
|                                      'category_transaction_journal', 'category_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id' |  | ||||||
|                                  ) |  | ||||||
|                                  ->leftJoin('categories', 'category_transaction_journal.category_id', '=', 'categories.id') |  | ||||||
|                                  ->where('account_meta.data', '"sharedAsset"') |  | ||||||
|                                  ->after($start) |  | ||||||
|                                  ->before($end) |  | ||||||
|                                  ->where('transaction_types.type', 'Transfer') |  | ||||||
|                                  ->where('transaction_journals.user_id', Auth::user()->id) |  | ||||||
|                                  ->groupBy('categories.name') |  | ||||||
|                                  ->get( |  | ||||||
|                                      [ |  | ||||||
|                                          'categories.id', |  | ||||||
|                                          'categories.name as name', |  | ||||||
|                                          DB::Raw('SUM(`transactions`.`amount`) * -1 AS `queryAmount`') |  | ||||||
|                                      ] |  | ||||||
|                                  ); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * |  | ||||||
|      * This query will get all transaction journals and budget information for a specified account |  | ||||||
|      * in a certain date range, where the transaction journal does not have a budget. |  | ||||||
|      * There is no get() specified, this is up to the method itself. |  | ||||||
|      * |      * | ||||||
|      * @param Account $account |      * @param Account $account | ||||||
|  |      * @param Budget  $budget | ||||||
|      * @param Carbon  $start |      * @param Carbon  $start | ||||||
|      * @param Carbon  $end |      * @param Carbon  $end | ||||||
|      * |      * | ||||||
|      * @return Builder |      * @return float | ||||||
|      */ |      */ | ||||||
|     protected function queryJournalsNoBudget(Account $account, Carbon $start, Carbon $end) |     public function spentInBudgetCorrected(Account $account, Budget $budget, Carbon $start, Carbon $end) | ||||||
|     { |     { | ||||||
|         return TransactionJournal:: |  | ||||||
|         leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') |         return floatval( | ||||||
|                                  ->leftJoin('budgets', 'budgets.id', '=', 'budget_transaction_journal.budget_id') |                    Auth::user()->transactionjournals() | ||||||
|                                  ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') |                        ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') | ||||||
|                                  ->leftJoin( |                        ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') | ||||||
|                                      'transactions', function (JoinClause $join) { |                        ->transactionTypes(['Withdrawal']) | ||||||
|                                      $join->on('transactions.transaction_journal_id', '=', 'transaction_journals.id')->where('transactions.amount', '<', 0); |                        ->where('transactions.account_id', $account->id) | ||||||
|                                  } |                        ->before($end) | ||||||
|                                  ) |                        ->after($start) | ||||||
|                                  ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id') |                        ->where('budget_transaction_journal.budget_id', $budget->id) | ||||||
|                                  ->before($end) |                        ->get(['transaction_journals.*'])->sum('amount') | ||||||
|                                  ->after($start) |                ) * -1; | ||||||
|                                  ->where('accounts.id', $account->id) |     } | ||||||
|                                  ->where('transaction_journals.user_id', Auth::user()->id) |  | ||||||
|                                  ->where('transaction_types.type', 'Withdrawal') |     /** | ||||||
|                                  ->groupBy('budgets.id') |      * @param Account $account | ||||||
|                                  ->orderBy('budgets.name', 'ASC'); |      * @param Carbon  $start | ||||||
|  |      * @param Carbon  $end | ||||||
|  |      * @param bool    $shared | ||||||
|  |      * | ||||||
|  |      * @return float | ||||||
|  |      */ | ||||||
|  |     public function spentNoBudget(Account $account, Carbon $start, Carbon $end, $shared = false) | ||||||
|  |     { | ||||||
|  |         return floatval( | ||||||
|  |             Auth::user()->transactionjournals() | ||||||
|  |                 ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') | ||||||
|  |                 ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') | ||||||
|  |                 ->where('transactions.amount', '<', 0) | ||||||
|  |                 ->transactionTypes(['Withdrawal']) | ||||||
|  |                 ->where('transactions.account_id', $account->id) | ||||||
|  |                 ->before($end) | ||||||
|  |                 ->after($start) | ||||||
|  |                 ->whereNull('budget_transaction_journal.budget_id') | ||||||
|  |                 ->sum('transactions.amount') | ||||||
|  |         ); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -601,5 +283,4 @@ class ReportQuery implements ReportQueryInterface | |||||||
|  |  | ||||||
|         return $query; |         return $query; | ||||||
|     } |     } | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -4,6 +4,7 @@ namespace FireflyIII\Helpers\Report; | |||||||
|  |  | ||||||
| use Carbon\Carbon; | use Carbon\Carbon; | ||||||
| use FireflyIII\Models\Account; | use FireflyIII\Models\Account; | ||||||
|  | use FireflyIII\Models\Budget; | ||||||
| use Illuminate\Support\Collection; | use Illuminate\Support\Collection; | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @@ -15,152 +16,66 @@ interface ReportQueryInterface | |||||||
| { | { | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * This query retrieves a list of accounts that are active and not shared. |      * See ReportQueryInterface::incomeInPeriodCorrected | ||||||
|      * |      * | ||||||
|      * @param bool $showSharedReports |      * This method returns all "expense" journals in a certain period, which are both transfers to a shared account | ||||||
|  |      * and "ordinary" withdrawals. The query used is almost equal to ReportQueryInterface::journalsByRevenueAccount but it does | ||||||
|  |      * not group and returns different fields. | ||||||
|  |      * | ||||||
|  |      * @param Carbon $start | ||||||
|  |      * @param Carbon $end | ||||||
|  |      * @param bool   $includeShared | ||||||
|      * |      * | ||||||
|      * @return Collection |      * @return Collection | ||||||
|  |      * | ||||||
|      */ |      */ | ||||||
|     public function accountList($showSharedReports = false); |     public function expenseInPeriodCorrected(Carbon $start, Carbon $end, $includeShared = false); | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * This method will get a list of all expenses in a certain time period that have no budget |  | ||||||
|      * and are balanced by a transfer to make up for it. |  | ||||||
|      * |  | ||||||
|      * @param Account $account |  | ||||||
|      * @param Carbon  $start |  | ||||||
|      * @param Carbon  $end |  | ||||||
|      * |  | ||||||
|      * @return Collection |  | ||||||
|      */ |  | ||||||
|     public function balancedTransactionsList(Account $account, Carbon $start, Carbon $end); |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * This method will get the sum of all expenses in a certain time period that have no budget |  | ||||||
|      * and are balanced by a transfer to make up for it. |  | ||||||
|      * |  | ||||||
|      * @param Account $account |  | ||||||
|      * @param Carbon  $start |  | ||||||
|      * @param Carbon  $end |  | ||||||
|      * |  | ||||||
|      * @return float |  | ||||||
|      */ |  | ||||||
|     public function balancedTransactionsSum(Account $account, Carbon $start, Carbon $end); |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Get a users accounts combined with various meta-data related to the start and end date. |      * Get a users accounts combined with various meta-data related to the start and end date. | ||||||
|      * |      * | ||||||
|      * @param Carbon $start |      * @param Carbon $start | ||||||
|      * @param Carbon $end |      * @param Carbon $end | ||||||
|      * @param bool   $showSharedReports |      * @param bool   $includeShared | ||||||
|      * |      * | ||||||
|      * @return Collection |      * @return Collection | ||||||
|      */ |      */ | ||||||
|     public function getAllAccounts(Carbon $start, Carbon $end, $showSharedReports = false); |     public function getAllAccounts(Carbon $start, Carbon $end, $includeShared = false); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Grabs a summary of all expenses grouped by budget, related to the account. |      * This method works the same way as ReportQueryInterface::incomeInPeriod does, but instead of returning results | ||||||
|  |      * will simply list the transaction journals only. This should allow any follow up counting to be accurate with | ||||||
|  |      * regards to tags. | ||||||
|  |      * | ||||||
|  |      * @param Carbon $start | ||||||
|  |      * @param Carbon $end | ||||||
|  |      * @param bool   $includeShared | ||||||
|  |      * | ||||||
|  |      * @return Collection | ||||||
|  |      */ | ||||||
|  |     public function incomeInPeriodCorrected(Carbon $start, Carbon $end, $includeShared = false); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Covers tags as well. | ||||||
|      * |      * | ||||||
|      * @param Account $account |      * @param Account $account | ||||||
|  |      * @param Budget  $budget | ||||||
|      * @param Carbon  $start |      * @param Carbon  $start | ||||||
|      * @param Carbon  $end |      * @param Carbon  $end | ||||||
|      * |      * | ||||||
|      * @return mixed |      * @return float | ||||||
|      */ |      */ | ||||||
|     public function getBudgetSummary(Account $account, Carbon $start, Carbon $end); |     public function spentInBudgetCorrected(Account $account, Budget $budget, Carbon $start, Carbon $end); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Get a list of transaction journals that have no budget, filtered for the specified account |  | ||||||
|      * and the specified date range. |  | ||||||
|      * |  | ||||||
|      * @param Account $account |      * @param Account $account | ||||||
|      * @param Carbon  $start |      * @param Carbon  $start | ||||||
|      * @param Carbon  $end |      * @param Carbon  $end | ||||||
|  |      * @param bool    $shared | ||||||
|      * |      * | ||||||
|      * @return Collection |      * @return float | ||||||
|      */ |      */ | ||||||
|     public function getTransactionsWithoutBudget(Account $account, Carbon $start, Carbon $end); |     public function spentNoBudget(Account $account, Carbon $start, Carbon $end, $shared = false); | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * This method returns all "income" journals in a certain period, which are both transfers from a shared account |  | ||||||
|      * and "ordinary" deposits. The query used is almost equal to ReportQueryInterface::journalsByRevenueAccount but it does |  | ||||||
|      * not group and returns different fields. |  | ||||||
|      * |  | ||||||
|      * @param Carbon $start |  | ||||||
|      * @param Carbon $end |  | ||||||
|      * @param bool   $showSharedReports |  | ||||||
|      * |  | ||||||
|      * @return Collection |  | ||||||
|      */ |  | ||||||
|     public function incomeByPeriod(Carbon $start, Carbon $end, $showSharedReports = false); |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Gets a list of expenses grouped by the budget they were filed under. |  | ||||||
|      * |  | ||||||
|      * @param Carbon $start |  | ||||||
|      * @param Carbon $end |  | ||||||
|      * @param bool   $showSharedReports |  | ||||||
|      * |  | ||||||
|      * @return Collection |  | ||||||
|      */ |  | ||||||
|     public function journalsByBudget(Carbon $start, Carbon $end, $showSharedReports = false); |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Gets a list of categories and the expenses therein, grouped by the relevant category. |  | ||||||
|      * This result excludes transfers to shared accounts which are expenses, technically. |  | ||||||
|      * |  | ||||||
|      * @param Carbon $start |  | ||||||
|      * @param Carbon $end |  | ||||||
|      * @param bool   $showSharedReports |  | ||||||
|      * |  | ||||||
|      * @return Collection |  | ||||||
|      */ |  | ||||||
|     public function journalsByCategory(Carbon $start, Carbon $end, $showSharedReports = false); |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Gets a list of expense accounts and the expenses therein, grouped by that expense account. |  | ||||||
|      * This result excludes transfers to shared accounts which are expenses, technically. |  | ||||||
|      * |  | ||||||
|      * So now it will include them! |  | ||||||
|      * |  | ||||||
|      * @param Carbon $start |  | ||||||
|      * @param Carbon $end |  | ||||||
|      * @param bool   $showSharedReports |  | ||||||
|      * |  | ||||||
|      * @return Collection |  | ||||||
|      */ |  | ||||||
|     public function journalsByExpenseAccount(Carbon $start, Carbon $end, $showSharedReports = false); |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * This method returns all deposits into asset accounts, grouped by the revenue account, |  | ||||||
|      * |  | ||||||
|      * @param Carbon $start |  | ||||||
|      * @param Carbon $end |  | ||||||
|      * @param bool   $showSharedReports |  | ||||||
|      * |  | ||||||
|      * @return Collection |  | ||||||
|      */ |  | ||||||
|     public function journalsByRevenueAccount(Carbon $start, Carbon $end, $showSharedReports = false); |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * With an equally misleading name, this query returns are transfers to shared accounts. These are considered |  | ||||||
|      * expenses. |  | ||||||
|      * |  | ||||||
|      * @param Carbon $start |  | ||||||
|      * @param Carbon $end |  | ||||||
|      * |  | ||||||
|      * @return Collection |  | ||||||
|      */ |  | ||||||
|     public function sharedExpenses(Carbon $start, Carbon $end); |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * With a slightly misleading name, this query returns all transfers to shared accounts |  | ||||||
|      * which are technically expenses, since it won't be just your money that gets spend. |  | ||||||
|      * |  | ||||||
|      * @param Carbon $start |  | ||||||
|      * @param Carbon $end |  | ||||||
|      * |  | ||||||
|      * @return Collection |  | ||||||
|      */ |  | ||||||
|     public function sharedExpensesByCategory(Carbon $start, Carbon $end); |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -28,7 +28,7 @@ class AccountController extends Controller | |||||||
|     { |     { | ||||||
|         parent::__construct(); |         parent::__construct(); | ||||||
|         View::share('mainTitleIcon', 'fa-credit-card'); |         View::share('mainTitleIcon', 'fa-credit-card'); | ||||||
|         View::share('title', 'Accounts'); |         View::share('title', trans('firefly.accounts')); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -67,11 +67,12 @@ class AccountController extends Controller | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @param Account $account |      * @param AccountRepositoryInterface $repository | ||||||
|  |      * @param Account                    $account | ||||||
|      * |      * | ||||||
|      * @return \Illuminate\Http\RedirectResponse |      * @return \Illuminate\Http\RedirectResponse | ||||||
|      */ |      */ | ||||||
|     public function destroy(Account $account, AccountRepositoryInterface $repository) |     public function destroy(AccountRepositoryInterface $repository, Account $account) | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $type     = $account->accountType->type; |         $type     = $account->accountType->type; | ||||||
| @@ -86,16 +87,16 @@ class AccountController extends Controller | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @param Account                    $account |  | ||||||
|      * @param AccountRepositoryInterface $repository |      * @param AccountRepositoryInterface $repository | ||||||
|  |      * @param Account                    $account | ||||||
|      * |      * | ||||||
|      * @return View |      * @return View | ||||||
|      */ |      */ | ||||||
|     public function edit(Account $account, AccountRepositoryInterface $repository) |     public function edit(AccountRepositoryInterface $repository, Account $account) | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $what           = Config::get('firefly.shortNamesByFullName')[$account->accountType->type]; |         $what           = Config::get('firefly.shortNamesByFullName')[$account->accountType->type]; | ||||||
|         $subTitle       = 'Edit ' . strtolower(e($account->accountType->type)) . ' "' . e($account->name) . '"'; |         $subTitle       = trans('firefly.edit_' . $what . '_account', ['name' => $account->name]); | ||||||
|         $subTitleIcon   = Config::get('firefly.subIconsByIdentifier.' . $what); |         $subTitleIcon   = Config::get('firefly.subIconsByIdentifier.' . $what); | ||||||
|         $openingBalance = $repository->openingBalanceTransaction($account); |         $openingBalance = $repository->openingBalanceTransaction($account); | ||||||
|  |  | ||||||
| @@ -129,14 +130,14 @@ class AccountController extends Controller | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @param                            $what |  | ||||||
|      * @param AccountRepositoryInterface $repository |      * @param AccountRepositoryInterface $repository | ||||||
|  |      * @param                            $what | ||||||
|      * |      * | ||||||
|      * @return View |      * @return View | ||||||
|      */ |      */ | ||||||
|     public function index($what, AccountRepositoryInterface $repository) |     public function index(AccountRepositoryInterface $repository, $what) | ||||||
|     { |     { | ||||||
|         $subTitle     = Config::get('firefly.subTitlesByIdentifier.' . $what); |         $subTitle     = trans('firefly.' . $what . '_accounts'); | ||||||
|         $subTitleIcon = Config::get('firefly.subIconsByIdentifier.' . $what); |         $subTitleIcon = Config::get('firefly.subIconsByIdentifier.' . $what); | ||||||
|         $types        = Config::get('firefly.accountTypesByIdentifier.' . $what); |         $types        = Config::get('firefly.accountTypesByIdentifier.' . $what); | ||||||
|         $accounts     = $repository->getAccounts($types); |         $accounts     = $repository->getAccounts($types); | ||||||
| @@ -158,18 +159,18 @@ class AccountController extends Controller | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @param Account                    $account |  | ||||||
|      * @param AccountRepositoryInterface $repository |      * @param AccountRepositoryInterface $repository | ||||||
|  |      * @param Account                    $account | ||||||
|      * |      * | ||||||
|      * @return View |      * @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')); |         $page         = intval(Input::get('page')) == 0 ? 1 : intval(Input::get('page')); | ||||||
|         $subTitleIcon = Config::get('firefly.subTitlesByIdentifier.' . $account->accountType->type); |         $subTitleIcon = Config::get('firefly.subTitlesByIdentifier.' . $account->accountType->type); | ||||||
|         $what         = Config::get('firefly.shortNamesByFullName.' . $account->accountType->type); |         $what         = Config::get('firefly.shortNamesByFullName.' . $account->accountType->type); | ||||||
|         $journals     = $repository->getJournals($account, $page); |         $journals     = $repository->getJournals($account, $page); | ||||||
|         $subTitle     = 'Details for ' . strtolower(e($account->accountType->type)) . ' "' . e($account->name) . '"'; |         $subTitle     = trans('firefly.details_for_' . $what, ['name' => $account->name]); | ||||||
|         $journals->setPath('accounts/show/' . $account->id); |         $journals->setPath('accounts/show/' . $account->id); | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -214,13 +215,13 @@ class AccountController extends Controller | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @param Account                    $account |  | ||||||
|      * @param AccountFormRequest         $request |      * @param AccountFormRequest         $request | ||||||
|      * @param AccountRepositoryInterface $repository |      * @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) | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $accountData = [ |         $accountData = [ | ||||||
|   | |||||||
| @@ -39,6 +39,8 @@ class AuthController extends Controller | |||||||
|      * @param  \Illuminate\Contracts\Auth\Guard     $auth |      * @param  \Illuminate\Contracts\Auth\Guard     $auth | ||||||
|      * @param  \Illuminate\Contracts\Auth\Registrar $registrar |      * @param  \Illuminate\Contracts\Auth\Registrar $registrar | ||||||
|      * |      * | ||||||
|  |      * @codeCoverageIgnore | ||||||
|  |      * | ||||||
|      */ |      */ | ||||||
|     public function __construct(Guard $auth, Registrar $registrar) |     public function __construct(Guard $auth, Registrar $registrar) | ||||||
|     { |     { | ||||||
| @@ -51,7 +53,9 @@ class AuthController extends Controller | |||||||
|     /** |     /** | ||||||
|      * Show the application login form. |      * Show the application login form. | ||||||
|      * |      * | ||||||
|  |      * @codeCoverageIgnore | ||||||
|      * @return \Illuminate\Http\Response |      * @return \Illuminate\Http\Response | ||||||
|  |      * | ||||||
|      */ |      */ | ||||||
|     public function getLogin() |     public function getLogin() | ||||||
|     { |     { | ||||||
| @@ -73,7 +77,9 @@ class AuthController extends Controller | |||||||
|             $this->throwValidationException( |             $this->throwValidationException( | ||||||
|                 $request, $validator |                 $request, $validator | ||||||
|             ); |             ); | ||||||
|  |             // @codeCoverageIgnoreStart | ||||||
|         } |         } | ||||||
|  |         // @codeCoverageIgnoreEnd | ||||||
|  |  | ||||||
|         $data             = $request->all(); |         $data             = $request->all(); | ||||||
|         $data['password'] = bcrypt($data['password']); |         $data['password'] = bcrypt($data['password']); | ||||||
|   | |||||||
| @@ -8,6 +8,7 @@ use Illuminate\Foundation\Auth\ResetsPasswords; | |||||||
| /** | /** | ||||||
|  * Class PasswordController |  * Class PasswordController | ||||||
|  * |  * | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  * @package FireflyIII\Http\Controllers\Auth |  * @package FireflyIII\Http\Controllers\Auth | ||||||
|  */ |  */ | ||||||
| class PasswordController extends Controller | class PasswordController extends Controller | ||||||
|   | |||||||
| @@ -4,11 +4,9 @@ use Config; | |||||||
| use FireflyIII\Http\Requests; | use FireflyIII\Http\Requests; | ||||||
| use FireflyIII\Http\Requests\BillFormRequest; | use FireflyIII\Http\Requests\BillFormRequest; | ||||||
| use FireflyIII\Models\Account; | use FireflyIII\Models\Account; | ||||||
| use FireflyIII\Models\AccountType; |  | ||||||
| use FireflyIII\Models\Bill; | use FireflyIII\Models\Bill; | ||||||
| use FireflyIII\Models\Transaction; | use FireflyIII\Models\Transaction; | ||||||
| use FireflyIII\Models\TransactionJournal; | use FireflyIII\Models\TransactionJournal; | ||||||
| use FireflyIII\Repositories\Account\AccountRepositoryInterface; |  | ||||||
| use FireflyIII\Repositories\Bill\BillRepositoryInterface; | use FireflyIII\Repositories\Bill\BillRepositoryInterface; | ||||||
| use Input; | use Input; | ||||||
| use Redirect; | use Redirect; | ||||||
| @@ -30,53 +28,10 @@ class BillController extends Controller | |||||||
|     public function __construct() |     public function __construct() | ||||||
|     { |     { | ||||||
|         parent::__construct(); |         parent::__construct(); | ||||||
|         View::share('title', 'Bills'); |         View::share('title', trans('firefly.bills')); | ||||||
|         View::share('mainTitleIcon', 'fa-calendar-o'); |         View::share('mainTitleIcon', 'fa-calendar-o'); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * @param Bill $bill |  | ||||||
|      * |  | ||||||
|      * @return \Illuminate\Http\RedirectResponse |  | ||||||
|      */ |  | ||||||
|     public function add(Bill $bill, AccountRepositoryInterface $repository) |  | ||||||
|     { |  | ||||||
|         $matches     = explode(',', $bill->match); |  | ||||||
|         $description = []; |  | ||||||
|         $expense     = null; |  | ||||||
|  |  | ||||||
|         // get users expense accounts: |  | ||||||
|         $accounts = $repository->getAccounts(Config::get('firefly.accountTypesByIdentifier.expense')); |  | ||||||
|  |  | ||||||
|         foreach ($matches as $match) { |  | ||||||
|             $match = strtolower($match); |  | ||||||
|             // find expense account for each word if not found already: |  | ||||||
|             if (is_null($expense)) { |  | ||||||
|                 /** @var Account $account */ |  | ||||||
|                 foreach ($accounts as $account) { |  | ||||||
|                     $name = strtolower($account->name); |  | ||||||
|                     if (!(strpos($name, $match) === false)) { |  | ||||||
|                         $expense = $account; |  | ||||||
|                         break; |  | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
|  |  | ||||||
|  |  | ||||||
|             } |  | ||||||
|             if (is_null($expense)) { |  | ||||||
|                 $description[] = $match; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         $parameters = [ |  | ||||||
|             'description'     => ucfirst(join(' ', $description)), |  | ||||||
|             'expense_account' => is_null($expense) ? '' : $expense->name, |  | ||||||
|             'amount'          => round(($bill->amount_min + $bill->amount_max), 2), |  | ||||||
|         ]; |  | ||||||
|         Session::put('preFilled', $parameters); |  | ||||||
|  |  | ||||||
|         return Redirect::to(route('transactions.create', 'withdrawal')); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @return $this |      * @return $this | ||||||
|      */ |      */ | ||||||
| @@ -89,8 +44,9 @@ class BillController extends Controller | |||||||
|             Session::put('bills.create.url', URL::previous()); |             Session::put('bills.create.url', URL::previous()); | ||||||
|         } |         } | ||||||
|         Session::forget('bills.create.fromStore'); |         Session::forget('bills.create.fromStore'); | ||||||
|  |         $subTitle = 'Create new bill'; | ||||||
|  |  | ||||||
|         return view('bills.create')->with('periods', $periods)->with('subTitle', 'Create new'); |         return view('bills.create', compact('periods', 'subTitle')); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -102,16 +58,18 @@ class BillController extends Controller | |||||||
|     { |     { | ||||||
|         // put previous url in session |         // put previous url in session | ||||||
|         Session::put('bills.delete.url', URL::previous()); |         Session::put('bills.delete.url', URL::previous()); | ||||||
|  |         $subTitle = 'Delete "' . e($bill->name) . '"'; | ||||||
|  |  | ||||||
|         return view('bills.delete')->with('bill', $bill)->with('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 |      * @return \Illuminate\Http\RedirectResponse | ||||||
|      */ |      */ | ||||||
|     public function destroy(Bill $bill, BillRepositoryInterface $repository) |     public function destroy(BillRepositoryInterface $repository, Bill $bill) | ||||||
|     { |     { | ||||||
|         $repository->destroy($bill); |         $repository->destroy($bill); | ||||||
|  |  | ||||||
| @@ -128,7 +86,8 @@ class BillController extends Controller | |||||||
|      */ |      */ | ||||||
|     public function edit(Bill $bill) |     public function edit(Bill $bill) | ||||||
|     { |     { | ||||||
|         $periods = Config::get('firefly.periods_to_text'); |         $periods  = Config::get('firefly.periods_to_text'); | ||||||
|  |         $subTitle = 'Edit "' . e($bill->name) . '"'; | ||||||
|  |  | ||||||
|         // put previous url in session if not redirect from store (not "return_to_edit"). |         // put previous url in session if not redirect from store (not "return_to_edit"). | ||||||
|         if (Session::get('bills.edit.fromUpdate') !== true) { |         if (Session::get('bills.edit.fromUpdate') !== true) { | ||||||
| @@ -136,7 +95,7 @@ class BillController extends Controller | |||||||
|         } |         } | ||||||
|         Session::forget('bills.edit.fromUpdate'); |         Session::forget('bills.edit.fromUpdate'); | ||||||
|  |  | ||||||
|         return view('bills.edit')->with('periods', $periods)->with('bill', $bill)->with('subTitle', 'Edit "' . e($bill->name) . '"'); |         return view('bills.edit', compact('subTitle', 'periods', 'bill')); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -158,11 +117,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) { |         if (intval($bill->active) == 0) { | ||||||
|             Session::flash('warning', 'Inactive bills cannot be scanned.'); |             Session::flash('warning', 'Inactive bills cannot be scanned.'); | ||||||
| @@ -183,21 +143,26 @@ class BillController extends Controller | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @param Bill $bill |      * @param BillRepositoryInterface $repository | ||||||
|  |      * @param Bill                    $bill | ||||||
|      * |      * | ||||||
|      * @return mixed |      * @return mixed | ||||||
|      */ |      */ | ||||||
|     public function show(Bill $bill, BillRepositoryInterface $repository) |     public function show(BillRepositoryInterface $repository, Bill $bill) | ||||||
|     { |     { | ||||||
|         $journals                = $repository->getJournals($bill); |         $journals                = $repository->getJournals($bill); | ||||||
|         $bill->nextExpectedMatch = $repository->nextExpectedMatch($bill); |         $bill->nextExpectedMatch = $repository->nextExpectedMatch($bill); | ||||||
|         $hideBill                = true; |         $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) |     public function store(BillFormRequest $request, BillRepositoryInterface $repository) | ||||||
|     { |     { | ||||||
| @@ -218,11 +183,13 @@ class BillController extends Controller | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @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(); |         $billData = $request->getBillData(); | ||||||
|         $bill     = $repository->update($bill, $billData); |         $bill     = $repository->update($bill, $billData); | ||||||
|   | |||||||
| @@ -5,7 +5,6 @@ use Carbon\Carbon; | |||||||
| use FireflyIII\Http\Requests; | use FireflyIII\Http\Requests; | ||||||
| use FireflyIII\Http\Requests\BudgetFormRequest; | use FireflyIII\Http\Requests\BudgetFormRequest; | ||||||
| use FireflyIII\Models\Budget; | use FireflyIII\Models\Budget; | ||||||
| use FireflyIII\Models\BudgetLimit; |  | ||||||
| use FireflyIII\Models\LimitRepetition; | use FireflyIII\Models\LimitRepetition; | ||||||
| use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; | use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; | ||||||
| use Input; | use Input; | ||||||
| @@ -30,17 +29,18 @@ class BudgetController extends Controller | |||||||
|     public function __construct() |     public function __construct() | ||||||
|     { |     { | ||||||
|         parent::__construct(); |         parent::__construct(); | ||||||
|         View::share('title', 'Budgets'); |         View::share('title', trans('firefly.budgets')); | ||||||
|         View::share('mainTitleIcon', 'fa-tasks'); |         View::share('mainTitleIcon', 'fa-tasks'); | ||||||
|         View::share('hideBudgets', true); |         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')); |         $amount          = intval(Input::get('amount')); | ||||||
|         $date            = Session::get('start', Carbon::now()->startOfMonth()); |         $date            = Session::get('start', Carbon::now()->startOfMonth()); | ||||||
| @@ -60,8 +60,9 @@ class BudgetController extends Controller | |||||||
|             Session::put('budgets.create.url', URL::previous()); |             Session::put('budgets.create.url', URL::previous()); | ||||||
|         } |         } | ||||||
|         Session::forget('budgets.create.fromStore'); |         Session::forget('budgets.create.fromStore'); | ||||||
|  |         $subTitle = trans('firefly.create_new_budget'); | ||||||
|  |  | ||||||
|         return view('budgets.create')->with('subTitle', 'Create a new budget'); |         return view('budgets.create', compact('subTitle')); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -80,7 +81,8 @@ class BudgetController extends Controller | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @param Budget $budget |      * @param Budget                    $budget | ||||||
|  |      * @param BudgetRepositoryInterface $repository | ||||||
|      * |      * | ||||||
|      * @return \Illuminate\Http\RedirectResponse |      * @return \Illuminate\Http\RedirectResponse | ||||||
|      */ |      */ | ||||||
| @@ -116,7 +118,9 @@ class BudgetController extends Controller | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @return mixed |      * @param BudgetRepositoryInterface $repository | ||||||
|  |      * | ||||||
|  |      * @return View | ||||||
|      */ |      */ | ||||||
|     public function index(BudgetRepositoryInterface $repository) |     public function index(BudgetRepositoryInterface $repository) | ||||||
|     { |     { | ||||||
| @@ -133,7 +137,8 @@ class BudgetController extends Controller | |||||||
|         $budgets->each( |         $budgets->each( | ||||||
|             function (Budget $budget) use ($repository) { |             function (Budget $budget) use ($repository) { | ||||||
|                 $date               = Session::get('start', Carbon::now()->startOfMonth()); |                 $date               = Session::get('start', Carbon::now()->startOfMonth()); | ||||||
|                 $budget->spent      = $repository->spentInMonth($budget, $date); |                 $end                = Session::get('end', Carbon::now()->endOfMonth()); | ||||||
|  |                 $budget->spent      = $repository->spentInPeriodCorrected($budget, $date, $end); | ||||||
|                 $budget->currentRep = $repository->getCurrentRepetition($budget, $date); |                 $budget->currentRep = $repository->getCurrentRepetition($budget, $date); | ||||||
|             } |             } | ||||||
|         ); |         ); | ||||||
| @@ -150,7 +155,9 @@ class BudgetController extends Controller | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @return \Illuminate\View\View |      * @param BudgetRepositoryInterface $repository | ||||||
|  |      * | ||||||
|  |      * @return View | ||||||
|      */ |      */ | ||||||
|     public function noBudget(BudgetRepositoryInterface $repository) |     public function noBudget(BudgetRepositoryInterface $repository) | ||||||
|     { |     { | ||||||
| @@ -163,7 +170,7 @@ class BudgetController extends Controller | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @return mixed |      * @return \Illuminate\Http\RedirectResponse | ||||||
|      */ |      */ | ||||||
|     public function postUpdateIncome() |     public function postUpdateIncome() | ||||||
|     { |     { | ||||||
| @@ -175,16 +182,18 @@ class BudgetController extends Controller | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * @param BudgetRepositoryInterface $repository | ||||||
|  |      * @param Budget                    $budget | ||||||
|  |      * @param LimitRepetition           $repetition | ||||||
|      * |      * | ||||||
|      * @param Budget          $budget |      * @return View | ||||||
|      * @param LimitRepetition $repetition |  | ||||||
|      * |  | ||||||
|      * @return \Illuminate\View\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) { |         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')); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         $journals = $repository->getJournals($budget, $repetition); |         $journals = $repository->getJournals($budget, $repetition); | ||||||
| @@ -224,13 +233,13 @@ class BudgetController extends Controller | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @param Budget                    $budget |  | ||||||
|      * @param BudgetFormRequest         $request |      * @param BudgetFormRequest         $request | ||||||
|      * @param BudgetRepositoryInterface $repository |      * @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 = [ |         $budgetData = [ | ||||||
|             'name'   => $request->input('name'), |             'name'   => $request->input('name'), | ||||||
| @@ -254,14 +263,14 @@ class BudgetController extends Controller | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @return $this |      * @return View | ||||||
|      */ |      */ | ||||||
|     public function updateIncome() |     public function updateIncome() | ||||||
|     { |     { | ||||||
|         $date         = Session::get('start', Carbon::now()->startOfMonth())->format('FY'); |         $date   = Session::get('start', Carbon::now()->startOfMonth())->format('FY'); | ||||||
|         $budgetAmount = Preferences::get('budgetIncomeTotal' . $date, 1000); |         $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 Auth; | ||||||
| use Carbon\Carbon; | use Carbon\Carbon; | ||||||
| use FireflyIII\Http\Requests; |  | ||||||
| use FireflyIII\Http\Requests\CategoryFormRequest; | use FireflyIII\Http\Requests\CategoryFormRequest; | ||||||
| use FireflyIII\Models\Category; | use FireflyIII\Models\Category; | ||||||
| use FireflyIII\Repositories\Category\CategoryRepositoryInterface; | use FireflyIII\Repositories\Category\CategoryRepositoryInterface; | ||||||
| @@ -27,7 +26,7 @@ class CategoryController extends Controller | |||||||
|     public function __construct() |     public function __construct() | ||||||
|     { |     { | ||||||
|         parent::__construct(); |         parent::__construct(); | ||||||
|         View::share('title', 'Categories'); |         View::share('title', trans('firefly.categories')); | ||||||
|         View::share('mainTitleIcon', 'fa-bar-chart'); |         View::share('mainTitleIcon', 'fa-bar-chart'); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -41,8 +40,9 @@ class CategoryController extends Controller | |||||||
|             Session::put('categories.create.url', URL::previous()); |             Session::put('categories.create.url', URL::previous()); | ||||||
|         } |         } | ||||||
|         Session::forget('categories.create.fromStore'); |         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')); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -61,11 +61,12 @@ class CategoryController extends Controller | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @param Category $category |      * @param CategoryRepositoryInterface $repository | ||||||
|  |      * @param Category                    $category | ||||||
|      * |      * | ||||||
|      * @return \Illuminate\Http\RedirectResponse |      * @return \Illuminate\Http\RedirectResponse | ||||||
|      */ |      */ | ||||||
|     public function destroy(Category $category, CategoryRepositoryInterface $repository) |     public function destroy(CategoryRepositoryInterface $repository, Category $category) | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $name = $category->name; |         $name = $category->name; | ||||||
| @@ -96,8 +97,9 @@ class CategoryController extends Controller | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @return $this |      * @param CategoryRepositoryInterface $repository | ||||||
|      * |      * | ||||||
|  |      * @return $this | ||||||
|      */ |      */ | ||||||
|     public function index(CategoryRepositoryInterface $repository) |     public function index(CategoryRepositoryInterface $repository) | ||||||
|     { |     { | ||||||
| @@ -113,6 +115,8 @@ class CategoryController extends Controller | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * @param CategoryRepositoryInterface $repository | ||||||
|  |      * | ||||||
|      * @return \Illuminate\View\View |      * @return \Illuminate\View\View | ||||||
|      */ |      */ | ||||||
|     public function noCategory(CategoryRepositoryInterface $repository) |     public function noCategory(CategoryRepositoryInterface $repository) | ||||||
| @@ -126,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. |         $hideCategory = true; // used in list. | ||||||
|         $page         = intval(Input::get('page')); |         $page         = intval(Input::get('page')); | ||||||
| @@ -169,13 +174,13 @@ class CategoryController extends Controller | |||||||
|  |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @param Category                    $category |  | ||||||
|      * @param CategoryFormRequest         $request |      * @param CategoryFormRequest         $request | ||||||
|      * @param CategoryRepositoryInterface $repository |      * @param CategoryRepositoryInterface $repository | ||||||
|  |      * @param Category                    $category | ||||||
|      * |      * | ||||||
|      * @return \Illuminate\Http\RedirectResponse |      * @return \Illuminate\Http\RedirectResponse | ||||||
|      */ |      */ | ||||||
|     public function update(Category $category, CategoryFormRequest $request, CategoryRepositoryInterface $repository) |     public function update(CategoryFormRequest $request, CategoryRepositoryInterface $repository, Category $category) | ||||||
|     { |     { | ||||||
|         $categoryData = [ |         $categoryData = [ | ||||||
|             'name' => $request->input('name'), |             'name' => $request->input('name'), | ||||||
|   | |||||||
							
								
								
									
										150
									
								
								app/Http/Controllers/Chart/AccountController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										150
									
								
								app/Http/Controllers/Chart/AccountController.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,150 @@ | |||||||
|  | <?php | ||||||
|  |  | ||||||
|  | namespace FireflyIII\Http\Controllers\Chart; | ||||||
|  |  | ||||||
|  | use Carbon\Carbon; | ||||||
|  | use FireflyIII\Http\Controllers\Controller; | ||||||
|  | use FireflyIII\Models\Account; | ||||||
|  | use FireflyIII\Repositories\Account\AccountRepositoryInterface; | ||||||
|  | use Grumpydictator\Gchart\GChart; | ||||||
|  | use Illuminate\Support\Collection; | ||||||
|  | use Preferences; | ||||||
|  | use Response; | ||||||
|  | use Session; | ||||||
|  | use Steam; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * Class AccountController | ||||||
|  |  * | ||||||
|  |  * @package FireflyIII\Http\Controllers\Chart | ||||||
|  |  */ | ||||||
|  | class AccountController extends Controller | ||||||
|  | { | ||||||
|  |     /** | ||||||
|  |      * Shows the balances for all the user's accounts. | ||||||
|  |      * | ||||||
|  |      * @param GChart                     $chart | ||||||
|  |      * @param AccountRepositoryInterface $repository | ||||||
|  |      * | ||||||
|  |      * @return \Symfony\Component\HttpFoundation\Response | ||||||
|  |      */ | ||||||
|  |     public function all(GChart $chart, AccountRepositoryInterface $repository, $year, $month, $shared = false) | ||||||
|  |     { | ||||||
|  |         $start = new Carbon($year . '-' . $month . '-01'); | ||||||
|  |         $end   = clone $start; | ||||||
|  |         $end->endOfMonth(); | ||||||
|  |         $chart->addColumn(trans('firefly.dayOfMonth'), 'date'); | ||||||
|  |  | ||||||
|  |         /** @var Collection $accounts */ | ||||||
|  |         $accounts = $repository->getAccounts(['Default account', 'Asset account']); | ||||||
|  |         if ($shared === false) { | ||||||
|  |             // remove the shared accounts from the collection: | ||||||
|  |             /** @var Account $account */ | ||||||
|  |             foreach ($accounts as $index => $account) { | ||||||
|  |                 if ($account->getMeta('accountRole') == 'sharedAsset') { | ||||||
|  |                     $accounts->forget($index); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |         $index = 1; | ||||||
|  |         /** @var Account $account */ | ||||||
|  |         foreach ($accounts as $account) { | ||||||
|  |             $chart->addColumn(trans('firefly.balanceFor', ['name' => $account->name]), 'number'); | ||||||
|  |             $chart->addCertainty($index); | ||||||
|  |             $index++; | ||||||
|  |         } | ||||||
|  |         $current = clone $start; | ||||||
|  |         $current->subDay(); | ||||||
|  |         $today = Carbon::now(); | ||||||
|  |         while ($end >= $current) { | ||||||
|  |             $row     = [clone $current]; | ||||||
|  |             $certain = $current < $today; | ||||||
|  |             foreach ($accounts as $account) { | ||||||
|  |                 $row[] = Steam::balance($account, $current); | ||||||
|  |                 $row[] = $certain; | ||||||
|  |             } | ||||||
|  |             $chart->addRowArray($row); | ||||||
|  |             $current->addDay(); | ||||||
|  |         } | ||||||
|  |         $chart->generate(); | ||||||
|  |  | ||||||
|  |         return Response::json($chart->getData()); | ||||||
|  |  | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Shows the balances for all the user's frontpage accounts. | ||||||
|  |      * | ||||||
|  |      * @param GChart                     $chart | ||||||
|  |      * @param AccountRepositoryInterface $repository | ||||||
|  |      * | ||||||
|  |      * @return \Symfony\Component\HttpFoundation\Response | ||||||
|  |      */ | ||||||
|  |     public function frontpage(GChart $chart, AccountRepositoryInterface $repository) | ||||||
|  |     { | ||||||
|  |         $chart->addColumn(trans('firefly.dayOfMonth'), 'date'); | ||||||
|  |  | ||||||
|  |         $frontPage = Preferences::get('frontPageAccounts', []); | ||||||
|  |         $start     = Session::get('start', Carbon::now()->startOfMonth()); | ||||||
|  |         $end       = Session::get('end', Carbon::now()->endOfMonth()); | ||||||
|  |         $accounts  = $repository->getFrontpageAccounts($frontPage); | ||||||
|  |  | ||||||
|  |         $index = 1; | ||||||
|  |         /** @var Account $account */ | ||||||
|  |         foreach ($accounts as $account) { | ||||||
|  |             $chart->addColumn(trans('firefly.balanceFor', ['name' => $account->name]), 'number'); | ||||||
|  |             $chart->addCertainty($index); | ||||||
|  |             $index++; | ||||||
|  |         } | ||||||
|  |         $current = clone $start; | ||||||
|  |         $current->subDay(); | ||||||
|  |         $today = Carbon::now(); | ||||||
|  |         while ($end >= $current) { | ||||||
|  |             $row     = [clone $current]; | ||||||
|  |             $certain = $current < $today; | ||||||
|  |             foreach ($accounts as $account) { | ||||||
|  |                 $row[] = Steam::balance($account, $current); | ||||||
|  |                 $row[] = $certain; | ||||||
|  |             } | ||||||
|  |             $chart->addRowArray($row); | ||||||
|  |             $current->addDay(); | ||||||
|  |         } | ||||||
|  |         $chart->generate(); | ||||||
|  |  | ||||||
|  |         return Response::json($chart->getData()); | ||||||
|  |  | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Shows an account's balance for a single month. | ||||||
|  |      * | ||||||
|  |      * @param GChart  $chart | ||||||
|  |      * @param Account $account | ||||||
|  |      * | ||||||
|  |      * @return \Symfony\Component\HttpFoundation\Response | ||||||
|  |      */ | ||||||
|  |     public function single(GChart $chart, Account $account) | ||||||
|  |     { | ||||||
|  |         $chart->addColumn(trans('firefly.dayOfMonth'), 'date'); | ||||||
|  |         $chart->addColumn(trans('firefly.balanceFor', ['name' => $account->name]), 'number'); | ||||||
|  |         $chart->addCertainty(1); | ||||||
|  |  | ||||||
|  |         $start   = Session::get('start', Carbon::now()->startOfMonth()); | ||||||
|  |         $end     = Session::get('end', Carbon::now()->endOfMonth()); | ||||||
|  |         $current = clone $start; | ||||||
|  |         $today   = new Carbon; | ||||||
|  |  | ||||||
|  |         while ($end >= $current) { | ||||||
|  |             $certain = $current < $today; | ||||||
|  |             $chart->addRow(clone $current, Steam::balance($account, $current), $certain); | ||||||
|  |             $current->addDay(); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |         $chart->generate(); | ||||||
|  |  | ||||||
|  |         return Response::json($chart->getData()); | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										141
									
								
								app/Http/Controllers/Chart/BillController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										141
									
								
								app/Http/Controllers/Chart/BillController.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,141 @@ | |||||||
|  | <?php | ||||||
|  |  | ||||||
|  | namespace FireflyIII\Http\Controllers\Chart; | ||||||
|  |  | ||||||
|  | use Carbon\Carbon; | ||||||
|  | use FireflyIII\Http\Controllers\Controller; | ||||||
|  | use FireflyIII\Models\Account; | ||||||
|  | use FireflyIII\Models\Bill; | ||||||
|  | use FireflyIII\Models\TransactionJournal; | ||||||
|  | use FireflyIII\Repositories\Account\AccountRepositoryInterface; | ||||||
|  | use FireflyIII\Repositories\Bill\BillRepositoryInterface; | ||||||
|  | use Grumpydictator\Gchart\GChart; | ||||||
|  | use Illuminate\Support\Collection; | ||||||
|  | use Response; | ||||||
|  | use Session; | ||||||
|  | use Steam; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * Class BillController | ||||||
|  |  * | ||||||
|  |  * @package FireflyIII\Http\Controllers\Chart | ||||||
|  |  */ | ||||||
|  | class BillController extends Controller | ||||||
|  | { | ||||||
|  |     /** | ||||||
|  |      * Shows the overview for a bill. The min/max amount and matched journals. | ||||||
|  |      * | ||||||
|  |      * @param GChart                  $chart | ||||||
|  |      * @param BillRepositoryInterface $repository | ||||||
|  |      * @param Bill                    $bill | ||||||
|  |      * | ||||||
|  |      * @return \Symfony\Component\HttpFoundation\Response | ||||||
|  |      */ | ||||||
|  |     public function single(GChart $chart, BillRepositoryInterface $repository, Bill $bill) | ||||||
|  |     { | ||||||
|  |  | ||||||
|  |         $chart->addColumn(trans('firefly.date'), 'date'); | ||||||
|  |         $chart->addColumn(trans('firefly.maxAmount'), 'number'); | ||||||
|  |         $chart->addColumn(trans('firefly.minAmount'), 'number'); | ||||||
|  |         $chart->addColumn(trans('firefly.billEntry'), 'number'); | ||||||
|  |  | ||||||
|  |         // get first transaction or today for start: | ||||||
|  |         $results = $repository->getJournals($bill); | ||||||
|  |         /** @var TransactionJournal $result */ | ||||||
|  |         foreach ($results as $result) { | ||||||
|  |             $chart->addRow(clone $result->date, floatval($bill->amount_max), floatval($bill->amount_min), floatval($result->amount)); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         $chart->generate(); | ||||||
|  |  | ||||||
|  |         return Response::json($chart->getData()); | ||||||
|  |  | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Shows all bills and whether or not theyve been paid this month (pie chart). | ||||||
|  |      * | ||||||
|  |      * @param GChart                     $chart | ||||||
|  |      * | ||||||
|  |      * @param BillRepositoryInterface    $repository | ||||||
|  |      * @param AccountRepositoryInterface $accounts | ||||||
|  |      * | ||||||
|  |      * @return \Symfony\Component\HttpFoundation\Response | ||||||
|  |      */ | ||||||
|  |     public function frontpage(GChart $chart, BillRepositoryInterface $repository, AccountRepositoryInterface $accounts) | ||||||
|  |     { | ||||||
|  |         $chart->addColumn(trans('firefly.name'), 'string'); | ||||||
|  |         $chart->addColumn(trans('firefly.amount'), 'number'); | ||||||
|  |  | ||||||
|  |         $start  = Session::get('start', Carbon::now()->startOfMonth()); | ||||||
|  |         $end    = Session::get('end', Carbon::now()->endOfMonth()); | ||||||
|  |         $bills  = $repository->getActiveBills(); | ||||||
|  |         $paid   = new Collection; // journals. | ||||||
|  |         $unpaid = new Collection; // bills | ||||||
|  |         // loop paid and create single entry: | ||||||
|  |         $paidDescriptions   = []; | ||||||
|  |         $paidAmount         = 0; | ||||||
|  |         $unpaidDescriptions = []; | ||||||
|  |         $unpaidAmount       = 0; | ||||||
|  |  | ||||||
|  |         /** @var Bill $bill */ | ||||||
|  |         foreach ($bills as $bill) { | ||||||
|  |             $ranges = $repository->getRanges($bill, $start, $end); | ||||||
|  |  | ||||||
|  |             foreach ($ranges as $range) { | ||||||
|  |                 // paid a bill in this range? | ||||||
|  |                 $journals = $repository->getJournalsInRange($bill, $range['start'], $range['end']); | ||||||
|  |                 if ($journals->count() == 0) { | ||||||
|  |                     $unpaid->push([$bill, $range['start']]); | ||||||
|  |                 } else { | ||||||
|  |                     $paid = $paid->merge($journals); | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         $creditCards = $accounts->getCreditCards(); | ||||||
|  |         foreach ($creditCards as $creditCard) { | ||||||
|  |             $balance = Steam::balance($creditCard, $end, true); | ||||||
|  |             $date    = new Carbon($creditCard->getMeta('ccMonthlyPaymentDate')); | ||||||
|  |             if ($balance < 0) { | ||||||
|  |                 // unpaid! create a fake bill that matches the amount. | ||||||
|  |                 $description = $creditCard->name; | ||||||
|  |                 $amount      = $balance * -1; | ||||||
|  |                 $fakeBill    = $repository->createFakeBill($description, $date, $amount); | ||||||
|  |                 unset($description, $amount); | ||||||
|  |                 $unpaid->push([$fakeBill, $date]); | ||||||
|  |             } | ||||||
|  |             if ($balance == 0) { | ||||||
|  |                 // find transfer(s) TO the credit card which should account for | ||||||
|  |                 // anything paid. If not, the CC is not yet used. | ||||||
|  |                 $journals = $accounts->getTransfersInRange($creditCard, $start, $end); | ||||||
|  |                 $paid     = $paid->merge($journals); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |         /** @var TransactionJournal $entry */ | ||||||
|  |         foreach ($paid as $entry) { | ||||||
|  |  | ||||||
|  |             $paidDescriptions[] = $entry->description; | ||||||
|  |             $paidAmount += floatval($entry->amount); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         // loop unpaid: | ||||||
|  |         /** @var Bill $entry */ | ||||||
|  |         foreach ($unpaid as $entry) { | ||||||
|  |             $description          = $entry[0]->name . ' (' . $entry[1]->format('jS M Y') . ')'; | ||||||
|  |             $amount               = ($entry[0]->amount_max + $entry[0]->amount_min) / 2; | ||||||
|  |             $unpaidDescriptions[] = $description; | ||||||
|  |             $unpaidAmount += $amount; | ||||||
|  |             unset($amount, $description); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         $chart->addRow(trans('firefly.unpaid') . ': ' . join(', ', $unpaidDescriptions), $unpaidAmount); | ||||||
|  |         $chart->addRow(trans('firefly.paid') . ': ' . join(', ', $paidDescriptions), $paidAmount); | ||||||
|  |         $chart->generate(); | ||||||
|  |  | ||||||
|  |         return Response::json($chart->getData()); | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										195
									
								
								app/Http/Controllers/Chart/BudgetController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										195
									
								
								app/Http/Controllers/Chart/BudgetController.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,195 @@ | |||||||
|  | <?php | ||||||
|  |  | ||||||
|  | namespace FireflyIII\Http\Controllers\Chart; | ||||||
|  |  | ||||||
|  | use Carbon\Carbon; | ||||||
|  | use FireflyIII\Http\Controllers\Controller; | ||||||
|  | use FireflyIII\Models\Budget; | ||||||
|  | use FireflyIII\Models\LimitRepetition; | ||||||
|  | use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; | ||||||
|  | use Grumpydictator\Gchart\GChart; | ||||||
|  | use Illuminate\Support\Collection; | ||||||
|  | use Navigation; | ||||||
|  | use Preferences; | ||||||
|  | use Response; | ||||||
|  | use Session; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * Class BudgetController | ||||||
|  |  * | ||||||
|  |  * @package FireflyIII\Http\Controllers\Chart | ||||||
|  |  */ | ||||||
|  | class BudgetController extends Controller | ||||||
|  | { | ||||||
|  |     /** | ||||||
|  |      * @param GChart                    $chart | ||||||
|  |      * @param BudgetRepositoryInterface $repository | ||||||
|  |      * @param Budget                    $budget | ||||||
|  |      */ | ||||||
|  |     public function budget(GChart $chart, BudgetRepositoryInterface $repository, Budget $budget) | ||||||
|  |     { | ||||||
|  |         $chart->addColumn(trans('firefly.period'), 'date'); | ||||||
|  |         $chart->addColumn(trans('firefly.spent'), 'number'); | ||||||
|  |  | ||||||
|  |  | ||||||
|  |         $first = $repository->getFirstBudgetLimitDate($budget); | ||||||
|  |         $range = $viewRange = Preferences::get('viewRange', '1M')->data; | ||||||
|  |         $last  = Session::get('end', new Carbon); | ||||||
|  |         $final = clone $last; | ||||||
|  |         $final->addYears(2); | ||||||
|  |         $last = Navigation::endOfX($last, $range, $final); | ||||||
|  |  | ||||||
|  |         while ($first < $last) { | ||||||
|  |             $end = Navigation::addPeriod($first, $range, 0); | ||||||
|  |  | ||||||
|  |             $spent = $repository->spentInPeriodCorrected($budget, $first, $end); | ||||||
|  |             $chart->addRow($end, $spent); | ||||||
|  |  | ||||||
|  |  | ||||||
|  |             $first = Navigation::addPeriod($first, $range, 0); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         $chart->generate(); | ||||||
|  |  | ||||||
|  |         return Response::json($chart->getData()); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Shows the amount left in a specific budget limit. | ||||||
|  |      * | ||||||
|  |      * @param GChart                    $chart | ||||||
|  |      * @param BudgetRepositoryInterface $repository | ||||||
|  |      * @param Budget                    $budget | ||||||
|  |      * @param LimitRepetition           $repetition | ||||||
|  |      * | ||||||
|  |      * @return \Symfony\Component\HttpFoundation\Response | ||||||
|  |      */ | ||||||
|  |     public function budgetLimit(GChart $chart, BudgetRepositoryInterface $repository, Budget $budget, LimitRepetition $repetition) | ||||||
|  |     { | ||||||
|  |         $start = clone $repetition->startdate; | ||||||
|  |         $end   = $repetition->enddate; | ||||||
|  |  | ||||||
|  |         $chart->addColumn(trans('firefly.day'), 'date'); | ||||||
|  |         $chart->addColumn(trans('firefly.left'), 'number'); | ||||||
|  |  | ||||||
|  |  | ||||||
|  |         $amount = $repetition->amount; | ||||||
|  |  | ||||||
|  |         while ($start <= $end) { | ||||||
|  |             /* | ||||||
|  |              * Sum of expenses on this day: | ||||||
|  |              */ | ||||||
|  |             $sum = $repository->expensesOnDayCorrected($budget, $start); | ||||||
|  |             $amount += $sum; | ||||||
|  |             $chart->addRow(clone $start, $amount); | ||||||
|  |             $start->addDay(); | ||||||
|  |         } | ||||||
|  |         $chart->generate(); | ||||||
|  |  | ||||||
|  |         return Response::json($chart->getData()); | ||||||
|  |  | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Shows a budget list with spent/left/overspent. | ||||||
|  |      * | ||||||
|  |      * @param GChart                    $chart | ||||||
|  |      * @param BudgetRepositoryInterface $repository | ||||||
|  |      * | ||||||
|  |      * @return \Symfony\Component\HttpFoundation\Response | ||||||
|  |      */ | ||||||
|  |     public function frontpage(GChart $chart, BudgetRepositoryInterface $repository) | ||||||
|  |     { | ||||||
|  |         $chart->addColumn(trans('firefly.budget'), 'string'); | ||||||
|  |         $chart->addColumn(trans('firefly.left'), 'number'); | ||||||
|  |         $chart->addColumn(trans('firefly.spent'), 'number'); | ||||||
|  |         $chart->addColumn(trans('firefly.overspent'), 'number'); | ||||||
|  |  | ||||||
|  |         $budgets    = $repository->getBudgets(); | ||||||
|  |         $start      = Session::get('start', Carbon::now()->startOfMonth()); | ||||||
|  |         $end        = Session::get('end', Carbon::now()->endOfMonth()); | ||||||
|  |         $allEntries = new Collection; | ||||||
|  |  | ||||||
|  |         foreach ($budgets as $budget) { | ||||||
|  |             $repetitions = $repository->getBudgetLimitRepetitions($budget, $start, $end); | ||||||
|  |             if ($repetitions->count() == 0) { | ||||||
|  |                 $expenses = $repository->spentInPeriodCorrected($budget, $start, $end, true); | ||||||
|  |                 $allEntries->push([$budget->name, 0, 0, $expenses]); | ||||||
|  |                 continue; | ||||||
|  |             } | ||||||
|  |             /** @var LimitRepetition $repetition */ | ||||||
|  |             foreach ($repetitions as $repetition) { | ||||||
|  |                 $expenses  = $repository->spentInPeriodCorrected($budget, $repetition->startdate, $repetition->enddate, true); | ||||||
|  |                 $left      = $expenses < floatval($repetition->amount) ? floatval($repetition->amount) - $expenses : 0; | ||||||
|  |                 $spent     = $expenses > floatval($repetition->amount) ? floatval($repetition->amount) : $expenses; | ||||||
|  |                 $overspent = $expenses > floatval($repetition->amount) ? $expenses - floatval($repetition->amount) : 0; | ||||||
|  |                 $allEntries->push( | ||||||
|  |                     [$budget->name . ' (' . $repetition->startdate->formatLocalized($this->monthAndDayFormat) . ')', | ||||||
|  |                      $left, | ||||||
|  |                      $spent, | ||||||
|  |                      $overspent | ||||||
|  |                     ] | ||||||
|  |                 ); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         $noBudgetExpenses = $repository->getWithoutBudgetSum($start, $end); | ||||||
|  |         $allEntries->push([trans('firefly.noBudget'), 0, 0, $noBudgetExpenses]); | ||||||
|  |  | ||||||
|  |         foreach ($allEntries as $entry) { | ||||||
|  |             if ($entry[1] != 0 || $entry[2] != 0 || $entry[3] != 0) { | ||||||
|  |                 $chart->addRow($entry[0], $entry[1], $entry[2], $entry[3]); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         $chart->generate(); | ||||||
|  |  | ||||||
|  |         return Response::json($chart->getData()); | ||||||
|  |  | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Show a yearly overview for a budget. | ||||||
|  |      * | ||||||
|  |      * @param GChart                    $chart | ||||||
|  |      * @param BudgetRepositoryInterface $repository | ||||||
|  |      * @param                           $year | ||||||
|  |      * @param bool                      $shared | ||||||
|  |      * | ||||||
|  |      * @return \Symfony\Component\HttpFoundation\Response | ||||||
|  |      */ | ||||||
|  |     public function year(GChart $chart, BudgetRepositoryInterface $repository, $year, $shared = false) | ||||||
|  |     { | ||||||
|  |         $start   = new Carbon($year . '-01-01'); | ||||||
|  |         $end     = new Carbon($year . '-12-31'); | ||||||
|  |         $shared  = $shared == 'shared' ? true : false; | ||||||
|  |         $budgets = $repository->getBudgets(); | ||||||
|  |  | ||||||
|  |         // add columns: | ||||||
|  |         $chart->addColumn(trans('firefly.month'), 'date'); | ||||||
|  |         foreach ($budgets as $budget) { | ||||||
|  |             $chart->addColumn($budget->name, 'number'); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         while ($start < $end) { | ||||||
|  |             // month is the current end of the period: | ||||||
|  |             $month = clone $start; | ||||||
|  |             $month->endOfMonth(); | ||||||
|  |             // make a row: | ||||||
|  |             $row = [clone $start]; | ||||||
|  |  | ||||||
|  |             // each budget, fill the row: | ||||||
|  |             foreach ($budgets as $budget) { | ||||||
|  |                 $spent = $repository->spentInPeriodCorrected($budget, $start, $month, $shared); | ||||||
|  |                 $row[] = $spent; | ||||||
|  |             } | ||||||
|  |             $chart->addRowArray($row); | ||||||
|  |  | ||||||
|  |             $start->addMonth(); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         $chart->generate(); | ||||||
|  |  | ||||||
|  |         return Response::json($chart->getData()); | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										180
									
								
								app/Http/Controllers/Chart/CategoryController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										180
									
								
								app/Http/Controllers/Chart/CategoryController.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,180 @@ | |||||||
|  | <?php | ||||||
|  |  | ||||||
|  | namespace FireflyIII\Http\Controllers\Chart; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | use Carbon\Carbon; | ||||||
|  | use FireflyIII\Http\Controllers\Controller; | ||||||
|  | use FireflyIII\Models\Category; | ||||||
|  | use FireflyIII\Models\LimitRepetition; | ||||||
|  | use FireflyIII\Models\Preference; | ||||||
|  | use FireflyIII\Repositories\Category\CategoryRepositoryInterface; | ||||||
|  | use Grumpydictator\Gchart\GChart; | ||||||
|  | use Navigation; | ||||||
|  | use Preferences; | ||||||
|  | use Response; | ||||||
|  | use Session; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * Class CategoryController | ||||||
|  |  * | ||||||
|  |  * @package FireflyIII\Http\Controllers\Chart | ||||||
|  |  */ | ||||||
|  | class CategoryController extends Controller | ||||||
|  | { | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Show an overview for a category for all time, per month/week/year. | ||||||
|  |      * | ||||||
|  |      * @param GChart                      $chart | ||||||
|  |      * @param CategoryRepositoryInterface $repository | ||||||
|  |      * @param Category                    $category | ||||||
|  |      * | ||||||
|  |      * @return \Symfony\Component\HttpFoundation\Response | ||||||
|  |      */ | ||||||
|  |     public function all(GChart $chart, CategoryRepositoryInterface $repository, Category $category) | ||||||
|  |     { | ||||||
|  |         // oldest transaction in category: | ||||||
|  |         $start = $repository->getFirstActivityDate($category); | ||||||
|  |         $range = Preferences::get('viewRange', '1M')->data; | ||||||
|  |         // jump to start of week / month / year / etc | ||||||
|  |         $start = Navigation::startOfPeriod($start, $range); | ||||||
|  |  | ||||||
|  |         $chart->addColumn(trans('firefly.period'), 'date'); | ||||||
|  |         $chart->addColumn(trans('firefly.spent'), 'number'); | ||||||
|  |  | ||||||
|  |  | ||||||
|  |         $end = new Carbon; | ||||||
|  |         while ($start <= $end) { | ||||||
|  |  | ||||||
|  |             $currentEnd = Navigation::endOfPeriod($start, $range); | ||||||
|  |             $spent      = $repository->spentInPeriodCorrected($category, $start, $currentEnd); | ||||||
|  |             $chart->addRow(clone $start, $spent); | ||||||
|  |  | ||||||
|  |             $start = Navigation::addPeriod($start, $range, 0); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         $chart->generate(); | ||||||
|  |  | ||||||
|  |         return Response::json($chart->getData()); | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Show this month's category overview. | ||||||
|  |      * | ||||||
|  |      * @param GChart                      $chart | ||||||
|  |      * @param CategoryRepositoryInterface $repository | ||||||
|  |      * | ||||||
|  |      * @return \Symfony\Component\HttpFoundation\Response | ||||||
|  |      */ | ||||||
|  |     public function frontpage(GChart $chart, CategoryRepositoryInterface $repository) | ||||||
|  |     { | ||||||
|  |         $chart->addColumn(trans('firefly.category'), 'string'); | ||||||
|  |         $chart->addColumn(trans('firefly.spent'), 'number'); | ||||||
|  |  | ||||||
|  |         $start = Session::get('start', Carbon::now()->startOfMonth()); | ||||||
|  |         $end   = Session::get('end', Carbon::now()->endOfMonth()); | ||||||
|  |         $set   = $repository->getCategoriesAndExpensesCorrected($start, $end); | ||||||
|  |  | ||||||
|  |         // sort by callback: | ||||||
|  |         uasort( | ||||||
|  |             $set, | ||||||
|  |             function ($left, $right) { | ||||||
|  |                 if ($left['sum'] == $right['sum']) { | ||||||
|  |                     return 0; | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 return ($left['sum'] < $right['sum']) ? 1 : -1; | ||||||
|  |             } | ||||||
|  |         ); | ||||||
|  |  | ||||||
|  |  | ||||||
|  |         foreach ($set as $entry) { | ||||||
|  |             $sum = floatval($entry['sum']); | ||||||
|  |             if ($sum != 0) { | ||||||
|  |                 $chart->addRow($entry['name'], $sum); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         $chart->generate(); | ||||||
|  |  | ||||||
|  |         return Response::json($chart->getData()); | ||||||
|  |  | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param GChart                      $chart | ||||||
|  |      * @param CategoryRepositoryInterface $repository | ||||||
|  |      * @param Category                    $category | ||||||
|  |      * | ||||||
|  |      * @return \Symfony\Component\HttpFoundation\Response | ||||||
|  |      */ | ||||||
|  |     public function month(GChart $chart, CategoryRepositoryInterface $repository, Category $category) | ||||||
|  |     { | ||||||
|  |         $start = clone Session::get('start', Carbon::now()->startOfMonth()); | ||||||
|  |         $end   = Session::get('end', Carbon::now()->endOfMonth()); | ||||||
|  |  | ||||||
|  |         $chart->addColumn(trans('firefly.period'), 'date'); | ||||||
|  |         $chart->addColumn(trans('firefly.spent'), 'number'); | ||||||
|  |  | ||||||
|  |         while ($start <= $end) { | ||||||
|  |             $spent = $repository->spentOnDaySumCorrected($category, $start); | ||||||
|  |             $chart->addRow(clone $start, $spent); | ||||||
|  |             $start->addDay(); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         $chart->generate(); | ||||||
|  |  | ||||||
|  |         return Response::json($chart->getData()); | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * This chart will only show expenses. | ||||||
|  |      * | ||||||
|  |      * @param GChart                      $chart | ||||||
|  |      * @param CategoryRepositoryInterface $repository | ||||||
|  |      * @param                             $year | ||||||
|  |      * @param bool                        $shared | ||||||
|  |      * | ||||||
|  |      * @return \Symfony\Component\HttpFoundation\Response | ||||||
|  |      */ | ||||||
|  |     public function year(GChart $chart, CategoryRepositoryInterface $repository, $year, $shared = false) | ||||||
|  |     { | ||||||
|  |         $start      = new Carbon($year . '-01-01'); | ||||||
|  |         $end        = new Carbon($year . '-12-31'); | ||||||
|  |         $shared     = $shared == 'shared' ? true : false; | ||||||
|  |         $categories = $repository->getCategories(); | ||||||
|  |  | ||||||
|  |         // add columns: | ||||||
|  |         $chart->addColumn(trans('firefly.month'), 'date'); | ||||||
|  |         foreach ($categories as $category) { | ||||||
|  |             $chart->addColumn($category->name, 'number'); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         while ($start < $end) { | ||||||
|  |             // month is the current end of the period: | ||||||
|  |             $month = clone $start; | ||||||
|  |             $month->endOfMonth(); | ||||||
|  |             // make a row: | ||||||
|  |             $row = [clone $start]; | ||||||
|  |  | ||||||
|  |             // each budget, fill the row: | ||||||
|  |             foreach ($categories as $category) { | ||||||
|  |                 $spent = $repository->spentInPeriodCorrected($category, $start, $month, $shared); | ||||||
|  |                 $row[] = $spent; | ||||||
|  |             } | ||||||
|  |             $chart->addRowArray($row); | ||||||
|  |  | ||||||
|  |             $start->addMonth(); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         $chart->generate(); | ||||||
|  |  | ||||||
|  |         return Response::json($chart->getData()); | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										58
									
								
								app/Http/Controllers/Chart/PiggyBankController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								app/Http/Controllers/Chart/PiggyBankController.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,58 @@ | |||||||
|  | <?php | ||||||
|  | /** | ||||||
|  |  * Created by PhpStorm. | ||||||
|  |  * User: sander | ||||||
|  |  * Date: 16/05/15 | ||||||
|  |  * Time: 09:36 | ||||||
|  |  */ | ||||||
|  |  | ||||||
|  | namespace FireflyIII\Http\Controllers\Chart; | ||||||
|  |  | ||||||
|  | use Carbon\Carbon; | ||||||
|  | use FireflyIII\Http\Controllers\Controller; | ||||||
|  | use FireflyIII\Models\Account; | ||||||
|  | use FireflyIII\Models\Bill; | ||||||
|  | use FireflyIII\Models\PiggyBank; | ||||||
|  | use FireflyIII\Models\TransactionJournal; | ||||||
|  | use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface; | ||||||
|  | use Grumpydictator\Gchart\GChart; | ||||||
|  | use Illuminate\Support\Collection; | ||||||
|  | use Response; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * Class PiggyBankController | ||||||
|  |  * | ||||||
|  |  * @package FireflyIII\Http\Controllers\Chart | ||||||
|  |  */ | ||||||
|  | class PiggyBankController extends Controller | ||||||
|  | { | ||||||
|  |     /** | ||||||
|  |      * Shows the piggy bank history. | ||||||
|  |      * | ||||||
|  |      * @param GChart                       $chart | ||||||
|  |      * @param PiggyBankRepositoryInterface $repository | ||||||
|  |      * @param PiggyBank                    $piggyBank | ||||||
|  |      * | ||||||
|  |      * @return \Symfony\Component\HttpFoundation\Response | ||||||
|  |      */ | ||||||
|  |     public function history(GChart $chart, PiggyBankRepositoryInterface $repository, PiggyBank $piggyBank) | ||||||
|  |     { | ||||||
|  |         $chart->addColumn(trans('firefly.date'), 'date'); | ||||||
|  |         $chart->addColumn(trans('firefly.balance'), 'number'); | ||||||
|  |  | ||||||
|  |         /** @var Collection $set */ | ||||||
|  |         $set = $repository->getEventSummarySet($piggyBank); | ||||||
|  |         $sum = 0; | ||||||
|  |  | ||||||
|  |         foreach ($set as $entry) { | ||||||
|  |             $sum += floatval($entry->sum); | ||||||
|  |             $chart->addRow(new Carbon($entry->date), $sum); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         $chart->generate(); | ||||||
|  |  | ||||||
|  |         return Response::json($chart->getData()); | ||||||
|  |  | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										101
									
								
								app/Http/Controllers/Chart/ReportController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										101
									
								
								app/Http/Controllers/Chart/ReportController.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,101 @@ | |||||||
|  | <?php | ||||||
|  |  | ||||||
|  | namespace FireflyIII\Http\Controllers\Chart; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | use Carbon\Carbon; | ||||||
|  | use FireflyIII\Helpers\Report\ReportQueryInterface; | ||||||
|  | use FireflyIII\Http\Controllers\Controller; | ||||||
|  | use Grumpydictator\Gchart\GChart; | ||||||
|  | use Response; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * Class ReportController | ||||||
|  |  * | ||||||
|  |  * @package FireflyIII\Http\Controllers\Chart | ||||||
|  |  */ | ||||||
|  | class ReportController extends Controller | ||||||
|  | { | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Summarizes all income and expenses, per month, for a given year. | ||||||
|  |      * | ||||||
|  |      * @param GChart               $chart | ||||||
|  |      * @param ReportQueryInterface $query | ||||||
|  |      * @param                      $year | ||||||
|  |      * @param bool                 $shared | ||||||
|  |      * | ||||||
|  |      * @return \Symfony\Component\HttpFoundation\Response | ||||||
|  |      */ | ||||||
|  |     public function yearInOut(GChart $chart, ReportQueryInterface $query, $year, $shared = false) | ||||||
|  |     { | ||||||
|  |         // get start and end of year | ||||||
|  |         $start  = new Carbon($year . '-01-01'); | ||||||
|  |         $end    = new Carbon($year . '-12-31'); | ||||||
|  |         $shared = $shared == 'shared' ? true : false; | ||||||
|  |  | ||||||
|  |         $chart->addColumn(trans('firefly.month'), 'date'); | ||||||
|  |         $chart->addColumn(trans('firefly.income'), 'number'); | ||||||
|  |         $chart->addColumn(trans('firefly.expenses'), 'number'); | ||||||
|  |  | ||||||
|  |         while ($start < $end) { | ||||||
|  |             $month = clone $start; | ||||||
|  |             $month->endOfMonth(); | ||||||
|  |             // total income and total expenses: | ||||||
|  |             $incomeSum  = floatval($query->incomeInPeriodCorrected($start, $month, $shared)->sum('amount')); | ||||||
|  |             $expenseSum = floatval($query->expenseInPeriodCorrected($start, $month, $shared)->sum('amount')); | ||||||
|  |  | ||||||
|  |             $chart->addRow(clone $start, $incomeSum, $expenseSum); | ||||||
|  |             $start->addMonth(); | ||||||
|  |         } | ||||||
|  |         $chart->generate(); | ||||||
|  |  | ||||||
|  |         return Response::json($chart->getData()); | ||||||
|  |  | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Summarizes all income and expenses for a given year. Gives a total and an average. | ||||||
|  |      * | ||||||
|  |      * @param GChart               $chart | ||||||
|  |      * @param ReportQueryInterface $query | ||||||
|  |      * @param                      $year | ||||||
|  |      * @param bool                 $shared | ||||||
|  |      * | ||||||
|  |      * @return \Symfony\Component\HttpFoundation\Response | ||||||
|  |      */ | ||||||
|  |     public function yearInOutSummarized(GChart $chart, ReportQueryInterface $query, $year, $shared = false) | ||||||
|  |     { | ||||||
|  |         $start   = new Carbon($year . '-01-01'); | ||||||
|  |         $end     = new Carbon($year . '-12-31'); | ||||||
|  |         $shared  = $shared == 'shared' ? true : false; | ||||||
|  |         $income  = 0; | ||||||
|  |         $expense = 0; | ||||||
|  |         $count   = 0; | ||||||
|  |  | ||||||
|  |         $chart->addColumn(trans('firefly.summary'), 'string'); | ||||||
|  |         $chart->addColumn(trans('firefly.income'), 'number'); | ||||||
|  |         $chart->addColumn(trans('firefly.expenses'), 'number'); | ||||||
|  |  | ||||||
|  |         while ($start < $end) { | ||||||
|  |             $month = clone $start; | ||||||
|  |             $month->endOfMonth(); | ||||||
|  |             // total income and total expenses: | ||||||
|  |             $income += floatval($query->incomeInPeriodCorrected($start, $month, $shared)->sum('amount')); | ||||||
|  |             $expense += floatval($query->expenseInPeriodCorrected($start, $month, $shared)->sum('amount')); | ||||||
|  |             $count++; | ||||||
|  |             $start->addMonth(); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         // add total + average: | ||||||
|  |         $chart->addRow(trans('firefly.sum'), $income, $expense); | ||||||
|  |         $count = $count > 0 ? $count : 1; | ||||||
|  |         $chart->addRow(trans('firefly.average'), ($income / $count), ($expense / $count)); | ||||||
|  |  | ||||||
|  |         $chart->generate(); | ||||||
|  |  | ||||||
|  |         return Response::json($chart->getData()); | ||||||
|  |  | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -1,8 +1,11 @@ | |||||||
| <?php namespace FireflyIII\Http\Controllers; | <?php namespace FireflyIII\Http\Controllers; | ||||||
|  |  | ||||||
|  | use Auth; | ||||||
|  | use Config; | ||||||
| use Illuminate\Foundation\Bus\DispatchesCommands; | use Illuminate\Foundation\Bus\DispatchesCommands; | ||||||
| use Illuminate\Foundation\Validation\ValidatesRequests; | use Illuminate\Foundation\Validation\ValidatesRequests; | ||||||
| use Illuminate\Routing\Controller as BaseController; | use Illuminate\Routing\Controller as BaseController; | ||||||
|  | use Preferences; | ||||||
| use View; | use View; | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @@ -15,6 +18,11 @@ abstract class Controller extends BaseController | |||||||
|  |  | ||||||
|     use DispatchesCommands, ValidatesRequests; |     use DispatchesCommands, ValidatesRequests; | ||||||
|  |  | ||||||
|  |     /** @var string */ | ||||||
|  |     protected $monthAndDayFormat; | ||||||
|  |     /** @var string */ | ||||||
|  |     protected $monthFormat; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * |      * | ||||||
|      */ |      */ | ||||||
| @@ -24,5 +32,16 @@ abstract class Controller extends BaseController | |||||||
|         View::share('hideCategories', false); |         View::share('hideCategories', false); | ||||||
|         View::share('hideBills', false); |         View::share('hideBills', false); | ||||||
|         View::share('hideTags', false); |         View::share('hideTags', false); | ||||||
|  |  | ||||||
|  |         if (Auth::check()) { | ||||||
|  |             $pref                    = Preferences::get('language', 'en'); | ||||||
|  |             $lang                    = $pref->data; | ||||||
|  |             $this->monthFormat       = Config::get('firefly.month.' . $lang); | ||||||
|  |             $this->monthAndDayFormat = Config::get('firefly.monthAndDay.' . $lang); | ||||||
|  |  | ||||||
|  |             View::share('monthFormat', $this->monthFormat); | ||||||
|  |             View::share('monthAndDayFormat', $this->monthAndDayFormat); | ||||||
|  |             View::share('language', $lang); | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -28,7 +28,7 @@ class CurrencyController extends Controller | |||||||
|     public function __construct() |     public function __construct() | ||||||
|     { |     { | ||||||
|         parent::__construct(); |         parent::__construct(); | ||||||
|         View::share('title', 'Currencies'); |         View::share('title', trans('firefly.currencies')); | ||||||
|         View::share('mainTitleIcon', 'fa-usd'); |         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) { |         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 |      * @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) { |         if ($repository->countJournals($currency) > 0) { | ||||||
|             Session::flash('error', 'Cannot destroy ' . e($currency->name) . ' because there are still transactions attached to it.'); |             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 |      * @return \Illuminate\View\View | ||||||
|      */ |      */ | ||||||
|     public function index(CurrencyRepositoryInterface $repository) |     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 |      * @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(); |         $data     = $request->getCurrencyData(); | ||||||
|         $currency = $repository->update($currency, $data); |         $currency = $repository->update($currency, $data); | ||||||
|   | |||||||
| @@ -1,565 +0,0 @@ | |||||||
| <?php namespace FireflyIII\Http\Controllers; |  | ||||||
|  |  | ||||||
| use Carbon\Carbon; |  | ||||||
| use Crypt; |  | ||||||
| use FireflyIII\Helpers\Report\ReportQueryInterface; |  | ||||||
| use FireflyIII\Models\Account; |  | ||||||
| use FireflyIII\Models\Bill; |  | ||||||
| use FireflyIII\Models\Budget; |  | ||||||
| use FireflyIII\Models\Category; |  | ||||||
| use FireflyIII\Models\LimitRepetition; |  | ||||||
| use FireflyIII\Models\PiggyBank; |  | ||||||
| use FireflyIII\Models\Preference; |  | ||||||
| use FireflyIII\Models\Transaction; |  | ||||||
| use FireflyIII\Models\TransactionJournal; |  | ||||||
| use FireflyIII\Repositories\Account\AccountRepositoryInterface; |  | ||||||
| use FireflyIII\Repositories\Bill\BillRepositoryInterface; |  | ||||||
| use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; |  | ||||||
| use FireflyIII\Repositories\Category\CategoryRepositoryInterface; |  | ||||||
| use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface; |  | ||||||
| use Grumpydictator\Gchart\GChart; |  | ||||||
| use Illuminate\Support\Collection; |  | ||||||
| use Navigation; |  | ||||||
| use Preferences; |  | ||||||
| use Response; |  | ||||||
| use Session; |  | ||||||
| use Steam; |  | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * Class GoogleChartController |  | ||||||
|  * |  | ||||||
|  * @package FireflyIII\Http\Controllers |  | ||||||
|  */ |  | ||||||
| class GoogleChartController extends Controller |  | ||||||
| { |  | ||||||
|  |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * @param Account $account |  | ||||||
|      * @param string  $view |  | ||||||
|      * |  | ||||||
|      * @return \Illuminate\Http\JsonResponse |  | ||||||
|      */ |  | ||||||
|     public function accountBalanceChart(Account $account, GChart $chart) |  | ||||||
|     { |  | ||||||
|         $chart->addColumn('Day of month', 'date'); |  | ||||||
|         $chart->addColumn('Balance for ' . $account->name, 'number'); |  | ||||||
|         $chart->addCertainty(1); |  | ||||||
|  |  | ||||||
|         $start   = Session::get('start', Carbon::now()->startOfMonth()); |  | ||||||
|         $end     = Session::get('end', Carbon::now()->endOfMonth()); |  | ||||||
|         $current = clone $start; |  | ||||||
|         $today   = new Carbon; |  | ||||||
|  |  | ||||||
|         while ($end >= $current) { |  | ||||||
|             $certain = $current < $today; |  | ||||||
|             $chart->addRow(clone $current, Steam::balance($account, $current), $certain); |  | ||||||
|             $current->addDay(); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|  |  | ||||||
|         $chart->generate(); |  | ||||||
|  |  | ||||||
|         return Response::json($chart->getData()); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * @param GChart $chart |  | ||||||
|      * |  | ||||||
|      * @return \Symfony\Component\HttpFoundation\Response |  | ||||||
|      */ |  | ||||||
|     public function allAccountsBalanceChart(GChart $chart, AccountRepositoryInterface $repository) |  | ||||||
|     { |  | ||||||
|         $chart->addColumn('Day of the month', 'date'); |  | ||||||
|  |  | ||||||
|         $frontPage = Preferences::get('frontPageAccounts', []); |  | ||||||
|         $start     = Session::get('start', Carbon::now()->startOfMonth()); |  | ||||||
|         $end       = Session::get('end', Carbon::now()->endOfMonth()); |  | ||||||
|         $accounts  = $repository->getFrontpageAccounts($frontPage); |  | ||||||
|  |  | ||||||
|         $index = 1; |  | ||||||
|         /** @var Account $account */ |  | ||||||
|         foreach ($accounts as $account) { |  | ||||||
|             $chart->addColumn('Balance for ' . $account->name, 'number'); |  | ||||||
|             $chart->addCertainty($index); |  | ||||||
|             $index++; |  | ||||||
|         } |  | ||||||
|         $current = clone $start; |  | ||||||
|         $current->subDay(); |  | ||||||
|         $today = Carbon::now(); |  | ||||||
|         while ($end >= $current) { |  | ||||||
|             $row     = [clone $current]; |  | ||||||
|             $certain = $current < $today; |  | ||||||
|             foreach ($accounts as $account) { |  | ||||||
|                 $row[] = Steam::balance($account, $current); |  | ||||||
|                 $row[] = $certain; |  | ||||||
|             } |  | ||||||
|             $chart->addRowArray($row); |  | ||||||
|             $current->addDay(); |  | ||||||
|         } |  | ||||||
|         $chart->generate(); |  | ||||||
|  |  | ||||||
|         return Response::json($chart->getData()); |  | ||||||
|  |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * @param int $year |  | ||||||
|      * |  | ||||||
|      * @return $this|\Illuminate\Http\JsonResponse |  | ||||||
|      */ |  | ||||||
|     public function allBudgetsAndSpending($year, GChart $chart, BudgetRepositoryInterface $repository) |  | ||||||
|     { |  | ||||||
|         $budgets = $repository->getBudgets(); |  | ||||||
|         $chart->addColumn('Month', 'date'); |  | ||||||
|         foreach ($budgets as $budget) { |  | ||||||
|             $chart->addColumn($budget->name, 'number'); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         $start = Carbon::createFromDate(intval($year), 1, 1); |  | ||||||
|         $end   = clone $start; |  | ||||||
|         $end->endOfYear(); |  | ||||||
|  |  | ||||||
|         while ($start <= $end) { |  | ||||||
|             $row = [clone $start]; |  | ||||||
|             foreach ($budgets as $budget) { |  | ||||||
|                 $spent = $repository->spentInMonth($budget, $start); |  | ||||||
|                 $row[] = $spent; |  | ||||||
|             } |  | ||||||
|             $chart->addRowArray($row); |  | ||||||
|             $start->addMonth(); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         $chart->generate(); |  | ||||||
|  |  | ||||||
|         return Response::json($chart->getData()); |  | ||||||
|  |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * @param GChart $chart |  | ||||||
|      * |  | ||||||
|      * @return \Symfony\Component\HttpFoundation\Response |  | ||||||
|      */ |  | ||||||
|     public function allBudgetsHomeChart(GChart $chart, BudgetRepositoryInterface $repository) |  | ||||||
|     { |  | ||||||
|         $chart->addColumn('Budget', 'string'); |  | ||||||
|         $chart->addColumn('Left', 'number'); |  | ||||||
|         //$chart->addColumn('Spent', 'number'); |  | ||||||
|  |  | ||||||
|         $budgets    = $repository->getBudgets(); |  | ||||||
|         $start      = Session::get('start', Carbon::now()->startOfMonth()); |  | ||||||
|         $end        = Session::get('end', Carbon::now()->endOfMonth()); |  | ||||||
|         $allEntries = new Collection; |  | ||||||
|  |  | ||||||
|         foreach ($budgets as $budget) { |  | ||||||
|             $repetitions = $repository->getBudgetLimitRepetitions($budget, $start, $end); |  | ||||||
|             if ($repetitions->count() == 0) { |  | ||||||
|                 $expenses = $repository->sumBudgetExpensesInPeriod($budget, $start, $end); |  | ||||||
|                 $allEntries->push([$budget->name, 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]); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         $noBudgetExpenses = $repository->getWithoutBudgetSum($start, $end); |  | ||||||
|         $allEntries->push(['(no budget)', 0, $noBudgetExpenses]); |  | ||||||
|  |  | ||||||
|         foreach ($allEntries as $entry) { |  | ||||||
|             if ($entry[2] > 0) { |  | ||||||
|                 $left = $entry[1] - $entry[2]; |  | ||||||
|                 $chart->addRow($entry[0], $left); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         $chart->generate(); |  | ||||||
|  |  | ||||||
|         return Response::json($chart->getData()); |  | ||||||
|  |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * @param GChart $chart |  | ||||||
|      * |  | ||||||
|      * @return \Symfony\Component\HttpFoundation\Response |  | ||||||
|      */ |  | ||||||
|     public function allCategoriesHomeChart(GChart $chart, CategoryRepositoryInterface $repository) |  | ||||||
|     { |  | ||||||
|         $chart->addColumn('Category', 'string'); |  | ||||||
|         $chart->addColumn('Spent', 'number'); |  | ||||||
|  |  | ||||||
|         $start = Session::get('start', Carbon::now()->startOfMonth()); |  | ||||||
|         $end   = Session::get('end', Carbon::now()->endOfMonth()); |  | ||||||
|         $set   = $repository->getCategoriesAndExpenses($start, $end); |  | ||||||
|  |  | ||||||
|         foreach ($set as $entry) { |  | ||||||
|             $isEncrypted = intval($entry->encrypted) == 1 ? true : false; |  | ||||||
|             $name        = strlen($entry->name) == 0 ? '(no category)' : $entry->name; |  | ||||||
|             $name        = $isEncrypted ? Crypt::decrypt($name) : $name; |  | ||||||
|             $chart->addRow($name, floatval($entry->sum)); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         $chart->generate(); |  | ||||||
|  |  | ||||||
|         return Response::json($chart->getData()); |  | ||||||
|  |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * @param Bill   $bill |  | ||||||
|      * @param GChart $chart |  | ||||||
|      * |  | ||||||
|      * @return \Symfony\Component\HttpFoundation\Response |  | ||||||
|      */ |  | ||||||
|     public function billOverview(Bill $bill, GChart $chart, BillRepositoryInterface $repository) |  | ||||||
|     { |  | ||||||
|  |  | ||||||
|         $chart->addColumn('Date', 'date'); |  | ||||||
|         $chart->addColumn('Max amount', 'number'); |  | ||||||
|         $chart->addColumn('Min amount', 'number'); |  | ||||||
|         $chart->addColumn('Recorded bill entry', 'number'); |  | ||||||
|  |  | ||||||
|         // get first transaction or today for start: |  | ||||||
|         $results = $repository->getJournals($bill); |  | ||||||
|         /** @var TransactionJournal $result */ |  | ||||||
|         foreach ($results as $result) { |  | ||||||
|             $chart->addRow(clone $result->date, floatval($bill->amount_max), floatval($bill->amount_min), floatval($result->amount)); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         $chart->generate(); |  | ||||||
|  |  | ||||||
|         return Response::json($chart->getData()); |  | ||||||
|  |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * @param GChart $chart |  | ||||||
|      * |  | ||||||
|      * @return \Symfony\Component\HttpFoundation\Response |  | ||||||
|      */ |  | ||||||
|     public function billsOverview(GChart $chart, BillRepositoryInterface $repository, AccountRepositoryInterface $accounts) |  | ||||||
|     { |  | ||||||
|         $chart->addColumn('Name', 'string'); |  | ||||||
|         $chart->addColumn('Amount', 'number'); |  | ||||||
|  |  | ||||||
|         $start  = Session::get('start', Carbon::now()->startOfMonth()); |  | ||||||
|         $end    = Session::get('end', Carbon::now()->endOfMonth()); |  | ||||||
|         $bills  = $repository->getActiveBills(); |  | ||||||
|         $paid   = new Collection; // journals. |  | ||||||
|         $unpaid = new Collection; // bills |  | ||||||
|         // loop paid and create single entry: |  | ||||||
|         $paidDescriptions   = []; |  | ||||||
|         $paidAmount         = 0; |  | ||||||
|         $unpaidDescriptions = []; |  | ||||||
|         $unpaidAmount       = 0; |  | ||||||
|  |  | ||||||
|         /** @var Bill $bill */ |  | ||||||
|         foreach ($bills as $bill) { |  | ||||||
|             $ranges = $repository->getRanges($bill, $start, $end); |  | ||||||
|  |  | ||||||
|             foreach ($ranges as $range) { |  | ||||||
|                 // paid a bill in this range? |  | ||||||
|                 $journals = $repository->getJournalsInRange($bill, $range['start'], $range['end']); |  | ||||||
|                 if ($journals->count() == 0) { |  | ||||||
|                     $unpaid->push([$bill, $range['start']]); |  | ||||||
|                 } else { |  | ||||||
|                     $paid = $paid->merge($journals); |  | ||||||
|                 } |  | ||||||
|  |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         $creditCards = $accounts->getCreditCards(); |  | ||||||
|         foreach ($creditCards as $creditCard) { |  | ||||||
|             $balance = Steam::balance($creditCard, null, true); |  | ||||||
|             $date    = new Carbon($creditCard->getMeta('ccMonthlyPaymentDate')); |  | ||||||
|             if ($balance < 0) { |  | ||||||
|                 // unpaid! create a fake bill that matches the amount. |  | ||||||
|                 $description = $creditCard->name; |  | ||||||
|                 $amount      = $balance * -1; |  | ||||||
|                 $fakeBill    = $repository->createFakeBill($description, $date, $amount); |  | ||||||
|                 unset($description, $amount); |  | ||||||
|                 $unpaid->push([$fakeBill, $date]); |  | ||||||
|             } |  | ||||||
|             if ($balance == 0) { |  | ||||||
|                 // find transfer(s) TO the credit card which should account for |  | ||||||
|                 // anything paid. If not, the CC is not yet used. |  | ||||||
|                 $journals = $accounts->getTransfersInRange($creditCard, $start, $end); |  | ||||||
|                 $paid     = $paid->merge($journals); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|  |  | ||||||
|         /** @var TransactionJournal $entry */ |  | ||||||
|         foreach ($paid as $entry) { |  | ||||||
|  |  | ||||||
|             $paidDescriptions[] = $entry->description; |  | ||||||
|             $paidAmount += floatval($entry->amount); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         // loop unpaid: |  | ||||||
|         /** @var Bill $entry */ |  | ||||||
|         foreach ($unpaid as $entry) { |  | ||||||
|             $description          = $entry[0]->name . ' (' . $entry[1]->format('jS M Y') . ')'; |  | ||||||
|             $amount               = ($entry[0]->amount_max + $entry[0]->amount_min) / 2; |  | ||||||
|             $unpaidDescriptions[] = $description; |  | ||||||
|             $unpaidAmount += $amount; |  | ||||||
|             unset($amount, $description); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         $chart->addRow('Unpaid: ' . join(', ', $unpaidDescriptions), $unpaidAmount); |  | ||||||
|         $chart->addRow('Paid: ' . join(', ', $paidDescriptions), $paidAmount); |  | ||||||
|         $chart->generate(); |  | ||||||
|  |  | ||||||
|         return Response::json($chart->getData()); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * |  | ||||||
|      * @param Budget          $budget |  | ||||||
|      * @param LimitRepetition $repetition |  | ||||||
|      * |  | ||||||
|      * @return \Illuminate\Http\JsonResponse |  | ||||||
|      */ |  | ||||||
|     public function budgetLimitSpending(Budget $budget, LimitRepetition $repetition, GChart $chart, BudgetRepositoryInterface $repository) |  | ||||||
|     { |  | ||||||
|         $start = clone $repetition->startdate; |  | ||||||
|         $end   = $repetition->enddate; |  | ||||||
|  |  | ||||||
|         $chart->addColumn('Day', 'date'); |  | ||||||
|         $chart->addColumn('Left', 'number'); |  | ||||||
|  |  | ||||||
|  |  | ||||||
|         $amount = $repetition->amount; |  | ||||||
|  |  | ||||||
|         while ($start <= $end) { |  | ||||||
|             /* |  | ||||||
|              * Sum of expenses on this day: |  | ||||||
|              */ |  | ||||||
|             $sum = $repository->expensesOnDay($budget, $start); |  | ||||||
|             $amount += $sum; |  | ||||||
|             $chart->addRow(clone $start, $amount); |  | ||||||
|             $start->addDay(); |  | ||||||
|         } |  | ||||||
|         $chart->generate(); |  | ||||||
|  |  | ||||||
|         return Response::json($chart->getData()); |  | ||||||
|  |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * @param Budget                    $budget |  | ||||||
|      * @param int                       $year |  | ||||||
|      * @param GChart                    $chart |  | ||||||
|      * @param BudgetRepositoryInterface $repository |  | ||||||
|      * |  | ||||||
|      * @return \Symfony\Component\HttpFoundation\Response |  | ||||||
|      */ |  | ||||||
|     public function budgetsAndSpending(GChart $chart, BudgetRepositoryInterface $repository, Budget $budget, $year = 0) |  | ||||||
|     { |  | ||||||
|         $chart->addColumn('Month', 'date'); |  | ||||||
|         $chart->addColumn('Budgeted', 'number'); |  | ||||||
|         $chart->addColumn('Spent', 'number'); |  | ||||||
|  |  | ||||||
|         if ($year == 0) { |  | ||||||
|             $start = $repository->getFirstBudgetLimitDate($budget); |  | ||||||
|             $end   = $repository->getLastBudgetLimitDate($budget); |  | ||||||
|         } else { |  | ||||||
|             $start = Carbon::createFromDate(intval($year), 1, 1); |  | ||||||
|             $end   = clone $start; |  | ||||||
|             $end->endOfYear(); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         while ($start <= $end) { |  | ||||||
|             $spent    = $repository->spentInMonth($budget, $start); |  | ||||||
|             $budgeted = $repository->getLimitAmountOnDate($budget, $start); |  | ||||||
|             $chart->addRow(clone $start, $budgeted, $spent); |  | ||||||
|             $start->addMonth(); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         $chart->generate(); |  | ||||||
|  |  | ||||||
|         return Response::json($chart->getData()); |  | ||||||
|  |  | ||||||
|  |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * |  | ||||||
|      * @param Category $category |  | ||||||
|      * |  | ||||||
|      * @return \Illuminate\Http\JsonResponse |  | ||||||
|      */ |  | ||||||
|     public function categoryOverviewChart(Category $category, GChart $chart, CategoryRepositoryInterface $repository) |  | ||||||
|     { |  | ||||||
|         // oldest transaction in category: |  | ||||||
|         $start = $repository->getFirstActivityDate($category); |  | ||||||
|  |  | ||||||
|         /** @var Preference $range */ |  | ||||||
|         $range = Preferences::get('viewRange', '1M'); |  | ||||||
|         // jump to start of week / month / year / etc (TODO). |  | ||||||
|         $start = Navigation::startOfPeriod($start, $range->data); |  | ||||||
|  |  | ||||||
|         $chart->addColumn('Period', 'date'); |  | ||||||
|         $chart->addColumn('Spent', 'number'); |  | ||||||
|  |  | ||||||
|         $end = new Carbon; |  | ||||||
|         while ($start <= $end) { |  | ||||||
|  |  | ||||||
|             $currentEnd = Navigation::endOfPeriod($start, $range->data); |  | ||||||
|             $spent      = $repository->spentInPeriodSum($category, $start, $currentEnd); |  | ||||||
|             $chart->addRow(clone $start, $spent); |  | ||||||
|  |  | ||||||
|             $start = Navigation::addPeriod($start, $range->data, 0); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         $chart->generate(); |  | ||||||
|  |  | ||||||
|         return Response::json($chart->getData()); |  | ||||||
|  |  | ||||||
|  |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * |  | ||||||
|      * @param Category $category |  | ||||||
|      * |  | ||||||
|      * @return \Illuminate\Http\JsonResponse |  | ||||||
|      */ |  | ||||||
|     public function categoryPeriodChart(Category $category, GChart $chart, CategoryRepositoryInterface $repository) |  | ||||||
|     { |  | ||||||
|         $start = clone Session::get('start', Carbon::now()->startOfMonth()); |  | ||||||
|         $chart->addColumn('Period', 'date'); |  | ||||||
|         $chart->addColumn('Spent', 'number'); |  | ||||||
|  |  | ||||||
|         $end = Session::get('end', Carbon::now()->endOfMonth()); |  | ||||||
|         while ($start <= $end) { |  | ||||||
|             $spent = $repository->spentOnDaySum($category, $start); |  | ||||||
|             $chart->addRow(clone $start, $spent); |  | ||||||
|             $start->addDay(); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         $chart->generate(); |  | ||||||
|  |  | ||||||
|         return Response::json($chart->getData()); |  | ||||||
|  |  | ||||||
|  |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * @param PiggyBank $piggyBank |  | ||||||
|      * |  | ||||||
|      * @return \Illuminate\Http\JsonResponse |  | ||||||
|      */ |  | ||||||
|     public function piggyBankHistory(PiggyBank $piggyBank, GChart $chart, PiggyBankRepositoryInterface $repository) |  | ||||||
|     { |  | ||||||
|         $chart->addColumn('Date', 'date'); |  | ||||||
|         $chart->addColumn('Balance', 'number'); |  | ||||||
|  |  | ||||||
|         /** @var Collection $set */ |  | ||||||
|         $set = $repository->getEventSummarySet($piggyBank); |  | ||||||
|         $sum = 0; |  | ||||||
|  |  | ||||||
|         foreach ($set as $entry) { |  | ||||||
|             $sum += floatval($entry->sum); |  | ||||||
|             $chart->addRow(new Carbon($entry->date), $sum); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         $chart->generate(); |  | ||||||
|  |  | ||||||
|         return Response::json($chart->getData()); |  | ||||||
|  |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * |  | ||||||
|      * @param $year |  | ||||||
|      * |  | ||||||
|      * @return \Illuminate\Http\JsonResponse |  | ||||||
|      */ |  | ||||||
|     public function yearInExp($year, GChart $chart, ReportQueryInterface $query) |  | ||||||
|     { |  | ||||||
|         $start = new Carbon('01-01-' . $year); |  | ||||||
|         $chart->addColumn('Month', 'date'); |  | ||||||
|         $chart->addColumn('Income', 'number'); |  | ||||||
|         $chart->addColumn('Expenses', 'number'); |  | ||||||
|  |  | ||||||
|         $pref              = Preferences::get('showSharedReports', false); |  | ||||||
|         $showSharedReports = $pref->data; |  | ||||||
|  |  | ||||||
|         // get report query interface. |  | ||||||
|  |  | ||||||
|         $end = clone $start; |  | ||||||
|         $end->endOfYear(); |  | ||||||
|         while ($start < $end) { |  | ||||||
|             $currentEnd = clone $start; |  | ||||||
|             $currentEnd->endOfMonth(); |  | ||||||
|             // total income && total expenses: |  | ||||||
|             $incomeSum  = floatval($query->incomeByPeriod($start, $currentEnd, $showSharedReports)->sum('queryAmount')); |  | ||||||
|             $expenseSum = floatval($query->journalsByExpenseAccount($start, $currentEnd, $showSharedReports)->sum('queryAmount')); |  | ||||||
|  |  | ||||||
|             $chart->addRow(clone $start, $incomeSum, $expenseSum); |  | ||||||
|             $start->addMonth(); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|  |  | ||||||
|         $chart->generate(); |  | ||||||
|  |  | ||||||
|         return Response::json($chart->getData()); |  | ||||||
|  |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * |  | ||||||
|      * @param $year |  | ||||||
|      * |  | ||||||
|      * @return \Illuminate\Http\JsonResponse |  | ||||||
|      */ |  | ||||||
|     public function yearInExpSum($year, GChart $chart, ReportQueryInterface $query) |  | ||||||
|     { |  | ||||||
|         $start = new Carbon('01-01-' . $year); |  | ||||||
|         $chart->addColumn('Summary', 'string'); |  | ||||||
|         $chart->addColumn('Income', 'number'); |  | ||||||
|         $chart->addColumn('Expenses', 'number'); |  | ||||||
|  |  | ||||||
|         $pref              = Preferences::get('showSharedReports', false); |  | ||||||
|         $showSharedReports = $pref->data; |  | ||||||
|  |  | ||||||
|         $income  = 0; |  | ||||||
|         $expense = 0; |  | ||||||
|         $count   = 0; |  | ||||||
|  |  | ||||||
|         $end = clone $start; |  | ||||||
|         $end->endOfYear(); |  | ||||||
|         while ($start < $end) { |  | ||||||
|             $currentEnd = clone $start; |  | ||||||
|             $currentEnd->endOfMonth(); |  | ||||||
|             // total income: |  | ||||||
|             $incomeSum = floatval($query->incomeByPeriod($start, $currentEnd, $showSharedReports)->sum('queryAmount')); |  | ||||||
|             // total expenses: |  | ||||||
|             $expenseSum = floatval($query->journalsByExpenseAccount($start, $currentEnd, $showSharedReports)->sum('queryAmount')); |  | ||||||
|  |  | ||||||
|             $income += $incomeSum; |  | ||||||
|             $expense += $expenseSum; |  | ||||||
|             $count++; |  | ||||||
|             $start->addMonth(); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|  |  | ||||||
|         $chart->addRow('Sum', $income, $expense); |  | ||||||
|         $count = $count > 0 ? $count : 1; |  | ||||||
|         $chart->addRow('Average', ($income / $count), ($expense / $count)); |  | ||||||
|  |  | ||||||
|         $chart->generate(); |  | ||||||
|  |  | ||||||
|         return Response::json($chart->getData()); |  | ||||||
|  |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|  |  | ||||||
| } |  | ||||||
| @@ -13,11 +13,12 @@ class HelpController extends Controller | |||||||
| { | { | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @param $route |      * @param HelpInterface $help | ||||||
|  |      * @param               $route | ||||||
|      * |      * | ||||||
|      * @return \Illuminate\Http\JsonResponse |      * @return \Illuminate\Http\JsonResponse | ||||||
|      */ |      */ | ||||||
|     public function show($route, HelpInterface $help) |     public function show(HelpInterface $help, $route) | ||||||
|     { |     { | ||||||
|         $content = [ |         $content = [ | ||||||
|             'text'  => '<p>There is no help for this route!</p>', |             'text'  => '<p>There is no help for this route!</p>', | ||||||
|   | |||||||
| @@ -53,7 +53,7 @@ class HomeController extends Controller | |||||||
|         $types             = Config::get('firefly.accountTypesByIdentifier.asset'); |         $types             = Config::get('firefly.accountTypesByIdentifier.asset'); | ||||||
|         $count             = $repository->countAccounts($types); |         $count             = $repository->countAccounts($types); | ||||||
|         $title             = 'Firefly'; |         $title             = 'Firefly'; | ||||||
|         $subTitle          = 'What\'s playing?'; |         $subTitle          = trans('firefly.welcomeBack'); | ||||||
|         $mainTitleIcon     = 'fa-fire'; |         $mainTitleIcon     = 'fa-fire'; | ||||||
|         $transactions      = []; |         $transactions      = []; | ||||||
|         $frontPage         = Preferences::get('frontPageAccounts', []); |         $frontPage         = Preferences::get('frontPageAccounts', []); | ||||||
| @@ -63,13 +63,11 @@ class HomeController extends Controller | |||||||
|         $savings           = $repository->getSavingsAccounts(); |         $savings           = $repository->getSavingsAccounts(); | ||||||
|         $piggyBankAccounts = $repository->getPiggyBankAccounts(); |         $piggyBankAccounts = $repository->getPiggyBankAccounts(); | ||||||
|  |  | ||||||
|  |  | ||||||
|         $savingsTotal = 0; |         $savingsTotal = 0; | ||||||
|         foreach ($savings as $savingAccount) { |         foreach ($savings as $savingAccount) { | ||||||
|             $savingsTotal += Steam::balance($savingAccount, $end); |             $savingsTotal += Steam::balance($savingAccount, $end); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         // check if all books are correct. |  | ||||||
|         $sum = $repository->sumOfEverything(); |         $sum = $repository->sumOfEverything(); | ||||||
|         if ($sum != 0) { |         if ($sum != 0) { | ||||||
|             Session::flash( |             Session::flash( | ||||||
|   | |||||||
| @@ -5,15 +5,13 @@ use Carbon\Carbon; | |||||||
| use FireflyIII\Helpers\Report\ReportQueryInterface; | use FireflyIII\Helpers\Report\ReportQueryInterface; | ||||||
| use FireflyIII\Models\Account; | use FireflyIII\Models\Account; | ||||||
| use FireflyIII\Models\Bill; | use FireflyIII\Models\Bill; | ||||||
| use FireflyIII\Models\Transaction; | use FireflyIII\Models\Preference; | ||||||
| use FireflyIII\Models\TransactionType; |  | ||||||
| use FireflyIII\Repositories\Account\AccountRepositoryInterface; | use FireflyIII\Repositories\Account\AccountRepositoryInterface; | ||||||
| use FireflyIII\Repositories\Bill\BillRepositoryInterface; | use FireflyIII\Repositories\Bill\BillRepositoryInterface; | ||||||
| use FireflyIII\Repositories\Category\CategoryRepositoryInterface; | use FireflyIII\Repositories\Category\CategoryRepositoryInterface; | ||||||
| use FireflyIII\Repositories\Journal\JournalRepositoryInterface; | use FireflyIII\Repositories\Journal\JournalRepositoryInterface; | ||||||
| use FireflyIII\Repositories\Tag\TagRepositoryInterface; | use FireflyIII\Repositories\Tag\TagRepositoryInterface; | ||||||
| use Illuminate\Support\Collection; | use Illuminate\Support\Collection; | ||||||
| use Preferences; |  | ||||||
| use Response; | use Response; | ||||||
| use Session; | use Session; | ||||||
| use Steam; | use Steam; | ||||||
| @@ -28,7 +26,9 @@ class JsonController extends Controller | |||||||
|  |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @param BillRepositoryInterface $repository |      * @param BillRepositoryInterface    $repository | ||||||
|  |      * | ||||||
|  |      * @param AccountRepositoryInterface $accountRepository | ||||||
|      * |      * | ||||||
|      * @return \Symfony\Component\HttpFoundation\Response |      * @return \Symfony\Component\HttpFoundation\Response | ||||||
|      */ |      */ | ||||||
| @@ -38,19 +38,14 @@ class JsonController extends Controller | |||||||
|         $end    = Session::get('end', Carbon::now()->endOfMonth()); |         $end    = Session::get('end', Carbon::now()->endOfMonth()); | ||||||
|         $amount = 0; |         $amount = 0; | ||||||
|  |  | ||||||
|         // these two functions are the same as the chart TODO |         // these two functions are the same as the chart | ||||||
|         $bills = $repository->getActiveBills(); |         $bills = $repository->getActiveBills(); | ||||||
|  |  | ||||||
|         /** @var Bill $bill */ |         /** @var Bill $bill */ | ||||||
|         foreach ($bills as $bill) { |         foreach ($bills as $bill) { | ||||||
|             $ranges = $repository->getRanges($bill, $start, $end); |             $amount += $repository->billPaymentsInRange($bill, $start, $end); | ||||||
|  |  | ||||||
|             foreach ($ranges as $range) { |  | ||||||
|                 // paid a bill in this range? |  | ||||||
|                 $amount += $repository->getJournalsInRange($bill, $range['start'], $range['end'])->sum('amount'); |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
|         unset($ranges, $bill, $range, $bills); |         unset($bill, $bills); | ||||||
|  |  | ||||||
|         /** |         /** | ||||||
|          * Find credit card accounts and possibly unpaid credit card bills. |          * Find credit card accounts and possibly unpaid credit card bills. | ||||||
| @@ -59,7 +54,7 @@ class JsonController extends Controller | |||||||
|         // if the balance is not zero, the monthly payment is still underway. |         // if the balance is not zero, the monthly payment is still underway. | ||||||
|         /** @var Account $creditCard */ |         /** @var Account $creditCard */ | ||||||
|         foreach ($creditCards as $creditCard) { |         foreach ($creditCards as $creditCard) { | ||||||
|             $balance = Steam::balance($creditCard, null, true); |             $balance = Steam::balance($creditCard, $end, true); | ||||||
|             if ($balance == 0) { |             if ($balance == 0) { | ||||||
|                 // find a transfer TO the credit card which should account for |                 // find a transfer TO the credit card which should account for | ||||||
|                 // anything paid. If not, the CC is not yet used. |                 // anything paid. If not, the CC is not yet used. | ||||||
| @@ -99,7 +94,7 @@ class JsonController extends Controller | |||||||
|  |  | ||||||
|         $creditCards = $accountRepository->getCreditCards(); |         $creditCards = $accountRepository->getCreditCards(); | ||||||
|         foreach ($creditCards as $creditCard) { |         foreach ($creditCards as $creditCard) { | ||||||
|             $balance = Steam::balance($creditCard, null, true); |             $balance = Steam::balance($creditCard, $end, true); | ||||||
|             $date    = new Carbon($creditCard->getMeta('ccMonthlyPaymentDate')); |             $date    = new Carbon($creditCard->getMeta('ccMonthlyPaymentDate')); | ||||||
|             if ($balance < 0) { |             if ($balance < 0) { | ||||||
|                 // unpaid! create a fake bill that matches the amount. |                 // unpaid! create a fake bill that matches the amount. | ||||||
| @@ -127,7 +122,12 @@ class JsonController extends Controller | |||||||
|     { |     { | ||||||
|         $start  = Session::get('start', Carbon::now()->startOfMonth()); |         $start  = Session::get('start', Carbon::now()->startOfMonth()); | ||||||
|         $end    = Session::get('end', Carbon::now()->endOfMonth()); |         $end    = Session::get('end', Carbon::now()->endOfMonth()); | ||||||
|         $amount = $reportQuery->incomeByPeriod($start, $end, true)->sum('queryAmount'); |         $amount = $reportQuery->incomeInPeriodCorrected($start, $end, true)->sum('amount'); | ||||||
|  |         //        $amount = 0; | ||||||
|  |         //        foreach($set as $entry) { | ||||||
|  |         //            //echo $entry->description.' ('.$entry->tags->count().'): ' . $entry->amount."\n"; | ||||||
|  |         //            $amount += $entry->amount; | ||||||
|  |         //        } | ||||||
|  |  | ||||||
|         return Response::json(['box' => 'in', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount]); |         return Response::json(['box' => 'in', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount]); | ||||||
|     } |     } | ||||||
| @@ -141,7 +141,7 @@ class JsonController extends Controller | |||||||
|     { |     { | ||||||
|         $start  = Session::get('start', Carbon::now()->startOfMonth()); |         $start  = Session::get('start', Carbon::now()->startOfMonth()); | ||||||
|         $end    = Session::get('end', Carbon::now()->endOfMonth()); |         $end    = Session::get('end', Carbon::now()->endOfMonth()); | ||||||
|         $amount = $reportQuery->journalsByExpenseAccount($start, $end, true)->sum('queryAmount'); |         $amount = $reportQuery->expenseInPeriodCorrected($start, $end, true)->sum('amount'); | ||||||
|  |  | ||||||
|         return Response::json(['box' => 'out', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount]); |         return Response::json(['box' => 'out', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount]); | ||||||
|     } |     } | ||||||
| @@ -149,6 +149,8 @@ class JsonController extends Controller | |||||||
|     /** |     /** | ||||||
|      * Returns a list of categories. |      * Returns a list of categories. | ||||||
|      * |      * | ||||||
|  |      * @param CategoryRepositoryInterface $repository | ||||||
|  |      * | ||||||
|      * @return \Illuminate\Http\JsonResponse |      * @return \Illuminate\Http\JsonResponse | ||||||
|      */ |      */ | ||||||
|     public function categories(CategoryRepositoryInterface $repository) |     public function categories(CategoryRepositoryInterface $repository) | ||||||
| @@ -166,6 +168,8 @@ class JsonController extends Controller | |||||||
|     /** |     /** | ||||||
|      * Returns a JSON list of all beneficiaries. |      * Returns a JSON list of all beneficiaries. | ||||||
|      * |      * | ||||||
|  |      * @param AccountRepositoryInterface $accountRepository | ||||||
|  |      * | ||||||
|      * @return \Illuminate\Http\JsonResponse |      * @return \Illuminate\Http\JsonResponse | ||||||
|      */ |      */ | ||||||
|     public function expenseAccounts(AccountRepositoryInterface $accountRepository) |     public function expenseAccounts(AccountRepositoryInterface $accountRepository) | ||||||
| @@ -180,9 +184,28 @@ class JsonController extends Controller | |||||||
|  |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param AccountRepositoryInterface $accountRepository | ||||||
|  |      * | ||||||
|  |      * @return \Illuminate\Http\JsonResponse | ||||||
|  |      */ | ||||||
|  |     public function revenueAccounts(AccountRepositoryInterface $accountRepository) | ||||||
|  |     { | ||||||
|  |         $list   = $accountRepository->getAccounts(['Revenue account']); | ||||||
|  |         $return = []; | ||||||
|  |         foreach ($list as $entry) { | ||||||
|  |             $return[] = $entry->name; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return Response::json($return); | ||||||
|  |  | ||||||
|  |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Returns a JSON list of all beneficiaries. |      * Returns a JSON list of all beneficiaries. | ||||||
|      * |      * | ||||||
|  |      * @param TagRepositoryInterface $tagRepository | ||||||
|  |      * | ||||||
|      * @return \Illuminate\Http\JsonResponse |      * @return \Illuminate\Http\JsonResponse | ||||||
|      */ |      */ | ||||||
|     public function tags(TagRepositoryInterface $tagRepository) |     public function tags(TagRepositoryInterface $tagRepository) | ||||||
| @@ -198,49 +221,12 @@ class JsonController extends Controller | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @return \Illuminate\Http\JsonResponse |      * @param JournalRepositoryInterface $repository | ||||||
|      */ |      * @param                            $what | ||||||
|     public function revenueAccounts(AccountRepositoryInterface $accountRepository) |  | ||||||
|     { |  | ||||||
|         $list   = $accountRepository->getAccounts(['Revenue account']); |  | ||||||
|         $return = []; |  | ||||||
|         foreach ($list as $entry) { |  | ||||||
|             $return[] = $entry->name; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         return Response::json($return); |  | ||||||
|  |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * @return \Symfony\Component\HttpFoundation\Response |  | ||||||
|      */ |  | ||||||
|     public function setSharedReports() |  | ||||||
|     { |  | ||||||
|         $pref = Preferences::get('showSharedReports', false); |  | ||||||
|         $new  = !$pref->data; |  | ||||||
|         Preferences::set('showSharedReports', $new); |  | ||||||
|  |  | ||||||
|  |  | ||||||
|         return Response::json(['value' => $new]); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * @return \Symfony\Component\HttpFoundation\Response |  | ||||||
|      */ |  | ||||||
|     public function showSharedReports() |  | ||||||
|     { |  | ||||||
|         $pref = Preferences::get('showSharedReports', false); |  | ||||||
|  |  | ||||||
|         return Response::json(['value' => $pref->data]); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * @param $what |  | ||||||
|      * |      * | ||||||
|      * @return \Symfony\Component\HttpFoundation\Response |      * @return \Symfony\Component\HttpFoundation\Response | ||||||
|      */ |      */ | ||||||
|     public function transactionJournals($what, JournalRepositoryInterface $repository) |     public function transactionJournals(JournalRepositoryInterface $repository, $what) | ||||||
|     { |     { | ||||||
|         $descriptions = []; |         $descriptions = []; | ||||||
|         $dbType       = $repository->getTransactionType($what); |         $dbType       = $repository->getTransactionType($what); | ||||||
|   | |||||||
| @@ -6,9 +6,7 @@ use Config; | |||||||
| use ExpandedForm; | use ExpandedForm; | ||||||
| use FireflyIII\Http\Requests; | use FireflyIII\Http\Requests; | ||||||
| use FireflyIII\Http\Requests\PiggyBankFormRequest; | use FireflyIII\Http\Requests\PiggyBankFormRequest; | ||||||
| use FireflyIII\Models\Account; |  | ||||||
| use FireflyIII\Models\PiggyBank; | use FireflyIII\Models\PiggyBank; | ||||||
| use FireflyIII\Models\PiggyBankEvent; |  | ||||||
| use FireflyIII\Repositories\Account\AccountRepositoryInterface; | use FireflyIII\Repositories\Account\AccountRepositoryInterface; | ||||||
| use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface; | use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface; | ||||||
| use Illuminate\Support\Collection; | use Illuminate\Support\Collection; | ||||||
| @@ -33,20 +31,22 @@ class PiggyBankController extends Controller | |||||||
|     public function __construct() |     public function __construct() | ||||||
|     { |     { | ||||||
|         parent::__construct(); |         parent::__construct(); | ||||||
|         View::share('title', 'Piggy banks'); |         View::share('title', trans('firefly.piggyBanks')); | ||||||
|         View::share('mainTitleIcon', 'fa-sort-amount-asc'); |         View::share('mainTitleIcon', 'fa-sort-amount-asc'); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Add money to piggy bank |      * Add money to piggy bank | ||||||
|      * |      * | ||||||
|      * @param PiggyBank $piggyBank |      * @param AccountRepositoryInterface $repository | ||||||
|  |      * @param PiggyBank                  $piggyBank | ||||||
|      * |      * | ||||||
|      * @return $this |      * @return $this | ||||||
|      */ |      */ | ||||||
|     public function add(PiggyBank $piggyBank, AccountRepositoryInterface $repository) |     public function add(AccountRepositoryInterface $repository, PiggyBank $piggyBank) | ||||||
|     { |     { | ||||||
|         $leftOnAccount = $repository->leftOnAccount($piggyBank->account); |         $date          = Session::get('end', Carbon::now()->endOfMonth()); | ||||||
|  |         $leftOnAccount = $repository->leftOnAccount($piggyBank->account, $date); | ||||||
|         $savedSoFar    = $piggyBank->currentRelevantRep()->currentamount; |         $savedSoFar    = $piggyBank->currentRelevantRep()->currentamount; | ||||||
|         $leftToSave    = $piggyBank->targetamount - $savedSoFar; |         $leftToSave    = $piggyBank->targetamount - $savedSoFar; | ||||||
|         $maxAmount     = min($leftOnAccount, $leftToSave); |         $maxAmount     = min($leftOnAccount, $leftToSave); | ||||||
| @@ -55,15 +55,15 @@ class PiggyBankController extends Controller | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * @param AccountRepositoryInterface $repository | ||||||
|  |      * | ||||||
|      * @return mixed |      * @return mixed | ||||||
|      */ |      */ | ||||||
|     public function create(AccountRepositoryInterface $repository) |     public function create(AccountRepositoryInterface $repository) | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $periods  = Config::get('firefly.piggy_bank_periods'); |         $periods      = Config::get('firefly.piggy_bank_periods'); | ||||||
|         $accounts = ExpandedForm::makeSelectList($repository->getAccounts(['Default account', 'Asset account'])); |         $accounts     = ExpandedForm::makeSelectList($repository->getAccounts(['Default account', 'Asset account'])); | ||||||
|         //Auth::user()->accounts()->orderBy('accounts.name', 'ASC')->accountTypeIn(['Default account', 'Asset account'])->get(['accounts.*']) |  | ||||||
|         //        ); |  | ||||||
|         $subTitle     = 'Create new piggy bank'; |         $subTitle     = 'Create new piggy bank'; | ||||||
|         $subTitleIcon = 'fa-plus'; |         $subTitleIcon = 'fa-plus'; | ||||||
|  |  | ||||||
| @@ -92,11 +92,12 @@ class PiggyBankController extends Controller | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @param PiggyBank $piggyBank |      * @param PiggyBankRepositoryInterface $repository | ||||||
|  |      * @param PiggyBank                    $piggyBank | ||||||
|      * |      * | ||||||
|      * @return \Illuminate\Http\RedirectResponse |      * @return \Illuminate\Http\RedirectResponse | ||||||
|      */ |      */ | ||||||
|     public function destroy(PiggyBank $piggyBank, PiggyBankRepositoryInterface $repository) |     public function destroy(PiggyBankRepositoryInterface $repository, PiggyBank $piggyBank) | ||||||
|     { |     { | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -107,13 +108,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 View | ||||||
|      * |  | ||||||
|      * @return $this |  | ||||||
|      */ |      */ | ||||||
|     public function edit(PiggyBank $piggyBank, AccountRepositoryInterface $repository) |     public function edit(AccountRepositoryInterface $repository, PiggyBank $piggyBank) | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $periods      = Config::get('firefly.piggy_bank_periods'); |         $periods      = Config::get('firefly.piggy_bank_periods'); | ||||||
| @@ -149,12 +149,16 @@ class PiggyBankController extends Controller | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @return $this |      * @param AccountRepositoryInterface   $repository | ||||||
|  |      * @param PiggyBankRepositoryInterface $piggyRepository | ||||||
|  |      * | ||||||
|  |      * @return View | ||||||
|      */ |      */ | ||||||
|     public function index(AccountRepositoryInterface $repository, PiggyBankRepositoryInterface $piggyRepository) |     public function index(AccountRepositoryInterface $repository, PiggyBankRepositoryInterface $piggyRepository) | ||||||
|     { |     { | ||||||
|         /** @var Collection $piggyBanks */ |         /** @var Collection $piggyBanks */ | ||||||
|         $piggyBanks = $piggyRepository->getPiggyBanks(); |         $piggyBanks = $piggyRepository->getPiggyBanks(); | ||||||
|  |         $end        = Session::get('end', Carbon::now()->endOfMonth()); | ||||||
|  |  | ||||||
|         $accounts = []; |         $accounts = []; | ||||||
|         /** @var PiggyBank $piggyBank */ |         /** @var PiggyBank $piggyBank */ | ||||||
| @@ -170,8 +174,8 @@ class PiggyBankController extends Controller | |||||||
|             if (!isset($accounts[$account->id])) { |             if (!isset($accounts[$account->id])) { | ||||||
|                 $accounts[$account->id] = [ |                 $accounts[$account->id] = [ | ||||||
|                     'name'              => $account->name, |                     'name'              => $account->name, | ||||||
|                     'balance'           => Steam::balance($account, null, true), |                     'balance'           => Steam::balance($account, $end, true), | ||||||
|                     'leftForPiggyBanks' => $repository->leftOnAccount($account), |                     'leftForPiggyBanks' => $repository->leftOnAccount($account, $end), | ||||||
|                     'sumOfSaved'        => $piggyBank->savedSoFar, |                     'sumOfSaved'        => $piggyBank->savedSoFar, | ||||||
|                     'sumOfTargets'      => floatval($piggyBank->targetamount), |                     'sumOfTargets'      => floatval($piggyBank->targetamount), | ||||||
|                     'leftToSave'        => $piggyBank->leftToSave |                     'leftToSave'        => $piggyBank->leftToSave | ||||||
| @@ -187,7 +191,7 @@ class PiggyBankController extends Controller | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Allow user to order piggy banks. |      * @param PiggyBankRepositoryInterface $repository | ||||||
|      */ |      */ | ||||||
|     public function order(PiggyBankRepositoryInterface $repository) |     public function order(PiggyBankRepositoryInterface $repository) | ||||||
|     { |     { | ||||||
| @@ -204,16 +208,17 @@ class PiggyBankController extends Controller | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * POST add money to piggy bank |      * @param PiggyBankRepositoryInterface $repository | ||||||
|      * |      * @param AccountRepositoryInterface   $accounts | ||||||
|      * @param PiggyBank $piggyBank |      * @param PiggyBank                    $piggyBank | ||||||
|      * |      * | ||||||
|      * @return \Illuminate\Http\RedirectResponse |      * @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); |         $amount        = round(floatval(Input::get('amount')), 2); | ||||||
|         $leftOnAccount = $accounts->leftOnAccount($piggyBank->account); |         $date          = Session::get('end', Carbon::now()->endOfMonth()); | ||||||
|  |         $leftOnAccount = $accounts->leftOnAccount($piggyBank->account, $date); | ||||||
|         $savedSoFar    = $piggyBank->currentRelevantRep()->currentamount; |         $savedSoFar    = $piggyBank->currentRelevantRep()->currentamount; | ||||||
|         $leftToSave    = $piggyBank->targetamount - $savedSoFar; |         $leftToSave    = $piggyBank->targetamount - $savedSoFar; | ||||||
|         $maxAmount     = round(min($leftOnAccount, $leftToSave), 2); |         $maxAmount     = round(min($leftOnAccount, $leftToSave), 2); | ||||||
| @@ -240,11 +245,12 @@ class PiggyBankController extends Controller | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @param PiggyBank $piggyBank |      * @param PiggyBankRepositoryInterface $repository | ||||||
|  |      * @param PiggyBank                    $piggyBank | ||||||
|      * |      * | ||||||
|      * @return \Illuminate\Http\RedirectResponse |      * @return \Illuminate\Http\RedirectResponse | ||||||
|      */ |      */ | ||||||
|     public function postRemove(PiggyBank $piggyBank, PiggyBankRepositoryInterface $repository) |     public function postRemove(PiggyBankRepositoryInterface $repository, PiggyBank $piggyBank) | ||||||
|     { |     { | ||||||
|         $amount = floatval(Input::get('amount')); |         $amount = floatval(Input::get('amount')); | ||||||
|  |  | ||||||
| @@ -269,7 +275,6 @@ class PiggyBankController extends Controller | |||||||
|     /** |     /** | ||||||
|      * @param PiggyBank $piggyBank |      * @param PiggyBank $piggyBank | ||||||
|      * |      * | ||||||
|      * @SuppressWarnings("Unused") |  | ||||||
|      * |      * | ||||||
|      * @return \Illuminate\View\View |      * @return \Illuminate\View\View | ||||||
|      */ |      */ | ||||||
| @@ -279,11 +284,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); |         $events = $repository->getEvents($piggyBank); | ||||||
|  |  | ||||||
| @@ -332,13 +338,13 @@ class PiggyBankController extends Controller | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @param PiggyBank $piggyBank |      * @param PiggyBankRepositoryInterface $repository | ||||||
|      * |      * @param PiggyBankFormRequest         $request | ||||||
|      * @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind. |      * @param PiggyBank                    $piggyBank | ||||||
|      * |      * | ||||||
|      * @return $this |      * @return $this | ||||||
|      */ |      */ | ||||||
|     public function update(PiggyBank $piggyBank, PiggyBankRepositoryInterface $repository, PiggyBankFormRequest $request) |     public function update(PiggyBankRepositoryInterface $repository, PiggyBankFormRequest $request, PiggyBank $piggyBank) | ||||||
|     { |     { | ||||||
|         $piggyBankData = [ |         $piggyBankData = [ | ||||||
|             'name'         => $request->get('name'), |             'name'         => $request->get('name'), | ||||||
|   | |||||||
| @@ -1,5 +1,6 @@ | |||||||
| <?php namespace FireflyIII\Http\Controllers; | <?php namespace FireflyIII\Http\Controllers; | ||||||
|  |  | ||||||
|  | use Config; | ||||||
| use FireflyIII\Repositories\Account\AccountRepositoryInterface; | use FireflyIII\Repositories\Account\AccountRepositoryInterface; | ||||||
| use Input; | use Input; | ||||||
| use Preferences; | use Preferences; | ||||||
| @@ -21,25 +22,27 @@ class PreferencesController extends Controller | |||||||
|     public function __construct() |     public function __construct() | ||||||
|     { |     { | ||||||
|         parent::__construct(); |         parent::__construct(); | ||||||
|         View::share('title', 'Preferences'); |         View::share('title', trans('firefly.preferences')); | ||||||
|         View::share('mainTitleIcon', 'fa-gear'); |         View::share('mainTitleIcon', 'fa-gear'); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * @param AccountRepositoryInterface $repository | ||||||
|  |      * | ||||||
|      * @return $this|\Illuminate\View\View |      * @return $this|\Illuminate\View\View | ||||||
|      */ |      */ | ||||||
|     public function index(AccountRepositoryInterface $repository) |     public function index(AccountRepositoryInterface $repository) | ||||||
|     { |     { | ||||||
|         $accounts       = $repository->getAccounts(['Default account', 'Asset account']); |         $accounts          = $repository->getAccounts(['Default account', 'Asset account']); | ||||||
|         $viewRange      = Preferences::get('viewRange', '1M'); |         $viewRangePref     = Preferences::get('viewRange', '1M'); | ||||||
|         $viewRangeValue = $viewRange->data; |         $viewRange         = $viewRangePref->data; | ||||||
|         $frontPage      = Preferences::get('frontPageAccounts', []); |         $frontPageAccounts = Preferences::get('frontPageAccounts', []); | ||||||
|         $budgetMax      = Preferences::get('budgetMaximum', 1000); |         $budgetMax         = Preferences::get('budgetMaximum', 1000); | ||||||
|         $budgetMaximum  = $budgetMax->data; |         $languagePref      = Preferences::get('language', 'en'); | ||||||
|  |         $language          = $languagePref->data; | ||||||
|  |         $budgetMaximum     = $budgetMax->data; | ||||||
|  |  | ||||||
|         return view('preferences.index', compact('budgetMaximum'))->with('accounts', $accounts)->with('frontPageAccounts', $frontPage)->with( |         return view('preferences.index', compact('budgetMaximum', 'language', 'accounts', 'frontPageAccounts', 'viewRange')); | ||||||
|             'viewRange', $viewRangeValue |  | ||||||
|         ); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -49,10 +52,12 @@ class PreferencesController extends Controller | |||||||
|     { |     { | ||||||
|         // front page accounts |         // front page accounts | ||||||
|         $frontPageAccounts = []; |         $frontPageAccounts = []; | ||||||
|         foreach (Input::get('frontPageAccounts') as $id) { |         if (is_array(Input::get('frontPageAccounts'))) { | ||||||
|             $frontPageAccounts[] = intval($id); |             foreach (Input::get('frontPageAccounts') as $id) { | ||||||
|  |                 $frontPageAccounts[] = intval($id); | ||||||
|  |             } | ||||||
|  |             Preferences::set('frontPageAccounts', $frontPageAccounts); | ||||||
|         } |         } | ||||||
|         Preferences::set('frontPageAccounts', $frontPageAccounts); |  | ||||||
|  |  | ||||||
|         // view range: |         // view range: | ||||||
|         Preferences::set('viewRange', Input::get('viewRange')); |         Preferences::set('viewRange', Input::get('viewRange')); | ||||||
| @@ -65,6 +70,12 @@ class PreferencesController extends Controller | |||||||
|         $budgetMaximum = intval(Input::get('budgetMaximum')); |         $budgetMaximum = intval(Input::get('budgetMaximum')); | ||||||
|         Preferences::set('budgetMaximum', $budgetMaximum); |         Preferences::set('budgetMaximum', $budgetMaximum); | ||||||
|  |  | ||||||
|  |         // language: | ||||||
|  |         $lang = Input::get('language'); | ||||||
|  |         if (in_array($lang, array_keys(Config::get('firefly.lang')))) { | ||||||
|  |             Preferences::set('language', $lang); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |  | ||||||
|         Session::flash('success', 'Preferences saved!'); |         Session::flash('success', 'Preferences saved!'); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -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 |      * @return \Illuminate\View\View | ||||||
|      */ |      */ | ||||||
| @@ -47,8 +37,66 @@ 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'); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param ProfileFormRequest $request | ||||||
|  |      * | ||||||
|  |      * @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View | ||||||
|  |      */ | ||||||
|  |     public function postChangePassword(ProfileFormRequest $request) | ||||||
|  |     { | ||||||
|  |         // old, new1, new2 | ||||||
|  |         if (!Hash::check($request->get('current_password'), Auth::user()->password)) { | ||||||
|  |             Session::flash('error', 'Invalid current password!'); | ||||||
|  |  | ||||||
|  |             return Redirect::route('change-password'); | ||||||
|  |         } | ||||||
|  |         $result = $this->validatePassword($request->get('current_password'), $request->get('new_password')); | ||||||
|  |         if (!($result === true)) { | ||||||
|  |             Session::flash('error', $result); | ||||||
|  |  | ||||||
|  |             return Redirect::route('change-password'); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         // update the user with the new password. | ||||||
|  |         Auth::user()->password = $request->get('new_password'); | ||||||
|  |         Auth::user()->save(); | ||||||
|  |  | ||||||
|  |         Session::flash('success', 'Password changed!'); | ||||||
|  |  | ||||||
|  |         return Redirect::route('profile'); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * | ||||||
|  |      * @param string $old | ||||||
|  |      * @param string $new1 | ||||||
|  |      * | ||||||
|  |      * @return string|bool | ||||||
|  |      */ | ||||||
|  |     protected function validatePassword($old, $new1) | ||||||
|  |     { | ||||||
|  |         if ($new1 == $old) { | ||||||
|  |             return 'The idea is to change your password.'; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return true; | ||||||
|  |  | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param DeleteAccountFormRequest $request | ||||||
|  |      * | ||||||
|  |      * @return \Illuminate\Http\RedirectResponse | ||||||
|  |      * @throws \Exception | ||||||
|  |      */ | ||||||
|     public function postDeleteAccount(DeleteAccountFormRequest $request) |     public function postDeleteAccount(DeleteAccountFormRequest $request) | ||||||
|     { |     { | ||||||
|         // old, new1, new2 |         // old, new1, new2 | ||||||
| @@ -66,57 +114,4 @@ class ProfileController extends Controller | |||||||
|     } |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View |  | ||||||
|      */ |  | ||||||
|     public function postChangePassword(ProfileFormRequest $request) |  | ||||||
|     { |  | ||||||
|         // old, new1, new2 |  | ||||||
|         if (!Hash::check($request->get('current_password'), Auth::user()->password)) { |  | ||||||
|             Session::flash('error', 'Invalid current password!'); |  | ||||||
|  |  | ||||||
|             return Redirect::route('change-password'); |  | ||||||
|         } |  | ||||||
|         $result = $this->validatePassword($request->get('current_password'), $request->get('new_password'), $request->get('new_password_confirmation')); |  | ||||||
|         if (!($result === true)) { |  | ||||||
|             Session::flash('error', $result); |  | ||||||
|  |  | ||||||
|             return Redirect::route('change-password'); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         // update the user with the new password. |  | ||||||
|         Auth::user()->password = $request->get('new_password'); |  | ||||||
|         Auth::user()->save(); |  | ||||||
|  |  | ||||||
|         Session::flash('success', 'Password changed!'); |  | ||||||
|  |  | ||||||
|         return Redirect::route('profile'); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * @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) |  | ||||||
|     { |  | ||||||
|         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; |  | ||||||
|  |  | ||||||
|     } |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,9 +1,7 @@ | |||||||
| <?php namespace FireflyIII\Http\Controllers; | <?php namespace FireflyIII\Http\Controllers; | ||||||
|  |  | ||||||
| use Auth; |  | ||||||
| use Carbon\Carbon; |  | ||||||
| use FireflyIII\Helpers\Reminders\ReminderHelperInterface; |  | ||||||
| use FireflyIII\Models\Reminder; | use FireflyIII\Models\Reminder; | ||||||
|  | use FireflyIII\Repositories\Reminder\ReminderRepositoryInterface; | ||||||
| use Redirect; | use Redirect; | ||||||
| use Session; | use Session; | ||||||
| use URL; | use URL; | ||||||
| @@ -19,6 +17,8 @@ class ReminderController extends Controller | |||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @param Reminder $reminder |      * @param Reminder $reminder | ||||||
|  |      * | ||||||
|  |      * @return \Illuminate\Http\RedirectResponse | ||||||
|      */ |      */ | ||||||
|     public function act(Reminder $reminder) |     public function act(Reminder $reminder) | ||||||
|     { |     { | ||||||
| @@ -36,6 +36,8 @@ class ReminderController extends Controller | |||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @param Reminder $reminder |      * @param Reminder $reminder | ||||||
|  |      * | ||||||
|  |      * @return \Illuminate\Http\RedirectResponse | ||||||
|      */ |      */ | ||||||
|     public function dismiss(Reminder $reminder) |     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( |         $active    = $repository->getActiveReminders(); | ||||||
|             function (Reminder $reminder) use ($helper) { |         $expired   = $repository->getExpiredReminders(); | ||||||
|                 $reminder->description = $helper->getReminderText($reminder); |         $inactive  = $repository->getInactiveReminders(); | ||||||
|             } |         $dismissed = $repository->getDismissedReminders(); | ||||||
|         ); |  | ||||||
|  |  | ||||||
|         $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; |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|         ); |  | ||||||
|  |  | ||||||
|         $title         = 'Reminders'; |         $title         = 'Reminders'; | ||||||
|         $mainTitleIcon = 'fa-clock-o'; |         $mainTitleIcon = 'fa-clock-o'; | ||||||
| @@ -106,6 +71,8 @@ class ReminderController extends Controller | |||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @param Reminder $reminder |      * @param Reminder $reminder | ||||||
|  |      * | ||||||
|  |      * @return \Illuminate\View\View | ||||||
|      */ |      */ | ||||||
|     public function show(Reminder $reminder) |     public function show(Reminder $reminder) | ||||||
|     { |     { | ||||||
|   | |||||||
| @@ -1,15 +1,14 @@ | |||||||
| <?php namespace FireflyIII\Http\Controllers; | <?php namespace FireflyIII\Http\Controllers; | ||||||
|  |  | ||||||
| use Carbon\Carbon; | use Carbon\Carbon; | ||||||
| use Exception; |  | ||||||
| use FireflyIII\Helpers\Report\ReportHelperInterface; | use FireflyIII\Helpers\Report\ReportHelperInterface; | ||||||
| use FireflyIII\Helpers\Report\ReportQueryInterface; |  | ||||||
| use FireflyIII\Models\Account; | use FireflyIII\Models\Account; | ||||||
|  | use FireflyIII\Models\Budget; | ||||||
|  | use FireflyIII\Models\LimitRepetition; | ||||||
| use FireflyIII\Models\Preference; | use FireflyIII\Models\Preference; | ||||||
| use FireflyIII\Models\TransactionJournal; | use FireflyIII\Models\TransactionJournal; | ||||||
| use Preferences; | use FireflyIII\Repositories\Account\AccountRepositoryInterface; | ||||||
| use Session; | use Session; | ||||||
| use Steam; |  | ||||||
| use View; | use View; | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @@ -22,332 +21,132 @@ class ReportController extends Controller | |||||||
|  |  | ||||||
|     /** @var ReportHelperInterface */ |     /** @var ReportHelperInterface */ | ||||||
|     protected $helper; |     protected $helper; | ||||||
|     /** @var ReportQueryInterface */ |  | ||||||
|     protected $query; |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @param ReportHelperInterface $helper |      * @param ReportHelperInterface $helper | ||||||
|      * @param ReportQueryInterface  $query |  | ||||||
|      */ |      */ | ||||||
|     public function __construct(ReportHelperInterface $helper, ReportQueryInterface $query) |     public function __construct(ReportHelperInterface $helper) | ||||||
|     { |     { | ||||||
|         $this->query  = $query; |         parent::__construct(); | ||||||
|         $this->helper = $helper; |         $this->helper = $helper; | ||||||
|  |  | ||||||
|         View::share('title', 'Reports'); |         View::share('title', trans('firefly.reports')); | ||||||
|         View::share('mainTitleIcon', 'fa-line-chart'); |         View::share('mainTitleIcon', 'fa-line-chart'); | ||||||
|  |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @param string $year |      * @param AccountRepositoryInterface $repository | ||||||
|      * @param string $month |  | ||||||
|      * |  | ||||||
|      * @return \Illuminate\View\View |  | ||||||
|      */ |  | ||||||
|     public function budget($year = '2014', $month = '1') |  | ||||||
|     { |  | ||||||
|         $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(); |  | ||||||
|  |  | ||||||
|         // 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) { |  | ||||||
|  |  | ||||||
|             $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) ^^ |  | ||||||
|  |  | ||||||
|             // array with budget information for each account: |  | ||||||
|             $array = []; |  | ||||||
|             // should always hide account |  | ||||||
|             $hide = true; |  | ||||||
|             // loop all budgets |  | ||||||
|             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; |  | ||||||
|                 } |  | ||||||
|                 $accountAmounts[$account->id] += $data['queryAmount']; |  | ||||||
|             } |  | ||||||
|             $account->hide              = $hide; |  | ||||||
|             $account->budgetInformation = $array; |  | ||||||
|             $account->balancedAmount    = $balancedAmount; |  | ||||||
|  |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /** |  | ||||||
|          * Start getBudgetsForMonth DONE |  | ||||||
|          */ |  | ||||||
|         $budgets = $this->helper->getBudgetsForMonth($date, $showSharedReports); |  | ||||||
|  |  | ||||||
|         /** |  | ||||||
|          * End getBudgetsForMonth DONE |  | ||||||
|          */ |  | ||||||
|  |  | ||||||
|         return view('reports.budget', compact('subTitle', 'accountAmounts', 'year', 'month', 'subTitleIcon', 'date', 'accounts', 'budgets')); |  | ||||||
|  |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * @param ReportHelperInterface $helper |  | ||||||
|      * |      * | ||||||
|      * @return View |      * @return View | ||||||
|  |      * @internal param ReportHelperInterface $helper | ||||||
|      */ |      */ | ||||||
|     public function index() |     public function index(AccountRepositoryInterface $repository) | ||||||
|     { |     { | ||||||
|         $start         = Session::get('first'); |         $start  = Session::get('first'); | ||||||
|         $months        = $this->helper->listOfMonths($start); |         $months = $this->helper->listOfMonths($start); | ||||||
|         $years         = $this->helper->listOfYears($start); |  | ||||||
|         $title         = 'Reports'; |  | ||||||
|         $mainTitleIcon = 'fa-line-chart'; |  | ||||||
|  |  | ||||||
|         return view('reports.index', compact('years', 'months', 'title', 'mainTitleIcon')); |         // does the user have shared accounts? | ||||||
|     } |         $accounts  = $repository->getAccounts(['Default account', 'Asset account']); | ||||||
|  |         $hasShared = false; | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * @param Account $account |  | ||||||
|      * @param string  $year |  | ||||||
|      * @param string  $month |  | ||||||
|      * |  | ||||||
|      * @return \Illuminate\View\View |  | ||||||
|      */ |  | ||||||
|     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(); |  | ||||||
|  |  | ||||||
|         $journals = $this->query->balancedTransactionsList($account, $start, $end); |  | ||||||
|  |  | ||||||
|         return view('reports.modal-journal-list', compact('journals')); |  | ||||||
|  |  | ||||||
|  |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * @param Account              $account |  | ||||||
|      * @param string               $year |  | ||||||
|      * @param string               $month |  | ||||||
|      * @param ReportQueryInterface $query |  | ||||||
|      * |  | ||||||
|      * @return View |  | ||||||
|      */ |  | ||||||
|     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(); |  | ||||||
|         $set = $this->query->getTransactionsWithoutBudget($account, $start, $end); |  | ||||||
|  |  | ||||||
|         $journals = $set->filter( |  | ||||||
|             function (TransactionJournal $journal) { |  | ||||||
|                 $count = $journal->transactiongroups()->where('relation', 'balance')->count(); |  | ||||||
|                 if ($count == 0) { |  | ||||||
|                     return $journal; |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|         ); |  | ||||||
|  |  | ||||||
|         return view('reports.modal-journal-list', compact('journals')); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * @param Account $account |  | ||||||
|      * @param string  $year |  | ||||||
|      * @param string  $month |  | ||||||
|      * |  | ||||||
|      * @return \Illuminate\View\View |  | ||||||
|      */ |  | ||||||
|     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(); |  | ||||||
|         $journals = $this->query->getTransactionsWithoutBudget($account, $start, $end); |  | ||||||
|  |  | ||||||
|         return view('reports.modal-journal-list', compact('journals')); |  | ||||||
|  |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * @param string $year |  | ||||||
|      * @param string $month |  | ||||||
|      * |  | ||||||
|      * @return \Illuminate\View\View |  | ||||||
|      */ |  | ||||||
|     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'; |  | ||||||
|         $displaySum   = true; // to show sums in report. |  | ||||||
|         /** @var Preference $pref */ |  | ||||||
|         $pref              = Preferences::get('showSharedReports', false); |  | ||||||
|         $showSharedReports = $pref->data; |  | ||||||
|  |  | ||||||
|  |  | ||||||
|         /** |  | ||||||
|          * |  | ||||||
|          * get income for month (date) |  | ||||||
|          * |  | ||||||
|          */ |  | ||||||
|  |  | ||||||
|         $start = clone $date; |  | ||||||
|         $start->startOfMonth(); |  | ||||||
|         $end = clone $date; |  | ||||||
|         $end->endOfMonth(); |  | ||||||
|  |  | ||||||
|         /** |  | ||||||
|          * Start getIncomeForMonth DONE |  | ||||||
|          */ |  | ||||||
|         $income = $this->query->incomeByPeriod($start, $end, $showSharedReports); |  | ||||||
|         /** |  | ||||||
|          * End getIncomeForMonth DONE |  | ||||||
|          */ |  | ||||||
|         /** |  | ||||||
|          * Start getExpenseGroupedForMonth DONE |  | ||||||
|          */ |  | ||||||
|         $set = $this->query->journalsByExpenseAccount($start, $end, $showSharedReports); |  | ||||||
|  |  | ||||||
|         $expenses = Steam::makeArray($set); |  | ||||||
|         $expenses = Steam::sortArray($expenses); |  | ||||||
|         $expenses = Steam::limitArray($expenses, 10); |  | ||||||
|         /** |  | ||||||
|          * End getExpenseGroupedForMonth DONE |  | ||||||
|          */ |  | ||||||
|         /** |  | ||||||
|          * Start getBudgetsForMonth DONE |  | ||||||
|          */ |  | ||||||
|         $budgets = $this->helper->getBudgetsForMonth($date, $showSharedReports); |  | ||||||
|  |  | ||||||
|         /** |  | ||||||
|          * End getBudgetsForMonth DONE |  | ||||||
|          */ |  | ||||||
|         /** |  | ||||||
|          * Start getCategoriesForMonth DONE |  | ||||||
|          */ |  | ||||||
|         // all categories. |  | ||||||
|         $result     = $this->query->journalsByCategory($start, $end); |  | ||||||
|         $categories = Steam::makeArray($result); |  | ||||||
|  |  | ||||||
|  |  | ||||||
|         // all transfers |  | ||||||
|         if ($showSharedReports === false) { |  | ||||||
|             $result    = $this->query->sharedExpensesByCategory($start, $end); |  | ||||||
|             $transfers = Steam::makeArray($result); |  | ||||||
|             $merged    = Steam::mergeArrays($categories, $transfers); |  | ||||||
|         } else { |  | ||||||
|             $merged = $categories; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|  |  | ||||||
|         // sort. |  | ||||||
|         $sorted = Steam::sortNegativeArray($merged); |  | ||||||
|  |  | ||||||
|         // limit to $limit: |  | ||||||
|         $categories = Steam::limitArray($sorted, 10); |  | ||||||
|         /** |  | ||||||
|          * End getCategoriesForMonth DONE |  | ||||||
|          */ |  | ||||||
|         /** |  | ||||||
|          * Start getAccountsForMonth |  | ||||||
|          */ |  | ||||||
|         $list     = $this->query->accountList($showSharedReports); |  | ||||||
|         $accounts = []; |  | ||||||
|         /** @var Account $account */ |         /** @var Account $account */ | ||||||
|         foreach ($list as $account) { |         foreach ($accounts as $account) { | ||||||
|             $id = intval($account->id); |             if ($account->getMeta('accountRole') == 'sharedAsset') { | ||||||
|             /** @noinspection PhpParamsInspection */ |                 $hasShared = true; | ||||||
|             $accounts[$id] = [ |             } | ||||||
|                 'name'         => $account->name, |  | ||||||
|                 'startBalance' => Steam::balance($account, $start), |  | ||||||
|                 'endBalance'   => Steam::balance($account, $end) |  | ||||||
|             ]; |  | ||||||
|  |  | ||||||
|             $accounts[$id]['difference'] = $accounts[$id]['endBalance'] - $accounts[$id]['startBalance']; |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         /** |  | ||||||
|          * End getAccountsForMonth |         return view('reports.index', compact('months', 'hasShared')); | ||||||
|          */ |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param string $year | ||||||
|  |      * @param string $month | ||||||
|  |      * | ||||||
|  |      * @param bool   $shared | ||||||
|  |      * | ||||||
|  |      * @return \Illuminate\View\View | ||||||
|  |      */ | ||||||
|  |     public function month($year = '2014', $month = '1', $shared = false) | ||||||
|  |     { | ||||||
|  |         $start            = new Carbon($year . '-' . $month . '-01'); | ||||||
|  |         $subTitle         = trans('firefly.reportForMonth', ['date' => $start->formatLocalized($this->monthFormat)]); | ||||||
|  |         $subTitleIcon     = 'fa-calendar'; | ||||||
|  |         $end              = clone $start; | ||||||
|  |         $incomeTopLength  = 8; | ||||||
|  |         $expenseTopLength = 8; | ||||||
|  |         if ($shared == 'shared') { | ||||||
|  |             $shared   = true; | ||||||
|  |             $subTitle = trans('firefly.reportForMonthShared', ['date' => $start->formatLocalized($this->monthFormat)]); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         $end->endOfMonth(); | ||||||
|  |  | ||||||
|  |         $accounts   = $this->helper->getAccountReport($start, $end, $shared); | ||||||
|  |         $incomes    = $this->helper->getIncomeReport($start, $end, $shared); | ||||||
|  |         $expenses   = $this->helper->getExpenseReport($start, $end, $shared); | ||||||
|  |         $budgets    = $this->helper->getBudgetReport($start, $end, $shared); | ||||||
|  |         $categories = $this->helper->getCategoryReport($start, $end, $shared); | ||||||
|  |         $balance    = $this->helper->getBalanceReport($start, $end, $shared); | ||||||
|  |         $bills      = $this->helper->getBillReport($start, $end, $shared); | ||||||
|  |  | ||||||
|  |  | ||||||
|         return view( |         return view( | ||||||
|             'reports.month', |             'reports.month', | ||||||
|             compact( |             compact( | ||||||
|                 'income', 'expenses', 'budgets', 'accounts', 'categories', |                 'start', 'shared', | ||||||
|                 'date', 'subTitle', 'displaySum', 'subTitleIcon' |                 'subTitle', 'subTitleIcon', | ||||||
|  |                 'accounts', | ||||||
|  |                 'incomes', 'incomeTopLength', | ||||||
|  |                 'expenses', 'expenseTopLength', | ||||||
|  |                 'budgets', 'balance', | ||||||
|  |                 'categories', | ||||||
|  |                 'bills' | ||||||
|             ) |             ) | ||||||
|         ); |         ); | ||||||
|  |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @param $year |      * @param      $year | ||||||
|  |      * | ||||||
|  |      * @param bool $shared | ||||||
|      * |      * | ||||||
|      * @return $this |      * @return $this | ||||||
|      */ |      */ | ||||||
|     public function year($year) |     public function year($year, $shared = false) | ||||||
|     { |     { | ||||||
|         try { |         $start            = new Carbon('01-01-' . $year); | ||||||
|             new Carbon('01-01-' . $year); |         $end              = clone $start; | ||||||
|         } catch (Exception $e) { |         $subTitle         = trans('firefly.reportForYear', ['year' => $year]); | ||||||
|             return view('error')->with('message', 'Invalid date.'); |         $subTitleIcon     = 'fa-bar-chart'; | ||||||
|  |         $incomeTopLength  = 8; | ||||||
|  |         $expenseTopLength = 8; | ||||||
|  |  | ||||||
|  |         if ($shared == 'shared') { | ||||||
|  |             $shared   = true; | ||||||
|  |             $subTitle = trans('firefly.reportForYearShared', ['year' => $year]); | ||||||
|         } |         } | ||||||
|         /** @var Preference $pref */ |  | ||||||
|         $pref              = Preferences::get('showSharedReports', false); |  | ||||||
|         $showSharedReports = $pref->data; |  | ||||||
|         $date              = new Carbon('01-01-' . $year); |  | ||||||
|         $end               = clone $date; |  | ||||||
|         $end->endOfYear(); |         $end->endOfYear(); | ||||||
|         $title           = 'Reports'; |  | ||||||
|         $subTitle        = $year; |         $accounts = $this->helper->getAccountReport($start, $end, $shared); | ||||||
|         $subTitleIcon    = 'fa-bar-chart'; |         $incomes  = $this->helper->getIncomeReport($start, $end, $shared); | ||||||
|         $mainTitleIcon   = 'fa-line-chart'; |         $expenses = $this->helper->getExpenseReport($start, $end, $shared); | ||||||
|         $balances        = $this->helper->yearBalanceReport($date, $showSharedReports); |  | ||||||
|         $groupedIncomes  = $this->query->journalsByRevenueAccount($date, $end, $showSharedReports); |  | ||||||
|         $groupedExpenses = $this->query->journalsByExpenseAccount($date, $end, $showSharedReports); |  | ||||||
|  |  | ||||||
|         return view( |         return view( | ||||||
|             'reports.year', compact('date', 'groupedIncomes', 'groupedExpenses', 'year', 'balances', 'title', 'subTitle', 'subTitleIcon', 'mainTitleIcon') |             'reports.year', | ||||||
|  |             compact( | ||||||
|  |                 'start', // the date for this report. | ||||||
|  |                 'shared', // is a shared report? | ||||||
|  |                 'accounts', // all accounts | ||||||
|  |                 'incomes', 'expenses', // expenses and incomes. | ||||||
|  |                 'subTitle', 'subTitleIcon', // subtitle and subtitle icon. | ||||||
|  |                 'incomeTopLength', // length of income top X | ||||||
|  |                 'expenseTopLength' // length of expense top X. | ||||||
|  |             ) | ||||||
|         ); |         ); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -12,6 +12,10 @@ class SearchController extends Controller | |||||||
| { | { | ||||||
|     /** |     /** | ||||||
|      * Results always come in the form of an array [results, count, fullCount] |      * Results always come in the form of an array [results, count, fullCount] | ||||||
|  |      * | ||||||
|  |      * @param SearchInterface $searcher | ||||||
|  |      * | ||||||
|  |      * @return $this | ||||||
|      */ |      */ | ||||||
|     public function index(SearchInterface $searcher) |     public function index(SearchInterface $searcher) | ||||||
|     { |     { | ||||||
|   | |||||||
| @@ -22,10 +22,10 @@ use View; | |||||||
|  * Remember: a balancingAct takes at most one expense and one transfer. |  * Remember: a balancingAct takes at most one expense and one transfer. | ||||||
|  *           an advancePayment takes at most one expense, infinite deposits and NO transfers. |  *           an advancePayment takes at most one expense, infinite deposits and NO transfers. | ||||||
|  * |  * | ||||||
|  * TODO transaction can only have one advancePayment OR balancingAct. |  *  transaction can only have one advancePayment OR balancingAct. | ||||||
|  * TODO Other attempts to put in such a tag are blocked. |  *  Other attempts to put in such a tag are blocked. | ||||||
|  * TODO also show an error when editing a tag and it becomes either |  *  also show an error when editing a tag and it becomes either | ||||||
|  * TODO of these two types. Or rather, block editing of the tag. |  *  of these two types. Or rather, block editing of the tag. | ||||||
|  * |  * | ||||||
|  * @package FireflyIII\Http\Controllers |  * @package FireflyIII\Http\Controllers | ||||||
|  */ |  */ | ||||||
| @@ -87,11 +87,12 @@ class TagController extends Controller | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @param Tag $tag |      * @param TagRepositoryInterface $repository | ||||||
|  |      * @param Tag                    $tag | ||||||
|      * |      * | ||||||
|      * @return \Illuminate\Http\RedirectResponse |      * @return \Illuminate\Http\RedirectResponse | ||||||
|      */ |      */ | ||||||
|     public function destroy(Tag $tag, TagRepositoryInterface $repository) |     public function destroy(TagRepositoryInterface $repository, Tag $tag) | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $tagName = $tag->tag; |         $tagName = $tag->tag; | ||||||
| @@ -132,7 +133,7 @@ class TagController extends Controller | |||||||
|          * changes to an advancePayment. |          * changes to an advancePayment. | ||||||
|          */ |          */ | ||||||
|  |  | ||||||
|         if ($tag->tagMode == 'balancingAct') { |         if ($tag->tagMode == 'balancingAct' || $tag->tagMode == 'nothing') { | ||||||
|             foreach ($tag->transactionjournals as $journal) { |             foreach ($tag->transactionjournals as $journal) { | ||||||
|                 if ($journal->transactionType->type == 'Transfer') { |                 if ($journal->transactionType->type == 'Transfer') { | ||||||
|                     $allowToAdvancePayment = false; |                     $allowToAdvancePayment = false; | ||||||
| @@ -149,7 +150,7 @@ class TagController extends Controller | |||||||
|                 $count++; |                 $count++; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         if($count > 1) { |         if ($count > 1) { | ||||||
|             $allowToAdvancePayment = false; |             $allowToAdvancePayment = false; | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -169,12 +170,12 @@ class TagController extends Controller | |||||||
|                 $count++; |                 $count++; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         if($count > 0) { |         if ($count > 0) { | ||||||
|             $allowToBalancingAct = false; |             $allowToBalancingAct = false; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |  | ||||||
|         // edit tagoptions: |         // edit tag options: | ||||||
|         if ($allowToAdvancePayment === false) { |         if ($allowToAdvancePayment === false) { | ||||||
|             unset($tagOptions['advancePayment']); |             unset($tagOptions['advancePayment']); | ||||||
|         } |         } | ||||||
| @@ -194,6 +195,8 @@ class TagController extends Controller | |||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @param $state |      * @param $state | ||||||
|  |      * | ||||||
|  |      * @return \Symfony\Component\HttpFoundation\Response | ||||||
|      */ |      */ | ||||||
|     public function hideTagHelp($state) |     public function hideTagHelp($state) | ||||||
|     { |     { | ||||||
| @@ -233,7 +236,11 @@ class TagController extends Controller | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @param TagFormRequest $request |      * @param TagFormRequest         $request | ||||||
|  |      * | ||||||
|  |      * @param TagRepositoryInterface $repository | ||||||
|  |      * | ||||||
|  |      * @return $this|\Illuminate\Http\RedirectResponse | ||||||
|      */ |      */ | ||||||
|     public function store(TagFormRequest $request, TagRepositoryInterface $repository) |     public function store(TagFormRequest $request, TagRepositoryInterface $repository) | ||||||
|     { |     { | ||||||
| @@ -273,14 +280,18 @@ class TagController extends Controller | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @param Tag $tag |      * @param TagFormRequest         $request | ||||||
|  |      * @param TagRepositoryInterface $repository | ||||||
|  |      * @param Tag                    $tag | ||||||
|  |      * | ||||||
|  |      * @return $this|\Illuminate\Http\RedirectResponse | ||||||
|      */ |      */ | ||||||
|     public function update(Tag $tag, TagFormRequest $request, TagRepositoryInterface $repository) |     public function update(TagFormRequest $request, TagRepositoryInterface $repository, Tag $tag) | ||||||
|     { |     { | ||||||
|         if (Input::get('setTag') == 'true') { |         if (Input::get('setTag') == 'true') { | ||||||
|             $latitude  = strlen($request->get('latitude')) > 0 ? $request->get('latitude') : null; |             $latitude  = $request->get('latitude'); | ||||||
|             $longitude = strlen($request->get('longitude')) > 0 ? $request->get('longitude') : null; |             $longitude = $request->get('longitude'); | ||||||
|             $zoomLevel = strlen($request->get('zoomLevel')) > 0 ? $request->get('zoomLevel') : null; |             $zoomLevel = $request->get('zoomLevel'); | ||||||
|         } else { |         } else { | ||||||
|             $latitude  = null; |             $latitude  = null; | ||||||
|             $longitude = null; |             $longitude = null; | ||||||
| @@ -311,4 +322,4 @@ class TagController extends Controller | |||||||
|         // redirect to previous URL. |         // redirect to previous URL. | ||||||
|         return Redirect::to(Session::get('tags.edit.url')); |         return Redirect::to(Session::get('tags.edit.url')); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,6 +1,7 @@ | |||||||
| <?php namespace FireflyIII\Http\Controllers; | <?php namespace FireflyIII\Http\Controllers; | ||||||
|  |  | ||||||
| use Auth; | use Auth; | ||||||
|  | use Carbon\Carbon; | ||||||
| use ExpandedForm; | use ExpandedForm; | ||||||
| use FireflyIII\Events\JournalCreated; | use FireflyIII\Events\JournalCreated; | ||||||
| use FireflyIII\Events\JournalSaved; | use FireflyIII\Events\JournalSaved; | ||||||
| @@ -8,8 +9,8 @@ use FireflyIII\Http\Requests; | |||||||
| use FireflyIII\Http\Requests\JournalFormRequest; | use FireflyIII\Http\Requests\JournalFormRequest; | ||||||
| use FireflyIII\Models\Transaction; | use FireflyIII\Models\Transaction; | ||||||
| use FireflyIII\Models\TransactionJournal; | use FireflyIII\Models\TransactionJournal; | ||||||
|  | use FireflyIII\Repositories\Account\AccountRepositoryInterface; | ||||||
| use FireflyIII\Repositories\Journal\JournalRepositoryInterface; | use FireflyIII\Repositories\Journal\JournalRepositoryInterface; | ||||||
| use Illuminate\Pagination\LengthAwarePaginator; |  | ||||||
| use Input; | use Input; | ||||||
| use Redirect; | use Redirect; | ||||||
| use Response; | use Response; | ||||||
| @@ -29,36 +30,29 @@ class TransactionController extends Controller | |||||||
|     public function __construct() |     public function __construct() | ||||||
|     { |     { | ||||||
|         parent::__construct(); |         parent::__construct(); | ||||||
|         View::share('title', 'Transactions'); |         View::share('title', trans('firefly.transactions')); | ||||||
|         View::share('mainTitleIcon', 'fa-repeat'); |         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 View | ||||||
|      * |  | ||||||
|      * @return \Illuminate\View\View |  | ||||||
|      */ |      */ | ||||||
|     public function create($what = 'deposit') |     public function create(AccountRepositoryInterface $repository, $what = 'deposit') | ||||||
|     { |     { | ||||||
|         $accounts   = ExpandedForm::makeSelectList( |         $accounts   = ExpandedForm::makeSelectList($repository->getAccounts(['Default account', 'Asset account'])); | ||||||
|             Auth::user()->accounts()->accountTypeIn(['Default account', 'Asset account'])->orderBy('accounts.name', 'ASC')->orderBy('name', 'ASC')->where( |  | ||||||
|                 'active', 1 |  | ||||||
|             )->orderBy('name', 'DESC')->get(['accounts.*']) |  | ||||||
|         ); |  | ||||||
|         $budgets    = ExpandedForm::makeSelectList(Auth::user()->budgets()->get()); |         $budgets    = ExpandedForm::makeSelectList(Auth::user()->budgets()->get()); | ||||||
|         $budgets[0] = '(no budget)'; |         $budgets[0] = trans('form.noBudget'); | ||||||
|         $piggies    = ExpandedForm::makeSelectList(Auth::user()->piggyBanks()->get()); |         $piggies    = ExpandedForm::makeSelectList(Auth::user()->piggyBanks()->get()); | ||||||
|         $piggies[0] = '(no piggy bank)'; |         $piggies[0] = trans('form.noPiggybank'); | ||||||
|         $preFilled  = Session::has('preFilled') ? Session::get('preFilled') : []; |         $preFilled  = Session::has('preFilled') ? Session::get('preFilled') : []; | ||||||
|         $respondTo  = ['account_id', 'account_from_id']; |         $respondTo  = ['account_id', 'account_from_id']; | ||||||
|         $subTitle   = 'Add a new ' . e($what); |         $subTitle   = trans('form.add_new_' . $what); | ||||||
|  |  | ||||||
|         foreach ($respondTo as $r) { |         foreach ($respondTo as $r) { | ||||||
|             if (!is_null(Input::get($r))) { |             $preFilled[$r] = Input::get($r); | ||||||
|                 $preFilled[$r] = Input::get($r); |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
|         Session::put('preFilled', $preFilled); |         Session::put('preFilled', $preFilled); | ||||||
|  |  | ||||||
| @@ -95,15 +89,16 @@ class TransactionController extends Controller | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @param TransactionJournal $transactionJournal |      * @param JournalRepositoryInterface $repository | ||||||
|  |      * @param TransactionJournal         $transactionJournal | ||||||
|      * |      * | ||||||
|      * @return \Illuminate\Http\RedirectResponse |      * @return \Illuminate\Http\RedirectResponse | ||||||
|      */ |      */ | ||||||
|     public function destroy(TransactionJournal $transactionJournal) |     public function destroy(JournalRepositoryInterface $repository, TransactionJournal $transactionJournal) | ||||||
|     { |     { | ||||||
|         Session::flash('success', 'Transaction "' . e($transactionJournal->description) . '" destroyed.'); |         Session::flash('success', 'Transaction "' . e($transactionJournal->description) . '" destroyed.'); | ||||||
|  |  | ||||||
|         $transactionJournal->delete(); |         $repository->delete($transactionJournal); | ||||||
|  |  | ||||||
|         // redirect to previous URL: |         // redirect to previous URL: | ||||||
|         return Redirect::to(Session::get('transactions.delete.url')); |         return Redirect::to(Session::get('transactions.delete.url')); | ||||||
| @@ -112,23 +107,21 @@ class TransactionController extends Controller | |||||||
|     /** |     /** | ||||||
|      * Shows the view to edit a transaction. |      * Shows the view to edit a transaction. | ||||||
|      * |      * | ||||||
|      * @param TransactionJournal $journal |      * @param AccountRepositoryInterface $repository | ||||||
|  |      * @param TransactionJournal         $journal | ||||||
|      * |      * | ||||||
|      * @return $this |      * @return $this | ||||||
|      */ |      */ | ||||||
|     public function edit(TransactionJournal $journal, JournalRepositoryInterface $repository) |     public function edit(AccountRepositoryInterface $repository, TransactionJournal $journal) | ||||||
|     { |     { | ||||||
|         $what         = strtolower($journal->transactiontype->type); |         $what         = strtolower($journal->transactiontype->type); | ||||||
|         $accounts     = ExpandedForm::makeSelectList( |         $accounts     = ExpandedForm::makeSelectList($repository->getAccounts(['Default account', 'Asset account'])); | ||||||
|             Auth::user()->accounts()->accountTypeIn(['Default account', 'Asset account'])->orderBy('accounts.name', 'ASC')->where('active', 1)->orderBy( |  | ||||||
|                 'name', 'DESC' |  | ||||||
|             )->get(['accounts.*']) |  | ||||||
|         ); |  | ||||||
|         $budgets      = ExpandedForm::makeSelectList(Auth::user()->budgets()->get()); |         $budgets      = ExpandedForm::makeSelectList(Auth::user()->budgets()->get()); | ||||||
|         $budgets[0]   = '(no budget)'; |         $budgets[0]   = trans('form.noBudget'); | ||||||
|         $transactions = $journal->transactions()->orderBy('amount', 'DESC')->get(); |         $transactions = $journal->transactions()->orderBy('amount', 'DESC')->get(); | ||||||
|         $piggies      = ExpandedForm::makeSelectList(Auth::user()->piggyBanks()->get()); |         $piggies      = ExpandedForm::makeSelectList(Auth::user()->piggyBanks()->get()); | ||||||
|         $piggies[0]   = '(no piggy bank)'; |         $piggies[0]   = trans('form.noPiggybank'); | ||||||
|  |         $subTitle     = trans('breadcrumbs.edit_journal', ['description' => $journal->description]); | ||||||
|         $preFilled    = [ |         $preFilled    = [ | ||||||
|             'date'          => $journal->date->format('Y-m-d'), |             'date'          => $journal->date->format('Y-m-d'), | ||||||
|             'category'      => '', |             'category'      => '', | ||||||
| @@ -156,7 +149,7 @@ class TransactionController extends Controller | |||||||
|             $preFilled['piggy_bank_id'] = $journal->piggyBankEvents()->orderBy('date', 'DESC')->first()->piggy_bank_id; |             $preFilled['piggy_bank_id'] = $journal->piggyBankEvents()->orderBy('date', 'DESC')->first()->piggy_bank_id; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         $preFilled['amount']          = $journal->amount; |         $preFilled['amount']          = $journal->actualAmount; | ||||||
|         $preFilled['account_id']      = $journal->assetAccount->id; |         $preFilled['account_id']      = $journal->assetAccount->id; | ||||||
|         $preFilled['expense_account'] = $transactions[0]->account->name; |         $preFilled['expense_account'] = $transactions[0]->account->name; | ||||||
|         $preFilled['revenue_account'] = $transactions[1]->account->name; |         $preFilled['revenue_account'] = $transactions[1]->account->name; | ||||||
| @@ -176,45 +169,39 @@ 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) { |         switch ($what) { | ||||||
|             case 'expenses': |             case 'expenses': | ||||||
|             case 'withdrawal': |             case 'withdrawal': | ||||||
|                 $subTitleIcon = 'fa-long-arrow-left'; |                 $subTitleIcon = 'fa-long-arrow-left'; | ||||||
|                 $subTitle     = 'Expenses'; |                 $subTitle     = trans('firefly.expenses'); | ||||||
|                 $types        = ['Withdrawal']; |                 $types        = ['Withdrawal']; | ||||||
|                 break; |                 break; | ||||||
|             case 'revenue': |             case 'revenue': | ||||||
|             case 'deposit': |             case 'deposit': | ||||||
|                 $subTitleIcon = 'fa-long-arrow-right'; |                 $subTitleIcon = 'fa-long-arrow-right'; | ||||||
|                 $subTitle     = 'Revenue, income and deposits'; |                 $subTitle     = trans('firefly.income'); | ||||||
|                 $types        = ['Deposit']; |                 $types        = ['Deposit']; | ||||||
|                 break; |                 break; | ||||||
|             case 'transfer': |             case 'transfer': | ||||||
|             case 'transfers': |             case 'transfers': | ||||||
|                 $subTitleIcon = 'fa-exchange'; |                 $subTitleIcon = 'fa-exchange'; | ||||||
|                 $subTitle     = 'Transfers'; |                 $subTitle     = trans('firefly.transfers'); | ||||||
|                 $types        = ['Transfer']; |                 $types        = ['Transfer']; | ||||||
|                 break; |                 break; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         $page   = intval(\Input::get('page')); |         $page     = intval(Input::get('page')); | ||||||
|         $offset = $page > 0 ? ($page - 1) * 50 : 0; |         $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); |         $journals->setPath('transactions/' . $what); | ||||||
|  |  | ||||||
|         return view('transactions.index', compact('subTitle', 'what', 'subTitleIcon', 'journals')); |         return view('transactions.index', compact('subTitle', 'what', 'subTitleIcon', 'journals')); | ||||||
| @@ -222,15 +209,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) { |         if (count($ids) > 0) { | ||||||
|             $order = 0; |             $order = 0; | ||||||
|             foreach ($ids as $id) { |             foreach ($ids as $id) { | ||||||
|                 $journal = Auth::user()->transactionjournals()->where('id', $id)->where('date', Input::get('date'))->first(); |  | ||||||
|  |                 $journal = $repository->getWithDate($id, $date); | ||||||
|                 if ($journal) { |                 if ($journal) { | ||||||
|                     $journal->order = $order; |                     $journal->order = $order; | ||||||
|                     $order++; |                     $order++; | ||||||
| @@ -244,31 +235,22 @@ class TransactionController extends Controller | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @param TransactionJournal $journal |      * @param JournalRepositoryInterface $repository | ||||||
|  |      * @param TransactionJournal         $journal | ||||||
|      * |      * | ||||||
|      * @return $this |      * @return $this | ||||||
|      */ |      */ | ||||||
|     public function show(TransactionJournal $journal) |     public function show(JournalRepositoryInterface $repository, TransactionJournal $journal) | ||||||
|     { |     { | ||||||
|         $journal->transactions->each( |         $journal->transactions->each( | ||||||
|             function (Transaction $t) use ($journal) { |             function (Transaction $t) use ($journal, $repository) { | ||||||
|                 $t->before = floatval( |                 $t->before = $repository->getAmountBefore($journal, $t); | ||||||
|                     $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') |  | ||||||
|                 ); |  | ||||||
|                 $t->after  = $t->before + $t->amount; |                 $t->after  = $t->before + $t->amount; | ||||||
|             } |             } | ||||||
|         ); |         ); | ||||||
|  |         $subTitle = trans('firefly.' . $journal->transactiontype->type) . ' "' . e($journal->description) . '"'; | ||||||
|  |  | ||||||
|  |         return view('transactions.show', compact('journal', 'subTitle')); | ||||||
|         return view('transactions.show', compact('journal'))->with( |  | ||||||
|             'subTitle', e($journal->transactiontype->type) . ' "' . e($journal->description) . '"' |  | ||||||
|         ); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -280,21 +262,18 @@ class TransactionController extends Controller | |||||||
|     public function store(JournalFormRequest $request, JournalRepositoryInterface $repository) |     public function store(JournalFormRequest $request, JournalRepositoryInterface $repository) | ||||||
|     { |     { | ||||||
|  |  | ||||||
|  |  | ||||||
|         $journalData = $request->getJournalData(); |         $journalData = $request->getJournalData(); | ||||||
|         $journal     = $repository->store($journalData); |         $journal     = $repository->store($journalData); | ||||||
|  |  | ||||||
|         // rescan journal, UpdateJournalConnection |         // rescan journal, UpdateJournalConnection | ||||||
|         event(new JournalSaved($journal)); |         event(new JournalSaved($journal)); | ||||||
|         // ConnectJournalToPiggyBank |         // ConnectJournalToPiggyBank | ||||||
|         event(new JournalCreated($journal, intval($request->get('piggy_bank_id')))); |         if ($journal->transactionType->type == 'Transfer' && intval($request->get('piggy_bank_id')) > 0) { | ||||||
|  |             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!'); |         Session::flash('success', 'New transaction "' . $journal->description . '" stored!'); | ||||||
|  |  | ||||||
|         if (intval(Input::get('create_another')) === 1) { |         if (intval(Input::get('create_another')) === 1) { | ||||||
| @@ -309,14 +288,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|\Illuminate\Http\RedirectResponse | ||||||
|      * |  | ||||||
|      * @return $this |  | ||||||
|      */ |      */ | ||||||
|     public function update(TransactionJournal $journal, JournalFormRequest $request, JournalRepositoryInterface $repository) |     public function update(JournalFormRequest $request, JournalRepositoryInterface $repository, TransactionJournal $journal) | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $journalData = $request->getJournalData(); |         $journalData = $request->getJournalData(); | ||||||
|   | |||||||
| @@ -1,12 +1,17 @@ | |||||||
| <?php namespace FireflyIII\Http\Middleware; | <?php namespace FireflyIII\Http\Middleware; | ||||||
|  |  | ||||||
|  | use App; | ||||||
| use Closure; | use Closure; | ||||||
|  | use Config; | ||||||
|  | use FireflyIII\Models\Preference; | ||||||
| use Illuminate\Contracts\Auth\Guard; | use Illuminate\Contracts\Auth\Guard; | ||||||
| use Illuminate\Http\Request; | use Illuminate\Http\Request; | ||||||
|  | use Preferences; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Class Authenticate |  * Class Authenticate | ||||||
|  * |  * | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  * @package FireflyIII\Http\Middleware |  * @package FireflyIII\Http\Middleware | ||||||
|  */ |  */ | ||||||
| class Authenticate | class Authenticate | ||||||
| @@ -47,6 +52,11 @@ class Authenticate | |||||||
|                 return redirect()->guest('auth/login'); |                 return redirect()->guest('auth/login'); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |         // if logged in, set user language: | ||||||
|  |         $pref = Preferences::get('language', 'en'); | ||||||
|  |         App::setLocale($pref->data); | ||||||
|  |  | ||||||
|  |         setlocale(LC_TIME, Config::get('firefly.locales.' . $pref->data)); | ||||||
|  |  | ||||||
|         return $next($request); |         return $next($request); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -3,7 +3,6 @@ | |||||||
| namespace FireflyIII\Http\Middleware; | namespace FireflyIII\Http\Middleware; | ||||||
|  |  | ||||||
|  |  | ||||||
| use App; |  | ||||||
| use Closure; | use Closure; | ||||||
| use FireflyIII\Models\PiggyBank; | use FireflyIII\Models\PiggyBank; | ||||||
| use FireflyIII\Models\PiggyBankRepetition; | use FireflyIII\Models\PiggyBankRepetition; | ||||||
| @@ -46,23 +45,22 @@ class PiggyBanks | |||||||
|      */ |      */ | ||||||
|     public function handle(Request $request, Closure $next) |     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: |             // get piggy banks without a repetition: | ||||||
|             /** @var Collection $set */ |             /** @var Collection $set */ | ||||||
|             $set = $this->auth->user()->piggybanks() |             $set = $this->auth->user()->piggybanks() | ||||||
|                               ->leftJoin('piggy_bank_repetitions', 'piggy_banks.id', '=', 'piggy_bank_repetitions.piggy_bank_id') |                               ->leftJoin('piggy_bank_repetitions', 'piggy_banks.id', '=', 'piggy_bank_repetitions.piggy_bank_id') | ||||||
|                               ->whereNull('piggy_bank_repetitions.id') |                               ->whereNull('piggy_bank_repetitions.id') | ||||||
|                               ->get(['piggy_banks.id', 'piggy_banks.startdate', 'piggy_banks.targetdate']); |                               ->get(['piggy_banks.id', 'piggy_banks.startdate', 'piggy_banks.targetdate']); | ||||||
|             if ($set->count() > 0) { |  | ||||||
|                 /** @var PiggyBank $partialPiggy */ |             /** @var PiggyBank $partialPiggy */ | ||||||
|                 foreach ($set as $partialPiggy) { |             foreach ($set as $partialPiggy) { | ||||||
|                     $repetition = new PiggyBankRepetition; |                 $repetition = new PiggyBankRepetition; | ||||||
|                     $repetition->piggyBank()->associate($partialPiggy); |                 $repetition->piggyBank()->associate($partialPiggy); | ||||||
|                     $repetition->startdate     = is_null($partialPiggy->startdate) ? null : $partialPiggy->startdate; |                 $repetition->startdate     = $partialPiggy->startdate; | ||||||
|                     $repetition->targetdate    = is_null($partialPiggy->targetdate) ? null : $partialPiggy->targetdate; |                 $repetition->targetdate    = $partialPiggy->targetdate; | ||||||
|                     $repetition->currentamount = 0; |                 $repetition->currentamount = 0; | ||||||
|                     $repetition->save(); |                 $repetition->save(); | ||||||
|                 } |  | ||||||
|             } |             } | ||||||
|             unset($partialPiggy, $set, $repetition); |             unset($partialPiggy, $set, $repetition); | ||||||
|         } |         } | ||||||
|   | |||||||
| @@ -43,29 +43,27 @@ class Range | |||||||
|      * |      * | ||||||
|      * @param  \Illuminate\Http\Request $request |      * @param  \Illuminate\Http\Request $request | ||||||
|      * @param  \Closure                 $theNext |      * @param  \Closure                 $theNext | ||||||
|  |      * @SuppressWarnings(PHPMD.CyclomaticComplexity) | ||||||
|      * |      * | ||||||
|      * @return mixed |      * @return mixed | ||||||
|      */ |      */ | ||||||
|     public function handle(Request $request, Closure $theNext) |     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: |             // ignore preference. set the range to be the current month: | ||||||
|             if (!Session::has('start') && !Session::has('end')) { |             if (!Session::has('start') && !Session::has('end')) { | ||||||
|  |  | ||||||
|                 /** @var \FireflyIII\Models\Preference $viewRange */ |                 /** @var \FireflyIII\Models\Preference $viewRange */ | ||||||
|                 $viewRange = Preferences::get('viewRange', '1M'); |                 $viewRange = Preferences::get('viewRange', '1M')->data; | ||||||
|                 $start     = new Carbon; |                 $start     = new Carbon; | ||||||
|                 $start     = Navigation::updateStartDate($viewRange->data, $start); |                 $start     = Navigation::updateStartDate($viewRange, $start); | ||||||
|                 $end       = Navigation::updateEndDate($viewRange->data, $start); |                 $end       = Navigation::updateEndDate($viewRange, $start); | ||||||
|  |  | ||||||
|                 Session::put('start', $start); |                 Session::put('start', $start); | ||||||
|                 Session::put('end', $end); |                 Session::put('end', $end); | ||||||
|             } |             } | ||||||
|             if (!Session::has('first')) { |             if (!Session::has('first')) { | ||||||
|                 /** |  | ||||||
|                  * Get helper thing. |  | ||||||
|                  */ |  | ||||||
|                 /** @var \FireflyIII\Repositories\Journal\JournalRepositoryInterface $repository */ |                 /** @var \FireflyIII\Repositories\Journal\JournalRepositoryInterface $repository */ | ||||||
|                 $repository = App::make('FireflyIII\Repositories\Journal\JournalRepositoryInterface'); |                 $repository = App::make('FireflyIII\Repositories\Journal\JournalRepositoryInterface'); | ||||||
|                 $journal    = $repository->first(); |                 $journal    = $repository->first(); | ||||||
| @@ -75,16 +73,12 @@ class Range | |||||||
|                     Session::put('first', Carbon::now()->startOfYear()); |                     Session::put('first', Carbon::now()->startOfYear()); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  |             $current = Carbon::now()->formatLocalized('%B %Y'); | ||||||
|             // set current / next / prev month. |             $next    = Carbon::now()->endOfMonth()->addDay()->formatLocalized('%B %Y'); | ||||||
|             $current = Carbon::now()->format('F Y'); |             $prev    = Carbon::now()->startOfMonth()->subDay()->formatLocalized('%B %Y'); | ||||||
|             $next    = Carbon::now()->endOfMonth()->addDay()->format('F Y'); |  | ||||||
|             $prev    = Carbon::now()->startOfMonth()->subDay()->format('F Y'); |  | ||||||
|             View::share('currentMonthName', $current); |             View::share('currentMonthName', $current); | ||||||
|             View::share('previousMonthName', $prev); |             View::share('previousMonthName', $prev); | ||||||
|             View::share('nextMonthName', $next); |             View::share('nextMonthName', $next); | ||||||
|  |  | ||||||
|  |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return $theNext($request); |         return $theNext($request); | ||||||
|   | |||||||
| @@ -8,6 +8,7 @@ use Illuminate\Http\Request; | |||||||
| /** | /** | ||||||
|  * Class RedirectIfAuthenticated |  * Class RedirectIfAuthenticated | ||||||
|  * |  * | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  * @package FireflyIII\Http\Middleware |  * @package FireflyIII\Http\Middleware | ||||||
|  */ |  */ | ||||||
| class RedirectIfAuthenticated | class RedirectIfAuthenticated | ||||||
|   | |||||||
| @@ -46,36 +46,25 @@ class Reminders | |||||||
|      */ |      */ | ||||||
|     public function handle(Request $request, Closure $next) |     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. |             // do reminders stuff. | ||||||
|             $piggyBanks = $this->auth->user()->piggyBanks()->where('remind_me', 1)->get(); |             $piggyBanks = $this->auth->user()->piggyBanks()->where('remind_me', 1)->get(); | ||||||
|             $today      = new Carbon; |  | ||||||
|             /** @var \FireflyIII\Helpers\Reminders\ReminderHelperInterface $helper */ |             /** @var \FireflyIII\Helpers\Reminders\ReminderHelperInterface $helper */ | ||||||
|             $helper = App::make('FireflyIII\Helpers\Reminders\ReminderHelperInterface'); |             $helper = App::make('FireflyIII\Helpers\Reminders\ReminderHelperInterface'); | ||||||
|  |  | ||||||
|             /** @var PiggyBank $piggyBank */ |             /** @var PiggyBank $piggyBank */ | ||||||
|             foreach ($piggyBanks as $piggyBank) { |             foreach ($piggyBanks as $piggyBank) { | ||||||
|                 $ranges = $helper->getReminderRanges($piggyBank); |                 $helper->createReminders($piggyBank, new Carbon); | ||||||
|  |  | ||||||
|                 foreach ($ranges as $range) { |  | ||||||
|                     if ($today < $range['end'] && $today > $range['start']) { |  | ||||||
|                         // create a reminder here! |  | ||||||
|                         $helper->createReminder($piggyBank, $range['start'], $range['end']); |  | ||||||
|                         // stop looping, we're done. |  | ||||||
|                         break; |  | ||||||
|                     } |  | ||||||
|  |  | ||||||
|                 } |  | ||||||
|             } |             } | ||||||
|             // delete invalid reminders |             // delete invalid reminders | ||||||
|             $set = $this->auth->user()->reminders()->leftJoin('piggy_banks', 'piggy_banks.id', '=', 'remindersable_id')->whereNull('piggy_banks.id')->get( |             // this is a construction SQLITE cannot handle :( | ||||||
|                 ['reminders.id'] |             if (env('DB_CONNECTION') != 'sqlite') { | ||||||
|             ); |                 Reminder::whereUserId($this->auth->user()->id) | ||||||
|             foreach ($set as $reminder) { |                         ->leftJoin('piggy_banks', 'piggy_banks.id', '=', 'remindersable_id') | ||||||
|                 $reminder->delete(); |                         ->whereNull('piggy_banks.id') | ||||||
|  |                         ->delete(); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|  |  | ||||||
|             // get and list active reminders: |             // get and list active reminders: | ||||||
|             $reminders = $this->auth->user()->reminders()->today()->get(); |             $reminders = $this->auth->user()->reminders()->today()->get(); | ||||||
|             $reminders->each( |             $reminders->each( | ||||||
|   | |||||||
| @@ -10,6 +10,7 @@ use Log; | |||||||
| /** | /** | ||||||
|  * Class ReplaceTestVars |  * Class ReplaceTestVars | ||||||
|  * |  * | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  * @package FireflyIII\Http\Middleware |  * @package FireflyIII\Http\Middleware | ||||||
|  */ |  */ | ||||||
| class ReplaceTestVars | class ReplaceTestVars | ||||||
|   | |||||||
| @@ -6,6 +6,7 @@ use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier; | |||||||
| /** | /** | ||||||
|  * Class VerifyCsrfToken |  * Class VerifyCsrfToken | ||||||
|  * |  * | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  * @package FireflyIII\Http\Middleware |  * @package FireflyIII\Http\Middleware | ||||||
|  */ |  */ | ||||||
| class VerifyCsrfToken extends BaseVerifier | class VerifyCsrfToken extends BaseVerifier | ||||||
|   | |||||||
| @@ -10,6 +10,7 @@ use Input; | |||||||
| /** | /** | ||||||
|  * Class AccountFormRequest |  * Class AccountFormRequest | ||||||
|  * |  * | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  * @package FireflyIII\Http\Requests |  * @package FireflyIII\Http\Requests | ||||||
|  */ |  */ | ||||||
| class AccountFormRequest extends Request | class AccountFormRequest extends Request | ||||||
|   | |||||||
| @@ -9,6 +9,7 @@ use Input; | |||||||
| /** | /** | ||||||
|  * Class BillFormRequest |  * Class BillFormRequest | ||||||
|  * |  * | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  * @package FireflyIII\Http\Requests |  * @package FireflyIII\Http\Requests | ||||||
|  */ |  */ | ||||||
| class BillFormRequest extends Request | class BillFormRequest extends Request | ||||||
|   | |||||||
| @@ -9,6 +9,7 @@ use Input; | |||||||
| /** | /** | ||||||
|  * Class BudgetFormRequest |  * Class BudgetFormRequest | ||||||
|  * |  * | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  * @package FireflyIII\Http\Requests |  * @package FireflyIII\Http\Requests | ||||||
|  */ |  */ | ||||||
| class BudgetFormRequest extends Request | class BudgetFormRequest extends Request | ||||||
|   | |||||||
| @@ -9,6 +9,7 @@ use Input; | |||||||
| /** | /** | ||||||
|  * Class CategoryFormRequest |  * Class CategoryFormRequest | ||||||
|  * |  * | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  * @package FireflyIII\Http\Requests |  * @package FireflyIII\Http\Requests | ||||||
|  */ |  */ | ||||||
| class CategoryFormRequest extends Request | class CategoryFormRequest extends Request | ||||||
|   | |||||||
| @@ -8,6 +8,7 @@ use Input; | |||||||
| /** | /** | ||||||
|  * Class BillFormRequest |  * Class BillFormRequest | ||||||
|  * |  * | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  * @package FireflyIII\Http\Requests |  * @package FireflyIII\Http\Requests | ||||||
|  */ |  */ | ||||||
| class CurrencyFormRequest extends Request | class CurrencyFormRequest extends Request | ||||||
|   | |||||||
| @@ -7,6 +7,7 @@ use Auth; | |||||||
| /** | /** | ||||||
|  * Class DeleteAccountFormRequest |  * Class DeleteAccountFormRequest | ||||||
|  * |  * | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  * @package FireflyIII\Http\Requests |  * @package FireflyIII\Http\Requests | ||||||
|  */ |  */ | ||||||
| class DeleteAccountFormRequest extends Request | class DeleteAccountFormRequest extends Request | ||||||
| @@ -26,7 +27,7 @@ class DeleteAccountFormRequest extends Request | |||||||
|     public function rules() |     public function rules() | ||||||
|     { |     { | ||||||
|         return [ |         return [ | ||||||
|             'password'          => 'required', |             'password' => 'required', | ||||||
|         ]; |         ]; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -10,6 +10,7 @@ use Input; | |||||||
| /** | /** | ||||||
|  * Class JournalFormRequest |  * Class JournalFormRequest | ||||||
|  * |  * | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  * @package FireflyIII\Http\Requests |  * @package FireflyIII\Http\Requests | ||||||
|  */ |  */ | ||||||
| class JournalFormRequest extends Request | class JournalFormRequest extends Request | ||||||
| @@ -49,15 +50,14 @@ class JournalFormRequest extends Request | |||||||
|     /** |     /** | ||||||
|      * @return array |      * @return array | ||||||
|      * @throws Exception |      * @throws Exception | ||||||
|  |      * @SuppressWarnings(PHPMD.CyclomaticComplexity) | ||||||
|      */ |      */ | ||||||
|     public function rules() |     public function rules() | ||||||
|     { |     { | ||||||
|         // can we switch on the "what"? |         $what  = Input::get('what'); | ||||||
|         $what = Input::get('what'); |  | ||||||
|  |  | ||||||
|         $rules = [ |         $rules = [ | ||||||
|             'description'        => 'required|min:1,max:255', |             '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', |             'amount'             => 'numeric|required|min:0.01', | ||||||
|             'date'               => 'required|date', |             'date'               => 'required|date', | ||||||
|             'reminder_id'        => 'numeric|exists:reminders,id', |             'reminder_id'        => 'numeric|exists:reminders,id', | ||||||
| @@ -73,8 +73,6 @@ class JournalFormRequest extends Request | |||||||
|                 if (intval(Input::get('budget_id')) != 0) { |                 if (intval(Input::get('budget_id')) != 0) { | ||||||
|                     $rules['budget_id'] = 'exists:budgets,id|belongsToUser:budgets'; |                     $rules['budget_id'] = 'exists:budgets,id|belongsToUser:budgets'; | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|  |  | ||||||
|                 break; |                 break; | ||||||
|             case 'deposit': |             case 'deposit': | ||||||
|                 $rules['category']        = 'between:1,255'; |                 $rules['category']        = 'between:1,255'; | ||||||
| @@ -92,7 +90,5 @@ class JournalFormRequest extends Request | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         return $rules; |         return $rules; | ||||||
|  |  | ||||||
|  |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -8,6 +8,7 @@ use Input; | |||||||
| /** | /** | ||||||
|  * Class PiggyBankFormRequest |  * Class PiggyBankFormRequest | ||||||
|  * |  * | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  * @package FireflyIII\Http\Requests |  * @package FireflyIII\Http\Requests | ||||||
|  */ |  */ | ||||||
| class PiggyBankFormRequest extends Request | class PiggyBankFormRequest extends Request | ||||||
|   | |||||||
| @@ -7,6 +7,7 @@ use Auth; | |||||||
| /** | /** | ||||||
|  * Class ProfileFormRequest |  * Class ProfileFormRequest | ||||||
|  * |  * | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  * @package FireflyIII\Http\Requests |  * @package FireflyIII\Http\Requests | ||||||
|  */ |  */ | ||||||
| class ProfileFormRequest extends Request | class ProfileFormRequest extends Request | ||||||
|   | |||||||
| @@ -5,6 +5,7 @@ use Illuminate\Foundation\Http\FormRequest; | |||||||
| /** | /** | ||||||
|  * Class Request |  * Class Request | ||||||
|  * |  * | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  * @package FireflyIII\Http\Requests |  * @package FireflyIII\Http\Requests | ||||||
|  */ |  */ | ||||||
| abstract class Request extends FormRequest | abstract class Request extends FormRequest | ||||||
|   | |||||||
| @@ -15,6 +15,7 @@ use Input; | |||||||
| /** | /** | ||||||
|  * Class TagFormRequest |  * Class TagFormRequest | ||||||
|  * |  * | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  * @package FireflyIII\Http\Requests |  * @package FireflyIII\Http\Requests | ||||||
|  */ |  */ | ||||||
| class TagFormRequest extends Request | class TagFormRequest extends Request | ||||||
| @@ -33,7 +34,7 @@ class TagFormRequest extends Request | |||||||
|      */ |      */ | ||||||
|     public function rules() |     public function rules() | ||||||
|     { |     { | ||||||
|         $idRule = ''; |         $idRule  = ''; | ||||||
|         $tagRule = 'required|min:1|uniqueObjectForUser:tags,tag,TRUE'; |         $tagRule = 'required|min:1|uniqueObjectForUser:tags,tag,TRUE'; | ||||||
|         if (Tag::find(Input::get('id'))) { |         if (Tag::find(Input::get('id'))) { | ||||||
|             $idRule  = 'belongsToUser:tags'; |             $idRule  = 'belongsToUser:tags'; | ||||||
| @@ -47,7 +48,8 @@ class TagFormRequest extends Request | |||||||
|             'date'        => 'date', |             'date'        => 'date', | ||||||
|             'latitude'    => 'numeric|min:-90|max:90', |             'latitude'    => 'numeric|min:-90|max:90', | ||||||
|             'longitude'   => 'numeric|min:-90|max:90', |             'longitude'   => 'numeric|min:-90|max:90', | ||||||
|  |             'zoomLevel'   => 'numeric|min:0|max:80', | ||||||
|             'tagMode'     => 'required|in:nothing,balancingAct,advancePayment' |             'tagMode'     => 'required|in:nothing,balancingAct,advancePayment' | ||||||
|         ]; |         ]; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -9,9 +9,10 @@ use FireflyIII\Models\Category; | |||||||
| use FireflyIII\Models\LimitRepetition; | use FireflyIII\Models\LimitRepetition; | ||||||
| use FireflyIII\Models\PiggyBank; | use FireflyIII\Models\PiggyBank; | ||||||
| use FireflyIII\Models\Reminder; | use FireflyIII\Models\Reminder; | ||||||
|  | use FireflyIII\Models\Tag; | ||||||
| use FireflyIII\Models\TransactionCurrency; | use FireflyIII\Models\TransactionCurrency; | ||||||
| use FireflyIII\Models\TransactionJournal; | use FireflyIII\Models\TransactionJournal; | ||||||
| use FireflyIII\Models\Tag; |  | ||||||
| /* | /* | ||||||
|  * Back home. |  * Back home. | ||||||
|  */ |  */ | ||||||
| @@ -19,7 +20,7 @@ Breadcrumbs::register( | |||||||
|     'home', |     'home', | ||||||
|     function (Generator $breadcrumbs) { |     function (Generator $breadcrumbs) { | ||||||
|  |  | ||||||
|         $breadcrumbs->push('Home', route('index')); |         $breadcrumbs->push(trans('breadcrumbs.home'), route('index')); | ||||||
|     } |     } | ||||||
| ); | ); | ||||||
|  |  | ||||||
| @@ -27,38 +28,32 @@ Breadcrumbs::register( | |||||||
|     'index', |     'index', | ||||||
|     function (Generator $breadcrumbs) { |     function (Generator $breadcrumbs) { | ||||||
|  |  | ||||||
|         $breadcrumbs->push('Home', route('index')); |         $breadcrumbs->push(trans('breadcrumbs.home'), route('index')); | ||||||
|     } |     } | ||||||
| ); | ); | ||||||
|  | //trans('breadcrumbs.') | ||||||
|  |  | ||||||
| // accounts | // accounts | ||||||
| Breadcrumbs::register( | Breadcrumbs::register( | ||||||
|     'accounts.index', function (Generator $breadcrumbs, $what) { |     'accounts.index', function (Generator $breadcrumbs, $what) { | ||||||
|     $breadcrumbs->parent('home'); |     $breadcrumbs->parent('home'); | ||||||
|     $breadcrumbs->push(ucfirst(e($what)) . ' accounts', route('accounts.index', $what)); |     $breadcrumbs->push(trans('breadcrumbs.' . strtolower(e($what)) . '_accounts'), route('accounts.index', $what)); | ||||||
| } | } | ||||||
| ); | ); | ||||||
|  |  | ||||||
|  | Breadcrumbs::register( | ||||||
|  |     'accounts.create', function (Generator $breadcrumbs, $what) { | ||||||
|  |     $breadcrumbs->parent('accounts.index', $what); | ||||||
|  |     $breadcrumbs->push(trans('breadcrumbs.new_' . strtolower(e($what)) . '_account'), route('accounts.create', $what)); | ||||||
|  | } | ||||||
|  | ); | ||||||
|  |  | ||||||
| Breadcrumbs::register( | Breadcrumbs::register( | ||||||
|     'accounts.show', function (Generator $breadcrumbs, Account $account) { |     'accounts.show', function (Generator $breadcrumbs, Account $account) { | ||||||
|     switch ($account->accountType->type) { |  | ||||||
|         default: |     $what = Config::get('firefly.shortNamesByFullName.' . $account->accountType->type); | ||||||
|             throw new FireflyException('Cannot handle account type "' . e($account->accountType->type) . '"'); |  | ||||||
|             break; |  | ||||||
|         case 'Default account': |  | ||||||
|         case 'Asset account': |  | ||||||
|             $what = 'asset'; |  | ||||||
|             break; |  | ||||||
|         case 'Cash account': |  | ||||||
|             $what = 'cash'; |  | ||||||
|             break; |  | ||||||
|         case 'Expense account': |  | ||||||
|         case 'Beneficiary account': |  | ||||||
|             $what = 'expense'; |  | ||||||
|             break; |  | ||||||
|         case 'Revenue account': |  | ||||||
|             $what = 'revenue'; |  | ||||||
|             break; |  | ||||||
|     } |  | ||||||
|     $breadcrumbs->parent('accounts.index', $what); |     $breadcrumbs->parent('accounts.index', $what); | ||||||
|     $breadcrumbs->push(e($account->name), route('accounts.show', $account->id)); |     $breadcrumbs->push(e($account->name), route('accounts.show', $account->id)); | ||||||
| } | } | ||||||
| @@ -66,14 +61,17 @@ Breadcrumbs::register( | |||||||
| Breadcrumbs::register( | Breadcrumbs::register( | ||||||
|     'accounts.delete', function (Generator $breadcrumbs, Account $account) { |     'accounts.delete', function (Generator $breadcrumbs, Account $account) { | ||||||
|     $breadcrumbs->parent('accounts.show', $account); |     $breadcrumbs->parent('accounts.show', $account); | ||||||
|     $breadcrumbs->push('Delete ' . e($account->name), route('accounts.delete', $account->id)); |     $breadcrumbs->push(trans('breadcrumbs.delete_account', ['name' => e($account->name)]), route('accounts.delete', $account->id)); | ||||||
| } | } | ||||||
| ); | ); | ||||||
|  |  | ||||||
|  |  | ||||||
| Breadcrumbs::register( | Breadcrumbs::register( | ||||||
|     'accounts.edit', function (Generator $breadcrumbs, Account $account) { |     'accounts.edit', function (Generator $breadcrumbs, Account $account) { | ||||||
|     $breadcrumbs->parent('accounts.show', $account); |     $breadcrumbs->parent('accounts.show', $account); | ||||||
|     $breadcrumbs->push('Edit ' . e($account->name), route('accounts.edit', $account->id)); |     $what = Config::get('firefly.shortNamesByFullName.' . $account->accountType->type); | ||||||
|  |  | ||||||
|  |     $breadcrumbs->push(trans('breadcrumbs.edit_'.$what.'_account', ['name' => e($account->name)]), route('accounts.edit', $account->id)); | ||||||
| } | } | ||||||
| ); | ); | ||||||
|  |  | ||||||
| @@ -81,26 +79,26 @@ Breadcrumbs::register( | |||||||
| Breadcrumbs::register( | Breadcrumbs::register( | ||||||
|     'budgets.index', function (Generator $breadcrumbs) { |     'budgets.index', function (Generator $breadcrumbs) { | ||||||
|     $breadcrumbs->parent('home'); |     $breadcrumbs->parent('home'); | ||||||
|     $breadcrumbs->push('Budgets', route('budgets.index')); |     $breadcrumbs->push(trans('breadcrumbs.budgets'), route('budgets.index')); | ||||||
| } | } | ||||||
| ); | ); | ||||||
| Breadcrumbs::register( | Breadcrumbs::register( | ||||||
|     'budgets.create', function (Generator $breadcrumbs) { |     'budgets.create', function (Generator $breadcrumbs) { | ||||||
|     $breadcrumbs->parent('budgets.index'); |     $breadcrumbs->parent('budgets.index'); | ||||||
|     $breadcrumbs->push('Create new budget', route('budgets.create')); |     $breadcrumbs->push(trans('breadcrumbs.newBudget'), route('budgets.create')); | ||||||
| } | } | ||||||
| ); | ); | ||||||
|  |  | ||||||
| Breadcrumbs::register( | Breadcrumbs::register( | ||||||
|     'budgets.edit', function (Generator $breadcrumbs, Budget $budget) { |     'budgets.edit', function (Generator $breadcrumbs, Budget $budget) { | ||||||
|     $breadcrumbs->parent('budgets.show', $budget); |     $breadcrumbs->parent('budgets.show', $budget); | ||||||
|     $breadcrumbs->push('Edit ' . e($budget->name), route('budgets.edit', $budget->id)); |     $breadcrumbs->push(trans('breadcrumbs.edit_budget', ['name' => e($budget->name)]), route('budgets.edit', $budget->id)); | ||||||
| } | } | ||||||
| ); | ); | ||||||
| Breadcrumbs::register( | Breadcrumbs::register( | ||||||
|     'budgets.delete', function (Generator $breadcrumbs, Budget $budget) { |     'budgets.delete', function (Generator $breadcrumbs, Budget $budget) { | ||||||
|     $breadcrumbs->parent('budgets.show', $budget); |     $breadcrumbs->parent('budgets.show', $budget); | ||||||
|     $breadcrumbs->push('Delete ' . e($budget->name), route('budgets.delete', $budget->id)); |     $breadcrumbs->push(trans('breadcrumbs.delete_budget', ['name' => e($budget->name)]), route('budgets.delete', $budget->id)); | ||||||
| } | } | ||||||
| ); | ); | ||||||
|  |  | ||||||
| @@ -127,26 +125,26 @@ Breadcrumbs::register( | |||||||
| Breadcrumbs::register( | Breadcrumbs::register( | ||||||
|     'categories.index', function (Generator $breadcrumbs) { |     'categories.index', function (Generator $breadcrumbs) { | ||||||
|     $breadcrumbs->parent('home'); |     $breadcrumbs->parent('home'); | ||||||
|     $breadcrumbs->push('Categories', route('categories.index')); |     $breadcrumbs->push(trans('breadcrumbs.categories'), route('categories.index')); | ||||||
| } | } | ||||||
| ); | ); | ||||||
| Breadcrumbs::register( | Breadcrumbs::register( | ||||||
|     'categories.create', function (Generator $breadcrumbs) { |     'categories.create', function (Generator $breadcrumbs) { | ||||||
|     $breadcrumbs->parent('categories.index'); |     $breadcrumbs->parent('categories.index'); | ||||||
|     $breadcrumbs->push('Create new category', route('categories.create')); |     $breadcrumbs->push(trans('breadcrumbs.newCategory'), route('categories.create')); | ||||||
| } | } | ||||||
| ); | ); | ||||||
|  |  | ||||||
| Breadcrumbs::register( | Breadcrumbs::register( | ||||||
|     'categories.edit', function (Generator $breadcrumbs, Category $category) { |     'categories.edit', function (Generator $breadcrumbs, Category $category) { | ||||||
|     $breadcrumbs->parent('categories.show', $category); |     $breadcrumbs->parent('categories.show', $category); | ||||||
|     $breadcrumbs->push('Edit ' . e($category->name), route('categories.edit', $category->id)); |     $breadcrumbs->push(trans('breadcrumbs.edit_category', ['name' => e($category->name)]), route('categories.edit', $category->id)); | ||||||
| } | } | ||||||
| ); | ); | ||||||
| Breadcrumbs::register( | Breadcrumbs::register( | ||||||
|     'categories.delete', function (Generator $breadcrumbs, Category $category) { |     'categories.delete', function (Generator $breadcrumbs, Category $category) { | ||||||
|     $breadcrumbs->parent('categories.show', $category); |     $breadcrumbs->parent('categories.show', $category); | ||||||
|     $breadcrumbs->push('Delete ' . e($category->name), route('categories.delete', $category->id)); |     $breadcrumbs->push(trans('breadcrumbs.delete_category', ['name' => e($category->name)]), route('categories.delete', $category->id)); | ||||||
| } | } | ||||||
| ); | ); | ||||||
|  |  | ||||||
| @@ -169,20 +167,20 @@ Breadcrumbs::register( | |||||||
| Breadcrumbs::register( | Breadcrumbs::register( | ||||||
|     'currency.index', function (Generator $breadcrumbs) { |     'currency.index', function (Generator $breadcrumbs) { | ||||||
|     $breadcrumbs->parent('home'); |     $breadcrumbs->parent('home'); | ||||||
|     $breadcrumbs->push('Currencies', route('currency.index')); |     $breadcrumbs->push(trans('breadcrumbs.currencies'), route('currency.index')); | ||||||
| } | } | ||||||
| ); | ); | ||||||
|  |  | ||||||
| Breadcrumbs::register( | Breadcrumbs::register( | ||||||
|     'currency.edit', function (Generator $breadcrumbs, TransactionCurrency $currency) { |     'currency.edit', function (Generator $breadcrumbs, TransactionCurrency $currency) { | ||||||
|     $breadcrumbs->parent('currency.index'); |     $breadcrumbs->parent('currency.index'); | ||||||
|     $breadcrumbs->push('Edit '.$currency->name, route('currency.edit', $currency->id)); |     $breadcrumbs->push(trans('breadcrumbs.edit_currency', ['name' => e($currency->name)]), route('currency.edit', $currency->id)); | ||||||
| } | } | ||||||
| ); | ); | ||||||
| Breadcrumbs::register( | Breadcrumbs::register( | ||||||
|     'currency.delete', function (Generator $breadcrumbs, TransactionCurrency $currency) { |     'currency.delete', function (Generator $breadcrumbs, TransactionCurrency $currency) { | ||||||
|     $breadcrumbs->parent('currency.index'); |     $breadcrumbs->parent('currency.index'); | ||||||
|     $breadcrumbs->push('Delete '.$currency->name, route('currency.delete', $currency->id)); |     $breadcrumbs->push(trans('breadcrumbs.delete_currency', ['name' => e($currency->name)]), route('currency.delete', $currency->id)); | ||||||
| } | } | ||||||
| ); | ); | ||||||
|  |  | ||||||
| @@ -191,26 +189,26 @@ Breadcrumbs::register( | |||||||
| Breadcrumbs::register( | Breadcrumbs::register( | ||||||
|     'piggy-banks.index', function (Generator $breadcrumbs) { |     'piggy-banks.index', function (Generator $breadcrumbs) { | ||||||
|     $breadcrumbs->parent('home'); |     $breadcrumbs->parent('home'); | ||||||
|     $breadcrumbs->push('Piggy banks', route('piggy-banks.index')); |     $breadcrumbs->push(trans('breadcrumbs.piggyBanks'), route('piggy-banks.index')); | ||||||
| } | } | ||||||
| ); | ); | ||||||
| Breadcrumbs::register( | Breadcrumbs::register( | ||||||
|     'piggy-banks.create', function (Generator $breadcrumbs) { |     'piggy-banks.create', function (Generator $breadcrumbs) { | ||||||
|     $breadcrumbs->parent('piggy-banks.index'); |     $breadcrumbs->parent('piggy-banks.index'); | ||||||
|     $breadcrumbs->push('Create new piggy bank', route('piggy-banks.create')); |     $breadcrumbs->push(trans('breadcrumbs.newPiggyBank'), route('piggy-banks.create')); | ||||||
| } | } | ||||||
| ); | ); | ||||||
|  |  | ||||||
| Breadcrumbs::register( | Breadcrumbs::register( | ||||||
|     'piggy-banks.edit', function (Generator $breadcrumbs, PiggyBank $piggyBank) { |     'piggy-banks.edit', function (Generator $breadcrumbs, PiggyBank $piggyBank) { | ||||||
|     $breadcrumbs->parent('piggy-banks.show', $piggyBank); |     $breadcrumbs->parent('piggy-banks.show', $piggyBank); | ||||||
|     $breadcrumbs->push('Edit ' . e($piggyBank->name), route('piggy-banks.edit', $piggyBank->id)); |     $breadcrumbs->push(trans('breadcrumbs.edit_piggyBank', ['name' => e($piggyBank->name)]), route('piggy-banks.edit', $piggyBank->id)); | ||||||
| } | } | ||||||
| ); | ); | ||||||
| Breadcrumbs::register( | Breadcrumbs::register( | ||||||
|     'piggy-banks.delete', function (Generator $breadcrumbs, PiggyBank $piggyBank) { |     'piggy-banks.delete', function (Generator $breadcrumbs, PiggyBank $piggyBank) { | ||||||
|     $breadcrumbs->parent('piggy-banks.show', $piggyBank); |     $breadcrumbs->parent('piggy-banks.show', $piggyBank); | ||||||
|     $breadcrumbs->push('Delete ' . e($piggyBank->name), route('piggy-banks.delete', $piggyBank->id)); |     $breadcrumbs->push(trans('breadcrumbs.delete_piggyBank', ['name' => e($piggyBank->name)]), route('piggy-banks.delete', $piggyBank->id)); | ||||||
| } | } | ||||||
| ); | ); | ||||||
|  |  | ||||||
| @@ -226,7 +224,7 @@ Breadcrumbs::register( | |||||||
| Breadcrumbs::register( | Breadcrumbs::register( | ||||||
|     'preferences', function (Generator $breadcrumbs) { |     'preferences', function (Generator $breadcrumbs) { | ||||||
|     $breadcrumbs->parent('home'); |     $breadcrumbs->parent('home'); | ||||||
|     $breadcrumbs->push('Preferences', route('preferences')); |     $breadcrumbs->push(trans('breadcrumbs.preferences'), route('preferences')); | ||||||
|  |  | ||||||
| } | } | ||||||
| ); | ); | ||||||
| @@ -235,14 +233,14 @@ Breadcrumbs::register( | |||||||
| Breadcrumbs::register( | Breadcrumbs::register( | ||||||
|     'profile', function (Generator $breadcrumbs) { |     'profile', function (Generator $breadcrumbs) { | ||||||
|     $breadcrumbs->parent('home'); |     $breadcrumbs->parent('home'); | ||||||
|     $breadcrumbs->push('Profile', route('profile')); |     $breadcrumbs->push(trans('breadcrumbs.profile'), route('profile')); | ||||||
|  |  | ||||||
| } | } | ||||||
| ); | ); | ||||||
| Breadcrumbs::register( | Breadcrumbs::register( | ||||||
|     'change-password', function (Generator $breadcrumbs) { |     'change-password', function (Generator $breadcrumbs) { | ||||||
|     $breadcrumbs->parent('profile'); |     $breadcrumbs->parent('profile'); | ||||||
|     $breadcrumbs->push('Change your password', route('change-password')); |     $breadcrumbs->push(trans('breadcrumbs.changePassword'), route('change-password')); | ||||||
|  |  | ||||||
| } | } | ||||||
| ); | ); | ||||||
| @@ -251,26 +249,26 @@ Breadcrumbs::register( | |||||||
| Breadcrumbs::register( | Breadcrumbs::register( | ||||||
|     'bills.index', function (Generator $breadcrumbs) { |     'bills.index', function (Generator $breadcrumbs) { | ||||||
|     $breadcrumbs->parent('home'); |     $breadcrumbs->parent('home'); | ||||||
|     $breadcrumbs->push('Bills', route('bills.index')); |     $breadcrumbs->push(trans('breadcrumbs.bills'), route('bills.index')); | ||||||
| } | } | ||||||
| ); | ); | ||||||
| Breadcrumbs::register( | Breadcrumbs::register( | ||||||
|     'bills.create', function (Generator $breadcrumbs) { |     'bills.create', function (Generator $breadcrumbs) { | ||||||
|     $breadcrumbs->parent('bills.index'); |     $breadcrumbs->parent('bills.index'); | ||||||
|     $breadcrumbs->push('Create new bill', route('bills.create')); |     $breadcrumbs->push(trans('breadcrumbs.newBill'), route('bills.create')); | ||||||
| } | } | ||||||
| ); | ); | ||||||
|  |  | ||||||
| Breadcrumbs::register( | Breadcrumbs::register( | ||||||
|     'bills.edit', function (Generator $breadcrumbs, Bill $bill) { |     'bills.edit', function (Generator $breadcrumbs, Bill $bill) { | ||||||
|     $breadcrumbs->parent('bills.show', $bill); |     $breadcrumbs->parent('bills.show', $bill); | ||||||
|     $breadcrumbs->push('Edit ' . e($bill->name), route('bills.edit', $bill->id)); |     $breadcrumbs->push(trans('breadcrumbs.edit_bill', ['name' => e($bill->name)]), route('bills.edit', $bill->id)); | ||||||
| } | } | ||||||
| ); | ); | ||||||
| Breadcrumbs::register( | Breadcrumbs::register( | ||||||
|     'bills.delete', function (Generator $breadcrumbs, Bill $bill) { |     'bills.delete', function (Generator $breadcrumbs, Bill $bill) { | ||||||
|     $breadcrumbs->parent('bills.show', $bill); |     $breadcrumbs->parent('bills.show', $bill); | ||||||
|     $breadcrumbs->push('Delete ' . e($bill->name), route('bills.delete', $bill->id)); |     $breadcrumbs->push(trans('breadcrumbs.delete_bill', ['name' => e($bill->name)]), route('bills.delete', $bill->id)); | ||||||
| } | } | ||||||
| ); | ); | ||||||
|  |  | ||||||
| @@ -286,7 +284,7 @@ Breadcrumbs::register( | |||||||
| Breadcrumbs::register( | Breadcrumbs::register( | ||||||
|     'reminders.index', function (Generator $breadcrumbs) { |     'reminders.index', function (Generator $breadcrumbs) { | ||||||
|     $breadcrumbs->parent('home'); |     $breadcrumbs->parent('home'); | ||||||
|     $breadcrumbs->push('Reminders', route('reminders.index')); |     $breadcrumbs->push(trans('breadcrumbs.reminders'), route('reminders.index')); | ||||||
|  |  | ||||||
| } | } | ||||||
| ); | ); | ||||||
| @@ -295,7 +293,7 @@ Breadcrumbs::register( | |||||||
| Breadcrumbs::register( | Breadcrumbs::register( | ||||||
|     'reminders.show', function (Generator $breadcrumbs, Reminder $reminder) { |     'reminders.show', function (Generator $breadcrumbs, Reminder $reminder) { | ||||||
|     $breadcrumbs->parent('reminders.index'); |     $breadcrumbs->parent('reminders.index'); | ||||||
|     $breadcrumbs->push('Reminder #' . $reminder->id, route('reminders.show', $reminder->id)); |     $breadcrumbs->push(trans('breadcrumbs.reminder', ['id' => e($reminder->id)]), route('reminders.show', $reminder->id)); | ||||||
|  |  | ||||||
| } | } | ||||||
| ); | ); | ||||||
| @@ -305,28 +303,33 @@ Breadcrumbs::register( | |||||||
| Breadcrumbs::register( | Breadcrumbs::register( | ||||||
|     'reports.index', function (Generator $breadcrumbs) { |     'reports.index', function (Generator $breadcrumbs) { | ||||||
|     $breadcrumbs->parent('home'); |     $breadcrumbs->parent('home'); | ||||||
|     $breadcrumbs->push('Reports', route('reports.index')); |     $breadcrumbs->push(trans('breadcrumbs.reports'), route('reports.index')); | ||||||
| } | } | ||||||
| ); | ); | ||||||
|  |  | ||||||
| Breadcrumbs::register( | Breadcrumbs::register( | ||||||
|     'reports.year', function (Generator $breadcrumbs, Carbon $date) { |     'reports.year', function (Generator $breadcrumbs, Carbon $date, $shared) { | ||||||
|     $breadcrumbs->parent('reports.index'); |     $breadcrumbs->parent('reports.index'); | ||||||
|     $breadcrumbs->push($date->format('Y'), route('reports.year', $date->format('Y'))); |     if ($shared) { | ||||||
|  |         $title = trans('breadcrumbs.yearly_report_shared', ['date' => $date->year]); | ||||||
|  |     } else { | ||||||
|  |         $title = trans('breadcrumbs.yearly_report', ['date' => $date->year]); | ||||||
|  |     } | ||||||
|  |     $breadcrumbs->push($title, route('reports.year', $date->year)); | ||||||
| } | } | ||||||
| ); | ); | ||||||
|  |  | ||||||
| Breadcrumbs::register( | Breadcrumbs::register( | ||||||
|     'reports.month', function (Generator $breadcrumbs, Carbon $date) { |     'reports.month', function (Generator $breadcrumbs, Carbon $date, $shared) { | ||||||
|     $breadcrumbs->parent('reports.index'); |     $breadcrumbs->parent('reports.year', $date, $shared); | ||||||
|     $breadcrumbs->push('Monthly report for ' . $date->format('F Y'), route('reports.month', $date)); |  | ||||||
| } |  | ||||||
| ); |  | ||||||
|  |  | ||||||
| Breadcrumbs::register( |     if ($shared) { | ||||||
|     'reports.budget', function (Generator $breadcrumbs, Carbon $date) { |         $title = trans('breadcrumbs.monthly_report_shared', ['date' => $date->year]); | ||||||
|     $breadcrumbs->parent('reports.index'); |     } else { | ||||||
|     $breadcrumbs->push('Budget report for ' . $date->format('F Y'), route('reports.budget', $date)); |         $title = trans('breadcrumbs.monthly_report', ['date' => $date->year]); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     $breadcrumbs->push($title, route('reports.month', [$date->year, $date->month])); | ||||||
| } | } | ||||||
| ); | ); | ||||||
|  |  | ||||||
| @@ -334,7 +337,7 @@ Breadcrumbs::register( | |||||||
| Breadcrumbs::register( | Breadcrumbs::register( | ||||||
|     'search', function (Generator $breadcrumbs, $query) { |     'search', function (Generator $breadcrumbs, $query) { | ||||||
|     $breadcrumbs->parent('home'); |     $breadcrumbs->parent('home'); | ||||||
|     $breadcrumbs->push('Search for "' . e($query) . '"', route('search')); |     $breadcrumbs->push(trans('breadcrumbs.searchResult', ['query' => e($query)]), route('search')); | ||||||
| } | } | ||||||
| ); | ); | ||||||
|  |  | ||||||
| @@ -342,47 +345,26 @@ Breadcrumbs::register( | |||||||
| Breadcrumbs::register( | Breadcrumbs::register( | ||||||
|     'transactions.index', function (Generator $breadcrumbs, $what) { |     'transactions.index', function (Generator $breadcrumbs, $what) { | ||||||
|     $breadcrumbs->parent('home'); |     $breadcrumbs->parent('home'); | ||||||
|  |     $breadcrumbs->push(trans('breadcrumbs.' . $what . '_list'), route('transactions.index', $what)); | ||||||
|     switch ($what) { |  | ||||||
|         case 'expenses': |  | ||||||
|         case 'withdrawal': |  | ||||||
|             $subTitle = 'Expenses'; |  | ||||||
|             break; |  | ||||||
|         case 'revenue': |  | ||||||
|         case 'deposit': |  | ||||||
|             $subTitle = 'Revenue, income and deposits'; |  | ||||||
|             break; |  | ||||||
|         case 'transfer': |  | ||||||
|         case 'transfers': |  | ||||||
|             $subTitle = 'Transfers'; |  | ||||||
|             break; |  | ||||||
|         case 'opening balance': |  | ||||||
|             $subTitle = 'Opening balances'; |  | ||||||
|             break; |  | ||||||
|         default: |  | ||||||
|             throw new FireflyException('Cannot handle $what "' . e($what) . '" in bread crumbs'); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     $breadcrumbs->push($subTitle, route('transactions.index', $what)); |  | ||||||
| } | } | ||||||
| ); | ); | ||||||
| Breadcrumbs::register( | Breadcrumbs::register( | ||||||
|     'transactions.create', function (Generator $breadcrumbs, $what) { |     'transactions.create', function (Generator $breadcrumbs, $what) { | ||||||
|     $breadcrumbs->parent('transactions.index', $what); |     $breadcrumbs->parent('transactions.index', $what); | ||||||
|     $breadcrumbs->push('Create new ' . e($what), route('transactions.create', $what)); |     $breadcrumbs->push(trans('breadcrumbs.create_' . e($what)), route('transactions.create', $what)); | ||||||
| } | } | ||||||
| ); | ); | ||||||
|  |  | ||||||
| Breadcrumbs::register( | Breadcrumbs::register( | ||||||
|     'transactions.edit', function (Generator $breadcrumbs, TransactionJournal $journal) { |     'transactions.edit', function (Generator $breadcrumbs, TransactionJournal $journal) { | ||||||
|     $breadcrumbs->parent('transactions.show', $journal); |     $breadcrumbs->parent('transactions.show', $journal); | ||||||
|     $breadcrumbs->push('Edit ' . e($journal->description), route('transactions.edit', $journal->id)); |     $breadcrumbs->push(trans('breadcrumbs.edit_journal', ['description' => $journal->description]), route('transactions.edit', $journal->id)); | ||||||
| } | } | ||||||
| ); | ); | ||||||
| Breadcrumbs::register( | Breadcrumbs::register( | ||||||
|     'transactions.delete', function (Generator $breadcrumbs, TransactionJournal $journal) { |     'transactions.delete', function (Generator $breadcrumbs, TransactionJournal $journal) { | ||||||
|     $breadcrumbs->parent('transactions.show', $journal); |     $breadcrumbs->parent('transactions.show', $journal); | ||||||
|     $breadcrumbs->push('Delete ' . e($journal->description), route('transactions.delete', $journal->id)); |     $breadcrumbs->push(trans('breadcrumbs.delete_journal', ['description' => e($journal->description)]), route('transactions.delete', $journal->id)); | ||||||
| } | } | ||||||
| ); | ); | ||||||
|  |  | ||||||
| @@ -390,7 +372,7 @@ Breadcrumbs::register( | |||||||
|     'transactions.show', function (Generator $breadcrumbs, TransactionJournal $journal) { |     'transactions.show', function (Generator $breadcrumbs, TransactionJournal $journal) { | ||||||
|  |  | ||||||
|     $breadcrumbs->parent('transactions.index', strtolower($journal->transactionType->type)); |     $breadcrumbs->parent('transactions.index', strtolower($journal->transactionType->type)); | ||||||
|     $breadcrumbs->push(e($journal->description), route('transactions.show', $journal->id)); |     $breadcrumbs->push($journal->description, route('transactions.show', $journal->id)); | ||||||
|  |  | ||||||
| } | } | ||||||
| ); | ); | ||||||
| @@ -399,19 +381,35 @@ Breadcrumbs::register( | |||||||
| Breadcrumbs::register( | Breadcrumbs::register( | ||||||
|     'tags.index', function (Generator $breadcrumbs) { |     'tags.index', function (Generator $breadcrumbs) { | ||||||
|     $breadcrumbs->parent('home'); |     $breadcrumbs->parent('home'); | ||||||
|     $breadcrumbs->push('Tags', route('tags.index')); |     $breadcrumbs->push(trans('breadcrumbs.tags'), route('tags.index')); | ||||||
| } | } | ||||||
| ); | ); | ||||||
|  |  | ||||||
| Breadcrumbs::register( | Breadcrumbs::register( | ||||||
|     'tags.create', function (Generator $breadcrumbs) { |     'tags.create', function (Generator $breadcrumbs) { | ||||||
|     $breadcrumbs->parent('tags.index'); |     $breadcrumbs->parent('tags.index'); | ||||||
|     $breadcrumbs->push('Create tag', route('tags.create')); |     $breadcrumbs->push(trans('breadcrumbs.createTag'), route('tags.create')); | ||||||
| } | } | ||||||
| ); | ); | ||||||
|  |  | ||||||
|  | Breadcrumbs::register( | ||||||
|  |     'tags.edit', function (Generator $breadcrumbs, Tag $tag) { | ||||||
|  |     $breadcrumbs->parent('tags.show', $tag); | ||||||
|  |     $breadcrumbs->push(trans('breadcrumbs.edit_tag', ['tag' => e($tag->tag)]), route('tags.edit', $tag->id)); | ||||||
|  | } | ||||||
|  | ); | ||||||
|  |  | ||||||
|  | Breadcrumbs::register( | ||||||
|  |     'tags.delete', function (Generator $breadcrumbs, Tag $tag) { | ||||||
|  |     $breadcrumbs->parent('tags.show', $tag); | ||||||
|  |     $breadcrumbs->push(trans('breadcrumbs.delete_tag', ['tag' => e($tag->tag)]), route('tags.delete', $tag->id)); | ||||||
|  | } | ||||||
|  | ); | ||||||
|  |  | ||||||
|  |  | ||||||
| Breadcrumbs::register( | Breadcrumbs::register( | ||||||
|     'tags.show', function (Generator $breadcrumbs, Tag $tag) { |     'tags.show', function (Generator $breadcrumbs, Tag $tag) { | ||||||
|     $breadcrumbs->parent('tags.index'); |     $breadcrumbs->parent('tags.index'); | ||||||
|     $breadcrumbs->push(e($tag->tag), route('tags.show', $tag)); |     $breadcrumbs->push(e($tag->tag), route('tags.show', $tag->id)); | ||||||
| } | } | ||||||
| ); | ); | ||||||
|   | |||||||
| @@ -13,6 +13,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | |||||||
|  |  | ||||||
|  |  | ||||||
| // models | // models | ||||||
|  | /** @noinspection PhpUnusedParameterInspection */ | ||||||
| Route::bind( | Route::bind( | ||||||
|     'account', |     'account', | ||||||
|     function ($value, $route) { |     function ($value, $route) { | ||||||
| @@ -30,6 +31,7 @@ Route::bind( | |||||||
|     } |     } | ||||||
| ); | ); | ||||||
|  |  | ||||||
|  | /** @noinspection PhpUnusedParameterInspection */ | ||||||
| Route::bind( | Route::bind( | ||||||
|     'tj', function ($value, $route) { |     'tj', function ($value, $route) { | ||||||
|     if (Auth::check()) { |     if (Auth::check()) { | ||||||
| @@ -43,6 +45,7 @@ Route::bind( | |||||||
| } | } | ||||||
| ); | ); | ||||||
|  |  | ||||||
|  | /** @noinspection PhpUnusedParameterInspection */ | ||||||
| Route::bind( | Route::bind( | ||||||
|     'currency', function ($value, $route) { |     'currency', function ($value, $route) { | ||||||
|     if (Auth::check()) { |     if (Auth::check()) { | ||||||
| @@ -55,6 +58,7 @@ Route::bind( | |||||||
| } | } | ||||||
| ); | ); | ||||||
|  |  | ||||||
|  | /** @noinspection PhpUnusedParameterInspection */ | ||||||
| Route::bind( | Route::bind( | ||||||
|     'bill', function ($value, $route) { |     'bill', function ($value, $route) { | ||||||
|     if (Auth::check()) { |     if (Auth::check()) { | ||||||
| @@ -68,6 +72,7 @@ Route::bind( | |||||||
| } | } | ||||||
| ); | ); | ||||||
|  |  | ||||||
|  | /** @noinspection PhpUnusedParameterInspection */ | ||||||
| Route::bind( | Route::bind( | ||||||
|     'budget', function ($value, $route) { |     'budget', function ($value, $route) { | ||||||
|     if (Auth::check()) { |     if (Auth::check()) { | ||||||
| @@ -81,6 +86,7 @@ Route::bind( | |||||||
| } | } | ||||||
| ); | ); | ||||||
|  |  | ||||||
|  | /** @noinspection PhpUnusedParameterInspection */ | ||||||
| Route::bind( | Route::bind( | ||||||
|     'reminder', function ($value, $route) { |     'reminder', function ($value, $route) { | ||||||
|     if (Auth::check()) { |     if (Auth::check()) { | ||||||
| @@ -94,6 +100,7 @@ Route::bind( | |||||||
| } | } | ||||||
| ); | ); | ||||||
|  |  | ||||||
|  | /** @noinspection PhpUnusedParameterInspection */ | ||||||
| Route::bind( | Route::bind( | ||||||
|     'limitrepetition', function ($value, $route) { |     'limitrepetition', function ($value, $route) { | ||||||
|     if (Auth::check()) { |     if (Auth::check()) { | ||||||
| @@ -111,6 +118,7 @@ Route::bind( | |||||||
| } | } | ||||||
| ); | ); | ||||||
|  |  | ||||||
|  | /** @noinspection PhpUnusedParameterInspection */ | ||||||
| Route::bind( | Route::bind( | ||||||
|     'piggyBank', function ($value, $route) { |     'piggyBank', function ($value, $route) { | ||||||
|     if (Auth::check()) { |     if (Auth::check()) { | ||||||
| @@ -127,12 +135,13 @@ Route::bind( | |||||||
| } | } | ||||||
| ); | ); | ||||||
|  |  | ||||||
|  | /** @noinspection PhpUnusedParameterInspection */ | ||||||
| Route::bind( | Route::bind( | ||||||
|     'category', function ($value, $route) { |     'category', function ($value, $route) { | ||||||
|     if (Auth::check()) { |     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) { |         if ($object) { | ||||||
|             $object = $object; |             return $object; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -140,12 +149,30 @@ Route::bind( | |||||||
| } | } | ||||||
| ); | ); | ||||||
|  |  | ||||||
|  | /** @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( | Route::bind( | ||||||
|     'tag', function ($value, $route) { |     'tag', function ($value, $route) { | ||||||
|     if (Auth::check()) { |     if (Auth::check()) { | ||||||
|         return Tag::where('id', $value)->where('user_id', Auth::user()->id)->first(); |         $object = Tag::where('id', $value)->where('user_id', Auth::user()->id)->first(); | ||||||
|         if ($object) { |         if ($object) { | ||||||
|             $object = $object; |             return $object; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -196,7 +223,6 @@ Route::group( | |||||||
|     Route::get('/bills/rescan/{bill}', ['uses' => 'BillController@rescan', 'as' => 'bills.rescan']); # rescan for matching. |     Route::get('/bills/rescan/{bill}', ['uses' => 'BillController@rescan', 'as' => 'bills.rescan']); # rescan for matching. | ||||||
|     Route::get('/bills/create', ['uses' => 'BillController@create', 'as' => 'bills.create']); |     Route::get('/bills/create', ['uses' => 'BillController@create', 'as' => 'bills.create']); | ||||||
|     Route::get('/bills/edit/{bill}', ['uses' => 'BillController@edit', 'as' => 'bills.edit']); |     Route::get('/bills/edit/{bill}', ['uses' => 'BillController@edit', 'as' => 'bills.edit']); | ||||||
|     Route::get('/bills/add/{bill}', ['uses' => 'BillController@add', 'as' => 'bills.add']); |  | ||||||
|     Route::get('/bills/delete/{bill}', ['uses' => 'BillController@delete', 'as' => 'bills.delete']); |     Route::get('/bills/delete/{bill}', ['uses' => 'BillController@delete', 'as' => 'bills.delete']); | ||||||
|     Route::get('/bills/show/{bill}', ['uses' => 'BillController@show', 'as' => 'bills.show']); |     Route::get('/bills/show/{bill}', ['uses' => 'BillController@show', 'as' => 'bills.show']); | ||||||
|     Route::post('/bills/store', ['uses' => 'BillController@store', 'as' => 'bills.store']); |     Route::post('/bills/store', ['uses' => 'BillController@store', 'as' => 'bills.store']); | ||||||
| @@ -246,22 +272,41 @@ Route::group( | |||||||
|  |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Google Chart Controller |      * ALL CHART Controllers | ||||||
|      */ |      */ | ||||||
|     Route::get('/chart/home/account', ['uses' => 'GoogleChartController@allAccountsBalanceChart']); |     // accounts: | ||||||
|     Route::get('/chart/home/budgets', ['uses' => 'GoogleChartController@allBudgetsHomeChart']); |     Route::get('/chart/account/frontpage', ['uses' => 'Chart\AccountController@frontpage']); | ||||||
|     Route::get('/chart/home/categories', ['uses' => 'GoogleChartController@allCategoriesHomeChart']); |     Route::get('/chart/account/month/{year}/{month}/{shared?}', ['uses' => 'Chart\AccountController@all'])->where( | ||||||
|     Route::get('/chart/home/bills', ['uses' => 'GoogleChartController@billsOverview']); |         ['year' => '[0-9]{4}', 'month' => '[0-9]{1,2}', 'shared' => 'shared'] | ||||||
|     Route::get('/chart/account/{account}/{view?}', ['uses' => 'GoogleChartController@accountBalanceChart']); |     ); | ||||||
|     Route::get('/chart/budget/{budget}/spending/{year?}', ['uses' => 'GoogleChartController@budgetsAndSpending']); |     Route::get('/chart/account/{account}', ['uses' => 'Chart\AccountController@single']); | ||||||
|     Route::get('/chart/budgets/spending/{year?}', ['uses' => 'GoogleChartController@allBudgetsAndSpending'])->where(['year' => '[0-9]+']); |  | ||||||
|     Route::get('/chart/budget/{budget}/{limitrepetition}', ['uses' => 'GoogleChartController@budgetLimitSpending']); |  | ||||||
|     Route::get('/chart/reports/income-expenses/{year}', ['uses' => 'GoogleChartController@yearInExp']); |     // bills: | ||||||
|     Route::get('/chart/reports/income-expenses-sum/{year}', ['uses' => 'GoogleChartController@yearInExpSum']); |     Route::get('/chart/bill/frontpage', ['uses' => 'Chart\BillController@frontpage']); | ||||||
|     Route::get('/chart/bills/{bill}', ['uses' => 'GoogleChartController@billOverview']); |     Route::get('/chart/bill/{bill}', ['uses' => 'Chart\BillController@single']); | ||||||
|     Route::get('/chart/piggy-history/{piggyBank}', ['uses' => 'GoogleChartController@piggyBankHistory']); |  | ||||||
|     Route::get('/chart/category/{category}/period', ['uses' => 'GoogleChartController@categoryPeriodChart']); |     // budgets: | ||||||
|     Route::get('/chart/category/{category}/overview', ['uses' => 'GoogleChartController@categoryOverviewChart']); |     Route::get('/chart/budget/frontpage', ['uses' => 'Chart\BudgetController@frontpage']); | ||||||
|  |     Route::get('/chart/budget/year/{year}/{shared?}', ['uses' => 'Chart\BudgetController@year'])->where(['year' => '[0-9]{4}', 'shared' => 'shared']); | ||||||
|  |     Route::get('/chart/budget/{budget}/{limitrepetition}', ['uses' => 'Chart\BudgetController@budgetLimit']); | ||||||
|  |     Route::get('/chart/budget/{budget}', ['uses' => 'Chart\BudgetController@budget']); | ||||||
|  |  | ||||||
|  |     // categories: | ||||||
|  |     Route::get('/chart/category/frontpage', ['uses' => 'Chart\CategoryController@frontpage']); | ||||||
|  |     Route::get('/chart/category/year/{year}/{shared?}', ['uses' => 'Chart\CategoryController@year'])->where(['year' => '[0-9]{4}', 'shared' => 'shared']); | ||||||
|  |     Route::get('/chart/category/{category}/month', ['uses' => 'Chart\CategoryController@month']); // should be period. | ||||||
|  |     Route::get('/chart/category/{category}/all', ['uses' => 'Chart\CategoryController@all']); | ||||||
|  |  | ||||||
|  |     // piggy banks: | ||||||
|  |     Route::get('/chart/piggyBank/{piggyBank}', ['uses' => 'Chart\PiggyBankController@history']); | ||||||
|  |  | ||||||
|  |     // reports: | ||||||
|  |     Route::get('/chart/report/in-out/{year}/{shared?}', ['uses' => 'Chart\ReportController@yearInOut'])->where(['year' => '[0-9]{4}', 'shared' => 'shared']); | ||||||
|  |     Route::get('/chart/report/in-out-sum/{year}/{shared?}', ['uses' => 'Chart\ReportController@yearInOutSummarized'])->where( | ||||||
|  |         ['year' => '[0-9]{4}', 'shared' => 'shared'] | ||||||
|  |     ); | ||||||
|  |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Help Controller |      * Help Controller | ||||||
| @@ -279,10 +324,7 @@ Route::group( | |||||||
|     Route::get('/json/box/out', ['uses' => 'JsonController@boxOut', 'as' => 'json.box.out']); |     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']); |     Route::get('/json/box/bills-unpaid', ['uses' => 'JsonController@boxBillsUnpaid', 'as' => 'json.box.paid']); | ||||||
|     Route::get('/json/box/bills-paid', ['uses' => 'JsonController@boxBillsPaid', 'as' => 'json.box.unpaid']); |     Route::get('/json/box/bills-paid', ['uses' => 'JsonController@boxBillsPaid', 'as' => 'json.box.unpaid']); | ||||||
|     Route::get('/json/show-shared-reports', 'JsonController@showSharedReports'); |  | ||||||
|     Route::get('/json/transaction-journals/{what}', 'JsonController@transactionJournals'); |     Route::get('/json/transaction-journals/{what}', 'JsonController@transactionJournals'); | ||||||
|     Route::get('/json/show-shared-reports/set', 'JsonController@setSharedReports'); |  | ||||||
|  |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Piggy Bank Controller |      * Piggy Bank Controller | ||||||
| @@ -328,19 +370,13 @@ Route::group( | |||||||
|      * Report Controller |      * Report Controller | ||||||
|      */ |      */ | ||||||
|     Route::get('/reports', ['uses' => 'ReportController@index', 'as' => 'reports.index']); |     Route::get('/reports', ['uses' => 'ReportController@index', 'as' => 'reports.index']); | ||||||
|     Route::get('/reports/{year}', ['uses' => 'ReportController@year', 'as' => 'reports.year']); |     //Route::get('/reports/{year}', ['uses' => 'ReportController@year', 'as' => 'reports.year'])->where(['year' => '[0-9]{4}']); | ||||||
|     Route::get('/reports/{year}/{month}', ['uses' => 'ReportController@month', 'as' => 'reports.month']); |     Route::get('/reports/{year}/{shared?}', ['uses' => 'ReportController@year', 'as' => 'reports.year'])->where(['year' => '[0-9]{4}', 'shared' => 'shared']); | ||||||
|     Route::get('/reports/budget/{year}/{month}', ['uses' => 'ReportController@budget', 'as' => 'reports.budget']); |     Route::get('/reports/{year}/{month}/{shared?}', ['uses' => 'ReportController@month', 'as' => 'reports.month'])->where( | ||||||
|  |         ['year' => '[0-9]{4}', 'month' => '[0-9]{1,2}', 'shared' => 'shared'] | ||||||
|  |     ); | ||||||
|  |  | ||||||
|     // pop ups for budget report: |     // pop ups for budget report: | ||||||
|     Route::get('/reports/modal/{account}/{year}/{month}/no-budget', ['uses' => 'ReportController@modalNoBudget', 'as' => 'reports.no-budget']); |  | ||||||
|     Route::get( |  | ||||||
|         '/reports/modal/{account}/{year}/{month}/balanced-transfers', |  | ||||||
|         ['uses' => 'ReportController@modalBalancedTransfers', 'as' => 'reports.balanced-transfers'] |  | ||||||
|     ); |  | ||||||
|     Route::get( |  | ||||||
|         '/reports/modal/{account}/{year}/{month}/left-unbalanced', ['uses' => 'ReportController@modalLeftUnbalanced', 'as' => 'reports.left-unbalanced'] |  | ||||||
|     ); |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Search Controller |      * Search Controller | ||||||
|   | |||||||
| @@ -28,6 +28,7 @@ class Account extends Model | |||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @param array $fields |      * @param array $fields | ||||||
|  |      * @SuppressWarnings(PHPMD.CyclomaticComplexity) | ||||||
|      * |      * | ||||||
|      * @return Account|null |      * @return Account|null | ||||||
|      */ |      */ | ||||||
| @@ -51,7 +52,7 @@ class Account extends Model | |||||||
|         $account = Account::create($fields); |         $account = Account::create($fields); | ||||||
|         if (is_null($account->id)) { |         if (is_null($account->id)) { | ||||||
|             // could not create account: |             // 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 |      * @return \Illuminate\Database\Eloquent\Relations\HasMany | ||||||
|      */ |      */ | ||||||
|     public function accountMeta() |     public function accountMeta() | ||||||
| @@ -69,6 +96,7 @@ class Account extends Model | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * @codeCoverageIgnore | ||||||
|      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo | ||||||
|      */ |      */ | ||||||
|     public function accountType() |     public function accountType() | ||||||
| @@ -77,6 +105,7 @@ class Account extends Model | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * @codeCoverageIgnore | ||||||
|      * @return array |      * @return array | ||||||
|      */ |      */ | ||||||
|     public function getDates() |     public function getDates() | ||||||
| @@ -85,6 +114,7 @@ class Account extends Model | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * | ||||||
|      * @param $fieldName |      * @param $fieldName | ||||||
|      * |      * | ||||||
|      * @return string|null |      * @return string|null | ||||||
| @@ -102,6 +132,8 @@ class Account extends Model | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * @codeCoverageIgnore | ||||||
|  |      * | ||||||
|      * @param $value |      * @param $value | ||||||
|      * |      * | ||||||
|      * @return string |      * @return string | ||||||
| @@ -119,6 +151,7 @@ class Account extends Model | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * @codeCoverageIgnore | ||||||
|      * @return \Illuminate\Database\Eloquent\Relations\HasMany |      * @return \Illuminate\Database\Eloquent\Relations\HasMany | ||||||
|      */ |      */ | ||||||
|     public function piggyBanks() |     public function piggyBanks() | ||||||
| @@ -127,6 +160,8 @@ class Account extends Model | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * @codeCoverageIgnore | ||||||
|  |      * | ||||||
|      * @param EloquentBuilder $query |      * @param EloquentBuilder $query | ||||||
|      * @param array           $types |      * @param array           $types | ||||||
|      */ |      */ | ||||||
| @@ -140,6 +175,8 @@ class Account extends Model | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * @codeCoverageIgnore | ||||||
|  |      * | ||||||
|      * @param EloquentBuilder $query |      * @param EloquentBuilder $query | ||||||
|      * @param string          $name |      * @param string          $name | ||||||
|      * @param string          $value |      * @param string          $value | ||||||
| @@ -156,6 +193,8 @@ class Account extends Model | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * @codeCoverageIgnore | ||||||
|  |      * | ||||||
|      * @param $value |      * @param $value | ||||||
|      */ |      */ | ||||||
|     public function setNameAttribute($value) |     public function setNameAttribute($value) | ||||||
| @@ -165,6 +204,7 @@ class Account extends Model | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * @codeCoverageIgnore | ||||||
|      * @return \Illuminate\Database\Eloquent\Relations\HasMany |      * @return \Illuminate\Database\Eloquent\Relations\HasMany | ||||||
|      */ |      */ | ||||||
|     public function transactions() |     public function transactions() | ||||||
| @@ -173,6 +213,7 @@ class Account extends Model | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * @codeCoverageIgnore | ||||||
|      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo | ||||||
|      */ |      */ | ||||||
|     public function user() |     public function user() | ||||||
|   | |||||||
| @@ -6,6 +6,7 @@ use Watson\Validating\ValidatingTrait; | |||||||
| /** | /** | ||||||
|  * Class AccountMeta |  * Class AccountMeta | ||||||
|  * |  * | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  * @package FireflyIII\Models |  * @package FireflyIII\Models | ||||||
|  */ |  */ | ||||||
| class AccountMeta extends Model | class AccountMeta extends Model | ||||||
| @@ -22,6 +23,7 @@ class AccountMeta extends Model | |||||||
|     protected $table    = 'account_meta'; |     protected $table    = 'account_meta'; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * | ||||||
|      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo | ||||||
|      */ |      */ | ||||||
|     public function account() |     public function account() | ||||||
|   | |||||||
| @@ -5,6 +5,7 @@ use Illuminate\Database\Eloquent\Model; | |||||||
| /** | /** | ||||||
|  * Class AccountType |  * Class AccountType | ||||||
|  * |  * | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  * @package FireflyIII\Models |  * @package FireflyIII\Models | ||||||
|  */ |  */ | ||||||
| class AccountType extends Model | class AccountType extends Model | ||||||
|   | |||||||
| @@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; | |||||||
| /** | /** | ||||||
|  * Class Budget |  * Class Budget | ||||||
|  * |  * | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  * @package FireflyIII\Models |  * @package FireflyIII\Models | ||||||
|  */ |  */ | ||||||
| class Budget extends Model | class Budget extends Model | ||||||
| @@ -17,6 +18,7 @@ class Budget extends Model | |||||||
|     protected $fillable = ['user_id', 'name']; |     protected $fillable = ['user_id', 'name']; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * | ||||||
|      * @return \Illuminate\Database\Eloquent\Relations\HasMany |      * @return \Illuminate\Database\Eloquent\Relations\HasMany | ||||||
|      */ |      */ | ||||||
|     public function budgetlimits() |     public function budgetlimits() | ||||||
|   | |||||||
| @@ -5,6 +5,7 @@ use Illuminate\Database\Eloquent\Model; | |||||||
| /** | /** | ||||||
|  * Class BudgetLimit |  * Class BudgetLimit | ||||||
|  * |  * | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  * @package FireflyIII\Models |  * @package FireflyIII\Models | ||||||
|  */ |  */ | ||||||
| class BudgetLimit extends Model | class BudgetLimit extends Model | ||||||
|   | |||||||
| @@ -1,12 +1,14 @@ | |||||||
| <?php namespace FireflyIII\Models; | <?php namespace FireflyIII\Models; | ||||||
|  |  | ||||||
|  | use App; | ||||||
| use Crypt; | use Crypt; | ||||||
| use Illuminate\Database\Eloquent\Model; | use Illuminate\Database\Eloquent\Model; | ||||||
| use Illuminate\Database\Eloquent\SoftDeletes; | use Illuminate\Database\Eloquent\SoftDeletes; | ||||||
| use App; |  | ||||||
| /** | /** | ||||||
|  * Class Category |  * Class Category | ||||||
|  * |  * | ||||||
|  |  * | ||||||
|  * @package FireflyIII\Models |  * @package FireflyIII\Models | ||||||
|  */ |  */ | ||||||
| class Category extends Model | class Category extends Model | ||||||
| @@ -16,6 +18,7 @@ class Category extends Model | |||||||
|     protected $fillable = ['user_id', 'name']; |     protected $fillable = ['user_id', 'name']; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * @codeCoverageIgnore | ||||||
|      * @return array |      * @return array | ||||||
|      */ |      */ | ||||||
|     public function getDates() |     public function getDates() | ||||||
| @@ -24,6 +27,7 @@ class Category extends Model | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * @codeCoverageIgnore | ||||||
|      * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |      * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany | ||||||
|      */ |      */ | ||||||
|     public function transactionjournals() |     public function transactionjournals() | ||||||
| @@ -33,6 +37,7 @@ class Category extends Model | |||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @param array $fields |      * @param array $fields | ||||||
|  |      * @SuppressWarnings(PHPMD.CyclomaticComplexity) | ||||||
|      * |      * | ||||||
|      * @return Account|null |      * @return Account|null | ||||||
|      */ |      */ | ||||||
| @@ -65,6 +70,7 @@ class Category extends Model | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * @codeCoverageIgnore | ||||||
|      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo | ||||||
|      */ |      */ | ||||||
|     public function user() |     public function user() | ||||||
| @@ -73,6 +79,8 @@ class Category extends Model | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * @codeCoverageIgnore | ||||||
|  |      * | ||||||
|      * @param $value |      * @param $value | ||||||
|      */ |      */ | ||||||
|     public function setNameAttribute($value) |     public function setNameAttribute($value) | ||||||
| @@ -82,6 +90,8 @@ class Category extends Model | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * @codeCoverageIgnore | ||||||
|  |      * | ||||||
|      * @param $value |      * @param $value | ||||||
|      * |      * | ||||||
|      * @return string |      * @return string | ||||||
| @@ -93,9 +103,7 @@ class Category extends Model | |||||||
|             return Crypt::decrypt($value); |             return Crypt::decrypt($value); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         // @codeCoverageIgnoreStart |  | ||||||
|         return $value; |         return $value; | ||||||
|         // @codeCoverageIgnoreEnd |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; | |||||||
| /** | /** | ||||||
|  * Class Component |  * Class Component | ||||||
|  * |  * | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  * @package FireflyIII\Models |  * @package FireflyIII\Models | ||||||
|  */ |  */ | ||||||
| class Component extends Model | class Component extends Model | ||||||
|   | |||||||
| @@ -13,6 +13,7 @@ class LimitRepetition extends Model | |||||||
| { | { | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * @codeCoverageIgnore | ||||||
|      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo | ||||||
|      */ |      */ | ||||||
|     public function budgetLimit() |     public function budgetLimit() | ||||||
| @@ -21,6 +22,7 @@ class LimitRepetition extends Model | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * @codeCoverageIgnore | ||||||
|      * @return array |      * @return array | ||||||
|      */ |      */ | ||||||
|     public function getDates() |     public function getDates() | ||||||
|   | |||||||
| @@ -14,9 +14,10 @@ class PiggyBank extends Model | |||||||
|     use SoftDeletes; |     use SoftDeletes; | ||||||
|  |  | ||||||
|     protected $fillable |     protected $fillable | ||||||
|         = ['name', 'account_id','order', '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 |      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo | ||||||
|      */ |      */ | ||||||
|     public function account() |     public function account() | ||||||
| @@ -44,6 +45,7 @@ class PiggyBank extends Model | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * @codeCoverageIgnore | ||||||
|      * @return \Illuminate\Database\Eloquent\Relations\HasMany |      * @return \Illuminate\Database\Eloquent\Relations\HasMany | ||||||
|      */ |      */ | ||||||
|     public function piggyBankRepetitions() |     public function piggyBankRepetitions() | ||||||
| @@ -52,6 +54,7 @@ class PiggyBank extends Model | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * @codeCoverageIgnore | ||||||
|      * @return array |      * @return array | ||||||
|      */ |      */ | ||||||
|     public function getDates() |     public function getDates() | ||||||
| @@ -60,6 +63,8 @@ class PiggyBank extends Model | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * @codeCoverageIgnore | ||||||
|  |      * | ||||||
|      * @param $value |      * @param $value | ||||||
|      * |      * | ||||||
|      * @return int |      * @return int | ||||||
| @@ -70,6 +75,7 @@ class PiggyBank extends Model | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * @codeCoverageIgnore | ||||||
|      * @return \Illuminate\Database\Eloquent\Relations\HasMany |      * @return \Illuminate\Database\Eloquent\Relations\HasMany | ||||||
|      */ |      */ | ||||||
|     public function piggyBankEvents() |     public function piggyBankEvents() | ||||||
| @@ -78,6 +84,7 @@ class PiggyBank extends Model | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * @codeCoverageIgnore | ||||||
|      * @return \Illuminate\Database\Eloquent\Relations\MorphMany |      * @return \Illuminate\Database\Eloquent\Relations\MorphMany | ||||||
|      */ |      */ | ||||||
|     public function reminders() |     public function reminders() | ||||||
| @@ -86,6 +93,8 @@ class PiggyBank extends Model | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * @codeCoverageIgnore | ||||||
|  |      * | ||||||
|      * @param $value |      * @param $value | ||||||
|      */ |      */ | ||||||
|     public function setNameAttribute($value) |     public function setNameAttribute($value) | ||||||
| @@ -95,6 +104,8 @@ class PiggyBank extends Model | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * @codeCoverageIgnore | ||||||
|  |      * | ||||||
|      * @param $value |      * @param $value | ||||||
|      * |      * | ||||||
|      * @return string |      * @return string | ||||||
|   | |||||||
| @@ -5,6 +5,7 @@ use Illuminate\Database\Eloquent\Model; | |||||||
| /** | /** | ||||||
|  * Class PiggyBankEvent |  * Class PiggyBankEvent | ||||||
|  * |  * | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  * @package FireflyIII\Models |  * @package FireflyIII\Models | ||||||
|  */ |  */ | ||||||
| class PiggyBankEvent extends Model | class PiggyBankEvent extends Model | ||||||
|   | |||||||
| @@ -7,11 +7,14 @@ use Illuminate\Database\Eloquent\Model; | |||||||
| /** | /** | ||||||
|  * Class PiggyBankRepetition |  * Class PiggyBankRepetition | ||||||
|  * |  * | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  * @package FireflyIII\Models |  * @package FireflyIII\Models | ||||||
|  */ |  */ | ||||||
| class PiggyBankRepetition extends Model | class PiggyBankRepetition extends Model | ||||||
| { | { | ||||||
|  |  | ||||||
|  |     protected $fillable = ['piggy_bank_id', 'startdate', 'targetdate', 'currentamount']; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @return array |      * @return array | ||||||
|      */ |      */ | ||||||
|   | |||||||
| @@ -5,6 +5,7 @@ use Illuminate\Database\Eloquent\Model; | |||||||
| /** | /** | ||||||
|  * Class Preference |  * Class Preference | ||||||
|  * |  * | ||||||
|  |  * @codeCoverageIgnore | ||||||
|  * @package FireflyIII\Models |  * @package FireflyIII\Models | ||||||
|  */ |  */ | ||||||
| class Preference extends Model | class Preference extends Model | ||||||
|   | |||||||
| @@ -17,6 +17,8 @@ class Reminder extends Model | |||||||
|     protected $fillable = ['user_id', 'startdate', 'metadata', 'enddate', 'active', 'notnow', 'remindersable_id', 'remindersable_type',]; |     protected $fillable = ['user_id', 'startdate', 'metadata', 'enddate', 'active', 'notnow', 'remindersable_id', 'remindersable_type',]; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * @codeCoverageIgnore | ||||||
|  |      * | ||||||
|      * @param $value |      * @param $value | ||||||
|      * |      * | ||||||
|      * @return int |      * @return int | ||||||
| @@ -27,6 +29,7 @@ class Reminder extends Model | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * @codeCoverageIgnore | ||||||
|      * @return array |      * @return array | ||||||
|      */ |      */ | ||||||
|     public function getDates() |     public function getDates() | ||||||
| @@ -35,6 +38,8 @@ class Reminder extends Model | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * @codeCoverageIgnore | ||||||
|  |      * | ||||||
|      * @param $value |      * @param $value | ||||||
|      * |      * | ||||||
|      * @return mixed |      * @return mixed | ||||||
| @@ -49,6 +54,8 @@ class Reminder extends Model | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * @codeCoverageIgnore | ||||||
|  |      * | ||||||
|      * @param $value |      * @param $value | ||||||
|      * |      * | ||||||
|      * @return bool |      * @return bool | ||||||
| @@ -59,6 +66,7 @@ class Reminder extends Model | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * @codeCoverageIgnore | ||||||
|      * @return \Illuminate\Database\Eloquent\Relations\MorphTo |      * @return \Illuminate\Database\Eloquent\Relations\MorphTo | ||||||
|      */ |      */ | ||||||
|     public function remindersable() |     public function remindersable() | ||||||
| @@ -67,6 +75,8 @@ class Reminder extends Model | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * @codeCoverageIgnore | ||||||
|  |      * | ||||||
|      * @param EloquentBuilder $query |      * @param EloquentBuilder $query | ||||||
|      * @param Carbon          $start |      * @param Carbon          $start | ||||||
|      * @param Carbon          $end |      * @param Carbon          $end | ||||||
| @@ -78,6 +88,13 @@ 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')); |         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) |     public function scopeToday(EloquentBuilder $query) | ||||||
|     { |     { | ||||||
|         $today = new Carbon; |         $today = new Carbon; | ||||||
| @@ -87,6 +104,8 @@ class Reminder extends Model | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * @codeCoverageIgnore | ||||||
|  |      * | ||||||
|      * @param $value |      * @param $value | ||||||
|      */ |      */ | ||||||
|     public function setMetadataAttribute($value) |     public function setMetadataAttribute($value) | ||||||
| @@ -96,6 +115,7 @@ class Reminder extends Model | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  |      * @codeCoverageIgnore | ||||||
|      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo | ||||||
|      */ |      */ | ||||||
|     public function user() |     public function user() | ||||||
|   | |||||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user